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.
Files changed (209) hide show
  1. package/README.md +259 -259
  2. package/SCHEMA.md +292 -292
  3. package/dist/scripts/cc-memory-bulk-sync.d.ts.map +1 -1
  4. package/dist/scripts/cc-memory-bulk-sync.js +4 -2
  5. package/dist/scripts/cc-memory-bulk-sync.js.map +1 -1
  6. package/dist/scripts/cc-session-sync.d.ts.map +1 -1
  7. package/dist/scripts/cc-session-sync.js +9 -7
  8. package/dist/scripts/cc-session-sync.js.map +1 -1
  9. package/dist/scripts/fetch-raw.js +5 -4
  10. package/dist/scripts/fetch-raw.js.map +1 -1
  11. package/dist/scripts/init.js +16 -12
  12. package/dist/scripts/init.js.map +1 -1
  13. package/dist/scripts/lib/consolidation.js +10 -10
  14. package/dist/scripts/lib/constants.d.ts +3 -0
  15. package/dist/scripts/lib/constants.d.ts.map +1 -1
  16. package/dist/scripts/lib/constants.js +11 -1
  17. package/dist/scripts/lib/constants.js.map +1 -1
  18. package/dist/scripts/lib/decay.js +9 -9
  19. package/dist/scripts/lib/episodes.js +23 -23
  20. package/dist/scripts/lib/err-msg.d.ts +2 -0
  21. package/dist/scripts/lib/err-msg.d.ts.map +1 -0
  22. package/dist/scripts/lib/err-msg.js +7 -0
  23. package/dist/scripts/lib/err-msg.js.map +1 -0
  24. package/dist/scripts/lib/mcp-namespace.d.ts +2 -0
  25. package/dist/scripts/lib/mcp-namespace.d.ts.map +1 -0
  26. package/dist/scripts/lib/mcp-namespace.js +21 -0
  27. package/dist/scripts/lib/mcp-namespace.js.map +1 -0
  28. package/dist/scripts/lib/mcp-telemetry.d.ts +11 -0
  29. package/dist/scripts/lib/mcp-telemetry.d.ts.map +1 -0
  30. package/dist/scripts/lib/mcp-telemetry.js +37 -0
  31. package/dist/scripts/lib/mcp-telemetry.js.map +1 -0
  32. package/dist/scripts/lib/mcp-tools.d.ts +10 -0
  33. package/dist/scripts/lib/mcp-tools.d.ts.map +1 -0
  34. package/dist/scripts/lib/mcp-tools.js +121 -0
  35. package/dist/scripts/lib/mcp-tools.js.map +1 -0
  36. package/dist/scripts/lib/migrations-v061.js +21 -21
  37. package/dist/scripts/lib/migrations-v062.js +11 -11
  38. package/dist/scripts/lib/migrations-v063.js +14 -14
  39. package/dist/scripts/lib/migrations-v067.js +11 -11
  40. package/dist/scripts/lib/rrf.d.ts.map +1 -1
  41. package/dist/scripts/lib/rrf.js +2 -1
  42. package/dist/scripts/lib/rrf.js.map +1 -1
  43. package/dist/scripts/lib/schema-version.js +6 -6
  44. package/dist/scripts/lib/search-cache.js +11 -11
  45. package/dist/scripts/lib/search-engine.d.ts +1 -0
  46. package/dist/scripts/lib/search-engine.d.ts.map +1 -1
  47. package/dist/scripts/lib/search-engine.js +9 -5
  48. package/dist/scripts/lib/search-engine.js.map +1 -1
  49. package/dist/scripts/lib/secure-io.d.ts +11 -0
  50. package/dist/scripts/lib/secure-io.d.ts.map +1 -0
  51. package/dist/scripts/lib/secure-io.js +26 -0
  52. package/dist/scripts/lib/secure-io.js.map +1 -0
  53. package/dist/scripts/lib/session-payload.js +7 -7
  54. package/dist/scripts/lib/slugify.d.ts +2 -0
  55. package/dist/scripts/lib/slugify.d.ts.map +1 -0
  56. package/dist/scripts/lib/slugify.js +13 -0
  57. package/dist/scripts/lib/slugify.js.map +1 -0
  58. package/dist/scripts/lib/smart-snippet.d.ts +9 -0
  59. package/dist/scripts/lib/smart-snippet.d.ts.map +1 -0
  60. package/dist/scripts/lib/smart-snippet.js +47 -0
  61. package/dist/scripts/lib/smart-snippet.js.map +1 -0
  62. package/dist/scripts/lib/tool-adapters/brief-adapter.d.ts +15 -0
  63. package/dist/scripts/lib/tool-adapters/brief-adapter.d.ts.map +1 -0
  64. package/dist/scripts/lib/tool-adapters/brief-adapter.js +66 -0
  65. package/dist/scripts/lib/tool-adapters/brief-adapter.js.map +1 -0
  66. package/dist/scripts/lib/tool-adapters/decide-adapter.d.ts +31 -0
  67. package/dist/scripts/lib/tool-adapters/decide-adapter.d.ts.map +1 -0
  68. package/dist/scripts/lib/tool-adapters/decide-adapter.js +71 -0
  69. package/dist/scripts/lib/tool-adapters/decide-adapter.js.map +1 -0
  70. package/dist/scripts/lib/tool-adapters/ingest-adapter.d.ts +16 -0
  71. package/dist/scripts/lib/tool-adapters/ingest-adapter.d.ts.map +1 -0
  72. package/dist/scripts/lib/tool-adapters/ingest-adapter.js +58 -0
  73. package/dist/scripts/lib/tool-adapters/ingest-adapter.js.map +1 -0
  74. package/dist/scripts/lib/tool-adapters/recall-adapter.d.ts +20 -0
  75. package/dist/scripts/lib/tool-adapters/recall-adapter.d.ts.map +1 -0
  76. package/dist/scripts/lib/tool-adapters/recall-adapter.js +69 -0
  77. package/dist/scripts/lib/tool-adapters/recall-adapter.js.map +1 -0
  78. package/dist/scripts/lib/tool-adapters/search-adapter.d.ts +22 -0
  79. package/dist/scripts/lib/tool-adapters/search-adapter.d.ts.map +1 -0
  80. package/dist/scripts/lib/tool-adapters/search-adapter.js +32 -0
  81. package/dist/scripts/lib/tool-adapters/search-adapter.js.map +1 -0
  82. package/dist/scripts/lib/tool-adapters/stats-adapter.d.ts +15 -0
  83. package/dist/scripts/lib/tool-adapters/stats-adapter.d.ts.map +1 -0
  84. package/dist/scripts/lib/tool-adapters/stats-adapter.js +66 -0
  85. package/dist/scripts/lib/tool-adapters/stats-adapter.js.map +1 -0
  86. package/dist/scripts/lib/triage.js +3 -3
  87. package/dist/scripts/lib/validate-manifest.d.ts +8 -0
  88. package/dist/scripts/lib/validate-manifest.d.ts.map +1 -0
  89. package/dist/scripts/lib/validate-manifest.js +80 -0
  90. package/dist/scripts/lib/validate-manifest.js.map +1 -0
  91. package/dist/scripts/maintain-cleanup.d.ts.map +1 -1
  92. package/dist/scripts/maintain-cleanup.js +3 -2
  93. package/dist/scripts/maintain-cleanup.js.map +1 -1
  94. package/dist/scripts/mcp-server.d.ts +3 -0
  95. package/dist/scripts/mcp-server.d.ts.map +1 -0
  96. package/dist/scripts/mcp-server.js +85 -0
  97. package/dist/scripts/mcp-server.js.map +1 -0
  98. package/dist/scripts/mindlore-backup.js +9 -9
  99. package/dist/scripts/mindlore-doctor.d.ts.map +1 -1
  100. package/dist/scripts/mindlore-doctor.js +4 -6
  101. package/dist/scripts/mindlore-doctor.js.map +1 -1
  102. package/dist/scripts/mindlore-fts5-index.js +12 -12
  103. package/dist/scripts/mindlore-fts5-index.js.map +1 -1
  104. package/dist/scripts/mindlore-health-check.d.ts.map +1 -1
  105. package/dist/scripts/mindlore-health-check.js +2 -2
  106. package/dist/scripts/mindlore-health-check.js.map +1 -1
  107. package/dist/scripts/validate-manifest-cli.d.ts +2 -0
  108. package/dist/scripts/validate-manifest-cli.d.ts.map +1 -0
  109. package/dist/scripts/validate-manifest-cli.js +38 -0
  110. package/dist/scripts/validate-manifest-cli.js.map +1 -0
  111. package/dist/tests/cc-memory-sync.test.js +3 -3
  112. package/dist/tests/chunks-migration.test.js +1 -1
  113. package/dist/tests/compaction-snapshot.test.js +2 -2
  114. package/dist/tests/consolidation.test.js +3 -3
  115. package/dist/tests/decay.test.js +9 -9
  116. package/dist/tests/diary.test.js +4 -4
  117. package/dist/tests/episode-file.test.js +2 -1
  118. package/dist/tests/episode-file.test.js.map +1 -1
  119. package/dist/tests/episodes-inject.test.js +9 -9
  120. package/dist/tests/err-msg.test.d.ts +2 -0
  121. package/dist/tests/err-msg.test.d.ts.map +1 -0
  122. package/dist/tests/err-msg.test.js +24 -0
  123. package/dist/tests/err-msg.test.js.map +1 -0
  124. package/dist/tests/fetch-raw.test.js +1 -2
  125. package/dist/tests/fetch-raw.test.js.map +1 -1
  126. package/dist/tests/fts5.test.js +75 -75
  127. package/dist/tests/fuzzy.test.js +1 -1
  128. package/dist/tests/git-snapshot.test.js +3 -5
  129. package/dist/tests/git-snapshot.test.js.map +1 -1
  130. package/dist/tests/helpers/db.d.ts +1 -2
  131. package/dist/tests/helpers/db.d.ts.map +1 -1
  132. package/dist/tests/helpers/db.js +18 -26
  133. package/dist/tests/helpers/db.js.map +1 -1
  134. package/dist/tests/manifest-v2.test.d.ts +2 -0
  135. package/dist/tests/manifest-v2.test.d.ts.map +1 -0
  136. package/dist/tests/manifest-v2.test.js +67 -0
  137. package/dist/tests/manifest-v2.test.js.map +1 -0
  138. package/dist/tests/mcp-server.test.d.ts +2 -0
  139. package/dist/tests/mcp-server.test.d.ts.map +1 -0
  140. package/dist/tests/mcp-server.test.js +118 -0
  141. package/dist/tests/mcp-server.test.js.map +1 -0
  142. package/dist/tests/mcp-tools.test.d.ts +2 -0
  143. package/dist/tests/mcp-tools.test.d.ts.map +1 -0
  144. package/dist/tests/mcp-tools.test.js +243 -0
  145. package/dist/tests/mcp-tools.test.js.map +1 -0
  146. package/dist/tests/migrations-v053.test.js +16 -16
  147. package/dist/tests/migrations-v061.test.js +10 -10
  148. package/dist/tests/migrations-v063.test.js +4 -4
  149. package/dist/tests/migrations-v068.test.js +6 -3
  150. package/dist/tests/migrations-v068.test.js.map +1 -1
  151. package/dist/tests/nomination-counts.test.js +6 -6
  152. package/dist/tests/nomination-counts.test.js.map +1 -1
  153. package/dist/tests/pre-compact.test.js +2 -1
  154. package/dist/tests/pre-compact.test.js.map +1 -1
  155. package/dist/tests/recall-telemetry.test.js +12 -11
  156. package/dist/tests/recall-telemetry.test.js.map +1 -1
  157. package/dist/tests/rrf.test.js +3 -3
  158. package/dist/tests/search-engine.test.js +1 -1
  159. package/dist/tests/search-hook.test.js +2 -2
  160. package/dist/tests/search-offload.test.js +1 -1
  161. package/dist/tests/search-offload.test.js.map +1 -1
  162. package/dist/tests/secure-io.test.d.ts +2 -0
  163. package/dist/tests/secure-io.test.d.ts.map +1 -0
  164. package/dist/tests/secure-io.test.js +65 -0
  165. package/dist/tests/secure-io.test.js.map +1 -0
  166. package/dist/tests/session-payload.test.js +1 -1
  167. package/dist/tests/session-summary.test.js +1 -1
  168. package/dist/tests/similarity.test.js +1 -1
  169. package/dist/tests/skill-path-resolution.test.js +22 -3
  170. package/dist/tests/skill-path-resolution.test.js.map +1 -1
  171. package/dist/tests/smart-snippet.test.d.ts +2 -0
  172. package/dist/tests/smart-snippet.test.d.ts.map +1 -0
  173. package/dist/tests/smart-snippet.test.js +67 -0
  174. package/dist/tests/smart-snippet.test.js.map +1 -0
  175. package/dist/tests/triage.test.js +1 -1
  176. package/hooks/lib/constants.cjs +15 -15
  177. package/hooks/lib/mindlore-common.cjs +975 -974
  178. package/hooks/mindlore-cwd-changed.cjs +57 -57
  179. package/hooks/mindlore-decision-detector.cjs +54 -54
  180. package/hooks/mindlore-dont-repeat.cjs +222 -222
  181. package/hooks/mindlore-fts5-sync.cjs +98 -97
  182. package/hooks/mindlore-index.cjs +230 -229
  183. package/hooks/mindlore-model-router.cjs +54 -54
  184. package/hooks/mindlore-post-compact.cjs +69 -69
  185. package/hooks/mindlore-post-read.cjs +106 -106
  186. package/hooks/mindlore-pre-compact.cjs +154 -154
  187. package/hooks/mindlore-read-guard.cjs +105 -105
  188. package/hooks/mindlore-research-guard.cjs +176 -176
  189. package/hooks/mindlore-search.cjs +200 -200
  190. package/hooks/mindlore-session-end.cjs +510 -509
  191. package/hooks/mindlore-session-focus.cjs +256 -256
  192. package/package.json +77 -75
  193. package/plugin.json +8 -1
  194. package/skills/mindlore-diary/SKILL.md +85 -85
  195. package/skills/mindlore-evolve/SKILL.md +126 -126
  196. package/skills/mindlore-explore/SKILL.md +109 -109
  197. package/skills/mindlore-ingest/SKILL.md +195 -195
  198. package/skills/mindlore-maintain/SKILL.md +125 -125
  199. package/skills/mindlore-query/SKILL.md +151 -151
  200. package/skills/mindlore-reflect/SKILL.md +141 -141
  201. package/skills/mindlore-stats/SKILL.md +106 -106
  202. package/templates/INDEX.md +14 -14
  203. package/templates/SCHEMA.md +292 -292
  204. package/templates/config.json +1 -1
  205. package/templates/extraction/article.md +15 -15
  206. package/templates/extraction/changelog.md +15 -15
  207. package/templates/extraction/default.md +15 -15
  208. package/templates/extraction/docs.md +15 -15
  209. package/templates/extraction/github-repo.md +17 -17
@@ -1,57 +1,57 @@
1
- #!/usr/bin/env node
2
- 'use strict';
3
-
4
- /**
5
- * mindlore-cwd-changed — CwdChanged hook
6
- *
7
- * Fires when user changes working directory.
8
- * CwdChanged has NO inject to Claude — stdout is swallowed, stderr shown to user.
9
- *
10
- * Side effects:
11
- * 1. Detect scope (global ~/.mindlore/ or none)
12
- * 2. Write scope state to .mindlore/diary/_scope.json for session-focus to read
13
- * 3. Show user-facing message via stderr
14
- */
15
-
16
- const fs = require('fs');
17
- const path = require('path');
18
- const { findMindloreDir, globalDir, hookLog, withTelemetry } = require('./lib/mindlore-common.cjs');
19
-
20
- function main() {
21
- const cwd = process.cwd();
22
- const activeDir = findMindloreDir();
23
- const scope = !activeDir ? 'none' : activeDir.startsWith(globalDir()) ? 'global' : 'project';
24
-
25
- if (activeDir) {
26
- const diaryDir = path.join(activeDir, 'diary');
27
- if (!fs.existsSync(diaryDir)) {
28
- fs.mkdirSync(diaryDir, { recursive: true });
29
- }
30
-
31
- // Dirty-check: skip write if scope hasn't changed
32
- const scopePath = path.join(diaryDir, '_scope.json');
33
- if (fs.existsSync(scopePath)) {
34
- try {
35
- const existing = JSON.parse(fs.readFileSync(scopePath, 'utf8'));
36
- if (existing.cwd === cwd && existing.scope === scope) return;
37
- } catch (_err) {
38
- // corrupt file — overwrite
39
- }
40
- }
41
-
42
- fs.writeFileSync(scopePath, JSON.stringify({
43
- scope,
44
- dir: activeDir,
45
- cwd,
46
- timestamp: new Date().toISOString(),
47
- }, null, 2), 'utf8');
48
- }
49
-
50
- if (scope === 'none') {
51
- process.stderr.write(`[Mindlore] Bu projede mindlore kurulu degil. npx mindlore init calistirin.\n`);
52
- } else {
53
- process.stderr.write(`[Mindlore scope: ${scope}] ${activeDir}\n`);
54
- }
55
- }
56
-
57
- withTelemetry('mindlore-cwd-changed', main).catch(err => { hookLog('cwd-changed', 'error', err?.message ?? String(err)); });
1
+ #!/usr/bin/env node
2
+ 'use strict';
3
+
4
+ /**
5
+ * mindlore-cwd-changed — CwdChanged hook
6
+ *
7
+ * Fires when user changes working directory.
8
+ * CwdChanged has NO inject to Claude — stdout is swallowed, stderr shown to user.
9
+ *
10
+ * Side effects:
11
+ * 1. Detect scope (global ~/.mindlore/ or none)
12
+ * 2. Write scope state to .mindlore/diary/_scope.json for session-focus to read
13
+ * 3. Show user-facing message via stderr
14
+ */
15
+
16
+ const fs = require('fs');
17
+ const path = require('path');
18
+ const { findMindloreDir, globalDir, hookLog, withTelemetry } = require('./lib/mindlore-common.cjs');
19
+
20
+ function main() {
21
+ const cwd = process.cwd();
22
+ const activeDir = findMindloreDir();
23
+ const scope = !activeDir ? 'none' : activeDir.startsWith(globalDir()) ? 'global' : 'project';
24
+
25
+ if (activeDir) {
26
+ const diaryDir = path.join(activeDir, 'diary');
27
+ if (!fs.existsSync(diaryDir)) {
28
+ fs.mkdirSync(diaryDir, { recursive: true });
29
+ }
30
+
31
+ // Dirty-check: skip write if scope hasn't changed
32
+ const scopePath = path.join(diaryDir, '_scope.json');
33
+ if (fs.existsSync(scopePath)) {
34
+ try {
35
+ const existing = JSON.parse(fs.readFileSync(scopePath, 'utf8'));
36
+ if (existing.cwd === cwd && existing.scope === scope) return;
37
+ } catch (_err) {
38
+ // corrupt file — overwrite
39
+ }
40
+ }
41
+
42
+ fs.writeFileSync(scopePath, JSON.stringify({
43
+ scope,
44
+ dir: activeDir,
45
+ cwd,
46
+ timestamp: new Date().toISOString(),
47
+ }, null, 2), 'utf8');
48
+ }
49
+
50
+ if (scope === 'none') {
51
+ process.stderr.write(`[Mindlore] Bu projede mindlore kurulu degil. npx mindlore init calistirin.\n`);
52
+ } else {
53
+ process.stderr.write(`[Mindlore scope: ${scope}] ${activeDir}\n`);
54
+ }
55
+ }
56
+
57
+ withTelemetry('mindlore-cwd-changed', main).catch(err => { hookLog('cwd-changed', 'error', err?.message ?? String(err)); });
@@ -1,54 +1,54 @@
1
- #!/usr/bin/env node
2
- 'use strict';
3
-
4
- /**
5
- * mindlore-decision-detector — UserPromptSubmit hook
6
- *
7
- * Detects decision signals in user messages (TR + EN).
8
- * Outputs a suggestion to record the decision via /mindlore-decide.
9
- * Does NOT block (exit 0) — advisory only.
10
- */
11
-
12
- const { findMindloreDir, readHookStdin, hookLog, withTelemetry } = require('./lib/mindlore-common.cjs');
13
-
14
- const SIGNALS_TR = [
15
- 'karar verdik', 'karar verildi', 'kararlastirdik', 'kararlaştırdık',
16
- 'şunu seçtik', 'sunu sectik', 'bunu yapmayalım', 'bunu yapmayalim',
17
- 'yerine', 'tercih ettik', 'onaylandi', 'onaylandı', 'kesinleşti', 'kesinlesti',
18
- 'vazgeçtik', 'vazgectik', 'iptal ettik',
19
- ];
20
-
21
- const SIGNALS_EN = [
22
- 'decided', 'decision made', "let's go with", 'lets go with',
23
- "we'll use", 'well use', 'approved', 'settled on',
24
- 'going with', 'chosen', 'finalized', 'rejected',
25
- ];
26
-
27
- function detectDecision(text) {
28
- const lower = text.toLowerCase();
29
- for (const signal of SIGNALS_TR) {
30
- if (lower.includes(signal)) return signal;
31
- }
32
- for (const signal of SIGNALS_EN) {
33
- if (lower.includes(signal)) return signal;
34
- }
35
- return null;
36
- }
37
-
38
- function main() {
39
- const baseDir = findMindloreDir();
40
- if (!baseDir) return;
41
-
42
- const userText = readHookStdin(['prompt', 'content', 'message']);
43
- if (!userText || userText.length < 10) return;
44
-
45
- const signal = detectDecision(userText);
46
- if (signal) {
47
- process.stdout.write(`[Mindlore: Karar sinyali tespit edildi ("${signal}") — /mindlore-decide record ile kaydetmek ister misin?]\n`);
48
- }
49
- }
50
-
51
- withTelemetry('mindlore-decision-detector', main).catch(err => {
52
- hookLog('mindlore-decision-detector', 'error', err?.message ?? String(err));
53
- process.exit(0);
54
- });
1
+ #!/usr/bin/env node
2
+ 'use strict';
3
+
4
+ /**
5
+ * mindlore-decision-detector — UserPromptSubmit hook
6
+ *
7
+ * Detects decision signals in user messages (TR + EN).
8
+ * Outputs a suggestion to record the decision via /mindlore-decide.
9
+ * Does NOT block (exit 0) — advisory only.
10
+ */
11
+
12
+ const { findMindloreDir, readHookStdin, hookLog, withTelemetry } = require('./lib/mindlore-common.cjs');
13
+
14
+ const SIGNALS_TR = [
15
+ 'karar verdik', 'karar verildi', 'kararlastirdik', 'kararlaştırdık',
16
+ 'şunu seçtik', 'sunu sectik', 'bunu yapmayalım', 'bunu yapmayalim',
17
+ 'yerine', 'tercih ettik', 'onaylandi', 'onaylandı', 'kesinleşti', 'kesinlesti',
18
+ 'vazgeçtik', 'vazgectik', 'iptal ettik',
19
+ ];
20
+
21
+ const SIGNALS_EN = [
22
+ 'decided', 'decision made', "let's go with", 'lets go with',
23
+ "we'll use", 'well use', 'approved', 'settled on',
24
+ 'going with', 'chosen', 'finalized', 'rejected',
25
+ ];
26
+
27
+ function detectDecision(text) {
28
+ const lower = text.toLowerCase();
29
+ for (const signal of SIGNALS_TR) {
30
+ if (lower.includes(signal)) return signal;
31
+ }
32
+ for (const signal of SIGNALS_EN) {
33
+ if (lower.includes(signal)) return signal;
34
+ }
35
+ return null;
36
+ }
37
+
38
+ function main() {
39
+ const baseDir = findMindloreDir();
40
+ if (!baseDir) return;
41
+
42
+ const userText = readHookStdin(['prompt', 'content', 'message']);
43
+ if (!userText || userText.length < 10) return;
44
+
45
+ const signal = detectDecision(userText);
46
+ if (signal) {
47
+ process.stdout.write(`[Mindlore: Karar sinyali tespit edildi ("${signal}") — /mindlore-decide record ile kaydetmek ister misin?]\n`);
48
+ }
49
+ }
50
+
51
+ withTelemetry('mindlore-decision-detector', main).catch(err => {
52
+ hookLog('mindlore-decision-detector', 'error', err?.message ?? String(err));
53
+ process.exit(0);
54
+ });
@@ -1,222 +1,222 @@
1
- #!/usr/bin/env node
2
- 'use strict';
3
-
4
- /**
5
- * mindlore-dont-repeat — PreToolUse hook (matcher: "Write|Edit")
6
- *
7
- * Checks code being written against negative rules (DON'T, NEVER, AVOID, YAPMA, etc.)
8
- * found in LESSONS files and Mindlore learnings/.
9
- *
10
- * Sources checked (in order):
11
- * 1. ~/.claude/lessons/global.md (global rules)
12
- * 2. ./LESSONS.md (project-level rules, if exists)
13
- * 3. .mindlore/learnings/*.md (Mindlore learnings, if exists)
14
- *
15
- * Advisory only (exit 0) — does not block, injects additionalContext warning.
16
- */
17
-
18
- const fs = require('fs');
19
- const path = require('path');
20
- const os = require('os');
21
- const { findMindloreDir, getProjectName, hookLog, withTelemetrySync } = require('./lib/mindlore-common.cjs');
22
-
23
- /**
24
- * File-persisted pattern cache — survives across process invocations.
25
- * Cache file: .mindlore/diary/_pattern-cache.json
26
- * Each entry keyed by source file path, stores mtimeMs + extracted patterns.
27
- * On hit: stat only, no readFile+parse. On miss: read, parse, update cache.
28
- */
29
-
30
- let cacheDirty = false;
31
-
32
- function readCache(cachePath) {
33
- if (!cachePath) return {};
34
- try {
35
- return JSON.parse(fs.readFileSync(cachePath, 'utf8'));
36
- } catch (_err) {
37
- return {};
38
- }
39
- }
40
-
41
- function writeCache(cachePath, cache) {
42
- if (!cachePath || !cacheDirty) return;
43
- try {
44
- fs.writeFileSync(cachePath, JSON.stringify(cache), 'utf8');
45
- } catch (_err) { /* write failure is non-fatal */ }
46
- }
47
-
48
- function loadPatterns(filePath, cache) {
49
- try {
50
- const stat = fs.statSync(filePath);
51
- const mtimeMs = stat.mtimeMs;
52
- const cached = cache[filePath];
53
- if (cached && cached.mtimeMs === mtimeMs) return cached.patterns;
54
-
55
- const patterns = extractNegativePatterns(fs.readFileSync(filePath, 'utf8'));
56
- cache[filePath] = { mtimeMs, patterns };
57
- cacheDirty = true;
58
- return patterns;
59
- } catch (_err) {
60
- return [];
61
- }
62
- }
63
-
64
- function extractNegativePatterns(content) {
65
- const patterns = [];
66
- const lines = content.split('\n');
67
-
68
- for (const line of lines) {
69
- const trimmed = line.trim();
70
- // Multi-language: TR (YAPMA, KRITIK) + EN (DON'T, NEVER, AVOID, DO NOT)
71
- const isNegativeRule = /^-\s*(YAPMA|KRITIK|DON'?T|NEVER|AVOID|DO NOT):/i.test(trimmed);
72
- if (!isNegativeRule) continue;
73
-
74
- // Extract backtick-quoted code patterns: `pattern`
75
- const backtickMatches = trimmed.match(/`([^`]+)`/g);
76
- if (backtickMatches) {
77
- for (const match of backtickMatches) {
78
- const pattern = match.slice(1, -1).trim();
79
- // Skip short/generic patterns — too many false positives
80
- if (pattern.length < 8) continue;
81
- if (/^[^a-zA-Z0-9]+$/.test(pattern)) continue;
82
- // Skip single words (too generic: "node", "bash", "any")
83
- if (/^\w+$/.test(pattern) && pattern.length < 12) continue;
84
- // Skip file extensions and paths
85
- if (/^\.\w{1,5}$/.test(pattern)) continue;
86
- if (pattern.startsWith('/') || pattern.startsWith('~')) continue;
87
- if (pattern.includes('.md') || pattern.includes('.json')) continue;
88
- // Skip common false-positive patterns
89
- if (/^(node|bash|npm|git|process|require|import|export|const|let|var)$/i.test(pattern)) continue;
90
-
91
- patterns.push({
92
- pattern,
93
- rule: trimmed.substring(0, 120),
94
- });
95
- }
96
- }
97
-
98
- // Extract "quoted strings" as patterns
99
- const quoteMatches = trimmed.match(/"([^"]+)"/g);
100
- if (quoteMatches) {
101
- for (const match of quoteMatches) {
102
- const quoted = match.slice(1, -1).trim();
103
- if (quoted.length < 4) continue;
104
- patterns.push({
105
- pattern: quoted,
106
- rule: trimmed.substring(0, 120),
107
- });
108
- }
109
- }
110
- }
111
-
112
- return patterns;
113
- }
114
-
115
- function checkContent(content, patterns) {
116
- const matches = [];
117
- for (const p of patterns) {
118
- try {
119
- const escaped = p.pattern.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
120
- const regex = new RegExp(escaped, 'i');
121
- if (regex.test(content)) {
122
- matches.push(p);
123
- }
124
- } catch { /* skip invalid patterns */ }
125
- }
126
- return matches;
127
- }
128
-
129
- function main() {
130
- let input = '';
131
- const stdinTimeout = setTimeout(() => process.exit(0), 3000);
132
- process.stdin.setEncoding('utf8');
133
- process.stdin.on('error', () => process.exit(0));
134
- process.stdin.on('data', chunk => input += chunk);
135
- process.stdin.on('end', () => {
136
- clearTimeout(stdinTimeout);
137
- try {
138
- const data = JSON.parse(input || '{}');
139
- const toolName = data.tool_name || '';
140
-
141
- if (!['Write', 'Edit'].includes(toolName)) {
142
- return process.exit(0);
143
- }
144
-
145
- const toolInput = data.tool_input || {};
146
- const filePath = toolInput.file_path || '';
147
-
148
- // Skip non-code files
149
- if (!filePath) return process.exit(0);
150
- const ext = path.extname(filePath).toLowerCase();
151
- const codeExts = ['.ts', '.tsx', '.js', '.jsx', '.cjs', '.mjs', '.py', '.go', '.rs', '.java', '.c', '.cpp', '.h', '.sh', '.yaml', '.yml'];
152
- if (!codeExts.includes(ext)) return process.exit(0);
153
-
154
- // Skip rule files themselves
155
- const basename = path.basename(filePath);
156
- if (basename === 'LESSONS.md' || basename === 'global.md' || basename === 'CLAUDE.md') {
157
- return process.exit(0);
158
- }
159
-
160
- // Collect content being written (skip old_string — that's code being removed, not added)
161
- const allContent = [
162
- toolInput.content || '',
163
- toolInput.new_string || '',
164
- ].join('\n');
165
-
166
- if (allContent.trim().length < 10) return process.exit(0);
167
-
168
- // Load patterns from all sources (file-persisted mtime cache)
169
- const mindloreDir = findMindloreDir();
170
- const cachePath = mindloreDir ? path.join(mindloreDir, 'diary', `_pattern-cache-${getProjectName()}.json`) : null;
171
- const cache = readCache(cachePath);
172
- const allPatterns = [];
173
- const cwd = process.cwd();
174
-
175
- // 1. Global lessons
176
- allPatterns.push(...loadPatterns(path.join(os.homedir(), '.claude', 'lessons', 'global.md'), cache));
177
-
178
- // 2. Project LESSONS.md
179
- allPatterns.push(...loadPatterns(path.join(cwd, 'LESSONS.md'), cache));
180
-
181
- // 3. Mindlore learnings/ directory
182
- if (mindloreDir) {
183
- const learningsDir = path.join(mindloreDir, 'learnings');
184
- try {
185
- const files = fs.readdirSync(learningsDir).filter(f => f.endsWith('.md'));
186
- for (const file of files) {
187
- allPatterns.push(...loadPatterns(path.join(learningsDir, file), cache));
188
- }
189
- } catch (_err) { /* learnings/ doesn't exist yet */ }
190
- }
191
-
192
- writeCache(cachePath, cache);
193
-
194
- if (allPatterns.length === 0) return process.exit(0);
195
-
196
- // Check content against patterns
197
- const matches = checkContent(allContent, allPatterns);
198
- if (matches.length === 0) return process.exit(0);
199
-
200
- // Build warning — max 3 matches shown
201
- const shown = matches.slice(0, 3);
202
- const warning = shown.map(m =>
203
- ` - Pattern: \`${m.pattern}\` → ${m.rule}`
204
- ).join('\n');
205
- const extra = matches.length > 3 ? `\n ... and ${matches.length - 3} more` : '';
206
-
207
- const msg = `[Mindlore: ${matches.length} dont-repeat rule violation detected]\n${warning}${extra}`;
208
-
209
- process.stdout.write(JSON.stringify({
210
- hookSpecificOutput: {
211
- hookEventName: 'PreToolUse',
212
- additionalContext: msg
213
- }
214
- }));
215
- } catch {
216
- // Silent fail
217
- }
218
- process.exit(0);
219
- });
220
- }
221
-
222
- try { withTelemetrySync('mindlore-dont-repeat', main); } catch (err) { hookLog('dont-repeat', 'error', err?.message ?? String(err)); }
1
+ #!/usr/bin/env node
2
+ 'use strict';
3
+
4
+ /**
5
+ * mindlore-dont-repeat — PreToolUse hook (matcher: "Write|Edit")
6
+ *
7
+ * Checks code being written against negative rules (DON'T, NEVER, AVOID, YAPMA, etc.)
8
+ * found in LESSONS files and Mindlore learnings/.
9
+ *
10
+ * Sources checked (in order):
11
+ * 1. ~/.claude/lessons/global.md (global rules)
12
+ * 2. ./LESSONS.md (project-level rules, if exists)
13
+ * 3. .mindlore/learnings/*.md (Mindlore learnings, if exists)
14
+ *
15
+ * Advisory only (exit 0) — does not block, injects additionalContext warning.
16
+ */
17
+
18
+ const fs = require('fs');
19
+ const path = require('path');
20
+ const os = require('os');
21
+ const { findMindloreDir, getProjectName, hookLog, withTelemetrySync } = require('./lib/mindlore-common.cjs');
22
+
23
+ /**
24
+ * File-persisted pattern cache — survives across process invocations.
25
+ * Cache file: .mindlore/diary/_pattern-cache.json
26
+ * Each entry keyed by source file path, stores mtimeMs + extracted patterns.
27
+ * On hit: stat only, no readFile+parse. On miss: read, parse, update cache.
28
+ */
29
+
30
+ let cacheDirty = false;
31
+
32
+ function readCache(cachePath) {
33
+ if (!cachePath) return {};
34
+ try {
35
+ return JSON.parse(fs.readFileSync(cachePath, 'utf8'));
36
+ } catch (_err) {
37
+ return {};
38
+ }
39
+ }
40
+
41
+ function writeCache(cachePath, cache) {
42
+ if (!cachePath || !cacheDirty) return;
43
+ try {
44
+ fs.writeFileSync(cachePath, JSON.stringify(cache), 'utf8');
45
+ } catch (_err) { /* write failure is non-fatal */ }
46
+ }
47
+
48
+ function loadPatterns(filePath, cache) {
49
+ try {
50
+ const stat = fs.statSync(filePath);
51
+ const mtimeMs = stat.mtimeMs;
52
+ const cached = cache[filePath];
53
+ if (cached && cached.mtimeMs === mtimeMs) return cached.patterns;
54
+
55
+ const patterns = extractNegativePatterns(fs.readFileSync(filePath, 'utf8'));
56
+ cache[filePath] = { mtimeMs, patterns };
57
+ cacheDirty = true;
58
+ return patterns;
59
+ } catch (_err) {
60
+ return [];
61
+ }
62
+ }
63
+
64
+ function extractNegativePatterns(content) {
65
+ const patterns = [];
66
+ const lines = content.split('\n');
67
+
68
+ for (const line of lines) {
69
+ const trimmed = line.trim();
70
+ // Multi-language: TR (YAPMA, KRITIK) + EN (DON'T, NEVER, AVOID, DO NOT)
71
+ const isNegativeRule = /^-\s*(YAPMA|KRITIK|DON'?T|NEVER|AVOID|DO NOT):/i.test(trimmed);
72
+ if (!isNegativeRule) continue;
73
+
74
+ // Extract backtick-quoted code patterns: `pattern`
75
+ const backtickMatches = trimmed.match(/`([^`]+)`/g);
76
+ if (backtickMatches) {
77
+ for (const match of backtickMatches) {
78
+ const pattern = match.slice(1, -1).trim();
79
+ // Skip short/generic patterns — too many false positives
80
+ if (pattern.length < 8) continue;
81
+ if (/^[^a-zA-Z0-9]+$/.test(pattern)) continue;
82
+ // Skip single words (too generic: "node", "bash", "any")
83
+ if (/^\w+$/.test(pattern) && pattern.length < 12) continue;
84
+ // Skip file extensions and paths
85
+ if (/^\.\w{1,5}$/.test(pattern)) continue;
86
+ if (pattern.startsWith('/') || pattern.startsWith('~')) continue;
87
+ if (pattern.includes('.md') || pattern.includes('.json')) continue;
88
+ // Skip common false-positive patterns
89
+ if (/^(node|bash|npm|git|process|require|import|export|const|let|var)$/i.test(pattern)) continue;
90
+
91
+ patterns.push({
92
+ pattern,
93
+ rule: trimmed.substring(0, 120),
94
+ });
95
+ }
96
+ }
97
+
98
+ // Extract "quoted strings" as patterns
99
+ const quoteMatches = trimmed.match(/"([^"]+)"/g);
100
+ if (quoteMatches) {
101
+ for (const match of quoteMatches) {
102
+ const quoted = match.slice(1, -1).trim();
103
+ if (quoted.length < 4) continue;
104
+ patterns.push({
105
+ pattern: quoted,
106
+ rule: trimmed.substring(0, 120),
107
+ });
108
+ }
109
+ }
110
+ }
111
+
112
+ return patterns;
113
+ }
114
+
115
+ function checkContent(content, patterns) {
116
+ const matches = [];
117
+ for (const p of patterns) {
118
+ try {
119
+ const escaped = p.pattern.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
120
+ const regex = new RegExp(escaped, 'i');
121
+ if (regex.test(content)) {
122
+ matches.push(p);
123
+ }
124
+ } catch { /* skip invalid patterns */ }
125
+ }
126
+ return matches;
127
+ }
128
+
129
+ function main() {
130
+ let input = '';
131
+ const stdinTimeout = setTimeout(() => process.exit(0), 3000);
132
+ process.stdin.setEncoding('utf8');
133
+ process.stdin.on('error', () => process.exit(0));
134
+ process.stdin.on('data', chunk => input += chunk);
135
+ process.stdin.on('end', () => {
136
+ clearTimeout(stdinTimeout);
137
+ try {
138
+ const data = JSON.parse(input || '{}');
139
+ const toolName = data.tool_name || '';
140
+
141
+ if (!['Write', 'Edit'].includes(toolName)) {
142
+ return process.exit(0);
143
+ }
144
+
145
+ const toolInput = data.tool_input || {};
146
+ const filePath = toolInput.file_path || '';
147
+
148
+ // Skip non-code files
149
+ if (!filePath) return process.exit(0);
150
+ const ext = path.extname(filePath).toLowerCase();
151
+ const codeExts = ['.ts', '.tsx', '.js', '.jsx', '.cjs', '.mjs', '.py', '.go', '.rs', '.java', '.c', '.cpp', '.h', '.sh', '.yaml', '.yml'];
152
+ if (!codeExts.includes(ext)) return process.exit(0);
153
+
154
+ // Skip rule files themselves
155
+ const basename = path.basename(filePath);
156
+ if (basename === 'LESSONS.md' || basename === 'global.md' || basename === 'CLAUDE.md') {
157
+ return process.exit(0);
158
+ }
159
+
160
+ // Collect content being written (skip old_string — that's code being removed, not added)
161
+ const allContent = [
162
+ toolInput.content || '',
163
+ toolInput.new_string || '',
164
+ ].join('\n');
165
+
166
+ if (allContent.trim().length < 10) return process.exit(0);
167
+
168
+ // Load patterns from all sources (file-persisted mtime cache)
169
+ const mindloreDir = findMindloreDir();
170
+ const cachePath = mindloreDir ? path.join(mindloreDir, 'diary', `_pattern-cache-${getProjectName()}.json`) : null;
171
+ const cache = readCache(cachePath);
172
+ const allPatterns = [];
173
+ const cwd = process.cwd();
174
+
175
+ // 1. Global lessons
176
+ allPatterns.push(...loadPatterns(path.join(os.homedir(), '.claude', 'lessons', 'global.md'), cache));
177
+
178
+ // 2. Project LESSONS.md
179
+ allPatterns.push(...loadPatterns(path.join(cwd, 'LESSONS.md'), cache));
180
+
181
+ // 3. Mindlore learnings/ directory
182
+ if (mindloreDir) {
183
+ const learningsDir = path.join(mindloreDir, 'learnings');
184
+ try {
185
+ const files = fs.readdirSync(learningsDir).filter(f => f.endsWith('.md'));
186
+ for (const file of files) {
187
+ allPatterns.push(...loadPatterns(path.join(learningsDir, file), cache));
188
+ }
189
+ } catch (_err) { /* learnings/ doesn't exist yet */ }
190
+ }
191
+
192
+ writeCache(cachePath, cache);
193
+
194
+ if (allPatterns.length === 0) return process.exit(0);
195
+
196
+ // Check content against patterns
197
+ const matches = checkContent(allContent, allPatterns);
198
+ if (matches.length === 0) return process.exit(0);
199
+
200
+ // Build warning — max 3 matches shown
201
+ const shown = matches.slice(0, 3);
202
+ const warning = shown.map(m =>
203
+ ` - Pattern: \`${m.pattern}\` → ${m.rule}`
204
+ ).join('\n');
205
+ const extra = matches.length > 3 ? `\n ... and ${matches.length - 3} more` : '';
206
+
207
+ const msg = `[Mindlore: ${matches.length} dont-repeat rule violation detected]\n${warning}${extra}`;
208
+
209
+ process.stdout.write(JSON.stringify({
210
+ hookSpecificOutput: {
211
+ hookEventName: 'PreToolUse',
212
+ additionalContext: msg
213
+ }
214
+ }));
215
+ } catch {
216
+ // Silent fail
217
+ }
218
+ process.exit(0);
219
+ });
220
+ }
221
+
222
+ try { withTelemetrySync('mindlore-dont-repeat', main); } catch (err) { hookLog('dont-repeat', 'error', err?.message ?? String(err)); }