@zvada/agent-server 0.3.25 → 0.3.26

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 (156) hide show
  1. package/CHANGELOG.md +80 -0
  2. package/README.md +3 -0
  3. package/dist/core/agents/acp/acp-agent.js +91 -14
  4. package/dist/core/agents/acp/mappings.js +5 -1
  5. package/dist/core/agents/claude-code/approvals.js +2 -1
  6. package/dist/core/agents/claude-code/claude-agent.js +12 -2
  7. package/dist/core/agents/claude-code/mcp.js +9 -1
  8. package/dist/core/agents/claude-code/models.js +16 -10
  9. package/dist/core/agents/claude-code/options.js +23 -2
  10. package/dist/core/agents/claude-code/session.js +21 -1
  11. package/dist/core/agents/claude-code/tools.js +9 -4
  12. package/dist/core/agents/claude-code/turn.js +2 -0
  13. package/dist/core/agents/codex-app-server/adapter.js +2 -0
  14. package/dist/core/agents/codex-app-server/client.js +8 -5
  15. package/dist/core/agents/codex-app-server/codex-agent.js +35 -2
  16. package/dist/core/agents/codex-app-server/effort.js +13 -6
  17. package/dist/core/agents/codex-app-server/mcp.js +35 -18
  18. package/dist/core/agents/codex-app-server/models.js +10 -10
  19. package/dist/core/agents/codex-app-server/options.js +11 -2
  20. package/dist/core/agents/codex-app-server/session.js +11 -4
  21. package/dist/core/agents/codex-app-server/thread-settings.js +30 -11
  22. package/dist/core/agents/host-tools.js +493 -0
  23. package/dist/core/agents/mcp-config.js +6 -2
  24. package/dist/core/agents/scripted/scripted-agent.js +9 -3
  25. package/dist/core/agents/scripted/steps.js +5 -1
  26. package/dist/core/agents/session-agent.js +70 -2
  27. package/dist/core/agents/thinking-levels.js +8 -5
  28. package/dist/core/index.js +1 -0
  29. package/dist/core/presets.js +12 -2
  30. package/dist/core/processes/lifeline.js +9 -5
  31. package/dist/core/provision/pins.js +7 -16
  32. package/dist/core/provision/releases.js +25 -25
  33. package/dist/core/proxy/loopback.js +22 -4
  34. package/dist/protocol/config.js +21 -1
  35. package/dist/protocol/model-catalog.js +58 -18
  36. package/dist/protocol/models.js +6 -27
  37. package/dist/protocol/thinking.js +22 -9
  38. package/dist/protocol/wire-api.js +2 -2
  39. package/dist/server/bin.js +6 -4
  40. package/dist/types/core/agents/acp/acp-agent.d.ts +15 -0
  41. package/dist/types/core/agents/acp/acp-agent.d.ts.map +1 -1
  42. package/dist/types/core/agents/acp/mappings.d.ts +5 -1
  43. package/dist/types/core/agents/acp/mappings.d.ts.map +1 -1
  44. package/dist/types/core/agents/acp/requests.d.ts +2 -0
  45. package/dist/types/core/agents/acp/requests.d.ts.map +1 -1
  46. package/dist/types/core/agents/claude-code/approvals.d.ts +2 -1
  47. package/dist/types/core/agents/claude-code/approvals.d.ts.map +1 -1
  48. package/dist/types/core/agents/claude-code/claude-agent.d.ts +1 -0
  49. package/dist/types/core/agents/claude-code/claude-agent.d.ts.map +1 -1
  50. package/dist/types/core/agents/claude-code/mcp.d.ts +8 -1
  51. package/dist/types/core/agents/claude-code/mcp.d.ts.map +1 -1
  52. package/dist/types/core/agents/claude-code/models.d.ts +9 -5
  53. package/dist/types/core/agents/claude-code/models.d.ts.map +1 -1
  54. package/dist/types/core/agents/claude-code/options.d.ts +10 -1
  55. package/dist/types/core/agents/claude-code/options.d.ts.map +1 -1
  56. package/dist/types/core/agents/claude-code/session.d.ts +2 -0
  57. package/dist/types/core/agents/claude-code/session.d.ts.map +1 -1
  58. package/dist/types/core/agents/claude-code/tools.d.ts.map +1 -1
  59. package/dist/types/core/agents/claude-code/turn.d.ts +3 -0
  60. package/dist/types/core/agents/claude-code/turn.d.ts.map +1 -1
  61. package/dist/types/core/agents/codex-app-server/adapter.d.ts.map +1 -1
  62. package/dist/types/core/agents/codex-app-server/client.d.ts +2 -0
  63. package/dist/types/core/agents/codex-app-server/client.d.ts.map +1 -1
  64. package/dist/types/core/agents/codex-app-server/codex-agent.d.ts +11 -0
  65. package/dist/types/core/agents/codex-app-server/codex-agent.d.ts.map +1 -1
  66. package/dist/types/core/agents/codex-app-server/effort.d.ts +7 -7
  67. package/dist/types/core/agents/codex-app-server/effort.d.ts.map +1 -1
  68. package/dist/types/core/agents/codex-app-server/mcp.d.ts +11 -3
  69. package/dist/types/core/agents/codex-app-server/mcp.d.ts.map +1 -1
  70. package/dist/types/core/agents/codex-app-server/models.d.ts +4 -1
  71. package/dist/types/core/agents/codex-app-server/models.d.ts.map +1 -1
  72. package/dist/types/core/agents/codex-app-server/options.d.ts +9 -2
  73. package/dist/types/core/agents/codex-app-server/options.d.ts.map +1 -1
  74. package/dist/types/core/agents/codex-app-server/requests.d.ts +2 -0
  75. package/dist/types/core/agents/codex-app-server/requests.d.ts.map +1 -1
  76. package/dist/types/core/agents/codex-app-server/session.d.ts +6 -3
  77. package/dist/types/core/agents/codex-app-server/session.d.ts.map +1 -1
  78. package/dist/types/core/agents/codex-app-server/thread-settings.d.ts.map +1 -1
  79. package/dist/types/core/agents/host-tools.d.ts +162 -0
  80. package/dist/types/core/agents/host-tools.d.ts.map +1 -0
  81. package/dist/types/core/agents/mcp-config.d.ts +11 -2
  82. package/dist/types/core/agents/mcp-config.d.ts.map +1 -1
  83. package/dist/types/core/agents/scripted/scripted-agent.d.ts.map +1 -1
  84. package/dist/types/core/agents/scripted/steps.d.ts.map +1 -1
  85. package/dist/types/core/agents/session-agent.d.ts +2 -7
  86. package/dist/types/core/agents/session-agent.d.ts.map +1 -1
  87. package/dist/types/core/agents/thinking-levels.d.ts +7 -3
  88. package/dist/types/core/agents/thinking-levels.d.ts.map +1 -1
  89. package/dist/types/core/index.d.ts +1 -0
  90. package/dist/types/core/index.d.ts.map +1 -1
  91. package/dist/types/core/presets.d.ts +11 -1
  92. package/dist/types/core/presets.d.ts.map +1 -1
  93. package/dist/types/core/processes/lifeline.d.ts.map +1 -1
  94. package/dist/types/core/provision/pins.d.ts +5 -4
  95. package/dist/types/core/provision/pins.d.ts.map +1 -1
  96. package/dist/types/core/proxy/loopback.d.ts.map +1 -1
  97. package/dist/types/protocol/config.d.ts +12 -19
  98. package/dist/types/protocol/config.d.ts.map +1 -1
  99. package/dist/types/protocol/conversation.d.ts +4 -36
  100. package/dist/types/protocol/conversation.d.ts.map +1 -1
  101. package/dist/types/protocol/execution.d.ts +2 -18
  102. package/dist/types/protocol/execution.d.ts.map +1 -1
  103. package/dist/types/protocol/lifecycle.d.ts +8 -72
  104. package/dist/types/protocol/lifecycle.d.ts.map +1 -1
  105. package/dist/types/protocol/model-catalog.d.ts.map +1 -1
  106. package/dist/types/protocol/models.d.ts +4 -42
  107. package/dist/types/protocol/models.d.ts.map +1 -1
  108. package/dist/types/protocol/thinking.d.ts +19 -19
  109. package/dist/types/protocol/thinking.d.ts.map +1 -1
  110. package/dist/types/protocol/wire-api.d.ts +20 -105
  111. package/dist/types/protocol/wire-api.d.ts.map +1 -1
  112. package/dist/types/protocol/wire.d.ts +16 -117
  113. package/dist/types/protocol/wire.d.ts.map +1 -1
  114. package/docs/consuming.md +68 -11
  115. package/docs/deploy.md +6 -5
  116. package/docs/harnesses.md +79 -31
  117. package/package.json +4 -4
  118. package/src/core/agents/acp/acp-agent.ts +123 -17
  119. package/src/core/agents/acp/mappings.ts +5 -1
  120. package/src/core/agents/acp/requests.ts +2 -0
  121. package/src/core/agents/claude-code/approvals.ts +2 -1
  122. package/src/core/agents/claude-code/claude-agent.ts +14 -2
  123. package/src/core/agents/claude-code/mcp.ts +11 -1
  124. package/src/core/agents/claude-code/models.ts +15 -10
  125. package/src/core/agents/claude-code/options.ts +33 -3
  126. package/src/core/agents/claude-code/session.ts +26 -1
  127. package/src/core/agents/claude-code/tools.ts +10 -4
  128. package/src/core/agents/claude-code/turn.ts +4 -0
  129. package/src/core/agents/codex-app-server/adapter.ts +2 -0
  130. package/src/core/agents/codex-app-server/client.ts +11 -5
  131. package/src/core/agents/codex-app-server/codex-agent.ts +45 -1
  132. package/src/core/agents/codex-app-server/effort.ts +15 -20
  133. package/src/core/agents/codex-app-server/mcp.ts +46 -23
  134. package/src/core/agents/codex-app-server/models.ts +10 -10
  135. package/src/core/agents/codex-app-server/options.ts +16 -2
  136. package/src/core/agents/codex-app-server/requests.ts +2 -0
  137. package/src/core/agents/codex-app-server/session.ts +19 -4
  138. package/src/core/agents/codex-app-server/thread-settings.ts +31 -11
  139. package/src/core/agents/host-tools.ts +649 -0
  140. package/src/core/agents/mcp-config.ts +15 -3
  141. package/src/core/agents/scripted/scripted-agent.ts +9 -2
  142. package/src/core/agents/scripted/steps.ts +5 -1
  143. package/src/core/agents/session-agent.ts +78 -2
  144. package/src/core/agents/thinking-levels.ts +9 -6
  145. package/src/core/index.ts +9 -0
  146. package/src/core/presets.ts +24 -3
  147. package/src/core/processes/lifeline.ts +9 -5
  148. package/src/core/provision/pins.ts +7 -16
  149. package/src/core/provision/releases.ts +25 -25
  150. package/src/core/proxy/loopback.ts +25 -4
  151. package/src/protocol/config.ts +22 -1
  152. package/src/protocol/model-catalog.ts +58 -18
  153. package/src/protocol/models.ts +6 -26
  154. package/src/protocol/thinking.ts +27 -14
  155. package/src/protocol/wire-api.ts +2 -2
  156. package/src/server/bin.ts +6 -4
@@ -201,7 +201,10 @@ export class ScriptedAgent extends SessionAgent {
201
201
  controller: AbortController,
202
202
  ): AsyncIterableIterator<RawAgentEvent> {
203
203
  const { signal } = controller;
204
- if (signal.aborted) throw stopped();
204
+ // A turn cancelled before it began is still a turn of its script: it
205
+ // opens it and stops at its first step (or at its end, when it has no
206
+ // step), so a queue skips the turn's steps through its `end` and the
207
+ // next turn plays its own.
205
208
  // A script runs nothing of its own: the abort stops it, so a cancel is confirmed at once.
206
209
  this.cancelWith(options, async () => true);
207
210
  const { sessionId, turnId } = options;
@@ -232,7 +235,11 @@ export class ScriptedAgent extends SessionAgent {
232
235
  for (let n = 1; ; n++) {
233
236
  // What the step before did is the value of its `yield` in a generator.
234
237
  const next = await untilAborted(Promise.resolve(iterator.next(outcome)), signal);
235
- if (next.done) return;
238
+ if (next.done) {
239
+ // No step left to stop at: the cancel was confirmed, so the turn ends cancelled.
240
+ if (signal.aborted) throw stopped();
241
+ return;
242
+ }
236
243
  const step = readStep(next.value, `Step ${n} of turn ${turnId}`);
237
244
  const played = yield* this.play(step, turn);
238
245
  if ("stop" in played || "end" in step) return;
@@ -70,7 +70,11 @@ export const ScriptStepSchema = z.union([
70
70
  z.strictObject({ echo: z.enum(["input", "config"]) }),
71
71
  /** A pause of this many ms. */
72
72
  z.strictObject({ wait: Ms }),
73
- /** Runs until the turn is cancelled, then `stopTakes` ms more before it stops, also when the cancel came first. */
73
+ /**
74
+ * Runs until the turn is cancelled, then `stopTakes` ms more before it
75
+ * stops, also when the cancel came first; not in an async generator's
76
+ * script, whose next step a cancel does not wait for.
77
+ */
74
78
  z.strictObject({ hang: z.literal(true), stopTakes: Ms.optional() }),
75
79
  /**
76
80
  * Ends the turn in an error with this message: of `category` when given,
@@ -6,11 +6,14 @@ import {
6
6
  BaseAgent,
7
7
  CANCEL_CONFIRM_MS,
8
8
  type CancelResult,
9
+ type PermissionDecision,
10
+ type PermissionRequestHandler,
9
11
  type RawAgentEvent,
10
12
  type SteerOutcome,
11
13
  type SteerRequest,
12
14
  } from "./base.ts";
13
15
  import { configFingerprint } from "./config-fingerprint.ts";
16
+ import { withoutSecret } from "./host-tools.ts";
14
17
 
15
18
  /** Hands one steer to the harness's native turn. */
16
19
  export type DeliverSteer = (request: SteerRequest) => SteerOutcome | Promise<SteerOutcome>;
@@ -59,6 +62,50 @@ export interface SessionAgentOptions {
59
62
  * exported while its design is a Draft (LLP 0016); a product's own harness
60
63
  * extends `BaseAgent`, the public base.
61
64
  */
65
+ // @ref LLP 0018#who-can-read-the-secret — the broker publishes a request's options too
66
+ /**
67
+ * A permission request as the broker publishes it: its tool call and its
68
+ * options (a harness's own labels and ids) without the secret, and the
69
+ * option picked mapped back to the harness's own id.
70
+ */
71
+ async function permission(
72
+ ask: PermissionRequestHandler,
73
+ scrub: <T>(value: T) => T,
74
+ call: Parameters<PermissionRequestHandler>[0],
75
+ rest: [Parameters<PermissionRequestHandler>[1]?],
76
+ ): Promise<PermissionDecision> {
77
+ const [opts] = rest;
78
+ if (!opts) return ask(scrub(call), ...rest);
79
+ const scrubbed = scrub(opts);
80
+ // A choice whose id held the secret gets an opaque id of its own, unique, so
81
+ // two redacted the same can never be taken for each other.
82
+ const used = new Set(
83
+ (scrubbed.options ?? []).flatMap((option, index) =>
84
+ opts.options?.[index]?.optionId === option.optionId ? [option.optionId] : [],
85
+ ),
86
+ );
87
+ const opaque = (index: number) => {
88
+ let id = `redacted-option-${index}`;
89
+ while (used.has(id)) id += "-";
90
+ used.add(id);
91
+ return id;
92
+ };
93
+ const choices = (scrubbed.options ?? []).map((option, index) => {
94
+ const own = opts.options?.[index]?.optionId ?? option.optionId;
95
+ return {
96
+ option: own === option.optionId ? option : { ...option, optionId: opaque(index) },
97
+ own,
98
+ };
99
+ });
100
+ const native = new Map(choices.map(({ option, own }) => [option.optionId, own]));
101
+ const shown = scrubbed.options
102
+ ? { ...scrubbed, options: choices.map(({ option }) => option) }
103
+ : scrubbed;
104
+ const decision = await ask(scrub(call), shown);
105
+ if (decision.decision === "cancel" || decision.optionId === undefined) return decision;
106
+ return { ...decision, optionId: native.get(decision.optionId) ?? decision.optionId };
107
+ }
108
+
62
109
  export abstract class SessionAgent extends BaseAgent {
63
110
  private terminated = false;
64
111
  /**
@@ -106,8 +153,32 @@ export abstract class SessionAgent extends BaseAgent {
106
153
  try {
107
154
  // The adapter still produces its native cancellation result for an
108
155
  // already-aborted turn. It must not select a conversation or do setup.
109
- const prepared = controller.signal.aborted ? options : this.prepareSessionOptions(options);
110
- yield* this.executeTurn(input, prepared, controller);
156
+ const ready = controller.signal.aborted ? options : this.prepareSessionOptions(options);
157
+ // @ref LLP 0018#who-can-read-the-secret — the session's own secret leaves in no text
158
+ // Kept for the turn once seen: its output may still drain after the session's release.
159
+ let secret: string | undefined;
160
+ const scrub = <T>(value: T): T => {
161
+ secret ??= this.hostSecret(sessionId);
162
+ return withoutSecret(value, secret);
163
+ };
164
+ const { onWarning, onPermissionRequest, onElicitationRequest } = ready;
165
+ const prepared: AgentExecuteOptions = {
166
+ ...ready,
167
+ ...(onWarning && { onWarning: (warning) => onWarning(scrub(warning)) }),
168
+ // What the broker puts on the stream (a request's input, its title) is the agent's text too.
169
+ ...(onPermissionRequest && {
170
+ onPermissionRequest: (call, ...rest) =>
171
+ permission(onPermissionRequest, scrub, call, rest),
172
+ }),
173
+ ...(onElicitationRequest && {
174
+ onElicitationRequest: (request, ...rest) => onElicitationRequest(scrub(request), ...rest),
175
+ }),
176
+ };
177
+ try {
178
+ for await (const event of this.executeTurn(input, prepared, controller)) yield scrub(event);
179
+ } catch (error) {
180
+ throw scrub(error);
181
+ }
111
182
  } finally {
112
183
  this.executed.set(sessionId, options.turnId);
113
184
  if (this.steering.get(sessionId) === steering) this.steering.delete(sessionId);
@@ -227,6 +298,11 @@ export abstract class SessionAgent extends BaseAgent {
227
298
  }
228
299
 
229
300
  /** Native protocol execution; options are prepared and the session is exclusively owned. */
301
+ /** The session's host-tools secret, which no event, warning or error it lets out may hold. */
302
+ protected hostSecret(_sessionId: string): string | undefined {
303
+ return undefined;
304
+ }
305
+
230
306
  protected abstract executeTurn(
231
307
  input: AgentInput,
232
308
  options: AgentExecuteOptions,
@@ -1,9 +1,12 @@
1
- import { THINKING_LEVELS, type ThinkingLevel, isThinkingLevel } from "../../protocol/index.ts";
1
+ import type { ThinkingLevel } from "../../protocol/index.ts";
2
2
 
3
- /** The values that are thinking levels, once each, lowest first. */
4
- export function knownThinkingLevels(values: Iterable<unknown>): ThinkingLevel[] {
3
+ /**
4
+ * The levels a harness lists: each non-blank string once, in the order given.
5
+ * The order is the harness's own (both CLIs list lowest first), and a name
6
+ * this build does not know is kept.
7
+ */
8
+ export function listedThinkingLevels(values: Iterable<unknown>): ThinkingLevel[] {
5
9
  const levels = new Set<ThinkingLevel>();
6
- for (const value of values)
7
- if (typeof value === "string" && isThinkingLevel(value)) levels.add(value);
8
- return THINKING_LEVELS.filter((level) => levels.has(level));
10
+ for (const value of values) if (typeof value === "string" && /\S/.test(value)) levels.add(value);
11
+ return [...levels];
9
12
  }
package/src/core/index.ts CHANGED
@@ -32,6 +32,15 @@ export {
32
32
  } from "./agents/base.ts";
33
33
  export { AgentRegistry } from "./agents/registry.ts";
34
34
  export { type CredentialSource, credentialsFromUrl } from "./agents/credentials.ts";
35
+ export {
36
+ HOST_TOOL_TIMEOUT_MS,
37
+ type HostTool,
38
+ type HostToolCaller,
39
+ type HostToolContent,
40
+ type HostToolResult,
41
+ type HostToolSource,
42
+ type HostTools,
43
+ } from "./agents/host-tools.ts";
35
44
  export type {
36
45
  LoginOptions,
37
46
  LoginStatus,
@@ -11,6 +11,7 @@ import {
11
11
  type CodexAppServerAgentOptions,
12
12
  } from "./agents/codex-app-server/codex-agent.ts";
13
13
  import type { CredentialSource } from "./agents/credentials.ts";
14
+ import type { HostTools } from "./agents/host-tools.ts";
14
15
  import type { InheritConfig } from "./agents/inherit-config.ts";
15
16
  import { AgentRegistry } from "./agents/registry.ts";
16
17
  import { createScriptedTransformer } from "./agents/scripted/adapter.ts";
@@ -31,7 +32,8 @@ type SaidOnce =
31
32
  | "idleTimeoutMs"
32
33
  | "credentials"
33
34
  | "cancelConfirmMs"
34
- | "cancelGraceMs";
35
+ | "cancelGraceMs"
36
+ | "hostTools";
35
37
 
36
38
  export interface CreateRegistryOptions {
37
39
  /**
@@ -70,6 +72,15 @@ export interface CreateRegistryOptions {
70
72
  * Operator-level only.
71
73
  */
72
74
  credentials?: CredentialSource;
75
+ /**
76
+ * The host's own tools (LLP 0018): asked once for each session, at its
77
+ * first turn, for a source of tools the engine gives its agent on every
78
+ * harness, under one server name. Claude runs them in process; Codex, and
79
+ * an ACP agent that takes HTTP MCP servers, reach them at the engine's
80
+ * loopback by a secret of the session's own. Each call names its session,
81
+ * the turn running and the mode. Operator-level only.
82
+ */
83
+ hostTools?: HostTools;
73
84
  /**
74
85
  * How long a session's agent process may wait unused between turns before
75
86
  * it is ended (5 minutes by default); 0 never ends one for idleness, and
@@ -140,6 +151,7 @@ const HARNESSES: Record<
140
151
  onDiagnostic: opts.onDiagnostic,
141
152
  ...opts.claudeCode,
142
153
  credentials: opts.credentials,
154
+ hostTools: opts.hostTools,
143
155
  idleTimeoutMs: opts.idleTimeoutMs,
144
156
  cancelConfirmMs: opts.cancelConfirmMs,
145
157
  cancelGraceMs: opts.cancelGraceMs,
@@ -153,6 +165,7 @@ const HARNESSES: Record<
153
165
  new CodexAppServerAgent({
154
166
  ...opts.codexAppServer,
155
167
  credentials: opts.credentials,
168
+ hostTools: opts.hostTools,
156
169
  idleTimeoutMs: opts.idleTimeoutMs,
157
170
  cancelConfirmMs: opts.cancelConfirmMs,
158
171
  cancelGraceMs: opts.cancelGraceMs,
@@ -166,9 +179,16 @@ const HARNESSES: Record<
166
179
  if (!opts.acp) {
167
180
  throw new Error("the acp harness requires CreateRegistryOptions.acp (resolveLaunch)");
168
181
  }
169
- const { idleTimeoutMs, cancelConfirmMs, cancelGraceMs } = opts;
182
+ const { idleTimeoutMs, cancelConfirmMs, cancelGraceMs, hostTools } = opts;
170
183
  return [
171
- new AcpAgent({ ...opts.acp, idleTimeoutMs, cancelConfirmMs, cancelGraceMs, processes }),
184
+ new AcpAgent({
185
+ ...opts.acp,
186
+ idleTimeoutMs,
187
+ cancelConfirmMs,
188
+ cancelGraceMs,
189
+ hostTools,
190
+ processes,
191
+ }),
172
192
  createAcpTransformer,
173
193
  ];
174
194
  },
@@ -190,6 +210,7 @@ const SAID_ONCE: Record<SaidOnce, string> = {
190
210
  cancelConfirmMs: atTheTop("cancelConfirmMs"),
191
211
  cancelGraceMs: atTheTop("cancelGraceMs"),
192
212
  inheritConfig: atTheTop("inheritConfig"),
213
+ hostTools: atTheTop("hostTools"),
193
214
  processes:
194
215
  "the registry gives every harness its processes; say how they are owned with nativeProcesses",
195
216
  resolveCliPath: "the registry's provisioner finds each CLI; name one with provision.overrides",
@@ -118,6 +118,13 @@ interface BunRuntime {
118
118
  */
119
119
  function startShell(ticks: string, exited: () => void, failed: () => void): LifelineShell {
120
120
  const args = ["-c", LIFELINE_SCRIPT, LIFELINE_NAME, ticks];
121
+ // @ref LLP 0007#the-environment-a-process-is-given — only what its script needs
122
+ // It lives as long as the engine, and any process of this user can read its
123
+ // environment (`/proc/<pid>/environ`): `PATH` finds its `sed`, `awk`, `cat`,
124
+ // `tr` and `sleep`. Nothing else of the engine's environment is given;
125
+ // Node itself adds `NODE_V8_COVERAGE` to every child when the engine runs
126
+ // with it set (Bun adds nothing).
127
+ const env = { PATH: process.env.PATH };
121
128
  const bun = (globalThis as { Bun?: BunRuntime }).Bun;
122
129
  if (bun) {
123
130
  // @ref LLP 0007#the-lifeline — registered before the CLI gets input
@@ -129,10 +136,7 @@ function startShell(ticks: string, exited: () => void, failed: () => void): Life
129
136
  stdout: "ignore",
130
137
  stderr: "ignore",
131
138
  detached: true,
132
- // @ref LLP 0007#the-environment-a-process-is-given — this process's environment now
133
- // Without one, Bun gives the environment it was launched with: a
134
- // secret the host deleted from `process.env` would live on here.
135
- env: process.env,
139
+ env,
136
140
  onExit: exited,
137
141
  });
138
142
  child.unref();
@@ -149,7 +153,7 @@ function startShell(ticks: string, exited: () => void, failed: () => void): Life
149
153
  // Node writes a pipe at once when it can (libuv's `uv_try_write`).
150
154
  const child = spawn("/bin/sh", args, {
151
155
  detached: true,
152
- env: process.env,
156
+ env,
153
157
  stdio: ["pipe", "ignore", "ignore"],
154
158
  });
155
159
  child.unref();
@@ -16,22 +16,13 @@ import type { CliTool } from "./tools.ts";
16
16
  * `auto` an installed `@openai/codex` package (a lockfile's) runs instead,
17
17
  * and a `codex` on PATH only in `system` mode.
18
18
  *
19
- * After any bump, run `bun run releases:refresh` (each platform's build and
20
- * its checksums, `releases.ts`) and `bun run models:refresh` (the model
21
- * catalog, which records the versions that listed it); tests fail until both
22
- * match these pins.
19
+ * A bump is `bun run bump -- <tool>`: it writes what changed upstream, moves
20
+ * the pin, and runs both refreshes, `releases:refresh` (each platform's build
21
+ * and its checksums, `releases.ts`) and `models:refresh` (the model catalog,
22
+ * which records the versions that listed it); tests fail until both match
23
+ * these pins. The `bump-clis` skill says what to read and prove.
23
24
  */
24
25
  export const DEFAULT_PINS: Record<CliTool, string> = {
25
- // 0.3.288 verified 2026-10-03: the paired CLI honors `--thinking-display
26
- // summarized`, so reasoning parts carry text (2.1.233 ignored the flag and
27
- // streamed token-estimate placeholders). Re-check thinking summaries on
28
- // every bump (see options.ts extraArgs).
29
- claude: "0.3.288",
30
- // 0.160.0 re-verified 2026-10-03 against generate-ts: thread/turn/item
31
- // methods, token usage, approvals, and host-managed ChatGPT auth changed
32
- // only additively since 0.153.4. Of the GPT-6 family, 0.153.4 lists only
33
- // gpt-6-astra; the rest needs 0.159 or newer.
34
- // Since 0.160 a thread has one writer: resuming it from a second process
35
- // fails until the first releases it.
36
- codex: "0.160.0",
26
+ claude: "0.3.327",
27
+ codex: "0.169.1",
37
28
  };
@@ -9,77 +9,77 @@ import type { CliReleases } from "./checksums.ts";
9
9
  */
10
10
  export const CLI_RELEASES: CliReleases = {
11
11
  claude: {
12
- version: "0.3.288",
13
- cli: "2.1.288",
12
+ version: "0.3.327",
13
+ cli: "2.1.327",
14
14
  builds: {
15
15
  "darwin-arm64": {
16
16
  integrity:
17
- "sha512-85niGScWj8sr7yqOjSfqINaKv/zB47T45o4NBq1BmpaKRYFK7grtK24LA6C7cjx1Pznp+WT68mo373fbbwFW0A==",
18
- sha256: "bbe93063f7a0879a1021b2891e5c9354e5b3b98433e32efe6750f7710afed750",
17
+ "sha512-n+tQOPqz264l12BAKBcBPBbdB/bmZ2SfyONtEXQufTU6EeCoQMPS58RSt51Cxk5sDUme1hTF0vVAqRPdhq8tFg==",
18
+ sha256: "76d48205c926c8a6978cfc2171b631bcd01e20bbadd085638bb2ec57bea91c5b",
19
19
  },
20
20
  "darwin-x64": {
21
21
  integrity:
22
- "sha512-hY8MQtgAi+cRedFb+qSqZzAYXIfjC+ZiXtCxKCs4OqWbqrdVZ0GKcEv4nB6MfQGs/Qr4U24cDNuO2lskBbZAWA==",
23
- sha256: "946acab03a55b60e2016e30964c48b96ef6673cb5da684383f4835da410eede0",
22
+ "sha512-u091X+eQIyqg8BIEYLWJ0o6U3BaivMcf8Im4hI3hti/NGJ6YC5sR+LLEa1RjSIKE+JoOfCxipdCNSKaEI+0d5Q==",
23
+ sha256: "1fe75c05df7be824af1ed80ff9ccdf2be991f3a2212b97e05fc9a3bff2f39ef9",
24
24
  },
25
25
  "linux-arm64": {
26
26
  integrity:
27
- "sha512-CCj0xau64T+Ia+X2wZgjYFSUIWfNJRWIGFbT8+jKiCzQggaBo6OSZ8hAYyME3h13JYrgpyrUTzB5YiwKaw8ZFg==",
28
- sha256: "359ab6a058fcde9741dff54979a212fd134cdf8e8cfc2f8de02bc350b9e2b9d5",
27
+ "sha512-/k6BfV+L2er67UoLUabcp0w3L1DMemJjoijdxvXDiU8w81fGfHaKWKhRuhUQFmIrMLyMyQcBKaoyUNSLWovPnw==",
28
+ sha256: "acf0ef2f9da8d5ab08f193f007e19a06cbfb608b96a2f1f758d63a92a386cff8",
29
29
  },
30
30
  "linux-x64": {
31
31
  integrity:
32
- "sha512-Y5M496UZKttScbzptA45NI+CMHYONnskw0aq3rJ6s+gE6L6Jy8F8UoKt0lQO11R5xTY65TIeCasjQf/bLavuNg==",
33
- sha256: "0298068b686e7fdbaf9402a7a587bb7f49c0b0e084de09f69145a0719207640c",
32
+ "sha512-oAdL7KM9UVAZlATeSjh2haeEjex1N7ZcHzWO1tY2hgyhkyLNVw/tWUhITOucxMwokBx++h2dMVjxiPJiZ5uVOQ==",
33
+ sha256: "343c744baa14bfd38286a7cb90871051f04379956da6c5b803a9e66019a76ac9",
34
34
  },
35
35
  "linux-arm64-musl": {
36
36
  integrity:
37
- "sha512-66MD4hzNTqrTL5MN21bSfxm/fhbnM+ERsmWHGEsJojxAWY5DXCUlDkaAYM0rxDpdvLMVt9PpRVIiWDptaiFPxA==",
38
- sha256: "6b9816b225b303dacc17acc9d83016055274498effdbce6227e62d5dbaa762b9",
37
+ "sha512-oV8/+ZixiPzEW1BStoP9FOXsHcznONaom6S2PwwIfhi5Pxa5fGuloy8TiOB9wK+03zavqt7jmzLgVPF2a2NsTA==",
38
+ sha256: "e44a59ef850788c578adaab7a6487d5d0af9c0844401da9d7263e7b41515754b",
39
39
  },
40
40
  "linux-x64-musl": {
41
41
  integrity:
42
- "sha512-g3HDERLfEamirfp+MJDVl1fT8YYQMILUH65jPzl+SzKLeBu26WmAXAoZFmU4dasEmKZkEnBdL0ZQy3qnDy5EXg==",
43
- sha256: "b4334268a2ce06bf984dab2d6925cc5afe9d2344fa427fc362e266da0d57a894",
42
+ "sha512-O0nDZ1gpXi83qAdd8SM0gTdjlzrqpOlW0M4W7PfHVrMXWLh9I+1tvHat+s17ehIW6A9VQIWIq4oMwq7jb708Dg==",
43
+ sha256: "d2b02e78664c1347aff8fcee045356ee044116be41d7f412721a6c50182b6d98",
44
44
  },
45
45
  "win32-arm64": {
46
46
  integrity:
47
- "sha512-ijVSU5Vl1L1SlEm1djPNEekxHm9FS5GOitz8kL8KLdYDspMA97bgFM4gy/+riA3qn4ERepJkjdDLE+oYMTO+UA==",
48
- sha256: "5015d2b92866232b85384ac6e5eef4ff155418a92123503e52714c29186af8c6",
47
+ "sha512-a5ju83mylDvUwvQyRt1E0TQ0ar2nzVMPeWZhjcmgpB1cNTjf+KT5jgUnLvxPOG2tyjhm8bYGysRMdgB+tVnhvw==",
48
+ sha256: "d2c3395d252007540a5662a2cfd4d8903a0beb5fa32c893cd13b81be427625a7",
49
49
  },
50
50
  "win32-x64": {
51
51
  integrity:
52
- "sha512-zh4yfGduDEBKUqb3BPtq/cLYwHoScqm7X5fJhmkSs0BJiSJGlb38j6FXWDvoPfe+OXNjE5onNx5HlAnDzsQzrA==",
53
- sha256: "84304f7d4b0cd0ebcbe8318695a260151b48991a6659c3366fdd5da290c0ab91",
52
+ "sha512-bf52nw4j5RCvkXI5Poj5Qf0jWvuLQ/UPFqdav86UwaGTZZ0txNV33MKBIUoCyxXV6IC1/p2BNfkwmCAZ+Uc9pw==",
53
+ sha256: "d6c8075bfb3b87f1c1254e64b6c35dadc628d21e75930ae51e47047b3f05a4a2",
54
54
  },
55
55
  },
56
56
  },
57
57
  codex: {
58
- version: "0.160.0",
58
+ version: "0.169.1",
59
59
  builds: {
60
60
  "darwin-arm64": {
61
61
  integrity:
62
- "sha512-aefV6cqZA2REZgR//4McyXlp7zLcTti4CI2v3j9IVgNndPBv2kCeNEcz07qeelXcwOdSFPUKb6roA48vZmDgrQ==",
62
+ "sha512-yOKvCJktlbxdETtXAidz2GcC4z/WMYPmu2plncYJtUI5AhnFIExen8n9eL/El6n9hYbzzZFf1JgyW7yHx6kwTw==",
63
63
  },
64
64
  "darwin-x64": {
65
65
  integrity:
66
- "sha512-ir7cdsPrb9VkqNqpTECoTiomv04xws/FQ968mHQzuL+2J5Da0Dkh2Qlxp7sguDDZJab4YpYmNjQvBVMXbTeQaQ==",
66
+ "sha512-IbHIskdPWGAXFCdGiB8CosfXXtdvMmusrQ2AdW2kFHd6aSJZ+dvgalwjpxmAytalnNM3pQgXwS/6fU1OclFv8Q==",
67
67
  },
68
68
  "linux-arm64": {
69
69
  integrity:
70
- "sha512-VnVdsS06YlDsL8OwaJjQ3xdqdJNG4i+eBJBV3LytddknzSaF/urijLzVg3ptkwvoj8C7Gn7iWpVE+y8WEaPiCg==",
70
+ "sha512-6vRE7ZxkngT6L5JQ9WUQ2UnztS6hqyfcQiFqvk0yhcvWsrZLJNiiDZcKzGbLfJK2sDy7tSt9uWdP1cIgMHIkaw==",
71
71
  },
72
72
  "linux-x64": {
73
73
  integrity:
74
- "sha512-KI/73OqGrHmR18s7ya7E1NqV6rT0y3lxr0s8S1qR2m6zU6QRF/HlR529jALLh5vjdUnsRT4Ahoxt0axb4kY99g==",
74
+ "sha512-KmlHQ/lB9jcn8Yy5z/tWCpSPsqBvI3pU+0PUPccr+pKiiU2NJSCvZcAD7s3dmIFq5ZvGYtGcSn2KdFFdaPQICg==",
75
75
  },
76
76
  "win32-arm64": {
77
77
  integrity:
78
- "sha512-tTvK9ZIGuj9WnYaYOAnfjJVSfPV7dKqWtDHqUPLf0Hadp6SgynTxx7S7iMXRieFeXVOI2XH76KxEHSOTOnz3zw==",
78
+ "sha512-EYXwgEdHHzwgA0nnDcK4pI98IdReB1aDebtOxcYixM1/GY2Y/76oDFYSs/u6DzA27f6Hhf5V92OwQFw/GLICUQ==",
79
79
  },
80
80
  "win32-x64": {
81
81
  integrity:
82
- "sha512-/gCFcuOmGlQkgGivWCtY8BNEDixh70Pue0HZOk9S8bj2vUIE1GLD9zcNB/KqqDJmn0S+lIttauLpzQnw6HOCHA==",
82
+ "sha512-fImXWqxwxqHh9+FhJWsRRFiBzgBrSeN1bYTvtGZtUKGTPzHefYAL1agmlf5XScfwY5i5pHsExfdhFekzRBbqIw==",
83
83
  },
84
84
  },
85
85
  },
@@ -55,31 +55,52 @@ interface BunRuntime {
55
55
  }): { readonly port: number; stop(closeActiveConnections?: boolean): unknown; unref(): void };
56
56
  }
57
57
 
58
+ /**
59
+ * Bun's own `Response`. A product's process may have replaced the global one
60
+ * (Hono's Node server does, with a class of its own), and `Bun.serve` refuses
61
+ * any other ("Expected a Response object"); `fetch` still answers with Bun's.
62
+ */
63
+ async function nativeResponse(): Promise<typeof Response> {
64
+ return (await fetch("data:,")).constructor as typeof Response;
65
+ }
66
+
58
67
  /**
59
68
  * Serve `handle` on 127.0.0.1, on a port of its own: with `Bun.serve` under
60
69
  * Bun, whose `node:http` says nothing of a client that left once its request
61
70
  * body was read (a stopped turn's request would run on upstream), and with
62
71
  * `node:http` under Node.
63
72
  */
64
- export function serveLoopback(handle: (request: Request) => Promise<Response>): Promise<Loopback> {
73
+ export async function serveLoopback(
74
+ handle: (request: Request) => Promise<Response>,
75
+ ): Promise<Loopback> {
65
76
  const bun = (globalThis as { Bun?: BunRuntime }).Bun;
66
77
  if (bun) {
78
+ const Native = await nativeResponse();
79
+ const native = (response: Response): Response =>
80
+ // Not `instanceof`: Hono's class sets Bun's prototype under its own.
81
+ response.constructor === Native
82
+ ? response
83
+ : new Native(response.body, {
84
+ status: response.status,
85
+ statusText: response.statusText,
86
+ headers: [...response.headers],
87
+ });
67
88
  const server = bun.serve({
68
89
  port: 0,
69
90
  hostname: "127.0.0.1",
70
91
  // A model can think longer than any idle limit between the events it streams.
71
92
  idleTimeout: 0,
72
- fetch: (request) => handle(request).catch(() => new Response(null, { status: 502 })),
93
+ fetch: (request) => handle(request).then(native, () => new Native(null, { status: 502 })),
73
94
  });
74
95
  // Nothing on it keeps the process alive.
75
96
  server.unref();
76
- return Promise.resolve({
97
+ return {
77
98
  url: `http://127.0.0.1:${server.port}`,
78
99
  // Not waited for: with a client still connected, Bun's stop can take its time.
79
100
  close: async () => {
80
101
  server.stop(true);
81
102
  },
82
- });
103
+ };
83
104
  }
84
105
  const server = createServer((req, res) => {
85
106
  bridge(handle, req, res).catch(() => {
@@ -29,7 +29,7 @@ export type PermissionMode = z.infer<typeof PermissionModeSchema>;
29
29
  export type ReportedPermissionMode = PermissionMode | (string & {});
30
30
  export const ReportedPermissionModeSchema = openVocabulary(PermissionModeSchema.options);
31
31
 
32
- /** The longest `requestTimeoutMs`: a timer's own limit, about 24.8 days. */
32
+ /** The longest `requestTimeoutMs` and the longest MCP `timeoutMs`: a timer's own limit, about 24.8 days. */
33
33
  export const MAX_REQUEST_TIMEOUT_MS = 2_147_483_647;
34
34
 
35
35
  /**
@@ -41,6 +41,24 @@ export const MAX_REQUEST_TIMEOUT_MS = 2_147_483_647;
41
41
  */
42
42
  const required = z.boolean().optional();
43
43
 
44
+ /**
45
+ * How long one call to one of the server's tools may run, in milliseconds,
46
+ * on any transport: past it the call fails, and the model is told it timed out.
47
+ * - Claude: the server's `timeout`. A value under 1000 is ignored, as if unset.
48
+ * Unset, a call to an HTTP or SSE server is cut at 60 s unless
49
+ * `MCP_TOOL_TIMEOUT` (ms) is in the turn's or the engine's environment; a
50
+ * call to a stdio server is not cut at 60 s (one ran 70 s), and Claude's
51
+ * own longer limits still apply.
52
+ * - Codex: the server's `tool_timeout_sec`, in whole seconds rounded up
53
+ * (1118 cuts a call at 2 s), as Codex reads a fraction back changed.
54
+ * Unset, a call is cut at 300 s.
55
+ * - An ACP agent is not given it (ACP v1 has no such field): the agent keeps
56
+ * its own limit, if it has one.
57
+ * At most `MAX_REQUEST_TIMEOUT_MS`, a timer's own limit; a larger value is refused.
58
+ * A changed value applies from the next turn of a warm session.
59
+ */
60
+ const timeoutMs = z.number().int().positive().max(MAX_REQUEST_TIMEOUT_MS).optional();
61
+
44
62
  /** Minimal external MCP server descriptor (stdio or http/sse). */
45
63
  export const McpServerConfigSchema = z.discriminatedUnion("type", [
46
64
  z.object({
@@ -49,18 +67,21 @@ export const McpServerConfigSchema = z.discriminatedUnion("type", [
49
67
  args: z.array(z.string()).optional(),
50
68
  env: z.record(z.string(), z.string()).optional(),
51
69
  required,
70
+ timeoutMs,
52
71
  }),
53
72
  z.object({
54
73
  type: z.literal("http"),
55
74
  url: z.string(),
56
75
  headers: z.record(z.string(), z.string()).optional(),
57
76
  required,
77
+ timeoutMs,
58
78
  }),
59
79
  z.object({
60
80
  type: z.literal("sse"),
61
81
  url: z.string(),
62
82
  headers: z.record(z.string(), z.string()).optional(),
63
83
  required,
84
+ timeoutMs,
64
85
  }),
65
86
  ]);
66
87
  export type McpServerConfig = z.infer<typeof McpServerConfigSchema>;