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

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

Overview

Finds a Gemini CLI session by scanning JSON chat files.

Gemini stores sessions under ~/.gemini/tmp/<sha256>/chats/*.json Directory name: SHA256 of the absolute working directory path Session ID: ‘sessionId` field in the JSON file First user message: `messages.content.text`

Constant Summary collapse

DEFAULT_BASE =
File.expand_path("~/.gemini/tmp").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



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

def self.call(working_dir:, prompt:, base_path: DEFAULT_BASE, max_candidates: 5)
  dir_hash = Digest::SHA256.hexdigest(File.expand_path(working_dir))
  chats_dir = File.join(base_path, dir_hash, "chats")
  return nil unless File.directory?(chats_dir)

  candidates = Dir.glob(File.join(chats_dir, "*.json"))
    .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