@qwen-code/qwen-code 0.19.12 → 0.20.0-nightly.20260720.0c271659d

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 (276) hide show
  1. package/bundled/qc-helper/docs/integration-github-action.md +1 -1
  2. package/bundled/qc-helper/docs/qwen-serve.md +42 -5
  3. package/bundled/review/DESIGN.md +2 -2
  4. package/bundled/review/SKILL.md +13 -9
  5. package/chunks/{MaxSizedBox-QOXLJGAF.js → MaxSizedBox-ED3QND6V.js} +30 -27
  6. package/chunks/{StandaloneSessionPicker-FLV6CGYJ.js → StandaloneSessionPicker-NQVAOTKS.js} +50 -45
  7. package/chunks/{acpAgent-OB2CTF3P.js → acpAgent-HOBFF5B6.js} +353 -130
  8. package/chunks/{agent-CKSI7BTR.js → agent-J7EPFLA6.js} +22 -22
  9. package/chunks/{agent-headless-U36LIYTU.js → agent-headless-RRG3JU7Q.js} +22 -22
  10. package/chunks/{anthropicContentGenerator-ZZRGFEES.js → anthropicContentGenerator-HVKLXOOU.js} +6 -5
  11. package/chunks/{artifact-tool-PHO5XEGZ.js → artifact-tool-WBCAMD3O.js} +2 -2
  12. package/chunks/{askUserQuestion-CEPBT47X.js → askUserQuestion-6DZC4UV5.js} +2 -2
  13. package/chunks/{bridge-AIKTINJG.js → bridge-OW5FZ6BF.js} +25 -25
  14. package/chunks/build-SSCNEHZZ.js +62 -0
  15. package/chunks/{channel-worker-group-NEUVTPB2.js → channel-worker-group-53CMOPFT.js} +4 -4
  16. package/chunks/{channel-worker-manager-7CQVOVWV.js → channel-worker-manager-UTXILKC2.js} +4 -4
  17. package/chunks/{channel-worker-supervisor-3BU2KNCZ.js → channel-worker-supervisor-ZGO2W2MD.js} +3 -3
  18. package/chunks/chunk-27AJEU6G.js +442 -0
  19. package/chunks/{chunk-BABX5XRO.js → chunk-2HOVDT7W.js} +1 -1
  20. package/chunks/{chunk-GW7BONBU.js → chunk-2JOLZA6L.js} +5 -5
  21. package/chunks/{chunk-ZSDFNE6Y.js → chunk-2TDSM7I6.js} +3 -3
  22. package/chunks/{chunk-6IITZE7O.js → chunk-2YJLFCYI.js} +7 -7
  23. package/chunks/{chunk-VEFR4XJQ.js → chunk-37MGCVTS.js} +1 -1
  24. package/chunks/{chunk-3B6PSWHE.js → chunk-3ML52IFS.js} +4 -4
  25. package/chunks/{chunk-TKASNYDS.js → chunk-3QR5MOHP.js} +2 -2
  26. package/chunks/{chunk-KRMARA3A.js → chunk-3SNKL6L6.js} +29 -13
  27. package/chunks/{chunk-DJ4VHAFJ.js → chunk-3ZL6YMO2.js} +3 -3
  28. package/chunks/chunk-43T5WDQ7.js +127 -0
  29. package/chunks/{chunk-W6CQPLWM.js → chunk-4ODB7WIB.js} +1 -1
  30. package/chunks/{chunk-CHPQFLW6.js → chunk-4UH63YE5.js} +5 -5
  31. package/chunks/{chunk-2CCDMJM7.js → chunk-53OPIXUE.js} +3 -3
  32. package/chunks/{chunk-HTHUX2T5.js → chunk-5QWWOFGG.js} +0 -1
  33. package/chunks/{chunk-3DJY4IFO.js → chunk-5SCI6E3E.js} +1 -1
  34. package/chunks/{chunk-4CHDYDG3.js → chunk-6EFTQYW7.js} +1 -1
  35. package/chunks/{chunk-OBSLEYCD.js → chunk-6HQW55TM.js} +29 -2
  36. package/chunks/{chunk-N47VAEAJ.js → chunk-6MN6XJTR.js} +2379 -1291
  37. package/chunks/{chunk-UCTCDLDS.js → chunk-6VGRTGOG.js} +1 -1
  38. package/chunks/{chunk-KNGZ5EYL.js → chunk-7JQK6FXK.js} +198 -120
  39. package/chunks/{chunk-2476XGOU.js → chunk-A4TJMY65.js} +1 -1
  40. package/chunks/{chunk-67Q33DQY.js → chunk-AMRWCMX4.js} +4 -4
  41. package/chunks/{chunk-XAAEDML2.js → chunk-AYCDXHZB.js} +1 -1
  42. package/chunks/{chunk-VAJS2E2D.js → chunk-BDBMYST4.js} +1 -1
  43. package/chunks/{chunk-F2RR4HO2.js → chunk-BVLROR2T.js} +1 -1
  44. package/chunks/{chunk-UE5TZ55T.js → chunk-C27BYUX6.js} +29 -2
  45. package/chunks/{chunk-PK7COE5O.js → chunk-CL7IRYTA.js} +1 -1
  46. package/chunks/{chunk-KMJOMWHE.js → chunk-COWNNAWJ.js} +1 -1
  47. package/chunks/{chunk-UOA2IHRI.js → chunk-CPCVCKKF.js} +1 -1
  48. package/chunks/{chunk-4RPARQ5D.js → chunk-D2VIDMVM.js} +2 -2
  49. package/chunks/{chunk-4MPYGENG.js → chunk-DCCW7CRR.js} +6 -6
  50. package/chunks/chunk-DIKIJS6Z.js +114 -0
  51. package/chunks/{chunk-ETN2G32U.js → chunk-DR5AUNJ2.js} +4 -4
  52. package/chunks/{chunk-6ETOSWAO.js → chunk-DSBCU6JY.js} +3 -3
  53. package/chunks/{chunk-LKR7QQ63.js → chunk-EAUYY7SS.js} +3 -3
  54. package/chunks/{chunk-J2MKYJKZ.js → chunk-EIAK6Q2B.js} +2 -2
  55. package/chunks/{chunk-WEPXQKGP.js → chunk-EZVDJFZ7.js} +1 -1
  56. package/chunks/{chunk-WHQNBBWW.js → chunk-FLSVD6BS.js} +2 -2
  57. package/chunks/{chunk-3ESL7JXA.js → chunk-FODJ5Q5K.js} +3 -3
  58. package/chunks/{chunk-4XCVGEEX.js → chunk-FSL5W5TI.js} +3 -3
  59. package/chunks/{chunk-NE6HHLL3.js → chunk-FWT66O5E.js} +2 -2
  60. package/chunks/{chunk-OSSDHJDU.js → chunk-G45X5TRN.js} +1 -1
  61. package/chunks/{chunk-ZGT623SG.js → chunk-G6MDKXDP.js} +12 -12
  62. package/chunks/{chunk-KANTXY7B.js → chunk-GKY2OJ7R.js} +2 -2
  63. package/chunks/chunk-GMGDLUC7.js +37 -0
  64. package/chunks/{chunk-J6NT5YTN.js → chunk-H2XVO6NE.js} +1 -289
  65. package/chunks/{chunk-XSEWNUMZ.js → chunk-I4HZ4GOD.js} +8 -8
  66. package/chunks/{chunk-CPU6I5YV.js → chunk-I6JUVU7J.js} +34 -24
  67. package/chunks/{chunk-UZC5VPOJ.js → chunk-IDGTC5AS.js} +3 -3
  68. package/chunks/{chunk-QIFTJDBY.js → chunk-INL2RSLA.js} +1 -1
  69. package/chunks/{chunk-GSPWDTYY.js → chunk-INQQM52C.js} +18 -16
  70. package/chunks/{chunk-HVGJWOR6.js → chunk-JBCFW3IL.js} +2 -2
  71. package/chunks/{chunk-LPHGXXZX.js → chunk-JD3MKVKL.js} +1 -1
  72. package/chunks/{chunk-GCY7QTCE.js → chunk-JDPCOUZ3.js} +1602 -398
  73. package/chunks/{chunk-NUHSLBJZ.js → chunk-JNWZQ27S.js} +15 -9
  74. package/chunks/{chunk-KGWA7XYL.js → chunk-JRJ2LV6P.js} +6 -226
  75. package/chunks/{chunk-QSG4ZFG4.js → chunk-KTUQMDEP.js} +1 -1
  76. package/chunks/{chunk-RKUMFUFM.js → chunk-LTQ5C5AB.js} +4 -4
  77. package/chunks/{chunk-V4PCIS25.js → chunk-MAQQGNQ5.js} +44 -1
  78. package/chunks/{chunk-EISVEV45.js → chunk-NBMIC7DR.js} +2 -2
  79. package/chunks/{chunk-GEHSF7MS.js → chunk-NEEB7UEN.js} +2545 -1974
  80. package/chunks/{chunk-BKNPMEN6.js → chunk-NIJEXGV6.js} +93 -17
  81. package/chunks/{chunk-PR5XQ73G.js → chunk-NQVA6O7F.js} +2 -2
  82. package/chunks/{chunk-FUSMC3SZ.js → chunk-NT324EJ6.js} +13 -8
  83. package/chunks/{chunk-5N7M4XYN.js → chunk-O2SPEQFA.js} +5 -5
  84. package/chunks/{chunk-OEHCAWUA.js → chunk-OLMETXLX.js} +2 -2
  85. package/chunks/{chunk-JCJPZMJV.js → chunk-OOCI5VVU.js} +1 -1
  86. package/chunks/{chunk-XSPFQQRE.js → chunk-OONJNQ42.js} +3 -3
  87. package/chunks/{chunk-ANRANWVE.js → chunk-OP4MOGXF.js} +1 -1
  88. package/chunks/{chunk-SGPFJMRP.js → chunk-PBATSWUQ.js} +1 -1
  89. package/chunks/chunk-QKYTTBYW.js +624 -0
  90. package/chunks/{chunk-W4UN42YP.js → chunk-QOSKUG5P.js} +77 -20
  91. package/chunks/{chunk-76BFY7AF.js → chunk-QTERJVPZ.js} +1 -6
  92. package/chunks/{chunk-WIYV7CSF.js → chunk-RB7NXUP5.js} +3 -3
  93. package/chunks/{chunk-HCCR43AY.js → chunk-RFIAR4YL.js} +1 -1
  94. package/chunks/{chunk-GMUPIMHF.js → chunk-RS5JPH6Y.js} +3 -3
  95. package/chunks/chunk-RS7MT2QG.js +305 -0
  96. package/chunks/{chunk-GXFYV7MP.js → chunk-SG2PEESS.js} +1106 -592
  97. package/chunks/{chunk-PUKUUASO.js → chunk-SLLG5XXE.js} +1 -1
  98. package/chunks/{chunk-GLH2NTPB.js → chunk-SQMTULHJ.js} +1 -1
  99. package/chunks/{chunk-NPMVLWYL.js → chunk-STFP7PJR.js} +6 -6
  100. package/chunks/chunk-SV5PQVQE.js +71 -0
  101. package/chunks/{chunk-HZ4M2UQD.js → chunk-TFNZCC4B.js} +1 -1
  102. package/chunks/{chunk-5QSVANRT.js → chunk-THNJYTA6.js} +2 -2
  103. package/chunks/{chunk-MRE77ST5.js → chunk-TN2BYMNH.js} +69 -2216
  104. package/chunks/{chunk-64GC5EMF.js → chunk-TQBA6DVX.js} +1 -1
  105. package/chunks/{chunk-VLHQMOZK.js → chunk-U24E4R5U.js} +3 -3
  106. package/chunks/{chunk-4CA4WUMS.js → chunk-UEY4AYUL.js} +2 -2
  107. package/chunks/{chunk-42VIHAYT.js → chunk-UGRL5B5F.js} +1 -1
  108. package/chunks/chunk-V7RNNPGC.js +44 -0
  109. package/chunks/{chunk-R3EDIMYZ.js → chunk-VGFFYNBD.js} +1 -1
  110. package/chunks/chunk-VIOFKPPN.js +125 -0
  111. package/chunks/{chunk-BEZPRKD3.js → chunk-VLDBVLC4.js} +156 -2
  112. package/chunks/{chunk-HD6EGS5K.js → chunk-VWLLDHAY.js} +6 -6
  113. package/chunks/chunk-WCDH2CRI.js +1187 -0
  114. package/chunks/{chunk-7SX6WZNO.js → chunk-XVVH63JG.js} +3 -3
  115. package/chunks/{chunk-I7RRHHYG.js → chunk-Y2ENGUD6.js} +1 -1
  116. package/chunks/{chunk-NALRQ3SG.js → chunk-Y5534U4G.js} +332 -116
  117. package/chunks/{chunk-4SJJT466.js → chunk-YDZ6J2BY.js} +72 -159
  118. package/chunks/{chunk-APOFULHK.js → chunk-YNBP3YSU.js} +7 -6
  119. package/chunks/{chunk-EFAXBOQO.js → chunk-YWEW33JY.js} +7 -7
  120. package/chunks/{chunk-335ECZTA.js → chunk-ZEOZL37W.js} +1 -1
  121. package/chunks/{chunk-DUR7BZYK.js → chunk-ZGJ4LDD2.js} +53 -28
  122. package/chunks/{computer-use-4PUGCUQK.js → computer-use-ET5476VX.js} +22 -22
  123. package/chunks/{config-utils-6PJUXHLI.js → config-utils-AHQ6YZ66.js} +3 -3
  124. package/chunks/{contextCommand-C57KTWFV.js → contextCommand-QIULFDBF.js} +25 -26
  125. package/chunks/{create-sub-session-5Q42XR6I.js → create-sub-session-BVL2ZHTM.js} +22 -22
  126. package/chunks/{create-sub-session-DIJOV6HV.js → create-sub-session-P26FE5GG.js} +2 -2
  127. package/chunks/{cron-create-X462ERYA.js → cron-create-JWFHBDRQ.js} +4 -4
  128. package/chunks/{cron-delete-SL5UJUM3.js → cron-delete-GDX4E26G.js} +4 -4
  129. package/chunks/{cron-list-3MD6SVXI.js → cron-list-USMAIWPT.js} +4 -4
  130. package/chunks/{daemon-ZW6LHOXT.js → daemon-EE5T3KOW.js} +169 -84
  131. package/chunks/{daemon-status-provider-YPV3UXHT.js → daemon-status-provider-L5UW7TGV.js} +29 -29
  132. package/chunks/{dist-3DQNQJ6H.js → dist-2BHAYBKP.js} +1 -1
  133. package/chunks/{dist-J2H4KTLB.js → dist-2MIU4UUH.js} +1 -1
  134. package/chunks/{dist-IEQSDXS7.js → dist-53PZYC5B.js} +2 -2
  135. package/chunks/{dist-NUXRQHC5.js → dist-AU7NQQRP.js} +1 -1
  136. package/chunks/{dist-XLE6ODMB.js → dist-FUTEXY6A.js} +1 -1
  137. package/chunks/{dist-IGZMVS5R.js → dist-WGTQO7F2.js} +1 -1
  138. package/chunks/{earlyInputCapture-5VDWSYAM.js → earlyInputCapture-ZLAL5GTE.js} +23 -23
  139. package/chunks/{edit-GORZTX2U.js → edit-4ZOPT6OC.js} +23 -23
  140. package/chunks/{enter-worktree-LJB2AW4L.js → enter-worktree-DFP5CZYS.js} +22 -22
  141. package/chunks/{enterPlanMode-LIIPP37T.js → enterPlanMode-7VEJ7A2A.js} +22 -22
  142. package/chunks/{environment-HQ2UHJ35.js → environment-KHS35XJY.js} +24 -24
  143. package/chunks/{errors-6JD5VMVQ.js → errors-574WBU5R.js} +24 -24
  144. package/chunks/{exit-worktree-IEP2WHOV.js → exit-worktree-5Q7V6D4C.js} +22 -22
  145. package/chunks/{exitPlanMode-U5Z6XBLO.js → exitPlanMode-SX2F6PDJ.js} +22 -22
  146. package/chunks/{fast-path-HFKNMP23.js → fast-path-G7BLOZVF.js} +2 -2
  147. package/chunks/{gemini-C2SCJH3N.js → gemini-M4JWSTGU.js} +70 -68
  148. package/chunks/{geminiContentGenerator-ADZTXEKV.js → geminiContentGenerator-MKXLUFUH.js} +4 -4
  149. package/chunks/{glob-GOAPGD6G.js → glob-FPKZY5W6.js} +22 -22
  150. package/chunks/{grep-HZLSTX7D.js → grep-RS22OMZG.js} +22 -22
  151. package/chunks/{handleAutoUpdate-UF74WGFE.js → handleAutoUpdate-RFNQ36JC.js} +27 -28
  152. package/chunks/{i18n-FMXIYUOC.js → i18n-MAEWSKYF.js} +23 -23
  153. package/chunks/{initializer-ERDBM3DU.js → initializer-T2BFZJBP.js} +28 -28
  154. package/chunks/{installationInfo-LROMXYLX.js → installationInfo-3UETF773.js} +25 -23
  155. package/chunks/{keychain-token-storage-K23CFKGN.js → keychain-token-storage-DWRJMNH3.js} +2 -2
  156. package/chunks/{list-6JPJROU5.js → list-FWZUKWD2.js} +30 -30
  157. package/chunks/{loadedSettingsAdapter-QCWYUBBF.js → loadedSettingsAdapter-3DUNHAPX.js} +27 -27
  158. package/chunks/{loop-wakeup-6H7OENTB.js → loop-wakeup-5GLTUBHA.js} +5 -5
  159. package/chunks/{ls-APTSOOS5.js → ls-FHBY3Y7I.js} +4 -4
  160. package/chunks/{lsp-HPACPJAN.js → lsp-B6VMEW6Y.js} +2 -2
  161. package/chunks/{mcp-3P3KWYWO.js → mcp-POXS7QWD.js} +27 -27
  162. package/chunks/{monitor-LMYKCF6R.js → monitor-2ZZC2NKH.js} +22 -22
  163. package/chunks/nonInteractiveCli-WSJVCB2W.js +126 -0
  164. package/chunks/{notebook-edit-IBEOVZ6A.js → notebook-edit-BMQLME3Q.js} +23 -23
  165. package/chunks/{openaiContentGenerator-42PZKET5.js → openaiContentGenerator-GOREG72R.js} +11 -11
  166. package/chunks/{pidfile-VTBDIGOH.js → pidfile-MVZDE5TC.js} +23 -23
  167. package/chunks/{processUtils-L7ZKOGDG.js → processUtils-RH5KNLDH.js} +2 -2
  168. package/chunks/{qwenContentGenerator-VR2CNFGI.js → qwenContentGenerator-R55BCLRI.js} +24 -24
  169. package/chunks/{qwenOAuth2-6LS2T3Q6.js → qwenOAuth2-QZBI2SOZ.js} +11 -11
  170. package/chunks/react-SG7JAQSZ.js +8 -0
  171. package/chunks/{read-file-VSKOE22I.js → read-file-CPS2CYYG.js} +8 -8
  172. package/chunks/{read-mcp-resource-C6NT52T6.js → read-mcp-resource-AKCL7I43.js} +2 -2
  173. package/chunks/{record-artifact-ENCU7QCL.js → record-artifact-PEUB7727.js} +2 -2
  174. package/chunks/resumeHistoryUtils-YD6DSYHU.js +78 -0
  175. package/chunks/{ripGrep-5V5FLW2A.js → ripGrep-UKGJ7RHZ.js} +22 -22
  176. package/chunks/{run-qwen-serve-LSOPP4R2.js → run-qwen-serve-GFKSKLF6.js} +1442 -148
  177. package/chunks/{runtime-LT7R4CS5.js → runtime-4KGNL3TP.js} +31 -31
  178. package/chunks/{scheduler-YOWQ7KZP.js → scheduler-GJ3CELWI.js} +22 -22
  179. package/chunks/{send-message-5GZ4FX2V.js → send-message-3RHE7HSM.js} +3 -3
  180. package/chunks/{serve-VWLBXKGK.js → serve-UU6Z4C7W.js} +27 -27
  181. package/chunks/{server-3RW3FYOH.js → server-RTJUMN24.js} +393 -256
  182. package/chunks/{session-ZONXFOBQ.js → session-EYD3CEB5.js} +79 -163
  183. package/chunks/{settings-JC3VC53L.js → settings-H5O22TGQ.js} +26 -26
  184. package/chunks/{shell-2NGEMAVM.js → shell-KVNHDHMT.js} +22 -22
  185. package/chunks/{skill-3U2T6H3E.js → skill-32525KCE.js} +10 -10
  186. package/chunks/{spawnChannel-QEAUPARQ.js → spawnChannel-G7DUQKHL.js} +24 -24
  187. package/chunks/{src-75ZPXO7B.js → src-DUFUUEHE.js} +52 -22
  188. package/chunks/{standalone-update-UUJWJWYY.js → standalone-update-UC6CWBLH.js} +24 -24
  189. package/chunks/{startInteractiveUI-V7XISPQ6.js → startInteractiveUI-A5YYAWLF.js} +5451 -2045
  190. package/chunks/{syntheticOutput-ULOVVLY4.js → syntheticOutput-FG5PQKIR.js} +3 -3
  191. package/chunks/{task-create-DUE2PMNI.js → task-create-HX32YXO7.js} +7 -7
  192. package/chunks/{task-list-WVPNX7BZ.js → task-list-QWSY4ZIU.js} +5 -5
  193. package/chunks/{task-stop-CPEQWOT6.js → task-stop-GWC6UWAL.js} +2 -2
  194. package/chunks/{task-update-HY2LNFFB.js → task-update-NCTAB73Q.js} +7 -7
  195. package/chunks/{team-create-R6AXDYPG.js → team-create-LS2Q32Y4.js} +22 -22
  196. package/chunks/{team-delete-JJV6IUOA.js → team-delete-KK37HTOG.js} +5 -5
  197. package/chunks/{team-plan-approval-O2ZPPT64.js → team-plan-approval-DWCZABX6.js} +22 -22
  198. package/chunks/{theme-manager-YIX2IC2D.js → theme-manager-E22CNBIL.js} +23 -23
  199. package/chunks/{todoWrite-JHHIDOIV.js → todoWrite-ERCAMLFS.js} +4 -4
  200. package/chunks/{tool-search-5IE2VO7X.js → tool-search-MHXUDFD2.js} +9 -9
  201. package/chunks/{total-session-admission-K6APQYEF.js → total-session-admission-KOPTGDJZ.js} +25 -25
  202. package/chunks/{trustedFolders-GPSSPVBF.js → trustedFolders-ANQXYAQT.js} +23 -23
  203. package/chunks/{update-relaunch-4BVAPX6Y.js → update-relaunch-HFGRB7PE.js} +9 -9
  204. package/chunks/{updateCheck-AHTHWLAM.js → updateCheck-EKIPND4B.js} +33 -26
  205. package/chunks/useAutoAcceptIndicator-EE22V2F5.js +80 -0
  206. package/chunks/{validateNonInterActiveAuth-UKAPCWDM.js → validateNonInterActiveAuth-RUICXVPH.js} +61 -63
  207. package/chunks/{version-EXGWKKQE.js → version-QLT755OV.js} +1 -1
  208. package/chunks/{web-fetch-ZDNE6FF2.js → web-fetch-DINW4Z65.js} +10 -10
  209. package/chunks/{workflow-G7U6OQWS.js → workflow-GPMXRWKK.js} +23 -23
  210. package/chunks/{workspace-providers-status-W6CEA6YM.js → workspace-providers-status-XCQKBVSX.js} +30 -30
  211. package/chunks/{workspace-registration-store-OGBMWCLC.js → workspace-registration-store-4I4KL7TN.js} +1 -1
  212. package/chunks/{workspace-registry-ZUWQM44P.js → workspace-registry-N4J57SFQ.js} +25 -25
  213. package/chunks/{workspace-service-UXX5P7GU.js → workspace-service-JJNJWVH3.js} +32 -32
  214. package/chunks/{workspace-skills-status-635B5R7N.js → workspace-skills-status-CEHLAQ2Y.js} +28 -28
  215. package/chunks/{write-file-DR3HN7IH.js → write-file-XRGEJRCC.js} +23 -23
  216. package/cli.js +11 -11
  217. package/package.json +3 -3
  218. package/web-shell/assets/{arc-_dVIKMdB.js → arc-DwJhljn9.js} +1 -1
  219. package/web-shell/assets/{architectureDiagram-3BPJPVTR-MuN3nKpL.js → architectureDiagram-3BPJPVTR-qdxSRav-.js} +1 -1
  220. package/web-shell/assets/{blockDiagram-GPEHLZMM-BtmvJjzx.js → blockDiagram-GPEHLZMM-2-dKM5aM.js} +1 -1
  221. package/web-shell/assets/{c4Diagram-AAUBKEIU-Dvi58_BU.js → c4Diagram-AAUBKEIU-Dt_Nu2HD.js} +1 -1
  222. package/web-shell/assets/channel-C6uyh95L.js +1 -0
  223. package/web-shell/assets/{chunk-2J33WTMH-YqxOVhS1.js → chunk-2J33WTMH-CBCeeNfD.js} +1 -1
  224. package/web-shell/assets/{chunk-4BX2VUAB-DoBgbC9z.js → chunk-4BX2VUAB-DPAzjqNs.js} +1 -1
  225. package/web-shell/assets/{chunk-55IACEB6-3NEQrBAr.js → chunk-55IACEB6-yrqyxvIK.js} +1 -1
  226. package/web-shell/assets/{chunk-727SXJPM-DrCZQxp0.js → chunk-727SXJPM-DguD_BBT.js} +1 -1
  227. package/web-shell/assets/{chunk-AQP2D5EJ-m_g3zjgv.js → chunk-AQP2D5EJ-KRUOG9v0.js} +1 -1
  228. package/web-shell/assets/{chunk-FMBD7UC4-D1_crABJ.js → chunk-FMBD7UC4-C0lilT2U.js} +1 -1
  229. package/web-shell/assets/{chunk-ND2GUHAM-BdhgVtBx.js → chunk-ND2GUHAM-DG9epIWK.js} +1 -1
  230. package/web-shell/assets/{chunk-QZHKN3VN-BlmThhm-.js → chunk-QZHKN3VN-PdJDkYHw.js} +1 -1
  231. package/web-shell/assets/classDiagram-4FO5ZUOK-Cv8Ulf-B.js +1 -0
  232. package/web-shell/assets/classDiagram-v2-Q7XG4LA2-Cv8Ulf-B.js +1 -0
  233. package/web-shell/assets/{cose-bilkent-S5V4N54A-Cbjm_00Z.js → cose-bilkent-S5V4N54A-BAOPPuJm.js} +1 -1
  234. package/web-shell/assets/{dagre-BM42HDAG-C39QNVgC.js → dagre-BM42HDAG-CDHJv82_.js} +1 -1
  235. package/web-shell/assets/{diagram-2AECGRRQ-DNXSAixC.js → diagram-2AECGRRQ-C_hkG5fN.js} +1 -1
  236. package/web-shell/assets/{diagram-5GNKFQAL-BCbGUPEA.js → diagram-5GNKFQAL-e9zo_eKt.js} +1 -1
  237. package/web-shell/assets/{diagram-KO2AKTUF-1eujKSDC.js → diagram-KO2AKTUF-BFN41SCb.js} +1 -1
  238. package/web-shell/assets/{diagram-LMA3HP47-DUMKXgql.js → diagram-LMA3HP47-DG72N0W0.js} +1 -1
  239. package/web-shell/assets/{diagram-OG6HWLK6-BFktU3_u.js → diagram-OG6HWLK6-Dkmp-tdv.js} +1 -1
  240. package/web-shell/assets/{erDiagram-TEJ5UH35-BvJC7DLk.js → erDiagram-TEJ5UH35-CyS0GnQV.js} +1 -1
  241. package/web-shell/assets/{flowDiagram-I6XJVG4X-Cgu3PlOt.js → flowDiagram-I6XJVG4X-Cg1SRmzV.js} +1 -1
  242. package/web-shell/assets/{ganttDiagram-6RSMTGT7-DLNXN5Xh.js → ganttDiagram-6RSMTGT7-CoNkSLs3.js} +1 -1
  243. package/web-shell/assets/{gitGraphDiagram-PVQCEYII-BQFRDv6R.js → gitGraphDiagram-PVQCEYII-DEA6GWPa.js} +1 -1
  244. package/web-shell/assets/index-B49xd8_A.css +5 -0
  245. package/web-shell/assets/{index-CdC3pjP3.js → index-CMaZgs6B.js} +1 -1
  246. package/web-shell/assets/index-D-cDAZgO.js +1192 -0
  247. package/web-shell/assets/{infoDiagram-5YYISTIA-DT2mOSvp.js → infoDiagram-5YYISTIA-BZshyoGT.js} +1 -1
  248. package/web-shell/assets/{ishikawaDiagram-YF4QCWOH-9fy_K4bd.js → ishikawaDiagram-YF4QCWOH-CT2ssZqC.js} +1 -1
  249. package/web-shell/assets/{journeyDiagram-JHISSGLW-CoGSEuhE.js → journeyDiagram-JHISSGLW-BtMQ0rDG.js} +1 -1
  250. package/web-shell/assets/{kanban-definition-UN3LZRKU-BP9hHYIj.js → kanban-definition-UN3LZRKU-CoDbK5Db.js} +1 -1
  251. package/web-shell/assets/{linear-uIroDsmp.js → linear-CwhZ6u7u.js} +1 -1
  252. package/web-shell/assets/{mermaid.core-BUwoStsA.js → mermaid.core-C9nn0nrr.js} +5 -5
  253. package/web-shell/assets/{mindmap-definition-RKZ34NQL-DZB-FWim.js → mindmap-definition-RKZ34NQL-BXUbjTeL.js} +1 -1
  254. package/web-shell/assets/{pieDiagram-4H26LBE5-YPptloKl.js → pieDiagram-4H26LBE5-JddiYlWQ.js} +1 -1
  255. package/web-shell/assets/{quadrantDiagram-W4KKPZXB-dgk3DSzm.js → quadrantDiagram-W4KKPZXB-DK5HKzXO.js} +1 -1
  256. package/web-shell/assets/{requirementDiagram-4Y6WPE33-BH2En2i9.js → requirementDiagram-4Y6WPE33-Y-uipa_6.js} +1 -1
  257. package/web-shell/assets/{sankeyDiagram-5OEKKPKP-BB98feeI.js → sankeyDiagram-5OEKKPKP-BbWeqo8H.js} +1 -1
  258. package/web-shell/assets/{sequenceDiagram-3UESZ5HK-CunAIGh8.js → sequenceDiagram-3UESZ5HK-tX2gOoo5.js} +1 -1
  259. package/web-shell/assets/{stateDiagram-AJRCARHV-DTJs_-I2.js → stateDiagram-AJRCARHV-CACN457G.js} +1 -1
  260. package/web-shell/assets/stateDiagram-v2-BHNVJYJU-DaUeO2zt.js +1 -0
  261. package/web-shell/assets/{timeline-definition-PNZ67QCA-Cd4AN7O0.js → timeline-definition-PNZ67QCA-DnHWKSOq.js} +1 -1
  262. package/web-shell/assets/{vennDiagram-CIIHVFJN-xIG-rUU9.js → vennDiagram-CIIHVFJN-BO8Yl2FG.js} +1 -1
  263. package/web-shell/assets/{wardley-L42UT6IY-D1UyjIcG.js → wardley-L42UT6IY-1NMqqrBi.js} +1 -1
  264. package/web-shell/assets/{wardleyDiagram-YWT4CUSO-BVM0Mb99.js → wardleyDiagram-YWT4CUSO-C3eWgIvD.js} +1 -1
  265. package/web-shell/assets/{xychartDiagram-2RQKCTM6-BX31JDSz.js → xychartDiagram-2RQKCTM6-D0h8FgFX.js} +1 -1
  266. package/web-shell/index.html +2 -2
  267. package/chunks/chunk-EDFD7VOX.js +0 -368
  268. package/chunks/chunk-GFYFLDEG.js +0 -709
  269. package/chunks/chunk-LUJQUNKY.js +0 -3288
  270. package/chunks/nonInteractiveCli-YURFHZV5.js +0 -129
  271. package/web-shell/assets/channel-Bi5TehaT.js +0 -1
  272. package/web-shell/assets/classDiagram-4FO5ZUOK-BKhhRdd1.js +0 -1
  273. package/web-shell/assets/classDiagram-v2-Q7XG4LA2-BKhhRdd1.js +0 -1
  274. package/web-shell/assets/index-C_ouplMQ.js +0 -1187
  275. package/web-shell/assets/index-XGDFJE-X.css +0 -5
  276. package/web-shell/assets/stateDiagram-v2-BHNVJYJU-DrfFMYta.js +0 -1
@@ -1,16 +1,15 @@
1
1
  // Force strict mode and setup for ESM
2
2
  "use strict";
3
3
  import {
4
- formatHistoryGapNotice,
5
- indexGapsByChild
6
- } from "./chunk-HZ4M2UQD.js";
4
+ formatHistoryGapNotice
5
+ } from "./chunk-TFNZCC4B.js";
7
6
  import {
8
7
  sanitizeTerminalText
9
- } from "./chunk-J6NT5YTN.js";
8
+ } from "./chunk-RS7MT2QG.js";
10
9
  import {
11
10
  isGoalStatusKind,
12
11
  isTerminalGoalStatusKind
13
- } from "./chunk-76BFY7AF.js";
12
+ } from "./chunk-QTERJVPZ.js";
14
13
  import {
15
14
  require_undici
16
15
  } from "./chunk-L573Z2QZ.js";
@@ -24,18 +23,18 @@ import {
24
23
  setGoalTerminalObserver,
25
24
  setLastGoalTerminal,
26
25
  unregisterGoalHook
27
- } from "./chunk-GCY7QTCE.js";
26
+ } from "./chunk-JDPCOUZ3.js";
28
27
  import {
29
28
  apiActivityTracker,
30
29
  formatVisionBridgeNoticeDisplay,
31
30
  isVisionBridgeNoticeDisplay
32
- } from "./chunk-CPU6I5YV.js";
31
+ } from "./chunk-I6JUVU7J.js";
33
32
  import {
34
33
  ToolNames
35
- } from "./chunk-ANRANWVE.js";
34
+ } from "./chunk-OP4MOGXF.js";
36
35
  import {
37
36
  createDebugLogger
38
- } from "./chunk-UE5TZ55T.js";
37
+ } from "./chunk-C27BYUX6.js";
39
38
  import {
40
39
  init_esbuild_shims
41
40
  } from "./chunk-5O2XNYP6.js";
@@ -683,6 +682,856 @@ __name(realpathOrResolve, "realpathOrResolve");
683
682
  // packages/cli/src/acp-integration/session/emitters/MessageEmitter.ts
684
683
  init_esbuild_shims();
685
684
 
685
+ // packages/acp-bridge/src/transcript-replay.ts
686
+ init_esbuild_shims();
687
+ var MISSING_TRANSCRIPT_TOOL_RESULT_MESSAGE = "Tool result missing from saved history; the previous run likely ended before this tool completed.";
688
+ var TRANSCRIPT_GOAL_STATUS_KINDS = /* @__PURE__ */ new Set([
689
+ "set",
690
+ "achieved",
691
+ "cleared",
692
+ "failed",
693
+ "aborted",
694
+ "checking"
695
+ ]);
696
+ function isObjectRecord(value) {
697
+ return typeof value === "object" && value !== null && !Array.isArray(value);
698
+ }
699
+ __name(isObjectRecord, "isObjectRecord");
700
+ function toTranscriptEpochMs(timestamp) {
701
+ if (typeof timestamp === "number") {
702
+ return Number.isFinite(timestamp) ? timestamp : void 0;
703
+ }
704
+ if (typeof timestamp !== "string") return void 0;
705
+ const epochMs = new Date(timestamp).getTime();
706
+ return Number.isFinite(epochMs) ? epochMs : void 0;
707
+ }
708
+ __name(toTranscriptEpochMs, "toTranscriptEpochMs");
709
+ function buildUpdateMeta(options) {
710
+ const timestamp = toTranscriptEpochMs(options.timestamp);
711
+ const sourceRecordIds = dedupeStrings(options.sourceRecordIds ?? []);
712
+ const qwenTranscript = {
713
+ ...sourceRecordIds.length > 0 ? { sourceRecordIds } : {},
714
+ ...options.planToolCallId ? { planToolCallId: options.planToolCallId } : {}
715
+ };
716
+ const meta = {
717
+ ...options.extra ?? {},
718
+ ...timestamp !== void 0 ? { timestamp } : {},
719
+ ...Object.keys(qwenTranscript).length > 0 ? { qwenTranscript } : {}
720
+ };
721
+ return Object.keys(meta).length > 0 ? meta : void 0;
722
+ }
723
+ __name(buildUpdateMeta, "buildUpdateMeta");
724
+ function createTranscriptMessageUpdate(options) {
725
+ const meta = buildUpdateMeta(options);
726
+ return {
727
+ sessionUpdate: options.role === "user" ? "user_message_chunk" : options.thought ? "agent_thought_chunk" : "agent_message_chunk",
728
+ content: { type: "text", text: options.text },
729
+ ...meta ? { _meta: meta } : {}
730
+ };
731
+ }
732
+ __name(createTranscriptMessageUpdate, "createTranscriptMessageUpdate");
733
+ function createTranscriptImageUpdate(options) {
734
+ const meta = buildUpdateMeta(options);
735
+ return {
736
+ sessionUpdate: "user_message_chunk",
737
+ content: { type: "image", data: options.data, mimeType: options.mimeType },
738
+ ...meta ? { _meta: meta } : {}
739
+ };
740
+ }
741
+ __name(createTranscriptImageUpdate, "createTranscriptImageUpdate");
742
+ function createTranscriptUsageUpdate(usageMetadata, options = {}) {
743
+ const usage = {
744
+ inputTokens: finiteNumber2(usageMetadata.promptTokenCount) ?? 0,
745
+ outputTokens: finiteNumber2(usageMetadata.candidatesTokenCount) ?? 0,
746
+ totalTokens: finiteNumber2(usageMetadata.totalTokenCount) ?? 0,
747
+ ...finiteNumber2(usageMetadata.thoughtsTokenCount) !== void 0 ? { thoughtTokens: finiteNumber2(usageMetadata.thoughtsTokenCount) } : {},
748
+ ...finiteNumber2(usageMetadata.cachedContentTokenCount) !== void 0 ? {
749
+ cachedReadTokens: finiteNumber2(usageMetadata.cachedContentTokenCount)
750
+ } : {}
751
+ };
752
+ const meta = buildUpdateMeta({
753
+ ...options,
754
+ extra: { usage, ...options.extra ?? {} }
755
+ });
756
+ return {
757
+ sessionUpdate: "agent_message_chunk",
758
+ content: { type: "text", text: options.text ?? "" },
759
+ _meta: meta
760
+ };
761
+ }
762
+ __name(createTranscriptUsageUpdate, "createTranscriptUsageUpdate");
763
+ function createTranscriptToolCallStartUpdate(options) {
764
+ const provenance = resolveToolProvenance(options.toolName);
765
+ return {
766
+ sessionUpdate: options.asUpdate ? "tool_call_update" : "tool_call",
767
+ toolCallId: options.callId,
768
+ status: options.status ?? "pending",
769
+ title: options.metadata.title,
770
+ content: [],
771
+ locations: [...options.metadata.locations],
772
+ kind: options.metadata.kind,
773
+ rawInput: options.args ?? {},
774
+ _meta: buildUpdateMeta({
775
+ ...options,
776
+ extra: {
777
+ toolName: options.toolName,
778
+ provenance: provenance.provenance,
779
+ ...provenance.serverId ? { serverId: provenance.serverId } : {},
780
+ ...options.extra ?? {}
781
+ }
782
+ })
783
+ };
784
+ }
785
+ __name(createTranscriptToolCallStartUpdate, "createTranscriptToolCallStartUpdate");
786
+ function createTranscriptToolCallResultUpdate(options) {
787
+ const provenance = resolveToolProvenance(options.toolName);
788
+ const content = buildToolResultContent(options);
789
+ const update = {
790
+ sessionUpdate: "tool_call_update",
791
+ toolCallId: options.callId,
792
+ status: options.success ? "completed" : "failed",
793
+ content,
794
+ _meta: buildUpdateMeta({
795
+ ...options,
796
+ extra: {
797
+ toolName: options.toolName,
798
+ provenance: provenance.provenance,
799
+ ...provenance.serverId ? { serverId: provenance.serverId } : {},
800
+ ...options.artifacts && options.artifacts.length > 0 ? { artifacts: options.artifacts } : {},
801
+ ...options.extra ?? {}
802
+ }
803
+ })
804
+ };
805
+ if (options.resultDisplay !== void 0 && !isTruncatedSessionDiffDisplay(options.resultDisplay)) {
806
+ update["rawOutput"] = options.resultDisplay;
807
+ }
808
+ return update;
809
+ }
810
+ __name(createTranscriptToolCallResultUpdate, "createTranscriptToolCallResultUpdate");
811
+ function createTranscriptPlanUpdate(todos, cumulativeUsage, options = {}) {
812
+ const meta = buildUpdateMeta({
813
+ ...options,
814
+ extra: {
815
+ ...cumulativeUsage ? { stats: { ...cumulativeUsage } } : {},
816
+ ...options.extra ?? {}
817
+ }
818
+ });
819
+ return {
820
+ sessionUpdate: "plan",
821
+ entries: todos.map((todo) => ({
822
+ content: todo.content,
823
+ priority: "medium",
824
+ status: todo.status
825
+ })),
826
+ ...meta ? { _meta: meta } : {}
827
+ };
828
+ }
829
+ __name(createTranscriptPlanUpdate, "createTranscriptPlanUpdate");
830
+ function extractTranscriptTodos(resultDisplay, args) {
831
+ const fromDisplay = extractTodosFromDisplay(resultDisplay);
832
+ if (fromDisplay) return fromDisplay;
833
+ return args && Array.isArray(args["todos"]) ? normalizeTodos(args["todos"]) : null;
834
+ }
835
+ __name(extractTranscriptTodos, "extractTranscriptTodos");
836
+ function createTranscriptReplayMachine(options = {}) {
837
+ return new DefaultTranscriptReplayMachine(options);
838
+ }
839
+ __name(createTranscriptReplayMachine, "createTranscriptReplayMachine");
840
+ var DefaultTranscriptReplayMachine = class {
841
+ constructor(options) {
842
+ this.options = options;
843
+ const initialState = parseInitialState(
844
+ options.initialState,
845
+ options.onDiagnostic
846
+ );
847
+ this.usage = { ...initialState.cumulativeUsage };
848
+ for (const pending of initialState.pendingToolCalls) {
849
+ this.pendingToolCalls.set(pending.callId, pending);
850
+ this.usedToolCallIds.add(pending.callId);
851
+ }
852
+ for (const gap of options.gaps ?? []) {
853
+ if (!this.gapByChild.has(gap.childUuid)) {
854
+ this.gapByChild.set(gap.childUuid, gap);
855
+ }
856
+ }
857
+ }
858
+ static {
859
+ __name(this, "DefaultTranscriptReplayMachine");
860
+ }
861
+ pendingToolCalls = /* @__PURE__ */ new Map();
862
+ usedToolCallIds = /* @__PURE__ */ new Set();
863
+ gapByChild = /* @__PURE__ */ new Map();
864
+ usage;
865
+ finalized = false;
866
+ *project(record) {
867
+ if (this.finalized) {
868
+ throw new Error(
869
+ "Cannot project records after transcript replay finalize."
870
+ );
871
+ }
872
+ let ordinal = 0;
873
+ const emit = /* @__PURE__ */ __name((update) => ({
874
+ sourceRecordId: record.uuid,
875
+ ...record.timestamp ? { sourceTimestamp: record.timestamp } : {},
876
+ emissionOrdinal: ordinal++,
877
+ update
878
+ }), "emit");
879
+ const meta = {
880
+ timestamp: record.timestamp,
881
+ sourceRecordIds: [record.uuid]
882
+ };
883
+ const gap = this.gapByChild.get(record.uuid);
884
+ if (gap) {
885
+ yield emit(
886
+ createTranscriptMessageUpdate({
887
+ role: "assistant",
888
+ text: this.formatGap(gap),
889
+ ...meta,
890
+ extra: { qwenDiscreteMessage: true }
891
+ })
892
+ );
893
+ }
894
+ switch (record.type) {
895
+ case "user":
896
+ yield* this.projectUserRecord(record, emit, meta);
897
+ break;
898
+ case "assistant":
899
+ yield* this.projectAssistantRecord(record, emit, meta);
900
+ break;
901
+ case "tool_result":
902
+ yield* this.projectToolResult(record, emit, meta);
903
+ break;
904
+ case "system":
905
+ yield* this.projectSystemRecord(record, emit, meta);
906
+ break;
907
+ default:
908
+ this.report(
909
+ "unknown_record_or_part",
910
+ "Skipped an unknown transcript record type.",
911
+ record.uuid
912
+ );
913
+ }
914
+ }
915
+ *finalize() {
916
+ if (this.finalized) return;
917
+ this.finalized = true;
918
+ let ordinal = 0;
919
+ for (const pending of [...this.pendingToolCalls.values()]) {
920
+ this.pendingToolCalls.delete(pending.callId);
921
+ yield {
922
+ sourceRecordId: pending.sourceRecordId,
923
+ ...pending.sourceTimestamp ? { sourceTimestamp: pending.sourceTimestamp } : {},
924
+ emissionOrdinal: ordinal++,
925
+ update: createTranscriptToolCallResultUpdate({
926
+ toolName: pending.toolName,
927
+ callId: pending.callId,
928
+ success: false,
929
+ errorMessage: MISSING_TRANSCRIPT_TOOL_RESULT_MESSAGE,
930
+ timestamp: pending.sourceTimestamp,
931
+ sourceRecordIds: [pending.sourceRecordId]
932
+ })
933
+ };
934
+ }
935
+ }
936
+ snapshot() {
937
+ return {
938
+ v: 1,
939
+ pendingToolCalls: [...this.pendingToolCalls.values()].map((pending) => ({
940
+ ...pending
941
+ })),
942
+ cumulativeUsage: { ...this.usage }
943
+ };
944
+ }
945
+ *projectUserRecord(record, emit, meta) {
946
+ if (record.subtype === "notification" || record.subtype === "cron" || record.subtype === "mid_turn_user_message") {
947
+ const payload = isObjectRecord(record.systemPayload) ? record.systemPayload : void 0;
948
+ const displayText = payload && typeof payload["displayText"] === "string" ? payload["displayText"] : void 0;
949
+ if (displayText) {
950
+ yield emit(
951
+ createTranscriptMessageUpdate({
952
+ role: "user",
953
+ text: displayText,
954
+ ...meta,
955
+ ...record.subtype === "cron" ? { extra: { source: "cron" } } : {}
956
+ })
957
+ );
958
+ return;
959
+ }
960
+ if (record.subtype !== "mid_turn_user_message") return;
961
+ }
962
+ yield* this.projectMessageParts(record, "user", emit, meta);
963
+ }
964
+ *projectAssistantRecord(record, emit, meta) {
965
+ const usageMetadata = isObjectRecord(record.usageMetadata) ? record.usageMetadata : void 0;
966
+ let usageEmitted = false;
967
+ const takeUsageUpdate = /* @__PURE__ */ __name(() => {
968
+ if (!usageMetadata || usageEmitted) return void 0;
969
+ usageEmitted = true;
970
+ this.addUsage(usageMetadata);
971
+ return createTranscriptUsageUpdate(usageMetadata, meta);
972
+ }, "takeUsageUpdate");
973
+ yield* this.projectMessageParts(
974
+ record,
975
+ "assistant",
976
+ emit,
977
+ meta,
978
+ takeUsageUpdate
979
+ );
980
+ const trailingUsage = takeUsageUpdate();
981
+ if (trailingUsage) yield emit(trailingUsage);
982
+ }
983
+ *projectMessageParts(record, role, emit, meta, beforeToolCall) {
984
+ const parts = record.message?.parts;
985
+ if (!parts) return;
986
+ for (let partIndex = 0; partIndex < parts.length; partIndex += 1) {
987
+ const part = parts[partIndex];
988
+ if (!isObjectRecord(part)) {
989
+ this.report(
990
+ "malformed_part",
991
+ "Skipped a malformed transcript message part.",
992
+ record.uuid,
993
+ `message.parts[${partIndex}]`
994
+ );
995
+ continue;
996
+ }
997
+ let recognized = false;
998
+ if (typeof part["text"] === "string" && part["text"].length > 0) {
999
+ recognized = true;
1000
+ yield emit(
1001
+ createTranscriptMessageUpdate({
1002
+ role,
1003
+ text: part["text"],
1004
+ thought: role === "assistant" && part["thought"] === true,
1005
+ ...meta
1006
+ })
1007
+ );
1008
+ }
1009
+ const inlineData = isObjectRecord(part["inlineData"]) ? part["inlineData"] : void 0;
1010
+ if (inlineData) {
1011
+ recognized = true;
1012
+ const data = inlineData["data"];
1013
+ const mimeType = inlineData["mimeType"];
1014
+ if (role === "user" && typeof data === "string" && typeof mimeType === "string" && mimeType.startsWith("image/")) {
1015
+ yield emit(createTranscriptImageUpdate({ data, mimeType, ...meta }));
1016
+ } else {
1017
+ this.report(
1018
+ "malformed_part",
1019
+ "Skipped an unsupported or malformed inline transcript part.",
1020
+ record.uuid,
1021
+ `message.parts[${partIndex}].inlineData`
1022
+ );
1023
+ }
1024
+ }
1025
+ const functionCall = isObjectRecord(part["functionCall"]) ? part["functionCall"] : void 0;
1026
+ if (functionCall) {
1027
+ recognized = true;
1028
+ const toolName = typeof functionCall["name"] === "string" ? functionCall["name"] : "";
1029
+ const args = isObjectRecord(functionCall["args"]) ? functionCall["args"] : {};
1030
+ if (!toolName) {
1031
+ this.report(
1032
+ "malformed_part",
1033
+ "Skipped a tool call without a tool name.",
1034
+ record.uuid,
1035
+ `message.parts[${partIndex}].functionCall`
1036
+ );
1037
+ continue;
1038
+ }
1039
+ const preToolUpdate = beforeToolCall?.();
1040
+ if (preToolUpdate) yield emit(preToolUpdate);
1041
+ if (toolName === "todo_write") continue;
1042
+ const explicitId = typeof functionCall["id"] === "string" && functionCall["id"].length > 0 ? functionCall["id"] : void 0;
1043
+ const callId = this.allocateToolCallId(
1044
+ explicitId ?? `qwen-replay-tool:${record.uuid}:${partIndex}`
1045
+ );
1046
+ const update = createTranscriptToolCallStartUpdate({
1047
+ toolName,
1048
+ callId,
1049
+ args,
1050
+ status: "in_progress",
1051
+ metadata: this.resolveToolMetadata(toolName, args, record.uuid),
1052
+ ...meta
1053
+ });
1054
+ yield emit(update);
1055
+ if (role === "assistant") {
1056
+ this.pendingToolCalls.set(callId, {
1057
+ callId,
1058
+ toolName,
1059
+ sourceRecordId: record.uuid,
1060
+ ...record.timestamp ? { sourceTimestamp: record.timestamp } : {}
1061
+ });
1062
+ }
1063
+ }
1064
+ if (!recognized && !("functionResponse" in part)) {
1065
+ this.report(
1066
+ "unknown_record_or_part",
1067
+ "Skipped an unknown transcript message part.",
1068
+ record.uuid,
1069
+ `message.parts[${partIndex}]`
1070
+ );
1071
+ }
1072
+ }
1073
+ }
1074
+ *projectToolResult(record, emit, meta) {
1075
+ const result = isObjectRecord(record.toolCallResult) ? record.toolCallResult : void 0;
1076
+ const toolName = extractToolName(record);
1077
+ if (!toolName) {
1078
+ this.report(
1079
+ "malformed_part",
1080
+ "A transcript tool result has no tool name.",
1081
+ record.uuid,
1082
+ "message.parts"
1083
+ );
1084
+ }
1085
+ const explicitCallId = extractToolResultCallId(record, result);
1086
+ const callId = explicitCallId ? this.allocateToolCallId(explicitCallId, true) : this.correlateResultCallId(toolName, record.uuid);
1087
+ this.pendingToolCalls.delete(callId);
1088
+ const resultDisplay = result?.["resultDisplay"];
1089
+ if (toolName === "todo_write") {
1090
+ const todos = extractTranscriptTodos(resultDisplay);
1091
+ if (todos) {
1092
+ yield emit(
1093
+ createTranscriptPlanUpdate(todos, this.usage, {
1094
+ ...meta,
1095
+ planToolCallId: callId
1096
+ })
1097
+ );
1098
+ }
1099
+ return;
1100
+ }
1101
+ yield emit(
1102
+ createTranscriptToolCallResultUpdate({
1103
+ toolName,
1104
+ callId,
1105
+ success: result?.["status"] === void 0 ? !result?.["error"] : result["status"] === "success" && !result["error"],
1106
+ errorMessage: extractErrorMessage(result?.["error"]),
1107
+ message: record.message?.parts,
1108
+ resultDisplay,
1109
+ artifacts: Array.isArray(result?.["artifacts"]) ? result["artifacts"] : void 0,
1110
+ contentPrefix: this.buildToolResultContentPrefix(
1111
+ resultDisplay,
1112
+ record.uuid
1113
+ ),
1114
+ ...meta
1115
+ })
1116
+ );
1117
+ if (isTaskExecutionDisplay(resultDisplay)) {
1118
+ const usage = usageFromTaskExecution(resultDisplay);
1119
+ if (Object.keys(usage).length > 0) {
1120
+ this.addUsage(usage);
1121
+ yield emit(createTranscriptUsageUpdate(usage, meta));
1122
+ }
1123
+ }
1124
+ }
1125
+ *projectSystemRecord(record, emit, meta) {
1126
+ if (record.subtype !== "slash_command") return;
1127
+ const payload = isObjectRecord(record.systemPayload) ? record.systemPayload : void 0;
1128
+ if (payload?.["phase"] !== "result") return;
1129
+ const items = Array.isArray(payload["outputHistoryItems"]) ? payload["outputHistoryItems"] : [];
1130
+ for (const item of items) {
1131
+ const goalStatus = parseTranscriptGoalStatus(item);
1132
+ if (goalStatus) {
1133
+ if (goalStatus.condition.length === 0) {
1134
+ this.report(
1135
+ "malformed_part",
1136
+ "Skipped replay of a goal card whose condition is empty.",
1137
+ record.uuid,
1138
+ "systemPayload.outputHistoryItems.goalStatus.condition"
1139
+ );
1140
+ } else if (goalStatus.kind !== "checking") {
1141
+ yield emit(
1142
+ createTranscriptMessageUpdate({
1143
+ role: "assistant",
1144
+ text: "",
1145
+ ...meta,
1146
+ extra: { goalStatus }
1147
+ })
1148
+ );
1149
+ }
1150
+ continue;
1151
+ }
1152
+ if (!isObjectRecord(item) || typeof item["text"] !== "string") continue;
1153
+ yield emit(
1154
+ createTranscriptMessageUpdate({
1155
+ role: "assistant",
1156
+ text: item["text"].replace(/\n/g, " \n"),
1157
+ ...meta,
1158
+ extra: { source: "slash_command" }
1159
+ })
1160
+ );
1161
+ }
1162
+ }
1163
+ addUsage(metadata) {
1164
+ this.usage.promptTokens += finiteNumber2(metadata["promptTokenCount"]) ?? 0;
1165
+ this.usage.candidateTokens += finiteNumber2(metadata["candidatesTokenCount"]) ?? 0;
1166
+ this.usage.cachedTokens += finiteNumber2(metadata["cachedContentTokenCount"]) ?? 0;
1167
+ }
1168
+ correlateResultCallId(toolName, recordId) {
1169
+ const candidates = [...this.pendingToolCalls.values()].filter(
1170
+ (pending) => pending.toolName === toolName
1171
+ );
1172
+ if (candidates.length === 1) return candidates[0].callId;
1173
+ this.report(
1174
+ "ambiguous_tool_call_correlation",
1175
+ "A tool result could not be matched to exactly one pending tool call.",
1176
+ recordId
1177
+ );
1178
+ return this.allocateToolCallId(`qwen-replay-tool:${recordId}:result`);
1179
+ }
1180
+ allocateToolCallId(candidate, reuse = false) {
1181
+ if (reuse && this.pendingToolCalls.has(candidate)) {
1182
+ this.usedToolCallIds.add(candidate);
1183
+ return candidate;
1184
+ }
1185
+ if (!this.usedToolCallIds.has(candidate)) {
1186
+ this.usedToolCallIds.add(candidate);
1187
+ return candidate;
1188
+ }
1189
+ let occurrence = 2;
1190
+ while (this.usedToolCallIds.has(`${candidate}:${occurrence}`)) {
1191
+ occurrence += 1;
1192
+ }
1193
+ const id = `${candidate}:${occurrence}`;
1194
+ this.usedToolCallIds.add(id);
1195
+ return id;
1196
+ }
1197
+ resolveToolMetadata(toolName, args, recordId) {
1198
+ try {
1199
+ return this.options.presentation?.resolveToolMetadata(toolName, args) ?? fallbackToolMetadata(toolName, args);
1200
+ } catch {
1201
+ this.report(
1202
+ "presentation_fallback",
1203
+ "Tool presentation metadata fell back to deterministic defaults.",
1204
+ recordId,
1205
+ void 0,
1206
+ false
1207
+ );
1208
+ return fallbackToolMetadata(toolName, args);
1209
+ }
1210
+ }
1211
+ formatGap(gap) {
1212
+ try {
1213
+ return this.options.presentation?.formatHistoryGap(gap) ?? "Some earlier messages are unavailable because the saved history is incomplete.";
1214
+ } catch {
1215
+ this.report(
1216
+ "presentation_fallback",
1217
+ "History gap presentation fell back to deterministic defaults.",
1218
+ gap.childUuid,
1219
+ void 0,
1220
+ false
1221
+ );
1222
+ return "Some earlier messages are unavailable because the saved history is incomplete.";
1223
+ }
1224
+ }
1225
+ buildToolResultContentPrefix(resultDisplay, recordId) {
1226
+ try {
1227
+ return this.options.presentation?.buildToolResultContentPrefix?.(
1228
+ resultDisplay
1229
+ ) ?? defaultToolResultContentPrefix(resultDisplay);
1230
+ } catch {
1231
+ this.report(
1232
+ "presentation_fallback",
1233
+ "Tool result content presentation fell back to deterministic defaults.",
1234
+ recordId,
1235
+ void 0,
1236
+ false
1237
+ );
1238
+ return defaultToolResultContentPrefix(resultDisplay);
1239
+ }
1240
+ }
1241
+ report(code, message, recordId, path2, affectsCompleteness = true) {
1242
+ this.options.onDiagnostic?.({
1243
+ code,
1244
+ severity: affectsCompleteness ? "warning" : "info",
1245
+ message,
1246
+ affectsCompleteness,
1247
+ ...recordId ? { recordId } : {},
1248
+ ...path2 ? { path: path2 } : {}
1249
+ });
1250
+ }
1251
+ };
1252
+ function parseTranscriptGoalStatus(value) {
1253
+ if (!isObjectRecord(value) || value["type"] !== "goal_status") {
1254
+ return void 0;
1255
+ }
1256
+ const kind = value["kind"];
1257
+ const condition = value["condition"];
1258
+ if (typeof kind !== "string" || !TRANSCRIPT_GOAL_STATUS_KINDS.has(kind) || typeof condition !== "string") {
1259
+ return void 0;
1260
+ }
1261
+ const iterations = finiteNumber2(value["iterations"]);
1262
+ const setAt = finiteNumber2(value["setAt"]);
1263
+ const durationMs = finiteNumber2(value["durationMs"]);
1264
+ const lastReason = typeof value["lastReason"] === "string" ? value["lastReason"] : void 0;
1265
+ return {
1266
+ kind,
1267
+ condition,
1268
+ ...iterations !== void 0 ? { iterations } : {},
1269
+ ...setAt !== void 0 ? { setAt } : {},
1270
+ ...durationMs !== void 0 ? { durationMs } : {},
1271
+ ...lastReason !== void 0 ? { lastReason } : {}
1272
+ };
1273
+ }
1274
+ __name(parseTranscriptGoalStatus, "parseTranscriptGoalStatus");
1275
+ function defaultToolResultContentPrefix(resultDisplay) {
1276
+ if (!isObjectRecord(resultDisplay) || resultDisplay["type"] !== "vision_bridge_notice" || typeof resultDisplay["summary"] !== "string" || typeof resultDisplay["notice"] !== "string") {
1277
+ return [];
1278
+ }
1279
+ return [
1280
+ {
1281
+ type: "content",
1282
+ content: {
1283
+ type: "text",
1284
+ text: `${resultDisplay["summary"]}
1285
+ ${resultDisplay["notice"]}`
1286
+ }
1287
+ }
1288
+ ];
1289
+ }
1290
+ __name(defaultToolResultContentPrefix, "defaultToolResultContentPrefix");
1291
+ function parseInitialState(value, onDiagnostic) {
1292
+ const empty = {
1293
+ v: 1,
1294
+ pendingToolCalls: [],
1295
+ cumulativeUsage: emptyUsage()
1296
+ };
1297
+ if (value === void 0) return empty;
1298
+ if (!isObjectRecord(value)) {
1299
+ throw new TypeError("Invalid transcript replay state.");
1300
+ }
1301
+ if ("v" in value && value["v"] !== 1) {
1302
+ throw new TypeError("Unsupported transcript replay state version.");
1303
+ }
1304
+ const rawPending = Array.isArray(value["pendingToolCalls"]) ? value["pendingToolCalls"] : [];
1305
+ const pendingToolCalls = rawPending.flatMap(
1306
+ (pending) => {
1307
+ if (!isObjectRecord(pending) || typeof pending["callId"] !== "string" || typeof pending["toolName"] !== "string" || typeof pending["sourceRecordId"] !== "string") {
1308
+ onDiagnostic?.({
1309
+ code: "invalid_replay_state",
1310
+ severity: "warning",
1311
+ message: "Dropped a malformed pending tool call from replay state.",
1312
+ affectsCompleteness: true
1313
+ });
1314
+ return [];
1315
+ }
1316
+ return [
1317
+ {
1318
+ callId: pending["callId"],
1319
+ toolName: pending["toolName"],
1320
+ sourceRecordId: pending["sourceRecordId"],
1321
+ ...typeof pending["sourceTimestamp"] === "string" ? { sourceTimestamp: pending["sourceTimestamp"] } : {}
1322
+ }
1323
+ ];
1324
+ }
1325
+ );
1326
+ const rawUsage = value.cumulativeUsage;
1327
+ const usage = isObjectRecord(rawUsage) ? rawUsage : {};
1328
+ const validUsage = finiteNumber2(usage["promptTokens"]) !== void 0 && finiteNumber2(usage["cachedTokens"]) !== void 0 && finiteNumber2(usage["candidateTokens"]) !== void 0 && finiteNumber2(usage["apiTimeMs"]) !== void 0;
1329
+ if (!validUsage) {
1330
+ onDiagnostic?.({
1331
+ code: "invalid_replay_state",
1332
+ severity: "warning",
1333
+ message: "Reset invalid cumulative usage in transcript replay state.",
1334
+ affectsCompleteness: true
1335
+ });
1336
+ }
1337
+ return {
1338
+ v: 1,
1339
+ pendingToolCalls,
1340
+ cumulativeUsage: validUsage ? {
1341
+ promptTokens: usage["promptTokens"],
1342
+ cachedTokens: usage["cachedTokens"],
1343
+ candidateTokens: usage["candidateTokens"],
1344
+ apiTimeMs: usage["apiTimeMs"]
1345
+ } : emptyUsage()
1346
+ };
1347
+ }
1348
+ __name(parseInitialState, "parseInitialState");
1349
+ function emptyUsage() {
1350
+ return {
1351
+ promptTokens: 0,
1352
+ cachedTokens: 0,
1353
+ candidateTokens: 0,
1354
+ apiTimeMs: 0
1355
+ };
1356
+ }
1357
+ __name(emptyUsage, "emptyUsage");
1358
+ function fallbackToolMetadata(toolName, args) {
1359
+ const description = typeof args["description"] === "string" ? args["description"].trim() : "";
1360
+ return {
1361
+ title: description ? `${toolName}: ${description}` : toolName,
1362
+ locations: [],
1363
+ kind: "other"
1364
+ };
1365
+ }
1366
+ __name(fallbackToolMetadata, "fallbackToolMetadata");
1367
+ function resolveToolProvenance(toolName) {
1368
+ if (toolName.startsWith("mcp__")) {
1369
+ const parts = toolName.split("__");
1370
+ if (parts.length >= 3 && parts[1]) {
1371
+ return { provenance: "mcp", serverId: parts[1] };
1372
+ }
1373
+ }
1374
+ return { provenance: "builtin" };
1375
+ }
1376
+ __name(resolveToolProvenance, "resolveToolProvenance");
1377
+ function buildToolResultContent(options) {
1378
+ const prefix = [...options.contentPrefix ?? []];
1379
+ const diff = extractDiffContent(options.resultDisplay);
1380
+ if (diff) return [...prefix, diff];
1381
+ if (options.errorMessage) {
1382
+ return [
1383
+ ...prefix,
1384
+ {
1385
+ type: "content",
1386
+ content: { type: "text", text: options.errorMessage }
1387
+ }
1388
+ ];
1389
+ }
1390
+ const content = [...prefix];
1391
+ for (const part of options.message ?? []) {
1392
+ if (!isObjectRecord(part)) continue;
1393
+ if (typeof part["text"] === "string" && part["text"]) {
1394
+ content.push({
1395
+ type: "content",
1396
+ content: { type: "text", text: part["text"] }
1397
+ });
1398
+ }
1399
+ const response = isObjectRecord(part["functionResponse"]) ? part["functionResponse"] : void 0;
1400
+ const payload = response && isObjectRecord(response["response"]) ? response["response"] : void 0;
1401
+ if (!payload) continue;
1402
+ try {
1403
+ const output = payload["output"];
1404
+ const error = payload["error"];
1405
+ const text = typeof output === "string" ? output : typeof error === "string" ? error : JSON.stringify(payload);
1406
+ content.push({
1407
+ type: "content",
1408
+ content: { type: "text", text }
1409
+ });
1410
+ } catch {
1411
+ }
1412
+ }
1413
+ return content;
1414
+ }
1415
+ __name(buildToolResultContent, "buildToolResultContent");
1416
+ function extractDiffContent(resultDisplay) {
1417
+ if (!isObjectRecord(resultDisplay)) return null;
1418
+ if (!("fileName" in resultDisplay) || !("newContent" in resultDisplay)) {
1419
+ return null;
1420
+ }
1421
+ if (isTruncatedSessionDiffDisplay(resultDisplay)) {
1422
+ return {
1423
+ type: "content",
1424
+ content: {
1425
+ type: "text",
1426
+ text: buildTruncatedDiffPreviewText(resultDisplay)
1427
+ }
1428
+ };
1429
+ }
1430
+ return {
1431
+ type: "diff",
1432
+ path: typeof resultDisplay["fileName"] === "string" ? resultDisplay["fileName"] : "",
1433
+ oldText: typeof resultDisplay["originalContent"] === "string" ? resultDisplay["originalContent"] : "",
1434
+ newText: typeof resultDisplay["newContent"] === "string" ? resultDisplay["newContent"] : ""
1435
+ };
1436
+ }
1437
+ __name(extractDiffContent, "extractDiffContent");
1438
+ function isTruncatedSessionDiffDisplay(value) {
1439
+ return isObjectRecord(value) && value["truncatedForSession"] === true && "fileName" in value && "newContent" in value;
1440
+ }
1441
+ __name(isTruncatedSessionDiffDisplay, "isTruncatedSessionDiffDisplay");
1442
+ function buildTruncatedDiffPreviewText(display) {
1443
+ const fileName = typeof display["fileName"] === "string" ? display["fileName"] : "the edited file";
1444
+ const fileDiffLength = typeof display["fileDiffLength"] === "number" ? ` Original fileDiff length: ${display["fileDiffLength"]} chars.` : "";
1445
+ return display["fileDiffTruncated"] === true ? `Full diff omitted from saved session history for ${fileName}.${fileDiffLength}` : `Saved session preview only for ${fileName}; full original and new file contents are unavailable.`;
1446
+ }
1447
+ __name(buildTruncatedDiffPreviewText, "buildTruncatedDiffPreviewText");
1448
+ function extractToolName(record) {
1449
+ for (const part of record.message?.parts ?? []) {
1450
+ if (!isObjectRecord(part) || !isObjectRecord(part["functionResponse"])) {
1451
+ continue;
1452
+ }
1453
+ const name = part["functionResponse"]["name"];
1454
+ if (typeof name === "string") return name;
1455
+ }
1456
+ return "";
1457
+ }
1458
+ __name(extractToolName, "extractToolName");
1459
+ function extractToolResultCallId(record, result) {
1460
+ if (typeof result?.["callId"] === "string" && result["callId"].length > 0) {
1461
+ return result["callId"];
1462
+ }
1463
+ for (const part of record.message?.parts ?? []) {
1464
+ if (!isObjectRecord(part) || !isObjectRecord(part["functionResponse"])) {
1465
+ continue;
1466
+ }
1467
+ const id = part["functionResponse"]["id"];
1468
+ if (typeof id === "string" && id.length > 0) return id;
1469
+ }
1470
+ return void 0;
1471
+ }
1472
+ __name(extractToolResultCallId, "extractToolResultCallId");
1473
+ function extractTodosFromDisplay(value) {
1474
+ if (isObjectRecord(value) && value["type"] === "todo_list") {
1475
+ return Array.isArray(value["todos"]) ? normalizeTodos(value["todos"]) : null;
1476
+ }
1477
+ if (typeof value !== "string") return null;
1478
+ try {
1479
+ const parsed = JSON.parse(value);
1480
+ return isObjectRecord(parsed) && parsed["type"] === "todo_list" && Array.isArray(parsed["todos"]) ? normalizeTodos(parsed["todos"]) : null;
1481
+ } catch {
1482
+ return null;
1483
+ }
1484
+ }
1485
+ __name(extractTodosFromDisplay, "extractTodosFromDisplay");
1486
+ function normalizeTodos(values) {
1487
+ return values.flatMap((value) => {
1488
+ if (!isObjectRecord(value) || typeof value["content"] !== "string")
1489
+ return [];
1490
+ const status = value["status"];
1491
+ if (status !== "pending" && status !== "in_progress" && status !== "completed") {
1492
+ return [];
1493
+ }
1494
+ return [
1495
+ {
1496
+ ...typeof value["id"] === "string" ? { id: value["id"] } : {},
1497
+ content: value["content"],
1498
+ status
1499
+ }
1500
+ ];
1501
+ });
1502
+ }
1503
+ __name(normalizeTodos, "normalizeTodos");
1504
+ function isTaskExecutionDisplay(value) {
1505
+ return isObjectRecord(value) && value["type"] === "task_execution";
1506
+ }
1507
+ __name(isTaskExecutionDisplay, "isTaskExecutionDisplay");
1508
+ function usageFromTaskExecution(display) {
1509
+ const summary = isObjectRecord(display["executionSummary"]) ? display["executionSummary"] : void 0;
1510
+ if (!summary) return {};
1511
+ return {
1512
+ ...finiteNumber2(summary["inputTokens"]) !== void 0 ? { promptTokenCount: summary["inputTokens"] } : {},
1513
+ ...finiteNumber2(summary["outputTokens"]) !== void 0 ? { candidatesTokenCount: summary["outputTokens"] } : {},
1514
+ ...finiteNumber2(summary["thoughtTokens"]) !== void 0 ? { thoughtsTokenCount: summary["thoughtTokens"] } : {},
1515
+ ...finiteNumber2(summary["cachedTokens"]) !== void 0 ? { cachedContentTokenCount: summary["cachedTokens"] } : {},
1516
+ ...finiteNumber2(summary["totalTokens"]) !== void 0 ? { totalTokenCount: summary["totalTokens"] } : {}
1517
+ };
1518
+ }
1519
+ __name(usageFromTaskExecution, "usageFromTaskExecution");
1520
+ function finiteNumber2(value) {
1521
+ return typeof value === "number" && Number.isFinite(value) ? value : void 0;
1522
+ }
1523
+ __name(finiteNumber2, "finiteNumber");
1524
+ function extractErrorMessage(value) {
1525
+ if (value instanceof Error) return value.message;
1526
+ if (!isObjectRecord(value)) return void 0;
1527
+ return typeof value["message"] === "string" ? value["message"] : void 0;
1528
+ }
1529
+ __name(extractErrorMessage, "extractErrorMessage");
1530
+ function dedupeStrings(values) {
1531
+ return [...new Set(values.filter((value) => value.length > 0))];
1532
+ }
1533
+ __name(dedupeStrings, "dedupeStrings");
1534
+
686
1535
  // packages/cli/src/acp-integration/session/emitters/base-emitter.ts
687
1536
  init_esbuild_shims();
688
1537
  var BaseEmitter = class {
@@ -785,16 +1634,14 @@ var MessageEmitter = class extends BaseEmitter {
785
1634
  * @param timestamp - Optional server-side timestamp (ISO string or ms) for message ordering
786
1635
  */
787
1636
  async emitUserMessage(text, timestamp, options = {}) {
788
- const epochMs = BaseEmitter.toEpochMs(timestamp);
789
- const _meta = {
790
- ...epochMs != null ? { timestamp: epochMs } : {},
791
- ...options.source ? { source: options.source } : {}
792
- };
793
- await this.sendUpdate({
794
- sessionUpdate: "user_message_chunk",
795
- content: { type: "text", text },
796
- ...Object.keys(_meta).length > 0 ? { _meta } : {}
797
- });
1637
+ await this.sendUpdate(
1638
+ createTranscriptMessageUpdate({
1639
+ role: "user",
1640
+ text,
1641
+ timestamp,
1642
+ ...options.source ? { extra: { source: options.source } } : {}
1643
+ })
1644
+ );
798
1645
  }
799
1646
  /**
800
1647
  * Emits an agent thought chunk.
@@ -803,15 +1650,15 @@ var MessageEmitter = class extends BaseEmitter {
803
1650
  * @param timestamp - Optional server-side timestamp (ISO string or ms) for message ordering
804
1651
  */
805
1652
  async emitAgentThought(text, timestamp, subagentMeta) {
806
- const _meta = this.buildChunkMeta(
807
- BaseEmitter.toEpochMs(timestamp),
808
- subagentMeta
1653
+ await this.sendUpdate(
1654
+ createTranscriptMessageUpdate({
1655
+ role: "assistant",
1656
+ thought: true,
1657
+ text,
1658
+ timestamp,
1659
+ ...subagentMeta ? { extra: { ...subagentMeta } } : {}
1660
+ })
809
1661
  );
810
- await this.sendUpdate({
811
- sessionUpdate: "agent_thought_chunk",
812
- content: { type: "text", text },
813
- ..._meta ? { _meta } : {}
814
- });
815
1662
  }
816
1663
  /**
817
1664
  * Emits an agent message chunk.
@@ -820,15 +1667,14 @@ var MessageEmitter = class extends BaseEmitter {
820
1667
  * @param timestamp - Optional server-side timestamp (ISO string or ms) for message ordering
821
1668
  */
822
1669
  async emitAgentMessage(text, timestamp, subagentMeta) {
823
- const _meta = this.buildChunkMeta(
824
- BaseEmitter.toEpochMs(timestamp),
825
- subagentMeta
1670
+ await this.sendUpdate(
1671
+ createTranscriptMessageUpdate({
1672
+ role: "assistant",
1673
+ text,
1674
+ timestamp,
1675
+ ...subagentMeta ? { extra: { ...subagentMeta } } : {}
1676
+ })
826
1677
  );
827
- await this.sendUpdate({
828
- sessionUpdate: "agent_message_chunk",
829
- content: { type: "text", text },
830
- ..._meta ? { _meta } : {}
831
- });
832
1678
  }
833
1679
  async emitSlashCommandOutput(text, timestamp) {
834
1680
  const epochMs = BaseEmitter.toEpochMs(timestamp);
@@ -845,48 +1691,41 @@ var MessageEmitter = class extends BaseEmitter {
845
1691
  * Emits usage metadata.
846
1692
  */
847
1693
  async emitUsageMetadata(usageMetadata, text = "", durationMs, subagentMeta) {
848
- const usage = {
849
- inputTokens: usageMetadata.promptTokenCount ?? 0,
850
- outputTokens: usageMetadata.candidatesTokenCount ?? 0,
851
- totalTokens: usageMetadata.totalTokenCount ?? 0,
852
- thoughtTokens: usageMetadata.thoughtsTokenCount,
853
- cachedReadTokens: usageMetadata.cachedContentTokenCount
854
- };
855
1694
  const cumulative = this.ctx.cumulativeUsage;
856
1695
  if (cumulative) {
857
1696
  const addFinite = /* @__PURE__ */ __name((total, value) => typeof value === "number" && Number.isFinite(value) ? total + value : total, "addFinite");
858
1697
  cumulative.promptTokens = addFinite(
859
1698
  cumulative.promptTokens,
860
- usage.inputTokens
1699
+ usageMetadata.promptTokenCount
861
1700
  );
862
1701
  cumulative.candidateTokens = addFinite(
863
1702
  cumulative.candidateTokens,
864
- usage.outputTokens
1703
+ usageMetadata.candidatesTokenCount
865
1704
  );
866
1705
  cumulative.cachedTokens = addFinite(
867
1706
  cumulative.cachedTokens,
868
- usage.cachedReadTokens
1707
+ usageMetadata.cachedContentTokenCount
869
1708
  );
870
1709
  cumulative.apiTimeMs = addFinite(cumulative.apiTimeMs, durationMs);
871
1710
  }
872
- let meta;
1711
+ let activityMeta = {};
873
1712
  if (typeof durationMs === "number") {
874
1713
  const activity = apiActivityTracker.drain();
875
- meta = {
876
- usage,
877
- durationMs,
1714
+ activityMeta = {
878
1715
  ...activity.errors > 0 ? { apiErrors: activity.errors } : {},
879
- ...activity.retries > 0 ? { apiRetries: activity.retries } : {},
880
- ...subagentMeta
1716
+ ...activity.retries > 0 ? { apiRetries: activity.retries } : {}
881
1717
  };
882
- } else {
883
- meta = { usage, ...subagentMeta };
884
1718
  }
885
- await this.sendUpdate({
886
- sessionUpdate: "agent_message_chunk",
887
- content: { type: "text", text },
888
- _meta: meta
889
- });
1719
+ await this.sendUpdate(
1720
+ createTranscriptUsageUpdate(usageMetadata, {
1721
+ text,
1722
+ extra: {
1723
+ ...typeof durationMs === "number" ? { durationMs } : {},
1724
+ ...activityMeta,
1725
+ ...subagentMeta
1726
+ }
1727
+ })
1728
+ );
890
1729
  }
891
1730
  /**
892
1731
  * Emits a message chunk based on role and thought flag.
@@ -903,14 +1742,6 @@ var MessageEmitter = class extends BaseEmitter {
903
1742
  }
904
1743
  return isThought ? this.emitAgentThought(text, timestamp, subagentMeta) : this.emitAgentMessage(text, timestamp, subagentMeta);
905
1744
  }
906
- buildChunkMeta(epochMs, subagentMeta) {
907
- const meta = {
908
- ...subagentMeta?.parentToolCallId ? { parentToolCallId: subagentMeta.parentToolCallId } : {},
909
- ...subagentMeta?.subagentType ? { subagentType: subagentMeta.subagentType } : {},
910
- ...epochMs != null ? { timestamp: epochMs } : {}
911
- };
912
- return Object.keys(meta).length > 0 ? meta : void 0;
913
- }
914
1745
  };
915
1746
 
916
1747
  // packages/cli/src/acp-integration/session/emitters/PlanEmitter.ts
@@ -925,18 +1756,8 @@ var PlanEmitter = class extends BaseEmitter {
925
1756
  * @param todos - Array of todo items to send as plan entries
926
1757
  */
927
1758
  async emitPlan(todos) {
928
- const entries = todos.map((todo) => ({
929
- content: todo.content,
930
- priority: "medium",
931
- // Default priority since todos don't have priority
932
- status: todo.status
933
- }));
934
1759
  const cumulative = this.ctx.cumulativeUsage;
935
- await this.sendUpdate({
936
- sessionUpdate: "plan",
937
- entries,
938
- ...cumulative ? { _meta: { stats: { ...cumulative } } } : {}
939
- });
1760
+ await this.sendUpdate(createTranscriptPlanUpdate(todos, cumulative));
940
1761
  }
941
1762
  /**
942
1763
  * Extracts todos from tool result display or args.
@@ -950,35 +1771,12 @@ var PlanEmitter = class extends BaseEmitter {
950
1771
  * @returns Array of todos if found, null otherwise
951
1772
  */
952
1773
  extractTodos(resultDisplay, args) {
953
- const fromDisplay = this.extractFromResultDisplay(resultDisplay);
954
- if (fromDisplay) return fromDisplay;
955
- if (args && Array.isArray(args["todos"])) {
956
- return args["todos"];
957
- }
958
- return null;
959
- }
960
- /**
961
- * Extracts todos from a result display value.
962
- * Handles both object and JSON string formats.
963
- */
964
- extractFromResultDisplay(resultDisplay) {
965
- if (!resultDisplay) return null;
966
- if (typeof resultDisplay === "object") {
967
- const obj = resultDisplay;
968
- if (obj["type"] === "todo_list" && Array.isArray(obj["todos"])) {
969
- return obj["todos"];
970
- }
971
- }
972
- if (typeof resultDisplay === "string") {
973
- try {
974
- const parsed = JSON.parse(resultDisplay);
975
- if (parsed?.["type"] === "todo_list" && Array.isArray(parsed["todos"])) {
976
- return parsed["todos"];
977
- }
978
- } catch {
979
- }
980
- }
981
- return null;
1774
+ const todos = extractTranscriptTodos(resultDisplay, args);
1775
+ return todos?.map((todo, index) => ({
1776
+ id: todo.id ?? String(index),
1777
+ content: todo.content,
1778
+ status: todo.status
1779
+ })) ?? null;
982
1780
  }
983
1781
  };
984
1782
 
@@ -992,18 +1790,6 @@ function hasFullSessionContext(context) {
992
1790
  }
993
1791
  __name(hasFullSessionContext, "hasFullSessionContext");
994
1792
 
995
- // packages/cli/src/utils/truncatedDiffPreview.ts
996
- init_esbuild_shims();
997
- function buildTruncatedDiffPreviewText(display) {
998
- const fileName = typeof display["fileName"] === "string" ? display["fileName"] : "the edited file";
999
- const fileDiffLength = typeof display["fileDiffLength"] === "number" ? ` Original fileDiff length: ${display["fileDiffLength"]} chars.` : "";
1000
- if (display["fileDiffTruncated"] === true) {
1001
- return `Full diff omitted from saved session history for ${fileName}.${fileDiffLength}`;
1002
- }
1003
- return `Saved session preview only for ${fileName}; full original and new file contents are unavailable.`;
1004
- }
1005
- __name(buildTruncatedDiffPreviewText, "buildTruncatedDiffPreviewText");
1006
-
1007
1793
  // packages/cli/src/acp-integration/session/emitters/tool-call-emitter.ts
1008
1794
  var KIND_MAP = {
1009
1795
  ["read" /* Read */]: "read",
@@ -1056,27 +1842,22 @@ var ToolCallEmitter = class _ToolCallEmitter extends BaseEmitter {
1056
1842
  params.subagentMeta
1057
1843
  );
1058
1844
  const updatesPreparedCall = params.phase !== "preparing" && this.preparedCallIds.delete(params.callId);
1059
- const update = {
1060
- toolCallId: params.callId,
1061
- status: params.status || "pending",
1062
- title,
1063
- content: [],
1064
- locations,
1065
- kind,
1066
- rawInput: params.args ?? {},
1067
- _meta: {
1845
+ await this.sendUpdate(
1846
+ createTranscriptToolCallStartUpdate({
1068
1847
  toolName: params.toolName,
1069
- ...params.phase ? { phase: params.phase } : {},
1070
- ...params.subagentMeta,
1071
- provenance: provenance.provenance,
1072
- ...provenance.serverId ? { serverId: provenance.serverId } : {},
1073
- ...BaseEmitter.toEpochMs(params.timestamp) != null && {
1074
- timestamp: BaseEmitter.toEpochMs(params.timestamp)
1848
+ callId: params.callId,
1849
+ status: params.status || "pending",
1850
+ args: params.args,
1851
+ metadata: { title, locations, kind },
1852
+ timestamp: params.timestamp,
1853
+ asUpdate: updatesPreparedCall,
1854
+ extra: {
1855
+ ...params.phase ? { phase: params.phase } : {},
1856
+ ...params.subagentMeta,
1857
+ provenance: provenance.provenance,
1858
+ ...provenance.serverId ? { serverId: provenance.serverId } : {}
1075
1859
  }
1076
- }
1077
- };
1078
- await this.sendUpdate(
1079
- updatesPreparedCall ? { sessionUpdate: "tool_call_update", ...update } : { sessionUpdate: "tool_call", ...update }
1860
+ })
1080
1861
  );
1081
1862
  if (params.phase === "preparing") {
1082
1863
  this.preparedCallIds.add(params.callId);
@@ -1121,62 +1902,35 @@ var ToolCallEmitter = class _ToolCallEmitter extends BaseEmitter {
1121
1902
  params.args
1122
1903
  );
1123
1904
  if (todos && todos.length > 0) {
1124
- await this.planEmitter.emitPlan(todos);
1125
- } else if (params.args && Array.isArray(params.args["todos"])) {
1126
- await this.planEmitter.emitPlan([]);
1127
- }
1128
- return;
1129
- }
1130
- this.preparedCallIds.delete(params.callId);
1131
- let contentArray = [];
1132
- const diffContent = this.extractDiffContent(params.resultDisplay);
1133
- if (diffContent) {
1134
- contentArray = [diffContent];
1135
- } else if (params.error) {
1136
- contentArray = [
1137
- {
1138
- type: "content",
1139
- content: { type: "text", text: params.error.message }
1140
- }
1141
- ];
1142
- } else {
1143
- contentArray = this.transformPartsToToolCallContent(params.message);
1144
- }
1145
- if (isVisionBridgeNoticeDisplay(params.resultDisplay)) {
1146
- contentArray.unshift({
1147
- type: "content",
1148
- content: {
1149
- type: "text",
1150
- text: sanitizeTerminalText(
1151
- formatVisionBridgeNoticeDisplay(params.resultDisplay)
1152
- )
1153
- }
1154
- });
1905
+ await this.planEmitter.emitPlan(todos);
1906
+ } else if (params.args && Array.isArray(params.args["todos"])) {
1907
+ await this.planEmitter.emitPlan([]);
1908
+ }
1909
+ return;
1155
1910
  }
1911
+ this.preparedCallIds.delete(params.callId);
1156
1912
  const provenance = _ToolCallEmitter.resolveToolProvenance(
1157
1913
  params.toolName,
1158
1914
  params.subagentMeta
1159
1915
  );
1160
- const update = {
1161
- sessionUpdate: "tool_call_update",
1162
- toolCallId: params.callId,
1163
- status: params.success ? "completed" : "failed",
1164
- content: contentArray,
1165
- _meta: {
1916
+ await this.sendUpdate(
1917
+ createTranscriptToolCallResultUpdate({
1166
1918
  toolName: params.toolName,
1167
- ...params.subagentMeta,
1168
- provenance: provenance.provenance,
1169
- ...provenance.serverId ? { serverId: provenance.serverId } : {},
1170
- ...BaseEmitter.toEpochMs(params.timestamp) != null && {
1171
- timestamp: BaseEmitter.toEpochMs(params.timestamp)
1172
- },
1173
- ...params.artifacts && params.artifacts.length > 0 ? { artifacts: params.artifacts } : {}
1174
- }
1175
- };
1176
- if (params.resultDisplay !== void 0 && !this.isTruncatedSessionDiffDisplay(params.resultDisplay)) {
1177
- update["rawOutput"] = params.resultDisplay;
1178
- }
1179
- await this.sendUpdate(update);
1919
+ callId: params.callId,
1920
+ success: params.success,
1921
+ message: params.message,
1922
+ resultDisplay: params.resultDisplay,
1923
+ errorMessage: params.error?.message,
1924
+ artifacts: params.artifacts,
1925
+ contentPrefix: buildToolResultContentPrefix(params.resultDisplay),
1926
+ timestamp: params.timestamp,
1927
+ extra: {
1928
+ ...params.subagentMeta,
1929
+ provenance: provenance.provenance,
1930
+ ...provenance.serverId ? { serverId: provenance.serverId } : {}
1931
+ }
1932
+ })
1933
+ );
1180
1934
  }
1181
1935
  /**
1182
1936
  * Emits a tool call error event.
@@ -1193,20 +1947,19 @@ var ToolCallEmitter = class _ToolCallEmitter extends BaseEmitter {
1193
1947
  toolName,
1194
1948
  subagentMeta
1195
1949
  );
1196
- await this.sendUpdate({
1197
- sessionUpdate: "tool_call_update",
1198
- toolCallId: callId,
1199
- status: "failed",
1200
- content: [
1201
- { type: "content", content: { type: "text", text: error.message } }
1202
- ],
1203
- _meta: {
1950
+ await this.sendUpdate(
1951
+ createTranscriptToolCallResultUpdate({
1204
1952
  toolName,
1205
- ...subagentMeta,
1206
- provenance: provenance.provenance,
1207
- ...provenance.serverId ? { serverId: provenance.serverId } : {}
1208
- }
1209
- });
1953
+ callId,
1954
+ success: false,
1955
+ errorMessage: error.message,
1956
+ extra: {
1957
+ ...subagentMeta,
1958
+ provenance: provenance.provenance,
1959
+ ...provenance.serverId ? { serverId: provenance.serverId } : {}
1960
+ }
1961
+ })
1962
+ );
1210
1963
  }
1211
1964
  /**
1212
1965
  * Resolve a tool's provenance for UI dispatch on tool_call events.
@@ -1315,167 +2068,88 @@ var ToolCallEmitter = class _ToolCallEmitter extends BaseEmitter {
1315
2068
  }
1316
2069
  return KIND_MAP[kind] ?? "other";
1317
2070
  }
1318
- // ==================== Private Helpers ====================
1319
- /**
1320
- * Extracts diff content from resultDisplay if it's a diff type (edit tool result).
1321
- * Returns null if not a diff.
1322
- */
1323
- extractDiffContent(resultDisplay) {
1324
- if (!resultDisplay || typeof resultDisplay !== "object") return null;
1325
- const obj = resultDisplay;
1326
- if ("fileName" in obj && "newContent" in obj) {
1327
- if (this.isTruncatedSessionDiffDisplay(resultDisplay)) {
1328
- return {
1329
- type: "content",
1330
- content: {
1331
- type: "text",
1332
- text: buildTruncatedDiffPreviewText(obj)
1333
- }
1334
- };
1335
- }
1336
- return {
1337
- type: "diff",
1338
- path: obj["fileName"],
1339
- oldText: obj["originalContent"] ?? "",
1340
- newText: obj["newContent"]
1341
- };
1342
- }
1343
- return null;
1344
- }
1345
- isTruncatedSessionDiffDisplay(resultDisplay) {
1346
- if (!resultDisplay || typeof resultDisplay !== "object") return false;
1347
- const obj = resultDisplay;
1348
- return obj["truncatedForSession"] === true && "fileName" in obj && "newContent" in obj;
1349
- }
1350
- /**
1351
- * Transforms Part[] to ToolCallContent[].
1352
- * Extracts text from functionResponse parts and text parts.
1353
- */
1354
- transformPartsToToolCallContent(parts) {
1355
- const result = [];
1356
- for (const part of parts) {
1357
- if ("text" in part && part.text) {
1358
- result.push({
1359
- type: "content",
1360
- content: { type: "text", text: part.text }
1361
- });
1362
- }
1363
- if ("functionResponse" in part && part.functionResponse) {
1364
- try {
1365
- const resp = part.functionResponse.response;
1366
- const outputField = resp["output"];
1367
- const errorField = resp["error"];
1368
- const responseText = typeof outputField === "string" ? outputField : typeof errorField === "string" ? errorField : JSON.stringify(resp);
1369
- result.push({
1370
- type: "content",
1371
- content: { type: "text", text: responseText }
1372
- });
1373
- } catch {
1374
- }
1375
- }
1376
- }
1377
- return result;
1378
- }
1379
2071
  };
1380
-
1381
- // packages/cli/src/acp-integration/session/history-replayer.ts
1382
- init_esbuild_shims();
1383
-
1384
- // packages/cli/src/utils/chat-record-tool-call-id.ts
1385
- init_esbuild_shims();
1386
- function getToolResultCallId(record) {
1387
- return getExplicitToolResultCallId(record) ?? record.uuid;
1388
- }
1389
- __name(getToolResultCallId, "getToolResultCallId");
1390
- function getExplicitToolResultCallId(record) {
1391
- const resultCallId = record.toolCallResult?.callId;
1392
- if (typeof resultCallId === "string" && resultCallId.length > 0) {
1393
- return resultCallId;
1394
- }
1395
- return extractFunctionResponseId(record);
1396
- }
1397
- __name(getExplicitToolResultCallId, "getExplicitToolResultCallId");
1398
- function extractFunctionResponseId(record) {
1399
- if (!record.message?.parts) {
1400
- return void 0;
1401
- }
1402
- for (const part of record.message.parts) {
1403
- const id = "functionResponse" in part ? part.functionResponse?.id : void 0;
1404
- if (typeof id === "string" && id.length > 0) {
1405
- return id;
2072
+ function buildToolResultContentPrefix(resultDisplay) {
2073
+ if (!isVisionBridgeNoticeDisplay(resultDisplay)) return [];
2074
+ return [
2075
+ {
2076
+ type: "content",
2077
+ content: {
2078
+ type: "text",
2079
+ text: sanitizeTerminalText(
2080
+ formatVisionBridgeNoticeDisplay(resultDisplay)
2081
+ )
2082
+ }
1406
2083
  }
1407
- }
1408
- return void 0;
2084
+ ];
1409
2085
  }
1410
- __name(extractFunctionResponseId, "extractFunctionResponseId");
2086
+ __name(buildToolResultContentPrefix, "buildToolResultContentPrefix");
1411
2087
 
1412
2088
  // packages/cli/src/acp-integration/session/history-replayer.ts
2089
+ init_esbuild_shims();
1413
2090
  var GOAL_NOT_RESTORED_REASON = {
1414
2091
  "untrusted-folder": "Goal not restored: this folder is not trusted, so its Stop hook cannot run.",
1415
2092
  "hooks-disabled": "Goal not restored: hooks are disabled for this session.",
1416
2093
  "no-hook-system": "Goal not restored: the hook system is unavailable."
1417
2094
  };
1418
- var MISSING_TOOL_RESULT_MESSAGE = "Tool result missing from saved history; the previous run likely ended before this tool completed.";
1419
2095
  var HistoryReplayer = class {
1420
- static {
1421
- __name(this, "HistoryReplayer");
1422
- }
1423
- ctx;
1424
- messageEmitter;
1425
- toolCallEmitter;
1426
- options;
1427
- pendingReplayToolCalls = /* @__PURE__ */ new Map();
1428
2096
  constructor(ctx, options = {}) {
1429
2097
  this.ctx = ctx;
1430
2098
  this.options = options;
1431
2099
  this.messageEmitter = new MessageEmitter(ctx);
1432
2100
  this.toolCallEmitter = new ToolCallEmitter(ctx);
2101
+ this.machine = this.createMachine();
1433
2102
  }
1434
- /**
1435
- * Replays all chat records from a loaded session.
1436
- *
1437
- * @param records - Array of chat records to replay
1438
- * @param gaps - Optional detected history gaps; a visible notice is emitted
1439
- * immediately before each gap's child record so the user sees that an
1440
- * earlier segment was lost rather than assuming the halves are contiguous.
1441
- */
2103
+ static {
2104
+ __name(this, "HistoryReplayer");
2105
+ }
2106
+ messageEmitter;
2107
+ toolCallEmitter;
2108
+ options;
2109
+ machine;
1442
2110
  async replay(records, gaps) {
1443
2111
  try {
1444
2112
  await this.replayPage(records, { finalizeDangling: true, gaps });
1445
2113
  await this.supersedeUnrestorableGoal(records);
1446
2114
  } finally {
1447
- this.pendingReplayToolCalls.clear();
1448
2115
  this.setActiveRecordId(null);
1449
2116
  }
1450
2117
  }
1451
2118
  async replayPage(records, options = {}) {
1452
- this.pendingReplayToolCalls.clear();
1453
- for (const pending of options.pendingToolCalls ?? []) {
1454
- this.pendingReplayToolCalls.set(pending.callId, pending);
1455
- }
1456
- const gapByChildUuid = indexGapsByChild(options.gaps);
2119
+ this.machine = this.createMachine(options);
1457
2120
  let replayError;
1458
2121
  try {
1459
2122
  for (const record of records) {
1460
- const gap = gapByChildUuid.get(record.uuid);
1461
- if (gap) {
1462
- await this.emitHistoryGapNotice(gap, record.timestamp);
2123
+ for (const emission of this.machine.project(record)) {
2124
+ this.setActiveRecordId(
2125
+ emission.sourceRecordId,
2126
+ emission.sourceTimestamp
2127
+ );
2128
+ await this.sendUpdate(emission.update);
1463
2129
  }
1464
- await this.replayRecord(record);
1465
2130
  }
1466
2131
  } catch (error) {
1467
2132
  replayError = error;
1468
2133
  }
1469
2134
  let danglingError;
1470
2135
  if (options.finalizeDangling === true) {
1471
- try {
1472
- await this.failDanglingToolCalls();
1473
- } catch (error) {
1474
- danglingError = error;
2136
+ for (const emission of this.machine.finalize()) {
2137
+ this.setActiveRecordId(
2138
+ emission.sourceRecordId,
2139
+ emission.sourceTimestamp
2140
+ );
2141
+ try {
2142
+ await this.sendUpdate(emission.update);
2143
+ } catch (error) {
2144
+ danglingError ??= error;
2145
+ }
1475
2146
  }
1476
2147
  }
2148
+ const replay = this.machine.snapshot();
2149
+ this.copyCumulativeUsage(replay);
1477
2150
  const state = {
1478
- pendingToolCalls: options.finalizeDangling === true ? [] : Array.from(this.pendingReplayToolCalls.values())
2151
+ pendingToolCalls: options.finalizeDangling === true ? [] : replay.pendingToolCalls.map(toLegacyPendingToolCall),
2152
+ replay
1479
2153
  };
1480
2154
  this.setActiveRecordId(null);
1481
2155
  if (replayError && danglingError) {
@@ -1484,271 +2158,62 @@ var HistoryReplayer = class {
1484
2158
  "Replay and dangling-cleanup both failed"
1485
2159
  );
1486
2160
  }
1487
- if (replayError) {
1488
- throw replayError;
1489
- }
1490
- if (danglingError) {
1491
- throw danglingError;
1492
- }
2161
+ if (replayError) throw replayError;
2162
+ if (danglingError) throw danglingError;
1493
2163
  return state;
1494
2164
  }
1495
2165
  getPendingToolCalls() {
1496
- return Array.from(this.pendingReplayToolCalls.values());
1497
- }
1498
- /**
1499
- * Replays a single chat record.
1500
- */
1501
- async replayRecord(record) {
1502
- this.setActiveRecordId(record.uuid, record.timestamp);
1503
- try {
1504
- switch (record.type) {
1505
- case "user":
1506
- if (record.subtype === "notification" || record.subtype === "cron") {
1507
- const displayText = record.systemPayload?.displayText;
1508
- if (displayText) {
1509
- await this.messageEmitter.emitUserMessage(
1510
- displayText,
1511
- record.timestamp,
1512
- record.subtype === "cron" ? { source: "cron" } : void 0
1513
- );
1514
- }
1515
- break;
1516
- }
1517
- if (record.subtype === "mid_turn_user_message") {
1518
- const displayText = record.systemPayload?.displayText;
1519
- if (displayText) {
1520
- await this.messageEmitter.emitUserMessage(
1521
- displayText,
1522
- record.timestamp
1523
- );
1524
- } else if (record.message) {
1525
- await this.replayContent(
1526
- record.message,
1527
- "user",
1528
- record.timestamp,
1529
- record.uuid
1530
- );
1531
- }
1532
- break;
1533
- }
1534
- if (record.message) {
1535
- await this.replayContent(
1536
- record.message,
1537
- "user",
1538
- record.timestamp,
1539
- record.uuid
1540
- );
1541
- }
1542
- break;
1543
- case "assistant":
1544
- if (record.message) {
1545
- await this.replayContent(
1546
- record.message,
1547
- "assistant",
1548
- record.timestamp,
1549
- record.uuid
1550
- );
1551
- }
1552
- if (record.usageMetadata) {
1553
- await this.replayUsageMetadata(record.usageMetadata);
1554
- }
1555
- break;
1556
- case "tool_result":
1557
- await this.replayToolResult(record);
1558
- break;
1559
- case "system":
1560
- if (record.subtype === "slash_command") {
1561
- await this.replaySlashCommandResult(record);
1562
- }
1563
- break;
1564
- default:
1565
- break;
1566
- }
1567
- } finally {
1568
- this.setActiveRecordId(null);
1569
- }
2166
+ return this.machine.snapshot().pendingToolCalls.map(toLegacyPendingToolCall);
1570
2167
  }
1571
- /**
1572
- * Emits a visible notice marking a break in the persisted history chain: an
1573
- * earlier segment was physically lost (storage interruption) and could not be
1574
- * recovered, so the surviving turns below must not be read as contiguous with
1575
- * whatever came before the gap. Uses the agent message channel — the same one
1576
- * used for other system notices (see MessageEmitter.emitStopHookLoop) — so no
1577
- * new session-update kind is needed.
1578
- */
1579
- async emitHistoryGapNotice(gap, timestamp) {
1580
- await this.messageEmitter.emitAgentMessage(
1581
- formatHistoryGapNotice(gap),
1582
- timestamp
1583
- );
2168
+ getReplayState() {
2169
+ return this.machine.snapshot();
1584
2170
  }
1585
- /**
1586
- * Replays content from a message (user or assistant).
1587
- * Handles text parts, thought parts, and function calls.
1588
- *
1589
- * @param content - The content to replay
1590
- * @param role - The role (user or assistant)
1591
- * @param timestamp - Optional server-side timestamp from the JSONL record
1592
- */
1593
- async replayContent(content, role, timestamp, recordId) {
1594
- for (const part of content.parts ?? []) {
1595
- if ("text" in part && part.text) {
1596
- const isThought = part.thought ?? false;
1597
- await this.messageEmitter.emitMessage(
1598
- part.text,
1599
- role,
1600
- isThought,
1601
- timestamp
1602
- );
2171
+ createMachine(options = {}) {
2172
+ const cumulative = this.ctx.cumulativeUsage;
2173
+ const initialState = {
2174
+ v: 1,
2175
+ pendingToolCalls: (options.pendingToolCalls ?? []).map(
2176
+ toPendingTranscriptToolCall
2177
+ ),
2178
+ cumulativeUsage: cumulative ? { ...cumulative } : {
2179
+ promptTokens: 0,
2180
+ cachedTokens: 0,
2181
+ candidateTokens: 0,
2182
+ apiTimeMs: 0
1603
2183
  }
1604
- if ("functionCall" in part && part.functionCall) {
1605
- const functionName = part.functionCall.name ?? "";
1606
- const sourceCallId = part.functionCall.id;
1607
- const callId = sourceCallId ?? `${functionName}-${Date.now()}`;
1608
- const emitted = await this.toolCallEmitter.emitStart({
1609
- toolName: functionName,
1610
- callId,
1611
- args: part.functionCall.args,
1612
- status: "in_progress",
1613
- timestamp
1614
- });
1615
- if (emitted && role === "assistant" && recordId && sourceCallId) {
1616
- this.pendingReplayToolCalls.set(callId, {
1617
- callId,
1618
- toolName: functionName,
1619
- timestamp,
1620
- recordId
1621
- });
2184
+ };
2185
+ return createTranscriptReplayMachine({
2186
+ initialState,
2187
+ gaps: options.gaps,
2188
+ presentation: this.presentationAdapter(),
2189
+ onDiagnostic: /* @__PURE__ */ __name((diagnostic) => {
2190
+ if (diagnostic.code === "malformed_part" && diagnostic.path === "systemPayload.outputHistoryItems.goalStatus.condition") {
2191
+ writeStderrLineSafe(`qwen: ${diagnostic.message}`);
1622
2192
  }
1623
- }
1624
- }
1625
- }
1626
- /**
1627
- * Replays usage metadata.
1628
- * @param usageMetadata - The usage metadata to replay
1629
- */
1630
- async replayUsageMetadata(usageMetadata) {
1631
- await this.messageEmitter.emitUsageMetadata(usageMetadata);
1632
- }
1633
- /**
1634
- * Replays a tool result record.
1635
- */
1636
- async replayToolResult(record) {
1637
- if (!record.message?.parts) {
1638
- return;
1639
- }
1640
- const result = record.toolCallResult;
1641
- const callId = getToolResultCallId(record);
1642
- this.pendingReplayToolCalls.delete(callId);
1643
- const toolName = this.extractToolNameFromRecord(record);
1644
- await this.toolCallEmitter.emitResult({
1645
- toolName,
1646
- callId,
1647
- success: result?.status === void 0 ? !result?.error : result.status === "success" && !result.error,
1648
- message: record.message.parts,
1649
- resultDisplay: result?.resultDisplay,
1650
- artifacts: result?.artifacts,
1651
- // For TodoWriteTool fallback, try to extract args from the record
1652
- // Note: args aren't stored in tool_result records by default
1653
- args: void 0,
1654
- timestamp: record.timestamp
2193
+ }, "onDiagnostic")
1655
2194
  });
1656
- const { resultDisplay } = result ?? {};
1657
- if (!!resultDisplay && typeof resultDisplay === "object" && "type" in resultDisplay && resultDisplay.type === "task_execution") {
1658
- await this.emitTaskUsageFromResultDisplay(
1659
- resultDisplay
1660
- );
1661
- }
1662
2195
  }
1663
- async failDanglingToolCalls() {
1664
- let firstError;
1665
- for (const pending of this.pendingReplayToolCalls.values()) {
1666
- this.setActiveRecordId(pending.recordId, pending.timestamp);
1667
- try {
1668
- await this.toolCallEmitter.emitResult({
1669
- toolName: pending.toolName,
1670
- callId: pending.callId,
1671
- success: false,
1672
- message: [],
1673
- error: new Error(MISSING_TOOL_RESULT_MESSAGE),
1674
- timestamp: pending.timestamp
1675
- });
1676
- } catch (error) {
1677
- firstError ??= error;
1678
- } finally {
1679
- this.setActiveRecordId(null);
1680
- }
1681
- }
1682
- if (firstError) {
1683
- throw firstError;
1684
- }
2196
+ presentationAdapter() {
2197
+ return {
2198
+ resolveToolMetadata: /* @__PURE__ */ __name((toolName, args) => this.toolCallEmitter.resolveToolMetadata(toolName, { ...args }), "resolveToolMetadata"),
2199
+ formatHistoryGap: /* @__PURE__ */ __name((gap) => formatHistoryGapNotice(gap), "formatHistoryGap"),
2200
+ buildToolResultContentPrefix
2201
+ };
1685
2202
  }
1686
- /**
1687
- * Emits token usage from a AgentResultDisplay execution summary, if present.
1688
- */
1689
- async emitTaskUsageFromResultDisplay(resultDisplay) {
1690
- const summary = resultDisplay.executionSummary;
1691
- if (!summary) {
2203
+ async sendUpdate(update) {
2204
+ if (this.ctx.messageRewriter) {
2205
+ await this.ctx.messageRewriter.interceptUpdate(update);
1692
2206
  return;
1693
2207
  }
1694
- const usageMetadata = {};
1695
- if (Number.isFinite(summary.inputTokens)) {
1696
- usageMetadata.promptTokenCount = summary.inputTokens;
1697
- }
1698
- if (Number.isFinite(summary.outputTokens)) {
1699
- usageMetadata.candidatesTokenCount = summary.outputTokens;
1700
- }
1701
- if (Number.isFinite(summary.thoughtTokens)) {
1702
- usageMetadata.thoughtsTokenCount = summary.thoughtTokens;
1703
- }
1704
- if (Number.isFinite(summary.cachedTokens)) {
1705
- usageMetadata.cachedContentTokenCount = summary.cachedTokens;
1706
- }
1707
- if (Number.isFinite(summary.totalTokens)) {
1708
- usageMetadata.totalTokenCount = summary.totalTokens;
1709
- }
1710
- if (Object.keys(usageMetadata).length > 0) {
1711
- await this.messageEmitter.emitUsageMetadata(usageMetadata);
1712
- }
2208
+ await this.ctx.sendUpdate(update);
1713
2209
  }
1714
- /**
1715
- * Replays a slash_command system record by re-emitting its output as an
1716
- * agent message chunk. This allows Zed to reconstruct the correct turn
1717
- * structure (user → agent) on session resume without polluting model context.
1718
- *
1719
- * Goal cards are re-emitted as `_meta.goalStatus` rather than text: they carry
1720
- * no `text` field, so the plain-text path below would silently drop them and
1721
- * the client would lose the goal card (and its status pill) on every reload.
1722
- * Per-iteration `checking` cards are skipped — a TUI transcript persists one
1723
- * per stop-hook turn, and clients suppress them as noise. Skipping costs no
1724
- * fidelity: goal restore reads the records directly, not this replay.
1725
- */
1726
- async replaySlashCommandResult(record) {
1727
- const payload = record.systemPayload;
1728
- if (payload?.phase !== "result") return;
1729
- const items = payload.outputHistoryItems;
1730
- if (!Array.isArray(items) || items.length === 0) return;
1731
- for (const item of items) {
1732
- const goalStatus = parseGoalStatusItem(item);
1733
- if (goalStatus) {
1734
- if (goalConditionBlockedBy(goalStatus.condition)) {
1735
- writeStderrLineSafe(
1736
- "qwen: skipping replay of a goal card whose condition is empty."
1737
- );
1738
- } else if (goalStatus.kind !== "checking") {
1739
- const { type: _type, ...status } = goalStatus;
1740
- await this.messageEmitter.emitGoalStatus(status);
1741
- }
1742
- continue;
1743
- }
1744
- const text = isTranscriptItemRecord(item) && typeof item["text"] === "string" ? item["text"] : "";
1745
- if (text) {
1746
- await this.messageEmitter.emitSlashCommandOutput(
1747
- text.replace(/\n/g, " \n"),
1748
- record.timestamp
1749
- );
1750
- }
1751
- }
2210
+ copyCumulativeUsage(state) {
2211
+ const cumulative = this.ctx.cumulativeUsage;
2212
+ if (!cumulative) return;
2213
+ cumulative.promptTokens = state.cumulativeUsage.promptTokens;
2214
+ cumulative.cachedTokens = state.cumulativeUsage.cachedTokens;
2215
+ cumulative.candidateTokens = state.cumulativeUsage.candidateTokens;
2216
+ cumulative.apiTimeMs = state.cumulativeUsage.apiTimeMs;
1752
2217
  }
1753
2218
  /**
1754
2219
  * Emits a trailing `cleared` card when the transcript ends on an active goal
@@ -1786,27 +2251,62 @@ var HistoryReplayer = class {
1786
2251
  lastReason: GOAL_NOT_RESTORED_REASON[blockedBy]
1787
2252
  });
1788
2253
  }
1789
- /**
1790
- * Extracts tool name from a chat record's function response.
1791
- */
1792
- extractToolNameFromRecord(record) {
1793
- if (record.message?.parts) {
1794
- for (const part of record.message.parts) {
1795
- if ("functionResponse" in part && part.functionResponse?.name) {
1796
- return part.functionResponse.name;
1797
- }
1798
- }
1799
- }
1800
- return "";
1801
- }
1802
2254
  setActiveRecordId(recordId, timestamp) {
1803
2255
  this.ctx.setActiveRecordId?.(recordId, timestamp);
1804
2256
  }
1805
2257
  };
2258
+ function toPendingTranscriptToolCall(pending) {
2259
+ return {
2260
+ callId: pending.callId,
2261
+ toolName: pending.toolName,
2262
+ sourceRecordId: pending.recordId,
2263
+ ...pending.timestamp ? { sourceTimestamp: pending.timestamp } : {}
2264
+ };
2265
+ }
2266
+ __name(toPendingTranscriptToolCall, "toPendingTranscriptToolCall");
2267
+ function toLegacyPendingToolCall(pending) {
2268
+ return {
2269
+ callId: pending.callId,
2270
+ toolName: pending.toolName,
2271
+ recordId: pending.sourceRecordId,
2272
+ ...pending.sourceTimestamp ? { timestamp: pending.sourceTimestamp } : {}
2273
+ };
2274
+ }
2275
+ __name(toLegacyPendingToolCall, "toLegacyPendingToolCall");
1806
2276
 
1807
2277
  // packages/cli/src/ui/utils/export/collect.ts
1808
2278
  init_esbuild_shims();
1809
2279
  import { randomUUID } from "node:crypto";
2280
+
2281
+ // packages/cli/src/utils/chat-record-tool-call-id.ts
2282
+ init_esbuild_shims();
2283
+ function getToolResultCallId(record) {
2284
+ return getExplicitToolResultCallId(record) ?? record.uuid;
2285
+ }
2286
+ __name(getToolResultCallId, "getToolResultCallId");
2287
+ function getExplicitToolResultCallId(record) {
2288
+ const resultCallId = record.toolCallResult?.callId;
2289
+ if (typeof resultCallId === "string" && resultCallId.length > 0) {
2290
+ return resultCallId;
2291
+ }
2292
+ return extractFunctionResponseId(record);
2293
+ }
2294
+ __name(getExplicitToolResultCallId, "getExplicitToolResultCallId");
2295
+ function extractFunctionResponseId(record) {
2296
+ if (!record.message?.parts) {
2297
+ return void 0;
2298
+ }
2299
+ for (const part of record.message.parts) {
2300
+ const id = "functionResponse" in part ? part.functionResponse?.id : void 0;
2301
+ if (typeof id === "string" && id.length > 0) {
2302
+ return id;
2303
+ }
2304
+ }
2305
+ return void 0;
2306
+ }
2307
+ __name(extractFunctionResponseId, "extractFunctionResponseId");
2308
+
2309
+ // packages/cli/src/ui/utils/export/collect.ts
1810
2310
  function extractToolNameFromRecord(record) {
1811
2311
  if (!record.message?.parts) {
1812
2312
  return void 0;
@@ -1993,7 +2493,7 @@ async function extractMetadata(conversation, config) {
1993
2493
  const gitBranch = firstRecord?.gitBranch;
1994
2494
  let gitRepo;
1995
2495
  if (cwd) {
1996
- const { getGitRepoName } = await import("./src-75ZPXO7B.js");
2496
+ const { getGitRepoName } = await import("./src-DUFUUEHE.js");
1997
2497
  gitRepo = getGitRepoName(cwd);
1998
2498
  }
1999
2499
  let model;
@@ -2220,6 +2720,20 @@ __name(collectSessionData, "collectSessionData");
2220
2720
 
2221
2721
  // packages/cli/src/ui/utils/export/normalize.ts
2222
2722
  init_esbuild_shims();
2723
+
2724
+ // packages/cli/src/utils/truncatedDiffPreview.ts
2725
+ init_esbuild_shims();
2726
+ function buildTruncatedDiffPreviewText2(display) {
2727
+ const fileName = typeof display["fileName"] === "string" ? display["fileName"] : "the edited file";
2728
+ const fileDiffLength = typeof display["fileDiffLength"] === "number" ? ` Original fileDiff length: ${display["fileDiffLength"]} chars.` : "";
2729
+ if (display["fileDiffTruncated"] === true) {
2730
+ return `Full diff omitted from saved session history for ${fileName}.${fileDiffLength}`;
2731
+ }
2732
+ return `Saved session preview only for ${fileName}; full original and new file contents are unavailable.`;
2733
+ }
2734
+ __name(buildTruncatedDiffPreviewText2, "buildTruncatedDiffPreviewText");
2735
+
2736
+ // packages/cli/src/ui/utils/export/normalize.ts
2223
2737
  function normalizeSessionData(sessionData, originalRecords, config) {
2224
2738
  const normalized = [...sessionData.messages];
2225
2739
  const toolCallIndexById = /* @__PURE__ */ new Map();
@@ -2308,7 +2822,7 @@ function buildToolCallMessageFromResult(record, config) {
2308
2822
  const rawInput = normalizeRawInput(
2309
2823
  functionCallArgs ?? toolCallResult?.args
2310
2824
  );
2311
- const resultContent = extractDiffContent(toolCallResult?.resultDisplay) ?? transformPartsToToolCallContent(record.message?.parts ?? []);
2825
+ const resultContent = extractDiffContent2(toolCallResult?.resultDisplay) ?? transformPartsToToolCallContent(record.message?.parts ?? []);
2312
2826
  const content = isVisionBridgeNoticeDisplay(toolCallResult?.resultDisplay) ? [
2313
2827
  {
2314
2828
  type: "content",
@@ -2408,7 +2922,7 @@ function mapToolKind(kind, toolName) {
2408
2922
  return "other";
2409
2923
  }
2410
2924
  __name(mapToolKind, "mapToolKind");
2411
- function extractDiffContent(resultDisplay) {
2925
+ function extractDiffContent2(resultDisplay) {
2412
2926
  if (!resultDisplay || typeof resultDisplay !== "object") {
2413
2927
  return null;
2414
2928
  }
@@ -2420,7 +2934,7 @@ function extractDiffContent(resultDisplay) {
2420
2934
  type: "content",
2421
2935
  content: {
2422
2936
  type: "text",
2423
- text: buildTruncatedDiffPreviewText(display)
2937
+ text: buildTruncatedDiffPreviewText2(display)
2424
2938
  }
2425
2939
  }
2426
2940
  ];
@@ -2436,7 +2950,7 @@ function extractDiffContent(resultDisplay) {
2436
2950
  }
2437
2951
  return null;
2438
2952
  }
2439
- __name(extractDiffContent, "extractDiffContent");
2953
+ __name(extractDiffContent2, "extractDiffContent");
2440
2954
  function normalizeRawInput(value) {
2441
2955
  if (typeof value === "string") return value;
2442
2956
  if (typeof value === "object" && value !== null) return value;