claude-mem-lite 6.32.0 → 6.33.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.
@@ -9,7 +9,7 @@
9
9
  "plugins": [
10
10
  {
11
11
  "name": "claude-mem-lite",
12
- "version": "6.32.0",
12
+ "version": "6.33.0",
13
13
  "source": "./",
14
14
  "homepage": "https://github.com/sdsrss/claude-mem-lite",
15
15
  "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)."
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "claude-mem-lite",
3
- "version": "6.32.0",
3
+ "version": "6.33.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
  "author": {
6
6
  "name": "sdsrss"
package/README.md CHANGED
@@ -239,6 +239,23 @@ rm -rf ~/claude-mem-lite/ # unhidden data dir from before the first release (n
239
239
  repos/ # Shallow-cloned source repos
240
240
  ```
241
241
 
242
+ ## Upgrading to 6.33.0
243
+
244
+ **`uninstall --purge` leaves your own files in a relocated data directory; nothing to run, and the
245
+ schema version stays 49.** The first open adds a nullable column to `events`, which an older build
246
+ ignores. To go back, pin `claude-mem-lite@6.32.0`.
247
+
248
+ - **With `CLAUDE_MEM_DIR` set, `uninstall --purge` removes only what claude-mem-lite writes
249
+ there**: its files by each writer's exact file-name format, and its `runtime/` and `managed/`
250
+ directories whole when nothing of yours sits beside them. It names what it leaves. It used to
251
+ remove the whole directory, your files included. The default
252
+ `~/.claude-mem-lite` is removed whole, as before.
253
+ - **The daily unattended maintenance pass no longer runs `normalize`**, which rewrote concept tags
254
+ with model-picked synonym groups and kept no record. Run it yourself with
255
+ `claude-mem-lite optimize --run --task normalize` (`--run-all` skips its weekly gate).
256
+ - **Dates and times are shown in local time**, the zone the date filters already read.
257
+ - Details in CHANGELOG.md.
258
+
242
259
  ## Upgrading to 6.32.0
243
260
 
244
261
  **The steering sync looks above the repository before writing its copy; nothing to run, and the
@@ -1290,7 +1307,7 @@ benchmark and A/B harness are calibrated against — changing them invalidates t
1290
1307
  | `CLAUDE_MEM_AUTO_DEEP` | `0` disables automatic deep-search escalation (one Haiku call rewriting a weak query into keyword/concept/HyDE variants). Explicit `deep: true` still works. | _(auto)_ |
1291
1308
  | `CLAUDE_MEM_DEEP_DISCLOSURE` | `off` suppresses the one-line caveat appended to a multi-variant deep result. The caveat exists because deep search fills the page even when the corpus cannot answer — measured at 10 of 10 slots on queries whose answers had been removed (`benchmark/deep-search-holdout.mjs`) — and `deep` is AUTO by default on the MCP surface, i.e. it escalates precisely when the honest answer is "nothing". It does not change retrieval, ranking, or which rows are returned. | _(on)_ |
1292
1309
  | `CLAUDE_MEM_REACH_DISCLOSURE` | `off` suppresses the one-line note that fires when a search's reported `total` exceeds what its pagination can hand back. The candidate pool is sized from `limit` alone and deliberately does not grow with `offset` (D#30 — an offset-scaled pool re-ranks its own prefix under RRF, so pages overlapped and gapped), while `total` is the full match count. Measured on a 128-row corpus: at the default limit of 20 the last non-empty offset is 59, so 60 of 128 rows are unreachable at any offset. The note reports that; it does not change retrieval, ranking, or which rows are returned. It stays **silent** when a filter you asked for (`tier`, or the CJK precision gate on prompts) removed rows after the count was taken — that gap is your filter, not the pool, and raising the limit would not recover it. | _(on)_ |
1293
- | `CLAUDE_MEM_NORMALIZE_CROSS_PROJECT` | `1` restores the pre-fix behaviour where the daily unattended `normalize` runs ONCE over every project's concepts at the same time. That is how one project's stored content could steer synonym groups applied to another project's rows, so the default is now one scoped pass per project (bounded to 8 per run). The cost of the default is that `k8s` in one project and `kubernetes` in another are no longer unified automatically. Note that EVERY unscoped run fans out, including an explicit `optimize --run --task normalize` with no `--project` — this variable is the only route back to the single cross-project pass. A foreground `optimize` run prints a warning when it is set; the daily unattended pass cannot (its worker is spawned with stderr closed), so `claude-mem-lite doctor` reports it as a ⚠ instead. | _(off)_ |
1310
+ | `CLAUDE_MEM_NORMALIZE_CROSS_PROJECT` | `1` restores the pre-fix behaviour where a `normalize` run without `--project` goes ONCE over every project's concepts at the same time. That is how one project's stored content could steer synonym groups applied to another project's rows, so the default is now one scoped pass per project (bounded to 8 per run). The cost of the default is that `k8s` in one project and `kubernetes` in another are no longer unified automatically. Note that EVERY unscoped run fans out, including an explicit `optimize --run --task normalize` with no `--project` — this variable is the only route back to the single cross-project pass. A foreground `optimize` run prints a warning when it is set, and `claude-mem-lite doctor` reports it as a ⚠ for `mem_optimize`, whose stderr is the MCP log. The daily unattended pass does not run normalize. | _(off)_ |
1294
1311
  | `CLAUDE_MEM_AUTO_DEEP_CLI` | `0` disables the same auto-escalation on the CLI path only. | _(auto)_ |
1295
1312
  | `CLAUDE_MEM_UPS_PROMPT_ECHO` | `0` lets the "Past similar questions" fallback show a stored question identical (or nearly) to the prompt just typed, from an earlier session. The current session's own prompts stay excluded either way: showing the prompt just typed was a bug. | _(on)_ |
1296
1313
  | `CLAUDE_MEM_SCOPE_FILTER` | `1` stops environment-scoped observations from firing on file-triggered recall. They stay reachable via search. **Leave it off**: on the face it gates, `environment` is not the low-relevance class its premise assumes — it cites at least as well as `project` (47.5% vs 44.3%, intervals overlapping), and an earlier measurement left 173 recall groups empty with it on. | _(off)_ |
@@ -1332,7 +1349,7 @@ what is already stored — only whether new work runs.
1332
1349
  | `CLAUDE_MEM_SKIP_SAVE_ENRICH` | Skip the background Haiku call that backfills `lesson_learned` / search aliases after a save. | _(runs)_ |
1333
1350
  | `CLAUDE_MEM_SKIP_COMPRESS` | Skip auto-compression of old observations. | _(runs)_ |
1334
1351
  | `CLAUDE_MEM_SKIP_MAINTAIN` | Skip the 24h auto-maintain pass (decay, purge, backup). | _(runs)_ |
1335
- | `CLAUDE_MEM_SKIP_OPTIMIZE` | Skip the LLM optimization pass (re-enrich, normalize, cluster-merge). | _(runs)_ |
1352
+ | `CLAUDE_MEM_SKIP_OPTIMIZE` | Skip the daily LLM optimization pass (re-enrich, cluster-merge, smart-compress). | _(runs)_ |
1336
1353
  | `CLAUDE_MEM_SKIP_AUTO_DEDUP_FUZZY` | Skip the MinHash near-duplicate pass, keeping exact dedup. | _(runs)_ |
1337
1354
  | `CLAUDE_MEM_SKIP_MARKER_GC` | Skip the runtime-marker sweep. **Must be exactly `1`** — unlike the other `CLAUDE_MEM_SKIP_*` flags, which accept any truthy value, this one compares against the string `1`. That is deliberate: a truthy check makes `=0` mean "skip", which is the opposite of what anyone typing it intends. | _(runs)_ |
1338
1355
  | `CLAUDE_MEM_SKIP_UPDATE` | Skip the 24h update check against GitHub Releases, its session-start notice, and `self-update` / `install.mjs update` (unset it to update). A `repair` triggered by a missing module or dependency still runs. | _(runs)_ |
package/README.zh-CN.md CHANGED
@@ -201,6 +201,15 @@ rm -rf ~/claude-mem-lite/ # 首个发布版之前的非隐藏目录(不是
201
201
  repos/ # 浅克隆的源代码仓库
202
202
  ```
203
203
 
204
+ ## 升级到 6.33.0
205
+
206
+ **数据目录改过位置时,`uninstall --purge` 不再删你自己的文件;不用执行任何操作,schema 版本仍是 49。** 第一次打开数据库时会给 `events` 加一个可空列,旧版本会忽略它。想退回,请固定 `claude-mem-lite@6.32.0`。
207
+
208
+ - **设了 `CLAUDE_MEM_DIR` 时,`uninstall --purge` 只删 claude-mem-lite 在那里写的东西**:按每个写入方的确切文件名格式匹配的文件;旁边没有你的东西时,再整个删掉它的 `runtime/` 和 `managed/` 目录。留下的东西会列出来。以前会删掉整个目录,连同你的文件。默认目录 `~/.claude-mem-lite` 仍然整个删除,和以前一样。
209
+ - **每日无人值守的维护不再运行 `normalize`**:它按模型挑的同义词组改写概念标签,而且不留记录。需要时手动运行 `claude-mem-lite optimize --run --task normalize`(用 `--run-all` 可跳过它的每周闸门)。
210
+ - **日期和时间按本地时区显示**,和日期筛选一直使用的时区一致。
211
+ - 详见 CHANGELOG.md。
212
+
204
213
  ## 升级到 6.32.0
205
214
 
206
215
  **写引导副本之前,插件先看仓库之上的文件;不用执行任何操作,schema 版本仍是 49。** 想退回,请固定 `claude-mem-lite@6.31.0`;它的下一个会话会把本地副本写回来。用户或项目设置里有 `claudeMdExcludes` 时,下面两条都不适用。
package/cli/activity.mjs CHANGED
@@ -17,9 +17,11 @@ import { snapshotDb } from '../lib/db-backup.mjs';
17
17
  import { isBlankText } from '../lib/blank-text.mjs';
18
18
  import { CLI_INVOKE } from '../cli-path.mjs';
19
19
 
20
+ // E#N, the form search, get and --supersedes use for an event: a bare #N names an observation
21
+ // everywhere else, so an id copied from this list into `delete` hit an unrelated row (converge R30).
20
22
  function formatActivityResults(rows) {
21
23
  if (!rows || rows.length === 0) return '(no events)';
22
- return rows.map((r) => `#${r.id} [${r.event_type}] ${r.title}`).join('\n');
24
+ return rows.map((r) => `E#${r.id} [${r.event_type}] ${r.title}`).join('\n');
23
25
  }
24
26
 
25
27
  /** An event id as typed: N, #N or E#N (the form search and get print), else null. */
package/cli/common.mjs CHANGED
@@ -9,7 +9,13 @@
9
9
  // consistent.
10
10
 
11
11
  import { editDistance } from '../lib/edit-distance.mjs';
12
- import { neutralizeContextDelimiters, neutralizeSkillDelimiters, truncate } from '../format-utils.mjs';
12
+ import {
13
+ neutralizeContextDelimiters,
14
+ neutralizeSkillDelimiters,
15
+ truncate,
16
+ localYmd,
17
+ localIsoTime,
18
+ } from '../format-utils.mjs';
13
19
  import { CLI_INVOKE } from '../cli-path.mjs';
14
20
 
15
21
  // ─── Argument Parsing ────────────────────────────────────────────────────────
@@ -554,10 +560,10 @@ export function relativeTime(epochMs) {
554
560
  return `${days}d ago`;
555
561
  }
556
562
 
557
- /** ISO date string → "YYYY-MM-DD" prefix. */
563
+ /** ISO date string → its local "YYYY-MM-DD" (D18: the day `--from/--to` read it as). */
558
564
  export function fmtDateShort(iso) {
559
565
  if (!iso) return '';
560
- return iso.slice(0, 10);
566
+ return localYmd(iso) || String(iso).slice(0, 10);
561
567
  }
562
568
 
563
569
  // Integer epoch-ms time fields on the observations table that `get`/`mem_get`
@@ -627,6 +633,10 @@ export function formatObsFieldValue(field, val) {
627
633
  if (OBS_TIME_FIELDS.includes(field) && typeof val === 'number') {
628
634
  return `${val} (${relativeTime(val)})`;
629
635
  }
636
+ // The stored ISO string is UTC; shown raw, its date is the next day for an evening save west of
637
+ // Greenwich, a day the date filters (local) do not find it on (D18). The CLI shows the local
638
+ // day in its header instead and skips the field.
639
+ if (field === 'created_at' && typeof val === 'string') return localIsoTime(val) || val;
630
640
  return val;
631
641
  }
632
642
 
@@ -671,6 +681,6 @@ export function formatReviewSide(row) {
671
681
  row.lesson_learned && row.lesson_learned !== 'none'
672
682
  ? `lesson: ${flat(row.lesson_learned, 100)}`
673
683
  : 'no lesson';
674
- const date = row.created_at_epoch ? new Date(row.created_at_epoch).toISOString().slice(0, 10) : '?';
684
+ const date = row.created_at_epoch ? localYmd(row.created_at_epoch) : '?';
675
685
  return `#${row.id} ${row.type || '?'} · importance ${row.importance ?? '?'} · ${row.project} · ${date} · ${lesson} · ${flat(row.narrative, 120) || '(no narrative)'}`;
676
686
  }
package/format-utils.mjs CHANGED
@@ -309,23 +309,62 @@ export function typeIcon(type) {
309
309
 
310
310
  const MONTHS = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
311
311
 
312
+ // Displayed dates and times are LOCAL (D18, converge R31, user-chosen 2026-11-11): `--from/--to`
313
+ // and date_from/date_to read a bare date as the local day (lib/search-core.mjs parseCalendarBound),
314
+ // and the dates printed in UTC disagreed with them — an evening save west of Greenwich showed as
315
+ // tomorrow and the date on screen did not find it.
316
+
317
+ /**
318
+ * A date (Date, epoch ms or ISO string) as the local calendar day "YYYY-MM-DD"; '' when unparseable.
319
+ * @param {Date|number|string} value
320
+ * @returns {string}
321
+ */
322
+ export function localYmd(value) {
323
+ if (value === null || value === undefined || value === '') return '';
324
+ const d = value instanceof Date ? value : new Date(value);
325
+ if (Number.isNaN(d.getTime())) return '';
326
+ const m = String(d.getMonth() + 1).padStart(2, '0');
327
+ const day = String(d.getDate()).padStart(2, '0');
328
+ return `${d.getFullYear()}-${m}-${day}`;
329
+ }
330
+
331
+ /**
332
+ * An instant (Date, epoch ms or ISO string) as local ISO 8601 with its UTC offset,
333
+ * "2026-11-10T21:52:00.000-08:00": the same instant as the stored UTC string, milliseconds
334
+ * included (writers store them, and a shown time pasted back as an inclusive `date_to` must not
335
+ * fall before its own row), and its date is the local day the date filters read. For detail
336
+ * views that print a full timestamp. '' when unparseable.
337
+ * @param {Date|number|string} value
338
+ * @returns {string}
339
+ */
340
+ export function localIsoTime(value) {
341
+ if (value === null || value === undefined || value === '') return '';
342
+ const d = value instanceof Date ? value : new Date(value);
343
+ if (Number.isNaN(d.getTime())) return '';
344
+ const p = (n) => String(n).padStart(2, '0');
345
+ const off = -d.getTimezoneOffset();
346
+ const zone = `${off < 0 ? '-' : '+'}${p(Math.floor(Math.abs(off) / 60))}:${p(Math.abs(off) % 60)}`;
347
+ const ms = String(d.getMilliseconds()).padStart(3, '0');
348
+ return `${localYmd(d)}T${p(d.getHours())}:${p(d.getMinutes())}:${p(d.getSeconds())}.${ms}${zone}`;
349
+ }
350
+
312
351
  /**
313
- * Format an ISO date string as "Mon DD HH:MM" for compact display.
352
+ * Format an ISO date string as local "Mon DD HH:MM" for compact display.
314
353
  * @param {string} iso ISO 8601 date string
315
354
  * @returns {string} Formatted date or empty string
316
355
  */
317
356
  export function fmtDate(iso) {
318
357
  if (!iso) return '';
319
358
  const d = new Date(iso);
320
- const mon = MONTHS[d.getUTCMonth()];
321
- const day = d.getUTCDate();
322
- const h = String(d.getUTCHours()).padStart(2, '0');
323
- const m = String(d.getUTCMinutes()).padStart(2, '0');
359
+ const mon = MONTHS[d.getMonth()];
360
+ const day = d.getDate();
361
+ const h = String(d.getHours()).padStart(2, '0');
362
+ const m = String(d.getMinutes()).padStart(2, '0');
324
363
  return `${mon} ${day} ${h}:${m}`;
325
364
  }
326
365
 
327
366
  /**
328
- * Format an ISO date string as "HH:MM" for time-only display.
367
+ * Format an ISO date string as local "HH:MM" for time-only display.
329
368
  * @param {string} iso ISO 8601 date string
330
369
  * @returns {string} Formatted time or empty string
331
370
  */
@@ -333,11 +372,11 @@ export function fmtTime(iso) {
333
372
  if (!iso) return '';
334
373
  const d = new Date(iso);
335
374
  // Guard against an unparseable timestamp (e.g. corrupt/imported created_at):
336
- // a bare new Date('garbage') yields Invalid Date → getUTCHours() is NaN →
375
+ // a bare new Date('garbage') yields Invalid Date → getHours() is NaN →
337
376
  // "NaN:NaN" leaking into the SessionStart Recent table. Degrade to '' like the
338
377
  // falsy-input case above.
339
378
  if (Number.isNaN(d.getTime())) return '';
340
- return `${String(d.getUTCHours()).padStart(2, '0')}:${String(d.getUTCMinutes()).padStart(2, '0')}`;
379
+ return `${String(d.getHours()).padStart(2, '0')}:${String(d.getMinutes()).padStart(2, '0')}`;
341
380
  }
342
381
 
343
382
  // ─── ISO Week ────────────────────────────────────────────────────────────────
package/hook-context.mjs CHANGED
@@ -13,6 +13,7 @@ import {
13
13
  truncate,
14
14
  typeIcon,
15
15
  fmtTime,
16
+ localYmd,
16
17
  inferProject,
17
18
  debugLog,
18
19
  neutralizeContextDelimiters,
@@ -757,7 +758,10 @@ export function buildSessionContextLines(
757
758
  if (recentObs.length > 0) {
758
759
  summaryLines.push('### Recent Activity');
759
760
  for (const o of recentObs) {
760
- summaryLines.push(`- ${truncate(o.title || '(untitled)', 80)}`);
761
+ // A row the top-up borrowed from another project says whose it is, as the Recent table
762
+ // does; bare, the model read it as this project's history (converge R30, E2E hooks F5).
763
+ const proj = o.project && o.project !== project ? ` (${o.project})` : '';
764
+ summaryLines.push(`- ${truncate(o.title || '(untitled)', 80)}${proj}`);
761
765
  }
762
766
  summaryLines.push('');
763
767
  }
@@ -930,17 +934,17 @@ export function buildSessionContextLines(
930
934
  (a, b) => Date.parse(b.created_at) - Date.parse(a.created_at) || b.id - a.id,
931
935
  );
932
936
  if (obsToShow.length > 0) {
933
- const today = now.toISOString().slice(0, 10);
937
+ const today = localYmd(now);
934
938
  obsLines.push(`### Recent (${today})`);
935
939
  obsLines.push('');
936
940
  obsLines.push('| ID | Time | T | Title |');
937
941
  obsLines.push('|----|------|---|-------|');
938
942
  // A row from another day carries its date: under the "Recent (<today>)" heading a bare
939
943
  // HH:MM read as today, and a 5-day-old row looked like this morning's (E2E 2026-10-16).
940
- // Same UTC calendar as the heading.
944
+ // Same local calendar as the heading (D18).
941
945
  const when = (iso) =>
942
- typeof iso === 'string' && fmtTime(iso) && iso.slice(0, 10) !== today
943
- ? `${iso.slice(5, 10)} ${fmtTime(iso)}`
946
+ typeof iso === 'string' && fmtTime(iso) && localYmd(iso) !== today
947
+ ? `${localYmd(iso).slice(5)} ${fmtTime(iso)}`
944
948
  : fmtTime(iso);
945
949
  for (const o of obsToShow) {
946
950
  const proj = o.project && o.project !== project ? ` (${o.project})` : '';
package/hook-llm.mjs CHANGED
@@ -545,6 +545,8 @@ export function persistHaikuSummary(db, summary, ctx) {
545
545
  : null,
546
546
  importance: summary.importance ?? 1,
547
547
  created_at_epoch: Date.now(),
548
+ // D21: so the session summary can read the episodes this session stored as events.
549
+ memory_session_id: ctx.session_id ?? null,
548
550
  });
549
551
 
550
552
  if (ctx.preSavedObsId) {
@@ -1728,6 +1730,84 @@ async function waitForEpisodeFlushes(flushTimeout, superseded) {
1728
1730
  return false;
1729
1731
  }
1730
1732
 
1733
+ /**
1734
+ * D19 — how much of the session's final reply the summary prompt carries: its first
1735
+ * SUMMARY_REPLY_HEAD and last SUMMARY_REPLY_TAIL characters. On this machine's 159 sessions
1736
+ * (2026-11-11) the reply's median length was 2293 chars, p90 3211, max 4704, and the report
1737
+ * convention there puts the open items LAST, so a head-only cut would drop exactly the part
1738
+ * that says what is left (tasks/specs/converge-r31-decisions.md).
1739
+ */
1740
+ export const SUMMARY_REPLY_HEAD = 2000;
1741
+ export const SUMMARY_REPLY_TAIL = 1000;
1742
+
1743
+ /**
1744
+ * The final reply as the summary prompt carries it: scrubbed whole first, so a secret
1745
+ * straddling a cut is never half-kept, then cut to head + tail with the omitted length named.
1746
+ * Cuts land on code-point boundaries. Empty for an empty or missing reply.
1747
+ */
1748
+ export function summaryReplyExcerpt(reply) {
1749
+ const text = scrubSecrets(String(reply ?? '')).trim();
1750
+ const points = Array.from(text);
1751
+ if (points.length <= SUMMARY_REPLY_HEAD + SUMMARY_REPLY_TAIL) return text;
1752
+ const omitted = points.length - SUMMARY_REPLY_HEAD - SUMMARY_REPLY_TAIL;
1753
+ return `${points.slice(0, SUMMARY_REPLY_HEAD).join('')}\n[… ${omitted} characters omitted …]\n${points.slice(-SUMMARY_REPLY_TAIL).join('')}`;
1754
+ }
1755
+
1756
+ /**
1757
+ * D21: one list for the summary prompt, newest first. An event becomes an observation-shaped
1758
+ * row (its body is the lesson or narrative the episode stored); at equal times the observation
1759
+ * comes first, so the order never depends on the two tables' unrelated ids.
1760
+ * @param {{created_at_epoch?: number}[]} observations newest first
1761
+ * @param {{event_type: string, title: string, body: string|null, created_at_epoch: number}[]} events
1762
+ */
1763
+ export function mergeSummaryRows(observations, events) {
1764
+ const rows = [
1765
+ ...observations.map((o) => ({ row: o, at: o.created_at_epoch ?? 0, table: 0 })),
1766
+ ...events.map((e) => ({
1767
+ row: { type: e.event_type, title: e.title, narrative: e.body || '' },
1768
+ at: e.created_at_epoch ?? 0,
1769
+ table: 1,
1770
+ })),
1771
+ ];
1772
+ rows.sort((a, b) => b.at - a.at || a.table - b.table);
1773
+ return rows.map((r) => r.row);
1774
+ }
1775
+
1776
+ /**
1777
+ * The session summary prompt. `observations` are {type, title, narrative} newest first,
1778
+ * `userPrompts` the raw prompt texts in order; both are cut here. `finalReply`, when given, is
1779
+ * the session's last assistant message (D19): it goes into the user part behind the same input
1780
+ * guard, and the system part says the outcome it reports wins. Without one the prompt is the
1781
+ * one shipped before D19, byte for byte.
1782
+ */
1783
+ export function buildSessionSummaryPrompt({ project, observations, userPrompts, finalReply }) {
1784
+ const obsList = observations
1785
+ .map((o, i) => `${i + 1}. [${o.type}] ${o.title}${o.narrative ? ': ' + truncate(o.narrative, 200) : ''}`)
1786
+ .join('\n');
1787
+ const prompts = userPrompts.map((p) => truncate(p, 300));
1788
+ const promptCtx = prompts.length > 0 ? `\nUser requests: ${prompts.join(' → ')}\n` : '';
1789
+ const reply = summaryReplyExcerpt(finalReply);
1790
+
1791
+ // cso F#4: split system/user. The userPrompts content is the single highest-leakage path
1792
+ // for memory poisoning — putting it in the user role behind an explicit boundary is the
1793
+ // main win here. The final reply is captured content too and goes on the same side.
1794
+ const system = `Summarize this coding session. Return ONLY valid JSON, no markdown fences.
1795
+ ${MEMORY_INPUT_GUARD}
1796
+
1797
+ JSON: {"request":"what the user was working on","completed":"specific items accomplished with file names","remaining_items":"specific unfinished items from the original request — compare investigation scope with actual changes to infer what was NOT yet done; be precise with file:issue format, or empty string if all done","next_steps":"suggested follow-up","lessons":["non-obvious insights discovered during this session"],"key_decisions":["important design choices made and WHY"]}
1798
+ lessons: Only genuinely non-obvious insights (debugging discoveries, gotchas, architectural reasons). Empty array if routine.
1799
+ key_decisions: Only decisions with lasting impact (library choices, architecture, data model). Include reasoning. Empty array if none.${
1800
+ reply
1801
+ ? `
1802
+ Final reply: the user message ends with the session's final reply, the assistant's own account of the outcome. Work it reports as done (tests passed, saved, committed, fixed) is completed — never list it in remaining_items or next_steps. What it reports as unfinished, failed or left for later belongs in remaining_items.`
1803
+ : ''
1804
+ }`;
1805
+ const user = `Project: ${project}${promptCtx}
1806
+ Observations (${observations.length} total):
1807
+ ${obsList}${reply ? `\n\nFinal reply:\n${reply}` : ''}`;
1808
+ return { system, user };
1809
+ }
1810
+
1731
1811
  export async function handleLLMSummary() {
1732
1812
  // Seconds. The default spans an episode worker's whole bound (E2E 2026-10-16 P2-4): it was 15,
1733
1813
  // below one CLI-leg episode (2-5 s delay + 8-13 s call, + the lesson retry on a bugfix), so the
@@ -1789,12 +1869,6 @@ export async function handleLLMSummary() {
1789
1869
 
1790
1870
  if (recentObs.length < 1) return outcome('no-obs');
1791
1871
 
1792
- const obsList = recentObs
1793
- .map(
1794
- (o, i) => `${i + 1}. [${o.type}] ${o.title}${o.narrative ? ': ' + truncate(o.narrative, 200) : ''}`,
1795
- )
1796
- .join('\n');
1797
-
1798
1872
  // Include user prompts for richer context
1799
1873
  const userPrompts = db
1800
1874
  .prepare(
@@ -1804,22 +1878,8 @@ export async function handleLLMSummary() {
1804
1878
  `,
1805
1879
  )
1806
1880
  .all(sessionId)
1807
- .map((p) => truncate(p.prompt_text, 300));
1808
- const promptCtx = userPrompts.length > 0 ? `\nUser requests: ${userPrompts.join(' → ')}\n` : '';
1809
-
1810
- // cso F#4: split system/user. The userPrompts content (line 921) is the
1811
- // single highest-leakage path for memory poisoning — putting it in the
1812
- // user role behind an explicit boundary is the main win here.
1813
- const system = `Summarize this coding session. Return ONLY valid JSON, no markdown fences.
1814
- ${MEMORY_INPUT_GUARD}
1815
-
1816
- JSON: {"request":"what the user was working on","completed":"specific items accomplished with file names","remaining_items":"specific unfinished items from the original request — compare investigation scope with actual changes to infer what was NOT yet done; be precise with file:issue format, or empty string if all done","next_steps":"suggested follow-up","lessons":["non-obvious insights discovered during this session"],"key_decisions":["important design choices made and WHY"]}
1817
- lessons: Only genuinely non-obvious insights (debugging discoveries, gotchas, architectural reasons). Empty array if routine.
1818
- key_decisions: Only decisions with lasting impact (library choices, architecture, data model). Include reasoning. Empty array if none.`;
1819
- const user = `Project: ${project}${promptCtx}
1820
- Observations (${recentObs.length} total):
1821
- ${obsList}`;
1822
- const prompt = { system, user };
1881
+ .map((p) => p.prompt_text);
1882
+ const prompt = buildSessionSummaryPrompt({ project, observations: recentObs, userPrompts });
1823
1883
 
1824
1884
  if (!(await acquireLLMSlot())) {
1825
1885
  debugLog('WARN', 'llm-summary', 'semaphore timeout, skipping summary');
package/hook-optimize.mjs CHANGED
@@ -1063,24 +1063,11 @@ export async function executeNormalize(db, force = false, { project } = {}) {
1063
1063
  // was simply still using the legacy unscoped mode.
1064
1064
  if (!project) {
1065
1065
  if (String(process.env.CLAUDE_MEM_NORMALIZE_CROSS_PROJECT || '') === '1') {
1066
- // This reaches a caller that OWNS ITS STDERR, and that bound is the whole story of
1067
- // the line. Three callers reach here: the CLI (`optimize --run --task normalize`,
1068
- // the user's own terminal), the MCP server (`mem_optimize`, server.mjs:1545 — its
1069
- // stderr is the host's MCP log, so this does land somewhere a human can reach), and
1070
- // the daily unattended pass, which is the one that cannot.
1071
- // Second review moved it off `debugLog` (which returns early unless
1072
- // CLAUDE_MEM_DEBUG is set, and the detached worker does not set it) and the test
1073
- // certifying the repair spied on `console.error` IN PROCESS — which proves the
1074
- // function emits, not that anyone receives. Nobody does, on the path that matters:
1075
- // `hook.mjs` reaches this via `spawnBackground('llm-optimize')`, and hook-shared.mjs
1076
- // spawns with `stdio: 'ignore'`, so the child's fd 2 IS /dev/null. Dropping the
1077
- // CLAUDE_MEM_DEBUG gate removed one of two blockers and the remaining one is
1078
- // sufficient on its own.
1079
- // So: useful for `claude-mem-lite optimize --run --task normalize`, silent for the
1080
- // daily unattended pass. The unattended disclosure is carried by `doctor`, which the
1081
- // user runs in their own terminal — same shape and prefix as install.mjs's
1082
- // CLAUDE_MEM_SKIP_SIG_VERIFY notice. Do not delete either half; they cover different
1083
- // paths, and tests/normalize-cross-project-disclosure.test.mjs pins both.
1066
+ // console.error, not debugLog (which returns early unless CLAUDE_MEM_DEBUG is set). Two
1067
+ // callers reach here: the CLI (`optimize --run --task normalize`, the user's own
1068
+ // terminal) and the MCP server (`mem_optimize`, whose stderr is the host's MCP log). The
1069
+ // daily pass does not since D20 (2026-11-11). `doctor` repeats the disclosure where the
1070
+ // user looks; tests/normalize-cross-project-disclosure.test.mjs pins both halves.
1084
1071
  console.error(
1085
1072
  '[claude-mem-lite] WARNING: CLAUDE_MEM_NORMALIZE_CROSS_PROJECT=1 — normalize is ' +
1086
1073
  'running over every project at once, so one project’s stored content can steer the ' +
@@ -2091,6 +2078,12 @@ export async function optimizeRun(
2091
2078
  return results;
2092
2079
  }
2093
2080
 
2081
+ /** What the daily unattended pass runs (D20: no normalize). Exported for its test. */
2082
+ export const DAILY_OPTIMIZE = Object.freeze({
2083
+ reenrichScope: 'wide',
2084
+ tasks: Object.freeze(['re-enrich', 'cluster-merge', 'smart-compress']),
2085
+ });
2086
+
2094
2087
  export async function handleLLMOptimize() {
2095
2088
  const { ensureDb } = await import('./schema.mjs');
2096
2089
  let db;
@@ -2108,10 +2101,18 @@ export async function handleLLMOptimize() {
2108
2101
  // targets bugfix/refactor/feature/decision rows with substantive narrative
2109
2102
  // but missing lesson_learned, which is exactly the audit's 11.2% coverage
2110
2103
  // gap. CLI `mem optimize` keeps narrow as default for explicit invocations.
2111
- const results = await optimizeRun(db, { reenrichScope: 'wide' });
2104
+ //
2105
+ // No normalize here (D20, 2026-11-11). It rewrites observations.concepts with whatever
2106
+ // synonym groups the model returns, and one real call on a copy of the maintainer's store
2107
+ // returned 21 groups, about half of them not synonyms (`fmtDate <- date`,
2108
+ // `CLAUDE.md <- CLAUDE.local.md`); nothing recorded the rewrite and nothing undoes it. The
2109
+ // groups it gets right are mostly case and plural variants, which search already covers:
2110
+ // the FTS tokenizer folds case, wordFormPrefixQuery adds the stem prefix, and the original
2111
+ // word stays in search_aliases. An explicit `optimize --run --task normalize` still runs it.
2112
+ // The three tasks keep the budgets they had: distributeBudget's normalize share is nominal.
2113
+ const results = await optimizeRun(db, { ...DAILY_OPTIMIZE, tasks: [...DAILY_OPTIMIZE.tasks] });
2112
2114
  const parts = [];
2113
2115
  if (results.reenrich?.processed) parts.push(`re-enriched: ${results.reenrich.processed}`);
2114
- if (results.normalize?.processed) parts.push(`normalized: ${results.normalize.processed}`);
2115
2116
  if (results.clusterMerge?.merged) parts.push(`merged: ${results.clusterMerge.merged}`);
2116
2117
  if (results.smartCompress?.compressed) parts.push(`compressed: ${results.smartCompress.compressed}`);
2117
2118
  if (parts.length > 0) debugLog('DEBUG', 'llm-optimize', parts.join(', '));
package/hook.mjs CHANGED
@@ -153,6 +153,7 @@ import {
153
153
  resolveDefaultMaintainOps,
154
154
  markAutoCompressible,
155
155
  selectFuzzyDedupeIds,
156
+ selectExactDedupeIds,
156
157
  stampDedupSuperseded,
157
158
  hardDeleteCandidateCount,
158
159
  purgeStale,
@@ -2173,34 +2174,13 @@ function runSessionStartAutoMaintain(db, project) {
2173
2174
  debugLog('DEBUG', 'auto-maintain', `boosted ${boosted} frequently-accessed observations`);
2174
2175
 
2175
2176
  // Auto-dedup (exact): merge identical-title observations within 1h.
2176
- // Catches rapid duplicate writes (same hook firing twice, race conditions).
2177
- // BOTH join sides must be live (audit 2026-08-14 H-1): without the
2178
- // superseded_at filters (which the fuzzy channel below always had), a row the
2179
- // fuzzy pass had tombstoned could come back as `a` (a.id < b.id) and tombstone
2180
- // the LIVE keeper `b` — both copies gone from every read path. Worse, a user
2181
- // correction saved with supersedes=[#A] (A.superseded_by = B's NUMERIC id) has
2182
- // the same title as A, so the pair (A, B) tombstoned the correction B itself
2183
- // and the string 'auto-dedup' write clobbered numeric supersession chains that
2184
- // citation-tracker decay hand-off and timeline re-anchoring both follow. The
2185
- // UPDATE repeats the guard so a concurrent writer can't re-stamp a chain.
2186
- const dupPairs = db
2187
- .prepare(
2188
- `
2189
- SELECT a.id as keep_id, b.id as remove_id
2190
- FROM observations a
2191
- JOIN observations b ON a.title = b.title AND a.project = b.project
2192
- AND a.id < b.id
2193
- AND ABS(a.created_at_epoch - b.created_at_epoch) < 3600000
2194
- AND ${liveObsFilterSql('a')}
2195
- AND ${liveObsFilterSql('b')}
2196
- LIMIT 20
2197
- `,
2198
- )
2199
- .all();
2200
- if (dupPairs.length > 0) {
2201
- const removeIds = dupPairs.map((p) => p.remove_id);
2177
+ // Catches rapid duplicate writes (same hook firing twice, race conditions). Both join
2178
+ // sides live (audit 2026-08-14 H-1); the keeper is the copy carrying a lesson, then the
2179
+ // older one (converge R28) — lib/maintain-core.mjs selectExactDedupeIds.
2180
+ const removeIds = selectExactDedupeIds(db);
2181
+ if (removeIds.length > 0) {
2202
2182
  stampDedupSuperseded(db, removeIds, 'auto-dedup');
2203
- debugLog('DEBUG', 'auto-maintain', `auto-deduped ${dupPairs.length} near-identical observations`);
2183
+ debugLog('DEBUG', 'auto-maintain', `auto-deduped ${removeIds.length} near-identical observations`);
2204
2184
  }
2205
2185
 
2206
2186
  // Auto-dedup (fuzzy): catches near-identical titles that exact-match
@@ -2222,7 +2202,7 @@ function runSessionStartAutoMaintain(db, project) {
2222
2202
  const recent = db
2223
2203
  .prepare(
2224
2204
  `
2225
- SELECT id, project, title, importance, created_at_epoch, narrative, text
2205
+ SELECT id, project, title, importance, created_at_epoch, narrative, text, lesson_learned
2226
2206
  FROM observations
2227
2207
  WHERE ${liveObsFilterSql('')}
2228
2208
  AND created_at_epoch > ?
@@ -2240,6 +2220,7 @@ function runSessionStartAutoMaintain(db, project) {
2240
2220
  project: r.project,
2241
2221
  title: r.title,
2242
2222
  importance: r.importance,
2223
+ lesson: r.lesson_learned,
2243
2224
  body: (r.narrative && r.narrative.trim()) || (r.text && r.text.trim()) || '',
2244
2225
  }));
2245
2226
  const fuzzyRemoveIds = selectFuzzyDedupeIds(rows, { maxMerges: FUZZY_MAX_MERGES });