@hivehub/rulebook 5.5.1 → 5.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude/commands/rulebook-learn-capture.md +41 -48
- package/.claude/commands/rulebook-learn-list.md +13 -13
- package/README.md +332 -394
- package/dist/cli/commands/context-intelligence.d.ts +0 -1
- package/dist/cli/commands/context-intelligence.d.ts.map +1 -1
- package/dist/cli/commands/context-intelligence.js +12 -33
- package/dist/cli/commands/context-intelligence.js.map +1 -1
- package/dist/cli/commands/index.d.ts +4 -7
- package/dist/cli/commands/index.d.ts.map +1 -1
- package/dist/cli/commands/index.js +4 -7
- package/dist/cli/commands/index.js.map +1 -1
- package/dist/cli/commands/init.d.ts.map +1 -1
- package/dist/cli/commands/init.js +40 -81
- package/dist/cli/commands/init.js.map +1 -1
- package/dist/cli/commands/mcp.d.ts +0 -1
- package/dist/cli/commands/mcp.d.ts.map +1 -1
- package/dist/cli/commands/mcp.js +1 -7
- package/dist/cli/commands/mcp.js.map +1 -1
- package/dist/cli/commands/memory.d.ts +7 -1
- package/dist/cli/commands/memory.d.ts.map +1 -1
- package/dist/cli/commands/memory.js +51 -57
- package/dist/cli/commands/memory.js.map +1 -1
- package/dist/cli/commands/misc.d.ts +1 -15
- package/dist/cli/commands/misc.d.ts.map +1 -1
- package/dist/cli/commands/misc.js +36 -215
- package/dist/cli/commands/misc.js.map +1 -1
- package/dist/cli/commands/plans.d.ts +0 -6
- package/dist/cli/commands/plans.d.ts.map +1 -1
- package/dist/cli/commands/plans.js +9 -77
- package/dist/cli/commands/plans.js.map +1 -1
- package/dist/cli/commands/skills.js +6 -6
- package/dist/cli/commands/skills.js.map +1 -1
- package/dist/cli/commands/task.js +4 -4
- package/dist/cli/commands/task.js.map +1 -1
- package/dist/cli/commands/update.d.ts.map +1 -1
- package/dist/cli/commands/update.js +122 -52
- package/dist/cli/commands/update.js.map +1 -1
- package/dist/cli/prompts.d.ts.map +1 -1
- package/dist/cli/prompts.js +1 -78
- package/dist/cli/prompts.js.map +1 -1
- package/dist/core/claude/claude-mcp.d.ts +59 -0
- package/dist/core/claude/claude-mcp.d.ts.map +1 -0
- package/dist/core/claude/claude-mcp.js +220 -0
- package/dist/core/claude/claude-mcp.js.map +1 -0
- package/dist/core/claude/claude-md-generator.d.ts +52 -0
- package/dist/core/claude/claude-md-generator.d.ts.map +1 -0
- package/dist/core/claude/claude-md-generator.js +104 -0
- package/dist/core/claude/claude-md-generator.js.map +1 -0
- package/dist/core/claude/claude-settings-manager.d.ts +44 -0
- package/dist/core/claude/claude-settings-manager.d.ts.map +1 -0
- package/dist/core/claude/claude-settings-manager.js +194 -0
- package/dist/core/claude/claude-settings-manager.js.map +1 -0
- package/dist/core/claude-settings-manager.d.ts.map +1 -1
- package/dist/core/claude-settings-manager.js +9 -3
- package/dist/core/claude-settings-manager.js.map +1 -1
- package/dist/core/console/cli-bridge.d.ts +113 -0
- package/dist/core/console/cli-bridge.d.ts.map +1 -0
- package/dist/core/console/cli-bridge.js +1094 -0
- package/dist/core/console/cli-bridge.js.map +1 -0
- package/dist/core/detect/detector.d.ts +35 -0
- package/dist/core/detect/detector.d.ts.map +1 -0
- package/dist/core/detect/detector.js +541 -0
- package/dist/core/detect/detector.js.map +1 -0
- package/dist/core/docs/docs-generator.d.ts +9 -0
- package/dist/core/docs/docs-generator.d.ts.map +1 -0
- package/dist/core/docs/docs-generator.js +531 -0
- package/dist/core/docs/docs-generator.js.map +1 -0
- package/dist/core/docs/mcp-reference-generator.d.ts +13 -0
- package/dist/core/docs/mcp-reference-generator.d.ts.map +1 -0
- package/dist/core/docs/mcp-reference-generator.js +66 -0
- package/dist/core/docs/mcp-reference-generator.js.map +1 -0
- package/dist/core/generators/generator.d.ts +54 -0
- package/dist/core/generators/generator.d.ts.map +1 -0
- package/dist/core/generators/generator.js +1041 -0
- package/dist/core/generators/generator.js.map +1 -0
- package/dist/core/generators/gitignore-generator.d.ts +13 -0
- package/dist/core/generators/gitignore-generator.d.ts.map +1 -0
- package/dist/core/generators/gitignore-generator.js +307 -0
- package/dist/core/generators/gitignore-generator.js.map +1 -0
- package/dist/core/generators/minimal-scaffolder.d.ts +8 -0
- package/dist/core/generators/minimal-scaffolder.d.ts.map +1 -0
- package/dist/core/generators/minimal-scaffolder.js +51 -0
- package/dist/core/generators/minimal-scaffolder.js.map +1 -0
- package/dist/core/generators/rules-generator.d.ts +73 -0
- package/dist/core/generators/rules-generator.d.ts.map +1 -0
- package/dist/core/generators/rules-generator.js +202 -0
- package/dist/core/generators/rules-generator.js.map +1 -0
- package/dist/core/generators/workflow-generator.d.ts +15 -0
- package/dist/core/generators/workflow-generator.d.ts.map +1 -0
- package/dist/core/generators/workflow-generator.js +390 -0
- package/dist/core/generators/workflow-generator.js.map +1 -0
- package/dist/core/ide/multi-tool-generator.d.ts +59 -0
- package/dist/core/ide/multi-tool-generator.d.ts.map +1 -0
- package/dist/core/ide/multi-tool-generator.js +157 -0
- package/dist/core/ide/multi-tool-generator.js.map +1 -0
- package/dist/core/ide/opencode-generator.d.ts +72 -0
- package/dist/core/ide/opencode-generator.d.ts.map +1 -0
- package/dist/core/ide/opencode-generator.js +450 -0
- package/dist/core/ide/opencode-generator.js.map +1 -0
- package/dist/core/merger.d.ts +1 -1
- package/dist/core/merger.d.ts.map +1 -1
- package/dist/core/merger.js +5 -5
- package/dist/core/merger.js.map +1 -1
- package/dist/core/migrator.d.ts +0 -1
- package/dist/core/migrator.d.ts.map +1 -1
- package/dist/core/migrator.js +4 -29
- package/dist/core/migrator.js.map +1 -1
- package/dist/core/quality/coverage-checker.d.ts +14 -0
- package/dist/core/quality/coverage-checker.d.ts.map +1 -0
- package/dist/core/quality/coverage-checker.js +176 -0
- package/dist/core/quality/coverage-checker.js.map +1 -0
- package/dist/core/quality/dependency-checker.d.ts +21 -0
- package/dist/core/quality/dependency-checker.d.ts.map +1 -0
- package/dist/core/quality/dependency-checker.js +247 -0
- package/dist/core/quality/dependency-checker.js.map +1 -0
- package/dist/core/quality/doctor.d.ts +19 -0
- package/dist/core/quality/doctor.d.ts.map +1 -0
- package/dist/core/quality/doctor.js +163 -0
- package/dist/core/quality/doctor.js.map +1 -0
- package/dist/core/quality/validator.d.ts +21 -0
- package/dist/core/quality/validator.d.ts.map +1 -0
- package/dist/core/quality/validator.js +177 -0
- package/dist/core/quality/validator.js.map +1 -0
- package/dist/core/ralph-scripts.d.ts.map +1 -1
- package/dist/core/ralph-scripts.js +7 -6
- package/dist/core/ralph-scripts.js.map +1 -1
- package/dist/core/skills/skills-manager.d.ts +126 -0
- package/dist/core/skills/skills-manager.d.ts.map +1 -0
- package/dist/core/skills/skills-manager.js +630 -0
- package/dist/core/skills/skills-manager.js.map +1 -0
- package/dist/core/state/config-manager.d.ts +86 -0
- package/dist/core/state/config-manager.d.ts.map +1 -0
- package/dist/core/state/config-manager.js +562 -0
- package/dist/core/state/config-manager.js.map +1 -0
- package/dist/core/state/override-manager.d.ts +23 -0
- package/dist/core/state/override-manager.d.ts.map +1 -0
- package/dist/core/state/override-manager.js +82 -0
- package/dist/core/state/override-manager.js.map +1 -0
- package/dist/core/state/state-writer.d.ts +34 -0
- package/dist/core/state/state-writer.d.ts.map +1 -0
- package/dist/core/state/state-writer.js +78 -0
- package/dist/core/state/state-writer.js.map +1 -0
- package/dist/core/state/version-bumper.d.ts +19 -0
- package/dist/core/state/version-bumper.d.ts.map +1 -0
- package/dist/core/state/version-bumper.js +180 -0
- package/dist/core/state/version-bumper.js.map +1 -0
- package/dist/core/tasks/decision-manager.d.ts +25 -0
- package/dist/core/tasks/decision-manager.d.ts.map +1 -0
- package/dist/core/tasks/decision-manager.js +183 -0
- package/dist/core/tasks/decision-manager.js.map +1 -0
- package/dist/core/tasks/knowledge-manager.d.ts +24 -0
- package/dist/core/tasks/knowledge-manager.d.ts.map +1 -0
- package/dist/core/tasks/knowledge-manager.js +173 -0
- package/dist/core/tasks/knowledge-manager.js.map +1 -0
- package/dist/core/tasks/learn-manager.d.ts +27 -0
- package/dist/core/tasks/learn-manager.d.ts.map +1 -0
- package/dist/core/tasks/learn-manager.js +121 -0
- package/dist/core/tasks/learn-manager.js.map +1 -0
- package/dist/core/tasks/plans-manager.d.ts +46 -0
- package/dist/core/tasks/plans-manager.d.ts.map +1 -0
- package/dist/core/tasks/plans-manager.js +158 -0
- package/dist/core/tasks/plans-manager.js.map +1 -0
- package/dist/core/tasks/task-manager.d.ts +127 -0
- package/dist/core/tasks/task-manager.d.ts.map +1 -0
- package/dist/core/tasks/task-manager.js +607 -0
- package/dist/core/tasks/task-manager.js.map +1 -0
- package/dist/core/workspace/project-worker.d.ts +6 -6
- package/dist/core/workspace/project-worker.d.ts.map +1 -1
- package/dist/core/workspace/project-worker.js +6 -6
- package/dist/core/workspace/project-worker.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +19 -176
- package/dist/index.js.map +1 -1
- package/dist/mcp/rulebook-server.d.ts.map +1 -1
- package/dist/mcp/rulebook-server.js +16 -960
- package/dist/mcp/rulebook-server.js.map +1 -1
- package/dist/memory/file-search.d.ts +43 -0
- package/dist/memory/file-search.d.ts.map +1 -0
- package/dist/memory/file-search.js +228 -0
- package/dist/memory/file-search.js.map +1 -0
- package/dist/memory/file-store.d.ts +99 -0
- package/dist/memory/file-store.d.ts.map +1 -0
- package/dist/memory/file-store.js +615 -0
- package/dist/memory/file-store.js.map +1 -0
- package/dist/memory/legacy-migrator.d.ts +27 -0
- package/dist/memory/legacy-migrator.d.ts.map +1 -0
- package/dist/memory/legacy-migrator.js +185 -0
- package/dist/memory/legacy-migrator.js.map +1 -0
- package/dist/memory/memory-manager.d.ts +25 -24
- package/dist/memory/memory-manager.d.ts.map +1 -1
- package/dist/memory/memory-manager.js +97 -140
- package/dist/memory/memory-manager.js.map +1 -1
- package/dist/memory/memory-types.d.ts +1 -1
- package/dist/memory/memory-types.d.ts.map +1 -1
- package/dist/types.d.ts +8 -119
- package/dist/types.d.ts.map +1 -1
- package/dist/utils/file-system.d.ts +22 -0
- package/dist/utils/file-system.d.ts.map +1 -1
- package/dist/utils/file-system.js +31 -0
- package/dist/utils/file-system.js.map +1 -1
- package/dist/utils/git-hooks.d.ts.map +1 -1
- package/dist/utils/git-hooks.js +3 -2
- package/dist/utils/git-hooks.js.map +1 -1
- package/package.json +2 -6
- package/templates/agents/context-intelligence.md +50 -52
- package/templates/cli/OPENCODE.md +85 -18
- package/templates/commands/rulebook-learn-capture.md +41 -48
- package/templates/commands/rulebook-learn-list.md +13 -13
- package/templates/core/AGENTS_LEAN.md +0 -14
- package/templates/hooks/check-context-and-handoff.sh +74 -76
- package/templates/hooks/enforce-pre-tool.sh +70 -0
- package/templates/hooks/enforce-team-for-background-agents.sh +55 -55
- package/templates/hooks/on-compact-reinject.sh +34 -34
- package/templates/hooks/resume-from-handoff.sh +61 -61
- package/templates/hooks/terse-activate.sh +197 -197
- package/templates/hooks/terse-mode-tracker.sh +190 -187
- package/templates/ides/OPENCODE.md +63 -0
- package/templates/skills/cli/opencode/SKILL.md +82 -28
- package/.claude/commands/ralph-config.md +0 -112
- package/.claude/commands/ralph-history.md +0 -110
- package/.claude/commands/ralph-init.md +0 -72
- package/.claude/commands/ralph-pause-resume.md +0 -105
- package/.claude/commands/ralph-run.md +0 -101
- package/.claude/commands/ralph-status.md +0 -76
- package/templates/core/RALPH.md +0 -471
- package/templates/frameworks/ANGULAR.md +0 -36
- package/templates/frameworks/DJANGO.md +0 -83
- package/templates/frameworks/ELECTRON.md +0 -147
- package/templates/frameworks/FLASK.md +0 -38
- package/templates/frameworks/FLUTTER.md +0 -55
- package/templates/frameworks/JQUERY.md +0 -32
- package/templates/frameworks/LARAVEL.md +0 -38
- package/templates/frameworks/NESTJS.md +0 -43
- package/templates/frameworks/NEXTJS.md +0 -127
- package/templates/frameworks/NUXT.md +0 -40
- package/templates/frameworks/RAILS.md +0 -66
- package/templates/frameworks/REACT.md +0 -38
- package/templates/frameworks/REACT_NATIVE.md +0 -47
- package/templates/frameworks/SPRING.md +0 -39
- package/templates/frameworks/SYMFONY.md +0 -36
- package/templates/frameworks/VUE.md +0 -36
- package/templates/frameworks/ZEND.md +0 -35
- package/templates/hooks/enforce-mcp-for-tasks.sh +0 -31
- package/templates/hooks/enforce-no-deferred.sh +0 -21
- package/templates/hooks/enforce-no-shortcuts.sh +0 -31
- package/templates/ides/COPILOT.md +0 -37
- package/templates/ides/CURSOR.md +0 -43
- package/templates/ides/JETBRAINS_AI.md +0 -35
- package/templates/ides/REPLIT.md +0 -36
- package/templates/ides/TABNINE.md +0 -29
- package/templates/ides/VSCODE.md +0 -40
- package/templates/ides/WINDSURF.md +0 -36
- package/templates/ides/ZED.md +0 -32
- package/templates/ides/cursor-mdc/go.mdc +0 -24
- package/templates/ides/cursor-mdc/python.mdc +0 -24
- package/templates/ides/cursor-mdc/quality.mdc +0 -25
- package/templates/ides/cursor-mdc/ralph.mdc +0 -39
- package/templates/ides/cursor-mdc/rulebook.mdc +0 -38
- package/templates/ides/cursor-mdc/rust.mdc +0 -24
- package/templates/ides/cursor-mdc/typescript.mdc +0 -25
- package/templates/ralph/ralph-history.bat +0 -4
- package/templates/ralph/ralph-history.sh +0 -5
- package/templates/ralph/ralph-init.bat +0 -5
- package/templates/ralph/ralph-init.sh +0 -5
- package/templates/ralph/ralph-pause.bat +0 -5
- package/templates/ralph/ralph-pause.sh +0 -5
- package/templates/ralph/ralph-run.bat +0 -5
- package/templates/ralph/ralph-run.sh +0 -5
- package/templates/ralph/ralph-status.bat +0 -4
- package/templates/ralph/ralph-status.sh +0 -5
- package/templates/services/AZURE_BLOB.md +0 -184
- package/templates/services/CASSANDRA.md +0 -239
- package/templates/services/DATADOG.md +0 -26
- package/templates/services/DOCKER.md +0 -124
- package/templates/services/DOCKER_COMPOSE.md +0 -168
- package/templates/services/DYNAMODB.md +0 -308
- package/templates/services/ELASTICSEARCH.md +0 -347
- package/templates/services/GCS.md +0 -178
- package/templates/services/HELM.md +0 -194
- package/templates/services/INFLUXDB.md +0 -265
- package/templates/services/KAFKA.md +0 -341
- package/templates/services/KUBERNETES.md +0 -208
- package/templates/services/MARIADB.md +0 -183
- package/templates/services/MEMCACHED.md +0 -242
- package/templates/services/MINIO.md +0 -201
- package/templates/services/MONGODB.md +0 -268
- package/templates/services/MYSQL.md +0 -358
- package/templates/services/NEO4J.md +0 -247
- package/templates/services/OPENTELEMETRY.md +0 -25
- package/templates/services/ORACLE.md +0 -290
- package/templates/services/PINO.md +0 -24
- package/templates/services/POSTGRESQL.md +0 -326
- package/templates/services/PROMETHEUS.md +0 -33
- package/templates/services/RABBITMQ.md +0 -286
- package/templates/services/REDIS.md +0 -292
- package/templates/services/S3.md +0 -298
- package/templates/services/SENTRY.md +0 -23
- package/templates/services/SQLITE.md +0 -294
- package/templates/services/SQLSERVER.md +0 -294
- package/templates/services/WINSTON.md +0 -30
- package/templates/skills/frameworks/angular/SKILL.md +0 -46
- package/templates/skills/frameworks/django/SKILL.md +0 -93
- package/templates/skills/frameworks/electron/SKILL.md +0 -157
- package/templates/skills/frameworks/flask/SKILL.md +0 -48
- package/templates/skills/frameworks/flutter/SKILL.md +0 -65
- package/templates/skills/frameworks/jquery/SKILL.md +0 -42
- package/templates/skills/frameworks/laravel/SKILL.md +0 -48
- package/templates/skills/frameworks/nestjs/SKILL.md +0 -53
- package/templates/skills/frameworks/nextjs/SKILL.md +0 -137
- package/templates/skills/frameworks/nuxt/SKILL.md +0 -50
- package/templates/skills/frameworks/rails/SKILL.md +0 -76
- package/templates/skills/frameworks/react/SKILL.md +0 -48
- package/templates/skills/frameworks/react-native/SKILL.md +0 -57
- package/templates/skills/frameworks/spring/SKILL.md +0 -49
- package/templates/skills/frameworks/symfony/SKILL.md +0 -46
- package/templates/skills/frameworks/vue/SKILL.md +0 -46
- package/templates/skills/frameworks/zend/SKILL.md +0 -45
- package/templates/skills/services/azure-blob/SKILL.md +0 -194
- package/templates/skills/services/cassandra/SKILL.md +0 -249
- package/templates/skills/services/dynamodb/SKILL.md +0 -318
- package/templates/skills/services/elasticsearch/SKILL.md +0 -357
- package/templates/skills/services/gcs/SKILL.md +0 -188
- package/templates/skills/services/influxdb/SKILL.md +0 -275
- package/templates/skills/services/kafka/SKILL.md +0 -351
- package/templates/skills/services/mariadb/SKILL.md +0 -193
- package/templates/skills/services/memcached/SKILL.md +0 -252
- package/templates/skills/services/minio/SKILL.md +0 -211
- package/templates/skills/services/mongodb/SKILL.md +0 -278
- package/templates/skills/services/mysql/SKILL.md +0 -368
- package/templates/skills/services/neo4j/SKILL.md +0 -257
- package/templates/skills/services/oracle/SKILL.md +0 -300
- package/templates/skills/services/postgresql/SKILL.md +0 -336
- package/templates/skills/services/rabbitmq/SKILL.md +0 -296
- package/templates/skills/services/redis/SKILL.md +0 -302
- package/templates/skills/services/s3/SKILL.md +0 -308
- package/templates/skills/services/sqlite/SKILL.md +0 -304
- package/templates/skills/services/sqlserver/SKILL.md +0 -304
- package/templates/skills/workflows/ralph/SETUP.md +0 -228
- package/templates/skills/workflows/ralph/SKILL.md +0 -309
- package/templates/skills/workflows/ralph/install.sh +0 -87
- package/templates/skills/workflows/ralph/manifest.json +0 -158
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"legacy-migrator.d.ts","sourceRoot":"","sources":["../../src/memory/legacy-migrator.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAGH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAGjD,UAAU,cAAc;IACtB,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;CAClB;AAqHD;;;;GAIG;AACH,wBAAsB,eAAe,CACnC,MAAM,EAAE,MAAM,EACd,SAAS,EAAE,SAAS,GACnB,OAAO,CAAC,cAAc,CAAC,CAmDzB"}
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* One-shot legacy SQLite → markdown migrator.
|
|
3
|
+
*
|
|
4
|
+
* Lazily imported only when an existing `memory.db` is detected on the
|
|
5
|
+
* first `MemoryManager.initialize()`. Reads memories + sessions from the
|
|
6
|
+
* legacy DB (using `better-sqlite3` if available, otherwise `sql.js` as a
|
|
7
|
+
* fallback) and writes one markdown file per row via `FileStore`.
|
|
8
|
+
*
|
|
9
|
+
* After the manager renames `memory.db` → `memory.db.legacy` neither
|
|
10
|
+
* sql.js nor better-sqlite3 is loaded again at runtime. The migrator
|
|
11
|
+
* itself isolates those imports inside try-blocks so a missing native
|
|
12
|
+
* binary is non-fatal — the user keeps the markdown migration that
|
|
13
|
+
* already succeeded for the rows the fallback could read.
|
|
14
|
+
*/
|
|
15
|
+
import { existsSync, readFileSync } from 'fs';
|
|
16
|
+
async function openDb(dbPath) {
|
|
17
|
+
try {
|
|
18
|
+
// better-sqlite3 is an optional native dep — keep the import indirect so
|
|
19
|
+
// tsc does not require its type declarations when the package is absent
|
|
20
|
+
// (matches the sql.js pattern below).
|
|
21
|
+
const moduleName = 'better-sqlite3';
|
|
22
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
23
|
+
const mod = await import(moduleName);
|
|
24
|
+
const Database = mod.default ?? mod;
|
|
25
|
+
const db = new Database(dbPath, { readonly: true });
|
|
26
|
+
return db;
|
|
27
|
+
}
|
|
28
|
+
catch {
|
|
29
|
+
// Fall through to sql.js
|
|
30
|
+
}
|
|
31
|
+
try {
|
|
32
|
+
// sql.js is deprecated as a runtime dep in v5.6 (file-based store).
|
|
33
|
+
// It is only used by the legacy migrator and only when the user has it
|
|
34
|
+
// installed locally. Indirect dynamic import keeps the TS compile clean
|
|
35
|
+
// even when the package is absent from node_modules.
|
|
36
|
+
const moduleName = 'sql.js';
|
|
37
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
38
|
+
const sqlMod = await import(moduleName);
|
|
39
|
+
const initSqlJs = sqlMod.default ?? sqlMod;
|
|
40
|
+
const SQL = await initSqlJs();
|
|
41
|
+
if (!existsSync(dbPath))
|
|
42
|
+
return null;
|
|
43
|
+
const raw = new SQL.Database(readFileSync(dbPath));
|
|
44
|
+
return {
|
|
45
|
+
prepare: (sql) => ({
|
|
46
|
+
all: (...params) => {
|
|
47
|
+
let processed = sql;
|
|
48
|
+
for (const p of params) {
|
|
49
|
+
if (p === null || p === undefined)
|
|
50
|
+
processed = processed.replace('?', 'NULL');
|
|
51
|
+
else if (typeof p === 'string')
|
|
52
|
+
processed = processed.replace('?', `'${p.replace(/'/g, "''")}'`);
|
|
53
|
+
else
|
|
54
|
+
processed = processed.replace('?', String(p));
|
|
55
|
+
}
|
|
56
|
+
const result = raw.exec(processed);
|
|
57
|
+
if (!result.length)
|
|
58
|
+
return [];
|
|
59
|
+
const cols = result[0].columns;
|
|
60
|
+
return result[0].values.map((row) => {
|
|
61
|
+
const obj = {};
|
|
62
|
+
cols.forEach((c, i) => {
|
|
63
|
+
obj[c] = row[i];
|
|
64
|
+
});
|
|
65
|
+
return obj;
|
|
66
|
+
});
|
|
67
|
+
},
|
|
68
|
+
}),
|
|
69
|
+
close: () => raw.close(),
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
catch {
|
|
73
|
+
return null;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
const KNOWN_TYPES = new Set([
|
|
77
|
+
'bugfix',
|
|
78
|
+
'feature',
|
|
79
|
+
'refactor',
|
|
80
|
+
'decision',
|
|
81
|
+
'discovery',
|
|
82
|
+
'change',
|
|
83
|
+
'observation',
|
|
84
|
+
]);
|
|
85
|
+
function rowToMemory(row) {
|
|
86
|
+
const id = typeof row.id === 'string' ? row.id : null;
|
|
87
|
+
const rawType = typeof row.type === 'string' ? row.type : 'observation';
|
|
88
|
+
const type = (KNOWN_TYPES.has(rawType) ? rawType : 'observation');
|
|
89
|
+
const title = typeof row.title === 'string' ? row.title : null;
|
|
90
|
+
if (!id || !title)
|
|
91
|
+
return null;
|
|
92
|
+
let tags = [];
|
|
93
|
+
try {
|
|
94
|
+
if (typeof row.tags === 'string')
|
|
95
|
+
tags = JSON.parse(row.tags);
|
|
96
|
+
}
|
|
97
|
+
catch {
|
|
98
|
+
tags = [];
|
|
99
|
+
}
|
|
100
|
+
return {
|
|
101
|
+
id,
|
|
102
|
+
type,
|
|
103
|
+
title,
|
|
104
|
+
summary: typeof row.summary === 'string' ? row.summary : undefined,
|
|
105
|
+
content: typeof row.content === 'string' ? row.content : '',
|
|
106
|
+
project: typeof row.project === 'string' ? row.project : '',
|
|
107
|
+
tags,
|
|
108
|
+
sessionId: typeof row.session_id === 'string' ? row.session_id : undefined,
|
|
109
|
+
createdAt: typeof row.created_at === 'number' ? row.created_at : Date.now(),
|
|
110
|
+
updatedAt: typeof row.updated_at === 'number' ? row.updated_at : Date.now(),
|
|
111
|
+
accessedAt: typeof row.accessed_at === 'number' ? row.accessed_at : Date.now(),
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
function rowToSession(row) {
|
|
115
|
+
const id = typeof row.id === 'string' ? row.id : null;
|
|
116
|
+
const startedAt = typeof row.started_at === 'number' ? row.started_at : null;
|
|
117
|
+
if (!id || startedAt === null)
|
|
118
|
+
return null;
|
|
119
|
+
const status = row.status === 'completed' ? 'completed' : 'active';
|
|
120
|
+
return {
|
|
121
|
+
id,
|
|
122
|
+
project: typeof row.project === 'string' ? row.project : '',
|
|
123
|
+
status,
|
|
124
|
+
startedAt,
|
|
125
|
+
endedAt: typeof row.ended_at === 'number' ? row.ended_at : undefined,
|
|
126
|
+
summary: typeof row.summary === 'string' ? row.summary : undefined,
|
|
127
|
+
toolCalls: typeof row.tool_calls === 'number' ? row.tool_calls : 0,
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Migrate every row of a legacy memory.db into the file-based store.
|
|
132
|
+
* Idempotent against the FileStore: if a memory id already exists on disk
|
|
133
|
+
* it is overwritten with the legacy content (same id → same partition).
|
|
134
|
+
*/
|
|
135
|
+
export async function migrateLegacyDb(dbPath, fileStore) {
|
|
136
|
+
if (!existsSync(dbPath))
|
|
137
|
+
return { memories: 0, sessions: 0 };
|
|
138
|
+
const db = await openDb(dbPath);
|
|
139
|
+
if (!db)
|
|
140
|
+
return { memories: 0, sessions: 0 };
|
|
141
|
+
let memories = 0;
|
|
142
|
+
let sessions = 0;
|
|
143
|
+
try {
|
|
144
|
+
const memoryRows = db
|
|
145
|
+
.prepare(`SELECT id, type, title, content, project, tags, session_id, created_at, updated_at, accessed_at
|
|
146
|
+
FROM memories`)
|
|
147
|
+
.all();
|
|
148
|
+
for (const row of memoryRows) {
|
|
149
|
+
const m = rowToMemory(row);
|
|
150
|
+
if (!m)
|
|
151
|
+
continue;
|
|
152
|
+
await fileStore.saveMemory(m);
|
|
153
|
+
memories++;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
catch {
|
|
157
|
+
// memories table may not exist on partial DBs
|
|
158
|
+
}
|
|
159
|
+
try {
|
|
160
|
+
const sessionRows = db
|
|
161
|
+
.prepare(`SELECT id, project, status, started_at, ended_at, summary, tool_calls
|
|
162
|
+
FROM sessions`)
|
|
163
|
+
.all();
|
|
164
|
+
for (const row of sessionRows) {
|
|
165
|
+
const s = rowToSession(row);
|
|
166
|
+
if (!s)
|
|
167
|
+
continue;
|
|
168
|
+
await fileStore.saveSession(s);
|
|
169
|
+
sessions++;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
catch {
|
|
173
|
+
// sessions table may not exist
|
|
174
|
+
}
|
|
175
|
+
if (db.close) {
|
|
176
|
+
try {
|
|
177
|
+
db.close();
|
|
178
|
+
}
|
|
179
|
+
catch {
|
|
180
|
+
// ignore
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
return { memories, sessions };
|
|
184
|
+
}
|
|
185
|
+
//# sourceMappingURL=legacy-migrator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"legacy-migrator.js","sourceRoot":"","sources":["../../src/memory/legacy-migrator.ts"],"names":[],"mappings":"AA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,EAAoC,CAAC;QAC3C,KAAK,MAAM,GAAG,IAAI,WAAW,EAAE,CAAC;YAC9B,MAAM,CAAC,GAAG,YAAY,CAAC,GAAG,CAAC,CAAC;YAC5B,IAAI,CAAC,CAAC;gBAAE,SAAS;YACjB,MAAM,SAAS,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC;YAC/B,QAAQ,EAAE,CAAC;QACb,CAAC;IACH,CAAC;IAAC,MAAM,CAAC;QACP,+BAA+B;IACjC,CAAC;IAED,IAAI,EAAE,CAAC,KAAK,EAAE,CAAC;QACb,IAAI,CAAC;YACH,EAAE,CAAC,KAAK,EAAE,CAAC;QACb,CAAC;QAAC,MAAM,CAAC;YACP,SAAS;QACX,CAAC;IACH,CAAC;IAED,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,CAAC;AAChC,CAAC"}
|
|
@@ -1,35 +1,33 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Memory Manager -
|
|
2
|
+
* Memory Manager - File-backed orchestrator (v5.6).
|
|
3
3
|
*
|
|
4
|
-
* Public API
|
|
5
|
-
*
|
|
6
|
-
*
|
|
4
|
+
* Public API kept stable for callers (saveMemory, searchMemories,
|
|
5
|
+
* getTimeline, getFullDetails, startSession, endSession, getStats,
|
|
6
|
+
* cleanup, exportMemories, plus the indexer code-graph methods).
|
|
7
|
+
*
|
|
8
|
+
* Internally uses the FileStore + FileSearch implementations under
|
|
9
|
+
* `.rulebook/memory/{memories,sessions,codegraph}/...` instead of
|
|
10
|
+
* SQLite + HNSW. On startup, an existing legacy `memory.db` is
|
|
11
|
+
* auto-detected and migrated to markdown one time, then renamed to
|
|
12
|
+
* `memory.db.legacy`.
|
|
7
13
|
*/
|
|
8
14
|
import type { Memory, MemoryConfig, MemorySearchOptions, MemorySearchResult, MemorySession, MemoryStats, MemoryType, TimelineEntry } from './memory-types.js';
|
|
15
|
+
import type { CodeNode, CodeEdge } from '../core/indexer/indexer-types.js';
|
|
9
16
|
export declare class MemoryManager {
|
|
10
17
|
private store;
|
|
11
|
-
private index;
|
|
12
18
|
private search;
|
|
13
|
-
private cache;
|
|
14
19
|
private initialized;
|
|
15
|
-
private
|
|
16
|
-
|
|
17
|
-
private readonly
|
|
20
|
+
private migrated;
|
|
21
|
+
/** Resolved root for the file-based store (sibling of legacy `memory.db`). */
|
|
22
|
+
private readonly memoryRoot;
|
|
23
|
+
/** Path to the legacy DB file, used for one-shot migration on first init. */
|
|
24
|
+
private readonly legacyDbPath;
|
|
18
25
|
private readonly maxSizeBytes;
|
|
19
|
-
private readonly dimensions;
|
|
20
|
-
private saveCount;
|
|
21
|
-
private static readonly EVICTION_CHECK_INTERVAL;
|
|
22
26
|
constructor(projectRoot: string, config: MemoryConfig);
|
|
23
27
|
private initPromise;
|
|
24
28
|
private ensureInitialized;
|
|
25
29
|
private doInit;
|
|
26
|
-
private doInitInner;
|
|
27
|
-
/**
|
|
28
|
-
* Strip <private>...</private> tags from content before storing
|
|
29
|
-
*/
|
|
30
30
|
private filterPrivate;
|
|
31
|
-
private saveHnswIfNeeded;
|
|
32
|
-
private saveHnswToDisk;
|
|
33
31
|
saveMemory(input: {
|
|
34
32
|
type: MemoryType;
|
|
35
33
|
title: string;
|
|
@@ -47,18 +45,21 @@ export declare class MemoryManager {
|
|
|
47
45
|
startSession(project: string): Promise<MemorySession>;
|
|
48
46
|
endSession(sessionId: string, summary?: string): Promise<void>;
|
|
49
47
|
getStats(): Promise<MemoryStats>;
|
|
50
|
-
|
|
48
|
+
/**
|
|
49
|
+
* Age-based retention. With no `maxAgeDays` arg, this is a no-op (the
|
|
50
|
+
* legacy LRU byte-budget eviction was removed in v5.6).
|
|
51
|
+
*/
|
|
52
|
+
cleanup(arg?: boolean | {
|
|
53
|
+
maxAgeDays?: number;
|
|
54
|
+
}): Promise<{
|
|
51
55
|
evictedCount: number;
|
|
52
56
|
freedBytes: number;
|
|
53
57
|
}>;
|
|
54
58
|
exportMemories(format?: 'json' | 'csv'): Promise<string>;
|
|
55
|
-
saveCodeNode(node:
|
|
56
|
-
saveCodeEdge(edge:
|
|
59
|
+
saveCodeNode(node: CodeNode): Promise<void>;
|
|
60
|
+
saveCodeEdge(edge: CodeEdge): Promise<void>;
|
|
57
61
|
deleteCodeNodesByFile(filePath: string): Promise<void>;
|
|
58
62
|
close(): Promise<void>;
|
|
59
63
|
}
|
|
60
|
-
/**
|
|
61
|
-
* Factory function
|
|
62
|
-
*/
|
|
63
64
|
export declare function createMemoryManager(projectRoot: string, config: MemoryConfig): MemoryManager;
|
|
64
65
|
//# sourceMappingURL=memory-manager.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"memory-manager.d.ts","sourceRoot":"","sources":["../../src/memory/memory-manager.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"memory-manager.d.ts","sourceRoot":"","sources":["../../src/memory/memory-manager.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAQH,OAAO,KAAK,EACV,MAAM,EACN,YAAY,EACZ,mBAAmB,EACnB,kBAAkB,EAClB,aAAa,EACb,WAAW,EACX,UAAU,EACV,aAAa,EACd,MAAM,mBAAmB,CAAC;AAC3B,OAAO,KAAK,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,kCAAkC,CAAC;AAO3E,qBAAa,aAAa;IACxB,OAAO,CAAC,KAAK,CAA0B;IACvC,OAAO,CAAC,MAAM,CAA2B;IACzC,OAAO,CAAC,WAAW,CAAS;IAC5B,OAAO,CAAC,QAAQ,CAAS;IAEzB,8EAA8E;IAC9E,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAS;IACpC,6EAA6E;IAC7E,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAS;IACtC,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAS;gBAE1B,WAAW,EAAE,MAAM,EAAE,MAAM,EAAE,YAAY;IAQrD,OAAO,CAAC,WAAW,CAA8B;YAEnC,iBAAiB;YAWjB,MAAM;IAyBpB,OAAO,CAAC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AAQ,GAAG,OAAO,CAAC,IAAI,CAAC;IAO3C,YAAY,CAAC,IAAI,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC;IAK3C,qBAAqB,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAKtD,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;CAM7B;AAED,wBAAgB,mBAAmB,CAAC,WAAW,EAAE,MAAM,EAAE,MAAM,EAAE,YAAY,GAAG,aAAa,CAE5F"}
|
|
@@ -1,51 +1,48 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Memory Manager -
|
|
2
|
+
* Memory Manager - File-backed orchestrator (v5.6).
|
|
3
3
|
*
|
|
4
|
-
* Public API
|
|
5
|
-
*
|
|
6
|
-
*
|
|
4
|
+
* Public API kept stable for callers (saveMemory, searchMemories,
|
|
5
|
+
* getTimeline, getFullDetails, startSession, endSession, getStats,
|
|
6
|
+
* cleanup, exportMemories, plus the indexer code-graph methods).
|
|
7
|
+
*
|
|
8
|
+
* Internally uses the FileStore + FileSearch implementations under
|
|
9
|
+
* `.rulebook/memory/{memories,sessions,codegraph}/...` instead of
|
|
10
|
+
* SQLite + HNSW. On startup, an existing legacy `memory.db` is
|
|
11
|
+
* auto-detected and migrated to markdown one time, then renamed to
|
|
12
|
+
* `memory.db.legacy`.
|
|
7
13
|
*/
|
|
8
14
|
import { randomUUID } from 'crypto';
|
|
9
|
-
import { existsSync
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
import { MemoryStore } from './memory-store.js';
|
|
15
|
-
import { vectorize } from './memory-vectorizer.js';
|
|
15
|
+
import { existsSync } from 'fs';
|
|
16
|
+
import { rename } from 'fs/promises';
|
|
17
|
+
import { join, dirname } from 'path';
|
|
18
|
+
import { FileStore } from './file-store.js';
|
|
19
|
+
import { FileSearch } from './file-search.js';
|
|
16
20
|
const DEFAULT_DB_PATH = '.rulebook/memory/memory.db';
|
|
17
|
-
const
|
|
18
|
-
const DEFAULT_MAX_SIZE = 524288000; // 500MB
|
|
19
|
-
const DEFAULT_DIMENSIONS = 256;
|
|
20
|
-
const HNSW_SAVE_THRESHOLD = 100;
|
|
21
|
+
const DEFAULT_MAX_SIZE = 524288000; // 500MB — kept for getStats compatibility
|
|
21
22
|
const PRIVATE_TAG_REGEX = /<private>[\s\S]*?<\/private>/g;
|
|
22
23
|
export class MemoryManager {
|
|
23
24
|
store = null;
|
|
24
|
-
index = null;
|
|
25
25
|
search = null;
|
|
26
|
-
cache = null;
|
|
27
26
|
initialized = false;
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
27
|
+
migrated = false;
|
|
28
|
+
/** Resolved root for the file-based store (sibling of legacy `memory.db`). */
|
|
29
|
+
memoryRoot;
|
|
30
|
+
/** Path to the legacy DB file, used for one-shot migration on first init. */
|
|
31
|
+
legacyDbPath;
|
|
31
32
|
maxSizeBytes;
|
|
32
|
-
dimensions;
|
|
33
|
-
saveCount = 0;
|
|
34
|
-
static EVICTION_CHECK_INTERVAL = 50;
|
|
35
33
|
constructor(projectRoot, config) {
|
|
36
|
-
|
|
37
|
-
|
|
34
|
+
const dbRel = config.dbPath ?? DEFAULT_DB_PATH;
|
|
35
|
+
const dbAbs = join(projectRoot, dbRel);
|
|
36
|
+
this.legacyDbPath = dbAbs;
|
|
37
|
+
this.memoryRoot = dirname(dbAbs);
|
|
38
38
|
this.maxSizeBytes = config.maxSizeBytes ?? DEFAULT_MAX_SIZE;
|
|
39
|
-
this.dimensions = config.vectorDimensions ?? DEFAULT_DIMENSIONS;
|
|
40
39
|
}
|
|
41
40
|
initPromise = null;
|
|
42
41
|
async ensureInitialized() {
|
|
43
42
|
if (this.initialized)
|
|
44
43
|
return;
|
|
45
|
-
// Deduplicate concurrent init calls (e.g. multiple tool calls hitting memory at once)
|
|
46
44
|
if (!this.initPromise) {
|
|
47
45
|
this.initPromise = this.doInit().catch((err) => {
|
|
48
|
-
// Reset so next call retries instead of getting stuck on a rejected promise
|
|
49
46
|
this.initPromise = null;
|
|
50
47
|
throw err;
|
|
51
48
|
});
|
|
@@ -53,56 +50,29 @@ export class MemoryManager {
|
|
|
53
50
|
await this.initPromise;
|
|
54
51
|
}
|
|
55
52
|
async doInit() {
|
|
56
|
-
|
|
57
|
-
const timeout = new Promise((_, reject) => setTimeout(() => reject(new Error(`Memory initialization timed out after ${INIT_TIMEOUT_MS}ms`)), INIT_TIMEOUT_MS));
|
|
58
|
-
await Promise.race([this.doInitInner(), timeout]);
|
|
59
|
-
}
|
|
60
|
-
async doInitInner() {
|
|
61
|
-
// Initialize store (loads WASM sql.js — can be slow on first load)
|
|
62
|
-
this.store = new MemoryStore(this.dbPath);
|
|
53
|
+
this.store = new FileStore(this.memoryRoot);
|
|
63
54
|
await this.store.initialize();
|
|
64
|
-
|
|
65
|
-
|
|
55
|
+
this.search = new FileSearch(this.store);
|
|
56
|
+
// One-shot legacy DB migration. The runtime never reads SQLite again.
|
|
57
|
+
if (!this.migrated && existsSync(this.legacyDbPath)) {
|
|
66
58
|
try {
|
|
67
|
-
const
|
|
68
|
-
|
|
59
|
+
const { migrateLegacyDb } = await import('./legacy-migrator.js');
|
|
60
|
+
await migrateLegacyDb(this.legacyDbPath, this.store);
|
|
61
|
+
await rename(this.legacyDbPath, this.legacyDbPath + '.legacy');
|
|
62
|
+
this.store.invalidateCaches();
|
|
69
63
|
}
|
|
70
|
-
catch {
|
|
71
|
-
|
|
64
|
+
catch (err) {
|
|
65
|
+
// Non-fatal: surface but keep the manager functional.
|
|
66
|
+
console.error('[MemoryManager] legacy DB migration failed; continuing with file-only store:', err instanceof Error ? err.message : String(err));
|
|
72
67
|
}
|
|
68
|
+
this.migrated = true;
|
|
73
69
|
}
|
|
74
|
-
else {
|
|
75
|
-
this.index = new HNSWIndex({ dimensions: this.dimensions });
|
|
76
|
-
}
|
|
77
|
-
// Initialize search and cache
|
|
78
|
-
this.search = new MemorySearch(this.store, this.index, this.dimensions);
|
|
79
|
-
this.cache = new MemoryCache(this.store, this.index, this.maxSizeBytes);
|
|
80
70
|
this.initialized = true;
|
|
81
71
|
}
|
|
82
|
-
/**
|
|
83
|
-
* Strip <private>...</private> tags from content before storing
|
|
84
|
-
*/
|
|
85
72
|
filterPrivate(content) {
|
|
86
73
|
return content.replace(PRIVATE_TAG_REGEX, '[REDACTED]');
|
|
87
74
|
}
|
|
88
|
-
|
|
89
|
-
this.hnswInsertCount++;
|
|
90
|
-
if (this.hnswInsertCount >= HNSW_SAVE_THRESHOLD) {
|
|
91
|
-
this.saveHnswToDisk();
|
|
92
|
-
this.hnswInsertCount = 0;
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
saveHnswToDisk() {
|
|
96
|
-
if (!this.index || this.index.size === 0)
|
|
97
|
-
return;
|
|
98
|
-
const dir = join(this.hnswPath, '..');
|
|
99
|
-
if (!existsSync(dir)) {
|
|
100
|
-
mkdirSync(dir, { recursive: true });
|
|
101
|
-
}
|
|
102
|
-
const buffer = this.index.serialize();
|
|
103
|
-
writeFileSync(this.hnswPath, Buffer.from(buffer));
|
|
104
|
-
}
|
|
105
|
-
// --- Public API ---
|
|
75
|
+
// ── public API ─────────────────────────────────────────────────────
|
|
106
76
|
async saveMemory(input) {
|
|
107
77
|
await this.ensureInitialized();
|
|
108
78
|
const now = Date.now();
|
|
@@ -119,35 +89,26 @@ export class MemoryManager {
|
|
|
119
89
|
updatedAt: now,
|
|
120
90
|
accessedAt: now,
|
|
121
91
|
};
|
|
122
|
-
this.store.saveMemory(memory);
|
|
123
|
-
//
|
|
124
|
-
|
|
125
|
-
.
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
this.saveHnswIfNeeded();
|
|
130
|
-
// Check cache limits periodically (not on every save — getDbSizeBytes is cheap now
|
|
131
|
-
// but eviction itself is expensive and rarely needed)
|
|
132
|
-
this.saveCount++;
|
|
133
|
-
if (this.saveCount >= MemoryManager.EVICTION_CHECK_INTERVAL) {
|
|
134
|
-
this.saveCount = 0;
|
|
135
|
-
this.cache.checkAndEvict();
|
|
92
|
+
await this.store.saveMemory(memory);
|
|
93
|
+
// Refresh the inverted-index sidecar lazily for large corpora.
|
|
94
|
+
try {
|
|
95
|
+
await this.search.maybeRebuildIndex();
|
|
96
|
+
}
|
|
97
|
+
catch {
|
|
98
|
+
// non-fatal — search falls back to in-memory build per call
|
|
136
99
|
}
|
|
137
100
|
return memory;
|
|
138
101
|
}
|
|
139
102
|
async getMemory(id) {
|
|
140
103
|
await this.ensureInitialized();
|
|
141
|
-
const memory = this.store.getMemory(id);
|
|
142
|
-
if (memory)
|
|
143
|
-
this.store.updateAccessedAt(id);
|
|
144
|
-
}
|
|
104
|
+
const memory = await this.store.getMemory(id);
|
|
105
|
+
if (memory)
|
|
106
|
+
await this.store.updateAccessedAt(id);
|
|
145
107
|
return memory;
|
|
146
108
|
}
|
|
147
109
|
async deleteMemory(id) {
|
|
148
110
|
await this.ensureInitialized();
|
|
149
|
-
this.store.deleteMemory(id);
|
|
150
|
-
this.index.remove(id);
|
|
111
|
+
await this.store.deleteMemory(id);
|
|
151
112
|
}
|
|
152
113
|
async searchMemories(options) {
|
|
153
114
|
await this.ensureInitialized();
|
|
@@ -170,43 +131,62 @@ export class MemoryManager {
|
|
|
170
131
|
startedAt: Date.now(),
|
|
171
132
|
toolCalls: 0,
|
|
172
133
|
};
|
|
173
|
-
this.store.
|
|
134
|
+
await this.store.saveSession(session);
|
|
174
135
|
return session;
|
|
175
136
|
}
|
|
176
137
|
async endSession(sessionId, summary) {
|
|
177
138
|
await this.ensureInitialized();
|
|
178
|
-
this.store.
|
|
139
|
+
const existing = await this.store.getSession(sessionId);
|
|
140
|
+
if (!existing)
|
|
141
|
+
return;
|
|
142
|
+
existing.status = 'completed';
|
|
143
|
+
existing.endedAt = Date.now();
|
|
144
|
+
if (summary !== undefined)
|
|
145
|
+
existing.summary = summary;
|
|
146
|
+
await this.store.saveSession(existing);
|
|
179
147
|
}
|
|
180
148
|
async getStats() {
|
|
181
149
|
await this.ensureInitialized();
|
|
182
|
-
const
|
|
183
|
-
const memoryCount = this.store.getMemoryCount();
|
|
184
|
-
const sessionCount = this.store.getSessionCount();
|
|
150
|
+
const stats = await this.store.getStats();
|
|
185
151
|
return {
|
|
186
|
-
dbSizeBytes:
|
|
187
|
-
memoryCount,
|
|
188
|
-
sessionCount,
|
|
189
|
-
|
|
190
|
-
|
|
152
|
+
dbSizeBytes: stats.totalBytes,
|
|
153
|
+
memoryCount: stats.memoryCount,
|
|
154
|
+
sessionCount: stats.sessionCount,
|
|
155
|
+
fileCount: stats.fileCount,
|
|
156
|
+
oldestMemory: stats.oldestMemory,
|
|
157
|
+
newestMemory: stats.newestMemory,
|
|
191
158
|
maxSizeBytes: this.maxSizeBytes,
|
|
192
|
-
usagePercent: (
|
|
193
|
-
indexHealth: this.index.size === memoryCount
|
|
194
|
-
? 'good'
|
|
195
|
-
: Math.abs(this.index.size - memoryCount) < memoryCount * 0.1
|
|
196
|
-
? 'degraded'
|
|
197
|
-
: 'needs-rebuild',
|
|
159
|
+
usagePercent: this.maxSizeBytes > 0 ? (stats.totalBytes / this.maxSizeBytes) * 100 : 0,
|
|
198
160
|
};
|
|
199
161
|
}
|
|
200
|
-
|
|
162
|
+
/**
|
|
163
|
+
* Age-based retention. With no `maxAgeDays` arg, this is a no-op (the
|
|
164
|
+
* legacy LRU byte-budget eviction was removed in v5.6).
|
|
165
|
+
*/
|
|
166
|
+
async cleanup(arg) {
|
|
201
167
|
await this.ensureInitialized();
|
|
202
|
-
|
|
203
|
-
|
|
168
|
+
const maxAgeDays = typeof arg === 'object' && arg !== null ? arg.maxAgeDays : undefined;
|
|
169
|
+
if (maxAgeDays === undefined || maxAgeDays <= 0) {
|
|
170
|
+
return { evictedCount: 0, freedBytes: 0 };
|
|
204
171
|
}
|
|
205
|
-
|
|
172
|
+
const cutoff = Date.now() - maxAgeDays * 24 * 60 * 60 * 1000;
|
|
173
|
+
const all = await this.store.listAllMemories();
|
|
174
|
+
let evicted = 0;
|
|
175
|
+
let freed = 0;
|
|
176
|
+
const before = (await this.store.getStats()).totalBytes;
|
|
177
|
+
for (const m of all) {
|
|
178
|
+
if (m.createdAt < cutoff) {
|
|
179
|
+
await this.store.deleteMemory(m.id);
|
|
180
|
+
evicted++;
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
const after = (await this.store.getStats()).totalBytes;
|
|
184
|
+
freed = Math.max(0, before - after);
|
|
185
|
+
return { evictedCount: evicted, freedBytes: freed };
|
|
206
186
|
}
|
|
207
187
|
async exportMemories(format = 'json') {
|
|
208
188
|
await this.ensureInitialized();
|
|
209
|
-
const memories = this.store.listMemories({ limit:
|
|
189
|
+
const memories = await this.store.listMemories({ limit: 10000 });
|
|
210
190
|
if (format === 'csv') {
|
|
211
191
|
const header = 'id,type,title,content,project,tags,createdAt,updatedAt';
|
|
212
192
|
const rows = memories.map((m) => `"${m.id}","${m.type}","${m.title.replace(/"/g, '""')}","${m.content.replace(/"/g, '""')}","${m.project}","${m.tags.join(';')}",${m.createdAt},${m.updatedAt}`);
|
|
@@ -214,52 +194,29 @@ export class MemoryManager {
|
|
|
214
194
|
}
|
|
215
195
|
return JSON.stringify(memories, null, 2);
|
|
216
196
|
}
|
|
217
|
-
//
|
|
197
|
+
// ── background indexer code-graph (JSONL log) ─────────────────────
|
|
218
198
|
async saveCodeNode(node) {
|
|
219
199
|
await this.ensureInitialized();
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
}
|
|
225
|
-
this.store.saveCodeNode(node);
|
|
226
|
-
// Vectorize code chunks for FTS/HNSW semantic search
|
|
227
|
-
const textToVectorize = [node.name, node.summary || '', node.content].filter(Boolean).join(' ');
|
|
228
|
-
// Important: We prepend an identifier so search knows it's a code node
|
|
229
|
-
const vecId = `__code__${node.id}`;
|
|
230
|
-
const vec = vectorize(textToVectorize, this.dimensions);
|
|
231
|
-
this.index.add(vecId, vec);
|
|
232
|
-
this.saveHnswIfNeeded();
|
|
200
|
+
const existing = await this.store.getCodeNodeHash(node.id);
|
|
201
|
+
if (existing === node.hash)
|
|
202
|
+
return;
|
|
203
|
+
await this.store.appendCodeNode(node);
|
|
233
204
|
}
|
|
234
205
|
async saveCodeEdge(edge) {
|
|
235
206
|
await this.ensureInitialized();
|
|
236
|
-
this.store.
|
|
207
|
+
await this.store.appendCodeEdge(edge);
|
|
237
208
|
}
|
|
238
209
|
async deleteCodeNodesByFile(filePath) {
|
|
239
210
|
await this.ensureInitialized();
|
|
240
|
-
|
|
241
|
-
const nodeIds = this.store.getCodeNodeIdsByFile(filePath);
|
|
242
|
-
this.store.deleteCodeNodesByFile(filePath);
|
|
243
|
-
// Remove corresponding vectors from HNSW to prevent orphan accumulation
|
|
244
|
-
for (const id of nodeIds) {
|
|
245
|
-
this.index.remove(`__code__${id}`);
|
|
246
|
-
}
|
|
211
|
+
await this.store.deleteCodeNodesByFile(filePath);
|
|
247
212
|
}
|
|
248
213
|
async close() {
|
|
249
|
-
if (this.store) {
|
|
250
|
-
this.store.close();
|
|
251
|
-
}
|
|
252
|
-
this.saveHnswToDisk();
|
|
253
214
|
this.initialized = false;
|
|
254
215
|
this.store = null;
|
|
255
|
-
this.index = null;
|
|
256
216
|
this.search = null;
|
|
257
|
-
this.
|
|
217
|
+
this.initPromise = null;
|
|
258
218
|
}
|
|
259
219
|
}
|
|
260
|
-
/**
|
|
261
|
-
* Factory function
|
|
262
|
-
*/
|
|
263
220
|
export function createMemoryManager(projectRoot, config) {
|
|
264
221
|
return new MemoryManager(projectRoot, config);
|
|
265
222
|
}
|