Class: Ace::LLM::Providers::CLI::Atoms::SessionFinders::OpenCodeSessionFinder
- Inherits:
-
Object
- Object
- Ace::LLM::Providers::CLI::Atoms::SessionFinders::OpenCodeSessionFinder
- Defined in:
- lib/ace/llm/providers/cli/atoms/session_finders/open_code_session_finder.rb
Overview
Finds an OpenCode session by scanning its JSON storage.
OpenCode stores data under ~/.local/share/opencode/storage/ Project mapping: ‘project/*.json` with `worktree` field matching working_dir Session: `session/<hash>/*.json` with `id` (ses_ prefix) Messages: 3-level chain: `message/<sid>/` -> `part/<mid>/` -> text content
Constant Summary collapse
- DEFAULT_BASE =
File.("~/.local/share/opencode/storage").freeze
Class Method Summary collapse
-
.call(working_dir:, prompt:, base_path: DEFAULT_BASE, max_candidates: 5) ⇒ Hash?
{ session_id:, session_path: } or nil.
Class Method Details
.call(working_dir:, prompt:, base_path: DEFAULT_BASE, max_candidates: 5) ⇒ Hash?
Returns { session_id:, session_path: } or nil.
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/ace/llm/providers/cli/atoms/session_finders/open_code_session_finder.rb', line 25 def self.call(working_dir:, prompt:, base_path: DEFAULT_BASE, max_candidates: 5) # Verify the working_dir is a known OpenCode project (nil-gate). # OpenCode sessions don't store a project reference, so we can't filter # sessions by project — prompt matching is the primary identification. project_id = find_project_id(base_path, working_dir) return nil unless project_id sessions = find_sessions(base_path, max_candidates) sessions.each do |session_path, session_data| session_id = session_data["id"] next unless session_id if (base_path, session_id, prompt) return {session_id: session_id, session_path: session_path} end end nil rescue nil end |