Class: Ace::LLM::Providers::CLI::Atoms::SessionFinders::ClaudeSessionFinder

Inherits:
Object
  • Object
show all
Defined in:
lib/ace/llm/providers/cli/atoms/session_finders/claude_session_finder.rb

Overview

Finds a Claude Code session by scanning JSONL session files.

Claude stores sessions under ~/.claude/projects/<encoded-path>/*.jsonl Path encoding: replace ‘/` and `.` with `-` Session ID: `sessionId` field on conversation entries First user message: `type:“user”` with `message.content` string

Constant Summary collapse

DEFAULT_BASE =
File.expand_path("~/.claude/projects").freeze

Class Method Summary collapse

Class Method Details

.call(working_dir:, prompt:, base_path: DEFAULT_BASE, max_candidates: 5) ⇒ Hash?

Returns { session_id:, session_path: } or nil.

Parameters:

  • working_dir (String)

    project directory to match

  • prompt (String)

    expected first user message

  • base_path (String) (defaults to: DEFAULT_BASE)

    override base path for testing

  • max_candidates (Integer) (defaults to: 5)

    max files to scan

Returns:

  • (Hash, nil)

    { session_id:, session_path: } or nil



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/ace/llm/providers/cli/atoms/session_finders/claude_session_finder.rb', line 25

def self.call(working_dir:, prompt:, base_path: DEFAULT_BASE, max_candidates: 5)
  encoded = encode_path(working_dir)
  project_dir = File.join(base_path, encoded)
  return nil unless File.directory?(project_dir)

  candidates = Dir.glob(File.join(project_dir, "*.jsonl"))
    .sort_by { |f| -File.mtime(f).to_f }
    .first(max_candidates)

  candidates.each do |path|
    result = scan_file(path, prompt)
    return result if result
  end

  nil
rescue
  nil
end