claude-mem-lite 6.32.0 → 6.34.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.
@@ -121,15 +121,73 @@ function bodiesSimilar(a, b, threshold) {
121
121
  return jaccardSimilarity(ba, bb) >= threshold;
122
122
  }
123
123
 
124
+ // A lesson as the rest of the code reads one: blank and the enrichers' 'none' carry nothing.
125
+ const hasLesson = (v) => typeof v === 'string' && v.trim() !== '' && v.trim().toLowerCase() !== 'none';
126
+
127
+ /**
128
+ * Which of two duplicate rows survives a merge or an auto-dedup: the one carrying a lesson,
129
+ * then the higher importance, then the more accessed, then `a`. Every dedup path keeps a row
130
+ * whole and hides or tombstones the other, nothing carried over, so keeping the bare copy put
131
+ * the lesson out of every search, recall and injection face (converge R28, E2E 2026-11-10:
132
+ * maintain scan's suggested merge, and both hook channels). Shared so the four paths agree.
133
+ * @param {{lesson?: string|null, importance?: number, accessCount?: number}} a
134
+ * @param {{lesson?: string|null, importance?: number, accessCount?: number}} b
135
+ * @returns {object} `a` or `b`
136
+ */
137
+ export function pickDedupKeeper(a, b) {
138
+ const la = hasLesson(a.lesson);
139
+ const lb = hasLesson(b.lesson);
140
+ if (la !== lb) return la ? a : b;
141
+ const ia = a.importance ?? 1;
142
+ const ib = b.importance ?? 1;
143
+ if (ia !== ib) return ia > ib ? a : b;
144
+ return (b.accessCount ?? 0) > (a.accessCount ?? 0) ? b : a;
145
+ }
146
+
147
+ /**
148
+ * The hook's exact auto-dedup channel: rows with the identical title in one project written
149
+ * within an hour of each other (the same hook firing twice, a race). Both sides live (audit
150
+ * 2026-08-14 H-1: a tombstone could otherwise come back as the keeper). The older row wins a
151
+ * tie, as it always did; a row carrying a lesson wins over one that does not.
152
+ * @returns {number[]} ids to stamp superseded
153
+ */
154
+ export function selectExactDedupeIds(db) {
155
+ const pairs = db
156
+ .prepare(
157
+ `
158
+ SELECT a.id AS a_id, a.importance AS a_imp, a.access_count AS a_acc, a.lesson_learned AS a_lesson,
159
+ b.id AS b_id, b.importance AS b_imp, b.access_count AS b_acc, b.lesson_learned AS b_lesson
160
+ FROM observations a
161
+ JOIN observations b ON a.title = b.title AND a.project = b.project
162
+ AND a.id < b.id
163
+ AND ABS(a.created_at_epoch - b.created_at_epoch) < 3600000
164
+ AND ${liveObsFilterSql('a')}
165
+ AND ${liveObsFilterSql('b')}
166
+ ORDER BY a.id, b.id
167
+ LIMIT 20
168
+ `,
169
+ )
170
+ .all();
171
+ // pickDedupKeeper orders rows totally (lesson, importance, access, then the older id), so the
172
+ // best row of a group loses no pair and the rest each lose at least one.
173
+ const removed = new Set();
174
+ for (const p of pairs) {
175
+ const a = { id: p.a_id, importance: p.a_imp, accessCount: p.a_acc, lesson: p.a_lesson };
176
+ const b = { id: p.b_id, importance: p.b_imp, accessCount: p.b_acc, lesson: p.b_lesson };
177
+ removed.add(pickDedupKeeper(a, b) === a ? b.id : a.id);
178
+ }
179
+ return [...removed];
180
+ }
181
+
124
182
  /**
125
183
  * Pick which near-duplicate observation ids to supersede in the hook fuzzy-dedup
126
184
  * pass. Pure (no DB) so it is unit-testable. A pair must clear BOTH the title
127
185
  * thresholds (MinHash prefilter → exact title Jaccard) AND the body Jaccard floor
128
- * before the lower-importance row is marked for superseding (audit #8 — title-only
186
+ * before the losing row (pickDedupKeeper) is marked for superseding (audit #8 — title-only
129
187
  * matching collapsed observations with the same title token-set but different bodies).
130
- * @param {Array<{id:number,project?:string,title:string,body:string,importance:number}>} rows
188
+ * @param {Array<{id:number,project?:string,title:string,body:string,importance:number,lesson?:string|null}>} rows
131
189
  * Candidate rows in scan order (caller decides ordering / recency window).
132
- * @returns {number[]} ids to supersede (lower-importance member of each kept pair).
190
+ * @returns {number[]} ids to supersede (the losing member of each kept pair).
133
191
  */
134
192
  export function selectFuzzyDedupeIds(
135
193
  rows,
@@ -155,8 +213,8 @@ export function selectFuzzyDedupeIds(
155
213
  if (estimateJaccardFromMinHash(minhashes[i], minhashes[j]) < minhashPrefilter) continue;
156
214
  if (jaccardSimilarity(titles[i], titles[j]) < titleThreshold) continue;
157
215
  if (!bodiesSimilar(rows[i].body, rows[j].body, bodyThreshold)) continue;
158
- // Keep the higher-importance row; tiebreak by earlier scan position (kept as i).
159
- const keep = (rows[i].importance ?? 1) >= (rows[j].importance ?? 1) ? rows[i] : rows[j];
216
+ // pickDedupKeeper: the lesson, then importance; a tie keeps the earlier scan position (i).
217
+ const keep = pickDedupKeeper(rows[i], rows[j]);
160
218
  const remove = keep === rows[i] ? rows[j] : rows[i];
161
219
  removeIds.push(remove.id);
162
220
  removed.add(remove.id);
@@ -826,7 +884,12 @@ export function reviewRows(db, ids) {
826
884
 
827
885
  /**
828
886
  * Near-duplicate title detection: MinHash pre-filter → exact Jaccard. Returns
829
- * [{ a:{id,title,importance}, b:{…}, similarity:'0.NN' }, …].
887
+ * [{ a:{id,title,importance,lesson,accessCount}, b:{…}, similarity:'0.NN' }, …]; callers pick
888
+ * the keeper with pickDedupKeeper.
889
+ *
890
+ * Rows a compression wrote (`compress-` writer: weekly summaries, cluster-merge keepers) are not
891
+ * candidates: a weekly summary is titled by its count and dominant type alone, so two different
892
+ * weeks scored 1.00 and the suggested merge hid one week's content (converge R28).
830
893
  */
831
894
  export function findDuplicates(
832
895
  db,
@@ -835,7 +898,7 @@ export function findDuplicates(
835
898
  const recent = db
836
899
  .prepare(
837
900
  `
838
- SELECT id, title, project, importance, access_count, created_at_epoch
901
+ SELECT id, title, project, importance, access_count, lesson_learned, created_at_epoch
839
902
  FROM observations
840
903
  -- liveObsFilterSql, not compressed_into alone (audit 2026-09-02 P0-2): this scan renders a
841
904
  -- ready-to-paste "maintain execute --ops dedup --merge-ids A,B", and the keeper rule is
@@ -843,6 +906,7 @@ export function findDuplicates(
843
906
  -- be nominated keeper. Same predicate the hook-side fuzzy dedup candidate query uses
844
907
  -- (hook.mjs), and the same one mergeDuplicates now enforces at write time.
845
908
  WHERE ${liveObsFilterSql('')} ${projectFilter}
909
+ AND COALESCE(memory_session_id, '') NOT LIKE 'compress-%'
846
910
  ORDER BY created_at_epoch DESC, id DESC LIMIT ${limit}
847
911
  `,
848
912
  )
@@ -861,9 +925,16 @@ export function findDuplicates(
861
925
  if (estimateJaccardFromMinHash(minhashes[i], minhashes[j]) < MINHASH_PRE_THRESHOLD) continue;
862
926
  const sim = jaccardSimilarity(titles[i], titles[j]);
863
927
  if (sim > SIMILARITY_THRESHOLD) {
928
+ const side = (r) => ({
929
+ id: r.id,
930
+ title: r.title,
931
+ importance: r.importance,
932
+ lesson: r.lesson_learned,
933
+ accessCount: r.access_count,
934
+ });
864
935
  duplicates.push({
865
- a: { id: recent[i].id, title: recent[i].title, importance: recent[i].importance },
866
- b: { id: recent[j].id, title: recent[j].title, importance: recent[j].importance },
936
+ a: side(recent[i]),
937
+ b: side(recent[j]),
867
938
  similarity: sim.toFixed(2),
868
939
  });
869
940
  }
@@ -93,7 +93,8 @@ export function computeStatsFeed(
93
93
  const daily = db
94
94
  .prepare(
95
95
  `
96
- SELECT date(created_at) as day, COUNT(*) as c FROM observations
96
+ -- The local day (D18), as every displayed date and the --from/--to filters read one.
97
+ SELECT date(created_at_epoch / 1000, 'unixepoch', 'localtime') as day, COUNT(*) as c FROM observations
97
98
  WHERE created_at_epoch >= ? ${projectFilter}
98
99
  GROUP BY day ORDER BY day DESC LIMIT 7
99
100
  `,
@@ -0,0 +1,91 @@
1
+ // D#825 — each turn's last reply, recorded at Stop under the memory session that answered it, for
2
+ // the session summary worker (D19 + D22). Reading the turns back out of the transcript had to
3
+ // infer which session a record belonged to, and that inference was wrong on real shapes: 148 of
4
+ // 1,939 simulated Stops on the maintainer's transcripts (2026-11-12) took another session's turn
5
+ // when cut at compactions alone, 57 still with a time floor (tasks/specs/d825-summary-turn-capture.md).
6
+ // Stop knows its own session and is handed the reply (`last_assistant_message`), so here nothing
7
+ // is inferred.
8
+ //
9
+ // One file per memory session in the runtime dir, keyed by prompt number: a turn's later reply
10
+ // (a background task's notice answered in the same turn) replaces the earlier one, and replies
11
+ // given before the session's first stored prompt (number 0) come first. SessionStart's 24 h
12
+ // runtime sweep removes the file; a session that expires (12 h) is summarized well before.
13
+
14
+ import { readFileSync, existsSync } from 'fs';
15
+ import { join } from 'path';
16
+ import { createHash } from 'crypto';
17
+ import { scrubSecrets } from '../secret-scrub.mjs';
18
+ import { atomicWriteFileSync } from './atomic-write.mjs';
19
+
20
+ export const TURN_REPLIES_PREFIX = 'turn-replies-';
21
+
22
+ // Code points kept per reply. The longest final reply over 1,939 Stops on the maintainer's
23
+ // transcripts was 7,081 (p99.9 5,187; 2026-11-12), and the summary prompt cuts every reply to at
24
+ // most 2,000 + 1,000 itself, so the cut only bounds the file.
25
+ export const TURN_REPLY_MAX_CHARS = 12000;
26
+ const HEAD = (TURN_REPLY_MAX_CHARS * 2) / 3;
27
+ const TAIL = TURN_REPLY_MAX_CHARS / 3;
28
+
29
+ /** The record file of `sessionId`; a long id keeps a hash of the whole id, so its tail still counts. */
30
+ export function turnRepliesPath(runtimeDir, sessionId) {
31
+ const id = String(sessionId);
32
+ const safe = id.replace(/[^a-zA-Z0-9_.-]/g, '-');
33
+ const key =
34
+ safe.length <= 120
35
+ ? safe
36
+ : `${safe.slice(0, 80)}-${createHash('sha256').update(id).digest('hex').slice(0, 16)}`;
37
+ return join(runtimeDir, `${TURN_REPLIES_PREFIX}${key}.json`);
38
+ }
39
+
40
+ /** Scrubbed whole first, so a secret across the cut is never half kept; then cut to head + tail. */
41
+ function storedText(reply) {
42
+ const text = scrubSecrets(String(reply ?? '')).trim();
43
+ const points = Array.from(text);
44
+ if (points.length <= TURN_REPLY_MAX_CHARS) return text;
45
+ const omitted = points.length - HEAD - TAIL;
46
+ return `${points.slice(0, HEAD).join('')}\n[… ${omitted} characters omitted …]\n${points.slice(-TAIL).join('')}`;
47
+ }
48
+
49
+ /** [promptNumber, text] pairs from the file, or [] when it is missing, unreadable or of another shape. */
50
+ function readPairs(file) {
51
+ try {
52
+ const turns = JSON.parse(readFileSync(file, 'utf8'))?.turns;
53
+ if (!Array.isArray(turns)) return [];
54
+ return turns.filter(
55
+ (t) => Array.isArray(t) && Number.isInteger(t[0]) && t[0] >= 0 && typeof t[1] === 'string' && t[1],
56
+ );
57
+ } catch {
58
+ return [];
59
+ }
60
+ }
61
+
62
+ /**
63
+ * Record `reply` as the last reply of prompt `promptNumber` in `sessionId` (0 before the first
64
+ * stored prompt). A blank reply records nothing. Never throws.
65
+ * @returns {boolean} whether the file was written
66
+ */
67
+ export function recordTurnReply(runtimeDir, sessionId, promptNumber, reply) {
68
+ if (!sessionId || !Number.isInteger(promptNumber) || promptNumber < 0) return false;
69
+ const text = storedText(reply);
70
+ if (!text) return false;
71
+ // A missing runtime dir records nothing (the atomic writer would create it).
72
+ if (!existsSync(runtimeDir)) return false;
73
+ const file = turnRepliesPath(runtimeDir, sessionId);
74
+ const turns = new Map(readPairs(file));
75
+ turns.set(promptNumber, text);
76
+ try {
77
+ atomicWriteFileSync(file, JSON.stringify({ turns: [...turns].sort((a, b) => a[0] - b[0]) }), {
78
+ mode: 0o600,
79
+ });
80
+ return true;
81
+ } catch {
82
+ return false;
83
+ }
84
+ }
85
+
86
+ /** Each turn's last reply in `sessionId`, in prompt order; [] when none was recorded. */
87
+ export function readTurnReplies(runtimeDir, sessionId) {
88
+ if (!sessionId) return [];
89
+ // Written in prompt order (recordTurnReply sorts), so read in file order.
90
+ return readPairs(turnRepliesPath(runtimeDir, sessionId)).map((t) => t[1]);
91
+ }
package/mem-cli.mjs CHANGED
@@ -13,6 +13,7 @@ import {
13
13
  inferProject,
14
14
  scrubSecrets,
15
15
  COMPRESSED_PENDING_PURGE,
16
+ localYmd,
16
17
  } from './utils.mjs';
17
18
  import { isBlankText } from './lib/blank-text.mjs';
18
19
  import { resolveProject, checkWriteProject, unknownProjectNote } from './project-utils.mjs';
@@ -57,6 +58,7 @@ import { selectCompressionCandidates, groupByProjectWeek, compressGroup } from '
57
58
  import {
58
59
  runMaintainOps,
59
60
  findDuplicates,
61
+ pickDedupKeeper,
60
62
  reviewRows,
61
63
  maintenanceStats,
62
64
  OP_CAP,
@@ -176,11 +178,9 @@ import { aggregateMetrics, readMetrics } from './lib/metrics.mjs';
176
178
  import {
177
179
  insertDeferred,
178
180
  listOpenWithOrdinal,
179
- openOrdinalOf,
180
181
  deferredDropLabel,
181
- dropDeferred,
182
+ dropDeferredMany,
182
183
  formatDropReasonHint,
183
- resolveDeferredIds,
184
184
  getDeferredByIds,
185
185
  formatDeferredDetail,
186
186
  searchDeferredWork,
@@ -1453,8 +1453,11 @@ function cmdSave(db, args) {
1453
1453
  }
1454
1454
 
1455
1455
  if (result.kind === 'duplicate') {
1456
+ // converge R28: say what did not happen — a --lesson riding on the refused save is gone too —
1457
+ // and the way past the window for a memory that really is different (--force).
1458
+ const lost = rawLesson ? ', including the lesson' : '';
1456
1459
  out(
1457
- `[mem] Skipped: similar to existing #${result.existingId}. Use "${CLI_INVOKE} get ${result.existingId}" to review.`,
1460
+ `[mem] Skipped: similar to existing #${result.existingId} — nothing was saved${lost}. Use "${CLI_INVOKE} get ${result.existingId}" to review; if this is a different memory, run the same save with --force.`,
1458
1461
  );
1459
1462
  // D#201: the dedup swallowed the requested supersession too — say so here,
1460
1463
  // because this branch returns before the note below is ever reached.
@@ -1561,10 +1564,9 @@ function cmdDeferAdd(db, args) {
1561
1564
  fail(`[mem] defer add failed: ${e.message}`);
1562
1565
  return;
1563
1566
  }
1564
- // Compute the freshly-inserted row's ordinal for an immediately-actionable
1565
- // response ("ok, deferred this as item N"), as mem_defer does.
1566
- const ord = openOrdinalOf(db, project, r.id) ?? '?';
1567
- out(`[mem] Deferred as D#${r.id} (item ${ord}) in project "${project}".${projectCheck.note}`);
1567
+ // D#N only (D17): an `(item N)` here went stale on the next higher-priority add, and dropping by
1568
+ // it hit another item.
1569
+ out(`[mem] Deferred as D#${r.id} in project "${project}".${projectCheck.note}`);
1568
1570
  }
1569
1571
 
1570
1572
  function cmdDeferList(db, args) {
@@ -1617,20 +1619,15 @@ function cmdDeferDrop(db, args) {
1617
1619
  const tokens = rawTokens.map((t) => (/^\d+$/.test(t) ? parseInt(t, 10) : t));
1618
1620
  const project = flags.project ? resolveProject(db, flags.project) : cliProject(db);
1619
1621
 
1620
- let realIds;
1622
+ // One transaction for every token (dropDeferredMany): a bad id, or a failure part-way, drops
1623
+ // nothing, so retrying the same ordinals cannot hit renumbered items.
1624
+ let dropped, noop;
1621
1625
  try {
1622
- realIds = resolveDeferredIds(db, project, tokens);
1626
+ ({ dropped, noop } = dropDeferredMany(db, project, tokens, reason));
1623
1627
  } catch (e) {
1624
1628
  fail(`[mem] defer drop: ${e.message}`);
1625
1629
  return;
1626
1630
  }
1627
- const dropped = [];
1628
- const noop = [];
1629
- for (const realId of realIds) {
1630
- const r = dropDeferred(db, realId, reason);
1631
- if (r.changed === 0) noop.push(realId);
1632
- else dropped.push(realId);
1633
- }
1634
1631
  if (dropped.length > 0) {
1635
1632
  out(
1636
1633
  `[mem] Dropped ${dropped.map((id) => deferredDropLabel(db, id)).join(', ')} in project "${project}". Reason: ${reason.trim()}`,
@@ -2797,14 +2794,14 @@ function cmdMaintain(db, args) {
2797
2794
  if (autoMergeable.length > 0) {
2798
2795
  out(` Auto-mergeable (similarity >= ${AUTO_MERGE_THRESHOLD}):`);
2799
2796
  for (const d of autoMergeable.slice(0, 15)) {
2800
- const keep = (d.a.importance ?? 1) >= (d.b.importance ?? 1) ? d.a : d.b;
2797
+ const keep = pickDedupKeeper(d.a, d.b);
2801
2798
  const remove = keep === d.a ? d.b : d.a;
2802
2799
  out(
2803
2800
  ` [${keep.id}] "${truncate(keep.title, 40)}" <-> [${remove.id}] "${truncate(remove.title, 40)}" (${d.similarity})`,
2804
2801
  );
2805
2802
  }
2806
2803
  const mergeIds = autoMergeable.map((d) => {
2807
- const keep = (d.a.importance ?? 1) >= (d.b.importance ?? 1) ? d.a : d.b;
2804
+ const keep = pickDedupKeeper(d.a, d.b);
2808
2805
  const remove = keep === d.a ? d.b : d.a;
2809
2806
  return `${keep.id}:${remove.id}`;
2810
2807
  });
@@ -2905,8 +2902,8 @@ function cmdMaintain(db, args) {
2905
2902
  lines.push(' Nothing to delete.');
2906
2903
  return lines.join('\n');
2907
2904
  }
2908
- lines.push(` Oldest: ${new Date(previewRow.oldest).toISOString().slice(0, 10)}`);
2909
- lines.push(` Newest: ${new Date(previewRow.newest).toISOString().slice(0, 10)}`);
2905
+ lines.push(` Oldest: ${localYmd(previewRow.oldest)}`);
2906
+ lines.push(` Newest: ${localYmd(previewRow.newest)}`);
2910
2907
  lines.push(' To delete, re-run with --confirm.');
2911
2908
  return lines.join('\n');
2912
2909
  },
@@ -3202,7 +3199,7 @@ function cmdCitationStats(db, args) {
3202
3199
  out(' (no resolved sessions in window)');
3203
3200
  } else {
3204
3201
  for (const s of funnel.sessions) {
3205
- const day = s.resolved_at ? new Date(s.resolved_at).toISOString().slice(0, 10) : '—'.repeat(10);
3202
+ const day = s.resolved_at ? localYmd(s.resolved_at) : '—'.repeat(10);
3206
3203
  const pct = (s.rate * 100).toFixed(1) + '%';
3207
3204
  out(
3208
3205
  ` ${day} ${(s.project || '').padEnd(28)} inj ${String(s.injected_n).padStart(3)} cited ${String(s.cited_n).padStart(3)} ${pct.padStart(6)}`,
@@ -3393,13 +3390,15 @@ Commands:
3393
3390
  --narrative T New narrative
3394
3391
  --concepts T Space-separated concept tags
3395
3392
 
3396
- export Export observations as JSON/JSONL (complete backup by default)
3393
+ export Export observations as JSON/JSONL (every live observation by default;
3394
+ rows hidden from search — compressed, merged or idle — need
3395
+ --include-compressed)
3397
3396
  --project P Filter by project
3398
3397
  --type T Filter by type
3399
3398
  --format F json (default) or jsonl
3400
3399
  --from DATE Start date
3401
3400
  --to DATE End date
3402
- --include-compressed Include compressed observations
3401
+ --include-compressed Also export rows hidden from search (compressed, merged or idle)
3403
3402
  --limit N Cap output at N rows (default: export ALL matching rows)
3404
3403
  restore <file> Restore observations from an export file (JSON/JSONL)
3405
3404
  --project P Override the restored project for every row
@@ -3454,6 +3453,16 @@ Commands:
3454
3453
  --session-audit Audit session/episode state for orphans and drift
3455
3454
  --json Machine-readable output (plain doctor run)
3456
3455
 
3456
+ status Show the install's state (--json for structured output)
3457
+ repair Recover a broken install: download the latest package, re-run install
3458
+ rebuild-binding Recompile better-sqlite3 for the running Node (fixes
3459
+ "NODE_MODULE_VERSION" after a Node upgrade)
3460
+ self-update Check for and install updates
3461
+ cleanup Remove stale temp/staging files (--dry-run to preview)
3462
+ cleanup-hooks Remove only claude-mem-lite's hooks from Claude Code's settings
3463
+ install Install or re-install (what \`npx claude-mem-lite\` runs)
3464
+ uninstall Remove the install, keep the data (--purge also deletes the data)
3465
+
3457
3466
  fts-check <check|rebuild> FTS5 index check, or a rebuild of the FTS5 indexes and then
3458
3467
  every other index (REINDEX)
3459
3468
  Exit 0 when the FTS5 indexes are healthy (check) or every index
@@ -3994,9 +4003,23 @@ export async function run(argv) {
3994
4003
  }
3995
4004
  }
3996
4005
 
4006
+ // cmdArgs with `--project .` / `--project current` (and the `=` forms) spelled as the current
4007
+ // project. Words after a bare `--` are text, not flags, and stay as written.
4008
+ function currentProjectSpelled(cmdArgs, current) {
4009
+ const isCurrent = (v) => v === '.' || v === 'current';
4010
+ const out = [...cmdArgs];
4011
+ for (let i = 0; i < out.length; i++) {
4012
+ if (out[i] === '--') break;
4013
+ if (out[i] === '--project' && isCurrent(out[i + 1])) out[i + 1] = current();
4014
+ else if (out[i].startsWith('--project=') && isCurrent(out[i].slice('--project='.length)))
4015
+ out[i] = `--project=${current()}`;
4016
+ }
4017
+ return out;
4018
+ }
4019
+
3997
4020
  async function runDispatch(argv) {
3998
4021
  const cmd = argv[0];
3999
- const cmdArgs = argv.slice(1);
4022
+ let cmdArgs = argv.slice(1);
4000
4023
 
4001
4024
  if (!cmd || cmd === 'help' || cmd === '--help' || cmd === '-h') {
4002
4025
  cmdHelp();
@@ -4347,6 +4370,10 @@ async function runDispatch(argv) {
4347
4370
  const note = unknownProjectNote(db, projectFlag);
4348
4371
  if (note) process.stderr.write(`[mem] ${note}\n`);
4349
4372
  }
4373
+ // `.` and `current` name the current project on every command, as optimize always read them.
4374
+ // Elsewhere they matched a project literally named "." — no results and no note on a read,
4375
+ // a new project of that name on a write (converge R28, E2E 2026-11-10).
4376
+ cmdArgs = currentProjectSpelled(cmdArgs, () => cliProject(db));
4350
4377
 
4351
4378
  try {
4352
4379
  switch (cmd) {
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "claude-mem-lite",
3
- "version": "6.32.0",
3
+ "version": "6.34.0",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "claude-mem-lite",
9
- "version": "6.32.0",
9
+ "version": "6.34.0",
10
10
  "os": [
11
11
  "darwin",
12
12
  "linux",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "claude-mem-lite",
3
- "version": "6.32.0",
3
+ "version": "6.34.0",
4
4
  "description": "Persistent long-term memory for Claude Code via MCP — captures coding decisions, bugfixes, and context across sessions. FTS5 BM25 keyword search with episode batching. Single SQLite DB, no external services. A lighter, lower-cost alternative to claude-mem (episode batching + a smaller model; cost savings are an internal estimate, not a measured benchmark).",
5
5
  "type": "module",
6
6
  "packageManager": "npm@10.9.2",
@@ -97,6 +97,7 @@
97
97
  "lib/cooldown-path.mjs",
98
98
  "lib/tmp-fixture-sweep.mjs",
99
99
  "lib/summary-extractor.mjs",
100
+ "lib/turn-replies.mjs",
100
101
  "lib/id-routing.mjs",
101
102
  "lib/err-sampler.mjs",
102
103
  "lib/hook-telemetry.mjs",
package/schema.mjs CHANGED
@@ -212,6 +212,8 @@ const LATEST_MIGRATION_COLUMNS = [
212
212
  // must also run when the column exists but events_fts is still (or again) the 4-column shape
213
213
  // (tests/events-cjk-search.test.mjs pins the upgrade).
214
214
  { table: 'events_fts', column: 'search_terms' },
215
+ // D21, no bump either (tests/d21-events-session-id.test.mjs pins the upgrade).
216
+ { table: 'events', column: 'memory_session_id' },
215
217
  { table: 'observations', column: 'last_access_session_id' }, // v48
216
218
  { table: 'observations', column: 'decay_seen_at_first_cite' }, // v46
217
219
  { table: 'citation_surface_log', column: 'surface' }, // v45
@@ -837,7 +839,8 @@ export function initSchema(db) {
837
839
  last_accessed_epoch INTEGER,
838
840
  superseded_at_epoch INTEGER,
839
841
  superseded_by_id INTEGER REFERENCES events(id),
840
- search_terms TEXT
842
+ search_terms TEXT,
843
+ memory_session_id TEXT
841
844
  );
842
845
  CREATE INDEX IF NOT EXISTS idx_events_project ON events(project);
843
846
  CREATE INDEX IF NOT EXISTS idx_events_type ON events(event_type);
@@ -867,6 +870,13 @@ export function initSchema(db) {
867
870
  .all()
868
871
  .map((c) => c.name);
869
872
  if (!eventCols.includes('search_terms')) db.exec(`ALTER TABLE events ADD COLUMN search_terms TEXT`);
873
+ // D21 (2026-11-11): the session an episode-written event came from, so the session summary can
874
+ // read it (it read `observations` alone and missed every episode typed as an event). Additive +
875
+ // nullable, no CURRENT_SCHEMA_VERSION bump: an older build opening this DB ignores the column and
876
+ // its event writes leave it NULL. Outside a swallowing catch for the search_terms reason: saveEvent
877
+ // names the column, so carrying on without it would fail every event write.
878
+ if (!eventCols.includes('memory_session_id'))
879
+ db.exec(`ALTER TABLE events ADD COLUMN memory_session_id TEXT`);
870
880
 
871
881
  // v42: column-aware self-heal for events_fts (the one FTS table the generic ensureFTS can't
872
882
  // manage — UNINDEXED cols + custom tokenizer + events_fts_* triggers). Creates events_fts and its
package/secret-scrub.mjs CHANGED
@@ -297,6 +297,14 @@ export const SECRET_PATTERNS = [
297
297
  ],
298
298
  // npm tokens (npm_...)
299
299
  [/\bnpm_[a-zA-Z0-9]{36,}(?![A-Za-z0-9])/g, '***'],
300
+ // D#812: fixed-prefix, fixed-body provider tokens. Shapes from gitleaks (config/gitleaks.toml
301
+ // @ 5f6ec56c: huggingface-*, digitalocean-*, pypi-upload-token, shopify-*) and trufflehog
302
+ // (pkg/detectors/groq). Each body is one character class, so a failing match is linear.
303
+ [/\b(?:hf|api_org)_[a-zA-Z0-9]{34}(?![A-Za-z0-9])/g, '***'],
304
+ [/\bdo[opr]_v1_[a-f0-9]{64}(?![A-Za-z0-9])/g, '***'],
305
+ [/\bpypi-AgE[A-Za-z0-9_-]{50,}/g, '***'],
306
+ [/\bshp(?:at|ca|pa|ss)_[a-fA-F0-9]{32}(?![A-Za-z0-9])/g, '***'],
307
+ [/\bgsk_[a-zA-Z0-9]{52}(?![A-Za-z0-9])/g, '***'],
300
308
  // Stripe keys (sk_live_, rk_live_, pk_live_, sk_test_, pk_test_) + webhook signing secret (whsec_)
301
309
  [/\b[srp]k_(?:live|test)_[a-zA-Z0-9]{20,}(?![A-Za-z0-9])/g, '***'],
302
310
  [/\bwhsec_[a-zA-Z0-9]{20,}(?![A-Za-z0-9])/g, '***'],