agent-cli-runtime 0.2.0 → 0.2.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -4,7 +4,9 @@ module AgentCliRuntime
4
4
  module OpenCode
5
5
  module ResultParser
6
6
  MAX_RUN_BYTES = 4 * 1024 * 1024
7
- MAX_EXPORT_BYTES = 4 * 1024 * 1024
7
+ # Sanitized exports contain the complete session and every tool result,
8
+ # so their bounded limit must accommodate long implementation sessions.
9
+ MAX_EXPORT_BYTES = 64 * 1024 * 1024
8
10
  MAX_FINAL_MESSAGE_BYTES = 1024 * 1024
9
11
  MAX_EVENTS = 10_000
10
12
  MAX_UNKNOWN_EVENTS = 16
@@ -22,8 +24,11 @@ module AgentCliRuntime
22
24
  AUTH_PATTERN = /auth|credential|api[ _-]?key|unauthorized|forbidden/i
23
25
  CONFIGURATION_PATTERN =
24
26
  /\b(?:Config(?:uration)?Error|UnknownProvider|UnknownModel|ModelNotFound|RouteUnavailable|VariantUnavailable)\b|\b(?:invalid|unknown|unsupported) (?:configuration|provider|model|route|variant)\b|\b(?:provider|model|route|variant)(?: [^\n]+)? (?:not found|unavailable)\b/i
27
+ UPSTREAM_TIMEOUT_PATTERN =
28
+ /\b(?:upstream\s+)?(?:idle\s+)?timeout\b|\btimed out\b|error_type['"\s:=>]+timeout\b|\bcode['"\s:=>]+504\b/i
25
29
  private_constant :KNOWN_EVENT_TYPES, :EVENT_PART_TYPES,
26
- :AUTH_PATTERN, :CONFIGURATION_PATTERN
30
+ :AUTH_PATTERN, :CONFIGURATION_PATTERN,
31
+ :UPSTREAM_TIMEOUT_PATTERN
27
32
 
28
33
  module_function
29
34
 
@@ -55,17 +60,22 @@ module AgentCliRuntime
55
60
  next
56
61
  end
57
62
 
58
- event_session = required_string(event, "sessionID", "event sessionID")
59
- session_id ||= event_session
60
- malformed!("OpenCode run sessionID changed within one capture") unless
61
- session_id == event_session
62
-
63
63
  if type == "error"
64
+ # OpenCode 2.x reports failures raised before a session exists
65
+ # (for example an empty prompt) with an empty sessionID.
66
+ error_session = validate_additive_session!(event, session_id) unless
67
+ event["sessionID"] == ""
68
+ session_id ||= error_session
64
69
  validate_error!(event)
65
70
  error_seen = true
66
71
  next
67
72
  end
68
73
 
74
+ event_session = required_string(event, "sessionID", "event sessionID")
75
+ session_id ||= event_session
76
+ malformed!("OpenCode run sessionID changed within one capture") unless
77
+ session_id == event_session
78
+
69
79
  part = required_hash(event, "part", "event part")
70
80
  validate_part!(part, type, session_id)
71
81
  message_id = required_string(part, "messageID", "part messageID")
@@ -88,8 +98,6 @@ module AgentCliRuntime
88
98
  message = texts.filter_map do |message_id, text|
89
99
  text if message_id == terminal.fetch(:message_id)
90
100
  end.join
91
- malformed!("OpenCode terminal assistant message is empty") if message.empty?
92
-
93
101
  final_message_truncated = message.bytesize > MAX_FINAL_MESSAGE_BYTES
94
102
  ParsedRun.new(
95
103
  session_id: session_id,
@@ -166,18 +174,21 @@ module AgentCliRuntime
166
174
  messages = export["messages"]
167
175
  malformed!("OpenCode sanitized export messages must be an array") unless
168
176
  messages.is_a?(Array)
169
- matches = messages.filter_map do |message|
177
+ assistant = nil
178
+ messages.each do |message|
170
179
  next unless message.is_a?(Hash) && message["info"].is_a?(Hash)
171
180
 
172
181
  record = message.fetch("info")
173
182
  next unless record["id"] == message_id
174
183
 
175
- record
184
+ if assistant
185
+ malformed!("OpenCode sanitized export must contain one terminal assistant record")
186
+ end
187
+ assistant = record
176
188
  end
177
- unless matches.one?
189
+ unless assistant
178
190
  malformed!("OpenCode sanitized export must contain one terminal assistant record")
179
191
  end
180
- assistant = matches.fetch(0)
181
192
  unless assistant["role"] == "assistant" &&
182
193
  assistant["sessionID"] == session_id
183
194
  malformed!("OpenCode sanitized export terminal record is not correlated")
@@ -208,7 +219,10 @@ module AgentCliRuntime
208
219
  cache_read: numeric(cache, "read", integer: true),
209
220
  cache_write: numeric(cache, "write", integer: true),
210
221
  reasoning: numeric(tokens, "reasoning", integer: true),
211
- cost: numeric(assistant, "cost", integer: false)
222
+ input_includes_cache_read: cache.key?("read") ? true : nil,
223
+ input_includes_cache_write: cache.key?("write") ? true : nil,
224
+ output_includes_reasoning: tokens.key?("reasoning") ? false : nil,
225
+ provider_reported_cost: numeric(assistant, "cost", integer: false)
212
226
  )
213
227
  }.freeze
214
228
  rescue JSON::ParserError => e
@@ -231,7 +245,10 @@ module AgentCliRuntime
231
245
  cache_read: required_numeric(cache, "read", integer: true),
232
246
  cache_write: required_numeric(cache, "write", integer: true),
233
247
  reasoning: required_numeric(tokens, "reasoning", integer: true),
234
- cost: required_numeric(part, "cost", integer: false)
248
+ input_includes_cache_read: true,
249
+ input_includes_cache_write: true,
250
+ output_includes_reasoning: false,
251
+ provider_reported_cost: required_numeric(part, "cost", integer: false)
235
252
  )
236
253
  }.freeze
237
254
  rescue ArgumentError => e
@@ -248,11 +265,18 @@ module AgentCliRuntime
248
265
  end
249
266
  private_class_method :validate_part!
250
267
 
268
+ # OpenCode 1.x: {"name": ..., "data": {"message": ...}}.
269
+ # OpenCode 2.x: {"type": ..., "message": ..., "status"?: ...}.
251
270
  def validate_error!(event)
252
271
  error = required_hash(event, "error", "error event payload")
253
- required_string(error, "name", "error name")
254
- data = required_hash(error, "data", "error data")
255
- required_string(data, "message", "error message")
272
+ if error.key?("name") || error.key?("data")
273
+ required_string(error, "name", "error name")
274
+ data = required_hash(error, "data", "error data")
275
+ required_string(data, "message", "error message")
276
+ else
277
+ required_string(error, "type", "error type")
278
+ required_string(error, "message", "error message")
279
+ end
256
280
  end
257
281
  private_class_method :validate_error!
258
282
 
@@ -279,6 +303,8 @@ module AgentCliRuntime
279
303
  :authentication_failure
280
304
  elsif corpus.match?(CONFIGURATION_PATTERN)
281
305
  :configuration_failure
306
+ elsif corpus.match?(UPSTREAM_TIMEOUT_PATTERN)
307
+ :timed_out
282
308
  else
283
309
  :cli_failure
284
310
  end
@@ -296,9 +322,8 @@ module AgentCliRuntime
296
322
  error = event["error"]
297
323
  next unless error.is_a?(Hash)
298
324
 
299
- name = error["name"].to_s
300
- data = error["data"]
301
- message = data.is_a?(Hash) ? data["message"].to_s : ""
325
+ name = (error["name"] || error["type"]).to_s
326
+ message = ErrorExtractors.opencode_error_message(error).to_s
302
327
  [ name, message ].reject(&:empty?).join(": ")
303
328
  rescue JSON::ParserError
304
329
  nil
@@ -4,10 +4,10 @@ require "rubygems/version"
4
4
 
5
5
  module AgentCliRuntime
6
6
  class Profile
7
- PROMPT_STYLES = %i[positional headless_flag_value stdin].freeze
7
+ PROMPT_STYLES = %i[positional headless_flag_value stdin piped_stdin].freeze
8
8
  WORKSPACE_WRITE_PERMISSION_MODE = "workspace-write".freeze
9
9
  READ_ONLY_PERMISSION_MODE = "read-only".freeze
10
- CAPTURE_TIMEOUT_SECONDS = 10
10
+ CAPTURE_TIMEOUT_SECONDS = 120
11
11
  CAPTURE_POLL_SECONDS = 0.01
12
12
  CAPTURE_TERM_GRACE_SECONDS = 0.2
13
13
  CAPTURE_REAP_GRACE_SECONDS = 0.2
@@ -23,25 +23,31 @@ module AgentCliRuntime
23
23
  :permission_skip_flag, :workspace_write_flags,
24
24
  :read_only_flags, :add_dir_flag, :tool_scope_flags,
25
25
  :budget_flag, :output_format_flags, :version_flag,
26
- :min_version, :prompt_style, :model_argument_builder,
26
+ :min_version, :prompt_style, :prompt_argument,
27
+ :model_argument_builder,
27
28
  :effort_argument_builder, :launcher_identity,
28
29
  :cli_capabilities, :declared_capability_support,
29
30
  :credential_environment_keys, :configuration_environment_key,
30
31
  :default_configuration_directory,
31
- :permission_policy_required, :result_parser
32
+ :permission_policy_required, :result_parser,
33
+ :version_check_timeout_sec
32
34
 
33
35
  def initialize(name:, bin_default:, headless_flag:, version_flag:,
34
36
  env_bin_override_keys: [], permission_skip_flag: nil,
35
37
  workspace_write_flags: [], read_only_flags: [],
36
38
  add_dir_flag: nil, tool_scope_flags: {}, budget_flag: nil,
37
39
  output_format_flags: [], min_version: nil,
38
- prompt_style: :positional, model_argument_builder: nil,
40
+ prompt_style: :positional, prompt_argument: nil,
41
+ model_argument_builder: nil,
39
42
  effort_argument_builder: nil, launcher_identity: nil,
40
- usage_extractor: nil, auth_configuration_probe: nil,
43
+ usage_extractor: nil, error_extractor: nil,
44
+ auth_configuration_probe: nil,
41
45
  cli_capabilities: {}, raw_cli_arguments_supported: false,
42
46
  credential_environment_keys: [], configuration_environment_key: nil,
43
47
  default_configuration_directory: nil,
44
- permission_policy_required: false, result_parser: nil)
48
+ configuration_directory_probe: nil,
49
+ permission_policy_required: false, result_parser: nil,
50
+ version_check_timeout_sec: CAPTURE_TIMEOUT_SECONDS)
45
51
  normalized_prompt_style = prompt_style.to_sym
46
52
  unless PROMPT_STYLES.include?(normalized_prompt_style)
47
53
  raise ArgumentError,
@@ -63,11 +69,14 @@ module AgentCliRuntime
63
69
  @version_flag = immutable_string(version_flag)
64
70
  @min_version = min_version.nil? ? nil : immutable_string(min_version)
65
71
  @prompt_style = normalized_prompt_style
72
+ @prompt_argument =
73
+ prompt_argument.nil? ? nil : immutable_string(prompt_argument)
66
74
  @model_argument_builder = model_argument_builder
67
75
  @effort_argument_builder = effort_argument_builder
68
76
  @launcher_identity =
69
77
  immutable_string(launcher_identity || "agent-cli-runtime/v1:#{@name}")
70
78
  @usage_extractor = usage_extractor || ->(_event) { nil }
79
+ @error_extractor = error_extractor || ErrorExtractors::DEFAULT
71
80
  @auth_configuration_probe = auth_configuration_probe
72
81
  @cli_capabilities = normalize_cli_capabilities(cli_capabilities)
73
82
  @raw_cli_arguments_supported = raw_cli_arguments_supported == true
@@ -80,8 +89,13 @@ module AgentCliRuntime
80
89
  @default_configuration_directory = optional_relative_directory(
81
90
  default_configuration_directory
82
91
  )
92
+ @configuration_directory_probe = configuration_directory_probe
83
93
  @permission_policy_required = permission_policy_required == true
84
94
  @result_parser = result_parser
95
+ @version_check_timeout_sec = Float(version_check_timeout_sec)
96
+ unless @version_check_timeout_sec.positive?
97
+ raise ArgumentError, "version_check_timeout_sec must be positive"
98
+ end
85
99
  @declared_capability_support = build_declared_capability_support
86
100
  freeze
87
101
  end
@@ -153,8 +167,8 @@ module AgentCliRuntime
153
167
  @raw_cli_arguments_supported
154
168
  end
155
169
 
156
- def binary_installed?(env: ENV)
157
- executable = bin(env:)
170
+ def binary_installed?(env: ENV, executable: nil)
171
+ executable ||= bin(env:)
158
172
  return File.file?(executable) && File.executable?(executable) if executable.include?(File::SEPARATOR)
159
173
 
160
174
  env.fetch("PATH", "").split(File::PATH_SEPARATOR).any? do |directory|
@@ -165,10 +179,10 @@ module AgentCliRuntime
165
179
  false
166
180
  end
167
181
 
168
- def check_version!(env: ENV)
169
- executable = bin(env:)
182
+ def check_version!(env: ENV, executable: nil)
183
+ executable ||= bin(env:)
170
184
  out, _err, status = bounded_capture3(
171
- executable, @version_flag, timeout_sec: CAPTURE_TIMEOUT_SECONDS, env: env
185
+ executable, @version_flag, timeout_sec: @version_check_timeout_sec, env: env
172
186
  )
173
187
  unless status.success?
174
188
  raise BinaryUnavailable,
@@ -180,12 +194,16 @@ module AgentCliRuntime
180
194
  raise VersionError,
181
195
  "could not parse #{@name} #{@version_flag} output"
182
196
  end
183
- if versions.length > 1
197
+ # A CLI may print one version twice in different forms (Muse prints
198
+ # "1.4.14 (1.4.14-R7309.1)"). That is one version, not ambiguity: only
199
+ # distinct numeric cores disagree about what is installed.
200
+ cores = versions.map { |value| value[/\A\d+\.\d+\.\d+/] }.uniq
201
+ if cores.length > 1
184
202
  raise VersionError,
185
203
  "ambiguous #{@name} #{@version_flag} output: " \
186
204
  "#{versions.join(', ')}"
187
205
  end
188
- version = versions.fetch(0)
206
+ version = versions.length == 1 ? versions.fetch(0) : cores.fetch(0)
189
207
  if @min_version &&
190
208
  Gem::Version.new(version) < Gem::Version.new(@min_version)
191
209
  raise VersionError,
@@ -197,7 +215,7 @@ module AgentCliRuntime
197
215
  "#{@name} binary not runnable: #{executable} (#{e.class.name.split('::').last})"
198
216
  rescue Timeout::Error
199
217
  raise BinaryUnavailable,
200
- "#{@name} version check timed out after #{CAPTURE_TIMEOUT_SECONDS}s: #{executable}"
218
+ "#{@name} version check timed out after #{@version_check_timeout_sec}s: #{executable}"
201
219
  end
202
220
 
203
221
  def auth_configuration(home: nil, env: ENV)
@@ -221,6 +239,12 @@ module AgentCliRuntime
221
239
  nil
222
240
  end
223
241
 
242
+ def extract_error_event(event)
243
+ @error_extractor.call(event)
244
+ rescue StandardError
245
+ nil
246
+ end
247
+
224
248
  def parse_run(stdout)
225
249
  unless @result_parser
226
250
  raise UnsupportedCapability,
@@ -242,6 +266,10 @@ module AgentCliRuntime
242
266
  end
243
267
 
244
268
  def configuration_directory(home: nil, env: ENV)
269
+ if @configuration_directory_probe
270
+ resolved = @configuration_directory_probe.call(home: home, env: env)
271
+ return File.expand_path(resolved) if resolved
272
+ end
245
273
  if @configuration_environment_key
246
274
  configured = env[@configuration_environment_key].to_s
247
275
  unless configured.empty?
@@ -278,9 +306,10 @@ module AgentCliRuntime
278
306
  flags.dup
279
307
  end
280
308
 
281
- def capture_local(*arguments, env: ENV, timeout_sec: CAPTURE_TIMEOUT_SECONDS)
309
+ def capture_local(*arguments, env: ENV, timeout_sec: CAPTURE_TIMEOUT_SECONDS,
310
+ executable: nil)
282
311
  bounded_capture3(
283
- bin(env:), *arguments, timeout_sec: timeout_sec, env: env
312
+ executable || bin(env:), *arguments, timeout_sec: timeout_sec, env: env
284
313
  )
285
314
  end
286
315
 
@@ -66,7 +66,7 @@ module AgentCliRuntime
66
66
 
67
67
  def auth_from_file(path, source:)
68
68
  configured = File.file?(path) &&
69
- !File.read(path).strip.match?(/\A(?:|\{\s*\})\z/m)
69
+ !File.binread(path).strip.match?(/\A(?:|\{\s*\})\z/m)
70
70
  AuthConfiguration.new(
71
71
  status: configured ? :configured : :missing,
72
72
  source: source
@@ -103,6 +103,61 @@ module AgentCliRuntime
103
103
  home_path(home, ".grok", "auth.json")
104
104
  end
105
105
 
106
+ # Muse keeps credentials and settings under the XDG config root
107
+ # ($XDG_CONFIG_HOME/muse, default ~/.config/muse). It has no config-dir
108
+ # environment override of its own, so XDG_CONFIG_HOME is the only
109
+ # relocation lever and it names the base, not the muse directory.
110
+ def muse_configuration_directory(home:, env:)
111
+ xdg = env["XDG_CONFIG_HOME"]
112
+ unless xdg.to_s.empty?
113
+ unless File.absolute_path?(xdg)
114
+ raise ArgumentError, "XDG_CONFIG_HOME must be absolute"
115
+ end
116
+
117
+ return File.join(File.expand_path(xdg), "muse")
118
+ end
119
+
120
+ base = home || env["HOME"]
121
+ base = nil if base.to_s.empty?
122
+ home_path(base, ".config", "muse")
123
+ end
124
+
125
+ def muse_auth_path(home:, env:)
126
+ File.join(muse_configuration_directory(home:, env:), "auth.json")
127
+ end
128
+
129
+ # Plugin state (installed.json, package cache) lives under the XDG data
130
+ # root ($XDG_DATA_HOME/muse, default ~/.local/share/muse), not beside
131
+ # the settings in the config root.
132
+ def muse_data_directory(home:, env:)
133
+ xdg = env["XDG_DATA_HOME"]
134
+ unless xdg.to_s.empty?
135
+ unless File.absolute_path?(xdg)
136
+ raise ArgumentError, "XDG_DATA_HOME must be absolute"
137
+ end
138
+
139
+ return File.join(File.expand_path(xdg), "muse")
140
+ end
141
+
142
+ base = home || env["HOME"]
143
+ base = nil if base.to_s.empty?
144
+ home_path(base, ".local", "share", "muse")
145
+ end
146
+
147
+ # Antigravity CLI (`agy`) stores settings and its fallback OAuth token
148
+ # under `~/.gemini/antigravity-cli`, while skills and plugins live under
149
+ # `~/.gemini/config`. Neither path has a CLI-specific environment override;
150
+ # both follow `HOME`.
151
+ def agy_state_directory(home:, env:)
152
+ base = home || env["HOME"]
153
+ base = nil if base.to_s.empty?
154
+ home_path(base, ".gemini", "antigravity-cli")
155
+ end
156
+
157
+ def agy_auth_path(home:, env:)
158
+ File.join(agy_state_directory(home:, env:), "antigravity-oauth-token")
159
+ end
160
+
106
161
  def opencode_auth_path(home:, env:)
107
162
  data_home = env["XDG_DATA_HOME"]
108
163
  if !data_home.to_s.empty?
@@ -139,6 +194,8 @@ module AgentCliRuntime
139
194
  bin_default: "claude",
140
195
  env_bin_override_keys: %w[AGENT_CLI_RUNTIME_CLAUDE_BIN HIVE_CLAUDE_BIN],
141
196
  headless_flag: "-p",
197
+ # Print mode reads stdin; keep large review prompts out of exec arguments.
198
+ prompt_style: :piped_stdin,
142
199
  permission_skip_flag: "--dangerously-skip-permissions",
143
200
  add_dir_flag: "--add-dir",
144
201
  tool_scope_flags: {
@@ -156,6 +213,7 @@ module AgentCliRuntime
156
213
  effort_argument_builder: ->(effort) { [ "--effort", effort ] },
157
214
  launcher_identity: "claude-code/v1",
158
215
  usage_extractor: UsageExtractors::CLAUDE,
216
+ error_extractor: ErrorExtractors::CLAUDE,
159
217
  credential_environment_keys: %w[
160
218
  ANTHROPIC_API_KEY ANTHROPIC_AUTH_TOKEN CLAUDE_API_KEY
161
219
  ],
@@ -200,6 +258,7 @@ module AgentCliRuntime
200
258
  ->(effort) { [ "-c", "model_reasoning_effort=#{effort}" ] },
201
259
  launcher_identity: "codex-cli/v1",
202
260
  usage_extractor: UsageExtractors::CODEX,
261
+ error_extractor: ErrorExtractors::CODEX,
203
262
  credential_environment_keys: %w[OPENAI_API_KEY],
204
263
  configuration_environment_key: "CODEX_HOME",
205
264
  default_configuration_directory: ".codex",
@@ -220,12 +279,17 @@ module AgentCliRuntime
220
279
  bin_default: "pi",
221
280
  env_bin_override_keys: %w[AGENT_CLI_RUNTIME_PI_BIN HIVE_PI_BIN],
222
281
  headless_flag: "-p",
282
+ # Pi reads a non-TTY stdin stream into its initial message without an
283
+ # argv placeholder. Keeping the prompt out of argv also avoids Linux's
284
+ # per-argument size limit on real implementation plans.
285
+ prompt_style: :piped_stdin,
223
286
  output_format_flags: [ "--mode", "json", "--no-session" ],
224
287
  version_flag: "--version",
225
288
  min_version: "0.70.2",
226
289
  model_argument_builder: ->(model) { [ "--model", model ] },
227
290
  launcher_identity: "pi-coding-agent/v1",
228
291
  usage_extractor: UsageExtractors::PI,
292
+ error_extractor: ErrorExtractors::PI,
229
293
  credential_environment_keys: PI_CREDENTIAL_ENVIRONMENT_KEYS,
230
294
  configuration_environment_key: "PI_CODING_AGENT_DIR",
231
295
  default_configuration_directory: ".pi/agent",
@@ -247,9 +311,18 @@ module AgentCliRuntime
247
311
  name: :grok,
248
312
  bin_default: "grok",
249
313
  env_bin_override_keys: %w[AGENT_CLI_RUNTIME_GROK_BIN HIVE_GROK_BIN],
250
- headless_flag: "-p",
251
- prompt_style: :headless_flag_value,
314
+ # Grok's Unix CLI reads a prompt file; stdin already has a managed lifetime.
315
+ headless_flag: "--prompt-file=/dev/stdin",
316
+ prompt_style: :piped_stdin,
252
317
  permission_skip_flag: "--always-approve",
318
+ # Grok confines the filesystem natively, the same shape codex uses.
319
+ # `workspace` limits writes to the working directory, `read-only`
320
+ # forbids them entirely; both are built-in profiles (custom ones extend
321
+ # them from ~/.grok/sandbox.toml). `--always-approve` suppresses the
322
+ # interactive approval prompt, which a headless reviewer can never answer
323
+ # — the sandbox, not the prompt, is what actually bounds the agent.
324
+ workspace_write_flags: [ "--sandbox", "workspace", "--always-approve" ],
325
+ read_only_flags: [ "--sandbox", "read-only", "--always-approve" ],
253
326
  output_format_flags: [ "--output-format", "streaming-json" ],
254
327
  version_flag: "--version",
255
328
  min_version: "0.2.90",
@@ -282,6 +355,14 @@ module AgentCliRuntime
282
355
  headless_flag: "run",
283
356
  output_format_flags: [ "--format", "json" ],
284
357
  version_flag: "--version",
358
+ # `opencode run` reads a non-TTY stdin stream as the initial message.
359
+ # Keep implementation-sized prompts out of one argv element: Linux
360
+ # rejects a single argument around 128 KiB with E2BIG even when the
361
+ # complete argv remains far below ARG_MAX.
362
+ prompt_style: :piped_stdin,
363
+ # Bun-backed OpenCode startup can exceed the generic 10-second bound
364
+ # under sustained host I/O even though the executable is healthy.
365
+ version_check_timeout_sec: 30,
285
366
  min_version: "1.18.16",
286
367
  model_argument_builder: ->(model) { opencode_model_arguments(model) },
287
368
  effort_argument_builder:
@@ -291,13 +372,17 @@ module AgentCliRuntime
291
372
  configuration_environment_key: "OPENCODE_CONFIG_DIR",
292
373
  default_configuration_directory: ".config/opencode",
293
374
  permission_policy_required: true,
375
+ error_extractor: ErrorExtractors::OPENCODE,
294
376
  result_parser: OpenCode::ResultParser,
295
377
  cli_capabilities: {
296
378
  json_events: [ "run", "--format" ],
297
379
  working_directory: [ "run", "--dir" ],
298
380
  model_variant: [ "run", "--variant" ],
299
381
  pure: [ "run", "--pure" ],
300
- sanitized_export: [ "export", "--sanitize" ]
382
+ sanitized_export: [ "export", "--sanitize" ],
383
+ # OpenCode 2.x only: a private server instead of the shared
384
+ # background service. The route probe records it when advertised.
385
+ private_server: [ "run", "--standalone" ]
301
386
  },
302
387
  auth_configuration_probe: lambda do |home:, env:|
303
388
  if env_configured?(env, *PI_CREDENTIAL_ENVIRONMENT_KEYS)
@@ -311,7 +396,111 @@ module AgentCliRuntime
311
396
  end
312
397
  )
313
398
 
314
- PROFILES = [ CLAUDE, CODEX, PI, GROK, OPENCODE ].to_h do |profile|
399
+ MUSE = Profile.new(
400
+ name: :muse,
401
+ bin_default: "muse",
402
+ env_bin_override_keys: %w[AGENT_CLI_RUNTIME_MUSE_BIN HIVE_MUSE_BIN],
403
+ headless_flag: "exec",
404
+ # Muse does not read a prompt from stdin, but --prompt-file accepts
405
+ # /dev/stdin when the host materializes stdin as a regular file (Hive
406
+ # spawns agents with stdin redirected from a tempfile). That keeps
407
+ # arbitrarily large prompts out of argv.
408
+ prompt_style: :piped_stdin,
409
+ prompt_argument: "--prompt-file=/dev/stdin",
410
+ # The unscoped path mirrors the other CLIs' skip flags: no approval
411
+ # prompts and no sandbox. The scoped modes below keep Muse's shell
412
+ # sandbox on (its default) and bound the run with approval policy
413
+ # instead of a prompt a headless caller can never answer.
414
+ permission_skip_flag: "--yolo",
415
+ workspace_write_flags: [
416
+ "--approval-mode", "never",
417
+ "--trust-workspace", "--disable-request-user-input"
418
+ ],
419
+ # Muse has no read-only filesystem sandbox mode. Disabling the write
420
+ # tools and the shell is the strongest native read-only boundary it
421
+ # offers; read/search tools stay available.
422
+ read_only_flags: [
423
+ "--approval-mode", "never",
424
+ "--trust-workspace", "--disable-request-user-input",
425
+ "--disable-write", "--disable-shell"
426
+ ],
427
+ # --json emits the MSP event stream (final text on
428
+ # run.terminal.completed, usage on run.usage). Reminder agents add
429
+ # extra model calls and injected prompts to a one-shot run, and
430
+ # request_user_input can never be answered headlessly.
431
+ output_format_flags: [
432
+ "--json", "--disable-reminders", "--disable-request-user-input",
433
+ "--no-session-log"
434
+ ],
435
+ version_flag: "--version",
436
+ min_version: "1.4.14",
437
+ model_argument_builder: ->(model) { [ "--model", model ] },
438
+ effort_argument_builder:
439
+ ->(effort) { [ "--reasoning-effort", effort ] },
440
+ launcher_identity: "muse-code/v1",
441
+ usage_extractor: UsageExtractors::MUSE,
442
+ error_extractor: ErrorExtractors::MUSE,
443
+ credential_environment_keys: %w[META_API_KEY],
444
+ # No configuration_environment_key: Muse has no private config-dir
445
+ # variable, and XDG_CONFIG_HOME names a base shared by every XDG
446
+ # tool (gh, git, Hive), so a launch binding must not export it. The
447
+ # probe below resolves the directory; non-default bindings are
448
+ # unsupported until Muse grows its own override.
449
+ default_configuration_directory: ".config/muse",
450
+ configuration_directory_probe: lambda do |home:, env:|
451
+ muse_configuration_directory(home: home, env: env)
452
+ end,
453
+ auth_configuration_probe: lambda do |home:, env:|
454
+ if env_configured?(env, "META_API_KEY")
455
+ AuthConfiguration.new(status: :configured, source: "environment")
456
+ else
457
+ auth_from_file(
458
+ muse_auth_path(home: home, env: env),
459
+ source: "muse auth.json"
460
+ )
461
+ end
462
+ end
463
+ )
464
+
465
+ AGY = Profile.new(
466
+ name: :agy,
467
+ bin_default: "agy",
468
+ env_bin_override_keys: %w[AGENT_CLI_RUNTIME_AGY_BIN HIVE_AGY_BIN],
469
+ # `agy` runs non-interactively and reads the prompt from piped or
470
+ # file-redirected stdin when `--input-format=text` is passed without `-p`,
471
+ # keeping arbitrarily large prompts out of argv.
472
+ headless_flag: "--input-format=text",
473
+ prompt_style: :piped_stdin,
474
+ permission_skip_flag: "--dangerously-skip-permissions",
475
+ add_dir_flag: "--add-dir",
476
+ output_format_flags: [ "--output-format", "stream-json" ],
477
+ version_flag: "--version",
478
+ min_version: "1.5.17",
479
+ model_argument_builder: ->(model) { [ "--model", model ] },
480
+ effort_argument_builder: ->(effort) { [ "--effort", effort ] },
481
+ launcher_identity: "antigravity-cli/v1",
482
+ usage_extractor: UsageExtractors::AGY,
483
+ error_extractor: ErrorExtractors::AGY,
484
+ credential_environment_keys: %w[
485
+ GEMINI_API_KEY GOOGLE_API_KEY GOOGLE_APPLICATION_CREDENTIALS
486
+ ],
487
+ configuration_environment_key: nil,
488
+ default_configuration_directory: ".gemini/config",
489
+ auth_configuration_probe: lambda do |home:, env:|
490
+ if env_configured?(
491
+ env, "GEMINI_API_KEY", "GOOGLE_API_KEY", "GOOGLE_APPLICATION_CREDENTIALS"
492
+ )
493
+ AuthConfiguration.new(status: :configured, source: "environment")
494
+ else
495
+ auth_from_file(
496
+ agy_auth_path(home: home, env: env),
497
+ source: "~/.gemini/antigravity-cli/antigravity-oauth-token"
498
+ )
499
+ end
500
+ end
501
+ )
502
+
503
+ PROFILES = [ CLAUDE, CODEX, PI, GROK, OPENCODE, MUSE, AGY ].to_h do |profile|
315
504
  [ profile.name, profile ]
316
505
  end.freeze
317
506
  PROVIDER_ORDER = PROFILES.keys.freeze