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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 38323f74e355a6a9da1dfb45ccee48c253ffbd0c9693a16cd62910ced381c7cb
4
- data.tar.gz: 2e38766e9b737df1e5360ac8013849cf2108dab3f8b937f24ec393c001aba669
3
+ metadata.gz: cdc9f14fbb7d9e17922d9689d51f101a7f0416c57b178112f3cae8dd38782e2e
4
+ data.tar.gz: 7620b45bfb0f64cad4be03131c0075a2721e2c7c2bf8dd609b7e36d4884d2dcb
5
5
  SHA512:
6
- metadata.gz: 95e1213e6586ea162e2a12294b350d4ea5190c8f09239e276fe4de17ceb1a7787c0c4979e3e71c6acb0f8e318facea099820a221130b123549d8a123c13e62b7
7
- data.tar.gz: 1cca33e3af240a7abf5b8627d69256ee43647557fc2aeeab4f74692c7ba08ff74a0b0a5cdef202796f4559cc04d0498138762003fd14845c61029bd0b7603231
6
+ metadata.gz: e3217709874457c652fcb20b994d134ea7056f58112e07525c4162597bb6d932b87896988ab0eb64a133d548433ab0a48b9d043dd39e2e1aee944fafa247cc73
7
+ data.tar.gz: f92516a4af7caeb5909fe3ed66b55b50a0d273e982ee371e8a32620c9e599573d2ee86958bd9db78f5f8a0e6e4b105d944b9467a85ea0b5e7b62c4b5630e03e0
data/CHANGELOG.md CHANGED
@@ -2,23 +2,110 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ ## 0.2.5 - 2026-11-26
6
+
7
+ Adds built-in **Antigravity CLI (`agy`)** and **Muse Code (`muse`)** providers alongside OpenCode 2.x compatibility and sharper provider error and environment handling. All changes are additive and backwards-compatible with `~> 0.2.0` consumers.
8
+
9
+ ### New providers
10
+
11
+ - **Antigravity CLI (`:agy`)**: Seventh built-in provider, appended after `:muse` without changing existing provider ordering. Compiles headless print mode (`agy --input-format=text --dangerously-skip-permissions --output-format stream-json`) over piped stdin so large prompts stay out of `argv`, with repeatable `--add-dir`, `--model`, and `--effort` flags. Includes binary-safe OAuth token probing (`~/.gemini/antigravity-cli/antigravity-oauth-token`), `step_update`/`result` usage extraction (`input_tokens`, `output_tokens`, `thinking_tokens` as `reasoning`, `cache_read_tokens` as `cache_read`, `output_includes_reasoning: true`), and non-`SUCCESS` `result` error extraction. Scoped `read-only` / `workspace-write` flags fail closed.
12
+ - **Muse Code (`:muse`)**: Sixth built-in provider, appended after `:opencode`. Compiles `muse exec --prompt-file=/dev/stdin --json` with tempfile-backed stdin, model and reasoning-effort pinning, sandboxed `workspace-write` and `read-only` modes, `run.usage` per-model token aggregation, `run.terminal` error extraction, and XDG config/data resolution. Adds three reusable profile hooks: dual-form version parsing (when one numeric core appears twice, e.g. `1.4.14 (1.4.14-R7309.1)`), `configuration_directory_probe`, and `prompt_argument`.
13
+
14
+ ### Provider compatibility & error handling
15
+
16
+ - **OpenCode 2.x private servers (`--standalone`)**: The route probe detects `--standalone` from `run --help`, records `:private_server` capability evidence, and threads the flag through `auth list`, `models`, prepared `run`, and sanitized `export` so isolated runs do not collide with OpenCode 2.x's shared background server. OpenCode 1.x is unchanged.
17
+ - **OpenCode 2.x flattened error payloads**: Parses both OpenCode 1.x nested (`error.name` + `error.data.message`) and 2.x flattened (`error.type` + `error.message` + `error.status`) error events, including pre-session errors without a `sessionID`, so upstream rate limits surface as typed `rate_limited` errors instead of `MalformedOutput`.
18
+ - **Claude quota window events**: Extracts Claude's message-free rejected `rate_limit_event` for `five_hour` and `seven_day` account windows as a typed `provider_limit` with bounded quota text.
19
+ - **Codex transport retry filtering**: Skips `Reconnecting... n/m` progress notices in provider error extraction so transient reconnect lines do not mask the terminal error (such as a `401` from a revoked login), and parses `unexpected status NNN` HTTP status codes.
20
+
21
+ ### Isolation & security
22
+
23
+ - **OpenCode probe & overlay environment hardening**: `ProbeRequest` restricts environment overrides to `OPENCODE_OVERLAY_ENVIRONMENT_KEYS` and scrubs Ruby/Bundler injection variables (`RUBYOPT`, `RUBYLIB`, `GEM_HOME`, `GEM_PATH`, `BUNDLE_BIN_PATH`, `BUNDLE_GEMFILE`) last; both `ProbeRequest` and `OpenCodePreparationRequest` reject credential keys overlapping `SCRUBBED_RUNTIME_ENVIRONMENT_KEYS`.
24
+
25
+ ## 0.2.4 - 2026-08-25
26
+
27
+ - Expose the OpenCode permission compiler independently from the prepared
28
+ overlay so callers can supply the same deny-first rules through native
29
+ per-process configuration without duplicating policy generation.
30
+
31
+ - Carry the already-resolved OpenCode executable on `ProbeRequest` (`executable:`)
32
+ instead of re-encoding it as the `AGENT_CLI_RUNTIME_OPENCODE_BIN` environment
33
+ override. The route-aware probe now resolves the executable once — honoring a
34
+ caller-supplied value first — and threads that single value through the
35
+ installation check, version check, every local inspection command, and the
36
+ reported result executable. `Profile#binary_installed?`,
37
+ `Profile#check_version!`, and `Profile#capture_local` accept an optional
38
+ `executable:` override; existing environment-based resolution is unchanged
39
+ when no explicit value is carried.
40
+
41
+ ## 0.2.3 - 2026-08-21
42
+
43
+ - Classify extracted provider failures once at the runtime boundary as
44
+ `provider_limit`, `rate_limited`, `model_output_limit`, or `provider_error`.
45
+ HTTP 402/429 payloads are authoritative even when their provider-specific
46
+ wording does not match an orchestrator's legacy quota phrases.
47
+
48
+ ## 0.2.2 - 2026-08-18
49
+
50
+ - Deliver built-in Pi prompts through its native non-TTY stdin reader instead
51
+ of one positional argv element. This prevents implementation-sized prompts
52
+ from failing at process spawn with the operating system's per-argument
53
+ `E2BIG` limit; Codex retains its separate stdin-plus-`-` transport.
54
+ - Treat Pi's `stopReason: "length"` as a typed `model_output_limit` failure.
55
+ Pi exits zero after this provider stop even when the model exhausted its
56
+ output allowance before writing the requested artifact; callers can now
57
+ distinguish that incomplete turn from an agent that silently produced
58
+ 0 bytes and tell operators to raise `maxTokens` or lower reasoning effort.
59
+ - Declare Grok's filesystem sandbox flags, so a caller asking for confined
60
+ execution gets it instead of being told Grok cannot confine. `--sandbox
61
+ workspace` limits writes to the working directory and `--sandbox read-only`
62
+ forbids them, both built-in profiles that custom ones extend from
63
+ `~/.grok/sandbox.toml`; `--always-approve` suppresses the approval prompt a
64
+ headless run can never answer, leaving the sandbox — not the prompt — as the
65
+ boundary. Only the Grok profile changes.
66
+
67
+ ## 0.2.1 - 2026-08-17
68
+
69
+ - Add per-profile provider-error extraction so a refusal a CLI reports on its
70
+ event stream is distinguishable from an agent that genuinely produced
71
+ nothing. `extract_provider_error` returns the provider, the HTTP status when
72
+ the provider supplied one, and the redacted provider text.
73
+ - Add the `pi` extractor for turns that keep the envelope type and carry the
74
+ refusal in `stopReason`/`errorMessage`, which no event-type match observes.
75
+ Such turns previously reached the caller as a clean run with empty content
76
+ while the process exited zero.
77
+ - Default every other profile to the previously assumed shapes — dedicated
78
+ `error`, `turn.failed`, and `rate_limit_event` events plus failed `result`
79
+ events — so no existing profile changes behaviour.
80
+ - Read usage from the assistant message and accept the bare
81
+ `input`/`output`/`cacheRead`/`cacheWrite` spellings, so a provider reporting
82
+ usage there is metered instead of silently recording nothing. The bare
83
+ spellings are matched last, leaving a provider that reports explicit
84
+ `*_tokens` keys with its existing reading.
85
+
5
86
  ## 0.2.0 - 2026-08-15
6
87
 
7
- - Add OpenCode `1.18.16+` as a fifth immutable built-in profile with exact
8
- `provider/model` routing and faithful model-variant validation.
9
- - Add route-aware offline probing for the required run/export flags, selected
10
- authentication source, cached model inventory, and exact requested route.
11
- - Add invocation-owned OpenCode config/data/cache/state overlays with
12
- deny-first `read-only` and `workspace-write` policies, explicit credential
13
- forwarding, owner-private resources, and idempotent cleanup.
14
- - Add strict run/export correlation and typed outcomes for completion,
15
- authentication/configuration/CLI failure, malformed output, cancellation,
16
- and timeout while preserving requested versus actual route identity.
17
- - Preserve unavailable separately from numeric zero for input, output,
18
- cache-read, cache-write, reasoning, and cost evidence.
19
- - Keep process spawning, streaming, timeout/cancellation supervision,
20
- process-tree cleanup, retries, and post-run inspection execution with the
21
- caller; the component returns commands and normalizes captured evidence.
88
+ - Add first-class OpenCode `1.18.16+` support alongside the built-in Claude
89
+ Code, Codex CLI, Pi, and Grok CLI profiles. OpenCode uses the shared request
90
+ and facade, then adds provider-specific preparation, route probing, and
91
+ strict result normalization.
92
+ - Route every OpenCode run to an exact `provider/model` and validate model
93
+ variants, preserving the route the application requested and the route the
94
+ captured result reports.
95
+ - Prepare owner-private OpenCode config, data, cache, and state overlays for
96
+ each invocation, with scoped `read-only` and `workspace-write` policies,
97
+ deliberate credential forwarding, and idempotent cleanup.
98
+ - Check run/export capabilities, selected authentication source, cached model
99
+ inventory, and the exact requested route locally before an application
100
+ starts work.
101
+ - Correlate run and sanitized-export evidence into typed outcomes for
102
+ completion, authentication, configuration, CLI failure, malformed output,
103
+ cancellation, and timeout.
104
+ - Report input, output, cache-read, cache-write, reasoning, and cost evidence
105
+ while preserving the difference between unavailable data and numeric zero.
106
+ - Return prepared commands and normalized evidence through lifecycle-safe
107
+ values that fit an application's existing streaming, timeout, cancellation,
108
+ retry, and process-supervision stack.
22
109
 
23
110
  ## 0.1.1 - 2026-08-11
24
111
 
data/README.md CHANGED
@@ -1,12 +1,31 @@
1
1
  # Agent CLI Runtime
2
2
 
3
- `agent-cli-runtime` is a small Ruby library for tools that integrate with
4
- locally installed headless agent CLIs. It ships immutable profiles for Claude
5
- Code, Codex CLI, Pi, Grok CLI, and OpenCode and compiles provider-neutral
6
- requests into argv/stdin. It also reports typed capability evidence, extracts
7
- usage from provider JSON events, and exposes an honest local diagnostic
8
- command. OpenCode adds an invocation-owned overlay and strict captured-result
9
- normalizer while leaving process supervision with the caller.
3
+ Agent CLI Runtime gives Ruby applications one stable integration layer for
4
+ Claude Code, Codex CLI, Pi, Grok CLI, OpenCode, Muse Code, and Antigravity CLI. It builds provider-specific
5
+ commands from a shared request model, checks local versions and named
6
+ capabilities, and normalizes usage and results afterward. Centralized profiles,
7
+ environment rules, and parsers make agent providers easier to add, switch, and
8
+ upgrade.
9
+
10
+ Version 0.2.0 adds first-class OpenCode support with exact `provider/model`
11
+ routing, isolated per-invocation configuration, scoped permission policies,
12
+ offline readiness checks, and typed outcome normalization. See the
13
+ [changelog](CHANGELOG.md) for the complete release notes.
14
+
15
+ ## Why use it?
16
+
17
+ Agent CLIs disagree on flags, prompt transport, configuration locations,
18
+ permission controls, usage events, and result formats. Agent CLI Runtime keeps
19
+ those differences in versioned profiles so application code can use one
20
+ request and result vocabulary.
21
+
22
+ - Add or switch agent CLIs without spreading provider conditionals throughout
23
+ the application.
24
+ - Validate installed versions, capabilities, and exact routes before starting
25
+ work.
26
+ - Preserve typed usage and outcome evidence across provider-specific output
27
+ formats.
28
+ - Add custom profiles through the same immutable compatibility contract.
10
29
 
11
30
  ## Install
12
31
 
@@ -41,6 +60,11 @@ Compilation does not execute the returned command. Unsupported requested
41
60
  controls raise `AgentCliRuntime::UnsupportedCapability` with typed evidence
42
61
  instead of silently widening the request.
43
62
 
63
+ Prompt transport is profile-owned. `:stdin` writes the prompt to stdin and
64
+ adds the CLI's conventional `-` argv marker; `:piped_stdin` writes the prompt
65
+ to stdin without a marker for CLIs such as Pi that consume a non-TTY stream
66
+ directly. Built-in Pi therefore keeps arbitrarily large prompts out of argv.
67
+
44
68
  `permission_mode: nil` selects the profile's default non-interactive permission
45
69
  flags, which may include a provider's bypass flag. Pass `"read-only"` or
46
70
  `"workspace-write"` explicitly when the integration requires that constraint.
@@ -58,12 +82,14 @@ represent.
58
82
  - `extract_usage(profile, event)` normalizes provider usage when present and
59
83
  returns `nil` when usage is absent or malformed.
60
84
  - `observe(profile, result)` normalizes bounded, redacted result metadata.
61
- - `prepare!(open_code_preparation)` creates and probes an isolated OpenCode
62
- overlay and returns a `PreparedInvocation`; it does not spawn OpenCode.
85
+ - `prepare!(open_code_preparation)` returns a `PreparedInvocation` containing
86
+ an isolated OpenCode overlay, argv, and child environment.
87
+ - `OpenCode::Permissions.compile(...)` returns the same deny-first permission
88
+ document independently for callers that retain native OpenCode state.
63
89
  - `parse_run(profile, stdout:)` parses a successful OpenCode JSONL capture
64
90
  into the session and terminal-message identity required for inspection.
65
- - `prepare_inspection(prepared, parsed_run)` compiles the non-model sanitized
66
- session-export command without executing it.
91
+ - `prepare_inspection(prepared, parsed_run)` returns the non-model sanitized
92
+ session-export invocation.
67
93
  - `normalize(profile, captured, requested_route:)` returns one typed OpenCode
68
94
  outcome from caller-captured run, termination, and inspection evidence.
69
95
 
@@ -125,6 +151,11 @@ read-only configuration source. Configuration may define providers and an
125
151
  exact default model, but it must not contain credential values. Name the
126
152
  credential environment variables the caller is allowed to forward instead.
127
153
 
154
+ Callers that deliberately retain native OpenCode config and login can use
155
+ `OpenCode::Permissions.compile` directly and pass the JSON document through
156
+ OpenCode's per-process permission input. The prepared-overlay API below
157
+ remains the closed, isolated option.
158
+
128
159
  ```ruby
129
160
  require "agent_cli_runtime"
130
161
  require "tmpdir"
@@ -150,7 +181,8 @@ preparation = AgentCliRuntime::OpenCodePreparationRequest.new(
150
181
  },
151
182
  credential_environment_keys: ["ANTHROPIC_API_KEY"],
152
183
  additional_read_roots: [Dir.pwd],
153
- additional_write_roots: [Dir.pwd]
184
+ additional_write_roots: [Dir.pwd],
185
+ bash_patterns: ["git*", "bundle*", "bin/*"]
154
186
  )
155
187
 
156
188
  prepared = AgentCliRuntime.prepare!(preparation)
@@ -198,8 +230,10 @@ to call twice. Call it from the process owner's `ensure` path after every
198
230
  pre-spawn and post-spawn outcome.
199
231
 
200
232
  `read-only` denies edits, shell, unsafe tools, and external writes.
201
- `workspace-write` permits edits only under the declared write roots and still
202
- denies unrestricted shell. A `nil` permission mode is rejected unless the
233
+ `workspace-write` permits edits only under the declared write roots. Shell is
234
+ denied unless the caller supplies explicit OpenCode `bash_patterns`; those
235
+ patterns are application permissions, not an OS sandbox. A `nil` permission
236
+ mode is rejected unless the
203
237
  consumer supplies an explicit typed `OpenCodePermissionPolicy`; the ordinary
204
238
  preparation API never silently falls back to a bypass. Plugin sources are
205
239
  explicit, and `--pure` remains enabled when no plugin was selected.
@@ -218,10 +252,12 @@ model request:
218
252
  bundle exec ruby -Itest test/opencode_offline_smoke_test.rb
219
253
  ```
220
254
 
221
- If an installation command is itself a package-manager shim, set
222
- `AGENT_CLI_RUNTIME_OPENCODE_OFFLINE_BIN` to the already-installed native
223
- OpenCode executable so the smoke cannot trigger shim installation or refresh
224
- behavior.
255
+ Auto-discovery considers every matching executable in `PATH` and prefers an
256
+ already-installed native executable over an earlier package-manager launcher,
257
+ including script and multicall-binary shims, so the
258
+ smoke cannot trigger package-manager installation or refresh behavior. If only
259
+ a shim is discoverable, set `AGENT_CLI_RUNTIME_OPENCODE_OFFLINE_BIN` to the
260
+ native OpenCode executable explicitly.
225
261
 
226
262
  The authenticated atomic-edit smoke is separately gated and refuses to run
227
263
  without an explicit route, config path, credential variable name, opt-in, and
@@ -5,13 +5,14 @@ Gem::Specification.new do |spec|
5
5
  spec.version = AgentCliRuntime::VERSION
6
6
  spec.authors = [ "Ivan Kuznetsov" ]
7
7
  spec.email = [ "ivan@ikuznetsov.com" ]
8
- spec.summary = "Provider-neutral contracts for installed agent CLIs"
8
+ spec.summary =
9
+ "One Ruby API for Claude Code, Codex CLI, Pi, Grok CLI, OpenCode, Muse Code, and Antigravity CLI"
9
10
  spec.description = <<~DESC
10
- Agent CLI Runtime provides immutable profiles, invocation compilation,
11
- local prerequisite probes, capability evidence, usage extraction, and
12
- result normalization for Claude Code, Codex CLI, Pi, Grok CLI, and
13
- OpenCode. It does not spawn agents or claim live provider health, quota,
14
- or credential validity.
11
+ Agent CLI Runtime gives Ruby applications one stable integration layer for
12
+ local coding-agent CLIs. It builds provider-specific commands from a shared
13
+ request model, checks local versions and named capabilities, and normalizes
14
+ usage and results afterward. Centralized profiles, environment rules, and
15
+ parsers make agent providers easier to add, switch, and upgrade.
15
16
  DESC
16
17
  spec.homepage = "https://github.com/ivankuznetsov/agent-cli-runtime"
17
18
  spec.license = "MIT"
@@ -42,7 +43,7 @@ Gem::Specification.new do |spec|
42
43
  spec.executables = [ "agent-runtime" ]
43
44
  spec.require_paths = [ "lib" ]
44
45
 
45
- spec.add_dependency "json", ">= 2.7", "< 3.0"
46
+ spec.add_dependency "json", ">= 2.7", "< 4.0"
46
47
  spec.add_dependency "open3", "~> 0.2"
47
48
  spec.add_dependency "timeout", ">= 0.4", "< 1.0"
48
49
  end
@@ -0,0 +1,154 @@
1
+ module AgentCliRuntime
2
+ # Provider-side failures that a CLI reports on its event stream while still
3
+ # exiting zero. Each profile owns the shape its own CLI emits. Extractors
4
+ # return either the raw provider text, an ExtractedFailure, or nil when the
5
+ # event carries no failure. Runtime.extract_provider_error normalizes and
6
+ # redacts the result.
7
+ module ErrorExtractors
8
+ module_function
9
+
10
+ # CLIs that name the failure with a dedicated event type. This is the same
11
+ # set Hive scanned for inline before provider shape moved behind the
12
+ # profile, so wiring a profile to DEFAULT preserves its behaviour.
13
+ DEFAULT = lambda do |event|
14
+ next nil unless event.is_a?(Hash)
15
+
16
+ case event["type"]
17
+ when "error", "turn.failed", "rate_limit_event"
18
+ ErrorExtractors.message_from(event)
19
+ when "result"
20
+ if event["is_error"] == true || event["subtype"].to_s.start_with?("error")
21
+ ErrorExtractors.message_from(event)
22
+ end
23
+ end
24
+ end
25
+
26
+ # Claude's subscription wall is a dedicated structured event with no
27
+ # human-readable message. The generic extractor therefore returned nil,
28
+ # leaving callers to flatten a rejected five-hour/seven-day window into a
29
+ # generic exit-code failure. Accept only the exact rejected account-window
30
+ # shapes observed from Claude Code and synthesize bounded provider text for
31
+ # the normal typed limit path. Other Claude errors retain DEFAULT behavior.
32
+ CLAUDE_ACCOUNT_LIMIT_TYPES = %w[five_hour seven_day].freeze
33
+ CLAUDE = lambda do |event|
34
+ if event.is_a?(Hash) && event["type"] == "rate_limit_event"
35
+ info = event["rate_limit_info"]
36
+ if info.is_a?(Hash) && info["status"] == "rejected"
37
+ limit_type = info["rateLimitType"].to_s
38
+ if CLAUDE_ACCOUNT_LIMIT_TYPES.include?(limit_type)
39
+ next ExtractedFailure.new(
40
+ kind: :provider_limit,
41
+ message: "Claude account quota reached (#{limit_type})"
42
+ )
43
+ end
44
+ end
45
+ end
46
+
47
+ DEFAULT.call(event)
48
+ end
49
+
50
+ # Codex reports each transport retry as its own "error" event
51
+ # ("Reconnecting... 2/5 (stream disconnected ...)") before the terminal
52
+ # error and turn.failed. Callers keep the first provider error, so a
53
+ # retry notice used to mask the real failure (for example a 401 from a
54
+ # revoked login). Retry notices are progress, not the failure.
55
+ CODEX_RETRY_NOTICE = /\AReconnecting\.\.\.\s*\d+\s*\/\s*\d+\b/
56
+ CODEX = lambda do |event|
57
+ text = DEFAULT.call(event)
58
+ next nil if text.is_a?(String) && text.match?(CODEX_RETRY_NOTICE)
59
+
60
+ text
61
+ end
62
+
63
+ # pi keeps the envelope type ("message_start"/"message_end") and moves the
64
+ # terminal state into stopReason. Provider refusals use
65
+ # stopReason=error/errorMessage. A model that consumes its entire output
66
+ # allowance uses stopReason=length and can exit zero without executing the
67
+ # final write tool. Matching on type alone sees neither failure.
68
+ PI = lambda do |event|
69
+ next nil unless event.is_a?(Hash)
70
+
71
+ message = event["message"].is_a?(Hash) ? event["message"] : event
72
+ case message["stopReason"].to_s
73
+ when "error"
74
+ ErrorExtractors.message_from(message) || ErrorExtractors.message_from(event)
75
+ when "length"
76
+ ExtractedFailure.new(
77
+ kind: :model_output_limit,
78
+ message: "model response reached its maximum output tokens"
79
+ )
80
+ end
81
+ end
82
+
83
+ # OpenCode 1.x keeps provider failures under error.data.message; 2.x
84
+ # flattens them to error.message (with error.type and error.status).
85
+ # Read only the dedicated error event so ordinary model text cannot forge
86
+ # a provider-limit signal.
87
+ OPENCODE = lambda do |event|
88
+ next nil unless event.is_a?(Hash) && event["type"] == "error"
89
+
90
+ ErrorExtractors.opencode_error_message(event["error"])
91
+ end
92
+
93
+ # Muse terminates every headless run with one `run.terminal.*` event.
94
+ # Only that run-level terminal is authoritative: `task.lifecycle.failed`
95
+ # also fires for internal reminder children on otherwise successful
96
+ # runs, so task-level failures must never become provider errors.
97
+ MUSE = lambda do |event|
98
+ next nil unless event.is_a?(Hash)
99
+ next nil unless event["payload_type"].to_s.start_with?("run.terminal.")
100
+
101
+ payload = event["payload"]
102
+ next nil unless payload.is_a?(Hash)
103
+
104
+ terminal = payload["terminal"].to_s
105
+ next nil if terminal.empty? || terminal == "completed"
106
+
107
+ reason = payload["reason"].to_s.strip
108
+ reason.empty? ? "muse run #{terminal}" : reason
109
+ end
110
+
111
+ # Antigravity CLI (`agy`) terminates every stream-json run with an
112
+ # `{"event":"result","result":{...}}` envelope. Non-SUCCESS statuses
113
+ # (`ERROR`, `CANCELED`, etc.) carry the provider/CLI diagnostic in
114
+ # `result.error`.
115
+ AGY = lambda do |event|
116
+ next nil unless event.is_a?(Hash)
117
+
118
+ case event["event"]
119
+ when "result"
120
+ result = event["result"]
121
+ next nil unless result.is_a?(Hash)
122
+
123
+ status = result["status"].to_s.upcase
124
+ next nil if status.empty? || status == "SUCCESS"
125
+
126
+ message = result["error"].to_s.strip
127
+ message.empty? ? "agy run #{status.downcase}" : message
128
+ when "error"
129
+ ErrorExtractors.message_from(event)
130
+ end
131
+ end
132
+
133
+ def opencode_error_message(error)
134
+ return nil unless error.is_a?(Hash)
135
+
136
+ data = error["data"]
137
+ message = data.is_a?(Hash) ? data["message"] : error["message"]
138
+ message if message.is_a?(String) && !message.strip.empty?
139
+ end
140
+
141
+ def message_from(event)
142
+ return nil unless event.is_a?(Hash)
143
+
144
+ candidates = [
145
+ event["errorMessage"],
146
+ event["message"],
147
+ event.dig("error", "message"),
148
+ event["error"]
149
+ ]
150
+ text = candidates.find { |value| value.is_a?(String) && !value.strip.empty? }
151
+ text&.strip
152
+ end
153
+ end
154
+ end
@@ -16,9 +16,15 @@ module AgentCliRuntime
16
16
  "sanitized export inspection requires an OpenCode invocation"
17
17
  end
18
18
 
19
+ # Export through a private server exactly when the run used one: both
20
+ # read the same overlay data home, and neither may attach to (or
21
+ # start) the shared background service.
22
+ server_arguments =
23
+ OpenCode::Probe.supported_arguments(prepared.invocation, :private_server)
19
24
  InspectionCommand.new(
20
25
  argv: [
21
- prepared.executable, "export", parsed_run.session_id, "--sanitize"
26
+ prepared.executable, "export", parsed_run.session_id, "--sanitize",
27
+ *server_arguments
22
28
  ],
23
29
  stdin_data: nil,
24
30
  environment: prepared.environment,