@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
package/docs/deploy.md CHANGED
@@ -2,10 +2,12 @@
2
2
 
3
3
  ## CLI provisioning (deterministic agents)
4
4
 
5
- The native harnesses spawn real CLIs (`claude` ~220 MB, `codex` ~320 MB
6
- unpacked). Instead of trusting whatever version a host happens to have, the
7
- engine downloads **the builds this release pins** from the npm registry into
8
- a local cache and installs them atomically, shared across processes. Nothing
5
+ The harnesses spawn real CLIs (`claude` ~220 MB, `codex` ~320 MB, and the
6
+ gemini harness's `agy` ~230 MB unpacked). Instead of trusting whatever version
7
+ a host happens to have, the engine downloads **the builds this release pins**
8
+ (Claude's and Codex's from the npm registry, agy's from the addresses Google's
9
+ update manifest named) into a local cache and installs them atomically,
10
+ shared across processes. Nothing
9
11
  needs to be installed on the machine first: no Node, npm or package manager,
10
12
  only the system `tar` (macOS, Linux, Windows 10 and later have one). Three
11
13
  modes (`--provision`, `$AGENT_SERVER_PROVISION`, or
@@ -25,8 +27,10 @@ codex (so your lockfile can pin it). A `codex` on `PATH` counts only in
25
27
  `system` mode: anywhere else it is no build anyone chose for this engine, and
26
28
  may be another app's private copy (Conductor puts its own on `PATH`), of
27
29
  another version whose app-server may not run the turn (an older one fails
28
- on the default model).
29
- Overrides are operator-level only — `$CLAUDE_CLI_PATH` / `$CODEX_CLI_PATH` (or
30
+ on the default model). agy's host install (where Google's installer puts it,
31
+ `~/.local/bin/agy` or `%LOCALAPPDATA%\agy\bin\agy.exe`, then `PATH`) counts
32
+ only in `system` mode too: it updates itself.
33
+ Overrides are operator-level only — `$CLAUDE_CLI_PATH` / `$CODEX_CLI_PATH` / `$ANTIGRAVITY_CLI_PATH` (or
30
34
  `provision.overrides`), never wire config: a remote client must not choose the
31
35
  executable a server spawns. Auth stays host-side either way: managed CLIs read
32
36
  the same `~/.claude` / `~/.codex` (or per-turn `config.apiKey` BYOK) as your
@@ -45,7 +49,10 @@ installed. (npm itself never changes a published version's bytes; the table
45
49
  is what holds a mirror to them.) A version the table does not pin (an
46
50
  operator's `provision.pins`) is checked against the installed Claude SDK's
47
51
  manifest when it names that version, else against the registry's checksum
48
- only, and the log says so once.
52
+ only, and the log says so once. agy's entries are each build's address and
53
+ the sha512 Google's update manifest named for it, which Google does not sign;
54
+ an agy version the table does not hold is refused, since nothing else can say
55
+ where it is or vouch for it.
49
56
 
50
57
  **A product that bundles the Claude SDK** (an ESM or single-file build of its
51
58
  own) sets `provision.pins.claude` to the SDK's version: nothing on disk says
@@ -213,7 +220,9 @@ send the same token: `AgentServerClient.connect(url, { token })`, or the CLI's
213
220
  `clis/list` before its first turn; a sandbox without baked CLIs is prepared
214
221
  remotely with `clis/prepare`, its progress streaming back.
215
222
 
216
- `agent-server install` respects `--harness a,b` (only fetch what you run) and
223
+ `agent-server install` with no `--harness` fetches every managed CLI, agy
224
+ (the gemini harness's, about 90 MB to download) among them; `--harness a,b`
225
+ fetches only what you run. It respects
217
226
  `$AGENT_SERVER_CACHE_DIR` (e.g. point it at a persistent volume instead of
218
227
  baking). It says what each version is: Claude's is the Claude SDK package's
219
228
  (`claude: Claude SDK package 0.3.288 (Claude Code 2.1.288) for linux-x64
package/docs/harnesses.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Harness support matrix
2
2
 
3
- Four harnesses, one event stream. The lifecycle event *structure* is identical
3
+ Five harnesses, one event stream. The lifecycle event *structure* is identical
4
4
  across harnesses (one generic `EventProcessor` drives it); payloads and config
5
5
  support differ only where the backends genuinely do.
6
6
 
@@ -8,14 +8,16 @@ support differ only where the backends genuinely do.
8
8
  | --- | --- | --- | --- | --- |
9
9
  | `claude-code` | `@anthropic-ai/claude-agent-sdk` (claude CLI) | token-level | yes (`resume`) | `in_session` (`setModel`) |
10
10
  | `codex-app-server` | `codex app-server` (JSON-RPC subprocess) | token-level | yes (`thread/resume`) | `in_session` (per-turn) |
11
+ | `gemini` | Google's Antigravity CLI, `agy acp`, an ACP agent ([below](#the-gemini-harness)) | chunk-level | yes (`session/resume`) | `in_session` (its `model` option) |
11
12
  | `acp` | any ACP v1 agent via `@agentclientprotocol/sdk` | per-agent | yes (`session/resume`, else `session/load`) | when the agent offers a `model` config option (so the capability says `unsupported`) |
12
13
  | `scripted` | a script the operator gives, no process ([below](#the-scripted-harness)) | a word at a time (`stream` steps) | any id (nothing to lose) | `unsupported`: it runs no model |
13
14
 
14
15
  The `acp` harness is opt-in (an operator-supplied launch command, never
15
16
  wire-sourced): well-known agents run by name (`--harness=pi`,
16
- `--harness=gemini`); anything else via `--acp-agent="<launch command>"` /
17
+ `--harness=gemini-cli`, Google's Gemini CLI, the enterprise one without
18
+ Gemini 4); anything else via `--acp-agent="<launch command>"` /
17
19
  `$AGENT_SERVER_ACP_AGENT`, or `CreateRegistryOptions.acp.resolveLaunch` when
18
- embedding.
20
+ embedding. `--harness=gemini` is the `gemini` harness.
19
21
 
20
22
  What the `acp` harness asks of an agent, and what it does when the agent
21
23
  offers it (checked against SDK 1.7.0 with `claude-agent-acp` and `codex-acp`):
@@ -24,14 +26,20 @@ offers it (checked against SDK 1.7.0 with `claude-agent-acp` and `codex-acp`):
24
26
  (the replayed history is discarded). An agent with neither fails the turn
25
27
  as `resume_failed`.
26
28
  - **Model and thinking level:** selected through the agent's `model` and
27
- `thought_level` config options (`session/set_config_option`). An agent
28
- without the option keeps its default. A model the agent does not list fails
29
- the turn as `invalid_request`; an unlisted thinking level is left alone.
29
+ `thought_level` config options (`session/set_config_option`), the model
30
+ first. An agent without the option keeps its default. A model the agent
31
+ does not list fails the turn as `invalid_request`. The levels are those
32
+ offered once the model is set, and the turn runs the nearest of them
33
+ (`clampThinkingLevel`); one that cannot be fitted is left alone.
34
+ `turn.ended.execution` reports the model and level the options then state.
30
35
  - **Permission mode:** an agent that offers modes is put in the turn's
31
36
  (`default` when it names none) with `session/set_mode`, by the agent's own
32
- id (`acceptEdits`, `bypassPermissions` and the like are read as the
33
- engine's); one it offers none of is reported not applied. The engine also
34
- answers the agent's permission requests by the mode.
37
+ id, whatever its case and separators (`acceptEdits`, `accept-edits`,
38
+ `bypassPermissions`). One with no id for the mode is put in its `default`,
39
+ and the engine answers what it asks by the turn's mode; `plan` there, or
40
+ any mode on an agent with no `default` either, is reported not applied.
41
+ In `accept_edits` the engine allows edits and reads and asks the person
42
+ for anything else, as Claude and Codex ask for a command.
35
43
  - **Extra directories:** `additionalDirectories` is sent to agents that
36
44
  advertise the capability and ignored otherwise.
37
45
  - **Token usage:** read from the prompt response when the agent sends it. The
@@ -81,8 +89,9 @@ rather than reaching the agent unread, and a steer carrying one is refused the
81
89
  same way. A Codex turn with `disableTools` fails so too, before Codex starts:
82
90
  with every feature that offers a tool turned off, Codex 0.160 still gives a
83
91
  model its code-mode `exec`, `apply_patch` inside it, its sub-agent tools and
84
- `request_user_input`, so the model would act anyway. ACP agents cannot be steered: ACP v1 has no input for a running
85
- prompt, so `turn/steer` answers `unsupported`. An ACP agent takes image data with its
92
+ `request_user_input`, so the model would act anyway. An ACP agent cannot be steered: ACP v1 has no input for a running
93
+ prompt, so `turn/steer` answers `unsupported`; the `gemini` harness steers,
94
+ since Antigravity takes a prompt sent while one runs as input to it. An ACP agent takes image data with its
86
95
  `image` prompt capability and files as embedded resources with
87
96
  `embeddedContext`; otherwise text files go inline and links as resource links.
88
97
  The harness states the most an agent can take (`images`, `files: text, pdf,
@@ -198,7 +207,8 @@ advertise is declined; for a client that advertises neither, the turn runs
198
207
  without `elicitation`, so the agent is told no one can answer.
199
208
 
200
209
  What a Claude or Codex session loads by itself is the operator's
201
- `inheritConfig` (LLP 0001, D17; choosing one: [consuming.md](consuming.md#choose-what-a-turn-inherits)).
210
+ `inheritConfig` (LLP 0001, D17; choosing one: [consuming.md](consuming.md#choose-what-a-turn-inherits)). A gemini
211
+ session runs at `all` only ([below](#the-gemini-harness)).
202
212
  At `all`, the default, a Claude session loads every settings source (user,
203
213
  project and local), as the CLI does: the operator's own MCP servers, hooks and
204
214
  plugins join the turn beside the servers its config names, and so does the
@@ -300,26 +310,26 @@ turn fails. **The agent's**: an ACP agent decides, by what it advertises.
300
310
  ends "(not applied: …)" is a case a harness finds as the turn runs, named in
301
311
  `turn.ended.execution.notApplied`.
302
312
 
303
- | Setting | claude-code | codex-app-server | acp | scripted |
304
- | --- | --- | --- | --- | --- |
305
- | `harness` | the engine | the engine | the engine | the engine |
306
- | `model` | applied, switched live | applied (`turn/start`) | the agent's: set through its `model` config option; an agent without one keeps its own (not applied: `model`); a value it does not list is refused | ignored: `echo: "config"` says it |
307
- | `thinkingLevel` | applied, fitted to the model's levels (a model with none: not applied: `thinkingLevel`) | applied as reasoning effort, fitted to the model; `off` is its lowest effort (a model with no reasoning control: not applied: `thinkingLevel`) | the agent's: set through its `thought_level` option when it lists the level (otherwise not applied: `thinkingLevel`) | ignored: `echo: "config"` says it |
308
- | `cwd` | applied | applied | applied | another meaning: a change needs a resume (as on every harness), and `echo: "config"` says it |
309
- | `additionalDirectories` | applied | another meaning: writable roots of the `accept_edits` sandbox, nothing in the other modes | the agent's: sent only to an agent that takes them (otherwise not applied: `additionalDirectories`) | ignored: `echo: "config"` says them |
310
- | `systemPromptAppend` | applied, appended to Claude Code's system prompt | another meaning: a developer message (`developerInstructions`) | ignored: ACP v1 has no system prompt | ignored: `echo: "config"` says it |
311
- | `maxTurns` | applied (unset is 100) | ignored | ignored | ignored |
312
- | `subagentMode` | applied | another meaning: Codex's `multi_agent` on, an instruction to collect every sub-agent, a native cleanup at the end | refused | refused |
313
- | `permissionMode` | applied (SDK modes) | another meaning: a sandbox and an approval policy (the table below) | applied where the agent offers a mode of that meaning (`session/set_mode`, by its own id; `default` when the turn names none), and the engine answers its requests by the mode; one it offers none of is not applied (`permissionMode`), nor `plan` on an agent with no modes | ignored: the script says which calls ask (`ask: true`); `echo: "config"` says it |
314
- | `elicitation` | applied | applied | applied: the agent's form and URL requests (ACP v1 has no question tool) | applied: an `ask` step asks the person, else the agent is told no one can answer |
315
- | `requestTimeoutMs` | the engine | the engine | the engine | the engine |
316
- | `resumeSessionId` | applied | applied (`thread/resume`) | the agent's: `session/resume`, else `session/load`; refused for an agent with neither | applied: reported as the native id, resumed |
317
- | `resumeSessionAt` | applied with a resume (without one: not applied: `resumeSessionAt`) | ignored | ignored | ignored |
318
- | `mcpServers` | applied, switched live | applied; SSE and the name `codex_apps` refused | the agent's: every server is sent, whatever it advertises; `required` is not checked | applied: a `call` step calls an `http` one |
319
- | `env` | applied | applied; `CODEX_HOME` is the session's home (below `all`, required) | applied | another meaning: a change needs a resume, and `echo: "config"` says its keys |
320
- | `apiKey` | applied (`ANTHROPIC_API_KEY`) | applied (an in-memory login) | ignored: the agent's credentials are its launch command's | ignored: it runs on no credential |
321
- | `disableTools` | applied (no tools, no MCP servers) | refused (`invalid_request`) | ignored: ACP v1 cannot ask for it | ignored: its tool calls are the script's |
322
- | `includeRaw` | the engine | the engine | the engine | the engine |
313
+ | Setting | claude-code | codex-app-server | gemini | acp | scripted |
314
+ | --- | --- | --- | --- | --- | --- |
315
+ | `harness` | the engine | the engine | the engine | the engine | the engine |
316
+ | `model` | applied, switched live | applied (`turn/start`) | applied (its `model` option, switched live); Antigravity's Claude, GPT-OSS and orchestrator models are refused | the agent's: set through its `model` config option; an agent without one keeps its own (not applied: `model`); a value it does not list is refused | ignored: `echo: "config"` says it |
317
+ | `thinkingLevel` | applied, fitted to the model's levels (a model with none: not applied: `thinkingLevel`) | applied as reasoning effort, fitted to the model; `off` is its lowest effort (a model with no reasoning control: not applied: `thinkingLevel`) | applied, fitted to the model's own levels (a level no ordering fits: not applied: `thinkingLevel`) | the agent's: set through its `thought_level` option, fitted to the levels the model offers (a level no ordering fits, or no option: not applied: `thinkingLevel`) | ignored: `echo: "config"` says it |
318
+ | `cwd` | applied | applied | applied | applied | another meaning: a change needs a resume (as on every harness), and `echo: "config"` says it |
319
+ | `additionalDirectories` | applied | another meaning: writable roots of the `accept_edits` sandbox, nothing in the other modes | applied | the agent's: sent only to an agent that takes them (otherwise not applied: `additionalDirectories`) | ignored: `echo: "config"` says them |
320
+ | `systemPromptAppend` | applied, appended to Claude Code's system prompt | another meaning: a developer message (`developerInstructions`) | applied once, at `session/new` (`_meta.antigravity.systemPrompt.append`); a later different one: not applied: `systemPromptAppend` | ignored: ACP v1 has no system prompt | ignored: `echo: "config"` says it |
321
+ | `maxTurns` | applied (unset is 100) | ignored | ignored | ignored | ignored |
322
+ | `subagentMode` | applied | another meaning: Codex's `multi_agent` on, an instruction to collect every sub-agent, a native cleanup at the end | refused | refused | refused |
323
+ | `permissionMode` | applied (SDK modes) | another meaning: a sandbox and an approval policy (the table below) | another meaning: Antigravity's modes, `auto` for `bypass_permissions`, its `default` for `dont_ask` (the table below) | applied: the agent's own mode for it (`session/set_mode`; `default` when the turn names none), else its `default` with the engine answering its requests by the mode; `plan` there, or any mode on an agent with no `default`, is not applied (`permissionMode`) | ignored: the script says which calls ask (`ask: true`); `echo: "config"` says it |
324
+ | `elicitation` | applied | applied | applied: the agent's form and URL requests | applied: the agent's form and URL requests (ACP v1 has no question tool) | applied: an `ask` step asks the person, else the agent is told no one can answer |
325
+ | `requestTimeoutMs` | the engine | the engine | the engine | the engine | the engine |
326
+ | `resumeSessionId` | applied | applied (`thread/resume`) | applied (`session/resume`) | the agent's: `session/resume`, else `session/load`; refused for an agent with neither | applied: reported as the native id, resumed |
327
+ | `resumeSessionAt` | applied with a resume (without one: not applied: `resumeSessionAt`) | ignored | ignored | ignored | ignored |
328
+ | `mcpServers` | applied, switched live | applied; SSE and the name `codex_apps` refused | applied: stdio and HTTP, though `initialize` does not advertise HTTP | the agent's: every server is sent, whatever it advertises; `required` is not checked | applied: a `call` step calls an `http` one |
329
+ | `env` | applied | applied; `CODEX_HOME` is the session's home (below `all`, required) | applied | applied | another meaning: a change needs a resume, and `echo: "config"` says its keys |
330
+ | `apiKey` | applied (`ANTHROPIC_API_KEY`) | applied (an in-memory login) | ignored: it runs on the person's own Antigravity sign-in | ignored: the agent's credentials are its launch command's | ignored: it runs on no credential |
331
+ | `disableTools` | applied (no tools, no MCP servers) | refused (`invalid_request`) | ignored: ACP v1 cannot ask for it | ignored: ACP v1 cannot ask for it | ignored: its tool calls are the script's |
332
+ | `includeRaw` | the engine | the engine | the engine | the engine | the engine |
323
333
 
324
334
  `test/core/agents/ignored-settings.test.ts` holds this table's verdicts; a
325
335
  new `RunConfig` field fails it until each harness's verdict is written there.
@@ -409,6 +419,21 @@ other:
409
419
  `default`, `gpt-6-luna` did not retry: no request came, and no tool part
410
420
  reached the stream.
411
421
 
422
+ The `gemini` harness puts Antigravity in its own mode for each (measured on
423
+ Antigravity 1.5.13 on 2026-11-21, live through the engine; LLP 0020.000,
424
+ Modes). It is not in the `permission-modes` scenario's tables.
425
+
426
+ | Engine mode | Antigravity's | A write in the folder | A command | An MCP tool |
427
+ | --- | --- | --- | --- | --- |
428
+ | `default` | `default` | asks | asks | asks |
429
+ | `accept_edits` | `accept-edits` | runs | asks | asks |
430
+ | `plan` | `plan` | writes a plan file and stops, asking nothing | not run | not run |
431
+ | `bypass_permissions` | `auto` | runs | runs | asked; the engine allows it |
432
+ | `dont_ask` | `default` | refused by the engine | refused by the engine | refused by the engine |
433
+
434
+ A later turn in another mode carries a plan out; there is no approval
435
+ request for it.
436
+
412
437
  ## Model lists
413
438
 
414
439
  `runtime.models({ harness, cwd })` (wire `models/list`, `client.listModels()`)
@@ -419,6 +444,7 @@ a turn with the same `cwd`, `env` and `apiKey` would use:
419
444
  | --- | --- | --- |
420
445
  | `claude-code` | `query().supportedModels()` on an idle CLI (no prompt, MCP servers or hooks), at the operator's `inheritConfig` | The folder's `availableModels` setting narrows the list. `default` is a model id: the account's default. Haiku 4.5 lists no levels; `haiku` runs Haiku 5.5, which does. Operator `sdkOptions` are not applied. |
421
446
  | `codex-app-server` | `model/list`, on the session's own process when `sessionId` has one | Lists what the login can run (a ChatGPT login gets no `gpt-5.5`). The default is the model `~/.codex/config.toml` selects, else Codex's own. With host-managed auth, pass the `sessionId` whose account to list. |
447
+ | `gemini` | a session with no turn, in a new private folder: the `model` option's Gemini models, each set in turn to read its `thought_level` values | About 1 s, and free. Antigravity's Claude, GPT-OSS and orchestrator models are left out. `thinking.default` only on the default model: the others' current level is the one carried over. The catalog has no rows: a failed read answers an empty list with its `error`. |
422
448
  | `acp` | none | The catalog (empty). ACP agents describe models as session config options. |
423
449
  | `scripted` | the harness | One model, `scripted`, with no thinking levels. |
424
450
 
@@ -468,11 +494,13 @@ recipe is in
468
494
  | --- | --- | --- | --- |
469
495
  | `claude-code` | `claude auth status --json`, with the turn's environment | `claudeai`, `console` (`browser`, with a `codeUrl` for another device; over the SDK's control requests, CLI 2.1.220 and later), `terminal` (`claude auth login`) | `claude auth logout` |
470
496
  | `codex-app-server` | `account/read` on an app-server of its own | `chatgpt` (`browser`, callback on `127.0.0.1:1455`, one per machine), `chatgpt_device_code`, `api_key`, `terminal` (`codex login`) | `account/logout` |
497
+ | `gemini` | a session with no turn opened in a new private folder: `signed_in`, a subscription from the CLI's login on the plan Antigravity's tier names (`Google AI Pro`) where the session names one, and claiming nothing more where it names none (a key; a wrong key reads `signed_in` too, its first turn failing as `auth`), or `signed_out` for `Authentication required`; shared as every harness's status read | `google` (`browser`: `agy acp --login`, a `codeUrl`, then the code the page shows), `terminal` (`agy acp --login`) | ACP `logout`, which removes the OS keyring entry |
471
498
  | `acp` | — (`unknown`: the agent signs in on its own) | none | — |
472
499
  | `scripted` | — (`signed_in`: it runs on nothing, so there is nothing to sign in to) | none | refused (`invalid_request`) |
473
500
 
474
501
  A login lands in the store a turn with the same `env` uses (`CLAUDE_CONFIG_DIR`,
475
- `CODEX_HOME`). Claude reports the credential a turn would run with, so a key in
502
+ `CODEX_HOME`); Antigravity's is one system keyring entry per user, whatever
503
+ the `env`. Claude reports the credential a turn would run with, so a key in
476
504
  the environment shows as `source: "environment"` over any login. A login change
477
505
  starts each session's next turn on a new CLI. A Codex session on its home's own
478
506
  login also follows a change made outside the engine (`codex login` in a
@@ -558,14 +586,24 @@ What a product draws a terminal step, a fetch, a diff or a permission card
558
586
  from, without reading a harness's own input keys (LLP 0002, A tool call says
559
587
  what it acts on). A field a harness does not give is left out.
560
588
 
561
- | Field | claude-code | codex-app-server | acp |
562
- | --- | --- | --- | --- |
563
- | `command` (part and request) | a `Bash` call's `input.command` | the line apart from the shell Codex wraps it in (`/bin/zsh -lc '…'`), unquoted; any other shape as Codex reports it. `input.command` stays wrapped | none: an agent's `title` is all ACP v1 gives |
564
- | `url` | a `WebFetch` call's `input.url` | none: its network approval was not observed | none |
565
- | `locations` | a file tool's path; once an `Edit` or a `Write` over a file is done, each hunk at its start line in the new file | a file change's hunks, each at its start line in the new file; a move's source and destination; an add's or a delete's path | the agent's own |
566
- | `reason` (request) | the CLI's `decisionReason`, when it sends one ("Path is outside allowed working directories") | the approval's `reason`, the model's own justification. `title` is never it | none: ACP v1's request has no field for it |
567
- | `diff` content | from the CLI's structured result: an `Edit`'s or an overwriting `Write`'s hunks; a created file's content as `newText`; a `NotebookEdit`'s cell, `old_source` to `new_source`. None on a failed edit | a hunk per entry for an update (at a move's destination, without its `Moved to:` trailer); an add's content as `newText`; a delete's as `oldText`, `newText` `""`. None on a failed or declined change | the agent's `diff` and `terminal` content, as it sent them, the latest update's winning |
568
- | `metadata.exitCode` | on a failed `Bash` call only, from the `Exit code N` its result begins with: the CLI reports no code for a success, and counts some non-zero exits as one | Codex's `exitCode`, on a completed and a failed command alike | none |
589
+ | Field | claude-code | codex-app-server | gemini | acp |
590
+ | --- | --- | --- | --- | --- |
591
+ | `command` (part and request) | a `Bash` call's `input.command` | the line apart from the shell Codex wraps it in (`/bin/zsh -lc '…'`), unquoted; any other shape as Codex reports it. `input.command` stays wrapped | a `run_command` call's `CommandLine` | none: an agent's `title` is all ACP v1 gives |
592
+ | `url` | a `WebFetch` call's `input.url` | none: its network approval was not observed | none | none |
593
+ | `locations` | a file tool's path; once an `Edit` or a `Write` over a file is done, each hunk at its start line in the new file | a file change's hunks, each at its start line in the new file; a move's source and destination; an add's or a delete's path | the agent's own (macOS paths may come as `/private/tmp/…`) | the agent's own |
594
+ | `reason` (request) | the CLI's `decisionReason`, when it sends one ("Path is outside allowed working directories") | the approval's `reason`, the model's own justification. `title` is never it | none: ACP v1's request has no field for it | none: ACP v1's request has no field for it |
595
+ | `diff` content | from the CLI's structured result: an `Edit`'s or an overwriting `Write`'s hunks; a created file's content as `newText`; a `NotebookEdit`'s cell, `old_source` to `new_source`. None on a failed edit | a hunk per entry for an update (at a move's destination, without its `Moved to:` trailer); an add's content as `newText`; a delete's as `oldText`, `newText` `""`. None on a failed or declined change | the agent's own: a write's new text | the agent's `diff` and `terminal` content, as it sent them, the latest update's winning |
596
+ | `metadata.exitCode` | on a failed `Bash` call only, from the `Exit code N` its result begins with: the CLI reports no code for a success, and counts some non-zero exits as one | Codex's `exitCode`, on a completed and a failed command alike | a `run_command` call's `exit_code`; non-zero fails it | none |
597
+
598
+ The `gemini` harness also names an MCP call's server and tool (`mcp`): for a
599
+ server the engine passed, from Antigravity's `mcp_<server>_<tool>` against
600
+ the session's own server names (a space spelled `_`), the longest first,
601
+ and none when none fits; for one from a configuration file, the person's or
602
+ the project's, from `call_mcp_tool`'s `ServerName` and `ToolName`. A
603
+ command's `output` is what it printed, without Antigravity's lines about it,
604
+ and its exit code `metadata.exitCode`; a non-zero one fails it, though
605
+ Antigravity says `completed`. A write, a read and an MCP call to a server
606
+ the engine passed send no text, and their `output` is empty.
569
607
 
570
608
  Every tool the pinned Claude CLI offers has a decided `kind`. A Claude pin
571
609
  bump runs `bun run test:live:free`: its `claude-tool-kinds` check starts the
@@ -587,7 +625,7 @@ context and added lines; a `` marker is dropped.
587
625
  the raw provider string travels in `finishReason`.
588
626
  - `cost` is reported only by Claude; `reasoning` tokens by every harness whose
589
627
  backend counts them (Claude's thinking, Codex's reasoning, an ACP agent's
590
- thought tokens).
628
+ thought tokens). An ACP turn steered by prompt sums every prompt's answer.
591
629
  - Tool names are provider-native for Claude (`Bash`, `Read`) and normalized
592
630
  for Codex (`shell`, `apply_patch`, …) — but the tool `kind`
593
631
  (`read`/`edit`/`execute`/…) is normalized for all.
@@ -635,6 +673,89 @@ turn totals take precedence over intermediate message usage.
635
673
  cache accounting. An ACP/custom agent that exposes only this gauge cannot
636
674
  provide the cache breakdown without an additional native usage report.
637
675
 
676
+ ## The gemini harness
677
+
678
+ Gemini models through Google's Antigravity CLI (`agy acp`), on the person's
679
+ own Antigravity sign-in (LLP 0020). It is the ACP harness with a profile of
680
+ Antigravity's (`core/agents/gemini/`), and is in the default set.
681
+ It runs on the person's own sign-in only. A Gemini API key the product holds
682
+ was measured to work and is not built (LLP 0020, decision 13); a
683
+ `GEMINI_API_KEY` or `GOOGLE_API_KEY` in the engine's environment changes
684
+ nothing, and the sign-in stays in charge.
685
+
686
+ - **Its CLI:** `agy`, installed and pinned by the engine as Claude's and
687
+ Codex's are ([deploy.md](deploy.md#cli-provisioning-deterministic-agents)):
688
+ `$ANTIGRAVITY_CLI_PATH` (operator-level), then a bundle folder, then the
689
+ cache, then a download of the pin (1.5.14), checked against the sha512
690
+ Google's unsigned update manifest named for it when this release was made
691
+ (LLP 0010, Source kinds). The person's own (`~/.local/bin/agy`;
692
+ `%LOCALAPPDATA%\agy\bin\agy.exe` on Windows; then PATH) runs only in
693
+ `system` mode. Every start sets `AGY_CLI_DISABLE_AUTO_UPDATE=true` over
694
+ any environment a turn brings, and the terminal sign-in carries it, so the
695
+ pinned build is the one that runs; one older than 1.5.13 is refused.
696
+ - **Redistribution:** downloading agy onto the user's machine at run time
697
+ is what Google's own installer and the AUR and Chocolatey packages do.
698
+ Bundling it in an app or an image (`install --dir`) is copying and
699
+ distributing, which Google's terms do not grant: that is the operator's to
700
+ clear.
701
+ - **`inheritConfig`:** `all` only; a turn at `project` or `none` fails as
702
+ `invalid_request` before agy starts, while the login's status and the
703
+ model list answer at every level. Antigravity always loads the folder's
704
+ own rules, skills, MCP servers and hooks (`AGENTS.md`, `GEMINI.md`,
705
+ `.agents/`), so `none` cannot be; `project` needs an Antigravity home of
706
+ the session's own (`--gemini-dir`), not taken yet (LLP 0020, decision 11).
707
+ - **Skills, MCP servers and hooks:** the person's and the folder's load. A
708
+ skill runs by `/name` or when the request calls for one, and shows on the
709
+ stream as a `read` of its `SKILL.md`; a folder's MCP server starts at the
710
+ first prompt. Started in the session's folder, as the engine starts it,
711
+ Antigravity runs each of the folder's hooks twice (LLP 0020.000, Skills,
712
+ MCP servers and hooks in a session).
713
+ - **Models:** the account's Gemini models, read live ([Model lists](#model-lists));
714
+ a turn naming another model Antigravity offers (Claude, GPT-OSS, an
715
+ orchestrator) fails as `invalid_request`, and a turn naming none runs a
716
+ Gemini model even when the account's own default is another: the one the
717
+ list marks default.
718
+ - **Files:** images and text files; a PDF or another binary file fails the
719
+ turn before any process starts, since Antigravity drops them unread.
720
+ - **Steering:** a steer is a second `session/prompt`, sent in order, each
721
+ once the one before it was taken, and while the agent asks nothing (until
722
+ it reports on the tool call it asked about). One the agent refused because
723
+ a request of its own crossed it on the wire goes again in its place; one
724
+ refused otherwise is undelivered. Its echo sits before the first model
725
+ call that read it: the call running when it was taken finishes first. The turn ends when no prompt is in flight, with the newest
726
+ prompt's stop reason and every answer's usage (LLP 0016.000, An ACP agent
727
+ steered by prompt).
728
+ - **A failed model call:** Antigravity tells it as the turn's last text and
729
+ answers as if it succeeded; the engine ends that turn `error` instead
730
+ (LLP 0020, decision 12), with Google's own sentence and its status as the
731
+ message. A wrong key is `auth` ("API key not valid. Please pass a valid
732
+ API key.", with 400 or 401 by the key's shape), a used-up quota `rate_limit` (429), an
733
+ overloaded model `overloaded` (503), a broken connection `network`, an
734
+ executor error in other words by those words.
735
+ Antigravity retries a 429, a 503 and a network failure eight times over
736
+ 2.5 to 4.6 minutes, saying nothing meanwhile: a turn can be silent for
737
+ minutes, then fail. A stalled connection has no timeout: only a cancel
738
+ ends it.
739
+ - **Known limits:** after one denial in a batch, Antigravity fails every
740
+ call still pending without asking, with empty output, and ends the turn
741
+ with no text. A command that could not run (its folder gone) fails with
742
+ Antigravity's own line saying why. An agy that dies on its own leaves its
743
+ shell command running until it ends by itself. A one-line edit of a large
744
+ file carries the whole file on both sides of the diff, and an image goes
745
+ back out on the stream in the user message. A session folder that is not
746
+ a directory fails the turn as `process_exit`, naming the binary.
747
+ - **Background commands:** a command Antigravity sends to the background is
748
+ still running when its turn ends; the stream closes its part at
749
+ `turn.ended`, and its process ends with the session's agy, whose process
750
+ group the engine owns.
751
+ - **Questions:** the model's question comes as a form elicitation whose
752
+ `message` is only "The agent has a question.": show the form's field
753
+ titles, which hold the question and its options, not `message` alone.
754
+ - **The system prompt:** given once, with the conversation's start; a later
755
+ turn asking another is told it was not applied.
756
+ - **Not offered:** a credential the product holds, `maxTurns`,
757
+ `disableTools`, a plan's approval, cost.
758
+
638
759
  ## The scripted harness
639
760
 
640
761
  `scripted` plays a script instead of a model, so a product can test its whole
@@ -753,11 +874,12 @@ once. Unstable methods (`session/list`, `session/fork`, `session/delete`,
753
874
  | --- | --- | --- | --- |
754
875
  | `initialize` | protocol 1; `clientInfo` (`agent-server`, the stock program's release); advertises form and URL elicitation, no `fs`, no `terminal` | answers protocol 1; images; MCP transports per harness; `resume` and `close`; no `loadSession`; no auth methods | loopback, `acp-session-config`, `bin.test` |
755
876
  | `authenticate`, `authMethods` | never called: an agent signs in on its own, and a turn fails with its words | none offered | — |
756
- | `session/new` | the turn's folder, MCP servers, extra directories when advertised | a session, its modes | loopback |
877
+ | `logout` | the gemini harness's sign-out, where `initialize` has `auth.logout` | not offered | `gemini/login` |
878
+ | `session/new` | the turn's folder, MCP servers, extra directories when advertised; a profile's `_meta` (gemini's system prompt) | a session, its modes | loopback |
757
879
  | `session/resume` | when advertised | from memory, else the session record | loopback (a new engine), `acp-session-config` |
758
880
  | `session/load` | when no resume (the replay is dropped) | not offered | `acp-session-config` |
759
881
  | `session/close` | not sent: the agent's process is ended | ends the session's turn and process | `acp-close-during-turn`, loopback (process table) |
760
- | `session/prompt`, `session/cancel` | yes; a cancel confirmed when the prompt ends within 2 s | yes | loopback, `acp-cancel` |
882
+ | `session/prompt`, `session/cancel` | yes; a cancel confirmed when the prompts end within 2 s; a second prompt during a turn is a steer where the profile says so (gemini) | yes | loopback, `acp-cancel`, `acp-steering` |
761
883
  | `session/set_mode` | the turn's permission mode, by the agent's own id | `default`, `accept_edits`, `plan` and the operator's own | loopback, `acp-session-config`, `acp-binding-modes` |
762
884
  | `session/set_config_option` | `model` and `thought_level` | none offered: the operator's `--model`, `--thinking` | `acp-session-config`, `bin.test` |
763
885
  | `session/request_permission` | to the engine's broker (an option id back; edited input denies) | from the broker: `name`, `kind`, `locations`, `rawInput`; no `content` | loopback |
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zvada/agent-server",
3
- "version": "0.3.27",
3
+ "version": "0.3.28",
4
4
  "description": "Harness-agnostic agent execution engine: run Claude Code, Codex (app-server), and any ACP agent behind one interface with a normalized event stream, multi-turn sessions, and resume. Root export is the wire contract; /core, /server, /client are the seats.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -0,0 +1,158 @@
1
+ import { mkdtempSync, rmSync } from "node:fs";
2
+ import { tmpdir } from "node:os";
3
+ import { join } from "node:path";
4
+ import type { InitializeResponse, NewSessionResponse } from "@agentclientprotocol/sdk";
5
+ import type { NativeProcesses } from "../../processes/native-processes.ts";
6
+ import { onAbort, untilAborted } from "../../utils/deadline.ts";
7
+ import type { LoginOptions } from "../login.ts";
8
+ import { AcpClient, type AcpClientOptions, type AcpLaunch } from "./client.ts";
9
+ import type { AcpProfile } from "./profile.ts";
10
+
11
+ /** ACP protocol major version this harness speaks. */
12
+ const PROTOCOL_VERSION = 1;
13
+
14
+ /** Deadline for `initialize` on a freshly spawned agent (mirrors codex startup). */
15
+ const INITIALIZE_TIMEOUT_MS = 15_000;
16
+
17
+ /** Deadline for session lifecycle requests (`session/new`, `session/resume`). */
18
+ export const SESSION_REQUEST_TIMEOUT_MS = 30_000;
19
+
20
+ /** How an agent of a profile starts, for a turn or with none, and how the client introduces itself. */
21
+ export interface AcpStart {
22
+ profile: AcpProfile;
23
+ processes: NativeProcesses;
24
+ clientName?: string;
25
+ clientVersion?: string;
26
+ createClient?: (options: AcpClientOptions) => Promise<AcpClient>;
27
+ }
28
+
29
+ /** The profile's launch, refused when it has none; a cancel ends the wait. */
30
+ export async function launchOf(profile: AcpProfile, signal?: AbortSignal): Promise<AcpLaunch> {
31
+ signal?.throwIfAborted();
32
+ const launch = await untilAborted(Promise.resolve(profile.launch()), signal);
33
+ signal?.throwIfAborted();
34
+ if (!launch) {
35
+ throw new Error(`${profile.harness} harness is not configured: it has no agent launch command`);
36
+ }
37
+ return launch;
38
+ }
39
+
40
+ /** Start an agent of the profile's harness on the engine's processes. */
41
+ export function startClient(
42
+ start: AcpStart,
43
+ options: Pick<AcpClientOptions, "launch" | "cwd" | "env" | "sessionId" | "watchRequests">,
44
+ ): Promise<AcpClient> {
45
+ const clientOptions: AcpClientOptions = {
46
+ ...options,
47
+ clientName: start.clientName,
48
+ processes: start.processes,
49
+ harness: start.profile.harness,
50
+ };
51
+ return start.createClient ? start.createClient(clientOptions) : AcpClient.create(clientOptions);
52
+ }
53
+
54
+ /** `initialize` the agent, and refuse one its profile cannot drive. */
55
+ export async function initialize(client: AcpClient, start: AcpStart): Promise<InitializeResponse> {
56
+ const init = await client.request(
57
+ "initialize",
58
+ {
59
+ protocolVersion: PROTOCOL_VERSION,
60
+ // The engine brokers the agent's requests for input, form or URL;
61
+ // a turn whose client cannot answer declines them.
62
+ clientCapabilities: { elicitation: { form: {}, url: {} } },
63
+ clientInfo: {
64
+ name: start.clientName ?? "agent-server",
65
+ version: start.clientVersion ?? "0.0.0",
66
+ },
67
+ },
68
+ INITIALIZE_TIMEOUT_MS,
69
+ );
70
+ start.profile.accept?.(init);
71
+ return init;
72
+ }
73
+
74
+ /**
75
+ * A folder of no project for an agent to start in, since an agent loads the
76
+ * rules, skills and hooks of the folder it runs in (Antigravity takes it as
77
+ * its workspace): a new one each time (`mkdtemp`, 0700), which nobody else
78
+ * can plant a project in, removed once `gone` settles (its process exited).
79
+ */
80
+ export function privateFolder(): {
81
+ path: string;
82
+ removeAfter(gone?: Promise<unknown>): Promise<void>;
83
+ } {
84
+ const path = mkdtempSync(join(tmpdir(), "agent-server-acp-"));
85
+ return {
86
+ path,
87
+ removeAfter: async (gone) => {
88
+ await gone;
89
+ rmSync(path, { recursive: true, force: true });
90
+ },
91
+ };
92
+ }
93
+
94
+ /** What a new session says of its account: the agent's `initialize`, and the session. */
95
+ export interface AcpAccountRead {
96
+ init: InitializeResponse;
97
+ session: NewSessionResponse;
98
+ }
99
+
100
+ /**
101
+ * The account an agent runs on, read through a session with no turn: the
102
+ * agent starts in a folder of no project, opens a session, is used, and ends.
103
+ * Its model list and its login read it this way.
104
+ */
105
+ export class AcpAccount {
106
+ constructor(private readonly start: AcpStart) {}
107
+
108
+ get processes(): NativeProcesses {
109
+ return this.start.processes;
110
+ }
111
+
112
+ launch(signal?: AbortSignal): Promise<AcpLaunch> {
113
+ return launchOf(this.start.profile, signal);
114
+ }
115
+
116
+ /**
117
+ * Start the agent in a folder of its own (`privateFolder`), `initialize`
118
+ * it, run `use`, and end it; `signal` ends it sooner.
119
+ */
120
+ async connect<T>(
121
+ options: LoginOptions,
122
+ use: (client: AcpClient, init: InitializeResponse, cwd: string) => Promise<T>,
123
+ ): Promise<T> {
124
+ const launch = await this.launch(options.signal);
125
+ const folder = privateFolder();
126
+ const cwd = folder.path;
127
+ let client: AcpClient | undefined;
128
+ const offAbort = onAbort(options.signal, () => client?.close());
129
+ try {
130
+ client = await startClient(this.start, {
131
+ launch,
132
+ cwd,
133
+ ...(options.env && { env: options.env }),
134
+ });
135
+ options.signal?.throwIfAborted();
136
+ return await use(client, await initialize(client, this.start), cwd);
137
+ } finally {
138
+ offAbort();
139
+ client?.close();
140
+ await folder.removeAfter(client?.gone());
141
+ }
142
+ }
143
+
144
+ /** As `connect`, with a session opened in its folder for `use`, and never prompted. */
145
+ open<T>(
146
+ options: LoginOptions,
147
+ use: (client: AcpClient, read: AcpAccountRead) => Promise<T>,
148
+ ): Promise<T> {
149
+ return this.connect(options, async (client, init, cwd) => {
150
+ const session = await client.request(
151
+ "session/new",
152
+ { cwd, mcpServers: [] },
153
+ SESSION_REQUEST_TIMEOUT_MS,
154
+ );
155
+ return use(client, { init, session });
156
+ });
157
+ }
158
+ }