@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
package/docs/consuming.md CHANGED
@@ -3,6 +3,9 @@
3
3
  The integration recipe, written down once — every rule here was re-derived
4
4
  independently by at least one real consumer before it landed in this file.
5
5
 
6
+ Short on time? Read [What products got wrong](#what-products-got-wrong-so-you-need-not)
7
+ first: each line is a mistake a real integration made, and what to do instead.
8
+
6
9
  ## Fold events with the shipped reducer
7
10
 
8
11
  Do not hand-roll a `switch (event.type)` state fold. The package ships the
@@ -65,6 +68,15 @@ The reducer encodes the rules consumers get wrong first:
65
68
  the mode it asks for: `state.permissionMode` holds the current one (the
66
69
  turn's, then the agent's switch), so send that mode next to stay with the
67
70
  agent.
71
+ - **Draw a tool call from its fields, not its input.** A tool part and a
72
+ request's `toolCall` say what the call acts on: `command` (the line as the
73
+ agent wrote it, never Codex's `/bin/zsh -lc` wrapper), `url`, and
74
+ `locations` (each hunk's start `line` once an edit is done); a request's
75
+ `reason` says why it asks, and its `title` is only a label. A result's
76
+ `content` holds its `diff` entries and `state.metadata.exitCode` a
77
+ command's exit code, failed or not, where the harness reports them.
78
+ `rawInput` and `state.input` stay each harness's own keys
79
+ (`docs/harnesses.md`, What a tool call says, per harness).
68
80
  - **Say why where the harness hears it.** A refused tool call's `message`
69
81
  reaches the agent when `initialize().harnesses[h].rejectionMessages` is
70
82
  true (Claude). Codex's refusal is a bare verdict and an ACP agent's an
@@ -100,7 +112,8 @@ The reducer encodes the rules consumers get wrong first:
100
112
  that changed (`five_hour`, `seven_day`, … with `usedPercent` and
101
113
  `resetsAt`); `state.limits` merges them by id. A recoverable `error` with
102
114
  `retry` means the harness is waiting to try again — show it, don't fail the
103
- turn.
115
+ turn. It reports a retry under way: its `category` is the failing call's,
116
+ not the turn's outcome, so show the attempt and the message, not "auth".
104
117
 
105
118
  Branch on the outcome with `isCleanStop` / `isFailureStopReason` rather than
106
119
  your own list: `cancelled` is clean (the user asked for the stop), `error` is
@@ -257,12 +270,18 @@ A harness's first turn on a machine without its CLI downloads it, about
257
270
  ```ts
258
271
  client.onCliProgress(({ harness, phase, receivedBytes, totalBytes }) => progressBar(harness, phase, receivedBytes, totalBytes));
259
272
  const [claude] = await client.prepareClis(["claude-code"]);
260
- if (claude?.state === "failed") showRetry(claude.error); // e.g. offline
273
+ if (claude?.state === "failed") showRetry(claude.error, claude.category); // "network": offline, ask again later
261
274
  ```
262
275
 
263
276
  `listClis()` says where each CLI is without installing (`ready`, `missing`,
264
- `installing`, `failed`, `unmanaged`); every connection hears `clis/progress`,
265
- whoever caused the install. `prepareClis()` waits on those, since the server
277
+ `installing`, `failed`, `unmanaged`; a `failed` one's `category` says what
278
+ failed, as a turn's error does); every connection hears `clis/progress`,
279
+ whoever caused the install. A read installs nothing: until a harness's CLI is
280
+ there, `authStatus()` answers it `unknown` with no `methods` and
281
+ `listModels()` the catalog, each with an `error` saying the CLI is not
282
+ installed yet, being installed, or failed to install; read again once
283
+ `clis/progress` says `ready` (the first model list after it is live). What
284
+ installs is an act: a turn, `prepareClis()`, `login()` and `logout()`. `prepareClis()` waits on those, since the server
266
285
  answers `clis/prepare` at once; its `signal` stops the waiting, not the
267
286
  install. In-process, `runtime.prepareClis()`, `runtime.listClis()` and
268
287
  `runtime.onCliProgress()` do the same. A product that bundles the Claude SDK
@@ -318,8 +337,12 @@ environment wins over the login; say so. Every connection hears
318
337
  it, and a status read notices a login made in a terminal. After a change,
319
338
  each session's next turn starts a new CLI, resuming its conversation. A turn
320
339
  that fails for its credential ends with `error.category: "auth"`: send the
321
- user to the login. A login handle that loses its connection settles at once:
322
- read the status again. Status reports the
340
+ user to the login. A login under way is `auth.loginUnderWay` (what
341
+ `client.login` answered: `loginId`, `url`, `codeUrl`, `userCode`,
342
+ `expiresAt`) in every status read and every `auth/updated`, which tells it as
343
+ it starts too, so a second window shows the same sign-in page and can cancel
344
+ it (`auth/cancel`). A login handle that loses its connection settles at once:
345
+ read the status again, which says whether the login still goes on. Status reports the
323
346
  CLI's own login and environment: a turn that brings its own `apiKey`, or runs
324
347
  on a credential the product holds (`credentials`), runs with that instead. In-process, `runtime.authStatus()`, `runtime.login()`,
325
348
  `runtime.completeLogin()`, `runtime.cancelLogin()`, `runtime.logout()` and
@@ -391,12 +414,15 @@ Fill a model picker from the harness's own list rather than a hard-coded one:
391
414
 
392
415
  ```ts
393
416
  const { models, source, error } = await client.listModels({ harness: "codex-app-server", cwd });
394
- // source: "catalog" + error = the CLI did not answer (e.g. logged out); offer a login.
417
+ // source: "catalog" + error = the CLI did not answer (e.g. logged out; offer a login)
418
+ // or is not installed yet (prepareClis, then list again).
395
419
  const choice = models.find((m) => m.isDefault) ?? models[0];
396
420
  const level = savedLevelFor(choice.id) ?? choice.thinking.default; // never invent one
397
421
  ```
398
422
 
399
- `thinking.levels` empty means the model has no thinking control. Keep the
423
+ `thinking.levels` empty means the model has no thinking control: a turn
424
+ that names a level for it runs without one (`off` is still sent on Claude),
425
+ and reports no `appliedThinkingLevel`. Keep the
400
426
  user's level per model, and use `clampThinkingLevel(level, model.thinking.levels)`
401
427
  only for a model the user has not set. Pass `refresh: true` after a login;
402
428
  lists are cached ten minutes.
@@ -413,6 +439,16 @@ model it rerouted to, after a reroute), and the requested `model` only where
413
439
  a harness names none. List models with the `cwd` (and credentials) your turns use: an alias
414
440
  such as `opus` is fitted only from its own login's list.
415
441
 
442
+ A setting a harness does not apply is said, not dropped in silence. Read
443
+ `capabilities.ignoredSettings` (from `initialize`) up front: the `RunConfig`
444
+ fields that harness never applies (`maxTurns` and `resumeSessionAt` on
445
+ Codex). Each turn names the ones it set in `turn.started.execution.notApplied`,
446
+ and `turn.ended.execution.notApplied` adds those the harness found it could
447
+ not apply as it ran (a model with no thinking control, an ACP agent that
448
+ takes no extra directories); the reducer keeps it on the turn. A product's own
449
+ "not on this harness" checks can go. `docs/harnesses.md`, "What each harness
450
+ does with each turn setting", has every field.
451
+
416
452
  ## Persist for resume
417
453
 
418
454
  Store `state.nativeSessionId` (from `session.created`) keyed by your logical
@@ -484,7 +520,9 @@ identical request converges on the original execution — the wire acks it with
484
520
  `deduplicated: true` and `events/replay` fills anything you missed. The same
485
521
  `turnId` with different input fails loudly (`turnConflict` /
486
522
  `TurnConflictError`). This is what makes at-least-once RPC layers (Durable
487
- Object retries, queue redelivery) safe over the engine.
523
+ Object retries, queue redelivery) safe over the engine. Without a journal the
524
+ engine keeps the answers of a session's last 16 turns: a retry of an older
525
+ one fails the same way (`TurnForgottenError`) rather than running it again.
488
526
 
489
527
  Built-in harnesses allow one active turn per logical session, including setup
490
528
  and cancellation cleanup. Different sessions can run in parallel. Wait for the
@@ -512,6 +550,14 @@ the turn ends. A command whose stop could not be confirmed is not closed as
512
550
  cancelled: its tool part fails with `TOOL_OUTCOME_UNKNOWN`, a failure the
513
551
  harness reports itself (no `closure`).
514
552
 
553
+ Two operator options time a cancel, each set once on `createAgentRuntime`
554
+ for every harness. `cancelConfirmMs` (2 s by default) is how long a cancel
555
+ waits for the agent to confirm it stopped before it answers `unconfirmed`;
556
+ a turn still starting is confirmed once it has ended within it.
557
+ `cancelGraceMs` is how long after a cancel the engine ends an agent that has
558
+ not stopped, and its turn then ends `cancelled`: 2 s on Codex, 10 s on an
559
+ ACP agent; Claude is not ended for it.
560
+
515
561
  Embedded `runtime.cancel(harness, sessionId)` cancels the session's active
516
562
  turn without a turn ID check. Prefer a per-turn `AbortSignal` when cancellation
517
563
  can arrive late; a completed turn's signal is detached before the next turn.
@@ -544,8 +590,8 @@ CLI's `--inherit-config`, choose how much (LLP 0001, D17):
544
590
 
545
591
  | Level | Claude Code | Codex app-server |
546
592
  | --- | --- | --- |
547
- | `all` (default) | every settings source (user, project, local) and the auto-memory Claude keeps for the repository, as the CLI itself does | the turn's `env.CODEX_HOME`, else the process's: the user's `~/.codex` |
548
- | `project` | the repository's settings, hooks, `.mcp.json` servers and instruction files; nothing of the user's, no auto-memory, no claude.ai connectors | the repository's `AGENTS.md` and skills, in a home of the session's own |
593
+ | `all` (default) | every settings source (user, project, local) and the auto-memory Claude keeps for the repository, as the CLI itself does | the turn's `env.CODEX_HOME`, else the process's: the user's `~/.codex`, which the engine never writes |
594
+ | `project` | the repository's settings, hooks, `.mcp.json` servers and instruction files; nothing of the user's, no auto-memory, no claude.ai connectors | the repository's `AGENTS.md` and skills, in a home of the session's own; no apps (the ChatGPT account's connectors) |
549
595
  | `none` | only the servers the host and the turn name | as `project`, without the repository's `AGENTS.md` |
550
596
 
551
597
  Choose by whose machine and whose repository it is. A desktop product that
@@ -569,9 +615,18 @@ At `project` and `none` every Codex turn needs `config.env.CODEX_HOME`, an
569
615
  existing absolute folder of the session's own: never the user's `~/.codex`,
570
616
  never another session's. A turn without one fails `invalid_request` before
571
617
  Codex starts. The engine owns that home's `mcp_servers` table, as for
572
- per-turn MCP below. A fresh home has no login: hand one over with
573
- [`credentials`](harnesses.md#host-managed-codex-authentication) or the turn's
574
- `apiKey`. Codex loads the repository's skills and
618
+ per-turn MCP in a home below. A fresh home has no login: run it on the
619
+ person's own Codex login (`codexAppServer.userLogin`, below), or hand one over
620
+ with [`credentials`](harnesses.md#host-managed-codex-authentication) or the
621
+ turn's `apiKey`. Below `all` Codex's apps, the ChatGPT account's connectors,
622
+ are off in every thread, as Claude's claude.ai connectors are, and its
623
+ plugins are off in every app-server that runs in such a home
624
+ (`-c features.plugins=false`), so a fresh home stays about 4 MB where it
625
+ cloned Codex's plugin catalogue (about 85 MB); a product that wants a plugin
626
+ runs at `all` or brings it as an MCP server. A home removed and made again
627
+ under a session's warm process starts a new process on the next turn, which
628
+ resumes the thread if the home still holds it, or fails `resume_failed`.
629
+ Codex loads the repository's skills and
575
630
  `~/.agents/skills` at every level; turn one off by name in the home you
576
631
  supply (`[[skills.config]]` with `enabled = false`).
577
632
 
@@ -581,6 +636,89 @@ On Claude a `disableTools` turn runs at `none` whatever the level.
581
636
  auto-memory and the connectors. An ACP agent loads what its launch command
582
637
  says.
583
638
 
639
+ ### A product's own agent on the person's own login
640
+
641
+ A product whose agent works only through the product's own tools, on the
642
+ person's own Claude or Codex login and with none of their configuration,
643
+ runs its turns at `inheritConfig: "none"` (LLP 0017). Nothing of it comes
644
+ from the wire.
645
+
646
+ ```ts
647
+ createAgentRuntime({
648
+ inheritConfig: "none",
649
+ claudeCode: { sdkOptions: () => ({ tools: [] }), toolPolicy },
650
+ codexAppServer: {
651
+ userLogin: true,
652
+ builtInTools: { local: false, webSearch: false, imageGeneration: false },
653
+ },
654
+ });
655
+
656
+ // Each Codex turn names a home of its session's own: an existing folder you
657
+ // make for the session and keep for its resume, never ~/.codex.
658
+ await runtime.run({
659
+ sessionId,
660
+ turnId,
661
+ input,
662
+ config: { harness: "codex-app-server", cwd, mcpServers, env: { CODEX_HOME: sessionHome } },
663
+ }, sink);
664
+ ```
665
+
666
+ - **Claude** runs on the login of the person's own Claude Code (no
667
+ `CLAUDE_CONFIG_DIR`). At `none` it loads no settings source, no
668
+ settings file's, plugin's or claude.ai connector's server and no
669
+ auto-memory: only the servers you name. `sdkOptions: () => ({ tools: [] })`
670
+ takes Claude's own tools away and keeps the MCP servers; to keep a few,
671
+ list their names (`tools: ["Read", "Grep"]`, the SDK's option, passed
672
+ through). `toolPolicy` is asked only about the calls Claude itself would
673
+ ask about, so it cannot keep a tool off alone: with the policy alone, a
674
+ `Read` of a file in the turn's folder ran and the policy was asked 0 times,
675
+ with 29 of Claude's own tools offered (measured, Claude Code 2.1.288).
676
+ `disableTools` is no substitute: it drops the MCP servers too. In `default`
677
+ mode Claude asks about every MCP call, so `toolPolicy` sees each of
678
+ yours. Claude keeps each session's transcript under the person's own
679
+ `~/.claude/projects/<folder>/`, at `none` too, and it stays after
680
+ `session/close`: a resume needs it.
681
+ - **Codex** runs each turn in the home it names, which holds the session's
682
+ conversation (its transcript goes with the home) and the turn's MCP
683
+ servers and nothing of the person's: no
684
+ `config.toml`, MCP servers, hooks, profiles, `AGENTS.md` or skills of
685
+ theirs, no apps or plugins, and at `none` not the repository's `AGENTS.md`.
686
+ `userLogin` runs it on the person's own Codex login (the one `codex login`
687
+ keeps in `$CODEX_HOME`, else `~/.codex`), read from Codex before each turn
688
+ and held in the session's process's memory: nothing is copied or written
689
+ to the session's home, and Codex renews the login in the person's own home
690
+ when it needs to. A product's `credentials` and the turn's `apiKey` come
691
+ first. Signed out, the turn fails `auth` before Codex starts. Codex still
692
+ loads the repository's skills and `~/.agents/skills`.
693
+ - `builtInTools`: each of Codex's own tool groups is on unless set `false`.
694
+ `local: false` takes away the shell, `apply_patch`, `view_image` and
695
+ `write_stdin`, from the sub-agents Codex spawns too, so nothing the agent
696
+ runs reads or writes the disk;
697
+ `webSearch: false` and `imageGeneration: false` take away those. With
698
+ image generation on, a picture comes as an `image_generation` tool part
699
+ without its bytes: `metadata.savedPath`, when Codex gives one, names a file
700
+ on the engine's machine, which a client elsewhere cannot open; a client
701
+ that asks for `includeRaw` still receives Codex's own item, bytes included.
702
+ Codex still gives the model code mode's `exec`, its sub-agent tools and
703
+ its question tool, so `disableTools` stays refused.
704
+ - **Status and sign-in** are the person's own: read `auth/status` and start
705
+ `auth/login` with no `env`, since the turns run on the person's own login,
706
+ not on anything in a session's home.
707
+
708
+ Codex holds MCP tools back from the model until it searches for them, so
709
+ name your tools in the turn's `systemPromptAppend`.
710
+
711
+ Codex asks about an MCP tool call (a `permission.requested`) unless the
712
+ server marks the tool `readOnlyHint: true`, and never asks about one it
713
+ marks so: on Codex your server's annotations decide what is asked, not a
714
+ rule of yours (measured, Codex 0.160.0: a `save_note` marked read-only ran
715
+ with nothing asked; unmarked, it was asked about). Annotate your tools to
716
+ match what you want asked. To tell which of your tools a call is, read
717
+ `mcp.server` and `mcp.tool` on the tool part or the permission request's
718
+ `toolCall`, the same on both harnesses: `toolName` is each harness's own
719
+ spelling (`mcp__<server>__<tool>` on Claude, `<server>.<tool>` on Codex).
720
+ Only a Claude `toolPolicy`, which sees no part, gets Claude's own name.
721
+
584
722
  ## Own your session resources
585
723
 
586
724
  ### Configure MCP between turns
@@ -588,7 +726,8 @@ says.
588
726
  For Claude and Codex app-server, `RunConfig.mcpServers` is the complete set of wire-configured
589
727
  servers for that turn, not an incremental patch. Repeating an unchanged set
590
728
  reuses the running process and its MCP connections. Changed entries are
591
- applied through the harness's native configuration API before the prompt;
729
+ applied through the harness's native configuration API before the prompt
730
+ (a Codex turn that names no home starts a new process for them, below);
592
731
  finishing a turn does not restart the agent or its servers. Omitting the map
593
732
  on a later turn removes the previous wire-configured set, just like `{}`.
594
733
  Claude's host `sdkMcpServers` remain attached. The native CLI may also load MCP servers
@@ -615,12 +754,49 @@ turns and supply the current complete map on each turn. The explicit live
615
754
  next turn's map takes precedence. External MCP servers enforce credential
616
755
  expiry; ending a turn does not itself revoke an attached credential.
617
756
 
618
- Codex supports stdio and Streamable HTTP servers; legacy SSE is rejected. Its
619
- per-turn MCP configuration requires an existing, absolute, session-specific
620
- `config.env.CODEX_HOME` directory (below `inheritConfig: "all"` every Codex
621
- turn does). Create it with mode `0700`, retain it while
757
+ Codex supports stdio and Streamable HTTP servers; legacy SSE is rejected,
758
+ and Codex's `codex_apps` name is reserved. Where a turn's servers go depends
759
+ on whether it names a home (LLP 0001, D21).
760
+
761
+ **No home named** (`inheritConfig: "all"` only). The turn runs in the
762
+ process's Codex home, the user's own `~/.codex`, with the user's servers,
763
+ threads and login, and its servers ride the thread's own config
764
+ (`thread/start` and `thread/resume`): the engine writes no file. What Codex
765
+ does with a thread's config is Codex's: with 0.160.0 no file of the home held
766
+ the servers' headers or environment (observed, LLP 0001 D21), and no test
767
+ holds that, so look again when the Codex pin moves. A thread's config is
768
+ fixed once it is open, so:
769
+
770
+ - An unchanged set keeps the warm process and its connections.
771
+ - A changed set (a server added, removed or changed, a rotated header)
772
+ replaces the session's process before the turn and resumes the thread with
773
+ the new set, as a login change does. It costs about a tenth of a second,
774
+ and ends the terminals earlier turns left running. `required` is the
775
+ engine's and is no change.
776
+ - A server that could not connect is tried again by a reload, in the same
777
+ process, on the schedule above.
778
+ - A server whose name Codex's own configuration also has (the user's
779
+ `config.toml`, a trusted repository's `.codex/config.toml`) is merged with
780
+ it by Codex, setting by setting: the turn's values win, and the other's
781
+ remaining headers, environment and tool filter would apply to the turn's
782
+ server. The engine reads Codex's configuration before the thread opens and
783
+ before each turn, and refuses such a turn as `invalid_request`, naming
784
+ `mcpServers.<name>`; rename one of them. A same-named server that sets
785
+ nothing more than the turn does goes on as the turn's. The refusal is the
786
+ whole turn's, `required: false` or not, so a product whose servers have
787
+ common names (`github`, `linear`) gives them names of its own before it
788
+ runs Codex without a home.
789
+ - A session whose first turn failed before the model ran (a required server
790
+ down) has no conversation yet, and reported no native id: its next turn
791
+ starts one.
792
+
793
+ **A home named** (`config.env.CODEX_HOME`; below `inheritConfig: "all"`
794
+ every Codex turn names one). An existing, absolute, session-specific
795
+ directory, where the engine writes the turn's servers. Create it with mode
796
+ `0700`, retain it while
622
797
  the conversation may resume, and delete it when that logical session is
623
- released. It contains conversation history and MCP credentials. Never share
798
+ released: `session/close` and `session/release` answer once the session's
799
+ processes have exited, so nothing writes to the home after the answer. It contains conversation history and MCP credentials. Never share
624
800
  it between sessions or use the operator's normal Codex home.
625
801
 
626
802
  This isolates writable MCP configuration and conversation state; it does not
@@ -631,24 +807,26 @@ while retaining login and token renewal in its own account manager.
631
807
  The repository's interactive CLI accepts `--codex-home=/absolute/private/path`
632
808
  and remembers the path for `--continue`; the operator supplies the existing home.
633
809
  Standalone CLI use relies on native authentication in that home. `--connect`
634
- can use an embedded server's external authentication instead.
810
+ can use an embedded server's external authentication instead. Without
811
+ `--codex-home`, at `--inherit-config=all`, the CLI's Codex turns run in the
812
+ user's own home with their `--mcp` servers in the thread's config.
635
813
  The ACP **server binding** (`createAcpAgentApp` /
636
- `agent-server --acp --harness codex-app-server`) has no per-session environment
637
- resource seam in this release. It rejects supplied Codex MCP servers explicitly
638
- at `session/new` or `session/resume`. Use the engine or standard JSON-RPC API
639
- with `config.env.CODEX_HOME` for that combination. This limitation is separate
640
- from the engine's ACP **harness**, which forwards MCP to other ACP agents.
814
+ `agent-server --acp --harness codex-app-server`) names no home for a session,
815
+ so it runs at `all` and a client's stdio and HTTP servers ride the thread's
816
+ config, as above; it refuses an SSE server and the name `codex_apps` at
817
+ `session/new` or `session/resume`. A session that needs a home of its own
818
+ uses the engine or the JSON-RPC API.
641
819
 
642
820
  An explicitly supplied `CODEX_HOME` gives the engine ownership of that home's
643
821
  user-layer `mcp_servers` table: each turn replaces that table, including
644
822
  clearing it when the map is omitted. Without an explicit home or a per-turn
645
823
  map, native Codex configuration continues to work normally. Repository and
646
824
  plugin servers remain separate, but a higher-priority setting that changes a
647
- requested server fails preparation before reload. Codex's `codex_apps` name
648
- is reserved.
825
+ requested server fails preparation before reload.
649
826
 
650
- Codex writes changed configuration without reloading, verifies its effective
651
- settings, then reloads MCP and checks readiness before submitting the prompt.
827
+ In a home, Codex writes changed configuration without reloading, verifies its
828
+ effective settings, then reloads MCP and checks readiness before submitting
829
+ the prompt; without one, the servers start with the thread.
652
830
  Servers still starting are awaited through native startup notifications, with
653
831
  a bounded deadline (30 seconds); a required server that failed fails
654
832
  preparation at once, with the cause Codex gave.
@@ -665,9 +843,11 @@ automatically replayed.
665
843
  After thawing a VM, call `runtime.invalidateMcpConnections()` before admitting
666
844
  new turns. Drain active turns before suspending the host. This embed-tier
667
845
  lifecycle signal retains conversation state and turn-admission receipts.
668
- Before the next prompt, the Claude and Codex app-server harnesses replace
669
- retained subprocesses and strictly resume their saved conversations, using
670
- that turn's current MCP credentials before reconnecting the tools.
846
+ It ends no process: before each session's next prompt, the Claude, Codex
847
+ app-server and ACP harnesses replace the retained subprocess and strictly
848
+ resume its saved conversation, using that turn's current MCP credentials
849
+ before reconnecting the tools. An ACP agent that can neither resume nor load
850
+ keeps its process, as it holds the only copy of its conversation.
671
851
  Missing history fails with `resume_failed`; it never silently starts an empty
672
852
  conversation. Ordinary warm turns still reuse the process.
673
853
 
@@ -709,10 +889,148 @@ event later: its `events/replay` answers `unknownSession`, and that answer *is*
709
889
  the terminal signal (the session is gone; nothing more will be appended to it).
710
890
  Treat `unknownSession` on replay as "session over", not as an error to retry.
711
891
 
892
+ ## Let an outside agent operate your sessions
893
+
894
+ `@zvada/agent-server/operator` gives a hosted assistant (ChatGPT, Claude, a
895
+ CLI agent) the tools to operate your product's coding agents:
896
+ `list_sessions`, `read_session`, `start_session`, `send_message`,
897
+ `wait_for_session`, `watch_sessions`, `answer_request`, `stop_session`. They
898
+ answer in short text that names the next call and never report a session
899
+ waiting on a person as done. Each tool that waits takes one argument, `wait`
900
+ (seconds, default 60, 0 looks once and returns), and no call is held past
901
+ `maxWaitSeconds` (90, or a function of the caller, such as the seconds its
902
+ sign-in has left; below one second a call looks once and answers). What an
903
+ agent, a person or a repository wrote is quoted, each line after ` | `, so
904
+ it never reads as a hint (` -> tool(args)`); a plan or permission is
905
+ approved only by an answer that is a yes and nothing more; a form, a page to
906
+ visit or a secret is shown as waiting on the person, where the session runs,
907
+ and the tools refuse to answer it (LLP 0014).
908
+
909
+ You implement `OperatorHost`: which sessions the caller sees, how to read one,
910
+ how to send, cancel and answer a turn. Who may call, what a session is called
911
+ and where it is stored stay yours. A host over the engine alone, folding
912
+ events in memory:
913
+
914
+ ```ts
915
+ import { OperatorError, createOperator, phaseOf, viewOf, type OperatorHost } from "@zvada/agent-server/operator";
916
+
917
+ server.onEvent(({ sessionId, event }) => {
918
+ const held = sessions.get(sessionId);
919
+ if (held) held.state = reduceConversation(held.state, event);
920
+ for (const wake of waiters) wake(); // `changed` below
921
+ });
922
+ const host: OperatorHost<Caller> = {
923
+ list: async () => [...sessions].map(([id, s]) =>
924
+ ({ id, name: s.name, group: s.project, phase: phaseOf(viewOf(s.state)), root: s.cwd })),
925
+ view: async (_caller, id) => viewOf(sessions.get(id)!.state),
926
+ async send(_caller, id, message, { delivery }) {
927
+ if (delivery === "interrupt") await client.cancelTurn(id);
928
+ try {
929
+ await client.startTurn({ sessionId: id, turnId: crypto.randomUUID(), input: message, config: configFor(id) });
930
+ } catch (error) {
931
+ if (/turnActive/.test(String(error))) throw new OperatorError("It is still working. Nothing was sent.");
932
+ throw error;
933
+ }
934
+ },
935
+ cancel: async (_caller, id) => void (await client.cancelTurn(id)),
936
+ async respond(_caller, id, answer) {
937
+ if (answer.kind === "question") await client.respondElicitation(id, answer.requestId, answer.outcome);
938
+ else await client.respondPermission(id, answer.requestId, answer.outcome);
939
+ },
940
+ start: async (_caller, { group, message }) => newSession(group, message), // optional
941
+ groups: async () => projects.map((p) => p.name), // optional
942
+ outcome: async (_caller, entry) => `changes: ${await diffStat(entry.root)}`, // optional
943
+ changed: (signal) => new Promise((resolve) => { // optional
944
+ const wake = () => { waiters.delete(wake); resolve(); };
945
+ waiters.add(wake);
946
+ signal.addEventListener("abort", wake, { once: true });
947
+ }),
948
+ };
949
+ const operator = createOperator(host);
950
+ ```
951
+
952
+ `viewOf` makes a session's view from the engine's folded state; a host that
953
+ keeps rows of its own builds the same `SessionView` (its messages, what it
954
+ waits on in the engine's request shapes). This host makes its own turn ids
955
+ and does not detect repeats, so a model that sends the same message twice is
956
+ told the session is busy. A host that wants to join a repeat instead (the
957
+ same caller, session and message while the turn that message started has not
958
+ ended) sends nothing and resolves `send` to `{ duplicate: true }`; `start`
959
+ returns its `SessionEntry` with `duplicate: true` for the same caller's same
960
+ task in the same project while that session sets up or its first turn runs
961
+ (`StartResult`). Only then does `wait: 0` look at the session, answering how
962
+ that turn stands, and a wait settle from the current view at once; a fresh
963
+ send or start answers "the agent is working", since your view may not show
964
+ its turn yet. `start` may return as soon as the session exists: until its
965
+ first turn begins, its view is `working` with no messages, and the wait
966
+ covers setup and the turn alike. When a send or a stop did something your
967
+ view cannot show (a message you held and replaced, or dropped before it was
968
+ sent), say it in one line: `send` resolves to `{ note }`, which
969
+ `send_message` says before the outcome, and `cancel` resolves to `{ note }`,
970
+ which `stop_session` answers with instead of waiting for the view to change.
971
+ `start` is optional, and without it there is no `start_session`.
972
+ `entry(caller, id)` is optional too: a host whose `list` holds only its
973
+ newest sessions gives the others by id there. It gets any reference that
974
+ names nothing listed, and may throw an `OperatorError` to refuse one in your
975
+ words (a session archived). `groups(caller)` is optional: every project a
976
+ session could start in, so `list_sessions` shows the ones with no session
977
+ yet. `extra: [tool({...})]` adds your own tools (a diff, an archive) beside
978
+ these; mark one that reaches past your host `openWorld` and one that may
979
+ lose work `destructive`. `changed` must remove what it registered when its
980
+ signal aborts; the operator aborts it after every look. A plan request you
981
+ build yourself uses the engine's `PLAN_OPTIONS` and `PLAN_TITLE`, exported
982
+ here, so `answer_request` reads it as a plan.
983
+
984
+ Access is yours too. `tools()` is the same for every caller (an assistant
985
+ keeps the list it got when it connected), so refuse a call around `call`, in
986
+ your words:
987
+
988
+ ```ts
989
+ import { OperatorError, type ToolSource } from "@zvada/agent-server/operator";
990
+
991
+ const tools: ToolSource<Caller> = {
992
+ tools: (caller) => operator.tools(caller),
993
+ async call(name, args, caller) {
994
+ const found = operator.tools(caller).find((tool) => tool.name === name);
995
+ if (found && !found.readOnly && !caller.canOperate) {
996
+ throw new OperatorError(`${name} needs operate access here. Nothing was done.`);
997
+ }
998
+ return operator.call(name, args, caller);
999
+ },
1000
+ };
1001
+ ```
1002
+
1003
+ Serve them over MCP (stateless Streamable HTTP) with `createMcpHandler`. It
1004
+ has no dependency and is not a server: your route authenticates and names the
1005
+ caller.
1006
+
1007
+ ```ts
1008
+ import { createMcpHandler } from "@zvada/agent-server/operator";
1009
+
1010
+ const mcp = createMcpHandler(tools, { name: "my-product", version: "1.0.0" });
1011
+ app.post("/mcp", async (c) => {
1012
+ const caller = await authenticate(c.req.header("authorization")); // yours: 401 if not
1013
+ const answer = await mcp(await c.req.json(), caller);
1014
+ return answer === null ? c.body(null, 202) : c.json(answer);
1015
+ });
1016
+ app.get("/mcp", (c) => c.body(null, 405));
1017
+ ```
1018
+
1019
+ A failed call reaches the model as an `isError` tool result, not a JSON-RPC
1020
+ error, so it reads the reason. Throw an `OperatorError` for words you mean
1021
+ the model to act on: its message goes through as it is. Any other error may
1022
+ carry an agent's or a repository's text, so it is answered as one quoted
1023
+ line (`The tool failed: "…"`); turn your own refusals into `OperatorError`s.
1024
+
712
1025
  ## Listen to the engine's diagnostics
713
1026
 
714
1027
  Pass `onDiagnostic` (registry/runtime/proxy options) and log what arrives:
715
- `interruptTimeout`, `sinkError`, `proxyUpstreamAuth`.
1028
+ `interruptTimeout`, `sinkError`, `proxyUpstreamAuth`, and `claudeSdkMismatch`:
1029
+ the Claude SDK that loaded (as it names itself when `query()` runs) and the
1030
+ CLI build it drives (its platform package's version) are different releases,
1031
+ said once per process with `detail: {sdkVersion, cliVersion, cliPath}` and on
1032
+ stderr. A package manager that lets another SDK in (bun says nothing of an
1033
+ exact peer) shows up here; the turn still runs.
716
1034
  These are the signals the engine deliberately does not fail turns over — a
717
1035
  product that doesn't surface them debugs blind.
718
1036
 
@@ -735,7 +1053,9 @@ open parts, then its frames live; omitted, from the head) until
735
1053
  `unsubscribe`, which ends the watch (a turn of this client's there is still
736
1054
  followed to its end); `subscribeAll()` is for observers: every session, live
737
1055
  from then, with no history (`session/subscribeAll` on the wire; `unsubscribeAll()`
738
- is `session/unsubscribeAll`). `joinTurn(sessionId, {fromSeq})` watches the
1056
+ is `session/unsubscribeAll`). The client follows every session from the
1057
+ call until `unsubscribeAll()`: a connection that drops before the answer asks
1058
+ the server it redials, and `subscribeAll()` resolves on that answer. `joinTurn(sessionId, {fromSeq})` watches the
739
1059
  session and joins the turn it runs (`undefined` when none): a handle that
740
1060
  yields the kept events from `fromSeq` (default: the turn's start), then the
741
1061
  turn's open parts, then live frames through its `turn.ended`, each once,
@@ -754,7 +1074,11 @@ with what the client kept of it. A redial subscribes again to each session
754
1074
  followed, from what the client holds, the running turns' first, and so does a
755
1075
  `session/overflow`: the notice a server sends when the connection fell
756
1076
  `maxBacklogBytes` (16 MiB) behind and it stopped streaming the session; what
757
- was dropped heals by replay and the open parts. A refused re-subscription
1077
+ was dropped heals by replay and the open parts. A connection is always told
1078
+ it overflowed, or closed: `listen` keeps Bun's own `backpressureLimit` 64 MiB
1079
+ above the bound, so the notice gets through, and a socket that still refuses
1080
+ a send (one frame larger than that headroom) is closed, which a client that
1081
+ reconnects heals by its redial and replay. Over stdio nothing is dropped. A refused re-subscription
758
1082
  fails the session's turns with `EventGapError` (`onEventGap`:
759
1083
  `session_missing`, or `subscription_refused`) instead of leaving them
760
1084
  waiting. When the answer says the turn it subscribed again for runs no more
@@ -783,10 +1107,15 @@ outage instead of going quiet: `disconnected` (with the reason), `reconnecting`
783
1107
  before each redial (`attempt`, `delayMs`, and the `error` the one before
784
1108
  failed with), `reconnected` (`attempts`, `downMs`, the new `initialize`, and
785
1109
  `serverChanged` when the server no longer holds the logs this client followed:
786
- another journal, none, or a volatile restart), `refused` (`reason`:
787
- `token_refused` or `token_required`) when the server refused a redial, which every
788
- redial would get, so the client stops and fails what waits with
789
- `ConnectionRefusedError`, and `closed` (`close()`, a connection that does not
1110
+ another journal, none, or a volatile restart), `refused` when the server
1111
+ refused the client, which every redial would get, so the client stops and
1112
+ fails what waits with `ConnectionRefusedError`: `reason` `token_refused` or
1113
+ `token_required` for a redial refused its token, or `protocol_mismatch`
1114
+ (with `protocolVersion`, this client's, and `supported`, the server's) for
1115
+ any handshake with a server of another wire protocol version, whose error is
1116
+ the `ProtocolVersionMismatchError` subclass (it carries the wire error's
1117
+ `code` and `data` too): only upgrading the older of the two helps, and `closed`
1118
+ (`close()`, a connection that does not
790
1119
  redial, redialing that gave up after `maxReconnectAttempts`, default 8,
791
1120
  `Infinity` redials until `close()`, or a refusal).
792
1121
  Handlers run before requests waiting on the redial are sent again. After
@@ -832,6 +1161,101 @@ platform it dials, never `$AGENT_SERVER_TOKEN`, which a listener's clients
832
1161
  present).
833
1162
  Subscriptions filter delivery; they are not an authorization boundary.
834
1163
 
1164
+ ## Test your integration for nothing
1165
+
1166
+ The `scripted` harness plays a script instead of a model, through the same
1167
+ runtime, server and client your product uses, under its own name, so your
1168
+ own code runs unchanged and costs nothing ([the steps](harnesses.md#the-scripted-harness)).
1169
+ A `call` step calls your real MCP server; `ask: true` goes through your
1170
+ permission handling; `echo: "config"` shows what your code sent.
1171
+
1172
+ ```ts
1173
+ const runtime = createAgentRuntime({
1174
+ harnesses: ["scripted"],
1175
+ scripted: {
1176
+ turn: scriptedQueue([
1177
+ { call: { server: "notes", tool: "search_notes", arguments: { query: "garden" } } },
1178
+ { say: "Found it." },
1179
+ { end: true },
1180
+ ]),
1181
+ },
1182
+ });
1183
+ ```
1184
+
1185
+ A product that spawns the stock program, or is not written in TypeScript,
1186
+ gives it a JSONL file instead, one step per line:
1187
+ `agent-server --script turns.jsonl --listen 4747`. `apps/agent-demo` runs
1188
+ its product checks this way: `bun run agent-demo -- --harness=scripted`.
1189
+
1190
+ ## What products got wrong, so you need not
1191
+
1192
+ Each of these was found in a product built on the engine, or measured against
1193
+ the agents themselves (LLP 0015). None needs code of your own to avoid.
1194
+
1195
+ **Sessions**
1196
+
1197
+ - **Close a session when you are done with it** (`closeSession`). Until then
1198
+ the engine keeps it bound to its harness and its process warm for the idle
1199
+ time (`idleTimeoutMs`, 5 minutes by default), and an ACP agent that cannot resume is never ended for idleness. One
1200
+ product never closed any. Remove what you made for the session (a Codex
1201
+ home) after the close answers: it answers once the agent's process has
1202
+ exited.
1203
+ - **Persist the native id** from `session.created` and pass it back as
1204
+ `resumeSessionId`. A wrong one fails every later turn of that `sessionId`
1205
+ on purpose; start a new `sessionId` to start over.
1206
+ - **Read how a reopened durable session's last turn ended from `getSession`**
1207
+ (`lastTurn`: `stopReason`, and `error` with the category `server_restart`
1208
+ for a turn a restart cut off), not by replaying its history; and whether it
1209
+ still waits for `confirmSessionStopped` from `recoveryRequired`, never from
1210
+ that turn's words, which a confirmation does not change.
1211
+ - **Name a journal file from `JOURNAL_SCHEMA_VERSION`**
1212
+ ([durable sessions](durable-sessions.md)), not from a number you copied.
1213
+
1214
+ **Logins and credentials**
1215
+
1216
+ - **Sign in through the engine** (`auth/login`), not by typing a CLI command
1217
+ into a terminal. The engine learns of a login made elsewhere only at the
1218
+ next status read.
1219
+ - **Hold a credential with [`./accounts`](#hold-the-login-yourself-for-sandboxes-and-other-devices),**
1220
+ not with a copy of it. One product rewrote about 550 lines of it.
1221
+ - **Offer models from `models/list`,** not from the built-in catalog: the
1222
+ live list belongs to the login and its route.
1223
+ - **Do not check the Claude SDK's version yourself.** The engine says when the
1224
+ SDK and the CLI build differ (`claudeSdkMismatch`, above); pin the CLI with
1225
+ `provision.pins` when your bundle carries its own SDK.
1226
+
1227
+ **What the agent may do**
1228
+
1229
+ - **Limit Claude's own tools with the SDK's `tools` list,** not with a
1230
+ `toolPolicy` alone: the policy hears only what Claude asks about, and a read
1231
+ in the turn's folder is not asked ([a product's own agent](#a-products-own-agent-on-the-persons-own-login)).
1232
+ - **Do not assume a permission mode means the same on both agents.**
1233
+ `accept_edits` lets Codex run shell writes unasked, `plan` stops writes on
1234
+ neither once a call is approved, and Codex never asks before a read
1235
+ ([the table](harnesses.md#what-each-permission-mode-does-per-agent)). Under
1236
+ `bypass_permissions` your policy and your approvals never run at all.
1237
+ - **Choose what a turn inherits with `inheritConfig`,** not with raw SDK
1238
+ options: `none` for a repository you do not trust.
1239
+ - **On Codex, mark your MCP tools as what they are.** A tool marked
1240
+ `readOnlyHint` is never asked about, any other always is.
1241
+
1242
+ **Reading the stream**
1243
+
1244
+ - **Read `mcp.server` and `mcp.tool`** on a tool part or a permission request,
1245
+ not the spelling of `toolName`, which differs by agent.
1246
+ - **Read `capabilities.ignoredSettings` and `execution.notApplied`,** not a
1247
+ table of your own of what each agent supports.
1248
+ - **Read an error's `category`,** not its text. One product classified
1249
+ failures by regular expressions on a provider's words.
1250
+ - **Ask `isFailureStopReason`** whether a turn failed. `max_tokens`,
1251
+ `max_turn_requests`, `refusal` and `cancelled` are clean ends; one product
1252
+ treated everything but `end_turn` as an interruption.
1253
+ - **Test against the engine, not a stand-in of your own,** where you can: the
1254
+ free scenario (`bun run harness -- --harness=codex-app-server
1255
+ --scenario=codex-tools-off`) and `apps/agent-demo` run real CLIs. Three
1256
+ products wrote a scripted agent of their own; the engine now ships one,
1257
+ the `scripted` harness ([test your integration for nothing](#test-your-integration-for-nothing)).
1258
+
835
1259
  ---
836
1260
 
837
1261
  Something here wrong, unclear or missing? [Report it to the maintainers](feedback.md).