@zvada/agent-server 0.3.26 → 0.3.28

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (262) hide show
  1. package/CHANGELOG.md +71 -0
  2. package/README.md +7 -5
  3. package/dist/client/client.js +27 -11
  4. package/dist/client/connection.js +35 -3
  5. package/dist/core/agents/acp/account.js +111 -0
  6. package/dist/core/agents/acp/acp-agent.js +247 -158
  7. package/dist/core/agents/acp/adapter.js +103 -34
  8. package/dist/core/agents/acp/client.js +169 -42
  9. package/dist/core/agents/acp/known-agents.js +12 -5
  10. package/dist/core/agents/acp/mappings.js +84 -20
  11. package/dist/core/agents/acp/models.js +59 -0
  12. package/dist/core/agents/acp/profile.js +36 -0
  13. package/dist/core/agents/acp/prompts.js +248 -0
  14. package/dist/core/agents/acp/requests.js +4 -4
  15. package/dist/core/agents/claude-code/approvals.js +1 -1
  16. package/dist/core/agents/claude-code/login.js +4 -1
  17. package/dist/core/agents/claude-code/session.js +38 -10
  18. package/dist/core/agents/claude-code/spawn.js +0 -26
  19. package/dist/core/agents/codex-app-server/client.js +12 -13
  20. package/dist/core/agents/codex-app-server/login.js +4 -1
  21. package/dist/core/agents/codex-app-server/plan-approval.js +1 -1
  22. package/dist/core/agents/gemini/failures.js +133 -0
  23. package/dist/core/agents/gemini/login.js +173 -0
  24. package/dist/core/agents/gemini/profile.js +137 -0
  25. package/dist/core/agents/gemini/tools.js +91 -0
  26. package/dist/core/agents/login.js +8 -6
  27. package/dist/core/agents/scripted/scripted-agent.js +30 -3
  28. package/dist/core/agents/stderr-tail.js +5 -2
  29. package/dist/core/presets.js +17 -1
  30. package/dist/core/processes/native-processes.js +23 -1
  31. package/dist/core/provision/install-build.js +70 -26
  32. package/dist/core/provision/pins.js +5 -0
  33. package/dist/core/provision/provisioner.js +39 -16
  34. package/dist/core/provision/releases.js +39 -1
  35. package/dist/core/provision/tools.js +87 -28
  36. package/dist/core/runtime/agent-runtime.js +15 -5
  37. package/dist/core/runtime/event-processor.js +13 -8
  38. package/dist/core/runtime/origin-line.js +42 -0
  39. package/dist/core/runtime/request-broker.js +2 -1
  40. package/dist/core/runtime/steering.js +4 -3
  41. package/dist/core/runtime/turn.js +6 -4
  42. package/dist/operator/errors.js +97 -0
  43. package/dist/operator/index.js +10 -5
  44. package/dist/operator/mcp.js +7 -12
  45. package/dist/operator/operator.js +1431 -378
  46. package/dist/operator/refs.js +59 -0
  47. package/dist/operator/render.js +199 -94
  48. package/dist/operator/session-tools.js +88 -0
  49. package/dist/operator/types.js +30 -0
  50. package/dist/operator/view.js +82 -27
  51. package/dist/protocol/account.js +5 -1
  52. package/dist/protocol/auth.js +5 -1
  53. package/dist/protocol/config.js +12 -5
  54. package/dist/protocol/conversation.js +3 -0
  55. package/dist/protocol/credentials.js +9 -1
  56. package/dist/protocol/harness.js +9 -1
  57. package/dist/protocol/history.js +2 -1
  58. package/dist/protocol/index.js +1 -0
  59. package/dist/protocol/lifecycle.js +19 -0
  60. package/dist/protocol/origin.js +39 -0
  61. package/dist/protocol/reduce.js +2 -0
  62. package/dist/protocol/wire.js +17 -0
  63. package/dist/server/bin.js +22 -7
  64. package/dist/server/install.js +6 -4
  65. package/dist/server/routes.js +15 -5
  66. package/dist/types/client/client.d.ts.map +1 -1
  67. package/dist/types/client/connection.d.ts +14 -2
  68. package/dist/types/client/connection.d.ts.map +1 -1
  69. package/dist/types/client/turns.d.ts +2 -2
  70. package/dist/types/client/turns.d.ts.map +1 -1
  71. package/dist/types/core/agents/acp/account.d.ts +55 -0
  72. package/dist/types/core/agents/acp/account.d.ts.map +1 -0
  73. package/dist/types/core/agents/acp/acp-agent.d.ts +65 -36
  74. package/dist/types/core/agents/acp/acp-agent.d.ts.map +1 -1
  75. package/dist/types/core/agents/acp/adapter.d.ts +28 -3
  76. package/dist/types/core/agents/acp/adapter.d.ts.map +1 -1
  77. package/dist/types/core/agents/acp/client.d.ts +66 -4
  78. package/dist/types/core/agents/acp/client.d.ts.map +1 -1
  79. package/dist/types/core/agents/acp/known-agents.d.ts +4 -2
  80. package/dist/types/core/agents/acp/known-agents.d.ts.map +1 -1
  81. package/dist/types/core/agents/acp/mappings.d.ts +53 -7
  82. package/dist/types/core/agents/acp/mappings.d.ts.map +1 -1
  83. package/dist/types/core/agents/acp/models.d.ts +22 -0
  84. package/dist/types/core/agents/acp/models.d.ts.map +1 -0
  85. package/dist/types/core/agents/acp/profile.d.ts +92 -0
  86. package/dist/types/core/agents/acp/profile.d.ts.map +1 -0
  87. package/dist/types/core/agents/acp/prompts.d.ts +108 -0
  88. package/dist/types/core/agents/acp/prompts.d.ts.map +1 -0
  89. package/dist/types/core/agents/acp/requests.d.ts +7 -1
  90. package/dist/types/core/agents/acp/requests.d.ts.map +1 -1
  91. package/dist/types/core/agents/base.d.ts +2 -0
  92. package/dist/types/core/agents/base.d.ts.map +1 -1
  93. package/dist/types/core/agents/claude-code/login.d.ts.map +1 -1
  94. package/dist/types/core/agents/claude-code/session.d.ts +3 -0
  95. package/dist/types/core/agents/claude-code/session.d.ts.map +1 -1
  96. package/dist/types/core/agents/claude-code/spawn.d.ts +0 -8
  97. package/dist/types/core/agents/claude-code/spawn.d.ts.map +1 -1
  98. package/dist/types/core/agents/codex-app-server/client.d.ts.map +1 -1
  99. package/dist/types/core/agents/codex-app-server/login.d.ts.map +1 -1
  100. package/dist/types/core/agents/gemini/failures.d.ts +25 -0
  101. package/dist/types/core/agents/gemini/failures.d.ts.map +1 -0
  102. package/dist/types/core/agents/gemini/login.d.ts +28 -0
  103. package/dist/types/core/agents/gemini/login.d.ts.map +1 -0
  104. package/dist/types/core/agents/gemini/profile.d.ts +30 -0
  105. package/dist/types/core/agents/gemini/profile.d.ts.map +1 -0
  106. package/dist/types/core/agents/gemini/tools.d.ts +18 -0
  107. package/dist/types/core/agents/gemini/tools.d.ts.map +1 -0
  108. package/dist/types/core/agents/login.d.ts +15 -5
  109. package/dist/types/core/agents/login.d.ts.map +1 -1
  110. package/dist/types/core/agents/scripted/scripted-agent.d.ts +14 -1
  111. package/dist/types/core/agents/scripted/scripted-agent.d.ts.map +1 -1
  112. package/dist/types/core/agents/stderr-tail.d.ts +1 -1
  113. package/dist/types/core/agents/stderr-tail.d.ts.map +1 -1
  114. package/dist/types/core/presets.d.ts +2 -2
  115. package/dist/types/core/presets.d.ts.map +1 -1
  116. package/dist/types/core/processes/native-processes.d.ts +6 -0
  117. package/dist/types/core/processes/native-processes.d.ts.map +1 -1
  118. package/dist/types/core/provision/checksums.d.ts +7 -1
  119. package/dist/types/core/provision/checksums.d.ts.map +1 -1
  120. package/dist/types/core/provision/install-build.d.ts +32 -6
  121. package/dist/types/core/provision/install-build.d.ts.map +1 -1
  122. package/dist/types/core/provision/pins.d.ts +4 -0
  123. package/dist/types/core/provision/pins.d.ts.map +1 -1
  124. package/dist/types/core/provision/provisioner.d.ts +18 -7
  125. package/dist/types/core/provision/provisioner.d.ts.map +1 -1
  126. package/dist/types/core/provision/releases.d.ts +2 -1
  127. package/dist/types/core/provision/releases.d.ts.map +1 -1
  128. package/dist/types/core/provision/tools.d.ts +36 -7
  129. package/dist/types/core/provision/tools.d.ts.map +1 -1
  130. package/dist/types/core/runtime/agent-runtime.d.ts +4 -2
  131. package/dist/types/core/runtime/agent-runtime.d.ts.map +1 -1
  132. package/dist/types/core/runtime/event-processor.d.ts +2 -2
  133. package/dist/types/core/runtime/event-processor.d.ts.map +1 -1
  134. package/dist/types/core/runtime/origin-line.d.ts +15 -0
  135. package/dist/types/core/runtime/origin-line.d.ts.map +1 -0
  136. package/dist/types/core/runtime/request-broker.d.ts +1 -1
  137. package/dist/types/core/runtime/request-broker.d.ts.map +1 -1
  138. package/dist/types/core/runtime/steering.d.ts +7 -4
  139. package/dist/types/core/runtime/steering.d.ts.map +1 -1
  140. package/dist/types/core/runtime/turn.d.ts.map +1 -1
  141. package/dist/types/operator/errors.d.ts +87 -0
  142. package/dist/types/operator/errors.d.ts.map +1 -0
  143. package/dist/types/operator/index.d.ts +10 -5
  144. package/dist/types/operator/index.d.ts.map +1 -1
  145. package/dist/types/operator/mcp.d.ts +1 -1
  146. package/dist/types/operator/mcp.d.ts.map +1 -1
  147. package/dist/types/operator/operator.d.ts +15 -197
  148. package/dist/types/operator/operator.d.ts.map +1 -1
  149. package/dist/types/operator/refs.d.ts +25 -0
  150. package/dist/types/operator/refs.d.ts.map +1 -0
  151. package/dist/types/operator/render.d.ts +67 -22
  152. package/dist/types/operator/render.d.ts.map +1 -1
  153. package/dist/types/operator/session-tools.d.ts +61 -0
  154. package/dist/types/operator/session-tools.d.ts.map +1 -0
  155. package/dist/types/operator/types.d.ts +442 -0
  156. package/dist/types/operator/types.d.ts.map +1 -0
  157. package/dist/types/operator/view.d.ts +19 -29
  158. package/dist/types/operator/view.d.ts.map +1 -1
  159. package/dist/types/protocol/account.d.ts +4 -2
  160. package/dist/types/protocol/account.d.ts.map +1 -1
  161. package/dist/types/protocol/auth.d.ts +10 -7
  162. package/dist/types/protocol/auth.d.ts.map +1 -1
  163. package/dist/types/protocol/clis.d.ts +4 -3
  164. package/dist/types/protocol/clis.d.ts.map +1 -1
  165. package/dist/types/protocol/config.d.ts +22 -5
  166. package/dist/types/protocol/config.d.ts.map +1 -1
  167. package/dist/types/protocol/conversation.d.ts +47 -6
  168. package/dist/types/protocol/conversation.d.ts.map +1 -1
  169. package/dist/types/protocol/credentials.d.ts +8 -0
  170. package/dist/types/protocol/credentials.d.ts.map +1 -1
  171. package/dist/types/protocol/execution.d.ts +1 -1
  172. package/dist/types/protocol/harness.d.ts +5 -2
  173. package/dist/types/protocol/harness.d.ts.map +1 -1
  174. package/dist/types/protocol/history.d.ts +1 -1
  175. package/dist/types/protocol/history.d.ts.map +1 -1
  176. package/dist/types/protocol/index.d.ts +1 -0
  177. package/dist/types/protocol/index.d.ts.map +1 -1
  178. package/dist/types/protocol/lifecycle.d.ts +48 -10
  179. package/dist/types/protocol/lifecycle.d.ts.map +1 -1
  180. package/dist/types/protocol/models.d.ts +3 -0
  181. package/dist/types/protocol/models.d.ts.map +1 -1
  182. package/dist/types/protocol/origin.d.ts +49 -0
  183. package/dist/types/protocol/origin.d.ts.map +1 -0
  184. package/dist/types/protocol/reduce.d.ts.map +1 -1
  185. package/dist/types/protocol/wire-api.d.ts +78 -30
  186. package/dist/types/protocol/wire-api.d.ts.map +1 -1
  187. package/dist/types/protocol/wire.d.ts +78 -12
  188. package/dist/types/protocol/wire.d.ts.map +1 -1
  189. package/dist/types/server/install.d.ts +2 -1
  190. package/dist/types/server/install.d.ts.map +1 -1
  191. package/dist/types/server/routes.d.ts.map +1 -1
  192. package/docs/consuming.md +62 -121
  193. package/docs/deploy.md +17 -8
  194. package/docs/harnesses.md +166 -44
  195. package/docs/sync-history.md +2 -1
  196. package/package.json +1 -1
  197. package/src/client/client.ts +36 -9
  198. package/src/client/connection.ts +31 -1
  199. package/src/client/turns.ts +2 -1
  200. package/src/core/agents/acp/account.ts +158 -0
  201. package/src/core/agents/acp/acp-agent.ts +288 -178
  202. package/src/core/agents/acp/adapter.ts +126 -35
  203. package/src/core/agents/acp/client.ts +196 -49
  204. package/src/core/agents/acp/known-agents.ts +14 -5
  205. package/src/core/agents/acp/mappings.ts +112 -21
  206. package/src/core/agents/acp/models.ts +72 -0
  207. package/src/core/agents/acp/profile.ts +127 -0
  208. package/src/core/agents/acp/prompts.ts +287 -0
  209. package/src/core/agents/acp/requests.ts +16 -9
  210. package/src/core/agents/base.ts +2 -0
  211. package/src/core/agents/claude-code/approvals.ts +2 -2
  212. package/src/core/agents/claude-code/login.ts +4 -1
  213. package/src/core/agents/claude-code/session.ts +38 -8
  214. package/src/core/agents/claude-code/spawn.ts +0 -26
  215. package/src/core/agents/codex-app-server/client.ts +11 -18
  216. package/src/core/agents/codex-app-server/login.ts +4 -5
  217. package/src/core/agents/codex-app-server/plan-approval.ts +1 -1
  218. package/src/core/agents/gemini/failures.ts +148 -0
  219. package/src/core/agents/gemini/login.ts +188 -0
  220. package/src/core/agents/gemini/profile.ts +162 -0
  221. package/src/core/agents/gemini/tools.ts +99 -0
  222. package/src/core/agents/login.ts +14 -8
  223. package/src/core/agents/scripted/scripted-agent.ts +42 -3
  224. package/src/core/agents/stderr-tail.ts +5 -2
  225. package/src/core/presets.ts +19 -3
  226. package/src/core/processes/native-processes.ts +32 -1
  227. package/src/core/provision/checksums.ts +12 -2
  228. package/src/core/provision/install-build.ts +122 -55
  229. package/src/core/provision/pins.ts +5 -0
  230. package/src/core/provision/provisioner.ts +62 -27
  231. package/src/core/provision/releases.ts +47 -1
  232. package/src/core/provision/tools.ts +124 -31
  233. package/src/core/runtime/agent-runtime.ts +31 -7
  234. package/src/core/runtime/event-processor.ts +13 -6
  235. package/src/core/runtime/origin-line.ts +43 -0
  236. package/src/core/runtime/request-broker.ts +2 -0
  237. package/src/core/runtime/steering.ts +8 -4
  238. package/src/core/runtime/turn.ts +11 -4
  239. package/src/operator/errors.ts +221 -0
  240. package/src/operator/index.ts +18 -23
  241. package/src/operator/mcp.ts +7 -16
  242. package/src/operator/operator.ts +1684 -610
  243. package/src/operator/refs.ts +75 -0
  244. package/src/operator/render.ts +260 -118
  245. package/src/operator/session-tools.ts +127 -0
  246. package/src/operator/types.ts +506 -0
  247. package/src/operator/view.ts +93 -42
  248. package/src/protocol/account.ts +5 -2
  249. package/src/protocol/auth.ts +5 -1
  250. package/src/protocol/config.ts +14 -6
  251. package/src/protocol/conversation.ts +3 -0
  252. package/src/protocol/credentials.ts +11 -2
  253. package/src/protocol/harness.ts +9 -1
  254. package/src/protocol/history.ts +2 -1
  255. package/src/protocol/index.ts +1 -0
  256. package/src/protocol/lifecycle.ts +21 -0
  257. package/src/protocol/origin.ts +47 -0
  258. package/src/protocol/reduce.ts +4 -0
  259. package/src/protocol/wire.ts +18 -0
  260. package/src/server/bin.ts +20 -6
  261. package/src/server/install.ts +6 -3
  262. package/src/server/routes.ts +16 -5
@@ -1,21 +1,31 @@
1
1
  import type {
2
2
  InitializeResponse,
3
- PromptRequest,
4
3
  SessionConfigOption,
5
4
  SessionModeState,
6
5
  } from "@agentclientprotocol/sdk";
7
6
  import type {
8
7
  AgentCapabilities,
8
+ AgentHarness,
9
9
  AgentInput,
10
10
  McpServerConfig,
11
+ ModelDescriptor,
11
12
  PermissionMode,
12
13
  RunConfig,
13
14
  } from "../../../protocol/index.ts";
14
- import { AsyncQueue } from "../../../protocol/index.ts";
15
+ import { AsyncQueue, clampThinkingLevel } from "../../../protocol/index.ts";
15
16
  import { type NativeProcesses, sharedNativeProcesses } from "../../processes/native-processes.ts";
16
17
  import { onAbort, untilAborted } from "../../utils/deadline.ts";
17
- import { McpUnavailableError, SessionResumeError } from "../../utils/errors.ts";
18
- import type { AgentExecuteOptions, RawAgentEvent } from "../base.ts";
18
+ import {
19
+ InvalidRequestError,
20
+ McpUnavailableError,
21
+ SessionResumeError,
22
+ } from "../../utils/errors.ts";
23
+ import type {
24
+ AgentExecuteOptions,
25
+ AppliedExecution,
26
+ ListModelsOptions,
27
+ RawAgentEvent,
28
+ } from "../base.ts";
19
29
  import { configFingerprint } from "../config-fingerprint.ts";
20
30
  import {
21
31
  type HostLease,
@@ -25,17 +35,38 @@ import {
25
35
  loopbackDirect,
26
36
  refuseHostName,
27
37
  } from "../host-tools.ts";
38
+ import type { CliLogin } from "../login.ts";
28
39
  import { IDLE_TIMEOUT_MS, ProcessPool } from "../process-pool.ts";
29
40
  import { SessionAgent } from "../session-agent.ts";
41
+ import {
42
+ AcpAccount,
43
+ type AcpStart,
44
+ SESSION_REQUEST_TIMEOUT_MS,
45
+ initialize,
46
+ launchOf,
47
+ startClient,
48
+ } from "./account.ts";
30
49
  import { type AcpRawEvent, CANCELLED_PROMPT_RESULT } from "./adapter.ts";
31
- import { AcpClient, type AcpClientOptions, type AcpLaunch } from "./client.ts";
50
+ import type { AcpClient, AcpClientOptions, AcpLaunch } from "./client.ts";
32
51
  import {
33
52
  type AcpPromptCapabilities,
34
- permissionModeOf,
53
+ type SelectOption,
54
+ modeNames,
55
+ refuseFiles,
56
+ selectOf,
57
+ selectableValues,
35
58
  toAcpMcpServers,
36
59
  toPromptBlocks,
37
60
  } from "./mappings.ts";
38
- import { type TurnScope, answerElicitation, answerPermission } from "./requests.ts";
61
+ import { defaultModel, listAcpModels } from "./models.ts";
62
+ import { type AcpProfile, genericAcpProfile } from "./profile.ts";
63
+ import { TurnPrompts } from "./prompts.ts";
64
+ import {
65
+ type RequestScope,
66
+ type TurnScope,
67
+ answerElicitation,
68
+ answerPermission,
69
+ } from "./requests.ts";
39
70
 
40
71
  /**
41
72
  * What a session's agent process was started with, as one key: a change to
@@ -69,7 +100,12 @@ function spawnKey(
69
100
  host: string | undefined,
70
101
  ): string {
71
102
  return configFingerprint({
72
- launch: { command: launch.command, args: launch.args ?? [], env: launch.env ?? {} },
103
+ launch: {
104
+ command: launch.command,
105
+ args: launch.args ?? [],
106
+ env: launch.env ?? {},
107
+ fixedEnv: launch.fixedEnv ?? {},
108
+ },
73
109
  cwd: options.cwd,
74
110
  env: options.env,
75
111
  // @ref LLP 0018#acp — only what the agent is given
@@ -81,42 +117,6 @@ function spawnKey(
81
117
  });
82
118
  }
83
119
 
84
- const CAPABILITIES: AgentCapabilities = {
85
- multiTurn: true,
86
- // A requested resume fails if the target agent cannot load saved sessions.
87
- sessionResume: true,
88
- // v1 has no portable model parameter. A requested model or thinking level
89
- // is applied only when the agent offers a `model` / `thought_level` config
90
- // option, so neither is promised here.
91
- modelSwitch: "unsupported",
92
- thinkingLevels: false,
93
- // The most an agent can take: its `initialize` decides, image data with its
94
- // `image` prompt capability and files beyond text with `embeddedContext`.
95
- images: true,
96
- files: ["text", "pdf", "binary"],
97
- mcpServers: true,
98
- permissionRequests: true,
99
- // The answer is an option id.
100
- rejectionMessages: false,
101
- ignoredSettings: [
102
- // ACP v1 has no system prompt: session/new takes the folder, the MCP
103
- // servers and the extra directories only (`resolveSession`).
104
- "systemPromptAppend",
105
- // A prompt runs until the agent ends it: ACP v1 has no turn limit.
106
- "maxTurns",
107
- // session/resume and session/load name a session, not a message in it.
108
- "resumeSessionAt",
109
- // The agent's credentials are its launch command's: the client gets the
110
- // launch, the folder and the env only (`AcpClientOptions`).
111
- "apiKey",
112
- // ACP v1 cannot ask an agent to run without its tools.
113
- "disableTools",
114
- ] satisfies Array<keyof RunConfig>,
115
- };
116
-
117
- /** ACP protocol major version this harness speaks. */
118
- const PROTOCOL_VERSION = 1;
119
-
120
120
  /**
121
121
  * How long a cancelled prompt may take to end before the agent is ended,
122
122
  * unless `cancelGraceMs` says otherwise: an agent that can neither resume nor
@@ -124,12 +124,6 @@ const PROTOCOL_VERSION = 1;
124
124
  */
125
125
  const CANCEL_GRACE_MS = 10_000;
126
126
 
127
- /** Deadline for `initialize` on a freshly spawned agent (mirrors codex startup). */
128
- const INITIALIZE_TIMEOUT_MS = 15_000;
129
-
130
- /** Deadline for session lifecycle requests (`session/new`, `session/resume`). */
131
- const SESSION_REQUEST_TIMEOUT_MS = 30_000;
132
-
133
127
  export interface AcpAgentOptions {
134
128
  /**
135
129
  * Resolve the ACP agent subprocess to launch. Operator-level only — never
@@ -171,7 +165,7 @@ export interface AcpAgentOptions {
171
165
  hostTools?: HostTools;
172
166
  }
173
167
 
174
- interface AcpSession {
168
+ interface AcpSession extends RequestScope {
175
169
  client: AcpClient;
176
170
  acpSessionId: string;
177
171
  /** What its agent process was started with (`spawnKey`). */
@@ -186,8 +180,12 @@ interface AcpSession {
186
180
  configOptions: SessionConfigOption[];
187
181
  /** The agent's modes, kept current by `current_mode_update`; absent when it offers none. */
188
182
  modes?: SessionModeState;
183
+ /** For a profile that lists models: the one a turn naming none runs, as the session opened on it. */
184
+ defaultModel?: string;
189
185
  /** From `initialize`: what the agent's prompts accept beyond text and links. */
190
186
  prompt: AcpPromptCapabilities;
187
+ /** The MCP servers the agent was given, by name: what tells a call's server from its tool. */
188
+ servers: string[];
191
189
  turn?: TurnScope;
192
190
  }
193
191
 
@@ -210,33 +208,81 @@ function failureMessage(error: unknown): string {
210
208
  return `${error}: ${detail}`;
211
209
  }
212
210
 
213
- /** Every value a select option offers, whether listed flat or in groups. */
214
- function selectableValues(option: SessionConfigOption & { type: "select" }): string[] {
215
- return option.options.flatMap((entry) =>
216
- "options" in entry ? entry.options.map((nested) => nested.value) : [entry.value],
211
+ /** Set an option to `value` unless it holds it; the answer carries every option as it now stands. */
212
+ async function select(session: AcpSession, option: SelectOption, value: string): Promise<void> {
213
+ if (option.currentValue === value) return;
214
+ const updated = await session.client.request(
215
+ "session/set_config_option",
216
+ { sessionId: session.acpSessionId, configId: option.id, value },
217
+ SESSION_REQUEST_TIMEOUT_MS,
217
218
  );
219
+ session.configOptions = updated.configOptions;
218
220
  }
219
221
 
220
222
  /**
221
- * ACP harness: drives any Agent Client Protocol v1 agent as a long-lived
222
- * subprocess (one per logical session, reused across turns). The launch
223
- * command comes from the operator's `resolveLaunch`; `initialize` negotiates
224
- * the protocol version and gates optional features (resume, images) on the
225
- * agent's advertised capabilities. The turn's stopReason arrives as the
223
+ * What the agent's options say the turn runs, where it has them: what it ran,
224
+ * not what was asked (a level the model lacks was fitted, or left alone).
225
+ */
226
+ function selected(session: AcpSession): AppliedExecution {
227
+ const model = selectOf(session.configOptions, "model")?.currentValue;
228
+ const thinkingLevel = selectOf(session.configOptions, "thought_level")?.currentValue;
229
+ return { ...(model && { model }), ...(thinkingLevel && { thinkingLevel }) };
230
+ }
231
+
232
+ // @ref LLP 0016.000#an-acp-agents-profile — a profile reaches the agent only through its harness's registration
233
+ /**
234
+ * An ACP agent running a profile: drives an Agent Client Protocol v1 agent
235
+ * as a long-lived subprocess (one per logical session, reused across turns).
236
+ * What is one agent's own, its name, its launch command and where it departs
237
+ * from its `initialize`, is its profile; `initialize` negotiates the protocol
238
+ * version and gates optional features (resume, images) on the agent's
239
+ * advertised capabilities. The turn's stopReason arrives as the
226
240
  * `session/prompt` *response*, so `execute` re-injects it into the raw stream
227
- * as a synthetic `session/prompt_result` event for the adapter.
241
+ * as a synthetic `session/prompt_result` event for the adapter. Internal to
242
+ * the engine: a harness that is a profile constructs it in its registration
243
+ * (`geminiHarness`); `AcpAgent` is the `acp` harness.
228
244
  */
229
- export class AcpAgent extends SessionAgent {
230
- readonly harness = "acp" as const;
231
- readonly capabilities = CAPABILITIES;
245
+ export class ProfiledAcpAgent extends SessionAgent {
246
+ readonly harness: AgentHarness;
247
+ readonly capabilities: AgentCapabilities;
248
+ readonly login?: CliLogin;
249
+ /** Present when its profile lists models: what the agent offers this login. */
250
+ readonly listModels?: (options: ListModelsOptions) => Promise<ModelDescriptor[]>;
232
251
  /** Its CLIs start here: the runtime's, or this OS process's own when it was made without one. */
233
252
  readonly processes: NativeProcesses;
253
+ private readonly profile: AcpProfile;
234
254
  private readonly sessions: ProcessPool<AcpSession, AcpPoolTurn>;
235
255
  private readonly host?: HostToolSessions;
256
+ /** How its agents start: its profile's, on its processes. */
257
+ private readonly starts: AcpStart;
258
+ /** The agent with no turn: its account, for the login and the model list. */
259
+ private readonly account: AcpAccount;
260
+ /** What each session's conversation was started with, when this agent started it (`newSession`). */
261
+ private readonly startedWith = new Map<string, { conversation: string; meta: string }>();
236
262
 
237
- constructor(private readonly agentOptions: AcpAgentOptions) {
263
+ constructor(
264
+ profile: AcpProfile,
265
+ private readonly agentOptions: Omit<AcpAgentOptions, "resolveLaunch">,
266
+ ) {
238
267
  super({ cancelConfirmMs: agentOptions.cancelConfirmMs });
268
+ this.profile = profile;
269
+ this.harness = this.profile.harness;
270
+ this.capabilities = this.profile.capabilities;
239
271
  this.processes = agentOptions.processes ?? sharedNativeProcesses();
272
+ const { clientName, clientVersion, createClient } = agentOptions;
273
+ this.starts = {
274
+ profile: this.profile,
275
+ processes: this.processes,
276
+ clientName,
277
+ clientVersion,
278
+ createClient,
279
+ };
280
+ this.account = new AcpAccount(this.starts);
281
+ this.login = this.profile.login?.(this.account);
282
+ const models = this.profile.models;
283
+ if (models)
284
+ this.listModels = (listing) =>
285
+ listAcpModels(this.account, this.harness, (value) => models.offers(value), listing);
240
286
  this.host = hostToolSessions(agentOptions.hostTools, this.harness, {
241
287
  // @ref LLP 0018#acp — the engine's mode: the turn's, moved only by a plan the broker approved
242
288
  // The agent's own `current_mode_update` never raises it.
@@ -272,15 +318,8 @@ export class AcpAgent extends SessionAgent {
272
318
  options: AgentExecuteOptions,
273
319
  signal: AbortSignal,
274
320
  ): Promise<AcpSession> {
275
- signal.throwIfAborted();
276
321
  // A cancel ends the wait: the operator's resolution goes on for the next turn.
277
- const launch = await untilAborted(Promise.resolve(this.agentOptions.resolveLaunch()), signal);
278
- signal.throwIfAborted();
279
- if (!launch) {
280
- throw new Error(
281
- "acp harness is not configured: resolveLaunch returned no agent launch command",
282
- );
283
- }
322
+ const launch = await launchOf(this.profile, signal);
284
323
 
285
324
  const host = await untilAborted(
286
325
  Promise.resolve(this.host?.lease(options.sessionId, options.cwd)),
@@ -337,24 +376,26 @@ export class AcpAgent extends SessionAgent {
337
376
  signal: AbortSignal,
338
377
  ): Promise<AcpSession> {
339
378
  const resumeTarget = options.resumeSessionId;
340
- const clientOptions: AcpClientOptions = {
379
+ const client = await startClient(this.starts, {
341
380
  launch,
342
381
  cwd: options.cwd,
343
382
  // @ref LLP 0018#acp — the bearer never travels through a proxy
344
- // In the client's own order: the engine's environment, the launch's, the turn's.
383
+ // In the client's own order: the engine's environment, the launch's, the turn's, the launch's fixed.
345
384
  env: this.host
346
385
  ? {
347
386
  ...options.env,
348
- ...loopbackDirect({ ...process.env, ...launch.env, ...options.env }),
387
+ ...loopbackDirect({
388
+ ...process.env,
389
+ ...launch.env,
390
+ ...options.env,
391
+ ...launch.fixedEnv,
392
+ }),
349
393
  }
350
394
  : options.env,
351
- clientName: this.agentOptions.clientName,
352
395
  sessionId: options.sessionId,
353
- processes: this.processes,
354
- };
355
- const client = this.agentOptions.createClient
356
- ? await this.agentOptions.createClient(clientOptions)
357
- : await AcpClient.create(clientOptions);
396
+ // What the agent asks gates the steers sent as prompts (`TurnPrompts`).
397
+ watchRequests: this.capabilities.steering === true,
398
+ });
358
399
  own(client);
359
400
  // Closed at once when the turn was cancelled meanwhile.
360
401
  const offAbort = onAbort(signal, () => client.close());
@@ -362,20 +403,7 @@ export class AcpAgent extends SessionAgent {
362
403
  let acpSessionId: string | undefined;
363
404
  try {
364
405
  signal.throwIfAborted();
365
- init = await client.request(
366
- "initialize",
367
- {
368
- protocolVersion: PROTOCOL_VERSION,
369
- // The engine brokers the agent's requests for input, form or URL;
370
- // a turn whose client cannot answer declines them.
371
- clientCapabilities: { elicitation: { form: {}, url: {} } },
372
- clientInfo: {
373
- name: this.agentOptions.clientName ?? "agent-server",
374
- version: this.agentOptions.clientVersion ?? "0.0.0",
375
- },
376
- },
377
- INITIALIZE_TIMEOUT_MS,
378
- );
406
+ init = await initialize(client, this.starts);
379
407
  signal.throwIfAborted();
380
408
  const capabilities = init.agentCapabilities;
381
409
  const takesDirectories = Boolean(capabilities?.sessionCapabilities?.additionalDirectories);
@@ -387,7 +415,7 @@ export class AcpAgent extends SessionAgent {
387
415
  const given = await this.serversFor(
388
416
  options,
389
417
  host,
390
- Boolean(capabilities?.mcpCapabilities?.http),
418
+ this.profile.httpMcp || Boolean(capabilities?.mcpCapabilities?.http),
391
419
  );
392
420
  const target = {
393
421
  cwd: options.cwd,
@@ -423,14 +451,26 @@ export class AcpAgent extends SessionAgent {
423
451
  configOptions = resumed?.configOptions;
424
452
  modes = resumed?.modes;
425
453
  } else {
426
- const created = await client.request("session/new", target, SESSION_REQUEST_TIMEOUT_MS);
454
+ const meta = this.profile.newSession?.meta(options);
455
+ const created = await client.request(
456
+ "session/new",
457
+ { ...target, ...(meta && { _meta: meta }) },
458
+ SESSION_REQUEST_TIMEOUT_MS,
459
+ );
427
460
  acpSessionId = created.sessionId;
461
+ if (this.profile.newSession)
462
+ this.startedWith.set(options.sessionId, {
463
+ conversation: created.sessionId,
464
+ meta: configFingerprint(meta ?? {}),
465
+ });
428
466
  configOptions = created.configOptions;
429
467
  modes = created.modes;
430
468
  }
431
469
  signal.throwIfAborted();
432
470
  if (!acpSessionId) throw new Error("acp agent returned no session id");
433
471
 
472
+ // A session opens, new or resumed, on the account's default model.
473
+ const opened = selectOf(configOptions ?? [], "model");
434
474
  const session: AcpSession = {
435
475
  client,
436
476
  acpSessionId,
@@ -440,11 +480,16 @@ export class AcpAgent extends SessionAgent {
440
480
  resumable: resumeMethod !== undefined,
441
481
  configOptions: configOptions ?? [],
442
482
  ...(modes?.availableModes.length && { modes }),
483
+ ...(this.profile.models &&
484
+ opened && { defaultModel: defaultModel(opened, this.profile.models.offers) }),
443
485
  prompt: {
444
486
  image: Boolean(init.agentCapabilities?.promptCapabilities?.image),
445
487
  embeddedContext: Boolean(init.agentCapabilities?.promptCapabilities?.embeddedContext),
446
488
  },
489
+ servers: Object.keys(given.servers ?? {}),
447
490
  };
491
+ const tools = this.profile.tools;
492
+ if (tools) session.describe = (call) => tools.describe(call, session.servers);
448
493
  client.setPermissionHandler((request) => answerPermission(session, request));
449
494
  client.setElicitationHandler((request) => answerElicitation(session, request));
450
495
  client.onSessionUpdate(({ sessionId, update }) => {
@@ -465,75 +510,104 @@ export class AcpAgent extends SessionAgent {
465
510
  }
466
511
 
467
512
  /**
468
- * Select the requested model and thinking level through the agent's config
469
- * options. An agent without the option keeps its own default. A model the
470
- * agent does not offer fails the turn; thinking levels are a normalized
471
- * vocabulary an agent may not share, so an unmatched level is left alone.
472
- * Returns the settings it left alone.
513
+ * Select the requested model, then the thinking level, through the agent's
514
+ * config options; an agent without the option keeps its own default. A
515
+ * model the agent does not offer, or its profile does not take, fails the
516
+ * turn; a turn that names none on a profile that lists models runs the
517
+ * one its list marks default (`defaultModel`). The levels are the ones
518
+ * offered once the model is set, which are that model's, and the turn
519
+ * runs the nearest of them, as on Claude and Codex (`clampThinkingLevel`);
520
+ * a level that cannot be fitted is left alone. Returns the settings it
521
+ * left alone.
473
522
  */
474
523
  private async applyConfig(
475
524
  session: AcpSession,
476
525
  options: AgentExecuteOptions,
477
526
  ): Promise<Array<keyof RunConfig>> {
478
- const requested = [
479
- ["model", options.model, "model"],
480
- ["thought_level", options.thinkingLevel, "thinkingLevel"],
481
- ] as const;
482
527
  const left: Array<keyof RunConfig> = [];
483
- for (const [category, value, field] of requested) {
484
- if (!value) continue;
485
- const option = session.configOptions.find(
486
- (candidate): candidate is SessionConfigOption & { type: "select" } =>
487
- candidate.category === category && candidate.type === "select",
488
- );
489
- if (!option) {
490
- left.push(field);
491
- continue;
492
- }
493
- if (option.currentValue === value) continue;
494
- const offered = selectableValues(option);
495
- if (!offered.includes(value)) {
496
- if (category === "thought_level") {
497
- left.push(field);
498
- continue;
499
- }
528
+ const option = selectOf(session.configOptions, "model");
529
+ const offers = this.profile.models?.offers;
530
+ if (!option) {
531
+ if (options.model) left.push("model");
532
+ } else if (options.model || offers) {
533
+ const offered = selectableValues(option).filter((value) => offers?.(value) ?? true);
534
+ // @ref LLP 0016.000#an-acp-agents-model-and-thinking-level — a harness that lists its models runs only one of them
535
+ // The default the session opened on, while the agent still offers it.
536
+ const opened =
537
+ session.defaultModel && offered.includes(session.defaultModel)
538
+ ? session.defaultModel
539
+ : undefined;
540
+ const model =
541
+ options.model ?? opened ?? (offers && defaultModel(option, offers)) ?? option.currentValue;
542
+ if (!offered.includes(model)) {
500
543
  throw new Error(
501
- `invalid request: the ACP agent does not offer model '${value}' (available: ${offered.join(", ")})`,
544
+ `invalid request: the ${this.harness} harness does not offer model '${model}' (available: ${offered.join(", ") || "none"})`,
502
545
  );
503
546
  }
504
- const updated = await session.client.request(
505
- "session/set_config_option",
506
- { sessionId: session.acpSessionId, configId: option.id, value },
507
- SESSION_REQUEST_TIMEOUT_MS,
508
- );
509
- session.configOptions = updated.configOptions;
547
+ await select(session, option, model);
548
+ }
549
+ if (options.thinkingLevel) {
550
+ const option = selectOf(session.configOptions, "thought_level");
551
+ const level = option && clampThinkingLevel(options.thinkingLevel, selectableValues(option));
552
+ if (option && level !== undefined) await select(session, option, level);
553
+ else left.push("thinkingLevel");
510
554
  }
511
555
  return left;
512
556
  }
513
557
 
514
- // @ref LLP 0016.000#an-acp-agents-permission-mode — a permission mode reaches the agent, or is said not applied
558
+ // @ref LLP 0016.000#an-acp-agents-profile — what a conversation starts with it keeps
559
+ /**
560
+ * What a conversation keeps from its start (`newSession`), said not
561
+ * applied by a later turn that asks otherwise; what a conversation this
562
+ * agent did not start was given is unknown, and nothing is said.
563
+ */
564
+ private keptFromStart(session: AcpSession, options: AgentExecuteOptions): Array<keyof RunConfig> {
565
+ const kept = this.profile.newSession;
566
+ const started = this.startedWith.get(options.sessionId);
567
+ if (!kept || started?.conversation !== session.acpSessionId) return [];
568
+ // Compared, not said of every later turn: a product sends the same config each turn, and that one is in effect.
569
+ return started.meta === configFingerprint(kept.meta(options) ?? {}) ? [] : [...kept.settings];
570
+ }
571
+
572
+ // @ref LLP 0016.000#an-acp-agents-permission-mode — never a turn in a mode the engine knows is not the one asked
515
573
  /**
516
574
  * Put the agent in the turn's permission mode (`default` when it names
517
- * none) through `session/set_mode`, by the agent's own id for it. Returns
518
- * whether the mode holds: false for one the agent offers none of, which
519
- * leaves the agent in its own. An agent that offers no modes runs as it
520
- * does, the engine answering what it asks by the mode (`autoDecide`); it
521
- * has no plan of its own to make, so `plan` does not hold there.
575
+ * none) through `session/set_mode`, by the agent's own id for it. An agent
576
+ * with no id for the mode is put in its `default`, never left in the mode
577
+ * an earlier turn left it in, and the engine answers what it asks by the
578
+ * turn's mode (`autoDecide`), as for an agent that offers no modes; neither
579
+ * has a plan of its own to make, so `plan` does not hold there. An agent
580
+ * with no `default` either stays where it is: in a mode the engine names
581
+ * and was not asked, the turn is refused; in one it cannot name, it runs,
582
+ * and the mode is said not applied. Returns whether the mode holds.
522
583
  */
523
584
  private async applyMode(session: AcpSession, requested: PermissionMode): Promise<boolean> {
524
585
  const modes = session.modes;
525
586
  if (!modes) return requested !== "plan";
526
- const target = modes.availableModes.find((mode) => permissionModeOf(mode.id) === requested);
527
- if (!target) return false;
528
- if (target.id !== modes.currentModeId) {
587
+ const names = modeNames(this.profile.modeIds);
588
+ const offered = modes.availableModes.map(({ id }) => id);
589
+ const own = names.idOf(requested, offered);
590
+ const target = own ?? names.idOf("default", offered);
591
+ if (target === undefined) {
592
+ const current = names.modeOf(modes.currentModeId);
593
+ if (current === undefined) return false;
594
+ if (current === requested) return true;
595
+ throw new InvalidRequestError([
596
+ {
597
+ path: "permissionMode",
598
+ message: `the ${this.harness} harness cannot run a ${requested} turn: the agent is in ${current}, and offers no mode to move it to`,
599
+ },
600
+ ]);
601
+ }
602
+ if (target !== modes.currentModeId) {
529
603
  await session.client.request(
530
604
  "session/set_mode",
531
- { sessionId: session.acpSessionId, modeId: target.id },
605
+ { sessionId: session.acpSessionId, modeId: target },
532
606
  SESSION_REQUEST_TIMEOUT_MS,
533
607
  );
534
- session.modes = { ...modes, currentModeId: target.id };
608
+ session.modes = { ...modes, currentModeId: target };
535
609
  }
536
- return true;
610
+ return own !== undefined || requested !== "plan";
537
611
  }
538
612
 
539
613
  protected override async *executeTurn(
@@ -547,6 +621,8 @@ export class AcpAgent extends SessionAgent {
547
621
  let session: AcpSession | undefined;
548
622
  try {
549
623
  controller.signal.throwIfAborted();
624
+ this.profile.admit?.(options);
625
+ refuseFiles(input, this.harness, this.capabilities.files);
550
626
  session = await this.resolveSession(options, controller.signal);
551
627
  const notApplied = await this.applyConfig(session, options);
552
628
  // Sent only to an agent that takes them (`resolveSession`).
@@ -554,7 +630,8 @@ export class AcpAgent extends SessionAgent {
554
630
  notApplied.push("additionalDirectories");
555
631
  if (!(await this.applyMode(session, options.permissionMode ?? "default")))
556
632
  notApplied.push("permissionMode");
557
- if (notApplied.length) options.onExecution?.({ notApplied });
633
+ notApplied.push(...this.keptFromStart(session, options));
634
+ options.onExecution?.({ ...selected(session), ...(notApplied.length && { notApplied }) });
558
635
  controller.signal.throwIfAborted();
559
636
  session.turn = {
560
637
  broker: options.onPermissionRequest,
@@ -566,33 +643,51 @@ export class AcpAgent extends SessionAgent {
566
643
  options.onNativeSession?.(session.acpSessionId, {
567
644
  resumed: session.acpSessionId === options.resumeSessionId,
568
645
  });
646
+ // What tells its calls' servers from their tools, for the adapter's tool rules.
647
+ if (this.profile.tools)
648
+ yield { method: "agentServer/mcpServers", params: { names: session.servers } };
569
649
  const { client, acpSessionId } = session;
650
+ const takes = session.prompt;
570
651
 
571
- unsubscribe.push(
572
- client.onSessionUpdate((notification) => {
573
- if (notification.sessionId !== acpSessionId) return;
574
- queue.push({ method: "session/update", params: notification });
575
- }),
576
- );
577
652
  const finishCancelled = () => {
578
653
  queue.push(CANCELLED_PROMPT_RESULT);
579
654
  queue.end();
580
655
  };
581
- // Settles once the agent is no longer prompting: its prompt answered, or it exited.
582
- let promptEnded = () => {};
583
- const prompted = new Promise<boolean>((resolve) => {
584
- promptEnded = () => resolve(true);
656
+ const prompts = new TurnPrompts({
657
+ send: (prompt) => client.request("session/prompt", { sessionId: acpSessionId, prompt }),
658
+ ...(client.asking && { asking: client.asking }),
659
+ signal: controller.signal,
660
+ ends: {
661
+ read: (steerId) => queue.push({ method: "agentServer/steerRead", params: { steerId } }),
662
+ ended: (result) => {
663
+ this.holdSteering(options);
664
+ queue.push({ method: "session/prompt_result", params: result });
665
+ queue.end();
666
+ },
667
+ failed: (error) => {
668
+ this.holdSteering(options);
669
+ if (controller.signal.aborted) return finishCancelled();
670
+ queue.push({ method: "error", params: { message: failureMessage(error) } });
671
+ queue.end();
672
+ },
673
+ },
585
674
  });
586
675
  unsubscribe.push(
676
+ client.onSessionUpdate((notification) => {
677
+ if (notification.sessionId !== acpSessionId) return;
678
+ // A steer the agent took is read before what it says next.
679
+ prompts.update(notification.update);
680
+ queue.push({ method: "session/update", params: notification });
681
+ }),
587
682
  client.onClose((error) => {
588
- promptEnded();
683
+ prompts.close();
589
684
  if (controller.signal.aborted) finishCancelled();
590
685
  else queue.fail(error ?? new Error("acp agent exited mid-turn"));
591
686
  }),
592
687
  );
593
688
 
594
689
  const cancelPrompt = () => {
595
- // ACP semantics: session/cancel makes the in-flight prompt resolve
690
+ // ACP semantics: session/cancel makes the in-flight prompts resolve
596
691
  // with stopReason=cancelled. Bound the wait for misbehaving agents.
597
692
  void client.notify("session/cancel", { sessionId: acpSessionId }).catch(() => {});
598
693
  cancelTimer = setTimeout(() => {
@@ -609,28 +704,16 @@ export class AcpAgent extends SessionAgent {
609
704
  finishCancelled();
610
705
  } else {
611
706
  unsubscribe.push(onAbort(controller.signal, cancelPrompt));
612
- const prompt: PromptRequest = {
613
- sessionId: acpSessionId,
614
- prompt: toPromptBlocks(input, session.prompt),
615
- };
616
- // @ref LLP 0001#d9--the-wire-is-quick-ack-json-rpc-requests-flow-one-way — confirmed only when the prompt ended
617
- this.cancelWith(options, () => prompted);
618
- client.request("session/prompt", prompt).then(
619
- (response) => {
620
- promptEnded();
621
- queue.push({ method: "session/prompt_result", params: response });
622
- queue.end();
623
- },
624
- (error: unknown) => {
625
- promptEnded();
626
- if (controller.signal.aborted) {
627
- finishCancelled();
628
- return;
629
- }
630
- queue.push({ method: "error", params: { message: failureMessage(error) } });
631
- queue.end();
632
- },
633
- );
707
+ // @ref LLP 0001#d9--the-wire-is-quick-ack-json-rpc-requests-flow-one-way — confirmed only when the prompts ended
708
+ this.cancelWith(options, () => prompts.settled.then(() => true));
709
+ prompts.start(toPromptBlocks(input, takes));
710
+ // @ref LLP 0016.000#an-acp-agent-steered-by-prompt — input during a turn is a prompt of its own
711
+ if (this.capabilities.steering)
712
+ await this.openSteering(options, (request) => {
713
+ if (!prompts.open || controller.signal.aborted) return "no_active_turn";
714
+ prompts.steer(request.steerId, toPromptBlocks(request.input, takes));
715
+ return "steered";
716
+ });
634
717
  }
635
718
 
636
719
  for await (const event of queue) {
@@ -643,18 +726,34 @@ export class AcpAgent extends SessionAgent {
643
726
  if (cancelTimer) clearTimeout(cancelTimer);
644
727
  for (const off of unsubscribe) off();
645
728
  if (session) {
729
+ // A turn that has ended asks nothing: what it left open is forgotten.
730
+ session.client.asking?.askNothing();
646
731
  session.turn = undefined;
647
732
  this.sessions.leave(options.sessionId, session);
648
733
  }
649
734
  }
650
735
  }
651
736
 
737
+ /** A steer's file of a kind the harness does not take is refused, as a turn's is. */
738
+ protected override checkSteerInput(input: AgentInput): void {
739
+ refuseFiles(input, this.harness, this.capabilities.files);
740
+ }
741
+
652
742
  override async release(sessionId: string): Promise<void> {
653
743
  // The cancel aborts its turn at once; the agent is ended beside its
654
744
  // confirm window, not after it, and its exit is what confirms it.
655
745
  // An agent an eviction or a replacement ended earlier is waited for too.
656
746
  await Promise.all([super.release(sessionId), this.sessions.release(sessionId)]);
657
747
  this.host?.release(sessionId);
748
+ this.startedWith.delete(sessionId);
749
+ }
750
+
751
+ /**
752
+ * The agent's login changed (in `store`, or in every store): each session's
753
+ * next turn starts a new agent, which resumes its conversation.
754
+ */
755
+ loginChanged(store?: string): void {
756
+ this.sessions.loginChanged(store);
658
757
  }
659
758
 
660
759
  /** After a host resume, each session's next turn starts its agent again, on its conversation. */
@@ -668,3 +767,14 @@ export class AcpAgent extends SessionAgent {
668
767
  await this.host?.close();
669
768
  }
670
769
  }
770
+
771
+ /**
772
+ * The `acp` harness: any ACP v1 agent the operator launches
773
+ * (`resolveLaunch`), taken at its `initialize`'s word.
774
+ */
775
+ export class AcpAgent extends ProfiledAcpAgent {
776
+ constructor(options: AcpAgentOptions) {
777
+ const { resolveLaunch, ...shared } = options;
778
+ super(genericAcpProfile(resolveLaunch), shared);
779
+ }
780
+ }