stitchkit 0.132.3 → 0.133.1

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 (338) hide show
  1. package/CHANGELOG.md +178 -1
  2. package/README.md +4 -0
  3. package/dist/agent-executor/acp/v1-connect.d.ts +12 -1
  4. package/dist/agent-executor/acp/v1-connect.d.ts.map +1 -1
  5. package/dist/agent-executor/acp/v1-driver.d.ts +3 -1
  6. package/dist/agent-executor/acp/v1-driver.d.ts.map +1 -1
  7. package/dist/agent-executor/acp/v1-handlers.d.ts +9 -1
  8. package/dist/agent-executor/acp/v1-handlers.d.ts.map +1 -1
  9. package/dist/agent-executor/acp/v1-permission.d.ts +3 -2
  10. package/dist/agent-executor/acp/v1-permission.d.ts.map +1 -1
  11. package/dist/agent-executor/acp/v1-probe.d.ts +10 -1
  12. package/dist/agent-executor/acp/v1-probe.d.ts.map +1 -1
  13. package/dist/agent-executor/acp/v1-session.d.ts +11 -2
  14. package/dist/agent-executor/acp/v1-session.d.ts.map +1 -1
  15. package/dist/agent-executor/acp/v1-turn.d.ts +13 -10
  16. package/dist/agent-executor/acp/v1-turn.d.ts.map +1 -1
  17. package/dist/agent-executor/claude/cli-driver.d.ts +6 -0
  18. package/dist/agent-executor/claude/cli-driver.d.ts.map +1 -1
  19. package/dist/agent-executor/claude/record-router.d.ts +44 -0
  20. package/dist/agent-executor/claude/record-router.d.ts.map +1 -0
  21. package/dist/agent-executor/claude/session.d.ts +2 -0
  22. package/dist/agent-executor/claude/session.d.ts.map +1 -1
  23. package/dist/agent-executor/claude-sdk/driver.d.ts +20 -2
  24. package/dist/agent-executor/claude-sdk/driver.d.ts.map +1 -1
  25. package/dist/agent-executor/claude-sdk/engine-spawn.d.ts +18 -0
  26. package/dist/agent-executor/claude-sdk/engine-spawn.d.ts.map +1 -0
  27. package/dist/agent-executor/claude-sdk/query-loop.d.ts +8 -11
  28. package/dist/agent-executor/claude-sdk/query-loop.d.ts.map +1 -1
  29. package/dist/agent-executor/claude-sdk/query-manager.d.ts +4 -2
  30. package/dist/agent-executor/claude-sdk/query-manager.d.ts.map +1 -1
  31. package/dist/agent-executor/claude-sdk/query-options.d.ts +1 -0
  32. package/dist/agent-executor/claude-sdk/query-options.d.ts.map +1 -1
  33. package/dist/agent-executor/claude-sdk/session.d.ts.map +1 -1
  34. package/dist/agent-executor/codex/capabilities.d.ts +8 -0
  35. package/dist/agent-executor/codex/capabilities.d.ts.map +1 -0
  36. package/dist/agent-executor/codex/connect.d.ts +6 -1
  37. package/dist/agent-executor/codex/connect.d.ts.map +1 -1
  38. package/dist/agent-executor/codex/driver.d.ts +10 -0
  39. package/dist/agent-executor/codex/driver.d.ts.map +1 -1
  40. package/dist/agent-executor/codex/event-routing.d.ts +23 -1
  41. package/dist/agent-executor/codex/event-routing.d.ts.map +1 -1
  42. package/dist/agent-executor/codex/handlers.d.ts +23 -3
  43. package/dist/agent-executor/codex/handlers.d.ts.map +1 -1
  44. package/dist/agent-executor/codex/limits.d.ts +17 -0
  45. package/dist/agent-executor/codex/limits.d.ts.map +1 -1
  46. package/dist/agent-executor/codex/request-answers.d.ts +23 -3
  47. package/dist/agent-executor/codex/request-answers.d.ts.map +1 -1
  48. package/dist/agent-executor/codex/session-bind.d.ts +6 -1
  49. package/dist/agent-executor/codex/session-bind.d.ts.map +1 -1
  50. package/dist/agent-executor/codex/session-types.d.ts +5 -1
  51. package/dist/agent-executor/codex/session-types.d.ts.map +1 -1
  52. package/dist/agent-executor/codex/session.d.ts.map +1 -1
  53. package/dist/agent-executor/codex/shared-server.d.ts.map +1 -1
  54. package/dist/agent-executor/codex/shared-thread.d.ts +6 -8
  55. package/dist/agent-executor/codex/shared-thread.d.ts.map +1 -1
  56. package/dist/agent-executor/codex/thread-open.d.ts +12 -3
  57. package/dist/agent-executor/codex/thread-open.d.ts.map +1 -1
  58. package/dist/agent-executor/engine-requests.d.ts +42 -0
  59. package/dist/agent-executor/engine-requests.d.ts.map +1 -1
  60. package/dist/agent-executor/handoff-schemas.d.ts.map +1 -1
  61. package/dist/agent-executor/handoff.d.ts.map +1 -1
  62. package/dist/agent-executor/image-input.d.ts +6 -5
  63. package/dist/agent-executor/image-input.d.ts.map +1 -1
  64. package/dist/agent-executor/profile.d.ts +3 -5
  65. package/dist/agent-executor/profile.d.ts.map +1 -1
  66. package/dist/agent-executor/session-primitives.d.ts +64 -3
  67. package/dist/agent-executor/session-primitives.d.ts.map +1 -1
  68. package/dist/agent-executor/testing/claude-sdk-stubs.d.ts +5 -0
  69. package/dist/agent-executor/testing/claude-sdk-stubs.d.ts.map +1 -0
  70. package/dist/agent-executor/testing/conformance-lifecycle.d.ts +11 -0
  71. package/dist/agent-executor/testing/conformance-lifecycle.d.ts.map +1 -0
  72. package/dist/agent-executor/testing/conformance-support.d.ts +23 -0
  73. package/dist/agent-executor/testing/conformance-support.d.ts.map +1 -0
  74. package/dist/agent-executor/testing/conformance.d.ts +7 -2
  75. package/dist/agent-executor/testing/conformance.d.ts.map +1 -1
  76. package/dist/agent-executor/testing/consumer-stubs.d.ts +5 -3
  77. package/dist/agent-executor/testing/consumer-stubs.d.ts.map +1 -1
  78. package/dist/agent-executor/testing/fake-codex-app-server.d.ts +5 -1
  79. package/dist/agent-executor/testing/fake-codex-app-server.d.ts.map +1 -1
  80. package/dist/agent-executor/testing/replay-driver.d.ts +6 -0
  81. package/dist/agent-executor/testing/replay-driver.d.ts.map +1 -1
  82. package/dist/agent-executor/testing/replay-gate.d.ts +4 -1
  83. package/dist/agent-executor/testing/replay-gate.d.ts.map +1 -1
  84. package/dist/agent-runtime/deferred-tool-types.d.ts +2 -0
  85. package/dist/agent-runtime/deferred-tool-types.d.ts.map +1 -1
  86. package/dist/agent-runtime/deferred-tools.d.ts.map +1 -1
  87. package/dist/browser/client.d.ts.map +1 -1
  88. package/dist/browser/operation-refusal.d.ts +10 -0
  89. package/dist/browser/operation-refusal.d.ts.map +1 -0
  90. package/dist/contract/client-types.d.ts +13 -4
  91. package/dist/contract/client-types.d.ts.map +1 -1
  92. package/dist/contract/define-validation.d.ts +6 -0
  93. package/dist/contract/define-validation.d.ts.map +1 -1
  94. package/dist/contract/define.d.ts +3 -0
  95. package/dist/contract/define.d.ts.map +1 -1
  96. package/dist/contract/errors-factory.d.ts +8 -2
  97. package/dist/contract/errors-factory.d.ts.map +1 -1
  98. package/dist/contract/errors.d.ts +9 -0
  99. package/dist/contract/errors.d.ts.map +1 -1
  100. package/dist/contract/fingerprint.d.ts +4 -1
  101. package/dist/contract/fingerprint.d.ts.map +1 -1
  102. package/dist/contract/operation-refusals.d.ts +51 -0
  103. package/dist/contract/operation-refusals.d.ts.map +1 -0
  104. package/dist/contract/tool-options.d.ts +4 -0
  105. package/dist/contract/tool-options.d.ts.map +1 -1
  106. package/dist/entrypoints/agent-executor/acp.js +253 -210
  107. package/dist/entrypoints/agent-executor/claude-sdk.js +248 -173
  108. package/dist/entrypoints/agent-executor/claude.js +57 -109
  109. package/dist/entrypoints/agent-executor/codex.js +412 -335
  110. package/dist/entrypoints/agent-executor/testing/claude-sdk.d.ts +3 -0
  111. package/dist/entrypoints/agent-executor/testing/claude-sdk.d.ts.map +1 -0
  112. package/dist/entrypoints/agent-executor/testing/claude-sdk.js +329 -0
  113. package/dist/entrypoints/agent-executor/testing.d.ts +1 -2
  114. package/dist/entrypoints/agent-executor/testing.d.ts.map +1 -1
  115. package/dist/entrypoints/agent-executor/testing.js +413 -667
  116. package/dist/entrypoints/agent-executor.d.ts +1 -1
  117. package/dist/entrypoints/agent-executor.d.ts.map +1 -1
  118. package/dist/entrypoints/agent-executor.js +12 -12
  119. package/dist/entrypoints/agent-runtime/browser.js +2 -2
  120. package/dist/entrypoints/agent-runtime/coding-tools.js +3 -3
  121. package/dist/entrypoints/agent-runtime/harness.js +8 -8
  122. package/dist/entrypoints/agent-runtime/postgres.js +5 -5
  123. package/dist/entrypoints/agent-runtime/realtime.js +2 -2
  124. package/dist/entrypoints/agent-runtime/sandbox.js +3 -3
  125. package/dist/entrypoints/agent-runtime/sqlite/bun.js +6 -6
  126. package/dist/entrypoints/agent-runtime/sqlite/node.js +6 -6
  127. package/dist/entrypoints/agent-runtime/testing.js +5 -5
  128. package/dist/entrypoints/agent-runtime.js +26 -18
  129. package/dist/entrypoints/application/grammy.js +1 -1
  130. package/dist/entrypoints/application.js +2 -2
  131. package/dist/entrypoints/cli.js +8 -8
  132. package/dist/entrypoints/contract.d.ts +3 -2
  133. package/dist/entrypoints/contract.d.ts.map +1 -1
  134. package/dist/entrypoints/contract.js +6 -4
  135. package/dist/entrypoints/files/packaging.d.ts +4 -1
  136. package/dist/entrypoints/files/packaging.d.ts.map +1 -1
  137. package/dist/entrypoints/files/packaging.js +1008 -168
  138. package/dist/entrypoints/files.js +1 -1
  139. package/dist/entrypoints/handler.js +7 -7
  140. package/dist/entrypoints/http.js +2 -2
  141. package/dist/entrypoints/index.js +10 -8
  142. package/dist/entrypoints/node.js +11 -11
  143. package/dist/entrypoints/observability.js +1 -1
  144. package/dist/entrypoints/process/bootstrap.d.ts +3 -0
  145. package/dist/entrypoints/process/bootstrap.d.ts.map +1 -0
  146. package/dist/entrypoints/process/bootstrap.js +16 -0
  147. package/dist/entrypoints/process.js +7 -7
  148. package/dist/entrypoints/realtime.js +3 -3
  149. package/dist/entrypoints/remote.js +8 -7
  150. package/dist/entrypoints/server.js +30 -14
  151. package/dist/entrypoints/service-host/macos.js +72 -206
  152. package/dist/entrypoints/service-host/work.d.ts +15 -0
  153. package/dist/entrypoints/service-host/work.d.ts.map +1 -0
  154. package/dist/entrypoints/service-host/work.js +676 -0
  155. package/dist/entrypoints/service-host.js +146 -536
  156. package/dist/entrypoints/telegram/screens.js +4 -4
  157. package/dist/entrypoints/telegram.js +4 -4
  158. package/dist/entrypoints/testing.d.ts +2 -1
  159. package/dist/entrypoints/testing.d.ts.map +1 -1
  160. package/dist/entrypoints/testing.js +27 -8
  161. package/dist/entrypoints/tools/agent.js +6 -6
  162. package/dist/entrypoints/tools/connections.js +2 -2
  163. package/dist/entrypoints/tools/invoker.js +5 -5
  164. package/dist/entrypoints/tools/mcp.js +8 -6
  165. package/dist/entrypoints/tools/toolkit.js +11 -9
  166. package/dist/entrypoints/tools.js +19 -17
  167. package/dist/entrypoints/tracking/contract.js +1 -1
  168. package/dist/entrypoints/tracking/performance.js +3 -3
  169. package/dist/files/client-artifact.d.ts +14 -42
  170. package/dist/files/client-artifact.d.ts.map +1 -1
  171. package/dist/files/client-build.d.ts +57 -0
  172. package/dist/files/client-build.d.ts.map +1 -0
  173. package/dist/files/client-declarations.d.ts +35 -0
  174. package/dist/files/client-declarations.d.ts.map +1 -0
  175. package/dist/files/client-package-bundle.d.ts +25 -0
  176. package/dist/files/client-package-bundle.d.ts.map +1 -0
  177. package/dist/files/client-package-contract.d.ts +183 -0
  178. package/dist/files/client-package-contract.d.ts.map +1 -0
  179. package/dist/files/client-package-proof.d.ts +40 -0
  180. package/dist/files/client-package-proof.d.ts.map +1 -0
  181. package/dist/files/client-package.d.ts +17 -0
  182. package/dist/files/client-package.d.ts.map +1 -0
  183. package/dist/files/declaration-specifiers.d.ts +30 -0
  184. package/dist/files/declaration-specifiers.d.ts.map +1 -0
  185. package/dist/{index-v759mzed.js → index-02r5sq9p.js} +36 -23
  186. package/dist/{index-0r15pkjq.js → index-0k1ba0ss.js} +1 -1
  187. package/dist/{index-znd1b57f.js → index-1dn2wjq6.js} +5 -4
  188. package/dist/{index-p06z7g7w.js → index-1p8q0yrt.js} +6 -5
  189. package/dist/{index-wa6h4tz6.js → index-1qwd54n3.js} +6 -5
  190. package/dist/index-2dzc7mv9.js +174 -0
  191. package/dist/index-2mz8hj58.js +155 -0
  192. package/dist/{index-17qgm6xe.js → index-34k82crg.js} +2 -2
  193. package/dist/index-3mcbr8sx.js +349 -0
  194. package/dist/{index-ybdq8kk2.js → index-3y2tzhr8.js} +3 -3
  195. package/dist/{index-fgahdc7s.js → index-5n3a8hd8.js} +5 -3
  196. package/dist/{index-jb4m241t.js → index-6918kxbf.js} +45 -1
  197. package/dist/{index-n3bm7zqq.js → index-6kmjcm81.js} +4 -4
  198. package/dist/{index-akf0xkrm.js → index-78da4g74.js} +1 -1
  199. package/dist/{index-9pv126eh.js → index-7fjbdga8.js} +7 -1
  200. package/dist/{index-zhshhxew.js → index-8jf4bt7v.js} +1 -1
  201. package/dist/{index-p16q492v.js → index-8t9dr41h.js} +18 -5
  202. package/dist/{index-xq4s9mka.js → index-8yt3rwe7.js} +1 -1
  203. package/dist/{index-39c2hj6h.js → index-9c76vfxf.js} +7 -3
  204. package/dist/index-9ft4n9j1.js +432 -0
  205. package/dist/{index-sd4e5x5j.js → index-9wdrwx3b.js} +8 -7
  206. package/dist/{index-z114ax5e.js → index-an7vcmwf.js} +49 -2
  207. package/dist/{index-pzhqydxb.js → index-d04w81fz.js} +1 -1
  208. package/dist/index-d2drhb9c.js +219 -0
  209. package/dist/{index-8gmmdz7k.js → index-dacxr7nf.js} +1 -1
  210. package/dist/{index-dnzxxf8a.js → index-dm6nxkn1.js} +1 -1
  211. package/dist/index-dxft2mnm.js +42 -0
  212. package/dist/{index-rxh3qy4x.js → index-fzd477xk.js} +1 -1
  213. package/dist/{index-xgae0bn7.js → index-g4gstmp1.js} +2 -2
  214. package/dist/{index-athc412x.js → index-g5fgeb6v.js} +1 -1
  215. package/dist/{index-z9d74jmb.js → index-gbhj370g.js} +3 -3
  216. package/dist/{index-3fym4j8n.js → index-gtaaxe9d.js} +1 -1
  217. package/dist/{index-v59pxmf1.js → index-jpecjm30.js} +2 -2
  218. package/dist/index-k9g061ma.js +164 -0
  219. package/dist/{index-669374qc.js → index-ma26mfnt.js} +84 -315
  220. package/dist/{index-ryxb427v.js → index-msxf2r8x.js} +16 -3
  221. package/dist/{index-rbd2rq3z.js → index-nr4fhfn4.js} +1 -1
  222. package/dist/{index-qa2jjb65.js → index-pbekeqzm.js} +1 -1
  223. package/dist/{index-mkfhpk11.js → index-pq6g1k9t.js} +2 -2
  224. package/dist/{index-gya4hwh3.js → index-pws5c3x6.js} +21 -1
  225. package/dist/{index-x2fb37t0.js → index-q427q23r.js} +3 -2
  226. package/dist/{index-jcrj0b8z.js → index-qggqqja2.js} +39 -2
  227. package/dist/{index-jxtg307y.js → index-rkjfzs0a.js} +1 -1
  228. package/dist/{index-5tdc0q43.js → index-rw8ze745.js} +5 -3
  229. package/dist/index-s43tr4my.js +129 -0
  230. package/dist/{index-f9p62ean.js → index-stpy56r3.js} +175 -249
  231. package/dist/index-t5g5rm9n.js +213 -0
  232. package/dist/{index-z20pdxeb.js → index-tmv3ez1h.js} +3 -3
  233. package/dist/{index-dcsxj68j.js → index-tqjamnax.js} +1 -1
  234. package/dist/{index-j15dhkda.js → index-wddcfbng.js} +1 -325
  235. package/dist/{index-9sfhje6y.js → index-wh70tmpd.js} +24 -234
  236. package/dist/index-wxjv4sqx.js +82 -0
  237. package/dist/{index-qhjmmsm2.js → index-x46y9z26.js} +2 -2
  238. package/dist/{index-nk0cy9g1.js → index-y53cqwke.js} +1 -1
  239. package/dist/{index-sv5svtq7.js → index-y68gavb5.js} +1 -1
  240. package/dist/{index-5y7j383h.js → index-yrhw10ef.js} +1 -1
  241. package/dist/process/bootstrap.d.ts +12 -0
  242. package/dist/process/bootstrap.d.ts.map +1 -0
  243. package/dist/process/owner-loss-guard.d.ts +2 -9
  244. package/dist/process/owner-loss-guard.d.ts.map +1 -1
  245. package/dist/process/work-root.d.ts +20 -0
  246. package/dist/process/work-root.d.ts.map +1 -0
  247. package/dist/server/contract-identity.d.ts.map +1 -1
  248. package/dist/server/contract-method.d.ts +12 -0
  249. package/dist/server/contract-method.d.ts.map +1 -1
  250. package/dist/server/implement.d.ts.map +1 -1
  251. package/dist/server/openapi.d.ts.map +1 -1
  252. package/dist/server/types.d.ts +10 -9
  253. package/dist/server/types.d.ts.map +1 -1
  254. package/dist/service-host/host-adapter.d.ts +2 -0
  255. package/dist/service-host/host-adapter.d.ts.map +1 -1
  256. package/dist/service-host/work/command.d.ts +72 -0
  257. package/dist/service-host/work/command.d.ts.map +1 -0
  258. package/dist/service-host/work/errors.d.ts +29 -0
  259. package/dist/service-host/work/errors.d.ts.map +1 -0
  260. package/dist/service-host/work/host.d.ts +38 -0
  261. package/dist/service-host/work/host.d.ts.map +1 -0
  262. package/dist/service-host/work/launch.d.ts +51 -0
  263. package/dist/service-host/work/launch.d.ts.map +1 -0
  264. package/dist/service-host/work/membership.d.ts +51 -0
  265. package/dist/service-host/work/membership.d.ts.map +1 -0
  266. package/dist/service-host/work/origin.d.ts +79 -0
  267. package/dist/service-host/work/origin.d.ts.map +1 -0
  268. package/dist/service-host/work/owner.d.ts +45 -0
  269. package/dist/service-host/work/owner.d.ts.map +1 -0
  270. package/dist/service-host/work/placement.d.ts +55 -0
  271. package/dist/service-host/work/placement.d.ts.map +1 -0
  272. package/dist/service-host/work/probe.d.ts +24 -0
  273. package/dist/service-host/work/probe.d.ts.map +1 -0
  274. package/dist/service-host/work/scope-command.d.ts +68 -0
  275. package/dist/service-host/work/scope-command.d.ts.map +1 -0
  276. package/dist/sync/session.d.ts +4 -1
  277. package/dist/sync/session.d.ts.map +1 -1
  278. package/dist/testing/surface-manifest-digest.d.ts +2 -0
  279. package/dist/testing/surface-manifest-digest.d.ts.map +1 -1
  280. package/dist/testing/surface-manifest.d.ts +32 -3
  281. package/dist/testing/surface-manifest.d.ts.map +1 -1
  282. package/dist/tools/agent.d.ts +2 -0
  283. package/dist/tools/agent.d.ts.map +1 -1
  284. package/dist/tools/cli/stream-surface.d.ts.map +1 -1
  285. package/dist/tools/internal/mcp-projection.d.ts +58 -0
  286. package/dist/tools/internal/mcp-projection.d.ts.map +1 -0
  287. package/dist/tools/internal/surface-projector.d.ts +3 -47
  288. package/dist/tools/internal/surface-projector.d.ts.map +1 -1
  289. package/dist/tools/invoker.d.ts +2 -0
  290. package/dist/tools/invoker.d.ts.map +1 -1
  291. package/dist/tools/manifest.d.ts +2 -0
  292. package/dist/tools/manifest.d.ts.map +1 -1
  293. package/dist/tools/mcp/handler.d.ts.map +1 -1
  294. package/dist/tools/mcp/lazy-discovery.d.ts.map +1 -1
  295. package/dist/tools/mcp/mount.d.ts +4 -0
  296. package/dist/tools/mcp/mount.d.ts.map +1 -1
  297. package/dist/tools/mcp/prepare.d.ts +5 -2
  298. package/dist/tools/mcp/prepare.d.ts.map +1 -1
  299. package/dist/tools/mount.d.ts +2 -0
  300. package/dist/tools/mount.d.ts.map +1 -1
  301. package/dist/tools/remote.d.ts.map +1 -1
  302. package/dist/tools/schema/nesting-limit.d.ts +8 -0
  303. package/dist/tools/schema/nesting-limit.d.ts.map +1 -0
  304. package/dist/tools/schema/presentation.d.ts +7 -0
  305. package/dist/tools/schema/presentation.d.ts.map +1 -1
  306. package/dist/tools/surface.d.ts.map +1 -1
  307. package/llms/agent-executor-acp.txt +3 -3
  308. package/llms/agent-executor-claude-sdk.txt +1 -1
  309. package/llms/agent-executor-claude.txt +1 -1
  310. package/llms/agent-executor-codex.txt +1 -1
  311. package/llms/agent-executor-testing-claude-sdk.txt +28 -0
  312. package/llms/agent-executor-testing.txt +7 -8
  313. package/llms/agent-executor.txt +27 -4
  314. package/llms/agent-runtime.txt +1 -1
  315. package/llms/contract.txt +8 -2
  316. package/llms/files-packaging.txt +11 -6
  317. package/llms/process-bootstrap.txt +18 -0
  318. package/llms/process.2.txt +248 -18
  319. package/llms/process.txt +130 -92
  320. package/llms/server.4.txt +49 -1
  321. package/llms/service-host-work.txt +34 -0
  322. package/llms/stitchkit.2.txt +31 -0
  323. package/llms/stitchkit.txt +78 -75
  324. package/llms/sync.txt +5 -2
  325. package/llms/testing.txt +1 -0
  326. package/llms/tools.2.txt +747 -775
  327. package/llms/tools.3.txt +846 -210
  328. package/llms/tools.4.txt +226 -0
  329. package/llms/tools.txt +3 -790
  330. package/llms/{upgrading-0.128.0-0.132.0.txt → upgrading-0.128.0-0.133.0.txt} +194 -6
  331. package/llms/upgrading.txt +1 -1
  332. package/llms-full.txt +779 -135
  333. package/llms.txt +18 -16
  334. package/package.json +12 -4
  335. package/dist/entrypoints/process/owner-loss.d.ts +0 -3
  336. package/dist/entrypoints/process/owner-loss.d.ts.map +0 -1
  337. package/dist/entrypoints/process/owner-loss.js +0 -7
  338. package/llms/process-owner-loss.txt +0 -18
@@ -1,7 +1,9 @@
1
1
  import"../../index-2rf33y2h.js";
2
2
  import {
3
3
  ExecutorThreadDispositionSchema2,
4
- ExecutorErrorKindSchema2,
4
+ ExecutorErrorKindSchema2
5
+ } from "../../index-s43tr4my.js";
6
+ import {
5
7
  InteractionReplySchema2,
6
8
  engineProfile,
7
9
  engineEnvironment2,
@@ -9,17 +11,19 @@ import {
9
11
  createTurnDeltaChannel,
10
12
  offerTurnDelta,
11
13
  sessionAbort,
14
+ sessionLiveness,
12
15
  stopConnection,
13
16
  withEphemeralConnection,
14
17
  safeJsonValue,
15
- invokeSafely,
18
+ reportObserverError,
19
+ invokeObserver,
16
20
  emitStartupPhase
17
- } from "../../index-f9p62ean.js";
21
+ } from "../../index-stpy56r3.js";
18
22
  import"../../index-09f7w2qq.js";
19
23
  import {
20
24
  NativeCommandError2
21
- } from "../../index-v59pxmf1.js";
22
- import"../../index-qa2jjb65.js";
25
+ } from "../../index-jpecjm30.js";
26
+ import"../../index-pbekeqzm.js";
23
27
  import"../../index-6kec3b14.js";
24
28
  import {
25
29
  JsonRpcError2,
@@ -30,20 +34,23 @@ import {
30
34
  DEFAULT_MAX_IMAGE_BYTES,
31
35
  validateImageOptions,
32
36
  bytesToBase64,
33
- resolveImageBytes
37
+ resolveImageBytes,
38
+ guardedTurnStarter
34
39
  } from "../../index-y0a4gt1s.js";
35
40
  import {
36
41
  holdEngineRequest,
37
- answerEngineRequest,
38
- drainEngineRequests,
39
42
  endEngineTurn,
40
- loseEngineTurn
41
- } from "../../index-jcrj0b8z.js";
43
+ loseEngineTurn,
44
+ abandonEngineTurn,
45
+ leaveEngineRequestUnanswered,
46
+ interruptEngineTurn,
47
+ respondToEngineRequest
48
+ } from "../../index-qggqqja2.js";
42
49
  import {
43
50
  spawnEngineProcess2
44
- } from "../../index-rxh3qy4x.js";
45
- import"../../index-3fym4j8n.js";
46
- import"../../index-pzhqydxb.js";
51
+ } from "../../index-fzd477xk.js";
52
+ import"../../index-gtaaxe9d.js";
53
+ import"../../index-d04w81fz.js";
47
54
  import {
48
55
  assertPositiveSafeInteger
49
56
  } from "../../index-gr0kxymw.js";
@@ -52,7 +59,8 @@ import {
52
59
  withSignalDeadline
53
60
  } from "../../index-agy5fqgf.js";
54
61
  import {
55
- abortReason
62
+ abortReason,
63
+ linkAbortSignals
56
64
  } from "../../index-rptj3qnc.js";
57
65
 
58
66
  // src/agent-executor/acp/scenarios.ts
@@ -436,6 +444,15 @@ function assertAcpDriverOptions(config) {
436
444
  validateSessionMetaObject(config.sessionMeta);
437
445
  }
438
446
  }
447
+ function keepsStdoutLine(filter, line) {
448
+ if (filter === undefined)
449
+ return true;
450
+ try {
451
+ return filter(line);
452
+ } catch (error) {
453
+ throw new Error(`The ACP stdoutLineFilter threw: ${error instanceof Error ? error.message : String(error)}`, { cause: error });
454
+ }
455
+ }
439
456
  async function connectAcp(config, profile, cwd, signal, handlers = {}) {
440
457
  assertAcpDriverOptions(config);
441
458
  const env = engineEnvironment2(profile, config.ambient ?? process.env);
@@ -446,7 +463,7 @@ async function connectAcp(config, profile, cwd, signal, handlers = {}) {
446
463
  ...handlers.onRequest && { onRequest: handlers.onRequest },
447
464
  ...handlers.onNotification && { onNotification: handlers.onNotification }
448
465
  });
449
- emitStartupPhase(handlers.onStartupPhase, "spawning");
466
+ emitStartupPhase(handlers.onStartupPhase, "spawning", config.onObserverError);
450
467
  const engine = spawnEngineProcess2({
451
468
  executable: config.executable,
452
469
  args: [...config.args ?? []],
@@ -458,15 +475,14 @@ async function connectAcp(config, profile, cwd, signal, handlers = {}) {
458
475
  if (handlers.onProviderPid !== undefined && engine.pidReady !== undefined) {
459
476
  engine.pidReady.then((pid) => {
460
477
  if (pid !== undefined)
461
- invokeSafely(() => handlers.onProviderPid?.(pid));
478
+ invokeObserver(config.onObserverError, "onProviderPid", () => handlers.onProviderPid?.(pid));
462
479
  });
463
480
  }
464
481
  const reading = (async () => {
465
482
  try {
466
483
  for await (const line of engine.lines) {
467
- if (config.stdoutLineFilter !== undefined && !config.stdoutLineFilter(line)) {
484
+ if (!keepsStdoutLine(config.stdoutLineFilter, line))
468
485
  continue;
469
- }
470
486
  peer.receive(line);
471
487
  }
472
488
  const ended = new Error(`The ACP agent ${config.executable} exited: ${engine.stderrTail().slice(-2000)}`);
@@ -484,7 +500,7 @@ async function connectAcp(config, profile, cwd, signal, handlers = {}) {
484
500
  }
485
501
  })();
486
502
  try {
487
- emitStartupPhase(handlers.onStartupPhase, "initializing");
503
+ emitStartupPhase(handlers.onStartupPhase, "initializing", config.onObserverError);
488
504
  const clientInfo = config.clientInfo !== undefined ? AcpClientInfoSchema.parse(config.clientInfo) : undefined;
489
505
  const rawInitialized = await peer.request("initialize", {
490
506
  protocolVersion: ACP_PROTOCOL_VERSION,
@@ -791,17 +807,13 @@ function buildAcpPermissionAnswer(detail, rawReply) {
791
807
  throw new TypeError("The agent offered no reject option");
792
808
  return { outcome: { outcome: "selected", optionId: option.optionId } };
793
809
  }
794
- function answerActiveAcpTurnRequest(turn, interactionId, rawReply) {
795
- const waiting = turn.pending.get(interactionId);
796
- if (waiting === undefined) {
797
- throw new TypeError(`Unknown interaction ${interactionId} for this turn`);
798
- }
799
- const answer = buildAcpPermissionAnswer(waiting.detail, rawReply);
800
- answerEngineRequest(turn, interactionId, answer);
810
+ function answerActiveAcpTurnRequest(turn, liveness, interactionId, rawReply) {
811
+ respondToEngineRequest(turn, liveness, interactionId, (detail) => buildAcpPermissionAnswer(detail, rawReply));
801
812
  }
802
813
  function answerAcpSessionRequest(input) {
814
+ input.liveness.ensureAlive();
803
815
  if (input.turn?.pending.has(input.interactionId)) {
804
- answerActiveAcpTurnRequest(input.turn, input.interactionId, input.reply);
816
+ answerActiveAcpTurnRequest(input.turn, input.liveness, input.interactionId, input.reply);
805
817
  return;
806
818
  }
807
819
  const external = input.externalPending.get(input.interactionId);
@@ -816,14 +828,6 @@ function answerAcpSessionRequest(input) {
816
828
  // src/agent-executor/acp/v1-handlers.ts
817
829
  var JSON_RPC_INTERNAL_ERROR = -32603;
818
830
  var MAX_EXTERNAL_PENDING_REQUESTS = 256;
819
- function isHandlersAlive(state) {
820
- try {
821
- state.ensureAlive();
822
- return true;
823
- } catch {
824
- return false;
825
- }
826
- }
827
831
  function normalizeTransformedUpdates(raw, transform) {
828
832
  if (transform === undefined)
829
833
  return [raw];
@@ -870,7 +874,8 @@ function handleAcpNotification(state, externalState, method, params) {
870
874
  try {
871
875
  updates = normalizeTransformedUpdates(parsed.data.update, state.transformUpdate);
872
876
  } catch (error) {
873
- if (!isHandlersAlive(state))
877
+ reportObserverError(state.onObserverError, "transformUpdate", error);
878
+ if (!state.liveness.isAlive())
874
879
  return;
875
880
  if (turn !== undefined) {
876
881
  turn.chunk += 1;
@@ -887,7 +892,7 @@ function handleAcpNotification(state, externalState, method, params) {
887
892
  }
888
893
  const opened = state.isOpened();
889
894
  for (const update of updates) {
890
- if (!isHandlersAlive(state))
895
+ if (!state.liveness.isAlive())
891
896
  return;
892
897
  state.onSessionMeta({
893
898
  ...update.configOptions !== undefined && { configOptions: update.configOptions },
@@ -913,7 +918,7 @@ function handleAcpNotification(state, externalState, method, params) {
913
918
  duringActiveTurn: turn !== undefined,
914
919
  deltas
915
920
  };
916
- invokeSafely(() => state.onUpdate?.(event));
921
+ invokeObserver(state.onObserverError, "onUpdate", () => state.onUpdate?.(event));
917
922
  }
918
923
  }
919
924
  }
@@ -954,17 +959,16 @@ function handleAcpRequest(state, method, params, id) {
954
959
  resolve
955
960
  });
956
961
  });
957
- if (state.permissionRequestDelivery === "all" && state.onPermissionRequest !== undefined && turn.pending.has(interactionId) && isHandlersAlive(state)) {
962
+ if (state.permissionRequestDelivery === "all" && state.onPermissionRequest !== undefined && turn.pending.has(interactionId) && state.liveness.isAlive()) {
958
963
  const observer = state.onPermissionRequest;
959
- invokeSafely(() => observer({
964
+ invokeObserver(state.onObserverError, "onPermissionRequest", () => observer({
960
965
  interactionId,
961
966
  sessionId: asked.sessionId,
962
967
  request: asked,
963
968
  duringActiveTurn: true,
964
969
  delta,
965
970
  async respond(reply) {
966
- state.ensureAlive();
967
- answerActiveAcpTurnRequest(turn, interactionId, reply);
971
+ answerActiveAcpTurnRequest(turn, state.liveness, interactionId, reply);
968
972
  }
969
973
  }));
970
974
  }
@@ -993,11 +997,16 @@ function handleAcpRequest(state, method, params, id) {
993
997
  return new Promise((resolve, reject) => {
994
998
  const entry = { detail: { options: asked.options }, resolve };
995
999
  state.externalPending.set(interactionId, entry);
996
- const onObserverError = (error) => {
1000
+ const report = (error) => {
1001
+ if (!(error instanceof JsonRpcError2))
1002
+ reportObserverError(state.onObserverError, "onPermissionRequest", error);
1003
+ };
1004
+ const onObserverFailure = (error) => {
1005
+ report(error);
997
1006
  if (state.externalPending.get(interactionId) !== entry)
998
1007
  return;
999
1008
  state.externalPending.delete(interactionId);
1000
- if (!isHandlersAlive(state))
1009
+ if (!state.liveness.isAlive())
1001
1010
  return;
1002
1011
  if (error instanceof JsonRpcError2)
1003
1012
  reject(error);
@@ -1012,8 +1021,8 @@ function handleAcpRequest(state, method, params, id) {
1012
1021
  duringActiveTurn: false,
1013
1022
  delta,
1014
1023
  async respond(reply) {
1015
- state.ensureAlive();
1016
1024
  answerAcpSessionRequest({
1025
+ liveness: state.liveness,
1017
1026
  turn: undefined,
1018
1027
  externalPending: state.externalPending,
1019
1028
  expectedEntry: entry,
@@ -1023,25 +1032,23 @@ function handleAcpRequest(state, method, params, id) {
1023
1032
  }
1024
1033
  });
1025
1034
  const thenable = typeof outcome === "object" && outcome !== null && "then" in outcome && typeof outcome.then === "function";
1026
- if (!isHandlersAlive(state)) {
1035
+ if (!state.liveness.isAlive()) {
1027
1036
  if (state.externalPending.get(interactionId) === entry) {
1028
1037
  state.externalPending.delete(interactionId);
1029
1038
  }
1030
1039
  if (thenable)
1031
- Promise.resolve(outcome).catch(() => {
1032
- return;
1033
- });
1040
+ Promise.resolve(outcome).catch(report);
1034
1041
  return;
1035
1042
  }
1036
1043
  if (thenable) {
1037
1044
  Promise.resolve(outcome).then(() => {
1038
- if (!isHandlersAlive(state) && state.externalPending.get(interactionId) === entry) {
1045
+ if (!state.liveness.isAlive() && state.externalPending.get(interactionId) === entry) {
1039
1046
  state.externalPending.delete(interactionId);
1040
1047
  }
1041
- }, onObserverError);
1048
+ }, onObserverFailure);
1042
1049
  }
1043
1050
  } catch (error) {
1044
- onObserverError(error);
1051
+ onObserverFailure(error);
1045
1052
  }
1046
1053
  });
1047
1054
  }
@@ -1050,18 +1057,22 @@ function createAcpHandlers(state) {
1050
1057
  chunk: 0,
1051
1058
  track: { segment: 0, toolNames: new Map }
1052
1059
  };
1053
- const dropClosedRequest = () => new Promise(() => {
1054
- return;
1055
- });
1060
+ const answerClosedRequest = (method) => {
1061
+ if (state.closingGracefully?.() !== true)
1062
+ return leaveEngineRequestUnanswered();
1063
+ if (method === "session/request_permission")
1064
+ return Promise.resolve(ACP_CANCELLED);
1065
+ return Promise.reject(new JsonRpcError2(JSON_RPC_METHOD_NOT_FOUND2, `${method} is not handled by this executor`));
1066
+ };
1056
1067
  return {
1057
1068
  onNotification: (method, params) => {
1058
- if (!isHandlersAlive(state))
1069
+ if (!state.liveness.isAlive())
1059
1070
  return;
1060
1071
  handleAcpNotification(state, externalState, method, params);
1061
1072
  },
1062
1073
  onRequest: (method, params, id) => {
1063
- if (!isHandlersAlive(state))
1064
- return dropClosedRequest();
1074
+ if (!state.liveness.isAlive())
1075
+ return answerClosedRequest(method);
1065
1076
  return handleAcpRequest(state, method, params, id);
1066
1077
  },
1067
1078
  onEnd: state.onEnd
@@ -1117,47 +1128,58 @@ async function applyAcpSessionSelections(input) {
1117
1128
  // src/agent-executor/acp/v1-probe.ts
1118
1129
  var DEFAULT_PROBE_TIMEOUT_MS = 30000;
1119
1130
  var ProbeSessionId = AcpNewSessionResultSchema.pick({ sessionId: true });
1120
- async function readProbeSession(config, connection, cwd, signal) {
1131
+ async function readProbeSession(config, connection, cwd, signal, inspect) {
1121
1132
  const meta = resolveAcpSessionMeta(config.sessionMeta, connection.initialized);
1122
1133
  const reply = await connection.peer.request("session/new", {
1123
1134
  cwd,
1124
1135
  mcpServers: [],
1125
1136
  ...meta !== undefined && { _meta: meta }
1126
1137
  }, { signal });
1127
- if (signal?.aborted)
1128
- throw abortReason(signal);
1129
- const { sessionId } = ProbeSessionId.parse(reply);
1138
+ const identified = ProbeSessionId.safeParse(reply);
1139
+ if (!identified.success) {
1140
+ if (signal?.aborted)
1141
+ throw abortReason(signal);
1142
+ throw identified.error;
1143
+ }
1144
+ const { sessionId } = identified.data;
1130
1145
  const parsed = AcpNewSessionResultSchema.safeParse(reply);
1131
- const failures = parsed.success ? [] : [parsed.error];
1132
- const timeoutMs = closeRequestTimeoutMs(config);
1133
- const cleanupOptions = { timeoutMs, ...signal !== undefined && { signal } };
1134
- const recordFailure = (method, cause) => failures.push(new Error(`${method} failed: ${cause instanceof Error ? cause.message : String(cause)}`, {
1146
+ let inspected;
1147
+ if (inspect !== undefined && parsed.success && signal?.aborted !== true) {
1148
+ try {
1149
+ inspected = { value: await inspect({ sessionId, reply }) };
1150
+ } catch (error) {
1151
+ inspected = { error };
1152
+ }
1153
+ }
1154
+ const cleanupFailures = [];
1155
+ const cleanupOptions = { timeoutMs: closeRequestTimeoutMs(config) };
1156
+ const recordFailure = (method, cause) => cleanupFailures.push(new Error(`${method} failed: ${cause instanceof Error ? cause.message : String(cause)}`, {
1135
1157
  cause
1136
1158
  }));
1137
1159
  if (acpCan(connection, "close")) {
1138
1160
  try {
1139
1161
  await connection.peer.request("session/close", { sessionId }, cleanupOptions);
1140
1162
  } catch (cause) {
1141
- if (signal?.aborted)
1142
- throw abortReason(signal);
1143
1163
  const canFallBack = cause instanceof JsonRpcError2 && cause.code === JSON_RPC_METHOD_NOT_FOUND2 && acpCan(connection, "delete");
1144
1164
  if (!canFallBack)
1145
1165
  recordFailure("session/close", cause);
1146
1166
  }
1147
1167
  }
1148
- if (signal?.aborted)
1149
- throw abortReason(signal);
1150
1168
  if (acpCan(connection, "delete")) {
1151
1169
  try {
1152
1170
  await connection.peer.request("session/delete", { sessionId }, cleanupOptions);
1153
1171
  } catch (cause) {
1154
- if (signal?.aborted)
1155
- throw abortReason(signal);
1156
1172
  recordFailure("session/delete", cause);
1157
1173
  }
1158
1174
  }
1159
- if (signal?.aborted)
1160
- throw abortReason(signal);
1175
+ if (signal?.aborted) {
1176
+ const reason = abortReason(signal);
1177
+ if (cleanupFailures.length === 0)
1178
+ throw reason;
1179
+ const all = [reason, ...cleanupFailures];
1180
+ throw new AggregateError(all, all.map(messageOf).join("; "), { cause: reason });
1181
+ }
1182
+ const failures = [...parsed.success ? [] : [parsed.error], ...cleanupFailures];
1161
1183
  if (failures.length > 1) {
1162
1184
  throw new AggregateError(failures, failures.map((error) => error.message).join("; "), {
1163
1185
  cause: failures[0]
@@ -1167,7 +1189,24 @@ async function readProbeSession(config, connection, cwd, signal) {
1167
1189
  throw parsed.error;
1168
1190
  if (failures[0] !== undefined)
1169
1191
  throw failures[0];
1170
- return parsed.data;
1192
+ if (inspected !== undefined && "error" in inspected)
1193
+ throw inspected.error;
1194
+ return { ...parsed.data, inspected: inspected?.value };
1195
+ }
1196
+ function messageOf(error) {
1197
+ return error instanceof Error ? error.message : String(error);
1198
+ }
1199
+ async function readEachModelOptions(connection, sessionId, reply, signal) {
1200
+ let options = AcpNewSessionResultSchema.parse(reply).configOptions ?? [];
1201
+ const model = options.find((option) => option.category === "model");
1202
+ const byModel = {};
1203
+ if (model === undefined)
1204
+ return byModel;
1205
+ for (const value of acpOptionValues(model)) {
1206
+ options = await setAcpConfigOption(connection.peer, sessionId, options, "model", value, signal);
1207
+ byModel[value] = options;
1208
+ }
1209
+ return byModel;
1171
1210
  }
1172
1211
  function extractProbeModels(configOptions, availableModels) {
1173
1212
  const option = configOptions.find((candidate) => candidate.category === "model");
@@ -1212,7 +1251,8 @@ async function probeAcpCapabilities(config, input) {
1212
1251
  let configOptions = [];
1213
1252
  let sawConfigOptionUpdate = false;
1214
1253
  let commands = [];
1215
- const connection = await connectAcp(config, profile, input.cwd, deadlineSignal, {
1254
+ const startup = linkAbortSignals(deadlineSignal, new AbortController().signal);
1255
+ const connection = await connectAcp(config, profile, input.cwd, startup.signal, {
1216
1256
  onNotification: (method, params) => {
1217
1257
  applyProbeNotification(config, method, params, (meta) => {
1218
1258
  if (meta.configOptions !== undefined) {
@@ -1224,10 +1264,10 @@ async function probeAcpCapabilities(config, input) {
1224
1264
  });
1225
1265
  },
1226
1266
  ...input.onStartupPhase !== undefined && { onStartupPhase: input.onStartupPhase }
1227
- });
1267
+ }).finally(() => startup.release());
1228
1268
  let result;
1229
1269
  try {
1230
- const session = await readProbeSession(config, connection, input.cwd, deadlineSignal);
1270
+ const session = await readProbeSession(config, connection, input.cwd, deadlineSignal, input.eachModel === true ? ({ sessionId, reply }) => readEachModelOptions(connection, sessionId, reply, deadlineSignal) : undefined);
1231
1271
  configOptions = mergeInitialAcpConfigOptions(configOptions, session.configOptions, sawConfigOptionUpdate);
1232
1272
  deadlineSignal.throwIfAborted();
1233
1273
  const models = extractProbeModels(configOptions, session.models?.availableModels);
@@ -1235,7 +1275,8 @@ async function probeAcpCapabilities(config, input) {
1235
1275
  initialized: connection.initialized,
1236
1276
  configOptions,
1237
1277
  commands,
1238
- models
1278
+ models,
1279
+ ...session.inspected !== undefined && { optionsByModel: session.inspected }
1239
1280
  };
1240
1281
  } catch (error) {
1241
1282
  await stopConnection(connection, { error });
@@ -1264,40 +1305,36 @@ function newAcpTurn(turnId) {
1264
1305
  track: { segment: 0, toolNames: new Map },
1265
1306
  promptGeneration: 1,
1266
1307
  accumulatedUsage: undefined,
1267
- settled: false
1308
+ settled: false,
1309
+ openGenerations: new Set,
1310
+ supersededResults: new Map
1268
1311
  };
1269
1312
  }
1270
1313
  function settleAcpTurn(turn, reason, sendCancelled) {
1271
- if (turn === undefined)
1272
- return;
1273
- turn.settled = true;
1274
- if (sendCancelled) {
1314
+ if (sendCancelled)
1275
1315
  loseEngineTurn(turn, () => ACP_CANCELLED, reason);
1276
- return;
1277
- }
1278
- turn.pending.clear();
1279
- turn.channel.fail(reason);
1316
+ else
1317
+ abandonEngineTurn(turn, reason);
1318
+ }
1319
+ function refusedSteer(turn, error, generation, previous) {
1320
+ const kind = classifyAcpRpcRefusal(error) ?? "unhandled";
1321
+ turn.promptGeneration = previous;
1322
+ offerTurnDelta(turn.channel, {
1323
+ type: "error",
1324
+ turnId: turn.state.turnId,
1325
+ itemId: `steer-refused:${generation}`,
1326
+ raw: { source: "acp", type: "session/prompt" },
1327
+ kind,
1328
+ message: `The ACP agent refused the steer prompt: ${error instanceof Error ? error.message : String(error)}`
1329
+ });
1280
1330
  }
1281
1331
  function runAcpPrompt(input) {
1282
- const { peer, sessionId, prompt, turn, generation, ensureAlive, checkOutcome, done } = input;
1283
- peer.request("session/prompt", { sessionId, prompt: [...prompt] }, { timeoutMs: null }).then(async (result) => {
1284
- if (turn.settled)
1285
- return;
1286
- ensureAlive();
1287
- const parsed = AcpPromptResultSchema.parse(result);
1288
- if (parsed.usage !== undefined && parsed.usage !== null) {
1289
- turn.accumulatedUsage = addAcpTokenUsage(turn.accumulatedUsage, normalizeAcpUsage(parsed.usage, {
1290
- ...input.usageInputIncludesCachedRead !== undefined && {
1291
- usageInputIncludesCachedRead: input.usageInputIncludesCachedRead
1292
- }
1293
- }));
1294
- }
1295
- if (generation !== turn.promptGeneration)
1296
- return;
1332
+ const { peer, sessionId, prompt, turn, generation, liveness, checkOutcome, done } = input;
1333
+ const settle = async (parsed) => {
1297
1334
  const rawOverride = !turn.state.interruptRequested && checkOutcome !== undefined ? await checkOutcome(parsed) : undefined;
1298
1335
  if (turn.settled || generation !== turn.promptGeneration)
1299
1336
  return;
1300
- ensureAlive();
1337
+ liveness.ensureAlive();
1301
1338
  const override = rawOverride !== undefined ? AcpPromptOutcomeOverrideSchema.parse(rawOverride) : undefined;
1302
1339
  const outcome = override !== undefined ? "failed" : acpOutcome(parsed.stopReason, turn.state.interruptRequested);
1303
1340
  const raw = { source: "acp", type: `session/prompt/${parsed.stopReason}` };
@@ -1340,26 +1377,29 @@ function runAcpPrompt(input) {
1340
1377
  threadDisposition: override.threadDisposition
1341
1378
  }
1342
1379
  });
1343
- turn.settled = true;
1344
1380
  endEngineTurn(turn, () => ACP_CANCELLED, last);
1345
1381
  done();
1346
- }).catch((error) => {
1382
+ };
1383
+ const fail = (error) => {
1384
+ turn.openGenerations.delete(generation);
1347
1385
  if (turn.settled || generation !== turn.promptGeneration)
1348
1386
  return;
1349
- turn.settled = true;
1350
- let failure = error;
1351
- let alive = true;
1352
- try {
1353
- ensureAlive();
1354
- } catch (aliveError) {
1355
- alive = false;
1356
- failure = aliveError;
1387
+ const earlier = [...turn.openGenerations, ...turn.supersededResults.keys()].filter((other) => other < generation);
1388
+ if (earlier.length > 0) {
1389
+ const previous = Math.max(...earlier);
1390
+ refusedSteer(turn, error, generation, previous);
1391
+ const ended = turn.supersededResults.get(previous);
1392
+ turn.supersededResults.delete(previous);
1393
+ ended?.();
1394
+ return;
1357
1395
  }
1358
- if (!alive) {
1359
- settleAcpTurn(turn, failure, false);
1396
+ const stop = liveness.stopped();
1397
+ if (stop !== undefined) {
1398
+ abandonEngineTurn(turn, stop.reason);
1360
1399
  done();
1361
1400
  return;
1362
1401
  }
1402
+ const failure = error;
1363
1403
  const kind = classifyAcpRpcRefusal(failure);
1364
1404
  if (kind !== undefined && failure instanceof Error) {
1365
1405
  const raw = { source: "acp", type: "session/prompt" };
@@ -1384,59 +1424,68 @@ function runAcpPrompt(input) {
1384
1424
  loseEngineTurn(turn, () => ACP_CANCELLED, failure);
1385
1425
  }
1386
1426
  done();
1387
- });
1427
+ };
1428
+ turn.openGenerations.add(generation);
1429
+ peer.request("session/prompt", { sessionId, prompt: [...prompt] }, { timeoutMs: null }).then(async (result) => {
1430
+ turn.openGenerations.delete(generation);
1431
+ if (turn.settled)
1432
+ return;
1433
+ liveness.ensureAlive();
1434
+ const parsed = AcpPromptResultSchema.parse(result);
1435
+ if (parsed.usage !== undefined && parsed.usage !== null) {
1436
+ turn.accumulatedUsage = addAcpTokenUsage(turn.accumulatedUsage, normalizeAcpUsage(parsed.usage, {
1437
+ ...input.usageInputIncludesCachedRead !== undefined && {
1438
+ usageInputIncludesCachedRead: input.usageInputIncludesCachedRead
1439
+ }
1440
+ }));
1441
+ }
1442
+ if (generation !== turn.promptGeneration) {
1443
+ turn.supersededResults.set(generation, () => {
1444
+ settle(parsed).catch(fail);
1445
+ });
1446
+ return;
1447
+ }
1448
+ await settle(parsed);
1449
+ }).catch(fail);
1388
1450
  }
1389
- function acpTurnHandle(peer, sessionId, turn, ensureAlive) {
1451
+ function acpTurnHandle(peer, sessionId, turn, liveness) {
1390
1452
  return {
1391
1453
  deltas: turn.channel,
1392
- async interrupt() {
1393
- if (turn.settled)
1394
- return;
1395
- try {
1396
- ensureAlive();
1397
- } catch {
1398
- return;
1399
- }
1400
- turn.state.interruptRequested = true;
1401
- peer.notify("session/cancel", { sessionId });
1402
- drainEngineRequests(turn, () => ACP_CANCELLED);
1403
- },
1454
+ interrupt: () => interruptEngineTurn(turn, liveness, {
1455
+ refusal: () => ACP_CANCELLED,
1456
+ tell: () => peer.notify("session/cancel", { sessionId })
1457
+ }),
1404
1458
  async respond(interactionId, rawReply) {
1405
- ensureAlive();
1406
- answerActiveAcpTurnRequest(turn, interactionId, rawReply);
1459
+ answerActiveAcpTurnRequest(turn, liveness, interactionId, rawReply);
1407
1460
  }
1408
1461
  };
1409
1462
  }
1410
1463
  function createAcpTurnControls(input) {
1411
- let turnOpening = false;
1412
1464
  let steering = false;
1413
1465
  const releaseTurn = (turn) => {
1414
1466
  if (input.getTurn() === turn)
1415
1467
  input.setTurn(undefined);
1416
1468
  };
1417
- return {
1418
- async startTurn(turnInput) {
1419
- input.ensureAlive();
1420
- if (input.getTurn() !== undefined || turnOpening) {
1469
+ const { liveness } = input;
1470
+ const startTurn = guardedTurnStarter({
1471
+ busyMessage: "A turn is already running in this ACP session",
1472
+ check() {
1473
+ liveness.ensureAlive();
1474
+ if (input.getTurn() !== undefined) {
1421
1475
  throw new Error("A turn is already running in this ACP session");
1422
1476
  }
1423
- turnOpening = true;
1424
- let prompt;
1425
- let checkOutcome;
1426
- try {
1427
- prompt = await acpPromptBlocks(turnInput.input, input.limits);
1428
- input.ensureAlive();
1429
- if (input.config.watchPromptOutcome !== undefined) {
1430
- checkOutcome = await input.config.watchPromptOutcome({
1431
- sessionId: input.sessionId,
1432
- turnId: turnInput.turnId,
1433
- generation: 1
1434
- });
1435
- }
1436
- } finally {
1437
- turnOpening = false;
1438
- }
1439
- input.ensureAlive();
1477
+ },
1478
+ async inline(turnInput) {
1479
+ const prompt = await acpPromptBlocks(turnInput.input, input.limits);
1480
+ liveness.ensureAlive();
1481
+ const checkOutcome = input.config.watchPromptOutcome !== undefined ? await input.config.watchPromptOutcome({
1482
+ sessionId: input.sessionId,
1483
+ turnId: turnInput.turnId,
1484
+ generation: 1
1485
+ }) : undefined;
1486
+ return { prompt, checkOutcome };
1487
+ },
1488
+ dispatch(turnInput, { prompt, checkOutcome }) {
1440
1489
  const turn = newAcpTurn(turnInput.turnId);
1441
1490
  input.setTurn(turn);
1442
1491
  runAcpPrompt({
@@ -1445,20 +1494,23 @@ function createAcpTurnControls(input) {
1445
1494
  prompt,
1446
1495
  turn,
1447
1496
  generation: 1,
1448
- ensureAlive: input.ensureAlive,
1497
+ liveness,
1449
1498
  ...input.config.usageInputIncludesCachedRead !== undefined && {
1450
1499
  usageInputIncludesCachedRead: input.config.usageInputIncludesCachedRead
1451
1500
  },
1452
1501
  ...checkOutcome !== undefined && { checkOutcome },
1453
1502
  done: () => releaseTurn(turn)
1454
1503
  });
1455
- return acpTurnHandle(input.peer, input.sessionId, turn, input.ensureAlive);
1456
- },
1504
+ return acpTurnHandle(input.peer, input.sessionId, turn, liveness);
1505
+ }
1506
+ });
1507
+ return {
1508
+ startTurn,
1457
1509
  async steerTurn(steerInput) {
1458
1510
  if ((input.config.steerMode ?? "none") !== "prompt") {
1459
1511
  throw new TypeError('The ACP driver does not support steering unless steerMode is "prompt"');
1460
1512
  }
1461
- input.ensureAlive();
1513
+ liveness.ensureAlive();
1462
1514
  const turn = input.getTurn();
1463
1515
  if (turn === undefined || turn.settled) {
1464
1516
  throw new Error("Cannot steer turn: no ACP turn is currently running");
@@ -1475,7 +1527,7 @@ function createAcpTurnControls(input) {
1475
1527
  let nextGeneration;
1476
1528
  try {
1477
1529
  prompt = await acpPromptBlocks(steerInput.input, input.limits);
1478
- input.ensureAlive();
1530
+ liveness.ensureAlive();
1479
1531
  if (input.getTurn() !== turn || turn.settled || turn.state.interruptRequested) {
1480
1532
  throw new Error("Cannot steer turn: the active ACP turn ended before steering was sent");
1481
1533
  }
@@ -1487,7 +1539,7 @@ function createAcpTurnControls(input) {
1487
1539
  generation: nextGeneration
1488
1540
  });
1489
1541
  }
1490
- input.ensureAlive();
1542
+ liveness.ensureAlive();
1491
1543
  if (input.getTurn() !== turn || turn.settled || turn.state.interruptRequested) {
1492
1544
  throw new Error("Cannot steer turn: the active ACP turn ended before steering was sent");
1493
1545
  }
@@ -1501,7 +1553,7 @@ function createAcpTurnControls(input) {
1501
1553
  prompt,
1502
1554
  turn,
1503
1555
  generation: nextGeneration,
1504
- ensureAlive: input.ensureAlive,
1556
+ liveness,
1505
1557
  ...input.config.usageInputIncludesCachedRead !== undefined && {
1506
1558
  usageInputIncludesCachedRead: input.config.usageInputIncludesCachedRead
1507
1559
  },
@@ -1515,16 +1567,16 @@ function createAcpTurnControls(input) {
1515
1567
 
1516
1568
  // src/agent-executor/acp/v1-session.ts
1517
1569
  function createAcpSessionClose(input) {
1518
- const { state, callerSignal, linked, externalPending } = input;
1570
+ const { state, liveness, linked, externalPending } = input;
1519
1571
  let closePromise;
1520
1572
  return () => {
1521
1573
  if (closePromise !== undefined)
1522
1574
  return closePromise;
1523
1575
  closePromise = (async () => {
1524
- const aborted = callerSignal?.aborted === true || linked.signal.aborted;
1525
- const alreadyTerminated = state.dead !== undefined || aborted;
1526
- const closeReason = state.dead ?? (callerSignal?.aborted ? abortReason(callerSignal) : linked.signal.aborted ? abortReason(linked.signal) : new Error("The ACP session is closing"));
1527
- state.closing = true;
1576
+ const terminated = liveness.terminated();
1577
+ const alreadyTerminated = terminated !== undefined;
1578
+ const closeReason = terminated === undefined ? new Error("The ACP session is closing") : terminated.reason;
1579
+ liveness.markClosing();
1528
1580
  const turn = state.current;
1529
1581
  state.current = undefined;
1530
1582
  settleAcpTurn(turn, closeReason, !alreadyTerminated);
@@ -1570,17 +1622,7 @@ async function openOrReopenAcpSession(input) {
1570
1622
  };
1571
1623
  }
1572
1624
  function buildAcpSession(input) {
1573
- const {
1574
- config,
1575
- connected,
1576
- sessionId,
1577
- callerSignal,
1578
- linked,
1579
- externalPending,
1580
- state,
1581
- ensureAlive,
1582
- stop
1583
- } = input;
1625
+ const { config, connected, sessionId, liveness, linked, externalPending, state, stop } = input;
1584
1626
  const { peer, initialized } = connected;
1585
1627
  const limits = {
1586
1628
  images: initialized.agentCapabilities?.promptCapabilities?.image === true,
@@ -1592,7 +1634,7 @@ function buildAcpSession(input) {
1592
1634
  peer,
1593
1635
  sessionId,
1594
1636
  limits,
1595
- ensureAlive,
1637
+ liveness,
1596
1638
  getTurn: () => state.current,
1597
1639
  setTurn: (turn) => {
1598
1640
  state.current = turn;
@@ -1602,20 +1644,21 @@ function buildAcpSession(input) {
1602
1644
  config,
1603
1645
  connected,
1604
1646
  sessionId,
1605
- callerSignal,
1647
+ liveness,
1606
1648
  linked,
1607
1649
  externalPending,
1608
1650
  state,
1609
1651
  stop
1610
1652
  });
1611
- ensureAlive();
1653
+ liveness.ensureAlive();
1612
1654
  state.opened = true;
1613
1655
  return {
1614
1656
  nativeThreadId: sessionId,
1615
1657
  get providerPid() {
1616
- return state.closing || state.dead !== undefined || callerSignal?.aborted === true || linked.signal.aborted ? undefined : state.livePid;
1658
+ return liveness.isAlive() ? state.livePid : undefined;
1617
1659
  },
1618
1660
  approvalEnforcement: "agent-initiated",
1661
+ initialized,
1619
1662
  get configOptions() {
1620
1663
  return state.configOptions;
1621
1664
  },
@@ -1626,13 +1669,18 @@ function buildAcpSession(input) {
1626
1669
  return state.commands;
1627
1670
  },
1628
1671
  async setConfigOption(configId, value) {
1629
- ensureAlive();
1672
+ liveness.ensureAlive();
1630
1673
  state.configOptions = await setAcpConfigOption(peer, sessionId, state.configOptions, configId, value, linked.signal);
1631
1674
  return state.configOptions;
1632
1675
  },
1633
1676
  async respond(interactionId, reply) {
1634
- ensureAlive();
1635
- answerAcpSessionRequest({ turn: state.current, externalPending, interactionId, reply });
1677
+ answerAcpSessionRequest({
1678
+ liveness,
1679
+ turn: state.current,
1680
+ externalPending,
1681
+ interactionId,
1682
+ reply
1683
+ });
1636
1684
  },
1637
1685
  ...turnControls,
1638
1686
  close
@@ -1646,8 +1694,6 @@ async function openAcpSession(config, input) {
1646
1694
  const state = {
1647
1695
  current: undefined,
1648
1696
  opened: false,
1649
- closing: false,
1650
- dead: undefined,
1651
1697
  livePid: undefined,
1652
1698
  pidNotified: false,
1653
1699
  configOptions: [],
@@ -1656,31 +1702,25 @@ async function openAcpSession(config, input) {
1656
1702
  commands: []
1657
1703
  };
1658
1704
  let connected;
1659
- const ensureAlive = () => {
1660
- if (state.closing)
1661
- throw new Error("The ACP session is closing");
1662
- if (state.dead !== undefined)
1663
- throw state.dead;
1664
- if (input.signal?.aborted)
1665
- throw abortReason(input.signal);
1666
- if (linked.signal.aborted)
1667
- throw abortReason(linked.signal);
1668
- };
1705
+ const liveness = sessionLiveness({
1706
+ closedMessage: "The ACP session is closing",
1707
+ caller: input.signal,
1708
+ linked: linked.signal
1709
+ });
1669
1710
  const recordPid = (pid) => {
1670
- if (pid === undefined || state.closing || state.dead !== undefined || input.signal?.aborted === true || linked.signal.aborted) {
1711
+ if (pid === undefined || !liveness.isAlive())
1671
1712
  return;
1672
- }
1673
1713
  state.livePid = pid;
1674
1714
  if (!state.pidNotified && config.onProviderPid !== undefined) {
1675
1715
  state.pidNotified = true;
1676
- invokeSafely(() => config.onProviderPid?.(pid));
1716
+ invokeObserver(config.onObserverError, "onProviderPid", () => config.onProviderPid?.(pid));
1677
1717
  }
1678
1718
  };
1679
1719
  try {
1680
1720
  connected = await connectAcp(config, input.profile, input.cwd, linked.signal, {
1681
1721
  ...createAcpHandlers({
1682
1722
  externalPending,
1683
- ensureAlive,
1723
+ liveness,
1684
1724
  isOpened: () => state.opened,
1685
1725
  getTurn: () => state.current,
1686
1726
  onSessionMeta(meta) {
@@ -1703,11 +1743,15 @@ async function openAcpSession(config, input) {
1703
1743
  ...config.permissionRequestDelivery !== undefined && {
1704
1744
  permissionRequestDelivery: config.permissionRequestDelivery
1705
1745
  },
1746
+ ...config.onObserverError !== undefined && {
1747
+ onObserverError: config.onObserverError
1748
+ },
1749
+ closingGracefully: () => liveness.closingGracefully,
1706
1750
  onEnd(error) {
1707
- const abortedByCaller = input.signal?.aborted === true;
1708
- const shouldNotify = state.opened && !state.closing && !abortedByCaller;
1709
- if (!state.closing && !abortedByCaller)
1710
- state.dead = error;
1751
+ const { abortedByCaller } = liveness;
1752
+ const shouldNotify = state.opened && !liveness.closing && !abortedByCaller;
1753
+ if (!liveness.closing && !abortedByCaller)
1754
+ liveness.markLost(error);
1711
1755
  state.livePid = undefined;
1712
1756
  const turn = state.current;
1713
1757
  state.current = undefined;
@@ -1715,13 +1759,13 @@ async function openAcpSession(config, input) {
1715
1759
  settleAcpTurn(turn, abortedByCaller && input.signal !== undefined ? abortReason(input.signal) : error, !abortedByCaller);
1716
1760
  linked.abort();
1717
1761
  if (shouldNotify)
1718
- invokeSafely(() => config.onDisconnect?.(error));
1762
+ invokeObserver(config.onObserverError, "onDisconnect", () => config.onDisconnect?.(error));
1719
1763
  }
1720
1764
  }),
1721
1765
  onProviderPid: recordPid,
1722
1766
  ...input.onStartupPhase !== undefined && { onStartupPhase: input.onStartupPhase }
1723
1767
  });
1724
- if (state.livePid === undefined && !state.closing && state.dead === undefined && input.signal?.aborted !== true && !linked.signal.aborted) {
1768
+ if (state.livePid === undefined && liveness.isAlive()) {
1725
1769
  recordPid(await connected.engine.pidReady ?? connected.engine.pid);
1726
1770
  }
1727
1771
  } catch (error) {
@@ -1730,8 +1774,8 @@ async function openAcpSession(config, input) {
1730
1774
  }
1731
1775
  const { peer, initialized } = connected;
1732
1776
  const stop = async (primary) => {
1733
- const terminated = state.dead !== undefined || input.signal?.aborted === true || linked.signal.aborted;
1734
- state.closing = true;
1777
+ const terminated = liveness.terminated() !== undefined;
1778
+ liveness.markClosing();
1735
1779
  state.livePid = undefined;
1736
1780
  if (terminated)
1737
1781
  externalPending.clear();
@@ -1773,11 +1817,10 @@ async function openAcpSession(config, input) {
1773
1817
  config,
1774
1818
  connected,
1775
1819
  sessionId,
1776
- callerSignal: input.signal,
1820
+ liveness,
1777
1821
  linked,
1778
1822
  externalPending,
1779
1823
  state,
1780
- ensureAlive,
1781
1824
  stop
1782
1825
  });
1783
1826
  } catch (error) {