@zvada/agent-server 0.3.21 → 0.3.23

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (367) hide show
  1. package/CHANGELOG.md +332 -0
  2. package/README.md +2 -1
  3. package/dist/types/accounts/chatgpt.d.ts +1 -1
  4. package/dist/types/accounts/chatgpt.d.ts.map +1 -1
  5. package/dist/types/accounts/http.d.ts +2 -4
  6. package/dist/types/accounts/http.d.ts.map +1 -1
  7. package/dist/types/client/client.d.ts +37 -11
  8. package/dist/types/client/client.d.ts.map +1 -1
  9. package/dist/types/client/connection.d.ts +66 -13
  10. package/dist/types/client/connection.d.ts.map +1 -1
  11. package/dist/types/client/index.d.ts +1 -1
  12. package/dist/types/client/index.d.ts.map +1 -1
  13. package/dist/types/client/logins.d.ts +4 -3
  14. package/dist/types/client/logins.d.ts.map +1 -1
  15. package/dist/types/client/streams.d.ts +9 -3
  16. package/dist/types/client/streams.d.ts.map +1 -1
  17. package/dist/types/client/turns.d.ts +1 -1
  18. package/dist/types/client/turns.d.ts.map +1 -1
  19. package/dist/types/core/agents/acp/acp-agent.d.ts +34 -1
  20. package/dist/types/core/agents/acp/acp-agent.d.ts.map +1 -1
  21. package/dist/types/core/agents/acp/adapter.d.ts.map +1 -1
  22. package/dist/types/core/agents/acp/client.d.ts +12 -3
  23. package/dist/types/core/agents/acp/client.d.ts.map +1 -1
  24. package/dist/types/core/agents/acp/mappings.d.ts +8 -2
  25. package/dist/types/core/agents/acp/mappings.d.ts.map +1 -1
  26. package/dist/types/core/agents/base.d.ts +22 -8
  27. package/dist/types/core/agents/base.d.ts.map +1 -1
  28. package/dist/types/core/agents/claude-code/adapter.d.ts +7 -0
  29. package/dist/types/core/agents/claude-code/adapter.d.ts.map +1 -1
  30. package/dist/types/core/agents/claude-code/approvals.d.ts +4 -1
  31. package/dist/types/core/agents/claude-code/approvals.d.ts.map +1 -1
  32. package/dist/types/core/agents/claude-code/claude-agent.d.ts +16 -5
  33. package/dist/types/core/agents/claude-code/claude-agent.d.ts.map +1 -1
  34. package/dist/types/core/agents/claude-code/events.d.ts +9 -1
  35. package/dist/types/core/agents/claude-code/events.d.ts.map +1 -1
  36. package/dist/types/core/agents/claude-code/login.d.ts +4 -1
  37. package/dist/types/core/agents/claude-code/login.d.ts.map +1 -1
  38. package/dist/types/core/agents/claude-code/mcp.d.ts +21 -7
  39. package/dist/types/core/agents/claude-code/mcp.d.ts.map +1 -1
  40. package/dist/types/core/agents/claude-code/models.d.ts +5 -1
  41. package/dist/types/core/agents/claude-code/models.d.ts.map +1 -1
  42. package/dist/types/core/agents/claude-code/options.d.ts +10 -4
  43. package/dist/types/core/agents/claude-code/options.d.ts.map +1 -1
  44. package/dist/types/core/agents/claude-code/outcome.d.ts +3 -5
  45. package/dist/types/core/agents/claude-code/outcome.d.ts.map +1 -1
  46. package/dist/types/core/agents/claude-code/results.d.ts +16 -0
  47. package/dist/types/core/agents/claude-code/results.d.ts.map +1 -0
  48. package/dist/types/core/agents/claude-code/sdk-pair.d.ts +13 -0
  49. package/dist/types/core/agents/claude-code/sdk-pair.d.ts.map +1 -0
  50. package/dist/types/core/agents/claude-code/session.d.ts +50 -12
  51. package/dist/types/core/agents/claude-code/session.d.ts.map +1 -1
  52. package/dist/types/core/agents/claude-code/spend.d.ts +2 -1
  53. package/dist/types/core/agents/claude-code/spend.d.ts.map +1 -1
  54. package/dist/types/core/agents/claude-code/tools.d.ts +26 -3
  55. package/dist/types/core/agents/claude-code/tools.d.ts.map +1 -1
  56. package/dist/types/core/agents/codex-app-server/adapter.d.ts +2 -2
  57. package/dist/types/core/agents/codex-app-server/adapter.d.ts.map +1 -1
  58. package/dist/types/core/agents/codex-app-server/client.d.ts +21 -2
  59. package/dist/types/core/agents/codex-app-server/client.d.ts.map +1 -1
  60. package/dist/types/core/agents/codex-app-server/codex-agent.d.ts +61 -14
  61. package/dist/types/core/agents/codex-app-server/codex-agent.d.ts.map +1 -1
  62. package/dist/types/core/agents/codex-app-server/commands.d.ts +2 -2
  63. package/dist/types/core/agents/codex-app-server/commands.d.ts.map +1 -1
  64. package/dist/types/core/agents/codex-app-server/credentials.d.ts +5 -1
  65. package/dist/types/core/agents/codex-app-server/credentials.d.ts.map +1 -1
  66. package/dist/types/core/agents/codex-app-server/effort.d.ts +2 -1
  67. package/dist/types/core/agents/codex-app-server/effort.d.ts.map +1 -1
  68. package/dist/types/core/agents/codex-app-server/homes.d.ts +26 -5
  69. package/dist/types/core/agents/codex-app-server/homes.d.ts.map +1 -1
  70. package/dist/types/core/agents/codex-app-server/items.d.ts +27 -2
  71. package/dist/types/core/agents/codex-app-server/items.d.ts.map +1 -1
  72. package/dist/types/core/agents/codex-app-server/login.d.ts +4 -1
  73. package/dist/types/core/agents/codex-app-server/login.d.ts.map +1 -1
  74. package/dist/types/core/agents/codex-app-server/mcp.d.ts +45 -20
  75. package/dist/types/core/agents/codex-app-server/mcp.d.ts.map +1 -1
  76. package/dist/types/core/agents/codex-app-server/models.d.ts +3 -10
  77. package/dist/types/core/agents/codex-app-server/models.d.ts.map +1 -1
  78. package/dist/types/core/agents/codex-app-server/options.d.ts +32 -5
  79. package/dist/types/core/agents/codex-app-server/options.d.ts.map +1 -1
  80. package/dist/types/core/agents/codex-app-server/plan-approval.d.ts +2 -1
  81. package/dist/types/core/agents/codex-app-server/plan-approval.d.ts.map +1 -1
  82. package/dist/types/core/agents/codex-app-server/protocol.d.ts +16 -3
  83. package/dist/types/core/agents/codex-app-server/protocol.d.ts.map +1 -1
  84. package/dist/types/core/agents/codex-app-server/requests.d.ts.map +1 -1
  85. package/dist/types/core/agents/codex-app-server/session.d.ts +70 -33
  86. package/dist/types/core/agents/codex-app-server/session.d.ts.map +1 -1
  87. package/dist/types/core/agents/codex-app-server/subagents.d.ts +9 -4
  88. package/dist/types/core/agents/codex-app-server/subagents.d.ts.map +1 -1
  89. package/dist/types/core/agents/codex-app-server/thread-settings.d.ts +3 -2
  90. package/dist/types/core/agents/codex-app-server/thread-settings.d.ts.map +1 -1
  91. package/dist/types/core/agents/codex-app-server/turn-items.d.ts +2 -1
  92. package/dist/types/core/agents/codex-app-server/turn-items.d.ts.map +1 -1
  93. package/dist/types/core/agents/codex-app-server/turn.d.ts +37 -8
  94. package/dist/types/core/agents/codex-app-server/turn.d.ts.map +1 -1
  95. package/dist/types/core/agents/codex-app-server/user-login.d.ts +28 -0
  96. package/dist/types/core/agents/codex-app-server/user-login.d.ts.map +1 -0
  97. package/dist/types/core/agents/credentials.d.ts +3 -1
  98. package/dist/types/core/agents/credentials.d.ts.map +1 -1
  99. package/dist/types/core/agents/diffs.d.ts +9 -0
  100. package/dist/types/core/agents/diffs.d.ts.map +1 -0
  101. package/dist/types/core/agents/elicitation.d.ts +3 -2
  102. package/dist/types/core/agents/elicitation.d.ts.map +1 -1
  103. package/dist/types/core/agents/login.d.ts +6 -0
  104. package/dist/types/core/agents/login.d.ts.map +1 -1
  105. package/dist/types/core/agents/mcp-config.d.ts +0 -4
  106. package/dist/types/core/agents/mcp-config.d.ts.map +1 -1
  107. package/dist/types/core/agents/plan.d.ts +2 -13
  108. package/dist/types/core/agents/plan.d.ts.map +1 -1
  109. package/dist/types/core/agents/process-pool.d.ts +193 -0
  110. package/dist/types/core/agents/process-pool.d.ts.map +1 -0
  111. package/dist/types/core/agents/scripted/adapter.d.ts +68 -0
  112. package/dist/types/core/agents/scripted/adapter.d.ts.map +1 -0
  113. package/dist/types/core/agents/scripted/mcp-call.d.ts +56 -0
  114. package/dist/types/core/agents/scripted/mcp-call.d.ts.map +1 -0
  115. package/dist/types/core/agents/scripted/scripted-agent.d.ts +73 -0
  116. package/dist/types/core/agents/scripted/scripted-agent.d.ts.map +1 -0
  117. package/dist/types/core/agents/scripted/scripts.d.ts +29 -0
  118. package/dist/types/core/agents/scripted/scripts.d.ts.map +1 -0
  119. package/dist/types/core/agents/scripted/steps.d.ts +132 -0
  120. package/dist/types/core/agents/scripted/steps.d.ts.map +1 -0
  121. package/dist/types/core/agents/session-agent.d.ts +49 -6
  122. package/dist/types/core/agents/session-agent.d.ts.map +1 -1
  123. package/dist/types/core/diagnostics.d.ts +4 -1
  124. package/dist/types/core/diagnostics.d.ts.map +1 -1
  125. package/dist/types/core/index.d.ts +6 -1
  126. package/dist/types/core/index.d.ts.map +1 -1
  127. package/dist/types/core/presets.d.ts +32 -6
  128. package/dist/types/core/presets.d.ts.map +1 -1
  129. package/dist/types/core/processes/lifeline.d.ts +0 -20
  130. package/dist/types/core/processes/lifeline.d.ts.map +1 -1
  131. package/dist/types/core/provision/index.d.ts +2 -2
  132. package/dist/types/core/provision/index.d.ts.map +1 -1
  133. package/dist/types/core/provision/install-build.d.ts +2 -1
  134. package/dist/types/core/provision/install-build.d.ts.map +1 -1
  135. package/dist/types/core/provision/npm.d.ts +20 -8
  136. package/dist/types/core/provision/npm.d.ts.map +1 -1
  137. package/dist/types/core/provision/provisioner.d.ts +4 -1
  138. package/dist/types/core/provision/provisioner.d.ts.map +1 -1
  139. package/dist/types/core/provision/tools.d.ts +2 -1
  140. package/dist/types/core/provision/tools.d.ts.map +1 -1
  141. package/dist/types/core/runtime/agent-runtime.d.ts +18 -9
  142. package/dist/types/core/runtime/agent-runtime.d.ts.map +1 -1
  143. package/dist/types/core/runtime/event-processor.d.ts +5 -1
  144. package/dist/types/core/runtime/event-processor.d.ts.map +1 -1
  145. package/dist/types/core/runtime/harness-clis.d.ts +9 -0
  146. package/dist/types/core/runtime/harness-clis.d.ts.map +1 -1
  147. package/dist/types/core/runtime/harness-logins.d.ts +33 -5
  148. package/dist/types/core/runtime/harness-logins.d.ts.map +1 -1
  149. package/dist/types/core/runtime/model-lists.d.ts +2 -0
  150. package/dist/types/core/runtime/model-lists.d.ts.map +1 -1
  151. package/dist/types/core/runtime/permission-policy.d.ts +5 -3
  152. package/dist/types/core/runtime/permission-policy.d.ts.map +1 -1
  153. package/dist/types/core/runtime/request-broker.d.ts +2 -1
  154. package/dist/types/core/runtime/request-broker.d.ts.map +1 -1
  155. package/dist/types/core/runtime/turn.d.ts +14 -1
  156. package/dist/types/core/runtime/turn.d.ts.map +1 -1
  157. package/dist/types/core/utils/deadline.d.ts +6 -0
  158. package/dist/types/core/utils/deadline.d.ts.map +1 -1
  159. package/dist/types/core/utils/errors.d.ts +15 -1
  160. package/dist/types/core/utils/errors.d.ts.map +1 -1
  161. package/dist/types/operator/index.d.ts +11 -0
  162. package/dist/types/operator/index.d.ts.map +1 -0
  163. package/dist/types/operator/mcp.d.ts +33 -0
  164. package/dist/types/operator/mcp.d.ts.map +1 -0
  165. package/dist/types/operator/operator.d.ts +206 -0
  166. package/dist/types/operator/operator.d.ts.map +1 -0
  167. package/dist/types/operator/render.d.ts +89 -0
  168. package/dist/types/operator/render.d.ts.map +1 -0
  169. package/dist/types/operator/view.d.ts +44 -0
  170. package/dist/types/operator/view.d.ts.map +1 -0
  171. package/dist/types/protocol/auth.d.ts +54 -24
  172. package/dist/types/protocol/auth.d.ts.map +1 -1
  173. package/dist/types/protocol/clis.d.ts +14 -7
  174. package/dist/types/protocol/clis.d.ts.map +1 -1
  175. package/dist/types/protocol/config.d.ts +2 -0
  176. package/dist/types/protocol/config.d.ts.map +1 -1
  177. package/dist/types/protocol/conversation.d.ts +40 -3
  178. package/dist/types/protocol/conversation.d.ts.map +1 -1
  179. package/dist/types/protocol/credentials.d.ts +7 -0
  180. package/dist/types/protocol/credentials.d.ts.map +1 -1
  181. package/dist/types/protocol/execution.d.ts +2 -1
  182. package/dist/types/protocol/execution.d.ts.map +1 -1
  183. package/dist/types/protocol/factories.d.ts +12 -2
  184. package/dist/types/protocol/factories.d.ts.map +1 -1
  185. package/dist/types/protocol/harness.d.ts +6 -2
  186. package/dist/types/protocol/harness.d.ts.map +1 -1
  187. package/dist/types/protocol/history.d.ts +19 -0
  188. package/dist/types/protocol/history.d.ts.map +1 -1
  189. package/dist/types/protocol/lifecycle.d.ts +47 -8
  190. package/dist/types/protocol/lifecycle.d.ts.map +1 -1
  191. package/dist/types/protocol/model-catalog.d.ts.map +1 -1
  192. package/dist/types/protocol/models.d.ts +3 -0
  193. package/dist/types/protocol/models.d.ts.map +1 -1
  194. package/dist/types/protocol/parts.d.ts +14 -0
  195. package/dist/types/protocol/parts.d.ts.map +1 -1
  196. package/dist/types/protocol/plan.d.ts +20 -0
  197. package/dist/types/protocol/plan.d.ts.map +1 -0
  198. package/dist/types/protocol/tool-state.d.ts +12 -0
  199. package/dist/types/protocol/tool-state.d.ts.map +1 -1
  200. package/dist/types/protocol/wire-api.d.ts +129 -23
  201. package/dist/types/protocol/wire-api.d.ts.map +1 -1
  202. package/dist/types/protocol/wire.d.ts +70 -10
  203. package/dist/types/protocol/wire.d.ts.map +1 -1
  204. package/dist/types/server/acp/binding.d.ts +6 -1
  205. package/dist/types/server/acp/binding.d.ts.map +1 -1
  206. package/dist/types/server/acp/translate.d.ts +33 -7
  207. package/dist/types/server/acp/translate.d.ts.map +1 -1
  208. package/dist/types/server/agent-server.d.ts +6 -0
  209. package/dist/types/server/agent-server.d.ts.map +1 -1
  210. package/dist/types/server/feedback.d.ts +2 -1
  211. package/dist/types/server/feedback.d.ts.map +1 -1
  212. package/dist/types/server/install.d.ts +11 -0
  213. package/dist/types/server/install.d.ts.map +1 -1
  214. package/dist/types/server/session-gate.d.ts +2 -1
  215. package/dist/types/server/session-gate.d.ts.map +1 -1
  216. package/dist/types/server/session-store.d.ts +1 -0
  217. package/dist/types/server/session-store.d.ts.map +1 -1
  218. package/dist/types/server/subscriptions.d.ts +2 -1
  219. package/dist/types/server/subscriptions.d.ts.map +1 -1
  220. package/dist/types/server/transports.d.ts.map +1 -1
  221. package/dist/types/sync/fit.d.ts +8 -7
  222. package/dist/types/sync/fit.d.ts.map +1 -1
  223. package/dist/types/sync/history-sqlite.d.ts.map +1 -1
  224. package/dist/types/sync/index.d.ts +1 -0
  225. package/dist/types/sync/index.d.ts.map +1 -1
  226. package/dist/types/sync/journal-sqlite.d.ts +2 -1
  227. package/dist/types/sync/journal-sqlite.d.ts.map +1 -1
  228. package/dist/types/sync/journal.d.ts +11 -3
  229. package/dist/types/sync/journal.d.ts.map +1 -1
  230. package/dist/types/sync/projection.d.ts +6 -0
  231. package/dist/types/sync/projection.d.ts.map +1 -1
  232. package/dist/types/sync/recovery.d.ts +2 -1
  233. package/dist/types/sync/recovery.d.ts.map +1 -1
  234. package/dist/types/sync/schema.d.ts +10 -0
  235. package/dist/types/sync/schema.d.ts.map +1 -1
  236. package/dist/types/sync/sql.d.ts +2 -1
  237. package/dist/types/sync/sql.d.ts.map +1 -1
  238. package/dist/types/sync/worker.d.ts.map +1 -1
  239. package/docs/consuming.md +464 -40
  240. package/docs/deploy.md +36 -8
  241. package/docs/durable-sessions.md +35 -5
  242. package/docs/harnesses.md +396 -30
  243. package/package.json +11 -1
  244. package/src/accounts/chatgpt.ts +2 -2
  245. package/src/accounts/http.ts +2 -16
  246. package/src/client/client.ts +92 -31
  247. package/src/client/connection.ts +113 -22
  248. package/src/client/index.ts +1 -0
  249. package/src/client/logins.ts +24 -15
  250. package/src/client/streams.ts +12 -4
  251. package/src/client/turns.ts +1 -1
  252. package/src/core/agents/acp/acp-agent.ts +181 -52
  253. package/src/core/agents/acp/adapter.ts +9 -1
  254. package/src/core/agents/acp/client.ts +16 -4
  255. package/src/core/agents/acp/mappings.ts +27 -0
  256. package/src/core/agents/base.ts +25 -10
  257. package/src/core/agents/claude-code/adapter.ts +47 -17
  258. package/src/core/agents/claude-code/approvals.ts +6 -5
  259. package/src/core/agents/claude-code/claude-agent.ts +60 -30
  260. package/src/core/agents/claude-code/events.ts +11 -1
  261. package/src/core/agents/claude-code/login.ts +14 -2
  262. package/src/core/agents/claude-code/mcp.ts +31 -15
  263. package/src/core/agents/claude-code/models.ts +7 -2
  264. package/src/core/agents/claude-code/options.ts +11 -3
  265. package/src/core/agents/claude-code/outcome.ts +10 -2
  266. package/src/core/agents/claude-code/results.ts +73 -0
  267. package/src/core/agents/claude-code/sdk-pair.ts +66 -0
  268. package/src/core/agents/claude-code/session.ts +166 -37
  269. package/src/core/agents/claude-code/spend.ts +1 -1
  270. package/src/core/agents/claude-code/tools.ts +108 -12
  271. package/src/core/agents/codex-app-server/adapter.ts +37 -12
  272. package/src/core/agents/codex-app-server/client.ts +69 -10
  273. package/src/core/agents/codex-app-server/codex-agent.ts +141 -55
  274. package/src/core/agents/codex-app-server/commands.ts +2 -2
  275. package/src/core/agents/codex-app-server/credentials.ts +10 -5
  276. package/src/core/agents/codex-app-server/effort.ts +1 -1
  277. package/src/core/agents/codex-app-server/homes.ts +59 -10
  278. package/src/core/agents/codex-app-server/items.ts +219 -31
  279. package/src/core/agents/codex-app-server/login.ts +14 -2
  280. package/src/core/agents/codex-app-server/mcp.ts +142 -26
  281. package/src/core/agents/codex-app-server/models.ts +9 -8
  282. package/src/core/agents/codex-app-server/options.ts +79 -11
  283. package/src/core/agents/codex-app-server/plan-approval.ts +1 -1
  284. package/src/core/agents/codex-app-server/protocol.ts +14 -4
  285. package/src/core/agents/codex-app-server/requests.ts +14 -6
  286. package/src/core/agents/codex-app-server/session.ts +156 -81
  287. package/src/core/agents/codex-app-server/subagents.ts +21 -14
  288. package/src/core/agents/codex-app-server/thread-settings.ts +18 -8
  289. package/src/core/agents/codex-app-server/turn-items.ts +1 -1
  290. package/src/core/agents/codex-app-server/turn.ts +96 -35
  291. package/src/core/agents/codex-app-server/user-login.ts +107 -0
  292. package/src/core/agents/credentials.ts +5 -2
  293. package/src/core/agents/diffs.ts +25 -0
  294. package/src/core/agents/elicitation.ts +2 -2
  295. package/src/core/agents/login.ts +6 -0
  296. package/src/core/agents/mcp-config.ts +2 -2
  297. package/src/core/agents/plan.ts +3 -19
  298. package/src/core/agents/process-pool.ts +432 -0
  299. package/src/core/agents/scripted/adapter.ts +142 -0
  300. package/src/core/agents/scripted/mcp-call.ts +134 -0
  301. package/src/core/agents/scripted/scripted-agent.ts +418 -0
  302. package/src/core/agents/scripted/scripts.ts +171 -0
  303. package/src/core/agents/scripted/steps.ts +127 -0
  304. package/src/core/agents/session-agent.ts +105 -8
  305. package/src/core/diagnostics.ts +9 -1
  306. package/src/core/index.ts +12 -0
  307. package/src/core/presets.ts +99 -14
  308. package/src/core/processes/lifeline.ts +99 -25
  309. package/src/core/provision/index.ts +1 -2
  310. package/src/core/provision/install-build.ts +4 -1
  311. package/src/core/provision/npm.ts +309 -97
  312. package/src/core/provision/provisioner.ts +22 -8
  313. package/src/core/provision/tools.ts +44 -19
  314. package/src/core/runtime/agent-runtime.ts +70 -34
  315. package/src/core/runtime/event-processor.ts +18 -2
  316. package/src/core/runtime/harness-clis.ts +36 -1
  317. package/src/core/runtime/harness-logins.ts +82 -31
  318. package/src/core/runtime/model-lists.ts +1 -1
  319. package/src/core/runtime/permission-policy.ts +4 -3
  320. package/src/core/runtime/request-broker.ts +1 -1
  321. package/src/core/runtime/turn.ts +53 -3
  322. package/src/core/utils/deadline.ts +23 -0
  323. package/src/core/utils/errors.ts +24 -4
  324. package/src/operator/index.ts +40 -0
  325. package/src/operator/mcp.ts +171 -0
  326. package/src/operator/operator.ts +782 -0
  327. package/src/operator/render.ts +473 -0
  328. package/src/operator/view.ts +82 -0
  329. package/src/protocol/auth.ts +30 -23
  330. package/src/protocol/clis.ts +12 -4
  331. package/src/protocol/credentials.ts +19 -0
  332. package/src/protocol/execution.ts +5 -0
  333. package/src/protocol/factories.ts +25 -3
  334. package/src/protocol/harness.ts +11 -1
  335. package/src/protocol/history.ts +20 -0
  336. package/src/protocol/lifecycle.ts +10 -1
  337. package/src/protocol/model-catalog.ts +19 -8
  338. package/src/protocol/parts.ts +12 -1
  339. package/src/protocol/plan.ts +35 -0
  340. package/src/protocol/tool-state.ts +14 -1
  341. package/src/protocol/wire.ts +14 -0
  342. package/src/server/acp/binding.ts +113 -22
  343. package/src/server/acp/translate.ts +161 -8
  344. package/src/server/agent-server.ts +10 -1
  345. package/src/server/bin.ts +83 -9
  346. package/src/server/feedback.ts +1 -1
  347. package/src/server/install.ts +82 -4
  348. package/src/server/session-gate.ts +1 -1
  349. package/src/server/session-store.ts +5 -1
  350. package/src/server/subscriptions.ts +1 -1
  351. package/src/server/transports.ts +14 -0
  352. package/src/sync/fit.ts +115 -28
  353. package/src/sync/history-sqlite.ts +6 -2
  354. package/src/sync/index.ts +1 -0
  355. package/src/sync/journal-sqlite.ts +20 -2
  356. package/src/sync/journal.ts +10 -2
  357. package/src/sync/projection.ts +10 -0
  358. package/src/sync/recovery.ts +11 -4
  359. package/src/sync/schema.ts +7 -5
  360. package/src/sync/sql.ts +1 -1
  361. package/src/sync/worker.ts +4 -0
  362. package/dist/types/core/agents/claude-code/session-pool.d.ts +0 -36
  363. package/dist/types/core/agents/claude-code/session-pool.d.ts.map +0 -1
  364. package/dist/types/core/agents/session-pool.d.ts +0 -41
  365. package/dist/types/core/agents/session-pool.d.ts.map +0 -1
  366. package/src/core/agents/claude-code/session-pool.ts +0 -136
  367. package/src/core/agents/session-pool.ts +0 -111
@@ -30,6 +30,13 @@ export function stdioTransport(
30
30
  return transport;
31
31
  }
32
32
 
33
+ /**
34
+ * How far past the server's backlog bound (`maxBacklogBytes`) a listener's
35
+ * socket may buffer before Bun closes it: room for the frame that crossed the
36
+ * bound, the `session/overflow` notice behind it, and the responses after it.
37
+ */
38
+ const SOCKET_HEADROOM_BYTES = 64 * 1024 * 1024;
39
+
33
40
  /** A WebSocket as a wire transport: its frames come in line by line, each line goes out as a frame. */
34
41
  function socketTransport(
35
42
  ws: { send(line: string): unknown; close(): void },
@@ -157,6 +164,13 @@ export function listen(
157
164
  : new Response("websocket upgrade required", { status: 426 });
158
165
  },
159
166
  websocket: {
167
+ // Above the server's own bound: the overflow notice it sends there is
168
+ // never dropped by Bun's (16 MiB by default, the bound's own default).
169
+ backpressureLimit: server.maxBacklogBytes + SOCKET_HEADROOM_BYTES,
170
+ // @ref LLP 0008#backpressure-and-overflow — a connection is told it overflowed, or closed
171
+ // Past it, a send Bun would drop closes the connection instead: the
172
+ // client redials and replays rather than wait for a lost line.
173
+ closeOnBackpressureLimit: true,
160
174
  open(ws) {
161
175
  ws.data.socket = socketTransport(ws, () => ws.getBufferedAmount());
162
176
  server.attach(ws.data.socket.transport);
package/src/sync/fit.ts CHANGED
@@ -2,6 +2,8 @@ import {
2
2
  HISTORY_MAX_BYTES,
3
3
  HistoryError,
4
4
  type LifecycleEvent,
5
+ OMITTED_BINARY_META_KEY,
6
+ type OmittedBinary,
5
7
  canonicalJson,
6
8
  decodeLifecycleEvent,
7
9
  jsonBytes,
@@ -25,39 +27,124 @@ export const REPLAY_PAGE_BYTES = HISTORY_MAX_BYTES - 64 * 1024;
25
27
  const encoder = new TextEncoder();
26
28
  const decoder = new TextDecoder();
27
29
 
30
+ /** An image or file as the protocol carries one: base64 `data` beside its `mimeType`. */
31
+ function isBinary(value: object): value is Record<string, unknown> & { data: string } {
32
+ const entry = value as Record<string, unknown>;
33
+ return (
34
+ (entry.type === "image" || entry.type === "file") &&
35
+ typeof entry.data === "string" &&
36
+ typeof entry.mimeType === "string"
37
+ );
38
+ }
39
+
40
+ /** The size of what base64 `data` encodes. */
41
+ function decodedBytes(data: string): number {
42
+ const padding = data.endsWith("==") ? 2 : data.endsWith("=") ? 1 : 0;
43
+ return Math.max(0, Math.floor((data.length * 3) / 4) - padding);
44
+ }
45
+
46
+ /** The part fields that address a part, which its stand-in keeps. */
47
+ const ADDRESS = ["id", "sessionId", "messageId", "parentToolCallId"] as const;
48
+
28
49
  /**
29
- * `event` cut down to `maxBytes`: its longest strings (usually a tool's output)
30
- * are truncated with a visible marker until it fits. `undefined` when only
31
- * short strings remain. An event that already fits is returned as is.
50
+ * What a store keeps in place of `binary`: text saying what it was, in words
51
+ * and under `OMITTED_BINARY_META_KEY`. A part stays at its address as a text
52
+ * part; a tool result's entry becomes a text entry.
32
53
  */
33
- export function fitEvent<T>(event: T, maxBytes = MAX_EVENT_BYTES): T | undefined {
34
- let size = jsonBytes(event);
35
- if (size <= maxBytes) return event;
36
- const copy = structuredClone(event);
37
- for (let attempt = 0; attempt < 8 && size > maxBytes; attempt++) {
38
- let longest: { holder: Record<string, unknown>; key: string; bytes: number } | undefined;
39
- const visit = (value: unknown) => {
40
- if (!value || typeof value !== "object") return;
41
- for (const [key, child] of Object.entries(value)) {
42
- if (typeof child !== "string") visit(child);
43
- else {
44
- const bytes = encoder.encode(child).byteLength;
45
- if (!longest || bytes > longest.bytes)
46
- longest = { holder: value as Record<string, unknown>, key, bytes };
47
- }
54
+ function omittedBinary(
55
+ binary: Record<string, unknown> & { data: string },
56
+ where: string,
57
+ ): Record<string, unknown> {
58
+ const facts: OmittedBinary = {
59
+ type: binary.type as OmittedBinary["type"],
60
+ mimeType: binary.mimeType as string,
61
+ bytes: decodedBytes(binary.data),
62
+ ...(typeof binary.filename === "string" && { filename: binary.filename }),
63
+ };
64
+ const meta =
65
+ binary._meta && typeof binary._meta === "object" && !Array.isArray(binary._meta)
66
+ ? binary._meta
67
+ : {};
68
+ const named = facts.filename === undefined ? "" : ` ${facts.filename}`;
69
+ return {
70
+ type: "text",
71
+ ...Object.fromEntries(
72
+ ADDRESS.filter((key) => typeof binary[key] === "string").map((key) => [key, binary[key]]),
73
+ ),
74
+ text: `[agent-server: ${facts.mimeType} ${facts.type}${named} of ${facts.bytes} bytes omitted to fit ${where}]`,
75
+ _meta: { ...meta, [OMITTED_BINARY_META_KEY]: facts },
76
+ };
77
+ }
78
+
79
+ // @ref LLP 0002#tool-output-has-three-audiences — a cut binary is no display at all: kept whole or replaced
80
+ /**
81
+ * `value` brought down to `maxBytes` by its longest strings, one at a time: a
82
+ * binary's `data` (an image or file, `isBinary`) is never cut, its whole entry
83
+ * is replaced by a text one saying what it was (`omittedBinary`); any other
84
+ * string is cut with a visible marker, when `cutText`. It stops when only
85
+ * short strings remain, so what it returns may still not fit. A value that
86
+ * already fits is returned as is.
87
+ */
88
+ function shrink<T>(value: T, maxBytes: number, where: string, cutText: boolean): T {
89
+ let size = jsonBytes(value);
90
+ if (size <= maxBytes) return value;
91
+ const copy = structuredClone(value);
92
+ // Each replacement removes a binary; cuts are bounded as they always were.
93
+ let cuts = 0;
94
+ while (size > maxBytes) {
95
+ let longest:
96
+ | { holder: Record<string, unknown>; key: string; bytes: number; binary: boolean }
97
+ | undefined;
98
+ const consider = (holder: object, key: string, bytes: number, binary: boolean) => {
99
+ if (!longest || bytes > longest.bytes)
100
+ longest = { holder: holder as Record<string, unknown>, key, bytes, binary };
101
+ };
102
+ const visit = (node: object) => {
103
+ for (const [key, child] of Object.entries(node)) {
104
+ if (child && typeof child === "object") {
105
+ // Base64 is ASCII: its length is its size.
106
+ if (isBinary(child)) consider(node, key, child.data.length, true);
107
+ else visit(child);
108
+ } else if (cutText && typeof child === "string")
109
+ consider(node, key, encoder.encode(child).byteLength, false);
48
110
  }
49
111
  };
50
- visit(copy);
51
- if (!longest || longest.bytes < 1024) return undefined;
52
- const keep = Math.max(0, longest.bytes - (size - maxBytes) - 256);
53
- const head = decoder
54
- .decode(encoder.encode(longest.holder[longest.key] as string).slice(0, keep))
55
- .replace(/�$/, "");
56
- longest.holder[longest.key] =
57
- `${head}\n[agent-server: ${longest.bytes - keep} bytes omitted to fit the journal]`;
112
+ if (copy && typeof copy === "object") visit(copy);
113
+ if (!longest || longest.bytes < 1024) break;
114
+ const { holder, key, bytes } = longest;
115
+ if (longest.binary)
116
+ holder[key] = omittedBinary(holder[key] as Record<string, unknown> & { data: string }, where);
117
+ else {
118
+ if (++cuts > 8) break;
119
+ const keep = Math.max(0, bytes - (size - maxBytes) - 256);
120
+ const head = decoder
121
+ .decode(encoder.encode(holder[key] as string).slice(0, keep))
122
+ .replace(/�$/, "");
123
+ holder[key] = `${head}\n[agent-server: ${bytes - keep} bytes omitted to fit ${where}]`;
124
+ }
58
125
  size = jsonBytes(copy);
59
126
  }
60
- return size <= maxBytes ? copy : undefined;
127
+ return copy;
128
+ }
129
+
130
+ /**
131
+ * `event` cut down to `maxBytes`: its longest strings (usually a tool's
132
+ * output) are truncated with a visible marker until it fits, and an image or
133
+ * file it cannot keep whole is replaced by text saying what it was. `undefined`
134
+ * when only short strings remain. An event that already fits is returned as is.
135
+ */
136
+ export function fitEvent<T>(event: T, maxBytes = MAX_EVENT_BYTES): T | undefined {
137
+ const fitted = shrink(event, maxBytes, "the journal", true);
138
+ return jsonBytes(fitted) <= maxBytes ? fitted : undefined;
139
+ }
140
+
141
+ /**
142
+ * `value` with its largest images and files replaced by text saying what they
143
+ * were (as `fitEvent` replaces them) until it fits `maxBytes`, or until none
144
+ * is left. Nothing else is changed. A value that already fits is returned as is.
145
+ */
146
+ export function omitBinaries<T>(value: T, maxBytes: number, where: string): T {
147
+ return shrink(value, maxBytes, where, false);
61
148
  }
62
149
 
63
150
  /**
@@ -65,7 +152,7 @@ export function fitEvent<T>(event: T, maxBytes = MAX_EVENT_BYTES): T | undefined
65
152
  * every other session keep going. A turn or session end keeps its meaning;
66
153
  * anything else becomes a recoverable error notice naming what was lost.
67
154
  */
68
- export function unrecordedEvent(event: LifecycleEvent, reason: string): LifecycleEvent {
155
+ function unrecordedEvent(event: LifecycleEvent, reason: string): LifecycleEvent {
69
156
  const message = `agent-server could not record a ${event.type} event: ${reason.slice(0, 300)}`;
70
157
  const timestamp = Date.now();
71
158
  if (event.type === "turn.ended")
@@ -35,7 +35,7 @@ import {
35
35
  } from "../protocol/index.ts";
36
36
  import { type EventLog, type EventRow, sha256 } from "./event-log.ts";
37
37
  import { MAX_EVENT_BYTES, PAGE_SLACK_BYTES } from "./fit.ts";
38
- import { checkCheckpointBytes, projectionFold } from "./projection.ts";
38
+ import { checkCheckpointBytes, fitCheckpoint, projectionFold } from "./projection.ts";
39
39
  import type { Db } from "./sql.ts";
40
40
 
41
41
  const conflict = (message: string) => new HistoryError("historyConflict", message);
@@ -322,7 +322,11 @@ export class SqliteHistory implements HistoryStore {
322
322
  : emptyConversation();
323
323
  for (const row of this.log.records(ref, prior?.version.seq ?? 0, target.seq))
324
324
  conversation = fold(conversation, JSON.parse(row.body));
325
- const checkpoint = { version: target, format: CONVERSATION_CHECKPOINT_FORMAT, conversation };
325
+ const checkpoint = fitCheckpoint({
326
+ version: target,
327
+ format: CONVERSATION_CHECKPOINT_FORMAT,
328
+ conversation,
329
+ });
326
330
  checkCheckpointBytes(checkpoint);
327
331
  this.db.atomic(() =>
328
332
  this.db.run(
package/src/sync/index.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  // Storage/transport-neutral host contracts. SQLite is an optional subpath.
2
2
  export { JournalError, type SessionJournal } from "./journal.ts";
3
+ export { JOURNAL_SCHEMA_VERSION } from "./schema.ts";
3
4
  export {
4
5
  type FollowHistoryOptions,
5
6
  type HistoryTransfer,
@@ -2,6 +2,7 @@ import {
2
2
  type AgentHarness,
3
3
  type DurableSession,
4
4
  HISTORY_MAX_RECORDS,
5
+ type LastTurn,
5
6
  type LifecycleEvent,
6
7
  type MessagePartDeltaEvent,
7
8
  type RecoveryReason,
@@ -116,6 +117,18 @@ export class SqliteJournal implements SessionJournal {
116
117
  }
117
118
  );
118
119
  }
120
+ lastTurn(sessionId: string): LastTurn | undefined {
121
+ // An admitted turn has no terminal yet: it sorts first, then the latest ended.
122
+ const row = this.db.one<{ turn_id: string; terminal: string | null }>(
123
+ "SELECT t.turn_id, e.body AS terminal FROM turns t LEFT JOIN events e ON e.source_id=? AND e.session_id=t.session_id AND e.seq=t.terminal_seq WHERE t.session_id=? ORDER BY t.state='admitted' DESC, t.terminal_seq DESC LIMIT 1",
124
+ this.sourceId,
125
+ sessionId,
126
+ );
127
+ if (!row) return undefined;
128
+ if (row.terminal === null) return { turnId: row.turn_id };
129
+ const { stopReason, error } = JSON.parse(row.terminal) as TurnEndedEvent;
130
+ return { turnId: row.turn_id, stopReason, ...(error && { error }) };
131
+ }
119
132
  turn(sessionId: string, turnId: string): TurnReceipt | undefined {
120
133
  const row = this.db.one<{
121
134
  state: TurnReceipt["state"];
@@ -160,8 +173,13 @@ export class SqliteJournal implements SessionJournal {
160
173
  "History branch is not a native execution session; prepare provider context explicitly",
161
174
  );
162
175
  const input = canonical(request.input);
163
- if (Buffer.byteLength(input) > MAX_EVENT_BYTES)
164
- throw new JournalError("invalidParams", "Input exceeds durable record limit");
176
+ const bytes = Buffer.byteLength(input);
177
+ if (bytes > MAX_EVENT_BYTES)
178
+ // `invalidParams` carries no data on the wire (`WIRE_REFUSAL_DATA`): the words say it.
179
+ throw new JournalError(
180
+ "invalidParams",
181
+ `Input is ${bytes} bytes; the durable record limit is ${MAX_EVENT_BYTES} bytes`,
182
+ );
165
183
  return this.db.atomic(() => {
166
184
  if (this.admission(request) === "duplicate") return "duplicate";
167
185
  const state = this.session(sessionId);
@@ -1,6 +1,7 @@
1
1
  import {
2
2
  type AgentHarness,
3
3
  type DurableSession,
4
+ type LastTurn,
4
5
  type LifecycleEvent,
5
6
  type MessagePartDeltaEvent,
6
7
  type RunRequest,
@@ -19,7 +20,7 @@ import {
19
20
  export class JournalError extends WireRefusal<JournalRefusal, Record<string, unknown>> {
20
21
  override readonly name = "JournalError";
21
22
  }
22
- export type JournalRefusal = Extract<
23
+ type JournalRefusal = Extract<
23
24
  WireErrorName,
24
25
  | "turnConflict"
25
26
  | "turnActive"
@@ -84,7 +85,13 @@ export interface SessionJournal {
84
85
  * `not_verified`. Either way until `confirmStopped`. Returns the release.
85
86
  */
86
87
  claim(options?: ClaimOptions): () => void;
88
+ /** What it knows of the session, less `lastTurn`: every admission and append reads it. */
87
89
  session(sessionId: string): DurableSession | undefined;
90
+ /**
91
+ * The session's admitted turn, or else the ended one whose `turn.ended` is
92
+ * latest, for `session/get`. Undefined before its first turn.
93
+ */
94
+ lastTurn(sessionId: string): LastTurn | undefined;
88
95
  turn(sessionId: string, turnId: string): TurnReceipt | undefined;
89
96
  /** Whether this journal already admitted the turn. Throws `turnConflict` for other input. */
90
97
  admission(request: RunRequest): "new" | "duplicate";
@@ -96,7 +103,8 @@ export interface SessionJournal {
96
103
  */
97
104
  admit(request: RunRequest): "new" | "duplicate";
98
105
  /** Commits `event`, or, when its content cannot be stored, a copy cut down to
99
- * fit or a notice in its place. Deliver what it returns. Throws only when
106
+ * fit (a binary that does not fit is replaced whole by a marker, never cut)
107
+ * or a notice in its place. Deliver what it returns. Throws only when
100
108
  * storage itself fails. */
101
109
  append(event: LifecycleEvent): WireEventEnvelope;
102
110
  /**
@@ -7,6 +7,7 @@ import {
7
7
  jsonBytes,
8
8
  reduceConversation,
9
9
  } from "../protocol/index.ts";
10
+ import { omitBinaries } from "./fit.ts";
10
11
 
11
12
  /** The most events a projection folds unless its caller says otherwise: it is built in memory. */
12
13
  const MAX_PROJECTION_RECORDS = 100_000;
@@ -28,6 +29,15 @@ export function projectionFold(
28
29
  };
29
30
  }
30
31
 
32
+ /**
33
+ * `checkpoint` with its largest images and files replaced by text saying what
34
+ * they were until it fits a history page (`omitBinaries`): binaries alone never
35
+ * make a checkpoint too large to keep. The events keep what they kept.
36
+ */
37
+ export function fitCheckpoint(checkpoint: HistoryCheckpoint): HistoryCheckpoint {
38
+ return omitBinaries(checkpoint, HISTORY_MAX_BYTES, "this checkpoint");
39
+ }
40
+
31
41
  /** A checkpoint fits a history page, as all history does: no store keeps, and no reader takes, a larger one. */
32
42
  export function checkCheckpointBytes(checkpoint: HistoryCheckpoint): void {
33
43
  if (jsonBytes(checkpoint) > HISTORY_MAX_BYTES)
@@ -12,7 +12,7 @@ import {
12
12
  import type { SessionEvent } from "./fit.ts";
13
13
 
14
14
  /** A turn a server restart cut off, as the journal holds it. */
15
- export interface CutOffTurn {
15
+ interface CutOffTurn {
16
16
  sessionId: string;
17
17
  turnId: string;
18
18
  /** The session's harness, which a turn cut off before its first event never named. */
@@ -76,6 +76,8 @@ export function recoveryFacts(history: Iterable<unknown>, turn: CutOffTurn): Ses
76
76
  outcome: { action: "cancel" },
77
77
  timestamp: at,
78
78
  });
79
+ // Whether a tool that may have run was open at the cut: only then is its outcome unknown.
80
+ let toolRan = false;
79
81
  for (const entry of state.timeline) {
80
82
  if (entry.kind !== "message" || entry.turnId !== turnId) continue;
81
83
  // A tool keeps running after the model message that called it ends, and
@@ -84,6 +86,8 @@ export function recoveryFacts(history: Iterable<unknown>, turn: CutOffTurn): Ses
84
86
  if ("raw" in part) continue;
85
87
  const where = address.get(part.id);
86
88
  const closed = where && closePart(state, turnId, part, at, turn.tails.get(part.id));
89
+ if (closed?.type === "tool" && closed.state.status === "failed")
90
+ toolRan ||= closed.state.closure === "interrupted";
87
91
  if (where && closed)
88
92
  facts.push({
89
93
  type: "message.part",
@@ -103,6 +107,11 @@ export function recoveryFacts(history: Iterable<unknown>, turn: CutOffTurn): Ses
103
107
  timestamp: at,
104
108
  });
105
109
  }
110
+ // @ref LLP 0003#commit-before-acknowledging — what the restart found, never what to do:
111
+ // the history outlives a fence, which `recoveryRequired` alone says is still up.
112
+ const agent = turn.fence
113
+ ? `Its agent could not be confirmed stopped at restart (${turn.fence})`
114
+ : "Its agent was stopped at restart";
106
115
  facts.push({
107
116
  type: "turn.ended",
108
117
  sessionId,
@@ -110,9 +119,7 @@ export function recoveryFacts(history: Iterable<unknown>, turn: CutOffTurn): Ses
110
119
  stopReason: "error",
111
120
  error: {
112
121
  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.",
122
+ message: `Server restarted before the turn settled. ${agent}${toolRan ? "; what its running tool did is unknown" : ""}.`,
116
123
  },
117
124
  timestamp: at,
118
125
  });
@@ -6,8 +6,10 @@ import type { Db } from "./sql.ts";
6
6
  * tail is the whole part; version 5 keeps the native processes its owners
7
7
  * started, and why a fence could not be lifted; version 4 keeps each
8
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;
9
+ * deltas (wire v3); version 2 journals kept them at their own seq. Exported
10
+ * from `./sync`, which loads no SQLite driver: a product that starts a new
11
+ * journal file per schema names the file from it. */
12
+ export const JOURNAL_SCHEMA_VERSION = 6;
11
13
 
12
14
  const DDL = `
13
15
  CREATE TABLE identity (id TEXT PRIMARY KEY);
@@ -57,15 +59,15 @@ CREATE TABLE checkpoints (
57
59
  source_id TEXT NOT NULL, session_id TEXT NOT NULL, format TEXT NOT NULL,
58
60
  seq INTEGER NOT NULL, body TEXT NOT NULL,
59
61
  PRIMARY KEY (source_id, session_id, format));
60
- PRAGMA user_version = ${SCHEMA_VERSION};
62
+ PRAGMA user_version = ${JOURNAL_SCHEMA_VERSION};
61
63
  `;
62
64
 
63
65
  /** Create or check the schema; returns the store's identity, minting it once. */
64
66
  export function openSchema(db: Db, newId: () => string): string {
65
67
  const { user_version: version } = db.one<{ user_version: number }>("PRAGMA user_version")!;
66
- if (version !== 0 && version !== SCHEMA_VERSION)
68
+ if (version !== 0 && version !== JOURNAL_SCHEMA_VERSION)
67
69
  throw new Error(
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`,
70
+ `Unsupported journal schema ${version}; this build reads schema ${JOURNAL_SCHEMA_VERSION}. Open it with the agent-server that wrote it, or start a new journal file`,
69
71
  );
70
72
  return db.atomic(() => {
71
73
  if (version === 0) {
package/src/sync/sql.ts CHANGED
@@ -1,4 +1,4 @@
1
- export type SqlValue = string | number | null;
1
+ type SqlValue = string | number | null;
2
2
 
3
3
  /** The shared implementation uses only positional scalar bindings. */
4
4
  export interface SqlStatement {
@@ -139,6 +139,10 @@ class HistorySync {
139
139
  : (await this.source.head(this.ref)).version;
140
140
  if (acknowledged && sameVersion(local, acknowledged)) {
141
141
  budget.progressed();
142
+ // The destination holds the source's head: synced, also after a
143
+ // failed wait, whose error no longer describes anything.
144
+ if (this.current.state !== "synced")
145
+ this.set({ state: "synced", localVersion: local, failures: 0, error: undefined });
142
146
  await idleAfter(waited, signal);
143
147
  continue;
144
148
  }
@@ -1,36 +0,0 @@
1
- import type { McpSetServersResult } from "@anthropic-ai/claude-agent-sdk";
2
- import type { McpServerConfig } from "../../../protocol/index.ts";
3
- import { type ClaudeCodeAgentOptions, type ClaudeSessionConfig, type ClaudeSessionSettings } from "./options.ts";
4
- import { ClaudeSession } from "./session.ts";
5
- /** The selected session and whether this invocation owns its new startup. */
6
- export interface ClaudeSessionSpawn {
7
- session: ClaudeSession;
8
- spawned: boolean;
9
- }
10
- /**
11
- * One live `ClaudeSession` per logical session id. Decides, per turn, whether
12
- * the existing session can be reused (hot-swapping model, mode and MCP) or
13
- * must be replaced by a new process that resumes the conversation.
14
- */
15
- export declare class ClaudeSessionPool {
16
- private readonly settings;
17
- private readonly sessions;
18
- /** Started before the login last changed: the next turn replaces the process. */
19
- private readonly priorLogin;
20
- constructor(settings: ClaudeSessionSettings & Pick<ClaudeCodeAgentOptions, "onSessionEnd">);
21
- getOrCreate(sessionId: string, config: ClaudeSessionConfig): Promise<ClaudeSessionSpawn>;
22
- get(sessionId: string): ClaudeSession | undefined;
23
- terminate(sessionId: string): Promise<void>;
24
- terminateAll(): Promise<void>;
25
- invalidateMcpConnections(): void;
26
- /** A running CLI keeps the credentials it started with: each session's next turn starts a new one. */
27
- loginChanged(): void;
28
- /**
29
- * Explicit live MCP swap (e.g. mid-conversation app registration). NOTE:
30
- * this syncs the session's servers, so the NEXT turn's wire config (if it
31
- * still carries the old server set) will swap back — explicit swappers
32
- * must keep their per-turn `mcpServers` in step.
33
- */
34
- setMcpServers(sessionId: string, servers: Record<string, McpServerConfig>): Promise<McpSetServersResult | undefined>;
35
- }
36
- //# sourceMappingURL=session-pool.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"session-pool.d.ts","sourceRoot":"","sources":["../../../../../src/core/agents/claude-code/session-pool.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,gCAAgC,CAAC;AAC1E,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAClE,OAAO,EACN,KAAK,sBAAsB,EAC3B,KAAK,mBAAmB,EACxB,KAAK,qBAAqB,EAE1B,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAE7C,6EAA6E;AAC7E,MAAM,WAAW,kBAAkB;IAClC,OAAO,EAAE,aAAa,CAAC;IACvB,OAAO,EAAE,OAAO,CAAC;CACjB;AA6BD;;;;GAIG;AACH,qBAAa,iBAAiB;IAM5B,OAAO,CAAC,QAAQ,CAAC,QAAQ;IAL1B,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAoC;IAC7D,iFAAiF;IACjF,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAgC;gBAGzC,QAAQ,EAAE,qBAAqB,GAAG,IAAI,CAAC,sBAAsB,EAAE,cAAc,CAAC;IAG1F,WAAW,CAAC,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,mBAAmB,GAAG,OAAO,CAAC,kBAAkB,CAAC;IAuC9F,GAAG,CAAC,SAAS,EAAE,MAAM,GAAG,aAAa,GAAG,SAAS;IAI3C,SAAS,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAO3C,YAAY,IAAI,OAAO,CAAC,IAAI,CAAC;IAKnC,wBAAwB,IAAI,IAAI;IAIhC,sGAAsG;IACtG,YAAY,IAAI,IAAI;IAIpB;;;;;OAKG;IACG,aAAa,CAClB,SAAS,EAAE,MAAM,EACjB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC,GACtC,OAAO,CAAC,mBAAmB,GAAG,SAAS,CAAC;CAK3C"}
@@ -1,41 +0,0 @@
1
- /**
2
- * Idle time before an unused session's subprocess is shut down, unless its
3
- * harness's `idleTimeoutMs` says otherwise.
4
- */
5
- export declare const IDLE_TIMEOUT_MS: number;
6
- /** The slice of a session a SessionPool manages: a closable client + idle timer. */
7
- export interface PooledSession {
8
- client: {
9
- closed: boolean;
10
- close(): void;
11
- };
12
- idleTimer?: ReturnType<typeof setTimeout>;
13
- }
14
- /**
15
- * Per-logical-session bookkeeping shared by subprocess-backed harnesses
16
- * (codex-app-server, acp): the sessionId → session map, idle-eviction timers,
17
- * self-healing when a client dies underneath us, and whole-pool teardown.
18
- * Harnesses own what a session *is*; this owns when one goes away.
19
- */
20
- export declare class SessionPool<S extends PooledSession> {
21
- private readonly sessions;
22
- private readonly pending;
23
- private closed;
24
- /** Own a client before its initialization RPCs have completed. */
25
- trackPending(sessionId: string, client: S["client"]): () => void;
26
- get(sessionId: string): S | undefined;
27
- set(sessionId: string, session: S): void;
28
- values(): IterableIterator<S>;
29
- /** Native clients include both retained sessions and unfinished initialization. */
30
- clients(): IterableIterator<S["client"]>;
31
- /** Self-heal: drop the mapping when this exact client closed underneath us. */
32
- dropIfCurrent(sessionId: string, client: S["client"]): void;
33
- /** Tear down one session: cancel its idle timer, unmap it, close its client. */
34
- close(sessionId: string): void;
35
- /** Tear down ready and initializing clients; refuse subsequent registrations. */
36
- closeAll(): void;
37
- /** Shut the session down after `idleMs` unless another turn claims it first. */
38
- armIdle(sessionId: string, session: S, idleMs: number): void;
39
- clearIdle(session: S): void;
40
- }
41
- //# sourceMappingURL=session-pool.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"session-pool.d.ts","sourceRoot":"","sources":["../../../../src/core/agents/session-pool.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,eAAO,MAAM,eAAe,QAAa,CAAC;AAE1C,oFAAoF;AACpF,MAAM,WAAW,aAAa;IAC7B,MAAM,EAAE;QAAE,MAAM,EAAE,OAAO,CAAC;QAAC,KAAK,IAAI,IAAI,CAAA;KAAE,CAAC;IAC3C,SAAS,CAAC,EAAE,UAAU,CAAC,OAAO,UAAU,CAAC,CAAC;CAC1C;AAED;;;;;GAKG;AACH,qBAAa,WAAW,CAAC,CAAC,SAAS,aAAa;IAC/C,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAwB;IACjD,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAuC;IAC/D,OAAO,CAAC,MAAM,CAAS;IAEvB,kEAAkE;IAClE,YAAY,CAAC,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC,QAAQ,CAAC,GAAG,MAAM,IAAI;IAmBhE,GAAG,CAAC,SAAS,EAAE,MAAM,GAAG,CAAC,GAAG,SAAS;IAIrC,GAAG,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,GAAG,IAAI;IAQxC,MAAM,IAAI,gBAAgB,CAAC,CAAC,CAAC;IAI7B,mFAAmF;IAClF,OAAO,IAAI,gBAAgB,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC;IAKzC,+EAA+E;IAC/E,aAAa,CAAC,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC,QAAQ,CAAC,GAAG,IAAI;IAQ3D,gFAAgF;IAChF,KAAK,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI;IAU9B,iFAAiF;IACjF,QAAQ,IAAI,IAAI;IAOhB,gFAAgF;IAChF,OAAO,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,EAAE,MAAM,EAAE,MAAM,GAAG,IAAI;IAU5D,SAAS,CAAC,OAAO,EAAE,CAAC,GAAG,IAAI;CAM3B"}