mindlore 0.7.0 → 0.7.2

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 (120) hide show
  1. package/README.md +30 -3
  2. package/dist/scripts/bundle-hooks.d.ts +2 -0
  3. package/dist/scripts/bundle-hooks.d.ts.map +1 -0
  4. package/dist/scripts/bundle-hooks.js +70 -0
  5. package/dist/scripts/bundle-hooks.js.map +1 -0
  6. package/dist/scripts/init.js +0 -3
  7. package/dist/scripts/init.js.map +1 -1
  8. package/dist/scripts/lib/all-migrations.d.ts.map +1 -1
  9. package/dist/scripts/lib/all-migrations.js +3 -0
  10. package/dist/scripts/lib/all-migrations.js.map +1 -1
  11. package/dist/scripts/lib/constants.d.ts +7 -2
  12. package/dist/scripts/lib/constants.d.ts.map +1 -1
  13. package/dist/scripts/lib/constants.js +17 -22
  14. package/dist/scripts/lib/constants.js.map +1 -1
  15. package/dist/scripts/lib/mcp-tools.d.ts.map +1 -1
  16. package/dist/scripts/lib/mcp-tools.js +63 -78
  17. package/dist/scripts/lib/mcp-tools.js.map +1 -1
  18. package/dist/scripts/lib/migrations-v072.d.ts +3 -0
  19. package/dist/scripts/lib/migrations-v072.d.ts.map +1 -0
  20. package/dist/scripts/lib/migrations-v072.js +25 -0
  21. package/dist/scripts/lib/migrations-v072.js.map +1 -0
  22. package/dist/scripts/lib/relation-helpers.d.ts +15 -0
  23. package/dist/scripts/lib/relation-helpers.d.ts.map +1 -0
  24. package/dist/scripts/lib/relation-helpers.js +30 -0
  25. package/dist/scripts/lib/relation-helpers.js.map +1 -0
  26. package/dist/scripts/lib/tool-adapters/get-adapter.d.ts +21 -0
  27. package/dist/scripts/lib/tool-adapters/get-adapter.d.ts.map +1 -0
  28. package/dist/scripts/lib/tool-adapters/get-adapter.js +51 -0
  29. package/dist/scripts/lib/tool-adapters/get-adapter.js.map +1 -0
  30. package/dist/scripts/lib/tool-adapters/relate-adapter.d.ts +34 -0
  31. package/dist/scripts/lib/tool-adapters/relate-adapter.d.ts.map +1 -0
  32. package/dist/scripts/lib/tool-adapters/relate-adapter.js +43 -0
  33. package/dist/scripts/lib/tool-adapters/relate-adapter.js.map +1 -0
  34. package/dist/scripts/lib/tool-adapters/search-adapter.d.ts +5 -0
  35. package/dist/scripts/lib/tool-adapters/search-adapter.d.ts.map +1 -1
  36. package/dist/scripts/lib/tool-adapters/search-adapter.js +37 -0
  37. package/dist/scripts/lib/tool-adapters/search-adapter.js.map +1 -1
  38. package/dist/scripts/mcp-server.js +1 -1
  39. package/dist/scripts/mcp-server.js.map +1 -1
  40. package/dist/tests/dont-repeat-dedup.test.d.ts +2 -0
  41. package/dist/tests/dont-repeat-dedup.test.d.ts.map +1 -0
  42. package/dist/tests/dont-repeat-dedup.test.js +93 -0
  43. package/dist/tests/dont-repeat-dedup.test.js.map +1 -0
  44. package/dist/tests/e2e-kg-pipeline.test.d.ts +2 -0
  45. package/dist/tests/e2e-kg-pipeline.test.d.ts.map +1 -0
  46. package/dist/tests/e2e-kg-pipeline.test.js +59 -0
  47. package/dist/tests/e2e-kg-pipeline.test.js.map +1 -0
  48. package/dist/tests/helpers/db.d.ts.map +1 -1
  49. package/dist/tests/helpers/db.js +2 -1
  50. package/dist/tests/helpers/db.js.map +1 -1
  51. package/dist/tests/hook-smoke.test.js +1 -1
  52. package/dist/tests/hook-smoke.test.js.map +1 -1
  53. package/dist/tests/mcp-get-tool.test.d.ts +2 -0
  54. package/dist/tests/mcp-get-tool.test.d.ts.map +1 -0
  55. package/dist/tests/mcp-get-tool.test.js +93 -0
  56. package/dist/tests/mcp-get-tool.test.js.map +1 -0
  57. package/dist/tests/mcp-relate-tool.test.d.ts +2 -0
  58. package/dist/tests/mcp-relate-tool.test.d.ts.map +1 -0
  59. package/dist/tests/mcp-relate-tool.test.js +85 -0
  60. package/dist/tests/mcp-relate-tool.test.js.map +1 -0
  61. package/dist/tests/mcp-server.test.js +3 -1
  62. package/dist/tests/mcp-server.test.js.map +1 -1
  63. package/dist/tests/mcp-tools.test.js +20 -0
  64. package/dist/tests/mcp-tools.test.js.map +1 -1
  65. package/dist/tests/memory-relate.test.d.ts +2 -0
  66. package/dist/tests/memory-relate.test.d.ts.map +1 -0
  67. package/dist/tests/memory-relate.test.js +70 -0
  68. package/dist/tests/memory-relate.test.js.map +1 -0
  69. package/dist/tests/migrations-v063.test.js +1 -1
  70. package/dist/tests/migrations-v072.test.d.ts +2 -0
  71. package/dist/tests/migrations-v072.test.d.ts.map +1 -0
  72. package/dist/tests/migrations-v072.test.js +74 -0
  73. package/dist/tests/migrations-v072.test.js.map +1 -0
  74. package/dist/tests/plugin-cache-regression.test.d.ts +2 -0
  75. package/dist/tests/plugin-cache-regression.test.d.ts.map +1 -0
  76. package/dist/tests/plugin-cache-regression.test.js +19 -0
  77. package/dist/tests/plugin-cache-regression.test.js.map +1 -0
  78. package/dist/tests/search-hook.test.js +1 -1
  79. package/dist/tests/search-hook.test.js.map +1 -1
  80. package/hooks/cc-memory-bulk-sync.cjs +606 -0
  81. package/hooks/cc-session-sync.cjs +856 -0
  82. package/hooks/hooks.json +149 -0
  83. package/hooks/lib/mindlore-common.cjs +2 -2
  84. package/hooks/lib/secure-io.cjs +17 -0
  85. package/hooks/mindlore-cwd-changed.cjs +19 -34
  86. package/hooks/mindlore-decision-detector.cjs +40 -31
  87. package/hooks/mindlore-dont-repeat.cjs +75 -115
  88. package/hooks/mindlore-fts5-sync.cjs +15 -44
  89. package/hooks/mindlore-index.cjs +100 -101
  90. package/hooks/mindlore-model-router.cjs +20 -32
  91. package/hooks/mindlore-post-compact.cjs +26 -42
  92. package/hooks/mindlore-post-read.cjs +35 -60
  93. package/hooks/mindlore-pre-compact.cjs +55 -73
  94. package/hooks/mindlore-read-guard.cjs +28 -51
  95. package/hooks/mindlore-research-guard.cjs +63 -101
  96. package/hooks/mindlore-search.cjs +1156 -93
  97. package/hooks/mindlore-session-end.cjs +155 -276
  98. package/hooks/mindlore-session-focus.cjs +672 -110
  99. package/hooks/src/lib/constants.cjs +15 -0
  100. package/hooks/src/lib/mindlore-common.cjs +975 -0
  101. package/hooks/src/lib/mindlore-common.d.cts +72 -0
  102. package/hooks/src/lib/secure-io.cjs +17 -0
  103. package/hooks/src/lib/types.d.ts +58 -0
  104. package/hooks/src/mindlore-cwd-changed.cjs +57 -0
  105. package/hooks/src/mindlore-decision-detector.cjs +54 -0
  106. package/hooks/src/mindlore-dont-repeat.cjs +243 -0
  107. package/hooks/src/mindlore-fts5-sync.cjs +98 -0
  108. package/hooks/src/mindlore-index.cjs +230 -0
  109. package/hooks/src/mindlore-model-router.cjs +54 -0
  110. package/hooks/src/mindlore-post-compact.cjs +69 -0
  111. package/hooks/src/mindlore-post-read.cjs +106 -0
  112. package/hooks/src/mindlore-pre-compact.cjs +154 -0
  113. package/hooks/src/mindlore-read-guard.cjs +105 -0
  114. package/hooks/src/mindlore-research-guard.cjs +176 -0
  115. package/hooks/src/mindlore-search.cjs +200 -0
  116. package/hooks/src/mindlore-session-end.cjs +511 -0
  117. package/hooks/src/mindlore-session-focus.cjs +256 -0
  118. package/package.json +8 -3
  119. package/plugin.json +5 -4
  120. package/templates/config.json +1 -1
@@ -0,0 +1,149 @@
1
+ {
2
+ "description": "Mindlore lifecycle hooks — session context injection, FTS5 search, decision detection, file sync, compaction handling, read/write guards, model routing",
3
+ "hooks": {
4
+ "SessionStart": [
5
+ {
6
+ "matcher": "",
7
+ "hooks": [
8
+ {
9
+ "type": "command",
10
+ "command": "node \"${CLAUDE_PLUGIN_ROOT}/hooks/mindlore-session-focus.cjs\""
11
+ }
12
+ ]
13
+ }
14
+ ],
15
+ "UserPromptSubmit": [
16
+ {
17
+ "matcher": "",
18
+ "hooks": [
19
+ {
20
+ "type": "command",
21
+ "command": "node \"${CLAUDE_PLUGIN_ROOT}/hooks/mindlore-search.cjs\""
22
+ }
23
+ ]
24
+ },
25
+ {
26
+ "matcher": "",
27
+ "hooks": [
28
+ {
29
+ "type": "command",
30
+ "command": "node \"${CLAUDE_PLUGIN_ROOT}/hooks/mindlore-decision-detector.cjs\""
31
+ }
32
+ ]
33
+ }
34
+ ],
35
+ "FileChanged": [
36
+ {
37
+ "matcher": "",
38
+ "hooks": [
39
+ {
40
+ "type": "command",
41
+ "command": "node \"${CLAUDE_PLUGIN_ROOT}/hooks/mindlore-index.cjs\""
42
+ }
43
+ ]
44
+ },
45
+ {
46
+ "matcher": "",
47
+ "hooks": [
48
+ {
49
+ "type": "command",
50
+ "command": "node \"${CLAUDE_PLUGIN_ROOT}/hooks/mindlore-fts5-sync.cjs\""
51
+ }
52
+ ]
53
+ }
54
+ ],
55
+ "SessionEnd": [
56
+ {
57
+ "matcher": "",
58
+ "hooks": [
59
+ {
60
+ "type": "command",
61
+ "command": "node \"${CLAUDE_PLUGIN_ROOT}/hooks/mindlore-session-end.cjs\""
62
+ }
63
+ ]
64
+ }
65
+ ],
66
+ "PreCompact": [
67
+ {
68
+ "matcher": "",
69
+ "hooks": [
70
+ {
71
+ "type": "command",
72
+ "command": "node \"${CLAUDE_PLUGIN_ROOT}/hooks/mindlore-pre-compact.cjs\""
73
+ }
74
+ ]
75
+ }
76
+ ],
77
+ "PostCompact": [
78
+ {
79
+ "matcher": "",
80
+ "hooks": [
81
+ {
82
+ "type": "command",
83
+ "command": "node \"${CLAUDE_PLUGIN_ROOT}/hooks/mindlore-post-compact.cjs\""
84
+ }
85
+ ]
86
+ }
87
+ ],
88
+ "PreToolUse": [
89
+ {
90
+ "matcher": "Read",
91
+ "hooks": [
92
+ {
93
+ "type": "command",
94
+ "command": "node \"${CLAUDE_PLUGIN_ROOT}/hooks/mindlore-read-guard.cjs\""
95
+ }
96
+ ]
97
+ },
98
+ {
99
+ "matcher": "Write|Edit",
100
+ "hooks": [
101
+ {
102
+ "type": "command",
103
+ "command": "node \"${CLAUDE_PLUGIN_ROOT}/hooks/mindlore-dont-repeat.cjs\""
104
+ }
105
+ ]
106
+ },
107
+ {
108
+ "matcher": "Agent",
109
+ "hooks": [
110
+ {
111
+ "type": "command",
112
+ "command": "node \"${CLAUDE_PLUGIN_ROOT}/hooks/mindlore-model-router.cjs\""
113
+ }
114
+ ]
115
+ },
116
+ {
117
+ "matcher": "Agent",
118
+ "hooks": [
119
+ {
120
+ "type": "command",
121
+ "command": "node \"${CLAUDE_PLUGIN_ROOT}/hooks/mindlore-research-guard.cjs\""
122
+ }
123
+ ]
124
+ }
125
+ ],
126
+ "PostToolUse": [
127
+ {
128
+ "matcher": "Read",
129
+ "hooks": [
130
+ {
131
+ "type": "command",
132
+ "command": "node \"${CLAUDE_PLUGIN_ROOT}/hooks/mindlore-post-read.cjs\""
133
+ }
134
+ ]
135
+ }
136
+ ],
137
+ "CwdChanged": [
138
+ {
139
+ "matcher": "",
140
+ "hooks": [
141
+ {
142
+ "type": "command",
143
+ "command": "node \"${CLAUDE_PLUGIN_ROOT}/hooks/mindlore-cwd-changed.cjs\""
144
+ }
145
+ ]
146
+ }
147
+ ]
148
+ }
149
+ }
@@ -10,7 +10,7 @@ const path = require('path');
10
10
  const crypto = require('crypto');
11
11
  const os = require('os');
12
12
  const { EPISODE_KINDS, isValidKind, DB_BUSY_TIMEOUT_MS } = require('./constants.cjs');
13
- const { safeMkdir, safeWriteFile } = require('../../dist/scripts/lib/secure-io.js');
13
+ const { safeMkdir, safeWriteFile } = require('./secure-io.cjs');
14
14
 
15
15
  const MINDLORE_DIR = '.mindlore';
16
16
  const DB_NAME = 'mindlore.db';
@@ -644,7 +644,7 @@ function resolveWin32Bin(name) {
644
644
  if (process.platform === 'win32') {
645
645
  try {
646
646
  return require('child_process')
647
- .execSync(`where ${name}`, { encoding: 'utf8', timeout: 3000, windowsHide: true })
647
+ .execFileSync('where', [name], { encoding: 'utf8', timeout: 3000, windowsHide: true })
648
648
  .trim().split('\n')[0].trim();
649
649
  } catch (_e) { /* fall through */ }
650
650
  }
@@ -0,0 +1,17 @@
1
+ 'use strict';
2
+
3
+ const fs = require('fs');
4
+
5
+ function safeMkdir(dirPath) {
6
+ fs.mkdirSync(dirPath, { recursive: true, mode: 0o700 });
7
+ }
8
+
9
+ function safeWriteFile(filePath, data) {
10
+ fs.writeFileSync(filePath, data, { encoding: 'utf8', mode: 0o600 });
11
+ }
12
+
13
+ function safeWriteJson(filePath, obj) {
14
+ safeWriteFile(filePath, JSON.stringify(obj, null, 2) + '\n');
15
+ }
16
+
17
+ module.exports = { safeMkdir, safeWriteFile, safeWriteJson };
@@ -1,57 +1,42 @@
1
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');
2
+ "use strict";
19
3
 
4
+ // hooks/src/mindlore-cwd-changed.cjs
5
+ var fs = require("fs");
6
+ var path = require("path");
7
+ var { findMindloreDir, globalDir, hookLog, withTelemetry } = require("./lib/mindlore-common.cjs");
20
8
  function main() {
21
9
  const cwd = process.cwd();
22
10
  const activeDir = findMindloreDir();
23
- const scope = !activeDir ? 'none' : activeDir.startsWith(globalDir()) ? 'global' : 'project';
24
-
11
+ const scope = !activeDir ? "none" : activeDir.startsWith(globalDir()) ? "global" : "project";
25
12
  if (activeDir) {
26
- const diaryDir = path.join(activeDir, 'diary');
13
+ const diaryDir = path.join(activeDir, "diary");
27
14
  if (!fs.existsSync(diaryDir)) {
28
15
  fs.mkdirSync(diaryDir, { recursive: true });
29
16
  }
30
-
31
- // Dirty-check: skip write if scope hasn't changed
32
- const scopePath = path.join(diaryDir, '_scope.json');
17
+ const scopePath = path.join(diaryDir, "_scope.json");
33
18
  if (fs.existsSync(scopePath)) {
34
19
  try {
35
- const existing = JSON.parse(fs.readFileSync(scopePath, 'utf8'));
20
+ const existing = JSON.parse(fs.readFileSync(scopePath, "utf8"));
36
21
  if (existing.cwd === cwd && existing.scope === scope) return;
37
22
  } catch (_err) {
38
- // corrupt file — overwrite
39
23
  }
40
24
  }
41
-
42
25
  fs.writeFileSync(scopePath, JSON.stringify({
43
26
  scope,
44
27
  dir: activeDir,
45
28
  cwd,
46
- timestamp: new Date().toISOString(),
47
- }, null, 2), 'utf8');
29
+ timestamp: (/* @__PURE__ */ new Date()).toISOString()
30
+ }, null, 2), "utf8");
48
31
  }
49
-
50
- if (scope === 'none') {
51
- process.stderr.write(`[Mindlore] Bu projede mindlore kurulu degil. npx mindlore init calistirin.\n`);
32
+ if (scope === "none") {
33
+ process.stderr.write(`[Mindlore] Bu projede mindlore kurulu degil. npx mindlore init calistirin.
34
+ `);
52
35
  } else {
53
- process.stderr.write(`[Mindlore scope: ${scope}] ${activeDir}\n`);
36
+ process.stderr.write(`[Mindlore scope: ${scope}] ${activeDir}
37
+ `);
54
38
  }
55
39
  }
56
-
57
- withTelemetry('mindlore-cwd-changed', main).catch(err => { hookLog('cwd-changed', 'error', err?.message ?? String(err)); });
40
+ withTelemetry("mindlore-cwd-changed", main).catch((err) => {
41
+ hookLog("cwd-changed", "error", err?.message ?? String(err));
42
+ });
@@ -1,29 +1,41 @@
1
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',
2
+ "use strict";
3
+
4
+ // hooks/src/mindlore-decision-detector.cjs
5
+ var { findMindloreDir, readHookStdin, hookLog, withTelemetry } = require("./lib/mindlore-common.cjs");
6
+ var SIGNALS_TR = [
7
+ "karar verdik",
8
+ "karar verildi",
9
+ "kararlastirdik",
10
+ "kararla\u015Ft\u0131rd\u0131k",
11
+ "\u015Funu se\xE7tik",
12
+ "sunu sectik",
13
+ "bunu yapmayal\u0131m",
14
+ "bunu yapmayalim",
15
+ "yerine",
16
+ "tercih ettik",
17
+ "onaylandi",
18
+ "onayland\u0131",
19
+ "kesinle\u015Fti",
20
+ "kesinlesti",
21
+ "vazge\xE7tik",
22
+ "vazgectik",
23
+ "iptal ettik"
19
24
  ];
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
+ var SIGNALS_EN = [
26
+ "decided",
27
+ "decision made",
28
+ "let's go with",
29
+ "lets go with",
30
+ "we'll use",
31
+ "well use",
32
+ "approved",
33
+ "settled on",
34
+ "going with",
35
+ "chosen",
36
+ "finalized",
37
+ "rejected"
25
38
  ];
26
-
27
39
  function detectDecision(text) {
28
40
  const lower = text.toLowerCase();
29
41
  for (const signal of SIGNALS_TR) {
@@ -34,21 +46,18 @@ function detectDecision(text) {
34
46
  }
35
47
  return null;
36
48
  }
37
-
38
49
  function main() {
39
50
  const baseDir = findMindloreDir();
40
51
  if (!baseDir) return;
41
-
42
- const userText = readHookStdin(['prompt', 'content', 'message']);
52
+ const userText = readHookStdin(["prompt", "content", "message"]);
43
53
  if (!userText || userText.length < 10) return;
44
-
45
54
  const signal = detectDecision(userText);
46
55
  if (signal) {
47
- process.stdout.write(`[Mindlore: Karar sinyali tespit edildi ("${signal}") /mindlore-decide record ile kaydetmek ister misin?]\n`);
56
+ process.stdout.write(`[Mindlore: Karar sinyali tespit edildi ("${signal}") \u2014 /mindlore-decide record ile kaydetmek ister misin?]
57
+ `);
48
58
  }
49
59
  }
50
-
51
- withTelemetry('mindlore-decision-detector', main).catch(err => {
52
- hookLog('mindlore-decision-detector', 'error', err?.message ?? String(err));
60
+ withTelemetry("mindlore-decision-detector", main).catch((err) => {
61
+ hookLog("mindlore-decision-detector", "error", err?.message ?? String(err));
53
62
  process.exit(0);
54
63
  });
@@ -1,58 +1,34 @@
1
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
-
2
+ "use strict";
3
+
4
+ // hooks/src/mindlore-dont-repeat.cjs
5
+ var fs = require("fs");
6
+ var path = require("path");
7
+ var os = require("os");
8
+ var { findMindloreDir, getProjectName, hookLog, withTelemetrySync } = require("./lib/mindlore-common.cjs");
9
+ var cacheDirty = false;
32
10
  function readCache(cachePath) {
33
11
  if (!cachePath) return {};
34
12
  try {
35
- return JSON.parse(fs.readFileSync(cachePath, 'utf8'));
13
+ return JSON.parse(fs.readFileSync(cachePath, "utf8"));
36
14
  } catch (_err) {
37
15
  return {};
38
16
  }
39
17
  }
40
-
41
18
  function writeCache(cachePath, cache) {
42
19
  if (!cachePath || !cacheDirty) return;
43
20
  try {
44
- fs.writeFileSync(cachePath, JSON.stringify(cache), 'utf8');
45
- } catch (_err) { /* write failure is non-fatal */ }
21
+ fs.writeFileSync(cachePath, JSON.stringify(cache), "utf8");
22
+ } catch (_err) {
23
+ }
46
24
  }
47
-
48
25
  function loadPatterns(filePath, cache) {
49
26
  try {
50
27
  const stat = fs.statSync(filePath);
51
28
  const mtimeMs = stat.mtimeMs;
52
29
  const cached = cache[filePath];
53
30
  if (cached && cached.mtimeMs === mtimeMs) return cached.patterns;
54
-
55
- const patterns = extractNegativePatterns(fs.readFileSync(filePath, 'utf8'));
31
+ const patterns = extractNegativePatterns(fs.readFileSync(filePath, "utf8"));
56
32
  cache[filePath] = { mtimeMs, patterns };
57
33
  cacheDirty = true;
58
34
  return patterns;
@@ -60,42 +36,30 @@ function loadPatterns(filePath, cache) {
60
36
  return [];
61
37
  }
62
38
  }
63
-
64
39
  function extractNegativePatterns(content) {
65
40
  const patterns = [];
66
- const lines = content.split('\n');
67
-
41
+ const lines = content.split("\n");
68
42
  for (const line of lines) {
69
43
  const trimmed = line.trim();
70
- // Multi-language: TR (YAPMA, KRITIK) + EN (DON'T, NEVER, AVOID, DO NOT)
71
44
  const isNegativeRule = /^-\s*(YAPMA|KRITIK|DON'?T|NEVER|AVOID|DO NOT):/i.test(trimmed);
72
45
  if (!isNegativeRule) continue;
73
-
74
- // Extract backtick-quoted code patterns: `pattern`
75
46
  const backtickMatches = trimmed.match(/`([^`]+)`/g);
76
47
  if (backtickMatches) {
77
48
  for (const match of backtickMatches) {
78
49
  const pattern = match.slice(1, -1).trim();
79
- // Skip short/generic patterns — too many false positives
80
50
  if (pattern.length < 8) continue;
81
51
  if (/^[^a-zA-Z0-9]+$/.test(pattern)) continue;
82
- // Skip single words (too generic: "node", "bash", "any")
83
52
  if (/^\w+$/.test(pattern) && pattern.length < 12) continue;
84
- // Skip file extensions and paths
85
53
  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
54
+ if (pattern.startsWith("/") || pattern.startsWith("~")) continue;
55
+ if (pattern.includes(".md") || pattern.includes(".json")) continue;
89
56
  if (/^(node|bash|npm|git|process|require|import|export|const|let|var)$/i.test(pattern)) continue;
90
-
91
57
  patterns.push({
92
58
  pattern,
93
- rule: trimmed.substring(0, 120),
59
+ rule: trimmed.substring(0, 120)
94
60
  });
95
61
  }
96
62
  }
97
-
98
- // Extract "quoted strings" as patterns
99
63
  const quoteMatches = trimmed.match(/"([^"]+)"/g);
100
64
  if (quoteMatches) {
101
65
  for (const match of quoteMatches) {
@@ -103,120 +67,116 @@ function extractNegativePatterns(content) {
103
67
  if (quoted.length < 4) continue;
104
68
  patterns.push({
105
69
  pattern: quoted,
106
- rule: trimmed.substring(0, 120),
70
+ rule: trimmed.substring(0, 120)
107
71
  });
108
72
  }
109
73
  }
110
74
  }
111
-
112
75
  return patterns;
113
76
  }
114
-
77
+ var _lessonsEnforcementCached = null;
78
+ function hasLessonsEnforcementHook() {
79
+ if (_lessonsEnforcementCached !== null) return _lessonsEnforcementCached;
80
+ try {
81
+ const settingsPath = path.join(os.homedir(), ".claude", "settings.json");
82
+ const settings = JSON.parse(fs.readFileSync(settingsPath, "utf8"));
83
+ const hooks = settings.hooks || {};
84
+ const preToolUse = hooks.PreToolUse || [];
85
+ _lessonsEnforcementCached = preToolUse.some((entry) => {
86
+ const cmds = (entry.hooks || []).map((h) => h.command || "").concat(entry.command || "");
87
+ return cmds.some((c) => c.includes("lessons-enforcement"));
88
+ });
89
+ } catch (_err) {
90
+ _lessonsEnforcementCached = false;
91
+ }
92
+ return _lessonsEnforcementCached;
93
+ }
115
94
  function checkContent(content, patterns) {
116
95
  const matches = [];
117
96
  for (const p of patterns) {
118
97
  try {
119
- const escaped = p.pattern.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
120
- const regex = new RegExp(escaped, 'i');
98
+ const escaped = p.pattern.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
99
+ const regex = new RegExp(escaped, "i");
121
100
  if (regex.test(content)) {
122
101
  matches.push(p);
123
102
  }
124
- } catch { /* skip invalid patterns */ }
103
+ } catch {
104
+ }
125
105
  }
126
106
  return matches;
127
107
  }
128
-
129
108
  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', () => {
109
+ let input = "";
110
+ const stdinTimeout = setTimeout(() => process.exit(0), 3e3);
111
+ process.stdin.setEncoding("utf8");
112
+ process.stdin.on("error", () => process.exit(0));
113
+ process.stdin.on("data", (chunk) => input += chunk);
114
+ process.stdin.on("end", () => {
136
115
  clearTimeout(stdinTimeout);
137
116
  try {
138
- const data = JSON.parse(input || '{}');
139
- const toolName = data.tool_name || '';
140
-
141
- if (!['Write', 'Edit'].includes(toolName)) {
117
+ const data = JSON.parse(input || "{}");
118
+ const toolName = data.tool_name || "";
119
+ if (!["Write", "Edit"].includes(toolName)) {
142
120
  return process.exit(0);
143
121
  }
144
-
145
122
  const toolInput = data.tool_input || {};
146
- const filePath = toolInput.file_path || '';
147
-
148
- // Skip non-code files
123
+ const filePath = toolInput.file_path || "";
149
124
  if (!filePath) return process.exit(0);
150
125
  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'];
126
+ const codeExts = [".ts", ".tsx", ".js", ".jsx", ".cjs", ".mjs", ".py", ".go", ".rs", ".java", ".c", ".cpp", ".h", ".sh", ".yaml", ".yml"];
152
127
  if (!codeExts.includes(ext)) return process.exit(0);
153
-
154
- // Skip rule files themselves
155
128
  const basename = path.basename(filePath);
156
- if (basename === 'LESSONS.md' || basename === 'global.md' || basename === 'CLAUDE.md') {
129
+ if (basename === "LESSONS.md" || basename === "global.md" || basename === "CLAUDE.md") {
157
130
  return process.exit(0);
158
131
  }
159
-
160
- // Collect content being written (skip old_string — that's code being removed, not added)
161
132
  const allContent = [
162
- toolInput.content || '',
163
- toolInput.new_string || '',
164
- ].join('\n');
165
-
133
+ toolInput.content || "",
134
+ toolInput.new_string || ""
135
+ ].join("\n");
166
136
  if (allContent.trim().length < 10) return process.exit(0);
167
-
168
- // Load patterns from all sources (file-persisted mtime cache)
137
+ if (hasLessonsEnforcementHook()) return process.exit(0);
169
138
  const mindloreDir = findMindloreDir();
170
- const cachePath = mindloreDir ? path.join(mindloreDir, 'diary', `_pattern-cache-${getProjectName()}.json`) : null;
139
+ const cachePath = mindloreDir ? path.join(mindloreDir, "diary", `_pattern-cache-${getProjectName()}.json`) : null;
171
140
  const cache = readCache(cachePath);
172
141
  const allPatterns = [];
173
142
  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
143
+ allPatterns.push(...loadPatterns(path.join(os.homedir(), ".claude", "lessons", "global.md"), cache));
144
+ allPatterns.push(...loadPatterns(path.join(cwd, "LESSONS.md"), cache));
182
145
  if (mindloreDir) {
183
- const learningsDir = path.join(mindloreDir, 'learnings');
146
+ const learningsDir = path.join(mindloreDir, "learnings");
184
147
  try {
185
- const files = fs.readdirSync(learningsDir).filter(f => f.endsWith('.md'));
148
+ const files = fs.readdirSync(learningsDir).filter((f) => f.endsWith(".md"));
186
149
  for (const file of files) {
187
150
  allPatterns.push(...loadPatterns(path.join(learningsDir, file), cache));
188
151
  }
189
- } catch (_err) { /* learnings/ doesn't exist yet */ }
152
+ } catch (_err) {
153
+ }
190
154
  }
191
-
192
155
  writeCache(cachePath, cache);
193
-
194
156
  if (allPatterns.length === 0) return process.exit(0);
195
-
196
- // Check content against patterns
197
157
  const matches = checkContent(allContent, allPatterns);
198
158
  if (matches.length === 0) return process.exit(0);
199
-
200
- // Build warning — max 3 matches shown
201
159
  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
-
160
+ const warning = shown.map(
161
+ (m) => ` - Pattern: \`${m.pattern}\` \u2192 ${m.rule}`
162
+ ).join("\n");
163
+ const extra = matches.length > 3 ? `
164
+ ... and ${matches.length - 3} more` : "";
165
+ const msg = `[Mindlore: ${matches.length} dont-repeat rule violation detected]
166
+ ${warning}${extra}`;
209
167
  process.stdout.write(JSON.stringify({
210
168
  hookSpecificOutput: {
211
- hookEventName: 'PreToolUse',
169
+ hookEventName: "PreToolUse",
212
170
  additionalContext: msg
213
171
  }
214
172
  }));
215
173
  } catch {
216
- // Silent fail
217
174
  }
218
175
  process.exit(0);
219
176
  });
220
177
  }
221
-
222
- try { withTelemetrySync('mindlore-dont-repeat', main); } catch (err) { hookLog('dont-repeat', 'error', err?.message ?? String(err)); }
178
+ try {
179
+ withTelemetrySync("mindlore-dont-repeat", main);
180
+ } catch (err) {
181
+ hookLog("dont-repeat", "error", err?.message ?? String(err));
182
+ }