@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
@@ -12,18 +12,20 @@ export function loginMethod(methods, id) {
12
12
  ]);
13
13
  }
14
14
  /**
15
- * Signing in from a terminal with the CLI's own command. Of the environment a
16
- * turn would run with, it takes only the variable that picks the CLI's store
17
- * (`storeVariable`), so the login lands where turns look.
15
+ * Signing in from a terminal with the CLI's own command. A CLI with more than
16
+ * one store names the variable that picks it (`store.variable`) and the
17
+ * environment a turn would run with (`store.env`): of it, the method takes
18
+ * only that variable, so the login lands where turns look. A CLI with one
19
+ * store names none.
18
20
  */
19
- export function terminalMethod(command, env, storeVariable) {
20
- const store = env[storeVariable];
21
+ export function terminalMethod(command, store) {
22
+ const value = store?.env[store.variable];
21
23
  return {
22
24
  id: "terminal",
23
25
  kind: "terminal",
24
26
  label: [basename(command[0] ?? ""), ...command.slice(1)].join(" "),
25
27
  command,
26
- ...(store && { env: { [storeVariable]: store } }),
28
+ ...(store && value && { env: { [store.variable]: value } }),
27
29
  };
28
30
  }
29
31
  /** How long a CLI's own auth command may take. */
@@ -21,6 +21,7 @@ import { inputToText, } from "../../../protocol/index.js";
21
21
  import { onAbort, untilAborted } from "../../utils/deadline.js";
22
22
  import { AgentServerError, InvalidRequestError } from "../../utils/errors.js";
23
23
  import { NO_ANSWERS, questionRequest } from "../elicitation.js";
24
+ import { hostToolSessions, refuseHostName, } from "../host-tools.js";
24
25
  import { SessionAgent } from "../session-agent.js";
25
26
  import { callMcpTool, callableServer } from "./mcp-call.js";
26
27
  import { readStep } from "./steps.js";
@@ -111,23 +112,32 @@ export class ScriptedAgent extends SessionAgent {
111
112
  /** Turns each session has run in this engine. */
112
113
  turns = new Map();
113
114
  processes;
115
+ host;
116
+ /** Each session's running turn and its mode, as its host tools' calls read them. */
117
+ live = new Map();
114
118
  constructor(options) {
115
119
  super();
116
120
  this.options = options;
117
121
  this.processes = options.processes;
122
+ // A script decides itself whether to ask before a call (`ask`): its writes are not held to full access.
123
+ this.host = hostToolSessions(options.hostTools, this.harness, {
124
+ live: (sessionId) => this.live.get(sessionId),
125
+ });
118
126
  }
119
127
  async listModels() {
120
128
  return [MODEL];
121
129
  }
122
- async *executeTurn(input, options, controller) {
130
+ async *executeTurn(input, given, controller) {
123
131
  const { signal } = controller;
124
132
  // A turn cancelled before it began is still a turn of its script: it
125
133
  // opens it and stops at its first step (or at its end, when it has no
126
134
  // step), so a queue skips the turn's steps through its `end` and the
127
135
  // next turn plays its own.
128
136
  // A script runs nothing of its own: the abort stops it, so a cancel is confirmed at once.
129
- this.cancelWith(options, async () => true);
130
- const { sessionId, turnId } = options;
137
+ this.cancelWith(given, async () => true);
138
+ const { sessionId, turnId } = given;
139
+ const options = await this.withHostTools(given);
140
+ this.live.set(sessionId, { turnId, permissionMode: options.permissionMode ?? "default" });
131
141
  // A later turn of the session resumes the id its first one reported.
132
142
  options.onNativeSession?.(options.resumeSessionId ?? `scripted-${sessionId}`, {
133
143
  resumed: options.resumeSessionId !== undefined,
@@ -157,6 +167,8 @@ export class ScriptedAgent extends SessionAgent {
157
167
  }
158
168
  }
159
169
  finally {
170
+ if (this.live.get(sessionId)?.turnId === turnId)
171
+ this.live.delete(sessionId);
160
172
  // Not awaited: a cancelled turn may have left a `next()` the test never releases.
161
173
  void Promise.resolve(iterator.return?.()).catch(() => { });
162
174
  }
@@ -316,10 +328,25 @@ export class ScriptedAgent extends SessionAgent {
316
328
  }
317
329
  return { input: decision.updatedInput ?? input };
318
330
  }
331
+ /** The turn's MCP servers with the host's, by the name its source gives, when it has one. */
332
+ async withHostTools(options) {
333
+ const lease = await this.host?.lease(options.sessionId, options.cwd);
334
+ if (!lease)
335
+ return options;
336
+ const { source } = lease;
337
+ refuseHostName(options.mcpServers, source.name);
338
+ const server = await lease.http();
339
+ return { ...options, mcpServers: { ...options.mcpServers, [source.name]: server } };
340
+ }
319
341
  async release(sessionId) {
320
342
  this.turns.delete(sessionId);
343
+ this.host?.release(sessionId);
321
344
  await super.release(sessionId);
322
345
  }
346
+ async terminateAll() {
347
+ await super.terminateAll();
348
+ await this.host?.close();
349
+ }
323
350
  }
324
351
  /** The turn's config, as `echo: "config"` says it: MCP servers by name, `env` by its keys alone. */
325
352
  function echoConfig(options) {
@@ -27,7 +27,10 @@ export class StderrTail {
27
27
  }
28
28
  /** The last `max` characters, redacted before the cut. */
29
29
  get text() {
30
- return redactSecrets(this.tail).slice(-this.max);
30
+ // A cut through a surrogate pair drops its remaining half.
31
+ return redactSecrets(this.tail)
32
+ .slice(-this.max)
33
+ .replace(/^[\uDC00-\uDFFF]/, "");
31
34
  }
32
35
  }
33
36
  /** What a secret's place reads once it is taken out. */
@@ -61,7 +64,7 @@ const SECRETS = [
61
64
  * `text` with every secret it holds replaced by `[REDACTED]`, and everything
62
65
  * else as it was. For whatever of a CLI's own output becomes part of an
63
66
  * error: the Claude SDK redacts the stderr it quotes, and this engine's exit
64
- * errors (Claude's restored tail, Codex's and ACP's) are redacted the same way.
67
+ * errors use that same redacted tail on every harness.
65
68
  */
66
69
  export function redactSecrets(text) {
67
70
  let redacted = text;
@@ -5,6 +5,7 @@ import { createClaudeCodeTransformer } from "./agents/claude-code/adapter.js";
5
5
  import { ClaudeCodeAgent } from "./agents/claude-code/claude-agent.js";
6
6
  import { createCodexAppServerTransformer } from "./agents/codex-app-server/adapter.js";
7
7
  import { CodexAppServerAgent, } from "./agents/codex-app-server/codex-agent.js";
8
+ import { geminiHarness } from "./agents/gemini/profile.js";
8
9
  import { AgentRegistry } from "./agents/registry.js";
9
10
  import { createScriptedTransformer } from "./agents/scripted/adapter.js";
10
11
  import { ScriptedAgent } from "./agents/scripted/scripted-agent.js";
@@ -45,6 +46,18 @@ const HARNESSES = {
45
46
  }),
46
47
  createCodexAppServerTransformer,
47
48
  ],
49
+ gemini: (opts, cliPath, processes) => {
50
+ const { idleTimeoutMs, cancelConfirmMs, cancelGraceMs, hostTools, inheritConfig } = opts;
51
+ return geminiHarness({
52
+ ...(inheritConfig && { inheritConfig }),
53
+ resolveCliPath: cliPath("agy"),
54
+ idleTimeoutMs,
55
+ cancelConfirmMs,
56
+ cancelGraceMs,
57
+ hostTools,
58
+ processes,
59
+ });
60
+ },
48
61
  acp: (opts, _cliPath, processes) => {
49
62
  if (!opts.acp) {
50
63
  throw new Error("the acp harness requires CreateRegistryOptions.acp (resolveLaunch)");
@@ -67,7 +80,10 @@ const HARNESSES = {
67
80
  throw new Error("the scripted harness requires CreateRegistryOptions.scripted (turn)");
68
81
  }
69
82
  // @ref LLP 0007#what-each-harness-does — it starts none, so a restart vouches for it
70
- return [new ScriptedAgent({ ...opts.scripted, processes }), createScriptedTransformer];
83
+ return [
84
+ new ScriptedAgent({ ...opts.scripted, hostTools: opts.hostTools, processes }),
85
+ createScriptedTransformer,
86
+ ];
71
87
  },
72
88
  };
73
89
  const atTheTop = (option) => `set ${option} at the top level of the registry's options`;
@@ -1,6 +1,7 @@
1
1
  import { spawn as nodeSpawn } from "node:child_process";
2
2
  import { StderrTail } from "../agents/stderr-tail.js";
3
- import { onAbort } from "../utils/deadline.js";
3
+ import { onAbort, withTimeout } from "../utils/deadline.js";
4
+ import { AgentExitedError } from "../utils/errors.js";
4
5
  import { bootId, startToken, verifyRecord } from "./identity.js";
5
6
  import { lifeline } from "./lifeline.js";
6
7
  import { POSIX, aliveTargets, readProcessTable, signalTargets, treeTargets, } from "./process-table.js";
@@ -10,6 +11,8 @@ export const DEFAULT_GRACE_MS = 3_000;
10
11
  const STDERR_TAIL_MAX = 2048;
11
12
  /** How long an exit waits for its stdout's and stderr's last words, as the Claude SDK's own spawner waits for stderr. */
12
13
  const OUTPUT_CLOSE_WAIT_MS = 200;
14
+ /** A broken transport may precede the exit that explains it. */
15
+ const EXIT_REASON_WAIT_MS = 1_000;
13
16
  const POLL_MS = 50;
14
17
  /** How long a SIGKILLed tree may take to be gone before it counts as not stopped. */
15
18
  const KILL_WAIT_MS = 1_000;
@@ -73,6 +76,25 @@ export class NativeProcess {
73
76
  get stderrTail() {
74
77
  return this.tail.text;
75
78
  }
79
+ /** The stderr a failure can show, including when the process printed nothing. */
80
+ get stderrSummary() {
81
+ const tail = this.stderrTail.trim().replace(/\s+/g, " ");
82
+ return tail ? `Last stderr: ${tail}` : "It printed nothing on stderr.";
83
+ }
84
+ /** Once the transport is lost, give the process a moment to exit and drain its output. */
85
+ async exitAfterDisconnect() {
86
+ return (await withTimeout(this.exited, EXIT_REASON_WAIT_MS))?.value;
87
+ }
88
+ // @ref LLP 0016.000#when-a-process-exits-before-answering — one exit sentence for every harness
89
+ exitError(name, { code, signal }, requests) {
90
+ const status = signal
91
+ ? `on ${signal}`
92
+ : code !== null
93
+ ? `with code ${code}`
94
+ : "without an exit status";
95
+ const pending = [...new Set(requests)].join(", ");
96
+ return new AgentExitedError(`${name} exited unexpectedly ${status}${pending ? ` before answering ${pending}` : ""}. ${this.stderrSummary}`);
97
+ }
76
98
  /**
77
99
  * Stop it and everything under it: SIGTERM to its group and its tool
78
100
  * sessions, SIGKILL to what is left after the grace. Whether all of it is
@@ -27,8 +27,56 @@ export async function openToAll(path) {
27
27
  else if (info.isFile())
28
28
  await chmod(path, info.mode & 0o100 ? 0o755 : 0o644);
29
29
  }
30
- export function noBinary(pkg) {
31
- return new CliProvisionError(`downloaded ${pkg.name}@${pkg.registryVersion} has no binary`);
30
+ /** `name` is `<package>@<version>` (`<tool>@<version>` for a file). */
31
+ export function noBinary(name) {
32
+ return new CliProvisionError(`downloaded ${name} has no binary`);
33
+ }
34
+ /**
35
+ * Where an npm build's tarball is and what it must match, asked before a
36
+ * byte of it is fetched: the registry's metadata, refused when it names
37
+ * another tarball than the table pins.
38
+ */
39
+ async function locateTarball(job, { pkg, expected }) {
40
+ const dist = await fetchDist(job.registry, pkg.name, pkg.registryVersion, job.fetch, job.timeouts);
41
+ if (expected.source === "release" && dist.integrity !== expected.integrity) {
42
+ throw new CliProvisionError(`${withoutSecrets(job.registry)} serves another ${pkg.name}@${pkg.registryVersion} than this release pins ` +
43
+ `(${dist.integrity.slice(0, 24)}…, pinned ${expected.integrity.slice(0, 24)}…)`,
44
+ // A digest's digits are no status code: classified by what it is, not its words.
45
+ { category: "internal" });
46
+ }
47
+ return {
48
+ url: dist.tarball,
49
+ integrity: expected.source === "release" ? expected.integrity : dist.integrity,
50
+ };
51
+ }
52
+ /** The tarball, extracted into the staging folder. */
53
+ async function extracted(job, download, staging) {
54
+ const dir = join(staging, "x");
55
+ await mkdir(dir, { mode: 0o700 });
56
+ await job.extract(download, dir);
57
+ return dir;
58
+ }
59
+ /**
60
+ * The download, unpacked into the folder that becomes the install: an npm
61
+ * tarball's payload, or a folder holding only the file's executable under
62
+ * its installed name (the tarball's `member`, or the file itself; a member
63
+ * that is not a regular file is no binary).
64
+ */
65
+ async function unpack(job, download, staging) {
66
+ const { plan } = job;
67
+ if (plan.kind === "npm")
68
+ return plan.payload(await extracted(job, download, staging));
69
+ let executable = download;
70
+ if (plan.member) {
71
+ const member = binaryIn(await extracted(job, download, staging), [plan.member]);
72
+ if (!member)
73
+ throw noBinary(plan.name);
74
+ executable = member;
75
+ }
76
+ const dir = join(staging, "build");
77
+ await mkdir(dir, { mode: 0o700 });
78
+ await rename(executable, join(dir, plan.binary));
79
+ return dir;
32
80
  }
33
81
  /**
34
82
  * Download a build, check it against what it must match, unpack it in a
@@ -37,21 +85,19 @@ export function noBinary(pkg) {
37
85
  * one that loses adopts the winner's tree. Answers the bytes downloaded.
38
86
  */
39
87
  export async function installBuild(job) {
40
- const { spec, pkg, expected, root, dir } = job;
41
- const staging = join(root, ".tmp", `${pkg.name.replace("/", "-")}-${pkg.registryVersion}-${process.pid}-${randomBytes(4).toString("hex")}`);
88
+ const { plan, binaries, root, dir } = job;
89
+ const { name } = plan;
90
+ const stem = plan.kind === "npm"
91
+ ? `${plan.pkg.name.replace("/", "-")}-${plan.pkg.registryVersion}`
92
+ : plan.name.replace("@", "-");
93
+ const staging = join(root, ".tmp", `${stem}-${process.pid}-${randomBytes(4).toString("hex")}`);
42
94
  try {
43
95
  managedDirectory(root, dirname(staging), true);
44
96
  await mkdir(staging, { mode: 0o700 });
45
- const dist = await fetchDist(job.registry, pkg.name, pkg.registryVersion, job.fetch, job.timeouts);
46
- if (expected.source === "release" && dist.integrity !== expected.integrity) {
47
- throw new CliProvisionError(`${withoutSecrets(job.registry)} serves another ${pkg.name}@${pkg.registryVersion} than this release pins ` +
48
- `(${dist.integrity.slice(0, 24)}…, pinned ${expected.integrity.slice(0, 24)}…)`,
49
- // A digest's digits are no status code: classified by what it is, not its words.
50
- { category: "internal" });
51
- }
52
- const tgz = join(staging, "package.tgz");
97
+ const { url, integrity } = plan.kind === "npm" ? await locateTarball(job, plan) : plan;
98
+ const download = join(staging, plan.kind === "npm" ? "package.tgz" : "download");
53
99
  let reportedAt = 0;
54
- const bytes = await downloadWithIntegrity(dist.tarball, tgz, expected.source === "release" ? expected.integrity : dist.integrity, job.fetch, {
100
+ const bytes = await downloadWithIntegrity(url, download, integrity, job.fetch, {
55
101
  timeouts: job.timeouts,
56
102
  onBytes: (receivedBytes, totalBytes) => {
57
103
  const now = Date.now();
@@ -62,18 +108,16 @@ export async function installBuild(job) {
62
108
  },
63
109
  });
64
110
  job.onProgress("verifying", bytes, bytes);
65
- const extracted = join(staging, "x");
66
- await mkdir(extracted, { mode: 0o700 });
67
- await job.extract(tgz, extracted);
68
- const payload = await spec.payload(extracted);
69
- const binary = binaryIn(payload, spec.binaries);
111
+ const payload = await unpack(job, download, staging);
112
+ const binary = binaryIn(payload, binaries);
70
113
  if (!binary)
71
- throw noBinary(pkg);
72
- const sha256 = expected.source === "registry" ? undefined : expected.sha256;
73
- if (sha256) {
114
+ throw noBinary(name);
115
+ const expected = plan.kind === "npm" ? plan.expected : undefined;
116
+ const sha256 = expected?.source === "registry" ? undefined : expected?.sha256;
117
+ if (expected && sha256) {
74
118
  const actual = await sha256Of(binary);
75
119
  if (actual !== sha256) {
76
- throw new CliProvisionError(`${pkg.name}@${pkg.registryVersion}'s binary is not the build ${expected.source === "local" ? expected.vouchedBy : "this release pins"} names (sha256 ${actual}, expected ${sha256})`, { category: "internal" });
120
+ throw new CliProvisionError(`${name}'s binary is not the build ${expected.source === "local" ? expected.vouchedBy : "this release pins"} names (sha256 ${actual}, expected ${sha256})`, { category: "internal" });
77
121
  }
78
122
  }
79
123
  await chmod(binary, 0o755);
@@ -85,12 +129,12 @@ export async function installBuild(job) {
85
129
  catch (error) {
86
130
  // Lost the race with another process installing the same build: the
87
131
  // directory is version-keyed, so its tree is what we would have written.
88
- if (trustedBinaryIn(root, dir, spec.binaries))
132
+ if (trustedBinaryIn(root, dir, binaries))
89
133
  return bytes;
90
- throw new CliProvisionError(`${dir} is there but holds no ${spec.binaries[0]}: remove it, and it installs again`, { cause: error });
134
+ throw new CliProvisionError(`${dir} is there but holds no ${binaries[0]}: remove it, and it installs again`, { cause: error });
91
135
  }
92
- if (!trustedBinaryIn(root, dir, spec.binaries))
93
- throw noBinary(pkg);
136
+ if (!trustedBinaryIn(root, dir, binaries))
137
+ throw noBinary(name);
94
138
  return bytes;
95
139
  }
96
140
  finally {
@@ -13,6 +13,10 @@
13
13
  * governs downloads (compiled binaries, bare sandboxes, `pinned` mode); in
14
14
  * `auto` an installed `@openai/codex` package (a lockfile's) runs instead,
15
15
  * and a `codex` on PATH only in `system` mode.
16
+ * - `agy` is the version of Google's Antigravity CLI the gemini harness
17
+ * downloads. Google's update manifest names only its latest build, so a
18
+ * refresh records the version it names: a bump moves to that one, and
19
+ * only forward. The person's own install runs only in `system` mode.
16
20
  *
17
21
  * A bump is `bun run bump -- <tool>`: it writes what changed upstream, moves
18
22
  * the pin, and runs both refreshes, `releases:refresh` (each platform's build
@@ -23,4 +27,5 @@
23
27
  export const DEFAULT_PINS = {
24
28
  claude: "0.3.327",
25
29
  codex: "0.169.1",
30
+ agy: "1.5.14",
26
31
  };
@@ -9,7 +9,7 @@ import { expectedBuild } from "./checksums.js";
9
9
  import { extractTarGz } from "./extract.js";
10
10
  import { installBuild, noBinary } from "./install-build.js";
11
11
  import { DEFAULT_DOWNLOAD_TIMEOUTS, DEFAULT_NPM_REGISTRY, withoutSecrets, } from "./npm.js";
12
- import { detectPlatform } from "./platform.js";
12
+ import { detectPlatform, platformName } from "./platform.js";
13
13
  import { CLI_RELEASES } from "./releases.js";
14
14
  import { CLI_TOOLS, CLI_TOOL_SPECS, binaryIn } from "./tools.js";
15
15
  function failureOf(error) {
@@ -25,10 +25,11 @@ function messageOf(error) {
25
25
  return error instanceof Error ? error.message : String(error);
26
26
  }
27
27
  /**
28
- * Resolves the native CLIs the harnesses spawn (`claude`, `codex`) and — in
29
- * managed modes — downloads the pinned builds from the npm registry into a
30
- * local cache, checked against this release's table of them (`releases.ts`)
31
- * and installed atomically (`install-build.ts`), so concurrent processes
28
+ * Resolves the native CLIs the harnesses spawn (`CLI_TOOLS`) and — in
29
+ * managed modes — downloads the pinned builds from where each comes from
30
+ * (the npm registry, or the address the release table names) into a local
31
+ * cache, checked against this release's table of them (`releases.ts`) and
32
+ * installed atomically (`install-build.ts`), so concurrent processes
32
33
  * converge on one copy. What differs per tool is its `CLI_TOOL_SPECS` entry.
33
34
  *
34
35
  * One instance per runtime; `resolve` is memoized per tool (a failure clears
@@ -263,8 +264,31 @@ export class CliProvisioner {
263
264
  this.say(note);
264
265
  version = spec.defaultVersion();
265
266
  }
266
- const pkg = spec.package(this.platform, version);
267
- return { version, pkg, entry: `${version}-${pkg.suffix}` };
267
+ const pkg = spec.source.kind === "npm" ? spec.source.package(this.platform, version) : undefined;
268
+ const suffix = pkg?.suffix ?? platformName(this.platform);
269
+ const name = pkg ? `${pkg.name}@${pkg.registryVersion}` : `${tool}@${version}`;
270
+ return { version, suffix, entry: `${version}-${suffix}`, pkg, name };
271
+ }
272
+ // @ref LLP 0010#source-kinds — the one place a build's pin is checked: a `url` build the table does not hold is refused
273
+ /**
274
+ * What installing `build` takes, resolved before anything is fetched: an
275
+ * npm build's package and what it must match (said once when that is not
276
+ * this release's table), or the file the table names for a `url` source.
277
+ */
278
+ plan(tool, build) {
279
+ const { source, localBuild } = CLI_TOOL_SPECS[tool];
280
+ const { version, suffix, name } = build;
281
+ const expected = expectedBuild(tool, version, suffix, this.releases, localBuild);
282
+ if (source.kind === "npm") {
283
+ if (expected.source !== "release")
284
+ this.say(`${tool} ${version} (${suffix}) is not pinned by this agent-server release: checked against ${expected.source === "local" ? expected.vouchedBy : "the registry's checksum only"}`);
285
+ const pkg = build.pkg ?? source.package(this.platform, version);
286
+ return { kind: "npm", name, pkg, expected, payload: source.payload };
287
+ }
288
+ if (expected.source !== "release" || !expected.url)
289
+ throw new CliProvisionError(`${tool} ${version} (${suffix}) is not a build this agent-server release pins, and only a pinned build of ${tool} downloads: pin the release's version, or name a binary with its override`, { category: "invalid_request" });
290
+ const { url, integrity } = expected;
291
+ return { kind: "file", name, url, integrity, ...source.executable(this.platform) };
268
292
  }
269
293
  /** Pin trusted aliases to their physical location and recheck on every use. */
270
294
  ensureTrustedCacheRoot() {
@@ -282,7 +306,7 @@ export class CliProvisioner {
282
306
  await this.download(tool, build, root, dir);
283
307
  path = trustedBinaryIn(root, dir, spec.binaries);
284
308
  if (!path)
285
- throw noBinary(build.pkg);
309
+ throw noBinary(build.name);
286
310
  }
287
311
  await this.used(tool, build.entry, true);
288
312
  // The cache grew: what no process used for a while goes. Best effort.
@@ -293,7 +317,7 @@ export class CliProvisioner {
293
317
  /** Download and install one build, reporting its progress to the observers and the log. */
294
318
  async download(tool, build, root, dir) {
295
319
  const spec = CLI_TOOL_SPECS[tool];
296
- const { version, pkg } = build;
320
+ const { version } = build;
297
321
  let progress = { tool, version, phase: "downloading", receivedBytes: 0 };
298
322
  const report = (next) => {
299
323
  progress = { ...progress, ...next };
@@ -310,14 +334,13 @@ export class CliProvisioner {
310
334
  const startedAt = Date.now();
311
335
  try {
312
336
  report({});
313
- const expected = expectedBuild(tool, version, pkg.suffix, this.releases, spec.localBuild);
314
- if (expected.source !== "release")
315
- this.say(`${tool} ${version} (${pkg.suffix}) is not pinned by this agent-server release: checked against ${expected.source === "local" ? expected.vouchedBy : "the registry's checksum only"}`);
316
- this.log(`downloading ${tool} ${version} (${pkg.suffix}) from ${withoutSecrets(this.registry)}…`);
337
+ const plan = this.plan(tool, build);
338
+ // A file is where the table says; an npm build, the registry's.
339
+ const from = plan.kind === "file" ? new URL(plan.url).origin : withoutSecrets(this.registry);
340
+ this.log(`downloading ${tool} ${version} (${build.suffix}) from ${from}…`);
317
341
  const bytes = await installBuild({
318
- spec,
319
- pkg,
320
- expected,
342
+ plan,
343
+ binaries: spec.binaries,
321
344
  root,
322
345
  dir,
323
346
  registry: this.registry,
@@ -1,7 +1,8 @@
1
1
  /**
2
2
  * The pinned CLIs' builds, by platform: each npm tarball's integrity, and for
3
3
  * Claude the binary's sha256 from Anthropic's signed release manifest (its
4
- * signature verified when this file was generated).
4
+ * signature verified when this file was generated); for agy each build's
5
+ * address and the sha512 Google's unsigned update manifest named for it.
5
6
  */
6
7
  export const CLI_RELEASES = {
7
8
  claude: {
@@ -65,4 +66,41 @@ export const CLI_RELEASES = {
65
66
  },
66
67
  },
67
68
  },
69
+ agy: {
70
+ version: "1.5.14",
71
+ builds: {
72
+ "darwin-arm64": {
73
+ integrity: "sha512-JoMP1Gv7kgDQc88+cb+UtwdVJVe0OA7AGv1umfOisDDmVCLasYZ/dzGAeGkt78hZp1R9F+xLCx6TafE8nDyupg==",
74
+ url: "https://storage.googleapis.com/antigravity-public/antigravity-cli/1.5.14-5302690847260672/darwin-arm/cli_mac_arm64.tar.gz",
75
+ },
76
+ "darwin-x64": {
77
+ integrity: "sha512-G2ofxtvka6bZ0EBdG2CVGJ816/xMPDPOsf0bbQyf1wK1KsELZLi1Ku0NjXGuAsXfPP/V4+PTdUnC2v/M4qhTxw==",
78
+ url: "https://storage.googleapis.com/antigravity-public/antigravity-cli/1.5.14-5302690847260672/darwin-x64/cli_mac_x64.tar.gz",
79
+ },
80
+ "linux-arm64": {
81
+ integrity: "sha512-ybKbukdfY6GoAWGuk7pysiHHpYbZhR5NAGFUZwS6tm1rJ2CyXXFtGRck/HVk8yRkVu4VHiiqN69I281yvcbEYw==",
82
+ url: "https://storage.googleapis.com/antigravity-public/antigravity-cli/1.5.14-5302690847260672/linux-arm/cli_linux_arm64.tar.gz",
83
+ },
84
+ "linux-x64": {
85
+ integrity: "sha512-gzEdPzVFZ2EtwWwa4uqbUD1vaDOqThONOaoinaPzu5mw5NfMoLzkeWsAYNalHYET63RJ7V3A55AL8hcQfqW/+Q==",
86
+ url: "https://storage.googleapis.com/antigravity-public/antigravity-cli/1.5.14-5302690847260672/linux-x64/cli_linux_x64.tar.gz",
87
+ },
88
+ "linux-arm64-musl": {
89
+ integrity: "sha512-9uNfw9qyzUn9Qpbd7ghBucxMcCC2xqrqZFLFs0UrCtjWZFHJCY5Bitay9uq8yBzfExBe0EOQMkixHW+ySucJqw==",
90
+ url: "https://storage.googleapis.com/antigravity-public/antigravity-cli/1.5.14-5302690847260672/linux-arm-musl/cli_linux_arm64_musl.tar.gz",
91
+ },
92
+ "linux-x64-musl": {
93
+ integrity: "sha512-HaJJInJ8W06ENp0IQ1ddfW8YChlG4txCiRca0ePKkllOaHck0ZAqfYPkB/mPCo07fD6XbwNoD9gNvtLS2gDA7Q==",
94
+ url: "https://storage.googleapis.com/antigravity-public/antigravity-cli/1.5.14-5302690847260672/linux-x64-musl/cli_linux_x64_musl.tar.gz",
95
+ },
96
+ "win32-arm64": {
97
+ integrity: "sha512-ss5UYs8YRbJcBcplG1vZNzX9gH+Oe0DGHQ6ZRF3xp2uX7iTIkNX1ugRT+EjKF0901JKtGQGi3cul16m0OZ3f7w==",
98
+ url: "https://storage.googleapis.com/antigravity-public/antigravity-cli/1.5.14-5302690847260672/windows-arm/cli_windows_arm64.exe",
99
+ },
100
+ "win32-x64": {
101
+ integrity: "sha512-eFVIsjJC7JESdZu0tSXZSj1NLpho5c7bnqNOXOAduwCr9d5mxB2PSQPopDeURfaFSD+Zns6Rhnv72dSBJ2DYNQ==",
102
+ url: "https://storage.googleapis.com/antigravity-public/antigravity-cli/1.5.14-5302690847260672/windows-x64/cli_windows_x64.exe",
103
+ },
104
+ },
105
+ },
68
106
  };