mindlore 0.6.8 → 0.7.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/README.md +259 -259
- package/SCHEMA.md +292 -292
- package/dist/scripts/cc-memory-bulk-sync.d.ts.map +1 -1
- package/dist/scripts/cc-memory-bulk-sync.js +4 -2
- package/dist/scripts/cc-memory-bulk-sync.js.map +1 -1
- package/dist/scripts/cc-session-sync.d.ts.map +1 -1
- package/dist/scripts/cc-session-sync.js +9 -7
- package/dist/scripts/cc-session-sync.js.map +1 -1
- package/dist/scripts/fetch-raw.js +5 -4
- package/dist/scripts/fetch-raw.js.map +1 -1
- package/dist/scripts/init.js +16 -12
- package/dist/scripts/init.js.map +1 -1
- package/dist/scripts/lib/consolidation.js +10 -10
- package/dist/scripts/lib/constants.d.ts +3 -0
- package/dist/scripts/lib/constants.d.ts.map +1 -1
- package/dist/scripts/lib/constants.js +11 -1
- package/dist/scripts/lib/constants.js.map +1 -1
- package/dist/scripts/lib/decay.js +9 -9
- package/dist/scripts/lib/episodes.js +23 -23
- package/dist/scripts/lib/err-msg.d.ts +2 -0
- package/dist/scripts/lib/err-msg.d.ts.map +1 -0
- package/dist/scripts/lib/err-msg.js +7 -0
- package/dist/scripts/lib/err-msg.js.map +1 -0
- package/dist/scripts/lib/mcp-namespace.d.ts +2 -0
- package/dist/scripts/lib/mcp-namespace.d.ts.map +1 -0
- package/dist/scripts/lib/mcp-namespace.js +21 -0
- package/dist/scripts/lib/mcp-namespace.js.map +1 -0
- package/dist/scripts/lib/mcp-telemetry.d.ts +11 -0
- package/dist/scripts/lib/mcp-telemetry.d.ts.map +1 -0
- package/dist/scripts/lib/mcp-telemetry.js +37 -0
- package/dist/scripts/lib/mcp-telemetry.js.map +1 -0
- package/dist/scripts/lib/mcp-tools.d.ts +10 -0
- package/dist/scripts/lib/mcp-tools.d.ts.map +1 -0
- package/dist/scripts/lib/mcp-tools.js +121 -0
- package/dist/scripts/lib/mcp-tools.js.map +1 -0
- package/dist/scripts/lib/migrations-v061.js +21 -21
- package/dist/scripts/lib/migrations-v062.js +11 -11
- package/dist/scripts/lib/migrations-v063.js +14 -14
- package/dist/scripts/lib/migrations-v067.js +11 -11
- package/dist/scripts/lib/rrf.d.ts.map +1 -1
- package/dist/scripts/lib/rrf.js +2 -1
- package/dist/scripts/lib/rrf.js.map +1 -1
- package/dist/scripts/lib/schema-version.js +6 -6
- package/dist/scripts/lib/search-cache.js +11 -11
- package/dist/scripts/lib/search-engine.d.ts +1 -0
- package/dist/scripts/lib/search-engine.d.ts.map +1 -1
- package/dist/scripts/lib/search-engine.js +9 -5
- package/dist/scripts/lib/search-engine.js.map +1 -1
- package/dist/scripts/lib/secure-io.d.ts +11 -0
- package/dist/scripts/lib/secure-io.d.ts.map +1 -0
- package/dist/scripts/lib/secure-io.js +26 -0
- package/dist/scripts/lib/secure-io.js.map +1 -0
- package/dist/scripts/lib/session-payload.js +7 -7
- package/dist/scripts/lib/slugify.d.ts +2 -0
- package/dist/scripts/lib/slugify.d.ts.map +1 -0
- package/dist/scripts/lib/slugify.js +13 -0
- package/dist/scripts/lib/slugify.js.map +1 -0
- package/dist/scripts/lib/smart-snippet.d.ts +9 -0
- package/dist/scripts/lib/smart-snippet.d.ts.map +1 -0
- package/dist/scripts/lib/smart-snippet.js +47 -0
- package/dist/scripts/lib/smart-snippet.js.map +1 -0
- package/dist/scripts/lib/tool-adapters/brief-adapter.d.ts +15 -0
- package/dist/scripts/lib/tool-adapters/brief-adapter.d.ts.map +1 -0
- package/dist/scripts/lib/tool-adapters/brief-adapter.js +66 -0
- package/dist/scripts/lib/tool-adapters/brief-adapter.js.map +1 -0
- package/dist/scripts/lib/tool-adapters/decide-adapter.d.ts +31 -0
- package/dist/scripts/lib/tool-adapters/decide-adapter.d.ts.map +1 -0
- package/dist/scripts/lib/tool-adapters/decide-adapter.js +71 -0
- package/dist/scripts/lib/tool-adapters/decide-adapter.js.map +1 -0
- package/dist/scripts/lib/tool-adapters/ingest-adapter.d.ts +16 -0
- package/dist/scripts/lib/tool-adapters/ingest-adapter.d.ts.map +1 -0
- package/dist/scripts/lib/tool-adapters/ingest-adapter.js +58 -0
- package/dist/scripts/lib/tool-adapters/ingest-adapter.js.map +1 -0
- package/dist/scripts/lib/tool-adapters/recall-adapter.d.ts +20 -0
- package/dist/scripts/lib/tool-adapters/recall-adapter.d.ts.map +1 -0
- package/dist/scripts/lib/tool-adapters/recall-adapter.js +69 -0
- package/dist/scripts/lib/tool-adapters/recall-adapter.js.map +1 -0
- package/dist/scripts/lib/tool-adapters/search-adapter.d.ts +22 -0
- package/dist/scripts/lib/tool-adapters/search-adapter.d.ts.map +1 -0
- package/dist/scripts/lib/tool-adapters/search-adapter.js +32 -0
- package/dist/scripts/lib/tool-adapters/search-adapter.js.map +1 -0
- package/dist/scripts/lib/tool-adapters/stats-adapter.d.ts +15 -0
- package/dist/scripts/lib/tool-adapters/stats-adapter.d.ts.map +1 -0
- package/dist/scripts/lib/tool-adapters/stats-adapter.js +66 -0
- package/dist/scripts/lib/tool-adapters/stats-adapter.js.map +1 -0
- package/dist/scripts/lib/triage.js +3 -3
- package/dist/scripts/lib/validate-manifest.d.ts +8 -0
- package/dist/scripts/lib/validate-manifest.d.ts.map +1 -0
- package/dist/scripts/lib/validate-manifest.js +80 -0
- package/dist/scripts/lib/validate-manifest.js.map +1 -0
- package/dist/scripts/maintain-cleanup.d.ts.map +1 -1
- package/dist/scripts/maintain-cleanup.js +3 -2
- package/dist/scripts/maintain-cleanup.js.map +1 -1
- package/dist/scripts/mcp-server.d.ts +3 -0
- package/dist/scripts/mcp-server.d.ts.map +1 -0
- package/dist/scripts/mcp-server.js +85 -0
- package/dist/scripts/mcp-server.js.map +1 -0
- package/dist/scripts/mindlore-backup.js +9 -9
- package/dist/scripts/mindlore-doctor.d.ts.map +1 -1
- package/dist/scripts/mindlore-doctor.js +4 -6
- package/dist/scripts/mindlore-doctor.js.map +1 -1
- package/dist/scripts/mindlore-fts5-index.js +12 -12
- package/dist/scripts/mindlore-fts5-index.js.map +1 -1
- package/dist/scripts/mindlore-health-check.d.ts.map +1 -1
- package/dist/scripts/mindlore-health-check.js +2 -2
- package/dist/scripts/mindlore-health-check.js.map +1 -1
- package/dist/scripts/validate-manifest-cli.d.ts +2 -0
- package/dist/scripts/validate-manifest-cli.d.ts.map +1 -0
- package/dist/scripts/validate-manifest-cli.js +38 -0
- package/dist/scripts/validate-manifest-cli.js.map +1 -0
- package/dist/tests/cc-memory-sync.test.js +3 -3
- package/dist/tests/chunks-migration.test.js +1 -1
- package/dist/tests/compaction-snapshot.test.js +2 -2
- package/dist/tests/consolidation.test.js +3 -3
- package/dist/tests/decay.test.js +9 -9
- package/dist/tests/diary.test.js +4 -4
- package/dist/tests/episode-file.test.js +2 -1
- package/dist/tests/episode-file.test.js.map +1 -1
- package/dist/tests/episodes-inject.test.js +9 -9
- package/dist/tests/err-msg.test.d.ts +2 -0
- package/dist/tests/err-msg.test.d.ts.map +1 -0
- package/dist/tests/err-msg.test.js +24 -0
- package/dist/tests/err-msg.test.js.map +1 -0
- package/dist/tests/fetch-raw.test.js +1 -2
- package/dist/tests/fetch-raw.test.js.map +1 -1
- package/dist/tests/fts5.test.js +75 -75
- package/dist/tests/fuzzy.test.js +1 -1
- package/dist/tests/git-snapshot.test.js +3 -5
- package/dist/tests/git-snapshot.test.js.map +1 -1
- package/dist/tests/helpers/db.d.ts +1 -2
- package/dist/tests/helpers/db.d.ts.map +1 -1
- package/dist/tests/helpers/db.js +18 -26
- package/dist/tests/helpers/db.js.map +1 -1
- package/dist/tests/manifest-v2.test.d.ts +2 -0
- package/dist/tests/manifest-v2.test.d.ts.map +1 -0
- package/dist/tests/manifest-v2.test.js +67 -0
- package/dist/tests/manifest-v2.test.js.map +1 -0
- package/dist/tests/mcp-server.test.d.ts +2 -0
- package/dist/tests/mcp-server.test.d.ts.map +1 -0
- package/dist/tests/mcp-server.test.js +118 -0
- package/dist/tests/mcp-server.test.js.map +1 -0
- package/dist/tests/mcp-tools.test.d.ts +2 -0
- package/dist/tests/mcp-tools.test.d.ts.map +1 -0
- package/dist/tests/mcp-tools.test.js +243 -0
- package/dist/tests/mcp-tools.test.js.map +1 -0
- package/dist/tests/migrations-v053.test.js +16 -16
- package/dist/tests/migrations-v061.test.js +10 -10
- package/dist/tests/migrations-v063.test.js +4 -4
- package/dist/tests/migrations-v068.test.js +6 -3
- package/dist/tests/migrations-v068.test.js.map +1 -1
- package/dist/tests/nomination-counts.test.js +6 -6
- package/dist/tests/nomination-counts.test.js.map +1 -1
- package/dist/tests/pre-compact.test.js +2 -1
- package/dist/tests/pre-compact.test.js.map +1 -1
- package/dist/tests/recall-telemetry.test.js +12 -11
- package/dist/tests/recall-telemetry.test.js.map +1 -1
- package/dist/tests/rrf.test.js +3 -3
- package/dist/tests/search-engine.test.js +1 -1
- package/dist/tests/search-hook.test.js +2 -2
- package/dist/tests/search-offload.test.js +1 -1
- package/dist/tests/search-offload.test.js.map +1 -1
- package/dist/tests/secure-io.test.d.ts +2 -0
- package/dist/tests/secure-io.test.d.ts.map +1 -0
- package/dist/tests/secure-io.test.js +65 -0
- package/dist/tests/secure-io.test.js.map +1 -0
- package/dist/tests/session-payload.test.js +1 -1
- package/dist/tests/session-summary.test.js +1 -1
- package/dist/tests/similarity.test.js +1 -1
- package/dist/tests/skill-path-resolution.test.js +22 -3
- package/dist/tests/skill-path-resolution.test.js.map +1 -1
- package/dist/tests/smart-snippet.test.d.ts +2 -0
- package/dist/tests/smart-snippet.test.d.ts.map +1 -0
- package/dist/tests/smart-snippet.test.js +67 -0
- package/dist/tests/smart-snippet.test.js.map +1 -0
- package/dist/tests/triage.test.js +1 -1
- package/hooks/lib/constants.cjs +15 -15
- package/hooks/lib/mindlore-common.cjs +975 -974
- package/hooks/mindlore-cwd-changed.cjs +57 -57
- package/hooks/mindlore-decision-detector.cjs +54 -54
- package/hooks/mindlore-dont-repeat.cjs +222 -222
- package/hooks/mindlore-fts5-sync.cjs +98 -97
- package/hooks/mindlore-index.cjs +230 -229
- package/hooks/mindlore-model-router.cjs +54 -54
- package/hooks/mindlore-post-compact.cjs +69 -69
- package/hooks/mindlore-post-read.cjs +106 -106
- package/hooks/mindlore-pre-compact.cjs +154 -154
- package/hooks/mindlore-read-guard.cjs +105 -105
- package/hooks/mindlore-research-guard.cjs +176 -176
- package/hooks/mindlore-search.cjs +200 -200
- package/hooks/mindlore-session-end.cjs +510 -509
- package/hooks/mindlore-session-focus.cjs +256 -256
- package/package.json +77 -75
- package/plugin.json +8 -1
- package/skills/mindlore-diary/SKILL.md +85 -85
- package/skills/mindlore-evolve/SKILL.md +126 -126
- package/skills/mindlore-explore/SKILL.md +109 -109
- package/skills/mindlore-ingest/SKILL.md +195 -195
- package/skills/mindlore-maintain/SKILL.md +125 -125
- package/skills/mindlore-query/SKILL.md +151 -151
- package/skills/mindlore-reflect/SKILL.md +141 -141
- package/skills/mindlore-stats/SKILL.md +106 -106
- package/templates/INDEX.md +14 -14
- package/templates/SCHEMA.md +292 -292
- package/templates/config.json +1 -1
- package/templates/extraction/article.md +15 -15
- package/templates/extraction/changelog.md +15 -15
- package/templates/extraction/default.md +15 -15
- package/templates/extraction/docs.md +15 -15
- package/templates/extraction/github-repo.md +17 -17
package/hooks/mindlore-index.cjs
CHANGED
|
@@ -1,229 +1,230 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
'use strict';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* mindlore-index — FileChanged hook
|
|
6
|
-
*
|
|
7
|
-
* When a .md file in .mindlore/ changes, update its FTS5 entry.
|
|
8
|
-
* Reads changed file path from stdin (CC FileChanged event).
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
const fs = require('fs');
|
|
12
|
-
const path = require('path');
|
|
13
|
-
const {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
&& resolvedFile.
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
db.prepare('DELETE FROM
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
const
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
.
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
const {
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
db
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
const
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
const
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
const
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
const
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
const
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
const
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
const
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
const
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
db.
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* mindlore-index — FileChanged hook
|
|
6
|
+
*
|
|
7
|
+
* When a .md file in .mindlore/ changes, update its FTS5 entry.
|
|
8
|
+
* Reads changed file path from stdin (CC FileChanged event).
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
const fs = require('fs');
|
|
12
|
+
const path = require('path');
|
|
13
|
+
const { safeMkdir, safeWriteFile } = require('../dist/scripts/lib/secure-io.js');
|
|
14
|
+
const { DB_NAME, SKIP_FILES, sha256, openDatabase, parseFrontmatter, extractFtsMetadata, insertFtsRow, readHookStdin, getProjectName, resolveProject, globalDir, hookLog, withTelemetry, isInsideMindloreDir, extractMindloreBaseDir } = require('./lib/mindlore-common.cjs');
|
|
15
|
+
|
|
16
|
+
function invalidateSearchCache(db) {
|
|
17
|
+
try { db.exec('DELETE FROM search_cache'); } catch (_) { /* table may not exist */ }
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function main() {
|
|
21
|
+
const filePath = readHookStdin(['path', 'file_path']);
|
|
22
|
+
if (!filePath) return;
|
|
23
|
+
|
|
24
|
+
// Only process .md files inside .mindlore/ (resolved path check prevents traversal)
|
|
25
|
+
if (!filePath.endsWith('.md')) return;
|
|
26
|
+
const resolvedFile = path.resolve(filePath);
|
|
27
|
+
if (!isInsideMindloreDir(resolvedFile)) {
|
|
28
|
+
// CC memory path (~/.claude/projects/*/memory/*.md) — index to global mindlore DB
|
|
29
|
+
const isCcMemory = resolvedFile.includes(path.sep + '.claude' + path.sep + 'projects' + path.sep)
|
|
30
|
+
&& resolvedFile.includes(path.sep + 'memory' + path.sep)
|
|
31
|
+
&& resolvedFile.endsWith('.md');
|
|
32
|
+
if (!isCcMemory) return;
|
|
33
|
+
|
|
34
|
+
// CC memory path — index to global mindlore DB
|
|
35
|
+
indexCcMemory(resolvedFile);
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const fileName = path.basename(filePath);
|
|
40
|
+
|
|
41
|
+
const baseDir = extractMindloreBaseDir(resolvedFile);
|
|
42
|
+
if (!baseDir) return;
|
|
43
|
+
const dbPath = path.join(baseDir, DB_NAME);
|
|
44
|
+
|
|
45
|
+
if (!fs.existsSync(dbPath)) return;
|
|
46
|
+
|
|
47
|
+
// Catch-up scan: when INDEX.md or log.md triggers, index recently-modified files
|
|
48
|
+
if (['INDEX.md', 'log.md'].includes(fileName)) {
|
|
49
|
+
catchUpScan(baseDir, dbPath);
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
if (SKIP_FILES.has(fileName)) return;
|
|
54
|
+
|
|
55
|
+
if (!fs.existsSync(filePath)) {
|
|
56
|
+
// File was deleted — remove from index
|
|
57
|
+
const db = openDatabase(dbPath);
|
|
58
|
+
if (!db) return;
|
|
59
|
+
try {
|
|
60
|
+
db.prepare('DELETE FROM mindlore_fts WHERE path = ?').run(filePath);
|
|
61
|
+
db.prepare('DELETE FROM file_hashes WHERE path = ?').run(filePath);
|
|
62
|
+
invalidateSearchCache(db);
|
|
63
|
+
} finally {
|
|
64
|
+
db.close();
|
|
65
|
+
}
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const content = fs.readFileSync(filePath, 'utf8').replace(/\r\n/g, '\n');
|
|
70
|
+
const hash = sha256(content);
|
|
71
|
+
|
|
72
|
+
const db = openDatabase(dbPath);
|
|
73
|
+
if (!db) return;
|
|
74
|
+
|
|
75
|
+
try {
|
|
76
|
+
// Check if content changed
|
|
77
|
+
const existing = db
|
|
78
|
+
.prepare('SELECT content_hash FROM file_hashes WHERE path = ?')
|
|
79
|
+
.get(filePath);
|
|
80
|
+
|
|
81
|
+
if (existing && existing.content_hash === hash) return; // Unchanged
|
|
82
|
+
|
|
83
|
+
// Parse frontmatter for rich FTS5 columns
|
|
84
|
+
const { meta, body } = parseFrontmatter(content);
|
|
85
|
+
const { slug, description, type, category, title, tags, quality, dateCaptured, project: ftsProject } = extractFtsMetadata(meta, body, filePath, baseDir);
|
|
86
|
+
|
|
87
|
+
// Update FTS5 + hash atomically
|
|
88
|
+
const updateIndex = db.transaction(() => {
|
|
89
|
+
db.prepare('DELETE FROM mindlore_fts WHERE path = ?').run(filePath);
|
|
90
|
+
insertFtsRow(db, { path: filePath, slug, description, type, category, title, content: body, tags, quality, dateCaptured, project: resolveProject(ftsProject, filePath, getProjectName()) });
|
|
91
|
+
db.prepare(
|
|
92
|
+
`INSERT INTO file_hashes (path, content_hash, last_indexed)
|
|
93
|
+
VALUES (?, ?, ?)
|
|
94
|
+
ON CONFLICT(path) DO UPDATE SET
|
|
95
|
+
content_hash = excluded.content_hash,
|
|
96
|
+
last_indexed = excluded.last_indexed`
|
|
97
|
+
).run(filePath, hash, new Date().toISOString());
|
|
98
|
+
});
|
|
99
|
+
updateIndex();
|
|
100
|
+
invalidateSearchCache(db);
|
|
101
|
+
} finally {
|
|
102
|
+
db.close();
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
function indexCcMemory(filePath) {
|
|
107
|
+
const CC_MEMORY_CATEGORY = 'cc-memory';
|
|
108
|
+
// CC memory constants live in TS (scripts/lib/constants.ts) — CJS hooks can't require TS directly
|
|
109
|
+
const globalBase = globalDir();
|
|
110
|
+
const dbPath = path.join(globalBase, DB_NAME);
|
|
111
|
+
|
|
112
|
+
const content = fs.readFileSync(filePath, 'utf8').replace(/\r\n/g, '\n');
|
|
113
|
+
if (!content.trim()) return;
|
|
114
|
+
|
|
115
|
+
// Privacy filter — redact secrets before DB write
|
|
116
|
+
let cleaned = content;
|
|
117
|
+
try {
|
|
118
|
+
const { redactSecrets } = require('../dist/scripts/lib/privacy-filter.js');
|
|
119
|
+
cleaned = redactSecrets(content);
|
|
120
|
+
} catch (_err) {
|
|
121
|
+
// privacy-filter not built — use raw content
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
// SHA256 dedup
|
|
125
|
+
const hash = sha256(cleaned);
|
|
126
|
+
const db = openDatabase(dbPath);
|
|
127
|
+
if (!db) return;
|
|
128
|
+
|
|
129
|
+
try {
|
|
130
|
+
const existing = db.prepare('SELECT content_hash FROM file_hashes WHERE path = ?').get(filePath);
|
|
131
|
+
if (existing && existing.content_hash === hash) {
|
|
132
|
+
return; // unchanged — finally handles db.close()
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
const { meta, body } = parseFrontmatter(cleaned);
|
|
136
|
+
const memType = String(meta.type || 'unknown');
|
|
137
|
+
|
|
138
|
+
// Extract project scope from path: ~/.claude/projects/C--Users-X-proj/memory/
|
|
139
|
+
const projMatch = filePath.match(/projects[/\\]([^/\\]+)[/\\]memory/);
|
|
140
|
+
const projectScope = projMatch ? projMatch[1] : null;
|
|
141
|
+
|
|
142
|
+
const ftsData = extractFtsMetadata(meta, body, filePath, globalBase);
|
|
143
|
+
|
|
144
|
+
// Update FTS5 + hash atomically
|
|
145
|
+
const updateIndex = db.transaction(() => {
|
|
146
|
+
db.prepare('DELETE FROM mindlore_fts WHERE path = ?').run(filePath);
|
|
147
|
+
insertFtsRow(db, {
|
|
148
|
+
path: filePath,
|
|
149
|
+
...ftsData,
|
|
150
|
+
category: CC_MEMORY_CATEGORY,
|
|
151
|
+
type: memType,
|
|
152
|
+
project: projectScope,
|
|
153
|
+
});
|
|
154
|
+
db.prepare(
|
|
155
|
+
`INSERT INTO file_hashes (path, content_hash, last_indexed, source_type, project_scope)
|
|
156
|
+
VALUES (?, ?, ?, ?, ?)
|
|
157
|
+
ON CONFLICT(path) DO UPDATE SET
|
|
158
|
+
content_hash = excluded.content_hash,
|
|
159
|
+
last_indexed = excluded.last_indexed,
|
|
160
|
+
source_type = excluded.source_type,
|
|
161
|
+
project_scope = excluded.project_scope`
|
|
162
|
+
).run(filePath, hash, new Date().toISOString(), CC_MEMORY_CATEGORY, projectScope);
|
|
163
|
+
});
|
|
164
|
+
updateIndex();
|
|
165
|
+
|
|
166
|
+
// Copy to ~/.mindlore/memory/{project}/ for git-sync + obsidian
|
|
167
|
+
const memoryDir = path.join(globalBase, 'memory', projectScope || '_global');
|
|
168
|
+
safeMkdir(memoryDir);
|
|
169
|
+
const destPath = path.join(memoryDir, path.basename(filePath));
|
|
170
|
+
safeWriteFile(destPath, cleaned);
|
|
171
|
+
} finally {
|
|
172
|
+
db.close();
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
function catchUpScan(baseDir, dbPath) {
|
|
177
|
+
const CATCH_UP_DIRS = ['raw', 'sources', 'analyses', 'diary'];
|
|
178
|
+
const fiveMinAgo = Date.now() - 5 * 60 * 1000;
|
|
179
|
+
|
|
180
|
+
const db = openDatabase(dbPath);
|
|
181
|
+
if (!db) return;
|
|
182
|
+
|
|
183
|
+
try {
|
|
184
|
+
let indexed = 0;
|
|
185
|
+
for (const dir of CATCH_UP_DIRS) {
|
|
186
|
+
const dirPath = path.join(baseDir, dir);
|
|
187
|
+
if (!fs.existsSync(dirPath)) continue;
|
|
188
|
+
|
|
189
|
+
const files = fs.readdirSync(dirPath).filter(f => f.endsWith('.md'));
|
|
190
|
+
for (const file of files) {
|
|
191
|
+
const filePath = path.join(dirPath, file);
|
|
192
|
+
const stat = fs.statSync(filePath);
|
|
193
|
+
if (stat.mtimeMs < fiveMinAgo) continue;
|
|
194
|
+
|
|
195
|
+
const content = fs.readFileSync(filePath, 'utf8').replace(/\r\n/g, '\n');
|
|
196
|
+
const hash = sha256(content);
|
|
197
|
+
|
|
198
|
+
const existing = db.prepare('SELECT content_hash FROM file_hashes WHERE path = ?').get(filePath);
|
|
199
|
+
if (existing && existing.content_hash === hash) continue;
|
|
200
|
+
|
|
201
|
+
const { meta, body } = parseFrontmatter(content);
|
|
202
|
+
const ftsData = extractFtsMetadata(meta, body, filePath, baseDir);
|
|
203
|
+
|
|
204
|
+
const update = db.transaction(() => {
|
|
205
|
+
db.prepare('DELETE FROM mindlore_fts WHERE path = ?').run(filePath);
|
|
206
|
+
insertFtsRow(db, { path: filePath, ...ftsData, project: resolveProject(ftsData.project, filePath, getProjectName()) });
|
|
207
|
+
db.prepare(
|
|
208
|
+
`INSERT INTO file_hashes (path, content_hash, last_indexed)
|
|
209
|
+
VALUES (?, ?, ?)
|
|
210
|
+
ON CONFLICT(path) DO UPDATE SET
|
|
211
|
+
content_hash = excluded.content_hash,
|
|
212
|
+
last_indexed = excluded.last_indexed`
|
|
213
|
+
).run(filePath, hash, new Date().toISOString());
|
|
214
|
+
});
|
|
215
|
+
update();
|
|
216
|
+
indexed++;
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
if (indexed > 0) {
|
|
220
|
+
hookLog(`catch-up: ${indexed} file(s) indexed`);
|
|
221
|
+
}
|
|
222
|
+
} finally {
|
|
223
|
+
db.close();
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
withTelemetry('mindlore-index', main).catch(err => {
|
|
228
|
+
hookLog('mindlore-index', 'error', err?.message ?? String(err));
|
|
229
|
+
process.exit(0);
|
|
230
|
+
});
|
|
@@ -1,54 +1,54 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* mindlore-model-router — PreToolUse (Agent) hook
|
|
5
|
-
* Overrides model for [mindlore:SKILL] marked Agent spawns.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
const fs = require('fs');
|
|
9
|
-
const { findMindloreDir, readConfig, DEFAULT_MODELS, hookLog, withTelemetrySync } = require('./lib/mindlore-common.cjs');
|
|
10
|
-
|
|
11
|
-
const SKILL_KEYS = Object.keys(DEFAULT_MODELS).filter((k) => k !== 'default');
|
|
12
|
-
const MARKER_REGEX = new RegExp(`\\[mindlore:(${SKILL_KEYS.join('|')})\\]`);
|
|
13
|
-
|
|
14
|
-
function main() {
|
|
15
|
-
const mindloreDir = findMindloreDir();
|
|
16
|
-
if (!mindloreDir) return;
|
|
17
|
-
|
|
18
|
-
let input;
|
|
19
|
-
try {
|
|
20
|
-
const raw = fs.readFileSync(0, 'utf8').trim();
|
|
21
|
-
if (!raw) return;
|
|
22
|
-
input = JSON.parse(raw);
|
|
23
|
-
} catch (_err) {
|
|
24
|
-
return;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
const toolName = input.tool_name || '';
|
|
28
|
-
if (toolName !== 'Agent') return;
|
|
29
|
-
|
|
30
|
-
const toolInput = input.tool_input || {};
|
|
31
|
-
const prompt = toolInput.prompt || '';
|
|
32
|
-
const match = prompt.match(MARKER_REGEX);
|
|
33
|
-
if (!match) return;
|
|
34
|
-
|
|
35
|
-
const skill = match[1];
|
|
36
|
-
|
|
37
|
-
// Resolve model: config.json → config default → hardcoded
|
|
38
|
-
const config = readConfig(mindloreDir);
|
|
39
|
-
const models = (config && config.models) || {};
|
|
40
|
-
const model = models[skill] || models.default || DEFAULT_MODELS[skill] || DEFAULT_MODELS.default;
|
|
41
|
-
|
|
42
|
-
const updatedInput = { ...toolInput, model: model };
|
|
43
|
-
|
|
44
|
-
const output = {
|
|
45
|
-
hookSpecificOutput: {
|
|
46
|
-
hookEventName: 'PreToolUse',
|
|
47
|
-
updatedInput: updatedInput,
|
|
48
|
-
},
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
process.stdout.write(JSON.stringify(output));
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
try { withTelemetrySync('mindlore-model-router', main); } catch (err) { hookLog('model-router', 'error', err?.message ?? String(err)); }
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* mindlore-model-router — PreToolUse (Agent) hook
|
|
5
|
+
* Overrides model for [mindlore:SKILL] marked Agent spawns.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
const fs = require('fs');
|
|
9
|
+
const { findMindloreDir, readConfig, DEFAULT_MODELS, hookLog, withTelemetrySync } = require('./lib/mindlore-common.cjs');
|
|
10
|
+
|
|
11
|
+
const SKILL_KEYS = Object.keys(DEFAULT_MODELS).filter((k) => k !== 'default');
|
|
12
|
+
const MARKER_REGEX = new RegExp(`\\[mindlore:(${SKILL_KEYS.join('|')})\\]`);
|
|
13
|
+
|
|
14
|
+
function main() {
|
|
15
|
+
const mindloreDir = findMindloreDir();
|
|
16
|
+
if (!mindloreDir) return;
|
|
17
|
+
|
|
18
|
+
let input;
|
|
19
|
+
try {
|
|
20
|
+
const raw = fs.readFileSync(0, 'utf8').trim();
|
|
21
|
+
if (!raw) return;
|
|
22
|
+
input = JSON.parse(raw);
|
|
23
|
+
} catch (_err) {
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const toolName = input.tool_name || '';
|
|
28
|
+
if (toolName !== 'Agent') return;
|
|
29
|
+
|
|
30
|
+
const toolInput = input.tool_input || {};
|
|
31
|
+
const prompt = toolInput.prompt || '';
|
|
32
|
+
const match = prompt.match(MARKER_REGEX);
|
|
33
|
+
if (!match) return;
|
|
34
|
+
|
|
35
|
+
const skill = match[1];
|
|
36
|
+
|
|
37
|
+
// Resolve model: config.json → config default → hardcoded
|
|
38
|
+
const config = readConfig(mindloreDir);
|
|
39
|
+
const models = (config && config.models) || {};
|
|
40
|
+
const model = models[skill] || models.default || DEFAULT_MODELS[skill] || DEFAULT_MODELS.default;
|
|
41
|
+
|
|
42
|
+
const updatedInput = { ...toolInput, model: model };
|
|
43
|
+
|
|
44
|
+
const output = {
|
|
45
|
+
hookSpecificOutput: {
|
|
46
|
+
hookEventName: 'PreToolUse',
|
|
47
|
+
updatedInput: updatedInput,
|
|
48
|
+
},
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
process.stdout.write(JSON.stringify(output));
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
try { withTelemetrySync('mindlore-model-router', main); } catch (err) { hookLog('model-router', 'error', err?.message ?? String(err)); }
|