claude-flow-novice 1.3.0 ā 1.3.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.
- package/.claude-flow-novice/preferences/generation.json +147 -0
- package/.claude-flow-novice/preferences/language-configs/javascript.json +51 -0
- package/.claude-flow-novice/preferences/language-configs/python.json +50 -0
- package/.claude-flow-novice/preferences/language-configs/rust.json +237 -0
- package/.claude-flow-novice/preferences/language-configs/typescript.json +54 -0
- package/.claude-flow-novice/preferences/project-local.json +91 -0
- package/.claude-flow-novice/preferences/resource-delegation.json +120 -0
- package/.claude-flow-novice/preferences/team-shared.json +195 -0
- package/.claude-flow-novice/preferences/user-global.json +247 -0
- package/.claude-flow-novice/templates/claude-md-templates/CLAUDE-JAVASCRIPT.md +769 -0
- package/.claude-flow-novice/templates/claude-md-templates/CLAUDE-PYTHON.md +1214 -0
- package/.claude-flow-novice/templates/claude-md-templates/CLAUDE-RUST.md +475 -0
- package/.claude-flow-novice/templates/claude-md-templates/CLAUDE-TYPESCRIPT.md +851 -0
- package/.claude-flow-novice/templates/claude-md-templates/README.md +263 -0
- package/CLAUDE.md +81 -0
- package/README-NPM.md +0 -0
- package/package.json +11 -7
- package/scripts/build/README.md +167 -0
- package/scripts/build/build-config.js +27 -0
- package/scripts/build/build-prompt-copier.sh +30 -0
- package/scripts/build/performance-monitor.js +869 -0
- package/scripts/build/prepare-publish.js +150 -0
- package/scripts/build/typescript-fixer.js +621 -0
- package/scripts/build/unified-builder.sh +428 -0
- package/scripts/build/update-bin-version.js +32 -0
- package/scripts/dev/README.md +264 -0
- package/scripts/dev/claude-flow-wrapper.sh +35 -0
- package/scripts/dev/claude-monitor.py +419 -0
- package/scripts/dev/claude-sparc.sh +562 -0
- package/scripts/dev/claude-wrapper.sh +17 -0
- package/scripts/dev/demo-phase3-compliance.js +172 -0
- package/scripts/dev/demo-task-system.ts +224 -0
- package/scripts/dev/deployment-validator.js +315 -0
- package/scripts/dev/spawn-claude-terminal.sh +32 -0
- package/scripts/dev/start-portal.sh +506 -0
- package/scripts/dev/start-web-ui.js +15 -0
- package/scripts/dev/stop-portal.sh +311 -0
- package/scripts/dev/validate-examples.ts +288 -0
- package/scripts/dev/validate-phase2.cjs +451 -0
- package/scripts/dev/validate-phase2.js +785 -0
- package/scripts/dev/validate-phase3.cjs +208 -0
- package/scripts/dev/validate-security-remediation.js +1 -0
- package/scripts/legacy/README.md +272 -0
- package/scripts/legacy/batch-fix-ts.sh +54 -0
- package/scripts/legacy/build-migration.sh +105 -0
- package/scripts/legacy/build-monitor.js +209 -0
- package/scripts/legacy/build-with-filter.sh +84 -0
- package/scripts/legacy/build-workaround.sh +71 -0
- package/scripts/legacy/fix-ts-advanced.js +358 -0
- package/scripts/legacy/fix-ts-final.sh +50 -0
- package/scripts/legacy/fix-ts-targeted.sh +49 -0
- package/scripts/legacy/fix-typescript-errors.js +305 -0
- package/scripts/legacy/force-build.sh +63 -0
- package/scripts/legacy/optimize-performance.js +400 -0
- package/scripts/legacy/performance-monitor.js +263 -0
- package/scripts/legacy/performance-monitoring.js +532 -0
- package/scripts/legacy/performance-test-runner.js +645 -0
- package/scripts/legacy/quick-fix-ts.js +281 -0
- package/scripts/legacy/safe-build.sh +63 -0
- package/scripts/migration/README.md +434 -0
- package/scripts/migration/install-arm64.js +78 -0
- package/scripts/migration/install.js +83 -0
- package/scripts/migration/migrate-hooks.js +173 -0
- package/scripts/migration/migration-examples.ts +318 -0
- package/scripts/optimization/build-optimizer.js +438 -0
- package/scripts/optimization/config-validator.js +761 -0
- package/scripts/optimization/test-optimization.js +432 -0
- package/scripts/optimization/unified-activation.js +839 -0
- package/scripts/performance/ACTIVATION_COMMANDS.md +292 -0
- package/scripts/performance/sqlite-enhanced-activation.sh +583 -0
- package/scripts/performance/test-enhanced-backend.sh +504 -0
- package/scripts/performance-test-runner.js +698 -0
- package/scripts/security/README.md +339 -0
- package/scripts/security/install-git-hooks.sh +132 -0
- package/scripts/security/ruv-swarm-safe.js +74 -0
- package/scripts/test/README.md +236 -0
- package/scripts/test/check-links.ts +274 -0
- package/scripts/test/check-performance-regression.ts +168 -0
- package/scripts/test/coverage-report.ts +692 -0
- package/scripts/test/generate-swarm-tests.js +633 -0
- package/scripts/test/integration-test-validation.cjs +253 -0
- package/scripts/test/load-test-swarm.js +576 -0
- package/scripts/test/run-phase3-compliance-tests.js +427 -0
- package/scripts/test/test-batch-tasks.ts +29 -0
- package/scripts/test/test-byzantine-resolution.js +246 -0
- package/scripts/test/test-claude-spawn-options.sh +63 -0
- package/scripts/test/test-cli-wizard.js +331 -0
- package/scripts/test/test-comprehensive.js +401 -0
- package/scripts/test/test-coordination-features.ts +238 -0
- package/scripts/test/test-fallback-systems.js +276 -0
- package/scripts/test/test-init-command.ts +302 -0
- package/scripts/test/test-mcp.ts +251 -0
- package/scripts/test/test-runner.ts +568 -0
- package/scripts/test/test-swarm-integration.sh +92 -0
- package/scripts/test/test-swarm.ts +142 -0
- package/scripts/test/validation-summary.ts +408 -0
- package/scripts/utils/README.md +261 -0
- package/scripts/utils/clean-build-artifacts.sh +94 -0
- package/scripts/utils/cleanup-root.sh +69 -0
- package/scripts/utils/fix-cliffy-imports.js +307 -0
- package/scripts/utils/fix-duplicate-imports.js +114 -0
- package/scripts/utils/fix-error-handling.cjs +70 -0
- package/scripts/utils/fix-import-paths.js +104 -0
- package/scripts/utils/fix-imports.js +116 -0
- package/scripts/utils/fix-shebang.js +78 -0
- package/scripts/utils/fix-test-modules.js +27 -0
- package/scripts/utils/fix-timezone-issue-246.js +200 -0
- package/scripts/utils/fix-ts-comprehensive.py +182 -0
- package/scripts/utils/fix-ts-targeted-batch.js +250 -0
- package/scripts/utils/remove-benchmark-conflicts.sh +140 -0
- package/scripts/utils/simple-test-fixer.js +190 -0
- package/scripts/utils/validate-metrics-structure.cjs +144 -0
- package/scripts/verify-mcp-server.js +86 -0
- package/src/cli/simple-commands/__tests__/agent.test.js +291 -0
- package/src/cli/simple-commands/__tests__/memory.test.js +8 -0
- package/src/cli/simple-commands/__tests__/swarm.test.js +371 -0
- package/src/cli/simple-commands/__tests__/task.test.js +8 -0
- package/src/cli/simple-commands/agent.js +216 -0
- package/src/cli/simple-commands/analysis.js +570 -0
- package/src/cli/simple-commands/automation-executor.js +1603 -0
- package/src/cli/simple-commands/automation.js +627 -0
- package/src/cli/simple-commands/batch-manager.js +338 -0
- package/src/cli/simple-commands/claude-telemetry.js +311 -0
- package/src/cli/simple-commands/claude-track.js +102 -0
- package/src/cli/simple-commands/concurrent-display.js +348 -0
- package/src/cli/simple-commands/config.js +319 -0
- package/src/cli/simple-commands/coordination.js +307 -0
- package/src/cli/simple-commands/enhanced-ui-views.js +654 -0
- package/src/cli/simple-commands/enhanced-webui-complete.js +1038 -0
- package/src/cli/simple-commands/fix-hook-variables.js +363 -0
- package/src/cli/simple-commands/github/gh-coordinator.js +605 -0
- package/src/cli/simple-commands/github/github-api.js +624 -0
- package/src/cli/simple-commands/github/init.js +543 -0
- package/src/cli/simple-commands/github.js +377 -0
- package/src/cli/simple-commands/goal.js +145 -0
- package/src/cli/simple-commands/hive-mind/auto-save-middleware.js +311 -0
- package/src/cli/simple-commands/hive-mind/communication.js +740 -0
- package/src/cli/simple-commands/hive-mind/core.js +1031 -0
- package/src/cli/simple-commands/hive-mind/db-optimizer.js +872 -0
- package/src/cli/simple-commands/hive-mind/mcp-wrapper.js +1364 -0
- package/src/cli/simple-commands/hive-mind/memory.js +1292 -0
- package/src/cli/simple-commands/hive-mind/performance-optimizer.js +618 -0
- package/src/cli/simple-commands/hive-mind/performance-test.js +373 -0
- package/src/cli/simple-commands/hive-mind/queen.js +809 -0
- package/src/cli/simple-commands/hive-mind/session-manager.js +1223 -0
- package/src/cli/simple-commands/hive-mind-optimize.js +361 -0
- package/src/cli/simple-commands/hive-mind-wizard.js +281 -0
- package/src/cli/simple-commands/hive-mind.js +3112 -0
- package/src/cli/simple-commands/hive.js +140 -0
- package/src/cli/simple-commands/hook-safety.js +671 -0
- package/src/cli/simple-commands/hooks.js +1268 -0
- package/src/cli/simple-commands/init/.claude/checkpoints/1756224542.json +7 -0
- package/src/cli/simple-commands/init/.claude/checkpoints/1756224544.json +8 -0
- package/src/cli/simple-commands/init/README.md +106 -0
- package/src/cli/simple-commands/init/VALIDATION_ROLLBACK.md +488 -0
- package/src/cli/simple-commands/init/agent-copier.js +347 -0
- package/src/cli/simple-commands/init/batch-init.js +663 -0
- package/src/cli/simple-commands/init/claude-commands/claude-flow-commands.js +438 -0
- package/src/cli/simple-commands/init/claude-commands/optimized-claude-flow-commands.js +876 -0
- package/src/cli/simple-commands/init/claude-commands/optimized-slash-commands.js +356 -0
- package/src/cli/simple-commands/init/claude-commands/optimized-sparc-commands.js +501 -0
- package/src/cli/simple-commands/init/claude-commands/slash-commands.js +57 -0
- package/src/cli/simple-commands/init/claude-commands/sparc-commands.js +296 -0
- package/src/cli/simple-commands/init/copy-revised-templates.js +175 -0
- package/src/cli/simple-commands/init/executable-wrapper.js +122 -0
- package/src/cli/simple-commands/init/gitignore-updater.js +137 -0
- package/src/cli/simple-commands/init/help.js +110 -0
- package/src/cli/simple-commands/init/hive-mind-init.js +749 -0
- package/src/cli/simple-commands/init/index.js +1953 -0
- package/src/cli/simple-commands/init/performance-monitor.js +344 -0
- package/src/cli/simple-commands/init/rollback/backup-manager.js +542 -0
- package/src/cli/simple-commands/init/rollback/index.js +399 -0
- package/src/cli/simple-commands/init/rollback/recovery-manager.js +778 -0
- package/src/cli/simple-commands/init/rollback/rollback-executor.js +521 -0
- package/src/cli/simple-commands/init/rollback/state-tracker.js +486 -0
- package/src/cli/simple-commands/init/sparc/roo-readme.js +61 -0
- package/src/cli/simple-commands/init/sparc/roomodes-config.js +102 -0
- package/src/cli/simple-commands/init/sparc/workflows.js +40 -0
- package/src/cli/simple-commands/init/sparc-structure.js +68 -0
- package/src/cli/simple-commands/init/template-copier.js +640 -0
- package/src/cli/simple-commands/init/templates/CLAUDE.md +1185 -0
- package/src/cli/simple-commands/init/templates/CLAUDE.md.optimized +265 -0
- package/src/cli/simple-commands/init/templates/claude-flow-universal +81 -0
- package/src/cli/simple-commands/init/templates/claude-flow.bat +18 -0
- package/src/cli/simple-commands/init/templates/claude-flow.ps1 +24 -0
- package/src/cli/simple-commands/init/templates/claude-md.js +1101 -0
- package/src/cli/simple-commands/init/templates/commands/analysis/bottleneck-detect.md +162 -0
- package/src/cli/simple-commands/init/templates/commands/automation/auto-agent.md +122 -0
- package/src/cli/simple-commands/init/templates/commands/coordination/swarm-init.md +85 -0
- package/src/cli/simple-commands/init/templates/commands/github/github-swarm.md +121 -0
- package/src/cli/simple-commands/init/templates/commands/helpers/standard-checkpoint-hooks.sh +179 -0
- package/src/cli/simple-commands/init/templates/commands/hooks/notification.md +113 -0
- package/src/cli/simple-commands/init/templates/commands/hooks/post-command.md +116 -0
- package/src/cli/simple-commands/init/templates/commands/hooks/post-edit.md +117 -0
- package/src/cli/simple-commands/init/templates/commands/hooks/post-task.md +112 -0
- package/src/cli/simple-commands/init/templates/commands/hooks/pre-command.md +113 -0
- package/src/cli/simple-commands/init/templates/commands/hooks/pre-edit.md +113 -0
- package/src/cli/simple-commands/init/templates/commands/hooks/pre-search.md +112 -0
- package/src/cli/simple-commands/init/templates/commands/hooks/pre-task.md +111 -0
- package/src/cli/simple-commands/init/templates/commands/hooks/session-end.md +118 -0
- package/src/cli/simple-commands/init/templates/commands/hooks/session-restore.md +118 -0
- package/src/cli/simple-commands/init/templates/commands/hooks/session-start.md +117 -0
- package/src/cli/simple-commands/init/templates/coordination-md.js +340 -0
- package/src/cli/simple-commands/init/templates/coordination.md +16 -0
- package/src/cli/simple-commands/init/templates/enhanced-templates.js +2347 -0
- package/src/cli/simple-commands/init/templates/github-safe-enhanced.js +331 -0
- package/src/cli/simple-commands/init/templates/github-safe.js +106 -0
- package/src/cli/simple-commands/init/templates/memory-bank-md.js +259 -0
- package/src/cli/simple-commands/init/templates/memory-bank.md +16 -0
- package/src/cli/simple-commands/init/templates/readme-files.js +72 -0
- package/src/cli/simple-commands/init/templates/safe-hook-patterns.js +430 -0
- package/src/cli/simple-commands/init/templates/settings.json +109 -0
- package/src/cli/simple-commands/init/templates/settings.json.enhanced +35 -0
- package/src/cli/simple-commands/init/templates/sparc-modes.js +1401 -0
- package/src/cli/simple-commands/init/templates/verification-claude-md.js +432 -0
- package/src/cli/simple-commands/init/validation/config-validator.js +354 -0
- package/src/cli/simple-commands/init/validation/health-checker.js +599 -0
- package/src/cli/simple-commands/init/validation/index.js +388 -0
- package/src/cli/simple-commands/init/validation/mode-validator.js +387 -0
- package/src/cli/simple-commands/init/validation/post-init-validator.js +390 -0
- package/src/cli/simple-commands/init/validation/pre-init-validator.js +290 -0
- package/src/cli/simple-commands/init/validation/test-runner.js +488 -0
- package/src/cli/simple-commands/init.js +4 -0
- package/src/cli/simple-commands/mcp-health.js +163 -0
- package/src/cli/simple-commands/mcp-integration-layer.js +689 -0
- package/src/cli/simple-commands/mcp.js +420 -0
- package/src/cli/simple-commands/memory-consolidation.js +631 -0
- package/src/cli/simple-commands/memory.js +345 -0
- package/src/cli/simple-commands/migrate-hooks.js +63 -0
- package/src/cli/simple-commands/monitor.js +417 -0
- package/src/cli/simple-commands/neural.js +148 -0
- package/src/cli/simple-commands/pair-autofix-only.js +755 -0
- package/src/cli/simple-commands/pair-basic.js +751 -0
- package/src/cli/simple-commands/pair-old.js +623 -0
- package/src/cli/simple-commands/pair-working.js +849 -0
- package/src/cli/simple-commands/pair.js +849 -0
- package/src/cli/simple-commands/performance-hooks.js +149 -0
- package/src/cli/simple-commands/performance-metrics.js +601 -0
- package/src/cli/simple-commands/process-ui-enhanced.js +821 -0
- package/src/cli/simple-commands/process-ui.js +274 -0
- package/src/cli/simple-commands/realtime-update-system.js +659 -0
- package/src/cli/simple-commands/sparc/architecture.js +1750 -0
- package/src/cli/simple-commands/sparc/commands.js +575 -0
- package/src/cli/simple-commands/sparc/completion.js +1831 -0
- package/src/cli/simple-commands/sparc/coordinator.js +1045 -0
- package/src/cli/simple-commands/sparc/index.js +321 -0
- package/src/cli/simple-commands/sparc/phase-base.js +430 -0
- package/src/cli/simple-commands/sparc/pseudocode.js +984 -0
- package/src/cli/simple-commands/sparc/refinement.js +1856 -0
- package/src/cli/simple-commands/sparc/specification.js +736 -0
- package/src/cli/simple-commands/sparc-modes/architect.js +125 -0
- package/src/cli/simple-commands/sparc-modes/ask.js +126 -0
- package/src/cli/simple-commands/sparc-modes/code.js +148 -0
- package/src/cli/simple-commands/sparc-modes/debug.js +112 -0
- package/src/cli/simple-commands/sparc-modes/devops.js +137 -0
- package/src/cli/simple-commands/sparc-modes/docs-writer.js +38 -0
- package/src/cli/simple-commands/sparc-modes/generic.js +34 -0
- package/src/cli/simple-commands/sparc-modes/index.js +201 -0
- package/src/cli/simple-commands/sparc-modes/integration.js +55 -0
- package/src/cli/simple-commands/sparc-modes/mcp.js +38 -0
- package/src/cli/simple-commands/sparc-modes/monitoring.js +38 -0
- package/src/cli/simple-commands/sparc-modes/optimization.js +38 -0
- package/src/cli/simple-commands/sparc-modes/security-review.js +130 -0
- package/src/cli/simple-commands/sparc-modes/sparc-orchestrator.js +167 -0
- package/src/cli/simple-commands/sparc-modes/spec-pseudocode.js +38 -0
- package/src/cli/simple-commands/sparc-modes/supabase-admin.js +149 -0
- package/src/cli/simple-commands/sparc-modes/swarm.js +436 -0
- package/src/cli/simple-commands/sparc-modes/tdd.js +112 -0
- package/src/cli/simple-commands/sparc-modes/tutorial.js +277 -0
- package/src/cli/simple-commands/sparc.js +530 -0
- package/src/cli/simple-commands/start-ui.js +147 -0
- package/src/cli/simple-commands/start-wrapper.js +285 -0
- package/src/cli/simple-commands/start.js +2 -0
- package/src/cli/simple-commands/status.js +303 -0
- package/src/cli/simple-commands/stream-chain-clean.js +221 -0
- package/src/cli/simple-commands/stream-chain-fixed.js +89 -0
- package/src/cli/simple-commands/stream-chain-real.js +408 -0
- package/src/cli/simple-commands/stream-chain-working.js +323 -0
- package/src/cli/simple-commands/stream-chain.js +491 -0
- package/src/cli/simple-commands/stream-processor.js +340 -0
- package/src/cli/simple-commands/swarm-executor.js +253 -0
- package/src/cli/simple-commands/swarm-metrics-integration.js +371 -0
- package/src/cli/simple-commands/swarm-ui.js +741 -0
- package/src/cli/simple-commands/swarm-webui-integration.js +311 -0
- package/src/cli/simple-commands/swarm.js +2277 -0
- package/src/cli/simple-commands/task.js +228 -0
- package/src/cli/simple-commands/templates/mle-star-workflow.json +294 -0
- package/src/cli/simple-commands/timestamp-fix.js +104 -0
- package/src/cli/simple-commands/token-tracker.js +372 -0
- package/src/cli/simple-commands/tool-execution-framework.js +555 -0
- package/src/cli/simple-commands/train-and-stream.js +354 -0
- package/src/cli/simple-commands/training-pipeline.js +874 -0
- package/src/cli/simple-commands/training.js +288 -0
- package/src/cli/simple-commands/verification-hooks.js +336 -0
- package/src/cli/simple-commands/verification-integration.js +464 -0
- package/src/cli/simple-commands/verification-training-integration.js +646 -0
- package/src/cli/simple-commands/verification.js +551 -0
- package/src/cli/simple-commands/web-server.js +929 -0
- package/src/cli/simple-commands/webui-validator.js +136 -0
- package/src/language/README.md +503 -0
- package/src/language/claude-md-generator.js +618 -0
- package/src/language/cli.js +422 -0
- package/src/language/example.js +347 -0
- package/src/language/integration-system.js +619 -0
- package/src/language/language-detector.js +581 -0
|
@@ -0,0 +1,631 @@
|
|
|
1
|
+
// memory-consolidation.js - Database consolidation utility
|
|
2
|
+
import { printSuccess, printError, printWarning, printInfo } from '../utils.js';
|
|
3
|
+
import { promises as fs } from 'fs';
|
|
4
|
+
import path from 'path';
|
|
5
|
+
import { existsSync } from '../node-compat.js';
|
|
6
|
+
// Dynamic imports for optional dependencies
|
|
7
|
+
let sqlite3;
|
|
8
|
+
let sqliteOpen;
|
|
9
|
+
|
|
10
|
+
async function loadSqliteModules() {
|
|
11
|
+
try {
|
|
12
|
+
const sqlite3Module = await import('sqlite3');
|
|
13
|
+
sqlite3 = sqlite3Module.default;
|
|
14
|
+
const sqliteModule = await import('sqlite');
|
|
15
|
+
sqliteOpen = sqliteModule.open;
|
|
16
|
+
return true;
|
|
17
|
+
} catch (err) {
|
|
18
|
+
return false;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Memory database consolidation strategy
|
|
24
|
+
* Consolidates multiple memory storage locations into a unified structure
|
|
25
|
+
*/
|
|
26
|
+
export class MemoryConsolidator {
|
|
27
|
+
constructor() {
|
|
28
|
+
this.primaryLocations = {
|
|
29
|
+
json: './memory/memory-store.json',
|
|
30
|
+
sqlite: './.claude-flow/memory/unified-memory.db',
|
|
31
|
+
backup: './.claude-flow/memory/backups/',
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
this.knownLocations = [
|
|
35
|
+
// JSON stores
|
|
36
|
+
'./memory/memory-store.json',
|
|
37
|
+
'./.claude-flow/memory/store.json',
|
|
38
|
+
|
|
39
|
+
// SQLite databases
|
|
40
|
+
'./.swarm/memory.db',
|
|
41
|
+
'./.hive-mind/memory.db',
|
|
42
|
+
'./.hive-mind/hive.db',
|
|
43
|
+
'./.ruv-swarm/swarm.db',
|
|
44
|
+
'./data/hive-mind.db',
|
|
45
|
+
|
|
46
|
+
// Legacy locations
|
|
47
|
+
'./memory.json',
|
|
48
|
+
'./data/memory.json',
|
|
49
|
+
];
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Scan for all memory storage locations
|
|
54
|
+
*/
|
|
55
|
+
async scanMemoryLocations() {
|
|
56
|
+
const found = {
|
|
57
|
+
json: [],
|
|
58
|
+
sqlite: [],
|
|
59
|
+
total: 0,
|
|
60
|
+
sizeBytes: 0,
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
// Check known locations
|
|
64
|
+
for (const location of this.knownLocations) {
|
|
65
|
+
if (existsSync(location)) {
|
|
66
|
+
const stats = await fs.stat(location);
|
|
67
|
+
const type = location.endsWith('.db') ? 'sqlite' : 'json';
|
|
68
|
+
|
|
69
|
+
found[type].push({
|
|
70
|
+
path: location,
|
|
71
|
+
size: stats.size,
|
|
72
|
+
modified: stats.mtime,
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
found.total++;
|
|
76
|
+
found.sizeBytes += stats.size;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// Scan for additional .db files
|
|
81
|
+
try {
|
|
82
|
+
const dbFiles = await this.findDatabaseFiles('.');
|
|
83
|
+
for (const dbFile of dbFiles) {
|
|
84
|
+
if (!this.knownLocations.includes(dbFile)) {
|
|
85
|
+
const stats = await fs.stat(dbFile);
|
|
86
|
+
found.sqlite.push({
|
|
87
|
+
path: dbFile,
|
|
88
|
+
size: stats.size,
|
|
89
|
+
modified: stats.mtime,
|
|
90
|
+
});
|
|
91
|
+
found.total++;
|
|
92
|
+
found.sizeBytes += stats.size;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
} catch (err) {
|
|
96
|
+
// Ignore scan errors
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
return found;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Find all .db files recursively
|
|
104
|
+
*/
|
|
105
|
+
async findDatabaseFiles(dir, files = []) {
|
|
106
|
+
try {
|
|
107
|
+
const items = await fs.readdir(dir);
|
|
108
|
+
|
|
109
|
+
for (const item of items) {
|
|
110
|
+
// Skip node_modules and hidden directories
|
|
111
|
+
if (item === 'node_modules' || item.startsWith('.git')) continue;
|
|
112
|
+
|
|
113
|
+
const fullPath = path.join(dir, item);
|
|
114
|
+
const stat = await fs.stat(fullPath);
|
|
115
|
+
|
|
116
|
+
if (stat.isDirectory() && item.startsWith('.')) {
|
|
117
|
+
// Check hidden directories for db files
|
|
118
|
+
await this.findDatabaseFiles(fullPath, files);
|
|
119
|
+
} else if (item.endsWith('.db')) {
|
|
120
|
+
files.push(fullPath);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
} catch (err) {
|
|
124
|
+
// Ignore permission errors
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
return files;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* Create consolidation plan
|
|
132
|
+
*/
|
|
133
|
+
async createConsolidationPlan(locations) {
|
|
134
|
+
const plan = {
|
|
135
|
+
steps: [],
|
|
136
|
+
estimatedTime: 0,
|
|
137
|
+
totalData: locations.sizeBytes,
|
|
138
|
+
backupRequired: locations.total > 0,
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
// Step 1: Backup existing data
|
|
142
|
+
if (plan.backupRequired) {
|
|
143
|
+
plan.steps.push({
|
|
144
|
+
action: 'backup',
|
|
145
|
+
description: 'Create backups of all existing memory stores',
|
|
146
|
+
sources: [...locations.json, ...locations.sqlite].map((l) => l.path),
|
|
147
|
+
destination: this.primaryLocations.backup,
|
|
148
|
+
});
|
|
149
|
+
plan.estimatedTime += 2; // seconds
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
// Step 2: Convert JSON stores to unified format
|
|
153
|
+
if (locations.json.length > 0) {
|
|
154
|
+
plan.steps.push({
|
|
155
|
+
action: 'convert-json',
|
|
156
|
+
description: 'Convert JSON memory stores to unified format',
|
|
157
|
+
sources: locations.json.map((l) => l.path),
|
|
158
|
+
destination: this.primaryLocations.sqlite,
|
|
159
|
+
});
|
|
160
|
+
plan.estimatedTime += locations.json.length * 1;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
// Step 3: Merge SQLite databases
|
|
164
|
+
if (locations.sqlite.length > 0) {
|
|
165
|
+
plan.steps.push({
|
|
166
|
+
action: 'merge-sqlite',
|
|
167
|
+
description: 'Merge SQLite databases into unified store',
|
|
168
|
+
sources: locations.sqlite.map((l) => l.path),
|
|
169
|
+
destination: this.primaryLocations.sqlite,
|
|
170
|
+
});
|
|
171
|
+
plan.estimatedTime += locations.sqlite.length * 2;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
// Step 4: Create indices for performance
|
|
175
|
+
plan.steps.push({
|
|
176
|
+
action: 'optimize',
|
|
177
|
+
description: 'Create indices and optimize unified database',
|
|
178
|
+
destination: this.primaryLocations.sqlite,
|
|
179
|
+
});
|
|
180
|
+
plan.estimatedTime += 1;
|
|
181
|
+
|
|
182
|
+
// Step 5: Update configuration
|
|
183
|
+
plan.steps.push({
|
|
184
|
+
action: 'update-config',
|
|
185
|
+
description: 'Update memory configuration to use unified store',
|
|
186
|
+
config: {
|
|
187
|
+
memoryStore: this.primaryLocations.sqlite,
|
|
188
|
+
backupLocation: this.primaryLocations.backup,
|
|
189
|
+
legacySupport: true,
|
|
190
|
+
},
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
return plan;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
* Execute consolidation plan
|
|
198
|
+
*/
|
|
199
|
+
async executeConsolidation(plan, options = {}) {
|
|
200
|
+
const results = {
|
|
201
|
+
success: false,
|
|
202
|
+
stepsCompleted: 0,
|
|
203
|
+
errors: [],
|
|
204
|
+
backupPath: null,
|
|
205
|
+
newStorePath: null,
|
|
206
|
+
};
|
|
207
|
+
|
|
208
|
+
try {
|
|
209
|
+
for (const step of plan.steps) {
|
|
210
|
+
printInfo(`Executing: ${step.description}`);
|
|
211
|
+
|
|
212
|
+
switch (step.action) {
|
|
213
|
+
case 'backup':
|
|
214
|
+
results.backupPath = await this.createBackups(step.sources, step.destination);
|
|
215
|
+
break;
|
|
216
|
+
|
|
217
|
+
case 'convert-json':
|
|
218
|
+
await this.convertJsonToSqlite(step.sources, step.destination);
|
|
219
|
+
break;
|
|
220
|
+
|
|
221
|
+
case 'merge-sqlite':
|
|
222
|
+
await this.mergeSqliteDatabases(step.sources, step.destination);
|
|
223
|
+
break;
|
|
224
|
+
|
|
225
|
+
case 'optimize':
|
|
226
|
+
await this.optimizeDatabase(step.destination);
|
|
227
|
+
break;
|
|
228
|
+
|
|
229
|
+
case 'update-config':
|
|
230
|
+
await this.updateConfiguration(step.config);
|
|
231
|
+
break;
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
results.stepsCompleted++;
|
|
235
|
+
printSuccess(`ā ${step.description}`);
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
results.success = true;
|
|
239
|
+
results.newStorePath = this.primaryLocations.sqlite;
|
|
240
|
+
} catch (err) {
|
|
241
|
+
results.errors.push(err.message);
|
|
242
|
+
printError(`Failed at step ${results.stepsCompleted + 1}: ${err.message}`);
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
return results;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
/**
|
|
249
|
+
* Create backups of all memory stores
|
|
250
|
+
*/
|
|
251
|
+
async createBackups(sources, backupDir) {
|
|
252
|
+
const timestamp = new Date().toISOString().replace(/[:.]/g, '-');
|
|
253
|
+
const backupPath = path.join(backupDir, `backup-${timestamp}`);
|
|
254
|
+
|
|
255
|
+
await fs.mkdir(backupPath, { recursive: true });
|
|
256
|
+
|
|
257
|
+
for (const source of sources) {
|
|
258
|
+
if (existsSync(source)) {
|
|
259
|
+
const filename = path.basename(source);
|
|
260
|
+
const dest = path.join(backupPath, filename);
|
|
261
|
+
await fs.copyFile(source, dest);
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
return backupPath;
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
/**
|
|
269
|
+
* Convert JSON memory stores to SQLite
|
|
270
|
+
*/
|
|
271
|
+
async convertJsonToSqlite(jsonFiles, dbPath) {
|
|
272
|
+
if (!sqlite3 || !sqliteOpen) {
|
|
273
|
+
throw new Error('SQLite modules not available. Install sqlite3 and sqlite packages.');
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
await fs.mkdir(path.dirname(dbPath), { recursive: true });
|
|
277
|
+
|
|
278
|
+
const db = await sqliteOpen({
|
|
279
|
+
filename: dbPath,
|
|
280
|
+
driver: sqlite3.Database,
|
|
281
|
+
});
|
|
282
|
+
|
|
283
|
+
// Create unified schema
|
|
284
|
+
await db.exec(`
|
|
285
|
+
CREATE TABLE IF NOT EXISTS memory_entries (
|
|
286
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
287
|
+
key TEXT NOT NULL,
|
|
288
|
+
value TEXT NOT NULL,
|
|
289
|
+
namespace TEXT NOT NULL DEFAULT 'default',
|
|
290
|
+
timestamp INTEGER NOT NULL,
|
|
291
|
+
source TEXT,
|
|
292
|
+
UNIQUE(key, namespace)
|
|
293
|
+
);
|
|
294
|
+
|
|
295
|
+
CREATE INDEX IF NOT EXISTS idx_namespace ON memory_entries(namespace);
|
|
296
|
+
CREATE INDEX IF NOT EXISTS idx_timestamp ON memory_entries(timestamp);
|
|
297
|
+
CREATE INDEX IF NOT EXISTS idx_key ON memory_entries(key);
|
|
298
|
+
`);
|
|
299
|
+
|
|
300
|
+
// Import each JSON file
|
|
301
|
+
for (const jsonFile of jsonFiles) {
|
|
302
|
+
if (!existsSync(jsonFile)) continue;
|
|
303
|
+
|
|
304
|
+
try {
|
|
305
|
+
const content = await fs.readFile(jsonFile, 'utf8');
|
|
306
|
+
const data = JSON.parse(content);
|
|
307
|
+
|
|
308
|
+
const stmt = await db.prepare(`
|
|
309
|
+
INSERT OR REPLACE INTO memory_entries (key, value, namespace, timestamp, source)
|
|
310
|
+
VALUES (?, ?, ?, ?, ?)
|
|
311
|
+
`);
|
|
312
|
+
|
|
313
|
+
for (const [namespace, entries] of Object.entries(data)) {
|
|
314
|
+
for (const entry of entries) {
|
|
315
|
+
await stmt.run(
|
|
316
|
+
entry.key,
|
|
317
|
+
entry.value,
|
|
318
|
+
entry.namespace || namespace,
|
|
319
|
+
entry.timestamp,
|
|
320
|
+
jsonFile,
|
|
321
|
+
);
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
await stmt.finalize();
|
|
326
|
+
} catch (err) {
|
|
327
|
+
printWarning(`Failed to import ${jsonFile}: ${err.message}`);
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
await db.close();
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
/**
|
|
335
|
+
* Merge multiple SQLite databases
|
|
336
|
+
*/
|
|
337
|
+
async mergeSqliteDatabases(dbFiles, targetDb) {
|
|
338
|
+
if (!sqlite3 || !sqliteOpen) {
|
|
339
|
+
throw new Error('SQLite modules not available. Install sqlite3 and sqlite packages.');
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
const db = await sqliteOpen({
|
|
343
|
+
filename: targetDb,
|
|
344
|
+
driver: sqlite3.Database,
|
|
345
|
+
});
|
|
346
|
+
|
|
347
|
+
for (const dbFile of dbFiles) {
|
|
348
|
+
if (!existsSync(dbFile) || dbFile === targetDb) continue;
|
|
349
|
+
|
|
350
|
+
try {
|
|
351
|
+
// Attach the source database
|
|
352
|
+
const alias = `db_${path.basename(dbFile, '.db')}`;
|
|
353
|
+
await db.exec(`ATTACH DATABASE '${dbFile}' AS ${alias}`);
|
|
354
|
+
|
|
355
|
+
// Get tables from source database
|
|
356
|
+
const tables = await db.all(`
|
|
357
|
+
SELECT name FROM ${alias}.sqlite_master
|
|
358
|
+
WHERE type='table' AND name LIKE '%memory%'
|
|
359
|
+
`);
|
|
360
|
+
|
|
361
|
+
// Copy data from each memory-related table
|
|
362
|
+
for (const table of tables) {
|
|
363
|
+
try {
|
|
364
|
+
await db.exec(`
|
|
365
|
+
INSERT OR IGNORE INTO memory_entries (key, value, namespace, timestamp, source)
|
|
366
|
+
SELECT
|
|
367
|
+
COALESCE(key, ''),
|
|
368
|
+
COALESCE(value, ''),
|
|
369
|
+
COALESCE(namespace, 'default'),
|
|
370
|
+
COALESCE(timestamp, strftime('%s', 'now') * 1000),
|
|
371
|
+
'${dbFile}'
|
|
372
|
+
FROM ${alias}.${table.name}
|
|
373
|
+
WHERE key IS NOT NULL AND value IS NOT NULL
|
|
374
|
+
`);
|
|
375
|
+
} catch (err) {
|
|
376
|
+
// Table structure might be different, skip
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
await db.exec(`DETACH DATABASE ${alias}`);
|
|
381
|
+
} catch (err) {
|
|
382
|
+
printWarning(`Failed to merge ${dbFile}: ${err.message}`);
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
await db.close();
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
/**
|
|
390
|
+
* Optimize the unified database
|
|
391
|
+
*/
|
|
392
|
+
async optimizeDatabase(dbPath) {
|
|
393
|
+
if (!sqlite3 || !sqliteOpen) {
|
|
394
|
+
throw new Error('SQLite modules not available. Install sqlite3 and sqlite packages.');
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
const db = await sqliteOpen({
|
|
398
|
+
filename: dbPath,
|
|
399
|
+
driver: sqlite3.Database,
|
|
400
|
+
});
|
|
401
|
+
|
|
402
|
+
// Add performance optimizations
|
|
403
|
+
await db.exec(`
|
|
404
|
+
-- Enable Write-Ahead Logging for better performance
|
|
405
|
+
PRAGMA journal_mode = WAL;
|
|
406
|
+
PRAGMA synchronous = NORMAL;
|
|
407
|
+
|
|
408
|
+
-- Optimize database
|
|
409
|
+
VACUUM;
|
|
410
|
+
ANALYZE;
|
|
411
|
+
|
|
412
|
+
-- Create additional indices for common queries
|
|
413
|
+
CREATE INDEX IF NOT EXISTS idx_key_value ON memory_entries(key, value);
|
|
414
|
+
CREATE INDEX IF NOT EXISTS idx_namespace_timestamp ON memory_entries(namespace, timestamp);
|
|
415
|
+
`);
|
|
416
|
+
|
|
417
|
+
await db.close();
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
/**
|
|
421
|
+
* Update configuration to use unified store
|
|
422
|
+
*/
|
|
423
|
+
async updateConfiguration(config) {
|
|
424
|
+
const configPath = './.claude-flow/memory-config.json';
|
|
425
|
+
|
|
426
|
+
await fs.mkdir(path.dirname(configPath), { recursive: true });
|
|
427
|
+
await fs.writeFile(configPath, JSON.stringify(config, null, 2));
|
|
428
|
+
|
|
429
|
+
// Create symlinks for backward compatibility
|
|
430
|
+
if (config.legacySupport) {
|
|
431
|
+
try {
|
|
432
|
+
// Create symlink from old JSON location to new
|
|
433
|
+
if (existsSync('./memory/memory-store.json')) {
|
|
434
|
+
await fs.rename('./memory/memory-store.json', './memory/memory-store.json.old');
|
|
435
|
+
}
|
|
436
|
+
// Note: We don't create actual symlinks to SQLite as JSON/SQLite formats differ
|
|
437
|
+
// Instead, the memory manager will check the config and use the unified store
|
|
438
|
+
} catch (err) {
|
|
439
|
+
// Ignore symlink errors
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
/**
|
|
445
|
+
* Generate consolidation report
|
|
446
|
+
*/
|
|
447
|
+
generateReport(scanResults, plan, executionResults) {
|
|
448
|
+
const report = [];
|
|
449
|
+
|
|
450
|
+
report.push('š Memory Consolidation Report');
|
|
451
|
+
report.push('================================\n');
|
|
452
|
+
|
|
453
|
+
report.push('š Discovered Memory Stores:');
|
|
454
|
+
report.push(` ⢠JSON files: ${scanResults.json.length}`);
|
|
455
|
+
report.push(` ⢠SQLite databases: ${scanResults.sqlite.length}`);
|
|
456
|
+
report.push(` ⢠Total size: ${(scanResults.sizeBytes / 1024 / 1024).toFixed(2)} MB\n`);
|
|
457
|
+
|
|
458
|
+
report.push('š Consolidation Plan:');
|
|
459
|
+
for (const step of plan.steps) {
|
|
460
|
+
report.push(` ā ${step.description}`);
|
|
461
|
+
}
|
|
462
|
+
report.push(` ⢠Estimated time: ${plan.estimatedTime} seconds\n`);
|
|
463
|
+
|
|
464
|
+
if (executionResults) {
|
|
465
|
+
report.push('ā
Execution Results:');
|
|
466
|
+
report.push(` ⢠Success: ${executionResults.success ? 'Yes' : 'No'}`);
|
|
467
|
+
report.push(` ⢠Steps completed: ${executionResults.stepsCompleted}/${plan.steps.length}`);
|
|
468
|
+
|
|
469
|
+
if (executionResults.backupPath) {
|
|
470
|
+
report.push(` ⢠Backup location: ${executionResults.backupPath}`);
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
if (executionResults.newStorePath) {
|
|
474
|
+
report.push(` ⢠Unified store: ${executionResults.newStorePath}`);
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
if (executionResults.errors.length > 0) {
|
|
478
|
+
report.push('\nā Errors:');
|
|
479
|
+
for (const error of executionResults.errors) {
|
|
480
|
+
report.push(` ⢠${error}`);
|
|
481
|
+
}
|
|
482
|
+
}
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
return report.join('\n');
|
|
486
|
+
}
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
/**
|
|
490
|
+
* Memory consolidation command
|
|
491
|
+
*/
|
|
492
|
+
export async function memoryConsolidationCommand(subArgs, flags) {
|
|
493
|
+
// Load SQLite modules if available
|
|
494
|
+
const sqliteAvailable = await loadSqliteModules();
|
|
495
|
+
|
|
496
|
+
const consolidator = new MemoryConsolidator();
|
|
497
|
+
const action = subArgs[0];
|
|
498
|
+
|
|
499
|
+
switch (action) {
|
|
500
|
+
case 'scan':
|
|
501
|
+
await scanMemoryStores(consolidator);
|
|
502
|
+
break;
|
|
503
|
+
|
|
504
|
+
case 'plan':
|
|
505
|
+
await createConsolidationPlan(consolidator);
|
|
506
|
+
break;
|
|
507
|
+
|
|
508
|
+
case 'execute':
|
|
509
|
+
await executeConsolidation(consolidator, flags);
|
|
510
|
+
break;
|
|
511
|
+
|
|
512
|
+
case 'report':
|
|
513
|
+
await generateConsolidationReport(consolidator);
|
|
514
|
+
break;
|
|
515
|
+
|
|
516
|
+
default:
|
|
517
|
+
showConsolidationHelp();
|
|
518
|
+
}
|
|
519
|
+
}
|
|
520
|
+
|
|
521
|
+
async function scanMemoryStores(consolidator) {
|
|
522
|
+
printInfo('Scanning for memory storage locations...');
|
|
523
|
+
|
|
524
|
+
const results = await consolidator.scanMemoryLocations();
|
|
525
|
+
|
|
526
|
+
printSuccess(`Found ${results.total} memory storage locations:`);
|
|
527
|
+
|
|
528
|
+
if (results.json.length > 0) {
|
|
529
|
+
console.log('\nš JSON Stores:');
|
|
530
|
+
for (const store of results.json) {
|
|
531
|
+
console.log(` ⢠${store.path} (${(store.size / 1024).toFixed(1)} KB)`);
|
|
532
|
+
}
|
|
533
|
+
}
|
|
534
|
+
|
|
535
|
+
if (results.sqlite.length > 0) {
|
|
536
|
+
console.log('\nšļø SQLite Databases:');
|
|
537
|
+
for (const db of results.sqlite) {
|
|
538
|
+
console.log(` ⢠${db.path} (${(db.size / 1024).toFixed(1)} KB)`);
|
|
539
|
+
}
|
|
540
|
+
}
|
|
541
|
+
|
|
542
|
+
console.log(`\nš¾ Total size: ${(results.sizeBytes / 1024 / 1024).toFixed(2)} MB`);
|
|
543
|
+
}
|
|
544
|
+
|
|
545
|
+
async function createConsolidationPlan(consolidator) {
|
|
546
|
+
const scanResults = await consolidator.scanMemoryLocations();
|
|
547
|
+
const plan = await consolidator.createConsolidationPlan(scanResults);
|
|
548
|
+
|
|
549
|
+
printSuccess('š Consolidation Plan Created:');
|
|
550
|
+
|
|
551
|
+
for (let i = 0; i < plan.steps.length; i++) {
|
|
552
|
+
const step = plan.steps[i];
|
|
553
|
+
console.log(`\n${i + 1}. ${step.description}`);
|
|
554
|
+
|
|
555
|
+
if (step.sources) {
|
|
556
|
+
console.log(' Sources:');
|
|
557
|
+
for (const source of step.sources) {
|
|
558
|
+
console.log(` ⢠${source}`);
|
|
559
|
+
}
|
|
560
|
+
}
|
|
561
|
+
|
|
562
|
+
if (step.destination) {
|
|
563
|
+
console.log(` Destination: ${step.destination}`);
|
|
564
|
+
}
|
|
565
|
+
}
|
|
566
|
+
|
|
567
|
+
console.log(`\nā±ļø Estimated time: ${plan.estimatedTime} seconds`);
|
|
568
|
+
console.log('\nRun "memory-consolidate execute" to perform consolidation');
|
|
569
|
+
}
|
|
570
|
+
|
|
571
|
+
async function executeConsolidation(consolidator, flags) {
|
|
572
|
+
const sqliteAvailable = await loadSqliteModules();
|
|
573
|
+
|
|
574
|
+
if (!sqliteAvailable) {
|
|
575
|
+
printError('SQLite modules not available.');
|
|
576
|
+
printInfo('Install required packages: npm install sqlite3 sqlite');
|
|
577
|
+
return;
|
|
578
|
+
}
|
|
579
|
+
|
|
580
|
+
const scanResults = await consolidator.scanMemoryLocations();
|
|
581
|
+
|
|
582
|
+
if (scanResults.total === 0) {
|
|
583
|
+
printWarning('No memory stores found to consolidate');
|
|
584
|
+
return;
|
|
585
|
+
}
|
|
586
|
+
|
|
587
|
+
const plan = await consolidator.createConsolidationPlan(scanResults);
|
|
588
|
+
|
|
589
|
+
if (!flags.force) {
|
|
590
|
+
printWarning('This will consolidate all memory stores into a unified database.');
|
|
591
|
+
printWarning('A backup will be created before any changes are made.');
|
|
592
|
+
console.log('\nUse --force flag to proceed without confirmation');
|
|
593
|
+
return;
|
|
594
|
+
}
|
|
595
|
+
|
|
596
|
+
printInfo('Starting memory consolidation...');
|
|
597
|
+
const results = await consolidator.executeConsolidation(plan);
|
|
598
|
+
|
|
599
|
+
const report = consolidator.generateReport(scanResults, plan, results);
|
|
600
|
+
console.log('\n' + report);
|
|
601
|
+
|
|
602
|
+
if (results.success) {
|
|
603
|
+
printSuccess('\nā
Memory consolidation completed successfully!');
|
|
604
|
+
console.log(`Unified store location: ${results.newStorePath}`);
|
|
605
|
+
} else {
|
|
606
|
+
printError('\nā Memory consolidation failed');
|
|
607
|
+
console.log('Check the errors above and try again');
|
|
608
|
+
}
|
|
609
|
+
}
|
|
610
|
+
|
|
611
|
+
async function generateConsolidationReport(consolidator) {
|
|
612
|
+
const scanResults = await consolidator.scanMemoryLocations();
|
|
613
|
+
const plan = await consolidator.createConsolidationPlan(scanResults);
|
|
614
|
+
|
|
615
|
+
const report = consolidator.generateReport(scanResults, plan);
|
|
616
|
+
console.log(report);
|
|
617
|
+
}
|
|
618
|
+
|
|
619
|
+
function showConsolidationHelp() {
|
|
620
|
+
console.log('Memory consolidation commands:');
|
|
621
|
+
console.log(' scan Scan for all memory storage locations');
|
|
622
|
+
console.log(' plan Create a consolidation plan');
|
|
623
|
+
console.log(' execute Execute the consolidation (use --force to skip confirmation)');
|
|
624
|
+
console.log(' report Generate a consolidation report');
|
|
625
|
+
console.log();
|
|
626
|
+
console.log('Examples:');
|
|
627
|
+
console.log(' memory-consolidate scan');
|
|
628
|
+
console.log(' memory-consolidate plan');
|
|
629
|
+
console.log(' memory-consolidate execute --force');
|
|
630
|
+
console.log(' memory-consolidate report');
|
|
631
|
+
}
|