@qwen-code/qwen-code 0.21.4 → 0.21.5-nightly.20260805.32e274157

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 (260) hide show
  1. package/bundled/qc-helper/docs/configuration/model-providers.md +8 -7
  2. package/bundled/qc-helper/docs/configuration/settings.md +16 -16
  3. package/bundled/qc-helper/docs/features/code-review.md +4 -0
  4. package/bundled/qc-helper/docs/features/headless.md +31 -0
  5. package/bundled/qc-helper/docs/features/mcp.md +11 -3
  6. package/bundled/qc-helper/docs/qwen-serve.md +75 -0
  7. package/bundled/review/SKILL.md +90 -52
  8. package/chunks/{MaxSizedBox-5XDFQHTQ.js → MaxSizedBox-H44SGRP7.js} +17 -16
  9. package/chunks/{StandaloneSessionPicker-DLADA54K.js → StandaloneSessionPicker-T5FQMYD3.js} +31 -30
  10. package/chunks/{acpAgent-MVEFZSBS.js → acpAgent-J474KXVM.js} +849 -313
  11. package/chunks/{agent-RB6LCRZX.js → agent-SC23IV5L.js} +17 -16
  12. package/chunks/{agent-headless-272ZACJV.js → agent-headless-2CHR5WJP.js} +17 -16
  13. package/chunks/{artifact-tool-TBOYEKTY.js → artifact-tool-RROCCJDA.js} +1 -1
  14. package/chunks/{askUserQuestion-23Y5WZFJ.js → askUserQuestion-2EPPBPUZ.js} +1 -1
  15. package/chunks/{bridge-GXUXFSHK.js → bridge-BLHYPCCR.js} +21 -19
  16. package/chunks/{channel-settings-store-5UA2SABE.js → channel-settings-store-CDOZ7GCP.js} +22 -21
  17. package/chunks/{channel-worker-group-NDG4WOOZ.js → channel-worker-group-SVGPDH2C.js} +3 -2
  18. package/chunks/{channel-worker-manager-ZCW6UW34.js → channel-worker-manager-72ZK2GTS.js} +3 -2
  19. package/chunks/{channel-worker-supervisor-ATGFTZRN.js → channel-worker-supervisor-NUEDVHX4.js} +2 -1
  20. package/chunks/{chunk-PWCQRLM5.js → chunk-2AGOQ7QO.js} +1 -1
  21. package/chunks/{chunk-AFJSRJTO.js → chunk-2B6FBVWE.js} +1 -1
  22. package/chunks/{chunk-XPAY4EMH.js → chunk-2OSE7Q5O.js} +3 -3
  23. package/chunks/{chunk-DHNFB7NC.js → chunk-2QOLRESU.js} +5 -5
  24. package/chunks/{chunk-UWSXFI6E.js → chunk-2U7GPHA6.js} +6 -2
  25. package/chunks/{chunk-CIUUYB23.js → chunk-3DTM3RPU.js} +1 -1
  26. package/chunks/{chunk-X6QNZOTC.js → chunk-3PRJYMXC.js} +2 -2
  27. package/chunks/{chunk-6KQUOXT5.js → chunk-3XDH6PZM.js} +7 -7
  28. package/chunks/{chunk-DJA7YBLJ.js → chunk-56MC5OM7.js} +2 -2
  29. package/chunks/{chunk-B3EBXISV.js → chunk-5DVP76WL.js} +90 -7
  30. package/chunks/{chunk-2T3RYG4L.js → chunk-5KDLX7ER.js} +919 -323
  31. package/chunks/{chunk-O2ZYHG33.js → chunk-5L6CQ4ZU.js} +131 -67
  32. package/chunks/{chunk-E2SYUEIA.js → chunk-5OAMVWFL.js} +874 -375
  33. package/chunks/{chunk-LPLMUGIM.js → chunk-5X76FZLI.js} +5 -5
  34. package/chunks/{chunk-M2L4TMH3.js → chunk-6HTEECQY.js} +3 -3
  35. package/chunks/{chunk-KHSJSMFS.js → chunk-6I6WUVYI.js} +1 -1
  36. package/chunks/{chunk-LLMGP5IC.js → chunk-6WBWIPBF.js} +2 -2
  37. package/chunks/{chunk-PQ5JFCNL.js → chunk-762UTZQZ.js} +3 -3
  38. package/chunks/{chunk-HBCKZF2A.js → chunk-7EW7CYLA.js} +1 -1
  39. package/chunks/{chunk-4PZ7SPD5.js → chunk-7FKLLD4X.js} +1 -1
  40. package/chunks/{chunk-XSOAW7FC.js → chunk-AE7AKP3E.js} +6 -6
  41. package/chunks/{chunk-UATJZOAJ.js → chunk-ASS3UQB5.js} +3 -3
  42. package/chunks/{chunk-XGA6XHH3.js → chunk-AXOFMDZC.js} +3 -3
  43. package/chunks/chunk-BKHCW2BI.js +41 -0
  44. package/chunks/{chunk-DZPOYHBT.js → chunk-D6FISK43.js} +1 -1
  45. package/chunks/{chunk-CFDR3GNL.js → chunk-D7D7RXIJ.js} +11 -0
  46. package/chunks/{chunk-FPPVCCAH.js → chunk-DNPP267F.js} +1 -1
  47. package/chunks/{chunk-I32URQI7.js → chunk-EA2CKB6L.js} +5 -5
  48. package/chunks/{chunk-C5YFS6VR.js → chunk-EL4W7MGQ.js} +4 -4
  49. package/chunks/{chunk-QXTGHZCX.js → chunk-FDLXWNCE.js} +3 -3
  50. package/chunks/{chunk-PCVMRBLN.js → chunk-FFCSRU3F.js} +1 -1
  51. package/chunks/{chunk-SV5X2EUV.js → chunk-FMU2QVA5.js} +1 -1
  52. package/chunks/{chunk-2ON2O4MD.js → chunk-FV2JYSWS.js} +28 -3
  53. package/chunks/{chunk-KB6VSG2U.js → chunk-GXP44JOS.js} +7 -7
  54. package/chunks/{chunk-BC4LTKEG.js → chunk-HP6MKLWU.js} +1 -1
  55. package/chunks/{chunk-YXEVDA66.js → chunk-HU5TUALO.js} +110 -22
  56. package/chunks/{chunk-2JN5V3I7.js → chunk-ITZK3L4S.js} +1 -1
  57. package/chunks/{chunk-5XGI4IPK.js → chunk-JEVHOCCA.js} +4 -4
  58. package/chunks/{chunk-6ME3PVMM.js → chunk-JNFWMBG6.js} +5 -5
  59. package/chunks/{chunk-3PHUGFPH.js → chunk-JXPOBM4B.js} +1 -1
  60. package/chunks/{chunk-TXZDRD36.js → chunk-LCCBAGRT.js} +5 -5
  61. package/chunks/{chunk-G7XXKQYS.js → chunk-LKRMNRSN.js} +27 -1
  62. package/chunks/{chunk-DOCBJIBL.js → chunk-MB3ILUB7.js} +1 -1
  63. package/chunks/{chunk-HFVW54NL.js → chunk-MBEMTXQT.js} +9 -2
  64. package/chunks/{chunk-RNKGMZEW.js → chunk-MFTOMYE2.js} +1 -1
  65. package/chunks/{chunk-RPYYTL7E.js → chunk-MGSSJT27.js} +2 -2
  66. package/chunks/{chunk-URVJ4AZC.js → chunk-MKMUBBEX.js} +1 -1
  67. package/chunks/{chunk-RL2NPV5E.js → chunk-N5QPOGRQ.js} +1 -1
  68. package/chunks/{chunk-2CCUHZP5.js → chunk-N7PF4KZR.js} +2 -2
  69. package/chunks/{chunk-JDJ7SC4E.js → chunk-NMBDPO63.js} +255 -197
  70. package/chunks/{chunk-M6RNMBUO.js → chunk-NQZ5IVLH.js} +4 -4
  71. package/chunks/{chunk-FV4TUUDE.js → chunk-O4WOWHMZ.js} +1 -1
  72. package/chunks/{chunk-GDREW3U5.js → chunk-OIVG6IHL.js} +2 -2
  73. package/chunks/{chunk-IMGNGOGC.js → chunk-PQ2J56BJ.js} +3 -3
  74. package/chunks/{chunk-EJXATV5R.js → chunk-PWFDZA5A.js} +2 -2
  75. package/chunks/{chunk-OOPFAIWP.js → chunk-Q7EXR3W2.js} +1 -1
  76. package/chunks/{chunk-4CTV3FZH.js → chunk-QJL2AQZI.js} +23 -19
  77. package/chunks/{chunk-SBBHZ3YT.js → chunk-QKWPXGW4.js} +1 -1
  78. package/chunks/{chunk-HI4YGRJD.js → chunk-RDICVTQC.js} +3 -3
  79. package/chunks/{chunk-ZRQY5BBS.js → chunk-REAWLQAU.js} +10 -10
  80. package/chunks/{chunk-BOWKLLWA.js → chunk-SOBA6GIW.js} +3 -3
  81. package/chunks/{chunk-WDLQGFWP.js → chunk-TYWI5NXY.js} +27 -27
  82. package/chunks/{chunk-A7PONO5G.js → chunk-URJHXOSO.js} +2 -2
  83. package/chunks/{chunk-C6FU76AA.js → chunk-V3BNVUFI.js} +1 -1
  84. package/chunks/{chunk-G6KI6B5L.js → chunk-VF6WPN4R.js} +1 -1
  85. package/chunks/{chunk-AWTLFUVN.js → chunk-VT27B2XS.js} +13 -13
  86. package/chunks/{chunk-O4IWFYUW.js → chunk-VY4TEQQ6.js} +4 -4
  87. package/chunks/{chunk-EIAPOG76.js → chunk-WECYW5EE.js} +4 -4
  88. package/chunks/{chunk-PDDYAXL2.js → chunk-WIRAPZ62.js} +7 -0
  89. package/chunks/chunk-WOJZWRAZ.js +123 -0
  90. package/chunks/{chunk-7UXI6P72.js → chunk-WVAESIM6.js} +2 -2
  91. package/chunks/{chunk-P5UJMCVS.js → chunk-XIDYVC4P.js} +4 -4
  92. package/chunks/{chunk-THLV7YGY.js → chunk-XIKKANF4.js} +2 -2
  93. package/chunks/{chunk-FHPKHXHT.js → chunk-XNZBXQCG.js} +4 -0
  94. package/chunks/{chunk-ZLJQIGCH.js → chunk-XZCMQUOF.js} +8 -0
  95. package/chunks/{chunk-PQEIKQXN.js → chunk-YJMFRTLV.js} +24 -6
  96. package/chunks/{chunk-QZQ72YF6.js → chunk-Z26UXKZE.js} +1 -1
  97. package/chunks/{chunk-VA5NLVPT.js → chunk-Z7JILXGX.js} +1 -1
  98. package/chunks/{chunk-UEJESCS7.js → chunk-ZPPP6VCL.js} +1 -1
  99. package/chunks/{computer-use-MDOMIVTL.js → computer-use-ENYMKQAI.js} +17 -16
  100. package/chunks/{config-utils-E3ZQTHGM.js → config-utils-LIRO7NSU.js} +2 -2
  101. package/chunks/{contextCommand-FCK3CB37.js → contextCommand-E7XMHU6M.js} +19 -18
  102. package/chunks/{core-runtime-UHRHHU2O.js → core-runtime-KDIRQ63A.js} +17 -16
  103. package/chunks/{create-sub-session-J32WC64U.js → create-sub-session-6EWLAZD5.js} +1 -1
  104. package/chunks/{create-sub-session-MIXUVLWW.js → create-sub-session-VVEL77UF.js} +17 -16
  105. package/chunks/{cron-create-HMFSHIAR.js → cron-create-CCRIULJE.js} +1 -1
  106. package/chunks/{cron-delete-ZJFHOX57.js → cron-delete-FCFW6BGP.js} +1 -1
  107. package/chunks/{cron-list-ZEX2NBMN.js → cron-list-QDBVCHRF.js} +1 -1
  108. package/chunks/{daemon-status-provider-6LC7LUNR.js → daemon-status-provider-4LMCSLZ4.js} +25 -23
  109. package/chunks/{daemon-trust-policy-Y36HGRAM.js → daemon-trust-policy-XLONWB2C.js} +22 -21
  110. package/chunks/{daemon-trust-policy-monitor-ROTBBDOH.js → daemon-trust-policy-monitor-FHFZ3NNG.js} +22 -21
  111. package/chunks/{deferred-core-runtime-ZQ4JIAJD.js → deferred-core-runtime-QNEBJ3DP.js} +17 -16
  112. package/chunks/{display-image-2WOG27DY.js → display-image-GUJA352B.js} +2 -2
  113. package/chunks/{earlyInputCapture-GPRUNXTP.js → earlyInputCapture-OG5IUF4R.js} +17 -16
  114. package/chunks/{edit-YK3UP6D2.js → edit-E2WNOITJ.js} +18 -17
  115. package/chunks/{enter-worktree-QMVQW7UG.js → enter-worktree-RMCBAAA2.js} +17 -16
  116. package/chunks/{enterPlanMode-TZAYQ5MP.js → enterPlanMode-GISFJA3O.js} +17 -16
  117. package/chunks/{environment-3UQURCZG.js → environment-JXTQGYDN.js} +19 -18
  118. package/chunks/{errors-VBIMTNNI.js → errors-2AYTYCQ3.js} +19 -18
  119. package/chunks/{exit-worktree-4EC7LBBC.js → exit-worktree-HORS3V7Z.js} +17 -16
  120. package/chunks/{exitPlanMode-K5Y3REU2.js → exitPlanMode-V75Y36HJ.js} +17 -16
  121. package/chunks/external-tool-guard-provider-5HTGOPGU.js +273 -0
  122. package/chunks/{fast-path-KS6IE7YR.js → fast-path-HURC6JUT.js} +5 -5
  123. package/chunks/{gemini-LTUCUOJH.js → gemini-WHMD4RGY.js} +70 -55
  124. package/chunks/{geminiContentGenerator-M3HJTHKR.js → geminiContentGenerator-DZB3GPNQ.js} +1 -1
  125. package/chunks/{glob-SKUYGTF2.js → glob-IGTV723M.js} +17 -16
  126. package/chunks/{goal-tools-SPQ5M6D3.js → goal-tools-3AZKX5WQ.js} +2 -18
  127. package/chunks/{grep-SQ7RD7SV.js → grep-SJ2NYUCD.js} +17 -16
  128. package/chunks/{handleAutoUpdate-OK7OX23A.js → handleAutoUpdate-NPBKROGA.js} +21 -20
  129. package/chunks/{i18n-P77YBKY4.js → i18n-CBSMJZ3Z.js} +18 -17
  130. package/chunks/{image-gen-2ZWPS42A.js → image-gen-KNKDTUEN.js} +2 -2
  131. package/chunks/{initializer-PIOYXVW7.js → initializer-JT5P3IQF.js} +22 -21
  132. package/chunks/{installationInfo-IWMM6DPV.js → installationInfo-CZVCKPPZ.js} +18 -17
  133. package/chunks/{list-3DCR4TRI.js → list-MT7T6JVH.js} +25 -24
  134. package/chunks/{list-agents-TWEGRJWO.js → list-agents-GC4BRET7.js} +1 -1
  135. package/chunks/{loadedSettingsAdapter-EJC6CU5N.js → loadedSettingsAdapter-D4JFGYYQ.js} +22 -21
  136. package/chunks/{loggingContentGenerator-2JEFU25T.js → loggingContentGenerator-SFT5CMPU.js} +9 -8
  137. package/chunks/{loop-wakeup-6LLEOQYV.js → loop-wakeup-SQQSBMEY.js} +2 -2
  138. package/chunks/{ls-H5WX22VK.js → ls-63CC3NNX.js} +1 -1
  139. package/chunks/{lsp-G6FXYEIS.js → lsp-P6NVJVNT.js} +1 -1
  140. package/chunks/{managed-npm-update-EGVQPSBR.js → managed-npm-update-YHJW6SGD.js} +18 -17
  141. package/chunks/{mcp-KFFH2MBV.js → mcp-53X2M7XL.js} +22 -21
  142. package/chunks/{monitor-6Y3NDMTI.js → monitor-I43P3MNV.js} +17 -16
  143. package/chunks/{nonInteractiveCli-426IQDPE.js → nonInteractiveCli-UADCDERF.js} +50 -48
  144. package/chunks/{notebook-edit-373IQQLE.js → notebook-edit-WKZUONWV.js} +18 -17
  145. package/chunks/{openaiContentGenerator-PGFSOMIQ.js → openaiContentGenerator-YHF3FIYI.js} +9 -8
  146. package/chunks/{pidfile-Y4INDMHG.js → pidfile-VU37FJS4.js} +17 -16
  147. package/chunks/{processUtils-6BCPCJZW.js → processUtils-VIQVTDWH.js} +2 -2
  148. package/chunks/{qwenContentGenerator-QC3KSHSX.js → qwenContentGenerator-46476NL4.js} +18 -17
  149. package/chunks/{qwenOAuth2-IOAXKJ3L.js → qwenOAuth2-D62OJZFU.js} +1 -1
  150. package/chunks/{read-file-2T54FYZV.js → read-file-6PSNROKB.js} +7 -6
  151. package/chunks/{read-mcp-resource-DRZSI3HE.js → read-mcp-resource-RTSSEER5.js} +1 -1
  152. package/chunks/{record-artifact-IPIRWMFY.js → record-artifact-E6AWQU2Z.js} +2 -2
  153. package/chunks/{resumeHistoryUtils-O62RDCZ3.js → resumeHistoryUtils-QFD6LB7N.js} +20 -19
  154. package/chunks/{ripGrep-3H72KY7S.js → ripGrep-4WZJEOGB.js} +17 -16
  155. package/chunks/{run-qwen-serve-3AIDNNHO.js → run-qwen-serve-SEL3TISE.js} +72 -36
  156. package/chunks/{runtime-AZ4EHHFV.js → runtime-T6JAS7GL.js} +25 -24
  157. package/chunks/{scheduler-L4UUCU4Z.js → scheduler-ZCTDMJJV.js} +17 -16
  158. package/chunks/{sdk-exporters-http-IKNWQJNV.js → sdk-exporters-http-IL2346MJ.js} +6 -2
  159. package/chunks/{sdk-impl-7CUUMQDB.js → sdk-impl-SYKGVWOZ.js} +2 -2
  160. package/chunks/{send-message-LHJLVWFD.js → send-message-TL6FIMMN.js} +3 -3
  161. package/chunks/{serve-CLXGSYOE.js → serve-A7B6VWK7.js} +23 -21
  162. package/chunks/{server-MEAE3WMM.js → server-6CCTTLO4.js} +170 -63
  163. package/chunks/{session-OSLD2LT5.js → session-3YYXW6MZ.js} +51 -49
  164. package/chunks/{settings-ILWAOKA4.js → settings-KWYWA3BS.js} +21 -20
  165. package/chunks/{shell-RT5DBH6B.js → shell-6SUYJURL.js} +17 -16
  166. package/chunks/{skill-LVGA3ATZ.js → skill-ZIQFS6YD.js} +8 -7
  167. package/chunks/{skill-settings-WTZE7EPE.js → skill-settings-23IFV7S3.js} +21 -20
  168. package/chunks/{spawnChannel-BOBS7DVM.js → spawnChannel-AI7QA35U.js} +20 -18
  169. package/chunks/{standalone-update-Y5JB4S2K.js → standalone-update-WNXRFLEA.js} +19 -18
  170. package/chunks/{startInteractiveUI-ZV25CD2S.js → startInteractiveUI-NPZU6YXV.js} +76 -71
  171. package/chunks/{syntheticOutput-EYL7DWO7.js → syntheticOutput-BN7E626U.js} +2 -2
  172. package/chunks/{task-create-4ALZMGP5.js → task-create-2X4UP4F3.js} +4 -4
  173. package/chunks/{task-list-6CVQPORX.js → task-list-WOLJPZ64.js} +1 -1
  174. package/chunks/{task-stop-Y5ZTFVRX.js → task-stop-TNXRNAL2.js} +1 -1
  175. package/chunks/{task-update-IKCEEWJ6.js → task-update-VDUSN36E.js} +4 -4
  176. package/chunks/{team-create-ZVPQIXCP.js → team-create-CMF2RRF2.js} +17 -16
  177. package/chunks/{team-delete-CE7DC53R.js → team-delete-D2VMSDOT.js} +1 -1
  178. package/chunks/{team-plan-approval-5UHUBY3W.js → team-plan-approval-5EET4S3I.js} +17 -16
  179. package/chunks/{terminal-image-renderer-NWC2RALG.js → terminal-image-renderer-TCEAHDFE.js} +18 -17
  180. package/chunks/{theme-manager-5KICSBOB.js → theme-manager-RPYRQJLX.js} +17 -16
  181. package/chunks/{todoWrite-FTZWQRZH.js → todoWrite-MHWHO5UO.js} +1 -1
  182. package/chunks/{tool-search-2AOU77H4.js → tool-search-HJN53LCN.js} +9 -8
  183. package/chunks/{total-session-admission-FR7RMHVL.js → total-session-admission-4FZK4PCR.js} +21 -19
  184. package/chunks/{trustedFolders-V7UUPQXO.js → trustedFolders-RIYUQQJC.js} +18 -17
  185. package/chunks/{update-relaunch-TBWRMQD6.js → update-relaunch-3HVSJU2T.js} +5 -5
  186. package/chunks/{updateCheck-42SPCLH7.js → updateCheck-EE2XXQNJ.js} +20 -19
  187. package/chunks/{useAutoAcceptIndicator-4C2KM345.js → useAutoAcceptIndicator-RRV7MW47.js} +23 -22
  188. package/chunks/{validateNonInterActiveAuth-UVFRXV3Z.js → validateNonInterActiveAuth-3QRII2BS.js} +47 -45
  189. package/chunks/{version-HKTV6TPN.js → version-4KUHPDAC.js} +1 -1
  190. package/chunks/{web-fetch-ZRXSV5AN.js → web-fetch-MXA6HQ42.js} +7 -6
  191. package/chunks/{web-search-WOLV3L6T.js → web-search-YENHOBMC.js} +5 -4
  192. package/chunks/{workflow-F63ES3OB.js → workflow-RYEVBM4L.js} +18 -17
  193. package/chunks/{workspace-providers-status-PJMGMYMC.js → workspace-providers-status-SBTU5TWO.js} +25 -24
  194. package/chunks/{workspace-registration-store-LNBOX5TJ.js → workspace-registration-store-VUMOTODR.js} +1 -1
  195. package/chunks/{workspace-registry-4PR7VDQ3.js → workspace-registry-OZ5ZUBJ6.js} +21 -19
  196. package/chunks/{workspace-service-PVI3VUNQ.js → workspace-service-Y3IGAN4K.js} +26 -25
  197. package/chunks/{workspace-skills-status-2Q5ZISO6.js → workspace-skills-status-FXOIDGOS.js} +23 -22
  198. package/chunks/{workspace-trust-reconciler-NOILUH3C.js → workspace-trust-reconciler-DQI7MYJS.js} +26 -24
  199. package/chunks/{write-file-MOM4JDHG.js → write-file-NK4C3GFC.js} +17 -16
  200. package/chunks/{zoom-image-E3VHRCFU.js → zoom-image-4Y6Y6DAX.js} +7 -6
  201. package/cli-entry.js +14 -0
  202. package/cli.js +16 -12
  203. package/package.json +3 -3
  204. package/web-shell/assets/{arc-GpdmhIxr.js → arc-DtI1rZcQ.js} +1 -1
  205. package/web-shell/assets/{architectureDiagram-3BPJPVTR-C-LhCgH_.js → architectureDiagram-3BPJPVTR-BPZwSVct.js} +1 -1
  206. package/web-shell/assets/{blockDiagram-GPEHLZMM-CzNdTCm-.js → blockDiagram-GPEHLZMM-BIQ03j4C.js} +1 -1
  207. package/web-shell/assets/{c4Diagram-AAUBKEIU-Ce7hbrRM.js → c4Diagram-AAUBKEIU-CB0RyFGm.js} +1 -1
  208. package/web-shell/assets/channel-vfbVFuM1.js +1 -0
  209. package/web-shell/assets/{chunk-2J33WTMH-BBSEn1PK.js → chunk-2J33WTMH-B3WoS-4H.js} +1 -1
  210. package/web-shell/assets/{chunk-4BX2VUAB-_llgjfe5.js → chunk-4BX2VUAB-C98xYZ1X.js} +1 -1
  211. package/web-shell/assets/{chunk-55IACEB6-9fJZ_oZE.js → chunk-55IACEB6-CbTIWRwQ.js} +1 -1
  212. package/web-shell/assets/{chunk-727SXJPM-DgEzQWOu.js → chunk-727SXJPM-DWGnKTPu.js} +1 -1
  213. package/web-shell/assets/{chunk-AQP2D5EJ-B4RthUTc.js → chunk-AQP2D5EJ-4__QyCEX.js} +1 -1
  214. package/web-shell/assets/{chunk-FMBD7UC4-CDI-emMW.js → chunk-FMBD7UC4-DFtG1YCW.js} +1 -1
  215. package/web-shell/assets/{chunk-ND2GUHAM-jM2-yOd8.js → chunk-ND2GUHAM-rvAhW51N.js} +1 -1
  216. package/web-shell/assets/{chunk-QZHKN3VN-XGZHlKPF.js → chunk-QZHKN3VN-DfiU9pwZ.js} +1 -1
  217. package/web-shell/assets/classDiagram-4FO5ZUOK-Cvr8atq3.js +1 -0
  218. package/web-shell/assets/classDiagram-v2-Q7XG4LA2-Cvr8atq3.js +1 -0
  219. package/web-shell/assets/{cose-bilkent-S5V4N54A-90nbW1xQ.js → cose-bilkent-S5V4N54A-Cc4EIdxu.js} +1 -1
  220. package/web-shell/assets/{dagre-BM42HDAG-BtzlyqZ9.js → dagre-BM42HDAG-CZNj4dGW.js} +1 -1
  221. package/web-shell/assets/{diagram-2AECGRRQ-DAaqGWaH.js → diagram-2AECGRRQ-D5tiqQCr.js} +1 -1
  222. package/web-shell/assets/{diagram-5GNKFQAL-CxlzSIFa.js → diagram-5GNKFQAL-pwzw0jVO.js} +1 -1
  223. package/web-shell/assets/{diagram-KO2AKTUF-8kj-1H6u.js → diagram-KO2AKTUF-4CWiM00x.js} +1 -1
  224. package/web-shell/assets/{diagram-LMA3HP47-6NhjFwRF.js → diagram-LMA3HP47-Dd7rc7Qf.js} +1 -1
  225. package/web-shell/assets/{diagram-OG6HWLK6-Bn9kvInz.js → diagram-OG6HWLK6-_vzV52ml.js} +1 -1
  226. package/web-shell/assets/{erDiagram-TEJ5UH35-CaRoGsAt.js → erDiagram-TEJ5UH35-CqbE2bx_.js} +1 -1
  227. package/web-shell/assets/{flowDiagram-I6XJVG4X-TkLweHdf.js → flowDiagram-I6XJVG4X-CaxNr7w4.js} +1 -1
  228. package/web-shell/assets/{ganttDiagram-6RSMTGT7-ruwhCKBl.js → ganttDiagram-6RSMTGT7-AGjrtfUA.js} +1 -1
  229. package/web-shell/assets/{gitGraphDiagram-PVQCEYII-DNI_PxoU.js → gitGraphDiagram-PVQCEYII-ADG2zSkc.js} +1 -1
  230. package/web-shell/assets/{index-p1gz-sxE.js → index-BOryKCqt.js} +1 -1
  231. package/web-shell/assets/index-Cb1LjsCv.css +5 -0
  232. package/web-shell/assets/{index-T4KluHvu.js → index-CvJDaIy8.js} +329 -329
  233. package/web-shell/assets/{infoDiagram-5YYISTIA-DarXq1-A.js → infoDiagram-5YYISTIA-CE3B_IoZ.js} +1 -1
  234. package/web-shell/assets/{ishikawaDiagram-YF4QCWOH-GxDaDlT0.js → ishikawaDiagram-YF4QCWOH-CN-Frhoi.js} +1 -1
  235. package/web-shell/assets/{journeyDiagram-JHISSGLW-mDEoGBzY.js → journeyDiagram-JHISSGLW-CGgezS93.js} +1 -1
  236. package/web-shell/assets/{kanban-definition-UN3LZRKU-Ds0t-Mup.js → kanban-definition-UN3LZRKU-BqWijky5.js} +1 -1
  237. package/web-shell/assets/{linear-05nJ0xZ7.js → linear-D8sfpZf6.js} +1 -1
  238. package/web-shell/assets/{mermaid.core-Bua24ThM.js → mermaid.core-3PA4QrzM.js} +5 -5
  239. package/web-shell/assets/{mindmap-definition-RKZ34NQL-D_zRdvUS.js → mindmap-definition-RKZ34NQL-D9QxwiCY.js} +1 -1
  240. package/web-shell/assets/{pieDiagram-4H26LBE5-DZHr1x16.js → pieDiagram-4H26LBE5-Bioaf6uE.js} +1 -1
  241. package/web-shell/assets/{quadrantDiagram-W4KKPZXB-HA06Wf0h.js → quadrantDiagram-W4KKPZXB-DBb2AS73.js} +1 -1
  242. package/web-shell/assets/{requirementDiagram-4Y6WPE33-DH3urmJf.js → requirementDiagram-4Y6WPE33-DXOvZ3KB.js} +1 -1
  243. package/web-shell/assets/{sankeyDiagram-5OEKKPKP-C4xgz0TT.js → sankeyDiagram-5OEKKPKP-D9qg09Dm.js} +1 -1
  244. package/web-shell/assets/{sequenceDiagram-3UESZ5HK-DAUoZWgv.js → sequenceDiagram-3UESZ5HK-DSAUIfpw.js} +1 -1
  245. package/web-shell/assets/{stateDiagram-AJRCARHV-v7NzXy4l.js → stateDiagram-AJRCARHV-BPZkzfQ3.js} +1 -1
  246. package/web-shell/assets/stateDiagram-v2-BHNVJYJU-DInOqnhZ.js +1 -0
  247. package/web-shell/assets/{timeline-definition-PNZ67QCA-B3GTYR2W.js → timeline-definition-PNZ67QCA-UDaQp9sP.js} +1 -1
  248. package/web-shell/assets/{vennDiagram-CIIHVFJN-BWHjSPAq.js → vennDiagram-CIIHVFJN-2ouhAnHO.js} +1 -1
  249. package/web-shell/assets/{wardley-L42UT6IY-m9r6IUBC.js → wardley-L42UT6IY-Cq_WEvTK.js} +1 -1
  250. package/web-shell/assets/{wardleyDiagram-YWT4CUSO-kT0FkVfK.js → wardleyDiagram-YWT4CUSO-Dt24aXOM.js} +1 -1
  251. package/web-shell/assets/{xychartDiagram-2RQKCTM6-CYRm10z5.js → xychartDiagram-2RQKCTM6-A5Xk2WCH.js} +1 -1
  252. package/web-shell/index.html +2 -2
  253. package/bundled/review/DESIGN.md +0 -724
  254. package/web-shell/assets/channel-95y6Rcp3.js +0 -1
  255. package/web-shell/assets/classDiagram-4FO5ZUOK-pfzVkmjQ.js +0 -1
  256. package/web-shell/assets/classDiagram-v2-Q7XG4LA2-pfzVkmjQ.js +0 -1
  257. package/web-shell/assets/index-WxSvj2tI.css +0 -5
  258. package/web-shell/assets/stateDiagram-v2-BHNVJYJU-CtdFexEf.js +0 -1
  259. package/chunks/{channel-management-service-UHX56NBO.js → channel-management-service-5XPPTWUQ.js} +3 -3
  260. package/chunks/{chunk-LEZFUYPM.js → chunk-7GYP5COR.js} +3 -3
@@ -2,7 +2,7 @@
2
2
  "use strict";
3
3
  import {
4
4
  recomputeMcpGating
5
- } from "./chunk-M6RNMBUO.js";
5
+ } from "./chunk-NQZ5IVLH.js";
6
6
  import {
7
7
  classifyApiError,
8
8
  fireSessionDeleteHook
@@ -16,14 +16,14 @@ import {
16
16
  matchMcpServerByRef,
17
17
  parseExtensionRef,
18
18
  parseMcpServerRef
19
- } from "./chunk-PQ5JFCNL.js";
19
+ } from "./chunk-762UTZQZ.js";
20
20
  import {
21
21
  getAvailableCommands,
22
22
  handleSlashCommand,
23
23
  insertAfterFunctionResponses,
24
24
  isSlashCommand,
25
25
  normalizePartList
26
- } from "./chunk-WDLQGFWP.js";
26
+ } from "./chunk-TYWI5NXY.js";
27
27
  import {
28
28
  SessionIdConflictError,
29
29
  appEvents,
@@ -31,23 +31,27 @@ import {
31
31
  cleanupReviewWorktreeLeases,
32
32
  loadCliConfig,
33
33
  normalizeDisabledToolList
34
- } from "./chunk-2T3RYG4L.js";
34
+ } from "./chunk-5KDLX7ER.js";
35
35
  import "./chunk-NYX53SV4.js";
36
36
  import {
37
37
  collectContextData,
38
38
  formatContextUsageText
39
- } from "./chunk-C5YFS6VR.js";
39
+ } from "./chunk-EL4W7MGQ.js";
40
40
  import {
41
41
  getCommandSubcommandNames
42
- } from "./chunk-QZQ72YF6.js";
42
+ } from "./chunk-Z26UXKZE.js";
43
43
  import {
44
44
  getEffectiveSupportedModes
45
- } from "./chunk-DJA7YBLJ.js";
45
+ } from "./chunk-56MC5OM7.js";
46
46
  import "./chunk-3LGZEYOF.js";
47
47
  import "./chunk-4WGODMVR.js";
48
- import "./chunk-THLV7YGY.js";
48
+ import "./chunk-XIKKANF4.js";
49
+ import "./chunk-YAF2MQZ6.js";
49
50
  import "./chunk-KKN2IE7Q.js";
50
- import "./chunk-2ON2O4MD.js";
51
+ import {
52
+ computeCpuPercent
53
+ } from "./chunk-LBOVL47Y.js";
54
+ import "./chunk-FV2JYSWS.js";
51
55
  import "./chunk-6H67XLET.js";
52
56
  import {
53
57
  beginAcpBootstrapConfigProfiling,
@@ -55,9 +59,8 @@ import {
55
59
  endAcpBootstrapConfigProfiling,
56
60
  markAcpStartup
57
61
  } from "./chunk-M744OFVE.js";
58
- import "./chunk-P5UJMCVS.js";
59
- import "./chunk-EJXATV5R.js";
60
- import "./chunk-YAF2MQZ6.js";
62
+ import "./chunk-XIDYVC4P.js";
63
+ import "./chunk-PWFDZA5A.js";
61
64
  import {
62
65
  GENERATION_MAX_PROMPT_BYTES,
63
66
  GENERATION_TIMEOUT_MS,
@@ -78,7 +81,7 @@ import {
78
81
  shouldSuppressRememberErrorDetails,
79
82
  workspaceMemoryFailureCode,
80
83
  workspaceMemoryFailureDiagnostics
81
- } from "./chunk-I32URQI7.js";
84
+ } from "./chunk-EA2CKB6L.js";
82
85
  import {
83
86
  HistoryReplayer,
84
87
  MessageEmitter,
@@ -88,19 +91,16 @@ import {
88
91
  goalTerminalEventToHistoryItem,
89
92
  recordGoalStatusItem,
90
93
  restoreGoalFromHistory
91
- } from "./chunk-DHNFB7NC.js";
94
+ } from "./chunk-2QOLRESU.js";
92
95
  import "./chunk-DYA25Y7U.js";
93
96
  import "./chunk-4NFY2S7N.js";
94
- import "./chunk-AFJSRJTO.js";
97
+ import "./chunk-2B6FBVWE.js";
95
98
  import "./chunk-2MIN6GRR.js";
96
99
  import "./chunk-QHTIBUWB.js";
97
100
  import {
98
101
  isTerminalGoalStatusKind
99
102
  } from "./chunk-EKTCKZV5.js";
100
103
  import "./chunk-3Z43GZUQ.js";
101
- import {
102
- computeCpuPercent
103
- } from "./chunk-LBOVL47Y.js";
104
104
  import "./chunk-RXFQM6FQ.js";
105
105
  import "./chunk-HGCQ5SE7.js";
106
106
  import {
@@ -112,38 +112,38 @@ import {
112
112
  buildPermissionSettings,
113
113
  normalizePermissionRules,
114
114
  readPermissionRuleSet
115
- } from "./chunk-RL2NPV5E.js";
115
+ } from "./chunk-N5QPOGRQ.js";
116
116
  import {
117
117
  MAX_AUDIO_BYTES,
118
118
  sanitizeVoiceErrorMessage,
119
119
  transcribeVoiceAudio
120
- } from "./chunk-G6KI6B5L.js";
120
+ } from "./chunk-VF6WPN4R.js";
121
121
  import {
122
122
  readVoiceModel
123
- } from "./chunk-FPPVCCAH.js";
123
+ } from "./chunk-DNPP267F.js";
124
124
  import "./chunk-JELIWHXD.js";
125
125
  import {
126
126
  resolveSkillSettings
127
127
  } from "./chunk-Z4X5MTRT.js";
128
- import "./chunk-5XGI4IPK.js";
129
- import "./chunk-O4IWFYUW.js";
128
+ import "./chunk-JEVHOCCA.js";
129
+ import "./chunk-VY4TEQQ6.js";
130
130
  import "./chunk-57OAHC2Y.js";
131
131
  import {
132
132
  createLoadedSettingsAdapter
133
- } from "./chunk-C6FU76AA.js";
133
+ } from "./chunk-V3BNVUFI.js";
134
134
  import "./chunk-VXZBKKQR.js";
135
- import "./chunk-XPAY4EMH.js";
135
+ import "./chunk-2OSE7Q5O.js";
136
136
  import "./chunk-3SH53ANB.js";
137
137
  import {
138
138
  SESSION_SOURCE_META_KEY,
139
139
  parseSessionSource
140
- } from "./chunk-B3EBXISV.js";
140
+ } from "./chunk-5DVP76WL.js";
141
141
  import "./chunk-GLWP3FDB.js";
142
142
  import "./chunk-XCGIMOLN.js";
143
143
  import "./chunk-OCPBI7J5.js";
144
144
  import {
145
145
  ndJsonStream
146
- } from "./chunk-UWSXFI6E.js";
146
+ } from "./chunk-2U7GPHA6.js";
147
147
  import {
148
148
  ACP_ROUTE_ID_PREFIX,
149
149
  buildAcpModelOptions,
@@ -152,7 +152,7 @@ import {
152
152
  parseAcpModelOption,
153
153
  resolveAcpModelOption,
154
154
  sanitizeProviderBaseUrl
155
- } from "./chunk-IMGNGOGC.js";
155
+ } from "./chunk-PQ2J56BJ.js";
156
156
  import {
157
157
  ACP_PREFLIGHT_KINDS,
158
158
  IDLE_HOOK_EVENTS,
@@ -160,10 +160,10 @@ import {
160
160
  SERVE_STATUS_EXT_METHODS,
161
161
  STATUS_SCHEMA_VERSION,
162
162
  mapDomainErrorToErrorKind
163
- } from "./chunk-PDDYAXL2.js";
164
- import "./chunk-LEZFUYPM.js";
165
- import "./chunk-DTAPI453.js";
163
+ } from "./chunk-WIRAPZ62.js";
164
+ import "./chunk-7GYP5COR.js";
166
165
  import "./chunk-VWOVHOTT.js";
166
+ import "./chunk-DTAPI453.js";
167
167
  import "./chunk-V6WHFGST.js";
168
168
  import {
169
169
  CHANNEL_STARTUP_PROFILE_META_KEY,
@@ -193,6 +193,13 @@ import "./chunk-QONSRAEV.js";
193
193
  import "./chunk-24ER7UV4.js";
194
194
  import "./chunk-ALMR3E6Q.js";
195
195
  import "./chunk-BK2UNYWD.js";
196
+ import {
197
+ EXTERNAL_TOOL_GUARD_READY_META_KEY,
198
+ EXTERNAL_TOOL_GUARD_REQUIRED_VALUE,
199
+ EXTERNAL_TOOL_GUARD_TOKEN_ENV,
200
+ PRIVATE_EXTERNAL_TOOL_GUARD_ENV,
201
+ isValidExternalToolGuardDenialReason
202
+ } from "./chunk-BKHCW2BI.js";
196
203
  import "./chunk-M5GB774H.js";
197
204
  import "./chunk-XC2VAFVZ.js";
198
205
  import "./chunk-WUC6ZFXO.js";
@@ -207,7 +214,7 @@ import {
207
214
  import {
208
215
  assembleMcpServers,
209
216
  loadMcpApprovals
210
- } from "./chunk-6ME3PVMM.js";
217
+ } from "./chunk-JNFWMBG6.js";
211
218
  import {
212
219
  getOutputLanguageFilePath,
213
220
  getPersistScopeForModelSelection,
@@ -215,7 +222,7 @@ import {
215
222
  resolveOutputLanguageOrPreserveAuto,
216
223
  updateOutputLanguageFile,
217
224
  writeOutputLanguageAndRegisterPath
218
- } from "./chunk-KB6VSG2U.js";
225
+ } from "./chunk-GXP44JOS.js";
219
226
  import "./chunk-RKUWKYED.js";
220
227
  import "./chunk-GOXKNSDZ.js";
221
228
  import "./chunk-IDS7MSUP.js";
@@ -223,19 +230,19 @@ import {
223
230
  SUPPORTED_LANGUAGES,
224
231
  getCurrentLanguage,
225
232
  setLanguageAsync
226
- } from "./chunk-FV4TUUDE.js";
233
+ } from "./chunk-O4WOWHMZ.js";
227
234
  import {
228
235
  reloadEnvironment
229
- } from "./chunk-4PZ7SPD5.js";
236
+ } from "./chunk-7FKLLD4X.js";
230
237
  import "./chunk-6PEXNQTX.js";
231
- import "./chunk-RNKGMZEW.js";
232
- import "./chunk-HBCKZF2A.js";
238
+ import "./chunk-MFTOMYE2.js";
239
+ import "./chunk-7EW7CYLA.js";
233
240
  import "./chunk-VJNBRRZG.js";
234
241
  import {
235
242
  isFolderTrustEnabled,
236
243
  isWorkspaceTrusted,
237
244
  loadTrustedFolders
238
- } from "./chunk-URVJ4AZC.js";
245
+ } from "./chunk-MKMUBBEX.js";
239
246
  import "./chunk-ALGGS7UH.js";
240
247
  import "./chunk-MR3PXB6E.js";
241
248
  import "./chunk-XFSFZCM5.js";
@@ -363,25 +370,25 @@ import {
363
370
  validatePlanModeShellApproval,
364
371
  validatePlanModeShellContext,
365
372
  wrapUserPromptSubmitContext
366
- } from "./chunk-E2SYUEIA.js";
373
+ } from "./chunk-5OAMVWFL.js";
367
374
  import "./chunk-GOFAQQZA.js";
368
375
  import "./chunk-5M6IDOMF.js";
369
376
  import "./chunk-TWPJO254.js";
370
377
  import {
371
378
  external_exports
372
379
  } from "./chunk-H6XPXXMH.js";
373
- import "./chunk-VA5NLVPT.js";
380
+ import "./chunk-Z7JILXGX.js";
374
381
  import "./chunk-I7JDGNG6.js";
375
382
  import "./chunk-A6SX5TAH.js";
376
383
  import "./chunk-33FNCQSY.js";
377
384
  import {
378
385
  parsePositiveIntegerEnv
379
386
  } from "./chunk-6PVPNMXU.js";
380
- import "./chunk-DZPOYHBT.js";
387
+ import "./chunk-D6FISK43.js";
381
388
  import "./chunk-IRH27ZC2.js";
382
389
  import "./chunk-QHWCP53L.js";
383
390
  import "./chunk-MOHAWIAW.js";
384
- import "./chunk-X6QNZOTC.js";
391
+ import "./chunk-3PRJYMXC.js";
385
392
  import {
386
393
  promptIdContext,
387
394
  todoWorkChainContext
@@ -397,21 +404,21 @@ import {
397
404
  } from "./chunk-A5YZ3FA2.js";
398
405
  import "./chunk-YAVY33G4.js";
399
406
  import "./chunk-2UISUFHQ.js";
400
- import "./chunk-HFVW54NL.js";
407
+ import "./chunk-MBEMTXQT.js";
401
408
  import {
402
409
  APPROVAL_MODES,
403
410
  runWithRuntimeContentGenerator
404
- } from "./chunk-LLMGP5IC.js";
411
+ } from "./chunk-6WBWIPBF.js";
405
412
  import "./chunk-S6LOFUVP.js";
406
413
  import {
407
414
  FORK_SUBAGENT_TYPE,
408
415
  getStartupContextLength,
409
416
  isSystemReminderContent
410
- } from "./chunk-7UXI6P72.js";
417
+ } from "./chunk-WVAESIM6.js";
411
418
  import "./chunk-K623ENWT.js";
412
419
  import "./chunk-AQ37AY7B.js";
413
420
  import "./chunk-432XCUHF.js";
414
- import "./chunk-YXEVDA66.js";
421
+ import "./chunk-HU5TUALO.js";
415
422
  import {
416
423
  clearCachedCredentialFile,
417
424
  qwenOAuth2Events
@@ -423,7 +430,7 @@ import "./chunk-DGEIYUC3.js";
423
430
  import "./chunk-MPHPFVKK.js";
424
431
  import "./chunk-GLNBDYUX.js";
425
432
  import "./chunk-DJ2GSRLV.js";
426
- import "./chunk-SBBHZ3YT.js";
433
+ import "./chunk-QKWPXGW4.js";
427
434
  import {
428
435
  addToolArgumentsAttributes,
429
436
  addToolCallResultAttributes,
@@ -431,7 +438,7 @@ import {
431
438
  registerAcpEventLoopLagGauge,
432
439
  startEventLoopLagMonitor,
433
440
  withDaemonSpan
434
- } from "./chunk-RPYYTL7E.js";
441
+ } from "./chunk-MGSSJT27.js";
435
442
  import "./chunk-2J3OJGTL.js";
436
443
  import "./chunk-P3QQPMQA.js";
437
444
  import "./chunk-6O5DVH27.js";
@@ -469,22 +476,23 @@ import {
469
476
  shouldRunVisionBridge,
470
477
  splitImageParts,
471
478
  uiTelemetryService
472
- } from "./chunk-JDJ7SC4E.js";
479
+ } from "./chunk-NMBDPO63.js";
480
+ import "./chunk-WOJZWRAZ.js";
473
481
  import "./chunk-VGC4I5JJ.js";
474
482
  import {
475
483
  getAutoMemoryRoot,
476
484
  getUserAutoMemoryRoot
477
485
  } from "./chunk-E4WHKETF.js";
478
- import "./chunk-UEJESCS7.js";
486
+ import "./chunk-ZPPP6VCL.js";
479
487
  import {
480
488
  ToolConfirmationOutcome,
481
489
  ToolNames,
482
490
  isShellProgressData
483
- } from "./chunk-CFDR3GNL.js";
491
+ } from "./chunk-D7D7RXIJ.js";
484
492
  import {
485
493
  AuthType,
486
494
  preloadContentGenerator
487
- } from "./chunk-TXZDRD36.js";
495
+ } from "./chunk-LCCBAGRT.js";
488
496
  import "./chunk-46UV252V.js";
489
497
  import {
490
498
  DEFAULT_TOKEN_LIMIT,
@@ -501,9 +509,9 @@ import {
501
509
  startToolExecutionSpan,
502
510
  startToolSpan,
503
511
  withInteractionSpan
504
- } from "./chunk-O2ZYHG33.js";
512
+ } from "./chunk-5L6CQ4ZU.js";
505
513
  import "./chunk-W4RQUHY3.js";
506
- import "./chunk-G7XXKQYS.js";
514
+ import "./chunk-LKRMNRSN.js";
507
515
  import {
508
516
  Storage,
509
517
  createDebugLogger,
@@ -512,10 +520,10 @@ import {
512
520
  isSubpath
513
521
  } from "./chunk-3RXUYQJI.js";
514
522
  import "./chunk-VOQXFAY5.js";
515
- import "./chunk-KHSJSMFS.js";
523
+ import "./chunk-6I6WUVYI.js";
516
524
  import {
517
525
  runExitCleanup
518
- } from "./chunk-SV5X2EUV.js";
526
+ } from "./chunk-FMU2QVA5.js";
519
527
  import {
520
528
  writeStderrLine,
521
529
  writeStderrLineSafe
@@ -1242,6 +1250,11 @@ var SubAgentTracker = class {
1242
1250
  callId: event.callId,
1243
1251
  args: event.args,
1244
1252
  subagentMeta: this.subagentMeta
1253
+ }).catch((error) => {
1254
+ debugLogger2.debug(
1255
+ `Failed to emit subagent tool start for ${event.name}:`,
1256
+ error
1257
+ );
1245
1258
  });
1246
1259
  };
1247
1260
  }
@@ -1261,6 +1274,11 @@ var SubAgentTracker = class {
1261
1274
  resultDisplay: event.resultDisplay,
1262
1275
  args: state?.args,
1263
1276
  subagentMeta: this.subagentMeta
1277
+ }).catch((error) => {
1278
+ debugLogger2.debug(
1279
+ `Failed to emit subagent tool result for ${event.name}:`,
1280
+ error
1281
+ );
1264
1282
  });
1265
1283
  this.toolStates.delete(event.callId);
1266
1284
  };
@@ -1314,7 +1332,7 @@ var SubAgentTracker = class {
1314
1332
  await event.respond(outcome, {
1315
1333
  answers: "answers" in output ? output.answers : void 0
1316
1334
  });
1317
- if (outcome === "cancel" /* Cancel */) {
1335
+ if (outcome === "cancel" /* Cancel */ && !abortSignal.aborted) {
1318
1336
  this.onPermissionCancel?.();
1319
1337
  }
1320
1338
  } catch (error) {
@@ -1322,7 +1340,9 @@ var SubAgentTracker = class {
1322
1340
  `Permission request failed for subagent tool ${event.name}:`,
1323
1341
  error
1324
1342
  );
1325
- this.onPermissionCancel?.();
1343
+ if (!abortSignal.aborted) {
1344
+ this.onPermissionCancel?.();
1345
+ }
1326
1346
  try {
1327
1347
  await event.respond("cancel" /* Cancel */);
1328
1348
  } catch (respondError) {
@@ -1341,12 +1361,9 @@ var SubAgentTracker = class {
1341
1361
  return (...args) => {
1342
1362
  const event = args[0];
1343
1363
  if (abortSignal.aborted) return;
1344
- this.messageEmitter.emitUsageMetadata(
1345
- event.usage,
1346
- "",
1347
- event.durationMs,
1348
- this.subagentMeta
1349
- );
1364
+ void this.messageEmitter.emitUsageMetadata(event.usage, "", event.durationMs, this.subagentMeta).catch((error) => {
1365
+ debugLogger2.debug("Failed to emit subagent usage metadata:", error);
1366
+ });
1350
1367
  };
1351
1368
  }
1352
1369
  /**
@@ -1363,7 +1380,9 @@ var SubAgentTracker = class {
1363
1380
  event.thought ?? false,
1364
1381
  void 0,
1365
1382
  this.subagentMeta
1366
- );
1383
+ ).catch((error) => {
1384
+ debugLogger2.debug("Failed to emit subagent stream text:", error);
1385
+ });
1367
1386
  };
1368
1387
  }
1369
1388
  };
@@ -1912,6 +1931,8 @@ var DAEMON_INVALID_TOOL_PARAMS_THRESHOLD = 3;
1912
1931
  var PERMISSION_CANCEL_SKIP_MESSAGE = "Skipped because a permission request was cancelled before the user answered; user input is required before continuing.";
1913
1932
  var LOOP_DETECTED_SKIP_MESSAGE = "Skipped because loop detection stopped the current turn before this tool call could run.";
1914
1933
  var LOOP_DETECTED_CONTEXT_MESSAGE = "System: this turn was terminated because the model exceeded tool-call safety limits. Try a different approach on the next turn.";
1934
+ var TOOL_EXECUTION_CANCELLED_MESSAGE = "Tool execution was cancelled.";
1935
+ var TOOL_POST_EXECUTION_CANCELLED_MESSAGE = "The tool had already completed; its output was discarded.";
1915
1936
  function createDaemonToolLoopState() {
1916
1937
  return {
1917
1938
  totalToolCalls: 0,
@@ -1924,7 +1945,14 @@ function recordDaemonLoopDetected(config, promptId, loopType, message, loopState
1924
1945
  if (!loopState.loopDetected) {
1925
1946
  loopState.loopDetected = true;
1926
1947
  debugLogger5.warn(message);
1927
- logLoopDetected(config, new LoopDetectedEvent(loopType, promptId));
1948
+ try {
1949
+ logLoopDetected(config, new LoopDetectedEvent(loopType, promptId));
1950
+ } catch (error) {
1951
+ debugLogger5.debug(
1952
+ "[Session] Failed to record loop detection telemetry",
1953
+ error
1954
+ );
1955
+ }
1928
1956
  }
1929
1957
  return true;
1930
1958
  }
@@ -2525,6 +2553,7 @@ var Session = class {
2525
2553
  resolveCloseGate = null;
2526
2554
  unsubscribeChatRecordingFailure;
2527
2555
  workflowApprovalAbortController = new AbortController();
2556
+ activeTodoPlanRevision;
2528
2557
  // Modular components
2529
2558
  historyReplayer;
2530
2559
  toolCallEmitter;
@@ -2747,6 +2776,9 @@ var Session = class {
2747
2776
  clearTodoStopGuardTrust() {
2748
2777
  this.#clearTodoStopGuardTrustAndDrainAutomaticQueues();
2749
2778
  }
2779
+ clearActiveTodoPlanRevision() {
2780
+ this.activeTodoPlanRevision = void 0;
2781
+ }
2750
2782
  hardSuspendTodoStopGuard() {
2751
2783
  this.#clearTodoStopGuardQueuedPromptWait();
2752
2784
  this.todoStopGuardDrainAutomaticQueuesWhenIdle = false;
@@ -3187,7 +3219,11 @@ var Session = class {
3187
3219
  }
3188
3220
  async replayHistory(records, gaps) {
3189
3221
  this.primeTurnFromHistory(records);
3190
- await this.historyReplayer.replay(records, gaps);
3222
+ try {
3223
+ await this.historyReplayer.replay(records, gaps);
3224
+ } finally {
3225
+ this.activeTodoPlanRevision = void 0;
3226
+ }
3191
3227
  }
3192
3228
  rewindToTurn(targetTurnIndex, opts) {
3193
3229
  if (!Number.isInteger(targetTurnIndex) || targetTurnIndex < 0) {
@@ -3216,6 +3252,7 @@ var Session = class {
3216
3252
  }
3217
3253
  chat.truncateHistory(apiTruncateIndex);
3218
3254
  chat.stripThoughtsFromHistory();
3255
+ this.activeTodoPlanRevision = void 0;
3219
3256
  const preserveQueuedPromptPriority = this.todoStopGuardQueuedPromptPriority;
3220
3257
  const shouldDrainAutomaticQueues = (this.todoStopGuard.blocksUnrelatedAutomaticTurns || this.todoStopGuard.hasCommittedContinuation) && !preserveQueuedPromptPriority;
3221
3258
  this.todoStopGuard.blockUntilOrdinaryPromptStarts();
@@ -3260,6 +3297,7 @@ var Session = class {
3260
3297
  );
3261
3298
  }
3262
3299
  this.config.getGeminiClient().getChat().setHistory(structuredClone(history));
3300
+ this.activeTodoPlanRevision = void 0;
3263
3301
  this.#clearTodoStopGuardTrustAndDrainAutomaticQueues();
3264
3302
  }
3265
3303
  #computeApiTruncationIndexForUserTurn(apiHistory, targetTurnIndex) {
@@ -3961,7 +3999,7 @@ ${this.pendingRecoveredAgentsNotice}
3961
3999
  onFullTurnModel
3962
4000
  )
3963
4001
  );
3964
- if (toolRun.stopAfterPermissionCancel) {
4002
+ if (toolRun.stopAfterPermissionCancel || pendingSend.signal.aborted) {
3965
4003
  this.todoStopGuard.suspend();
3966
4004
  await this.#preserveStoppedToolRun(
3967
4005
  toolRun,
@@ -4700,7 +4738,7 @@ ${this.pendingRecoveredAgentsNotice}
4700
4738
  options.onFullTurnModel
4701
4739
  )
4702
4740
  );
4703
- if (toolRun.stopAfterPermissionCancel || toolRun.loopDetected) {
4741
+ if (toolRun.stopAfterPermissionCancel || toolRun.loopDetected || pendingSend.signal.aborted) {
4704
4742
  this.todoStopGuard.suspend();
4705
4743
  await this.#preserveStoppedToolRun(toolRun, pendingSend.signal);
4706
4744
  return {
@@ -4799,7 +4837,21 @@ ${this.pendingRecoveredAgentsNotice}
4799
4837
  sessionId: this.sessionId,
4800
4838
  update
4801
4839
  };
4840
+ if (update.sessionUpdate === "plan") {
4841
+ this.activeTodoPlanRevision = void 0;
4842
+ }
4802
4843
  await this.client.sessionUpdate(params);
4844
+ if (update.sessionUpdate === "plan") {
4845
+ this.#captureTodoPlanRevision(update);
4846
+ }
4847
+ }
4848
+ #captureTodoPlanRevision(update) {
4849
+ const meta = isRecord2(update["_meta"]) ? update["_meta"] : void 0;
4850
+ const plan = isRecord2(meta?.["qwenTodoPlan"]) ? meta["qwenTodoPlan"] : void 0;
4851
+ const transcript = isRecord2(meta?.["qwenTranscript"]) ? meta["qwenTranscript"] : void 0;
4852
+ const planId = plan?.["id"];
4853
+ const sourceCallId = transcript?.["planToolCallId"];
4854
+ this.activeTodoPlanRevision = typeof planId === "string" && typeof sourceCallId === "string" && update.entries.length > 0 ? { planId, sourceCallId } : void 0;
4803
4855
  }
4804
4856
  #scheduleChannelDelivery(params) {
4805
4857
  const timer = setTimeout(() => {
@@ -5661,7 +5713,7 @@ ${this.pendingRecoveredAgentsNotice}
5661
5713
  functionCalls,
5662
5714
  toolLoopState
5663
5715
  );
5664
- if (toolRun.stopAfterPermissionCancel) {
5716
+ if (toolRun.stopAfterPermissionCancel || ac.signal.aborted) {
5665
5717
  this.todoStopGuard.suspend();
5666
5718
  await this.#preserveStoppedToolRun(toolRun, ac.signal);
5667
5719
  return;
@@ -6067,7 +6119,7 @@ ${this.pendingRecoveredAgentsNotice}
6067
6119
  functionCalls,
6068
6120
  toolLoopState
6069
6121
  );
6070
- if (toolRun.stopAfterPermissionCancel) {
6122
+ if (toolRun.stopAfterPermissionCancel || ac.signal.aborted) {
6071
6123
  this.todoStopGuard.suspend();
6072
6124
  await this.#preserveStoppedToolRun(toolRun, ac.signal);
6073
6125
  await this.#emitBackgroundNotificationEndTurn(
@@ -6294,8 +6346,12 @@ ${this.pendingRecoveredAgentsNotice}
6294
6346
  `Unknown approval mode: ${params.modeId}`
6295
6347
  );
6296
6348
  }
6349
+ const previousApprovalMode = this.config.getApprovalMode();
6297
6350
  this.config.setApprovalMode(approvalMode);
6298
6351
  if (approvalMode === "plan" /* PLAN */) {
6352
+ if (previousApprovalMode !== "plan" /* PLAN */) {
6353
+ this.activeTodoPlanRevision = void 0;
6354
+ }
6299
6355
  this.clearTodoStopGuardTrust();
6300
6356
  }
6301
6357
  void this.client.extNotification("qwen/notify/session/mode-update", {
@@ -6493,9 +6549,10 @@ ${this.pendingRecoveredAgentsNotice}
6493
6549
  metadata: {
6494
6550
  callId,
6495
6551
  status: "error",
6552
+ executionStatus: "not_started",
6496
6553
  resultDisplay: void 0,
6497
6554
  error,
6498
- errorType
6555
+ errorType: errorType ?? "execution_denied" /* EXECUTION_DENIED */
6499
6556
  }
6500
6557
  });
6501
6558
  if (emitStart) {
@@ -6521,7 +6578,12 @@ ${this.pendingRecoveredAgentsNotice}
6521
6578
  return await finalizeRunToolResult({
6522
6579
  parts: await Promise.all(
6523
6580
  dedupedFunctionCalls.map(
6524
- (fc) => recordSkippedToolCall(fc, LOOP_DETECTED_SKIP_MESSAGE, false)
6581
+ (fc) => recordSkippedToolCall(
6582
+ fc,
6583
+ LOOP_DETECTED_SKIP_MESSAGE,
6584
+ false,
6585
+ "unknown" /* UNKNOWN */
6586
+ )
6525
6587
  )
6526
6588
  ),
6527
6589
  stopAfterPermissionCancel: false,
@@ -6563,38 +6625,47 @@ ${this.pendingRecoveredAgentsNotice}
6563
6625
  }, "pushDuplicateBatch");
6564
6626
  const emitDuplicateBatch = /* @__PURE__ */ __name(async (batch) => {
6565
6627
  const { request, response } = batch;
6566
- if (request.name === ToolNames.TODO_WRITE) {
6567
- const provenance = ToolCallEmitter.resolveToolProvenance(request.name);
6568
- await this.sendUpdate({
6569
- sessionUpdate: "tool_call_update",
6570
- toolCallId: response.callId,
6571
- status: "failed",
6572
- content: [
6573
- {
6574
- type: "content",
6575
- content: {
6576
- type: "text",
6577
- text: response.error?.message ?? String(response.resultDisplay)
6628
+ try {
6629
+ if (request.name === ToolNames.TODO_WRITE) {
6630
+ const provenance = ToolCallEmitter.resolveToolProvenance(
6631
+ request.name
6632
+ );
6633
+ await this.sendUpdate({
6634
+ sessionUpdate: "tool_call_update",
6635
+ toolCallId: response.callId,
6636
+ status: "failed",
6637
+ content: [
6638
+ {
6639
+ type: "content",
6640
+ content: {
6641
+ type: "text",
6642
+ text: response.error?.message ?? String(response.resultDisplay)
6643
+ }
6578
6644
  }
6645
+ ],
6646
+ rawOutput: response.resultDisplay,
6647
+ _meta: {
6648
+ toolName: request.name,
6649
+ provenance: provenance.provenance,
6650
+ ...provenance.serverId ? { serverId: provenance.serverId } : {}
6579
6651
  }
6580
- ],
6581
- rawOutput: response.resultDisplay,
6582
- _meta: {
6652
+ });
6653
+ } else {
6654
+ await this.toolCallEmitter.emitResult({
6655
+ callId: response.callId,
6583
6656
  toolName: request.name,
6584
- provenance: provenance.provenance,
6585
- ...provenance.serverId ? { serverId: provenance.serverId } : {}
6586
- }
6587
- });
6588
- } else {
6589
- await this.toolCallEmitter.emitResult({
6590
- callId: response.callId,
6591
- toolName: request.name,
6592
- args: request.args,
6593
- message: response.responseParts,
6594
- resultDisplay: response.resultDisplay,
6595
- error: response.error,
6596
- success: false
6597
- });
6657
+ args: request.args,
6658
+ message: response.responseParts,
6659
+ resultDisplay: response.resultDisplay,
6660
+ error: response.error,
6661
+ success: false
6662
+ });
6663
+ }
6664
+ } catch (emitError) {
6665
+ debugLogger5.debug(
6666
+ "[Session.runToolCalls] Failed to emit duplicate tool update",
6667
+ emitError
6668
+ );
6598
6669
  }
6599
6670
  queueToolResultRecord(batch.fc, {
6600
6671
  callId: response.callId,
@@ -6604,6 +6675,7 @@ ${this.pendingRecoveredAgentsNotice}
6604
6675
  metadata: {
6605
6676
  callId: response.callId,
6606
6677
  status: "error",
6678
+ executionStatus: response.executionStatus ?? "not_started",
6607
6679
  resultDisplay: response.resultDisplay,
6608
6680
  error: response.error,
6609
6681
  errorType: response.errorType
@@ -6642,10 +6714,12 @@ ${this.pendingRecoveredAgentsNotice}
6642
6714
  executableCalls.map((call) => call.name)
6643
6715
  );
6644
6716
  const planModeEntryBoundary = planModeEntryBoundaryIndex === void 0 ? void 0 : executableCalls[planModeEntryBoundaryIndex];
6645
- const appendSkippedAfter = /* @__PURE__ */ __name(async (parts2, fc, message = PERMISSION_CANCEL_SKIP_MESSAGE) => {
6717
+ const appendSkippedAfter = /* @__PURE__ */ __name(async (parts2, fc, message = PERMISSION_CANCEL_SKIP_MESSAGE, errorType) => {
6646
6718
  const startIndex = dedupedFunctionCalls.indexOf(fc) + 1;
6647
6719
  for (const remainingCall of dedupedFunctionCalls.slice(startIndex)) {
6648
- parts2.push(await recordSkippedToolCall(remainingCall, message));
6720
+ parts2.push(
6721
+ await recordSkippedToolCall(remainingCall, message, true, errorType)
6722
+ );
6649
6723
  }
6650
6724
  }, "appendSkippedAfter");
6651
6725
  const memoryWriteCandidates = [];
@@ -6675,7 +6749,12 @@ ${this.pendingRecoveredAgentsNotice}
6675
6749
  if (results[i]) continue;
6676
6750
  results[i] = {
6677
6751
  parts: [
6678
- await recordSkippedToolCall(calls[i], LOOP_DETECTED_SKIP_MESSAGE)
6752
+ await recordSkippedToolCall(
6753
+ calls[i],
6754
+ LOOP_DETECTED_SKIP_MESSAGE,
6755
+ true,
6756
+ "unknown" /* UNKNOWN */
6757
+ )
6679
6758
  ],
6680
6759
  stopAfterPermissionCancel: false,
6681
6760
  loopDetected: true
@@ -6839,7 +6918,8 @@ ${this.pendingRecoveredAgentsNotice}
6839
6918
  await appendSkippedAfter(
6840
6919
  parts,
6841
6920
  batch.calls[batch.calls.length - 1],
6842
- LOOP_DETECTED_SKIP_MESSAGE
6921
+ LOOP_DETECTED_SKIP_MESSAGE,
6922
+ "unknown" /* UNKNOWN */
6843
6923
  );
6844
6924
  return await finalizeRunToolResult({
6845
6925
  parts,
@@ -6876,7 +6956,12 @@ ${this.pendingRecoveredAgentsNotice}
6876
6956
  parts.push(...r.parts);
6877
6957
  collectMemoryWriteCandidates(r);
6878
6958
  if (r.loopDetected) {
6879
- await appendSkippedAfter(parts, fc, LOOP_DETECTED_SKIP_MESSAGE);
6959
+ await appendSkippedAfter(
6960
+ parts,
6961
+ fc,
6962
+ LOOP_DETECTED_SKIP_MESSAGE,
6963
+ "unknown" /* UNKNOWN */
6964
+ );
6880
6965
  return await finalizeRunToolResult({
6881
6966
  parts,
6882
6967
  stopAfterPermissionCancel: false,
@@ -6939,10 +7024,21 @@ ${this.pendingRecoveredAgentsNotice}
6939
7024
  async runTool(abortSignal, promptId, fc, onStopAfterPermissionCancel, toolLoopState, recordSkippedToolCall, queueToolResultRecord, generatedCallId, onFullTurnModel) {
6940
7025
  const callId = fc.id ?? generatedCallId ?? `${fc.name}-${Date.now()}`;
6941
7026
  let args = fc.args ?? {};
7027
+ let executionStatus = "not_started";
7028
+ let executionErrorType;
7029
+ let executeReturned = false;
7030
+ let terminalStatus;
7031
+ let toolType = "native";
7032
+ let mcpServerName = void 0;
6942
7033
  if (toolLoopState?.loopDetected) {
6943
7034
  return {
6944
7035
  parts: [
6945
- recordSkippedToolCall ? await recordSkippedToolCall(fc, LOOP_DETECTED_SKIP_MESSAGE, false) : {
7036
+ recordSkippedToolCall ? await recordSkippedToolCall(
7037
+ fc,
7038
+ LOOP_DETECTED_SKIP_MESSAGE,
7039
+ false,
7040
+ "unknown" /* UNKNOWN */
7041
+ ) : {
6946
7042
  functionResponse: {
6947
7043
  id: callId,
6948
7044
  name: fc.name ?? "unknown_tool",
@@ -6967,51 +7063,80 @@ ${this.pendingRecoveredAgentsNotice}
6967
7063
  removeAgentToolAbortPropagation?.();
6968
7064
  removeAgentToolAbortPropagation = void 0;
6969
7065
  }, "cleanupAgentToolResources");
6970
- const errorResponse = /* @__PURE__ */ __name((error) => {
7066
+ const errorResponse = /* @__PURE__ */ __name((error, toolName2, status, errorType) => {
6971
7067
  const durationMs = Date.now() - startTime;
6972
- logToolCall(this.config, {
6973
- "event.name": "tool_call",
6974
- "event.timestamp": (/* @__PURE__ */ new Date()).toISOString(),
6975
- prompt_id: promptId,
6976
- function_name: fc.name ?? "",
6977
- function_args: args,
6978
- duration_ms: durationMs,
6979
- // An aborted signal means the call was cancelled, not a genuine error.
6980
- status: activeToolAbortSignal.aborted ? "cancelled" : "error",
6981
- success: false,
6982
- error: error.message,
6983
- tool_type: typeof tool !== "undefined" && tool instanceof DiscoveredMCPTool ? "mcp" : "native"
6984
- });
7068
+ try {
7069
+ logToolCall(this.config, {
7070
+ "event.name": "tool_call",
7071
+ "event.timestamp": (/* @__PURE__ */ new Date()).toISOString(),
7072
+ call_id: callId,
7073
+ prompt_id: promptId,
7074
+ function_name: toolName2,
7075
+ function_args: args,
7076
+ duration_ms: durationMs,
7077
+ status,
7078
+ execution_status: executionStatus,
7079
+ success: false,
7080
+ ...status === "error" ? {
7081
+ error: error.message,
7082
+ error_type: errorType
7083
+ } : {},
7084
+ tool_type: toolType,
7085
+ mcp_server_name: mcpServerName
7086
+ });
7087
+ } catch (telemetryError) {
7088
+ debugLogger5.debug(
7089
+ "[Session.runTool] Failed to record terminal tool telemetry",
7090
+ telemetryError
7091
+ );
7092
+ }
6985
7093
  return [
6986
7094
  {
6987
7095
  functionResponse: {
6988
7096
  id: callId,
6989
- name: fc.name ?? "",
7097
+ name: toolName2,
6990
7098
  response: { error: error.message }
6991
7099
  }
6992
7100
  }
6993
7101
  ];
6994
7102
  }, "errorResponse");
6995
7103
  const earlyErrorResponse = /* @__PURE__ */ __name(async (error, toolName2 = fc.name ?? "unknown_tool", opts) => {
6996
- spanError = error.message;
7104
+ executionStatus = opts.executionStatus;
7105
+ terminalStatus = opts.status;
7106
+ spanError = opts.status === "error" ? error.message : void 0;
6997
7107
  cleanupAgentToolResources();
6998
7108
  if (toolName2 !== ToolNames.TODO_WRITE) {
6999
- await this.toolCallEmitter.emitError(callId, toolName2, error);
7109
+ try {
7110
+ await this.toolCallEmitter.emitError(callId, toolName2, error);
7111
+ } catch (emitError) {
7112
+ debugLogger5.debug(
7113
+ "[Session.runTool] Failed to emit terminal tool update",
7114
+ emitError
7115
+ );
7116
+ }
7000
7117
  }
7001
- const errorParts = errorResponse(error);
7118
+ const errorParts = errorResponse(
7119
+ error,
7120
+ toolName2,
7121
+ opts.status,
7122
+ opts.errorType
7123
+ );
7002
7124
  queueToolResultRecord?.(fc, {
7003
7125
  callId,
7004
7126
  toolName: toolName2,
7005
7127
  responseParts: errorParts,
7006
7128
  metadata: {
7007
7129
  callId,
7008
- status: opts?.status ?? "error",
7130
+ status: opts.status,
7131
+ executionStatus,
7009
7132
  resultDisplay: void 0,
7010
- error,
7011
- errorType: opts?.errorType
7133
+ error: opts.status === "error" ? error : void 0,
7134
+ errorType: opts.status === "error" ? opts.errorType : void 0
7012
7135
  }
7013
7136
  });
7014
- const loopDetected = opts?.recordInvalidToolParams === true && !activeToolAbortSignal.aborted && !opts?.stopAfterPermissionCancel && recordDaemonInvalidToolParams(
7137
+ const loopDetected = opts.recordInvalidToolParams === true && !activeToolAbortSignal.aborted && // A permission cancellation is the user declining, not the model
7138
+ // re-sending invalid params, so it must not feed loop detection.
7139
+ !opts.stopAfterPermissionCancel && recordDaemonInvalidToolParams(
7015
7140
  this.config,
7016
7141
  promptId,
7017
7142
  toolLoopState,
@@ -7020,14 +7145,32 @@ ${this.pendingRecoveredAgentsNotice}
7020
7145
  );
7021
7146
  return {
7022
7147
  parts: errorParts,
7023
- stopAfterPermissionCancel: opts?.stopAfterPermissionCancel ?? false,
7148
+ stopAfterPermissionCancel: opts.stopAfterPermissionCancel ?? false,
7024
7149
  loopDetected
7025
7150
  };
7026
7151
  }, "earlyErrorResponse");
7152
+ const cancelBeforeExecutionIfAborted = /* @__PURE__ */ __name((toolName2 = fc.name ?? "unknown_tool") => activeToolAbortSignal.aborted ? earlyErrorResponse(
7153
+ new Error("Tool call was cancelled before execution."),
7154
+ toolName2,
7155
+ {
7156
+ status: "cancelled",
7157
+ errorType: void 0,
7158
+ executionStatus: "not_started"
7159
+ }
7160
+ ) : void 0, "cancelBeforeExecutionIfAborted");
7161
+ const initialCancellation = cancelBeforeExecutionIfAborted();
7162
+ if (initialCancellation) return initialCancellation;
7027
7163
  if (!fc.name) {
7028
- return earlyErrorResponse(new Error("Missing function name"), void 0, {
7029
- recordInvalidToolParams: true
7030
- });
7164
+ return earlyErrorResponse(
7165
+ new Error("Missing function name"),
7166
+ "unknown_tool",
7167
+ {
7168
+ status: "error",
7169
+ errorType: "invalid_tool_params" /* INVALID_TOOL_PARAMS */,
7170
+ executionStatus: "not_started",
7171
+ recordInvalidToolParams: true
7172
+ }
7173
+ );
7031
7174
  }
7032
7175
  const toolName = fc.name;
7033
7176
  const toolRegistry = this.config.getToolRegistry();
@@ -7036,9 +7179,16 @@ ${this.pendingRecoveredAgentsNotice}
7036
7179
  return earlyErrorResponse(
7037
7180
  new Error(`Tool "${toolName}" not found in registry.`),
7038
7181
  toolName,
7039
- { recordInvalidToolParams: true }
7182
+ {
7183
+ status: "error",
7184
+ errorType: "tool_not_registered" /* TOOL_NOT_REGISTERED */,
7185
+ executionStatus: "not_started",
7186
+ recordInvalidToolParams: true
7187
+ }
7040
7188
  );
7041
7189
  }
7190
+ toolType = tool instanceof DiscoveredMCPTool ? "mcp" : "native";
7191
+ mcpServerName = tool instanceof DiscoveredMCPTool ? tool.serverName : void 0;
7042
7192
  const policyToolName = tool.name;
7043
7193
  const originalPolicyRequestArgs = policyToolName === ToolNames.SHELL || policyToolName === ToolNames.MONITOR ? structuredClone(args) : args;
7044
7194
  const toolSpan = startToolSpan(
@@ -7055,14 +7205,23 @@ ${this.pendingRecoveredAgentsNotice}
7055
7205
  tool.description,
7056
7206
  promptId
7057
7207
  );
7058
- let spanSuccess = false;
7059
7208
  try {
7060
7209
  return await runInToolSpanContext(toolSpan, async () => {
7210
+ const entryCancellation = cancelBeforeExecutionIfAborted(toolName);
7211
+ if (entryCancellation) return entryCancellation;
7061
7212
  const pm = this.config.getPermissionManager?.();
7062
- if (pm && !await pm.isToolEnabled(policyToolName)) {
7213
+ const toolEnabled = pm ? await pm.isToolEnabled(policyToolName) : true;
7214
+ const enablementCancellation = cancelBeforeExecutionIfAborted(toolName);
7215
+ if (enablementCancellation) return enablementCancellation;
7216
+ if (pm && !toolEnabled) {
7063
7217
  return earlyErrorResponse(
7064
7218
  new Error(`Tool "${toolName}" is disabled.`),
7065
- toolName
7219
+ toolName,
7220
+ {
7221
+ status: "error",
7222
+ errorType: "execution_denied" /* EXECUTION_DENIED */,
7223
+ executionStatus: "not_started"
7224
+ }
7066
7225
  );
7067
7226
  }
7068
7227
  const isTodoWriteTool = tool.name === ToolNames.TODO_WRITE;
@@ -7124,6 +7283,8 @@ ${this.pendingRecoveredAgentsNotice}
7124
7283
  policyToolName,
7125
7284
  toolParams
7126
7285
  );
7286
+ const permissionFlowCancellation = cancelBeforeExecutionIfAborted(toolName);
7287
+ if (permissionFlowCancellation) return permissionFlowCancellation;
7127
7288
  const {
7128
7289
  finalPermission,
7129
7290
  pmForcedAsk,
@@ -7137,7 +7298,12 @@ ${this.pendingRecoveredAgentsNotice}
7137
7298
  if (finalPermission === "deny") {
7138
7299
  return earlyErrorResponse(
7139
7300
  new Error(denyMessage ?? `Tool "${toolName}" is denied.`),
7140
- toolName
7301
+ toolName,
7302
+ {
7303
+ status: "error",
7304
+ errorType: "execution_denied" /* EXECUTION_DENIED */,
7305
+ executionStatus: "not_started"
7306
+ }
7141
7307
  );
7142
7308
  }
7143
7309
  let planShellAmbientWorkingDirectory;
@@ -7159,6 +7325,8 @@ ${this.pendingRecoveredAgentsNotice}
7159
7325
  ambientWorkingDirectory: planShellAmbientWorkingDirectory,
7160
7326
  signal: activeToolAbortSignal
7161
7327
  }) : { classification: "not-applicable" };
7328
+ const planPolicyCancellation = cancelBeforeExecutionIfAborted(toolName);
7329
+ if (planPolicyCancellation) return planPolicyCancellation;
7162
7330
  if (planShellDecision.classification !== "not-applicable") {
7163
7331
  const initialPlanShellError = await validatePlanModeShellContext({
7164
7332
  config: this.config,
@@ -7167,17 +7335,31 @@ ${this.pendingRecoveredAgentsNotice}
7167
7335
  invocationParams: invocation.params,
7168
7336
  signal: activeToolAbortSignal
7169
7337
  });
7338
+ const initialPlanValidationCancellation = cancelBeforeExecutionIfAborted(toolName);
7339
+ if (initialPlanValidationCancellation) {
7340
+ return initialPlanValidationCancellation;
7341
+ }
7170
7342
  if (initialPlanShellError) {
7171
7343
  return earlyErrorResponse(
7172
7344
  new Error(initialPlanShellError),
7173
- toolName
7345
+ toolName,
7346
+ {
7347
+ status: "error",
7348
+ errorType: "execution_denied" /* EXECUTION_DENIED */,
7349
+ executionStatus: "not_started"
7350
+ }
7174
7351
  );
7175
7352
  }
7176
7353
  }
7177
7354
  if (planShellDecision.classification === "write") {
7178
7355
  return earlyErrorResponse(
7179
7356
  new Error(planShellDecision.writeBlockMessage),
7180
- toolName
7357
+ toolName,
7358
+ {
7359
+ status: "error",
7360
+ errorType: "execution_denied" /* EXECUTION_DENIED */,
7361
+ executionStatus: "not_started"
7362
+ }
7181
7363
  );
7182
7364
  }
7183
7365
  const planShellRequiresConfirmation = planShellDecision.classification === "unknown";
@@ -7212,6 +7394,8 @@ ${this.pendingRecoveredAgentsNotice}
7212
7394
  signal: abortSignal,
7213
7395
  skipClassifierReason: fallback.fallback ? fallback.reason : void 0
7214
7396
  });
7397
+ const autoModeCancellation = cancelBeforeExecutionIfAborted(toolName);
7398
+ if (autoModeCancellation) return autoModeCancellation;
7215
7399
  const outcome = applyAutoModeDecision(
7216
7400
  decision,
7217
7401
  this.config,
@@ -7226,6 +7410,10 @@ ${this.pendingRecoveredAgentsNotice}
7226
7410
  callId,
7227
7411
  abortSignal
7228
7412
  );
7413
+ const permissionDeniedHookCancellation = cancelBeforeExecutionIfAborted(toolName);
7414
+ if (permissionDeniedHookCancellation) {
7415
+ return permissionDeniedHookCancellation;
7416
+ }
7229
7417
  switch (outcome.kind) {
7230
7418
  case "approved":
7231
7419
  autoModeAllowed = true;
@@ -7236,7 +7424,12 @@ ${this.pendingRecoveredAgentsNotice}
7236
7424
  );
7237
7425
  return earlyErrorResponse(
7238
7426
  new Error(outcome.errorMessage),
7239
- toolName
7427
+ toolName,
7428
+ {
7429
+ status: "error",
7430
+ errorType: "execution_denied" /* EXECUTION_DENIED */,
7431
+ executionStatus: "not_started"
7432
+ }
7240
7433
  );
7241
7434
  case "fallback":
7242
7435
  wasAutoModeManualFallback = isDenialFallbackReason(outcome.reason) || outcome.reason === "classifier_unavailable";
@@ -7280,6 +7473,10 @@ ${this.pendingRecoveredAgentsNotice}
7280
7473
  confirmationDetails = await invocation.getConfirmationDetails(
7281
7474
  activeToolAbortSignal
7282
7475
  );
7476
+ const confirmationDetailsCancellation = cancelBeforeExecutionIfAborted(toolName);
7477
+ if (confirmationDetailsCancellation) {
7478
+ return confirmationDetailsCancellation;
7479
+ }
7283
7480
  if (autoModeFallbackMessage) {
7284
7481
  confirmationDetails = decorateClassifierUnavailableConfirmation(
7285
7482
  confirmationDetails,
@@ -7294,10 +7491,19 @@ ${this.pendingRecoveredAgentsNotice}
7294
7491
  invocationParams: invocation.params,
7295
7492
  signal: activeToolAbortSignal
7296
7493
  });
7494
+ const preDisplayValidationCancellation = cancelBeforeExecutionIfAborted(toolName);
7495
+ if (preDisplayValidationCancellation) {
7496
+ return preDisplayValidationCancellation;
7497
+ }
7297
7498
  if (preDisplayPlanShellError) {
7298
7499
  return earlyErrorResponse(
7299
7500
  new Error(preDisplayPlanShellError),
7300
- toolName
7501
+ toolName,
7502
+ {
7503
+ status: "error",
7504
+ errorType: "execution_denied" /* EXECUTION_DENIED */,
7505
+ executionStatus: "not_started"
7506
+ }
7301
7507
  );
7302
7508
  }
7303
7509
  }
@@ -7310,7 +7516,12 @@ ${this.pendingRecoveredAgentsNotice}
7310
7516
  if (planShellDecision.classification === "unknown") {
7311
7517
  return earlyErrorResponse(
7312
7518
  new Error(planShellDecision.noApprovalMessage),
7313
- toolName
7519
+ toolName,
7520
+ {
7521
+ status: "error",
7522
+ errorType: "execution_denied" /* EXECUTION_DENIED */,
7523
+ executionStatus: "not_started"
7524
+ }
7314
7525
  );
7315
7526
  }
7316
7527
  throw new Error("Unable to prepare shell confirmation.");
@@ -7327,7 +7538,12 @@ ${this.pendingRecoveredAgentsNotice}
7327
7538
  new Error(
7328
7539
  `Plan mode is active. The tool "${toolName}" cannot be executed because it modifies the system. Please use the exit_plan_mode tool to present your plan and exit plan mode before making changes.`
7329
7540
  ),
7330
- toolName
7541
+ toolName,
7542
+ {
7543
+ status: "error",
7544
+ errorType: "execution_denied" /* EXECUTION_DENIED */,
7545
+ executionStatus: "not_started"
7546
+ }
7331
7547
  );
7332
7548
  }
7333
7549
  const messageBus = this.config.getMessageBus?.();
@@ -7342,6 +7558,10 @@ ${this.pendingRecoveredAgentsNotice}
7342
7558
  void 0,
7343
7559
  activeToolAbortSignal
7344
7560
  );
7561
+ const permissionHookCancellation = cancelBeforeExecutionIfAborted(toolName);
7562
+ if (permissionHookCancellation) {
7563
+ return permissionHookCancellation;
7564
+ }
7345
7565
  if (hookResult.hasDecision && (!hookResult.shouldAllow || !requiresUserInteraction)) {
7346
7566
  hookHandled = true;
7347
7567
  if (hookResult.shouldAllow) {
@@ -7355,16 +7575,29 @@ ${this.pendingRecoveredAgentsNotice}
7355
7575
  outcome: "proceed_once" /* ProceedOnce */,
7356
7576
  payload: hookResult.updatedInput ? { updatedInput: hookResult.updatedInput } : void 0
7357
7577
  });
7578
+ const hookPlanApprovalCancellation = cancelBeforeExecutionIfAborted(toolName);
7579
+ if (hookPlanApprovalCancellation) {
7580
+ return hookPlanApprovalCancellation;
7581
+ }
7358
7582
  await confirmationDetails.onConfirm(
7359
7583
  approval.outcome,
7360
7584
  approval.payload
7361
7585
  );
7586
+ const hookPlanConfirmationCancellation = cancelBeforeExecutionIfAborted(toolName);
7587
+ if (hookPlanConfirmationCancellation) {
7588
+ return hookPlanConfirmationCancellation;
7589
+ }
7362
7590
  if (approval.outcome === "cancel" /* Cancel */) {
7363
7591
  return earlyErrorResponse(
7364
7592
  new Error(
7365
7593
  approval.payload?.cancelMessage ?? planShellDecision.noApprovalMessage
7366
7594
  ),
7367
- toolName
7595
+ toolName,
7596
+ {
7597
+ status: "error",
7598
+ errorType: "execution_denied" /* EXECUTION_DENIED */,
7599
+ executionStatus: "not_started"
7600
+ }
7368
7601
  );
7369
7602
  }
7370
7603
  recordAutoModeFallbackResolution(approval.outcome);
@@ -7376,6 +7609,10 @@ ${this.pendingRecoveredAgentsNotice}
7376
7609
  await confirmationDetails.onConfirm(
7377
7610
  "proceed_once" /* ProceedOnce */
7378
7611
  );
7612
+ const hookConfirmationCancellation = cancelBeforeExecutionIfAborted(toolName);
7613
+ if (hookConfirmationCancellation) {
7614
+ return hookConfirmationCancellation;
7615
+ }
7379
7616
  recordAutoModeFallbackResolution(
7380
7617
  "proceed_once" /* ProceedOnce */
7381
7618
  );
@@ -7385,7 +7622,12 @@ ${this.pendingRecoveredAgentsNotice}
7385
7622
  new Error(
7386
7623
  hookResult.denyMessage || `Permission denied by hook for "${toolName}"`
7387
7624
  ),
7388
- toolName
7625
+ toolName,
7626
+ {
7627
+ status: "error",
7628
+ errorType: "execution_denied" /* EXECUTION_DENIED */,
7629
+ executionStatus: "not_started"
7630
+ }
7389
7631
  );
7390
7632
  }
7391
7633
  }
@@ -7400,10 +7642,19 @@ ${this.pendingRecoveredAgentsNotice}
7400
7642
  invocationParams: invocation.params,
7401
7643
  signal: activeToolAbortSignal
7402
7644
  });
7645
+ const finalPlanValidationCancellation = cancelBeforeExecutionIfAborted(toolName);
7646
+ if (finalPlanValidationCancellation) {
7647
+ return finalPlanValidationCancellation;
7648
+ }
7403
7649
  if (finalPreDisplayPlanShellError) {
7404
7650
  return earlyErrorResponse(
7405
7651
  new Error(finalPreDisplayPlanShellError),
7406
- toolName
7652
+ toolName,
7653
+ {
7654
+ status: "error",
7655
+ errorType: "execution_denied" /* EXECUTION_DENIED */,
7656
+ executionStatus: "not_started"
7657
+ }
7407
7658
  );
7408
7659
  }
7409
7660
  }
@@ -7445,7 +7696,10 @@ ${this.pendingRecoveredAgentsNotice}
7445
7696
  // frame already ships _meta.toolName; mirror it here.
7446
7697
  _meta: {
7447
7698
  toolName,
7448
- ...interactionMetaFields(confirmationDetails)
7699
+ ...interactionMetaFields(confirmationDetails),
7700
+ ...isExitPlanModeTool && this.activeTodoPlanRevision ? {
7701
+ qwenTodoApproval: this.activeTodoPlanRevision
7702
+ } : {}
7449
7703
  }
7450
7704
  }
7451
7705
  };
@@ -7456,7 +7710,12 @@ ${this.pendingRecoveredAgentsNotice}
7456
7710
  message ?? `Tool "${toolName}" was canceled by the user.`
7457
7711
  ),
7458
7712
  toolName,
7459
- { stopAfterPermissionCancel: true }
7713
+ {
7714
+ status: "cancelled",
7715
+ errorType: void 0,
7716
+ executionStatus: "not_started",
7717
+ stopAfterPermissionCancel: true
7718
+ }
7460
7719
  );
7461
7720
  }, "stopAfterPermissionCancel");
7462
7721
  let output;
@@ -7466,6 +7725,10 @@ ${this.pendingRecoveredAgentsNotice}
7466
7725
  params,
7467
7726
  activeToolAbortSignal
7468
7727
  );
7728
+ const permissionRequestCancellation = cancelBeforeExecutionIfAborted(toolName);
7729
+ if (permissionRequestCancellation) {
7730
+ return permissionRequestCancellation;
7731
+ }
7469
7732
  outcome = resolvePermissionOutcome(
7470
7733
  output,
7471
7734
  offeredPermissionOptions
@@ -7485,16 +7748,26 @@ ${this.pendingRecoveredAgentsNotice}
7485
7748
  confirmError
7486
7749
  );
7487
7750
  }
7488
- onStopAfterPermissionCancel?.();
7751
+ const wasAborted = activeToolAbortSignal.aborted;
7752
+ if (!wasAborted) {
7753
+ onStopAfterPermissionCancel?.();
7754
+ }
7489
7755
  const permissionFailureMessage = isExitPlanModeTool ? "The host could not present plan-exit approval. Plan mode remains active; use the host mode selector or /plan exit to leave plan mode." : planShellDecision.classification === "unknown" ? `Plan mode could not complete approval for this shell command: ${this.#formatError(
7490
7756
  error
7491
7757
  )}. The command was not run; Plan mode remains active.` : `Permission request failed for "${toolName}": ${this.#formatError(
7492
7758
  error
7493
7759
  )}`;
7494
7760
  return earlyErrorResponse(
7495
- new Error(permissionFailureMessage),
7761
+ new Error(
7762
+ wasAborted ? "Tool call was cancelled before execution." : permissionFailureMessage
7763
+ ),
7496
7764
  toolName,
7497
- { stopAfterPermissionCancel: true }
7765
+ {
7766
+ status: wasAborted ? "cancelled" : "error",
7767
+ errorType: wasAborted ? void 0 : "unhandled_exception" /* UNHANDLED_EXCEPTION */,
7768
+ executionStatus: "not_started",
7769
+ stopAfterPermissionCancel: !wasAborted
7770
+ }
7498
7771
  );
7499
7772
  }
7500
7773
  let confirmationPayload = {
@@ -7510,6 +7783,10 @@ ${this.pendingRecoveredAgentsNotice}
7510
7783
  outcome,
7511
7784
  payload: confirmationPayload
7512
7785
  });
7786
+ const planApprovalCancellation = cancelBeforeExecutionIfAborted(toolName);
7787
+ if (planApprovalCancellation) {
7788
+ return planApprovalCancellation;
7789
+ }
7513
7790
  outcome = approval.outcome;
7514
7791
  confirmationPayload = approval.payload;
7515
7792
  }
@@ -7523,6 +7800,10 @@ ${this.pendingRecoveredAgentsNotice}
7523
7800
  outcome,
7524
7801
  confirmationPayload
7525
7802
  );
7803
+ const confirmationCancellation = cancelBeforeExecutionIfAborted(toolName);
7804
+ if (confirmationCancellation) {
7805
+ return confirmationCancellation;
7806
+ }
7526
7807
  } catch (error) {
7527
7808
  if (outcome !== "cancel" /* Cancel */) {
7528
7809
  throw error;
@@ -7536,6 +7817,8 @@ ${this.pendingRecoveredAgentsNotice}
7536
7817
  if (shouldSwitchToDefault) {
7537
7818
  this.config.setApprovalMode("default" /* DEFAULT */);
7538
7819
  await this.sendCurrentModeUpdateNotification();
7820
+ const modeUpdateCancellation = cancelBeforeExecutionIfAborted(toolName);
7821
+ if (modeUpdateCancellation) return modeUpdateCancellation;
7539
7822
  }
7540
7823
  if (outcome === "proceed_always" /* ProceedAlways */ || outcome === "proceed_always_project" /* ProceedAlwaysProject */ || outcome === "proceed_always_user" /* ProceedAlwaysUser */) {
7541
7824
  await persistPermissionOutcome(
@@ -7545,9 +7828,17 @@ ${this.pendingRecoveredAgentsNotice}
7545
7828
  this.config.getPermissionManager?.(),
7546
7829
  confirmationPayload
7547
7830
  );
7831
+ const permissionPersistenceCancellation = cancelBeforeExecutionIfAborted(toolName);
7832
+ if (permissionPersistenceCancellation) {
7833
+ return permissionPersistenceCancellation;
7834
+ }
7548
7835
  }
7549
7836
  if (confirmationDetails.type === "edit" && outcome === "proceed_always" /* ProceedAlways */) {
7550
7837
  await this.sendCurrentModeUpdateNotification();
7838
+ const editModeUpdateCancellation = cancelBeforeExecutionIfAborted(toolName);
7839
+ if (editModeUpdateCancellation) {
7840
+ return editModeUpdateCancellation;
7841
+ }
7551
7842
  }
7552
7843
  switch (outcome) {
7553
7844
  case "proceed_once_and_switch_to_default" /* ProceedOnceAndSwitchToDefault */:
@@ -7581,7 +7872,16 @@ ${this.pendingRecoveredAgentsNotice}
7581
7872
  args,
7582
7873
  status: "in_progress"
7583
7874
  };
7584
- await this.toolCallEmitter.emitStart(startParams);
7875
+ try {
7876
+ await this.toolCallEmitter.emitStart(startParams);
7877
+ } catch (emitError) {
7878
+ debugLogger5.debug(
7879
+ "[Session.runTool] Failed to emit tool start update",
7880
+ emitError
7881
+ );
7882
+ }
7883
+ const startEmissionCancellation = cancelBeforeExecutionIfAborted(toolName);
7884
+ if (startEmissionCancellation) return startEmissionCancellation;
7585
7885
  }
7586
7886
  const hooksEnabledForTool = !this.config.getDisableAllHooks?.();
7587
7887
  const messageBusForTool = this.config.getMessageBus?.();
@@ -7596,12 +7896,27 @@ ${this.pendingRecoveredAgentsNotice}
7596
7896
  activeToolAbortSignal,
7597
7897
  callId
7598
7898
  );
7899
+ const preHookCancellation = cancelBeforeExecutionIfAborted(toolName);
7900
+ if (preHookCancellation) return preHookCancellation;
7599
7901
  if (!preHookResult.shouldProceed) {
7600
7902
  const blockReason = preHookResult.blockReason || "Blocked by PreToolUse hook";
7601
- await this.messageEmitter.emitAgentMessage(
7602
- `\u2717 **PreToolUse blocked**: ${toolName} - ${blockReason}`
7603
- );
7604
- return earlyErrorResponse(new Error(blockReason), toolName);
7903
+ try {
7904
+ await this.messageEmitter.emitAgentMessage(
7905
+ `\u2717 **PreToolUse blocked**: ${toolName} - ${blockReason}`
7906
+ );
7907
+ } catch (emitError) {
7908
+ debugLogger5.debug(
7909
+ "[Session.runTool] Failed to emit PreToolUse block message",
7910
+ emitError
7911
+ );
7912
+ }
7913
+ const blockMessageCancellation = cancelBeforeExecutionIfAborted(toolName);
7914
+ if (blockMessageCancellation) return blockMessageCancellation;
7915
+ return earlyErrorResponse(new Error(blockReason), toolName, {
7916
+ status: "error",
7917
+ errorType: "execution_denied" /* EXECUTION_DENIED */,
7918
+ executionStatus: "not_started"
7919
+ });
7605
7920
  }
7606
7921
  if (preHookResult.additionalContext) {
7607
7922
  debugLogger5.debug(
@@ -7611,30 +7926,44 @@ ${this.pendingRecoveredAgentsNotice}
7611
7926
  }
7612
7927
  const toolInvocationGuard = this.config.getToolInvocationGuard?.();
7613
7928
  if (toolInvocationGuard) {
7929
+ const invocationContext = getInvocationContext();
7614
7930
  const guardDecision = await evaluateToolInvocationGuard(
7615
7931
  toolInvocationGuard,
7616
7932
  {
7617
7933
  callId,
7618
7934
  toolName: policyToolName,
7619
7935
  args: invocation.params,
7620
- signal: activeToolAbortSignal
7936
+ signal: activeToolAbortSignal,
7937
+ ...invocationContext ? { invocationContext } : {}
7621
7938
  }
7622
7939
  );
7623
7940
  if (activeToolAbortSignal.aborted) {
7624
7941
  return earlyErrorResponse(
7625
7942
  new Error("Tool invocation was cancelled"),
7626
7943
  toolName,
7627
- { status: "cancelled" }
7944
+ {
7945
+ status: "cancelled",
7946
+ errorType: void 0,
7947
+ executionStatus: "not_started"
7948
+ }
7628
7949
  );
7629
7950
  }
7630
7951
  if (!guardDecision.allowed) {
7631
7952
  return earlyErrorResponse(
7632
7953
  new Error(guardDecision.reason),
7633
7954
  toolName,
7634
- { errorType: "execution_denied" /* EXECUTION_DENIED */ }
7955
+ {
7956
+ status: "error",
7957
+ errorType: "execution_denied" /* EXECUTION_DENIED */,
7958
+ executionStatus: "not_started"
7959
+ }
7635
7960
  );
7636
7961
  }
7637
7962
  }
7963
+ const executionBoundaryCancellation = cancelBeforeExecutionIfAborted(toolName);
7964
+ if (executionBoundaryCancellation) {
7965
+ return executionBoundaryCancellation;
7966
+ }
7638
7967
  const continuedAgentId = toolName === ToolNames.SEND_MESSAGE && typeof args["task_id"] === "string" && args["task_id"].length > 0 ? args["task_id"] : void 0;
7639
7968
  const provisionalRelatedAgent = continuedAgentId !== void 0 && !this.relatedAgentIds.has(continuedAgentId);
7640
7969
  if (provisionalRelatedAgent) {
@@ -7662,9 +7991,9 @@ ${this.pendingRecoveredAgentsNotice}
7662
7991
  this.relatedAgentIds.add(continuedAgentId);
7663
7992
  }
7664
7993
  }, "settleRelatedAgent");
7665
- const execSpan = startToolExecutionSpan();
7666
7994
  let toolResult;
7667
7995
  let isExecutionTimeout = false;
7996
+ let parentAbortedAtExecutionSettle = false;
7668
7997
  let aborted = false;
7669
7998
  let toolSettled = false;
7670
7999
  let heartbeatCount = 0;
@@ -7694,58 +8023,81 @@ ${this.pendingRecoveredAgentsNotice}
7694
8023
  }
7695
8024
  }
7696
8025
  } : void 0, "heartbeatSpanAttributes");
8026
+ const sleepInhibitorHandle = acquireSleepInhibitor(
8027
+ this.config,
8028
+ `Qwen Code is executing tool ${toolName}`
8029
+ );
7697
8030
  try {
7698
- const sleepInhibitorHandle = acquireSleepInhibitor(
7699
- this.config,
7700
- `Qwen Code is executing tool ${toolName}`
7701
- );
7702
8031
  try {
7703
- try {
7704
- addToolArgumentsAttributes(
7705
- this.config,
7706
- toolSpan,
7707
- invocation.params
7708
- );
7709
- } catch {
7710
- debugLogger5.debug(
7711
- "[Session.runTool] Failed to record tool arguments telemetry"
7712
- );
7713
- }
8032
+ addToolArgumentsAttributes(
8033
+ this.config,
8034
+ toolSpan,
8035
+ invocation.params
8036
+ );
8037
+ } catch {
8038
+ debugLogger5.debug(
8039
+ "[Session.runTool] Failed to record tool arguments telemetry"
8040
+ );
8041
+ }
8042
+ const execSpan = startToolExecutionSpan({
8043
+ toolName: policyToolName,
8044
+ callId
8045
+ });
8046
+ executionStatus = "error";
8047
+ try {
7714
8048
  toolResult = await invocation.execute(
7715
8049
  activeToolAbortSignal,
7716
8050
  onToolProgress
7717
8051
  );
7718
- } finally {
7719
- toolSettled = true;
7720
- sleepInhibitorHandle.release();
8052
+ executeReturned = true;
8053
+ parentAbortedAtExecutionSettle = activeToolAbortSignal.aborted;
8054
+ isExecutionTimeout = toolResult.error?.type === "execution_timeout" /* EXECUTION_TIMEOUT */;
8055
+ aborted = parentAbortedAtExecutionSettle && !isExecutionTimeout;
8056
+ executionStatus = aborted ? "cancelled" : toolResult.error ? "error" : "success";
8057
+ executionErrorType = toolResult.error ? toolResult.error.type ?? (toolType === "mcp" ? "mcp_tool_error" /* MCP_TOOL_ERROR */ : "unknown" /* UNKNOWN */) : void 0;
8058
+ settleRelatedAgent(executionStatus === "success");
8059
+ endToolExecutionSpan(execSpan, {
8060
+ success: executionStatus === "success",
8061
+ error: aborted ? "tool_cancelled" : isExecutionTimeout ? "tool_timeout" : toolResult.error ? "tool_error" : void 0,
8062
+ cancelled: aborted,
8063
+ executionStatus,
8064
+ errorType: executionErrorType,
8065
+ ...heartbeatSpanAttributes()
8066
+ });
8067
+ } catch (execError) {
8068
+ const explicitErrorType = execError?.errorType;
8069
+ const executionTimedOut = explicitErrorType === "execution_timeout" /* EXECUTION_TIMEOUT */;
8070
+ executionStatus = activeToolAbortSignal.aborted && !executionTimedOut ? "cancelled" : "error";
8071
+ executionErrorType = executionStatus === "error" ? explicitErrorType ?? (toolType === "mcp" ? "mcp_tool_error" /* MCP_TOOL_ERROR */ : "unhandled_exception" /* UNHANDLED_EXCEPTION */) : void 0;
8072
+ settleRelatedAgent(false);
8073
+ endToolExecutionSpan(execSpan, {
8074
+ success: false,
8075
+ error: executionStatus === "cancelled" ? "tool_cancelled" : executionTimedOut ? "tool_timeout" : "tool_exception",
8076
+ cancelled: executionStatus === "cancelled",
8077
+ executionStatus,
8078
+ errorType: executionErrorType,
8079
+ ...heartbeatSpanAttributes()
8080
+ });
8081
+ throw execError;
7721
8082
  }
7722
- isExecutionTimeout = toolResult.error?.type === "execution_timeout" /* EXECUTION_TIMEOUT */;
7723
- aborted = activeToolAbortSignal.aborted && !isExecutionTimeout;
7724
- settleRelatedAgent(!toolResult.error && !aborted);
7725
- endToolExecutionSpan(execSpan, {
7726
- success: !toolResult.error && !aborted,
7727
- error: aborted ? "tool_cancelled" : isExecutionTimeout ? "tool_timeout" : toolResult.error ? "tool_error" : void 0,
7728
- cancelled: aborted,
7729
- ...heartbeatSpanAttributes()
7730
- });
7731
- } catch (execError) {
7732
- settleRelatedAgent(false);
7733
- endToolExecutionSpan(execSpan, {
7734
- success: false,
7735
- error: activeToolAbortSignal.aborted ? "tool_cancelled" : "tool_exception",
7736
- cancelled: activeToolAbortSignal.aborted,
7737
- ...heartbeatSpanAttributes()
7738
- });
7739
- throw execError;
8083
+ } finally {
8084
+ toolSettled = true;
8085
+ sleepInhibitorHandle.release();
7740
8086
  }
7741
8087
  cleanupAgentToolResources();
7742
8088
  if ((isEnterPlanModeTool || isExitPlanModeTool) && !toolResult.error && this.config.getApprovalMode() !== approvalMode) {
7743
8089
  await this.sendCurrentModeUpdateNotification();
7744
8090
  if (this.config.getApprovalMode() === "plan" /* PLAN */) {
8091
+ this.activeTodoPlanRevision = void 0;
7745
8092
  this.#clearTodoStopGuardTrustAndDrainAutomaticQueues();
7746
8093
  }
7747
8094
  }
7748
- let responseParts = toolResult.error ? convertToFunctionErrorResponse(
8095
+ let responseParts = aborted ? convertToFunctionErrorResponse(
8096
+ toolName,
8097
+ callId,
8098
+ TOOL_EXECUTION_CANCELLED_MESSAGE,
8099
+ TOOL_EXECUTION_CANCELLED_MESSAGE
8100
+ ) : toolResult.error ? convertToFunctionErrorResponse(
7749
8101
  toolName,
7750
8102
  callId,
7751
8103
  toolResult.llmContent,
@@ -7755,9 +8107,7 @@ ${this.pendingRecoveredAgentsNotice}
7755
8107
  callId,
7756
8108
  toolResult.llmContent
7757
8109
  );
7758
- const status = aborted ? "cancelled" : toolResult.error ? "error" : "success";
7759
- const succeeded = status === "success";
7760
- const responseError = toolResult.error ? new Error(toolResult.error.message) : aborted ? new Error("Tool execution was cancelled") : void 0;
8110
+ let status = aborted ? "cancelled" : toolResult.error ? "error" : "success";
7761
8111
  if (isTrustedTodoWriteTool && !toolResult.error) {
7762
8112
  this.todoStopGuard.observeTodoWrite(
7763
8113
  toolResult.returnDisplay,
@@ -7780,13 +8130,28 @@ ${this.pendingRecoveredAgentsNotice}
7780
8130
  activeToolAbortSignal,
7781
8131
  callId
7782
8132
  );
8133
+ if (activeToolAbortSignal.aborted) {
8134
+ return earlyErrorResponse(
8135
+ new Error(TOOL_POST_EXECUTION_CANCELLED_MESSAGE),
8136
+ toolName,
8137
+ {
8138
+ status: "cancelled",
8139
+ errorType: void 0,
8140
+ executionStatus
8141
+ }
8142
+ );
8143
+ }
7783
8144
  if (postHookResult.shouldStop) {
7784
8145
  const stopMessage = postHookResult.stopReason || "Execution stopped by PostToolUse hook";
7785
8146
  debugLogger5.info(
7786
8147
  `PostToolUse hook requested stop for ${toolName}: ${stopMessage}`
7787
8148
  );
7788
8149
  this.todoStopGuard.suspend();
7789
- return earlyErrorResponse(new Error(stopMessage), toolName);
8150
+ return earlyErrorResponse(new Error(stopMessage), toolName, {
8151
+ status: "error",
8152
+ errorType: "execution_denied" /* EXECUTION_DENIED */,
8153
+ executionStatus
8154
+ });
7790
8155
  }
7791
8156
  if (postHookResult.additionalContext) {
7792
8157
  const contextPart = { text: postHookResult.additionalContext };
@@ -7800,28 +8165,35 @@ ${this.pendingRecoveredAgentsNotice}
7800
8165
  });
7801
8166
  } else if (hooksEnabledForTool && messageBusForTool && (toolResult.error || aborted)) {
7802
8167
  const isInterrupt = aborted;
7803
- const failureHookResult = await firePostToolUseFailureHook(
7804
- messageBusForTool,
7805
- toolUseId,
7806
- policyToolName,
7807
- args,
7808
- toolResult.error?.message ?? "Tool execution was cancelled",
7809
- isInterrupt,
7810
- permissionMode,
7811
- activeToolAbortSignal,
7812
- callId
7813
- );
7814
- if (failureHookResult.additionalContext) {
8168
+ try {
8169
+ const failureHookResult = await firePostToolUseFailureHook(
8170
+ messageBusForTool,
8171
+ toolUseId,
8172
+ policyToolName,
8173
+ args,
8174
+ toolResult.error?.message ?? TOOL_EXECUTION_CANCELLED_MESSAGE,
8175
+ isInterrupt,
8176
+ permissionMode,
8177
+ activeToolAbortSignal,
8178
+ callId
8179
+ );
8180
+ if (failureHookResult.additionalContext) {
8181
+ debugLogger5.debug(
8182
+ `PostToolUseFailure hook additional context for ${toolName}: ${failureHookResult.additionalContext}`
8183
+ );
8184
+ }
8185
+ await this.emitHookArtifactsNotification({
8186
+ hookEventName: "PostToolUseFailure",
8187
+ toolName,
8188
+ toolCallId: callId,
8189
+ artifacts: failureHookResult.artifacts
8190
+ });
8191
+ } catch (hookError) {
7815
8192
  debugLogger5.debug(
7816
- `PostToolUseFailure hook additional context for ${toolName}: ${failureHookResult.additionalContext}`
8193
+ "[Session.runTool] PostToolUseFailure hook failed",
8194
+ hookError
7817
8195
  );
7818
8196
  }
7819
- await this.emitHookArtifactsNotification({
7820
- hookEventName: "PostToolUseFailure",
7821
- toolName,
7822
- toolCallId: callId,
7823
- artifacts: failureHookResult.artifacts
7824
- });
7825
8197
  }
7826
8198
  const visionBridgeNotices = [];
7827
8199
  responseParts = await bridgeToolResultImages({
@@ -7833,7 +8205,29 @@ ${this.pendingRecoveredAgentsNotice}
7833
8205
  });
7834
8206
  const visionBridgeNotice = visionBridgeNotices.length > 0 ? visionBridgeNotices.join("\n") : void 0;
7835
8207
  if (visionBridgeNotice) {
7836
- await this.messageEmitter.emitAgentMessage(visionBridgeNotice);
8208
+ try {
8209
+ await this.messageEmitter.emitAgentMessage(visionBridgeNotice);
8210
+ } catch (emitError) {
8211
+ debugLogger5.debug(
8212
+ "[Session.runTool] Failed to emit vision bridge notice",
8213
+ emitError
8214
+ );
8215
+ }
8216
+ }
8217
+ if (activeToolAbortSignal.aborted && !(isExecutionTimeout && parentAbortedAtExecutionSettle)) {
8218
+ status = "cancelled";
8219
+ responseParts = convertToFunctionErrorResponse(
8220
+ toolName,
8221
+ callId,
8222
+ TOOL_POST_EXECUTION_CANCELLED_MESSAGE,
8223
+ TOOL_POST_EXECUTION_CANCELLED_MESSAGE
8224
+ );
8225
+ }
8226
+ terminalStatus = status;
8227
+ const succeeded = status === "success";
8228
+ const responseError = status === "error" && toolResult.error ? new Error(toolResult.error.message) : status === "cancelled" ? new Error(TOOL_POST_EXECUTION_CANCELLED_MESSAGE) : void 0;
8229
+ if (isTrustedTodoWriteTool && status === "cancelled") {
8230
+ this.todoStopGuard.suspend();
7837
8231
  }
7838
8232
  if (isTodoWriteTool) {
7839
8233
  const plan = this.planEmitter.extractPlan(
@@ -7841,34 +8235,60 @@ ${this.pendingRecoveredAgentsNotice}
7841
8235
  succeeded ? args : void 0
7842
8236
  );
7843
8237
  if (plan && (plan.todos.length > 0 || Array.isArray(args["todos"]))) {
7844
- await this.planEmitter.emitPlan(plan, callId);
8238
+ try {
8239
+ await this.planEmitter.emitPlan(plan, callId);
8240
+ } catch (emitError) {
8241
+ debugLogger5.debug(
8242
+ "[Session.runTool] Failed to emit plan update",
8243
+ emitError
8244
+ );
8245
+ }
7845
8246
  }
7846
8247
  } else if (!isTodoWriteTool) {
7847
- await this.toolCallEmitter.emitResult({
7848
- callId,
7849
- toolName,
7850
- args,
7851
- message: responseParts,
7852
- resultDisplay: toolResult.returnDisplay,
7853
- error: responseError,
8248
+ try {
8249
+ await this.toolCallEmitter.emitResult({
8250
+ callId,
8251
+ toolName,
8252
+ args,
8253
+ message: responseParts,
8254
+ resultDisplay: toolResult.returnDisplay,
8255
+ error: responseError,
8256
+ success: succeeded,
8257
+ artifacts: toolResult.artifacts
8258
+ });
8259
+ } catch (emitError) {
8260
+ debugLogger5.debug(
8261
+ "[Session.runTool] Failed to emit terminal tool update",
8262
+ emitError
8263
+ );
8264
+ }
8265
+ }
8266
+ const durationMs = Date.now() - startTime;
8267
+ try {
8268
+ logToolCall(this.config, {
8269
+ "event.name": "tool_call",
8270
+ "event.timestamp": (/* @__PURE__ */ new Date()).toISOString(),
8271
+ call_id: callId,
8272
+ function_name: toolName,
8273
+ function_args: args,
8274
+ duration_ms: durationMs,
8275
+ status,
8276
+ execution_status: executionStatus,
7854
8277
  success: succeeded,
7855
- artifacts: toolResult.artifacts
8278
+ ...status === "error" ? {
8279
+ error: toolResult.error?.message,
8280
+ error_type: executionErrorType
8281
+ } : {},
8282
+ prompt_id: promptId,
8283
+ tool_type: toolType,
8284
+ mcp_server_name: mcpServerName
7856
8285
  });
8286
+ } catch (telemetryError) {
8287
+ debugLogger5.debug(
8288
+ "[Session.runTool] Failed to record terminal tool telemetry",
8289
+ telemetryError
8290
+ );
7857
8291
  }
7858
- const durationMs = Date.now() - startTime;
7859
- logToolCall(this.config, {
7860
- "event.name": "tool_call",
7861
- "event.timestamp": (/* @__PURE__ */ new Date()).toISOString(),
7862
- function_name: toolName,
7863
- function_args: args,
7864
- duration_ms: durationMs,
7865
- status,
7866
- success: succeeded,
7867
- error: toolResult.error?.message,
7868
- error_type: toolResult.error?.type,
7869
- prompt_id: promptId,
7870
- tool_type: typeof tool !== "undefined" && tool instanceof DiscoveredMCPTool ? "mcp" : "native"
7871
- });
7872
8292
  queueToolResultRecord?.(fc, {
7873
8293
  callId,
7874
8294
  toolName,
@@ -7877,13 +8297,13 @@ ${this.pendingRecoveredAgentsNotice}
7877
8297
  metadata: {
7878
8298
  callId,
7879
8299
  status,
8300
+ executionStatus,
7880
8301
  resultDisplay: toolResult.returnDisplay,
7881
8302
  ...visionBridgeNotice !== void 0 ? { visionBridgeNotice } : {},
7882
- error: toolResult.error ? new Error(toolResult.error.message) : void 0,
7883
- errorType: toolResult.error?.type
8303
+ error: status === "error" && toolResult.error ? new Error(toolResult.error.message) : void 0,
8304
+ errorType: status === "error" ? executionErrorType : void 0
7884
8305
  }
7885
8306
  });
7886
- spanSuccess = succeeded;
7887
8307
  if (succeeded && !nestedPermissionCancelled) {
7888
8308
  const result = responseParts.find(
7889
8309
  (part) => part.functionResponse !== void 0
@@ -7898,10 +8318,8 @@ ${this.pendingRecoveredAgentsNotice}
7898
8318
  }
7899
8319
  }
7900
8320
  }
7901
- if (toolResult.error) {
8321
+ if (status === "error" && toolResult.error) {
7902
8322
  spanError = toolResult.error.message;
7903
- } else if (aborted) {
7904
- spanError = "Tool execution was cancelled";
7905
8323
  }
7906
8324
  return {
7907
8325
  parts: responseParts,
@@ -7915,66 +8333,74 @@ ${this.pendingRecoveredAgentsNotice}
7915
8333
  ] : void 0
7916
8334
  };
7917
8335
  } catch (e) {
7918
- cleanupAgentToolResources();
7919
8336
  const error = e instanceof Error ? e : new Error(String(e));
7920
- spanError = error.message;
7921
8337
  const hooksEnabledForError = !this.config.getDisableAllHooks?.();
7922
8338
  const messageBusForError = this.config.getMessageBus?.();
7923
- const isInterrupt = activeToolAbortSignal.aborted;
8339
+ const executionTimeoutException = !executeReturned && executionErrorType === "execution_timeout" /* EXECUTION_TIMEOUT */;
8340
+ let status = executionStatus === "cancelled" || activeToolAbortSignal.aborted && !executionTimeoutException ? "cancelled" : "error";
8341
+ const isInterrupt = status === "cancelled";
7924
8342
  if (hooksEnabledForError && messageBusForError) {
7925
- const failureHookResult = await firePostToolUseFailureHook(
7926
- messageBusForError,
7927
- toolUseId,
7928
- policyToolName,
7929
- args,
7930
- error.message,
7931
- isInterrupt,
7932
- String(approvalMode),
7933
- activeToolAbortSignal,
7934
- callId
7935
- );
7936
- if (failureHookResult.additionalContext) {
8343
+ try {
8344
+ const failureHookResult = await firePostToolUseFailureHook(
8345
+ messageBusForError,
8346
+ toolUseId,
8347
+ policyToolName,
8348
+ args,
8349
+ error.message,
8350
+ isInterrupt,
8351
+ String(approvalMode),
8352
+ activeToolAbortSignal,
8353
+ callId
8354
+ );
8355
+ if (failureHookResult.additionalContext) {
8356
+ debugLogger5.debug(
8357
+ `PostToolUseFailure hook additional context for ${toolName}: ${failureHookResult.additionalContext}`
8358
+ );
8359
+ }
8360
+ await this.emitHookArtifactsNotification({
8361
+ hookEventName: "PostToolUseFailure",
8362
+ toolName,
8363
+ toolCallId: callId,
8364
+ artifacts: failureHookResult.artifacts
8365
+ });
8366
+ } catch (hookError) {
7937
8367
  debugLogger5.debug(
7938
- `PostToolUseFailure hook additional context for ${toolName}: ${failureHookResult.additionalContext}`
8368
+ "[Session.runTool] PostToolUseFailure hook failed",
8369
+ hookError
7939
8370
  );
7940
8371
  }
7941
- await this.emitHookArtifactsNotification({
7942
- hookEventName: "PostToolUseFailure",
7943
- toolName,
7944
- toolCallId: callId,
7945
- artifacts: failureHookResult.artifacts
7946
- });
7947
8372
  }
7948
- await this.toolCallEmitter.emitError(callId, toolName, error);
7949
- const loopDetected = !activeToolAbortSignal.aborted && !toolBuildSucceeded && recordDaemonInvalidToolParams(
7950
- this.config,
7951
- promptId,
7952
- toolLoopState,
7953
- toolName,
7954
- error
7955
- );
7956
- const responseParts = errorResponse(error);
7957
- queueToolResultRecord?.(fc, {
7958
- callId,
7959
- toolName,
7960
- responseParts,
7961
- metadata: {
7962
- callId,
7963
- status: activeToolAbortSignal.aborted ? "cancelled" : "error",
7964
- resultDisplay: void 0,
7965
- error,
7966
- errorType: void 0
7967
- }
8373
+ if (activeToolAbortSignal.aborted && !executionTimeoutException) {
8374
+ status = "cancelled";
8375
+ }
8376
+ const explicitErrorType = e?.errorType;
8377
+ const errorType = status === "cancelled" ? void 0 : explicitErrorType ?? (executeReturned ? "unhandled_exception" /* UNHANDLED_EXCEPTION */ : executionErrorType ?? (!toolBuildSucceeded ? "invalid_tool_params" /* INVALID_TOOL_PARAMS */ : "unhandled_exception" /* UNHANDLED_EXCEPTION */));
8378
+ return earlyErrorResponse(error, toolName, {
8379
+ status,
8380
+ errorType,
8381
+ executionStatus,
8382
+ recordInvalidToolParams: !toolBuildSucceeded,
8383
+ stopAfterPermissionCancel: nestedPermissionCancelled
7968
8384
  });
7969
- return {
7970
- parts: responseParts,
7971
- stopAfterPermissionCancel: nestedPermissionCancelled,
7972
- loopDetected
7973
- };
7974
8385
  }
7975
8386
  });
8387
+ } catch (e) {
8388
+ const error = e instanceof Error ? e : new Error(String(e));
8389
+ const status = activeToolAbortSignal.aborted ? "cancelled" : "error";
8390
+ return await earlyErrorResponse(error, toolName, {
8391
+ status,
8392
+ errorType: status === "error" ? "unhandled_exception" /* UNHANDLED_EXCEPTION */ : void 0,
8393
+ executionStatus
8394
+ });
7976
8395
  } finally {
7977
- endToolSpan(toolSpan, { success: spanSuccess, error: spanError });
8396
+ if (terminalStatus === "cancelled") {
8397
+ endToolSpan(toolSpan, { success: false, cancelled: true });
8398
+ } else {
8399
+ endToolSpan(toolSpan, {
8400
+ success: terminalStatus === "success",
8401
+ error: spanError
8402
+ });
8403
+ }
7978
8404
  }
7979
8405
  }
7980
8406
  #emitGoalStatusItems(result) {
@@ -10308,6 +10734,74 @@ async function deliverClientMcpMessage(connection, serverName, message, sessionI
10308
10734
  return payload;
10309
10735
  }
10310
10736
  __name(deliverClientMcpMessage, "deliverClientMcpMessage");
10737
+ function createManagedExternalToolGuard(connection) {
10738
+ return async (context) => {
10739
+ const invocation = context.invocationContext;
10740
+ if (!invocation) {
10741
+ throw new Error(
10742
+ "Managed external tool guard requires a runtime invocation context."
10743
+ );
10744
+ }
10745
+ if (context.signal.aborted) {
10746
+ throw new DOMException("Tool invocation aborted", "AbortError");
10747
+ }
10748
+ if (context.toolName === ToolNames.AGENT || context.toolName === ToolNames.WORKFLOW || context.toolName === ToolNames.CREATE_SUB_SESSION || context.toolName === ToolNames.SEND_MESSAGE) {
10749
+ return {
10750
+ allowed: false,
10751
+ reason: "Managed external tool guard v1 does not support nested or delegated agent execution."
10752
+ };
10753
+ }
10754
+ let rejectOnAbort;
10755
+ const aborted = new Promise((_resolve, reject) => {
10756
+ rejectOnAbort = reject;
10757
+ });
10758
+ const onAbort = /* @__PURE__ */ __name(() => rejectOnAbort?.(
10759
+ new DOMException("Tool invocation aborted", "AbortError")
10760
+ ), "onAbort");
10761
+ context.signal.addEventListener("abort", onAbort, { once: true });
10762
+ if (context.signal.aborted) onAbort();
10763
+ try {
10764
+ const response = await Promise.race([
10765
+ connection.extMethod(
10766
+ SERVE_CONTROL_EXT_METHODS.externalToolGuardPrepare,
10767
+ {
10768
+ sessionId: invocation.sessionId,
10769
+ promptId: invocation.promptId,
10770
+ toolCallId: context.callId,
10771
+ toolName: context.toolName,
10772
+ arguments: context.args
10773
+ }
10774
+ ),
10775
+ aborted
10776
+ ]);
10777
+ const keys = Object.keys(response);
10778
+ if (typeof response["allowed"] !== "boolean" || keys.some((key) => key !== "allowed" && key !== "reason")) {
10779
+ throw new Error(
10780
+ "Managed external tool guard returned an invalid reply."
10781
+ );
10782
+ }
10783
+ if (response["allowed"]) {
10784
+ if (Object.hasOwn(response, "reason")) {
10785
+ throw new Error(
10786
+ "Managed external tool guard allow reply contains a reason."
10787
+ );
10788
+ }
10789
+ return { allowed: true };
10790
+ }
10791
+ const reason = response["reason"];
10792
+ if (reason === void 0) return { allowed: false };
10793
+ if (!isValidExternalToolGuardDenialReason(reason)) {
10794
+ throw new Error(
10795
+ "Managed external tool guard denial reason is invalid."
10796
+ );
10797
+ }
10798
+ return { allowed: false, reason };
10799
+ } finally {
10800
+ context.signal.removeEventListener("abort", onAbort);
10801
+ }
10802
+ };
10803
+ }
10804
+ __name(createManagedExternalToolGuard, "createManagedExternalToolGuard");
10311
10805
  function readRuntimeMcpRequest(params) {
10312
10806
  const name = params["name"];
10313
10807
  if (typeof name !== "string" || name.length === 0) {
@@ -10401,6 +10895,14 @@ async function runAcpAgent(config, settings, argv, options) {
10401
10895
  const sessionWriterLeaseEnabledAtStartup = typeof config.isSessionWriterLeaseEnabled === "function" ? config.isSessionWriterLeaseEnabled() : settings.merged.experimental?.sessionWriterLease === true;
10402
10896
  const privateParentCapability = options === void 0 ? process.env[PRIVATE_ACP_CAPABILITY_ENV] : options.privateParentCapability;
10403
10897
  delete process.env[PRIVATE_ACP_CAPABILITY_ENV];
10898
+ delete process.env[PRIVATE_EXTERNAL_TOOL_GUARD_ENV];
10899
+ delete process.env[EXTERNAL_TOOL_GUARD_TOKEN_ENV];
10900
+ const externalToolGuardRequired = options?.externalToolGuardRequired === true;
10901
+ if (externalToolGuardRequired && privateParentCapability === void 0) {
10902
+ throw new Error(
10903
+ "Required external tool guard is available only to a private managed ACP parent."
10904
+ );
10905
+ }
10404
10906
  let acpConnection;
10405
10907
  const bootstrapClientMcpSender = /* @__PURE__ */ __name((serverName, message) => deliverClientMcpMessage(acpConnection, serverName, message), "bootstrapClientMcpSender");
10406
10908
  beginAcpBootstrapConfigProfiling();
@@ -10477,13 +10979,15 @@ async function runAcpAgent(config, settings, argv, options) {
10477
10979
  });
10478
10980
  connection = new AgentSideConnection((conn) => {
10479
10981
  acpConnection = conn;
10982
+ const managedToolInvocationGuard = externalToolGuardRequired ? createManagedExternalToolGuard(conn) : void 0;
10480
10983
  agentInstance = new QwenAgent(
10481
10984
  config,
10482
10985
  settings,
10483
10986
  argv,
10484
10987
  conn,
10485
10988
  privateParentCapability,
10486
- sessionWriterLeaseEnabledAtStartup
10989
+ sessionWriterLeaseEnabledAtStartup,
10990
+ managedToolInvocationGuard
10487
10991
  );
10488
10992
  return agentInstance;
10489
10993
  }, stream);
@@ -10780,13 +11284,14 @@ function parseAcpSessionListCursor(value) {
10780
11284
  }
10781
11285
  __name(parseAcpSessionListCursor, "parseAcpSessionListCursor");
10782
11286
  var QwenAgent = class {
10783
- constructor(config, settings, argv, connection, expectedPrivateParentCapability, sessionWriterLeaseEnabledAtStartup = false) {
11287
+ constructor(config, settings, argv, connection, expectedPrivateParentCapability, sessionWriterLeaseEnabledAtStartup = false, managedToolInvocationGuard) {
10784
11288
  this.config = config;
10785
11289
  this.settings = settings;
10786
11290
  this.argv = argv;
10787
11291
  this.connection = connection;
10788
11292
  this.expectedPrivateParentCapability = expectedPrivateParentCapability;
10789
11293
  this.sessionWriterLeaseEnabledAtStartup = sessionWriterLeaseEnabledAtStartup;
11294
+ this.managedToolInvocationGuard = managedToolInvocationGuard;
10790
11295
  if (process.env["QWEN_SERVE_NO_MCP_POOL"] === "1") {
10791
11296
  this.mcpPool = void 0;
10792
11297
  this.workspaceMcpBudget = void 0;
@@ -10877,6 +11382,14 @@ var QwenAgent = class {
10877
11382
  throw new SessionWriterUnavailableError();
10878
11383
  }
10879
11384
  }
11385
+ rejectUnsupportedGuardedHiddenAgent(operation) {
11386
+ if (this.managedToolInvocationGuard) {
11387
+ throw RequestError.invalidParams(
11388
+ void 0,
11389
+ `Managed external tool guard v1 does not support ${operation}.`
11390
+ );
11391
+ }
11392
+ }
10880
11393
  beginManagedShutdown() {
10881
11394
  if (!this.isTrustedManagedParent()) {
10882
11395
  throw new Error("Managed shutdown requires a trusted private parent");
@@ -11528,7 +12041,7 @@ var QwenAgent = class {
11528
12041
  }
11529
12042
  this.clientCapabilities = args.clientCapabilities;
11530
12043
  const authMethods = buildAuthMethods();
11531
- const version = "0.21.4";
12044
+ const version = "0.21.5-nightly.20260805.32e274157";
11532
12045
  const response = {
11533
12046
  protocolVersion: PROTOCOL_VERSION,
11534
12047
  agentInfo: {
@@ -11567,12 +12080,13 @@ var QwenAgent = class {
11567
12080
  }
11568
12081
  const requestedProfile = args._meta?.[CHANNEL_STARTUP_PROFILE_META_KEY];
11569
12082
  const profileRequested = requestedProfile !== null && typeof requestedProfile === "object" && !Array.isArray(requestedProfile) && requestedProfile["v"] === CHANNEL_STARTUP_PROFILE_VERSION;
11570
- return profileRequested && startupProfile ? {
11571
- ...response,
11572
- _meta: {
11573
- [CHANNEL_STARTUP_PROFILE_META_KEY]: startupProfile
11574
- }
11575
- } : response;
12083
+ const responseMeta = {
12084
+ ...this.managedToolInvocationGuard ? {
12085
+ [EXTERNAL_TOOL_GUARD_READY_META_KEY]: EXTERNAL_TOOL_GUARD_REQUIRED_VALUE
12086
+ } : {},
12087
+ ...profileRequested && startupProfile ? { [CHANNEL_STARTUP_PROFILE_META_KEY]: startupProfile } : {}
12088
+ };
12089
+ return Object.keys(responseMeta).length > 0 ? { ...response, _meta: responseMeta } : response;
11576
12090
  }
11577
12091
  async authenticate({ methodId }) {
11578
12092
  const method = external_exports.nativeEnum(AuthType).parse(methodId);
@@ -11693,8 +12207,12 @@ var QwenAgent = class {
11693
12207
  logger: debugLogger6
11694
12208
  });
11695
12209
  if (!bulkReplay2) {
11696
- for (const update of replay.updates) {
11697
- await liveSession.sendUpdate(update);
12210
+ try {
12211
+ for (const update of replay.updates) {
12212
+ await liveSession.sendUpdate(update);
12213
+ }
12214
+ } finally {
12215
+ liveSession.clearActiveTodoPlanRevision();
11698
12216
  }
11699
12217
  if (replay.replayError !== void 0) {
11700
12218
  throw RequestError.internalError(void 0, replay.replayError);
@@ -14381,9 +14899,12 @@ var QwenAgent = class {
14381
14899
  );
14382
14900
  case SERVE_CONTROL_EXT_METHODS.workspaceMemoryRememberAvailability:
14383
14901
  return {
14384
- available: this.config.isManagedMemoryAvailable()
14902
+ available: !this.managedToolInvocationGuard && this.config.isManagedMemoryAvailable()
14385
14903
  };
14386
14904
  case SERVE_CONTROL_EXT_METHODS.workspaceMemoryRemember: {
14905
+ this.rejectUnsupportedGuardedHiddenAgent(
14906
+ "agent-backed workspace memory remember"
14907
+ );
14387
14908
  const content = params["content"];
14388
14909
  if (typeof content !== "string" || !content.trim()) {
14389
14910
  throw RequestError.invalidParams(
@@ -14562,6 +15083,9 @@ var QwenAgent = class {
14562
15083
  }
14563
15084
  }
14564
15085
  case SERVE_CONTROL_EXT_METHODS.workspaceMemoryDream: {
15086
+ this.rejectUnsupportedGuardedHiddenAgent(
15087
+ "agent-backed workspace memory dream"
15088
+ );
14565
15089
  if (!this.config.isManagedMemoryAvailable()) {
14566
15090
  throw new RequestError(
14567
15091
  -32009,
@@ -15478,6 +16002,9 @@ var QwenAgent = class {
15478
16002
  }
15479
16003
  const current = config.getApprovalMode();
15480
16004
  if (current === "plan") {
16005
+ if (previous !== "plan") {
16006
+ session.clearActiveTodoPlanRevision();
16007
+ }
15481
16008
  session.clearTodoStopGuardTrust();
15482
16009
  }
15483
16010
  return { previous, current };
@@ -15708,6 +16235,12 @@ var QwenAgent = class {
15708
16235
  return { sessionId, answer: result.text || null };
15709
16236
  }
15710
16237
  case SERVE_CONTROL_EXT_METHODS.sessionForkAgent: {
16238
+ if (this.managedToolInvocationGuard) {
16239
+ throw RequestError.invalidParams(
16240
+ void 0,
16241
+ "Managed external tool guard v1 does not support /fork."
16242
+ );
16243
+ }
15711
16244
  const sessionId = params["sessionId"];
15712
16245
  if (typeof sessionId !== "string" || sessionId.length === 0) {
15713
16246
  throw RequestError.invalidParams(
@@ -16713,6 +17246,7 @@ ${outputText}
16713
17246
  try {
16714
17247
  config.setApprovalMode(newMode);
16715
17248
  if (newMode === "plan") {
17249
+ session.clearActiveTodoPlanRevision();
16716
17250
  session.clearTodoStopGuardTrust();
16717
17251
  }
16718
17252
  } catch (err) {
@@ -17058,7 +17592,8 @@ ${outputText}
17058
17592
  // A duplicate caller-supplied session id must fail this one request,
17059
17593
  // not process.exit(1) the shared ACP child and every session on its
17060
17594
  // channel. newSessionConfig maps the throw to a RequestError.
17061
- true
17595
+ true,
17596
+ this.managedToolInvocationGuard ? { toolInvocationGuard: this.managedToolInvocationGuard } : void 0
17062
17597
  );
17063
17598
  if (sessionSource) {
17064
17599
  config.setSessionSource(sessionSource.sourceType, sessionSource.sourceId);
@@ -17333,6 +17868,7 @@ __name(diffSettingsKeys, "diffSettingsKeys");
17333
17868
  export {
17334
17869
  AUTH_PREFLIGHT_ENV_KEYS,
17335
17870
  AUTH_PREFLIGHT_WAIVED_AUTH_TYPES,
17871
+ createManagedExternalToolGuard,
17336
17872
  createWorkspaceMcpBudget,
17337
17873
  deliverClientMcpMessage,
17338
17874
  extractFilesFromTarGz,