moflo 4.0.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/agents/MIGRATION_SUMMARY.md +222 -0
- package/.claude/agents/analysis/analyze-code-quality.md +179 -0
- package/.claude/agents/analysis/code-analyzer.md +210 -0
- package/.claude/agents/analysis/code-review/analyze-code-quality.md +179 -0
- package/.claude/agents/architecture/system-design/arch-system-design.md +155 -0
- package/.claude/agents/base-template-generator.md +42 -0
- package/.claude/agents/consensus/byzantine-coordinator.md +63 -0
- package/.claude/agents/consensus/crdt-synchronizer.md +997 -0
- package/.claude/agents/consensus/gossip-coordinator.md +63 -0
- package/.claude/agents/consensus/performance-benchmarker.md +851 -0
- package/.claude/agents/consensus/quorum-manager.md +823 -0
- package/.claude/agents/consensus/raft-manager.md +63 -0
- package/.claude/agents/consensus/security-manager.md +622 -0
- package/.claude/agents/core/coder.md +266 -0
- package/.claude/agents/core/planner.md +168 -0
- package/.claude/agents/core/researcher.md +190 -0
- package/.claude/agents/core/reviewer.md +326 -0
- package/.claude/agents/core/tester.md +319 -0
- package/.claude/agents/custom/test-long-runner.md +44 -0
- package/.claude/agents/data/ml/data-ml-model.md +193 -0
- package/.claude/agents/database-specialist.yaml +21 -0
- package/.claude/agents/development/backend/dev-backend-api.md +142 -0
- package/.claude/agents/development/dev-backend-api.md +345 -0
- package/.claude/agents/devops/ci-cd/ops-cicd-github.md +164 -0
- package/.claude/agents/documentation/api-docs/docs-api-openapi.md +174 -0
- package/.claude/agents/dual-mode/codex-coordinator.md +224 -0
- package/.claude/agents/dual-mode/codex-worker.md +211 -0
- package/.claude/agents/dual-mode/dual-orchestrator.md +291 -0
- package/.claude/agents/flow-nexus/app-store.md +88 -0
- package/.claude/agents/flow-nexus/authentication.md +69 -0
- package/.claude/agents/flow-nexus/challenges.md +81 -0
- package/.claude/agents/flow-nexus/neural-network.md +88 -0
- package/.claude/agents/flow-nexus/payments.md +83 -0
- package/.claude/agents/flow-nexus/sandbox.md +76 -0
- package/.claude/agents/flow-nexus/swarm.md +76 -0
- package/.claude/agents/flow-nexus/user-tools.md +96 -0
- package/.claude/agents/flow-nexus/workflow.md +84 -0
- package/.claude/agents/github/code-review-swarm.md +538 -0
- package/.claude/agents/github/github-modes.md +173 -0
- package/.claude/agents/github/issue-tracker.md +319 -0
- package/.claude/agents/github/multi-repo-swarm.md +553 -0
- package/.claude/agents/github/pr-manager.md +191 -0
- package/.claude/agents/github/project-board-sync.md +509 -0
- package/.claude/agents/github/release-manager.md +367 -0
- package/.claude/agents/github/release-swarm.md +583 -0
- package/.claude/agents/github/repo-architect.md +398 -0
- package/.claude/agents/github/swarm-issue.md +573 -0
- package/.claude/agents/github/swarm-pr.md +428 -0
- package/.claude/agents/github/sync-coordinator.md +452 -0
- package/.claude/agents/github/workflow-automation.md +635 -0
- package/.claude/agents/goal/agent.md +816 -0
- package/.claude/agents/goal/code-goal-planner.md +446 -0
- package/.claude/agents/goal/goal-planner.md +168 -0
- package/.claude/agents/hive-mind/collective-intelligence-coordinator.md +130 -0
- package/.claude/agents/hive-mind/queen-coordinator.md +203 -0
- package/.claude/agents/hive-mind/scout-explorer.md +242 -0
- package/.claude/agents/hive-mind/swarm-memory-manager.md +193 -0
- package/.claude/agents/hive-mind/worker-specialist.md +217 -0
- package/.claude/agents/index.yaml +17 -0
- package/.claude/agents/neural/safla-neural.md +74 -0
- package/.claude/agents/optimization/benchmark-suite.md +665 -0
- package/.claude/agents/optimization/load-balancer.md +431 -0
- package/.claude/agents/optimization/performance-monitor.md +672 -0
- package/.claude/agents/optimization/resource-allocator.md +674 -0
- package/.claude/agents/optimization/topology-optimizer.md +808 -0
- package/.claude/agents/payments/agentic-payments.md +126 -0
- package/.claude/agents/project-coordinator.yaml +15 -0
- package/.claude/agents/python-specialist.yaml +21 -0
- package/.claude/agents/reasoning/agent.md +816 -0
- package/.claude/agents/reasoning/goal-planner.md +73 -0
- package/.claude/agents/security-auditor.yaml +20 -0
- package/.claude/agents/sona/sona-learning-optimizer.md +74 -0
- package/.claude/agents/sparc/architecture.md +472 -0
- package/.claude/agents/sparc/pseudocode.md +318 -0
- package/.claude/agents/sparc/refinement.md +525 -0
- package/.claude/agents/sparc/specification.md +276 -0
- package/.claude/agents/specialized/mobile/spec-mobile-react-native.md +225 -0
- package/.claude/agents/sublinear/consensus-coordinator.md +338 -0
- package/.claude/agents/sublinear/matrix-optimizer.md +185 -0
- package/.claude/agents/sublinear/pagerank-analyzer.md +299 -0
- package/.claude/agents/sublinear/performance-optimizer.md +368 -0
- package/.claude/agents/sublinear/trading-predictor.md +246 -0
- package/.claude/agents/swarm/adaptive-coordinator.md +396 -0
- package/.claude/agents/swarm/hierarchical-coordinator.md +327 -0
- package/.claude/agents/swarm/mesh-coordinator.md +392 -0
- package/.claude/agents/templates/automation-smart-agent.md +205 -0
- package/.claude/agents/templates/coordinator-swarm-init.md +105 -0
- package/.claude/agents/templates/github-pr-manager.md +177 -0
- package/.claude/agents/templates/implementer-sparc-coder.md +259 -0
- package/.claude/agents/templates/memory-coordinator.md +187 -0
- package/.claude/agents/templates/migration-plan.md +746 -0
- package/.claude/agents/templates/orchestrator-task.md +139 -0
- package/.claude/agents/templates/performance-analyzer.md +199 -0
- package/.claude/agents/templates/sparc-coordinator.md +183 -0
- package/.claude/agents/testing/production-validator.md +395 -0
- package/.claude/agents/testing/tdd-london-swarm.md +244 -0
- package/.claude/agents/testing/unit/tdd-london-swarm.md +244 -0
- package/.claude/agents/testing/validation/production-validator.md +395 -0
- package/.claude/agents/typescript-specialist.yaml +21 -0
- package/.claude/agents/v3/database-specialist.yaml +21 -0
- package/.claude/agents/v3/index.yaml +17 -0
- package/.claude/agents/v3/project-coordinator.yaml +15 -0
- package/.claude/agents/v3/python-specialist.yaml +21 -0
- package/.claude/agents/v3/test-architect.yaml +20 -0
- package/.claude/agents/v3/typescript-specialist.yaml +21 -0
- package/.claude/agents/v3/v3-integration-architect.md +346 -0
- package/.claude/agents/v3/v3-memory-specialist.md +318 -0
- package/.claude/agents/v3/v3-performance-engineer.md +397 -0
- package/.claude/agents/v3/v3-queen-coordinator.md +98 -0
- package/.claude/agents/v3/v3-security-architect.md +174 -0
- package/.claude/checkpoints/1767754460.json +8 -0
- package/.claude/commands/agents/README.md +10 -0
- package/.claude/commands/agents/agent-capabilities.md +21 -0
- package/.claude/commands/agents/agent-coordination.md +28 -0
- package/.claude/commands/agents/agent-spawning.md +28 -0
- package/.claude/commands/agents/agent-types.md +26 -0
- package/.claude/commands/analysis/COMMAND_COMPLIANCE_REPORT.md +54 -0
- package/.claude/commands/analysis/README.md +9 -0
- package/.claude/commands/analysis/bottleneck-detect.md +162 -0
- package/.claude/commands/analysis/performance-bottlenecks.md +59 -0
- package/.claude/commands/analysis/performance-report.md +25 -0
- package/.claude/commands/analysis/token-efficiency.md +45 -0
- package/.claude/commands/analysis/token-usage.md +25 -0
- package/.claude/commands/automation/README.md +9 -0
- package/.claude/commands/automation/auto-agent.md +122 -0
- package/.claude/commands/automation/self-healing.md +106 -0
- package/.claude/commands/automation/session-memory.md +90 -0
- package/.claude/commands/automation/smart-agents.md +73 -0
- package/.claude/commands/automation/smart-spawn.md +25 -0
- package/.claude/commands/automation/workflow-select.md +25 -0
- package/.claude/commands/claude-flow-help.md +103 -0
- package/.claude/commands/claude-flow-memory.md +107 -0
- package/.claude/commands/claude-flow-swarm.md +205 -0
- package/.claude/commands/coordination/README.md +9 -0
- package/.claude/commands/coordination/agent-spawn.md +25 -0
- package/.claude/commands/coordination/init.md +44 -0
- package/.claude/commands/coordination/orchestrate.md +43 -0
- package/.claude/commands/coordination/spawn.md +45 -0
- package/.claude/commands/coordination/swarm-init.md +85 -0
- package/.claude/commands/coordination/task-orchestrate.md +25 -0
- package/.claude/commands/flow-nexus/app-store.md +124 -0
- package/.claude/commands/flow-nexus/challenges.md +120 -0
- package/.claude/commands/flow-nexus/login-registration.md +65 -0
- package/.claude/commands/flow-nexus/neural-network.md +134 -0
- package/.claude/commands/flow-nexus/payments.md +116 -0
- package/.claude/commands/flow-nexus/sandbox.md +83 -0
- package/.claude/commands/flow-nexus/swarm.md +87 -0
- package/.claude/commands/flow-nexus/user-tools.md +152 -0
- package/.claude/commands/flow-nexus/workflow.md +115 -0
- package/.claude/commands/github/README.md +11 -0
- package/.claude/commands/github/code-review-swarm.md +514 -0
- package/.claude/commands/github/code-review.md +25 -0
- package/.claude/commands/github/github-modes.md +147 -0
- package/.claude/commands/github/github-swarm.md +121 -0
- package/.claude/commands/github/issue-tracker.md +292 -0
- package/.claude/commands/github/issue-triage.md +25 -0
- package/.claude/commands/github/multi-repo-swarm.md +519 -0
- package/.claude/commands/github/pr-enhance.md +26 -0
- package/.claude/commands/github/pr-manager.md +170 -0
- package/.claude/commands/github/project-board-sync.md +471 -0
- package/.claude/commands/github/release-manager.md +338 -0
- package/.claude/commands/github/release-swarm.md +544 -0
- package/.claude/commands/github/repo-analyze.md +25 -0
- package/.claude/commands/github/repo-architect.md +367 -0
- package/.claude/commands/github/swarm-issue.md +482 -0
- package/.claude/commands/github/swarm-pr.md +285 -0
- package/.claude/commands/github/sync-coordinator.md +301 -0
- package/.claude/commands/github/workflow-automation.md +442 -0
- package/.claude/commands/hive-mind/README.md +17 -0
- package/.claude/commands/hive-mind/hive-mind-consensus.md +8 -0
- package/.claude/commands/hive-mind/hive-mind-init.md +18 -0
- package/.claude/commands/hive-mind/hive-mind-memory.md +8 -0
- package/.claude/commands/hive-mind/hive-mind-metrics.md +8 -0
- package/.claude/commands/hive-mind/hive-mind-resume.md +8 -0
- package/.claude/commands/hive-mind/hive-mind-sessions.md +8 -0
- package/.claude/commands/hive-mind/hive-mind-spawn.md +21 -0
- package/.claude/commands/hive-mind/hive-mind-status.md +8 -0
- package/.claude/commands/hive-mind/hive-mind-stop.md +8 -0
- package/.claude/commands/hive-mind/hive-mind-wizard.md +8 -0
- package/.claude/commands/hive-mind/hive-mind.md +27 -0
- package/.claude/commands/hooks/README.md +11 -0
- package/.claude/commands/hooks/overview.md +58 -0
- package/.claude/commands/hooks/post-edit.md +117 -0
- package/.claude/commands/hooks/post-task.md +112 -0
- package/.claude/commands/hooks/pre-edit.md +113 -0
- package/.claude/commands/hooks/pre-task.md +111 -0
- package/.claude/commands/hooks/session-end.md +118 -0
- package/.claude/commands/hooks/setup.md +103 -0
- package/.claude/commands/memory/README.md +9 -0
- package/.claude/commands/memory/memory-persist.md +25 -0
- package/.claude/commands/memory/memory-search.md +25 -0
- package/.claude/commands/memory/memory-usage.md +25 -0
- package/.claude/commands/memory/neural.md +47 -0
- package/.claude/commands/monitoring/README.md +9 -0
- package/.claude/commands/monitoring/agent-metrics.md +25 -0
- package/.claude/commands/monitoring/agents.md +44 -0
- package/.claude/commands/monitoring/real-time-view.md +25 -0
- package/.claude/commands/monitoring/status.md +46 -0
- package/.claude/commands/monitoring/swarm-monitor.md +25 -0
- package/.claude/commands/optimization/README.md +9 -0
- package/.claude/commands/optimization/auto-topology.md +62 -0
- package/.claude/commands/optimization/cache-manage.md +25 -0
- package/.claude/commands/optimization/parallel-execute.md +25 -0
- package/.claude/commands/optimization/parallel-execution.md +50 -0
- package/.claude/commands/optimization/topology-optimize.md +25 -0
- package/.claude/commands/pair/README.md +261 -0
- package/.claude/commands/pair/commands.md +546 -0
- package/.claude/commands/pair/config.md +510 -0
- package/.claude/commands/pair/examples.md +512 -0
- package/.claude/commands/pair/modes.md +348 -0
- package/.claude/commands/pair/session.md +407 -0
- package/.claude/commands/pair/start.md +209 -0
- package/.claude/commands/sparc/analyzer.md +52 -0
- package/.claude/commands/sparc/architect.md +53 -0
- package/.claude/commands/sparc/ask.md +97 -0
- package/.claude/commands/sparc/batch-executor.md +54 -0
- package/.claude/commands/sparc/code.md +89 -0
- package/.claude/commands/sparc/coder.md +54 -0
- package/.claude/commands/sparc/debug.md +83 -0
- package/.claude/commands/sparc/debugger.md +54 -0
- package/.claude/commands/sparc/designer.md +53 -0
- package/.claude/commands/sparc/devops.md +109 -0
- package/.claude/commands/sparc/docs-writer.md +80 -0
- package/.claude/commands/sparc/documenter.md +54 -0
- package/.claude/commands/sparc/innovator.md +54 -0
- package/.claude/commands/sparc/integration.md +83 -0
- package/.claude/commands/sparc/mcp.md +117 -0
- package/.claude/commands/sparc/memory-manager.md +54 -0
- package/.claude/commands/sparc/optimizer.md +54 -0
- package/.claude/commands/sparc/orchestrator.md +132 -0
- package/.claude/commands/sparc/post-deployment-monitoring-mode.md +83 -0
- package/.claude/commands/sparc/refinement-optimization-mode.md +83 -0
- package/.claude/commands/sparc/researcher.md +54 -0
- package/.claude/commands/sparc/reviewer.md +54 -0
- package/.claude/commands/sparc/security-review.md +80 -0
- package/.claude/commands/sparc/sparc-modes.md +174 -0
- package/.claude/commands/sparc/sparc.md +111 -0
- package/.claude/commands/sparc/spec-pseudocode.md +80 -0
- package/.claude/commands/sparc/supabase-admin.md +348 -0
- package/.claude/commands/sparc/swarm-coordinator.md +54 -0
- package/.claude/commands/sparc/tdd.md +54 -0
- package/.claude/commands/sparc/tester.md +54 -0
- package/.claude/commands/sparc/tutorial.md +79 -0
- package/.claude/commands/sparc/workflow-manager.md +54 -0
- package/.claude/commands/sparc.md +166 -0
- package/.claude/commands/stream-chain/pipeline.md +121 -0
- package/.claude/commands/stream-chain/run.md +70 -0
- package/.claude/commands/swarm/README.md +15 -0
- package/.claude/commands/swarm/analysis.md +95 -0
- package/.claude/commands/swarm/development.md +96 -0
- package/.claude/commands/swarm/examples.md +168 -0
- package/.claude/commands/swarm/maintenance.md +102 -0
- package/.claude/commands/swarm/optimization.md +117 -0
- package/.claude/commands/swarm/research.md +136 -0
- package/.claude/commands/swarm/swarm-analysis.md +8 -0
- package/.claude/commands/swarm/swarm-background.md +8 -0
- package/.claude/commands/swarm/swarm-init.md +19 -0
- package/.claude/commands/swarm/swarm-modes.md +8 -0
- package/.claude/commands/swarm/swarm-monitor.md +8 -0
- package/.claude/commands/swarm/swarm-spawn.md +19 -0
- package/.claude/commands/swarm/swarm-status.md +8 -0
- package/.claude/commands/swarm/swarm-strategies.md +8 -0
- package/.claude/commands/swarm/swarm.md +27 -0
- package/.claude/commands/swarm/testing.md +131 -0
- package/.claude/commands/training/README.md +9 -0
- package/.claude/commands/training/model-update.md +25 -0
- package/.claude/commands/training/neural-patterns.md +74 -0
- package/.claude/commands/training/neural-train.md +25 -0
- package/.claude/commands/training/pattern-learn.md +25 -0
- package/.claude/commands/training/specialization.md +63 -0
- package/.claude/commands/truth/start.md +143 -0
- package/.claude/commands/verify/check.md +50 -0
- package/.claude/commands/verify/start.md +128 -0
- package/.claude/commands/workflows/README.md +9 -0
- package/.claude/commands/workflows/development.md +78 -0
- package/.claude/commands/workflows/research.md +63 -0
- package/.claude/commands/workflows/workflow-create.md +25 -0
- package/.claude/commands/workflows/workflow-execute.md +25 -0
- package/.claude/commands/workflows/workflow-export.md +25 -0
- package/.claude/config/v3-dependency-optimization.json +266 -0
- package/.claude/config/v3-performance-targets.json +251 -0
- package/.claude/helpers/README.md +97 -0
- package/.claude/helpers/adr-compliance.sh +186 -0
- package/.claude/helpers/aggressive-microcompact.mjs +36 -0
- package/.claude/helpers/auto-commit.sh +178 -0
- package/.claude/helpers/auto-memory-hook.mjs +363 -0
- package/.claude/helpers/checkpoint-manager.sh +251 -0
- package/.claude/helpers/context-persistence-hook.mjs +1979 -0
- package/.claude/helpers/daemon-manager.sh +252 -0
- package/.claude/helpers/ddd-tracker.sh +144 -0
- package/.claude/helpers/github-safe.js +106 -0
- package/.claude/helpers/github-setup.sh +28 -0
- package/.claude/helpers/guidance-hook.sh +13 -0
- package/.claude/helpers/guidance-hooks.sh +102 -0
- package/.claude/helpers/health-monitor.sh +108 -0
- package/.claude/helpers/hook-handler.cjs +229 -0
- package/.claude/helpers/intelligence.cjs +197 -0
- package/.claude/helpers/learning-hooks.sh +329 -0
- package/.claude/helpers/learning-optimizer.sh +127 -0
- package/.claude/helpers/learning-service.mjs +1144 -0
- package/.claude/helpers/memory.cjs +84 -0
- package/.claude/helpers/metrics-db.mjs +488 -0
- package/.claude/helpers/patch-aggressive-prune.mjs +184 -0
- package/.claude/helpers/pattern-consolidator.sh +86 -0
- package/.claude/helpers/perf-worker.sh +160 -0
- package/.claude/helpers/quick-start.sh +19 -0
- package/.claude/helpers/router.cjs +62 -0
- package/.claude/helpers/security-scanner.sh +127 -0
- package/.claude/helpers/session.cjs +125 -0
- package/.claude/helpers/setup-mcp.sh +18 -0
- package/.claude/helpers/standard-checkpoint-hooks.sh +189 -0
- package/.claude/helpers/statusline.cjs +742 -0
- package/.claude/helpers/swarm-comms.sh +353 -0
- package/.claude/helpers/swarm-hooks.sh +761 -0
- package/.claude/helpers/swarm-monitor.sh +211 -0
- package/.claude/helpers/sync-v3-metrics.sh +245 -0
- package/.claude/helpers/update-v3-progress.sh +166 -0
- package/.claude/helpers/v3-quick-status.sh +58 -0
- package/.claude/helpers/v3.sh +111 -0
- package/.claude/helpers/validate-v3-config.sh +216 -0
- package/.claude/helpers/worker-manager.sh +170 -0
- package/.claude/mcp.json +13 -0
- package/.claude/settings copy.json +526 -0
- package/.claude/settings.json +305 -0
- package/.claude/skills/agentdb-advanced/SKILL.md +550 -0
- package/.claude/skills/agentdb-learning/SKILL.md +545 -0
- package/.claude/skills/agentdb-memory-patterns/SKILL.md +339 -0
- package/.claude/skills/agentdb-optimization/SKILL.md +509 -0
- package/.claude/skills/agentdb-vector-search/SKILL.md +339 -0
- package/.claude/skills/agentic-jujutsu/SKILL.md +645 -0
- package/.claude/skills/dual-mode/README.md +71 -0
- package/.claude/skills/dual-mode/dual-collect.md +103 -0
- package/.claude/skills/dual-mode/dual-coordinate.md +85 -0
- package/.claude/skills/dual-mode/dual-spawn.md +81 -0
- package/.claude/skills/flow-nexus-neural/SKILL.md +738 -0
- package/.claude/skills/flow-nexus-platform/SKILL.md +1157 -0
- package/.claude/skills/flow-nexus-swarm/SKILL.md +610 -0
- package/.claude/skills/github-code-review/SKILL.md +1140 -0
- package/.claude/skills/github-multi-repo/SKILL.md +874 -0
- package/.claude/skills/github-project-management/SKILL.md +1277 -0
- package/.claude/skills/github-release-management/SKILL.md +1081 -0
- package/.claude/skills/github-workflow-automation/SKILL.md +1065 -0
- package/.claude/skills/hive-mind-advanced/SKILL.md +712 -0
- package/.claude/skills/hooks-automation/SKILL.md +1201 -0
- package/.claude/skills/pair-programming/SKILL.md +1202 -0
- package/.claude/skills/performance-analysis/SKILL.md +563 -0
- package/.claude/skills/reasoningbank-agentdb/SKILL.md +446 -0
- package/.claude/skills/reasoningbank-intelligence/SKILL.md +201 -0
- package/.claude/skills/skill-builder/SKILL.md +910 -0
- package/.claude/skills/sparc-methodology/SKILL.md +1115 -0
- package/.claude/skills/stream-chain/SKILL.md +563 -0
- package/.claude/skills/swarm-advanced/SKILL.md +973 -0
- package/.claude/skills/swarm-orchestration/SKILL.md +179 -0
- package/.claude/skills/v3-cli-modernization/SKILL.md +872 -0
- package/.claude/skills/v3-core-implementation/SKILL.md +797 -0
- package/.claude/skills/v3-ddd-architecture/SKILL.md +442 -0
- package/.claude/skills/v3-integration-deep/SKILL.md +241 -0
- package/.claude/skills/v3-mcp-optimization/SKILL.md +777 -0
- package/.claude/skills/v3-memory-unification/SKILL.md +174 -0
- package/.claude/skills/v3-performance-optimization/SKILL.md +390 -0
- package/.claude/skills/v3-security-overhaul/SKILL.md +82 -0
- package/.claude/skills/v3-swarm-coordination/SKILL.md +340 -0
- package/.claude/skills/verification-quality/SKILL.md +649 -0
- package/.claude/skills/worker-benchmarks/skill.md +135 -0
- package/.claude/skills/worker-integration/skill.md +154 -0
- package/.claude/statusline-command.sh +176 -0
- package/.claude/statusline.mjs +109 -0
- package/.claude/statusline.sh +431 -0
- package/.claude/workflow-state.json +8 -0
- package/.claude-plugin/README.md +720 -0
- package/.claude-plugin/docs/INSTALLATION.md +261 -0
- package/.claude-plugin/docs/PLUGIN_SUMMARY.md +361 -0
- package/.claude-plugin/docs/QUICKSTART.md +361 -0
- package/.claude-plugin/docs/STRUCTURE.md +128 -0
- package/.claude-plugin/hooks/hooks.json +74 -0
- package/.claude-plugin/marketplace.json +96 -0
- package/.claude-plugin/plugin.json +71 -0
- package/.claude-plugin/scripts/install.sh +234 -0
- package/.claude-plugin/scripts/uninstall.sh +36 -0
- package/.claude-plugin/scripts/verify.sh +108 -0
- package/LICENSE +21 -0
- package/README.md +148 -0
- package/bin/cli.js +12 -0
- package/bin/npx-repair.js +7 -0
- package/bin/npx-safe-launch.js +9 -0
- package/package.json +109 -0
- package/v3/@claude-flow/cli/README.md +7536 -0
- package/v3/@claude-flow/cli/bin/cli.js +156 -0
- package/v3/@claude-flow/cli/bin/mcp-server.js +189 -0
- package/v3/@claude-flow/cli/bin/preinstall.cjs +2 -0
- package/v3/@claude-flow/cli/dist/src/appliance/gguf-engine.d.ts +91 -0
- package/v3/@claude-flow/cli/dist/src/appliance/gguf-engine.js +425 -0
- package/v3/@claude-flow/cli/dist/src/appliance/ruvllm-bridge.d.ts +102 -0
- package/v3/@claude-flow/cli/dist/src/appliance/ruvllm-bridge.js +292 -0
- package/v3/@claude-flow/cli/dist/src/appliance/rvfa-builder.d.ts +44 -0
- package/v3/@claude-flow/cli/dist/src/appliance/rvfa-builder.js +329 -0
- package/v3/@claude-flow/cli/dist/src/appliance/rvfa-distribution.d.ts +97 -0
- package/v3/@claude-flow/cli/dist/src/appliance/rvfa-distribution.js +370 -0
- package/v3/@claude-flow/cli/dist/src/appliance/rvfa-format.d.ts +111 -0
- package/v3/@claude-flow/cli/dist/src/appliance/rvfa-format.js +393 -0
- package/v3/@claude-flow/cli/dist/src/appliance/rvfa-runner.d.ts +69 -0
- package/v3/@claude-flow/cli/dist/src/appliance/rvfa-runner.js +238 -0
- package/v3/@claude-flow/cli/dist/src/appliance/rvfa-signing.d.ts +123 -0
- package/v3/@claude-flow/cli/dist/src/appliance/rvfa-signing.js +347 -0
- package/v3/@claude-flow/cli/dist/src/benchmarks/pretrain/index.d.ts +58 -0
- package/v3/@claude-flow/cli/dist/src/benchmarks/pretrain/index.js +404 -0
- package/v3/@claude-flow/cli/dist/src/commands/agent.d.ts +8 -0
- package/v3/@claude-flow/cli/dist/src/commands/agent.js +857 -0
- package/v3/@claude-flow/cli/dist/src/commands/analyze.d.ts +19 -0
- package/v3/@claude-flow/cli/dist/src/commands/analyze.js +1823 -0
- package/v3/@claude-flow/cli/dist/src/commands/appliance-advanced.d.ts +9 -0
- package/v3/@claude-flow/cli/dist/src/commands/appliance-advanced.js +215 -0
- package/v3/@claude-flow/cli/dist/src/commands/appliance.d.ts +8 -0
- package/v3/@claude-flow/cli/dist/src/commands/appliance.js +406 -0
- package/v3/@claude-flow/cli/dist/src/commands/benchmark.d.ts +10 -0
- package/v3/@claude-flow/cli/dist/src/commands/benchmark.js +459 -0
- package/v3/@claude-flow/cli/dist/src/commands/claims.d.ts +10 -0
- package/v3/@claude-flow/cli/dist/src/commands/claims.js +373 -0
- package/v3/@claude-flow/cli/dist/src/commands/completions.d.ts +10 -0
- package/v3/@claude-flow/cli/dist/src/commands/completions.js +539 -0
- package/v3/@claude-flow/cli/dist/src/commands/config.d.ts +8 -0
- package/v3/@claude-flow/cli/dist/src/commands/config.js +406 -0
- package/v3/@claude-flow/cli/dist/src/commands/daemon.d.ts +8 -0
- package/v3/@claude-flow/cli/dist/src/commands/daemon.js +609 -0
- package/v3/@claude-flow/cli/dist/src/commands/deployment.d.ts +10 -0
- package/v3/@claude-flow/cli/dist/src/commands/deployment.js +289 -0
- package/v3/@claude-flow/cli/dist/src/commands/doctor.d.ts +10 -0
- package/v3/@claude-flow/cli/dist/src/commands/doctor.js +603 -0
- package/v3/@claude-flow/cli/dist/src/commands/embeddings.d.ts +18 -0
- package/v3/@claude-flow/cli/dist/src/commands/embeddings.js +1576 -0
- package/v3/@claude-flow/cli/dist/src/commands/gate.d.ts +23 -0
- package/v3/@claude-flow/cli/dist/src/commands/gate.js +54 -0
- package/v3/@claude-flow/cli/dist/src/commands/guidance.d.ts +8 -0
- package/v3/@claude-flow/cli/dist/src/commands/guidance.js +560 -0
- package/v3/@claude-flow/cli/dist/src/commands/hive-mind.d.ts +11 -0
- package/v3/@claude-flow/cli/dist/src/commands/hive-mind.js +1230 -0
- package/v3/@claude-flow/cli/dist/src/commands/hooks.d.ts +8 -0
- package/v3/@claude-flow/cli/dist/src/commands/hooks.js +3945 -0
- package/v3/@claude-flow/cli/dist/src/commands/index.d.ts +113 -0
- package/v3/@claude-flow/cli/dist/src/commands/index.js +372 -0
- package/v3/@claude-flow/cli/dist/src/commands/init.d.ts +8 -0
- package/v3/@claude-flow/cli/dist/src/commands/init.js +990 -0
- package/v3/@claude-flow/cli/dist/src/commands/issues.d.ts +21 -0
- package/v3/@claude-flow/cli/dist/src/commands/issues.js +567 -0
- package/v3/@claude-flow/cli/dist/src/commands/mcp.d.ts +11 -0
- package/v3/@claude-flow/cli/dist/src/commands/mcp.js +715 -0
- package/v3/@claude-flow/cli/dist/src/commands/memory.d.ts +8 -0
- package/v3/@claude-flow/cli/dist/src/commands/memory.js +2425 -0
- package/v3/@claude-flow/cli/dist/src/commands/migrate.d.ts +8 -0
- package/v3/@claude-flow/cli/dist/src/commands/migrate.js +410 -0
- package/v3/@claude-flow/cli/dist/src/commands/neural.d.ts +10 -0
- package/v3/@claude-flow/cli/dist/src/commands/neural.js +1448 -0
- package/v3/@claude-flow/cli/dist/src/commands/orc.d.ts +17 -0
- package/v3/@claude-flow/cli/dist/src/commands/orc.js +629 -0
- package/v3/@claude-flow/cli/dist/src/commands/performance.d.ts +10 -0
- package/v3/@claude-flow/cli/dist/src/commands/performance.js +579 -0
- package/v3/@claude-flow/cli/dist/src/commands/plugins.d.ts +11 -0
- package/v3/@claude-flow/cli/dist/src/commands/plugins.js +820 -0
- package/v3/@claude-flow/cli/dist/src/commands/process.d.ts +10 -0
- package/v3/@claude-flow/cli/dist/src/commands/process.js +641 -0
- package/v3/@claude-flow/cli/dist/src/commands/progress.d.ts +11 -0
- package/v3/@claude-flow/cli/dist/src/commands/progress.js +259 -0
- package/v3/@claude-flow/cli/dist/src/commands/providers.d.ts +10 -0
- package/v3/@claude-flow/cli/dist/src/commands/providers.js +232 -0
- package/v3/@claude-flow/cli/dist/src/commands/route.d.ts +16 -0
- package/v3/@claude-flow/cli/dist/src/commands/route.js +813 -0
- package/v3/@claude-flow/cli/dist/src/commands/ruvector/backup.d.ts +11 -0
- package/v3/@claude-flow/cli/dist/src/commands/ruvector/backup.js +746 -0
- package/v3/@claude-flow/cli/dist/src/commands/ruvector/benchmark.d.ts +11 -0
- package/v3/@claude-flow/cli/dist/src/commands/ruvector/benchmark.js +480 -0
- package/v3/@claude-flow/cli/dist/src/commands/ruvector/import.d.ts +18 -0
- package/v3/@claude-flow/cli/dist/src/commands/ruvector/import.js +350 -0
- package/v3/@claude-flow/cli/dist/src/commands/ruvector/index.d.ts +29 -0
- package/v3/@claude-flow/cli/dist/src/commands/ruvector/index.js +129 -0
- package/v3/@claude-flow/cli/dist/src/commands/ruvector/init.d.ts +11 -0
- package/v3/@claude-flow/cli/dist/src/commands/ruvector/init.js +431 -0
- package/v3/@claude-flow/cli/dist/src/commands/ruvector/migrate.d.ts +11 -0
- package/v3/@claude-flow/cli/dist/src/commands/ruvector/migrate.js +481 -0
- package/v3/@claude-flow/cli/dist/src/commands/ruvector/optimize.d.ts +11 -0
- package/v3/@claude-flow/cli/dist/src/commands/ruvector/optimize.js +503 -0
- package/v3/@claude-flow/cli/dist/src/commands/ruvector/setup.d.ts +18 -0
- package/v3/@claude-flow/cli/dist/src/commands/ruvector/setup.js +765 -0
- package/v3/@claude-flow/cli/dist/src/commands/ruvector/status.d.ts +11 -0
- package/v3/@claude-flow/cli/dist/src/commands/ruvector/status.js +456 -0
- package/v3/@claude-flow/cli/dist/src/commands/security.d.ts +10 -0
- package/v3/@claude-flow/cli/dist/src/commands/security.js +576 -0
- package/v3/@claude-flow/cli/dist/src/commands/session.d.ts +8 -0
- package/v3/@claude-flow/cli/dist/src/commands/session.js +750 -0
- package/v3/@claude-flow/cli/dist/src/commands/start.d.ts +8 -0
- package/v3/@claude-flow/cli/dist/src/commands/start.js +418 -0
- package/v3/@claude-flow/cli/dist/src/commands/status.d.ts +8 -0
- package/v3/@claude-flow/cli/dist/src/commands/status.js +591 -0
- package/v3/@claude-flow/cli/dist/src/commands/swarm.d.ts +8 -0
- package/v3/@claude-flow/cli/dist/src/commands/swarm.js +748 -0
- package/v3/@claude-flow/cli/dist/src/commands/task.d.ts +8 -0
- package/v3/@claude-flow/cli/dist/src/commands/task.js +671 -0
- package/v3/@claude-flow/cli/dist/src/commands/transfer-store.d.ts +13 -0
- package/v3/@claude-flow/cli/dist/src/commands/transfer-store.js +428 -0
- package/v3/@claude-flow/cli/dist/src/commands/update.d.ts +8 -0
- package/v3/@claude-flow/cli/dist/src/commands/update.js +276 -0
- package/v3/@claude-flow/cli/dist/src/commands/workflow.d.ts +8 -0
- package/v3/@claude-flow/cli/dist/src/commands/workflow.js +617 -0
- package/v3/@claude-flow/cli/dist/src/config/moflo-config.d.ts +43 -0
- package/v3/@claude-flow/cli/dist/src/config/moflo-config.js +181 -0
- package/v3/@claude-flow/cli/dist/src/config-adapter.d.ts +15 -0
- package/v3/@claude-flow/cli/dist/src/config-adapter.js +186 -0
- package/v3/@claude-flow/cli/dist/src/index.d.ts +76 -0
- package/v3/@claude-flow/cli/dist/src/index.js +470 -0
- package/v3/@claude-flow/cli/dist/src/infrastructure/in-memory-repositories.d.ts +68 -0
- package/v3/@claude-flow/cli/dist/src/infrastructure/in-memory-repositories.js +264 -0
- package/v3/@claude-flow/cli/dist/src/init/claudemd-generator.d.ts +25 -0
- package/v3/@claude-flow/cli/dist/src/init/claudemd-generator.js +486 -0
- package/v3/@claude-flow/cli/dist/src/init/executor.d.ts +41 -0
- package/v3/@claude-flow/cli/dist/src/init/executor.js +1741 -0
- package/v3/@claude-flow/cli/dist/src/init/helpers-generator.d.ts +60 -0
- package/v3/@claude-flow/cli/dist/src/init/helpers-generator.js +1166 -0
- package/v3/@claude-flow/cli/dist/src/init/index.d.ts +13 -0
- package/v3/@claude-flow/cli/dist/src/init/index.js +15 -0
- package/v3/@claude-flow/cli/dist/src/init/mcp-generator.d.ts +26 -0
- package/v3/@claude-flow/cli/dist/src/init/mcp-generator.js +116 -0
- package/v3/@claude-flow/cli/dist/src/init/moflo-init.d.ts +14 -0
- package/v3/@claude-flow/cli/dist/src/init/moflo-init.js +392 -0
- package/v3/@claude-flow/cli/dist/src/init/settings-generator.d.ts +14 -0
- package/v3/@claude-flow/cli/dist/src/init/settings-generator.js +399 -0
- package/v3/@claude-flow/cli/dist/src/init/statusline-generator.d.ts +28 -0
- package/v3/@claude-flow/cli/dist/src/init/statusline-generator.js +818 -0
- package/v3/@claude-flow/cli/dist/src/init/types.d.ts +287 -0
- package/v3/@claude-flow/cli/dist/src/init/types.js +259 -0
- package/v3/@claude-flow/cli/dist/src/mcp-client.d.ts +92 -0
- package/v3/@claude-flow/cli/dist/src/mcp-client.js +237 -0
- package/v3/@claude-flow/cli/dist/src/mcp-server.d.ts +161 -0
- package/v3/@claude-flow/cli/dist/src/mcp-server.js +627 -0
- package/v3/@claude-flow/cli/dist/src/mcp-tools/agent-tools.d.ts +9 -0
- package/v3/@claude-flow/cli/dist/src/mcp-tools/agent-tools.js +549 -0
- package/v3/@claude-flow/cli/dist/src/mcp-tools/agentdb-tools.d.ts +30 -0
- package/v3/@claude-flow/cli/dist/src/mcp-tools/agentdb-tools.js +557 -0
- package/v3/@claude-flow/cli/dist/src/mcp-tools/analyze-tools.d.ts +38 -0
- package/v3/@claude-flow/cli/dist/src/mcp-tools/analyze-tools.js +317 -0
- package/v3/@claude-flow/cli/dist/src/mcp-tools/auto-install.d.ts +83 -0
- package/v3/@claude-flow/cli/dist/src/mcp-tools/auto-install.js +132 -0
- package/v3/@claude-flow/cli/dist/src/mcp-tools/browser-tools.d.ts +13 -0
- package/v3/@claude-flow/cli/dist/src/mcp-tools/browser-tools.js +551 -0
- package/v3/@claude-flow/cli/dist/src/mcp-tools/claims-tools.d.ts +12 -0
- package/v3/@claude-flow/cli/dist/src/mcp-tools/claims-tools.js +732 -0
- package/v3/@claude-flow/cli/dist/src/mcp-tools/config-tools.d.ts +8 -0
- package/v3/@claude-flow/cli/dist/src/mcp-tools/config-tools.js +343 -0
- package/v3/@claude-flow/cli/dist/src/mcp-tools/coordination-tools.d.ts +13 -0
- package/v3/@claude-flow/cli/dist/src/mcp-tools/coordination-tools.js +486 -0
- package/v3/@claude-flow/cli/dist/src/mcp-tools/daa-tools.d.ts +13 -0
- package/v3/@claude-flow/cli/dist/src/mcp-tools/daa-tools.js +426 -0
- package/v3/@claude-flow/cli/dist/src/mcp-tools/embeddings-tools.d.ts +9 -0
- package/v3/@claude-flow/cli/dist/src/mcp-tools/embeddings-tools.js +782 -0
- package/v3/@claude-flow/cli/dist/src/mcp-tools/github-tools.d.ts +13 -0
- package/v3/@claude-flow/cli/dist/src/mcp-tools/github-tools.js +373 -0
- package/v3/@claude-flow/cli/dist/src/mcp-tools/hive-mind-tools.d.ts +8 -0
- package/v3/@claude-flow/cli/dist/src/mcp-tools/hive-mind-tools.js +583 -0
- package/v3/@claude-flow/cli/dist/src/mcp-tools/hooks-tools.d.ts +44 -0
- package/v3/@claude-flow/cli/dist/src/mcp-tools/hooks-tools.js +3045 -0
- package/v3/@claude-flow/cli/dist/src/mcp-tools/index.d.ts +23 -0
- package/v3/@claude-flow/cli/dist/src/mcp-tools/index.js +22 -0
- package/v3/@claude-flow/cli/dist/src/mcp-tools/memory-tools.d.ts +14 -0
- package/v3/@claude-flow/cli/dist/src/mcp-tools/memory-tools.js +499 -0
- package/v3/@claude-flow/cli/dist/src/mcp-tools/neural-tools.d.ts +16 -0
- package/v3/@claude-flow/cli/dist/src/mcp-tools/neural-tools.js +461 -0
- package/v3/@claude-flow/cli/dist/src/mcp-tools/performance-tools.d.ts +16 -0
- package/v3/@claude-flow/cli/dist/src/mcp-tools/performance-tools.js +534 -0
- package/v3/@claude-flow/cli/dist/src/mcp-tools/progress-tools.d.ts +14 -0
- package/v3/@claude-flow/cli/dist/src/mcp-tools/progress-tools.js +348 -0
- package/v3/@claude-flow/cli/dist/src/mcp-tools/security-tools.d.ts +18 -0
- package/v3/@claude-flow/cli/dist/src/mcp-tools/security-tools.js +434 -0
- package/v3/@claude-flow/cli/dist/src/mcp-tools/session-tools.d.ts +8 -0
- package/v3/@claude-flow/cli/dist/src/mcp-tools/session-tools.js +315 -0
- package/v3/@claude-flow/cli/dist/src/mcp-tools/swarm-tools.d.ts +8 -0
- package/v3/@claude-flow/cli/dist/src/mcp-tools/swarm-tools.js +102 -0
- package/v3/@claude-flow/cli/dist/src/mcp-tools/system-tools.d.ts +13 -0
- package/v3/@claude-flow/cli/dist/src/mcp-tools/system-tools.js +417 -0
- package/v3/@claude-flow/cli/dist/src/mcp-tools/task-tools.d.ts +8 -0
- package/v3/@claude-flow/cli/dist/src/mcp-tools/task-tools.js +338 -0
- package/v3/@claude-flow/cli/dist/src/mcp-tools/terminal-tools.d.ts +13 -0
- package/v3/@claude-flow/cli/dist/src/mcp-tools/terminal-tools.js +246 -0
- package/v3/@claude-flow/cli/dist/src/mcp-tools/transfer-tools.d.ts +14 -0
- package/v3/@claude-flow/cli/dist/src/mcp-tools/transfer-tools.js +396 -0
- package/v3/@claude-flow/cli/dist/src/mcp-tools/types.d.ts +31 -0
- package/v3/@claude-flow/cli/dist/src/mcp-tools/types.js +7 -0
- package/v3/@claude-flow/cli/dist/src/mcp-tools/workflow-tools.d.ts +8 -0
- package/v3/@claude-flow/cli/dist/src/mcp-tools/workflow-tools.js +572 -0
- package/v3/@claude-flow/cli/dist/src/memory/ewc-consolidation.d.ts +271 -0
- package/v3/@claude-flow/cli/dist/src/memory/ewc-consolidation.js +542 -0
- package/v3/@claude-flow/cli/dist/src/memory/intelligence.d.ts +285 -0
- package/v3/@claude-flow/cli/dist/src/memory/intelligence.js +794 -0
- package/v3/@claude-flow/cli/dist/src/memory/memory-bridge.d.ts +407 -0
- package/v3/@claude-flow/cli/dist/src/memory/memory-bridge.js +1494 -0
- package/v3/@claude-flow/cli/dist/src/memory/memory-initializer.d.ts +405 -0
- package/v3/@claude-flow/cli/dist/src/memory/memory-initializer.js +2213 -0
- package/v3/@claude-flow/cli/dist/src/memory/sona-optimizer.d.ts +227 -0
- package/v3/@claude-flow/cli/dist/src/memory/sona-optimizer.js +633 -0
- package/v3/@claude-flow/cli/dist/src/output.d.ts +133 -0
- package/v3/@claude-flow/cli/dist/src/output.js +514 -0
- package/v3/@claude-flow/cli/dist/src/parser.d.ts +41 -0
- package/v3/@claude-flow/cli/dist/src/parser.js +377 -0
- package/v3/@claude-flow/cli/dist/src/plugins/manager.d.ts +133 -0
- package/v3/@claude-flow/cli/dist/src/plugins/manager.js +400 -0
- package/v3/@claude-flow/cli/dist/src/plugins/store/discovery.d.ts +88 -0
- package/v3/@claude-flow/cli/dist/src/plugins/store/discovery.js +1147 -0
- package/v3/@claude-flow/cli/dist/src/plugins/store/index.d.ts +76 -0
- package/v3/@claude-flow/cli/dist/src/plugins/store/index.js +141 -0
- package/v3/@claude-flow/cli/dist/src/plugins/store/search.d.ts +46 -0
- package/v3/@claude-flow/cli/dist/src/plugins/store/search.js +230 -0
- package/v3/@claude-flow/cli/dist/src/plugins/store/types.d.ts +274 -0
- package/v3/@claude-flow/cli/dist/src/plugins/store/types.js +7 -0
- package/v3/@claude-flow/cli/dist/src/plugins/tests/demo-plugin-store.d.ts +7 -0
- package/v3/@claude-flow/cli/dist/src/plugins/tests/demo-plugin-store.js +126 -0
- package/v3/@claude-flow/cli/dist/src/plugins/tests/standalone-test.d.ts +12 -0
- package/v3/@claude-flow/cli/dist/src/plugins/tests/standalone-test.js +188 -0
- package/v3/@claude-flow/cli/dist/src/plugins/tests/test-plugin-store.d.ts +7 -0
- package/v3/@claude-flow/cli/dist/src/plugins/tests/test-plugin-store.js +206 -0
- package/v3/@claude-flow/cli/dist/src/production/circuit-breaker.d.ts +101 -0
- package/v3/@claude-flow/cli/dist/src/production/circuit-breaker.js +241 -0
- package/v3/@claude-flow/cli/dist/src/production/error-handler.d.ts +92 -0
- package/v3/@claude-flow/cli/dist/src/production/error-handler.js +299 -0
- package/v3/@claude-flow/cli/dist/src/production/index.d.ts +23 -0
- package/v3/@claude-flow/cli/dist/src/production/index.js +18 -0
- package/v3/@claude-flow/cli/dist/src/production/monitoring.d.ts +161 -0
- package/v3/@claude-flow/cli/dist/src/production/monitoring.js +356 -0
- package/v3/@claude-flow/cli/dist/src/production/rate-limiter.d.ts +80 -0
- package/v3/@claude-flow/cli/dist/src/production/rate-limiter.js +201 -0
- package/v3/@claude-flow/cli/dist/src/production/retry.d.ts +48 -0
- package/v3/@claude-flow/cli/dist/src/production/retry.js +179 -0
- package/v3/@claude-flow/cli/dist/src/prompt.d.ts +44 -0
- package/v3/@claude-flow/cli/dist/src/prompt.js +501 -0
- package/v3/@claude-flow/cli/dist/src/runtime/headless.d.ts +60 -0
- package/v3/@claude-flow/cli/dist/src/runtime/headless.js +284 -0
- package/v3/@claude-flow/cli/dist/src/ruvector/ast-analyzer.d.ts +67 -0
- package/v3/@claude-flow/cli/dist/src/ruvector/ast-analyzer.js +277 -0
- package/v3/@claude-flow/cli/dist/src/ruvector/coverage-router.d.ts +160 -0
- package/v3/@claude-flow/cli/dist/src/ruvector/coverage-router.js +529 -0
- package/v3/@claude-flow/cli/dist/src/ruvector/coverage-tools.d.ts +33 -0
- package/v3/@claude-flow/cli/dist/src/ruvector/coverage-tools.js +157 -0
- package/v3/@claude-flow/cli/dist/src/ruvector/diff-classifier.d.ts +175 -0
- package/v3/@claude-flow/cli/dist/src/ruvector/diff-classifier.js +698 -0
- package/v3/@claude-flow/cli/dist/src/ruvector/enhanced-model-router.d.ts +146 -0
- package/v3/@claude-flow/cli/dist/src/ruvector/enhanced-model-router.js +530 -0
- package/v3/@claude-flow/cli/dist/src/ruvector/flash-attention.d.ts +195 -0
- package/v3/@claude-flow/cli/dist/src/ruvector/flash-attention.js +643 -0
- package/v3/@claude-flow/cli/dist/src/ruvector/graph-analyzer.d.ts +187 -0
- package/v3/@claude-flow/cli/dist/src/ruvector/graph-analyzer.js +929 -0
- package/v3/@claude-flow/cli/dist/src/ruvector/index.d.ts +34 -0
- package/v3/@claude-flow/cli/dist/src/ruvector/index.js +60 -0
- package/v3/@claude-flow/cli/dist/src/ruvector/lora-adapter.d.ts +218 -0
- package/v3/@claude-flow/cli/dist/src/ruvector/lora-adapter.js +455 -0
- package/v3/@claude-flow/cli/dist/src/ruvector/model-router.d.ts +220 -0
- package/v3/@claude-flow/cli/dist/src/ruvector/model-router.js +488 -0
- package/v3/@claude-flow/cli/dist/src/ruvector/moe-router.d.ts +206 -0
- package/v3/@claude-flow/cli/dist/src/ruvector/moe-router.js +626 -0
- package/v3/@claude-flow/cli/dist/src/ruvector/q-learning-router.d.ts +211 -0
- package/v3/@claude-flow/cli/dist/src/ruvector/q-learning-router.js +681 -0
- package/v3/@claude-flow/cli/dist/src/ruvector/semantic-router.d.ts +77 -0
- package/v3/@claude-flow/cli/dist/src/ruvector/semantic-router.js +178 -0
- package/v3/@claude-flow/cli/dist/src/ruvector/vector-db.d.ts +69 -0
- package/v3/@claude-flow/cli/dist/src/ruvector/vector-db.js +243 -0
- package/v3/@claude-flow/cli/dist/src/services/agent-router.d.ts +49 -0
- package/v3/@claude-flow/cli/dist/src/services/agent-router.js +161 -0
- package/v3/@claude-flow/cli/dist/src/services/agentic-flow-bridge.d.ts +50 -0
- package/v3/@claude-flow/cli/dist/src/services/agentic-flow-bridge.js +95 -0
- package/v3/@claude-flow/cli/dist/src/services/claim-service.d.ts +204 -0
- package/v3/@claude-flow/cli/dist/src/services/claim-service.js +818 -0
- package/v3/@claude-flow/cli/dist/src/services/container-worker-pool.d.ts +197 -0
- package/v3/@claude-flow/cli/dist/src/services/container-worker-pool.js +584 -0
- package/v3/@claude-flow/cli/dist/src/services/headless-worker-executor.d.ts +304 -0
- package/v3/@claude-flow/cli/dist/src/services/headless-worker-executor.js +999 -0
- package/v3/@claude-flow/cli/dist/src/services/index.d.ts +15 -0
- package/v3/@claude-flow/cli/dist/src/services/index.js +15 -0
- package/v3/@claude-flow/cli/dist/src/services/learning-service.d.ts +161 -0
- package/v3/@claude-flow/cli/dist/src/services/learning-service.js +679 -0
- package/v3/@claude-flow/cli/dist/src/services/registry-api.d.ts +58 -0
- package/v3/@claude-flow/cli/dist/src/services/registry-api.js +146 -0
- package/v3/@claude-flow/cli/dist/src/services/ruvector-training.d.ts +214 -0
- package/v3/@claude-flow/cli/dist/src/services/ruvector-training.js +497 -0
- package/v3/@claude-flow/cli/dist/src/services/worker-daemon.d.ts +203 -0
- package/v3/@claude-flow/cli/dist/src/services/worker-daemon.js +756 -0
- package/v3/@claude-flow/cli/dist/src/services/worker-queue.d.ts +194 -0
- package/v3/@claude-flow/cli/dist/src/services/worker-queue.js +513 -0
- package/v3/@claude-flow/cli/dist/src/services/workflow-gate.d.ts +77 -0
- package/v3/@claude-flow/cli/dist/src/services/workflow-gate.js +278 -0
- package/v3/@claude-flow/cli/dist/src/suggest.d.ts +53 -0
- package/v3/@claude-flow/cli/dist/src/suggest.js +200 -0
- package/v3/@claude-flow/cli/dist/src/transfer/anonymization/index.d.ts +25 -0
- package/v3/@claude-flow/cli/dist/src/transfer/anonymization/index.js +175 -0
- package/v3/@claude-flow/cli/dist/src/transfer/deploy-seraphine.d.ts +13 -0
- package/v3/@claude-flow/cli/dist/src/transfer/deploy-seraphine.js +205 -0
- package/v3/@claude-flow/cli/dist/src/transfer/export.d.ts +25 -0
- package/v3/@claude-flow/cli/dist/src/transfer/export.js +113 -0
- package/v3/@claude-flow/cli/dist/src/transfer/index.d.ts +12 -0
- package/v3/@claude-flow/cli/dist/src/transfer/index.js +31 -0
- package/v3/@claude-flow/cli/dist/src/transfer/ipfs/client.d.ts +109 -0
- package/v3/@claude-flow/cli/dist/src/transfer/ipfs/client.js +307 -0
- package/v3/@claude-flow/cli/dist/src/transfer/ipfs/upload.d.ts +95 -0
- package/v3/@claude-flow/cli/dist/src/transfer/ipfs/upload.js +411 -0
- package/v3/@claude-flow/cli/dist/src/transfer/models/seraphine.d.ts +72 -0
- package/v3/@claude-flow/cli/dist/src/transfer/models/seraphine.js +373 -0
- package/v3/@claude-flow/cli/dist/src/transfer/serialization/cfp.d.ts +49 -0
- package/v3/@claude-flow/cli/dist/src/transfer/serialization/cfp.js +183 -0
- package/v3/@claude-flow/cli/dist/src/transfer/storage/gcs.d.ts +82 -0
- package/v3/@claude-flow/cli/dist/src/transfer/storage/gcs.js +230 -0
- package/v3/@claude-flow/cli/dist/src/transfer/storage/index.d.ts +6 -0
- package/v3/@claude-flow/cli/dist/src/transfer/storage/index.js +6 -0
- package/v3/@claude-flow/cli/dist/src/transfer/store/discovery.d.ts +84 -0
- package/v3/@claude-flow/cli/dist/src/transfer/store/discovery.js +382 -0
- package/v3/@claude-flow/cli/dist/src/transfer/store/download.d.ts +70 -0
- package/v3/@claude-flow/cli/dist/src/transfer/store/download.js +334 -0
- package/v3/@claude-flow/cli/dist/src/transfer/store/index.d.ts +84 -0
- package/v3/@claude-flow/cli/dist/src/transfer/store/index.js +153 -0
- package/v3/@claude-flow/cli/dist/src/transfer/store/publish.d.ts +76 -0
- package/v3/@claude-flow/cli/dist/src/transfer/store/publish.js +294 -0
- package/v3/@claude-flow/cli/dist/src/transfer/store/registry.d.ts +58 -0
- package/v3/@claude-flow/cli/dist/src/transfer/store/registry.js +285 -0
- package/v3/@claude-flow/cli/dist/src/transfer/store/search.d.ts +54 -0
- package/v3/@claude-flow/cli/dist/src/transfer/store/search.js +232 -0
- package/v3/@claude-flow/cli/dist/src/transfer/store/tests/standalone-test.d.ts +12 -0
- package/v3/@claude-flow/cli/dist/src/transfer/store/tests/standalone-test.js +190 -0
- package/v3/@claude-flow/cli/dist/src/transfer/store/types.d.ts +193 -0
- package/v3/@claude-flow/cli/dist/src/transfer/store/types.js +6 -0
- package/v3/@claude-flow/cli/dist/src/transfer/test-seraphine.d.ts +6 -0
- package/v3/@claude-flow/cli/dist/src/transfer/test-seraphine.js +105 -0
- package/v3/@claude-flow/cli/dist/src/transfer/tests/test-store.d.ts +7 -0
- package/v3/@claude-flow/cli/dist/src/transfer/tests/test-store.js +214 -0
- package/v3/@claude-flow/cli/dist/src/transfer/types.d.ts +245 -0
- package/v3/@claude-flow/cli/dist/src/transfer/types.js +6 -0
- package/v3/@claude-flow/cli/dist/src/types.d.ts +198 -0
- package/v3/@claude-flow/cli/dist/src/types.js +38 -0
- package/v3/@claude-flow/cli/dist/src/update/checker.d.ts +34 -0
- package/v3/@claude-flow/cli/dist/src/update/checker.js +190 -0
- package/v3/@claude-flow/cli/dist/src/update/executor.d.ts +32 -0
- package/v3/@claude-flow/cli/dist/src/update/executor.js +183 -0
- package/v3/@claude-flow/cli/dist/src/update/index.d.ts +33 -0
- package/v3/@claude-flow/cli/dist/src/update/index.js +64 -0
- package/v3/@claude-flow/cli/dist/src/update/rate-limiter.d.ts +20 -0
- package/v3/@claude-flow/cli/dist/src/update/rate-limiter.js +96 -0
- package/v3/@claude-flow/cli/dist/src/update/validator.d.ts +17 -0
- package/v3/@claude-flow/cli/dist/src/update/validator.js +123 -0
- package/v3/@claude-flow/cli/package.json +110 -0
- package/v3/@claude-flow/guidance/README.md +1195 -0
- package/v3/@claude-flow/guidance/package.json +198 -0
- package/v3/@claude-flow/shared/README.md +323 -0
- package/v3/@claude-flow/shared/dist/core/config/defaults.d.ts +41 -0
- package/v3/@claude-flow/shared/dist/core/config/defaults.js +186 -0
- package/v3/@claude-flow/shared/dist/core/config/index.d.ts +8 -0
- package/v3/@claude-flow/shared/dist/core/config/index.js +12 -0
- package/v3/@claude-flow/shared/dist/core/config/loader.d.ts +45 -0
- package/v3/@claude-flow/shared/dist/core/config/loader.js +222 -0
- package/v3/@claude-flow/shared/dist/core/config/schema.d.ts +1134 -0
- package/v3/@claude-flow/shared/dist/core/config/schema.js +158 -0
- package/v3/@claude-flow/shared/dist/core/config/validator.d.ts +92 -0
- package/v3/@claude-flow/shared/dist/core/config/validator.js +147 -0
- package/v3/@claude-flow/shared/dist/core/event-bus.d.ts +31 -0
- package/v3/@claude-flow/shared/dist/core/event-bus.js +197 -0
- package/v3/@claude-flow/shared/dist/core/index.d.ts +15 -0
- package/v3/@claude-flow/shared/dist/core/index.js +19 -0
- package/v3/@claude-flow/shared/dist/core/interfaces/agent.interface.d.ts +200 -0
- package/v3/@claude-flow/shared/dist/core/interfaces/agent.interface.js +6 -0
- package/v3/@claude-flow/shared/dist/core/interfaces/coordinator.interface.d.ts +310 -0
- package/v3/@claude-flow/shared/dist/core/interfaces/coordinator.interface.js +7 -0
- package/v3/@claude-flow/shared/dist/core/interfaces/event.interface.d.ts +224 -0
- package/v3/@claude-flow/shared/dist/core/interfaces/event.interface.js +46 -0
- package/v3/@claude-flow/shared/dist/core/interfaces/index.d.ts +10 -0
- package/v3/@claude-flow/shared/dist/core/interfaces/index.js +15 -0
- package/v3/@claude-flow/shared/dist/core/interfaces/memory.interface.d.ts +298 -0
- package/v3/@claude-flow/shared/dist/core/interfaces/memory.interface.js +7 -0
- package/v3/@claude-flow/shared/dist/core/interfaces/task.interface.d.ts +185 -0
- package/v3/@claude-flow/shared/dist/core/interfaces/task.interface.js +6 -0
- package/v3/@claude-flow/shared/dist/core/orchestrator/event-coordinator.d.ts +35 -0
- package/v3/@claude-flow/shared/dist/core/orchestrator/event-coordinator.js +101 -0
- package/v3/@claude-flow/shared/dist/core/orchestrator/health-monitor.d.ts +60 -0
- package/v3/@claude-flow/shared/dist/core/orchestrator/health-monitor.js +166 -0
- package/v3/@claude-flow/shared/dist/core/orchestrator/index.d.ts +46 -0
- package/v3/@claude-flow/shared/dist/core/orchestrator/index.js +64 -0
- package/v3/@claude-flow/shared/dist/core/orchestrator/lifecycle-manager.d.ts +56 -0
- package/v3/@claude-flow/shared/dist/core/orchestrator/lifecycle-manager.js +195 -0
- package/v3/@claude-flow/shared/dist/core/orchestrator/session-manager.d.ts +83 -0
- package/v3/@claude-flow/shared/dist/core/orchestrator/session-manager.js +193 -0
- package/v3/@claude-flow/shared/dist/core/orchestrator/task-manager.d.ts +49 -0
- package/v3/@claude-flow/shared/dist/core/orchestrator/task-manager.js +253 -0
- package/v3/@claude-flow/shared/dist/events/domain-events.d.ts +282 -0
- package/v3/@claude-flow/shared/dist/events/domain-events.js +165 -0
- package/v3/@claude-flow/shared/dist/events/event-store.d.ts +126 -0
- package/v3/@claude-flow/shared/dist/events/event-store.js +416 -0
- package/v3/@claude-flow/shared/dist/events/event-store.test.d.ts +8 -0
- package/v3/@claude-flow/shared/dist/events/event-store.test.js +293 -0
- package/v3/@claude-flow/shared/dist/events/example-usage.d.ts +10 -0
- package/v3/@claude-flow/shared/dist/events/example-usage.js +193 -0
- package/v3/@claude-flow/shared/dist/events/index.d.ts +21 -0
- package/v3/@claude-flow/shared/dist/events/index.js +22 -0
- package/v3/@claude-flow/shared/dist/events/projections.d.ts +177 -0
- package/v3/@claude-flow/shared/dist/events/projections.js +421 -0
- package/v3/@claude-flow/shared/dist/events/rvf-event-log.d.ts +82 -0
- package/v3/@claude-flow/shared/dist/events/rvf-event-log.js +340 -0
- package/v3/@claude-flow/shared/dist/events/state-reconstructor.d.ts +101 -0
- package/v3/@claude-flow/shared/dist/events/state-reconstructor.js +263 -0
- package/v3/@claude-flow/shared/dist/events.d.ts +80 -0
- package/v3/@claude-flow/shared/dist/events.js +249 -0
- package/v3/@claude-flow/shared/dist/hooks/example-usage.d.ts +42 -0
- package/v3/@claude-flow/shared/dist/hooks/example-usage.js +351 -0
- package/v3/@claude-flow/shared/dist/hooks/executor.d.ts +100 -0
- package/v3/@claude-flow/shared/dist/hooks/executor.js +264 -0
- package/v3/@claude-flow/shared/dist/hooks/hooks.test.d.ts +9 -0
- package/v3/@claude-flow/shared/dist/hooks/hooks.test.js +322 -0
- package/v3/@claude-flow/shared/dist/hooks/index.d.ts +52 -0
- package/v3/@claude-flow/shared/dist/hooks/index.js +51 -0
- package/v3/@claude-flow/shared/dist/hooks/registry.d.ts +133 -0
- package/v3/@claude-flow/shared/dist/hooks/registry.js +277 -0
- package/v3/@claude-flow/shared/dist/hooks/safety/bash-safety.d.ts +105 -0
- package/v3/@claude-flow/shared/dist/hooks/safety/bash-safety.js +481 -0
- package/v3/@claude-flow/shared/dist/hooks/safety/file-organization.d.ts +144 -0
- package/v3/@claude-flow/shared/dist/hooks/safety/file-organization.js +328 -0
- package/v3/@claude-flow/shared/dist/hooks/safety/git-commit.d.ts +158 -0
- package/v3/@claude-flow/shared/dist/hooks/safety/git-commit.js +450 -0
- package/v3/@claude-flow/shared/dist/hooks/safety/index.d.ts +17 -0
- package/v3/@claude-flow/shared/dist/hooks/safety/index.js +17 -0
- package/v3/@claude-flow/shared/dist/hooks/session-hooks.d.ts +234 -0
- package/v3/@claude-flow/shared/dist/hooks/session-hooks.js +334 -0
- package/v3/@claude-flow/shared/dist/hooks/task-hooks.d.ts +163 -0
- package/v3/@claude-flow/shared/dist/hooks/task-hooks.js +326 -0
- package/v3/@claude-flow/shared/dist/hooks/types.d.ts +267 -0
- package/v3/@claude-flow/shared/dist/hooks/types.js +62 -0
- package/v3/@claude-flow/shared/dist/hooks/verify-exports.test.d.ts +9 -0
- package/v3/@claude-flow/shared/dist/hooks/verify-exports.test.js +93 -0
- package/v3/@claude-flow/shared/dist/index.d.ts +20 -0
- package/v3/@claude-flow/shared/dist/index.js +50 -0
- package/v3/@claude-flow/shared/dist/mcp/connection-pool.d.ts +98 -0
- package/v3/@claude-flow/shared/dist/mcp/connection-pool.js +364 -0
- package/v3/@claude-flow/shared/dist/mcp/index.d.ts +69 -0
- package/v3/@claude-flow/shared/dist/mcp/index.js +84 -0
- package/v3/@claude-flow/shared/dist/mcp/server.d.ts +166 -0
- package/v3/@claude-flow/shared/dist/mcp/server.js +593 -0
- package/v3/@claude-flow/shared/dist/mcp/session-manager.d.ts +136 -0
- package/v3/@claude-flow/shared/dist/mcp/session-manager.js +335 -0
- package/v3/@claude-flow/shared/dist/mcp/tool-registry.d.ts +178 -0
- package/v3/@claude-flow/shared/dist/mcp/tool-registry.js +439 -0
- package/v3/@claude-flow/shared/dist/mcp/transport/http.d.ts +104 -0
- package/v3/@claude-flow/shared/dist/mcp/transport/http.js +476 -0
- package/v3/@claude-flow/shared/dist/mcp/transport/index.d.ts +102 -0
- package/v3/@claude-flow/shared/dist/mcp/transport/index.js +238 -0
- package/v3/@claude-flow/shared/dist/mcp/transport/stdio.d.ts +104 -0
- package/v3/@claude-flow/shared/dist/mcp/transport/stdio.js +263 -0
- package/v3/@claude-flow/shared/dist/mcp/transport/websocket.d.ts +133 -0
- package/v3/@claude-flow/shared/dist/mcp/transport/websocket.js +396 -0
- package/v3/@claude-flow/shared/dist/mcp/types.d.ts +438 -0
- package/v3/@claude-flow/shared/dist/mcp/types.js +54 -0
- package/v3/@claude-flow/shared/dist/plugin-interface.d.ts +544 -0
- package/v3/@claude-flow/shared/dist/plugin-interface.js +23 -0
- package/v3/@claude-flow/shared/dist/plugin-loader.d.ts +139 -0
- package/v3/@claude-flow/shared/dist/plugin-loader.js +434 -0
- package/v3/@claude-flow/shared/dist/plugin-registry.d.ts +183 -0
- package/v3/@claude-flow/shared/dist/plugin-registry.js +457 -0
- package/v3/@claude-flow/shared/dist/plugins/index.d.ts +10 -0
- package/v3/@claude-flow/shared/dist/plugins/index.js +10 -0
- package/v3/@claude-flow/shared/dist/plugins/official/hive-mind-plugin.d.ts +106 -0
- package/v3/@claude-flow/shared/dist/plugins/official/hive-mind-plugin.js +241 -0
- package/v3/@claude-flow/shared/dist/plugins/official/index.d.ts +10 -0
- package/v3/@claude-flow/shared/dist/plugins/official/index.js +10 -0
- package/v3/@claude-flow/shared/dist/plugins/official/maestro-plugin.d.ts +121 -0
- package/v3/@claude-flow/shared/dist/plugins/official/maestro-plugin.js +355 -0
- package/v3/@claude-flow/shared/dist/plugins/types.d.ts +93 -0
- package/v3/@claude-flow/shared/dist/plugins/types.js +9 -0
- package/v3/@claude-flow/shared/dist/resilience/bulkhead.d.ts +105 -0
- package/v3/@claude-flow/shared/dist/resilience/bulkhead.js +206 -0
- package/v3/@claude-flow/shared/dist/resilience/circuit-breaker.d.ts +132 -0
- package/v3/@claude-flow/shared/dist/resilience/circuit-breaker.js +233 -0
- package/v3/@claude-flow/shared/dist/resilience/index.d.ts +19 -0
- package/v3/@claude-flow/shared/dist/resilience/index.js +19 -0
- package/v3/@claude-flow/shared/dist/resilience/rate-limiter.d.ts +168 -0
- package/v3/@claude-flow/shared/dist/resilience/rate-limiter.js +314 -0
- package/v3/@claude-flow/shared/dist/resilience/retry.d.ts +91 -0
- package/v3/@claude-flow/shared/dist/resilience/retry.js +159 -0
- package/v3/@claude-flow/shared/dist/security/index.d.ts +10 -0
- package/v3/@claude-flow/shared/dist/security/index.js +12 -0
- package/v3/@claude-flow/shared/dist/security/input-validation.d.ts +73 -0
- package/v3/@claude-flow/shared/dist/security/input-validation.js +201 -0
- package/v3/@claude-flow/shared/dist/security/secure-random.d.ts +92 -0
- package/v3/@claude-flow/shared/dist/security/secure-random.js +142 -0
- package/v3/@claude-flow/shared/dist/services/index.d.ts +7 -0
- package/v3/@claude-flow/shared/dist/services/index.js +7 -0
- package/v3/@claude-flow/shared/dist/services/v3-progress.service.d.ts +124 -0
- package/v3/@claude-flow/shared/dist/services/v3-progress.service.js +402 -0
- package/v3/@claude-flow/shared/dist/types/agent.types.d.ts +137 -0
- package/v3/@claude-flow/shared/dist/types/agent.types.js +6 -0
- package/v3/@claude-flow/shared/dist/types/index.d.ts +11 -0
- package/v3/@claude-flow/shared/dist/types/index.js +17 -0
- package/v3/@claude-flow/shared/dist/types/mcp.types.d.ts +266 -0
- package/v3/@claude-flow/shared/dist/types/mcp.types.js +7 -0
- package/v3/@claude-flow/shared/dist/types/memory.types.d.ts +236 -0
- package/v3/@claude-flow/shared/dist/types/memory.types.js +7 -0
- package/v3/@claude-flow/shared/dist/types/swarm.types.d.ts +186 -0
- package/v3/@claude-flow/shared/dist/types/swarm.types.js +65 -0
- package/v3/@claude-flow/shared/dist/types/task.types.d.ts +178 -0
- package/v3/@claude-flow/shared/dist/types/task.types.js +32 -0
- package/v3/@claude-flow/shared/dist/types.d.ts +197 -0
- package/v3/@claude-flow/shared/dist/types.js +21 -0
- package/v3/@claude-flow/shared/dist/utils/secure-logger.d.ts +69 -0
- package/v3/@claude-flow/shared/dist/utils/secure-logger.js +208 -0
- package/v3/@claude-flow/shared/package.json +42 -0
- package/v3/README.md +493 -0
|
@@ -0,0 +1,2425 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* V3 CLI Memory Command
|
|
3
|
+
* Memory operations for AgentDB integration
|
|
4
|
+
*/
|
|
5
|
+
import * as fs from 'fs';
|
|
6
|
+
import * as pathModule from 'path';
|
|
7
|
+
import { output } from '../output.js';
|
|
8
|
+
import { select, confirm, input } from '../prompt.js';
|
|
9
|
+
import { callMCPTool, MCPClientError } from '../mcp-client.js';
|
|
10
|
+
// Memory backends
|
|
11
|
+
const BACKENDS = [
|
|
12
|
+
{ value: 'agentdb', label: 'AgentDB', hint: 'Vector database with HNSW indexing (150x-12,500x faster)' },
|
|
13
|
+
{ value: 'sqlite', label: 'SQLite', hint: 'Lightweight local storage' },
|
|
14
|
+
{ value: 'hybrid', label: 'Hybrid', hint: 'SQLite + AgentDB (recommended)' },
|
|
15
|
+
{ value: 'memory', label: 'In-Memory', hint: 'Fast but non-persistent' }
|
|
16
|
+
];
|
|
17
|
+
// Store command
|
|
18
|
+
const storeCommand = {
|
|
19
|
+
name: 'store',
|
|
20
|
+
description: 'Store data in memory',
|
|
21
|
+
options: [
|
|
22
|
+
{
|
|
23
|
+
name: 'key',
|
|
24
|
+
short: 'k',
|
|
25
|
+
description: 'Storage key/namespace',
|
|
26
|
+
type: 'string',
|
|
27
|
+
required: true
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
name: 'value',
|
|
31
|
+
// Note: No short flag - global -v is reserved for verbose
|
|
32
|
+
description: 'Value to store (use --value)',
|
|
33
|
+
type: 'string'
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
name: 'namespace',
|
|
37
|
+
short: 'n',
|
|
38
|
+
description: 'Memory namespace',
|
|
39
|
+
type: 'string',
|
|
40
|
+
default: 'default'
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
name: 'ttl',
|
|
44
|
+
description: 'Time to live in seconds',
|
|
45
|
+
type: 'number'
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
name: 'tags',
|
|
49
|
+
description: 'Comma-separated tags',
|
|
50
|
+
type: 'string'
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
name: 'vector',
|
|
54
|
+
description: 'Store as vector embedding',
|
|
55
|
+
type: 'boolean',
|
|
56
|
+
default: false
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
name: 'upsert',
|
|
60
|
+
short: 'u',
|
|
61
|
+
description: 'Update if key exists (insert or replace)',
|
|
62
|
+
type: 'boolean',
|
|
63
|
+
default: false
|
|
64
|
+
}
|
|
65
|
+
],
|
|
66
|
+
examples: [
|
|
67
|
+
{ command: 'claude-flow memory store -k "api/auth" -v "JWT implementation"', description: 'Store text' },
|
|
68
|
+
{ command: 'claude-flow memory store -k "pattern/singleton" --vector', description: 'Store vector' },
|
|
69
|
+
{ command: 'claude-flow memory store -k "pattern" -v "updated" --upsert', description: 'Update existing' }
|
|
70
|
+
],
|
|
71
|
+
action: async (ctx) => {
|
|
72
|
+
const key = ctx.flags.key;
|
|
73
|
+
let value = ctx.flags.value || ctx.args[0];
|
|
74
|
+
const namespace = ctx.flags.namespace;
|
|
75
|
+
const ttl = ctx.flags.ttl;
|
|
76
|
+
const tags = ctx.flags.tags ? ctx.flags.tags.split(',') : [];
|
|
77
|
+
const asVector = ctx.flags.vector;
|
|
78
|
+
const upsert = ctx.flags.upsert;
|
|
79
|
+
if (!key) {
|
|
80
|
+
output.printError('Key is required. Use --key or -k');
|
|
81
|
+
return { success: false, exitCode: 1 };
|
|
82
|
+
}
|
|
83
|
+
if (!value && ctx.interactive) {
|
|
84
|
+
value = await input({
|
|
85
|
+
message: 'Enter value to store:',
|
|
86
|
+
validate: (v) => v.length > 0 || 'Value is required'
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
if (!value) {
|
|
90
|
+
output.printError('Value is required. Use --value');
|
|
91
|
+
return { success: false, exitCode: 1 };
|
|
92
|
+
}
|
|
93
|
+
const storeData = {
|
|
94
|
+
key,
|
|
95
|
+
namespace,
|
|
96
|
+
value,
|
|
97
|
+
ttl,
|
|
98
|
+
tags,
|
|
99
|
+
asVector,
|
|
100
|
+
storedAt: new Date().toISOString(),
|
|
101
|
+
size: Buffer.byteLength(value, 'utf8')
|
|
102
|
+
};
|
|
103
|
+
output.printInfo(`Storing in ${namespace}/${key}...`);
|
|
104
|
+
// Use direct sql.js storage with automatic embedding generation
|
|
105
|
+
try {
|
|
106
|
+
const { storeEntry } = await import('../memory/memory-initializer.js');
|
|
107
|
+
if (asVector) {
|
|
108
|
+
output.writeln(output.dim(' Generating embedding vector...'));
|
|
109
|
+
}
|
|
110
|
+
const result = await storeEntry({
|
|
111
|
+
key,
|
|
112
|
+
value,
|
|
113
|
+
namespace,
|
|
114
|
+
generateEmbeddingFlag: true, // Always generate embeddings for semantic search
|
|
115
|
+
tags,
|
|
116
|
+
ttl,
|
|
117
|
+
upsert
|
|
118
|
+
});
|
|
119
|
+
if (!result.success) {
|
|
120
|
+
output.printError(result.error || 'Failed to store');
|
|
121
|
+
return { success: false, exitCode: 1 };
|
|
122
|
+
}
|
|
123
|
+
output.writeln();
|
|
124
|
+
output.printTable({
|
|
125
|
+
columns: [
|
|
126
|
+
{ key: 'property', header: 'Property', width: 15 },
|
|
127
|
+
{ key: 'val', header: 'Value', width: 40 }
|
|
128
|
+
],
|
|
129
|
+
data: [
|
|
130
|
+
{ property: 'Key', val: key },
|
|
131
|
+
{ property: 'Namespace', val: namespace },
|
|
132
|
+
{ property: 'Size', val: `${storeData.size} bytes` },
|
|
133
|
+
{ property: 'TTL', val: ttl ? `${ttl}s` : 'None' },
|
|
134
|
+
{ property: 'Tags', val: tags.length > 0 ? tags.join(', ') : 'None' },
|
|
135
|
+
{ property: 'Vector', val: result.embedding ? `Yes (${result.embedding.dimensions}-dim)` : 'No' },
|
|
136
|
+
{ property: 'ID', val: result.id.substring(0, 20) }
|
|
137
|
+
]
|
|
138
|
+
});
|
|
139
|
+
output.writeln();
|
|
140
|
+
output.printSuccess('Data stored successfully');
|
|
141
|
+
return { success: true, data: { ...storeData, id: result.id, embedding: result.embedding } };
|
|
142
|
+
}
|
|
143
|
+
catch (error) {
|
|
144
|
+
output.printError(`Failed to store: ${error instanceof Error ? error.message : 'Unknown error'}`);
|
|
145
|
+
return { success: false, exitCode: 1 };
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
};
|
|
149
|
+
// Retrieve command
|
|
150
|
+
const retrieveCommand = {
|
|
151
|
+
name: 'retrieve',
|
|
152
|
+
aliases: ['get'],
|
|
153
|
+
description: 'Retrieve data from memory',
|
|
154
|
+
options: [
|
|
155
|
+
{
|
|
156
|
+
name: 'key',
|
|
157
|
+
short: 'k',
|
|
158
|
+
description: 'Storage key',
|
|
159
|
+
type: 'string'
|
|
160
|
+
},
|
|
161
|
+
{
|
|
162
|
+
name: 'namespace',
|
|
163
|
+
short: 'n',
|
|
164
|
+
description: 'Memory namespace',
|
|
165
|
+
type: 'string',
|
|
166
|
+
default: 'default'
|
|
167
|
+
}
|
|
168
|
+
],
|
|
169
|
+
action: async (ctx) => {
|
|
170
|
+
const key = ctx.flags.key || ctx.args[0];
|
|
171
|
+
const namespace = ctx.flags.namespace;
|
|
172
|
+
if (!key) {
|
|
173
|
+
output.printError('Key is required');
|
|
174
|
+
return { success: false, exitCode: 1 };
|
|
175
|
+
}
|
|
176
|
+
// Use sql.js directly for consistent data access
|
|
177
|
+
try {
|
|
178
|
+
const { getEntry } = await import('../memory/memory-initializer.js');
|
|
179
|
+
const result = await getEntry({ key, namespace });
|
|
180
|
+
if (!result.success) {
|
|
181
|
+
output.printError(`Failed to retrieve: ${result.error}`);
|
|
182
|
+
return { success: false, exitCode: 1 };
|
|
183
|
+
}
|
|
184
|
+
if (!result.found || !result.entry) {
|
|
185
|
+
output.printWarning(`Key not found: ${key}`);
|
|
186
|
+
return { success: false, exitCode: 1, data: { key, found: false } };
|
|
187
|
+
}
|
|
188
|
+
const entry = result.entry;
|
|
189
|
+
if (ctx.flags.format === 'json') {
|
|
190
|
+
output.printJson(entry);
|
|
191
|
+
return { success: true, data: entry };
|
|
192
|
+
}
|
|
193
|
+
output.writeln();
|
|
194
|
+
output.printBox([
|
|
195
|
+
`Namespace: ${entry.namespace}`,
|
|
196
|
+
`Key: ${entry.key}`,
|
|
197
|
+
`Size: ${entry.content.length} bytes`,
|
|
198
|
+
`Access Count: ${entry.accessCount}`,
|
|
199
|
+
`Tags: ${entry.tags.length > 0 ? entry.tags.join(', ') : 'None'}`,
|
|
200
|
+
`Vector: ${entry.hasEmbedding ? 'Yes' : 'No'}`,
|
|
201
|
+
'',
|
|
202
|
+
output.bold('Value:'),
|
|
203
|
+
entry.content
|
|
204
|
+
].join('\n'), 'Memory Entry');
|
|
205
|
+
return { success: true, data: entry };
|
|
206
|
+
}
|
|
207
|
+
catch (error) {
|
|
208
|
+
output.printError(`Failed to retrieve: ${error instanceof Error ? error.message : 'Unknown error'}`);
|
|
209
|
+
return { success: false, exitCode: 1 };
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
};
|
|
213
|
+
// Search command
|
|
214
|
+
const searchCommand = {
|
|
215
|
+
name: 'search',
|
|
216
|
+
description: 'Search memory with semantic/vector search',
|
|
217
|
+
options: [
|
|
218
|
+
{
|
|
219
|
+
name: 'query',
|
|
220
|
+
short: 'q',
|
|
221
|
+
description: 'Search query',
|
|
222
|
+
type: 'string',
|
|
223
|
+
required: true
|
|
224
|
+
},
|
|
225
|
+
{
|
|
226
|
+
name: 'namespace',
|
|
227
|
+
short: 'n',
|
|
228
|
+
description: 'Memory namespace',
|
|
229
|
+
type: 'string'
|
|
230
|
+
},
|
|
231
|
+
{
|
|
232
|
+
name: 'limit',
|
|
233
|
+
short: 'l',
|
|
234
|
+
description: 'Maximum results',
|
|
235
|
+
type: 'number',
|
|
236
|
+
default: 10
|
|
237
|
+
},
|
|
238
|
+
{
|
|
239
|
+
name: 'threshold',
|
|
240
|
+
description: 'Similarity threshold (0-1)',
|
|
241
|
+
type: 'number',
|
|
242
|
+
default: 0.7
|
|
243
|
+
},
|
|
244
|
+
{
|
|
245
|
+
name: 'type',
|
|
246
|
+
short: 't',
|
|
247
|
+
description: 'Search type (semantic, keyword, hybrid)',
|
|
248
|
+
type: 'string',
|
|
249
|
+
default: 'semantic',
|
|
250
|
+
choices: ['semantic', 'keyword', 'hybrid']
|
|
251
|
+
},
|
|
252
|
+
{
|
|
253
|
+
name: 'build-hnsw',
|
|
254
|
+
description: 'Build/rebuild HNSW index before searching (enables 150x-12,500x speedup)',
|
|
255
|
+
type: 'boolean',
|
|
256
|
+
default: false
|
|
257
|
+
}
|
|
258
|
+
],
|
|
259
|
+
examples: [
|
|
260
|
+
{ command: 'claude-flow memory search -q "authentication patterns"', description: 'Semantic search' },
|
|
261
|
+
{ command: 'claude-flow memory search -q "JWT" -t keyword', description: 'Keyword search' },
|
|
262
|
+
{ command: 'claude-flow memory search -q "test" --build-hnsw', description: 'Build HNSW index and search' }
|
|
263
|
+
],
|
|
264
|
+
action: async (ctx) => {
|
|
265
|
+
const query = ctx.flags.query || ctx.args[0];
|
|
266
|
+
const namespace = ctx.flags.namespace || 'all';
|
|
267
|
+
const limit = ctx.flags.limit || 10;
|
|
268
|
+
const threshold = ctx.flags.threshold || 0.3;
|
|
269
|
+
const searchType = ctx.flags.type || 'semantic';
|
|
270
|
+
const buildHnsw = (ctx.flags['build-hnsw'] || ctx.flags.buildHnsw);
|
|
271
|
+
if (!query) {
|
|
272
|
+
output.printError('Query is required. Use --query or -q');
|
|
273
|
+
return { success: false, exitCode: 1 };
|
|
274
|
+
}
|
|
275
|
+
// Build/rebuild HNSW index if requested
|
|
276
|
+
if (buildHnsw) {
|
|
277
|
+
output.printInfo('Building HNSW index...');
|
|
278
|
+
try {
|
|
279
|
+
const { getHNSWIndex, getHNSWStatus } = await import('../memory/memory-initializer.js');
|
|
280
|
+
const startTime = Date.now();
|
|
281
|
+
const index = await getHNSWIndex({ forceRebuild: true });
|
|
282
|
+
const buildTime = Date.now() - startTime;
|
|
283
|
+
if (index) {
|
|
284
|
+
const status = getHNSWStatus();
|
|
285
|
+
output.printSuccess(`HNSW index built (${status.entryCount} vectors, ${buildTime}ms)`);
|
|
286
|
+
output.writeln(output.dim(` Dimensions: ${status.dimensions}, Metric: cosine`));
|
|
287
|
+
output.writeln(output.dim(` Search speedup: ${status.entryCount > 10000 ? '12,500x' : status.entryCount > 1000 ? '150x' : '10x'}`));
|
|
288
|
+
}
|
|
289
|
+
else {
|
|
290
|
+
output.printWarning('HNSW index not available (install @ruvector/core for acceleration)');
|
|
291
|
+
}
|
|
292
|
+
output.writeln();
|
|
293
|
+
}
|
|
294
|
+
catch (error) {
|
|
295
|
+
output.printWarning(`HNSW build failed: ${error instanceof Error ? error.message : 'Unknown error'}`);
|
|
296
|
+
output.writeln(output.dim(' Falling back to brute-force search'));
|
|
297
|
+
output.writeln();
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
output.printInfo(`Searching: "${query}" (${searchType})`);
|
|
301
|
+
output.writeln();
|
|
302
|
+
// Use direct sql.js search with vector similarity
|
|
303
|
+
try {
|
|
304
|
+
const { searchEntries } = await import('../memory/memory-initializer.js');
|
|
305
|
+
const searchResult = await searchEntries({
|
|
306
|
+
query,
|
|
307
|
+
namespace,
|
|
308
|
+
limit,
|
|
309
|
+
threshold
|
|
310
|
+
});
|
|
311
|
+
if (!searchResult.success) {
|
|
312
|
+
output.printError(searchResult.error || 'Search failed');
|
|
313
|
+
return { success: false, exitCode: 1 };
|
|
314
|
+
}
|
|
315
|
+
const results = searchResult.results.map(r => ({
|
|
316
|
+
key: r.key,
|
|
317
|
+
score: r.score,
|
|
318
|
+
namespace: r.namespace,
|
|
319
|
+
preview: r.content
|
|
320
|
+
}));
|
|
321
|
+
if (ctx.flags.format === 'json') {
|
|
322
|
+
output.printJson({ query, searchType, results, searchTime: `${searchResult.searchTime}ms` });
|
|
323
|
+
return { success: true, data: results };
|
|
324
|
+
}
|
|
325
|
+
// Performance stats
|
|
326
|
+
output.writeln(output.dim(` Search time: ${searchResult.searchTime}ms`));
|
|
327
|
+
output.writeln();
|
|
328
|
+
if (results.length === 0) {
|
|
329
|
+
output.printWarning('No results found');
|
|
330
|
+
output.writeln(output.dim('Try: claude-flow memory store -k "key" --value "data"'));
|
|
331
|
+
return { success: true, data: [] };
|
|
332
|
+
}
|
|
333
|
+
output.printTable({
|
|
334
|
+
columns: [
|
|
335
|
+
{ key: 'key', header: 'Key', width: 20 },
|
|
336
|
+
{ key: 'score', header: 'Score', width: 8, align: 'right', format: (v) => Number(v).toFixed(2) },
|
|
337
|
+
{ key: 'namespace', header: 'Namespace', width: 12 },
|
|
338
|
+
{ key: 'preview', header: 'Preview', width: 35 }
|
|
339
|
+
],
|
|
340
|
+
data: results
|
|
341
|
+
});
|
|
342
|
+
output.writeln();
|
|
343
|
+
output.printInfo(`Found ${results.length} results`);
|
|
344
|
+
return { success: true, data: results };
|
|
345
|
+
}
|
|
346
|
+
catch (error) {
|
|
347
|
+
output.printError(`Search failed: ${error instanceof Error ? error.message : 'Unknown error'}`);
|
|
348
|
+
return { success: false, exitCode: 1 };
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
};
|
|
352
|
+
// List command
|
|
353
|
+
const listCommand = {
|
|
354
|
+
name: 'list',
|
|
355
|
+
aliases: ['ls'],
|
|
356
|
+
description: 'List memory entries',
|
|
357
|
+
options: [
|
|
358
|
+
{
|
|
359
|
+
name: 'namespace',
|
|
360
|
+
short: 'n',
|
|
361
|
+
description: 'Filter by namespace',
|
|
362
|
+
type: 'string'
|
|
363
|
+
},
|
|
364
|
+
{
|
|
365
|
+
name: 'tags',
|
|
366
|
+
short: 't',
|
|
367
|
+
description: 'Filter by tags (comma-separated)',
|
|
368
|
+
type: 'string'
|
|
369
|
+
},
|
|
370
|
+
{
|
|
371
|
+
name: 'limit',
|
|
372
|
+
short: 'l',
|
|
373
|
+
description: 'Maximum entries',
|
|
374
|
+
type: 'number',
|
|
375
|
+
default: 20
|
|
376
|
+
}
|
|
377
|
+
],
|
|
378
|
+
action: async (ctx) => {
|
|
379
|
+
const namespace = ctx.flags.namespace;
|
|
380
|
+
const limit = ctx.flags.limit;
|
|
381
|
+
// Use sql.js directly for consistent data access
|
|
382
|
+
try {
|
|
383
|
+
const { listEntries } = await import('../memory/memory-initializer.js');
|
|
384
|
+
const listResult = await listEntries({ namespace, limit, offset: 0 });
|
|
385
|
+
if (!listResult.success) {
|
|
386
|
+
output.printError(`Failed to list: ${listResult.error}`);
|
|
387
|
+
return { success: false, exitCode: 1 };
|
|
388
|
+
}
|
|
389
|
+
// Format entries for display
|
|
390
|
+
const entries = listResult.entries.map(e => ({
|
|
391
|
+
key: e.key,
|
|
392
|
+
namespace: e.namespace,
|
|
393
|
+
size: e.size + ' B',
|
|
394
|
+
vector: e.hasEmbedding ? '✓' : '-',
|
|
395
|
+
accessCount: e.accessCount,
|
|
396
|
+
updated: formatRelativeTime(e.updatedAt)
|
|
397
|
+
}));
|
|
398
|
+
if (ctx.flags.format === 'json') {
|
|
399
|
+
output.printJson(listResult.entries);
|
|
400
|
+
return { success: true, data: listResult.entries };
|
|
401
|
+
}
|
|
402
|
+
output.writeln();
|
|
403
|
+
output.writeln(output.bold('Memory Entries'));
|
|
404
|
+
output.writeln();
|
|
405
|
+
if (entries.length === 0) {
|
|
406
|
+
output.printWarning('No entries found');
|
|
407
|
+
output.printInfo('Store data: claude-flow memory store -k "key" --value "data"');
|
|
408
|
+
return { success: true, data: [] };
|
|
409
|
+
}
|
|
410
|
+
output.printTable({
|
|
411
|
+
columns: [
|
|
412
|
+
{ key: 'key', header: 'Key', width: 25 },
|
|
413
|
+
{ key: 'namespace', header: 'Namespace', width: 12 },
|
|
414
|
+
{ key: 'size', header: 'Size', width: 10, align: 'right' },
|
|
415
|
+
{ key: 'vector', header: 'Vector', width: 8, align: 'center' },
|
|
416
|
+
{ key: 'accessCount', header: 'Accessed', width: 10, align: 'right' },
|
|
417
|
+
{ key: 'updated', header: 'Updated', width: 12 }
|
|
418
|
+
],
|
|
419
|
+
data: entries
|
|
420
|
+
});
|
|
421
|
+
output.writeln();
|
|
422
|
+
output.printInfo(`Showing ${entries.length} of ${listResult.total} entries`);
|
|
423
|
+
return { success: true, data: listResult.entries };
|
|
424
|
+
}
|
|
425
|
+
catch (error) {
|
|
426
|
+
output.printError(`Failed to list: ${error instanceof Error ? error.message : 'Unknown error'}`);
|
|
427
|
+
return { success: false, exitCode: 1 };
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
};
|
|
431
|
+
// Helper function to format relative time
|
|
432
|
+
function formatRelativeTime(isoDate) {
|
|
433
|
+
const now = Date.now();
|
|
434
|
+
const date = new Date(isoDate).getTime();
|
|
435
|
+
const diff = now - date;
|
|
436
|
+
const seconds = Math.floor(diff / 1000);
|
|
437
|
+
const minutes = Math.floor(seconds / 60);
|
|
438
|
+
const hours = Math.floor(minutes / 60);
|
|
439
|
+
const days = Math.floor(hours / 24);
|
|
440
|
+
if (days > 0)
|
|
441
|
+
return `${days}d ago`;
|
|
442
|
+
if (hours > 0)
|
|
443
|
+
return `${hours}h ago`;
|
|
444
|
+
if (minutes > 0)
|
|
445
|
+
return `${minutes}m ago`;
|
|
446
|
+
return 'just now';
|
|
447
|
+
}
|
|
448
|
+
// Delete command
|
|
449
|
+
const deleteCommand = {
|
|
450
|
+
name: 'delete',
|
|
451
|
+
aliases: ['rm'],
|
|
452
|
+
description: 'Delete memory entry',
|
|
453
|
+
options: [
|
|
454
|
+
{
|
|
455
|
+
name: 'key',
|
|
456
|
+
short: 'k',
|
|
457
|
+
description: 'Storage key',
|
|
458
|
+
type: 'string'
|
|
459
|
+
},
|
|
460
|
+
{
|
|
461
|
+
name: 'namespace',
|
|
462
|
+
short: 'n',
|
|
463
|
+
description: 'Memory namespace',
|
|
464
|
+
type: 'string',
|
|
465
|
+
default: 'default'
|
|
466
|
+
},
|
|
467
|
+
{
|
|
468
|
+
name: 'force',
|
|
469
|
+
short: 'f',
|
|
470
|
+
description: 'Skip confirmation',
|
|
471
|
+
type: 'boolean',
|
|
472
|
+
default: false
|
|
473
|
+
}
|
|
474
|
+
],
|
|
475
|
+
examples: [
|
|
476
|
+
{ command: 'claude-flow memory delete -k "mykey"', description: 'Delete entry with default namespace' },
|
|
477
|
+
{ command: 'claude-flow memory delete -k "lesson" -n "lessons"', description: 'Delete entry from specific namespace' },
|
|
478
|
+
{ command: 'claude-flow memory delete mykey -f', description: 'Delete without confirmation' }
|
|
479
|
+
],
|
|
480
|
+
action: async (ctx) => {
|
|
481
|
+
// Support both --key flag and positional argument
|
|
482
|
+
const key = ctx.flags.key || ctx.args[0];
|
|
483
|
+
const namespace = ctx.flags.namespace || 'default';
|
|
484
|
+
const force = ctx.flags.force;
|
|
485
|
+
if (!key) {
|
|
486
|
+
output.printError('Key is required. Use: memory delete -k "key" [-n "namespace"]');
|
|
487
|
+
return { success: false, exitCode: 1 };
|
|
488
|
+
}
|
|
489
|
+
if (!force && ctx.interactive) {
|
|
490
|
+
const confirmed = await confirm({
|
|
491
|
+
message: `Delete memory entry "${key}" from namespace "${namespace}"?`,
|
|
492
|
+
default: false
|
|
493
|
+
});
|
|
494
|
+
if (!confirmed) {
|
|
495
|
+
output.printInfo('Operation cancelled');
|
|
496
|
+
return { success: true };
|
|
497
|
+
}
|
|
498
|
+
}
|
|
499
|
+
// Use sql.js directly for consistent data access (Issue #980)
|
|
500
|
+
try {
|
|
501
|
+
const { deleteEntry } = await import('../memory/memory-initializer.js');
|
|
502
|
+
const result = await deleteEntry({ key, namespace });
|
|
503
|
+
if (!result.success) {
|
|
504
|
+
output.printError(result.error || 'Failed to delete');
|
|
505
|
+
return { success: false, exitCode: 1 };
|
|
506
|
+
}
|
|
507
|
+
if (result.deleted) {
|
|
508
|
+
output.printSuccess(`Deleted "${key}" from namespace "${namespace}"`);
|
|
509
|
+
output.printInfo(`Remaining entries: ${result.remainingEntries}`);
|
|
510
|
+
}
|
|
511
|
+
else {
|
|
512
|
+
output.printWarning(`Key not found: "${key}" in namespace "${namespace}"`);
|
|
513
|
+
}
|
|
514
|
+
return { success: result.deleted, data: result };
|
|
515
|
+
}
|
|
516
|
+
catch (error) {
|
|
517
|
+
output.printError(`Failed to delete: ${error instanceof Error ? error.message : 'Unknown error'}`);
|
|
518
|
+
return { success: false, exitCode: 1 };
|
|
519
|
+
}
|
|
520
|
+
}
|
|
521
|
+
};
|
|
522
|
+
// Stats command
|
|
523
|
+
const statsCommand = {
|
|
524
|
+
name: 'stats',
|
|
525
|
+
description: 'Show memory statistics',
|
|
526
|
+
action: async (ctx) => {
|
|
527
|
+
// Call MCP memory/stats tool for real statistics
|
|
528
|
+
try {
|
|
529
|
+
const statsResult = await callMCPTool('memory_stats', {});
|
|
530
|
+
const stats = {
|
|
531
|
+
backend: statsResult.backend,
|
|
532
|
+
entries: {
|
|
533
|
+
total: statsResult.totalEntries,
|
|
534
|
+
vectors: 0, // Would need vector backend support
|
|
535
|
+
text: statsResult.totalEntries
|
|
536
|
+
},
|
|
537
|
+
storage: {
|
|
538
|
+
total: statsResult.totalSize,
|
|
539
|
+
location: statsResult.location
|
|
540
|
+
},
|
|
541
|
+
version: statsResult.version,
|
|
542
|
+
oldestEntry: statsResult.oldestEntry,
|
|
543
|
+
newestEntry: statsResult.newestEntry
|
|
544
|
+
};
|
|
545
|
+
if (ctx.flags.format === 'json') {
|
|
546
|
+
output.printJson(stats);
|
|
547
|
+
return { success: true, data: stats };
|
|
548
|
+
}
|
|
549
|
+
output.writeln();
|
|
550
|
+
output.writeln(output.bold('Memory Statistics'));
|
|
551
|
+
output.writeln();
|
|
552
|
+
output.writeln(output.bold('Overview'));
|
|
553
|
+
output.printTable({
|
|
554
|
+
columns: [
|
|
555
|
+
{ key: 'metric', header: 'Metric', width: 20 },
|
|
556
|
+
{ key: 'value', header: 'Value', width: 30, align: 'right' }
|
|
557
|
+
],
|
|
558
|
+
data: [
|
|
559
|
+
{ metric: 'Backend', value: stats.backend },
|
|
560
|
+
{ metric: 'Version', value: stats.version },
|
|
561
|
+
{ metric: 'Total Entries', value: stats.entries.total.toLocaleString() },
|
|
562
|
+
{ metric: 'Total Storage', value: stats.storage.total },
|
|
563
|
+
{ metric: 'Location', value: stats.storage.location }
|
|
564
|
+
]
|
|
565
|
+
});
|
|
566
|
+
output.writeln();
|
|
567
|
+
output.writeln(output.bold('Timeline'));
|
|
568
|
+
output.printTable({
|
|
569
|
+
columns: [
|
|
570
|
+
{ key: 'metric', header: 'Metric', width: 20 },
|
|
571
|
+
{ key: 'value', header: 'Value', width: 30, align: 'right' }
|
|
572
|
+
],
|
|
573
|
+
data: [
|
|
574
|
+
{ metric: 'Oldest Entry', value: stats.oldestEntry || 'N/A' },
|
|
575
|
+
{ metric: 'Newest Entry', value: stats.newestEntry || 'N/A' }
|
|
576
|
+
]
|
|
577
|
+
});
|
|
578
|
+
output.writeln();
|
|
579
|
+
output.printInfo('V3 Performance: 150x-12,500x faster search with HNSW indexing');
|
|
580
|
+
return { success: true, data: stats };
|
|
581
|
+
}
|
|
582
|
+
catch (error) {
|
|
583
|
+
output.printError(`Failed to get stats: ${error instanceof Error ? error.message : 'Unknown error'}`);
|
|
584
|
+
return { success: false, exitCode: 1 };
|
|
585
|
+
}
|
|
586
|
+
}
|
|
587
|
+
};
|
|
588
|
+
// Configure command
|
|
589
|
+
const configureCommand = {
|
|
590
|
+
name: 'configure',
|
|
591
|
+
aliases: ['config'],
|
|
592
|
+
description: 'Configure memory backend',
|
|
593
|
+
options: [
|
|
594
|
+
{
|
|
595
|
+
name: 'backend',
|
|
596
|
+
short: 'b',
|
|
597
|
+
description: 'Memory backend',
|
|
598
|
+
type: 'string',
|
|
599
|
+
choices: BACKENDS.map(b => b.value)
|
|
600
|
+
},
|
|
601
|
+
{
|
|
602
|
+
name: 'path',
|
|
603
|
+
description: 'Storage path',
|
|
604
|
+
type: 'string'
|
|
605
|
+
},
|
|
606
|
+
{
|
|
607
|
+
name: 'cache-size',
|
|
608
|
+
description: 'Cache size in MB',
|
|
609
|
+
type: 'number'
|
|
610
|
+
},
|
|
611
|
+
{
|
|
612
|
+
name: 'hnsw-m',
|
|
613
|
+
description: 'HNSW M parameter',
|
|
614
|
+
type: 'number',
|
|
615
|
+
default: 16
|
|
616
|
+
},
|
|
617
|
+
{
|
|
618
|
+
name: 'hnsw-ef',
|
|
619
|
+
description: 'HNSW ef parameter',
|
|
620
|
+
type: 'number',
|
|
621
|
+
default: 200
|
|
622
|
+
}
|
|
623
|
+
],
|
|
624
|
+
action: async (ctx) => {
|
|
625
|
+
let backend = ctx.flags.backend;
|
|
626
|
+
if (!backend && ctx.interactive) {
|
|
627
|
+
backend = await select({
|
|
628
|
+
message: 'Select memory backend:',
|
|
629
|
+
options: BACKENDS,
|
|
630
|
+
default: 'hybrid'
|
|
631
|
+
});
|
|
632
|
+
}
|
|
633
|
+
const config = {
|
|
634
|
+
backend: backend || 'hybrid',
|
|
635
|
+
path: ctx.flags.path || './data/memory',
|
|
636
|
+
cacheSize: ctx.flags.cacheSize || 256,
|
|
637
|
+
hnsw: {
|
|
638
|
+
m: ctx.flags.hnswM || 16,
|
|
639
|
+
ef: ctx.flags.hnswEf || 200
|
|
640
|
+
}
|
|
641
|
+
};
|
|
642
|
+
output.writeln();
|
|
643
|
+
output.printInfo('Memory Configuration');
|
|
644
|
+
output.writeln();
|
|
645
|
+
output.printTable({
|
|
646
|
+
columns: [
|
|
647
|
+
{ key: 'setting', header: 'Setting', width: 20 },
|
|
648
|
+
{ key: 'value', header: 'Value', width: 25 }
|
|
649
|
+
],
|
|
650
|
+
data: [
|
|
651
|
+
{ setting: 'Backend', value: config.backend },
|
|
652
|
+
{ setting: 'Storage Path', value: config.path },
|
|
653
|
+
{ setting: 'Cache Size', value: `${config.cacheSize} MB` },
|
|
654
|
+
{ setting: 'HNSW M', value: config.hnsw.m },
|
|
655
|
+
{ setting: 'HNSW ef', value: config.hnsw.ef }
|
|
656
|
+
]
|
|
657
|
+
});
|
|
658
|
+
output.writeln();
|
|
659
|
+
output.printSuccess('Memory configuration updated');
|
|
660
|
+
return { success: true, data: config };
|
|
661
|
+
}
|
|
662
|
+
};
|
|
663
|
+
// Cleanup command
|
|
664
|
+
const cleanupCommand = {
|
|
665
|
+
name: 'cleanup',
|
|
666
|
+
description: 'Clean up stale and expired memory entries',
|
|
667
|
+
options: [
|
|
668
|
+
{
|
|
669
|
+
name: 'dry-run',
|
|
670
|
+
short: 'd',
|
|
671
|
+
description: 'Show what would be deleted',
|
|
672
|
+
type: 'boolean',
|
|
673
|
+
default: false
|
|
674
|
+
},
|
|
675
|
+
{
|
|
676
|
+
name: 'older-than',
|
|
677
|
+
short: 'o',
|
|
678
|
+
description: 'Delete entries older than (e.g., "7d", "30d")',
|
|
679
|
+
type: 'string'
|
|
680
|
+
},
|
|
681
|
+
{
|
|
682
|
+
name: 'expired-only',
|
|
683
|
+
short: 'e',
|
|
684
|
+
description: 'Only delete expired TTL entries',
|
|
685
|
+
type: 'boolean',
|
|
686
|
+
default: false
|
|
687
|
+
},
|
|
688
|
+
{
|
|
689
|
+
name: 'low-quality',
|
|
690
|
+
short: 'l',
|
|
691
|
+
description: 'Delete low quality patterns (threshold)',
|
|
692
|
+
type: 'number'
|
|
693
|
+
},
|
|
694
|
+
{
|
|
695
|
+
name: 'namespace',
|
|
696
|
+
short: 'n',
|
|
697
|
+
description: 'Clean specific namespace only',
|
|
698
|
+
type: 'string'
|
|
699
|
+
},
|
|
700
|
+
{
|
|
701
|
+
name: 'force',
|
|
702
|
+
short: 'f',
|
|
703
|
+
description: 'Skip confirmation',
|
|
704
|
+
type: 'boolean',
|
|
705
|
+
default: false
|
|
706
|
+
}
|
|
707
|
+
],
|
|
708
|
+
examples: [
|
|
709
|
+
{ command: 'claude-flow memory cleanup --dry-run', description: 'Preview cleanup' },
|
|
710
|
+
{ command: 'claude-flow memory cleanup --older-than 30d', description: 'Delete entries older than 30 days' },
|
|
711
|
+
{ command: 'claude-flow memory cleanup --expired-only', description: 'Clean expired entries' }
|
|
712
|
+
],
|
|
713
|
+
action: async (ctx) => {
|
|
714
|
+
const dryRun = ctx.flags.dryRun;
|
|
715
|
+
const force = ctx.flags.force;
|
|
716
|
+
if (dryRun) {
|
|
717
|
+
output.writeln(output.warning('DRY RUN - No changes will be made'));
|
|
718
|
+
}
|
|
719
|
+
output.printInfo('Analyzing memory for cleanup...');
|
|
720
|
+
try {
|
|
721
|
+
const result = await callMCPTool('memory_cleanup', {
|
|
722
|
+
dryRun,
|
|
723
|
+
olderThan: ctx.flags.olderThan,
|
|
724
|
+
expiredOnly: ctx.flags.expiredOnly,
|
|
725
|
+
lowQualityThreshold: ctx.flags.lowQuality,
|
|
726
|
+
namespace: ctx.flags.namespace,
|
|
727
|
+
});
|
|
728
|
+
if (ctx.flags.format === 'json') {
|
|
729
|
+
output.printJson(result);
|
|
730
|
+
return { success: true, data: result };
|
|
731
|
+
}
|
|
732
|
+
output.writeln();
|
|
733
|
+
output.writeln(output.bold('Cleanup Analysis'));
|
|
734
|
+
output.printTable({
|
|
735
|
+
columns: [
|
|
736
|
+
{ key: 'category', header: 'Category', width: 20 },
|
|
737
|
+
{ key: 'count', header: 'Count', width: 15, align: 'right' }
|
|
738
|
+
],
|
|
739
|
+
data: [
|
|
740
|
+
{ category: 'Expired (TTL)', count: result.candidates.expired },
|
|
741
|
+
{ category: 'Stale (unused)', count: result.candidates.stale },
|
|
742
|
+
{ category: 'Low Quality', count: result.candidates.lowQuality },
|
|
743
|
+
{ category: output.bold('Total'), count: output.bold(String(result.candidates.total)) }
|
|
744
|
+
]
|
|
745
|
+
});
|
|
746
|
+
if (!dryRun && result.candidates.total > 0 && !force) {
|
|
747
|
+
const confirmed = await confirm({
|
|
748
|
+
message: `Delete ${result.candidates.total} entries (${result.freed.formatted})?`,
|
|
749
|
+
default: false
|
|
750
|
+
});
|
|
751
|
+
if (!confirmed) {
|
|
752
|
+
output.printInfo('Cleanup cancelled');
|
|
753
|
+
return { success: true, data: result };
|
|
754
|
+
}
|
|
755
|
+
}
|
|
756
|
+
if (!dryRun) {
|
|
757
|
+
output.writeln();
|
|
758
|
+
output.printSuccess(`Cleaned ${result.deleted.entries} entries`);
|
|
759
|
+
output.printList([
|
|
760
|
+
`Vectors removed: ${result.deleted.vectors}`,
|
|
761
|
+
`Patterns removed: ${result.deleted.patterns}`,
|
|
762
|
+
`Space freed: ${result.freed.formatted}`,
|
|
763
|
+
`Duration: ${result.duration}ms`
|
|
764
|
+
]);
|
|
765
|
+
}
|
|
766
|
+
return { success: true, data: result };
|
|
767
|
+
}
|
|
768
|
+
catch (error) {
|
|
769
|
+
if (error instanceof MCPClientError) {
|
|
770
|
+
output.printError(`Cleanup error: ${error.message}`);
|
|
771
|
+
}
|
|
772
|
+
else {
|
|
773
|
+
output.printError(`Unexpected error: ${String(error)}`);
|
|
774
|
+
}
|
|
775
|
+
return { success: false, exitCode: 1 };
|
|
776
|
+
}
|
|
777
|
+
}
|
|
778
|
+
};
|
|
779
|
+
// Compress command
|
|
780
|
+
const compressCommand = {
|
|
781
|
+
name: 'compress',
|
|
782
|
+
description: 'Compress and optimize memory storage',
|
|
783
|
+
options: [
|
|
784
|
+
{
|
|
785
|
+
name: 'level',
|
|
786
|
+
short: 'l',
|
|
787
|
+
description: 'Compression level (fast, balanced, max)',
|
|
788
|
+
type: 'string',
|
|
789
|
+
choices: ['fast', 'balanced', 'max'],
|
|
790
|
+
default: 'balanced'
|
|
791
|
+
},
|
|
792
|
+
{
|
|
793
|
+
name: 'target',
|
|
794
|
+
short: 't',
|
|
795
|
+
description: 'Target (vectors, text, patterns, all)',
|
|
796
|
+
type: 'string',
|
|
797
|
+
choices: ['vectors', 'text', 'patterns', 'all'],
|
|
798
|
+
default: 'all'
|
|
799
|
+
},
|
|
800
|
+
{
|
|
801
|
+
name: 'quantize',
|
|
802
|
+
short: 'z',
|
|
803
|
+
description: 'Enable vector quantization (reduces memory 4-32x)',
|
|
804
|
+
type: 'boolean',
|
|
805
|
+
default: false
|
|
806
|
+
},
|
|
807
|
+
{
|
|
808
|
+
name: 'bits',
|
|
809
|
+
description: 'Quantization bits (4, 8, 16)',
|
|
810
|
+
type: 'number',
|
|
811
|
+
default: 8
|
|
812
|
+
},
|
|
813
|
+
{
|
|
814
|
+
name: 'rebuild-index',
|
|
815
|
+
short: 'r',
|
|
816
|
+
description: 'Rebuild HNSW index after compression',
|
|
817
|
+
type: 'boolean',
|
|
818
|
+
default: true
|
|
819
|
+
}
|
|
820
|
+
],
|
|
821
|
+
examples: [
|
|
822
|
+
{ command: 'claude-flow memory compress', description: 'Balanced compression' },
|
|
823
|
+
{ command: 'claude-flow memory compress --quantize --bits 4', description: '4-bit quantization (32x reduction)' },
|
|
824
|
+
{ command: 'claude-flow memory compress -l max -t vectors', description: 'Max compression on vectors' }
|
|
825
|
+
],
|
|
826
|
+
action: async (ctx) => {
|
|
827
|
+
const level = ctx.flags.level || 'balanced';
|
|
828
|
+
const target = ctx.flags.target || 'all';
|
|
829
|
+
const quantize = ctx.flags.quantize;
|
|
830
|
+
const bits = ctx.flags.bits || 8;
|
|
831
|
+
const rebuildIndex = ctx.flags.rebuildIndex ?? true;
|
|
832
|
+
output.writeln();
|
|
833
|
+
output.writeln(output.bold('Memory Compression'));
|
|
834
|
+
output.writeln(output.dim(`Level: ${level}, Target: ${target}, Quantize: ${quantize ? `${bits}-bit` : 'no'}`));
|
|
835
|
+
output.writeln();
|
|
836
|
+
const spinner = output.createSpinner({ text: 'Analyzing current storage...', spinner: 'dots' });
|
|
837
|
+
spinner.start();
|
|
838
|
+
try {
|
|
839
|
+
const result = await callMCPTool('memory_compress', {
|
|
840
|
+
level,
|
|
841
|
+
target,
|
|
842
|
+
quantize,
|
|
843
|
+
bits,
|
|
844
|
+
rebuildIndex,
|
|
845
|
+
});
|
|
846
|
+
spinner.succeed('Compression complete');
|
|
847
|
+
if (ctx.flags.format === 'json') {
|
|
848
|
+
output.printJson(result);
|
|
849
|
+
return { success: true, data: result };
|
|
850
|
+
}
|
|
851
|
+
output.writeln();
|
|
852
|
+
output.writeln(output.bold('Storage Comparison'));
|
|
853
|
+
output.printTable({
|
|
854
|
+
columns: [
|
|
855
|
+
{ key: 'category', header: 'Category', width: 15 },
|
|
856
|
+
{ key: 'before', header: 'Before', width: 12, align: 'right' },
|
|
857
|
+
{ key: 'after', header: 'After', width: 12, align: 'right' },
|
|
858
|
+
{ key: 'saved', header: 'Saved', width: 12, align: 'right' }
|
|
859
|
+
],
|
|
860
|
+
data: [
|
|
861
|
+
{ category: 'Vectors', before: result.before.vectorsSize, after: result.after.vectorsSize, saved: '-' },
|
|
862
|
+
{ category: 'Text', before: result.before.textSize, after: result.after.textSize, saved: '-' },
|
|
863
|
+
{ category: 'Patterns', before: result.before.patternsSize, after: result.after.patternsSize, saved: '-' },
|
|
864
|
+
{ category: 'Index', before: result.before.indexSize, after: result.after.indexSize, saved: '-' },
|
|
865
|
+
{ category: output.bold('Total'), before: result.before.totalSize, after: result.after.totalSize, saved: output.success(result.compression.formattedSaved) }
|
|
866
|
+
]
|
|
867
|
+
});
|
|
868
|
+
output.writeln();
|
|
869
|
+
output.printBox([
|
|
870
|
+
`Compression Ratio: ${result.compression.ratio.toFixed(2)}x`,
|
|
871
|
+
`Space Saved: ${result.compression.formattedSaved}`,
|
|
872
|
+
`Quantization: ${result.compression.quantizationApplied ? `Yes (${bits}-bit)` : 'No'}`,
|
|
873
|
+
`Index Rebuilt: ${result.compression.indexRebuilt ? 'Yes' : 'No'}`,
|
|
874
|
+
`Duration: ${(result.duration / 1000).toFixed(1)}s`
|
|
875
|
+
].join('\n'), 'Results');
|
|
876
|
+
if (result.performance) {
|
|
877
|
+
output.writeln();
|
|
878
|
+
output.writeln(output.bold('Performance Impact'));
|
|
879
|
+
output.printList([
|
|
880
|
+
`Search latency: ${result.performance.searchLatencyBefore.toFixed(2)}ms → ${result.performance.searchLatencyAfter.toFixed(2)}ms`,
|
|
881
|
+
`Speedup: ${output.success(result.performance.searchSpeedup)}`
|
|
882
|
+
]);
|
|
883
|
+
}
|
|
884
|
+
return { success: true, data: result };
|
|
885
|
+
}
|
|
886
|
+
catch (error) {
|
|
887
|
+
spinner.fail('Compression failed');
|
|
888
|
+
if (error instanceof MCPClientError) {
|
|
889
|
+
output.printError(`Compression error: ${error.message}`);
|
|
890
|
+
}
|
|
891
|
+
else {
|
|
892
|
+
output.printError(`Unexpected error: ${String(error)}`);
|
|
893
|
+
}
|
|
894
|
+
return { success: false, exitCode: 1 };
|
|
895
|
+
}
|
|
896
|
+
}
|
|
897
|
+
};
|
|
898
|
+
// Export command
|
|
899
|
+
const exportCommand = {
|
|
900
|
+
name: 'export',
|
|
901
|
+
description: 'Export memory to file',
|
|
902
|
+
options: [
|
|
903
|
+
{
|
|
904
|
+
name: 'output',
|
|
905
|
+
short: 'o',
|
|
906
|
+
description: 'Output file path',
|
|
907
|
+
type: 'string',
|
|
908
|
+
required: true
|
|
909
|
+
},
|
|
910
|
+
{
|
|
911
|
+
name: 'format',
|
|
912
|
+
short: 'f',
|
|
913
|
+
description: 'Export format (json, csv, binary)',
|
|
914
|
+
type: 'string',
|
|
915
|
+
choices: ['json', 'csv', 'binary'],
|
|
916
|
+
default: 'json'
|
|
917
|
+
},
|
|
918
|
+
{
|
|
919
|
+
name: 'namespace',
|
|
920
|
+
short: 'n',
|
|
921
|
+
description: 'Export specific namespace',
|
|
922
|
+
type: 'string'
|
|
923
|
+
},
|
|
924
|
+
{
|
|
925
|
+
name: 'include-vectors',
|
|
926
|
+
description: 'Include vector embeddings',
|
|
927
|
+
type: 'boolean',
|
|
928
|
+
default: true
|
|
929
|
+
}
|
|
930
|
+
],
|
|
931
|
+
examples: [
|
|
932
|
+
{ command: 'claude-flow memory export -o ./backup.json', description: 'Export all to JSON' },
|
|
933
|
+
{ command: 'claude-flow memory export -o ./data.csv -f csv', description: 'Export to CSV' }
|
|
934
|
+
],
|
|
935
|
+
action: async (ctx) => {
|
|
936
|
+
const outputPath = ctx.flags.output;
|
|
937
|
+
const format = ctx.flags.format || 'json';
|
|
938
|
+
if (!outputPath) {
|
|
939
|
+
output.printError('Output path is required. Use --output or -o');
|
|
940
|
+
return { success: false, exitCode: 1 };
|
|
941
|
+
}
|
|
942
|
+
output.printInfo(`Exporting memory to ${outputPath}...`);
|
|
943
|
+
try {
|
|
944
|
+
const result = await callMCPTool('memory_export', {
|
|
945
|
+
outputPath,
|
|
946
|
+
format,
|
|
947
|
+
namespace: ctx.flags.namespace,
|
|
948
|
+
includeVectors: ctx.flags.includeVectors ?? true,
|
|
949
|
+
});
|
|
950
|
+
output.printSuccess(`Exported to ${result.outputPath}`);
|
|
951
|
+
output.printList([
|
|
952
|
+
`Entries: ${result.exported.entries}`,
|
|
953
|
+
`Vectors: ${result.exported.vectors}`,
|
|
954
|
+
`Patterns: ${result.exported.patterns}`,
|
|
955
|
+
`File size: ${result.fileSize}`
|
|
956
|
+
]);
|
|
957
|
+
return { success: true, data: result };
|
|
958
|
+
}
|
|
959
|
+
catch (error) {
|
|
960
|
+
if (error instanceof MCPClientError) {
|
|
961
|
+
output.printError(`Export error: ${error.message}`);
|
|
962
|
+
}
|
|
963
|
+
else {
|
|
964
|
+
output.printError(`Unexpected error: ${String(error)}`);
|
|
965
|
+
}
|
|
966
|
+
return { success: false, exitCode: 1 };
|
|
967
|
+
}
|
|
968
|
+
}
|
|
969
|
+
};
|
|
970
|
+
// Import command
|
|
971
|
+
const importCommand = {
|
|
972
|
+
name: 'import',
|
|
973
|
+
description: 'Import memory from file',
|
|
974
|
+
options: [
|
|
975
|
+
{
|
|
976
|
+
name: 'input',
|
|
977
|
+
short: 'i',
|
|
978
|
+
description: 'Input file path',
|
|
979
|
+
type: 'string',
|
|
980
|
+
required: true
|
|
981
|
+
},
|
|
982
|
+
{
|
|
983
|
+
name: 'merge',
|
|
984
|
+
short: 'm',
|
|
985
|
+
description: 'Merge with existing (skip duplicates)',
|
|
986
|
+
type: 'boolean',
|
|
987
|
+
default: true
|
|
988
|
+
},
|
|
989
|
+
{
|
|
990
|
+
name: 'namespace',
|
|
991
|
+
short: 'n',
|
|
992
|
+
description: 'Import into specific namespace',
|
|
993
|
+
type: 'string'
|
|
994
|
+
}
|
|
995
|
+
],
|
|
996
|
+
examples: [
|
|
997
|
+
{ command: 'claude-flow memory import -i ./backup.json', description: 'Import from file' },
|
|
998
|
+
{ command: 'claude-flow memory import -i ./data.json -n archive', description: 'Import to namespace' }
|
|
999
|
+
],
|
|
1000
|
+
action: async (ctx) => {
|
|
1001
|
+
const inputPath = ctx.flags.input || ctx.args[0];
|
|
1002
|
+
if (!inputPath) {
|
|
1003
|
+
output.printError('Input path is required. Use --input or -i');
|
|
1004
|
+
return { success: false, exitCode: 1 };
|
|
1005
|
+
}
|
|
1006
|
+
output.printInfo(`Importing memory from ${inputPath}...`);
|
|
1007
|
+
try {
|
|
1008
|
+
const result = await callMCPTool('memory_import', {
|
|
1009
|
+
inputPath,
|
|
1010
|
+
merge: ctx.flags.merge ?? true,
|
|
1011
|
+
namespace: ctx.flags.namespace,
|
|
1012
|
+
});
|
|
1013
|
+
output.printSuccess(`Imported from ${result.inputPath}`);
|
|
1014
|
+
output.printList([
|
|
1015
|
+
`Entries: ${result.imported.entries}`,
|
|
1016
|
+
`Vectors: ${result.imported.vectors}`,
|
|
1017
|
+
`Patterns: ${result.imported.patterns}`,
|
|
1018
|
+
`Skipped (duplicates): ${result.skipped}`,
|
|
1019
|
+
`Duration: ${result.duration}ms`
|
|
1020
|
+
]);
|
|
1021
|
+
return { success: true, data: result };
|
|
1022
|
+
}
|
|
1023
|
+
catch (error) {
|
|
1024
|
+
if (error instanceof MCPClientError) {
|
|
1025
|
+
output.printError(`Import error: ${error.message}`);
|
|
1026
|
+
}
|
|
1027
|
+
else {
|
|
1028
|
+
output.printError(`Unexpected error: ${String(error)}`);
|
|
1029
|
+
}
|
|
1030
|
+
return { success: false, exitCode: 1 };
|
|
1031
|
+
}
|
|
1032
|
+
}
|
|
1033
|
+
};
|
|
1034
|
+
// Init subcommand - initialize memory database using sql.js
|
|
1035
|
+
const initMemoryCommand = {
|
|
1036
|
+
name: 'init',
|
|
1037
|
+
description: 'Initialize memory database with sql.js (WASM SQLite) - includes vector embeddings, pattern learning, temporal decay',
|
|
1038
|
+
options: [
|
|
1039
|
+
{
|
|
1040
|
+
name: 'backend',
|
|
1041
|
+
short: 'b',
|
|
1042
|
+
description: 'Backend type: hybrid (default), sqlite, or agentdb',
|
|
1043
|
+
type: 'string',
|
|
1044
|
+
default: 'hybrid'
|
|
1045
|
+
},
|
|
1046
|
+
{
|
|
1047
|
+
name: 'path',
|
|
1048
|
+
short: 'p',
|
|
1049
|
+
description: 'Database path',
|
|
1050
|
+
type: 'string'
|
|
1051
|
+
},
|
|
1052
|
+
{
|
|
1053
|
+
name: 'force',
|
|
1054
|
+
short: 'f',
|
|
1055
|
+
description: 'Overwrite existing database',
|
|
1056
|
+
type: 'boolean',
|
|
1057
|
+
default: false
|
|
1058
|
+
},
|
|
1059
|
+
{
|
|
1060
|
+
name: 'verbose',
|
|
1061
|
+
description: 'Show detailed initialization output',
|
|
1062
|
+
type: 'boolean',
|
|
1063
|
+
default: false
|
|
1064
|
+
},
|
|
1065
|
+
{
|
|
1066
|
+
name: 'verify',
|
|
1067
|
+
description: 'Run verification tests after initialization',
|
|
1068
|
+
type: 'boolean',
|
|
1069
|
+
default: true
|
|
1070
|
+
},
|
|
1071
|
+
{
|
|
1072
|
+
name: 'load-embeddings',
|
|
1073
|
+
description: 'Pre-load ONNX embedding model (lazy by default)',
|
|
1074
|
+
type: 'boolean',
|
|
1075
|
+
default: false
|
|
1076
|
+
}
|
|
1077
|
+
],
|
|
1078
|
+
examples: [
|
|
1079
|
+
{ command: 'claude-flow memory init', description: 'Initialize hybrid backend with all features' },
|
|
1080
|
+
{ command: 'claude-flow memory init -b agentdb', description: 'Initialize AgentDB backend' },
|
|
1081
|
+
{ command: 'claude-flow memory init -p ./data/memory.db --force', description: 'Reinitialize at custom path' },
|
|
1082
|
+
{ command: 'claude-flow memory init --verbose --verify', description: 'Initialize with full verification' }
|
|
1083
|
+
],
|
|
1084
|
+
action: async (ctx) => {
|
|
1085
|
+
const backend = ctx.flags.backend || 'hybrid';
|
|
1086
|
+
const customPath = ctx.flags.path;
|
|
1087
|
+
const force = ctx.flags.force;
|
|
1088
|
+
const verbose = ctx.flags.verbose;
|
|
1089
|
+
const verify = ctx.flags.verify !== false; // Default true
|
|
1090
|
+
const loadEmbeddings = ctx.flags.loadEmbeddings;
|
|
1091
|
+
output.writeln();
|
|
1092
|
+
output.writeln(output.bold('Initializing Memory Database'));
|
|
1093
|
+
output.writeln(output.dim('─'.repeat(50)));
|
|
1094
|
+
const spinner = output.createSpinner({ text: 'Initializing schema...', spinner: 'dots' });
|
|
1095
|
+
spinner.start();
|
|
1096
|
+
try {
|
|
1097
|
+
// Import the memory initializer
|
|
1098
|
+
const { initializeMemoryDatabase, loadEmbeddingModel, verifyMemoryInit } = await import('../memory/memory-initializer.js');
|
|
1099
|
+
const result = await initializeMemoryDatabase({
|
|
1100
|
+
backend,
|
|
1101
|
+
dbPath: customPath,
|
|
1102
|
+
force,
|
|
1103
|
+
verbose
|
|
1104
|
+
});
|
|
1105
|
+
if (!result.success) {
|
|
1106
|
+
spinner.fail('Initialization failed');
|
|
1107
|
+
output.printError(result.error || 'Unknown error');
|
|
1108
|
+
return { success: false, exitCode: 1 };
|
|
1109
|
+
}
|
|
1110
|
+
spinner.succeed('Schema initialized');
|
|
1111
|
+
// Lazy load or pre-load embedding model
|
|
1112
|
+
if (loadEmbeddings) {
|
|
1113
|
+
const embeddingSpinner = output.createSpinner({ text: 'Loading embedding model...', spinner: 'dots' });
|
|
1114
|
+
embeddingSpinner.start();
|
|
1115
|
+
const embeddingResult = await loadEmbeddingModel({ verbose });
|
|
1116
|
+
if (embeddingResult.success) {
|
|
1117
|
+
embeddingSpinner.succeed(`Embedding model loaded: ${embeddingResult.modelName} (${embeddingResult.dimensions}-dim, ${embeddingResult.loadTime}ms)`);
|
|
1118
|
+
}
|
|
1119
|
+
else {
|
|
1120
|
+
embeddingSpinner.stop(output.warning(`Embedding model: ${embeddingResult.error || 'Using fallback'}`));
|
|
1121
|
+
}
|
|
1122
|
+
}
|
|
1123
|
+
output.writeln();
|
|
1124
|
+
// Show features enabled with detailed capabilities
|
|
1125
|
+
const featureLines = [
|
|
1126
|
+
`Backend: ${result.backend}`,
|
|
1127
|
+
`Schema Version: ${result.schemaVersion}`,
|
|
1128
|
+
`Database Path: ${result.dbPath}`,
|
|
1129
|
+
'',
|
|
1130
|
+
output.bold('Features:'),
|
|
1131
|
+
` Vector Embeddings: ${result.features.vectorEmbeddings ? output.success('✓ Enabled') : output.dim('✗ Disabled')}`,
|
|
1132
|
+
` Pattern Learning: ${result.features.patternLearning ? output.success('✓ Enabled') : output.dim('✗ Disabled')}`,
|
|
1133
|
+
` Temporal Decay: ${result.features.temporalDecay ? output.success('✓ Enabled') : output.dim('✗ Disabled')}`,
|
|
1134
|
+
` HNSW Indexing: ${result.features.hnswIndexing ? output.success('✓ Enabled') : output.dim('✗ Disabled')}`,
|
|
1135
|
+
` Migration Tracking: ${result.features.migrationTracking ? output.success('✓ Enabled') : output.dim('✗ Disabled')}`
|
|
1136
|
+
];
|
|
1137
|
+
if (verbose) {
|
|
1138
|
+
featureLines.push('', output.bold('HNSW Configuration:'), ` M (connections): 16`, ` ef (construction): 200`, ` ef (search): 100`, ` Metric: cosine`, '', output.bold('Pattern Learning:'), ` Confidence scoring: 0.0 - 1.0`, ` Temporal decay: Half-life 30 days`, ` Pattern versioning: Enabled`, ` Types: task-routing, error-recovery, optimization, coordination, prediction`);
|
|
1139
|
+
}
|
|
1140
|
+
output.printBox(featureLines.join('\n'), 'Configuration');
|
|
1141
|
+
output.writeln();
|
|
1142
|
+
// ADR-053: Show ControllerRegistry activation results
|
|
1143
|
+
if (result.controllers) {
|
|
1144
|
+
const { activated, failed, initTimeMs } = result.controllers;
|
|
1145
|
+
if (activated.length > 0 || failed.length > 0) {
|
|
1146
|
+
const controllerLines = [
|
|
1147
|
+
output.bold('AgentDB Controllers:'),
|
|
1148
|
+
` Activated: ${activated.length} Failed: ${failed.length} Init: ${Math.round(initTimeMs)}ms`,
|
|
1149
|
+
];
|
|
1150
|
+
if (verbose && activated.length > 0) {
|
|
1151
|
+
controllerLines.push('');
|
|
1152
|
+
for (const name of activated) {
|
|
1153
|
+
controllerLines.push(` ${output.success('✓')} ${name}`);
|
|
1154
|
+
}
|
|
1155
|
+
}
|
|
1156
|
+
if (failed.length > 0 && verbose) {
|
|
1157
|
+
controllerLines.push('');
|
|
1158
|
+
for (const name of failed) {
|
|
1159
|
+
controllerLines.push(` ${output.dim('✗')} ${name}`);
|
|
1160
|
+
}
|
|
1161
|
+
}
|
|
1162
|
+
output.printBox(controllerLines.join('\n'), 'Controller Registry (ADR-053)');
|
|
1163
|
+
output.writeln();
|
|
1164
|
+
}
|
|
1165
|
+
}
|
|
1166
|
+
// Show tables created
|
|
1167
|
+
if (verbose && result.tablesCreated.length > 0) {
|
|
1168
|
+
output.writeln(output.bold('Tables Created:'));
|
|
1169
|
+
output.printTable({
|
|
1170
|
+
columns: [
|
|
1171
|
+
{ key: 'table', header: 'Table', width: 22 },
|
|
1172
|
+
{ key: 'purpose', header: 'Purpose', width: 38 }
|
|
1173
|
+
],
|
|
1174
|
+
data: [
|
|
1175
|
+
{ table: 'memory_entries', purpose: 'Core memory storage with embeddings' },
|
|
1176
|
+
{ table: 'patterns', purpose: 'Learned patterns with confidence scores' },
|
|
1177
|
+
{ table: 'pattern_history', purpose: 'Pattern versioning and evolution' },
|
|
1178
|
+
{ table: 'trajectories', purpose: 'SONA learning trajectories' },
|
|
1179
|
+
{ table: 'trajectory_steps', purpose: 'Individual trajectory steps' },
|
|
1180
|
+
{ table: 'migration_state', purpose: 'Migration progress tracking' },
|
|
1181
|
+
{ table: 'sessions', purpose: 'Context persistence' },
|
|
1182
|
+
{ table: 'vector_indexes', purpose: 'HNSW index configuration' },
|
|
1183
|
+
{ table: 'metadata', purpose: 'System metadata' }
|
|
1184
|
+
]
|
|
1185
|
+
});
|
|
1186
|
+
output.writeln();
|
|
1187
|
+
output.writeln(output.bold('Indexes Created:'));
|
|
1188
|
+
output.printList(result.indexesCreated.slice(0, 8).map(idx => output.dim(idx)));
|
|
1189
|
+
if (result.indexesCreated.length > 8) {
|
|
1190
|
+
output.writeln(output.dim(` ... and ${result.indexesCreated.length - 8} more`));
|
|
1191
|
+
}
|
|
1192
|
+
output.writeln();
|
|
1193
|
+
}
|
|
1194
|
+
// Run verification if enabled
|
|
1195
|
+
if (verify) {
|
|
1196
|
+
const verifySpinner = output.createSpinner({ text: 'Verifying initialization...', spinner: 'dots' });
|
|
1197
|
+
verifySpinner.start();
|
|
1198
|
+
const verification = await verifyMemoryInit(result.dbPath, { verbose });
|
|
1199
|
+
if (verification.success) {
|
|
1200
|
+
verifySpinner.succeed(`Verification passed (${verification.summary.passed}/${verification.summary.total} tests)`);
|
|
1201
|
+
}
|
|
1202
|
+
else {
|
|
1203
|
+
verifySpinner.fail(`Verification failed (${verification.summary.failed}/${verification.summary.total} tests failed)`);
|
|
1204
|
+
}
|
|
1205
|
+
if (verbose || !verification.success) {
|
|
1206
|
+
output.writeln();
|
|
1207
|
+
output.writeln(output.bold('Verification Results:'));
|
|
1208
|
+
output.printTable({
|
|
1209
|
+
columns: [
|
|
1210
|
+
{ key: 'status', header: '', width: 3 },
|
|
1211
|
+
{ key: 'name', header: 'Test', width: 22 },
|
|
1212
|
+
{ key: 'details', header: 'Details', width: 30 },
|
|
1213
|
+
{ key: 'duration', header: 'Time', width: 8, align: 'right' }
|
|
1214
|
+
],
|
|
1215
|
+
data: verification.tests.map(t => ({
|
|
1216
|
+
status: t.passed ? output.success('✓') : output.error('✗'),
|
|
1217
|
+
name: t.name,
|
|
1218
|
+
details: t.details || '',
|
|
1219
|
+
duration: t.duration ? `${t.duration}ms` : '-'
|
|
1220
|
+
}))
|
|
1221
|
+
});
|
|
1222
|
+
}
|
|
1223
|
+
output.writeln();
|
|
1224
|
+
}
|
|
1225
|
+
// Show next steps
|
|
1226
|
+
output.writeln(output.bold('Next Steps:'));
|
|
1227
|
+
output.printList([
|
|
1228
|
+
`Store data: ${output.highlight('claude-flow memory store -k "key" --value "data"')}`,
|
|
1229
|
+
`Search: ${output.highlight('claude-flow memory search -q "query"')}`,
|
|
1230
|
+
`Train patterns: ${output.highlight('claude-flow neural train -p coordination')}`,
|
|
1231
|
+
`View stats: ${output.highlight('claude-flow memory stats')}`
|
|
1232
|
+
]);
|
|
1233
|
+
// Also sync to .claude directory
|
|
1234
|
+
const fs = await import('fs');
|
|
1235
|
+
const path = await import('path');
|
|
1236
|
+
const claudeDir = path.join(process.cwd(), '.claude');
|
|
1237
|
+
const claudeDbPath = path.join(claudeDir, 'memory.db');
|
|
1238
|
+
if (!fs.existsSync(claudeDir)) {
|
|
1239
|
+
fs.mkdirSync(claudeDir, { recursive: true });
|
|
1240
|
+
}
|
|
1241
|
+
if (fs.existsSync(result.dbPath) && (!fs.existsSync(claudeDbPath) || force)) {
|
|
1242
|
+
fs.copyFileSync(result.dbPath, claudeDbPath);
|
|
1243
|
+
output.writeln();
|
|
1244
|
+
output.writeln(output.dim(`Synced to: ${claudeDbPath}`));
|
|
1245
|
+
}
|
|
1246
|
+
return {
|
|
1247
|
+
success: true,
|
|
1248
|
+
data: result
|
|
1249
|
+
};
|
|
1250
|
+
}
|
|
1251
|
+
catch (error) {
|
|
1252
|
+
spinner.fail('Initialization failed');
|
|
1253
|
+
output.printError(`Failed to initialize memory: ${error instanceof Error ? error.message : String(error)}`);
|
|
1254
|
+
return { success: false, exitCode: 1 };
|
|
1255
|
+
}
|
|
1256
|
+
}
|
|
1257
|
+
};
|
|
1258
|
+
// ============================================================================
|
|
1259
|
+
// Shared DB helpers for batch commands (index-guidance, rebuild-index, code-map)
|
|
1260
|
+
// ============================================================================
|
|
1261
|
+
const DB_FILENAME = 'memory.db';
|
|
1262
|
+
const SWARM_DIR = '.swarm';
|
|
1263
|
+
async function openDb(cwd) {
|
|
1264
|
+
const fs = await import('fs');
|
|
1265
|
+
const path = await import('path');
|
|
1266
|
+
const initSqlJs = (await import('sql.js')).default;
|
|
1267
|
+
const SQL = await initSqlJs();
|
|
1268
|
+
const dbPath = path.join(cwd, SWARM_DIR, DB_FILENAME);
|
|
1269
|
+
const dir = path.dirname(dbPath);
|
|
1270
|
+
if (!fs.existsSync(dir)) {
|
|
1271
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
1272
|
+
}
|
|
1273
|
+
let db;
|
|
1274
|
+
if (fs.existsSync(dbPath)) {
|
|
1275
|
+
const buffer = fs.readFileSync(dbPath);
|
|
1276
|
+
db = new SQL.Database(buffer);
|
|
1277
|
+
}
|
|
1278
|
+
else {
|
|
1279
|
+
db = new SQL.Database();
|
|
1280
|
+
}
|
|
1281
|
+
// Ensure table exists
|
|
1282
|
+
db.run(`
|
|
1283
|
+
CREATE TABLE IF NOT EXISTS memory_entries (
|
|
1284
|
+
id TEXT PRIMARY KEY,
|
|
1285
|
+
key TEXT NOT NULL,
|
|
1286
|
+
namespace TEXT DEFAULT 'default',
|
|
1287
|
+
content TEXT NOT NULL,
|
|
1288
|
+
type TEXT DEFAULT 'semantic',
|
|
1289
|
+
embedding TEXT,
|
|
1290
|
+
embedding_model TEXT DEFAULT 'local',
|
|
1291
|
+
embedding_dimensions INTEGER,
|
|
1292
|
+
tags TEXT,
|
|
1293
|
+
metadata TEXT,
|
|
1294
|
+
owner_id TEXT,
|
|
1295
|
+
created_at INTEGER NOT NULL DEFAULT (strftime('%s', 'now') * 1000),
|
|
1296
|
+
updated_at INTEGER NOT NULL DEFAULT (strftime('%s', 'now') * 1000),
|
|
1297
|
+
expires_at INTEGER,
|
|
1298
|
+
last_accessed_at INTEGER,
|
|
1299
|
+
access_count INTEGER DEFAULT 0,
|
|
1300
|
+
status TEXT DEFAULT 'active',
|
|
1301
|
+
UNIQUE(namespace, key)
|
|
1302
|
+
)
|
|
1303
|
+
`);
|
|
1304
|
+
db.run(`CREATE INDEX IF NOT EXISTS idx_memory_key_ns ON memory_entries(key, namespace)`);
|
|
1305
|
+
db.run(`CREATE INDEX IF NOT EXISTS idx_memory_namespace ON memory_entries(namespace)`);
|
|
1306
|
+
return { db, dbPath, SQL };
|
|
1307
|
+
}
|
|
1308
|
+
function saveAndCloseDb(db, dbPath) {
|
|
1309
|
+
const data = db.export();
|
|
1310
|
+
fs.writeFileSync(dbPath, Buffer.from(data));
|
|
1311
|
+
db.close();
|
|
1312
|
+
}
|
|
1313
|
+
function batchGenerateId() {
|
|
1314
|
+
return `mem_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`;
|
|
1315
|
+
}
|
|
1316
|
+
function batchStoreEntry(db, key, namespace, content, metadata = {}, tags = [], embedding, embeddingModel, embeddingDimensions) {
|
|
1317
|
+
const now = Date.now();
|
|
1318
|
+
const id = batchGenerateId();
|
|
1319
|
+
if (embedding) {
|
|
1320
|
+
db.run(`
|
|
1321
|
+
INSERT OR REPLACE INTO memory_entries
|
|
1322
|
+
(id, key, namespace, content, metadata, tags, embedding, embedding_model, embedding_dimensions, created_at, updated_at, status)
|
|
1323
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 'active')
|
|
1324
|
+
`, [id, key, namespace, content, JSON.stringify(metadata), JSON.stringify(tags),
|
|
1325
|
+
JSON.stringify(embedding), embeddingModel || 'local', embeddingDimensions || 384, now, now]);
|
|
1326
|
+
}
|
|
1327
|
+
else {
|
|
1328
|
+
db.run(`
|
|
1329
|
+
INSERT OR REPLACE INTO memory_entries
|
|
1330
|
+
(id, key, namespace, content, metadata, tags, created_at, updated_at, status)
|
|
1331
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?, 'active')
|
|
1332
|
+
`, [id, key, namespace, content, JSON.stringify(metadata), JSON.stringify(tags), now, now]);
|
|
1333
|
+
}
|
|
1334
|
+
}
|
|
1335
|
+
function hashContent(content) {
|
|
1336
|
+
let hash = 0;
|
|
1337
|
+
for (let i = 0; i < content.length; i++) {
|
|
1338
|
+
const char = content.charCodeAt(i);
|
|
1339
|
+
hash = ((hash << 5) - hash) + char;
|
|
1340
|
+
hash = hash & hash;
|
|
1341
|
+
}
|
|
1342
|
+
return hash.toString(16);
|
|
1343
|
+
}
|
|
1344
|
+
// ============================================================================
|
|
1345
|
+
// index-guidance subcommand
|
|
1346
|
+
// ============================================================================
|
|
1347
|
+
const MIN_CHUNK_SIZE = 50;
|
|
1348
|
+
const MAX_CHUNK_SIZE = 4000;
|
|
1349
|
+
const FORCE_CHUNK_THRESHOLD = 6000;
|
|
1350
|
+
const DEFAULT_OVERLAP_PERCENT = 20;
|
|
1351
|
+
function chunkMarkdown(content, fileName) {
|
|
1352
|
+
const lines = content.split('\n');
|
|
1353
|
+
const chunks = [];
|
|
1354
|
+
let currentChunk = {
|
|
1355
|
+
title: fileName, content: [], level: 0, headerLine: 0
|
|
1356
|
+
};
|
|
1357
|
+
for (let lineNum = 0; lineNum < lines.length; lineNum++) {
|
|
1358
|
+
const line = lines[lineNum].replace(/\r$/, '');
|
|
1359
|
+
const h2Match = line.match(/^## (.+)$/);
|
|
1360
|
+
const h3Match = line.match(/^### (.+)$/);
|
|
1361
|
+
if (h2Match || h3Match) {
|
|
1362
|
+
if (currentChunk.content.length > 0) {
|
|
1363
|
+
const chunkContent = currentChunk.content.join('\n').trim();
|
|
1364
|
+
if (chunkContent.length >= MIN_CHUNK_SIZE) {
|
|
1365
|
+
chunks.push({
|
|
1366
|
+
title: currentChunk.title,
|
|
1367
|
+
content: chunkContent,
|
|
1368
|
+
level: currentChunk.level,
|
|
1369
|
+
headerLine: currentChunk.headerLine
|
|
1370
|
+
});
|
|
1371
|
+
}
|
|
1372
|
+
}
|
|
1373
|
+
currentChunk = {
|
|
1374
|
+
title: h2Match ? h2Match[1] : h3Match[1],
|
|
1375
|
+
content: [line],
|
|
1376
|
+
level: h2Match ? 2 : 3,
|
|
1377
|
+
headerLine: lineNum
|
|
1378
|
+
};
|
|
1379
|
+
}
|
|
1380
|
+
else {
|
|
1381
|
+
currentChunk.content.push(line);
|
|
1382
|
+
}
|
|
1383
|
+
}
|
|
1384
|
+
if (currentChunk.content.length > 0) {
|
|
1385
|
+
const chunkContent = currentChunk.content.join('\n').trim();
|
|
1386
|
+
if (chunkContent.length >= MIN_CHUNK_SIZE) {
|
|
1387
|
+
chunks.push({
|
|
1388
|
+
title: currentChunk.title,
|
|
1389
|
+
content: chunkContent,
|
|
1390
|
+
level: currentChunk.level,
|
|
1391
|
+
headerLine: currentChunk.headerLine
|
|
1392
|
+
});
|
|
1393
|
+
}
|
|
1394
|
+
}
|
|
1395
|
+
// Split oversized chunks by paragraphs
|
|
1396
|
+
const finalChunks = [];
|
|
1397
|
+
for (const chunk of chunks) {
|
|
1398
|
+
if (chunk.content.length > MAX_CHUNK_SIZE) {
|
|
1399
|
+
const paragraphs = chunk.content.split(/\n\n+/);
|
|
1400
|
+
let currentPart = [];
|
|
1401
|
+
let currentLength = 0;
|
|
1402
|
+
let partNum = 1;
|
|
1403
|
+
for (const para of paragraphs) {
|
|
1404
|
+
if (currentLength + para.length > MAX_CHUNK_SIZE && currentPart.length > 0) {
|
|
1405
|
+
finalChunks.push({
|
|
1406
|
+
title: `${chunk.title} (part ${partNum})`,
|
|
1407
|
+
content: currentPart.join('\n\n'),
|
|
1408
|
+
level: chunk.level,
|
|
1409
|
+
headerLine: chunk.headerLine,
|
|
1410
|
+
isPart: true,
|
|
1411
|
+
partNum
|
|
1412
|
+
});
|
|
1413
|
+
currentPart = [para];
|
|
1414
|
+
currentLength = para.length;
|
|
1415
|
+
partNum++;
|
|
1416
|
+
}
|
|
1417
|
+
else {
|
|
1418
|
+
currentPart.push(para);
|
|
1419
|
+
currentLength += para.length;
|
|
1420
|
+
}
|
|
1421
|
+
}
|
|
1422
|
+
if (currentPart.length > 0) {
|
|
1423
|
+
finalChunks.push({
|
|
1424
|
+
title: partNum > 1 ? `${chunk.title} (part ${partNum})` : chunk.title,
|
|
1425
|
+
content: currentPart.join('\n\n'),
|
|
1426
|
+
level: chunk.level,
|
|
1427
|
+
headerLine: chunk.headerLine,
|
|
1428
|
+
isPart: partNum > 1,
|
|
1429
|
+
partNum: partNum > 1 ? partNum : undefined
|
|
1430
|
+
});
|
|
1431
|
+
}
|
|
1432
|
+
}
|
|
1433
|
+
else {
|
|
1434
|
+
finalChunks.push(chunk);
|
|
1435
|
+
}
|
|
1436
|
+
}
|
|
1437
|
+
// Force chunking for large files with few chunks
|
|
1438
|
+
const totalContent = finalChunks.reduce((acc, c) => acc + c.content.length, 0);
|
|
1439
|
+
if (totalContent > FORCE_CHUNK_THRESHOLD && finalChunks.length < 3) {
|
|
1440
|
+
const allContent = finalChunks.map(c => c.content).join('\n\n');
|
|
1441
|
+
const TARGET_CHUNK_SIZE = 2500;
|
|
1442
|
+
const rawSections = allContent.split(/\n---+\n/);
|
|
1443
|
+
const sections = [];
|
|
1444
|
+
for (const raw of rawSections) {
|
|
1445
|
+
if (raw.length > TARGET_CHUNK_SIZE) {
|
|
1446
|
+
const headerSplit = raw.split(/\n(?=## )/);
|
|
1447
|
+
for (const hSect of headerSplit) {
|
|
1448
|
+
if (hSect.length > TARGET_CHUNK_SIZE) {
|
|
1449
|
+
const sLines = hSect.split('\n');
|
|
1450
|
+
let chunk = '';
|
|
1451
|
+
for (const line of sLines) {
|
|
1452
|
+
if (chunk.length + line.length > TARGET_CHUNK_SIZE && chunk.length > 100) {
|
|
1453
|
+
sections.push(chunk.trim());
|
|
1454
|
+
chunk = line;
|
|
1455
|
+
}
|
|
1456
|
+
else {
|
|
1457
|
+
chunk += (chunk ? '\n' : '') + line;
|
|
1458
|
+
}
|
|
1459
|
+
}
|
|
1460
|
+
if (chunk.trim().length > 30)
|
|
1461
|
+
sections.push(chunk.trim());
|
|
1462
|
+
}
|
|
1463
|
+
else if (hSect.trim().length > 30) {
|
|
1464
|
+
sections.push(hSect.trim());
|
|
1465
|
+
}
|
|
1466
|
+
}
|
|
1467
|
+
}
|
|
1468
|
+
else if (raw.trim().length > 30) {
|
|
1469
|
+
sections.push(raw.trim());
|
|
1470
|
+
}
|
|
1471
|
+
}
|
|
1472
|
+
const forcedChunks = [];
|
|
1473
|
+
let currentGroup = [];
|
|
1474
|
+
let currentLength = 0;
|
|
1475
|
+
let groupNum = 1;
|
|
1476
|
+
const flushGroup = () => {
|
|
1477
|
+
if (currentGroup.length === 0)
|
|
1478
|
+
return;
|
|
1479
|
+
const firstLine = currentGroup[0].split('\n')[0].trim();
|
|
1480
|
+
const title = firstLine.startsWith('#')
|
|
1481
|
+
? firstLine.replace(/^#+\s*/, '').slice(0, 60)
|
|
1482
|
+
: `${fileName} Section ${groupNum}`;
|
|
1483
|
+
forcedChunks.push({
|
|
1484
|
+
title,
|
|
1485
|
+
content: currentGroup.join('\n\n'),
|
|
1486
|
+
level: 2,
|
|
1487
|
+
headerLine: 0,
|
|
1488
|
+
isForced: true,
|
|
1489
|
+
forceNum: groupNum
|
|
1490
|
+
});
|
|
1491
|
+
groupNum++;
|
|
1492
|
+
currentGroup = [];
|
|
1493
|
+
currentLength = 0;
|
|
1494
|
+
};
|
|
1495
|
+
for (const section of sections) {
|
|
1496
|
+
if (currentLength + section.length > TARGET_CHUNK_SIZE && currentGroup.length > 0) {
|
|
1497
|
+
flushGroup();
|
|
1498
|
+
}
|
|
1499
|
+
currentGroup.push(section);
|
|
1500
|
+
currentLength += section.length;
|
|
1501
|
+
}
|
|
1502
|
+
flushGroup();
|
|
1503
|
+
if (forcedChunks.length >= 2) {
|
|
1504
|
+
return forcedChunks;
|
|
1505
|
+
}
|
|
1506
|
+
}
|
|
1507
|
+
return finalChunks;
|
|
1508
|
+
}
|
|
1509
|
+
function extractOverlapContext(text, percent, position) {
|
|
1510
|
+
if (!text || percent <= 0)
|
|
1511
|
+
return '';
|
|
1512
|
+
const targetLength = Math.floor(text.length * (percent / 100));
|
|
1513
|
+
if (targetLength < 20)
|
|
1514
|
+
return '';
|
|
1515
|
+
if (position === 'start') {
|
|
1516
|
+
let end = targetLength;
|
|
1517
|
+
const nextPara = text.indexOf('\n\n', targetLength - 50);
|
|
1518
|
+
const nextSentence = text.indexOf('. ', targetLength - 30);
|
|
1519
|
+
if (nextPara > 0 && nextPara < targetLength + 100)
|
|
1520
|
+
end = nextPara;
|
|
1521
|
+
else if (nextSentence > 0 && nextSentence < targetLength + 50)
|
|
1522
|
+
end = nextSentence + 1;
|
|
1523
|
+
return text.substring(0, end).trim();
|
|
1524
|
+
}
|
|
1525
|
+
else {
|
|
1526
|
+
let start = text.length - targetLength;
|
|
1527
|
+
const prevPara = text.lastIndexOf('\n\n', start + 50);
|
|
1528
|
+
const prevSentence = text.lastIndexOf('. ', start + 30);
|
|
1529
|
+
if (prevPara > 0 && prevPara > start - 100)
|
|
1530
|
+
start = prevPara + 2;
|
|
1531
|
+
else if (prevSentence > 0 && prevSentence > start - 50)
|
|
1532
|
+
start = prevSentence + 2;
|
|
1533
|
+
return text.substring(start).trim();
|
|
1534
|
+
}
|
|
1535
|
+
}
|
|
1536
|
+
function buildHierarchy(chunks, chunkPrefix) {
|
|
1537
|
+
const hierarchy = {};
|
|
1538
|
+
let currentH2Index = null;
|
|
1539
|
+
for (let i = 0; i < chunks.length; i++) {
|
|
1540
|
+
const chunk = chunks[i];
|
|
1541
|
+
const chunkKey = `${chunkPrefix}-${i}`;
|
|
1542
|
+
hierarchy[chunkKey] = { parent: null, children: [] };
|
|
1543
|
+
if (chunk.level === 2) {
|
|
1544
|
+
currentH2Index = i;
|
|
1545
|
+
}
|
|
1546
|
+
else if (chunk.level === 3 && currentH2Index !== null) {
|
|
1547
|
+
const parentKey = `${chunkPrefix}-${currentH2Index}`;
|
|
1548
|
+
hierarchy[chunkKey].parent = parentKey;
|
|
1549
|
+
hierarchy[parentKey].children.push(chunkKey);
|
|
1550
|
+
}
|
|
1551
|
+
}
|
|
1552
|
+
return hierarchy;
|
|
1553
|
+
}
|
|
1554
|
+
const indexGuidanceCommand = {
|
|
1555
|
+
name: 'index-guidance',
|
|
1556
|
+
description: 'Index .claude/guidance/ markdown files into the guidance namespace with RAG linked segments',
|
|
1557
|
+
options: [
|
|
1558
|
+
{
|
|
1559
|
+
name: 'force',
|
|
1560
|
+
short: 'f',
|
|
1561
|
+
description: 'Force reindex all files (even unchanged)',
|
|
1562
|
+
type: 'boolean',
|
|
1563
|
+
default: false
|
|
1564
|
+
},
|
|
1565
|
+
{
|
|
1566
|
+
name: 'file',
|
|
1567
|
+
description: 'Index a specific file only',
|
|
1568
|
+
type: 'string'
|
|
1569
|
+
},
|
|
1570
|
+
{
|
|
1571
|
+
name: 'no-embeddings',
|
|
1572
|
+
description: 'Skip embedding generation after indexing',
|
|
1573
|
+
type: 'boolean',
|
|
1574
|
+
default: false
|
|
1575
|
+
},
|
|
1576
|
+
{
|
|
1577
|
+
name: 'overlap',
|
|
1578
|
+
description: 'Context overlap percentage (default: 20)',
|
|
1579
|
+
type: 'number',
|
|
1580
|
+
default: 20
|
|
1581
|
+
}
|
|
1582
|
+
],
|
|
1583
|
+
examples: [
|
|
1584
|
+
{ command: 'claude-flow memory index-guidance', description: 'Index all guidance files' },
|
|
1585
|
+
{ command: 'claude-flow memory index-guidance --force', description: 'Force reindex all' },
|
|
1586
|
+
{ command: 'claude-flow memory index-guidance --file .claude/guidance/coding-rules.md', description: 'Index specific file' }
|
|
1587
|
+
],
|
|
1588
|
+
action: async (ctx) => {
|
|
1589
|
+
const forceReindex = ctx.flags.force;
|
|
1590
|
+
const specificFile = ctx.flags.file;
|
|
1591
|
+
const skipEmbeddings = ctx.flags['no-embeddings'];
|
|
1592
|
+
const overlapPercent = ctx.flags.overlap || DEFAULT_OVERLAP_PERCENT;
|
|
1593
|
+
const NAMESPACE = 'guidance';
|
|
1594
|
+
const fs = await import('fs');
|
|
1595
|
+
const pathMod = await import('path');
|
|
1596
|
+
const cwd = ctx.cwd || process.cwd();
|
|
1597
|
+
output.writeln();
|
|
1598
|
+
output.writeln(output.bold('Indexing Guidance Files'));
|
|
1599
|
+
output.writeln(output.dim(`Context overlap: ${overlapPercent}%`));
|
|
1600
|
+
output.writeln();
|
|
1601
|
+
const { db, dbPath } = await openDb(cwd);
|
|
1602
|
+
let docsIndexed = 0;
|
|
1603
|
+
let chunksIndexed = 0;
|
|
1604
|
+
let unchanged = 0;
|
|
1605
|
+
let errors = 0;
|
|
1606
|
+
const indexFile = (filePath, keyPrefix) => {
|
|
1607
|
+
const fileName = pathModule.basename(filePath, pathModule.extname(filePath));
|
|
1608
|
+
const docKey = `doc-${keyPrefix}-${fileName}`;
|
|
1609
|
+
const chunkPrefix = `chunk-${keyPrefix}-${fileName}`;
|
|
1610
|
+
try {
|
|
1611
|
+
const content = fs.readFileSync(filePath, 'utf-8');
|
|
1612
|
+
const contentHash_ = hashContent(content);
|
|
1613
|
+
// Check if content changed
|
|
1614
|
+
if (!forceReindex) {
|
|
1615
|
+
const stmt = db.prepare('SELECT metadata FROM memory_entries WHERE key = ? AND namespace = ?');
|
|
1616
|
+
stmt.bind([docKey, NAMESPACE]);
|
|
1617
|
+
const entry = stmt.step() ? stmt.getAsObject() : null;
|
|
1618
|
+
stmt.free();
|
|
1619
|
+
if (entry?.metadata) {
|
|
1620
|
+
try {
|
|
1621
|
+
const meta = JSON.parse(entry.metadata);
|
|
1622
|
+
if (meta.contentHash === contentHash_) {
|
|
1623
|
+
return { docKey, status: 'unchanged', chunks: 0 };
|
|
1624
|
+
}
|
|
1625
|
+
}
|
|
1626
|
+
catch { /* ignore */ }
|
|
1627
|
+
}
|
|
1628
|
+
}
|
|
1629
|
+
const stats = fs.statSync(filePath);
|
|
1630
|
+
const relativePath = filePath.replace(cwd, '').replace(/\\/g, '/');
|
|
1631
|
+
// Delete old chunks
|
|
1632
|
+
db.run(`DELETE FROM memory_entries WHERE namespace = ? AND key LIKE ?`, [NAMESPACE, `${chunkPrefix}%`]);
|
|
1633
|
+
// Store full document
|
|
1634
|
+
const docMetadata = {
|
|
1635
|
+
type: 'document',
|
|
1636
|
+
filePath: relativePath,
|
|
1637
|
+
fileSize: stats.size,
|
|
1638
|
+
lastModified: stats.mtime.toISOString(),
|
|
1639
|
+
contentHash: contentHash_,
|
|
1640
|
+
indexedAt: new Date().toISOString(),
|
|
1641
|
+
ragVersion: '2.0',
|
|
1642
|
+
};
|
|
1643
|
+
batchStoreEntry(db, docKey, NAMESPACE, content, docMetadata, [keyPrefix, 'document']);
|
|
1644
|
+
// Chunk content
|
|
1645
|
+
const chunks = chunkMarkdown(content, fileName);
|
|
1646
|
+
if (chunks.length === 0) {
|
|
1647
|
+
return { docKey, status: 'indexed', chunks: 0 };
|
|
1648
|
+
}
|
|
1649
|
+
const hierarchy = buildHierarchy(chunks, chunkPrefix);
|
|
1650
|
+
const siblings = chunks.map((_, i) => `${chunkPrefix}-${i}`);
|
|
1651
|
+
// Update doc with children refs
|
|
1652
|
+
const docChildrenMeta = { ...docMetadata, children: siblings, chunkCount: chunks.length };
|
|
1653
|
+
batchStoreEntry(db, docKey, NAMESPACE, content, docChildrenMeta, [keyPrefix, 'document']);
|
|
1654
|
+
for (let i = 0; i < chunks.length; i++) {
|
|
1655
|
+
const chunk = chunks[i];
|
|
1656
|
+
const chunkKey = `${chunkPrefix}-${i}`;
|
|
1657
|
+
const prevChunk = i > 0 ? `${chunkPrefix}-${i - 1}` : null;
|
|
1658
|
+
const nextChunk = i < chunks.length - 1 ? `${chunkPrefix}-${i + 1}` : null;
|
|
1659
|
+
const contextBefore = i > 0
|
|
1660
|
+
? extractOverlapContext(chunks[i - 1].content, overlapPercent, 'end')
|
|
1661
|
+
: null;
|
|
1662
|
+
const contextAfter = i < chunks.length - 1
|
|
1663
|
+
? extractOverlapContext(chunks[i + 1].content, overlapPercent, 'start')
|
|
1664
|
+
: null;
|
|
1665
|
+
const hierInfo = hierarchy[chunkKey];
|
|
1666
|
+
const chunkMetadata = {
|
|
1667
|
+
type: 'chunk',
|
|
1668
|
+
ragVersion: '2.0',
|
|
1669
|
+
parentDoc: docKey,
|
|
1670
|
+
parentPath: relativePath,
|
|
1671
|
+
chunkIndex: i,
|
|
1672
|
+
totalChunks: chunks.length,
|
|
1673
|
+
prevChunk,
|
|
1674
|
+
nextChunk,
|
|
1675
|
+
siblings,
|
|
1676
|
+
hierarchicalParent: hierInfo.parent,
|
|
1677
|
+
hierarchicalChildren: hierInfo.children.length > 0 ? hierInfo.children : null,
|
|
1678
|
+
chunkTitle: chunk.title,
|
|
1679
|
+
headerLevel: chunk.level,
|
|
1680
|
+
headerLine: chunk.headerLine,
|
|
1681
|
+
isPart: chunk.isPart || false,
|
|
1682
|
+
partNum: chunk.partNum || null,
|
|
1683
|
+
contextOverlapPercent: overlapPercent,
|
|
1684
|
+
hasContextBefore: !!contextBefore,
|
|
1685
|
+
hasContextAfter: !!contextAfter,
|
|
1686
|
+
contentLength: chunk.content.length,
|
|
1687
|
+
contentHash: hashContent(chunk.content),
|
|
1688
|
+
indexedAt: new Date().toISOString(),
|
|
1689
|
+
};
|
|
1690
|
+
let searchableContent = `# ${chunk.title}\n\n`;
|
|
1691
|
+
if (contextBefore) {
|
|
1692
|
+
searchableContent += `[Context from previous section:]\n${contextBefore}\n\n---\n\n`;
|
|
1693
|
+
}
|
|
1694
|
+
searchableContent += chunk.content;
|
|
1695
|
+
if (contextAfter) {
|
|
1696
|
+
searchableContent += `\n\n---\n\n[Context from next section:]\n${contextAfter}`;
|
|
1697
|
+
}
|
|
1698
|
+
batchStoreEntry(db, chunkKey, NAMESPACE, searchableContent, chunkMetadata, [keyPrefix, 'chunk', `level-${chunk.level}`, chunk.title.toLowerCase().replace(/[^a-z0-9]+/g, '-')]);
|
|
1699
|
+
}
|
|
1700
|
+
return { docKey, status: 'indexed', chunks: chunks.length };
|
|
1701
|
+
}
|
|
1702
|
+
catch (err) {
|
|
1703
|
+
return { docKey, status: 'error', error: err.message, chunks: 0 };
|
|
1704
|
+
}
|
|
1705
|
+
};
|
|
1706
|
+
if (specificFile) {
|
|
1707
|
+
const filePath = pathModule.resolve(cwd, specificFile);
|
|
1708
|
+
if (!fs.existsSync(filePath)) {
|
|
1709
|
+
output.printError(`File not found: ${specificFile}`);
|
|
1710
|
+
db.close();
|
|
1711
|
+
return { success: false, exitCode: 1 };
|
|
1712
|
+
}
|
|
1713
|
+
let prefix = 'docs';
|
|
1714
|
+
if (specificFile.includes('.claude/guidance/') || specificFile.includes('.claude\\guidance\\')) {
|
|
1715
|
+
prefix = 'guidance';
|
|
1716
|
+
}
|
|
1717
|
+
const result = indexFile(filePath, prefix);
|
|
1718
|
+
if (result.status === 'indexed') {
|
|
1719
|
+
docsIndexed++;
|
|
1720
|
+
chunksIndexed += result.chunks;
|
|
1721
|
+
}
|
|
1722
|
+
else if (result.status === 'unchanged') {
|
|
1723
|
+
unchanged++;
|
|
1724
|
+
}
|
|
1725
|
+
else {
|
|
1726
|
+
errors++;
|
|
1727
|
+
output.printError(`${result.docKey}: ${result.error}`);
|
|
1728
|
+
}
|
|
1729
|
+
}
|
|
1730
|
+
else {
|
|
1731
|
+
const guidanceDir = pathModule.resolve(cwd, '.claude/guidance');
|
|
1732
|
+
if (!fs.existsSync(guidanceDir)) {
|
|
1733
|
+
output.printError(`Guidance directory not found: .claude/guidance/`);
|
|
1734
|
+
db.close();
|
|
1735
|
+
return { success: false, exitCode: 1 };
|
|
1736
|
+
}
|
|
1737
|
+
const files = fs.readdirSync(guidanceDir).filter((f) => f.endsWith('.md'));
|
|
1738
|
+
for (const file of files) {
|
|
1739
|
+
const filePath = pathModule.resolve(guidanceDir, file);
|
|
1740
|
+
const result = indexFile(filePath, 'guidance');
|
|
1741
|
+
if (result.status === 'indexed') {
|
|
1742
|
+
output.printSuccess(`${result.docKey} (${result.chunks} chunks)`);
|
|
1743
|
+
docsIndexed++;
|
|
1744
|
+
chunksIndexed += result.chunks;
|
|
1745
|
+
}
|
|
1746
|
+
else if (result.status === 'unchanged') {
|
|
1747
|
+
unchanged++;
|
|
1748
|
+
}
|
|
1749
|
+
else {
|
|
1750
|
+
output.printError(`${result.docKey}: ${result.error}`);
|
|
1751
|
+
errors++;
|
|
1752
|
+
}
|
|
1753
|
+
}
|
|
1754
|
+
// Clean stale entries for deleted files
|
|
1755
|
+
const docsStmt = db.prepare(`SELECT DISTINCT key FROM memory_entries WHERE namespace = ? AND key LIKE 'doc-%'`);
|
|
1756
|
+
docsStmt.bind([NAMESPACE]);
|
|
1757
|
+
const docs = [];
|
|
1758
|
+
while (docsStmt.step())
|
|
1759
|
+
docs.push(docsStmt.getAsObject());
|
|
1760
|
+
docsStmt.free();
|
|
1761
|
+
for (const { key } of docs) {
|
|
1762
|
+
if (!key.startsWith('doc-guidance-'))
|
|
1763
|
+
continue;
|
|
1764
|
+
const checkPath = pathModule.resolve(cwd, '.claude/guidance', key.replace('doc-guidance-', '') + '.md');
|
|
1765
|
+
if (!fs.existsSync(checkPath)) {
|
|
1766
|
+
const cp = key.replace('doc-', 'chunk-');
|
|
1767
|
+
db.run(`DELETE FROM memory_entries WHERE namespace = ? AND key LIKE ?`, [NAMESPACE, `${cp}%`]);
|
|
1768
|
+
db.run(`DELETE FROM memory_entries WHERE namespace = ? AND key = ?`, [NAMESPACE, key]);
|
|
1769
|
+
output.writeln(output.dim(` Removed stale: ${key}`));
|
|
1770
|
+
}
|
|
1771
|
+
}
|
|
1772
|
+
}
|
|
1773
|
+
// Save DB
|
|
1774
|
+
if (docsIndexed > 0 || chunksIndexed > 0) {
|
|
1775
|
+
saveAndCloseDb(db, dbPath);
|
|
1776
|
+
}
|
|
1777
|
+
else {
|
|
1778
|
+
db.close();
|
|
1779
|
+
}
|
|
1780
|
+
output.writeln();
|
|
1781
|
+
output.writeln(output.bold('Indexing Complete'));
|
|
1782
|
+
output.writeln(` Documents indexed: ${docsIndexed}`);
|
|
1783
|
+
output.writeln(` Chunks created: ${chunksIndexed}`);
|
|
1784
|
+
output.writeln(` Unchanged: ${unchanged}`);
|
|
1785
|
+
output.writeln(` Errors: ${errors}`);
|
|
1786
|
+
// Generate embeddings unless skipped
|
|
1787
|
+
if (!skipEmbeddings && (docsIndexed > 0 || chunksIndexed > 0)) {
|
|
1788
|
+
output.writeln();
|
|
1789
|
+
output.writeln(output.dim('Generating embeddings for new entries...'));
|
|
1790
|
+
try {
|
|
1791
|
+
const { generateEmbedding } = await import('../memory/memory-initializer.js');
|
|
1792
|
+
const { db: db2, dbPath: dbPath2 } = await openDb(cwd);
|
|
1793
|
+
const stmt = db2.prepare(`SELECT id, content FROM memory_entries WHERE namespace = ? AND (embedding IS NULL OR embedding = '')`);
|
|
1794
|
+
stmt.bind([NAMESPACE]);
|
|
1795
|
+
const entries = [];
|
|
1796
|
+
while (stmt.step())
|
|
1797
|
+
entries.push(stmt.getAsObject());
|
|
1798
|
+
stmt.free();
|
|
1799
|
+
let embedded = 0;
|
|
1800
|
+
for (const entry of entries) {
|
|
1801
|
+
try {
|
|
1802
|
+
const text = entry.content.substring(0, 1500);
|
|
1803
|
+
const { embedding, dimensions, model } = await generateEmbedding(text);
|
|
1804
|
+
db2.run(`UPDATE memory_entries SET embedding = ?, embedding_model = ?, embedding_dimensions = ?, updated_at = ? WHERE id = ?`, [JSON.stringify(embedding), model, dimensions, Date.now(), entry.id]);
|
|
1805
|
+
embedded++;
|
|
1806
|
+
}
|
|
1807
|
+
catch { /* skip individual failures */ }
|
|
1808
|
+
}
|
|
1809
|
+
if (embedded > 0) {
|
|
1810
|
+
saveAndCloseDb(db2, dbPath2);
|
|
1811
|
+
output.printSuccess(`Generated ${embedded} embeddings`);
|
|
1812
|
+
}
|
|
1813
|
+
else {
|
|
1814
|
+
db2.close();
|
|
1815
|
+
output.writeln(output.dim(' No new embeddings needed'));
|
|
1816
|
+
}
|
|
1817
|
+
}
|
|
1818
|
+
catch (err) {
|
|
1819
|
+
output.writeln(output.dim(` Embedding generation skipped: ${err.message}`));
|
|
1820
|
+
}
|
|
1821
|
+
}
|
|
1822
|
+
return { success: errors === 0, exitCode: errors > 0 ? 1 : 0 };
|
|
1823
|
+
}
|
|
1824
|
+
};
|
|
1825
|
+
// ============================================================================
|
|
1826
|
+
// rebuild-index subcommand
|
|
1827
|
+
// ============================================================================
|
|
1828
|
+
const rebuildIndexCommand = {
|
|
1829
|
+
name: 'rebuild-index',
|
|
1830
|
+
description: 'Regenerate embeddings for memory entries missing them (or all with --force)',
|
|
1831
|
+
options: [
|
|
1832
|
+
{
|
|
1833
|
+
name: 'force',
|
|
1834
|
+
short: 'f',
|
|
1835
|
+
description: 'Re-embed all entries, not just those missing embeddings',
|
|
1836
|
+
type: 'boolean',
|
|
1837
|
+
default: false
|
|
1838
|
+
},
|
|
1839
|
+
{
|
|
1840
|
+
name: 'namespace',
|
|
1841
|
+
short: 'n',
|
|
1842
|
+
description: 'Only process entries in this namespace',
|
|
1843
|
+
type: 'string'
|
|
1844
|
+
},
|
|
1845
|
+
{
|
|
1846
|
+
name: 'verbose',
|
|
1847
|
+
description: 'Show detailed progress',
|
|
1848
|
+
type: 'boolean',
|
|
1849
|
+
default: false
|
|
1850
|
+
}
|
|
1851
|
+
],
|
|
1852
|
+
examples: [
|
|
1853
|
+
{ command: 'claude-flow memory rebuild-index', description: 'Embed entries without embeddings' },
|
|
1854
|
+
{ command: 'claude-flow memory rebuild-index --force', description: 'Re-embed all entries' },
|
|
1855
|
+
{ command: 'claude-flow memory rebuild-index -n guidance', description: 'Only guidance namespace' }
|
|
1856
|
+
],
|
|
1857
|
+
action: async (ctx) => {
|
|
1858
|
+
const forceAll = ctx.flags.force;
|
|
1859
|
+
const namespaceFilter = ctx.flags.namespace;
|
|
1860
|
+
const verbose = ctx.flags.verbose;
|
|
1861
|
+
const BATCH_SIZE = 100;
|
|
1862
|
+
const cwd = ctx.cwd || process.cwd();
|
|
1863
|
+
output.writeln();
|
|
1864
|
+
output.writeln(output.bold('Rebuilding Embedding Index'));
|
|
1865
|
+
output.writeln(output.dim('─'.repeat(50)));
|
|
1866
|
+
const { db, dbPath } = await openDb(cwd);
|
|
1867
|
+
// Build query
|
|
1868
|
+
let sql = `SELECT id, key, namespace, content FROM memory_entries WHERE status = 'active'`;
|
|
1869
|
+
const params = [];
|
|
1870
|
+
if (!forceAll) {
|
|
1871
|
+
sql += ` AND (embedding IS NULL OR embedding = '')`;
|
|
1872
|
+
}
|
|
1873
|
+
if (namespaceFilter) {
|
|
1874
|
+
sql += ` AND namespace = ?`;
|
|
1875
|
+
params.push(namespaceFilter);
|
|
1876
|
+
}
|
|
1877
|
+
sql += ` ORDER BY created_at DESC`;
|
|
1878
|
+
const stmt = db.prepare(sql);
|
|
1879
|
+
stmt.bind(params);
|
|
1880
|
+
const entries = [];
|
|
1881
|
+
while (stmt.step())
|
|
1882
|
+
entries.push(stmt.getAsObject());
|
|
1883
|
+
stmt.free();
|
|
1884
|
+
if (entries.length === 0) {
|
|
1885
|
+
// Show stats
|
|
1886
|
+
const totalStmt = db.prepare(`SELECT COUNT(*) as cnt FROM memory_entries WHERE status = 'active'`);
|
|
1887
|
+
const total = totalStmt.step() ? totalStmt.getAsObject().cnt : 0;
|
|
1888
|
+
totalStmt.free();
|
|
1889
|
+
const embedStmt = db.prepare(`SELECT COUNT(*) as cnt FROM memory_entries WHERE status = 'active' AND embedding IS NOT NULL AND embedding != ''`);
|
|
1890
|
+
const withEmbed = embedStmt.step() ? embedStmt.getAsObject().cnt : 0;
|
|
1891
|
+
embedStmt.free();
|
|
1892
|
+
output.printSuccess(`All entries already have embeddings (${withEmbed}/${total})`);
|
|
1893
|
+
db.close();
|
|
1894
|
+
return { success: true };
|
|
1895
|
+
}
|
|
1896
|
+
output.writeln(`Found ${entries.length} entries to embed`);
|
|
1897
|
+
output.writeln();
|
|
1898
|
+
const { generateEmbedding } = await import('../memory/memory-initializer.js');
|
|
1899
|
+
let embedded = 0;
|
|
1900
|
+
let failed = 0;
|
|
1901
|
+
const startTime = Date.now();
|
|
1902
|
+
for (let i = 0; i < entries.length; i++) {
|
|
1903
|
+
const entry = entries[i];
|
|
1904
|
+
try {
|
|
1905
|
+
const text = entry.content.substring(0, 1500);
|
|
1906
|
+
const { embedding, dimensions, model } = await generateEmbedding(text);
|
|
1907
|
+
db.run(`UPDATE memory_entries SET embedding = ?, embedding_model = ?, embedding_dimensions = ?, updated_at = ? WHERE id = ?`, [JSON.stringify(embedding), model, dimensions, Date.now(), entry.id]);
|
|
1908
|
+
embedded++;
|
|
1909
|
+
if (verbose && (i + 1) % 10 === 0) {
|
|
1910
|
+
output.writeln(output.dim(` Progress: ${i + 1}/${entries.length}`));
|
|
1911
|
+
}
|
|
1912
|
+
}
|
|
1913
|
+
catch (err) {
|
|
1914
|
+
if (verbose) {
|
|
1915
|
+
output.writeln(output.dim(` Failed: ${entry.key}: ${err.message}`));
|
|
1916
|
+
}
|
|
1917
|
+
failed++;
|
|
1918
|
+
}
|
|
1919
|
+
// Batch save every BATCH_SIZE entries
|
|
1920
|
+
if ((i + 1) % BATCH_SIZE === 0) {
|
|
1921
|
+
const fs = await import('fs');
|
|
1922
|
+
const data = db.export();
|
|
1923
|
+
fs.writeFileSync(dbPath, Buffer.from(data));
|
|
1924
|
+
}
|
|
1925
|
+
}
|
|
1926
|
+
const totalTime = ((Date.now() - startTime) / 1000).toFixed(1);
|
|
1927
|
+
// Final stats
|
|
1928
|
+
const totalStmt2 = db.prepare(`SELECT COUNT(*) as cnt FROM memory_entries WHERE status = 'active'`);
|
|
1929
|
+
const total2 = totalStmt2.step() ? totalStmt2.getAsObject().cnt : 0;
|
|
1930
|
+
totalStmt2.free();
|
|
1931
|
+
const embedStmt2 = db.prepare(`SELECT COUNT(*) as cnt FROM memory_entries WHERE status = 'active' AND embedding IS NOT NULL AND embedding != ''`);
|
|
1932
|
+
const withEmbed2 = embedStmt2.step() ? embedStmt2.getAsObject().cnt : 0;
|
|
1933
|
+
embedStmt2.free();
|
|
1934
|
+
if (embedded > 0) {
|
|
1935
|
+
saveAndCloseDb(db, dbPath);
|
|
1936
|
+
}
|
|
1937
|
+
else {
|
|
1938
|
+
db.close();
|
|
1939
|
+
}
|
|
1940
|
+
output.writeln();
|
|
1941
|
+
output.writeln(output.bold('Embedding Generation Complete'));
|
|
1942
|
+
output.writeln(` Embedded: ${embedded} entries`);
|
|
1943
|
+
output.writeln(` Failed: ${failed} entries`);
|
|
1944
|
+
output.writeln(` Time: ${totalTime}s`);
|
|
1945
|
+
output.writeln(` Total coverage: ${withEmbed2}/${total2} entries`);
|
|
1946
|
+
return { success: failed === 0, exitCode: failed > 0 ? 1 : 0 };
|
|
1947
|
+
}
|
|
1948
|
+
};
|
|
1949
|
+
// ============================================================================
|
|
1950
|
+
// code-map subcommand
|
|
1951
|
+
// ============================================================================
|
|
1952
|
+
const EXCLUDE_DIRS = [
|
|
1953
|
+
'back-office-template', 'template', '.claude', 'node_modules',
|
|
1954
|
+
'dist', 'build', '.next', 'coverage',
|
|
1955
|
+
];
|
|
1956
|
+
const DIR_DESCRIPTIONS = {
|
|
1957
|
+
entities: 'MikroORM entity definitions',
|
|
1958
|
+
services: 'business logic services',
|
|
1959
|
+
routes: 'Fastify route handlers',
|
|
1960
|
+
middleware: 'request middleware (auth, validation, tenancy)',
|
|
1961
|
+
schemas: 'Zod validation schemas',
|
|
1962
|
+
types: 'TypeScript type definitions',
|
|
1963
|
+
utils: 'utility helpers',
|
|
1964
|
+
config: 'configuration',
|
|
1965
|
+
migrations: 'database migrations',
|
|
1966
|
+
scripts: 'CLI scripts',
|
|
1967
|
+
components: 'React components',
|
|
1968
|
+
pages: 'route page components',
|
|
1969
|
+
contexts: 'React context providers',
|
|
1970
|
+
hooks: 'React custom hooks',
|
|
1971
|
+
layout: 'app shell layout',
|
|
1972
|
+
themes: 'MUI theme configuration',
|
|
1973
|
+
api: 'API client layer',
|
|
1974
|
+
locales: 'i18n translation files',
|
|
1975
|
+
tests: 'test suites',
|
|
1976
|
+
e2e: 'end-to-end tests',
|
|
1977
|
+
};
|
|
1978
|
+
const TS_PATTERNS = [
|
|
1979
|
+
/^export\s+(?:default\s+)?(?:abstract\s+)?class\s+(\w+)(?:\s+extends\s+([\w.]+))?(?:\s+implements\s+([\w,\s.]+))?/,
|
|
1980
|
+
/^export\s+(?:default\s+)?interface\s+(\w+)(?:\s+extends\s+([\w,\s.]+))?/,
|
|
1981
|
+
/^export\s+(?:default\s+)?type\s+(\w+)\s*[=<]/,
|
|
1982
|
+
/^export\s+(?:const\s+)?enum\s+(\w+)/,
|
|
1983
|
+
/^export\s+(?:default\s+)?(?:async\s+)?function\s+(\w+)/,
|
|
1984
|
+
/^export\s+(?:default\s+)?const\s+(\w+)\s*[=:]/,
|
|
1985
|
+
];
|
|
1986
|
+
const ENTITY_DECORATOR = /@Entity\s*\(/;
|
|
1987
|
+
const IFACE_MAP_BATCH = 20;
|
|
1988
|
+
const TYPE_INDEX_BATCH = 80;
|
|
1989
|
+
function detectKind(line) {
|
|
1990
|
+
if (/\bclass\b/.test(line))
|
|
1991
|
+
return 'class';
|
|
1992
|
+
if (/\binterface\b/.test(line))
|
|
1993
|
+
return 'interface';
|
|
1994
|
+
if (/\btype\b/.test(line))
|
|
1995
|
+
return 'type';
|
|
1996
|
+
if (/\benum\b/.test(line))
|
|
1997
|
+
return 'enum';
|
|
1998
|
+
if (/\bfunction\b/.test(line))
|
|
1999
|
+
return 'function';
|
|
2000
|
+
if (/\bconst\b/.test(line))
|
|
2001
|
+
return 'const';
|
|
2002
|
+
return 'export';
|
|
2003
|
+
}
|
|
2004
|
+
function extractTypesFromFile(filePath, projectRoot) {
|
|
2005
|
+
const fullPath = pathModule.resolve(projectRoot, filePath);
|
|
2006
|
+
if (!fs.existsSync(fullPath))
|
|
2007
|
+
return [];
|
|
2008
|
+
let content;
|
|
2009
|
+
try {
|
|
2010
|
+
content = fs.readFileSync(fullPath, 'utf-8');
|
|
2011
|
+
}
|
|
2012
|
+
catch {
|
|
2013
|
+
return [];
|
|
2014
|
+
}
|
|
2015
|
+
const lines = content.split('\n');
|
|
2016
|
+
const types = [];
|
|
2017
|
+
const seen = new Set();
|
|
2018
|
+
let isEntityNext = false;
|
|
2019
|
+
for (let i = 0; i < lines.length; i++) {
|
|
2020
|
+
const line = lines[i].trim();
|
|
2021
|
+
if (ENTITY_DECORATOR.test(line)) {
|
|
2022
|
+
isEntityNext = true;
|
|
2023
|
+
continue;
|
|
2024
|
+
}
|
|
2025
|
+
for (const pattern of TS_PATTERNS) {
|
|
2026
|
+
const m = line.match(pattern);
|
|
2027
|
+
if (m && m[1] && !seen.has(m[1])) {
|
|
2028
|
+
seen.add(m[1]);
|
|
2029
|
+
const kind = detectKind(line);
|
|
2030
|
+
const bases = (m[2] || '').trim();
|
|
2031
|
+
const implements_ = (m[3] || '').trim();
|
|
2032
|
+
types.push({
|
|
2033
|
+
name: m[1],
|
|
2034
|
+
kind,
|
|
2035
|
+
bases: bases || null,
|
|
2036
|
+
implements: implements_ || null,
|
|
2037
|
+
isEntity: isEntityNext,
|
|
2038
|
+
file: filePath,
|
|
2039
|
+
});
|
|
2040
|
+
isEntityNext = false;
|
|
2041
|
+
break;
|
|
2042
|
+
}
|
|
2043
|
+
}
|
|
2044
|
+
if (isEntityNext && !line.startsWith('@') && !line.startsWith('export') && line.length > 0) {
|
|
2045
|
+
isEntityNext = false;
|
|
2046
|
+
}
|
|
2047
|
+
}
|
|
2048
|
+
return types;
|
|
2049
|
+
}
|
|
2050
|
+
function getProjectName(filePath) {
|
|
2051
|
+
const parts = filePath.split('/');
|
|
2052
|
+
if (parts[0] === 'packages' && parts.length >= 2)
|
|
2053
|
+
return `${parts[0]}/${parts[1]}`;
|
|
2054
|
+
if (parts[0] === 'back-office' && parts.length >= 2)
|
|
2055
|
+
return `${parts[0]}/${parts[1]}`;
|
|
2056
|
+
if (parts[0] === 'customer-portal' && parts.length >= 2)
|
|
2057
|
+
return `${parts[0]}/${parts[1]}`;
|
|
2058
|
+
if (parts[0] === 'admin-console' && parts.length >= 2)
|
|
2059
|
+
return `${parts[0]}/${parts[1]}`;
|
|
2060
|
+
if (parts[0] === 'webhooks' && parts.length >= 2)
|
|
2061
|
+
return `${parts[0]}/${parts[1]}`;
|
|
2062
|
+
if (parts[0] === 'mobile-app')
|
|
2063
|
+
return 'mobile-app';
|
|
2064
|
+
if (parts[0] === 'tests')
|
|
2065
|
+
return 'tests';
|
|
2066
|
+
if (parts[0] === 'scripts')
|
|
2067
|
+
return 'scripts';
|
|
2068
|
+
return parts[0];
|
|
2069
|
+
}
|
|
2070
|
+
const codeMapCommand = {
|
|
2071
|
+
name: 'code-map',
|
|
2072
|
+
description: 'Generate structural code map (project overviews, directory details, type indexes) into code-map namespace',
|
|
2073
|
+
options: [
|
|
2074
|
+
{
|
|
2075
|
+
name: 'force',
|
|
2076
|
+
short: 'f',
|
|
2077
|
+
description: 'Force full regeneration even if file list unchanged',
|
|
2078
|
+
type: 'boolean',
|
|
2079
|
+
default: false
|
|
2080
|
+
},
|
|
2081
|
+
{
|
|
2082
|
+
name: 'verbose',
|
|
2083
|
+
description: 'Show detailed logging',
|
|
2084
|
+
type: 'boolean',
|
|
2085
|
+
default: false
|
|
2086
|
+
},
|
|
2087
|
+
{
|
|
2088
|
+
name: 'stats',
|
|
2089
|
+
description: 'Print stats and exit without regenerating',
|
|
2090
|
+
type: 'boolean',
|
|
2091
|
+
default: false
|
|
2092
|
+
},
|
|
2093
|
+
{
|
|
2094
|
+
name: 'no-embeddings',
|
|
2095
|
+
description: 'Skip embedding generation after mapping',
|
|
2096
|
+
type: 'boolean',
|
|
2097
|
+
default: false
|
|
2098
|
+
}
|
|
2099
|
+
],
|
|
2100
|
+
examples: [
|
|
2101
|
+
{ command: 'claude-flow memory code-map', description: 'Incremental code map update' },
|
|
2102
|
+
{ command: 'claude-flow memory code-map --force', description: 'Full regeneration' },
|
|
2103
|
+
{ command: 'claude-flow memory code-map --stats', description: 'Show stats only' }
|
|
2104
|
+
],
|
|
2105
|
+
action: async (ctx) => {
|
|
2106
|
+
const forceRegen = ctx.flags.force;
|
|
2107
|
+
const verbose = ctx.flags.verbose;
|
|
2108
|
+
const statsOnly = ctx.flags.stats;
|
|
2109
|
+
const skipEmbeddings = ctx.flags['no-embeddings'];
|
|
2110
|
+
const NAMESPACE = 'code-map';
|
|
2111
|
+
const fs = await import('fs');
|
|
2112
|
+
const pathMod = await import('path');
|
|
2113
|
+
const { execSync } = await import('child_process');
|
|
2114
|
+
const { createHash } = await import('crypto');
|
|
2115
|
+
const cwd = ctx.cwd || process.cwd();
|
|
2116
|
+
const hashCachePath = pathModule.join(cwd, '.swarm', 'code-map-hash.txt');
|
|
2117
|
+
output.writeln();
|
|
2118
|
+
output.writeln(output.bold('Generating Code Map'));
|
|
2119
|
+
output.writeln(output.dim('─'.repeat(50)));
|
|
2120
|
+
// 1. Get source files via git
|
|
2121
|
+
let raw;
|
|
2122
|
+
try {
|
|
2123
|
+
raw = execSync(`git ls-files -- "*.ts" "*.tsx" "*.js" "*.mjs" "*.jsx"`, { cwd, encoding: 'utf-8', maxBuffer: 10 * 1024 * 1024 }).trim();
|
|
2124
|
+
}
|
|
2125
|
+
catch {
|
|
2126
|
+
output.printError('Failed to list source files via git. Is this a git repository?');
|
|
2127
|
+
return { success: false, exitCode: 1 };
|
|
2128
|
+
}
|
|
2129
|
+
const files = raw ? raw.split('\n').filter((f) => {
|
|
2130
|
+
for (const ex of EXCLUDE_DIRS) {
|
|
2131
|
+
if (f.startsWith(ex + '/') || f.startsWith(ex + '\\'))
|
|
2132
|
+
return false;
|
|
2133
|
+
}
|
|
2134
|
+
return true;
|
|
2135
|
+
}) : [];
|
|
2136
|
+
if (files.length === 0) {
|
|
2137
|
+
output.writeln('No source files found.');
|
|
2138
|
+
return { success: true };
|
|
2139
|
+
}
|
|
2140
|
+
output.writeln(`Found ${files.length} source files`);
|
|
2141
|
+
// 2. Hash check
|
|
2142
|
+
const sorted = [...files].sort();
|
|
2143
|
+
const currentHash = createHash('sha256').update(sorted.join('\n')).digest('hex');
|
|
2144
|
+
if (statsOnly) {
|
|
2145
|
+
const { db } = await openDb(cwd);
|
|
2146
|
+
const stmt = db.prepare(`SELECT COUNT(*) as cnt FROM memory_entries WHERE namespace = ?`);
|
|
2147
|
+
stmt.bind([NAMESPACE]);
|
|
2148
|
+
const count = stmt.step() ? stmt.getAsObject().cnt : 0;
|
|
2149
|
+
stmt.free();
|
|
2150
|
+
db.close();
|
|
2151
|
+
output.writeln(`Stats: ${files.length} source files, ${count} chunks in code-map namespace`);
|
|
2152
|
+
output.writeln(`File list hash: ${currentHash.slice(0, 12)}...`);
|
|
2153
|
+
return { success: true };
|
|
2154
|
+
}
|
|
2155
|
+
// Check if unchanged
|
|
2156
|
+
if (!forceRegen && fs.existsSync(hashCachePath)) {
|
|
2157
|
+
const cached = fs.readFileSync(hashCachePath, 'utf-8').trim();
|
|
2158
|
+
if (cached === currentHash) {
|
|
2159
|
+
const { db } = await openDb(cwd);
|
|
2160
|
+
const stmt = db.prepare(`SELECT COUNT(*) as cnt FROM memory_entries WHERE namespace = ?`);
|
|
2161
|
+
stmt.bind([NAMESPACE]);
|
|
2162
|
+
const count = stmt.step() ? stmt.getAsObject().cnt : 0;
|
|
2163
|
+
stmt.free();
|
|
2164
|
+
db.close();
|
|
2165
|
+
if (count > 0) {
|
|
2166
|
+
output.writeln(output.dim(`Skipping -- file list unchanged (${count} chunks in DB)`));
|
|
2167
|
+
return { success: true };
|
|
2168
|
+
}
|
|
2169
|
+
}
|
|
2170
|
+
}
|
|
2171
|
+
// 3. Extract types
|
|
2172
|
+
output.writeln('Extracting type declarations...');
|
|
2173
|
+
const allTypes = [];
|
|
2174
|
+
const filesByProject = {};
|
|
2175
|
+
const typesByProject = {};
|
|
2176
|
+
const typesByDir = {};
|
|
2177
|
+
for (const file of files) {
|
|
2178
|
+
const project = getProjectName(file);
|
|
2179
|
+
if (!filesByProject[project])
|
|
2180
|
+
filesByProject[project] = [];
|
|
2181
|
+
filesByProject[project].push(file);
|
|
2182
|
+
const types = extractTypesFromFile(file, cwd);
|
|
2183
|
+
for (const t of types) {
|
|
2184
|
+
allTypes.push(t);
|
|
2185
|
+
if (!typesByProject[project])
|
|
2186
|
+
typesByProject[project] = [];
|
|
2187
|
+
typesByProject[project].push(t);
|
|
2188
|
+
const dir = pathModule.dirname(t.file).replace(/\\/g, '/');
|
|
2189
|
+
if (!typesByDir[dir])
|
|
2190
|
+
typesByDir[dir] = [];
|
|
2191
|
+
typesByDir[dir].push(t);
|
|
2192
|
+
}
|
|
2193
|
+
}
|
|
2194
|
+
output.writeln(`Extracted ${allTypes.length} types from ${Object.keys(filesByProject).length} projects`);
|
|
2195
|
+
// 4. Generate chunks
|
|
2196
|
+
const allChunks = [];
|
|
2197
|
+
// Project overviews
|
|
2198
|
+
for (const [project, projFiles] of Object.entries(filesByProject)) {
|
|
2199
|
+
const types = typesByProject[project] || [];
|
|
2200
|
+
const dirMap = {};
|
|
2201
|
+
for (const t of types) {
|
|
2202
|
+
const rel = pathModule.relative(project, pathModule.dirname(t.file)).replace(/\\/g, '/') || '(root)';
|
|
2203
|
+
if (!dirMap[rel])
|
|
2204
|
+
dirMap[rel] = [];
|
|
2205
|
+
dirMap[rel].push(t.name);
|
|
2206
|
+
}
|
|
2207
|
+
// Detect primary language
|
|
2208
|
+
let tsx = 0, ts = 0, js = 0;
|
|
2209
|
+
for (const f of projFiles) {
|
|
2210
|
+
const ext = pathModule.extname(f);
|
|
2211
|
+
if (ext === '.tsx' || ext === '.jsx')
|
|
2212
|
+
tsx++;
|
|
2213
|
+
else if (ext === '.ts')
|
|
2214
|
+
ts++;
|
|
2215
|
+
else
|
|
2216
|
+
js++;
|
|
2217
|
+
}
|
|
2218
|
+
const lang = tsx > ts && tsx > js ? 'React/TypeScript' : ts >= js ? 'TypeScript' : 'JavaScript';
|
|
2219
|
+
let content = `# ${project} [${lang}, ${projFiles.length} files, ${types.length} types]\n\n`;
|
|
2220
|
+
for (const dir of Object.keys(dirMap).sort()) {
|
|
2221
|
+
const names = dirMap[dir];
|
|
2222
|
+
const lastDir = dir.split('/').pop() || '';
|
|
2223
|
+
const desc = DIR_DESCRIPTIONS[lastDir];
|
|
2224
|
+
const descStr = desc ? ` -- ${desc}` : '';
|
|
2225
|
+
const shown = names.slice(0, 8).join(', ');
|
|
2226
|
+
const overflow = names.length > 8 ? `, ... (+${names.length - 8} more)` : '';
|
|
2227
|
+
content += ` ${dir}${descStr}: ${shown}${overflow}\n`;
|
|
2228
|
+
}
|
|
2229
|
+
allChunks.push({
|
|
2230
|
+
key: `project:${project}`,
|
|
2231
|
+
content: content.trim(),
|
|
2232
|
+
metadata: { kind: 'project-overview', project, language: lang, fileCount: projFiles.length, typeCount: types.length },
|
|
2233
|
+
tags: ['project', project],
|
|
2234
|
+
});
|
|
2235
|
+
}
|
|
2236
|
+
// Directory details
|
|
2237
|
+
for (const [dir, types] of Object.entries(typesByDir)) {
|
|
2238
|
+
if (types.length < 2)
|
|
2239
|
+
continue;
|
|
2240
|
+
const lastDir = dir.split('/').pop() || '';
|
|
2241
|
+
const desc = DIR_DESCRIPTIONS[lastDir];
|
|
2242
|
+
let content = `# ${dir} (${types.length} types)\n`;
|
|
2243
|
+
if (desc)
|
|
2244
|
+
content += `${desc}\n`;
|
|
2245
|
+
content += '\n';
|
|
2246
|
+
const sortedTypes = [...types].sort((a, b) => a.name.localeCompare(b.name));
|
|
2247
|
+
for (const t of sortedTypes) {
|
|
2248
|
+
const suffix = [];
|
|
2249
|
+
if (t.bases)
|
|
2250
|
+
suffix.push(`: ${t.bases}`);
|
|
2251
|
+
if (t.implements)
|
|
2252
|
+
suffix.push(`: ${t.implements}`);
|
|
2253
|
+
const suffixStr = suffix.length ? ` ${suffix.join(' ')}` : '';
|
|
2254
|
+
const fileName = pathModule.basename(t.file);
|
|
2255
|
+
content += ` ${t.name}${suffixStr} (${fileName})\n`;
|
|
2256
|
+
}
|
|
2257
|
+
allChunks.push({
|
|
2258
|
+
key: `dir:${dir}`,
|
|
2259
|
+
content: content.trim(),
|
|
2260
|
+
metadata: { kind: 'directory-detail', directory: dir, typeCount: types.length },
|
|
2261
|
+
tags: ['directory', dir.split('/')[0]],
|
|
2262
|
+
});
|
|
2263
|
+
}
|
|
2264
|
+
// Interface maps
|
|
2265
|
+
const interfaces = new Map();
|
|
2266
|
+
for (const t of allTypes) {
|
|
2267
|
+
if (t.kind === 'interface' && !interfaces.has(t.name)) {
|
|
2268
|
+
interfaces.set(t.name, { defined: t.file, implementations: [] });
|
|
2269
|
+
}
|
|
2270
|
+
}
|
|
2271
|
+
for (const t of allTypes) {
|
|
2272
|
+
if (t.kind !== 'class')
|
|
2273
|
+
continue;
|
|
2274
|
+
const impls = t.implements ? t.implements.split(',').map((s) => s.trim()) : [];
|
|
2275
|
+
const bases = t.bases ? [t.bases.trim()] : [];
|
|
2276
|
+
for (const iface of [...impls, ...bases]) {
|
|
2277
|
+
if (interfaces.has(iface)) {
|
|
2278
|
+
interfaces.get(iface).implementations.push({ name: t.name, project: getProjectName(t.file) });
|
|
2279
|
+
}
|
|
2280
|
+
}
|
|
2281
|
+
}
|
|
2282
|
+
const mapped = Array.from(interfaces.entries())
|
|
2283
|
+
.filter(([, v]) => v.implementations.length > 0)
|
|
2284
|
+
.sort(([a], [b]) => a.localeCompare(b));
|
|
2285
|
+
if (mapped.length > 0) {
|
|
2286
|
+
const totalBatches = Math.ceil(mapped.length / IFACE_MAP_BATCH);
|
|
2287
|
+
for (let i = 0; i < mapped.length; i += IFACE_MAP_BATCH) {
|
|
2288
|
+
const batch = mapped.slice(i, i + IFACE_MAP_BATCH);
|
|
2289
|
+
const batchNum = Math.floor(i / IFACE_MAP_BATCH) + 1;
|
|
2290
|
+
let content = `# Interface-to-Implementation Map (${batchNum}/${totalBatches})\n\n`;
|
|
2291
|
+
for (const [name, info] of batch) {
|
|
2292
|
+
const implStr = info.implementations.map(impl => `${impl.name} (${impl.project})`).join(', ');
|
|
2293
|
+
content += ` ${name} -> ${implStr}\n`;
|
|
2294
|
+
}
|
|
2295
|
+
allChunks.push({
|
|
2296
|
+
key: `iface-map:${batchNum}`,
|
|
2297
|
+
content: content.trim(),
|
|
2298
|
+
metadata: { kind: 'interface-map', batch: batchNum, totalBatches, count: batch.length },
|
|
2299
|
+
tags: ['interface-map'],
|
|
2300
|
+
});
|
|
2301
|
+
}
|
|
2302
|
+
}
|
|
2303
|
+
// Type index
|
|
2304
|
+
const sortedAllTypes = [...allTypes].sort((a, b) => a.name.localeCompare(b.name));
|
|
2305
|
+
const typeIdxTotalBatches = Math.ceil(sortedAllTypes.length / TYPE_INDEX_BATCH);
|
|
2306
|
+
for (let i = 0; i < sortedAllTypes.length; i += TYPE_INDEX_BATCH) {
|
|
2307
|
+
const batch = sortedAllTypes.slice(i, i + TYPE_INDEX_BATCH);
|
|
2308
|
+
const batchNum = Math.floor(i / TYPE_INDEX_BATCH) + 1;
|
|
2309
|
+
let content = `# Type Index (batch ${batchNum}, ${batch.length} types)\n\n`;
|
|
2310
|
+
for (const t of batch) {
|
|
2311
|
+
const ext = pathModule.extname(t.file);
|
|
2312
|
+
const lang = (ext === '.tsx' || ext === '.jsx') ? 'tsx' : ext === '.ts' ? 'ts' : ext === '.mjs' ? 'esm' : 'js';
|
|
2313
|
+
content += ` ${t.name} -> ${t.file} [${lang}]\n`;
|
|
2314
|
+
}
|
|
2315
|
+
allChunks.push({
|
|
2316
|
+
key: `type-index:${batchNum}`,
|
|
2317
|
+
content: content.trim(),
|
|
2318
|
+
metadata: { kind: 'type-index', batch: batchNum, totalBatches: typeIdxTotalBatches, count: batch.length },
|
|
2319
|
+
tags: ['type-index'],
|
|
2320
|
+
});
|
|
2321
|
+
}
|
|
2322
|
+
output.writeln(`Generated ${allChunks.length} chunks`);
|
|
2323
|
+
if (verbose) {
|
|
2324
|
+
const projectCount = allChunks.filter(c => c.metadata.kind === 'project-overview').length;
|
|
2325
|
+
const dirCount = allChunks.filter(c => c.metadata.kind === 'directory-detail').length;
|
|
2326
|
+
const ifaceCount = allChunks.filter(c => c.metadata.kind === 'interface-map').length;
|
|
2327
|
+
const typeIdxCount = allChunks.filter(c => c.metadata.kind === 'type-index').length;
|
|
2328
|
+
output.writeln(` Project overviews: ${projectCount}`);
|
|
2329
|
+
output.writeln(` Directory details: ${dirCount}`);
|
|
2330
|
+
output.writeln(` Interface maps: ${ifaceCount}`);
|
|
2331
|
+
output.writeln(` Type index: ${typeIdxCount}`);
|
|
2332
|
+
}
|
|
2333
|
+
// 5. Write to DB
|
|
2334
|
+
output.writeln('Writing to memory database...');
|
|
2335
|
+
const { db, dbPath } = await openDb(cwd);
|
|
2336
|
+
// Clear old code-map entries
|
|
2337
|
+
db.run(`DELETE FROM memory_entries WHERE namespace = ?`, [NAMESPACE]);
|
|
2338
|
+
for (const chunk of allChunks) {
|
|
2339
|
+
batchStoreEntry(db, chunk.key, NAMESPACE, chunk.content, chunk.metadata, chunk.tags);
|
|
2340
|
+
}
|
|
2341
|
+
saveAndCloseDb(db, dbPath);
|
|
2342
|
+
// Save hash
|
|
2343
|
+
const hashDir = pathModule.dirname(hashCachePath);
|
|
2344
|
+
if (!fs.existsSync(hashDir)) {
|
|
2345
|
+
fs.mkdirSync(hashDir, { recursive: true });
|
|
2346
|
+
}
|
|
2347
|
+
fs.writeFileSync(hashCachePath, currentHash, 'utf-8');
|
|
2348
|
+
output.printSuccess(`${allChunks.length} chunks written to code-map namespace`);
|
|
2349
|
+
// Generate embeddings unless skipped
|
|
2350
|
+
if (!skipEmbeddings) {
|
|
2351
|
+
output.writeln(output.dim('Generating embeddings for code-map entries...'));
|
|
2352
|
+
try {
|
|
2353
|
+
const { generateEmbedding } = await import('../memory/memory-initializer.js');
|
|
2354
|
+
const { db: db2, dbPath: dbPath2 } = await openDb(cwd);
|
|
2355
|
+
const stmt = db2.prepare(`SELECT id, content FROM memory_entries WHERE namespace = ? AND (embedding IS NULL OR embedding = '')`);
|
|
2356
|
+
stmt.bind([NAMESPACE]);
|
|
2357
|
+
const entries = [];
|
|
2358
|
+
while (stmt.step())
|
|
2359
|
+
entries.push(stmt.getAsObject());
|
|
2360
|
+
stmt.free();
|
|
2361
|
+
let embedded = 0;
|
|
2362
|
+
for (const entry of entries) {
|
|
2363
|
+
try {
|
|
2364
|
+
const text = entry.content.substring(0, 1500);
|
|
2365
|
+
const { embedding, dimensions, model } = await generateEmbedding(text);
|
|
2366
|
+
db2.run(`UPDATE memory_entries SET embedding = ?, embedding_model = ?, embedding_dimensions = ?, updated_at = ? WHERE id = ?`, [JSON.stringify(embedding), model, dimensions, Date.now(), entry.id]);
|
|
2367
|
+
embedded++;
|
|
2368
|
+
}
|
|
2369
|
+
catch { /* skip */ }
|
|
2370
|
+
}
|
|
2371
|
+
if (embedded > 0) {
|
|
2372
|
+
saveAndCloseDb(db2, dbPath2);
|
|
2373
|
+
output.printSuccess(`Generated ${embedded} embeddings`);
|
|
2374
|
+
}
|
|
2375
|
+
else {
|
|
2376
|
+
db2.close();
|
|
2377
|
+
}
|
|
2378
|
+
}
|
|
2379
|
+
catch (err) {
|
|
2380
|
+
output.writeln(output.dim(` Embedding generation skipped: ${err.message}`));
|
|
2381
|
+
}
|
|
2382
|
+
}
|
|
2383
|
+
return { success: true };
|
|
2384
|
+
}
|
|
2385
|
+
};
|
|
2386
|
+
// Main memory command
|
|
2387
|
+
export const memoryCommand = {
|
|
2388
|
+
name: 'memory',
|
|
2389
|
+
description: 'Memory management commands',
|
|
2390
|
+
subcommands: [initMemoryCommand, storeCommand, retrieveCommand, searchCommand, listCommand, deleteCommand, statsCommand, configureCommand, cleanupCommand, compressCommand, exportCommand, importCommand, indexGuidanceCommand, rebuildIndexCommand, codeMapCommand],
|
|
2391
|
+
options: [],
|
|
2392
|
+
examples: [
|
|
2393
|
+
{ command: 'claude-flow memory store -k "key" -v "value"', description: 'Store data' },
|
|
2394
|
+
{ command: 'claude-flow memory search -q "auth patterns"', description: 'Search memory' },
|
|
2395
|
+
{ command: 'claude-flow memory stats', description: 'Show statistics' }
|
|
2396
|
+
],
|
|
2397
|
+
action: async (ctx) => {
|
|
2398
|
+
output.writeln();
|
|
2399
|
+
output.writeln(output.bold('Memory Management Commands'));
|
|
2400
|
+
output.writeln();
|
|
2401
|
+
output.writeln('Usage: claude-flow memory <subcommand> [options]');
|
|
2402
|
+
output.writeln();
|
|
2403
|
+
output.writeln('Subcommands:');
|
|
2404
|
+
output.printList([
|
|
2405
|
+
`${output.highlight('init')} - Initialize memory database (sql.js)`,
|
|
2406
|
+
`${output.highlight('store')} - Store data in memory`,
|
|
2407
|
+
`${output.highlight('retrieve')} - Retrieve data from memory`,
|
|
2408
|
+
`${output.highlight('search')} - Semantic/vector search`,
|
|
2409
|
+
`${output.highlight('list')} - List memory entries`,
|
|
2410
|
+
`${output.highlight('delete')} - Delete memory entry`,
|
|
2411
|
+
`${output.highlight('stats')} - Show statistics`,
|
|
2412
|
+
`${output.highlight('configure')} - Configure backend`,
|
|
2413
|
+
`${output.highlight('cleanup')} - Clean expired entries`,
|
|
2414
|
+
`${output.highlight('compress')} - Compress database`,
|
|
2415
|
+
`${output.highlight('export')} - Export memory to file`,
|
|
2416
|
+
`${output.highlight('import')} - Import from file`,
|
|
2417
|
+
`${output.highlight('index-guidance')} - Index .claude/guidance/ files with RAG segments`,
|
|
2418
|
+
`${output.highlight('rebuild-index')} - Regenerate embeddings for memory entries`,
|
|
2419
|
+
`${output.highlight('code-map')} - Generate structural code map`
|
|
2420
|
+
]);
|
|
2421
|
+
return { success: true };
|
|
2422
|
+
}
|
|
2423
|
+
};
|
|
2424
|
+
export default memoryCommand;
|
|
2425
|
+
//# sourceMappingURL=memory.js.map
|