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

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

Overview

Finds a Pi agent session by scanning JSONL session files.

Pi stores sessions under ~/.pi/agent/sessions/<encoded-path>/*.jsonl Path encoding: replace ‘/` with `-`, wrap in `–` Session ID: `type:“session”` entry → `id` field First user message: `message.role:“user”` + `message.content.text`

Constant Summary collapse

DEFAULT_BASE =
File.expand_path("~/.pi/agent/sessions").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/pi_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