Class: Ace::Assign::Molecules::ForkSessionLauncher
- Inherits:
-
Object
- Object
- Ace::Assign::Molecules::ForkSessionLauncher
- Defined in:
- lib/ace/assign/molecules/fork_session_launcher.rb
Overview
Launches a forked assignment-driving session via CLI LLM providers.
Constant Summary collapse
- DEFAULT_PROVIDER =
"claude:sonnet"- DEFAULT_TIMEOUT =
1800- DEFAULT_LAUNCH_MODE =
"auto"- VALID_LAUNCH_MODES =
%w[auto headless tmux].freeze
- TMUX_POLL_INTERVAL =
0.5- DEFAULT_TARGET_ENV =
"ACE_ASSIGN_DEFAULT_TARGET"- CURRENT_ASSIGNMENT_ID_ENV =
"ACE_ASSIGN_CURRENT_ASSIGNMENT_ID"- CURRENT_FORK_ROOT_ENV =
"ACE_ASSIGN_CURRENT_FORK_ROOT"
Class Method Summary collapse
- .fork_scope_env(assignment_id:, fork_root:) ⇒ Object
- .same_scoped_refork?(assignment_id:, fork_root:, env: ENV) ⇒ Boolean
Instance Method Summary collapse
- #callback_pane ⇒ Object
-
#initialize(config: nil, query_interface: Ace::LLM::QueryInterface, tmux_runner: nil, interactive_builder: nil) ⇒ ForkSessionLauncher
constructor
A new instance of ForkSessionLauncher.
- #launch(assignment_id:, fork_root:, provider: nil, cli_args: nil, timeout: nil, cache_dir: nil, launch_mode: nil, callback_pane: nil) ⇒ Object
- #launch_provider_session(assignment_id:, fork_root:, provider:, cli_args: nil, timeout: nil, cache_dir: nil, last_message_file: nil, session_meta_file: nil) ⇒ Object
Constructor Details
#initialize(config: nil, query_interface: Ace::LLM::QueryInterface, tmux_runner: nil, interactive_builder: nil) ⇒ ForkSessionLauncher
Returns a new instance of ForkSessionLauncher.
38 39 40 41 42 43 |
# File 'lib/ace/assign/molecules/fork_session_launcher.rb', line 38 def initialize(config: nil, query_interface: Ace::LLM::QueryInterface, tmux_runner: nil, interactive_builder: nil) @config = config || Ace::Assign.config @query_interface = query_interface @tmux_runner = tmux_runner || TmuxControlSurfaceRunner.new @interactive_builder = interactive_builder || Ace::LLM::Molecules::InteractiveCommandBuilder.new end |
Class Method Details
.fork_scope_env(assignment_id:, fork_root:) ⇒ Object
20 21 22 23 24 25 26 27 |
# File 'lib/ace/assign/molecules/fork_session_launcher.rb', line 20 def self.fork_scope_env(assignment_id:, fork_root:) scoped_target = "#{assignment_id}@#{fork_root}" { DEFAULT_TARGET_ENV => scoped_target, CURRENT_ASSIGNMENT_ID_ENV => assignment_id.to_s, CURRENT_FORK_ROOT_ENV => fork_root.to_s } end |
.same_scoped_refork?(assignment_id:, fork_root:, env: ENV) ⇒ Boolean
29 30 31 32 33 34 35 36 |
# File 'lib/ace/assign/molecules/fork_session_launcher.rb', line 29 def self.same_scoped_refork?(assignment_id:, fork_root:, env: ENV) assignment_ref = assignment_id.to_s.strip root_ref = fork_root.to_s.strip return false if assignment_ref.empty? || root_ref.empty? env[CURRENT_ASSIGNMENT_ID_ENV].to_s.strip == assignment_ref && env[CURRENT_FORK_ROOT_ENV].to_s.strip == root_ref end |
Instance Method Details
#callback_pane ⇒ Object
73 74 75 |
# File 'lib/ace/assign/molecules/fork_session_launcher.rb', line 73 def callback_pane tmux_runner.current_pane end |
#launch(assignment_id:, fork_root:, provider: nil, cli_args: nil, timeout: nil, cache_dir: nil, launch_mode: nil, callback_pane: nil) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/ace/assign/molecules/fork_session_launcher.rb', line 45 def launch(assignment_id:, fork_root:, provider: nil, cli_args: nil, timeout: nil, cache_dir: nil, launch_mode: nil, callback_pane: nil) ensure_not_same_scoped_refork!(assignment_id: assignment_id, fork_root: fork_root) resolved_provider = provider || config.dig("execution", "provider") || DEFAULT_PROVIDER resolved_timeout = timeout || config.dig("execution", "timeout") || DEFAULT_TIMEOUT resolved_mode = resolve_launch_mode(launch_mode) if resolved_mode == "tmux" launch_tmux( assignment_id: assignment_id, fork_root: fork_root, provider: resolved_provider, cli_args: cli_args, timeout: resolved_timeout, cache_dir: cache_dir, callback_pane: callback_pane ) else launch_provider_session( assignment_id: assignment_id, fork_root: fork_root, provider: resolved_provider, cli_args: cli_args, timeout: resolved_timeout, cache_dir: cache_dir ) end end |
#launch_provider_session(assignment_id:, fork_root:, provider:, cli_args: nil, timeout: nil, cache_dir: nil, last_message_file: nil, session_meta_file: nil) ⇒ Object
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/ace/assign/molecules/fork_session_launcher.rb', line 77 def launch_provider_session(assignment_id:, fork_root:, provider:, cli_args: nil, timeout: nil, cache_dir: nil, last_message_file: nil, session_meta_file: nil) ensure_not_same_scoped_refork!(assignment_id: assignment_id, fork_root: fork_root) resolved_provider = provider || config.dig("execution", "provider") || DEFAULT_PROVIDER resolved_timeout = timeout || config.dig("execution", "timeout") || DEFAULT_TIMEOUT scoped_assignment = "#{assignment_id}@#{fork_root}" prompt = "/as-assign-drive #{scoped_assignment}" last_msg_file = || (cache_dir, fork_root) scope_env = self.class.fork_scope_env(assignment_id: assignment_id, fork_root: fork_root) result = query_interface.query( resolved_provider, prompt, system: nil, cli_args: cli_args, timeout: resolved_timeout, fallback: false, last_message_file: last_msg_file, subprocess_env: scope_env ) if last_msg_file && result[:text] && !result[:text].strip.empty? existing = File.exist?(last_msg_file) ? File.read(last_msg_file).strip : "" File.write(last_msg_file, result[:text]) if existing.empty? end (last_msg_file, result, prompt: prompt, session_meta_file: ) result rescue Ace::LLM::Error => e raise Error, "Fork session execution failed via #{resolved_provider}: #{e.}" end |