@qwen-code/qwen-code 0.21.0-nightly.20260727.c003e1718 → 0.21.0-preview.0

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 (329) hide show
  1. package/bundled/qc-helper/docs/configuration/settings.md +4 -0
  2. package/bundled/qc-helper/docs/features/channels/github.md +14 -14
  3. package/bundled/qc-helper/docs/features/hooks.md +50 -13
  4. package/bundled/qc-helper/docs/reference/keyboard-shortcuts.md +2 -2
  5. package/bundled/qc-helper/docs/support/troubleshooting.md +2 -1
  6. package/bundled/review/SKILL.md +15 -0
  7. package/chunks/{MaxSizedBox-2N5IOLMA.js → MaxSizedBox-UQGQ6O3I.js} +36 -36
  8. package/chunks/{StandaloneSessionPicker-6SNFY63D.js → StandaloneSessionPicker-QLO5COVM.js} +51 -51
  9. package/chunks/{acp-startup-profiler-RV3IV562.js → acp-startup-profiler-DFVPFQ6C.js} +2 -2
  10. package/chunks/{acpAgent-6BDY452E.js → acpAgent-ECMKCJPZ.js} +1265 -505
  11. package/chunks/{agent-WPMRCC7E.js → agent-NJ4VPY5B.js} +31 -31
  12. package/chunks/{agent-headless-OSOKZOZK.js → agent-headless-JB6RF5HT.js} +31 -31
  13. package/chunks/{anthropicContentGenerator-EJEHPX2W.js → anthropicContentGenerator-V2QOGVYD.js} +54 -13
  14. package/chunks/{artifact-tool-FQYTXKFY.js → artifact-tool-6K6U7XYJ.js} +2 -2
  15. package/chunks/{askUserQuestion-DJQIJ5T4.js → askUserQuestion-GD2IJJ7I.js} +2 -2
  16. package/chunks/{bridge-VR3WL36L.js → bridge-EXKCQ7MD.js} +38 -37
  17. package/chunks/{build-47LY6L7H.js → build-S6DO7LMM.js} +1 -1
  18. package/chunks/{ca-UBSN3YSM.js → ca-6W3SK7OQ.js} +1 -1
  19. package/chunks/{channel-management-service-2WRAWZQU.js → channel-management-service-XR7GZSWF.js} +7 -7
  20. package/chunks/{channel-settings-store-3FOVM5TF.js → channel-settings-store-VA4J7HPF.js} +38 -38
  21. package/chunks/{channel-worker-group-VMGKUBUY.js → channel-worker-group-XDPTDWTX.js} +9 -5
  22. package/chunks/{channel-worker-manager-2SCF42S2.js → channel-worker-manager-YYEHVRRE.js} +9 -5
  23. package/chunks/{channel-worker-supervisor-F3HADSDC.js → channel-worker-supervisor-74HTWA2G.js} +5 -4
  24. package/chunks/{chunk-2PHWA4IO.js → chunk-2DN4J57Y.js} +2 -2
  25. package/chunks/{chunk-HHYPUCUF.js → chunk-2LKVPASC.js} +3 -3
  26. package/chunks/{chunk-ECBKZ7SV.js → chunk-2LQTH543.js} +2 -2
  27. package/chunks/{chunk-EDEO3ZXU.js → chunk-2XSLTRFZ.js} +2 -2
  28. package/chunks/{chunk-HIJQF5B5.js → chunk-3L2SPEBH.js} +1 -1
  29. package/chunks/{chunk-2KHUM3TN.js → chunk-3MGBLIXX.js} +167 -81
  30. package/chunks/{chunk-CWFC2GZB.js → chunk-3Q4TGVUX.js} +1385 -785
  31. package/chunks/{chunk-KR2UZ6QL.js → chunk-4G2BISNC.js} +1 -1
  32. package/chunks/{chunk-IUYFCE34.js → chunk-4WSL256B.js} +3 -3
  33. package/chunks/{chunk-LI4HGDLZ.js → chunk-5FNROPXI.js} +4 -4
  34. package/chunks/{chunk-ECEJ6T4L.js → chunk-5TBMQLGG.js} +2 -2
  35. package/chunks/{chunk-KW3H2FM4.js → chunk-5YKDXHUY.js} +2 -2
  36. package/chunks/{chunk-PIVH7FAY.js → chunk-5YVWMI26.js} +5 -5
  37. package/chunks/{chunk-IUNB6SUW.js → chunk-64LQLPL7.js} +3 -3
  38. package/chunks/{chunk-7R4YENCL.js → chunk-6QIGFD5W.js} +1 -1
  39. package/chunks/{chunk-SHJ4R6JF.js → chunk-727I7LJ2.js} +5 -5
  40. package/chunks/{chunk-BRKWIX5C.js → chunk-74YNMTJP.js} +30 -19
  41. package/chunks/{chunk-IM6PC55H.js → chunk-75GFAX4R.js} +1 -1
  42. package/chunks/{chunk-IXNNGTUI.js → chunk-75MIQ3LV.js} +18 -3
  43. package/chunks/{chunk-VCBKBEU7.js → chunk-7A4ZDITM.js} +27 -14
  44. package/chunks/{chunk-FZZTCEXC.js → chunk-7HRXAFCW.js} +10 -10
  45. package/chunks/{chunk-BJHP755Z.js → chunk-7I5GTCT4.js} +271 -164
  46. package/chunks/{chunk-BOWYL27T.js → chunk-7XATOOE7.js} +1 -1
  47. package/chunks/{chunk-HAZMIZP7.js → chunk-A2APC6HM.js} +2 -2
  48. package/chunks/{chunk-ZYD3KZPB.js → chunk-A3NDJ5SB.js} +2 -2
  49. package/chunks/{chunk-IIJCNWAY.js → chunk-AL62VKMS.js} +4 -4
  50. package/chunks/{chunk-NZYXKNSZ.js → chunk-AOAYOH3R.js} +1 -1
  51. package/chunks/{chunk-C6U6ZR65.js → chunk-ATZOB5Y2.js} +11 -11
  52. package/chunks/{chunk-UH3WSE5L.js → chunk-B4AJNNOL.js} +1 -6
  53. package/chunks/{chunk-JJY7H2ZU.js → chunk-BCZFQXWK.js} +2 -2
  54. package/chunks/{chunk-FUFNINKB.js → chunk-BGTQCTQW.js} +42 -3
  55. package/chunks/{chunk-6PQHZ4YW.js → chunk-BWKCTLEJ.js} +193 -149
  56. package/chunks/{chunk-3FNJBOF7.js → chunk-CVHIL5IG.js} +3 -3
  57. package/chunks/{chunk-55PWRVIR.js → chunk-DABQX74H.js} +8 -8
  58. package/chunks/{chunk-N7U3LRNS.js → chunk-DDKAZLZ7.js} +17 -6
  59. package/chunks/{chunk-CPF4NIKT.js → chunk-DIQGH5CN.js} +1 -1
  60. package/chunks/{chunk-3YAW4B2W.js → chunk-DJGYJDYR.js} +1 -1
  61. package/chunks/{chunk-4IQSPE3A.js → chunk-DNDETPES.js} +3 -3
  62. package/chunks/{chunk-4CCAX23S.js → chunk-DZLYR4U3.js} +1 -1
  63. package/chunks/{chunk-7XSFZ3FM.js → chunk-EABYVKAK.js} +2 -2
  64. package/chunks/{chunk-SJXVC6ZO.js → chunk-F3EYHTOC.js} +4 -4
  65. package/chunks/{chunk-RKMMVQDZ.js → chunk-FNMZK765.js} +1 -1
  66. package/chunks/{chunk-2KLJYA37.js → chunk-FW4M4GA7.js} +1 -1
  67. package/chunks/chunk-FYJ7W2PI.js +194 -0
  68. package/chunks/{chunk-7GC5YKSS.js → chunk-GATT5TKW.js} +1 -1
  69. package/chunks/{chunk-4CSVLZXK.js → chunk-GBAZKAZW.js} +3 -3
  70. package/chunks/{chunk-5ADNRHTY.js → chunk-GEBV2JGB.js} +28 -5
  71. package/chunks/{chunk-VV6QF662.js → chunk-GKX7E4CO.js} +1 -1
  72. package/chunks/{chunk-ELHHYF7E.js → chunk-GNR2RNMP.js} +157 -4
  73. package/chunks/{chunk-PLMOXLFY.js → chunk-GW3XHA6P.js} +2 -2
  74. package/chunks/{chunk-SAXBG6AR.js → chunk-GXIJHV66.js} +3 -3
  75. package/chunks/{chunk-4AVIERNE.js → chunk-GZ3RCT54.js} +1 -1
  76. package/chunks/{chunk-6K2CPEAB.js → chunk-HKFEPLKW.js} +1 -1
  77. package/chunks/{chunk-QVKDVURA.js → chunk-HRD7NI6D.js} +11 -3
  78. package/chunks/{chunk-G3RJEBAA.js → chunk-HUK2P4RS.js} +2510 -1273
  79. package/chunks/{chunk-RRNQGWR4.js → chunk-HWNLU2HC.js} +7 -7
  80. package/chunks/{chunk-TH6TQR5Y.js → chunk-IZO36O6O.js} +252 -15
  81. package/chunks/{chunk-67IE7N5D.js → chunk-JMONIXMJ.js} +1 -1
  82. package/chunks/{chunk-DMEKUQ5Z.js → chunk-JSD33JG6.js} +3 -3
  83. package/chunks/{chunk-CX2KLDRX.js → chunk-JYBU6YUE.js} +1 -1
  84. package/chunks/{chunk-SJOQ5GW7.js → chunk-KADQPLPX.js} +1 -1
  85. package/chunks/{chunk-PAJNXBXO.js → chunk-KBNDRM4U.js} +3 -3
  86. package/chunks/{chunk-TD665TIY.js → chunk-KFPFJAR3.js} +24 -22
  87. package/chunks/{chunk-ZGVQLKMP.js → chunk-KY3NRFJ5.js} +9 -6
  88. package/chunks/{chunk-DEKCAHRS.js → chunk-LGAOC3ZS.js} +1 -1
  89. package/chunks/{chunk-GVHHFBJ2.js → chunk-LHZRAR2Q.js} +37 -40
  90. package/chunks/{chunk-2WUAKFCQ.js → chunk-LNHZ3A4I.js} +44 -11
  91. package/chunks/{chunk-2LFSPVBC.js → chunk-LW3RFMG7.js} +3 -3
  92. package/chunks/{chunk-SEWRIH7H.js → chunk-M7OONWYU.js} +2 -2
  93. package/chunks/{chunk-CO3BKKFP.js → chunk-ML5M5XOY.js} +269 -248
  94. package/chunks/{chunk-YF6D7CRB.js → chunk-NG3V2LPY.js} +8 -13
  95. package/chunks/{chunk-ZAJIOSFI.js → chunk-NNERMV7T.js} +2 -2
  96. package/chunks/{chunk-N5JEINK3.js → chunk-NOKIVHOL.js} +15 -2
  97. package/chunks/chunk-OCPBI7J5.js +18 -0
  98. package/chunks/{chunk-YF7TVSQK.js → chunk-OKF7JF3R.js} +3 -3
  99. package/chunks/{chunk-5FQ3CINJ.js → chunk-OXWFQXKX.js} +6 -6
  100. package/chunks/{chunk-EWYICJNY.js → chunk-P2YNZWXZ.js} +3 -3
  101. package/chunks/{chunk-6LOSXNKO.js → chunk-PONHVBRT.js} +2 -2
  102. package/chunks/{chunk-FZP2GLM4.js → chunk-QQLCYEN2.js} +1 -1
  103. package/chunks/{chunk-HEVX5YOM.js → chunk-R3NOCPFB.js} +4 -4
  104. package/chunks/{chunk-WZOPR2ZP.js → chunk-R7ZITH3J.js} +3 -1
  105. package/chunks/{chunk-ACPMPDKQ.js → chunk-RPLGZJV2.js} +38 -1
  106. package/chunks/{chunk-MFBM3CQZ.js → chunk-SGFT55XI.js} +1 -1
  107. package/chunks/{chunk-QSDUHJAR.js → chunk-SGM6M3XG.js} +1 -1
  108. package/chunks/{chunk-II55VZQA.js → chunk-SUWVXF2E.js} +3 -3
  109. package/chunks/{chunk-VYPFXUCB.js → chunk-SZ3KHTDR.js} +1 -1
  110. package/chunks/{chunk-UWSREISS.js → chunk-T2QMKU3R.js} +79 -1
  111. package/chunks/{chunk-7VOUXBKJ.js → chunk-TFRMVU6R.js} +1 -1
  112. package/chunks/{chunk-RGZ34F4F.js → chunk-TUQ36KWK.js} +10 -5
  113. package/chunks/{chunk-R2F2DRBY.js → chunk-U3E3UQAA.js} +4 -4
  114. package/chunks/{chunk-2XORP6RV.js → chunk-UEDIRTKG.js} +1 -1
  115. package/chunks/{chunk-VOTXHGKJ.js → chunk-UFI5GRDS.js} +3 -3
  116. package/chunks/{chunk-ATIV6G7N.js → chunk-UHUSJ6X7.js} +1 -1
  117. package/chunks/{chunk-2WVVMSPB.js → chunk-UPUG4GXM.js} +3 -3
  118. package/chunks/{chunk-TXI4LPWT.js → chunk-UWMLWVCA.js} +18 -6
  119. package/chunks/{chunk-G2W6OP2O.js → chunk-V5AWXXVA.js} +3 -3
  120. package/chunks/{chunk-5CGAUBFZ.js → chunk-VYO6YPYG.js} +3 -3
  121. package/chunks/{chunk-67ZRSECV.js → chunk-W4MIWP6M.js} +26 -15
  122. package/chunks/{chunk-OJJVALKY.js → chunk-WBSMNTSV.js} +3 -3
  123. package/chunks/{chunk-BZU6TRNQ.js → chunk-WUKGHS32.js} +5 -5
  124. package/chunks/{chunk-WTCKVXNT.js → chunk-WUNZAP5I.js} +4 -4
  125. package/chunks/{chunk-XM5V2A2E.js → chunk-WZRWHXFE.js} +1 -1
  126. package/chunks/{chunk-K2P7QBXF.js → chunk-X6XZITHR.js} +3 -3
  127. package/chunks/{chunk-ZEVUICUF.js → chunk-XBYYDKAZ.js} +7 -7
  128. package/chunks/{chunk-XL7TLW5I.js → chunk-XBZQT63P.js} +1 -1
  129. package/chunks/{chunk-DC2Y3JSV.js → chunk-XH7E5IGP.js} +1 -1
  130. package/chunks/{chunk-B5DJFAHN.js → chunk-XR2NFLNQ.js} +4 -4
  131. package/chunks/{chunk-FOT6JBY5.js → chunk-XRYM3MCI.js} +348 -126
  132. package/chunks/{chunk-IJDXG4RL.js → chunk-XWWKIXVD.js} +1 -1
  133. package/chunks/{chunk-3SJ43L4W.js → chunk-XZC5VLBZ.js} +2 -0
  134. package/chunks/{chunk-ZWL7SSVL.js → chunk-Y4IHBGBP.js} +1 -1
  135. package/chunks/{chunk-MB3M2BFP.js → chunk-Y6AXW2OG.js} +9 -3
  136. package/chunks/{chunk-6ENJ2DGB.js → chunk-Y6RATHM5.js} +2 -2
  137. package/chunks/{chunk-D33ZN3GK.js → chunk-YAKKV4WO.js} +12 -12
  138. package/chunks/{chunk-IPUUTYMV.js → chunk-YDLJGZHL.js} +1 -1
  139. package/chunks/{chunk-H6YTFKW7.js → chunk-YGF33UXG.js} +60 -7
  140. package/chunks/{chunk-BV6LBI45.js → chunk-YPCRRO7K.js} +3 -3
  141. package/chunks/{chunk-WDMODYUC.js → chunk-ZBVS26BY.js} +4 -0
  142. package/chunks/{chunk-GBJUC5ZL.js → chunk-ZHBO7WVX.js} +1 -1
  143. package/chunks/{chunk-4CKLWQQR.js → chunk-ZSQ5LDBH.js} +1 -1
  144. package/chunks/{computer-use-42W2GDED.js → computer-use-TGJRGZWO.js} +31 -31
  145. package/chunks/{config-utils-OTUC46XY.js → config-utils-NYSXDMEQ.js} +4 -4
  146. package/chunks/{contextCommand-2WIK6DG3.js → contextCommand-HGWDMG36.js} +33 -33
  147. package/chunks/{core-runtime-YFT4JKHA.js → core-runtime-WHE3LSHF.js} +31 -31
  148. package/chunks/{create-sub-session-HQMFFLL5.js → create-sub-session-OWI4RC7D.js} +31 -31
  149. package/chunks/{create-sub-session-Q4BUPKIO.js → create-sub-session-SBYUMSSS.js} +2 -2
  150. package/chunks/{cron-create-NI2G2ACR.js → cron-create-2QK6TCEC.js} +4 -4
  151. package/chunks/{cron-delete-KHD2WOMV.js → cron-delete-FDCDFYMG.js} +4 -4
  152. package/chunks/{cron-list-LZMV5V7N.js → cron-list-XN3WVBTP.js} +4 -4
  153. package/chunks/{daemon-KN3FWTYU.js → daemon-Q2AB5Z23.js} +139 -2
  154. package/chunks/{daemon-status-provider-DYVQTAZX.js → daemon-status-provider-KY35PVUR.js} +43 -42
  155. package/chunks/{daemon-trust-policy-QUHMUDOQ.js → daemon-trust-policy-QSQRPXHD.js} +37 -37
  156. package/chunks/{daemon-trust-policy-monitor-AHIPWCQD.js → daemon-trust-policy-monitor-VJQ54EM3.js} +37 -37
  157. package/chunks/{de-LVJPZWUT.js → de-SY6O76BF.js} +1 -1
  158. package/chunks/{deferred-core-runtime-VWKP5HVD.js → deferred-core-runtime-U3DDMMV2.js} +31 -31
  159. package/chunks/{dist-CWCPAMA2.js → dist-BSTVRPMT.js} +234 -78
  160. package/chunks/{dist-GWORRKWL.js → dist-DOLYHMXE.js} +2 -2
  161. package/chunks/{dist-CRNO2KXU.js → dist-HVRQ2CFL.js} +271 -11
  162. package/chunks/{dist-TPJRJ237.js → dist-IXQEQWRG.js} +1 -1
  163. package/chunks/{dist-ONF2ZUUX.js → dist-SSU66DM4.js} +1 -1
  164. package/chunks/{dist-BRVIXBFA.js → dist-SV7Q3AWJ.js} +1 -1
  165. package/chunks/{dist-2HFXMUT6.js → dist-YGBBMK3Z.js} +1 -1
  166. package/chunks/{earlyInputCapture-AZAUUSDE.js → earlyInputCapture-H4YOY6R7.js} +32 -32
  167. package/chunks/{edit-2GM73YUN.js → edit-NZWMOOX6.js} +31 -31
  168. package/chunks/{en-7JEDYSBE.js → en-NBK3JKCE.js} +4 -1
  169. package/chunks/{enter-worktree-O6MC2FZM.js → enter-worktree-6FMYNZ4S.js} +31 -31
  170. package/chunks/{enterPlanMode-NJNHHLAJ.js → enterPlanMode-RYK5P7WC.js} +31 -31
  171. package/chunks/{environment-L5QWIYKQ.js → environment-RBLY3QVX.js} +33 -33
  172. package/chunks/{errors-GO7MH572.js → errors-WVUI42QV.js} +33 -33
  173. package/chunks/{exit-worktree-FR7KKQSW.js → exit-worktree-FRFYEX6R.js} +31 -31
  174. package/chunks/{exitPlanMode-QKNK5MBZ.js → exitPlanMode-STTGKHP2.js} +31 -31
  175. package/chunks/{fast-path-7SP4KXIF.js → fast-path-OZD2JFDY.js} +3 -3
  176. package/chunks/{fast-path-settings-GTWXZLJZ.js → fast-path-settings-WQJU2LAT.js} +2 -2
  177. package/chunks/{fr-JXF5ONTD.js → fr-4KG5V7UT.js} +1 -1
  178. package/chunks/{gemini-J5WX6DS3.js → gemini-PUKYW6OF.js} +83 -82
  179. package/chunks/{geminiContentGenerator-X4FCO2IH.js → geminiContentGenerator-HYMWIERE.js} +6 -6
  180. package/chunks/{glob-UYGYQ73X.js → glob-IZATNUPS.js} +31 -31
  181. package/chunks/{grep-HWLK333D.js → grep-DWHBLRXJ.js} +33 -32
  182. package/chunks/{handleAutoUpdate-H55RTXMU.js → handleAutoUpdate-3VHGEOAV.js} +35 -35
  183. package/chunks/{i18n-6YL3VGHQ.js → i18n-A56PNKBP.js} +32 -32
  184. package/chunks/{image-gen-ZN43Y352.js → image-gen-RBLQKXQJ.js} +9 -9
  185. package/chunks/{initializer-ATU3WGM5.js → initializer-TCD6H7VY.js} +38 -38
  186. package/chunks/{installationInfo-3D4M363G.js → installationInfo-276EXQW2.js} +32 -32
  187. package/chunks/{ja-72VBFAM5.js → ja-F3GSQXMF.js} +1 -1
  188. package/chunks/{keychain-token-storage-U6BBK3IE.js → keychain-token-storage-72IYCAZV.js} +2 -2
  189. package/chunks/{list-K7TOZQ5T.js → list-NWDHWJ4D.js} +40 -40
  190. package/chunks/{list-agents-FHIQAX2Y.js → list-agents-R6KDXQR3.js} +2 -2
  191. package/chunks/{loadedSettingsAdapter-IDASCO2P.js → loadedSettingsAdapter-YXJKWUYF.js} +37 -37
  192. package/chunks/{loggingContentGenerator-C7ECOBP5.js → loggingContentGenerator-LU6TII3U.js} +18 -18
  193. package/chunks/{loop-wakeup-PSF72P7O.js → loop-wakeup-3IQKCYAH.js} +5 -5
  194. package/chunks/{ls-RVQ2JC4C.js → ls-DKZ37A7N.js} +4 -4
  195. package/chunks/{lsp-UFP2H2RG.js → lsp-QNWN7KN3.js} +2 -2
  196. package/chunks/{managed-npm-update-MWQIFEJC.js → managed-npm-update-AO3CL6VU.js} +32 -32
  197. package/chunks/{mcp-YJ4SZXFF.js → mcp-5PMHEFAR.js} +37 -37
  198. package/chunks/{monitor-MWKW6W4Q.js → monitor-2YELRQ6S.js} +31 -31
  199. package/chunks/nonInteractiveCli-74R5S76M.js +144 -0
  200. package/chunks/{notebook-edit-ALAKK5DZ.js → notebook-edit-SV6GDWUG.js} +31 -31
  201. package/chunks/{openaiContentGenerator-V5GYCLVN.js → openaiContentGenerator-FMBXX26Z.js} +19 -19
  202. package/chunks/{pidfile-I7IOGSVT.js → pidfile-HZA26WFC.js} +32 -32
  203. package/chunks/process-registry-2CHQBXH5.js +157 -0
  204. package/chunks/{processUtils-SRGJPX5P.js → processUtils-4F7EMUKQ.js} +2 -2
  205. package/chunks/{pt-E4AMXNUG.js → pt-EQ33KWEN.js} +1 -1
  206. package/chunks/{qwenContentGenerator-INCMQJG3.js → qwenContentGenerator-CXAD5IOE.js} +37 -37
  207. package/chunks/{qwenOAuth2-MIL7MEKO.js → qwenOAuth2-7V2RGLUU.js} +8 -8
  208. package/chunks/{read-file-BBQ6BN7G.js → read-file-AQKNOXOV.js} +11 -11
  209. package/chunks/{read-mcp-resource-M4IJUOXP.js → read-mcp-resource-GFTWYXMK.js} +2 -2
  210. package/chunks/{record-artifact-4NWBVHNM.js → record-artifact-XAMSFSW4.js} +2 -2
  211. package/chunks/{resumeHistoryUtils-X74IGERO.js → resumeHistoryUtils-NSHGEJZY.js} +37 -37
  212. package/chunks/{ripGrep-GCSZGI22.js → ripGrep-KVWIREMR.js} +31 -31
  213. package/chunks/{ru-OJOR34RM.js → ru-7OZAUKGG.js} +1 -1
  214. package/chunks/{run-qwen-serve-RAPQ4UBN.js → run-qwen-serve-LBBMQRWJ.js} +94 -58
  215. package/chunks/{runtime-F4YK7A5M.js → runtime-XR3VFARS.js} +42 -42
  216. package/chunks/{scheduler-JFOAST7W.js → scheduler-OLI5YERT.js} +31 -31
  217. package/chunks/{sdk-exporters-http-H6MWAYGV.js → sdk-exporters-http-WO556XNU.js} +2 -2
  218. package/chunks/{sdk-impl-U4BU6LE5.js → sdk-impl-LPAVACSF.js} +2 -2
  219. package/chunks/{send-message-GAB3K4KN.js → send-message-SAWK4DZX.js} +4 -4
  220. package/chunks/{serve-WAK4FQIT.js → serve-2WM3HPSN.js} +37 -37
  221. package/chunks/{server-GJFU7OZ6.js → server-T4C6UGPM.js} +895 -127
  222. package/chunks/{session-WFWS7D6U.js → session-IAPGXMG3.js} +78 -77
  223. package/chunks/{settings-NI7K6BOS.js → settings-LIYC7NVY.js} +39 -39
  224. package/chunks/{shell-PI52ZRBM.js → shell-M455ZXG6.js} +31 -31
  225. package/chunks/{skill-EGJY4VDT.js → skill-ZHDF6IVV.js} +15 -15
  226. package/chunks/{skill-settings-27BQIOWC.js → skill-settings-MEFO33AC.js} +36 -36
  227. package/chunks/{spawnChannel-LU6YO2IZ.js → spawnChannel-NAISQSBK.js} +33 -33
  228. package/chunks/{standalone-update-TG2BLT73.js → standalone-update-K4RNR537.js} +33 -33
  229. package/chunks/{startInteractiveUI-4NTL2RZ6.js → startInteractiveUI-HJUQMCBD.js} +426 -216
  230. package/chunks/{syntheticOutput-YCOHYBPM.js → syntheticOutput-355CB6CJ.js} +3 -3
  231. package/chunks/{task-create-YRN3PDAT.js → task-create-INGWNUG4.js} +8 -8
  232. package/chunks/{task-list-FYGHXFOT.js → task-list-5XNNGTF4.js} +5 -5
  233. package/chunks/{task-stop-I7CNWL7J.js → task-stop-4ROAOBXH.js} +2 -2
  234. package/chunks/{task-update-5QOY2AIK.js → task-update-CRK5VWWZ.js} +8 -8
  235. package/chunks/{team-create-5H4T3ENJ.js → team-create-YWCUC55A.js} +31 -31
  236. package/chunks/{team-delete-OAA4YOAC.js → team-delete-S2RCXA4P.js} +5 -5
  237. package/chunks/{team-plan-approval-44SCBFBB.js → team-plan-approval-ZJGZRKV5.js} +31 -31
  238. package/chunks/{theme-manager-HYFW3GL7.js → theme-manager-5LUFI5NY.js} +32 -32
  239. package/chunks/{todoWrite-YFIBFZO3.js → todoWrite-7WM3VDMY.js} +4 -4
  240. package/chunks/{tool-search-YAIIWTSJ.js → tool-search-LZMDLBAK.js} +13 -13
  241. package/chunks/{total-session-admission-FPF66OF6.js → total-session-admission-MDA3ANYQ.js} +39 -38
  242. package/chunks/{trustedFolders-4RSRSIO3.js → trustedFolders-NZEZRJPU.js} +32 -32
  243. package/chunks/{update-relaunch-4NKVI2H5.js → update-relaunch-D7EKBO4E.js} +5 -5
  244. package/chunks/{updateCheck-E2336RGI.js → updateCheck-AKFMZZCG.js} +34 -34
  245. package/chunks/{useAutoAcceptIndicator-YXC4OJ2B.js → useAutoAcceptIndicator-55OEL7UZ.js} +40 -40
  246. package/chunks/{validateNonInterActiveAuth-G5PREALO.js → validateNonInterActiveAuth-K5WQOFUQ.js} +72 -71
  247. package/chunks/{version-IBROP4MJ.js → version-ANSPR52A.js} +1 -1
  248. package/chunks/{web-fetch-G2GFNE3L.js → web-fetch-WFKX5SJM.js} +14 -14
  249. package/chunks/{web-search-4ISTNKIX.js → web-search-XDPHXEUC.js} +9 -9
  250. package/chunks/{workflow-OQY4Y74P.js → workflow-6YYVMHCS.js} +32 -32
  251. package/chunks/{workspace-providers-status-SRB65GMC.js → workspace-providers-status-5L4FEPYR.js} +40 -40
  252. package/chunks/{workspace-registration-store-XOUNCX5G.js → workspace-registration-store-C2HIDNXV.js} +1 -1
  253. package/chunks/{workspace-registry-XMDDRCP3.js → workspace-registry-7B7T5SC3.js} +39 -38
  254. package/chunks/{workspace-service-XUAHBWUX.js → workspace-service-VGGIWADS.js} +46 -45
  255. package/chunks/{workspace-skills-status-GGH6TYSU.js → workspace-skills-status-MZZLEGL5.js} +38 -38
  256. package/chunks/{workspace-trust-reconciler-AKKLKLJQ.js → workspace-trust-reconciler-3PA5PLHX.js} +45 -44
  257. package/chunks/{write-file-7MSTD3VC.js → write-file-5GNKRL2B.js} +31 -31
  258. package/chunks/{zh-2MA5UKNJ.js → zh-H3YDK5QW.js} +4 -1
  259. package/chunks/{zh-TW-JO4Z7CVC.js → zh-TW-JYCP7XUA.js} +4 -1
  260. package/chunks/zoom-image-JIRPKLNA.js +351 -0
  261. package/cli.js +13 -13
  262. package/locales/ca.js +2 -2
  263. package/locales/de.js +2 -2
  264. package/locales/en.js +5 -2
  265. package/locales/fr.js +2 -2
  266. package/locales/ja.js +2 -2
  267. package/locales/pt.js +2 -2
  268. package/locales/ru.js +2 -2
  269. package/locales/zh-TW.js +5 -2
  270. package/locales/zh.js +5 -2
  271. package/package.json +5 -4
  272. package/web-shell/assets/{arc-DYNfZ967.js → arc-75-Wdeo3.js} +1 -1
  273. package/web-shell/assets/{architectureDiagram-3BPJPVTR-CkKsIF39.js → architectureDiagram-3BPJPVTR-FKeXQbyP.js} +1 -1
  274. package/web-shell/assets/{blockDiagram-GPEHLZMM-FfDv_qOy.js → blockDiagram-GPEHLZMM-CY0vc-A3.js} +1 -1
  275. package/web-shell/assets/{c4Diagram-AAUBKEIU-pA5r7guO.js → c4Diagram-AAUBKEIU-CNP-A-8u.js} +1 -1
  276. package/web-shell/assets/channel-DPYMT76A.js +1 -0
  277. package/web-shell/assets/{chunk-2J33WTMH-Bfnf2k-q.js → chunk-2J33WTMH-GybS4Gii.js} +1 -1
  278. package/web-shell/assets/{chunk-4BX2VUAB-BCpgiyb4.js → chunk-4BX2VUAB-02H91V8v.js} +1 -1
  279. package/web-shell/assets/{chunk-55IACEB6-BrwrazA2.js → chunk-55IACEB6-D3M-2VT6.js} +1 -1
  280. package/web-shell/assets/{chunk-727SXJPM-DDCxd_BK.js → chunk-727SXJPM-CCu29u4H.js} +1 -1
  281. package/web-shell/assets/{chunk-AQP2D5EJ-Ce-B1Qi5.js → chunk-AQP2D5EJ-CaFKWgrn.js} +1 -1
  282. package/web-shell/assets/{chunk-FMBD7UC4-Dl2u6_p7.js → chunk-FMBD7UC4-ZZpPqIwQ.js} +1 -1
  283. package/web-shell/assets/{chunk-ND2GUHAM-32W_JFKh.js → chunk-ND2GUHAM-D22DqGs8.js} +1 -1
  284. package/web-shell/assets/{chunk-QZHKN3VN-BmtCt0RT.js → chunk-QZHKN3VN-Bu85S0fw.js} +1 -1
  285. package/web-shell/assets/classDiagram-4FO5ZUOK--JstsIgL.js +1 -0
  286. package/web-shell/assets/classDiagram-v2-Q7XG4LA2--JstsIgL.js +1 -0
  287. package/web-shell/assets/{cose-bilkent-S5V4N54A-D_DXerbn.js → cose-bilkent-S5V4N54A-f1CK1Gwe.js} +1 -1
  288. package/web-shell/assets/{dagre-BM42HDAG-C3fMtjq2.js → dagre-BM42HDAG-D0Ow8F_n.js} +1 -1
  289. package/web-shell/assets/{diagram-2AECGRRQ-CBiuEoIi.js → diagram-2AECGRRQ-BPrmTWp8.js} +1 -1
  290. package/web-shell/assets/{diagram-5GNKFQAL-J8DRS3up.js → diagram-5GNKFQAL-HccuFAzy.js} +1 -1
  291. package/web-shell/assets/{diagram-KO2AKTUF-DEVjvvjZ.js → diagram-KO2AKTUF-BrS76mbA.js} +1 -1
  292. package/web-shell/assets/{diagram-LMA3HP47-Bh9hEXeR.js → diagram-LMA3HP47-V7T9lU-5.js} +1 -1
  293. package/web-shell/assets/{diagram-OG6HWLK6-CgV4R96R.js → diagram-OG6HWLK6-DKidyJMR.js} +1 -1
  294. package/web-shell/assets/{erDiagram-TEJ5UH35-BGCFyfGU.js → erDiagram-TEJ5UH35-DBadZIkp.js} +1 -1
  295. package/web-shell/assets/{flowDiagram-I6XJVG4X-BCaQuiMb.js → flowDiagram-I6XJVG4X-BymfqdNJ.js} +1 -1
  296. package/web-shell/assets/{ganttDiagram-6RSMTGT7-B9J27vXf.js → ganttDiagram-6RSMTGT7-DOw340jf.js} +1 -1
  297. package/web-shell/assets/{gitGraphDiagram-PVQCEYII-C2u3FvFn.js → gitGraphDiagram-PVQCEYII-_8EiD8sl.js} +1 -1
  298. package/web-shell/assets/{index-BF2Ug_o6.js → index-CKIadvET.js} +1 -1
  299. package/web-shell/assets/index-D1eXNRHe.js +1389 -0
  300. package/web-shell/assets/index-DVLD4CQq.css +5 -0
  301. package/web-shell/assets/{infoDiagram-5YYISTIA-VGjh3Icm.js → infoDiagram-5YYISTIA-D61KYQBu.js} +1 -1
  302. package/web-shell/assets/{ishikawaDiagram-YF4QCWOH-8AZWigme.js → ishikawaDiagram-YF4QCWOH-CsiXSpNx.js} +1 -1
  303. package/web-shell/assets/{journeyDiagram-JHISSGLW-CnAVNJU5.js → journeyDiagram-JHISSGLW-Sdfionyh.js} +1 -1
  304. package/web-shell/assets/{kanban-definition-UN3LZRKU-DAh7CFUA.js → kanban-definition-UN3LZRKU-C3WI3Cnl.js} +1 -1
  305. package/web-shell/assets/{linear-BMHEIvy4.js → linear-Dpigcc62.js} +1 -1
  306. package/web-shell/assets/{mermaid.core-CpHDMzGU.js → mermaid.core-Ct97pqgW.js} +5 -5
  307. package/web-shell/assets/{mindmap-definition-RKZ34NQL-Cf3CMPHf.js → mindmap-definition-RKZ34NQL-BzeaN0rB.js} +1 -1
  308. package/web-shell/assets/{pieDiagram-4H26LBE5-BpRfWcVA.js → pieDiagram-4H26LBE5-CvjgcbVD.js} +1 -1
  309. package/web-shell/assets/{quadrantDiagram-W4KKPZXB-kqzUnUwh.js → quadrantDiagram-W4KKPZXB-BUzgTNdH.js} +1 -1
  310. package/web-shell/assets/{requirementDiagram-4Y6WPE33-D2FenOqg.js → requirementDiagram-4Y6WPE33-B7zKlgUQ.js} +1 -1
  311. package/web-shell/assets/{sankeyDiagram-5OEKKPKP-dWDMUdUe.js → sankeyDiagram-5OEKKPKP-Bb9CQgrT.js} +1 -1
  312. package/web-shell/assets/{sequenceDiagram-3UESZ5HK-CYcL0MEP.js → sequenceDiagram-3UESZ5HK-DJ6V7itG.js} +1 -1
  313. package/web-shell/assets/{stateDiagram-AJRCARHV-DkpIKZM6.js → stateDiagram-AJRCARHV-IImflERY.js} +1 -1
  314. package/web-shell/assets/stateDiagram-v2-BHNVJYJU-CYI_YoNR.js +1 -0
  315. package/web-shell/assets/{timeline-definition-PNZ67QCA-B50fgyFY.js → timeline-definition-PNZ67QCA-6Q_uWHKh.js} +1 -1
  316. package/web-shell/assets/{vennDiagram-CIIHVFJN-DMlYXh0E.js → vennDiagram-CIIHVFJN-TmyKyjwv.js} +1 -1
  317. package/web-shell/assets/{wardley-L42UT6IY-B2iJy8jY.js → wardley-L42UT6IY-CRh9uiPv.js} +1 -1
  318. package/web-shell/assets/{wardleyDiagram-YWT4CUSO-B-PG81LW.js → wardleyDiagram-YWT4CUSO-59TKAW8w.js} +1 -1
  319. package/web-shell/assets/{xychartDiagram-2RQKCTM6-D1N8kSF9.js → xychartDiagram-2RQKCTM6-GCSUIK2L.js} +1 -1
  320. package/web-shell/index.html +2 -2
  321. package/chunks/nonInteractiveCli-74XMYNLX.js +0 -143
  322. package/web-shell/assets/channel-C-gQ4Nim.js +0 -1
  323. package/web-shell/assets/classDiagram-4FO5ZUOK-DKEurkx0.js +0 -1
  324. package/web-shell/assets/classDiagram-v2-Q7XG4LA2-DKEurkx0.js +0 -1
  325. package/web-shell/assets/index-Du08qEb3.js +0 -1249
  326. package/web-shell/assets/index-tq1xUECo.css +0 -5
  327. package/web-shell/assets/stateDiagram-v2-BHNVJYJU-QSG1JRm2.js +0 -1
  328. package/chunks/{chunk-IAU6HCJZ.js → chunk-D3UEZIQH.js} +6 -6
  329. /package/chunks/{chunk-LXXMOYPL.js → chunk-VXZBKKQR.js} +0 -0
@@ -1,8 +1,5 @@
1
1
  // Force strict mode and setup for ESM
2
2
  "use strict";
3
- import {
4
- recomputeMcpGating
5
- } from "./chunk-YF6D7CRB.js";
6
3
  import {
7
4
  classifyApiError
8
5
  } from "./chunk-V7RNNPGC.js";
@@ -15,50 +12,53 @@ import {
15
12
  matchMcpServerByRef,
16
13
  parseExtensionRef,
17
14
  parseMcpServerRef
18
- } from "./chunk-PIVH7FAY.js";
19
- import {
20
- getCommandSubcommandNames
21
- } from "./chunk-SJOQ5GW7.js";
15
+ } from "./chunk-5YVWMI26.js";
22
16
  import {
23
17
  getAvailableCommands,
24
18
  handleSlashCommand,
25
19
  insertAfterFunctionResponses,
26
20
  isSlashCommand,
27
21
  normalizePartList
28
- } from "./chunk-GVHHFBJ2.js";
22
+ } from "./chunk-LHZRAR2Q.js";
23
+ import {
24
+ recomputeMcpGating
25
+ } from "./chunk-NG3V2LPY.js";
29
26
  import {
30
27
  appEvents,
31
28
  buildDisabledSkillNamesProvider,
32
29
  cleanupReviewWorktreeLeases,
33
30
  loadCliConfig,
34
31
  normalizeDisabledToolList
35
- } from "./chunk-CWFC2GZB.js";
32
+ } from "./chunk-3Q4TGVUX.js";
33
+ import {
34
+ getCommandSubcommandNames
35
+ } from "./chunk-KADQPLPX.js";
36
36
  import {
37
37
  getEffectiveSupportedModes
38
- } from "./chunk-RGZ34F4F.js";
38
+ } from "./chunk-TUQ36KWK.js";
39
39
  import "./chunk-PQNHRFJC.js";
40
- import "./chunk-SEWRIH7H.js";
40
+ import "./chunk-M7OONWYU.js";
41
41
  import {
42
42
  collectContextData,
43
43
  formatContextUsageText
44
- } from "./chunk-SHJ4R6JF.js";
44
+ } from "./chunk-727I7LJ2.js";
45
45
  import "./chunk-4WGODMVR.js";
46
- import "./chunk-K2P7QBXF.js";
46
+ import "./chunk-GATT5TKW.js";
47
+ import "./chunk-R3NOCPFB.js";
48
+ import "./chunk-VYO6YPYG.js";
49
+ import "./chunk-X6XZITHR.js";
47
50
  import "./chunk-YAF2MQZ6.js";
48
- import "./chunk-7GC5YKSS.js";
49
51
  import {
50
52
  computeCpuPercent
51
53
  } from "./chunk-HGT6JR3U.js";
52
- import "./chunk-4CSVLZXK.js";
54
+ import "./chunk-GBAZKAZW.js";
53
55
  import "./chunk-6H67XLET.js";
54
56
  import {
55
57
  beginAcpBootstrapConfigProfiling,
56
58
  buildAndFreezeAcpStartupProfile,
57
59
  endAcpBootstrapConfigProfiling,
58
60
  markAcpStartup
59
- } from "./chunk-HIJQF5B5.js";
60
- import "./chunk-HEVX5YOM.js";
61
- import "./chunk-5CGAUBFZ.js";
61
+ } from "./chunk-3L2SPEBH.js";
62
62
  import {
63
63
  GENERATION_MAX_PROMPT_BYTES,
64
64
  GENERATION_TIMEOUT_MS,
@@ -78,7 +78,7 @@ import {
78
78
  shouldSuppressRememberErrorDetails,
79
79
  workspaceMemoryFailureCode,
80
80
  workspaceMemoryFailureDiagnostics
81
- } from "./chunk-N7U3LRNS.js";
81
+ } from "./chunk-DDKAZLZ7.js";
82
82
  import {
83
83
  HistoryReplayer,
84
84
  MessageEmitter,
@@ -88,10 +88,10 @@ import {
88
88
  goalTerminalEventToHistoryItem,
89
89
  recordGoalStatusItem,
90
90
  restoreGoalFromHistory
91
- } from "./chunk-TH6TQR5Y.js";
92
- import "./chunk-DEKCAHRS.js";
93
- import "./chunk-IPUUTYMV.js";
94
- import "./chunk-6K2CPEAB.js";
91
+ } from "./chunk-IZO36O6O.js";
92
+ import "./chunk-LGAOC3ZS.js";
93
+ import "./chunk-HKFEPLKW.js";
94
+ import "./chunk-YDLJGZHL.js";
95
95
  import "./chunk-2MIN6GRR.js";
96
96
  import "./chunk-QHTIBUWB.js";
97
97
  import {
@@ -105,45 +105,31 @@ import {
105
105
  buildPermissionSettings,
106
106
  normalizePermissionRules,
107
107
  readPermissionRuleSet
108
- } from "./chunk-2XORP6RV.js";
108
+ } from "./chunk-UEDIRTKG.js";
109
109
  import {
110
110
  MAX_AUDIO_BYTES,
111
111
  sanitizeVoiceErrorMessage,
112
112
  transcribeVoiceAudio
113
- } from "./chunk-G2W6OP2O.js";
113
+ } from "./chunk-V5AWXXVA.js";
114
114
  import {
115
115
  readVoiceModel
116
- } from "./chunk-FZP2GLM4.js";
117
- import "./chunk-GBJUC5ZL.js";
118
- import "./chunk-LXXMOYPL.js";
119
- import "./chunk-WTCKVXNT.js";
116
+ } from "./chunk-QQLCYEN2.js";
117
+ import "./chunk-ZHBO7WVX.js";
118
+ import {
119
+ createLoadedSettingsAdapter
120
+ } from "./chunk-ZSQ5LDBH.js";
121
+ import "./chunk-VXZBKKQR.js";
122
+ import "./chunk-WUNZAP5I.js";
120
123
  import "./chunk-E5Z2AVNV.js";
121
124
  import {
122
125
  parseSessionSource
123
- } from "./chunk-FOT6JBY5.js";
126
+ } from "./chunk-XRYM3MCI.js";
124
127
  import "./chunk-GLWP3FDB.js";
125
128
  import "./chunk-XCGIMOLN.js";
126
- import {
127
- CHANNEL_STARTUP_PROFILE_META_KEY,
128
- CHANNEL_STARTUP_PROFILE_VERSION,
129
- CLIENT_MCP_OVER_WS_CONFIG_FLAG,
130
- DAEMON_CHANNEL_DELIVERY_META_KEY,
131
- LOAD_REPLAY_BULK_MODE,
132
- LOAD_REPLAY_META_KEY,
133
- LOAD_REPLAY_MODE_META_KEY,
134
- LOAD_REPLAY_PAGE_SIZE_META_KEY,
135
- LOAD_REPLAY_VERSION,
136
- MID_TURN_QUEUE_DRAIN_METHOD,
137
- PROMPT_CANCEL_METHOD,
138
- TODO_STOP_GUARD_QUEUE_RELEASE_METHOD
139
- } from "./chunk-3SJ43L4W.js";
140
- import {
141
- NOT_CURRENTLY_GENERATING_CANCEL_MESSAGE,
142
- isNotCurrentlyGeneratingCancelError
143
- } from "./chunk-UH3WSE5L.js";
129
+ import "./chunk-OCPBI7J5.js";
144
130
  import {
145
131
  ndJsonStream
146
- } from "./chunk-2KHUM3TN.js";
132
+ } from "./chunk-3MGBLIXX.js";
147
133
  import {
148
134
  ACP_ROUTE_ID_PREFIX,
149
135
  buildAcpModelOptions,
@@ -152,7 +138,7 @@ import {
152
138
  parseAcpModelOption,
153
139
  resolveAcpModelOption,
154
140
  sanitizeProviderBaseUrl
155
- } from "./chunk-PAJNXBXO.js";
141
+ } from "./chunk-KBNDRM4U.js";
156
142
  import {
157
143
  mapSkillConfigToStatus
158
144
  } from "./chunk-L55JWS76.js";
@@ -163,28 +149,46 @@ import {
163
149
  SERVE_STATUS_EXT_METHODS,
164
150
  STATUS_SCHEMA_VERSION,
165
151
  mapDomainErrorToErrorKind
166
- } from "./chunk-WZOPR2ZP.js";
152
+ } from "./chunk-R7ZITH3J.js";
167
153
  import {
168
154
  resolveSkillSettings
169
155
  } from "./chunk-Z4X5MTRT.js";
170
- import "./chunk-RRNQGWR4.js";
171
- import "./chunk-B5DJFAHN.js";
156
+ import "./chunk-HWNLU2HC.js";
157
+ import "./chunk-XR2NFLNQ.js";
172
158
  import "./chunk-57OAHC2Y.js";
173
- import "./chunk-EDEO3ZXU.js";
174
- import "./chunk-7VOUXBKJ.js";
175
- import "./chunk-ZEVUICUF.js";
159
+ import "./chunk-2XSLTRFZ.js";
160
+ import "./chunk-TFRMVU6R.js";
161
+ import "./chunk-XBYYDKAZ.js";
176
162
  import "./chunk-V6WHFGST.js";
177
163
  import {
178
- createLoadedSettingsAdapter
179
- } from "./chunk-4CKLWQQR.js";
164
+ CHANNEL_STARTUP_PROFILE_META_KEY,
165
+ CHANNEL_STARTUP_PROFILE_VERSION,
166
+ CLIENT_MCP_OVER_WS_CONFIG_FLAG,
167
+ DAEMON_CHANNEL_DELIVERY_META_KEY,
168
+ LOAD_REPLAY_BULK_MODE,
169
+ LOAD_REPLAY_META_KEY,
170
+ LOAD_REPLAY_MODE_META_KEY,
171
+ LOAD_REPLAY_PAGE_SIZE_META_KEY,
172
+ LOAD_REPLAY_VERSION,
173
+ MID_TURN_QUEUE_DRAIN_METHOD,
174
+ PROMPT_CANCEL_METHOD,
175
+ TODO_STOP_GUARD_CONTINUATION_CLAIM_METHOD,
176
+ TODO_STOP_GUARD_QUEUE_RELEASE_METHOD
177
+ } from "./chunk-XZC5VLBZ.js";
178
+ import {
179
+ NOT_CURRENTLY_GENERATING_CANCEL_MESSAGE,
180
+ isNotCurrentlyGeneratingCancelError
181
+ } from "./chunk-B4AJNNOL.js";
182
+ import "./chunk-2RFKHEXL.js";
183
+ import "./chunk-FYJ7W2PI.js";
180
184
  import "./chunk-U4VTUMMK.js";
181
- import "./chunk-4AVIERNE.js";
185
+ import "./chunk-GZ3RCT54.js";
182
186
  import "./chunk-ALMR3E6Q.js";
183
187
  import "./chunk-BK2UNYWD.js";
184
188
  import "./chunk-M5GB774H.js";
185
- import "./chunk-KR2UZ6QL.js";
186
- import "./chunk-5ADNRHTY.js";
187
- import "./chunk-BJHP755Z.js";
189
+ import "./chunk-4G2BISNC.js";
190
+ import "./chunk-GEBV2JGB.js";
191
+ import "./chunk-7I5GTCT4.js";
188
192
  import {
189
193
  AgentSideConnection,
190
194
  PROTOCOL_VERSION,
@@ -193,7 +197,7 @@ import {
193
197
  import {
194
198
  assembleMcpServers,
195
199
  loadMcpApprovals
196
- } from "./chunk-5FQ3CINJ.js";
200
+ } from "./chunk-OXWFQXKX.js";
197
201
  import {
198
202
  getOutputLanguageFilePath,
199
203
  getPersistScopeForModelSelection,
@@ -202,34 +206,33 @@ import {
202
206
  resolveOutputLanguageOrPreserveAuto,
203
207
  updateOutputLanguageFile,
204
208
  writeOutputLanguageAndRegisterPath
205
- } from "./chunk-VCBKBEU7.js";
209
+ } from "./chunk-7A4ZDITM.js";
206
210
  import "./chunk-RKUWKYED.js";
207
211
  import {
208
212
  SUPPORTED_LANGUAGES,
209
213
  getCurrentLanguage,
210
214
  setLanguageAsync
211
- } from "./chunk-C6U6ZR65.js";
215
+ } from "./chunk-ATZOB5Y2.js";
212
216
  import {
213
217
  findEnvFiles,
214
218
  preResolveHomeEnvOverrides,
215
219
  reloadEnvironment
216
- } from "./chunk-ZAJIOSFI.js";
217
- import "./chunk-PLMOXLFY.js";
220
+ } from "./chunk-NNERMV7T.js";
221
+ import "./chunk-GW3XHA6P.js";
218
222
  import "./chunk-GOXKNSDZ.js";
219
- import "./chunk-6PEXNQTX.js";
220
- import "./chunk-2RFKHEXL.js";
221
223
  import {
222
224
  getSystemDefaultsPath,
223
225
  getSystemSettingsPath
224
226
  } from "./chunk-IDS7MSUP.js";
227
+ import "./chunk-6PEXNQTX.js";
225
228
  import "./chunk-XFSFZCM5.js";
226
- import "./chunk-NZYXKNSZ.js";
229
+ import "./chunk-AOAYOH3R.js";
227
230
  import "./chunk-VJNBRRZG.js";
228
231
  import {
229
232
  isFolderTrustEnabled,
230
233
  isWorkspaceTrusted,
231
234
  loadTrustedFolders
232
- } from "./chunk-IUYFCE34.js";
235
+ } from "./chunk-4WSL256B.js";
233
236
  import "./chunk-ALGGS7UH.js";
234
237
  import "./chunk-MR3PXB6E.js";
235
238
  import {
@@ -275,6 +278,7 @@ import {
275
278
  applyAutoModeDecision,
276
279
  applyProviderInstallPlan,
277
280
  approxBase64Bytes,
281
+ bridgeToolResultImages,
278
282
  buildBackgroundEntryLabel,
279
283
  buildBtwCacheSafeParams,
280
284
  buildBtwPrompt,
@@ -359,56 +363,56 @@ import {
359
363
  updateSetting,
360
364
  validatePlanModeShellApproval,
361
365
  validatePlanModeShellContext
362
- } from "./chunk-G3RJEBAA.js";
366
+ } from "./chunk-HUK2P4RS.js";
363
367
  import "./chunk-TWPJO254.js";
364
368
  import {
365
369
  external_exports
366
370
  } from "./chunk-H6XPXXMH.js";
367
371
  import "./chunk-5M6IDOMF.js";
368
- import "./chunk-2WVVMSPB.js";
369
- import "./chunk-IUNB6SUW.js";
370
- import "./chunk-ECBKZ7SV.js";
372
+ import "./chunk-UPUG4GXM.js";
373
+ import "./chunk-64LQLPL7.js";
374
+ import "./chunk-2LQTH543.js";
371
375
  import "./chunk-KRXPRVGL.js";
372
- import "./chunk-3FNJBOF7.js";
376
+ import "./chunk-DJGYJDYR.js";
377
+ import "./chunk-CVHIL5IG.js";
373
378
  import "./chunk-IRH27ZC2.js";
374
379
  import "./chunk-QHWCP53L.js";
375
- import "./chunk-6LOSXNKO.js";
380
+ import "./chunk-PONHVBRT.js";
376
381
  import "./chunk-T26EAKDL.js";
377
382
  import {
378
383
  parsePositiveIntegerEnv
379
384
  } from "./chunk-6PVPNMXU.js";
380
- import "./chunk-3YAW4B2W.js";
381
385
  import "./chunk-CPBF7KYF.js";
382
- import "./chunk-7R4YENCL.js";
386
+ import "./chunk-6QIGFD5W.js";
383
387
  import {
384
388
  HookEventName,
385
389
  createHookOutput
386
- } from "./chunk-IJDXG4RL.js";
387
- import "./chunk-IM6PC55H.js";
388
- import "./chunk-YF7TVSQK.js";
390
+ } from "./chunk-XWWKIXVD.js";
391
+ import "./chunk-75GFAX4R.js";
392
+ import "./chunk-OKF7JF3R.js";
389
393
  import {
390
394
  APPROVAL_MODES,
391
395
  FORK_SUBAGENT_TYPE,
392
396
  getStartupContextLength,
393
397
  isSystemReminderContent,
394
398
  runWithRuntimeContentGenerator
395
- } from "./chunk-DMEKUQ5Z.js";
399
+ } from "./chunk-JSD33JG6.js";
396
400
  import "./chunk-S6LOFUVP.js";
397
401
  import "./chunk-JCW2R7WC.js";
398
- import "./chunk-2PHWA4IO.js";
402
+ import "./chunk-2DN4J57Y.js";
399
403
  import "./chunk-ZPJWUGCS.js";
400
404
  import {
401
405
  clearCachedCredentialFile,
402
406
  qwenOAuth2Events
403
- } from "./chunk-HHYPUCUF.js";
407
+ } from "./chunk-2LKVPASC.js";
404
408
  import "./chunk-NAVJD2PQ.js";
405
- import "./chunk-2LFSPVBC.js";
406
- import "./chunk-67ZRSECV.js";
409
+ import "./chunk-LW3RFMG7.js";
410
+ import "./chunk-W4MIWP6M.js";
407
411
  import "./chunk-DGEIYUC3.js";
408
412
  import "./chunk-MPHPFVKK.js";
409
413
  import "./chunk-GLNBDYUX.js";
410
414
  import "./chunk-DJ2GSRLV.js";
411
- import "./chunk-EWYICJNY.js";
415
+ import "./chunk-P2YNZWXZ.js";
412
416
  import {
413
417
  addToolArgumentsAttributes,
414
418
  addToolCallResultAttributes,
@@ -416,14 +420,14 @@ import {
416
420
  registerAcpEventLoopLagGauge,
417
421
  startEventLoopLagMonitor,
418
422
  withDaemonSpan
419
- } from "./chunk-IXNNGTUI.js";
423
+ } from "./chunk-75MIQ3LV.js";
420
424
  import "./chunk-2J3OJGTL.js";
421
425
  import "./chunk-P3QQPMQA.js";
422
- import "./chunk-ACPMPDKQ.js";
426
+ import "./chunk-RPLGZJV2.js";
423
427
  import {
424
428
  getToolCallPreparations
425
429
  } from "./chunk-GLCZKT5V.js";
426
- import "./chunk-4CCAX23S.js";
430
+ import "./chunk-DZLYR4U3.js";
427
431
  import {
428
432
  ConversationFinishedEvent,
429
433
  DiscoveredMCPTool,
@@ -437,6 +441,7 @@ import {
437
441
  formatVisionBridgeNotice,
438
442
  getAllGeminiMdFilenames,
439
443
  getFullTurnVisionModelSelector,
444
+ getInvocationContext,
440
445
  getMCPServerStatus,
441
446
  getSpecificMimeType,
442
447
  hasImageParts,
@@ -453,29 +458,30 @@ import {
453
458
  shouldRunVisionBridge,
454
459
  splitImageParts,
455
460
  uiTelemetryService
456
- } from "./chunk-6PQHZ4YW.js";
461
+ } from "./chunk-BWKCTLEJ.js";
457
462
  import "./chunk-VGC4I5JJ.js";
458
463
  import {
459
464
  getAutoMemoryRoot,
460
465
  getUserAutoMemoryRoot
461
- } from "./chunk-MFBM3CQZ.js";
462
- import "./chunk-ZWL7SSVL.js";
466
+ } from "./chunk-SGFT55XI.js";
467
+ import "./chunk-Y4IHBGBP.js";
463
468
  import {
464
469
  ToolConfirmationOutcome,
465
470
  ToolNames,
466
471
  isShellProgressData
467
- } from "./chunk-MB3M2BFP.js";
472
+ } from "./chunk-Y6AXW2OG.js";
468
473
  import {
469
- AuthType
470
- } from "./chunk-2WUAKFCQ.js";
474
+ AuthType,
475
+ preloadContentGenerator
476
+ } from "./chunk-LNHZ3A4I.js";
471
477
  import "./chunk-46UV252V.js";
472
478
  import {
473
479
  DEFAULT_TOKEN_LIMIT,
474
480
  tokenLimit
475
- } from "./chunk-WDMODYUC.js";
476
- import "./chunk-XM5V2A2E.js";
477
- import "./chunk-ZYD3KZPB.js";
478
- import "./chunk-BOWYL27T.js";
481
+ } from "./chunk-ZBVS26BY.js";
482
+ import "./chunk-WZRWHXFE.js";
483
+ import "./chunk-A3NDJ5SB.js";
484
+ import "./chunk-7XATOOE7.js";
479
485
  import {
480
486
  endToolExecutionSpan,
481
487
  endToolSpan,
@@ -484,7 +490,7 @@ import {
484
490
  startToolExecutionSpan,
485
491
  startToolSpan,
486
492
  withInteractionSpan
487
- } from "./chunk-FUFNINKB.js";
493
+ } from "./chunk-BGTQCTQW.js";
488
494
  import "./chunk-W4RQUHY3.js";
489
495
  import "./chunk-S7W2GKIO.js";
490
496
  import {
@@ -493,12 +499,12 @@ import {
493
499
  getErrorMessage,
494
500
  getErrorStatus,
495
501
  isSubpath
496
- } from "./chunk-ATIV6G7N.js";
502
+ } from "./chunk-UHUSJ6X7.js";
497
503
  import "./chunk-VOQXFAY5.js";
498
- import "./chunk-CPF4NIKT.js";
504
+ import "./chunk-DIQGH5CN.js";
499
505
  import {
500
506
  runExitCleanup
501
- } from "./chunk-XL7TLW5I.js";
507
+ } from "./chunk-XBZQT63P.js";
502
508
  import "./chunk-75DOP5OR.js";
503
509
  import "./chunk-DMTGGOSA.js";
504
510
  import "./chunk-YQ3U5MUC.js";
@@ -1957,6 +1963,7 @@ var DaemonTodoStopGuard = class {
1957
1963
  // packages/cli/src/acp-integration/session/Session.ts
1958
1964
  var debugLogger6 = createDebugLogger("SESSION");
1959
1965
  var USER_CANCEL_ABORT_REASON = "qwen:user-cancel";
1966
+ var SESSION_DISPOSE_ABORT_REASON = "qwen:session-dispose";
1960
1967
  var DAEMON_RETRY_META_KEY = "qwen.daemon.retry";
1961
1968
  var DAEMON_CONTINUE_META_KEY = "qwen.daemon.continueLastTurn";
1962
1969
  var TODO_STOP_GUARD_PROMPT_PREFIX = "[Todo Stop Guard] ";
@@ -2228,6 +2235,20 @@ function parseMidTurnDrainResponse(response) {
2228
2235
  ).map((message) => ({ kind: "text", message }));
2229
2236
  }
2230
2237
  __name(parseMidTurnDrainResponse, "parseMidTurnDrainResponse");
2238
+ function isValidMidTurnDrainResponse(response, requireQueuedPromptState) {
2239
+ if (!isRecord2(response) || requireQueuedPromptState && typeof response["hasQueuedPrompt"] !== "boolean") {
2240
+ return false;
2241
+ }
2242
+ if (Array.isArray(response["items"])) {
2243
+ return response["items"].every(
2244
+ (item) => isRecord2(item) && Array.isArray(item["content"]) && item["content"].length > 0 && item["content"].every(isContentBlock)
2245
+ );
2246
+ }
2247
+ return Array.isArray(response["messages"]) && response["messages"].every(
2248
+ (message) => typeof message === "string" && message.trim().length > 0
2249
+ );
2250
+ }
2251
+ __name(isValidMidTurnDrainResponse, "isValidMidTurnDrainResponse");
2231
2252
  var MidTurnDrainTimeoutError = class extends Error {
2232
2253
  static {
2233
2254
  __name(this, "MidTurnDrainTimeoutError");
@@ -2238,6 +2259,16 @@ var MidTurnDrainTimeoutError = class extends Error {
2238
2259
  );
2239
2260
  }
2240
2261
  };
2262
+ var TodoStopGuardClaimTimeoutError = class extends Error {
2263
+ static {
2264
+ __name(this, "TodoStopGuardClaimTimeoutError");
2265
+ }
2266
+ constructor() {
2267
+ super(
2268
+ `Todo Stop Guard continuation claim got no response within ${MID_TURN_QUEUE_DRAIN_TIMEOUT_MS}ms`
2269
+ );
2270
+ }
2271
+ };
2241
2272
  function beginChannelDeliveryResponseBlock(capture) {
2242
2273
  if (!capture) return void 0;
2243
2274
  capture.finalText = "";
@@ -2571,7 +2602,12 @@ var Session = class {
2571
2602
  midTurnRecoveredMessages = [];
2572
2603
  todoStopGuard;
2573
2604
  todoStopGuardBackgroundBaseline;
2605
+ relatedAgentIds = /* @__PURE__ */ new Set();
2606
+ provisionalRelatedAgentCounts = /* @__PURE__ */ new Map();
2574
2607
  todoStopGuardQueuedPromptPriority = false;
2608
+ todoStopGuardQueuedPromptOwnerPromptId;
2609
+ todoStopGuardClaimOwnerCounts = /* @__PURE__ */ new Map();
2610
+ todoStopGuardReleasedDuringClaim = /* @__PURE__ */ new Set();
2575
2611
  todoStopGuardDrainAutomaticQueuesWhenIdle = false;
2576
2612
  // Background notification drain state. ACP does not have the TUI's idle
2577
2613
  // hook, so the session serializes registry callbacks through this queue.
@@ -2623,7 +2659,7 @@ var Session = class {
2623
2659
  }
2624
2660
  const drainSupersededAutomaticQueues = this.todoStopGuard.blocksUnrelatedAutomaticTurns || this.todoStopGuard.hasCommittedContinuation || this.todoStopGuardQueuedPromptPriority;
2625
2661
  if (this.config.getApprovalMode() === "plan" /* PLAN */) {
2626
- this.todoStopGuardQueuedPromptPriority = false;
2662
+ this.#clearTodoStopGuardQueuedPromptWait();
2627
2663
  this.todoStopGuard.blockUntilOrdinaryPromptStarts();
2628
2664
  return {
2629
2665
  startsWorkChain: false,
@@ -2634,7 +2670,7 @@ var Session = class {
2634
2670
  const isRetry = params.retry === true || metadata?.[DAEMON_RETRY_META_KEY] === true;
2635
2671
  const isContinue = metadata?.[DAEMON_CONTINUE_META_KEY] === true;
2636
2672
  if (isRetry || isContinue) {
2637
- this.todoStopGuardQueuedPromptPriority = false;
2673
+ this.#clearTodoStopGuardQueuedPromptWait();
2638
2674
  if (this.todoStopGuard.hasTrustedUnfinishedState) {
2639
2675
  this.todoStopGuard.resumeTrustedPrompt();
2640
2676
  return {
@@ -2648,7 +2684,7 @@ var Session = class {
2648
2684
  drainSupersededAutomaticQueues
2649
2685
  };
2650
2686
  }
2651
- this.todoStopGuardQueuedPromptPriority = false;
2687
+ this.#clearTodoStopGuardQueuedPromptWait();
2652
2688
  this.todoStopGuard.blockUntilOrdinaryPromptStarts();
2653
2689
  return {
2654
2690
  startsWorkChain: true,
@@ -2661,7 +2697,7 @@ var Session = class {
2661
2697
  this.todoStopGuard.blockUntilOrdinaryPromptStarts();
2662
2698
  return;
2663
2699
  }
2664
- if (continuesCurrentWorkChain && this.todoStopGuard.isHardSuspended) {
2700
+ if (this.todoStopGuard.isHardSuspended) {
2665
2701
  return;
2666
2702
  }
2667
2703
  if (continuesCurrentWorkChain && this.todoStopGuard.hasTrustedUnfinishedState) {
@@ -2669,7 +2705,7 @@ var Session = class {
2669
2705
  return;
2670
2706
  }
2671
2707
  this.todoStopGuard.clearTrust();
2672
- this.todoStopGuardBackgroundBaseline = this.#captureTodoStopGuardBackgroundBaseline();
2708
+ this.#resetTodoStopGuardBackgroundLineage();
2673
2709
  }
2674
2710
  #clearTodoStopGuardTrustAndDrainAutomaticQueues() {
2675
2711
  const preserveQueuedPromptPriority = this.todoStopGuardQueuedPromptPriority;
@@ -2683,35 +2719,116 @@ var Session = class {
2683
2719
  void this.#drainCronQueue();
2684
2720
  void this.#drainNotificationQueue();
2685
2721
  }
2686
- releaseTodoStopGuardQueuedPromptWait() {
2687
- if (!this.todoStopGuardQueuedPromptPriority) return false;
2688
- this.todoStopGuardQueuedPromptPriority = false;
2722
+ releaseTodoStopGuardQueuedPromptWait(promptId) {
2723
+ const matchesCurrentWait = this.todoStopGuardQueuedPromptPriority && this.todoStopGuardQueuedPromptOwnerPromptId === promptId;
2724
+ if (!matchesCurrentWait) {
2725
+ if ((this.todoStopGuardClaimOwnerCounts.get(promptId) ?? 0) === 0) {
2726
+ return false;
2727
+ }
2728
+ this.todoStopGuardReleasedDuringClaim.add(promptId);
2729
+ if (!this.todoStopGuardQueuedPromptPriority) {
2730
+ this.#finishTodoStopGuardQueuedPromptRelease();
2731
+ }
2732
+ return true;
2733
+ }
2734
+ this.#clearTodoStopGuardQueuedPromptWait(promptId);
2735
+ this.#finishTodoStopGuardQueuedPromptRelease();
2736
+ return true;
2737
+ }
2738
+ #finishTodoStopGuardQueuedPromptRelease() {
2689
2739
  this.todoStopGuard.blockUntilOrdinaryPromptStarts();
2690
2740
  if (this.pendingPrompt) {
2691
2741
  this.todoStopGuardDrainAutomaticQueuesWhenIdle = true;
2692
- return true;
2742
+ return;
2693
2743
  }
2694
2744
  void this.#drainCronQueue();
2695
2745
  void this.#drainNotificationQueue();
2696
- return true;
2697
2746
  }
2698
2747
  clearTodoStopGuardTrust() {
2699
2748
  this.#clearTodoStopGuardTrustAndDrainAutomaticQueues();
2700
2749
  }
2701
- #beginTodoStopGuardQueuedPromptCheck() {
2702
- this.todoStopGuardQueuedPromptPriority = this.todoStopGuard.awaitQueuedPrompt();
2750
+ hardSuspendTodoStopGuard() {
2751
+ this.#clearTodoStopGuardQueuedPromptWait();
2752
+ this.todoStopGuardDrainAutomaticQueuesWhenIdle = false;
2753
+ this.todoStopGuard.blockUntilOrdinaryPromptStarts();
2703
2754
  }
2704
- #finishTodoStopGuardQueuedPromptCheck(hasQueuedPrompt) {
2705
- const shouldWait = hasQueuedPrompt && this.todoStopGuardQueuedPromptPriority;
2706
- this.todoStopGuardQueuedPromptPriority = shouldWait;
2707
- if (!shouldWait) this.todoStopGuard.resumeTrustedPrompt();
2708
- return shouldWait;
2755
+ #clearTodoStopGuardQueuedPromptWait(expectedOwner) {
2756
+ if (expectedOwner !== void 0 && this.todoStopGuardQueuedPromptOwnerPromptId !== expectedOwner) {
2757
+ return;
2758
+ }
2759
+ this.todoStopGuardQueuedPromptPriority = false;
2760
+ this.todoStopGuardQueuedPromptOwnerPromptId = void 0;
2761
+ }
2762
+ #awaitTodoStopGuardQueuedPrompt(promptId) {
2763
+ this.todoStopGuard.awaitQueuedPrompt();
2764
+ this.todoStopGuardQueuedPromptPriority = true;
2765
+ this.todoStopGuardQueuedPromptOwnerPromptId = promptId;
2766
+ }
2767
+ async #claimTodoStopGuardContinuation(abortSignal) {
2768
+ const context = getInvocationContext();
2769
+ const ownerPromptId = context?.sessionId === this.sessionId ? context.promptId : void 0;
2770
+ if (ownerPromptId) {
2771
+ this.todoStopGuardClaimOwnerCounts.set(
2772
+ ownerPromptId,
2773
+ (this.todoStopGuardClaimOwnerCounts.get(ownerPromptId) ?? 0) + 1
2774
+ );
2775
+ }
2776
+ let timeoutHandle;
2777
+ try {
2778
+ const claimPromise = this.client.extMethod(
2779
+ TODO_STOP_GUARD_CONTINUATION_CLAIM_METHOD,
2780
+ {
2781
+ sessionId: this.sessionId,
2782
+ ...ownerPromptId ? { promptId: ownerPromptId } : {}
2783
+ }
2784
+ );
2785
+ const timeoutPromise = new Promise((_, reject) => {
2786
+ timeoutHandle = setTimeout(
2787
+ () => reject(new TodoStopGuardClaimTimeoutError()),
2788
+ MID_TURN_QUEUE_DRAIN_TIMEOUT_MS
2789
+ );
2790
+ });
2791
+ const response = await Promise.race([claimPromise, timeoutPromise]);
2792
+ if (abortSignal.aborted || !isRecord2(response)) {
2793
+ return "unavailable";
2794
+ }
2795
+ if (ownerPromptId && response["claimed"] === false && response["hasQueuedPrompt"] === true) {
2796
+ if (this.closing || this.disposed) return "unavailable";
2797
+ if (this.todoStopGuardReleasedDuringClaim.has(ownerPromptId)) {
2798
+ return "unavailable";
2799
+ }
2800
+ this.#awaitTodoStopGuardQueuedPrompt(ownerPromptId);
2801
+ return "queued";
2802
+ }
2803
+ if (this.todoStopGuard.isHardSuspended) return "unavailable";
2804
+ if (response["claimed"] === true && response["hasQueuedPrompt"] === false) {
2805
+ if (ownerPromptId) {
2806
+ this.#clearTodoStopGuardQueuedPromptWait(ownerPromptId);
2807
+ }
2808
+ this.todoStopGuard.resumeTrustedPrompt();
2809
+ return "claimed";
2810
+ }
2811
+ return "unavailable";
2812
+ } catch (error) {
2813
+ debugLogger6.warn(
2814
+ `Todo Stop Guard continuation claim unavailable [session ${this.sessionId}]: ${this.#formatError(error)}`
2815
+ );
2816
+ return "unavailable";
2817
+ } finally {
2818
+ clearTimeout(timeoutHandle);
2819
+ if (ownerPromptId) {
2820
+ const remaining = (this.todoStopGuardClaimOwnerCounts.get(ownerPromptId) ?? 1) - 1;
2821
+ if (remaining > 0) {
2822
+ this.todoStopGuardClaimOwnerCounts.set(ownerPromptId, remaining);
2823
+ } else {
2824
+ this.todoStopGuardClaimOwnerCounts.delete(ownerPromptId);
2825
+ this.todoStopGuardReleasedDuringClaim.delete(ownerPromptId);
2826
+ }
2827
+ }
2828
+ }
2709
2829
  }
2710
2830
  #notificationContinuesTodoStopGuardWorkChain(item) {
2711
- const baseline = this.todoStopGuardBackgroundBaseline;
2712
- if (item.kind === "agent") return !baseline.agents.has(item.taskId);
2713
- if (item.kind === "shell") return !baseline.shells.has(item.taskId);
2714
- return !baseline.monitors.has(item.taskId);
2831
+ return item.continuesTodoStopGuardWorkChain;
2715
2832
  }
2716
2833
  #cronContinuesTodoStopGuardWorkChain(item) {
2717
2834
  return item.source === "loop" && item.taskId !== void 0 && !this.todoStopGuardBackgroundBaseline.wakeups.has(item.taskId);
@@ -2744,6 +2861,37 @@ var Session = class {
2744
2861
  ])
2745
2862
  };
2746
2863
  }
2864
+ #resetTodoStopGuardBackgroundLineage() {
2865
+ this.relatedAgentIds.clear();
2866
+ this.provisionalRelatedAgentCounts.clear();
2867
+ this.todoStopGuardBackgroundBaseline = this.#captureTodoStopGuardBackgroundBaseline();
2868
+ for (const item of this.notificationQueue) {
2869
+ item.continuesTodoStopGuardWorkChain = false;
2870
+ }
2871
+ }
2872
+ #agentContinuesTodoStopGuardWorkChain(taskId, visiting = /* @__PURE__ */ new Set()) {
2873
+ if (this.relatedAgentIds.has(taskId) || (this.provisionalRelatedAgentCounts.get(taskId) ?? 0) > 0) {
2874
+ return true;
2875
+ }
2876
+ if (this.todoStopGuardBackgroundBaseline.agents.has(taskId)) return false;
2877
+ if (visiting.has(taskId)) return false;
2878
+ const task = this.config.getBackgroundTaskRegistry?.()?.get?.(taskId);
2879
+ if (!task) return false;
2880
+ if (!task.parentAgentId) return true;
2881
+ visiting.add(taskId);
2882
+ const related = this.#agentContinuesTodoStopGuardWorkChain(
2883
+ task.parentAgentId,
2884
+ visiting
2885
+ );
2886
+ visiting.delete(taskId);
2887
+ return related;
2888
+ }
2889
+ #monitorContinuesTodoStopGuardWorkChain(monitorId, ownerAgentId) {
2890
+ if (ownerAgentId) {
2891
+ return this.#agentContinuesTodoStopGuardWorkChain(ownerAgentId);
2892
+ }
2893
+ return !this.todoStopGuardBackgroundBaseline.monitors.has(monitorId);
2894
+ }
2747
2895
  #hasRelevantTodoStopGuardBackgroundInput() {
2748
2896
  if (this.notificationQueue.some(
2749
2897
  (item) => this.#notificationContinuesTodoStopGuardWorkChain(item)
@@ -2755,7 +2903,7 @@ var Session = class {
2755
2903
  const baseline = this.todoStopGuardBackgroundBaseline;
2756
2904
  const agents = this.config.getBackgroundTaskRegistry?.()?.getAll?.() ?? [];
2757
2905
  if (agents.some(
2758
- (task) => !baseline.agents.has(task.id) && task.isBackgrounded && (task.status === "running" || task.status === "paused" || task.status === "cancelled" && !task.notified)
2906
+ (task) => this.#agentContinuesTodoStopGuardWorkChain(task.id) && task.isBackgrounded && (task.status === "running" || task.status === "paused" || task.status === "cancelled" && !task.notified)
2759
2907
  )) {
2760
2908
  return true;
2761
2909
  }
@@ -2767,7 +2915,10 @@ var Session = class {
2767
2915
  }
2768
2916
  const monitors = this.config.getMonitorRegistry?.()?.getAll?.() ?? [];
2769
2917
  if (monitors.some(
2770
- (task) => !baseline.monitors.has(task.id) && task.status === "running"
2918
+ (task) => this.#monitorContinuesTodoStopGuardWorkChain(
2919
+ task.id,
2920
+ task.ownerAgentId
2921
+ ) && task.status === "running"
2771
2922
  )) {
2772
2923
  return true;
2773
2924
  }
@@ -2898,12 +3049,19 @@ var Session = class {
2898
3049
  return this.closeGateCompletion ?? Promise.resolve();
2899
3050
  }
2900
3051
  async waitForActiveTurnsToSettle() {
2901
- const pending = [
2902
- this.pendingPromptCompletion,
2903
- this.cronCompletion,
2904
- this.notificationCompletion
2905
- ].filter((completion) => completion !== null);
2906
- await Promise.allSettled(pending);
3052
+ while (this.#hasActiveTurn()) {
3053
+ const pending = [
3054
+ this.pendingPromptCompletion,
3055
+ this.cronCompletion,
3056
+ this.notificationCompletion
3057
+ ].filter(
3058
+ (completion) => completion !== null
3059
+ );
3060
+ if (pending.length > 0) {
3061
+ await Promise.allSettled(pending);
3062
+ }
3063
+ await new Promise((resolve5) => setImmediate(resolve5));
3064
+ }
2907
3065
  }
2908
3066
  #deferAutomaticQueueDrainUntilTurnsSettle() {
2909
3067
  const completions = [
@@ -2932,12 +3090,12 @@ var Session = class {
2932
3090
  dispose() {
2933
3091
  this.disposed = true;
2934
3092
  this.closing = true;
3093
+ this.pendingPrompt?.abort(SESSION_DISPOSE_ABORT_REASON);
3094
+ this.pendingPrompt = null;
2935
3095
  this.resolveCloseGate?.();
2936
3096
  this.resolveCloseGate = null;
2937
3097
  this.closeGateCompletion = null;
2938
- this.todoStopGuardQueuedPromptPriority = false;
2939
- this.todoStopGuardDrainAutomaticQueuesWhenIdle = false;
2940
- this.todoStopGuard.clearTrust();
3098
+ this.hardSuspendTodoStopGuard();
2941
3099
  this.notificationQueue = [];
2942
3100
  this.cronQueue = [];
2943
3101
  this.notificationAbortController?.abort();
@@ -3178,6 +3336,9 @@ var Session = class {
3178
3336
  throw RequestError.invalidParams(void 0, "Session is closing");
3179
3337
  }
3180
3338
  await this.assertCanStartTurn();
3339
+ if (this.closing) {
3340
+ throw RequestError.invalidParams(void 0, "Session is closing");
3341
+ }
3181
3342
  if (admissionCancellation?.aborted) {
3182
3343
  return { stopReason: "cancelled" };
3183
3344
  }
@@ -3239,9 +3400,9 @@ var Session = class {
3239
3400
  return { stopReason: "cancelled" };
3240
3401
  }
3241
3402
  if (todoStopGuardPreparation.startsWorkChain) {
3242
- this.todoStopGuardQueuedPromptPriority = false;
3403
+ this.#clearTodoStopGuardQueuedPromptWait();
3243
3404
  this.todoStopGuard.startOrdinaryPrompt();
3244
- this.todoStopGuardBackgroundBaseline = this.#captureTodoStopGuardBackgroundBaseline();
3405
+ this.#resetTodoStopGuardBackgroundLineage();
3245
3406
  }
3246
3407
  this.duplicateProviderToolCallResponseIds.clear();
3247
3408
  const channelDelivery = parsePromptChannelDelivery(params);
@@ -3282,9 +3443,12 @@ var Session = class {
3282
3443
  }
3283
3444
  throw error;
3284
3445
  } finally {
3446
+ const stillOwnsPendingPrompt = this.pendingPrompt === pendingSend;
3285
3447
  releasePendingSend();
3286
3448
  const shouldDrainAutomaticQueues = todoStopGuardPreparation.drainSupersededAutomaticQueues || this.todoStopGuardDrainAutomaticQueuesWhenIdle || this.todoStopGuard.blocksUnrelatedAutomaticTurns || this.todoStopGuard.hasCommittedContinuation || this.todoStopGuardQueuedPromptPriority;
3287
- this.todoStopGuardDrainAutomaticQueuesWhenIdle = false;
3449
+ if (stillOwnsPendingPrompt) {
3450
+ this.todoStopGuardDrainAutomaticQueuesWhenIdle = false;
3451
+ }
3288
3452
  if (shouldDrainAutomaticQueues) {
3289
3453
  void this.#drainCronQueue();
3290
3454
  void this.#drainNotificationQueue();
@@ -3505,6 +3669,9 @@ var Session = class {
3505
3669
  let parts;
3506
3670
  let fullTurnModelOverride;
3507
3671
  const onFullTurnModel = /* @__PURE__ */ __name((model) => {
3672
+ if (fullTurnModelOverride === model) {
3673
+ return true;
3674
+ }
3508
3675
  if (fullTurnModelOverride) {
3509
3676
  return false;
3510
3677
  }
@@ -3713,7 +3880,8 @@ ${this.pendingRecoveredAgentsNotice}
3713
3880
  }
3714
3881
  strippedOrphanEntries = null;
3715
3882
  }
3716
- if (pendingSend.signal.aborted && pendingSend.signal.reason === USER_CANCEL_ABORT_REASON && this.#isAbortError(error)) {
3883
+ const isControlledCancellation = pendingSend.signal.aborted && (pendingSend.signal.reason === USER_CANCEL_ABORT_REASON || pendingSend.signal.reason === SESSION_DISPOSE_ABORT_REASON);
3884
+ if (isControlledCancellation) {
3717
3885
  this.todoStopGuard.suspend();
3718
3886
  return { stopReason: "cancelled" };
3719
3887
  }
@@ -3765,7 +3933,8 @@ ${this.pendingRecoveredAgentsNotice}
3765
3933
  pendingSend.signal,
3766
3934
  promptId,
3767
3935
  functionCalls,
3768
- toolLoopState
3936
+ toolLoopState,
3937
+ onFullTurnModel
3769
3938
  )
3770
3939
  );
3771
3940
  if (toolRun.stopAfterPermissionCancel) {
@@ -3837,6 +4006,9 @@ ${this.pendingRecoveredAgentsNotice}
3837
4006
  let stopHookIterationCount = 0;
3838
4007
  let stopHookReasons = [];
3839
4008
  const onFullTurnModel = /* @__PURE__ */ __name((model) => {
4009
+ if (modelOverride === model) {
4010
+ return true;
4011
+ }
3840
4012
  if (modelOverride) {
3841
4013
  return false;
3842
4014
  }
@@ -3845,6 +4017,9 @@ ${this.pendingRecoveredAgentsNotice}
3845
4017
  }, "onFullTurnModel");
3846
4018
  let midTurnContinuationCount = 0;
3847
4019
  while (true) {
4020
+ if (this.pendingPrompt && this.pendingPrompt !== pendingSend) {
4021
+ return { stopReason: "cancelled" };
4022
+ }
3848
4023
  if (pendingSend.signal.aborted) {
3849
4024
  this.todoStopGuard.suspend();
3850
4025
  return { stopReason: "cancelled" };
@@ -3856,15 +4031,26 @@ ${this.pendingRecoveredAgentsNotice}
3856
4031
  return { stopReason: "end_turn" };
3857
4032
  }
3858
4033
  if (this.todoStopGuard.needsStopInspection) {
3859
- this.#beginTodoStopGuardQueuedPromptCheck();
3860
4034
  const drained = await this.#drainMidTurnInput(pendingSend.signal, {
3861
4035
  watchQueuedPromptForTodoStopGuard: true,
3862
4036
  onFullTurnModel
3863
4037
  });
3864
- const waitsForQueuedPrompt = this.#finishTodoStopGuardQueuedPromptCheck(
3865
- drained.hasQueuedPrompt
3866
- );
3867
4038
  if (drained.parts.length > 0) {
4039
+ if (drained.hasQueuedPrompt) {
4040
+ const claim = await this.#claimTodoStopGuardContinuation(
4041
+ pendingSend.signal
4042
+ );
4043
+ if (claim === "queued") {
4044
+ this.#preserveUnsentMessageHistory(
4045
+ { role: "user", parts: drained.parts },
4046
+ true
4047
+ );
4048
+ return { stopReason: "end_turn" };
4049
+ }
4050
+ if (claim === "unavailable") {
4051
+ this.todoStopGuard.blockUntilOrdinaryPromptStarts();
4052
+ }
4053
+ }
3868
4054
  this.todoStopGuard.acceptMidTurnUserInput();
3869
4055
  const continuation2 = await this.#runStopContinuation(
3870
4056
  pendingSend,
@@ -3883,13 +4069,22 @@ ${this.pendingRecoveredAgentsNotice}
3883
4069
  }
3884
4070
  continue;
3885
4071
  }
3886
- if (waitsForQueuedPrompt) {
3887
- return { stopReason: "end_turn" };
4072
+ if (!drained.reliable) {
4073
+ this.todoStopGuard.blockUntilOrdinaryPromptStarts();
4074
+ } else if (drained.hasQueuedPrompt) {
4075
+ const claim = await this.#claimTodoStopGuardContinuation(
4076
+ pendingSend.signal
4077
+ );
4078
+ if (claim === "queued") {
4079
+ return { stopReason: "end_turn" };
4080
+ }
4081
+ if (claim === "unavailable") {
4082
+ this.todoStopGuard.blockUntilOrdinaryPromptStarts();
4083
+ }
3888
4084
  }
3889
4085
  }
3890
4086
  let externalReason = null;
3891
4087
  let stopHookCount = 1;
3892
- let queuedPromptArrivedDuringStopHook = false;
3893
4088
  if (allowExternalHooks && hooksEnabled && messageBus && stopHookIterationCount < stopHookBlockingCap && this.config.hasHooksForEvent?.("Stop")) {
3894
4089
  const responseText = this.#getCurrentChat().getLastModelMessageText?.() || "[no response text]";
3895
4090
  const contextUsage = buildContextUsage(
@@ -3920,14 +4115,26 @@ ${this.pendingRecoveredAgentsNotice}
3920
4115
  return { stopReason: "cancelled" };
3921
4116
  }
3922
4117
  if (this.todoStopGuard.needsStopInspection) {
3923
- this.#beginTodoStopGuardQueuedPromptCheck();
3924
4118
  const drained = await this.#drainMidTurnInput(pendingSend.signal, {
3925
4119
  watchQueuedPromptForTodoStopGuard: true,
3926
4120
  onFullTurnModel
3927
4121
  });
3928
- const waitsForQueuedPrompt = this.#finishTodoStopGuardQueuedPromptCheck(drained.hasQueuedPrompt);
3929
- queuedPromptArrivedDuringStopHook = waitsForQueuedPrompt;
3930
4122
  if (drained.parts.length > 0) {
4123
+ if (drained.hasQueuedPrompt) {
4124
+ const claim = await this.#claimTodoStopGuardContinuation(
4125
+ pendingSend.signal
4126
+ );
4127
+ if (claim === "queued") {
4128
+ this.#preserveUnsentMessageHistory(
4129
+ { role: "user", parts: drained.parts },
4130
+ true
4131
+ );
4132
+ return { stopReason: "end_turn" };
4133
+ }
4134
+ if (claim === "unavailable") {
4135
+ this.todoStopGuard.blockUntilOrdinaryPromptStarts();
4136
+ }
4137
+ }
3931
4138
  this.todoStopGuard.acceptMidTurnUserInput();
3932
4139
  const continuation2 = await this.#runStopContinuation(
3933
4140
  pendingSend,
@@ -3944,6 +4151,20 @@ ${this.pendingRecoveredAgentsNotice}
3944
4151
  if (continuation2.kind === "terminal") {
3945
4152
  return { stopReason: continuation2.stopReason };
3946
4153
  }
4154
+ continue;
4155
+ }
4156
+ if (!drained.reliable) {
4157
+ this.todoStopGuard.blockUntilOrdinaryPromptStarts();
4158
+ } else if (drained.hasQueuedPrompt) {
4159
+ const claim = await this.#claimTodoStopGuardContinuation(
4160
+ pendingSend.signal
4161
+ );
4162
+ if (claim === "queued") {
4163
+ return { stopReason: "end_turn" };
4164
+ }
4165
+ if (claim === "unavailable") {
4166
+ this.todoStopGuard.blockUntilOrdinaryPromptStarts();
4167
+ }
3947
4168
  }
3948
4169
  }
3949
4170
  const hookOutput = response.output ? createHookOutput("Stop", response.output) : void 0;
@@ -3956,9 +4177,13 @@ ${this.pendingRecoveredAgentsNotice}
3956
4177
  stopHookIterationCount++;
3957
4178
  stopHookReasons = [...stopHookReasons, externalReason];
3958
4179
  stopHookCount = response.stopHookCount ?? 1;
4180
+ } else {
4181
+ stopHookIterationCount = 0;
4182
+ stopHookReasons = [];
4183
+ stopHookCount = 1;
3959
4184
  }
3960
4185
  }
3961
- const guardDecision = queuedPromptArrivedDuringStopHook ? null : this.todoStopGuard.decide(
4186
+ const guardDecision = this.todoStopGuard.decide(
3962
4187
  this.todoStopGuard.needsStopInspection ? this.#hasRelevantTodoStopGuardBackgroundInput() : false
3963
4188
  );
3964
4189
  const guardContinuation = guardDecision?.kind === "continue" ? guardDecision : null;
@@ -3981,9 +4206,6 @@ ${this.pendingRecoveredAgentsNotice}
3981
4206
  debugLogger6.warn(warning);
3982
4207
  return { stopReason: "end_turn" };
3983
4208
  }
3984
- if (queuedPromptArrivedDuringStopHook) {
3985
- return { stopReason: "end_turn" };
3986
- }
3987
4209
  if (!externalReason && !guardContinuation) {
3988
4210
  return { stopReason: "end_turn" };
3989
4211
  }
@@ -4039,8 +4261,27 @@ ${this.pendingRecoveredAgentsNotice}
4039
4261
  let initialSend = true;
4040
4262
  let automaticContinuationValidated = false;
4041
4263
  let supersededAutomaticContinuation = false;
4264
+ const preservePendingMessage = /* @__PURE__ */ __name((message) => {
4265
+ if (initialSend) return;
4266
+ const preservedParts = (message.parts ?? []).filter(
4267
+ (part) => !("text" in part && isTodoStopGuardPromptText(part.text))
4268
+ );
4269
+ this.#preserveUnsentMessageHistory(
4270
+ preservedParts.length > 0 ? { ...message, parts: preservedParts } : null,
4271
+ true
4272
+ );
4273
+ }, "preservePendingMessage");
4042
4274
  while (nextMessage !== null) {
4275
+ if (this.pendingPrompt && this.pendingPrompt !== pendingSend) {
4276
+ preservePendingMessage(nextMessage);
4277
+ return {
4278
+ kind: "terminal",
4279
+ stopReason: "cancelled",
4280
+ ...supersededAutomaticContinuation ? { supersededAutomaticContinuation: true } : {}
4281
+ };
4282
+ }
4043
4283
  if (pendingSend.signal.aborted) {
4284
+ preservePendingMessage(nextMessage);
4044
4285
  this.todoStopGuard.suspend();
4045
4286
  return {
4046
4287
  kind: "terminal",
@@ -4058,12 +4299,18 @@ ${this.pendingRecoveredAgentsNotice}
4058
4299
  let guardForThisSend = nextGuardContinuation;
4059
4300
  let preserveGuardOnSkippedSend = false;
4060
4301
  let messageForPreservation = nextMessage;
4302
+ let preparedMessage = nextMessage.parts ?? [];
4303
+ let preservePreparedMessageOnSkippedSend = !guardForThisSend && preparedMessage.some(
4304
+ (part) => !("text" in part && isTodoStopGuardPromptText(part.text))
4305
+ );
4061
4306
  const externalParts = initialSend ? options.externalParts : void 0;
4062
4307
  const promptIdForSend = guardForThisSend && guardForThisSend.attempt !== options.guardContinuation?.attempt ? toolPromptId + "_todo_stop_guard_" + guardForThisSend.attempt : streamPromptId;
4063
4308
  const messageDisplay = this.#createMessageDisplayDispatcher(
4064
4309
  pendingSend.signal
4065
4310
  );
4066
4311
  let channelDeliveryResponseBlock;
4312
+ let providerSendChat;
4313
+ let userContentPushCountBeforeSend = 0;
4067
4314
  try {
4068
4315
  const sendResult = await this.#sendMessageStreamWithAutoCompression(
4069
4316
  promptIdForSend,
@@ -4072,44 +4319,134 @@ ${this.pendingRecoveredAgentsNotice}
4072
4319
  {
4073
4320
  skipCompression: skipCompression || (guardForThisSend?.attempt ?? 0) > 1,
4074
4321
  getModelOverride: options.getModelOverride,
4075
- beforeSend: guardForThisSend || !automaticContinuationValidated && options.onAutomaticContinuationValidated ? async ({ compressionFailed }) => {
4076
- const inspectGuardPriority = guardForThisSend !== void 0;
4077
- const guardCompressionFailed = inspectGuardPriority && compressionFailed;
4078
- if (inspectGuardPriority) {
4079
- this.#beginTodoStopGuardQueuedPromptCheck();
4080
- const drained = await this.#drainMidTurnInput(
4081
- pendingSend.signal,
4082
- {
4083
- watchQueuedPromptForTodoStopGuard: true,
4084
- onFullTurnModel: options.onFullTurnModel
4322
+ prepareBeforeCompression: guardForThisSend ? async () => {
4323
+ const drained = await this.#drainMidTurnInput(
4324
+ pendingSend.signal,
4325
+ {
4326
+ watchQueuedPromptForTodoStopGuard: true,
4327
+ onFullTurnModel: options.onFullTurnModel
4328
+ }
4329
+ );
4330
+ if (drained.parts.length > 0) {
4331
+ if (drained.hasQueuedPrompt) {
4332
+ const claim = await this.#claimTodoStopGuardContinuation(
4333
+ pendingSend.signal
4334
+ );
4335
+ if (claim === "queued") {
4336
+ guardForThisSend = void 0;
4337
+ nextGuardContinuation = void 0;
4338
+ preserveGuardOnSkippedSend = true;
4339
+ preservePreparedMessageOnSkippedSend = true;
4340
+ messageForPreservation = {
4341
+ role: "user",
4342
+ parts: drained.parts
4343
+ };
4344
+ if (initialSend) {
4345
+ supersededAutomaticContinuation = true;
4346
+ }
4347
+ return { kind: "stop", stopReason: "end_turn" };
4085
4348
  }
4349
+ if (claim === "unavailable") {
4350
+ this.todoStopGuard.blockUntilOrdinaryPromptStarts();
4351
+ }
4352
+ }
4353
+ preservePreparedMessageOnSkippedSend = true;
4354
+ this.todoStopGuard.acceptMidTurnUserInput();
4355
+ guardForThisSend = void 0;
4356
+ nextGuardContinuation = void 0;
4357
+ if (initialSend) {
4358
+ supersededAutomaticContinuation = true;
4359
+ }
4360
+ preparedMessage = initialSend ? drained.parts : [
4361
+ ...(nextMessage?.parts ?? []).filter(
4362
+ (part) => !("text" in part && isTodoStopGuardPromptText(part.text))
4363
+ ),
4364
+ ...drained.parts
4365
+ ];
4366
+ messageForPreservation = {
4367
+ role: "user",
4368
+ parts: preparedMessage
4369
+ };
4370
+ return { kind: "send", message: preparedMessage };
4371
+ }
4372
+ if (!drained.reliable) {
4373
+ this.todoStopGuard.blockUntilOrdinaryPromptStarts();
4374
+ guardForThisSend = void 0;
4375
+ nextGuardContinuation = void 0;
4376
+ if (!options.externalParts) {
4377
+ preserveGuardOnSkippedSend = true;
4378
+ return { kind: "stop", stopReason: "end_turn" };
4379
+ }
4380
+ if (!initialSend && nextMessage) {
4381
+ nextMessage = {
4382
+ ...nextMessage,
4383
+ parts: (nextMessage.parts ?? []).filter(
4384
+ (part) => !("text" in part && isTodoStopGuardPromptText(part.text))
4385
+ )
4386
+ };
4387
+ }
4388
+ } else if (drained.hasQueuedPrompt) {
4389
+ const probe = await this.#claimTodoStopGuardContinuation(
4390
+ pendingSend.signal
4086
4391
  );
4087
- const waitsForQueuedPrompt = this.#finishTodoStopGuardQueuedPromptCheck(
4088
- drained.hasQueuedPrompt
4089
- );
4090
- if (drained.parts.length > 0) {
4091
- this.todoStopGuard.acceptMidTurnUserInput();
4392
+ if (probe === "queued") {
4092
4393
  guardForThisSend = void 0;
4093
4394
  nextGuardContinuation = void 0;
4395
+ preserveGuardOnSkippedSend = true;
4094
4396
  if (initialSend) {
4095
4397
  supersededAutomaticContinuation = true;
4096
4398
  }
4097
- const replacementMessage = initialSend ? drained.parts : [
4098
- ...(nextMessage?.parts ?? []).filter(
4099
- (part) => !("text" in part && isTodoStopGuardPromptText(part.text))
4100
- ),
4101
- ...drained.parts
4102
- ];
4103
- messageForPreservation = {
4104
- role: "user",
4105
- parts: replacementMessage
4106
- };
4107
- return {
4108
- kind: "send",
4109
- message: replacementMessage
4110
- };
4399
+ return { kind: "stop", stopReason: "end_turn" };
4111
4400
  }
4112
- if (waitsForQueuedPrompt) {
4401
+ if (probe === "unavailable") {
4402
+ this.todoStopGuard.blockUntilOrdinaryPromptStarts();
4403
+ guardForThisSend = void 0;
4404
+ nextGuardContinuation = void 0;
4405
+ if (!options.externalParts) {
4406
+ preserveGuardOnSkippedSend = true;
4407
+ return { kind: "stop", stopReason: "end_turn" };
4408
+ }
4409
+ if (!initialSend && nextMessage) {
4410
+ nextMessage = {
4411
+ ...nextMessage,
4412
+ parts: (nextMessage.parts ?? []).filter(
4413
+ (part) => !("text" in part && isTodoStopGuardPromptText(part.text))
4414
+ )
4415
+ };
4416
+ }
4417
+ }
4418
+ }
4419
+ if (guardForThisSend && this.config.getApprovalMode() === "plan" /* PLAN */) {
4420
+ this.#clearTodoStopGuardTrustAndDrainAutomaticQueues();
4421
+ }
4422
+ if (guardForThisSend) {
4423
+ const hasRelevantBackgroundInput = this.#hasRelevantTodoStopGuardBackgroundInput();
4424
+ const refreshedDecision = guardForThisSend.toolClosure ? this.todoStopGuard.decideToolClosure(
4425
+ guardForThisSend.attempt - 1,
4426
+ hasRelevantBackgroundInput
4427
+ ) : this.todoStopGuard.decide(hasRelevantBackgroundInput);
4428
+ if (refreshedDecision.kind !== "continue" || refreshedDecision.attempt !== guardForThisSend.attempt) {
4429
+ guardForThisSend = void 0;
4430
+ nextGuardContinuation = void 0;
4431
+ if (!options.externalParts) {
4432
+ preserveGuardOnSkippedSend = true;
4433
+ return { kind: "stop", stopReason: "end_turn" };
4434
+ }
4435
+ if (!initialSend && nextMessage) {
4436
+ nextMessage = {
4437
+ ...nextMessage,
4438
+ parts: (nextMessage.parts ?? []).filter(
4439
+ (part) => !("text" in part && isTodoStopGuardPromptText(part.text))
4440
+ )
4441
+ };
4442
+ }
4443
+ }
4444
+ }
4445
+ if (guardForThisSend) {
4446
+ const claim = await this.#claimTodoStopGuardContinuation(
4447
+ pendingSend.signal
4448
+ );
4449
+ if (claim === "queued") {
4113
4450
  guardForThisSend = void 0;
4114
4451
  nextGuardContinuation = void 0;
4115
4452
  preserveGuardOnSkippedSend = true;
@@ -4118,41 +4455,21 @@ ${this.pendingRecoveredAgentsNotice}
4118
4455
  }
4119
4456
  return { kind: "stop", stopReason: "end_turn" };
4120
4457
  }
4121
- if (guardCompressionFailed) {
4122
- this.todoStopGuard.suspend();
4458
+ if (claim === "unavailable") {
4459
+ this.todoStopGuard.blockUntilOrdinaryPromptStarts();
4123
4460
  guardForThisSend = void 0;
4124
4461
  nextGuardContinuation = void 0;
4125
- if (!externalParts || externalParts.length === 0) {
4462
+ if (!options.externalParts) {
4126
4463
  preserveGuardOnSkippedSend = true;
4127
4464
  return { kind: "stop", stopReason: "end_turn" };
4128
4465
  }
4129
- }
4130
- if (guardForThisSend && this.config.getApprovalMode() === "plan" /* PLAN */) {
4131
- this.#clearTodoStopGuardTrustAndDrainAutomaticQueues();
4132
- }
4133
- if (guardForThisSend) {
4134
- const hasRelevantBackgroundInput = this.#hasRelevantTodoStopGuardBackgroundInput();
4135
- const refreshedDecision = guardForThisSend.toolClosure ? this.todoStopGuard.decideToolClosure(
4136
- guardForThisSend.attempt - 1,
4137
- hasRelevantBackgroundInput
4138
- ) : this.todoStopGuard.decide(
4139
- hasRelevantBackgroundInput
4140
- );
4141
- if (refreshedDecision.kind !== "continue" || refreshedDecision.attempt !== guardForThisSend.attempt) {
4142
- guardForThisSend = void 0;
4143
- nextGuardContinuation = void 0;
4144
- if (!options.externalParts) {
4145
- preserveGuardOnSkippedSend = true;
4146
- return { kind: "stop", stopReason: "end_turn" };
4147
- }
4148
- if (!initialSend && nextMessage) {
4149
- nextMessage = {
4150
- ...nextMessage,
4151
- parts: (nextMessage.parts ?? []).filter(
4152
- (part) => !("text" in part && isTodoStopGuardPromptText(part.text))
4153
- )
4154
- };
4155
- }
4466
+ if (!initialSend && nextMessage) {
4467
+ nextMessage = {
4468
+ ...nextMessage,
4469
+ parts: (nextMessage.parts ?? []).filter(
4470
+ (part) => !("text" in part && isTodoStopGuardPromptText(part.text))
4471
+ )
4472
+ };
4156
4473
  }
4157
4474
  }
4158
4475
  }
@@ -4160,16 +4477,42 @@ ${this.pendingRecoveredAgentsNotice}
4160
4477
  await options.onAutomaticContinuationValidated();
4161
4478
  automaticContinuationValidated = true;
4162
4479
  }
4163
- const selectedMessage = guardForThisSend || !externalParts ? nextMessage?.parts ?? [] : externalParts;
4480
+ preparedMessage = guardForThisSend || !externalParts ? nextMessage?.parts ?? [] : externalParts;
4164
4481
  messageForPreservation = {
4165
4482
  role: "user",
4166
- parts: selectedMessage
4483
+ parts: preparedMessage
4167
4484
  };
4168
- return {
4169
- kind: "send",
4170
- message: selectedMessage
4485
+ preservePreparedMessageOnSkippedSend = preparedMessage.some(
4486
+ (part) => !("text" in part && isTodoStopGuardPromptText(part.text))
4487
+ );
4488
+ return { kind: "send", message: preparedMessage };
4489
+ } : void 0,
4490
+ beforeSend: /* @__PURE__ */ __name(async ({ compressionFailed }) => {
4491
+ if (guardForThisSend && compressionFailed) {
4492
+ this.todoStopGuard.suspend();
4493
+ guardForThisSend = void 0;
4494
+ nextGuardContinuation = void 0;
4495
+ if (!options.externalParts) {
4496
+ preserveGuardOnSkippedSend = true;
4497
+ return { kind: "stop", stopReason: "end_turn" };
4498
+ }
4499
+ preparedMessage = initialSend && externalParts ? externalParts : preparedMessage.filter(
4500
+ (part) => !("text" in part && isTodoStopGuardPromptText(part.text))
4501
+ );
4502
+ preservePreparedMessageOnSkippedSend = true;
4503
+ }
4504
+ if (!automaticContinuationValidated && options.onAutomaticContinuationValidated) {
4505
+ await options.onAutomaticContinuationValidated();
4506
+ automaticContinuationValidated = true;
4507
+ }
4508
+ messageForPreservation = {
4509
+ role: "user",
4510
+ parts: preparedMessage
4171
4511
  };
4172
- } : void 0
4512
+ providerSendChat = this.#getCurrentChat();
4513
+ userContentPushCountBeforeSend = providerSendChat.getUserContentPushCount?.() ?? 0;
4514
+ return { kind: "send", message: preparedMessage };
4515
+ }, "beforeSend")
4173
4516
  }
4174
4517
  );
4175
4518
  if (!sendResult.responseStream) {
@@ -4185,7 +4528,7 @@ ${this.pendingRecoveredAgentsNotice}
4185
4528
  );
4186
4529
  this.#preserveUnsentMessageHistory(
4187
4530
  preservedParts.length > 0 ? { ...messageForPreservation, parts: preservedParts } : null,
4188
- sendResult.stopReason === "cancelled"
4531
+ sendResult.stopReason === "cancelled" || preservePreparedMessageOnSkippedSend
4189
4532
  );
4190
4533
  return {
4191
4534
  kind: "terminal",
@@ -4207,7 +4550,7 @@ ${this.pendingRecoveredAgentsNotice}
4207
4550
  if (guardCommitted) {
4208
4551
  await this.#emitTodoStopGuardContinuation(guardForThisSend);
4209
4552
  }
4210
- if (!guardCommitted && externalParts) {
4553
+ if (!guardCommitted && options.externalParts) {
4211
4554
  guardForThisSend = void 0;
4212
4555
  }
4213
4556
  }
@@ -4261,6 +4604,24 @@ ${this.pendingRecoveredAgentsNotice}
4261
4604
  }
4262
4605
  } catch (error) {
4263
4606
  streamFailed = true;
4607
+ const preservedParts = (messageForPreservation.parts ?? []).filter(
4608
+ (part) => !("text" in part && isTodoStopGuardPromptText(part.text))
4609
+ );
4610
+ if (preservedParts.length > 0 && (!providerSendChat || (providerSendChat.getUserContentPushCount?.() ?? 0) <= userContentPushCountBeforeSend)) {
4611
+ this.#preserveUnsentMessageHistory(
4612
+ { ...messageForPreservation, parts: preservedParts },
4613
+ true
4614
+ );
4615
+ }
4616
+ const isControlledCancellation = pendingSend.signal.aborted && (pendingSend.signal.reason === USER_CANCEL_ABORT_REASON || pendingSend.signal.reason === SESSION_DISPOSE_ABORT_REASON);
4617
+ if (isControlledCancellation) {
4618
+ this.todoStopGuard.suspend();
4619
+ return {
4620
+ kind: "terminal",
4621
+ stopReason: "cancelled",
4622
+ ...supersededAutomaticContinuation ? { supersededAutomaticContinuation: true } : {}
4623
+ };
4624
+ }
4264
4625
  this.todoStopGuard.pauseForTrustedRetry();
4265
4626
  const errorStatus = getErrorStatus(error);
4266
4627
  const errorMessage = error instanceof Error ? error.message : String(error);
@@ -4310,7 +4671,8 @@ ${this.pendingRecoveredAgentsNotice}
4310
4671
  pendingSend.signal,
4311
4672
  toolPromptId,
4312
4673
  functionCalls,
4313
- toolLoopState
4674
+ toolLoopState,
4675
+ options.onFullTurnModel
4314
4676
  )
4315
4677
  );
4316
4678
  if (toolRun.stopAfterPermissionCancel || toolRun.loopDetected) {
@@ -4468,6 +4830,19 @@ ${this.pendingRecoveredAgentsNotice}
4468
4830
  */
4469
4831
  async #sendMessageStreamWithAutoCompression(promptId, message, abortSignal, options = {}) {
4470
4832
  const geminiClient = this.config.getGeminiClient();
4833
+ if (options.prepareBeforeCompression) {
4834
+ const decision = await options.prepareBeforeCompression();
4835
+ if (decision.kind === "stop") {
4836
+ return { responseStream: null, stopReason: decision.stopReason };
4837
+ }
4838
+ message = decision.message;
4839
+ }
4840
+ if (abortSignal.aborted) {
4841
+ debugLogger6.debug(
4842
+ `Send aborted after pre-compression preparation for prompt ${promptId}`
4843
+ );
4844
+ return { responseStream: null, stopReason: "cancelled" };
4845
+ }
4471
4846
  let compressionDiagnostic = null;
4472
4847
  let compressionInfo = null;
4473
4848
  let compressionFailed = false;
@@ -4489,10 +4864,13 @@ ${this.pendingRecoveredAgentsNotice}
4489
4864
  compressionDiagnostic = `IMPORTANT: This conversation ${reasonClause}. A compressed context will be sent for future messages (compressed from: ${compressed.originalTokenCount ?? "unknown"} to ${compressed.newTokenCount ?? "unknown"} tokens).`;
4490
4865
  }
4491
4866
  } catch (compressionError) {
4492
- if (abortSignal.aborted || this.#isAbortError(compressionError)) {
4867
+ if (abortSignal.aborted) {
4493
4868
  debugLogger6.debug(`Auto-compression aborted for prompt ${promptId}`);
4494
4869
  return { responseStream: null, stopReason: "cancelled" };
4495
4870
  }
4871
+ if (this.#isAbortError(compressionError)) {
4872
+ throw compressionError;
4873
+ }
4496
4874
  debugLogger6.warn(
4497
4875
  `Auto-compression failed for prompt ${promptId}; proceeding without compression: ` + this.#formatError(compressionError)
4498
4876
  );
@@ -4707,7 +5085,8 @@ ${this.pendingRecoveredAgentsNotice}
4707
5085
  if (this.midTurnDrainUnavailable) {
4708
5086
  return {
4709
5087
  parts: await this.#buildMidTurnParts(recovered, abortSignal, options),
4710
- hasQueuedPrompt: false
5088
+ hasQueuedPrompt: false,
5089
+ reliable: false
4711
5090
  };
4712
5091
  }
4713
5092
  let drainPromise;
@@ -4730,13 +5109,18 @@ ${this.pendingRecoveredAgentsNotice}
4730
5109
  clearTimeout(timeoutHandle);
4731
5110
  }
4732
5111
  this.midTurnDrainTimeoutStrikes = 0;
5112
+ const reliable = isValidMidTurnDrainResponse(
5113
+ response,
5114
+ options.watchQueuedPromptForTodoStopGuard === true
5115
+ );
4733
5116
  return {
4734
5117
  parts: await this.#buildMidTurnParts(
4735
5118
  [...recovered, ...parseMidTurnDrainResponse(response)],
4736
5119
  abortSignal,
4737
5120
  options
4738
5121
  ),
4739
- hasQueuedPrompt: isRecord2(response) && response["hasQueuedPrompt"] === true
5122
+ hasQueuedPrompt: isRecord2(response) && response["hasQueuedPrompt"] === true,
5123
+ reliable
4740
5124
  };
4741
5125
  } catch (error) {
4742
5126
  const errorMessage = error instanceof Error ? error.message : error && typeof error === "object" && "message" in error ? String(error.message) : String(error);
@@ -4755,7 +5139,8 @@ ${this.pendingRecoveredAgentsNotice}
4755
5139
  );
4756
5140
  return {
4757
5141
  parts: await this.#buildMidTurnParts(recovered, abortSignal, options),
4758
- hasQueuedPrompt: false
5142
+ hasQueuedPrompt: false,
5143
+ reliable: false
4759
5144
  };
4760
5145
  }
4761
5146
  }
@@ -4895,26 +5280,39 @@ ${this.pendingRecoveredAgentsNotice}
4895
5280
  );
4896
5281
  }
4897
5282
  #enqueueCronPrompt(item) {
4898
- if ((this.todoStopGuard.blocksUnrelatedAutomaticTurns || this.todoStopGuardQueuedPromptPriority) && !this.#cronContinuesTodoStopGuardWorkChain(item)) {
4899
- if (item.taskId) {
5283
+ const automaticWorkDeferred = this.todoStopGuard.blocksUnrelatedAutomaticTurns || this.todoStopGuardQueuedPromptPriority;
5284
+ if (automaticWorkDeferred) {
5285
+ const incomingIsRelated = this.#cronContinuesTodoStopGuardWorkChain(item);
5286
+ let shouldAppend = true;
5287
+ if (!incomingIsRelated && item.taskId) {
4900
5288
  const duplicateIndex = this.cronQueue.findIndex(
4901
5289
  (queued) => queued.taskId === item.taskId && !this.#cronContinuesTodoStopGuardWorkChain(queued)
4902
5290
  );
4903
5291
  if (duplicateIndex >= 0) {
4904
5292
  this.cronQueue[duplicateIndex] = item;
4905
- return;
5293
+ shouldAppend = false;
4906
5294
  }
4907
5295
  }
4908
- const unrelatedIndices = this.cronQueue.map(
4909
- (queued, index) => this.#cronContinuesTodoStopGuardWorkChain(queued) ? -1 : index
4910
- ).filter((index) => index >= 0);
4911
- if (unrelatedIndices.length >= MAX_DEFERRED_UNRELATED_CRON_QUEUE) {
4912
- const evictedIndex = unrelatedIndices[0];
5296
+ const maxBeforeAppend = MAX_DEFERRED_UNRELATED_CRON_QUEUE - (shouldAppend && !incomingIsRelated ? 1 : 0);
5297
+ let unrelatedCount = this.cronQueue.filter(
5298
+ (queued) => !this.#cronContinuesTodoStopGuardWorkChain(queued)
5299
+ ).length;
5300
+ const evictedTaskIds = [];
5301
+ while (unrelatedCount > maxBeforeAppend) {
5302
+ const evictedIndex = this.cronQueue.findIndex(
5303
+ (queued) => !this.#cronContinuesTodoStopGuardWorkChain(queued)
5304
+ );
5305
+ if (evictedIndex < 0) break;
4913
5306
  const [evicted] = this.cronQueue.splice(evictedIndex, 1);
5307
+ evictedTaskIds.push(evicted?.taskId ?? "unknown");
5308
+ unrelatedCount--;
5309
+ }
5310
+ if (evictedTaskIds.length > 0) {
4914
5311
  debugLogger6.warn(
4915
- `Cron queue overflow while automatic work is deferred: evicting task=${evicted?.taskId ?? "unknown"}`
5312
+ `Cron queue overflow while automatic work is deferred: evicted ${evictedTaskIds.length} unrelated task(s): ${evictedTaskIds.join(", ")}`
4916
5313
  );
4917
5314
  }
5315
+ if (!shouldAppend) return;
4918
5316
  }
4919
5317
  this.cronQueue.push(item);
4920
5318
  }
@@ -5316,6 +5714,7 @@ ${this.pendingRecoveredAgentsNotice}
5316
5714
  taskId: meta.agentId,
5317
5715
  status: meta.status,
5318
5716
  kind: "agent",
5717
+ continuesTodoStopGuardWorkChain: this.#agentContinuesTodoStopGuardWorkChain(meta.agentId),
5319
5718
  toolUseId: meta.toolUseId
5320
5719
  });
5321
5720
  }
@@ -5331,6 +5730,10 @@ ${this.pendingRecoveredAgentsNotice}
5331
5730
  taskId: meta.monitorId,
5332
5731
  status: meta.status,
5333
5732
  kind: "monitor",
5733
+ continuesTodoStopGuardWorkChain: this.#monitorContinuesTodoStopGuardWorkChain(
5734
+ meta.monitorId,
5735
+ meta.ownerAgentId
5736
+ ),
5334
5737
  toolUseId: meta.toolUseId
5335
5738
  });
5336
5739
  });
@@ -5341,7 +5744,8 @@ ${this.pendingRecoveredAgentsNotice}
5341
5744
  modelText,
5342
5745
  taskId: meta.shellId,
5343
5746
  status: meta.status,
5344
- kind: "shell"
5747
+ kind: "shell",
5748
+ continuesTodoStopGuardWorkChain: !this.todoStopGuardBackgroundBaseline.shells.has(meta.shellId)
5345
5749
  });
5346
5750
  });
5347
5751
  this.config.getChatRecordingService()?.setTitleRecordedCallback((customTitle, titleSource, sessionId) => {
@@ -5473,7 +5877,12 @@ ${this.pendingRecoveredAgentsNotice}
5473
5877
  if (ac.signal.aborted) return;
5474
5878
  await this.#emitBackgroundNotificationDisplay(item);
5475
5879
  const notificationParts = [{ text: item.modelText }];
5476
- this.config.getChatRecordingService()?.recordNotification(notificationParts, item.displayText);
5880
+ this.config.getChatRecordingService()?.recordNotification(notificationParts, item.displayText, {
5881
+ taskId: item.taskId,
5882
+ status: item.status,
5883
+ kind: item.kind,
5884
+ toolUseId: item.toolUseId
5885
+ });
5477
5886
  const notificationReminders = await this.#buildInitialSystemReminders();
5478
5887
  let nextMessage = {
5479
5888
  role: "user",
@@ -5926,7 +6335,7 @@ ${this.pendingRecoveredAgentsNotice}
5926
6335
  * sequential batch to preserve the implicit ordering the model may rely
5927
6336
  * on. Response-part ordering matches the original `functionCalls` order.
5928
6337
  */
5929
- async runToolCalls(abortSignal, promptId, functionCalls, toolLoopState) {
6338
+ async runToolCalls(abortSignal, promptId, functionCalls, toolLoopState, onFullTurnModel) {
5930
6339
  const dedupedFunctionCalls = dedupeToolCallsById(functionCalls);
5931
6340
  const generatedCallIdBase = randomUUID();
5932
6341
  const executionCallIds = new Map(
@@ -6203,7 +6612,8 @@ ${this.pendingRecoveredAgentsNotice}
6203
6612
  toolLoopState,
6204
6613
  recordSkippedToolCall,
6205
6614
  queueToolResultRecord,
6206
- executionCallIds.get(calls[i])
6615
+ executionCallIds.get(calls[i]),
6616
+ onFullTurnModel
6207
6617
  );
6208
6618
  results[i] = r;
6209
6619
  if (r.loopDetected) {
@@ -6237,7 +6647,8 @@ ${this.pendingRecoveredAgentsNotice}
6237
6647
  toolLoopState,
6238
6648
  recordSkippedToolCall,
6239
6649
  queueToolResultRecord,
6240
- executionCallIds.get(calls[idx])
6650
+ executionCallIds.get(calls[idx]),
6651
+ onFullTurnModel
6241
6652
  ).then((r) => {
6242
6653
  results[idx] = r;
6243
6654
  }).finally(() => {
@@ -6361,7 +6772,8 @@ ${this.pendingRecoveredAgentsNotice}
6361
6772
  toolLoopState,
6362
6773
  recordSkippedToolCall,
6363
6774
  queueToolResultRecord,
6364
- executionCallIds.get(fc)
6775
+ executionCallIds.get(fc),
6776
+ onFullTurnModel
6365
6777
  );
6366
6778
  parts.push(...r.parts);
6367
6779
  collectMemoryWriteCandidates(r);
@@ -6426,7 +6838,7 @@ ${this.pendingRecoveredAgentsNotice}
6426
6838
  }
6427
6839
  return reminders;
6428
6840
  }
6429
- async runTool(abortSignal, promptId, fc, onStopAfterPermissionCancel, toolLoopState, recordSkippedToolCall, queueToolResultRecord, generatedCallId) {
6841
+ async runTool(abortSignal, promptId, fc, onStopAfterPermissionCancel, toolLoopState, recordSkippedToolCall, queueToolResultRecord, generatedCallId, onFullTurnModel) {
6430
6842
  const callId = fc.id ?? generatedCallId ?? `${fc.name}-${Date.now()}`;
6431
6843
  let args = fc.args ?? {};
6432
6844
  if (toolLoopState?.loopDetected) {
@@ -6542,7 +6954,8 @@ ${this.pendingRecoveredAgentsNotice}
6542
6954
  call_id: callId,
6543
6955
  tool_name: policyToolName
6544
6956
  },
6545
- tool.description
6957
+ tool.description,
6958
+ promptId
6546
6959
  );
6547
6960
  let spanSuccess = false;
6548
6961
  try {
@@ -6581,6 +6994,10 @@ ${this.pendingRecoveredAgentsNotice}
6581
6994
  let toolBuildSucceeded = false;
6582
6995
  try {
6583
6996
  const invocation = tool.build(args);
6997
+ if (policyToolName === ToolNames.MONITOR) {
6998
+ const callIdAware = invocation;
6999
+ callIdAware.setCallId?.(callId);
7000
+ }
6584
7001
  toolBuildSucceeded = true;
6585
7002
  const taskEventEmitter = invocation.eventEmitter;
6586
7003
  if (isAgentTool && taskEventEmitter) {
@@ -7096,6 +7513,33 @@ ${this.pendingRecoveredAgentsNotice}
7096
7513
  );
7097
7514
  }
7098
7515
  }
7516
+ const continuedAgentId = toolName === ToolNames.SEND_MESSAGE && typeof args["task_id"] === "string" && args["task_id"].length > 0 ? args["task_id"] : void 0;
7517
+ const provisionalRelatedAgent = continuedAgentId !== void 0 && !this.relatedAgentIds.has(continuedAgentId);
7518
+ if (provisionalRelatedAgent) {
7519
+ this.provisionalRelatedAgentCounts.set(
7520
+ continuedAgentId,
7521
+ (this.provisionalRelatedAgentCounts.get(continuedAgentId) ?? 0) + 1
7522
+ );
7523
+ }
7524
+ let relatedAgentSettled = false;
7525
+ const settleRelatedAgent = /* @__PURE__ */ __name((succeeded2) => {
7526
+ if (relatedAgentSettled || !provisionalRelatedAgent || !continuedAgentId) {
7527
+ return;
7528
+ }
7529
+ relatedAgentSettled = true;
7530
+ const remaining = (this.provisionalRelatedAgentCounts.get(continuedAgentId) ?? 1) - 1;
7531
+ if (remaining > 0) {
7532
+ this.provisionalRelatedAgentCounts.set(
7533
+ continuedAgentId,
7534
+ remaining
7535
+ );
7536
+ } else {
7537
+ this.provisionalRelatedAgentCounts.delete(continuedAgentId);
7538
+ }
7539
+ if (succeeded2) {
7540
+ this.relatedAgentIds.add(continuedAgentId);
7541
+ }
7542
+ }, "settleRelatedAgent");
7099
7543
  const execSpan = startToolExecutionSpan();
7100
7544
  let toolResult;
7101
7545
  let isExecutionTimeout = false;
@@ -7155,6 +7599,7 @@ ${this.pendingRecoveredAgentsNotice}
7155
7599
  }
7156
7600
  isExecutionTimeout = toolResult.error?.type === "execution_timeout" /* EXECUTION_TIMEOUT */;
7157
7601
  aborted = activeToolAbortSignal.aborted && !isExecutionTimeout;
7602
+ settleRelatedAgent(!toolResult.error && !aborted);
7158
7603
  endToolExecutionSpan(execSpan, {
7159
7604
  success: !toolResult.error && !aborted,
7160
7605
  error: aborted ? "tool_cancelled" : isExecutionTimeout ? "tool_timeout" : toolResult.error ? "tool_error" : void 0,
@@ -7162,6 +7607,7 @@ ${this.pendingRecoveredAgentsNotice}
7162
7607
  ...heartbeatSpanAttributes()
7163
7608
  });
7164
7609
  } catch (execError) {
7610
+ settleRelatedAgent(false);
7165
7611
  endToolExecutionSpan(execSpan, {
7166
7612
  success: false,
7167
7613
  error: activeToolAbortSignal.aborted ? "tool_cancelled" : "tool_exception",
@@ -7177,7 +7623,7 @@ ${this.pendingRecoveredAgentsNotice}
7177
7623
  this.#clearTodoStopGuardTrustAndDrainAutomaticQueues();
7178
7624
  }
7179
7625
  }
7180
- const responseParts = toolResult.error ? convertToFunctionErrorResponse(
7626
+ let responseParts = toolResult.error ? convertToFunctionErrorResponse(
7181
7627
  toolName,
7182
7628
  callId,
7183
7629
  toolResult.llmContent,
@@ -7255,6 +7701,18 @@ ${this.pendingRecoveredAgentsNotice}
7255
7701
  artifacts: failureHookResult.artifacts
7256
7702
  });
7257
7703
  }
7704
+ const visionBridgeNotices = [];
7705
+ responseParts = await bridgeToolResultImages({
7706
+ config: this.config,
7707
+ responseParts,
7708
+ signal: activeToolAbortSignal,
7709
+ onFullTurnModel,
7710
+ onVisionBridgeNotice: /* @__PURE__ */ __name((notice) => visionBridgeNotices.push(notice), "onVisionBridgeNotice")
7711
+ });
7712
+ const visionBridgeNotice = visionBridgeNotices.length > 0 ? visionBridgeNotices.join("\n") : void 0;
7713
+ if (visionBridgeNotice) {
7714
+ await this.messageEmitter.emitAgentMessage(visionBridgeNotice);
7715
+ }
7258
7716
  if (isTodoWriteTool) {
7259
7717
  const todos = this.planEmitter.extractTodos(
7260
7718
  toolResult.returnDisplay,
@@ -7298,6 +7756,7 @@ ${this.pendingRecoveredAgentsNotice}
7298
7756
  callId,
7299
7757
  status,
7300
7758
  resultDisplay: toolResult.returnDisplay,
7759
+ ...visionBridgeNotice !== void 0 ? { visionBridgeNotice } : {},
7301
7760
  error: toolResult.error ? new Error(toolResult.error.message) : void 0,
7302
7761
  errorType: toolResult.error?.type
7303
7762
  }
@@ -7986,7 +8445,8 @@ function serializeMonitorTask(entry, now) {
7986
8445
  ...optionalField("pid", entry.pid),
7987
8446
  ...optionalField("exitCode", entry.exitCode),
7988
8447
  ...optionalField("error", entry.error),
7989
- ...optionalField("ownerAgentId", entry.ownerAgentId)
8448
+ ...optionalField("ownerAgentId", entry.ownerAgentId),
8449
+ ...optionalField("toolUseId", entry.toolUseId)
7990
8450
  };
7991
8451
  }
7992
8452
  __name(serializeMonitorTask, "serializeMonitorTask");
@@ -9657,7 +10117,97 @@ async function deliverClientMcpMessage(connection, serverName, message, sessionI
9657
10117
  return payload;
9658
10118
  }
9659
10119
  __name(deliverClientMcpMessage, "deliverClientMcpMessage");
10120
+ function readRuntimeMcpRequest(params) {
10121
+ const name = params["name"];
10122
+ if (typeof name !== "string" || name.length === 0) {
10123
+ throw RequestError.invalidParams(void 0, "Invalid or missing name");
10124
+ }
10125
+ if (!isValidServerName(name)) {
10126
+ throw RequestError.invalidParams(
10127
+ void 0,
10128
+ "Server name must be \u2264256 chars, alphanumeric + underscore/hyphen, and not a reserved JS property name"
10129
+ );
10130
+ }
10131
+ const originatorClientId = params["originatorClientId"];
10132
+ return {
10133
+ name,
10134
+ runtimeClientId: typeof originatorClientId === "string" && originatorClientId.length > 0 ? originatorClientId : "daemon"
10135
+ };
10136
+ }
10137
+ __name(readRuntimeMcpRequest, "readRuntimeMcpRequest");
10138
+ function readRuntimeMcpAddRequest(params) {
10139
+ const request = readRuntimeMcpRequest(params);
10140
+ const config = params["config"];
10141
+ if (!config || typeof config !== "object" || Array.isArray(config)) {
10142
+ throw RequestError.invalidParams(void 0, "Invalid or missing config");
10143
+ }
10144
+ const {
10145
+ trust: _trust,
10146
+ authProviderType: _auth,
10147
+ includeTools: _inc,
10148
+ excludeTools: _exc,
10149
+ cwd: _cwd,
10150
+ env: _env,
10151
+ oauth: _oauth,
10152
+ headers: _headers,
10153
+ type: _type,
10154
+ [CLIENT_MCP_OVER_WS_CONFIG_FLAG]: clientMcpOverWs,
10155
+ ...safeConfig
10156
+ } = config;
10157
+ if (clientMcpOverWs === true) {
10158
+ safeConfig["type"] = "sdk";
10159
+ }
10160
+ return {
10161
+ ...request,
10162
+ config: safeConfig
10163
+ };
10164
+ }
10165
+ __name(readRuntimeMcpAddRequest, "readRuntimeMcpAddRequest");
10166
+ function getRuntimeMcpManager(config) {
10167
+ const manager = config.getToolRegistry()?.getMcpClientManager();
10168
+ if (!manager) {
10169
+ throw RequestError.internalError(
10170
+ void 0,
10171
+ "McpClientManager unavailable on this Config"
10172
+ );
10173
+ }
10174
+ return manager;
10175
+ }
10176
+ __name(getRuntimeMcpManager, "getRuntimeMcpManager");
10177
+ async function addRuntimeMcpServer(manager, request) {
10178
+ try {
10179
+ return await manager.addRuntimeMcpServer(
10180
+ request.name,
10181
+ request.config,
10182
+ request.runtimeClientId
10183
+ );
10184
+ } catch (err) {
10185
+ if (err instanceof McpBudgetWouldExceedError) {
10186
+ throw new RequestError(-32099, err.message, {
10187
+ errorKind: err.code,
10188
+ serverName: err.serverName
10189
+ });
10190
+ }
10191
+ if (err instanceof McpServerSpawnFailedError) {
10192
+ throw new RequestError(-32099, err.message, {
10193
+ errorKind: err.code,
10194
+ serverName: err.serverName,
10195
+ ...err.details
10196
+ });
10197
+ }
10198
+ if (err instanceof InvalidMcpConfigError) {
10199
+ throw new RequestError(-32099, err.message, {
10200
+ errorKind: err.code,
10201
+ serverName: err.serverName,
10202
+ reason: err.reason
10203
+ });
10204
+ }
10205
+ throw err;
10206
+ }
10207
+ }
10208
+ __name(addRuntimeMcpServer, "addRuntimeMcpServer");
9660
10209
  async function runAcpAgent(config, settings, argv, options) {
10210
+ const sessionWriterLeaseEnabledAtStartup = typeof config.isSessionWriterLeaseEnabled === "function" ? config.isSessionWriterLeaseEnabled() : settings.merged.experimental?.sessionWriterLease === true;
9661
10211
  const privateParentCapability = options === void 0 ? process.env[PRIVATE_ACP_CAPABILITY_ENV] : options.privateParentCapability;
9662
10212
  delete process.env[PRIVATE_ACP_CAPABILITY_ENV];
9663
10213
  let acpConnection;
@@ -9697,12 +10247,31 @@ async function runAcpAgent(config, settings, argv, options) {
9697
10247
  console.info = console.error;
9698
10248
  console.debug = console.error;
9699
10249
  let initializeRequestId;
10250
+ const pendingNewSessionRequestIds = /* @__PURE__ */ new Set();
9700
10251
  const stream = ndJsonStream(stdout, stdin, {
9701
10252
  onMessageObserved: /* @__PURE__ */ __name(({ direction, message }) => {
9702
- if (direction === "received" && "id" in message && "method" in message && message.method === "initialize") {
9703
- initializeRequestId = message.id;
10253
+ if (direction === "received" && "id" in message && "method" in message) {
10254
+ if (message.method === "session/new") {
10255
+ pendingNewSessionRequestIds.add(message.id);
10256
+ } else if (message.method === "initialize") {
10257
+ initializeRequestId = message.id;
10258
+ }
9704
10259
  return;
9705
10260
  }
10261
+ if (direction === "sent" && "id" in message && !("method" in message) && pendingNewSessionRequestIds.delete(message.id) && "result" in message && typeof message.result === "object" && message.result !== null && "sessionId" in message.result && typeof message.result.sessionId === "string") {
10262
+ const sessionId = message.result.sessionId;
10263
+ setImmediate(() => {
10264
+ const session = agentInstance?.getActiveSessions().find((candidate) => candidate.getId() === sessionId);
10265
+ if (!session) return;
10266
+ void preloadContentGenerator(
10267
+ session.getConfig().getContentGenerator()
10268
+ ).catch((error) => {
10269
+ debugLogger7.debug(
10270
+ `[ACP] Session provider preload failed for ${sessionId}: ${error instanceof Error ? error.message : String(error)}`
10271
+ );
10272
+ });
10273
+ }).unref();
10274
+ }
9706
10275
  if (direction !== "sent" || initializeRequestId === void 0 || !("id" in message) || "method" in message || message.id !== initializeRequestId) {
9707
10276
  return;
9708
10277
  }
@@ -9721,7 +10290,8 @@ async function runAcpAgent(config, settings, argv, options) {
9721
10290
  settings,
9722
10291
  argv,
9723
10292
  conn,
9724
- privateParentCapability
10293
+ privateParentCapability,
10294
+ sessionWriterLeaseEnabledAtStartup
9725
10295
  );
9726
10296
  return agentInstance;
9727
10297
  }, stream);
@@ -9730,29 +10300,34 @@ async function runAcpAgent(config, settings, argv, options) {
9730
10300
  eventLoopMonitor.dispose();
9731
10301
  throw err;
9732
10302
  }
9733
- const drainPoolBeforeExit = /* @__PURE__ */ __name(async (label) => {
10303
+ const drainPoolBeforeExit = /* @__PURE__ */ __name(async (label, strict = false) => {
9734
10304
  if (!agentInstance) return;
9735
10305
  try {
9736
10306
  await agentInstance.shutdownMcpPool(8e3);
9737
10307
  } catch (err) {
9738
10308
  debugLogger7.error(`[ACP] MCP pool drain (${label}) error:`, err);
10309
+ if (strict) throw err;
9739
10310
  }
9740
10311
  }, "drainPoolBeforeExit");
9741
10312
  let shuttingDown = false;
10313
+ let managedShutdownPromise;
9742
10314
  let sessionEndFired = false;
9743
- const fireSessionEndOnce = /* @__PURE__ */ __name(async (reason) => {
10315
+ const fireSessionEndOnce = /* @__PURE__ */ __name(async (reason, managedConfigs) => {
9744
10316
  if (sessionEndFired) return;
9745
10317
  sessionEndFired = true;
9746
- const configs = /* @__PURE__ */ new Set([config]);
9747
- const sessions = agentInstance?.getActiveSessions();
9748
- if (sessions) {
9749
- for (const session of sessions) {
9750
- const sessionConfig = session.getConfig?.();
9751
- if (sessionConfig) {
9752
- configs.add(sessionConfig);
10318
+ const configs = new Set(managedConfigs ?? [config]);
10319
+ if (!managedConfigs) {
10320
+ const sessions = agentInstance?.getActiveSessions();
10321
+ if (sessions) {
10322
+ for (const session of sessions) {
10323
+ const sessionConfig = session.getConfig?.();
10324
+ if (sessionConfig) {
10325
+ configs.add(sessionConfig);
10326
+ }
9753
10327
  }
9754
10328
  }
9755
10329
  }
10330
+ const failures = [];
9756
10331
  for (const cfg of configs) {
9757
10332
  const hookSystem = cfg.getHookSystem?.();
9758
10333
  const hooksEnabled = !cfg.getDisableAllHooks?.();
@@ -9760,18 +10335,101 @@ async function runAcpAgent(config, settings, argv, options) {
9760
10335
  continue;
9761
10336
  }
9762
10337
  try {
9763
- await hookSystem.fireSessionEndEvent(reason);
9764
- } catch (err) {
9765
- debugLogger7.warn(
9766
- `SessionEnd hook failed: ${err instanceof Error ? err.message : String(err)}`
9767
- );
10338
+ await hookSystem.fireSessionEndEvent(reason);
10339
+ } catch (err) {
10340
+ if (managedConfigs) failures.push(err);
10341
+ debugLogger7.warn(
10342
+ `SessionEnd hook failed: ${err instanceof Error ? err.message : String(err)}`
10343
+ );
10344
+ }
10345
+ }
10346
+ if (failures.length > 0) {
10347
+ throw new AggregateError(failures, "SessionEnd hook shutdown failed");
10348
+ }
10349
+ }, "fireSessionEndOnce");
10350
+ const shutdownManagedAgent = /* @__PURE__ */ __name((reason, label) => {
10351
+ if (managedShutdownPromise) return managedShutdownPromise;
10352
+ const agent = agentInstance;
10353
+ if (!agent?.isTrustedManagedParent()) {
10354
+ return Promise.reject(
10355
+ new Error("Managed shutdown requires a trusted private parent")
10356
+ );
10357
+ }
10358
+ const terminal = agent.beginManagedShutdown();
10359
+ managedShutdownPromise = (async () => {
10360
+ const failures = [];
10361
+ try {
10362
+ await terminal.writerShutdown;
10363
+ } catch (error) {
10364
+ failures.push(error);
10365
+ debugLogger7.error("[ACP] Managed writer shutdown error:", error);
10366
+ const retainedLockPaths = terminal.configs.flatMap((config2) => {
10367
+ if (typeof config2.getSessionRuntimeBaseDir !== "function" || typeof config2.getSessionId !== "function") {
10368
+ return [];
10369
+ }
10370
+ return [
10371
+ path4.join(
10372
+ config2.getSessionRuntimeBaseDir(),
10373
+ "tmp",
10374
+ "session-writer-locks",
10375
+ `${encodeURIComponent(config2.getSessionId())}.lock`
10376
+ )
10377
+ ];
10378
+ });
10379
+ writeStderrLineSafe(
10380
+ "qwen --acp: managed session writer shutdown failed; a writer lock may be retained for safety. Verify that no previous writer is running before manual cleanup." + (retainedLockPaths.length > 0 ? ` Candidate lock paths: ${retainedLockPaths.join(", ")}` : "")
10381
+ );
10382
+ }
10383
+ try {
10384
+ await fireSessionEndOnce(reason, terminal.configs);
10385
+ } catch (error) {
10386
+ failures.push(error);
10387
+ }
10388
+ try {
10389
+ await agent.finishManagedShutdown(terminal.configs);
10390
+ } catch (error) {
10391
+ failures.push(error);
10392
+ debugLogger7.error("[ACP] Managed resource shutdown error:", error);
10393
+ }
10394
+ try {
10395
+ await drainPoolBeforeExit(label, true);
10396
+ } catch (error) {
10397
+ failures.push(error);
9768
10398
  }
9769
- }
9770
- }, "fireSessionEndOnce");
10399
+ try {
10400
+ await runExitCleanup();
10401
+ } catch (error) {
10402
+ failures.push(error);
10403
+ debugLogger7.error("[ACP] Cleanup error:", error);
10404
+ }
10405
+ if (failures.length > 0) {
10406
+ throw new AggregateError(failures, "Managed ACP shutdown failed");
10407
+ }
10408
+ })();
10409
+ return managedShutdownPromise;
10410
+ }, "shutdownManagedAgent");
9771
10411
  const shutdownHandler = /* @__PURE__ */ __name(async () => {
9772
10412
  if (shuttingDown) return;
9773
10413
  shuttingDown = true;
9774
10414
  debugLogger7.debug("[ACP] Shutdown signal received, closing streams");
10415
+ if (agentInstance?.isTrustedManagedParent()) {
10416
+ let exitCode = 0;
10417
+ try {
10418
+ await shutdownManagedAgent("other" /* Other */, "signal");
10419
+ } catch (err) {
10420
+ exitCode = 1;
10421
+ debugLogger7.error("[ACP] Managed shutdown error:", err);
10422
+ } finally {
10423
+ eventLoopMonitor.dispose();
10424
+ }
10425
+ try {
10426
+ process.stdin.destroy();
10427
+ process.stdout.destroy();
10428
+ } catch {
10429
+ }
10430
+ process.exit(exitCode);
10431
+ return;
10432
+ }
9775
10433
  try {
9776
10434
  await fireSessionEndOnce("other" /* Other */);
9777
10435
  await agentInstance?.disposeSessions();
@@ -9799,9 +10457,21 @@ async function runAcpAgent(config, settings, argv, options) {
9799
10457
  process.on("SIGINT", shutdownHandler);
9800
10458
  try {
9801
10459
  await connection.closed;
9802
- await fireSessionEndOnce("prompt_input_exit" /* PromptInputExit */);
9803
- await drainPoolBeforeExit("ide_close");
9804
- await agentInstance?.disposeSessions();
10460
+ if (agentInstance?.isTrustedManagedParent()) {
10461
+ try {
10462
+ await shutdownManagedAgent(
10463
+ "prompt_input_exit" /* PromptInputExit */,
10464
+ "ide_close"
10465
+ );
10466
+ } catch (error) {
10467
+ process.exitCode = 1;
10468
+ throw error;
10469
+ }
10470
+ } else {
10471
+ await fireSessionEndOnce("prompt_input_exit" /* PromptInputExit */);
10472
+ await drainPoolBeforeExit("ide_close");
10473
+ await agentInstance?.disposeSessions();
10474
+ }
9805
10475
  } finally {
9806
10476
  process.off("SIGTERM", shutdownHandler);
9807
10477
  process.off("SIGINT", shutdownHandler);
@@ -9918,12 +10588,13 @@ function parseAcpSessionListCursor(value) {
9918
10588
  }
9919
10589
  __name(parseAcpSessionListCursor, "parseAcpSessionListCursor");
9920
10590
  var QwenAgent = class {
9921
- constructor(config, settings, argv, connection, expectedPrivateParentCapability) {
10591
+ constructor(config, settings, argv, connection, expectedPrivateParentCapability, sessionWriterLeaseEnabledAtStartup = false) {
9922
10592
  this.config = config;
9923
10593
  this.settings = settings;
9924
10594
  this.argv = argv;
9925
10595
  this.connection = connection;
9926
10596
  this.expectedPrivateParentCapability = expectedPrivateParentCapability;
10597
+ this.sessionWriterLeaseEnabledAtStartup = sessionWriterLeaseEnabledAtStartup;
9927
10598
  if (process.env["QWEN_SERVE_NO_MCP_POOL"] === "1") {
9928
10599
  this.mcpPool = void 0;
9929
10600
  this.workspaceMcpBudget = void 0;
@@ -9964,6 +10635,8 @@ var QwenAgent = class {
9964
10635
  workspaceGenerationControllers = /* @__PURE__ */ new Map();
9965
10636
  transcriptReplayConfigCache = /* @__PURE__ */ new Map();
9966
10637
  pendingConfigCleanup = /* @__PURE__ */ new Map();
10638
+ initializingConfigs = /* @__PURE__ */ new Set();
10639
+ managedShuttingDown = false;
9967
10640
  clientCapabilities;
9968
10641
  privateParentState = "uninitialized";
9969
10642
  // CPU-usage delta baseline for the daemon's `workspaceResource` extMethod
@@ -9997,6 +10670,102 @@ var QwenAgent = class {
9997
10670
  getActiveSessions() {
9998
10671
  return [...this.sessions.values()];
9999
10672
  }
10673
+ isTrustedManagedParent() {
10674
+ return this.privateParentState === "trusted";
10675
+ }
10676
+ assertManagedSessionAdmission() {
10677
+ if (this.expectedPrivateParentCapability !== void 0 && !this.isTrustedManagedParent()) {
10678
+ throw RequestError.invalidParams(
10679
+ void 0,
10680
+ "Private ACP parent is not initialized"
10681
+ );
10682
+ }
10683
+ if (this.managedShuttingDown) {
10684
+ throw new SessionWriterUnavailableError();
10685
+ }
10686
+ }
10687
+ beginManagedShutdown() {
10688
+ if (!this.isTrustedManagedParent()) {
10689
+ throw new Error("Managed shutdown requires a trusted private parent");
10690
+ }
10691
+ this.managedShuttingDown = true;
10692
+ for (const generation of this.generationControllers.values()) {
10693
+ generation.controller.abort();
10694
+ }
10695
+ this.generationControllers.clear();
10696
+ for (const controller of this.workspaceGenerationControllers.values()) {
10697
+ controller.abort();
10698
+ }
10699
+ this.workspaceGenerationControllers.clear();
10700
+ const configs = /* @__PURE__ */ new Set([this.config, ...this.initializingConfigs]);
10701
+ for (const session of this.sessions.values()) {
10702
+ try {
10703
+ session.beginCloseIfAvailable();
10704
+ } catch (error) {
10705
+ debugLogger7.debug(
10706
+ `Session ${session.getId()} admission close during managed shutdown failed: ${error instanceof Error ? error.message : String(error)}`
10707
+ );
10708
+ }
10709
+ void session.cancelPendingPrompt().catch((error) => {
10710
+ debugLogger7.debug(
10711
+ `Session ${session.getId()} cancel during managed shutdown failed: ${error instanceof Error ? error.message : String(error)}`
10712
+ );
10713
+ });
10714
+ configs.add(session.getConfig());
10715
+ }
10716
+ for (const pending of this.pendingConfigCleanup.values()) {
10717
+ for (const config of pending) configs.add(config);
10718
+ }
10719
+ const configList = [...configs];
10720
+ const writerTerminals = [];
10721
+ for (const config of configList) {
10722
+ try {
10723
+ writerTerminals.push(config.closeSessionWriter());
10724
+ } catch (error) {
10725
+ writerTerminals.push(Promise.reject(error));
10726
+ }
10727
+ }
10728
+ const writerShutdown = Promise.allSettled(writerTerminals).then(
10729
+ (results) => {
10730
+ const failures = results.flatMap(
10731
+ (result) => result.status === "rejected" ? [result.reason] : []
10732
+ );
10733
+ if (failures.length > 0) {
10734
+ throw new AggregateError(
10735
+ failures,
10736
+ "Managed session writer shutdown failed"
10737
+ );
10738
+ }
10739
+ }
10740
+ );
10741
+ return { configs: configList, writerShutdown };
10742
+ }
10743
+ async finishManagedShutdown(configs) {
10744
+ const failures = [];
10745
+ for (const [sessionId, session] of [...this.sessions]) {
10746
+ await this.removeStoredSessionEntry(sessionId, session, failures, {
10747
+ shutdownConfig: false
10748
+ });
10749
+ }
10750
+ const results = await Promise.allSettled(
10751
+ configs.map(
10752
+ (config) => config.shutdown({
10753
+ shutdownTelemetry: false,
10754
+ skipSessionWriter: true,
10755
+ strictResourceCleanup: true
10756
+ })
10757
+ )
10758
+ );
10759
+ for (const result of results) {
10760
+ if (result.status === "rejected") failures.push(result.reason);
10761
+ }
10762
+ this.initializingConfigs.clear();
10763
+ this.pendingConfigCleanup.clear();
10764
+ this.disposeTranscriptReplayConfigs();
10765
+ if (failures.length > 0) {
10766
+ throw new AggregateError(failures, "Managed session cleanup failed");
10767
+ }
10768
+ }
10000
10769
  getWorkspaceMcpConfig(serverName) {
10001
10770
  if (serverName && this.config.getRuntimeMcpServers?.()[serverName] !== void 0) {
10002
10771
  return this.config;
@@ -10139,16 +10908,18 @@ var QwenAgent = class {
10139
10908
  for (const config of liveConfigs) {
10140
10909
  try {
10141
10910
  const cwd = config.getTargetDir();
10142
- const mcpServers = assembleMcpServers(
10911
+ const isBareOrSafe = config.getBareMode() || config.isSafeMode();
10912
+ const mcpServers = isBareOrSafe ? { ...config.getTopTierMcpServers() } : assembleMcpServers(
10143
10913
  settings.merged.mcpServers,
10144
10914
  cwd,
10145
10915
  config.getTopTierMcpServers()
10146
10916
  );
10147
- const gating = recomputeMcpGating(
10917
+ const bootAllowed = config.getCliAllowedMcpServerNames();
10918
+ const gating = isBareOrSafe ? { allowed: bootAllowed ? [...bootAllowed] : void 0 } : recomputeMcpGating(
10148
10919
  settings,
10149
10920
  mcpServers,
10150
10921
  cwd,
10151
- config.getCliAllowedMcpServerNames(),
10922
+ bootAllowed,
10152
10923
  config.getApprovalMode() === "yolo" /* YOLO */
10153
10924
  );
10154
10925
  config.setExcludedMcpServers(gating.excluded ?? []);
@@ -10241,11 +11012,15 @@ var QwenAgent = class {
10241
11012
  debugLogger7.warn(
10242
11013
  `MCP pool drain: ${result.drained} clean, ${result.forced} timed out, ${result.errors.length} errors`
10243
11014
  );
11015
+ throw new Error(
11016
+ `MCP pool drain incomplete: ${result.forced} forced, ${result.errors.length} errors`
11017
+ );
10244
11018
  }
10245
11019
  } catch (err) {
10246
11020
  debugLogger7.error(
10247
11021
  `MCP pool drainAll failed: ${err instanceof Error ? err.message : String(err)}`
10248
11022
  );
11023
+ throw err;
10249
11024
  }
10250
11025
  }
10251
11026
  async removeStoredSessionEntry(sessionId, session, cleanupErrors = [], options = {}) {
@@ -10316,11 +11091,13 @@ var QwenAgent = class {
10316
11091
  try {
10317
11092
  await shutdownSessionConfig(config);
10318
11093
  } catch (error) {
11094
+ this.initializingConfigs.delete(config);
10319
11095
  const pending2 = this.pendingConfigCleanup.get(cleanupKey) ?? /* @__PURE__ */ new Set();
10320
11096
  pending2.add(config);
10321
11097
  this.pendingConfigCleanup.set(cleanupKey, pending2);
10322
11098
  throw mapSessionWriterRequestError(error);
10323
11099
  }
11100
+ this.initializingConfigs.delete(config);
10324
11101
  const pending = this.pendingConfigCleanup.get(cleanupKey);
10325
11102
  pending?.delete(config);
10326
11103
  if (pending?.size === 0) {
@@ -10335,7 +11112,7 @@ var QwenAgent = class {
10335
11112
  `Session cleanup failed while preserving the original request error: ${cleanupError instanceof Error ? cleanupError.message : String(cleanupError)}`
10336
11113
  );
10337
11114
  }
10338
- throw error;
11115
+ throw mapSessionWriterRequestError(error);
10339
11116
  }
10340
11117
  pendingConfigCleanupKey(runtimeBaseDir, sessionId) {
10341
11118
  return `${path4.resolve(runtimeBaseDir)}\0${sessionId}`;
@@ -10525,7 +11302,7 @@ var QwenAgent = class {
10525
11302
  }
10526
11303
  this.clientCapabilities = args.clientCapabilities;
10527
11304
  const authMethods = buildAuthMethods();
10528
- const version = "0.21.0-nightly.20260727.c003e1718";
11305
+ const version = "0.21.0-preview.0";
10529
11306
  const response = {
10530
11307
  protocolVersion: PROTOCOL_VERSION,
10531
11308
  agentInfo: {
@@ -10720,16 +11497,59 @@ var QwenAgent = class {
10720
11497
  const sessionData = config.getResumedSessionData();
10721
11498
  const bulkReplay = isBulkLoadReplayRequest(params);
10722
11499
  const replayPageSize = bulkReplay ? getLoadReplayPageSize(params) : void 0;
10723
- let session;
11500
+ let replayEnvelope;
10724
11501
  try {
10725
11502
  await this.ensureAuthenticated(config);
10726
11503
  this.setupFileSystem(config);
10727
- session = await this.createAndStoreSession(
10728
- config,
10729
- settings,
10730
- sessionData,
10731
- bulkReplay ? { replayHistory: false, startPostReplayServices: false } : {}
10732
- );
11504
+ await this.createAndStoreSession(config, settings, sessionData, {
11505
+ ...bulkReplay ? { replayHistory: false } : {},
11506
+ beforeStartPostReplayServices: /* @__PURE__ */ __name(async (createdSession) => {
11507
+ if (bulkReplay) {
11508
+ const records = sessionData?.conversation.messages;
11509
+ let replayUpdates = [];
11510
+ if (records) {
11511
+ createdSession.primeTurnFromHistory(records);
11512
+ const replayPage = selectRecentHistoryRecords(
11513
+ records,
11514
+ replayPageSize
11515
+ );
11516
+ const replayUsage = createReplayCumulativeUsage();
11517
+ const replay = await collectHistoryReplayUpdates({
11518
+ sessionId: params.sessionId,
11519
+ config,
11520
+ records: replayPage.records,
11521
+ gaps: sessionData?.historyGaps,
11522
+ cumulativeUsage: replayUsage,
11523
+ supersedeUnrestorableGoal: true,
11524
+ logger: debugLogger7
11525
+ });
11526
+ replayUpdates = replay.updates;
11527
+ copyCumulativeUsage(createdSession.cumulativeUsage, replayUsage);
11528
+ if (replay.replayError !== void 0) {
11529
+ replayEnvelope = {
11530
+ v: LOAD_REPLAY_VERSION,
11531
+ updates: replayUpdates,
11532
+ partial: true,
11533
+ replayError: replay.replayError,
11534
+ ...replayPage.hasMore ? { hasMore: true } : {}
11535
+ };
11536
+ }
11537
+ replayEnvelope ??= {
11538
+ v: LOAD_REPLAY_VERSION,
11539
+ updates: replayUpdates,
11540
+ ...replayPage.hasMore ? { hasMore: true } : {}
11541
+ };
11542
+ }
11543
+ replayEnvelope ??= {
11544
+ v: LOAD_REPLAY_VERSION,
11545
+ updates: replayUpdates
11546
+ };
11547
+ }
11548
+ await this.#restoreWorktreeOnResume(config, createdSession);
11549
+ await this.#restoreBackgroundAgentsOnResume(config, createdSession);
11550
+ this.#restoreGoalOnResume(config, createdSession);
11551
+ }, "beforeStartPostReplayServices")
11552
+ });
10733
11553
  } catch (error) {
10734
11554
  return this.cleanupAfterRequestFailure(error, async () => {
10735
11555
  if (this.sessions.get(config.getSessionId())?.getConfig() !== config) {
@@ -10737,72 +11557,6 @@ var QwenAgent = class {
10737
11557
  }
10738
11558
  });
10739
11559
  }
10740
- let replayEnvelope;
10741
- if (bulkReplay) {
10742
- try {
10743
- const records = sessionData?.conversation.messages;
10744
- let replayUpdates = [];
10745
- if (records) {
10746
- session.primeTurnFromHistory(records);
10747
- const replayPage = selectRecentHistoryRecords(
10748
- records,
10749
- replayPageSize
10750
- );
10751
- const replayUsage = createReplayCumulativeUsage();
10752
- const replay = await collectHistoryReplayUpdates({
10753
- sessionId: params.sessionId,
10754
- config,
10755
- records: replayPage.records,
10756
- gaps: sessionData?.historyGaps,
10757
- cumulativeUsage: replayUsage,
10758
- // A resume: the goal restore runs right after this.
10759
- supersedeUnrestorableGoal: true,
10760
- logger: debugLogger7
10761
- });
10762
- replayUpdates = replay.updates;
10763
- copyCumulativeUsage(session.cumulativeUsage, replayUsage);
10764
- if (replay.replayError !== void 0) {
10765
- replayEnvelope = {
10766
- v: LOAD_REPLAY_VERSION,
10767
- updates: replayUpdates,
10768
- partial: true,
10769
- replayError: replay.replayError,
10770
- ...replayPage.hasMore ? { hasMore: true } : {}
10771
- };
10772
- }
10773
- replayEnvelope ??= {
10774
- v: LOAD_REPLAY_VERSION,
10775
- updates: replayUpdates,
10776
- ...replayPage.hasMore ? { hasMore: true } : {}
10777
- };
10778
- }
10779
- replayEnvelope ??= {
10780
- v: LOAD_REPLAY_VERSION,
10781
- updates: replayUpdates
10782
- };
10783
- session.installRewriter();
10784
- session.startCronScheduler();
10785
- } catch (err) {
10786
- return this.cleanupAfterRequestFailure(err, async () => {
10787
- try {
10788
- await this.discardStoredSessionIfCurrent(params.sessionId, session);
10789
- } catch (cleanupError) {
10790
- await this.removeStoredSessionEntry(
10791
- params.sessionId,
10792
- session,
10793
- [cleanupError],
10794
- {
10795
- shutdownConfig: false
10796
- }
10797
- );
10798
- await this.cleanupUnstoredConfig(config);
10799
- }
10800
- });
10801
- }
10802
- }
10803
- await this.#restoreWorktreeOnResume(config, session);
10804
- await this.#restoreBackgroundAgentsOnResume(config, session);
10805
- this.#restoreGoalOnResume(config, session);
10806
11560
  const modesData = this.buildModesData(config);
10807
11561
  const availableModels = this.buildAvailableModels(config);
10808
11562
  const configOptions = this.buildConfigOptions(config);
@@ -10858,15 +11612,21 @@ var QwenAgent = class {
10858
11612
  params.sessionId,
10859
11613
  true
10860
11614
  );
10861
- let session;
10862
11615
  try {
10863
11616
  await this.ensureAuthenticated(config);
10864
11617
  this.setupFileSystem(config);
10865
- session = await this.createAndStoreSession(
11618
+ await this.createAndStoreSession(
10866
11619
  config,
10867
11620
  settings,
10868
11621
  config.getResumedSessionData(),
10869
- { replayHistory: false }
11622
+ {
11623
+ replayHistory: false,
11624
+ beforeStartPostReplayServices: /* @__PURE__ */ __name(async (createdSession) => {
11625
+ await this.#restoreWorktreeOnResume(config, createdSession);
11626
+ await this.#restoreBackgroundAgentsOnResume(config, createdSession);
11627
+ this.#restoreGoalOnResume(config, createdSession);
11628
+ }, "beforeStartPostReplayServices")
11629
+ }
10870
11630
  );
10871
11631
  } catch (error) {
10872
11632
  return this.cleanupAfterRequestFailure(error, async () => {
@@ -10875,9 +11635,6 @@ var QwenAgent = class {
10875
11635
  }
10876
11636
  });
10877
11637
  }
10878
- await this.#restoreWorktreeOnResume(config, session);
10879
- await this.#restoreBackgroundAgentsOnResume(config, session);
10880
- this.#restoreGoalOnResume(config, session);
10881
11638
  const modesData = this.buildModesData(config);
10882
11639
  const availableModels = this.buildAvailableModels(config);
10883
11640
  const configOptions = this.buildConfigOptions(config);
@@ -12900,12 +13657,19 @@ var QwenAgent = class {
12900
13657
  }
12901
13658
  case TODO_STOP_GUARD_QUEUE_RELEASE_METHOD: {
12902
13659
  const sessionId = params["sessionId"];
13660
+ const promptId = params["promptId"];
12903
13661
  if (typeof sessionId !== "string" || sessionId.length === 0) {
12904
13662
  throw RequestError.invalidParams(
12905
13663
  void 0,
12906
13664
  "Invalid or missing sessionId"
12907
13665
  );
12908
13666
  }
13667
+ if (typeof promptId !== "string" || promptId.length === 0) {
13668
+ throw RequestError.invalidParams(
13669
+ void 0,
13670
+ "Invalid or missing promptId"
13671
+ );
13672
+ }
12909
13673
  const session = this.sessions.get(sessionId);
12910
13674
  if (!session) {
12911
13675
  throw RequestError.invalidParams(
@@ -12914,7 +13678,7 @@ var QwenAgent = class {
12914
13678
  );
12915
13679
  }
12916
13680
  return {
12917
- released: session.releaseTodoStopGuardQueuedPromptWait()
13681
+ released: session.releaseTodoStopGuardQueuedPromptWait(promptId)
12918
13682
  };
12919
13683
  }
12920
13684
  case "qwen/providers/list": {
@@ -14335,10 +15099,12 @@ var QwenAgent = class {
14335
15099
  }
14336
15100
  }
14337
15101
  const previousCwd = config.getTargetDir();
14338
- if (canonicalPath === previousCwd) {
14339
- return { previousCwd, newCwd: canonicalPath, warnings: [] };
14340
- }
14341
- if (isFolderTrustEnabled(this.settings.merged)) {
15102
+ let trustValidated = false;
15103
+ const validateTrust = /* @__PURE__ */ __name(() => {
15104
+ if (!isFolderTrustEnabled(this.settings.merged)) {
15105
+ trustValidated = true;
15106
+ return;
15107
+ }
14342
15108
  const trustedFolders = loadTrustedFolders();
14343
15109
  if (trustedFolders.isPathTrusted(canonicalPath) !== true) {
14344
15110
  throw new RequestError(
@@ -14347,27 +15113,62 @@ var QwenAgent = class {
14347
15113
  { errorKind: "directory_not_trusted", path: canonicalPath }
14348
15114
  );
14349
15115
  }
15116
+ trustValidated = true;
15117
+ }, "validateTrust");
15118
+ if (canonicalPath !== previousCwd) {
15119
+ validateTrust();
14350
15120
  }
14351
- const warnings = [];
14352
- const relocation = await config.relocateWorkingDirectory(
14353
- canonicalPath,
14354
- canonicalPath,
14355
- { skipProcessChdir: true, skipArtifactMigration: true }
15121
+ const releaseGate = await beginSessionCloseAfterCurrentGate(
15122
+ session,
15123
+ SESSION_DRAIN_TIMEOUT_MS
14356
15124
  );
14357
- if (relocation.memoryRefreshError) {
14358
- warnings.push(
14359
- `Memory refresh failed: ${relocation.memoryRefreshError instanceof Error ? relocation.memoryRefreshError.message : String(relocation.memoryRefreshError)}`
14360
- );
14361
- }
14362
15125
  try {
14363
- await config.getGeminiClient()?.addWorkingDirectoryChangedContext(previousCwd, canonicalPath);
14364
- } catch (error) {
14365
- warnings.push(
14366
- `Model context refresh failed: ${error instanceof Error ? error.message : String(error)}`
15126
+ const settledPreviousCwd = config.getTargetDir();
15127
+ if (canonicalPath === settledPreviousCwd) {
15128
+ return {
15129
+ previousCwd: settledPreviousCwd,
15130
+ newCwd: canonicalPath,
15131
+ warnings: []
15132
+ };
15133
+ }
15134
+ if (!trustValidated) {
15135
+ validateTrust();
15136
+ }
15137
+ session.hardSuspendTodoStopGuard();
15138
+ await waitForSessionDrain(
15139
+ session.waitForActiveTurnsToSettle(),
15140
+ SESSION_DRAIN_TIMEOUT_MS,
15141
+ "close"
14367
15142
  );
15143
+ const warnings = [];
15144
+ const relocation = await config.relocateWorkingDirectory(
15145
+ canonicalPath,
15146
+ canonicalPath,
15147
+ { skipProcessChdir: true, skipArtifactMigration: true }
15148
+ );
15149
+ if (relocation.memoryRefreshError) {
15150
+ warnings.push(
15151
+ `Memory refresh failed: ${relocation.memoryRefreshError instanceof Error ? relocation.memoryRefreshError.message : String(relocation.memoryRefreshError)}`
15152
+ );
15153
+ }
15154
+ try {
15155
+ await config.getGeminiClient()?.addWorkingDirectoryChangedContext(
15156
+ settledPreviousCwd,
15157
+ canonicalPath
15158
+ );
15159
+ } catch (error) {
15160
+ warnings.push(
15161
+ `Model context refresh failed: ${error instanceof Error ? error.message : String(error)}`
15162
+ );
15163
+ }
15164
+ return {
15165
+ previousCwd: settledPreviousCwd,
15166
+ newCwd: canonicalPath,
15167
+ warnings
15168
+ };
15169
+ } finally {
15170
+ releaseGate();
14368
15171
  }
14369
- session.clearTodoStopGuardTrust();
14370
- return { previousCwd, newCwd: canonicalPath, warnings };
14371
15172
  }
14372
15173
  case SERVE_CONTROL_EXT_METHODS.sessionApprovalMode: {
14373
15174
  const sessionId = params["sessionId"];
@@ -14883,147 +15684,82 @@ ${outputText}
14883
15684
  return result;
14884
15685
  }
14885
15686
  case SERVE_CONTROL_EXT_METHODS.workspaceMcpRuntimeAdd: {
14886
- const name = params["name"];
14887
- const config = params["config"];
14888
- const originatorClientId = params["originatorClientId"];
14889
- if (typeof name !== "string" || name.length === 0) {
14890
- throw RequestError.invalidParams(
14891
- void 0,
14892
- "Invalid or missing name"
14893
- );
14894
- }
14895
- if (!isValidServerName(name)) {
14896
- throw RequestError.invalidParams(
14897
- void 0,
14898
- "Server name must be \u2264256 chars, alphanumeric + underscore/hyphen, and not a reserved JS property name"
14899
- );
14900
- }
14901
- if (!config || typeof config !== "object" || Array.isArray(config)) {
14902
- throw RequestError.invalidParams(
14903
- void 0,
14904
- "Invalid or missing config"
14905
- );
14906
- }
14907
- const runtimeClientId = typeof originatorClientId === "string" && originatorClientId.length > 0 ? originatorClientId : "daemon";
14908
- const manager = this.config.getToolRegistry()?.getMcpClientManager();
14909
- if (!manager) {
14910
- throw RequestError.internalError(
14911
- void 0,
14912
- "McpClientManager unavailable on this Config"
14913
- );
14914
- }
14915
- try {
14916
- const {
14917
- trust: _trust,
14918
- authProviderType: _auth,
14919
- includeTools: _inc,
14920
- excludeTools: _exc,
14921
- cwd: _cwd,
14922
- env: _env,
14923
- oauth: _oauth,
14924
- headers: _headers,
14925
- type: _type,
14926
- // Reverse tool channel marker (issue #5626, Phase 2). The parent
14927
- // serve process stamps this on a client-hosted (extension) MCP
14928
- // server's runtime config; it never reaches the transport itself.
14929
- [CLIENT_MCP_OVER_WS_CONFIG_FLAG]: clientMcpOverWs,
14930
- ...safeConfig
14931
- } = config;
14932
- if (clientMcpOverWs === true) {
14933
- safeConfig["type"] = "sdk";
14934
- }
14935
- const result = await manager.addRuntimeMcpServer(
14936
- name,
14937
- safeConfig,
14938
- runtimeClientId
14939
- );
14940
- await Promise.all(
14941
- this.getActiveSessions().map(async (session) => {
14942
- const sessionManager = session.getConfig().getToolRegistry()?.getMcpClientManager();
14943
- if (!sessionManager) return;
14944
- try {
14945
- await sessionManager.addRuntimeMcpServer(
14946
- name,
14947
- safeConfig,
14948
- runtimeClientId
14949
- );
14950
- } catch (sessionErr) {
14951
- debugLogger7.warn(
14952
- `workspaceMcpRuntimeAdd: failed to add runtime MCP server '${name}' to active session ${session.getConfig().getSessionId()}: ${sessionErr instanceof Error ? sessionErr.message : String(sessionErr)}`
14953
- );
14954
- }
14955
- })
14956
- );
14957
- return result;
14958
- } catch (err) {
14959
- if (err instanceof McpBudgetWouldExceedError) {
14960
- throw new RequestError(-32099, err.message, {
14961
- errorKind: err.code,
14962
- serverName: err.serverName
14963
- });
14964
- }
14965
- if (err instanceof McpServerSpawnFailedError) {
14966
- throw new RequestError(-32099, err.message, {
14967
- errorKind: err.code,
14968
- serverName: err.serverName,
14969
- ...err.details
14970
- });
14971
- }
14972
- if (err instanceof InvalidMcpConfigError) {
14973
- throw new RequestError(-32099, err.message, {
14974
- errorKind: err.code,
14975
- serverName: err.serverName,
14976
- reason: err.reason
14977
- });
14978
- }
14979
- throw err;
14980
- }
15687
+ const request = readRuntimeMcpAddRequest(params);
15688
+ const result = await addRuntimeMcpServer(
15689
+ getRuntimeMcpManager(this.config),
15690
+ request
15691
+ );
15692
+ await Promise.all(
15693
+ this.getActiveSessions().map(async (session) => {
15694
+ const sessionManager = session.getConfig().getToolRegistry()?.getMcpClientManager();
15695
+ if (!sessionManager) return;
15696
+ try {
15697
+ await sessionManager.addRuntimeMcpServer(
15698
+ request.name,
15699
+ request.config,
15700
+ request.runtimeClientId
15701
+ );
15702
+ } catch (sessionErr) {
15703
+ debugLogger7.warn(
15704
+ `workspaceMcpRuntimeAdd: failed to add runtime MCP server '${request.name}' to active session ${session.getConfig().getSessionId()}: ${sessionErr instanceof Error ? sessionErr.message : String(sessionErr)}`
15705
+ );
15706
+ }
15707
+ })
15708
+ );
15709
+ return result;
14981
15710
  }
14982
15711
  case SERVE_CONTROL_EXT_METHODS.workspaceMcpRuntimeRemove: {
14983
- const name = params["name"];
14984
- const originatorClientId = params["originatorClientId"];
14985
- if (typeof name !== "string" || name.length === 0) {
14986
- throw RequestError.invalidParams(
14987
- void 0,
14988
- "Invalid or missing name"
14989
- );
14990
- }
14991
- if (!isValidServerName(name)) {
14992
- throw RequestError.invalidParams(
14993
- void 0,
14994
- "Server name must be \u2264256 chars, alphanumeric + underscore/hyphen, and not a reserved JS property name"
14995
- );
14996
- }
14997
- const runtimeClientId = typeof originatorClientId === "string" && originatorClientId.length > 0 ? originatorClientId : "daemon";
14998
- const manager = this.config.getToolRegistry()?.getMcpClientManager();
14999
- if (!manager) {
15000
- throw RequestError.internalError(
15001
- void 0,
15002
- "McpClientManager unavailable on this Config"
15003
- );
15004
- }
15005
- const result = await manager.removeRuntimeMcpServer(
15006
- name,
15007
- runtimeClientId
15008
- );
15712
+ const request = readRuntimeMcpRequest(params);
15713
+ const result = await getRuntimeMcpManager(
15714
+ this.config
15715
+ ).removeRuntimeMcpServer(request.name, request.runtimeClientId);
15009
15716
  await Promise.all(
15010
15717
  this.getActiveSessions().map(async (session) => {
15011
15718
  const sessionManager = session.getConfig().getToolRegistry()?.getMcpClientManager();
15012
15719
  if (!sessionManager) return;
15013
15720
  try {
15014
15721
  await sessionManager.removeRuntimeMcpServer(
15015
- name,
15016
- runtimeClientId
15722
+ request.name,
15723
+ request.runtimeClientId
15017
15724
  );
15018
15725
  } catch (sessionErr) {
15019
15726
  debugLogger7.warn(
15020
- `workspaceMcpRuntimeRemove: failed to remove runtime MCP server '${name}' from active session ${session.getConfig().getSessionId()}: ${sessionErr instanceof Error ? sessionErr.message : String(sessionErr)}`
15727
+ `workspaceMcpRuntimeRemove: failed to remove runtime MCP server '${request.name}' from active session ${session.getConfig().getSessionId()}: ${sessionErr instanceof Error ? sessionErr.message : String(sessionErr)}`
15021
15728
  );
15022
15729
  }
15023
15730
  })
15024
15731
  );
15025
15732
  return result;
15026
15733
  }
15734
+ case SERVE_CONTROL_EXT_METHODS.sessionMcpRuntimeAdd: {
15735
+ const sessionId = params["sessionId"];
15736
+ if (typeof sessionId !== "string" || sessionId.length === 0) {
15737
+ throw RequestError.invalidParams(
15738
+ void 0,
15739
+ "Invalid or missing sessionId"
15740
+ );
15741
+ }
15742
+ const session = this.sessionOrThrow(sessionId);
15743
+ return addRuntimeMcpServer(
15744
+ getRuntimeMcpManager(session.getConfig()),
15745
+ readRuntimeMcpAddRequest(params)
15746
+ );
15747
+ }
15748
+ case SERVE_CONTROL_EXT_METHODS.sessionMcpRuntimeRemove: {
15749
+ const sessionId = params["sessionId"];
15750
+ if (typeof sessionId !== "string" || sessionId.length === 0) {
15751
+ throw RequestError.invalidParams(
15752
+ void 0,
15753
+ "Invalid or missing sessionId"
15754
+ );
15755
+ }
15756
+ const session = this.sessionOrThrow(sessionId);
15757
+ const request = readRuntimeMcpRequest(params);
15758
+ const result = await getRuntimeMcpManager(
15759
+ session.getConfig()
15760
+ ).removeRuntimeMcpServer(request.name, request.runtimeClientId);
15761
+ return result;
15762
+ }
15027
15763
  case SERVE_CONTROL_EXT_METHODS.workspaceExtensionsRefresh: {
15028
15764
  const sessionId = params["sessionId"];
15029
15765
  const session = this.sessionOrThrow(sessionId);
@@ -15839,6 +16575,7 @@ ${outputText}
15839
16575
  }
15840
16576
  async newSessionConfig(cwd, mcpServers, settings, sessionId, resume, initializeOptions = {}, chatRecording) {
15841
16577
  try {
16578
+ this.assertManagedSessionAdmission();
15842
16579
  return await this.runWithPinnedRuntimeBaseDir(settings, cwd, async () => {
15843
16580
  await this.retryPendingConfigCleanup(
15844
16581
  Storage.getRuntimeBaseDir(),
@@ -15916,7 +16653,13 @@ ${outputText}
15916
16653
  continue;
15917
16654
  }
15918
16655
  }
15919
- const mergedSettings = settings.merged;
16656
+ const mergedSettings = {
16657
+ ...settings.merged,
16658
+ experimental: {
16659
+ ...settings.merged.experimental,
16660
+ sessionWriterLease: this.sessionWriterLeaseEnabledAtStartup
16661
+ }
16662
+ };
15920
16663
  const sessionArg = resume === true ? { resume: sessionId, sessionId: void 0 } : { sessionId, resume: void 0 };
15921
16664
  const argvForSession = {
15922
16665
  ...this.argv,
@@ -15951,6 +16694,20 @@ ${outputText}
15951
16694
  buildDisabledSkillNamesProvider(settings),
15952
16695
  sessionMcpServers
15953
16696
  );
16697
+ if (chatRecording !== false) {
16698
+ this.initializingConfigs.add(config);
16699
+ }
16700
+ try {
16701
+ this.assertManagedSessionAdmission();
16702
+ if (this.isTrustedManagedParent()) {
16703
+ config.setSessionWriterReclaimPolicy("never");
16704
+ }
16705
+ } catch (error) {
16706
+ return this.cleanupAfterRequestFailure(
16707
+ error,
16708
+ () => this.cleanupUnstoredConfig(config)
16709
+ );
16710
+ }
15954
16711
  if (!initializeOptions.skipFileCheckpointing && typeof config.enableFileCheckpointing === "function") {
15955
16712
  config.enableFileCheckpointing();
15956
16713
  }
@@ -15991,6 +16748,7 @@ ${outputText}
15991
16748
  // (the daemon only adds SDK-type runtime servers for client MCP).
15992
16749
  sendSdkMcpMessage: this.buildClientMcpSender(wiredSessionId)
15993
16750
  });
16751
+ this.assertManagedSessionAdmission();
15994
16752
  } catch (error) {
15995
16753
  return this.cleanupAfterRequestFailure(
15996
16754
  error,
@@ -16051,17 +16809,20 @@ ${outputText}
16051
16809
  config.setFileSystemService(acpFileSystemService);
16052
16810
  }
16053
16811
  async createAndStoreSession(config, settings, sessionData, options = {}) {
16812
+ this.assertManagedSessionAdmission();
16054
16813
  const sessionId = config.getSessionId();
16055
16814
  const geminiClient = config.getGeminiClient();
16056
16815
  const needsInitialize = !geminiClient.isInitialized();
16057
16816
  if (needsInitialize) {
16058
16817
  await geminiClient.initialize();
16059
16818
  }
16819
+ this.assertManagedSessionAdmission();
16060
16820
  if (this.sessions.has(sessionId)) {
16061
16821
  throw new Error(`Session ${sessionId} is already active.`);
16062
16822
  }
16063
16823
  const session = new Session(sessionId, config, this.connection, settings);
16064
16824
  this.sessions.set(sessionId, session);
16825
+ this.initializingConfigs.delete(config);
16065
16826
  try {
16066
16827
  if (sessionData?.fileHistorySnapshots?.length) {
16067
16828
  config.getFileHistoryService().restoreFromSnapshots(sessionData.fileHistorySnapshots);
@@ -16075,10 +16836,9 @@ ${outputText}
16075
16836
  sessionData.historyGaps
16076
16837
  );
16077
16838
  }
16078
- if (options.startPostReplayServices !== false) {
16079
- session.installRewriter();
16080
- session.startCronScheduler();
16081
- }
16839
+ await options.beforeStartPostReplayServices?.(session);
16840
+ session.installRewriter();
16841
+ session.startCronScheduler();
16082
16842
  setTimeout(() => {
16083
16843
  void session.sendAvailableCommandsUpdate();
16084
16844
  }, 0);