@jini-ai/agent-runtime 0.4.11 → 0.6.10

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.
Files changed (111) hide show
  1. package/CHANGELOG.md +83 -1
  2. package/dist/acp-model-probe.d.ts +2 -20
  3. package/dist/agent-protocol/acp/json.js +46 -37
  4. package/dist/agent-protocol/acp/models.js +91 -73
  5. package/dist/agent-protocol/acp/rpc.d.ts +3 -2
  6. package/dist/agent-protocol/acp/rpc.js +3 -2
  7. package/dist/agent-protocol/acp/session-params.d.ts +1 -1
  8. package/dist/agent-protocol/acp/session-params.js +33 -30
  9. package/dist/agent-protocol/acp/session.d.ts +3 -1
  10. package/dist/agent-protocol/acp/session.js +62 -24
  11. package/dist/agent-protocol/acp/updates.js +49 -35
  12. package/dist/agent-protocol/pi-rpc/session.js +3 -1
  13. package/dist/anthropic-live-models.d.ts +12 -4
  14. package/dist/anthropic-live-models.js +0 -0
  15. package/dist/auth.js +84 -91
  16. package/dist/claude-code-models.d.ts +6 -5
  17. package/dist/claude-code-models.js +19 -12
  18. package/dist/claude-segment-usage.d.ts +3 -3
  19. package/dist/claude-segment-usage.js +63 -29
  20. package/dist/claude-stream.d.ts +2 -0
  21. package/dist/claude-stream.js +16 -5
  22. package/dist/copilot-stream.js +42 -50
  23. package/dist/defs/aider.js +3 -4
  24. package/dist/defs/amr.js +52 -61
  25. package/dist/defs/antigravity.d.ts +6 -5
  26. package/dist/defs/antigravity.js +48 -34
  27. package/dist/defs/auggie.d.ts +1 -1
  28. package/dist/defs/claude-compatible-args.d.ts +19 -0
  29. package/dist/defs/claude-compatible-args.js +42 -0
  30. package/dist/defs/claude.d.ts +7 -2
  31. package/dist/defs/claude.js +96 -85
  32. package/dist/defs/cline.d.ts +1 -1
  33. package/dist/defs/codebuddy.d.ts +1 -1
  34. package/dist/defs/codebuddy.js +29 -46
  35. package/dist/defs/codex.d.ts +15 -3
  36. package/dist/defs/codex.js +143 -108
  37. package/dist/defs/cursor-agent.d.ts +9 -7
  38. package/dist/defs/cursor-agent.js +53 -51
  39. package/dist/defs/devin.d.ts +1 -1
  40. package/dist/defs/goose.d.ts +1 -1
  41. package/dist/defs/hermes.d.ts +1 -1
  42. package/dist/defs/kilo.d.ts +1 -1
  43. package/dist/defs/kimi.d.ts +1 -1
  44. package/dist/defs/kiro.d.ts +1 -1
  45. package/dist/defs/opencode.d.ts +5 -4
  46. package/dist/defs/opencode.js +26 -32
  47. package/dist/defs/pi.d.ts +6 -5
  48. package/dist/defs/pi.js +24 -26
  49. package/dist/defs/qoder.d.ts +4 -3
  50. package/dist/defs/qoder.js +25 -25
  51. package/dist/defs/reasonix.d.ts +1 -1
  52. package/dist/defs/shared.d.ts +12 -3
  53. package/dist/defs/shared.js +19 -13
  54. package/dist/defs/trae-cli.d.ts +1 -1
  55. package/dist/defs/vibe.d.ts +1 -1
  56. package/dist/detection.d.ts +13 -20
  57. package/dist/detection.js +129 -111
  58. package/dist/env.js +56 -41
  59. package/dist/executables.js +103 -114
  60. package/dist/index.d.ts +1 -0
  61. package/dist/index.js +1 -0
  62. package/dist/json-event-stream.js +611 -527
  63. package/dist/launch.js +44 -37
  64. package/dist/model-discovery-adapters.d.ts +17 -0
  65. package/dist/model-discovery-adapters.js +223 -164
  66. package/dist/model-discovery-config.js +107 -87
  67. package/dist/model-discovery-sdk.d.ts +16 -2
  68. package/dist/model-discovery-sdk.js +4 -3
  69. package/dist/model-discovery-shared.d.ts +14 -0
  70. package/dist/model-discovery-shared.js +50 -15
  71. package/dist/model-discovery-types.d.ts +2 -0
  72. package/dist/model-discovery.js +219 -117
  73. package/dist/models.d.ts +14 -1
  74. package/dist/models.js +75 -19
  75. package/dist/native-tool-policy.d.ts +29 -0
  76. package/dist/native-tool-policy.js +36 -0
  77. package/dist/opencode-log.js +46 -30
  78. package/dist/paths.d.ts +2 -0
  79. package/dist/paths.js +3 -3
  80. package/dist/providers/aihubmix.js +13 -18
  81. package/dist/providers/anthropic-messages.d.ts +7 -0
  82. package/dist/providers/anthropic-messages.js +45 -21
  83. package/dist/providers/azure-chat.d.ts +5 -0
  84. package/dist/providers/azure-chat.js +13 -5
  85. package/dist/providers/connection-guard.d.ts +2 -45
  86. package/dist/providers/connection-guard.js +11 -10
  87. package/dist/providers/connection-test.d.ts +4 -0
  88. package/dist/providers/connection-test.js +127 -110
  89. package/dist/providers/elevenlabs.js +4 -1
  90. package/dist/providers/google-messages.d.ts +4 -0
  91. package/dist/providers/google-messages.js +48 -23
  92. package/dist/providers/google-schema.js +17 -23
  93. package/dist/providers/model-catalog.js +160 -145
  94. package/dist/providers/oauth-callback-server.js +37 -34
  95. package/dist/providers/oauth-credentials.js +23 -23
  96. package/dist/providers/oauth-tokens.js +16 -24
  97. package/dist/providers/openai-chat.d.ts +42 -0
  98. package/dist/providers/openai-chat.js +80 -10
  99. package/dist/providers/operation-schema.d.ts +25 -0
  100. package/dist/providers/operation-schema.js +226 -0
  101. package/dist/providers/response-text.d.ts +10 -0
  102. package/dist/providers/response-text.js +23 -0
  103. package/dist/providers/tool-turn-types.d.ts +56 -9
  104. package/dist/providers/tool-turn.d.ts +7 -0
  105. package/dist/providers/tool-turn.js +120 -32
  106. package/dist/qoder-stream.js +93 -80
  107. package/dist/registry.d.ts +45 -0
  108. package/dist/registry.js +39 -0
  109. package/dist/runtime-state.d.ts +1 -1
  110. package/dist/types.d.ts +43 -1
  111. package/package.json +19 -14
package/CHANGELOG.md CHANGED
@@ -1,3 +1,86 @@
1
+ ## 0.6.10
2
+
3
+ ### Patch Changes
4
+
5
+ - 3fe4d14: Parse optional delegated-result markers while preserving the CLI call id and original content for daemon validation.
6
+
7
+ Require the co-released protocol package at runtime for its shared marker codec, replacing the optional protocol peer. The workspace dependency follows the protocol release version when Changesets versions the release set.
8
+
9
+ - aad3d2e: Add the optional `onUnexposedToolCall` refusal hook to `runProviderToolTurn` for all four
10
+ provider protocols. Hosts can await audit writes and supply uniform refusal text without
11
+ calling the normal tool executor. Results remain errors; omitted hooks and `undefined`
12
+ replies preserve the existing refusal text and protocol formatting. Hook failures propagate
13
+ without falling through to execution.
14
+ - 8ff5653: Drive Antigravity (`agy`) — the 24th and last agent definition `AgentExecutor` rejected.
15
+
16
+ `AgentExecutor` drove 23 of 24 registered definitions. Antigravity was rejected by an explicit
17
+ `def.id === 'antigravity'` guard, for two reasons that are real but narrow:
18
+
19
+ - **`agy` can print an OAuth sign-in URL to stdout and still exit 0.** Streaming stdout live shows
20
+ that URL to the user as if it were the model's reply — a URL that carries the daemon operator's
21
+ `client_id`/`redirect_uri` into a chat transcript, and that is useless to click anyway (`agy -p`
22
+ print mode has no field to paste the resulting auth code into).
23
+ - **`agy` has no `--model` flag.** The model choice is written into one process-global
24
+ `~/.gemini/antigravity-cli/settings.json` that `agy` reads on its own startup, so two concurrent
25
+ runs race: run A writes model A, A spawns, B writes model B, and only _then_ does A's `agy` read
26
+ the file — so A silently executes on B's model.
27
+
28
+ Both are now met by **declarative `RuntimeAgentDef` fields the executor reads generically**, joining
29
+ the 14 optional behavior flags (`promptViaFile`, `authProbe`, …) that already work this way. There is
30
+ no agent-id branch anywhere in the dispatch path — a deliberate divergence from Open Design's own
31
+ daemon, which hardcodes the id twice.
32
+
33
+ New on `@jini-ai/agent-runtime`'s `RuntimeAgentDef`:
34
+
35
+ - `needsAgentLogFile?: boolean` — asks the caller to stage a temp path and pass it as
36
+ `RuntimeContext.agentLogFilePath` before `buildArgs` runs, mirroring `promptViaFile`. Staged by the
37
+ new `prepareAgentLogFile(def, label)` (the sibling of `preparePromptFileForAgent`; it creates only
38
+ the `0o700` containing directory, since the log file is output the CLI authors, not input we do).
39
+ - `stdoutPolicy?: RuntimeStdoutPolicy` — `{buffering: 'live'}` (the default, and every other
40
+ definition's behavior) or `{buffering: 'until-close', sanitize?}`. A discriminated union rather
41
+ than two flat fields on purpose: a sanitizer is only meaningful on the buffered path, because the
42
+ pattern to redact can straddle two `'data'` chunks. Two independent flags would let a definition
43
+ declare a sanitizer the caller could not honor — a confidentiality gap that _looks_ closed.
44
+ - `runtimeLock?: RuntimeLock` — a mutex around a process-global side effect `buildArgs` performs.
45
+ Acquired before `buildArgs`, released on whichever of `waitForHandoff` settling or process exit
46
+ comes first. Releasing on exit is load-bearing, not a fallback: a watcher that stops polling means
47
+ "I stopped watching", never "the child definitely didn't read the file".
48
+
49
+ All three are stripped from the `DetectedAgent` registry projection. They instruct whoever _spawns_
50
+ the CLI, not whoever lists agents — and two carry closures, which `JSON.stringify` would flatten into
51
+ a misleading `{"buffering":"until-close"}` / `{}` rather than omit.
52
+
53
+ In `@jini-ai/daemon`, `AgentExecutor` now stages a log file when `needsAgentLogFile` is set (released
54
+ on every pre-spawn, spawn-failure, and close path alongside the prompt file, through one composed
55
+ `cleanupStagedFiles` closure), calls `runtimeLock.acquire()` before `buildArgs`, and branches its
56
+ `streamFormat: 'plain'` stdout handling on `stdoutPolicy`. `assessAgentExecutorCompatibility` no
57
+ longer rejects anything by id, and `isAgentExecutorSupported` now accepts all 24 definitions.
58
+
59
+ **No behavior change for any other agent.** Antigravity is the only definition declaring any of the
60
+ three fields; the other four `streamFormat: 'plain'` definitions (`grok-build`, `aider`, `deepseek`,
61
+ `qwen`) keep streaming live, per chunk, which `aider`'s and `deepseek`'s own comments call out as
62
+ deliberate. That is pinned by an explicit regression test rather than left implied.
63
+
64
+ One thing worth knowing if you consume the run event stream: on the buffered path the raw `'stdout'`
65
+ echo is held back and sanitized too, not just the `'agent'`/`text_delta` copy. Emitting an
66
+ unsanitized raw echo while withholding the chat copy would leak the exact string the sanitizer exists
67
+ to remove to any subscriber. The opt-in byte journal still records raw bytes per chunk — that is its
68
+ documented contract, and it deliberately lives in a separate `EventLog` instance that is never
69
+ replayed to run-event subscribers.
70
+
71
+ - e16a907: Add optional adapter-owned usageCostBasis metadata; Claude declares that its reported dollars are cumulative within a session.
72
+ - Updated dependencies [22f0619]
73
+ - Updated dependencies [82ed2d3]
74
+ - Updated dependencies [3fe4d14]
75
+ - Updated dependencies [5a3de86]
76
+ - @jini-ai/core@0.6.10
77
+ - @jini-ai/protocol@0.6.10
78
+ - @jini-ai/oauth@0.6.10
79
+
80
+ ## 0.4.12 — 2026-10-22
81
+
82
+ - 2026-10-22: Probe-gated chromeIntegration build option, declarative supportsSubagents, network-capture and asset-harvest fixes, coverage.
83
+
1
84
  ## 0.4.11 — 2026-10-14
2
85
 
3
86
  - Gemini: `applyGoogleUsage` adds `input_tokens` (`promptTokenCount`) and `output_tokens` (`candidatesTokenCount` + `thoughtsTokenCount`) next to the raw `usageMetadata` fields, so usage reducers show Gemini token counts (024fe7e8).
@@ -63,7 +146,6 @@
63
146
  - Model catalog clocks use core `Clock.nowMs()`; ACP unknown-value records are named `UnknownRecord`, not JSON objects.
64
147
  - Callback payload caches use the main bounded store while retaining exclusive TTL and unref timer behavior. Neutralize host-settings wording and host identity comments. Drop the conversion report from published files; the document remains for later relocation.
65
148
 
66
-
67
149
  - Preserve host environment customization after CLI housekeeping; correct the hook documentation.
68
150
  - Keep DNS resolver injection required and reject lookup failures or empty answers instead of allowing unpinned fallback.
69
151
  - Validate model catalogue variants with an explicit `TypeError` before trimming.
@@ -5,26 +5,8 @@
5
5
  * and null restores native transport. noopAcpModelProbe is an explicit opt-out that returns no
6
6
  * live models, allowing detection to fall back to the def's static catalog.
7
7
  */
8
- import type { RuntimeEnv, RuntimeModelOption } from './types.js';
9
- export interface AcpModelProbeRequest {
10
- bin: string;
11
- args: string[];
12
- cwd?: string;
13
- env?: RuntimeEnv;
14
- timeoutMs?: number;
15
- signal?: AbortSignal;
16
- clientName?: string;
17
- clientVersion?: string;
18
- defaultModelOption?: RuntimeModelOption;
19
- }
20
- export interface AcpModelProbe {
21
- detectModels(requiredArgs: Pick<AcpModelProbeRequest, 'bin' | 'args'>, optionalArgs?: Omit<AcpModelProbeRequest, 'bin' | 'args'>): Promise<RuntimeModelOption[]>;
22
- /** Optional metadata capability preserves a native current selection without guessing from order. */
23
- detectMetadata?(requiredArgs: Pick<AcpModelProbeRequest, 'bin' | 'args'>, optionalArgs?: Omit<AcpModelProbeRequest, 'bin' | 'args'>): Promise<{
24
- models: RuntimeModelOption[];
25
- currentModelId: string | null;
26
- }>;
27
- }
8
+ import type { AcpModelProbe, AcpModelProbeRequest, RuntimeModelOption } from './types.js';
9
+ export type { AcpModelProbeRequest, AcpModelProbe } from './types.js';
28
10
  export declare const noopAcpModelProbe: AcpModelProbe;
29
11
  /** Native adapter selected once by each host composition; independent of the compatibility setter. */
30
12
  export declare const nativeAcpModelProbe: AcpModelProbe;
@@ -85,29 +85,54 @@ export function extractAcpTextValue(value, depth = 0) {
85
85
  return null;
86
86
  if (typeof value === 'string')
87
87
  return value.length > 0 ? value : null;
88
- if (Array.isArray(value)) {
89
- const text = value
90
- .map((item) => extractAcpTextValue(item, depth + 1))
91
- .filter((part) => typeof part === 'string' && part.length > 0)
92
- .join('');
93
- return text.length > 0 ? text : null;
94
- }
88
+ if (Array.isArray(value))
89
+ return joinAcpArrayText({ items: value, depth });
95
90
  const obj = asObject(value);
96
91
  if (!obj)
97
92
  return null;
98
- for (const key of [
99
- 'text',
100
- 'delta',
101
- 'content',
102
- 'message',
103
- 'output',
104
- 'answer',
105
- 'value',
106
- 'body',
107
- 'parts',
108
- 'choices',
109
- ]) {
110
- const text = extractAcpTextValue(obj[key], depth + 1);
93
+ return firstAcpKeyText({ obj, keys: NESTED_TEXT_KEYS, depth: depth + 1 });
94
+ }
95
+ /** Key order `extractAcpTextValue` probes on nested objects. */
96
+ const NESTED_TEXT_KEYS = [
97
+ 'text',
98
+ 'delta',
99
+ 'content',
100
+ 'message',
101
+ 'output',
102
+ 'answer',
103
+ 'value',
104
+ 'body',
105
+ 'parts',
106
+ 'choices',
107
+ ];
108
+ /** Key order `extractAcpUpdateText` probes on the top-level update object
109
+ * (`content` first, unlike the nested order). */
110
+ const UPDATE_TEXT_KEYS = [
111
+ 'content',
112
+ 'text',
113
+ 'delta',
114
+ 'message',
115
+ 'output',
116
+ 'answer',
117
+ 'value',
118
+ 'body',
119
+ 'parts',
120
+ 'choices',
121
+ ];
122
+ /** Concatenates the non-empty text of every array item (one level deeper),
123
+ * or `null` when the joined text is empty. */
124
+ function joinAcpArrayText({ items, depth }) {
125
+ const text = items
126
+ .map((item) => extractAcpTextValue(item, depth + 1))
127
+ .filter((part) => typeof part === 'string' && part.length > 0)
128
+ .join('');
129
+ return text.length > 0 ? text : null;
130
+ }
131
+ /** Returns the first non-empty text found under `keys` of `obj`, traversing
132
+ * each value at `depth`. */
133
+ function firstAcpKeyText({ obj, keys, depth, }) {
134
+ for (const key of keys) {
135
+ const text = extractAcpTextValue(obj[key], depth);
111
136
  if (text)
112
137
  return text;
113
138
  }
@@ -123,22 +148,6 @@ export function extractAcpTextValue(value, depth = 0) {
123
148
  * @returns The first non-empty text string, or `null` when none is present.
124
149
  */
125
150
  export function extractAcpUpdateText(update) {
126
- for (const key of [
127
- 'content',
128
- 'text',
129
- 'delta',
130
- 'message',
131
- 'output',
132
- 'answer',
133
- 'value',
134
- 'body',
135
- 'parts',
136
- 'choices',
137
- ]) {
138
- const text = extractAcpTextValue(update[key]);
139
- if (text)
140
- return text;
141
- }
142
- return null;
151
+ return firstAcpKeyText({ obj: update, keys: UPDATE_TEXT_KEYS, depth: 0 });
143
152
  }
144
153
  //# sourceMappingURL=json.js.map
@@ -55,28 +55,63 @@ export function isModelConfigOption(option, configId) {
55
55
  export function findModelConfigOption(configOptions) {
56
56
  const options = Array.isArray(configOptions) ? configOptions : [];
57
57
  for (const rawOption of options) {
58
- const option = asObject(rawOption);
59
- if (!option)
60
- continue;
61
- const configId = typeof option.id === 'string' ? option.id.trim() : '';
62
- if (!configId)
63
- continue;
64
- const type = typeof option.type === 'string' ? option.type.trim() : '';
65
- if (type && type !== 'select')
66
- continue;
67
- if (!isModelConfigOption(option, configId))
68
- continue;
69
- const currentValue = typeof option.currentValue === 'string' && option.currentValue.trim()
70
- ? option.currentValue.trim()
71
- : null;
72
- return {
73
- configId,
74
- currentValue,
75
- values: Array.isArray(option.options) ? option.options : [],
76
- };
58
+ const parsed = parseModelConfigOption(rawOption);
59
+ if (parsed)
60
+ return parsed;
77
61
  }
78
62
  return null;
79
63
  }
64
+ /** Returns the trimmed string when `value` is a string, else `''`. */
65
+ function trimmedOrEmpty(value) {
66
+ return typeof value === 'string' ? value.trim() : '';
67
+ }
68
+ /** Parses one `configOptions` entry, returning it only when it is a
69
+ * select-type (or untyped) model-selection option with a non-blank id. */
70
+ function parseModelConfigOption(rawOption) {
71
+ const option = asObject(rawOption);
72
+ if (!option)
73
+ return null;
74
+ const configId = trimmedOrEmpty(option.id);
75
+ if (!configId)
76
+ return null;
77
+ const type = trimmedOrEmpty(option.type);
78
+ if (type && type !== 'select')
79
+ return null;
80
+ if (!isModelConfigOption(option, configId))
81
+ return null;
82
+ return {
83
+ configId,
84
+ currentValue: trimmedOrEmpty(option.currentValue) || null,
85
+ values: Array.isArray(option.options) ? option.options : [],
86
+ };
87
+ }
88
+ /** Builds the deduplicated option list: `defaultModelOption` first, then each
89
+ * entry with a non-blank unseen id, labelled `name (id)` when a distinct name
90
+ * exists and suffixed ` • current` for `currentId`. */
91
+ function buildModelOptions({ defaultModelOption, currentId, entries, }) {
92
+ const seen = new Set([defaultModelOption.id]);
93
+ const out = [defaultModelOption];
94
+ for (const { id, name } of entries) {
95
+ if (!id || seen.has(id))
96
+ continue;
97
+ seen.add(id);
98
+ const labelBase = name && name !== id ? `${name} (${id})` : id;
99
+ out.push({ id, label: id === currentId ? `${labelBase} • current` : labelBase });
100
+ }
101
+ return out;
102
+ }
103
+ /** Reads a config-option value entry: id from `value` (when non-blank) else `id`. */
104
+ function configOptionEntry(value) {
105
+ return {
106
+ id: trimmedOrEmpty(value.value) || trimmedOrEmpty(value.id),
107
+ name: trimmedOrEmpty(value.name),
108
+ };
109
+ }
110
+ /** Reads a legacy `models.availableModels` entry. */
111
+ function legacyModelEntry(model) {
112
+ const obj = asObject(model);
113
+ return { id: trimmedOrEmpty(obj?.modelId), name: trimmedOrEmpty(obj?.name) };
114
+ }
80
115
  /**
81
116
  * Extracts and normalises the available models list from an ACP
82
117
  * `configOptions` array (preferred) into a `ModelOption[]`. Prepends
@@ -91,26 +126,18 @@ export function normalizeModelConfigOptions(configOptions, defaultModelOption) {
91
126
  const modelConfig = findModelConfigOption(configOptions);
92
127
  if (!modelConfig)
93
128
  return null;
94
- const seen = new Set([defaultModelOption.id]);
95
- const out = [defaultModelOption];
129
+ const entries = [];
96
130
  for (const rawValue of modelConfig.values) {
97
131
  const value = asObject(rawValue);
98
- if (!value)
99
- continue;
100
- const id = typeof value.value === 'string' && value.value.trim()
101
- ? value.value.trim()
102
- : typeof value.id === 'string'
103
- ? value.id.trim()
104
- : '';
105
- if (!id || seen.has(id))
106
- continue;
107
- seen.add(id);
108
- const name = typeof value.name === 'string' ? value.name.trim() : '';
109
- const isCurrent = id === modelConfig.currentValue;
110
- const labelBase = name && name !== id ? `${name} (${id})` : id;
111
- out.push({ id, label: isCurrent ? `${labelBase} • current` : labelBase });
132
+ if (value)
133
+ entries.push(configOptionEntry(value));
112
134
  }
113
- return { currentModelId: modelConfig.currentValue, models: out };
135
+ const models = buildModelOptions({
136
+ defaultModelOption,
137
+ currentId: modelConfig.currentValue,
138
+ entries,
139
+ });
140
+ return { currentModelId: modelConfig.currentValue, models };
114
141
  }
115
142
  /**
116
143
  * Produces the final ordered `ModelOption[]` for a session, merging the
@@ -128,22 +155,15 @@ export function normalizeModels({ models, defaultModelOption }, { configOptions
128
155
  if (configModels && configModels.models.length > 1) {
129
156
  return configModels.models;
130
157
  }
158
+ const out = legacyModelOptions({ models, defaultModelOption });
159
+ return out.length > 1 || !configModels ? out : configModels.models;
160
+ }
161
+ /** The legacy `result.models.availableModels` path of `normalizeModels`. */
162
+ function legacyModelOptions({ models, defaultModelOption, }) {
131
163
  const modelsObj = asObject(models);
132
164
  const available = Array.isArray(modelsObj?.availableModels) ? modelsObj.availableModels : [];
133
- const currentModelId = typeof modelsObj?.currentModelId === 'string' ? modelsObj.currentModelId : null;
134
- const seen = new Set([defaultModelOption.id]);
135
- const out = [defaultModelOption];
136
- for (const model of available) {
137
- const id = typeof model?.modelId === 'string' ? model.modelId.trim() : '';
138
- if (!id || seen.has(id))
139
- continue;
140
- seen.add(id);
141
- const name = typeof model?.name === 'string' ? model.name.trim() : '';
142
- const isCurrent = id === currentModelId;
143
- const labelBase = name && name !== id ? `${name} (${id})` : id;
144
- out.push({ id, label: isCurrent ? `${labelBase} • current` : labelBase });
145
- }
146
- return out.length > 1 || !configModels ? out : configModels.models;
165
+ const currentId = typeof modelsObj?.currentModelId === 'string' ? modelsObj.currentModelId : null;
166
+ return buildModelOptions({ defaultModelOption, currentId, entries: available.map(legacyModelEntry) });
147
167
  }
148
168
  /**
149
169
  * Returns `true` for JSON-RPC error codes that indicate a model-selection
@@ -206,7 +226,6 @@ export async function detectAcpModels(requiredArgs, optionalArgs = {}) {
206
226
  let stderrBuf = '';
207
227
  let stdoutBytes = 0;
208
228
  let expectedId = 1;
209
- let nextId = 2;
210
229
  let timer = null;
211
230
  const finish = (fn, value) => {
212
231
  if (settled)
@@ -250,37 +269,36 @@ export async function detectAcpModels(requiredArgs, optionalArgs = {}) {
250
269
  fail(`stdin write failed: ${errorMessage(err)}`);
251
270
  }
252
271
  };
253
- const sendSessionNew = () => {
254
- expectedId = nextId;
255
- writeRpc(nextId, 'session/new', buildAcpSessionNewParams({ cwd: cwd }));
256
- nextId += 1;
272
+ const handleRpcError = (obj, rpcErr) => {
273
+ // JSON-RPC -32603 "Internal error" during model detection:
274
+ // If this is for the current expected-id (initialize/session/new),
275
+ // it's a real probe failure — reject immediately.
276
+ // Otherwise it's cleanup noise — suppress it.
277
+ if (asObject(obj?.error)?.code === -32603 && obj?.id !== expectedId)
278
+ return;
279
+ fail(rpcErr);
280
+ };
281
+ const handleResult = (result) => {
282
+ if (expectedId === 1) {
283
+ expectedId = 2;
284
+ writeRpc(2, 'session/new', buildAcpSessionNewParams({ cwd: cwd }));
285
+ return;
286
+ }
287
+ onSessionResult?.(result);
288
+ const models = normalizeModels({ models: result.models, defaultModelOption: defaultModelOption }, { configOptions: result.configOptions });
289
+ finish(resolve, models);
257
290
  };
258
291
  const parser = createJsonLineStream({ onMessage: ({ message: raw }) => {
259
292
  const obj = asObject(raw);
260
- const error = asObject(obj?.error);
261
- const result = asObject(obj?.result);
262
293
  const rpcErr = rpcErrorMessage(raw);
263
294
  if (rpcErr) {
264
- // JSON-RPC -32603 "Internal error" during model detection:
265
- // If this is for the current expected-id (initialize/session/new),
266
- // it's a real probe failure — reject immediately.
267
- // Otherwise it's cleanup noise — suppress it.
268
- if (error?.code === -32603 && obj?.id !== expectedId)
269
- return;
270
- fail(rpcErr);
295
+ handleRpcError(obj, rpcErr);
271
296
  return;
272
297
  }
298
+ const result = asObject(obj?.result);
273
299
  if (obj?.id !== expectedId || !result)
274
300
  return;
275
- if (expectedId === 1) {
276
- sendSessionNew();
277
- return;
278
- }
279
- if (expectedId === 2) {
280
- onSessionResult?.(result);
281
- const models = normalizeModels({ models: result.models, defaultModelOption: defaultModelOption }, { configOptions: result.configOptions });
282
- finish(resolve, models);
283
- }
301
+ handleResult(result);
284
302
  } });
285
303
  child.stdout.on('data', (chunk) => {
286
304
  stdoutBytes += Buffer.byteLength(String(chunk), 'utf8');
@@ -99,12 +99,13 @@ export declare function formatUsage(usage: unknown): FormattedUsage | null;
99
99
  /**
100
100
  * Selects the best permission-outcome `optionId` to reply with when an ACP
101
101
  * agent sends a `session/request_permission` request. Bypass permits only
102
- * this invocation; otherwise reject. Never broaden approval to future calls.
102
+ * this invocation; otherwise reject. Trusted CLI parity may accept allow_always if that is
103
+ * the only offered approval, matching an explicitly bypassed native CLI.
103
104
  *
104
105
  * @param options - The `params.options` array from the incoming permission request.
105
106
  * @param policy - The existing run permission mode; absence is conservative.
106
107
  * @returns An offered `optionId`, or `null` when no safe choice exists.
107
108
  * @complexity O(n) time and O(1) space for n offered options.
108
109
  */
109
- export declare function choosePermissionOutcome(options: unknown, policy?: Pick<RuntimeBuildOptions, 'permissionMode'>): string | null;
110
+ export declare function choosePermissionOutcome(options: unknown, policy?: Pick<RuntimeBuildOptions, 'permissionMode' | 'cliParity'>): string | null;
110
111
  //# sourceMappingURL=rpc.d.ts.map
@@ -141,7 +141,8 @@ export function formatUsage(usage) {
141
141
  /**
142
142
  * Selects the best permission-outcome `optionId` to reply with when an ACP
143
143
  * agent sends a `session/request_permission` request. Bypass permits only
144
- * this invocation; otherwise reject. Never broaden approval to future calls.
144
+ * this invocation; otherwise reject. Trusted CLI parity may accept allow_always if that is
145
+ * the only offered approval, matching an explicitly bypassed native CLI.
145
146
  *
146
147
  * @param options - The `params.options` array from the incoming permission request.
147
148
  * @param policy - The existing run permission mode; absence is conservative.
@@ -151,7 +152,7 @@ export function formatUsage(usage) {
151
152
  export function choosePermissionOutcome(options, policy = {}) {
152
153
  const list = Array.isArray(options) ? options : [];
153
154
  const kinds = policy.permissionMode === 'bypass'
154
- ? ['allow_once', 'reject_once', 'reject_always']
155
+ ? policy.cliParity ? ['allow_once', 'allow_always', 'reject_once', 'reject_always'] : ['allow_once', 'reject_once', 'reject_always']
155
156
  : ['reject_once', 'reject_always'];
156
157
  for (const kind of kinds) {
157
158
  const option = list.find((value) => {
@@ -40,7 +40,7 @@ export declare function buildAcpSessionNewParams({ cwd }: {
40
40
  name: string;
41
41
  command: string;
42
42
  args: any[];
43
- env: any;
43
+ env: unknown;
44
44
  }[];
45
45
  };
46
46
  /**
@@ -28,38 +28,41 @@ export function buildAcpSessionNewParams({ cwd }, options = {}) {
28
28
  // agents can run through the skill + CLI path without MCP support. Do not
29
29
  // auto-install or mutate user/global MCP config; callers must pass an
30
30
  // explicit per-session MCP descriptor when a compatible agent supports it.
31
- mcpServers: servers.map((s) => {
32
- const rawEnv = s?.env;
33
- // Already a plain object — pass through in map mode, convert to
34
- // array in array mode (e.g. live-artifacts MCP from
35
- // buildLiveArtifactsMcpServersForAgent which already respects
36
- // acpMcpEnvFormat).
37
- const isPlainObject = rawEnv && typeof rawEnv === 'object' && !Array.isArray(rawEnv);
38
- if (wantsMap && isPlainObject) {
39
- return {
40
- type: typeof s?.type === 'string' ? s.type : 'stdio',
41
- name: typeof s?.name === 'string' ? s.name : '',
42
- command: typeof s?.command === 'string' ? s.command : '',
43
- args: Array.isArray(s?.args) ? s.args : [],
44
- env: rawEnv,
45
- };
46
- }
47
- const envArr = Array.isArray(rawEnv) ? rawEnv : [];
48
- const env = wantsMap
49
- ? Object.fromEntries(envArr.map((e) => [e?.name ?? '', e?.value ?? '']))
50
- : isPlainObject
51
- ? Object.entries(rawEnv).map(([name, value]) => ({ name, value }))
52
- : envArr;
53
- return {
54
- type: typeof s?.type === 'string' ? s.type : 'stdio',
55
- name: typeof s?.name === 'string' ? s.name : '',
56
- command: typeof s?.command === 'string' ? s.command : '',
57
- args: Array.isArray(s?.args) ? s.args : [],
58
- env,
59
- };
60
- }),
31
+ mcpServers: servers.map((server) => normalizeMcpServer({ server, wantsMap })),
61
32
  };
62
33
  }
34
+ /** Returns `value` when it is a string, else `fallback`. */
35
+ function stringOr({ value, fallback }) {
36
+ return typeof value === 'string' ? value : fallback;
37
+ }
38
+ /** Normalises one caller-supplied MCP server descriptor into the wire shape
39
+ * (`type`/`name`/`command`/`args`/`env`, in that key order). */
40
+ function normalizeMcpServer({ server: s, wantsMap, }) {
41
+ return {
42
+ type: stringOr({ value: s?.type, fallback: 'stdio' }),
43
+ name: stringOr({ value: s?.name, fallback: '' }),
44
+ command: stringOr({ value: s?.command, fallback: '' }),
45
+ args: Array.isArray(s?.args) ? s.args : [],
46
+ env: normalizeMcpEnv({ rawEnv: s?.env, wantsMap }),
47
+ };
48
+ }
49
+ /** Converts an MCP server `env` value to the requested wire format. */
50
+ function normalizeMcpEnv({ rawEnv, wantsMap }) {
51
+ // Already a plain object — pass through in map mode, convert to
52
+ // array in array mode (e.g. live-artifacts MCP from
53
+ // buildLiveArtifactsMcpServersForAgent which already respects
54
+ // acpMcpEnvFormat).
55
+ const isPlainObject = rawEnv && typeof rawEnv === 'object' && !Array.isArray(rawEnv);
56
+ if (isPlainObject) {
57
+ return wantsMap
58
+ ? rawEnv
59
+ : Object.entries(rawEnv).map(([name, value]) => ({ name, value }));
60
+ }
61
+ const envArr = Array.isArray(rawEnv) ? rawEnv : [];
62
+ return wantsMap
63
+ ? Object.fromEntries(envArr.map((e) => [e?.name ?? '', e?.value ?? '']))
64
+ : envArr;
65
+ }
63
66
  /**
64
67
  * Assembles the `prompt` array for a `session/prompt` ACP call. Always
65
68
  * includes a leading `{ type: 'text', text: prompt }` block, followed by
@@ -49,6 +49,8 @@ export interface AcpSessionController {
49
49
  * `send` are optional and carry sensible defaults.
50
50
  */
51
51
  export interface AttachAcpSessionOptions {
52
+ /** Host-authorized parity: bypass native permission requests; disable silence watchdog. */
53
+ cliParity?: boolean;
52
54
  child: AcpChildProcess;
53
55
  prompt: string;
54
56
  cwd?: string;
@@ -127,7 +129,7 @@ export interface AcpSessionEffects {
127
129
  details?: unknown;
128
130
  retryable?: boolean;
129
131
  }) => void;
130
- failWithPayload: (payload: unknown) => void;
132
+ failWithPayload: (payload: UnknownRecord) => void;
131
133
  writeRpc: (id: JsonRpcId, method: string, params: unknown, timeoutLabel: string) => void;
132
134
  sendPrompt: () => void;
133
135
  recoverFromModelSelectionError: () => void;