nolo-cli 0.8.0-alpha.24 → 0.8.0-alpha.26

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 (113) hide show
  1. package/{_executeModel-2ZAPHFOX.js → _executeModel-HM7KOYQX.js} +48 -50
  2. package/{action-QM2ONPYZ.js → action-UAHWPMZB.js} +7 -8
  3. package/{addContentAction-UXY3GM53.js → addContentAction-PFIP76LT.js} +6 -8
  4. package/{addDialogAgentAction-MUBYOG65.js → addDialogAgentAction-LWDAIDEU.js} +8 -9
  5. package/{agentDeleteCommand-5TFSII4Z.js → agentDeleteCommand-M6KIV6ZZ.js} +35 -26
  6. package/{agentEmailCommands-XMXWGUMZ.js → agentEmailCommands-X24B32EE.js} +60 -61
  7. package/{agentListCommands-OWEFQEY4.js → agentListCommands-3TQWUC4W.js} +34 -26
  8. package/{agentMachineCommands-DGHYBBFC.js → agentMachineCommands-AHOFELNN.js} +37 -27
  9. package/{agentRecordCommands-I433EE5F.js → agentRecordCommands-GCX4YO5J.js} +53 -54
  10. package/{agentRunCommand-UQSX3IGW.js → agentRunCommand-6Z73OBXZ.js} +56 -59
  11. package/{agentRuntimeLocal-73SVOC5U.js → agentRuntimeLocal-6Q4CEFXY.js} +26 -13
  12. package/{agentSlice-JQCS4LR3.js → agentSlice-73367RQ3.js} +7 -8
  13. package/{authCommand-B6P2XYLN.js → authCommand-ELPMOABY.js} +13 -13
  14. package/{authCommands-4YKA4GTU.js → authCommands-PUQRVHHW.js} +5 -5
  15. package/{chunk-DS3VC4EA.js → chunk-2H4I6KR4.js} +5 -5
  16. package/{chunk-AFON4QUU.js → chunk-3QKO4EHV.js} +3 -3
  17. package/{chunk-LE6JAIXE.js → chunk-3WSPFJ7B.js} +6 -6
  18. package/{chunk-QWM7YWVT.js → chunk-4GBNEA5B.js} +1 -1
  19. package/{chunk-PXZAAB4L.js → chunk-4LG74DRG.js} +4 -4
  20. package/{chunk-IYMGQ3TN.js → chunk-66DXKPRS.js} +2 -2
  21. package/{chunk-L76QNLGU.js → chunk-6L2PIG7I.js} +1 -1
  22. package/{chunk-FZ2G3I4B.js → chunk-6PXKSN2M.js} +2 -2
  23. package/{chunk-GAKEBQD6.js → chunk-D6OQHXVG.js} +11 -7
  24. package/{chunk-GROGNZOA.js → chunk-DXLC3MIQ.js} +85 -2326
  25. package/{chunk-Q7S2ORXX.js → chunk-EUELM55L.js} +10 -10
  26. package/{chunk-BT57QC5K.js → chunk-GK7YFA5J.js} +14 -14
  27. package/chunk-GVQT3FIB.js +2286 -0
  28. package/{chunk-LRKEOCWY.js → chunk-HUHOMATY.js} +17 -17
  29. package/{chunk-6QFNUK2G.js → chunk-I2HCZWJU.js} +1 -1
  30. package/{chunk-WVS3GX3B.js → chunk-IB65MC33.js} +2 -2
  31. package/{chunk-C4DZRHFJ.js → chunk-IG2EZS3N.js} +64 -17
  32. package/{chunk-Z3NEXVYE.js → chunk-IKXL2HZ3.js} +38 -1
  33. package/{chunk-2CVZSC5L.js → chunk-IVAOVLM7.js} +1 -1
  34. package/{chunk-L3KWEH3V.js → chunk-KPFGD3YA.js} +43 -12
  35. package/{chunk-AVMKZHBC.js → chunk-L53FGHA4.js} +3 -2
  36. package/{chunk-WKQGZJVI.js → chunk-LFETMU66.js} +8 -8
  37. package/{chunk-AISLHYDB.js → chunk-LWYCA4ZT.js} +306 -42
  38. package/{chunk-SBVUZC2E.js → chunk-MMCDCZM4.js} +6 -6
  39. package/{chunk-YOCHZD7D.js → chunk-NCGFB7NN.js} +5 -3
  40. package/{chunk-C4FTUXVF.js → chunk-QLUFR47U.js} +11 -1
  41. package/{chunk-IPA2WQGY.js → chunk-QXZ4YDXW.js} +178 -75
  42. package/{chunk-RQPZX6KP.js → chunk-S37OTGU7.js} +2 -2
  43. package/{chunk-FVVST32H.js → chunk-SCBYSC74.js} +1 -1
  44. package/{chunk-WM7P5OWZ.js → chunk-TUIH56DJ.js} +87 -53
  45. package/{chunk-UBSKX3LP.js → chunk-UZZCXRHF.js} +6 -6
  46. package/{chunk-WTBWWBSF.js → chunk-VAHPL4CG.js} +63 -40
  47. package/{chunk-BQECZ3Q4.js → chunk-VDS3NXE5.js} +219 -46
  48. package/{chunk-G7KM6BBZ.js → chunk-VNGCTQ32.js} +1 -1
  49. package/{chunk-BKGNXJAM.js → chunk-WKWEV6K4.js} +1 -1
  50. package/{chunk-JTINRTBT.js → chunk-WPHL6ALY.js} +1 -1
  51. package/{chunk-KTHLAJEY.js → chunk-WZF7M6GX.js} +1 -1
  52. package/{chunk-LTH6AVG7.js → chunk-XDXO65DS.js} +3 -3
  53. package/{chunk-BFDWXLFF.js → chunk-XGMCGPEA.js} +64 -5
  54. package/{chunk-VBKJTOAW.js → chunk-XHQWJUW4.js} +2 -2
  55. package/{chunk-VUEXKW6U.js → chunk-XIZIRGXB.js} +15 -15
  56. package/{chunk-P2SPC3FT.js → chunk-XW6CFB3M.js} +27 -25
  57. package/{chunk-3KGTFX3T.js → chunk-ZR4VHQ5D.js} +13 -1
  58. package/{createAgentAutomationAction-GXZNLJZK.js → createAgentAutomationAction-MYQ7Z7VA.js} +22 -25
  59. package/{createDialogAction-KLW42ZGF.js → createDialogAction-PIV7Z7ZQ.js} +24 -27
  60. package/{createPageAction-IBJHE6MH.js → createPageAction-7ZAEDSUY.js} +24 -27
  61. package/{dbSlice-R5EJKZBW.js → dbSlice-V4H2JFNB.js} +5 -6
  62. package/{deleteFile-WPWVZE4B.js → deleteFile-M7UNIUOO.js} +3 -3
  63. package/{dialogCommands-7O5PUZRU.js → dialogCommands-UMT7AOOR.js} +30 -21
  64. package/{dialogSlice-GGV7PF53.js → dialogSlice-4PYFGN7J.js} +22 -25
  65. package/{docCreateCommands-7ZO2NQQF.js → docCreateCommands-MAZSFQQ5.js} +33 -24
  66. package/{docDeleteCommands-YKIXZYBR.js → docDeleteCommands-DOTLD7HA.js} +33 -25
  67. package/{docReadCommands-5UDONBUL.js → docReadCommands-PH255AKZ.js} +33 -24
  68. package/{docStore-VDWTATFH.js → docStore-P7PG4YDJ.js} +21 -24
  69. package/{docUpdateCommands-EPZIIQMY.js → docUpdateCommands-RLRID2K7.js} +33 -24
  70. package/fetchMessages-KTNM7QAR.js +1 -1
  71. package/getPricing-6TOZXPAU.js +1 -1
  72. package/{handleSendMessageAction-MMATC5V5.js → handleSendMessageAction-BHUXTQHK.js} +27 -30
  73. package/index.js +62 -62
  74. package/{localDialogRead-YSKFFRTT.js → localDialogRead-2VRI24F4.js} +1 -1
  75. package/{machineCommands-PTHPKSIZ.js → machineCommands-GD46ZUZC.js} +63 -62
  76. package/{machineWsRunDispatch-M5L2NVWJ.js → machineWsRunDispatch-5SF5RE7E.js} +52 -53
  77. package/{models-H524GH3U.js → models-LSCRJJ6P.js} +1 -2
  78. package/package.json +1 -1
  79. package/{read-5ZMY7FKP.js → read-2MIMRBZ2.js} +3 -3
  80. package/{readDocTool-2NXDK32S.js → readDocTool-QHVGQHUJ.js} +1 -1
  81. package/{readlineWorkspace-4NXMEOHP.js → readlineWorkspace-IKXTXTYB.js} +115 -100
  82. package/{removeDialogAgentAction-KOLQ2R5W.js → removeDialogAgentAction-7GO2PRVQ.js} +12 -13
  83. package/{runAgentClientLoop-FGUYNGSA.js → runAgentClientLoop-CRIQXO42.js} +45 -48
  84. package/{setDialogExtraReferencesAction-OMTEO7X6.js → setDialogExtraReferencesAction-ZIDAVJSZ.js} +8 -9
  85. package/{setPrimaryDialogAgentAction-DOCIS6V4.js → setPrimaryDialogAgentAction-LK35C2D7.js} +12 -13
  86. package/{settingSlice-UWZJYDOA.js → settingSlice-PRRC6IJ7.js} +6 -7
  87. package/{skillDiscovery-UGSQGX2U.js → skillDiscovery-ZYHSX7VD.js} +3 -3
  88. package/{spaceCommands-S3EB6TOS.js → spaceCommands-XE4PS24W.js} +35 -28
  89. package/{spaceSlice-RG2GSV7K.js → spaceSlice-NYR6BQDL.js} +20 -23
  90. package/{streamAgentChatTurn-X576C23M.js → streamAgentChatTurn-CYEFWT4D.js} +95 -88
  91. package/{toolApiClient-C7P7YSE4.js → toolApiClient-QI3YBNWB.js} +2 -2
  92. package/{tools-HURZ2N4O.js → tools-4YAV2HQH.js} +32 -35
  93. package/{tuiSummaryLlmCaller-DG2LBTBX.js → tuiSummaryLlmCaller-TXLF4MEI.js} +3 -3
  94. package/{updateDialogTitleAction-62LVIAUZ.js → updateDialogTitleAction-FEEBVBNP.js} +27 -29
  95. package/chunk-5MMAK75Q.js +0 -15
  96. package/chunk-AZPCASRE.js +0 -36
  97. package/chunk-IOQIOZNI.js +0 -42
  98. package/chunk-UAD2WT54.js +0 -64
  99. package/{agentPullCommand-N6UWRTVL.js → agentPullCommand-LHFBA5EI.js} +6 -6
  100. package/{chunk-JK7VW2FN.js → chunk-5MIDPSSK.js} +3 -3
  101. package/{chunk-VC6OZXO5.js → chunk-6WWHKODG.js} +4 -4
  102. package/{chunk-BT37DVDA.js → chunk-7VKWMOSI.js} +9 -9
  103. package/{chunk-3QAF2LTL.js → chunk-DZ3XJVET.js} +3 -3
  104. package/{chunk-5CS33IBL.js → chunk-PDL2AV3E.js} +3 -3
  105. package/{chunk-5MMZUWSG.js → chunk-TOILAPLH.js} +5 -5
  106. package/{chunk-3HPUUWOR.js → chunk-TSKWE74T.js} +3 -3
  107. package/{chunk-DVRHHFEA.js → chunk-TSUJOM6N.js} +3 -3
  108. package/{db-6QED3ZVO.js → db-HCJ5PRB5.js} +3 -3
  109. package/{memoryCommands-HG4WKTU7.js → memoryCommands-HGNEENIN.js} +3 -3
  110. package/{offlineMarxistsAgentCommand-BCPJITJL.js → offlineMarxistsAgentCommand-5OOWZLJI.js} +3 -3
  111. package/{runtimeDoctorCommands-UWR5UDSM.js → runtimeDoctorCommands-4YVMXBQP.js} +5 -5
  112. package/{tableCommands-M3DJUETS.js → tableCommands-LV2PPHNY.js} +6 -6
  113. package/{understanding-ZOESBLF3.js → understanding-3CUQQ6SV.js} +3 -3
@@ -2,32 +2,40 @@ import {
2
2
  buildCurrentTimeBlock,
3
3
  buildIdentityBlock,
4
4
  buildRuntimeGuidanceBlocks
5
- } from "./chunk-G7KM6BBZ.js";
5
+ } from "./chunk-VNGCTQ32.js";
6
6
  import {
7
7
  canonicalizeToolNames
8
- } from "./chunk-FZ2G3I4B.js";
8
+ } from "./chunk-6PXKSN2M.js";
9
9
  import {
10
- clipCompactText
11
- } from "./chunk-5MMAK75Q.js";
10
+ clipCompactText,
11
+ estimateTokenCount,
12
+ getModelContextWindow,
13
+ planCompression,
14
+ planContextUsage,
15
+ serializeMessageContent
16
+ } from "./chunk-GVQT3FIB.js";
12
17
  import {
13
18
  findModelConfig,
14
19
  getProviderByModelName
15
20
  } from "./chunk-S3UTETIC.js";
21
+ import {
22
+ toErrorMessage
23
+ } from "./chunk-HNMXYYJR.js";
16
24
  import {
17
25
  asRecordOrEmpty
18
26
  } from "./chunk-KX6YBIHG.js";
19
27
  import {
20
28
  asTrimmedLowercaseString
21
29
  } from "./chunk-QSJ3HFEF.js";
22
- import {
23
- toErrorMessage
24
- } from "./chunk-HNMXYYJR.js";
25
30
  import {
26
31
  isRecord
27
32
  } from "./chunk-KUG52IAP.js";
28
33
  import {
29
34
  asOptionalTrimmedString
30
35
  } from "./chunk-G3SUCT4W.js";
36
+ import {
37
+ buildDialogSummaryLayer
38
+ } from "./chunk-QLUFR47U.js";
31
39
 
32
40
  // packages/agent-runtime/actionGate.ts
33
41
  function readCommandActionGatePayload(payload) {
@@ -284,6 +292,213 @@ var normalizeContextBlockScopes = (legacyBlocks = void 0, scopes = void 0) => {
284
292
  return (Array.isArray(legacyBlocks) ? legacyBlocks : []).filter((block) => typeof block === "string").map((block) => block.trim()).filter((block) => block.length > 0).map((block) => ({ content: block, cacheScope: "turn" }));
285
293
  };
286
294
 
295
+ // packages/ai/agent/toolOutputPolicy.ts
296
+ var MAX_HISTORICAL_TOOL_CONTENT_CHARS = 1600;
297
+ var MAX_IN_TURN_TOOL_CONTENT_CHARS = 4e3;
298
+ var FRESH_TOOL_OUTPUT_MAX_CHARS = 32e3;
299
+ var DEFAULT_TOOL_OUTPUT_PROFILE = {
300
+ maxChars: MAX_IN_TURN_TOOL_CONTENT_CHARS,
301
+ headRatio: 0.5
302
+ };
303
+ var TOOL_OUTPUT_PROFILES = {
304
+ readFile: { maxChars: 4800, headRatio: 0.68 },
305
+ read_file: { maxChars: 4800, headRatio: 0.68 },
306
+ readWorkspaceFile: { maxChars: 4800, headRatio: 0.68 },
307
+ searchFiles: { maxChars: 3600, headRatio: 0.78 },
308
+ search_files: { maxChars: 3600, headRatio: 0.78 },
309
+ listFiles: { maxChars: 2800, headRatio: 0.85 },
310
+ globFiles: { maxChars: 2800, headRatio: 0.85 },
311
+ execShell: { maxChars: 4e3, headRatio: 0.35 },
312
+ runCommand: { maxChars: 4e3, headRatio: 0.35 },
313
+ launchProcess: { maxChars: 2800, headRatio: 0.35 },
314
+ editFile: { maxChars: 2800, headRatio: 0.62 },
315
+ writeFile: { maxChars: 2400, headRatio: 0.62 },
316
+ readPastedText: { maxChars: 4800, headRatio: 0.5 }
317
+ };
318
+ function resolveToolOutputProfile(toolName) {
319
+ return (toolName ? TOOL_OUTPUT_PROFILES[toolName] : void 0) ?? DEFAULT_TOOL_OUTPUT_PROFILE;
320
+ }
321
+ function projectToolMessageContent(input) {
322
+ const { content, isFresh, toolName, historicalMaxChars } = input;
323
+ if (isFresh) {
324
+ if (content.length <= FRESH_TOOL_OUTPUT_MAX_CHARS) return content;
325
+ return clipToolText(
326
+ content,
327
+ FRESH_TOOL_OUTPUT_MAX_CHARS,
328
+ resolveToolOutputProfile(toolName).headRatio,
329
+ `
330
+ \u2026[\u622A\u65AD\uFF0C\u539F\u59CB\u957F\u5EA6 ${content.length} \u5B57\u7B26]`
331
+ );
332
+ }
333
+ if (content.length <= historicalMaxChars) return content;
334
+ return content.slice(0, historicalMaxChars) + `
335
+ \u2026[\u622A\u65AD\uFF0C\u539F\u59CB\u957F\u5EA6 ${content.length} \u5B57\u7B26]`;
336
+ }
337
+ function clipToolText(content, maxChars, headRatio, marker = "\n\n[... tool output middle omitted; head/tail preserved ...]\n\n") {
338
+ const normalized = content.replace(/\r\n/g, "\n").trim();
339
+ if (normalized.length <= maxChars) return normalized;
340
+ if (maxChars <= marker.length + 2) return normalized.slice(0, maxChars);
341
+ const available = maxChars - marker.length;
342
+ const headChars = Math.max(1, Math.floor(available * headRatio));
343
+ const tailChars = Math.max(1, available - headChars);
344
+ return `${normalized.slice(0, headChars)}${marker}${normalized.slice(-tailChars)}`;
345
+ }
346
+
347
+ // packages/agent-runtime/localAutoCompaction.ts
348
+ var LOCAL_AUTO_COMPACTION_SYSTEM_PROMPT = `\u4F60\u662F\u5BF9\u8BDD\u4E0A\u4E0B\u6587\u538B\u7F29\u5668\u3002\u6839\u636E\u3010\u73B0\u6709\u8BB0\u5FC6\u3011\u548C\u3010\u65B0\u589E\u5BF9\u8BDD\u3011\uFF0C\u8F93\u51FA\u53EF\u66FF\u4EE3\u539F\u59CB\u6D88\u606F\u7684\u4E8B\u5B9E\u6027\u8981\u70B9\uFF0C\u4F9B\u540E\u7EED\u5BF9\u8BDD\u76F4\u63A5\u4F7F\u7528\u3002
349
+
350
+ \u4E25\u683C\u53EA\u8F93\u51FA\u4E0B\u9762\u4E24\u90E8\u5206\uFF0C\u6807\u9898\u5FC5\u987B\u5B8C\u5168\u4E00\u81F4\uFF1A
351
+ \u5173\u952E\u4E8B\u5B9E\u6863\u6848
352
+ - ...
353
+ \u5BF9\u8BDD\u8FDB\u5C55\u4E0E\u5F85\u529E
354
+ - ...
355
+
356
+ \u8981\u6C42\uFF1A
357
+ 1) \u4F7F\u7528\u5BF9\u8BDD\u4E3B\u8BED\u8A00\uFF1B\u6DF7\u5408\u8BED\u8A00\u65F6\u4F18\u5148\u7528\u6237\u4E3B\u8981\u8BED\u8A00\uFF1B\u4E13\u6709\u540D\u8BCD\u3001\u6587\u4EF6\u8DEF\u5F84\u3001\u6807\u8BC6\u7B26\u3001\u547D\u4EE4\u4FDD\u7559\u539F\u6587\u3002
358
+ 2) \u5173\u952E\u4E8B\u5B9E\u6863\u6848\u53EA\u4FDD\u7559\u4E4B\u540E\u7EE7\u7EED\u5BF9\u8BDD\u4ECD\u6709\u4EF7\u503C\u7684\u4FE1\u606F\uFF1A\u7528\u6237\u76EE\u6807/\u504F\u597D\u3001\u7EA6\u675F\u3001\u6280\u672F\u6808\u3001\u786E\u5B9A\u7684\u6587\u4EF6\u8DEF\u5F84\u3001\u6838\u5FC3\u51B3\u7B56\u3001\u672A\u5B8C\u6210\u5F85\u529E\u3002
359
+ 3) \u5BF9\u8BDD\u8FDB\u5C55\u4E0E\u5F85\u529E\uFF1A\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
360
+ 4) \u5FFD\u7565\u5BD2\u6684\u3001\u91CD\u590D\u5C1D\u8BD5\u3001\u5DF2\u653E\u5F03\u65B9\u6848\u548C\u65E0\u4EF7\u503C\u5E9F\u8BDD\u3002
361
+ 5) \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`;
362
+ function buildLocalAutoCompactionUserContent(previousSummary, messagesText) {
363
+ return `\u3010\u73B0\u6709\u8BB0\u5FC6\u3011\uFF1A
364
+ ${previousSummary || "(\u65E0)"}
365
+
366
+ \u3010\u65B0\u589E\u5BF9\u8BDD\u3011\uFF1A
367
+ ${messagesText}`.trim();
368
+ }
369
+ function toPlanCompressionMessages(history) {
370
+ return history.map((message, index) => {
371
+ const usage = message.usage;
372
+ return {
373
+ id: `local-${index}`,
374
+ role: message.role,
375
+ content: message.content,
376
+ ...Array.isArray(message.tool_calls) ? { tool_calls: message.tool_calls } : {},
377
+ ...usage?.completion_tokens != null ? { usage: { completion_tokens: usage.completion_tokens } } : {}
378
+ };
379
+ });
380
+ }
381
+ function formatMessagesForLocalSummary(msgs) {
382
+ return msgs.map((msg) => {
383
+ const content = serializeMessageContent(msg.content) || (Array.isArray(msg.tool_calls) ? `[tool_calls:${msg.tool_calls.map((c) => c.function?.name).filter(Boolean).join(",")}]` : "[\u975E\u6587\u672C\u5185\u5BB9]");
384
+ return `${msg.role}: ${content}`;
385
+ }).join("\n");
386
+ }
387
+ function buildLocalSummaryHistoryMessage(summary) {
388
+ const layer = buildDialogSummaryLayer({ summary });
389
+ return {
390
+ role: "user",
391
+ content: layer?.content ?? `--- \u5386\u53F2\u5BF9\u8BDD\u6458\u8981 ---
392
+ ${summary.trim()}`
393
+ };
394
+ }
395
+ function projectHistoryWithSummary(args) {
396
+ const bridged = toPlanCompressionMessages(args.history);
397
+ let startIndex = 0;
398
+ if (args.summarizedBeforeId) {
399
+ const found = bridged.findIndex((m) => m.id === args.summarizedBeforeId);
400
+ if (found !== -1) startIndex = found + 1;
401
+ }
402
+ return [
403
+ buildLocalSummaryHistoryMessage(args.summary),
404
+ ...args.history.slice(startIndex)
405
+ ];
406
+ }
407
+ var COLD_RESUME_IDLE_MS = 60 * 60 * 1e3;
408
+ function isColdResume(history, nowMs) {
409
+ for (let i = history.length - 1; i >= 0; i -= 1) {
410
+ const at = history[i]?.createdAt;
411
+ if (typeof at === "number" && Number.isFinite(at)) {
412
+ return nowMs - at > COLD_RESUME_IDLE_MS;
413
+ }
414
+ }
415
+ return false;
416
+ }
417
+ async function maybeAutoCompactLocalHistory(args) {
418
+ const { adapter, dialogId, history } = args;
419
+ const unchanged = () => ({
420
+ history,
421
+ compressed: false,
422
+ summaryGenerated: false
423
+ });
424
+ if (!dialogId || history.length === 0 || typeof adapter.loadDialogSummary !== "function" || typeof adapter.saveDialogSummary !== "function") {
425
+ return unchanged();
426
+ }
427
+ let stored = null;
428
+ try {
429
+ stored = await adapter.loadDialogSummary(dialogId);
430
+ } catch (error) {
431
+ console.warn("[localLoop] loadDialogSummary failed:", error);
432
+ return unchanged();
433
+ }
434
+ const existingSummary = typeof stored?.summary === "string" ? stored.summary : "";
435
+ const summarizedBeforeId = typeof stored?.summarizedBeforeId === "string" ? stored.summarizedBeforeId : void 0;
436
+ const contextWindow = typeof args.contextWindow === "number" && Number.isFinite(args.contextWindow) && args.contextWindow > 0 ? args.contextWindow : getModelContextWindow(args.model ?? "");
437
+ const allMsgs = toPlanCompressionMessages(history);
438
+ const coldResume = isColdResume(history, args.now?.() ?? Date.now());
439
+ const plan = planCompression({
440
+ allMsgs,
441
+ summarizedBeforeId,
442
+ summary: existingSummary,
443
+ contextWindow,
444
+ ...coldResume ? { force: true, reason: "context_budget" } : {}
445
+ });
446
+ const projectExisting = () => {
447
+ if (!existingSummary.trim()) return unchanged();
448
+ return {
449
+ history: projectHistoryWithSummary({
450
+ history,
451
+ summary: existingSummary,
452
+ summarizedBeforeId
453
+ }),
454
+ compressed: true,
455
+ summaryGenerated: false
456
+ };
457
+ };
458
+ if (!plan.shouldCompress) {
459
+ return projectExisting();
460
+ }
461
+ try {
462
+ const provider = await args.resolveProvider();
463
+ const messagesText = formatMessagesForLocalSummary(
464
+ plan.msgsToCompress
465
+ );
466
+ const promptContent = buildLocalAutoCompactionUserContent(
467
+ existingSummary,
468
+ messagesText
469
+ );
470
+ const result = await provider.complete([
471
+ { role: "system", content: LOCAL_AUTO_COMPACTION_SYSTEM_PROMPT },
472
+ { role: "user", content: promptContent }
473
+ ]);
474
+ const newSummary = typeof result.content === "string" ? result.content.trim() : "";
475
+ if (!newSummary) {
476
+ console.warn(
477
+ "[localLoop] auto-compaction produced empty summary; keeping prior projection"
478
+ );
479
+ return projectExisting();
480
+ }
481
+ await adapter.saveDialogSummary({
482
+ dialogId,
483
+ summary: newSummary,
484
+ summarizedBeforeId: plan.newSummarizedBeforeId
485
+ });
486
+ return {
487
+ history: projectHistoryWithSummary({
488
+ history,
489
+ summary: newSummary,
490
+ summarizedBeforeId: plan.newSummarizedBeforeId
491
+ }),
492
+ compressed: true,
493
+ summaryGenerated: true,
494
+ ...result.usage ? { usage: result.usage } : {}
495
+ };
496
+ } catch (error) {
497
+ console.warn("[localLoop] auto-compaction failed:", error);
498
+ return projectExisting();
499
+ }
500
+ }
501
+
287
502
  // packages/agent-runtime/localLoop.ts
288
503
  var LOCAL_AGENT_CONFIG_MISSING_CODE = "LOCAL_AGENT_CONFIG_MISSING";
289
504
  var EMPTY_ASSISTANT_REPAIR_PROMPT = "\u8BF7\u7ED9\u51FA\u660E\u786E\u7684\u6587\u5B57\u56DE\u7B54\u6216\u6267\u884C\u4E0B\u4E00\u6B65\uFF1A\u5982\u679C\u4EFB\u52A1\u5DF2\u5B8C\u6210\uFF0C\u8BF7\u76F4\u63A5\u603B\u7ED3\u7ED3\u679C\uFF1B\u5982\u679C\u9700\u8981\u8C03\u7528\u5DE5\u5177\uFF0C\u8BF7\u76F4\u63A5\u8F93\u51FA tool_calls\u3002\u8BF7\u5207\u52FF\u8FD4\u56DE\u7A7A\u5185\u5BB9\u3002";
@@ -551,27 +766,6 @@ function buildActionGate(args) {
551
766
  toolCallId: args.toolCallId
552
767
  };
553
768
  }
554
- var MAX_HISTORICAL_TOOL_CONTENT_CHARS = 1600;
555
- var MAX_IN_TURN_TOOL_CONTENT_CHARS = 4e3;
556
- var DEFAULT_TOOL_OUTPUT_PROFILE = {
557
- maxChars: MAX_IN_TURN_TOOL_CONTENT_CHARS,
558
- headRatio: 0.5
559
- };
560
- var TOOL_OUTPUT_PROFILES = {
561
- readFile: { maxChars: 4800, headRatio: 0.68 },
562
- read_file: { maxChars: 4800, headRatio: 0.68 },
563
- readWorkspaceFile: { maxChars: 4800, headRatio: 0.68 },
564
- searchFiles: { maxChars: 3600, headRatio: 0.78 },
565
- search_files: { maxChars: 3600, headRatio: 0.78 },
566
- listFiles: { maxChars: 2800, headRatio: 0.85 },
567
- globFiles: { maxChars: 2800, headRatio: 0.85 },
568
- execShell: { maxChars: 4e3, headRatio: 0.35 },
569
- runCommand: { maxChars: 4e3, headRatio: 0.35 },
570
- launchProcess: { maxChars: 2800, headRatio: 0.35 },
571
- editFile: { maxChars: 2800, headRatio: 0.62 },
572
- writeFile: { maxChars: 2400, headRatio: 0.62 },
573
- readPastedText: { maxChars: 4800, headRatio: 0.5 }
574
- };
575
769
  var TOOL_METADATA_KEYS = [
576
770
  "path",
577
771
  "query",
@@ -601,8 +795,41 @@ var TOOL_METADATA_KEYS = [
601
795
  "pasteId",
602
796
  "source"
603
797
  ];
604
- function resolveToolOutputProfile(toolName) {
605
- return (toolName ? TOOL_OUTPUT_PROFILES[toolName] : void 0) ?? DEFAULT_TOOL_OUTPUT_PROFILE;
798
+ function trimHistoryToContextBudget(history, model) {
799
+ if (history.length === 0) return { history, droppedCount: 0 };
800
+ const { rawMessageBudget } = planContextUsage({
801
+ contextWindow: getModelContextWindow(model ?? ""),
802
+ summaryTokens: 0,
803
+ // localLoop 没有 web 端的负载分档器;medium 是中性默认值,
804
+ // 不为了省几个 token 在这里复制一份分类逻辑。
805
+ recentLoad: "medium"
806
+ });
807
+ const messageTokens = (message) => {
808
+ const toolCalls = message.tool_calls;
809
+ return estimateTokenCount(contentAsText(message.content)) + (Array.isArray(toolCalls) ? estimateTokenCount(JSON.stringify(toolCalls)) : 0);
810
+ };
811
+ let used = 0;
812
+ let start = history.length;
813
+ for (let i = history.length - 1; i >= 0; i -= 1) {
814
+ const cost = messageTokens(history[i]);
815
+ if (used + cost > rawMessageBudget && start < history.length) break;
816
+ used += cost;
817
+ start = i;
818
+ }
819
+ if (start === 0) return { history, droppedCount: 0 };
820
+ return {
821
+ history: sanitizeToolCallPairing(history.slice(start)),
822
+ droppedCount: start
823
+ };
824
+ }
825
+ function contentAsText(content) {
826
+ if (typeof content === "string") return content;
827
+ if (!Array.isArray(content)) return "";
828
+ return content.map((part) => {
829
+ if (part?.type === "text") return part.text;
830
+ if (part?.type === "image_url") return part.image_url.url;
831
+ return "";
832
+ }).join("\n");
606
833
  }
607
834
  function contentCharCount(content) {
608
835
  if (typeof content === "string") return content.length;
@@ -633,16 +860,6 @@ function compactToolMetadata(metadata) {
633
860
  }
634
861
  return Object.keys(selected).length > 0 ? clipCompactText(JSON.stringify(selected), 1200) : "";
635
862
  }
636
- function clipToolText(content, maxChars, headRatio) {
637
- const normalized = content.replace(/\r\n/g, "\n").trim();
638
- if (normalized.length <= maxChars) return normalized;
639
- const marker = "\n\n[... tool output middle omitted; head/tail preserved ...]\n\n";
640
- if (maxChars <= marker.length + 2) return normalized.slice(0, maxChars);
641
- const available = maxChars - marker.length;
642
- const headChars = Math.max(1, Math.floor(available * headRatio));
643
- const tailChars = Math.max(1, available - headChars);
644
- return `${normalized.slice(0, headChars)}${marker}${normalized.slice(-tailChars)}`;
645
- }
646
863
  function projectToolContentForProvider(args) {
647
864
  const content = args.content;
648
865
  if (typeof content !== "string") return content;
@@ -826,6 +1043,24 @@ function mergeTurnUsage(current, next) {
826
1043
  cache_creation_input_tokens: left.cacheMiss + right.cacheMiss
827
1044
  };
828
1045
  }
1046
+ function addOutOfBandUsage(turn, extra) {
1047
+ if (!extra) return turn;
1048
+ const num = (u, ...keys) => {
1049
+ if (!u) return 0;
1050
+ for (const k of keys) {
1051
+ const v = Number(u[k]);
1052
+ if (Number.isFinite(v) && v !== 0) return v;
1053
+ }
1054
+ return 0;
1055
+ };
1056
+ return {
1057
+ ...turn ?? {},
1058
+ input_tokens: num(turn, "input_tokens", "prompt_tokens") + num(extra, "input_tokens", "prompt_tokens"),
1059
+ output_tokens: num(turn, "output_tokens", "completion_tokens") + num(extra, "output_tokens", "completion_tokens"),
1060
+ cache_read_input_tokens: num(turn, "cache_read_input_tokens", "prompt_cache_hit_tokens") + num(extra, "cache_read_input_tokens", "prompt_cache_hit_tokens"),
1061
+ cache_creation_input_tokens: num(turn, "cache_creation_input_tokens", "prompt_cache_miss_tokens") + num(extra, "cache_creation_input_tokens", "prompt_cache_miss_tokens")
1062
+ };
1063
+ }
829
1064
  function extractUserInputText(content) {
830
1065
  if (typeof content === "string") return content;
831
1066
  if (!Array.isArray(content)) return "";
@@ -926,6 +1161,31 @@ async function runLocalAgentTurn(input) {
926
1161
  ...currentTimeScope,
927
1162
  ...callerScopes
928
1163
  ];
1164
+ let resolvedProvider;
1165
+ const resolveProviderOnce = async () => {
1166
+ if (!resolvedProvider) {
1167
+ resolvedProvider = await input.adapter.resolveProvider(agentConfig);
1168
+ }
1169
+ return resolvedProvider;
1170
+ };
1171
+ let compactionUsage;
1172
+ try {
1173
+ const compacted = await maybeAutoCompactLocalHistory({
1174
+ adapter: input.adapter,
1175
+ dialogId: input.continueDialogId,
1176
+ history,
1177
+ model: agentConfig.model,
1178
+ resolveProvider: resolveProviderOnce
1179
+ });
1180
+ history = compacted.history;
1181
+ compactionUsage = compacted.usage;
1182
+ } catch (error) {
1183
+ console.warn("[localLoop] auto-compaction unexpected error:", error);
1184
+ }
1185
+ const trimmedHistory = trimHistoryToContextBudget(history, agentConfig.model);
1186
+ if (trimmedHistory.droppedCount > 0) {
1187
+ history = trimmedHistory.history;
1188
+ }
929
1189
  const hasContextBlocks = callerScopes.some((block) => block.content.trim()) || mergedContextBlockScopes.some((block) => block.content.trim());
930
1190
  const promptMessageCount = agentConfig.prompt?.trim() || hasContextBlocks ? 1 : 0;
931
1191
  const turnStartIndex = promptMessageCount + history.length;
@@ -955,7 +1215,7 @@ async function runLocalAgentTurn(input) {
955
1215
  let skipFinalAppend = false;
956
1216
  let partialContent = "";
957
1217
  try {
958
- const provider = await input.adapter.resolveProvider(agentConfig);
1218
+ const provider = await resolveProviderOnce();
959
1219
  while (true) {
960
1220
  partialContent = "";
961
1221
  throwIfAborted(input);
@@ -1192,7 +1452,10 @@ async function runLocalAgentTurn(input) {
1192
1452
  });
1193
1453
  return {
1194
1454
  ...result,
1195
- ...turnUsage ? { usage: turnUsage } : {},
1455
+ ...(() => {
1456
+ const merged = addOutOfBandUsage(turnUsage, compactionUsage);
1457
+ return merged ? { usage: merged } : {};
1458
+ })(),
1196
1459
  ...toolCallCount > 0 ? { toolCallCount } : {},
1197
1460
  ...agentConfig.toolSurface ? { runtimeToolSurface: agentConfig.toolSurface } : {},
1198
1461
  // 透出最后一轮 provider 调用的 finish_reason;多轮工具循环里只有最后一轮收尾状态有意义。
@@ -1208,6 +1471,7 @@ export {
1208
1471
  parseToolArgumentsJson,
1209
1472
  summarizeToolArguments,
1210
1473
  resolveAgentImageInputSupport,
1474
+ projectToolMessageContent,
1211
1475
  LOCAL_AGENT_CONFIG_MISSING_CODE,
1212
1476
  EMPTY_ASSISTANT_REPAIR_PROMPT,
1213
1477
  LOCAL_TURN_ABORTED_CODE,
@@ -2,17 +2,17 @@ import {
2
2
  buildLocalAgentLookupKeys,
3
3
  normalizeAgentHandle,
4
4
  shouldReadAgentKeyRemotely
5
- } from "./chunk-FVVST32H.js";
5
+ } from "./chunk-SCBYSC74.js";
6
6
  import {
7
7
  resolveCliAgentKeyInput
8
8
  } from "./chunk-VHBWHNVT.js";
9
+ import {
10
+ toErrorMessage
11
+ } from "./chunk-HNMXYYJR.js";
9
12
  import {
10
13
  readPipeText,
11
14
  spawnProcess
12
15
  } from "./chunk-IDZTNRP2.js";
13
- import {
14
- createAgentKey
15
- } from "./chunk-O4BU24WZ.js";
16
16
  import {
17
17
  parseUserIdFromAuthToken,
18
18
  readOption,
@@ -21,8 +21,8 @@ import {
21
21
  resolveServerUrl
22
22
  } from "./chunk-AVMJVOQY.js";
23
23
  import {
24
- toErrorMessage
25
- } from "./chunk-HNMXYYJR.js";
24
+ createAgentKey
25
+ } from "./chunk-O4BU24WZ.js";
26
26
 
27
27
  // packages/cli/agentRecordHelpers.ts
28
28
  import { readFileSync } from "node:fs";
@@ -1,12 +1,12 @@
1
1
  import {
2
2
  asOptionalFiniteNumber
3
3
  } from "./chunk-WWC7I6TA.js";
4
- import {
5
- asTrimmedString
6
- } from "./chunk-3EUW3WEO.js";
7
4
  import {
8
5
  isRecord
9
6
  } from "./chunk-KUG52IAP.js";
7
+ import {
8
+ asTrimmedString
9
+ } from "./chunk-3EUW3WEO.js";
10
10
  import {
11
11
  asOptionalTrimmedString
12
12
  } from "./chunk-G3SUCT4W.js";
@@ -261,6 +261,8 @@ function pickAllowlistedAgentConfigFields(source, dbKey) {
261
261
  }
262
262
  const tools = uniqueToolNames(source.tools) ?? uniqueToolNames(source.toolNames);
263
263
  if (tools) snapshot.tools = tools;
264
+ const enabledPacks = uniqueToolNames(source.enabledPacks);
265
+ if (enabledPacks) snapshot.enabledPacks = enabledPacks;
264
266
  for (const key of DESKTOP_AGENT_CONFIG_SNAPSHOT_OBJECT_FIELDS) {
265
267
  const value = sanitizePlainObject(source[key]);
266
268
  if (value) {
@@ -1,5 +1,6 @@
1
1
  import {
2
- MEMORY_USE_GUIDANCE
2
+ MEMORY_USE_GUIDANCE,
3
+ wrapHistoricalSummaryWithReplayGuard
3
4
  } from "./chunk-KKY4B2Q2.js";
4
5
 
5
6
  // packages/agent-runtime/turnContext.ts
@@ -122,6 +123,14 @@ var buildLinkedSpacesSection = async (args) => {
122
123
  "\u63D0\u793A\uFF1A\u5982\u9700\u67E5\u8BE2\u8FD9\u4E9B\u7A7A\u95F4\u7684\u8BE6\u7EC6\u5185\u5BB9\uFF0C\u53EF\u4F7F\u7528 read \u5DE5\u5177\u914D\u5408\u5BF9\u5E94\u7684 dbKey\u3002"
123
124
  ].join("\n");
124
125
  };
126
+ var buildDialogSummaryLayer = (args) => {
127
+ const historical = wrapHistoricalSummaryWithReplayGuard(
128
+ asTrimmed(args.summary)
129
+ );
130
+ if (!historical) return null;
131
+ return makeLayer("dialog-summary", `--- \u5386\u53F2\u5BF9\u8BDD\u6458\u8981 ---
132
+ ${historical}`);
133
+ };
125
134
  var buildMemoryOverlayLayer = (args) => {
126
135
  const promptBlock = asTrimmed(args.promptBlock);
127
136
  if (!promptBlock) return null;
@@ -141,6 +150,7 @@ export {
141
150
  buildSpaceContextLayer,
142
151
  buildSkillDiscoveryLayer,
143
152
  buildLinkedSpacesSection,
153
+ buildDialogSummaryLayer,
144
154
  buildMemoryOverlayLayer,
145
155
  buildMemoryUseGuidanceLayer
146
156
  };