@spike1292/claude-memory 0.0.0-stage → 0.14.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.
- package/LICENSE +21 -0
- package/README.md +412 -2
- package/hooks/distill-session.mjs +74 -0
- package/hooks/graph-staleness-check.mjs +25 -0
- package/hooks/hooks.json +94 -0
- package/hooks/insights-surface.mjs +48 -0
- package/hooks/lib/distill-session.mjs +1560 -0
- package/hooks/lib/dupe-report.mjs +61 -0
- package/hooks/lib/env-shell.mjs +92 -0
- package/hooks/lib/graph-staleness-check.mjs +394 -0
- package/hooks/lib/hook-io.mjs +715 -0
- package/hooks/lib/insights-surface.mjs +165 -0
- package/hooks/lib/memory-link-lint.mjs +499 -0
- package/hooks/lib/memory-recall.mjs +219 -0
- package/hooks/lib/omp.mjs +103 -0
- package/hooks/lib/opencode.mjs +231 -0
- package/hooks/lib/paths.mjs +452 -0
- package/hooks/lib/semantic-index-refresh.mjs +155 -0
- package/hooks/lib/validate-note.mjs +218 -0
- package/hooks/lib/vault-env.sh +110 -0
- package/hooks/memory-link-lint.mjs +65 -0
- package/hooks/memory-recall.mjs +251 -0
- package/hooks/semantic-index-refresh.mjs +23 -0
- package/hooks/session-context.mjs +9 -0
- package/hooks/validate-note.mjs +52 -0
- package/hooks/vault-memory-sync.sh +154 -0
- package/omp/index.js +1 -0
- package/opencode/index.js +1 -0
- package/package.json +51 -4
- package/scripts/claude-memory.mjs +31 -0
- package/scripts/doctor-perf.mjs +121 -0
- package/scripts/doctor.sh +558 -0
- package/scripts/env.mjs +6 -0
- package/scripts/lib/claude-memory.mjs +168 -0
- package/scripts/lib/doctor-perf.mjs +434 -0
- package/scripts/lib/hook-stats.mjs +864 -0
- package/scripts/lib/lexical.mjs +85 -0
- package/scripts/lib/memory-adopt.mjs +69 -0
- package/scripts/lib/memory-audit-checks.mjs +344 -0
- package/scripts/lib/memory-eval.mjs +381 -0
- package/scripts/lib/memory-mark.mjs +135 -0
- package/scripts/lib/memory-mcp.mjs +142 -0
- package/scripts/lib/memory-merge.mjs +316 -0
- package/scripts/lib/memory-mine.mjs +108 -0
- package/scripts/lib/memory-promote.mjs +207 -0
- package/scripts/lib/memory-prune.mjs +84 -0
- package/scripts/lib/memory-semantic.mjs +999 -0
- package/scripts/lib/memory-setup.mjs +170 -0
- package/scripts/lib/memory-synth-vault.mjs +538 -0
- package/scripts/lib/model-default.mjs +7 -0
- package/scripts/lib/models.mjs +58 -0
- package/scripts/lib/prune-logs.mjs +130 -0
- package/scripts/lib/recall-stats.mjs +354 -0
- package/scripts/lib/share-modules.mjs +70 -0
- package/scripts/lib/slim-install.mjs +162 -0
- package/scripts/lib/vault-mcp.mjs +405 -0
- package/scripts/memory-adopt.mjs +160 -0
- package/scripts/memory-audit-checks.mjs +375 -0
- package/scripts/memory-eval.mjs +753 -0
- package/scripts/memory-mark.mjs +39 -0
- package/scripts/memory-mcp.mjs +35 -0
- package/scripts/memory-merge.mjs +55 -0
- package/scripts/memory-prune.mjs +44 -0
- package/scripts/memory-semantic.mjs +1192 -0
- package/scripts/memory-setup.mjs +33 -0
- package/scripts/memory-synth-vault.mjs +251 -0
- package/scripts/prune-logs.mjs +42 -0
- package/scripts/share-modules.mjs +79 -0
- package/scripts/slim-install.mjs +55 -0
- package/scripts/vault-mcp.mjs +50 -0
- package/stubs/onnxruntime-web/index.mjs +11 -0
- package/stubs/onnxruntime-web/package.json +12 -0
- package/stubs/sharp/index.mjs +11 -0
- package/stubs/sharp/package.json +12 -0
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// Apply a reviewed /memory:synthesize draft from Staging/<slug>/ into permanent/ — the ONLY path
|
|
3
|
+
// that writes there (#96). Gated on a held-out case set (#87/#126) so a promotion cannot ship a
|
|
4
|
+
// number fitted to the questions that motivated it.
|
|
5
|
+
//
|
|
6
|
+
// Usage:
|
|
7
|
+
// node memory-adopt.mjs <staged-note-name> --min-rank1 <percent> [--cases <path>]
|
|
8
|
+
// node memory-adopt.mjs <staged-note-name> --dry-run
|
|
9
|
+
// node memory-adopt.mjs <staged-note-name> --min-rank1 <percent> --force # overwrite an existing note
|
|
10
|
+
// [--vault <dir>] [--slug <slug>] to point at a synthetic vault instead of the real one.
|
|
11
|
+
//
|
|
12
|
+
// Entry only: argv, fs, subprocess. The accept/rollback state machine and its tests live in
|
|
13
|
+
// lib/memory-adopt.mjs.
|
|
14
|
+
import fs from 'node:fs';
|
|
15
|
+
import path from 'node:path';
|
|
16
|
+
import { execFileSync } from 'node:child_process';
|
|
17
|
+
import * as paths from '../hooks/lib/paths.mjs';
|
|
18
|
+
import { adopt } from './lib/memory-adopt.mjs';
|
|
19
|
+
|
|
20
|
+
const argv = process.argv.slice(2);
|
|
21
|
+
const flag = (/** @type {string} */ n) => argv.includes(n);
|
|
22
|
+
const val = (/** @type {string} */ n) => {
|
|
23
|
+
const i = argv.indexOf(n);
|
|
24
|
+
return i >= 0 ? argv[i + 1] : null;
|
|
25
|
+
};
|
|
26
|
+
// Skip both a flag and, for the value-taking ones, the token right after it — otherwise
|
|
27
|
+
// `--min-rank1 60 my-note` picks up "60" as the name instead of skipping past its flag.
|
|
28
|
+
const VALUE_FLAGS = new Set(['--min-rank1', '--cases', '--vault', '--slug']);
|
|
29
|
+
let name;
|
|
30
|
+
for (let i = 0; i < argv.length; i++) {
|
|
31
|
+
if (argv[i].startsWith('--')) {
|
|
32
|
+
if (VALUE_FLAGS.has(argv[i])) i++;
|
|
33
|
+
continue;
|
|
34
|
+
}
|
|
35
|
+
name = argv[i];
|
|
36
|
+
break;
|
|
37
|
+
}
|
|
38
|
+
if (!name) {
|
|
39
|
+
console.error(
|
|
40
|
+
'usage: memory-adopt.mjs <staged-note-name> --min-rank1 <percent> [--dry-run] [--force]\n' +
|
|
41
|
+
' [--cases <path>] [--vault <dir>] [--slug <slug>]',
|
|
42
|
+
);
|
|
43
|
+
process.exit(1);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const VAULT = val('--vault') || paths.vault();
|
|
47
|
+
const SLUG = val('--slug') || paths.projectKey(process.cwd());
|
|
48
|
+
const dryRun = flag('--dry-run');
|
|
49
|
+
const force = flag('--force');
|
|
50
|
+
const minRank1 = val('--min-rank1');
|
|
51
|
+
// A real adopt with no floor is how #96 shipped a promotion gain fitted to its own questions —
|
|
52
|
+
// --dry-run is the only path that skips the gate, because it writes nothing to score.
|
|
53
|
+
if (!dryRun && !minRank1) {
|
|
54
|
+
console.error(
|
|
55
|
+
'--min-rank1 <percent> is required for a real adopt. Use --dry-run to preview without it.',
|
|
56
|
+
);
|
|
57
|
+
process.exit(1);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// Not memory-mark.mjs's resolveNote(): it treats a `.md`-suffixed name that exists relative to
|
|
61
|
+
// CWD as already-resolved, which would let a name coinciding with an unrelated relative path
|
|
62
|
+
// escape Staging/<slug>/ entirely. `--propose` writes flat files directly under this directory —
|
|
63
|
+
// path.basename strips any traversal, so the lookup can only ever land inside it.
|
|
64
|
+
const stagingDir = path.join(VAULT, 'Staging', SLUG);
|
|
65
|
+
const staged = path.join(stagingDir, path.basename(name.endsWith('.md') ? name : `${name}.md`));
|
|
66
|
+
if (!fs.existsSync(staged)) {
|
|
67
|
+
console.error(`not found in Staging/${SLUG}: ${name}`);
|
|
68
|
+
process.exit(1);
|
|
69
|
+
}
|
|
70
|
+
const target = path.join(VAULT, 'permanent', `${path.basename(staged, '.md')}.md`);
|
|
71
|
+
|
|
72
|
+
const result = adopt(
|
|
73
|
+
{
|
|
74
|
+
readFile: (p) => fs.readFileSync(p, 'utf8'),
|
|
75
|
+
writeFile: (p, s) => fs.writeFileSync(p, s),
|
|
76
|
+
removeFile: (p) => fs.unlinkSync(p),
|
|
77
|
+
exists: (p) => fs.existsSync(p),
|
|
78
|
+
reindex: () => {
|
|
79
|
+
execFileSync(
|
|
80
|
+
'node',
|
|
81
|
+
[
|
|
82
|
+
path.join(paths.scriptsDir, 'memory-semantic.mjs'),
|
|
83
|
+
'--index',
|
|
84
|
+
'--vault',
|
|
85
|
+
VAULT,
|
|
86
|
+
'--slug',
|
|
87
|
+
SLUG,
|
|
88
|
+
],
|
|
89
|
+
{ stdio: 'ignore' },
|
|
90
|
+
);
|
|
91
|
+
},
|
|
92
|
+
runGate: () => {
|
|
93
|
+
const args = ['--run', '--json', '--kind', 'held-out', '--vault', VAULT, '--slug', SLUG];
|
|
94
|
+
if (minRank1) args.push('--min-rank1', minRank1);
|
|
95
|
+
const cases = val('--cases');
|
|
96
|
+
if (cases) args.push('--cases', cases);
|
|
97
|
+
// --run exits non-zero when the gate fails, but still prints the JSON envelope to stdout —
|
|
98
|
+
// execFileSync throws on that exit code and attaches stdout to the error, not to a return.
|
|
99
|
+
try {
|
|
100
|
+
const out = execFileSync(
|
|
101
|
+
'node',
|
|
102
|
+
[path.join(paths.scriptsDir, 'memory-eval.mjs'), ...args],
|
|
103
|
+
{
|
|
104
|
+
encoding: 'utf8',
|
|
105
|
+
},
|
|
106
|
+
);
|
|
107
|
+
const env = JSON.parse(out);
|
|
108
|
+
return {
|
|
109
|
+
failures: env.gate ?? [],
|
|
110
|
+
recall1: env.recall?.[1] ?? null,
|
|
111
|
+
frozen: env.frozen ?? null,
|
|
112
|
+
};
|
|
113
|
+
} catch (e) {
|
|
114
|
+
const stdout = /** @type {{ stdout?: string }} */ (e).stdout;
|
|
115
|
+
try {
|
|
116
|
+
return { failures: JSON.parse(String(stdout)).gate ?? ['held-out eval run failed'] };
|
|
117
|
+
} catch {
|
|
118
|
+
// Not JSON — e.g. memory-eval.mjs exited before printing an envelope at all (no case
|
|
119
|
+
// set yet). stdout still carries the real reason; e.message is just "exit code 1".
|
|
120
|
+
const reason = stdout?.trim() || /** @type {Error} */ (e).message;
|
|
121
|
+
return { failures: [`held-out eval run failed: ${reason}`] };
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
},
|
|
125
|
+
},
|
|
126
|
+
{ stagedPath: staged, targetPath: target, dryRun, force },
|
|
127
|
+
);
|
|
128
|
+
|
|
129
|
+
switch (result.status) {
|
|
130
|
+
case 'undrafted':
|
|
131
|
+
console.log(`still the /memory:synthesize skeleton — draft it before adopting: ${staged}`);
|
|
132
|
+
process.exit(1);
|
|
133
|
+
case 'wrong-type':
|
|
134
|
+
console.log(
|
|
135
|
+
`frontmatter type is not "permanent" — /memory:synthesize should set it when drafting: ${staged}`,
|
|
136
|
+
);
|
|
137
|
+
process.exit(1);
|
|
138
|
+
case 'exists':
|
|
139
|
+
console.log(`${target} already exists — pass --force to overwrite.`);
|
|
140
|
+
process.exit(1);
|
|
141
|
+
case 'dry-run':
|
|
142
|
+
console.log(`would adopt ${staged}\n -> ${target}`);
|
|
143
|
+
process.exit(0);
|
|
144
|
+
case 'rejected':
|
|
145
|
+
console.log(
|
|
146
|
+
`rejected — held-out gate failed, permanent/ left unchanged:\n${(result.reasons ?? [])
|
|
147
|
+
.map((r) => ` - ${r}`)
|
|
148
|
+
.join('\n')}\nStaged proposal kept for a retry: ${staged}`,
|
|
149
|
+
);
|
|
150
|
+
process.exit(1);
|
|
151
|
+
case 'adopted':
|
|
152
|
+
console.log(
|
|
153
|
+
`adopted: ${target}\nremoved staged proposal: ${staged}` +
|
|
154
|
+
(result.recall1 != null
|
|
155
|
+
? `\nheld-out recall@1: ${(result.recall1 * 100).toFixed(1)}%`
|
|
156
|
+
: '') +
|
|
157
|
+
(result.frozen ? `\nheld-out set: ${result.frozen}` : '\nheld-out set: not frozen'),
|
|
158
|
+
);
|
|
159
|
+
process.exit(0);
|
|
160
|
+
}
|
|
@@ -0,0 +1,375 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// Mechanical vault-audit checks — CLI entry.
|
|
3
|
+
//
|
|
4
|
+
// Thin on purpose: argv, vault scan, stdout. Every predicate and `checkFile` live in
|
|
5
|
+
// lib/memory-audit-checks.mjs with their tests beside them, so /memory:health and validate-note
|
|
6
|
+
// share one implementation instead of re-deriving the checks in prose.
|
|
7
|
+
//
|
|
8
|
+
// node scripts/memory-audit-checks.mjs [repo] full audit
|
|
9
|
+
// node scripts/memory-audit-checks.mjs --check-file <f>
|
|
10
|
+
// node scripts/memory-audit-checks.mjs --deferred
|
|
11
|
+
import { execSync } from 'node:child_process';
|
|
12
|
+
import fs from 'node:fs';
|
|
13
|
+
import path from 'node:path';
|
|
14
|
+
import * as paths from '../hooks/lib/paths.mjs';
|
|
15
|
+
import { linkTargets, noteTargets } from '../hooks/lib/memory-link-lint.mjs';
|
|
16
|
+
import {
|
|
17
|
+
isStandingNegative,
|
|
18
|
+
hasConfidence,
|
|
19
|
+
isAbbreviated,
|
|
20
|
+
parseDeferred,
|
|
21
|
+
supersessionState,
|
|
22
|
+
freshnessFindings,
|
|
23
|
+
staleStampFindings,
|
|
24
|
+
isUnprovenancedMetric,
|
|
25
|
+
buildSuffixIndex,
|
|
26
|
+
checkFile,
|
|
27
|
+
pathFates,
|
|
28
|
+
linkResolver,
|
|
29
|
+
} from './lib/memory-audit-checks.mjs';
|
|
30
|
+
|
|
31
|
+
if (process.argv.includes('--check-file')) {
|
|
32
|
+
const f = process.argv[process.argv.indexOf('--check-file') + 1];
|
|
33
|
+
if (f) {
|
|
34
|
+
const out = checkFile(f);
|
|
35
|
+
if (out.length) console.log(out.join('\n'));
|
|
36
|
+
}
|
|
37
|
+
process.exit(0);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const repo = process.argv.slice(2).find((a) => !a.startsWith('--')) || process.cwd();
|
|
41
|
+
// maxBuffer: `git ls-files` in this monorepo is ~2 MB; the 1 MB default fails with ENOBUFS.
|
|
42
|
+
/** @param {string} c @param {string} [cwd] @returns {string} */
|
|
43
|
+
const sh = (c, cwd = repo) =>
|
|
44
|
+
execSync(c, {
|
|
45
|
+
cwd,
|
|
46
|
+
encoding: 'utf8',
|
|
47
|
+
stdio: ['ignore', 'pipe', 'ignore'],
|
|
48
|
+
maxBuffer: 64 * 1024 * 1024,
|
|
49
|
+
}).trim();
|
|
50
|
+
const VAULT = paths.vault();
|
|
51
|
+
const SLUG = paths.projectKey(repo);
|
|
52
|
+
const MEM = path.join(VAULT, 'Memory', SLUG);
|
|
53
|
+
const INS = path.join(VAULT, 'Insights', SLUG);
|
|
54
|
+
const FOLDERS = ['Patterns', 'Mistakes', 'Decisions'];
|
|
55
|
+
|
|
56
|
+
if (!fs.existsSync(MEM)) {
|
|
57
|
+
console.log(`no vault memory for ${SLUG} at ${MEM}`);
|
|
58
|
+
process.exit(0);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** @param {string} f @returns {string} */
|
|
62
|
+
const read = (f) => fs.readFileSync(f, 'utf8');
|
|
63
|
+
|
|
64
|
+
// --deferred: the carry-forward list alone, no repo scan. /memory:prune calls this first.
|
|
65
|
+
const reflections = path.join(INS, 'REFLECTIONS.md');
|
|
66
|
+
const stillDeferred = fs.existsSync(reflections) ? parseDeferred(read(reflections)) : [];
|
|
67
|
+
if (process.argv.includes('--deferred')) {
|
|
68
|
+
// Echo the resolved project. `repo` defaults to cwd, so running this from ~/.claude audits the
|
|
69
|
+
// CONFIG repo, finds its near-empty vault and reports "nothing deferred" with total confidence —
|
|
70
|
+
// which happened on 2026-08-14. Naming the slug makes a wrong-project run obvious at a glance.
|
|
71
|
+
console.log(`project: ${SLUG} (from ${repo})`);
|
|
72
|
+
if (!fs.existsSync(reflections))
|
|
73
|
+
console.log(`⚠ no REFLECTIONS.md for this project — wrong directory?`);
|
|
74
|
+
if (!stillDeferred.length) console.log('nothing still deferred in REFLECTIONS.md');
|
|
75
|
+
else {
|
|
76
|
+
console.log(
|
|
77
|
+
`${stillDeferred.length} item(s) still deferred — handle these BEFORE new findings:`,
|
|
78
|
+
);
|
|
79
|
+
for (const r of stillDeferred) console.log(` [${r.entry}] ${r.finding}`);
|
|
80
|
+
console.log(
|
|
81
|
+
'\nClosing one means editing its disposition in REFLECTIONS.md. An unedited row stays open forever.',
|
|
82
|
+
);
|
|
83
|
+
}
|
|
84
|
+
process.exit(0);
|
|
85
|
+
}
|
|
86
|
+
/** @param {string} d @returns {string[]} */
|
|
87
|
+
const mds = (d) => (fs.existsSync(d) ? fs.readdirSync(d).filter((f) => f.endsWith('.md')) : []);
|
|
88
|
+
/** @param {string} title @param {readonly string[]} lines */
|
|
89
|
+
const section = (title, lines) => {
|
|
90
|
+
if (!lines.length) return;
|
|
91
|
+
console.log(`\n## ${title}`);
|
|
92
|
+
lines.forEach((l) => console.log(' ' + l));
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
// ---------------------------------------------------------------- load
|
|
96
|
+
/** @typedef {{ file: string, layer: string, body: string }} Note */
|
|
97
|
+
/** @type {Map<string, Note>} */
|
|
98
|
+
const notes = new Map(); // name -> { file, layer, body }
|
|
99
|
+
for (const f of mds(MEM)) {
|
|
100
|
+
if (f === 'MEMORY.md') continue;
|
|
101
|
+
notes.set(f.slice(0, -3), {
|
|
102
|
+
file: path.join(MEM, f),
|
|
103
|
+
layer: 'Memory',
|
|
104
|
+
body: read(path.join(MEM, f)),
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
for (const fo of FOLDERS)
|
|
108
|
+
for (const f of mds(path.join(INS, fo)))
|
|
109
|
+
notes.set(f.slice(0, -3), {
|
|
110
|
+
file: path.join(INS, fo, f),
|
|
111
|
+
layer: fo,
|
|
112
|
+
body: read(path.join(INS, fo, f)),
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
const memNames = [...notes].filter(([, v]) => v.layer === 'Memory').map(([k]) => k);
|
|
116
|
+
const counts = FOLDERS.map((f) => `${f} ${mds(path.join(INS, f)).length}`).join(' / ');
|
|
117
|
+
console.log(`# ${SLUG}`);
|
|
118
|
+
console.log(
|
|
119
|
+
`snapshot: ${memNames.length} Memory + ${notes.size - memNames.length} Insights (${counts})`,
|
|
120
|
+
);
|
|
121
|
+
console.log(
|
|
122
|
+
'NOTE: the distiller writes concurrently — re-run at the end and report both counts if they moved.',
|
|
123
|
+
);
|
|
124
|
+
|
|
125
|
+
const resolve = linkResolver(VAULT, SLUG, new Set(notes.keys()));
|
|
126
|
+
/** @param {string} n @returns {boolean} */
|
|
127
|
+
const resolves = (n) => resolve(n) !== null;
|
|
128
|
+
|
|
129
|
+
// ---------------------------------------------------------------- MOC + graph
|
|
130
|
+
const mocPath = path.join(MEM, 'MEMORY.md');
|
|
131
|
+
const moc = fs.existsSync(mocPath) ? read(mocPath) : '';
|
|
132
|
+
// MEMORY.md is written with markdown links, not wikilinks; a wikilink-only parser reported all 8 L1
|
|
133
|
+
// notes as missing from the MOC on 2026-08-22. `noteTargets` reads both forms and is the only parser
|
|
134
|
+
// for this — `linkTargets` below stays wikilink-only, since a markdown link from the MOC is exactly what
|
|
135
|
+
// does NOT make a note reachable from a sibling.
|
|
136
|
+
const mocLinks = new Set(noteTargets(moc));
|
|
137
|
+
section(
|
|
138
|
+
'Not in the MOC',
|
|
139
|
+
memNames.filter((n) => !mocLinks.has(n)).map((n) => `${n} — add a one-line pointer to MEMORY.md`),
|
|
140
|
+
);
|
|
141
|
+
const allLinks = [...new Set([...notes.values()].flatMap((v) => [...linkTargets(v.body)]))];
|
|
142
|
+
section(
|
|
143
|
+
'Dangling wikilinks',
|
|
144
|
+
allLinks.filter((n) => !resolves(n)).map((n) => `[[${n}]] — no such note anywhere in the vault`),
|
|
145
|
+
);
|
|
146
|
+
// By link name only: another project's slug is a private repo's remote, and this output is pasted into issues.
|
|
147
|
+
section(
|
|
148
|
+
'Links to other projects (resolve in Obsidian — not dangling)',
|
|
149
|
+
allLinks.filter((n) => resolve(n) === 'elsewhere').map((n) => `[[${n}]]`),
|
|
150
|
+
);
|
|
151
|
+
|
|
152
|
+
const inbound = new Map([...notes.keys()].map((k) => /** @type {[string, number]} */ ([k, 0])));
|
|
153
|
+
for (const [k, v] of notes)
|
|
154
|
+
for (const l of linkTargets(v.body))
|
|
155
|
+
if (inbound.has(l) && l !== k && path.basename(v.file) !== 'MEMORY.md')
|
|
156
|
+
inbound.set(l, /** @type {number} */ (inbound.get(l)) + 1);
|
|
157
|
+
section(
|
|
158
|
+
'MOC-only (no inbound sibling link)',
|
|
159
|
+
memNames
|
|
160
|
+
.filter((n) => inbound.get(n) === 0)
|
|
161
|
+
.map((n) => `${n} — link it from a note someone reads before needing it`),
|
|
162
|
+
);
|
|
163
|
+
|
|
164
|
+
// ---------------------------------------------------------------- frontmatter
|
|
165
|
+
// confidence: lives under metadata:, so it is indented. A ^-anchored grep reports 46 false hits.
|
|
166
|
+
/** @type {string[]} */
|
|
167
|
+
const noConfidence = [];
|
|
168
|
+
/** @type {string[]} */
|
|
169
|
+
const nameMismatch = [];
|
|
170
|
+
for (const n of memNames) {
|
|
171
|
+
const body = /** @type {Note} */ (notes.get(n)).body;
|
|
172
|
+
const fm = (body.match(/^---\n([\s\S]*?)\n---/) || [])[1] || '';
|
|
173
|
+
if (!hasConfidence(fm)) noConfidence.push(n);
|
|
174
|
+
const declared = (fm.match(/^name:\s*(.+)$/m) || [])[1];
|
|
175
|
+
if (declared && declared.trim().replace(/^["']|["']$/g, '') !== n)
|
|
176
|
+
nameMismatch.push(`${n} — frontmatter says ${declared.trim()}`);
|
|
177
|
+
}
|
|
178
|
+
section('Missing confidence:', noConfidence);
|
|
179
|
+
section('name: does not match filename', nameMismatch);
|
|
180
|
+
// Insights notes carry title:, not name: — by distiller convention, not a defect. Not checked.
|
|
181
|
+
|
|
182
|
+
// ---------------------------------------------------------------- repo path claims
|
|
183
|
+
const tracked = new Set(sh('git ls-files').split('\n').filter(Boolean));
|
|
184
|
+
const bySuffix = buildSuffixIndex(tracked);
|
|
185
|
+
const TOP = '(?:apps|libs|tools|scripts|docs|styles|assets|e2e|\\.claude|\\.agents|\\.gitlab)';
|
|
186
|
+
const claimRe = new RegExp(`(?:^|[\\s\`'"(\\[])(${TOP}/[A-Za-z0-9._/-]*[A-Za-z0-9._-])`, 'g');
|
|
187
|
+
/** @type {string[]} */
|
|
188
|
+
const abbreviated = [];
|
|
189
|
+
/** @type {string[]} */
|
|
190
|
+
const suffixOnly = [];
|
|
191
|
+
/** @type {[string, string][]} */
|
|
192
|
+
const absent = [];
|
|
193
|
+
for (const n of memNames) {
|
|
194
|
+
const body = /** @type {Note} */ (notes.get(n)).body;
|
|
195
|
+
for (const line of body.split('\n')) {
|
|
196
|
+
for (const m of line.matchAll(claimRe)) {
|
|
197
|
+
const c = m[1].replace(/[.,;:]+$/, '');
|
|
198
|
+
if (isAbbreviated(line.slice(Math.max(0, m.index - 2), m.index + m[0].length + 2))) {
|
|
199
|
+
abbreviated.push(`${n}: ${c}`);
|
|
200
|
+
continue;
|
|
201
|
+
}
|
|
202
|
+
if (tracked.has(c) || fs.existsSync(path.join(repo, c))) continue;
|
|
203
|
+
const full = bySuffix.get(c);
|
|
204
|
+
if (full)
|
|
205
|
+
suffixOnly.push(
|
|
206
|
+
`${n}: \`${c}\` → real path is \`${full[0]}\`${full.length > 1 ? ` (+${full.length - 1} more)` : ''}`,
|
|
207
|
+
);
|
|
208
|
+
else absent.push([n, c]);
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
section('Path abbreviated to a suffix — WRITE THE FULL PATH', [...new Set(suffixOnly)]);
|
|
213
|
+
const fates = pathFates(
|
|
214
|
+
repo,
|
|
215
|
+
absent.map(([, c]) => c),
|
|
216
|
+
);
|
|
217
|
+
section(
|
|
218
|
+
'Path not on this branch (check whether the note names the branch — many are legitimately branch-only)',
|
|
219
|
+
[
|
|
220
|
+
...new Set(
|
|
221
|
+
absent.map(([n, c]) => {
|
|
222
|
+
const f = fates.get(c);
|
|
223
|
+
if (!f) return `${n}: ${c}`;
|
|
224
|
+
return f.to
|
|
225
|
+
? `${n}: ${c} → renamed to ${f.to} in ${f.sha}`
|
|
226
|
+
: `${n}: ${c} → deleted in ${f.sha}`;
|
|
227
|
+
}),
|
|
228
|
+
),
|
|
229
|
+
],
|
|
230
|
+
);
|
|
231
|
+
if (abbreviated.length)
|
|
232
|
+
console.log(
|
|
233
|
+
`\n(${new Set(abbreviated).size} ellipsis-abbreviated paths skipped — prose, not claims)`,
|
|
234
|
+
);
|
|
235
|
+
|
|
236
|
+
// ---------------------------------------------------------------- supersession candidates
|
|
237
|
+
// Standing-negative claims — what/why: skills/protocol/SKILL.md "Writing down an event? Name
|
|
238
|
+
// what it kills." Evidence it's real, not theoretical: REFLECTIONS 2026-08-14, the prod cutover
|
|
239
|
+
// killed exactly such a claim in two notes and nothing had pointed at it.
|
|
240
|
+
/** @type {string[]} */
|
|
241
|
+
const timeBombs = [];
|
|
242
|
+
for (const n of memNames) {
|
|
243
|
+
const body = /** @type {Note} */ (notes.get(n)).body;
|
|
244
|
+
body.split('\n').forEach((l, i) => {
|
|
245
|
+
if (isStandingNegative(l)) timeBombs.push(`${n}:${i + 1} ${l.trim().slice(0, 120)}`);
|
|
246
|
+
});
|
|
247
|
+
}
|
|
248
|
+
section(
|
|
249
|
+
`Standing-negative claims (${timeBombs.length}) — re-verify against anything that happened since`,
|
|
250
|
+
timeBombs.slice(0, 25).concat(timeBombs.length > 25 ? [`… +${timeBombs.length - 25} more`] : []),
|
|
251
|
+
);
|
|
252
|
+
|
|
253
|
+
// ---------------------------------------------------------------- duplicates
|
|
254
|
+
const STOP = new Set(
|
|
255
|
+
'the a an and or of to in on for is are was were it its this that with as by at from be not you your we our they them if then when what which how why do does did use used using via no yes into over under more most less least than each per also only just same other'.split(
|
|
256
|
+
' ',
|
|
257
|
+
),
|
|
258
|
+
);
|
|
259
|
+
/** @param {string} t @returns {Set<string>} */
|
|
260
|
+
const toks = (t) =>
|
|
261
|
+
new Set(
|
|
262
|
+
t
|
|
263
|
+
.toLowerCase()
|
|
264
|
+
.replace(/[^a-z0-9\s-]/g, ' ')
|
|
265
|
+
.split(/\s+/)
|
|
266
|
+
.filter((w) => w.length > 3 && !STOP.has(w)),
|
|
267
|
+
);
|
|
268
|
+
/** @type {{ jac: number, fo: string, a: string, b: string }[]} */
|
|
269
|
+
const dups = [];
|
|
270
|
+
for (const fo of FOLDERS) {
|
|
271
|
+
const docs = mds(path.join(INS, fo)).map((f) => ({
|
|
272
|
+
f: f.slice(0, -3),
|
|
273
|
+
t: toks(read(path.join(INS, fo, f))),
|
|
274
|
+
}));
|
|
275
|
+
for (let i = 0; i < docs.length; i++)
|
|
276
|
+
for (let j = i + 1; j < docs.length; j++) {
|
|
277
|
+
const [a, b] = [docs[i], docs[j]];
|
|
278
|
+
let inter = 0;
|
|
279
|
+
const [small, big] = a.t.size < b.t.size ? [a.t, b.t] : [b.t, a.t];
|
|
280
|
+
for (const t of small) if (big.has(t)) inter++;
|
|
281
|
+
const jac = inter / (a.t.size + b.t.size - inter);
|
|
282
|
+
if (jac >= 0.45) dups.push({ jac, fo, a: a.f, b: b.f });
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
dups.sort((x, y) => y.jac - x.jac);
|
|
286
|
+
section(
|
|
287
|
+
'Same-folder near-duplicates ≥0.45 (same folder first — cross-type pairs are complementary by design)',
|
|
288
|
+
dups.map((d) => `${d.jac.toFixed(2)} [${d.fo}] ${d.a}\n <> ${d.b}`),
|
|
289
|
+
);
|
|
290
|
+
if (dups.length)
|
|
291
|
+
console.log(
|
|
292
|
+
' → hand these to /memory:prune in the SAME session; a deferred pair only survives if the next prune happens to rank it.',
|
|
293
|
+
);
|
|
294
|
+
|
|
295
|
+
// ---------------------------------------------------------------- supersession (bi-temporal)
|
|
296
|
+
/** @type {string[]} */
|
|
297
|
+
const proseOnly = [];
|
|
298
|
+
/** @type {string[]} */
|
|
299
|
+
const supersededOk = [];
|
|
300
|
+
/** @type {string[]} */
|
|
301
|
+
const danglingSupersede = [];
|
|
302
|
+
for (const [n, v] of notes) {
|
|
303
|
+
const s = supersessionState(v.body);
|
|
304
|
+
if (s.declared) {
|
|
305
|
+
(resolves(s.declared) ? supersededOk : danglingSupersede).push(
|
|
306
|
+
`${n} → ${s.declared}${s.on ? ` (${s.on})` : ' — no superseded_on:'}`,
|
|
307
|
+
);
|
|
308
|
+
} else if (s.inProse && !s.marked && v.layer === 'Memory') {
|
|
309
|
+
proseOnly.push(
|
|
310
|
+
`${n} — reversal stated in prose only; mark the claim inline: (superseded YYYY-MM-DD by [[note]])`,
|
|
311
|
+
);
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
section('Supersession not machine-readable', proseOnly);
|
|
315
|
+
|
|
316
|
+
// FRESH-1: unstamped volatile claims. Reported for Memory only — Insights notes are lessons, and a
|
|
317
|
+
// dated Insight filename already makes the whole note a snapshot.
|
|
318
|
+
/** @type {string[]} */
|
|
319
|
+
const unstamped = [];
|
|
320
|
+
for (const n of memNames)
|
|
321
|
+
for (const f of freshnessFindings(/** @type {Note} */ (notes.get(n)).body))
|
|
322
|
+
unstamped.push(`${n}:${f.line} ${f.text.slice(0, 110)}`);
|
|
323
|
+
// FRESH-2 runs over both layers: a stamp is a stamp wherever it sits.
|
|
324
|
+
const now = new Date();
|
|
325
|
+
const today = [now.getFullYear(), now.getMonth() + 1, now.getDate()]
|
|
326
|
+
.map((n) => String(n).padStart(2, '0'))
|
|
327
|
+
.join('-');
|
|
328
|
+
/** @type {string[]} */
|
|
329
|
+
const staleStamps = [];
|
|
330
|
+
for (const [n, v] of notes) {
|
|
331
|
+
const w = paths.freshnessWindow(path.relative(VAULT, v.file).split(path.sep).join('/'));
|
|
332
|
+
for (const f of staleStampFindings(v.body, w.days, today))
|
|
333
|
+
staleStamps.push(
|
|
334
|
+
`${n}:${f.line} ${f.age}d old, ${w.folder} window ${w.days}d — ${f.text.slice(0, 80)}`,
|
|
335
|
+
);
|
|
336
|
+
}
|
|
337
|
+
// CLAIM-1 runs over BOTH layers: the inflated recall figure reached L1 notes, L3 Decision notes and
|
|
338
|
+
// a public README, so restricting it to Memory would have missed most of the damage.
|
|
339
|
+
/** @type {string[]} */
|
|
340
|
+
const unprovenanced = [];
|
|
341
|
+
for (const [n, v] of notes) {
|
|
342
|
+
const lines = v.body.split('\n');
|
|
343
|
+
lines.forEach((l, i) => {
|
|
344
|
+
const ctx = lines.slice(Math.max(0, i - 2), i + 2).join(' ');
|
|
345
|
+
if (isUnprovenancedMetric(l, ctx))
|
|
346
|
+
unprovenanced.push(`${n}:${i + 1} ${l.trim().slice(0, 105)}`);
|
|
347
|
+
});
|
|
348
|
+
}
|
|
349
|
+
section(
|
|
350
|
+
`CLAIM-1 — metric with no instrument named (${unprovenanced.length}); cite the run, script, case set or date that produced it`,
|
|
351
|
+
unprovenanced
|
|
352
|
+
.slice(0, 12)
|
|
353
|
+
.concat(unprovenanced.length > 12 ? [`… +${unprovenanced.length - 12} more`] : []),
|
|
354
|
+
);
|
|
355
|
+
|
|
356
|
+
section(
|
|
357
|
+
`FRESH-1 — volatile quantity, present tense, no stamp (${unstamped.length}); make it timeless, a dated snapshot, or a pointer`,
|
|
358
|
+
unstamped.slice(0, 15).concat(unstamped.length > 15 ? [`… +${unstamped.length - 15} more`] : []),
|
|
359
|
+
);
|
|
360
|
+
section(
|
|
361
|
+
`FRESH-2 — \`as of\` stamp older than its freshness window (${staleStamps.length}); refresh the observation or convert it to a pointer`,
|
|
362
|
+
staleStamps
|
|
363
|
+
.slice(0, 15)
|
|
364
|
+
.concat(staleStamps.length > 15 ? [`… +${staleStamps.length - 15} more`] : []),
|
|
365
|
+
);
|
|
366
|
+
section('superseded_by: points at a note that does not exist', danglingSupersede);
|
|
367
|
+
if (supersededOk.length)
|
|
368
|
+
console.log(`\n(${supersededOk.length} note(s) carry machine-readable supersession — good)`);
|
|
369
|
+
|
|
370
|
+
section(
|
|
371
|
+
'Still deferred from an earlier audit — close these before adding new ones',
|
|
372
|
+
stillDeferred.map((r) => `[${r.entry}] ${r.finding}`),
|
|
373
|
+
);
|
|
374
|
+
|
|
375
|
+
console.log('\ndone — every section above is a candidate, not a verdict.');
|