@qwen-code/qwen-code 0.21.10 → 0.21.11-nightly.20260815.c396fe3d12

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 (386) hide show
  1. package/bundled/coordinate/SKILL.md +52 -0
  2. package/bundled/qc-helper/docs/configuration/model-providers.md +10 -8
  3. package/bundled/qc-helper/docs/configuration/settings.md +10 -0
  4. package/bundled/qc-helper/docs/extension/_meta.ts +1 -0
  5. package/bundled/qc-helper/docs/extension/agent-plugins.md +50 -0
  6. package/bundled/qc-helper/docs/extension/extension-releasing.md +3 -3
  7. package/bundled/qc-helper/docs/extension/introduction.md +17 -3
  8. package/bundled/qc-helper/docs/features/_meta.ts +1 -0
  9. package/bundled/qc-helper/docs/features/arena.md +4 -3
  10. package/bundled/qc-helper/docs/features/channels/overview.md +1 -1
  11. package/bundled/qc-helper/docs/features/channels/plugins.md +11 -11
  12. package/bundled/qc-helper/docs/features/code-review.md +1 -1
  13. package/bundled/qc-helper/docs/features/commands.md +7 -6
  14. package/bundled/qc-helper/docs/features/dual-output.md +5 -0
  15. package/bundled/qc-helper/docs/features/headless.md +8 -0
  16. package/bundled/qc-helper/docs/features/multi-agent-coordination.md +30 -0
  17. package/bundled/qc-helper/docs/qwen-serve.md +105 -40
  18. package/bundled/review/SKILL.md +72 -43
  19. package/chunks/{MaxSizedBox-FKXYULMW.js → MaxSizedBox-RRYY7LE5.js} +45 -44
  20. package/chunks/{StandaloneSessionPicker-OQS3M7AY.js → StandaloneSessionPicker-CK3O3N7F.js} +68 -67
  21. package/chunks/{acp-startup-profiler-VNTFWYAC.js → acp-startup-profiler-SVPUHLXV.js} +2 -2
  22. package/chunks/{acpAgent-AGS6HLQQ.js → acpAgent-DXUWYWDM.js} +1889 -640
  23. package/chunks/{agent-4NCVO27U.js → agent-DEPG4BP7.js} +42 -41
  24. package/chunks/agent-headless-VLBUWGPP.js +87 -0
  25. package/chunks/{anthropicContentGenerator-D3Y4RFT4.js → anthropicContentGenerator-YDT4EOKO.js} +8 -8
  26. package/chunks/{artifact-tool-N652YE4L.js → artifact-tool-4GCQQDZI.js} +2 -2
  27. package/chunks/{askUserQuestion-ONW74PKJ.js → askUserQuestion-HZJJLR3Z.js} +2 -2
  28. package/chunks/bridge-U7LETTTF.js +104 -0
  29. package/chunks/{ca-ZLKAB4K3.js → ca-4CQ6MYNQ.js} +2 -1
  30. package/chunks/{channel-management-service-PHELKOW2.js → channel-management-service-OADNGQM3.js} +6 -6
  31. package/chunks/channel-settings-store-B2GRIZ2D.js +102 -0
  32. package/chunks/{channel-worker-group-WQP4RCDO.js → channel-worker-group-IHBIHQ45.js} +9 -8
  33. package/chunks/{channel-worker-manager-MRDFAKIM.js → channel-worker-manager-GEHYJ5AE.js} +9 -8
  34. package/chunks/{channel-worker-supervisor-IVSDIMI4.js → channel-worker-supervisor-ZJIIWM4I.js} +7 -6
  35. package/chunks/{chunk-26CXSA6V.js → chunk-25VWCPYE.js} +2 -2
  36. package/chunks/{chunk-DP3IHZGG.js → chunk-2AUM35J5.js} +59 -7
  37. package/chunks/{chunk-URKIBIFC.js → chunk-2QHWLRQ2.js} +3 -3
  38. package/chunks/{chunk-4PYCZH2V.js → chunk-2ZWH53I4.js} +3 -3
  39. package/chunks/{chunk-UVX4Y6IN.js → chunk-3AEKDXKT.js} +1 -1
  40. package/chunks/{chunk-ABVRJU3D.js → chunk-3ER3FWZM.js} +9 -9
  41. package/chunks/{chunk-DZUO626D.js → chunk-3GM5DLBI.js} +3 -3
  42. package/chunks/{chunk-VSFKIRRW.js → chunk-3NBTNFNC.js} +4 -4
  43. package/chunks/{chunk-NEOXOWYH.js → chunk-3QZY3JSR.js} +7 -7
  44. package/chunks/{chunk-BKHCW2BI.js → chunk-3VUENPWF.js} +10 -0
  45. package/chunks/{chunk-67EWJE77.js → chunk-45NQKMYB.js} +1 -1
  46. package/chunks/{chunk-KKBPOU75.js → chunk-4AOVQPJU.js} +1 -1
  47. package/chunks/{chunk-OONWZLFK.js → chunk-4EB5GRRC.js} +4 -4
  48. package/chunks/{chunk-YGT2AUJ7.js → chunk-4KM2SYK5.js} +39 -19
  49. package/chunks/{chunk-Y3OVRWRY.js → chunk-4N4JVRZA.js} +1 -1
  50. package/chunks/{chunk-VNNWAZSI.js → chunk-56HVDG3M.js} +6 -6
  51. package/chunks/{chunk-TRRF5BSP.js → chunk-5C42HXEX.js} +1 -1
  52. package/chunks/{chunk-J6SZID63.js → chunk-5RUCD4ED.js} +2 -2
  53. package/chunks/{chunk-WAUGQKUU.js → chunk-63FNZTWG.js} +9 -5
  54. package/chunks/{chunk-F6WDTQ3M.js → chunk-655DWW7X.js} +5 -5
  55. package/chunks/{chunk-AAE6SR4Q.js → chunk-7P5NK5EI.js} +1 -1
  56. package/chunks/{chunk-MZSJ43WV.js → chunk-7U5G6JXI.js} +24 -2
  57. package/chunks/{chunk-GWVUR3QZ.js → chunk-7WROZ3E6.js} +3 -3
  58. package/chunks/{chunk-PBRVUF5B.js → chunk-A6NRNRKE.js} +1 -1
  59. package/chunks/{chunk-IBUGFUXC.js → chunk-A6TJ7QUA.js} +13 -13
  60. package/chunks/{chunk-DCZEPFB4.js → chunk-ADM4C4TX.js} +3 -3
  61. package/chunks/{chunk-UBX6NL47.js → chunk-AGWK35OJ.js} +47 -3
  62. package/chunks/{chunk-4MKXUHXY.js → chunk-AGWZRQJJ.js} +5 -5
  63. package/chunks/{chunk-GNPNYXJB.js → chunk-AKBFSOC5.js} +2 -2
  64. package/chunks/{chunk-YWPSGJFI.js → chunk-ARSQPRYL.js} +2 -2
  65. package/chunks/{chunk-IWTMYQ32.js → chunk-AVKPDOQZ.js} +12 -11
  66. package/chunks/{chunk-DX3RGJMS.js → chunk-AW27A43Y.js} +76 -19
  67. package/chunks/{chunk-MIKXJYZB.js → chunk-AZPFLLFR.js} +315 -299
  68. package/chunks/{chunk-2PLNY5TN.js → chunk-BBCGHZ4S.js} +4 -4
  69. package/chunks/{chunk-KID7K6H2.js → chunk-BP5VZBVK.js} +6 -6
  70. package/chunks/{chunk-LLCWZQCU.js → chunk-BRQR2FJ5.js} +3 -3
  71. package/chunks/{chunk-LHEC5V6G.js → chunk-BSR5AXZR.js} +4 -3
  72. package/chunks/{chunk-ONSZH6VM.js → chunk-CGM3E75C.js} +2 -2
  73. package/chunks/{chunk-SEZ556DZ.js → chunk-CPFFU46D.js} +1 -1
  74. package/chunks/{chunk-H6XPXXMH.js → chunk-CQ35AJ4Z.js} +252 -254
  75. package/chunks/{chunk-7MH4J33A.js → chunk-D2RNVVH6.js} +2 -2
  76. package/chunks/{chunk-M6HMMKVG.js → chunk-D7QGE3RT.js} +1 -1
  77. package/chunks/{chunk-UMD7WQTR.js → chunk-D7VALEOK.js} +13 -9
  78. package/chunks/chunk-DAV4QFD5.js +1280 -0
  79. package/chunks/{chunk-B2GJNDTV.js → chunk-DD6O3ZRD.js} +1 -1
  80. package/chunks/{chunk-HUWENAHO.js → chunk-DEDESZDL.js} +1 -1
  81. package/chunks/{chunk-3P2LV43B.js → chunk-DG4IQ6JG.js} +3 -3
  82. package/chunks/{chunk-QUI267ZP.js → chunk-DPTMKFIH.js} +492 -63
  83. package/chunks/{chunk-Q3JQ7OSU.js → chunk-EJOGLSNJ.js} +1 -1
  84. package/chunks/{chunk-NRLFZWCT.js → chunk-EQHCHTHC.js} +48 -5
  85. package/chunks/{chunk-P3BJLFSZ.js → chunk-EQR7YDXY.js} +3 -3
  86. package/chunks/{chunk-4WL6SY4F.js → chunk-EQUXHAFW.js} +1 -1
  87. package/chunks/{chunk-Q3AL4JQ3.js → chunk-F5BD3RNA.js} +2 -2
  88. package/chunks/{chunk-A7XMDZRI.js → chunk-FJYUSD2N.js} +5 -5
  89. package/chunks/{chunk-JT7XS4YW.js → chunk-FMIH5KMQ.js} +1 -1
  90. package/chunks/{chunk-ZBVS26BY.js → chunk-FPGTNKCP.js} +7 -5
  91. package/chunks/{chunk-W5UC37EE.js → chunk-FQDCO3CJ.js} +12 -1
  92. package/chunks/{chunk-EQL65XGA.js → chunk-FRHQQC2Z.js} +47 -21
  93. package/chunks/{chunk-FVKHVJZQ.js → chunk-G6MUFRNI.js} +1 -1
  94. package/chunks/{chunk-D27I6YJT.js → chunk-GB245X4Z.js} +129 -26
  95. package/chunks/{chunk-WCG5O7IP.js → chunk-GZDWTBT3.js} +2 -2
  96. package/chunks/{chunk-AOHJKPKL.js → chunk-H7TMVHKE.js} +1 -1
  97. package/chunks/{chunk-ZJ4W6SUY.js → chunk-HDRTQ5DH.js} +3 -3
  98. package/chunks/{chunk-ZZCWJWTF.js → chunk-HG3UBTJ4.js} +31 -11
  99. package/chunks/chunk-HHJLM3WQ.js +41 -0
  100. package/chunks/{chunk-6LP743KE.js → chunk-HHZU6ZZM.js} +79 -113
  101. package/chunks/{chunk-OIVKILPI.js → chunk-HOSVOUDK.js} +74 -0
  102. package/chunks/{chunk-DA4HRSBW.js → chunk-HTYND72J.js} +1 -1
  103. package/chunks/{chunk-ZRBMO3C7.js → chunk-IKFHTAQW.js} +1 -1
  104. package/chunks/{chunk-KZ22NXBY.js → chunk-IVROQYG5.js} +4 -4
  105. package/chunks/{chunk-UDXSXLER.js → chunk-IW6RQPQB.js} +14 -4
  106. package/chunks/{chunk-F24A2JBM.js → chunk-J6JVP7ZZ.js} +1180 -254
  107. package/chunks/{chunk-ECWR5LQR.js → chunk-JB6IM2TJ.js} +3 -3
  108. package/chunks/{chunk-MVUQRLOH.js → chunk-JRIVMPD2.js} +3 -3
  109. package/chunks/{chunk-Q7YDKOGY.js → chunk-JVEGA3MM.js} +1 -1
  110. package/chunks/{chunk-4TRQPFDP.js → chunk-K34GJQOZ.js} +140 -20
  111. package/chunks/{chunk-W4RQUHY3.js → chunk-K5IDV3PC.js} +184 -22
  112. package/chunks/{chunk-NDU63YLI.js → chunk-KD6FGI2Q.js} +4 -4
  113. package/chunks/{chunk-HV76SFIA.js → chunk-KEC5FHLM.js} +3 -3
  114. package/chunks/{chunk-IIJEYBNH.js → chunk-KLOMACIR.js} +197 -60
  115. package/chunks/{chunk-Z4JX4NSH.js → chunk-KSPRBJJ3.js} +50 -50
  116. package/chunks/{chunk-KONVMRK7.js → chunk-KX5TNFCJ.js} +1 -1
  117. package/chunks/{chunk-QGNOFE5E.js → chunk-KX7PC5QG.js} +1 -1
  118. package/chunks/{chunk-OJUQF2PL.js → chunk-LEKKQEQW.js} +5 -5
  119. package/chunks/{chunk-COBO5EBO.js → chunk-LSRI3ND3.js} +1 -1
  120. package/chunks/{chunk-BSI645OU.js → chunk-LUISTZXI.js} +3 -3
  121. package/chunks/{chunk-YTFDX4PR.js → chunk-M6NDLY2T.js} +1 -1
  122. package/chunks/{chunk-EBZ6BJTF.js → chunk-MNUKNVYQ.js} +1 -1
  123. package/chunks/{chunk-VFMASYQA.js → chunk-MS7GNABG.js} +3 -0
  124. package/chunks/{chunk-EI3NWELG.js → chunk-MSSNVG2G.js} +6430 -4463
  125. package/chunks/{chunk-L2AFWWJE.js → chunk-N4SVADAV.js} +351 -144
  126. package/chunks/{chunk-URK542T4.js → chunk-NF5J2WFA.js} +15 -2
  127. package/chunks/{chunk-EI3HZX6C.js → chunk-NLFLYSS4.js} +1 -1
  128. package/chunks/{chunk-NV3F44FL.js → chunk-NW2GIPG3.js} +2 -2
  129. package/chunks/{chunk-OQTXYMKW.js → chunk-NX4A23LY.js} +3 -3
  130. package/chunks/{chunk-E2FPSSKP.js → chunk-OK47XBYH.js} +97 -10
  131. package/chunks/{chunk-EKPKKXY2.js → chunk-OWGRUU7F.js} +1 -1
  132. package/chunks/{chunk-CTJLZLB5.js → chunk-OYWVIXHT.js} +1 -1
  133. package/chunks/{chunk-47PEPJO7.js → chunk-P7PSGVWP.js} +3 -3
  134. package/chunks/{chunk-6Q5ABMTU.js → chunk-PTSEETCO.js} +23 -19
  135. package/chunks/{chunk-6ZRFAKXK.js → chunk-PVXEJB66.js} +1 -1
  136. package/chunks/{chunk-EUNWC2VS.js → chunk-PZW46OTB.js} +2 -2
  137. package/chunks/{chunk-QSWDGAIC.js → chunk-QILD6R27.js} +1 -1
  138. package/chunks/{chunk-CKASRHZI.js → chunk-QLTATTPS.js} +1 -1
  139. package/chunks/{chunk-2UUMVNYT.js → chunk-QPBFRWCP.js} +3 -3
  140. package/chunks/{chunk-QJMOAMXT.js → chunk-QQSXM3FE.js} +8 -8
  141. package/chunks/{chunk-AEL7KN2O.js → chunk-RN7GFREP.js} +2 -2
  142. package/chunks/{chunk-AQAJJMRR.js → chunk-RYSBWLLV.js} +1 -1
  143. package/chunks/{chunk-MFDYOYZZ.js → chunk-SYHXR6WM.js} +26 -3
  144. package/chunks/{chunk-SR7RZ4MS.js → chunk-TB4YFWXG.js} +2 -2
  145. package/chunks/{chunk-IRZ2ZH72.js → chunk-TCMU4ZUE.js} +4 -4
  146. package/chunks/{chunk-OWMAZHIX.js → chunk-TMFWI4RC.js} +1 -1
  147. package/chunks/{chunk-TZEZYNYD.js → chunk-TQDFSQQF.js} +1 -1
  148. package/chunks/{chunk-IA7TGCN2.js → chunk-TTRH3RTQ.js} +4 -4
  149. package/chunks/{chunk-PJRW65JO.js → chunk-TXP5NGG3.js} +1 -1
  150. package/chunks/{chunk-VWKER4ZH.js → chunk-ULJGMSG5.js} +3 -3
  151. package/chunks/{chunk-2FRY5CRX.js → chunk-ULNWG62W.js} +3 -3
  152. package/chunks/{chunk-XVHYA33G.js → chunk-URYJYT5W.js} +4 -4
  153. package/chunks/{chunk-7GTMV7UE.js → chunk-US7J7LJT.js} +10786 -4462
  154. package/chunks/{chunk-HGCQ5SE7.js → chunk-UXEO7E3V.js} +21 -0
  155. package/chunks/{chunk-NV65ZUVM.js → chunk-VKT2R3NB.js} +1 -1
  156. package/chunks/{chunk-CPG6P4GG.js → chunk-VPV7WBVT.js} +1 -1
  157. package/chunks/{chunk-QG3FFJYU.js → chunk-VXSD4AGT.js} +1 -1
  158. package/chunks/{chunk-XCGIMOLN.js → chunk-WCCLLK7X.js} +14 -1
  159. package/chunks/{chunk-VJNBRRZG.js → chunk-WZMH7II3.js} +1 -1
  160. package/chunks/{chunk-5MZCSWI4.js → chunk-WZRLXVLJ.js} +1185 -1451
  161. package/chunks/{chunk-YF5MALI4.js → chunk-X5QJFMLY.js} +21 -17
  162. package/chunks/{chunk-DREZZAZM.js → chunk-XDRXOSAD.js} +13 -5
  163. package/chunks/{chunk-FOGU3LJX.js → chunk-YBHUXEC6.js} +1 -1
  164. package/chunks/{chunk-GM463R2B.js → chunk-YBVVOSOH.js} +1 -1
  165. package/chunks/{chunk-PYQADEFD.js → chunk-YIGGWOJE.js} +1 -1
  166. package/chunks/{chunk-XCWO3SMQ.js → chunk-YILJKX2T.js} +3 -3
  167. package/chunks/{chunk-Y4R47ZUH.js → chunk-YM3I6VW5.js} +7 -7
  168. package/chunks/{chunk-OCSFNUU4.js → chunk-YMALTWIZ.js} +13 -11
  169. package/chunks/{chunk-WOJZWRAZ.js → chunk-YRLW2MSX.js} +1 -1
  170. package/chunks/{chunk-UEOKWYGY.js → chunk-YYIOFWVH.js} +11 -11
  171. package/chunks/chunk-Z7B6SRPM.js +32 -0
  172. package/chunks/{chunk-S6HYI3MF.js → chunk-ZBB5EZZV.js} +2 -2
  173. package/chunks/{chunk-VKJ4KTPJ.js → chunk-ZLCT4C5A.js} +1 -1
  174. package/chunks/{chunk-O3EU6GMH.js → chunk-ZO37CAQH.js} +27 -4
  175. package/chunks/{computer-use-WQFK33Z3.js → computer-use-TMDO6TEC.js} +42 -41
  176. package/chunks/{config-utils-ULCSRMWD.js → config-utils-Z3OW3IQG.js} +6 -6
  177. package/chunks/{contextCommand-7EOZND7C.js → contextCommand-IUQ6G5ES.js} +44 -43
  178. package/chunks/{core-runtime-FGMQRM6E.js → core-runtime-HAZLPQXI.js} +42 -41
  179. package/chunks/{create-sub-session-QM2K5HLZ.js → create-sub-session-GREIOIZU.js} +42 -41
  180. package/chunks/{create-sub-session-QIDZUOPU.js → create-sub-session-XT6DLYOE.js} +2 -2
  181. package/chunks/{cron-create-VONA5JYY.js → cron-create-2JZ2TWTF.js} +4 -4
  182. package/chunks/{cron-delete-5JXSP2MI.js → cron-delete-CTPD2P26.js} +4 -4
  183. package/chunks/{cron-list-KE4F2CIR.js → cron-list-V44KHAF6.js} +4 -4
  184. package/chunks/{daemon-GWD7BT6E.js → daemon-GED37WOX.js} +216 -9
  185. package/chunks/daemon-git-worktree-guard-BSKVBYPM.js +2062 -0
  186. package/chunks/daemon-status-provider-7UK2DVVN.js +102 -0
  187. package/chunks/daemon-trust-policy-BZEALQSM.js +99 -0
  188. package/chunks/{daemon-trust-policy-monitor-6UKEABN5.js → daemon-trust-policy-monitor-P7OM342T.js} +49 -48
  189. package/chunks/{de-LIW4XVLN.js → de-UBEBKG6V.js} +2 -1
  190. package/chunks/{deferred-core-runtime-67GJXHXS.js → deferred-core-runtime-MTDXZT6B.js} +42 -41
  191. package/chunks/{display-image-NQRSIBXM.js → display-image-M2ELAVN4.js} +4 -4
  192. package/chunks/{dist-OTUO3AS2.js → dist-4ZPG4BY6.js} +13 -5
  193. package/chunks/{dist-B2CGTW6T.js → dist-BROOP2EG.js} +3 -3
  194. package/chunks/{dist-EZE3V3Q7.js → dist-IYYN3RUT.js} +3 -3
  195. package/chunks/{dist-3NTTUAHT.js → dist-JWMKPWT5.js} +5 -3
  196. package/chunks/{dist-Z3CS4OVP.js → dist-K7IQB53U.js} +11 -5
  197. package/chunks/{dist-J47AXBZC.js → dist-MAQXAQ2Y.js} +3 -3
  198. package/chunks/{dist-6BMOAE3Z.js → dist-WJ4BHIEW.js} +4 -4
  199. package/chunks/{dist-EWW3J4HQ.js → dist-YEPL4RAW.js} +3 -3
  200. package/chunks/{earlyInputCapture-IWMYR6OB.js → earlyInputCapture-BGZYFN2F.js} +43 -42
  201. package/chunks/{edit-ZFGROCAF.js → edit-ASQVJARF.js} +45 -43
  202. package/chunks/{en-SY5GTIGX.js → en-X6YV7GME.js} +2 -1
  203. package/chunks/{enter-worktree-TZZZCDM5.js → enter-worktree-WIUNMC64.js} +42 -41
  204. package/chunks/{enterPlanMode-U77BI3R6.js → enterPlanMode-TUBB2L7O.js} +42 -41
  205. package/chunks/{environment-HC37DS2I.js → environment-RWSNEY4T.js} +45 -44
  206. package/chunks/{errors-6AG54JPD.js → errors-44QVVNGT.js} +44 -43
  207. package/chunks/{exit-worktree-UYYWFPNK.js → exit-worktree-WPBRPIRR.js} +42 -41
  208. package/chunks/exitPlanMode-AP7J626M.js +85 -0
  209. package/chunks/{external-tool-guard-provider-5HTGOPGU.js → external-tool-guard-provider-TE4DRY36.js} +1 -1
  210. package/chunks/{fast-path-F5FSZ3O7.js → fast-path-XG5KXXLS.js} +6 -6
  211. package/chunks/{fast-path-settings-RPAVBD7P.js → fast-path-settings-LNOFM2YP.js} +2 -2
  212. package/chunks/{fr-RQFO7U4P.js → fr-VENTC2BS.js} +2 -1
  213. package/chunks/{gemini-NKQHYM36.js → gemini-PGXORAFF.js} +112 -103
  214. package/chunks/{geminiContentGenerator-HCWZOUX3.js → geminiContentGenerator-ZQVVD4J4.js} +6 -6
  215. package/chunks/{glob-3PDXKBAO.js → glob-Q6LWKMBU.js} +42 -41
  216. package/chunks/{goal-tools-SWNB6GP4.js → goal-tools-M4UDAZXP.js} +4 -4
  217. package/chunks/{grep-5HZKZYVD.js → grep-C67Z35I4.js} +42 -41
  218. package/chunks/handleAutoUpdate-75L74MB4.js +94 -0
  219. package/chunks/{i18n-Q27KKNDL.js → i18n-GYUC23UJ.js} +43 -42
  220. package/chunks/{image-gen-2Z2RJ6W7.js → image-gen-XE56S4MG.js} +10 -10
  221. package/chunks/initializer-V7XZVY35.js +100 -0
  222. package/chunks/{installationInfo-XXB75T7O.js → installationInfo-S5PPSD7T.js} +43 -42
  223. package/chunks/{ja-KOZKHJHZ.js → ja-QHT4EQTO.js} +2 -1
  224. package/chunks/{keychain-token-storage-TVAMTNP7.js → keychain-token-storage-NKKCUHI2.js} +2 -2
  225. package/chunks/list-JJ2FB7SP.js +103 -0
  226. package/chunks/{list-agents-Z4WABFDZ.js → list-agents-O6WSY4CT.js} +2 -2
  227. package/chunks/loadedSettingsAdapter-LNUDRGW5.js +97 -0
  228. package/chunks/{loggingContentGenerator-6NTFBM7Q.js → loggingContentGenerator-HCJ2DX2S.js} +162 -112
  229. package/chunks/{loop-wakeup-UZ5RL5Y2.js → loop-wakeup-GVQRMUKS.js} +5 -5
  230. package/chunks/{ls-TVHDGIES.js → ls-6W2D7TKU.js} +4 -4
  231. package/chunks/{lsp-CVN6OQPI.js → lsp-NJ4KFBI2.js} +2 -2
  232. package/chunks/{managed-npm-update-SPHYQUWZ.js → managed-npm-update-MDF2JDTH.js} +45 -44
  233. package/chunks/mcp-M5OML5FI.js +97 -0
  234. package/chunks/{monitor-ZBBPAA54.js → monitor-U5NM5ONC.js} +42 -41
  235. package/chunks/nonInteractiveCli-TX3QP7JT.js +163 -0
  236. package/chunks/{notebook-edit-5W3FW7Z2.js → notebook-edit-Q7SUR44R.js} +42 -41
  237. package/chunks/{openaiContentGenerator-TQANPEVZ.js → openaiContentGenerator-2H5CYLXP.js} +29 -29
  238. package/chunks/{pidfile-EQOBLH4E.js → pidfile-SHSMSAZR.js} +43 -42
  239. package/chunks/{processUtils-7XQG7EHS.js → processUtils-GZAP6EYW.js} +2 -2
  240. package/chunks/{pt-U6AOCTMF.js → pt-VL3I5RNY.js} +2 -1
  241. package/chunks/{qwenContentGenerator-BKCPHHXU.js → qwenContentGenerator-2624VVZH.js} +48 -48
  242. package/chunks/{qwenOAuth2-BJ6PQKE6.js → qwenOAuth2-AAWH3C7N.js} +9 -9
  243. package/chunks/read-file-ZWGQE2TE.js +32 -0
  244. package/chunks/{read-mcp-resource-PZ4ZF6YL.js → read-mcp-resource-GWCP23WG.js} +2 -2
  245. package/chunks/{read-package-up-TCM6I7S2.js → read-package-up-K6RKTL5D.js} +1 -1
  246. package/chunks/{record-artifact-P4HFMS7X.js → record-artifact-IYQDEYMV.js} +3 -3
  247. package/chunks/{resumeHistoryUtils-6N6XGJJW.js → resumeHistoryUtils-7N2H4QCU.js} +50 -49
  248. package/chunks/ripGrep-6JGJDWYB.js +85 -0
  249. package/chunks/{ru-CMX4UMYP.js → ru-4RCKL4PY.js} +2 -1
  250. package/chunks/{run-qwen-serve-BCKBCAMX.js → run-qwen-serve-2A6RHHI7.js} +197 -90
  251. package/chunks/{runtime-E2437YKL.js → runtime-NPYVZVRI.js} +55 -54
  252. package/chunks/{scheduler-K3D5Z655.js → scheduler-UMKTEQAM.js} +44 -43
  253. package/chunks/{sdk-exporters-http-XVTZQRCE.js → sdk-exporters-http-NHBYB5FZ.js} +11 -7
  254. package/chunks/{sdk-impl-7W7AKCS4.js → sdk-impl-SK4P5WON.js} +13 -10
  255. package/chunks/{send-message-CAMSLG2L.js → send-message-O7FO63UK.js} +6 -6
  256. package/chunks/serve-LYADPWRV.js +107 -0
  257. package/chunks/{server-UD6INW7J.js → server-WMVPH4G4.js} +1137 -382
  258. package/chunks/{session-GR4ZEVW4.js → session-LE6O62ZE.js} +122 -102
  259. package/chunks/{settings-5O24D3OJ.js → settings-2IPZYYGS.js} +48 -47
  260. package/chunks/{shell-UTLWLG5G.js → shell-VOBAZFFI.js} +42 -41
  261. package/chunks/{skill-QQAZL4VO.js → skill-6LKOWJV4.js} +19 -19
  262. package/chunks/{skill-settings-P3YHJVBZ.js → skill-settings-J5IHQA7L.js} +48 -47
  263. package/chunks/spawnChannel-TLW7N3SM.js +98 -0
  264. package/chunks/{standalone-update-QP742MGP.js → standalone-update-6OFPUBEM.js} +44 -43
  265. package/chunks/{startInteractiveUI-YCS6AEPN.js → startInteractiveUI-KVHNCR2L.js} +836 -444
  266. package/chunks/{syntheticOutput-PEBJQYJV.js → syntheticOutput-DVHJMUGV.js} +3 -3
  267. package/chunks/{task-create-5NWCQSJF.js → task-create-4NC7PDI4.js} +10 -10
  268. package/chunks/{task-list-53265TRZ.js → task-list-LBSRMOC7.js} +5 -5
  269. package/chunks/{task-stop-FPCOIRYX.js → task-stop-YFNATTIM.js} +2 -2
  270. package/chunks/{task-update-5HN577LS.js → task-update-BPLM52GD.js} +10 -10
  271. package/chunks/{team-create-WFH7OCDQ.js → team-create-INCC7G74.js} +44 -43
  272. package/chunks/{team-delete-MMQB4OSC.js → team-delete-MKYMYBFM.js} +5 -5
  273. package/chunks/{team-plan-approval-EGTT53MV.js → team-plan-approval-6DCWGZQ4.js} +42 -41
  274. package/chunks/{terminal-image-renderer-BWRESAQ7.js → terminal-image-renderer-O5EDW64G.js} +44 -43
  275. package/chunks/theme-manager-NZZO4SWE.js +89 -0
  276. package/chunks/{todoWrite-JGV6VLOX.js → todoWrite-K5K7NRE5.js} +4 -4
  277. package/chunks/{tool-search-TI5PTIBF.js → tool-search-JB2PXD5P.js} +19 -19
  278. package/chunks/total-session-admission-NWNMU6AW.js +99 -0
  279. package/chunks/{trustedFolders-4KYHA4IG.js → trustedFolders-A5ZWRRSP.js} +43 -42
  280. package/chunks/{update-relaunch-WB6LGIF2.js → update-relaunch-GG7EDBEA.js} +5 -5
  281. package/chunks/{updateCheck-LOS5GYFC.js → updateCheck-P6JJ4MBU.js} +48 -47
  282. package/chunks/{useAutoAcceptIndicator-MHAPY52L.js → useAutoAcceptIndicator-KV2AANVG.js} +53 -52
  283. package/chunks/{validateNonInterActiveAuth-QV22HNQU.js → validateNonInterActiveAuth-HXRCYXY7.js} +89 -88
  284. package/chunks/{version-DALWZHKQ.js → version-HH5V762G.js} +2 -2
  285. package/chunks/{web-fetch-JMJVMYFE.js → web-fetch-LVXPFB5O.js} +19 -19
  286. package/chunks/{web-search-DNDUIPU5.js → web-search-4E234FSM.js} +11 -11
  287. package/chunks/{workflow-JGNN64PM.js → workflow-GUE6WIMP.js} +117 -50
  288. package/chunks/workspace-providers-status-TUWLGJOF.js +100 -0
  289. package/chunks/{workspace-registration-store-LRJG7QA4.js → workspace-registration-store-22XXHPKR.js} +1 -1
  290. package/chunks/{workspace-registry-KVXIFM36.js → workspace-registry-HUFJF5W5.js} +50 -49
  291. package/chunks/{workspace-service-PO4AAKKT.js → workspace-service-NAGTBJXJ.js} +54 -53
  292. package/chunks/workspace-skills-status-LWDBXAQI.js +100 -0
  293. package/chunks/{workspace-trust-reconciler-DOZPCVHG.js → workspace-trust-reconciler-DLWV2ZO6.js} +57 -56
  294. package/chunks/write-file-QVHVOKKR.js +87 -0
  295. package/chunks/{zh-AGL2FVBI.js → zh-LMSTK4WD.js} +2 -1
  296. package/chunks/{zh-TW-KI66MHQY.js → zh-TW-SQ4HTSCW.js} +2 -1
  297. package/chunks/{zoom-image-CNC77ZMA.js → zoom-image-CJDXYWJH.js} +15 -15
  298. package/cli.js +18 -17
  299. package/locales/ca.js +1 -0
  300. package/locales/de.js +1 -0
  301. package/locales/en.js +1 -0
  302. package/locales/fr.js +1 -0
  303. package/locales/ja.js +1 -0
  304. package/locales/pt.js +1 -0
  305. package/locales/ru.js +1 -0
  306. package/locales/zh-TW.js +1 -0
  307. package/locales/zh.js +1 -0
  308. package/package.json +4 -4
  309. package/web-shell/assets/{arc-CDk0d60K.js → arc-DagtOPoO.js} +1 -1
  310. package/web-shell/assets/{architectureDiagram-3BPJPVTR-h-W3I2lP.js → architectureDiagram-3BPJPVTR-Dc3kGCBm.js} +1 -1
  311. package/web-shell/assets/{blockDiagram-GPEHLZMM-D1pvSmZg.js → blockDiagram-GPEHLZMM-BUZvQLL_.js} +1 -1
  312. package/web-shell/assets/{c4Diagram-AAUBKEIU-ByAm5ZNf.js → c4Diagram-AAUBKEIU-BbBgCu9K.js} +1 -1
  313. package/web-shell/assets/channel-aMHKHCQ2.js +1 -0
  314. package/web-shell/assets/{chunk-2J33WTMH-VrGPPOGV.js → chunk-2J33WTMH-CZ4miMNB.js} +1 -1
  315. package/web-shell/assets/{chunk-4BX2VUAB-B7hTowgG.js → chunk-4BX2VUAB-B2_qQSGx.js} +1 -1
  316. package/web-shell/assets/{chunk-55IACEB6-j1Fq8DpE.js → chunk-55IACEB6-EdmTwZW7.js} +1 -1
  317. package/web-shell/assets/{chunk-727SXJPM-UjABYpF2.js → chunk-727SXJPM-l2EpyrLV.js} +1 -1
  318. package/web-shell/assets/{chunk-AQP2D5EJ-D4uBItrs.js → chunk-AQP2D5EJ-0q9sx5lV.js} +1 -1
  319. package/web-shell/assets/{chunk-FMBD7UC4-DeFbKlb8.js → chunk-FMBD7UC4-CbGnA4Dp.js} +1 -1
  320. package/web-shell/assets/{chunk-ND2GUHAM-rQJ8TIgT.js → chunk-ND2GUHAM-D8JBELgZ.js} +1 -1
  321. package/web-shell/assets/{chunk-QZHKN3VN-DAGcRxvq.js → chunk-QZHKN3VN-DQMpGGOO.js} +1 -1
  322. package/web-shell/assets/classDiagram-4FO5ZUOK-zASpLzDx.js +1 -0
  323. package/web-shell/assets/classDiagram-v2-Q7XG4LA2-zASpLzDx.js +1 -0
  324. package/web-shell/assets/{cose-bilkent-S5V4N54A-MaE7MJSt.js → cose-bilkent-S5V4N54A-DzM-ZRsM.js} +1 -1
  325. package/web-shell/assets/{dagre-BM42HDAG-DzijYGSb.js → dagre-BM42HDAG-uxLS-TtN.js} +1 -1
  326. package/web-shell/assets/{diagram-2AECGRRQ-WdbG7WnX.js → diagram-2AECGRRQ-DH7Gnqzr.js} +1 -1
  327. package/web-shell/assets/{diagram-5GNKFQAL-NYutsBnw.js → diagram-5GNKFQAL-B2TngKRK.js} +1 -1
  328. package/web-shell/assets/{diagram-KO2AKTUF-Dqg0eBY0.js → diagram-KO2AKTUF-DQ61-HiV.js} +1 -1
  329. package/web-shell/assets/{diagram-LMA3HP47-C7vRP2Lb.js → diagram-LMA3HP47-By6qvgAT.js} +1 -1
  330. package/web-shell/assets/{diagram-OG6HWLK6-B2sEPpPt.js → diagram-OG6HWLK6-ClVSEz-3.js} +1 -1
  331. package/web-shell/assets/{erDiagram-TEJ5UH35-a4zIbzm8.js → erDiagram-TEJ5UH35-C9gFc5Fg.js} +1 -1
  332. package/web-shell/assets/{flowDiagram-I6XJVG4X-BK9y89ya.js → flowDiagram-I6XJVG4X-BWPLLJ5-.js} +1 -1
  333. package/web-shell/assets/{ganttDiagram-6RSMTGT7-wUQTSNvV.js → ganttDiagram-6RSMTGT7-C6RMacQQ.js} +1 -1
  334. package/web-shell/assets/{gitGraphDiagram-PVQCEYII-Dnzt4SAi.js → gitGraphDiagram-PVQCEYII-LnqiWuka.js} +1 -1
  335. package/web-shell/assets/index---fOcMdS.js +1789 -0
  336. package/web-shell/assets/{index-BA3wUcKL.js → index-B9iqcrv0.js} +1 -1
  337. package/web-shell/assets/index-BIGQygTL.css +5 -0
  338. package/web-shell/assets/{infoDiagram-5YYISTIA-DcaoToij.js → infoDiagram-5YYISTIA-Bc4iS8YB.js} +1 -1
  339. package/web-shell/assets/{ishikawaDiagram-YF4QCWOH-DzduqhP2.js → ishikawaDiagram-YF4QCWOH-9pH4Dpnd.js} +1 -1
  340. package/web-shell/assets/{journeyDiagram-JHISSGLW-BvviZR_O.js → journeyDiagram-JHISSGLW-C-YMnw2W.js} +1 -1
  341. package/web-shell/assets/{kanban-definition-UN3LZRKU-Efm2JxY3.js → kanban-definition-UN3LZRKU-D-PaAIp-.js} +1 -1
  342. package/web-shell/assets/{linear-DtY3IbOs.js → linear-DpLgI2kt.js} +1 -1
  343. package/web-shell/assets/{mermaid.core-PzpFqoMe.js → mermaid.core-nZbOHGxx.js} +5 -5
  344. package/web-shell/assets/{mindmap-definition-RKZ34NQL-BLlTkHS0.js → mindmap-definition-RKZ34NQL-Dq0xxnET.js} +1 -1
  345. package/web-shell/assets/{pieDiagram-4H26LBE5-D-mKF-jE.js → pieDiagram-4H26LBE5-ctqG2eeF.js} +1 -1
  346. package/web-shell/assets/{quadrantDiagram-W4KKPZXB-DYCzslGm.js → quadrantDiagram-W4KKPZXB-MivToddn.js} +1 -1
  347. package/web-shell/assets/{requirementDiagram-4Y6WPE33-Dfpxlk7R.js → requirementDiagram-4Y6WPE33-DrLLnkpQ.js} +1 -1
  348. package/web-shell/assets/{sankeyDiagram-5OEKKPKP-D5cRaaxh.js → sankeyDiagram-5OEKKPKP-sYdYhdpV.js} +1 -1
  349. package/web-shell/assets/{sequenceDiagram-3UESZ5HK-s04DReiS.js → sequenceDiagram-3UESZ5HK-CuvhxDOs.js} +1 -1
  350. package/web-shell/assets/{stateDiagram-AJRCARHV-01UNFgnb.js → stateDiagram-AJRCARHV-BLZgbV7Q.js} +1 -1
  351. package/web-shell/assets/stateDiagram-v2-BHNVJYJU-DR_gXrIC.js +1 -0
  352. package/web-shell/assets/{timeline-definition-PNZ67QCA-DX8_wZBC.js → timeline-definition-PNZ67QCA-lNr2Uz_Q.js} +1 -1
  353. package/web-shell/assets/{vennDiagram-CIIHVFJN-BK0FlBme.js → vennDiagram-CIIHVFJN-CoaexGVO.js} +1 -1
  354. package/web-shell/assets/{wardley-L42UT6IY-DkPc9UlD.js → wardley-L42UT6IY-DG1vhGKA.js} +1 -1
  355. package/web-shell/assets/{wardleyDiagram-YWT4CUSO-DNKkpDAo.js → wardleyDiagram-YWT4CUSO-CqNjF5xC.js} +1 -1
  356. package/web-shell/assets/{xychartDiagram-2RQKCTM6-CiPwg8QG.js → xychartDiagram-2RQKCTM6-BXg1gx3C.js} +1 -1
  357. package/web-shell/index.html +2 -2
  358. package/chunks/agent-headless-HYEHZFH6.js +0 -86
  359. package/chunks/bridge-FHINXZMN.js +0 -103
  360. package/chunks/channel-settings-store-OXYG5S5X.js +0 -101
  361. package/chunks/chunk-I5VM3SKY.js +0 -451
  362. package/chunks/chunk-PDPFQ2FO.js +0 -156
  363. package/chunks/daemon-status-provider-L3J6GKCT.js +0 -102
  364. package/chunks/daemon-trust-policy-4PHPY23S.js +0 -98
  365. package/chunks/exitPlanMode-RWJR2KGB.js +0 -84
  366. package/chunks/handleAutoUpdate-NHFSGYTF.js +0 -93
  367. package/chunks/initializer-Y5DJLT43.js +0 -99
  368. package/chunks/list-YHNQ32CS.js +0 -102
  369. package/chunks/loadedSettingsAdapter-GHUQK7H4.js +0 -96
  370. package/chunks/mcp-EA3KO6FS.js +0 -96
  371. package/chunks/nonInteractiveCli-NNOR56HU.js +0 -162
  372. package/chunks/read-file-KKTXGIZD.js +0 -32
  373. package/chunks/ripGrep-SJVAAYDV.js +0 -84
  374. package/chunks/serve-IH4XR5IL.js +0 -106
  375. package/chunks/spawnChannel-UAQMH6Y6.js +0 -94
  376. package/chunks/theme-manager-ZNDGAHJN.js +0 -88
  377. package/chunks/total-session-admission-66UDSOHO.js +0 -98
  378. package/chunks/workspace-providers-status-K22B3Z6B.js +0 -99
  379. package/chunks/workspace-skills-status-DDYCBVSH.js +0 -99
  380. package/chunks/write-file-TT6MWIKC.js +0 -86
  381. package/web-shell/assets/channel-DPFUV4oi.js +0 -1
  382. package/web-shell/assets/classDiagram-4FO5ZUOK-CLm0hVvw.js +0 -1
  383. package/web-shell/assets/classDiagram-v2-Q7XG4LA2-CLm0hVvw.js +0 -1
  384. package/web-shell/assets/index-BjC3yjjL.css +0 -5
  385. package/web-shell/assets/index-QzFq6w7o.js +0 -1775
  386. package/web-shell/assets/stateDiagram-v2-BHNVJYJU-DXb5olqv.js +0 -1
@@ -6,18 +6,20 @@ import {
6
6
  EventBus,
7
7
  logEventSizingFailed,
8
8
  serializedBridgeEventByteLength
9
- } from "./chunk-MZSJ43WV.js";
9
+ } from "./chunk-7U5G6JXI.js";
10
10
  import {
11
+ JOURNAL_GROWTH_HARD_CAP_BYTES,
11
12
  normalizeCompactedReplayMaxBytes,
13
+ normalizeJournalGrowthPoolBytes,
12
14
  normalizeMaxJournalBytes,
13
15
  normalizeMaxJournalEvents
14
- } from "./chunk-XCGIMOLN.js";
16
+ } from "./chunk-WCCLLK7X.js";
15
17
  import {
16
18
  MCP_RESTART_SERVER_DEADLINE_MS
17
19
  } from "./chunk-OCPBI7J5.js";
18
20
  import {
19
21
  defaultSpawnChannelFactory
20
- } from "./chunk-I5VM3SKY.js";
22
+ } from "./chunk-DAV4QFD5.js";
21
23
  import {
22
24
  BridgeChannelClosedError,
23
25
  BridgeTimeoutError,
@@ -27,7 +29,7 @@ import {
27
29
  SessionRestoreTimeoutError,
28
30
  createIdleWorkspaceExtensionsStatus,
29
31
  createIdleWorkspaceHooksStatus
30
- } from "./chunk-DA4HRSBW.js";
32
+ } from "./chunk-HTYND72J.js";
31
33
  import {
32
34
  ACTIVE_WORK_CLOSE_IF_UNHELD_PARAM,
33
35
  ACTIVE_WORK_CLOSE_TIMEOUT_MS,
@@ -39,12 +41,15 @@ import {
39
41
  ACTIVE_WORK_MAX_SNAPSHOT_SESSIONS,
40
42
  ACTIVE_WORK_NOTIFICATION_METHOD,
41
43
  ACTIVE_WORK_STALE_INTERVALS,
44
+ CHANNEL_PROMPT_META_KEY,
42
45
  CHANNEL_STARTUP_PROFILE_META_KEY,
43
46
  CHANNEL_STARTUP_PROFILE_VERSION,
44
47
  DAEMON_CHANNEL_DELIVERY_META_KEY,
45
48
  DAEMON_MODEL_PROMPT_META_KEY,
49
+ DAEMON_PROMPT_DISPLAY_TEXT_META_KEY,
46
50
  LOAD_REPLAY_BULK_MODE,
47
51
  LOAD_REPLAY_HIDE_INHERITED_META_KEY,
52
+ LOAD_REPLAY_MAX_UPDATES,
48
53
  LOAD_REPLAY_META_KEY,
49
54
  LOAD_REPLAY_MODE_META_KEY,
50
55
  LOAD_REPLAY_PAGE_SIZE_META_KEY,
@@ -58,7 +63,7 @@ import {
58
63
  WORKTREE_MCP_DEFER_META_KEY,
59
64
  clampActiveWorkIntervalMs,
60
65
  isValidTrustedModelPrompt
61
- } from "./chunk-W5UC37EE.js";
66
+ } from "./chunk-FQDCO3CJ.js";
62
67
  import {
63
68
  BranchWhilePromptActiveError,
64
69
  BridgeChannelQuarantinedError,
@@ -97,14 +102,15 @@ import {
97
102
  EXTERNAL_TOOL_GUARD_READY_META_KEY,
98
103
  EXTERNAL_TOOL_GUARD_REQUIRED_VALUE,
99
104
  isValidExternalToolGuardDenialReason
100
- } from "./chunk-BKHCW2BI.js";
105
+ } from "./chunk-3VUENPWF.js";
101
106
  import {
102
107
  ClientSideConnection,
103
108
  PROTOCOL_VERSION,
104
109
  RequestError
105
- } from "./chunk-UDXSXLER.js";
110
+ } from "./chunk-IW6RQPQB.js";
106
111
  import {
107
112
  SESSION_ARTIFACT_PERSISTENCE_VERSION,
113
+ SESSION_TRANSCRIPT_MAX_LIMIT,
108
114
  ShellExecutionService,
109
115
  TrustGateError,
110
116
  WORKSPACE_CONTENT_MTIME_MS_METADATA_KEY,
@@ -114,16 +120,16 @@ import {
114
120
  metadataBudgetBytes,
115
121
  normalizeSnapshotPayload,
116
122
  stableSessionArtifactId
117
- } from "./chunk-EI3NWELG.js";
123
+ } from "./chunk-MSSNVG2G.js";
118
124
  import {
119
125
  DAEMON_TRACEPARENT_META_KEY,
120
126
  DAEMON_TRACESTATE_META_KEY
121
- } from "./chunk-4TRQPFDP.js";
127
+ } from "./chunk-K34GJQOZ.js";
122
128
  import {
123
129
  INVOCATION_CONTEXT_META_KEY,
124
130
  PRIVATE_ACP_CAPABILITY_ENV,
125
131
  PRIVATE_PARENT_CAPABILITY_META_KEY
126
- } from "./chunk-YGT2AUJ7.js";
132
+ } from "./chunk-4KM2SYK5.js";
127
133
  import {
128
134
  init_esbuild_shims
129
135
  } from "./chunk-5O2XNYP6.js";
@@ -135,6 +141,7 @@ import {
135
141
  init_esbuild_shims();
136
142
  import { randomBytes, randomUUID as randomUUID2 } from "node:crypto";
137
143
  import * as path3 from "node:path";
144
+ import { inspect } from "node:util";
138
145
 
139
146
  // packages/acp-bridge/src/compactionEngine.ts
140
147
  init_esbuild_shims();
@@ -152,6 +159,17 @@ var LATEST_WINS_UPDATES = /* @__PURE__ */ new Set([
152
159
  ]);
153
160
  var REPLAY_SEGMENT_COMPACT_THRESHOLD = 64;
154
161
  var LIVE_JOURNAL_TEXT_CHUNKS_PER_EVENT = 256;
162
+ function createLiveJournalState() {
163
+ return {
164
+ entries: [],
165
+ entryBytes: [],
166
+ entryEvents: [],
167
+ totalBytes: 0,
168
+ totalEvents: 0,
169
+ truncatedEvents: 0
170
+ };
171
+ }
172
+ __name(createLiveJournalState, "createLiveJournalState");
155
173
  function replayRecordId(event) {
156
174
  if (event.type !== "session_update") return void 0;
157
175
  const data = event.data;
@@ -177,26 +195,35 @@ function lastRecordIdIn(events) {
177
195
  return void 0;
178
196
  }
179
197
  __name(lastRecordIdIn, "lastRecordIdIn");
198
+ function lastSummaryRecordIdIn(events) {
199
+ for (let i = events.length - 1; i >= 0; i--) {
200
+ if (!isSummaryLiveJournalEvent(events[i])) continue;
201
+ const id = replayRecordId(events[i]);
202
+ if (id !== void 0) return id;
203
+ }
204
+ return void 0;
205
+ }
206
+ __name(lastSummaryRecordIdIn, "lastSummaryRecordIdIn");
207
+ var JOURNAL_GROWTH_REASK_INTERVAL_MS = 1e4;
208
+ var JOURNAL_GROWTH_MAX_GRANTS_PER_BREACH = 64;
180
209
  var TurnBoundaryCompactionEngine = class {
181
210
  static {
182
211
  __name(this, "TurnBoundaryCompactionEngine");
183
212
  }
184
213
  maxReplayBytes;
214
+ // Mutable: adaptive growth (see `maybeGrowJournalLimits`) raises these
215
+ // in place when the advisor grants headroom.
185
216
  maxJournalEvents;
186
217
  maxJournalBytes;
218
+ onJournalGrowth;
219
+ now;
220
+ journalGrowthDeniedAt;
187
221
  onReplayWindowEviction;
188
222
  replaySegments = [];
189
223
  replaySegmentStart = 0;
190
224
  replayBytes = 0;
191
- liveJournal = [];
192
- /** Serialized source-event size of each `liveJournal` entry, index-parallel. */
193
- journalEntryBytes = [];
194
- /** Raw event count represented by each `liveJournal` entry. */
195
- journalEntryEvents = [];
196
- journalTotalBytes = 0;
197
- journalTotalEvents = 0;
198
- journalTruncatedEvents = 0;
199
- liveJournalTextSegment;
225
+ fullJournal = createLiveJournalState();
226
+ summaryJournal = createLiveJournalState();
200
227
  lastEventId = 0;
201
228
  closed = false;
202
229
  truncatedEvents = 0;
@@ -209,6 +236,7 @@ var TurnBoundaryCompactionEngine = class {
209
236
  // pagination. Undefined until at least one recordId has been observed;
210
237
  // omitted from the marker in that case.
211
238
  activeRecordId;
239
+ summaryRecordId;
212
240
  // Pagination anchor for the replay-path `history_truncated` marker,
213
241
  // frozen at the first replay-window eviction. Prefers the first
214
242
  // retained recordId (the eviction boundary, so `beforeRecordId`
@@ -229,19 +257,30 @@ var TurnBoundaryCompactionEngine = class {
229
257
  this.maxReplayBytes = normalizeCompactedReplayMaxBytes(opts.maxReplayBytes);
230
258
  this.maxJournalEvents = normalizeMaxJournalEvents(opts.maxJournalEvents);
231
259
  this.maxJournalBytes = normalizeMaxJournalBytes(opts.maxJournalBytes);
260
+ this.onJournalGrowth = opts.onJournalGrowth;
261
+ this.now = opts.now ?? (() => performance.now());
232
262
  this.onReplayWindowEviction = opts.onReplayWindowEviction;
233
263
  }
264
+ /** Current journal caps — may have grown past the configured baseline. */
265
+ journalLimits() {
266
+ return { maxEvents: this.maxJournalEvents, maxBytes: this.maxJournalBytes };
267
+ }
234
268
  ingest(event, byteLength) {
235
269
  if (this.closed) return;
236
270
  if (event.id !== void 0) {
237
271
  this.lastEventId = event.id;
238
272
  }
239
273
  if (TRANSIENT_TYPES.has(event.type)) return;
274
+ const summaryEvent = isSummaryLiveJournalEvent(event);
240
275
  const seenRecordId = replayRecordId(event);
241
276
  if (seenRecordId !== void 0) {
242
277
  this.activeRecordId = seenRecordId;
278
+ if (summaryEvent) this.summaryRecordId = seenRecordId;
279
+ }
280
+ this.appendLiveJournal(this.fullJournal, event, byteLength);
281
+ if (summaryEvent) {
282
+ this.appendLiveJournal(this.summaryJournal, event, byteLength);
243
283
  }
244
- this.appendLiveJournal(event, byteLength);
245
284
  if (TURN_BOUNDARY_TYPES.has(event.type)) {
246
285
  this.compactCurrentTurn(event);
247
286
  return;
@@ -252,49 +291,62 @@ var TurnBoundaryCompactionEngine = class {
252
291
  }
253
292
  this.slots.push({ kind: "misc", event });
254
293
  }
255
- snapshot() {
294
+ snapshot(liveReplayMode = "full") {
256
295
  const compactedTurns = this.flattenReplaySegments();
257
296
  if (this.truncatedEvents > 0) {
258
297
  compactedTurns.unshift(
259
298
  this.makeHistoryTruncatedEvent(compactedTurns.length)
260
299
  );
261
300
  }
262
- const liveJournal = this.liveJournal.map(
301
+ return {
302
+ compactedTurns,
303
+ liveJournal: this.liveJournalSnapshot(liveReplayMode),
304
+ lastEventId: this.lastEventId
305
+ };
306
+ }
307
+ /**
308
+ * Snapshot of only the in-flight live journal — the events ingested
309
+ * since the last turn boundary (a boundary folds its turn into the
310
+ * replay window and resets the journal). Cheaper than `snapshot()`:
311
+ * no replay-window flatten.
312
+ */
313
+ liveJournalSnapshot(liveReplayMode = "full") {
314
+ const journal = liveReplayMode === "summary" ? this.summaryJournal : this.fullJournal;
315
+ const journalRecordId = liveReplayMode === "summary" ? this.summaryRecordId : this.activeRecordId;
316
+ const liveJournal = journal.entries.map(
263
317
  (entry) => isLiveJournalTextSegment(entry) ? mergeLiveJournalTextEvent(
264
318
  entry.firstEvent,
265
319
  entry.lastEvent,
266
320
  entry.chunks
267
321
  ) : entry
268
322
  );
269
- if (this.journalTruncatedEvents > 0) {
323
+ if (journal.truncatedEvents > 0) {
270
324
  liveJournal.unshift({
271
325
  v: EVENT_SCHEMA_VERSION,
272
326
  type: "history_truncated",
273
327
  data: {
274
328
  reason: "replay_window_exceeded",
275
329
  scope: "live_journal",
276
- truncatedEvents: this.journalTruncatedEvents,
277
- retainedEvents: this.journalTotalEvents,
330
+ truncatedEvents: journal.truncatedEvents,
331
+ retainedEvents: journal.totalEvents,
278
332
  maxBytes: this.maxJournalBytes,
279
333
  maxEvents: this.maxJournalEvents,
280
334
  // Pagination anchor — see makeHistoryTruncatedEvent.
281
- ...this.activeRecordId !== void 0 ? { recordId: this.activeRecordId } : {},
335
+ ...journalRecordId !== void 0 ? { recordId: journalRecordId } : {},
282
336
  fullTranscriptAvailable: true
283
337
  }
284
338
  });
285
339
  }
286
- return {
287
- compactedTurns,
288
- liveJournal,
289
- lastEventId: this.lastEventId
290
- };
340
+ return liveJournal;
291
341
  }
292
342
  seed(snapshot) {
293
343
  if (this.closed) return;
294
344
  this.resetReplayWindow();
295
345
  this.lastEventId = snapshot.lastEventId;
296
346
  this.activeRecordId = void 0;
347
+ this.summaryRecordId = void 0;
297
348
  this.activeRecordId = lastRecordIdIn(snapshot.compactedTurns);
349
+ this.summaryRecordId = lastSummaryRecordIdIn(snapshot.compactedTurns);
298
350
  for (const event of snapshot.compactedTurns) {
299
351
  if (TRANSIENT_TYPES.has(event.type)) continue;
300
352
  this.addReplaySegment([event], 0);
@@ -308,7 +360,9 @@ var TurnBoundaryCompactionEngine = class {
308
360
  if (this.closed) return;
309
361
  this.resetReplayWindow();
310
362
  this.activeRecordId = void 0;
363
+ this.summaryRecordId = void 0;
311
364
  this.activeRecordId = lastRecordIdIn(events);
365
+ this.summaryRecordId = lastSummaryRecordIdIn(events);
312
366
  let recordEvents = [];
313
367
  let recordId;
314
368
  const flushRecord = /* @__PURE__ */ __name(() => {
@@ -343,22 +397,23 @@ var TurnBoundaryCompactionEngine = class {
343
397
  this.resetReplayWindow();
344
398
  this.resetJournal();
345
399
  this.activeRecordId = void 0;
400
+ this.summaryRecordId = void 0;
346
401
  this.slots = [];
347
402
  this.toolSlotIndex.clear();
348
403
  this.clearTextSlotIndex();
349
404
  }
350
- appendLiveJournal(event, byteLength) {
405
+ appendLiveJournal(journal, event, byteLength) {
351
406
  const bytes = byteLength ?? serializedBridgeEventByteLength(event) ?? 0;
352
407
  const textChunk = liveJournalTextChunk(event);
353
- const current = this.liveJournalTextSegment;
354
- const currentIndex = this.liveJournal.length - 1;
355
- if (textChunk && current && this.liveJournal[currentIndex] === current && current.chunks.length < LIVE_JOURNAL_TEXT_CHUNKS_PER_EVENT && this.journalEntryBytes[currentIndex] + bytes <= this.maxJournalBytes && current.sessionUpdate === textChunk.sessionUpdate && current.parentToolCallId === textChunk.parentToolCallId && stringArraysEqual(current.sourceRecordIds, textChunk.sourceRecordIds) && current.promptId === event.promptId && current.originatorClientId === event.originatorClientId && current.sessionId === captureSessionId(event) && hasOnlyTimestampEnvelopeMeta(current.lastEvent._meta) && hasOnlyTimestampEnvelopeMeta(event._meta)) {
408
+ const current = journal.textSegment;
409
+ const currentIndex = journal.entries.length - 1;
410
+ if (textChunk && current && journal.entries[currentIndex] === current && current.chunks.length < LIVE_JOURNAL_TEXT_CHUNKS_PER_EVENT && journal.entryBytes[currentIndex] + bytes <= this.maxJournalBytes && current.sessionUpdate === textChunk.sessionUpdate && current.parentToolCallId === textChunk.parentToolCallId && stringArraysEqual(current.sourceRecordIds, textChunk.sourceRecordIds) && current.promptId === event.promptId && current.originatorClientId === event.originatorClientId && current.sessionId === captureSessionId(event) && hasOnlyTimestampEnvelopeMeta(current.lastEvent._meta) && hasOnlyTimestampEnvelopeMeta(event._meta)) {
356
411
  current.chunks.push(textChunk.text);
357
412
  current.lastEvent = event;
358
- this.journalEntryBytes[currentIndex] += bytes;
359
- this.journalEntryEvents[currentIndex] += 1;
360
- this.journalTotalBytes += bytes;
361
- this.journalTotalEvents += 1;
413
+ journal.entryBytes[currentIndex] += bytes;
414
+ journal.entryEvents[currentIndex] += 1;
415
+ journal.totalBytes += bytes;
416
+ journal.totalEvents += 1;
362
417
  } else {
363
418
  let entry = event;
364
419
  if (textChunk) {
@@ -374,27 +429,97 @@ var TurnBoundaryCompactionEngine = class {
374
429
  lastEvent: event
375
430
  };
376
431
  entry = segment;
377
- this.liveJournalTextSegment = segment;
432
+ journal.textSegment = segment;
378
433
  } else {
379
- this.liveJournalTextSegment = void 0;
434
+ journal.textSegment = void 0;
380
435
  }
381
- this.liveJournal.push(entry);
382
- this.journalEntryBytes.push(bytes);
383
- this.journalEntryEvents.push(1);
384
- this.journalTotalBytes += bytes;
385
- this.journalTotalEvents += 1;
436
+ journal.entries.push(entry);
437
+ journal.entryBytes.push(bytes);
438
+ journal.entryEvents.push(1);
439
+ journal.totalBytes += bytes;
440
+ journal.totalEvents += 1;
386
441
  }
387
- while (this.liveJournal.length > this.maxJournalEvents || this.journalTotalBytes > this.maxJournalBytes && this.liveJournal.length > 1) {
388
- const dropped = this.liveJournal.shift();
389
- this.journalTotalBytes -= this.journalEntryBytes.shift() ?? 0;
390
- const droppedEvents = this.journalEntryEvents.shift() ?? 0;
391
- this.journalTotalEvents -= droppedEvents;
392
- this.journalTruncatedEvents += droppedEvents;
393
- if (dropped === this.liveJournalTextSegment) {
394
- this.liveJournalTextSegment = void 0;
442
+ if (!TURN_BOUNDARY_TYPES.has(event.type) && (journal.entries.length > this.maxJournalEvents || journal.totalBytes > this.maxJournalBytes && journal.entries.length > 1)) {
443
+ this.maybeGrowJournalLimits(journal);
444
+ }
445
+ while (journal.entries.length > this.maxJournalEvents || journal.totalBytes > this.maxJournalBytes && journal.entries.length > 1) {
446
+ const dropped = journal.entries.shift();
447
+ journal.totalBytes -= journal.entryBytes.shift() ?? 0;
448
+ const droppedEvents = journal.entryEvents.shift() ?? 0;
449
+ journal.totalEvents -= droppedEvents;
450
+ journal.truncatedEvents += droppedEvents;
451
+ if (dropped === journal.textSegment) {
452
+ journal.textSegment = void 0;
395
453
  }
396
454
  }
397
455
  }
456
+ /**
457
+ * Consults the growth advisor once the journal breaches its caps and
458
+ * applies a grant in place, so the eviction loop below only drops what
459
+ * still exceeds the (possibly raised) caps. An intermediate grant that
460
+ * does not yet retain an extra entry is still applied tentatively —
461
+ * each applied cap is what the next ask reports and is charged for —
462
+ * and the walk continues until a grant retains strictly more than the
463
+ * pre-breach caps, the advisor refuses, or the step budget runs out. A
464
+ * walk that never improves retention rolls back to the original caps
465
+ * and counts as a refusal, so the pool is never charged for growth that
466
+ * preserves no replay. Never throws: a misbehaving advisor degrades to
467
+ * plain eviction, matching the engine's best-effort contract.
468
+ */
469
+ maybeGrowJournalLimits(journal) {
470
+ const advisor = this.onJournalGrowth;
471
+ if (!advisor || this.closed) return;
472
+ const now = this.now();
473
+ if (this.journalGrowthDeniedAt !== void 0) {
474
+ const sinceDenialMs = now - this.journalGrowthDeniedAt;
475
+ if (sinceDenialMs >= 0 && sinceDenialMs < JOURNAL_GROWTH_REASK_INTERVAL_MS) {
476
+ return;
477
+ }
478
+ }
479
+ const originalEvents = this.maxJournalEvents;
480
+ const originalBytes = this.maxJournalBytes;
481
+ const originalRetained = this.retainedTailCount(
482
+ journal,
483
+ originalEvents,
484
+ originalBytes
485
+ );
486
+ for (let step = 0; step < JOURNAL_GROWTH_MAX_GRANTS_PER_BREACH; step++) {
487
+ let grant;
488
+ try {
489
+ grant = advisor({
490
+ maxEvents: this.maxJournalEvents,
491
+ maxBytes: this.maxJournalBytes
492
+ });
493
+ } catch {
494
+ grant = void 0;
495
+ }
496
+ if (!grant || !Number.isSafeInteger(grant.maxBytes) || !Number.isSafeInteger(grant.maxEvents) || grant.maxBytes <= this.maxJournalBytes || grant.maxEvents < this.maxJournalEvents) {
497
+ break;
498
+ }
499
+ this.maxJournalBytes = grant.maxBytes;
500
+ this.maxJournalEvents = grant.maxEvents;
501
+ if (this.retainedTailCount(journal, grant.maxEvents, grant.maxBytes) > originalRetained) {
502
+ this.journalGrowthDeniedAt = void 0;
503
+ return;
504
+ }
505
+ }
506
+ this.maxJournalEvents = originalEvents;
507
+ this.maxJournalBytes = originalBytes;
508
+ this.journalGrowthDeniedAt = now;
509
+ }
510
+ /** Entries of the newest-first tail the eviction loop would retain. */
511
+ retainedTailCount(journal, maxEvents, maxBytes) {
512
+ let count = 0;
513
+ let bytes = 0;
514
+ for (let i = journal.entries.length - 1; i >= 0; i--) {
515
+ const entryBytes = journal.entryBytes[i] ?? 0;
516
+ if (count + 1 > maxEvents) break;
517
+ if (count >= 1 && bytes + entryBytes > maxBytes) break;
518
+ count += 1;
519
+ bytes += entryBytes;
520
+ }
521
+ return count;
522
+ }
398
523
  classifySessionUpdate(event) {
399
524
  const data = event.data;
400
525
  const updateType = data?.update?.sessionUpdate;
@@ -562,13 +687,9 @@ var TurnBoundaryCompactionEngine = class {
562
687
  }
563
688
  }
564
689
  resetJournal() {
565
- this.liveJournal = [];
566
- this.journalEntryBytes = [];
567
- this.journalEntryEvents = [];
568
- this.journalTotalBytes = 0;
569
- this.journalTotalEvents = 0;
570
- this.journalTruncatedEvents = 0;
571
- this.liveJournalTextSegment = void 0;
690
+ this.fullJournal = createLiveJournalState();
691
+ this.summaryJournal = createLiveJournalState();
692
+ this.journalGrowthDeniedAt = void 0;
572
693
  }
573
694
  addReplaySegment(events, turnCount) {
574
695
  if (events.length === 0) return;
@@ -803,6 +924,21 @@ function extractParentToolCallIdFromMeta(meta) {
803
924
  return void 0;
804
925
  }
805
926
  __name(extractParentToolCallIdFromMeta, "extractParentToolCallIdFromMeta");
927
+ function isSummaryLiveJournalEvent(event) {
928
+ if (event.type !== "session_update") return true;
929
+ const data = event.data;
930
+ const meta = data?.update?._meta;
931
+ const parentToolCallId = extractParentToolCallIdFromMeta(meta);
932
+ if (parentToolCallId === void 0) return true;
933
+ if (parentToolCallId === data?.update?.toolCallId) return true;
934
+ if (data?.update?.sessionUpdate !== "agent_message_chunk") return false;
935
+ if (typeof meta !== "object" || meta === null) return false;
936
+ const usage = meta["usage"];
937
+ if (typeof usage !== "object" || usage === null) return false;
938
+ const fields = usage;
939
+ return typeof fields["inputTokens"] === "number" || typeof fields["outputTokens"] === "number";
940
+ }
941
+ __name(isSummaryLiveJournalEvent, "isSummaryLiveJournalEvent");
806
942
  function extractSourceRecordIdsFromMeta(meta) {
807
943
  if (typeof meta !== "object" || meta === null) return void 0;
808
944
  const transcript = meta["qwenTranscript"];
@@ -925,6 +1061,44 @@ function mergeTranscriptUpdateMeta(existing, incoming) {
925
1061
  }
926
1062
  __name(mergeTranscriptUpdateMeta, "mergeTranscriptUpdateMeta");
927
1063
 
1064
+ // packages/acp-bridge/src/journalGrowthPolicy.ts
1065
+ init_esbuild_shims();
1066
+ function createJournalGrowthPolicy(opts) {
1067
+ const hardCapEvents = Math.min(
1068
+ Number.MAX_SAFE_INTEGER,
1069
+ Math.max(
1070
+ opts.baselineEvents,
1071
+ Math.ceil(opts.hardCapBytes / opts.baselineBytes * opts.baselineEvents)
1072
+ )
1073
+ );
1074
+ return {
1075
+ grant(request) {
1076
+ if (request.currentMaxBytes >= opts.hardCapBytes) return void 0;
1077
+ const extraGranted = request.allSessionLimits.reduce(
1078
+ (sum, session) => sum + Math.max(0, session.limitBytes - session.baselineBytes),
1079
+ 0
1080
+ );
1081
+ const available = opts.poolBytes - extraGranted;
1082
+ if (available <= 0) return void 0;
1083
+ const maxBytes = Math.min(
1084
+ request.currentMaxBytes * 2,
1085
+ request.currentMaxBytes + available,
1086
+ opts.hardCapBytes
1087
+ );
1088
+ if (maxBytes <= request.currentMaxBytes) return void 0;
1089
+ const maxEvents = Math.min(
1090
+ Math.max(
1091
+ request.currentMaxEvents,
1092
+ Math.ceil(maxBytes / opts.baselineBytes * opts.baselineEvents)
1093
+ ),
1094
+ hardCapEvents
1095
+ );
1096
+ return { maxBytes, maxEvents };
1097
+ }
1098
+ };
1099
+ }
1100
+ __name(createJournalGrowthPolicy, "createJournalGrowthPolicy");
1101
+
928
1102
  // packages/acp-bridge/src/session-restore-timeout.ts
929
1103
  init_esbuild_shims();
930
1104
  var DEFAULT_SESSION_RESTORE_TIMEOUT_MS = 6e4;
@@ -2458,12 +2632,13 @@ var BridgeClient = class {
2458
2632
  const toolCallId = params["toolCallId"];
2459
2633
  const toolName = params["toolName"];
2460
2634
  const args = params["arguments"];
2461
- if (typeof sessionId !== "string" || sessionId.length === 0 || typeof promptId !== "string" || promptId.length === 0 || typeof toolCallId !== "string" || toolCallId.length === 0 || typeof toolName !== "string" || toolName.length === 0 || !isRecord2(args)) {
2635
+ if (typeof sessionId !== "string" || sessionId.length === 0 || promptId !== void 0 && (typeof promptId !== "string" || promptId.length === 0) || typeof toolCallId !== "string" || toolCallId.length === 0 || typeof toolName !== "string" || toolName.length === 0 || !isRecord2(args)) {
2462
2636
  throw RequestError.invalidParams(
2463
2637
  void 0,
2464
2638
  "Invalid external tool guard request"
2465
2639
  );
2466
2640
  }
2641
+ const promptScoped = promptId !== void 0;
2467
2642
  if (!this.ownsSession(sessionId)) {
2468
2643
  throw RequestError.invalidParams(
2469
2644
  void 0,
@@ -2471,21 +2646,26 @@ var BridgeClient = class {
2471
2646
  );
2472
2647
  }
2473
2648
  const entry = this.resolveEntry(sessionId);
2474
- if (!entry || !entry.promptActive || entry.activePromptId !== promptId) {
2649
+ if (!entry || promptScoped && (!entry.promptActive || entry.activePromptId !== promptId)) {
2475
2650
  throw RequestError.invalidParams(
2476
2651
  void 0,
2477
2652
  "External tool guard prompt is not the active prompt"
2478
2653
  );
2479
2654
  }
2655
+ const invocationCwd = params["invocationCwd"];
2480
2656
  const decision = await this.externalToolGuard({
2481
2657
  sessionId: entry.sessionId,
2482
- promptId: entry.activePromptId,
2658
+ ...promptScoped ? { promptId } : {},
2483
2659
  toolCallId,
2484
2660
  toolName,
2485
- arguments: args
2661
+ arguments: args,
2662
+ effectiveCwd: entry.effectiveCwd,
2663
+ // Forwarded verbatim and explicitly untrusted: the host policy decides
2664
+ // whether it can establish this scope from state it owns.
2665
+ ...typeof invocationCwd === "string" && invocationCwd.length > 0 ? { invocationCwd } : {}
2486
2666
  });
2487
2667
  const currentEntry = this.resolveEntry(sessionId);
2488
- if (!this.ownsSession(sessionId) || currentEntry !== entry || !currentEntry.promptActive || currentEntry.activePromptId !== promptId) {
2668
+ if (!this.ownsSession(sessionId) || currentEntry !== entry || promptScoped && (!currentEntry.promptActive || currentEntry.activePromptId !== promptId)) {
2489
2669
  throw RequestError.invalidParams(
2490
2670
  void 0,
2491
2671
  "External tool guard prompt is no longer active"
@@ -5908,11 +6088,16 @@ var KNOWN_SESSION_UPDATE_TYPES = /* @__PURE__ */ new Set([
5908
6088
  "session_info_update",
5909
6089
  "usage_update"
5910
6090
  ]);
5911
- var MAX_BULK_REPLAY_UPDATES = 1e4;
5912
6091
  function isRecord3(value) {
5913
6092
  return typeof value === "object" && value !== null && !Array.isArray(value);
5914
6093
  }
5915
6094
  __name(isRecord3, "isRecord");
6095
+ function safeTransportFailureCode(error) {
6096
+ if (!isRecord3(error)) return void 0;
6097
+ const code = error["code"];
6098
+ return typeof code === "string" && /^[a-z0-9_.-]{1,64}$/iu.test(code) ? code : void 0;
6099
+ }
6100
+ __name(safeTransportFailureCode, "safeTransportFailureCode");
5916
6101
  function sessionSourceRequestMeta(sourceType, sourceId) {
5917
6102
  return sourceType ? {
5918
6103
  [SESSION_SOURCE_META_KEY]: {
@@ -5922,12 +6107,280 @@ function sessionSourceRequestMeta(sourceType, sourceId) {
5922
6107
  } : {};
5923
6108
  }
5924
6109
  __name(sessionSourceRequestMeta, "sessionSourceRequestMeta");
6110
+ function getChannelPromptDisplayText(entry, displayText) {
6111
+ return entry.sourceType === "channel" && typeof displayText === "string" ? displayText : void 0;
6112
+ }
6113
+ __name(getChannelPromptDisplayText, "getChannelPromptDisplayText");
5925
6114
  function isDefinitiveAcpRequestError(error) {
5926
6115
  if (error instanceof RequestError) return true;
5927
6116
  if (!isRecord3(error)) return false;
5928
6117
  return typeof error["code"] === "number" && Number.isInteger(error["code"]) && typeof error["message"] === "string";
5929
6118
  }
5930
6119
  __name(isDefinitiveAcpRequestError, "isDefinitiveAcpRequestError");
6120
+ var LogSafeAcpRequestError = class extends RequestError {
6121
+ constructor(code, message, data, reservePreparedResponse) {
6122
+ super(code, message, data);
6123
+ this.reservePreparedResponse = reservePreparedResponse;
6124
+ }
6125
+ static {
6126
+ __name(this, "LogSafeAcpRequestError");
6127
+ }
6128
+ toResult() {
6129
+ const result = super.toResult();
6130
+ if ("error" in result) {
6131
+ Object.defineProperty(result.error, inspect.custom, {
6132
+ configurable: true,
6133
+ value: /* @__PURE__ */ __name(() => ({ code: result.error.code, payloadOmitted: true }), "value")
6134
+ });
6135
+ try {
6136
+ this.reservePreparedResponse?.(result.error);
6137
+ } catch {
6138
+ }
6139
+ }
6140
+ return result;
6141
+ }
6142
+ };
6143
+ var MAX_LOG_SAFE_ACP_ERROR_DETAILS_CHARS = 1024;
6144
+ var MAX_LOG_SAFE_ACP_ERROR_KIND_CHARS = 128;
6145
+ var MAX_LOG_SAFE_ACP_ERROR_HINT_CHARS = 512;
6146
+ function logSafeAcpErrorDetails(error) {
6147
+ const details = error instanceof Error ? error.message : isRecord3(error) && typeof error["message"] === "string" ? error["message"] : void 0;
6148
+ if (!details) return void 0;
6149
+ return {
6150
+ details: details.length <= MAX_LOG_SAFE_ACP_ERROR_DETAILS_CHARS ? details : `${details.slice(0, MAX_LOG_SAFE_ACP_ERROR_DETAILS_CHARS)}\u2026`
6151
+ };
6152
+ }
6153
+ __name(logSafeAcpErrorDetails, "logSafeAcpErrorDetails");
6154
+ function boundedAcpErrorString(value, maxChars) {
6155
+ return value.length <= maxChars ? value : `${value.slice(0, maxChars)}\u2026`;
6156
+ }
6157
+ __name(boundedAcpErrorString, "boundedAcpErrorString");
6158
+ function logSafeRequestErrorMessage(code) {
6159
+ switch (code) {
6160
+ case -32700:
6161
+ return "Parse error";
6162
+ case -32600:
6163
+ return "Invalid request";
6164
+ case -32601:
6165
+ return "Method not found";
6166
+ case -32602:
6167
+ return "Invalid params";
6168
+ case -32603:
6169
+ return "Internal error";
6170
+ case -32e3:
6171
+ return "Authentication required";
6172
+ case -32002:
6173
+ return "Resource not found";
6174
+ default:
6175
+ return "ACP client request failed";
6176
+ }
6177
+ }
6178
+ __name(logSafeRequestErrorMessage, "logSafeRequestErrorMessage");
6179
+ function logSafeRequestErrorData(data) {
6180
+ if (!isRecord3(data) || typeof data["errorKind"] !== "string") {
6181
+ return void 0;
6182
+ }
6183
+ const status = data["status"];
6184
+ const hint = data["hint"];
6185
+ return {
6186
+ errorKind: boundedAcpErrorString(
6187
+ data["errorKind"],
6188
+ MAX_LOG_SAFE_ACP_ERROR_KIND_CHARS
6189
+ ),
6190
+ ...typeof status === "number" && Number.isFinite(status) ? { status } : {},
6191
+ ...typeof hint === "string" ? {
6192
+ hint: boundedAcpErrorString(hint, MAX_LOG_SAFE_ACP_ERROR_HINT_CHARS)
6193
+ } : {}
6194
+ };
6195
+ }
6196
+ __name(logSafeRequestErrorData, "logSafeRequestErrorData");
6197
+ var AcpInboundHandlerLimitError = class extends Error {
6198
+ constructor(maxActiveHandlers, maxActiveHandlerBytes, requiredBytes, availableBytes) {
6199
+ super("ACP inbound handler capacity exceeded");
6200
+ this.maxActiveHandlers = maxActiveHandlers;
6201
+ this.maxActiveHandlerBytes = maxActiveHandlerBytes;
6202
+ this.requiredBytes = requiredBytes;
6203
+ this.availableBytes = availableBytes;
6204
+ this.name = "AcpInboundHandlerLimitError";
6205
+ }
6206
+ static {
6207
+ __name(this, "AcpInboundHandlerLimitError");
6208
+ }
6209
+ code = "acp_handler_limit_exceeded";
6210
+ };
6211
+ function estimateAcpHandlerBytes(value, limitBytes) {
6212
+ let bytes = 0;
6213
+ const stack = [value];
6214
+ const seen = /* @__PURE__ */ new WeakSet();
6215
+ while (stack.length > 0) {
6216
+ const current = stack.pop();
6217
+ if (current === null) {
6218
+ bytes += 4;
6219
+ } else if (typeof current === "string") {
6220
+ bytes += Buffer.byteLength(current) + 2;
6221
+ } else if (typeof current === "number") {
6222
+ bytes += 24;
6223
+ } else if (typeof current === "boolean") {
6224
+ bytes += 5;
6225
+ } else if (Array.isArray(current)) {
6226
+ if (seen.has(current)) return limitBytes + 1;
6227
+ seen.add(current);
6228
+ bytes += 2 + Math.max(0, current.length - 1);
6229
+ if (bytes + current.length > limitBytes) return limitBytes + 1;
6230
+ for (let index = current.length - 1; index >= 0; index--) {
6231
+ stack.push(current[index]);
6232
+ }
6233
+ } else if (isRecord3(current)) {
6234
+ if (seen.has(current)) return limitBytes + 1;
6235
+ seen.add(current);
6236
+ const entries = Object.entries(current);
6237
+ bytes += 2 + Math.max(0, entries.length - 1);
6238
+ for (const [key, entryValue] of entries) {
6239
+ bytes += Buffer.byteLength(key) + 3;
6240
+ stack.push(entryValue);
6241
+ }
6242
+ } else {
6243
+ bytes += 4;
6244
+ }
6245
+ if (bytes > limitBytes) return limitBytes + 1;
6246
+ }
6247
+ return Math.max(1, bytes);
6248
+ }
6249
+ __name(estimateAcpHandlerBytes, "estimateAcpHandlerBytes");
6250
+ var AcpInboundHandlerAdmission = class {
6251
+ constructor(guard) {
6252
+ this.guard = guard;
6253
+ }
6254
+ static {
6255
+ __name(this, "AcpInboundHandlerAdmission");
6256
+ }
6257
+ activeHandlers = 0;
6258
+ activeBytes = 0;
6259
+ async run(params, operation) {
6260
+ const envelopeBytes = Math.min(2048, this.guard.maxActiveHandlerBytes);
6261
+ const requiredBytes = envelopeBytes + estimateAcpHandlerBytes(
6262
+ params,
6263
+ Math.max(0, this.guard.maxActiveHandlerBytes - envelopeBytes)
6264
+ );
6265
+ const availableBytes = Math.max(
6266
+ 0,
6267
+ this.guard.maxActiveHandlerBytes - this.activeBytes
6268
+ );
6269
+ if (this.activeHandlers >= this.guard.maxActiveHandlers || requiredBytes > availableBytes) {
6270
+ const error = new AcpInboundHandlerLimitError(
6271
+ this.guard.maxActiveHandlers,
6272
+ this.guard.maxActiveHandlerBytes,
6273
+ requiredBytes,
6274
+ availableBytes
6275
+ );
6276
+ this.guard.fail(error);
6277
+ throw error;
6278
+ }
6279
+ this.activeHandlers++;
6280
+ this.activeBytes += requiredBytes;
6281
+ try {
6282
+ return await operation();
6283
+ } finally {
6284
+ this.activeHandlers--;
6285
+ this.activeBytes -= requiredBytes;
6286
+ }
6287
+ }
6288
+ };
6289
+ async function withLogSafeAcpError(operation, reservePreparedResponse) {
6290
+ try {
6291
+ return await operation();
6292
+ } catch (error) {
6293
+ if (error instanceof RequestError) {
6294
+ const code = Number.isFinite(error.code) ? error.code : -32603;
6295
+ throw new LogSafeAcpRequestError(
6296
+ code,
6297
+ logSafeRequestErrorMessage(code),
6298
+ logSafeRequestErrorData(error.data),
6299
+ reservePreparedResponse
6300
+ );
6301
+ }
6302
+ throw new LogSafeAcpRequestError(
6303
+ -32603,
6304
+ "Internal error",
6305
+ logSafeAcpErrorDetails(error),
6306
+ reservePreparedResponse
6307
+ );
6308
+ }
6309
+ }
6310
+ __name(withLogSafeAcpError, "withLogSafeAcpError");
6311
+ function createLogSafeAcpClient(client, transportGuard) {
6312
+ const admission = new AcpInboundHandlerAdmission(transportGuard);
6313
+ const runNotification = /* @__PURE__ */ __name((params, operation) => withLogSafeAcpError(() => admission.run(params, operation)), "runNotification");
6314
+ const runRequest = /* @__PURE__ */ __name((params, operation) => withLogSafeAcpError(
6315
+ () => admission.run(params, async () => {
6316
+ const result = await operation();
6317
+ transportGuard.reservePreparedResponse(result ?? null);
6318
+ return result;
6319
+ }),
6320
+ transportGuard.reservePreparedResponse
6321
+ ), "runRequest");
6322
+ return {
6323
+ requestPermission: /* @__PURE__ */ __name((params) => runRequest(params, () => client.requestPermission(params)), "requestPermission"),
6324
+ sessionUpdate: /* @__PURE__ */ __name((params) => runNotification(params, () => client.sessionUpdate(params)), "sessionUpdate"),
6325
+ writeTextFile: client.writeTextFile ? (params) => runRequest(params, () => client.writeTextFile(params)) : void 0,
6326
+ readTextFile: client.readTextFile ? (params) => runRequest(params, () => client.readTextFile(params)) : void 0,
6327
+ createTerminal: client.createTerminal ? (params) => runRequest(params, () => client.createTerminal(params)) : void 0,
6328
+ terminalOutput: client.terminalOutput ? (params) => runRequest(params, () => client.terminalOutput(params)) : void 0,
6329
+ releaseTerminal: client.releaseTerminal ? (params) => runRequest(
6330
+ params,
6331
+ async () => await client.releaseTerminal(params) ?? {}
6332
+ ) : void 0,
6333
+ waitForTerminalExit: client.waitForTerminalExit ? (params) => runRequest(params, () => client.waitForTerminalExit(params)) : void 0,
6334
+ killTerminal: client.killTerminal ? (params) => runRequest(
6335
+ params,
6336
+ async () => await client.killTerminal(params) ?? {}
6337
+ ) : void 0,
6338
+ extMethod: client.extMethod ? (method, params) => runRequest(params, () => client.extMethod(method, params)) : void 0,
6339
+ extNotification: client.extNotification ? (method, params) => runNotification(params, () => client.extNotification(method, params)) : void 0
6340
+ };
6341
+ }
6342
+ __name(createLogSafeAcpClient, "createLogSafeAcpClient");
6343
+ var OUTBOUND_GUARDED_CONNECTION_METHODS = /* @__PURE__ */ new Set([
6344
+ "initialize",
6345
+ "newSession",
6346
+ "loadSession",
6347
+ "unstable_forkSession",
6348
+ "unstable_listSessions",
6349
+ "unstable_resumeSession",
6350
+ "setSessionMode",
6351
+ "unstable_setSessionModel",
6352
+ "setSessionConfigOption",
6353
+ "authenticate",
6354
+ "prompt",
6355
+ "cancel",
6356
+ "extMethod",
6357
+ "extNotification"
6358
+ ]);
6359
+ function createOutboundGuardedConnection(connection, transportGuard) {
6360
+ const wrappers = /* @__PURE__ */ new Map();
6361
+ return new Proxy(connection, {
6362
+ get(target, property) {
6363
+ const value = Reflect.get(target, property, target);
6364
+ if (typeof value !== "function" || !OUTBOUND_GUARDED_CONNECTION_METHODS.has(property)) {
6365
+ return value;
6366
+ }
6367
+ let wrapper = wrappers.get(property);
6368
+ if (!wrapper) {
6369
+ wrapper = /* @__PURE__ */ __name(async (...args) => {
6370
+ const release = transportGuard.reserveOutboundOperation(args);
6371
+ try {
6372
+ return await Reflect.apply(value, target, args);
6373
+ } finally {
6374
+ release();
6375
+ }
6376
+ }, "wrapper");
6377
+ wrappers.set(property, wrapper);
6378
+ }
6379
+ return wrapper;
6380
+ }
6381
+ });
6382
+ }
6383
+ __name(createOutboundGuardedConnection, "createOutboundGuardedConnection");
5931
6384
  function getCanonicalModelId(response, fallback) {
5932
6385
  if (!isRecord3(response) || !isRecord3(response["_meta"])) return fallback;
5933
6386
  const modelSwitch = response["_meta"]["qwenModelSwitch"];
@@ -5964,9 +6417,9 @@ function extractLoadReplayResponse(state) {
5964
6417
  `Invalid qwen.session.loadReplay updates (version=${LOAD_REPLAY_VERSION}, count=not-array)`
5965
6418
  );
5966
6419
  }
5967
- if (rawUpdates.length > MAX_BULK_REPLAY_UPDATES) {
6420
+ if (rawUpdates.length > LOAD_REPLAY_MAX_UPDATES) {
5968
6421
  throw new Error(
5969
- `qwen.session.loadReplay updates exceed limit (${rawUpdates.length} > ${MAX_BULK_REPLAY_UPDATES})`
6422
+ `qwen.session.loadReplay updates exceed limit (${rawUpdates.length} > ${LOAD_REPLAY_MAX_UPDATES})`
5970
6423
  );
5971
6424
  }
5972
6425
  const partial = replay["partial"];
@@ -5987,6 +6440,12 @@ function extractLoadReplayResponse(state) {
5987
6440
  `Invalid qwen.session.loadReplay hasMore (version=${LOAD_REPLAY_VERSION}, hasMore=${describeLoadReplayValue(hasMore)})`
5988
6441
  );
5989
6442
  }
6443
+ const anchorRecordId = replay["anchorRecordId"];
6444
+ if (anchorRecordId !== void 0 && typeof anchorRecordId !== "string") {
6445
+ throw new Error(
6446
+ `Invalid qwen.session.loadReplay anchorRecordId (version=${LOAD_REPLAY_VERSION}, anchorRecordId=${describeLoadReplayValue(anchorRecordId)})`
6447
+ );
6448
+ }
5990
6449
  const invalidUpdateIndex = rawUpdates.findIndex(
5991
6450
  (update) => !isBulkReplayUpdate(update)
5992
6451
  );
@@ -6008,6 +6467,7 @@ function extractLoadReplayResponse(state) {
6008
6467
  return {
6009
6468
  state: cleanState,
6010
6469
  updates: rawUpdates,
6470
+ ...typeof anchorRecordId === "string" ? { anchorRecordId } : {},
6011
6471
  ...partial === true ? { partial: true } : {},
6012
6472
  ...typeof replayError === "string" ? { replayError } : {},
6013
6473
  ...hasMore === true ? { hasMore: true } : {}
@@ -6134,14 +6594,27 @@ function pickUserInputEchoMeta(meta) {
6134
6594
  return Array.isArray(inputAnnotations) ? { inputAnnotations } : {};
6135
6595
  }
6136
6596
  __name(pickUserInputEchoMeta, "pickUserInputEchoMeta");
6137
- function echoPromptToSessionBus(entry, req, promptId, originatorClientId) {
6597
+ function echoPromptToSessionBus(entry, req, promptId, originatorClientId, displayText) {
6138
6598
  const prompt = req.prompt;
6139
6599
  if (!Array.isArray(prompt) || prompt.length === 0) return;
6600
+ let displayTextPublished = false;
6140
6601
  const serverTimestamp = Date.now();
6141
- const blockCount = Math.min(prompt.length, MAX_ECHO_CONTENT_BLOCKS);
6602
+ const echoPrompt = prompt.slice(0, MAX_ECHO_CONTENT_BLOCKS);
6603
+ if (displayText && !echoPrompt.some((part) => isRecord3(part) && part["type"] === "text")) {
6604
+ const textPart = prompt.slice(MAX_ECHO_CONTENT_BLOCKS).find((part) => isRecord3(part) && part["type"] === "text");
6605
+ if (textPart) echoPrompt[echoPrompt.length - 1] = textPart;
6606
+ }
6607
+ const blockCount = echoPrompt.length;
6142
6608
  for (let i = 0; i < blockCount; i += 1) {
6143
- const part = prompt[i];
6609
+ const part = echoPrompt[i];
6144
6610
  if (!part || typeof part !== "object" || Array.isArray(part)) continue;
6611
+ let displayPart = part;
6612
+ if (displayText !== void 0 && part.type === "text") {
6613
+ if (displayTextPublished) continue;
6614
+ displayTextPublished = true;
6615
+ if (!displayText) continue;
6616
+ displayPart = { ...part, text: displayText };
6617
+ }
6145
6618
  try {
6146
6619
  entry.events.publish({
6147
6620
  type: "session_update",
@@ -6150,7 +6623,7 @@ function echoPromptToSessionBus(entry, req, promptId, originatorClientId) {
6150
6623
  sessionId: req.sessionId,
6151
6624
  update: {
6152
6625
  sessionUpdate: "user_message_chunk",
6153
- content: part,
6626
+ content: displayPart,
6154
6627
  // `_meta` lives inside the `update` object rather than at
6155
6628
  // envelope level. `_meta` is a standard JSON-RPC/MCP extension
6156
6629
  // field permitted alongside spec fields, the SDK normalizer
@@ -6203,9 +6676,9 @@ function broadcastPromptCancelledOnce(entry, sessionId, promptId, originatorClie
6203
6676
  );
6204
6677
  }
6205
6678
  __name(broadcastPromptCancelledOnce, "broadcastPromptCancelledOnce");
6206
- function broadcastTurnComplete(entry, sessionId, promptResult, promptId, originatorClientId) {
6679
+ function broadcastTurnComplete(entry, sessionId, promptResult, promptId, originatorClientId, mutateTurnState) {
6207
6680
  try {
6208
- entry.events.publish({
6681
+ const published = entry.events.publish({
6209
6682
  type: "turn_complete",
6210
6683
  ...promptId ? { promptId } : {},
6211
6684
  data: {
@@ -6215,6 +6688,8 @@ function broadcastTurnComplete(entry, sessionId, promptResult, promptId, origina
6215
6688
  },
6216
6689
  ...originatorClientId ? { originatorClientId } : {}
6217
6690
  });
6691
+ if (mutateTurnState && published !== void 0)
6692
+ entry.turnErrorEvent = void 0;
6218
6693
  } catch {
6219
6694
  }
6220
6695
  }
@@ -6246,6 +6721,14 @@ function extractJsonRpcErrorDetail(data) {
6246
6721
  return void 0;
6247
6722
  }
6248
6723
  __name(extractJsonRpcErrorDetail, "extractJsonRpcErrorDetail");
6724
+ function extractJsonRpcErrorField(err, field) {
6725
+ if (typeof err !== "object" || err === null) return void 0;
6726
+ const data = err.data;
6727
+ if (typeof data !== "object" || data === null) return void 0;
6728
+ const value = data[field];
6729
+ return typeof value === "string" && value.length > 0 ? value : void 0;
6730
+ }
6731
+ __name(extractJsonRpcErrorField, "extractJsonRpcErrorField");
6249
6732
  function extractErrorCode(err) {
6250
6733
  if (typeof err !== "object" || err === null || !("code" in err))
6251
6734
  return void 0;
@@ -6255,14 +6738,79 @@ function extractErrorCode(err) {
6255
6738
  return void 0;
6256
6739
  }
6257
6740
  __name(extractErrorCode, "extractErrorCode");
6741
+ var REFRESH_APPEND_BOOKKEEPING_EVENT_TYPES = /* @__PURE__ */ new Set([
6742
+ "pending_prompt_added",
6743
+ "pending_prompt_completed",
6744
+ "prompt_cancelled",
6745
+ "model_switched",
6746
+ "model_switch_failed",
6747
+ "approval_mode_changed",
6748
+ "language_changed",
6749
+ "session_metadata_updated",
6750
+ "session_cwd_changed",
6751
+ "artifact_changed",
6752
+ "settings_changed",
6753
+ "extensions_changed",
6754
+ "mcp_server_changed",
6755
+ "mcp_server_added",
6756
+ "mcp_server_removed",
6757
+ "user_shell_command",
6758
+ "user_shell_result",
6759
+ // Workspace-level fan-out (workspace service, git watcher, memory /
6760
+ // agent CRUD, device-flow registry) reaches every session bus via
6761
+ // `publishWorkspaceEvent` while idle. The `auth_device_flow_*` members
6762
+ // mirror the closed `DeviceFlowEventEmission` union — audit that union
6763
+ // when it grows.
6764
+ "tool_toggled",
6765
+ "workspace_initialized",
6766
+ "mcp_server_restarted",
6767
+ "mcp_server_restart_refused",
6768
+ "settings_reloaded",
6769
+ "trust_change_requested",
6770
+ "memory_changed",
6771
+ "agent_changed",
6772
+ "git_status_changed",
6773
+ "git_branch_changed",
6774
+ "github_setup_completed",
6775
+ "auth_device_flow_started",
6776
+ "auth_device_flow_throttled",
6777
+ "auth_device_flow_authorized",
6778
+ "auth_device_flow_failed",
6779
+ "auth_device_flow_cancelled"
6780
+ ]);
6781
+ function isIdleBookkeepingSessionUpdate(event) {
6782
+ if (event.type !== "session_update") return false;
6783
+ const data = event.data;
6784
+ if (!data || typeof data !== "object" || Array.isArray(data)) return false;
6785
+ const update = data["update"];
6786
+ if (!update || typeof update !== "object" || Array.isArray(update))
6787
+ return false;
6788
+ const updateRecord = update;
6789
+ const subtype = updateRecord["sessionUpdate"];
6790
+ if (subtype === "available_commands_update" || subtype === "current_mode_update") {
6791
+ return true;
6792
+ }
6793
+ const meta = updateRecord["_meta"];
6794
+ if (!meta || typeof meta !== "object" || Array.isArray(meta)) return false;
6795
+ return meta["source"] === "user-shell";
6796
+ }
6797
+ __name(isIdleBookkeepingSessionUpdate, "isIdleBookkeepingSessionUpdate");
6798
+ function isRefreshAppendTurnContent(event) {
6799
+ if (event.type === "history_truncated") return false;
6800
+ if (REFRESH_APPEND_BOOKKEEPING_EVENT_TYPES.has(event.type)) return false;
6801
+ return !isIdleBookkeepingSessionUpdate(event);
6802
+ }
6803
+ __name(isRefreshAppendTurnContent, "isRefreshAppendTurnContent");
6258
6804
  function classifyTurnErrorKind(message) {
6259
6805
  return message.trim().toLowerCase() === "terminated" ? "model_stream_interrupted" : void 0;
6260
6806
  }
6261
6807
  __name(classifyTurnErrorKind, "classifyTurnErrorKind");
6262
6808
  function broadcastTurnError(entry, sessionId, err, promptId, originatorClientId, mutateTurnState) {
6263
6809
  const message = extractErrorMessage(err);
6264
- const code = extractErrorCode(err);
6265
- const errorKind = classifyTurnErrorKind(message);
6810
+ const structuredErrorKind = extractJsonRpcErrorField(err, "errorKind");
6811
+ const errorKind = structuredErrorKind ?? classifyTurnErrorKind(message);
6812
+ const code = structuredErrorKind !== void 0 ? extractJsonRpcErrorField(err, "code") ?? extractErrorCode(err) : extractErrorCode(err);
6813
+ const loopType = extractJsonRpcErrorField(err, "loopType");
6266
6814
  if (errorKind) {
6267
6815
  writeServeDebugLine(
6268
6816
  `turn_error classified session=${JSON.stringify(sessionId)} message=${JSON.stringify(message)} errorKind=${JSON.stringify(errorKind)}` + (code ? ` code=${JSON.stringify(code)}` : "") + (promptId ? ` promptId=${JSON.stringify(promptId)}` : "")
@@ -6277,7 +6825,7 @@ function broadcastTurnError(entry, sessionId, err, promptId, originatorClientId,
6277
6825
  };
6278
6826
  }
6279
6827
  try {
6280
- entry.events.publish({
6828
+ const published = entry.events.publish({
6281
6829
  type: "turn_error",
6282
6830
  ...promptId ? { promptId } : {},
6283
6831
  data: {
@@ -6285,10 +6833,14 @@ function broadcastTurnError(entry, sessionId, err, promptId, originatorClientId,
6285
6833
  message,
6286
6834
  ...code ? { code } : {},
6287
6835
  ...errorKind ? { errorKind } : {},
6836
+ ...loopType ? { loopType } : {},
6288
6837
  ...promptId ? { promptId } : {}
6289
6838
  },
6290
6839
  ...originatorClientId ? { originatorClientId } : {}
6291
6840
  });
6841
+ if (mutateTurnState) {
6842
+ entry.turnErrorEvent = published;
6843
+ }
6292
6844
  } catch {
6293
6845
  }
6294
6846
  }
@@ -6302,13 +6854,21 @@ function publishPromptTerminal(entry, pendingEntry, terminal) {
6302
6854
  }
6303
6855
  pendingEntry.terminalPublished = true;
6304
6856
  const originatorClientId = pendingEntry.originatorClientId;
6857
+ const mutateTurnState = pendingEntry.state === "running";
6858
+ if (!mutateTurnState && entry.turnErrorEvent) {
6859
+ const journal = entry.events.liveJournalSnapshot() ?? [];
6860
+ if (journal.some(isRefreshAppendTurnContent)) {
6861
+ entry.turnErrorEvent = void 0;
6862
+ }
6863
+ }
6305
6864
  if (terminal.kind === "complete") {
6306
6865
  broadcastTurnComplete(
6307
6866
  entry,
6308
6867
  entry.sessionId,
6309
6868
  terminal.result,
6310
6869
  pendingEntry.promptId,
6311
- originatorClientId
6870
+ originatorClientId,
6871
+ mutateTurnState
6312
6872
  );
6313
6873
  } else if (terminal.kind === "cancelled") {
6314
6874
  broadcastTurnComplete(
@@ -6316,7 +6876,8 @@ function publishPromptTerminal(entry, pendingEntry, terminal) {
6316
6876
  entry.sessionId,
6317
6877
  { stopReason: "cancelled" },
6318
6878
  pendingEntry.promptId,
6319
- originatorClientId
6879
+ originatorClientId,
6880
+ mutateTurnState
6320
6881
  );
6321
6882
  } else {
6322
6883
  broadcastTurnError(
@@ -6325,13 +6886,7 @@ function publishPromptTerminal(entry, pendingEntry, terminal) {
6325
6886
  terminal.err,
6326
6887
  pendingEntry.promptId,
6327
6888
  originatorClientId,
6328
- // Only a running prompt's failure is the active turn's failure. The
6329
- // `state === 'running'` gate (not `activePromptId`) is deliberate:
6330
- // on the normal settle path `settleActivePromptState` runs in
6331
- // `promptPromise.finally` BEFORE the terminal is published, so
6332
- // `activePromptId` is already cleared when a genuine active failure
6333
- // lands here.
6334
- pendingEntry.state === "running"
6889
+ mutateTurnState
6335
6890
  );
6336
6891
  }
6337
6892
  }
@@ -6482,6 +7037,16 @@ function createAcpSessionBridge(opts) {
6482
7037
  );
6483
7038
  const maxJournalEvents = normalizeMaxJournalEvents(opts.maxJournalEvents);
6484
7039
  const maxJournalBytes = normalizeMaxJournalBytes(opts.maxJournalBytes);
7040
+ const journalGrowthPoolBytes = normalizeJournalGrowthPoolBytes(
7041
+ opts.journalGrowthPoolBytes
7042
+ );
7043
+ const journalGrowthPolicy = journalGrowthPoolBytes !== void 0 ? createJournalGrowthPolicy({
7044
+ baselineEvents: maxJournalEvents,
7045
+ baselineBytes: maxJournalBytes,
7046
+ poolBytes: journalGrowthPoolBytes,
7047
+ hardCapBytes: JOURNAL_GROWTH_HARD_CAP_BYTES
7048
+ }) : void 0;
7049
+ const journalGrowthSessionLimits = opts.journalGrowthSessionLimits;
6485
7050
  const channelFactory = opts.channelFactory ?? defaultSpawnChannelFactory;
6486
7051
  const childEnvOverrides = opts.childEnvOverrides ? Object.freeze({ ...opts.childEnvOverrides }) : Object.freeze({});
6487
7052
  const initTimeoutMs = opts.initializeTimeoutMs ?? DEFAULT_INIT_TIMEOUT_MS;
@@ -6579,6 +7144,12 @@ function createAcpSessionBridge(opts) {
6579
7144
  if (entryHasLocalWork(entry)) return false;
6580
7145
  const owner = channelInfoForEntry(entry);
6581
7146
  if (owner?.pendingRestoreIds.has(entry.sessionId)) return false;
7147
+ const capability = owner?.activeWork;
7148
+ if (capability && !owner.isQuarantined && !owner.restoreSettlementOverdue && ACTIVE_WORK_HOLD_CATEGORIES.some(
7149
+ (category) => !capability.categories.includes(category)
7150
+ )) {
7151
+ return false;
7152
+ }
6582
7153
  return !childReportsHeldWork(entry);
6583
7154
  }
6584
7155
  __name(entryIsAutoCloseCandidate, "entryIsAutoCloseCandidate");
@@ -6717,6 +7288,14 @@ function createAcpSessionBridge(opts) {
6717
7288
  }
6718
7289
  }
6719
7290
  __name(cancelIdleTimer, "cancelIdleTimer");
7291
+ function channelUnavailableReject(channel, context) {
7292
+ const unavailable = channel.transportFailed ? Promise.race([channel.exited, channel.transportFailed]) : channel.exited;
7293
+ const reject = /* @__PURE__ */ __name(() => {
7294
+ throw new BridgeChannelClosedError(context);
7295
+ }, "reject");
7296
+ return unavailable.then(reject, reject);
7297
+ }
7298
+ __name(channelUnavailableReject, "channelUnavailableReject");
6720
7299
  async function killChannelWithLog(ci, context) {
6721
7300
  ci.isDying = true;
6722
7301
  await ci.channel.kill().catch((err) => {
@@ -6923,6 +7502,14 @@ function createAcpSessionBridge(opts) {
6923
7502
  const generationRequests = /* @__PURE__ */ new Map();
6924
7503
  const workspaceGenerationRequests = /* @__PURE__ */ new Map();
6925
7504
  const inFlightExtensionRefreshes = /* @__PURE__ */ new Map();
7505
+ const clearInFlightExtensionRefreshes = /* @__PURE__ */ __name((connection) => {
7506
+ for (const [sessionId, refresh] of inFlightExtensionRefreshes) {
7507
+ if (refresh.connection === connection) {
7508
+ refresh.rejectUnavailable();
7509
+ inFlightExtensionRefreshes.delete(sessionId);
7510
+ }
7511
+ }
7512
+ }, "clearInFlightExtensionRefreshes");
6926
7513
  const toSessionSummary = /* @__PURE__ */ __name((entry) => {
6927
7514
  let isWaitingForPermission = false;
6928
7515
  let isWaitingForUserQuestion = false;
@@ -6989,6 +7576,22 @@ function createAcpSessionBridge(opts) {
6989
7576
  const inFlightRequestedSessionSpawns = /* @__PURE__ */ new Map();
6990
7577
  const inFlightRestores = /* @__PURE__ */ new Map();
6991
7578
  const pendingRestoreEvents = /* @__PURE__ */ new Map();
7579
+ const journalSessionLimits = /* @__PURE__ */ __name(() => {
7580
+ const limits = [...byId.values()].map((entry) => ({
7581
+ limitBytes: entry.events.journalLimitBytes() ?? maxJournalBytes,
7582
+ baselineBytes: maxJournalBytes
7583
+ }));
7584
+ for (const [restoreId, bus] of pendingRestoreEvents) {
7585
+ if (!byId.has(restoreId)) {
7586
+ limits.push({
7587
+ limitBytes: bus.journalLimitBytes() ?? maxJournalBytes,
7588
+ baselineBytes: maxJournalBytes
7589
+ });
7590
+ }
7591
+ }
7592
+ return limits;
7593
+ }, "journalSessionLimits");
7594
+ const unregisterJournalGrowthSessionLimits = journalGrowthPolicy !== void 0 && opts.registerJournalGrowthSessionLimits !== void 0 ? opts.registerJournalGrowthSessionLimits(journalSessionLimits) : void 0;
6992
7595
  const createClientId = /* @__PURE__ */ __name(() => `client_${randomUUID2()}`, "createClientId");
6993
7596
  const registerClient = /* @__PURE__ */ __name((entry, requestedClientId) => {
6994
7597
  if (requestedClientId && entry.clientIds.has(requestedClientId)) {
@@ -7171,7 +7774,14 @@ function createAcpSessionBridge(opts) {
7171
7774
  applyActiveWorkSnapshot(currentInfo, snapshot);
7172
7775
  }
7173
7776
  );
7174
- connection = new ClientSideConnection(() => client, channel.stream);
7777
+ const rawConnection = new ClientSideConnection(
7778
+ () => channel.transportGuard ? createLogSafeAcpClient(client, channel.transportGuard) : client,
7779
+ channel.stream
7780
+ );
7781
+ connection = channel.transportGuard ? createOutboundGuardedConnection(
7782
+ rawConnection,
7783
+ channel.transportGuard
7784
+ ) : rawConnection;
7175
7785
  } catch (error) {
7176
7786
  try {
7177
7787
  channel.killSync();
@@ -7207,11 +7817,26 @@ function createAcpSessionBridge(opts) {
7207
7817
  unsettledAbandonedRestores: /* @__PURE__ */ new Set(),
7208
7818
  restoreSettlementOverdue: false,
7209
7819
  restoreSettlementTimers: /* @__PURE__ */ new Map(),
7820
+ transportFailed: false,
7821
+ transportFailureInitiatedTeardown: false,
7210
7822
  isDying: false,
7211
7823
  isQuarantined: false,
7212
7824
  handshakeComplete: false
7213
7825
  };
7214
7826
  infoRef.current = info;
7827
+ const markTransportFailed = /* @__PURE__ */ __name((error) => {
7828
+ if (!info.isDying) {
7829
+ info.transportFailureInitiatedTeardown = true;
7830
+ }
7831
+ info.transportFailed = true;
7832
+ info.transportFailureCode = safeTransportFailureCode(error);
7833
+ info.isDying = true;
7834
+ clearInFlightExtensionRefreshes(info.connection);
7835
+ }, "markTransportFailed");
7836
+ void channel.transportFailed?.then(
7837
+ markTransportFailed,
7838
+ markTransportFailed
7839
+ );
7215
7840
  aliveChannels.add(info);
7216
7841
  if (aliveChannels.size > 2) {
7217
7842
  writeStderrLine(
@@ -7219,6 +7844,7 @@ function createAcpSessionBridge(opts) {
7219
7844
  );
7220
7845
  }
7221
7846
  void channel.exited.then((exitInfo) => {
7847
+ clearInFlightExtensionRefreshes(info.connection);
7222
7848
  if (channelInfo === info) cancelIdleTimer();
7223
7849
  if (info.workspaceMcpDiscoveryTimer) {
7224
7850
  clearTimeout(info.workspaceMcpDiscoveryTimer);
@@ -7237,7 +7863,7 @@ function createAcpSessionBridge(opts) {
7237
7863
  if (channelInfo === info) channelInfo = void 0;
7238
7864
  const sessions = Array.from(info.sessionIds);
7239
7865
  info.sessionIds.clear();
7240
- const channelExitExpected = shuttingDown || info.isDying;
7866
+ const channelExitExpected = shuttingDown || info.isDying && !info.transportFailureInitiatedTeardown;
7241
7867
  if (info.handshakeComplete) {
7242
7868
  telemetry.metrics?.channelLifecycle("exit", channelExitExpected);
7243
7869
  }
@@ -7245,10 +7871,15 @@ function createAcpSessionBridge(opts) {
7245
7871
  telemetry.event("channel.exited", {
7246
7872
  "qwen-code.daemon.channel.exit_code": exitInfo?.exitCode ?? -1,
7247
7873
  "qwen-code.daemon.channel.session_count": sessions.length,
7874
+ "qwen-code.daemon.channel.transport_failed": info.transportFailed,
7875
+ "qwen-code.daemon.channel.transport_failure_initiated_teardown": info.transportFailureInitiatedTeardown,
7876
+ ...info.transportFailureCode ? {
7877
+ "qwen-code.daemon.channel.transport_error_code": info.transportFailureCode
7878
+ } : {},
7248
7879
  ...exitInfo?.signalCode ? { "qwen-code.daemon.channel.signal": exitInfo.signalCode } : {}
7249
7880
  });
7250
7881
  writeStderrLine(
7251
- `qwen serve: channel exited (code=${exitInfo?.exitCode ?? "none"}, signal=${exitInfo?.signalCode ?? "none"}, ${sessions.length} session(s) torn down)`
7882
+ `qwen serve: channel exited (code=${exitInfo?.exitCode ?? "none"}, signal=${exitInfo?.signalCode ?? "none"}, transport=${info.transportFailed ? info.transportFailureCode ?? "failed" : "ok"}, ${sessions.length} session(s) torn down)`
7252
7883
  );
7253
7884
  }
7254
7885
  for (const sid of sessions) {
@@ -7300,26 +7931,30 @@ function createAcpSessionBridge(opts) {
7300
7931
  },
7301
7932
  async () => {
7302
7933
  const response = await withTimeout(
7303
- connection.initialize({
7304
- protocolVersion: PROTOCOL_VERSION,
7305
- _meta: {
7306
- [ACTIVE_WORK_HEARTBEAT_META_KEY]: {
7307
- v: ACTIVE_WORK_HEARTBEAT_VERSION,
7308
- intervalMs: ACTIVE_WORK_HEARTBEAT_INTERVAL_MS
7934
+ Promise.race([
7935
+ connection.initialize({
7936
+ protocolVersion: PROTOCOL_VERSION,
7937
+ _meta: {
7938
+ [ACTIVE_WORK_HEARTBEAT_META_KEY]: {
7939
+ v: ACTIVE_WORK_HEARTBEAT_VERSION,
7940
+ intervalMs: ACTIVE_WORK_HEARTBEAT_INTERVAL_MS,
7941
+ categories: [...ACTIVE_WORK_HOLD_CATEGORIES]
7942
+ },
7943
+ [CHANNEL_STARTUP_PROFILE_META_KEY]: {
7944
+ v: CHANNEL_STARTUP_PROFILE_VERSION
7945
+ },
7946
+ [PRIVATE_PARENT_CAPABILITY_META_KEY]: privateParentCapability
7309
7947
  },
7310
- [CHANNEL_STARTUP_PROFILE_META_KEY]: {
7311
- v: CHANNEL_STARTUP_PROFILE_VERSION
7948
+ clientCapabilities: {
7949
+ fs: {
7950
+ readTextFile: delegateReadTextFileToClient,
7951
+ writeTextFile: true
7952
+ }
7312
7953
  },
7313
- [PRIVATE_PARENT_CAPABILITY_META_KEY]: privateParentCapability
7314
- },
7315
- clientCapabilities: {
7316
- fs: {
7317
- readTextFile: delegateReadTextFileToClient,
7318
- writeTextFile: true
7319
- }
7320
- },
7321
- clientInfo: { name: "qwen-serve-bridge", version: "0" }
7322
- }),
7954
+ clientInfo: { name: "qwen-serve-bridge", version: "0" }
7955
+ }),
7956
+ channelUnavailableReject(channel, "during initialize")
7957
+ ]),
7323
7958
  initTimeoutMs,
7324
7959
  "initialize"
7325
7960
  );
@@ -7364,6 +7999,11 @@ function createAcpSessionBridge(opts) {
7364
7999
  });
7365
8000
  throw err;
7366
8001
  }
8002
+ if (info.isDying) {
8003
+ await channel.kill().catch(() => {
8004
+ });
8005
+ throw new BridgeChannelClosedError("during initialize");
8006
+ }
7367
8007
  if (shuttingDown) {
7368
8008
  info.isDying = true;
7369
8009
  await channel.kill().catch(() => {
@@ -7393,6 +8033,9 @@ function createAcpSessionBridge(opts) {
7393
8033
  },
7394
8034
  ensureChannel
7395
8035
  );
8036
+ if (ci.isDying) {
8037
+ throw new BridgeChannelClosedError("before newSession");
8038
+ }
7396
8039
  ci.sessionSpawnsInFlight++;
7397
8040
  if (requestedSessionId !== void 0) {
7398
8041
  ci.client.markSessionRegistrationInFlight(requestedSessionId);
@@ -7425,15 +8068,18 @@ function createAcpSessionBridge(opts) {
7425
8068
  } : {}
7426
8069
  });
7427
8070
  const response = await withTimeout(
7428
- ci.connection.newSession(
7429
- worktree ? {
7430
- ...request,
7431
- _meta: {
7432
- ...isRecord3(request._meta) ? request._meta : {},
7433
- [WORKTREE_MCP_DEFER_META_KEY]: true
7434
- }
7435
- } : request
7436
- ),
8071
+ Promise.race([
8072
+ ci.connection.newSession(
8073
+ worktree ? {
8074
+ ...request,
8075
+ _meta: {
8076
+ ...isRecord3(request._meta) ? request._meta : {},
8077
+ [WORKTREE_MCP_DEFER_META_KEY]: true
8078
+ }
8079
+ } : request
8080
+ ),
8081
+ channelUnavailableReject(ci.channel, "during newSession")
8082
+ ]),
7437
8083
  initTimeoutMs,
7438
8084
  "newSession"
7439
8085
  );
@@ -7454,6 +8100,10 @@ function createAcpSessionBridge(opts) {
7454
8100
  }
7455
8101
  throw err;
7456
8102
  }
8103
+ await Promise.resolve();
8104
+ if (ci.isDying) {
8105
+ throw new BridgeChannelClosedError("after newSession");
8106
+ }
7457
8107
  if (shuttingDown) {
7458
8108
  throw new Error("AcpSessionBridge is shutting down");
7459
8109
  }
@@ -7772,13 +8422,25 @@ function createAcpSessionBridge(opts) {
7772
8422
  __name(applyApprovalMode, "applyApprovalMode");
7773
8423
  async function applyApprovalModeForAttach(entry, mode, clientId) {
7774
8424
  try {
7775
- await applyApprovalMode(entry, mode, false, clientId);
8425
+ const result = await applyApprovalMode(entry, mode, false, clientId);
8426
+ return result.previous;
7776
8427
  } catch (err) {
7777
8428
  await rollbackAttachRegistration(entry, clientId);
7778
8429
  throw err;
7779
8430
  }
7780
8431
  }
7781
8432
  __name(applyApprovalModeForAttach, "applyApprovalModeForAttach");
8433
+ async function rollbackApprovalModeForRejectedAttach(entry, previous, clientId) {
8434
+ if (byId.get(entry.sessionId) !== entry) return;
8435
+ try {
8436
+ await applyApprovalMode(entry, previous, false, clientId);
8437
+ } catch (err) {
8438
+ writeStderrLine(
8439
+ `attach: failed to restore approval mode for session ${entry.sessionId}: ${extractErrorMessage(err)}`
8440
+ );
8441
+ }
8442
+ }
8443
+ __name(rollbackApprovalModeForRejectedAttach, "rollbackApprovalModeForRejectedAttach");
7782
8444
  const cancelPendingForSession = /* @__PURE__ */ __name((sessionId) => {
7783
8445
  permissionMediator.forgetSession(sessionId);
7784
8446
  byId.get(sessionId)?.pendingPermissionIds.clear();
@@ -7786,11 +8448,10 @@ function createAcpSessionBridge(opts) {
7786
8448
  }, "cancelPendingForSession");
7787
8449
  const getTransportClosedReject = /* @__PURE__ */ __name((entry) => {
7788
8450
  if (!entry.transportClosedReject) {
7789
- entry.transportClosedReject = entry.channel.exited.then(() => {
7790
- throw new BridgeChannelClosedError(
7791
- `mid-request (session ${entry.sessionId})`
7792
- );
7793
- });
8451
+ entry.transportClosedReject = channelUnavailableReject(
8452
+ entry.channel,
8453
+ `mid-request (session ${entry.sessionId})`
8454
+ );
7794
8455
  }
7795
8456
  return entry.transportClosedReject;
7796
8457
  }, "getTransportClosedReject");
@@ -7818,6 +8479,28 @@ function createAcpSessionBridge(opts) {
7818
8479
  }
7819
8480
  return void 0;
7820
8481
  }, "channelInfoForEntry");
8482
+ const assertAttachableSessionEntry = /* @__PURE__ */ __name((sessionId, entry) => {
8483
+ if (byId.get(sessionId) !== entry) {
8484
+ throw new SessionNotFoundError(
8485
+ sessionId,
8486
+ "The session channel is unavailable; retry after teardown completes"
8487
+ );
8488
+ }
8489
+ if (isClosingOrAuthorizingClose(entry)) {
8490
+ throw new SessionNotFoundError(
8491
+ sessionId,
8492
+ "The session is closing; retry after close completes",
8493
+ "session_closing"
8494
+ );
8495
+ }
8496
+ const owner = channelInfoForEntry(entry);
8497
+ if (!owner || owner.isDying) {
8498
+ throw new SessionNotFoundError(
8499
+ sessionId,
8500
+ "The session channel is unavailable; retry after teardown completes"
8501
+ );
8502
+ }
8503
+ }, "assertAttachableSessionEntry");
7821
8504
  const assertLivePromptEntry = /* @__PURE__ */ __name((sessionId, entry) => {
7822
8505
  const info = channelInfoForEntry(entry);
7823
8506
  if (byId.get(sessionId) !== entry || !info || info.isDying) {
@@ -7826,9 +8509,10 @@ function createAcpSessionBridge(opts) {
7826
8509
  }, "assertLivePromptEntry");
7827
8510
  const getChannelClosedReject = /* @__PURE__ */ __name((info) => {
7828
8511
  if (!info.statusClosedReject) {
7829
- info.statusClosedReject = info.channel.exited.then(() => {
7830
- throw new BridgeChannelClosedError("mid-request (workspace status)");
7831
- });
8512
+ info.statusClosedReject = channelUnavailableReject(
8513
+ info.channel,
8514
+ "mid-request (workspace status)"
8515
+ );
7832
8516
  }
7833
8517
  return info.statusClosedReject;
7834
8518
  }, "getChannelClosedReject");
@@ -8039,7 +8723,7 @@ function createAcpSessionBridge(opts) {
8039
8723
  `ACP session close channel unavailable for ${entry.sessionId}`
8040
8724
  );
8041
8725
  }
8042
- return;
8726
+ return false;
8043
8727
  }
8044
8728
  try {
8045
8729
  const closeRequest = entry.connection.extMethod(
@@ -8051,7 +8735,7 @@ function createAcpSessionBridge(opts) {
8051
8735
  }
8052
8736
  );
8053
8737
  const observedCloseRequest = opts2?.timeoutMs ? withTimeout(closeRequest, opts2.timeoutMs, label) : closeRequest;
8054
- await Promise.race([
8738
+ const response = await Promise.race([
8055
8739
  opts2?.throwOnFailure === true ? observedCloseRequest : withTimeout(
8056
8740
  observedCloseRequest,
8057
8741
  initTimeoutMs,
@@ -8059,6 +8743,7 @@ function createAcpSessionBridge(opts) {
8059
8743
  ),
8060
8744
  getTransportClosedReject(entry)
8061
8745
  ]);
8746
+ return response["closed"] === true;
8062
8747
  } catch (err) {
8063
8748
  writeStderrLine(
8064
8749
  `qwen serve: ${label} ACP session close notification failed for session ${JSON.stringify(entry.sessionId)}: ${String(
@@ -8068,6 +8753,7 @@ function createAcpSessionBridge(opts) {
8068
8753
  if (opts2?.throwOnFailure === true) {
8069
8754
  throw err;
8070
8755
  }
8756
+ return false;
8071
8757
  }
8072
8758
  }, "notifyAgentSessionClose");
8073
8759
  const broadcastWorkspaceEvent = /* @__PURE__ */ __name((envelope, skipSessionId) => {
@@ -8118,7 +8804,34 @@ function createAcpSessionBridge(opts) {
8118
8804
  teeServeDebugLine(
8119
8805
  `replay window evicted ${JSON.stringify(eviction)}`
8120
8806
  );
8121
- }, "onReplayWindowEviction")
8807
+ }, "onReplayWindowEviction"),
8808
+ // Adaptive growth: the engine asks before evicting past its caps.
8809
+ // The policy accounts growth across this bridge's live sessions
8810
+ // from every session's CURRENT journal cap (stateless — no ledger
8811
+ // to reconcile when a session is reaped), so granted headroom dies
8812
+ // with its session.
8813
+ ...journalGrowthPolicy ? {
8814
+ onJournalGrowth: /* @__PURE__ */ __name((current) => {
8815
+ const allSessionLimits = journalGrowthSessionLimits ? [...journalGrowthSessionLimits()] : journalSessionLimits();
8816
+ if (!byId.has(sessionId) && !pendingRestoreEvents.has(sessionId)) {
8817
+ allSessionLimits.push({
8818
+ limitBytes: current.maxBytes,
8819
+ baselineBytes: maxJournalBytes
8820
+ });
8821
+ }
8822
+ const grant = journalGrowthPolicy.grant({
8823
+ currentMaxEvents: current.maxEvents,
8824
+ currentMaxBytes: current.maxBytes,
8825
+ allSessionLimits
8826
+ });
8827
+ if (grant) {
8828
+ teeServeDebugLine(
8829
+ `live journal growth session=${JSON.stringify(sessionId)}: ${current.maxBytes} -> ${grant.maxBytes} bytes, ${current.maxEvents} -> ${grant.maxEvents} entries`
8830
+ );
8831
+ }
8832
+ return grant;
8833
+ }, "onJournalGrowth")
8834
+ } : {}
8122
8835
  }),
8123
8836
  {
8124
8837
  // Fired once, on the FIRST ingest/seed failure (the bus keeps the
@@ -8394,18 +9107,19 @@ function createAcpSessionBridge(opts) {
8394
9107
  }
8395
9108
  return typeof maybe.message === "string" && maybe.message === `Resource not found: ${expectedUri}`;
8396
9109
  }, "isAcpSessionResourceNotFound");
8397
- const replayFieldsFor = /* @__PURE__ */ __name((entry, action) => {
9110
+ const replayFieldsFor = /* @__PURE__ */ __name((entry, action, liveReplayMode = "full") => {
8398
9111
  const replayStatus = action === "load" && entry.restoreReplayPartial === true ? {
8399
9112
  partial: true,
8400
9113
  ...typeof entry.restoreReplayError === "string" ? { replayError: entry.restoreReplayError } : {}
8401
9114
  } : {};
8402
9115
  const eventEpoch = entry.events.epoch;
8403
- const snapshot = entry.events.snapshotReplay();
9116
+ const snapshot = entry.events.snapshotReplay(liveReplayMode);
8404
9117
  if (!snapshot) {
8405
9118
  return {
8406
9119
  lastEventId: entry.events.lastEventId,
8407
9120
  eventEpoch,
8408
- ...replayStatus
9121
+ ...replayStatus,
9122
+ ...action === "load" && entry.restoreHistoryAnchorRecordId !== void 0 ? { historyAnchorRecordId: entry.restoreHistoryAnchorRecordId } : {}
8409
9123
  };
8410
9124
  }
8411
9125
  if (action === "load") {
@@ -8422,7 +9136,8 @@ function createAcpSessionBridge(opts) {
8422
9136
  eventEpoch,
8423
9137
  ...replayStatus,
8424
9138
  ...snapshot.degraded ? { replayDegraded: true } : {},
8425
- ...entry.restoreHistoryHasMore === true ? { historyHasMore: true } : {}
9139
+ ...entry.restoreHistoryHasMore === true ? { historyHasMore: true } : {},
9140
+ ...entry.restoreHistoryAnchorRecordId !== void 0 ? { historyAnchorRecordId: entry.restoreHistoryAnchorRecordId } : {}
8426
9141
  };
8427
9142
  }
8428
9143
  return { lastEventId: snapshot.lastEventId, eventEpoch, ...replayStatus };
@@ -8488,10 +9203,11 @@ function createAcpSessionBridge(opts) {
8488
9203
  }
8489
9204
  }
8490
9205
  __name(requestSessionTranscriptPage, "requestSessionTranscriptPage");
8491
- async function refreshedReplayFieldsFor(entry, historyPageSize) {
9206
+ async function refreshedReplayFieldsFor(entry, historyPageSize, liveReplayMode) {
8492
9207
  for (let attempt = 0; attempt < 2; attempt++) {
8493
9208
  try {
8494
9209
  const lastEventId = entry.events.lastEventId;
9210
+ const eventEpoch = entry.events.epoch;
8495
9211
  const seenCursors = /* @__PURE__ */ new Set();
8496
9212
  let emptyPageCount = 0;
8497
9213
  let cursor;
@@ -8512,11 +9228,23 @@ function createAcpSessionBridge(opts) {
8512
9228
  cursor = nextCursor;
8513
9229
  if (cursor !== void 0) seenCursors.add(cursor);
8514
9230
  } while (page.events.length === 0 && page.hasMore && cursor !== void 0 && page.partial !== true && page.replayError === void 0);
8515
- if (byId.get(entry.sessionId) === entry && !entry.promptActive && entry.events.lastEventId === lastEventId) {
9231
+ if (byId.get(entry.sessionId) === entry && !entry.promptActive && entry.events.epoch === eventEpoch && entry.events.lastEventId === lastEventId) {
9232
+ let compactedReplay = page.events;
9233
+ const turnErrorEvent = entry.turnErrorEvent;
9234
+ if (turnErrorEvent) {
9235
+ const journal = entry.events.liveJournalSnapshot() ?? [];
9236
+ const hasNewerTurnContent = journal.some(
9237
+ isRefreshAppendTurnContent
9238
+ );
9239
+ if (!hasNewerTurnContent) {
9240
+ compactedReplay = [...page.events, turnErrorEvent];
9241
+ }
9242
+ }
8516
9243
  return {
8517
- compactedReplay: page.events,
9244
+ compactedReplay,
8518
9245
  liveJournal: [],
8519
9246
  lastEventId,
9247
+ eventEpoch,
8520
9248
  ...page.partial === true ? { partial: true } : {},
8521
9249
  ...page.replayError !== void 0 ? { replayError: page.replayError } : {},
8522
9250
  ...page.hasMore ? { historyHasMore: true } : {}
@@ -8526,7 +9254,7 @@ function createAcpSessionBridge(opts) {
8526
9254
  break;
8527
9255
  }
8528
9256
  }
8529
- return replayFieldsFor(entry, "load");
9257
+ return replayFieldsFor(entry, "load", liveReplayMode);
8530
9258
  }
8531
9259
  __name(refreshedReplayFieldsFor, "refreshedReplayFieldsFor");
8532
9260
  function transcriptEventRecordId(event) {
@@ -8580,33 +9308,50 @@ function createAcpSessionBridge(opts) {
8580
9308
  );
8581
9309
  }
8582
9310
  const historyReplay = action === "load" ? req.historyReplay ?? "stream" : "stream";
9311
+ const historyPageSize = action === "load" && historyReplay === "response" ? req.historyPageSize : void 0;
9312
+ const requestedLiveReplayMode = req.liveReplayMode;
9313
+ if (requestedLiveReplayMode !== void 0 && requestedLiveReplayMode !== "full" && requestedLiveReplayMode !== "summary") {
9314
+ throw new Error(
9315
+ `Invalid liveReplayMode: ${JSON.stringify(requestedLiveReplayMode)}`
9316
+ );
9317
+ }
9318
+ const liveReplayMode = action === "load" ? requestedLiveReplayMode ?? "full" : "full";
9319
+ if (historyPageSize !== void 0 && (!Number.isSafeInteger(historyPageSize) || historyPageSize < 1 || historyPageSize > SESSION_TRANSCRIPT_MAX_LIMIT)) {
9320
+ throw new Error(
9321
+ `Invalid historyPageSize; expected 1..${SESSION_TRANSCRIPT_MAX_LIMIT}`
9322
+ );
9323
+ }
8583
9324
  const hideInheritedHistory = action === "load" && req.hideInheritedHistory === true;
8584
9325
  const existing = byId.get(req.sessionId);
8585
9326
  if (existing) {
8586
- if (isClosingOrAuthorizingClose(existing)) {
8587
- throw new SessionNotFoundError(
8588
- req.sessionId,
8589
- "The session is closing; retry after close completes",
8590
- "session_closing"
8591
- );
8592
- }
8593
- const replayFields = action === "load" && req.historyPageSize !== void 0 ? await refreshedReplayFieldsFor(existing, req.historyPageSize) : replayFieldsFor(existing, action);
9327
+ assertAttachableSessionEntry(req.sessionId, existing);
9328
+ const replayFields = historyPageSize !== void 0 ? await refreshedReplayFieldsFor(
9329
+ existing,
9330
+ historyPageSize,
9331
+ liveReplayMode
9332
+ ) : replayFieldsFor(existing, action, liveReplayMode);
8594
9333
  const historyAnchorRecordId = action === "load" ? await resolveHistoryAnchorRecordId(existing, replayFields) : void 0;
8595
- if (byId.get(req.sessionId) !== existing) {
8596
- throw new SessionNotFoundError(req.sessionId);
8597
- }
8598
- if (isClosingOrAuthorizingClose(existing)) {
8599
- throw new SessionNotFoundError(
8600
- req.sessionId,
8601
- "The session is closing; retry after close completes",
8602
- "session_closing"
8603
- );
8604
- }
9334
+ assertAttachableSessionEntry(req.sessionId, existing);
8605
9335
  existing.attachCount++;
8606
9336
  const clientId = registerClient(existing, req.clientId);
8607
9337
  recordAttachRef(existing, clientId);
8608
9338
  if (req.approvalMode) {
8609
- await applyApprovalModeForAttach(existing, req.approvalMode, clientId);
9339
+ const previousApprovalMode = await applyApprovalModeForAttach(
9340
+ existing,
9341
+ req.approvalMode,
9342
+ clientId
9343
+ );
9344
+ try {
9345
+ assertAttachableSessionEntry(req.sessionId, existing);
9346
+ } catch (error) {
9347
+ await rollbackApprovalModeForRejectedAttach(
9348
+ existing,
9349
+ previousApprovalMode,
9350
+ clientId
9351
+ );
9352
+ await rollbackAttachRegistration(existing, clientId);
9353
+ throw error;
9354
+ }
8610
9355
  }
8611
9356
  return {
8612
9357
  sessionId: existing.sessionId,
@@ -8630,7 +9375,7 @@ function createAcpSessionBridge(opts) {
8630
9375
  }
8631
9376
  const inFlight = inFlightRestores.get(req.sessionId);
8632
9377
  if (inFlight) {
8633
- if (inFlight.lifecycle.phase === "abandoned" || action !== inFlight.action || historyReplay !== inFlight.historyReplay || hideInheritedHistory !== inFlight.hideInheritedHistory) {
9378
+ if (inFlight.lifecycle.phase === "abandoned" || action !== inFlight.action || historyReplay !== inFlight.historyReplay || historyPageSize !== inFlight.historyPageSize || inFlight.liveReplayMode === "summary" && liveReplayMode === "full" || hideInheritedHistory !== inFlight.hideInheritedHistory) {
8634
9379
  const abandoned = inFlight.lifecycle.phase === "abandoned";
8635
9380
  throw new RestoreInProgressError(
8636
9381
  req.sessionId,
@@ -8658,17 +9403,52 @@ function createAcpSessionBridge(opts) {
8658
9403
  "the agent child likely crashed during session restore \u2014 retry to restore the session"
8659
9404
  );
8660
9405
  }
9406
+ try {
9407
+ assertAttachableSessionEntry(restored.sessionId, entry);
9408
+ } catch (error) {
9409
+ inFlight.coalesceState.count--;
9410
+ entry.attachCount = Math.max(0, entry.attachCount - 1);
9411
+ throw error;
9412
+ }
9413
+ const waiterReplayFields = liveReplayMode !== inFlight.liveReplayMode ? historyPageSize !== void 0 ? await refreshedReplayFieldsFor(
9414
+ entry,
9415
+ historyPageSize,
9416
+ liveReplayMode
9417
+ ) : replayFieldsFor(entry, action, liveReplayMode) : void 0;
9418
+ try {
9419
+ assertAttachableSessionEntry(restored.sessionId, entry);
9420
+ } catch (error) {
9421
+ inFlight.coalesceState.count--;
9422
+ entry.attachCount = Math.max(0, entry.attachCount - 1);
9423
+ throw error;
9424
+ }
8661
9425
  const clientId = registerClient(entry, req.clientId);
8662
9426
  recordAttachRef(entry, clientId);
8663
9427
  if (req.approvalMode) {
8664
- await applyApprovalModeForAttach(entry, req.approvalMode, clientId);
9428
+ const previousApprovalMode = await applyApprovalModeForAttach(
9429
+ entry,
9430
+ req.approvalMode,
9431
+ clientId
9432
+ );
9433
+ try {
9434
+ assertAttachableSessionEntry(restored.sessionId, entry);
9435
+ } catch (error) {
9436
+ await rollbackApprovalModeForRejectedAttach(
9437
+ entry,
9438
+ previousApprovalMode,
9439
+ clientId
9440
+ );
9441
+ await rollbackAttachRegistration(entry, clientId);
9442
+ throw error;
9443
+ }
8665
9444
  }
8666
9445
  return {
8667
9446
  ...restored,
8668
9447
  attached: true,
8669
9448
  clientId,
8670
9449
  createdAt: entry.createdAt,
8671
- hasActivePrompt: entry.promptActive
9450
+ hasActivePrompt: entry.promptActive,
9451
+ ...waiterReplayFields ?? {}
8672
9452
  };
8673
9453
  }
8674
9454
  assertFreshSessionsAvailable();
@@ -8825,12 +9605,16 @@ function createAcpSessionBridge(opts) {
8825
9605
  const promise = (async () => {
8826
9606
  pendingRestoreEvents.set(req.sessionId, restoreEvents);
8827
9607
  const restoreChannel = await ensureChannel();
9608
+ if (restoreChannel.isDying) {
9609
+ throw new BridgeChannelClosedError(`before session/${action}`);
9610
+ }
8828
9611
  ci = restoreChannel;
8829
9612
  restoreChannel.pendingRestoreIds.add(req.sessionId);
8830
9613
  restoreChannel.client.markRestoreInFlight(req.sessionId);
8831
- const transportClosed = restoreChannel.channel.exited.then(() => {
8832
- throw new BridgeChannelClosedError(`during session/${action}`);
8833
- });
9614
+ const transportClosed = channelUnavailableReject(
9615
+ restoreChannel.channel,
9616
+ `during session/${action}`
9617
+ );
8834
9618
  transportClosed.catch(() => {
8835
9619
  });
8836
9620
  let state;
@@ -8838,6 +9622,7 @@ function createAcpSessionBridge(opts) {
8838
9622
  let replayPartial;
8839
9623
  let replayError;
8840
9624
  let replayHasMore;
9625
+ let replayAnchorRecordId;
8841
9626
  try {
8842
9627
  const rawRestore = telemetry.withSpan(
8843
9628
  "session.restore",
@@ -8863,8 +9648,8 @@ function createAcpSessionBridge(opts) {
8863
9648
  ...sessionSourceRequestMeta(req.sourceType, req.sourceId),
8864
9649
  ...historyReplay === "response" ? {
8865
9650
  [LOAD_REPLAY_MODE_META_KEY]: LOAD_REPLAY_BULK_MODE,
8866
- ...req.historyPageSize !== void 0 ? {
8867
- [LOAD_REPLAY_PAGE_SIZE_META_KEY]: req.historyPageSize
9651
+ ...historyPageSize !== void 0 ? {
9652
+ [LOAD_REPLAY_PAGE_SIZE_META_KEY]: historyPageSize
8868
9653
  } : {}
8869
9654
  } : {},
8870
9655
  ...hideInheritedHistory ? { [LOAD_REPLAY_HIDE_INHERITED_META_KEY]: true } : {}
@@ -8948,6 +9733,7 @@ function createAcpSessionBridge(opts) {
8948
9733
  replayPartial = extracted.partial;
8949
9734
  replayError = extracted.replayError;
8950
9735
  replayHasMore = extracted.hasMore === true ? true : void 0;
9736
+ replayAnchorRecordId = extracted.anchorRecordId;
8951
9737
  }
8952
9738
  } catch (err) {
8953
9739
  if (err instanceof SessionRestoreTimeoutError) throw err;
@@ -8976,24 +9762,20 @@ function createAcpSessionBridge(opts) {
8976
9762
  const racedEntry = byId.get(req.sessionId);
8977
9763
  if (racedEntry) {
8978
9764
  restoreEvents.close();
8979
- if (isClosingOrAuthorizingClose(racedEntry)) {
8980
- throw new SessionNotFoundError(
8981
- req.sessionId,
8982
- "The session is closing; retry after close completes",
8983
- "session_closing"
8984
- );
8985
- }
9765
+ assertAttachableSessionEntry(req.sessionId, racedEntry);
8986
9766
  racedEntry.attachCount += 1 + coalesceState.count;
8987
9767
  const clientId2 = registerClient(racedEntry, req.clientId);
8988
9768
  recordAttachRef(racedEntry, clientId2);
8989
9769
  if (req.approvalMode) {
9770
+ let previousApprovalMode;
8990
9771
  try {
8991
- await applyApprovalMode(
9772
+ const result = await applyApprovalMode(
8992
9773
  racedEntry,
8993
9774
  req.approvalMode,
8994
9775
  false,
8995
9776
  clientId2
8996
9777
  );
9778
+ previousApprovalMode = result.previous;
8997
9779
  } catch (err) {
8998
9780
  await rollbackAttachRegistration(
8999
9781
  racedEntry,
@@ -9002,6 +9784,21 @@ function createAcpSessionBridge(opts) {
9002
9784
  );
9003
9785
  throw err;
9004
9786
  }
9787
+ try {
9788
+ assertAttachableSessionEntry(req.sessionId, racedEntry);
9789
+ } catch (error) {
9790
+ await rollbackApprovalModeForRejectedAttach(
9791
+ racedEntry,
9792
+ previousApprovalMode,
9793
+ clientId2
9794
+ );
9795
+ await rollbackAttachRegistration(
9796
+ racedEntry,
9797
+ clientId2,
9798
+ 1 + coalesceState.count
9799
+ );
9800
+ throw error;
9801
+ }
9005
9802
  }
9006
9803
  return {
9007
9804
  sessionId: racedEntry.sessionId,
@@ -9014,7 +9811,7 @@ function createAcpSessionBridge(opts) {
9014
9811
  ...racedEntry.sourceId !== void 0 ? { sourceId: racedEntry.sourceId } : {},
9015
9812
  state: racedEntry.restoreState ?? {},
9016
9813
  hasActivePrompt: racedEntry.promptActive,
9017
- ...replayFieldsFor(racedEntry, action)
9814
+ ...replayFieldsFor(racedEntry, action, liveReplayMode)
9018
9815
  };
9019
9816
  }
9020
9817
  const entry = createSessionEntry(
@@ -9045,6 +9842,9 @@ function createAcpSessionBridge(opts) {
9045
9842
  if (replayHasMore === true) {
9046
9843
  entry.restoreHistoryHasMore = true;
9047
9844
  }
9845
+ if (replayAnchorRecordId !== void 0) {
9846
+ entry.restoreHistoryAnchorRecordId = replayAnchorRecordId;
9847
+ }
9048
9848
  seedSnapshotCaches(entry, publicState);
9049
9849
  const artifactRestoreWarnings = await entry.artifacts.restore(
9050
9850
  restoredArtifactSnapshot
@@ -9063,14 +9863,16 @@ function createAcpSessionBridge(opts) {
9063
9863
  await ci.client.seedSessionUpdates(entry, replayUpdates, {
9064
9864
  ingestArtifacts: restoredArtifactSnapshot === void 0 || artifactRestoreFailed
9065
9865
  });
9066
- if (req.historyPageSize !== void 0 && entry.events.snapshotReplay()?.compactedTurns.some((event) => event.type === "history_truncated")) {
9866
+ if (historyPageSize !== void 0 && entry.events.snapshotReplay()?.compactedTurns.some((event) => event.type === "history_truncated")) {
9067
9867
  entry.restoreHistoryHasMore = true;
9068
9868
  }
9069
9869
  ci.client.drainEarlyEvents(entry.sessionId, entry);
9070
9870
  }
9871
+ assertAttachableSessionEntry(req.sessionId, entry);
9071
9872
  const clientId = registerClient(entry, req.clientId);
9072
9873
  if (req.approvalMode) {
9073
9874
  await applyApprovalModeForAttach(entry, req.approvalMode, clientId);
9875
+ assertAttachableSessionEntry(req.sessionId, entry);
9074
9876
  }
9075
9877
  entry.attachCount = coalesceState.count;
9076
9878
  registeredEntry = entry;
@@ -9085,7 +9887,7 @@ function createAcpSessionBridge(opts) {
9085
9887
  state: publicState,
9086
9888
  ...artifactRestoreWarnings.length > 0 ? { artifactWarnings: artifactRestoreWarnings } : {},
9087
9889
  hasActivePrompt: entry.promptActive,
9088
- ...replayFieldsFor(entry, action)
9890
+ ...replayFieldsFor(entry, action, liveReplayMode)
9089
9891
  };
9090
9892
  })().finally(async () => {
9091
9893
  if (restoreLifecycle.phase === "abandoned") return;
@@ -9147,6 +9949,8 @@ function createAcpSessionBridge(opts) {
9147
9949
  inFlightRestores.set(req.sessionId, {
9148
9950
  action,
9149
9951
  historyReplay,
9952
+ ...historyPageSize !== void 0 ? { historyPageSize } : {},
9953
+ liveReplayMode,
9150
9954
  hideInheritedHistory,
9151
9955
  publicPromise: promise,
9152
9956
  settlementPromise,
@@ -9192,15 +9996,21 @@ function createAcpSessionBridge(opts) {
9192
9996
  `qwen serve: closeSession channelInfoForEntry returned undefined for session ${JSON.stringify(sessionId)} \u2014 channel cleanup skipped (entry's channel already torn down)`
9193
9997
  );
9194
9998
  }
9999
+ let agentSessionClosed = false;
9195
10000
  try {
9196
10001
  permissionMediator.forgetSession(sessionId);
9197
10002
  entry.pendingPermissionIds.clear();
9198
10003
  entry.pendingInteractions.clear();
9199
- await notifyAgentSessionClose(entry, ci, "closeSession", {
9200
- throwOnFailure: true,
9201
- requireFlush: closeOpts?.requireAgentClose === true,
9202
- ...closeOpts?.agentCloseTimeoutMs !== void 0 ? { timeoutMs: closeOpts.agentCloseTimeoutMs } : {}
9203
- });
10004
+ agentSessionClosed = await notifyAgentSessionClose(
10005
+ entry,
10006
+ ci,
10007
+ "closeSession",
10008
+ {
10009
+ throwOnFailure: true,
10010
+ requireFlush: closeOpts?.requireAgentClose === true,
10011
+ ...closeOpts?.agentCloseTimeoutMs !== void 0 ? { timeoutMs: closeOpts.agentCloseTimeoutMs } : {}
10012
+ }
10013
+ );
9204
10014
  } catch (error) {
9205
10015
  if (isDefinitiveAcpRequestError(error)) {
9206
10016
  entry.closing = false;
@@ -9254,16 +10064,18 @@ function createAcpSessionBridge(opts) {
9254
10064
  } catch {
9255
10065
  }
9256
10066
  entry.events.close();
9257
- try {
9258
- await telemetry.withSpan(
9259
- "session.close.cancel_active_prompt",
9260
- {
9261
- "qwen-code.daemon.bridge.operation": "session.close.cancel_active_prompt",
9262
- "session.id": sessionId
9263
- },
9264
- async () => await entry.connection.cancel({ sessionId })
9265
- );
9266
- } catch {
10067
+ if (!agentSessionClosed) {
10068
+ try {
10069
+ await telemetry.withSpan(
10070
+ "session.close.cancel_active_prompt",
10071
+ {
10072
+ "qwen-code.daemon.bridge.operation": "session.close.cancel_active_prompt",
10073
+ "session.id": sessionId
10074
+ },
10075
+ async () => await entry.connection.cancel({ sessionId })
10076
+ );
10077
+ } catch {
10078
+ }
9267
10079
  }
9268
10080
  if (ci && hasNoChannelWork(ci)) {
9269
10081
  await reapPendingEmptyChannel(ci);
@@ -9323,6 +10135,10 @@ function createAcpSessionBridge(opts) {
9323
10135
  compactedReplayMaxBytes,
9324
10136
  maxJournalEvents,
9325
10137
  maxJournalBytes,
10138
+ journalGrowth: journalGrowthPoolBytes !== void 0 ? {
10139
+ poolBytes: journalGrowthPoolBytes,
10140
+ hardCapBytes: JOURNAL_GROWTH_HARD_CAP_BYTES
10141
+ } : null,
9326
10142
  channelIdleTimeoutMs: resolvedChannelIdleTimeoutMs(),
9327
10143
  sessionIdleTimeoutMs
9328
10144
  },
@@ -9330,22 +10146,27 @@ function createAcpSessionBridge(opts) {
9330
10146
  pendingPermissionCount: permissionMediator.pendingCount,
9331
10147
  channelLive: !!liveChannelInfo(),
9332
10148
  permissionPolicy: permissionMediator.policy,
9333
- sessions: [...byId.values()].map((entry) => ({
9334
- sessionId: entry.sessionId,
9335
- workspaceCwd: entry.workspaceCwd,
9336
- createdAt: entry.createdAt,
9337
- ...entry.displayName ? { displayName: entry.displayName } : {},
9338
- clientCount: entry.clientIds.size,
9339
- subscriberCount: entry.events.subscriberCount,
9340
- attachCount: entry.attachCount,
9341
- pendingPromptCount: entry.pendingPromptCount,
9342
- pendingPermissionCount: entry.pendingPermissionIds.size,
9343
- hasActivePrompt: entry.promptActive,
9344
- lastEventId: entry.events.lastEventId,
9345
- ...entry.sessionLastSeenAt !== void 0 ? { lastSeenAt: entry.sessionLastSeenAt } : {},
9346
- ...entry.currentModelId ? { currentModelId: entry.currentModelId } : {},
9347
- ...entry.currentApprovalMode ? { currentApprovalMode: entry.currentApprovalMode } : {}
9348
- }))
10149
+ sessions: [...byId.values()].map((entry) => {
10150
+ const journalLimits = entry.events.journalLimits();
10151
+ return {
10152
+ sessionId: entry.sessionId,
10153
+ workspaceCwd: entry.workspaceCwd,
10154
+ createdAt: entry.createdAt,
10155
+ ...entry.displayName ? { displayName: entry.displayName } : {},
10156
+ clientCount: entry.clientIds.size,
10157
+ subscriberCount: entry.events.subscriberCount,
10158
+ attachCount: entry.attachCount,
10159
+ pendingPromptCount: entry.pendingPromptCount,
10160
+ pendingPermissionCount: entry.pendingPermissionIds.size,
10161
+ hasActivePrompt: entry.promptActive,
10162
+ lastEventId: entry.events.lastEventId,
10163
+ ...entry.sessionLastSeenAt !== void 0 ? { lastSeenAt: entry.sessionLastSeenAt } : {},
10164
+ ...entry.currentModelId ? { currentModelId: entry.currentModelId } : {},
10165
+ ...entry.currentApprovalMode ? { currentApprovalMode: entry.currentApprovalMode } : {},
10166
+ maxJournalEvents: journalLimits?.maxEvents ?? maxJournalEvents,
10167
+ maxJournalBytes: journalLimits?.maxBytes ?? maxJournalBytes
10168
+ };
10169
+ })
9349
10170
  };
9350
10171
  },
9351
10172
  get sessionCount() {
@@ -9447,13 +10268,7 @@ function createAcpSessionBridge(opts) {
9447
10268
  if (effectiveScope === "single") {
9448
10269
  const existing = defaultEntry;
9449
10270
  if (existing) {
9450
- if (isClosingOrAuthorizingClose(existing)) {
9451
- throw new SessionNotFoundError(
9452
- existing.sessionId,
9453
- "The session is closing; retry after close completes",
9454
- "session_closing"
9455
- );
9456
- }
10271
+ assertAttachableSessionEntry(existing.sessionId, existing);
9457
10272
  existing.attachCount++;
9458
10273
  const clientId = registerClient(existing, req.clientId);
9459
10274
  recordAttachRef(existing, clientId);
@@ -9466,13 +10281,27 @@ function createAcpSessionBridge(opts) {
9466
10281
  ).catch(() => {
9467
10282
  });
9468
10283
  }
10284
+ let previousApprovalMode;
9469
10285
  if (req.approvalMode) {
9470
- await applyApprovalModeForAttach(
10286
+ previousApprovalMode = await applyApprovalModeForAttach(
9471
10287
  existing,
9472
10288
  req.approvalMode,
9473
10289
  clientId
9474
10290
  );
9475
10291
  }
10292
+ try {
10293
+ assertAttachableSessionEntry(existing.sessionId, existing);
10294
+ } catch (error) {
10295
+ if (previousApprovalMode !== void 0) {
10296
+ await rollbackApprovalModeForRejectedAttach(
10297
+ existing,
10298
+ previousApprovalMode,
10299
+ clientId
10300
+ );
10301
+ }
10302
+ await rollbackAttachRegistration(existing, clientId);
10303
+ throw error;
10304
+ }
9476
10305
  return {
9477
10306
  sessionId: existing.sessionId,
9478
10307
  workspaceCwd: existing.workspaceCwd,
@@ -9489,13 +10318,14 @@ function createAcpSessionBridge(opts) {
9489
10318
  if (inFlight) {
9490
10319
  const session = await inFlight;
9491
10320
  const attachedEntry = byId.get(session.sessionId);
9492
- if (attachedEntry) attachedEntry.attachCount++;
9493
10321
  if (!attachedEntry) {
9494
10322
  throw new SessionNotFoundError(
9495
10323
  session.sessionId,
9496
10324
  "the agent child likely crashed during initialization \u2014 retry to spawn a new session"
9497
10325
  );
9498
10326
  }
10327
+ assertAttachableSessionEntry(session.sessionId, attachedEntry);
10328
+ attachedEntry.attachCount++;
9499
10329
  const clientId = registerClient(attachedEntry, req.clientId);
9500
10330
  recordAttachRef(attachedEntry, clientId);
9501
10331
  if (req.modelServiceId) {
@@ -9507,13 +10337,27 @@ function createAcpSessionBridge(opts) {
9507
10337
  ).catch(() => {
9508
10338
  });
9509
10339
  }
10340
+ let previousApprovalMode;
9510
10341
  if (req.approvalMode) {
9511
- await applyApprovalModeForAttach(
10342
+ previousApprovalMode = await applyApprovalModeForAttach(
9512
10343
  attachedEntry,
9513
10344
  req.approvalMode,
9514
10345
  clientId
9515
10346
  );
9516
10347
  }
10348
+ try {
10349
+ assertAttachableSessionEntry(session.sessionId, attachedEntry);
10350
+ } catch (error) {
10351
+ if (previousApprovalMode !== void 0) {
10352
+ await rollbackApprovalModeForRejectedAttach(
10353
+ attachedEntry,
10354
+ previousApprovalMode,
10355
+ clientId
10356
+ );
10357
+ }
10358
+ await rollbackAttachRegistration(attachedEntry, clientId);
10359
+ throw error;
10360
+ }
9517
10361
  return {
9518
10362
  ...session,
9519
10363
  attached: true,
@@ -9662,12 +10506,19 @@ function createAcpSessionBridge(opts) {
9662
10506
  );
9663
10507
  }
9664
10508
  }
10509
+ const channelDisplayText = getChannelPromptDisplayText(
10510
+ entry,
10511
+ context?.promptDisplayText
10512
+ );
10513
+ const pendingText = channelDisplayText === void 0 ? extractPromptText(req.prompt) : channelDisplayText || (req.prompt.some(
10514
+ (block) => isRecord3(block) && block["type"] === "image"
10515
+ ) ? "[image]" : "");
9665
10516
  const pendingEntry = {
9666
10517
  promptId,
9667
10518
  queuedAt,
9668
10519
  ...originatorClientId !== void 0 ? { originatorClientId } : {},
9669
10520
  ...isPromotedMidTurn ? { promotedMidTurn: true } : {},
9670
- text: extractPromptText(req.prompt),
10521
+ text: pendingText,
9671
10522
  abortController: pendingAbort,
9672
10523
  state: isQueued ? "queued" : "running"
9673
10524
  };
@@ -9805,12 +10656,15 @@ function createAcpSessionBridge(opts) {
9805
10656
  delete copy.retry;
9806
10657
  delete copy.delivery;
9807
10658
  const meta = copy._meta && typeof copy._meta === "object" ? { ...copy._meta } : {};
10659
+ const promptDisplayText = channelDisplayText;
9808
10660
  delete meta[DAEMON_RETRY_META_KEY];
9809
10661
  delete meta[INVOCATION_CONTEXT_META_KEY];
9810
10662
  delete meta[PRIVATE_PARENT_CAPABILITY_META_KEY];
9811
10663
  delete meta[DAEMON_CONTINUE_META_KEY];
9812
10664
  delete meta[DAEMON_CHANNEL_DELIVERY_META_KEY];
10665
+ delete meta[DAEMON_PROMPT_DISPLAY_TEXT_META_KEY];
9813
10666
  delete meta[DAEMON_MODEL_PROMPT_META_KEY];
10667
+ delete meta[CHANNEL_PROMPT_META_KEY];
9814
10668
  if (isRetry) {
9815
10669
  meta[DAEMON_RETRY_META_KEY] = true;
9816
10670
  }
@@ -9820,9 +10674,15 @@ function createAcpSessionBridge(opts) {
9820
10674
  if (context?.channelDelivery) {
9821
10675
  meta[DAEMON_CHANNEL_DELIVERY_META_KEY] = context.channelDelivery;
9822
10676
  }
10677
+ if (promptDisplayText !== void 0) {
10678
+ meta[DAEMON_PROMPT_DISPLAY_TEXT_META_KEY] = promptDisplayText;
10679
+ }
9823
10680
  if (modelPrompt !== void 0) {
9824
10681
  meta[DAEMON_MODEL_PROMPT_META_KEY] = modelPrompt;
9825
10682
  }
10683
+ if (context?.channelPrompt === true) {
10684
+ meta[CHANNEL_PROMPT_META_KEY] = true;
10685
+ }
9826
10686
  meta[INVOCATION_CONTEXT_META_KEY] = invocationContext;
9827
10687
  if (Object.keys(meta).length > 0) {
9828
10688
  copy._meta = meta;
@@ -9835,6 +10695,7 @@ function createAcpSessionBridge(opts) {
9835
10695
  entry.activePromptId = pendingEntry.promptId;
9836
10696
  delete entry.cancelBroadcastWithoutPrompt;
9837
10697
  delete entry.turnError;
10698
+ delete entry.turnErrorEvent;
9838
10699
  activePromptCounter++;
9839
10700
  entry.sessionLastSeenAt = Date.now();
9840
10701
  touchActivity();
@@ -9849,7 +10710,8 @@ function createAcpSessionBridge(opts) {
9849
10710
  entry,
9850
10711
  promptRequest,
9851
10712
  pendingEntry.promptId,
9852
- originatorClientId
10713
+ originatorClientId,
10714
+ channelDisplayText
9853
10715
  );
9854
10716
  }
9855
10717
  } catch (echoErr) {
@@ -9881,6 +10743,10 @@ function createAcpSessionBridge(opts) {
9881
10743
  );
9882
10744
  return;
9883
10745
  }
10746
+ if (extractJsonRpcErrorField(err, "errorKind")) {
10747
+ cancelPendingForSession(sessionId);
10748
+ return;
10749
+ }
9884
10750
  writeStderrLine(
9885
10751
  `sendPrompt: forward failed for session ${sessionId}: ${extractErrorMessage(err)}`
9886
10752
  );
@@ -10208,16 +11074,20 @@ function createAcpSessionBridge(opts) {
10208
11074
  releaseFreshSessionReservation(admission);
10209
11075
  }, "releaseAdmissionOnce");
10210
11076
  try {
10211
- const ci = await ensureChannel();
11077
+ assertLivePromptEntry(sessionId, entry);
11078
+ const ci = channelInfoForEntry(entry);
10212
11079
  const result = await withTimeout(
10213
- ci.connection.extMethod(
10214
- isSideTask ? SERVE_CONTROL_EXT_METHODS.sessionSideTask : SERVE_CONTROL_EXT_METHODS.sessionBranch,
10215
- {
10216
- sessionId,
10217
- cwd: boundWorkspace,
10218
- name: req.name
10219
- }
10220
- ),
11080
+ Promise.race([
11081
+ ci.connection.extMethod(
11082
+ isSideTask ? SERVE_CONTROL_EXT_METHODS.sessionSideTask : SERVE_CONTROL_EXT_METHODS.sessionBranch,
11083
+ {
11084
+ sessionId,
11085
+ cwd: boundWorkspace,
11086
+ name: req.name
11087
+ }
11088
+ ),
11089
+ getTransportClosedReject(entry)
11090
+ ]),
10221
11091
  initTimeoutMs,
10222
11092
  isSideTask ? "createSideTaskSession" : "branchSession"
10223
11093
  );
@@ -10253,10 +11123,25 @@ function createAcpSessionBridge(opts) {
10253
11123
  `qwen serve: branchSession load failed for ${result.newSessionId}, attempting cleanup...`
10254
11124
  );
10255
11125
  try {
10256
- await ci.connection.extMethod(
10257
- SERVE_CONTROL_EXT_METHODS.sessionClose,
10258
- { sessionId: result.newSessionId, cwd: boundWorkspace }
10259
- );
11126
+ if (!ci.isDying) {
11127
+ await withTimeout(
11128
+ Promise.race([
11129
+ ci.connection.extMethod(
11130
+ SERVE_CONTROL_EXT_METHODS.sessionClose,
11131
+ {
11132
+ sessionId: result.newSessionId,
11133
+ cwd: boundWorkspace
11134
+ }
11135
+ ),
11136
+ channelUnavailableReject(
11137
+ ci.channel,
11138
+ "during branchSession cleanup"
11139
+ )
11140
+ ]),
11141
+ initTimeoutMs,
11142
+ "branchSession cleanup"
11143
+ );
11144
+ }
10260
11145
  } catch (cleanupErr) {
10261
11146
  writeStderrLine(
10262
11147
  `qwen serve: branchSession cleanup of ${result.newSessionId} failed: ${cleanupErr instanceof Error ? cleanupErr.message : cleanupErr}`
@@ -10352,16 +11237,16 @@ function createAcpSessionBridge(opts) {
10352
11237
  if (entry.promptActive) {
10353
11238
  throw new CdWhilePromptActiveError(sessionId);
10354
11239
  }
10355
- const ci = await ensureChannel();
10356
- const raw = await ci.connection.extMethod(
10357
- SERVE_CONTROL_EXT_METHODS.sessionCd,
10358
- {
11240
+ assertLivePromptEntry(sessionId, entry);
11241
+ const raw = await Promise.race([
11242
+ entry.connection.extMethod(SERVE_CONTROL_EXT_METHODS.sessionCd, {
10359
11243
  sessionId,
10360
11244
  path: req.path,
10361
11245
  ...req.allowedRoots ? { allowedRoots: req.allowedRoots } : {},
10362
11246
  ...req.managedRelocation ? { managedRelocation: req.managedRelocation } : {}
10363
- }
10364
- );
11247
+ }),
11248
+ getTransportClosedReject(entry)
11249
+ ]);
10365
11250
  const extResult = raw;
10366
11251
  if (typeof extResult?.previousCwd !== "string" || typeof extResult?.newCwd !== "string" || !Array.isArray(extResult?.warnings)) {
10367
11252
  throw new Error(
@@ -10894,6 +11779,7 @@ function createAcpSessionBridge(opts) {
10894
11779
  const bootstrapRefreshConnections = /* @__PURE__ */ new Set();
10895
11780
  const refreshSession = /* @__PURE__ */ __name(async (entry, refreshBootstrap) => {
10896
11781
  let inFlight = inFlightExtensionRefreshes.get(entry.sessionId);
11782
+ let created = false;
10897
11783
  if (!inFlight || inFlight.connection !== entry.connection || refreshBootstrap && !inFlight.refreshBootstrap) {
10898
11784
  const promise = (async () => {
10899
11785
  await entry.connection.extMethod(
@@ -10904,27 +11790,36 @@ function createAcpSessionBridge(opts) {
10904
11790
  }
10905
11791
  );
10906
11792
  })();
11793
+ let rejectUnavailable;
11794
+ const unavailable = new Promise((_resolve, reject) => {
11795
+ rejectUnavailable = /* @__PURE__ */ __name(() => reject(
11796
+ new BridgeChannelClosedError("refreshExtensionsForAllSessions")
11797
+ ), "rejectUnavailable");
11798
+ });
10907
11799
  inFlight = {
10908
11800
  connection: entry.connection,
10909
11801
  promise,
11802
+ wait: Promise.race([
11803
+ withTimeout(
11804
+ promise,
11805
+ 3e4,
11806
+ SERVE_CONTROL_EXT_METHODS.workspaceExtensionsRefresh
11807
+ ),
11808
+ unavailable
11809
+ ]),
11810
+ rejectUnavailable,
10910
11811
  refreshBootstrap
10911
11812
  };
10912
11813
  inFlightExtensionRefreshes.set(entry.sessionId, inFlight);
10913
- const clear = /* @__PURE__ */ __name(() => {
10914
- if (inFlightExtensionRefreshes.get(entry.sessionId) === inFlight) {
10915
- inFlightExtensionRefreshes.delete(entry.sessionId);
10916
- }
10917
- }, "clear");
10918
- void promise.then(clear, clear);
11814
+ created = true;
10919
11815
  }
10920
- await Promise.race([
10921
- withTimeout(
10922
- inFlight.promise,
10923
- 3e4,
10924
- SERVE_CONTROL_EXT_METHODS.workspaceExtensionsRefresh
10925
- ),
10926
- getTransportClosedReject(entry)
10927
- ]);
11816
+ const clear = /* @__PURE__ */ __name(() => {
11817
+ if (inFlightExtensionRefreshes.get(entry.sessionId) === inFlight) {
11818
+ inFlightExtensionRefreshes.delete(entry.sessionId);
11819
+ }
11820
+ }, "clear");
11821
+ if (created) void inFlight.promise.then(clear, clear);
11822
+ await inFlight.wait;
10928
11823
  }, "refreshSession");
10929
11824
  const results = await Promise.all(
10930
11825
  sessions.map(async (entry) => {
@@ -11051,6 +11946,29 @@ function createAcpSessionBridge(opts) {
11051
11946
  }
11052
11947
  return response;
11053
11948
  },
11949
+ async setSessionConfigOption(sessionId, req) {
11950
+ const entry = byId.get(sessionId);
11951
+ if (!entry) throw new SessionNotFoundError(sessionId);
11952
+ const info = channelInfoForEntry(entry);
11953
+ if (!info || info.isDying) throw new SessionNotFoundError(sessionId);
11954
+ const normalized = { ...req, sessionId };
11955
+ const transportClosed = getTransportClosedReject(entry);
11956
+ const work = entry.modelChangeQueue.then(
11957
+ () => Promise.race([
11958
+ withTimeout(
11959
+ entry.connection.setSessionConfigOption(normalized),
11960
+ initTimeoutMs,
11961
+ "setSessionConfigOption"
11962
+ ),
11963
+ transportClosed
11964
+ ])
11965
+ );
11966
+ entry.modelChangeQueue = work.then(
11967
+ () => void 0,
11968
+ () => void 0
11969
+ );
11970
+ return await work;
11971
+ },
11054
11972
  async setSessionLanguage(sessionId, params, context) {
11055
11973
  const entry = byId.get(sessionId);
11056
11974
  if (!entry) throw new SessionNotFoundError(sessionId);
@@ -11659,9 +12577,16 @@ function createAcpSessionBridge(opts) {
11659
12577
  });
11660
12578
  const historyOutput = output.length > MAX_SHELL_OUTPUT_FOR_HISTORY ? output.substring(0, MAX_SHELL_OUTPUT_FOR_HISTORY) + "\n... (truncated)" : output;
11661
12579
  try {
11662
- await entry.connection.extMethod(
11663
- SERVE_CONTROL_EXT_METHODS.sessionShellHistory,
11664
- { sessionId, command, output: historyOutput, exitCode }
12580
+ await withTimeout(
12581
+ Promise.race([
12582
+ entry.connection.extMethod(
12583
+ SERVE_CONTROL_EXT_METHODS.sessionShellHistory,
12584
+ { sessionId, command, output: historyOutput, exitCode }
12585
+ ),
12586
+ getTransportClosedReject(entry)
12587
+ ]),
12588
+ initTimeoutMs,
12589
+ "sessionShellHistory"
11665
12590
  );
11666
12591
  } catch (err) {
11667
12592
  writeServeDebugLine(
@@ -12226,6 +13151,7 @@ function createAcpSessionBridge(opts) {
12226
13151
  });
12227
13152
  void (async () => {
12228
13153
  shuttingDown = true;
13154
+ unregisterJournalGrowthSessionLimits?.();
12229
13155
  cancelIdleTimer();
12230
13156
  stopSessionReaper();
12231
13157
  const entries = Array.from(byId.values());