claude-mem-lite 6.35.3 → 6.35.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -9,7 +9,7 @@
9
9
  "plugins": [
10
10
  {
11
11
  "name": "claude-mem-lite",
12
- "version": "6.35.3",
12
+ "version": "6.35.4",
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.4",
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
@@ -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.4",
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.4",
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.35.3",
3
+ "version": "6.35.4",
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",
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