claude-mem-lite 2.34.1 → 2.34.3

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.
@@ -10,7 +10,7 @@
10
10
  "plugins": [
11
11
  {
12
12
  "name": "claude-mem-lite",
13
- "version": "2.34.1",
13
+ "version": "2.34.3",
14
14
  "source": "./",
15
15
  "description": "Lightweight persistent memory system for Claude Code — FTS5 search, episode batching, error-triggered recall"
16
16
  }
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "claude-mem-lite",
3
- "version": "2.34.1",
3
+ "version": "2.34.3",
4
4
  "description": "Lightweight persistent memory system for Claude Code — FTS5 search, episode batching, error-triggered recall",
5
5
  "author": {
6
6
  "name": "sdsrss"
package/mem-cli.mjs CHANGED
@@ -742,8 +742,11 @@ function cmdTimeline(db, args) {
742
742
  return;
743
743
  }
744
744
 
745
- const projectFilter = project ? 'AND project = ?' : '';
746
- const baseParams = project ? [project] : [];
745
+ // Auto-scope to anchor's project when --project not explicitly given: users asking
746
+ // "what happened around #N" expect same-project context, not cross-project time-bleed.
747
+ const effectiveProject = project || anchorRow.project;
748
+ const projectFilter = effectiveProject ? 'AND project = ?' : '';
749
+ const baseParams = effectiveProject ? [effectiveProject] : [];
747
750
 
748
751
  // Before anchor
749
752
  const beforeRows = db.prepare(`
@@ -1721,17 +1724,26 @@ function cmdMaintain(db, args) {
1721
1724
  }
1722
1725
 
1723
1726
  if (ops.includes('dedup') && flags['merge-ids']) {
1724
- // Parse merge-ids: "keepId:removeId1:removeId2,keepId2:removeId3" format
1727
+ // Parse merge-ids: "keepId:removeId1:removeId2,keepId2:removeId3" format.
1728
+ // Surface malformed segments (non-numeric tokens, single-element pairs) instead of
1729
+ // silently dropping them, so typos like "abc:def" don't hide behind "Merged 0".
1725
1730
  let totalMerged = 0;
1731
+ const invalidSegments = [];
1726
1732
  const mergeStmt = db.prepare('UPDATE observations SET compressed_into = ? WHERE id = ? AND COALESCE(compressed_into, 0) = 0');
1727
- const groups = flags['merge-ids'].split(',').map(g => g.trim().split(':').map(Number).filter(n => !isNaN(n)));
1728
- for (const group of groups) {
1729
- if (group.length < 2) continue;
1730
- const [keepId, ...removeIds] = group;
1733
+ const rawSegments = flags['merge-ids'].split(',').map(s => s.trim()).filter(Boolean);
1734
+ for (const seg of rawSegments) {
1735
+ const parts = seg.split(':').map(s => s.trim());
1736
+ const nums = parts.map(p => Number(p));
1737
+ const badToken = parts.length < 2 || nums.some(n => !Number.isFinite(n) || n <= 0);
1738
+ if (badToken) { invalidSegments.push(seg); continue; }
1739
+ const [keepId, ...removeIds] = nums;
1731
1740
  for (const removeId of removeIds) {
1732
1741
  totalMerged += mergeStmt.run(keepId, removeId).changes;
1733
1742
  }
1734
1743
  }
1744
+ if (invalidSegments.length) {
1745
+ results.push(`Warning: ignored ${invalidSegments.length} malformed --merge-ids segment(s): ${invalidSegments.join(', ')} (expected keepId:removeId[:removeId...] with positive integers)`);
1746
+ }
1735
1747
  results.push(`Merged ${totalMerged} duplicate observations`);
1736
1748
  }
1737
1749
 
@@ -2070,6 +2082,16 @@ Commands:
2070
2082
  --project P Filter by project
2071
2083
  --retain-days N For purge_stale: keep last N days (default 30)
2072
2084
 
2085
+ optimize LLM-powered memory optimization (preview by default)
2086
+ --run Execute (default: preview gates)
2087
+ --run-all Execute bypassing gates
2088
+ --task T Comma-separated: re-enrich,normalize,cluster-merge,smart-compress
2089
+ --max N Max items per task (1-100, default 15)
2090
+ --scope S re-enrich scope: narrow (default) or wide
2091
+
2092
+ doctor Environment diagnostics and benchmarks
2093
+ --benchmark Run perf benchmark and emit JSON
2094
+
2073
2095
  fts-check <check|rebuild> FTS5 index check or rebuild
2074
2096
 
2075
2097
  stats Show memory statistics
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "claude-mem-lite",
3
- "version": "2.34.1",
3
+ "version": "2.34.3",
4
4
  "description": "Lightweight persistent memory system for Claude Code",
5
5
  "type": "module",
6
6
  "engines": {
@@ -188,15 +188,19 @@ try {
188
188
  const lines = [];
189
189
  if (allRows.length > 0) {
190
190
  lines.push(`[mem] Lessons for ${fname}:`);
191
+ // R3-UX: raised from 120 → 240 after measuring 97% of lessons exceed 120 chars
192
+ // (p50=218, avg=247). Previous limit truncated the actionable "Fix:" tail in 80%
193
+ // of lessons containing it. 3 × 240 ≈ 180 tokens/Edit — negligible context cost.
194
+ const LESSON_MAX = 240;
191
195
  for (const r of allRows) {
192
196
  if (r.lesson_learned) {
193
- const lesson = r.lesson_learned.length > 120
194
- ? r.lesson_learned.slice(0, 117) + '...'
197
+ const lesson = r.lesson_learned.length > LESSON_MAX
198
+ ? r.lesson_learned.slice(0, LESSON_MAX - 3) + '...'
195
199
  : r.lesson_learned;
196
200
  lines.push(` #${r.id} [${r.type}] ${lesson}`);
197
201
  } else {
198
- const title = (r.title || '').length > 120
199
- ? r.title.slice(0, 117) + '...'
202
+ const title = (r.title || '').length > LESSON_MAX
203
+ ? r.title.slice(0, LESSON_MAX - 3) + '...'
200
204
  : (r.title || '');
201
205
  lines.push(` #${r.id} [${r.type}] ${title}`);
202
206
  }
@@ -16,18 +16,18 @@ const INJECTED_IDS_FILE = join(DB_DIR, 'runtime', `.claude-mem-injected-${inferP
16
16
  const MAX_RESULTS = 5;
17
17
  const LOOKBACK_MS = 60 * 86400000; // 60 days
18
18
 
19
- // T3 (v2.31): BM25 magnitude threshold. OBS_BM25 (in scoring-sql.mjs) returns the
20
- // raw bm25() value, which in SQLite FTS5 is always negative lower = better match.
21
- // The `relevance` column multiplies that negative bm25 by positive decay / type /
22
- // importance weights, keeping the sign negative. "Stronger match" therefore means
23
- // larger magnitude, so we compare against `Math.abs(relevance)`.
19
+ // T3 (v2.31): per-row BM25 magnitude floor. OBS_BM25 (in scoring-sql.mjs)
20
+ // returns the raw bm25() value negative, smaller = better. Multiplied by
21
+ // decay × type-quality × (0.5+0.5·importance), sign stays negative. We
22
+ // compare against Math.abs(relevance).
24
23
  //
25
- // Empirically (see Task 3 probe in docs/plans/2026-04-14-mem-v2.31-mvp.md):
26
- // - OR-fallback single-stem match: |rel| ~ 3e-6
27
- // - Multi-term AND match w/ importance+type boost: |rel| ~ 2e-5 .. 5e-5
28
- // The plan's hinted default (3.5) was a guess that's six orders of magnitude too
29
- // high for this codebase's scoring expression. 1e-5 suppresses OR-fallback noise
30
- // while preserving real hits. Env-overridable for tuning without a redeploy.
24
+ // v2.34.3 note: the historic comment claimed |rel| falls in 3e-6..5e-5 range.
25
+ // Re-measured against real data (see v2.34.3 CHANGELOG probe), actual scores
26
+ // span ~6..133 across SIGNAL / META / NOISE prompts the scoring expression
27
+ // was revised in later versions and this constant was never retuned. 1e-5 now
28
+ // acts as a NULL-rel guard, not a real noise filter. The primary noise gate
29
+ // is TOP_REL_FLOOR below, which drops the whole FTS set when the best match
30
+ // is weak.
31
31
  const BM25_MIN_SCORE = Number(process.env.CLAUDE_MEM_UPS_BM25_MIN || 1e-5);
32
32
  // Raw-character minimum length for the prompt. Additional to the CJK-weighted
33
33
  // `shouldSkip()` effective-length gate; catches medium-short Latin prompts that
@@ -41,6 +41,27 @@ const PROMPT_MIN_LENGTH = 15;
41
41
  const FOLLOWUP_PROMPT_MIN_LENGTH = 8;
42
42
  const FOLLOWUP_BM25_MIN_SCORE = Number(process.env.CLAUDE_MEM_UPS_BM25_MIN_FOLLOWUP || 5e-6);
43
43
 
44
+ // v2.34.3: top-|rel| sanity gate. BM25_MIN_SCORE filters per-row; this floor
45
+ // gates the entire FTS set. Noise prompts ("today's date", "current time")
46
+ // produce OR-fallback leakage where every hit shares one tangential stem and
47
+ // per-row filtering leaves all of them through. When the best match scores
48
+ // below this floor, the whole FTS result set is dropped.
49
+ //
50
+ // Empirical distribution (v2.34.3 probe, 12 prompts):
51
+ // SIGNAL top-|rel| 60..133
52
+ // NOISE top-|rel| 25..48
53
+ // WEAK-META 6.86..33
54
+ // Default 50 sits in the clean 48→60 gap. Env override for project tuning.
55
+ // Error-signature hits (sigRows) and file-recall (fileRows) bypass this gate —
56
+ // both are precision passes with independent relevance signal.
57
+ //
58
+ // Note: no follow-up halving (unlike PROMPT_MIN_LENGTH / BM25_MIN_SCORE).
59
+ // Those lower the length/per-row bar to let short context-dependent prompts
60
+ // through, but the top-|rel| gap is an absolute distribution separator —
61
+ // lowering it in follow-up mode re-admits the 37..48 noise band that the
62
+ // gate exists to drop.
63
+ const TOP_REL_FLOOR = Number(process.env.CLAUDE_MEM_UPS_TOP_MIN || 50);
64
+
44
65
  function isFollowUpSession() {
45
66
  try {
46
67
  const raw = readFileSync(INJECTED_IDS_FILE, 'utf8');
@@ -323,6 +344,16 @@ async function main() {
323
344
  typeof r.relevance === 'number' && Math.abs(r.relevance) >= bm25Floor
324
345
  );
325
346
 
347
+ // v2.34.3: top-|rel| sanity gate. Per-row filtering above leaves noise
348
+ // prompts intact when many rows share a weak stem (all in 25..48 range).
349
+ // If the best remaining FTS match is below the top floor, drop the
350
+ // whole FTS set — noise prompts should produce no FTS injection.
351
+ // Query orders by `relevance` ASC; negative values → ftsRows[0] has the
352
+ // largest magnitude (strongest match) in this scoring expression.
353
+ if (ftsRows.length > 0 && Math.abs(ftsRows[0].relevance) < TOP_REL_FLOOR) {
354
+ ftsRows = [];
355
+ }
356
+
326
357
  // Merge: FTS results first, then file results, deduplicated
327
358
  const seen = new Set(ftsRows.map(r => r.id));
328
359
  rows = [...ftsRows];
package/server.mjs CHANGED
@@ -789,8 +789,11 @@ server.registerTool(
789
789
  db.prepare('UPDATE observations SET access_count = COALESCE(access_count, 0) + 1, last_accessed_at = ? WHERE id = ?').run(Date.now(), anchorId);
790
790
  } catch { /* non-critical: FTS5 trigger may fail on corrupted index */ }
791
791
 
792
- const projectFilter = args.project ? 'AND project = ?' : '';
793
- const baseParams = args.project ? [args.project] : [];
792
+ // Auto-scope to anchor's project when caller didn't pass one: "timeline around #N"
793
+ // means same-project context by default; cross-project bleed breaks user mental model.
794
+ const effectiveProject = args.project || anchorRow.project;
795
+ const projectFilter = effectiveProject ? 'AND project = ?' : '';
796
+ const baseParams = effectiveProject ? [effectiveProject] : [];
794
797
 
795
798
  // Before anchor
796
799
  const beforeRows = db.prepare(`