@zvada/agent-server 0.3.18 → 0.3.19

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 (572) hide show
  1. package/AGENTS.md +11 -26
  2. package/CHANGELOG.md +1005 -1
  3. package/README.md +35 -39
  4. package/dist/types/accounts/chatgpt.d.ts +34 -0
  5. package/dist/types/accounts/chatgpt.d.ts.map +1 -0
  6. package/dist/types/accounts/check.d.ts +24 -0
  7. package/dist/types/accounts/check.d.ts.map +1 -0
  8. package/dist/types/accounts/claude.d.ts +21 -0
  9. package/dist/types/accounts/claude.d.ts.map +1 -0
  10. package/dist/types/accounts/endpoint.d.ts +50 -0
  11. package/dist/types/accounts/endpoint.d.ts.map +1 -0
  12. package/dist/types/accounts/http.d.ts +38 -0
  13. package/dist/types/accounts/http.d.ts.map +1 -0
  14. package/dist/types/accounts/index.d.ts +6 -0
  15. package/dist/types/accounts/index.d.ts.map +1 -0
  16. package/dist/types/client/client.d.ts +272 -0
  17. package/dist/types/client/client.d.ts.map +1 -0
  18. package/dist/types/client/connection.d.ts +160 -0
  19. package/dist/types/client/connection.d.ts.map +1 -0
  20. package/dist/types/client/history.d.ts +8 -0
  21. package/dist/types/client/history.d.ts.map +1 -0
  22. package/dist/types/client/index.d.ts +5 -0
  23. package/dist/types/client/index.d.ts.map +1 -0
  24. package/dist/types/client/listeners.d.ts +8 -0
  25. package/dist/types/client/listeners.d.ts.map +1 -0
  26. package/dist/types/client/logins.d.ts +35 -0
  27. package/dist/types/client/logins.d.ts.map +1 -0
  28. package/dist/types/client/rpc.d.ts +46 -0
  29. package/dist/types/client/rpc.d.ts.map +1 -0
  30. package/dist/types/client/streams.d.ts +150 -0
  31. package/dist/types/client/streams.d.ts.map +1 -0
  32. package/dist/types/client/transports.d.ts +35 -0
  33. package/dist/types/client/transports.d.ts.map +1 -0
  34. package/dist/types/client/turns.d.ts +81 -0
  35. package/dist/types/client/turns.d.ts.map +1 -0
  36. package/dist/types/core/agents/acp/acp-agent.d.ts +68 -0
  37. package/dist/types/core/agents/acp/acp-agent.d.ts.map +1 -0
  38. package/dist/types/core/agents/acp/adapter.d.ts +39 -0
  39. package/dist/types/core/agents/acp/adapter.d.ts.map +1 -0
  40. package/dist/types/core/agents/acp/client.d.ts +90 -0
  41. package/dist/types/core/agents/acp/client.d.ts.map +1 -0
  42. package/dist/types/core/agents/acp/known-agents.d.ts +35 -0
  43. package/dist/types/core/agents/acp/known-agents.d.ts.map +1 -0
  44. package/dist/types/core/agents/acp/mappings.d.ts +46 -0
  45. package/dist/types/core/agents/acp/mappings.d.ts.map +1 -0
  46. package/dist/types/core/agents/acp/requests.d.ts +26 -0
  47. package/dist/types/core/agents/acp/requests.d.ts.map +1 -0
  48. package/dist/types/core/agents/attachments.d.ts +11 -0
  49. package/dist/types/core/agents/attachments.d.ts.map +1 -0
  50. package/dist/types/core/agents/base.d.ts +227 -0
  51. package/dist/types/core/agents/base.d.ts.map +1 -0
  52. package/dist/types/core/agents/claude-code/adapter.d.ts +58 -0
  53. package/dist/types/core/agents/claude-code/adapter.d.ts.map +1 -0
  54. package/dist/types/core/agents/claude-code/approvals.d.ts +26 -0
  55. package/dist/types/core/agents/claude-code/approvals.d.ts.map +1 -0
  56. package/dist/types/core/agents/claude-code/claude-agent.d.ts +70 -0
  57. package/dist/types/core/agents/claude-code/claude-agent.d.ts.map +1 -0
  58. package/dist/types/core/agents/claude-code/credentials.d.ts +54 -0
  59. package/dist/types/core/agents/claude-code/credentials.d.ts.map +1 -0
  60. package/dist/types/core/agents/claude-code/events.d.ts +42 -0
  61. package/dist/types/core/agents/claude-code/events.d.ts.map +1 -0
  62. package/dist/types/core/agents/claude-code/login.d.ts +61 -0
  63. package/dist/types/core/agents/claude-code/login.d.ts.map +1 -0
  64. package/dist/types/core/agents/claude-code/mcp.d.ts +52 -0
  65. package/dist/types/core/agents/claude-code/mcp.d.ts.map +1 -0
  66. package/dist/types/core/agents/claude-code/models.d.ts +30 -0
  67. package/dist/types/core/agents/claude-code/models.d.ts.map +1 -0
  68. package/dist/types/core/agents/claude-code/options.d.ts +183 -0
  69. package/dist/types/core/agents/claude-code/options.d.ts.map +1 -0
  70. package/dist/types/core/agents/claude-code/outcome.d.ts +50 -0
  71. package/dist/types/core/agents/claude-code/outcome.d.ts.map +1 -0
  72. package/dist/types/core/agents/claude-code/session-pool.d.ts +36 -0
  73. package/dist/types/core/agents/claude-code/session-pool.d.ts.map +1 -0
  74. package/dist/types/core/agents/claude-code/session.d.ts +148 -0
  75. package/dist/types/core/agents/claude-code/session.d.ts.map +1 -0
  76. package/dist/types/core/agents/claude-code/spawn.d.ts +29 -0
  77. package/dist/types/core/agents/claude-code/spawn.d.ts.map +1 -0
  78. package/dist/types/core/agents/claude-code/spend.d.ts +58 -0
  79. package/dist/types/core/agents/claude-code/spend.d.ts.map +1 -0
  80. package/dist/types/core/agents/claude-code/tools.d.ts +4 -0
  81. package/dist/types/core/agents/claude-code/tools.d.ts.map +1 -0
  82. package/dist/types/core/agents/claude-code/turn-usage.d.ts +52 -0
  83. package/dist/types/core/agents/claude-code/turn-usage.d.ts.map +1 -0
  84. package/dist/types/core/agents/claude-code/turn.d.ts +121 -0
  85. package/dist/types/core/agents/claude-code/turn.d.ts.map +1 -0
  86. package/dist/types/core/agents/codex-app-server/adapter.d.ts +59 -0
  87. package/dist/types/core/agents/codex-app-server/adapter.d.ts.map +1 -0
  88. package/dist/types/core/agents/codex-app-server/client.d.ts +116 -0
  89. package/dist/types/core/agents/codex-app-server/client.d.ts.map +1 -0
  90. package/dist/types/core/agents/codex-app-server/codex-agent.d.ts +113 -0
  91. package/dist/types/core/agents/codex-app-server/codex-agent.d.ts.map +1 -0
  92. package/dist/types/core/agents/codex-app-server/commands.d.ts +66 -0
  93. package/dist/types/core/agents/codex-app-server/commands.d.ts.map +1 -0
  94. package/dist/types/core/agents/codex-app-server/credentials.d.ts +49 -0
  95. package/dist/types/core/agents/codex-app-server/credentials.d.ts.map +1 -0
  96. package/dist/types/core/agents/codex-app-server/effort.d.ts +12 -0
  97. package/dist/types/core/agents/codex-app-server/effort.d.ts.map +1 -0
  98. package/dist/types/core/agents/codex-app-server/events.d.ts +45 -0
  99. package/dist/types/core/agents/codex-app-server/events.d.ts.map +1 -0
  100. package/dist/types/core/agents/codex-app-server/homes.d.ts +20 -0
  101. package/dist/types/core/agents/codex-app-server/homes.d.ts.map +1 -0
  102. package/dist/types/core/agents/codex-app-server/input.d.ts +26 -0
  103. package/dist/types/core/agents/codex-app-server/input.d.ts.map +1 -0
  104. package/dist/types/core/agents/codex-app-server/items.d.ts +31 -0
  105. package/dist/types/core/agents/codex-app-server/items.d.ts.map +1 -0
  106. package/dist/types/core/agents/codex-app-server/login.d.ts +38 -0
  107. package/dist/types/core/agents/codex-app-server/login.d.ts.map +1 -0
  108. package/dist/types/core/agents/codex-app-server/mcp.d.ts +62 -0
  109. package/dist/types/core/agents/codex-app-server/mcp.d.ts.map +1 -0
  110. package/dist/types/core/agents/codex-app-server/models.d.ts +67 -0
  111. package/dist/types/core/agents/codex-app-server/models.d.ts.map +1 -0
  112. package/dist/types/core/agents/codex-app-server/options.d.ts +40 -0
  113. package/dist/types/core/agents/codex-app-server/options.d.ts.map +1 -0
  114. package/dist/types/core/agents/codex-app-server/plan-approval.d.ts +19 -0
  115. package/dist/types/core/agents/codex-app-server/plan-approval.d.ts.map +1 -0
  116. package/dist/types/core/agents/codex-app-server/protocol.d.ts +99 -0
  117. package/dist/types/core/agents/codex-app-server/protocol.d.ts.map +1 -0
  118. package/dist/types/core/agents/codex-app-server/requests.d.ts +42 -0
  119. package/dist/types/core/agents/codex-app-server/requests.d.ts.map +1 -0
  120. package/dist/types/core/agents/codex-app-server/session.d.ts +96 -0
  121. package/dist/types/core/agents/codex-app-server/session.d.ts.map +1 -0
  122. package/dist/types/core/agents/codex-app-server/subagents.d.ts +53 -0
  123. package/dist/types/core/agents/codex-app-server/subagents.d.ts.map +1 -0
  124. package/dist/types/core/agents/codex-app-server/thread-settings.d.ts +87 -0
  125. package/dist/types/core/agents/codex-app-server/thread-settings.d.ts.map +1 -0
  126. package/dist/types/core/agents/codex-app-server/turn-items.d.ts +33 -0
  127. package/dist/types/core/agents/codex-app-server/turn-items.d.ts.map +1 -0
  128. package/dist/types/core/agents/codex-app-server/turn.d.ts +163 -0
  129. package/dist/types/core/agents/codex-app-server/turn.d.ts.map +1 -0
  130. package/dist/types/core/agents/config-fingerprint.d.ts +5 -0
  131. package/dist/types/core/agents/config-fingerprint.d.ts.map +1 -0
  132. package/dist/types/core/agents/credentials.d.ts +28 -0
  133. package/dist/types/core/agents/credentials.d.ts.map +1 -0
  134. package/dist/types/core/agents/elicitation.d.ts +37 -0
  135. package/dist/types/core/agents/elicitation.d.ts.map +1 -0
  136. package/dist/types/core/agents/inherit-config.d.ts +18 -0
  137. package/dist/types/core/agents/inherit-config.d.ts.map +1 -0
  138. package/dist/types/core/agents/login.d.ts +67 -0
  139. package/dist/types/core/agents/login.d.ts.map +1 -0
  140. package/dist/types/core/agents/mcp-config.d.ts +57 -0
  141. package/dist/types/core/agents/mcp-config.d.ts.map +1 -0
  142. package/dist/types/core/agents/plan.d.ts +16 -0
  143. package/dist/types/core/agents/plan.d.ts.map +1 -0
  144. package/dist/types/core/agents/registry.d.ts +30 -0
  145. package/dist/types/core/agents/registry.d.ts.map +1 -0
  146. package/dist/types/core/agents/session-agent.d.ts +48 -0
  147. package/dist/types/core/agents/session-agent.d.ts.map +1 -0
  148. package/dist/types/core/agents/session-pool.d.ts +41 -0
  149. package/dist/types/core/agents/session-pool.d.ts.map +1 -0
  150. package/dist/types/core/agents/stderr-tail.d.ts +28 -0
  151. package/dist/types/core/agents/stderr-tail.d.ts.map +1 -0
  152. package/dist/types/core/agents/thinking-levels.d.ts +4 -0
  153. package/dist/types/core/agents/thinking-levels.d.ts.map +1 -0
  154. package/dist/types/core/agents/types.d.ts +124 -0
  155. package/dist/types/core/agents/types.d.ts.map +1 -0
  156. package/dist/types/core/diagnostics.d.ts +36 -0
  157. package/dist/types/core/diagnostics.d.ts.map +1 -0
  158. package/dist/types/core/index.d.ts +29 -0
  159. package/dist/types/core/index.d.ts.map +1 -0
  160. package/dist/types/core/presets.d.ts +80 -0
  161. package/dist/types/core/presets.d.ts.map +1 -0
  162. package/dist/types/core/processes/identity.d.ts +31 -0
  163. package/dist/types/core/processes/identity.d.ts.map +1 -0
  164. package/dist/types/core/processes/lifeline.d.ts +47 -0
  165. package/dist/types/core/processes/lifeline.d.ts.map +1 -0
  166. package/dist/types/core/processes/native-processes.d.ts +130 -0
  167. package/dist/types/core/processes/native-processes.d.ts.map +1 -0
  168. package/dist/types/core/processes/process-table.d.ts +43 -0
  169. package/dist/types/core/processes/process-table.d.ts.map +1 -0
  170. package/dist/types/core/provision/cache-trust.d.ts +13 -0
  171. package/dist/types/core/provision/cache-trust.d.ts.map +1 -0
  172. package/dist/types/core/provision/cache-usage.d.ts +14 -0
  173. package/dist/types/core/provision/cache-usage.d.ts.map +1 -0
  174. package/dist/types/core/provision/checksums.d.ts +46 -0
  175. package/dist/types/core/provision/checksums.d.ts.map +1 -0
  176. package/dist/types/core/provision/extract.d.ts +7 -0
  177. package/dist/types/core/provision/extract.d.ts.map +1 -0
  178. package/dist/types/core/provision/index.d.ts +5 -0
  179. package/dist/types/core/provision/index.d.ts.map +1 -0
  180. package/dist/types/core/provision/install-build.d.ts +36 -0
  181. package/dist/types/core/provision/install-build.d.ts.map +1 -0
  182. package/dist/types/core/provision/npm.d.ts +40 -0
  183. package/dist/types/core/provision/npm.d.ts.map +1 -0
  184. package/dist/types/core/provision/pins.d.ts +24 -0
  185. package/dist/types/core/provision/pins.d.ts.map +1 -0
  186. package/dist/types/core/provision/platform.d.ts +28 -0
  187. package/dist/types/core/provision/platform.d.ts.map +1 -0
  188. package/dist/types/core/provision/provisioner.d.ts +189 -0
  189. package/dist/types/core/provision/provisioner.d.ts.map +1 -0
  190. package/dist/types/core/provision/releases.d.ts +8 -0
  191. package/dist/types/core/provision/releases.d.ts.map +1 -0
  192. package/dist/types/core/provision/tools.d.ts +81 -0
  193. package/dist/types/core/provision/tools.d.ts.map +1 -0
  194. package/dist/types/core/proxy/anthropic-proxy.d.ts +52 -0
  195. package/dist/types/core/proxy/anthropic-proxy.d.ts.map +1 -0
  196. package/dist/types/core/proxy/api-key-store.d.ts +37 -0
  197. package/dist/types/core/proxy/api-key-store.d.ts.map +1 -0
  198. package/dist/types/core/proxy/index.d.ts +3 -0
  199. package/dist/types/core/proxy/index.d.ts.map +1 -0
  200. package/dist/types/core/proxy/loopback.d.ts +14 -0
  201. package/dist/types/core/proxy/loopback.d.ts.map +1 -0
  202. package/dist/types/core/runtime/agent-runtime.d.ts +181 -0
  203. package/dist/types/core/runtime/agent-runtime.d.ts.map +1 -0
  204. package/dist/types/core/runtime/event-processor.d.ts +87 -0
  205. package/dist/types/core/runtime/event-processor.d.ts.map +1 -0
  206. package/dist/types/core/runtime/event-sink.d.ts +44 -0
  207. package/dist/types/core/runtime/event-sink.d.ts.map +1 -0
  208. package/dist/types/core/runtime/harness-clis.d.ts +10 -0
  209. package/dist/types/core/runtime/harness-clis.d.ts.map +1 -0
  210. package/dist/types/core/runtime/harness-logins.d.ts +68 -0
  211. package/dist/types/core/runtime/harness-logins.d.ts.map +1 -0
  212. package/dist/types/core/runtime/login-reads.d.ts +28 -0
  213. package/dist/types/core/runtime/login-reads.d.ts.map +1 -0
  214. package/dist/types/core/runtime/model-lists.d.ts +37 -0
  215. package/dist/types/core/runtime/model-lists.d.ts.map +1 -0
  216. package/dist/types/core/runtime/permission-policy.d.ts +61 -0
  217. package/dist/types/core/runtime/permission-policy.d.ts.map +1 -0
  218. package/dist/types/core/runtime/request-broker.d.ts +49 -0
  219. package/dist/types/core/runtime/request-broker.d.ts.map +1 -0
  220. package/dist/types/core/runtime/steering.d.ts +38 -0
  221. package/dist/types/core/runtime/steering.d.ts.map +1 -0
  222. package/dist/types/core/runtime/turn-outcome.d.ts +21 -0
  223. package/dist/types/core/runtime/turn-outcome.d.ts.map +1 -0
  224. package/dist/types/core/runtime/turn.d.ts +121 -0
  225. package/dist/types/core/runtime/turn.d.ts.map +1 -0
  226. package/dist/types/core/utils/bounded.d.ts +6 -0
  227. package/dist/types/core/utils/bounded.d.ts.map +1 -0
  228. package/dist/types/core/utils/deadline.d.ts +14 -0
  229. package/dist/types/core/utils/deadline.d.ts.map +1 -0
  230. package/dist/types/core/utils/errors.d.ts +104 -0
  231. package/dist/types/core/utils/errors.d.ts.map +1 -0
  232. package/dist/types/core/utils/is-record.d.ts +3 -0
  233. package/dist/types/core/utils/is-record.d.ts.map +1 -0
  234. package/dist/types/core/utils/loopback.d.ts +6 -0
  235. package/dist/types/core/utils/loopback.d.ts.map +1 -0
  236. package/dist/types/index.d.ts +2 -0
  237. package/dist/types/index.d.ts.map +1 -0
  238. package/dist/types/protocol/account.d.ts +26 -0
  239. package/dist/types/protocol/account.d.ts.map +1 -0
  240. package/dist/types/protocol/async-queue.d.ts +21 -0
  241. package/dist/types/protocol/async-queue.d.ts.map +1 -0
  242. package/dist/types/protocol/auth.d.ts +228 -0
  243. package/dist/types/protocol/auth.d.ts.map +1 -0
  244. package/dist/types/protocol/canonical.d.ts +9 -0
  245. package/dist/types/protocol/canonical.d.ts.map +1 -0
  246. package/dist/types/protocol/clis.d.ts +74 -0
  247. package/dist/types/protocol/clis.d.ts.map +1 -0
  248. package/dist/types/protocol/config.d.ts +200 -0
  249. package/dist/types/protocol/config.d.ts.map +1 -0
  250. package/dist/types/protocol/conversation.d.ts +942 -0
  251. package/dist/types/protocol/conversation.d.ts.map +1 -0
  252. package/dist/types/protocol/credentials.d.ts +145 -0
  253. package/dist/types/protocol/credentials.d.ts.map +1 -0
  254. package/dist/types/protocol/errors.d.ts +36 -0
  255. package/dist/types/protocol/errors.d.ts.map +1 -0
  256. package/dist/types/protocol/execution.d.ts +28 -0
  257. package/dist/types/protocol/execution.d.ts.map +1 -0
  258. package/dist/types/protocol/factories.d.ts +94 -0
  259. package/dist/types/protocol/factories.d.ts.map +1 -0
  260. package/dist/types/protocol/guards.d.ts +55 -0
  261. package/dist/types/protocol/guards.d.ts.map +1 -0
  262. package/dist/types/protocol/harness.d.ts +70 -0
  263. package/dist/types/protocol/harness.d.ts.map +1 -0
  264. package/dist/types/protocol/history.d.ts +318 -0
  265. package/dist/types/protocol/history.d.ts.map +1 -0
  266. package/dist/types/protocol/ids.d.ts +9 -0
  267. package/dist/types/protocol/ids.d.ts.map +1 -0
  268. package/dist/types/protocol/index.d.ts +35 -0
  269. package/dist/types/protocol/index.d.ts.map +1 -0
  270. package/dist/types/protocol/lifecycle.d.ts +1190 -0
  271. package/dist/types/protocol/lifecycle.d.ts.map +1 -0
  272. package/dist/types/protocol/meta-keys.d.ts +17 -0
  273. package/dist/types/protocol/meta-keys.d.ts.map +1 -0
  274. package/dist/types/protocol/meta.d.ts +13 -0
  275. package/dist/types/protocol/meta.d.ts.map +1 -0
  276. package/dist/types/protocol/model-catalog.d.ts +11 -0
  277. package/dist/types/protocol/model-catalog.d.ts.map +1 -0
  278. package/dist/types/protocol/models.d.ts +107 -0
  279. package/dist/types/protocol/models.d.ts.map +1 -0
  280. package/dist/types/protocol/part-input.d.ts +101 -0
  281. package/dist/types/protocol/part-input.d.ts.map +1 -0
  282. package/dist/types/protocol/parts.d.ts +357 -0
  283. package/dist/types/protocol/parts.d.ts.map +1 -0
  284. package/dist/types/protocol/reduce.d.ts +26 -0
  285. package/dist/types/protocol/reduce.d.ts.map +1 -0
  286. package/dist/types/protocol/selectors.d.ts +64 -0
  287. package/dist/types/protocol/selectors.d.ts.map +1 -0
  288. package/dist/types/protocol/seq-cursor.d.ts +66 -0
  289. package/dist/types/protocol/seq-cursor.d.ts.map +1 -0
  290. package/dist/types/protocol/stop-reasons.d.ts +33 -0
  291. package/dist/types/protocol/stop-reasons.d.ts.map +1 -0
  292. package/dist/types/protocol/thinking.d.ts +28 -0
  293. package/dist/types/protocol/thinking.d.ts.map +1 -0
  294. package/dist/types/protocol/time.d.ts +21 -0
  295. package/dist/types/protocol/time.d.ts.map +1 -0
  296. package/dist/types/protocol/tokens.d.ts +29 -0
  297. package/dist/types/protocol/tokens.d.ts.map +1 -0
  298. package/dist/types/protocol/tool-closure.d.ts +25 -0
  299. package/dist/types/protocol/tool-closure.d.ts.map +1 -0
  300. package/dist/types/protocol/tool-state.d.ts +209 -0
  301. package/dist/types/protocol/tool-state.d.ts.map +1 -0
  302. package/dist/types/protocol/verify.d.ts +52 -0
  303. package/dist/types/protocol/verify.d.ts.map +1 -0
  304. package/dist/types/protocol/vocabulary.d.ts +19 -0
  305. package/dist/types/protocol/vocabulary.d.ts.map +1 -0
  306. package/dist/types/protocol/wire-api.d.ts +1983 -0
  307. package/dist/types/protocol/wire-api.d.ts.map +1 -0
  308. package/dist/types/protocol/wire.d.ts +1758 -0
  309. package/dist/types/protocol/wire.d.ts.map +1 -0
  310. package/dist/types/server/acp/binding.d.ts +33 -0
  311. package/dist/types/server/acp/binding.d.ts.map +1 -0
  312. package/dist/types/server/acp/session-records.d.ts +17 -0
  313. package/dist/types/server/acp/session-records.d.ts.map +1 -0
  314. package/dist/types/server/acp/translate.d.ts +48 -0
  315. package/dist/types/server/acp/translate.d.ts.map +1 -0
  316. package/dist/types/server/agent-server.d.ts +121 -0
  317. package/dist/types/server/agent-server.d.ts.map +1 -0
  318. package/dist/types/server/feedback.d.ts +37 -0
  319. package/dist/types/server/feedback.d.ts.map +1 -0
  320. package/dist/types/server/history.d.ts +15 -0
  321. package/dist/types/server/history.d.ts.map +1 -0
  322. package/dist/types/server/index.d.ts +7 -0
  323. package/dist/types/server/index.d.ts.map +1 -0
  324. package/dist/types/server/install.d.ts +42 -0
  325. package/dist/types/server/install.d.ts.map +1 -0
  326. package/dist/types/server/open-parts.d.ts +27 -0
  327. package/dist/types/server/open-parts.d.ts.map +1 -0
  328. package/dist/types/server/routes.d.ts +61 -0
  329. package/dist/types/server/routes.d.ts.map +1 -0
  330. package/dist/types/server/secrets.d.ts +11 -0
  331. package/dist/types/server/secrets.d.ts.map +1 -0
  332. package/dist/types/server/session-gate.d.ts +32 -0
  333. package/dist/types/server/session-gate.d.ts.map +1 -0
  334. package/dist/types/server/session-log.d.ts +39 -0
  335. package/dist/types/server/session-log.d.ts.map +1 -0
  336. package/dist/types/server/session-store.d.ts +119 -0
  337. package/dist/types/server/session-store.d.ts.map +1 -0
  338. package/dist/types/server/subscriptions.d.ts +74 -0
  339. package/dist/types/server/subscriptions.d.ts.map +1 -0
  340. package/dist/types/server/transports.d.ts +74 -0
  341. package/dist/types/server/transports.d.ts.map +1 -0
  342. package/dist/types/server/wire-error.d.ts +9 -0
  343. package/dist/types/server/wire-error.d.ts.map +1 -0
  344. package/dist/types/sync/event-log.d.ts +45 -0
  345. package/dist/types/sync/event-log.d.ts.map +1 -0
  346. package/dist/types/sync/fit.d.ts +40 -0
  347. package/dist/types/sync/fit.d.ts.map +1 -0
  348. package/dist/types/sync/history-reader.d.ts +8 -0
  349. package/dist/types/sync/history-reader.d.ts.map +1 -0
  350. package/dist/types/sync/history-sqlite.d.ts +37 -0
  351. package/dist/types/sync/history-sqlite.d.ts.map +1 -0
  352. package/dist/types/sync/history.d.ts +70 -0
  353. package/dist/types/sync/history.d.ts.map +1 -0
  354. package/dist/types/sync/index.d.ts +4 -0
  355. package/dist/types/sync/index.d.ts.map +1 -0
  356. package/dist/types/sync/journal-sqlite.d.ts +51 -0
  357. package/dist/types/sync/journal-sqlite.d.ts.map +1 -0
  358. package/dist/types/sync/journal.d.ts +107 -0
  359. package/dist/types/sync/journal.d.ts.map +1 -0
  360. package/dist/types/sync/live-tails.d.ts +30 -0
  361. package/dist/types/sync/live-tails.d.ts.map +1 -0
  362. package/dist/types/sync/node-sqlite.d.ts +7 -0
  363. package/dist/types/sync/node-sqlite.d.ts.map +1 -0
  364. package/dist/types/sync/projection.d.ts +10 -0
  365. package/dist/types/sync/projection.d.ts.map +1 -0
  366. package/dist/types/sync/recovery.d.ts +25 -0
  367. package/dist/types/sync/recovery.d.ts.map +1 -0
  368. package/dist/types/sync/retry.d.ts +25 -0
  369. package/dist/types/sync/retry.d.ts.map +1 -0
  370. package/dist/types/sync/schema.d.ts +4 -0
  371. package/dist/types/sync/schema.d.ts.map +1 -0
  372. package/dist/types/sync/sql.d.ts +38 -0
  373. package/dist/types/sync/sql.d.ts.map +1 -0
  374. package/dist/types/sync/sqlite-file.d.ts +9 -0
  375. package/dist/types/sync/sqlite-file.d.ts.map +1 -0
  376. package/dist/types/sync/sqlite.d.ts +6 -0
  377. package/dist/types/sync/sqlite.d.ts.map +1 -0
  378. package/dist/types/sync/worker.d.ts +63 -0
  379. package/dist/types/sync/worker.d.ts.map +1 -0
  380. package/docs/consuming.md +452 -53
  381. package/docs/deploy.md +218 -47
  382. package/docs/{sync-experiment.md → durable-sessions.md} +77 -72
  383. package/docs/feedback.md +116 -0
  384. package/docs/harnesses.md +212 -88
  385. package/docs/sync-history.md +29 -13
  386. package/docs/sync-integration.md +52 -66
  387. package/package.json +43 -25
  388. package/src/accounts/chatgpt.ts +194 -0
  389. package/src/accounts/check.ts +112 -0
  390. package/src/accounts/claude.ts +111 -0
  391. package/src/accounts/endpoint.ts +151 -0
  392. package/src/accounts/http.ts +97 -0
  393. package/src/accounts/index.ts +19 -0
  394. package/src/client/client.ts +604 -670
  395. package/src/client/connection.ts +371 -0
  396. package/src/client/history.ts +29 -52
  397. package/src/client/index.ts +11 -2
  398. package/src/client/listeners.ts +20 -0
  399. package/src/client/logins.ts +105 -0
  400. package/src/client/rpc.ts +144 -0
  401. package/src/client/streams.ts +488 -0
  402. package/src/client/transports.ts +62 -8
  403. package/src/client/turns.ts +171 -0
  404. package/src/core/agents/acp/acp-agent.ts +94 -118
  405. package/src/core/agents/acp/adapter.ts +20 -9
  406. package/src/core/agents/acp/client.ts +125 -47
  407. package/src/core/agents/acp/known-agents.ts +36 -4
  408. package/src/core/agents/acp/mappings.ts +64 -18
  409. package/src/core/agents/acp/requests.ts +125 -0
  410. package/src/core/agents/attachments.ts +18 -0
  411. package/src/core/agents/base.ts +120 -42
  412. package/src/core/agents/claude-code/adapter.ts +177 -238
  413. package/src/core/agents/claude-code/approvals.ts +270 -0
  414. package/src/core/agents/claude-code/claude-agent.ts +175 -158
  415. package/src/core/agents/claude-code/credentials.ts +171 -0
  416. package/src/core/agents/claude-code/events.ts +55 -0
  417. package/src/core/agents/claude-code/login.ts +269 -0
  418. package/src/core/agents/claude-code/mcp.ts +206 -0
  419. package/src/core/agents/claude-code/models.ts +15 -9
  420. package/src/core/agents/claude-code/options.ts +326 -39
  421. package/src/core/agents/claude-code/outcome.ts +209 -0
  422. package/src/core/agents/claude-code/session-pool.ts +136 -0
  423. package/src/core/agents/claude-code/session.ts +513 -0
  424. package/src/core/agents/claude-code/spawn.ts +144 -0
  425. package/src/core/agents/claude-code/spend.ts +160 -0
  426. package/src/core/agents/claude-code/tools.ts +47 -0
  427. package/src/core/agents/claude-code/turn-usage.ts +135 -0
  428. package/src/core/agents/claude-code/turn.ts +232 -0
  429. package/src/core/agents/codex-app-server/adapter.ts +314 -117
  430. package/src/core/agents/codex-app-server/client.ts +186 -84
  431. package/src/core/agents/codex-app-server/codex-agent.ts +343 -0
  432. package/src/core/agents/codex-app-server/commands.ts +228 -0
  433. package/src/core/agents/codex-app-server/credentials.ts +126 -0
  434. package/src/core/agents/codex-app-server/effort.ts +29 -0
  435. package/src/core/agents/codex-app-server/events.ts +47 -0
  436. package/src/core/agents/codex-app-server/homes.ts +64 -0
  437. package/src/core/agents/codex-app-server/input.ts +60 -0
  438. package/src/core/agents/codex-app-server/items.ts +149 -0
  439. package/src/core/agents/codex-app-server/login.ts +180 -0
  440. package/src/core/agents/codex-app-server/mcp.ts +182 -37
  441. package/src/core/agents/codex-app-server/models.ts +99 -46
  442. package/src/core/agents/codex-app-server/options.ts +146 -0
  443. package/src/core/agents/codex-app-server/plan-approval.ts +135 -0
  444. package/src/core/agents/codex-app-server/protocol.ts +117 -0
  445. package/src/core/agents/codex-app-server/requests.ts +332 -0
  446. package/src/core/agents/codex-app-server/session.ts +285 -0
  447. package/src/core/agents/codex-app-server/subagents.ts +108 -42
  448. package/src/core/agents/codex-app-server/thread-settings.ts +279 -0
  449. package/src/core/agents/codex-app-server/turn-items.ts +88 -0
  450. package/src/core/agents/codex-app-server/turn.ts +463 -0
  451. package/src/core/agents/config-fingerprint.ts +7 -14
  452. package/src/core/agents/credentials.ts +98 -0
  453. package/src/core/agents/elicitation.ts +75 -0
  454. package/src/core/agents/inherit-config.ts +21 -0
  455. package/src/core/agents/login.ts +116 -0
  456. package/src/core/agents/mcp-config.ts +112 -8
  457. package/src/core/agents/plan.ts +25 -0
  458. package/src/core/agents/registry.ts +21 -4
  459. package/src/core/agents/session-agent.ts +96 -4
  460. package/src/core/agents/{session-store.ts → session-pool.ts} +11 -5
  461. package/src/core/agents/stderr-tail.ts +75 -0
  462. package/src/core/agents/types.ts +40 -5
  463. package/src/core/index.ts +58 -48
  464. package/src/core/presets.ts +100 -39
  465. package/src/core/processes/identity.ts +113 -0
  466. package/src/core/processes/lifeline.ts +170 -0
  467. package/src/core/processes/native-processes.ts +379 -0
  468. package/src/core/processes/process-table.ts +174 -0
  469. package/src/core/provision/cache-trust.ts +121 -0
  470. package/src/core/provision/cache-usage.ts +69 -0
  471. package/src/core/provision/checksums.ts +64 -0
  472. package/src/core/provision/extract.ts +11 -2
  473. package/src/core/provision/index.ts +4 -1
  474. package/src/core/provision/install-build.ts +136 -0
  475. package/src/core/provision/npm.ts +112 -17
  476. package/src/core/provision/pins.ts +9 -33
  477. package/src/core/provision/platform.ts +12 -1
  478. package/src/core/provision/provisioner.ts +329 -397
  479. package/src/core/provision/releases.ts +86 -0
  480. package/src/core/provision/tools.ts +329 -0
  481. package/src/core/proxy/anthropic-proxy.ts +55 -25
  482. package/src/core/proxy/api-key-store.ts +2 -12
  483. package/src/core/proxy/loopback.ts +106 -0
  484. package/src/core/runtime/agent-runtime.ts +327 -498
  485. package/src/core/runtime/event-processor.ts +197 -70
  486. package/src/core/runtime/harness-clis.ts +61 -0
  487. package/src/core/runtime/harness-logins.ts +328 -0
  488. package/src/core/runtime/login-reads.ts +78 -0
  489. package/src/core/runtime/model-lists.ts +33 -48
  490. package/src/core/runtime/permission-policy.ts +113 -0
  491. package/src/core/runtime/request-broker.ts +204 -0
  492. package/src/core/runtime/steering.ts +112 -0
  493. package/src/core/runtime/turn-outcome.ts +30 -0
  494. package/src/core/runtime/turn.ts +360 -0
  495. package/src/core/utils/bounded.ts +12 -0
  496. package/src/core/utils/deadline.ts +38 -0
  497. package/src/core/utils/errors.ts +113 -21
  498. package/src/core/utils/is-record.ts +4 -0
  499. package/src/core/utils/loopback.ts +10 -0
  500. package/src/protocol/account.ts +104 -0
  501. package/src/protocol/auth.ts +199 -0
  502. package/src/protocol/canonical.ts +16 -0
  503. package/src/protocol/clis.ts +69 -0
  504. package/src/protocol/config.ts +60 -6
  505. package/src/protocol/conversation.ts +272 -0
  506. package/src/protocol/credentials.ts +145 -0
  507. package/src/protocol/errors.ts +78 -20
  508. package/src/protocol/execution.ts +5 -2
  509. package/src/protocol/factories.ts +55 -7
  510. package/src/protocol/guards.ts +55 -2
  511. package/src/protocol/harness.ts +56 -6
  512. package/src/protocol/history.ts +72 -64
  513. package/src/protocol/ids.ts +0 -12
  514. package/src/protocol/index.ts +9 -0
  515. package/src/protocol/lifecycle.ts +250 -79
  516. package/src/protocol/meta-keys.ts +17 -0
  517. package/src/protocol/meta.ts +3 -3
  518. package/src/protocol/models.ts +2 -43
  519. package/src/protocol/part-input.ts +2 -1
  520. package/src/protocol/parts.ts +12 -3
  521. package/src/protocol/reduce.ts +302 -413
  522. package/src/protocol/selectors.ts +1 -20
  523. package/src/protocol/seq-cursor.ts +14 -0
  524. package/src/protocol/stop-reasons.ts +1 -1
  525. package/src/protocol/thinking.ts +1 -30
  526. package/src/protocol/time.ts +2 -2
  527. package/src/protocol/tool-closure.ts +93 -0
  528. package/src/protocol/tool-state.ts +19 -4
  529. package/src/protocol/verify.ts +222 -92
  530. package/src/protocol/vocabulary.ts +21 -5
  531. package/src/protocol/wire-api.ts +232 -0
  532. package/src/protocol/wire.ts +351 -64
  533. package/src/server/acp/binding.ts +63 -103
  534. package/src/server/acp/session-records.ts +53 -0
  535. package/src/server/acp/translate.ts +129 -20
  536. package/src/server/agent-server.ts +223 -387
  537. package/src/server/bin.ts +280 -78
  538. package/src/server/feedback.ts +204 -14
  539. package/src/server/history.ts +116 -122
  540. package/src/server/index.ts +3 -8
  541. package/src/server/install.ts +107 -8
  542. package/src/server/open-parts.ts +95 -0
  543. package/src/server/routes.ts +391 -0
  544. package/src/server/secrets.ts +24 -0
  545. package/src/server/session-gate.ts +69 -0
  546. package/src/server/session-log.ts +14 -2
  547. package/src/server/session-store.ts +136 -72
  548. package/src/server/subscriptions.ts +232 -0
  549. package/src/server/transports.ts +125 -25
  550. package/src/server/wire-error.ts +31 -45
  551. package/src/sync/event-log.ts +31 -3
  552. package/src/sync/fit.ts +27 -11
  553. package/src/sync/history-reader.ts +10 -5
  554. package/src/sync/history-sqlite.ts +37 -42
  555. package/src/sync/history.ts +9 -15
  556. package/src/sync/index.ts +17 -5
  557. package/src/sync/journal-sqlite.ts +162 -76
  558. package/src/sync/journal.ts +91 -32
  559. package/src/sync/live-tails.ts +107 -0
  560. package/src/sync/projection.ts +35 -0
  561. package/src/sync/recovery.ts +80 -51
  562. package/src/sync/schema.ts +27 -6
  563. package/docs/rfds/0001-deterministic-echo-ids.md +0 -44
  564. package/docs/rfds/0002-native-subagents.md +0 -197
  565. package/src/client/request.ts +0 -19
  566. package/src/core/agents/claude-code/generator-session.ts +0 -572
  567. package/src/core/agents/claude-code/session-manager.ts +0 -166
  568. package/src/core/agents/codex-app-server/codex-app-server-agent.ts +0 -962
  569. package/src/core/agents/codex-items.ts +0 -149
  570. package/src/core/agents/codex-sdk/adapter.ts +0 -237
  571. package/src/core/agents/codex-sdk/codex-sdk-agent.ts +0 -330
  572. package/src/core/agents/tool-meta.ts +0 -68
package/docs/consuming.md CHANGED
@@ -22,7 +22,7 @@ for await (const event of turn.events) {
22
22
  The reducer encodes the rules consumers get wrong first:
23
23
 
24
24
  - **Every turn starts with your own prompt echoed back.** See below — this is
25
- the rule that surprises consumers upgrading to 0.3.0.
25
+ the rule that surprises consumers first.
26
26
 
27
27
  - **Upsert parts by `part.id`.** A tool part can complete AFTER its message —
28
28
  or its turn — ended; the event's `messageId` names the original message and
@@ -31,12 +31,76 @@ The reducer encodes the rules consumers get wrong first:
31
31
  - **Snapshots are authoritative; deltas are streaming sugar.** `message.part`
32
32
  replaces whatever `message.part.delta`s built. Never append a snapshot's
33
33
  text onto delta-accumulated text.
34
+ - **Deltas are live only; a streaming part is kept at its opening, its
35
+ changes and its end.** A delta notification carries the `seq` of the last
36
+ kept event, not one of its own, and is not retained. The engine keeps no
37
+ snapshots of a part while it streams (no checkpoints): it flushes what
38
+ streamed before `turn.ended`, including cancellation. History viewers see a
39
+ part when it opens and when it ends. A journal keeps what a part streamed,
40
+ a row per delta, before the delta is delivered, so a server process that
41
+ dies loses none of what a client was shown; a server without a journal can
42
+ lose it.
43
+ - **Joining receives the open parts.** A subscription's answer
44
+ (`session/subscribe`, or `turn/start`'s ack) marks a point in the
45
+ connection's frames; right after it come the session's open parts, each a
46
+ `message.part` with its content so far, sent `live: true` at the head seq.
47
+ Fold it like any snapshot, then the deltas after it. Tokens missed while
48
+ disconnected have no sequence gap, so the wire client delivers a part's
49
+ deltas only after a snapshot of it on the current connection, which the
50
+ open part a redial's subscription sends is. Custom raw-wire consumers fold
51
+ every `live: true` frame with `advanceLive` (`isLiveEnvelope`), never
52
+ `advance`; `SeqCursor` only orders retained events and cannot recover lost
53
+ tokens.
34
54
  - **`turn.ended.tokens` ≠ `session.usage`.** The first is the turn's billing
35
55
  total (sum for spend); the second is the live context-window gauge (render
36
56
  for "how full"). Different numbers, both kept by the reducer.
37
57
  - **Permissions resolve exactly once.** Turn end or cancel resolves pending
38
58
  requests as `cancelled`; you will always observe a `permission.resolved`
39
59
  before that turn's `turn.ended`.
60
+ - **Render the request's own options.** A plan's approval (`toolCall.kind:
61
+ "switch_mode"`, the plan in `toolCall.rawInput.plan`) offers the modes to go
62
+ on in instead of the standard four: `accept_edits`, `default`, `plan` ("keep
63
+ planning"). Answer with the `optionId` picked, and a `message` to say what
64
+ should change; a plain `allow` approves it in `default`. Each turn runs in
65
+ the mode it asks for: `state.permissionMode` holds the current one (the
66
+ turn's, then the agent's switch), so send that mode next to stay with the
67
+ agent.
68
+ - **Say why where the harness hears it.** A refused tool call's `message`
69
+ reaches the agent when `initialize().harnesses[h].rejectionMessages` is
70
+ true (Claude). Codex's refusal is a bare verdict and an ACP agent's an
71
+ option id: send the user's words as the next input (a steer) instead.
72
+ - **Check an attachment before sending it.** `harnesses[h].images` and
73
+ `harnesses[h].files`, the kinds of file it reads as data
74
+ (`fileKind(mimeType)`: `text`, `pdf`, `binary`), say what a turn may
75
+ carry; anything else fails the turn as `invalid_request`.
76
+ - **A tool its turn left running is closed for you.** At `turn.ended` the
77
+ reducer closes it: `cancelled` when the turn was cancelled, else `failed`
78
+ with a `closure` that says how: `outcome_unknown` (it may have run, its
79
+ effects stand), `never_ran` (its input never finished streaming, or its
80
+ approval was refused), or `interrupted` (agent-server stopped under it;
81
+ journal recovery). Match on `closure`: the `error` sentence
82
+ (`TOOL_OUTCOME_UNKNOWN`, `TOOL_NEVER_RAN`, `TOOL_INTERRUPTED`) is for the
83
+ model and the user, and a failure the harness reported has no `closure`.
84
+ - **The agent's questions are elicitations, not permissions.** A turn whose
85
+ `config.elicitation` is true may raise `elicitation.requested`: the agent's
86
+ own question with choices (`mode: "question"`: Claude's AskUserQuestion,
87
+ Codex's plan-mode questions) or an MCP server's request for input (`form`, a
88
+ JSON schema; `url`, a link to visit). Answer with `respondElicitation` —
89
+ `accept` with `content` (question id → array of answers, or the form's
90
+ values), `decline`, or `cancel`; `pendingElicitations(state)` lists what to
91
+ render. Like permissions they resolve exactly once, before `turn.ended`.
92
+ Without `elicitation: true` the engine declines on the user's behalf and the
93
+ agent carries on, so an unattended turn never waits for an answer.
94
+ - **A request can expire.** `config.requestTimeoutMs` bounds how long a
95
+ permission request or question waits: unanswered by then, it resolves as a
96
+ cancel would (`cancelled` / `cancel` on its `*.resolved`; a cancelled
97
+ permission ends a Claude turn). Absent, it waits until the turn ends.
98
+
99
+ - **Plan usage arrives as `session.limits`.** Each report carries the windows
100
+ that changed (`five_hour`, `seven_day`, … with `usedPercent` and
101
+ `resetsAt`); `state.limits` merges them by id. A recoverable `error` with
102
+ `retry` means the harness is waiting to try again — show it, don't fail the
103
+ turn.
40
104
 
41
105
  Branch on the outcome with `isCleanStop` / `isFailureStopReason` rather than
42
106
  your own list: `cancelled` is clean (the user asked for the stop), `error` is
@@ -52,11 +116,11 @@ Rendering needs the state; persisting needs to know what moved. Use
52
116
  const { state, changes } = reduceConversationWithChanges(previous, event);
53
117
  for (const change of changes) {
54
118
  switch (change.kind) {
55
- case "message-upserted": upsertMessageRow(state, change.messageId); break;
56
- case "part-upserted": upsertPartRow(state, change.messageId, change.partId); break;
57
- case "turn-updated": upsertTurnRow(state, change.turnId); break;
58
- // …message-ended · delta-buffered · compaction-upserted · permission-updated
59
- // usage-updated · session-meta-updated · session-ended · unknown-event-recorded
119
+ case "message_upserted": upsertMessageRow(state, change.messageId); break;
120
+ case "part_upserted": upsertPartRow(state, change.messageId, change.partId); break;
121
+ case "turn_updated": upsertTurnRow(state, change.turnId); break;
122
+ // …message_ended · delta_buffered · compaction_upserted · permission_updated · elicitation_updated
123
+ // usage_updated · session_meta_updated · session_ended · unknown_event_recorded
60
124
  }
61
125
  }
62
126
  ```
@@ -71,7 +135,7 @@ knowledge.
71
135
 
72
136
  ## Project the state with the shipped selectors
73
137
 
74
- Four pure functions over `ConversationState`, so a UI does not re-derive them:
138
+ Three pure functions over `ConversationState`, so a UI does not re-derive them:
75
139
 
76
140
  - `groupIntoTurns(state)` — turn cards: consecutive entries of the same turn
77
141
  and the same speaker. `isLatest` is true for the FINAL group only; render
@@ -86,9 +150,6 @@ Four pure functions over `ConversationState`, so a UI does not re-derive them:
86
150
  message of the last ACTIVE turn. `idle` during an active turn means
87
151
  "between observable activities", not "finished" — combine it with your own
88
152
  busy flag.
89
- - `toolResultText(toolPart.state)` — the display fallback: completed →
90
- `output`, failed → `error`, everything else → `""` (deliberately empty, not
91
- invented placeholder prose).
92
153
 
93
154
  ## Track `seq` with the shared cursor
94
155
 
@@ -97,7 +158,12 @@ from a log — use `createSeqCursor()` instead of comparing numbers by hand:
97
158
 
98
159
  ```ts
99
160
  const cursor = createSeqCursor();
100
- switch (cursor.advance(envelope.sessionId, envelope.seq)) {
161
+ // A live frame (a delta, an open part) carries the seq of the kept event
162
+ // before it; replay never returns one.
163
+ const verdict = isLiveEnvelope(envelope)
164
+ ? cursor.advanceLive(envelope.sessionId, envelope.seq)
165
+ : cursor.advance(envelope.sessionId, envelope.seq);
166
+ switch (verdict) {
101
167
  case "deliver": return fold(envelope.event);
102
168
  case "duplicate": return; // already folded
103
169
  case "gap": return holdAndReplay(envelope); // request events/replay
@@ -114,12 +180,12 @@ object — there is no second implementation.
114
180
  Restarts themselves are not guessed from seq patterns on the wire: `initialize`
115
181
  returns a per-process `instanceId`, the client re-handshakes on every
116
182
  reconnect, and a changed id adopts the fresh logs outright (cursors reset,
117
- sessions resynced from seq 1). The `reset` verdict remains for consumers that
118
- fold envelopes without a handshake of their own.
183
+ sessions subscribed again from seq 0). The `reset` verdict remains for
184
+ consumers that fold envelopes without a handshake of their own.
119
185
 
120
186
  ## Render by role — the turn opens with the user echo
121
187
 
122
- Every turn now begins with the submitted input echoed back as a complete user
188
+ Every turn begins with the submitted input echoed back as a complete user
123
189
  message, before any harness output:
124
190
 
125
191
  ```text
@@ -134,7 +200,7 @@ turn.ended
134
200
 
135
201
  Consequences, in the order they bite:
136
202
 
137
- - **A consumer that renders every `message.part` as model output now prints the
203
+ - **A consumer that renders every `message.part` as model output prints the
138
204
  user's own prompt.** Filter by the role of the part's message — never by
139
205
  position. `conversationMessages(state)` gives the timeline's messages in
140
206
  order, each with its `role`, so `messages.filter(m => m.role === "assistant")`
@@ -159,7 +225,7 @@ Consequences, in the order they bite:
159
225
  approach is where file and image parts got dropped). These two are the
160
226
  documented exception to engine-minted UUIDv7 ids — everything else on the
161
227
  wire stays opaque, and nothing may parse structure out of an id.
162
- - The stream is now a complete transcript. Multi-client attach, replay and
228
+ - The stream is a complete transcript. Multi-client attach, replay and
163
229
  persistence no longer need the client's private copy of the prompt — which
164
230
  is the point: a second UI attaching mid-turn sees what was asked.
165
231
 
@@ -183,6 +249,142 @@ known `type`, and **store and forward what you don't understand** — a
183
249
  round trip through your persistence layer must not be where a newer server's
184
250
  data disappears. A known type with a malformed body still fails loudly.
185
251
 
252
+ ## Install the CLIs before the first turn
253
+
254
+ A harness's first turn on a machine without its CLI downloads it, about
255
+ 100 MB, and its stream is silent meanwhile. Install at setup and show it:
256
+
257
+ ```ts
258
+ client.onCliProgress(({ harness, phase, receivedBytes, totalBytes }) => progressBar(harness, phase, receivedBytes, totalBytes));
259
+ const [claude] = await client.prepareClis(["claude-code"]);
260
+ if (claude?.state === "failed") showRetry(claude.error); // e.g. offline
261
+ ```
262
+
263
+ `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
266
+ answers `clis/prepare` at once; its `signal` stops the waiting, not the
267
+ install. In-process, `runtime.prepareClis()`, `runtime.listClis()` and
268
+ `runtime.onCliProgress()` do the same. A product that bundles the Claude SDK
269
+ sets `provision.pins.claude` to its version. See
270
+ [Ready before the first turn](deploy.md#ready-before-the-first-turn).
271
+
272
+ ## Show each harness's login, and sign it in
273
+
274
+ A settings page shows whether each harness is logged in and offers a way in.
275
+ The engine reads the login from the CLI and runs the CLI's own sign-in; the
276
+ credential lands in the CLI's store, the one a turn with the same `env` uses:
277
+
278
+ ```ts
279
+ const [codex] = await client.authStatus({ harnesses: ["codex-app-server"] });
280
+ // { state: "signed_in", credential: "subscription", provider: "openai", plan: "pro", email, methods }
281
+ const chatgpt = codex.methods.find((method) => method.id === "chatgpt");
282
+
283
+ // Signed in on this computer already (a terminal, another app): nothing to open.
284
+ if (!signedInBy(codex, chatgpt)) {
285
+ const login = await client.login("codex-app-server", "chatgpt");
286
+ openBrowser(login.url); // a device code instead: show login.userCode with login.url
287
+ await login.done; // the login after it; rejects with a LoginError (failed, cancelled, expired)
288
+ }
289
+ ```
290
+
291
+ A login reads the same for every harness: `label` says what to show ("Claude
292
+ Max", "ChatGPT Pro", "OpenAI API key"), `source` where it comes from, and
293
+ `email`, `organization`, `plan`, `expiresAt` who and until when.
294
+
295
+ Read the login first, as a "Sign in with ChatGPT" button should: with no
296
+ `env`, status is the user's own CLI login, so one they already made is picked
297
+ up and the button opens nothing. `signedInBy(auth, method)` says whether the
298
+ harness already runs on the CLI's own login of that method's `credential`
299
+ (`subscription`, `api_key`); a key from the environment is not one.
300
+
301
+ Each harness lists its `methods`, by `kind`:
302
+
303
+ - `browser`: the user signs in at `url` in a browser on the server's machine,
304
+ and the login finishes by itself. Where the login also has a `codeUrl`
305
+ (Claude), a browser on another device signs in there and the user pastes
306
+ the code the page shows: `login.complete(code)`.
307
+ - `device_code`: the user enters `userCode` at `url`, on any device (Codex).
308
+ - `api_key`: `client.login("codex-app-server", "api_key", { apiKey })`
309
+ stores the key in Codex's own login. Claude Code keeps no pasted key: keep
310
+ it yourself and send it with each turn (`config.apiKey`), or sign in with
311
+ `console`, whose key the CLI mints and keeps.
312
+ - `terminal`: a CLI login for a terminal of your own, `command` (the engine's
313
+ CLI, not `PATH`'s) and the `env` naming the store.
314
+
315
+ `state: "signed_in"` with `source: "environment"` means a key in the server's
316
+ environment wins over the login; say so. Every connection hears
317
+ `auth/updated` (`client.onAuthUpdated`) when a login changes, whoever changed
318
+ it, and a status read notices a login made in a terminal. After a change,
319
+ each session's next turn starts a new CLI, resuming its conversation. A turn
320
+ 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
323
+ CLI's own login and environment: a turn that brings its own `apiKey`, or runs
324
+ on a credential the product holds (`credentials`), runs with that instead. In-process, `runtime.authStatus()`, `runtime.login()`,
325
+ `runtime.completeLogin()`, `runtime.cancelLogin()`, `runtime.logout()` and
326
+ `runtime.onAuthUpdated()` do the same. [`apps/login-demo`](../../../apps/login-demo)
327
+ is such a settings page, end to end.
328
+
329
+ ## Hold the login yourself, for sandboxes and other devices
330
+
331
+ A login on the engine's machine (above) stays on that machine. To run turns
332
+ in cloud sandboxes, or one account on all of a person's devices, hold the
333
+ login in your product and let each turn ask for it (LLP 0012). Your backend
334
+ signs the person in with `@zvada/agent-server/accounts`, which needs only
335
+ `fetch` (a Worker runs it), and stores the grant:
336
+
337
+ ```ts
338
+ import { completeClaudeLogin, pollChatGptLogin, startChatGptLogin, startClaudeLogin } from "@zvada/agent-server/accounts";
339
+
340
+ const claude = await startClaudeLogin(); // show claude.url; the page shows a code
341
+ const grant = await completeClaudeLogin(claude, pastedCode); // a one-year token: store `grant`
342
+
343
+ const chatgpt = await startChatGptLogin(); // show chatgpt.userCode at chatgpt.verificationUrl
344
+ const codexGrant = await pollChatGptLogin(chatgpt); // every intervalMs until it is not undefined
345
+ ```
346
+
347
+ `pastedGrant(harness, credential)` checks a pasted API key or a
348
+ `claude setup-token` token first. Mount the endpoint your engines ask before
349
+ each turn over your store; `credentialsFrom` answers each request with the
350
+ grant's credential, renewing a ChatGPT grant first when it is about to expire
351
+ or the harness refused it (one renewal at a time, deciding on the grant as
352
+ read inside it), and writes the renewal back:
353
+
354
+ ```ts
355
+ import { createCredentialHandler, credentialsFrom } from "@zvada/agent-server/accounts";
356
+
357
+ export const credentials = createCredentialHandler({
358
+ authorize: (request) => sandboxOwner(request.headers.get("authorization")), // undefined: 401
359
+ resolve: credentialsFrom({
360
+ read: (request, user) => db.grantFor(user, request.harness, request.turnId), // who pays for this turn
361
+ write: (grant, request, user) => db.saveGrant(user, grant), // compare a revision across processes
362
+ }),
363
+ });
364
+ ```
365
+
366
+ Show a login you hold with the same view as a CLI's own: `grantAuth(grant)`
367
+ answers a `HarnessAuth` (`source: "product"`, its `label` and expiry), never
368
+ the secret.
369
+
370
+ A grant that is not there answers none: that turn runs on the engine's own
371
+ CLI login. A Claude Code turn runs on an `api_key` (with a `baseUrl` for a
372
+ gateway) or an `oauth_token`, a Codex turn on an `api_key` to OpenAI or a
373
+ `chatgpt` token; a credential its harness cannot run fails the turn before it
374
+ starts.
375
+
376
+ Start each sandbox's engine with `agent-server --credentials-url
377
+ https://you/agent-credentials` and the token that `authorize` takes in
378
+ `$AGENT_SERVER_CREDENTIALS_TOKEN`; in-process, `createAgentRuntime({
379
+ credentials: credentialsFromUrl({url, token}) })`, or any
380
+ `CredentialSource` of your own, which gets the same `CredentialRequest` an
381
+ endpoint does. Claude runs through the engine's own proxy, so the CLI and its
382
+ tools hold only a placeholder; the credential is held there while a turn
383
+ runs, and a token the API refuses is asked for again and the request retried.
384
+ Codex holds ChatGPT tokens in memory, never a refresh token. A refusal
385
+ reaches your source as `rejectedSha256`, the token's digest (`tokenDigest`). [`apps/login-demo`](../../../apps/login-demo)'s
386
+ "Held by the product" mode is all of this, with a sandbox.
387
+
186
388
  ## Offer models and show what ran
187
389
 
188
390
  Fill a model picker from the harness's own list rather than a hard-coded one:
@@ -204,8 +406,12 @@ the model ran at (`ultra` on a model whose top is `max` shows `max`), and
204
406
  `reportedModels` the models the harness reported (Claude's API model, Codex's
205
407
  thread model). Show those, not the requested `model` and `thinkingLevel`,
206
408
  when they are present. Both are absent when a turn failed before its model
207
- answered. List models with the `cwd` (and credentials) your turns use: an
208
- alias such as `opus` is fitted only from its own login's list.
409
+ answered. Each assistant `message.started` names its own `model` the same
410
+ way: the API model that wrote it on Claude (a plan turn can mix two, and a
411
+ sub-agent's message names the sub-agent's), the thread's model on Codex (the
412
+ model it rerouted to, after a reroute), and the requested `model` only where
413
+ a harness names none. List models with the `cwd` (and credentials) your turns use: an alias
414
+ such as `opus` is fitted only from its own login's list.
209
415
 
210
416
  ## Persist for resume
211
417
 
@@ -231,6 +437,45 @@ A successful Claude resume can mint a new native ID; use the reported `resumed`
231
437
  flag rather than comparing Claude IDs. The `resumed: false` wire value remains
232
438
  readable for older engines and custom harnesses.
233
439
 
440
+ ## Steer a running turn
441
+
442
+ A user who types while the agent works means "and also…" or "stop, do this
443
+ instead". Send it into the running turn rather than queueing a new one:
444
+
445
+ ```ts
446
+ const handle = await client.runTurn({ sessionId, input, config });
447
+ // …the user types while it runs:
448
+ const result = await handle.steer("Use the staging database instead", steerId);
449
+ // or: client.steerTurn({ sessionId, turnId: handle.turnId, steerId, input })
450
+ ```
451
+
452
+ - **`steered`**: the harness accepted it. The agent reads it at its next step
453
+ (after the tool it is running, or as one more query when it was already
454
+ answering), and the stream shows it there as a user message whose ids derive
455
+ from the steer id: `steerMessageId(steerId)`, parts `steerPartId(steerId, i)`.
456
+ Show a pending bubble under that id outside the folded state (an overlay):
457
+ folding your own `message.started` for it would make the reducer keep your
458
+ bubble's position and ignore the real one, which lands where the agent read
459
+ the steer.
460
+ - **Delivered means echoed.** A steer reached the agent exactly when its user
461
+ message appears in the turn. A turn that ends first lists it in
462
+ `turn.ended.undeliveredSteers`, and it never runs later: a cancel drops
463
+ unread steers; for a turn that ended normally, send the text as a new turn.
464
+ A turn a durable server lost to a crash lists nothing it never journaled, so
465
+ go by the echo.
466
+ - **`no_active_turn`**: the turn is not taking input (it ended, is ending, or
467
+ another turn runs, see `activeTurnId`). Send the input as a new turn.
468
+ - **`unsupported`**: this harness cannot steer
469
+ (`initialize().harnesses[h].steering`; ACP agents cannot).
470
+
471
+ A turn takes steers from the moment `turn/start` acks. A steer id, like a turn
472
+ id, is unique in its session (mint a UUIDv7): a retry with the same `steerId`
473
+ and input converges (`deduplicated: true`), even after the turn ended; the
474
+ same id with other input, or in another turn, is `turnConflict`. Inside the
475
+ turn, a later user message (`outputIndex > 0`) is always a steer, so a steered
476
+ turn has several user and assistant groups under one `turnId`: render by role
477
+ and order, never one card per (turn, role).
478
+
234
479
  ## Retry safely
235
480
 
236
481
  Turn admission is idempotent on `{sessionId, turnId}`: mint the `turnId`
@@ -261,6 +506,11 @@ interrupt; `unconfirmed` means it did not land — including the window between
261
506
  the `turn/start` quick-ack and the harness registering its abortable turn —
262
507
  and the agent may still be running. On `unconfirmed`, report "stopping…" and
263
508
  treat `turn.ended` as the source of truth, not the cancel response.
509
+ `cancelled` also covers what the turn started: Codex keeps a command running
510
+ after an interrupt, so the engine stops the turn's commands and checks before
511
+ the turn ends. A command whose stop could not be confirmed is not closed as
512
+ cancelled: its tool part fails with `TOOL_OUTCOME_UNKNOWN`, a failure the
513
+ harness reports itself (no `closure`).
264
514
 
265
515
  Embedded `runtime.cancel(harness, sessionId)` cancels the session's active
266
516
  turn without a turn ID check. Prefer a per-turn `AbortSignal` when cancellation
@@ -275,9 +525,9 @@ seq monotonicity — then folds it twice: once to assert the reducer's final
275
525
  state agrees with the authoritative snapshots, and once with every upsert
276
526
  delivered TWICE to assert re-delivery changes nothing (the property a replay
277
527
  overlap or a reconnect resync depends on). Run it in CI over recorded fixtures
278
- and in staging over live turns (`agent-server run "…" --verify` exits 1 on any
279
- violation); a product pipeline (a Durable Object, a persistence shim) can run
280
- it on replay to fail loudly instead of storing a corrupt projection.
528
+ and in staging over the events of live turns, failing on any violation; a
529
+ product pipeline (a Durable Object, a persistence shim) can run it on replay to
530
+ fail loudly instead of storing a corrupt projection.
281
531
 
282
532
  It takes **one session's** stream, of any length: `session.created` is expected
283
533
  once per turn (not once per stream), deltas that trail the last snapshot of a
@@ -285,6 +535,52 @@ cancelled turn are legal (a snapshot is a prefix of the fold, not a ceiling),
285
535
  and unknown event/part types are forward-compat rather than violations. Pass
286
536
  `{expectEcho: false}` for a partial capture that begins mid-turn.
287
537
 
538
+ ## Choose what a turn inherits
539
+
540
+ A Claude or Codex turn loads configuration by itself when it starts, from the
541
+ host user and from the repository: settings, MCP servers, hooks, instructions
542
+ and memory. `createAgentRuntime({ inheritConfig })`, and the bin's and the
543
+ CLI's `--inherit-config`, choose how much (LLP 0001, D17):
544
+
545
+ | Level | Claude Code | Codex app-server |
546
+ | --- | --- | --- |
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 |
549
+ | `none` | only the servers the host and the turn name | as `project`, without the repository's `AGENTS.md` |
550
+
551
+ Choose by whose machine and whose repository it is. A desktop product that
552
+ works in its user's own repositories can stay at `all`, or take `project` to
553
+ keep the user's personal settings and memory out of its turns. A cloud
554
+ sandbox, a test, an eval or CI takes `project` for a repository you trust and
555
+ `none` for any other.
556
+
557
+ The level never changes where the agent may read or run: the permission mode,
558
+ Codex's sandbox and your `toolPolicy` decide that. But `all` and `project`
559
+ load the repository's configuration, and an SDK session never asks to trust a
560
+ folder: the repository's hooks and `.mcp.json` servers run at session start
561
+ as the server's user, a PreToolUse hook can approve a tool call your policy
562
+ and the broker never see, and one `env` line can send the turn's API traffic,
563
+ with its API key or subscription token, elsewhere. Give a repository you do
564
+ not trust `none`, and keep real API keys out of the agent's environment: the
565
+ `./core/proxy` building block hands the agent a placeholder key and swaps in
566
+ the real one.
567
+
568
+ At `project` and `none` every Codex turn needs `config.env.CODEX_HOME`, an
569
+ existing absolute folder of the session's own: never the user's `~/.codex`,
570
+ never another session's. A turn without one fails `invalid_request` before
571
+ 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
575
+ `~/.agents/skills` at every level; turn one off by name in the home you
576
+ supply (`[[skills.config]]` with `enabled = false`).
577
+
578
+ On Claude a `disableTools` turn runs at `none` whatever the level.
579
+ `claudeCode.sdkOptions` can still name `settingSources` (and
580
+ `strictMcpConfig`) itself, and wins over the level's; the level still decides
581
+ auto-memory and the connectors. An ACP agent loads what its launch command
582
+ says.
583
+
288
584
  ## Own your session resources
289
585
 
290
586
  ### Configure MCP between turns
@@ -296,7 +592,20 @@ applied through the harness's native configuration API before the prompt;
296
592
  finishing a turn does not restart the agent or its servers. Omitting the map
297
593
  on a later turn removes the previous wire-configured set, just like `{}`.
298
594
  Claude's host `sdkMcpServers` remain attached. The native CLI may also load MCP servers
299
- from settings or plugins; this map is not an exclusive tool allowlist.
595
+ from settings or plugins (Claude not at `inheritConfig: "none"`); this map is
596
+ not an exclusive tool allowlist.
597
+
598
+ Each server is one the turn needs unless it says `required: false`. A turn
599
+ fails before the model runs when a server it needs cannot connect: the error is
600
+ `mcp_unavailable`, names each server and why, and says how to drop it. A
601
+ server that is not required and cannot connect is said as a recoverable
602
+ `error` of the same category (no `retry`), and the turn goes on without its
603
+ tools. A later turn tries it again once 30 s have passed (`MCP_RETRY_MS`),
604
+ and at once when its configuration changes or a turn requires it. The
605
+ flag is the engine's: Claude and Codex never see it. An ACP agent connects
606
+ its servers itself and decides. The repository's CLI gives turns the servers
607
+ a user adds as not required, as Claude Code treats them;
608
+ `/mcp <name> required` makes turns need one.
300
609
 
301
610
  The engine snapshots the supplied wire configuration, including headers,
302
611
  before asynchronous setup. Credential rotation therefore works even if the
@@ -308,15 +617,15 @@ expiry; ending a turn does not itself revoke an attached credential.
308
617
 
309
618
  Codex supports stdio and Streamable HTTP servers; legacy SSE is rejected. Its
310
619
  per-turn MCP configuration requires an existing, absolute, session-specific
311
- `config.env.CODEX_HOME` directory. Create it with mode `0700`, retain it while
620
+ `config.env.CODEX_HOME` directory (below `inheritConfig: "all"` every Codex
621
+ turn does). Create it with mode `0700`, retain it while
312
622
  the conversation may resume, and delete it when that logical session is
313
623
  released. It contains conversation history and MCP credentials. Never share
314
- it between sessions or use the operator's normal Codex home. AGNT supplies
315
- and owns these directories for its callers.
624
+ it between sessions or use the operator's normal Codex home.
316
625
 
317
626
  This isolates writable MCP configuration and conversation state; it does not
318
627
  require a separate ChatGPT login for each home. An embedding host can supply
319
- access credentials through [`codexAppServer.resolveAuth`](harnesses.md#host-managed-codex-authentication)
628
+ access credentials through [`credentials`](harnesses.md#host-managed-codex-authentication)
320
629
  while retaining login and token renewal in its own account manager.
321
630
 
322
631
  The repository's interactive CLI accepts `--codex-home=/absolute/private/path`
@@ -341,8 +650,12 @@ is reserved.
341
650
  Codex writes changed configuration without reloading, verifies its effective
342
651
  settings, then reloads MCP and checks readiness before submitting the prompt.
343
652
  Servers still starting are awaited through native startup notifications, with
344
- a bounded deadline; unavailable or failed servers fail preparation immediately.
345
- Unchanged configuration is checked without reloading. A failed setup fails
653
+ a bounded deadline (30 seconds); a required server that failed fails
654
+ preparation at once, with the cause Codex gave.
655
+ Unchanged configuration is checked without reloading, and readiness is read
656
+ for each requested server by name on the turn's thread, which answers from
657
+ the thread's connection: Codex connects to a server once per process, not on
658
+ every turn. A failed setup fails
346
659
  the turn; an explicitly submitted next turn reapplies the configuration so a
347
660
  previously failed native client can reconnect. No model turn or tool call is
348
661
  automatically replayed.
@@ -369,8 +682,9 @@ are unaffected. Other harnesses without this lifecycle hook are unaffected.
369
682
  Claude MCP updates also repair a transient socket setup failure once. Recovery
370
683
  removes and re-adds the affected connection: an identical SDK update can cache
371
684
  a failed client, and the SDK's reconnect-by-name command can restore startup
372
- credentials. Persistent connection failures and invalid credentials fail the
373
- turn before prompt submission. Tool calls and model turns are never replayed.
685
+ credentials. A required server's persistent connection failure or invalid
686
+ credentials fail the turn before prompt submission. Tool calls and model turns
687
+ are never replayed.
374
688
 
375
689
  ### Release a session
376
690
 
@@ -388,7 +702,7 @@ completion before starting another turn on that ID. Await shutdown before
388
702
  disposing the runtime. Cancellation acknowledgement alone does not mean the
389
703
  old execution has finished cleaning up.
390
704
 
391
- `session/close` also broadcasts `session.ended {reason: "released"}` — but
705
+ `session/close` also broadcasts `session.ended {reason: "closed"}` — but
392
706
  only to subscribers **connected at that moment**, because the replay log is
393
707
  retired in the same operation. A subscriber that was detached does not get the
394
708
  event later: its `events/replay` answers `unknownSession`, and that answer *is*
@@ -406,12 +720,79 @@ product that doesn't surface them debugs blind.
406
720
 
407
721
  `spawn` (stdio subprocess), `connect` (dial a `--listen` server; reconnects
408
722
  and replays by default), `attach` (an accepted socket, e.g. the server dialed
409
- OUT to you via `--dial`). The client dedupes by per-session `seq` and heals
410
- gaps via `events/replay`; an unfillable gap raises `EventGapError` instead of
411
- silently losing events. When using `startTurn` with `onEvent`, subscribe to
412
- `onEventGap` before starting work. It runs synchronously before any surviving
413
- suffix and returns an unsubscribe function. `runTurn().result` continues to
414
- reject on these same gaps.
723
+ OUT to you via `--dial`). In one process, `channelPair()` (root and
724
+ `/protocol`) is the wire between them: `server.attach(pair.server)`, then
725
+ `AgentServerClient.attach(pair.client)`; `kill()` drops it at both ends.
726
+
727
+ A connection receives the sessions it subscribes to, not every session on
728
+ the server, in two ways. A turn's subscription: `runTurn` and `startTurn`
729
+ subscribe the client to their turn from the head at admission (the ack's
730
+ `headSeq`) until the turn's `turn.ended`, so a turn in a session with
731
+ history downloads none of it, and `runTurn`'s handle starts at its own
732
+ `turn.started`. A watch: `subscribe(sessionId, {afterSeq})` follows a session
733
+ from `afterSeq` (its kept events after it reach `onEvent` first, then its
734
+ open parts, then its frames live; omitted, from the head) until
735
+ `unsubscribe`, which ends the watch (a turn of this client's there is still
736
+ followed to its end); `subscribeAll()` is for observers: every session, live
737
+ from then, with no history (`session/subscribeAll` on the wire; `unsubscribeAll()`
738
+ is `session/unsubscribeAll`). `joinTurn(sessionId, {fromSeq})` watches the
739
+ session and joins the turn it runs (`undefined` when none): a handle that
740
+ yields the kept events from `fromSeq` (default: the turn's start), then the
741
+ turn's open parts, then live frames through its `turn.ended`, each once,
742
+ however many handles join; its `catchUp` says how many of its first events
743
+ were replayed. `runTurn(params, {signal})` and `joinTurn(sessionId,
744
+ {signal})` stop following when the signal aborts: the handle's `events` and
745
+ `result` fail with an `AbortError`, the turn runs on (`cancelTurn` stops it),
746
+ and `onEvent` still hears it to its end. `steerTurn` follows the turn it
747
+ steers in a session the client does not follow, so the steer's user message
748
+ reaches it.
749
+
750
+ `onEvent` delivers a session's events while the client watches it or one of
751
+ its turns runs in it (`AgentServer.onEvent`, in process, still sees every
752
+ session): a session whose turn ended, and that it does not watch, is let go,
753
+ with what the client kept of it. A redial subscribes again to each session
754
+ followed, from what the client holds, the running turns' first, and so does a
755
+ `session/overflow`: the notice a server sends when the connection fell
756
+ `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
758
+ fails the session's turns with `EventGapError` (`onEventGap`:
759
+ `session_missing`, or `subscription_refused`) instead of leaving them
760
+ waiting. When the answer says the turn it subscribed again for runs no more
761
+ (it ended while the client was away), the client replays up to the answer's
762
+ `headSeq`, the turn's end with it unless the window evicted it, and lets the
763
+ session go unless it watches it. A connection may watch at most `maxSubscriptions` sessions (256;
764
+ `subscribeAll` counts once), past which `subscribe` is refused
765
+ `subscriptionLimit`: unsubscribe what you no longer watch. A turn's
766
+ subscription never counts and ends with the turn, so a backend that runs
767
+ every session's turns over one connection is never refused a turn, and
768
+ follows only the sessions whose turns run and those it watches.
769
+
770
+ The client dedupes by per-session `seq` and heals gaps via `events/replay`;
771
+ an unfillable gap raises `EventGapError` instead of silently losing events.
772
+ `replay(sessionId, fromSeq)` is one page of a session's kept events;
773
+ `replayAll(sessionId, fromSeq, throughSeq?)` reads every page through
774
+ `throughSeq` (default: the last), failing `EventGapError` when some were
775
+ evicted.
776
+ When using `startTurn` with `onEvent`, subscribe to `onEventGap` before
777
+ starting work. It runs synchronously before any surviving suffix and returns
778
+ an unsubscribe function. `runTurn().result` continues to reject on these same
779
+ gaps.
780
+
781
+ `onConnection` says what the connection does, so a product can show an
782
+ outage instead of going quiet: `disconnected` (with the reason), `reconnecting`
783
+ before each redial (`attempt`, `delayMs`, and the `error` the one before
784
+ failed with), `reconnected` (`attempts`, `downMs`, the new `initialize`, and
785
+ `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
790
+ redial, redialing that gave up after `maxReconnectAttempts`, default 8,
791
+ `Infinity` redials until `close()`, or a refusal).
792
+ Handlers run before requests waiting on the redial are sent again. After
793
+ `serverChanged`, a turn under a session id the old server knew starts a new
794
+ history there: name its native conversation (`config.resumeSessionId`) to
795
+ continue it.
415
796
 
416
797
  A gap describes incomplete delivery, not a successful stop. Keep the affected
417
798
  turn's output marked incomplete even if its native terminal says `end_turn`.
@@ -420,19 +801,37 @@ turn's output marked incomplete even if its native terminal says `end_turn`.
420
801
  `cancelTurn(sessionId, turnId)` to reconcile execution. Never cancel a successor
421
802
  by reading its ID after an asynchronous recovery operation.
422
803
 
423
- The WebSocket wire itself carries no auth — keep it
424
- on a trusted channel (localhost, sandbox-internal, or behind your own
425
- authenticated boundary).
426
-
427
- ## Feedback
428
-
429
- If anything in this guide is broken, confusing, outdated, or notably good,
430
- report it to the maintainers (no auth, one command):
431
-
432
- ```sh
433
- npx --yes hivenet@latest --to agent-server --category docs --subject "docs/consuming.md" "<specific, actionable feedback>"
434
- ```
435
-
436
- The response may include `guidance` (a maintainer reply) and an `ask` (their
437
- question plus a ready-to-run answer command — answer only from what you actually
438
- observed). Only specific, actionable reports.
804
+ Localhost is not a trusted channel against browsers: any page the user
805
+ visits may open a WebSocket to `127.0.0.1` (CORS does not apply to
806
+ WebSockets) and run a turn there, tools and `bypass_permissions` included.
807
+ So a listener answers native clients only (LLP 0001, D16). An upgrade that
808
+ carries an `Origin` header, which a browser always sends and Bun's and
809
+ Node's WebSocket never do, is refused 403 unless that origin is allowed
810
+ (`--allow-origin`, `ListenOptions.allowedOrigins`): exactly
811
+ `scheme://host[:port]` as the browser sends it, never `null` or a wildcard.
812
+ A product whose browser, Electron or Tauri renderer connects directly allows
813
+ its own origin, on a loopback listener without a token, since a browser
814
+ cannot send one. A token (`--token-file <path>` or `$AGENT_SERVER_TOKEN`;
815
+ `ListenOptions.token`) makes every upgrade carry `Authorization: Bearer
816
+ <token>` or be refused 401, and a listener beyond loopback will not start
817
+ without one: `AgentServerClient.connect(url, {token})` sends it with every
818
+ dial and redial. A server that refuses the client fails `connect` with
819
+ `ConnectionRefusedError` (a `ConnectionClosedError`; `reason`
820
+ `token_refused` for a token it sent, `token_required` for none), and is not
821
+ redialed: since a WebSocket does not say why its handshake failed, the client
822
+ asks once with a plain request carrying the same headers, and only a 401
823
+ answer is a refusal. A 403 is not (`listen` sends it only for an `Origin`,
824
+ which a native client never sends): it comes from something in front of the
825
+ server, a proxy, and the client redials on. The token
826
+ authenticates the connection, not a user, and the wire has no TLS of its own:
827
+ put a `wss://` proxy in front of a listener other machines reach. stdio
828
+ inherits its spawner's trust, and `dial` connects out (`dial(server, url,
829
+ {headers})` sends a credential in a header, not the URL; the bin's `--dial`
830
+ sends `$AGENT_SERVER_DIAL_TOKEN` so, the credential it presents to the
831
+ platform it dials, never `$AGENT_SERVER_TOKEN`, which a listener's clients
832
+ present).
833
+ Subscriptions filter delivery; they are not an authorization boundary.
834
+
835
+ ---
836
+
837
+ Something here wrong, unclear or missing? [Report it to the maintainers](feedback.md).