@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
@@ -1,7 +1,7 @@
1
1
  import { type ThinkingLevel, clampThinkingLevel } from "../../../protocol/index.ts";
2
2
 
3
3
  /** Codex reasoning-effort string for a level (matches the `ReasoningEffort` enum). */
4
- export type CodexReasoningEffort =
4
+ type CodexReasoningEffort =
5
5
  | "none"
6
6
  | "minimal"
7
7
  | "low"
@@ -1,4 +1,4 @@
1
- import { existsSync, realpathSync } from "node:fs";
1
+ import { closeSync, existsSync, openSync, realpathSync, statSync } from "node:fs";
2
2
  import { homedir } from "node:os";
3
3
  import { isAbsolute, resolve } from "node:path";
4
4
  import { InvalidRequestError } from "../../utils/errors.ts";
@@ -8,10 +8,12 @@ import type { InheritConfig } from "../inherit-config.ts";
8
8
  /**
9
9
  * Which logical session owns each `CODEX_HOME` its turns name. A turn that
10
10
  * names one claims it for its session, which keeps it until it is released,
11
- * through process eviction and failed preparation: one session to a home. A
12
- * turn with MCP servers must name one, since the engine writes them there,
13
- * and below `inheritConfig: "all"` every turn must: the user's own home holds
14
- * the user's configuration. That home is never claimed, nor written to.
11
+ * through process eviction and failed preparation: one session to a home,
12
+ * since the engine writes the turn's MCP servers there. Below
13
+ * `inheritConfig: "all"` every turn must name one: the user's own home holds
14
+ * the user's configuration. At `all` a turn that names none runs in the
15
+ * process's, the user's own, which is never claimed, nor written to: its
16
+ * MCP servers go in its thread's config instead (`mcp.ts`).
15
17
  */
16
18
  export class CodexHomes {
17
19
  private readonly owners = new Map<string, string>();
@@ -19,7 +21,7 @@ export class CodexHomes {
19
21
  constructor(private readonly level: InheritConfig = "all") {}
20
22
 
21
23
  /** Whether the turn runs in a home of its session's own, which it claims. */
22
- claim(options: AgentExecuteOptions, hasServers: boolean): boolean {
24
+ claim(options: AgentExecuteOptions): boolean {
23
25
  const home = options.env?.CODEX_HOME;
24
26
  // @ref LLP 0001#d17--a-turn-inherits-what-the-operator-chooses-all-the-projects-or-none — every turn's home, below `all`
25
27
  const needs =
@@ -28,22 +30,27 @@ export class CodexHomes {
28
30
  const refused = (message: string) =>
29
31
  new InvalidRequestError([{ path: "env.CODEX_HOME", message }]);
30
32
  if (!home) {
31
- if (this.level === "all" && !hasServers) return false;
33
+ if (this.level === "all") return false;
32
34
  throw refused(
33
35
  `${needs} requires a session-specific one (an existing absolute folder no other session uses)`,
34
36
  );
35
37
  }
36
38
  if (!isAbsolute(home)) throw refused("must be an absolute path");
37
39
  const shared = resolve(process.env.CODEX_HOME ?? `${homedir()}/.codex`);
38
- if (resolve(home) === shared) throw refused(`${needs} cannot use the user's shared one`);
40
+ // A home a turn names is written to. At `all` a turn runs in the user's
41
+ // by naming none.
42
+ const isShared = () =>
43
+ refused(
44
+ `${needs} cannot use the user's shared one${this.level === "all" ? " as a session's home; leave it out to run there" : ""}`,
45
+ );
46
+ if (resolve(home) === shared) throw isShared();
39
47
  let path: string;
40
48
  try {
41
49
  path = realpathSync(home);
42
50
  } catch {
43
51
  throw refused(`${home} must be an existing folder`);
44
52
  }
45
- if (existsSync(shared) && path === realpathSync(shared))
46
- throw refused(`${needs} cannot use the user's shared one`);
53
+ if (existsSync(shared) && path === realpathSync(shared)) throw isShared();
47
54
  const owner = this.owners.get(path);
48
55
  if (owner && owner !== options.sessionId) {
49
56
  throw refused(
@@ -62,3 +69,45 @@ export class CodexHomes {
62
69
  this.owners.clear();
63
70
  }
64
71
  }
72
+
73
+ /**
74
+ * Which folder a `CODEX_HOME` is now (its device and inode), `"gone"` when
75
+ * there is none; nothing when the turn names no home. A process keeps the
76
+ * files it opened in the home it started in, so a home removed or replaced
77
+ * under it is another home: the conversation it writes is in deleted files,
78
+ * and the `config.toml` it reads is not the one there. The comparison holds
79
+ * only while the session holds its home open (`holdHome`): on ext4 a removed
80
+ * folder's inode number goes to the next folder made, at once, unless a
81
+ * handle on the old one is open (measured under Node 22 and Bun 1.3.14), so
82
+ * `rm -rf home; mkdir home` would otherwise read as the same folder.
83
+ */
84
+ export function homeIdentity(home: string | undefined): string | undefined {
85
+ if (!home) return undefined;
86
+ try {
87
+ const { dev, ino } = statSync(home);
88
+ return `${dev}:${ino}`;
89
+ } catch {
90
+ return "gone";
91
+ }
92
+ }
93
+
94
+ /**
95
+ * Hold the folder a `CODEX_HOME` is now open, keeping its inode number its
96
+ * own (`homeIdentity`), until the answer is called; calling it again does
97
+ * nothing. A turn that names no home, or a home that cannot be opened (no
98
+ * folder, a platform that does not open directories), holds nothing.
99
+ */
100
+ export function holdHome(home: string | undefined): () => void {
101
+ if (!home) return () => {};
102
+ let fd: number | undefined;
103
+ try {
104
+ fd = openSync(home, "r");
105
+ } catch {
106
+ return () => {};
107
+ }
108
+ return () => {
109
+ if (fd === undefined) return;
110
+ closeSync(fd);
111
+ fd = undefined;
112
+ };
113
+ }
@@ -1,4 +1,11 @@
1
- import type { ToolKind, ToolLocation, ToolMeta } from "../../../protocol/index.ts";
1
+ import type {
2
+ ToolKind,
3
+ ToolLocation,
4
+ ToolMeta,
5
+ ToolResultContent,
6
+ } from "../../../protocol/index.ts";
7
+ import { isRecord } from "../../utils/is-record.ts";
8
+ import { hunkDiff } from "../diffs.ts";
2
9
  import type { CodexFileChange, CodexItem } from "./protocol.ts";
3
10
 
4
11
  /** Codex tools are already normalized names; kinds are fixed per item type. */
@@ -7,6 +14,7 @@ export const CODEX_TOOL_KINDS = {
7
14
  apply_patch: "edit",
8
15
  web_search: "fetch",
9
16
  mcp: "other",
17
+ image_generation: "other",
10
18
  /** The plan Codex proposes in Plan mode, put to the user like Claude's ExitPlanMode. */
11
19
  plan: "switch_mode",
12
20
  } as const satisfies Record<string, ToolKind>;
@@ -19,8 +27,15 @@ export const CODEX_TOOL_KINDS = {
19
27
  export interface CodexToolDescriptor {
20
28
  toolName(item: CodexItem): string;
21
29
  input(item: CodexItem): Record<string, unknown>;
30
+ /** Codex says this tool's input only once it is done: its completed item sets it again. */
31
+ inputAtCompletion?: true;
22
32
  meta(item: CodexItem): ToolMeta;
23
- result(item: CodexItem): { output: string; isError: boolean };
33
+ result(item: CodexItem): {
34
+ output: string;
35
+ isError: boolean;
36
+ content?: ToolResultContent[];
37
+ metadata?: Record<string, unknown>;
38
+ };
24
39
  }
25
40
 
26
41
  function pickCodexError(err: CodexItem["error"]): string {
@@ -28,24 +43,53 @@ function pickCodexError(err: CodexItem["error"]): string {
28
43
  return typeof err === "string" ? err : (err.message ?? "");
29
44
  }
30
45
 
31
- /** Join `{text}` blocks of an MCP content array; JSON-stringify anything else. */
32
- function stringifyMcpResult(result: unknown): string {
33
- const content =
34
- result && typeof result === "object" && "content" in result
35
- ? (result as { content?: unknown }).content
36
- : result;
37
- if (content == null) return "";
38
- if (typeof content === "string") return content;
39
- if (Array.isArray(content)) {
40
- return content
41
- .map((b) =>
42
- b && typeof b === "object" && "text" in b
43
- ? String((b as { text: unknown }).text)
44
- : JSON.stringify(b),
45
- )
46
- .join("");
46
+ /** Base64 a block carries (an image's or audio's `data`, an embedded resource's `blob`). */
47
+ function carriesBytes(block: Record<string, unknown>): boolean {
48
+ const resource = isRecord(block.resource) ? block.resource : {};
49
+ return typeof block.data === "string" || typeof resource.blob === "string";
50
+ }
51
+
52
+ /** A block's MIME type, its own or its embedded resource's. */
53
+ function blockMimeType(block: Record<string, unknown>): string | undefined {
54
+ const resource = isRecord(block.resource) ? block.resource : {};
55
+ const mimeType = block.mimeType ?? resource.mimeType;
56
+ return typeof mimeType === "string" ? mimeType : undefined;
57
+ }
58
+
59
+ /**
60
+ * One MCP content block, as the stream shows it: what `output` says of it,
61
+ * and its `content` entry. Text is text and an image an image; another
62
+ * block is the text `output` has for it. No block's bytes are ever text: a
63
+ * placeholder naming its type (and MIME type) stands for them.
64
+ */
65
+ function mcpBlock(block: unknown): { shown: string; entry: ToolResultContent } {
66
+ if (isRecord(block) && block.type === "text" && typeof block.text === "string")
67
+ return { shown: block.text, entry: { type: "text", text: block.text } };
68
+ let shown = JSON.stringify(block);
69
+ if (isRecord(block) && carriesBytes(block)) {
70
+ const mimeType = blockMimeType(block);
71
+ shown = `[${String(block.type ?? "binary")}${mimeType ? ` ${mimeType}` : ""}]`;
72
+ if (block.type === "image" && typeof block.data === "string" && mimeType)
73
+ return { shown, entry: { type: "image", data: block.data, mimeType } };
47
74
  }
48
- return JSON.stringify(content);
75
+ return { shown, entry: { type: "text", text: shown } };
76
+ }
77
+
78
+ // @ref LLP 0002#tool-output-has-three-audiences — `content` is display-grade, `output` model-facing
79
+ /**
80
+ * An MCP tool's result: its blocks as `output` shows them, joined. A result
81
+ * with an image also has `content`, every block in order, as Claude's tool
82
+ * results do; one without has nothing `output` does not say.
83
+ */
84
+ function mcpResult(result: unknown): { output: string; content?: ToolResultContent[] } {
85
+ const blocks = isRecord(result) && "content" in result ? result.content : result;
86
+ if (blocks == null) return { output: "" };
87
+ if (typeof blocks === "string") return { output: blocks };
88
+ if (!Array.isArray(blocks)) return { output: JSON.stringify(blocks) };
89
+ const read = blocks.map(mcpBlock);
90
+ const output = read.map(({ shown }) => shown).join("");
91
+ if (!read.some(({ entry }) => entry.type === "image")) return { output };
92
+ return { output, content: read.map(({ entry }) => entry) };
49
93
  }
50
94
 
51
95
  const failed = (item: CodexItem) => item.status === "failed";
@@ -64,11 +108,125 @@ function describeChange(change: CodexFileChange): string {
64
108
  return `${kind ?? "change"} ${change.path}${to ? ` -> ${to}` : ""}`;
65
109
  }
66
110
 
67
- function codexFileChangeLocations(
68
- changes: Array<{ path: string }> | undefined,
69
- ): ToolLocation[] | undefined {
70
- if (!changes?.length) return undefined;
71
- return changes.map((c) => ({ path: c.path }));
111
+ /** A shell Codex runs a command in, `-lc` and its one argument, the line. */
112
+ const SHELL_WRAPPER = /^(?:\S*\/)?(?:ba|z)?sh -lc (.+)$/s;
113
+ /** Characters a word may hold unquoted and mean only themselves. */
114
+ const PLAIN = /[A-Za-z0-9_@%+=:,./-]/;
115
+
116
+ /**
117
+ * The one shell word `text` is, unquoted as the shell would; undefined when
118
+ * it is several words, unterminated, or would expand (an unquoted special
119
+ * character, a `$` or a backquote inside double quotes).
120
+ */
121
+ function shellWord(text: string): string | undefined {
122
+ let word = "";
123
+ let i = 0;
124
+ while (i < text.length) {
125
+ const c = text[i] as string;
126
+ if (c === "'") {
127
+ const end = text.indexOf("'", i + 1);
128
+ if (end < 0) return undefined;
129
+ word += text.slice(i + 1, end);
130
+ i = end + 1;
131
+ } else if (c === '"') {
132
+ i++;
133
+ for (;;) {
134
+ const d = text[i];
135
+ if (d === undefined || d === "$" || d === "`") return undefined;
136
+ if (d === '"') break;
137
+ if (d === "\\" && '"\\$`'.includes(text[i + 1] ?? "")) {
138
+ word += text[i + 1];
139
+ i += 2;
140
+ } else {
141
+ word += d;
142
+ i++;
143
+ }
144
+ }
145
+ i++;
146
+ } else if (PLAIN.test(c)) {
147
+ word += c;
148
+ i++;
149
+ } else return undefined;
150
+ }
151
+ return word;
152
+ }
153
+
154
+ // @ref LLP 0002#a-tool-call-says-what-it-acts-on — the line, apart from the shell Codex adds
155
+ /**
156
+ * The line a Codex command runs: Codex wraps it in a shell
157
+ * (`/bin/zsh -lc '<line>'`, quoted as Codex quotes it), and the line is that
158
+ * shell's one argument, unquoted. Codex's `commandActions` are not it: they
159
+ * keep only the pieces Codex recognizes (`cd sub && cat c.txt` is one read of
160
+ * `cat c.txt`) and normalize their quoting. A command of any other shape is
161
+ * as Codex reports it; one that is not a string, nothing.
162
+ */
163
+ export function codexCommandLine(command: unknown): string | undefined {
164
+ if (typeof command !== "string" || !command) return undefined;
165
+ const quoted = SHELL_WRAPPER.exec(command)?.[1];
166
+ return (quoted !== undefined && shellWord(quoted)) || command;
167
+ }
168
+
169
+ /** A change's kind (`add`, `delete`, `update`), and where an update moves the file. */
170
+ function changeKind(change: CodexFileChange): { kind?: string; movedTo?: string } {
171
+ if (typeof change.kind === "string") return { kind: change.kind };
172
+ return { kind: change.kind?.type, movedTo: change.kind?.move_path ?? undefined };
173
+ }
174
+
175
+ /**
176
+ * An update's unified diff as hunks: each `@@` header's start line in the
177
+ * new file, and the lines under it. A move's diff ends with Codex's own
178
+ * `Moved to:` trailer, which is no line of the file.
179
+ */
180
+ function updateHunks(diff: string, movedTo?: string): Array<{ line?: number; lines: string[] }> {
181
+ const trailer = movedTo !== undefined ? `\n\nMoved to: ${movedTo}` : undefined;
182
+ const body = trailer && diff.endsWith(trailer) ? diff.slice(0, -trailer.length) : diff;
183
+ const hunks: Array<{ line?: number; lines: string[] }> = [];
184
+ for (const line of body.replace(/\n$/, "").split("\n")) {
185
+ if (line.startsWith("@@")) {
186
+ const start = /^@@ -\d+(?:,\d+)? \+(\d+)/.exec(line)?.[1];
187
+ hunks.push({ ...(start !== undefined && { line: Number(start) }), lines: [] });
188
+ } else hunks.at(-1)?.lines.push(line);
189
+ }
190
+ return hunks;
191
+ }
192
+
193
+ /**
194
+ * What a file change shows: a `diff` entry per hunk of an update, at the
195
+ * file it leaves (a move's destination); an add's content as `newText`; a
196
+ * delete's as `oldText`, its `newText` empty. Its locations are each hunk's
197
+ * start in the new file, a move's source too, and an add's or a delete's
198
+ * path alone.
199
+ */
200
+ export function codexChangeView(changes: CodexFileChange[] | undefined): {
201
+ content: ToolResultContent[];
202
+ locations: ToolLocation[];
203
+ } {
204
+ const content: ToolResultContent[] = [];
205
+ const locations: ToolLocation[] = [];
206
+ for (const change of changes ?? []) {
207
+ const { kind, movedTo } = changeKind(change);
208
+ const diff = change.diff ?? "";
209
+ if (kind === "add" || kind === "delete") {
210
+ locations.push({ path: change.path });
211
+ if (change.diff !== undefined)
212
+ content.push(
213
+ kind === "add"
214
+ ? { type: "diff", path: change.path, newText: diff }
215
+ : { type: "diff", path: change.path, oldText: diff, newText: "" },
216
+ );
217
+ continue;
218
+ }
219
+ const path = movedTo ?? change.path;
220
+ if (movedTo) locations.push({ path: change.path });
221
+ const hunks = updateHunks(diff, movedTo);
222
+ if (!hunks.length) locations.push({ path });
223
+ for (const hunk of hunks) {
224
+ locations.push({ path, ...(hunk.line !== undefined && { line: hunk.line }) });
225
+ const entry = hunkDiff(path, hunk.lines);
226
+ if (entry) content.push(entry);
227
+ }
228
+ }
229
+ return { content, locations };
72
230
  }
73
231
 
74
232
  const CODEX_TOOL_ITEMS: Record<string, CodexToolDescriptor> = {
@@ -96,13 +254,17 @@ const CODEX_TOOL_ITEMS: Record<string, CodexToolDescriptor> = {
96
254
  commandExecution: {
97
255
  toolName: () => "shell",
98
256
  input: (item) => ({ command: item.command ?? "" }),
99
- meta: () => ({ kind: CODEX_TOOL_KINDS.shell }),
257
+ meta: (item) => {
258
+ const command = codexCommandLine(item.command);
259
+ return { kind: CODEX_TOOL_KINDS.shell, ...(command && { command }) };
260
+ },
100
261
  result: (item) =>
101
262
  item.status === "declined"
102
263
  ? { output: CODEX_COMMAND_DECLINED, isError: true }
103
264
  : {
104
265
  output: item.aggregatedOutput ?? "",
105
266
  isError: failed(item) || (item.exitCode ?? 0) !== 0,
267
+ ...(typeof item.exitCode === "number" && { metadata: { exitCode: item.exitCode } }),
106
268
  },
107
269
  },
108
270
  fileChange: {
@@ -110,28 +272,54 @@ const CODEX_TOOL_ITEMS: Record<string, CodexToolDescriptor> = {
110
272
  input: (item) => ({ changes: item.changes ?? [] }),
111
273
  meta: (item) => ({
112
274
  kind: CODEX_TOOL_KINDS.apply_patch,
113
- locations: codexFileChangeLocations(item.changes),
275
+ locations: codexChangeView(item.changes).locations,
114
276
  }),
277
+ // A failed or declined change shows no diff: `completeToolPart` keeps none.
115
278
  result: (item) =>
116
279
  item.status === "declined"
117
280
  ? { output: CODEX_CHANGE_DECLINED, isError: true }
118
281
  : {
119
282
  output: (item.changes ?? []).map(describeChange).join("\n"),
120
283
  isError: failed(item),
284
+ content: codexChangeView(item.changes).content,
121
285
  },
122
286
  },
123
287
  mcpToolCall: {
124
288
  toolName: (item) => `${item.server ?? "mcp"}.${item.tool ?? "tool"}`,
125
289
  input: (item) => ({ arguments: item.arguments }),
126
- meta: () => ({ kind: CODEX_TOOL_KINDS.mcp }),
290
+ meta: (item) => ({
291
+ kind: CODEX_TOOL_KINDS.mcp,
292
+ // Codex names both on the item: never read out of `toolName`.
293
+ ...(item.server !== undefined &&
294
+ item.tool !== undefined && { mcp: { server: item.server, tool: item.tool } }),
295
+ }),
127
296
  result: (item) => {
128
297
  const err = pickCodexError(item.error);
129
- return {
130
- output: err || stringifyMcpResult(item.result),
131
- isError: failed(item) || Boolean(err),
132
- };
298
+ if (err) return { output: err, isError: true };
299
+ return { ...mcpResult(item.result), isError: failed(item) };
133
300
  },
134
301
  },
302
+ // @ref LLP 0017#codexs-own-pictures-and-an-mcp-tools-picture — a picture Codex makes itself, without its bytes
303
+ imageGeneration: {
304
+ toolName: () => "image_generation",
305
+ // The prompt Codex wrote, when it gives one, comes with the picture.
306
+ input: (item) => (item.revisedPrompt ? { prompt: item.revisedPrompt } : {}),
307
+ inputAtCompletion: true,
308
+ meta: () => ({ kind: CODEX_TOOL_KINDS.image_generation }),
309
+ // Megabytes of base64 stay out of the stream, the journal and every
310
+ // checkpoint: the picture is the file Codex saved.
311
+ result: (item) =>
312
+ item.failure || failed(item)
313
+ ? {
314
+ output: `Image generation failed${item.failure?.type ? `: ${item.failure.type}` : ""}`,
315
+ isError: true,
316
+ }
317
+ : {
318
+ output: "Generated an image.",
319
+ ...(item.savedPath && { metadata: { savedPath: item.savedPath } }),
320
+ isError: false,
321
+ },
322
+ },
135
323
  webSearch: {
136
324
  toolName: () => "web_search",
137
325
  input: (item) => ({ query: item.query ?? "" }),
@@ -31,7 +31,7 @@ const LOGINS: readonly (AuthMethod & { type: string })[] = [
31
31
  },
32
32
  ];
33
33
 
34
- export interface CodexCliLoginOptions {
34
+ interface CodexCliLoginOptions {
35
35
  /**
36
36
  * A new app-server, not yet initialized, for a turn's `env`: its
37
37
  * `CODEX_HOME` is the store a login lands in.
@@ -78,10 +78,22 @@ export function codexLoginStatus(read: CodexAccountRead): LoginStatus {
78
78
  }
79
79
  }
80
80
 
81
+ /** The variable that picks Codex's login store, its home. */
82
+ const STORE_VARIABLE = "CODEX_HOME";
83
+
84
+ /** The login store a turn or a login with this `env` uses: its `CODEX_HOME`, empty when unset. */
85
+ export function codexLoginStore(env: Record<string, string> | undefined): string {
86
+ return env?.[STORE_VARIABLE] ?? "";
87
+ }
88
+
81
89
  /** Codex's login, through its app-server: `account/read`, `account/login/start`, `account/logout`. */
82
90
  export class CodexCliLogin implements CliLogin {
83
91
  constructor(private readonly options: CodexCliLoginOptions) {}
84
92
 
93
+ store(env: Record<string, string> | undefined): string {
94
+ return codexLoginStore(env);
95
+ }
96
+
85
97
  /** Initialize a new app-server, run `use` on it, and end it. */
86
98
  private async with<T>(
87
99
  options: LoginOptions,
@@ -105,7 +117,7 @@ export class CodexCliLogin implements CliLogin {
105
117
  terminalMethod(
106
118
  [await this.options.cliPath(), "login"],
107
119
  { ...process.env, ...options.env },
108
- "CODEX_HOME",
120
+ STORE_VARIABLE,
109
121
  ),
110
122
  ];
111
123
  }