@cloudpftc/opencode-orchestrator 3.5.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (715) hide show
  1. package/.opencode/agents/architect.yaml +33 -0
  2. package/.opencode/agents/coder.yaml +45 -0
  3. package/.opencode/agents/coordinator.yaml +38 -0
  4. package/.opencode/agents/performance-engineer.yaml +33 -0
  5. package/.opencode/agents/researcher.yaml +32 -0
  6. package/.opencode/agents/reviewer.yaml +32 -0
  7. package/.opencode/agents/security-architect.yaml +32 -0
  8. package/.opencode/agents/tester.yaml +37 -0
  9. package/.opencode/skills/agent-adaptive-coordinator/SKILL.md +403 -0
  10. package/.opencode/skills/agent-agent/SKILL.md +823 -0
  11. package/.opencode/skills/agent-agentic-payments/SKILL.md +133 -0
  12. package/.opencode/skills/agent-analyze-code-quality/SKILL.md +186 -0
  13. package/.opencode/skills/agent-app-store/SKILL.md +95 -0
  14. package/.opencode/skills/agent-arch-system-design/SKILL.md +162 -0
  15. package/.opencode/skills/agent-architecture/SKILL.md +479 -0
  16. package/.opencode/skills/agent-authentication/SKILL.md +76 -0
  17. package/.opencode/skills/agent-automation-smart-agent/SKILL.md +212 -0
  18. package/.opencode/skills/agent-base-template-generator/SKILL.md +49 -0
  19. package/.opencode/skills/agent-benchmark-suite/SKILL.md +672 -0
  20. package/.opencode/skills/agent-byzantine-coordinator/SKILL.md +70 -0
  21. package/.opencode/skills/agent-challenges/SKILL.md +88 -0
  22. package/.opencode/skills/agent-code-analyzer/SKILL.md +217 -0
  23. package/.opencode/skills/agent-code-goal-planner/SKILL.md +453 -0
  24. package/.opencode/skills/agent-code-review-swarm/SKILL.md +545 -0
  25. package/.opencode/skills/agent-coder/SKILL.md +273 -0
  26. package/.opencode/skills/agent-collective-intelligence-coordinator/SKILL.md +137 -0
  27. package/.opencode/skills/agent-consensus-coordinator/SKILL.md +345 -0
  28. package/.opencode/skills/agent-coordination/SKILL.md +82 -0
  29. package/.opencode/skills/agent-coordinator-swarm-init/SKILL.md +112 -0
  30. package/.opencode/skills/agent-crdt-synchronizer/SKILL.md +1004 -0
  31. package/.opencode/skills/agent-data-ml-model/SKILL.md +200 -0
  32. package/.opencode/skills/agent-dev-backend-api/SKILL.md +352 -0
  33. package/.opencode/skills/agent-docs-api-openapi/SKILL.md +181 -0
  34. package/.opencode/skills/agent-github-modes/SKILL.md +180 -0
  35. package/.opencode/skills/agent-github-pr-manager/SKILL.md +184 -0
  36. package/.opencode/skills/agent-goal-planner/SKILL.md +80 -0
  37. package/.opencode/skills/agent-gossip-coordinator/SKILL.md +70 -0
  38. package/.opencode/skills/agent-hierarchical-coordinator/SKILL.md +334 -0
  39. package/.opencode/skills/agent-implementer-sparc-coder/SKILL.md +266 -0
  40. package/.opencode/skills/agent-issue-tracker/SKILL.md +326 -0
  41. package/.opencode/skills/agent-load-balancer/SKILL.md +438 -0
  42. package/.opencode/skills/agent-matrix-optimizer/SKILL.md +192 -0
  43. package/.opencode/skills/agent-memory-coordinator/SKILL.md +194 -0
  44. package/.opencode/skills/agent-mesh-coordinator/SKILL.md +399 -0
  45. package/.opencode/skills/agent-migration-plan/SKILL.md +753 -0
  46. package/.opencode/skills/agent-multi-repo-swarm/SKILL.md +560 -0
  47. package/.opencode/skills/agent-neural-network/SKILL.md +95 -0
  48. package/.opencode/skills/agent-ops-cicd-github/SKILL.md +171 -0
  49. package/.opencode/skills/agent-orchestrator-task/SKILL.md +146 -0
  50. package/.opencode/skills/agent-pagerank-analyzer/SKILL.md +306 -0
  51. package/.opencode/skills/agent-payments/SKILL.md +90 -0
  52. package/.opencode/skills/agent-performance-analyzer/SKILL.md +206 -0
  53. package/.opencode/skills/agent-performance-benchmarker/SKILL.md +858 -0
  54. package/.opencode/skills/agent-performance-monitor/SKILL.md +679 -0
  55. package/.opencode/skills/agent-performance-optimizer/SKILL.md +375 -0
  56. package/.opencode/skills/agent-planner/SKILL.md +175 -0
  57. package/.opencode/skills/agent-pr-manager/SKILL.md +198 -0
  58. package/.opencode/skills/agent-production-validator/SKILL.md +402 -0
  59. package/.opencode/skills/agent-project-board-sync/SKILL.md +516 -0
  60. package/.opencode/skills/agent-pseudocode/SKILL.md +325 -0
  61. package/.opencode/skills/agent-queen-coordinator/SKILL.md +210 -0
  62. package/.opencode/skills/agent-quorum-manager/SKILL.md +830 -0
  63. package/.opencode/skills/agent-raft-manager/SKILL.md +70 -0
  64. package/.opencode/skills/agent-refinement/SKILL.md +532 -0
  65. package/.opencode/skills/agent-release-manager/SKILL.md +374 -0
  66. package/.opencode/skills/agent-release-swarm/SKILL.md +590 -0
  67. package/.opencode/skills/agent-repo-architect/SKILL.md +405 -0
  68. package/.opencode/skills/agent-researcher/SKILL.md +197 -0
  69. package/.opencode/skills/agent-resource-allocator/SKILL.md +681 -0
  70. package/.opencode/skills/agent-reviewer/SKILL.md +333 -0
  71. package/.opencode/skills/agent-safla-neural/SKILL.md +81 -0
  72. package/.opencode/skills/agent-sandbox/SKILL.md +83 -0
  73. package/.opencode/skills/agent-scout-explorer/SKILL.md +249 -0
  74. package/.opencode/skills/agent-security-manager/SKILL.md +629 -0
  75. package/.opencode/skills/agent-sona-learning-optimizer/SKILL.md +81 -0
  76. package/.opencode/skills/agent-sparc-coordinator/SKILL.md +190 -0
  77. package/.opencode/skills/agent-spec-mobile-react-native/SKILL.md +232 -0
  78. package/.opencode/skills/agent-specification/SKILL.md +283 -0
  79. package/.opencode/skills/agent-swarm/SKILL.md +83 -0
  80. package/.opencode/skills/agent-swarm-issue/SKILL.md +580 -0
  81. package/.opencode/skills/agent-swarm-memory-manager/SKILL.md +200 -0
  82. package/.opencode/skills/agent-swarm-pr/SKILL.md +435 -0
  83. package/.opencode/skills/agent-sync-coordinator/SKILL.md +459 -0
  84. package/.opencode/skills/agent-tdd-london-swarm/SKILL.md +251 -0
  85. package/.opencode/skills/agent-test-long-runner/SKILL.md +51 -0
  86. package/.opencode/skills/agent-tester/SKILL.md +326 -0
  87. package/.opencode/skills/agent-topology-optimizer/SKILL.md +815 -0
  88. package/.opencode/skills/agent-trading-predictor/SKILL.md +253 -0
  89. package/.opencode/skills/agent-user-tools/SKILL.md +103 -0
  90. package/.opencode/skills/agent-v3-integration-architect/SKILL.md +353 -0
  91. package/.opencode/skills/agent-v3-memory-specialist/SKILL.md +325 -0
  92. package/.opencode/skills/agent-v3-performance-engineer/SKILL.md +404 -0
  93. package/.opencode/skills/agent-v3-queen-coordinator/SKILL.md +105 -0
  94. package/.opencode/skills/agent-v3-security-architect/SKILL.md +181 -0
  95. package/.opencode/skills/agent-worker-specialist/SKILL.md +224 -0
  96. package/.opencode/skills/agent-workflow/SKILL.md +91 -0
  97. package/.opencode/skills/agent-workflow-automation/SKILL.md +642 -0
  98. package/.opencode/skills/agentdb-advanced/SKILL.md +552 -0
  99. package/.opencode/skills/agentdb-learning/SKILL.md +547 -0
  100. package/.opencode/skills/agentdb-memory-patterns/SKILL.md +341 -0
  101. package/.opencode/skills/agentdb-optimization/SKILL.md +511 -0
  102. package/.opencode/skills/agentdb-vector-search/SKILL.md +341 -0
  103. package/.opencode/skills/agentic-jujutsu/SKILL.md +647 -0
  104. package/.opencode/skills/claims/SKILL.md +72 -0
  105. package/.opencode/skills/embeddings/SKILL.md +71 -0
  106. package/.opencode/skills/flow-nexus-neural/SKILL.md +740 -0
  107. package/.opencode/skills/flow-nexus-platform/SKILL.md +1159 -0
  108. package/.opencode/skills/flow-nexus-swarm/SKILL.md +612 -0
  109. package/.opencode/skills/github-automation/SKILL.md +65 -0
  110. package/.opencode/skills/github-code-review/SKILL.md +1142 -0
  111. package/.opencode/skills/github-multi-repo/SKILL.md +876 -0
  112. package/.opencode/skills/github-project-management/SKILL.md +1279 -0
  113. package/.opencode/skills/github-release-management/SKILL.md +1083 -0
  114. package/.opencode/skills/github-workflow-automation/SKILL.md +1067 -0
  115. package/.opencode/skills/hive-mind/SKILL.md +67 -0
  116. package/.opencode/skills/hive-mind-advanced/SKILL.md +714 -0
  117. package/.opencode/skills/hooks-automation/SKILL.md +1203 -0
  118. package/.opencode/skills/memory-management/SKILL.md +128 -0
  119. package/.opencode/skills/neural-training/SKILL.md +70 -0
  120. package/.opencode/skills/pair-programming/SKILL.md +1204 -0
  121. package/.opencode/skills/performance-analysis/SKILL.md +565 -0
  122. package/.opencode/skills/reasoningbank-agentdb/SKILL.md +448 -0
  123. package/.opencode/skills/reasoningbank-intelligence/SKILL.md +203 -0
  124. package/.opencode/skills/security-audit/SKILL.md +137 -0
  125. package/.opencode/skills/skill-builder/SKILL.md +912 -0
  126. package/.opencode/skills/sparc-methodology/SKILL.md +120 -0
  127. package/.opencode/skills/stream-chain/SKILL.md +565 -0
  128. package/.opencode/skills/swarm-advanced/SKILL.md +975 -0
  129. package/.opencode/skills/swarm-orchestration/SKILL.md +116 -0
  130. package/.opencode/skills/v3-cli-modernization/SKILL.md +874 -0
  131. package/.opencode/skills/v3-core-implementation/SKILL.md +799 -0
  132. package/.opencode/skills/v3-ddd-architecture/SKILL.md +444 -0
  133. package/.opencode/skills/v3-integration-deep/SKILL.md +243 -0
  134. package/.opencode/skills/v3-mcp-optimization/SKILL.md +779 -0
  135. package/.opencode/skills/v3-memory-unification/SKILL.md +176 -0
  136. package/.opencode/skills/v3-performance-optimization/SKILL.md +392 -0
  137. package/.opencode/skills/v3-security-overhaul/SKILL.md +84 -0
  138. package/.opencode/skills/v3-swarm-coordination/SKILL.md +342 -0
  139. package/.opencode/skills/verification-quality/SKILL.md +651 -0
  140. package/.opencode/skills/worker-benchmarks/SKILL.md +137 -0
  141. package/.opencode/skills/worker-integration/SKILL.md +156 -0
  142. package/.opencode/skills/workflow-automation/SKILL.md +80 -0
  143. package/LICENSE +21 -0
  144. package/README.md +7393 -0
  145. package/bin/cli.js +11 -0
  146. package/bin/npx-repair.js +7 -0
  147. package/bin/npx-safe-launch.js +9 -0
  148. package/opencode.json +84 -0
  149. package/package.json +131 -0
  150. package/v3/@claude-flow/cli/README.md +7536 -0
  151. package/v3/@claude-flow/cli/bin/cli.js +156 -0
  152. package/v3/@claude-flow/cli/bin/mcp-server.js +189 -0
  153. package/v3/@claude-flow/cli/bin/preinstall.cjs +2 -0
  154. package/v3/@claude-flow/cli/dist/src/appliance/gguf-engine.d.ts +91 -0
  155. package/v3/@claude-flow/cli/dist/src/appliance/gguf-engine.js +425 -0
  156. package/v3/@claude-flow/cli/dist/src/appliance/ruvllm-bridge.d.ts +102 -0
  157. package/v3/@claude-flow/cli/dist/src/appliance/ruvllm-bridge.js +292 -0
  158. package/v3/@claude-flow/cli/dist/src/appliance/rvfa-builder.d.ts +44 -0
  159. package/v3/@claude-flow/cli/dist/src/appliance/rvfa-builder.js +328 -0
  160. package/v3/@claude-flow/cli/dist/src/appliance/rvfa-distribution.d.ts +97 -0
  161. package/v3/@claude-flow/cli/dist/src/appliance/rvfa-distribution.js +370 -0
  162. package/v3/@claude-flow/cli/dist/src/appliance/rvfa-format.d.ts +111 -0
  163. package/v3/@claude-flow/cli/dist/src/appliance/rvfa-format.js +393 -0
  164. package/v3/@claude-flow/cli/dist/src/appliance/rvfa-runner.d.ts +69 -0
  165. package/v3/@claude-flow/cli/dist/src/appliance/rvfa-runner.js +237 -0
  166. package/v3/@claude-flow/cli/dist/src/appliance/rvfa-signing.d.ts +123 -0
  167. package/v3/@claude-flow/cli/dist/src/appliance/rvfa-signing.js +347 -0
  168. package/v3/@claude-flow/cli/dist/src/benchmarks/pretrain/index.d.ts +58 -0
  169. package/v3/@claude-flow/cli/dist/src/benchmarks/pretrain/index.js +404 -0
  170. package/v3/@claude-flow/cli/dist/src/commands/agent.d.ts +8 -0
  171. package/v3/@claude-flow/cli/dist/src/commands/agent.js +819 -0
  172. package/v3/@claude-flow/cli/dist/src/commands/analyze.d.ts +19 -0
  173. package/v3/@claude-flow/cli/dist/src/commands/analyze.js +1823 -0
  174. package/v3/@claude-flow/cli/dist/src/commands/appliance-advanced.d.ts +9 -0
  175. package/v3/@claude-flow/cli/dist/src/commands/appliance-advanced.js +215 -0
  176. package/v3/@claude-flow/cli/dist/src/commands/appliance.d.ts +8 -0
  177. package/v3/@claude-flow/cli/dist/src/commands/appliance.js +406 -0
  178. package/v3/@claude-flow/cli/dist/src/commands/benchmark.d.ts +10 -0
  179. package/v3/@claude-flow/cli/dist/src/commands/benchmark.js +459 -0
  180. package/v3/@claude-flow/cli/dist/src/commands/claims.d.ts +10 -0
  181. package/v3/@claude-flow/cli/dist/src/commands/claims.js +373 -0
  182. package/v3/@claude-flow/cli/dist/src/commands/completions.d.ts +10 -0
  183. package/v3/@claude-flow/cli/dist/src/commands/completions.js +539 -0
  184. package/v3/@claude-flow/cli/dist/src/commands/config.d.ts +8 -0
  185. package/v3/@claude-flow/cli/dist/src/commands/config.js +406 -0
  186. package/v3/@claude-flow/cli/dist/src/commands/daemon.d.ts +8 -0
  187. package/v3/@claude-flow/cli/dist/src/commands/daemon.js +609 -0
  188. package/v3/@claude-flow/cli/dist/src/commands/deployment.d.ts +10 -0
  189. package/v3/@claude-flow/cli/dist/src/commands/deployment.js +289 -0
  190. package/v3/@claude-flow/cli/dist/src/commands/doctor.d.ts +10 -0
  191. package/v3/@claude-flow/cli/dist/src/commands/doctor.js +548 -0
  192. package/v3/@claude-flow/cli/dist/src/commands/embeddings.d.ts +18 -0
  193. package/v3/@claude-flow/cli/dist/src/commands/embeddings.js +1576 -0
  194. package/v3/@claude-flow/cli/dist/src/commands/guidance.d.ts +8 -0
  195. package/v3/@claude-flow/cli/dist/src/commands/guidance.js +560 -0
  196. package/v3/@claude-flow/cli/dist/src/commands/hive-mind.d.ts +11 -0
  197. package/v3/@claude-flow/cli/dist/src/commands/hive-mind.js +1145 -0
  198. package/v3/@claude-flow/cli/dist/src/commands/hooks.d.ts +8 -0
  199. package/v3/@claude-flow/cli/dist/src/commands/hooks.js +3759 -0
  200. package/v3/@claude-flow/cli/dist/src/commands/index.d.ts +113 -0
  201. package/v3/@claude-flow/cli/dist/src/commands/index.js +368 -0
  202. package/v3/@claude-flow/cli/dist/src/commands/init.d.ts +8 -0
  203. package/v3/@claude-flow/cli/dist/src/commands/init.js +822 -0
  204. package/v3/@claude-flow/cli/dist/src/commands/issues.d.ts +21 -0
  205. package/v3/@claude-flow/cli/dist/src/commands/issues.js +567 -0
  206. package/v3/@claude-flow/cli/dist/src/commands/mcp.d.ts +11 -0
  207. package/v3/@claude-flow/cli/dist/src/commands/mcp.js +715 -0
  208. package/v3/@claude-flow/cli/dist/src/commands/memory.d.ts +8 -0
  209. package/v3/@claude-flow/cli/dist/src/commands/memory.js +1292 -0
  210. package/v3/@claude-flow/cli/dist/src/commands/migrate.d.ts +8 -0
  211. package/v3/@claude-flow/cli/dist/src/commands/migrate.js +410 -0
  212. package/v3/@claude-flow/cli/dist/src/commands/neural.d.ts +10 -0
  213. package/v3/@claude-flow/cli/dist/src/commands/neural.js +1448 -0
  214. package/v3/@claude-flow/cli/dist/src/commands/performance.d.ts +10 -0
  215. package/v3/@claude-flow/cli/dist/src/commands/performance.js +579 -0
  216. package/v3/@claude-flow/cli/dist/src/commands/plugins.d.ts +11 -0
  217. package/v3/@claude-flow/cli/dist/src/commands/plugins.js +820 -0
  218. package/v3/@claude-flow/cli/dist/src/commands/process.d.ts +10 -0
  219. package/v3/@claude-flow/cli/dist/src/commands/process.js +641 -0
  220. package/v3/@claude-flow/cli/dist/src/commands/progress.d.ts +11 -0
  221. package/v3/@claude-flow/cli/dist/src/commands/progress.js +259 -0
  222. package/v3/@claude-flow/cli/dist/src/commands/providers.d.ts +10 -0
  223. package/v3/@claude-flow/cli/dist/src/commands/providers.js +232 -0
  224. package/v3/@claude-flow/cli/dist/src/commands/route.d.ts +16 -0
  225. package/v3/@claude-flow/cli/dist/src/commands/route.js +813 -0
  226. package/v3/@claude-flow/cli/dist/src/commands/ruvector/backup.d.ts +11 -0
  227. package/v3/@claude-flow/cli/dist/src/commands/ruvector/backup.js +746 -0
  228. package/v3/@claude-flow/cli/dist/src/commands/ruvector/benchmark.d.ts +11 -0
  229. package/v3/@claude-flow/cli/dist/src/commands/ruvector/benchmark.js +480 -0
  230. package/v3/@claude-flow/cli/dist/src/commands/ruvector/import.d.ts +18 -0
  231. package/v3/@claude-flow/cli/dist/src/commands/ruvector/import.js +349 -0
  232. package/v3/@claude-flow/cli/dist/src/commands/ruvector/index.d.ts +29 -0
  233. package/v3/@claude-flow/cli/dist/src/commands/ruvector/index.js +129 -0
  234. package/v3/@claude-flow/cli/dist/src/commands/ruvector/init.d.ts +11 -0
  235. package/v3/@claude-flow/cli/dist/src/commands/ruvector/init.js +431 -0
  236. package/v3/@claude-flow/cli/dist/src/commands/ruvector/migrate.d.ts +11 -0
  237. package/v3/@claude-flow/cli/dist/src/commands/ruvector/migrate.js +481 -0
  238. package/v3/@claude-flow/cli/dist/src/commands/ruvector/optimize.d.ts +11 -0
  239. package/v3/@claude-flow/cli/dist/src/commands/ruvector/optimize.js +503 -0
  240. package/v3/@claude-flow/cli/dist/src/commands/ruvector/setup.d.ts +18 -0
  241. package/v3/@claude-flow/cli/dist/src/commands/ruvector/setup.js +765 -0
  242. package/v3/@claude-flow/cli/dist/src/commands/ruvector/status.d.ts +11 -0
  243. package/v3/@claude-flow/cli/dist/src/commands/ruvector/status.js +456 -0
  244. package/v3/@claude-flow/cli/dist/src/commands/security.d.ts +10 -0
  245. package/v3/@claude-flow/cli/dist/src/commands/security.js +575 -0
  246. package/v3/@claude-flow/cli/dist/src/commands/session.d.ts +8 -0
  247. package/v3/@claude-flow/cli/dist/src/commands/session.js +750 -0
  248. package/v3/@claude-flow/cli/dist/src/commands/start.d.ts +8 -0
  249. package/v3/@claude-flow/cli/dist/src/commands/start.js +418 -0
  250. package/v3/@claude-flow/cli/dist/src/commands/status.d.ts +8 -0
  251. package/v3/@claude-flow/cli/dist/src/commands/status.js +591 -0
  252. package/v3/@claude-flow/cli/dist/src/commands/swarm.d.ts +8 -0
  253. package/v3/@claude-flow/cli/dist/src/commands/swarm.js +748 -0
  254. package/v3/@claude-flow/cli/dist/src/commands/task.d.ts +8 -0
  255. package/v3/@claude-flow/cli/dist/src/commands/task.js +671 -0
  256. package/v3/@claude-flow/cli/dist/src/commands/transfer-store.d.ts +13 -0
  257. package/v3/@claude-flow/cli/dist/src/commands/transfer-store.js +428 -0
  258. package/v3/@claude-flow/cli/dist/src/commands/update.d.ts +8 -0
  259. package/v3/@claude-flow/cli/dist/src/commands/update.js +276 -0
  260. package/v3/@claude-flow/cli/dist/src/commands/workflow.d.ts +8 -0
  261. package/v3/@claude-flow/cli/dist/src/commands/workflow.js +617 -0
  262. package/v3/@claude-flow/cli/dist/src/config-adapter.d.ts +15 -0
  263. package/v3/@claude-flow/cli/dist/src/config-adapter.js +186 -0
  264. package/v3/@claude-flow/cli/dist/src/index.d.ts +76 -0
  265. package/v3/@claude-flow/cli/dist/src/index.js +470 -0
  266. package/v3/@claude-flow/cli/dist/src/infrastructure/in-memory-repositories.d.ts +68 -0
  267. package/v3/@claude-flow/cli/dist/src/infrastructure/in-memory-repositories.js +264 -0
  268. package/v3/@claude-flow/cli/dist/src/init/claudemd-generator.d.ts +25 -0
  269. package/v3/@claude-flow/cli/dist/src/init/claudemd-generator.js +486 -0
  270. package/v3/@claude-flow/cli/dist/src/init/executor.d.ts +41 -0
  271. package/v3/@claude-flow/cli/dist/src/init/executor.js +1734 -0
  272. package/v3/@claude-flow/cli/dist/src/init/helpers-generator.d.ts +60 -0
  273. package/v3/@claude-flow/cli/dist/src/init/helpers-generator.js +1166 -0
  274. package/v3/@claude-flow/cli/dist/src/init/index.d.ts +13 -0
  275. package/v3/@claude-flow/cli/dist/src/init/index.js +15 -0
  276. package/v3/@claude-flow/cli/dist/src/init/mcp-generator.d.ts +31 -0
  277. package/v3/@claude-flow/cli/dist/src/init/mcp-generator.js +147 -0
  278. package/v3/@claude-flow/cli/dist/src/init/settings-generator.d.ts +14 -0
  279. package/v3/@claude-flow/cli/dist/src/init/settings-generator.js +399 -0
  280. package/v3/@claude-flow/cli/dist/src/init/statusline-generator.d.ts +28 -0
  281. package/v3/@claude-flow/cli/dist/src/init/statusline-generator.js +817 -0
  282. package/v3/@claude-flow/cli/dist/src/init/types.d.ts +283 -0
  283. package/v3/@claude-flow/cli/dist/src/init/types.js +254 -0
  284. package/v3/@claude-flow/cli/dist/src/mcp-client.d.ts +92 -0
  285. package/v3/@claude-flow/cli/dist/src/mcp-client.js +237 -0
  286. package/v3/@claude-flow/cli/dist/src/mcp-server.d.ts +161 -0
  287. package/v3/@claude-flow/cli/dist/src/mcp-server.js +627 -0
  288. package/v3/@claude-flow/cli/dist/src/mcp-tools/agent-tools.d.ts +9 -0
  289. package/v3/@claude-flow/cli/dist/src/mcp-tools/agent-tools.js +549 -0
  290. package/v3/@claude-flow/cli/dist/src/mcp-tools/agentdb-tools.d.ts +30 -0
  291. package/v3/@claude-flow/cli/dist/src/mcp-tools/agentdb-tools.js +557 -0
  292. package/v3/@claude-flow/cli/dist/src/mcp-tools/analyze-tools.d.ts +38 -0
  293. package/v3/@claude-flow/cli/dist/src/mcp-tools/analyze-tools.js +317 -0
  294. package/v3/@claude-flow/cli/dist/src/mcp-tools/auto-install.d.ts +83 -0
  295. package/v3/@claude-flow/cli/dist/src/mcp-tools/auto-install.js +131 -0
  296. package/v3/@claude-flow/cli/dist/src/mcp-tools/browser-tools.d.ts +13 -0
  297. package/v3/@claude-flow/cli/dist/src/mcp-tools/browser-tools.js +550 -0
  298. package/v3/@claude-flow/cli/dist/src/mcp-tools/claims-tools.d.ts +12 -0
  299. package/v3/@claude-flow/cli/dist/src/mcp-tools/claims-tools.js +732 -0
  300. package/v3/@claude-flow/cli/dist/src/mcp-tools/config-tools.d.ts +8 -0
  301. package/v3/@claude-flow/cli/dist/src/mcp-tools/config-tools.js +343 -0
  302. package/v3/@claude-flow/cli/dist/src/mcp-tools/coordination-tools.d.ts +13 -0
  303. package/v3/@claude-flow/cli/dist/src/mcp-tools/coordination-tools.js +486 -0
  304. package/v3/@claude-flow/cli/dist/src/mcp-tools/daa-tools.d.ts +13 -0
  305. package/v3/@claude-flow/cli/dist/src/mcp-tools/daa-tools.js +426 -0
  306. package/v3/@claude-flow/cli/dist/src/mcp-tools/embeddings-tools.d.ts +9 -0
  307. package/v3/@claude-flow/cli/dist/src/mcp-tools/embeddings-tools.js +782 -0
  308. package/v3/@claude-flow/cli/dist/src/mcp-tools/github-tools.d.ts +13 -0
  309. package/v3/@claude-flow/cli/dist/src/mcp-tools/github-tools.js +373 -0
  310. package/v3/@claude-flow/cli/dist/src/mcp-tools/hive-mind-tools.d.ts +8 -0
  311. package/v3/@claude-flow/cli/dist/src/mcp-tools/hive-mind-tools.js +583 -0
  312. package/v3/@claude-flow/cli/dist/src/mcp-tools/hooks-tools.d.ts +44 -0
  313. package/v3/@claude-flow/cli/dist/src/mcp-tools/hooks-tools.js +2969 -0
  314. package/v3/@claude-flow/cli/dist/src/mcp-tools/index.d.ts +23 -0
  315. package/v3/@claude-flow/cli/dist/src/mcp-tools/index.js +22 -0
  316. package/v3/@claude-flow/cli/dist/src/mcp-tools/memory-tools.d.ts +14 -0
  317. package/v3/@claude-flow/cli/dist/src/mcp-tools/memory-tools.js +499 -0
  318. package/v3/@claude-flow/cli/dist/src/mcp-tools/neural-tools.d.ts +16 -0
  319. package/v3/@claude-flow/cli/dist/src/mcp-tools/neural-tools.js +461 -0
  320. package/v3/@claude-flow/cli/dist/src/mcp-tools/performance-tools.d.ts +16 -0
  321. package/v3/@claude-flow/cli/dist/src/mcp-tools/performance-tools.js +534 -0
  322. package/v3/@claude-flow/cli/dist/src/mcp-tools/progress-tools.d.ts +14 -0
  323. package/v3/@claude-flow/cli/dist/src/mcp-tools/progress-tools.js +348 -0
  324. package/v3/@claude-flow/cli/dist/src/mcp-tools/security-tools.d.ts +18 -0
  325. package/v3/@claude-flow/cli/dist/src/mcp-tools/security-tools.js +434 -0
  326. package/v3/@claude-flow/cli/dist/src/mcp-tools/session-tools.d.ts +8 -0
  327. package/v3/@claude-flow/cli/dist/src/mcp-tools/session-tools.js +315 -0
  328. package/v3/@claude-flow/cli/dist/src/mcp-tools/swarm-tools.d.ts +9 -0
  329. package/v3/@claude-flow/cli/dist/src/mcp-tools/swarm-tools.js +197 -0
  330. package/v3/@claude-flow/cli/dist/src/mcp-tools/system-tools.d.ts +13 -0
  331. package/v3/@claude-flow/cli/dist/src/mcp-tools/system-tools.js +417 -0
  332. package/v3/@claude-flow/cli/dist/src/mcp-tools/task-tools.d.ts +8 -0
  333. package/v3/@claude-flow/cli/dist/src/mcp-tools/task-tools.js +338 -0
  334. package/v3/@claude-flow/cli/dist/src/mcp-tools/terminal-tools.d.ts +13 -0
  335. package/v3/@claude-flow/cli/dist/src/mcp-tools/terminal-tools.js +246 -0
  336. package/v3/@claude-flow/cli/dist/src/mcp-tools/transfer-tools.d.ts +14 -0
  337. package/v3/@claude-flow/cli/dist/src/mcp-tools/transfer-tools.js +396 -0
  338. package/v3/@claude-flow/cli/dist/src/mcp-tools/types.d.ts +31 -0
  339. package/v3/@claude-flow/cli/dist/src/mcp-tools/types.js +7 -0
  340. package/v3/@claude-flow/cli/dist/src/mcp-tools/workflow-tools.d.ts +8 -0
  341. package/v3/@claude-flow/cli/dist/src/mcp-tools/workflow-tools.js +572 -0
  342. package/v3/@claude-flow/cli/dist/src/memory/ewc-consolidation.d.ts +271 -0
  343. package/v3/@claude-flow/cli/dist/src/memory/ewc-consolidation.js +542 -0
  344. package/v3/@claude-flow/cli/dist/src/memory/intelligence.d.ts +285 -0
  345. package/v3/@claude-flow/cli/dist/src/memory/intelligence.js +794 -0
  346. package/v3/@claude-flow/cli/dist/src/memory/memory-bridge.d.ts +407 -0
  347. package/v3/@claude-flow/cli/dist/src/memory/memory-bridge.js +1494 -0
  348. package/v3/@claude-flow/cli/dist/src/memory/memory-initializer.d.ts +405 -0
  349. package/v3/@claude-flow/cli/dist/src/memory/memory-initializer.js +2105 -0
  350. package/v3/@claude-flow/cli/dist/src/memory/sona-optimizer.d.ts +227 -0
  351. package/v3/@claude-flow/cli/dist/src/memory/sona-optimizer.js +633 -0
  352. package/v3/@claude-flow/cli/dist/src/output.d.ts +133 -0
  353. package/v3/@claude-flow/cli/dist/src/output.js +514 -0
  354. package/v3/@claude-flow/cli/dist/src/parser.d.ts +41 -0
  355. package/v3/@claude-flow/cli/dist/src/parser.js +377 -0
  356. package/v3/@claude-flow/cli/dist/src/plugins/manager.d.ts +133 -0
  357. package/v3/@claude-flow/cli/dist/src/plugins/manager.js +400 -0
  358. package/v3/@claude-flow/cli/dist/src/plugins/store/discovery.d.ts +88 -0
  359. package/v3/@claude-flow/cli/dist/src/plugins/store/discovery.js +1147 -0
  360. package/v3/@claude-flow/cli/dist/src/plugins/store/index.d.ts +76 -0
  361. package/v3/@claude-flow/cli/dist/src/plugins/store/index.js +141 -0
  362. package/v3/@claude-flow/cli/dist/src/plugins/store/search.d.ts +46 -0
  363. package/v3/@claude-flow/cli/dist/src/plugins/store/search.js +230 -0
  364. package/v3/@claude-flow/cli/dist/src/plugins/store/types.d.ts +274 -0
  365. package/v3/@claude-flow/cli/dist/src/plugins/store/types.js +7 -0
  366. package/v3/@claude-flow/cli/dist/src/plugins/tests/demo-plugin-store.d.ts +7 -0
  367. package/v3/@claude-flow/cli/dist/src/plugins/tests/demo-plugin-store.js +126 -0
  368. package/v3/@claude-flow/cli/dist/src/plugins/tests/standalone-test.d.ts +12 -0
  369. package/v3/@claude-flow/cli/dist/src/plugins/tests/standalone-test.js +188 -0
  370. package/v3/@claude-flow/cli/dist/src/plugins/tests/test-plugin-store.d.ts +7 -0
  371. package/v3/@claude-flow/cli/dist/src/plugins/tests/test-plugin-store.js +206 -0
  372. package/v3/@claude-flow/cli/dist/src/production/circuit-breaker.d.ts +101 -0
  373. package/v3/@claude-flow/cli/dist/src/production/circuit-breaker.js +241 -0
  374. package/v3/@claude-flow/cli/dist/src/production/error-handler.d.ts +92 -0
  375. package/v3/@claude-flow/cli/dist/src/production/error-handler.js +299 -0
  376. package/v3/@claude-flow/cli/dist/src/production/index.d.ts +23 -0
  377. package/v3/@claude-flow/cli/dist/src/production/index.js +18 -0
  378. package/v3/@claude-flow/cli/dist/src/production/monitoring.d.ts +161 -0
  379. package/v3/@claude-flow/cli/dist/src/production/monitoring.js +356 -0
  380. package/v3/@claude-flow/cli/dist/src/production/rate-limiter.d.ts +80 -0
  381. package/v3/@claude-flow/cli/dist/src/production/rate-limiter.js +201 -0
  382. package/v3/@claude-flow/cli/dist/src/production/retry.d.ts +48 -0
  383. package/v3/@claude-flow/cli/dist/src/production/retry.js +179 -0
  384. package/v3/@claude-flow/cli/dist/src/prompt.d.ts +44 -0
  385. package/v3/@claude-flow/cli/dist/src/prompt.js +501 -0
  386. package/v3/@claude-flow/cli/dist/src/runtime/headless.d.ts +60 -0
  387. package/v3/@claude-flow/cli/dist/src/runtime/headless.js +284 -0
  388. package/v3/@claude-flow/cli/dist/src/ruvector/ast-analyzer.d.ts +67 -0
  389. package/v3/@claude-flow/cli/dist/src/ruvector/ast-analyzer.js +277 -0
  390. package/v3/@claude-flow/cli/dist/src/ruvector/coverage-router.d.ts +160 -0
  391. package/v3/@claude-flow/cli/dist/src/ruvector/coverage-router.js +529 -0
  392. package/v3/@claude-flow/cli/dist/src/ruvector/coverage-tools.d.ts +33 -0
  393. package/v3/@claude-flow/cli/dist/src/ruvector/coverage-tools.js +157 -0
  394. package/v3/@claude-flow/cli/dist/src/ruvector/diff-classifier.d.ts +175 -0
  395. package/v3/@claude-flow/cli/dist/src/ruvector/diff-classifier.js +698 -0
  396. package/v3/@claude-flow/cli/dist/src/ruvector/enhanced-model-router.d.ts +146 -0
  397. package/v3/@claude-flow/cli/dist/src/ruvector/enhanced-model-router.js +529 -0
  398. package/v3/@claude-flow/cli/dist/src/ruvector/flash-attention.d.ts +195 -0
  399. package/v3/@claude-flow/cli/dist/src/ruvector/flash-attention.js +643 -0
  400. package/v3/@claude-flow/cli/dist/src/ruvector/graph-analyzer.d.ts +187 -0
  401. package/v3/@claude-flow/cli/dist/src/ruvector/graph-analyzer.js +929 -0
  402. package/v3/@claude-flow/cli/dist/src/ruvector/index.d.ts +34 -0
  403. package/v3/@claude-flow/cli/dist/src/ruvector/index.js +60 -0
  404. package/v3/@claude-flow/cli/dist/src/ruvector/lora-adapter.d.ts +218 -0
  405. package/v3/@claude-flow/cli/dist/src/ruvector/lora-adapter.js +455 -0
  406. package/v3/@claude-flow/cli/dist/src/ruvector/model-router.d.ts +220 -0
  407. package/v3/@claude-flow/cli/dist/src/ruvector/model-router.js +488 -0
  408. package/v3/@claude-flow/cli/dist/src/ruvector/moe-router.d.ts +206 -0
  409. package/v3/@claude-flow/cli/dist/src/ruvector/moe-router.js +626 -0
  410. package/v3/@claude-flow/cli/dist/src/ruvector/q-learning-router.d.ts +211 -0
  411. package/v3/@claude-flow/cli/dist/src/ruvector/q-learning-router.js +681 -0
  412. package/v3/@claude-flow/cli/dist/src/ruvector/semantic-router.d.ts +77 -0
  413. package/v3/@claude-flow/cli/dist/src/ruvector/semantic-router.js +178 -0
  414. package/v3/@claude-flow/cli/dist/src/ruvector/vector-db.d.ts +69 -0
  415. package/v3/@claude-flow/cli/dist/src/ruvector/vector-db.js +243 -0
  416. package/v3/@claude-flow/cli/dist/src/services/agentic-flow-bridge.d.ts +50 -0
  417. package/v3/@claude-flow/cli/dist/src/services/agentic-flow-bridge.js +95 -0
  418. package/v3/@claude-flow/cli/dist/src/services/claim-service.d.ts +204 -0
  419. package/v3/@claude-flow/cli/dist/src/services/claim-service.js +818 -0
  420. package/v3/@claude-flow/cli/dist/src/services/container-worker-pool.d.ts +197 -0
  421. package/v3/@claude-flow/cli/dist/src/services/container-worker-pool.js +583 -0
  422. package/v3/@claude-flow/cli/dist/src/services/headless-worker-executor.d.ts +302 -0
  423. package/v3/@claude-flow/cli/dist/src/services/headless-worker-executor.js +971 -0
  424. package/v3/@claude-flow/cli/dist/src/services/index.d.ts +13 -0
  425. package/v3/@claude-flow/cli/dist/src/services/index.js +11 -0
  426. package/v3/@claude-flow/cli/dist/src/services/registry-api.d.ts +58 -0
  427. package/v3/@claude-flow/cli/dist/src/services/registry-api.js +146 -0
  428. package/v3/@claude-flow/cli/dist/src/services/ruvector-training.d.ts +214 -0
  429. package/v3/@claude-flow/cli/dist/src/services/ruvector-training.js +497 -0
  430. package/v3/@claude-flow/cli/dist/src/services/worker-daemon.d.ts +203 -0
  431. package/v3/@claude-flow/cli/dist/src/services/worker-daemon.js +756 -0
  432. package/v3/@claude-flow/cli/dist/src/services/worker-queue.d.ts +194 -0
  433. package/v3/@claude-flow/cli/dist/src/services/worker-queue.js +513 -0
  434. package/v3/@claude-flow/cli/dist/src/suggest.d.ts +53 -0
  435. package/v3/@claude-flow/cli/dist/src/suggest.js +200 -0
  436. package/v3/@claude-flow/cli/dist/src/transfer/anonymization/index.d.ts +25 -0
  437. package/v3/@claude-flow/cli/dist/src/transfer/anonymization/index.js +175 -0
  438. package/v3/@claude-flow/cli/dist/src/transfer/deploy-seraphine.d.ts +13 -0
  439. package/v3/@claude-flow/cli/dist/src/transfer/deploy-seraphine.js +205 -0
  440. package/v3/@claude-flow/cli/dist/src/transfer/export.d.ts +25 -0
  441. package/v3/@claude-flow/cli/dist/src/transfer/export.js +113 -0
  442. package/v3/@claude-flow/cli/dist/src/transfer/index.d.ts +12 -0
  443. package/v3/@claude-flow/cli/dist/src/transfer/index.js +31 -0
  444. package/v3/@claude-flow/cli/dist/src/transfer/ipfs/client.d.ts +109 -0
  445. package/v3/@claude-flow/cli/dist/src/transfer/ipfs/client.js +307 -0
  446. package/v3/@claude-flow/cli/dist/src/transfer/ipfs/upload.d.ts +95 -0
  447. package/v3/@claude-flow/cli/dist/src/transfer/ipfs/upload.js +411 -0
  448. package/v3/@claude-flow/cli/dist/src/transfer/models/seraphine.d.ts +72 -0
  449. package/v3/@claude-flow/cli/dist/src/transfer/models/seraphine.js +373 -0
  450. package/v3/@claude-flow/cli/dist/src/transfer/serialization/cfp.d.ts +49 -0
  451. package/v3/@claude-flow/cli/dist/src/transfer/serialization/cfp.js +183 -0
  452. package/v3/@claude-flow/cli/dist/src/transfer/storage/gcs.d.ts +82 -0
  453. package/v3/@claude-flow/cli/dist/src/transfer/storage/gcs.js +256 -0
  454. package/v3/@claude-flow/cli/dist/src/transfer/storage/index.d.ts +6 -0
  455. package/v3/@claude-flow/cli/dist/src/transfer/storage/index.js +6 -0
  456. package/v3/@claude-flow/cli/dist/src/transfer/store/discovery.d.ts +84 -0
  457. package/v3/@claude-flow/cli/dist/src/transfer/store/discovery.js +382 -0
  458. package/v3/@claude-flow/cli/dist/src/transfer/store/download.d.ts +70 -0
  459. package/v3/@claude-flow/cli/dist/src/transfer/store/download.js +334 -0
  460. package/v3/@claude-flow/cli/dist/src/transfer/store/index.d.ts +84 -0
  461. package/v3/@claude-flow/cli/dist/src/transfer/store/index.js +153 -0
  462. package/v3/@claude-flow/cli/dist/src/transfer/store/publish.d.ts +76 -0
  463. package/v3/@claude-flow/cli/dist/src/transfer/store/publish.js +294 -0
  464. package/v3/@claude-flow/cli/dist/src/transfer/store/registry.d.ts +58 -0
  465. package/v3/@claude-flow/cli/dist/src/transfer/store/registry.js +285 -0
  466. package/v3/@claude-flow/cli/dist/src/transfer/store/search.d.ts +54 -0
  467. package/v3/@claude-flow/cli/dist/src/transfer/store/search.js +232 -0
  468. package/v3/@claude-flow/cli/dist/src/transfer/store/tests/standalone-test.d.ts +12 -0
  469. package/v3/@claude-flow/cli/dist/src/transfer/store/tests/standalone-test.js +190 -0
  470. package/v3/@claude-flow/cli/dist/src/transfer/store/types.d.ts +193 -0
  471. package/v3/@claude-flow/cli/dist/src/transfer/store/types.js +6 -0
  472. package/v3/@claude-flow/cli/dist/src/transfer/test-seraphine.d.ts +6 -0
  473. package/v3/@claude-flow/cli/dist/src/transfer/test-seraphine.js +105 -0
  474. package/v3/@claude-flow/cli/dist/src/transfer/tests/test-store.d.ts +7 -0
  475. package/v3/@claude-flow/cli/dist/src/transfer/tests/test-store.js +214 -0
  476. package/v3/@claude-flow/cli/dist/src/transfer/types.d.ts +245 -0
  477. package/v3/@claude-flow/cli/dist/src/transfer/types.js +6 -0
  478. package/v3/@claude-flow/cli/dist/src/types.d.ts +198 -0
  479. package/v3/@claude-flow/cli/dist/src/types.js +38 -0
  480. package/v3/@claude-flow/cli/dist/src/update/checker.d.ts +34 -0
  481. package/v3/@claude-flow/cli/dist/src/update/checker.js +190 -0
  482. package/v3/@claude-flow/cli/dist/src/update/executor.d.ts +32 -0
  483. package/v3/@claude-flow/cli/dist/src/update/executor.js +181 -0
  484. package/v3/@claude-flow/cli/dist/src/update/index.d.ts +33 -0
  485. package/v3/@claude-flow/cli/dist/src/update/index.js +64 -0
  486. package/v3/@claude-flow/cli/dist/src/update/rate-limiter.d.ts +20 -0
  487. package/v3/@claude-flow/cli/dist/src/update/rate-limiter.js +96 -0
  488. package/v3/@claude-flow/cli/dist/src/update/validator.d.ts +17 -0
  489. package/v3/@claude-flow/cli/dist/src/update/validator.js +123 -0
  490. package/v3/@claude-flow/cli/package.json +108 -0
  491. package/v3/@claude-flow/guidance/README.md +1195 -0
  492. package/v3/@claude-flow/guidance/dist/adversarial.d.ts +284 -0
  493. package/v3/@claude-flow/guidance/dist/adversarial.js +572 -0
  494. package/v3/@claude-flow/guidance/dist/analyzer.d.ts +530 -0
  495. package/v3/@claude-flow/guidance/dist/analyzer.js +2518 -0
  496. package/v3/@claude-flow/guidance/dist/artifacts.d.ts +283 -0
  497. package/v3/@claude-flow/guidance/dist/artifacts.js +356 -0
  498. package/v3/@claude-flow/guidance/dist/authority.d.ts +290 -0
  499. package/v3/@claude-flow/guidance/dist/authority.js +558 -0
  500. package/v3/@claude-flow/guidance/dist/capabilities.d.ts +209 -0
  501. package/v3/@claude-flow/guidance/dist/capabilities.js +485 -0
  502. package/v3/@claude-flow/guidance/dist/coherence.d.ts +233 -0
  503. package/v3/@claude-flow/guidance/dist/coherence.js +372 -0
  504. package/v3/@claude-flow/guidance/dist/compiler.d.ts +87 -0
  505. package/v3/@claude-flow/guidance/dist/compiler.js +419 -0
  506. package/v3/@claude-flow/guidance/dist/conformance-kit.d.ts +225 -0
  507. package/v3/@claude-flow/guidance/dist/conformance-kit.js +629 -0
  508. package/v3/@claude-flow/guidance/dist/continue-gate.d.ts +214 -0
  509. package/v3/@claude-flow/guidance/dist/continue-gate.js +353 -0
  510. package/v3/@claude-flow/guidance/dist/crypto-utils.d.ts +17 -0
  511. package/v3/@claude-flow/guidance/dist/crypto-utils.js +24 -0
  512. package/v3/@claude-flow/guidance/dist/evolution.d.ts +282 -0
  513. package/v3/@claude-flow/guidance/dist/evolution.js +500 -0
  514. package/v3/@claude-flow/guidance/dist/gates.d.ts +79 -0
  515. package/v3/@claude-flow/guidance/dist/gates.js +302 -0
  516. package/v3/@claude-flow/guidance/dist/gateway.d.ts +206 -0
  517. package/v3/@claude-flow/guidance/dist/gateway.js +452 -0
  518. package/v3/@claude-flow/guidance/dist/generators.d.ts +153 -0
  519. package/v3/@claude-flow/guidance/dist/generators.js +682 -0
  520. package/v3/@claude-flow/guidance/dist/headless.d.ts +177 -0
  521. package/v3/@claude-flow/guidance/dist/headless.js +342 -0
  522. package/v3/@claude-flow/guidance/dist/hooks.d.ts +109 -0
  523. package/v3/@claude-flow/guidance/dist/hooks.js +347 -0
  524. package/v3/@claude-flow/guidance/dist/index.d.ts +205 -0
  525. package/v3/@claude-flow/guidance/dist/index.js +321 -0
  526. package/v3/@claude-flow/guidance/dist/ledger.d.ts +162 -0
  527. package/v3/@claude-flow/guidance/dist/ledger.js +375 -0
  528. package/v3/@claude-flow/guidance/dist/manifest-validator.d.ts +289 -0
  529. package/v3/@claude-flow/guidance/dist/manifest-validator.js +838 -0
  530. package/v3/@claude-flow/guidance/dist/memory-gate.d.ts +222 -0
  531. package/v3/@claude-flow/guidance/dist/memory-gate.js +382 -0
  532. package/v3/@claude-flow/guidance/dist/meta-governance.d.ts +265 -0
  533. package/v3/@claude-flow/guidance/dist/meta-governance.js +348 -0
  534. package/v3/@claude-flow/guidance/dist/optimizer.d.ts +104 -0
  535. package/v3/@claude-flow/guidance/dist/optimizer.js +329 -0
  536. package/v3/@claude-flow/guidance/dist/persistence.d.ts +189 -0
  537. package/v3/@claude-flow/guidance/dist/persistence.js +464 -0
  538. package/v3/@claude-flow/guidance/dist/proof.d.ts +185 -0
  539. package/v3/@claude-flow/guidance/dist/proof.js +238 -0
  540. package/v3/@claude-flow/guidance/dist/retriever.d.ts +116 -0
  541. package/v3/@claude-flow/guidance/dist/retriever.js +394 -0
  542. package/v3/@claude-flow/guidance/dist/ruvbot-integration.d.ts +370 -0
  543. package/v3/@claude-flow/guidance/dist/ruvbot-integration.js +738 -0
  544. package/v3/@claude-flow/guidance/dist/temporal.d.ts +426 -0
  545. package/v3/@claude-flow/guidance/dist/temporal.js +658 -0
  546. package/v3/@claude-flow/guidance/dist/trust.d.ts +283 -0
  547. package/v3/@claude-flow/guidance/dist/trust.js +473 -0
  548. package/v3/@claude-flow/guidance/dist/truth-anchors.d.ts +276 -0
  549. package/v3/@claude-flow/guidance/dist/truth-anchors.js +488 -0
  550. package/v3/@claude-flow/guidance/dist/types.d.ts +378 -0
  551. package/v3/@claude-flow/guidance/dist/types.js +10 -0
  552. package/v3/@claude-flow/guidance/dist/uncertainty.d.ts +372 -0
  553. package/v3/@claude-flow/guidance/dist/uncertainty.js +619 -0
  554. package/v3/@claude-flow/guidance/dist/wasm-kernel.d.ts +48 -0
  555. package/v3/@claude-flow/guidance/dist/wasm-kernel.js +158 -0
  556. package/v3/@claude-flow/guidance/package.json +197 -0
  557. package/v3/@claude-flow/shared/README.md +323 -0
  558. package/v3/@claude-flow/shared/dist/core/config/defaults.d.ts +41 -0
  559. package/v3/@claude-flow/shared/dist/core/config/defaults.js +186 -0
  560. package/v3/@claude-flow/shared/dist/core/config/index.d.ts +8 -0
  561. package/v3/@claude-flow/shared/dist/core/config/index.js +12 -0
  562. package/v3/@claude-flow/shared/dist/core/config/loader.d.ts +45 -0
  563. package/v3/@claude-flow/shared/dist/core/config/loader.js +222 -0
  564. package/v3/@claude-flow/shared/dist/core/config/schema.d.ts +1134 -0
  565. package/v3/@claude-flow/shared/dist/core/config/schema.js +158 -0
  566. package/v3/@claude-flow/shared/dist/core/config/validator.d.ts +92 -0
  567. package/v3/@claude-flow/shared/dist/core/config/validator.js +147 -0
  568. package/v3/@claude-flow/shared/dist/core/event-bus.d.ts +31 -0
  569. package/v3/@claude-flow/shared/dist/core/event-bus.js +197 -0
  570. package/v3/@claude-flow/shared/dist/core/index.d.ts +15 -0
  571. package/v3/@claude-flow/shared/dist/core/index.js +19 -0
  572. package/v3/@claude-flow/shared/dist/core/interfaces/agent.interface.d.ts +200 -0
  573. package/v3/@claude-flow/shared/dist/core/interfaces/agent.interface.js +6 -0
  574. package/v3/@claude-flow/shared/dist/core/interfaces/coordinator.interface.d.ts +310 -0
  575. package/v3/@claude-flow/shared/dist/core/interfaces/coordinator.interface.js +7 -0
  576. package/v3/@claude-flow/shared/dist/core/interfaces/event.interface.d.ts +224 -0
  577. package/v3/@claude-flow/shared/dist/core/interfaces/event.interface.js +46 -0
  578. package/v3/@claude-flow/shared/dist/core/interfaces/index.d.ts +10 -0
  579. package/v3/@claude-flow/shared/dist/core/interfaces/index.js +15 -0
  580. package/v3/@claude-flow/shared/dist/core/interfaces/memory.interface.d.ts +298 -0
  581. package/v3/@claude-flow/shared/dist/core/interfaces/memory.interface.js +7 -0
  582. package/v3/@claude-flow/shared/dist/core/interfaces/task.interface.d.ts +185 -0
  583. package/v3/@claude-flow/shared/dist/core/interfaces/task.interface.js +6 -0
  584. package/v3/@claude-flow/shared/dist/core/orchestrator/event-coordinator.d.ts +35 -0
  585. package/v3/@claude-flow/shared/dist/core/orchestrator/event-coordinator.js +101 -0
  586. package/v3/@claude-flow/shared/dist/core/orchestrator/health-monitor.d.ts +60 -0
  587. package/v3/@claude-flow/shared/dist/core/orchestrator/health-monitor.js +166 -0
  588. package/v3/@claude-flow/shared/dist/core/orchestrator/index.d.ts +46 -0
  589. package/v3/@claude-flow/shared/dist/core/orchestrator/index.js +64 -0
  590. package/v3/@claude-flow/shared/dist/core/orchestrator/lifecycle-manager.d.ts +56 -0
  591. package/v3/@claude-flow/shared/dist/core/orchestrator/lifecycle-manager.js +195 -0
  592. package/v3/@claude-flow/shared/dist/core/orchestrator/session-manager.d.ts +83 -0
  593. package/v3/@claude-flow/shared/dist/core/orchestrator/session-manager.js +193 -0
  594. package/v3/@claude-flow/shared/dist/core/orchestrator/task-manager.d.ts +49 -0
  595. package/v3/@claude-flow/shared/dist/core/orchestrator/task-manager.js +253 -0
  596. package/v3/@claude-flow/shared/dist/events/domain-events.d.ts +282 -0
  597. package/v3/@claude-flow/shared/dist/events/domain-events.js +165 -0
  598. package/v3/@claude-flow/shared/dist/events/event-store.d.ts +126 -0
  599. package/v3/@claude-flow/shared/dist/events/event-store.js +416 -0
  600. package/v3/@claude-flow/shared/dist/events/event-store.test.d.ts +8 -0
  601. package/v3/@claude-flow/shared/dist/events/event-store.test.js +293 -0
  602. package/v3/@claude-flow/shared/dist/events/example-usage.d.ts +10 -0
  603. package/v3/@claude-flow/shared/dist/events/example-usage.js +193 -0
  604. package/v3/@claude-flow/shared/dist/events/index.d.ts +21 -0
  605. package/v3/@claude-flow/shared/dist/events/index.js +22 -0
  606. package/v3/@claude-flow/shared/dist/events/projections.d.ts +177 -0
  607. package/v3/@claude-flow/shared/dist/events/projections.js +421 -0
  608. package/v3/@claude-flow/shared/dist/events/rvf-event-log.d.ts +82 -0
  609. package/v3/@claude-flow/shared/dist/events/rvf-event-log.js +340 -0
  610. package/v3/@claude-flow/shared/dist/events/state-reconstructor.d.ts +101 -0
  611. package/v3/@claude-flow/shared/dist/events/state-reconstructor.js +263 -0
  612. package/v3/@claude-flow/shared/dist/events.d.ts +80 -0
  613. package/v3/@claude-flow/shared/dist/events.js +249 -0
  614. package/v3/@claude-flow/shared/dist/hooks/example-usage.d.ts +42 -0
  615. package/v3/@claude-flow/shared/dist/hooks/example-usage.js +351 -0
  616. package/v3/@claude-flow/shared/dist/hooks/executor.d.ts +100 -0
  617. package/v3/@claude-flow/shared/dist/hooks/executor.js +264 -0
  618. package/v3/@claude-flow/shared/dist/hooks/hooks.test.d.ts +9 -0
  619. package/v3/@claude-flow/shared/dist/hooks/hooks.test.js +322 -0
  620. package/v3/@claude-flow/shared/dist/hooks/index.d.ts +52 -0
  621. package/v3/@claude-flow/shared/dist/hooks/index.js +51 -0
  622. package/v3/@claude-flow/shared/dist/hooks/registry.d.ts +133 -0
  623. package/v3/@claude-flow/shared/dist/hooks/registry.js +277 -0
  624. package/v3/@claude-flow/shared/dist/hooks/safety/bash-safety.d.ts +105 -0
  625. package/v3/@claude-flow/shared/dist/hooks/safety/bash-safety.js +481 -0
  626. package/v3/@claude-flow/shared/dist/hooks/safety/file-organization.d.ts +144 -0
  627. package/v3/@claude-flow/shared/dist/hooks/safety/file-organization.js +328 -0
  628. package/v3/@claude-flow/shared/dist/hooks/safety/git-commit.d.ts +158 -0
  629. package/v3/@claude-flow/shared/dist/hooks/safety/git-commit.js +450 -0
  630. package/v3/@claude-flow/shared/dist/hooks/safety/index.d.ts +17 -0
  631. package/v3/@claude-flow/shared/dist/hooks/safety/index.js +17 -0
  632. package/v3/@claude-flow/shared/dist/hooks/session-hooks.d.ts +234 -0
  633. package/v3/@claude-flow/shared/dist/hooks/session-hooks.js +334 -0
  634. package/v3/@claude-flow/shared/dist/hooks/task-hooks.d.ts +163 -0
  635. package/v3/@claude-flow/shared/dist/hooks/task-hooks.js +326 -0
  636. package/v3/@claude-flow/shared/dist/hooks/types.d.ts +267 -0
  637. package/v3/@claude-flow/shared/dist/hooks/types.js +62 -0
  638. package/v3/@claude-flow/shared/dist/hooks/verify-exports.test.d.ts +9 -0
  639. package/v3/@claude-flow/shared/dist/hooks/verify-exports.test.js +93 -0
  640. package/v3/@claude-flow/shared/dist/index.d.ts +20 -0
  641. package/v3/@claude-flow/shared/dist/index.js +50 -0
  642. package/v3/@claude-flow/shared/dist/mcp/connection-pool.d.ts +98 -0
  643. package/v3/@claude-flow/shared/dist/mcp/connection-pool.js +364 -0
  644. package/v3/@claude-flow/shared/dist/mcp/index.d.ts +69 -0
  645. package/v3/@claude-flow/shared/dist/mcp/index.js +84 -0
  646. package/v3/@claude-flow/shared/dist/mcp/server.d.ts +166 -0
  647. package/v3/@claude-flow/shared/dist/mcp/server.js +593 -0
  648. package/v3/@claude-flow/shared/dist/mcp/session-manager.d.ts +136 -0
  649. package/v3/@claude-flow/shared/dist/mcp/session-manager.js +335 -0
  650. package/v3/@claude-flow/shared/dist/mcp/tool-registry.d.ts +178 -0
  651. package/v3/@claude-flow/shared/dist/mcp/tool-registry.js +439 -0
  652. package/v3/@claude-flow/shared/dist/mcp/transport/http.d.ts +104 -0
  653. package/v3/@claude-flow/shared/dist/mcp/transport/http.js +476 -0
  654. package/v3/@claude-flow/shared/dist/mcp/transport/index.d.ts +102 -0
  655. package/v3/@claude-flow/shared/dist/mcp/transport/index.js +238 -0
  656. package/v3/@claude-flow/shared/dist/mcp/transport/stdio.d.ts +104 -0
  657. package/v3/@claude-flow/shared/dist/mcp/transport/stdio.js +263 -0
  658. package/v3/@claude-flow/shared/dist/mcp/transport/websocket.d.ts +133 -0
  659. package/v3/@claude-flow/shared/dist/mcp/transport/websocket.js +396 -0
  660. package/v3/@claude-flow/shared/dist/mcp/types.d.ts +438 -0
  661. package/v3/@claude-flow/shared/dist/mcp/types.js +54 -0
  662. package/v3/@claude-flow/shared/dist/plugin-interface.d.ts +544 -0
  663. package/v3/@claude-flow/shared/dist/plugin-interface.js +23 -0
  664. package/v3/@claude-flow/shared/dist/plugin-loader.d.ts +139 -0
  665. package/v3/@claude-flow/shared/dist/plugin-loader.js +434 -0
  666. package/v3/@claude-flow/shared/dist/plugin-registry.d.ts +183 -0
  667. package/v3/@claude-flow/shared/dist/plugin-registry.js +457 -0
  668. package/v3/@claude-flow/shared/dist/plugins/index.d.ts +10 -0
  669. package/v3/@claude-flow/shared/dist/plugins/index.js +10 -0
  670. package/v3/@claude-flow/shared/dist/plugins/official/hive-mind-plugin.d.ts +106 -0
  671. package/v3/@claude-flow/shared/dist/plugins/official/hive-mind-plugin.js +241 -0
  672. package/v3/@claude-flow/shared/dist/plugins/official/index.d.ts +10 -0
  673. package/v3/@claude-flow/shared/dist/plugins/official/index.js +10 -0
  674. package/v3/@claude-flow/shared/dist/plugins/official/maestro-plugin.d.ts +121 -0
  675. package/v3/@claude-flow/shared/dist/plugins/official/maestro-plugin.js +355 -0
  676. package/v3/@claude-flow/shared/dist/plugins/types.d.ts +93 -0
  677. package/v3/@claude-flow/shared/dist/plugins/types.js +9 -0
  678. package/v3/@claude-flow/shared/dist/resilience/bulkhead.d.ts +105 -0
  679. package/v3/@claude-flow/shared/dist/resilience/bulkhead.js +206 -0
  680. package/v3/@claude-flow/shared/dist/resilience/circuit-breaker.d.ts +132 -0
  681. package/v3/@claude-flow/shared/dist/resilience/circuit-breaker.js +233 -0
  682. package/v3/@claude-flow/shared/dist/resilience/index.d.ts +19 -0
  683. package/v3/@claude-flow/shared/dist/resilience/index.js +19 -0
  684. package/v3/@claude-flow/shared/dist/resilience/rate-limiter.d.ts +168 -0
  685. package/v3/@claude-flow/shared/dist/resilience/rate-limiter.js +314 -0
  686. package/v3/@claude-flow/shared/dist/resilience/retry.d.ts +91 -0
  687. package/v3/@claude-flow/shared/dist/resilience/retry.js +159 -0
  688. package/v3/@claude-flow/shared/dist/security/index.d.ts +10 -0
  689. package/v3/@claude-flow/shared/dist/security/index.js +12 -0
  690. package/v3/@claude-flow/shared/dist/security/input-validation.d.ts +73 -0
  691. package/v3/@claude-flow/shared/dist/security/input-validation.js +201 -0
  692. package/v3/@claude-flow/shared/dist/security/secure-random.d.ts +92 -0
  693. package/v3/@claude-flow/shared/dist/security/secure-random.js +142 -0
  694. package/v3/@claude-flow/shared/dist/services/index.d.ts +7 -0
  695. package/v3/@claude-flow/shared/dist/services/index.js +7 -0
  696. package/v3/@claude-flow/shared/dist/services/v3-progress.service.d.ts +124 -0
  697. package/v3/@claude-flow/shared/dist/services/v3-progress.service.js +402 -0
  698. package/v3/@claude-flow/shared/dist/types/agent.types.d.ts +137 -0
  699. package/v3/@claude-flow/shared/dist/types/agent.types.js +6 -0
  700. package/v3/@claude-flow/shared/dist/types/index.d.ts +11 -0
  701. package/v3/@claude-flow/shared/dist/types/index.js +17 -0
  702. package/v3/@claude-flow/shared/dist/types/mcp.types.d.ts +266 -0
  703. package/v3/@claude-flow/shared/dist/types/mcp.types.js +7 -0
  704. package/v3/@claude-flow/shared/dist/types/memory.types.d.ts +236 -0
  705. package/v3/@claude-flow/shared/dist/types/memory.types.js +7 -0
  706. package/v3/@claude-flow/shared/dist/types/swarm.types.d.ts +186 -0
  707. package/v3/@claude-flow/shared/dist/types/swarm.types.js +65 -0
  708. package/v3/@claude-flow/shared/dist/types/task.types.d.ts +178 -0
  709. package/v3/@claude-flow/shared/dist/types/task.types.js +32 -0
  710. package/v3/@claude-flow/shared/dist/types.d.ts +197 -0
  711. package/v3/@claude-flow/shared/dist/types.js +21 -0
  712. package/v3/@claude-flow/shared/dist/utils/secure-logger.d.ts +69 -0
  713. package/v3/@claude-flow/shared/dist/utils/secure-logger.js +208 -0
  714. package/v3/@claude-flow/shared/package.json +42 -0
  715. package/v3/README.md +493 -0
@@ -0,0 +1,1494 @@
1
+ /**
2
+ * Memory Bridge — Routes CLI memory operations through ControllerRegistry + AgentDB v3
3
+ *
4
+ * Per ADR-053 Phases 1-6: Full controller activation pipeline.
5
+ * CLI → ControllerRegistry → AgentDB v3 controllers.
6
+ *
7
+ * Phase 1: Core CRUD + embeddings + HNSW + controller access (complete)
8
+ * Phase 2: BM25 hybrid search, TieredCache read/write, MutationGuard validation
9
+ * Phase 3: ReasoningBank pattern store, recordFeedback, CausalMemoryGraph edges
10
+ * Phase 4: SkillLibrary promotion, ExplainableRecall provenance, AttestationLog
11
+ * Phase 5: ReflexionMemory session lifecycle, WitnessChain attestation
12
+ * Phase 6: AgentDB MCP tools (separate file), COW branching
13
+ *
14
+ * Uses better-sqlite3 API (synchronous .all()/.get()/.run()) since that's
15
+ * what AgentDB v3 uses internally.
16
+ *
17
+ * @module v3/cli/memory-bridge
18
+ */
19
+ import * as path from 'path';
20
+ import * as crypto from 'crypto';
21
+ // ===== Lazy singleton =====
22
+ let registryPromise = null;
23
+ let registryInstance = null;
24
+ let bridgeAvailable = null;
25
+ /**
26
+ * Resolve database path with path traversal protection.
27
+ * Only allows paths within or below the project's .swarm directory,
28
+ * or the special ':memory:' path.
29
+ */
30
+ function getDbPath(customPath) {
31
+ const swarmDir = path.resolve(process.cwd(), '.swarm');
32
+ if (!customPath)
33
+ return path.join(swarmDir, 'memory.db');
34
+ if (customPath === ':memory:')
35
+ return ':memory:';
36
+ const resolved = path.resolve(customPath);
37
+ // Ensure the path doesn't escape the working directory
38
+ const cwd = process.cwd();
39
+ if (!resolved.startsWith(cwd)) {
40
+ return path.join(swarmDir, 'memory.db'); // fallback to safe default
41
+ }
42
+ return resolved;
43
+ }
44
+ /**
45
+ * Generate a secure random ID for memory entries.
46
+ */
47
+ function generateId(prefix) {
48
+ return `${prefix}_${Date.now()}_${crypto.randomBytes(8).toString('hex')}`;
49
+ }
50
+ /**
51
+ * Lazily initialize the ControllerRegistry singleton.
52
+ * Returns null if @claude-flow/memory is not available.
53
+ */
54
+ async function getRegistry(dbPath) {
55
+ if (bridgeAvailable === false)
56
+ return null;
57
+ if (registryInstance)
58
+ return registryInstance;
59
+ if (!registryPromise) {
60
+ registryPromise = (async () => {
61
+ try {
62
+ const { ControllerRegistry } = await import('@claude-flow/memory');
63
+ const registry = new ControllerRegistry();
64
+ // Suppress noisy console.log during init
65
+ const origLog = console.log;
66
+ console.log = (...args) => {
67
+ const msg = String(args[0] ?? '');
68
+ if (msg.includes('Transformers.js') ||
69
+ msg.includes('better-sqlite3') ||
70
+ msg.includes('[AgentDB]') ||
71
+ msg.includes('[HNSWLibBackend]') ||
72
+ msg.includes('RuVector graph'))
73
+ return;
74
+ origLog.apply(console, args);
75
+ };
76
+ try {
77
+ await registry.initialize({
78
+ dbPath: dbPath || getDbPath(),
79
+ dimension: 384,
80
+ controllers: {
81
+ reasoningBank: true,
82
+ learningBridge: false,
83
+ tieredCache: true,
84
+ hierarchicalMemory: true,
85
+ memoryConsolidation: true,
86
+ memoryGraph: true, // issue #1214: enable MemoryGraph for graph-aware ranking
87
+ },
88
+ });
89
+ }
90
+ finally {
91
+ console.log = origLog;
92
+ }
93
+ registryInstance = registry;
94
+ bridgeAvailable = true;
95
+ return registry;
96
+ }
97
+ catch {
98
+ bridgeAvailable = false;
99
+ registryPromise = null;
100
+ return null;
101
+ }
102
+ })();
103
+ }
104
+ return registryPromise;
105
+ }
106
+ // ===== Phase 2: BM25 hybrid scoring =====
107
+ /**
108
+ * BM25 scoring for keyword-based search.
109
+ * Replaces naive String.includes() with proper information retrieval scoring.
110
+ * Parameters tuned for short memory entries (k1=1.2, b=0.75).
111
+ */
112
+ function bm25Score(queryTerms, docContent, avgDocLength, docCount, termDocFreqs) {
113
+ const k1 = 1.2;
114
+ const b = 0.75;
115
+ const docWords = docContent.toLowerCase().split(/\s+/);
116
+ const docLength = docWords.length;
117
+ let score = 0;
118
+ for (const term of queryTerms) {
119
+ const tf = docWords.filter(w => w === term || w.includes(term)).length;
120
+ if (tf === 0)
121
+ continue;
122
+ const df = termDocFreqs.get(term) || 1;
123
+ const idf = Math.log((docCount - df + 0.5) / (df + 0.5) + 1);
124
+ const tfNorm = (tf * (k1 + 1)) / (tf + k1 * (1 - b + b * (docLength / Math.max(1, avgDocLength))));
125
+ score += idf * tfNorm;
126
+ }
127
+ return score;
128
+ }
129
+ /**
130
+ * Compute BM25 term document frequencies for a set of rows.
131
+ */
132
+ function computeTermDocFreqs(queryTerms, rows) {
133
+ const termDocFreqs = new Map();
134
+ let totalLength = 0;
135
+ for (const row of rows) {
136
+ const content = (row.content || '').toLowerCase();
137
+ const words = content.split(/\s+/);
138
+ totalLength += words.length;
139
+ for (const term of queryTerms) {
140
+ if (content.includes(term)) {
141
+ termDocFreqs.set(term, (termDocFreqs.get(term) || 0) + 1);
142
+ }
143
+ }
144
+ }
145
+ return { termDocFreqs, avgDocLength: rows.length > 0 ? totalLength / rows.length : 1 };
146
+ }
147
+ // ===== Phase 2: TieredCache helpers =====
148
+ /**
149
+ * Try to read from TieredCache before hitting DB.
150
+ * Returns cached value or null if cache miss.
151
+ */
152
+ async function cacheGet(registry, cacheKey) {
153
+ try {
154
+ const cache = registry.get('tieredCache');
155
+ if (!cache || typeof cache.get !== 'function')
156
+ return null;
157
+ return cache.get(cacheKey) ?? null;
158
+ }
159
+ catch {
160
+ return null;
161
+ }
162
+ }
163
+ /**
164
+ * Write to TieredCache after DB write.
165
+ */
166
+ async function cacheSet(registry, cacheKey, value) {
167
+ try {
168
+ const cache = registry.get('tieredCache');
169
+ if (cache && typeof cache.set === 'function') {
170
+ cache.set(cacheKey, value);
171
+ }
172
+ }
173
+ catch {
174
+ // Non-fatal
175
+ }
176
+ }
177
+ /**
178
+ * Invalidate a cache key after mutation.
179
+ */
180
+ async function cacheInvalidate(registry, cacheKey) {
181
+ try {
182
+ const cache = registry.get('tieredCache');
183
+ if (cache && typeof cache.delete === 'function') {
184
+ cache.delete(cacheKey);
185
+ }
186
+ }
187
+ catch {
188
+ // Non-fatal
189
+ }
190
+ }
191
+ // ===== Phase 2: MutationGuard helpers =====
192
+ /**
193
+ * Validate a mutation through MutationGuard before executing.
194
+ * Returns true if the mutation is allowed, false if rejected.
195
+ * When guard is unavailable (not installed), mutations are allowed.
196
+ * When guard is present but throws, mutations are DENIED (fail-closed).
197
+ */
198
+ async function guardValidate(registry, operation, params) {
199
+ try {
200
+ const guard = registry.get('mutationGuard');
201
+ if (!guard || typeof guard.validate !== 'function') {
202
+ return { allowed: true }; // No guard installed = allow (degraded mode)
203
+ }
204
+ const result = guard.validate({ operation, params, timestamp: Date.now() });
205
+ return { allowed: result?.allowed === true, reason: result?.reason };
206
+ }
207
+ catch {
208
+ return { allowed: false, reason: 'MutationGuard validation error' }; // Fail-closed
209
+ }
210
+ }
211
+ // ===== Phase 3: AttestationLog helpers =====
212
+ /**
213
+ * Log a write operation to AttestationLog/WitnessChain.
214
+ */
215
+ async function logAttestation(registry, operation, entryId, metadata) {
216
+ try {
217
+ const attestation = registry.get('attestationLog');
218
+ if (!attestation)
219
+ return;
220
+ if (typeof attestation.record === 'function') {
221
+ attestation.record({ operation, entryId, timestamp: Date.now(), ...metadata });
222
+ }
223
+ else if (typeof attestation.log === 'function') {
224
+ attestation.log(operation, entryId, metadata);
225
+ }
226
+ }
227
+ catch {
228
+ // Non-fatal — attestation is observability, not correctness
229
+ }
230
+ }
231
+ /**
232
+ * Get the AgentDB database handle and ensure memory_entries table exists.
233
+ * Returns null if not available.
234
+ */
235
+ function getDb(registry) {
236
+ const agentdb = registry.getAgentDB();
237
+ if (!agentdb?.database)
238
+ return null;
239
+ const db = agentdb.database;
240
+ // Ensure memory_entries table exists (idempotent)
241
+ try {
242
+ db.exec(`CREATE TABLE IF NOT EXISTS memory_entries (
243
+ id TEXT PRIMARY KEY,
244
+ key TEXT NOT NULL,
245
+ namespace TEXT DEFAULT 'default',
246
+ content TEXT NOT NULL,
247
+ type TEXT DEFAULT 'semantic',
248
+ embedding TEXT,
249
+ embedding_model TEXT DEFAULT 'local',
250
+ embedding_dimensions INTEGER,
251
+ tags TEXT,
252
+ metadata TEXT,
253
+ owner_id TEXT,
254
+ created_at INTEGER NOT NULL DEFAULT (strftime('%s', 'now') * 1000),
255
+ updated_at INTEGER NOT NULL DEFAULT (strftime('%s', 'now') * 1000),
256
+ expires_at INTEGER,
257
+ last_accessed_at INTEGER,
258
+ access_count INTEGER DEFAULT 0,
259
+ status TEXT DEFAULT 'active',
260
+ UNIQUE(namespace, key)
261
+ )`);
262
+ // Ensure indexes
263
+ db.exec(`CREATE INDEX IF NOT EXISTS idx_bridge_ns ON memory_entries(namespace)`);
264
+ db.exec(`CREATE INDEX IF NOT EXISTS idx_bridge_key ON memory_entries(key)`);
265
+ db.exec(`CREATE INDEX IF NOT EXISTS idx_bridge_status ON memory_entries(status)`);
266
+ }
267
+ catch {
268
+ // Table already exists or db is read-only — that's fine
269
+ }
270
+ return { db, agentdb };
271
+ }
272
+ // ===== Bridge functions — match memory-initializer.ts signatures =====
273
+ /**
274
+ * Store an entry via AgentDB v3.
275
+ * Phase 2-5: Routes through MutationGuard → TieredCache → DB → AttestationLog.
276
+ * Returns null to signal fallback to sql.js.
277
+ */
278
+ export async function bridgeStoreEntry(options) {
279
+ const registry = await getRegistry(options.dbPath);
280
+ if (!registry)
281
+ return null;
282
+ const ctx = getDb(registry);
283
+ if (!ctx)
284
+ return null;
285
+ try {
286
+ const { key, value, namespace = 'default', tags = [], ttl } = options;
287
+ const id = generateId('entry');
288
+ const now = Date.now();
289
+ // Phase 5: MutationGuard validation before write
290
+ const guardResult = await guardValidate(registry, 'store', { key, namespace, size: value.length });
291
+ if (!guardResult.allowed) {
292
+ return { success: false, id, error: `MutationGuard rejected: ${guardResult.reason}` };
293
+ }
294
+ // Generate embedding via AgentDB's embedder
295
+ let embeddingJson = null;
296
+ let dimensions = 0;
297
+ let model = 'local';
298
+ if (options.generateEmbeddingFlag !== false && value.length > 0) {
299
+ try {
300
+ const embedder = ctx.agentdb.embedder;
301
+ if (embedder) {
302
+ const emb = await embedder.embed(value);
303
+ if (emb) {
304
+ embeddingJson = JSON.stringify(Array.from(emb));
305
+ dimensions = emb.length;
306
+ model = 'Xenova/all-MiniLM-L6-v2';
307
+ }
308
+ }
309
+ }
310
+ catch {
311
+ // Embedding failed — store without
312
+ }
313
+ }
314
+ // better-sqlite3 uses synchronous .run() with positional params
315
+ const insertSql = options.upsert
316
+ ? `INSERT OR REPLACE INTO memory_entries (
317
+ id, key, namespace, content, type,
318
+ embedding, embedding_dimensions, embedding_model,
319
+ tags, metadata, created_at, updated_at, expires_at, status
320
+ ) VALUES (?, ?, ?, ?, 'semantic', ?, ?, ?, ?, ?, ?, ?, ?, 'active')`
321
+ : `INSERT INTO memory_entries (
322
+ id, key, namespace, content, type,
323
+ embedding, embedding_dimensions, embedding_model,
324
+ tags, metadata, created_at, updated_at, expires_at, status
325
+ ) VALUES (?, ?, ?, ?, 'semantic', ?, ?, ?, ?, ?, ?, ?, ?, 'active')`;
326
+ const stmt = ctx.db.prepare(insertSql);
327
+ stmt.run(id, key, namespace, value, embeddingJson, dimensions || null, model, tags.length > 0 ? JSON.stringify(tags) : null, '{}', now, now, ttl ? now + (ttl * 1000) : null);
328
+ // Phase 2: Write-through to TieredCache
329
+ const safeNs = String(namespace).replace(/:/g, '_');
330
+ const safeKey = String(key).replace(/:/g, '_');
331
+ const cacheKey = `entry:${safeNs}:${safeKey}`;
332
+ await cacheSet(registry, cacheKey, { id, key, namespace, content: value, embedding: embeddingJson });
333
+ // Phase 4: AttestationLog write audit
334
+ await logAttestation(registry, 'store', id, { key, namespace, hasEmbedding: !!embeddingJson });
335
+ return {
336
+ success: true,
337
+ id,
338
+ embedding: embeddingJson ? { dimensions, model } : undefined,
339
+ guarded: true,
340
+ cached: true,
341
+ attested: true,
342
+ };
343
+ }
344
+ catch {
345
+ return null;
346
+ }
347
+ }
348
+ /**
349
+ * Search entries via AgentDB v3.
350
+ * Phase 2: BM25 hybrid scoring replaces naive String.includes() keyword fallback.
351
+ * Combines cosine similarity (semantic) with BM25 (lexical) via reciprocal rank fusion.
352
+ */
353
+ export async function bridgeSearchEntries(options) {
354
+ const registry = await getRegistry(options.dbPath);
355
+ if (!registry)
356
+ return null;
357
+ const ctx = getDb(registry);
358
+ if (!ctx)
359
+ return null;
360
+ try {
361
+ const { query: queryStr, namespace = 'default', limit = 10, threshold = 0.3 } = options;
362
+ const startTime = Date.now();
363
+ // Generate query embedding
364
+ let queryEmbedding = null;
365
+ try {
366
+ const embedder = ctx.agentdb.embedder;
367
+ if (embedder) {
368
+ const emb = await embedder.embed(queryStr);
369
+ queryEmbedding = Array.from(emb);
370
+ }
371
+ }
372
+ catch {
373
+ // Fall back to keyword search
374
+ }
375
+ // better-sqlite3: .prepare().all() returns array of objects
376
+ const nsFilter = namespace !== 'all'
377
+ ? `AND namespace = ?`
378
+ : '';
379
+ let rows;
380
+ try {
381
+ const stmt = ctx.db.prepare(`
382
+ SELECT id, key, namespace, content, embedding
383
+ FROM memory_entries
384
+ WHERE status = 'active' ${nsFilter}
385
+ LIMIT 1000
386
+ `);
387
+ rows = namespace !== 'all' ? stmt.all(namespace) : stmt.all();
388
+ }
389
+ catch {
390
+ return null;
391
+ }
392
+ // Phase 2: Compute BM25 term stats for the corpus
393
+ const queryTerms = queryStr.toLowerCase().split(/\s+/).filter(t => t.length > 1);
394
+ const { termDocFreqs, avgDocLength } = computeTermDocFreqs(queryTerms, rows);
395
+ const docCount = rows.length;
396
+ const results = [];
397
+ for (const row of rows) {
398
+ let semanticScore = 0;
399
+ let bm25ScoreVal = 0;
400
+ // Semantic scoring via cosine similarity
401
+ if (queryEmbedding && row.embedding) {
402
+ try {
403
+ const embedding = JSON.parse(row.embedding);
404
+ semanticScore = cosineSim(queryEmbedding, embedding);
405
+ }
406
+ catch {
407
+ // Invalid embedding
408
+ }
409
+ }
410
+ // Phase 2: BM25 keyword scoring (replaces String.includes fallback)
411
+ if (queryTerms.length > 0 && row.content) {
412
+ bm25ScoreVal = bm25Score(queryTerms, row.content, avgDocLength, docCount, termDocFreqs);
413
+ // Normalize BM25 to 0-1 range (cap at 10 for normalization)
414
+ bm25ScoreVal = Math.min(bm25ScoreVal / 10, 1.0);
415
+ }
416
+ // Reciprocal rank fusion: combine semantic and BM25
417
+ // Weight: 0.7 semantic + 0.3 BM25 (semantic preferred when embeddings available)
418
+ const score = queryEmbedding
419
+ ? (0.7 * semanticScore + 0.3 * bm25ScoreVal)
420
+ : bm25ScoreVal; // BM25-only when no embeddings
421
+ if (score >= threshold) {
422
+ // Phase 4: ExplainableRecall provenance
423
+ const provenance = queryEmbedding
424
+ ? `semantic:${semanticScore.toFixed(3)}+bm25:${bm25ScoreVal.toFixed(3)}`
425
+ : `bm25:${bm25ScoreVal.toFixed(3)}`;
426
+ results.push({
427
+ id: String(row.id).substring(0, 12),
428
+ key: row.key || String(row.id).substring(0, 15),
429
+ content: (row.content || '').substring(0, 60) + ((row.content || '').length > 60 ? '...' : ''),
430
+ score,
431
+ namespace: row.namespace || 'default',
432
+ provenance,
433
+ });
434
+ }
435
+ }
436
+ results.sort((a, b) => b.score - a.score);
437
+ return {
438
+ success: true,
439
+ results: results.slice(0, limit),
440
+ searchTime: Date.now() - startTime,
441
+ searchMethod: queryEmbedding ? 'hybrid-bm25-semantic' : 'bm25-only',
442
+ };
443
+ }
444
+ catch {
445
+ return null;
446
+ }
447
+ }
448
+ /**
449
+ * List entries via AgentDB v3.
450
+ */
451
+ export async function bridgeListEntries(options) {
452
+ const registry = await getRegistry(options.dbPath);
453
+ if (!registry)
454
+ return null;
455
+ const ctx = getDb(registry);
456
+ if (!ctx)
457
+ return null;
458
+ try {
459
+ const { namespace, limit = 20, offset = 0 } = options;
460
+ const nsFilter = namespace ? `AND namespace = ?` : '';
461
+ const nsParams = namespace ? [namespace] : [];
462
+ // Count
463
+ let total = 0;
464
+ try {
465
+ const countStmt = ctx.db.prepare(`SELECT COUNT(*) as cnt FROM memory_entries WHERE status = 'active' ${nsFilter}`);
466
+ const countRow = countStmt.get(...nsParams);
467
+ total = countRow?.cnt ?? 0;
468
+ }
469
+ catch {
470
+ return null;
471
+ }
472
+ // List
473
+ const entries = [];
474
+ try {
475
+ const stmt = ctx.db.prepare(`
476
+ SELECT id, key, namespace, content, embedding, access_count, created_at, updated_at
477
+ FROM memory_entries
478
+ WHERE status = 'active' ${nsFilter}
479
+ ORDER BY updated_at DESC
480
+ LIMIT ? OFFSET ?
481
+ `);
482
+ const rows = stmt.all(...nsParams, limit, offset);
483
+ for (const row of rows) {
484
+ entries.push({
485
+ id: String(row.id).substring(0, 20),
486
+ key: row.key || String(row.id).substring(0, 15),
487
+ namespace: row.namespace || 'default',
488
+ size: (row.content || '').length,
489
+ accessCount: row.access_count ?? 0,
490
+ createdAt: row.created_at || new Date().toISOString(),
491
+ updatedAt: row.updated_at || new Date().toISOString(),
492
+ hasEmbedding: !!(row.embedding && String(row.embedding).length > 10),
493
+ });
494
+ }
495
+ }
496
+ catch {
497
+ return null;
498
+ }
499
+ return { success: true, entries, total };
500
+ }
501
+ catch {
502
+ return null;
503
+ }
504
+ }
505
+ /**
506
+ * Get a specific entry via AgentDB v3.
507
+ * Phase 2: TieredCache consulted before DB hit.
508
+ */
509
+ export async function bridgeGetEntry(options) {
510
+ const registry = await getRegistry(options.dbPath);
511
+ if (!registry)
512
+ return null;
513
+ const ctx = getDb(registry);
514
+ if (!ctx)
515
+ return null;
516
+ try {
517
+ const { key, namespace = 'default' } = options;
518
+ // Phase 2: Check TieredCache first
519
+ const safeNs = String(namespace).replace(/:/g, '_');
520
+ const safeKey = String(key).replace(/:/g, '_');
521
+ const cacheKey = `entry:${safeNs}:${safeKey}`;
522
+ const cached = await cacheGet(registry, cacheKey);
523
+ if (cached && cached.content) {
524
+ return {
525
+ success: true,
526
+ found: true,
527
+ cacheHit: true,
528
+ entry: {
529
+ id: String(cached.id || ''),
530
+ key: cached.key || key,
531
+ namespace: cached.namespace || namespace,
532
+ content: cached.content || '',
533
+ accessCount: cached.accessCount ?? 0,
534
+ createdAt: cached.createdAt || new Date().toISOString(),
535
+ updatedAt: cached.updatedAt || new Date().toISOString(),
536
+ hasEmbedding: !!cached.embedding,
537
+ tags: cached.tags || [],
538
+ },
539
+ };
540
+ }
541
+ let row;
542
+ try {
543
+ const stmt = ctx.db.prepare(`
544
+ SELECT id, key, namespace, content, embedding, access_count, created_at, updated_at, tags
545
+ FROM memory_entries
546
+ WHERE status = 'active' AND key = ? AND namespace = ?
547
+ LIMIT 1
548
+ `);
549
+ row = stmt.get(key, namespace);
550
+ }
551
+ catch {
552
+ return null;
553
+ }
554
+ if (!row) {
555
+ return { success: true, found: false };
556
+ }
557
+ // Update access count
558
+ try {
559
+ ctx.db.prepare(`UPDATE memory_entries SET access_count = access_count + 1, last_accessed_at = ? WHERE id = ?`).run(Date.now(), row.id);
560
+ }
561
+ catch {
562
+ // Non-fatal
563
+ }
564
+ let tags = [];
565
+ if (row.tags) {
566
+ try {
567
+ tags = JSON.parse(row.tags);
568
+ }
569
+ catch { /* invalid */ }
570
+ }
571
+ const entry = {
572
+ id: String(row.id),
573
+ key: row.key || String(row.id),
574
+ namespace: row.namespace || 'default',
575
+ content: row.content || '',
576
+ accessCount: (row.access_count ?? 0) + 1,
577
+ createdAt: row.created_at || new Date().toISOString(),
578
+ updatedAt: row.updated_at || new Date().toISOString(),
579
+ hasEmbedding: !!(row.embedding && String(row.embedding).length > 10),
580
+ tags,
581
+ };
582
+ // Phase 2: Populate cache for next read
583
+ await cacheSet(registry, cacheKey, entry);
584
+ return { success: true, found: true, cacheHit: false, entry };
585
+ }
586
+ catch {
587
+ return null;
588
+ }
589
+ }
590
+ /**
591
+ * Delete an entry via AgentDB v3.
592
+ * Phase 5: MutationGuard validation, cache invalidation, attestation logging.
593
+ */
594
+ export async function bridgeDeleteEntry(options) {
595
+ const registry = await getRegistry(options.dbPath);
596
+ if (!registry)
597
+ return null;
598
+ const ctx = getDb(registry);
599
+ if (!ctx)
600
+ return null;
601
+ try {
602
+ const { key, namespace = 'default' } = options;
603
+ // Phase 5: MutationGuard validation before delete
604
+ const guardResult = await guardValidate(registry, 'delete', { key, namespace });
605
+ if (!guardResult.allowed) {
606
+ return { success: false, deleted: false, key, namespace, remainingEntries: 0, error: `MutationGuard rejected: ${guardResult.reason}` };
607
+ }
608
+ // Soft delete using parameterized query
609
+ let changes = 0;
610
+ try {
611
+ const result = ctx.db.prepare(`
612
+ UPDATE memory_entries
613
+ SET status = 'deleted', updated_at = ?
614
+ WHERE key = ? AND namespace = ? AND status = 'active'
615
+ `).run(Date.now(), key, namespace);
616
+ changes = result?.changes ?? 0;
617
+ }
618
+ catch {
619
+ return null;
620
+ }
621
+ // Phase 2: Invalidate cache
622
+ const safeNs = String(namespace).replace(/:/g, '_');
623
+ const safeKey = String(key).replace(/:/g, '_');
624
+ await cacheInvalidate(registry, `entry:${safeNs}:${safeKey}`);
625
+ // Phase 4: AttestationLog delete audit
626
+ if (changes > 0) {
627
+ await logAttestation(registry, 'delete', key, { namespace });
628
+ }
629
+ let remaining = 0;
630
+ try {
631
+ const row = ctx.db.prepare(`SELECT COUNT(*) as cnt FROM memory_entries WHERE status = 'active'`).get();
632
+ remaining = row?.cnt ?? 0;
633
+ }
634
+ catch {
635
+ // Non-fatal
636
+ }
637
+ return {
638
+ success: true,
639
+ deleted: changes > 0,
640
+ key,
641
+ namespace,
642
+ remainingEntries: remaining,
643
+ guarded: true,
644
+ };
645
+ }
646
+ catch {
647
+ return null;
648
+ }
649
+ }
650
+ // ===== Phase 2: Embedding bridge =====
651
+ /**
652
+ * Generate embedding via AgentDB v3's embedder.
653
+ * Returns null if bridge unavailable — caller falls back to own ONNX/hash.
654
+ */
655
+ export async function bridgeGenerateEmbedding(text, dbPath) {
656
+ const registry = await getRegistry(dbPath);
657
+ if (!registry)
658
+ return null;
659
+ try {
660
+ const agentdb = registry.getAgentDB();
661
+ const embedder = agentdb?.embedder;
662
+ if (!embedder)
663
+ return null;
664
+ const emb = await embedder.embed(text);
665
+ if (!emb)
666
+ return null;
667
+ return {
668
+ embedding: Array.from(emb),
669
+ dimensions: emb.length,
670
+ model: 'Xenova/all-MiniLM-L6-v2',
671
+ };
672
+ }
673
+ catch {
674
+ return null;
675
+ }
676
+ }
677
+ /**
678
+ * Load embedding model via AgentDB v3 (it loads on init).
679
+ * Returns null if unavailable.
680
+ */
681
+ export async function bridgeLoadEmbeddingModel(dbPath) {
682
+ const startTime = Date.now();
683
+ const registry = await getRegistry(dbPath);
684
+ if (!registry)
685
+ return null;
686
+ try {
687
+ const agentdb = registry.getAgentDB();
688
+ const embedder = agentdb?.embedder;
689
+ if (!embedder)
690
+ return null;
691
+ // Verify embedder works by generating a test embedding
692
+ const test = await embedder.embed('test');
693
+ if (!test)
694
+ return null;
695
+ return {
696
+ success: true,
697
+ dimensions: test.length,
698
+ modelName: 'Xenova/all-MiniLM-L6-v2',
699
+ loadTime: Date.now() - startTime,
700
+ };
701
+ }
702
+ catch {
703
+ return null;
704
+ }
705
+ }
706
+ // ===== Phase 3: HNSW bridge =====
707
+ /**
708
+ * Get HNSW status from AgentDB v3's vector backend or HNSW index.
709
+ * Returns null if unavailable.
710
+ */
711
+ export async function bridgeGetHNSWStatus(dbPath) {
712
+ const registry = await getRegistry(dbPath);
713
+ if (!registry)
714
+ return null;
715
+ try {
716
+ const ctx = getDb(registry);
717
+ if (!ctx)
718
+ return null;
719
+ // Count entries with embeddings
720
+ let entryCount = 0;
721
+ try {
722
+ const row = ctx.db.prepare(`SELECT COUNT(*) as cnt FROM memory_entries WHERE status = 'active' AND embedding IS NOT NULL`).get();
723
+ entryCount = row?.cnt ?? 0;
724
+ }
725
+ catch {
726
+ // Table might not exist
727
+ }
728
+ return {
729
+ available: true,
730
+ initialized: true,
731
+ entryCount,
732
+ dimensions: 384,
733
+ };
734
+ }
735
+ catch {
736
+ return null;
737
+ }
738
+ }
739
+ /**
740
+ * Search using AgentDB v3's embedder + SQLite entries.
741
+ * This is the HNSW-equivalent search through the bridge.
742
+ * Returns null if unavailable.
743
+ */
744
+ export async function bridgeSearchHNSW(queryEmbedding, options, dbPath) {
745
+ const registry = await getRegistry(dbPath);
746
+ if (!registry)
747
+ return null;
748
+ const ctx = getDb(registry);
749
+ if (!ctx)
750
+ return null;
751
+ try {
752
+ const k = options?.k ?? 10;
753
+ const threshold = options?.threshold ?? 0.3;
754
+ const nsFilter = options?.namespace && options.namespace !== 'all'
755
+ ? `AND namespace = ?`
756
+ : '';
757
+ let rows;
758
+ try {
759
+ const stmt = ctx.db.prepare(`
760
+ SELECT id, key, namespace, content, embedding
761
+ FROM memory_entries
762
+ WHERE status = 'active' AND embedding IS NOT NULL ${nsFilter}
763
+ LIMIT 10000
764
+ `);
765
+ rows = nsFilter
766
+ ? stmt.all(options.namespace)
767
+ : stmt.all();
768
+ }
769
+ catch {
770
+ return null;
771
+ }
772
+ const results = [];
773
+ for (const row of rows) {
774
+ if (!row.embedding)
775
+ continue;
776
+ try {
777
+ const emb = JSON.parse(row.embedding);
778
+ const score = cosineSim(queryEmbedding, emb);
779
+ if (score >= threshold) {
780
+ results.push({
781
+ id: String(row.id).substring(0, 12),
782
+ key: row.key || String(row.id).substring(0, 15),
783
+ content: (row.content || '').substring(0, 60) +
784
+ ((row.content || '').length > 60 ? '...' : ''),
785
+ score,
786
+ namespace: row.namespace || 'default',
787
+ });
788
+ }
789
+ }
790
+ catch {
791
+ // Skip invalid embeddings
792
+ }
793
+ }
794
+ results.sort((a, b) => b.score - a.score);
795
+ return results.slice(0, k);
796
+ }
797
+ catch {
798
+ return null;
799
+ }
800
+ }
801
+ /**
802
+ * Add entry to the bridge's database with embedding.
803
+ * Returns null if unavailable.
804
+ */
805
+ export async function bridgeAddToHNSW(id, embedding, entry, dbPath) {
806
+ const registry = await getRegistry(dbPath);
807
+ if (!registry)
808
+ return null;
809
+ const ctx = getDb(registry);
810
+ if (!ctx)
811
+ return null;
812
+ try {
813
+ const now = Date.now();
814
+ const embeddingJson = JSON.stringify(embedding);
815
+ ctx.db.prepare(`
816
+ INSERT OR REPLACE INTO memory_entries (
817
+ id, key, namespace, content, type,
818
+ embedding, embedding_dimensions, embedding_model,
819
+ created_at, updated_at, status
820
+ ) VALUES (?, ?, ?, ?, 'semantic', ?, ?, 'Xenova/all-MiniLM-L6-v2', ?, ?, 'active')
821
+ `).run(id, entry.key, entry.namespace, entry.content, embeddingJson, embedding.length, now, now);
822
+ return true;
823
+ }
824
+ catch {
825
+ return null;
826
+ }
827
+ }
828
+ // ===== Phase 4: Controller access =====
829
+ /**
830
+ * Get a named controller from AgentDB v3 via ControllerRegistry.
831
+ * Returns null if unavailable.
832
+ */
833
+ export async function bridgeGetController(name, dbPath) {
834
+ const registry = await getRegistry(dbPath);
835
+ if (!registry)
836
+ return null;
837
+ try {
838
+ return registry.get(name) ?? null;
839
+ }
840
+ catch {
841
+ return null;
842
+ }
843
+ }
844
+ /**
845
+ * Check if a controller is available.
846
+ */
847
+ export async function bridgeHasController(name, dbPath) {
848
+ const registry = await getRegistry(dbPath);
849
+ if (!registry)
850
+ return false;
851
+ try {
852
+ const controller = registry.get(name);
853
+ return controller !== null && controller !== undefined;
854
+ }
855
+ catch {
856
+ return false;
857
+ }
858
+ }
859
+ /**
860
+ * List all controllers and their status.
861
+ */
862
+ export async function bridgeListControllers(dbPath) {
863
+ const registry = await getRegistry(dbPath);
864
+ if (!registry)
865
+ return null;
866
+ try {
867
+ return registry.listControllers();
868
+ }
869
+ catch {
870
+ return null;
871
+ }
872
+ }
873
+ /**
874
+ * Check if the AgentDB v3 bridge is available.
875
+ */
876
+ export async function isBridgeAvailable(dbPath) {
877
+ if (bridgeAvailable !== null)
878
+ return bridgeAvailable;
879
+ const registry = await getRegistry(dbPath);
880
+ return registry !== null;
881
+ }
882
+ /**
883
+ * Get the ControllerRegistry instance (for advanced consumers).
884
+ */
885
+ export async function getControllerRegistry(dbPath) {
886
+ return getRegistry(dbPath);
887
+ }
888
+ /**
889
+ * Shutdown the bridge and release resources.
890
+ */
891
+ export async function shutdownBridge() {
892
+ if (registryInstance) {
893
+ try {
894
+ await registryInstance.shutdown();
895
+ }
896
+ catch {
897
+ // Best-effort
898
+ }
899
+ registryInstance = null;
900
+ registryPromise = null;
901
+ bridgeAvailable = null;
902
+ }
903
+ }
904
+ // ===== Phase 3: ReasoningBank pattern operations =====
905
+ /**
906
+ * Store a pattern via ReasoningBank controller.
907
+ * Falls back to raw SQL if ReasoningBank unavailable.
908
+ */
909
+ export async function bridgeStorePattern(options) {
910
+ const registry = await getRegistry(options.dbPath);
911
+ if (!registry)
912
+ return null;
913
+ try {
914
+ const reasoningBank = registry.get('reasoningBank');
915
+ const patternId = generateId('pattern');
916
+ if (reasoningBank && typeof reasoningBank.store === 'function') {
917
+ await reasoningBank.store({
918
+ id: patternId,
919
+ content: options.pattern,
920
+ type: options.type,
921
+ confidence: options.confidence,
922
+ metadata: options.metadata,
923
+ timestamp: Date.now(),
924
+ });
925
+ return { success: true, patternId, controller: 'reasoningBank' };
926
+ }
927
+ // Fallback: store via bridge SQL
928
+ const result = await bridgeStoreEntry({
929
+ key: patternId,
930
+ value: JSON.stringify({ pattern: options.pattern, type: options.type, confidence: options.confidence, metadata: options.metadata }),
931
+ namespace: 'pattern',
932
+ generateEmbeddingFlag: true,
933
+ tags: [options.type, 'reasoning-pattern'],
934
+ dbPath: options.dbPath,
935
+ });
936
+ return result ? { success: true, patternId: result.id, controller: 'bridge-fallback' } : null;
937
+ }
938
+ catch {
939
+ return null;
940
+ }
941
+ }
942
+ /**
943
+ * Search patterns via ReasoningBank controller.
944
+ */
945
+ export async function bridgeSearchPatterns(options) {
946
+ const registry = await getRegistry(options.dbPath);
947
+ if (!registry)
948
+ return null;
949
+ try {
950
+ const reasoningBank = registry.get('reasoningBank');
951
+ if (reasoningBank && typeof reasoningBank.search === 'function') {
952
+ const results = await reasoningBank.search(options.query, {
953
+ topK: options.topK || 5,
954
+ minScore: options.minConfidence || 0.3,
955
+ });
956
+ return {
957
+ results: Array.isArray(results) ? results.map((r) => ({
958
+ id: r.id || r.patternId || '',
959
+ content: r.content || r.pattern || '',
960
+ score: r.score ?? r.confidence ?? 0,
961
+ })) : [],
962
+ controller: 'reasoningBank',
963
+ };
964
+ }
965
+ // Fallback: search via bridge
966
+ const result = await bridgeSearchEntries({
967
+ query: options.query,
968
+ namespace: 'pattern',
969
+ limit: options.topK || 5,
970
+ threshold: options.minConfidence || 0.3,
971
+ dbPath: options.dbPath,
972
+ });
973
+ return result ? {
974
+ results: result.results.map(r => ({ id: r.id, content: r.content, score: r.score })),
975
+ controller: 'bridge-fallback',
976
+ } : null;
977
+ }
978
+ catch {
979
+ return null;
980
+ }
981
+ }
982
+ // ===== Phase 3: Feedback recording =====
983
+ /**
984
+ * Record task feedback for learning via ReasoningBank or LearningSystem.
985
+ * Wired into hooks_post-task handler.
986
+ */
987
+ export async function bridgeRecordFeedback(options) {
988
+ const registry = await getRegistry(options.dbPath);
989
+ if (!registry)
990
+ return null;
991
+ try {
992
+ let controller = 'none';
993
+ let updated = 0;
994
+ // Try LearningSystem first (Phase 4)
995
+ const learningSystem = registry.get('learningSystem');
996
+ if (learningSystem) {
997
+ try {
998
+ if (typeof learningSystem.recordFeedback === 'function') {
999
+ await learningSystem.recordFeedback({
1000
+ taskId: options.taskId, success: options.success, quality: options.quality,
1001
+ agent: options.agent, duration: options.duration, timestamp: Date.now(),
1002
+ });
1003
+ controller = 'learningSystem';
1004
+ updated++;
1005
+ }
1006
+ else if (typeof learningSystem.record === 'function') {
1007
+ await learningSystem.record(options.taskId, options.quality, options.success ? 'success' : 'failure');
1008
+ controller = 'learningSystem';
1009
+ updated++;
1010
+ }
1011
+ }
1012
+ catch { /* API mismatch — skip */ }
1013
+ }
1014
+ // Also record in ReasoningBank for pattern reinforcement
1015
+ const reasoningBank = registry.get('reasoningBank');
1016
+ if (reasoningBank) {
1017
+ try {
1018
+ if (typeof reasoningBank.recordOutcome === 'function') {
1019
+ await reasoningBank.recordOutcome({
1020
+ taskId: options.taskId, verdict: options.success ? 'success' : 'failure',
1021
+ score: options.quality, timestamp: Date.now(),
1022
+ });
1023
+ controller = controller === 'none' ? 'reasoningBank' : `${controller}+reasoningBank`;
1024
+ updated++;
1025
+ }
1026
+ else if (typeof reasoningBank.record === 'function') {
1027
+ await reasoningBank.record(options.taskId, options.quality);
1028
+ controller = controller === 'none' ? 'reasoningBank' : `${controller}+reasoningBank`;
1029
+ updated++;
1030
+ }
1031
+ }
1032
+ catch { /* API mismatch — skip */ }
1033
+ }
1034
+ // Phase 4: SkillLibrary promotion for high-quality patterns
1035
+ if (options.success && options.quality >= 0.9 && options.patterns?.length) {
1036
+ const skills = registry.get('skills');
1037
+ if (skills && typeof skills.promote === 'function') {
1038
+ for (const pattern of options.patterns) {
1039
+ try {
1040
+ await skills.promote(pattern, options.quality);
1041
+ updated++;
1042
+ }
1043
+ catch { /* skip */ }
1044
+ }
1045
+ controller += '+skills';
1046
+ }
1047
+ }
1048
+ // Always store feedback as a memory entry for retrieval (ensures it persists)
1049
+ const storeResult = await bridgeStoreEntry({
1050
+ key: `feedback-${options.taskId}`,
1051
+ value: JSON.stringify(options),
1052
+ namespace: 'feedback',
1053
+ tags: [options.success ? 'success' : 'failure', options.agent || 'unknown'],
1054
+ dbPath: options.dbPath,
1055
+ });
1056
+ if (storeResult?.success) {
1057
+ controller = controller === 'none' ? 'bridge-store' : `${controller}+bridge-store`;
1058
+ updated++;
1059
+ }
1060
+ return { success: true, controller, updated };
1061
+ }
1062
+ catch {
1063
+ return null;
1064
+ }
1065
+ }
1066
+ // ===== Phase 3: CausalMemoryGraph =====
1067
+ /**
1068
+ * Record a causal edge between two entries (e.g., task → result).
1069
+ */
1070
+ export async function bridgeRecordCausalEdge(options) {
1071
+ const registry = await getRegistry(options.dbPath);
1072
+ if (!registry)
1073
+ return null;
1074
+ try {
1075
+ const causalGraph = registry.get('causalGraph');
1076
+ if (causalGraph && typeof causalGraph.addEdge === 'function') {
1077
+ causalGraph.addEdge(options.sourceId, options.targetId, {
1078
+ relation: options.relation,
1079
+ weight: options.weight ?? 1.0,
1080
+ timestamp: Date.now(),
1081
+ });
1082
+ return { success: true, controller: 'causalGraph' };
1083
+ }
1084
+ // Fallback: store edge as metadata
1085
+ const ctx = getDb(registry);
1086
+ if (ctx) {
1087
+ try {
1088
+ ctx.db.prepare(`
1089
+ INSERT OR REPLACE INTO memory_entries (id, key, namespace, content, type, created_at, updated_at, status)
1090
+ VALUES (?, ?, 'causal-edges', ?, 'procedural', ?, ?, 'active')
1091
+ `).run(generateId('edge'), `${options.sourceId}→${options.targetId}`, JSON.stringify(options), Date.now(), Date.now());
1092
+ return { success: true, controller: 'bridge-fallback' };
1093
+ }
1094
+ catch { /* skip */ }
1095
+ }
1096
+ return null;
1097
+ }
1098
+ catch {
1099
+ return null;
1100
+ }
1101
+ }
1102
+ // ===== Phase 5: ReflexionMemory session lifecycle =====
1103
+ /**
1104
+ * Start a session with ReflexionMemory episodic replay.
1105
+ * Loads relevant past session patterns for the new session.
1106
+ */
1107
+ export async function bridgeSessionStart(options) {
1108
+ const registry = await getRegistry(options.dbPath);
1109
+ if (!registry)
1110
+ return null;
1111
+ try {
1112
+ let restoredPatterns = 0;
1113
+ let controller = 'none';
1114
+ // Try ReflexionMemory for episodic session replay
1115
+ const reflexion = registry.get('reflexion');
1116
+ if (reflexion && typeof reflexion.startEpisode === 'function') {
1117
+ await reflexion.startEpisode(options.sessionId, { context: options.context });
1118
+ controller = 'reflexion';
1119
+ }
1120
+ // Load recent patterns from past sessions
1121
+ const searchResult = await bridgeSearchEntries({
1122
+ query: options.context || 'session patterns',
1123
+ namespace: 'session',
1124
+ limit: 10,
1125
+ threshold: 0.2,
1126
+ dbPath: options.dbPath,
1127
+ });
1128
+ if (searchResult?.results) {
1129
+ restoredPatterns = searchResult.results.length;
1130
+ }
1131
+ return {
1132
+ success: true,
1133
+ controller: controller === 'none' ? 'bridge-search' : controller,
1134
+ restoredPatterns,
1135
+ sessionId: options.sessionId,
1136
+ };
1137
+ }
1138
+ catch {
1139
+ return null;
1140
+ }
1141
+ }
1142
+ /**
1143
+ * End a session and persist episodic summary to ReflexionMemory.
1144
+ */
1145
+ export async function bridgeSessionEnd(options) {
1146
+ const registry = await getRegistry(options.dbPath);
1147
+ if (!registry)
1148
+ return null;
1149
+ try {
1150
+ let controller = 'none';
1151
+ let persisted = false;
1152
+ // End episode in ReflexionMemory
1153
+ const reflexion = registry.get('reflexion');
1154
+ if (reflexion && typeof reflexion.endEpisode === 'function') {
1155
+ await reflexion.endEpisode(options.sessionId, {
1156
+ summary: options.summary,
1157
+ tasksCompleted: options.tasksCompleted,
1158
+ patternsLearned: options.patternsLearned,
1159
+ });
1160
+ controller = 'reflexion';
1161
+ persisted = true;
1162
+ }
1163
+ // Persist session summary as memory entry
1164
+ await bridgeStoreEntry({
1165
+ key: `session-${options.sessionId}`,
1166
+ value: JSON.stringify({
1167
+ sessionId: options.sessionId,
1168
+ summary: options.summary || 'Session ended',
1169
+ tasksCompleted: options.tasksCompleted ?? 0,
1170
+ patternsLearned: options.patternsLearned ?? 0,
1171
+ endedAt: new Date().toISOString(),
1172
+ }),
1173
+ namespace: 'session',
1174
+ tags: ['session-end'],
1175
+ upsert: true,
1176
+ dbPath: options.dbPath,
1177
+ });
1178
+ if (controller === 'none')
1179
+ controller = 'bridge-store';
1180
+ persisted = true;
1181
+ // Phase 3: Trigger NightlyLearner consolidation if available
1182
+ const nightlyLearner = registry.get('nightlyLearner');
1183
+ if (nightlyLearner && typeof nightlyLearner.consolidate === 'function') {
1184
+ try {
1185
+ await nightlyLearner.consolidate({ sessionId: options.sessionId });
1186
+ controller += '+nightlyLearner';
1187
+ }
1188
+ catch { /* non-fatal */ }
1189
+ }
1190
+ return { success: true, controller, persisted };
1191
+ }
1192
+ catch {
1193
+ return null;
1194
+ }
1195
+ }
1196
+ // ===== Phase 5: SemanticRouter bridge =====
1197
+ /**
1198
+ * Route a task via AgentDB's SemanticRouter.
1199
+ * Returns null to fall back to local ruvector router.
1200
+ */
1201
+ export async function bridgeRouteTask(options) {
1202
+ const registry = await getRegistry(options.dbPath);
1203
+ if (!registry)
1204
+ return null;
1205
+ try {
1206
+ // Try AgentDB's SemanticRouter
1207
+ const semanticRouter = registry.get('semanticRouter');
1208
+ if (semanticRouter && typeof semanticRouter.route === 'function') {
1209
+ const result = await semanticRouter.route(options.task, { context: options.context });
1210
+ if (result) {
1211
+ return {
1212
+ route: result.route || result.category || 'general',
1213
+ confidence: result.confidence ?? result.score ?? 0.5,
1214
+ agents: result.agents || result.suggestedAgents || [],
1215
+ controller: 'semanticRouter',
1216
+ };
1217
+ }
1218
+ }
1219
+ // Try LearningSystem recommendAlgorithm (Phase 4)
1220
+ const learningSystem = registry.get('learningSystem');
1221
+ if (learningSystem && typeof learningSystem.recommendAlgorithm === 'function') {
1222
+ const rec = await learningSystem.recommendAlgorithm(options.task);
1223
+ if (rec) {
1224
+ return {
1225
+ route: rec.algorithm || rec.route || 'general',
1226
+ confidence: rec.confidence ?? 0.5,
1227
+ agents: rec.agents || [],
1228
+ controller: 'learningSystem',
1229
+ };
1230
+ }
1231
+ }
1232
+ return null; // Fall back to local router
1233
+ }
1234
+ catch {
1235
+ return null;
1236
+ }
1237
+ }
1238
+ // ===== Phase 4: Health check with attestation =====
1239
+ /**
1240
+ * Get comprehensive bridge health including all controller statuses.
1241
+ */
1242
+ export async function bridgeHealthCheck(dbPath) {
1243
+ const registry = await getRegistry(dbPath);
1244
+ if (!registry)
1245
+ return null;
1246
+ try {
1247
+ const controllers = registry.listControllers();
1248
+ // Phase 4: AttestationLog stats
1249
+ let attestationCount = 0;
1250
+ const attestation = registry.get('attestationLog');
1251
+ if (attestation && typeof attestation.count === 'function') {
1252
+ attestationCount = attestation.count();
1253
+ }
1254
+ // Phase 2: TieredCache stats
1255
+ let cacheStats = { size: 0, hits: 0, misses: 0 };
1256
+ const cache = registry.get('tieredCache');
1257
+ if (cache && typeof cache.stats === 'function') {
1258
+ const s = cache.stats();
1259
+ cacheStats = { size: s.size ?? 0, hits: s.hits ?? 0, misses: s.misses ?? 0 };
1260
+ }
1261
+ return { available: true, controllers, attestationCount, cacheStats };
1262
+ }
1263
+ catch {
1264
+ return null;
1265
+ }
1266
+ }
1267
+ // ===== Phase 7: Hierarchical memory, consolidation, batch, context, semantic route =====
1268
+ /**
1269
+ * Store to hierarchical memory with tier.
1270
+ * Valid tiers: working, episodic, semantic
1271
+ *
1272
+ * Real HierarchicalMemory API (agentdb alpha.10+):
1273
+ * store(content, importance?, tier?, options?) → Promise<string>
1274
+ * Stub API (fallback):
1275
+ * store(key, value, tier) — synchronous
1276
+ */
1277
+ export async function bridgeHierarchicalStore(params) {
1278
+ const registry = await getRegistry();
1279
+ if (!registry)
1280
+ return null;
1281
+ try {
1282
+ const hm = registry.get('hierarchicalMemory');
1283
+ if (!hm)
1284
+ return { success: false, error: 'HierarchicalMemory not available' };
1285
+ const tier = params.tier || 'working';
1286
+ // Detect real HierarchicalMemory (has async store returning id) vs stub
1287
+ if (typeof hm.getStats === 'function' && typeof hm.promote === 'function') {
1288
+ // Real agentdb HierarchicalMemory
1289
+ const id = await hm.store(params.value, params.importance || 0.5, tier, {
1290
+ metadata: { key: params.key },
1291
+ tags: [params.key],
1292
+ });
1293
+ return { success: true, id, key: params.key, tier };
1294
+ }
1295
+ // Stub fallback
1296
+ hm.store(params.key, params.value, tier);
1297
+ return { success: true, key: params.key, tier };
1298
+ }
1299
+ catch (e) {
1300
+ return { success: false, error: e.message };
1301
+ }
1302
+ }
1303
+ /**
1304
+ * Recall from hierarchical memory.
1305
+ *
1306
+ * Real HierarchicalMemory API (agentdb alpha.10+):
1307
+ * recall(query: MemoryQuery) → Promise<MemoryItem[]>
1308
+ * where MemoryQuery = { query, tier?, k?, threshold?, context?, includeDecayed? }
1309
+ * Stub API (fallback):
1310
+ * recall(query: string, topK: number) → synchronous array
1311
+ */
1312
+ export async function bridgeHierarchicalRecall(params) {
1313
+ const registry = await getRegistry();
1314
+ if (!registry)
1315
+ return null;
1316
+ try {
1317
+ const hm = registry.get('hierarchicalMemory');
1318
+ if (!hm)
1319
+ return { results: [], error: 'HierarchicalMemory not available' };
1320
+ // Detect real HierarchicalMemory vs stub
1321
+ if (typeof hm.getStats === 'function' && typeof hm.promote === 'function') {
1322
+ // Real agentdb HierarchicalMemory — recall takes MemoryQuery object
1323
+ const memoryQuery = {
1324
+ query: params.query,
1325
+ k: params.topK || 5,
1326
+ };
1327
+ if (params.tier) {
1328
+ memoryQuery.tier = params.tier;
1329
+ }
1330
+ const results = await hm.recall(memoryQuery);
1331
+ return { results: results || [], controller: 'hierarchicalMemory' };
1332
+ }
1333
+ // Stub fallback — recall(string, number)
1334
+ const results = hm.recall(params.query, params.topK || 5);
1335
+ const filtered = params.tier
1336
+ ? results.filter((r) => r.tier === params.tier)
1337
+ : results;
1338
+ return { results: filtered, controller: 'hierarchicalMemory' };
1339
+ }
1340
+ catch (e) {
1341
+ return { results: [], error: e.message };
1342
+ }
1343
+ }
1344
+ /**
1345
+ * Run memory consolidation.
1346
+ *
1347
+ * Real MemoryConsolidation API (agentdb alpha.10+):
1348
+ * consolidate() → Promise<ConsolidationReport>
1349
+ * ConsolidationReport = { episodicProcessed, semanticCreated, memoriesForgotten, ... }
1350
+ * Stub API (fallback):
1351
+ * consolidate() → { promoted, pruned, timestamp }
1352
+ */
1353
+ export async function bridgeConsolidate(params) {
1354
+ const registry = await getRegistry();
1355
+ if (!registry)
1356
+ return null;
1357
+ try {
1358
+ const mc = registry.get('memoryConsolidation');
1359
+ if (!mc)
1360
+ return { success: false, error: 'MemoryConsolidation not available' };
1361
+ const result = await mc.consolidate();
1362
+ return { success: true, consolidated: result };
1363
+ }
1364
+ catch (e) {
1365
+ return { success: false, error: e.message };
1366
+ }
1367
+ }
1368
+ /**
1369
+ * Batch operations (insert, update, delete).
1370
+ * - insert: calls insertEpisodes(entries) where entries are {content, metadata?}
1371
+ * - delete: calls bulkDelete(table, conditions) on episodes table
1372
+ * - update: calls bulkUpdate(table, updates, conditions) on episodes table
1373
+ */
1374
+ export async function bridgeBatchOperation(params) {
1375
+ const registry = await getRegistry();
1376
+ if (!registry)
1377
+ return null;
1378
+ try {
1379
+ const batch = registry.get('batchOperations');
1380
+ if (!batch)
1381
+ return { success: false, error: 'BatchOperations not available' };
1382
+ let result;
1383
+ switch (params.operation) {
1384
+ case 'insert': {
1385
+ // insertEpisodes expects [{content, metadata?, embedding?}]
1386
+ const episodes = params.entries.map((e) => ({
1387
+ content: e.value || e.content || JSON.stringify(e),
1388
+ metadata: e.metadata || { key: e.key },
1389
+ }));
1390
+ result = await batch.insertEpisodes(episodes);
1391
+ break;
1392
+ }
1393
+ case 'delete': {
1394
+ // bulkDelete(table, conditions) — conditions is a WHERE clause object
1395
+ const keys = params.entries.map((e) => e.key).filter(Boolean);
1396
+ for (const key of keys) {
1397
+ await batch.bulkDelete('episodes', { key });
1398
+ }
1399
+ result = { deleted: keys.length };
1400
+ break;
1401
+ }
1402
+ case 'update': {
1403
+ // bulkUpdate(table, updates, conditions)
1404
+ for (const entry of params.entries) {
1405
+ await batch.bulkUpdate('episodes', { content: entry.value || entry.content }, { key: entry.key });
1406
+ }
1407
+ result = { updated: params.entries.length };
1408
+ break;
1409
+ }
1410
+ default: return { success: false, error: `Unknown operation: ${params.operation}` };
1411
+ }
1412
+ return { success: true, operation: params.operation, count: params.entries.length, result };
1413
+ }
1414
+ catch (e) {
1415
+ return { success: false, error: e.message };
1416
+ }
1417
+ }
1418
+ /**
1419
+ * Synthesize context from memories.
1420
+ * ContextSynthesizer.synthesize is a static method that takes MemoryPattern[] (not a string).
1421
+ */
1422
+ export async function bridgeContextSynthesize(params) {
1423
+ const registry = await getRegistry();
1424
+ if (!registry)
1425
+ return null;
1426
+ try {
1427
+ const CS = registry.get('contextSynthesizer');
1428
+ if (!CS || typeof CS.synthesize !== 'function') {
1429
+ return { success: false, error: 'ContextSynthesizer not available' };
1430
+ }
1431
+ // Gather memory patterns from hierarchical memory as input
1432
+ const hm = registry.get('hierarchicalMemory');
1433
+ let memories = [];
1434
+ if (hm && typeof hm.recall === 'function') {
1435
+ // Detect real HierarchicalMemory (MemoryQuery object) vs stub (string, number)
1436
+ let recalled;
1437
+ if (typeof hm.promote === 'function') {
1438
+ // Real agentdb HierarchicalMemory
1439
+ recalled = await hm.recall({ query: params.query, k: params.maxEntries || 10 });
1440
+ }
1441
+ else {
1442
+ // Stub
1443
+ recalled = hm.recall(params.query, params.maxEntries || 10);
1444
+ }
1445
+ memories = (recalled || []).map((r) => ({
1446
+ content: r.value || r.content || '',
1447
+ key: r.key || r.id || '',
1448
+ reward: 1,
1449
+ verdict: 'success',
1450
+ }));
1451
+ }
1452
+ const result = CS.synthesize(memories, { includeRecommendations: true });
1453
+ return { success: true, synthesis: result };
1454
+ }
1455
+ catch (e) {
1456
+ return { success: false, error: e.message };
1457
+ }
1458
+ }
1459
+ /**
1460
+ * Route via SemanticRouter.
1461
+ * Available since agentdb 3.0.0-alpha.10 — uses @ruvector/router for
1462
+ * semantic matching with keyword fallback.
1463
+ */
1464
+ export async function bridgeSemanticRoute(params) {
1465
+ const registry = await getRegistry();
1466
+ if (!registry)
1467
+ return null;
1468
+ try {
1469
+ const router = registry.get('semanticRouter');
1470
+ if (!router)
1471
+ return { route: null, error: 'SemanticRouter not available' };
1472
+ const result = await router.route(params.input);
1473
+ return { route: result, controller: 'semanticRouter' };
1474
+ }
1475
+ catch (e) {
1476
+ return { route: null, error: e.message };
1477
+ }
1478
+ }
1479
+ // ===== Utility =====
1480
+ function cosineSim(a, b) {
1481
+ if (!a || !b || a.length === 0 || b.length === 0)
1482
+ return 0;
1483
+ const len = Math.min(a.length, b.length);
1484
+ let dot = 0, normA = 0, normB = 0;
1485
+ for (let i = 0; i < len; i++) {
1486
+ const ai = a[i], bi = b[i];
1487
+ dot += ai * bi;
1488
+ normA += ai * ai;
1489
+ normB += bi * bi;
1490
+ }
1491
+ const mag = Math.sqrt(normA * normB);
1492
+ return mag === 0 ? 0 : dot / mag;
1493
+ }
1494
+ //# sourceMappingURL=memory-bridge.js.map