@qwen-code/qwen-code 0.22.2 → 0.22.3-nightly.20260831.3a0c4c6108

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 (480) hide show
  1. package/bundled/computer-use/SKILL.md +3 -3
  2. package/bundled/qc-helper/docs/common-workflow.md +32 -0
  3. package/bundled/qc-helper/docs/configuration/auth.md +6 -6
  4. package/bundled/qc-helper/docs/configuration/model-providers.md +4 -2
  5. package/bundled/qc-helper/docs/configuration/settings.md +47 -44
  6. package/bundled/qc-helper/docs/extension/introduction.md +1 -1
  7. package/bundled/qc-helper/docs/features/approval-mode.md +3 -0
  8. package/bundled/qc-helper/docs/features/auto-mode.md +34 -17
  9. package/bundled/qc-helper/docs/features/channels/dws.md +2 -0
  10. package/bundled/qc-helper/docs/features/channels/overview.md +36 -3
  11. package/bundled/qc-helper/docs/features/code-review.md +5 -5
  12. package/bundled/qc-helper/docs/features/commands.md +41 -0
  13. package/bundled/qc-helper/docs/features/computer-use.md +2 -2
  14. package/bundled/qc-helper/docs/features/hooks.md +6 -2
  15. package/bundled/qc-helper/docs/features/memory.md +1 -0
  16. package/bundled/qc-helper/docs/features/tool-use-summaries.md +1 -1
  17. package/bundled/qc-helper/docs/qwen-serve-deploy-local.md +17 -7
  18. package/bundled/qc-helper/docs/qwen-serve.md +59 -55
  19. package/bundled/review/SKILL.md +90 -31
  20. package/bundled/review/references/persistence.md +7 -3
  21. package/bundled/review/references/posting.md +11 -5
  22. package/chunks/MaxSizedBox-IHRTWGSY.js +115 -0
  23. package/chunks/{StandaloneSessionPicker-AVLI6VJP.js → StandaloneSessionPicker-TLVWVTJ7.js} +88 -85
  24. package/chunks/{acp-startup-profiler-GNYAL6LI.js → acp-startup-profiler-M4X5F3VK.js} +2 -2
  25. package/chunks/{acpAgent-MXEAN54C.js → acpAgent-7I5LLPP3.js} +1563 -407
  26. package/chunks/agent-4Z4NTJXD.js +99 -0
  27. package/chunks/agent-headless-TVUJXQWU.js +89 -0
  28. package/chunks/{anthropicContentGenerator-HGMBACVE.js → anthropicContentGenerator-VSSPG7XV.js} +84 -55
  29. package/chunks/{artifact-tool-5YT4QF7Y.js → artifact-tool-TEYW6I4A.js} +11 -3
  30. package/chunks/{askUserQuestion-4SWJY65V.js → askUserQuestion-PYNBWV63.js} +45 -7
  31. package/chunks/bridge-EVURP4NO.js +122 -0
  32. package/chunks/{ca-7HPYOYSZ.js → ca-BNU7YNDE.js} +3 -0
  33. package/chunks/{channel-management-service-X4AZ6IXX.js → channel-management-service-IDBNYSFW.js} +6 -6
  34. package/chunks/channel-settings-store-MZNXRKVI.js +125 -0
  35. package/chunks/{channel-worker-group-27HMGD5S.js → channel-worker-group-ZLP5SJHT.js} +7 -7
  36. package/chunks/{channel-worker-manager-QEGX646Z.js → channel-worker-manager-FG5377T2.js} +7 -7
  37. package/chunks/{channel-worker-supervisor-UEW2WWCC.js → channel-worker-supervisor-HDVE4ADS.js} +4 -4
  38. package/chunks/{chunk-PPKZ7JOE.js → chunk-22UH7VTP.js} +1 -1
  39. package/chunks/chunk-24FVUD5P.js +49 -0
  40. package/chunks/{chunk-CMHFCLBU.js → chunk-26SIKQIC.js} +1 -1
  41. package/chunks/{chunk-5PA6UEYA.js → chunk-3452WXOK.js} +4 -1
  42. package/chunks/{chunk-SFPGAQUL.js → chunk-373DQUVA.js} +72 -31
  43. package/chunks/{chunk-H2WDGQ6D.js → chunk-3AKCBZVW.js} +3 -3
  44. package/chunks/{chunk-LXIBMVRN.js → chunk-3CZGSTZX.js} +15 -9
  45. package/chunks/{chunk-JVPFTDBK.js → chunk-3EGEBDTW.js} +1 -1
  46. package/chunks/{chunk-K2NQPH5D.js → chunk-3NQCZMUB.js} +79 -5
  47. package/chunks/{chunk-E7REAOTN.js → chunk-47ECGEJC.js} +4 -0
  48. package/chunks/{chunk-WKK5BQNP.js → chunk-4P7PPAHN.js} +45 -421
  49. package/chunks/chunk-4VQBQLIZ.js +293 -0
  50. package/chunks/{chunk-4JWNNLPT.js → chunk-5FGWVPCM.js} +4 -4
  51. package/chunks/{chunk-ZFKOCECU.js → chunk-5ICKESC3.js} +2 -2
  52. package/chunks/{chunk-3I6UTTDX.js → chunk-67AY5D3M.js} +20 -20
  53. package/chunks/chunk-6HUXPLB5.js +110 -0
  54. package/chunks/{chunk-BRVWYMKV.js → chunk-6MBXY6WM.js} +1 -1
  55. package/chunks/{chunk-6LFTG244.js → chunk-6NWPR2EB.js} +19 -9
  56. package/chunks/chunk-6OO7QEWV.js +2581 -0
  57. package/chunks/{chunk-TWSKM647.js → chunk-6VHIWUJP.js} +1 -1
  58. package/chunks/{chunk-RJC5EIKY.js → chunk-6YXNJXQW.js} +7 -5
  59. package/chunks/{chunk-TPI7O7HR.js → chunk-7DDTI7Q3.js} +1 -1
  60. package/chunks/{chunk-KGJGEEVR.js → chunk-7FA2II6K.js} +10 -1
  61. package/chunks/chunk-7J6OTNGO.js +424 -0
  62. package/chunks/{chunk-NIFYWDYN.js → chunk-7TBU7PU2.js} +1 -1
  63. package/chunks/{chunk-3FDFA4MZ.js → chunk-7XICSE62.js} +3 -3
  64. package/chunks/{chunk-V2NDP3I4.js → chunk-7XL4WRXM.js} +2 -2
  65. package/chunks/{chunk-F7TNAPZ4.js → chunk-AAX236AR.js} +45 -11
  66. package/chunks/{chunk-T32W2JHI.js → chunk-ACZ4YRYK.js} +6 -6
  67. package/chunks/chunk-ADJD4LZF.js +210 -0
  68. package/chunks/{chunk-JWALNCLT.js → chunk-AF3QB6OL.js} +1 -1
  69. package/chunks/{chunk-P2SU6ZTI.js → chunk-AI35S34R.js} +3 -3
  70. package/chunks/{chunk-OIP7C4FE.js → chunk-AKNQMSL2.js} +5 -5
  71. package/chunks/{chunk-6CGL7E7G.js → chunk-AN3KFCNH.js} +2 -2
  72. package/chunks/{chunk-ABS25QER.js → chunk-ANVG3BVV.js} +1 -1
  73. package/chunks/chunk-AYYKUUKP.js +972 -0
  74. package/chunks/chunk-B2RIIK3K.js +346 -0
  75. package/chunks/{chunk-F5SZP77N.js → chunk-BBYTY46C.js} +153 -112
  76. package/chunks/{chunk-XRSOI3DL.js → chunk-BE5FGT5Z.js} +1 -1
  77. package/chunks/{chunk-BGXZBI5B.js → chunk-BHTYRHJF.js} +3 -2
  78. package/chunks/{chunk-CSMI4FP5.js → chunk-BSJOBW4U.js} +1 -1
  79. package/chunks/{chunk-Z7TGYN5F.js → chunk-BXNKREX7.js} +3 -3
  80. package/chunks/{chunk-4MQEPP3Y.js → chunk-BY24DZ4J.js} +5 -119
  81. package/chunks/{chunk-5XBFCMWD.js → chunk-CAZADEU7.js} +17 -9
  82. package/chunks/chunk-CHEIIBT3.js +40 -0
  83. package/chunks/{chunk-BBWV7ONL.js → chunk-CM4F4JBB.js} +6 -6
  84. package/chunks/{chunk-CAJTKR6W.js → chunk-D7D3HSYQ.js} +6 -5
  85. package/chunks/{chunk-3DXFGHAJ.js → chunk-DBTMP3P4.js} +213 -185
  86. package/chunks/chunk-DJBQCO2E.js +842 -0
  87. package/chunks/{chunk-RXFQM6FQ.js → chunk-DMEUXLSS.js} +16 -1
  88. package/chunks/{chunk-3AFMQUTI.js → chunk-E4JNFXNI.js} +3 -3
  89. package/chunks/{chunk-UHQFIS7N.js → chunk-EAHOJF6V.js} +28 -4
  90. package/chunks/{chunk-OIVXBW3W.js → chunk-ED7DD7MV.js} +3 -3
  91. package/chunks/{chunk-6DIGWMGT.js → chunk-EIJT2PQ6.js} +2 -2
  92. package/chunks/{chunk-XQFT3QUF.js → chunk-ENYUKMFK.js} +1 -1
  93. package/chunks/{chunk-CQH5KTKC.js → chunk-ERHAMGAA.js} +1 -1
  94. package/chunks/{chunk-IOPCFOTF.js → chunk-ERRJA23L.js} +3 -3
  95. package/chunks/{chunk-LDP5OD6N.js → chunk-EU2B4P3D.js} +12 -12
  96. package/chunks/{chunk-W5MJJ2V7.js → chunk-FHPYRXRH.js} +1 -1
  97. package/chunks/{chunk-IZIVM7LZ.js → chunk-FIWZOMBF.js} +3 -3
  98. package/chunks/{chunk-4HV6HH33.js → chunk-FPMQT2YY.js} +9 -9
  99. package/chunks/{chunk-Z7VOMGDC.js → chunk-FTJMWDND.js} +0 -24
  100. package/chunks/{chunk-L2M46FP5.js → chunk-FXUSWLBF.js} +225 -12
  101. package/chunks/{chunk-VVW4ZNFY.js → chunk-GB4UKWY5.js} +16 -8
  102. package/chunks/{chunk-PKAYJDB3.js → chunk-GCUR24KK.js} +22 -4
  103. package/chunks/{chunk-DIMEPKCW.js → chunk-GDXSXL3H.js} +11 -1
  104. package/chunks/{chunk-7JPW6IYH.js → chunk-GN422P4J.js} +1 -1
  105. package/chunks/{chunk-66KDY3LV.js → chunk-GS7XT345.js} +3 -3
  106. package/chunks/{chunk-PFCQ62V4.js → chunk-H2A2GJGL.js} +6 -6
  107. package/chunks/{chunk-Z7FLBQPR.js → chunk-H5GPPDGY.js} +8 -8
  108. package/chunks/{chunk-CPGJJJLU.js → chunk-HDMKCJHI.js} +1 -1
  109. package/chunks/{chunk-6PJOTWAN.js → chunk-HT5S5TRQ.js} +1 -1
  110. package/chunks/{chunk-Z4X5MTRT.js → chunk-HWVUSYSN.js} +5 -12
  111. package/chunks/{chunk-V4QXXQJ2.js → chunk-I75VKFCJ.js} +4 -4
  112. package/chunks/{chunk-NU7RKEZR.js → chunk-IBMUI5EV.js} +3 -3
  113. package/chunks/{chunk-4J657AJR.js → chunk-ID33ZRWH.js} +42 -42
  114. package/chunks/{chunk-R4PMVSR5.js → chunk-IIFL7QDN.js} +30 -192
  115. package/chunks/{chunk-MQM5PJML.js → chunk-IVUWTA2D.js} +1 -1
  116. package/chunks/{chunk-E55H6BZ7.js → chunk-IXEZHTDR.js} +1616 -151
  117. package/chunks/{chunk-XF63PKEN.js → chunk-IXHV5MIC.js} +1 -1
  118. package/chunks/{chunk-JHS74YAB.js → chunk-J4Y3QJHF.js} +3 -1
  119. package/chunks/{chunk-MIIVI25Q.js → chunk-JDIO45X7.js} +3 -3
  120. package/chunks/{chunk-QFCDF5PL.js → chunk-JHN7UIDW.js} +1 -1
  121. package/chunks/{chunk-FDY5RMGH.js → chunk-JLSZT354.js} +2 -2
  122. package/chunks/chunk-JMRE4WJQ.js +1849 -0
  123. package/chunks/{chunk-FY76G3G5.js → chunk-JOTYTYYW.js} +6 -6
  124. package/chunks/{chunk-TRZTNIQ6.js → chunk-JOWQD4LO.js} +3 -3
  125. package/chunks/{chunk-KEKZFOL6.js → chunk-JPKTAQS3.js} +1 -1
  126. package/chunks/chunk-JS73NNWF.js +30 -0
  127. package/chunks/chunk-JX6XHPTX.js +26 -0
  128. package/chunks/{chunk-5JTIYALA.js → chunk-JZWOCUZ3.js} +1 -1
  129. package/chunks/{chunk-3JGZSIDA.js → chunk-KFN2IZYR.js} +3 -3
  130. package/chunks/{chunk-23RFD54N.js → chunk-KHP66DFN.js} +1 -1
  131. package/chunks/{chunk-AGR5UROZ.js → chunk-KUDI54QQ.js} +23 -33
  132. package/chunks/{chunk-3SGB2UHX.js → chunk-L2OKAIUK.js} +28 -16
  133. package/chunks/{chunk-BXDAPVQU.js → chunk-L6CUJZDG.js} +28 -4
  134. package/chunks/chunk-LAUEEBDL.js +277 -0
  135. package/chunks/{chunk-BNMF3K5X.js → chunk-LFAR7CPW.js} +55 -39
  136. package/chunks/{chunk-Y3QL45LS.js → chunk-LKODFJRD.js} +9 -9
  137. package/chunks/{chunk-BWORX6FA.js → chunk-LMMHS3RS.js} +1 -1
  138. package/chunks/{chunk-UTLCH2FK.js → chunk-LYSZVCCD.js} +10 -7
  139. package/chunks/{chunk-F6FV3C5K.js → chunk-MBZ5ORJB.js} +264 -283
  140. package/chunks/{chunk-L6YT5H34.js → chunk-MJBHSZEJ.js} +5 -5
  141. package/chunks/{chunk-B7CDU2SL.js → chunk-MOF6VZN2.js} +18 -21
  142. package/chunks/{chunk-6LFJEACX.js → chunk-MZ5A5PQW.js} +7 -7
  143. package/chunks/chunk-MZYWNU66.js +149 -0
  144. package/chunks/{chunk-2TNL5KPM.js → chunk-N4QWUPDM.js} +7 -0
  145. package/chunks/{chunk-5O72BNDD.js → chunk-ND7TQQPE.js} +9 -9
  146. package/chunks/{chunk-QP4C6WCE.js → chunk-NGKLMNWN.js} +3 -3
  147. package/chunks/{chunk-JSC3H3TD.js → chunk-NT5XIL5H.js} +46 -18
  148. package/chunks/{chunk-KUX5D6DK.js → chunk-NT7LXVV5.js} +11010 -11138
  149. package/chunks/{chunk-PDQGMSZK.js → chunk-ODZF64DM.js} +1 -1
  150. package/chunks/{chunk-FBSSIAAQ.js → chunk-OE5AQVNB.js} +8 -8
  151. package/chunks/chunk-OHU2H5CS.js +130 -0
  152. package/chunks/{chunk-2K6ORIHJ.js → chunk-OKMDOATP.js} +13 -13
  153. package/chunks/{chunk-JB4JIVTJ.js → chunk-OKTNXDVO.js} +1 -1
  154. package/chunks/{chunk-XDLEZ5HX.js → chunk-OQYXJK2V.js} +1 -1
  155. package/chunks/{chunk-EFUM7RVY.js → chunk-OSTQZIOY.js} +944 -18
  156. package/chunks/{chunk-VQUGEVGR.js → chunk-OTTNXUT5.js} +1 -1
  157. package/chunks/{chunk-T3WXYEZ4.js → chunk-PB7JBAHF.js} +53 -54
  158. package/chunks/{chunk-WAOIHTJS.js → chunk-PDAKFU7M.js} +1 -1
  159. package/chunks/{chunk-43GGFFLY.js → chunk-PDXYZBBQ.js} +3 -3
  160. package/chunks/{chunk-4CMJKUND.js → chunk-PNIGAVY6.js} +67 -2
  161. package/chunks/{chunk-SAH4BD2J.js → chunk-PQEISIKS.js} +67 -0
  162. package/chunks/{chunk-4CDSK5AZ.js → chunk-PWR2NQBS.js} +6 -6
  163. package/chunks/{chunk-YTDVNSUQ.js → chunk-QAK5475D.js} +1 -1
  164. package/chunks/{chunk-IJKTMLBE.js → chunk-QE7DTCLX.js} +1 -1
  165. package/chunks/{chunk-SMPR7SPO.js → chunk-QJNDUTOL.js} +45 -239
  166. package/chunks/{chunk-C6K43ZDE.js → chunk-QTMPM6RC.js} +16 -10
  167. package/chunks/{chunk-P5GGM4KS.js → chunk-RAEEQEC5.js} +5 -5
  168. package/chunks/{chunk-XDFHY4R3.js → chunk-RGEV5AUD.js} +242 -14
  169. package/chunks/{chunk-M6FOJXW3.js → chunk-RKW36UWC.js} +1 -1
  170. package/chunks/{chunk-RIEFGNTP.js → chunk-RLSPPTWH.js} +5119 -683
  171. package/chunks/{chunk-PDMJ3KGS.js → chunk-RT4QNQ5P.js} +3 -3
  172. package/chunks/{chunk-SJ3ZUWFK.js → chunk-RVCGAHC7.js} +4 -26
  173. package/chunks/{chunk-77RG5SFQ.js → chunk-RY7DL5IF.js} +11 -6
  174. package/chunks/{chunk-4FTKQNWJ.js → chunk-S2T7H5MI.js} +182 -3
  175. package/chunks/{chunk-EOGELB3H.js → chunk-SDCHI64N.js} +4 -4
  176. package/chunks/{chunk-EKSCLBBF.js → chunk-SMJYTKTB.js} +23 -5
  177. package/chunks/{chunk-MZS7GEC7.js → chunk-SMRDCANI.js} +1 -1
  178. package/chunks/{chunk-43UYNAWX.js → chunk-T3TL6S3B.js} +4 -4
  179. package/chunks/{chunk-4K7NQDCG.js → chunk-T4EFG2P5.js} +18 -9
  180. package/chunks/{chunk-IK5BW3CS.js → chunk-T4RMUTTT.js} +16 -5
  181. package/chunks/{chunk-L6BZRIUL.js → chunk-TBJ3SNS3.js} +183 -5
  182. package/chunks/{chunk-CCBZDVUA.js → chunk-TNMOFNT4.js} +133 -122
  183. package/chunks/{chunk-Y6LSMB6J.js → chunk-TV7BJ7TX.js} +1 -1
  184. package/chunks/{chunk-G34IR3D6.js → chunk-U5RTYI7D.js} +102 -146
  185. package/chunks/{chunk-TTX2JUE6.js → chunk-U6D2PPMN.js} +1 -1
  186. package/chunks/{chunk-D5LUXLUH.js → chunk-UJ4DUYIH.js} +18 -4
  187. package/chunks/{chunk-A7YP63XN.js → chunk-UKB2TZAO.js} +5 -5
  188. package/chunks/{chunk-VTHREBQM.js → chunk-UKYXYWI2.js} +2 -2
  189. package/chunks/{chunk-2NYCN6F2.js → chunk-UVYKCRJZ.js} +46 -29
  190. package/chunks/{chunk-HVEYF6VT.js → chunk-UXEW7TQS.js} +2 -2
  191. package/chunks/{chunk-HVQ3B7FF.js → chunk-V4HN35IF.js} +44 -7
  192. package/chunks/chunk-VGHZT6JR.js +51 -0
  193. package/chunks/{chunk-V5J4J5TP.js → chunk-VYSZUQGU.js} +2 -20
  194. package/chunks/{chunk-6IUNAPLR.js → chunk-W4BDHLRT.js} +3 -3
  195. package/chunks/{chunk-Q26AYA62.js → chunk-W7KWB6AH.js} +7 -4
  196. package/chunks/chunk-WLEYH7CD.js +332 -0
  197. package/chunks/{chunk-RU7BK6B3.js → chunk-X7C7KFWA.js} +2 -2
  198. package/chunks/{chunk-YRLW2MSX.js → chunk-XBVNNDPK.js} +11 -4
  199. package/chunks/{chunk-BFPESSTR.js → chunk-XEAAO654.js} +1 -1
  200. package/chunks/{chunk-JU4EEXC7.js → chunk-XLENZQXH.js} +2 -2
  201. package/chunks/{chunk-JSHHYW6T.js → chunk-XPDKSOVW.js} +69 -64
  202. package/chunks/chunk-YDQ4OCDK.js +1222 -0
  203. package/chunks/{chunk-ZU4UDIWX.js → chunk-YKADANK6.js} +6 -7
  204. package/chunks/{chunk-JCQD3INC.js → chunk-YNG7XAJU.js} +3 -3
  205. package/chunks/{chunk-O2UN57NX.js → chunk-YOFULAHO.js} +19 -2
  206. package/chunks/{chunk-BAJKAAOY.js → chunk-YOMKOM7E.js} +4892 -1504
  207. package/chunks/{chunk-ERFDKH32.js → chunk-YPISTYEI.js} +8 -7
  208. package/chunks/{chunk-TGWAQ5RB.js → chunk-ZBDYI7VM.js} +6900 -6882
  209. package/chunks/{chunk-OZ6KS6KW.js → chunk-ZGCKTAL5.js} +6 -1
  210. package/chunks/chunk-ZHO2CW6D.js +205 -0
  211. package/chunks/{chunk-DZWPESIF.js → chunk-ZQ3FKEWA.js} +3 -3
  212. package/chunks/{chunk-7EQQR46F.js → chunk-ZVP4PWBU.js} +1 -1
  213. package/chunks/{chunk-7UYV53BC.js → chunk-ZYPJ7HVZ.js} +1 -1
  214. package/chunks/config-utils-NNUPVGEC.js +118 -0
  215. package/chunks/contextCommand-S3TPCDM5.js +111 -0
  216. package/chunks/{core-runtime-677KFX6Q.js → core-runtime-NASPCSQX.js} +66 -63
  217. package/chunks/{create-sub-session-23ITIELI.js → create-sub-session-36TNCHCP.js} +3 -3
  218. package/chunks/{create-sub-session-JKZAYZX7.js → create-sub-session-DS4BJLYZ.js} +97 -68
  219. package/chunks/{cron-create-KJ4IY6PP.js → cron-create-QXHTYUTO.js} +4 -4
  220. package/chunks/{cron-delete-MBLQCAYY.js → cron-delete-WV2BM42M.js} +4 -4
  221. package/chunks/{cron-list-DWH2PQ47.js → cron-list-7KVNBLZ7.js} +4 -4
  222. package/chunks/{daemon-MJQUO7RA.js → daemon-UCVUHPJD.js} +723 -90
  223. package/chunks/{daemon-git-worktree-guard-6MVAAZZZ.js → daemon-git-worktree-guard-ATXVQPS3.js} +63 -60
  224. package/chunks/daemon-status-provider-UI3GBTMO.js +121 -0
  225. package/chunks/daemon-trust-policy-SUCBJ2CA.js +117 -0
  226. package/chunks/{daemon-trust-policy-monitor-B5U6TQX5.js → daemon-trust-policy-monitor-3LM5RQNS.js} +71 -68
  227. package/chunks/{de-X6HLSIFE.js → de-T4BLOKEC.js} +3 -0
  228. package/chunks/deferred-core-runtime-SCOJLVYG.js +119 -0
  229. package/chunks/{display-image-BE7I6ZB6.js → display-image-Z4VBQDEJ.js} +5 -5
  230. package/chunks/{dist-TJUDJTCB.js → dist-5423MG3D.js} +411 -91
  231. package/chunks/{dist-ILDBUWDB.js → dist-7WDZYMWV.js} +43 -25
  232. package/chunks/{dist-ZBVOXSKF.js → dist-FLJLHASF.js} +219 -121
  233. package/chunks/{dist-QODVOVWI.js → dist-GPSRNVVP.js} +43 -35
  234. package/chunks/{dist-DJBNNPLN.js → dist-LY66XNUL.js} +10 -3
  235. package/chunks/{dist-7CKN54NL.js → dist-S3BKCTWF.js} +205 -89
  236. package/chunks/{dist-UQUFZDIY.js → dist-SDKHGH5O.js} +41 -20
  237. package/chunks/{dist-4Q7NTUNB.js → dist-WAUO5OMN.js} +46 -22
  238. package/chunks/{dist-SATKXKUR.js → dist-WIVVPE7M.js} +28 -14
  239. package/chunks/earlyInputCapture-INWJ2STR.js +112 -0
  240. package/chunks/{edit-BSV6YRVW.js → edit-B7ZRRGAE.js} +51 -49
  241. package/chunks/{en-YLXBXM4Z.js → en-E4AYTX6H.js} +3 -0
  242. package/chunks/{enter-worktree-MQXFFPKM.js → enter-worktree-SPZHEETQ.js} +7 -7
  243. package/chunks/{enterPlanMode-PKNF35FE.js → enterPlanMode-S554IKJ2.js} +55 -53
  244. package/chunks/environment-25ADH4Y6.js +134 -0
  245. package/chunks/errors-G2I6LFTW.js +118 -0
  246. package/chunks/{exit-worktree-L344UY7K.js → exit-worktree-AWUXAMAM.js} +7 -7
  247. package/chunks/exitPlanMode-ZFH4OYPM.js +87 -0
  248. package/chunks/{fast-path-773PV7PU.js → fast-path-WZHVZ2ER.js} +8 -7
  249. package/chunks/{fast-path-settings-XMFBYFUH.js → fast-path-settings-NILM6QZL.js} +3 -3
  250. package/chunks/{fr-FTZWF462.js → fr-BGHGYX6A.js} +3 -0
  251. package/chunks/{glob-CZHOWUEA.js → glob-UOVDMBUP.js} +50 -48
  252. package/chunks/{goal-tools-YZQJXTGH.js → goal-tools-7TNK5ZHC.js} +5 -4
  253. package/chunks/{grep-5GPICQBU.js → grep-LHYJ5V2N.js} +9 -7
  254. package/chunks/handleAutoUpdate-4MZ45DZY.js +114 -0
  255. package/chunks/i18n-KWUEI4DS.js +129 -0
  256. package/chunks/{image-gen-HAYOEQ4O.js → image-gen-YZDVO5YS.js} +8 -10
  257. package/chunks/initializer-2NBROGMG.js +118 -0
  258. package/chunks/installationInfo-YKUSY3ZB.js +112 -0
  259. package/chunks/{ja-2GL5FKYJ.js → ja-G3FTD5XE.js} +3 -0
  260. package/chunks/{keychain-token-storage-37XPR34V.js → keychain-token-storage-REZVMJA6.js} +2 -2
  261. package/chunks/list-W2WV3COM.js +121 -0
  262. package/chunks/list-agents-PMVMHNY7.js +128 -0
  263. package/chunks/{gemini-IP4FJAP5.js → llm-NPPHLIJI.js} +162 -133
  264. package/chunks/{geminiContentGenerator-PUNEBWJW.js → llm-content-generator-YK3WN6XW.js} +29 -29
  265. package/chunks/loadedSettingsAdapter-2P7DFWUR.js +115 -0
  266. package/chunks/{loggingContentGenerator-2GGZNGLG.js → loggingContentGenerator-QYYYGU6V.js} +318 -35
  267. package/chunks/{loop-wakeup-XJFONSQ7.js → loop-wakeup-EBM4F5MZ.js} +5 -5
  268. package/chunks/{ls-3VAT2J7A.js → ls-F6TRX3DD.js} +4 -4
  269. package/chunks/{lsp-5W7IRUBH.js → lsp-QYTOS2FI.js} +2 -2
  270. package/chunks/{managed-npm-update-5TEV2E3J.js → managed-npm-update-UMC4NBWW.js} +64 -61
  271. package/chunks/mcp-OFI6XDP2.js +115 -0
  272. package/chunks/{monitor-FI7PY36Z.js → monitor-QX3BM3JY.js} +50 -48
  273. package/chunks/nonInteractiveCli-NVRMD5MN.js +193 -0
  274. package/chunks/{notebook-edit-TPGMGBST.js → notebook-edit-AAILDPSV.js} +51 -49
  275. package/chunks/{open-with-auth-4UI3KHUR.js → open-with-auth-D6JD6LDS.js} +4 -4
  276. package/chunks/{openaiContentGenerator-SUCYANUZ.js → openaiContentGenerator-53PB3CMN.js} +27 -29
  277. package/chunks/pidfile-5ACKG2LI.js +116 -0
  278. package/chunks/process-registry-OAEG6WGC.js +662 -0
  279. package/chunks/{processUtils-IQZBYWSB.js → processUtils-2BCDO3DZ.js} +2 -2
  280. package/chunks/prompt-terminal-ledger-3RKW73A2.js +110 -0
  281. package/chunks/{pt-XN2YWJVM.js → pt-D73IFYT7.js} +3 -0
  282. package/chunks/{qwenContentGenerator-J4TXFGJT.js → qwenContentGenerator-N4LLWDPH.js} +56 -54
  283. package/chunks/{qwenOAuth2-RF33DNZW.js → qwenOAuth2-7AOCKSOQ.js} +7 -9
  284. package/chunks/{read-file-QE2B5FTX.js → read-file-DPAKXHYE.js} +13 -13
  285. package/chunks/{read-mcp-resource-XD257PGJ.js → read-mcp-resource-R4NO75DW.js} +2 -2
  286. package/chunks/{record-artifact-RZGZBENU.js → record-artifact-2EAYLAL5.js} +4 -4
  287. package/chunks/{report-findings-Q3SYKKW5.js → report-findings-Y4MSHDS3.js} +9 -5
  288. package/chunks/{request-shutdown-BCLA3JV2.js → request-shutdown-DWRMGTMB.js} +8 -7
  289. package/chunks/resumeHistoryUtils-3JQORXAK.js +123 -0
  290. package/chunks/ripGrep-AHF5QCI7.js +39 -0
  291. package/chunks/{ru-OLTMFJEW.js → ru-QMISLKRH.js} +3 -0
  292. package/chunks/{run-qwen-serve-TPHZMSXJ.js → run-qwen-serve-3LKV7KDC.js} +728 -256
  293. package/chunks/runtime-66F4W3IA.js +153 -0
  294. package/chunks/scheduled-tasks-2NVKS5Q2.js +132 -0
  295. package/chunks/scheduler-JNV7T3ZO.js +127 -0
  296. package/chunks/{sdk-exporters-http-KCJ4ZFG7.js → sdk-exporters-http-MFIWD23D.js} +2 -2
  297. package/chunks/{sdk-impl-HLSEDAEP.js → sdk-impl-2RXJ4Q6X.js} +11 -5
  298. package/chunks/send-message-WPZRCJOB.js +442 -0
  299. package/chunks/serve-GP2UNRP7.js +123 -0
  300. package/chunks/{server-DFUSSSHI.js → server-7W6C3SOW.js} +5233 -3623
  301. package/chunks/{session-3TEHNENZ.js → session-PZLBAQGG.js} +125 -118
  302. package/chunks/session-pr-refresh-OIVL3U3Z.js +367 -0
  303. package/chunks/{settings-VOZYKLTT.js → settings-ZOHIQWYK.js} +70 -67
  304. package/chunks/shell-FWZT6IUR.js +97 -0
  305. package/chunks/{skill-FEOKFX26.js → skill-RTQC2YGA.js} +121 -65
  306. package/chunks/skill-settings-AKMIXFSJ.js +123 -0
  307. package/chunks/spawnChannel-ZP23JL6O.js +116 -0
  308. package/chunks/standalone-update-P2Q5H4ZU.js +123 -0
  309. package/chunks/{startInteractiveUI-WHJPFOGH.js → startInteractiveUI-NSA6QPQZ.js} +2018 -1526
  310. package/chunks/{stdioHelpers-7A2EE64Z.js → stdioHelpers-AY6XCDY2.js} +3 -1
  311. package/chunks/{syntheticOutput-ML43GEFN.js → syntheticOutput-5URSQLIS.js} +3 -3
  312. package/chunks/{task-create-TMSV7RD5.js → task-create-3EXVDG3G.js} +12 -12
  313. package/chunks/{task-list-W55RBFRX.js → task-list-PIBYNSE7.js} +5 -6
  314. package/chunks/{task-stop-CXEH5L2D.js → task-stop-IV3BYWJC.js} +2 -2
  315. package/chunks/{task-update-N536I4GQ.js → task-update-H5BPDS5Y.js} +13 -14
  316. package/chunks/{team-create-QYSWCYCL.js → team-create-53T42W37.js} +56 -55
  317. package/chunks/{team-delete-FJRFX33M.js → team-delete-X3WPELS6.js} +25 -8
  318. package/chunks/{team-plan-approval-P7DAD644.js → team-plan-approval-D45ZC5OE.js} +50 -48
  319. package/chunks/terminal-image-renderer-FCRUWT6C.js +121 -0
  320. package/chunks/theme-manager-MHNPEDP7.js +107 -0
  321. package/chunks/{todoWrite-WDJNQEMW.js → todoWrite-A5IOZZ3P.js} +4 -4
  322. package/chunks/{tool-search-F2EMIAPV.js → tool-search-6RPBGGUX.js} +27 -23
  323. package/chunks/total-session-admission-MGV56XDK.js +117 -0
  324. package/chunks/trustedFolders-QJYEFMTU.js +127 -0
  325. package/chunks/{types-WYCFCEHR.js → types-HKLPXZB3.js} +1 -3
  326. package/chunks/{update-relaunch-4GF3OXMB.js → update-relaunch-ZDMQX63C.js} +6 -6
  327. package/chunks/updateCheck-4QZWCGP6.js +123 -0
  328. package/chunks/useAutoAcceptIndicator-DLIQN256.js +125 -0
  329. package/chunks/{validateNonInterActiveAuth-BPPA563H.js → validateNonInterActiveAuth-HGTG7AEK.js} +114 -107
  330. package/chunks/{version-ANP4TS6O.js → version-CPAZMC4B.js} +1 -1
  331. package/chunks/{web-fetch-QJADSAH3.js → web-fetch-N4K5M3M4.js} +16 -18
  332. package/chunks/{web-search-7TTQKEKM.js → web-search-4VZKM5SF.js} +9 -11
  333. package/chunks/{web-shell-static-A6QMUNNV.js → web-shell-static-PW7OEDQO.js} +3 -2
  334. package/chunks/{workflow-5XN6XSOT.js → workflow-2ALQKTHG.js} +229 -146
  335. package/chunks/workspace-providers-status-5JM4CB6R.js +119 -0
  336. package/chunks/{workspace-registration-store-XKVW2YVH.js → workspace-registration-store-RNMFVCH7.js} +2 -1
  337. package/chunks/workspace-registry-6EULAPZC.js +126 -0
  338. package/chunks/workspace-runtime-coordinator-IRI2DRCJ.js +127 -0
  339. package/chunks/workspace-service-SETHN4WE.js +131 -0
  340. package/chunks/workspace-skills-status-4D4EUEQU.js +118 -0
  341. package/chunks/{workspace-trust-reconciler-KLGOB53D.js → workspace-trust-reconciler-4LR3CDL4.js} +77 -76
  342. package/chunks/write-file-45GWPSOI.js +92 -0
  343. package/chunks/{zh-UNY63FR3.js → zh-2BQ7P6OD.js} +3 -0
  344. package/chunks/{zh-TW-RPTMRTHG.js → zh-TW-UFXRZTXX.js} +3 -0
  345. package/chunks/{zoom-image-6ASG6J4C.js → zoom-image-K6IQUKRC.js} +13 -13
  346. package/cli.js +129 -92
  347. package/locales/ca.js +6 -0
  348. package/locales/de.js +6 -0
  349. package/locales/en.js +6 -0
  350. package/locales/fr.js +6 -0
  351. package/locales/ja.js +6 -0
  352. package/locales/pt.js +6 -0
  353. package/locales/ru.js +6 -0
  354. package/locales/zh-TW.js +6 -0
  355. package/locales/zh.js +6 -0
  356. package/package.json +3 -3
  357. package/web-shell/assets/{abnfDiagram-VCTEODGH-uS-vtfs3.js → abnfDiagram-VCTEODGH-C80OZcPP.js} +1 -1
  358. package/web-shell/assets/{arc-BSTnk5pu.js → arc-AUqStYgf.js} +1 -1
  359. package/web-shell/assets/{architectureDiagram-5GKGNRK7-DCMyiqzy.js → architectureDiagram-5GKGNRK7-CQYOdYla.js} +1 -1
  360. package/web-shell/assets/{blockDiagram-NRAW4CY4-C7_gt0r1.js → blockDiagram-NRAW4CY4-lYKlFysy.js} +1 -1
  361. package/web-shell/assets/{c4Diagram-UCG6FXSJ-BeQg2L8B.js → c4Diagram-UCG6FXSJ-BoS23iIp.js} +1 -1
  362. package/web-shell/assets/channel-B0ovOJeK.js +1 -0
  363. package/web-shell/assets/{chunk-2Q5K7J3B-DnV9bKBe.js → chunk-2Q5K7J3B-DLLooL1E.js} +1 -1
  364. package/web-shell/assets/{chunk-5VM5RSS4-rT1GAcT7.js → chunk-5VM5RSS4-kPfJxScY.js} +1 -1
  365. package/web-shell/assets/{chunk-F27PBJKO-BcgSxqGA.js → chunk-F27PBJKO-CVGFBqkD.js} +1 -1
  366. package/web-shell/assets/{chunk-G27WJ6UU-Bw1ZhyZq.js → chunk-G27WJ6UU-CnM_kOVV.js} +1 -1
  367. package/web-shell/assets/{chunk-JWPE2WC7-D4iDw-96.js → chunk-JWPE2WC7-Cj-ajOkT.js} +1 -1
  368. package/web-shell/assets/{chunk-LCL6LL3I-D3MB3GTZ.js → chunk-LCL6LL3I-8L5c-wFo.js} +1 -1
  369. package/web-shell/assets/{chunk-POPQ4Y6H-Cep2ndrS.js → chunk-POPQ4Y6H-DsXTxpvL.js} +1 -1
  370. package/web-shell/assets/{chunk-SVP7TREG-BuahMHJc.js → chunk-SVP7TREG-DU5GE1_z.js} +1 -1
  371. package/web-shell/assets/{chunk-XXDRQBXY-BdujIvJY.js → chunk-XXDRQBXY-D2IIWZKt.js} +1 -1
  372. package/web-shell/assets/classDiagram-DTDB5LWJ-DMll2-6_.js +1 -0
  373. package/web-shell/assets/classDiagram-v2-JRS7N3AN-DMll2-6_.js +1 -0
  374. package/web-shell/assets/{cose-bilkent-JH36ORCC-CGLLUbF8.js → cose-bilkent-JH36ORCC-CF_txUJr.js} +1 -1
  375. package/web-shell/assets/{cynefin-OW5HDTMX-D6kDsRSh.js → cynefin-OW5HDTMX-DEZ-My-Z.js} +1 -1
  376. package/web-shell/assets/{cynefinDiagram-5FMLGOSQ-CCy78qZx.js → cynefinDiagram-5FMLGOSQ-BV7EKUS6.js} +1 -1
  377. package/web-shell/assets/{dagre-3AP2YEHR-D5gJuJsf.js → dagre-3AP2YEHR-JGIX0G4H.js} +1 -1
  378. package/web-shell/assets/{diagram-S7CK7UJ4-ZwEZ5W__.js → diagram-S7CK7UJ4-DdUY7q6A.js} +1 -1
  379. package/web-shell/assets/{diagram-UQ7AKVKN-B036APjv.js → diagram-UQ7AKVKN-fhzRZ19v.js} +1 -1
  380. package/web-shell/assets/{diagram-VSXAHHWV-BfDJ57Fq.js → diagram-VSXAHHWV-BOgOex6q.js} +1 -1
  381. package/web-shell/assets/{diagram-VX7I27RA-Wha0p5rT.js → diagram-VX7I27RA-C0NknIz6.js} +1 -1
  382. package/web-shell/assets/{diagram-Z3DM3KII-L20bz2K1.js → diagram-Z3DM3KII-C__3mUBX.js} +1 -1
  383. package/web-shell/assets/{ebnfDiagram-PWID7BFC-D1ZM0Cp7.js → ebnfDiagram-PWID7BFC-BvPhqycH.js} +1 -1
  384. package/web-shell/assets/{erDiagram-SSCWMZ5O-CMtA19v8.js → erDiagram-SSCWMZ5O-BqzoNoL9.js} +1 -1
  385. package/web-shell/assets/{flowDiagram-A5DVABFB-D96m326S.js → flowDiagram-A5DVABFB-CJKOre47.js} +1 -1
  386. package/web-shell/assets/{ganttDiagram-EL5Y4UJY-BuHiYG2o.js → ganttDiagram-EL5Y4UJY-C5xZjrp0.js} +1 -1
  387. package/web-shell/assets/{gitGraphDiagram-WWUBYQGX-Ck3NmkSw.js → gitGraphDiagram-WWUBYQGX-C0EjwuPK.js} +1 -1
  388. package/web-shell/assets/index-B_IPzA0h.js +2020 -0
  389. package/web-shell/assets/{index-CBGz4Qjl.js → index-C5M93syE.js} +1 -1
  390. package/web-shell/assets/index-D1OKGQlM.css +36 -0
  391. package/web-shell/assets/{infoDiagram-RXCK75RN-B6DAOyXe.js → infoDiagram-RXCK75RN-BUwzsYOs.js} +1 -1
  392. package/web-shell/assets/{ishikawaDiagram-5VMMS53U-Bpg-joFo.js → ishikawaDiagram-5VMMS53U-EDJ_DH3V.js} +1 -1
  393. package/web-shell/assets/{journeyDiagram-EYS64GPL-BclrHzGa.js → journeyDiagram-EYS64GPL-BnfcOsS0.js} +1 -1
  394. package/web-shell/assets/{kanban-definition-3QL26DDD-5gJzNTYG.js → kanban-definition-3QL26DDD-D_ofTVGu.js} +1 -1
  395. package/web-shell/assets/{layout-CEz_1L8z.js → layout-CBuQFdfZ.js} +1 -1
  396. package/web-shell/assets/{linear-CBjTq9Hc.js → linear-DRIHtmGv.js} +1 -1
  397. package/web-shell/assets/{mermaid.core-Dzhbxx_I.js → mermaid.core-CmR5wZH6.js} +6 -6
  398. package/web-shell/assets/{mindmap-definition-FBJOCRG2-DQdVqlBF.js → mindmap-definition-FBJOCRG2-BV374olC.js} +1 -1
  399. package/web-shell/assets/{pegDiagram-XKGWAZYB-D1JZlYXL.js → pegDiagram-XKGWAZYB-Bpy1SplK.js} +1 -1
  400. package/web-shell/assets/{pieDiagram-E7YTZNPT-BmkpYL0w.js → pieDiagram-E7YTZNPT-CeZx4hR2.js} +1 -1
  401. package/web-shell/assets/{quadrantDiagram-AXDQQJYC-DRvD6co5.js → quadrantDiagram-AXDQQJYC-COYKs14h.js} +1 -1
  402. package/web-shell/assets/{railroadDiagram-O6MQD6OU-CEdjDuoo.js → railroadDiagram-O6MQD6OU-5g2pOeTs.js} +1 -1
  403. package/web-shell/assets/{requirementDiagram-EFPCY7ZU-BCHG-ie8.js → requirementDiagram-EFPCY7ZU-Yn8uPGtF.js} +1 -1
  404. package/web-shell/assets/{sankeyDiagram-P5KCCOFB-C9cZMnye.js → sankeyDiagram-P5KCCOFB-CTayAGq6.js} +1 -1
  405. package/web-shell/assets/{sequenceDiagram-WJ2MYXX4-DYHRV4zL.js → sequenceDiagram-WJ2MYXX4-BFWDKzUU.js} +1 -1
  406. package/web-shell/assets/{sizeCapture-X5ZJPWSS-DlK21aye.js → sizeCapture-X5ZJPWSS-CtErUbj4.js} +1 -1
  407. package/web-shell/assets/{stateDiagram-HBIQ2CUA-BrmZssvk.js → stateDiagram-HBIQ2CUA-Co3HFzOd.js} +1 -1
  408. package/web-shell/assets/stateDiagram-v2-4QOOHH4V-C3gdRjPm.js +1 -0
  409. package/web-shell/assets/{swimlanes-XN3QIQJK-D9xfcayR.js → swimlanes-XN3QIQJK-CDZuxzOj.js} +1 -1
  410. package/web-shell/assets/swimlanesDiagram-VK2B7HYN-C34TGCPZ.js +8 -0
  411. package/web-shell/assets/{timeline-definition-24CTP7MA-D4gdDL_d.js → timeline-definition-24CTP7MA-UcNHj8At.js} +1 -1
  412. package/web-shell/assets/{vennDiagram-4TSXK5OY-DdhIExjI.js → vennDiagram-4TSXK5OY-JKR9pVFG.js} +1 -1
  413. package/web-shell/assets/{wardleyDiagram-VM6X3IG4-C9RS_Zof.js → wardleyDiagram-VM6X3IG4-C4SU-yIW.js} +1 -1
  414. package/web-shell/assets/{xychartDiagram-S5SC5T6Z-orRgmxWk.js → xychartDiagram-S5SC5T6Z-D_yoWGZ4.js} +1 -1
  415. package/web-shell/index.html +197 -3
  416. package/chunks/MaxSizedBox-X5FZSNAJ.js +0 -112
  417. package/chunks/agent-PJIPDWHB.js +0 -97
  418. package/chunks/agent-headless-B4JVD7UK.js +0 -87
  419. package/chunks/bridge-FKZTVIS3.js +0 -121
  420. package/chunks/channel-settings-store-4UFCLBBG.js +0 -117
  421. package/chunks/chunk-7DJCPZE3.js +0 -945
  422. package/chunks/chunk-CPBF7KYF.js +0 -51
  423. package/chunks/chunk-H72BQNM3.js +0 -645
  424. package/chunks/chunk-J2OSJFP3.js +0 -202
  425. package/chunks/chunk-K2OJUPOE.js +0 -78
  426. package/chunks/chunk-P3QQPMQA.js +0 -19
  427. package/chunks/chunk-RUGNCYNO.js +0 -699
  428. package/chunks/chunk-T26EAKDL.js +0 -13
  429. package/chunks/chunk-ZGXYO7DY.js +0 -3416
  430. package/chunks/chunk-ZYNTSXWK.js +0 -32
  431. package/chunks/config-utils-BBOCOGZW.js +0 -113
  432. package/chunks/contextCommand-EET67MQ2.js +0 -108
  433. package/chunks/daemon-status-provider-RFKZOK3S.js +0 -119
  434. package/chunks/daemon-trust-policy-DRZPFB4Q.js +0 -114
  435. package/chunks/deferred-core-runtime-BBVIOP24.js +0 -116
  436. package/chunks/earlyInputCapture-2JOMMNQ4.js +0 -109
  437. package/chunks/environment-MOZMPUHR.js +0 -131
  438. package/chunks/errors-DMPQVYJL.js +0 -115
  439. package/chunks/exitPlanMode-UE4FGCY4.js +0 -85
  440. package/chunks/handleAutoUpdate-SGXKTQM6.js +0 -111
  441. package/chunks/i18n-B42HKHKH.js +0 -126
  442. package/chunks/initializer-FB66WYR3.js +0 -115
  443. package/chunks/installationInfo-Y7AULNMX.js +0 -109
  444. package/chunks/list-2HWGSVRA.js +0 -118
  445. package/chunks/list-agents-DI3YFTDT.js +0 -80
  446. package/chunks/loadedSettingsAdapter-7Y7IEI6T.js +0 -112
  447. package/chunks/mcp-QGG5NMJJ.js +0 -112
  448. package/chunks/nonInteractiveCli-4LO2TL72.js +0 -186
  449. package/chunks/pidfile-JMF2CLMY.js +0 -113
  450. package/chunks/process-registry-PMJOA5CO.js +0 -172
  451. package/chunks/prompt-terminal-ledger-DCZO6S7C.js +0 -107
  452. package/chunks/resumeHistoryUtils-CZ4JRDVW.js +0 -120
  453. package/chunks/ripGrep-R6B6HWPX.js +0 -39
  454. package/chunks/runtime-TTIGSBM4.js +0 -150
  455. package/chunks/scheduled-tasks-QB4ZVUQS.js +0 -129
  456. package/chunks/scheduler-YRUG22M7.js +0 -124
  457. package/chunks/send-message-Y5I6NYAM.js +0 -295
  458. package/chunks/serve-MXXCDAQN.js +0 -120
  459. package/chunks/shell-6RTKZVMI.js +0 -95
  460. package/chunks/skill-settings-VA4XVYVL.js +0 -120
  461. package/chunks/spawnChannel-F6WVP723.js +0 -114
  462. package/chunks/standalone-update-RGILUQVK.js +0 -120
  463. package/chunks/terminal-image-renderer-SMQE46UJ.js +0 -116
  464. package/chunks/theme-manager-RFO5WWFF.js +0 -104
  465. package/chunks/total-session-admission-HTVTP4BS.js +0 -116
  466. package/chunks/trustedFolders-7OCNMUQE.js +0 -124
  467. package/chunks/updateCheck-7QBDXZRT.js +0 -120
  468. package/chunks/useAutoAcceptIndicator-UI4SNL2O.js +0 -122
  469. package/chunks/workspace-providers-status-PDFZWL5Q.js +0 -116
  470. package/chunks/workspace-registry-23R7XRB5.js +0 -125
  471. package/chunks/workspace-service-MUYO2QIC.js +0 -131
  472. package/chunks/workspace-skills-status-IKECTOOQ.js +0 -115
  473. package/chunks/write-file-GGRBB5TZ.js +0 -90
  474. package/web-shell/assets/channel-CENAhErJ.js +0 -1
  475. package/web-shell/assets/classDiagram-DTDB5LWJ-CM6FArGH.js +0 -1
  476. package/web-shell/assets/classDiagram-v2-JRS7N3AN-CM6FArGH.js +0 -1
  477. package/web-shell/assets/index-8hXIpvo4.js +0 -1865
  478. package/web-shell/assets/index-DclEv91i.css +0 -5
  479. package/web-shell/assets/stateDiagram-v2-4QOOHH4V-B2Q7XDaE.js +0 -1
  480. package/web-shell/assets/swimlanesDiagram-VK2B7HYN-DpZPOSbX.js +0 -8
@@ -0,0 +1,2581 @@
1
+ // Force strict mode and setup for ESM
2
+ "use strict";
3
+ import {
4
+ classifyTopLevelConversationSource
5
+ } from "./chunk-OHU2H5CS.js";
6
+ import {
7
+ A1_MIN_VERSION,
8
+ a1VersionAtLeast,
9
+ isAoneCanonicalHost,
10
+ parseA1Version,
11
+ parseRemoteUrl
12
+ } from "./chunk-4VQBQLIZ.js";
13
+ import {
14
+ safeLogValue
15
+ } from "./chunk-LAUEEBDL.js";
16
+ import {
17
+ normalizeSessionIdForLookup,
18
+ parseCallerSuppliedSessionId
19
+ } from "./chunk-ZEZKIS2K.js";
20
+ import {
21
+ SessionArchivedError,
22
+ SessionArchivingError,
23
+ SessionConflictError,
24
+ SessionNotArchivedError,
25
+ SessionNotFoundError
26
+ } from "./chunk-YPISTYEI.js";
27
+ import {
28
+ gitEnv
29
+ } from "./chunk-NT7LXVV5.js";
30
+ import {
31
+ readWorktreeSession
32
+ } from "./chunk-ED7DD7MV.js";
33
+ import {
34
+ SESSION_PR_URL_MAX_LENGTH,
35
+ SessionIdCaseConflictError,
36
+ SessionOrganizationError,
37
+ SessionOrganizationService,
38
+ SessionService,
39
+ SessionTranscriptChangedError,
40
+ SessionWriterUnavailableError,
41
+ canonicalSessionPrUrl,
42
+ readSessionPrs
43
+ } from "./chunk-ZBDYI7VM.js";
44
+ import {
45
+ updateCronTasks
46
+ } from "./chunk-UJ4DUYIH.js";
47
+ import {
48
+ findGitRoot
49
+ } from "./chunk-ZHO2CW6D.js";
50
+ import {
51
+ addDaemonRequestAttribute
52
+ } from "./chunk-UXEW7TQS.js";
53
+ import {
54
+ Storage
55
+ } from "./chunk-EAHOJF6V.js";
56
+ import {
57
+ writeStderrLine
58
+ } from "./chunk-7FA2II6K.js";
59
+ import {
60
+ init_esbuild_shims
61
+ } from "./chunk-5O2XNYP6.js";
62
+ import {
63
+ __name
64
+ } from "./chunk-J2S4EL5Y.js";
65
+
66
+ // packages/cli/src/serve/server/session-list.ts
67
+ init_esbuild_shims();
68
+
69
+ // packages/cli/src/serve/session-organization-helpers.ts
70
+ init_esbuild_shims();
71
+ function createSessionOrganizationService(workspaceCwd) {
72
+ return new SessionOrganizationService(workspaceCwd, (message) => {
73
+ writeStderrLine(`qwen serve: session-org: ${message}`);
74
+ });
75
+ }
76
+ __name(createSessionOrganizationService, "createSessionOrganizationService");
77
+
78
+ // packages/cli/src/serve/server/persisted-session-list-cache.ts
79
+ init_esbuild_shims();
80
+ import path from "node:path";
81
+ var PersistedSessionListCache = class {
82
+ constructor(ttlMs, maxRetainedSummaries) {
83
+ this.ttlMs = ttlMs;
84
+ this.maxRetainedSummaries = maxRetainedSummaries;
85
+ }
86
+ static {
87
+ __name(this, "PersistedSessionListCache");
88
+ }
89
+ slots = /* @__PURE__ */ new Map();
90
+ retainedSummaries = 0;
91
+ lookup(scope, loader, options = {}) {
92
+ options.signal?.throwIfAborted();
93
+ const key = this.key(scope);
94
+ let slot = this.slots.get(key);
95
+ if (!slot) {
96
+ slot = { generation: 0 };
97
+ this.slots.set(key, slot);
98
+ }
99
+ const now = Date.now();
100
+ if (slot.value) {
101
+ const cacheAgeMs = Math.max(0, now - slot.value.completedAt);
102
+ if (cacheAgeMs < this.ttlMs) {
103
+ const snapshot = slot.value.snapshot;
104
+ return {
105
+ status: "cache_hit",
106
+ promise: Promise.resolve().then(() => {
107
+ options.signal?.throwIfAborted();
108
+ return snapshot;
109
+ }),
110
+ cacheAgeMs
111
+ };
112
+ }
113
+ this.removeValue(slot);
114
+ }
115
+ if (slot.inFlight !== void 0 && slot.inFlight.generation === slot.generation && !slot.inFlight.controller.signal.aborted) {
116
+ return {
117
+ status: "single_flight",
118
+ promise: this.attachWaiter(key, slot, slot.inFlight, options.signal)
119
+ };
120
+ }
121
+ const generation = slot.generation;
122
+ const controller = new AbortController();
123
+ const load = {
124
+ generation,
125
+ controller,
126
+ promise: void 0,
127
+ waiterCount: 0,
128
+ settled: false
129
+ };
130
+ const managed = Promise.resolve().then(() => {
131
+ controller.signal.throwIfAborted();
132
+ return loader(controller.signal);
133
+ }).then(
134
+ (snapshot) => {
135
+ load.settled = true;
136
+ const current = this.slots.get(key);
137
+ if (current === slot && current.inFlight === load) {
138
+ current.inFlight = void 0;
139
+ if (current.generation === generation && !controller.signal.aborted && snapshot.sessions.length <= this.maxRetainedSummaries) {
140
+ this.installValue(key, current, snapshot);
141
+ } else if (current.value === void 0) {
142
+ this.slots.delete(key);
143
+ }
144
+ }
145
+ return snapshot;
146
+ },
147
+ (error) => {
148
+ load.settled = true;
149
+ const current = this.slots.get(key);
150
+ if (current === slot && current.inFlight === load) {
151
+ current.inFlight = void 0;
152
+ if (current.value === void 0) this.slots.delete(key);
153
+ }
154
+ throw error;
155
+ }
156
+ );
157
+ load.promise = managed;
158
+ slot.inFlight = load;
159
+ return {
160
+ status: "scan",
161
+ promise: this.attachWaiter(key, slot, load, options.signal)
162
+ };
163
+ }
164
+ invalidate(scope) {
165
+ const key = this.key(scope);
166
+ const slot = this.slots.get(key);
167
+ if (!slot) return;
168
+ slot.generation += 1;
169
+ this.removeValue(slot);
170
+ if (slot.inFlight === void 0) this.slots.delete(key);
171
+ }
172
+ clear() {
173
+ for (const slot of this.slots.values()) {
174
+ if (slot.value) clearTimeout(slot.value.expiryTimer);
175
+ }
176
+ this.slots.clear();
177
+ this.retainedSummaries = 0;
178
+ }
179
+ installValue(key, slot, snapshot) {
180
+ const completedAt = Date.now();
181
+ this.evictFor(snapshot.sessions.length);
182
+ const remainingTtlMs = Math.max(0, this.ttlMs - (Date.now() - completedAt));
183
+ const expiryTimer = setTimeout(() => {
184
+ const current = this.slots.get(key);
185
+ if (current !== slot || current.value?.expiryTimer !== expiryTimer) {
186
+ return;
187
+ }
188
+ this.removeValue(current);
189
+ if (current.inFlight === void 0) this.slots.delete(key);
190
+ }, remainingTtlMs);
191
+ if (typeof expiryTimer.unref === "function") expiryTimer.unref();
192
+ const value = { snapshot, completedAt, expiryTimer };
193
+ slot.value = value;
194
+ this.retainedSummaries += snapshot.sessions.length;
195
+ }
196
+ evictFor(incomingSummaries) {
197
+ while (this.retainedSummaries + incomingSummaries > this.maxRetainedSummaries) {
198
+ let oldest;
199
+ for (const [key, slot] of this.slots) {
200
+ if (slot.value && (oldest === void 0 || slot.value.completedAt < oldest.completedAt)) {
201
+ oldest = { key, slot, completedAt: slot.value.completedAt };
202
+ }
203
+ }
204
+ if (!oldest) return;
205
+ this.removeValue(oldest.slot);
206
+ if (oldest.slot.inFlight === void 0) this.slots.delete(oldest.key);
207
+ }
208
+ }
209
+ removeValue(slot) {
210
+ const value = slot.value;
211
+ if (!value) return;
212
+ clearTimeout(value.expiryTimer);
213
+ this.retainedSummaries -= value.snapshot.sessions.length;
214
+ slot.value = void 0;
215
+ }
216
+ attachWaiter(key, slot, load, signal) {
217
+ load.waiterCount += 1;
218
+ return new Promise((resolve, reject) => {
219
+ let settled = false;
220
+ const settle = /* @__PURE__ */ __name((finish) => {
221
+ if (settled) return;
222
+ settled = true;
223
+ signal?.removeEventListener("abort", onAbort);
224
+ load.waiterCount -= 1;
225
+ if (load.waiterCount === 0 && !load.settled) {
226
+ load.controller.abort(
227
+ new DOMException("No active session list waiters", "AbortError")
228
+ );
229
+ const current = this.slots.get(key);
230
+ if (current === slot && current.inFlight === load) {
231
+ current.inFlight = void 0;
232
+ if (current.value === void 0) this.slots.delete(key);
233
+ }
234
+ }
235
+ finish();
236
+ }, "settle");
237
+ const onAbort = /* @__PURE__ */ __name(() => {
238
+ if (load.settled) return;
239
+ settle(() => reject(signal?.reason));
240
+ }, "onAbort");
241
+ signal?.addEventListener("abort", onAbort, { once: true });
242
+ if (signal?.aborted) onAbort();
243
+ void load.promise.then(
244
+ (snapshot) => settle(() => resolve(snapshot)),
245
+ (error) => settle(() => reject(error))
246
+ );
247
+ });
248
+ }
249
+ key(scope) {
250
+ return JSON.stringify([
251
+ path.resolve(scope.runtimeBaseDir),
252
+ scope.workspaceCwd,
253
+ scope.archiveState
254
+ ]);
255
+ }
256
+ };
257
+
258
+ // packages/cli/src/serve/server/activity-timestamp.ts
259
+ init_esbuild_shims();
260
+ function laterActivityTimestamp(live, persisted) {
261
+ const liveTime = live === void 0 ? Number.NaN : Date.parse(live);
262
+ const persistedTime = persisted === void 0 ? Number.NaN : Date.parse(persisted);
263
+ const liveValid = Number.isFinite(liveTime);
264
+ const persistedValid = Number.isFinite(persistedTime);
265
+ if (liveValid && persistedValid) {
266
+ return liveTime >= persistedTime ? live : persisted;
267
+ }
268
+ if (liveValid) return live;
269
+ if (persistedValid) return persisted;
270
+ return live ?? persisted;
271
+ }
272
+ __name(laterActivityTimestamp, "laterActivityTimestamp");
273
+
274
+ // packages/cli/src/serve/server/session-list.ts
275
+ var DEFAULT_SESSION_PAGE_SIZE = 20;
276
+ var MAX_SESSION_PAGE_SIZE = 100;
277
+ var MAX_ORGANIZED_SESSIONS = 5e4;
278
+ var MAX_EMITTED_CURSOR_SESSION_IDS = 64;
279
+ var PERSISTED_SESSION_LIST_CACHE_TTL_MS = 2e3;
280
+ var persistedSessionListCache = new PersistedSessionListCache(
281
+ PERSISTED_SESSION_LIST_CACHE_TTL_MS,
282
+ MAX_ORGANIZED_SESSIONS
283
+ );
284
+ function invalidateWorkspaceSessionListCache(options) {
285
+ for (const archiveState of options.archiveStates) {
286
+ persistedSessionListCache.invalidate({
287
+ runtimeBaseDir: options.runtimeBaseDir,
288
+ workspaceCwd: options.workspaceCwd,
289
+ archiveState
290
+ });
291
+ }
292
+ }
293
+ __name(invalidateWorkspaceSessionListCache, "invalidateWorkspaceSessionListCache");
294
+ var InvalidCursorError = class extends Error {
295
+ static {
296
+ __name(this, "InvalidCursorError");
297
+ }
298
+ constructor(cursor, kind = "numeric") {
299
+ super(`Invalid cursor: "${cursor}" is not a valid ${kind} cursor`);
300
+ this.name = "InvalidCursorError";
301
+ }
302
+ };
303
+ function parseSessionCursor(cursor) {
304
+ if (cursor === "") return void 0;
305
+ const trimmed = cursor.trim();
306
+ const parsed = Number(trimmed);
307
+ if (trimmed === "" || !Number.isFinite(parsed) || parsed < 0 || parsed > Number.MAX_SAFE_INTEGER) {
308
+ throw new InvalidCursorError(cursor);
309
+ }
310
+ return parsed;
311
+ }
312
+ __name(parseSessionCursor, "parseSessionCursor");
313
+ function parseEmittedSessionIds(value) {
314
+ if (value === void 0) return [];
315
+ if (!Array.isArray(value) || value.some((id) => typeof id !== "string" || id.length === 0)) {
316
+ return void 0;
317
+ }
318
+ return value;
319
+ }
320
+ __name(parseEmittedSessionIds, "parseEmittedSessionIds");
321
+ function parseOrganizedCursor(cursor, expected) {
322
+ if (cursor === "") return void 0;
323
+ try {
324
+ const decoded = Buffer.from(cursor, "base64url").toString("utf8");
325
+ const parsed = JSON.parse(decoded);
326
+ const last = parsed.last;
327
+ if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed) || typeof last !== "object" || last === null || Array.isArray(last) || typeof last.isPinned !== "boolean" || typeof last.activityTime !== "number" || !Number.isFinite(last.activityTime) || typeof last.sessionId !== "string" || last.sessionId.length === 0 || parsed.group !== expected.group || parsed.archiveState !== expected.archiveState || parsed.sourceType !== expected.sourceType || parsed.sourceId !== expected.sourceId || parsed.conversationKind !== expected.conversationKind) {
328
+ throw new Error("invalid organized cursor");
329
+ }
330
+ const emitted = parseEmittedSessionIds(parsed.emitted);
331
+ if (emitted === void 0) {
332
+ throw new Error("invalid organized cursor");
333
+ }
334
+ return { last, emitted };
335
+ } catch {
336
+ throw new InvalidCursorError(cursor, "organized");
337
+ }
338
+ }
339
+ __name(parseOrganizedCursor, "parseOrganizedCursor");
340
+ function encodeOrganizedCursor(last, group, archiveState, sourceType, sourceId, conversationKind, emitted = []) {
341
+ return Buffer.from(
342
+ JSON.stringify({
343
+ group,
344
+ archiveState,
345
+ sourceType,
346
+ sourceId,
347
+ conversationKind,
348
+ last,
349
+ ...emitted.length > 0 ? { emitted } : {}
350
+ }),
351
+ "utf8"
352
+ ).toString("base64url");
353
+ }
354
+ __name(encodeOrganizedCursor, "encodeOrganizedCursor");
355
+ function parseLiveSessionCursor(cursor) {
356
+ if (cursor === "") return void 0;
357
+ try {
358
+ const parsed = JSON.parse(
359
+ Buffer.from(cursor, "base64url").toString("utf8")
360
+ );
361
+ if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed) || typeof parsed.activityTime !== "number" || !Number.isFinite(parsed.activityTime) || typeof parsed.sessionId !== "string" || parsed.sessionId.length === 0) {
362
+ throw new Error("invalid live cursor");
363
+ }
364
+ return parsed;
365
+ } catch {
366
+ throw new InvalidCursorError(cursor, "live");
367
+ }
368
+ }
369
+ __name(parseLiveSessionCursor, "parseLiveSessionCursor");
370
+ function encodeLiveSessionCursor(last) {
371
+ return Buffer.from(JSON.stringify(last), "utf8").toString("base64url");
372
+ }
373
+ __name(encodeLiveSessionCursor, "encodeLiveSessionCursor");
374
+ function matchesSessionMetadataSource(session, filter) {
375
+ if (filter.conversationKind === "standalone-top-level" && classifyTopLevelConversationSource(session)?.kind !== "standalone") {
376
+ return false;
377
+ }
378
+ const sourceTypeMatches = filter.sourceType === void 0 || session.sourceType === filter.sourceType || // Legacy sessions without source metadata belong to the default catalog.
379
+ filter.sourceType === "default" && session.sourceType === void 0;
380
+ return sourceTypeMatches && // sourceId remains exact; only the default source type has legacy fallback.
381
+ (filter.sourceId === void 0 || session.sourceId === filter.sourceId);
382
+ }
383
+ __name(matchesSessionMetadataSource, "matchesSessionMetadataSource");
384
+ function parseMetadataSessionCursor(cursor, expected) {
385
+ if (cursor === "") return void 0;
386
+ try {
387
+ const parsed = JSON.parse(
388
+ Buffer.from(cursor, "base64url").toString("utf8")
389
+ );
390
+ const last = parsed.last;
391
+ if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed) || typeof last !== "object" || last === null || Array.isArray(last) || typeof last.activityTime !== "number" || !Number.isFinite(last.activityTime) || typeof last.sessionId !== "string" || last.sessionId.length === 0 || parsed.parentSessionId !== expected.parentSessionId || parsed.sourceType !== expected.sourceType || parsed.sourceId !== expected.sourceId || parsed.conversationKind !== expected.conversationKind || parsed.archiveState !== expected.archiveState) {
392
+ throw new Error("invalid metadata cursor");
393
+ }
394
+ const emitted = parseEmittedSessionIds(
395
+ parsed.emitted
396
+ );
397
+ if (emitted === void 0) {
398
+ throw new Error("invalid metadata cursor");
399
+ }
400
+ return {
401
+ last: { activityTime: last.activityTime, sessionId: last.sessionId },
402
+ emitted
403
+ };
404
+ } catch {
405
+ throw new InvalidCursorError(
406
+ cursor,
407
+ expected.sourceType === void 0 ? "parent" : "metadata"
408
+ );
409
+ }
410
+ }
411
+ __name(parseMetadataSessionCursor, "parseMetadataSessionCursor");
412
+ function encodeMetadataSessionCursor(last, filter, archiveState, emitted = []) {
413
+ return Buffer.from(
414
+ JSON.stringify({
415
+ ...filter,
416
+ archiveState,
417
+ last,
418
+ ...emitted.length > 0 ? { emitted } : {}
419
+ }),
420
+ "utf8"
421
+ ).toString("base64url");
422
+ }
423
+ __name(encodeMetadataSessionCursor, "encodeMetadataSessionCursor");
424
+ async function enrichWorktreeSidecars(bySessionId, sessionService, archiveState = "active", signal) {
425
+ for (const [sessionId, summary] of bySessionId) {
426
+ signal?.throwIfAborted();
427
+ if (summary.worktree) continue;
428
+ let sidecar;
429
+ try {
430
+ const sidecarPath = sessionService.getWorktreeSessionPathForArchiveState(
431
+ sessionId,
432
+ archiveState
433
+ );
434
+ sidecar = signal ? await readWorktreeSession(sidecarPath, { signal }) : await readWorktreeSession(sidecarPath);
435
+ } catch {
436
+ signal?.throwIfAborted();
437
+ sidecar = null;
438
+ }
439
+ if (sidecar) {
440
+ bySessionId.set(sessionId, {
441
+ ...summary,
442
+ worktree: {
443
+ slug: sidecar.slug,
444
+ path: sidecar.worktreePath,
445
+ branch: sidecar.worktreeBranch
446
+ }
447
+ });
448
+ }
449
+ }
450
+ }
451
+ __name(enrichWorktreeSidecars, "enrichWorktreeSidecars");
452
+ async function enrichPrSidecars(bySessionId, sessionService, archiveState, signal) {
453
+ for (const [sessionId, summary] of bySessionId) {
454
+ signal?.throwIfAborted();
455
+ let sidecar;
456
+ try {
457
+ const sidecarPath = sessionService.getPrSessionPathForArchiveState(
458
+ sessionId,
459
+ archiveState
460
+ );
461
+ sidecar = signal ? await readSessionPrs(sidecarPath, { signal }) : await readSessionPrs(sidecarPath);
462
+ } catch {
463
+ signal?.throwIfAborted();
464
+ sidecar = null;
465
+ }
466
+ if (sidecar) {
467
+ bySessionId.set(sessionId, {
468
+ ...summary,
469
+ prs: sidecarToPrInfos(sidecar)
470
+ });
471
+ }
472
+ }
473
+ }
474
+ __name(enrichPrSidecars, "enrichPrSidecars");
475
+ function toSummary(item) {
476
+ return {
477
+ sessionId: item.sessionId,
478
+ workspaceCwd: item.cwd,
479
+ createdAt: item.startTime,
480
+ updatedAt: new Date(item.mtime).toISOString(),
481
+ displayName: item.customTitle || item.prompt,
482
+ ...item.parentSessionId ? { parentSessionId: item.parentSessionId } : {},
483
+ ...item.sourceType ? { sourceType: item.sourceType } : {},
484
+ ...item.sourceId !== void 0 ? { sourceId: item.sourceId } : {},
485
+ clientCount: 0,
486
+ hasActivePrompt: false,
487
+ isArchived: item.isArchived === true
488
+ };
489
+ }
490
+ __name(toSummary, "toSummary");
491
+ function mergeLiveSessionSummary(existing, live) {
492
+ const merged = {
493
+ ...existing,
494
+ ...live,
495
+ createdAt: existing.createdAt,
496
+ displayName: live.displayName ?? existing.displayName,
497
+ // Immutable lineage; the persisted transcript is authoritative, and a live
498
+ // entry only carries it when spawned this run.
499
+ parentSessionId: existing.parentSessionId ?? live.parentSessionId,
500
+ sourceType: existing.sourceType ?? live.sourceType,
501
+ sourceId: existing.sourceType !== void 0 ? existing.sourceId : live.sourceId,
502
+ updatedAt: laterActivityTimestamp(live.updatedAt, existing.updatedAt),
503
+ clientCount: live.clientCount,
504
+ hasActivePrompt: live.hasActivePrompt,
505
+ isArchived: false
506
+ };
507
+ if (existing.prs || live.prs) {
508
+ merged.prs = mergeSummaryPrs(existing.prs, live.prs);
509
+ }
510
+ return merged;
511
+ }
512
+ __name(mergeLiveSessionSummary, "mergeLiveSessionSummary");
513
+ function sidecarToPrInfos(sidecar) {
514
+ return sidecar.map(({ number, url, state }) => ({
515
+ number,
516
+ url,
517
+ ...state ? { state } : {}
518
+ }));
519
+ }
520
+ __name(sidecarToPrInfos, "sidecarToPrInfos");
521
+ function mergeSummaryPrs(persistedPrs, livePrs) {
522
+ const live = livePrs ?? [];
523
+ const persistedByNumber = new Map(
524
+ (persistedPrs ?? []).map((p) => [p.number, p])
525
+ );
526
+ return [
527
+ ...(persistedPrs ?? []).filter(
528
+ (p) => !live.some((l) => l.number === p.number)
529
+ ),
530
+ ...live.map((l) => {
531
+ const persisted = persistedByNumber.get(l.number);
532
+ return persisted?.state !== void 0 && persisted.state !== l.state ? { ...l, state: persisted.state } : l;
533
+ })
534
+ ];
535
+ }
536
+ __name(mergeSummaryPrs, "mergeSummaryPrs");
537
+ async function liveOnlySummary(live, sessionService, signal) {
538
+ const summary = {
539
+ ...live,
540
+ createdAt: live.createdAt,
541
+ clientCount: live.clientCount,
542
+ hasActivePrompt: live.hasActivePrompt,
543
+ isArchived: false
544
+ };
545
+ let sidecar;
546
+ try {
547
+ const sidecarPath = sessionService.getPrSessionPathForArchiveState(
548
+ live.sessionId,
549
+ "active"
550
+ );
551
+ sidecar = signal ? await readSessionPrs(sidecarPath, { signal }) : await readSessionPrs(sidecarPath);
552
+ } catch {
553
+ signal?.throwIfAborted();
554
+ sidecar = null;
555
+ }
556
+ if (sidecar) {
557
+ summary.prs = mergeSummaryPrs(sidecarToPrInfos(sidecar), live.prs);
558
+ }
559
+ return summary;
560
+ }
561
+ __name(liveOnlySummary, "liveOnlySummary");
562
+ function clonePersistedSummary(session) {
563
+ return {
564
+ ...session,
565
+ ...session.worktree ? { worktree: { ...session.worktree } } : {}
566
+ };
567
+ }
568
+ __name(clonePersistedSummary, "clonePersistedSummary");
569
+ async function loadAllPersistedSummaries(sessionService, archiveState, signal) {
570
+ const scanStartedAt = performance.now();
571
+ signal.throwIfAborted();
572
+ const sessions = [];
573
+ let truncated = false;
574
+ let scanPages = 0;
575
+ let cursor;
576
+ do {
577
+ scanPages += 1;
578
+ const page = await sessionService.listSessions({
579
+ cursor,
580
+ size: 1e4,
581
+ archiveState,
582
+ signal
583
+ });
584
+ signal.throwIfAborted();
585
+ const remaining = MAX_ORGANIZED_SESSIONS - sessions.length;
586
+ sessions.push(...page.items.slice(0, remaining).map(toSummary));
587
+ cursor = page.nextCursor;
588
+ if (page.items.length === 0) {
589
+ break;
590
+ }
591
+ if (page.items.length > remaining || sessions.length >= MAX_ORGANIZED_SESSIONS && cursor !== void 0) {
592
+ writeStderrLine(
593
+ `qwen serve: organized session list truncated at ${MAX_ORGANIZED_SESSIONS} sessions`
594
+ );
595
+ truncated = true;
596
+ break;
597
+ }
598
+ } while (cursor !== void 0);
599
+ const bySessionId = new Map(
600
+ sessions.map((session) => [session.sessionId, session])
601
+ );
602
+ await enrichWorktreeSidecars(
603
+ bySessionId,
604
+ sessionService,
605
+ archiveState,
606
+ signal
607
+ );
608
+ await enrichPrSidecars(bySessionId, sessionService, archiveState, signal);
609
+ signal.throwIfAborted();
610
+ return {
611
+ sessions: [...bySessionId.values()],
612
+ truncated,
613
+ scanPages,
614
+ scanDurationMs: Math.max(0, performance.now() - scanStartedAt)
615
+ };
616
+ }
617
+ __name(loadAllPersistedSummaries, "loadAllPersistedSummaries");
618
+ async function listAllPersistedSummaries(sessionService, workspaceCwd, archiveState, runtimeBaseDir, queryKind, signal) {
619
+ const lookup = persistedSessionListCache.lookup(
620
+ { runtimeBaseDir, workspaceCwd, archiveState },
621
+ (loadSignal) => loadAllPersistedSummaries(sessionService, archiveState, loadSignal),
622
+ { signal }
623
+ );
624
+ addDaemonRequestAttribute(
625
+ "qwen-code.daemon.session_list.cache_status",
626
+ lookup.status
627
+ );
628
+ addDaemonRequestAttribute(
629
+ "qwen-code.daemon.session_list.archive_state",
630
+ archiveState
631
+ );
632
+ addDaemonRequestAttribute(
633
+ "qwen-code.daemon.session_list.query_kind",
634
+ queryKind
635
+ );
636
+ if (lookup.cacheAgeMs !== void 0) {
637
+ addDaemonRequestAttribute(
638
+ "qwen-code.daemon.session_list.cache_age_ms",
639
+ lookup.cacheAgeMs
640
+ );
641
+ }
642
+ const snapshot = await lookup.promise;
643
+ signal?.throwIfAborted();
644
+ addDaemonRequestAttribute(
645
+ "qwen-code.daemon.session_list.persisted_sessions",
646
+ snapshot.sessions.length
647
+ );
648
+ addDaemonRequestAttribute(
649
+ "qwen-code.daemon.session_list.scan_pages",
650
+ snapshot.scanPages
651
+ );
652
+ addDaemonRequestAttribute(
653
+ "qwen-code.daemon.session_list.truncated",
654
+ snapshot.truncated
655
+ );
656
+ if (lookup.status !== "cache_hit") {
657
+ addDaemonRequestAttribute(
658
+ "qwen-code.daemon.session_list.scan_duration_ms",
659
+ snapshot.scanDurationMs
660
+ );
661
+ }
662
+ return snapshot;
663
+ }
664
+ __name(listAllPersistedSummaries, "listAllPersistedSummaries");
665
+ function getSummaryActivityTime(session) {
666
+ const time = Date.parse(session.updatedAt ?? session.createdAt);
667
+ return Number.isFinite(time) ? time : 0;
668
+ }
669
+ __name(getSummaryActivityTime, "getSummaryActivityTime");
670
+ function getLiveSessionCursorKey(session) {
671
+ return {
672
+ activityTime: getSummaryActivityTime(session),
673
+ sessionId: session.sessionId
674
+ };
675
+ }
676
+ __name(getLiveSessionCursorKey, "getLiveSessionCursorKey");
677
+ function compareLiveSessionCursorKeys(a, b) {
678
+ const byTime = b.activityTime - a.activityTime;
679
+ if (byTime !== 0) return byTime;
680
+ return a.sessionId.localeCompare(b.sessionId);
681
+ }
682
+ __name(compareLiveSessionCursorKeys, "compareLiveSessionCursorKeys");
683
+ function compareOrganizedSessions(activityTimeById, a, b) {
684
+ return compareOrganizedCursorKeys(
685
+ getOrganizedCursorKey(activityTimeById, a),
686
+ getOrganizedCursorKey(activityTimeById, b)
687
+ );
688
+ }
689
+ __name(compareOrganizedSessions, "compareOrganizedSessions");
690
+ function getOrganizedCursorKey(activityTimeById, session) {
691
+ return {
692
+ isPinned: session.isPinned === true,
693
+ activityTime: activityTimeById.get(session.sessionId) ?? 0,
694
+ sessionId: session.sessionId
695
+ };
696
+ }
697
+ __name(getOrganizedCursorKey, "getOrganizedCursorKey");
698
+ function compareOrganizedCursorKeys(a, b) {
699
+ const byPinned = Number(b.isPinned) - Number(a.isPinned);
700
+ if (byPinned !== 0) return byPinned;
701
+ const byTime = b.activityTime - a.activityTime;
702
+ if (byTime !== 0) return byTime;
703
+ return a.sessionId.localeCompare(b.sessionId);
704
+ }
705
+ __name(compareOrganizedCursorKeys, "compareOrganizedCursorKeys");
706
+ function nextEmittedSessionIds(options) {
707
+ const candidates = new Set(options.carried);
708
+ for (const row of options.page) {
709
+ if (options.liveSessionIds.has(row.sessionId)) {
710
+ candidates.add(row.sessionId);
711
+ }
712
+ }
713
+ const kept = [];
714
+ for (const sessionId of candidates) {
715
+ const row = options.listedById.get(sessionId);
716
+ if (!row) {
717
+ kept.push({ sessionId, persistedTime: Number.NEGATIVE_INFINITY });
718
+ continue;
719
+ }
720
+ const persistedTime = options.persistedTimeById.get(sessionId);
721
+ if (persistedTime === void 0) {
722
+ kept.push({ sessionId, persistedTime: Number.NEGATIVE_INFINITY });
723
+ continue;
724
+ }
725
+ if (options.reenters(row, persistedTime)) {
726
+ kept.push({ sessionId, persistedTime });
727
+ }
728
+ }
729
+ if (kept.length > MAX_EMITTED_CURSOR_SESSION_IDS) {
730
+ kept.sort((a, b) => a.persistedTime - b.persistedTime);
731
+ kept.length = MAX_EMITTED_CURSOR_SESSION_IDS;
732
+ }
733
+ return kept.map((entry) => entry.sessionId);
734
+ }
735
+ __name(nextEmittedSessionIds, "nextEmittedSessionIds");
736
+ function applyOrganization(session, organization) {
737
+ return {
738
+ ...session,
739
+ groupId: organization?.groupId ?? null,
740
+ color: organization?.color ?? null,
741
+ isPinned: organization?.isPinned === true,
742
+ ...organization?.pinnedAt !== void 0 ? { pinnedAt: organization.pinnedAt } : {}
743
+ };
744
+ }
745
+ __name(applyOrganization, "applyOrganization");
746
+ async function listOrganizedWorkspaceSessionsForResponse(bridge, workspaceCwd, options, pageSize, readOptions) {
747
+ const archiveState = options.archiveState ?? "active";
748
+ const sessionService = new SessionService(workspaceCwd);
749
+ const organizationService = createSessionOrganizationService(workspaceCwd);
750
+ readOptions.signal?.throwIfAborted();
751
+ const snapshot = await organizationService.readSnapshot();
752
+ readOptions.signal?.throwIfAborted();
753
+ const knownGroupIds = new Set(snapshot.groups.map((group2) => group2.id));
754
+ const group = options.group ?? "all";
755
+ if (group !== "all" && group !== "pinned" && group !== "ungrouped" && !knownGroupIds.has(group)) {
756
+ throw new SessionOrganizationError(
757
+ `Group not found: ${group}`,
758
+ "group_not_found",
759
+ "group"
760
+ );
761
+ }
762
+ const cursor = options.cursor !== void 0 ? parseOrganizedCursor(options.cursor, {
763
+ group,
764
+ archiveState,
765
+ sourceType: options.sourceType,
766
+ sourceId: options.sourceId,
767
+ conversationKind: options.conversationKind
768
+ }) : void 0;
769
+ const cursorKey = cursor?.last;
770
+ const emittedBeforePage = new Set(cursor?.emitted ?? []);
771
+ const isFirstPage = cursorKey === void 0;
772
+ let liveMergeFailed = false;
773
+ const bySessionId = /* @__PURE__ */ new Map();
774
+ const persisted = await listAllPersistedSummaries(
775
+ sessionService,
776
+ workspaceCwd,
777
+ archiveState,
778
+ readOptions.runtimeBaseDir,
779
+ "organized",
780
+ readOptions.signal
781
+ );
782
+ readOptions.signal?.throwIfAborted();
783
+ for (const session of persisted.sessions) {
784
+ bySessionId.set(
785
+ session.sessionId,
786
+ applyOrganization(
787
+ clonePersistedSummary(session),
788
+ snapshot.sessions.get(session.sessionId)
789
+ )
790
+ );
791
+ }
792
+ const persistedTimeById = new Map(
793
+ persisted.sessions.map((session) => [
794
+ session.sessionId,
795
+ getSummaryActivityTime(session)
796
+ ])
797
+ );
798
+ const liveSessionIds = /* @__PURE__ */ new Set();
799
+ if (readOptions.mergeLive !== false && archiveState !== "archived") {
800
+ try {
801
+ const liveSessions = bridge.listWorkspaceSessions(workspaceCwd);
802
+ for (const live of liveSessions) {
803
+ liveSessionIds.add(live.sessionId);
804
+ const existing = bySessionId.get(live.sessionId);
805
+ const organization = snapshot.sessions.get(live.sessionId);
806
+ if (existing) {
807
+ bySessionId.set(
808
+ live.sessionId,
809
+ applyOrganization(
810
+ mergeLiveSessionSummary(existing, live),
811
+ organization
812
+ )
813
+ );
814
+ } else if (
815
+ // A live-only row has no persisted key to page by, so it stays a
816
+ // first-page-only insertion as before.
817
+ isFirstPage && // `listAllPersistedSummaries` already scanned every persisted
818
+ // session when the scan wasn't truncated, so a `sessionId` missing
819
+ // from `bySessionId` is definitively new — no disk re-check
820
+ // needed. Re-checking here raced a session that persists its
821
+ // first write (e.g. a `displayName` update) between the scan
822
+ // above and this point: `existing` stayed undefined but
823
+ // `sessionExists` flipped to true, silently dropping the live
824
+ // session from the response instead of merging it.
825
+ (!persisted.truncated || !await (readOptions.signal ? sessionService.sessionExists(live.sessionId, {
826
+ signal: readOptions.signal
827
+ }) : sessionService.sessionExists(live.sessionId)))
828
+ ) {
829
+ bySessionId.set(
830
+ live.sessionId,
831
+ applyOrganization(
832
+ await liveOnlySummary(live, sessionService, readOptions.signal),
833
+ organization
834
+ )
835
+ );
836
+ }
837
+ }
838
+ } catch (error) {
839
+ readOptions.signal?.throwIfAborted();
840
+ liveMergeFailed = true;
841
+ writeStderrLine(
842
+ `qwen serve: organized session list live merge failed; using persisted sessions only: ${error instanceof Error ? error.message : String(error)}`
843
+ );
844
+ }
845
+ }
846
+ const filtered = [...bySessionId.values()].filter((session) => {
847
+ if (!matchesSessionMetadataSource(session, options)) return false;
848
+ if (group === "all") return true;
849
+ if (group === "pinned") return session.isPinned === true;
850
+ if (group === "ungrouped")
851
+ return session.groupId == null && session.color == null;
852
+ return session.color == null && session.groupId === group;
853
+ });
854
+ readOptions.signal?.throwIfAborted();
855
+ const activityTimeById = new Map(
856
+ filtered.map((session) => [
857
+ session.sessionId,
858
+ getSummaryActivityTime(session)
859
+ ])
860
+ );
861
+ filtered.sort((a, b) => compareOrganizedSessions(activityTimeById, a, b));
862
+ readOptions.signal?.throwIfAborted();
863
+ const afterCursor = cursorKey === void 0 ? filtered : filtered.filter(
864
+ (session) => (
865
+ // A row already emitted at a live-derived key stays excluded even
866
+ // if its key regressed behind the cursor (live retirement, or a
867
+ // live-only row that persisted mid-pass).
868
+ !emittedBeforePage.has(session.sessionId) && compareOrganizedCursorKeys(
869
+ cursorKey,
870
+ getOrganizedCursorKey(activityTimeById, session)
871
+ ) < 0
872
+ )
873
+ );
874
+ const page = afterCursor.slice(0, pageSize);
875
+ let nextCursor;
876
+ if (page.length < afterCursor.length) {
877
+ const boundary = getOrganizedCursorKey(
878
+ activityTimeById,
879
+ page[page.length - 1]
880
+ );
881
+ const emitted = nextEmittedSessionIds({
882
+ carried: emittedBeforePage,
883
+ page,
884
+ liveSessionIds,
885
+ listedById: new Map(
886
+ filtered.map((session) => [session.sessionId, session])
887
+ ),
888
+ persistedTimeById,
889
+ // `isPinned` is re-read from the organization snapshot on every page
890
+ // request, so a pin flip between fetches can move the persisted key
891
+ // across the pinned/unpinned blocks. Keep the identity while the key
892
+ // could re-enter under either state.
893
+ reenters: /* @__PURE__ */ __name((row, persistedTime) => [true, false].some(
894
+ (isPinned) => compareOrganizedCursorKeys(boundary, {
895
+ isPinned,
896
+ activityTime: persistedTime,
897
+ sessionId: row.sessionId
898
+ }) < 0
899
+ ), "reenters")
900
+ });
901
+ nextCursor = encodeOrganizedCursor(
902
+ boundary,
903
+ group,
904
+ archiveState,
905
+ options.sourceType,
906
+ options.sourceId,
907
+ options.conversationKind,
908
+ emitted
909
+ );
910
+ }
911
+ return {
912
+ sessions: page,
913
+ ...nextCursor !== void 0 ? { nextCursor } : {},
914
+ ...liveMergeFailed ? { liveMergeFailed: true } : {},
915
+ ...persisted.truncated ? { truncated: true } : {}
916
+ };
917
+ }
918
+ __name(listOrganizedWorkspaceSessionsForResponse, "listOrganizedWorkspaceSessionsForResponse");
919
+ async function listWorkspaceSessionsByMetadataForResponse(bridge, workspaceCwd, options, pageSize, filter, readOptions) {
920
+ const archiveState = options.archiveState ?? "active";
921
+ const sessionService = new SessionService(workspaceCwd);
922
+ const bySessionId = /* @__PURE__ */ new Map();
923
+ const persisted = await listAllPersistedSummaries(
924
+ sessionService,
925
+ workspaceCwd,
926
+ archiveState,
927
+ readOptions.runtimeBaseDir,
928
+ "metadata",
929
+ readOptions.signal
930
+ );
931
+ readOptions.signal?.throwIfAborted();
932
+ const canonicalizeStandaloneIds = filter.conversationKind === "standalone-top-level";
933
+ const conflictedStandaloneIds = /* @__PURE__ */ new Set();
934
+ const persistedTimeById = /* @__PURE__ */ new Map();
935
+ for (const session of persisted.sessions) {
936
+ let sessionId = session.sessionId;
937
+ if (canonicalizeStandaloneIds) {
938
+ const parsed = parseCallerSuppliedSessionId(sessionId);
939
+ if (parsed.kind !== "valid") continue;
940
+ sessionId = parsed.sessionId;
941
+ if (conflictedStandaloneIds.has(sessionId)) continue;
942
+ if (bySessionId.has(sessionId)) {
943
+ bySessionId.delete(sessionId);
944
+ persistedTimeById.delete(sessionId);
945
+ conflictedStandaloneIds.add(sessionId);
946
+ continue;
947
+ }
948
+ }
949
+ bySessionId.set(sessionId, {
950
+ ...clonePersistedSummary(session),
951
+ sessionId
952
+ });
953
+ persistedTimeById.set(sessionId, getSummaryActivityTime(session));
954
+ }
955
+ const liveSessionIds = /* @__PURE__ */ new Set();
956
+ let liveMergeFailed = false;
957
+ if (readOptions.mergeLive !== false && archiveState !== "archived") {
958
+ try {
959
+ for (const live of bridge.listWorkspaceSessions(workspaceCwd)) {
960
+ let sessionId = live.sessionId;
961
+ if (canonicalizeStandaloneIds) {
962
+ const parsed = parseCallerSuppliedSessionId(sessionId);
963
+ if (parsed.kind !== "valid" || conflictedStandaloneIds.has(parsed.sessionId)) {
964
+ continue;
965
+ }
966
+ sessionId = parsed.sessionId;
967
+ }
968
+ const canonicalLive = sessionId === live.sessionId ? live : { ...live, sessionId };
969
+ liveSessionIds.add(sessionId);
970
+ const existing = bySessionId.get(sessionId);
971
+ if (existing) {
972
+ bySessionId.set(
973
+ sessionId,
974
+ mergeLiveSessionSummary(existing, canonicalLive)
975
+ );
976
+ } else if (
977
+ // See the matching comment in
978
+ // `listOrganizedWorkspaceSessionsForResponse`: an untruncated scan
979
+ // already covers every persisted session, so skip the racy
980
+ // re-check when nothing was truncated.
981
+ !persisted.truncated || !await (readOptions.signal ? sessionService.sessionExists(sessionId, {
982
+ signal: readOptions.signal
983
+ }) : sessionService.sessionExists(sessionId))
984
+ ) {
985
+ bySessionId.set(
986
+ sessionId,
987
+ await liveOnlySummary(
988
+ canonicalLive,
989
+ sessionService,
990
+ readOptions.signal
991
+ )
992
+ );
993
+ }
994
+ }
995
+ } catch (error) {
996
+ readOptions.signal?.throwIfAborted();
997
+ liveMergeFailed = true;
998
+ writeStderrLine(
999
+ `qwen serve: session metadata filter live merge failed; using persisted sessions only: ${error instanceof Error ? error.message : String(error)}`
1000
+ );
1001
+ }
1002
+ }
1003
+ const matches = [...bySessionId.values()].filter(
1004
+ (session) => (filter.parentSessionId === void 0 || session.parentSessionId === filter.parentSessionId) && matchesSessionMetadataSource(session, filter)
1005
+ ).sort(
1006
+ (a, b) => compareLiveSessionCursorKeys(
1007
+ getLiveSessionCursorKey(a),
1008
+ getLiveSessionCursorKey(b)
1009
+ )
1010
+ );
1011
+ readOptions.signal?.throwIfAborted();
1012
+ const cursor = options.cursor !== void 0 && options.cursor !== "" ? parseMetadataSessionCursor(options.cursor, {
1013
+ ...filter,
1014
+ archiveState
1015
+ }) : void 0;
1016
+ const cursorKey = cursor?.last;
1017
+ const emittedBeforePage = new Set(cursor?.emitted ?? []);
1018
+ const afterCursor = cursorKey === void 0 ? matches : matches.filter(
1019
+ (session) => (
1020
+ // See the organized path: exclude rows already emitted at a
1021
+ // live-derived key whose key regressed behind the cursor.
1022
+ !emittedBeforePage.has(session.sessionId) && compareLiveSessionCursorKeys(
1023
+ cursorKey,
1024
+ getLiveSessionCursorKey(session)
1025
+ ) < 0
1026
+ )
1027
+ );
1028
+ const page = afterCursor.slice(0, pageSize);
1029
+ let nextCursor;
1030
+ if (page.length < afterCursor.length) {
1031
+ const boundary = getLiveSessionCursorKey(page[page.length - 1]);
1032
+ const emitted = nextEmittedSessionIds({
1033
+ carried: emittedBeforePage,
1034
+ page,
1035
+ liveSessionIds,
1036
+ listedById: new Map(
1037
+ matches.map((session) => [session.sessionId, session])
1038
+ ),
1039
+ persistedTimeById,
1040
+ reenters: /* @__PURE__ */ __name((row, persistedTime) => compareLiveSessionCursorKeys(boundary, {
1041
+ activityTime: persistedTime,
1042
+ sessionId: row.sessionId
1043
+ }) < 0, "reenters")
1044
+ });
1045
+ nextCursor = encodeMetadataSessionCursor(
1046
+ boundary,
1047
+ filter,
1048
+ archiveState,
1049
+ emitted
1050
+ );
1051
+ }
1052
+ return {
1053
+ sessions: page,
1054
+ ...nextCursor !== void 0 ? { nextCursor } : {},
1055
+ ...liveMergeFailed ? { liveMergeFailed: true } : {},
1056
+ ...persisted.truncated ? { truncated: true } : {}
1057
+ };
1058
+ }
1059
+ __name(listWorkspaceSessionsByMetadataForResponse, "listWorkspaceSessionsByMetadataForResponse");
1060
+ async function listWorkspaceSessionsForResponse(bridge, workspaceCwd, options, readOptions = {}) {
1061
+ readOptions.signal?.throwIfAborted();
1062
+ const runtimeBaseDir = new Storage(
1063
+ workspaceCwd,
1064
+ readOptions.runtimeBaseDir
1065
+ ).getRuntimeBaseDir();
1066
+ const result = await Storage.runWithResolvedRuntimeBaseDir(
1067
+ runtimeBaseDir,
1068
+ () => listWorkspaceSessionsForResponseInRuntime(bridge, workspaceCwd, options, {
1069
+ ...readOptions.mergeLive !== void 0 ? { mergeLive: readOptions.mergeLive } : {},
1070
+ ...readOptions.signal !== void 0 ? { signal: readOptions.signal } : {},
1071
+ runtimeBaseDir
1072
+ })
1073
+ );
1074
+ readOptions.signal?.throwIfAborted();
1075
+ return result;
1076
+ }
1077
+ __name(listWorkspaceSessionsForResponse, "listWorkspaceSessionsForResponse");
1078
+ async function listWorkspaceSessionsForResponseInRuntime(bridge, workspaceCwd, options, readOptions) {
1079
+ readOptions.signal?.throwIfAborted();
1080
+ const rawSize = options?.size;
1081
+ const requestedSize = typeof rawSize === "number" && Number.isSafeInteger(rawSize) ? rawSize : DEFAULT_SESSION_PAGE_SIZE;
1082
+ const pageSize = Math.min(Math.max(requestedSize, 1), MAX_SESSION_PAGE_SIZE);
1083
+ if (options?.view === "organized") {
1084
+ return listOrganizedWorkspaceSessionsForResponse(
1085
+ bridge,
1086
+ workspaceCwd,
1087
+ options,
1088
+ pageSize,
1089
+ readOptions
1090
+ );
1091
+ }
1092
+ if (options?.parentSessionId !== void 0 || options?.sourceType !== void 0 || options?.conversationKind !== void 0) {
1093
+ return listWorkspaceSessionsByMetadataForResponse(
1094
+ bridge,
1095
+ workspaceCwd,
1096
+ options,
1097
+ pageSize,
1098
+ {
1099
+ ...options.parentSessionId !== void 0 ? { parentSessionId: options.parentSessionId } : {},
1100
+ ...options.sourceType !== void 0 ? { sourceType: options.sourceType } : {},
1101
+ ...options.sourceId !== void 0 ? { sourceId: options.sourceId } : {},
1102
+ ...options.conversationKind !== void 0 ? { conversationKind: options.conversationKind } : {}
1103
+ },
1104
+ readOptions
1105
+ );
1106
+ }
1107
+ let numericCursor;
1108
+ if (options?.cursor != null) {
1109
+ numericCursor = parseSessionCursor(options.cursor);
1110
+ }
1111
+ const isFirstPage = numericCursor === void 0;
1112
+ const sessionService = new SessionService(workspaceCwd);
1113
+ const archiveState = options?.archiveState ?? "active";
1114
+ const persisted = await sessionService.listSessions({
1115
+ cursor: numericCursor,
1116
+ size: pageSize,
1117
+ archiveState,
1118
+ ...readOptions.signal ? { signal: readOptions.signal } : {}
1119
+ });
1120
+ readOptions.signal?.throwIfAborted();
1121
+ const bySessionId = /* @__PURE__ */ new Map();
1122
+ for (const item of persisted.items) {
1123
+ bySessionId.set(item.sessionId, toSummary(item));
1124
+ }
1125
+ await enrichWorktreeSidecars(
1126
+ bySessionId,
1127
+ sessionService,
1128
+ archiveState,
1129
+ readOptions.signal
1130
+ );
1131
+ await enrichPrSidecars(
1132
+ bySessionId,
1133
+ sessionService,
1134
+ archiveState,
1135
+ readOptions.signal
1136
+ );
1137
+ readOptions.signal?.throwIfAborted();
1138
+ if (archiveState === "archived" || readOptions.mergeLive === false) {
1139
+ const sessions2 = [...bySessionId.values()];
1140
+ const nextCursor2 = persisted.nextCursor != null ? String(persisted.nextCursor) : void 0;
1141
+ return { sessions: sessions2, nextCursor: nextCursor2 };
1142
+ }
1143
+ const liveSessions = bridge.listWorkspaceSessions(workspaceCwd);
1144
+ for (const live of liveSessions) {
1145
+ const existing = bySessionId.get(live.sessionId);
1146
+ if (existing) {
1147
+ bySessionId.set(live.sessionId, mergeLiveSessionSummary(existing, live));
1148
+ } else if (isFirstPage && // If this is a complete scan (no further pages), a missing
1149
+ // `sessionId` here is definitively new — no disk re-check needed.
1150
+ // Re-checking raced a session that persists its first write (e.g. a
1151
+ // `displayName` update) between the scan above and this point:
1152
+ // `existing` stayed undefined but `sessionExists` flipped to true,
1153
+ // silently dropping the live session from the response instead of
1154
+ // merging it.
1155
+ (persisted.nextCursor == null || !await (readOptions.signal ? sessionService.sessionExists(live.sessionId, {
1156
+ signal: readOptions.signal
1157
+ }) : sessionService.sessionExists(live.sessionId)))) {
1158
+ bySessionId.set(
1159
+ live.sessionId,
1160
+ await liveOnlySummary(live, sessionService, readOptions.signal)
1161
+ );
1162
+ }
1163
+ }
1164
+ const sessions = [...bySessionId.values()].sort((a, b) => {
1165
+ const aTime = Date.parse(a.updatedAt ?? a.createdAt);
1166
+ const bTime = Date.parse(b.updatedAt ?? b.createdAt);
1167
+ return bTime - aTime;
1168
+ });
1169
+ readOptions.signal?.throwIfAborted();
1170
+ const nextCursor = persisted.nextCursor != null ? String(persisted.nextCursor) : void 0;
1171
+ return { sessions, nextCursor };
1172
+ }
1173
+ __name(listWorkspaceSessionsForResponseInRuntime, "listWorkspaceSessionsForResponseInRuntime");
1174
+ async function listLiveWorkspaceSessionsForResponse(bridge, workspaceCwd, options, readOptions = {}) {
1175
+ const runtimeBaseDir = new Storage(
1176
+ workspaceCwd,
1177
+ readOptions.runtimeBaseDir
1178
+ ).getRuntimeBaseDir();
1179
+ return Storage.runWithResolvedRuntimeBaseDir(runtimeBaseDir, async () => {
1180
+ const rawSize = options?.size;
1181
+ const requestedSize = typeof rawSize === "number" && Number.isSafeInteger(rawSize) ? rawSize : DEFAULT_SESSION_PAGE_SIZE;
1182
+ const pageSize = Math.min(
1183
+ Math.max(requestedSize, 1),
1184
+ MAX_SESSION_PAGE_SIZE
1185
+ );
1186
+ const cursorKey = options?.cursor !== void 0 ? parseLiveSessionCursor(options.cursor) : void 0;
1187
+ const sessions = bridge.listWorkspaceSessions(workspaceCwd).sort(
1188
+ (a, b) => compareLiveSessionCursorKeys(
1189
+ getLiveSessionCursorKey(a),
1190
+ getLiveSessionCursorKey(b)
1191
+ )
1192
+ );
1193
+ const afterCursor = cursorKey === void 0 ? sessions : sessions.filter(
1194
+ (session) => compareLiveSessionCursorKeys(
1195
+ cursorKey,
1196
+ getLiveSessionCursorKey(session)
1197
+ ) < 0
1198
+ );
1199
+ const page = afterCursor.slice(0, pageSize);
1200
+ const sessionService = new SessionService(workspaceCwd);
1201
+ const enriched = await Promise.all(
1202
+ page.map(
1203
+ (summary) => liveOnlySummary(summary, sessionService, readOptions.signal)
1204
+ )
1205
+ );
1206
+ const nextCursor = page.length < afterCursor.length ? encodeLiveSessionCursor(
1207
+ getLiveSessionCursorKey(page[page.length - 1])
1208
+ ) : void 0;
1209
+ return {
1210
+ sessions: enriched,
1211
+ ...nextCursor !== void 0 ? { nextCursor } : {}
1212
+ };
1213
+ });
1214
+ }
1215
+ __name(listLiveWorkspaceSessionsForResponse, "listLiveWorkspaceSessionsForResponse");
1216
+ async function getWorkspaceSessionInfoForResponse(bridge, workspaceCwd, options = {}) {
1217
+ const counts = await new SessionService(workspaceCwd).getSessionInfoCounts();
1218
+ return {
1219
+ active: counts.active,
1220
+ archived: counts.archived,
1221
+ total: counts.total,
1222
+ ...options.includeLive === false ? {} : { live: bridge.listWorkspaceSessions(workspaceCwd).length },
1223
+ expensive: true,
1224
+ cost: "disk_scan",
1225
+ ...counts.truncated ? { truncated: true } : {}
1226
+ };
1227
+ }
1228
+ __name(getWorkspaceSessionInfoForResponse, "getWorkspaceSessionInfoForResponse");
1229
+ function parseSessionPageSizeQuery(raw) {
1230
+ if (typeof raw !== "string") return void 0;
1231
+ const trimmed = raw.trim();
1232
+ if (!/^[+-]?\d+$/.test(trimmed)) return void 0;
1233
+ const parsed = Number.parseInt(trimmed, 10);
1234
+ if (!Number.isFinite(parsed)) return void 0;
1235
+ if (Number.isSafeInteger(parsed)) return parsed;
1236
+ return trimmed.startsWith("-") ? 1 : MAX_SESSION_PAGE_SIZE;
1237
+ }
1238
+ __name(parseSessionPageSizeQuery, "parseSessionPageSizeQuery");
1239
+
1240
+ // packages/cli/src/serve/workspace-runtime-storage.ts
1241
+ init_esbuild_shims();
1242
+ function runWithWorkspaceRuntimeStorage(runtime, fn) {
1243
+ return Storage.runWithResolvedRuntimeBaseDir(
1244
+ runtime.sessionRuntimeBaseDir,
1245
+ fn
1246
+ );
1247
+ }
1248
+ __name(runWithWorkspaceRuntimeStorage, "runWithWorkspaceRuntimeStorage");
1249
+ function createWorkspaceRuntimeSessionService(runtime, options = {}) {
1250
+ return new SessionService(runtime.workspaceCwd, {
1251
+ ...options,
1252
+ runtimeBaseDir: runtime.sessionRuntimeBaseDir
1253
+ });
1254
+ }
1255
+ __name(createWorkspaceRuntimeSessionService, "createWorkspaceRuntimeSessionService");
1256
+
1257
+ // packages/cli/src/serve/server/session-archive.ts
1258
+ init_esbuild_shims();
1259
+
1260
+ // packages/cli/src/serve/scheduled-task-session-lifecycle.ts
1261
+ init_esbuild_shims();
1262
+ function isBoundTask(task) {
1263
+ return typeof task.sessionId === "string" && task.sessionId.length > 0;
1264
+ }
1265
+ __name(isBoundTask, "isBoundTask");
1266
+ async function disableTasksForSessions(projectRoot, sessionIds, options = {}) {
1267
+ if (sessionIds.length === 0) return;
1268
+ const targets = new Set(sessionIds);
1269
+ await updateCronTasks(
1270
+ projectRoot,
1271
+ (tasks) => {
1272
+ let changed = false;
1273
+ const next = tasks.map((task) => {
1274
+ if (isBoundTask(task) && targets.has(task.sessionId) && task.enabled !== false) {
1275
+ changed = true;
1276
+ return { ...task, enabled: false, disabledByArchive: true };
1277
+ }
1278
+ return task;
1279
+ });
1280
+ return changed ? next : tasks;
1281
+ },
1282
+ options
1283
+ );
1284
+ }
1285
+ __name(disableTasksForSessions, "disableTasksForSessions");
1286
+ async function enableTasksForSessions(projectRoot, sessionIds, now = Date.now(), options = {}) {
1287
+ if (sessionIds.length === 0) return;
1288
+ const targets = new Set(sessionIds);
1289
+ await updateCronTasks(
1290
+ projectRoot,
1291
+ (tasks) => {
1292
+ let changed = false;
1293
+ const next = tasks.map((task) => {
1294
+ if (isBoundTask(task) && targets.has(task.sessionId) && task.enabled === false && task.disabledByArchive === true) {
1295
+ changed = true;
1296
+ const resumed = { ...task, enabled: true };
1297
+ delete resumed.disabledByArchive;
1298
+ const minute = now - now % 6e4;
1299
+ if (resumed.recurring) {
1300
+ resumed.lastFiredAt = minute;
1301
+ } else {
1302
+ resumed.createdAt = now;
1303
+ resumed.lastFiredAt = minute;
1304
+ }
1305
+ return resumed;
1306
+ }
1307
+ return task;
1308
+ });
1309
+ return changed ? next : tasks;
1310
+ },
1311
+ options
1312
+ );
1313
+ }
1314
+ __name(enableTasksForSessions, "enableTasksForSessions");
1315
+ async function removeTasksForSessions(projectRoot, sessionIds, options = {}) {
1316
+ if (sessionIds.length === 0) return;
1317
+ const targets = new Set(sessionIds);
1318
+ await updateCronTasks(
1319
+ projectRoot,
1320
+ (tasks) => {
1321
+ const next = tasks.filter(
1322
+ (task) => !isBoundTask(task) || !targets.has(task.sessionId)
1323
+ );
1324
+ return next.length === tasks.length ? tasks : next;
1325
+ },
1326
+ options
1327
+ );
1328
+ }
1329
+ __name(removeTasksForSessions, "removeTasksForSessions");
1330
+
1331
+ // packages/cli/src/serve/server/session-archive.ts
1332
+ var DaemonDrainingError = class extends Error {
1333
+ static {
1334
+ __name(this, "DaemonDrainingError");
1335
+ }
1336
+ name = "DaemonDrainingError";
1337
+ code = "daemon_draining";
1338
+ constructor() {
1339
+ super("The daemon is draining and no longer accepts session maintenance.");
1340
+ }
1341
+ };
1342
+ var SessionArchiveCoordinator = class {
1343
+ static {
1344
+ __name(this, "SessionArchiveCoordinator");
1345
+ }
1346
+ exclusive = /* @__PURE__ */ new Set();
1347
+ shared = /* @__PURE__ */ new Map();
1348
+ sharedDrains = /* @__PURE__ */ new Map();
1349
+ maintenanceSealed = false;
1350
+ activeMaintenance = 0;
1351
+ maintenanceDrain;
1352
+ // Lock keys are canonicalized like every other session-id lookup: batch
1353
+ // delete/archive/unarchive lock raw caller spellings while restore locks
1354
+ // the request spelling, and on a case-insensitive filesystem both reach
1355
+ // the same transcript file — uncanonicalized keys would let a differently
1356
+ // cased caller id slip past a held guard and unlink it mid-restore.
1357
+ assertNotTransitioning(sessionId) {
1358
+ if (this.exclusive.has(normalizeSessionIdForLookup(sessionId))) {
1359
+ throw new SessionArchivingError(sessionId);
1360
+ }
1361
+ }
1362
+ async runExclusiveMany(sessionIds, fn) {
1363
+ if (this.maintenanceSealed) {
1364
+ throw new DaemonDrainingError();
1365
+ }
1366
+ const uniqueSessionIds = [
1367
+ ...new Set(sessionIds.map(normalizeSessionIdForLookup))
1368
+ ];
1369
+ for (const sessionId of uniqueSessionIds) {
1370
+ this.assertNotTransitioning(sessionId);
1371
+ if ((this.shared.get(sessionId) ?? 0) > 0) {
1372
+ throw new SessionArchivingError(sessionId, "shared");
1373
+ }
1374
+ }
1375
+ for (const sessionId of uniqueSessionIds) {
1376
+ this.exclusive.add(sessionId);
1377
+ }
1378
+ this.activeMaintenance++;
1379
+ try {
1380
+ return await fn();
1381
+ } finally {
1382
+ for (const sessionId of uniqueSessionIds) {
1383
+ this.exclusive.delete(sessionId);
1384
+ }
1385
+ this.activeMaintenance--;
1386
+ if (this.activeMaintenance === 0) {
1387
+ this.maintenanceDrain?.resolve();
1388
+ this.maintenanceDrain = void 0;
1389
+ }
1390
+ }
1391
+ }
1392
+ async runExclusiveAfterShared(rawSessionId, fn) {
1393
+ if (this.maintenanceSealed) {
1394
+ throw new DaemonDrainingError();
1395
+ }
1396
+ const sessionId = normalizeSessionIdForLookup(rawSessionId);
1397
+ this.assertNotTransitioning(sessionId);
1398
+ this.exclusive.add(sessionId);
1399
+ this.activeMaintenance++;
1400
+ try {
1401
+ const sharedCount = this.shared.get(sessionId) ?? 0;
1402
+ if (sharedCount > 0) {
1403
+ let drain = this.sharedDrains.get(sessionId);
1404
+ if (!drain) {
1405
+ let resolve;
1406
+ const promise = new Promise((done) => {
1407
+ resolve = done;
1408
+ });
1409
+ drain = { promise, resolve };
1410
+ this.sharedDrains.set(sessionId, drain);
1411
+ }
1412
+ await drain.promise;
1413
+ }
1414
+ return await fn();
1415
+ } finally {
1416
+ this.sharedDrains.delete(sessionId);
1417
+ this.exclusive.delete(sessionId);
1418
+ this.activeMaintenance--;
1419
+ if (this.activeMaintenance === 0) {
1420
+ this.maintenanceDrain?.resolve();
1421
+ this.maintenanceDrain = void 0;
1422
+ }
1423
+ }
1424
+ }
1425
+ sealMaintenanceAndWait() {
1426
+ this.maintenanceSealed = true;
1427
+ if (this.activeMaintenance === 0) {
1428
+ return Promise.resolve();
1429
+ }
1430
+ if (!this.maintenanceDrain) {
1431
+ let resolve;
1432
+ const promise = new Promise((done) => {
1433
+ resolve = done;
1434
+ });
1435
+ this.maintenanceDrain = { promise, resolve };
1436
+ }
1437
+ return this.maintenanceDrain.promise;
1438
+ }
1439
+ async runSharedMany(sessionIds, fn) {
1440
+ if (this.maintenanceSealed) {
1441
+ throw new DaemonDrainingError();
1442
+ }
1443
+ const uniqueSessionIds = [
1444
+ ...new Set(sessionIds.map(normalizeSessionIdForLookup))
1445
+ ];
1446
+ for (const sessionId of uniqueSessionIds) {
1447
+ this.assertNotTransitioning(sessionId);
1448
+ }
1449
+ for (const sessionId of uniqueSessionIds) {
1450
+ this.shared.set(sessionId, (this.shared.get(sessionId) ?? 0) + 1);
1451
+ }
1452
+ this.activeMaintenance++;
1453
+ try {
1454
+ return await fn();
1455
+ } finally {
1456
+ for (const sessionId of uniqueSessionIds) {
1457
+ const count = (this.shared.get(sessionId) ?? 1) - 1;
1458
+ if (count <= 0) {
1459
+ this.shared.delete(sessionId);
1460
+ this.sharedDrains.get(sessionId)?.resolve();
1461
+ this.sharedDrains.delete(sessionId);
1462
+ } else {
1463
+ this.shared.set(sessionId, count);
1464
+ }
1465
+ }
1466
+ this.activeMaintenance--;
1467
+ if (this.activeMaintenance === 0) {
1468
+ this.maintenanceDrain?.resolve();
1469
+ this.maintenanceDrain = void 0;
1470
+ }
1471
+ }
1472
+ }
1473
+ };
1474
+ async function runWithDaemonWriterLease(params) {
1475
+ const {
1476
+ action,
1477
+ sessionId,
1478
+ service,
1479
+ mutate,
1480
+ mutationAppliedAfterError,
1481
+ afterMutationApplied
1482
+ } = params;
1483
+ let lease;
1484
+ try {
1485
+ const leaseOptions = {
1486
+ processKind: "daemon",
1487
+ reclaimPolicy: "never",
1488
+ takeoverPolicy: "certified"
1489
+ };
1490
+ try {
1491
+ lease = await service.acquireSessionWriterLease(sessionId, leaseOptions);
1492
+ } catch (error) {
1493
+ if (!(error instanceof SessionWriterUnavailableError) && !(error instanceof SessionTranscriptChangedError)) {
1494
+ throw error;
1495
+ }
1496
+ lease = await service.acquireSessionMaintenanceLease(
1497
+ sessionId,
1498
+ leaseOptions
1499
+ );
1500
+ }
1501
+ } catch (error) {
1502
+ return { mutationApplied: false, error };
1503
+ }
1504
+ let value;
1505
+ let mutationApplied = false;
1506
+ let mutationError;
1507
+ try {
1508
+ const mutation = await mutate(
1509
+ () => lease.assertOwnedAndUnchanged(),
1510
+ () => lease.assertCleanupOwned()
1511
+ );
1512
+ value = mutation.value;
1513
+ mutationApplied = mutation.mutationApplied;
1514
+ } catch (error) {
1515
+ mutationError = error;
1516
+ try {
1517
+ mutationApplied = await mutationAppliedAfterError();
1518
+ } catch {
1519
+ mutationApplied = false;
1520
+ }
1521
+ }
1522
+ let maintenanceError;
1523
+ if (mutationApplied) {
1524
+ try {
1525
+ await afterMutationApplied();
1526
+ } catch (error) {
1527
+ maintenanceError = error;
1528
+ logSessionArchiveWarning(
1529
+ `scheduled task lifecycle update failed action=${action} workspace=${safeLogValue(
1530
+ service.getProjectRoot()
1531
+ )} session=${safeLogValue(sessionId)} error=${safeLogValue(
1532
+ errorMessage(error)
1533
+ )}`
1534
+ );
1535
+ }
1536
+ }
1537
+ let releaseError;
1538
+ try {
1539
+ await lease.release();
1540
+ } catch (error) {
1541
+ releaseError = error;
1542
+ }
1543
+ if (releaseError !== void 0) {
1544
+ logMaintenanceLeaseReleaseFailure({
1545
+ action,
1546
+ workspace: service.getProjectRoot(),
1547
+ sessionId,
1548
+ error: releaseError,
1549
+ mutationApplied
1550
+ });
1551
+ if (mutationError !== void 0) {
1552
+ logSessionArchiveWarning(
1553
+ `session maintenance mutation also failed action=${action} workspace=${safeLogValue(
1554
+ service.getProjectRoot()
1555
+ )} session=${safeLogValue(sessionId)} error=${safeLogValue(
1556
+ errorMessage(mutationError)
1557
+ )}`
1558
+ );
1559
+ }
1560
+ return { mutationApplied, error: releaseError, maintenanceError };
1561
+ }
1562
+ if (mutationError !== void 0) {
1563
+ return { mutationApplied, error: mutationError, maintenanceError };
1564
+ }
1565
+ return { value, mutationApplied, maintenanceError };
1566
+ }
1567
+ __name(runWithDaemonWriterLease, "runWithDaemonWriterLease");
1568
+ function logMaintenanceLeaseReleaseFailure(params) {
1569
+ const errorKind = typeof params.error === "object" && params.error !== null && typeof params.error.errorKind === "string" ? params.error.errorKind : "unknown";
1570
+ logSessionArchiveWarning(
1571
+ `session maintenance lease release failed action=${params.action} workspace=${safeLogValue(
1572
+ params.workspace
1573
+ )} session=${safeLogValue(params.sessionId)} errorKind=${safeLogValue(
1574
+ errorKind
1575
+ )} mutationApplied=${params.mutationApplied}`
1576
+ );
1577
+ }
1578
+ __name(logMaintenanceLeaseReleaseFailure, "logMaintenanceLeaseReleaseFailure");
1579
+ async function classifySessionLocation(service, sessionId) {
1580
+ return service.getMaintainableSessionLocation(sessionId);
1581
+ }
1582
+ __name(classifySessionLocation, "classifySessionLocation");
1583
+ function sessionLocationError(sessionId) {
1584
+ const error = new SessionConflictError(sessionId);
1585
+ error.message = `Session "${sessionId}" exists in both active and archived directories. Retry with resolveConflicts: true to keep one copy.`;
1586
+ return error;
1587
+ }
1588
+ __name(sessionLocationError, "sessionLocationError");
1589
+ function updateScheduledTaskForMaintenance(service, sessionId, action, assertCanMutate) {
1590
+ if (action === "archive") {
1591
+ return disableTasksForSessions(service.getProjectRoot(), [sessionId], {
1592
+ assertCanCommit: assertCanMutate
1593
+ });
1594
+ }
1595
+ if (action === "unarchive") {
1596
+ return enableTasksForSessions(
1597
+ service.getProjectRoot(),
1598
+ [sessionId],
1599
+ Date.now(),
1600
+ { assertCanCommit: assertCanMutate }
1601
+ );
1602
+ }
1603
+ return removeTasksForSessions(service.getProjectRoot(), [sessionId], {
1604
+ assertCanCommit: assertCanMutate
1605
+ });
1606
+ }
1607
+ __name(updateScheduledTaskForMaintenance, "updateScheduledTaskForMaintenance");
1608
+ async function deletePersistedSessionWithLease(service, sessionId, assertCanMutate) {
1609
+ const initialLocation = await classifySessionLocation(service, sessionId);
1610
+ if (initialLocation === void 0) {
1611
+ let maintenanceError;
1612
+ try {
1613
+ assertCanMutate?.();
1614
+ await updateScheduledTaskForMaintenance(
1615
+ service,
1616
+ sessionId,
1617
+ "delete",
1618
+ assertCanMutate
1619
+ );
1620
+ } catch (error) {
1621
+ maintenanceError = error;
1622
+ logSessionArchiveWarning(
1623
+ `scheduled task lifecycle update failed action=delete workspace=${safeLogValue(
1624
+ service.getProjectRoot()
1625
+ )} session=${safeLogValue(sessionId)} error=${safeLogValue(
1626
+ errorMessage(error)
1627
+ )}`
1628
+ );
1629
+ }
1630
+ return {
1631
+ kind: "notFound",
1632
+ mutationApplied: false,
1633
+ maintenanceError
1634
+ };
1635
+ }
1636
+ const mutation = await runWithDaemonWriterLease({
1637
+ action: "delete",
1638
+ sessionId,
1639
+ service,
1640
+ mutate: /* @__PURE__ */ __name(async (assertOwnedAndUnchanged, assertCleanupOwned) => {
1641
+ const lockedLocation = await classifySessionLocation(service, sessionId);
1642
+ if (lockedLocation === void 0) {
1643
+ return {
1644
+ value: "notFound",
1645
+ mutationApplied: false
1646
+ };
1647
+ }
1648
+ const removed = await service.removeSession(sessionId, {
1649
+ assertStorageUnchanged: assertOwnedAndUnchanged,
1650
+ assertCanMutate,
1651
+ assertCleanupOwned
1652
+ });
1653
+ return {
1654
+ value: removed ? "removed" : "notFound",
1655
+ mutationApplied: removed
1656
+ };
1657
+ }, "mutate"),
1658
+ mutationAppliedAfterError: /* @__PURE__ */ __name(async () => await classifySessionLocation(service, sessionId) === void 0, "mutationAppliedAfterError"),
1659
+ afterMutationApplied: /* @__PURE__ */ __name(async () => {
1660
+ assertCanMutate?.();
1661
+ await updateScheduledTaskForMaintenance(
1662
+ service,
1663
+ sessionId,
1664
+ "delete",
1665
+ assertCanMutate
1666
+ );
1667
+ }, "afterMutationApplied")
1668
+ });
1669
+ if (mutation.error !== void 0) {
1670
+ return {
1671
+ kind: "error",
1672
+ error: mutation.error,
1673
+ mutationApplied: mutation.mutationApplied,
1674
+ maintenanceError: mutation.maintenanceError
1675
+ };
1676
+ }
1677
+ return {
1678
+ kind: mutation.value ?? "notFound",
1679
+ mutationApplied: mutation.mutationApplied,
1680
+ maintenanceError: mutation.maintenanceError
1681
+ };
1682
+ }
1683
+ __name(deletePersistedSessionWithLease, "deletePersistedSessionWithLease");
1684
+ async function deleteDaemonSessions(params) {
1685
+ const {
1686
+ sessionIds,
1687
+ service,
1688
+ bridge,
1689
+ coordinator,
1690
+ coordinatorLockHeld = false,
1691
+ assertCanMutate,
1692
+ onError
1693
+ } = params;
1694
+ const uniqueSessionIds = [
1695
+ ...new Set(sessionIds.map(normalizeSessionIdForLookup))
1696
+ ];
1697
+ if (!coordinatorLockHeld) {
1698
+ for (const sessionId of uniqueSessionIds) {
1699
+ coordinator.assertNotTransitioning(sessionId);
1700
+ }
1701
+ }
1702
+ const results = await Promise.all(
1703
+ uniqueSessionIds.map(async (sessionId) => {
1704
+ try {
1705
+ const mutateSession = /* @__PURE__ */ __name(async () => {
1706
+ assertCanMutate?.();
1707
+ const removePersistedSession = /* @__PURE__ */ __name(async () => {
1708
+ const result = await deletePersistedSessionWithLease(
1709
+ service,
1710
+ sessionId,
1711
+ assertCanMutate
1712
+ );
1713
+ if (result.kind === "error") {
1714
+ onError?.({
1715
+ phase: "remove",
1716
+ sessionId,
1717
+ error: errorMessage(result.error)
1718
+ });
1719
+ return result;
1720
+ }
1721
+ try {
1722
+ if (assertCanMutate) {
1723
+ await bridge.deleteSessionAttachments(sessionId, {
1724
+ assertCanCommit: assertCanMutate
1725
+ });
1726
+ } else {
1727
+ await bridge.deleteSessionAttachments(sessionId);
1728
+ }
1729
+ return result;
1730
+ } catch (error) {
1731
+ onError?.({
1732
+ phase: "delete",
1733
+ sessionId,
1734
+ error: errorMessage(error)
1735
+ });
1736
+ return {
1737
+ kind: "error",
1738
+ error,
1739
+ mutationApplied: result.mutationApplied,
1740
+ maintenanceError: result.maintenanceError
1741
+ };
1742
+ }
1743
+ }, "removePersistedSession");
1744
+ try {
1745
+ await bridge.closeSession(sessionId);
1746
+ } catch (error) {
1747
+ if (isSessionNotFoundError(error)) {
1748
+ return await removePersistedSession();
1749
+ }
1750
+ onError?.({
1751
+ phase: "close",
1752
+ sessionId,
1753
+ error: errorMessage(error)
1754
+ });
1755
+ return {
1756
+ kind: "error",
1757
+ error,
1758
+ mutationApplied: false
1759
+ };
1760
+ }
1761
+ return await removePersistedSession();
1762
+ }, "mutateSession");
1763
+ return await (coordinatorLockHeld ? mutateSession() : coordinator.runExclusiveMany([sessionId], mutateSession));
1764
+ } catch (error) {
1765
+ if (error instanceof DaemonDrainingError) {
1766
+ throw error;
1767
+ }
1768
+ onError?.({
1769
+ phase: "delete",
1770
+ sessionId,
1771
+ error: errorMessage(error)
1772
+ });
1773
+ return {
1774
+ kind: "error",
1775
+ error,
1776
+ mutationApplied: false
1777
+ };
1778
+ }
1779
+ })
1780
+ );
1781
+ const removed = [];
1782
+ const notFound = [];
1783
+ const errors = [];
1784
+ for (let i = 0; i < results.length; i++) {
1785
+ const sessionId = uniqueSessionIds[i];
1786
+ const result = results[i];
1787
+ if (result.kind === "removed") {
1788
+ removed.push(sessionId);
1789
+ } else if (result.kind === "notFound") {
1790
+ notFound.push(sessionId);
1791
+ } else {
1792
+ errors.push({ sessionId, error: errorMessage(result.error) });
1793
+ }
1794
+ if (result.maintenanceError !== void 0) {
1795
+ errors.push({
1796
+ sessionId,
1797
+ error: "Scheduled task lifecycle update failed."
1798
+ });
1799
+ }
1800
+ }
1801
+ return { removed, notFound, errors };
1802
+ }
1803
+ __name(deleteDaemonSessions, "deleteDaemonSessions");
1804
+ async function deleteDaemonSessionIfOrphan(params) {
1805
+ const { sessionId, service, bridge, coordinator } = params;
1806
+ coordinator.assertNotTransitioning(sessionId);
1807
+ const result = await coordinator.runExclusiveMany([sessionId], async () => {
1808
+ let killed = false;
1809
+ try {
1810
+ killed = await bridge.killSession(sessionId, {
1811
+ requireZeroAttaches: true
1812
+ });
1813
+ } catch (error) {
1814
+ if (!isSessionNotFoundError(error)) throw error;
1815
+ killed = true;
1816
+ }
1817
+ if (!killed) {
1818
+ return void 0;
1819
+ }
1820
+ return deletePersistedSessionWithLease(service, sessionId);
1821
+ });
1822
+ if (result === void 0) {
1823
+ return false;
1824
+ }
1825
+ if (result.kind === "error") {
1826
+ throw result.error;
1827
+ }
1828
+ bridge.markSessionCatalogChanged();
1829
+ return true;
1830
+ }
1831
+ __name(deleteDaemonSessionIfOrphan, "deleteDaemonSessionIfOrphan");
1832
+ async function assertSessionLoadable(workspaceCwd, sessionId, runtimeBaseDir, options = {}) {
1833
+ const service = new SessionService(workspaceCwd, {
1834
+ runtimeBaseDir
1835
+ });
1836
+ const location = await service.getSessionLocation(sessionId);
1837
+ if (location === "archived") {
1838
+ throw new SessionArchivedError(sessionId);
1839
+ }
1840
+ if (location === "conflict") {
1841
+ if (options.allowActiveConflict) {
1842
+ try {
1843
+ await service.findSessionIdIgnoringCase(sessionId);
1844
+ } catch (error) {
1845
+ if (error instanceof SessionIdCaseConflictError && error.reason === "case_conflict" && error.candidateSessionId === sessionId) {
1846
+ return "active";
1847
+ }
1848
+ if (!(error instanceof SessionIdCaseConflictError)) throw error;
1849
+ }
1850
+ }
1851
+ throw new SessionConflictError(sessionId);
1852
+ }
1853
+ return location;
1854
+ }
1855
+ __name(assertSessionLoadable, "assertSessionLoadable");
1856
+ async function resolveSessionIdForRestore(service, sessionId) {
1857
+ try {
1858
+ return await service.findSessionIdIgnoringCase(sessionId);
1859
+ } catch (error) {
1860
+ if (error instanceof SessionIdCaseConflictError) {
1861
+ if (error.candidateSessionId === sessionId) return sessionId;
1862
+ throw new SessionConflictError(sessionId);
1863
+ }
1864
+ throw error;
1865
+ }
1866
+ }
1867
+ __name(resolveSessionIdForRestore, "resolveSessionIdForRestore");
1868
+ async function assertSessionRestorable(workspaceCwd, sessionId, requestedSessionId, runtimeBaseDir) {
1869
+ const location = await new SessionService(workspaceCwd, {
1870
+ runtimeBaseDir
1871
+ }).getSessionLocation(sessionId);
1872
+ if (location === "archived") {
1873
+ throw new SessionArchivedError(sessionId);
1874
+ }
1875
+ if (location === "conflict") {
1876
+ if (sessionId !== requestedSessionId) {
1877
+ throw new SessionConflictError(requestedSessionId);
1878
+ }
1879
+ return "active";
1880
+ }
1881
+ return location;
1882
+ }
1883
+ __name(assertSessionRestorable, "assertSessionRestorable");
1884
+ async function assertSessionArchived(workspaceCwd, sessionId, runtimeBaseDir) {
1885
+ const location = await new SessionService(workspaceCwd, {
1886
+ runtimeBaseDir
1887
+ }).getSessionLocation(sessionId);
1888
+ if (location === "active") {
1889
+ throw new SessionNotArchivedError(sessionId);
1890
+ }
1891
+ if (location === "conflict") {
1892
+ throw new SessionConflictError(sessionId);
1893
+ }
1894
+ if (location === void 0) {
1895
+ throw new SessionNotFoundError(sessionId);
1896
+ }
1897
+ }
1898
+ __name(assertSessionArchived, "assertSessionArchived");
1899
+ function isSessionNotFoundError(err) {
1900
+ return err instanceof SessionNotFoundError || err instanceof Error && err.name === "SessionNotFoundError";
1901
+ }
1902
+ __name(isSessionNotFoundError, "isSessionNotFoundError");
1903
+ function logSessionArchiveResult(action, result) {
1904
+ const changedLabel = action === "archive" ? "archived" : "unarchived";
1905
+ const alreadyLabel = action === "archive" ? "alreadyArchived" : "alreadyActive";
1906
+ const details = [
1907
+ `requested=${result.requested.length} requestedIds=${formatSessionIds(result.requested)}`,
1908
+ `${changedLabel}=${result.changed.length} ${changedLabel}Ids=${formatSessionIds(result.changed)}`,
1909
+ `${alreadyLabel}=${result.already.length} ${alreadyLabel}Ids=${formatSessionIds(result.already)}`,
1910
+ `notFound=${result.notFound.length} notFoundIds=${formatSessionIds(result.notFound)}`,
1911
+ `errors=${result.errors.length} errorIds=${formatSessionErrors(result.errors)}`
1912
+ ].join(" ");
1913
+ writeStderrLine(`qwen serve: sessions ${action} result ${details}`);
1914
+ }
1915
+ __name(logSessionArchiveResult, "logSessionArchiveResult");
1916
+ function formatSessionIds(sessionIds) {
1917
+ return `[${sessionIds.map((sessionId) => safeLogValue(sessionId)).join(",")}]`;
1918
+ }
1919
+ __name(formatSessionIds, "formatSessionIds");
1920
+ function formatSessionErrors(errors) {
1921
+ return `[${errors.map(
1922
+ ({ sessionId, error }) => `${safeLogValue(sessionId)}:${safeLogValue(errorMessage(error))}`
1923
+ ).join(",")}]`;
1924
+ }
1925
+ __name(formatSessionErrors, "formatSessionErrors");
1926
+ function errorMessage(error) {
1927
+ return error instanceof Error ? error.message : String(error);
1928
+ }
1929
+ __name(errorMessage, "errorMessage");
1930
+ function logSessionArchiveWarning(message) {
1931
+ writeStderrLine(`qwen serve: ${sanitizeLogLine(message)}`);
1932
+ }
1933
+ __name(logSessionArchiveWarning, "logSessionArchiveWarning");
1934
+ var LOG_LINE_UNSAFE_RE = /[\x00-\x1f\x7f-\x9f\u200b-\u200f\u2028-\u202e\u2066-\u2069\ufeff]/g;
1935
+ function sanitizeLogLine(message) {
1936
+ return message.replace(LOG_LINE_UNSAFE_RE, " ").slice(0, 4096);
1937
+ }
1938
+ __name(sanitizeLogLine, "sanitizeLogLine");
1939
+ async function archiveDaemonSessions(params) {
1940
+ const {
1941
+ sessionIds,
1942
+ service,
1943
+ bridge,
1944
+ coordinator,
1945
+ coordinatorLockHeld = false,
1946
+ resolveConflicts = false,
1947
+ assertCanMutate
1948
+ } = params;
1949
+ const uniqueSessionIds = [
1950
+ ...new Set(sessionIds.map(normalizeSessionIdForLookup))
1951
+ ];
1952
+ if (!coordinatorLockHeld) {
1953
+ for (const sessionId of uniqueSessionIds) {
1954
+ coordinator.assertNotTransitioning(sessionId);
1955
+ }
1956
+ }
1957
+ const results = await Promise.all(
1958
+ uniqueSessionIds.map(async (sessionId) => {
1959
+ try {
1960
+ const mutateSession = /* @__PURE__ */ __name(async () => {
1961
+ assertCanMutate?.();
1962
+ try {
1963
+ await bridge.closeSession(sessionId, void 0, {
1964
+ requireAgentClose: true
1965
+ });
1966
+ } catch (error) {
1967
+ if (!isSessionNotFoundError(error)) {
1968
+ return {
1969
+ kind: "error",
1970
+ error,
1971
+ mutationApplied: false
1972
+ };
1973
+ }
1974
+ }
1975
+ const initialLocation = await classifySessionLocation(
1976
+ service,
1977
+ sessionId
1978
+ );
1979
+ if (initialLocation === void 0) {
1980
+ return { kind: "notFound", mutationApplied: false };
1981
+ }
1982
+ if (initialLocation === "conflict" && !resolveConflicts) {
1983
+ return {
1984
+ kind: "error",
1985
+ error: sessionLocationError(sessionId),
1986
+ mutationApplied: false
1987
+ };
1988
+ }
1989
+ const mutation = await runWithDaemonWriterLease({
1990
+ action: "archive",
1991
+ sessionId,
1992
+ service,
1993
+ mutate: /* @__PURE__ */ __name(async (assertOwnedAndUnchanged, assertCleanupOwned) => {
1994
+ const lockedLocation = await classifySessionLocation(
1995
+ service,
1996
+ sessionId
1997
+ );
1998
+ if (lockedLocation === void 0) {
1999
+ return {
2000
+ value: "notFound",
2001
+ mutationApplied: false
2002
+ };
2003
+ }
2004
+ if (lockedLocation === "conflict" && !resolveConflicts) {
2005
+ throw sessionLocationError(sessionId);
2006
+ }
2007
+ const result = await service.archiveSessions([sessionId], {
2008
+ resolveConflicts,
2009
+ assertStorageUnchanged: assertOwnedAndUnchanged,
2010
+ assertCanMutate,
2011
+ assertCleanupOwned
2012
+ });
2013
+ if (result.errors[0]) throw result.errors[0].error;
2014
+ if (result.archived.length > 0) {
2015
+ return {
2016
+ value: result.resolvedConflicts.length ? "resolvedConflict" : "archived",
2017
+ mutationApplied: true
2018
+ };
2019
+ }
2020
+ return {
2021
+ value: result.alreadyArchived.length > 0 ? "alreadyArchived" : "notFound",
2022
+ mutationApplied: false
2023
+ };
2024
+ }, "mutate"),
2025
+ mutationAppliedAfterError: /* @__PURE__ */ __name(async () => await classifySessionLocation(service, sessionId) === "archived", "mutationAppliedAfterError"),
2026
+ afterMutationApplied: /* @__PURE__ */ __name(async () => {
2027
+ assertCanMutate?.();
2028
+ await updateScheduledTaskForMaintenance(
2029
+ service,
2030
+ sessionId,
2031
+ "archive",
2032
+ assertCanMutate
2033
+ );
2034
+ }, "afterMutationApplied")
2035
+ });
2036
+ if (mutation.error !== void 0) {
2037
+ return {
2038
+ kind: "error",
2039
+ error: mutation.error,
2040
+ mutationApplied: mutation.mutationApplied,
2041
+ maintenanceError: mutation.maintenanceError
2042
+ };
2043
+ }
2044
+ let maintenanceError = mutation.maintenanceError;
2045
+ if (mutation.value === "alreadyArchived") {
2046
+ try {
2047
+ await updateScheduledTaskForMaintenance(
2048
+ service,
2049
+ sessionId,
2050
+ "archive",
2051
+ assertCanMutate
2052
+ );
2053
+ } catch (error) {
2054
+ maintenanceError = error;
2055
+ logSessionArchiveWarning(
2056
+ `scheduled task lifecycle update failed action=archive workspace=${safeLogValue(
2057
+ service.getProjectRoot()
2058
+ )} session=${safeLogValue(sessionId)} error=${safeLogValue(
2059
+ errorMessage(error)
2060
+ )}`
2061
+ );
2062
+ }
2063
+ }
2064
+ return {
2065
+ kind: mutation.value ?? "notFound",
2066
+ mutationApplied: mutation.mutationApplied,
2067
+ maintenanceError
2068
+ };
2069
+ }, "mutateSession");
2070
+ return await (coordinatorLockHeld ? mutateSession() : coordinator.runExclusiveMany([sessionId], mutateSession));
2071
+ } catch (error) {
2072
+ if (error instanceof DaemonDrainingError) {
2073
+ throw error;
2074
+ }
2075
+ return {
2076
+ kind: "error",
2077
+ error,
2078
+ mutationApplied: false,
2079
+ maintenanceError: void 0
2080
+ };
2081
+ }
2082
+ })
2083
+ );
2084
+ const archived = [];
2085
+ const alreadyArchived = [];
2086
+ const resolvedConflicts = [];
2087
+ const notFound = [];
2088
+ const errors = [];
2089
+ for (let i = 0; i < results.length; i++) {
2090
+ const sessionId = uniqueSessionIds[i];
2091
+ const result = results[i];
2092
+ if (result.kind === "archived") archived.push(sessionId);
2093
+ else if (result.kind === "resolvedConflict") {
2094
+ archived.push(sessionId);
2095
+ resolvedConflicts.push(sessionId);
2096
+ } else if (result.kind === "alreadyArchived") {
2097
+ alreadyArchived.push(sessionId);
2098
+ } else if (result.kind === "notFound") notFound.push(sessionId);
2099
+ else errors.push({ sessionId, error: result.error });
2100
+ if ("maintenanceError" in result && result.maintenanceError !== void 0) {
2101
+ errors.push({ sessionId, error: result.maintenanceError });
2102
+ }
2103
+ }
2104
+ logSessionArchiveResult("archive", {
2105
+ requested: uniqueSessionIds,
2106
+ changed: archived,
2107
+ already: alreadyArchived,
2108
+ notFound,
2109
+ errors
2110
+ });
2111
+ return {
2112
+ archived,
2113
+ alreadyArchived,
2114
+ resolvedConflicts,
2115
+ notFound,
2116
+ errors
2117
+ };
2118
+ }
2119
+ __name(archiveDaemonSessions, "archiveDaemonSessions");
2120
+ async function unarchiveDaemonSessions(params) {
2121
+ const {
2122
+ sessionIds,
2123
+ service,
2124
+ coordinator,
2125
+ coordinatorLockHeld = false,
2126
+ resolveConflicts = false,
2127
+ assertCanMutate
2128
+ } = params;
2129
+ const uniqueSessionIds = [
2130
+ ...new Set(sessionIds.map(normalizeSessionIdForLookup))
2131
+ ];
2132
+ if (!coordinatorLockHeld) {
2133
+ for (const sessionId of uniqueSessionIds) {
2134
+ coordinator.assertNotTransitioning(sessionId);
2135
+ }
2136
+ }
2137
+ const results = await Promise.all(
2138
+ uniqueSessionIds.map(async (sessionId) => {
2139
+ try {
2140
+ const mutateSession = /* @__PURE__ */ __name(async () => {
2141
+ assertCanMutate?.();
2142
+ const initialLocation = await classifySessionLocation(
2143
+ service,
2144
+ sessionId
2145
+ );
2146
+ if (initialLocation === void 0) {
2147
+ return { kind: "notFound", mutationApplied: false };
2148
+ }
2149
+ if (initialLocation === "conflict" && !resolveConflicts) {
2150
+ return {
2151
+ kind: "error",
2152
+ error: sessionLocationError(sessionId),
2153
+ mutationApplied: false
2154
+ };
2155
+ }
2156
+ const mutation = await runWithDaemonWriterLease({
2157
+ action: "unarchive",
2158
+ sessionId,
2159
+ service,
2160
+ mutate: /* @__PURE__ */ __name(async (assertOwnedAndUnchanged, assertCleanupOwned) => {
2161
+ const lockedLocation = await classifySessionLocation(
2162
+ service,
2163
+ sessionId
2164
+ );
2165
+ if (lockedLocation === void 0) {
2166
+ return {
2167
+ value: "notFound",
2168
+ mutationApplied: false
2169
+ };
2170
+ }
2171
+ if (lockedLocation === "conflict" && !resolveConflicts) {
2172
+ throw sessionLocationError(sessionId);
2173
+ }
2174
+ const result = await service.unarchiveSessions([sessionId], {
2175
+ resolveConflicts,
2176
+ assertStorageUnchanged: assertOwnedAndUnchanged,
2177
+ assertCanMutate,
2178
+ assertCleanupOwned
2179
+ });
2180
+ if (result.errors[0]) throw result.errors[0].error;
2181
+ if (result.unarchived.length > 0) {
2182
+ return {
2183
+ value: result.resolvedConflicts.length ? "resolvedConflict" : "unarchived",
2184
+ mutationApplied: true
2185
+ };
2186
+ }
2187
+ return {
2188
+ value: result.alreadyActive.length > 0 ? "alreadyActive" : "notFound",
2189
+ mutationApplied: false
2190
+ };
2191
+ }, "mutate"),
2192
+ mutationAppliedAfterError: /* @__PURE__ */ __name(async () => await classifySessionLocation(service, sessionId) === "active", "mutationAppliedAfterError"),
2193
+ afterMutationApplied: /* @__PURE__ */ __name(async () => {
2194
+ assertCanMutate?.();
2195
+ await updateScheduledTaskForMaintenance(
2196
+ service,
2197
+ sessionId,
2198
+ "unarchive",
2199
+ assertCanMutate
2200
+ );
2201
+ }, "afterMutationApplied")
2202
+ });
2203
+ if (mutation.error !== void 0) {
2204
+ return {
2205
+ kind: "error",
2206
+ error: mutation.error,
2207
+ mutationApplied: mutation.mutationApplied,
2208
+ maintenanceError: mutation.maintenanceError
2209
+ };
2210
+ }
2211
+ let maintenanceError = mutation.maintenanceError;
2212
+ if (mutation.value === "alreadyActive") {
2213
+ try {
2214
+ await updateScheduledTaskForMaintenance(
2215
+ service,
2216
+ sessionId,
2217
+ "unarchive",
2218
+ assertCanMutate
2219
+ );
2220
+ } catch (error) {
2221
+ maintenanceError = error;
2222
+ logSessionArchiveWarning(
2223
+ `scheduled task lifecycle update failed action=unarchive workspace=${safeLogValue(
2224
+ service.getProjectRoot()
2225
+ )} session=${safeLogValue(sessionId)} error=${safeLogValue(
2226
+ errorMessage(error)
2227
+ )}`
2228
+ );
2229
+ }
2230
+ }
2231
+ return {
2232
+ kind: mutation.value ?? "notFound",
2233
+ mutationApplied: mutation.mutationApplied,
2234
+ maintenanceError
2235
+ };
2236
+ }, "mutateSession");
2237
+ return await (coordinatorLockHeld ? mutateSession() : coordinator.runExclusiveMany([sessionId], mutateSession));
2238
+ } catch (error) {
2239
+ if (error instanceof DaemonDrainingError) {
2240
+ throw error;
2241
+ }
2242
+ return {
2243
+ kind: "error",
2244
+ error,
2245
+ mutationApplied: false,
2246
+ maintenanceError: void 0
2247
+ };
2248
+ }
2249
+ })
2250
+ );
2251
+ const unarchived = [];
2252
+ const alreadyActive = [];
2253
+ const resolvedConflicts = [];
2254
+ const notFound = [];
2255
+ const errors = [];
2256
+ for (let i = 0; i < results.length; i++) {
2257
+ const sessionId = uniqueSessionIds[i];
2258
+ const result = results[i];
2259
+ if (result.kind === "unarchived") unarchived.push(sessionId);
2260
+ else if (result.kind === "resolvedConflict") {
2261
+ unarchived.push(sessionId);
2262
+ resolvedConflicts.push(sessionId);
2263
+ } else if (result.kind === "alreadyActive") alreadyActive.push(sessionId);
2264
+ else if (result.kind === "notFound") notFound.push(sessionId);
2265
+ else errors.push({ sessionId, error: result.error });
2266
+ if (result.maintenanceError !== void 0) {
2267
+ errors.push({ sessionId, error: result.maintenanceError });
2268
+ }
2269
+ }
2270
+ logSessionArchiveResult("unarchive", {
2271
+ requested: uniqueSessionIds,
2272
+ changed: unarchived,
2273
+ already: alreadyActive,
2274
+ notFound,
2275
+ errors
2276
+ });
2277
+ return {
2278
+ unarchived,
2279
+ alreadyActive,
2280
+ resolvedConflicts,
2281
+ notFound,
2282
+ errors
2283
+ };
2284
+ }
2285
+ __name(unarchiveDaemonSessions, "unarchiveDaemonSessions");
2286
+
2287
+ // packages/cli/src/serve/server/aone-mrs.ts
2288
+ init_esbuild_shims();
2289
+ import { execFile } from "node:child_process";
2290
+ import { promisify } from "node:util";
2291
+ var execFileAsync = promisify(execFile);
2292
+ var a1AvailabilityVerified = false;
2293
+ var defaultA1Exec = /* @__PURE__ */ __name(async (args, options) => {
2294
+ const { stdout } = await execFileAsync("a1", [...args], {
2295
+ ...options,
2296
+ encoding: "utf8",
2297
+ windowsHide: true
2298
+ // No env override: a1 authenticates through its own `a1 auth login`
2299
+ // config (review precedent); there is no A1_* token convention.
2300
+ });
2301
+ return { stdout };
2302
+ }, "defaultA1Exec");
2303
+ var a1Exec = defaultA1Exec;
2304
+ var A1_TIMEOUT_MS = 2e4;
2305
+ var A1_MAX_BUFFER = 16 * 1024 * 1024;
2306
+ var GIT_ORIGIN_TIMEOUT_MS = 5e3;
2307
+ var A1_VERSION_TIMEOUT_MS = 1e4;
2308
+ var A1_ERROR_MESSAGE_MAX = 512;
2309
+ var AONE_DETAIL_URL_HOST = "code.alibaba-inc.com";
2310
+ var AONE_MR_LIST_PAGE_SIZE = 20;
2311
+ var AONE_BACKFILL_PAGES_PER_STATE = 3;
2312
+ var AONE_MAX_MR_VIEW_CALLS_PER_RUN = 25;
2313
+ var AoneCliUnavailableError = class extends Error {
2314
+ static {
2315
+ __name(this, "AoneCliUnavailableError");
2316
+ }
2317
+ };
2318
+ var AoneCommandError = class extends Error {
2319
+ static {
2320
+ __name(this, "AoneCommandError");
2321
+ }
2322
+ };
2323
+ function mapAoneMrState(raw) {
2324
+ switch (raw?.toLowerCase()) {
2325
+ case "merged":
2326
+ return "merged";
2327
+ case "closed":
2328
+ return "closed";
2329
+ default:
2330
+ return "open";
2331
+ }
2332
+ }
2333
+ __name(mapAoneMrState, "mapAoneMrState");
2334
+ async function resolveAoneWorkspaceRepo(workspaceCwd, env) {
2335
+ const gitRoot = findGitRoot(workspaceCwd);
2336
+ if (!gitRoot) return void 0;
2337
+ let origin;
2338
+ try {
2339
+ ({ stdout: origin } = await execFileAsync(
2340
+ "git",
2341
+ ["remote", "get-url", "origin"],
2342
+ {
2343
+ cwd: gitRoot,
2344
+ timeout: GIT_ORIGIN_TIMEOUT_MS,
2345
+ encoding: "utf8",
2346
+ windowsHide: true,
2347
+ // Same sanitization as every sibling git spawn in these paths —
2348
+ // an inherited GIT_DIR/GIT_CONFIG_* would resolve origin against
2349
+ // a different repository despite the cwd.
2350
+ env: gitEnv(env)
2351
+ }
2352
+ ));
2353
+ } catch {
2354
+ return void 0;
2355
+ }
2356
+ const identity = parseRemoteUrl(origin.trim());
2357
+ if (!identity || !isAoneCanonicalHost(identity.host)) return void 0;
2358
+ return { gitRoot, repoPath: identity.groupPath };
2359
+ }
2360
+ __name(resolveAoneWorkspaceRepo, "resolveAoneWorkspaceRepo");
2361
+ function isAoneDetailUrlForRepo(repoPath, number, url) {
2362
+ return canonicalSessionPrUrl(url) === canonicalSessionPrUrl(
2363
+ `https://${AONE_DETAIL_URL_HOST}/${repoPath}/codereview/${number}`
2364
+ );
2365
+ }
2366
+ __name(isAoneDetailUrlForRepo, "isAoneDetailUrlForRepo");
2367
+ function isA1ErrorObject(value) {
2368
+ return typeof value === "object" && value !== null && value["schemaVersion"] === "a1.error/v1";
2369
+ }
2370
+ __name(isA1ErrorObject, "isA1ErrorObject");
2371
+ function a1ErrorMessage(error) {
2372
+ if (error?.killed === true) {
2373
+ return `a1 timed out after ${A1_TIMEOUT_MS / 1e3}s`;
2374
+ }
2375
+ const stderr = error?.stderr;
2376
+ const raw = typeof stderr === "string" && stderr.trim() ? stderr : error instanceof Error ? error.message : String(error);
2377
+ return raw.replace(/\s+/g, " ").trim().slice(0, A1_ERROR_MESSAGE_MAX);
2378
+ }
2379
+ __name(a1ErrorMessage, "a1ErrorMessage");
2380
+ function assertA1Version(stdout) {
2381
+ const triple = parseA1Version(stdout);
2382
+ const floor = parseA1Version(A1_MIN_VERSION);
2383
+ if (triple && floor && !a1VersionAtLeast(triple, floor)) {
2384
+ throw new AoneCliUnavailableError(
2385
+ `a1 ${A1_MIN_VERSION}+ is required (found ${stdout.trim().split("\n")[0]}); upgrade from https://code.alibaba-inc.com/aone/a1`
2386
+ );
2387
+ }
2388
+ }
2389
+ __name(assertA1Version, "assertA1Version");
2390
+ async function runA1Json(args) {
2391
+ let stdout;
2392
+ try {
2393
+ ({ stdout } = await a1Exec([...args, "--format", "json"], {
2394
+ timeout: A1_TIMEOUT_MS,
2395
+ maxBuffer: A1_MAX_BUFFER
2396
+ }));
2397
+ } catch (error) {
2398
+ if (error.code === "ENOENT") {
2399
+ throw new AoneCliUnavailableError(
2400
+ "a1 CLI not installed; install it and run `a1 auth login`"
2401
+ );
2402
+ }
2403
+ const errorStdout = error?.stdout;
2404
+ if (typeof errorStdout === "string" && errorStdout.trim()) {
2405
+ try {
2406
+ const parsed2 = JSON.parse(errorStdout);
2407
+ if (isA1ErrorObject(parsed2)) {
2408
+ throw new AoneCommandError(parsed2.message || "a1 command failed");
2409
+ }
2410
+ } catch (parseError) {
2411
+ if (parseError instanceof AoneCommandError) throw parseError;
2412
+ }
2413
+ }
2414
+ throw new AoneCommandError(a1ErrorMessage(error));
2415
+ }
2416
+ let parsed;
2417
+ try {
2418
+ parsed = JSON.parse(stdout);
2419
+ } catch {
2420
+ throw new AoneCommandError("a1 returned non-JSON output");
2421
+ }
2422
+ if (isA1ErrorObject(parsed)) {
2423
+ throw new AoneCommandError(parsed.message || "a1 command failed");
2424
+ }
2425
+ return parsed;
2426
+ }
2427
+ __name(runA1Json, "runA1Json");
2428
+ async function checkA1Available() {
2429
+ if (a1AvailabilityVerified) return;
2430
+ let stdout;
2431
+ try {
2432
+ ({ stdout } = await a1Exec(["--version"], {
2433
+ timeout: A1_VERSION_TIMEOUT_MS
2434
+ }));
2435
+ } catch (error) {
2436
+ if (error.code === "ENOENT") {
2437
+ throw new AoneCliUnavailableError(
2438
+ "a1 CLI not installed; install it and run `a1 auth login`"
2439
+ );
2440
+ }
2441
+ return;
2442
+ }
2443
+ assertA1Version(stdout);
2444
+ a1AvailabilityVerified = true;
2445
+ }
2446
+ __name(checkA1Available, "checkA1Available");
2447
+ function parseAoneMrListPage(raw) {
2448
+ if (!Array.isArray(raw)) {
2449
+ throw new AoneCommandError("unexpected a1 mr list output");
2450
+ }
2451
+ const entries = [];
2452
+ for (const item of raw) {
2453
+ if (item === null || typeof item !== "object") continue;
2454
+ const v = item;
2455
+ if (typeof v["id"] !== "number" || !Number.isInteger(v["id"]) || v["id"] <= 0) {
2456
+ continue;
2457
+ }
2458
+ entries.push({
2459
+ number: v["id"],
2460
+ headRefName: typeof v["sourceBranch"] === "string" ? v["sourceBranch"] : "",
2461
+ state: mapAoneMrState(
2462
+ typeof v["state"] === "string" ? v["state"] : void 0
2463
+ )
2464
+ });
2465
+ }
2466
+ return entries;
2467
+ }
2468
+ __name(parseAoneMrListPage, "parseAoneMrListPage");
2469
+ async function listAoneMergeRequests(repoPath, options) {
2470
+ await checkA1Available();
2471
+ const entries = [];
2472
+ const pages = Math.max(options.pages, 1);
2473
+ for (let page = 1; page <= pages; page++) {
2474
+ const parsed = await runA1Json([
2475
+ "repo",
2476
+ "mr",
2477
+ "list",
2478
+ "--repo",
2479
+ repoPath,
2480
+ "--state",
2481
+ options.state,
2482
+ "--page",
2483
+ String(page)
2484
+ ]);
2485
+ const pageEntries = parseAoneMrListPage(parsed);
2486
+ entries.push(...pageEntries);
2487
+ if (Array.isArray(parsed) && parsed.length < AONE_MR_LIST_PAGE_SIZE) {
2488
+ break;
2489
+ }
2490
+ }
2491
+ return entries;
2492
+ }
2493
+ __name(listAoneMergeRequests, "listAoneMergeRequests");
2494
+ function hasControlCharacter(value) {
2495
+ return Array.from(value).some((character) => {
2496
+ const code = character.charCodeAt(0);
2497
+ return code <= 31 || code === 127;
2498
+ });
2499
+ }
2500
+ __name(hasControlCharacter, "hasControlCharacter");
2501
+ function parseAoneMrView(raw, id) {
2502
+ const mr = raw !== null && typeof raw === "object" ? raw["mergeRequest"] : void 0;
2503
+ if (mr === null || typeof mr !== "object") {
2504
+ throw new AoneCommandError("unexpected a1 mr view output");
2505
+ }
2506
+ const v = mr;
2507
+ const url = typeof v["detailUrl"] === "string" ? v["detailUrl"] : "";
2508
+ if (!/^https?:\/\//i.test(url)) {
2509
+ throw new AoneCommandError("a1 mr view returned no detailUrl");
2510
+ }
2511
+ if (url.length > SESSION_PR_URL_MAX_LENGTH) {
2512
+ throw new AoneCommandError("a1 mr view returned an oversized detailUrl");
2513
+ }
2514
+ if (hasControlCharacter(url)) {
2515
+ throw new AoneCommandError("a1 mr view returned a malformed detailUrl");
2516
+ }
2517
+ return {
2518
+ number: id,
2519
+ url,
2520
+ state: mapAoneMrState(
2521
+ typeof v["state"] === "string" ? v["state"] : void 0
2522
+ )
2523
+ };
2524
+ }
2525
+ __name(parseAoneMrView, "parseAoneMrView");
2526
+ async function viewAoneMergeRequest(repoPath, id) {
2527
+ await checkA1Available();
2528
+ const parsed = await runA1Json([
2529
+ "repo",
2530
+ "mr",
2531
+ "view",
2532
+ String(id),
2533
+ "--repo",
2534
+ repoPath
2535
+ ]);
2536
+ return parseAoneMrView(parsed, id);
2537
+ }
2538
+ __name(viewAoneMergeRequest, "viewAoneMergeRequest");
2539
+ var defaultAoneMrBackend = {
2540
+ list: /* @__PURE__ */ __name((repoPath, state, pages) => listAoneMergeRequests(repoPath, { state, pages }), "list"),
2541
+ view: viewAoneMergeRequest
2542
+ };
2543
+
2544
+ export {
2545
+ createSessionOrganizationService,
2546
+ laterActivityTimestamp,
2547
+ invalidateWorkspaceSessionListCache,
2548
+ InvalidCursorError,
2549
+ listWorkspaceSessionsForResponse,
2550
+ listLiveWorkspaceSessionsForResponse,
2551
+ getWorkspaceSessionInfoForResponse,
2552
+ parseSessionPageSizeQuery,
2553
+ runWithWorkspaceRuntimeStorage,
2554
+ createWorkspaceRuntimeSessionService,
2555
+ DaemonDrainingError,
2556
+ SessionArchiveCoordinator,
2557
+ deleteDaemonSessions,
2558
+ deleteDaemonSessionIfOrphan,
2559
+ assertSessionLoadable,
2560
+ resolveSessionIdForRestore,
2561
+ assertSessionRestorable,
2562
+ assertSessionArchived,
2563
+ logSessionArchiveWarning,
2564
+ archiveDaemonSessions,
2565
+ unarchiveDaemonSessions,
2566
+ AONE_BACKFILL_PAGES_PER_STATE,
2567
+ AONE_MAX_MR_VIEW_CALLS_PER_RUN,
2568
+ resolveAoneWorkspaceRepo,
2569
+ isAoneDetailUrlForRepo,
2570
+ defaultAoneMrBackend
2571
+ };
2572
+ /**
2573
+ * @license
2574
+ * Copyright 2025 Qwen Team
2575
+ * SPDX-License-Identifier: Apache-2.0
2576
+ */
2577
+ /**
2578
+ * @license
2579
+ * Copyright 2026 Qwen Team
2580
+ * SPDX-License-Identifier: Apache-2.0
2581
+ */