@hongmaple0820/scale-engine 0.24.0 → 0.26.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 (155) hide show
  1. package/LICENSE +15 -15
  2. package/README.en.md +336 -304
  3. package/README.md +500 -475
  4. package/dist/adapters/AiderAdapter.js +52 -52
  5. package/dist/adapters/AntigravityAdapter.d.ts +4 -0
  6. package/dist/adapters/AntigravityAdapter.js +21 -0
  7. package/dist/adapters/AntigravityAdapter.js.map +1 -0
  8. package/dist/adapters/ClaudeCodeAdapter.d.ts +4 -1
  9. package/dist/adapters/ClaudeCodeAdapter.js +34 -34
  10. package/dist/adapters/ClaudeCodeAdapter.js.map +1 -1
  11. package/dist/adapters/ClineAdapter.d.ts +4 -0
  12. package/dist/adapters/ClineAdapter.js +20 -0
  13. package/dist/adapters/ClineAdapter.js.map +1 -0
  14. package/dist/adapters/CodexAdapter.js +28 -28
  15. package/dist/adapters/CursorAdapter.js +26 -26
  16. package/dist/adapters/DeepSeekTuiAdapter.js +97 -97
  17. package/dist/adapters/DoubaoAdapter.js +33 -33
  18. package/dist/adapters/GeminiAdapter.js +26 -26
  19. package/dist/adapters/GenericProjectAgentAdapter.d.ts +29 -0
  20. package/dist/adapters/GenericProjectAgentAdapter.js +204 -0
  21. package/dist/adapters/GenericProjectAgentAdapter.js.map +1 -0
  22. package/dist/adapters/HermesAdapter.js +26 -26
  23. package/dist/adapters/JCodeAdapter.d.ts +4 -0
  24. package/dist/adapters/JCodeAdapter.js +19 -0
  25. package/dist/adapters/JCodeAdapter.js.map +1 -0
  26. package/dist/adapters/KiloCodeAdapter.d.ts +4 -0
  27. package/dist/adapters/KiloCodeAdapter.js +20 -0
  28. package/dist/adapters/KiloCodeAdapter.js.map +1 -0
  29. package/dist/adapters/KimiAdapter.js +32 -32
  30. package/dist/adapters/KiroAdapter.js +26 -26
  31. package/dist/adapters/OpenClawAdapter.js +26 -26
  32. package/dist/adapters/OpenCodeAdapter.js +26 -26
  33. package/dist/adapters/QCoderAdapter.js +26 -26
  34. package/dist/adapters/QoderAdapter.d.ts +4 -0
  35. package/dist/adapters/QoderAdapter.js +21 -0
  36. package/dist/adapters/QoderAdapter.js.map +1 -0
  37. package/dist/adapters/TraeAdapter.js +26 -26
  38. package/dist/adapters/VSCAdapter.js +26 -26
  39. package/dist/adapters/WindsurfAdapter.js +32 -32
  40. package/dist/adapters/WorkBuddyAdapter.js +26 -26
  41. package/dist/adapters/index.d.ts +5 -0
  42. package/dist/adapters/index.js +15 -0
  43. package/dist/adapters/index.js.map +1 -1
  44. package/dist/api/cli.js +226 -48
  45. package/dist/api/cli.js.map +1 -1
  46. package/dist/api/doctor.js +10 -3
  47. package/dist/api/doctor.js.map +1 -1
  48. package/dist/api/quickstart.js +7 -1
  49. package/dist/api/quickstart.js.map +1 -1
  50. package/dist/artifact/sqliteStore.js +89 -89
  51. package/dist/artifact/types.d.ts +1 -1
  52. package/dist/cli/phaseCommands.js +45 -45
  53. package/dist/context/AntiPatternRegistry.js +20 -20
  54. package/dist/context/ContextBuilder.js +155 -155
  55. package/dist/evolution/EvolutionEngine.js +31 -31
  56. package/dist/evolution/EvolutionEvaluator.d.ts +2 -0
  57. package/dist/evolution/EvolutionEvaluator.js +7 -1
  58. package/dist/evolution/EvolutionEvaluator.js.map +1 -1
  59. package/dist/fsm/FSMAgentBridge.js +11 -11
  60. package/dist/hooks/HookGeneratorEnhanced.js +218 -218
  61. package/dist/index.d.ts +1 -1
  62. package/dist/index.js +2 -2
  63. package/dist/index.js.map +1 -1
  64. package/dist/knowledge/SQLiteKnowledgeBase.js +28 -28
  65. package/dist/memory/MemoryBrain.d.ts +1 -0
  66. package/dist/memory/MemoryBrain.js +55 -52
  67. package/dist/memory/MemoryBrain.js.map +1 -1
  68. package/dist/memory/MemoryFabric.d.ts +13 -1
  69. package/dist/memory/MemoryFabric.js +35 -0
  70. package/dist/memory/MemoryFabric.js.map +1 -1
  71. package/dist/memory/MemoryProviders.d.ts +111 -0
  72. package/dist/memory/MemoryProviders.js +385 -0
  73. package/dist/memory/MemoryProviders.js.map +1 -0
  74. package/dist/memory/index.d.ts +1 -0
  75. package/dist/memory/index.js +1 -0
  76. package/dist/memory/index.js.map +1 -1
  77. package/dist/output/GovernanceDashboard.js +44 -44
  78. package/dist/output/HTMLArtifactLayer.js +31 -31
  79. package/dist/prompts/VibeTemplateGallery.js +121 -121
  80. package/dist/skills/SkillDiscovery.js +12 -1
  81. package/dist/skills/SkillDiscovery.js.map +1 -1
  82. package/dist/skills/SkillRadar.js +20 -0
  83. package/dist/skills/SkillRadar.js.map +1 -1
  84. package/dist/skills/SkillRepository.d.ts +9 -1
  85. package/dist/skills/SkillRepository.js +70 -0
  86. package/dist/skills/SkillRepository.js.map +1 -1
  87. package/dist/skills/routing/SkillPlanner.js +40 -40
  88. package/dist/workflow/EngineeringStandards.js +62 -62
  89. package/dist/workflow/GovernanceTemplatePacks.d.ts +1 -1
  90. package/dist/workflow/GovernanceTemplatePacks.js +1990 -162
  91. package/dist/workflow/GovernanceTemplatePacks.js.map +1 -1
  92. package/dist/workflow/GovernanceTemplates.d.ts +2 -0
  93. package/dist/workflow/GovernanceTemplates.js +1012 -1001
  94. package/dist/workflow/GovernanceTemplates.js.map +1 -1
  95. package/dist/workflow/ResourceGovernance.js +16 -16
  96. package/dist/workflow/TaskArtifactScaffolder.js +10 -10
  97. package/dist/workflow/UpgradeManager.d.ts +3 -2
  98. package/dist/workflow/UpgradeManager.js +134 -49
  99. package/dist/workflow/UpgradeManager.js.map +1 -1
  100. package/dist/workflow/WorkspaceTopology.js +18 -15
  101. package/dist/workflow/WorkspaceTopology.js.map +1 -1
  102. package/docs/CODE_INTELLIGENCE.md +138 -138
  103. package/docs/CONTEXT_BUDGET.md +81 -81
  104. package/docs/EXTERNAL_REFERENCES.md +63 -0
  105. package/docs/GITLAB_FLOW.md +125 -125
  106. package/docs/GOVERNANCE_DASHBOARD.md +64 -64
  107. package/docs/MEMORY_BRAIN.md +104 -104
  108. package/docs/MEMORY_FABRIC.md +134 -107
  109. package/docs/README.md +79 -68
  110. package/docs/RUNTIME_EVIDENCE.md +101 -101
  111. package/docs/SKILL-REPOSITORY.md +57 -0
  112. package/docs/SKILL_RADAR.md +122 -115
  113. package/docs/THIRD_PARTY_SKILLS.md +57 -0
  114. package/docs/WORKFLOW_EVAL.md +151 -151
  115. package/docs/guides/DEVELOPMENT_WORKFLOW.md +80 -0
  116. package/docs/guides/GETTING_STARTED.md +50 -0
  117. package/docs/start/README.md +78 -72
  118. package/docs/start/agent-governance-demo.md +107 -107
  119. package/docs/start/quickstart.md +137 -127
  120. package/docs/start/workflow-upgrade.md +32 -8
  121. package/docs/workflow/README.md +67 -0
  122. package/docs/workflow/node-library.md +52 -0
  123. package/docs/workflow/templates/api-contract.md +29 -0
  124. package/docs/workflow/templates/architecture-review.md +23 -0
  125. package/docs/workflow/templates/db-change-plan.md +20 -0
  126. package/docs/workflow/templates/docs-impact.md +17 -0
  127. package/docs/workflow/templates/e2e-plan.md +20 -0
  128. package/docs/workflow/templates/explore.md +16 -0
  129. package/docs/workflow/templates/github-actions-scale-preflight.yml +32 -0
  130. package/docs/workflow/templates/mini-prd.md +16 -0
  131. package/docs/workflow/templates/plan.md +37 -0
  132. package/docs/workflow/templates/pre-push-scale-preflight.sh +8 -0
  133. package/docs/workflow/templates/product-smoke.md +61 -0
  134. package/docs/workflow/templates/reality-check.md +28 -0
  135. package/docs/workflow/templates/resource-cleanup.md +17 -0
  136. package/docs/workflow/templates/resource-impact.md +25 -0
  137. package/docs/workflow/templates/review.md +12 -0
  138. package/docs/workflow/templates/runtime.md +23 -0
  139. package/docs/workflow/templates/security-review.md +26 -0
  140. package/docs/workflow/templates/skill-evidence.md +33 -0
  141. package/docs/workflow/templates/skill-plan.md +39 -0
  142. package/docs/workflow/templates/spec.md +17 -0
  143. package/docs/workflow/templates/standards-impact.md +28 -0
  144. package/docs/workflow/templates/summary.md +16 -0
  145. package/docs/workflow/templates/tasks.md +8 -0
  146. package/docs/workflow/templates/ui-spec.md +29 -0
  147. package/docs/workflow/templates/verification.md +20 -0
  148. package/docs/workflow/templates/visual-review.md +20 -0
  149. package/examples/demo-projects/agent-governance-demo/CONTEXT.md +14 -14
  150. package/examples/demo-projects/agent-governance-demo/README.md +48 -48
  151. package/examples/demo-projects/agent-governance-demo/docs/CONTEXT-MAP.md +14 -14
  152. package/examples/demo-projects/agent-governance-demo/package.json +22 -21
  153. package/examples/demo-projects/agent-governance-demo/src/oauth-state.ts +39 -39
  154. package/examples/demo-projects/agent-governance-demo/tests/oauth-state.test.ts +52 -52
  155. package/package.json +88 -75
@@ -143,33 +143,33 @@ const BUILTIN_TEMPLATES = [
143
143
  hookType: 'PreToolUse',
144
144
  matcherPattern: 'Read',
145
145
  description: 'Look up file description from anatomy.md before Claude reads it',
146
- templateBody: String.raw `
147
- const fs = require("fs");
148
- const path = require("path");
149
- const scaleDir = process.env.SCALE_DIR || ".scale";
150
- const input = JSON.parse(process.argv[2] || "{}");
151
- const filePath = input.tool_input?.file_path || input.tool_input?.path || "";
152
- if (!filePath) { console.log("[PASS]"); process.exit(0); }
153
- const anatomyPath = path.join(scaleDir, "anatomy.md");
154
- if (!fs.existsSync(anatomyPath)) { console.log("[PASS]"); process.exit(0); }
155
- try {
156
- const content = fs.readFileSync(anatomyPath, "utf-8");
157
- const basename = path.basename(filePath);
158
- const lines = content.split("\n");
159
- for (const line of lines) {
160
- if (!line.startsWith("- ")) continue;
161
- if (line.indexOf(basename) === -1) continue;
162
- var tokMatch = line.match(/\(~(\d+)\s+tok\)/);
163
- var tokens = tokMatch ? tokMatch[1] : "?";
164
- var descPart = line.split(" - ")[1];
165
- var desc = descPart ? descPart.split("(")[0].trim() : "no description";
166
- console.error("[ANATOMY] " + basename + " - " + desc + " (~" + tokens + " tok)");
167
- break;
168
- }
169
- } catch (error) {
170
- console.error("[ANATOMY] Lookup skipped: " + (error && error.message ? error.message : String(error)));
171
- }
172
- console.log("[PASS]");
146
+ templateBody: String.raw `
147
+ const fs = require("fs");
148
+ const path = require("path");
149
+ const scaleDir = process.env.SCALE_DIR || ".scale";
150
+ const input = JSON.parse(process.argv[2] || "{}");
151
+ const filePath = input.tool_input?.file_path || input.tool_input?.path || "";
152
+ if (!filePath) { console.log("[PASS]"); process.exit(0); }
153
+ const anatomyPath = path.join(scaleDir, "anatomy.md");
154
+ if (!fs.existsSync(anatomyPath)) { console.log("[PASS]"); process.exit(0); }
155
+ try {
156
+ const content = fs.readFileSync(anatomyPath, "utf-8");
157
+ const basename = path.basename(filePath);
158
+ const lines = content.split("\n");
159
+ for (const line of lines) {
160
+ if (!line.startsWith("- ")) continue;
161
+ if (line.indexOf(basename) === -1) continue;
162
+ var tokMatch = line.match(/\(~(\d+)\s+tok\)/);
163
+ var tokens = tokMatch ? tokMatch[1] : "?";
164
+ var descPart = line.split(" - ")[1];
165
+ var desc = descPart ? descPart.split("(")[0].trim() : "no description";
166
+ console.error("[ANATOMY] " + basename + " - " + desc + " (~" + tokens + " tok)");
167
+ break;
168
+ }
169
+ } catch (error) {
170
+ console.error("[ANATOMY] Lookup skipped: " + (error && error.message ? error.message : String(error)));
171
+ }
172
+ console.log("[PASS]");
173
173
  process.exit(0);`,
174
174
  variables: []
175
175
  },
@@ -179,29 +179,29 @@ process.exit(0);`,
179
179
  hookType: 'PostToolUse',
180
180
  matcherPattern: 'Write|Edit',
181
181
  description: 'Update anatomy.md after file write/edit',
182
- templateBody: String.raw `
183
- const fs = require("fs");
184
- const path = require("path");
185
- const scaleDir = process.env.SCALE_DIR || ".scale";
186
- const projectDir = process.env.SCALE_PROJECT_DIR || process.cwd();
187
- const input = JSON.parse(process.argv[2] || "{}");
188
- const filePath = input.tool_input?.file_path || input.tool_input?.path || "";
189
- if (!filePath) { console.log("[PASS]"); process.exit(0); }
190
- const baseName = path.basename(filePath);
191
- if (baseName === ".env" || baseName.startsWith(".env.")) { console.log("[PASS]"); process.exit(0); }
192
- if (filePath.includes(scaleDir)) { console.log("[PASS]"); process.exit(0); }
193
- try {
194
- const content = input.tool_input?.content || input.tool_input?.new_string || "";
195
- if (!content) { console.log("[PASS]"); process.exit(0); }
196
- const tokens = Math.ceil(content.length / 4);
197
- const relPath = path.relative(projectDir, filePath).replace(/\\\\/g, "/");
198
- const dir = path.dirname(relPath);
199
- const sectionKey = dir === "." ? "./" : dir + "/";
200
- console.log("[ANATOMY-UPDATE] " + relPath + " (~" + tokens + " tok)");
201
- } catch (error) {
202
- console.error("[ANATOMY-UPDATE] Skipped: " + (error && error.message ? error.message : String(error)));
203
- }
204
- console.log("[PASS]");
182
+ templateBody: String.raw `
183
+ const fs = require("fs");
184
+ const path = require("path");
185
+ const scaleDir = process.env.SCALE_DIR || ".scale";
186
+ const projectDir = process.env.SCALE_PROJECT_DIR || process.cwd();
187
+ const input = JSON.parse(process.argv[2] || "{}");
188
+ const filePath = input.tool_input?.file_path || input.tool_input?.path || "";
189
+ if (!filePath) { console.log("[PASS]"); process.exit(0); }
190
+ const baseName = path.basename(filePath);
191
+ if (baseName === ".env" || baseName.startsWith(".env.")) { console.log("[PASS]"); process.exit(0); }
192
+ if (filePath.includes(scaleDir)) { console.log("[PASS]"); process.exit(0); }
193
+ try {
194
+ const content = input.tool_input?.content || input.tool_input?.new_string || "";
195
+ if (!content) { console.log("[PASS]"); process.exit(0); }
196
+ const tokens = Math.ceil(content.length / 4);
197
+ const relPath = path.relative(projectDir, filePath).replace(/\\\\/g, "/");
198
+ const dir = path.dirname(relPath);
199
+ const sectionKey = dir === "." ? "./" : dir + "/";
200
+ console.log("[ANATOMY-UPDATE] " + relPath + " (~" + tokens + " tok)");
201
+ } catch (error) {
202
+ console.error("[ANATOMY-UPDATE] Skipped: " + (error && error.message ? error.message : String(error)));
203
+ }
204
+ console.log("[PASS]");
205
205
  process.exit(0);`,
206
206
  variables: []
207
207
  },
@@ -211,26 +211,26 @@ process.exit(0);`,
211
211
  hookType: 'SessionStart',
212
212
  matcherPattern: '',
213
213
  description: 'Show project overview from anatomy.md at session start',
214
- templateBody: String.raw `
215
- const fs = require("fs");
216
- const path = require("path");
217
- const scaleDir = process.env.SCALE_DIR || ".scale";
218
- const anatomyPath = path.join(scaleDir, "anatomy.md");
219
- if (!fs.existsSync(anatomyPath)) { console.log("[PASS]"); process.exit(0); }
220
- try {
221
- const content = fs.readFileSync(anatomyPath, "utf-8");
222
- const header = content.match(/> Files: (\d+) \| Total: ~([\d,]+) tokens/);
223
- if (header) {
224
- console.error("[ANATOMY] Project map: " + header[1] + " files, ~" + header[2] + " tokens");
225
- }
226
- const age = (Date.now() - fs.statSync(anatomyPath).mtimeMs) / (1000 * 60 * 60 * 24);
227
- if (age > 7) {
228
- console.error("[ANATOMY] anatomy.md is " + Math.floor(age) + " days old. Consider: scale scan");
229
- }
230
- } catch (error) {
231
- console.error("[ANATOMY] Session summary skipped: " + (error && error.message ? error.message : String(error)));
232
- }
233
- console.log("[PASS]");
214
+ templateBody: String.raw `
215
+ const fs = require("fs");
216
+ const path = require("path");
217
+ const scaleDir = process.env.SCALE_DIR || ".scale";
218
+ const anatomyPath = path.join(scaleDir, "anatomy.md");
219
+ if (!fs.existsSync(anatomyPath)) { console.log("[PASS]"); process.exit(0); }
220
+ try {
221
+ const content = fs.readFileSync(anatomyPath, "utf-8");
222
+ const header = content.match(/> Files: (\d+) \| Total: ~([\d,]+) tokens/);
223
+ if (header) {
224
+ console.error("[ANATOMY] Project map: " + header[1] + " files, ~" + header[2] + " tokens");
225
+ }
226
+ const age = (Date.now() - fs.statSync(anatomyPath).mtimeMs) / (1000 * 60 * 60 * 24);
227
+ if (age > 7) {
228
+ console.error("[ANATOMY] anatomy.md is " + Math.floor(age) + " days old. Consider: scale scan");
229
+ }
230
+ } catch (error) {
231
+ console.error("[ANATOMY] Session summary skipped: " + (error && error.message ? error.message : String(error)));
232
+ }
233
+ console.log("[PASS]");
234
234
  process.exit(0);`,
235
235
  variables: []
236
236
  },
@@ -241,35 +241,35 @@ process.exit(0);`,
241
241
  hookType: 'PreToolUse',
242
242
  matcherPattern: 'Write|Edit',
243
243
  description: 'Check Do-Not-Repeat rules before writing code',
244
- templateBody: String.raw `
245
- const fs = require("fs");
246
- const path = require("path");
247
- const input = JSON.parse(process.argv[2] || "{}");
248
- const content = input.tool_input?.content || input.tool_input?.new_string || "";
249
- if (!content) { console.log("[PASS]"); process.exit(0); }
250
- const scaleDir = process.env.SCALE_DIR || ".scale";
251
- const cerebrumPath = path.join(scaleDir, "cerebrum.md");
252
- if (!fs.existsSync(cerebrumPath)) { console.log("[PASS]"); process.exit(0); }
253
- try {
254
- const cerebrum = fs.readFileSync(cerebrumPath, "utf-8");
255
- const dnrSection = cerebrum.split("## Do Not Repeat")[1]?.split("## ")[0] || "";
256
- const rules = dnrSection.match(/- \*\*(.+?)\*\*\s+-\s+(.+)/g) || [];
257
- const contentLower = content.toLowerCase();
258
- for (const rule of rules) {
259
- const m = rule.match(/- \*\*(.+?)\*\*\s+-\s+(.+)/);
260
- if (!m) continue;
261
- const pattern = m[1].toLowerCase();
262
- const desc = m[2];
263
- const words = pattern.split(/\s+/).filter(w => w.length > 2);
264
- const hits = words.filter(w => contentLower.includes(w));
265
- if (hits.length > 0 && hits.length >= Math.ceil(words.length * 0.4)) {
266
- console.error("[CEREBRUM] Do-Not-Repeat: \"" + m[1] + "\" - " + desc);
267
- }
268
- }
269
- } catch (error) {
270
- console.error("[CEREBRUM] Check skipped: " + (error && error.message ? error.message : String(error)));
271
- }
272
- console.log("[PASS]");
244
+ templateBody: String.raw `
245
+ const fs = require("fs");
246
+ const path = require("path");
247
+ const input = JSON.parse(process.argv[2] || "{}");
248
+ const content = input.tool_input?.content || input.tool_input?.new_string || "";
249
+ if (!content) { console.log("[PASS]"); process.exit(0); }
250
+ const scaleDir = process.env.SCALE_DIR || ".scale";
251
+ const cerebrumPath = path.join(scaleDir, "cerebrum.md");
252
+ if (!fs.existsSync(cerebrumPath)) { console.log("[PASS]"); process.exit(0); }
253
+ try {
254
+ const cerebrum = fs.readFileSync(cerebrumPath, "utf-8");
255
+ const dnrSection = cerebrum.split("## Do Not Repeat")[1]?.split("## ")[0] || "";
256
+ const rules = dnrSection.match(/- \*\*(.+?)\*\*\s+-\s+(.+)/g) || [];
257
+ const contentLower = content.toLowerCase();
258
+ for (const rule of rules) {
259
+ const m = rule.match(/- \*\*(.+?)\*\*\s+-\s+(.+)/);
260
+ if (!m) continue;
261
+ const pattern = m[1].toLowerCase();
262
+ const desc = m[2];
263
+ const words = pattern.split(/\s+/).filter(w => w.length > 2);
264
+ const hits = words.filter(w => contentLower.includes(w));
265
+ if (hits.length > 0 && hits.length >= Math.ceil(words.length * 0.4)) {
266
+ console.error("[CEREBRUM] Do-Not-Repeat: \"" + m[1] + "\" - " + desc);
267
+ }
268
+ }
269
+ } catch (error) {
270
+ console.error("[CEREBRUM] Check skipped: " + (error && error.message ? error.message : String(error)));
271
+ }
272
+ console.log("[PASS]");
273
273
  process.exit(0);`,
274
274
  variables: []
275
275
  },
@@ -280,25 +280,25 @@ process.exit(0);`,
280
280
  hookType: 'SessionStart',
281
281
  matcherPattern: '',
282
282
  description: 'Show cerebrum status at session start',
283
- templateBody: String.raw `
284
- const fs = require("fs");
285
- const path = require("path");
286
- const scaleDir = process.env.SCALE_DIR || ".scale";
287
- const cerebrumPath = path.join(scaleDir, "cerebrum.md");
288
- if (!fs.existsSync(cerebrumPath)) { console.log("[PASS]"); process.exit(0); }
289
- try {
290
- const content = fs.readFileSync(cerebrumPath, "utf-8");
291
- const dnrCount = (content.match(/- \*\*.+?\*\*/g) || []).length;
292
- const prefCount = (content.match(/^- [^-]/gm) || []).length - dnrCount;
293
- console.error("[CEREBRUM] " + dnrCount + " do-not-repeat rules, preferences loaded");
294
- const age = (Date.now() - fs.statSync(cerebrumPath).mtimeMs) / (1000 * 60 * 60 * 24);
295
- if (age > 14) {
296
- console.error("[CEREBRUM] cerebrum.md is " + Math.floor(age) + " days old. Learning may be stale.");
297
- }
298
- } catch (error) {
299
- console.error("[CEREBRUM] Session summary skipped: " + (error && error.message ? error.message : String(error)));
300
- }
301
- console.log("[PASS]");
283
+ templateBody: String.raw `
284
+ const fs = require("fs");
285
+ const path = require("path");
286
+ const scaleDir = process.env.SCALE_DIR || ".scale";
287
+ const cerebrumPath = path.join(scaleDir, "cerebrum.md");
288
+ if (!fs.existsSync(cerebrumPath)) { console.log("[PASS]"); process.exit(0); }
289
+ try {
290
+ const content = fs.readFileSync(cerebrumPath, "utf-8");
291
+ const dnrCount = (content.match(/- \*\*.+?\*\*/g) || []).length;
292
+ const prefCount = (content.match(/^- [^-]/gm) || []).length - dnrCount;
293
+ console.error("[CEREBRUM] " + dnrCount + " do-not-repeat rules, preferences loaded");
294
+ const age = (Date.now() - fs.statSync(cerebrumPath).mtimeMs) / (1000 * 60 * 60 * 24);
295
+ if (age > 14) {
296
+ console.error("[CEREBRUM] cerebrum.md is " + Math.floor(age) + " days old. Learning may be stale.");
297
+ }
298
+ } catch (error) {
299
+ console.error("[CEREBRUM] Session summary skipped: " + (error && error.message ? error.message : String(error)));
300
+ }
301
+ console.log("[PASS]");
302
302
  process.exit(0);`,
303
303
  variables: []
304
304
  },
@@ -309,68 +309,68 @@ process.exit(0);`,
309
309
  hookType: 'PostToolUse',
310
310
  matcherPattern: 'Edit',
311
311
  description: 'Auto-detect bug fix patterns from Edit operations and log to buglog.json',
312
- templateBody: String.raw `
313
- const fs = require("fs");
314
- const path = require("path");
315
- const input = JSON.parse(process.argv[2] || "{}");
316
- const oldStr = input.tool_input?.old_string || "";
317
- const newStr = input.tool_input?.new_string || "";
318
- const filePath = input.tool_input?.file_path || "";
319
- if (!oldStr || !newStr || oldStr === newStr) { console.log("[PASS]"); process.exit(0); }
320
-
321
- function detectPattern(old, nw) {
322
- if (/catch\s*\(/.test(nw) && !/catch\s*\(/.test(old)) return "error-handling";
323
- if (/\?\./.test(nw) && !/\?\./.test(old)) return "null-safety";
324
- if (/\?\?/.test(nw) && !/\?\?/.test(old)) return "null-safety";
325
- if (/if\s*\([^)]+\)\s*(return|throw)/.test(nw) && !/if\s*\([^)]+\)\s*(return|throw)/.test(old)) return "guard-clause";
326
- if (/^import\s+/m.test(nw) && !/^import\s+/m.test(old)) return "missing-import";
327
- if (/\bawait\b/.test(nw) && !/\bawait\b/.test(old)) return "async-fix";
328
- if (/===/.test(nw) && /==[^=]/.test(old) && !/===/.test(old)) return "operator-fix";
329
- if (/!==/.test(nw) && /!=[^=]/.test(old) && !/!==/.test(old)) return "operator-fix";
330
- if (/:\s*(string|number|boolean|any)\b/.test(nw) && !/:\s*(string|number|boolean|any)\b/.test(old) && /\.(ts|tsx)$/.test(filePath)) return "type-fix";
331
- if (old.split("\n").length === 1 && nw.split("\n").length === 1) {
332
- var oldIds = (old.match(/\b[a-zA-Z_]\w*\b/g) || []);
333
- var newIds = (nw.match(/\b[a-zA-Z_]\w*\b/g) || []);
334
- var diff = oldIds.filter(function(i) { return newIds.indexOf(i) < 0; });
335
- var added = newIds.filter(function(i) { return oldIds.indexOf(i) < 0; });
336
- if (diff.length === 1 && added.length === 1) return "wrong-reference";
337
- }
338
- return null;
339
- }
340
-
341
- var pattern = detectPattern(oldStr, newStr);
342
- if (!pattern) { console.log("[PASS]"); process.exit(0); }
343
-
344
- var scaleDir = process.env.SCALE_DIR || ".scale";
345
- var buglogPath = path.join(scaleDir, "buglog.json");
346
- try {
347
- var buglog = { version: 1, bugs: [] };
348
- if (fs.existsSync(buglogPath)) {
349
- buglog = JSON.parse(fs.readFileSync(buglogPath, "utf-8"));
350
- }
351
- var existing = buglog.bugs.find(function(b) { return b.file === filePath && b.pattern === pattern; });
352
- if (existing) {
353
- existing.occurrences = (existing.occurrences || 1) + 1;
354
- existing.timestamp = new Date().toISOString();
355
- } else {
356
- buglog.bugs.push({
357
- id: "bug-" + String(buglog.bugs.length + 1).padStart(3, "0"),
358
- timestamp: new Date().toISOString(),
359
- file: filePath,
360
- pattern: pattern,
361
- oldSnippet: oldStr.slice(0, 200),
362
- newSnippet: newStr.slice(0, 200),
363
- tags: ["auto-detected", pattern],
364
- occurrences: 1
365
- });
366
- }
367
- fs.mkdirSync(scaleDir, { recursive: true });
368
- fs.writeFileSync(buglogPath, JSON.stringify(buglog, null, 2));
369
- console.error("[BUG-CAPTURE] Detected " + pattern + " fix in " + path.basename(filePath));
370
- } catch (e) {
371
- console.error("[BUG-CAPTURE] Failed to log: " + e.message);
372
- }
373
- console.log("[PASS]");
312
+ templateBody: String.raw `
313
+ const fs = require("fs");
314
+ const path = require("path");
315
+ const input = JSON.parse(process.argv[2] || "{}");
316
+ const oldStr = input.tool_input?.old_string || "";
317
+ const newStr = input.tool_input?.new_string || "";
318
+ const filePath = input.tool_input?.file_path || "";
319
+ if (!oldStr || !newStr || oldStr === newStr) { console.log("[PASS]"); process.exit(0); }
320
+
321
+ function detectPattern(old, nw) {
322
+ if (/catch\s*\(/.test(nw) && !/catch\s*\(/.test(old)) return "error-handling";
323
+ if (/\?\./.test(nw) && !/\?\./.test(old)) return "null-safety";
324
+ if (/\?\?/.test(nw) && !/\?\?/.test(old)) return "null-safety";
325
+ if (/if\s*\([^)]+\)\s*(return|throw)/.test(nw) && !/if\s*\([^)]+\)\s*(return|throw)/.test(old)) return "guard-clause";
326
+ if (/^import\s+/m.test(nw) && !/^import\s+/m.test(old)) return "missing-import";
327
+ if (/\bawait\b/.test(nw) && !/\bawait\b/.test(old)) return "async-fix";
328
+ if (/===/.test(nw) && /==[^=]/.test(old) && !/===/.test(old)) return "operator-fix";
329
+ if (/!==/.test(nw) && /!=[^=]/.test(old) && !/!==/.test(old)) return "operator-fix";
330
+ if (/:\s*(string|number|boolean|any)\b/.test(nw) && !/:\s*(string|number|boolean|any)\b/.test(old) && /\.(ts|tsx)$/.test(filePath)) return "type-fix";
331
+ if (old.split("\n").length === 1 && nw.split("\n").length === 1) {
332
+ var oldIds = (old.match(/\b[a-zA-Z_]\w*\b/g) || []);
333
+ var newIds = (nw.match(/\b[a-zA-Z_]\w*\b/g) || []);
334
+ var diff = oldIds.filter(function(i) { return newIds.indexOf(i) < 0; });
335
+ var added = newIds.filter(function(i) { return oldIds.indexOf(i) < 0; });
336
+ if (diff.length === 1 && added.length === 1) return "wrong-reference";
337
+ }
338
+ return null;
339
+ }
340
+
341
+ var pattern = detectPattern(oldStr, newStr);
342
+ if (!pattern) { console.log("[PASS]"); process.exit(0); }
343
+
344
+ var scaleDir = process.env.SCALE_DIR || ".scale";
345
+ var buglogPath = path.join(scaleDir, "buglog.json");
346
+ try {
347
+ var buglog = { version: 1, bugs: [] };
348
+ if (fs.existsSync(buglogPath)) {
349
+ buglog = JSON.parse(fs.readFileSync(buglogPath, "utf-8"));
350
+ }
351
+ var existing = buglog.bugs.find(function(b) { return b.file === filePath && b.pattern === pattern; });
352
+ if (existing) {
353
+ existing.occurrences = (existing.occurrences || 1) + 1;
354
+ existing.timestamp = new Date().toISOString();
355
+ } else {
356
+ buglog.bugs.push({
357
+ id: "bug-" + String(buglog.bugs.length + 1).padStart(3, "0"),
358
+ timestamp: new Date().toISOString(),
359
+ file: filePath,
360
+ pattern: pattern,
361
+ oldSnippet: oldStr.slice(0, 200),
362
+ newSnippet: newStr.slice(0, 200),
363
+ tags: ["auto-detected", pattern],
364
+ occurrences: 1
365
+ });
366
+ }
367
+ fs.mkdirSync(scaleDir, { recursive: true });
368
+ fs.writeFileSync(buglogPath, JSON.stringify(buglog, null, 2));
369
+ console.error("[BUG-CAPTURE] Detected " + pattern + " fix in " + path.basename(filePath));
370
+ } catch (e) {
371
+ console.error("[BUG-CAPTURE] Failed to log: " + e.message);
372
+ }
373
+ console.log("[PASS]");
374
374
  process.exit(0);`,
375
375
  variables: []
376
376
  },
@@ -381,26 +381,26 @@ process.exit(0);`,
381
381
  hookType: 'PreToolUse',
382
382
  matcherPattern: 'Edit',
383
383
  description: 'Check buglog.json for past bugs in the same file before editing',
384
- templateBody: String.raw `
385
- const fs = require("fs");
386
- const path = require("path");
387
- const input = JSON.parse(process.argv[2] || "{}");
388
- const filePath = input.tool_input?.file_path || "";
389
- if (!filePath) { console.log("[PASS]"); process.exit(0); }
390
- const scaleDir = process.env.SCALE_DIR || ".scale";
391
- const buglogPath = path.join(scaleDir, "buglog.json");
392
- if (!fs.existsSync(buglogPath)) { console.log("[PASS]"); process.exit(0); }
393
- try {
394
- const buglog = JSON.parse(fs.readFileSync(buglogPath, "utf-8"));
395
- const fileBugs = buglog.bugs.filter(b => b.file === filePath || b.file.endsWith(path.basename(filePath)));
396
- if (fileBugs.length > 0) {
397
- const summary = fileBugs.slice(0, 3).map(b => b.pattern + " (" + (b.timestamp || "").slice(0, 10) + ")").join(", ");
398
- console.error("[BUG-RECALL] " + fileBugs.length + " past bugs in " + path.basename(filePath) + ": " + summary);
399
- }
400
- } catch (error) {
401
- console.error("[BUG-RECALL] Skipped: " + (error && error.message ? error.message : String(error)));
402
- }
403
- console.log("[PASS]");
384
+ templateBody: String.raw `
385
+ const fs = require("fs");
386
+ const path = require("path");
387
+ const input = JSON.parse(process.argv[2] || "{}");
388
+ const filePath = input.tool_input?.file_path || "";
389
+ if (!filePath) { console.log("[PASS]"); process.exit(0); }
390
+ const scaleDir = process.env.SCALE_DIR || ".scale";
391
+ const buglogPath = path.join(scaleDir, "buglog.json");
392
+ if (!fs.existsSync(buglogPath)) { console.log("[PASS]"); process.exit(0); }
393
+ try {
394
+ const buglog = JSON.parse(fs.readFileSync(buglogPath, "utf-8"));
395
+ const fileBugs = buglog.bugs.filter(b => b.file === filePath || b.file.endsWith(path.basename(filePath)));
396
+ if (fileBugs.length > 0) {
397
+ const summary = fileBugs.slice(0, 3).map(b => b.pattern + " (" + (b.timestamp || "").slice(0, 10) + ")").join(", ");
398
+ console.error("[BUG-RECALL] " + fileBugs.length + " past bugs in " + path.basename(filePath) + ": " + summary);
399
+ }
400
+ } catch (error) {
401
+ console.error("[BUG-RECALL] Skipped: " + (error && error.message ? error.message : String(error)));
402
+ }
403
+ console.log("[PASS]");
404
404
  process.exit(0);`,
405
405
  variables: []
406
406
  },
@@ -411,24 +411,24 @@ process.exit(0);`,
411
411
  hookType: 'PostToolUse',
412
412
  matcherPattern: 'Write|Edit',
413
413
  description: 'Check markdown files comply with DOCUMENT_STANDARDS.md',
414
- templateBody: String.raw `
415
- const input = JSON.parse(process.argv[2] || "{}");
416
- const filePath = input.tool_input?.file_path || "";
417
- if (!filePath.endsWith(".md")) { console.log("[PASS]"); process.exit(0); }
418
- const content = input.tool_input?.content || "";
419
- const issues = [];
420
- // Check version header
421
- if (!content.includes("Version:")) { issues.push("Missing version header"); }
422
- // Check localhost links
423
- if (/localhost[:\\/]/.test(content)) { issues.push("Contains localhost links"); }
424
- // Check hardcoded secrets
425
- if (/(password|secret|token|api_key)\\s*[:=]\\s*['"][^'"]{8,}/i.test(content)) { issues.push("Possible hardcoded secret"); }
426
- // Check code blocks without language
427
- const codeBlockPattern = /\`\`\`\\s*$/gm;
428
- const matches = content.match(codeBlockPattern);
429
- if (matches && matches.length > 0) { issues.push("Code blocks without language annotation"); }
430
- if (issues.length > 0) { console.error("[WARN] G8-DocStandards: " + issues.join("; ")); }
431
- console.log("[PASS]");
414
+ templateBody: String.raw `
415
+ const input = JSON.parse(process.argv[2] || "{}");
416
+ const filePath = input.tool_input?.file_path || "";
417
+ if (!filePath.endsWith(".md")) { console.log("[PASS]"); process.exit(0); }
418
+ const content = input.tool_input?.content || "";
419
+ const issues = [];
420
+ // Check version header
421
+ if (!content.includes("Version:")) { issues.push("Missing version header"); }
422
+ // Check localhost links
423
+ if (/localhost[:\\/]/.test(content)) { issues.push("Contains localhost links"); }
424
+ // Check hardcoded secrets
425
+ if (/(password|secret|token|api_key)\\s*[:=]\\s*['"][^'"]{8,}/i.test(content)) { issues.push("Possible hardcoded secret"); }
426
+ // Check code blocks without language
427
+ const codeBlockPattern = /\`\`\`\\s*$/gm;
428
+ const matches = content.match(codeBlockPattern);
429
+ if (matches && matches.length > 0) { issues.push("Code blocks without language annotation"); }
430
+ if (issues.length > 0) { console.error("[WARN] G8-DocStandards: " + issues.join("; ")); }
431
+ console.log("[PASS]");
432
432
  process.exit(0);`,
433
433
  variables: []
434
434
  }
package/dist/index.d.ts CHANGED
@@ -61,7 +61,7 @@ export * from './memory/index.js';
61
61
  export { ModelRouter, DEFAULT_MODELS } from './routing/ModelRouter.js';
62
62
  export { PromptCachePolicy, resolvePromptCachePolicy, shouldCacheContextCategory } from './routing/PromptCachePolicy.js';
63
63
  export type { PromptCachePolicyInput, PromptCachePolicyOptions, PromptCachePolicyResult, PromptCacheCandidate, PromptCacheProvider } from './routing/PromptCachePolicy.js';
64
- export { ClaudeCodeAdapter, CodexAdapter, OpenCodeAdapter, CursorAdapter, GeminiAdapter, OpenClawAdapter, HermesAdapter, TraeAdapter, WorkBuddyAdapter, VSCAdapter, QCoderAdapter, DeepSeekTuiAdapter, createAdapter, SUPPORTED_AGENTS, } from './adapters/index.js';
64
+ export { ClaudeCodeAdapter, CodexAdapter, OpenCodeAdapter, CursorAdapter, GeminiAdapter, OpenClawAdapter, HermesAdapter, TraeAdapter, WorkBuddyAdapter, VSCAdapter, QCoderAdapter, DeepSeekTuiAdapter, AiderAdapter, WindsurfAdapter, KimiAdapter, DoubaoAdapter, KiroAdapter, QoderAdapter, JCodeAdapter, ClineAdapter, KiloCodeAdapter, AntigravityAdapter, createAdapter, SUPPORTED_AGENTS, } from './adapters/index.js';
65
65
  export type { IAgentAdapter, AdapterConfig, InitResult, SettingsJson, HookEntry } from './adapters/ClaudeCodeAdapter.js';
66
66
  export { OutOfScopeStore } from './workflow/OutOfScopeStore.js';
67
67
  export type { OutOfScopeEntry } from './workflow/OutOfScopeStore.js';
package/dist/index.js CHANGED
@@ -64,8 +64,8 @@ export * from './memory/index.js';
64
64
  // Routing
65
65
  export { ModelRouter, DEFAULT_MODELS } from './routing/ModelRouter.js';
66
66
  export { PromptCachePolicy, resolvePromptCachePolicy, shouldCacheContextCategory } from './routing/PromptCachePolicy.js';
67
- // Adapters (all 11 platforms)
68
- export { ClaudeCodeAdapter, CodexAdapter, OpenCodeAdapter, CursorAdapter, GeminiAdapter, OpenClawAdapter, HermesAdapter, TraeAdapter, WorkBuddyAdapter, VSCAdapter, QCoderAdapter, DeepSeekTuiAdapter, createAdapter, SUPPORTED_AGENTS, } from './adapters/index.js';
67
+ // Adapters
68
+ export { ClaudeCodeAdapter, CodexAdapter, OpenCodeAdapter, CursorAdapter, GeminiAdapter, OpenClawAdapter, HermesAdapter, TraeAdapter, WorkBuddyAdapter, VSCAdapter, QCoderAdapter, DeepSeekTuiAdapter, AiderAdapter, WindsurfAdapter, KimiAdapter, DoubaoAdapter, KiroAdapter, QoderAdapter, JCodeAdapter, ClineAdapter, KiloCodeAdapter, AntigravityAdapter, createAdapter, SUPPORTED_AGENTS, } from './adapters/index.js';
69
69
  // Out-of-Scope Knowledge Base
70
70
  export { OutOfScopeStore } from './workflow/OutOfScopeStore.js';
71
71
  // Workflow Presets
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,mCAAmC;AACnC,oEAAoE;AAEpE,aAAa;AACb,cAAc,qBAAqB,CAAA;AAEnC,MAAM;AACN,OAAO,EAAE,GAAG,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAA;AAEhD,4BAA4B;AAC5B,OAAO,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAA;AAGxD,iBAAiB;AACjB,OAAO,EAAE,qBAAqB,EAAE,MAAM,qBAAqB,CAAA;AAG3D,sBAAsB;AACtB,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAA;AAE7C,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAA;AACvE,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAA;AAEzC,cAAc;AACd,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAA;AAElD,iBAAiB;AACjB,OAAO,EAAE,aAAa,EAAE,MAAM,8BAA8B,CA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zD,OAAO,EAAE,sBAAsB,EAAE,MAAM,kCAAkC,CAAA;AAEzE,OAAO,EAAE,wBAAwB,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,MAAM,+BAA+B,CAAA;AAChH,cAAc,iCAAiC,CAAA;AAC/C,cAAc,8BAA8B,CAAA;AAC5C,cAAc,uBAAuB,CAAA;AACrC,cAAc,gCAAgC,CAAA;AAE9C,yDAAyD;AACzD,OAAO,EAAE,cAAc,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAA;AAGhF,2DAA2D;AAC3D,OAAO,EAAE,iBAAiB,EAAE,MAAM,gCAAgC,CAAA;AAElE,OAAO,EAAE,kBAAkB,EAAE,sBAAsB,EAAE,MAAM,gCAAgC,CAAA;AAE3F,uDAAuD;AACvD,OAAO,EAAE,mBAAmB,EAAE,yBAAyB,EAAE,MAAM,kCAAkC,CAAA;AAGjG,qBAAqB;AACrB,OAAO,EAAE,eAAe,EAAE,MAAM,gCAAgC,CAAA;AAGhE,MAAM;AACN,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAA;AACxC,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAA;AAE7C,mCAAmC;AACnC,OAAO,EAAE,oBAAoB,EAAE,MAAM,kCAAkC,CAAA;AAEvE,OAAO,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAA;AAE/D,OAAO,EAAE,mBAAmB,EAAE,MAAM,iCAAiC,CAAA"}
@@ -6,28 +6,28 @@ import { TfidfIndex } from './TfidfIndex.js';
6
6
  import { logger } from '../core/logger.js';
7
7
  import { mkdirSync } from 'node:fs';
8
8
  import { dirname } from 'node:path';
9
- const KB_SCHEMA = `
10
- CREATE TABLE IF NOT EXISTS knowledge_entries (
11
- id TEXT PRIMARY KEY,
12
- type TEXT NOT NULL,
13
- title TEXT NOT NULL,
14
- tags TEXT NOT NULL DEFAULT '[]',
15
- content_ref TEXT NOT NULL DEFAULT '',
16
- embedding_id TEXT,
17
- relevance REAL NOT NULL DEFAULT 0.5,
18
- access_count INTEGER NOT NULL DEFAULT 0,
19
- last_accessed INTEGER,
20
- verified INTEGER NOT NULL DEFAULT 0,
21
- verified_by TEXT,
22
- verified_at INTEGER,
23
- created_at INTEGER NOT NULL,
24
- source_artifact TEXT
25
- );
26
-
27
- CREATE INDEX IF NOT EXISTS idx_kb_type ON knowledge_entries(type);
28
- CREATE INDEX IF NOT EXISTS idx_kb_relevance ON knowledge_entries(relevance);
29
- CREATE INDEX IF NOT EXISTS idx_kb_verified ON knowledge_entries(verified);
30
- CREATE INDEX IF NOT EXISTS idx_kb_created ON knowledge_entries(created_at);
9
+ const KB_SCHEMA = `
10
+ CREATE TABLE IF NOT EXISTS knowledge_entries (
11
+ id TEXT PRIMARY KEY,
12
+ type TEXT NOT NULL,
13
+ title TEXT NOT NULL,
14
+ tags TEXT NOT NULL DEFAULT '[]',
15
+ content_ref TEXT NOT NULL DEFAULT '',
16
+ embedding_id TEXT,
17
+ relevance REAL NOT NULL DEFAULT 0.5,
18
+ access_count INTEGER NOT NULL DEFAULT 0,
19
+ last_accessed INTEGER,
20
+ verified INTEGER NOT NULL DEFAULT 0,
21
+ verified_by TEXT,
22
+ verified_at INTEGER,
23
+ created_at INTEGER NOT NULL,
24
+ source_artifact TEXT
25
+ );
26
+
27
+ CREATE INDEX IF NOT EXISTS idx_kb_type ON knowledge_entries(type);
28
+ CREATE INDEX IF NOT EXISTS idx_kb_relevance ON knowledge_entries(relevance);
29
+ CREATE INDEX IF NOT EXISTS idx_kb_verified ON knowledge_entries(verified);
30
+ CREATE INDEX IF NOT EXISTS idx_kb_created ON knowledge_entries(created_at);
31
31
  `;
32
32
  export class SQLiteKnowledgeBase {
33
33
  constructor(eventBus, opts = {}) {
@@ -55,12 +55,12 @@ export class SQLiteKnowledgeBase {
55
55
  accessCount: 0,
56
56
  relevance: 0.5,
57
57
  };
58
- this.db.prepare(`
59
- INSERT INTO knowledge_entries
60
- (id, type, title, tags, content_ref, embedding_id, relevance,
61
- access_count, last_accessed, verified, verified_by, verified_at,
62
- created_at, source_artifact)
63
- VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
58
+ this.db.prepare(`
59
+ INSERT INTO knowledge_entries
60
+ (id, type, title, tags, content_ref, embedding_id, relevance,
61
+ access_count, last_accessed, verified, verified_by, verified_at,
62
+ created_at, source_artifact)
63
+ VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
64
64
  `).run(entry.id, entry.type, entry.title, JSON.stringify(entry.tags), entry.contentRef, entry.embeddingId ?? null, entry.relevance, entry.accessCount, entry.lastAccessed ?? null, entry.verified ? 1 : 0, entry.verifiedBy ?? null, entry.verifiedAt ?? null, entry.createdAt, entry.sourceArtifact ?? null);
65
65
  this.eventBus.emit('lesson.proposed', { lessonId: entry.id }, { artifactId: input.sourceArtifact });
66
66
  // Update TF-IDF index
@@ -126,6 +126,7 @@ export declare class MemoryBrain {
126
126
  scope?: MemoryNodeScope;
127
127
  }): MemoryNode[];
128
128
  get(id: string): MemoryNode | null;
129
+ close(): void;
129
130
  private ingestEvidence;
130
131
  private ingestCandidate;
131
132
  private ingestFailureReplay;