nolo-cli 0.213.0 → 0.220.0

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 (271) hide show
  1. package/README.md +3 -2
  2. package/{_executeModel-CUJLCFWR.js → _executeModel-BNEMFCAO.js} +125 -96
  3. package/{accountResolver-4LKIHEKL.js → accountResolver-QETKNC7T.js} +4 -4
  4. package/{action-DF5UYSJF.js → action-GDZDXPMB.js} +14 -13
  5. package/{addContentAction-WERAONNY.js → addContentAction-7RO4AMRI.js} +21 -20
  6. package/{addDialogAgentAction-7VI7YRML.js → addDialogAgentAction-EVYBGTXB.js} +26 -25
  7. package/{agentDeleteCommand-XJORXPGU.js → agentDeleteCommand-7QTQNFCO.js} +145 -137
  8. package/{agentEmailCommands-XTYYFR6Z.js → agentEmailCommands-I7SHOSD6.js} +146 -139
  9. package/{agentFavoriteCommands-EDK743YA.js → agentFavoriteCommands-7LOP3HUD.js} +11 -12
  10. package/{agentGrantCommands-RQWK2TEV.js → agentGrantCommands-L6O2HVJI.js} +9 -9
  11. package/{agentListCommands-OBLRBLHS.js → agentListCommands-GUGMORTK.js} +180 -103
  12. package/{agentMachineCommands-5FMT3OT5.js → agentMachineCommands-UMDKILU3.js} +75 -66
  13. package/{agentProviderCommands-Q5O33MED.js → agentProviderCommands-STI3DQ6A.js} +8 -8
  14. package/{agentPullCommand-6EM3URVK.js → agentPullCommand-KHV4EELF.js} +11 -11
  15. package/agentRecordCommands-YTAMTHOY.js +175 -0
  16. package/agentRunCommand-DBM6YNO6.js +207 -0
  17. package/{agentRunControl-TAMHJQSR.js → agentRunControl-MBG4U6SL.js} +40 -19
  18. package/{agentRuntimeLocal-SOO2OPJG.js → agentRuntimeLocal-TU4LA353.js} +55 -48
  19. package/{agentSlice-CHR6KOZN.js → agentSlice-DPG7Q7IA.js} +24 -23
  20. package/{appDeleteCommands-GUP6P5YE.js → appDeleteCommands-JWP3XPUA.js} +67 -58
  21. package/{appDeployCommands-MH2FX4O5.js → appDeployCommands-6E4TQCWI.js} +67 -58
  22. package/{appDeployStatusCommands-SUHN3HPJ.js → appDeployStatusCommands-ALU4SADG.js} +67 -58
  23. package/{appGetCommands-YWDEX6Z4.js → appGetCommands-JEY4L6L4.js} +67 -58
  24. package/{appListCommands-ZQVMLPAY.js → appListCommands-PCAVHU7M.js} +67 -58
  25. package/{authCommand-PWX2ZNUP.js → authCommand-CGRIIOOV.js} +37 -33
  26. package/{authCommands-HV3EAU3V.js → authCommands-55OGQGCR.js} +16 -12
  27. package/{builtinSkillRegistry-2QETTQPM.js → builtinSkillRegistry-BAE2LDXF.js} +11 -13
  28. package/{chromeCommands-REEAH4SX.js → chromeCommands-G5UDKVSV.js} +3 -3
  29. package/{chromeOpsCommands-DIVM2K3T.js → chromeOpsCommands-WAA45NCS.js} +23 -13
  30. package/{chunk-VNYYOX3V.js → chunk-262R3XNN.js} +157 -50
  31. package/chunk-2MCB7CD7.js +98 -0
  32. package/{chunk-CTPXME7U.js → chunk-2NPD3FTX.js} +30 -7
  33. package/{chunk-YB3YZK56.js → chunk-2WZXXAQD.js} +1 -67
  34. package/{chunk-HRMJUN5J.js → chunk-2X7WFDT6.js} +1 -1
  35. package/chunk-2YGBI2XB.js +30 -0
  36. package/{chunk-TY3TIUJK.js → chunk-324FWHUA.js} +85 -3
  37. package/{chunk-KFLT5KAD.js → chunk-3NNXR7EH.js} +20 -20
  38. package/{chunk-ZRSNONOB.js → chunk-3P54D2E4.js} +8 -3
  39. package/{chunk-7OCO4TDT.js → chunk-3U44JB3O.js} +1 -1
  40. package/{chunk-TX5EYMGT.js → chunk-44J7Z5AQ.js} +34 -258
  41. package/chunk-4D4QD7FT.js +201 -0
  42. package/chunk-4I2MXV5Q.js +275 -0
  43. package/{chunk-MYOH447Z.js → chunk-4JVNURX4.js} +1 -1
  44. package/{chunk-COFEN36Z.js → chunk-4ZGPHFLE.js} +3 -3
  45. package/{chunk-ZXOUUDCG.js → chunk-53MFERZ3.js} +3869 -362
  46. package/chunk-547ENH5T.js +226 -0
  47. package/{chunk-YDH3FDFQ.js → chunk-5FUN7EG4.js} +1 -1
  48. package/{chunk-6DWMYIUY.js → chunk-5WKDR7HS.js} +14 -9
  49. package/chunk-5ZUOVCKT.js +32 -0
  50. package/{chunk-T43B7LB2.js → chunk-62HXNQVV.js} +1 -1
  51. package/{chunk-ZC3CMUKU.js → chunk-6OVNSQHN.js} +84 -2
  52. package/{chunk-IXNGOHV5.js → chunk-6QHKRARD.js} +12 -153
  53. package/{chunk-4T2WNOY7.js → chunk-6RDBLXVQ.js} +28 -17
  54. package/{chunk-EYLGAEB4.js → chunk-6XRPBZRS.js} +134 -0
  55. package/{chunk-KIM6CLW5.js → chunk-7JGMNKKG.js} +57 -26
  56. package/{chunk-P5L7CXOC.js → chunk-7Z6EW7AH.js} +3 -2
  57. package/chunk-AGYPUBFW.js +686 -0
  58. package/{chunk-Y63ZSOR6.js → chunk-AL3TYDIF.js} +1 -1
  59. package/{chunk-NOKUNJON.js → chunk-ALAES342.js} +75 -94
  60. package/{chunk-4I7ERB7F.js → chunk-ATEKLSLR.js} +2 -2
  61. package/{chunk-CRHOO2ZR.js → chunk-AUAJTAFM.js} +8 -8
  62. package/{chunk-LLRPJECG.js → chunk-AWIL6EHN.js} +15 -157
  63. package/chunk-BIDSIRTS.js +307 -0
  64. package/chunk-BIWI5M4E.js +62 -0
  65. package/{chunk-4VJAC32I.js → chunk-BNMPUQW6.js} +3 -2
  66. package/{chunk-RLBNLZVC.js → chunk-BP5ZJ6B4.js} +1 -1
  67. package/{chunk-NBTY7YJF.js → chunk-BR3GT6MR.js} +1 -0
  68. package/{chunk-7RFNTILS.js → chunk-BUDVRYES.js} +2 -2
  69. package/{chunk-SVYO6AO7.js → chunk-BV3FLP2L.js} +41 -1
  70. package/{chunk-ZL5RAEEB.js → chunk-CBUZ6DKA.js} +3 -3
  71. package/{chunk-SM3NSZJV.js → chunk-CD3RU7XL.js} +36 -2
  72. package/chunk-CMMI3DAT.js +1621 -0
  73. package/{chunk-J2NHJ7WX.js → chunk-CYWNWA77.js} +6 -6
  74. package/{chunk-MOIJOHA5.js → chunk-D6YNCNM6.js} +35 -21
  75. package/{chunk-H2TJUNCH.js → chunk-DBUR22G5.js} +16 -16
  76. package/chunk-DEA37IUY.js +271 -0
  77. package/{chunk-O2TZF4AI.js → chunk-DGYCDA6W.js} +4 -4
  78. package/{chunk-YWSEPJ7C.js → chunk-DUUDXSLX.js} +21 -7
  79. package/{chunk-KFHREHUQ.js → chunk-DXWGFL2Z.js} +89 -1
  80. package/{chunk-H5HF7TJA.js → chunk-EEOOBRA7.js} +6 -6
  81. package/{chunk-Y6ORVLSS.js → chunk-EVGU5P4U.js} +1 -1
  82. package/chunk-EWQ3HGNZ.js +90 -0
  83. package/{chunk-6VLJ6YA7.js → chunk-F6Z6ZCUV.js} +9 -9
  84. package/{chunk-75XIDFBW.js → chunk-FJ23FZXF.js} +72 -28
  85. package/chunk-FJSNBZXR.js +142 -0
  86. package/{chunk-WRYQ35LQ.js → chunk-G7IUT2V3.js} +860 -57
  87. package/{chunk-PCLE46CE.js → chunk-GBWGPTA7.js} +2 -1
  88. package/{chunk-H7PPIYWP.js → chunk-GPOV42YM.js} +19 -19
  89. package/{chunk-W4S457LU.js → chunk-GUXZK7SE.js} +42 -6
  90. package/{chunk-QHPRUL4O.js → chunk-GV6PRJBU.js} +4 -4
  91. package/{chunk-YUA6OAH5.js → chunk-HBRDSQ3M.js} +2 -2
  92. package/{chunk-G7MLNNEX.js → chunk-HHFGE2WF.js} +7 -7
  93. package/{chunk-OQPKUBPB.js → chunk-HSSBDZLD.js} +19 -7
  94. package/{chunk-EHSZD5OI.js → chunk-HXER7YJF.js} +4 -4
  95. package/{chunk-TAKB25RM.js → chunk-HYLRQDEE.js} +6 -6
  96. package/{chunk-LOEO7LRC.js → chunk-ILHQ2AXT.js} +10 -8
  97. package/{chunk-BBJ22CLB.js → chunk-JJMR2EA3.js} +64 -34
  98. package/{chunk-G2BQWAVT.js → chunk-JLAMNSBC.js} +4 -4
  99. package/{chunk-RSHTSUEG.js → chunk-JUSHVFNF.js} +2133 -622
  100. package/{chunk-YJAFKXMU.js → chunk-KHVFJSVE.js} +54 -49
  101. package/{chunk-X7SDOJUM.js → chunk-KRI6N5QZ.js} +16 -16
  102. package/{chunk-7BT37FK3.js → chunk-L32W3PRP.js} +675 -128
  103. package/chunk-LKA64WH4.js +227 -0
  104. package/{chunk-HUBHAQK2.js → chunk-LMRRCEDE.js} +31 -31
  105. package/chunk-M4SFKP5L.js +675 -0
  106. package/{chunk-MDB67IWP.js → chunk-MSMHU36U.js} +12 -12
  107. package/{chunk-7Y4YTDQF.js → chunk-MXKWTPUM.js} +288 -166
  108. package/{chunk-WYDI6TGM.js → chunk-MXRUXMZ3.js} +94 -135
  109. package/{chunk-AZMYUSVF.js → chunk-N5Z2V73W.js} +1 -1
  110. package/{chunk-QG4AOSON.js → chunk-NHY322ZU.js} +154 -32
  111. package/{chunk-UHJGXRJ4.js → chunk-OBIC6EG7.js} +6 -6
  112. package/{chunk-GOO6G4PY.js → chunk-OBSEKCVK.js} +123 -70
  113. package/{chunk-WMTBPBMP.js → chunk-OG6MQOQG.js} +130 -60
  114. package/{chunk-XJWWBO34.js → chunk-OJKUU3LP.js} +5 -7
  115. package/{chunk-ALQ3657A.js → chunk-OOJNQK6V.js} +21 -1
  116. package/{chunk-NSAPDIN2.js → chunk-OWKNSIXL.js} +679 -74
  117. package/{chunk-6XIE5ZGI.js → chunk-PDCV7P5W.js} +1 -1
  118. package/{chunk-A7TFUNZO.js → chunk-PPJYZRSQ.js} +6 -2
  119. package/{chunk-F6UUQOG6.js → chunk-Q3IVPFVO.js} +4 -4
  120. package/{chunk-VO4WSAVP.js → chunk-QBZCGP34.js} +3 -3
  121. package/chunk-QCB42576.js +13 -0
  122. package/chunk-QHEN7NZ7.js +46 -0
  123. package/{chunk-3UKL3HPD.js → chunk-QJTZ76CP.js} +32 -84
  124. package/{chunk-V5Y3R6BT.js → chunk-QRGDJA4B.js} +215 -212
  125. package/{chunk-4KB6WQUL.js → chunk-QYB23WUH.js} +1 -1
  126. package/{chunk-ZNWI6OVT.js → chunk-R44TU3MZ.js} +85 -11
  127. package/{chunk-PYRUW7XN.js → chunk-R6Z5S5GA.js} +139 -57
  128. package/{chunk-VL5KOY2C.js → chunk-R7XWZDOH.js} +125 -29
  129. package/{chunk-R5O4QAWG.js → chunk-RBPUNSG5.js} +11 -77
  130. package/{chunk-NJLL224W.js → chunk-RG2DGNL6.js} +3 -3
  131. package/{chunk-C6KNNXWU.js → chunk-RGQ4UUWZ.js} +25 -2
  132. package/{chunk-TCZHTTUU.js → chunk-RTHFJZ6M.js} +11 -11
  133. package/{chunk-RZOV7OMV.js → chunk-RYOLWYBK.js} +146 -200
  134. package/{chunk-OWYYDMGJ.js → chunk-S2NTVGA2.js} +4 -2
  135. package/{chunk-XHQC4PXX.js → chunk-S5NA3C52.js} +488 -226
  136. package/{secretCommands-LXDWOLZ6.js → chunk-S6FDXXZV.js} +190 -15
  137. package/chunk-S6K5F3KP.js +99 -0
  138. package/{chunk-INN4LTAJ.js → chunk-SRCCSTIM.js} +8 -8
  139. package/{chunk-JY5NGFFH.js → chunk-SYTHYBMI.js} +5 -5
  140. package/{chunk-UYD5HQ6T.js → chunk-SZVMASJ2.js} +3300 -1396
  141. package/{chunk-FUGMREBO.js → chunk-TGNIKIHR.js} +3 -3
  142. package/{chunk-HPFCI4SK.js → chunk-TI2EPRHE.js} +4 -4
  143. package/chunk-TLE77UJ5.js +230 -0
  144. package/chunk-TSPMLCWI.js +364 -0
  145. package/{chunk-YGILMZ7N.js → chunk-TUSTONB3.js} +1 -1
  146. package/{chunk-4VNS5WPM.js → chunk-U67V476Y.js} +1 -8
  147. package/{chunk-F7CI2ZC5.js → chunk-UAIHKQIA.js} +2 -1
  148. package/{chunk-WPORQFYN.js → chunk-UVLYNWIE.js} +2 -2
  149. package/{chunk-H4UOTUOX.js → chunk-VMJVAJ6W.js} +152 -19
  150. package/{chunk-KC4XDTT3.js → chunk-VS276URX.js} +4 -4
  151. package/{chunk-YTF4WH7J.js → chunk-WWTSEBDF.js} +1 -1
  152. package/{chunk-E2BESSAW.js → chunk-X4O7FJF5.js} +2 -0
  153. package/{chunk-RPQXPZZF.js → chunk-XSW4EXQV.js} +976 -17
  154. package/{chunk-7QTZCMKL.js → chunk-XTETTSKN.js} +3036 -2468
  155. package/{chunk-J5JTMQIA.js → chunk-YFLVRVYK.js} +1 -1
  156. package/chunk-YKY4OVOX.js +1141 -0
  157. package/{chunk-MMA3LZ3W.js → chunk-YNIYE47Z.js} +1 -1
  158. package/chunk-YZMNK53S.js +68 -0
  159. package/{chunk-FY7F4Q6X.js → chunk-Z4PCXPUE.js} +2 -2
  160. package/{chunk-INUFILG6.js → chunk-ZH3KXFHS.js} +11 -3
  161. package/chunk-ZOHO6MOF.js +376 -0
  162. package/{cliAgentConfigHelpers-WJBZQTLW.js → cliAgentConfigHelpers-BTRHMPW2.js} +18 -19
  163. package/{cliAuthorityBrokerClient-PM3U6Q6J.js → cliAuthorityBrokerClient-XHH7MH2P.js} +1 -1
  164. package/{cliAuthorityStoreDriver-TKLXNNTG.js → cliAuthorityStoreDriver-6FE3BJNB.js} +1 -1
  165. package/{cliEnvHelpers-BVYTMUPJ.js → cliEnvHelpers-CNMP3RDX.js} +3 -3
  166. package/{cliExecutor-BWBF2MTI.js → cliExecutor-K6FDZTQ2.js} +4 -2
  167. package/cliLocalAgentRecordReader-M3F76NIP.js +90 -0
  168. package/{commandRegistry-W63CYRZJ.js → commandRegistry-T3UBK6OA.js} +105 -97
  169. package/{contentThunks-U7PL5MQD.js → contentThunks-YEPZAHXU.js} +53 -48
  170. package/{cooldownCommands-TIGUHXTD.js → cooldownCommands-YB5H5BBK.js} +5 -4
  171. package/{createAgentAutomationAction-OLBQDD6R.js → createAgentAutomationAction-TBIIO5WT.js} +51 -48
  172. package/{createDialogAction-SVH6B3SB.js → createDialogAction-KBKMYFTQ.js} +52 -53
  173. package/{createPageAction-F4DIWZ2Z.js → createPageAction-3FGAPLJO.js} +56 -53
  174. package/{cursorProvider-YGGNMVWX.js → cursorProvider-2RACMEMF.js} +1 -1
  175. package/{db-HUCI5R4G.js → db-M7FU2GNK.js} +10 -7
  176. package/{dbSlice-BVH2YZPQ.js → dbSlice-XRUZOGSU.js} +20 -19
  177. package/{deleteFile-5YOEKV4U.js → deleteFile-6URDHYRB.js} +12 -12
  178. package/{desktopFolderProjects-SFY5EZS3.js → desktopFolderProjects-4POAMVJN.js} +2 -2
  179. package/{dialogCommands-KHIEPY3M.js → dialogCommands-NRLCOPJR.js} +71 -64
  180. package/dialogNotifyCommand-SHGPCU22.js +36 -0
  181. package/{dialogSlice-ZCTDV2PZ.js → dialogSlice-DP2WTMNO.js} +48 -45
  182. package/{dialogUsageCommand-7KCPYGHG.js → dialogUsageCommand-W2WCSGKF.js} +11 -10
  183. package/{docCreateCommands-DPMZI7G5.js → docCreateCommands-YJRDA3RX.js} +66 -59
  184. package/{docDeleteCommands-IRQQLUBT.js → docDeleteCommands-A5QIHZNF.js} +69 -62
  185. package/{docReadCommands-LK37XH6L.js → docReadCommands-CF2LTMYH.js} +66 -59
  186. package/{docStore-V2KECILA.js → docStore-NDY3K3PK.js} +25 -24
  187. package/{docUpdateCommands-O6T3HJHH.js → docUpdateCommands-QRKV4ZXE.js} +69 -62
  188. package/{fetchMessages-NR4KNQLO.js → fetchMessages-TQEUZD7H.js} +8 -7
  189. package/{getPricing-2MNMXEVG.js → getPricing-LF5C4XSI.js} +7 -7
  190. package/{handleSendMessageAction-2PE25WM3.js → handleSendMessageAction-IUGVVJ43.js} +206 -314
  191. package/{hostCredentialCreate-S233UMAP.js → hostCredentialCreate-X2ZFRXDR.js} +132 -124
  192. package/index.js +65 -27
  193. package/{keys-BEGDOTRL.js → keys-RWF7UCB4.js} +5 -4
  194. package/legacyMigration-TF4SYJCZ.js +19 -0
  195. package/{lib-5KKIBFIT.js → lib-OT5OTXRU.js} +7087 -6664
  196. package/{localDialogRead-7NNDVVF7.js → localDialogRead-CCOCVGAP.js} +3 -3
  197. package/{localFirstLog-DHNOY2NA.js → localFirstLog-OIETGK66.js} +1 -1
  198. package/localRecall-BDYKXB46.js +17 -0
  199. package/{localRuntimeAdapter-KY6WXNBR.js → localRuntimeAdapter-KAG3T4LF.js} +138 -130
  200. package/{localRuntimeAuthority-OYH4AE4G.js → localRuntimeAuthority-IBJAT62G.js} +1 -1
  201. package/{localRuntimeDb-VBIMCWUC.js → localRuntimeDb-N7KHDXS2.js} +2 -2
  202. package/{machineCommands-Q6HA3IXF.js → machineCommands-6NIQJE2A.js} +143 -135
  203. package/{machineInfo-UKPTZO5Y.js → machineInfo-LWHTEBHJ.js} +1 -1
  204. package/machineWsRunDispatch-RA5NOSGG.js +190 -0
  205. package/{memberThunks-7EDJADWU.js → memberThunks-7Y3OYSJQ.js} +30 -29
  206. package/{memoryCommands-ASCE5STX.js → memoryCommands-BC6REPQB.js} +7 -7
  207. package/models-H5NNZRLH.js +9 -0
  208. package/{oauthTokenStore-OEERZFUC.js → oauthTokenStore-RUYNYALS.js} +1 -1
  209. package/{offlineMarxistsAgentCommand-2QTHJCHV.js → offlineMarxistsAgentCommand-XVXUE6G5.js} +6 -6
  210. package/overlay-BBQZXGYI.js +13 -0
  211. package/package.json +2 -2
  212. package/{pdf-U6KSUEZZ.js → pdf-KE3QI2V7.js} +1 -1
  213. package/{processSpawn-ZU5QFM43.js → processSpawn-6GEO77KV.js} +1 -1
  214. package/{profileConfig-KN3N2BLF.js → profileConfig-KOWK4HOG.js} +1 -1
  215. package/{projectArchive-DRTDIMEV.js → projectArchive-OIUP63MV.js} +59 -56
  216. package/{providerPresetApply-YXGV6NXB.js → providerPresetApply-WHAMP2D5.js} +20 -13
  217. package/{providerRegistry-S6UL6UNA.js → providerRegistry-ZI2KORJ7.js} +11 -11
  218. package/{read-4V2RMG7N.js → read-TYMBGEXO.js} +13 -13
  219. package/{readDocTool-BH6ATGQO.js → readDocTool-SKQVHBLO.js} +2 -2
  220. package/{readlineWorkspace-2W4WRCOU.js → readlineWorkspace-ZGC4KSXG.js} +7760 -6499
  221. package/{removeDialogAgentAction-LYAZGNKW.js → removeDialogAgentAction-F5QE2O2B.js} +29 -28
  222. package/{runAgentClientLoop-J2VQBS2Z.js → runAgentClientLoop-NKUW2DSJ.js} +94 -88
  223. package/{runtimeDoctorCommands-QAI3MBKQ.js → runtimeDoctorCommands-RRKPBGVO.js} +19 -19
  224. package/{runtimeModeArgs-2Y7BALTO.js → runtimeModeArgs-X7DL7PUN.js} +1 -1
  225. package/secretCommands-KZWBZIYS.js +24 -0
  226. package/{setDialogExtraReferencesAction-OCRPGPYH.js → setDialogExtraReferencesAction-72L27ERM.js} +25 -24
  227. package/{setPrimaryDialogAgentAction-HFJDQIBU.js → setPrimaryDialogAgentAction-GJJDUSGJ.js} +29 -28
  228. package/{settingThunks-RAMHMTGM.js → settingThunks-ZRGWVGZD.js} +99 -90
  229. package/{skillDiscovery-XKHROSH2.js → skillDiscovery-I37M5KJC.js} +4 -4
  230. package/{skillSummaryMarker-42HKSXYY.js → skillSummaryMarker-62UW7HI7.js} +1 -1
  231. package/{slateToRenderMarkdown-Y5IYN73U.js → slateToRenderMarkdown-R3X74MCX.js} +1 -1
  232. package/{slateUtils-NGV2NMKM.js → slateUtils-ESQAJ6RN.js} +1 -1
  233. package/{spaceCommands-KVJZVKVO.js → spaceCommands-MEH3HJBC.js} +66 -57
  234. package/store-Z53ICFL3.js +48 -0
  235. package/{streamAgentChatTurn-GHBMJJ6S.js → streamAgentChatTurn-FJTUUXHJ.js} +886 -668
  236. package/{switchDialogAgentAction-EBRMW3RA.js → switchDialogAgentAction-IIJBPND3.js} +26 -25
  237. package/{tableCommands-MP6VFSVT.js → tableCommands-FTAOCBTX.js} +13 -13
  238. package/tombstones-FQQMEDOW.js +32 -0
  239. package/{toolApiClient-HGNO53TC.js → toolApiClient-OGQEBQVX.js} +4 -4
  240. package/{tools-EWKCPKMS.js → tools-ZXHIAOSP.js} +82 -81
  241. package/tuiRestart-2IL37YIB.js +41 -0
  242. package/tuiSummaryLlmCaller-W2QN4VAC.js +44 -0
  243. package/{updateCommands-ZQYU6SCI.js → updateCommands-CPATDG6J.js} +11 -7
  244. package/{updateDialogTitleAction-5GGMBTDF.js → updateDialogTitleAction-JMKLKL4P.js} +54 -51
  245. package/{usageCommand-F4IPVMIZ.js → usageCommand-2BF74MKF.js} +11 -10
  246. package/{usageRebuildCommand-HAW2AD5N.js → usageRebuildCommand-UHB55BQM.js} +12 -11
  247. package/userDataMerge-HT2ZVHBJ.js +13 -0
  248. package/{windowsSelfUpdate-257DV2T6.js → windowsSelfUpdate-ZFD6J5HF.js} +3 -3
  249. package/{workloadLifecycle-4C42SVBD.js → workloadLifecycle-HFJIN5IZ.js} +4 -4
  250. package/agentRecordCommands-ZQ7SVYGG.js +0 -167
  251. package/agentRunCommand-WS7IGO2W.js +0 -196
  252. package/chunk-3CGG2PAL.js +0 -594
  253. package/chunk-5MQRBSMW.js +0 -862
  254. package/chunk-5XBUWM6I.js +0 -89
  255. package/chunk-CJEIOP3E.js +0 -0
  256. package/chunk-EHGEOAHI.js +0 -636
  257. package/chunk-FW6YHHLI.js +0 -842
  258. package/chunk-GPVRUGGY.js +0 -115
  259. package/chunk-HSVBJRF4.js +0 -339
  260. package/chunk-LEC5ALIN.js +0 -91
  261. package/chunk-WACI5I6V.js +0 -147
  262. package/chunk-WJZOQR2J.js +0 -151
  263. package/chunk-ZCWRMUWT.js +0 -89
  264. package/dist-M676ULYG.js +0 -7314
  265. package/machineWsRunDispatch-WWJQ6WR3.js +0 -182
  266. package/models-PJBE6JDV.js +0 -9
  267. package/tuiSummaryLlmCaller-ALQYUUWB.js +0 -189
  268. package/{chunk-AGP3YSEC.js → chunk-4N6G2CKP.js} +3 -3
  269. package/{chunk-BLVSFYQ3.js → chunk-LISC7BD4.js} +3 -3
  270. package/{chunk-2QHFH3DR.js → chunk-USGHJSGO.js} +3 -3
  271. package/{chunk-AETZ7AD6.js → chunk-W6RFEDN4.js} +3 -3
@@ -1,16 +1,32 @@
1
1
  import {
2
- ALL_MODELS
3
- } from "./chunk-T43B7LB2.js";
2
+ normalizeTimingMs
3
+ } from "./chunk-H57T64RA.js";
4
+ import {
5
+ isAbortError
6
+ } from "./chunk-7DPNBQSV.js";
4
7
  import {
5
8
  estimateTokenCount
6
9
  } from "./chunk-PSCNXBYA.js";
10
+ import {
11
+ asTrimmedNonEmptyStringArray
12
+ } from "./chunk-I42VC5KR.js";
13
+ import {
14
+ ALL_MODELS
15
+ } from "./chunk-62HXNQVV.js";
7
16
  import {
8
17
  MODEL_LOOKUP_MAP
9
- } from "./chunk-SM3NSZJV.js";
18
+ } from "./chunk-CD3RU7XL.js";
19
+ import {
20
+ asOptionalFiniteNumber
21
+ } from "./chunk-WWC7I6TA.js";
10
22
  import {
23
+ asOptionalTrimmedString
24
+ } from "./chunk-G3SUCT4W.js";
25
+ import {
26
+ PLATFORM_HOSTED_DEEPSEEK_FLASH_MODEL,
11
27
  isPlatformManagedProvider,
12
28
  resolvePlatformEffectiveModel
13
- } from "./chunk-GOO6G4PY.js";
29
+ } from "./chunk-OBSEKCVK.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;
@@ -650,6 +1145,35 @@ function computeSummarySourceMetadata(messagesWithIds, summarizedBeforeId) {
650
1145
  schemaVersion: COMPACTION_SUMMARY_SCHEMA_VERSION
651
1146
  };
652
1147
  }
1148
+ function buildSummarySourceDiagnostics(messages, anchor) {
1149
+ const end = anchor ? messages.findIndex((message) => message.id === anchor) : -1;
1150
+ if (end < 0) return [];
1151
+ const width = Math.max(1, Math.ceil((end + 1) / 64));
1152
+ const sorted = (value) => {
1153
+ if (Array.isArray(value)) return value.map(sorted);
1154
+ if (value && typeof value === "object") return Object.fromEntries(
1155
+ Object.entries(value).sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0).map(([key, child]) => [key, sorted(child)])
1156
+ );
1157
+ return value;
1158
+ };
1159
+ const rows = [];
1160
+ for (let start = 0; start <= end; start += width) {
1161
+ const group = messages.slice(start, Math.min(end + 1, start + width));
1162
+ const content = group.map((message) => ({
1163
+ role: message.role,
1164
+ content: message.content ?? "",
1165
+ ...Array.isArray(message.tool_calls) ? { tool_calls: message.tool_calls } : {}
1166
+ }));
1167
+ rows.push({
1168
+ start,
1169
+ count: group.length,
1170
+ idHash: sha256Hex(JSON.stringify(group.map((message) => message.id ?? null))).slice(0, 16),
1171
+ messageHash: sha256Hex(JSON.stringify(content)).slice(0, 16),
1172
+ canonicalHash: sha256Hex(JSON.stringify(sorted(content))).slice(0, 16)
1173
+ });
1174
+ }
1175
+ return rows;
1176
+ }
653
1177
 
654
1178
  // packages/ai/llm/getModelContextWindow.ts
655
1179
  var DEFAULT_CONTEXT_WINDOW = 256e3;
@@ -743,11 +1267,11 @@ function fuzzyContextWindow(normalizedName) {
743
1267
  if (normalizedName.includes("gemini")) return 1048576;
744
1268
  if (normalizedName.includes("qwen3.6") || normalizedName.includes("qwen3p6")) return QWEN_3_6_CONTEXT_WINDOW;
745
1269
  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
- );
1270
+ if (/minimax[-_ ]m2(?![\d.])/.test(normalizedName)) return 262144;
1271
+ const MISTRAL_LARGE_4 = /mistral[-_ ]large[-_ ]4/;
1272
+ const large4 = MISTRAL_LARGE_4.exec(normalizedName);
1273
+ if (large4) {
1274
+ const rest = normalizedName.slice(large4.index + large4[0].length);
751
1275
  if (rest === "" || /^[-:_@/\s]/.test(rest)) return 524288;
752
1276
  }
753
1277
  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 +1296,7 @@ function fuzzyContextWindow(normalizedName) {
772
1296
  if (normalizedName.includes("llama3") || normalizedName.includes("llama-3") || normalizedName.includes("gemma2") || normalizedName.includes("gemma-2") || normalizedName.includes("gemma")) {
773
1297
  return 8192;
774
1298
  }
775
- if (normalizedName.includes("llama2") || normalizedName.includes("llama-2") || normalizedName.includes("llama")) {
1299
+ if (/(^|[^a-z])llama/.test(normalizedName)) {
776
1300
  return 4096;
777
1301
  }
778
1302
  return void 0;
@@ -782,7 +1306,8 @@ var findCodexOAuthPinnedContextWindow = (modelName, provider) => {
782
1306
  if (isPlatformManagedProvider(provider, modelName)) return void 0;
783
1307
  return channelPinnedContextWindow(modelName.toLowerCase());
784
1308
  };
785
- var findModelContextWindow = (modelName, provider) => {
1309
+ var findModelContextWindow = (modelName, provider) => findModelContextWindowImpl(modelName, provider, false);
1310
+ var findModelContextWindowImpl = (modelName, provider, allowHyphenRetry) => {
786
1311
  if (!modelName) return void 0;
787
1312
  const onPlatformChannel = isPlatformManagedProvider(provider, modelName);
788
1313
  const normalizedName = modelName.toLowerCase();
@@ -834,8 +1359,19 @@ var findModelContextWindow = (modelName, provider) => {
834
1359
  if (pinned !== void 0) return pinned;
835
1360
  }
836
1361
  }
837
- return fuzzyContextWindow(normalizedName);
1362
+ const fuzzy = fuzzyContextWindow(normalizedName);
1363
+ if (fuzzy !== void 0) return fuzzy;
1364
+ if (!allowHyphenRetry) {
1365
+ const canonical = normalizeSeparators(modelName);
1366
+ if (canonical.toLowerCase() !== normalizedName) {
1367
+ return findModelContextWindowImpl(canonical, provider, true);
1368
+ }
1369
+ }
1370
+ return void 0;
838
1371
  };
1372
+ function normalizeSeparators(raw) {
1373
+ return raw.replace(/\s+/g, "-").replace(/(?<=[a-z0-9])_(?=[a-z0-9])/g, "-");
1374
+ }
839
1375
  var getModelContextWindow = (modelName, provider) => findModelContextWindow(modelName, provider) ?? DEFAULT_CONTEXT_WINDOW;
840
1376
  var getModelInfo = (modelName) => {
841
1377
  if (!modelName) return null;
@@ -849,17 +1385,28 @@ export {
849
1385
  findModelContextWindow,
850
1386
  getModelContextWindow,
851
1387
  getModelInfo,
852
- sha256Hex,
1388
+ readCacheReadInputTokens,
1389
+ readCacheReadInputTokensOrNull,
1390
+ readCacheCreationInputTokens,
1391
+ normalizeUsage,
853
1392
  serializeMessageContent,
854
1393
  resolveCompressionTriggerRatio,
855
1394
  truncateToolOutputForContext,
856
1395
  getMessageTokenCount,
857
1396
  resolveEffectiveCompactionBudgets,
858
1397
  planCompression,
1398
+ createSummaryBudget,
1399
+ classifySummaryError,
1400
+ isTruncatedCompletion,
1401
+ summaryCompletionTokens,
1402
+ selectSummaryRoute,
1403
+ runSummaryWithContract,
1404
+ sha256Hex,
859
1405
  COMPACTION_SUMMARY_SCHEMA_VERSION,
860
1406
  COMPACTION_SUMMARY_SYSTEM_PROMPT,
861
1407
  buildBoundedCompactionRequest,
862
1408
  buildCompactionMetricsFromPlan,
863
1409
  formatCompactionMetricsLog,
864
- computeSummarySourceMetadata
1410
+ computeSummarySourceMetadata,
1411
+ buildSummarySourceDiagnostics
865
1412
  };