@zvada/agent-server 0.3.25 → 0.3.27

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 (256) hide show
  1. package/CHANGELOG.md +113 -0
  2. package/README.md +4 -1
  3. package/dist/client/client.js +27 -11
  4. package/dist/client/connection.js +35 -3
  5. package/dist/core/agents/acp/acp-agent.js +91 -14
  6. package/dist/core/agents/acp/mappings.js +5 -1
  7. package/dist/core/agents/claude-code/approvals.js +3 -2
  8. package/dist/core/agents/claude-code/claude-agent.js +12 -2
  9. package/dist/core/agents/claude-code/mcp.js +9 -1
  10. package/dist/core/agents/claude-code/models.js +16 -10
  11. package/dist/core/agents/claude-code/options.js +23 -2
  12. package/dist/core/agents/claude-code/session.js +21 -1
  13. package/dist/core/agents/claude-code/tools.js +9 -4
  14. package/dist/core/agents/claude-code/turn.js +2 -0
  15. package/dist/core/agents/codex-app-server/adapter.js +2 -0
  16. package/dist/core/agents/codex-app-server/client.js +8 -5
  17. package/dist/core/agents/codex-app-server/codex-agent.js +35 -2
  18. package/dist/core/agents/codex-app-server/effort.js +13 -6
  19. package/dist/core/agents/codex-app-server/mcp.js +35 -18
  20. package/dist/core/agents/codex-app-server/models.js +10 -10
  21. package/dist/core/agents/codex-app-server/options.js +11 -2
  22. package/dist/core/agents/codex-app-server/plan-approval.js +1 -1
  23. package/dist/core/agents/codex-app-server/session.js +11 -4
  24. package/dist/core/agents/codex-app-server/thread-settings.js +30 -11
  25. package/dist/core/agents/host-tools.js +493 -0
  26. package/dist/core/agents/mcp-config.js +6 -2
  27. package/dist/core/agents/scripted/scripted-agent.js +39 -6
  28. package/dist/core/agents/scripted/steps.js +5 -1
  29. package/dist/core/agents/session-agent.js +70 -2
  30. package/dist/core/agents/thinking-levels.js +8 -5
  31. package/dist/core/index.js +1 -0
  32. package/dist/core/presets.js +16 -3
  33. package/dist/core/processes/lifeline.js +9 -5
  34. package/dist/core/provision/pins.js +7 -16
  35. package/dist/core/provision/releases.js +25 -25
  36. package/dist/core/proxy/loopback.js +22 -4
  37. package/dist/core/runtime/agent-runtime.js +15 -5
  38. package/dist/core/runtime/event-processor.js +13 -8
  39. package/dist/core/runtime/origin-line.js +42 -0
  40. package/dist/core/runtime/request-broker.js +2 -1
  41. package/dist/core/runtime/steering.js +4 -3
  42. package/dist/core/runtime/turn.js +6 -4
  43. package/dist/operator/errors.js +97 -0
  44. package/dist/operator/index.js +10 -5
  45. package/dist/operator/mcp.js +7 -12
  46. package/dist/operator/operator.js +1336 -380
  47. package/dist/operator/refs.js +59 -0
  48. package/dist/operator/render.js +171 -74
  49. package/dist/operator/session-tools.js +87 -0
  50. package/dist/operator/types.js +30 -0
  51. package/dist/operator/view.js +82 -27
  52. package/dist/protocol/config.js +33 -6
  53. package/dist/protocol/conversation.js +3 -0
  54. package/dist/protocol/history.js +2 -1
  55. package/dist/protocol/index.js +1 -0
  56. package/dist/protocol/lifecycle.js +19 -0
  57. package/dist/protocol/model-catalog.js +58 -18
  58. package/dist/protocol/models.js +6 -27
  59. package/dist/protocol/origin.js +39 -0
  60. package/dist/protocol/reduce.js +2 -0
  61. package/dist/protocol/thinking.js +22 -9
  62. package/dist/protocol/wire-api.js +2 -2
  63. package/dist/protocol/wire.js +17 -0
  64. package/dist/server/bin.js +6 -4
  65. package/dist/server/routes.js +15 -5
  66. package/dist/types/client/client.d.ts.map +1 -1
  67. package/dist/types/client/connection.d.ts +14 -2
  68. package/dist/types/client/connection.d.ts.map +1 -1
  69. package/dist/types/client/turns.d.ts +2 -2
  70. package/dist/types/client/turns.d.ts.map +1 -1
  71. package/dist/types/core/agents/acp/acp-agent.d.ts +15 -0
  72. package/dist/types/core/agents/acp/acp-agent.d.ts.map +1 -1
  73. package/dist/types/core/agents/acp/mappings.d.ts +5 -1
  74. package/dist/types/core/agents/acp/mappings.d.ts.map +1 -1
  75. package/dist/types/core/agents/acp/requests.d.ts +2 -0
  76. package/dist/types/core/agents/acp/requests.d.ts.map +1 -1
  77. package/dist/types/core/agents/base.d.ts +2 -0
  78. package/dist/types/core/agents/base.d.ts.map +1 -1
  79. package/dist/types/core/agents/claude-code/approvals.d.ts +2 -1
  80. package/dist/types/core/agents/claude-code/approvals.d.ts.map +1 -1
  81. package/dist/types/core/agents/claude-code/claude-agent.d.ts +1 -0
  82. package/dist/types/core/agents/claude-code/claude-agent.d.ts.map +1 -1
  83. package/dist/types/core/agents/claude-code/mcp.d.ts +8 -1
  84. package/dist/types/core/agents/claude-code/mcp.d.ts.map +1 -1
  85. package/dist/types/core/agents/claude-code/models.d.ts +9 -5
  86. package/dist/types/core/agents/claude-code/models.d.ts.map +1 -1
  87. package/dist/types/core/agents/claude-code/options.d.ts +10 -1
  88. package/dist/types/core/agents/claude-code/options.d.ts.map +1 -1
  89. package/dist/types/core/agents/claude-code/session.d.ts +2 -0
  90. package/dist/types/core/agents/claude-code/session.d.ts.map +1 -1
  91. package/dist/types/core/agents/claude-code/tools.d.ts.map +1 -1
  92. package/dist/types/core/agents/claude-code/turn.d.ts +3 -0
  93. package/dist/types/core/agents/claude-code/turn.d.ts.map +1 -1
  94. package/dist/types/core/agents/codex-app-server/adapter.d.ts.map +1 -1
  95. package/dist/types/core/agents/codex-app-server/client.d.ts +2 -0
  96. package/dist/types/core/agents/codex-app-server/client.d.ts.map +1 -1
  97. package/dist/types/core/agents/codex-app-server/codex-agent.d.ts +11 -0
  98. package/dist/types/core/agents/codex-app-server/codex-agent.d.ts.map +1 -1
  99. package/dist/types/core/agents/codex-app-server/effort.d.ts +7 -7
  100. package/dist/types/core/agents/codex-app-server/effort.d.ts.map +1 -1
  101. package/dist/types/core/agents/codex-app-server/mcp.d.ts +11 -3
  102. package/dist/types/core/agents/codex-app-server/mcp.d.ts.map +1 -1
  103. package/dist/types/core/agents/codex-app-server/models.d.ts +4 -1
  104. package/dist/types/core/agents/codex-app-server/models.d.ts.map +1 -1
  105. package/dist/types/core/agents/codex-app-server/options.d.ts +9 -2
  106. package/dist/types/core/agents/codex-app-server/options.d.ts.map +1 -1
  107. package/dist/types/core/agents/codex-app-server/requests.d.ts +2 -0
  108. package/dist/types/core/agents/codex-app-server/requests.d.ts.map +1 -1
  109. package/dist/types/core/agents/codex-app-server/session.d.ts +6 -3
  110. package/dist/types/core/agents/codex-app-server/session.d.ts.map +1 -1
  111. package/dist/types/core/agents/codex-app-server/thread-settings.d.ts.map +1 -1
  112. package/dist/types/core/agents/host-tools.d.ts +162 -0
  113. package/dist/types/core/agents/host-tools.d.ts.map +1 -0
  114. package/dist/types/core/agents/mcp-config.d.ts +11 -2
  115. package/dist/types/core/agents/mcp-config.d.ts.map +1 -1
  116. package/dist/types/core/agents/scripted/scripted-agent.d.ts +14 -1
  117. package/dist/types/core/agents/scripted/scripted-agent.d.ts.map +1 -1
  118. package/dist/types/core/agents/scripted/steps.d.ts.map +1 -1
  119. package/dist/types/core/agents/session-agent.d.ts +2 -7
  120. package/dist/types/core/agents/session-agent.d.ts.map +1 -1
  121. package/dist/types/core/agents/thinking-levels.d.ts +7 -3
  122. package/dist/types/core/agents/thinking-levels.d.ts.map +1 -1
  123. package/dist/types/core/index.d.ts +1 -0
  124. package/dist/types/core/index.d.ts.map +1 -1
  125. package/dist/types/core/presets.d.ts +11 -1
  126. package/dist/types/core/presets.d.ts.map +1 -1
  127. package/dist/types/core/processes/lifeline.d.ts.map +1 -1
  128. package/dist/types/core/provision/pins.d.ts +5 -4
  129. package/dist/types/core/provision/pins.d.ts.map +1 -1
  130. package/dist/types/core/proxy/loopback.d.ts.map +1 -1
  131. package/dist/types/core/runtime/agent-runtime.d.ts +4 -2
  132. package/dist/types/core/runtime/agent-runtime.d.ts.map +1 -1
  133. package/dist/types/core/runtime/event-processor.d.ts +2 -2
  134. package/dist/types/core/runtime/event-processor.d.ts.map +1 -1
  135. package/dist/types/core/runtime/origin-line.d.ts +15 -0
  136. package/dist/types/core/runtime/origin-line.d.ts.map +1 -0
  137. package/dist/types/core/runtime/request-broker.d.ts +1 -1
  138. package/dist/types/core/runtime/request-broker.d.ts.map +1 -1
  139. package/dist/types/core/runtime/steering.d.ts +7 -4
  140. package/dist/types/core/runtime/steering.d.ts.map +1 -1
  141. package/dist/types/core/runtime/turn.d.ts.map +1 -1
  142. package/dist/types/operator/errors.d.ts +83 -0
  143. package/dist/types/operator/errors.d.ts.map +1 -0
  144. package/dist/types/operator/index.d.ts +10 -5
  145. package/dist/types/operator/index.d.ts.map +1 -1
  146. package/dist/types/operator/mcp.d.ts +1 -1
  147. package/dist/types/operator/mcp.d.ts.map +1 -1
  148. package/dist/types/operator/operator.d.ts +15 -197
  149. package/dist/types/operator/operator.d.ts.map +1 -1
  150. package/dist/types/operator/refs.d.ts +25 -0
  151. package/dist/types/operator/refs.d.ts.map +1 -0
  152. package/dist/types/operator/render.d.ts +59 -19
  153. package/dist/types/operator/render.d.ts.map +1 -1
  154. package/dist/types/operator/session-tools.d.ts +61 -0
  155. package/dist/types/operator/session-tools.d.ts.map +1 -0
  156. package/dist/types/operator/types.d.ts +441 -0
  157. package/dist/types/operator/types.d.ts.map +1 -0
  158. package/dist/types/operator/view.d.ts +19 -29
  159. package/dist/types/operator/view.d.ts.map +1 -1
  160. package/dist/types/protocol/config.d.ts +32 -24
  161. package/dist/types/protocol/config.d.ts.map +1 -1
  162. package/dist/types/protocol/conversation.d.ts +48 -39
  163. package/dist/types/protocol/conversation.d.ts.map +1 -1
  164. package/dist/types/protocol/execution.d.ts +2 -18
  165. package/dist/types/protocol/execution.d.ts.map +1 -1
  166. package/dist/types/protocol/history.d.ts +1 -1
  167. package/dist/types/protocol/history.d.ts.map +1 -1
  168. package/dist/types/protocol/index.d.ts +1 -0
  169. package/dist/types/protocol/index.d.ts.map +1 -1
  170. package/dist/types/protocol/lifecycle.d.ts +48 -74
  171. package/dist/types/protocol/lifecycle.d.ts.map +1 -1
  172. package/dist/types/protocol/model-catalog.d.ts.map +1 -1
  173. package/dist/types/protocol/models.d.ts +4 -42
  174. package/dist/types/protocol/models.d.ts.map +1 -1
  175. package/dist/types/protocol/origin.d.ts +49 -0
  176. package/dist/types/protocol/origin.d.ts.map +1 -0
  177. package/dist/types/protocol/reduce.d.ts.map +1 -1
  178. package/dist/types/protocol/thinking.d.ts +19 -19
  179. package/dist/types/protocol/thinking.d.ts.map +1 -1
  180. package/dist/types/protocol/wire-api.d.ts +59 -106
  181. package/dist/types/protocol/wire-api.d.ts.map +1 -1
  182. package/dist/types/protocol/wire.d.ts +81 -119
  183. package/dist/types/protocol/wire.d.ts.map +1 -1
  184. package/dist/types/server/routes.d.ts.map +1 -1
  185. package/docs/consuming.md +124 -132
  186. package/docs/deploy.md +6 -5
  187. package/docs/harnesses.md +79 -31
  188. package/docs/sync-history.md +2 -1
  189. package/package.json +4 -4
  190. package/src/client/client.ts +36 -9
  191. package/src/client/connection.ts +31 -1
  192. package/src/client/turns.ts +2 -1
  193. package/src/core/agents/acp/acp-agent.ts +123 -17
  194. package/src/core/agents/acp/mappings.ts +5 -1
  195. package/src/core/agents/acp/requests.ts +2 -0
  196. package/src/core/agents/base.ts +2 -0
  197. package/src/core/agents/claude-code/approvals.ts +4 -3
  198. package/src/core/agents/claude-code/claude-agent.ts +14 -2
  199. package/src/core/agents/claude-code/mcp.ts +11 -1
  200. package/src/core/agents/claude-code/models.ts +15 -10
  201. package/src/core/agents/claude-code/options.ts +33 -3
  202. package/src/core/agents/claude-code/session.ts +26 -1
  203. package/src/core/agents/claude-code/tools.ts +10 -4
  204. package/src/core/agents/claude-code/turn.ts +4 -0
  205. package/src/core/agents/codex-app-server/adapter.ts +2 -0
  206. package/src/core/agents/codex-app-server/client.ts +11 -5
  207. package/src/core/agents/codex-app-server/codex-agent.ts +45 -1
  208. package/src/core/agents/codex-app-server/effort.ts +15 -20
  209. package/src/core/agents/codex-app-server/mcp.ts +46 -23
  210. package/src/core/agents/codex-app-server/models.ts +10 -10
  211. package/src/core/agents/codex-app-server/options.ts +16 -2
  212. package/src/core/agents/codex-app-server/plan-approval.ts +1 -1
  213. package/src/core/agents/codex-app-server/requests.ts +2 -0
  214. package/src/core/agents/codex-app-server/session.ts +19 -4
  215. package/src/core/agents/codex-app-server/thread-settings.ts +31 -11
  216. package/src/core/agents/host-tools.ts +649 -0
  217. package/src/core/agents/mcp-config.ts +15 -3
  218. package/src/core/agents/scripted/scripted-agent.ts +51 -5
  219. package/src/core/agents/scripted/steps.ts +5 -1
  220. package/src/core/agents/session-agent.ts +78 -2
  221. package/src/core/agents/thinking-levels.ts +9 -6
  222. package/src/core/index.ts +9 -0
  223. package/src/core/presets.ts +28 -4
  224. package/src/core/processes/lifeline.ts +9 -5
  225. package/src/core/provision/pins.ts +7 -16
  226. package/src/core/provision/releases.ts +25 -25
  227. package/src/core/proxy/loopback.ts +25 -4
  228. package/src/core/runtime/agent-runtime.ts +31 -7
  229. package/src/core/runtime/event-processor.ts +13 -6
  230. package/src/core/runtime/origin-line.ts +43 -0
  231. package/src/core/runtime/request-broker.ts +2 -0
  232. package/src/core/runtime/steering.ts +8 -4
  233. package/src/core/runtime/turn.ts +11 -4
  234. package/src/operator/errors.ts +218 -0
  235. package/src/operator/index.ts +18 -23
  236. package/src/operator/mcp.ts +7 -16
  237. package/src/operator/operator.ts +1583 -613
  238. package/src/operator/refs.ts +75 -0
  239. package/src/operator/render.ts +208 -98
  240. package/src/operator/session-tools.ts +126 -0
  241. package/src/operator/types.ts +505 -0
  242. package/src/operator/view.ts +93 -42
  243. package/src/protocol/config.ts +36 -7
  244. package/src/protocol/conversation.ts +3 -0
  245. package/src/protocol/history.ts +2 -1
  246. package/src/protocol/index.ts +1 -0
  247. package/src/protocol/lifecycle.ts +21 -0
  248. package/src/protocol/model-catalog.ts +58 -18
  249. package/src/protocol/models.ts +6 -26
  250. package/src/protocol/origin.ts +47 -0
  251. package/src/protocol/reduce.ts +4 -0
  252. package/src/protocol/thinking.ts +27 -14
  253. package/src/protocol/wire-api.ts +2 -2
  254. package/src/protocol/wire.ts +18 -0
  255. package/src/server/bin.ts +6 -4
  256. package/src/server/routes.ts +16 -5
package/CHANGELOG.md CHANGED
@@ -7,6 +7,119 @@ and the measurements. Evidence lives in the LLP, not here. A release groups
7
7
  its bullets under Breaking, Added, Changed and Fixed, breaking first. The
8
8
  released sections below that predate this convention are kept as written.
9
9
 
10
+ ## 0.3.27
11
+
12
+ ### Breaking
13
+
14
+ - `./operator` is v2 and replaces v1: callers are `SessionCaller` or `ExternalCaller`,
15
+ the host is the new `OperatorHost` (`list`, `view`, `send` and capabilities), and the
16
+ tools are `whoami`, `list_sessions`, `read_session`, `wait_for_sessions`, `list_models`,
17
+ `start_session`, `send_message`, `answer_request`, `stop_sessions`, `archive` (LLP 0019).
18
+ - The operator holds nothing between calls: a message is sent only while its call is
19
+ open. A host refuses at its own commit by throwing `Refused` (code, sessions, state);
20
+ caps across starters are the host's, and `start` delivers the first task as the turn
21
+ `StartInput.turnId` (LLP 0019).
22
+
23
+ ### Added
24
+
25
+ - `origin` on `turn/start`, `turn/steer` and `RunRequest` (`OriginSchema`: `person`,
26
+ `session`, `assistant`): the agent reads one line saying an agent sent it, the user
27
+ message's `message.started` carries `origin`, and a retry from another sender is
28
+ `turnConflict`. `initialize` answers `features: ["origin"]`; the client refuses a
29
+ non-person origin to a server without it, re-sends after a redial included. An
30
+ origin's ids and names are at most 255 characters (`ORIGIN_FIELD_MAX`); a
31
+ `TurnHandle`'s `steer` takes one. Conversation checkpoints are format `v2` (LLP 0019).
32
+ - `permission.requested` says what it decides: `purpose` is `plan` for a plan's
33
+ approval and `tool` otherwise (`PERMISSION_PURPOSES`, open; none reads as `tool`).
34
+ `./operator` reads a plan from it, not from its option ids (LLP 0002, Permissions).
35
+ - `operatorSessionTools` and `OPERATOR_GUIDANCE`: the operator as a session's own
36
+ tools, through the engine's delivery of host tools (LLP 0019, LLP 0018).
37
+ - A host's own tool is given its call's deadline and signal (`CallScope`), and a
38
+ refusal's archive hint names a workspace's only chat as its workspace (`Archivable`;
39
+ `refuse.hasChildren` and `refuse.limitSessions` take one) (LLP 0019).
40
+ - `OperatorOptions.onError(error, tool, caller)`: the host sees each unexpected failure a
41
+ call answers without, once; never a refusal, and it cannot change the answer (LLP 0019).
42
+
43
+ ## 0.3.26
44
+
45
+ ### Breaking
46
+
47
+ - `ThinkingLevel` is an open vocabulary: the type widens, so an exhaustive `switch` over
48
+ it no longer type-checks (`KnownThinkingLevel` is the seven), and `decodeModelList` is
49
+ removed. A model's `thinking.levels` holds every level its harness lists; a level it
50
+ does not list is fitted to the nearest, or not applied, and the turn says so (LLP 0002).
51
+ - Claude SDK 0.3.327 checks the options the engine passes on from yours: a hook
52
+ event's value and a matcher's `hooks` must be arrays, an option it cannot send to
53
+ Claude Code (a circular or BigInt field) is refused, and it needs Node 18.14 or
54
+ newer (LLP 0004, A pin bump).
55
+ - `sdkOptions.sandbox` no longer approves sandboxed Bash commands by itself (Claude
56
+ SDK 0.3.325): set `autoAllowBashIfSandboxed: true` in it to keep that (LLP 0004,
57
+ A pin bump).
58
+
59
+ ### Added
60
+
61
+ - An MCP server's entry takes an optional `timeoutMs`, how long one call to its tools may
62
+ run: it becomes Claude's per-server `timeout` and Codex's `tool_timeout_sec`. Without it
63
+ Claude cuts a call to an HTTP or SSE server at 60 s (or at `MCP_TOOL_TIMEOUT`) and Codex
64
+ a call at 300 s; an ACP agent is not given it and keeps its own (LLP 0001, D15; LLP 0015.001).
65
+ - `hostTools` (registry option, types `HostTools`, `HostToolSource`, `HostToolCaller`):
66
+ a product's own tools reach every harness under one server name, Claude in process,
67
+ Codex and HTTP-capable ACP agents at the engine's loopback by a per-session secret;
68
+ each call names its session, turn and current mode (LLP 0018). A call is held to the
69
+ source's limit, over ACP a tool that writes runs only with full access, the harness
70
+ process reaches the loopback past any proxy (`NO_PROXY`), and the session's secret is
71
+ redacted from every event, warning and error the turn lets out (LLP 0018).
72
+
73
+ ### Changed
74
+
75
+ - A turn's own MCP server named like the host's tools is refused, `invalid_request`
76
+ (LLP 0018, The API).
77
+
78
+ - The pinned Codex is 0.169.1 (it was 0.160.0). Its models add `gpt-6.2-sol`, the default
79
+ in place of `gpt-6.1-sol`, and `gpt-6.2-astra`; neither has an `off` effort, so a turn
80
+ at `thinkingLevel: "off"` runs them at `low` and says so (`appliedThinkingLevel`)
81
+ (LLP 0004, A pin bump).
82
+ - With `codexAppServer.builtInTools.local: false` Codex (since 0.164) still lists
83
+ `apply_patch` to the model and refuses each call, writing nothing; the engine now also
84
+ switches `view_image` off. A refused call is not on the stream: say in your agent's
85
+ instructions that it has no files (LLP 0017, Each turn names its environments).
86
+ - A cancel that lands as an approved Codex command starts (within 110 ms, measured on
87
+ Linux) answers `confirmed: false` with the default deadlines, and Codex's process is
88
+ ended: since 0.169.1 Codex ends such a command itself and says nothing of it. The
89
+ command is stopped either way (LLP 0002, Tools a turn leaves open).
90
+ - Claude runs on Claude SDK 0.3.327 and Claude Code 2.1.327 (from 0.3.288 and
91
+ 2.1.288). `fable` runs Fable 5.2, and `haiku` Haiku 5.5, which has thinking
92
+ levels; the models they ran stay as `claude-fable-5-1` and
93
+ `claude-haiku-4-5-20251001` (LLP 0004, A pin bump).
94
+ - `Monitor` is kept off while background tasks are off, beside your own
95
+ `disallowedTools`: Claude Code 2.1.327 offers it, and its watch outlives the turn
96
+ with requests no turn shows. An env that turns background tasks on leaves it (LLP
97
+ 0001, D14).
98
+ - `ToolSearch` parts appear on the stream (kind `other`): Claude Code 2.1.327 holds
99
+ some tools back, `ExitPlanMode`, `WebFetch` and MCP tools among them, and loads
100
+ them through it before their call (LLP 0002, A tool call says what it acts on).
101
+ - The lifeline shell, the one process that lives as long as the engine, is given `PATH`
102
+ alone, so it holds no secret of the host's (LLP 0007, The environment a process is
103
+ given).
104
+
105
+ ### Fixed
106
+
107
+ - Under Bun, the engine's loopback (the host's tools, the Anthropic proxy) answers in a
108
+ process whose global `Response` a framework replaced (Hono's Node server): `Bun.serve`
109
+ refused every answer before (LLP 0018, Codex).
110
+
111
+ - A Codex turn on `gpt-6.2-sol` or `gpt-6.2-astra` runs, and so does a turn that names no
112
+ model on an account whose own default is one of them: Codex 0.160.0 refused both
113
+ models (LLP 0004, A pin bump).
114
+ - `plan` asks before a read outside the folder, a shell write or an MCP tool on every
115
+ model: the engine sets `useAutoModeDuringPlan: false` beneath your
116
+ `sdkOptions.settings` (your keys win; a settings path is left as it is). On Sonnet
117
+ 5.5, which `haiku` plans on, those ran unasked (LLP 0001, D4).
118
+ - A scripted turn cancelled before the harness has it takes its own steps, so a queue or
119
+ file script's next turn plays its own, not the cancelled one's (and no longer hangs on its
120
+ `hang`, which takes `stopTakes`, except in an async generator's script). A script given as
121
+ a function is now called for such a turn too (LLP 0016.000, The scripted harness; LLP 0001, D23).
122
+
10
123
  ## 0.3.25
11
124
 
12
125
  ### Changed
package/README.md CHANGED
@@ -14,7 +14,7 @@ One package, seven seats — pick the subpath for how you consume it:
14
14
  | `@zvada/agent-server/server` | **The standard wire** — serve the engine over JSON-RPC 2.0 NDJSON (stdio / WebSocket listen / dial-out) with quick-ack turns, per-session `seq`, bounded replay, and an ACP v1 binding (`--acp`). Ships the `agent-server` bin. |
15
15
  | `@zvada/agent-server/client` | **The typed consumer client** — spawn/connect/attach, `runTurn` as an async iterable, permission responses, reconnect with sequenced replay healing (a turn start whose ack a dropped connection lost is re-sent and joins the running turn), `subscribe` / `joinTurn` to follow a session or a turn another client started, the harnesses' logins (`authStatus`, `login`). Depends only on the contract + node builtins. |
16
16
  | `@zvada/agent-server/accounts` | **A login the product holds** — sign a subscription in for a credential the product stores (ChatGPT, Claude), renew it, and answer each turn's credential request (`createCredentialHandler`, `credentialsFrom`). `fetch` and Web Crypto only: it runs in a Worker. |
17
- | `@zvada/agent-server/operator` | **Operator tools** — the session tools an outside agent (a hosted assistant, a CLI agent) operates your product's coding agents with, over an `OperatorHost` you implement, and a dependency-free MCP binding (`createMcpHandler`). Protocol and zod only. See [consuming](docs/consuming.md#let-an-outside-agent-operate-your-sessions) and LLP 0014. |
17
+ | `@zvada/agent-server/operator` | **Operator tools** — the session tools an outside assistant, your window or your own sessions' agents operate your product's coding agents with, over an `OperatorHost` you implement, and a dependency-free MCP binding (`createMcpHandler`). Protocol and zod only. See [consuming](docs/consuming.md#let-agents-operate-your-sessions), LLP 0014 and LLP 0019. |
18
18
  | `@zvada/agent-server/sync` | **Experimental.** Optional durable journal port and history helpers: transfer, open, follow, managed sync. |
19
19
  | `@zvada/agent-server/sync/sqlite` | **Experimental.** Bun SQLite journal with its history and checkpoint store. |
20
20
  | `@zvada/agent-server/sync/node-sqlite` | **Experimental.** Same storage under Node >=22.16 using built-in SQLite (itself experimental in Node 22). |
@@ -47,6 +47,9 @@ SDK present. Codex needs none: its harness drives the `codex` CLI directly.
47
47
 
48
48
  ## Run the wire server
49
49
 
50
+ The `agent-server` command runs its TypeScript source and needs Bun: run it
51
+ with `bunx @zvada/agent-server`.
52
+
50
53
  ```sh
51
54
  bunx @zvada/agent-server --listen 4747 # WebSocket wire on 127.0.0.1
52
55
  bunx @zvada/agent-server --stdio # stdio wire (for spawners)
@@ -1,4 +1,4 @@
1
- import { AuthUpdatedSchema, HarnessCliProgressSchema, SessionOverflowParamsSchema, WIRE_ERROR_CODES, WIRE_METHODS, decodeWireEventEnvelope, decodeWireMessage, generateUUIDv7, } from "../protocol/index.js";
1
+ import { AuthUpdatedSchema, HarnessCliProgressSchema, SessionOverflowParamsSchema, WIRE_ERROR_CODES, WIRE_FEATURES, WIRE_METHODS, agentOrigin, decodeWireEventEnvelope, decodeWireMessage, generateUUIDv7, } from "../protocol/index.js";
2
2
  import { Connection, ConnectionClosedError, ConnectionRefusedError, ProtocolVersionMismatchError, } from "./connection.js";
3
3
  import { createHistoryClient } from "./history.js";
4
4
  import { Listeners } from "./listeners.js";
@@ -163,7 +163,7 @@ export class AgentServerClient {
163
163
  // Before the first `await`: a cancel sent right behind this call goes out after the start.
164
164
  const release = this.starts.begin(sessionId, turnId);
165
165
  try {
166
- await this.initialize();
166
+ carriesOrigin(await this.initialize(), params.origin);
167
167
  if (this.turns.running(sessionId))
168
168
  throw new Error(`session ${sessionId} already has an active turn`);
169
169
  const handle = this.turns.open(sessionId, turnId, true);
@@ -175,7 +175,7 @@ export class AgentServerClient {
175
175
  (ack) => {
176
176
  if (!ack.terminal)
177
177
  this.joinAt(handle, ack.headSeq, { turnId });
178
- });
178
+ }, (server) => carriesOrigin(server, params.origin));
179
179
  release();
180
180
  const accepted = await sending;
181
181
  const { terminal } = accepted;
@@ -211,12 +211,12 @@ export class AgentServerClient {
211
211
  // As in `runTurn`: a cancel sent right behind this call goes out after the start.
212
212
  const release = this.starts.begin(sessionId, turnId);
213
213
  try {
214
- await this.initialize();
214
+ carriesOrigin(await this.initialize(), params.origin);
215
215
  // `request` sends (or fails for no connection) in this call.
216
216
  const answer = this.connection.request(WIRE_METHODS.turnStart, { ...params, sessionId, turnId }, (ack) => {
217
217
  if (params.subscribe !== false && !ack.terminal)
218
218
  this.streams.joined(sessionId, ack.headSeq, { turnId });
219
- });
219
+ }, (server) => carriesOrigin(server, params.origin));
220
220
  release();
221
221
  return await answer;
222
222
  }
@@ -263,7 +263,7 @@ export class AgentServerClient {
263
263
  * steer's user message, its receipt, reaches it.
264
264
  */
265
265
  async steerTurn(params) {
266
- await this.initialize();
266
+ carriesOrigin(await this.initialize(), params.origin);
267
267
  const { sessionId, turnId } = params;
268
268
  // One it cannot subscribe to still takes the steer; only its receipt is lost.
269
269
  if (!this.streams.follows(sessionId))
@@ -272,10 +272,7 @@ export class AgentServerClient {
272
272
  if (ack.activeTurn?.turnId === turnId)
273
273
  this.streams.joined(sessionId, ack.headSeq, { turnId });
274
274
  }).catch(() => undefined);
275
- return this.connection.resend(WIRE_METHODS.turnSteer, {
276
- ...params,
277
- steerId: params.steerId ?? generateUUIDv7(),
278
- });
275
+ return this.connection.resend(WIRE_METHODS.turnSteer, { ...params, steerId: params.steerId ?? generateUUIDv7() }, undefined, (server) => carriesOrigin(server, params.origin));
279
276
  }
280
277
  /**
281
278
  * Cancel the session's active turn; resolves once cancellation propagated.
@@ -669,7 +666,13 @@ export class AgentServerClient {
669
666
  get catchUp() {
670
667
  return handle.catchUp;
671
668
  },
672
- steer: (input, steerId) => this.steerTurn({ sessionId, turnId, input, ...(steerId !== undefined && { steerId }) }),
669
+ steer: (input, steerId, origin) => this.steerTurn({
670
+ sessionId,
671
+ turnId,
672
+ input,
673
+ ...(steerId !== undefined && { steerId }),
674
+ ...(origin && { origin }),
675
+ }),
673
676
  };
674
677
  }
675
678
  /**
@@ -743,3 +746,16 @@ export class AgentServerClient {
743
746
  return this.connection.request(WIRE_METHODS.sessionSubscribe, params, onAnswer);
744
747
  }
745
748
  }
749
+ // @ref LLP 0019#origin-on-the-wire-and-to-the-model — fail closed: an origin a server would strip reads as the person's
750
+ /**
751
+ * Refuse to send another sender's input to a server that does not carry
752
+ * `origin`: its schema would drop the field, and the agent would read the
753
+ * message as the person's. The person's input goes anywhere.
754
+ */
755
+ function carriesOrigin(server, origin) {
756
+ if (!agentOrigin(origin))
757
+ return;
758
+ if (server.features?.includes(WIRE_FEATURES.origin))
759
+ return;
760
+ throw new Error("This server does not carry a message's origin (no `origin` in its features); nothing was sent. Upgrade the server, or send the input as the person's.");
761
+ }
@@ -73,6 +73,10 @@ export class Connection {
73
73
  /** The server process (or, durable, the journal) whose logs the client follows. */
74
74
  serverIdentity;
75
75
  initializing = null;
76
+ /** The current transport's handshake, once answered; cleared when it is asked again. */
77
+ negotiated;
78
+ /** The transport `negotiated` was answered on: a feature check holds only for it. */
79
+ negotiatedOn = null;
76
80
  reconnecting = false;
77
81
  /** Ends the redial backoff early: `close()` must not wait it out. */
78
82
  stopBackoff = null;
@@ -110,6 +114,10 @@ export class Connection {
110
114
  if (transport.closed)
111
115
  throw new ConnectionClosedError("transport opened already closed");
112
116
  this.transport = transport;
117
+ // A new transport's server is not the old one's until its own handshake says so.
118
+ this.initializing = null;
119
+ this.negotiated = undefined;
120
+ this.negotiatedOn = null;
113
121
  this.host.opened(this.reconnecting);
114
122
  transport.onLine((line) => {
115
123
  if (this.transport === transport)
@@ -122,6 +130,9 @@ export class Connection {
122
130
  * client for good: it rejects with `ProtocolVersionMismatchError`.
123
131
  */
124
132
  initialize() {
133
+ if (!this.initializing)
134
+ this.negotiated = undefined;
135
+ const on = this.transport;
125
136
  this.initializing ??= this.request(WIRE_METHODS.initialize, {
126
137
  protocolVersion: WIRE_PROTOCOL_VERSION,
127
138
  client: this.options.clientInfo,
@@ -137,6 +148,8 @@ export class Connection {
137
148
  if (this.serverIdentity !== undefined && this.serverIdentity !== identity)
138
149
  this.host.serverChanged();
139
150
  this.serverIdentity = identity;
151
+ this.negotiated = result;
152
+ this.negotiatedOn = on;
140
153
  return result;
141
154
  })
142
155
  .catch((error) => {
@@ -156,12 +169,25 @@ export class Connection {
156
169
  return this.refusal ?? refusal;
157
170
  }
158
171
  /** A request, its answer read as `WIRE_API` reads the method's. */
159
- request(method, params, onAnswer) {
172
+ request(method, params, onAnswer,
173
+ /** Asked with the handshake of the very transport the request goes on; throw to send nothing. */
174
+ admit) {
160
175
  if (this.closed)
161
176
  return Promise.reject(this.refusal ?? new ConnectionClosedError("client closed"));
162
177
  const transport = this.transport;
163
178
  if (!transport)
164
179
  return Promise.reject(new ConnectionClosedError("not connected"));
180
+ if (admit) {
181
+ // This transport's handshake not answered yet: wait for it, then ask again.
182
+ if (this.negotiatedOn !== transport || !this.negotiated)
183
+ return this.initialize().then(() => this.request(method, params, onAnswer, admit));
184
+ try {
185
+ admit(this.negotiated);
186
+ }
187
+ catch (error) {
188
+ return Promise.reject(error);
189
+ }
190
+ }
165
191
  return this.rpc.request(transport, method, params, WIRE_API[method].decode, onAnswer);
166
192
  }
167
193
  /**
@@ -173,11 +199,17 @@ export class Connection {
173
199
  * re-sends at most: a server that accepts connections but never answers
174
200
  * would otherwise be retried forever.
175
201
  */
176
- async resend(method, params, onAnswer) {
202
+ async resend(method, params, onAnswer,
203
+ /**
204
+ * Asked with the server this attempt goes to, before each send, re-sends
205
+ * included: a redial may reach another build of the server. Throw to send
206
+ * nothing (LLP 0019: an origin that server would strip).
207
+ */
208
+ admit) {
177
209
  for (let resends = 0;; resends++) {
178
210
  const identity = this.serverIdentity;
179
211
  try {
180
- return await this.request(method, params, onAnswer);
212
+ return await this.request(method, params, onAnswer, admit);
181
213
  }
182
214
  catch (error) {
183
215
  if (!(error instanceof ConnectionClosedError) || !this.redials || resends >= MAX_RESENDS)
@@ -1,9 +1,9 @@
1
1
  import { AsyncQueue } from "../../../protocol/index.js";
2
2
  import { sharedNativeProcesses } from "../../processes/native-processes.js";
3
3
  import { onAbort, untilAborted } from "../../utils/deadline.js";
4
- import { SessionResumeError } from "../../utils/errors.js";
4
+ import { McpUnavailableError, SessionResumeError } from "../../utils/errors.js";
5
5
  import { configFingerprint } from "../config-fingerprint.js";
6
- import { nativeMcpServer } from "../mcp-config.js";
6
+ import { hostToolSessions, loopbackDirect, refuseHostName, } from "../host-tools.js";
7
7
  import { IDLE_TIMEOUT_MS, ProcessPool } from "../process-pool.js";
8
8
  import { SessionAgent } from "../session-agent.js";
9
9
  import { CANCELLED_PROMPT_RESULT } from "./adapter.js";
@@ -13,18 +13,32 @@ import { answerElicitation, answerPermission } from "./requests.js";
13
13
  /**
14
14
  * What a session's agent process was started with, as one key: a change to
15
15
  * any of it starts another, which resumes the conversation where the agent
16
- * can. MCP servers go without `required`, which is the engine's; extra
17
- * directories count, in any order, only for an agent that takes them.
16
+ * can. MCP servers count as the agent is given them (no `required`, which is
17
+ * the engine's, no `timeoutMs`, which ACP cannot carry); the host's tools by
18
+ * their name, their address and secret being the session's for its life;
19
+ * extra directories, in any order, only for an agent that takes them.
18
20
  * Hashed: the env and MCP headers carry credentials.
19
21
  */
20
- function spawnKey(options, launch, takesDirectories) {
21
- const servers = options.mcpServers;
22
+ /** What the agent is given, in an order of its own: a server's, header's or variable's place means nothing. */
23
+ function canonicalServers(servers) {
24
+ // A total order by code unit: `localeCompare` calls distinct names equal.
25
+ const byName = (a, b) => a.name < b.name ? -1 : a.name > b.name ? 1 : 0;
26
+ return toAcpMcpServers(servers)
27
+ .map((server) => "headers" in server
28
+ ? { ...server, headers: [...server.headers].sort(byName) }
29
+ : "env" in server
30
+ ? { ...server, env: [...server.env].sort(byName) }
31
+ : server)
32
+ .sort(byName);
33
+ }
34
+ function spawnKey(options, launch, takesDirectories, host) {
22
35
  return configFingerprint({
23
36
  launch: { command: launch.command, args: launch.args ?? [], env: launch.env ?? {} },
24
37
  cwd: options.cwd,
25
38
  env: options.env,
26
- mcpServers: servers &&
27
- Object.fromEntries(Object.entries(servers).map(([name, server]) => [name, nativeMcpServer(server)])),
39
+ // @ref LLP 0018#acp — only what the agent is given
40
+ mcpServers: options.mcpServers && canonicalServers(options.mcpServers),
41
+ host,
28
42
  directories: takesDirectories
29
43
  ? [...new Set(options.additionalDirectories ?? [])].sort()
30
44
  : undefined,
@@ -105,14 +119,30 @@ export class AcpAgent extends SessionAgent {
105
119
  /** Its CLIs start here: the runtime's, or this OS process's own when it was made without one. */
106
120
  processes;
107
121
  sessions;
122
+ host;
108
123
  constructor(agentOptions) {
109
124
  super({ cancelConfirmMs: agentOptions.cancelConfirmMs });
110
125
  this.agentOptions = agentOptions;
111
126
  this.processes = agentOptions.processes ?? sharedNativeProcesses();
127
+ this.host = hostToolSessions(agentOptions.hostTools, this.harness, {
128
+ // @ref LLP 0018#acp — the engine's mode: the turn's, moved only by a plan the broker approved
129
+ // The agent's own `current_mode_update` never raises it.
130
+ live: (sessionId) => {
131
+ const turn = this.sessions.get(sessionId)?.turn;
132
+ return turn?.turnId
133
+ ? { turnId: turn.turnId, permissionMode: turn.mode ?? "default", signal: turn.signal }
134
+ : undefined;
135
+ },
136
+ writesNeedFullAccess: true,
137
+ });
112
138
  this.sessions = new ProcessPool({
113
139
  resumeOf: ({ options }) => options.resumeSessionId,
114
140
  conversationsOf: (session) => [session.acpSessionId],
115
- fits: (session, { options, launch }) => session.spawnKey === spawnKey(options, launch, session.takesDirectories),
141
+ fits: (session, { options, launch, host }) => session.spawnKey ===
142
+ spawnKey(options, launch, session.takesDirectories, host?.source.name) &&
143
+ // @ref LLP 0018#acp — an agent started without the host's tools while the loopback was down
144
+ // One that can resume is started again, to get them; one that cannot keeps its conversation.
145
+ !(session.hostFailed && session.resumable),
116
146
  // @ref LLP 0001#d10--built-in-turns-own-their-logical-session-through-cleanup — not ended for idleness when it cannot be resumed
117
147
  // An agent that can neither resume nor load holds the only copy of
118
148
  // its conversation: neither idleness nor a host resume ends it.
@@ -128,7 +158,42 @@ export class AcpAgent extends SessionAgent {
128
158
  if (!launch) {
129
159
  throw new Error("acp harness is not configured: resolveLaunch returned no agent launch command");
130
160
  }
131
- return this.sessions.acquire(options.sessionId, { options, launch }, signal);
161
+ const host = await untilAborted(Promise.resolve(this.host?.lease(options.sessionId, options.cwd)), signal);
162
+ if (host)
163
+ refuseHostName(options.mcpServers, host.source.name);
164
+ return this.sessions.acquire(options.sessionId, { options, launch, host }, signal);
165
+ }
166
+ hostSecret(sessionId) {
167
+ return this.host?.secretOf(sessionId);
168
+ }
169
+ // @ref LLP 0018#acp — an agent that takes no HTTP server goes without the host's tools, and says so
170
+ /**
171
+ * The servers the agent is given: the turn's, and the host's when the agent
172
+ * takes HTTP servers, the loopback started only then. Without it, or with a
173
+ * loopback that cannot start, the turn says so and goes on without them.
174
+ */
175
+ async serversFor(options, host, http) {
176
+ if (!host)
177
+ return { servers: options.mcpServers };
178
+ const { name } = host.source;
179
+ let cause = "the agent takes no HTTP MCP server";
180
+ let hostFailed;
181
+ if (http) {
182
+ try {
183
+ return { servers: { ...options.mcpServers, [name]: await host.http() } };
184
+ }
185
+ catch (error) {
186
+ if (!(error instanceof McpUnavailableError))
187
+ throw error;
188
+ cause = error.servers[name] ?? error.message;
189
+ hostFailed = true;
190
+ }
191
+ }
192
+ await options.onWarning?.({
193
+ category: "mcp_unavailable",
194
+ message: `MCP server ${name} could not connect (${cause}); the turn goes on without the host's tools`,
195
+ });
196
+ return { servers: options.mcpServers, ...(hostFailed && { hostFailed }) };
132
197
  }
133
198
  /**
134
199
  * Start the session's agent and open its conversation: the one the turn
@@ -136,12 +201,19 @@ export class AcpAgent extends SessionAgent {
136
201
  * starts it once every agent of the session before it has exited, so a
137
202
  * successor never loads a conversation another agent still has.
138
203
  */
139
- async spawn({ options, launch }, own, signal) {
204
+ async spawn({ options, launch, host }, own, signal) {
140
205
  const resumeTarget = options.resumeSessionId;
141
206
  const clientOptions = {
142
207
  launch,
143
208
  cwd: options.cwd,
144
- env: options.env,
209
+ // @ref LLP 0018#acp — the bearer never travels through a proxy
210
+ // In the client's own order: the engine's environment, the launch's, the turn's.
211
+ env: this.host
212
+ ? {
213
+ ...options.env,
214
+ ...loopbackDirect({ ...process.env, ...launch.env, ...options.env }),
215
+ }
216
+ : options.env,
145
217
  clientName: this.agentOptions.clientName,
146
218
  sessionId: options.sessionId,
147
219
  processes: this.processes,
@@ -174,9 +246,10 @@ export class AcpAgent extends SessionAgent {
174
246
  : capabilities?.loadSession
175
247
  ? "session/load"
176
248
  : undefined;
249
+ const given = await this.serversFor(options, host, Boolean(capabilities?.mcpCapabilities?.http));
177
250
  const target = {
178
251
  cwd: options.cwd,
179
- mcpServers: toAcpMcpServers(options.mcpServers),
252
+ mcpServers: toAcpMcpServers(given.servers),
180
253
  // Sent only to agents that advertise it; others keep `cwd` alone.
181
254
  ...(takesDirectories &&
182
255
  options.additionalDirectories?.length && {
@@ -213,7 +286,8 @@ export class AcpAgent extends SessionAgent {
213
286
  const session = {
214
287
  client,
215
288
  acpSessionId,
216
- spawnKey: spawnKey(options, launch, takesDirectories),
289
+ spawnKey: spawnKey(options, launch, takesDirectories, host?.source.name),
290
+ ...(given.hostFailed && { hostFailed: true }),
217
291
  takesDirectories,
218
292
  resumable: resumeMethod !== undefined,
219
293
  configOptions: configOptions ?? [],
@@ -324,6 +398,7 @@ export class AcpAgent extends SessionAgent {
324
398
  elicitation: options.onElicitationRequest,
325
399
  mode: options.permissionMode,
326
400
  signal: controller.signal,
401
+ turnId: options.turnId,
327
402
  };
328
403
  options.onNativeSession?.(session.acpSessionId, {
329
404
  resumed: session.acpSessionId === options.resumeSessionId,
@@ -413,6 +488,7 @@ export class AcpAgent extends SessionAgent {
413
488
  // confirm window, not after it, and its exit is what confirms it.
414
489
  // An agent an eviction or a replacement ended earlier is waited for too.
415
490
  await Promise.all([super.release(sessionId), this.sessions.release(sessionId)]);
491
+ this.host?.release(sessionId);
416
492
  }
417
493
  /** After a host resume, each session's next turn starts its agent again, on its conversation. */
418
494
  invalidateMcpConnections() {
@@ -421,5 +497,6 @@ export class AcpAgent extends SessionAgent {
421
497
  async terminateAll() {
422
498
  await super.terminateAll();
423
499
  await this.sessions.closeAll();
500
+ await this.host?.close();
424
501
  }
425
502
  }
@@ -41,7 +41,11 @@ export function toToolResultContent(content) {
41
41
  return [];
42
42
  });
43
43
  }
44
- /** Engine MCP config map → ACP `McpServer[]` (names come from the record keys). */
44
+ /**
45
+ * Engine MCP config map → ACP `McpServer[]` (names come from the record keys).
46
+ * ACP's fields only: a strict agent may refuse one it does not know, and ACP
47
+ * v1 has none for `required` or a tool-call limit (`timeoutMs`).
48
+ */
45
49
  export function toAcpMcpServers(mcpServers) {
46
50
  if (!mcpServers)
47
51
  return [];
@@ -32,7 +32,8 @@ export function startQuery(permissionMode, start) {
32
32
  /**
33
33
  * The SDK approval callback, fixed at spawn: it asks the turn running when it
34
34
  * is called, which Claude does for a call its mode and rules do not approve
35
- * by themselves (under `bypass_permissions`, only questions and plans). The
35
+ * by themselves (under `bypass_permissions`, questions, plans and, since
36
+ * Claude Code 2.1.326, the few calls it holds back as dangerous). The
36
37
  * host `toolPolicy` sees each such call first (full native PermissionResult
37
38
  * power), questions and plans included; a call it leaves
38
39
  * (`undefined`) goes to the turn: a question to its elicitation, a plan or a
@@ -93,7 +94,7 @@ export function createCanUseTool(deps) {
93
94
  return decision;
94
95
  };
95
96
  if (toolName === "ExitPlanMode") {
96
- return planVerdict(await ask(PLAN_TITLE, { options: PLAN_OPTIONS }), input);
97
+ return planVerdict(await ask(PLAN_TITLE, { options: PLAN_OPTIONS, purpose: "plan" }), input);
97
98
  }
98
99
  // @ref LLP 0001#d4--permission-requests-are-first-class-protocol — "always" is Claude's own rule
99
100
  // "Always" is the rule Claude suggests (`Bash(npm test *)`, accept-edits
@@ -3,6 +3,7 @@ import { sharedNativeProcesses } from "../../processes/native-processes.js";
3
3
  import { onAbort, untilAborted } from "../../utils/deadline.js";
4
4
  import { SessionResumeError } from "../../utils/errors.js";
5
5
  import { UnsupportedAttachmentError, attachedText, isTextMedia } from "../attachments.js";
6
+ import { hostToolSessions, refuseHostName } from "../host-tools.js";
6
7
  import { SessionAgent } from "../session-agent.js";
7
8
  import { ClaudeCredentials, ON_PLACEHOLDER } from "./credentials.js";
8
9
  import { ClaudeCliLogin } from "./login.js";
@@ -95,12 +96,14 @@ export class ClaudeCodeAgent extends SessionAgent {
95
96
  pool;
96
97
  credentials;
97
98
  cancelGraceMs;
99
+ host;
98
100
  constructor(agentOptions = {}) {
99
101
  super({ cancelConfirmMs: agentOptions.cancelConfirmMs });
100
102
  this.agentOptions = agentOptions;
101
103
  this.cancelGraceMs = agentOptions.cancelGraceMs ?? CANCEL_GRACE_MS;
102
104
  this.processes = agentOptions.processes ?? sharedNativeProcesses();
103
- this.pool = claudeSessionPool({ ...agentOptions, processes: this.processes });
105
+ this.host = hostToolSessions(agentOptions.hostTools, this.harness);
106
+ this.pool = claudeSessionPool({ ...agentOptions, processes: this.processes, host: this.host });
104
107
  this.login = new ClaudeCliLogin({
105
108
  resolveCliPath: agentOptions.resolveCliPath,
106
109
  processes: this.processes,
@@ -134,6 +137,9 @@ export class ClaudeCodeAgent extends SessionAgent {
134
137
  const cliPath = resolveCliPath && (await untilAborted(resolveCliPath(), controller.signal));
135
138
  const content = toClaudeContent(input);
136
139
  controller.signal.throwIfAborted();
140
+ const source = await untilAborted(Promise.resolve(this.host?.source(options.sessionId, options.cwd)), controller.signal);
141
+ if (source)
142
+ refuseHostName(options.mcpServers, source.name);
137
143
  const thinking = fitClaudeThinking(options.thinkingLevel, options.modelThinking);
138
144
  const turnOptions = this.withDelivery(options, await this.credentials?.forTurn(options.sessionId, options.turnId, controller.signal));
139
145
  controller.signal.throwIfAborted();
@@ -147,7 +153,8 @@ export class ClaudeCodeAgent extends SessionAgent {
147
153
  if (thinking.applied && !session.operatorThinking)
148
154
  options.onExecution?.({ thinkingLevel: thinking.applied });
149
155
  const notApplied = [];
150
- // A model known to have no effort levels is sent no level (`fitClaudeThinking`).
156
+ // A model known to have no effort levels, or whose levels hold no fit for
157
+ // the turn's, is sent no level (`fitClaudeThinking`).
151
158
  if (options.thinkingLevel !== undefined && thinking.send === undefined)
152
159
  notApplied.push("thinkingLevel");
153
160
  // A message to resume at goes only with a resume (`buildClaudeOptions`).
@@ -177,6 +184,7 @@ export class ClaudeCodeAgent extends SessionAgent {
177
184
  report(session.currentSessionId);
178
185
  const turn = session.sendMessage(content, {
179
186
  turnId: options.turnId,
187
+ signal: controller.signal,
180
188
  permissions: options.onPermissionRequest,
181
189
  elicitation: options.onElicitationRequest,
182
190
  });
@@ -308,6 +316,7 @@ export class ClaudeCodeAgent extends SessionAgent {
308
316
  await super.release(sessionId);
309
317
  await this.pool.release(sessionId);
310
318
  this.credentials?.release(sessionId);
319
+ this.host?.release(sessionId);
311
320
  }
312
321
  async terminateAll() {
313
322
  // Before the turns are aborted: a start under way ends for shutdown, not as a cancel.
@@ -315,5 +324,6 @@ export class ClaudeCodeAgent extends SessionAgent {
315
324
  await super.terminateAll();
316
325
  await closed;
317
326
  await this.credentials?.close();
327
+ await this.host?.close();
318
328
  }
319
329
  }
@@ -1,5 +1,13 @@
1
1
  import { configFingerprint } from "../config-fingerprint.js";
2
2
  import { UnavailableMcpServers, mcpConnectionErrors, nativeMcpServer, settleMcpFailures, snapshotMcpServers, } from "../mcp-config.js";
3
+ /**
4
+ * A turn's server as Claude takes it: its tool-call limit is the SDK's
5
+ * per-server `timeout`, in milliseconds as on the wire.
6
+ */
7
+ export function claudeMcpServer(server) {
8
+ const native = nativeMcpServer(server);
9
+ return server.timeoutMs === undefined ? native : { ...native, timeout: server.timeoutMs };
10
+ }
3
11
  function remoteMcpServer(server) {
4
12
  return server.type === "http" || server.type === "sse";
5
13
  }
@@ -106,7 +114,7 @@ export class ClaudeMcpConnections {
106
114
  // for an identical configuration, and its old failure must not decide.
107
115
  const retry = new Set(this.unavailable.retryNow(servers));
108
116
  const resetNames = Object.keys(servers).filter((name) => failed.has(name) || retry.has(name));
109
- const native = Object.fromEntries(Object.entries(servers).map(([name, server]) => [name, nativeMcpServer(server)]));
117
+ const native = Object.fromEntries(Object.entries(servers).map(([name, server]) => [name, claudeMcpServer(server)]));
110
118
  const desired = { ...native, ...this.host };
111
119
  const added = new Set();
112
120
  const removed = new Set();