dsh-cross-memory 0.2.3 → 0.2.4

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.
package/lib/index.js CHANGED
@@ -25,9 +25,9 @@ import { ACCOUNT_QUOTA_EXCEEDED_CODE, createUserMessage, isQuotaExceededError, Q
25
25
  import { homedir } from 'node:os';
26
26
  import { join, resolve, sep } from 'node:path';
27
27
  import { Config as ConfigSchema, consolidationRouteOf, DEFAULT_ROTATION_MAX_BYTES, readTunables, resolveConfig } from './config.js';
28
- import { MemoryStore, slugify } from './storage.js';
28
+ import { MemoryStore, projectSlug, slugify } from './storage.js';
29
29
  import { StateStore, importLegacyState, statePath } from './state.js';
30
- import { browseMemories, EXPAND_SEEDS, hubTerms, matchCredit, prefilterEntries, QUALIFIED_SCORE_FACTOR, relatedHits, searchMemories } from './search.js';
30
+ import { ALIAS_FLOOR_SHARE, browseMemories, EXPAND_SEEDS, hubTerms, matchCredit, prefilterEntries, QUALIFIED_SCORE_FACTOR, relatedHits, searchMemories, suggestAliases } from './search.js';
31
31
  import { readFile } from 'node:fs/promises';
32
32
  import { isPersonaLocked, readPersona, renderPersonaBlock, writePersona } from './persona.js';
33
33
  import { StoreSyncService } from './sync-runtime.js';
@@ -43,7 +43,7 @@ import { findProjectRoot, isWithin } from './workspace.js';
43
43
  import { citationRoots, citationWarning, ignoredUnder, missingCitations } from './citations.js';
44
44
  import { planRetention, retentionKey } from './retention.js';
45
45
  import { MemoryLog, createFileSink, createLogExporter, pluginLogger } from './log.js';
46
- import { collectWindow, resolveLlmRoute, runExtraction } from './extract.js';
46
+ import { collectExtractionWindow, collectWindow, resolveLlmRoute, runExtraction, selectKnownTitles } from './extract.js';
47
47
  import { collectExcerpts } from './raw-recall.js';
48
48
  import { decodeSessionLog, findSessionLogs, parseSessionLog, planWindows, zstdAvailable } from './backfill.js';
49
49
  import { backgroundDelayMs, cappedBackoffMs, extractionDelayMs, formatDelay, parsePeakHours, peakDelayMs } from './schedule.js';
@@ -105,8 +105,22 @@ const NO_PROJECT_LABEL = 'project:none';
105
105
  const KNOWN_TITLE_LIMIT = 80;
106
106
  /** How many late-injection blocks one conversation may receive. */
107
107
  const DELTA_MAX_PER_CONVERSATION = 2;
108
- /** Byte budget for one late-injection block. */
109
- const DELTA_MAX_BYTES = 800;
108
+ /**
109
+ * Most entries one late-injection block names.
110
+ *
111
+ * A count cap as well as the byte budget: a scope full of short entries would
112
+ * otherwise pack twenty titles into one block and turn a nudge into a list.
113
+ */
114
+ const DELTA_MAX_ENTRIES = 6;
115
+ /**
116
+ * How long a project-slug conflict scan is trusted.
117
+ *
118
+ * The scan reads every project's descriptor and host files — cheap per file,
119
+ * but not something to repeat on every injection. An hour is short enough that
120
+ * a collision found today reaches the next session, long enough that a store
121
+ * with sixty projects pays for it once.
122
+ */
123
+ const CONFLICT_SCAN_TTL_MS = 3_600_000;
110
124
  /** Sessions one `/memories backfill` run mines unless `--limit` says otherwise. */
111
125
  const BACKFILL_DEFAULT_SESSIONS = 3;
112
126
  /** Windows one backfilled session may spend, so one huge log cannot run for an hour. */
@@ -201,6 +215,10 @@ export class MemoriesRuntime {
201
215
  consolidateSkip;
202
216
  /** Hub-term predicates by store signature; see `hubFor`. */
203
217
  hubCache = new Map();
218
+ /** Last project-slug conflict scan, with the time it ran. */
219
+ conflictScan;
220
+ /** Whether the conflict scan has already logged its findings once. */
221
+ conflictLogged = false;
204
222
  /** Sessions whose conversation already carries the memory block. */
205
223
  injected = new WeakSet();
206
224
  /** Recall deltas already injected into each conversation. */
@@ -445,6 +463,26 @@ export class MemoriesRuntime {
445
463
  const states = await this.allScopes(session);
446
464
  return browseMemories(this.groups(states), options);
447
465
  }
466
+ /**
467
+ * The vocabulary this store files memories under, for a query that found
468
+ * nothing.
469
+ *
470
+ * Search is lexical, so a query phrased in the user's words cannot reach a
471
+ * memory filed under the product's words. Returning the aliases and tags that
472
+ * share characters with the query is what lets the caller try again with the
473
+ * store's own terms instead of concluding the fact was never recorded.
474
+ *
475
+ * @param session - conversation asking.
476
+ * @param query - the query that returned nothing.
477
+ * @param limit - most terms to return.
478
+ * @returns shared terms first, then the most widely used ones.
479
+ */
480
+ async aliasHints(session, query, limit = 12) {
481
+ const states = await this.allScopes(session);
482
+ const hints = suggestAliases(this.groups(states), query, limit);
483
+ this.log.decision('dsh-cross-memory: no hit for %s, offering %d alias hint(s)', JSON.stringify(query.slice(0, 60)), hints.length);
484
+ return hints;
485
+ }
448
486
  /** Read one entry by scope and id, recording the hit. */
449
487
  async read(session, scope, id, record = true) {
450
488
  const root = scope === 'project' ? await this.projectRoot(session) : undefined;
@@ -566,20 +604,26 @@ export class MemoriesRuntime {
566
604
  * cap. Extraction is otherwise blind to what is already known, which is how one
567
605
  * session's lesson ended up stored twice — once in Chinese, once in English.
568
606
  *
607
+ * The whole scope is returned, uncapped; the caller ranks it against the
608
+ * window with {@link selectKnownTitles} and only then cuts. Cutting here was
609
+ * the bug: on a store larger than the cap, every title past the cut was
610
+ * invisible to the extractor, which then re-derived those facts under new
611
+ * titles.
612
+ *
569
613
  * @param root - the session's project root, when it has one.
570
- * @returns existing titles, capped for the prompt.
614
+ * @returns every candidate title with its write time.
571
615
  */
572
- async knownTitles(root) {
573
- const titles = [];
616
+ async knownTitleCandidates(root) {
617
+ const candidates = [];
574
618
  if (root !== undefined) {
575
619
  const project = await this.store.list('project', root).catch(() => []);
576
620
  for (const entry of project)
577
- titles.push(entry.title);
621
+ candidates.push({ title: entry.title, updatedAt: entry.updatedAt });
578
622
  }
579
623
  const global = await this.store.list('global', undefined).catch(() => []);
580
624
  for (const entry of global)
581
- titles.push(entry.title);
582
- return titles.slice(0, KNOWN_TITLE_LIMIT);
625
+ candidates.push({ title: entry.title, updatedAt: entry.updatedAt });
626
+ return candidates;
583
627
  }
584
628
  /** Delete one entry. */
585
629
  async forget(session, scope, id) {
@@ -657,7 +701,7 @@ export class MemoriesRuntime {
657
701
  : {},
658
702
  }));
659
703
  const loopNote = renderOpenLoops((await readLoops(this.store.memoriesDir).catch(() => ({ version: 1, loops: [] }))).loops, { now: Date.now() });
660
- const note = [await this.draftNote(), loopNote]
704
+ const note = [await this.conflictNote(await this.projectRoot(session)), await this.draftNote(), loopNote]
661
705
  .filter((part) => part !== undefined && part.trim().length > 0)
662
706
  .join('\n\n');
663
707
  // Check the citations of what is about to be shown, not of the whole store:
@@ -817,6 +861,41 @@ export class MemoriesRuntime {
817
861
  return `Applying them failed and the store was rolled back: ${message}`;
818
862
  }
819
863
  }
864
+ /**
865
+ * A warning when this workspace's memory directory is shared with another
866
+ * repository of the same name.
867
+ *
868
+ * `projectSlug` keys a project by its basename, which is what lets one
869
+ * repository checked out at two paths on two machines share one memory
870
+ * directory. The accepted cost is that two unrelated repositories called
871
+ * `backend` also share one — and the failure is silent and confusing: each
872
+ * project's memories are injected into the other's sessions, with nothing
873
+ * saying why. The store already records every host's git origin; two
874
+ * different origins for one slug is the proof. This surfaces it once per
875
+ * injected conversation, in the block the model actually reads.
876
+ *
877
+ * @param root - the session's project root, when it has one.
878
+ * @returns the warning line, or `undefined` when there is no collision.
879
+ */
880
+ async conflictNote(root) {
881
+ if (root === undefined)
882
+ return undefined;
883
+ const now = Date.now();
884
+ if (this.conflictScan === undefined || now - this.conflictScan.at >= CONFLICT_SCAN_TTL_MS) {
885
+ const rows = await this.store.originConflicts().catch(() => []);
886
+ this.conflictScan = { at: now, rows };
887
+ // Logged once per process rather than once per scan: the finding does not
888
+ // change between scans, and a line every hour reads as a new problem.
889
+ if (rows.length > 0 && !this.conflictLogged) {
890
+ this.conflictLogged = true;
891
+ this.log.warn('dsh-cross-memory: %d project memory director%s shared by more than one repository: %s', rows.length, rows.length === 1 ? 'y is' : 'ies are', rows.map((row) => `${row.slug} (${row.origins.join(' vs ')})`).join('; '));
892
+ }
893
+ }
894
+ const row = (this.conflictScan?.rows ?? []).find((item) => item.slug === projectSlug(root));
895
+ if (row === undefined)
896
+ return undefined;
897
+ return `⚠ 本项目记忆目录 projects/${row.slug} 被 ${row.origins.length} 个不同仓库共用(${row.origins.join(' / ')}),本会话的项目记忆可能混入另一个仓库的内容。`;
898
+ }
820
899
  /**
821
900
  * The one line this plugin wants in the summary but cannot express as a memory.
822
901
  *
@@ -1160,6 +1239,27 @@ export class MemoriesRuntime {
1160
1239
  // Which words are too common in these scopes to prove anything. Computed
1161
1240
  // once for the turn and cached until the store changes.
1162
1241
  const hub = this.hubFor(states);
1242
+ // Ranked by relevance first, and only then by the decayed score.
1243
+ //
1244
+ // It used to be the other way round, on the theory that recency and the
1245
+ // entry's track record should break ties between equally relevant memories.
1246
+ // A full sort by the decayed score is not a tie-break, though: importance
1247
+ // multiplies by up to 5 and decay spans 4×, so the attention term does not
1248
+ // nudge near-ties, it decides the order. Measured on 150 hand-written turns
1249
+ // against this store (bench/ablate.mjs), sorting the credited candidates by
1250
+ // the decayed score put the turn's own memory first 42% of the time and
1251
+ // inside the four injected slots 75%; sorting by relevance first gives 80%
1252
+ // and 91%. Every decay blend in between was worse than plain relevance, so
1253
+ // the attention model is a tie-break here and nothing more. It still earns
1254
+ // that much: entries the lexical path rates equally are ordered by what this
1255
+ // conversation and recent sessions actually read.
1256
+ //
1257
+ // The seeds for the one-hop expansion are taken after this sort for the same
1258
+ // reason: they used to be whichever three candidates the store listed first.
1259
+ const byStrength = (left, right) => right.relevance - left.relevance
1260
+ || right.score - left.score
1261
+ || right.entry.updatedAt - left.entry.updatedAt
1262
+ || left.entry.title.localeCompare(right.entry.title);
1163
1263
  const eligible = [];
1164
1264
  let near;
1165
1265
  for (const state of states) {
@@ -1189,6 +1289,63 @@ export class MemoriesRuntime {
1189
1289
  }
1190
1290
  }
1191
1291
  if (eligible.length === 0) {
1292
+ // Alias fallback, before the archive is consulted.
1293
+ //
1294
+ // The strict gate asks for two pieces of evidence, and a turn that names a
1295
+ // memory by its OTHER name often shares only one: 「monorepo 该怎么配」
1296
+ // against an entry filed under `keys: [monorepo]` with
1297
+ // `appliesTo: 配置 monorepo 工作区时` — one substantive term, so the strict
1298
+ // gate refuses it. That single hit is real (`keys` exists to hold exactly
1299
+ // that name) while a single title or body word is not, which is why this
1300
+ // pass scores only `keys` and `appliesTo` and only runs after the strict
1301
+ // gate found nothing. Live aliases beat a retired entry, so this runs
1302
+ // before {@link archivedFor}.
1303
+ const byAlias = [];
1304
+ // A scaled floor, not the shared one: see {@link ALIAS_FLOOR_SHARE} for the
1305
+ // measurement. Keeping the full floor here made the pass fire for English
1306
+ // turns and never for Chinese ones.
1307
+ const aliasFloor = this.settings.recallMinScore * ALIAS_FLOOR_SHARE;
1308
+ for (const state of states) {
1309
+ for (const entry of prefilterEntries(state.entries, query)) {
1310
+ if (seen.has(entry.id))
1311
+ continue;
1312
+ const why = matchCredit(entry, query, aliasFloor, 1, {
1313
+ range: window ?? null,
1314
+ fields: ['keys', 'appliesTo'],
1315
+ ...hub === undefined ? {} : { hub },
1316
+ });
1317
+ if (why.about)
1318
+ byAlias.push({ entry, ...why });
1319
+ }
1320
+ }
1321
+ if (byAlias.length > 0) {
1322
+ byAlias.sort(byStrength);
1323
+ const aliasPicked = [];
1324
+ // Two at most: this block is a widened gate, not a second recall budget.
1325
+ for (const candidate of byAlias) {
1326
+ if (aliasPicked.length >= Math.min(remaining, 2))
1327
+ break;
1328
+ if (renderRecall([...aliasPicked, candidate].map((item) => item.entry), this.settings.recallMaxBytes) === undefined)
1329
+ break;
1330
+ aliasPicked.push(candidate);
1331
+ }
1332
+ const rendered = aliasPicked.length === 0
1333
+ ? undefined
1334
+ : renderRecall(aliasPicked.map((item) => item.entry), this.settings.recallMaxBytes);
1335
+ if (rendered !== undefined) {
1336
+ // The block says how these matched. A reader who does not know the
1337
+ // match was on an alias will treat a one-word hit as a strong one.
1338
+ const text = rendered.replace(RECALL_OPEN, `${RECALL_OPEN}\n以下 ${aliasPicked.length} 条按别名(keys/appliesTo)匹配,只与当前提问共享一个词,请按背景参考对待:`);
1339
+ this.recallCounts.set(session, used + aliasPicked.length);
1340
+ await this.markSurfaced(session, aliasPicked.map((item) => item.entry));
1341
+ this.recordInjection(session, aliasPicked.map((item) => item.entry.id));
1342
+ this.log.info('dsh-cross-memory: session %s recalled %s by alias only (single shared term, keys/appliesTo)', session.id, aliasPicked.map((item) => item.entry.id).join(', '));
1343
+ return createUserMessage({
1344
+ content: [{ type: 'text', text }],
1345
+ source: { kind: MEMORY_SOURCE_KIND, form: 'recall' },
1346
+ });
1347
+ }
1348
+ }
1192
1349
  // Nothing live answers this turn. An entry retired by the cap, folded by a
1193
1350
  // rewrite or aged out can still hold the answer, and "we used to say this"
1194
1351
  // costs one line where silence is a miss the reader never learns about.
@@ -1229,33 +1386,12 @@ export class MemoriesRuntime {
1229
1386
  // asking for three consecutive characters, every ordinary mid-conversation
1230
1387
  // turn produced one of these, and six turns in a row recalled nothing at
1231
1388
  // all with the right memory sitting one shared pair away.
1232
- if (near !== undefined && near.relevance >= this.settings.recallMinScore && !this.nearMissLogged.has(session)) {
1389
+ if (near !== undefined && near.relevance >= this.settings.recallMinScore * ALIAS_FLOOR_SHARE && !this.nearMissLogged.has(session)) {
1233
1390
  this.nearMissLogged.add(session);
1234
1391
  this.log.info('dsh-cross-memory: session %s had a near miss worth reading: %s', session.id, detail);
1235
1392
  }
1236
1393
  return undefined;
1237
1394
  }
1238
- // Ranked by relevance first, and only then by the decayed score.
1239
- //
1240
- // It used to be the other way round, on the theory that recency and the
1241
- // entry's track record should break ties between equally relevant memories.
1242
- // A full sort by the decayed score is not a tie-break, though: importance
1243
- // multiplies by up to 5 and decay spans 4×, so the attention term does not
1244
- // nudge near-ties, it decides the order. Measured on 150 hand-written turns
1245
- // against this store (bench/ablate.mjs), sorting the credited candidates by
1246
- // the decayed score put the turn's own memory first 42% of the time and
1247
- // inside the four injected slots 75%; sorting by relevance first gives 80%
1248
- // and 91%. Every decay blend in between was worse than plain relevance, so
1249
- // the attention model is a tie-break here and nothing more. It still earns
1250
- // that much: entries the lexical path rates equally are ordered by what this
1251
- // conversation and recent sessions actually read.
1252
- //
1253
- // The seeds for the one-hop expansion are taken after this sort for the same
1254
- // reason: they used to be whichever three candidates the store listed first.
1255
- const byStrength = (left, right) => right.relevance - left.relevance
1256
- || right.score - left.score
1257
- || right.entry.updatedAt - left.entry.updatedAt
1258
- || left.entry.title.localeCompare(right.entry.title);
1259
1395
  eligible.sort(byStrength);
1260
1396
  // The one-hop neighbours go in after the seeds and carry no lexical
1261
1397
  // relevance, so they can only fill slots the lexical path left empty — the
@@ -1382,8 +1518,8 @@ export class MemoriesRuntime {
1382
1518
  * later is invisible until the model thinks to search for it. This path names
1383
1519
  * only entries whose `updated` stamp is newer than the last injection, and
1384
1520
  * only those the conversation has not already been shown, so it is a short
1385
- * paragraph rather than a second summary. Two per conversation, 800 bytes
1386
- * each: the block is a nudge, not a channel.
1521
+ * paragraph rather than a second summary. Two per conversation, at
1522
+ * `deltaMaxBytes` each: the block is a nudge, not a channel.
1387
1523
  *
1388
1524
  * @param agent - the agent whose next step is being prepared.
1389
1525
  * @returns the message to append, or `undefined` when nothing new is worth it.
@@ -1397,6 +1533,9 @@ export class MemoriesRuntime {
1397
1533
  const used = this.deltaCounts.get(session) ?? 0;
1398
1534
  if (used >= DELTA_MAX_PER_CONVERSATION)
1399
1535
  return undefined;
1536
+ const maxBytes = this.settings.deltaMaxBytes;
1537
+ if (maxBytes <= 0)
1538
+ return undefined;
1400
1539
  const record = this.state.getInjection(session.id);
1401
1540
  if (record === undefined)
1402
1541
  return undefined;
@@ -1421,15 +1560,15 @@ export class MemoriesRuntime {
1421
1560
  || left.title.localeCompare(right.title));
1422
1561
  const picked = [];
1423
1562
  for (const entry of fresh) {
1424
- if (picked.length >= 3)
1563
+ if (picked.length >= DELTA_MAX_ENTRIES)
1425
1564
  break;
1426
- if (renderRecall([...picked, entry], DELTA_MAX_BYTES) === undefined)
1565
+ if (renderRecall([...picked, entry], maxBytes) === undefined)
1427
1566
  break;
1428
1567
  picked.push(entry);
1429
1568
  }
1430
1569
  if (picked.length === 0)
1431
1570
  return undefined;
1432
- const rendered = renderRecall(picked, DELTA_MAX_BYTES);
1571
+ const rendered = renderRecall(picked, maxBytes);
1433
1572
  if (rendered === undefined)
1434
1573
  return undefined;
1435
1574
  const text = rendered.replace(RECALL_OPEN, `${RECALL_OPEN}\n这 ${picked.length} 条记忆是在本次会话开始之后新增或更新的,只作背景参考:`);
@@ -2343,12 +2482,15 @@ export class MemoriesRuntime {
2343
2482
  try {
2344
2483
  const watermark = this.state.getSession(key);
2345
2484
  const afterSeq = watermark?.lastSeq ?? 0;
2346
- const window = collectWindow(session, afterSeq, this.settings.extractWindowMessages, this.settings.extractMaxInputChars);
2485
+ const window = collectExtractionWindow(session, afterSeq, this.settings.extractWindowMessages, this.settings.extractMaxInputChars);
2347
2486
  if (window.lastSeq === undefined || window.text.trim().length === 0)
2348
2487
  return { stored: 0, reason: 'empty' };
2349
2488
  const root = await this.projectRoot(session);
2350
2489
  const projectLabel = root === undefined ? NO_PROJECT_LABEL : this.store.target('project', root).label;
2351
- const knownTitles = await this.knownTitles(root);
2490
+ // Ranked against the window rather than cut in time order: on a store
2491
+ // bigger than the prompt's title budget, the titles past a time-order cut
2492
+ // were invisible, so the extractor re-derived facts it already had.
2493
+ const knownTitles = selectKnownTitles(await this.knownTitleCandidates(root), window.text, KNOWN_TITLE_LIMIT);
2352
2494
  // A settle-window pass deliberately does NOT inherit the plugin lifecycle
2353
2495
  // signal: the plugin is disposed as the process shuts down, and tying the
2354
2496
  // pass to that signal would abort exactly the pass a one-shot run needs.
@@ -2439,6 +2581,12 @@ export class MemoriesRuntime {
2439
2581
  // prompt/route problem — say so rather than letting the pass look
2440
2582
  // merely less productive.
2441
2583
  this.log.info('dsh-cross-memory: dropped %d candidate(s) from session %s whose evidence quote did not appear verbatim in the transcript', outcome.unsupported, key);
2584
+ // Which ones, and why. The count alone cannot be acted on: "no quote at
2585
+ // all" and "quote invented" are different fixes (prompt vs route), and
2586
+ // neither is visible from a number.
2587
+ for (const item of outcome.droppedEvidence ?? []) {
2588
+ this.log.decision('dsh-cross-memory: dropped "%s" from session %s (%s), quote so far: %s', item.title, key, item.reason, item.quotePreview.length === 0 ? '(none)' : `"${item.quotePreview}…"`);
2589
+ }
2442
2590
  }
2443
2591
  }
2444
2592
  // Only a completed extraction may consume the transcript window. A capped
@@ -2579,12 +2727,15 @@ export class MemoriesRuntime {
2579
2727
  : await findProjectRoot(log.cwd, this.deployment.projectRootMarkers).catch(() => undefined);
2580
2728
  const projectRoot = found !== undefined && !isCatchAllDirectory(found, this.deployment.dshHome) ? found : undefined;
2581
2729
  const projectLabel = projectRoot === undefined ? NO_PROJECT_LABEL : this.store.target('project', projectRoot).label;
2582
- const titles = await this.knownTitles(projectRoot);
2730
+ // Ranked per window, not once per session: each backfilled window is a
2731
+ // different piece of the transcript, so the titles worth showing it differ.
2732
+ const titleCandidates = await this.knownTitleCandidates(projectRoot);
2583
2733
  // A log is not a live Session: the extractor needs the id for provenance
2584
2734
  // only, and the route is passed explicitly so no session header is read.
2585
2735
  const stub = { id: log.sessionId, requestHeader: () => undefined };
2586
2736
  let lastSeq = this.state.getSession(log.sessionId)?.lastSeq ?? 0;
2587
2737
  for (const window of item.windows.slice(0, BACKFILL_MAX_WINDOWS_PER_SESSION)) {
2738
+ const titles = selectKnownTitles(titleCandidates, window.text, KNOWN_TITLE_LIMIT);
2588
2739
  try {
2589
2740
  const outcome = await runExtraction(llm, {
2590
2741
  session: stub,
@@ -3809,7 +3960,7 @@ export class MemoriesRuntime {
3809
3960
  `auto-extract: ${this.settings.autoExtract ? `on (every ${formatDelay(this.settings.extractIntervalMinutes * 60_000)}${this.settings.minIdleHours > 0 ? ` + ${formatDelay(extractionDelayMs(this.settings))} quiet to settle` : ''}, ≤${this.settings.maxAgeDays}d old)` : 'off'}`,
3810
3961
  `peak-hours: ${this.peakLine()}`,
3811
3962
  `recall: ${this.settings.recallMode} (relevance ≥${this.settings.recallMinScore} plus ${this.settings.recallMinTerms} terms or a shared run, ≤${this.settings.recallMaxPerConversation} memories and ≤${this.settings.recallMaxBytes}B per conversation)`,
3812
- `late memories: ${this.settings.injectDelta ? 'on (≤2 blocks, ≤800B each, new or updated entries only)' : 'off'}`,
3963
+ `late memories: ${this.settings.injectDelta ? `on (≤2 blocks, ≤${this.settings.deltaMaxBytes}B each, new or updated entries only)` : 'off'}`,
3813
3964
  `rotation: ${this.settings.rotationEntries > 0 ? `${this.settings.rotationEntries} titles/session` : 'off'}`,
3814
3965
  `projects: ${await this.projectLine()}`,
3815
3966
  `summary: ≤${this.settings.maxSummaryEntries} per scope with ${this.settings.summaryFreshSlots} reserved for never-listed memories`,
package/lib/loops.js CHANGED
@@ -83,10 +83,15 @@ export function mergeLoops(store, candidates, now, sessionId) {
83
83
  const existing = loops.find((loop) => loop.state === 'open' && overlaps(normalize(loop.text), key));
84
84
  if (existing !== undefined) {
85
85
  // A later deadline wins: the user moved the promise, they did not make two.
86
- if (candidate.dueAt !== undefined && (existing.dueAt === undefined || candidate.dueAt > existing.dueAt)) {
87
- const index = loops.indexOf(existing);
88
- loops[index] = { ...existing, dueAt: candidate.dueAt };
89
- }
86
+ // The text is carried forward too when the candidate re-words it (a
87
+ // progress report is told to keep the original promise's wording, so
88
+ // containment still recognises it), and the first sighting keeps its age.
89
+ const index = loops.indexOf(existing);
90
+ const dueAt = candidate.dueAt !== undefined && (existing.dueAt === undefined || candidate.dueAt > existing.dueAt)
91
+ ? candidate.dueAt
92
+ : existing.dueAt;
93
+ const same = normalize(existing.text) === key;
94
+ loops[index] = { ...existing, ...same ? {} : { text }, openedAt: same ? existing.openedAt : now, ...dueAt === undefined ? {} : { dueAt } };
90
95
  continue;
91
96
  }
92
97
  loops.push({
package/lib/render.js CHANGED
@@ -496,8 +496,8 @@ export function renderOpenLoops(loops, options = {}) {
496
496
  || right.openedAt - left.openedAt);
497
497
  if (open.length === 0)
498
498
  return undefined;
499
- const maxEntries = options.maxEntries ?? 8;
500
- const maxBytes = options.maxBytes ?? 800;
499
+ const maxEntries = options.maxEntries ?? 12;
500
+ const maxBytes = options.maxBytes ?? 1000;
501
501
  const header = 'Open loops (the user said they would do these; not done yet):';
502
502
  const lines = [header];
503
503
  let used = bytes(header);