nolo-cli 0.213.0 → 0.222.0-alpha.2

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 (262) hide show
  1. package/README.md +3 -2
  2. package/{_executeModel-CUJLCFWR.js → _executeModel-4GGQQHOB.js} +111 -82
  3. package/{accountResolver-4LKIHEKL.js → accountResolver-EK2S4PWF.js} +6 -6
  4. package/{action-DF5UYSJF.js → action-CK64LS6S.js} +12 -11
  5. package/{addContentAction-WERAONNY.js → addContentAction-GDHDOF4U.js} +18 -17
  6. package/{addDialogAgentAction-7VI7YRML.js → addDialogAgentAction-CAKRU3ZT.js} +21 -20
  7. package/{agentDeleteCommand-XJORXPGU.js → agentDeleteCommand-BPV2XZL7.js} +128 -119
  8. package/{agentEmailCommands-XTYYFR6Z.js → agentEmailCommands-EJOS75YL.js} +132 -124
  9. package/{agentFavoriteCommands-EDK743YA.js → agentFavoriteCommands-2LKGKSUD.js} +7 -8
  10. package/{agentGrantCommands-RQWK2TEV.js → agentGrantCommands-QQV4N4JW.js} +5 -5
  11. package/{agentListCommands-OBLRBLHS.js → agentListCommands-HIZODBF3.js} +155 -92
  12. package/{agentMachineCommands-5FMT3OT5.js → agentMachineCommands-ZMQ2CY7Y.js} +62 -54
  13. package/{agentProviderCommands-Q5O33MED.js → agentProviderCommands-WKJOAWBP.js} +5 -5
  14. package/{agentPullCommand-6EM3URVK.js → agentPullCommand-XN6ZPBUW.js} +7 -7
  15. package/agentRecordCommands-OMXVDLDX.js +176 -0
  16. package/agentRunCommand-CB34YWMV.js +206 -0
  17. package/{agentRunControl-TAMHJQSR.js → agentRunControl-JNONH3RP.js} +30 -15
  18. package/{agentRuntimeLocal-SOO2OPJG.js → agentRuntimeLocal-QZPFWMLG.js} +52 -45
  19. package/{agentSlice-CHR6KOZN.js → agentSlice-RD2CDU7T.js} +20 -19
  20. package/{appDeleteCommands-GUP6P5YE.js → appDeleteCommands-QCCFDIEQ.js} +61 -53
  21. package/{appDeployCommands-MH2FX4O5.js → appDeployCommands-V2T7TNMQ.js} +61 -53
  22. package/{appDeployStatusCommands-SUHN3HPJ.js → appDeployStatusCommands-6PGH7ZCG.js} +61 -53
  23. package/{appGetCommands-YWDEX6Z4.js → appGetCommands-3L7WWJA6.js} +61 -53
  24. package/{appListCommands-ZQVMLPAY.js → appListCommands-ENJCK4PO.js} +61 -53
  25. package/{authCommand-PWX2ZNUP.js → authCommand-6V47SYGK.js} +29 -28
  26. package/{authCommands-HV3EAU3V.js → authCommands-GAJ3NIXO.js} +14 -13
  27. package/{builtinSkillRegistry-2QETTQPM.js → builtinSkillRegistry-2ECA42FC.js} +11 -13
  28. package/{chromeCommands-REEAH4SX.js → chromeCommands-G5UDKVSV.js} +3 -3
  29. package/{chromeOpsCommands-DIVM2K3T.js → chromeOpsCommands-YKX2QX3A.js} +20 -10
  30. package/{chunk-CRHOO2ZR.js → chunk-27PCUMJI.js} +2 -2
  31. package/chunk-2CI3ZFWD.js +97 -0
  32. package/{chunk-NSAPDIN2.js → chunk-2GJKRKI6.js} +541 -31
  33. package/{chunk-SM3NSZJV.js → chunk-2UCBGYO4.js} +20 -1
  34. package/{chunk-PYRUW7XN.js → chunk-2VUZSVAS.js} +136 -54
  35. package/{chunk-YB3YZK56.js → chunk-2WZXXAQD.js} +1 -67
  36. package/chunk-2YGBI2XB.js +30 -0
  37. package/chunk-2ZKFCIJJ.js +13 -0
  38. package/{chunk-QG4AOSON.js → chunk-34J5K2YA.js} +13 -32
  39. package/{chunk-LOEO7LRC.js → chunk-3IK6ILVW.js} +4 -1
  40. package/{chunk-CTPXME7U.js → chunk-3LMUPOHG.js} +29 -6
  41. package/chunk-44X52WOJ.js +1621 -0
  42. package/{chunk-6VLJ6YA7.js → chunk-4DESLZTK.js} +9 -9
  43. package/{chunk-MYOH447Z.js → chunk-4JVNURX4.js} +1 -1
  44. package/chunk-5CHGAKRT.js +364 -0
  45. package/{chunk-YDH3FDFQ.js → chunk-5FUN7EG4.js} +1 -1
  46. package/{chunk-INUFILG6.js → chunk-5RKUPJYL.js} +1 -1
  47. package/{chunk-ZC3CMUKU.js → chunk-6OVNSQHN.js} +84 -2
  48. package/{chunk-MOIJOHA5.js → chunk-6WU5572L.js} +36 -25
  49. package/{chunk-IXNGOHV5.js → chunk-7EEZJ6BS.js} +11 -152
  50. package/{chunk-Y6ORVLSS.js → chunk-7ET2U67U.js} +1 -1
  51. package/{chunk-G7MLNNEX.js → chunk-7JLY4WYF.js} +5 -5
  52. package/{chunk-P5L7CXOC.js → chunk-7Z6EW7AH.js} +3 -2
  53. package/{chunk-NJLL224W.js → chunk-AD5EWDFD.js} +2 -2
  54. package/{chunk-J2NHJ7WX.js → chunk-AIHYNKGV.js} +4 -4
  55. package/{chunk-HPFCI4SK.js → chunk-AK5O76CC.js} +3 -3
  56. package/{chunk-Y63ZSOR6.js → chunk-AL3TYDIF.js} +1 -1
  57. package/{chunk-ALQ3657A.js → chunk-AMEOV5VZ.js} +32 -12
  58. package/chunk-AN74ON4G.js +675 -0
  59. package/{chunk-HRMJUN5J.js → chunk-AQZ6BMRK.js} +1 -1
  60. package/{chunk-XHQC4PXX.js → chunk-B4GOW4MT.js} +424 -194
  61. package/{chunk-4KB6WQUL.js → chunk-BGP2EDFG.js} +1 -1
  62. package/{chunk-NBTY7YJF.js → chunk-BR3GT6MR.js} +1 -0
  63. package/{chunk-7RFNTILS.js → chunk-BUDVRYES.js} +2 -2
  64. package/{chunk-SVYO6AO7.js → chunk-BV3FLP2L.js} +41 -1
  65. package/{chunk-RZOV7OMV.js → chunk-C4VAR65S.js} +83 -141
  66. package/{chunk-COFEN36Z.js → chunk-C4WTX5TU.js} +2 -2
  67. package/{chunk-ZL5RAEEB.js → chunk-CIRB724Q.js} +1 -1
  68. package/{chunk-F6UUQOG6.js → chunk-CKT6QUE2.js} +4 -4
  69. package/{chunk-X7SDOJUM.js → chunk-CMZ3Z5PT.js} +14 -14
  70. package/{secretCommands-LXDWOLZ6.js → chunk-D726I5AZ.js} +191 -16
  71. package/{chunk-TAKB25RM.js → chunk-DNKTQ3IN.js} +4 -4
  72. package/chunk-DVQH4BTR.js +1137 -0
  73. package/{chunk-WYDI6TGM.js → chunk-DWX2HEVC.js} +91 -132
  74. package/{chunk-5MQRBSMW.js → chunk-EIAI3PPH.js} +111 -113
  75. package/chunk-EUCFKKDM.js +247 -0
  76. package/chunk-EWQ3HGNZ.js +90 -0
  77. package/{chunk-RPQXPZZF.js → chunk-F3GRJO4Z.js} +908 -13
  78. package/{chunk-YTF4WH7J.js → chunk-FIYSMXHY.js} +1 -1
  79. package/{chunk-75XIDFBW.js → chunk-FJ23FZXF.js} +72 -28
  80. package/{chunk-INN4LTAJ.js → chunk-FJK526XH.js} +2 -2
  81. package/chunk-FS2XP5D7.js +142 -0
  82. package/{chunk-FUGMREBO.js → chunk-FYF2TONJ.js} +5 -5
  83. package/{chunk-PCLE46CE.js → chunk-GBWGPTA7.js} +2 -1
  84. package/{chunk-TX5EYMGT.js → chunk-GYVCJABP.js} +30 -254
  85. package/{chunk-3UKL3HPD.js → chunk-HOCHUZQ7.js} +8 -78
  86. package/{chunk-EHSZD5OI.js → chunk-HXER7YJF.js} +4 -4
  87. package/chunk-HYIETXA6.js +99 -0
  88. package/{chunk-H2TJUNCH.js → chunk-I4EADJ4P.js} +6 -6
  89. package/{chunk-TCZHTTUU.js → chunk-I7WBYGBP.js} +8 -8
  90. package/{chunk-6DWMYIUY.js → chunk-IILMY4W4.js} +14 -9
  91. package/chunk-JA3ICVJY.js +271 -0
  92. package/{chunk-ZRSNONOB.js → chunk-JWXITTQB.js} +8 -3
  93. package/{chunk-H4UOTUOX.js → chunk-KEN3N2TN.js} +148 -18
  94. package/{chunk-LEC5ALIN.js → chunk-KEPOVMF4.js} +1 -1
  95. package/{chunk-UHJGXRJ4.js → chunk-KQSYAIZR.js} +3 -3
  96. package/{chunk-4VJAC32I.js → chunk-L5I543VB.js} +3 -2
  97. package/chunk-LKA64WH4.js +227 -0
  98. package/{chunk-QHPRUL4O.js → chunk-LVL6GFCM.js} +4 -4
  99. package/{chunk-H5HF7TJA.js → chunk-MAIITKBT.js} +2 -2
  100. package/chunk-MBG66ZBH.js +226 -0
  101. package/{chunk-YUA6OAH5.js → chunk-MDLS23JK.js} +2 -2
  102. package/{chunk-VL5KOY2C.js → chunk-MK2Q7ZJD.js} +67 -5
  103. package/{chunk-MDB67IWP.js → chunk-MS4NZNKI.js} +10 -10
  104. package/{chunk-VO4WSAVP.js → chunk-MYHNBEXD.js} +3 -3
  105. package/{chunk-ZXOUUDCG.js → chunk-MZLE5HQ3.js} +3654 -231
  106. package/{chunk-AZMYUSVF.js → chunk-N5Z2V73W.js} +1 -1
  107. package/{chunk-V5Y3R6BT.js → chunk-NIZ2BXFD.js} +213 -210
  108. package/{chunk-KFLT5KAD.js → chunk-NWP2OYOX.js} +20 -20
  109. package/{chunk-G2BQWAVT.js → chunk-O6J3OTOP.js} +4 -4
  110. package/{chunk-VNYYOX3V.js → chunk-OB6DVWPF.js} +141 -48
  111. package/{chunk-YWSEPJ7C.js → chunk-OBWT45ZU.js} +3 -3
  112. package/{chunk-ZNWI6OVT.js → chunk-ODJ7BVSI.js} +80 -11
  113. package/{chunk-XJWWBO34.js → chunk-OJKUU3LP.js} +5 -7
  114. package/{chunk-HUBHAQK2.js → chunk-ON37YXGX.js} +29 -29
  115. package/{chunk-UYD5HQ6T.js → chunk-P5ZJRTCH.js} +5429 -1752
  116. package/{chunk-6XIE5ZGI.js → chunk-PDCV7P5W.js} +1 -1
  117. package/{chunk-WRYQ35LQ.js → chunk-PJCIP64Z.js} +859 -57
  118. package/{chunk-7QTZCMKL.js → chunk-PJVKMGPZ.js} +1089 -1639
  119. package/{chunk-A7TFUNZO.js → chunk-PPJYZRSQ.js} +6 -2
  120. package/chunk-QHEN7NZ7.js +46 -0
  121. package/{chunk-OQPKUBPB.js → chunk-QNWG52I4.js} +19 -7
  122. package/{chunk-YGILMZ7N.js → chunk-QVBXJNZ2.js} +1 -1
  123. package/{chunk-7BT37FK3.js → chunk-RDH5CQ4T.js} +648 -131
  124. package/{chunk-C6KNNXWU.js → chunk-RGQ4UUWZ.js} +25 -2
  125. package/{chunk-OWYYDMGJ.js → chunk-S2NTVGA2.js} +4 -2
  126. package/{chunk-KC4XDTT3.js → chunk-SOF4OWDM.js} +6 -4
  127. package/{chunk-RLBNLZVC.js → chunk-SQYIK6HO.js} +1 -1
  128. package/{chunk-YJAFKXMU.js → chunk-SVT62ULE.js} +50 -48
  129. package/{chunk-KIM6CLW5.js → chunk-SY3C4SQ7.js} +42 -15
  130. package/{chunk-JY5NGFFH.js → chunk-SYTHYBMI.js} +5 -5
  131. package/{chunk-WMTBPBMP.js → chunk-T6DXNI6Z.js} +52 -50
  132. package/chunk-TLE77UJ5.js +230 -0
  133. package/{chunk-4VNS5WPM.js → chunk-U67V476Y.js} +1 -8
  134. package/{chunk-F7CI2ZC5.js → chunk-UAIHKQIA.js} +2 -1
  135. package/{chunk-R5O4QAWG.js → chunk-UB3D4TRQ.js} +11 -77
  136. package/{chunk-WPORQFYN.js → chunk-UVLYNWIE.js} +2 -2
  137. package/{chunk-NOKUNJON.js → chunk-UYOICCYG.js} +29 -19
  138. package/{chunk-4I7ERB7F.js → chunk-VREDDN25.js} +1 -1
  139. package/{chunk-O2TZF4AI.js → chunk-WAE3GFCJ.js} +3 -3
  140. package/{chunk-H7PPIYWP.js → chunk-WI67URFP.js} +20 -20
  141. package/{chunk-7OCO4TDT.js → chunk-WJVYAO6P.js} +1 -1
  142. package/{chunk-T43B7LB2.js → chunk-WKGQSYTB.js} +1 -1
  143. package/{chunk-BBJ22CLB.js → chunk-WUUH4LWZ.js} +60 -30
  144. package/{chunk-4T2WNOY7.js → chunk-X7UF53VA.js} +33 -22
  145. package/{chunk-TY3TIUJK.js → chunk-XI2BWJM5.js} +65 -0
  146. package/{chunk-LLRPJECG.js → chunk-XWVCYUUU.js} +16 -159
  147. package/{chunk-J5JTMQIA.js → chunk-YFLVRVYK.js} +1 -1
  148. package/{chunk-EYLGAEB4.js → chunk-YGMBIXCF.js} +132 -0
  149. package/chunk-YL3EFYL3.js +199 -0
  150. package/{chunk-MMA3LZ3W.js → chunk-YNIYE47Z.js} +1 -1
  151. package/{chunk-W4S457LU.js → chunk-YU4ZPWVF.js} +41 -5
  152. package/{chunk-7Y4YTDQF.js → chunk-YWWDC3O7.js} +281 -159
  153. package/chunk-YZMNK53S.js +68 -0
  154. package/{chunk-RSHTSUEG.js → chunk-Z2PITYZN.js} +2060 -602
  155. package/{chunk-FY7F4Q6X.js → chunk-Z4PCXPUE.js} +2 -2
  156. package/{cliAgentConfigHelpers-WJBZQTLW.js → cliAgentConfigHelpers-TKYL43MT.js} +15 -16
  157. package/{cliAuthorityBrokerClient-PM3U6Q6J.js → cliAuthorityBrokerClient-XHH7MH2P.js} +1 -1
  158. package/{cliAuthorityStoreDriver-TKLXNNTG.js → cliAuthorityStoreDriver-6FE3BJNB.js} +1 -1
  159. package/{cliEnvHelpers-BVYTMUPJ.js → cliEnvHelpers-VPSJ4XWC.js} +3 -3
  160. package/{cliExecutor-BWBF2MTI.js → cliExecutor-4MAX3PZL.js} +2 -2
  161. package/cliLocalAgentRecordReader-MHHD4T7R.js +90 -0
  162. package/{commandRegistry-W63CYRZJ.js → commandRegistry-5DA5UP7S.js} +105 -97
  163. package/{contentThunks-U7PL5MQD.js → contentThunks-5GUQ7FWJ.js} +47 -43
  164. package/{cooldownCommands-TIGUHXTD.js → cooldownCommands-X7P5M2V5.js} +5 -4
  165. package/{createAgentAutomationAction-OLBQDD6R.js → createAgentAutomationAction-UCLTHQRI.js} +51 -49
  166. package/{createDialogAction-SVH6B3SB.js → createDialogAction-UPN774AF.js} +46 -48
  167. package/{createPageAction-F4DIWZ2Z.js → createPageAction-JRQ2TA4O.js} +50 -48
  168. package/{cursorProvider-YGGNMVWX.js → cursorProvider-2RACMEMF.js} +1 -1
  169. package/{db-HUCI5R4G.js → db-CS4ZJQKV.js} +1 -1
  170. package/{dbSlice-BVH2YZPQ.js → dbSlice-WNON7TOL.js} +17 -16
  171. package/{deleteFile-5YOEKV4U.js → deleteFile-Q3YDB4ML.js} +9 -9
  172. package/{desktopFolderProjects-SFY5EZS3.js → desktopFolderProjects-4POAMVJN.js} +2 -2
  173. package/{dialogCommands-KHIEPY3M.js → dialogCommands-VRI7VCXH.js} +64 -57
  174. package/dialogNotifyCommand-6TMCX4D2.js +36 -0
  175. package/{dialogSlice-ZCTDV2PZ.js → dialogSlice-LFNVUSAN.js} +42 -40
  176. package/{dialogUsageCommand-7KCPYGHG.js → dialogUsageCommand-HTVPR2CX.js} +11 -10
  177. package/{docCreateCommands-DPMZI7G5.js → docCreateCommands-AMPXMOX3.js} +61 -55
  178. package/{docDeleteCommands-IRQQLUBT.js → docDeleteCommands-I5WFAEHP.js} +63 -57
  179. package/{docReadCommands-LK37XH6L.js → docReadCommands-X53ELNIE.js} +61 -55
  180. package/{docStore-V2KECILA.js → docStore-2VAWVLWH.js} +21 -20
  181. package/{docUpdateCommands-O6T3HJHH.js → docUpdateCommands-6QPNDC7M.js} +64 -58
  182. package/{fetchMessages-NR4KNQLO.js → fetchMessages-TQEUZD7H.js} +8 -7
  183. package/{getPricing-2MNMXEVG.js → getPricing-MB2GBXOK.js} +6 -6
  184. package/{handleSendMessageAction-2PE25WM3.js → handleSendMessageAction-AAJOHXOB.js} +194 -302
  185. package/{hostCredentialCreate-S233UMAP.js → hostCredentialCreate-GLMJ22M6.js} +123 -114
  186. package/index.js +29 -29
  187. package/{keys-BEGDOTRL.js → keys-RWF7UCB4.js} +5 -4
  188. package/legacyMigration-TF4SYJCZ.js +19 -0
  189. package/{lib-5KKIBFIT.js → lib-OT5OTXRU.js} +7087 -6664
  190. package/{localDialogRead-7NNDVVF7.js → localDialogRead-SVTPA5GY.js} +3 -3
  191. package/{localFirstLog-DHNOY2NA.js → localFirstLog-OIETGK66.js} +1 -1
  192. package/localRecall-2J6QPOK2.js +15 -0
  193. package/{localRuntimeAdapter-KY6WXNBR.js → localRuntimeAdapter-BMP57P42.js} +119 -110
  194. package/{localRuntimeAuthority-OYH4AE4G.js → localRuntimeAuthority-IBJAT62G.js} +1 -1
  195. package/{localRuntimeDb-VBIMCWUC.js → localRuntimeDb-N7KHDXS2.js} +2 -2
  196. package/{machineCommands-Q6HA3IXF.js → machineCommands-3MLIAK5Q.js} +128 -119
  197. package/{machineInfo-UKPTZO5Y.js → machineInfo-LWHTEBHJ.js} +1 -1
  198. package/machineWsRunDispatch-FKIGROQF.js +191 -0
  199. package/{memberThunks-7EDJADWU.js → memberThunks-ZGLZ36PK.js} +29 -28
  200. package/{memoryCommands-ASCE5STX.js → memoryCommands-5WC3T66U.js} +4 -4
  201. package/models-ULVWLSQ6.js +9 -0
  202. package/{oauthTokenStore-OEERZFUC.js → oauthTokenStore-RUYNYALS.js} +1 -1
  203. package/{offlineMarxistsAgentCommand-2QTHJCHV.js → offlineMarxistsAgentCommand-4IC3Y4C6.js} +4 -4
  204. package/overlay-THLKYIWY.js +11 -0
  205. package/package.json +2 -2
  206. package/{pdf-U6KSUEZZ.js → pdf-KE3QI2V7.js} +1 -1
  207. package/{processSpawn-ZU5QFM43.js → processSpawn-6GEO77KV.js} +1 -1
  208. package/{profileConfig-KN3N2BLF.js → profileConfig-KOWK4HOG.js} +1 -1
  209. package/{projectArchive-DRTDIMEV.js → projectArchive-HK63GMF4.js} +52 -50
  210. package/{providerPresetApply-YXGV6NXB.js → providerPresetApply-OIFQ73LH.js} +19 -12
  211. package/{providerRegistry-S6UL6UNA.js → providerRegistry-KZ3SDZ3D.js} +10 -10
  212. package/{read-4V2RMG7N.js → read-MRQHJMJ2.js} +10 -10
  213. package/{readDocTool-BH6ATGQO.js → readDocTool-4BGTXTXA.js} +2 -2
  214. package/{readlineWorkspace-2W4WRCOU.js → readlineWorkspace-AKAHSCNY.js} +7982 -6274
  215. package/{removeDialogAgentAction-LYAZGNKW.js → removeDialogAgentAction-B6H7DXFM.js} +23 -22
  216. package/{runAgentClientLoop-J2VQBS2Z.js → runAgentClientLoop-UVAWGEON.js} +81 -79
  217. package/{runtimeDoctorCommands-QAI3MBKQ.js → runtimeDoctorCommands-FW6XKDUG.js} +12 -12
  218. package/{runtimeModeArgs-2Y7BALTO.js → runtimeModeArgs-X7DL7PUN.js} +1 -1
  219. package/secretCommands-LJXOOYA7.js +24 -0
  220. package/{setDialogExtraReferencesAction-OCRPGPYH.js → setDialogExtraReferencesAction-EVCY3TRW.js} +22 -21
  221. package/{setPrimaryDialogAgentAction-HFJDQIBU.js → setPrimaryDialogAgentAction-KPFVPHCJ.js} +23 -22
  222. package/{settingThunks-RAMHMTGM.js → settingThunks-ENOAK2WV.js} +97 -88
  223. package/{skillDiscovery-XKHROSH2.js → skillDiscovery-B5V23AXP.js} +4 -4
  224. package/{skillSummaryMarker-42HKSXYY.js → skillSummaryMarker-62UW7HI7.js} +1 -1
  225. package/{slateToRenderMarkdown-Y5IYN73U.js → slateToRenderMarkdown-R3X74MCX.js} +1 -1
  226. package/{slateUtils-NGV2NMKM.js → slateUtils-ESQAJ6RN.js} +1 -1
  227. package/{spaceCommands-KVJZVKVO.js → spaceCommands-DTTNAS2L.js} +61 -53
  228. package/store-JRVN62NM.js +46 -0
  229. package/{streamAgentChatTurn-GHBMJJ6S.js → streamAgentChatTurn-R5UY25VB.js} +875 -618
  230. package/{switchDialogAgentAction-EBRMW3RA.js → switchDialogAgentAction-SZ44XDRY.js} +21 -20
  231. package/{tableCommands-MP6VFSVT.js → tableCommands-HITDSLHS.js} +10 -10
  232. package/tombstones-FQQMEDOW.js +32 -0
  233. package/{toolApiClient-HGNO53TC.js → toolApiClient-OGQEBQVX.js} +4 -4
  234. package/{tools-EWKCPKMS.js → tools-HWFG6GMJ.js} +75 -74
  235. package/tuiSummaryLlmCaller-HQQZAMYF.js +44 -0
  236. package/{updateCommands-ZQYU6SCI.js → updateCommands-RJVCRSBP.js} +10 -8
  237. package/{updateDialogTitleAction-5GGMBTDF.js → updateDialogTitleAction-KNPOAMVS.js} +48 -46
  238. package/{usageCommand-F4IPVMIZ.js → usageCommand-FWZCB7AM.js} +11 -10
  239. package/{usageRebuildCommand-HAW2AD5N.js → usageRebuildCommand-SP2BLNJU.js} +12 -11
  240. package/userDataMerge-HT2ZVHBJ.js +13 -0
  241. package/{windowsSelfUpdate-257DV2T6.js → windowsSelfUpdate-KERHIAB4.js} +3 -3
  242. package/{workloadLifecycle-4C42SVBD.js → workloadLifecycle-DYNEYHV5.js} +6 -6
  243. package/agentRecordCommands-ZQ7SVYGG.js +0 -167
  244. package/agentRunCommand-WS7IGO2W.js +0 -196
  245. package/chunk-3CGG2PAL.js +0 -594
  246. package/chunk-5XBUWM6I.js +0 -89
  247. package/chunk-CJEIOP3E.js +0 -0
  248. package/chunk-EHGEOAHI.js +0 -636
  249. package/chunk-FW6YHHLI.js +0 -842
  250. package/chunk-GPVRUGGY.js +0 -115
  251. package/chunk-HSVBJRF4.js +0 -339
  252. package/chunk-WJZOQR2J.js +0 -151
  253. package/chunk-ZCWRMUWT.js +0 -89
  254. package/dist-M676ULYG.js +0 -7314
  255. package/machineWsRunDispatch-WWJQ6WR3.js +0 -182
  256. package/models-PJBE6JDV.js +0 -9
  257. package/tuiSummaryLlmCaller-ALQYUUWB.js +0 -189
  258. package/{chunk-WACI5I6V.js → chunk-2THCNKE4.js} +3 -3
  259. package/{chunk-2QHFH3DR.js → chunk-47ITIXO7.js} +6 -6
  260. package/{chunk-GOO6G4PY.js → chunk-CKG3PRZ7.js} +0 -0
  261. package/{chunk-OQHIVPG4.js → chunk-SNBZZPYH.js} +3 -3
  262. package/{chunk-AETZ7AD6.js → chunk-W6RFEDN4.js} +3 -3
@@ -1,16 +1,32 @@
1
+ import {
2
+ normalizeTimingMs
3
+ } from "./chunk-H57T64RA.js";
4
+ import {
5
+ isAbortError
6
+ } from "./chunk-7DPNBQSV.js";
1
7
  import {
2
8
  ALL_MODELS
3
- } from "./chunk-T43B7LB2.js";
9
+ } from "./chunk-WKGQSYTB.js";
10
+ import {
11
+ asTrimmedNonEmptyStringArray
12
+ } from "./chunk-I42VC5KR.js";
4
13
  import {
5
14
  estimateTokenCount
6
15
  } from "./chunk-PSCNXBYA.js";
7
16
  import {
8
17
  MODEL_LOOKUP_MAP
9
- } from "./chunk-SM3NSZJV.js";
18
+ } from "./chunk-2UCBGYO4.js";
10
19
  import {
20
+ PLATFORM_HOSTED_DEEPSEEK_FLASH_MODEL,
11
21
  isPlatformManagedProvider,
12
22
  resolvePlatformEffectiveModel
13
- } from "./chunk-GOO6G4PY.js";
23
+ } from "./chunk-CKG3PRZ7.js";
24
+ import {
25
+ asOptionalFiniteNumber
26
+ } from "./chunk-WWC7I6TA.js";
27
+ import {
28
+ asOptionalTrimmedString
29
+ } from "./chunk-G3SUCT4W.js";
14
30
 
15
31
  // packages/core/chat/messageContentSerialize.ts
16
32
  var serializeMessageContent = (content, imagePlaceholder = "[\u56FE\u7247]") => {
@@ -34,6 +50,277 @@ var serializeMessageContent = (content, imagePlaceholder = "[\u56FE\u7247]") =>
34
50
  return null;
35
51
  };
36
52
 
53
+ // packages/ai/token/cacheTokenFields.ts
54
+ var finiteTokenCount = (value) => {
55
+ if (typeof value !== "number" || !Number.isFinite(value)) return void 0;
56
+ return Math.max(0, Math.floor(value));
57
+ };
58
+ var readNested = (value, path) => {
59
+ let cursor = value;
60
+ for (const key of path) {
61
+ if (!cursor || typeof cursor !== "object") return void 0;
62
+ cursor = cursor[key];
63
+ }
64
+ return finiteTokenCount(cursor);
65
+ };
66
+ var firstPositive = (usage, readers) => {
67
+ for (const read of readers) {
68
+ const value = read(usage);
69
+ if (value !== void 0 && value !== 0) return value;
70
+ }
71
+ return 0;
72
+ };
73
+ var topLevel = (field) => (usage) => {
74
+ if (!usage || typeof usage !== "object") return void 0;
75
+ return finiteTokenCount(usage[field]);
76
+ };
77
+ var nested = (path) => (usage) => readNested(usage, path);
78
+ var firstPresentAsNumber = (usage, readers) => {
79
+ let sawField = false;
80
+ for (const read of readers) {
81
+ const value = read(usage);
82
+ if (value === void 0) continue;
83
+ sawField = true;
84
+ if (value !== 0) return value;
85
+ }
86
+ return sawField ? 0 : null;
87
+ };
88
+ var CACHE_READ_READERS = [
89
+ topLevel("cache_read_input_tokens"),
90
+ topLevel("prompt_cache_hit_tokens"),
91
+ nested(["input_tokens_details", "cached_tokens"]),
92
+ nested(["prompt_tokens_details", "cached_tokens"])
93
+ ];
94
+ var CACHE_CREATION_READERS = [
95
+ topLevel("cache_creation_input_tokens"),
96
+ topLevel("prompt_cache_miss_tokens"),
97
+ nested(["input_tokens_details", "cache_write_tokens"])
98
+ ];
99
+ var readCacheReadInputTokens = (usage) => firstPositive(usage, CACHE_READ_READERS);
100
+ var readCacheReadInputTokensOrNull = (usage) => firstPresentAsNumber(usage, CACHE_READ_READERS);
101
+ var readCacheCreationInputTokens = (usage) => firstPositive(usage, CACHE_CREATION_READERS);
102
+
103
+ // packages/ai/token/normalizeUsage.ts
104
+ var normalizeStringArray = (value) => {
105
+ if (!Array.isArray(value)) return void 0;
106
+ const normalized = [...new Set(asTrimmedNonEmptyStringArray(value))];
107
+ return normalized.length > 0 ? normalized : void 0;
108
+ };
109
+ var finiteTokenCount2 = (value) => {
110
+ const finite = asOptionalFiniteNumber(value);
111
+ if (finite === void 0) return void 0;
112
+ return Math.max(0, Math.floor(finite));
113
+ };
114
+ var readFiniteNumberField = (usage, field) => {
115
+ if (!usage || typeof usage !== "object") return void 0;
116
+ if (!(field in usage)) return void 0;
117
+ const candidate = usage[field];
118
+ return asOptionalFiniteNumber(candidate);
119
+ };
120
+ var readOptionalOutputTokens = (usage) => {
121
+ if (!usage || typeof usage !== "object") return void 0;
122
+ const field = "output_tokens" in usage && usage.output_tokens != null ? "output_tokens" : "completion_tokens";
123
+ return readFiniteNumberField(usage, field);
124
+ };
125
+ var readCostInUsdTicks = (usage) => readFiniteNumberField(usage, "cost_in_usd_ticks");
126
+ var normalizeUsage = (usage) => {
127
+ if (!usage || typeof usage !== "object") {
128
+ return {
129
+ input_tokens: 0,
130
+ output_tokens: 0,
131
+ total_tokens: 0,
132
+ cache_creation_input_tokens: 0,
133
+ cache_read_input_tokens: 0,
134
+ cost: 0
135
+ };
136
+ }
137
+ const inputTokens = "input_tokens" in usage ? usage.input_tokens ?? 0 : "prompt_tokens" in usage ? usage.prompt_tokens : 0;
138
+ const outputTokens = "output_tokens" in usage ? usage.output_tokens ?? 0 : "completion_tokens" in usage ? usage.completion_tokens : 0;
139
+ const cacheCreationInputTokens = readCacheCreationInputTokens(usage);
140
+ const cacheReadInputTokens = readCacheReadInputTokens(usage);
141
+ let cost = 0;
142
+ const providedCost = readFiniteNumberField(usage, "cost");
143
+ if (providedCost !== void 0) {
144
+ cost = providedCost;
145
+ }
146
+ const xaiTicks = readCostInUsdTicks(usage);
147
+ if (xaiTicks !== void 0 && providedCost === void 0) {
148
+ cost = xaiTicks / 1e10;
149
+ }
150
+ const billingProvider = asOptionalTrimmedString(usage.billing_provider);
151
+ const billingModel = asOptionalTrimmedString(usage.billing_model);
152
+ const billingServiceTier = asOptionalTrimmedString(usage.billing_service_tier);
153
+ const billingEstimated = "billing_estimated" in usage && usage.billing_estimated === true;
154
+ const serverBilled = "server_billed" in usage && usage.server_billed === true;
155
+ const providerCallId = asOptionalTrimmedString(usage.provider_call_id);
156
+ const imageGenerationCount = "image_generation_count" in usage ? asOptionalFiniteNumber(usage.image_generation_count) : void 0;
157
+ const providerResponseIds = normalizeStringArray(
158
+ usage.provider_response_ids
159
+ );
160
+ const providerRequestIds = normalizeStringArray(
161
+ usage.provider_request_ids
162
+ );
163
+ const firstOutputMs = normalizeTimingMs(
164
+ readFiniteNumberField(usage, "firstOutputMs") ?? readFiniteNumberField(usage, "firstTokenMs")
165
+ );
166
+ const callDurationMs = normalizeTimingMs(
167
+ readFiniteNumberField(usage, "callDurationMs") ?? readFiniteNumberField(usage, "durationMs")
168
+ );
169
+ return {
170
+ input_tokens: inputTokens,
171
+ output_tokens: outputTokens,
172
+ total_tokens: finiteTokenCount2(usage.total_tokens) ?? inputTokens + outputTokens,
173
+ cache_creation_input_tokens: cacheCreationInputTokens,
174
+ cache_read_input_tokens: cacheReadInputTokens,
175
+ cost,
176
+ ...typeof imageGenerationCount === "number" ? { image_generation_count: imageGenerationCount } : {},
177
+ ...providerResponseIds ? { provider_response_ids: providerResponseIds } : {},
178
+ ...providerRequestIds ? { provider_request_ids: providerRequestIds } : {},
179
+ ...billingProvider ? { billing_provider: billingProvider } : {},
180
+ ...billingModel ? { billing_model: billingModel } : {},
181
+ ...billingServiceTier ? { billing_service_tier: billingServiceTier } : {},
182
+ ...billingEstimated ? { billing_estimated: true } : {},
183
+ ...serverBilled ? { server_billed: true } : {},
184
+ ...providerCallId ? { provider_call_id: providerCallId } : {},
185
+ ...xaiTicks !== void 0 ? { cost_in_usd_ticks: xaiTicks } : {},
186
+ ...firstOutputMs !== void 0 ? { firstOutputMs } : {},
187
+ ...callDurationMs !== void 0 ? { callDurationMs } : {}
188
+ };
189
+ };
190
+
191
+ // packages/ai/context/summaryContract.ts
192
+ var SUMMARY_TOTAL_BUDGET_MS = { automatic: 6e4, manual: 12e4 };
193
+ var realClock = {
194
+ now: Date.now,
195
+ setTimeout: (callback, ms) => setTimeout(callback, ms),
196
+ clearTimeout: (handle) => clearTimeout(handle)
197
+ };
198
+ function createSummaryBudget(options) {
199
+ const clock = options.clock ?? realClock;
200
+ if (options.deadlineMs !== void 0 && !Number.isFinite(options.deadlineMs)) {
201
+ throw new RangeError("Summary deadline must be finite");
202
+ }
203
+ const deadlineMs = Math.min(clock.now() + SUMMARY_TOTAL_BUDGET_MS[options.mode], options.deadlineMs ?? Infinity);
204
+ const controller = new AbortController();
205
+ const cancel = () => controller.abort(new DOMException("Summary cancelled", "AbortError"));
206
+ const expire = () => controller.abort(new DOMException("Summary deadline exceeded", "TimeoutError"));
207
+ const remainingMs = () => Math.max(0, deadlineMs - clock.now());
208
+ const check = () => {
209
+ if (!controller.signal.aborted && remainingMs() === 0) expire();
210
+ if (controller.signal.aborted) throw controller.signal.reason;
211
+ };
212
+ let timer;
213
+ const cleanup = () => {
214
+ if (timer !== void 0) clock.clearTimeout(timer);
215
+ options.signal?.removeEventListener("abort", cancel);
216
+ };
217
+ controller.signal.addEventListener("abort", cleanup, { once: true });
218
+ options.signal?.addEventListener("abort", cancel, { once: true });
219
+ if (options.signal?.aborted) cancel();
220
+ else if (remainingMs() === 0) expire();
221
+ else timer = clock.setTimeout(expire, remainingMs());
222
+ const budget = {
223
+ deadlineMs,
224
+ signal: controller.signal,
225
+ remainingMs,
226
+ async run(operation) {
227
+ check();
228
+ let onAbort;
229
+ const stopped = new Promise((_, reject) => {
230
+ onAbort = () => reject(controller.signal.reason);
231
+ controller.signal.addEventListener("abort", onAbort, { once: true });
232
+ });
233
+ try {
234
+ const value = await Promise.race([Promise.resolve().then(() => {
235
+ check();
236
+ return operation({ deadlineMs, signal: controller.signal });
237
+ }), stopped]);
238
+ check();
239
+ return value;
240
+ } finally {
241
+ if (onAbort) controller.signal.removeEventListener("abort", onAbort);
242
+ }
243
+ },
244
+ dispose() {
245
+ cancel();
246
+ cleanup();
247
+ }
248
+ };
249
+ return budget;
250
+ }
251
+ function record(value) {
252
+ return value !== null && typeof value === "object" ? value : {};
253
+ }
254
+ function identifier(value) {
255
+ return typeof value === "string" && value.length <= 128 && /^[a-zA-Z0-9][a-zA-Z0-9._:/-]*$/.test(value) && !/https?:|^bearer|^sk-|^vault-cred|^nolo_cred/i.test(value) ? value : void 0;
256
+ }
257
+ function classifySummaryError(error, context = {}) {
258
+ const top = record(error);
259
+ const nested2 = record(top.error);
260
+ const rawStatus = top.status ?? top.statusCode ?? nested2.status;
261
+ const status = typeof rawStatus === "number" && Number.isInteger(rawStatus) && rawStatus >= 100 && rawStatus <= 599 ? rawStatus : void 0;
262
+ const code = identifier(top.code ?? nested2.code);
263
+ const errorType = identifier(top.type ?? nested2.type);
264
+ const balanceSource = errorType === "insufficient_balance_error" || top.balanceSource === "upstream" ? "upstream" : code === "INSUFFICIENT_BALANCE" ? "platform-user" : void 0;
265
+ const category = top.name === "TimeoutError" || code === "ETIMEDOUT" || code === "DEADLINE_EXCEEDED" ? "timeout" : isAbortError(error) ? "cancelled" : status !== void 0 ? "http" : code ? "provider" : "unknown";
266
+ return {
267
+ category,
268
+ message: `Summary ${category} failure`,
269
+ ...status === void 0 ? {} : { status },
270
+ ...code === void 0 ? {} : { code },
271
+ ...errorType === void 0 ? {} : { errorType },
272
+ ...balanceSource === void 0 ? {} : { balanceSource },
273
+ model: identifier(top.model) ?? identifier(context.model),
274
+ provider: identifier(top.provider) ?? identifier(context.provider),
275
+ attemptId: identifier(top.attemptId) ?? identifier(context.attemptId),
276
+ stage: identifier(top.stage) ?? identifier(context.stage) ?? "attempt",
277
+ ...Object.fromEntries(["finishReason", "responseStatus", "incompleteReason"].flatMap((key) => {
278
+ const value = identifier(top[key]);
279
+ return value === void 0 ? [] : [[key, value]];
280
+ })),
281
+ ...Object.fromEntries(["maxOutputTokens", "completionTokens", "outputChars"].flatMap((key) => typeof top[key] === "number" && Number.isSafeInteger(top[key]) && top[key] >= 0 ? [[key, top[key]]] : []))
282
+ };
283
+ }
284
+ function isTruncatedCompletion(completion) {
285
+ return completion.truncated === true || completion.finishReason === "length" || completion.finishReason === "max_tokens" || completion.responseStatus === "incomplete" || completion.incompleteReason !== void 0;
286
+ }
287
+ function summaryCompletionTokens(usage) {
288
+ const tokens = readOptionalOutputTokens(usage);
289
+ return typeof tokens === "number" && Number.isSafeInteger(tokens) && tokens >= 0 ? tokens : void 0;
290
+ }
291
+
292
+ // packages/ai/context/summaryRouting.ts
293
+ function selectSummaryRoute(input) {
294
+ return input.authenticated && input.platformAvailable && !!input.userId && input.userId !== "local" && input.userId !== "guest" && typeof input.credits === "number" && Number.isFinite(input.credits) && input.credits > 0 ? { kind: "platform", model: PLATFORM_HOSTED_DEEPSEEK_FLASH_MODEL } : { kind: "current" };
295
+ }
296
+ async function runSummaryWithContract(args) {
297
+ const attempts = [];
298
+ const execute = async (route) => {
299
+ const attempt = args[route];
300
+ try {
301
+ const completion = await args.budget.run((context) => attempt.run(context));
302
+ if (typeof completion?.text !== "string") {
303
+ throw { code: "INVALID_SUMMARY_COMPLETION", stage: "decode" };
304
+ }
305
+ const text = completion.text.trim();
306
+ const kind = isTruncatedCompletion(completion) ? "truncated" : text ? "success" : "empty";
307
+ attempts.push({ route, outcome: kind });
308
+ if (kind === "empty") return { kind, route, attempts, completion };
309
+ return { kind, text, route, attempts, completion };
310
+ } catch (cause) {
311
+ const error = classifySummaryError(args.budget.signal.aborted ? args.budget.signal.reason : cause, attempt);
312
+ const kind = error.category === "cancelled" ? "cancelled" : "error";
313
+ attempts.push({ route, outcome: kind, error });
314
+ return { kind, error, route, attempts };
315
+ }
316
+ };
317
+ if (selectSummaryRoute(args.eligibility).kind === "platform") {
318
+ const result = await execute("platform");
319
+ if (result.kind !== "error" || result.error.code !== "INSUFFICIENT_BALANCE" || result.error.balanceSource !== "platform-user" || result.error.category === "timeout" || args.budget.signal.aborted) return result;
320
+ }
321
+ return execute("current");
322
+ }
323
+
37
324
  // packages/core/sha256.ts
38
325
  import SHA256 from "crypto-js/sha256.js";
39
326
  function sha256Hex(text) {
@@ -44,32 +331,14 @@ function sha256Hex(text) {
44
331
  var TOOL_OUTPUT_CAP_WINDOW_RATIO = 0.12;
45
332
  var TOOL_OUTPUT_CAP_MIN_TOKENS = 4e3;
46
333
  var TOOL_OUTPUT_CAP_MAX_TOKENS = 5e4;
47
- var COMPRESSION_TRIGGER_RATIO_MAX = 0.78;
48
- var COMPRESSION_TRIGGER_RATIO_MIN = 0.5;
49
- var ROUND_OVERHEAD_WINDOW_RATIO = 0.08;
50
- var ROUND_OVERHEAD_MIN_TOKENS = 4e3;
51
- var ROUND_OVERHEAD_MAX_TOKENS = 24e3;
334
+ var COMPRESSION_TRIGGER_RATIO_MAX = 0.9;
52
335
  var clamp = (v, min, max) => Math.min(max, Math.max(min, v));
53
336
  var capToolOutputTokens = (contextWindow) => clamp(
54
337
  Math.floor(contextWindow * TOOL_OUTPUT_CAP_WINDOW_RATIO),
55
338
  TOOL_OUTPUT_CAP_MIN_TOKENS,
56
339
  TOOL_OUTPUT_CAP_MAX_TOKENS
57
340
  );
58
- var resolveCompressionTriggerRatio = (contextWindow) => {
59
- if (typeof contextWindow !== "number" || !Number.isFinite(contextWindow) || contextWindow <= 0) {
60
- return COMPRESSION_TRIGGER_RATIO_MAX;
61
- }
62
- const headroom = capToolOutputTokens(contextWindow) + clamp(
63
- Math.floor(contextWindow * ROUND_OVERHEAD_WINDOW_RATIO),
64
- ROUND_OVERHEAD_MIN_TOKENS,
65
- ROUND_OVERHEAD_MAX_TOKENS
66
- );
67
- return clamp(
68
- 1 - headroom / contextWindow,
69
- COMPRESSION_TRIGGER_RATIO_MIN,
70
- COMPRESSION_TRIGGER_RATIO_MAX
71
- );
72
- };
341
+ var resolveCompressionTriggerRatio = (_contextWindow) => COMPRESSION_TRIGGER_RATIO_MAX;
73
342
  var truncateToolOutputForContext = (text, contextWindow) => {
74
343
  if (!text) return text;
75
344
  const capTokens = capToolOutputTokens(contextWindow);
@@ -96,8 +365,10 @@ var truncateToolOutputForContext = (text, contextWindow) => {
96
365
 
97
366
  // packages/ai/context/planCompression.ts
98
367
  var MIN_COMPRESS_COUNT = 5;
368
+ var INPUT_ITEM_TRIGGER_RATIO = 0.9;
369
+ var INPUT_ITEM_RETENTION_RATIO = 0.6;
99
370
  var ACTIVE_SUMMARY_TAIL_KEEP_COUNT = 2;
100
- var COMPACTION_RETENTION_CUSHION_RATIO = 0.18;
371
+ var RECENT_ORIGINAL_TOKEN_BUDGET = 2e4;
101
372
  var MIN_TRIGGER_PENDING_COUNT = MIN_COMPRESS_COUNT + ACTIVE_SUMMARY_TAIL_KEEP_COUNT;
102
373
  var getMessageTokenCount = (msg) => {
103
374
  const content = serializeMessageContent(msg.content) || "";
@@ -151,7 +422,7 @@ function shouldTriggerCompaction(args) {
151
422
  const usageRatio = normalizeContextUsageRatio(realContextUsagePercent);
152
423
  const triggeredByRealUsage = usageRatio !== void 0 && usageRatio >= triggerRatio;
153
424
  const triggeredByEstimate = usageRatio === void 0 && totalUsed >= historyBudget;
154
- const shouldRunActiveSummary = force && reason === "manual";
425
+ const shouldRunActiveSummary = force && (reason === "manual" || reason === "budget_rescue");
155
426
  const triggeredByColdResume = false;
156
427
  return {
157
428
  trigger: triggeredByRealUsage || triggeredByEstimate || shouldRunActiveSummary || triggeredByColdResume,
@@ -172,28 +443,17 @@ function calculateCompressCount(pendingMsgs, rawMessageBudget) {
172
443
  return pendingMsgs.length - keepCount;
173
444
  }
174
445
  function resolveEffectiveCompactionBudgets(args) {
175
- const {
176
- contextWindow,
177
- triggerRatio,
178
- historyBudget,
179
- rawMessageBudget,
180
- summaryTokens,
181
- cushionRatio = COMPACTION_RETENTION_CUSHION_RATIO
182
- } = args;
183
- const maxRetainedRatio = Math.max(
184
- 0.2,
185
- Number((triggerRatio - cushionRatio).toFixed(4))
186
- );
187
- const maxRetainedHistoryBudget = Math.floor(contextWindow * maxRetainedRatio);
188
- const effectiveHistoryBudget = Math.min(historyBudget, maxRetainedHistoryBudget);
189
- const effectiveRawMessageBudget = Math.min(
190
- rawMessageBudget,
191
- Math.max(0, effectiveHistoryBudget - summaryTokens)
192
- );
446
+ const effectiveHistoryBudget = Math.max(0, Math.min(
447
+ Math.floor(args.contextWindow),
448
+ Math.floor(args.historyBudget)
449
+ ));
450
+ const newSummaryTokenReserve = args.newSummaryTokenReserve ?? Math.min(8192, Math.max(1, Math.floor(args.contextWindow / 4)));
193
451
  return {
194
452
  effectiveHistoryBudget,
195
- effectiveRawMessageBudget,
196
- maxRetainedRatio
453
+ effectiveRawMessageBudget: Math.max(0, Math.min(
454
+ RECENT_ORIGINAL_TOKEN_BUDGET,
455
+ effectiveHistoryBudget - Math.max(0, newSummaryTokenReserve)
456
+ ))
197
457
  };
198
458
  }
199
459
  function guardToolChainBoundary(pendingMsgs, compressCount, preserveByProjection) {
@@ -212,6 +472,10 @@ function guardToolChainBoundary(pendingMsgs, compressCount, preserveByProjection
212
472
  }
213
473
  return count;
214
474
  }
475
+ function calculateItemCompressCount(pendingMsgs, maxInputItems, preserveByProjection) {
476
+ const keepCount = Math.max(0, Math.floor(maxInputItems * INPUT_ITEM_RETENTION_RATIO) - 2 - (preserveByProjection ? 1 : 0));
477
+ return Math.max(0, pendingMsgs.length - keepCount);
478
+ }
215
479
  function planCompression(input) {
216
480
  const {
217
481
  allMsgs,
@@ -249,6 +513,9 @@ function planCompression(input) {
249
513
  }
250
514
  }
251
515
  }
516
+ const maxInputItems = typeof input.maxInputItems === "number" && Number.isFinite(input.maxInputItems) && input.maxInputItems > 0 ? input.maxInputItems : void 0;
517
+ const itemCount = pendingMsgs.length + (summary ? 1 : 0) + 1 + (coveredUserTokens > 0 ? 1 : 0);
518
+ const triggeredByItemLimit = maxInputItems !== void 0 && itemCount >= maxInputItems * INPUT_ITEM_TRIGGER_RATIO;
252
519
  const totalUsed = summaryTokens + coveredUserTokens + pendingTokens;
253
520
  const triggerRatio = resolveCompressionTriggerRatio(contextWindow);
254
521
  const historyBudget = Math.floor(contextWindow * triggerRatio);
@@ -268,6 +535,7 @@ function planCompression(input) {
268
535
  });
269
536
  const diagnostics = {
270
537
  pendingMsgCount: pendingMsgs.length,
538
+ ...maxInputItems !== void 0 ? { itemCount, maxInputItems, triggeredByItemLimit } : {},
271
539
  totalUsed,
272
540
  historyBudget,
273
541
  triggerRatio,
@@ -277,7 +545,7 @@ function planCompression(input) {
277
545
  triggeredByColdResume,
278
546
  shouldRunActiveSummary
279
547
  };
280
- if (!trigger) {
548
+ if (!trigger && !triggeredByItemLimit) {
281
549
  return emptyPlan(startIndex, {
282
550
  ...diagnostics,
283
551
  emptyReason: "not-triggered"
@@ -286,17 +554,26 @@ function planCompression(input) {
286
554
  const { effectiveRawMessageBudget } = resolveEffectiveCompactionBudgets({
287
555
  contextWindow,
288
556
  triggerRatio,
289
- historyBudget,
557
+ historyBudget: Math.min(historyBudget, input.availableHistoryTokens ?? historyBudget),
290
558
  rawMessageBudget,
291
- summaryTokens: Math.max(summaryTokens, Math.min(1e3, Math.floor(contextWindow * 0.1)))
559
+ summaryTokens,
560
+ newSummaryTokenReserve: input.newSummaryTokenReserve
292
561
  });
293
562
  const minimumPrefixTokens = Math.min(1e3, Math.floor(contextWindow * 0.1));
294
- const tailBudget = Math.min(effectiveRawMessageBudget, Math.max(0, pendingTokens - minimumPrefixTokens));
295
- let compressCount = guardToolChainBoundary(
296
- pendingMsgs,
297
- calculateCompressCount(pendingMsgs, tailBudget),
298
- preserveLatestUserByProjection
299
- );
563
+ const tailBudget = triggeredByItemLimit ? effectiveRawMessageBudget : Math.min(effectiveRawMessageBudget, Math.max(0, pendingTokens - minimumPrefixTokens));
564
+ const itemCompressCount = maxInputItems !== void 0 ? calculateItemCompressCount(pendingMsgs, maxInputItems, preserveLatestUserByProjection) : 0;
565
+ const guardedCut = (tokenCompressCount) => {
566
+ let candidate = Math.max(tokenCompressCount, itemCompressCount);
567
+ let guarded = guardToolChainBoundary(pendingMsgs, candidate, preserveLatestUserByProjection);
568
+ while (guarded < itemCompressCount && candidate < pendingMsgs.length - 1) {
569
+ candidate++;
570
+ const next = guardToolChainBoundary(pendingMsgs, candidate, preserveLatestUserByProjection);
571
+ if (next === guarded && pendingMsgs[next]?.role === "user" && !preserveLatestUserByProjection) break;
572
+ guarded = next;
573
+ }
574
+ return guarded;
575
+ };
576
+ let compressCount = guardedCut(calculateCompressCount(pendingMsgs, tailBudget));
300
577
  if (preserveLatestUserByProjection) {
301
578
  let latestUser = -1;
302
579
  for (let i = pendingMsgs.length - 1; i >= 0; i--) {
@@ -307,10 +584,8 @@ function planCompression(input) {
307
584
  }
308
585
  const preservedTokens = latestUser >= 0 && latestUser < compressCount ? getMessageTokenCount(pendingMsgs[latestUser]) : latestUser < 0 ? coveredUserTokens : 0;
309
586
  if (preservedTokens > 0) {
310
- compressCount = guardToolChainBoundary(
311
- pendingMsgs,
312
- calculateCompressCount(pendingMsgs, Math.max(0, tailBudget - preservedTokens)),
313
- true
587
+ compressCount = guardedCut(
588
+ calculateCompressCount(pendingMsgs, Math.max(0, tailBudget - preservedTokens))
314
589
  );
315
590
  }
316
591
  }
@@ -336,7 +611,12 @@ function planCompression(input) {
336
611
  msgsToKeep,
337
612
  newSummarizedBeforeId,
338
613
  startIndex,
339
- diagnostics: { ...diagnostics, compressCount }
614
+ diagnostics: {
615
+ ...diagnostics,
616
+ compressCount,
617
+ recentOriginalTokenBudget: tailBudget,
618
+ retainedTailOverBudget: msgsToKeep.reduce((sum, msg) => sum + getMessageTokenCount(msg), 0) > tailBudget
619
+ }
340
620
  };
341
621
  }
342
622
 
@@ -368,7 +648,7 @@ var COMPACTION_SUMMARY_SYSTEM_PROMPT = `\u4F60\u662F\u5BF9\u8BDD\u4E0A\u4E0B\u65
368
648
  - \u300C\u5361\u70B9\u4E0E\u9700\u7528\u6237\u51B3\u5B9A\u300D\uFF1A\u963B\u585E\u9879\u5361\u5728\u54EA\u3001\u9700\u8981\u7528\u6237\u63D0\u4F9B\u4EC0\u4E48\uFF08\u6388\u6743 / \u51ED\u636E / \u51B3\u5B9A\uFF09\uFF0C\u5199\u6E05\u695A\uFF0C\u4E0D\u5F97\u542B\u7CCA\u3002
369
649
  - \u300C\u8F93\u5165\u672A\u8986\u76D6\u300D\uFF1A\u538B\u7F29\u8303\u56F4\u5185\u67E5\u4E0D\u5230\u7684\u5173\u952E\u4FE1\u606F\uFF08\u5982\u521D\u59CB\u539F\u8BDD\u3001\u6307\u5B9A id\uFF09\uFF0C\u5FC5\u987B\u5199"\u8F93\u5165\u4E2D\u672A\u89C1"\uFF0C\u7981\u6B62\u8111\u8865\u3002
370
650
  3) \u5BF9\u8BDD\u8FDB\u5C55\u4E0E\u5F85\u529E\u4EE5\u7B2C\u4E00\u4EBA\u79F0\u7EED\u4F5C\u7B14\u8BB0\u7684\u53E3\u543B\u5199\uFF08"\u6211\u505A\u4E86\u2026""\u7528\u6237\u8981\u6C42\u2026""\u4E0B\u4E00\u6B65\u6211\u9700\u8981\u2026"\uFF09\uFF0C\u4E0D\u8981\u5199\u6210\u7B2C\u4E09\u65B9\u89C2\u5BDF\u62A5\u544A\u3002\u5148\u6781\u7B80\u6982\u62EC\u65E7\u4E0A\u4E0B\u6587\uFF0C\u518D\u66F4\u8BE6\u7EC6\u8BB0\u5F55\u6700\u8FD1\u8FDB\u5C55\u3001\u7ED3\u8BBA\u3001\u5206\u6B67\u4E0E\u4E0B\u4E00\u6B65\u3002\u5BF9\u4E8E\u58F0\u79F0\u5DF2\u5B8C\u6210\u4F46\u5C1A\u672A\u9A8C\u8BC1\u7684\u5DE5\u4F5C\uFF08\u5982\u5DE5\u5177\u8C03\u7528\u8FD4\u56DE\u6210\u529F\u4F46\u7ED3\u679C\u672A\u4EBA\u5DE5\u786E\u8BA4\uFF09\uFF0C\u660E\u786E\u6807\u6CE8"\uFF08\u5F85\u9A8C\u8BC1\uFF09"\u2014\u2014\u4E0D\u8981\u9ED8\u8BA4\u4FE1\u4EFB\u5DE5\u5177\u8FD4\u56DE\u503C\u3002
371
- 4) \u6587\u4EF6\u64CD\u4F5C\u6E05\u5355\uFF1A\u5217\u51FA\u672C\u6B21\u538B\u7F29\u8303\u56F4\u5185\u8BFB\u53D6\u3001\u5199\u5165\u3001\u7F16\u8F91\u8FC7\u7684\u6587\u4EF6\u8DEF\u5F84\u53CA\u64CD\u4F5C\u7C7B\u578B\uFF08\u5982: - \u8BFB\u53D6: path/to/file\uFF1B\u82E5\u672A\u6D89\u53CA\u6587\u4EF6\u64CD\u4F5C\u5199"\u65E0"\uFF09\u3002
651
+ 4) \u6587\u4EF6\u64CD\u4F5C\u6E05\u5355\uFF1A\u6309\u8BFB\u53D6\u3001\u5199\u5165\u3001\u7F16\u8F91\u5217\u51FA\u8DEF\u5F84\uFF08\u5982: - \u8BFB\u53D6: path/to/file\uFF1B\u672A\u6D89\u53CA\u5219\u5199"\u65E0"\uFF09\u3002\u6709\u957F\u5EA6\u7EA6\u675F\u65F6\u5408\u5E76\u65E7\u64CD\u4F5C\uFF0C\u7701\u7565\u65E0\u5173\u8BFB\u53D6\u3002
372
652
  5) \u5FFD\u7565\u5BD2\u6684\u3001\u91CD\u590D\u5C1D\u8BD5\u548C\u65E0\u4EF7\u503C\u5E9F\u8BDD\uFF1B**\u5DF2\u653E\u5F03\u7684\u65B9\u6848/\u5C1D\u8BD5**\u53EF\u4EE5\u7701\u7565\uFF0C\u4F46\u7528\u6237\u5F53\u521D\u7684\u610F\u56FE\u4E0E\u7406\u7531\u4E0D\u53EF\u7701\u7565\uFF08\u89C1\u7B2C 2 \u6761\uFF09\u3002
373
653
  6) \u4E0D\u8981\u7F16\u9020\u672A\u51FA\u73B0\u7684\u4FE1\u606F\uFF1B\u4E0D\u8981\u5F00\u573A\u767D\u3001\u7ED3\u675F\u8BED\u3001markdown \u4EE3\u7801\u5757\u6216\u989D\u5916\u7AE0\u8282\uFF1B\u4E0D\u8981\u8C03\u7528\u4EFB\u4F55\u5DE5\u5177\u3002`;
374
654
  function formatMessageContentFallback(msg) {
@@ -380,8 +660,16 @@ function formatMessageContentFallback(msg) {
380
660
  return "[\u975E\u6587\u672C\u5185\u5BB9]";
381
661
  }
382
662
  function buildCompactionUserContent(args) {
383
- const parts = [`\u3010\u73B0\u6709\u8BB0\u5FC6\u3011\uFF1A
384
- ${args.previousSummary || "(\u65E0)"}`];
663
+ const parts = [];
664
+ if (args.outputTokenBudget !== void 0) {
665
+ const budget = args.outputTokenBudget;
666
+ if (!Number.isFinite(budget) || budget < 1) throw new RangeError("Invalid summary output budget");
667
+ const limit = Math.floor(budget);
668
+ const target = Math.max(1, Math.min(2e3, Math.floor(limit / 2)));
669
+ parts.push(`Summary target: ${target} tokens; hard output limit: ${limit} tokens. Complete 3 sections; merge old progress/files.`);
670
+ }
671
+ parts.push(`\u3010\u73B0\u6709\u8BB0\u5FC6\u3011\uFF1A
672
+ ${args.previousSummary || "(\u65E0)"}`);
385
673
  if (args.fileOpsText !== void 0) {
386
674
  parts.push(`\u3010\u6587\u4EF6\u64CD\u4F5C\u6E05\u5355\u3011\uFF1A
387
675
  ${args.fileOpsText || "\u65E0"}`);
@@ -449,17 +737,46 @@ function makeBoundedExcerpt(content) {
449
737
  return content.slice(0, headLength) + marker + (selected.length ? selected.join("\n") + "\n" : "") + (tailLength ? content.slice(-tailLength) : "");
450
738
  };
451
739
  }
740
+ var OMITTED_ROLE_ORDER = ["user", "assistant", "tool", "system"];
741
+ var MIN_INLINE_CONTENT_TOKENS = 12;
742
+ function formatOmittedRun(start, end, counts) {
743
+ const ordered = [
744
+ ...OMITTED_ROLE_ORDER,
745
+ ...[...counts.keys()].filter((role) => !OMITTED_ROLE_ORDER.includes(role))
746
+ ];
747
+ const parts = ordered.filter((role) => (counts.get(role) ?? 0) > 0).map((role) => `${role} ${counts.get(role)}`);
748
+ const range = start === end ? `\u6D88\u606F ${start + 1}` : `\u6D88\u606F ${start + 1}\u2013${end + 1}`;
749
+ return `[... ${range} \u5DF2\u7701\u7565\uFF1A${parts.join("\u3001")} ...]`;
750
+ }
751
+ var SUMMARY_HEAD_SHARE = 0.4;
752
+ var DECLARATION_RESERVE = 40;
753
+ var USER_MESSAGE_MAX_DEMAND = 600;
754
+ var SUMMARY_USER_SHARE = 0.2;
755
+ var DECLARATION_SPLIT_COST = 20;
452
756
  function buildBoundedCompactionRequest(args) {
453
757
  const { msgsToCompress: msgs, previousSummary, contextWindow } = args;
454
- if (!Number.isFinite(contextWindow) || contextWindow <= 0) return { status: "blocked", reason: "invalid-window" };
455
- if (!msgs.length) return { status: "blocked", reason: "empty-input" };
456
- const window = Math.floor(contextWindow);
457
- const outputTokenBudget = Math.min(8192, Math.max(1, Math.floor(window / 4)));
458
- const cap = Math.min(computeSummaryInputTokenCap(contextWindow), window - outputTokenBudget);
758
+ const windowValid = Number.isFinite(contextWindow) && contextWindow > 0;
759
+ const window = windowValid ? Math.floor(contextWindow) : 0;
760
+ const outputTokenBudget = windowValid ? Math.min(8192, Math.max(1, Math.floor(window / 4))) : 0;
761
+ const cap = windowValid ? Math.min(computeSummaryInputTokenCap(contextWindow), window - outputTokenBudget) : 0;
762
+ const blocked = (reason, extra = {}) => ({
763
+ status: "blocked",
764
+ reason,
765
+ diagnostics: {
766
+ contextWindow: window,
767
+ cap,
768
+ outputTokenBudget,
769
+ previousSummaryTokens: estimateTokenCount(previousSummary ?? ""),
770
+ messageCount: msgs.length,
771
+ ...extra
772
+ }
773
+ });
774
+ if (!windowValid) return blocked("invalid-window");
775
+ if (!msgs.length) return blocked("empty-input");
459
776
  const systemTokens = estimateTokenCount(COMPACTION_SUMMARY_SYSTEM_PROMPT);
460
777
  for (let i = 0; i < msgs.length; ) {
461
778
  const msg = msgs[i];
462
- if (msg.role === "tool") return { status: "blocked", reason: "no-safe-group" };
779
+ if (msg.role === "tool") return blocked("no-safe-group");
463
780
  const calls = msg.role === "assistant" && Array.isArray(msg.tool_calls) ? msg.tool_calls : [];
464
781
  if (!calls.length) {
465
782
  i++;
@@ -468,20 +785,20 @@ function buildBoundedCompactionRequest(args) {
468
785
  const ids = calls.map((call) => call.id);
469
786
  const hasIds = ids.every((id) => typeof id === "string" && id.length > 0);
470
787
  if (!hasIds && ids.some((id) => id !== void 0) || hasIds && new Set(ids).size !== ids.length) {
471
- return { status: "blocked", reason: "no-safe-group" };
788
+ return blocked("no-safe-group");
472
789
  }
473
- const remaining2 = new Set(ids);
790
+ const remaining = new Set(ids);
474
791
  let count = 0;
475
792
  i++;
476
793
  while (i < msgs.length && msgs[i].role === "tool") {
477
794
  const id = msgs[i].tool_call_id;
478
- if (hasIds ? !id || !remaining2.delete(id) : id !== void 0) {
479
- return { status: "blocked", reason: "no-safe-group" };
795
+ if (hasIds ? !id || !remaining.delete(id) : id !== void 0) {
796
+ return blocked("no-safe-group");
480
797
  }
481
798
  count++;
482
799
  i++;
483
800
  }
484
- if (count !== calls.length || hasIds && remaining2.size) return { status: "blocked", reason: "no-safe-group" };
801
+ if (count !== calls.length || hasIds && remaining.size) return blocked("no-safe-group");
485
802
  }
486
803
  const canonicalize = args.canonicalizeToolName ?? ((name) => name);
487
804
  const operations = /* @__PURE__ */ new Map();
@@ -493,44 +810,45 @@ function buildBoundedCompactionRequest(args) {
493
810
  }
494
811
  const labelsByOperation = { read: "\u8BFB\u53D6", write: "\u5199\u5165", edit: "\u7F16\u8F91" };
495
812
  const fileOpsText = [...operations.values()].map((op) => `- ${labelsByOperation[op.type]}: ${op.path}`).join("\n") || "\u65E0";
496
- const note = "\u4EE5\u4E0B\u662F\u6709\u635F\u6295\u5F71\uFF0C\u90E8\u5206\u6D88\u606F\u53EF\u80FD\u88AB\u622A\u53D6\uFF1B\u539F\u6587\u4ECD\u5B58\u5386\u53F2\u3002";
813
+ const note = "\u4EE5\u4E0B\u662F\u6709\u635F\u6295\u5F71\uFF1A\u90E8\u5206\u6D88\u606F\u88AB\u622A\u53D6\uFF0C\u8FDE\u7EED\u7701\u7565\u7684\u533A\u95F4\u5408\u5E76\u4E3A\u4E00\u884C [...] \u58F0\u660E\uFF1B\u539F\u6587\u4ECD\u5B58\u5386\u53F2\u3002";
497
814
  const omitted = "[... \u5185\u5BB9\u5DF2\u622A\u53D6 ...]";
498
815
  const contents = msgs.map((msg) => serializeMessageContent(msg.content) || formatMessageContentFallback(msg));
499
- const excerpts = contents.map((content, i) => msgs[i].role === "user" ? void 0 : makeBoundedExcerpt(content));
816
+ const excerpts = contents.map((content) => makeBoundedExcerpt(content));
500
817
  const raw = contents.map((content, i) => msgs[i].role === "tool" ? excerpts[i](TOOL_RESULT_TRUNCATE_CHARS) : content);
501
- const labels = msgs.map((msg) => `${msg.role} [id=${JSON.stringify(msg.id)}]: `);
502
- const projected = msgs.map((msg, i) => msg.role === "user" ? raw[i] : omitted);
503
- const makePrompt = () => buildCompactionUserContent({
818
+ const promptFor = (messagesText) => buildCompactionUserContent({
504
819
  previousSummary,
505
820
  fileOpsText,
506
- messagesText: `${note}
507
- ${labels.map((label, i) => label + projected[i]).join("\n")}`
821
+ outputTokenBudget,
822
+ messagesText
508
823
  });
509
- const base = makePrompt();
510
- const baseTokens = systemTokens + estimateTokenCount(base);
511
- if (baseTokens > cap) return { status: "blocked", reason: "no-budget" };
512
- const remaining = cap - baseTokens;
513
- const demands = raw.map((text, i) => msgs[i].role === "user" ? 0 : estimateTokenCount(text));
514
- const weights = msgs.map((msg) => msg.role === "assistant" ? 2 : 1);
515
- let low = 0;
516
- let high = remaining + 1;
517
- while (low + 1 < high) {
518
- const mid = Math.floor((low + high) / 2);
519
- const used = demands.reduce((sum, demand, i) => sum + Math.min(demand, mid * weights[i]), 0);
520
- if (used <= remaining) low = mid;
521
- else high = mid;
522
- }
523
- let extra = remaining - demands.reduce((sum, demand, i) => sum + Math.min(demand, low * weights[i]), 0);
524
- for (let i = 0; i < msgs.length; i++) {
525
- if (msgs[i].role === "user") continue;
526
- let allowance = Math.min(demands[i], low * weights[i]);
527
- const bonus = Math.min(extra, demands[i] - allowance);
528
- allowance += bonus;
529
- extra -= bonus;
530
- if (demands[i] <= allowance) {
531
- projected[i] = raw[i];
532
- continue;
533
- }
824
+ const demands = raw.map((text) => estimateTokenCount(text));
825
+ const lineOverheads = msgs.map((msg) => estimateTokenCount(`${msg.role}: `) + 1);
826
+ const fixedTokens = systemTokens + estimateTokenCount(promptFor(`${note}
827
+ `));
828
+ const availableTokens = cap - fixedTokens;
829
+ const diagnosticsOf = (expandedMessages, omittedMessages) => {
830
+ const previousSummaryTokens = estimateTokenCount(previousSummary ?? "");
831
+ const baseTokens = systemTokens + estimateTokenCount(promptFor(""));
832
+ return {
833
+ contextWindow: window,
834
+ cap,
835
+ outputTokenBudget,
836
+ previousSummaryTokens,
837
+ messageCount: msgs.length,
838
+ systemTokens,
839
+ templateTokens: fixedTokens - systemTokens - previousSummaryTokens,
840
+ availableTokens,
841
+ expandedMessages,
842
+ omittedMessages,
843
+ baseTokens,
844
+ fileOpsCount: operations.size
845
+ };
846
+ };
847
+ if (availableTokens <= 0) {
848
+ return blocked("no-budget", diagnosticsOf(0, msgs.length));
849
+ }
850
+ const projectContent = (i, allowance) => {
851
+ if (demands[i] <= allowance) return raw[i];
534
852
  let lo = 0;
535
853
  let hi = Math.min(contents[i].length, msgs[i].role === "tool" ? TOOL_RESULT_TRUNCATE_CHARS : contents[i].length);
536
854
  let best = omitted;
@@ -544,19 +862,175 @@ ${labels.map((label, i) => label + projected[i]).join("\n")}`
544
862
  hi = mid - 1;
545
863
  }
546
864
  }
547
- projected[i] = best;
865
+ return best;
866
+ };
867
+ const selectRegions = (budget2) => {
868
+ const expanded = msgs.map(() => false);
869
+ const allowances = msgs.map(() => 0);
870
+ let used = 0;
871
+ const declarationReserve = Math.min(DECLARATION_RESERVE, Math.max(4, Math.floor(budget2 / 4)));
872
+ const room = () => budget2 - used - declarationReserve;
873
+ const takeFull = (i) => {
874
+ expanded[i] = true;
875
+ allowances[i] = demands[i];
876
+ used += lineOverheads[i] + demands[i];
877
+ };
878
+ const drop = (i) => {
879
+ if (!expanded[i]) return;
880
+ expanded[i] = false;
881
+ used -= lineOverheads[i] + allowances[i];
882
+ allowances[i] = 0;
883
+ };
884
+ const headBudget = Math.floor(budget2 * SUMMARY_HEAD_SHARE);
885
+ let headEnd = -1;
886
+ let headUsed = 0;
887
+ for (let i = 0; i < msgs.length; i++) {
888
+ const cost = lineOverheads[i] + demands[i];
889
+ const limit = i === 0 ? Math.max(headBudget, room()) : headBudget - headUsed;
890
+ if (cost > limit) break;
891
+ takeFull(i);
892
+ headUsed += cost;
893
+ headEnd = i;
894
+ }
895
+ const userBudget = Math.floor(budget2 * SUMMARY_USER_SHARE);
896
+ let userSpend = 0;
897
+ for (let i = msgs.length - 1; i > headEnd; i--) {
898
+ if (expanded[i] || msgs[i].role !== "user") continue;
899
+ if (demands[i] > USER_MESSAGE_MAX_DEMAND) continue;
900
+ const cost = lineOverheads[i] + demands[i] + DECLARATION_SPLIT_COST;
901
+ if (userSpend + cost > userBudget || cost > room()) continue;
902
+ takeFull(i);
903
+ userSpend += cost;
904
+ }
905
+ let tailStart = msgs.length;
906
+ for (let i = msgs.length - 1; i > headEnd; i--) {
907
+ if (expanded[i]) {
908
+ tailStart = i;
909
+ continue;
910
+ }
911
+ if (lineOverheads[i] + demands[i] > room()) break;
912
+ takeFull(i);
913
+ tailStart = i;
914
+ }
915
+ const boundaryCap = Math.floor(room() * 0.5);
916
+ const takeBoundary = (i) => {
917
+ const inline = Math.min(room(), boundaryCap) - lineOverheads[i];
918
+ if (inline < MIN_INLINE_CONTENT_TOKENS) return false;
919
+ expanded[i] = true;
920
+ allowances[i] = inline;
921
+ used += lineOverheads[i] + inline;
922
+ return true;
923
+ };
924
+ if (tailStart - 1 > headEnd && !expanded[tailStart - 1] && takeBoundary(tailStart - 1)) tailStart--;
925
+ if (headEnd + 1 < tailStart && !expanded[headEnd + 1] && takeBoundary(headEnd + 1)) headEnd++;
926
+ let grew = true;
927
+ while (grew) {
928
+ grew = false;
929
+ for (let i = tailStart - 1; i > headEnd; i--) {
930
+ if (expanded[i]) {
931
+ tailStart = i;
932
+ continue;
933
+ }
934
+ if (lineOverheads[i] + demands[i] > room()) break;
935
+ takeFull(i);
936
+ tailStart = i;
937
+ grew = true;
938
+ break;
939
+ }
940
+ for (let i = headEnd + 1; i < tailStart; i++) {
941
+ if (expanded[i]) {
942
+ headEnd = i;
943
+ continue;
944
+ }
945
+ if (lineOverheads[i] + demands[i] > room()) break;
946
+ takeFull(i);
947
+ headEnd = i;
948
+ grew = true;
949
+ break;
950
+ }
951
+ }
952
+ const callOfResult = /* @__PURE__ */ new Map();
953
+ const resultsOfCall = /* @__PURE__ */ new Map();
954
+ for (let i = 0; i < msgs.length; i++) {
955
+ const msg = msgs[i];
956
+ const calls = msg.role === "assistant" && Array.isArray(msg.tool_calls) ? msg.tool_calls : [];
957
+ if (!calls.length) continue;
958
+ const ids = calls.map((call) => call.id);
959
+ const byId = ids.every((id) => typeof id === "string" && id.length > 0);
960
+ const results = [];
961
+ for (let j = i + 1; j < msgs.length && msgs[j].role === "tool"; j++) {
962
+ const id = msgs[j].tool_call_id;
963
+ if (!(byId ? typeof id === "string" && ids.includes(id) : id === void 0)) break;
964
+ results.push(j);
965
+ callOfResult.set(j, i);
966
+ }
967
+ resultsOfCall.set(i, results);
968
+ }
969
+ for (const [callIndex, results] of resultsOfCall) {
970
+ if (!expanded[callIndex] || !results.length) continue;
971
+ if (results.every((j) => expanded[j])) continue;
972
+ drop(callIndex);
973
+ }
974
+ for (let i = 0; i < msgs.length; i++) {
975
+ if (!expanded[i] || msgs[i].role !== "tool") continue;
976
+ const callIndex = callOfResult.get(i);
977
+ if (callIndex === void 0 || !expanded[callIndex]) drop(i);
978
+ }
979
+ return { expanded, allowances };
980
+ };
981
+ const render = (budget2) => {
982
+ const { expanded, allowances } = selectRegions(budget2);
983
+ const pieces = [];
984
+ let runStart = -1;
985
+ let runCounts = /* @__PURE__ */ new Map();
986
+ const flushRun = (end) => {
987
+ if (runStart < 0) return;
988
+ pieces.push(formatOmittedRun(runStart, end, runCounts));
989
+ runStart = -1;
990
+ runCounts = /* @__PURE__ */ new Map();
991
+ };
992
+ let expandedCount = 0;
993
+ for (let i = 0; i < msgs.length; i++) {
994
+ if (!expanded[i]) {
995
+ if (runStart < 0) runStart = i;
996
+ runCounts.set(msgs[i].role, (runCounts.get(msgs[i].role) ?? 0) + 1);
997
+ continue;
998
+ }
999
+ flushRun(i - 1);
1000
+ expandedCount++;
1001
+ pieces.push(`${msgs[i].role}: ${projectContent(i, allowances[i])}`);
1002
+ }
1003
+ flushRun(msgs.length - 1);
1004
+ const promptContent = promptFor(`${note}
1005
+ ${pieces.join("\n")}`);
1006
+ return {
1007
+ promptContent,
1008
+ inputTokens: systemTokens + estimateTokenCount(promptContent),
1009
+ expandedCount,
1010
+ omittedCount: msgs.length - expandedCount
1011
+ };
1012
+ };
1013
+ let budget = availableTokens;
1014
+ let last = render(budget);
1015
+ for (let attempt = 0; attempt < 12 && last.inputTokens > cap; attempt++) {
1016
+ const overflow = last.inputTokens - cap;
1017
+ budget = Math.max(0, Math.floor(budget - Math.max(overflow, Math.ceil(budget * 0.15))));
1018
+ last = render(budget);
1019
+ }
1020
+ if (last.inputTokens > cap || last.expandedCount === 0) {
1021
+ return blocked("no-budget", diagnosticsOf(last.expandedCount, last.omittedCount));
548
1022
  }
549
- const promptContent = makePrompt();
550
- const inputTokens = systemTokens + estimateTokenCount(promptContent);
551
- if (inputTokens > cap) return { status: "blocked", reason: "no-budget" };
552
1023
  return {
553
1024
  status: "ready",
554
- promptContent,
1025
+ promptContent: last.promptContent,
555
1026
  coveredMessages: msgs.slice(),
556
1027
  summarizedBeforeId: msgs[msgs.length - 1].id,
557
- inputTokens,
1028
+ inputTokens: last.inputTokens,
558
1029
  outputTokenBudget,
559
- partial: false
1030
+ partial: false,
1031
+ capTokens: cap,
1032
+ expandedMessages: last.expandedCount,
1033
+ omittedMessages: last.omittedCount
560
1034
  };
561
1035
  }
562
1036
  var TOOL_RESULT_TRUNCATE_CHARS = 4e3;
@@ -602,16 +1076,29 @@ function buildCompactionMetrics(args) {
602
1076
  estimateTokens,
603
1077
  estimateMessageTokens
604
1078
  } = args;
1079
+ const previousSummaryTokens = estimateTokens(previousSummary || "");
1080
+ const compressedTokens = msgsToCompress.reduce((s, m) => s + estimateMessageTokens(m), 0);
1081
+ const newSummaryTokens = estimateTokens(newSummary || "");
1082
+ const summaryInput = args.summaryInput;
605
1083
  return {
606
1084
  reason,
607
- previousSummaryTokens: estimateTokens(previousSummary || ""),
608
- compressedTokens: msgsToCompress.reduce((s, m) => s + estimateMessageTokens(m), 0),
1085
+ previousSummaryTokens,
1086
+ compressedTokens,
609
1087
  retainedTokens: msgsToKeep.reduce((s, m) => s + estimateMessageTokens(m), 0),
610
- newSummaryTokens: estimateTokens(newSummary || ""),
1088
+ newSummaryTokens,
611
1089
  compressedCount: msgsToCompress.length,
612
1090
  retainedCount: msgsToKeep.length,
613
1091
  summaryUsage,
614
- hadPreviousSummary: previousSummary.trim().length > 0
1092
+ hadPreviousSummary: previousSummary.trim().length > 0,
1093
+ residentReductionTokens: previousSummaryTokens + compressedTokens - newSummaryTokens,
1094
+ ...summaryInput ? {
1095
+ summaryInputTokens: summaryInput.inputTokens,
1096
+ ...summaryInput.capTokens !== void 0 ? { summaryInputCapTokens: summaryInput.capTokens } : {},
1097
+ ...summaryInput.expandedMessages !== void 0 ? { summaryExpandedMessages: summaryInput.expandedMessages } : {},
1098
+ ...summaryInput.omittedMessages !== void 0 ? { summaryOmittedMessages: summaryInput.omittedMessages } : {}
1099
+ } : {},
1100
+ ...args.planCounts?.pendingMessageCount !== void 0 ? { pendingMessageCount: args.planCounts.pendingMessageCount } : {},
1101
+ ...args.planCounts?.plannedCompressCount !== void 0 ? { plannedCompressCount: args.planCounts.plannedCompressCount } : {}
615
1102
  };
616
1103
  }
617
1104
  function buildCompactionMetricsFromPlan(args) {
@@ -622,6 +1109,8 @@ function buildCompactionMetricsFromPlan(args) {
622
1109
  msgsToKeep: args.plan.msgsToKeep,
623
1110
  newSummary: args.newSummary,
624
1111
  summaryUsage: args.summaryUsage,
1112
+ ...args.summaryInput ? { summaryInput: args.summaryInput } : {},
1113
+ ...args.planCounts ? { planCounts: args.planCounts } : {},
625
1114
  estimateTokens: estimateTokenCount,
626
1115
  estimateMessageTokens: getMessageTokenCount
627
1116
  });
@@ -631,7 +1120,13 @@ function formatCompactionMetricsLog(metrics) {
631
1120
  const totalAfter = metrics.newSummaryTokens + metrics.retainedTokens;
632
1121
  const ratio = totalBefore > 0 ? (totalAfter / totalBefore).toFixed(2) : "N/A";
633
1122
  const llmInfo = metrics.summaryUsage ? `, summary_llm_in=${metrics.summaryUsage.input_tokens ?? "?"} out=${metrics.summaryUsage.output_tokens ?? "?"}` : "";
634
- return `[Compaction] reason=${metrics.reason} compressed=${metrics.compressedCount}->${metrics.retainedCount} msgs, tokens=${totalBefore}->${totalAfter} (ratio=${ratio})${llmInfo}`;
1123
+ const netInfo = `, net=${metrics.residentReductionTokens}`;
1124
+ const omittedTotal = (metrics.summaryExpandedMessages ?? 0) + (metrics.summaryOmittedMessages ?? 0);
1125
+ const capSuffix = metrics.summaryInputCapTokens !== void 0 ? `/${metrics.summaryInputCapTokens}` : "";
1126
+ const omittedSuffix = metrics.summaryOmittedMessages !== void 0 ? ` omitted=${metrics.summaryOmittedMessages}/${omittedTotal}` : "";
1127
+ const projectionInfo = metrics.summaryInputTokens !== void 0 ? `, summary_in=${metrics.summaryInputTokens}${capSuffix}${omittedSuffix}` : "";
1128
+ const planInfo = metrics.pendingMessageCount !== void 0 ? `, pending=${metrics.pendingMessageCount}${metrics.plannedCompressCount !== void 0 ? ` fold=${metrics.plannedCompressCount}/${metrics.pendingMessageCount}` : ""}` : "";
1129
+ return `[Compaction] reason=${metrics.reason} compressed=${metrics.compressedCount}->${metrics.retainedCount} msgs, tokens=${totalBefore}->${totalAfter} (ratio=${ratio})${llmInfo}${netInfo}${projectionInfo}${planInfo}`;
635
1130
  }
636
1131
  function computeSummarySourceMetadata(messagesWithIds, summarizedBeforeId) {
637
1132
  if (!summarizedBeforeId) return void 0;
@@ -743,11 +1238,11 @@ function fuzzyContextWindow(normalizedName) {
743
1238
  if (normalizedName.includes("gemini")) return 1048576;
744
1239
  if (normalizedName.includes("qwen3.6") || normalizedName.includes("qwen3p6")) return QWEN_3_6_CONTEXT_WINDOW;
745
1240
  if (normalizedName.includes("qwen3.7") || normalizedName.includes("qwen3p7")) return 262144;
746
- if (normalizedName.includes("minimax-m2") || normalizedName.includes("minimax_m2")) return 262144;
747
- if (normalizedName.includes("mistral-large-4")) {
748
- const rest = normalizedName.slice(
749
- normalizedName.indexOf("mistral-large-4") + "mistral-large-4".length
750
- );
1241
+ if (/minimax[-_ ]m2(?![\d.])/.test(normalizedName)) return 262144;
1242
+ const MISTRAL_LARGE_4 = /mistral[-_ ]large[-_ ]4/;
1243
+ const large4 = MISTRAL_LARGE_4.exec(normalizedName);
1244
+ if (large4) {
1245
+ const rest = normalizedName.slice(large4.index + large4[0].length);
751
1246
  if (rest === "" || /^[-:_@/\s]/.test(rest)) return 524288;
752
1247
  }
753
1248
  if (normalizedName.includes("mistral-vibe-cli") || normalizedName.includes("mistral-medium-3.5") || normalizedName.includes("mistral-medium-3-5") || normalizedName.includes("mistral-medium-latest") || normalizedName.includes("mistral-medium-2604") || normalizedName.includes("mistral-large-latest") || normalizedName.includes("mistral-large-2512") || normalizedName.includes("mistral-small-latest") || normalizedName.includes("mistral-small-2603") || normalizedName.includes("magistral-medium-latest") || normalizedName.includes("magistral-small-latest") || // 展示名(TUI 传 displayName 的路径;Mistral 不在 MODEL_LOOKUP_MAP,无法走精确表):
@@ -772,7 +1267,7 @@ function fuzzyContextWindow(normalizedName) {
772
1267
  if (normalizedName.includes("llama3") || normalizedName.includes("llama-3") || normalizedName.includes("gemma2") || normalizedName.includes("gemma-2") || normalizedName.includes("gemma")) {
773
1268
  return 8192;
774
1269
  }
775
- if (normalizedName.includes("llama2") || normalizedName.includes("llama-2") || normalizedName.includes("llama")) {
1270
+ if (/(^|[^a-z])llama/.test(normalizedName)) {
776
1271
  return 4096;
777
1272
  }
778
1273
  return void 0;
@@ -782,7 +1277,8 @@ var findCodexOAuthPinnedContextWindow = (modelName, provider) => {
782
1277
  if (isPlatformManagedProvider(provider, modelName)) return void 0;
783
1278
  return channelPinnedContextWindow(modelName.toLowerCase());
784
1279
  };
785
- var findModelContextWindow = (modelName, provider) => {
1280
+ var findModelContextWindow = (modelName, provider) => findModelContextWindowImpl(modelName, provider, false);
1281
+ var findModelContextWindowImpl = (modelName, provider, allowHyphenRetry) => {
786
1282
  if (!modelName) return void 0;
787
1283
  const onPlatformChannel = isPlatformManagedProvider(provider, modelName);
788
1284
  const normalizedName = modelName.toLowerCase();
@@ -834,8 +1330,19 @@ var findModelContextWindow = (modelName, provider) => {
834
1330
  if (pinned !== void 0) return pinned;
835
1331
  }
836
1332
  }
837
- return fuzzyContextWindow(normalizedName);
1333
+ const fuzzy = fuzzyContextWindow(normalizedName);
1334
+ if (fuzzy !== void 0) return fuzzy;
1335
+ if (!allowHyphenRetry) {
1336
+ const canonical = normalizeSeparators(modelName);
1337
+ if (canonical.toLowerCase() !== normalizedName) {
1338
+ return findModelContextWindowImpl(canonical, provider, true);
1339
+ }
1340
+ }
1341
+ return void 0;
838
1342
  };
1343
+ function normalizeSeparators(raw) {
1344
+ return raw.replace(/\s+/g, "-").replace(/(?<=[a-z0-9])_(?=[a-z0-9])/g, "-");
1345
+ }
839
1346
  var getModelContextWindow = (modelName, provider) => findModelContextWindow(modelName, provider) ?? DEFAULT_CONTEXT_WINDOW;
840
1347
  var getModelInfo = (modelName) => {
841
1348
  if (!modelName) return null;
@@ -844,18 +1351,28 @@ var getModelInfo = (modelName) => {
844
1351
  };
845
1352
 
846
1353
  export {
847
- DEFAULT_CONTEXT_WINDOW,
848
- findCodexOAuthPinnedContextWindow,
849
- findModelContextWindow,
850
- getModelContextWindow,
851
- getModelInfo,
852
- sha256Hex,
1354
+ readCacheReadInputTokens,
1355
+ readCacheReadInputTokensOrNull,
1356
+ readCacheCreationInputTokens,
1357
+ normalizeUsage,
853
1358
  serializeMessageContent,
854
1359
  resolveCompressionTriggerRatio,
855
1360
  truncateToolOutputForContext,
856
1361
  getMessageTokenCount,
857
1362
  resolveEffectiveCompactionBudgets,
858
1363
  planCompression,
1364
+ DEFAULT_CONTEXT_WINDOW,
1365
+ findCodexOAuthPinnedContextWindow,
1366
+ findModelContextWindow,
1367
+ getModelContextWindow,
1368
+ getModelInfo,
1369
+ createSummaryBudget,
1370
+ classifySummaryError,
1371
+ isTruncatedCompletion,
1372
+ summaryCompletionTokens,
1373
+ selectSummaryRoute,
1374
+ runSummaryWithContract,
1375
+ sha256Hex,
859
1376
  COMPACTION_SUMMARY_SCHEMA_VERSION,
860
1377
  COMPACTION_SUMMARY_SYSTEM_PROMPT,
861
1378
  buildBoundedCompactionRequest,