@zvada/agent-server 0.3.27 → 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 (170) hide show
  1. package/CHANGELOG.md +38 -0
  2. package/README.md +6 -4
  3. package/dist/core/agents/acp/account.js +111 -0
  4. package/dist/core/agents/acp/acp-agent.js +247 -158
  5. package/dist/core/agents/acp/adapter.js +103 -34
  6. package/dist/core/agents/acp/client.js +169 -42
  7. package/dist/core/agents/acp/known-agents.js +12 -5
  8. package/dist/core/agents/acp/mappings.js +84 -20
  9. package/dist/core/agents/acp/models.js +59 -0
  10. package/dist/core/agents/acp/profile.js +36 -0
  11. package/dist/core/agents/acp/prompts.js +248 -0
  12. package/dist/core/agents/acp/requests.js +4 -4
  13. package/dist/core/agents/claude-code/login.js +4 -1
  14. package/dist/core/agents/claude-code/session.js +38 -10
  15. package/dist/core/agents/claude-code/spawn.js +0 -26
  16. package/dist/core/agents/codex-app-server/client.js +12 -13
  17. package/dist/core/agents/codex-app-server/login.js +4 -1
  18. package/dist/core/agents/gemini/failures.js +133 -0
  19. package/dist/core/agents/gemini/login.js +173 -0
  20. package/dist/core/agents/gemini/profile.js +137 -0
  21. package/dist/core/agents/gemini/tools.js +91 -0
  22. package/dist/core/agents/login.js +8 -6
  23. package/dist/core/agents/stderr-tail.js +5 -2
  24. package/dist/core/presets.js +13 -0
  25. package/dist/core/processes/native-processes.js +23 -1
  26. package/dist/core/provision/install-build.js +70 -26
  27. package/dist/core/provision/pins.js +5 -0
  28. package/dist/core/provision/provisioner.js +39 -16
  29. package/dist/core/provision/releases.js +39 -1
  30. package/dist/core/provision/tools.js +87 -28
  31. package/dist/operator/errors.js +2 -2
  32. package/dist/operator/operator.js +171 -74
  33. package/dist/operator/render.js +33 -25
  34. package/dist/operator/session-tools.js +2 -1
  35. package/dist/protocol/account.js +5 -1
  36. package/dist/protocol/auth.js +5 -1
  37. package/dist/protocol/credentials.js +9 -1
  38. package/dist/protocol/harness.js +9 -1
  39. package/dist/server/bin.js +22 -7
  40. package/dist/server/install.js +6 -4
  41. package/dist/types/core/agents/acp/account.d.ts +55 -0
  42. package/dist/types/core/agents/acp/account.d.ts.map +1 -0
  43. package/dist/types/core/agents/acp/acp-agent.d.ts +65 -36
  44. package/dist/types/core/agents/acp/acp-agent.d.ts.map +1 -1
  45. package/dist/types/core/agents/acp/adapter.d.ts +28 -3
  46. package/dist/types/core/agents/acp/adapter.d.ts.map +1 -1
  47. package/dist/types/core/agents/acp/client.d.ts +66 -4
  48. package/dist/types/core/agents/acp/client.d.ts.map +1 -1
  49. package/dist/types/core/agents/acp/known-agents.d.ts +4 -2
  50. package/dist/types/core/agents/acp/known-agents.d.ts.map +1 -1
  51. package/dist/types/core/agents/acp/mappings.d.ts +53 -7
  52. package/dist/types/core/agents/acp/mappings.d.ts.map +1 -1
  53. package/dist/types/core/agents/acp/models.d.ts +22 -0
  54. package/dist/types/core/agents/acp/models.d.ts.map +1 -0
  55. package/dist/types/core/agents/acp/profile.d.ts +92 -0
  56. package/dist/types/core/agents/acp/profile.d.ts.map +1 -0
  57. package/dist/types/core/agents/acp/prompts.d.ts +108 -0
  58. package/dist/types/core/agents/acp/prompts.d.ts.map +1 -0
  59. package/dist/types/core/agents/acp/requests.d.ts +7 -1
  60. package/dist/types/core/agents/acp/requests.d.ts.map +1 -1
  61. package/dist/types/core/agents/claude-code/login.d.ts.map +1 -1
  62. package/dist/types/core/agents/claude-code/session.d.ts +3 -0
  63. package/dist/types/core/agents/claude-code/session.d.ts.map +1 -1
  64. package/dist/types/core/agents/claude-code/spawn.d.ts +0 -8
  65. package/dist/types/core/agents/claude-code/spawn.d.ts.map +1 -1
  66. package/dist/types/core/agents/codex-app-server/client.d.ts.map +1 -1
  67. package/dist/types/core/agents/codex-app-server/login.d.ts.map +1 -1
  68. package/dist/types/core/agents/gemini/failures.d.ts +25 -0
  69. package/dist/types/core/agents/gemini/failures.d.ts.map +1 -0
  70. package/dist/types/core/agents/gemini/login.d.ts +28 -0
  71. package/dist/types/core/agents/gemini/login.d.ts.map +1 -0
  72. package/dist/types/core/agents/gemini/profile.d.ts +30 -0
  73. package/dist/types/core/agents/gemini/profile.d.ts.map +1 -0
  74. package/dist/types/core/agents/gemini/tools.d.ts +18 -0
  75. package/dist/types/core/agents/gemini/tools.d.ts.map +1 -0
  76. package/dist/types/core/agents/login.d.ts +15 -5
  77. package/dist/types/core/agents/login.d.ts.map +1 -1
  78. package/dist/types/core/agents/stderr-tail.d.ts +1 -1
  79. package/dist/types/core/agents/stderr-tail.d.ts.map +1 -1
  80. package/dist/types/core/presets.d.ts +2 -2
  81. package/dist/types/core/presets.d.ts.map +1 -1
  82. package/dist/types/core/processes/native-processes.d.ts +6 -0
  83. package/dist/types/core/processes/native-processes.d.ts.map +1 -1
  84. package/dist/types/core/provision/checksums.d.ts +7 -1
  85. package/dist/types/core/provision/checksums.d.ts.map +1 -1
  86. package/dist/types/core/provision/install-build.d.ts +32 -6
  87. package/dist/types/core/provision/install-build.d.ts.map +1 -1
  88. package/dist/types/core/provision/pins.d.ts +4 -0
  89. package/dist/types/core/provision/pins.d.ts.map +1 -1
  90. package/dist/types/core/provision/provisioner.d.ts +18 -7
  91. package/dist/types/core/provision/provisioner.d.ts.map +1 -1
  92. package/dist/types/core/provision/releases.d.ts +2 -1
  93. package/dist/types/core/provision/releases.d.ts.map +1 -1
  94. package/dist/types/core/provision/tools.d.ts +36 -7
  95. package/dist/types/core/provision/tools.d.ts.map +1 -1
  96. package/dist/types/operator/errors.d.ts +5 -1
  97. package/dist/types/operator/errors.d.ts.map +1 -1
  98. package/dist/types/operator/operator.d.ts.map +1 -1
  99. package/dist/types/operator/render.d.ts +11 -6
  100. package/dist/types/operator/render.d.ts.map +1 -1
  101. package/dist/types/operator/session-tools.d.ts.map +1 -1
  102. package/dist/types/operator/types.d.ts +1 -0
  103. package/dist/types/operator/types.d.ts.map +1 -1
  104. package/dist/types/protocol/account.d.ts +4 -2
  105. package/dist/types/protocol/account.d.ts.map +1 -1
  106. package/dist/types/protocol/auth.d.ts +10 -7
  107. package/dist/types/protocol/auth.d.ts.map +1 -1
  108. package/dist/types/protocol/clis.d.ts +4 -3
  109. package/dist/types/protocol/clis.d.ts.map +1 -1
  110. package/dist/types/protocol/config.d.ts +2 -0
  111. package/dist/types/protocol/config.d.ts.map +1 -1
  112. package/dist/types/protocol/conversation.d.ts +3 -3
  113. package/dist/types/protocol/credentials.d.ts +8 -0
  114. package/dist/types/protocol/credentials.d.ts.map +1 -1
  115. package/dist/types/protocol/execution.d.ts +1 -1
  116. package/dist/types/protocol/harness.d.ts +5 -2
  117. package/dist/types/protocol/harness.d.ts.map +1 -1
  118. package/dist/types/protocol/lifecycle.d.ts +8 -8
  119. package/dist/types/protocol/models.d.ts +3 -0
  120. package/dist/types/protocol/models.d.ts.map +1 -1
  121. package/dist/types/protocol/wire-api.d.ts +39 -29
  122. package/dist/types/protocol/wire-api.d.ts.map +1 -1
  123. package/dist/types/protocol/wire.d.ts +13 -10
  124. package/dist/types/protocol/wire.d.ts.map +1 -1
  125. package/dist/types/server/install.d.ts +2 -1
  126. package/dist/types/server/install.d.ts.map +1 -1
  127. package/docs/consuming.md +6 -0
  128. package/docs/deploy.md +17 -8
  129. package/docs/harnesses.md +166 -44
  130. package/package.json +1 -1
  131. package/src/core/agents/acp/account.ts +158 -0
  132. package/src/core/agents/acp/acp-agent.ts +288 -178
  133. package/src/core/agents/acp/adapter.ts +126 -35
  134. package/src/core/agents/acp/client.ts +196 -49
  135. package/src/core/agents/acp/known-agents.ts +14 -5
  136. package/src/core/agents/acp/mappings.ts +112 -21
  137. package/src/core/agents/acp/models.ts +72 -0
  138. package/src/core/agents/acp/profile.ts +127 -0
  139. package/src/core/agents/acp/prompts.ts +287 -0
  140. package/src/core/agents/acp/requests.ts +16 -9
  141. package/src/core/agents/claude-code/login.ts +4 -1
  142. package/src/core/agents/claude-code/session.ts +38 -8
  143. package/src/core/agents/claude-code/spawn.ts +0 -26
  144. package/src/core/agents/codex-app-server/client.ts +11 -18
  145. package/src/core/agents/codex-app-server/login.ts +4 -5
  146. package/src/core/agents/gemini/failures.ts +148 -0
  147. package/src/core/agents/gemini/login.ts +188 -0
  148. package/src/core/agents/gemini/profile.ts +162 -0
  149. package/src/core/agents/gemini/tools.ts +99 -0
  150. package/src/core/agents/login.ts +14 -8
  151. package/src/core/agents/stderr-tail.ts +5 -2
  152. package/src/core/presets.ts +15 -2
  153. package/src/core/processes/native-processes.ts +32 -1
  154. package/src/core/provision/checksums.ts +12 -2
  155. package/src/core/provision/install-build.ts +122 -55
  156. package/src/core/provision/pins.ts +5 -0
  157. package/src/core/provision/provisioner.ts +62 -27
  158. package/src/core/provision/releases.ts +47 -1
  159. package/src/core/provision/tools.ts +124 -31
  160. package/src/operator/errors.ts +5 -2
  161. package/src/operator/operator.ts +181 -77
  162. package/src/operator/render.ts +60 -28
  163. package/src/operator/session-tools.ts +2 -1
  164. package/src/operator/types.ts +1 -0
  165. package/src/protocol/account.ts +5 -2
  166. package/src/protocol/auth.ts +5 -1
  167. package/src/protocol/credentials.ts +11 -2
  168. package/src/protocol/harness.ts +9 -1
  169. package/src/server/bin.ts +20 -6
  170. package/src/server/install.ts +6 -3
@@ -11,6 +11,7 @@ import {
11
11
  type CodexAppServerAgentOptions,
12
12
  } from "./agents/codex-app-server/codex-agent.ts";
13
13
  import type { CredentialSource } from "./agents/credentials.ts";
14
+ import { geminiHarness } from "./agents/gemini/profile.ts";
14
15
  import type { HostTools } from "./agents/host-tools.ts";
15
16
  import type { InheritConfig } from "./agents/inherit-config.ts";
16
17
  import { AgentRegistry } from "./agents/registry.ts";
@@ -37,8 +38,8 @@ type SaidOnce =
37
38
 
38
39
  export interface CreateRegistryOptions {
39
40
  /**
40
- * Which harnesses to register. Defaults to `claude-code` and
41
- * `codex-app-server`, plus `acp` when `acp` config is provided (it has no
41
+ * Which harnesses to register. Defaults to `claude-code`,
42
+ * `codex-app-server` and `gemini`, plus `acp` when `acp` config is provided (it has no
42
43
  * default launch), and `scripted` when `scripted` is (it has no script).
43
44
  */
44
45
  harnesses?: AgentHarness[];
@@ -175,6 +176,18 @@ const HARNESSES: Record<
175
176
  }),
176
177
  createCodexAppServerTransformer,
177
178
  ],
179
+ gemini: (opts, cliPath, processes) => {
180
+ const { idleTimeoutMs, cancelConfirmMs, cancelGraceMs, hostTools, inheritConfig } = opts;
181
+ return geminiHarness({
182
+ ...(inheritConfig && { inheritConfig }),
183
+ resolveCliPath: cliPath("agy"),
184
+ idleTimeoutMs,
185
+ cancelConfirmMs,
186
+ cancelGraceMs,
187
+ hostTools,
188
+ processes,
189
+ });
190
+ },
178
191
  acp: (opts, _cliPath, processes) => {
179
192
  if (!opts.acp) {
180
193
  throw new Error("the acp harness requires CreateRegistryOptions.acp (resolveLaunch)");
@@ -1,7 +1,8 @@
1
1
  import { type ChildProcess, type SpawnOptions, spawn as nodeSpawn } from "node:child_process";
2
2
  import type { AgentHarness, RecoveryReason } from "../../protocol/index.ts";
3
3
  import { StderrTail } from "../agents/stderr-tail.ts";
4
- import { onAbort } from "../utils/deadline.ts";
4
+ import { onAbort, withTimeout } from "../utils/deadline.ts";
5
+ import { AgentExitedError } from "../utils/errors.ts";
5
6
  import { type NativeRecord, bootId, startToken, verifyRecord } from "./identity.ts";
6
7
  import { lifeline } from "./lifeline.ts";
7
8
  import {
@@ -20,6 +21,8 @@ export const DEFAULT_GRACE_MS = 3_000;
20
21
  const STDERR_TAIL_MAX = 2048;
21
22
  /** How long an exit waits for its stdout's and stderr's last words, as the Claude SDK's own spawner waits for stderr. */
22
23
  const OUTPUT_CLOSE_WAIT_MS = 200;
24
+ /** A broken transport may precede the exit that explains it. */
25
+ const EXIT_REASON_WAIT_MS = 1_000;
23
26
  const POLL_MS = 50;
24
27
  /** How long a SIGKILLed tree may take to be gone before it counts as not stopped. */
25
28
  const KILL_WAIT_MS = 1_000;
@@ -136,6 +139,34 @@ export class NativeProcess {
136
139
  return this.tail.text;
137
140
  }
138
141
 
142
+ /** The stderr a failure can show, including when the process printed nothing. */
143
+ get stderrSummary(): string {
144
+ const tail = this.stderrTail.trim().replace(/\s+/g, " ");
145
+ return tail ? `Last stderr: ${tail}` : "It printed nothing on stderr.";
146
+ }
147
+
148
+ /** Once the transport is lost, give the process a moment to exit and drain its output. */
149
+ async exitAfterDisconnect(): Promise<NativeExit | undefined> {
150
+ return (await withTimeout(this.exited, EXIT_REASON_WAIT_MS))?.value;
151
+ }
152
+
153
+ // @ref LLP 0016.000#when-a-process-exits-before-answering — one exit sentence for every harness
154
+ exitError(
155
+ name: string,
156
+ { code, signal }: NativeExit,
157
+ requests: readonly string[],
158
+ ): AgentExitedError {
159
+ const status = signal
160
+ ? `on ${signal}`
161
+ : code !== null
162
+ ? `with code ${code}`
163
+ : "without an exit status";
164
+ const pending = [...new Set(requests)].join(", ");
165
+ return new AgentExitedError(
166
+ `${name} exited unexpectedly ${status}${pending ? ` before answering ${pending}` : ""}. ${this.stderrSummary}`,
167
+ );
168
+ }
169
+
139
170
  /**
140
171
  * Stop it and everything under it: SIGTERM to its group and its tool
141
172
  * sessions, SIGKILL to what is left after the grace. Whether all of it is
@@ -4,10 +4,15 @@ import type { CliTool } from "./tools.ts";
4
4
 
5
5
  /** One platform's build of a pinned version, as `bun run releases:refresh` recorded it. */
6
6
  export interface CliBuild {
7
- /** The npm tarball's subresource integrity (`sha512-…`). */
7
+ /**
8
+ * The download's subresource integrity (`sha512-…`): the npm tarball's, or
9
+ * for a `url` source the sha512 its vendor's manifest named.
10
+ */
8
11
  readonly integrity: string;
9
12
  /** The binary's sha256, where its vendor signs a manifest of it (Claude). */
10
13
  readonly sha256?: string;
14
+ /** Where a `url` source's build is: only this table says. */
15
+ readonly url?: string;
11
16
  }
12
17
 
13
18
  /** A pinned version of one CLI and its builds, by platform as the cache names them. */
@@ -33,7 +38,12 @@ export interface LocalBuild {
33
38
  * comes from (`registry`).
34
39
  */
35
40
  export type ExpectedBuild =
36
- | { readonly source: "release"; readonly integrity: string; readonly sha256?: string }
41
+ | {
42
+ readonly source: "release";
43
+ readonly integrity: string;
44
+ readonly sha256?: string;
45
+ readonly url?: string;
46
+ }
37
47
  | { readonly source: "local"; readonly sha256: string; readonly vouchedBy: string }
38
48
  | { readonly source: "registry" };
39
49
 
@@ -5,16 +5,44 @@ import { CliProvisionError } from "../utils/errors.ts";
5
5
  import { managedDirectory, trustedBinaryIn } from "./cache-trust.ts";
6
6
  import { type ExpectedBuild, sha256Of } from "./checksums.ts";
7
7
  import { type DownloadTimeouts, downloadWithIntegrity, fetchDist, withoutSecrets } from "./npm.ts";
8
- import { type CliToolSpec, type ToolPackage, binaryIn } from "./tools.ts";
8
+ import { type ToolPackage, binaryIn } from "./tools.ts";
9
9
 
10
10
  /** At most this often an install reports its bytes. */
11
11
  const PROGRESS_INTERVAL_MS = 250;
12
12
 
13
- /** One build to install into the cache, and what it must match. */
13
+ /**
14
+ * One build, resolved for its platform before anything is fetched
15
+ * (`CliProvisioner.plan`): an npm package, its tarball found and checked
16
+ * through the registry; or a file at the address the release table names,
17
+ * checked against the table's integrity.
18
+ */
19
+ export type BuildPlan =
20
+ | {
21
+ readonly kind: "npm";
22
+ /** `<package>@<registry version>`, as messages name it. */
23
+ readonly name: string;
24
+ readonly pkg: ToolPackage;
25
+ readonly expected: ExpectedBuild;
26
+ /** The directory of the extracted tarball that becomes the install. */
27
+ payload(extractedRoot: string): Promise<string>;
28
+ }
29
+ | {
30
+ readonly kind: "file";
31
+ /** `<tool>@<version>`, as messages name it. */
32
+ readonly name: string;
33
+ readonly url: string;
34
+ readonly integrity: string;
35
+ /** The executable's name in the install. */
36
+ readonly binary: string;
37
+ /** Its name inside the tarball the file is; absent, the file is the executable. */
38
+ readonly member?: string;
39
+ };
40
+
41
+ /** One build to install into the cache. */
14
42
  interface BuildInstall {
15
- spec: CliToolSpec;
16
- pkg: ToolPackage;
17
- expected: ExpectedBuild;
43
+ plan: BuildPlan;
44
+ /** Where the binary sits in the installed tree (`CliToolSpec.binaries`). */
45
+ binaries: readonly string[];
18
46
  /** The trusted cache root, and the build's folder in it. */
19
47
  root: string;
20
48
  dir: string;
@@ -46,8 +74,68 @@ export async function openToAll(path: string): Promise<void> {
46
74
  } else if (info.isFile()) await chmod(path, info.mode & 0o100 ? 0o755 : 0o644);
47
75
  }
48
76
 
49
- export function noBinary(pkg: ToolPackage): CliProvisionError {
50
- return new CliProvisionError(`downloaded ${pkg.name}@${pkg.registryVersion} has no binary`);
77
+ /** `name` is `<package>@<version>` (`<tool>@<version>` for a file). */
78
+ export function noBinary(name: string): CliProvisionError {
79
+ return new CliProvisionError(`downloaded ${name} has no binary`);
80
+ }
81
+
82
+ /**
83
+ * Where an npm build's tarball is and what it must match, asked before a
84
+ * byte of it is fetched: the registry's metadata, refused when it names
85
+ * another tarball than the table pins.
86
+ */
87
+ async function locateTarball(
88
+ job: BuildInstall,
89
+ { pkg, expected }: Extract<BuildPlan, { kind: "npm" }>,
90
+ ): Promise<{ url: string; integrity: string }> {
91
+ const dist = await fetchDist(
92
+ job.registry,
93
+ pkg.name,
94
+ pkg.registryVersion,
95
+ job.fetch,
96
+ job.timeouts,
97
+ );
98
+ if (expected.source === "release" && dist.integrity !== expected.integrity) {
99
+ throw new CliProvisionError(
100
+ `${withoutSecrets(job.registry)} serves another ${pkg.name}@${pkg.registryVersion} than this release pins ` +
101
+ `(${dist.integrity.slice(0, 24)}…, pinned ${expected.integrity.slice(0, 24)}…)`,
102
+ // A digest's digits are no status code: classified by what it is, not its words.
103
+ { category: "internal" },
104
+ );
105
+ }
106
+ return {
107
+ url: dist.tarball,
108
+ integrity: expected.source === "release" ? expected.integrity : dist.integrity,
109
+ };
110
+ }
111
+
112
+ /** The tarball, extracted into the staging folder. */
113
+ async function extracted(job: BuildInstall, download: string, staging: string): Promise<string> {
114
+ const dir = join(staging, "x");
115
+ await mkdir(dir, { mode: 0o700 });
116
+ await job.extract(download, dir);
117
+ return dir;
118
+ }
119
+
120
+ /**
121
+ * The download, unpacked into the folder that becomes the install: an npm
122
+ * tarball's payload, or a folder holding only the file's executable under
123
+ * its installed name (the tarball's `member`, or the file itself; a member
124
+ * that is not a regular file is no binary).
125
+ */
126
+ async function unpack(job: BuildInstall, download: string, staging: string): Promise<string> {
127
+ const { plan } = job;
128
+ if (plan.kind === "npm") return plan.payload(await extracted(job, download, staging));
129
+ let executable = download;
130
+ if (plan.member) {
131
+ const member = binaryIn(await extracted(job, download, staging), [plan.member]);
132
+ if (!member) throw noBinary(plan.name);
133
+ executable = member;
134
+ }
135
+ const dir = join(staging, "build");
136
+ await mkdir(dir, { mode: 0o700 });
137
+ await rename(executable, join(dir, plan.binary));
138
+ return dir;
51
139
  }
52
140
 
53
141
  /**
@@ -57,60 +145,39 @@ export function noBinary(pkg: ToolPackage): CliProvisionError {
57
145
  * one that loses adopts the winner's tree. Answers the bytes downloaded.
58
146
  */
59
147
  export async function installBuild(job: BuildInstall): Promise<number> {
60
- const { spec, pkg, expected, root, dir } = job;
61
- const staging = join(
62
- root,
63
- ".tmp",
64
- `${pkg.name.replace("/", "-")}-${pkg.registryVersion}-${process.pid}-${randomBytes(4).toString("hex")}`,
65
- );
148
+ const { plan, binaries, root, dir } = job;
149
+ const { name } = plan;
150
+ const stem =
151
+ plan.kind === "npm"
152
+ ? `${plan.pkg.name.replace("/", "-")}-${plan.pkg.registryVersion}`
153
+ : plan.name.replace("@", "-");
154
+ const staging = join(root, ".tmp", `${stem}-${process.pid}-${randomBytes(4).toString("hex")}`);
66
155
  try {
67
156
  managedDirectory(root, dirname(staging), true);
68
157
  await mkdir(staging, { mode: 0o700 });
69
- const dist = await fetchDist(
70
- job.registry,
71
- pkg.name,
72
- pkg.registryVersion,
73
- job.fetch,
74
- job.timeouts,
75
- );
76
- if (expected.source === "release" && dist.integrity !== expected.integrity) {
77
- throw new CliProvisionError(
78
- `${withoutSecrets(job.registry)} serves another ${pkg.name}@${pkg.registryVersion} than this release pins ` +
79
- `(${dist.integrity.slice(0, 24)}…, pinned ${expected.integrity.slice(0, 24)}…)`,
80
- // A digest's digits are no status code: classified by what it is, not its words.
81
- { category: "internal" },
82
- );
83
- }
84
- const tgz = join(staging, "package.tgz");
158
+ const { url, integrity } = plan.kind === "npm" ? await locateTarball(job, plan) : plan;
159
+ const download = join(staging, plan.kind === "npm" ? "package.tgz" : "download");
85
160
  let reportedAt = 0;
86
- const bytes = await downloadWithIntegrity(
87
- dist.tarball,
88
- tgz,
89
- expected.source === "release" ? expected.integrity : dist.integrity,
90
- job.fetch,
91
- {
92
- timeouts: job.timeouts,
93
- onBytes: (receivedBytes, totalBytes) => {
94
- const now = Date.now();
95
- if (now - reportedAt < PROGRESS_INTERVAL_MS && receivedBytes !== totalBytes) return;
96
- reportedAt = now;
97
- job.onProgress("downloading", receivedBytes, totalBytes);
98
- },
161
+ const bytes = await downloadWithIntegrity(url, download, integrity, job.fetch, {
162
+ timeouts: job.timeouts,
163
+ onBytes: (receivedBytes, totalBytes) => {
164
+ const now = Date.now();
165
+ if (now - reportedAt < PROGRESS_INTERVAL_MS && receivedBytes !== totalBytes) return;
166
+ reportedAt = now;
167
+ job.onProgress("downloading", receivedBytes, totalBytes);
99
168
  },
100
- );
169
+ });
101
170
  job.onProgress("verifying", bytes, bytes);
102
- const extracted = join(staging, "x");
103
- await mkdir(extracted, { mode: 0o700 });
104
- await job.extract(tgz, extracted);
105
- const payload = await spec.payload(extracted);
106
- const binary = binaryIn(payload, spec.binaries);
107
- if (!binary) throw noBinary(pkg);
108
- const sha256 = expected.source === "registry" ? undefined : expected.sha256;
109
- if (sha256) {
171
+ const payload = await unpack(job, download, staging);
172
+ const binary = binaryIn(payload, binaries);
173
+ if (!binary) throw noBinary(name);
174
+ const expected = plan.kind === "npm" ? plan.expected : undefined;
175
+ const sha256 = expected?.source === "registry" ? undefined : expected?.sha256;
176
+ if (expected && sha256) {
110
177
  const actual = await sha256Of(binary);
111
178
  if (actual !== sha256) {
112
179
  throw new CliProvisionError(
113
- `${pkg.name}@${pkg.registryVersion}'s binary is not the build ${
180
+ `${name}'s binary is not the build ${
114
181
  expected.source === "local" ? expected.vouchedBy : "this release pins"
115
182
  } names (sha256 ${actual}, expected ${sha256})`,
116
183
  { category: "internal" },
@@ -125,13 +192,13 @@ export async function installBuild(job: BuildInstall): Promise<number> {
125
192
  } catch (error) {
126
193
  // Lost the race with another process installing the same build: the
127
194
  // directory is version-keyed, so its tree is what we would have written.
128
- if (trustedBinaryIn(root, dir, spec.binaries)) return bytes;
195
+ if (trustedBinaryIn(root, dir, binaries)) return bytes;
129
196
  throw new CliProvisionError(
130
- `${dir} is there but holds no ${spec.binaries[0]}: remove it, and it installs again`,
197
+ `${dir} is there but holds no ${binaries[0]}: remove it, and it installs again`,
131
198
  { cause: error },
132
199
  );
133
200
  }
134
- if (!trustedBinaryIn(root, dir, spec.binaries)) throw noBinary(pkg);
201
+ if (!trustedBinaryIn(root, dir, binaries)) throw noBinary(name);
135
202
  return bytes;
136
203
  } finally {
137
204
  await rm(staging, { recursive: true, force: true });
@@ -15,6 +15,10 @@ import type { CliTool } from "./tools.ts";
15
15
  * governs downloads (compiled binaries, bare sandboxes, `pinned` mode); in
16
16
  * `auto` an installed `@openai/codex` package (a lockfile's) runs instead,
17
17
  * and a `codex` on PATH only in `system` mode.
18
+ * - `agy` is the version of Google's Antigravity CLI the gemini harness
19
+ * downloads. Google's update manifest names only its latest build, so a
20
+ * refresh records the version it names: a bump moves to that one, and
21
+ * only forward. The person's own install runs only in `system` mode.
18
22
  *
19
23
  * A bump is `bun run bump -- <tool>`: it writes what changed upstream, moves
20
24
  * the pin, and runs both refreshes, `releases:refresh` (each platform's build
@@ -25,4 +29,5 @@ import type { CliTool } from "./tools.ts";
25
29
  export const DEFAULT_PINS: Record<CliTool, string> = {
26
30
  claude: "0.3.327",
27
31
  codex: "0.169.1",
32
+ agy: "1.5.14",
28
33
  };
@@ -12,14 +12,14 @@ import {
12
12
  import { markUsed, pruneCache } from "./cache-usage.ts";
13
13
  import { type CliReleases, expectedBuild } from "./checksums.ts";
14
14
  import { extractTarGz } from "./extract.ts";
15
- import { installBuild, noBinary } from "./install-build.ts";
15
+ import { type BuildPlan, installBuild, noBinary } from "./install-build.ts";
16
16
  import {
17
17
  DEFAULT_DOWNLOAD_TIMEOUTS,
18
18
  DEFAULT_NPM_REGISTRY,
19
19
  type DownloadTimeouts,
20
20
  withoutSecrets,
21
21
  } from "./npm.ts";
22
- import { type PlatformInfo, detectPlatform } from "./platform.ts";
22
+ import { type PlatformInfo, detectPlatform, platformName } from "./platform.ts";
23
23
  import { CLI_RELEASES } from "./releases.ts";
24
24
  import { CLI_TOOLS, CLI_TOOL_SPECS, type CliTool, type ToolPackage, binaryIn } from "./tools.ts";
25
25
 
@@ -46,7 +46,11 @@ export interface ProvisionOptions {
46
46
  * A desktop app names a folder of its own, so removing it removes them.
47
47
  */
48
48
  cacheDir?: string;
49
- /** npm registry base URL. Defaults to `$AGENT_SERVER_NPM_REGISTRY`, then npmjs. */
49
+ /**
50
+ * npm registry base URL, for the tools published there. Defaults to
51
+ * `$AGENT_SERVER_NPM_REGISTRY`, then npmjs. A `url` source's builds come
52
+ * from where the release table says.
53
+ */
50
54
  registry?: string;
51
55
  /**
52
56
  * Version pins overriding this release's defaults (see `DEFAULT_PINS`). A
@@ -55,8 +59,8 @@ export interface ProvisionOptions {
55
59
  */
56
60
  pins?: Partial<Record<CliTool, string>>;
57
61
  /**
58
- * Explicit CLI paths — the operator escape hatch. Defaults to
59
- * `$CLAUDE_CLI_PATH` / `$CODEX_CLI_PATH`. Never sourced from the wire:
62
+ * Explicit CLI paths — the operator escape hatch. Defaults to each tool's
63
+ * variable (`$CLAUDE_CLI_PATH`, `$CODEX_CLI_PATH`, `$ANTIGRAVITY_CLI_PATH`). Never sourced from the wire:
60
64
  * letting a remote client pick the spawned executable would be RCE.
61
65
  */
62
66
  overrides?: Partial<Record<CliTool, string>>;
@@ -129,9 +133,14 @@ export interface ProvisionerDeps {
129
133
  /** A tool's build for this platform at the version this engine runs, and where the cache keeps it. */
130
134
  interface Build {
131
135
  version: string;
132
- pkg: ToolPackage;
136
+ /** The platform part of its folder's name. */
137
+ suffix: string;
133
138
  /** `<version>-<suffix>`, its folder under `<cache>/<tool>/`. */
134
139
  entry: string;
140
+ /** Its npm package, for a tool published there. */
141
+ pkg: ToolPackage | undefined;
142
+ /** How messages name it: `<package>@<registry version>`, or `<tool>@<version>`. */
143
+ name: string;
135
144
  }
136
145
 
137
146
  const MODES: readonly ProvisionMode[] = ["auto", "pinned", "system"];
@@ -147,10 +156,11 @@ function messageOf(error: unknown): string {
147
156
  }
148
157
 
149
158
  /**
150
- * Resolves the native CLIs the harnesses spawn (`claude`, `codex`) and — in
151
- * managed modes — downloads the pinned builds from the npm registry into a
152
- * local cache, checked against this release's table of them (`releases.ts`)
153
- * and installed atomically (`install-build.ts`), so concurrent processes
159
+ * Resolves the native CLIs the harnesses spawn (`CLI_TOOLS`) and — in
160
+ * managed modes — downloads the pinned builds from where each comes from
161
+ * (the npm registry, or the address the release table names) into a local
162
+ * cache, checked against this release's table of them (`releases.ts`) and
163
+ * installed atomically (`install-build.ts`), so concurrent processes
154
164
  * converge on one copy. What differs per tool is its `CLI_TOOL_SPECS` entry.
155
165
  *
156
166
  * One instance per runtime; `resolve` is memoized per tool (a failure clears
@@ -389,8 +399,40 @@ export class CliProvisioner {
389
399
  if (note) this.say(note);
390
400
  version = spec.defaultVersion();
391
401
  }
392
- const pkg = spec.package(this.platform, version);
393
- return { version, pkg, entry: `${version}-${pkg.suffix}` };
402
+ const pkg =
403
+ spec.source.kind === "npm" ? spec.source.package(this.platform, version) : undefined;
404
+ const suffix = pkg?.suffix ?? platformName(this.platform);
405
+ const name = pkg ? `${pkg.name}@${pkg.registryVersion}` : `${tool}@${version}`;
406
+ return { version, suffix, entry: `${version}-${suffix}`, pkg, name };
407
+ }
408
+
409
+ // @ref LLP 0010#source-kinds — the one place a build's pin is checked: a `url` build the table does not hold is refused
410
+ /**
411
+ * What installing `build` takes, resolved before anything is fetched: an
412
+ * npm build's package and what it must match (said once when that is not
413
+ * this release's table), or the file the table names for a `url` source.
414
+ */
415
+ private plan(tool: CliTool, build: Build): BuildPlan {
416
+ const { source, localBuild } = CLI_TOOL_SPECS[tool];
417
+ const { version, suffix, name } = build;
418
+ const expected = expectedBuild(tool, version, suffix, this.releases, localBuild);
419
+ if (source.kind === "npm") {
420
+ if (expected.source !== "release")
421
+ this.say(
422
+ `${tool} ${version} (${suffix}) is not pinned by this agent-server release: checked against ${
423
+ expected.source === "local" ? expected.vouchedBy : "the registry's checksum only"
424
+ }`,
425
+ );
426
+ const pkg = build.pkg ?? source.package(this.platform, version);
427
+ return { kind: "npm", name, pkg, expected, payload: source.payload };
428
+ }
429
+ if (expected.source !== "release" || !expected.url)
430
+ throw new CliProvisionError(
431
+ `${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`,
432
+ { category: "invalid_request" },
433
+ );
434
+ const { url, integrity } = expected;
435
+ return { kind: "file", name, url, integrity, ...source.executable(this.platform) };
394
436
  }
395
437
 
396
438
  /** Pin trusted aliases to their physical location and recheck on every use. */
@@ -409,7 +451,7 @@ export class CliProvisioner {
409
451
  if (!path) {
410
452
  await this.download(tool, build, root, dir);
411
453
  path = trustedBinaryIn(root, dir, spec.binaries);
412
- if (!path) throw noBinary(build.pkg);
454
+ if (!path) throw noBinary(build.name);
413
455
  }
414
456
  await this.used(tool, build.entry, true);
415
457
  // The cache grew: what no process used for a while goes. Best effort.
@@ -421,7 +463,7 @@ export class CliProvisioner {
421
463
  /** Download and install one build, reporting its progress to the observers and the log. */
422
464
  private async download(tool: CliTool, build: Build, root: string, dir: string): Promise<void> {
423
465
  const spec = CLI_TOOL_SPECS[tool];
424
- const { version, pkg } = build;
466
+ const { version } = build;
425
467
  let progress: CliProgress = { tool, version, phase: "downloading", receivedBytes: 0 };
426
468
  const report = (next: Partial<CliProgress>) => {
427
469
  progress = { ...progress, ...next };
@@ -437,20 +479,13 @@ export class CliProvisioner {
437
479
  const startedAt = Date.now();
438
480
  try {
439
481
  report({});
440
- const expected = expectedBuild(tool, version, pkg.suffix, this.releases, spec.localBuild);
441
- if (expected.source !== "release")
442
- this.say(
443
- `${tool} ${version} (${pkg.suffix}) is not pinned by this agent-server release: checked against ${
444
- expected.source === "local" ? expected.vouchedBy : "the registry's checksum only"
445
- }`,
446
- );
447
- this.log(
448
- `downloading ${tool} ${version} (${pkg.suffix}) from ${withoutSecrets(this.registry)}…`,
449
- );
482
+ const plan = this.plan(tool, build);
483
+ // A file is where the table says; an npm build, the registry's.
484
+ const from = plan.kind === "file" ? new URL(plan.url).origin : withoutSecrets(this.registry);
485
+ this.log(`downloading ${tool} ${version} (${build.suffix}) from ${from}…`);
450
486
  const bytes = await installBuild({
451
- spec,
452
- pkg,
453
- expected,
487
+ plan,
488
+ binaries: spec.binaries,
454
489
  root,
455
490
  dir,
456
491
  registry: this.registry,
@@ -5,7 +5,8 @@ import type { CliReleases } from "./checksums.ts";
5
5
  /**
6
6
  * The pinned CLIs' builds, by platform: each npm tarball's integrity, and for
7
7
  * Claude the binary's sha256 from Anthropic's signed release manifest (its
8
- * signature verified when this file was generated).
8
+ * signature verified when this file was generated); for agy each build's
9
+ * address and the sha512 Google's unsigned update manifest named for it.
9
10
  */
10
11
  export const CLI_RELEASES: CliReleases = {
11
12
  claude: {
@@ -83,4 +84,49 @@ export const CLI_RELEASES: CliReleases = {
83
84
  },
84
85
  },
85
86
  },
87
+ agy: {
88
+ version: "1.5.14",
89
+ builds: {
90
+ "darwin-arm64": {
91
+ integrity:
92
+ "sha512-JoMP1Gv7kgDQc88+cb+UtwdVJVe0OA7AGv1umfOisDDmVCLasYZ/dzGAeGkt78hZp1R9F+xLCx6TafE8nDyupg==",
93
+ url: "https://storage.googleapis.com/antigravity-public/antigravity-cli/1.5.14-5302690847260672/darwin-arm/cli_mac_arm64.tar.gz",
94
+ },
95
+ "darwin-x64": {
96
+ integrity:
97
+ "sha512-G2ofxtvka6bZ0EBdG2CVGJ816/xMPDPOsf0bbQyf1wK1KsELZLi1Ku0NjXGuAsXfPP/V4+PTdUnC2v/M4qhTxw==",
98
+ url: "https://storage.googleapis.com/antigravity-public/antigravity-cli/1.5.14-5302690847260672/darwin-x64/cli_mac_x64.tar.gz",
99
+ },
100
+ "linux-arm64": {
101
+ integrity:
102
+ "sha512-ybKbukdfY6GoAWGuk7pysiHHpYbZhR5NAGFUZwS6tm1rJ2CyXXFtGRck/HVk8yRkVu4VHiiqN69I281yvcbEYw==",
103
+ url: "https://storage.googleapis.com/antigravity-public/antigravity-cli/1.5.14-5302690847260672/linux-arm/cli_linux_arm64.tar.gz",
104
+ },
105
+ "linux-x64": {
106
+ integrity:
107
+ "sha512-gzEdPzVFZ2EtwWwa4uqbUD1vaDOqThONOaoinaPzu5mw5NfMoLzkeWsAYNalHYET63RJ7V3A55AL8hcQfqW/+Q==",
108
+ url: "https://storage.googleapis.com/antigravity-public/antigravity-cli/1.5.14-5302690847260672/linux-x64/cli_linux_x64.tar.gz",
109
+ },
110
+ "linux-arm64-musl": {
111
+ integrity:
112
+ "sha512-9uNfw9qyzUn9Qpbd7ghBucxMcCC2xqrqZFLFs0UrCtjWZFHJCY5Bitay9uq8yBzfExBe0EOQMkixHW+ySucJqw==",
113
+ url: "https://storage.googleapis.com/antigravity-public/antigravity-cli/1.5.14-5302690847260672/linux-arm-musl/cli_linux_arm64_musl.tar.gz",
114
+ },
115
+ "linux-x64-musl": {
116
+ integrity:
117
+ "sha512-HaJJInJ8W06ENp0IQ1ddfW8YChlG4txCiRca0ePKkllOaHck0ZAqfYPkB/mPCo07fD6XbwNoD9gNvtLS2gDA7Q==",
118
+ url: "https://storage.googleapis.com/antigravity-public/antigravity-cli/1.5.14-5302690847260672/linux-x64-musl/cli_linux_x64_musl.tar.gz",
119
+ },
120
+ "win32-arm64": {
121
+ integrity:
122
+ "sha512-ss5UYs8YRbJcBcplG1vZNzX9gH+Oe0DGHQ6ZRF3xp2uX7iTIkNX1ugRT+EjKF0901JKtGQGi3cul16m0OZ3f7w==",
123
+ url: "https://storage.googleapis.com/antigravity-public/antigravity-cli/1.5.14-5302690847260672/windows-arm/cli_windows_arm64.exe",
124
+ },
125
+ "win32-x64": {
126
+ integrity:
127
+ "sha512-eFVIsjJC7JESdZu0tSXZSj1NLpho5c7bnqNOXOAduwCr9d5mxB2PSQPopDeURfaFSD+Zns6Rhnv72dSBJ2DYNQ==",
128
+ url: "https://storage.googleapis.com/antigravity-public/antigravity-cli/1.5.14-5302690847260672/windows-x64/cli_windows_x64.exe",
129
+ },
130
+ },
131
+ },
86
132
  };