@zvada/agent-server 0.3.22 → 0.3.23

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (348) hide show
  1. package/CHANGELOG.md +261 -0
  2. package/dist/types/accounts/chatgpt.d.ts +1 -1
  3. package/dist/types/accounts/chatgpt.d.ts.map +1 -1
  4. package/dist/types/accounts/http.d.ts +2 -4
  5. package/dist/types/accounts/http.d.ts.map +1 -1
  6. package/dist/types/client/client.d.ts +37 -11
  7. package/dist/types/client/client.d.ts.map +1 -1
  8. package/dist/types/client/connection.d.ts +64 -13
  9. package/dist/types/client/connection.d.ts.map +1 -1
  10. package/dist/types/client/index.d.ts +1 -1
  11. package/dist/types/client/index.d.ts.map +1 -1
  12. package/dist/types/client/logins.d.ts +2 -1
  13. package/dist/types/client/logins.d.ts.map +1 -1
  14. package/dist/types/client/streams.d.ts +9 -3
  15. package/dist/types/client/streams.d.ts.map +1 -1
  16. package/dist/types/client/turns.d.ts +1 -1
  17. package/dist/types/client/turns.d.ts.map +1 -1
  18. package/dist/types/core/agents/acp/acp-agent.d.ts +34 -1
  19. package/dist/types/core/agents/acp/acp-agent.d.ts.map +1 -1
  20. package/dist/types/core/agents/acp/adapter.d.ts.map +1 -1
  21. package/dist/types/core/agents/acp/client.d.ts +12 -3
  22. package/dist/types/core/agents/acp/client.d.ts.map +1 -1
  23. package/dist/types/core/agents/acp/mappings.d.ts +8 -2
  24. package/dist/types/core/agents/acp/mappings.d.ts.map +1 -1
  25. package/dist/types/core/agents/base.d.ts +22 -8
  26. package/dist/types/core/agents/base.d.ts.map +1 -1
  27. package/dist/types/core/agents/claude-code/adapter.d.ts +7 -0
  28. package/dist/types/core/agents/claude-code/adapter.d.ts.map +1 -1
  29. package/dist/types/core/agents/claude-code/approvals.d.ts +4 -1
  30. package/dist/types/core/agents/claude-code/approvals.d.ts.map +1 -1
  31. package/dist/types/core/agents/claude-code/claude-agent.d.ts +16 -5
  32. package/dist/types/core/agents/claude-code/claude-agent.d.ts.map +1 -1
  33. package/dist/types/core/agents/claude-code/events.d.ts +9 -1
  34. package/dist/types/core/agents/claude-code/events.d.ts.map +1 -1
  35. package/dist/types/core/agents/claude-code/login.d.ts +4 -1
  36. package/dist/types/core/agents/claude-code/login.d.ts.map +1 -1
  37. package/dist/types/core/agents/claude-code/mcp.d.ts +21 -7
  38. package/dist/types/core/agents/claude-code/mcp.d.ts.map +1 -1
  39. package/dist/types/core/agents/claude-code/models.d.ts +5 -1
  40. package/dist/types/core/agents/claude-code/models.d.ts.map +1 -1
  41. package/dist/types/core/agents/claude-code/options.d.ts +10 -4
  42. package/dist/types/core/agents/claude-code/options.d.ts.map +1 -1
  43. package/dist/types/core/agents/claude-code/outcome.d.ts +3 -5
  44. package/dist/types/core/agents/claude-code/outcome.d.ts.map +1 -1
  45. package/dist/types/core/agents/claude-code/results.d.ts +16 -0
  46. package/dist/types/core/agents/claude-code/results.d.ts.map +1 -0
  47. package/dist/types/core/agents/claude-code/sdk-pair.d.ts +13 -0
  48. package/dist/types/core/agents/claude-code/sdk-pair.d.ts.map +1 -0
  49. package/dist/types/core/agents/claude-code/session.d.ts +50 -12
  50. package/dist/types/core/agents/claude-code/session.d.ts.map +1 -1
  51. package/dist/types/core/agents/claude-code/spend.d.ts +2 -1
  52. package/dist/types/core/agents/claude-code/spend.d.ts.map +1 -1
  53. package/dist/types/core/agents/claude-code/tools.d.ts +26 -3
  54. package/dist/types/core/agents/claude-code/tools.d.ts.map +1 -1
  55. package/dist/types/core/agents/codex-app-server/adapter.d.ts +2 -2
  56. package/dist/types/core/agents/codex-app-server/adapter.d.ts.map +1 -1
  57. package/dist/types/core/agents/codex-app-server/client.d.ts +12 -2
  58. package/dist/types/core/agents/codex-app-server/client.d.ts.map +1 -1
  59. package/dist/types/core/agents/codex-app-server/codex-agent.d.ts +58 -13
  60. package/dist/types/core/agents/codex-app-server/codex-agent.d.ts.map +1 -1
  61. package/dist/types/core/agents/codex-app-server/commands.d.ts +2 -2
  62. package/dist/types/core/agents/codex-app-server/commands.d.ts.map +1 -1
  63. package/dist/types/core/agents/codex-app-server/credentials.d.ts +5 -1
  64. package/dist/types/core/agents/codex-app-server/credentials.d.ts.map +1 -1
  65. package/dist/types/core/agents/codex-app-server/effort.d.ts +2 -1
  66. package/dist/types/core/agents/codex-app-server/effort.d.ts.map +1 -1
  67. package/dist/types/core/agents/codex-app-server/homes.d.ts +19 -0
  68. package/dist/types/core/agents/codex-app-server/homes.d.ts.map +1 -1
  69. package/dist/types/core/agents/codex-app-server/items.d.ts +27 -2
  70. package/dist/types/core/agents/codex-app-server/items.d.ts.map +1 -1
  71. package/dist/types/core/agents/codex-app-server/login.d.ts +4 -1
  72. package/dist/types/core/agents/codex-app-server/login.d.ts.map +1 -1
  73. package/dist/types/core/agents/codex-app-server/mcp.d.ts +15 -30
  74. package/dist/types/core/agents/codex-app-server/mcp.d.ts.map +1 -1
  75. package/dist/types/core/agents/codex-app-server/models.d.ts +3 -10
  76. package/dist/types/core/agents/codex-app-server/models.d.ts.map +1 -1
  77. package/dist/types/core/agents/codex-app-server/options.d.ts +27 -4
  78. package/dist/types/core/agents/codex-app-server/options.d.ts.map +1 -1
  79. package/dist/types/core/agents/codex-app-server/plan-approval.d.ts +2 -1
  80. package/dist/types/core/agents/codex-app-server/plan-approval.d.ts.map +1 -1
  81. package/dist/types/core/agents/codex-app-server/protocol.d.ts +16 -3
  82. package/dist/types/core/agents/codex-app-server/protocol.d.ts.map +1 -1
  83. package/dist/types/core/agents/codex-app-server/requests.d.ts.map +1 -1
  84. package/dist/types/core/agents/codex-app-server/session.d.ts +68 -40
  85. package/dist/types/core/agents/codex-app-server/session.d.ts.map +1 -1
  86. package/dist/types/core/agents/codex-app-server/subagents.d.ts +9 -4
  87. package/dist/types/core/agents/codex-app-server/subagents.d.ts.map +1 -1
  88. package/dist/types/core/agents/codex-app-server/thread-settings.d.ts +3 -2
  89. package/dist/types/core/agents/codex-app-server/thread-settings.d.ts.map +1 -1
  90. package/dist/types/core/agents/codex-app-server/turn-items.d.ts +2 -1
  91. package/dist/types/core/agents/codex-app-server/turn-items.d.ts.map +1 -1
  92. package/dist/types/core/agents/codex-app-server/turn.d.ts +31 -8
  93. package/dist/types/core/agents/codex-app-server/turn.d.ts.map +1 -1
  94. package/dist/types/core/agents/codex-app-server/user-login.d.ts +28 -0
  95. package/dist/types/core/agents/codex-app-server/user-login.d.ts.map +1 -0
  96. package/dist/types/core/agents/credentials.d.ts +3 -1
  97. package/dist/types/core/agents/credentials.d.ts.map +1 -1
  98. package/dist/types/core/agents/diffs.d.ts +9 -0
  99. package/dist/types/core/agents/diffs.d.ts.map +1 -0
  100. package/dist/types/core/agents/elicitation.d.ts +3 -2
  101. package/dist/types/core/agents/elicitation.d.ts.map +1 -1
  102. package/dist/types/core/agents/login.d.ts +6 -0
  103. package/dist/types/core/agents/login.d.ts.map +1 -1
  104. package/dist/types/core/agents/mcp-config.d.ts +0 -4
  105. package/dist/types/core/agents/mcp-config.d.ts.map +1 -1
  106. package/dist/types/core/agents/process-pool.d.ts +193 -0
  107. package/dist/types/core/agents/process-pool.d.ts.map +1 -0
  108. package/dist/types/core/agents/scripted/adapter.d.ts +68 -0
  109. package/dist/types/core/agents/scripted/adapter.d.ts.map +1 -0
  110. package/dist/types/core/agents/scripted/mcp-call.d.ts +56 -0
  111. package/dist/types/core/agents/scripted/mcp-call.d.ts.map +1 -0
  112. package/dist/types/core/agents/scripted/scripted-agent.d.ts +73 -0
  113. package/dist/types/core/agents/scripted/scripted-agent.d.ts.map +1 -0
  114. package/dist/types/core/agents/scripted/scripts.d.ts +29 -0
  115. package/dist/types/core/agents/scripted/scripts.d.ts.map +1 -0
  116. package/dist/types/core/agents/scripted/steps.d.ts +132 -0
  117. package/dist/types/core/agents/scripted/steps.d.ts.map +1 -0
  118. package/dist/types/core/agents/session-agent.d.ts +49 -6
  119. package/dist/types/core/agents/session-agent.d.ts.map +1 -1
  120. package/dist/types/core/diagnostics.d.ts +4 -1
  121. package/dist/types/core/diagnostics.d.ts.map +1 -1
  122. package/dist/types/core/index.d.ts +5 -0
  123. package/dist/types/core/index.d.ts.map +1 -1
  124. package/dist/types/core/presets.d.ts +32 -6
  125. package/dist/types/core/presets.d.ts.map +1 -1
  126. package/dist/types/core/processes/lifeline.d.ts +0 -20
  127. package/dist/types/core/processes/lifeline.d.ts.map +1 -1
  128. package/dist/types/core/provision/index.d.ts +2 -2
  129. package/dist/types/core/provision/index.d.ts.map +1 -1
  130. package/dist/types/core/provision/install-build.d.ts +2 -1
  131. package/dist/types/core/provision/install-build.d.ts.map +1 -1
  132. package/dist/types/core/provision/npm.d.ts +20 -8
  133. package/dist/types/core/provision/npm.d.ts.map +1 -1
  134. package/dist/types/core/provision/provisioner.d.ts +4 -1
  135. package/dist/types/core/provision/provisioner.d.ts.map +1 -1
  136. package/dist/types/core/provision/tools.d.ts +2 -1
  137. package/dist/types/core/provision/tools.d.ts.map +1 -1
  138. package/dist/types/core/runtime/agent-runtime.d.ts +16 -8
  139. package/dist/types/core/runtime/agent-runtime.d.ts.map +1 -1
  140. package/dist/types/core/runtime/event-processor.d.ts +5 -1
  141. package/dist/types/core/runtime/event-processor.d.ts.map +1 -1
  142. package/dist/types/core/runtime/harness-clis.d.ts +9 -0
  143. package/dist/types/core/runtime/harness-clis.d.ts.map +1 -1
  144. package/dist/types/core/runtime/harness-logins.d.ts +33 -5
  145. package/dist/types/core/runtime/harness-logins.d.ts.map +1 -1
  146. package/dist/types/core/runtime/model-lists.d.ts +2 -0
  147. package/dist/types/core/runtime/model-lists.d.ts.map +1 -1
  148. package/dist/types/core/runtime/permission-policy.d.ts +5 -3
  149. package/dist/types/core/runtime/permission-policy.d.ts.map +1 -1
  150. package/dist/types/core/runtime/request-broker.d.ts +2 -1
  151. package/dist/types/core/runtime/request-broker.d.ts.map +1 -1
  152. package/dist/types/core/runtime/turn.d.ts +12 -1
  153. package/dist/types/core/runtime/turn.d.ts.map +1 -1
  154. package/dist/types/core/utils/deadline.d.ts +6 -0
  155. package/dist/types/core/utils/deadline.d.ts.map +1 -1
  156. package/dist/types/core/utils/errors.d.ts +7 -1
  157. package/dist/types/core/utils/errors.d.ts.map +1 -1
  158. package/dist/types/operator/operator.d.ts.map +1 -1
  159. package/dist/types/operator/render.d.ts +6 -4
  160. package/dist/types/operator/render.d.ts.map +1 -1
  161. package/dist/types/protocol/auth.d.ts +54 -24
  162. package/dist/types/protocol/auth.d.ts.map +1 -1
  163. package/dist/types/protocol/clis.d.ts +14 -7
  164. package/dist/types/protocol/clis.d.ts.map +1 -1
  165. package/dist/types/protocol/config.d.ts +2 -0
  166. package/dist/types/protocol/config.d.ts.map +1 -1
  167. package/dist/types/protocol/conversation.d.ts +40 -3
  168. package/dist/types/protocol/conversation.d.ts.map +1 -1
  169. package/dist/types/protocol/credentials.d.ts +7 -0
  170. package/dist/types/protocol/credentials.d.ts.map +1 -1
  171. package/dist/types/protocol/execution.d.ts +2 -1
  172. package/dist/types/protocol/execution.d.ts.map +1 -1
  173. package/dist/types/protocol/factories.d.ts +12 -2
  174. package/dist/types/protocol/factories.d.ts.map +1 -1
  175. package/dist/types/protocol/harness.d.ts +6 -2
  176. package/dist/types/protocol/harness.d.ts.map +1 -1
  177. package/dist/types/protocol/history.d.ts +19 -0
  178. package/dist/types/protocol/history.d.ts.map +1 -1
  179. package/dist/types/protocol/lifecycle.d.ts +47 -8
  180. package/dist/types/protocol/lifecycle.d.ts.map +1 -1
  181. package/dist/types/protocol/model-catalog.d.ts.map +1 -1
  182. package/dist/types/protocol/models.d.ts +3 -0
  183. package/dist/types/protocol/models.d.ts.map +1 -1
  184. package/dist/types/protocol/parts.d.ts +14 -0
  185. package/dist/types/protocol/parts.d.ts.map +1 -1
  186. package/dist/types/protocol/tool-state.d.ts +12 -0
  187. package/dist/types/protocol/tool-state.d.ts.map +1 -1
  188. package/dist/types/protocol/wire-api.d.ts +129 -23
  189. package/dist/types/protocol/wire-api.d.ts.map +1 -1
  190. package/dist/types/protocol/wire.d.ts +70 -10
  191. package/dist/types/protocol/wire.d.ts.map +1 -1
  192. package/dist/types/server/acp/binding.d.ts +6 -1
  193. package/dist/types/server/acp/binding.d.ts.map +1 -1
  194. package/dist/types/server/acp/translate.d.ts +33 -7
  195. package/dist/types/server/acp/translate.d.ts.map +1 -1
  196. package/dist/types/server/agent-server.d.ts +6 -0
  197. package/dist/types/server/agent-server.d.ts.map +1 -1
  198. package/dist/types/server/feedback.d.ts +2 -1
  199. package/dist/types/server/feedback.d.ts.map +1 -1
  200. package/dist/types/server/install.d.ts +11 -0
  201. package/dist/types/server/install.d.ts.map +1 -1
  202. package/dist/types/server/session-gate.d.ts +2 -1
  203. package/dist/types/server/session-gate.d.ts.map +1 -1
  204. package/dist/types/server/session-store.d.ts +1 -0
  205. package/dist/types/server/session-store.d.ts.map +1 -1
  206. package/dist/types/server/subscriptions.d.ts +2 -1
  207. package/dist/types/server/subscriptions.d.ts.map +1 -1
  208. package/dist/types/server/transports.d.ts.map +1 -1
  209. package/dist/types/sync/fit.d.ts +8 -7
  210. package/dist/types/sync/fit.d.ts.map +1 -1
  211. package/dist/types/sync/history-sqlite.d.ts.map +1 -1
  212. package/dist/types/sync/index.d.ts +1 -0
  213. package/dist/types/sync/index.d.ts.map +1 -1
  214. package/dist/types/sync/journal-sqlite.d.ts +2 -1
  215. package/dist/types/sync/journal-sqlite.d.ts.map +1 -1
  216. package/dist/types/sync/journal.d.ts +11 -3
  217. package/dist/types/sync/journal.d.ts.map +1 -1
  218. package/dist/types/sync/projection.d.ts +6 -0
  219. package/dist/types/sync/projection.d.ts.map +1 -1
  220. package/dist/types/sync/recovery.d.ts +2 -1
  221. package/dist/types/sync/recovery.d.ts.map +1 -1
  222. package/dist/types/sync/schema.d.ts +10 -0
  223. package/dist/types/sync/schema.d.ts.map +1 -1
  224. package/dist/types/sync/sql.d.ts +2 -1
  225. package/dist/types/sync/sql.d.ts.map +1 -1
  226. package/docs/consuming.md +278 -28
  227. package/docs/deploy.md +36 -8
  228. package/docs/durable-sessions.md +35 -5
  229. package/docs/harnesses.md +385 -24
  230. package/package.json +6 -1
  231. package/src/accounts/chatgpt.ts +2 -2
  232. package/src/accounts/http.ts +2 -16
  233. package/src/client/client.ts +92 -31
  234. package/src/client/connection.ts +103 -22
  235. package/src/client/index.ts +1 -0
  236. package/src/client/logins.ts +1 -1
  237. package/src/client/streams.ts +12 -4
  238. package/src/client/turns.ts +1 -1
  239. package/src/core/agents/acp/acp-agent.ts +181 -52
  240. package/src/core/agents/acp/adapter.ts +9 -1
  241. package/src/core/agents/acp/client.ts +16 -4
  242. package/src/core/agents/acp/mappings.ts +27 -0
  243. package/src/core/agents/base.ts +25 -10
  244. package/src/core/agents/claude-code/adapter.ts +47 -17
  245. package/src/core/agents/claude-code/approvals.ts +6 -5
  246. package/src/core/agents/claude-code/claude-agent.ts +60 -30
  247. package/src/core/agents/claude-code/events.ts +11 -1
  248. package/src/core/agents/claude-code/login.ts +14 -2
  249. package/src/core/agents/claude-code/mcp.ts +31 -15
  250. package/src/core/agents/claude-code/models.ts +7 -2
  251. package/src/core/agents/claude-code/options.ts +11 -3
  252. package/src/core/agents/claude-code/outcome.ts +10 -2
  253. package/src/core/agents/claude-code/results.ts +73 -0
  254. package/src/core/agents/claude-code/sdk-pair.ts +66 -0
  255. package/src/core/agents/claude-code/session.ts +166 -37
  256. package/src/core/agents/claude-code/spend.ts +1 -1
  257. package/src/core/agents/claude-code/tools.ts +108 -12
  258. package/src/core/agents/codex-app-server/adapter.ts +37 -12
  259. package/src/core/agents/codex-app-server/client.ts +37 -8
  260. package/src/core/agents/codex-app-server/codex-agent.ts +115 -50
  261. package/src/core/agents/codex-app-server/commands.ts +2 -2
  262. package/src/core/agents/codex-app-server/credentials.ts +10 -5
  263. package/src/core/agents/codex-app-server/effort.ts +1 -1
  264. package/src/core/agents/codex-app-server/homes.ts +43 -1
  265. package/src/core/agents/codex-app-server/items.ts +219 -31
  266. package/src/core/agents/codex-app-server/login.ts +14 -2
  267. package/src/core/agents/codex-app-server/mcp.ts +47 -32
  268. package/src/core/agents/codex-app-server/models.ts +9 -8
  269. package/src/core/agents/codex-app-server/options.ts +69 -10
  270. package/src/core/agents/codex-app-server/plan-approval.ts +1 -1
  271. package/src/core/agents/codex-app-server/protocol.ts +14 -4
  272. package/src/core/agents/codex-app-server/requests.ts +14 -6
  273. package/src/core/agents/codex-app-server/session.ts +151 -113
  274. package/src/core/agents/codex-app-server/subagents.ts +21 -14
  275. package/src/core/agents/codex-app-server/thread-settings.ts +18 -8
  276. package/src/core/agents/codex-app-server/turn-items.ts +1 -1
  277. package/src/core/agents/codex-app-server/turn.ts +79 -32
  278. package/src/core/agents/codex-app-server/user-login.ts +107 -0
  279. package/src/core/agents/credentials.ts +5 -2
  280. package/src/core/agents/diffs.ts +25 -0
  281. package/src/core/agents/elicitation.ts +2 -2
  282. package/src/core/agents/login.ts +6 -0
  283. package/src/core/agents/mcp-config.ts +2 -2
  284. package/src/core/agents/process-pool.ts +432 -0
  285. package/src/core/agents/scripted/adapter.ts +142 -0
  286. package/src/core/agents/scripted/mcp-call.ts +134 -0
  287. package/src/core/agents/scripted/scripted-agent.ts +418 -0
  288. package/src/core/agents/scripted/scripts.ts +171 -0
  289. package/src/core/agents/scripted/steps.ts +127 -0
  290. package/src/core/agents/session-agent.ts +105 -8
  291. package/src/core/diagnostics.ts +9 -1
  292. package/src/core/index.ts +11 -0
  293. package/src/core/presets.ts +99 -14
  294. package/src/core/processes/lifeline.ts +99 -25
  295. package/src/core/provision/index.ts +1 -2
  296. package/src/core/provision/install-build.ts +4 -1
  297. package/src/core/provision/npm.ts +309 -97
  298. package/src/core/provision/provisioner.ts +22 -8
  299. package/src/core/provision/tools.ts +44 -19
  300. package/src/core/runtime/agent-runtime.ts +48 -18
  301. package/src/core/runtime/event-processor.ts +18 -2
  302. package/src/core/runtime/harness-clis.ts +36 -1
  303. package/src/core/runtime/harness-logins.ts +82 -31
  304. package/src/core/runtime/model-lists.ts +1 -1
  305. package/src/core/runtime/permission-policy.ts +4 -3
  306. package/src/core/runtime/request-broker.ts +1 -1
  307. package/src/core/runtime/turn.ts +51 -3
  308. package/src/core/utils/deadline.ts +23 -0
  309. package/src/core/utils/errors.ts +11 -4
  310. package/src/operator/operator.ts +8 -4
  311. package/src/operator/render.ts +46 -8
  312. package/src/protocol/auth.ts +30 -23
  313. package/src/protocol/clis.ts +12 -4
  314. package/src/protocol/credentials.ts +19 -0
  315. package/src/protocol/execution.ts +5 -0
  316. package/src/protocol/factories.ts +25 -3
  317. package/src/protocol/harness.ts +11 -1
  318. package/src/protocol/history.ts +20 -0
  319. package/src/protocol/lifecycle.ts +10 -1
  320. package/src/protocol/model-catalog.ts +19 -8
  321. package/src/protocol/parts.ts +12 -1
  322. package/src/protocol/tool-state.ts +14 -1
  323. package/src/protocol/wire.ts +14 -0
  324. package/src/server/acp/binding.ts +113 -23
  325. package/src/server/acp/translate.ts +161 -8
  326. package/src/server/agent-server.ts +10 -1
  327. package/src/server/bin.ts +83 -9
  328. package/src/server/feedback.ts +1 -1
  329. package/src/server/install.ts +82 -4
  330. package/src/server/session-gate.ts +1 -1
  331. package/src/server/session-store.ts +5 -1
  332. package/src/server/subscriptions.ts +1 -1
  333. package/src/server/transports.ts +14 -0
  334. package/src/sync/fit.ts +115 -28
  335. package/src/sync/history-sqlite.ts +6 -2
  336. package/src/sync/index.ts +1 -0
  337. package/src/sync/journal-sqlite.ts +20 -2
  338. package/src/sync/journal.ts +10 -2
  339. package/src/sync/projection.ts +10 -0
  340. package/src/sync/recovery.ts +11 -4
  341. package/src/sync/schema.ts +7 -5
  342. package/src/sync/sql.ts +1 -1
  343. package/dist/types/core/agents/claude-code/session-pool.d.ts +0 -36
  344. package/dist/types/core/agents/claude-code/session-pool.d.ts.map +0 -1
  345. package/dist/types/core/agents/session-pool.d.ts +0 -41
  346. package/dist/types/core/agents/session-pool.d.ts.map +0 -1
  347. package/src/core/agents/claude-code/session-pool.ts +0 -136
  348. package/src/core/agents/session-pool.ts +0 -111
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
@@ -514,6 +550,14 @@ the turn ends. A command whose stop could not be confirmed is not closed as
514
550
  cancelled: its tool part fails with `TOOL_OUTCOME_UNKNOWN`, a failure the
515
551
  harness reports itself (no `closure`).
516
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
+
517
561
  Embedded `runtime.cancel(harness, sessionId)` cancels the session's active
518
562
  turn without a turn ID check. Prefer a per-turn `AbortSignal` when cancellation
519
563
  can arrive late; a completed turn's signal is detached before the next turn.
@@ -547,7 +591,7 @@ CLI's `--inherit-config`, choose how much (LLP 0001, D17):
547
591
  | Level | Claude Code | Codex app-server |
548
592
  | --- | --- | --- |
549
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 |
550
- | `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 |
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) |
551
595
  | `none` | only the servers the host and the turn name | as `project`, without the repository's `AGENTS.md` |
552
596
 
553
597
  Choose by whose machine and whose repository it is. A desktop product that
@@ -571,9 +615,18 @@ At `project` and `none` every Codex turn needs `config.env.CODEX_HOME`, an
571
615
  existing absolute folder of the session's own: never the user's `~/.codex`,
572
616
  never another session's. A turn without one fails `invalid_request` before
573
617
  Codex starts. The engine owns that home's `mcp_servers` table, as for
574
- per-turn MCP in a home below. A fresh home has no login: hand one over with
575
- [`credentials`](harnesses.md#host-managed-codex-authentication) or the turn's
576
- `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
577
630
  `~/.agents/skills` at every level; turn one off by name in the home you
578
631
  supply (`[[skills.config]]` with `enabled = false`).
579
632
 
@@ -583,6 +636,89 @@ On Claude a `disableTools` turn runs at `none` whatever the level.
583
636
  auto-memory and the connectors. An ACP agent loads what its launch command
584
637
  says.
585
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
+
586
722
  ## Own your session resources
587
723
 
588
724
  ### Configure MCP between turns
@@ -659,7 +795,8 @@ every Codex turn names one). An existing, absolute, session-specific
659
795
  directory, where the engine writes the turn's servers. Create it with mode
660
796
  `0700`, retain it while
661
797
  the conversation may resume, and delete it when that logical session is
662
- 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
663
800
  it between sessions or use the operator's normal Codex home.
664
801
 
665
802
  This isolates writable MCP configuration and conversation state; it does not
@@ -674,11 +811,11 @@ can use an embedded server's external authentication instead. Without
674
811
  `--codex-home`, at `--inherit-config=all`, the CLI's Codex turns run in the
675
812
  user's own home with their `--mcp` servers in the thread's config.
676
813
  The ACP **server binding** (`createAcpAgentApp` /
677
- `agent-server --acp --harness codex-app-server`) has no per-session environment
678
- resource seam in this release. It rejects supplied Codex MCP servers explicitly
679
- at `session/new` or `session/resume`. Use the engine or standard JSON-RPC API
680
- for that combination. This limitation is separate
681
- 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.
682
819
 
683
820
  An explicitly supplied `CODEX_HOME` gives the engine ownership of that home's
684
821
  user-layer `mcp_servers` table: each turn replaces that table, including
@@ -706,9 +843,11 @@ automatically replayed.
706
843
  After thawing a VM, call `runtime.invalidateMcpConnections()` before admitting
707
844
  new turns. Drain active turns before suspending the host. This embed-tier
708
845
  lifecycle signal retains conversation state and turn-admission receipts.
709
- Before the next prompt, the Claude and Codex app-server harnesses replace
710
- retained subprocesses and strictly resume their saved conversations, using
711
- 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.
712
851
  Missing history fails with `resume_failed`; it never silently starts an empty
713
852
  conversation. Ordinary warm turns still reuse the process.
714
853
 
@@ -886,7 +1025,12 @@ line (`The tool failed: "…"`); turn your own refusals into `OperatorError`s.
886
1025
  ## Listen to the engine's diagnostics
887
1026
 
888
1027
  Pass `onDiagnostic` (registry/runtime/proxy options) and log what arrives:
889
- `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.
890
1034
  These are the signals the engine deliberately does not fail turns over — a
891
1035
  product that doesn't surface them debugs blind.
892
1036
 
@@ -909,7 +1053,9 @@ open parts, then its frames live; omitted, from the head) until
909
1053
  `unsubscribe`, which ends the watch (a turn of this client's there is still
910
1054
  followed to its end); `subscribeAll()` is for observers: every session, live
911
1055
  from then, with no history (`session/subscribeAll` on the wire; `unsubscribeAll()`
912
- 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
913
1059
  session and joins the turn it runs (`undefined` when none): a handle that
914
1060
  yields the kept events from `fromSeq` (default: the turn's start), then the
915
1061
  turn's open parts, then live frames through its `turn.ended`, each once,
@@ -928,7 +1074,11 @@ with what the client kept of it. A redial subscribes again to each session
928
1074
  followed, from what the client holds, the running turns' first, and so does a
929
1075
  `session/overflow`: the notice a server sends when the connection fell
930
1076
  `maxBacklogBytes` (16 MiB) behind and it stopped streaming the session; what
931
- 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
932
1082
  fails the session's turns with `EventGapError` (`onEventGap`:
933
1083
  `session_missing`, or `subscription_refused`) instead of leaving them
934
1084
  waiting. When the answer says the turn it subscribed again for runs no more
@@ -957,10 +1107,15 @@ outage instead of going quiet: `disconnected` (with the reason), `reconnecting`
957
1107
  before each redial (`attempt`, `delayMs`, and the `error` the one before
958
1108
  failed with), `reconnected` (`attempts`, `downMs`, the new `initialize`, and
959
1109
  `serverChanged` when the server no longer holds the logs this client followed:
960
- another journal, none, or a volatile restart), `refused` (`reason`:
961
- `token_refused` or `token_required`) when the server refused a redial, which every
962
- redial would get, so the client stops and fails what waits with
963
- `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
964
1119
  redial, redialing that gave up after `maxReconnectAttempts`, default 8,
965
1120
  `Infinity` redials until `close()`, or a refusal).
966
1121
  Handlers run before requests waiting on the redial are sent again. After
@@ -1006,6 +1161,101 @@ platform it dials, never `$AGENT_SERVER_TOKEN`, which a listener's clients
1006
1161
  present).
1007
1162
  Subscriptions filter delivery; they are not an authorization boundary.
1008
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
+
1009
1259
  ---
1010
1260
 
1011
1261
  Something here wrong, unclear or missing? [Report it to the maintainers](feedback.md).
package/docs/deploy.md CHANGED
@@ -49,8 +49,15 @@ only, and the log says so once.
49
49
 
50
50
  **A product that bundles the Claude SDK** (an ESM or single-file build of its
51
51
  own) sets `provision.pins.claude` to the SDK's version: nothing on disk says
52
- which SDK runs, so the engine runs the CLI of its own pin and logs that once.
53
- Within a compiled `agent-server` binary the pin is the SDK it bundles.
52
+ which SDK runs, so the engine runs the CLI of its own pin and logs that once,
53
+ naming the folder it looked up from. The engine looks from where its own
54
+ module (or the bundle holding it) is, under Bun, Node's ESM (tsx, an ESM
55
+ bundle) and CJS alike, never from the working folder. Within a compiled
56
+ `agent-server` binary the pin is the SDK it bundles. When the SDK that
57
+ loaded and the CLI build it drives are different releases, the engine says
58
+ so once, on stderr and as the `claudeSdkMismatch` diagnostic
59
+ ([consuming.md](consuming.md#listen-to-the-engines-diagnostics)); the turn
60
+ still runs.
54
61
 
55
62
  Pins live in `src/core/provision/pins.ts`: the claude pin tracks the
56
63
  lockfile's `@anthropic-ai/claude-agent-sdk` version (test-enforced); the codex
@@ -62,9 +69,18 @@ test-enforced).
62
69
  image layers and shared volumes dedupe naturally. Processes that cold-start
63
70
  together on one cache each download, and the build's atomic rename leaves one
64
71
  copy (four at once took 15.8 s instead of 4.9 s): bake the CLIs into the
65
- image instead. A request that gets no response within 30 s (headers or
66
- body), a download that receives nothing for 30 s, or a `tar` still running
67
- after 5 min fails rather than holding a turn. Each use of a build is
72
+ image instead. A download that is cut (a reset connection, nothing
73
+ received for 30 s, or an end short of its stated size) goes on from the
74
+ bytes it has with an HTTP `Range` request, or starts over where the server
75
+ does not honour one; it gives up after five attempts in a row that get no
76
+ further into the file (25 in all), as a `network` failure saying how far it
77
+ got ("the transfer ended after 10485760 of 100276474 bytes"). The checksum is
78
+ checked once, over the whole file, so "Integrity mismatch" is said only of a
79
+ file that arrived whole (one put together from several responses is first
80
+ downloaded once more in one piece), and a build whose checksum is wrong is
81
+ never installed. The registry metadata is asked up to three times, waiting
82
+ 30 s, 60 s, then 90 s for its answer (headers and body); a `tar` still
83
+ running after 5 min fails rather than holding a turn. Each use of a build is
68
84
  recorded (again hourly while a process keeps resolving it), and after each
69
85
  download builds whose recorded use is 14 days old are removed: several
70
86
  products may share one cache, each keeping its own pins by using them.
@@ -102,7 +118,12 @@ await client.listClis(); // ready | missing | installing | failed | unmanaged, i
102
118
  ```
103
119
 
104
120
  `prepareClis` joins an install already running and answers once each CLI is
105
- ready or failed (`error` says why); it never throws for a failed install.
121
+ ready or failed (`error` says why, and `category` what failed, from the
122
+ error vocabulary: `network` for a registry that cannot be reached or answers
123
+ 5xx and for a transfer that was cut, so ask again later; `internal` for a
124
+ build whose checksum is wrong; `invalid_request` for an override that points
125
+ nowhere); it never throws for a failed install. A turn that fails on the
126
+ install carries the same category.
106
127
  Over the wire, `clis/prepare` answers at once (`installing`), since an
107
128
  install outlasts a request's timeout, and the client waits on `clis/progress`
108
129
  and `clis/list`. `missing` without a `version` means the server installs
@@ -166,7 +187,10 @@ remotely with `clis/prepare`, its progress streaming back.
166
187
 
167
188
  `agent-server install` respects `--harness a,b` (only fetch what you run) and
168
189
  `$AGENT_SERVER_CACHE_DIR` (e.g. point it at a persistent volume instead of
169
- baking).
190
+ baking). It says what each version is: Claude's is the Claude SDK package's
191
+ (`claude: Claude SDK package 0.3.288 (Claude Code 2.1.288) for linux-x64
192
+ ready: …`), Codex's its CLI's. A harness it installs nothing for (an ACP
193
+ agent such as `pi`, which runs from its launch command) is said as such.
170
194
 
171
195
  Measured (2026-10-31, `debian:bookworm-slim` arm64 under Docker, from a home
172
196
  connection): `install` of both CLIs 5 s; a cold sandbox prepared over the
@@ -203,7 +227,11 @@ agent-server install --platform darwin-arm64,darwin-x64 --dir build/agent-clis
203
227
  `--dir` writes the cache's layout into a new or empty folder (or one it wrote
204
228
  before; any other is refused, as staging opens what it writes to every
205
229
  user), makes the builds it staged readable by every user, never through a
206
- symlink, and leaves out the install's records; `--harness` selects
230
+ symlink, creates the folder and the parents of it that are missing readable
231
+ and traversable by every user (0755, whatever the umask: `install --dir
232
+ /opt/app/clis` as root in an image build leaves `/opt/app` reachable by the
233
+ runtime user; a folder that was there is left as it is), and leaves out the
234
+ install's records; `--harness` selects
207
235
  as usual. Where it runs, the app names the folder: `provision.bundleDirs`
208
236
  (or `$AGENT_SERVER_BUNDLE_DIR`, a path list). A bundle folder is used in
209
237
  every mode when it holds the version this engine runs, before the host and
@@ -70,7 +70,7 @@ file; serve other readers over the wire.
70
70
  | `turn/start` | Admission is committed (with the input) before the ack. A retry converges on the receipt: `deduplicated: true`, plus `terminal` once the turn ended. A redialing client re-sends a start whose ack it lost, unless the server's logs are new (a volatile restart). |
71
71
  | `events/replay` | Served from the journal, a page at a time; `hasMore` asks for the next. Closed sessions answer `unknownSession`, as on volatile servers. |
72
72
  | `turn/get` | A turn's receipt: `admitted`, `completed` or `interrupted`, its input and terminal event. |
73
- | `session/get` | `headSeq`, `nativeSessionId`, `closed`, `recoveryRequired`. |
73
+ | `session/get` | `headSeq`, `nativeSessionId`, `closed`, `recoveryRequired` (and `recoveryReason`), and `lastTurn`: the latest turn's `turnId`, with its `stopReason` and `error` once it ended (`server_restart` for one a restart cut off). |
74
74
  | `session/confirmStopped` | Lifts the fence a restart put on a session, fenced by `expectedHeadSeq`. |
75
75
  | `session/release` | Lets an idle session's agent go (its process, a Codex home it holds) and keeps the session open. Its next turn names its native conversation (`resumeRequired` until it does), as after a restart. Nothing is broadcast: another client of the session meets `resumeRequired` on its next turn. `released: false` for no open session by that id; `turnActive` while a turn runs. |
76
76
  | `history/*` | Opt-in (`history` option): the [history protocol](sync-history.md). |
@@ -93,7 +93,10 @@ refusal carries in `data` is typed by `WIRE_REFUSAL_DATA`, and
93
93
  | `unknownTurn` (-32013) | `turn/get` for a turn the session never admitted (`unknownSession` when the session itself is unknown). | |
94
94
 
95
95
  A request the journal cannot store (an id over 512 characters, input over the
96
- record limit, `includeRaw`) is `invalidParams`, never a server fault.
96
+ record limit, `includeRaw`) is `invalidParams`, never a server fault. Input
97
+ over the limit says both sizes in its message, `Input is N bytes; the durable
98
+ record limit is 8355840 bytes`: the record limit below, 8 MB less 32 KB, of
99
+ the input's canonical JSON.
97
100
 
98
101
  ## Guarantees
99
102
 
@@ -105,8 +108,25 @@ record limit, `includeRaw`) is `invalidParams`, never a server fault.
105
108
  2. **Event before delivery.** Each event commits (and advances its hash chain)
106
109
  before broadcast. `turn.ended` settles the receipt and `session.ended` closes
107
110
  the session in the same transaction. An event the journal cannot store is
108
- stored cut down to fit, marked `[agent-server: N bytes omitted to fit the
109
- journal]`, or as a notice in its place; the turn and other sessions go on.
111
+ stored cut down to fit, or as a notice in its place; the turn and other
112
+ sessions go on. Cutting takes the event's longest string first, until it
113
+ fits: text is cut, marked `[agent-server: N bytes omitted to fit the
114
+ journal]`; an image or file (an object whose `type` is `image` or `file`,
115
+ with base64 `data` and a `mimeType`: a tool result's `content` image, an
116
+ image or file part) is never cut, but replaced whole by text saying what it
117
+ was, `[agent-server: image/png image of N bytes omitted to fit the
118
+ journal]`: a `content` entry by a `text` entry, a part by a `text` part
119
+ with the same `id`. Its `_meta` holds the facts under
120
+ `OMITTED_BINARY_META_KEY` (`"agent-server/omittedBinary"`):
121
+ `{ type, mimeType, bytes, filename? }`, `bytes` the binary's decoded size.
122
+ What the journal keeps is what every client receives, live and on replay
123
+ alike: an entry too large for a record is the marker for everyone, and a
124
+ product that needs larger pictures delivers them outside the stream. A
125
+ checkpoint (`createCheckpoint`) replaces images and files the same way, largest first,
126
+ saying `omitted to fit this checkpoint`, until it fits `HISTORY_MAX_BYTES`
127
+ (8 MB); only text alone can still make one too large. A reader that opens a
128
+ history from a checkpoint sees its markers where a full replay sees the
129
+ images the events kept.
110
130
  3. **A decision follows its record.** The harness receives a permission
111
131
  decision only after `permission.resolved` is written; a failed write refuses
112
132
  the tool. Async sinks that must record a request before a reentrant response
@@ -134,7 +154,9 @@ record limit, `includeRaw`) is `invalidParams`, never a server fault.
134
154
  it; `not_verified`; `not_stopped`, it survived SIGKILL); a host checks it
135
155
  and confirms (`session/confirmStopped`). Either way the next turn resumes
136
156
  the native session explicitly (`resumeRequired` names it). The turn's error
137
- message says which it was.
157
+ message says which it was, and `session/get` says it without the history:
158
+ `lastTurn.error.category` is `server_restart`, and `recoveryRequired` is
159
+ whether the fence is still up.
138
160
 
139
161
  While the server lives, its lifeline (one `/bin/sh` per process, holding a
140
162
  pipe from it) stops every agent and tool it started when the server dies
@@ -170,6 +192,14 @@ started, until each is seen gone; `commits` and `checkpoints` serve branches
170
192
  and cached projections. `EventLog.append` is the one write path for execution, commits,
171
193
  imports and recovery.
172
194
 
195
+ The schema's number is exported: `JOURNAL_SCHEMA_VERSION` from
196
+ `@zvada/agent-server/sync`, which loads no SQLite driver. A product that
197
+ starts a new journal file per schema names the file from it
198
+ (`` `journal-${JOURNAL_SCHEMA_VERSION}.sqlite` ``) rather than from a number
199
+ of its own: a release that changes the schema then opens a new file for its
200
+ existing users too, where a hardcoded name would refuse their old one, which
201
+ a test on a fresh file never meets.
202
+
173
203
  ## Not covered
174
204
 
175
205
  - No product integration, public relay, deployment or credential exchange.