@zvada/agent-server 0.3.27 → 0.3.30

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 (190) hide show
  1. package/CHANGELOG.md +61 -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 +249 -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/claude-agent.js +2 -12
  14. package/dist/core/agents/claude-code/login.js +4 -1
  15. package/dist/core/agents/claude-code/session.js +50 -18
  16. package/dist/core/agents/claude-code/spawn.js +0 -26
  17. package/dist/core/agents/claude-code/turn.js +6 -2
  18. package/dist/core/agents/codex-app-server/client.js +12 -13
  19. package/dist/core/agents/codex-app-server/login.js +4 -1
  20. package/dist/core/agents/gemini/failures.js +133 -0
  21. package/dist/core/agents/gemini/login.js +173 -0
  22. package/dist/core/agents/gemini/profile.js +138 -0
  23. package/dist/core/agents/gemini/tools.js +91 -0
  24. package/dist/core/agents/login.js +8 -6
  25. package/dist/core/agents/stderr-tail.js +5 -2
  26. package/dist/core/presets.js +13 -0
  27. package/dist/core/processes/native-processes.js +23 -1
  28. package/dist/core/provision/install-build.js +70 -26
  29. package/dist/core/provision/pins.js +5 -0
  30. package/dist/core/provision/provisioner.js +39 -16
  31. package/dist/core/provision/releases.js +39 -1
  32. package/dist/core/provision/tools.js +87 -28
  33. package/dist/operator/errors.js +2 -2
  34. package/dist/operator/operator.js +201 -90
  35. package/dist/operator/render.js +34 -28
  36. package/dist/operator/session-tools.js +2 -1
  37. package/dist/protocol/account.js +5 -1
  38. package/dist/protocol/auth.js +5 -1
  39. package/dist/protocol/config.js +4 -2
  40. package/dist/protocol/credentials.js +9 -1
  41. package/dist/protocol/harness.js +9 -1
  42. package/dist/protocol/part-input.js +2 -6
  43. package/dist/protocol/text-parts.js +10 -0
  44. package/dist/server/bin.js +22 -7
  45. package/dist/server/install.js +6 -4
  46. package/dist/types/core/agents/acp/account.d.ts +55 -0
  47. package/dist/types/core/agents/acp/account.d.ts.map +1 -0
  48. package/dist/types/core/agents/acp/acp-agent.d.ts +65 -36
  49. package/dist/types/core/agents/acp/acp-agent.d.ts.map +1 -1
  50. package/dist/types/core/agents/acp/adapter.d.ts +28 -3
  51. package/dist/types/core/agents/acp/adapter.d.ts.map +1 -1
  52. package/dist/types/core/agents/acp/client.d.ts +66 -4
  53. package/dist/types/core/agents/acp/client.d.ts.map +1 -1
  54. package/dist/types/core/agents/acp/known-agents.d.ts +4 -2
  55. package/dist/types/core/agents/acp/known-agents.d.ts.map +1 -1
  56. package/dist/types/core/agents/acp/mappings.d.ts +53 -7
  57. package/dist/types/core/agents/acp/mappings.d.ts.map +1 -1
  58. package/dist/types/core/agents/acp/models.d.ts +22 -0
  59. package/dist/types/core/agents/acp/models.d.ts.map +1 -0
  60. package/dist/types/core/agents/acp/profile.d.ts +97 -0
  61. package/dist/types/core/agents/acp/profile.d.ts.map +1 -0
  62. package/dist/types/core/agents/acp/prompts.d.ts +108 -0
  63. package/dist/types/core/agents/acp/prompts.d.ts.map +1 -0
  64. package/dist/types/core/agents/acp/requests.d.ts +7 -1
  65. package/dist/types/core/agents/acp/requests.d.ts.map +1 -1
  66. package/dist/types/core/agents/claude-code/claude-agent.d.ts +1 -2
  67. package/dist/types/core/agents/claude-code/claude-agent.d.ts.map +1 -1
  68. package/dist/types/core/agents/claude-code/login.d.ts.map +1 -1
  69. package/dist/types/core/agents/claude-code/options.d.ts +1 -1
  70. package/dist/types/core/agents/claude-code/options.d.ts.map +1 -1
  71. package/dist/types/core/agents/claude-code/session.d.ts +7 -6
  72. package/dist/types/core/agents/claude-code/session.d.ts.map +1 -1
  73. package/dist/types/core/agents/claude-code/spawn.d.ts +0 -8
  74. package/dist/types/core/agents/claude-code/spawn.d.ts.map +1 -1
  75. package/dist/types/core/agents/claude-code/turn.d.ts +3 -2
  76. package/dist/types/core/agents/claude-code/turn.d.ts.map +1 -1
  77. package/dist/types/core/agents/codex-app-server/client.d.ts.map +1 -1
  78. package/dist/types/core/agents/codex-app-server/login.d.ts.map +1 -1
  79. package/dist/types/core/agents/gemini/failures.d.ts +25 -0
  80. package/dist/types/core/agents/gemini/failures.d.ts.map +1 -0
  81. package/dist/types/core/agents/gemini/login.d.ts +28 -0
  82. package/dist/types/core/agents/gemini/login.d.ts.map +1 -0
  83. package/dist/types/core/agents/gemini/profile.d.ts +30 -0
  84. package/dist/types/core/agents/gemini/profile.d.ts.map +1 -0
  85. package/dist/types/core/agents/gemini/tools.d.ts +18 -0
  86. package/dist/types/core/agents/gemini/tools.d.ts.map +1 -0
  87. package/dist/types/core/agents/login.d.ts +15 -5
  88. package/dist/types/core/agents/login.d.ts.map +1 -1
  89. package/dist/types/core/agents/stderr-tail.d.ts +1 -1
  90. package/dist/types/core/agents/stderr-tail.d.ts.map +1 -1
  91. package/dist/types/core/presets.d.ts +2 -2
  92. package/dist/types/core/presets.d.ts.map +1 -1
  93. package/dist/types/core/processes/native-processes.d.ts +6 -0
  94. package/dist/types/core/processes/native-processes.d.ts.map +1 -1
  95. package/dist/types/core/provision/checksums.d.ts +7 -1
  96. package/dist/types/core/provision/checksums.d.ts.map +1 -1
  97. package/dist/types/core/provision/install-build.d.ts +32 -6
  98. package/dist/types/core/provision/install-build.d.ts.map +1 -1
  99. package/dist/types/core/provision/pins.d.ts +4 -0
  100. package/dist/types/core/provision/pins.d.ts.map +1 -1
  101. package/dist/types/core/provision/provisioner.d.ts +18 -7
  102. package/dist/types/core/provision/provisioner.d.ts.map +1 -1
  103. package/dist/types/core/provision/releases.d.ts +2 -1
  104. package/dist/types/core/provision/releases.d.ts.map +1 -1
  105. package/dist/types/core/provision/tools.d.ts +36 -7
  106. package/dist/types/core/provision/tools.d.ts.map +1 -1
  107. package/dist/types/operator/errors.d.ts +5 -1
  108. package/dist/types/operator/errors.d.ts.map +1 -1
  109. package/dist/types/operator/operator.d.ts.map +1 -1
  110. package/dist/types/operator/render.d.ts +11 -6
  111. package/dist/types/operator/render.d.ts.map +1 -1
  112. package/dist/types/operator/session-tools.d.ts.map +1 -1
  113. package/dist/types/operator/types.d.ts +5 -4
  114. package/dist/types/operator/types.d.ts.map +1 -1
  115. package/dist/types/protocol/account.d.ts +4 -2
  116. package/dist/types/protocol/account.d.ts.map +1 -1
  117. package/dist/types/protocol/auth.d.ts +10 -7
  118. package/dist/types/protocol/auth.d.ts.map +1 -1
  119. package/dist/types/protocol/clis.d.ts +4 -3
  120. package/dist/types/protocol/clis.d.ts.map +1 -1
  121. package/dist/types/protocol/config.d.ts +6 -2
  122. package/dist/types/protocol/config.d.ts.map +1 -1
  123. package/dist/types/protocol/conversation.d.ts +3 -3
  124. package/dist/types/protocol/credentials.d.ts +8 -0
  125. package/dist/types/protocol/credentials.d.ts.map +1 -1
  126. package/dist/types/protocol/execution.d.ts +1 -1
  127. package/dist/types/protocol/harness.d.ts +5 -2
  128. package/dist/types/protocol/harness.d.ts.map +1 -1
  129. package/dist/types/protocol/lifecycle.d.ts +8 -8
  130. package/dist/types/protocol/models.d.ts +3 -0
  131. package/dist/types/protocol/models.d.ts.map +1 -1
  132. package/dist/types/protocol/part-input.d.ts.map +1 -1
  133. package/dist/types/protocol/text-parts.d.ts +10 -0
  134. package/dist/types/protocol/text-parts.d.ts.map +1 -0
  135. package/dist/types/protocol/wire-api.d.ts +39 -29
  136. package/dist/types/protocol/wire-api.d.ts.map +1 -1
  137. package/dist/types/protocol/wire.d.ts +13 -10
  138. package/dist/types/protocol/wire.d.ts.map +1 -1
  139. package/dist/types/server/install.d.ts +2 -1
  140. package/dist/types/server/install.d.ts.map +1 -1
  141. package/docs/consuming.md +8 -1
  142. package/docs/deploy.md +17 -8
  143. package/docs/harnesses.md +173 -44
  144. package/package.json +1 -1
  145. package/src/core/agents/acp/account.ts +158 -0
  146. package/src/core/agents/acp/acp-agent.ts +290 -178
  147. package/src/core/agents/acp/adapter.ts +126 -35
  148. package/src/core/agents/acp/client.ts +196 -49
  149. package/src/core/agents/acp/known-agents.ts +14 -5
  150. package/src/core/agents/acp/mappings.ts +112 -21
  151. package/src/core/agents/acp/models.ts +72 -0
  152. package/src/core/agents/acp/profile.ts +133 -0
  153. package/src/core/agents/acp/prompts.ts +287 -0
  154. package/src/core/agents/acp/requests.ts +16 -9
  155. package/src/core/agents/claude-code/claude-agent.ts +2 -13
  156. package/src/core/agents/claude-code/login.ts +4 -1
  157. package/src/core/agents/claude-code/options.ts +1 -1
  158. package/src/core/agents/claude-code/session.ts +50 -16
  159. package/src/core/agents/claude-code/spawn.ts +0 -26
  160. package/src/core/agents/claude-code/turn.ts +7 -2
  161. package/src/core/agents/codex-app-server/client.ts +11 -18
  162. package/src/core/agents/codex-app-server/login.ts +4 -5
  163. package/src/core/agents/gemini/failures.ts +148 -0
  164. package/src/core/agents/gemini/login.ts +188 -0
  165. package/src/core/agents/gemini/profile.ts +163 -0
  166. package/src/core/agents/gemini/tools.ts +99 -0
  167. package/src/core/agents/login.ts +14 -8
  168. package/src/core/agents/stderr-tail.ts +5 -2
  169. package/src/core/presets.ts +15 -2
  170. package/src/core/processes/native-processes.ts +32 -1
  171. package/src/core/provision/checksums.ts +12 -2
  172. package/src/core/provision/install-build.ts +122 -55
  173. package/src/core/provision/pins.ts +5 -0
  174. package/src/core/provision/provisioner.ts +62 -27
  175. package/src/core/provision/releases.ts +47 -1
  176. package/src/core/provision/tools.ts +124 -31
  177. package/src/operator/errors.ts +5 -2
  178. package/src/operator/operator.ts +208 -91
  179. package/src/operator/render.ts +61 -33
  180. package/src/operator/session-tools.ts +2 -1
  181. package/src/operator/types.ts +5 -4
  182. package/src/protocol/account.ts +5 -2
  183. package/src/protocol/auth.ts +5 -1
  184. package/src/protocol/config.ts +4 -2
  185. package/src/protocol/credentials.ts +11 -2
  186. package/src/protocol/harness.ts +9 -1
  187. package/src/protocol/part-input.ts +2 -5
  188. package/src/protocol/text-parts.ts +10 -0
  189. package/src/server/bin.ts +20 -6
  190. package/src/server/install.ts +6 -3
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` with `--dangerously-skip-permissions` 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,28 @@ 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` modes were measured through the engine on Antigravity 1.5.13
423
+ on 2026-11-21. On that build, `auto` alone still asked for an MCP call and
424
+ the engine allowed it. The full-access row below was measured with the
425
+ start flag on 1.5.14 on 2026-11-24 (LLP 0020.000, Modes). Gemini is
426
+ not in the `permission-modes` scenario's tables. The `full-access` scenario
427
+ checks its worktree commit, network access and write outside the worktree.
428
+
429
+ | Engine mode | Antigravity's | A write in the folder | A command | An MCP tool |
430
+ | --- | --- | --- | --- | --- |
431
+ | `default` | `default` | asks | asks | asks |
432
+ | `accept_edits` | `accept-edits` | runs | asks | asks |
433
+ | `plan` | `plan` | writes a plan file and stops, asking nothing | not run | not run |
434
+ | `bypass_permissions` | `auto` with `--dangerously-skip-permissions` | runs | runs outside the terminal sandbox | runs unasked |
435
+ | `dont_ask` | `default` | refused by the engine | refused by the engine | refused by the engine |
436
+
437
+ A later turn in another mode carries a plan out. Switching into or out of
438
+ `bypass_permissions` resumes the conversation in a new agy process, ending
439
+ commands left in the background. With `enableTerminalSandbox` unset, an
440
+ approved command ran outside the terminal sandbox in `default` and
441
+ `accept_edits`. In `default`, enabling the setting sandboxed the approved
442
+ command.
443
+
412
444
  ## Model lists
413
445
 
414
446
  `runtime.models({ harness, cwd })` (wire `models/list`, `client.listModels()`)
@@ -419,6 +451,7 @@ a turn with the same `cwd`, `env` and `apiKey` would use:
419
451
  | --- | --- | --- |
420
452
  | `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
453
  | `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. |
454
+ | `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
455
  | `acp` | none | The catalog (empty). ACP agents describe models as session config options. |
423
456
  | `scripted` | the harness | One model, `scripted`, with no thinking levels. |
424
457
 
@@ -468,11 +501,13 @@ recipe is in
468
501
  | --- | --- | --- | --- |
469
502
  | `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
503
  | `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` |
504
+ | `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
505
  | `acp` | — (`unknown`: the agent signs in on its own) | none | — |
472
506
  | `scripted` | — (`signed_in`: it runs on nothing, so there is nothing to sign in to) | none | refused (`invalid_request`) |
473
507
 
474
508
  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
509
+ `CODEX_HOME`); Antigravity's is one system keyring entry per user, whatever
510
+ the `env`. Claude reports the credential a turn would run with, so a key in
476
511
  the environment shows as `source: "environment"` over any login. A login change
477
512
  starts each session's next turn on a new CLI. A Codex session on its home's own
478
513
  login also follows a change made outside the engine (`codex login` in a
@@ -558,14 +593,24 @@ What a product draws a terminal step, a fetch, a diff or a permission card
558
593
  from, without reading a harness's own input keys (LLP 0002, A tool call says
559
594
  what it acts on). A field a harness does not give is left out.
560
595
 
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 |
596
+ | Field | claude-code | codex-app-server | gemini | acp |
597
+ | --- | --- | --- | --- | --- |
598
+ | `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 |
599
+ | `url` | a `WebFetch` call's `input.url` | none: its network approval was not observed | none | none |
600
+ | `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 |
601
+ | `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 |
602
+ | `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 |
603
+ | `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 |
604
+
605
+ The `gemini` harness also names an MCP call's server and tool (`mcp`): for a
606
+ server the engine passed, from Antigravity's `mcp_<server>_<tool>` against
607
+ the session's own server names (a space spelled `_`), the longest first,
608
+ and none when none fits; for one from a configuration file, the person's or
609
+ the project's, from `call_mcp_tool`'s `ServerName` and `ToolName`. A
610
+ command's `output` is what it printed, without Antigravity's lines about it,
611
+ and its exit code `metadata.exitCode`; a non-zero one fails it, though
612
+ Antigravity says `completed`. A write, a read and an MCP call to a server
613
+ the engine passed send no text, and their `output` is empty.
569
614
 
570
615
  Every tool the pinned Claude CLI offers has a decided `kind`. A Claude pin
571
616
  bump runs `bun run test:live:free`: its `claude-tool-kinds` check starts the
@@ -587,7 +632,7 @@ context and added lines; a `` marker is dropped.
587
632
  the raw provider string travels in `finishReason`.
588
633
  - `cost` is reported only by Claude; `reasoning` tokens by every harness whose
589
634
  backend counts them (Claude's thinking, Codex's reasoning, an ACP agent's
590
- thought tokens).
635
+ thought tokens). An ACP turn steered by prompt sums every prompt's answer.
591
636
  - Tool names are provider-native for Claude (`Bash`, `Read`) and normalized
592
637
  for Codex (`shell`, `apply_patch`, …) — but the tool `kind`
593
638
  (`read`/`edit`/`execute`/…) is normalized for all.
@@ -635,6 +680,89 @@ turn totals take precedence over intermediate message usage.
635
680
  cache accounting. An ACP/custom agent that exposes only this gauge cannot
636
681
  provide the cache breakdown without an additional native usage report.
637
682
 
683
+ ## The gemini harness
684
+
685
+ Gemini models through Google's Antigravity CLI (`agy acp`), on the person's
686
+ own Antigravity sign-in (LLP 0020). It is the ACP harness with a profile of
687
+ Antigravity's (`core/agents/gemini/`), and is in the default set.
688
+ It runs on the person's own sign-in only. A Gemini API key the product holds
689
+ was measured to work and is not built (LLP 0020, decision 13); a
690
+ `GEMINI_API_KEY` or `GOOGLE_API_KEY` in the engine's environment changes
691
+ nothing, and the sign-in stays in charge.
692
+
693
+ - **Its CLI:** `agy`, installed and pinned by the engine as Claude's and
694
+ Codex's are ([deploy.md](deploy.md#cli-provisioning-deterministic-agents)):
695
+ `$ANTIGRAVITY_CLI_PATH` (operator-level), then a bundle folder, then the
696
+ cache, then a download of the pin (1.5.14), checked against the sha512
697
+ Google's unsigned update manifest named for it when this release was made
698
+ (LLP 0010, Source kinds). The person's own (`~/.local/bin/agy`;
699
+ `%LOCALAPPDATA%\agy\bin\agy.exe` on Windows; then PATH) runs only in
700
+ `system` mode. Every start sets `AGY_CLI_DISABLE_AUTO_UPDATE=true` over
701
+ any environment a turn brings, and the terminal sign-in carries it, so the
702
+ pinned build is the one that runs; one older than 1.5.13 is refused.
703
+ - **Redistribution:** downloading agy onto the user's machine at run time
704
+ is what Google's own installer and the AUR and Chocolatey packages do.
705
+ Bundling it in an app or an image (`install --dir`) is copying and
706
+ distributing, which Google's terms do not grant: that is the operator's to
707
+ clear.
708
+ - **`inheritConfig`:** `all` only; a turn at `project` or `none` fails as
709
+ `invalid_request` before agy starts, while the login's status and the
710
+ model list answer at every level. Antigravity always loads the folder's
711
+ own rules, skills, MCP servers and hooks (`AGENTS.md`, `GEMINI.md`,
712
+ `.agents/`), so `none` cannot be; `project` needs an Antigravity home of
713
+ the session's own (`--gemini-dir`), not taken yet (LLP 0020, decision 11).
714
+ - **Skills, MCP servers and hooks:** the person's and the folder's load. A
715
+ skill runs by `/name` or when the request calls for one, and shows on the
716
+ stream as a `read` of its `SKILL.md`; a folder's MCP server starts at the
717
+ first prompt. Started in the session's folder, as the engine starts it,
718
+ Antigravity runs each of the folder's hooks twice (LLP 0020.000, Skills,
719
+ MCP servers and hooks in a session).
720
+ - **Models:** the account's Gemini models, read live ([Model lists](#model-lists));
721
+ a turn naming another model Antigravity offers (Claude, GPT-OSS, an
722
+ orchestrator) fails as `invalid_request`, and a turn naming none runs a
723
+ Gemini model even when the account's own default is another: the one the
724
+ list marks default.
725
+ - **Files:** images and text files; a PDF or another binary file fails the
726
+ turn before any process starts, since Antigravity drops them unread.
727
+ - **Steering:** a steer is a second `session/prompt`, sent in order, each
728
+ once the one before it was taken, and while the agent asks nothing (until
729
+ it reports on the tool call it asked about). One the agent refused because
730
+ a request of its own crossed it on the wire goes again in its place; one
731
+ refused otherwise is undelivered. Its echo sits before the first model
732
+ 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
733
+ prompt's stop reason and every answer's usage (LLP 0016.000, An ACP agent
734
+ steered by prompt).
735
+ - **A failed model call:** Antigravity tells it as the turn's last text and
736
+ answers as if it succeeded; the engine ends that turn `error` instead
737
+ (LLP 0020, decision 12), with Google's own sentence and its status as the
738
+ message. A wrong key is `auth` ("API key not valid. Please pass a valid
739
+ API key.", with 400 or 401 by the key's shape), a used-up quota `rate_limit` (429), an
740
+ overloaded model `overloaded` (503), a broken connection `network`, an
741
+ executor error in other words by those words.
742
+ Antigravity retries a 429, a 503 and a network failure eight times over
743
+ 2.5 to 4.6 minutes, saying nothing meanwhile: a turn can be silent for
744
+ minutes, then fail. A stalled connection has no timeout: only a cancel
745
+ ends it.
746
+ - **Known limits:** after one denial in a batch, Antigravity fails every
747
+ call still pending without asking, with empty output, and ends the turn
748
+ with no text. A command that could not run (its folder gone) fails with
749
+ Antigravity's own line saying why. An agy that dies on its own leaves its
750
+ shell command running until it ends by itself. A one-line edit of a large
751
+ file carries the whole file on both sides of the diff, and an image goes
752
+ back out on the stream in the user message. A session folder that is not
753
+ a directory fails the turn as `process_exit`, naming the binary.
754
+ - **Background commands:** a command Antigravity sends to the background is
755
+ still running when its turn ends; the stream closes its part at
756
+ `turn.ended`, and its process ends with the session's agy, whose process
757
+ group the engine owns.
758
+ - **Questions:** the model's question comes as a form elicitation whose
759
+ `message` is only "The agent has a question.": show the form's field
760
+ titles, which hold the question and its options, not `message` alone.
761
+ - **The system prompt:** given once, with the conversation's start; a later
762
+ turn asking another is told it was not applied.
763
+ - **Not offered:** a credential the product holds, `maxTurns`,
764
+ `disableTools`, a plan's approval, cost.
765
+
638
766
  ## The scripted harness
639
767
 
640
768
  `scripted` plays a script instead of a model, so a product can test its whole
@@ -753,11 +881,12 @@ once. Unstable methods (`session/list`, `session/fork`, `session/delete`,
753
881
  | --- | --- | --- | --- |
754
882
  | `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
883
  | `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 |
884
+ | `logout` | the gemini harness's sign-out, where `initialize` has `auth.logout` | not offered | `gemini/login` |
885
+ | `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
886
  | `session/resume` | when advertised | from memory, else the session record | loopback (a new engine), `acp-session-config` |
758
887
  | `session/load` | when no resume (the replay is dropped) | not offered | `acp-session-config` |
759
888
  | `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` |
889
+ | `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
890
  | `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
891
  | `session/set_config_option` | `model` and `thought_level` | none offered: the operator's `--model`, `--thinking` | `acp-session-config`, `bin.test` |
763
892
  | `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.30",
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
+ }