@zvada/agent-server 0.3.21 → 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 (367) hide show
  1. package/CHANGELOG.md +332 -0
  2. package/README.md +2 -1
  3. package/dist/types/accounts/chatgpt.d.ts +1 -1
  4. package/dist/types/accounts/chatgpt.d.ts.map +1 -1
  5. package/dist/types/accounts/http.d.ts +2 -4
  6. package/dist/types/accounts/http.d.ts.map +1 -1
  7. package/dist/types/client/client.d.ts +37 -11
  8. package/dist/types/client/client.d.ts.map +1 -1
  9. package/dist/types/client/connection.d.ts +66 -13
  10. package/dist/types/client/connection.d.ts.map +1 -1
  11. package/dist/types/client/index.d.ts +1 -1
  12. package/dist/types/client/index.d.ts.map +1 -1
  13. package/dist/types/client/logins.d.ts +4 -3
  14. package/dist/types/client/logins.d.ts.map +1 -1
  15. package/dist/types/client/streams.d.ts +9 -3
  16. package/dist/types/client/streams.d.ts.map +1 -1
  17. package/dist/types/client/turns.d.ts +1 -1
  18. package/dist/types/client/turns.d.ts.map +1 -1
  19. package/dist/types/core/agents/acp/acp-agent.d.ts +34 -1
  20. package/dist/types/core/agents/acp/acp-agent.d.ts.map +1 -1
  21. package/dist/types/core/agents/acp/adapter.d.ts.map +1 -1
  22. package/dist/types/core/agents/acp/client.d.ts +12 -3
  23. package/dist/types/core/agents/acp/client.d.ts.map +1 -1
  24. package/dist/types/core/agents/acp/mappings.d.ts +8 -2
  25. package/dist/types/core/agents/acp/mappings.d.ts.map +1 -1
  26. package/dist/types/core/agents/base.d.ts +22 -8
  27. package/dist/types/core/agents/base.d.ts.map +1 -1
  28. package/dist/types/core/agents/claude-code/adapter.d.ts +7 -0
  29. package/dist/types/core/agents/claude-code/adapter.d.ts.map +1 -1
  30. package/dist/types/core/agents/claude-code/approvals.d.ts +4 -1
  31. package/dist/types/core/agents/claude-code/approvals.d.ts.map +1 -1
  32. package/dist/types/core/agents/claude-code/claude-agent.d.ts +16 -5
  33. package/dist/types/core/agents/claude-code/claude-agent.d.ts.map +1 -1
  34. package/dist/types/core/agents/claude-code/events.d.ts +9 -1
  35. package/dist/types/core/agents/claude-code/events.d.ts.map +1 -1
  36. package/dist/types/core/agents/claude-code/login.d.ts +4 -1
  37. package/dist/types/core/agents/claude-code/login.d.ts.map +1 -1
  38. package/dist/types/core/agents/claude-code/mcp.d.ts +21 -7
  39. package/dist/types/core/agents/claude-code/mcp.d.ts.map +1 -1
  40. package/dist/types/core/agents/claude-code/models.d.ts +5 -1
  41. package/dist/types/core/agents/claude-code/models.d.ts.map +1 -1
  42. package/dist/types/core/agents/claude-code/options.d.ts +10 -4
  43. package/dist/types/core/agents/claude-code/options.d.ts.map +1 -1
  44. package/dist/types/core/agents/claude-code/outcome.d.ts +3 -5
  45. package/dist/types/core/agents/claude-code/outcome.d.ts.map +1 -1
  46. package/dist/types/core/agents/claude-code/results.d.ts +16 -0
  47. package/dist/types/core/agents/claude-code/results.d.ts.map +1 -0
  48. package/dist/types/core/agents/claude-code/sdk-pair.d.ts +13 -0
  49. package/dist/types/core/agents/claude-code/sdk-pair.d.ts.map +1 -0
  50. package/dist/types/core/agents/claude-code/session.d.ts +50 -12
  51. package/dist/types/core/agents/claude-code/session.d.ts.map +1 -1
  52. package/dist/types/core/agents/claude-code/spend.d.ts +2 -1
  53. package/dist/types/core/agents/claude-code/spend.d.ts.map +1 -1
  54. package/dist/types/core/agents/claude-code/tools.d.ts +26 -3
  55. package/dist/types/core/agents/claude-code/tools.d.ts.map +1 -1
  56. package/dist/types/core/agents/codex-app-server/adapter.d.ts +2 -2
  57. package/dist/types/core/agents/codex-app-server/adapter.d.ts.map +1 -1
  58. package/dist/types/core/agents/codex-app-server/client.d.ts +21 -2
  59. package/dist/types/core/agents/codex-app-server/client.d.ts.map +1 -1
  60. package/dist/types/core/agents/codex-app-server/codex-agent.d.ts +61 -14
  61. package/dist/types/core/agents/codex-app-server/codex-agent.d.ts.map +1 -1
  62. package/dist/types/core/agents/codex-app-server/commands.d.ts +2 -2
  63. package/dist/types/core/agents/codex-app-server/commands.d.ts.map +1 -1
  64. package/dist/types/core/agents/codex-app-server/credentials.d.ts +5 -1
  65. package/dist/types/core/agents/codex-app-server/credentials.d.ts.map +1 -1
  66. package/dist/types/core/agents/codex-app-server/effort.d.ts +2 -1
  67. package/dist/types/core/agents/codex-app-server/effort.d.ts.map +1 -1
  68. package/dist/types/core/agents/codex-app-server/homes.d.ts +26 -5
  69. package/dist/types/core/agents/codex-app-server/homes.d.ts.map +1 -1
  70. package/dist/types/core/agents/codex-app-server/items.d.ts +27 -2
  71. package/dist/types/core/agents/codex-app-server/items.d.ts.map +1 -1
  72. package/dist/types/core/agents/codex-app-server/login.d.ts +4 -1
  73. package/dist/types/core/agents/codex-app-server/login.d.ts.map +1 -1
  74. package/dist/types/core/agents/codex-app-server/mcp.d.ts +45 -20
  75. package/dist/types/core/agents/codex-app-server/mcp.d.ts.map +1 -1
  76. package/dist/types/core/agents/codex-app-server/models.d.ts +3 -10
  77. package/dist/types/core/agents/codex-app-server/models.d.ts.map +1 -1
  78. package/dist/types/core/agents/codex-app-server/options.d.ts +32 -5
  79. package/dist/types/core/agents/codex-app-server/options.d.ts.map +1 -1
  80. package/dist/types/core/agents/codex-app-server/plan-approval.d.ts +2 -1
  81. package/dist/types/core/agents/codex-app-server/plan-approval.d.ts.map +1 -1
  82. package/dist/types/core/agents/codex-app-server/protocol.d.ts +16 -3
  83. package/dist/types/core/agents/codex-app-server/protocol.d.ts.map +1 -1
  84. package/dist/types/core/agents/codex-app-server/requests.d.ts.map +1 -1
  85. package/dist/types/core/agents/codex-app-server/session.d.ts +70 -33
  86. package/dist/types/core/agents/codex-app-server/session.d.ts.map +1 -1
  87. package/dist/types/core/agents/codex-app-server/subagents.d.ts +9 -4
  88. package/dist/types/core/agents/codex-app-server/subagents.d.ts.map +1 -1
  89. package/dist/types/core/agents/codex-app-server/thread-settings.d.ts +3 -2
  90. package/dist/types/core/agents/codex-app-server/thread-settings.d.ts.map +1 -1
  91. package/dist/types/core/agents/codex-app-server/turn-items.d.ts +2 -1
  92. package/dist/types/core/agents/codex-app-server/turn-items.d.ts.map +1 -1
  93. package/dist/types/core/agents/codex-app-server/turn.d.ts +37 -8
  94. package/dist/types/core/agents/codex-app-server/turn.d.ts.map +1 -1
  95. package/dist/types/core/agents/codex-app-server/user-login.d.ts +28 -0
  96. package/dist/types/core/agents/codex-app-server/user-login.d.ts.map +1 -0
  97. package/dist/types/core/agents/credentials.d.ts +3 -1
  98. package/dist/types/core/agents/credentials.d.ts.map +1 -1
  99. package/dist/types/core/agents/diffs.d.ts +9 -0
  100. package/dist/types/core/agents/diffs.d.ts.map +1 -0
  101. package/dist/types/core/agents/elicitation.d.ts +3 -2
  102. package/dist/types/core/agents/elicitation.d.ts.map +1 -1
  103. package/dist/types/core/agents/login.d.ts +6 -0
  104. package/dist/types/core/agents/login.d.ts.map +1 -1
  105. package/dist/types/core/agents/mcp-config.d.ts +0 -4
  106. package/dist/types/core/agents/mcp-config.d.ts.map +1 -1
  107. package/dist/types/core/agents/plan.d.ts +2 -13
  108. package/dist/types/core/agents/plan.d.ts.map +1 -1
  109. package/dist/types/core/agents/process-pool.d.ts +193 -0
  110. package/dist/types/core/agents/process-pool.d.ts.map +1 -0
  111. package/dist/types/core/agents/scripted/adapter.d.ts +68 -0
  112. package/dist/types/core/agents/scripted/adapter.d.ts.map +1 -0
  113. package/dist/types/core/agents/scripted/mcp-call.d.ts +56 -0
  114. package/dist/types/core/agents/scripted/mcp-call.d.ts.map +1 -0
  115. package/dist/types/core/agents/scripted/scripted-agent.d.ts +73 -0
  116. package/dist/types/core/agents/scripted/scripted-agent.d.ts.map +1 -0
  117. package/dist/types/core/agents/scripted/scripts.d.ts +29 -0
  118. package/dist/types/core/agents/scripted/scripts.d.ts.map +1 -0
  119. package/dist/types/core/agents/scripted/steps.d.ts +132 -0
  120. package/dist/types/core/agents/scripted/steps.d.ts.map +1 -0
  121. package/dist/types/core/agents/session-agent.d.ts +49 -6
  122. package/dist/types/core/agents/session-agent.d.ts.map +1 -1
  123. package/dist/types/core/diagnostics.d.ts +4 -1
  124. package/dist/types/core/diagnostics.d.ts.map +1 -1
  125. package/dist/types/core/index.d.ts +6 -1
  126. package/dist/types/core/index.d.ts.map +1 -1
  127. package/dist/types/core/presets.d.ts +32 -6
  128. package/dist/types/core/presets.d.ts.map +1 -1
  129. package/dist/types/core/processes/lifeline.d.ts +0 -20
  130. package/dist/types/core/processes/lifeline.d.ts.map +1 -1
  131. package/dist/types/core/provision/index.d.ts +2 -2
  132. package/dist/types/core/provision/index.d.ts.map +1 -1
  133. package/dist/types/core/provision/install-build.d.ts +2 -1
  134. package/dist/types/core/provision/install-build.d.ts.map +1 -1
  135. package/dist/types/core/provision/npm.d.ts +20 -8
  136. package/dist/types/core/provision/npm.d.ts.map +1 -1
  137. package/dist/types/core/provision/provisioner.d.ts +4 -1
  138. package/dist/types/core/provision/provisioner.d.ts.map +1 -1
  139. package/dist/types/core/provision/tools.d.ts +2 -1
  140. package/dist/types/core/provision/tools.d.ts.map +1 -1
  141. package/dist/types/core/runtime/agent-runtime.d.ts +18 -9
  142. package/dist/types/core/runtime/agent-runtime.d.ts.map +1 -1
  143. package/dist/types/core/runtime/event-processor.d.ts +5 -1
  144. package/dist/types/core/runtime/event-processor.d.ts.map +1 -1
  145. package/dist/types/core/runtime/harness-clis.d.ts +9 -0
  146. package/dist/types/core/runtime/harness-clis.d.ts.map +1 -1
  147. package/dist/types/core/runtime/harness-logins.d.ts +33 -5
  148. package/dist/types/core/runtime/harness-logins.d.ts.map +1 -1
  149. package/dist/types/core/runtime/model-lists.d.ts +2 -0
  150. package/dist/types/core/runtime/model-lists.d.ts.map +1 -1
  151. package/dist/types/core/runtime/permission-policy.d.ts +5 -3
  152. package/dist/types/core/runtime/permission-policy.d.ts.map +1 -1
  153. package/dist/types/core/runtime/request-broker.d.ts +2 -1
  154. package/dist/types/core/runtime/request-broker.d.ts.map +1 -1
  155. package/dist/types/core/runtime/turn.d.ts +14 -1
  156. package/dist/types/core/runtime/turn.d.ts.map +1 -1
  157. package/dist/types/core/utils/deadline.d.ts +6 -0
  158. package/dist/types/core/utils/deadline.d.ts.map +1 -1
  159. package/dist/types/core/utils/errors.d.ts +15 -1
  160. package/dist/types/core/utils/errors.d.ts.map +1 -1
  161. package/dist/types/operator/index.d.ts +11 -0
  162. package/dist/types/operator/index.d.ts.map +1 -0
  163. package/dist/types/operator/mcp.d.ts +33 -0
  164. package/dist/types/operator/mcp.d.ts.map +1 -0
  165. package/dist/types/operator/operator.d.ts +206 -0
  166. package/dist/types/operator/operator.d.ts.map +1 -0
  167. package/dist/types/operator/render.d.ts +89 -0
  168. package/dist/types/operator/render.d.ts.map +1 -0
  169. package/dist/types/operator/view.d.ts +44 -0
  170. package/dist/types/operator/view.d.ts.map +1 -0
  171. package/dist/types/protocol/auth.d.ts +54 -24
  172. package/dist/types/protocol/auth.d.ts.map +1 -1
  173. package/dist/types/protocol/clis.d.ts +14 -7
  174. package/dist/types/protocol/clis.d.ts.map +1 -1
  175. package/dist/types/protocol/config.d.ts +2 -0
  176. package/dist/types/protocol/config.d.ts.map +1 -1
  177. package/dist/types/protocol/conversation.d.ts +40 -3
  178. package/dist/types/protocol/conversation.d.ts.map +1 -1
  179. package/dist/types/protocol/credentials.d.ts +7 -0
  180. package/dist/types/protocol/credentials.d.ts.map +1 -1
  181. package/dist/types/protocol/execution.d.ts +2 -1
  182. package/dist/types/protocol/execution.d.ts.map +1 -1
  183. package/dist/types/protocol/factories.d.ts +12 -2
  184. package/dist/types/protocol/factories.d.ts.map +1 -1
  185. package/dist/types/protocol/harness.d.ts +6 -2
  186. package/dist/types/protocol/harness.d.ts.map +1 -1
  187. package/dist/types/protocol/history.d.ts +19 -0
  188. package/dist/types/protocol/history.d.ts.map +1 -1
  189. package/dist/types/protocol/lifecycle.d.ts +47 -8
  190. package/dist/types/protocol/lifecycle.d.ts.map +1 -1
  191. package/dist/types/protocol/model-catalog.d.ts.map +1 -1
  192. package/dist/types/protocol/models.d.ts +3 -0
  193. package/dist/types/protocol/models.d.ts.map +1 -1
  194. package/dist/types/protocol/parts.d.ts +14 -0
  195. package/dist/types/protocol/parts.d.ts.map +1 -1
  196. package/dist/types/protocol/plan.d.ts +20 -0
  197. package/dist/types/protocol/plan.d.ts.map +1 -0
  198. package/dist/types/protocol/tool-state.d.ts +12 -0
  199. package/dist/types/protocol/tool-state.d.ts.map +1 -1
  200. package/dist/types/protocol/wire-api.d.ts +129 -23
  201. package/dist/types/protocol/wire-api.d.ts.map +1 -1
  202. package/dist/types/protocol/wire.d.ts +70 -10
  203. package/dist/types/protocol/wire.d.ts.map +1 -1
  204. package/dist/types/server/acp/binding.d.ts +6 -1
  205. package/dist/types/server/acp/binding.d.ts.map +1 -1
  206. package/dist/types/server/acp/translate.d.ts +33 -7
  207. package/dist/types/server/acp/translate.d.ts.map +1 -1
  208. package/dist/types/server/agent-server.d.ts +6 -0
  209. package/dist/types/server/agent-server.d.ts.map +1 -1
  210. package/dist/types/server/feedback.d.ts +2 -1
  211. package/dist/types/server/feedback.d.ts.map +1 -1
  212. package/dist/types/server/install.d.ts +11 -0
  213. package/dist/types/server/install.d.ts.map +1 -1
  214. package/dist/types/server/session-gate.d.ts +2 -1
  215. package/dist/types/server/session-gate.d.ts.map +1 -1
  216. package/dist/types/server/session-store.d.ts +1 -0
  217. package/dist/types/server/session-store.d.ts.map +1 -1
  218. package/dist/types/server/subscriptions.d.ts +2 -1
  219. package/dist/types/server/subscriptions.d.ts.map +1 -1
  220. package/dist/types/server/transports.d.ts.map +1 -1
  221. package/dist/types/sync/fit.d.ts +8 -7
  222. package/dist/types/sync/fit.d.ts.map +1 -1
  223. package/dist/types/sync/history-sqlite.d.ts.map +1 -1
  224. package/dist/types/sync/index.d.ts +1 -0
  225. package/dist/types/sync/index.d.ts.map +1 -1
  226. package/dist/types/sync/journal-sqlite.d.ts +2 -1
  227. package/dist/types/sync/journal-sqlite.d.ts.map +1 -1
  228. package/dist/types/sync/journal.d.ts +11 -3
  229. package/dist/types/sync/journal.d.ts.map +1 -1
  230. package/dist/types/sync/projection.d.ts +6 -0
  231. package/dist/types/sync/projection.d.ts.map +1 -1
  232. package/dist/types/sync/recovery.d.ts +2 -1
  233. package/dist/types/sync/recovery.d.ts.map +1 -1
  234. package/dist/types/sync/schema.d.ts +10 -0
  235. package/dist/types/sync/schema.d.ts.map +1 -1
  236. package/dist/types/sync/sql.d.ts +2 -1
  237. package/dist/types/sync/sql.d.ts.map +1 -1
  238. package/dist/types/sync/worker.d.ts.map +1 -1
  239. package/docs/consuming.md +464 -40
  240. package/docs/deploy.md +36 -8
  241. package/docs/durable-sessions.md +35 -5
  242. package/docs/harnesses.md +396 -30
  243. package/package.json +11 -1
  244. package/src/accounts/chatgpt.ts +2 -2
  245. package/src/accounts/http.ts +2 -16
  246. package/src/client/client.ts +92 -31
  247. package/src/client/connection.ts +113 -22
  248. package/src/client/index.ts +1 -0
  249. package/src/client/logins.ts +24 -15
  250. package/src/client/streams.ts +12 -4
  251. package/src/client/turns.ts +1 -1
  252. package/src/core/agents/acp/acp-agent.ts +181 -52
  253. package/src/core/agents/acp/adapter.ts +9 -1
  254. package/src/core/agents/acp/client.ts +16 -4
  255. package/src/core/agents/acp/mappings.ts +27 -0
  256. package/src/core/agents/base.ts +25 -10
  257. package/src/core/agents/claude-code/adapter.ts +47 -17
  258. package/src/core/agents/claude-code/approvals.ts +6 -5
  259. package/src/core/agents/claude-code/claude-agent.ts +60 -30
  260. package/src/core/agents/claude-code/events.ts +11 -1
  261. package/src/core/agents/claude-code/login.ts +14 -2
  262. package/src/core/agents/claude-code/mcp.ts +31 -15
  263. package/src/core/agents/claude-code/models.ts +7 -2
  264. package/src/core/agents/claude-code/options.ts +11 -3
  265. package/src/core/agents/claude-code/outcome.ts +10 -2
  266. package/src/core/agents/claude-code/results.ts +73 -0
  267. package/src/core/agents/claude-code/sdk-pair.ts +66 -0
  268. package/src/core/agents/claude-code/session.ts +166 -37
  269. package/src/core/agents/claude-code/spend.ts +1 -1
  270. package/src/core/agents/claude-code/tools.ts +108 -12
  271. package/src/core/agents/codex-app-server/adapter.ts +37 -12
  272. package/src/core/agents/codex-app-server/client.ts +69 -10
  273. package/src/core/agents/codex-app-server/codex-agent.ts +141 -55
  274. package/src/core/agents/codex-app-server/commands.ts +2 -2
  275. package/src/core/agents/codex-app-server/credentials.ts +10 -5
  276. package/src/core/agents/codex-app-server/effort.ts +1 -1
  277. package/src/core/agents/codex-app-server/homes.ts +59 -10
  278. package/src/core/agents/codex-app-server/items.ts +219 -31
  279. package/src/core/agents/codex-app-server/login.ts +14 -2
  280. package/src/core/agents/codex-app-server/mcp.ts +142 -26
  281. package/src/core/agents/codex-app-server/models.ts +9 -8
  282. package/src/core/agents/codex-app-server/options.ts +79 -11
  283. package/src/core/agents/codex-app-server/plan-approval.ts +1 -1
  284. package/src/core/agents/codex-app-server/protocol.ts +14 -4
  285. package/src/core/agents/codex-app-server/requests.ts +14 -6
  286. package/src/core/agents/codex-app-server/session.ts +156 -81
  287. package/src/core/agents/codex-app-server/subagents.ts +21 -14
  288. package/src/core/agents/codex-app-server/thread-settings.ts +18 -8
  289. package/src/core/agents/codex-app-server/turn-items.ts +1 -1
  290. package/src/core/agents/codex-app-server/turn.ts +96 -35
  291. package/src/core/agents/codex-app-server/user-login.ts +107 -0
  292. package/src/core/agents/credentials.ts +5 -2
  293. package/src/core/agents/diffs.ts +25 -0
  294. package/src/core/agents/elicitation.ts +2 -2
  295. package/src/core/agents/login.ts +6 -0
  296. package/src/core/agents/mcp-config.ts +2 -2
  297. package/src/core/agents/plan.ts +3 -19
  298. package/src/core/agents/process-pool.ts +432 -0
  299. package/src/core/agents/scripted/adapter.ts +142 -0
  300. package/src/core/agents/scripted/mcp-call.ts +134 -0
  301. package/src/core/agents/scripted/scripted-agent.ts +418 -0
  302. package/src/core/agents/scripted/scripts.ts +171 -0
  303. package/src/core/agents/scripted/steps.ts +127 -0
  304. package/src/core/agents/session-agent.ts +105 -8
  305. package/src/core/diagnostics.ts +9 -1
  306. package/src/core/index.ts +12 -0
  307. package/src/core/presets.ts +99 -14
  308. package/src/core/processes/lifeline.ts +99 -25
  309. package/src/core/provision/index.ts +1 -2
  310. package/src/core/provision/install-build.ts +4 -1
  311. package/src/core/provision/npm.ts +309 -97
  312. package/src/core/provision/provisioner.ts +22 -8
  313. package/src/core/provision/tools.ts +44 -19
  314. package/src/core/runtime/agent-runtime.ts +70 -34
  315. package/src/core/runtime/event-processor.ts +18 -2
  316. package/src/core/runtime/harness-clis.ts +36 -1
  317. package/src/core/runtime/harness-logins.ts +82 -31
  318. package/src/core/runtime/model-lists.ts +1 -1
  319. package/src/core/runtime/permission-policy.ts +4 -3
  320. package/src/core/runtime/request-broker.ts +1 -1
  321. package/src/core/runtime/turn.ts +53 -3
  322. package/src/core/utils/deadline.ts +23 -0
  323. package/src/core/utils/errors.ts +24 -4
  324. package/src/operator/index.ts +40 -0
  325. package/src/operator/mcp.ts +171 -0
  326. package/src/operator/operator.ts +782 -0
  327. package/src/operator/render.ts +473 -0
  328. package/src/operator/view.ts +82 -0
  329. package/src/protocol/auth.ts +30 -23
  330. package/src/protocol/clis.ts +12 -4
  331. package/src/protocol/credentials.ts +19 -0
  332. package/src/protocol/execution.ts +5 -0
  333. package/src/protocol/factories.ts +25 -3
  334. package/src/protocol/harness.ts +11 -1
  335. package/src/protocol/history.ts +20 -0
  336. package/src/protocol/lifecycle.ts +10 -1
  337. package/src/protocol/model-catalog.ts +19 -8
  338. package/src/protocol/parts.ts +12 -1
  339. package/src/protocol/plan.ts +35 -0
  340. package/src/protocol/tool-state.ts +14 -1
  341. package/src/protocol/wire.ts +14 -0
  342. package/src/server/acp/binding.ts +113 -22
  343. package/src/server/acp/translate.ts +161 -8
  344. package/src/server/agent-server.ts +10 -1
  345. package/src/server/bin.ts +83 -9
  346. package/src/server/feedback.ts +1 -1
  347. package/src/server/install.ts +82 -4
  348. package/src/server/session-gate.ts +1 -1
  349. package/src/server/session-store.ts +5 -1
  350. package/src/server/subscriptions.ts +1 -1
  351. package/src/server/transports.ts +14 -0
  352. package/src/sync/fit.ts +115 -28
  353. package/src/sync/history-sqlite.ts +6 -2
  354. package/src/sync/index.ts +1 -0
  355. package/src/sync/journal-sqlite.ts +20 -2
  356. package/src/sync/journal.ts +10 -2
  357. package/src/sync/projection.ts +10 -0
  358. package/src/sync/recovery.ts +11 -4
  359. package/src/sync/schema.ts +7 -5
  360. package/src/sync/sql.ts +1 -1
  361. package/src/sync/worker.ts +4 -0
  362. package/dist/types/core/agents/claude-code/session-pool.d.ts +0 -36
  363. package/dist/types/core/agents/claude-code/session-pool.d.ts.map +0 -1
  364. package/dist/types/core/agents/session-pool.d.ts +0 -41
  365. package/dist/types/core/agents/session-pool.d.ts.map +0 -1
  366. package/src/core/agents/claude-code/session-pool.ts +0 -136
  367. package/src/core/agents/session-pool.ts +0 -111
@@ -1,6 +1,12 @@
1
1
  import type {
2
2
  ToolKind as AcpToolKind,
3
3
  ContentBlock,
4
+ CreateElicitationRequest,
5
+ CreateElicitationResponse,
6
+ ElicitationCapabilities,
7
+ ElicitationPropertySchema,
8
+ ElicitationSchema,
9
+ EnumOption,
4
10
  McpServer,
5
11
  PermissionOption,
6
12
  PermissionOptionKind,
@@ -8,9 +14,13 @@ import type {
8
14
  RequestPermissionRequest,
9
15
  SessionUpdate,
10
16
  StopReason,
17
+ ToolCallContent,
11
18
  } from "@agentclientprotocol/sdk";
12
19
  import type { RunSummary } from "../../core/index.ts";
13
20
  import {
21
+ type ElicitationOutcome,
22
+ type ElicitationQuestion,
23
+ type ElicitationRequestedEvent,
14
24
  type LifecycleEvent,
15
25
  META_KEYS,
16
26
  type McpServerConfig,
@@ -19,6 +29,7 @@ import {
19
29
  type TokenUsage,
20
30
  type ToolKind,
21
31
  type ToolPart,
32
+ type ToolResultContent,
22
33
  } from "../../protocol/index.ts";
23
34
 
24
35
  /** ACP v1's ToolKind set: ours without `task` and the extensions. */
@@ -64,7 +75,7 @@ function isAcpOption(option: { kind: string }): option is PermissionOption {
64
75
  }
65
76
 
66
77
  /** The engine's disjoint token buckets as ACP's (still unstable) turn usage. */
67
- export function toAcpUsage(usage: TokenUsage): NonNullable<PromptResponse["usage"]> {
78
+ function toAcpUsage(usage: TokenUsage): NonNullable<PromptResponse["usage"]> {
68
79
  const read = usage.cache?.read ?? 0;
69
80
  const write = usage.cache?.write ?? 0;
70
81
  return {
@@ -104,7 +115,9 @@ export function toAcpPromptResponse(
104
115
  /**
105
116
  * A brokered permission request as ACP's `session/request_permission`: the
106
117
  * option vocabulary is ACP's, so the options pass through (one of a kind ACP
107
- * cannot carry is not offered, never read as an approval).
118
+ * cannot carry is not offered, never read as an approval). The call's name
119
+ * and locations ride ACP's own fields; its command, address, reason and MCP
120
+ * identity have none.
108
121
  */
109
122
  export function toAcpPermissionRequest(
110
123
  sessionId: string,
@@ -116,14 +129,108 @@ export function toAcpPermissionRequest(
116
129
  toolCall: {
117
130
  toolCallId: call?.toolCallId ?? event.requestId,
118
131
  title: event.title,
132
+ ...(call && { name: call.toolName }),
119
133
  status: "pending",
120
134
  ...(call?.kind && { kind: toAcpToolKind(call.kind) }),
135
+ ...(call?.locations?.length && { locations: call.locations }),
121
136
  ...(call?.rawInput && { rawInput: call.rawInput }),
122
137
  },
123
138
  options: event.options.filter(isAcpOption),
124
139
  };
125
140
  }
126
141
 
142
+ // @ref LLP 0001#d12--what-the-agent-asks-the-user-is-first-class-protocol-opted-into-per-turn — a question reaches an ACP client as a form
143
+ /**
144
+ * A request for the person's input as ACP's `elicitation/create`, or
145
+ * `undefined` when the client cannot take it. ACP v1 has a form and a URL
146
+ * mode and no question mode, so the agent's own questions are a form, one
147
+ * required field per question: its choices a single or multiple select, a
148
+ * free answer (or one beside the choices) a string. ACP has no masked
149
+ * field, so a `secret` question is an ordinary one.
150
+ */
151
+ export function toAcpElicitation(
152
+ sessionId: string,
153
+ event: ElicitationRequestedEvent,
154
+ client: ElicitationCapabilities | null | undefined,
155
+ ): CreateElicitationRequest | undefined {
156
+ const scope = {
157
+ sessionId,
158
+ ...(event.toolCallId && { toolCallId: event.toolCallId }),
159
+ message: event.message,
160
+ };
161
+ if (event.mode === "question" && client?.form && event.questions?.length)
162
+ return {
163
+ ...scope,
164
+ mode: "form",
165
+ requestedSchema: {
166
+ type: "object",
167
+ properties: Object.fromEntries(event.questions.map((q) => [q.id, questionField(q)])),
168
+ required: event.questions.map((q) => q.id),
169
+ },
170
+ };
171
+ if (event.mode === "form" && client?.form && event.requestedSchema)
172
+ return {
173
+ ...scope,
174
+ mode: "form",
175
+ // An MCP server's schema, which ACP's form mode takes as MCP defines it.
176
+ requestedSchema: event.requestedSchema as ElicitationSchema,
177
+ };
178
+ if (event.mode === "url" && client?.url && event.url && event.elicitationId)
179
+ return { ...scope, mode: "url", url: event.url, elicitationId: event.elicitationId };
180
+ return undefined;
181
+ }
182
+
183
+ /** One question as a form field. */
184
+ function questionField(question: ElicitationQuestion): ElicitationPropertySchema {
185
+ const label = {
186
+ title: question.header ?? question.question,
187
+ ...(question.header && { description: question.question }),
188
+ };
189
+ const choices = question.options?.map(
190
+ (option): EnumOption => ({
191
+ const: option.label,
192
+ title: option.label,
193
+ ...(option.description && { description: option.description }),
194
+ }),
195
+ );
196
+ // Words of the person's own beside the choices: a string, the choices named.
197
+ if (!choices?.length || question.allowOther)
198
+ return {
199
+ type: "string",
200
+ ...label,
201
+ ...(choices?.length && {
202
+ description: `${question.question} (${choices.map((c) => c.const).join(", ")}, or your own words)`,
203
+ }),
204
+ };
205
+ if (question.multiSelect) return { type: "array", ...label, items: { anyOf: choices } };
206
+ return { type: "string", ...label, oneOf: choices };
207
+ }
208
+
209
+ /**
210
+ * The client's answer as the engine's outcome: a question's answers are each
211
+ * an array (a form's single value becomes one), a form's content passes as
212
+ * it is, and an action ACP may add later is a cancel.
213
+ */
214
+ export function fromAcpElicitation(
215
+ event: ElicitationRequestedEvent,
216
+ response: CreateElicitationResponse,
217
+ ): ElicitationOutcome {
218
+ if (response.action === "decline") return { action: "decline" };
219
+ if (response.action !== "accept") return { action: "cancel" };
220
+ const content = (response as { content?: Record<string, unknown> | null }).content;
221
+ if (!content) return { action: "accept" };
222
+ if (event.mode !== "question") return { action: "accept", content };
223
+ return {
224
+ action: "accept",
225
+ content: Object.fromEntries(
226
+ Object.entries(content).map(([id, value]) => [
227
+ id,
228
+ Array.isArray(value) ? value.map(String) : [String(value)],
229
+ ]),
230
+ ),
231
+ };
232
+ }
233
+
127
234
  /**
128
235
  * Per-prompt translator from the engine's LifecycleEvents to ACP v1
129
236
  * `session/update` payloads — the exact inverse of the acp harness adapter
@@ -256,18 +363,43 @@ export class AcpUpdateTranslator {
256
363
  : part.state.status === "completed"
257
364
  ? part.state.output
258
365
  : undefined;
366
+ const content: ToolCallContent[] = [
367
+ ...(output
368
+ ? [{ type: "content" as const, content: { type: "text" as const, text: output } }]
369
+ : []),
370
+ ...toAcpDiffs(part.state.status === "completed" ? part.state.content : undefined),
371
+ ];
259
372
  updates.push({
260
373
  sessionUpdate: "tool_call_update",
261
374
  toolCallId: part.toolCallId,
262
375
  status,
263
- ...(output && {
264
- content: [{ type: "content", content: { type: "text", text: output } }],
265
- }),
376
+ ...(content.length && { content }),
266
377
  });
267
378
  return updates;
268
379
  }
269
380
  }
270
381
 
382
+ // @ref LLP 0002#tool-output-has-three-audiences — a part's diffs reach an ACP client as ACP diffs
383
+ /**
384
+ * A part's `diff` entries as ACP's, which a client draws. A `terminal`
385
+ * names a terminal of the agent's, which no client of ours can show, so it
386
+ * is not sent; text is the part's output.
387
+ */
388
+ function toAcpDiffs(content: ToolResultContent[] | undefined): ToolCallContent[] {
389
+ return (content ?? []).flatMap((item): ToolCallContent[] =>
390
+ item.type === "diff"
391
+ ? [
392
+ {
393
+ type: "diff",
394
+ path: item.path,
395
+ ...(item.oldText !== undefined && { oldText: item.oldText }),
396
+ newText: item.newText,
397
+ },
398
+ ]
399
+ : [],
400
+ );
401
+ }
402
+
271
403
  function chunk(
272
404
  kind: "agent_message_chunk" | "agent_thought_chunk",
273
405
  text: string,
@@ -276,11 +408,21 @@ function chunk(
276
408
  return { sessionUpdate: kind, content: { type: "text", text }, messageId };
277
409
  }
278
410
 
279
- /** ACP prompt content → engine input (text + base64 images; the rest is dropped). */
411
+ /**
412
+ * ACP prompt content → engine input: text, base64 images, and a resource
413
+ * link as a Markdown link in the text, which ACP v1 has every agent take (a
414
+ * client's @-mention of a file) and any harness's agent can follow. Audio
415
+ * and embedded resources, which the binding does not advertise, are dropped.
416
+ */
280
417
  export function fromPromptBlocks(prompt: ContentBlock[]): string | PartInput[] {
281
418
  const parts: PartInput[] = [];
282
419
  for (const block of prompt) {
283
420
  if (block.type === "text" && block.text) parts.push({ type: "text", text: block.text });
421
+ else if (block.type === "resource_link")
422
+ parts.push({
423
+ type: "text",
424
+ text: block.name && block.name !== block.uri ? `[${block.name}](${block.uri})` : block.uri,
425
+ });
284
426
  else if (block.type === "image" && block.data) {
285
427
  parts.push({ type: "image", data: block.data, mimeType: block.mimeType });
286
428
  }
@@ -289,13 +431,18 @@ export function fromPromptBlocks(prompt: ContentBlock[]): string | PartInput[] {
289
431
  return parts.length ? parts : "";
290
432
  }
291
433
 
292
- /** ACP `McpServer[]` → engine MCP config map (inverse of the harness-side mapping). */
434
+ /**
435
+ * ACP `McpServer[]` → engine MCP config map (inverse of the harness-side
436
+ * mapping). A server of another transport throws, naming it: ACP v1 lets a
437
+ * client send one only to an agent that advertised it, says nothing of what
438
+ * an agent does with one it did not, and a session without a server it
439
+ * asked for must not run as if it had it.
440
+ */
293
441
  export function fromAcpMcpServers(
294
442
  servers: McpServer[] | undefined,
295
443
  ): Record<string, McpServerConfig> | undefined {
296
444
  if (!servers?.length) return undefined;
297
445
  const out: Record<string, McpServerConfig> = {};
298
- // Note: the SDK's `type: "acp"` nested-agent variant is silently dropped.
299
446
  for (const server of servers) {
300
447
  if ("command" in server) {
301
448
  out[server.name] = {
@@ -310,6 +457,12 @@ export function fromAcpMcpServers(
310
457
  url: server.url,
311
458
  headers: Object.fromEntries((server.headers ?? []).map((h) => [h.name, h.value])),
312
459
  };
460
+ } else {
461
+ // The SDK's `acp` transport (MCP over the ACP channel, unstable) or one newer still.
462
+ const transport = (server as { type?: unknown }).type;
463
+ throw new Error(
464
+ `MCP server "${server.name}" uses the ${String(transport)} transport, which agent-server cannot attach (it takes stdio, http and sse)`,
465
+ );
313
466
  }
314
467
  }
315
468
  return Object.keys(out).length ? out : undefined;
@@ -134,7 +134,7 @@ export class AgentServer {
134
134
  this.store = journal ?? new MemorySessionStore(options.bufferSize);
135
135
  this.subscriptions = new Subscriptions({
136
136
  maxSubscriptions: options.maxSubscriptions ?? DEFAULT_MAX_SUBSCRIPTIONS,
137
- maxBacklogBytes: options.maxBacklogBytes ?? DEFAULT_MAX_BACKLOG_BYTES,
137
+ maxBacklogBytes: this.maxBacklogBytes,
138
138
  });
139
139
  // Each native process a session's turn starts is in the journal before it gets work.
140
140
  this.unrecord = journal
@@ -179,6 +179,15 @@ export class AgentServer {
179
179
  };
180
180
  }
181
181
 
182
+ /**
183
+ * How far behind a connection may fall before it is sent `session/overflow`
184
+ * (`AgentServerOptions.maxBacklogBytes`): `listen` keeps its socket's own
185
+ * limit above it, so the notice is never the frame the socket drops.
186
+ */
187
+ get maxBacklogBytes(): number {
188
+ return this.options.maxBacklogBytes ?? DEFAULT_MAX_BACKLOG_BYTES;
189
+ }
190
+
182
191
  /** Serve the wire on a transport; returns a detach function, which drops its subscriptions. */
183
192
  attach(transport: WireTransport): () => void {
184
193
  this.subscriptions.attach(transport);
package/src/server/bin.ts CHANGED
@@ -8,7 +8,10 @@
8
8
  // # (with $AGENT_SERVER_DIAL_TOKEN as its bearer token)
9
9
  // agent-server --harness a,b # restrict registered harnesses
10
10
  // agent-server --acp-agent "npx -y pi-acp" # enable the acp harness
11
+ // agent-server --script turns.jsonl # the scripted harness plays this script
12
+ // agent-server --script turns.jsonl --script-position at.json # and goes on after a restart
11
13
  // agent-server --acp --harness claude-code # BE an ACP agent on stdio (for Zed etc.)
14
+ // agent-server --acp --harness codex-app-server --model gpt-6-luna --thinking low
12
15
  // agent-server --buffer 8192 # replay buffer size per session
13
16
  // agent-server --inherit-config none # a turn loads no ambient settings, MCP, hooks, memory
14
17
  // agent-server install # prefetch the pinned agent CLIs
@@ -22,15 +25,18 @@ import {
22
25
  type CredentialSource,
23
26
  type InheritConfig,
24
27
  type ProvisionMode,
28
+ type ScriptSource,
25
29
  createAgentRuntime,
26
30
  credentialsFromUrl,
27
31
  isInheritConfig,
28
32
  resolveAcpLaunch,
29
33
  resolveHarnessName,
34
+ scriptedFile,
30
35
  } from "../core/index.ts";
36
+ import { THINKING_LEVELS, type ThinkingLevel, isThinkingLevel } from "../protocol/index.ts";
31
37
  import { AgentServer } from "./agent-server.ts";
32
38
  import { runFeedbackCommand } from "./feedback.ts";
33
- import { runInstall } from "./install.ts";
39
+ import { installedLine, nothingToInstall, runInstall, toolsFor } from "./install.ts";
34
40
  import { takeSecrets } from "./secrets.ts";
35
41
  import {
36
42
  type ListenOptions,
@@ -55,10 +61,17 @@ interface Args {
55
61
  dialUrl?: string;
56
62
  harnesses?: string[];
57
63
  acpAgent?: string;
64
+ /** --script: the JSONL file the scripted harness plays. */
65
+ script?: string;
66
+ /** --script-position: where the script's position is kept across restarts. */
67
+ scriptPosition?: string;
58
68
  bufferSize?: number;
59
69
  journalPath?: string;
60
70
  provisionMode?: ProvisionMode;
61
71
  inheritConfig?: InheritConfig;
72
+ /** --acp: the model and thinking level of every turn, the operator's alone. */
73
+ model?: string;
74
+ thinking?: ThinkingLevel;
62
75
  /** A product's credential endpoint, asked before each turn (LLP 0012). */
63
76
  credentialsUrl?: string;
64
77
  /** install: the platforms to stage, the folder to stage them into, and whether to prune. */
@@ -74,6 +87,9 @@ function usage(exitCode: number): never {
74
87
  "",
75
88
  " --stdio serve NDJSON JSON-RPC on stdio (the default)",
76
89
  " --acp speak ACP v1 on stdio instead (be the agent)",
90
+ " --model <id> every turn runs on this model (default: the harness's own)",
91
+ ` --thinking <level> and at this thinking level (${THINKING_LEVELS.join(", ")});`,
92
+ " the operator's choice: an ACP client cannot change either",
77
93
  " install download the pinned agent CLIs into the managed cache",
78
94
  " (always downloads — run at image build time to erase",
79
95
  " sandbox cold starts; --provision applies to serving only)",
@@ -95,6 +111,11 @@ function usage(exitCode: number): never {
95
111
  " $AGENT_SERVER_DIAL_TOKEN, never argv or the URL",
96
112
  " --harness <a,b> restrict harnesses (default: all installed)",
97
113
  " --acp-agent <spec> ACP agent: known name (pi|gemini) or launch command",
114
+ " --script <file> the scripted harness plays this JSONL script, one step a",
115
+ " line (its only harness unless --harness names others);",
116
+ " one turn plays at a time, from the start at each start",
117
+ " --script-position <file> keep the script's position here, so a restarted",
118
+ " server goes on where the last one stopped",
98
119
  " --provision <mode> CLI provisioning: auto | pinned | system (default auto)",
99
120
  " --inherit-config <level> what a turn loads by itself (settings, MCP servers, hooks,",
100
121
  " memory): all, the user's and the repository's (the default),",
@@ -145,8 +166,12 @@ const VALUE_OPTIONS = new Set([
145
166
  "--dial",
146
167
  "--harness",
147
168
  "--acp-agent",
169
+ "--script",
170
+ "--script-position",
148
171
  "--provision",
149
172
  "--inherit-config",
173
+ "--model",
174
+ "--thinking",
150
175
  "--credentials-url",
151
176
  "--journal",
152
177
  "--buffer",
@@ -192,6 +217,12 @@ function parseArgs(argv: string[]): Args {
192
217
  if (spec === undefined || !spec.trim() || spec.startsWith("-"))
193
218
  fail("--acp-agent needs a known agent name (pi, gemini) or a launch command");
194
219
  args.acpAgent = spec;
220
+ } else if (arg === "--script") {
221
+ args.script = next();
222
+ if (!args.script) fail("--script needs a file path");
223
+ } else if (arg === "--script-position") {
224
+ args.scriptPosition = next();
225
+ if (!args.scriptPosition) fail("--script-position needs a file path");
195
226
  } else if (arg === "--provision") {
196
227
  const mode = next();
197
228
  if (mode !== "auto" && mode !== "pinned" && mode !== "system")
@@ -201,6 +232,16 @@ function parseArgs(argv: string[]): Args {
201
232
  const level = next();
202
233
  if (!isInheritConfig(level)) fail(`--inherit-config ${level}: use all, project or none`);
203
234
  args.inheritConfig = level;
235
+ } else if (arg === "--model") {
236
+ args.model = next();
237
+ if (!args.model) fail("--model needs a model id");
238
+ } else if (arg === "--thinking") {
239
+ const level = next();
240
+ if (!isThinkingLevel(level))
241
+ fail(
242
+ `--thinking ${level}: use ${THINKING_LEVELS.slice(0, -1).join(", ")} or ${THINKING_LEVELS.at(-1)}`,
243
+ );
244
+ args.thinking = level;
204
245
  } else if (arg === "--credentials-url") {
205
246
  args.credentialsUrl = next();
206
247
  } else if (arg === "--journal") {
@@ -291,25 +332,47 @@ if (args.journalPath && (args.mode === "acp" || args.command !== "serve"))
291
332
  fail("--journal is supported only for the stdio/listen/dial wire server");
292
333
  if (args.command !== "install" && (args.platforms || args.installDir || args.prune))
293
334
  fail("--platform, --dir and --prune are install's: agent-server install --dir <path> …");
335
+ // A wire client names each turn's model and level itself.
336
+ if (
337
+ (args.model !== undefined || args.thinking) &&
338
+ (args.mode !== "acp" || args.command !== "serve")
339
+ )
340
+ fail("--model and --thinking apply to --acp only (a wire client names them on each turn)");
294
341
  const listening = args.command === "serve" && args.mode === "listen";
295
342
  if (!listening && args.tokenFile !== undefined) fail("--token-file applies to --listen only");
296
343
  if (!listening && args.allowedOrigins) fail("--allow-origin applies to --listen only");
297
344
  const listener = listening ? listenOptions(args) : undefined;
298
345
  const credential = args.command === "serve" && args.mode === "dial" ? dialToken() : undefined;
299
346
 
300
- const harnesses = args.harnesses?.map((h) => {
347
+ const named = args.harnesses?.map((h) => {
301
348
  const choice = resolveHarnessName(h);
302
349
  if (!choice) fail(`unknown harness: ${h}`);
303
350
  // Friendly ACP agent names ("pi", "gemini") ride the acp harness.
304
351
  if (choice.acpAgent) args.acpAgent ??= choice.acpAgent;
305
352
  return choice.harness;
306
353
  });
354
+ // A script plays the scripted harness, alone unless --harness names others too.
355
+ if (args.scriptPosition !== undefined && args.script === undefined)
356
+ fail("--script-position keeps a script's position: give --script <file> too");
357
+ if (args.script !== undefined && args.command === "install")
358
+ fail("--script is the server's: agent-server --script <file>");
359
+ if (args.script !== undefined && named && !named.includes("scripted"))
360
+ fail("--script plays the scripted harness: name it in --harness (--harness scripted,…)");
361
+ if (args.command !== "install" && named?.includes("scripted") && args.script === undefined)
362
+ fail("the scripted harness needs a script: --script <file>");
363
+ const harnesses = named ?? (args.script !== undefined ? ["scripted" as const] : undefined);
307
364
  const provision = args.provisionMode ? { mode: args.provisionMode } : {};
308
365
  const acpLaunch = resolveAcpLaunch(args.acpAgent ?? process.env.AGENT_SERVER_ACP_AGENT);
309
- if (harnesses?.includes("acp") && !acpLaunch)
366
+ // `install` runs no agent: an acp harness there has nothing to install, and says so.
367
+ if (args.command !== "install" && harnesses?.includes("acp") && !acpLaunch)
310
368
  fail('the acp harness needs an agent: --harness pi|gemini or --acp-agent "<spec>"');
311
369
 
312
370
  if (args.command === "install") {
371
+ // A harness the engine installs nothing for is said, not passed over in silence.
372
+ for (const [i, harness] of (harnesses ?? []).entries())
373
+ if (!toolsFor([harness]).length)
374
+ console.error(nothingToInstall(args.harnesses?.[i] ?? harness, harness));
375
+ if (harnesses && !toolsFor(harnesses).length) process.exit(0);
313
376
  try {
314
377
  // install always downloads, into the managed cache or --dir; --provision
315
378
  // (a serving concern) is deliberately not forwarded.
@@ -319,11 +382,7 @@ if (args.command === "install") {
319
382
  ...(args.installDir && { dir: args.installDir }),
320
383
  ...(args.prune && { prune: true }),
321
384
  });
322
- for (const { tool, platform, cli } of results) {
323
- console.error(
324
- `${tool} ${cli.version ?? ""} (${platform}) ready: ${cli.path} (${cli.source})`,
325
- );
326
- }
385
+ for (const result of results) console.error(installedLine(result));
327
386
  process.exit(0);
328
387
  } catch (error) {
329
388
  console.error(`install failed: ${error instanceof Error ? error.message : String(error)}`);
@@ -353,9 +412,22 @@ if (args.credentialsUrl) {
353
412
  }
354
413
  }
355
414
 
415
+ let script: ScriptSource | undefined;
416
+ if (args.script !== undefined) {
417
+ try {
418
+ script = scriptedFile(args.script, {
419
+ ...(args.scriptPosition && { position: args.scriptPosition }),
420
+ });
421
+ } catch (error) {
422
+ fail(`--script: ${error instanceof Error ? error.message : String(error)}`);
423
+ }
424
+ }
425
+
356
426
  const runtime = createAgentRuntime({
357
427
  ...(harnesses ? { harnesses } : {}),
358
- ...(acpLaunch ? { acp: { resolveLaunch: () => acpLaunch } } : {}),
428
+ // An ACP agent is told which release drives it (`clientInfo`).
429
+ ...(acpLaunch ? { acp: { resolveLaunch: () => acpLaunch, clientVersion: VERSION } } : {}),
430
+ ...(script && { scripted: { turn: script } }),
359
431
  provision,
360
432
  ...(args.inheritConfig && { inheritConfig: args.inheritConfig }),
361
433
  ...(credentials && { credentials }),
@@ -369,6 +441,8 @@ if (args.mode === "acp") {
369
441
  const connection = await serveAcpStdio({
370
442
  runtime,
371
443
  harness: frontedHarness,
444
+ ...(args.model && { model: args.model }),
445
+ ...(args.thinking && { thinkingLevel: args.thinking }),
372
446
  version: VERSION,
373
447
  sessionDir:
374
448
  process.env.AGENT_SERVER_ACP_SESSION_DIR ??
@@ -34,7 +34,7 @@ export interface FeedbackOptions {
34
34
  fetchImpl?: (url: string, init: RequestInit) => Promise<Response>;
35
35
  }
36
36
 
37
- export interface FeedbackResult {
37
+ interface FeedbackResult {
38
38
  delivered: boolean;
39
39
  threadId: string;
40
40
  /** Human-readable lines to print (thread id, guidance, ask). */
@@ -1,5 +1,6 @@
1
- import { chmod, readdir, realpath, rm } from "node:fs/promises";
2
- import { join, relative, sep } from "node:path";
1
+ import { readFileSync } from "node:fs";
2
+ import { chmod, mkdir, readdir, realpath, rm, stat } from "node:fs/promises";
3
+ import { dirname, join, relative, resolve, sep } from "node:path";
3
4
  import {
4
5
  CLI_TOOLS,
5
6
  CliProvisioner,
@@ -11,7 +12,8 @@ import {
11
12
  } from "../core/index.ts";
12
13
  import { openToAll } from "../core/provision/install-build.ts";
13
14
  import { detectPlatform, parsePlatform, platformName } from "../core/provision/platform.ts";
14
- import { CLI_TOOL_SPECS } from "../core/provision/tools.ts";
15
+ import { CLI_RELEASES } from "../core/provision/releases.ts";
16
+ import { CLI_TOOL_SPECS, claudeSdkOnDisk } from "../core/provision/tools.ts";
15
17
  import type { AgentHarness } from "../protocol/index.ts";
16
18
 
17
19
  export interface InstallOptions {
@@ -56,6 +58,50 @@ export function toolsFor(harnesses: AgentHarness[] | undefined): CliTool[] {
56
58
  return CLI_TOOLS.filter((tool) => needed.has(tool));
57
59
  }
58
60
 
61
+ /**
62
+ * What `install` says of a harness it installs nothing for (`acp`, the ACP
63
+ * agents by name, `scripted`): there is no CLI the engine installs.
64
+ */
65
+ export function nothingToInstall(name: string, harness: AgentHarness): string {
66
+ const why =
67
+ harness === "scripted"
68
+ ? "the scripted harness runs no CLI"
69
+ : "an ACP agent runs from its launch command, which the operator installs";
70
+ return `${name}: nothing to install: the engine installs no CLI for it (${why})`;
71
+ }
72
+
73
+ /**
74
+ * The Claude Code version the Claude SDK package `version` carries, where
75
+ * this release pins it or the SDK on disk is that version.
76
+ */
77
+ function claudeCodeVersion(version: string): string | undefined {
78
+ if (CLI_RELEASES.claude.version === version) return CLI_RELEASES.claude.cli;
79
+ const sdk = claudeSdkOnDisk();
80
+ if (sdk?.version !== version) return undefined;
81
+ try {
82
+ return (
83
+ JSON.parse(readFileSync(join(sdk.dir, "package.json"), "utf8")) as {
84
+ claudeCodeVersion?: string;
85
+ }
86
+ ).claudeCodeVersion;
87
+ } catch {
88
+ return undefined;
89
+ }
90
+ }
91
+
92
+ /**
93
+ * The line `install` prints for a CLI it installed, saying what its version
94
+ * is: Claude's is the Claude SDK package's (`0.3.288`), which carries a
95
+ * Claude Code of its own number (`2.1.288`), the one `claude --version` says.
96
+ */
97
+ export function installedLine({ tool, platform, cli }: InstallResult): string {
98
+ const where = `for ${platform} ready: ${cli.path} (${cli.source})`;
99
+ if (tool === "codex") return `codex: Codex CLI ${cli.version ?? "(version not known)"} ${where}`;
100
+ if (!cli.version) return `claude: Claude Code (version not known) ${where}`;
101
+ const code = claudeCodeVersion(cli.version);
102
+ return `claude: Claude SDK package ${cli.version}${code ? ` (Claude Code ${code})` : ""} ${where}`;
103
+ }
104
+
59
105
  /** The platforms named, each one some CLI is published for, or what is wrong. */
60
106
  export function platformsFor(names: readonly string[]): PlatformInfo[] {
61
107
  const known = [...new Set(CLI_TOOLS.flatMap((tool) => CLI_TOOL_SPECS[tool].platforms))];
@@ -88,6 +134,34 @@ function stagedBuild(dir: string, path: string): string {
88
134
  return join(tool, entry);
89
135
  }
90
136
 
137
+ /**
138
+ * `dir` and the parents of it that are missing, created readable and
139
+ * traversable by every user (0755, whatever the umask), as the builds staged
140
+ * in it are: run as root in an image build, the engine's own 0700 would leave
141
+ * a runtime user unable to reach them. A folder that was there is left as it
142
+ * is. The engine's own cache keeps its 0700 (`trustedCacheDirectory`).
143
+ */
144
+ async function createStagingFolders(dir: string): Promise<void> {
145
+ const missing: string[] = [];
146
+ for (let path = resolve(dir); ; path = dirname(path)) {
147
+ const exists = await stat(path).then(
148
+ () => true,
149
+ (error: NodeJS.ErrnoException) => {
150
+ if (error.code === "ENOENT") return false;
151
+ throw error;
152
+ },
153
+ );
154
+ if (exists || dirname(path) === path) break;
155
+ missing.unshift(path);
156
+ }
157
+ for (const path of missing) {
158
+ await mkdir(path, { mode: 0o755 }).catch((error: NodeJS.ErrnoException) => {
159
+ if (error.code !== "EEXIST") throw error;
160
+ });
161
+ await chmod(path, 0o755);
162
+ }
163
+ }
164
+
91
165
  /**
92
166
  * The builds just staged, readable and runnable by every user, and the
93
167
  * folder without the install's records: an owner-only tree baked into an
@@ -116,7 +190,11 @@ export async function runInstall(options: InstallOptions = {}): Promise<InstallR
116
190
  ...(options.dir && { mode: "pinned", cacheDir: options.dir }),
117
191
  };
118
192
  const platforms = options.platforms ? platformsFor(options.platforms) : [detectPlatform()];
119
- if (options.dir) await stageable(options.dir);
193
+ if (options.dir) {
194
+ await stageable(options.dir);
195
+ // @ref LLP 0010#p4--staging-for-images-and-app-bundles — what staging creates, every user may reach
196
+ await createStagingFolders(options.dir);
197
+ }
120
198
  const create =
121
199
  options.createProvisioner ??
122
200
  ((provisionOptions: ProvisionOptions, platform: PlatformInfo) =>
@@ -1,7 +1,7 @@
1
1
  import { type AgentHarness, WireRefusal } from "../protocol/index.ts";
2
2
 
3
3
  /** The turn a session runs. */
4
- export interface ActiveTurn {
4
+ interface ActiveTurn {
5
5
  turnId: string;
6
6
  harness: AgentHarness;
7
7
  }
@@ -242,8 +242,12 @@ export class JournalSessionStore implements SessionLogStore {
242
242
  receipt(sessionId: string, turnId: string): TurnReceipt | undefined {
243
243
  return this.journal.turn(sessionId, turnId);
244
244
  }
245
+ // @ref LLP 0003#commit-before-acknowledging — the latest turn is read for `session/get` alone
246
+ /** `session/get`'s answer: the journal's summary and its latest turn. */
245
247
  session(sessionId: string): DurableSession | undefined {
246
- return this.journal.session(sessionId);
248
+ const session = this.journal.session(sessionId);
249
+ const lastTurn = session && this.journal.lastTurn(sessionId);
250
+ return session && { ...session, ...(lastTurn && { lastTurn }) };
247
251
  }
248
252
  confirmStopped(sessionId: string, expectedHeadSeq: number): boolean {
249
253
  return this.write(() => this.journal.confirmStopped(sessionId, expectedHeadSeq));
@@ -20,7 +20,7 @@ export const DEFAULT_MAX_SUBSCRIPTIONS = 256;
20
20
  */
21
21
  export const DEFAULT_MAX_BACKLOG_BYTES = 16 * 1024 * 1024;
22
22
 
23
- export interface SubscriptionLimits {
23
+ interface SubscriptionLimits {
24
24
  maxSubscriptions: number;
25
25
  maxBacklogBytes: number;
26
26
  }