@zvada/agent-server 0.3.18 → 0.3.20

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 +1041 -1
  3. package/README.md +40 -40
  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 +45 -28
  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 +155 -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
@@ -0,0 +1,107 @@
1
+ import type { MessagePartDeltaEvent } from "../protocol/index.ts";
2
+ import type { Db } from "./sql.ts";
3
+
4
+ /** A streaming part with rows: what it streamed since its last kept snapshot. */
5
+ interface Tail {
6
+ sessionId: string;
7
+ turnId: string;
8
+ partId: string;
9
+ /** The rows it has, the next one's `n`. */
10
+ rows: number;
11
+ }
12
+ const keyOf = (sessionId: string, partId: string) => `${sessionId}\u0000${partId}`;
13
+
14
+ /**
15
+ * Each streaming part's tail, kept outside every history so recovery closes
16
+ * the part with what was shown: one row per delta. The only code that touches
17
+ * the `live_tails` table, as `EventLog` is for the histories; which parts
18
+ * have rows is kept in memory too, to number the next row and drop a turn's.
19
+ */
20
+ export class LiveTails {
21
+ private readonly tails = new Map<string, Tail>();
22
+
23
+ constructor(private readonly db: Db) {}
24
+
25
+ // @ref LLP 0003#a-crash-keeps-what-was-shown — written before the delta is delivered
26
+ // @ref LLP 0008#the-journal-live_tails-becomes-append-only — a row per delta, never the whole part again
27
+ /** Append what `event` streamed to its part's tail. */
28
+ keep(event: MessagePartDeltaEvent): void {
29
+ const key = keyOf(event.sessionId, event.partId);
30
+ let tail = this.tails.get(key);
31
+ if (!tail) {
32
+ tail = { sessionId: event.sessionId, turnId: event.turnId, partId: event.partId, rows: 0 };
33
+ this.tails.set(key, tail);
34
+ }
35
+ // Every delta, as kept events are committed before delivery: a model can
36
+ // stream hundreds of characters in one burst, and what a client was
37
+ // shown must not depend on a timer. A row of its own: the tail is the
38
+ // whole part now that no checkpoint is kept, and rewriting it per delta
39
+ // grows with the square of its length (250 MB written for a 100 KB tool
40
+ // input, where appending costs a flat 14 µs). Without an fsync: a
41
+ // committed write survives the process dying at any `synchronous` level
42
+ // (only power loss could lose it), and the next kept event's commit
43
+ // flushes it; an fsync'd write took 60 µs on a laptop and a millisecond
44
+ // on cloud disks, on the server's one thread.
45
+ const level = this.relaxSync();
46
+ try {
47
+ this.db.run(
48
+ "INSERT INTO live_tails(session_id,turn_id,part_id,n,body) VALUES (?,?,?,?,?)",
49
+ tail.sessionId,
50
+ tail.turnId,
51
+ tail.partId,
52
+ tail.rows,
53
+ event.delta.type === "tool_input" ? event.delta.input : event.delta.text,
54
+ );
55
+ tail.rows++;
56
+ } finally {
57
+ if (level !== undefined) this.db.exec(`PRAGMA synchronous=${level}`);
58
+ }
59
+ }
60
+
61
+ /** The part's kept snapshot holds what it streamed so far. */
62
+ dropPart(sessionId: string, partId: string): void {
63
+ if (!this.tails.delete(keyOf(sessionId, partId))) return;
64
+ this.db.run("DELETE FROM live_tails WHERE session_id=? AND part_id=?", sessionId, partId);
65
+ }
66
+
67
+ /** The turn ended: its parts stream no more. */
68
+ dropTurn(sessionId: string, turnId: string): void {
69
+ for (const tail of [...this.tails.values()])
70
+ if (tail.sessionId === sessionId && tail.turnId === turnId)
71
+ this.dropPart(sessionId, tail.partId);
72
+ }
73
+
74
+ /** What the turn's parts streamed after their last kept snapshots, by part id: their rows joined in order. */
75
+ ofTurn(sessionId: string, turnId: string): Map<string, string> {
76
+ const tails = new Map<string, string>();
77
+ for (const row of this.db.all<{ part_id: string; body: string }>(
78
+ "SELECT part_id,body FROM live_tails WHERE session_id=? AND turn_id=? ORDER BY part_id,n",
79
+ sessionId,
80
+ turnId,
81
+ ))
82
+ tails.set(row.part_id, (tails.get(row.part_id) ?? "") + row.body);
83
+ return tails;
84
+ }
85
+
86
+ /** Forget every tail: only an interrupted turn's mean anything, and recovery took them. */
87
+ clear(): void {
88
+ this.tails.clear();
89
+ this.db.run("DELETE FROM live_tails");
90
+ }
91
+
92
+ /**
93
+ * Set the connection to NORMAL for one write, returning the level to put
94
+ * back: read each time, as SQLite moves an unset level by itself. Best
95
+ * effort: a host that refuses the pragma gets the write as it stands.
96
+ */
97
+ private relaxSync(): number | undefined {
98
+ try {
99
+ const level = this.db.one<{ synchronous: number }>("PRAGMA synchronous")?.synchronous;
100
+ if (level === undefined || level <= 1) return undefined;
101
+ this.db.exec("PRAGMA synchronous=NORMAL");
102
+ return level;
103
+ } catch {
104
+ return undefined;
105
+ }
106
+ }
107
+ }
@@ -0,0 +1,35 @@
1
+ import {
2
+ type ConversationState,
3
+ HISTORY_MAX_BYTES,
4
+ type HistoryCheckpoint,
5
+ HistoryError,
6
+ decodeLifecycleEvent,
7
+ jsonBytes,
8
+ reduceConversation,
9
+ } from "../protocol/index.ts";
10
+
11
+ /** The most events a projection folds unless its caller says otherwise: it is built in memory. */
12
+ const MAX_PROJECTION_RECORDS = 100_000;
13
+
14
+ /**
15
+ * A fold of history events into a conversation that takes at most
16
+ * `maxRecords` of them, across every call: past that it throws, and a longer
17
+ * history is read in pages instead.
18
+ */
19
+ export function projectionFold(
20
+ maxRecords = MAX_PROJECTION_RECORDS,
21
+ ): (conversation: ConversationState, event: unknown) => ConversationState {
22
+ if (!Number.isSafeInteger(maxRecords) || maxRecords < 0)
23
+ throw new Error("maxRecords must be a nonnegative safe integer");
24
+ let left = maxRecords;
25
+ return (conversation, event) => {
26
+ if (--left < 0) throw new Error("History projection limit exceeded; use paged reads");
27
+ return reduceConversation(conversation, decodeLifecycleEvent(event));
28
+ };
29
+ }
30
+
31
+ /** A checkpoint fits a history page, as all history does: no store keeps, and no reader takes, a larger one. */
32
+ export function checkCheckpointBytes(checkpoint: HistoryCheckpoint): void {
33
+ if (jsonBytes(checkpoint) > HISTORY_MAX_BYTES)
34
+ throw new HistoryError("invalidParams", "Checkpoint exceeds byte limit; use paged history");
35
+ }
@@ -1,66 +1,43 @@
1
1
  import {
2
- type LifecycleEvent,
3
- PARTIAL_INPUT_META_KEY,
2
+ type ConversationState,
3
+ type HarnessId,
4
4
  type Part,
5
+ type RecoveryReason,
6
+ closeToolLeftOpen,
5
7
  decodeLifecycleEvent,
6
8
  emptyConversation,
7
9
  isUnknownEvent,
8
10
  reduceConversation,
9
11
  } from "../protocol/index.ts";
12
+ import type { SessionEvent } from "./fit.ts";
10
13
 
11
- /** What a tool that was running when the process died reports. */
12
- export const INTERRUPTED_TOOL_ERROR =
13
- "Tool execution was interrupted when agent-server stopped. Its outcome is unknown and its effects were not undone. Check the current state before continuing or retrying.";
14
-
15
- function closePart(part: Part, at: number): Part | undefined {
16
- if (part.type === "tool") {
17
- const state = part.state;
18
- if (state.status === "pending")
19
- return {
20
- ...part,
21
- state: {
22
- status: "failed",
23
- input: {},
24
- error: INTERRUPTED_TOOL_ERROR,
25
- time: { start: at, end: at },
26
- ...(state.partialInput && {
27
- _meta: { ...state._meta, [PARTIAL_INPUT_META_KEY]: state.partialInput },
28
- }),
29
- },
30
- };
31
- if (state.status === "in_progress")
32
- return {
33
- ...part,
34
- state: {
35
- status: "failed",
36
- input: state.input,
37
- error: INTERRUPTED_TOOL_ERROR,
38
- time: { start: state.time.start, end: at },
39
- ...(state._meta && { _meta: state._meta }),
40
- },
41
- };
42
- return undefined;
43
- }
44
- if ((part.type === "text" || part.type === "reasoning") && part.state === "streaming")
45
- return { ...part, state: "done" };
46
- return undefined;
14
+ /** A turn a server restart cut off, as the journal holds it. */
15
+ export interface CutOffTurn {
16
+ sessionId: string;
17
+ turnId: string;
18
+ /** The session's harness, which a turn cut off before its first event never named. */
19
+ harness: HarnessId;
20
+ /** When recovery ends it. */
21
+ at: number;
22
+ /** By part id, what a part streamed after its last kept snapshot. */
23
+ tails: ReadonlyMap<string, string>;
24
+ /** Why its session stays fenced; absent once the restart stopped its agent. */
25
+ fence?: RecoveryReason;
47
26
  }
48
27
 
49
28
  /**
50
- * The facts that close what an interrupted turn left open, to commit before
51
- * its `turn.ended`: pending permissions resolve as cancelled, running tools
52
- * fail with an outcome-unknown error, streaming text is marked done, and open
53
- * messages end. `events` is the turn's committed history, oldest first.
29
+ * The facts that end a turn a server restart cut off, in the order to commit
30
+ * them, so its history stays a valid stream: its `turn.started` when it was
31
+ * cut off before its first event; then what it left open closed (pending
32
+ * permissions and questions cancelled, running tools failed as interrupted,
33
+ * streaming parts done with their tails, open messages ended); then its
34
+ * `turn.ended`. `history` is the session's committed events, oldest first.
54
35
  */
55
- export function interruptionFacts(
56
- events: Iterable<unknown>,
57
- sessionId: string,
58
- turnId: string,
59
- at: number,
60
- ): LifecycleEvent[] {
36
+ export function recoveryFacts(history: Iterable<unknown>, turn: CutOffTurn): SessionEvent[] {
37
+ const { sessionId, turnId, at } = turn;
61
38
  let state = emptyConversation();
62
39
  const address = new Map<string, { messageId: string; outputIndex: number; partIndex: number }>();
63
- for (const raw of events) {
40
+ for (const raw of history) {
64
41
  const event = decodeLifecycleEvent(raw);
65
42
  state = reduceConversation(state, event);
66
43
  if (!isUnknownEvent(event) && event.type === "message.part" && event.turnId === turnId)
@@ -70,7 +47,15 @@ export function interruptionFacts(
70
47
  partIndex: event.partIndex,
71
48
  });
72
49
  }
73
- const facts: LifecycleEvent[] = [];
50
+ const facts: SessionEvent[] = [];
51
+ if (!state.turns.some((t) => t.turnId === turnId))
52
+ facts.push({
53
+ type: "turn.started",
54
+ sessionId,
55
+ turnId,
56
+ execution: { harness: turn.harness },
57
+ timestamp: at,
58
+ });
74
59
  for (const permission of state.permissions)
75
60
  if (permission.turnId === turnId && permission.outcome === undefined)
76
61
  facts.push({
@@ -81,6 +66,16 @@ export function interruptionFacts(
81
66
  outcome: { outcome: "cancelled" },
82
67
  timestamp: at,
83
68
  });
69
+ for (const elicitation of state.elicitations)
70
+ if (elicitation.turnId === turnId && elicitation.outcome === undefined)
71
+ facts.push({
72
+ type: "elicitation.resolved",
73
+ sessionId,
74
+ turnId,
75
+ requestId: elicitation.requestId,
76
+ outcome: { action: "cancel" },
77
+ timestamp: at,
78
+ });
84
79
  for (const entry of state.timeline) {
85
80
  if (entry.kind !== "message" || entry.turnId !== turnId) continue;
86
81
  // A tool keeps running after the model message that called it ends, and
@@ -88,7 +83,7 @@ export function interruptionFacts(
88
83
  for (const part of entry.parts) {
89
84
  if ("raw" in part) continue;
90
85
  const where = address.get(part.id);
91
- const closed = where && closePart(part, at);
86
+ const closed = where && closePart(state, turnId, part, at, turn.tails.get(part.id));
92
87
  if (where && closed)
93
88
  facts.push({
94
89
  type: "message.part",
@@ -108,5 +103,39 @@ export function interruptionFacts(
108
103
  timestamp: at,
109
104
  });
110
105
  }
106
+ facts.push({
107
+ type: "turn.ended",
108
+ sessionId,
109
+ turnId,
110
+ stopReason: "error",
111
+ error: {
112
+ category: "server_restart",
113
+ message: turn.fence
114
+ ? `Server restarted before the turn settled and could not confirm its agent stopped (${turn.fence}); check it before continuing.`
115
+ : "Server restarted before the turn settled. Its agent was stopped at restart; what its running tool did is unknown.",
116
+ },
117
+ timestamp: at,
118
+ });
111
119
  return facts;
112
120
  }
121
+
122
+ // A tool closes as the reducer closes it, interrupted where it may have run.
123
+ // A streaming part keeps what it streamed after its last kept snapshot.
124
+ function closePart(
125
+ state: ConversationState,
126
+ turnId: string,
127
+ part: Part,
128
+ at: number,
129
+ tail = "",
130
+ ): Part | undefined {
131
+ if (part.type === "tool")
132
+ return closeToolLeftOpen(state, turnId, part, {
133
+ at,
134
+ cancelled: false,
135
+ outcomeUnknown: "interrupted",
136
+ tail,
137
+ });
138
+ if ((part.type === "text" || part.type === "reasoning") && part.state === "streaming")
139
+ return { ...part, text: part.text + tail, state: "done" };
140
+ return undefined;
141
+ }
@@ -1,9 +1,13 @@
1
1
  import type { Db } from "./sql.ts";
2
2
 
3
- /** Nothing has been released yet, so there are no migrations: an empty file
4
- * gets this schema, and a released change will add ordered migrations keyed
5
- * by `user_version`. Version 1 was an unreleased experiment's layout. */
6
- export const SCHEMA_VERSION = 2;
3
+ /** The journal format, kept in `user_version`. An empty file gets this schema;
4
+ * a file of another version is refused, never migrated. Version 6 keeps a
5
+ * streaming part's tail as one row per delta, since with no checkpoints the
6
+ * tail is the whole part; version 5 keeps the native processes its owners
7
+ * started, and why a fence could not be lifted; version 4 keeps each
8
+ * streaming part's unsnapshotted tail for recovery; version 3 stored no token
9
+ * deltas (wire v3); version 2 journals kept them at their own seq. */
10
+ const SCHEMA_VERSION = 6;
7
11
 
8
12
  const DDL = `
9
13
  CREATE TABLE identity (id TEXT PRIMARY KEY);
@@ -18,9 +22,11 @@ CREATE TABLE events (
18
22
  hash TEXT NOT NULL, body TEXT NOT NULL,
19
23
  PRIMARY KEY (source_id, session_id, seq));
20
24
  -- The sessions this store executes; their histories have its identity as source.
25
+ -- recovery_reason, with the fence: why a restart could not lift it.
21
26
  CREATE TABLE sessions (
22
27
  session_id TEXT PRIMARY KEY, harness TEXT NOT NULL, native_id TEXT,
23
- closed INTEGER NOT NULL DEFAULT 0, recovery_required INTEGER NOT NULL DEFAULT 0);
28
+ closed INTEGER NOT NULL DEFAULT 0, recovery_required INTEGER NOT NULL DEFAULT 0,
29
+ recovery_reason TEXT);
24
30
  -- Admitted turns: the request's fingerprint and input, then how it settled.
25
31
  CREATE TABLE turns (
26
32
  session_id TEXT NOT NULL, turn_id TEXT NOT NULL, fingerprint TEXT NOT NULL,
@@ -31,6 +37,21 @@ CREATE UNIQUE INDEX one_active_turn ON turns (session_id) WHERE state = 'admitte
31
37
  CREATE TABLE commits (
32
38
  session_id TEXT NOT NULL, commit_id TEXT NOT NULL, fingerprint TEXT NOT NULL,
33
39
  version TEXT NOT NULL, PRIMARY KEY (session_id, commit_id));
40
+ -- What each open part streamed since its last kept snapshot, one row per
41
+ -- delta: never part of a history, written before the delta is delivered,
42
+ -- deleted with the part's next kept snapshot or its turn's end. Recovery
43
+ -- closes the part with its rows, in order.
44
+ CREATE TABLE live_tails (
45
+ session_id TEXT NOT NULL, turn_id TEXT NOT NULL, part_id TEXT NOT NULL,
46
+ n INTEGER NOT NULL, body TEXT NOT NULL, PRIMARY KEY (session_id, part_id, n));
47
+ -- The native processes this store's owners started, until each is seen gone:
48
+ -- what a restart verifies and stops before it decides whether to fence. pid
49
+ -- (also its process group) is NULL when a host's own spawner started it.
50
+ -- Never part of a history.
51
+ CREATE TABLE native_processes (
52
+ id INTEGER PRIMARY KEY, session_id TEXT NOT NULL, harness TEXT NOT NULL,
53
+ pid INTEGER, boot TEXT, started TEXT, executable TEXT NOT NULL);
54
+ CREATE INDEX native_processes_session ON native_processes (session_id);
34
55
  -- Cached conversation projections; the events stay authoritative.
35
56
  CREATE TABLE checkpoints (
36
57
  source_id TEXT NOT NULL, session_id TEXT NOT NULL, format TEXT NOT NULL,
@@ -44,7 +65,7 @@ export function openSchema(db: Db, newId: () => string): string {
44
65
  const { user_version: version } = db.one<{ user_version: number }>("PRAGMA user_version")!;
45
66
  if (version !== 0 && version !== SCHEMA_VERSION)
46
67
  throw new Error(
47
- `Unsupported journal schema ${version}; this build reads schema ${SCHEMA_VERSION}`,
68
+ `Unsupported journal schema ${version}; this build reads schema ${SCHEMA_VERSION}. Open it with the agent-server that wrote it, or start a new journal file`,
48
69
  );
49
70
  return db.atomic(() => {
50
71
  if (version === 0) {
@@ -1,44 +0,0 @@
1
- # RFD 0001 — Deterministic echo ids
2
-
3
- **Status: adopted** (0.3.0, unpublished — shipped with the consumer-machinery batch).
4
-
5
- ## Change
6
-
7
- The user echo's ids are **derived from the turn id** instead of minted as UUIDv7:
8
-
9
- - echo message id: `echo-<turnId>`
10
- - echo part ids: `echo-<turnId>-<index>`
11
-
12
- Exported as `echoMessageId(turnId)` / `echoPartId(turnId, index)`;
13
- `createUserEchoParts(input, turnId)` stamps them. This is a **documented
14
- exception to Law 8** (engine-minted UUIDv7).
15
-
16
- ## Why
17
-
18
- The echo is not new information — it is the caller's own input played back, and
19
- one turn has exactly one echo message. Every consumer that renders an
20
- optimistic prompt bubble was reconciling a look-alike against the echo by
21
- `turnId` (spec §7.2's old rule) — a swap with visible failure modes (deus lost
22
- file parts in the swap; agnt double-echoed). With derived ids, a consumer that
23
- minted the `turnId` predicts the echo **byte-for-byte**: the optimistic bubble
24
- IS the echo, and it upserts onto itself. Retried turns converge the same way
25
- (turn admission is idempotent on `{sessionId, turnId}`).
26
-
27
- ## What ids still are
28
-
29
- Opaque to peers. Derivation is a producer rule matched by exported consumer
30
- helpers — not a licence to parse structure out of ids anywhere else.
31
-
32
- ## Costs (documented, accepted)
33
-
34
- - Echo ids do not time-sort against UUIDv7 ids. Never order by id; order by
35
- `outputIndex`/`seq` (which the spec already mandates — Law 5).
36
- - Echo ids fail UUID-shaped derivations: uuid-typed columns and
37
- `createdAtFromUUID7`-style timestamp extraction (returns 0). Derive the
38
- echo's time from the **`turnId` field** the event/row already carries (it is
39
- UUIDv7) — never by parsing the echo id string; ids stay opaque.
40
-
41
- ## Spec delta
42
-
43
- PROTOCOL.md §7.2 (echo reconciliation) and Law 8 (id minting) carry the
44
- amendment; `docs/consuming.md` describes prediction instead of reconciliation.
@@ -1,197 +0,0 @@
1
- # RFD 0002 — Native delegation within a managed turn
2
-
3
- **Status:** implemented; native Claude and Codex qualification passed on 2026-09-29.
4
- **Date:** 2026-09-29
5
- **Scope:** Claude Code and Codex app-server in agent-server and AGNT.
6
- **Baseline:** agent-server `7248c43`; AGNT `39df4fa9`.
7
-
8
- ## Recommendation
9
-
10
- Support native delegation inside the existing logical engine turn. The parent
11
- assigns work, collects results and produces the final answer. The engine retains
12
- ownership until its native work finishes or is stopped. AGNT keeps using its
13
- existing turn-scoped credentials, permission bridge, persistence and cancellation.
14
-
15
- This is a smaller extension of [DESIGN D10](../../../../DESIGN.md#d10--built-in-turns-own-their-logical-session-through-cleanup).
16
- It does not require a second scheduler, child credential leases, a worker
17
- database, or a stream that remains active between managed turns. Independently
18
- running workers across later turns are outside this first contract.
19
-
20
- ## What already works — observed
21
-
22
- Deus Machine already configures this engine with `forwardSubagentText: true`
23
- and renders nested subagent output. At `origin/main` `4e957a26c`, see
24
- `apps/agent-server/agents/core/engine.ts`,
25
- `apps/web/src/features/session/ui/blocks/SubagentGroupBlock.tsx` and
26
- `apps/backend/test/unit/services/event-persistence-integration.test.ts`.
27
- The last file tests nesting a worker message under its spawning tool. This is
28
- source evidence, not a new live execution.
29
-
30
- The engine already carries `ToolPart.subagent` and `parentToolCallId`; its
31
- `test/server/flows.test.ts` covers nested output. AGNT already round-trips these
32
- fields. Its two focused message suites passed **37 tests** during this rehearsal.
33
-
34
- [SessionAgent](../../src/core/agents/session-agent.ts) already reserves a session
35
- through `executeTurn` cleanup. AGNT's controller waits for its predecessor to
36
- drain before preparing a new credential and releases credentials in its existing
37
- `finally`. These are the owners to reuse.
38
-
39
- AGNT does not globally disable native delegation. Its explicit `toolAllowlist`
40
- rejects `Agent` and `Task`; QApp also omits them. AGNT's Claude SDK options omit
41
- Deus Machine's forwarding flag. Saying that the whole stack lacked subagents
42
- was too broad.
43
-
44
- ## Pass 1 — the smallest apparent patch
45
-
46
- 1. Enable Claude child-text forwarding in AGNT. Recognize modern `Agent` as
47
- well as legacy `Task` in the Claude adapter.
48
- 2. Normalize Codex's existing native delegation output.
49
- 3. Permit delegation under AGNT's scoped tool policy.
50
-
51
- Steps 1–3 alone are insufficient. The following counterexamples determine the
52
- additional work; they do not justify a general background-worker platform.
53
-
54
- ## Pass 2 — counterexamples and smallest corrections
55
-
56
- | Trigger and current path | Wrong result | Smallest correction and proof |
57
- | --- | --- | --- |
58
- | Claude returns its parent `result` while background work remains; `ClaudeGeneratorSession` closes the tap. | Late child output is lost or reaches the next tap after the host changes policy. | In the managed mode, enforce native foreground execution and qualify cleanup on the pinned SDK. Test cancellation plus a successor with changed policy. |
59
- | Codex emits root `turn/completed`; `executeTurn` ends its queue and removes listeners. | Child activity disappears; credentials can be released too early. | Track native descendants for this execution, separate parent completion from execution settlement, and retain the existing session reservation through cleanup. |
60
- | Merely delay Codex's queue end, leaving `turnEnded = true`. | `forceCancel` returns early, so cancellation can hang or falsely settle. | Make cancellation depend on execution settlement, target active owned native turns, and observe completion. Test cancel after the parent response. |
61
- | A Codex child requests approval. `bindRequests` currently declines every foreign thread id. | Owned children cannot use the existing permission broker. | Admit only descendants proven by native ownership; route them through the current turn's handler. Test an owned child and an unrelated thread. |
62
- | Treat `client.close()` or a stop request as proof of teardown. | Current `close()` marks itself closed before the OS process exits. | Await actual native completion or bounded subprocess teardown; qualify descendant tools too. Never report a clean stop from the local boolean alone. |
63
- | Set foreground behavior globally for all engine consumers. | Existing interactive Deus Machine behavior changes unintentionally. | Use one explicit managed-turn option, include it in native session configuration, and preserve the default for existing consumers. |
64
- | Wait for workers after the parent has already submitted its answer. | The final answer may never have used their results. | Require the parent to collect results. If it returns with outstanding work, stop that work and report incomplete execution; do not silently run another model turn. |
65
-
66
- The earlier synthetic probes reproduced omitted adapter events and late-tap
67
- routing, not a live permission escape. Artifacts remain under
68
- `.context/subagents-research/` and QApp's `.context/delegation-audit/`.
69
-
70
- ## Pass 3 — revised implementation
71
-
72
- ### Engine option and lifetime
73
-
74
- The opt-in `RunConfig.subagentMode: "turn"` preserves existing native behavior
75
- when omitted. Unsupported
76
- harnesses reject the request. Thread it through
77
- `src/protocol/config.ts`, `src/core/agents/base.ts`,
78
- `src/core/runtime/agent-runtime.ts` and native session configuration.
79
- A warm process must not silently retain an incompatible mode.
80
-
81
- The normal path remains one run: native workers execute, the parent receives
82
- their results, and the engine finishes after native cleanup. Multiple native
83
- workers may run concurrently where the pinned harness supports it; qualify that
84
- behavior rather than promising it from an SDK option.
85
-
86
- The adapter needs an execution-local record of owned native work, not a durable
87
- child-session service. Track starts, terminal outcomes and active native turn
88
- identifiers, including descendants. A spawn acknowledgement is not completion.
89
- On early parent exit or cancellation, stop remaining owned work before releasing
90
- ownership. Failure to establish cleanup must remain a failed/unconfirmed
91
- execution and prevent unsafe session reuse. Do not add automatic retries or
92
- background parent wake-ups.
93
-
94
- ### Claude
95
-
96
- Use the native foreground control in managed mode and forward child text.
97
- The current [Claude documentation](https://code.claude.com/docs/en/sub-agents#run-subagents-in-foreground-or-background)
98
- documents `CLAUDE_CODE_DISABLE_BACKGROUND_TASKS=1`; verify the behavior against
99
- the pinned SDK **0.3.220**, including explicit background requests and
100
- cancellation. Reuse the existing message nesting.
101
-
102
- Changes belong in `claude-code/options.ts`, `claude-agent.ts`,
103
- `generator-session.ts` as required by that qualification, and the
104
- `subagentFromInput` branch in `claude-code/adapter.ts`. Do not build a separate
105
- Claude scheduler. If the native foreground control does not contain the pinned
106
- runtime, keep the managed capability disabled until that specific gap is fixed.
107
-
108
- ### Codex
109
-
110
- The pinned CLI **0.153.4** emits V1 `collabAgentToolCall` and V2
111
- `subAgentActivity`. Both currently disappear in the adapters. V2 activity may
112
- arrive after its originating parent response. The
113
- [pinned app-server contract](https://github.com/openai/codex/blob/3d2ee51ca2d5db578f328aa75e20aa22c0197c9a/codex-rs/app-server/README.md)
114
- supports `turn/interrupt` for parent-owned V2 children too: use each child's
115
- active native turn, then observe its terminal outcome. Interrupting an already
116
- completed root is insufficient. Native background terminals have a separate
117
- cleanup operation; include child-owned terminals in cancellation qualification.
118
-
119
- Implement ownership, notification selection and drain behavior in
120
- `codex-app-server/codex-app-server-agent.ts`; add awaited process-exit fallback
121
- in `client.ts`. Use native parent links/read APIs to settle notification-order
122
- races, never permissive thread matching. Child approval handling stays on the
123
- existing broker.
124
-
125
- Normalize V1 calls in `codex-app-server/adapter.ts` and `codex-items.ts`.
126
- Preserve real native ids, results and task metadata. V2 is an activity, not a
127
- public tool invocation: add the small typed activity representation it needs to
128
- the existing Part/adapter/reducer path rather than inventing a tool call.
129
- Carry its native activity id, child thread id and observed kind. This is a
130
- persisted message part, not a new independently managed session. Full child
131
- transcript parity is not a prerequisite; unavailable transcripts stay explicit.
132
-
133
- ### AGNT and review consumers
134
-
135
- AGNT enables the qualified managed mode in `AgentEngine.prepareTurn` and adds
136
- `forwardSubagentText`. Its existing controller and credential cleanup remain
137
- the owners. Extend existing part persistence only for the activity shape the
138
- engine actually emits; no new worker table is needed.
139
-
140
- Relax `Agent`/`Task` rejection only when child tools demonstrably obey the same
141
- Claude allowlist, including bypass mode. Gate this admission on an updated
142
- sidecar version. Codex's existing lack of custom `toolAllowlist` enforcement
143
- remains a separate limitation; this work must not claim to solve it.
144
-
145
- The parent decides what to test through skills, gives each worker the necessary
146
- context, waits for results and submits one report. Device workers share no
147
- simulator concurrently unless separate devices exist. QApp's evidence still
148
- comes through its trusted capture path. No review roles belong in the engine.
149
-
150
- ## Checks that establish the feature
151
-
152
- - Adapter fixtures cover modern Claude `Agent`, legacy `Task`, Codex V1 and
153
- V2, interleaved workers, native ids and honest outcomes.
154
- - Runtime tests cover early parent completion, child failure, cancellation while
155
- waiting, owned/unrelated approvals, actual teardown, and a successor with
156
- different credentials/MCP/policy. No old child reaches that successor.
157
- - Existing reducer, replay and AGNT JSON-part round trips retain nesting and
158
- activity without a separate lifecycle database.
159
- - Live pinned Claude and Codex runs each delegate two tasks and incorporate both
160
- results. Repeat through AGNT's real proxy/MCP path, including a denied child
161
- tool for Claude. Prove stop behavior and absence of continued child execution.
162
- - Existing consumers without the managed option keep their native behavior.
163
- A QApp review demonstrates worker evidence reaching the final report and
164
- visible partial coverage on failure.
165
-
166
- ## Implementation qualification
167
-
168
- The deterministic engine suite passes (907 tests). The opt-in live suite
169
- `test/core/live/subagents.live.test.ts` passes four real-model cases: Claude and
170
- Codex each delegate to two workers and incorporate both unique file values;
171
- each cancels a worker running a real shell command, confirms that PID stopped,
172
- and successfully runs a successor. Proof is retained in `.context/proof/subagents`.
173
- No simulator was used in these engine tests.
174
-
175
- Live testing found that Claude can return `error_during_execution` with
176
- `stop_reason: tool_use` on an acknowledged cancellation. The adapter now uses
177
- the confirmed interrupt marker to distinguish that from an execution failure.
178
-
179
- Codex can register a background terminal AFTER its thread becomes idle. An
180
- interrupt response and empty terminal list therefore cannot prove cleanup.
181
- Managed Codex turns close the app-server through stdin EOF after reconciliation,
182
- which invokes native thread/tool shutdown. Root SIGTERM alone left a real child
183
- command running on macOS. Forced exits or native cleanup warnings are unconfirmed
184
- and quarantine the logical session. A managed successor resumes persisted context
185
- in a fresh process; the default interactive mode retains its warm process.
186
-
187
- This contract covers native managed work. It does not turn arbitrary shell
188
- commands into an OS containment boundary; sandbox custody remains with the host.
189
- AGNT and QApp integration qualification is recorded in their own design documents.
190
-
191
- Repeated cancellation also consults persistent unconfirmed native cleanup after the wrapper turn has ended. The idle response of another harness must not erase that result in the host. AGNT cloud qualification additionally verified real child PID cleanup and a successful successor for both harnesses.
192
-
193
- Releasing a quarantined Codex session also refuses unconfirmed cleanup. A host
194
- must propagate that release failure before resetting the session or switching
195
- harnesses; otherwise a successor could bypass the same-harness admission guard.
196
- Deterministic regressions cover failure after normal parent completion, repeated
197
- release attempts, and successful release after confirmed cleanup.
@@ -1,19 +0,0 @@
1
- export const DEFAULT_REQUEST_TIMEOUT_MS = 30_000;
2
-
3
- /** The server answered a request with a JSON-RPC error. */
4
- export class WireRequestError extends Error {
5
- override readonly name = "WireRequestError";
6
- constructor(
7
- readonly code: number,
8
- message: string,
9
- readonly data?: unknown,
10
- ) {
11
- super(message);
12
- }
13
- }
14
-
15
- export interface ResultSchema<T> {
16
- safeParse(raw: unknown): { success: true; data: T } | { success: false };
17
- }
18
-
19
- export type Request = <T>(method: string, params: unknown, schema: ResultSchema<T>) => Promise<T>;