@zvada/agent-server 0.3.22 → 0.3.23

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 (348) hide show
  1. package/CHANGELOG.md +261 -0
  2. package/dist/types/accounts/chatgpt.d.ts +1 -1
  3. package/dist/types/accounts/chatgpt.d.ts.map +1 -1
  4. package/dist/types/accounts/http.d.ts +2 -4
  5. package/dist/types/accounts/http.d.ts.map +1 -1
  6. package/dist/types/client/client.d.ts +37 -11
  7. package/dist/types/client/client.d.ts.map +1 -1
  8. package/dist/types/client/connection.d.ts +64 -13
  9. package/dist/types/client/connection.d.ts.map +1 -1
  10. package/dist/types/client/index.d.ts +1 -1
  11. package/dist/types/client/index.d.ts.map +1 -1
  12. package/dist/types/client/logins.d.ts +2 -1
  13. package/dist/types/client/logins.d.ts.map +1 -1
  14. package/dist/types/client/streams.d.ts +9 -3
  15. package/dist/types/client/streams.d.ts.map +1 -1
  16. package/dist/types/client/turns.d.ts +1 -1
  17. package/dist/types/client/turns.d.ts.map +1 -1
  18. package/dist/types/core/agents/acp/acp-agent.d.ts +34 -1
  19. package/dist/types/core/agents/acp/acp-agent.d.ts.map +1 -1
  20. package/dist/types/core/agents/acp/adapter.d.ts.map +1 -1
  21. package/dist/types/core/agents/acp/client.d.ts +12 -3
  22. package/dist/types/core/agents/acp/client.d.ts.map +1 -1
  23. package/dist/types/core/agents/acp/mappings.d.ts +8 -2
  24. package/dist/types/core/agents/acp/mappings.d.ts.map +1 -1
  25. package/dist/types/core/agents/base.d.ts +22 -8
  26. package/dist/types/core/agents/base.d.ts.map +1 -1
  27. package/dist/types/core/agents/claude-code/adapter.d.ts +7 -0
  28. package/dist/types/core/agents/claude-code/adapter.d.ts.map +1 -1
  29. package/dist/types/core/agents/claude-code/approvals.d.ts +4 -1
  30. package/dist/types/core/agents/claude-code/approvals.d.ts.map +1 -1
  31. package/dist/types/core/agents/claude-code/claude-agent.d.ts +16 -5
  32. package/dist/types/core/agents/claude-code/claude-agent.d.ts.map +1 -1
  33. package/dist/types/core/agents/claude-code/events.d.ts +9 -1
  34. package/dist/types/core/agents/claude-code/events.d.ts.map +1 -1
  35. package/dist/types/core/agents/claude-code/login.d.ts +4 -1
  36. package/dist/types/core/agents/claude-code/login.d.ts.map +1 -1
  37. package/dist/types/core/agents/claude-code/mcp.d.ts +21 -7
  38. package/dist/types/core/agents/claude-code/mcp.d.ts.map +1 -1
  39. package/dist/types/core/agents/claude-code/models.d.ts +5 -1
  40. package/dist/types/core/agents/claude-code/models.d.ts.map +1 -1
  41. package/dist/types/core/agents/claude-code/options.d.ts +10 -4
  42. package/dist/types/core/agents/claude-code/options.d.ts.map +1 -1
  43. package/dist/types/core/agents/claude-code/outcome.d.ts +3 -5
  44. package/dist/types/core/agents/claude-code/outcome.d.ts.map +1 -1
  45. package/dist/types/core/agents/claude-code/results.d.ts +16 -0
  46. package/dist/types/core/agents/claude-code/results.d.ts.map +1 -0
  47. package/dist/types/core/agents/claude-code/sdk-pair.d.ts +13 -0
  48. package/dist/types/core/agents/claude-code/sdk-pair.d.ts.map +1 -0
  49. package/dist/types/core/agents/claude-code/session.d.ts +50 -12
  50. package/dist/types/core/agents/claude-code/session.d.ts.map +1 -1
  51. package/dist/types/core/agents/claude-code/spend.d.ts +2 -1
  52. package/dist/types/core/agents/claude-code/spend.d.ts.map +1 -1
  53. package/dist/types/core/agents/claude-code/tools.d.ts +26 -3
  54. package/dist/types/core/agents/claude-code/tools.d.ts.map +1 -1
  55. package/dist/types/core/agents/codex-app-server/adapter.d.ts +2 -2
  56. package/dist/types/core/agents/codex-app-server/adapter.d.ts.map +1 -1
  57. package/dist/types/core/agents/codex-app-server/client.d.ts +12 -2
  58. package/dist/types/core/agents/codex-app-server/client.d.ts.map +1 -1
  59. package/dist/types/core/agents/codex-app-server/codex-agent.d.ts +58 -13
  60. package/dist/types/core/agents/codex-app-server/codex-agent.d.ts.map +1 -1
  61. package/dist/types/core/agents/codex-app-server/commands.d.ts +2 -2
  62. package/dist/types/core/agents/codex-app-server/commands.d.ts.map +1 -1
  63. package/dist/types/core/agents/codex-app-server/credentials.d.ts +5 -1
  64. package/dist/types/core/agents/codex-app-server/credentials.d.ts.map +1 -1
  65. package/dist/types/core/agents/codex-app-server/effort.d.ts +2 -1
  66. package/dist/types/core/agents/codex-app-server/effort.d.ts.map +1 -1
  67. package/dist/types/core/agents/codex-app-server/homes.d.ts +19 -0
  68. package/dist/types/core/agents/codex-app-server/homes.d.ts.map +1 -1
  69. package/dist/types/core/agents/codex-app-server/items.d.ts +27 -2
  70. package/dist/types/core/agents/codex-app-server/items.d.ts.map +1 -1
  71. package/dist/types/core/agents/codex-app-server/login.d.ts +4 -1
  72. package/dist/types/core/agents/codex-app-server/login.d.ts.map +1 -1
  73. package/dist/types/core/agents/codex-app-server/mcp.d.ts +15 -30
  74. package/dist/types/core/agents/codex-app-server/mcp.d.ts.map +1 -1
  75. package/dist/types/core/agents/codex-app-server/models.d.ts +3 -10
  76. package/dist/types/core/agents/codex-app-server/models.d.ts.map +1 -1
  77. package/dist/types/core/agents/codex-app-server/options.d.ts +27 -4
  78. package/dist/types/core/agents/codex-app-server/options.d.ts.map +1 -1
  79. package/dist/types/core/agents/codex-app-server/plan-approval.d.ts +2 -1
  80. package/dist/types/core/agents/codex-app-server/plan-approval.d.ts.map +1 -1
  81. package/dist/types/core/agents/codex-app-server/protocol.d.ts +16 -3
  82. package/dist/types/core/agents/codex-app-server/protocol.d.ts.map +1 -1
  83. package/dist/types/core/agents/codex-app-server/requests.d.ts.map +1 -1
  84. package/dist/types/core/agents/codex-app-server/session.d.ts +68 -40
  85. package/dist/types/core/agents/codex-app-server/session.d.ts.map +1 -1
  86. package/dist/types/core/agents/codex-app-server/subagents.d.ts +9 -4
  87. package/dist/types/core/agents/codex-app-server/subagents.d.ts.map +1 -1
  88. package/dist/types/core/agents/codex-app-server/thread-settings.d.ts +3 -2
  89. package/dist/types/core/agents/codex-app-server/thread-settings.d.ts.map +1 -1
  90. package/dist/types/core/agents/codex-app-server/turn-items.d.ts +2 -1
  91. package/dist/types/core/agents/codex-app-server/turn-items.d.ts.map +1 -1
  92. package/dist/types/core/agents/codex-app-server/turn.d.ts +31 -8
  93. package/dist/types/core/agents/codex-app-server/turn.d.ts.map +1 -1
  94. package/dist/types/core/agents/codex-app-server/user-login.d.ts +28 -0
  95. package/dist/types/core/agents/codex-app-server/user-login.d.ts.map +1 -0
  96. package/dist/types/core/agents/credentials.d.ts +3 -1
  97. package/dist/types/core/agents/credentials.d.ts.map +1 -1
  98. package/dist/types/core/agents/diffs.d.ts +9 -0
  99. package/dist/types/core/agents/diffs.d.ts.map +1 -0
  100. package/dist/types/core/agents/elicitation.d.ts +3 -2
  101. package/dist/types/core/agents/elicitation.d.ts.map +1 -1
  102. package/dist/types/core/agents/login.d.ts +6 -0
  103. package/dist/types/core/agents/login.d.ts.map +1 -1
  104. package/dist/types/core/agents/mcp-config.d.ts +0 -4
  105. package/dist/types/core/agents/mcp-config.d.ts.map +1 -1
  106. package/dist/types/core/agents/process-pool.d.ts +193 -0
  107. package/dist/types/core/agents/process-pool.d.ts.map +1 -0
  108. package/dist/types/core/agents/scripted/adapter.d.ts +68 -0
  109. package/dist/types/core/agents/scripted/adapter.d.ts.map +1 -0
  110. package/dist/types/core/agents/scripted/mcp-call.d.ts +56 -0
  111. package/dist/types/core/agents/scripted/mcp-call.d.ts.map +1 -0
  112. package/dist/types/core/agents/scripted/scripted-agent.d.ts +73 -0
  113. package/dist/types/core/agents/scripted/scripted-agent.d.ts.map +1 -0
  114. package/dist/types/core/agents/scripted/scripts.d.ts +29 -0
  115. package/dist/types/core/agents/scripted/scripts.d.ts.map +1 -0
  116. package/dist/types/core/agents/scripted/steps.d.ts +132 -0
  117. package/dist/types/core/agents/scripted/steps.d.ts.map +1 -0
  118. package/dist/types/core/agents/session-agent.d.ts +49 -6
  119. package/dist/types/core/agents/session-agent.d.ts.map +1 -1
  120. package/dist/types/core/diagnostics.d.ts +4 -1
  121. package/dist/types/core/diagnostics.d.ts.map +1 -1
  122. package/dist/types/core/index.d.ts +5 -0
  123. package/dist/types/core/index.d.ts.map +1 -1
  124. package/dist/types/core/presets.d.ts +32 -6
  125. package/dist/types/core/presets.d.ts.map +1 -1
  126. package/dist/types/core/processes/lifeline.d.ts +0 -20
  127. package/dist/types/core/processes/lifeline.d.ts.map +1 -1
  128. package/dist/types/core/provision/index.d.ts +2 -2
  129. package/dist/types/core/provision/index.d.ts.map +1 -1
  130. package/dist/types/core/provision/install-build.d.ts +2 -1
  131. package/dist/types/core/provision/install-build.d.ts.map +1 -1
  132. package/dist/types/core/provision/npm.d.ts +20 -8
  133. package/dist/types/core/provision/npm.d.ts.map +1 -1
  134. package/dist/types/core/provision/provisioner.d.ts +4 -1
  135. package/dist/types/core/provision/provisioner.d.ts.map +1 -1
  136. package/dist/types/core/provision/tools.d.ts +2 -1
  137. package/dist/types/core/provision/tools.d.ts.map +1 -1
  138. package/dist/types/core/runtime/agent-runtime.d.ts +16 -8
  139. package/dist/types/core/runtime/agent-runtime.d.ts.map +1 -1
  140. package/dist/types/core/runtime/event-processor.d.ts +5 -1
  141. package/dist/types/core/runtime/event-processor.d.ts.map +1 -1
  142. package/dist/types/core/runtime/harness-clis.d.ts +9 -0
  143. package/dist/types/core/runtime/harness-clis.d.ts.map +1 -1
  144. package/dist/types/core/runtime/harness-logins.d.ts +33 -5
  145. package/dist/types/core/runtime/harness-logins.d.ts.map +1 -1
  146. package/dist/types/core/runtime/model-lists.d.ts +2 -0
  147. package/dist/types/core/runtime/model-lists.d.ts.map +1 -1
  148. package/dist/types/core/runtime/permission-policy.d.ts +5 -3
  149. package/dist/types/core/runtime/permission-policy.d.ts.map +1 -1
  150. package/dist/types/core/runtime/request-broker.d.ts +2 -1
  151. package/dist/types/core/runtime/request-broker.d.ts.map +1 -1
  152. package/dist/types/core/runtime/turn.d.ts +12 -1
  153. package/dist/types/core/runtime/turn.d.ts.map +1 -1
  154. package/dist/types/core/utils/deadline.d.ts +6 -0
  155. package/dist/types/core/utils/deadline.d.ts.map +1 -1
  156. package/dist/types/core/utils/errors.d.ts +7 -1
  157. package/dist/types/core/utils/errors.d.ts.map +1 -1
  158. package/dist/types/operator/operator.d.ts.map +1 -1
  159. package/dist/types/operator/render.d.ts +6 -4
  160. package/dist/types/operator/render.d.ts.map +1 -1
  161. package/dist/types/protocol/auth.d.ts +54 -24
  162. package/dist/types/protocol/auth.d.ts.map +1 -1
  163. package/dist/types/protocol/clis.d.ts +14 -7
  164. package/dist/types/protocol/clis.d.ts.map +1 -1
  165. package/dist/types/protocol/config.d.ts +2 -0
  166. package/dist/types/protocol/config.d.ts.map +1 -1
  167. package/dist/types/protocol/conversation.d.ts +40 -3
  168. package/dist/types/protocol/conversation.d.ts.map +1 -1
  169. package/dist/types/protocol/credentials.d.ts +7 -0
  170. package/dist/types/protocol/credentials.d.ts.map +1 -1
  171. package/dist/types/protocol/execution.d.ts +2 -1
  172. package/dist/types/protocol/execution.d.ts.map +1 -1
  173. package/dist/types/protocol/factories.d.ts +12 -2
  174. package/dist/types/protocol/factories.d.ts.map +1 -1
  175. package/dist/types/protocol/harness.d.ts +6 -2
  176. package/dist/types/protocol/harness.d.ts.map +1 -1
  177. package/dist/types/protocol/history.d.ts +19 -0
  178. package/dist/types/protocol/history.d.ts.map +1 -1
  179. package/dist/types/protocol/lifecycle.d.ts +47 -8
  180. package/dist/types/protocol/lifecycle.d.ts.map +1 -1
  181. package/dist/types/protocol/model-catalog.d.ts.map +1 -1
  182. package/dist/types/protocol/models.d.ts +3 -0
  183. package/dist/types/protocol/models.d.ts.map +1 -1
  184. package/dist/types/protocol/parts.d.ts +14 -0
  185. package/dist/types/protocol/parts.d.ts.map +1 -1
  186. package/dist/types/protocol/tool-state.d.ts +12 -0
  187. package/dist/types/protocol/tool-state.d.ts.map +1 -1
  188. package/dist/types/protocol/wire-api.d.ts +129 -23
  189. package/dist/types/protocol/wire-api.d.ts.map +1 -1
  190. package/dist/types/protocol/wire.d.ts +70 -10
  191. package/dist/types/protocol/wire.d.ts.map +1 -1
  192. package/dist/types/server/acp/binding.d.ts +6 -1
  193. package/dist/types/server/acp/binding.d.ts.map +1 -1
  194. package/dist/types/server/acp/translate.d.ts +33 -7
  195. package/dist/types/server/acp/translate.d.ts.map +1 -1
  196. package/dist/types/server/agent-server.d.ts +6 -0
  197. package/dist/types/server/agent-server.d.ts.map +1 -1
  198. package/dist/types/server/feedback.d.ts +2 -1
  199. package/dist/types/server/feedback.d.ts.map +1 -1
  200. package/dist/types/server/install.d.ts +11 -0
  201. package/dist/types/server/install.d.ts.map +1 -1
  202. package/dist/types/server/session-gate.d.ts +2 -1
  203. package/dist/types/server/session-gate.d.ts.map +1 -1
  204. package/dist/types/server/session-store.d.ts +1 -0
  205. package/dist/types/server/session-store.d.ts.map +1 -1
  206. package/dist/types/server/subscriptions.d.ts +2 -1
  207. package/dist/types/server/subscriptions.d.ts.map +1 -1
  208. package/dist/types/server/transports.d.ts.map +1 -1
  209. package/dist/types/sync/fit.d.ts +8 -7
  210. package/dist/types/sync/fit.d.ts.map +1 -1
  211. package/dist/types/sync/history-sqlite.d.ts.map +1 -1
  212. package/dist/types/sync/index.d.ts +1 -0
  213. package/dist/types/sync/index.d.ts.map +1 -1
  214. package/dist/types/sync/journal-sqlite.d.ts +2 -1
  215. package/dist/types/sync/journal-sqlite.d.ts.map +1 -1
  216. package/dist/types/sync/journal.d.ts +11 -3
  217. package/dist/types/sync/journal.d.ts.map +1 -1
  218. package/dist/types/sync/projection.d.ts +6 -0
  219. package/dist/types/sync/projection.d.ts.map +1 -1
  220. package/dist/types/sync/recovery.d.ts +2 -1
  221. package/dist/types/sync/recovery.d.ts.map +1 -1
  222. package/dist/types/sync/schema.d.ts +10 -0
  223. package/dist/types/sync/schema.d.ts.map +1 -1
  224. package/dist/types/sync/sql.d.ts +2 -1
  225. package/dist/types/sync/sql.d.ts.map +1 -1
  226. package/docs/consuming.md +278 -28
  227. package/docs/deploy.md +36 -8
  228. package/docs/durable-sessions.md +35 -5
  229. package/docs/harnesses.md +385 -24
  230. package/package.json +6 -1
  231. package/src/accounts/chatgpt.ts +2 -2
  232. package/src/accounts/http.ts +2 -16
  233. package/src/client/client.ts +92 -31
  234. package/src/client/connection.ts +103 -22
  235. package/src/client/index.ts +1 -0
  236. package/src/client/logins.ts +1 -1
  237. package/src/client/streams.ts +12 -4
  238. package/src/client/turns.ts +1 -1
  239. package/src/core/agents/acp/acp-agent.ts +181 -52
  240. package/src/core/agents/acp/adapter.ts +9 -1
  241. package/src/core/agents/acp/client.ts +16 -4
  242. package/src/core/agents/acp/mappings.ts +27 -0
  243. package/src/core/agents/base.ts +25 -10
  244. package/src/core/agents/claude-code/adapter.ts +47 -17
  245. package/src/core/agents/claude-code/approvals.ts +6 -5
  246. package/src/core/agents/claude-code/claude-agent.ts +60 -30
  247. package/src/core/agents/claude-code/events.ts +11 -1
  248. package/src/core/agents/claude-code/login.ts +14 -2
  249. package/src/core/agents/claude-code/mcp.ts +31 -15
  250. package/src/core/agents/claude-code/models.ts +7 -2
  251. package/src/core/agents/claude-code/options.ts +11 -3
  252. package/src/core/agents/claude-code/outcome.ts +10 -2
  253. package/src/core/agents/claude-code/results.ts +73 -0
  254. package/src/core/agents/claude-code/sdk-pair.ts +66 -0
  255. package/src/core/agents/claude-code/session.ts +166 -37
  256. package/src/core/agents/claude-code/spend.ts +1 -1
  257. package/src/core/agents/claude-code/tools.ts +108 -12
  258. package/src/core/agents/codex-app-server/adapter.ts +37 -12
  259. package/src/core/agents/codex-app-server/client.ts +37 -8
  260. package/src/core/agents/codex-app-server/codex-agent.ts +115 -50
  261. package/src/core/agents/codex-app-server/commands.ts +2 -2
  262. package/src/core/agents/codex-app-server/credentials.ts +10 -5
  263. package/src/core/agents/codex-app-server/effort.ts +1 -1
  264. package/src/core/agents/codex-app-server/homes.ts +43 -1
  265. package/src/core/agents/codex-app-server/items.ts +219 -31
  266. package/src/core/agents/codex-app-server/login.ts +14 -2
  267. package/src/core/agents/codex-app-server/mcp.ts +47 -32
  268. package/src/core/agents/codex-app-server/models.ts +9 -8
  269. package/src/core/agents/codex-app-server/options.ts +69 -10
  270. package/src/core/agents/codex-app-server/plan-approval.ts +1 -1
  271. package/src/core/agents/codex-app-server/protocol.ts +14 -4
  272. package/src/core/agents/codex-app-server/requests.ts +14 -6
  273. package/src/core/agents/codex-app-server/session.ts +151 -113
  274. package/src/core/agents/codex-app-server/subagents.ts +21 -14
  275. package/src/core/agents/codex-app-server/thread-settings.ts +18 -8
  276. package/src/core/agents/codex-app-server/turn-items.ts +1 -1
  277. package/src/core/agents/codex-app-server/turn.ts +79 -32
  278. package/src/core/agents/codex-app-server/user-login.ts +107 -0
  279. package/src/core/agents/credentials.ts +5 -2
  280. package/src/core/agents/diffs.ts +25 -0
  281. package/src/core/agents/elicitation.ts +2 -2
  282. package/src/core/agents/login.ts +6 -0
  283. package/src/core/agents/mcp-config.ts +2 -2
  284. package/src/core/agents/process-pool.ts +432 -0
  285. package/src/core/agents/scripted/adapter.ts +142 -0
  286. package/src/core/agents/scripted/mcp-call.ts +134 -0
  287. package/src/core/agents/scripted/scripted-agent.ts +418 -0
  288. package/src/core/agents/scripted/scripts.ts +171 -0
  289. package/src/core/agents/scripted/steps.ts +127 -0
  290. package/src/core/agents/session-agent.ts +105 -8
  291. package/src/core/diagnostics.ts +9 -1
  292. package/src/core/index.ts +11 -0
  293. package/src/core/presets.ts +99 -14
  294. package/src/core/processes/lifeline.ts +99 -25
  295. package/src/core/provision/index.ts +1 -2
  296. package/src/core/provision/install-build.ts +4 -1
  297. package/src/core/provision/npm.ts +309 -97
  298. package/src/core/provision/provisioner.ts +22 -8
  299. package/src/core/provision/tools.ts +44 -19
  300. package/src/core/runtime/agent-runtime.ts +48 -18
  301. package/src/core/runtime/event-processor.ts +18 -2
  302. package/src/core/runtime/harness-clis.ts +36 -1
  303. package/src/core/runtime/harness-logins.ts +82 -31
  304. package/src/core/runtime/model-lists.ts +1 -1
  305. package/src/core/runtime/permission-policy.ts +4 -3
  306. package/src/core/runtime/request-broker.ts +1 -1
  307. package/src/core/runtime/turn.ts +51 -3
  308. package/src/core/utils/deadline.ts +23 -0
  309. package/src/core/utils/errors.ts +11 -4
  310. package/src/operator/operator.ts +8 -4
  311. package/src/operator/render.ts +46 -8
  312. package/src/protocol/auth.ts +30 -23
  313. package/src/protocol/clis.ts +12 -4
  314. package/src/protocol/credentials.ts +19 -0
  315. package/src/protocol/execution.ts +5 -0
  316. package/src/protocol/factories.ts +25 -3
  317. package/src/protocol/harness.ts +11 -1
  318. package/src/protocol/history.ts +20 -0
  319. package/src/protocol/lifecycle.ts +10 -1
  320. package/src/protocol/model-catalog.ts +19 -8
  321. package/src/protocol/parts.ts +12 -1
  322. package/src/protocol/tool-state.ts +14 -1
  323. package/src/protocol/wire.ts +14 -0
  324. package/src/server/acp/binding.ts +113 -23
  325. package/src/server/acp/translate.ts +161 -8
  326. package/src/server/agent-server.ts +10 -1
  327. package/src/server/bin.ts +83 -9
  328. package/src/server/feedback.ts +1 -1
  329. package/src/server/install.ts +82 -4
  330. package/src/server/session-gate.ts +1 -1
  331. package/src/server/session-store.ts +5 -1
  332. package/src/server/subscriptions.ts +1 -1
  333. package/src/server/transports.ts +14 -0
  334. package/src/sync/fit.ts +115 -28
  335. package/src/sync/history-sqlite.ts +6 -2
  336. package/src/sync/index.ts +1 -0
  337. package/src/sync/journal-sqlite.ts +20 -2
  338. package/src/sync/journal.ts +10 -2
  339. package/src/sync/projection.ts +10 -0
  340. package/src/sync/recovery.ts +11 -4
  341. package/src/sync/schema.ts +7 -5
  342. package/src/sync/sql.ts +1 -1
  343. package/dist/types/core/agents/claude-code/session-pool.d.ts +0 -36
  344. package/dist/types/core/agents/claude-code/session-pool.d.ts.map +0 -1
  345. package/dist/types/core/agents/session-pool.d.ts +0 -41
  346. package/dist/types/core/agents/session-pool.d.ts.map +0 -1
  347. package/src/core/agents/claude-code/session-pool.ts +0 -136
  348. package/src/core/agents/session-pool.ts +0 -111
@@ -7,7 +7,9 @@ import {
7
7
  realpathSync,
8
8
  } from "node:fs";
9
9
  import { readdir } from "node:fs/promises";
10
- import { dirname, join } from "node:path";
10
+ import { createRequire } from "node:module";
11
+ import { dirname, join, resolve } from "node:path";
12
+ import { pathToFileURL } from "node:url";
11
13
  import type { AgentHarness } from "../../protocol/index.ts";
12
14
  import { CliNotFoundError, CliProvisionError } from "../utils/errors.ts";
13
15
  import type { LocalBuild } from "./checksums.ts";
@@ -22,20 +24,22 @@ import {
22
24
  /**
23
25
  * The managed CLIs. Each native harness maps onto exactly one of these; the
24
26
  * `acp` harness maps onto none (its agent binaries are arbitrary third-party
25
- * commands the operator supplies, not something we pin or download).
27
+ * commands the operator supplies, not something we pin or download), nor does
28
+ * `scripted`, which runs no process.
26
29
  */
27
30
  export const CLI_TOOLS = ["claude", "codex"] as const;
28
31
  export type CliTool = (typeof CLI_TOOLS)[number];
29
32
 
30
33
  /**
31
34
  * Which managed CLI a harness runs on — `undefined` for unmanaged harnesses
32
- * (`acp`). Exhaustive by construction: adding a harness fails to compile here
33
- * until someone decides whether it is provisioner-managed.
35
+ * (`acp`, `scripted`). Exhaustive by construction: adding a harness fails to
36
+ * compile here until someone decides whether it is provisioner-managed.
34
37
  */
35
38
  const TOOL_FOR_HARNESS: Record<AgentHarness, CliTool | undefined> = {
36
39
  "claude-code": "claude",
37
40
  "codex-app-server": "codex",
38
41
  acp: undefined,
42
+ scripted: undefined,
39
43
  };
40
44
 
41
45
  export function toolForHarness(harness: AgentHarness): CliTool | undefined {
@@ -136,21 +140,33 @@ function findPackageDir(name: string, fromDir: string): string | undefined {
136
140
 
137
141
  /**
138
142
  * Where this package lives on disk — the walk anchor: this module's folder,
139
- * or a bundle's when bundled (Bun defines `__dirname` in ESM too), and
140
- * `undefined` in an ESM bundle under Node, where nothing on disk says. The
141
- * walk never starts from the working folder, whose project may hold another
142
- * Claude SDK than the one that runs. A compiled binary sees the path it was
143
- * built at, which misses on any other machine, so pins take over. NOTE: this
144
- * must not mention `import.meta` — consumers bundle these sources to CJS,
145
- * where that token is a parse error (and older bundlers don't rewrite it).
143
+ * or a bundle's when bundled (Bun defines `__dirname` in ESM too). Under
144
+ * Node's ESM (tsx, an ESM bundle), which has neither `__dirname` nor
145
+ * `require`, a `require` made from the entry script resolves this package's
146
+ * own manifest (an explicit export; the product's install, or the package
147
+ * itself by self-reference). Anything unresolvable is `undefined`, and pins
148
+ * take over. The walk never starts from the working folder, whose project
149
+ * may hold another Claude SDK than the one that runs. A compiled binary's
150
+ * modules are in `$bunfs`, nowhere on disk. NOTE: this must not mention
151
+ * `import` `.meta` (the meta-property; spelled apart here so the check in
152
+ * `test/core/provision/module-dir.test.ts` holds for comments too) —
153
+ * consumers bundle these sources to CJS, where that token is a parse error
154
+ * (and older bundlers, Bun 1.2.x, don't rewrite it).
146
155
  */
147
156
  function moduleDir(): string | undefined {
157
+ if (inCompiledBinary()) return undefined;
148
158
  // CJS bundle output: anchor at the bundle location.
149
159
  if (typeof __dirname !== "undefined") return __dirname;
150
160
  try {
151
- // Bun/ESM: resolve our own manifest through the module graph (Bun
152
- // provides `require` in ESM; "./package.json" is an explicit export).
153
- return dirname(require.resolve("@zvada/agent-server/package.json"));
161
+ // Bun/ESM provides `require`; Node's ESM gets one from its entry script.
162
+ const entry = process.argv[1];
163
+ const resolver =
164
+ typeof require !== "undefined"
165
+ ? require
166
+ : entry
167
+ ? createRequire(pathToFileURL(resolve(entry)).href)
168
+ : undefined;
169
+ return resolver && dirname(resolver.resolve("@zvada/agent-server/package.json"));
154
170
  } catch {
155
171
  return undefined;
156
172
  }
@@ -175,7 +191,10 @@ function versionOf(packageDir: string): string | undefined {
175
191
  * never skew. Unresolvable inside compiled binaries — pins take over there.
176
192
  */
177
193
  export function claudeSdkOnDisk(): { dir: string; version?: string } | undefined {
178
- const from = moduleDir();
194
+ return claudeSdkFrom(moduleDir());
195
+ }
196
+
197
+ function claudeSdkFrom(from: string | undefined): { dir: string; version?: string } | undefined {
179
198
  if (!from) return undefined;
180
199
  try {
181
200
  const dir = findPackageDir("@anthropic-ai/claude-agent-sdk", from);
@@ -237,10 +256,16 @@ export const CLI_TOOL_SPECS: Record<CliTool, CliToolSpec> = {
237
256
  // @ref LLP 0010#p2--claudes-build-follows-the-sdk-that-runs — a bundled SDK's version is the host's to say
238
257
  // The compiled agent-server binary bundles the SDK it pins, so only
239
258
  // another product's bundle runs an SDK nothing here can name.
240
- defaultVersionNote: () =>
241
- claudeSdkOnDisk() || inCompiledBinary()
242
- ? undefined
243
- : `claude: no Claude SDK on disk, so this runs the CLI of agent-server's pin ${DEFAULT_PINS.claude}; a product that bundles the SDK sets provision.pins.claude to its version`,
259
+ // Said only as it is: where the engine looked and found none, or that it could not look.
260
+ defaultVersionNote: () => {
261
+ if (inCompiledBinary()) return undefined;
262
+ const from = moduleDir();
263
+ if (claudeSdkFrom(from)) return undefined;
264
+ const why = from
265
+ ? `no Claude SDK is installed beside agent-server (looked up from ${from})`
266
+ : "agent-server cannot tell where it runs from here and could not look for a Claude SDK";
267
+ return `claude: ${why}, so this runs the CLI of agent-server's pin ${DEFAULT_PINS.claude}; a product that bundles the SDK sets provision.pins.claude to its version`;
268
+ },
244
269
  // The platform package beside the installed Claude SDK: the build that
245
270
  // SDK would spawn itself.
246
271
  hostInstall: ({ platform }) => {
@@ -23,12 +23,18 @@ import type { NativeProcessEvent, OrphanOutcome } from "../processes/native-proc
23
23
  import { withTimeout } from "../utils/deadline.ts";
24
24
  import { InvalidRequestError, TurnConflictError, TurnForgottenError } from "../utils/errors.ts";
25
25
  import { type EventSink, EventSinkError } from "./event-sink.ts";
26
- import { harnessCliProgress, harnessClis } from "./harness-clis.ts";
26
+ import { awaitingInstall, harnessCliProgress, harnessClis } from "./harness-clis.ts";
27
27
  import { HarnessLogins } from "./harness-logins.ts";
28
- import { ModelLists } from "./model-lists.ts";
28
+ import { ModelLists, catalogModelList } from "./model-lists.ts";
29
29
  import { StandingRules } from "./permission-policy.ts";
30
30
  import type { RequestAnswers, RequestKind } from "./request-broker.ts";
31
- import { type RunSummary, type SessionMemory, Turn, type TurnHost } from "./turn.ts";
31
+ import {
32
+ type RunSummary,
33
+ type SessionMemory,
34
+ Turn,
35
+ type TurnHost,
36
+ wellFormedInput,
37
+ } from "./turn.ts";
32
38
 
33
39
  /**
34
40
  * How `run()` would treat a request: execute it (`new`), or converge a retry
@@ -81,8 +87,8 @@ export class AgentRuntime {
81
87
  ) {
82
88
  this.logins = new HarnessLogins(
83
89
  (harness) => registry.getAgent(harness),
84
- (harness) => {
85
- registry.getAgent(harness).loginChanged?.();
90
+ (harness, store) => {
91
+ registry.getAgent(harness).loginChanged?.(store);
86
92
  this.modelLists.forget(harness);
87
93
  },
88
94
  );
@@ -100,7 +106,8 @@ export class AgentRuntime {
100
106
  }
101
107
 
102
108
  capabilities(harness: AgentHarness): AgentCapabilities {
103
- return this.registry.getAgent(harness).capabilities;
109
+ // A custom agent that declares none says it ignores nothing.
110
+ return { ignoredSettings: [], ...this.registry.getAgent(harness).capabilities };
104
111
  }
105
112
 
106
113
  /**
@@ -108,10 +115,17 @@ export class AgentRuntime {
108
115
  * turn with the same `cwd`, `env` and `apiKey` would use, and cached. Never
109
116
  * rejects for a registered harness: without a live list it returns the
110
117
  * catalog, with `error` saying why. Turns then fit their thinking level to
111
- * the listed levels of the model they run.
118
+ * the listed levels of the model they run. A read installs nothing: while
119
+ * the harness's CLI is not installed yet, being installed or failed to,
120
+ * the answer is the catalog with that `error`, kept by no cache, so the
121
+ * first read after the install is live.
112
122
  */
113
123
  async models(query: ModelsListParams): Promise<ModelList> {
114
- return await this.modelLists.get(this.registry.getAgent(query.harness), query);
124
+ const agent = this.registry.getAgent(query.harness);
125
+ // @ref LLP 0010#a-read-installs-nothing — a model picker opened downloads no CLI
126
+ const awaiting = await awaitingInstall(this.registry.provisioner, query.harness);
127
+ if (awaiting) return { ...catalogModelList(query.harness, Date.now()), error: awaiting };
128
+ return await this.modelLists.get(agent, query);
115
129
  }
116
130
 
117
131
  /**
@@ -138,9 +152,9 @@ export class AgentRuntime {
138
152
  }
139
153
 
140
154
  /**
141
- * Every install of a harness's CLI, whoever caused it (a turn, a model
142
- * list, `prepareClis`): at most four a second, and always its last phase.
143
- * Returns the unsubscribe.
155
+ * Every install of a harness's CLI, whoever caused it (a turn,
156
+ * `prepareClis`, a login or logout; a read installs nothing): at most four
157
+ * a second, and always its last phase. Returns the unsubscribe.
144
158
  */
145
159
  onCliProgress(observer: (progress: HarnessCliProgress) => void): () => void {
146
160
  const provisioner = this.registry.provisioner;
@@ -156,13 +170,25 @@ export class AgentRuntime {
156
170
  * absent): signed in, with what and as whom, signed out, or unknown and
157
171
  * why; and the logins it offers. A login made elsewhere (a terminal) that
158
172
  * a read notices counts as a change, as `login` and `logout` do: each
159
- * session's next turn starts a new CLI, and `onAuthUpdated` hears it.
173
+ * session's next turn starts a new CLI, and `onAuthUpdated` hears it. A
174
+ * login under way to the store is `loginUnderWay`. A read installs
175
+ * nothing: a harness whose CLI is not installed yet, being installed or
176
+ * failed to is `unknown`, with no methods and `error` saying which, and
177
+ * its CLI is not run.
160
178
  */
161
- authStatus(
179
+ async authStatus(
162
180
  harnesses: readonly AgentHarness[] = this.harnesses,
163
181
  env?: Record<string, string>,
164
182
  ): Promise<HarnessAuth[]> {
165
- return this.logins.status(harnesses, env);
183
+ for (const harness of harnesses) this.registry.getAgent(harness);
184
+ return Promise.all(
185
+ harnesses.map(async (harness): Promise<HarnessAuth> => {
186
+ // @ref LLP 0010#a-read-installs-nothing — a settings page opened downloads no CLI
187
+ const error = await awaitingInstall(this.registry.provisioner, harness);
188
+ if (error === undefined) return this.logins.statusOf(harness, env);
189
+ return { harness, state: "unknown", methods: [], error };
190
+ }),
191
+ );
166
192
  }
167
193
 
168
194
  /**
@@ -366,7 +392,10 @@ export class AgentRuntime {
366
392
  const agent = this.registry.getAgent(turn.harness);
367
393
  const deliver = agent.capabilities.steering ? agent.steer?.bind(agent) : undefined;
368
394
  if (!deliver) return { outcome: "unsupported" };
369
- return await turn.steers.accept(steerId, inputKey, input, () => deliver(sessionId, request));
395
+ // Its echo is the caller's input; the agent is given it well-formed.
396
+ return await turn.steers.accept(steerId, inputKey, input, () =>
397
+ deliver(sessionId, { ...request, input: wellFormedInput(input) }),
398
+ );
370
399
  }
371
400
 
372
401
  /** Whether another turn of the session, live or remembered, took this steer id. */
@@ -380,9 +409,10 @@ export class AgentRuntime {
380
409
 
381
410
  /**
382
411
  * Call after the host resumes from suspension, before admitting new turns.
383
- * Retains conversations and admission receipts. Claude and Codex app-server
384
- * replace retained subprocesses before the next prompt and strictly resume
385
- * saved history. Their MCP reset/reload controls can retain dead connections.
412
+ * Retains conversations and admission receipts, and ends no process: Claude,
413
+ * Codex app-server and ACP replace each retained subprocess before its
414
+ * session's next prompt and strictly resume saved history. Their MCP
415
+ * reset/reload controls can retain dead connections.
386
416
  */
387
417
  invalidateMcpConnections(): void {
388
418
  for (const harness of this.registry.list()) {
@@ -28,6 +28,7 @@ import type { TurnOutcome } from "./turn-outcome.ts";
28
28
  function endedExecution(
29
29
  execution: TurnExecution,
30
30
  result: Pick<TransformResult, "reportedModels">,
31
+ notApplied: ReadonlySet<string>,
31
32
  applied?: AppliedExecution,
32
33
  ): TurnExecution {
33
34
  const reportedModels = result.reportedModels?.length
@@ -39,6 +40,8 @@ function endedExecution(
39
40
  ...execution,
40
41
  ...(applied?.thinkingLevel !== undefined && { appliedThinkingLevel: applied.thinkingLevel }),
41
42
  ...(reportedModels.length > 0 && { reportedModels }),
43
+ // Whether or not the model ran: what was not applied never was.
44
+ ...(notApplied.size > 0 && { notApplied: [...notApplied] }),
42
45
  };
43
46
  }
44
47
 
@@ -91,6 +94,8 @@ export class EventProcessor {
91
94
  private permissionMode: string;
92
95
  /** What the harness runs the turn with, once it says (`AgentExecuteOptions.onExecution`). */
93
96
  private applied?: AppliedExecution;
97
+ /** The settings the turn set that were not applied, in the order they were found. */
98
+ private readonly notApplied = new Set<string>();
94
99
  /** The model writing what follows, by sub-agent tool call ("" for the turn's own). */
95
100
  private readonly writtenBy = new Map<string, string>();
96
101
  /** The model the open message named. */
@@ -107,8 +112,14 @@ export class EventProcessor {
107
112
  }
108
113
 
109
114
  /** What the harness runs the turn with, as it learns it: its model names the messages no event names. */
110
- applyExecution(update: AppliedExecution): void {
115
+ applyExecution({ notApplied, ...update }: AppliedExecution): void {
111
116
  this.applied = { ...this.applied, ...update };
117
+ this.markNotApplied(notApplied ?? []);
118
+ }
119
+
120
+ /** Settings the turn set that were not applied: `turn.ended.execution.notApplied`. */
121
+ markNotApplied(fields: Iterable<string>): void {
122
+ for (const field of fields) this.notApplied.add(field);
112
123
  }
113
124
 
114
125
  /**
@@ -287,7 +298,12 @@ export class EventProcessor {
287
298
  finishReason: result.finishReason,
288
299
  tokens: result.usage,
289
300
  cost: result.cost,
290
- execution: endedExecution(this.execution, result, ran ? this.applied : undefined),
301
+ execution: endedExecution(
302
+ this.execution,
303
+ result,
304
+ this.notApplied,
305
+ ran ? this.applied : undefined,
306
+ ),
291
307
  error: outcome.error,
292
308
  ...(undelivered.length > 0 && { undeliveredSteers: undelivered }),
293
309
  timestamp: Date.now(),
@@ -20,7 +20,13 @@ function harnessCli(harness: AgentHarness, status: CliStatus | undefined): Harne
20
20
  ...(status.totalBytes !== undefined && { totalBytes: status.totalBytes }),
21
21
  };
22
22
  case "failed":
23
- return { harness, state: "failed", ...version, error: status.error };
23
+ return {
24
+ harness,
25
+ state: "failed",
26
+ ...version,
27
+ error: status.error,
28
+ category: status.category,
29
+ };
24
30
  }
25
31
  }
26
32
 
@@ -43,6 +49,34 @@ export async function harnessClis(
43
49
  );
44
50
  }
45
51
 
52
+ // @ref LLP 0010#a-read-installs-nothing — a read answers without the CLI rather than install it
53
+ /**
54
+ * Why a read (a model list, a login's status) of this harness waits for an
55
+ * install it does not start: its CLI is not ready and the provisioner names
56
+ * the version an install would fetch (`missing` where the engine installs,
57
+ * `installing`, or `failed` after an install). `undefined` where a read goes
58
+ * ahead: the CLI is ready, nothing installs (`system`, which names no
59
+ * version), or the harness has no managed CLI.
60
+ */
61
+ export async function awaitingInstall(
62
+ provisioner: CliProvisioner | undefined,
63
+ harness: AgentHarness,
64
+ ): Promise<string | undefined> {
65
+ const tool = toolForHarness(harness);
66
+ if (!provisioner || !tool) return undefined;
67
+ const status = await provisioner.status(tool).catch(() => undefined);
68
+ if (!status || status.state === "ready" || status.version === undefined) return undefined;
69
+ const cli = `The ${harness} CLI ${status.version}`;
70
+ switch (status.state) {
71
+ case "missing":
72
+ return `${cli} is not installed yet.`;
73
+ case "installing":
74
+ return `${cli} is being installed.`;
75
+ case "failed":
76
+ return `${cli} failed to install: ${status.error}`;
77
+ }
78
+ }
79
+
46
80
  /** An install's progress, once per harness that runs its CLI. */
47
81
  export function harnessCliProgress(
48
82
  progress: CliProgress,
@@ -57,5 +91,6 @@ export function harnessCliProgress(
57
91
  receivedBytes: progress.receivedBytes,
58
92
  ...(progress.totalBytes !== undefined && { totalBytes: progress.totalBytes }),
59
93
  ...(progress.error !== undefined && { error: progress.error }),
94
+ ...(progress.category !== undefined && { category: progress.category }),
60
95
  }));
61
96
  }
@@ -22,7 +22,7 @@ const LOGIN_TTL_MS = 10 * 60_000;
22
22
  const LOGIN_START_TIMEOUT_MS = 20_000;
23
23
  /** A status read is reused this long once it answered: a settings page that polls starts no CLI each time. */
24
24
  const STATUS_TTL_MS = 2_000;
25
- /** A status read that takes longer (a CLI still installing) answers `unknown`. */
25
+ /** A status read that takes longer (a CLI slow to start) answers `unknown`. */
26
26
  const STATUS_TIMEOUT_MS = 20_000;
27
27
 
28
28
  interface Login {
@@ -40,7 +40,7 @@ interface Login {
40
40
  readonly settle: (update: AuthUpdated) => void;
41
41
  }
42
42
 
43
- export interface HarnessLoginsOptions {
43
+ interface HarnessLoginsOptions {
44
44
  now?: () => number;
45
45
  newId?: () => string;
46
46
  loginTtlMs?: number;
@@ -63,8 +63,13 @@ const storeKey = (harness: AgentHarness, env: Record<string, string> | undefined
63
63
  * Each harness's login, read from its CLI, and the logins under way. A login
64
64
  * that succeeds and a logout change the login, and so does a read that
65
65
  * differs from the last one of its store (a login in a terminal): `onChanged`
66
- * hears it (each session's next turn starts a new CLI, model lists are read
67
- * again) and `onUpdated` listeners are told, as they are when a login ends.
66
+ * hears it, with the store as the harness names it (each of that store's
67
+ * sessions starts its next turn on a new CLI, model lists are read again),
68
+ * and `onUpdated` listeners are told, as they are when a login starts
69
+ * and when it ends. Every login that leaves here carries the store's login
70
+ * under way (`loginUnderWay`), added as it leaves: a reading kept for its
71
+ * store never holds it, so a login starting or ending is no change of the
72
+ * login.
68
73
  */
69
74
  export class HarnessLogins {
70
75
  /** Logins under way, until their end is told. */
@@ -75,7 +80,7 @@ export class HarnessLogins {
75
80
 
76
81
  constructor(
77
82
  private readonly agentFor: (harness: AgentHarness) => Agent,
78
- private readonly onChanged: (harness: AgentHarness) => void,
83
+ private readonly onChanged: (harness: AgentHarness, store: string | undefined) => void,
79
84
  private readonly options: HarnessLoginsOptions = {},
80
85
  ) {
81
86
  this.reads = new LoginReads(() => this.now(), options.statusTtlMs ?? STATUS_TTL_MS);
@@ -85,24 +90,49 @@ export class HarnessLogins {
85
90
  return this.options.now?.() ?? Date.now();
86
91
  }
87
92
 
93
+ /**
94
+ * The login changed in the store a turn with this `env` uses, as its
95
+ * harness names it. Status reads stay keyed by the whole `env`, which can
96
+ * differ in more than the store.
97
+ */
98
+ private changed(harness: AgentHarness, env: Record<string, string> | undefined): void {
99
+ // @ref LLP 0011#a-login-change-starts-the-next-turn-on-a-new-cli — the person's own store is every store's
100
+ // A change in the default store (no store variable: the person's own)
101
+ // is a change in every store, none named: a product may link or hand
102
+ // that login into stores of its sessions' own (Deus links
103
+ // `~/.codex/auth.json` into each session's `CODEX_HOME`).
104
+ const store = this.agentFor(harness).login?.store?.(env) || undefined;
105
+ this.onChanged(harness, store);
106
+ }
107
+
88
108
  /** Each harness's login: a read under way, or one a moment old, is shared. */
89
- async status(
90
- harnesses: readonly AgentHarness[],
91
- env?: Record<string, string>,
92
- ): Promise<HarnessAuth[]> {
93
- return Promise.all(
94
- harnesses.map(async (harness) => {
95
- const recent = this.reads.recent(storeKey(harness, env));
96
- if (recent) return (await recent).auth;
97
- const { auth, differs } = await this.reread(harness, env);
98
- // Changed where the engine did not change it: a login in a terminal.
99
- if (differs) {
100
- this.onChanged(harness);
101
- this.emit({ auth });
102
- }
103
- return auth;
104
- }),
105
- );
109
+ status(harnesses: readonly AgentHarness[], env?: Record<string, string>): Promise<HarnessAuth[]> {
110
+ return Promise.all(harnesses.map((harness) => this.statusOf(harness, env)));
111
+ }
112
+
113
+ /** One harness's login, with the store's login under way. */
114
+ async statusOf(harness: AgentHarness, env?: Record<string, string>): Promise<HarnessAuth> {
115
+ const store = storeKey(harness, env);
116
+ const recent = this.reads.recent(store);
117
+ if (recent) return this.withLogin((await recent).auth, store);
118
+ const { auth, differs } = await this.reread(harness, env);
119
+ // Changed where the engine did not change it: a login in a terminal.
120
+ if (differs) {
121
+ this.changed(harness, env);
122
+ this.emit({ auth: this.withLogin(auth, store) });
123
+ }
124
+ return this.withLogin(auth, store);
125
+ }
126
+
127
+ // @ref LLP 0011#the-wire — every reader sees a login under way, and can cancel it
128
+ /**
129
+ * The login as it leaves here: with the store's login under way, as
130
+ * `auth/login` answered it, when there is one. Made at the moment it is
131
+ * told, so no answer or update shows a login a newer one replaced.
132
+ */
133
+ private withLogin(auth: HarnessAuth, store: string): HarnessAuth {
134
+ const login = this.underWay().find((candidate) => candidate.store === store);
135
+ return login ? { ...auth, loginUnderWay: { ...login.answer } } : auth;
106
136
  }
107
137
 
108
138
  private reread(harness: AgentHarness, env: Record<string, string> | undefined): Promise<Reading> {
@@ -188,7 +218,26 @@ export class HarnessLogins {
188
218
  for (const login of this.underWay()) {
189
219
  if (login.store === store) this.end(login, "cancelled");
190
220
  }
191
- return this.track(harness, method, store, env, native);
221
+ const login = this.track(harness, method, store, env, native);
222
+ void this.tellStarted(login);
223
+ return login.answer;
224
+ }
225
+
226
+ /**
227
+ * Tell every listener a login started, after `auth/login` is answered:
228
+ * the store's login (its recent reading, else a new one) with this one
229
+ * under way. Nothing when it ended meanwhile, as its end says it; a read
230
+ * of its own that noticed a change is told all the same. A recent
231
+ * reading's change is its reader's, who told it already.
232
+ */
233
+ private async tellStarted(login: Login): Promise<void> {
234
+ const recent = this.reads.recent(login.store);
235
+ const reading = await (recent ?? this.reread(login.harness, login.env)).catch(() => undefined);
236
+ if (!reading || this.stopped) return;
237
+ const noticed = !recent && reading.differs;
238
+ if (noticed) this.changed(login.harness, login.env);
239
+ else if (login.end) return;
240
+ this.emit({ auth: this.withLogin(reading.auth, login.store) });
192
241
  }
193
242
 
194
243
  /** Keep a started login until it ends, and expire it. */
@@ -198,7 +247,7 @@ export class HarnessLogins {
198
247
  store: string,
199
248
  env: Record<string, string> | undefined,
200
249
  native: NativeLogin,
201
- ): AuthLogin {
250
+ ): Login {
202
251
  const loginId = this.options.newId?.() ?? generateUUIDv7();
203
252
  const ttl = this.options.loginTtlMs ?? LOGIN_TTL_MS;
204
253
  const answer: AuthLogin = {
@@ -230,7 +279,7 @@ export class HarnessLogins {
230
279
  () => this.finish(login, { loginId, outcome: "succeeded" }),
231
280
  (error: unknown) => this.finish(login, { loginId, outcome: "failed", error: message(error) }),
232
281
  );
233
- return answer;
282
+ return login;
234
283
  }
235
284
 
236
285
  /**
@@ -264,13 +313,14 @@ export class HarnessLogins {
264
313
  /** Remove the CLI's own login: the harness's login after it. */
265
314
  async logout(harness: AgentHarness, env?: Record<string, string>): Promise<HarnessAuth> {
266
315
  await this.cliOf(harness).logout({ ...(env && { env }) });
267
- this.onChanged(harness);
268
- const { auth } = await this.reread(harness, env);
316
+ this.changed(harness, env);
317
+ const { auth: read } = await this.reread(harness, env);
318
+ const auth = this.withLogin(read, storeKey(harness, env));
269
319
  this.emit({ auth });
270
320
  return auth;
271
321
  }
272
322
 
273
- /** Every change of a harness's login, and every login's end. Returns the unsubscribe. */
323
+ /** Every change of a harness's login, and every login's start and end. Returns the unsubscribe. */
274
324
  onUpdated(listener: (update: AuthUpdated) => void): () => void {
275
325
  this.listeners.add(listener);
276
326
  return () => this.listeners.delete(listener);
@@ -304,13 +354,14 @@ export class HarnessLogins {
304
354
  const { harness } = login;
305
355
  const succeeded = end.outcome === "succeeded";
306
356
  // Before the read: a turn that starts meanwhile already runs a new CLI.
307
- if (succeeded) this.onChanged(harness);
357
+ if (succeeded) this.changed(harness, login.env);
308
358
  // Shutting down starts no CLI to read it.
309
359
  const { auth, differs }: Reading = this.stopped
310
360
  ? { auth: { harness, state: "unknown", methods: [] }, differs: false }
311
361
  : await this.reread(harness, login.env);
312
- if (differs && !succeeded) this.onChanged(harness);
313
- const update: AuthUpdated = { auth, login: end };
362
+ if (differs && !succeeded) this.changed(harness, login.env);
363
+ // Ended already, so it is no longer under way: a newer login that replaced it is.
364
+ const update: AuthUpdated = { auth: this.withLogin(auth, login.store), login: end };
314
365
  this.logins.delete(end.loginId);
315
366
  if (!this.stopped) this.emit(update);
316
367
  login.settle(update);
@@ -33,7 +33,7 @@ interface Read {
33
33
  }
34
34
 
35
35
  /** The catalog's models for a harness, as a list (`source: "catalog"`). */
36
- function catalogModelList(harness: AgentHarness, fetchedAt: number): ModelList {
36
+ export function catalogModelList(harness: AgentHarness, fetchedAt: number): ModelList {
37
37
  return {
38
38
  harness,
39
39
  models: CATALOG_MODELS.filter((model) => model.harness === harness),
@@ -10,7 +10,7 @@ import type { PermissionDecision, PermissionRequestHandler } from "../agents/bas
10
10
  * What a harness's request offers, and so who keeps an "always" answer: read
11
11
  * once from `PermissionRequestHandler`'s `options` and `always`.
12
12
  */
13
- export type PermissionAsk =
13
+ type PermissionAsk =
14
14
  /** The harness's own choices (a plan's approval: the mode to go on in). */
15
15
  | { kind: "own_options"; options: PermissionOption[] }
16
16
  /** The standard four; the engine keeps "always" as a standing rule for the tool. */
@@ -26,8 +26,9 @@ export type PermissionAsk =
26
26
  * standing answer covers. "Always" covers what the harness says it does,
27
27
  * never every call to the tool: one `npm test` must not approve every later
28
28
  * command, so a harness that keeps it itself, or cannot scope one, says so,
29
- * and the engine keeps no standing rule for its requests (only a harness
30
- * with no memory of its own, ACP, leaves the engine one).
29
+ * and the engine keeps no standing rule for its requests. A request no
30
+ * "always" is kept for at all (an ACP agent's, Codex's consent for an MCP
31
+ * tool call) leaves the engine one per tool.
31
32
  */
32
33
  export function permissionAsk(opts: Parameters<PermissionRequestHandler>[1]): PermissionAsk {
33
34
  if (opts?.options) return { kind: "own_options", options: opts.options };
@@ -32,7 +32,7 @@ interface Pending<A> {
32
32
  }
33
33
 
34
34
  /** What a broker writes to and how long a request may wait. */
35
- export interface BrokerTurn {
35
+ interface BrokerTurn {
36
36
  sessionId: string;
37
37
  turnId: string;
38
38
  emit(event: LifecycleEvent): Promise<void>;