@zvada/agent-server 0.3.24 → 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 (190) hide show
  1. package/CHANGELOG.md +110 -0
  2. package/README.md +3 -0
  3. package/dist/client/client.js +93 -34
  4. package/dist/core/agents/acp/acp-agent.js +91 -14
  5. package/dist/core/agents/acp/mappings.js +5 -1
  6. package/dist/core/agents/claude-code/approvals.js +2 -1
  7. package/dist/core/agents/claude-code/claude-agent.js +12 -2
  8. package/dist/core/agents/claude-code/mcp.js +9 -1
  9. package/dist/core/agents/claude-code/models.js +16 -10
  10. package/dist/core/agents/claude-code/options.js +23 -2
  11. package/dist/core/agents/claude-code/session.js +21 -1
  12. package/dist/core/agents/claude-code/tools.js +9 -4
  13. package/dist/core/agents/claude-code/turn.js +2 -0
  14. package/dist/core/agents/codex-app-server/adapter.js +2 -0
  15. package/dist/core/agents/codex-app-server/client.js +8 -5
  16. package/dist/core/agents/codex-app-server/codex-agent.js +35 -2
  17. package/dist/core/agents/codex-app-server/effort.js +13 -6
  18. package/dist/core/agents/codex-app-server/mcp.js +35 -18
  19. package/dist/core/agents/codex-app-server/models.js +10 -10
  20. package/dist/core/agents/codex-app-server/options.js +11 -2
  21. package/dist/core/agents/codex-app-server/session.js +11 -4
  22. package/dist/core/agents/codex-app-server/thread-settings.js +30 -11
  23. package/dist/core/agents/host-tools.js +493 -0
  24. package/dist/core/agents/mcp-config.js +6 -2
  25. package/dist/core/agents/scripted/scripted-agent.js +11 -4
  26. package/dist/core/agents/scripted/steps.js +5 -1
  27. package/dist/core/agents/session-agent.js +70 -2
  28. package/dist/core/agents/thinking-levels.js +8 -5
  29. package/dist/core/index.js +1 -0
  30. package/dist/core/presets.js +12 -2
  31. package/dist/core/processes/identity.js +1 -0
  32. package/dist/core/processes/lifeline.js +13 -1
  33. package/dist/core/processes/process-table.js +1 -0
  34. package/dist/core/provision/extract.js +1 -0
  35. package/dist/core/provision/pins.js +7 -16
  36. package/dist/core/provision/releases.js +25 -25
  37. package/dist/core/proxy/loopback.js +22 -4
  38. package/dist/core/runtime/agent-runtime.js +6 -3
  39. package/dist/core/runtime/turn.js +20 -10
  40. package/dist/protocol/config.js +21 -1
  41. package/dist/protocol/credentials.js +2 -1
  42. package/dist/protocol/errors.js +12 -3
  43. package/dist/protocol/model-catalog.js +58 -18
  44. package/dist/protocol/models.js +6 -27
  45. package/dist/protocol/thinking.js +22 -9
  46. package/dist/protocol/wire-api.js +2 -2
  47. package/dist/server/bin.js +6 -4
  48. package/dist/server/routes.js +3 -2
  49. package/dist/types/client/client.d.ts +6 -1
  50. package/dist/types/client/client.d.ts.map +1 -1
  51. package/dist/types/core/agents/acp/acp-agent.d.ts +15 -0
  52. package/dist/types/core/agents/acp/acp-agent.d.ts.map +1 -1
  53. package/dist/types/core/agents/acp/mappings.d.ts +5 -1
  54. package/dist/types/core/agents/acp/mappings.d.ts.map +1 -1
  55. package/dist/types/core/agents/acp/requests.d.ts +2 -0
  56. package/dist/types/core/agents/acp/requests.d.ts.map +1 -1
  57. package/dist/types/core/agents/claude-code/approvals.d.ts +2 -1
  58. package/dist/types/core/agents/claude-code/approvals.d.ts.map +1 -1
  59. package/dist/types/core/agents/claude-code/claude-agent.d.ts +1 -0
  60. package/dist/types/core/agents/claude-code/claude-agent.d.ts.map +1 -1
  61. package/dist/types/core/agents/claude-code/mcp.d.ts +8 -1
  62. package/dist/types/core/agents/claude-code/mcp.d.ts.map +1 -1
  63. package/dist/types/core/agents/claude-code/models.d.ts +9 -5
  64. package/dist/types/core/agents/claude-code/models.d.ts.map +1 -1
  65. package/dist/types/core/agents/claude-code/options.d.ts +14 -1
  66. package/dist/types/core/agents/claude-code/options.d.ts.map +1 -1
  67. package/dist/types/core/agents/claude-code/session.d.ts +2 -0
  68. package/dist/types/core/agents/claude-code/session.d.ts.map +1 -1
  69. package/dist/types/core/agents/claude-code/tools.d.ts.map +1 -1
  70. package/dist/types/core/agents/claude-code/turn.d.ts +3 -0
  71. package/dist/types/core/agents/claude-code/turn.d.ts.map +1 -1
  72. package/dist/types/core/agents/codex-app-server/adapter.d.ts.map +1 -1
  73. package/dist/types/core/agents/codex-app-server/client.d.ts +2 -0
  74. package/dist/types/core/agents/codex-app-server/client.d.ts.map +1 -1
  75. package/dist/types/core/agents/codex-app-server/codex-agent.d.ts +11 -0
  76. package/dist/types/core/agents/codex-app-server/codex-agent.d.ts.map +1 -1
  77. package/dist/types/core/agents/codex-app-server/effort.d.ts +7 -7
  78. package/dist/types/core/agents/codex-app-server/effort.d.ts.map +1 -1
  79. package/dist/types/core/agents/codex-app-server/mcp.d.ts +11 -3
  80. package/dist/types/core/agents/codex-app-server/mcp.d.ts.map +1 -1
  81. package/dist/types/core/agents/codex-app-server/models.d.ts +4 -1
  82. package/dist/types/core/agents/codex-app-server/models.d.ts.map +1 -1
  83. package/dist/types/core/agents/codex-app-server/options.d.ts +9 -2
  84. package/dist/types/core/agents/codex-app-server/options.d.ts.map +1 -1
  85. package/dist/types/core/agents/codex-app-server/requests.d.ts +2 -0
  86. package/dist/types/core/agents/codex-app-server/requests.d.ts.map +1 -1
  87. package/dist/types/core/agents/codex-app-server/session.d.ts +6 -3
  88. package/dist/types/core/agents/codex-app-server/session.d.ts.map +1 -1
  89. package/dist/types/core/agents/codex-app-server/thread-settings.d.ts.map +1 -1
  90. package/dist/types/core/agents/host-tools.d.ts +162 -0
  91. package/dist/types/core/agents/host-tools.d.ts.map +1 -0
  92. package/dist/types/core/agents/mcp-config.d.ts +11 -2
  93. package/dist/types/core/agents/mcp-config.d.ts.map +1 -1
  94. package/dist/types/core/agents/scripted/scripted-agent.d.ts.map +1 -1
  95. package/dist/types/core/agents/scripted/steps.d.ts +1 -1
  96. package/dist/types/core/agents/scripted/steps.d.ts.map +1 -1
  97. package/dist/types/core/agents/session-agent.d.ts +2 -7
  98. package/dist/types/core/agents/session-agent.d.ts.map +1 -1
  99. package/dist/types/core/agents/thinking-levels.d.ts +7 -3
  100. package/dist/types/core/agents/thinking-levels.d.ts.map +1 -1
  101. package/dist/types/core/index.d.ts +1 -0
  102. package/dist/types/core/index.d.ts.map +1 -1
  103. package/dist/types/core/presets.d.ts +11 -1
  104. package/dist/types/core/presets.d.ts.map +1 -1
  105. package/dist/types/core/processes/identity.d.ts.map +1 -1
  106. package/dist/types/core/processes/lifeline.d.ts.map +1 -1
  107. package/dist/types/core/processes/process-table.d.ts.map +1 -1
  108. package/dist/types/core/provision/extract.d.ts.map +1 -1
  109. package/dist/types/core/provision/pins.d.ts +5 -4
  110. package/dist/types/core/provision/pins.d.ts.map +1 -1
  111. package/dist/types/core/proxy/loopback.d.ts.map +1 -1
  112. package/dist/types/core/runtime/agent-runtime.d.ts +4 -1
  113. package/dist/types/core/runtime/agent-runtime.d.ts.map +1 -1
  114. package/dist/types/core/runtime/turn.d.ts +12 -7
  115. package/dist/types/core/runtime/turn.d.ts.map +1 -1
  116. package/dist/types/protocol/clis.d.ts +3 -3
  117. package/dist/types/protocol/config.d.ts +12 -19
  118. package/dist/types/protocol/config.d.ts.map +1 -1
  119. package/dist/types/protocol/conversation.d.ts +10 -42
  120. package/dist/types/protocol/conversation.d.ts.map +1 -1
  121. package/dist/types/protocol/credentials.d.ts +13 -1
  122. package/dist/types/protocol/credentials.d.ts.map +1 -1
  123. package/dist/types/protocol/errors.d.ts +6 -4
  124. package/dist/types/protocol/errors.d.ts.map +1 -1
  125. package/dist/types/protocol/execution.d.ts +2 -18
  126. package/dist/types/protocol/execution.d.ts.map +1 -1
  127. package/dist/types/protocol/lifecycle.d.ts +12 -76
  128. package/dist/types/protocol/lifecycle.d.ts.map +1 -1
  129. package/dist/types/protocol/model-catalog.d.ts.map +1 -1
  130. package/dist/types/protocol/models.d.ts +4 -42
  131. package/dist/types/protocol/models.d.ts.map +1 -1
  132. package/dist/types/protocol/thinking.d.ts +19 -19
  133. package/dist/types/protocol/thinking.d.ts.map +1 -1
  134. package/dist/types/protocol/wire-api.d.ts +32 -117
  135. package/dist/types/protocol/wire-api.d.ts.map +1 -1
  136. package/dist/types/protocol/wire.d.ts +24 -125
  137. package/dist/types/protocol/wire.d.ts.map +1 -1
  138. package/dist/types/server/routes.d.ts.map +1 -1
  139. package/docs/consuming.md +92 -12
  140. package/docs/deploy.md +8 -0
  141. package/docs/harnesses.md +88 -27
  142. package/package.json +4 -4
  143. package/src/client/client.ts +114 -44
  144. package/src/core/agents/acp/acp-agent.ts +123 -17
  145. package/src/core/agents/acp/mappings.ts +5 -1
  146. package/src/core/agents/acp/requests.ts +2 -0
  147. package/src/core/agents/claude-code/approvals.ts +2 -1
  148. package/src/core/agents/claude-code/claude-agent.ts +14 -2
  149. package/src/core/agents/claude-code/mcp.ts +11 -1
  150. package/src/core/agents/claude-code/models.ts +15 -10
  151. package/src/core/agents/claude-code/options.ts +37 -3
  152. package/src/core/agents/claude-code/session.ts +26 -1
  153. package/src/core/agents/claude-code/tools.ts +10 -4
  154. package/src/core/agents/claude-code/turn.ts +4 -0
  155. package/src/core/agents/codex-app-server/adapter.ts +2 -0
  156. package/src/core/agents/codex-app-server/client.ts +11 -5
  157. package/src/core/agents/codex-app-server/codex-agent.ts +45 -1
  158. package/src/core/agents/codex-app-server/effort.ts +15 -20
  159. package/src/core/agents/codex-app-server/mcp.ts +46 -23
  160. package/src/core/agents/codex-app-server/models.ts +10 -10
  161. package/src/core/agents/codex-app-server/options.ts +16 -2
  162. package/src/core/agents/codex-app-server/requests.ts +2 -0
  163. package/src/core/agents/codex-app-server/session.ts +19 -4
  164. package/src/core/agents/codex-app-server/thread-settings.ts +31 -11
  165. package/src/core/agents/host-tools.ts +649 -0
  166. package/src/core/agents/mcp-config.ts +15 -3
  167. package/src/core/agents/scripted/scripted-agent.ts +11 -3
  168. package/src/core/agents/scripted/steps.ts +5 -1
  169. package/src/core/agents/session-agent.ts +78 -2
  170. package/src/core/agents/thinking-levels.ts +9 -6
  171. package/src/core/index.ts +9 -0
  172. package/src/core/presets.ts +24 -3
  173. package/src/core/processes/identity.ts +1 -0
  174. package/src/core/processes/lifeline.ts +14 -1
  175. package/src/core/processes/process-table.ts +1 -0
  176. package/src/core/provision/extract.ts +1 -0
  177. package/src/core/provision/pins.ts +7 -16
  178. package/src/core/provision/releases.ts +25 -25
  179. package/src/core/proxy/loopback.ts +25 -4
  180. package/src/core/runtime/agent-runtime.ts +6 -3
  181. package/src/core/runtime/turn.ts +21 -9
  182. package/src/protocol/config.ts +22 -1
  183. package/src/protocol/credentials.ts +19 -5
  184. package/src/protocol/errors.ts +12 -3
  185. package/src/protocol/model-catalog.ts +58 -18
  186. package/src/protocol/models.ts +6 -26
  187. package/src/protocol/thinking.ts +27 -14
  188. package/src/protocol/wire-api.ts +2 -2
  189. package/src/server/bin.ts +6 -4
  190. package/src/server/routes.ts +3 -2
@@ -7,16 +7,24 @@ import type {
7
7
  import type {
8
8
  AgentCapabilities,
9
9
  AgentInput,
10
+ McpServerConfig,
10
11
  PermissionMode,
11
12
  RunConfig,
12
13
  } from "../../../protocol/index.ts";
13
14
  import { AsyncQueue } from "../../../protocol/index.ts";
14
15
  import { type NativeProcesses, sharedNativeProcesses } from "../../processes/native-processes.ts";
15
16
  import { onAbort, untilAborted } from "../../utils/deadline.ts";
16
- import { SessionResumeError } from "../../utils/errors.ts";
17
+ import { McpUnavailableError, SessionResumeError } from "../../utils/errors.ts";
17
18
  import type { AgentExecuteOptions, RawAgentEvent } from "../base.ts";
18
19
  import { configFingerprint } from "../config-fingerprint.ts";
19
- import { nativeMcpServer } from "../mcp-config.ts";
20
+ import {
21
+ type HostLease,
22
+ type HostToolSessions,
23
+ type HostTools,
24
+ hostToolSessions,
25
+ loopbackDirect,
26
+ refuseHostName,
27
+ } from "../host-tools.ts";
20
28
  import { IDLE_TIMEOUT_MS, ProcessPool } from "../process-pool.ts";
21
29
  import { SessionAgent } from "../session-agent.ts";
22
30
  import { type AcpRawEvent, CANCELLED_PROMPT_RESULT } from "./adapter.ts";
@@ -32,25 +40,41 @@ import { type TurnScope, answerElicitation, answerPermission } from "./requests.
32
40
  /**
33
41
  * What a session's agent process was started with, as one key: a change to
34
42
  * any of it starts another, which resumes the conversation where the agent
35
- * can. MCP servers go without `required`, which is the engine's; extra
36
- * directories count, in any order, only for an agent that takes them.
43
+ * can. MCP servers count as the agent is given them (no `required`, which is
44
+ * the engine's, no `timeoutMs`, which ACP cannot carry); the host's tools by
45
+ * their name, their address and secret being the session's for its life;
46
+ * extra directories, in any order, only for an agent that takes them.
37
47
  * Hashed: the env and MCP headers carry credentials.
38
48
  */
49
+ /** What the agent is given, in an order of its own: a server's, header's or variable's place means nothing. */
50
+ function canonicalServers(servers: Record<string, McpServerConfig>) {
51
+ // A total order by code unit: `localeCompare` calls distinct names equal.
52
+ const byName = (a: { name: string }, b: { name: string }) =>
53
+ a.name < b.name ? -1 : a.name > b.name ? 1 : 0;
54
+ return toAcpMcpServers(servers)
55
+ .map((server) =>
56
+ "headers" in server
57
+ ? { ...server, headers: [...server.headers].sort(byName) }
58
+ : "env" in server
59
+ ? { ...server, env: [...server.env].sort(byName) }
60
+ : server,
61
+ )
62
+ .sort(byName);
63
+ }
64
+
39
65
  function spawnKey(
40
66
  options: AgentExecuteOptions,
41
67
  launch: AcpLaunch,
42
68
  takesDirectories: boolean,
69
+ host: string | undefined,
43
70
  ): string {
44
- const servers = options.mcpServers;
45
71
  return configFingerprint({
46
72
  launch: { command: launch.command, args: launch.args ?? [], env: launch.env ?? {} },
47
73
  cwd: options.cwd,
48
74
  env: options.env,
49
- mcpServers:
50
- servers &&
51
- Object.fromEntries(
52
- Object.entries(servers).map(([name, server]) => [name, nativeMcpServer(server)]),
53
- ),
75
+ // @ref LLP 0018#acp — only what the agent is given
76
+ mcpServers: options.mcpServers && canonicalServers(options.mcpServers),
77
+ host,
54
78
  directories: takesDirectories
55
79
  ? [...new Set(options.additionalDirectories ?? [])].sort()
56
80
  : undefined,
@@ -139,6 +163,12 @@ export interface AcpAgentOptions {
139
163
  * and recorded for its session (`createAgentRegistry` passes the runtime's).
140
164
  */
141
165
  processes?: NativeProcesses;
166
+ /**
167
+ * The host's tools for each session (LLP 0018), at the engine's loopback,
168
+ * for an agent that takes HTTP MCP servers; another goes without them,
169
+ * which its turn says. Operator-level only.
170
+ */
171
+ hostTools?: HostTools;
142
172
  }
143
173
 
144
174
  interface AcpSession {
@@ -150,6 +180,8 @@ interface AcpSession {
150
180
  takesDirectories: boolean;
151
181
  /** From `initialize`: whether another process could continue the conversation (resume or load). */
152
182
  resumable: boolean;
183
+ /** The agent takes HTTP servers, and was started without the host's: the loopback was down. */
184
+ hostFailed?: true;
153
185
  /** The agent's selectable settings, kept current by `config_option_update`. */
154
186
  configOptions: SessionConfigOption[];
155
187
  /** The agent's modes, kept current by `current_mode_update`; absent when it offers none. */
@@ -163,6 +195,8 @@ interface AcpSession {
163
195
  interface AcpPoolTurn {
164
196
  options: AgentExecuteOptions;
165
197
  launch: AcpLaunch;
198
+ /** The host's tools, which the agent reaches over HTTP when it takes such a server. */
199
+ host?: HostLease;
166
200
  }
167
201
 
168
202
  /** A JSON-RPC error's `data` usually holds the cause its message only names. */
@@ -198,16 +232,32 @@ export class AcpAgent extends SessionAgent {
198
232
  /** Its CLIs start here: the runtime's, or this OS process's own when it was made without one. */
199
233
  readonly processes: NativeProcesses;
200
234
  private readonly sessions: ProcessPool<AcpSession, AcpPoolTurn>;
235
+ private readonly host?: HostToolSessions;
201
236
 
202
237
  constructor(private readonly agentOptions: AcpAgentOptions) {
203
238
  super({ cancelConfirmMs: agentOptions.cancelConfirmMs });
204
239
  this.processes = agentOptions.processes ?? sharedNativeProcesses();
240
+ this.host = hostToolSessions(agentOptions.hostTools, this.harness, {
241
+ // @ref LLP 0018#acp — the engine's mode: the turn's, moved only by a plan the broker approved
242
+ // The agent's own `current_mode_update` never raises it.
243
+ live: (sessionId) => {
244
+ const turn = this.sessions.get(sessionId)?.turn;
245
+ return turn?.turnId
246
+ ? { turnId: turn.turnId, permissionMode: turn.mode ?? "default", signal: turn.signal }
247
+ : undefined;
248
+ },
249
+ writesNeedFullAccess: true,
250
+ });
205
251
  this.sessions = new ProcessPool<AcpSession, AcpPoolTurn>(
206
252
  {
207
253
  resumeOf: ({ options }) => options.resumeSessionId,
208
254
  conversationsOf: (session) => [session.acpSessionId],
209
- fits: (session, { options, launch }) =>
210
- session.spawnKey === spawnKey(options, launch, session.takesDirectories),
255
+ fits: (session, { options, launch, host }) =>
256
+ session.spawnKey ===
257
+ spawnKey(options, launch, session.takesDirectories, host?.source.name) &&
258
+ // @ref LLP 0018#acp — an agent started without the host's tools while the loopback was down
259
+ // One that can resume is started again, to get them; one that cannot keeps its conversation.
260
+ !(session.hostFailed && session.resumable),
211
261
  // @ref LLP 0001#d10--built-in-turns-own-their-logical-session-through-cleanup — not ended for idleness when it cannot be resumed
212
262
  // An agent that can neither resume nor load holds the only copy of
213
263
  // its conversation: neither idleness nor a host resume ends it.
@@ -232,7 +282,47 @@ export class AcpAgent extends SessionAgent {
232
282
  );
233
283
  }
234
284
 
235
- return this.sessions.acquire(options.sessionId, { options, launch }, signal);
285
+ const host = await untilAborted(
286
+ Promise.resolve(this.host?.lease(options.sessionId, options.cwd)),
287
+ signal,
288
+ );
289
+ if (host) refuseHostName(options.mcpServers, host.source.name);
290
+ return this.sessions.acquire(options.sessionId, { options, launch, host }, signal);
291
+ }
292
+
293
+ protected override hostSecret(sessionId: string): string | undefined {
294
+ return this.host?.secretOf(sessionId);
295
+ }
296
+
297
+ // @ref LLP 0018#acp — an agent that takes no HTTP server goes without the host's tools, and says so
298
+ /**
299
+ * The servers the agent is given: the turn's, and the host's when the agent
300
+ * takes HTTP servers, the loopback started only then. Without it, or with a
301
+ * loopback that cannot start, the turn says so and goes on without them.
302
+ */
303
+ private async serversFor(
304
+ options: AgentExecuteOptions,
305
+ host: HostLease | undefined,
306
+ http: boolean,
307
+ ): Promise<{ servers: AgentExecuteOptions["mcpServers"]; hostFailed?: true }> {
308
+ if (!host) return { servers: options.mcpServers };
309
+ const { name } = host.source;
310
+ let cause = "the agent takes no HTTP MCP server";
311
+ let hostFailed: true | undefined;
312
+ if (http) {
313
+ try {
314
+ return { servers: { ...options.mcpServers, [name]: await host.http() } };
315
+ } catch (error) {
316
+ if (!(error instanceof McpUnavailableError)) throw error;
317
+ cause = error.servers[name] ?? error.message;
318
+ hostFailed = true;
319
+ }
320
+ }
321
+ await options.onWarning?.({
322
+ category: "mcp_unavailable",
323
+ message: `MCP server ${name} could not connect (${cause}); the turn goes on without the host's tools`,
324
+ });
325
+ return { servers: options.mcpServers, ...(hostFailed && { hostFailed }) };
236
326
  }
237
327
 
238
328
  /**
@@ -242,7 +332,7 @@ export class AcpAgent extends SessionAgent {
242
332
  * successor never loads a conversation another agent still has.
243
333
  */
244
334
  private async spawn(
245
- { options, launch }: AcpPoolTurn,
335
+ { options, launch, host }: AcpPoolTurn,
246
336
  own: (client: AcpClient) => void,
247
337
  signal: AbortSignal,
248
338
  ): Promise<AcpSession> {
@@ -250,7 +340,14 @@ export class AcpAgent extends SessionAgent {
250
340
  const clientOptions: AcpClientOptions = {
251
341
  launch,
252
342
  cwd: options.cwd,
253
- env: options.env,
343
+ // @ref LLP 0018#acp — the bearer never travels through a proxy
344
+ // In the client's own order: the engine's environment, the launch's, the turn's.
345
+ env: this.host
346
+ ? {
347
+ ...options.env,
348
+ ...loopbackDirect({ ...process.env, ...launch.env, ...options.env }),
349
+ }
350
+ : options.env,
254
351
  clientName: this.agentOptions.clientName,
255
352
  sessionId: options.sessionId,
256
353
  processes: this.processes,
@@ -287,9 +384,14 @@ export class AcpAgent extends SessionAgent {
287
384
  : capabilities?.loadSession
288
385
  ? "session/load"
289
386
  : undefined;
387
+ const given = await this.serversFor(
388
+ options,
389
+ host,
390
+ Boolean(capabilities?.mcpCapabilities?.http),
391
+ );
290
392
  const target = {
291
393
  cwd: options.cwd,
292
- mcpServers: toAcpMcpServers(options.mcpServers),
394
+ mcpServers: toAcpMcpServers(given.servers),
293
395
  // Sent only to agents that advertise it; others keep `cwd` alone.
294
396
  ...(takesDirectories &&
295
397
  options.additionalDirectories?.length && {
@@ -332,7 +434,8 @@ export class AcpAgent extends SessionAgent {
332
434
  const session: AcpSession = {
333
435
  client,
334
436
  acpSessionId,
335
- spawnKey: spawnKey(options, launch, takesDirectories),
437
+ spawnKey: spawnKey(options, launch, takesDirectories, host?.source.name),
438
+ ...(given.hostFailed && { hostFailed: true }),
336
439
  takesDirectories,
337
440
  resumable: resumeMethod !== undefined,
338
441
  configOptions: configOptions ?? [],
@@ -458,6 +561,7 @@ export class AcpAgent extends SessionAgent {
458
561
  elicitation: options.onElicitationRequest,
459
562
  mode: options.permissionMode,
460
563
  signal: controller.signal,
564
+ turnId: options.turnId,
461
565
  };
462
566
  options.onNativeSession?.(session.acpSessionId, {
463
567
  resumed: session.acpSessionId === options.resumeSessionId,
@@ -550,6 +654,7 @@ export class AcpAgent extends SessionAgent {
550
654
  // confirm window, not after it, and its exit is what confirms it.
551
655
  // An agent an eviction or a replacement ended earlier is waited for too.
552
656
  await Promise.all([super.release(sessionId), this.sessions.release(sessionId)]);
657
+ this.host?.release(sessionId);
553
658
  }
554
659
 
555
660
  /** After a host resume, each session's next turn starts its agent again, on its conversation. */
@@ -560,5 +665,6 @@ export class AcpAgent extends SessionAgent {
560
665
  override async terminateAll(): Promise<void> {
561
666
  await super.terminateAll();
562
667
  await this.sessions.closeAll();
668
+ await this.host?.close();
563
669
  }
564
670
  }
@@ -71,7 +71,11 @@ export function toToolResultContent(
71
71
  });
72
72
  }
73
73
 
74
- /** Engine MCP config map → ACP `McpServer[]` (names come from the record keys). */
74
+ /**
75
+ * Engine MCP config map → ACP `McpServer[]` (names come from the record keys).
76
+ * ACP's fields only: a strict agent may refuse one it does not know, and ACP
77
+ * v1 has none for `required` or a tool-call limit (`timeoutMs`).
78
+ */
75
79
  export function toAcpMcpServers(
76
80
  mcpServers: Record<string, McpServerConfig> | undefined,
77
81
  ): McpServer[] {
@@ -27,6 +27,8 @@ export interface TurnScope {
27
27
  elicitation?: ElicitationRequestHandler;
28
28
  mode?: PermissionMode;
29
29
  signal: AbortSignal;
30
+ /** The engine's id of the turn, for a host tool's caller. */
31
+ turnId?: string;
30
32
  }
31
33
 
32
34
  /** The session a request is answered against: its ACP id and the turn running on it. */
@@ -51,7 +51,8 @@ export function startQuery<Q>(permissionMode: string | undefined, start: () => Q
51
51
  /**
52
52
  * The SDK approval callback, fixed at spawn: it asks the turn running when it
53
53
  * is called, which Claude does for a call its mode and rules do not approve
54
- * by themselves (under `bypass_permissions`, only questions and plans). The
54
+ * by themselves (under `bypass_permissions`, questions, plans and, since
55
+ * Claude Code 2.1.326, the few calls it holds back as dangerous). The
55
56
  * host `toolPolicy` sees each such call first (full native PermissionResult
56
57
  * power), questions and plans included; a call it leaves
57
58
  * (`undefined`) goes to the turn: a question to its elicitation, a plan or a
@@ -16,6 +16,7 @@ import { onAbort, untilAborted } from "../../utils/deadline.ts";
16
16
  import { SessionResumeError } from "../../utils/errors.ts";
17
17
  import { UnsupportedAttachmentError, attachedText, isTextMedia } from "../attachments.ts";
18
18
  import type { AgentExecuteOptions, ListModelsOptions } from "../base.ts";
19
+ import { type HostToolSessions, hostToolSessions, refuseHostName } from "../host-tools.ts";
19
20
  import { SessionAgent } from "../session-agent.ts";
20
21
  import { ClaudeCredentials, type ClaudeDelivery, ON_PLACEHOLDER } from "./credentials.ts";
21
22
  import type { ClaudeRawEvent } from "./events.ts";
@@ -125,12 +126,14 @@ export class ClaudeCodeAgent extends SessionAgent {
125
126
  private readonly pool: ClaudeSessionPool;
126
127
  private readonly credentials?: ClaudeCredentials;
127
128
  private readonly cancelGraceMs: number;
129
+ private readonly host?: HostToolSessions;
128
130
 
129
131
  constructor(private readonly agentOptions: ClaudeCodeAgentOptions = {}) {
130
132
  super({ cancelConfirmMs: agentOptions.cancelConfirmMs });
131
133
  this.cancelGraceMs = agentOptions.cancelGraceMs ?? CANCEL_GRACE_MS;
132
134
  this.processes = agentOptions.processes ?? sharedNativeProcesses();
133
- this.pool = claudeSessionPool({ ...agentOptions, processes: this.processes });
135
+ this.host = hostToolSessions(agentOptions.hostTools, this.harness);
136
+ this.pool = claudeSessionPool({ ...agentOptions, processes: this.processes, host: this.host });
134
137
  this.login = new ClaudeCliLogin({
135
138
  resolveCliPath: agentOptions.resolveCliPath,
136
139
  processes: this.processes,
@@ -176,6 +179,11 @@ export class ClaudeCodeAgent extends SessionAgent {
176
179
  const cliPath = resolveCliPath && (await untilAborted(resolveCliPath(), controller.signal));
177
180
  const content = toClaudeContent(input);
178
181
  controller.signal.throwIfAborted();
182
+ const source = await untilAborted(
183
+ Promise.resolve(this.host?.source(options.sessionId, options.cwd)),
184
+ controller.signal,
185
+ );
186
+ if (source) refuseHostName(options.mcpServers, source.name);
179
187
  const thinking = fitClaudeThinking(options.thinkingLevel, options.modelThinking);
180
188
  const turnOptions = this.withDelivery(
181
189
  options,
@@ -196,7 +204,8 @@ export class ClaudeCodeAgent extends SessionAgent {
196
204
  if (thinking.applied && !session.operatorThinking)
197
205
  options.onExecution?.({ thinkingLevel: thinking.applied });
198
206
  const notApplied: Array<keyof RunConfig> = [];
199
- // A model known to have no effort levels is sent no level (`fitClaudeThinking`).
207
+ // A model known to have no effort levels, or whose levels hold no fit for
208
+ // the turn's, is sent no level (`fitClaudeThinking`).
200
209
  if (options.thinkingLevel !== undefined && thinking.send === undefined)
201
210
  notApplied.push("thinkingLevel");
202
211
  // A message to resume at goes only with a resume (`buildClaudeOptions`).
@@ -221,6 +230,7 @@ export class ClaudeCodeAgent extends SessionAgent {
221
230
  if (!attemptedResume && session.currentSessionId) report(session.currentSessionId);
222
231
  const turn = session.sendMessage(content, {
223
232
  turnId: options.turnId,
233
+ signal: controller.signal,
224
234
  permissions: options.onPermissionRequest,
225
235
  elicitation: options.onElicitationRequest,
226
236
  });
@@ -369,6 +379,7 @@ export class ClaudeCodeAgent extends SessionAgent {
369
379
  await super.release(sessionId);
370
380
  await this.pool.release(sessionId);
371
381
  this.credentials?.release(sessionId);
382
+ this.host?.release(sessionId);
372
383
  }
373
384
 
374
385
  override async terminateAll(): Promise<void> {
@@ -377,5 +388,6 @@ export class ClaudeCodeAgent extends SessionAgent {
377
388
  await super.terminateAll();
378
389
  await closed;
379
390
  await this.credentials?.close();
391
+ await this.host?.close();
380
392
  }
381
393
  }
@@ -2,6 +2,7 @@ import type { McpSetServersResult, Query } from "@anthropic-ai/claude-agent-sdk"
2
2
  import type { McpServerConfig } from "../../../protocol/index.ts";
3
3
  import { configFingerprint } from "../config-fingerprint.ts";
4
4
  import {
5
+ type NativeMcpServer,
5
6
  UnavailableMcpServers,
6
7
  mcpConnectionErrors,
7
8
  nativeMcpServer,
@@ -13,6 +14,15 @@ import type { SdkMcpServers } from "./options.ts";
13
14
  /** What an MCP update asks of the live query. */
14
15
  type McpControl = Pick<Query, "setMcpServers" | "mcpServerStatus">;
15
16
 
17
+ /**
18
+ * A turn's server as Claude takes it: its tool-call limit is the SDK's
19
+ * per-server `timeout`, in milliseconds as on the wire.
20
+ */
21
+ export function claudeMcpServer(server: McpServerConfig): NativeMcpServer & { timeout?: number } {
22
+ const native = nativeMcpServer(server);
23
+ return server.timeoutMs === undefined ? native : { ...native, timeout: server.timeoutMs };
24
+ }
25
+
16
26
  function remoteMcpServer(server: McpServerConfig): boolean {
17
27
  return server.type === "http" || server.type === "sse";
18
28
  }
@@ -145,7 +155,7 @@ export class ClaudeMcpConnections {
145
155
  const retry = new Set(this.unavailable.retryNow(servers));
146
156
  const resetNames = Object.keys(servers).filter((name) => failed.has(name) || retry.has(name));
147
157
  const native = Object.fromEntries(
148
- Object.entries(servers).map(([name, server]) => [name, nativeMcpServer(server)]),
158
+ Object.entries(servers).map(([name, server]) => [name, claudeMcpServer(server)]),
149
159
  );
150
160
  const desired = { ...native, ...this.host };
151
161
  const added = new Set<string>();
@@ -7,7 +7,7 @@ import {
7
7
  } from "../../../protocol/index.ts";
8
8
  import type { NativeProcesses } from "../../processes/native-processes.ts";
9
9
  import { onAbort } from "../../utils/deadline.ts";
10
- import { knownThinkingLevels } from "../thinking-levels.ts";
10
+ import { listedThinkingLevels } from "../thinking-levels.ts";
11
11
  import { type ClaudeSessionConfig, buildClaudeOptions } from "./options.ts";
12
12
 
13
13
  /**
@@ -26,7 +26,7 @@ export function claudeModelDescriptors(models: readonly ClaudeModelInfo[]): Mode
26
26
  ...(model.resolvedModel &&
27
27
  model.resolvedModel !== model.value && { resolvedId: model.resolvedModel }),
28
28
  ...(model.value === "default" && { isDefault: true }),
29
- thinking: { levels: knownThinkingLevels(model.supportedEffortLevels ?? []) },
29
+ thinking: { levels: listedThinkingLevels(model.supportedEffortLevels ?? []) },
30
30
  }));
31
31
  }
32
32
 
@@ -35,20 +35,25 @@ export function claudeModelDescriptors(models: readonly ClaudeModelInfo[]): Mode
35
35
  * lowers a level its model lacks on its own and does not say so (`max` and
36
36
  * `xhigh` become `high`), so the level is fitted here, where the model's levels
37
37
  * are known. `off` is sent as it is: some models do not let thinking be
38
- * disabled, and Claude Code then thinks at its default effort; Haiku, which
39
- * Claude Code otherwise starts thinking, does not think with it. A model known
40
- * to have no effort levels (`levels: []`, Haiku) is sent no other level, so it
41
- * is not started on adaptive thinking at an effort it has no control for; a
42
- * model whose levels are unknown (`undefined`) is sent the level as asked.
38
+ * disabled (Haiku 5.5 at `off` still spends thinking tokens, with an empty
39
+ * reasoning part, on Claude Code 2.1.327); Haiku 4.5, which Claude Code
40
+ * otherwise starts thinking, does not think with it. A model known to have no
41
+ * effort levels (`levels: []`, Haiku 4.5) is sent no other level, so it is not
42
+ * started on adaptive thinking at an effort it has no control for: it thinks
43
+ * at its own default, as Claude Code starts it. Neither is a model sent a
44
+ * level that has no fit among the levels it lists. A model whose levels are
45
+ * unknown (`undefined`) is sent the level as asked, but `ultra` as `max`,
46
+ * Claude's ceiling; a model that lists `ultra` is sent it.
43
47
  */
44
48
  export function fitClaudeThinking(
45
49
  level: ThinkingLevel | undefined,
46
50
  levels: readonly ThinkingLevel[] | undefined,
47
51
  ): { send?: ThinkingLevel; applied?: ThinkingLevel } {
48
52
  if (level === undefined) return {};
49
- if (level === "off" || levels === undefined) return { send: level };
50
- if (!levels.length) return {};
51
- const fitted = clampThinkingLevel(level, levels) ?? level;
53
+ if (level === "off") return { send: level };
54
+ if (levels === undefined) return { send: level === "ultra" ? "max" : level };
55
+ const fitted = clampThinkingLevel(level, levels);
56
+ if (fitted === undefined) return {};
52
57
  return { send: fitted, applied: fitted };
53
58
  }
54
59
 
@@ -11,6 +11,7 @@ import type { NativeProcesses } from "../../processes/native-processes.ts";
11
11
  import type { AgentExecuteOptions } from "../base.ts";
12
12
  import { configFingerprint, directoriesFingerprint } from "../config-fingerprint.ts";
13
13
  import type { CredentialSource } from "../credentials.ts";
14
+ import type { HostToolSessions, HostTools } from "../host-tools.ts";
14
15
  import type { InheritConfig } from "../inherit-config.ts";
15
16
  import { type ClaudeSpawn, claudeSpawner } from "./spawn.ts";
16
17
 
@@ -52,7 +53,8 @@ export type ClaudeSdkOptionOverrides = Partial<
52
53
  * asks about, questions (AskUserQuestion) and plan approvals (ExitPlanMode)
53
54
  * included, BEFORE the interactive permission broker and elicitation. Claude
54
55
  * asks about a call its mode and rules do not approve by themselves: under
55
- * `bypass_permissions`, only questions and plans. Returns the SDK's own
56
+ * `bypass_permissions`, questions, plans and, since Claude Code 2.1.326, the
57
+ * few calls it holds back as dangerous. Returns the SDK's own
56
58
  * `PermissionResult` (so hosts keep full native power: `updatedInput`,
57
59
  * `updatedPermissions`) or undefined to fall through to the broker.
58
60
  * Operator embed-tier only — never wire-sourced.
@@ -137,6 +139,11 @@ export interface ClaudeCodeAgentOptions {
137
139
  * wire-configured servers.
138
140
  */
139
141
  sdkMcpServers?: (ctx: SessionSpawn) => SdkMcpServers | Promise<SdkMcpServers>;
142
+ /**
143
+ * The host's tools for each session (LLP 0018), run in process: no secret,
144
+ * no HTTP. A turn's own server may not take their name. Operator-level only.
145
+ */
146
+ hostTools?: HostTools;
140
147
  /**
141
148
  * Pre-broker tool policy (SDK PermissionResult or undefined = fall through
142
149
  * to the interactive broker). Operator embed-tier only.
@@ -153,6 +160,10 @@ export interface ClaudeCodeAgentOptions {
153
160
  * recorders — instead of re-deriving termination from side effects.
154
161
  * NOTE: `replaced` sessions usually respawn immediately with context
155
162
  * preserved; drop only resources bound to the dead subprocess.
163
+ * A cancel during a start answers at once; this callback for that
164
+ * process (`released`, as for a close) can come after the cancel's
165
+ * answer, and comes before that turn's end: set up the next turn's
166
+ * per-session resources after the turn's end, not the cancel's answer.
156
167
  */
157
168
  onSessionEnd?: (sessionId: string, reason: ClaudeSessionEndReason) => void;
158
169
  /** Operational diagnostics (interrupt timeouts). */
@@ -196,6 +207,8 @@ export type ClaudeSessionSettings = ClaudeSessionExtras &
196
207
  Pick<ClaudeCodeAgentOptions, "idleTimeoutMs" | "cancelConfirmMs"> & {
197
208
  /** The agent's: where its sessions' `claude` processes start. */
198
209
  processes: NativeProcesses;
210
+ /** The agent's: its sessions' host tools. */
211
+ host?: HostToolSessions;
199
212
  };
200
213
 
201
214
  /** What a turn asks of the Claude session it runs on. */
@@ -392,6 +405,11 @@ function buildEnv(
392
405
  };
393
406
  }
394
407
 
408
+ /** Whether Claude Code reads a flag as on: `1`, `true`, `yes` or `on`, in any case (2.1.327). */
409
+ function envFlagOn(value: string | undefined): boolean {
410
+ return ["1", "true", "yes", "on"].includes((value ?? "").trim().toLowerCase());
411
+ }
412
+
395
413
  /** The environment Claude Code runs a turn with this `env` in, which decides whose login it runs on. */
396
414
  export function claudeEnv(
397
415
  config: Pick<ClaudeSessionConfig, "env" | "inheritConfig">,
@@ -440,8 +458,10 @@ export function buildClaudeOptions(
440
458
  options.thinking = { type: "disabled" };
441
459
  } else {
442
460
  options.thinking = { type: "adaptive" };
443
- // Claude's ceiling is `max`.
444
- options.effort = config.thinkingLevel === "ultra" ? "max" : config.thinkingLevel;
461
+ // The level as `fitClaudeThinking` gave it. The SDK types `effort` as
462
+ // the levels it knows; one beyond them (a level the model lists, or
463
+ // any when its levels are unknown) goes to the CLI as it is named.
464
+ options.effort = config.thinkingLevel as CCOptions["effort"];
445
465
  }
446
466
  }
447
467
  if (config.resumeSessionId) {
@@ -462,7 +482,21 @@ export function buildClaudeOptions(
462
482
  // this function returns, so those can never be clobbered (and the
463
483
  // ClaudeSdkOptionOverrides type excludes them anyway).
464
484
  if (overrides) Object.assign(options, overrides);
485
+ // @ref LLP 0001#d4--permission-requests-are-first-class-protocol — plan mode asks through the broker
486
+ // On a model with auto mode, plan mode takes auto mode's semantics: calls run that the broker
487
+ // never sees. Off beneath the operator's own settings object; a path, or `extraArgs.settings`, stays theirs.
488
+ if (typeof options.settings !== "string" && options.extraArgs?.settings === undefined)
489
+ options.settings = { useAutoModeDuringPlan: false, ...options.settings };
465
490
  if (config.subagentMode === "turn") options.forwardSubagentText = true;
491
+ // @ref LLP 0001#d14--nothing-the-agent-does-is-off-the-stream — a watch outlives its turn
492
+ // Claude Code 2.1.327 offers `Monitor` with background tasks off: its watch
493
+ // runs past the turn and Claude answers each line with a query of its own,
494
+ // which no turn shows. With background tasks off it is off too, beside the
495
+ // operator's own denials; an env that turns them on leaves it alone.
496
+ if (envFlagOn(options.env?.CLAUDE_CODE_DISABLE_BACKGROUND_TASKS)) {
497
+ const denied = options.disallowedTools ?? [];
498
+ if (!denied.includes("Monitor")) options.disallowedTools = [...denied, "Monitor"];
499
+ }
466
500
  // Engine wiring over the operator's: their spawner still runs, as theirs.
467
501
  if (spawn)
468
502
  options.spawnClaudeCodeProcess = claudeSpawner(
@@ -14,6 +14,7 @@ import type { NativeProcess } from "../../processes/native-processes.ts";
14
14
  import { onAbort, untilAborted, withTimeout } from "../../utils/deadline.ts";
15
15
  import { SessionResumeError } from "../../utils/errors.ts";
16
16
  import { CANCEL_CONFIRM_MS } from "../base.ts";
17
+ import type { LiveTurn } from "../host-tools.ts";
17
18
  import {
18
19
  IDLE_TIMEOUT_MS,
19
20
  type PooledClient,
@@ -30,6 +31,7 @@ import {
30
31
  type ClaudeSessionConfig,
31
32
  type ClaudeSessionEndReason,
32
33
  type ClaudeSessionSettings,
34
+ type SdkMcpServers,
33
35
  buildClaudeOptions,
34
36
  claudeSpawnKey,
35
37
  fromSdkPermissionMode,
@@ -217,11 +219,27 @@ export class ClaudeSession implements PooledProcess, PooledClient {
217
219
  return true;
218
220
  }
219
221
 
222
+ /** The turn running now and the mode the process runs in, for a host tool's caller. */
223
+ private liveTurn(): ReturnType<LiveTurn> {
224
+ return this.turn
225
+ ? {
226
+ turnId: this.turn.id,
227
+ permissionMode: this.config.permissionMode ?? "default",
228
+ signal: this.turn.signal,
229
+ }
230
+ : undefined;
231
+ }
232
+
220
233
  async start(): Promise<void> {
221
234
  if (this.state !== "starting") throw new Error(`Cannot start in state: ${this.state}`);
222
235
  const sdk = await import("@anthropic-ai/claude-agent-sdk");
223
236
  const spawn = { sessionId: this.id, cwd: this.config.cwd };
224
- const hostServers = await this.settings.sdkMcpServers?.(spawn);
237
+ const source = await this.settings.host?.source(this.id, this.config.cwd);
238
+ const hostServers: SdkMcpServers = { ...(await this.settings.sdkMcpServers?.(spawn)) };
239
+ if (source && this.settings.host)
240
+ hostServers[source.name] = this.settings.host.inProcess(this.id, source, () =>
241
+ this.liveTurn(),
242
+ ) as unknown as SdkMcpServers[string];
225
243
  this.mcp.useHostServers(hostServers);
226
244
  const overrides = await this.settings.sdkOptions?.(spawn);
227
245
  this.thinkingOverridden = Boolean(
@@ -234,6 +252,13 @@ export class ClaudeSession implements PooledProcess, PooledClient {
234
252
  this.native = native;
235
253
  },
236
254
  });
255
+ // @ref LLP 0018#permissions — a read-only host tool runs unasked, as on Codex; any other asks
256
+ const readOnly = (source?.tools ?? []).filter((tool) => tool.annotations?.readOnly);
257
+ if (source && readOnly.length)
258
+ options.allowedTools = [
259
+ ...(options.allowedTools ?? []),
260
+ ...readOnly.map((tool) => `mcp__${source.name}__${tool.name}`),
261
+ ];
237
262
  if (this.settings.hooks) {
238
263
  options.hooks = this.settings.hooks({
239
264
  sessionId: this.id,
@@ -14,12 +14,14 @@ import type { McpTool, ToolKind, ToolLocation, ToolMeta } from "../../../protoco
14
14
  * CLI offers that is not here, so a pin bump decides it.
15
15
  */
16
16
  export const CLAUDE_TOOL_KINDS: ReadonlyMap<string, ToolKind> = new Map<string, ToolKind>([
17
- // What the pinned CLI (2.1.288) offers, with the engine's options or a product's.
17
+ // What the pinned CLI offers, with the engine's options or a product's.
18
18
  ["Read", "read"],
19
19
  ["Edit", "edit"],
20
20
  ["Write", "edit"],
21
21
  ["NotebookEdit", "edit"],
22
22
  ["Bash", "execute"],
23
+ // Runs a shell command and reports its output as it comes.
24
+ ["Monitor", "execute"],
23
25
  // Stops a background shell or sub-agent the agent started.
24
26
  ["TaskStop", "execute"],
25
27
  // Runs a script the agent wrote, which starts sub-agents of its own.
@@ -28,6 +30,8 @@ export const CLAUDE_TOOL_KINDS: ReadonlyMap<string, ToolKind> = new Map<string,
28
30
  ["WebSearch", "fetch"],
29
31
  // Loads a skill's instructions into the conversation.
30
32
  ["Skill", "read"],
33
+ // Loads the definition of a tool the CLI held back: nothing of the person's.
34
+ ["ToolSearch", "other"],
31
35
  // The sub-agent tool: `init` names it `Task`, the model `Agent`. A spawn is `task` by its subagent.
32
36
  ["Task", "think"],
33
37
  ["Agent", "think"],
@@ -77,8 +81,8 @@ function toolLocationsFromInput(input: Record<string, unknown>): ToolLocation[]
77
81
  const MCP_PREFIX = "mcp__";
78
82
 
79
83
  /**
80
- * A server's name as Claude Code spells it in a tool name (the pinned CLI
81
- * 2.1.288, SDK 0.3.288, and 2.1.325 alike):
84
+ * A server's name as Claude Code spells it in a tool name (the pinned CLI;
85
+ * 2.1.288 and 2.1.325 spell it alike, observed 2026-11-16):
82
86
  * other than letters, digits, `_` and `-` become `_`, and a claude.ai
83
87
  * connector's runs of `_` collapse.
84
88
  */
@@ -131,7 +135,9 @@ export function claudeToolMeta(
131
135
  servers?: Iterable<string>,
132
136
  ): ToolMeta {
133
137
  const mcp = claudeMcpTool(toolName, servers);
134
- const command = toolName === "Bash" ? textOf(input, "command") : undefined;
138
+ // A `Monitor` on a WebSocket has no command.
139
+ const command =
140
+ toolName === "Bash" || toolName === "Monitor" ? textOf(input, "command") : undefined;
135
141
  const url = toolName === "WebFetch" ? textOf(input, "url") : undefined;
136
142
  return {
137
143
  kind: CLAUDE_TOOL_KINDS.get(toolName) ?? "other",