@zvada/agent-server 0.3.26 → 0.3.28

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 (262) hide show
  1. package/CHANGELOG.md +71 -0
  2. package/README.md +7 -5
  3. package/dist/client/client.js +27 -11
  4. package/dist/client/connection.js +35 -3
  5. package/dist/core/agents/acp/account.js +111 -0
  6. package/dist/core/agents/acp/acp-agent.js +247 -158
  7. package/dist/core/agents/acp/adapter.js +103 -34
  8. package/dist/core/agents/acp/client.js +169 -42
  9. package/dist/core/agents/acp/known-agents.js +12 -5
  10. package/dist/core/agents/acp/mappings.js +84 -20
  11. package/dist/core/agents/acp/models.js +59 -0
  12. package/dist/core/agents/acp/profile.js +36 -0
  13. package/dist/core/agents/acp/prompts.js +248 -0
  14. package/dist/core/agents/acp/requests.js +4 -4
  15. package/dist/core/agents/claude-code/approvals.js +1 -1
  16. package/dist/core/agents/claude-code/login.js +4 -1
  17. package/dist/core/agents/claude-code/session.js +38 -10
  18. package/dist/core/agents/claude-code/spawn.js +0 -26
  19. package/dist/core/agents/codex-app-server/client.js +12 -13
  20. package/dist/core/agents/codex-app-server/login.js +4 -1
  21. package/dist/core/agents/codex-app-server/plan-approval.js +1 -1
  22. package/dist/core/agents/gemini/failures.js +133 -0
  23. package/dist/core/agents/gemini/login.js +173 -0
  24. package/dist/core/agents/gemini/profile.js +137 -0
  25. package/dist/core/agents/gemini/tools.js +91 -0
  26. package/dist/core/agents/login.js +8 -6
  27. package/dist/core/agents/scripted/scripted-agent.js +30 -3
  28. package/dist/core/agents/stderr-tail.js +5 -2
  29. package/dist/core/presets.js +17 -1
  30. package/dist/core/processes/native-processes.js +23 -1
  31. package/dist/core/provision/install-build.js +70 -26
  32. package/dist/core/provision/pins.js +5 -0
  33. package/dist/core/provision/provisioner.js +39 -16
  34. package/dist/core/provision/releases.js +39 -1
  35. package/dist/core/provision/tools.js +87 -28
  36. package/dist/core/runtime/agent-runtime.js +15 -5
  37. package/dist/core/runtime/event-processor.js +13 -8
  38. package/dist/core/runtime/origin-line.js +42 -0
  39. package/dist/core/runtime/request-broker.js +2 -1
  40. package/dist/core/runtime/steering.js +4 -3
  41. package/dist/core/runtime/turn.js +6 -4
  42. package/dist/operator/errors.js +97 -0
  43. package/dist/operator/index.js +10 -5
  44. package/dist/operator/mcp.js +7 -12
  45. package/dist/operator/operator.js +1431 -378
  46. package/dist/operator/refs.js +59 -0
  47. package/dist/operator/render.js +199 -94
  48. package/dist/operator/session-tools.js +88 -0
  49. package/dist/operator/types.js +30 -0
  50. package/dist/operator/view.js +82 -27
  51. package/dist/protocol/account.js +5 -1
  52. package/dist/protocol/auth.js +5 -1
  53. package/dist/protocol/config.js +12 -5
  54. package/dist/protocol/conversation.js +3 -0
  55. package/dist/protocol/credentials.js +9 -1
  56. package/dist/protocol/harness.js +9 -1
  57. package/dist/protocol/history.js +2 -1
  58. package/dist/protocol/index.js +1 -0
  59. package/dist/protocol/lifecycle.js +19 -0
  60. package/dist/protocol/origin.js +39 -0
  61. package/dist/protocol/reduce.js +2 -0
  62. package/dist/protocol/wire.js +17 -0
  63. package/dist/server/bin.js +22 -7
  64. package/dist/server/install.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/account.d.ts +55 -0
  72. package/dist/types/core/agents/acp/account.d.ts.map +1 -0
  73. package/dist/types/core/agents/acp/acp-agent.d.ts +65 -36
  74. package/dist/types/core/agents/acp/acp-agent.d.ts.map +1 -1
  75. package/dist/types/core/agents/acp/adapter.d.ts +28 -3
  76. package/dist/types/core/agents/acp/adapter.d.ts.map +1 -1
  77. package/dist/types/core/agents/acp/client.d.ts +66 -4
  78. package/dist/types/core/agents/acp/client.d.ts.map +1 -1
  79. package/dist/types/core/agents/acp/known-agents.d.ts +4 -2
  80. package/dist/types/core/agents/acp/known-agents.d.ts.map +1 -1
  81. package/dist/types/core/agents/acp/mappings.d.ts +53 -7
  82. package/dist/types/core/agents/acp/mappings.d.ts.map +1 -1
  83. package/dist/types/core/agents/acp/models.d.ts +22 -0
  84. package/dist/types/core/agents/acp/models.d.ts.map +1 -0
  85. package/dist/types/core/agents/acp/profile.d.ts +92 -0
  86. package/dist/types/core/agents/acp/profile.d.ts.map +1 -0
  87. package/dist/types/core/agents/acp/prompts.d.ts +108 -0
  88. package/dist/types/core/agents/acp/prompts.d.ts.map +1 -0
  89. package/dist/types/core/agents/acp/requests.d.ts +7 -1
  90. package/dist/types/core/agents/acp/requests.d.ts.map +1 -1
  91. package/dist/types/core/agents/base.d.ts +2 -0
  92. package/dist/types/core/agents/base.d.ts.map +1 -1
  93. package/dist/types/core/agents/claude-code/login.d.ts.map +1 -1
  94. package/dist/types/core/agents/claude-code/session.d.ts +3 -0
  95. package/dist/types/core/agents/claude-code/session.d.ts.map +1 -1
  96. package/dist/types/core/agents/claude-code/spawn.d.ts +0 -8
  97. package/dist/types/core/agents/claude-code/spawn.d.ts.map +1 -1
  98. package/dist/types/core/agents/codex-app-server/client.d.ts.map +1 -1
  99. package/dist/types/core/agents/codex-app-server/login.d.ts.map +1 -1
  100. package/dist/types/core/agents/gemini/failures.d.ts +25 -0
  101. package/dist/types/core/agents/gemini/failures.d.ts.map +1 -0
  102. package/dist/types/core/agents/gemini/login.d.ts +28 -0
  103. package/dist/types/core/agents/gemini/login.d.ts.map +1 -0
  104. package/dist/types/core/agents/gemini/profile.d.ts +30 -0
  105. package/dist/types/core/agents/gemini/profile.d.ts.map +1 -0
  106. package/dist/types/core/agents/gemini/tools.d.ts +18 -0
  107. package/dist/types/core/agents/gemini/tools.d.ts.map +1 -0
  108. package/dist/types/core/agents/login.d.ts +15 -5
  109. package/dist/types/core/agents/login.d.ts.map +1 -1
  110. package/dist/types/core/agents/scripted/scripted-agent.d.ts +14 -1
  111. package/dist/types/core/agents/scripted/scripted-agent.d.ts.map +1 -1
  112. package/dist/types/core/agents/stderr-tail.d.ts +1 -1
  113. package/dist/types/core/agents/stderr-tail.d.ts.map +1 -1
  114. package/dist/types/core/presets.d.ts +2 -2
  115. package/dist/types/core/presets.d.ts.map +1 -1
  116. package/dist/types/core/processes/native-processes.d.ts +6 -0
  117. package/dist/types/core/processes/native-processes.d.ts.map +1 -1
  118. package/dist/types/core/provision/checksums.d.ts +7 -1
  119. package/dist/types/core/provision/checksums.d.ts.map +1 -1
  120. package/dist/types/core/provision/install-build.d.ts +32 -6
  121. package/dist/types/core/provision/install-build.d.ts.map +1 -1
  122. package/dist/types/core/provision/pins.d.ts +4 -0
  123. package/dist/types/core/provision/pins.d.ts.map +1 -1
  124. package/dist/types/core/provision/provisioner.d.ts +18 -7
  125. package/dist/types/core/provision/provisioner.d.ts.map +1 -1
  126. package/dist/types/core/provision/releases.d.ts +2 -1
  127. package/dist/types/core/provision/releases.d.ts.map +1 -1
  128. package/dist/types/core/provision/tools.d.ts +36 -7
  129. package/dist/types/core/provision/tools.d.ts.map +1 -1
  130. package/dist/types/core/runtime/agent-runtime.d.ts +4 -2
  131. package/dist/types/core/runtime/agent-runtime.d.ts.map +1 -1
  132. package/dist/types/core/runtime/event-processor.d.ts +2 -2
  133. package/dist/types/core/runtime/event-processor.d.ts.map +1 -1
  134. package/dist/types/core/runtime/origin-line.d.ts +15 -0
  135. package/dist/types/core/runtime/origin-line.d.ts.map +1 -0
  136. package/dist/types/core/runtime/request-broker.d.ts +1 -1
  137. package/dist/types/core/runtime/request-broker.d.ts.map +1 -1
  138. package/dist/types/core/runtime/steering.d.ts +7 -4
  139. package/dist/types/core/runtime/steering.d.ts.map +1 -1
  140. package/dist/types/core/runtime/turn.d.ts.map +1 -1
  141. package/dist/types/operator/errors.d.ts +87 -0
  142. package/dist/types/operator/errors.d.ts.map +1 -0
  143. package/dist/types/operator/index.d.ts +10 -5
  144. package/dist/types/operator/index.d.ts.map +1 -1
  145. package/dist/types/operator/mcp.d.ts +1 -1
  146. package/dist/types/operator/mcp.d.ts.map +1 -1
  147. package/dist/types/operator/operator.d.ts +15 -197
  148. package/dist/types/operator/operator.d.ts.map +1 -1
  149. package/dist/types/operator/refs.d.ts +25 -0
  150. package/dist/types/operator/refs.d.ts.map +1 -0
  151. package/dist/types/operator/render.d.ts +67 -22
  152. package/dist/types/operator/render.d.ts.map +1 -1
  153. package/dist/types/operator/session-tools.d.ts +61 -0
  154. package/dist/types/operator/session-tools.d.ts.map +1 -0
  155. package/dist/types/operator/types.d.ts +442 -0
  156. package/dist/types/operator/types.d.ts.map +1 -0
  157. package/dist/types/operator/view.d.ts +19 -29
  158. package/dist/types/operator/view.d.ts.map +1 -1
  159. package/dist/types/protocol/account.d.ts +4 -2
  160. package/dist/types/protocol/account.d.ts.map +1 -1
  161. package/dist/types/protocol/auth.d.ts +10 -7
  162. package/dist/types/protocol/auth.d.ts.map +1 -1
  163. package/dist/types/protocol/clis.d.ts +4 -3
  164. package/dist/types/protocol/clis.d.ts.map +1 -1
  165. package/dist/types/protocol/config.d.ts +22 -5
  166. package/dist/types/protocol/config.d.ts.map +1 -1
  167. package/dist/types/protocol/conversation.d.ts +47 -6
  168. package/dist/types/protocol/conversation.d.ts.map +1 -1
  169. package/dist/types/protocol/credentials.d.ts +8 -0
  170. package/dist/types/protocol/credentials.d.ts.map +1 -1
  171. package/dist/types/protocol/execution.d.ts +1 -1
  172. package/dist/types/protocol/harness.d.ts +5 -2
  173. package/dist/types/protocol/harness.d.ts.map +1 -1
  174. package/dist/types/protocol/history.d.ts +1 -1
  175. package/dist/types/protocol/history.d.ts.map +1 -1
  176. package/dist/types/protocol/index.d.ts +1 -0
  177. package/dist/types/protocol/index.d.ts.map +1 -1
  178. package/dist/types/protocol/lifecycle.d.ts +48 -10
  179. package/dist/types/protocol/lifecycle.d.ts.map +1 -1
  180. package/dist/types/protocol/models.d.ts +3 -0
  181. package/dist/types/protocol/models.d.ts.map +1 -1
  182. package/dist/types/protocol/origin.d.ts +49 -0
  183. package/dist/types/protocol/origin.d.ts.map +1 -0
  184. package/dist/types/protocol/reduce.d.ts.map +1 -1
  185. package/dist/types/protocol/wire-api.d.ts +78 -30
  186. package/dist/types/protocol/wire-api.d.ts.map +1 -1
  187. package/dist/types/protocol/wire.d.ts +78 -12
  188. package/dist/types/protocol/wire.d.ts.map +1 -1
  189. package/dist/types/server/install.d.ts +2 -1
  190. package/dist/types/server/install.d.ts.map +1 -1
  191. package/dist/types/server/routes.d.ts.map +1 -1
  192. package/docs/consuming.md +62 -121
  193. package/docs/deploy.md +17 -8
  194. package/docs/harnesses.md +166 -44
  195. package/docs/sync-history.md +2 -1
  196. package/package.json +1 -1
  197. package/src/client/client.ts +36 -9
  198. package/src/client/connection.ts +31 -1
  199. package/src/client/turns.ts +2 -1
  200. package/src/core/agents/acp/account.ts +158 -0
  201. package/src/core/agents/acp/acp-agent.ts +288 -178
  202. package/src/core/agents/acp/adapter.ts +126 -35
  203. package/src/core/agents/acp/client.ts +196 -49
  204. package/src/core/agents/acp/known-agents.ts +14 -5
  205. package/src/core/agents/acp/mappings.ts +112 -21
  206. package/src/core/agents/acp/models.ts +72 -0
  207. package/src/core/agents/acp/profile.ts +127 -0
  208. package/src/core/agents/acp/prompts.ts +287 -0
  209. package/src/core/agents/acp/requests.ts +16 -9
  210. package/src/core/agents/base.ts +2 -0
  211. package/src/core/agents/claude-code/approvals.ts +2 -2
  212. package/src/core/agents/claude-code/login.ts +4 -1
  213. package/src/core/agents/claude-code/session.ts +38 -8
  214. package/src/core/agents/claude-code/spawn.ts +0 -26
  215. package/src/core/agents/codex-app-server/client.ts +11 -18
  216. package/src/core/agents/codex-app-server/login.ts +4 -5
  217. package/src/core/agents/codex-app-server/plan-approval.ts +1 -1
  218. package/src/core/agents/gemini/failures.ts +148 -0
  219. package/src/core/agents/gemini/login.ts +188 -0
  220. package/src/core/agents/gemini/profile.ts +162 -0
  221. package/src/core/agents/gemini/tools.ts +99 -0
  222. package/src/core/agents/login.ts +14 -8
  223. package/src/core/agents/scripted/scripted-agent.ts +42 -3
  224. package/src/core/agents/stderr-tail.ts +5 -2
  225. package/src/core/presets.ts +19 -3
  226. package/src/core/processes/native-processes.ts +32 -1
  227. package/src/core/provision/checksums.ts +12 -2
  228. package/src/core/provision/install-build.ts +122 -55
  229. package/src/core/provision/pins.ts +5 -0
  230. package/src/core/provision/provisioner.ts +62 -27
  231. package/src/core/provision/releases.ts +47 -1
  232. package/src/core/provision/tools.ts +124 -31
  233. package/src/core/runtime/agent-runtime.ts +31 -7
  234. package/src/core/runtime/event-processor.ts +13 -6
  235. package/src/core/runtime/origin-line.ts +43 -0
  236. package/src/core/runtime/request-broker.ts +2 -0
  237. package/src/core/runtime/steering.ts +8 -4
  238. package/src/core/runtime/turn.ts +11 -4
  239. package/src/operator/errors.ts +221 -0
  240. package/src/operator/index.ts +18 -23
  241. package/src/operator/mcp.ts +7 -16
  242. package/src/operator/operator.ts +1684 -610
  243. package/src/operator/refs.ts +75 -0
  244. package/src/operator/render.ts +260 -118
  245. package/src/operator/session-tools.ts +127 -0
  246. package/src/operator/types.ts +506 -0
  247. package/src/operator/view.ts +93 -42
  248. package/src/protocol/account.ts +5 -2
  249. package/src/protocol/auth.ts +5 -1
  250. package/src/protocol/config.ts +14 -6
  251. package/src/protocol/conversation.ts +3 -0
  252. package/src/protocol/credentials.ts +11 -2
  253. package/src/protocol/harness.ts +9 -1
  254. package/src/protocol/history.ts +2 -1
  255. package/src/protocol/index.ts +1 -0
  256. package/src/protocol/lifecycle.ts +21 -0
  257. package/src/protocol/origin.ts +47 -0
  258. package/src/protocol/reduce.ts +4 -0
  259. package/src/protocol/wire.ts +18 -0
  260. package/src/server/bin.ts +20 -6
  261. package/src/server/install.ts +6 -3
  262. package/src/server/routes.ts +16 -5
@@ -1,18 +1,20 @@
1
1
  import { existsSync, lstatSync, readFileSync, readdirSync, realpathSync, } from "node:fs";
2
2
  import { readdir } from "node:fs/promises";
3
3
  import { createRequire } from "node:module";
4
+ import { homedir } from "node:os";
4
5
  import { dirname, join, resolve } from "node:path";
5
6
  import { pathToFileURL } from "node:url";
6
7
  import { CliNotFoundError, CliProvisionError } from "../utils/errors.js";
7
8
  import { DEFAULT_PINS } from "./pins.js";
8
9
  import { claudePackageSuffix, codexPackageSuffix, findOnPath, } from "./platform.js";
9
10
  /**
10
- * The managed CLIs. Each native harness maps onto exactly one of these; the
11
+ * The managed CLIs. Each native harness maps onto exactly one of these, and
12
+ * so does `gemini`, a profile on the ACP agent that runs Google's `agy`; the
11
13
  * `acp` harness maps onto none (its agent binaries are arbitrary third-party
12
14
  * commands the operator supplies, not something we pin or download), nor does
13
15
  * `scripted`, which runs no process.
14
16
  */
15
- export const CLI_TOOLS = ["claude", "codex"];
17
+ export const CLI_TOOLS = ["claude", "codex", "agy"];
16
18
  /**
17
19
  * Which managed CLI a harness runs on — `undefined` for unmanaged harnesses
18
20
  * (`acp`, `scripted`). Exhaustive by construction: adding a harness fails to
@@ -21,6 +23,7 @@ export const CLI_TOOLS = ["claude", "codex"];
21
23
  const TOOL_FOR_HARNESS = {
22
24
  "claude-code": "claude",
23
25
  "codex-app-server": "codex",
26
+ gemini: "agy",
24
27
  acp: undefined,
25
28
  scripted: undefined,
26
29
  };
@@ -150,6 +153,7 @@ const CODEX_BINARIES = [join("bin", "codex"), join("bin", "codex.exe")];
150
153
  */
151
154
  export const CLI_TOOL_SPECS = {
152
155
  claude: {
156
+ title: "Claude Code",
153
157
  overrideEnv: "CLAUDE_CLI_PATH",
154
158
  binaries: ["claude", "claude.exe"],
155
159
  platforms: [
@@ -162,10 +166,23 @@ export const CLI_TOOL_SPECS = {
162
166
  "win32-arm64",
163
167
  "win32-x64",
164
168
  ],
165
- // The platform packages carry the native CLI matched to the SDK JS.
166
- package: (platform, version) => {
167
- const suffix = claudePackageSuffix(platform);
168
- return { name: `@anthropic-ai/claude-agent-sdk-${suffix}`, registryVersion: version, suffix };
169
+ source: {
170
+ kind: "npm",
171
+ // The platform packages carry the native CLI matched to the SDK JS.
172
+ package: (platform, version) => {
173
+ const suffix = claudePackageSuffix(platform);
174
+ return {
175
+ name: `@anthropic-ai/claude-agent-sdk-${suffix}`,
176
+ registryVersion: version,
177
+ suffix,
178
+ };
179
+ },
180
+ payload: async (extractedRoot) => {
181
+ const dir = join(extractedRoot, "package");
182
+ if (existsSync(dir))
183
+ return dir;
184
+ throw new CliProvisionError("claude tarball has no package/ directory");
185
+ },
169
186
  },
170
187
  // The on-disk SDK's version (the pair that actually runs) over the
171
188
  // release default, which only decides inside compiled binaries. Even
@@ -203,12 +220,6 @@ export const CLI_TOOL_SPECS = {
203
220
  const path = join(platformDir, claudeManifestBuild(sdk.dir, suffix)?.binary ?? "claude");
204
221
  return existsSync(path) ? { path, version: sdk.version } : undefined;
205
222
  },
206
- payload: async (extractedRoot) => {
207
- const dir = join(extractedRoot, "package");
208
- if (existsSync(dir))
209
- return dir;
210
- throw new CliProvisionError("claude tarball has no package/ directory");
211
- },
212
223
  // The SDK on disk names its own CLI's checksum, for a version this
213
224
  // release did not pin (a consumer's lockfile moved the SDK).
214
225
  localBuild: (suffix, version) => {
@@ -218,6 +229,7 @@ export const CLI_TOOL_SPECS = {
218
229
  },
219
230
  },
220
231
  codex: {
232
+ title: "Codex CLI",
221
233
  overrideEnv: "CODEX_CLI_PATH",
222
234
  binaries: CODEX_BINARIES,
223
235
  // Its linux builds are static, so there is no musl variant.
@@ -229,10 +241,25 @@ export const CLI_TOOL_SPECS = {
229
241
  "win32-arm64",
230
242
  "win32-x64",
231
243
  ],
232
- // Codex publishes its platform builds as version suffixes of one package.
233
- package: (platform, version) => {
234
- const suffix = codexPackageSuffix(platform);
235
- return { name: "@openai/codex", registryVersion: `${version}-${suffix}`, suffix };
244
+ source: {
245
+ kind: "npm",
246
+ // Codex publishes its platform builds as version suffixes of one package.
247
+ package: (platform, version) => {
248
+ const suffix = codexPackageSuffix(platform);
249
+ return { name: "@openai/codex", registryVersion: `${version}-${suffix}`, suffix };
250
+ },
251
+ // Codex vendors per-target trees: package/vendor/<rust-triple>/bin/codex.
252
+ // Install the whole tree — the CLI expects its vendored rg/zsh siblings.
253
+ payload: async (extractedRoot) => {
254
+ const vendor = join(extractedRoot, "package", "vendor");
255
+ const entries = existsSync(vendor) ? await readdir(vendor) : [];
256
+ for (const entry of entries) {
257
+ const dir = join(vendor, entry);
258
+ if (binaryIn(dir, CODEX_BINARIES))
259
+ return dir;
260
+ }
261
+ throw new CliProvisionError("codex tarball has no vendor/<target>/bin/codex");
262
+ },
236
263
  },
237
264
  defaultVersion: () => DEFAULT_PINS.codex,
238
265
  // @ref LLP 0001#d18--the-engine-installs-the-clis-it-runs-pinned-builds-checked-before-a-turn — a lockfile's build, or in `system` the operator's PATH
@@ -261,19 +288,51 @@ export const CLI_TOOL_SPECS = {
261
288
  const path = searchPath ? findOnPath("codex", env, platform.platform) : undefined;
262
289
  return path ? { path } : undefined;
263
290
  },
264
- // Codex vendors per-target trees: package/vendor/<rust-triple>/bin/codex.
265
- // Install the whole tree — the CLI expects its vendored rg/zsh siblings.
266
- payload: async (extractedRoot) => {
267
- const vendor = join(extractedRoot, "package", "vendor");
268
- const entries = existsSync(vendor) ? await readdir(vendor) : [];
269
- for (const entry of entries) {
270
- const dir = join(vendor, entry);
271
- if (binaryIn(dir, CODEX_BINARIES))
272
- return dir;
273
- }
274
- throw new CliProvisionError("codex tarball has no vendor/<target>/bin/codex");
275
- },
276
291
  // A bare spawn would just ENOENT.
277
292
  notOnHost: () => new CliNotFoundError("codex", 'install it, set $CODEX_CLI_PATH, or use provision mode "auto"'),
278
293
  },
294
+ // Google's Antigravity CLI, for the gemini harness.
295
+ agy: {
296
+ title: "Antigravity CLI",
297
+ overrideEnv: "ANTIGRAVITY_CLI_PATH",
298
+ binaries: ["agy", "agy.exe"],
299
+ platforms: [
300
+ "darwin-arm64",
301
+ "darwin-x64",
302
+ "linux-arm64",
303
+ "linux-x64",
304
+ "linux-arm64-musl",
305
+ "linux-x64-musl",
306
+ "win32-arm64",
307
+ "win32-x64",
308
+ ],
309
+ // Google publishes no package: each build is a file its update manifest
310
+ // names, with a sha512 and no signature, recorded at refresh
311
+ // (`scripts/refresh-cli-releases.ts`). The tarball's one member is
312
+ // `antigravity`, which its installer puts in place as `agy`; Windows'
313
+ // build is the executable itself.
314
+ source: {
315
+ kind: "url",
316
+ executable: ({ platform }) => platform === "win32" ? { binary: "agy.exe" } : { binary: "agy", member: "antigravity" },
317
+ },
318
+ defaultVersion: () => DEFAULT_PINS.agy,
319
+ // @ref LLP 0010#source-kinds — the person's own agy updates itself: only `system` runs it
320
+ // Where Google's installers put it (`install.sh`: ~/.local/bin/agy;
321
+ // `install.ps1` and `install.cmd`: %LOCALAPPDATA%\agy\bin\agy.exe),
322
+ // then PATH, in `system` mode only: nobody chose that build for this
323
+ // engine, and it updates itself.
324
+ hostInstall: ({ platform, env, searchPath }) => {
325
+ if (!searchPath)
326
+ return undefined;
327
+ const windows = platform.platform === "win32";
328
+ const local = windows ? env.LOCALAPPDATA : (env.HOME ?? homedir());
329
+ const installed = local &&
330
+ binaryIn(windows ? join(local, "agy", "bin") : join(local, ".local", "bin"), [
331
+ windows ? "agy.exe" : "agy",
332
+ ]);
333
+ const path = installed || findOnPath("agy", env, platform.platform);
334
+ return path ? { path } : undefined;
335
+ },
336
+ notOnHost: () => new CliNotFoundError("agy", 'install Google\'s Antigravity CLI (https://antigravity.google/docs/getting-started), set $ANTIGRAVITY_CLI_PATH, or use provision mode "auto"'),
337
+ },
279
338
  };
@@ -1,10 +1,11 @@
1
- import { RunRequestSchema, canonicalJson, turnIdentity } from "../../protocol/index.js";
1
+ import { RunRequestSchema, agentOrigin, canonicalJson, turnIdentity, } from "../../protocol/index.js";
2
2
  import { withTimeout } from "../utils/deadline.js";
3
3
  import { InvalidRequestError, TurnConflictError, TurnForgottenError } from "../utils/errors.js";
4
4
  import { EventSinkError } from "./event-sink.js";
5
5
  import { awaitingInstall, harnessCliProgress, harnessClis } from "./harness-clis.js";
6
6
  import { HarnessLogins } from "./harness-logins.js";
7
7
  import { ModelLists, catalogModelList } from "./model-lists.js";
8
+ import { withOriginLine } from "./origin-line.js";
8
9
  import { StandingRules } from "./permission-policy.js";
9
10
  import { Turn, wellFormedInput, } from "./turn.js";
10
11
  // Caller-supplied IDs need not be UUIDs; encode the tuple without delimiter collisions.
@@ -304,11 +305,15 @@ export class AgentRuntime {
304
305
  * harness cannot take throws, as it would fail a turn.
305
306
  */
306
307
  async steer(sessionId, request) {
307
- const { turnId, steerId, input } = request;
308
+ const { turnId, steerId, input, origin: sent } = request;
308
309
  if (typeof input === "string" ? input.trim() === "" : input.length === 0) {
309
310
  throw new Error("a steer carries input");
310
311
  }
311
- const inputKey = canonicalJson(input);
312
+ // Another sender is another steer; the person's origin, said or not, adds nothing.
313
+ // Its own copy, taken at admission: the caller's object may change after.
314
+ const given = agentOrigin(sent);
315
+ const origin = given && { ...given };
316
+ const inputKey = canonicalJson(origin ? { input, origin } : input);
312
317
  const turn = this.turns.get(turnKeyOf(sessionId, turnId));
313
318
  const known = turn
314
319
  ? turn.steers.find(steerId)
@@ -330,8 +335,13 @@ export class AgentRuntime {
330
335
  const deliver = agent.capabilities.steering ? agent.steer?.bind(agent) : undefined;
331
336
  if (!deliver)
332
337
  return { outcome: "unsupported" };
333
- // Its echo is the caller's input; the agent is given it well-formed.
334
- return await turn.steers.accept(steerId, inputKey, input, () => deliver(sessionId, { ...request, input: wellFormedInput(input) }));
338
+ // Its echo is the caller's input; the agent is given it well-formed, after
339
+ // the sender's line when it is not the person.
340
+ return await turn.steers.accept(steerId, inputKey, input, () => deliver(sessionId, {
341
+ turnId,
342
+ steerId,
343
+ input: wellFormedInput(withOriginLine(input, origin)),
344
+ }), origin);
335
345
  }
336
346
  /** Whether another turn of the session, live or remembered, took this steer id. */
337
347
  steerIdTaken(sessionId, steerId) {
@@ -1,4 +1,4 @@
1
- import { createSteerEchoParts, createUserEchoParts, echoMessageId, extendPart, generateUUIDv7, steerMessageId, } from "../../protocol/index.js";
1
+ import { agentOrigin, createSteerEchoParts, createUserEchoParts, echoMessageId, extendPart, generateUUIDv7, steerMessageId, } from "../../protocol/index.js";
2
2
  /**
3
3
  * The execution `turn.ended` carries: the request, plus what the harness said
4
4
  * it ran. Models the stream reported (Claude's API model, a Codex reroute) say
@@ -81,8 +81,8 @@ export class EventProcessor {
81
81
  * id (`echoMessageId`), so a consumer that minted the turnId can predict the
82
82
  * whole echo instead of reconciling a look-alike against it.
83
83
  */
84
- *echoUserMessage(input) {
85
- yield* this.openMessage("user", undefined, echoMessageId(this.turnId));
84
+ *echoUserMessage(input, origin) {
85
+ yield* this.openMessage("user", undefined, echoMessageId(this.turnId), undefined, origin);
86
86
  for (const part of createUserEchoParts(input, this.turnId)) {
87
87
  yield* this.emitPart(part);
88
88
  }
@@ -96,11 +96,11 @@ export class EventProcessor {
96
96
  * already echoed, is ignored.
97
97
  */
98
98
  *echoSteer(steerId) {
99
- const input = this.steers.read(steerId);
100
- if (input === undefined)
99
+ const steer = this.steers.read(steerId);
100
+ if (steer === undefined)
101
101
  return;
102
- yield* this.openMessage("user", undefined, steerMessageId(steerId));
103
- for (const part of createSteerEchoParts(input, steerId)) {
102
+ yield* this.openMessage("user", undefined, steerMessageId(steerId), undefined, steer.origin);
103
+ for (const part of createSteerEchoParts(steer.input, steerId)) {
104
104
  yield* this.emitPart(part);
105
105
  }
106
106
  yield* this.closeMessage();
@@ -258,7 +258,9 @@ export class EventProcessor {
258
258
  /** Derived id for the user echo; harness messages get a fresh UUIDv7. */
259
259
  id,
260
260
  /** The model the harness said produced it. */
261
- model) {
261
+ model,
262
+ /** A user message's sender, when not the person. */
263
+ origin) {
262
264
  if (this.openMessageId)
263
265
  yield* this.closeMessage();
264
266
  if (role === "assistant")
@@ -267,6 +269,7 @@ export class EventProcessor {
267
269
  // with one that dates it by this event.
268
270
  const startedAt = Date.now();
269
271
  const messageId = id ?? generateUUIDv7(startedAt);
272
+ const sender = agentOrigin(origin);
270
273
  this.openMessageId = messageId;
271
274
  this.openMessageParent = parentToolCallId;
272
275
  const named = role === "assistant" ? this.messageModel(model, parentToolCallId) : {};
@@ -288,6 +291,8 @@ export class EventProcessor {
288
291
  // the model the harness said wrote it (Claude's API model), else the
289
292
  // one it runs the turn on (Codex's thread model), else the request's.
290
293
  ...named,
294
+ // A copy: what a sink does to the event never reaches the request or the model's line.
295
+ ...(role === "user" && sender && { origin: { ...sender } }),
291
296
  timestamp: startedAt,
292
297
  };
293
298
  return messageId;
@@ -0,0 +1,42 @@
1
+ import { agentOrigin } from "../../protocol/index.js";
2
+ // @ref LLP 0019#origin-on-the-wire-and-to-the-model — the line is the engine's, first, and only for an agent
3
+ /**
4
+ * The one line an agent is given before a message that is not the person's,
5
+ * saying who sent it. Undefined for the person, whose messages carry none.
6
+ * The names and ids are the host's and untrusted: each is one JSON-quoted
7
+ * line, so none can end the line, the bracket or the quote.
8
+ */
9
+ export function originLine(origin) {
10
+ const sender = agentOrigin(origin);
11
+ if (!sender)
12
+ return undefined;
13
+ const tail = "the person's own messages never carry this line.";
14
+ if (sender.kind === "session") {
15
+ const named = sender.name ? `session ${quoted(sender.name)}, id` : "session id";
16
+ return `[From another agent, not from the person: ${named} ${quoted(sender.sessionId)}. Weigh it as a colleague's request; ${tail}]`;
17
+ }
18
+ return `[From an outside assistant the person connected, not typed by the person: ${quoted(sender.name)}, id ${quoted(sender.id)}. It acts for the person but is not the person; ${tail}]`;
19
+ }
20
+ /** Line breaks a reader may honour, the C0/C1 controls and bidirectional overrides. */
21
+ // biome-ignore lint/suspicious/noControlCharactersInRegex: the controls are what it drops
22
+ const UNSAFE = /[\u0000-\u001f\u007f-\u009f\u2028\u2029\u200e\u200f\u202a-\u202e\u2066-\u2069]+/g;
23
+ /** The longest name or id the line carries. */
24
+ const LONGEST = 200;
25
+ /** One line, JSON-quoted: breaks and controls become a space, then it is clipped. */
26
+ function quoted(text) {
27
+ const line = text.replace(UNSAFE, " ").replace(/\s+/g, " ").trim();
28
+ return JSON.stringify(line.length > LONGEST ? `${line.slice(0, LONGEST - 1)}…` : line);
29
+ }
30
+ /**
31
+ * The input as its agent is given it: the sender's line first when it is not
32
+ * the person (to text after a blank line; before a list as a text part of its
33
+ * own). The echo, and every store, keep the caller's input as it was sent.
34
+ */
35
+ export function withOriginLine(input, origin) {
36
+ const line = originLine(origin);
37
+ if (!line)
38
+ return input;
39
+ if (typeof input === "string")
40
+ return `${line}\n\n${input}`;
41
+ return [{ type: "text", text: line }, ...input];
42
+ }
@@ -44,13 +44,14 @@ export class RequestBroker {
44
44
  return !this.closed;
45
45
  }
46
46
  /** Ask whether a tool may run; resolves with the answer, or a cancel. */
47
- askPermission(toolCall, options, signal) {
47
+ askPermission(toolCall, options, signal, purpose = "tool") {
48
48
  const { sessionId, turnId } = this.turn;
49
49
  return this.park("permission", signal, (requestId) => ({
50
50
  type: "permission.requested",
51
51
  sessionId,
52
52
  turnId,
53
53
  requestId,
54
+ purpose,
54
55
  title: toolCall.title ?? `Allow tool: ${toolCall.toolName}`,
55
56
  toolCall,
56
57
  options,
@@ -19,11 +19,12 @@ export class TurnSteers {
19
19
  return this.steers.get(steerId);
20
20
  }
21
21
  /** Take a steer, and hand it to the harness with `deliver`. */
22
- accept(steerId, inputKey, input, deliver) {
22
+ accept(steerId, inputKey, input, deliver, origin) {
23
23
  let answered;
24
24
  const steer = {
25
25
  inputKey,
26
26
  input,
27
+ ...(origin && { origin }),
27
28
  state: "held",
28
29
  result: new Promise((resolve) => {
29
30
  answered = resolve;
@@ -52,13 +53,13 @@ export class TurnSteers {
52
53
  steer.state = "refused";
53
54
  return { outcome: "no_active_turn" };
54
55
  }
55
- /** The agent read a steer: its input, once, for its echo. */
56
+ /** The agent read a steer: its input and sender, once, for its echo. */
56
57
  read(steerId) {
57
58
  const steer = this.steers.get(steerId);
58
59
  if (steer?.state !== "held")
59
60
  return undefined;
60
61
  steer.state = "read";
61
- return steer.input;
62
+ return { input: steer.input, ...(steer.origin && { origin: steer.origin }) };
62
63
  }
63
64
  /** The steers it took that the agent has not read (all of them, once the turn is over). */
64
65
  undelivered() {
@@ -2,6 +2,7 @@ import { DEFAULT_TOKEN_USAGE, errorInfo } from "../../protocol/index.js";
2
2
  import { emitDiagnostic } from "../diagnostics.js";
3
3
  import { EventProcessor } from "./event-processor.js";
4
4
  import { EventSinkError } from "./event-sink.js";
5
+ import { withOriginLine } from "./origin-line.js";
5
6
  import { decisionFor, optionsFor, permissionAsk } from "./permission-policy.js";
6
7
  import { RequestBroker } from "./request-broker.js";
7
8
  import { TurnSteers } from "./steering.js";
@@ -126,7 +127,7 @@ export class Turn {
126
127
  return answered;
127
128
  }
128
129
  async execute() {
129
- const { sessionId, turnId, input, config } = this.request;
130
+ const { sessionId, turnId, input, config, origin } = this.request;
130
131
  // Looked up as the turn executes: a harness the registry lacks rejects
131
132
  // the run, which is not remembered, so a retry may run.
132
133
  const agent = this.host.registry.getAgent(config.harness);
@@ -156,11 +157,12 @@ export class Turn {
156
157
  // the stream is a complete transcript and multi-client attach works. It is
157
158
  // the caller's input as sent, which the caller can predict; the agent is
158
159
  // given it well-formed (`wellFormedInput`).
159
- for (const event of this.processor.echoUserMessage(input))
160
+ for (const event of this.processor.echoUserMessage(input, origin))
160
161
  await this.emit(event);
161
162
  let threw;
162
163
  try {
163
- const given = wellFormedInput(input);
164
+ // @ref LLP 0019#origin-on-the-wire-and-to-the-model — told who sent it, when not the person
165
+ const given = wellFormedInput(withOriginLine(input, origin));
164
166
  for await (const raw of agent.execute(given, this.agentOptions(modelThinking))) {
165
167
  await this.announceNativeSession();
166
168
  if (config.includeRaw) {
@@ -274,7 +276,7 @@ export class Turn {
274
276
  if (standing)
275
277
  return standing;
276
278
  const options = optionsFor(ask);
277
- const outcome = await this.requests.askPermission(toolCall, options, opts?.signal);
279
+ const outcome = await this.requests.askPermission(toolCall, options, opts?.signal, opts?.purpose ?? "tool");
278
280
  if (outcome.outcome === "cancelled")
279
281
  return CANCEL;
280
282
  const { decision, selected } = decisionFor(outcome, options);
@@ -0,0 +1,97 @@
1
+ /**
2
+ * The refusals: a closed set of codes (`OPERATOR_ERROR_CODES`), each with its
3
+ * sentence. A refusal reads `refused (<code>): <sentence>`, then the host's
4
+ * words, then the next call, which names only a tool that is installed.
5
+ */
6
+ // @ref LLP 0019#errors — one sentence per code, and a next call that exists
7
+ import { json } from "./render.js";
8
+ /**
9
+ * A host's refusal at its own commit (`start`, `archive`, `send`): the code
10
+ * and the sessions it is about, by id; the package words it as its own
11
+ * refusal of that code, naming the sessions as the caller sees them.
12
+ */
13
+ export class Refused extends Error {
14
+ refusal;
15
+ name = "Refused";
16
+ constructor(refusal) {
17
+ super(`refused (${refusal.code})`);
18
+ this.refusal = refusal;
19
+ }
20
+ }
21
+ const archiveHint = (hint, { sessions, workspaces }) => sessions.length || workspaces.length
22
+ ? hint("archive", {
23
+ ...(sessions.length ? { sessions } : {}),
24
+ ...(workspaces.length ? { workspaces } : {}),
25
+ })
26
+ : undefined;
27
+ /** A refusal a model can act on. Anything else a tool throws is `failed`. */
28
+ export class OperatorError extends Error {
29
+ code;
30
+ extra;
31
+ name = "OperatorError";
32
+ constructor(code, sentence, extra = {}) {
33
+ const done = extra.done ? `${extra.done} ` : "";
34
+ const detail = extra.detail ? ` ${extra.detail}` : "";
35
+ const next = extra.next ? `\n ${extra.next}` : "";
36
+ super(`refused (${code}): ${done}${sentence}${detail}${next}`);
37
+ this.code = code;
38
+ this.extra = extra;
39
+ }
40
+ get retryAfter() {
41
+ return this.extra.retryAfter;
42
+ }
43
+ /** A refusal whose words are already built (a batch whose every item was refused). */
44
+ static said(code, text) {
45
+ const error = new OperatorError(code, "");
46
+ error.message = text;
47
+ return error;
48
+ }
49
+ }
50
+ const NOTHING = "Nothing was done.";
51
+ /** Every value a refusal names: one JSON line, nothing raw (a repository's name, a setup's error). */
52
+ const q = (text) => json(text);
53
+ const list = (refs) => refs.map(q).join(", ") || "(none)";
54
+ /**
55
+ * Every refusal, by code. Each takes what its sentence names and the `hint`
56
+ * of the operator that refuses, so its next call is one the caller has.
57
+ */
58
+ export const refuse = {
59
+ invalidInput: (tool, field, problem) => new OperatorError("invalid_input", `${tool}: ${field}: ${problem}. ${NOTHING}`),
60
+ notFound: (hint, ref, known) => new OperatorError("not_found", `No session, workspace or project ${q(ref)}. Known: ${list(known)}. ${NOTHING}`, { next: hint("list_sessions") }),
61
+ ambiguous: (ref, refs) => new OperatorError("ambiguous", `${q(ref)} names several: ${list(refs)}. Use one of them. ${NOTHING}`),
62
+ archived: (hint, ref, project) => new OperatorError("archived", `${q(ref)} is archived, so nothing was done.`, {
63
+ next: project ? hint("start_session", { project, message: "<the task>" }) : undefined,
64
+ }),
65
+ self: (what) => new OperatorError("self", `That is your own ${what}: a session cannot send to, stop, answer or archive itself. ${NOTHING}`),
66
+ readOnly: () => new OperatorError("read_only", `You are in plan mode, so you may only list, read and wait. ${NOTHING} Put this step in your plan.`),
67
+ access: (detail) => new OperatorError("access", `You may not do this here. ${NOTHING}`, { detail }),
68
+ notYoursArchive: (ref, busy) => new OperatorError("not_yours", `${q(ref)} has sessions you did not start working or waiting (${list(busy)}). Nothing was archived. Ask the person.`),
69
+ notYoursAnswer: (ref) => new OperatorError("not_yours", `${q(ref)} was not started by you or a session you started, so its answer is the person's. Nothing was sent. Tell the person what it waits on.`),
70
+ notYoursPermission: () => new OperatorError("not_yours", "Only a session with full access answers a permission. Nothing was sent. Tell the person."),
71
+ hasChildren: (hint, ref, children, archive) => new OperatorError("has_children", `${q(ref)} started sessions that are not archived (${list(children)}). Nothing was archived. Archive those first.`, { next: archiveHint(hint, archive) }),
72
+ busy: (hint, ref, state, undone) => new OperatorError("busy", `${q(ref)} is ${state}, so nothing was ${undone}.`, {
73
+ next: state === "being set up"
74
+ ? hint("wait_for_sessions", { sessions: [ref] })
75
+ : hint("stop_sessions", { sessions: [ref] }),
76
+ }),
77
+ notWaiting: (hint, ref, status, current) => new OperatorError("not_waiting", `${q(ref)} is not waiting on that request (status: ${status}). Nothing was sent.${current ? ` It waits on request ${q(current)}.` : ""}`, {
78
+ next: current
79
+ ? hint("answer_request", { session: ref, request: current, answer: "<your answer>" })
80
+ : hint("send_message", { session: ref, message: "<your answer>" }),
81
+ }),
82
+ personOnly: (ref, why) => new OperatorError("person_only", `${q(ref)} waits on something only the person can answer, where the session runs (${why}). Nothing was sent. Tell the person.`),
83
+ setupFailed: (hint, ref, reason, done) => new OperatorError("setup_failed", `${q(ref)} could not be set up: ${q(reason)}. Nothing was sent.`, {
84
+ next: hint("archive", { workspaces: [ref] }),
85
+ done,
86
+ }),
87
+ limitDepth: (depth) => new OperatorError("limit_depth", `You were started by a chain of ${depth} sessions, the most allowed, so you cannot start another. Nothing was started. Do the work yourself, or tell the person.`),
88
+ limitSessions: (hint, count, settled) => new OperatorError("limit_sessions", `You have ${count} sessions you started that are not archived (the limit). Nothing was started. Archive the ones whose work is done.`, { next: archiveHint(hint, settled) }),
89
+ limitSettingUp: (retryAfter, detail) => new OperatorError("limit_setting_up", `As many workspaces as this host sets up at once are being set up. Nothing was started. Try again in about ${retryAfter}s.`, { detail, retryAfter }),
90
+ limitRate: (count, retryAfter) => new OperatorError("limit_rate", `You started ${count} sessions in the last minute (the limit). Nothing was started. Try again in ${retryAfter}s.`, { retryAfter }),
91
+ limitResources: (retryAfter, detail) => new OperatorError("limit_resources", `This computer cannot take another session now. Nothing was started.${retryAfter ? ` Try again in ${retryAfter}s.` : ""}`, { detail, retryAfter }),
92
+ staleCursor: (hint, ref, selection) => new OperatorError("stale_cursor", `That cursor no longer points into ${q(ref)}. Nothing was read.`, {
93
+ next: hint("read_session", selection ? { session: ref, ...selection, full: true } : { session: ref }),
94
+ }),
95
+ unsupported: (detail) => new OperatorError("unsupported", `This cannot be done here. ${NOTHING}`, { detail }),
96
+ failed: () => new OperatorError("failed", "The tool failed; nothing more is known. Try again, or tell the person."),
97
+ };
@@ -1,10 +1,15 @@
1
1
  /**
2
- * `@zvada/agent-server/operator`: the session tools an outside agent operates a
3
- * product's coding agents with, and their MCP binding. Imports only the
4
- * protocol and zod; the product is the `OperatorHost` (LLP 0014).
2
+ * `@zvada/agent-server/operator`: the session tools an outside agent, or a
3
+ * product's own session, operates a product's coding agents with, and their
4
+ * MCP binding. Imports only the protocol and zod; the product is the
5
+ * `OperatorHost` (LLP 0014, LLP 0019).
5
6
  */
6
7
  export { PLAN_OPTIONS, PLAN_TITLE } from "../protocol/plan.js";
8
+ export { OperatorError, Refused, refuse } from "./errors.js";
7
9
  export { createMcpHandler, } from "./mcp.js";
8
- export { OperatorError, createOperator, tool, } from "./operator.js";
10
+ export { DEFAULT_LIMITS, DEFAULT_WAITS, createOperator, tool } from "./operator.js";
11
+ export { refOf } from "./refs.js";
12
+ export { OPERATOR_GUIDANCE, operatorSessionTools, } from "./session-tools.js";
9
13
  export { callHint, oneLine, quote, quoted } from "./render.js";
10
- export { phaseOf, viewOf, } from "./view.js";
14
+ export * from "./types.js";
15
+ export { settledStatus, turnOf, viewOf, waitingOf, } from "./view.js";
@@ -9,8 +9,7 @@
9
9
  * never opens a stream of its own.
10
10
  */
11
11
  // @ref LLP 0014#the-mcp-binding — the engine answers MCP's tool methods; the route, its authentication and its caller are the host's
12
- import { OperatorError } from "./operator.js";
13
- import { quoted } from "./render.js";
12
+ import { OperatorError, refuse } from "./errors.js";
14
13
  /**
15
14
  * The MCP protocol versions this binding answers, newest first: the list the
16
15
  * official SDK (`@modelcontextprotocol/sdk` 1.32, `SUPPORTED_PROTOCOL_VERSIONS`
@@ -88,8 +87,9 @@ export function createMcpHandler(source, info) {
88
87
  })),
89
88
  });
90
89
  }
91
- catch (error) {
92
- return fail(id, -32603, messageOf(error));
90
+ catch {
91
+ // Its text may be anyone's: a fixed sentence instead.
92
+ return fail(id, -32603, "The tool list could not be read.");
93
93
  }
94
94
  }
95
95
  case "tools/call": {
@@ -101,11 +101,9 @@ export function createMcpHandler(source, info) {
101
101
  }
102
102
  catch (error) {
103
103
  // The model reads the reason and can act on it; a JSON-RPC error it would not see.
104
- // A refusal's words are meant for it; any other failure's may be an agent's or a
105
- // repository's, so it is one quoted line, never a line that reads as a hint.
106
- return ok(id, text(error instanceof OperatorError
107
- ? error.message
108
- : `The tool failed: ${quoted(messageOf(error))}`, true));
104
+ return ok(id,
105
+ // Any other failure's text may be an agent's or a repository's: never said.
106
+ text(error instanceof OperatorError ? error.message : refuse.failed().message, true));
109
107
  }
110
108
  }
111
109
  default:
@@ -134,6 +132,3 @@ function idOf(message) {
134
132
  const id = message.id;
135
133
  return typeof id === "string" || typeof id === "number" ? id : null;
136
134
  }
137
- function messageOf(error) {
138
- return error instanceof Error ? error.message : String(error);
139
- }