claude-mem-lite 6.35.3 → 6.35.5

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.35.3",
12
+ "version": "6.35.5",
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.35.3",
3
+ "version": "6.35.5",
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/adopt-cli.mjs CHANGED
@@ -1078,10 +1078,15 @@ function unadoptProject(dir, dryRun) {
1078
1078
  if (r.action === 'removed') {
1079
1079
  log(`[unadopt --all] ${dir} → removed`);
1080
1080
  n.blocks++;
1081
+ } else if (r.action === 'skipped-symlink') {
1082
+ log(`[unadopt --all] ${dir} → skipped-symlink`);
1083
+ n.failures++;
1081
1084
  } else {
1082
1085
  log(`[unadopt --all] ${dir} → cleaned partial residue (detail doc/state, no block)`);
1083
1086
  n.partial++;
1084
1087
  }
1088
+ for (const l of r.left ?? []) log(` ⚠ left ${l.link} alone: ${l.why}`);
1089
+ if (r.action === 'skipped-symlink') log(` ⚠ ${BLOCK_LEFT_NOTE}`);
1085
1090
  // OUTSIDE the branch, because residue is orthogonal to what happened to the block: a
1086
1091
  // project can have its block removed AND still carry an unpaired sentinel. An orphan is
1087
1092
  // the one kind of residue the sweep cannot finish — its block has no end marker, so its
@@ -1092,6 +1097,11 @@ function unadoptProject(dir, dryRun) {
1092
1097
  return n;
1093
1098
  }
1094
1099
 
1100
+ // unadopt's line when CLAUDE.md is a link it will not write through: the block, the detail doc and its
1101
+ // state file all stay, and only the user can take the block out (v6.35.4 pre-tag round 1, F5).
1102
+ const BLOCK_LEFT_NOTE =
1103
+ 'the block stays in the file CLAUDE.md links to, and the detail doc and its state file stay too: remove the block from that file by hand, then run unadopt again';
1104
+
1095
1105
  export function cmdUnadopt(args = []) {
1096
1106
  if (hasFlag(args, '--status')) return statusAll();
1097
1107
 
@@ -1126,6 +1136,11 @@ export function cmdUnadopt(args = []) {
1126
1136
  const mig = migrateLegacyMemoryDir(cwd, PLUGIN_SLUG, { force });
1127
1137
  const migNote = mig.action === 'removed' ? ' (+cleaned legacy memdir)' : '';
1128
1138
  log(`[unadopt] ${cwd} → ${r.action}${migNote}`);
1139
+ for (const l of r.left ?? []) log(` ⚠ left ${l.link} alone: ${l.why}`);
1140
+ if (r.action === 'skipped-symlink') {
1141
+ log(` ⚠ ${BLOCK_LEFT_NOTE}`);
1142
+ process.exitCode = 1;
1143
+ }
1129
1144
  const local = dropLocalSteering(cwd);
1130
1145
  if (local.action !== 'absent') log(`[unadopt] ${local.path} → ${local.action}`);
1131
1146
  if (local.residue) log(` ⚠ ${local.residue}`);
package/claudemd.mjs CHANGED
@@ -18,6 +18,7 @@
18
18
  import { existsSync, unlinkSync, mkdirSync, rmdirSync, readdirSync, lstatSync, statSync } from 'fs';
19
19
  import { atomicWriteFileSync as atomicWrite } from './lib/atomic-write.mjs';
20
20
  import { readRegularText, readRegularTextOrThrow } from './lib/regular-file.mjs';
21
+ import { linkRefusal, refusalText } from './lib/project-link.mjs';
21
22
  import { join, basename } from 'path';
22
23
  import { createHash } from 'crypto';
23
24
  import { memdirPath, removePluginSection, removePluginDoc, isAdopted as memdirIsAdopted } from './memdir.mjs';
@@ -34,11 +35,26 @@ export function claudeMdPath(cwd) {
34
35
  function dotClaudeDir(cwd) {
35
36
  return join(cwd, '.claude');
36
37
  }
38
+ const docRel = (slug) => `.claude/plugin_${slugSnake(slug)}.md`;
39
+ const stateRel = (slug) => `.claude/.plugin_${slugSnake(slug)}_state.json`;
37
40
  export function detailDocPath(cwd, slug) {
38
- return join(dotClaudeDir(cwd), `plugin_${slugSnake(slug)}.md`);
41
+ return join(cwd, docRel(slug));
39
42
  }
40
43
  function stateFilePath(cwd, slug) {
41
- return join(dotClaudeDir(cwd), `.plugin_${slugSnake(slug)}_state.json`);
44
+ return join(cwd, stateRel(slug));
45
+ }
46
+
47
+ // The three files adopt writes, each with whether the plugin writes it whole (lib/project-link.mjs).
48
+ const managedTargets = (slug) => [
49
+ ['CLAUDE.md', false],
50
+ [docRel(slug), true],
51
+ [stateRel(slug), true],
52
+ ];
53
+
54
+ // Throws the first refusal: a link on the way to `rel` that the plugin must not write through.
55
+ function assertWritable(cwd, rel, whole) {
56
+ const r = linkRefusal(cwd, rel, { whole });
57
+ if (r) throw new Error(refusalText(r));
42
58
  }
43
59
 
44
60
  // First line of the detail doc — an invisible (in rendered markdown) marker that
@@ -219,6 +235,7 @@ export function holdsOnlyPluginLines(p, slug) {
219
235
  * @returns {'added'|'present'}
220
236
  */
221
237
  export function addAgentsImports(cwd, slug, imports) {
238
+ assertWritable(cwd, 'CLAUDE.md', false);
222
239
  const p = claudeMdPath(cwd);
223
240
  const raw = existsSync(p) ? readRegularTextOrThrow(p) : '';
224
241
  const marker = agentsImportMarker(slug);
@@ -407,19 +424,11 @@ export function needsRefresh(cwd, { slug, version, block, doc }) {
407
424
  * (block disposition, and the detail doc's)
408
425
  */
409
426
  export function writeManaged(cwd, { slug, version, block, doc }) {
410
- // The detail doc and the state sidecar are this plugin's own files, and the shared writer writes
411
- // THROUGH a link (for a dotfiles-managed CLAUDE.md): a cloned repository that committed either as
412
- // a link out of the project had SessionStart overwrite the file it names. Refused before
413
- // anything is written.
414
- for (const p of [detailDocPath(cwd, slug), stateFilePath(cwd, slug)]) {
415
- let link = false;
416
- try {
417
- link = lstatSync(p).isSymbolicLink();
418
- } catch {
419
- /* absent */
420
- }
421
- if (link) throw new Error(`${p}: a symbolic link; not written through`);
422
- }
427
+ // The shared writer writes THROUGH a link (for a dotfiles-managed CLAUDE.md), and a cloned
428
+ // repository can commit links: one as the doc or the state, as `.claude`, or as CLAUDE.md had this
429
+ // write outside the project (D#880). All three are checked before anything is written, so a
430
+ // refusal leaves CLAUDE.md as it was too.
431
+ for (const [rel, whole] of managedTargets(slug)) assertWritable(cwd, rel, whole);
423
432
  const { action } = writeBlockAt(claudeMdPath(cwd), { slug, version, block });
424
433
 
425
434
  // Detail doc (marker on first line so unadopt/refresh can tell it apart from a
@@ -506,10 +515,32 @@ export function writeBlockAt(p, { slug, version, block }) {
506
515
  * (that is the defect, not a detail), and guessing a span in a file we do not own is how the
507
516
  * adopt side came to delete a user's runbook. Report, do not repair.
508
517
  *
509
- * @returns {{action: 'removed'|'partial'|'absent', residue?: string}}
518
+ * A file reached through a link the plugin must not write through (lib/project-link.mjs) is left as
519
+ * it is, and named in `left`: a cloned repository's committed `.claude` link had unadopt delete two
520
+ * files in the directory it picked (D#880). `skipped-symlink` = CLAUDE.md was such a file; the doc
521
+ * and the state then stay too.
522
+ *
523
+ * @returns {{action: 'removed'|'partial'|'absent'|'skipped-symlink', residue?: string,
524
+ * left?: {link: string, why: string}[]}}
510
525
  */
511
526
  export function removeManaged(cwd, slug) {
512
- const { action, orphans } = removeBlockAt(claudeMdPath(cwd), slug);
527
+ const left = [];
528
+ // A CLAUDE.md the plugin will not write through is left alone only while the block is in it (read
529
+ // with a bound, never written): once the user has taken the block out by hand, the rest goes.
530
+ const mdRefusal = linkRefusal(cwd, 'CLAUDE.md');
531
+ const mdLeft = mdRefusal !== null && readBlockAt(claudeMdPath(cwd), slug).body !== null;
532
+ if (mdLeft) left.push(mdRefusal);
533
+ const { action, orphans } = mdLeft
534
+ ? { action: 'skipped-symlink', orphans: 0 }
535
+ : mdRefusal
536
+ ? { action: 'absent', orphans: 0 }
537
+ : removeBlockAt(claudeMdPath(cwd), slug);
538
+ // The doc and the state go only with the block: a block left behind a link still points at the
539
+ // doc (v6.35.4 pre-tag round 1, F5). Deleting either one is unlinkSync, which removes a link
540
+ // itself, not what it names; what can lead it out of the project is a `.claude` link.
541
+ const dirRefusal = linkRefusal(cwd, '.claude');
542
+ if (dirRefusal) left.push(dirRefusal);
543
+ const keep = dirRefusal !== null || mdLeft;
513
544
  // Captured BEFORE the deletions below, because they are what it asks about: is there any
514
545
  // evidence the plugin ever wrote in this project? An unpaired sentinel is NOT such
515
546
  // evidence — it is text, and a project that merely documents the marker in prose has one
@@ -517,13 +548,13 @@ export function removeManaged(cwd, slug) {
517
548
  // own paragraph, on a project this tool has never touched.
518
549
  const dp = detailDocPath(cwd, slug);
519
550
  const wasOurs = action === 'removed' || existsSync(dp) || existsSync(stateFilePath(cwd, slug));
520
- if (existsSync(dp))
551
+ if (!keep && existsSync(dp))
521
552
  try {
522
553
  unlinkSync(dp);
523
554
  } catch {
524
555
  /* best-effort */
525
556
  }
526
- clearState(cwd, slug);
557
+ if (!keep) clearState(cwd, slug);
527
558
  // Drop an emptied .claude/ so unadopt leaves no trace (skips if it holds
528
559
  // anything else — e.g. settings.local.json).
529
560
  try {
@@ -539,9 +570,10 @@ export function removeManaged(cwd, slug) {
539
570
  // `partial++`, so a sweep that DID remove a block reported "no block" and tallied zero
540
571
  // removals. Two facts, two fields.
541
572
  const residue = orphans > 0 && wasOurs ? orphanResidueNote(orphans, slug, claudeMdPath(cwd)) : null;
542
- if (action === 'removed') return residue ? { action, residue } : { action };
543
- if (residue) return { action: 'partial', residue };
544
- return { action };
573
+ const leftField = left.length > 0 ? { left } : {};
574
+ if (action === 'removed') return residue ? { action, residue, ...leftField } : { action, ...leftField };
575
+ if (residue) return { action: 'partial', residue, ...leftField };
576
+ return { action, ...leftField };
545
577
  }
546
578
 
547
579
  /**
package/hook-context.mjs CHANGED
@@ -8,6 +8,7 @@
8
8
  import { basename, join } from 'path';
9
9
  import { existsSync, writeFileSync } from 'fs';
10
10
  import { atomicWriteFileSync } from './lib/atomic-write.mjs';
11
+ import { linkRefusal, refusalText } from './lib/project-link.mjs';
11
12
  import { readRegularTextOrThrow } from './lib/regular-file.mjs';
12
13
  import {
13
14
  estimateTokens,
@@ -481,8 +482,11 @@ export function cleanupClaudeMdLegacyBlock() {
481
482
  }
482
483
  }
483
484
 
484
- // Swallow a single preceding newline to avoid leaving a blank-line gap behind.
485
- if (removeStart > 0 && content[removeStart - 1] === '\n') removeStart -= 1;
485
+ // A span at the end of the file has no newline after it: take the one before it instead. Never
486
+ // both — that joined the lines around the span (`keep this` + `trailing` → `keep thistrailing`,
487
+ // v6.35.3 pre-tag round 2, O1).
488
+ if (removeEnd === endIdx + endTag.length && removeStart > 0 && content[removeStart - 1] === '\n')
489
+ removeStart -= 1;
486
490
 
487
491
  const cleaned = content.slice(0, removeStart) + content.slice(removeEnd);
488
492
  // Collapse any ≥3 consecutive newlines to two, then ensure exactly one trailing newline.
@@ -493,6 +497,15 @@ export function cleanupClaudeMdLegacyBlock() {
493
497
  return;
494
498
  }
495
499
 
500
+ // Not through a CLAUDE.md link the repository may have committed: it rewrote the outside file
501
+ // it names, with auto-adopt off too (D#880). Marked done, as a file without a block is.
502
+ const refusal = linkRefusal(inferProjectDir(), 'CLAUDE.md');
503
+ if (refusal) {
504
+ debugLog('WARN', 'cleanupClaudeMdLegacyBlock', refusalText(refusal));
505
+ dropMarker();
506
+ return;
507
+ }
508
+
496
509
  // atomicWriteFileSync keeps the per-pid temp (two concurrent first-run SessionStarts in
497
510
  // one project must not rename each other's half-written temp onto the user's tracked
498
511
  // CLAUDE.md) AND adds the lstat the local twin lacked: renaming onto a symlink NAME
package/install.mjs CHANGED
@@ -4900,6 +4900,9 @@ async function rebuildBinding() {
4900
4900
  // dependency is the kind of thing that reads as corruption six months later.
4901
4901
  log(` the shipped prebuild would not load — moved aside to ${verify.quarantined}.unusable`);
4902
4902
  }
4903
+ for (const f of verify.setAside || []) {
4904
+ log(` a compiled addon would not load — moved aside to ${f}.unusable`);
4905
+ }
4903
4906
  } else {
4904
4907
  fail(`better-sqlite3 binding still unusable in ${label}: ${verify.error}`);
4905
4908
  log(`Try manually: ${nativeBindingRepairHint(root)}`);
@@ -66,12 +66,12 @@ export function nativeBindingRepairHint(root) {
66
66
  // double quotes, a `$` or backtick still expands), and a `cd` that splits hands the user a
67
67
  // command that fails on exactly the machines least able to debug it.
68
68
  const npmPair = `cd ${shellWord(root)} && ${NATIVE_BINDING_REBUILD_CMD} && ${NATIVE_BINDING_SOURCE_BUILD_CMD}`;
69
- // The pair above heals a platform better-sqlite3 ships NO prebuild for. It cannot heal a
70
- // prebuild that is present and will not load — 13 selects `prebuilds/<target>.node` on
71
- // existence alone and prefers it over `build/`, so the addon those two commands compile
72
- // stays shadowed. Only ensureBetterSqlite3Working moves the dead prebuild out of the way
73
- // first, and `rebuild-binding` is how a human reaches it — so it goes FIRST, because a user
74
- // runs the first command they are given and stops looking when it reports success.
69
+ // The pair above heals a platform better-sqlite3 ships NO prebuild for, and from 13.2.0 a
70
+ // prebuild that is present and will not load: 13.2.0 loads a compiled `build/` addon before
71
+ // `prebuilds/` (13.0.x did the reverse, and the pair could not heal that shape). Measured
72
+ // 2026-11-21: corrupt prebuild + healthy build/Release → opens via build/Release.
73
+ // `rebuild-binding` still goes FIRST: it runs the whole chain, and a user runs the first
74
+ // command they are given and stops looking when it reports success.
75
75
  const cli = join(root, 'cli.mjs');
76
76
  if (!existsSync(cli)) return npmPair;
77
77
  return `node ${shellWord(cli)} rebuild-binding (or, without the CLI: ${npmPair})`;
@@ -217,9 +217,10 @@ export function probeBindingInFreshProcess(installDir, { timeoutMs = 30_000 } =
217
217
  };
218
218
  }
219
219
 
220
- // Suffix for a prebuilt addon that is present and will not load. Renamed, never deleted:
221
- // the file is evidence for whoever debugs the machine, and `npm install` puts a fresh
222
- // prebuild back at the original name regardless.
220
+ // Suffix for a prebuilt addon that is present and will not load — and, since D#928, for a
221
+ // compiled `build/` addon in the same state. Renamed, never deleted: the file is evidence for
222
+ // whoever debugs the machine, and `npm install` puts a fresh prebuild back at the original
223
+ // name regardless.
223
224
  const UNUSABLE_PREBUILD_SUFFIX = '.unusable';
224
225
 
225
226
  /**
@@ -256,17 +257,76 @@ function resolvedPrebuildPath(installDir) {
256
257
  return p && existsSync(p) ? p : null;
257
258
  }
258
259
 
260
+ /** Out of process: does the addon at `file` dlopen? A crash or a hang counts as no. */
261
+ function addonLoadsInFreshProcess(file) {
262
+ const r = spawnSync(process.execPath, ['-e', `require(${JSON.stringify(file)})`], {
263
+ stdio: 'pipe',
264
+ timeout: 10_000,
265
+ });
266
+ return !r.error && r.status === 0;
267
+ }
268
+
269
+ /** Undo setAsideDeadCompiledAddons. Best-effort, like restorePrebuild below. */
270
+ function putBackCompiledAddons(files) {
271
+ for (const f of files) {
272
+ try {
273
+ renameSync(f + UNUSABLE_PREBUILD_SUFFIX, f);
274
+ } catch {
275
+ // Nothing better to do; the caller goes on to the npm and compile steps.
276
+ }
277
+ }
278
+ }
279
+
280
+ /**
281
+ * D#928. better-sqlite3 13.2.0 loads `build/Debug` or `build/Release/better_sqlite3.node`
282
+ * BEFORE the prebuild, so a compiled addon that will not load hides a prebuild that would.
283
+ * Measured 2026-11-21: that tree does not open. Renaming it is enough, needs no compiler, and
284
+ * so is safe on the time-budgeted SessionStart path that the source build below is not.
285
+ *
286
+ * Moves only compiled addons that themselves fail to load (a working one may be the user's
287
+ * own build — 13.2.0's release notes describe compiling a custom SQLite that way), and only when the
288
+ * prebuild loads in their place, so "broken addon" never becomes "no addon". The two paths
289
+ * are node-gyp's fixed output locations, checked in the order 13.2.0's `getBinding()` uses;
290
+ * the package exports no selector for them, unlike `getPrebuildPath()`.
291
+ *
292
+ * @param {string} installDir Directory whose node_modules holds better-sqlite3
293
+ * @returns {string[]} the files renamed to `<file>.unusable`; empty when the shape is absent
294
+ */
295
+ function setAsideDeadCompiledAddons(installDir) {
296
+ const pkg = join(installDir, 'node_modules', 'better-sqlite3');
297
+ const dead = ['Debug', 'Release']
298
+ .map((type) => join(pkg, 'build', type, 'better_sqlite3.node'))
299
+ .filter((f) => existsSync(f) && !addonLoadsInFreshProcess(f));
300
+ if (dead.length === 0) return [];
301
+ const prebuild = resolvedPrebuildPath(installDir);
302
+ if (!prebuild || !addonLoadsInFreshProcess(prebuild)) return [];
303
+ const moved = [];
304
+ for (const f of dead) {
305
+ try {
306
+ renameSync(f, f + UNUSABLE_PREBUILD_SUFFIX);
307
+ moved.push(f);
308
+ } catch {
309
+ // A read-only tree: leave it exactly as found and let the remaining steps try.
310
+ putBackCompiledAddons(moved);
311
+ return [];
312
+ }
313
+ }
314
+ return moved;
315
+ }
316
+
259
317
  /**
260
318
  * Verify better-sqlite3 binding works in `installDir`; if not, run
261
319
  * `npm rebuild better-sqlite3` and re-probe. Returns
262
- * { ok: true, action: 'verified' | 'rebuilt' } on success or
320
+ * { ok: true, action: 'verified' | 'rebuilt' } on success,
321
+ * { ok: true, action: 'restored', setAside } when moving dead compiled addons aside was
322
+ * enough (D#928), { ok: true, action: 'compiled', quarantined? } after the source build, or
263
323
  * { ok: false, error } if rebuild can't fix it. The `probe`, `verify` and
264
324
  * `rebuild` deps are injectable so this can be unit-tested without a real npm
265
325
  * subprocess.
266
326
  *
267
327
  * @param {string} installDir Directory containing node_modules/better-sqlite3
268
328
  * @param {{probe?: () => Promise<{ok: boolean, error?: string}>, verify?: () => Promise<{ok: boolean, error?: string}> | {ok: boolean, error?: string}, rebuild?: () => Promise<void>, exec?: (cmd: string, opts: object) => void}} [deps]
269
- * @returns {Promise<{ok: true, action: 'verified' | 'rebuilt'} | {ok: false, error: string}>}
329
+ * @returns {Promise<{ok: true, action: 'verified' | 'rebuilt'} | {ok: true, action: 'restored', setAside: string[]} | {ok: true, action: 'compiled', quarantined?: string} | {ok: false, error: string}>}
270
330
  */
271
331
  export async function ensureBetterSqlite3Working(installDir, deps = {}) {
272
332
  // BOTH probes run out of process by default, because a probe must never
@@ -321,6 +381,15 @@ export async function ensureBetterSqlite3Working(installDir, deps = {}) {
321
381
  const first = await probe();
322
382
  if (first.ok) return { ok: true, action: 'verified' };
323
383
 
384
+ // Before any npm step: the rename costs a few short spawns where the npm step can take its
385
+ // whole cap.
386
+ const setAside = setAsideDeadCompiledAddons(installDir);
387
+ if (setAside.length > 0) {
388
+ const unshadowed = await verify();
389
+ if (unshadowed.ok) return { ok: true, action: 'restored', setAside };
390
+ putBackCompiledAddons(setAside);
391
+ }
392
+
324
393
  try {
325
394
  await rebuild();
326
395
  } catch (e) {
@@ -361,14 +430,12 @@ export async function ensureBetterSqlite3Working(installDir, deps = {}) {
361
430
  : () => exec(NATIVE_BINDING_SOURCE_BUILD_CMD, { cwd: installDir, stdio: 'pipe' }));
362
431
  if (!sourceBuild) return { ok: false, error: second.error || first.error };
363
432
 
364
- // A prebuild that is present and unloadable SHADOWS everything the source build is about
365
- // to produce: better-sqlite3 13 picks `prebuilds/<target>.node` on existence alone and
366
- // prefers it over `build/`. Measured 2026-09-06 with a control — corrupt prebuild +
367
- // healthy build/Release → `wrong ELF class`; the same tree with the prebuild moved aside →
368
- // opens; with neither → fails. Until this, `rebuild-binding` (the foreground repair doctor
369
- // prints, deliberately given no time budget) exited 1 on that shape and the manual command
370
- // it offered instead could not fix it either. Reproduced end-to-end in
371
- // tests/sandbox/phaseB-npm.mjs before the fix.
433
+ // Quarantine the prebuild before compiling. On better-sqlite3 13.0.x this was the fix: it
434
+ // picked `prebuilds/<target>.node` on existence alone, before `build/`, so a dead prebuild
435
+ // shadowed the compile (measured 2026-09-06: corrupt prebuild + healthy build/Release →
436
+ // `wrong ELF class`; prebuild moved aside → opens). 13.2.0 loads `build/` first (measured
437
+ // 2026-11-21: the same tree opens via build/Release), so the compile no longer needs it. It
438
+ // stays: dropping it is a behaviour change of its own, not part of a dependency bump.
372
439
  //
373
440
  // Deliberately inside this branch and after the npm step: quarantining without a compile to
374
441
  // follow it turns "broken addon" into "no addon", which is strictly worse — so the
@@ -0,0 +1,147 @@
1
+ // Leaf (node: imports only): whether the plugin may write a project file reached through a link.
2
+ //
3
+ // A cloned repository can commit links, and the plugin writes into the project it is opened in:
4
+ // with `.claude -> ../../somewhere` committed, adopt and the SessionStart sync wrote their two files
5
+ // into a directory the repository picked, unadopt deleted them there, and a CLAUDE.md committed as a
6
+ // link had its outside target rewritten (D#880; v6.35.3 pre-tag round 2, F1). A link the user made
7
+ // at `.claude` or CLAUDE.md — a dotfiles-managed one, a worktree sharing the main checkout's — is
8
+ // theirs to point anywhere, and git lists it as untracked where it lists a committed one as a staged
9
+ // symlink. git cannot tell the user's from one an unpacked archive left in a work tree (untracked
10
+ // too): a link at either file the plugin rewrites whole is never written through, as before
11
+ // (v6.35.4 pre-tag round 1, F1).
12
+ import { lstatSync, realpathSync } from 'node:fs';
13
+ import { execFileSync } from 'node:child_process';
14
+ import { basename, dirname, isAbsolute, join, relative, sep } from 'node:path';
15
+
16
+ /**
17
+ * Why the plugin must not write `rel` under `root` through the links on its way, or null when it
18
+ * may. Each link on the path, nearest the project first:
19
+ * - the file itself, when `whole` is set (the plugin replaces or deletes that file whole): refused,
20
+ * whoever made it;
21
+ * - git lists it as untracked: written through;
22
+ * - otherwise it must resolve inside the project (the git top-level, else `root`) and not into a
23
+ * `.git` directory, in any letter case.
24
+ * No link on the path costs one lstat per component and no git.
25
+ * `kind`: 'whole', 'committed' (git lists the path as tracked: a committed link, or a committed file
26
+ * the link replaced) or 'unknown' (git does not list it: no work tree, git missing or refusing, a path
27
+ * git tracks only under another letter case).
28
+ * @param {string} root the project directory
29
+ * @param {string} rel '/'-separated path below it
30
+ * @param {{whole?: boolean}} [opts]
31
+ * @returns {{link: string, why: string, kind: 'whole'|'committed'|'unknown'}|null}
32
+ */
33
+ export function linkRefusal(root, rel, { whole = false } = {}) {
34
+ const parts = rel.split('/');
35
+ let top;
36
+ for (let i = 0; i < parts.length; i++) {
37
+ const lex = join(root, ...parts.slice(0, i + 1));
38
+ let st;
39
+ try {
40
+ st = lstatSync(lex);
41
+ } catch {
42
+ return null; // absent: nothing below it exists to write through
43
+ }
44
+ if (!st.isSymbolicLink()) continue;
45
+ if (whole && i === parts.length - 1)
46
+ return {
47
+ link: lex,
48
+ kind: 'whole',
49
+ why: 'a link, and the plugin rewrites this file whole: git cannot tell a link you made here from one a repository or an unpacked archive put there',
50
+ };
51
+ const made = userMade(root, lex);
52
+ if (made) continue;
53
+ let target = null;
54
+ try {
55
+ target = realpathSync(lex);
56
+ } catch {
57
+ /* dangling: where a write would land is unknown */
58
+ }
59
+ let where = target === null ? 'out' : place(root, target);
60
+ if (where === 'out' && target !== null) {
61
+ if (top === undefined) top = gitTop(root);
62
+ if (top) where = place(top, target);
63
+ }
64
+ if (where === 'in') continue;
65
+ const who =
66
+ made === false
67
+ ? 'a link this repository commits'
68
+ : 'a link git does not list as one you made (outside a git work tree, or git did not answer)';
69
+ const to =
70
+ target === null
71
+ ? 'to a path that does not resolve'
72
+ : `to ${target}, ${where === 'git' ? 'inside a .git directory' : 'outside this project'}`;
73
+ return { link: lex, kind: made === false ? 'committed' : 'unknown', why: `${who}, ${to}` };
74
+ }
75
+ return null;
76
+ }
77
+
78
+ /** The refusal as adopt reports it: what the link is, then what to do. */
79
+ export function refusalText(r) {
80
+ const next =
81
+ r.kind === 'unknown'
82
+ ? 'if you made the link, adopt in a git work tree, where git lists it as untracked; otherwise delete it, then run adopt again'
83
+ : 'delete the link, then run adopt again';
84
+ return `${r.link}: ${r.why}. Not written through; ${next}.`;
85
+ }
86
+
87
+ // 'in': inside `dir` by real path; 'git': inside a `.git` directory below it (a link into one
88
+ // reaches git's own config and hooks; any letter case, for case-insensitive file systems); 'out'.
89
+ function place(dir, target) {
90
+ let base;
91
+ try {
92
+ base = realpathSync(dir);
93
+ } catch {
94
+ return 'out';
95
+ }
96
+ const r = relative(base, target);
97
+ if (r === '') return 'in';
98
+ if (isAbsolute(r)) return 'out';
99
+ const segs = r.split(sep);
100
+ if (segs[0] === '..') return 'out';
101
+ return segs.some((s) => s.toLowerCase() === '.git') ? 'git' : 'in';
102
+ }
103
+
104
+ function git(cwd, args) {
105
+ return execFileSync('git', args, {
106
+ cwd,
107
+ encoding: 'utf8',
108
+ stdio: ['ignore', 'pipe', 'ignore'],
109
+ timeout: 5000,
110
+ env: { ...process.env, GIT_OPTIONAL_LOCKS: '0', GIT_LITERAL_PATHSPECS: '1' },
111
+ });
112
+ }
113
+
114
+ function gitTop(root) {
115
+ try {
116
+ return git(root, ['rev-parse', '--show-toplevel']).trim() || null;
117
+ } catch {
118
+ return null;
119
+ }
120
+ }
121
+
122
+ // true: git lists the link as untracked; false: as a tracked path (a committed link, or a committed
123
+ // file the link replaced, which is also what a case-insensitive checkout of `CLAUDE.md` beside a
124
+ // committed `claude.md` link leaves — v6.35.4 pre-tag round 1, F3); null: git does not list it (not a
125
+ // work tree, no git or git refusing, a path git tracks only under another letter case).
126
+ // Asked by its real directory, so a path below a link inside the project is still one git knows.
127
+ function userMade(root, lex) {
128
+ let here;
129
+ try {
130
+ here = join(realpathSync(dirname(lex)), basename(lex));
131
+ } catch {
132
+ return null;
133
+ }
134
+ let out;
135
+ try {
136
+ out = git(root, ['ls-files', '-z', '-s', '-o', '--', here]);
137
+ } catch {
138
+ return null;
139
+ }
140
+ let made = null;
141
+ for (const entry of out.split('\0')) {
142
+ if (entry === '') continue;
143
+ if (!/^\d{6} [0-9a-f]+ \d\t/.test(entry)) return true;
144
+ made = false;
145
+ }
146
+ return made;
147
+ }
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "claude-mem-lite",
3
- "version": "6.35.3",
3
+ "version": "6.35.5",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "claude-mem-lite",
9
- "version": "6.35.3",
9
+ "version": "6.35.5",
10
10
  "os": [
11
11
  "darwin",
12
12
  "linux",
@@ -14,7 +14,7 @@
14
14
  ],
15
15
  "dependencies": {
16
16
  "@modelcontextprotocol/sdk": "^1.32.2",
17
- "better-sqlite3": "^13.0.3",
17
+ "better-sqlite3": "^13.2.0",
18
18
  "zod": "^4.6.7"
19
19
  },
20
20
  "bin": {
@@ -134,9 +134,9 @@
134
134
  }
135
135
  },
136
136
  "node_modules/better-sqlite3": {
137
- "version": "13.0.3",
138
- "resolved": "https://registry.npmjs.org/better-sqlite3/-/better-sqlite3-13.0.3.tgz",
139
- "integrity": "sha512-RbOBxmLBG8uvFUc15X9+9SFemKcQ0WBuISBVkpuiaUB2qblC8UWlHEjdWVoZ8AdhSwmoEgsiXKfopX0CQxaACQ==",
137
+ "version": "13.2.0",
138
+ "resolved": "https://registry.npmjs.org/better-sqlite3/-/better-sqlite3-13.2.0.tgz",
139
+ "integrity": "sha512-Z8Q/9x/uNyKxA1v4FNodyItRVRw1TeKBrmj32JhxhR0ceNcBY+wMobt/Bv7M7TzwPAXjnZRtNaEsATnUZSKWZQ==",
140
140
  "license": "MIT",
141
141
  "dependencies": {
142
142
  "node-addon-api": "^8.0.0"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "claude-mem-lite",
3
- "version": "6.35.3",
3
+ "version": "6.35.5",
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",
@@ -134,6 +134,7 @@
134
134
  "lib/proc-lock.mjs",
135
135
  "lib/atomic-write.mjs",
136
136
  "lib/regular-file.mjs",
137
+ "lib/project-link.mjs",
137
138
  "lib/platform-gate.mjs",
138
139
  "lib/hook-prune.mjs",
139
140
  "lib/proxy-fetch.mjs",
@@ -240,7 +241,7 @@
240
241
  ],
241
242
  "dependencies": {
242
243
  "@modelcontextprotocol/sdk": "^1.32.2",
243
- "better-sqlite3": "^13.0.3",
244
+ "better-sqlite3": "^13.2.0",
244
245
  "zod": "^4.6.7"
245
246
  },
246
247
  "overrides": {
@@ -157,4 +157,9 @@ if (!result.ok) {
157
157
  if (result.action === 'rebuilt') {
158
158
  process.stderr.write('[claude-mem-lite] rebuilt better-sqlite3 binding for current Node ABI\n');
159
159
  }
160
+ for (const f of result.setAside || []) {
161
+ process.stderr.write(
162
+ `[claude-mem-lite] moved a compiled better-sqlite3 addon that would not load aside: ${f}.unusable\n`,
163
+ );
164
+ }
160
165
  process.exit(0);
package/scripts/setup.sh CHANGED
@@ -336,11 +336,8 @@ if [[ -d "$ROOT/node_modules/better-sqlite3" ]]; then
336
336
  # better-sqlite3 13 (no install script to run), so it never signals failure and
337
337
  # an `||` chain would never reach the source build. A20260906-R8-P1-1.
338
338
  #
339
- # …and the pair alone is still not enough. It heals a platform 13 ships no prebuild
340
- # for; it cannot heal a prebuild that is PRESENT and will not load, because 13 prefers
341
- # `prebuilds/<target>.node` over anything the source build produces. This string is what
342
- # the SessionStart dashboard prints as `Repair:`, so it leads with the CLI, which is the
343
- # only path that moves the dead prebuild aside first (lib/binding-probe.mjs). Mirrors
339
+ # This string is what the SessionStart dashboard prints as `Repair:`, so it leads with
340
+ # the CLI, which runs the whole chain (lib/binding-probe.mjs). Mirrors
344
341
  # nativeBindingRepairHint(); this file may not import lib/, hence the duplication —
345
342
  # tests/audit-r8-binding-repair-hint.test.mjs pins the set of files allowed to do that.
346
343
  # mark_deps_broken already prefixes `cd <root> && `, so these are root-relative.
package/source-files.mjs CHANGED
@@ -83,6 +83,9 @@ export const SOURCE_FILES = [
83
83
  // Leaf (node: imports only): bounded reads of files someone else can occupy. Ahead of plugin-key,
84
84
  // claudemd, local-steering and hook-context, which import it.
85
85
  'lib/regular-file.mjs',
86
+ // Leaf (node: imports only): whether a project file reached through a link may be written. Ahead
87
+ // of claudemd and hook-context, which import it.
88
+ 'lib/project-link.mjs',
86
89
  // v2.71.x: better-sqlite3 ABI probe + auto-rebuild. Shared by install.mjs
87
90
  // (post-`npm install` verify) and scripts/launch.mjs (pre-server-launch
88
91
  // self-heal after Node ABI changes). Missing from manifest → auto-update