nolo-cli 0.8.0-alpha.7 → 0.9.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 (99) hide show
  1. package/{_executeModel-XIGO7HW5.js → _executeModel-UD44KGZ4.js} +33 -28
  2. package/{action-PAXRPJJF.js → action-ZJWE3Y5S.js} +5 -4
  3. package/{addContentAction-CZVWF3QZ.js → addContentAction-TVDBNJM5.js} +4 -3
  4. package/{addDialogAgentAction-CCIDTPHC.js → addDialogAgentAction-EKH774VT.js} +3 -2
  5. package/{agentDeleteCommand-47B24JYG.js → agentDeleteCommand-TCPEFJTF.js} +15 -11
  6. package/{agentEmailCommands-D4FC6OZJ.js → agentEmailCommands-CZ3UILZ4.js} +36 -31
  7. package/{agentListCommands-UFET7CC4.js → agentListCommands-SJKO2FFB.js} +16 -12
  8. package/{agentMachineCommands-LH7QDQPP.js → agentMachineCommands-PSNABISZ.js} +15 -11
  9. package/{agentRecordCommands-CWS2B5IA.js → agentRecordCommands-MH2JKFHS.js} +36 -31
  10. package/{agentRunCommand-3FRPISLG.js → agentRunCommand-4KH6MIZR.js} +42 -34
  11. package/{agentRuntimeLocal-JNQQC2WG.js → agentRuntimeLocal-SKHJUWSS.js} +20 -15
  12. package/{agentSlice-XDFSELFJ.js → agentSlice-3WXXN4VK.js} +5 -4
  13. package/{authCommand-WXMD3IPR.js → authCommand-PXFX6JDT.js} +8 -1
  14. package/{authCommands-X74AFDTC.js → authCommands-356AYWEK.js} +10 -1
  15. package/{chunk-E5HMHIKL.js → chunk-2K2ECKSG.js} +4 -4
  16. package/{chunk-364VYAX2.js → chunk-2PUGVR6E.js} +1 -1
  17. package/chunk-3TZDXYSF.js +71 -0
  18. package/{chunk-YIJFUVKA.js → chunk-3WYQEUBI.js} +1 -1
  19. package/{chunk-543C7RDK.js → chunk-4K2KKCSD.js} +23 -8
  20. package/chunk-4ZDM73SD.js +34 -0
  21. package/{chunk-TDIQFT2F.js → chunk-5CS33IBL.js} +1 -1
  22. package/chunk-5KLGBAAR.js +386 -0
  23. package/{chunk-YD43KPCK.js → chunk-5PJ3VWCS.js} +3 -3
  24. package/{chunk-IAXBCTTE.js → chunk-63SLEOLK.js} +2 -2
  25. package/{chunk-BSTNFPHD.js → chunk-6GANEXVO.js} +1 -1
  26. package/{chunk-6PWWWMI7.js → chunk-7OOXPE3N.js} +2 -2
  27. package/{chunk-KK6SWS5B.js → chunk-7QRKCBOP.js} +5 -5
  28. package/{chunk-LM25IZBJ.js → chunk-AUQ747NZ.js} +2 -2
  29. package/{chunk-572EKYLF.js → chunk-BBYVOSU2.js} +1 -1
  30. package/{chunk-2MALU52L.js → chunk-C3RUNRHT.js} +1 -1
  31. package/{chunk-G5H7RNFL.js → chunk-COMXDWNM.js} +2 -2
  32. package/{chunk-2LMT6K6N.js → chunk-CPB2YM4D.js} +2 -2
  33. package/{chunk-USZMK5UT.js → chunk-DCOA4QSN.js} +1 -1
  34. package/{chunk-OF5H3QWS.js → chunk-EXTIQUCI.js} +182 -0
  35. package/{chunk-B76D3JJK.js → chunk-G43KEVSC.js} +4 -4
  36. package/{chunk-USZDUWOV.js → chunk-GG4AJPSR.js} +2 -2
  37. package/chunk-I42VC5KR.js +15 -0
  38. package/{chunk-BR2WP3DF.js → chunk-IWX4UW2E.js} +9 -9
  39. package/chunk-JEXVIMYZ.js +55 -0
  40. package/{chunk-XDVAYP26.js → chunk-JRKKFRAV.js} +1 -1
  41. package/{chunk-DA2OEKS6.js → chunk-KKY4B2Q2.js} +2 -8
  42. package/{chunk-A3X4Y7MO.js → chunk-KOCA5FCS.js} +482 -26
  43. package/{chunk-IYQV26RA.js → chunk-KTVVPRJS.js} +2 -2
  44. package/{chunk-V2F4OGYM.js → chunk-LARL2V6G.js} +22 -18
  45. package/{chunk-H2RMRZJE.js → chunk-MGOJ5R6J.js} +1 -1
  46. package/{chunk-UVPF33PW.js → chunk-MKMWT7SA.js} +63 -19862
  47. package/chunk-OPZYGHUC.js +89 -0
  48. package/chunk-PAKN26FP.js +239 -0
  49. package/{chunk-OVGXXUVI.js → chunk-PCWC3JTN.js} +2 -2
  50. package/{chunk-AR7ZSGDI.js → chunk-PG5PNA7Y.js} +16 -6
  51. package/{chunk-HEIIIZBX.js → chunk-Q2YZULBH.js} +1 -1
  52. package/{chunk-2JHWPW5B.js → chunk-SBR32ZZS.js} +77 -303
  53. package/{chunk-PN7AFLOK.js → chunk-SH2CFQOH.js} +3 -13
  54. package/{chunk-CM54RSSA.js → chunk-SL35K7AH.js} +21 -1
  55. package/{chunk-VEJLAVTC.js → chunk-TSS3XJY4.js} +4 -4
  56. package/{chunk-IECI4YHR.js → chunk-UUJDGGAK.js} +3 -3
  57. package/{chunk-GEKCOPTN.js → chunk-WKM6FH35.js} +1 -1
  58. package/{chunk-SL3EPWB4.js → chunk-XE635NI4.js} +21 -22
  59. package/{chunk-NE3E3XJ2.js → chunk-XS466O7S.js} +96 -99
  60. package/{chunk-5XH3NZ4T.js → chunk-YBWOP46I.js} +20 -379
  61. package/{chunk-VQ2AJRGD.js → chunk-YPRZSPF3.js} +1 -1
  62. package/{chunk-AUGHVUFE.js → chunk-YYUCRDOK.js} +1 -1
  63. package/{chunk-KTI2WDDG.js → chunk-ZIG5LJ7X.js} +357 -266
  64. package/{chunk-NXZGF7F7.js → chunk-ZQ2UM4KG.js} +1 -1
  65. package/{createAgentAutomationAction-3QTGNYJC.js → createAgentAutomationAction-63OIP6X5.js} +15 -13
  66. package/{createDialogAction-5YX3ARBK.js → createDialogAction-ZLYZDYBB.js} +18 -16
  67. package/{createPageAction-EQNQQRCW.js → createPageAction-AL5FSDCK.js} +16 -14
  68. package/{dbSlice-C4UJLRZP.js → dbSlice-PR44QPXY.js} +3 -2
  69. package/{dialogCommands-AOQS23FV.js → dialogCommands-F6YI5742.js} +17 -13
  70. package/{dialogSlice-GZE3NCMC.js → dialogSlice-JSBNZRLR.js} +15 -13
  71. package/{docCreateCommands-GVOQVJON.js → docCreateCommands-4CTO7ERT.js} +16 -12
  72. package/{docDeleteCommands-GEB7YAUZ.js → docDeleteCommands-VBWERDRG.js} +17 -13
  73. package/{docReadCommands-XYKI2DF2.js → docReadCommands-KNP4MFYB.js} +16 -12
  74. package/{docStore-MLM5AME5.js → docStore-ADP5VYY4.js} +16 -14
  75. package/{docUpdateCommands-4L3RAMHZ.js → docUpdateCommands-4BCBJQHA.js} +16 -12
  76. package/{fetchMessages-JOCYIFKL.js → fetchMessages-U6ZHN56A.js} +3 -2
  77. package/{getPricing-PWPJ6MNV.js → getPricing-3E6UNPKL.js} +3 -3
  78. package/{handleSendMessageAction-WG2GKTGZ.js → handleSendMessageAction-IJDQ6ARA.js} +15 -13
  79. package/index.js +60 -56
  80. package/lib-FYYBQIXS.js +19839 -0
  81. package/{localDialogRead-D3BELSTF.js → localDialogRead-Z5UTAJPU.js} +1 -1
  82. package/{machineCommands-ZNXKLH6Q.js → machineCommands-EA3M4XTN.js} +38 -33
  83. package/{machineWsRunDispatch-7WRG6HNV.js → machineWsRunDispatch-NAPKE5ZA.js} +34 -29
  84. package/{models-XLEOET3E.js → models-4OPOOLFS.js} +2 -2
  85. package/package.json +1 -1
  86. package/{readlineWorkspace-AQURUDN4.js → readlineWorkspace-KMWT4T4S.js} +196 -44
  87. package/{removeDialogAgentAction-CXLST3N6.js → removeDialogAgentAction-GJQJNDW6.js} +5 -4
  88. package/{runAgentClientLoop-VQUEKGA5.js → runAgentClientLoop-U5Q6NDTJ.js} +28 -25
  89. package/{setDialogExtraReferencesAction-LP6VYGU7.js → setDialogExtraReferencesAction-M7OQG54N.js} +3 -2
  90. package/{setPrimaryDialogAgentAction-D3GGH23T.js → setPrimaryDialogAgentAction-46UNFJDL.js} +5 -4
  91. package/{settingSlice-J4I3Z5H7.js → settingSlice-FVUUH4JA.js} +4 -3
  92. package/{spaceCommands-R2RXD5UY.js → spaceCommands-E2CFRPZJ.js} +15 -11
  93. package/{spaceSlice-5UT4JNIN.js → spaceSlice-L3R6IMXE.js} +15 -13
  94. package/{streamAgentChatTurn-NRWSQKFN.js → streamAgentChatTurn-UBDAOQWE.js} +60 -35
  95. package/{tableCommands-66XEWHAK.js → tableCommands-GOFP7QKA.js} +1 -1
  96. package/{tools-TNMUDDRK.js → tools-TMJXZTCA.js} +22 -20
  97. package/tuiSummaryLlmCaller-RV3THLZF.js +78 -0
  98. package/{understanding-HCSFPE7R.js → understanding-GQKNDDWM.js} +7 -54
  99. package/{updateDialogTitleAction-IXOKAVX3.js → updateDialogTitleAction-ZTWRDXI2.js} +17 -14
@@ -1,3 +1,8 @@
1
+ import {
2
+ createRunActivityTracker,
3
+ finalizeRunRecord,
4
+ spawnLocalBackgroundRun
5
+ } from "./chunk-2FTTDCD4.js";
1
6
  import {
2
7
  buildLocalRunEnv,
3
8
  isFullstackCodingAgentRef,
@@ -7,50 +12,61 @@ import {
7
12
  resolveServerUrl,
8
13
  writeUsage
9
14
  } from "./chunk-DZ3XJVET.js";
15
+ import {
16
+ createCliCallAgentToolExecutor,
17
+ createCliLocalRuntimeAdapter,
18
+ isBuiltinNoloAgentRef
19
+ } from "./chunk-LARL2V6G.js";
10
20
  import {
11
21
  getReadableCliDb
12
22
  } from "./chunk-W4NVOSFF.js";
13
23
  import {
14
24
  readDbRecord,
15
25
  resolveAgentRecordFromHybridStore
16
- } from "./chunk-6PWWWMI7.js";
17
- import {
18
- createCliCallAgentToolExecutor,
19
- createCliLocalRuntimeAdapter,
20
- isBuiltinNoloAgentRef
21
- } from "./chunk-V2F4OGYM.js";
26
+ } from "./chunk-7OOXPE3N.js";
22
27
  import {
23
28
  normalizeAgentHandle
24
- } from "./chunk-364VYAX2.js";
29
+ } from "./chunk-2PUGVR6E.js";
25
30
  import {
26
31
  NOLO_PROJECT_MANAGER_AGENT_KEY,
27
32
  isLocalCliAgentKey
28
33
  } from "./chunk-VHBWHNVT.js";
29
34
  import {
30
35
  applyModelLayerOverride,
36
+ buildMemoryOverlayLayer,
37
+ buildMemoryUseGuidanceLayer,
31
38
  buildModelLayerOverride,
32
39
  buildSkillDiscoveryLayer
33
- } from "./chunk-CM54RSSA.js";
40
+ } from "./chunk-SL35K7AH.js";
34
41
  import {
35
42
  CliProviderQuotaError
36
43
  } from "./chunk-X7W4TNB4.js";
37
44
  import {
38
- createRunActivityTracker,
39
- finalizeRunRecord,
40
- spawnLocalBackgroundRun
41
- } from "./chunk-2FTTDCD4.js";
45
+ resolveMachineId
46
+ } from "./chunk-6HYVJV7B.js";
42
47
  import {
43
48
  isGatewayHttpStatus
44
49
  } from "./chunk-GAKEBQD6.js";
50
+ import {
51
+ buildMemorySubjectsForAgent,
52
+ resolveAgentMemoryPolicy
53
+ } from "./chunk-PG5PNA7Y.js";
45
54
  import {
46
55
  load,
47
56
  parseExternalSkillMarkdown,
48
57
  parseSkillDocProtocol
49
- } from "./chunk-NXZGF7F7.js";
58
+ } from "./chunk-ZQ2UM4KG.js";
59
+ import {
60
+ touchMemoryItemsInDb
61
+ } from "./chunk-3TZDXYSF.js";
62
+ import {
63
+ chooseMemoryOwners,
64
+ loadMemoryCandidatesFromDb
65
+ } from "./chunk-Q2YZULBH.js";
50
66
  import {
51
67
  getModelContextWindow,
52
68
  parseUiAskChoiceContent
53
- } from "./chunk-KTI2WDDG.js";
69
+ } from "./chunk-ZIG5LJ7X.js";
54
70
  import {
55
71
  readPipeText,
56
72
  spawnProcess
@@ -61,7 +77,7 @@ import {
61
77
  import {
62
78
  buildPlatformChatCompletionRequest,
63
79
  parsePlatformChatCompletionData
64
- } from "./chunk-5XH3NZ4T.js";
80
+ } from "./chunk-5KLGBAAR.js";
65
81
  import {
66
82
  resolveAgentRuntimeConfigFromRecord
67
83
  } from "./chunk-TILFE6LV.js";
@@ -70,28 +86,31 @@ import {
70
86
  LOCAL_TURN_ABORTED_CODE,
71
87
  readActionGate,
72
88
  readCommandActionGatePayload
73
- } from "./chunk-NE3E3XJ2.js";
89
+ } from "./chunk-XS466O7S.js";
74
90
  import {
75
91
  resolvePlatformChatCompletionsEndpoint
76
- } from "./chunk-XDVAYP26.js";
92
+ } from "./chunk-JRKKFRAV.js";
77
93
  import {
78
94
  clipCompactText
79
95
  } from "./chunk-5MMAK75Q.js";
80
96
  import {
81
97
  findModelConfig
82
- } from "./chunk-572EKYLF.js";
98
+ } from "./chunk-BBYVOSU2.js";
83
99
  import {
84
100
  compactWhitespace
85
101
  } from "./chunk-DWLEOOGR.js";
86
102
  import {
87
103
  toErrorMessage
88
104
  } from "./chunk-HNMXYYJR.js";
105
+ import {
106
+ getDefaultCliLocalRuntimeDb
107
+ } from "./chunk-H33743XH.js";
89
108
  import {
90
109
  parsePositiveFiniteNumberOrFallback
91
110
  } from "./chunk-Y5GCAMGP.js";
92
111
  import {
93
112
  require_index_umd
94
- } from "./chunk-PN7AFLOK.js";
113
+ } from "./chunk-SH2CFQOH.js";
95
114
  import {
96
115
  asTrimmedLowercaseString
97
116
  } from "./chunk-QSJ3HFEF.js";
@@ -486,10 +505,35 @@ function themeText(text, token, colorEnabled = resolveCliColorEnabled(), env = p
486
505
  if (!colorEnabled) return text;
487
506
  return `${themeColorSequence(token, env)}${text}\x1B[39m`;
488
507
  }
508
+ function renderDiffCodeBlock(code, env = process.env) {
509
+ const border = themeText("\u2502", "chrome", true, env);
510
+ const addedColor = themeColorSequence("success", env);
511
+ const deletedColor = themeColorSequence("danger", env);
512
+ const hunkColor = themeColorSequence("info", env);
513
+ const contextColor = themeColorSequence("chrome", env);
514
+ const reset = "\x1B[0m";
515
+ const lines = code.split("\n").map((line) => {
516
+ let color = contextColor;
517
+ if (line.startsWith("@@")) {
518
+ color = hunkColor;
519
+ } else if (line.startsWith("+") && !line.startsWith("+++")) {
520
+ color = addedColor;
521
+ } else if (line.startsWith("-") && !line.startsWith("---")) {
522
+ color = deletedColor;
523
+ }
524
+ return ` ${border} ${color}${line}${reset}`;
525
+ });
526
+ return ` ${themeText("\u250C\u2500\u2500\u2500", "chrome", true, env)}
527
+ ${lines.join("\n")}
528
+ ${themeText("\u2514\u2500\u2500\u2500", "chrome", true, env)}`;
529
+ }
489
530
  function highlightMarkdown(text, colorEnabled = resolveCliColorEnabled(), env = process.env) {
490
531
  if (!colorEnabled) return text;
491
532
  let result = text;
492
- result = result.replace(/```[a-zA-Z-]*\n([\s\S]*?)\n```/g, (match, code) => {
533
+ result = result.replace(/```([a-zA-Z-]*)\n([\s\S]*?)\n```/g, (match, lang, code) => {
534
+ if (lang.toLowerCase() === "diff") {
535
+ return renderDiffCodeBlock(code, env);
536
+ }
493
537
  const infoColor = themeColorSequence("info", env);
494
538
  const reset2 = "\x1B[39m\x1B[22m";
495
539
  const border = themeText("\u2502", "chrome", true, env);
@@ -580,6 +624,8 @@ function normalizeCodeLang(raw) {
580
624
  return "sh";
581
625
  case "json":
582
626
  return "json";
627
+ case "diff":
628
+ return "diff";
583
629
  default:
584
630
  return "unknown";
585
631
  }
@@ -652,7 +698,8 @@ var KEYWORDS = {
652
698
  "echo",
653
699
  "cd"
654
700
  ]),
655
- json: /* @__PURE__ */ new Set(["true", "false", "null"])
701
+ json: /* @__PURE__ */ new Set(["true", "false", "null"]),
702
+ diff: /* @__PURE__ */ new Set([])
656
703
  };
657
704
  function scanStringCommentRegions(line, lang) {
658
705
  const regions = [];
@@ -698,6 +745,22 @@ function highlightCodeLine(line, lang, brightness) {
698
745
  if (lang === "unknown") {
699
746
  return `${info}${line}${STYLE.reset}`;
700
747
  }
748
+ if (lang === "diff") {
749
+ const added = colorSeq("success", brightness);
750
+ const deleted = colorSeq("danger", brightness);
751
+ const hunk = colorSeq("info", brightness);
752
+ const context = colorSeq("chrome", brightness);
753
+ const reset2 = STYLE.reset;
754
+ let color = context;
755
+ if (line.startsWith("@@")) {
756
+ color = hunk;
757
+ } else if (line.startsWith("+") && !line.startsWith("+++")) {
758
+ color = added;
759
+ } else if (line.startsWith("-") && !line.startsWith("---")) {
760
+ color = deleted;
761
+ }
762
+ return `${color}${line}${reset2}`;
763
+ }
701
764
  const regions = scanStringCommentRegions(line, lang);
702
765
  const keywords = KEYWORDS[lang];
703
766
  const accent = colorSeq("accent", brightness);
@@ -2732,7 +2795,7 @@ function isKnownServerPlatformAgent(options) {
2732
2795
  // packages/cli/client/agentRun.ts
2733
2796
  var import_ulid = __toESM(require_index_umd(), 1);
2734
2797
  async function loadRunLocalAgentTurn() {
2735
- const { runLocalAgentTurn } = await import("./agentRuntimeLocal-JNQQC2WG.js");
2798
+ const { runLocalAgentTurn } = await import("./agentRuntimeLocal-SKHJUWSS.js");
2736
2799
  return runLocalAgentTurn;
2737
2800
  }
2738
2801
  async function resolveCurrentMachineId(options) {
@@ -3130,7 +3193,7 @@ async function runLocalAgentTurnForCli(options, settings) {
3130
3193
  } : void 0;
3131
3194
  const currentDialogId = options.continueDialogId ?? (0, import_ulid.ulid)();
3132
3195
  const runChildTurn = async (input) => {
3133
- const { runLocalAgentTurn } = await import("./agentRuntimeLocal-JNQQC2WG.js");
3196
+ const { runLocalAgentTurn } = await import("./agentRuntimeLocal-SKHJUWSS.js");
3134
3197
  return runLocalAgentTurn(input);
3135
3198
  };
3136
3199
  const createFreshChildBaseAdapter = () => {
@@ -3199,6 +3262,7 @@ async function runLocalAgentTurnForCli(options, settings) {
3199
3262
  noStream: options.noStream,
3200
3263
  ...runtimeContext ? { runtimeContext } : {},
3201
3264
  ...options.extraContextBlocks?.length ? { contextBlocks: options.extraContextBlocks } : {},
3265
+ ...options.contextBlockScopes?.length ? { contextBlockScopes: options.contextBlockScopes } : {},
3202
3266
  ...typeof options.timeoutMs === "number" ? { timeoutMs: options.timeoutMs } : {},
3203
3267
  ...options.actionGateHandler ? { onActionGate: options.actionGateHandler } : {},
3204
3268
  onLoopEvent: (event) => {
@@ -3233,7 +3297,12 @@ async function runLocalAgentTurnForCli(options, settings) {
3233
3297
  } catch (error) {
3234
3298
  turnOutput.spinner.stop();
3235
3299
  if (error?.code === LOCAL_TURN_ABORTED_CODE || options.abortSignal?.aborted) {
3236
- return { exitCode: 0, streamInterrupted: true };
3300
+ const stoppedDialogId = error?.dialogId;
3301
+ return {
3302
+ exitCode: 0,
3303
+ streamInterrupted: true,
3304
+ ...stoppedDialogId ? { dialogId: stoppedDialogId } : {}
3305
+ };
3237
3306
  }
3238
3307
  if (settings.reportFailure) {
3239
3308
  options.output.write(
@@ -3260,7 +3329,8 @@ async function runAgentTurn(options) {
3260
3329
  return {
3261
3330
  exitCode: localResult.exitCode,
3262
3331
  ...localResult.dialogId ? { dialogId: localResult.dialogId } : {},
3263
- ...localResult.turnTokens ? { turnTokens: localResult.turnTokens } : {}
3332
+ ...localResult.turnTokens ? { turnTokens: localResult.turnTokens } : {},
3333
+ ...localResult.streamInterrupted ? { streamInterrupted: localResult.streamInterrupted } : {}
3264
3334
  };
3265
3335
  }
3266
3336
  if (isMissingLocalAgentConfigError(localResult.localError, options.agentKey)) {
@@ -3820,6 +3890,327 @@ ${args.inspection.status.trim()}`] : [],
3820
3890
  ].join("\n");
3821
3891
  }
3822
3892
 
3893
+ // packages/ai/memory/overlay.ts
3894
+ var KIND_TITLES = {
3895
+ episodic: "Episodic",
3896
+ semantic: "Semantic",
3897
+ procedural: "Procedural"
3898
+ };
3899
+ var normalizeDisplayContent = (item) => {
3900
+ const normalized = item.content.trim().replace(/^(你要记住|请记住|以后记住|记住)[,,。.\s::]*/u, "").replace(/[。!?!?]+$/u, "").trim();
3901
+ const stripPrefix = (prefix) => normalized.startsWith(prefix) ? normalized.slice(prefix.length).trim() : normalized;
3902
+ if (item.kind === "semantic") {
3903
+ if (item.tags?.includes("understanding-memory")) {
3904
+ switch (item.facet) {
3905
+ case "unfinished":
3906
+ return `\u7528\u6237\u4ECD\u672A\u5B9A\u4E0B\uFF1A${stripPrefix("\u8FD8\u6CA1\u51B3\u5B9A")}`;
3907
+ case "tension":
3908
+ return `\u7528\u6237\u5F53\u524D\u5728\u6743\u8861\uFF1A${stripPrefix("\u5728\u6743\u8861")}`;
3909
+ case "preference":
3910
+ return `\u7528\u6237\u5F53\u524D\u66F4\u5728\u610F\uFF1A${stripPrefix("\u66F4\u5728\u610F")}`;
3911
+ case "style":
3912
+ return `\u7528\u6237\u4E92\u52A8\u504F\u597D\uFF1A${stripPrefix("\u66F4\u559C\u6B22")}`;
3913
+ case "goal":
3914
+ return `\u7528\u6237\u5F53\u524D\u76EE\u6807\uFF1A${stripPrefix("\u60F3\u63A8\u8FDB")}`;
3915
+ }
3916
+ }
3917
+ return `\u7528\u6237\u957F\u671F\u504F\u597D/\u4E8B\u5B9E\uFF1A${normalized}`;
3918
+ }
3919
+ if (item.kind === "episodic" && (item.patternKey === "explicit-remember" || item.patternKey === "agent-remember")) {
3920
+ return `\u7528\u6237\u660E\u786E\u8981\u6C42\u4F60\u8BB0\u4F4F\uFF1A${normalized}`;
3921
+ }
3922
+ if (item.kind === "episodic" && item.tags?.includes("understanding-memory")) {
3923
+ switch (item.facet) {
3924
+ case "unfinished":
3925
+ return `\u6700\u8FD1\u4E00\u6B21\u5BF9\u8BDD\u663E\u793A\uFF1A\u7528\u6237\u8FD8\u6CA1\u5B9A\u4E0B ${stripPrefix("\u8FD8\u6CA1\u51B3\u5B9A")}`;
3926
+ case "tension":
3927
+ return `\u6700\u8FD1\u4E00\u6B21\u5BF9\u8BDD\u663E\u793A\uFF1A\u7528\u6237\u8FD8\u5728\u6743\u8861 ${stripPrefix("\u5728\u6743\u8861")}`;
3928
+ case "preference":
3929
+ return `\u6700\u8FD1\u4E00\u6B21\u5BF9\u8BDD\u663E\u793A\uFF1A\u7528\u6237\u66F4\u5728\u610F ${stripPrefix("\u66F4\u5728\u610F")}`;
3930
+ case "style":
3931
+ return `\u6700\u8FD1\u4E00\u6B21\u5BF9\u8BDD\u663E\u793A\uFF1A\u7528\u6237\u66F4\u504F\u597D ${stripPrefix("\u66F4\u559C\u6B22")}`;
3932
+ case "goal":
3933
+ return `\u6700\u8FD1\u4E00\u6B21\u5BF9\u8BDD\u663E\u793A\uFF1A\u7528\u6237\u60F3\u63A8\u8FDB ${stripPrefix("\u60F3\u63A8\u8FDB")}`;
3934
+ }
3935
+ }
3936
+ return normalized;
3937
+ };
3938
+ var buildMemoryOverlay = (items) => {
3939
+ if (items.length === 0) return null;
3940
+ const byKind = {
3941
+ episodic: [],
3942
+ semantic: [],
3943
+ procedural: []
3944
+ };
3945
+ for (const item of items) {
3946
+ byKind[item.kind].push(item);
3947
+ }
3948
+ const sections = Object.entries(byKind).filter(([, list]) => list.length > 0).map(([kind, list]) => {
3949
+ const lines = list.slice(0, 3).map((item) => `- ${normalizeDisplayContent(item)}`);
3950
+ return [`[${KIND_TITLES[kind]}]`, ...lines].join("\n");
3951
+ });
3952
+ return [
3953
+ "--- Memory Overlay ---",
3954
+ "\u4EE5\u4E0B\u662F\u5F53\u524D\u8BF7\u6C42\u53EF\u7528\u7684\u8BB0\u5FC6\u4E8B\u5B9E\uFF1B\u76F8\u5173\u65F6\u76F4\u63A5\u57FA\u4E8E\u8FD9\u4E9B\u8BB0\u5FC6\u56DE\u7B54\u3002",
3955
+ "\u7528\u6237\u5F53\u524D\u8F93\u5165\u4F18\u5148\u4E8E\u8BB0\u5FC6\uFF1B\u8BB0\u5FC6\u53EA\u8F85\u52A9\u7406\u89E3\uFF0C\u4E0D\u8981\u6C42\u8FCE\u5408\u3002",
3956
+ "",
3957
+ ...sections
3958
+ ].join("\n");
3959
+ };
3960
+
3961
+ // packages/ai/memory/rank.ts
3962
+ var CJK_SEQUENCE_REGEX = /[\u3400-\u4dbf\u4e00-\u9fff]+/g;
3963
+ var MEMORY_IDENTIFIER_REGEX = /\b(?:memory|noise)-[a-z0-9][a-z0-9-]*/gi;
3964
+ var buildCjkTokens = (text) => {
3965
+ const sequences = text.match(CJK_SEQUENCE_REGEX) ?? [];
3966
+ const tokens = [];
3967
+ for (const sequence of sequences) {
3968
+ if (sequence.length >= 2) {
3969
+ tokens.push(sequence);
3970
+ }
3971
+ for (let index = 0; index < sequence.length - 1; index += 1) {
3972
+ tokens.push(sequence.slice(index, index + 2));
3973
+ }
3974
+ }
3975
+ return tokens;
3976
+ };
3977
+ var tokenize = (text) => {
3978
+ const normalized = text.toLowerCase();
3979
+ const wordTokens = normalized.split(/[\s,.;:!?()[\]{}"'`,。!?:;、]+/).map((token) => token.trim()).filter((token) => token.length >= 2);
3980
+ return [...wordTokens, ...buildCjkTokens(normalized)];
3981
+ };
3982
+ var keywordScore = (query, item) => {
3983
+ const queryTokens = new Set(tokenize(query));
3984
+ if (queryTokens.size === 0) return 0;
3985
+ const haystack = /* @__PURE__ */ new Set([
3986
+ ...tokenize(item.content),
3987
+ ...(item.tags ?? []).map((tag) => tag.toLowerCase()),
3988
+ item.patternKey?.toLowerCase() ?? ""
3989
+ ]);
3990
+ let matches = 0;
3991
+ for (const token of queryTokens) {
3992
+ if (haystack.has(token)) matches += 1;
3993
+ }
3994
+ return Math.min(1, matches / Math.max(2, queryTokens.size));
3995
+ };
3996
+ var identifierScore = (query, item) => {
3997
+ const identifiers = query.match(MEMORY_IDENTIFIER_REGEX) ?? [];
3998
+ if (identifiers.length === 0) return 0;
3999
+ const content = item.content.toLowerCase();
4000
+ const matches = identifiers.filter(
4001
+ (identifier) => content.includes(identifier.toLowerCase())
4002
+ ).length;
4003
+ return matches / identifiers.length;
4004
+ };
4005
+ var activationScore = (item, nowMs) => {
4006
+ const lastActivatedMs = Date.parse(item.lastActivatedAt || item.createdAt);
4007
+ const ageDays = Math.max(0, (nowMs - lastActivatedMs) / 864e5);
4008
+ const recency = 1 / (1 + ageDays / 7);
4009
+ const reinforcement = Math.min(1, Math.log1p(item.activationCount ?? 0) / 3);
4010
+ return 0.7 * recency + 0.3 * reinforcement;
4011
+ };
4012
+ var creationRecencyScore = (item, nowMs) => {
4013
+ const createdMs = Date.parse(item.createdAt);
4014
+ const ageDays = Math.max(0, (nowMs - createdMs) / 864e5);
4015
+ return 1 / (1 + ageDays / 7);
4016
+ };
4017
+ var typeFitScore = (item) => {
4018
+ if (item.kind === "episodic") return 0.75;
4019
+ if (item.kind === "semantic") return 0.9;
4020
+ return 0.85;
4021
+ };
4022
+ var understandingScore = (item) => {
4023
+ if (!item.tags?.includes("understanding-memory")) return 0;
4024
+ if (item.facet === "unfinished") return 1;
4025
+ if (item.facet === "tension") return 0.95;
4026
+ if (item.facet === "preference") return 0.85;
4027
+ if (item.facet === "style") return 0.75;
4028
+ return 0.8;
4029
+ };
4030
+ var pathScore = (item, context) => {
4031
+ let score = 0;
4032
+ if (context?.currentOwner && item.ownerType === context.currentOwner.ownerType && item.ownerId === context.currentOwner.ownerId) {
4033
+ score += 0.65;
4034
+ }
4035
+ if (context?.currentSubject && item.subjectType === context.currentSubject.subjectType && item.subjectId === context.currentSubject.subjectId) {
4036
+ score += 0.85;
4037
+ }
4038
+ return Math.min(1, score);
4039
+ };
4040
+ var scoreMemoryItem = (item, query, nowMs = Date.now(), context) => {
4041
+ const queryMatch = keywordScore(query, item);
4042
+ const identifierMatch = identifierScore(query, item);
4043
+ const activation = activationScore(item, nowMs);
4044
+ const createdRecency = creationRecencyScore(item, nowMs);
4045
+ const importance = item.importance ?? 0;
4046
+ const confidence = item.confidence ?? 0;
4047
+ const typeFit = typeFitScore(item);
4048
+ const understanding = understandingScore(item);
4049
+ const path = pathScore(item, context);
4050
+ return 0.25 * queryMatch + 0.2 * identifierMatch + 0.2 * path + 0.09 * activation + 0.16 * createdRecency + 0.06 * importance + 0.03 * confidence + 0.02 * typeFit + 0.01 * understanding;
4051
+ };
4052
+ var rankMemoryCandidates = (items, query, context) => {
4053
+ const nowMs = Date.now();
4054
+ return [...items].sort((a, b) => {
4055
+ const aExplicit = a.sourceKind === "explicit-user-directive";
4056
+ const bExplicit = b.sourceKind === "explicit-user-directive";
4057
+ if (aExplicit !== bExplicit) return bExplicit ? 1 : -1;
4058
+ if (aExplicit) {
4059
+ return Date.parse(b.createdAt) - Date.parse(a.createdAt);
4060
+ }
4061
+ return scoreMemoryItem(b, query, nowMs, context) - scoreMemoryItem(a, query, nowMs, context);
4062
+ });
4063
+ };
4064
+
4065
+ // packages/ai/memory/runtime.ts
4066
+ var COLD_STORAGE_CONFIDENCE = 0.3;
4067
+ var normalizeSelectedContent = (text) => text.trim().replace(/^(你要记住|请记住|以后记住|记住)[,,。.\s::]*/u, "").replace(/[。!?!?]+$/u, "").trim();
4068
+ var STACK_TERMS = [
4069
+ "typescript",
4070
+ "javascript",
4071
+ "python",
4072
+ "rust",
4073
+ "go",
4074
+ "golang",
4075
+ "java",
4076
+ "kotlin",
4077
+ "swift",
4078
+ "ruby",
4079
+ "php"
4080
+ ];
4081
+ var stackAliases = {
4082
+ golang: "go"
4083
+ };
4084
+ var normalizeStackTerm = (term) => stackAliases[term] ?? term;
4085
+ var stackTermsIn = (text) => {
4086
+ const lower = text.toLowerCase();
4087
+ const terms = /* @__PURE__ */ new Set();
4088
+ for (const term of STACK_TERMS) {
4089
+ const pattern = term.length <= 2 ? new RegExp(`\\b${term}\\b`, "i") : new RegExp(term, "i");
4090
+ if (pattern.test(lower)) {
4091
+ terms.add(normalizeStackTerm(term));
4092
+ }
4093
+ }
4094
+ return terms;
4095
+ };
4096
+ var conflictsWithCurrentStack = (item, userInput) => {
4097
+ const currentStacks = stackTermsIn(userInput);
4098
+ if (currentStacks.size === 0) return false;
4099
+ const memoryStacks = stackTermsIn(item.content);
4100
+ if (memoryStacks.size === 0) return false;
4101
+ for (const stack of memoryStacks) {
4102
+ if (!currentStacks.has(stack)) return true;
4103
+ }
4104
+ return false;
4105
+ };
4106
+ var INTERACTION_PREFERENCE_TERMS = [
4107
+ "\u56DE\u7B54\u504F\u597D",
4108
+ "\u8F93\u51FA\u504F\u597D",
4109
+ "\u56DE\u590D\u504F\u597D",
4110
+ "\u56DE\u7B54\u7ED3\u6784",
4111
+ "\u8F93\u51FA\u7ED3\u6784",
4112
+ "\u56DE\u590D\u7ED3\u6784",
4113
+ "\u5148\u7ED9\u7ED3\u8BBA",
4114
+ "\u518D\u5217\u98CE\u9669",
4115
+ "\u6700\u540E\u7ED9\u8BC1\u636E",
4116
+ "\u8BED\u6C14",
4117
+ "\u98CE\u683C",
4118
+ "\u79F0\u547C",
4119
+ "\u53EB\u6211"
4120
+ ];
4121
+ var isInteractionPreferenceMemory = (item) => {
4122
+ if (item.facet === "style") return true;
4123
+ const content = normalizeSelectedContent(item.content);
4124
+ return INTERACTION_PREFERENCE_TERMS.some((term) => content.includes(term));
4125
+ };
4126
+ var isOffCurrentPath = (item, context) => {
4127
+ const currentOwner = context?.currentOwner;
4128
+ const currentSubject = context?.currentSubject;
4129
+ if (currentSubject && (item.subjectType === "project" || item.subjectType === "space") && item.subjectType === currentSubject.subjectType && item.subjectId !== currentSubject.subjectId) {
4130
+ return true;
4131
+ }
4132
+ if (currentOwner?.ownerType === "space" && item.ownerType === "user" && (item.subjectType === "project" || item.subjectType === "space") && item.subjectId !== currentOwner.ownerId) {
4133
+ return true;
4134
+ }
4135
+ return false;
4136
+ };
4137
+ var selectRuntimeMemoryItems = (items, context, userInput = "") => {
4138
+ const seen = /* @__PURE__ */ new Set();
4139
+ const unique = items.filter((item) => {
4140
+ if ((item.confidence ?? 0) < COLD_STORAGE_CONFIDENCE) return false;
4141
+ if (isOffCurrentPath(item, context)) return false;
4142
+ if (conflictsWithCurrentStack(item, userInput)) return false;
4143
+ const key = `${item.kind}:${normalizeSelectedContent(item.content).toLowerCase()}`;
4144
+ if (seen.has(key)) return false;
4145
+ seen.add(key);
4146
+ return true;
4147
+ });
4148
+ const selected = [];
4149
+ const selectedIds = /* @__PURE__ */ new Set();
4150
+ const add = (item) => {
4151
+ if (!item || selectedIds.has(item.id) || selected.length >= 4) return;
4152
+ selected.push(item);
4153
+ selectedIds.add(item.id);
4154
+ };
4155
+ add(
4156
+ unique.find(
4157
+ (item) => context?.currentSubject && item.subjectType === context.currentSubject.subjectType && item.subjectId === context.currentSubject.subjectId
4158
+ )
4159
+ );
4160
+ add(unique.find(isInteractionPreferenceMemory));
4161
+ add(
4162
+ unique.find(
4163
+ (item) => context?.currentOwner && item.ownerType === context.currentOwner.ownerType && item.ownerId === context.currentOwner.ownerId
4164
+ )
4165
+ );
4166
+ add(unique.find((item) => item.ownerType === "user"));
4167
+ add(unique.find((item) => item.ownerType === "space"));
4168
+ add(unique.find((item) => item.kind === "procedural"));
4169
+ for (const item of unique) {
4170
+ add(item);
4171
+ }
4172
+ return selected;
4173
+ };
4174
+ var resolveMemoryRuntime = async (input) => {
4175
+ const owners = chooseMemoryOwners({
4176
+ userId: input.userId,
4177
+ spaceId: input.spaceId
4178
+ });
4179
+ if (owners.length === 0) {
4180
+ return { selectedItems: [], promptBlock: null };
4181
+ }
4182
+ const policy = resolveAgentMemoryPolicy({ agentKey: input.agentKey });
4183
+ const candidates = await loadMemoryCandidatesFromDb(input.db, {
4184
+ owners,
4185
+ subjects: buildMemorySubjectsForAgent({
4186
+ userId: input.userId,
4187
+ spaceId: input.spaceId,
4188
+ agentKey: input.agentKey,
4189
+ policy
4190
+ }),
4191
+ kinds: ["episodic", "semantic", "procedural"],
4192
+ ownerLimit: 20,
4193
+ ownerFallback: policy.ownerFallback
4194
+ });
4195
+ const rankContext = {
4196
+ currentOwner: input.spaceId ? { ownerType: "space", ownerId: input.spaceId } : input.userId ? { ownerType: "user", ownerId: input.userId } : null,
4197
+ currentSubject: input.spaceId ? { subjectType: "space", subjectId: input.spaceId } : input.userId ? { subjectType: "user", subjectId: input.userId } : null
4198
+ };
4199
+ const ranked = selectRuntimeMemoryItems(
4200
+ rankMemoryCandidates(candidates, input.userInput, rankContext),
4201
+ rankContext,
4202
+ input.userInput
4203
+ );
4204
+ if (ranked.length === 0) {
4205
+ return { selectedItems: [], promptBlock: null };
4206
+ }
4207
+ await touchMemoryItemsInDb(input.db, ranked);
4208
+ return {
4209
+ selectedItems: ranked,
4210
+ promptBlock: buildMemoryOverlay(ranked)
4211
+ };
4212
+ };
4213
+
3823
4214
  // packages/cli/agentRunCommand.ts
3824
4215
  function resolvePositiveMs(value, fallback) {
3825
4216
  return parsePositiveFiniteNumberOrFallback(value, fallback);
@@ -4102,6 +4493,70 @@ ${mdContent}`);
4102
4493
  if (skillDiscoveryBlock) {
4103
4494
  extraContextBlocks.push(skillDiscoveryBlock);
4104
4495
  }
4496
+ let memoryPromptBlock = null;
4497
+ if (!deps.memoryRecallDisabled) {
4498
+ const memoryServerUrl = resolveServerUrl(env);
4499
+ const memoryAuthToken = resolveAuthToken(args, env);
4500
+ const memoryAgentKey = effectiveAgentKey;
4501
+ const memorySpaceId = parsed.spaceId ?? void 0;
4502
+ try {
4503
+ if (memoryAuthToken && memoryServerUrl) {
4504
+ const memoryResponse = await fetch(`${memoryServerUrl}/api/memory/query`, {
4505
+ method: "POST",
4506
+ headers: {
4507
+ "Content-Type": "application/json",
4508
+ Authorization: `Bearer ${memoryAuthToken}`
4509
+ },
4510
+ body: JSON.stringify({
4511
+ agentKey: memoryAgentKey,
4512
+ userInput: effectiveMessage,
4513
+ ...memorySpaceId ? { spaceId: memorySpaceId } : {}
4514
+ }),
4515
+ signal: AbortSignal.timeout(5e3)
4516
+ });
4517
+ if (memoryResponse.ok) {
4518
+ const memoryPayload = await memoryResponse.json().catch(() => null);
4519
+ const block = typeof memoryPayload?.promptBlock === "string" ? memoryPayload.promptBlock.trim() : "";
4520
+ memoryPromptBlock = block || null;
4521
+ } else {
4522
+ console.warn("[cli-memory] memory query returned non-ok status:", memoryResponse.status);
4523
+ }
4524
+ } else {
4525
+ const localDb = await getDefaultCliLocalRuntimeDb({ env });
4526
+ const machineId = resolveMachineId();
4527
+ const resolution = await resolveMemoryRuntime({
4528
+ db: localDb,
4529
+ userId: machineId,
4530
+ agentKey: memoryAgentKey,
4531
+ userInput: effectiveMessage,
4532
+ ...memorySpaceId ? { spaceId: memorySpaceId } : {}
4533
+ });
4534
+ memoryPromptBlock = resolution.promptBlock;
4535
+ }
4536
+ } catch (memoryError) {
4537
+ console.warn("[cli-memory] memory recall failed, omitting memory layer:", memoryError);
4538
+ }
4539
+ }
4540
+ const memoryOverlayLayer = buildMemoryOverlayLayer({ promptBlock: memoryPromptBlock });
4541
+ const memoryUseGuidanceLayer = buildMemoryUseGuidanceLayer({ promptBlock: memoryPromptBlock });
4542
+ const contextBlockScopes = [];
4543
+ const agentsMdMarker = "--- \u9879\u76EE\u6307\u4EE4\uFF08";
4544
+ for (const block of extraContextBlocks) {
4545
+ if (block.startsWith(agentsMdMarker)) {
4546
+ contextBlockScopes.push({ content: block, cacheScope: "session" });
4547
+ }
4548
+ }
4549
+ if (memoryUseGuidanceLayer?.content?.trim()) {
4550
+ contextBlockScopes.push({ content: memoryUseGuidanceLayer.content, cacheScope: "session" });
4551
+ }
4552
+ for (const block of extraContextBlocks) {
4553
+ if (!block.startsWith(agentsMdMarker)) {
4554
+ contextBlockScopes.push({ content: block, cacheScope: "turn" });
4555
+ }
4556
+ }
4557
+ if (memoryOverlayLayer?.content?.trim()) {
4558
+ contextBlockScopes.push({ content: memoryOverlayLayer.content, cacheScope: "turn" });
4559
+ }
4105
4560
  const buildRunOptions = (targetAgentKey) => ({
4106
4561
  agentName: targetAgentKey,
4107
4562
  agentKey: targetAgentKey,
@@ -4142,7 +4597,8 @@ ${mdContent}`);
4142
4597
  traceTools: parsed.traceTools,
4143
4598
  ...parsed.eventsMode ? { eventsMode: parsed.eventsMode } : {},
4144
4599
  ...parsed.taskEvidence ? { taskEvidence: parsed.taskEvidence } : {},
4145
- ...extraContextBlocks.length > 0 ? { extraContextBlocks } : {}
4600
+ ...extraContextBlocks.length > 0 ? { extraContextBlocks } : {},
4601
+ ...contextBlockScopes.length > 0 ? { contextBlockScopes } : {}
4146
4602
  });
4147
4603
  let result = await raceWithWatchdog(
4148
4604
  runner({
@@ -1,9 +1,9 @@
1
1
  import {
2
2
  selectCurrentServer
3
- } from "./chunk-VEJLAVTC.js";
3
+ } from "./chunk-TSS3XJY4.js";
4
4
  import {
5
5
  patch
6
- } from "./chunk-G5H7RNFL.js";
6
+ } from "./chunk-COMXDWNM.js";
7
7
  import {
8
8
  selectIdentityToken
9
9
  } from "./chunk-EYEEHCU4.js";