moflo 4.8.25 → 4.8.26

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 (260) hide show
  1. package/.claude/agents/browser/browser-agent.yaml +182 -182
  2. package/.claude/agents/core/coder.md +265 -265
  3. package/.claude/agents/core/planner.md +167 -167
  4. package/.claude/agents/core/researcher.md +189 -189
  5. package/.claude/agents/core/reviewer.md +325 -325
  6. package/.claude/agents/core/tester.md +318 -318
  7. package/.claude/agents/database-specialist.yaml +21 -21
  8. package/.claude/agents/dual-mode/codex-coordinator.md +224 -224
  9. package/.claude/agents/dual-mode/codex-worker.md +211 -211
  10. package/.claude/agents/dual-mode/dual-orchestrator.md +291 -291
  11. package/.claude/agents/github/code-review-swarm.md +537 -537
  12. package/.claude/agents/github/github-modes.md +172 -172
  13. package/.claude/agents/github/issue-tracker.md +318 -318
  14. package/.claude/agents/github/multi-repo-swarm.md +552 -552
  15. package/.claude/agents/github/pr-manager.md +190 -190
  16. package/.claude/agents/github/project-board-sync.md +508 -508
  17. package/.claude/agents/github/release-manager.md +366 -366
  18. package/.claude/agents/github/release-swarm.md +582 -582
  19. package/.claude/agents/github/repo-architect.md +397 -397
  20. package/.claude/agents/github/swarm-issue.md +572 -572
  21. package/.claude/agents/github/swarm-pr.md +427 -427
  22. package/.claude/agents/github/sync-coordinator.md +451 -451
  23. package/.claude/agents/github/workflow-automation.md +634 -634
  24. package/.claude/agents/goal/code-goal-planner.md +445 -445
  25. package/.claude/agents/hive-mind/collective-intelligence-coordinator.md +129 -129
  26. package/.claude/agents/hive-mind/queen-coordinator.md +202 -202
  27. package/.claude/agents/hive-mind/scout-explorer.md +241 -241
  28. package/.claude/agents/hive-mind/swarm-memory-manager.md +192 -192
  29. package/.claude/agents/hive-mind/worker-specialist.md +216 -216
  30. package/.claude/agents/index.yaml +17 -17
  31. package/.claude/agents/neural/safla-neural.md +73 -73
  32. package/.claude/agents/project-coordinator.yaml +15 -15
  33. package/.claude/agents/python-specialist.yaml +21 -21
  34. package/.claude/agents/reasoning/goal-planner.md +72 -72
  35. package/.claude/agents/security-auditor.yaml +20 -20
  36. package/.claude/agents/swarm/adaptive-coordinator.md +395 -395
  37. package/.claude/agents/swarm/hierarchical-coordinator.md +326 -326
  38. package/.claude/agents/swarm/mesh-coordinator.md +391 -391
  39. package/.claude/agents/templates/migration-plan.md +745 -745
  40. package/.claude/agents/typescript-specialist.yaml +21 -21
  41. package/.claude/checkpoints/1767754460.json +8 -8
  42. package/.claude/commands/agents/agent-spawning.md +28 -28
  43. package/.claude/commands/github/github-modes.md +146 -146
  44. package/.claude/commands/github/github-swarm.md +121 -121
  45. package/.claude/commands/github/issue-tracker.md +291 -291
  46. package/.claude/commands/github/pr-manager.md +169 -169
  47. package/.claude/commands/github/release-manager.md +337 -337
  48. package/.claude/commands/github/repo-architect.md +366 -366
  49. package/.claude/commands/github/sync-coordinator.md +300 -300
  50. package/.claude/commands/memory/neural.md +47 -47
  51. package/.claude/commands/sparc/analyzer.md +51 -51
  52. package/.claude/commands/sparc/architect.md +53 -53
  53. package/.claude/commands/sparc/ask.md +97 -97
  54. package/.claude/commands/sparc/batch-executor.md +54 -54
  55. package/.claude/commands/sparc/code.md +89 -89
  56. package/.claude/commands/sparc/coder.md +54 -54
  57. package/.claude/commands/sparc/debug.md +83 -83
  58. package/.claude/commands/sparc/debugger.md +54 -54
  59. package/.claude/commands/sparc/designer.md +53 -53
  60. package/.claude/commands/sparc/devops.md +109 -109
  61. package/.claude/commands/sparc/docs-writer.md +80 -80
  62. package/.claude/commands/sparc/documenter.md +54 -54
  63. package/.claude/commands/sparc/innovator.md +54 -54
  64. package/.claude/commands/sparc/integration.md +83 -83
  65. package/.claude/commands/sparc/mcp.md +117 -117
  66. package/.claude/commands/sparc/memory-manager.md +54 -54
  67. package/.claude/commands/sparc/optimizer.md +54 -54
  68. package/.claude/commands/sparc/orchestrator.md +131 -131
  69. package/.claude/commands/sparc/post-deployment-monitoring-mode.md +83 -83
  70. package/.claude/commands/sparc/refinement-optimization-mode.md +83 -83
  71. package/.claude/commands/sparc/researcher.md +54 -54
  72. package/.claude/commands/sparc/reviewer.md +54 -54
  73. package/.claude/commands/sparc/security-review.md +80 -80
  74. package/.claude/commands/sparc/sparc-modes.md +174 -174
  75. package/.claude/commands/sparc/sparc.md +111 -111
  76. package/.claude/commands/sparc/spec-pseudocode.md +80 -80
  77. package/.claude/commands/sparc/supabase-admin.md +348 -348
  78. package/.claude/commands/sparc/swarm-coordinator.md +54 -54
  79. package/.claude/commands/sparc/tdd.md +54 -54
  80. package/.claude/commands/sparc/tester.md +54 -54
  81. package/.claude/commands/sparc/tutorial.md +79 -79
  82. package/.claude/commands/sparc/workflow-manager.md +54 -54
  83. package/.claude/commands/sparc.md +166 -166
  84. package/.claude/commands/swarm/analysis.md +95 -95
  85. package/.claude/commands/swarm/development.md +96 -96
  86. package/.claude/commands/swarm/examples.md +168 -168
  87. package/.claude/commands/swarm/maintenance.md +102 -102
  88. package/.claude/commands/swarm/optimization.md +117 -117
  89. package/.claude/commands/swarm/research.md +136 -136
  90. package/.claude/commands/swarm/testing.md +131 -131
  91. package/.claude/commands/workflows/development.md +77 -77
  92. package/.claude/commands/workflows/research.md +62 -62
  93. package/.claude/guidance/moflo-bootstrap.md +126 -126
  94. package/.claude/guidance/shipped/agent-bootstrap.md +143 -131
  95. package/.claude/guidance/shipped/guidance-memory-strategy.md +262 -262
  96. package/.claude/guidance/shipped/memory-strategy.md +204 -204
  97. package/.claude/guidance/shipped/moflo.md +675 -668
  98. package/.claude/guidance/shipped/task-swarm-integration.md +441 -441
  99. package/.claude/helpers/intelligence.cjs +207 -207
  100. package/.claude/helpers/statusline.cjs +851 -851
  101. package/.claude/skills/fl/SKILL.md +583 -583
  102. package/.claude/skills/flo/SKILL.md +583 -583
  103. package/.claude/skills/github-code-review/SKILL.md +1140 -1140
  104. package/.claude/skills/github-multi-repo/SKILL.md +874 -874
  105. package/.claude/skills/github-project-management/SKILL.md +1277 -1277
  106. package/.claude/skills/github-release-management/SKILL.md +1081 -1081
  107. package/.claude/skills/github-workflow-automation/SKILL.md +1065 -1065
  108. package/.claude/skills/hive-mind-advanced/SKILL.md +712 -712
  109. package/.claude/skills/hooks-automation/SKILL.md +1201 -1201
  110. package/.claude/skills/performance-analysis/SKILL.md +563 -563
  111. package/.claude/skills/sparc-methodology/SKILL.md +1115 -1115
  112. package/.claude/skills/swarm-advanced/SKILL.md +973 -973
  113. package/.claude/workflow-state.json +5 -5
  114. package/LICENSE +21 -21
  115. package/README.md +685 -698
  116. package/bin/cli.js +0 -0
  117. package/bin/gate-hook.mjs +50 -50
  118. package/bin/gate.cjs +138 -138
  119. package/bin/generate-code-map.mjs +937 -775
  120. package/bin/hook-handler.cjs +83 -83
  121. package/bin/hooks.mjs +696 -656
  122. package/bin/index-guidance.mjs +892 -892
  123. package/bin/index-tests.mjs +709 -709
  124. package/bin/lib/process-manager.mjs +256 -243
  125. package/bin/lib/registry-cleanup.cjs +41 -41
  126. package/bin/prompt-hook.mjs +72 -72
  127. package/bin/semantic-search.mjs +472 -472
  128. package/bin/session-start-launcher.mjs +238 -238
  129. package/bin/setup-project.mjs +251 -253
  130. package/package.json +123 -123
  131. package/src/@claude-flow/cli/README.md +452 -452
  132. package/src/@claude-flow/cli/bin/cli.js +180 -180
  133. package/src/@claude-flow/cli/bin/preinstall.cjs +2 -2
  134. package/src/@claude-flow/cli/dist/src/commands/completions.js +409 -409
  135. package/src/@claude-flow/cli/dist/src/commands/doctor.js +2 -18
  136. package/src/@claude-flow/cli/dist/src/commands/embeddings.js +25 -25
  137. package/src/@claude-flow/cli/dist/src/commands/github.js +61 -61
  138. package/src/@claude-flow/cli/dist/src/commands/hive-mind.js +90 -90
  139. package/src/@claude-flow/cli/dist/src/commands/hooks.js +9 -9
  140. package/src/@claude-flow/cli/dist/src/commands/init.js +8 -3
  141. package/src/@claude-flow/cli/dist/src/commands/ruvector/import.js +14 -14
  142. package/src/@claude-flow/cli/dist/src/commands/ruvector/setup.js +624 -624
  143. package/src/@claude-flow/cli/dist/src/config/moflo-config.d.ts +0 -3
  144. package/src/@claude-flow/cli/dist/src/config/moflo-config.js +91 -101
  145. package/src/@claude-flow/cli/dist/src/index.d.ts +0 -5
  146. package/src/@claude-flow/cli/dist/src/index.js +0 -44
  147. package/src/@claude-flow/cli/dist/src/init/claudemd-generator.d.ts +29 -29
  148. package/src/@claude-flow/cli/dist/src/init/claudemd-generator.js +43 -45
  149. package/src/@claude-flow/cli/dist/src/init/executor.js +453 -453
  150. package/src/@claude-flow/cli/dist/src/init/helpers-generator.js +482 -482
  151. package/src/@claude-flow/cli/dist/src/init/moflo-init.d.ts +30 -30
  152. package/src/@claude-flow/cli/dist/src/init/moflo-init.js +144 -200
  153. package/src/@claude-flow/cli/dist/src/init/statusline-generator.js +876 -876
  154. package/src/@claude-flow/cli/dist/src/mcp-tools/hooks-tools.js +11 -5
  155. package/src/@claude-flow/cli/dist/src/memory/memory-initializer.js +371 -371
  156. package/src/@claude-flow/cli/dist/src/runtime/headless.js +28 -28
  157. package/src/@claude-flow/cli/dist/src/services/daemon-lock.d.ts +0 -14
  158. package/src/@claude-flow/cli/dist/src/services/daemon-lock.js +1 -1
  159. package/src/@claude-flow/cli/dist/src/services/headless-worker-executor.js +84 -84
  160. package/src/@claude-flow/cli/package.json +1 -1
  161. package/src/@claude-flow/guidance/README.md +1195 -1195
  162. package/src/@claude-flow/guidance/package.json +198 -198
  163. package/src/@claude-flow/memory/README.md +587 -587
  164. package/src/@claude-flow/memory/dist/agentdb-backend.js +26 -26
  165. package/src/@claude-flow/memory/dist/auto-memory-bridge.test.js +27 -27
  166. package/src/@claude-flow/memory/dist/sqljs-backend.js +26 -26
  167. package/src/@claude-flow/memory/package.json +44 -44
  168. package/src/@claude-flow/shared/README.md +323 -323
  169. package/src/@claude-flow/shared/dist/events/event-store.js +31 -31
  170. package/src/README.md +493 -493
  171. package/.claude/agents/flow-nexus/app-store.md +0 -88
  172. package/.claude/agents/flow-nexus/authentication.md +0 -69
  173. package/.claude/agents/flow-nexus/challenges.md +0 -81
  174. package/.claude/agents/flow-nexus/neural-network.md +0 -88
  175. package/.claude/agents/flow-nexus/payments.md +0 -83
  176. package/.claude/agents/flow-nexus/sandbox.md +0 -76
  177. package/.claude/agents/flow-nexus/swarm.md +0 -76
  178. package/.claude/agents/flow-nexus/user-tools.md +0 -96
  179. package/.claude/agents/flow-nexus/workflow.md +0 -84
  180. package/.claude/agents/payments/agentic-payments.md +0 -126
  181. package/.claude/agents/sona/sona-learning-optimizer.md +0 -74
  182. package/.claude/agents/sublinear/consensus-coordinator.md +0 -338
  183. package/.claude/agents/sublinear/matrix-optimizer.md +0 -185
  184. package/.claude/agents/sublinear/pagerank-analyzer.md +0 -299
  185. package/.claude/agents/sublinear/performance-optimizer.md +0 -368
  186. package/.claude/agents/sublinear/trading-predictor.md +0 -246
  187. package/.claude/agents/v3/adr-architect.md +0 -184
  188. package/.claude/agents/v3/aidefence-guardian.md +0 -282
  189. package/.claude/agents/v3/claims-authorizer.md +0 -208
  190. package/.claude/agents/v3/collective-intelligence-coordinator.md +0 -993
  191. package/.claude/agents/v3/ddd-domain-expert.md +0 -220
  192. package/.claude/agents/v3/injection-analyst.md +0 -236
  193. package/.claude/agents/v3/memory-specialist.md +0 -995
  194. package/.claude/agents/v3/performance-engineer.md +0 -1233
  195. package/.claude/agents/v3/pii-detector.md +0 -151
  196. package/.claude/agents/v3/reasoningbank-learner.md +0 -213
  197. package/.claude/agents/v3/security-architect-aidefence.md +0 -410
  198. package/.claude/agents/v3/security-architect.md +0 -867
  199. package/.claude/agents/v3/security-auditor.md +0 -771
  200. package/.claude/agents/v3/sparc-orchestrator.md +0 -182
  201. package/.claude/agents/v3/swarm-memory-manager.md +0 -157
  202. package/.claude/agents/v3/v3-integration-architect.md +0 -205
  203. package/.claude/commands/analysis/COMMAND_COMPLIANCE_REPORT.md +0 -54
  204. package/.claude/commands/analysis/README.md +0 -9
  205. package/.claude/commands/analysis/bottleneck-detect.md +0 -162
  206. package/.claude/commands/analysis/performance-bottlenecks.md +0 -59
  207. package/.claude/commands/analysis/performance-report.md +0 -25
  208. package/.claude/commands/analysis/token-efficiency.md +0 -45
  209. package/.claude/commands/analysis/token-usage.md +0 -25
  210. package/.claude/commands/automation/README.md +0 -9
  211. package/.claude/commands/automation/auto-agent.md +0 -122
  212. package/.claude/commands/automation/self-healing.md +0 -106
  213. package/.claude/commands/automation/session-memory.md +0 -90
  214. package/.claude/commands/automation/smart-agents.md +0 -73
  215. package/.claude/commands/automation/smart-spawn.md +0 -25
  216. package/.claude/commands/automation/workflow-select.md +0 -25
  217. package/.claude/commands/monitoring/README.md +0 -9
  218. package/.claude/commands/monitoring/agent-metrics.md +0 -25
  219. package/.claude/commands/monitoring/agents.md +0 -44
  220. package/.claude/commands/monitoring/real-time-view.md +0 -25
  221. package/.claude/commands/monitoring/status.md +0 -46
  222. package/.claude/commands/monitoring/swarm-monitor.md +0 -25
  223. package/.claude/commands/optimization/README.md +0 -9
  224. package/.claude/commands/optimization/auto-topology.md +0 -62
  225. package/.claude/commands/optimization/cache-manage.md +0 -25
  226. package/.claude/commands/optimization/parallel-execute.md +0 -25
  227. package/.claude/commands/optimization/parallel-execution.md +0 -50
  228. package/.claude/commands/optimization/topology-optimize.md +0 -25
  229. package/.claude/guidance/shipped/task-icons.md +0 -42
  230. package/.claude/helpers/gate-hook.mjs +0 -50
  231. package/.claude/helpers/gate.cjs +0 -138
  232. package/.claude/helpers/hook-handler.cjs +0 -76
  233. package/.claude/helpers/prompt-hook.mjs +0 -72
  234. package/.claude/scripts/build-embeddings.mjs +0 -549
  235. package/.claude/scripts/generate-code-map.mjs +0 -776
  236. package/.claude/scripts/hooks.mjs +0 -656
  237. package/.claude/scripts/index-guidance.mjs +0 -893
  238. package/.claude/scripts/index-tests.mjs +0 -710
  239. package/.claude/scripts/semantic-search.mjs +0 -473
  240. package/.claude/scripts/session-start-launcher.mjs +0 -238
  241. package/.claude/settings.local.json +0 -18
  242. package/.claude/skills/pair-programming/SKILL.md +0 -1202
  243. package/.claude/skills/stream-chain/SKILL.md +0 -563
  244. package/.claude/skills/v3-cli-modernization/SKILL.md +0 -872
  245. package/.claude/skills/v3-core-implementation/SKILL.md +0 -797
  246. package/.claude/skills/v3-ddd-architecture/SKILL.md +0 -442
  247. package/.claude/skills/v3-integration-deep/SKILL.md +0 -241
  248. package/.claude/skills/v3-mcp-optimization/SKILL.md +0 -777
  249. package/.claude/skills/v3-memory-unification/SKILL.md +0 -174
  250. package/.claude/skills/v3-performance-optimization/SKILL.md +0 -390
  251. package/.claude/skills/v3-security-overhaul/SKILL.md +0 -82
  252. package/.claude/skills/v3-swarm-coordination/SKILL.md +0 -340
  253. package/src/@claude-flow/cli/dist/src/services/container-worker-pool.d.ts +0 -197
  254. package/src/@claude-flow/cli/dist/src/services/container-worker-pool.js +0 -584
  255. package/src/@claude-flow/memory/dist/hybrid-backend.d.ts +0 -245
  256. package/src/@claude-flow/memory/dist/hybrid-backend.js +0 -569
  257. package/src/@claude-flow/memory/dist/hybrid-backend.test.d.ts +0 -8
  258. package/src/@claude-flow/memory/dist/hybrid-backend.test.js +0 -320
  259. package/src/@claude-flow/memory/dist/sqlite-backend.d.ts +0 -121
  260. package/src/@claude-flow/memory/dist/sqlite-backend.js +0 -572
@@ -1,549 +0,0 @@
1
- #!/usr/bin/env node
2
- /**
3
- * Generate embeddings for all memory entries and build HNSW index
4
- *
5
- * Embedding Strategy (in order of preference):
6
- * 1. Transformers.js with all-MiniLM-L6-v2 (best quality, requires sharp)
7
- * 2. Domain-aware semantic hash embeddings (fast, good quality, no deps)
8
- *
9
- * The domain-aware hash embeddings use:
10
- * - Domain clustering for semantic grouping (database, frontend, backend, testing, etc.)
11
- * - SimHash-style word encoding with multiple hash positions
12
- * - N-gram features (bigrams, trigrams) for phrase detection
13
- * - L2 normalization for cosine similarity
14
- *
15
- * Usage:
16
- * node node_modules/moflo/bin/build-embeddings.mjs # Embed entries without embeddings
17
- * npx flo-embeddings --force # Re-embed all entries
18
- * npx flo-embeddings --namespace guidance # Only specific namespace
19
- */
20
-
21
- import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'fs';
22
- import { resolve, dirname } from 'path';
23
- import { mofloResolveURL } from './lib/moflo-resolve.mjs';
24
- const initSqlJs = (await import(mofloResolveURL('sql.js'))).default;
25
-
26
- function findProjectRoot() {
27
- let dir = process.cwd();
28
- const root = resolve(dir, '/');
29
- while (dir !== root) {
30
- if (existsSync(resolve(dir, 'package.json'))) return dir;
31
- dir = dirname(dir);
32
- }
33
- return process.cwd();
34
- }
35
-
36
- const projectRoot = findProjectRoot();
37
-
38
- const DB_PATH = resolve(projectRoot, '.swarm/memory.db');
39
-
40
- // Embedding config
41
- const EMBEDDING_MODEL_NEURAL = 'Xenova/all-MiniLM-L6-v2';
42
- const EMBEDDING_MODEL_HASH = 'domain-aware-hash-v1';
43
- const EMBEDDING_DIMS = 384;
44
- const BATCH_SIZE = 100;
45
-
46
- // Parse args
47
- const args = process.argv.slice(2);
48
- const force = args.includes('--force');
49
- const namespaceFilter = args.includes('--namespace')
50
- ? args[args.indexOf('--namespace') + 1]
51
- : null;
52
- const verbose = args.includes('--verbose') || args.includes('-v');
53
-
54
- let pipeline = null;
55
- let useTransformers = false;
56
- let embeddingModel = EMBEDDING_MODEL_HASH;
57
-
58
- function log(msg) {
59
- console.log(`[build-embeddings] ${msg}`);
60
- }
61
-
62
- function debug(msg) {
63
- if (verbose) console.log(`[build-embeddings] ${msg}`);
64
- }
65
-
66
- // ============================================================================
67
- // Domain-Aware Semantic Hash Embeddings
68
- // ============================================================================
69
-
70
- // Domain clusters for semantic grouping
71
- const DOMAIN_CLUSTERS = {
72
- database: ['typeorm', 'mongodb', 'database', 'entity', 'schema', 'table', 'collection',
73
- 'query', 'sql', 'nosql', 'orm', 'model', 'migration', 'repository', 'column',
74
- 'relation', 'foreign', 'primary', 'index', 'constraint', 'transaction'],
75
- frontend: ['react', 'component', 'ui', 'styling', 'css', 'html', 'jsx', 'tsx', 'frontend',
76
- 'material', 'mui', 'tailwind', 'dom', 'render', 'hook', 'state', 'props',
77
- 'redux', 'context', 'styled', 'emotion', 'theme', 'layout', 'responsive'],
78
- backend: ['fastify', 'api', 'route', 'handler', 'rest', 'endpoint', 'server', 'controller',
79
- 'middleware', 'request', 'response', 'http', 'express', 'nest', 'graphql',
80
- 'websocket', 'socket', 'cors', 'auth', 'jwt', 'session', 'cookie'],
81
- testing: ['test', 'testing', 'vitest', 'jest', 'mock', 'spy', 'assert', 'expect', 'describe',
82
- 'it', 'spec', 'unit', 'integration', 'e2e', 'playwright', 'cypress', 'coverage',
83
- 'fixture', 'stub', 'fake', 'snapshot', 'beforeeach', 'aftereach'],
84
- tenancy: ['tenant', 'tenancy', 'companyid', 'company', 'isolation', 'multi', 'multitenant',
85
- 'organization', 'workspace', 'account', 'customer', 'client'],
86
- security: ['security', 'auth', 'authentication', 'authorization', 'permission', 'role',
87
- 'access', 'token', 'jwt', 'oauth', 'password', 'encrypt', 'hash', 'salt',
88
- 'csrf', 'xss', 'injection', 'sanitize', 'validate'],
89
- patterns: ['pattern', 'service', 'factory', 'singleton', 'decorator', 'adapter', 'facade',
90
- 'observer', 'strategy', 'command', 'repository', 'usecase', 'domain', 'ddd',
91
- 'clean', 'architecture', 'solid', 'dry', 'kiss'],
92
- workflow: ['workflow', 'pipeline', 'ci', 'cd', 'deploy', 'build', 'actions',
93
- 'hook', 'trigger', 'job', 'step', 'artifact', 'release', 'version', 'tag'],
94
- memory: ['memory', 'cache', 'store', 'persist', 'storage', 'redis', 'session', 'state',
95
- 'buffer', 'queue', 'stack', 'heap', 'gc', 'leak', 'embedding', 'vector', 'hnsw',
96
- 'semantic', 'search', 'index', 'retrieval'],
97
- agent: ['agent', 'swarm', 'coordinator', 'orchestrator', 'task', 'worker', 'spawn',
98
- 'parallel', 'concurrent', 'async', 'promise', 'queue', 'priority', 'schedule'],
99
- github: ['github', 'issue', 'branch', 'pr', 'pull', 'request', 'merge', 'commit', 'push',
100
- 'clone', 'fork', 'remote', 'origin', 'main', 'master', 'checkout', 'rebase',
101
- 'squash', 'repository', 'repo', 'gh', 'git', 'assignee', 'label', 'mandatory',
102
- 'checklist', 'closes', 'fixes', 'conventional', 'feat', 'refactor'],
103
- documentation: ['guidance', 'documentation', 'docs', 'readme', 'guide', 'tutorial',
104
- 'reference', 'standard', 'convention', 'rule', 'policy', 'template',
105
- 'example', 'usage', 'instruction', 'meta', 'index', 'umbrella', 'claude',
106
- 'optimized', 'audience', 'structure', 'format', 'markdown']
107
- };
108
-
109
- // Common words to downweight
110
- const COMMON_WORDS = new Set([
111
- 'the', 'a', 'an', 'is', 'are', 'was', 'were', 'be', 'been', 'being', 'have', 'has', 'had',
112
- 'do', 'does', 'did', 'will', 'would', 'could', 'should', 'may', 'might', 'must', 'shall',
113
- 'can', 'need', 'to', 'of', 'in', 'for', 'on', 'with', 'at', 'by', 'from', 'as', 'into',
114
- 'through', 'during', 'before', 'after', 'above', 'below', 'between', 'under', 'and', 'but',
115
- 'or', 'nor', 'so', 'yet', 'both', 'either', 'neither', 'not', 'only', 'own', 'same', 'than',
116
- 'too', 'very', 'just', 'also', 'this', 'that', 'these', 'those', 'it', 'its', 'if', 'then',
117
- 'else', 'when', 'where', 'why', 'how', 'all', 'each', 'every', 'any', 'some', 'no', 'yes',
118
- 'use', 'using', 'used', 'uses', 'get', 'set', 'new', 'see', 'like', 'make', 'made'
119
- ]);
120
-
121
- // MurmurHash3-inspired hash function for better distribution
122
- function hash(str, seed = 0) {
123
- let h = seed ^ str.length;
124
- for (let i = 0; i < str.length; i++) {
125
- h ^= str.charCodeAt(i);
126
- h = Math.imul(h, 0x5bd1e995);
127
- h ^= h >>> 15;
128
- }
129
- return h >>> 0;
130
- }
131
-
132
- // Pre-compute domain signature vectors
133
- const domainSignatures = {};
134
- for (const [domain, keywords] of Object.entries(DOMAIN_CLUSTERS)) {
135
- const sig = new Float32Array(EMBEDDING_DIMS);
136
- for (const kw of keywords) {
137
- // Use multiple positions per keyword for robustness
138
- for (let h = 0; h < 2; h++) {
139
- const idx = hash(kw + '_dom_' + domain, h) % EMBEDDING_DIMS;
140
- sig[idx] = 1;
141
- }
142
- }
143
- domainSignatures[domain] = sig;
144
- }
145
-
146
- /**
147
- * Generate domain-aware semantic hash embedding
148
- * @param {string} text - Text to embed
149
- * @param {number} dims - Embedding dimensions
150
- * @returns {Float32Array} - Normalized embedding vector
151
- */
152
- function semanticHashEmbed(text, dims = EMBEDDING_DIMS) {
153
- const vec = new Float32Array(dims);
154
- const lowerText = text.toLowerCase();
155
- const words = lowerText.replace(/[^a-z0-9\s]/g, ' ').split(/\s+/).filter(w => w.length > 1);
156
-
157
- if (words.length === 0) {
158
- // Empty text - return zero vector (will have low similarity to everything)
159
- return vec;
160
- }
161
-
162
- // 1. Add domain signatures for matched domains
163
- for (const [domain, keywords] of Object.entries(DOMAIN_CLUSTERS)) {
164
- let matchCount = 0;
165
- for (const kw of keywords) {
166
- if (lowerText.includes(kw)) {
167
- matchCount++;
168
- }
169
- }
170
- if (matchCount > 0) {
171
- const weight = Math.min(2.0, 0.5 + matchCount * 0.3); // More matches = stronger signal
172
- const sig = domainSignatures[domain];
173
- for (let i = 0; i < dims; i++) {
174
- vec[i] += sig[i] * weight;
175
- }
176
- }
177
- }
178
-
179
- // 2. Add word features (simhash-style with multiple positions)
180
- for (let i = 0; i < words.length; i++) {
181
- const word = words[i];
182
- const isCommon = COMMON_WORDS.has(word);
183
- const weight = isCommon ? 0.2 : (word.length > 6 ? 0.8 : 0.5);
184
-
185
- // Multiple hash positions per word
186
- for (let h = 0; h < 3; h++) {
187
- const idx = hash(word, h * 17) % dims;
188
- const sign = (hash(word, h * 31 + 1) % 2 === 0) ? 1 : -1;
189
- vec[idx] += sign * weight;
190
- }
191
- }
192
-
193
- // 3. Add bigram features for local context
194
- for (let i = 0; i < words.length - 1; i++) {
195
- if (COMMON_WORDS.has(words[i]) && COMMON_WORDS.has(words[i + 1])) continue;
196
- const bigram = words[i] + '_' + words[i + 1];
197
- const idx = hash(bigram, 42) % dims;
198
- const sign = (hash(bigram, 43) % 2 === 0) ? 1 : -1;
199
- vec[idx] += sign * 0.4;
200
- }
201
-
202
- // 4. Add trigram features for phrase detection
203
- for (let i = 0; i < words.length - 2; i++) {
204
- const trigram = words[i] + '_' + words[i + 1] + '_' + words[i + 2];
205
- const idx = hash(trigram, 99) % dims;
206
- const sign = (hash(trigram, 100) % 2 === 0) ? 1 : -1;
207
- vec[idx] += sign * 0.3;
208
- }
209
-
210
- // 5. L2 normalize
211
- let norm = 0;
212
- for (let i = 0; i < dims; i++) norm += vec[i] * vec[i];
213
- norm = Math.sqrt(norm);
214
- if (norm > 0) {
215
- for (let i = 0; i < dims; i++) vec[i] /= norm;
216
- }
217
-
218
- return vec;
219
- }
220
-
221
- // ============================================================================
222
- // Transformers.js Neural Embeddings (fallback)
223
- // ============================================================================
224
-
225
- async function loadTransformersModel() {
226
- if (pipeline) return pipeline;
227
-
228
- log('Attempting to load Transformers.js neural model...');
229
-
230
- try {
231
- const { env, pipeline: createPipeline } = await import(mofloResolveURL('@xenova/transformers'));
232
- env.allowLocalModels = false;
233
- env.backends.onnx.wasm.numThreads = 1;
234
-
235
- pipeline = await createPipeline('feature-extraction', EMBEDDING_MODEL_NEURAL, {
236
- quantized: false,
237
- });
238
-
239
- useTransformers = true;
240
- embeddingModel = EMBEDDING_MODEL_NEURAL;
241
- log('Transformers.js model loaded successfully');
242
- return pipeline;
243
- } catch (err) {
244
- const errMsg = err.message?.split('\n')[0] || err.message;
245
- log(`Transformers.js not available: ${errMsg}`);
246
- log('Using domain-aware hash embeddings (fast, good quality)');
247
- useTransformers = false;
248
- embeddingModel = EMBEDDING_MODEL_HASH;
249
- return null;
250
- }
251
- }
252
-
253
- async function generateEmbeddingNeural(text) {
254
- if (!pipeline) return null;
255
- try {
256
- const output = await pipeline(text, { pooling: 'mean', normalize: true });
257
- return Array.from(output.data);
258
- } catch {
259
- return null;
260
- }
261
- }
262
-
263
- // ============================================================================
264
- // Database Operations
265
- // ============================================================================
266
-
267
- async function getDb() {
268
- if (!existsSync(DB_PATH)) {
269
- throw new Error(`Database not found: ${DB_PATH}`);
270
- }
271
- const SQL = await initSqlJs();
272
- const buffer = readFileSync(DB_PATH);
273
- return new SQL.Database(buffer);
274
- }
275
-
276
- function saveDb(db) {
277
- const data = db.export();
278
- writeFileSync(DB_PATH, Buffer.from(data));
279
- }
280
-
281
- function getEntriesNeedingEmbeddings(db, namespace = null, forceAll = false) {
282
- let sql = `SELECT id, key, namespace, content FROM memory_entries WHERE status = 'active'`;
283
- const params = [];
284
-
285
- if (!forceAll) {
286
- // Include entries with no embedding OR entries with hash/fallback embeddings
287
- // that should be upgraded to Xenova when available
288
- sql += ` AND (embedding IS NULL OR embedding = '' OR embedding_model IN ('domain-aware-hash-v1', 'hash-fallback', 'local'))`;
289
- }
290
-
291
- if (namespace) {
292
- sql += ` AND namespace = ?`;
293
- params.push(namespace);
294
- }
295
-
296
- sql += ` ORDER BY created_at DESC`;
297
-
298
- const stmt = db.prepare(sql);
299
- stmt.bind(params);
300
- const results = [];
301
- while (stmt.step()) results.push(stmt.getAsObject());
302
- stmt.free();
303
- return results;
304
- }
305
-
306
- function updateEmbedding(db, id, embedding, model) {
307
- const stmt = db.prepare(
308
- `UPDATE memory_entries SET embedding = ?, embedding_model = ?, embedding_dimensions = ?, updated_at = ? WHERE id = ?`
309
- );
310
- stmt.run([JSON.stringify(embedding), model, EMBEDDING_DIMS, Date.now(), id]);
311
- stmt.free();
312
- }
313
-
314
- function getNamespaceStats(db) {
315
- const stmt = db.prepare(`
316
- SELECT
317
- namespace,
318
- COUNT(*) as total,
319
- SUM(CASE WHEN embedding IS NOT NULL AND embedding != '' AND embedding_model != 'domain-aware-hash-v1' THEN 1 ELSE 0 END) as vectorized,
320
- SUM(CASE WHEN embedding IS NULL OR embedding = '' THEN 1 ELSE 0 END) as missing,
321
- SUM(CASE WHEN embedding_model = 'domain-aware-hash-v1' THEN 1 ELSE 0 END) as hash_only
322
- FROM memory_entries
323
- WHERE status = 'active'
324
- GROUP BY namespace
325
- ORDER BY namespace
326
- `);
327
- const results = [];
328
- while (stmt.step()) results.push(stmt.getAsObject());
329
- stmt.free();
330
- return results;
331
- }
332
-
333
- function getEmbeddingStats(db) {
334
- const stmtTotal = db.prepare(`SELECT COUNT(*) as cnt FROM memory_entries WHERE status = 'active'`);
335
- const total = stmtTotal.step() ? stmtTotal.getAsObject() : { cnt: 0 };
336
- stmtTotal.free();
337
-
338
- const stmtEmbed = db.prepare(`SELECT COUNT(*) as cnt FROM memory_entries WHERE status = 'active' AND embedding IS NOT NULL AND embedding != ''`);
339
- const withEmbed = stmtEmbed.step() ? stmtEmbed.getAsObject() : { cnt: 0 };
340
- stmtEmbed.free();
341
-
342
- const stmtModel = db.prepare(`SELECT embedding_model, COUNT(*) as cnt FROM memory_entries WHERE status = 'active' AND embedding IS NOT NULL GROUP BY embedding_model`);
343
- const byModel = [];
344
- while (stmtModel.step()) byModel.push(stmtModel.getAsObject());
345
- stmtModel.free();
346
-
347
- return {
348
- total: total?.cnt || 0,
349
- withEmbeddings: withEmbed?.cnt || 0,
350
- byModel
351
- };
352
- }
353
-
354
- // ============================================================================
355
- // Main
356
- // ============================================================================
357
-
358
- async function main() {
359
- console.log('');
360
- log('═══════════════════════════════════════════════════════════');
361
- log(' Embedding Generation for Memory Entries');
362
- log('═══════════════════════════════════════════════════════════');
363
- console.log('');
364
-
365
- const db = await getDb();
366
-
367
- // Get entries needing embeddings
368
- const entries = getEntriesNeedingEmbeddings(db, namespaceFilter, force);
369
-
370
- if (entries.length === 0) {
371
- log('All entries already have embeddings');
372
- const stats = getEmbeddingStats(db);
373
- log(`Total: ${stats.withEmbeddings}/${stats.total} entries embedded`);
374
-
375
- // Update vector-stats cache even on early exit
376
- try {
377
- const nsStats = getNamespaceStats(db);
378
- const dbSizeKB = Math.floor(readFileSync(DB_PATH).length / 1024);
379
- const hnswExists = existsSync(resolve(projectRoot, '.swarm', 'hnsw.index'))
380
- || existsSync(resolve(projectRoot, '.claude-flow', 'hnsw.index'));
381
- const cacheData = {
382
- vectorCount: stats.withEmbeddings,
383
- dbSizeKB,
384
- namespaces: nsStats.length,
385
- hasHnsw: hnswExists,
386
- updatedAt: Date.now(),
387
- };
388
- for (const cacheDir of [resolve(projectRoot, '.claude-flow'), resolve(projectRoot, '.swarm')]) {
389
- if (!existsSync(cacheDir)) mkdirSync(cacheDir, { recursive: true });
390
- writeFileSync(resolve(cacheDir, 'vector-stats.json'), JSON.stringify(cacheData));
391
- }
392
- } catch { /* non-fatal */ }
393
-
394
- db.close();
395
- return;
396
- }
397
-
398
- log(`Found ${entries.length} entries to embed`);
399
-
400
- // Try to load Transformers.js, fall back to hash embeddings
401
- await loadTransformersModel();
402
-
403
- log(`Using embedding model: ${embeddingModel}`);
404
- console.log('');
405
-
406
- let embedded = 0;
407
- let failed = 0;
408
- const startTime = Date.now();
409
-
410
- // Process entries
411
- for (let i = 0; i < entries.length; i++) {
412
- const entry = entries[i];
413
-
414
- try {
415
- // Truncate content for embedding (first 1500 chars for context)
416
- const text = entry.content.substring(0, 1500);
417
-
418
- let embedding;
419
- if (useTransformers && pipeline) {
420
- embedding = await generateEmbeddingNeural(text);
421
- }
422
-
423
- // Fall back to hash embedding if neural failed or not available
424
- if (!embedding || embedding.length !== EMBEDDING_DIMS) {
425
- embedding = Array.from(semanticHashEmbed(text));
426
- }
427
-
428
- if (embedding && embedding.length === EMBEDDING_DIMS) {
429
- updateEmbedding(db, entry.id, embedding, embeddingModel);
430
- embedded++;
431
- } else {
432
- failed++;
433
- }
434
-
435
- // Progress update
436
- if ((i + 1) % 50 === 0 || i === entries.length - 1) {
437
- const pct = Math.round(((i + 1) / entries.length) * 100);
438
- const elapsed = ((Date.now() - startTime) / 1000).toFixed(1);
439
- process.stdout.write(`\r[build-embeddings] Progress: ${i + 1}/${entries.length} (${pct}%) - ${elapsed}s elapsed`);
440
- }
441
- } catch (err) {
442
- debug(`Failed to embed ${entry.key}: ${err.message}`);
443
- failed++;
444
- }
445
- }
446
-
447
- console.log(''); // New line after progress
448
-
449
- const totalTime = ((Date.now() - startTime) / 1000).toFixed(1);
450
- const stats = getEmbeddingStats(db);
451
-
452
- // Write changes back to disk (sql.js operates in-memory)
453
- if (embedded > 0) {
454
- saveDb(db);
455
-
456
- // Delete stale HNSW index so the CLI rebuilds from fresh vectors
457
- const hnswPaths = [
458
- resolve(projectRoot, '.swarm/hnsw.index'),
459
- resolve(projectRoot, '.swarm/hnsw.metadata.json'),
460
- ];
461
- for (const p of hnswPaths) {
462
- if (existsSync(p)) {
463
- const { unlinkSync } = await import('fs');
464
- unlinkSync(p);
465
- log(`Deleted stale HNSW index: ${p}`);
466
- }
467
- }
468
- }
469
-
470
- console.log('');
471
- log('═══════════════════════════════════════════════════════════');
472
- log(' Embedding Generation Complete');
473
- log('═══════════════════════════════════════════════════════════');
474
- log(` Embedded: ${embedded} entries`);
475
- log(` Failed: ${failed} entries`);
476
- log(` Time: ${totalTime}s`);
477
- log(` Model: ${embeddingModel}`);
478
- log(` Dimensions: ${EMBEDDING_DIMS}`);
479
- log('');
480
- log(` Total Coverage: ${stats.withEmbeddings}/${stats.total} entries`);
481
- if (stats.byModel.length > 0) {
482
- log(' By Model:');
483
- for (const m of stats.byModel) {
484
- log(` - ${m.embedding_model}: ${m.cnt}`);
485
- }
486
- }
487
- log('');
488
-
489
- // Per-namespace health report
490
- const nsStats = getNamespaceStats(db);
491
- if (nsStats.length > 0) {
492
- log(' Namespace Health:');
493
- log(' ┌─────────────────┬───────┬────────────┬─────────┬───────────┐');
494
- log(' │ Namespace │ Total │ Vectorized │ Missing │ Hash-Only │');
495
- log(' ├─────────────────┼───────┼────────────┼─────────┼───────────┤');
496
- let hasWarnings = false;
497
- for (const ns of nsStats) {
498
- const name = String(ns.namespace).padEnd(15);
499
- const total = String(ns.total).padStart(5);
500
- const vectorized = String(ns.vectorized).padStart(10);
501
- const missing = String(ns.missing).padStart(7);
502
- const hashOnly = String(ns.hash_only).padStart(9);
503
- const warn = (ns.missing > 0 || ns.hash_only > 0) ? ' ⚠' : ' ';
504
- log(` │ ${name} │${total} │${vectorized} │${missing} │${hashOnly} │${warn}`);
505
- if (ns.missing > 0 || ns.hash_only > 0) hasWarnings = true;
506
- }
507
- log(' └─────────────────┴───────┴────────────┴─────────┴───────────┘');
508
- if (hasWarnings) {
509
- log('');
510
- log(' ⚠ Some namespaces have entries without Xenova embeddings.');
511
- log(' Run with --force to re-embed all entries:');
512
- log(' node node_modules/moflo/bin/build-embeddings.mjs --force');
513
- if (!useTransformers) {
514
- log('');
515
- log(' ⚠ Xenova model not available — using hash fallback.');
516
- log(' Install @xenova/transformers for neural embeddings:');
517
- log(' npm install @xenova/transformers');
518
- }
519
- }
520
- }
521
-
522
- log('═══════════════════════════════════════════════════════════');
523
-
524
- // Update vector-stats cache for statusline display
525
- try {
526
- const dbSizeKB = Math.floor(readFileSync(DB_PATH).length / 1024);
527
- const hnswExists = existsSync(resolve(projectRoot, '.swarm', 'hnsw.index'))
528
- || existsSync(resolve(projectRoot, '.claude-flow', 'hnsw.index'));
529
- const cacheData = {
530
- vectorCount: stats.withEmbeddings,
531
- dbSizeKB,
532
- namespaces: nsStats.length,
533
- hasHnsw: hnswExists,
534
- updatedAt: Date.now(),
535
- };
536
- // Write to both locations so statusline finds it regardless of which dir it checks
537
- for (const cacheDir of [resolve(projectRoot, '.claude-flow'), resolve(projectRoot, '.swarm')]) {
538
- if (!existsSync(cacheDir)) mkdirSync(cacheDir, { recursive: true });
539
- writeFileSync(resolve(cacheDir, 'vector-stats.json'), JSON.stringify(cacheData));
540
- }
541
- } catch { /* non-fatal */ }
542
-
543
- db.close();
544
- }
545
-
546
- main().catch(err => {
547
- log(`Error: ${err.message}`);
548
- process.exit(1);
549
- });