@1agents/acp-service 0.8.3 → 0.9.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 (302) hide show
  1. package/README.md +25 -13
  2. package/dist/bin/a2a.js +16 -4
  3. package/dist/bin/acp-service.js +30 -0
  4. package/dist/bin/process.d.ts +4 -0
  5. package/dist/bin/process.js +57 -0
  6. package/dist/bin/roles.d.ts +1 -0
  7. package/dist/bin/roles.js +24 -0
  8. package/dist/bin/rsi.d.ts +3 -0
  9. package/dist/bin/rsi.js +114 -0
  10. package/dist/bin/ticket.d.ts +13 -0
  11. package/dist/bin/ticket.js +97 -0
  12. package/dist/bin/trail.d.ts +4 -0
  13. package/dist/bin/trail.js +62 -0
  14. package/dist/src/a2a/artifact-content.d.ts +9 -0
  15. package/dist/src/a2a/artifact-content.js +45 -0
  16. package/dist/src/a2a/desktop-notify.d.ts +1 -0
  17. package/dist/src/a2a/desktop-notify.js +12 -0
  18. package/dist/src/a2a/execution-binding.d.ts +9 -0
  19. package/dist/src/a2a/execution-binding.js +19 -0
  20. package/dist/src/a2a/executor.d.ts +22 -1
  21. package/dist/src/a2a/executor.js +308 -22
  22. package/dist/src/a2a/gateway.d.ts +613 -1
  23. package/dist/src/a2a/gateway.js +1337 -88
  24. package/dist/src/a2a/index.d.ts +14 -1
  25. package/dist/src/a2a/index.js +8 -0
  26. package/dist/src/a2a/job-directory.d.ts +6 -0
  27. package/dist/src/a2a/job-directory.js +19 -0
  28. package/dist/src/a2a/preflight.js +16 -1
  29. package/dist/src/a2a/resubmit.d.ts +46 -0
  30. package/dist/src/a2a/resubmit.js +82 -0
  31. package/dist/src/a2a/result-metadata.d.ts +6 -0
  32. package/dist/src/a2a/result-metadata.js +25 -6
  33. package/dist/src/a2a/server.d.ts +10 -0
  34. package/dist/src/a2a/server.js +127 -2
  35. package/dist/src/a2a/session-lifecycle.d.ts +40 -0
  36. package/dist/src/a2a/session-lifecycle.js +54 -0
  37. package/dist/src/a2a/store.d.ts +4 -0
  38. package/dist/src/a2a/store.js +76 -1
  39. package/dist/src/a2a/types.d.ts +77 -1
  40. package/dist/src/a2a/types.js +11 -1
  41. package/dist/src/a2a/workbench-ui.d.ts +28 -0
  42. package/dist/src/a2a/workbench-ui.js +182 -0
  43. package/dist/src/acp-connection.js +119 -14
  44. package/dist/src/bridge.d.ts +1 -0
  45. package/dist/src/bridge.js +312 -37
  46. package/dist/src/capacity-lifecycle.d.ts +5 -0
  47. package/dist/src/capacity-lifecycle.js +57 -0
  48. package/dist/src/capacity-queue.d.ts +58 -0
  49. package/dist/src/capacity-queue.js +388 -0
  50. package/dist/src/capacity.d.ts +101 -0
  51. package/dist/src/capacity.js +416 -0
  52. package/dist/src/dsh.js +1 -1
  53. package/dist/src/execution/agent-files.d.ts +25 -0
  54. package/dist/src/execution/agent-files.js +90 -0
  55. package/dist/src/execution/agent-registry.d.ts +164 -0
  56. package/dist/src/execution/agent-registry.js +275 -0
  57. package/dist/src/execution/human-review.d.ts +105 -0
  58. package/dist/src/execution/human-review.js +89 -0
  59. package/dist/src/execution/ledger.d.ts +57 -0
  60. package/dist/src/execution/ledger.js +122 -13
  61. package/dist/src/execution/ppt-delivery.d.ts +36 -3
  62. package/dist/src/execution/ppt-delivery.js +243 -53
  63. package/dist/src/execution/process-request.d.ts +151 -0
  64. package/dist/src/execution/process-request.js +177 -0
  65. package/dist/src/execution/project-discovery.d.ts +56 -0
  66. package/dist/src/execution/project-discovery.js +429 -0
  67. package/dist/src/execution/report-review.d.ts +60 -0
  68. package/dist/src/execution/report-review.js +173 -0
  69. package/dist/src/execution/targets.d.ts +20 -0
  70. package/dist/src/execution/targets.js +23 -3
  71. package/dist/src/execution/ticket-executor.d.ts +25 -0
  72. package/dist/src/execution/ticket-executor.js +27 -0
  73. package/dist/src/execution/ticket.d.ts +326 -0
  74. package/dist/src/execution/ticket.js +301 -0
  75. package/dist/src/execution/workbench-chat.d.ts +25 -0
  76. package/dist/src/execution/workbench-chat.js +54 -0
  77. package/dist/src/execution/workbench.d.ts +162 -0
  78. package/dist/src/execution/workbench.js +356 -0
  79. package/dist/src/index.d.ts +4 -0
  80. package/dist/src/index.js +3 -0
  81. package/dist/src/roles/index.d.ts +1 -0
  82. package/dist/src/roles/index.js +1 -0
  83. package/dist/src/roles/skills.d.ts +71 -0
  84. package/dist/src/roles/skills.js +427 -0
  85. package/dist/src/rsi/gate.d.ts +25 -0
  86. package/dist/src/rsi/gate.js +59 -0
  87. package/dist/src/rsi/outline-run.d.ts +107 -0
  88. package/dist/src/rsi/outline-run.js +443 -0
  89. package/dist/workbench-ui/app.css +453 -0
  90. package/dist/workbench-ui/app.js +13 -0
  91. package/dist/workbench-ui/chunk-23JHGYT3.js +1 -0
  92. package/dist/workbench-ui/chunk-3H6STGPV.js +1 -0
  93. package/dist/workbench-ui/chunk-3SNBBMGH.js +1 -0
  94. package/dist/workbench-ui/chunk-3XJZ6DIE.js +1 -0
  95. package/dist/workbench-ui/chunk-44KDLLKJ.js +1 -0
  96. package/dist/workbench-ui/chunk-46H7FU5Y.js +7 -0
  97. package/dist/workbench-ui/chunk-4N44QPL7.js +1 -0
  98. package/dist/workbench-ui/chunk-4YN4BS7I.js +1 -0
  99. package/dist/workbench-ui/chunk-53EG4IVQ.js +96 -0
  100. package/dist/workbench-ui/chunk-5FIPUNR4.js +1 -0
  101. package/dist/workbench-ui/chunk-6DWWYA6G.js +2 -0
  102. package/dist/workbench-ui/chunk-6FU3T633.js +99 -0
  103. package/dist/workbench-ui/chunk-6XKIHRA4.js +1 -0
  104. package/dist/workbench-ui/chunk-7GIX43Y5.js +1 -0
  105. package/dist/workbench-ui/chunk-7Q4WBGX6.js +4 -0
  106. package/dist/workbench-ui/chunk-A3BQM7HR.js +1 -0
  107. package/dist/workbench-ui/chunk-AFCFDDOP.js +24 -0
  108. package/dist/workbench-ui/chunk-AG67EUYD.js +89 -0
  109. package/dist/workbench-ui/chunk-AGJHMMTN.js +1 -0
  110. package/dist/workbench-ui/chunk-AO6JUBV6.js +41 -0
  111. package/dist/workbench-ui/chunk-AUSLTP43.js +72 -0
  112. package/dist/workbench-ui/chunk-AVZL46TT.js +1 -0
  113. package/dist/workbench-ui/chunk-AZRIGIV2.js +168 -0
  114. package/dist/workbench-ui/chunk-B2LIVH37.js +1 -0
  115. package/dist/workbench-ui/chunk-B7YX5TR5.js +1 -0
  116. package/dist/workbench-ui/chunk-BCB4X4XX.js +1 -0
  117. package/dist/workbench-ui/chunk-BCRQUL2A.js +88 -0
  118. package/dist/workbench-ui/chunk-BI6UHHQP.js +1 -0
  119. package/dist/workbench-ui/chunk-BLSLQ4AQ.js +120 -0
  120. package/dist/workbench-ui/chunk-C3QSRS6E.js +1 -0
  121. package/dist/workbench-ui/chunk-CK7M2PJ3.js +62 -0
  122. package/dist/workbench-ui/chunk-CM6LZ7TU.js +1 -0
  123. package/dist/workbench-ui/chunk-CP63H27F.js +36 -0
  124. package/dist/workbench-ui/chunk-CPUMMIS2.js +70 -0
  125. package/dist/workbench-ui/chunk-CSEIBI5U.js +2 -0
  126. package/dist/workbench-ui/chunk-CUS65DKZ.js +161 -0
  127. package/dist/workbench-ui/chunk-CVQY7TNC.js +1 -0
  128. package/dist/workbench-ui/chunk-D6S3XBIX.js +106 -0
  129. package/dist/workbench-ui/chunk-E253Y562.js +1 -0
  130. package/dist/workbench-ui/chunk-EADDJUDC.js +1 -0
  131. package/dist/workbench-ui/chunk-EBGJ3YXG.js +206 -0
  132. package/dist/workbench-ui/chunk-EKPVZ3WY.js +8 -0
  133. package/dist/workbench-ui/chunk-EQDCEAFY.js +1 -0
  134. package/dist/workbench-ui/chunk-ES3SSDJY.js +40 -0
  135. package/dist/workbench-ui/chunk-ESFD2H7N.js +231 -0
  136. package/dist/workbench-ui/chunk-FVOHPMS6.js +1 -0
  137. package/dist/workbench-ui/chunk-FXMQAGVT.js +1 -0
  138. package/dist/workbench-ui/chunk-GGTADRXD.js +24 -0
  139. package/dist/workbench-ui/chunk-GHIVPGNQ.js +1 -0
  140. package/dist/workbench-ui/chunk-GLU2YQV2.js +1 -0
  141. package/dist/workbench-ui/chunk-GOCKBYSM.js +1 -0
  142. package/dist/workbench-ui/chunk-H2KMMTJB.js +1 -0
  143. package/dist/workbench-ui/chunk-HGVLDNPP.js +39 -0
  144. package/dist/workbench-ui/chunk-HSAVC5GY.js +1 -0
  145. package/dist/workbench-ui/chunk-HSEAD2JH.js +1 -0
  146. package/dist/workbench-ui/chunk-HSIHOBTY.js +1 -0
  147. package/dist/workbench-ui/chunk-IZXOKUGG.js +67 -0
  148. package/dist/workbench-ui/chunk-JFT2LC2T.js +1 -0
  149. package/dist/workbench-ui/chunk-JHL3ZDYK.js +3 -0
  150. package/dist/workbench-ui/chunk-JMORLCZG.js +257 -0
  151. package/dist/workbench-ui/chunk-JR4SIX7A.js +1 -0
  152. package/dist/workbench-ui/chunk-K23HAGEH.js +30 -0
  153. package/dist/workbench-ui/chunk-K43JDCBH.js +1 -0
  154. package/dist/workbench-ui/chunk-KINKFJY7.js +1 -0
  155. package/dist/workbench-ui/chunk-KKQSA4LI.js +2 -0
  156. package/dist/workbench-ui/chunk-KOUZX3UX.js +1 -0
  157. package/dist/workbench-ui/chunk-KR4DRHW2.js +78 -0
  158. package/dist/workbench-ui/chunk-KT4DJNOR.js +1 -0
  159. package/dist/workbench-ui/chunk-KTPNKRRZ.js +292 -0
  160. package/dist/workbench-ui/chunk-LFHIPGSU.js +7 -0
  161. package/dist/workbench-ui/chunk-LWDL4HZB.js +125 -0
  162. package/dist/workbench-ui/chunk-MVYC3CY4.js +1 -0
  163. package/dist/workbench-ui/chunk-NWUPALCY.js +129 -0
  164. package/dist/workbench-ui/chunk-NY7C662Z.js +1 -0
  165. package/dist/workbench-ui/chunk-O76WTHWP.js +1 -0
  166. package/dist/workbench-ui/chunk-OTF7YHRE.js +162 -0
  167. package/dist/workbench-ui/chunk-P6TKKRKP.js +1 -0
  168. package/dist/workbench-ui/chunk-PFHOOWV3.js +1 -0
  169. package/dist/workbench-ui/chunk-PUQLANIM.js +1 -0
  170. package/dist/workbench-ui/chunk-PZCGBYVO.js +1 -0
  171. package/dist/workbench-ui/chunk-QOHUZGP4.js +1 -0
  172. package/dist/workbench-ui/chunk-QSEG3OFF.js +1 -0
  173. package/dist/workbench-ui/chunk-QYPOXZIA.js +84 -0
  174. package/dist/workbench-ui/chunk-R6SOF3JC.js +1 -0
  175. package/dist/workbench-ui/chunk-RCLOYU5F.js +1 -0
  176. package/dist/workbench-ui/chunk-RSRUP64S.js +1 -0
  177. package/dist/workbench-ui/chunk-RVAIT6JW.js +1 -0
  178. package/dist/workbench-ui/chunk-S2CCN3II.js +1 -0
  179. package/dist/workbench-ui/chunk-S2Q52W46.js +1 -0
  180. package/dist/workbench-ui/chunk-S2W5THJ5.js +1 -0
  181. package/dist/workbench-ui/chunk-S6ZQZNOX.js +1 -0
  182. package/dist/workbench-ui/chunk-S74PLMMS.js +1 -0
  183. package/dist/workbench-ui/chunk-S7C4HKEY.js +1 -0
  184. package/dist/workbench-ui/chunk-SDTB3Q65.js +1 -0
  185. package/dist/workbench-ui/chunk-SLPRGYUV.js +32 -0
  186. package/dist/workbench-ui/chunk-SQE76S5B.js +1 -0
  187. package/dist/workbench-ui/chunk-SSDZPVPW.js +1 -0
  188. package/dist/workbench-ui/chunk-SVI7DGIE.js +1 -0
  189. package/dist/workbench-ui/chunk-T6QKLZ4H.js +62 -0
  190. package/dist/workbench-ui/chunk-TJNRPTFL.js +1 -0
  191. package/dist/workbench-ui/chunk-TP6U4EDH.js +2 -0
  192. package/dist/workbench-ui/chunk-TYAAT3GQ.js +1 -0
  193. package/dist/workbench-ui/chunk-U6OCY4ZH.js +1 -0
  194. package/dist/workbench-ui/chunk-UAN3NLRF.js +1 -0
  195. package/dist/workbench-ui/chunk-UMLU3FIX.js +1 -0
  196. package/dist/workbench-ui/chunk-URIY2OTM.js +1 -0
  197. package/dist/workbench-ui/chunk-V2NUKAA7.js +38 -0
  198. package/dist/workbench-ui/chunk-V4QLL4TE.js +139 -0
  199. package/dist/workbench-ui/chunk-VASHXUK4.js +2 -0
  200. package/dist/workbench-ui/chunk-VJLIWNIU.js +1 -0
  201. package/dist/workbench-ui/chunk-VQNQFBID.js +1 -0
  202. package/dist/workbench-ui/chunk-VSIWU7XA.js +3 -0
  203. package/dist/workbench-ui/chunk-VSJASPUZ.js +321 -0
  204. package/dist/workbench-ui/chunk-VXPNUNUX.js +3 -0
  205. package/dist/workbench-ui/chunk-WBKLDCV6.js +1 -0
  206. package/dist/workbench-ui/chunk-WOKJM3FY.js +1 -0
  207. package/dist/workbench-ui/chunk-X3U3NA3X.js +34 -0
  208. package/dist/workbench-ui/chunk-XBYU7M4J.js +1 -0
  209. package/dist/workbench-ui/chunk-XBZAO4ID.js +10 -0
  210. package/dist/workbench-ui/chunk-XLLPZ2WO.js +1 -0
  211. package/dist/workbench-ui/chunk-YFVL4NJL.js +1 -0
  212. package/dist/workbench-ui/chunk-YRFQENM4.js +1 -0
  213. package/dist/workbench-ui/chunk-YUADQVB2.js +1 -0
  214. package/dist/workbench-ui/chunk-Z3TCAKM5.js +1 -0
  215. package/dist/workbench-ui/chunk-Z6QR6FRE.js +10 -0
  216. package/dist/workbench-ui/chunk-ZJPSORPP.js +3 -0
  217. package/dist/workbench-ui/chunk-ZLGCSTR2.js +15 -0
  218. package/dist/workbench-ui/chunk-ZLR4SG5X.js +1 -0
  219. package/dist/workbench-ui/chunk-ZND3TTGF.js +1 -0
  220. package/dist/workbench-ui/chunk-ZOP3ZYH7.js +2 -0
  221. package/dist/workbench-ui/index.html +14 -0
  222. package/package.json +23 -8
  223. package/skills/acp-service/SKILL.md +24 -8
  224. package/skills/acp-service/references/a2a.md +24 -8
  225. package/skills/acp-service/references/async-caller.md +48 -0
  226. package/skills/acp-service/references/dsh.md +2 -0
  227. package/skills/acp-service/references/roles-and-tasks.md +120 -0
  228. package/skills/acp-service/scripts/a2a-caller.py +242 -0
  229. package/skills/rsi-coach/SKILL.md +134 -0
  230. package/vendor/dsh/README.md +11 -5
  231. package/vendor/dsh/a2a-executor.d.ts +60 -3
  232. package/vendor/dsh/a2a-executor.js +208 -18
  233. package/vendor/dsh/a2a.d.ts +12 -2
  234. package/vendor/dsh/a2a.js +9 -2
  235. package/vendor/dsh/adapter.d.ts +61 -2
  236. package/vendor/dsh/adapter.js +354 -23
  237. package/vendor/dsh/client.js +67 -11
  238. package/vendor/dsh/index.js +57 -4
  239. package/vendor/dsh/native-approvals.d.ts +4 -0
  240. package/vendor/dsh/native-approvals.js +44 -0
  241. package/vendor/dsh/preset-route.d.ts +49 -0
  242. package/vendor/dsh/preset-route.js +51 -0
  243. package/vendor/dsh/preset.js +10 -3
  244. package/vendor/dsh/process-admission.d.ts +25 -0
  245. package/vendor/dsh/process-admission.js +87 -0
  246. package/vendor/dsh/process-requests.d.ts +57 -0
  247. package/vendor/dsh/process-requests.js +49 -0
  248. package/vendor/dsh/review-mcp.d.ts +1 -0
  249. package/vendor/dsh/review-mcp.js +56 -0
  250. package/vendor/dsh/review.d.ts +30 -0
  251. package/vendor/dsh/review.js +149 -0
  252. package/vendor/dsh/session-settings.d.ts +34 -0
  253. package/vendor/dsh/session-settings.js +114 -0
  254. package/vendor/dsh/ticket-spec.d.ts +30 -0
  255. package/vendor/dsh/ticket-spec.js +10 -0
  256. package/vendor/dsh/ticket-tools.d.ts +21 -0
  257. package/vendor/dsh/ticket-tools.js +43 -0
  258. package/vendor/dsh/workbench.d.ts +18 -0
  259. package/vendor/dsh/workbench.js +91 -0
  260. package/vendor/runtime/README.md +6 -4
  261. package/vendor/runtime/dist/{cli-DeOpE2Xz.js → cli-DXmYwv3U.js} +4 -4
  262. package/vendor/runtime/dist/{cli-DeOpE2Xz.js.map → cli-DXmYwv3U.js.map} +1 -1
  263. package/vendor/runtime/dist/cli.js +7 -7
  264. package/vendor/runtime/dist/client-VQsqcIOJ.d.ts.map +1 -1
  265. package/vendor/runtime/dist/docs-site/CLI.html +2 -2
  266. package/vendor/runtime/dist/docs-site/VISION.html +2 -2
  267. package/vendor/runtime/dist/docs-site/agents.html +2 -2
  268. package/vendor/runtime/dist/docs-site/compare.html +2 -2
  269. package/vendor/runtime/dist/docs-site/config.html +2 -2
  270. package/vendor/runtime/dist/docs-site/custom-agents.html +2 -2
  271. package/vendor/runtime/dist/docs-site/exit-codes.html +2 -2
  272. package/vendor/runtime/dist/docs-site/flows.html +2 -2
  273. package/vendor/runtime/dist/docs-site/index.html +1 -1
  274. package/vendor/runtime/dist/docs-site/install.html +2 -2
  275. package/vendor/runtime/dist/docs-site/llms.txt +1 -1
  276. package/vendor/runtime/dist/docs-site/output-formats.html +2 -2
  277. package/vendor/runtime/dist/docs-site/permissions.html +2 -2
  278. package/vendor/runtime/dist/docs-site/prompting.html +2 -2
  279. package/vendor/runtime/dist/docs-site/quickstart.html +2 -2
  280. package/vendor/runtime/dist/docs-site/releasing.html +2 -2
  281. package/vendor/runtime/dist/docs-site/runtime-environment.html +2 -2
  282. package/vendor/runtime/dist/docs-site/runtime-process-lifecycle.html +3 -2
  283. package/vendor/runtime/dist/docs-site/safe-errors.html +2 -2
  284. package/vendor/runtime/dist/docs-site/session-control.html +2 -2
  285. package/vendor/runtime/dist/docs-site/session-watch.html +2 -2
  286. package/vendor/runtime/dist/docs-site/sessions.html +2 -2
  287. package/vendor/runtime/dist/docs-site/shared-sessions.html +2 -2
  288. package/vendor/runtime/dist/{flows-oaBGn31w.js → flows-DJ17ajbw.js} +3 -3
  289. package/vendor/runtime/dist/{flows-oaBGn31w.js.map → flows-DJ17ajbw.js.map} +1 -1
  290. package/vendor/runtime/dist/flows.js +1 -1
  291. package/vendor/runtime/dist/{invocation-options-CUDEE8vW.js → invocation-options-PBfCgrdi.js} +3 -3
  292. package/vendor/runtime/dist/{invocation-options-CUDEE8vW.js.map → invocation-options-PBfCgrdi.js.map} +1 -1
  293. package/vendor/runtime/dist/{output-CFv3jcOQ.js → output-B3MDn7kv.js} +2 -2
  294. package/vendor/runtime/dist/{output-CFv3jcOQ.js.map → output-B3MDn7kv.js.map} +1 -1
  295. package/vendor/runtime/dist/{queue-owner-runtime-DvMJiGbP.js → queue-owner-runtime-DXCVngwU.js} +15 -8
  296. package/vendor/runtime/dist/queue-owner-runtime-DXCVngwU.js.map +1 -0
  297. package/vendor/runtime/dist/runtime.js +1 -1
  298. package/vendor/runtime/dist/{session-watch-Di-wIdCH.js → session-watch-DURyCw31.js} +2 -2
  299. package/vendor/runtime/dist/{session-watch-Di-wIdCH.js.map → session-watch-DURyCw31.js.map} +1 -1
  300. package/vendor/runtime/package.json +6 -4
  301. package/vendor/runtime/skills/acpx/SKILL.md +2 -0
  302. package/vendor/runtime/dist/queue-owner-runtime-DvMJiGbP.js.map +0 -1
@@ -1,13 +1,37 @@
1
1
  /** Presents an external Agent's output through DSH's existing streaming surface. */
2
2
  import { createHash } from 'node:crypto';
3
3
  import { randomUUID } from 'node:crypto';
4
+ import { isAbsolute, resolve } from 'node:path';
4
5
  import { setTimeout as delay } from 'node:timers/promises';
5
6
  import { LlmError } from '@deepseek-ai/dsh-llm';
6
7
  import { RequestError } from '@agentclientprotocol/sdk';
7
8
  import { connect, object } from './transport.js';
8
9
  import { State, hasActiveWriter } from './state.js';
9
10
  import { mergeTool } from './tool-events.js';
11
+ import { currentA2AExecution } from '@1agents/acp-service/a2a';
10
12
  import { toSafeError } from '@1agents/acp-service/runtime';
13
+ import { capacityPendingOf, noteProcessCapacity, noteProcessReady, noteSessionRestore, requestWhenAdmitted } from './process-admission.js';
14
+ import { AgentSessionSettings, pinnedModeError, pinnedOptionError, replayPinnedOptions } from './session-settings.js';
15
+ export function validateSessionPolicies(policies = []) {
16
+ const seen = new Set();
17
+ if (!Array.isArray(policies))
18
+ throw new Error('sessionPolicies must be an array');
19
+ return policies.map(policy => {
20
+ if (!policy || typeof policy.cwd !== 'string' || !isAbsolute(policy.cwd)
21
+ || typeof policy.agent !== 'string' || !/^[a-z0-9_-]+$/i.test(policy.agent)
22
+ || (policy.permissionMode !== undefined && !['approve-reads', 'approve-all', 'deny-all'].includes(policy.permissionMode))
23
+ || (policy.initialModeId !== undefined && (typeof policy.initialModeId !== 'string' || !policy.initialModeId))) {
24
+ throw new Error('Invalid workspace-scoped ACP session policy');
25
+ }
26
+ const normalized = { ...policy, cwd: resolve(policy.cwd) };
27
+ const key = JSON.stringify([normalized.cwd, normalized.agent]);
28
+ if (seen.has(key))
29
+ throw new Error('Duplicate workspace-scoped ACP session policy');
30
+ seen.add(key);
31
+ return normalized;
32
+ });
33
+ }
34
+ const recoveryMessage = 'ACP session initialization failed and remote cleanup could not be confirmed; host recovery is required before retrying.';
11
35
  /** Only the negotiated service's direct canonical error data is a projection. */
12
36
  function serviceProjection(error) {
13
37
  if (!(error instanceof RequestError) || error.code !== -32000
@@ -23,6 +47,12 @@ function serviceProjection(error) {
23
47
  return data;
24
48
  }
25
49
  /** Only actual cancellation rejections may replace a racing provider failure. */
50
+ function isDeletedAcpSession(error) {
51
+ if (!error || typeof error !== 'object')
52
+ return false;
53
+ const value = error;
54
+ return value.code === -32003 || value.message === 'Session was deleted';
55
+ }
26
56
  function isCancellationRejection(error, signal) {
27
57
  if (!signal.aborted)
28
58
  return false;
@@ -64,11 +94,24 @@ class Queue {
64
94
  }
65
95
  }
66
96
  }
97
+ function acpFromProcessView(kind, view) {
98
+ const outcome = view.answer?.outcome;
99
+ const closed = view.status === 'expired' || view.status === 'cancelled' || outcome === 'cancelled' || outcome === 'abandoned';
100
+ if (kind === 'permission')
101
+ return { outcome: !closed && (outcome === 'approved' || outcome === 'rejected') ? outcome : 'cancelled' };
102
+ if (kind === 'plan')
103
+ return { outcome: !closed && (outcome === 'approved' || outcome === 'rejected') ? outcome : 'abandoned' };
104
+ if (!closed && outcome === 'accepted' && view.answer?.answers)
105
+ return { outcome: 'accepted', answers: view.answer.answers };
106
+ return { outcome: 'cancelled' };
107
+ }
67
108
  export class AcpAdapter {
68
109
  ctx;
69
110
  config;
70
111
  diagnostics;
112
+ processRequests;
71
113
  state;
114
+ initializationFailures = new Map();
72
115
  controllers = new Map();
73
116
  jobs = new Set();
74
117
  links = new Map();
@@ -79,15 +122,24 @@ export class AcpAdapter {
79
122
  commandDisposers = new Map();
80
123
  output = new Map();
81
124
  lifetime = new AbortController();
82
- constructor(ctx, config, diagnostics) {
125
+ sessionSettings;
126
+ /** MCP servers offered when a session is created or restored, such as the A2A hand-back tool. */
127
+ mcpServersFor;
128
+ constructor(ctx, config, diagnostics, processRequests) {
83
129
  this.ctx = ctx;
84
130
  this.config = config;
85
131
  this.diagnostics = diagnostics;
132
+ this.processRequests = processRequests;
86
133
  this.state = new State(config.stateDirectory);
134
+ this.sessionSettings = new AgentSessionSettings(config.stateDirectory);
87
135
  }
88
136
  providerInfo(provider) { return { id: provider, name: 'ACP Agents' }; }
89
137
  providerRetryPolicy() { return { mode: 'normal', maxRetries: 0, retryableCodes: [], initialDelayMs: 1000, maxDelayMs: 1000, jitterRatio: 0 }; }
90
138
  imageRequestPricing() { return undefined; }
139
+ /** DSH 0.2.1 requires this. ACP Agents take text only, so keep the base class's untouched image target. */
140
+ imageRequestTarget(_provider, _model, image) {
141
+ return { width: image.width, height: image.height, maxBytes: image.bytes };
142
+ }
91
143
  async listModels(provider) {
92
144
  return [];
93
145
  }
@@ -140,11 +192,15 @@ export class AcpAdapter {
140
192
  const link = await this.connection(agent);
141
193
  const sessionId = this.state.get(agent.id).sessionId;
142
194
  const capabilities = this.capabilities.get(agent.id);
195
+ const name = this.agentName(agent);
196
+ const cwd = agent.session.header.cwd;
143
197
  if (configId === '$mode') {
144
198
  if (!capabilities.modes?.availableModes.some(m => m.id === value))
145
199
  throw new Error('Unknown ACP mode');
146
200
  await link.rpc.request('session/set_mode', { sessionId, modeId: value });
147
201
  capabilities.modes.currentModeId = value;
202
+ if (name && cwd)
203
+ this.sessionSettings.remember(cwd, name, { modeId: value });
148
204
  }
149
205
  else {
150
206
  const option = capabilities.configOptions.find(o => o.id === configId);
@@ -152,6 +208,8 @@ export class AcpAdapter {
152
208
  throw new Error('Unknown ACP configuration');
153
209
  const result = await link.rpc.request('session/set_config_option', { sessionId, configId, value });
154
210
  capabilities.configOptions = result.configOptions;
211
+ if (name && cwd)
212
+ this.sessionSettings.remember(cwd, name, { option: { id: configId, value, ...(option.category === 'model' || option.id === 'model' ? { model: true } : {}) } });
155
213
  }
156
214
  return capabilities;
157
215
  }
@@ -174,10 +232,18 @@ export class AcpAdapter {
174
232
  plan: async () => ({ outcome: 'abandoned' }),
175
233
  }, this.lifetime.signal);
176
234
  try {
177
- const result = object(await link.rpc.request('_1agents/session/import', {
178
- sessionId: nativeSessionId, cwd, mcpServers: [],
179
- _meta: { '1agents': { permissionMode: 'approve-reads' } },
180
- }, { cancellationSignal: AbortSignal.any([this.lifetime.signal, AbortSignal.timeout(60_000)]) }));
235
+ const capacityId = `import:${nativeSessionId}`;
236
+ const result = object(await requestWhenAdmitted({
237
+ signal: this.lifetime.signal,
238
+ isPending: capacityPendingOf,
239
+ cancel: async () => { await link.rpc.request('_1agents/capacity/cancel', { capacityId }).catch(() => undefined); },
240
+ request: () => link.rpc.request('_1agents/session/import', {
241
+ sessionId: nativeSessionId, cwd, mcpServers: [],
242
+ // Bridge permissionMode is not sent. The imported session keeps the
243
+ // Agent's own mode and config options (ACP 设置).
244
+ _meta: { '1agents': { capacityId } },
245
+ }, { cancellationSignal: AbortSignal.any([this.lifetime.signal, AbortSignal.timeout(60_000)]) }),
246
+ }));
181
247
  if (typeof result.sessionId !== 'string' || !result.sessionId)
182
248
  throw new Error('ACP import returned no service session ID');
183
249
  return { agent: name, cwd, endpoint: endpoint.href, sessionId: result.sessionId, restoreMethod: 'session/resume' };
@@ -218,9 +284,33 @@ export class AcpAdapter {
218
284
  }));
219
285
  }
220
286
  }
221
- async connection(agent) {
287
+ /** Replay this Agent's own accepted values. Another Agent's catalog is never consulted. */
288
+ async applyPinnedSettings(name, cwd, link, sessionId, capabilities, policy, cancellationSignal) {
289
+ const pinned = this.sessionSettings.get(cwd, name);
290
+ let advertised = capabilities.configOptions;
291
+ for (const option of replayPinnedOptions(pinned?.options ?? [])) {
292
+ const mismatch = pinnedOptionError(name, option, advertised);
293
+ if (mismatch)
294
+ throw new Error(mismatch);
295
+ const next = await link.rpc.request('session/set_config_option', { sessionId, configId: option.id, value: option.value }, { cancellationSignal });
296
+ advertised = next.configOptions ?? [];
297
+ capabilities.configOptions = advertised;
298
+ }
299
+ const modeId = pinned?.modeId ?? policy?.initialModeId;
300
+ if (!modeId)
301
+ return;
302
+ const mismatch = pinned?.modeId
303
+ ? pinnedModeError(name, modeId, capabilities.modes?.availableModes)
304
+ : capabilities.modes?.availableModes.some(mode => mode.id === modeId) ? undefined : 'Configured initial ACP mode is not advertised by the Agent';
305
+ if (mismatch)
306
+ throw new Error(mismatch);
307
+ await link.rpc.request('session/set_mode', { sessionId, modeId }, { cancellationSignal });
308
+ if (capabilities.modes)
309
+ capabilities.modes.currentModeId = modeId;
310
+ }
311
+ async connection(agent, capacityId, callerSignal) {
222
312
  const operation = (this.connections.get(agent.id) ?? Promise.resolve())
223
- .catch(() => undefined).then(() => this.openConnection(agent));
313
+ .catch(() => undefined).then(() => this.openConnection(agent, capacityId, callerSignal));
224
314
  this.connections.set(agent.id, operation);
225
315
  try {
226
316
  return await operation;
@@ -230,7 +320,7 @@ export class AcpAdapter {
230
320
  this.connections.delete(agent.id);
231
321
  }
232
322
  }
233
- async openConnection(agent) {
323
+ async openConnection(agent, capacityId, callerSignal) {
234
324
  const name = this.agentName(agent);
235
325
  if (!name)
236
326
  throw new Error('ACP is available only in an ACP Agent preset; start a new ACP session');
@@ -239,7 +329,12 @@ export class AcpAdapter {
239
329
  throw new Error('Create the ACP session in a workspace first');
240
330
  const endpoint = new URL(`/agents/${encodeURIComponent(name)}`, this.config.serviceUrl);
241
331
  endpoint.protocol = endpoint.protocol === 'https:' ? 'wss:' : 'ws:';
332
+ const initializationFailure = this.initializationFailures.get(agent.id);
333
+ if (initializationFailure)
334
+ throw initializationFailure;
242
335
  let binding = this.state.get(agent.id);
336
+ if (binding && 'initializationCleanupPending' in binding)
337
+ throw new Error(recoveryMessage);
243
338
  if (binding && (binding.agent !== name || binding.cwd !== cwd || binding.endpoint !== endpoint.href)) {
244
339
  const boundary = this.ctx.sessionProjections.stateOf(agent.session, 'turnBoundary');
245
340
  const previousEndpoint = new URL(`/agents/${encodeURIComponent(binding.agent)}`, this.config.serviceUrl);
@@ -317,23 +412,80 @@ export class AcpAdapter {
317
412
  question: (p, s) => this.question(agent, p, interactionSignal(s)),
318
413
  plan: (p, s) => this.plan(agent, p, interactionSignal(s)),
319
414
  }, this.lifetime.signal);
415
+ let createdBinding;
320
416
  try {
321
- const params = { cwd, mcpServers: [], _meta: { '1agents': { permissionMode: 'approve-reads' } } };
322
- const cancellationSignal = AbortSignal.any([this.lifetime.signal, AbortSignal.timeout(60_000)]);
417
+ const policy = this.config.sessionPolicies?.find(p => p.cwd === resolve(cwd) && p.agent === name);
418
+ // Bridge permissionMode (approve-reads / approve-all / deny-all) is not
419
+ // sent. Mode and reasoning effort come from ACP 设置: session/set_mode,
420
+ // session/set_config_option, or the settings kept by a native import.
421
+ // initialModeId below still selects an advertised native mode.
422
+ const params = { cwd, mcpServers: this.mcpServersFor?.(agent.id) ?? [], ...(capacityId ? { _meta: { '1agents': { capacityId } } } : {}) };
423
+ const admit = (request) => capacityId
424
+ ? requestWhenAdmitted({
425
+ request,
426
+ signal: callerSignal ? AbortSignal.any([this.lifetime.signal, callerSignal]) : this.lifetime.signal,
427
+ isPending: capacityPendingOf,
428
+ onPending: pending => noteProcessCapacity(agent.id, pending),
429
+ cancel: async () => { await link.rpc.request('_1agents/capacity/cancel', { capacityId }).catch(() => undefined); },
430
+ })
431
+ : request();
432
+ // Queue waits return immediately. This 60s bound covers only the attempt that holds the slot.
433
+ const handshake = () => AbortSignal.any([this.lifetime.signal, AbortSignal.timeout(60_000), ...(callerSignal ? [callerSignal] : [])]);
434
+ const restoreMethod = binding ? binding.restoreMethod ?? 'session/load' : undefined;
323
435
  const result = binding
324
- ? await link.rpc.request(binding.restoreMethod ?? 'session/load', { ...params, sessionId: binding.sessionId }, { cancellationSignal })
325
- : await link.rpc.request('session/new', params, { cancellationSignal });
436
+ ? await admit(() => link.rpc.request(restoreMethod, { ...params, sessionId: binding.sessionId }, { cancellationSignal: handshake() }))
437
+ : await admit(() => link.rpc.request('session/new', params, { cancellationSignal: handshake() }));
438
+ if (binding && restoreMethod)
439
+ noteSessionRestore(agent.id, restoreMethod);
326
440
  if (!binding)
327
- this.state.save(agent.id, { agent: name, endpoint: endpoint.href, cwd, sessionId: result.sessionId });
441
+ createdBinding = { agent: name, endpoint: endpoint.href, cwd, sessionId: result.sessionId };
328
442
  capabilities.configOptions = result.configOptions ?? capabilities.configOptions;
329
443
  capabilities.modes = result.modes ?? undefined;
444
+ // A new session replays only this Agent's accepted settings. Loading an
445
+ // existing session keeps the mode and options already on that session.
446
+ if (!binding)
447
+ await this.applyPinnedSettings(name, resolve(cwd), link, result.sessionId, capabilities, policy, handshake());
448
+ if (createdBinding)
449
+ this.state.save(agent.id, createdBinding);
330
450
  void link.closed.then(() => { if (this.links.get(agent.id) === operation)
331
451
  this.links.delete(agent.id); });
332
452
  return link;
333
453
  }
334
454
  catch (error) {
455
+ if (binding && isDeletedAcpSession(error)) {
456
+ link.close();
457
+ const deleted = new LlmError('Session was deleted', 'SESSION_DELETED');
458
+ // The stream catch replaces unowned errors with ACP_TURN_FAILED. Keep this code.
459
+ ownedFailures.set(deleted, toSafeError(deleted, { origin: 'acp', outcomeUnknown: false }));
460
+ throw deleted;
461
+ }
462
+ let failure = error;
463
+ if (createdBinding) {
464
+ const cleanup = new AbortController();
465
+ try {
466
+ // SDK cancellation alone only notifies the peer, so bound the wait locally as well.
467
+ await Promise.race([
468
+ link.rpc.request('session/close', { sessionId: createdBinding.sessionId }, { cancellationSignal: cleanup.signal }),
469
+ delay(5000, undefined, { signal: cleanup.signal }).then(() => { throw new Error(recoveryMessage); }),
470
+ ]);
471
+ }
472
+ catch {
473
+ // Preserve a recovery identity rather than create another process on retry.
474
+ const recoveryError = new Error(recoveryMessage);
475
+ this.initializationFailures.set(agent.id, recoveryError);
476
+ const recovering = { ...createdBinding, initializationCleanupPending: true };
477
+ try {
478
+ this.state.save(agent.id, recovering);
479
+ }
480
+ catch { /* The in-memory guard still blocks retry if local storage is also unavailable. */ }
481
+ failure = recoveryError;
482
+ }
483
+ finally {
484
+ cleanup.abort();
485
+ }
486
+ }
335
487
  link.close();
336
- throw error;
488
+ throw failure;
337
489
  }
338
490
  })();
339
491
  this.links.set(agent.id, operation);
@@ -346,6 +498,93 @@ export class AcpAdapter {
346
498
  throw error;
347
499
  }
348
500
  }
501
+ /** Ordinary ACP release. The binding, session id, and restore method stay. No session/delete. */
502
+ async releaseSession(sessionId) {
503
+ const agent = this.ctx.agents.get(sessionId);
504
+ if (!agent) {
505
+ const error = new Error('Session not found');
506
+ error.code = 'SESSION_NOT_FOUND';
507
+ throw error;
508
+ }
509
+ if (!this.agentName(agent))
510
+ return { processReleased: true, acp: false };
511
+ const binding = this.state.get(agent.id);
512
+ const pending = this.links.get(agent.id);
513
+ const link = pending ? await pending.catch(() => undefined) : undefined;
514
+ let processReleased = 'pending';
515
+ if (link && binding?.sessionId) {
516
+ try {
517
+ const result = await link.rpc.request('session/close', { sessionId: binding.sessionId }, {
518
+ cancellationSignal: AbortSignal.any([this.lifetime.signal, AbortSignal.timeout(60_000)]),
519
+ });
520
+ // The service confirms only after it saw the agent exit and its process lease disappear.
521
+ if (result?._meta?.['1agents']?.processReleased === true)
522
+ processReleased = true;
523
+ }
524
+ catch (error) {
525
+ const message = error instanceof Error ? error.message : '';
526
+ if (!/not found|Session not found|-32001/i.test(message)) {
527
+ const wrapped = new Error('Remote session close failed');
528
+ wrapped.code = 'REMOTE_UNAVAILABLE';
529
+ throw wrapped;
530
+ }
531
+ }
532
+ link.close();
533
+ if (this.links.get(agent.id) === pending)
534
+ this.links.delete(agent.id);
535
+ }
536
+ return { processReleased, acp: true };
537
+ }
538
+ /**
539
+ * Controlled delete. ACP session/delete closes the process and marks the record deleted.
540
+ * The DSH session and its history stay. A detached session gets a bare link, so no agent process starts.
541
+ */
542
+ async deleteSession(sessionId) {
543
+ const agent = this.ctx.agents.get(sessionId);
544
+ if (!agent) {
545
+ const error = new Error('Session not found');
546
+ error.code = 'SESSION_NOT_FOUND';
547
+ throw error;
548
+ }
549
+ if (!this.agentName(agent))
550
+ return { processReleased: true, acp: false };
551
+ const binding = this.state.get(agent.id);
552
+ if (!binding?.sessionId || 'initializationCleanupPending' in binding)
553
+ return { processReleased: true, acp: true };
554
+ const pending = this.links.get(agent.id);
555
+ const attached = pending ? await pending.catch(() => undefined) : undefined;
556
+ const link = attached ?? await connect(binding.endpoint, {
557
+ update: () => { },
558
+ permission: async () => ({ outcome: { outcome: 'cancelled' } }),
559
+ question: async () => ({ outcome: 'cancelled' }),
560
+ plan: async () => ({ outcome: 'abandoned' }),
561
+ }, this.lifetime.signal);
562
+ try {
563
+ await link.rpc.request('session/delete', { sessionId: binding.sessionId }, {
564
+ cancellationSignal: AbortSignal.any([this.lifetime.signal, AbortSignal.timeout(60_000)]),
565
+ });
566
+ }
567
+ catch (error) {
568
+ const message = error instanceof Error ? error.message : '';
569
+ if (!/not found|Session not found|-32001/i.test(message)) {
570
+ const wrapped = new Error('Remote session delete failed');
571
+ wrapped.code = 'REMOTE_UNAVAILABLE';
572
+ throw wrapped;
573
+ }
574
+ }
575
+ finally {
576
+ link.close();
577
+ if (attached && this.links.get(agent.id) === pending)
578
+ this.links.delete(agent.id);
579
+ }
580
+ return { processReleased: attached ? 'pending' : true, acp: true };
581
+ }
582
+ async sessionStatus(sessionId) {
583
+ const agent = this.ctx.agents.get(sessionId);
584
+ if (!agent)
585
+ return { attached: false, activeTurn: false };
586
+ return { attached: this.links.has(agent.id), activeTurn: this.controllers.has(agent.id) };
587
+ }
349
588
  async *stream(options) {
350
589
  const agent = options.sessionId ? this.ctx.agents.get(options.sessionId) : undefined;
351
590
  if (!agent || options.purpose)
@@ -374,18 +613,33 @@ export class AcpAdapter {
374
613
  const deny = params.options.find(o => o.kind === 'reject_once');
375
614
  if (!allow)
376
615
  return { outcome: { outcome: 'cancelled' } };
377
- const decision = await this.ctx.approval.request({ agent, toolName: params.toolCall.title || 'ACP tool',
378
- reason: JSON.stringify(params.toolCall.rawInput ?? params.toolCall.content ?? {}, null, 2), signal });
379
- const selected = decision === 'allowed-once' ? allow : decision === 'rejected' ? deny : undefined;
616
+ // DSH full access never asks, so its approval service would reject every ACP request. The user's switch to
617
+ // full access is the grant: allow without asking. The fold reads only an explicit sandbox/mode switch.
618
+ if (this.ctx.sessionProjections.stateOf(agent.session, 'sandboxMode') === 'danger-full-access') {
619
+ return { outcome: { outcome: 'selected', optionId: allow.optionId } };
620
+ }
621
+ const toolName = params.toolCall.title || 'ACP tool';
622
+ const reason = JSON.stringify(params.toolCall.rawInput ?? params.toolCall.content ?? {}, null, 2);
623
+ // An A2A turn also offers the approval to the workbench; the first answer wins. The tool call id keeps
624
+ // each call its own request, so an earlier approval never covers a later identical command.
625
+ const result = await this.withProcessRequest(agent, signal, { kind: 'permission', body: [params.toolCall.toolCallId, toolName, reason],
626
+ toolTitle: toolName.slice(0, 500), toolDetail: reason.slice(0, 16 * 1024),
627
+ local: async (localSignal) => {
628
+ const decision = await this.ctx.approval.request({ agent, toolName, reason, signal: localSignal });
629
+ return { outcome: decision === 'allowed-once' ? 'approved' : decision === 'rejected' ? 'rejected' : 'cancelled' };
630
+ } });
631
+ const selected = result.outcome === 'approved' ? allow : result.outcome === 'rejected' ? deny : undefined;
380
632
  return { outcome: selected ? { outcome: 'selected', optionId: selected.optionId } : { outcome: 'cancelled' } };
381
633
  }
382
- async question(agent, p, signal) {
383
- const questions = (Array.isArray(p.questions) ? p.questions : []).map((value, i) => {
634
+ questionsOf(p) {
635
+ return (Array.isArray(p.questions) ? p.questions : []).map((value, i) => {
384
636
  const q = object(value);
385
637
  return { id: String(i), question: String(q.question ?? ''), header: typeof q.header === 'string' ? q.header : undefined,
386
- options: Array.isArray(q.options) ? q.options.map(value => { const o = object(value); return { label: String(o.label), description: typeof o.description === 'string' ? o.description : undefined }; }) : undefined,
638
+ options: Array.isArray(q.options) ? q.options.map(item => { const o = object(item); return { label: String(o.label), description: typeof o.description === 'string' ? o.description : undefined }; }) : undefined,
387
639
  multiSelect: q.multiSelect === true };
388
640
  });
641
+ }
642
+ async askQuestions(agent, questions, signal) {
389
643
  try {
390
644
  const result = await this.ctx.userQuestions.ask({ agent, questions, signal });
391
645
  return { outcome: 'accepted', answers: Object.fromEntries(result.answers.map(a => [questions[Number(a.id)].question, a.custom || (a.selected.length === 1 ? a.selected[0] : a.selected)])) };
@@ -396,9 +650,9 @@ export class AcpAdapter {
396
650
  throw error;
397
651
  }
398
652
  }
399
- async plan(agent, p, signal) {
653
+ async askPlan(agent, content, signal) {
400
654
  try {
401
- const result = await this.ctx.userQuestions.ask({ agent, signal, questions: [{ id: 'plan', question: 'ACP Agent 请求执行计划', detail: String(p.planContent ?? ''), options: [{ label: '批准' }, { label: '拒绝' }], intent: { kind: 'plan-review', approve: '批准' } }] });
655
+ const result = await this.ctx.userQuestions.ask({ agent, signal, questions: [{ id: 'plan', question: 'ACP Agent 请求执行计划', detail: content, options: [{ label: '批准' }, { label: '拒绝' }], intent: { kind: 'plan-review', approve: '批准' } }] });
402
656
  return { outcome: result.answers[0]?.selected.includes('批准') ? 'approved' : 'rejected' };
403
657
  }
404
658
  catch (error) {
@@ -407,6 +661,74 @@ export class AcpAdapter {
407
661
  throw error;
408
662
  }
409
663
  }
664
+ async question(agent, p, signal) {
665
+ const questions = this.questionsOf(p);
666
+ return this.withProcessRequest(agent, signal, { kind: 'question', body: questions, questions, local: askSignal => this.askQuestions(agent, questions, askSignal) });
667
+ }
668
+ async plan(agent, p, signal) {
669
+ const planContent = String(p.planContent ?? '');
670
+ return this.withProcessRequest(agent, signal, { kind: 'plan', body: planContent, planContent, local: askSignal => this.askPlan(agent, planContent, askSignal) });
671
+ }
672
+ /** The workbench answer completes this wait. A later A2A user message does not. */
673
+ async withProcessRequest(agent, signal, spec) {
674
+ const fallback = spec.kind === 'plan' ? 'abandoned' : 'cancelled';
675
+ if (!this.processRequests)
676
+ return spec.local(signal);
677
+ const binding = currentA2AExecution(agent.id);
678
+ if (!binding)
679
+ return spec.local(signal);
680
+ const requestId = `prc-${createHash('sha256').update(JSON.stringify([binding.jobId, binding.attemptId, spec.kind, spec.body])).digest('hex').slice(0, 32)}`;
681
+ let opened;
682
+ try {
683
+ opened = await this.processRequests.open({ requestId, jobId: binding.jobId, attemptId: binding.attemptId, sessionId: agent.id, kind: spec.kind, questions: spec.questions, planContent: spec.planContent,
684
+ ...(spec.toolTitle ? { toolTitle: spec.toolTitle, toolDetail: spec.toolDetail } : {}) });
685
+ }
686
+ catch {
687
+ return spec.local(signal);
688
+ }
689
+ if (signal.aborted) {
690
+ void this.reportProcess(binding.jobId, opened.requestId, fallback, undefined, `dsh-cancel:${opened.requestId}`);
691
+ return { outcome: fallback };
692
+ }
693
+ const child = new AbortController(), waitAbort = new AbortController();
694
+ const stop = () => { child.abort(signal.reason); waitAbort.abort(signal.reason); };
695
+ signal.addEventListener('abort', stop, { once: true });
696
+ const localTask = spec.local(child.signal);
697
+ const remoteTask = this.processRequests.wait({ jobId: binding.jobId, requestId: opened.requestId, signal: AbortSignal.any([signal, waitAbort.signal]) });
698
+ void localTask.catch(() => { });
699
+ void remoteTask.catch(() => { });
700
+ try {
701
+ const winner = await Promise.race([
702
+ localTask.then(value => ({ source: 'local', value })),
703
+ remoteTask.then(value => ({ source: 'workbench', value })),
704
+ ]);
705
+ if (winner.source === 'local') {
706
+ waitAbort.abort();
707
+ const outcome = typeof winner.value.outcome === 'string' ? winner.value.outcome : fallback;
708
+ const answers = winner.value.answers;
709
+ void this.reportProcess(binding.jobId, opened.requestId, outcome, answers, outcome === 'cancelled' || outcome === 'abandoned' ? `dsh-cancel:${opened.requestId}` : `dsh-ui:${opened.requestId}`);
710
+ return winner.value;
711
+ }
712
+ child.abort();
713
+ return acpFromProcessView(spec.kind, winner.value);
714
+ }
715
+ catch (error) {
716
+ child.abort();
717
+ waitAbort.abort();
718
+ if (signal.aborted) {
719
+ void this.reportProcess(binding.jobId, opened.requestId, fallback, undefined, `dsh-cancel:${opened.requestId}`);
720
+ return { outcome: fallback };
721
+ }
722
+ void this.reportProcess(binding.jobId, opened.requestId, fallback, undefined, `dsh-cancel:${opened.requestId}`);
723
+ throw error;
724
+ }
725
+ finally {
726
+ signal.removeEventListener('abort', stop);
727
+ }
728
+ }
729
+ reportProcess(jobId, requestId, outcome, answers, clientRequestId) {
730
+ return this.processRequests.report({ jobId, requestId, clientRequestId: clientRequestId ?? `dsh-ui:${requestId}`, outcome, ...(answers ? { answers } : {}) }).catch(() => { });
731
+ }
410
732
  async run(agent, options, signal, queue) {
411
733
  const cwd = agent.session.header.cwd;
412
734
  if (!cwd)
@@ -532,7 +854,16 @@ export class AcpAdapter {
532
854
  signal.throwIfAborted();
533
855
  try {
534
856
  this.output.set(agent.id, update);
535
- active = await this.connection(agent);
857
+ const capacityId = input.flatMap(message => message.role === 'user' && message.source?.kind === 'user' && 'rpcId' in message.source
858
+ && typeof message.source.rpcId === 'string' && message.source.rpcId.startsWith('a2a-') ? [message.source.rpcId] : [])[0];
859
+ try {
860
+ active = await this.connection(agent, capacityId, signal);
861
+ noteProcessReady(agent.id);
862
+ }
863
+ catch (error) {
864
+ noteProcessCapacity(agent.id, undefined);
865
+ throw error;
866
+ }
536
867
  binding = this.state.get(agent.id);
537
868
  signal.throwIfAborted();
538
869
  if (diagnosticId)