agentic-flow 2.0.7 → 2.0.9

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 (316) hide show
  1. package/.claude/settings.json +133 -9
  2. package/.claude/skills/agentic-flow-quickstart/skill.md +69 -0
  3. package/.claude/skills/hooks-automation/skill.md +155 -0
  4. package/.claude/skills/memory-patterns/skill.md +110 -0
  5. package/.claude/skills/sparc-methodology/skill.md +137 -0
  6. package/.claude/skills/swarm-coordination/skill.md +94 -0
  7. package/.claude/skills/worker-benchmarks/skill.md +135 -0
  8. package/.claude/skills/worker-integration/skill.md +154 -0
  9. package/.claude/statusline.mjs +109 -0
  10. package/.claude/statusline.sh +71 -0
  11. package/README.md +1797 -624
  12. package/dist/.tsbuildinfo +1 -1
  13. package/dist/agentdb/index.d.ts +2 -0
  14. package/dist/agentdb/index.d.ts.map +1 -1
  15. package/dist/agentdb/index.js +5 -0
  16. package/dist/agentdb/index.js.map +1 -1
  17. package/dist/agentdb/prerequisites.d.ts +25 -0
  18. package/dist/agentdb/prerequisites.d.ts.map +1 -0
  19. package/dist/agentdb/prerequisites.js +180 -0
  20. package/dist/agentdb/prerequisites.js.map +1 -0
  21. package/dist/benchmarks/embeddings-benchmark.d.ts +38 -0
  22. package/dist/benchmarks/embeddings-benchmark.d.ts.map +1 -0
  23. package/dist/benchmarks/embeddings-benchmark.js +282 -0
  24. package/dist/benchmarks/embeddings-benchmark.js.map +1 -0
  25. package/dist/billing/mcp/tools.js +1 -0
  26. package/dist/billing/mcp/tools.js.map +1 -1
  27. package/dist/cli/commands/embeddings.d.ts +12 -0
  28. package/dist/cli/commands/embeddings.d.ts.map +1 -0
  29. package/dist/cli/commands/embeddings.js +386 -0
  30. package/dist/cli/commands/embeddings.js.map +1 -0
  31. package/dist/cli/commands/hooks.d.ts.map +1 -1
  32. package/dist/cli/commands/hooks.js +79 -4
  33. package/dist/cli/commands/hooks.js.map +1 -1
  34. package/dist/cli/commands/init.d.ts +8 -0
  35. package/dist/cli/commands/init.d.ts.map +1 -0
  36. package/dist/cli/commands/init.js +514 -0
  37. package/dist/cli/commands/init.js.map +1 -0
  38. package/dist/cli/commands/workers.d.ts +9 -0
  39. package/dist/cli/commands/workers.d.ts.map +1 -0
  40. package/dist/cli/commands/workers.js +991 -0
  41. package/dist/cli/commands/workers.js.map +1 -0
  42. package/dist/cli/config-wizard.d.ts.map +1 -1
  43. package/dist/cli/config-wizard.js +47 -25
  44. package/dist/cli/config-wizard.js.map +1 -1
  45. package/dist/cli-proxy.js +89 -1
  46. package/dist/cli-proxy.js.map +1 -1
  47. package/dist/core/agentdb-fast.js +3 -3
  48. package/dist/core/agentdb-fast.js.map +1 -1
  49. package/dist/core/agentdb-wrapper-enhanced.d.ts.map +1 -1
  50. package/dist/core/agentdb-wrapper-enhanced.js +37 -11
  51. package/dist/core/agentdb-wrapper-enhanced.js.map +1 -1
  52. package/dist/core/agentdb-wrapper.d.ts +3 -2
  53. package/dist/core/agentdb-wrapper.d.ts.map +1 -1
  54. package/dist/core/agentdb-wrapper.js +15 -1
  55. package/dist/core/agentdb-wrapper.js.map +1 -1
  56. package/dist/core/attention-native.d.ts +4 -0
  57. package/dist/core/attention-native.d.ts.map +1 -1
  58. package/dist/core/attention-native.js +14 -2
  59. package/dist/core/attention-native.js.map +1 -1
  60. package/dist/core/gnn-wrapper.d.ts.map +1 -1
  61. package/dist/core/gnn-wrapper.js +14 -0
  62. package/dist/core/gnn-wrapper.js.map +1 -1
  63. package/dist/embeddings/index.d.ts +17 -0
  64. package/dist/embeddings/index.d.ts.map +1 -0
  65. package/dist/embeddings/index.js +17 -0
  66. package/dist/embeddings/index.js.map +1 -0
  67. package/dist/embeddings/neural-substrate.d.ts +206 -0
  68. package/dist/embeddings/neural-substrate.d.ts.map +1 -0
  69. package/dist/embeddings/neural-substrate.js +629 -0
  70. package/dist/embeddings/neural-substrate.js.map +1 -0
  71. package/dist/embeddings/optimized-embedder.d.ts +103 -0
  72. package/dist/embeddings/optimized-embedder.d.ts.map +1 -0
  73. package/dist/embeddings/optimized-embedder.js +730 -0
  74. package/dist/embeddings/optimized-embedder.js.map +1 -0
  75. package/dist/examples/embedding-geometry.d.ts +105 -0
  76. package/dist/examples/embedding-geometry.d.ts.map +1 -0
  77. package/dist/examples/embedding-geometry.js +528 -0
  78. package/dist/examples/embedding-geometry.js.map +1 -0
  79. package/dist/federation/SecurityManager.d.ts +11 -2
  80. package/dist/federation/SecurityManager.d.ts.map +1 -1
  81. package/dist/federation/SecurityManager.js +50 -17
  82. package/dist/federation/SecurityManager.js.map +1 -1
  83. package/dist/federation/integrations/supabase-adapter-debug.js +3 -3
  84. package/dist/federation/integrations/supabase-adapter-debug.js.map +1 -1
  85. package/dist/hooks/swarm-learning-optimizer.js +5 -5
  86. package/dist/hooks/swarm-learning-optimizer.js.map +1 -1
  87. package/dist/index.d.ts +5 -3
  88. package/dist/index.d.ts.map +1 -1
  89. package/dist/index.js +89 -51
  90. package/dist/index.js.map +1 -1
  91. package/dist/intelligence/IntelligenceStore.d.ts +35 -26
  92. package/dist/intelligence/IntelligenceStore.d.ts.map +1 -1
  93. package/dist/intelligence/IntelligenceStore.js +308 -123
  94. package/dist/intelligence/IntelligenceStore.js.map +1 -1
  95. package/dist/intelligence/RuVectorIntelligence.d.ts +26 -1
  96. package/dist/intelligence/RuVectorIntelligence.d.ts.map +1 -1
  97. package/dist/intelligence/RuVectorIntelligence.js +49 -10
  98. package/dist/intelligence/RuVectorIntelligence.js.map +1 -1
  99. package/dist/intelligence/agent-booster-enhanced.d.ts +1 -0
  100. package/dist/intelligence/agent-booster-enhanced.d.ts.map +1 -1
  101. package/dist/intelligence/agent-booster-enhanced.js +24 -3
  102. package/dist/intelligence/agent-booster-enhanced.js.map +1 -1
  103. package/dist/intelligence/index.d.ts +29 -3
  104. package/dist/intelligence/index.d.ts.map +1 -1
  105. package/dist/intelligence/index.js +13 -3
  106. package/dist/intelligence/index.js.map +1 -1
  107. package/dist/mcp/claudeFlowSdkServer.d.ts.map +1 -1
  108. package/dist/mcp/claudeFlowSdkServer.js +162 -115
  109. package/dist/mcp/claudeFlowSdkServer.js.map +1 -1
  110. package/dist/mcp/fastmcp/tools/hooks/intelligence-bridge.js +5 -5
  111. package/dist/mcp/fastmcp/tools/hooks/intelligence-bridge.js.map +1 -1
  112. package/dist/mcp/fastmcp/tools/swarm/init.d.ts.map +1 -1
  113. package/dist/mcp/fastmcp/tools/swarm/init.js +36 -7
  114. package/dist/mcp/fastmcp/tools/swarm/init.js.map +1 -1
  115. package/dist/mcp/fastmcp/tools/swarm/spawn.d.ts.map +1 -1
  116. package/dist/mcp/fastmcp/tools/swarm/spawn.js +47 -8
  117. package/dist/mcp/fastmcp/tools/swarm/spawn.js.map +1 -1
  118. package/dist/mcp/tools/agent-booster-tools.d.ts +15 -1
  119. package/dist/mcp/tools/agent-booster-tools.d.ts.map +1 -1
  120. package/dist/mcp/tools/agent-booster-tools.js +79 -63
  121. package/dist/mcp/tools/agent-booster-tools.js.map +1 -1
  122. package/dist/mcp/tools/sona-tools.d.ts.map +1 -1
  123. package/dist/mcp/tools/sona-tools.js +6 -0
  124. package/dist/mcp/tools/sona-tools.js.map +1 -1
  125. package/dist/memory/SharedMemoryPool.d.ts +103 -0
  126. package/dist/memory/SharedMemoryPool.d.ts.map +1 -0
  127. package/dist/memory/SharedMemoryPool.js +263 -0
  128. package/dist/memory/SharedMemoryPool.js.map +1 -0
  129. package/dist/optimizations/agent-booster-migration.d.ts +2 -1
  130. package/dist/optimizations/agent-booster-migration.d.ts.map +1 -1
  131. package/dist/optimizations/agent-booster-migration.js +69 -45
  132. package/dist/optimizations/agent-booster-migration.js.map +1 -1
  133. package/dist/orchestration/index.d.ts +11 -0
  134. package/dist/orchestration/index.d.ts.map +1 -0
  135. package/dist/orchestration/index.js +10 -0
  136. package/dist/orchestration/index.js.map +1 -0
  137. package/dist/orchestration/memory-plane-types.d.ts +23 -0
  138. package/dist/orchestration/memory-plane-types.d.ts.map +1 -0
  139. package/dist/orchestration/memory-plane-types.js +5 -0
  140. package/dist/orchestration/memory-plane-types.js.map +1 -0
  141. package/dist/orchestration/memory-plane.d.ts +41 -0
  142. package/dist/orchestration/memory-plane.d.ts.map +1 -0
  143. package/dist/orchestration/memory-plane.js +84 -0
  144. package/dist/orchestration/memory-plane.js.map +1 -0
  145. package/dist/orchestration/orchestration-client.d.ts +104 -0
  146. package/dist/orchestration/orchestration-client.d.ts.map +1 -0
  147. package/dist/orchestration/orchestration-client.js +94 -0
  148. package/dist/orchestration/orchestration-client.js.map +1 -0
  149. package/dist/orchestration/orchestration-runtime.d.ts +26 -0
  150. package/dist/orchestration/orchestration-runtime.d.ts.map +1 -0
  151. package/dist/orchestration/orchestration-runtime.js +78 -0
  152. package/dist/orchestration/orchestration-runtime.js.map +1 -0
  153. package/dist/orchestration/orchestration-types.d.ts +124 -0
  154. package/dist/orchestration/orchestration-types.d.ts.map +1 -0
  155. package/dist/orchestration/orchestration-types.js +7 -0
  156. package/dist/orchestration/orchestration-types.js.map +1 -0
  157. package/dist/proxy/anthropic-to-openrouter.js.map +1 -1
  158. package/dist/proxy/anthropic-to-requesty.js.map +1 -1
  159. package/dist/proxy/quic-proxy.d.ts +0 -1
  160. package/dist/proxy/quic-proxy.d.ts.map +1 -1
  161. package/dist/proxy/quic-proxy.js +2 -2
  162. package/dist/proxy/quic-proxy.js.map +1 -1
  163. package/dist/reasoningbank/AdvancedMemory.js +1 -1
  164. package/dist/reasoningbank/AdvancedMemory.js.map +1 -1
  165. package/dist/reasoningbank/HybridBackend.d.ts.map +1 -1
  166. package/dist/reasoningbank/HybridBackend.js +2 -5
  167. package/dist/reasoningbank/HybridBackend.js.map +1 -1
  168. package/dist/reasoningbank/backend-selector.d.ts +11 -1
  169. package/dist/reasoningbank/backend-selector.d.ts.map +1 -1
  170. package/dist/reasoningbank/backend-selector.js +45 -5
  171. package/dist/reasoningbank/backend-selector.js.map +1 -1
  172. package/dist/reasoningbank/core/consolidate.d.ts.map +1 -1
  173. package/dist/reasoningbank/core/consolidate.js +113 -45
  174. package/dist/reasoningbank/core/consolidate.js.map +1 -1
  175. package/dist/reasoningbank/index-new.d.ts +1 -6
  176. package/dist/reasoningbank/index-new.d.ts.map +1 -1
  177. package/dist/reasoningbank/index-new.js +1 -6
  178. package/dist/reasoningbank/index-new.js.map +1 -1
  179. package/dist/reasoningbank/index.d.ts +6 -0
  180. package/dist/reasoningbank/index.d.ts.map +1 -1
  181. package/dist/reasoningbank/index.js +6 -13
  182. package/dist/reasoningbank/index.js.map +1 -1
  183. package/dist/reasoningbank/utils/embeddings.d.ts +1 -0
  184. package/dist/reasoningbank/utils/embeddings.d.ts.map +1 -1
  185. package/dist/reasoningbank/utils/embeddings.js +53 -26
  186. package/dist/reasoningbank/utils/embeddings.js.map +1 -1
  187. package/dist/router/index.d.ts +2 -1
  188. package/dist/router/index.d.ts.map +1 -1
  189. package/dist/router/index.js +1 -0
  190. package/dist/router/index.js.map +1 -1
  191. package/dist/router/providers/ollama.d.ts +20 -0
  192. package/dist/router/providers/ollama.d.ts.map +1 -0
  193. package/dist/router/providers/ollama.js +242 -0
  194. package/dist/router/providers/ollama.js.map +1 -0
  195. package/dist/router/providers/onnx-local-optimized.d.ts +2 -0
  196. package/dist/router/providers/onnx-local-optimized.d.ts.map +1 -1
  197. package/dist/router/providers/onnx-local-optimized.js +10 -0
  198. package/dist/router/providers/onnx-local-optimized.js.map +1 -1
  199. package/dist/router/providers/onnx-local.d.ts +1 -0
  200. package/dist/router/providers/onnx-local.d.ts.map +1 -1
  201. package/dist/router/providers/onnx-local.js +22 -5
  202. package/dist/router/providers/onnx-local.js.map +1 -1
  203. package/dist/router/router.d.ts.map +1 -1
  204. package/dist/router/router.js +39 -23
  205. package/dist/router/router.js.map +1 -1
  206. package/dist/sdk/index.d.ts +2 -1
  207. package/dist/sdk/index.d.ts.map +1 -1
  208. package/dist/sdk/index.js +3 -1
  209. package/dist/sdk/index.js.map +1 -1
  210. package/dist/services/embedding-service.js.map +1 -1
  211. package/dist/services/sona-agent-training.d.ts +1 -0
  212. package/dist/services/sona-agent-training.d.ts.map +1 -1
  213. package/dist/services/sona-agent-training.js.map +1 -1
  214. package/dist/services/sona-agentdb-integration.d.ts.map +1 -1
  215. package/dist/services/sona-agentdb-integration.js +9 -6
  216. package/dist/services/sona-agentdb-integration.js.map +1 -1
  217. package/dist/services/sona-service.d.ts.map +1 -1
  218. package/dist/services/sona-service.js +6 -5
  219. package/dist/services/sona-service.js.map +1 -1
  220. package/dist/utils/cli.d.ts +1 -1
  221. package/dist/utils/cli.d.ts.map +1 -1
  222. package/dist/utils/cli.js +21 -0
  223. package/dist/utils/cli.js.map +1 -1
  224. package/dist/utils/index.d.ts +6 -0
  225. package/dist/utils/index.d.ts.map +1 -0
  226. package/dist/utils/index.js +6 -0
  227. package/dist/utils/index.js.map +1 -0
  228. package/dist/utils/model-cache.d.ts +61 -0
  229. package/dist/utils/model-cache.d.ts.map +1 -0
  230. package/dist/utils/model-cache.js +176 -0
  231. package/dist/utils/model-cache.js.map +1 -0
  232. package/dist/utils/suppress-warnings.d.ts +19 -0
  233. package/dist/utils/suppress-warnings.d.ts.map +1 -0
  234. package/dist/utils/suppress-warnings.js +59 -0
  235. package/dist/utils/suppress-warnings.js.map +1 -0
  236. package/dist/workers/consolidated-phases.d.ts +40 -0
  237. package/dist/workers/consolidated-phases.d.ts.map +1 -0
  238. package/dist/workers/consolidated-phases.js +497 -0
  239. package/dist/workers/consolidated-phases.js.map +1 -0
  240. package/dist/workers/custom-worker-config.d.ts +133 -0
  241. package/dist/workers/custom-worker-config.d.ts.map +1 -0
  242. package/dist/workers/custom-worker-config.js +215 -0
  243. package/dist/workers/custom-worker-config.js.map +1 -0
  244. package/dist/workers/custom-worker-factory.d.ts +89 -0
  245. package/dist/workers/custom-worker-factory.d.ts.map +1 -0
  246. package/dist/workers/custom-worker-factory.js +404 -0
  247. package/dist/workers/custom-worker-factory.js.map +1 -0
  248. package/dist/workers/dispatch-service.d.ts +123 -0
  249. package/dist/workers/dispatch-service.d.ts.map +1 -0
  250. package/dist/workers/dispatch-service.js +1024 -0
  251. package/dist/workers/dispatch-service.js.map +1 -0
  252. package/dist/workers/hooks-integration.d.ts +79 -0
  253. package/dist/workers/hooks-integration.d.ts.map +1 -0
  254. package/dist/workers/hooks-integration.js +286 -0
  255. package/dist/workers/hooks-integration.js.map +1 -0
  256. package/dist/workers/index.d.ts +42 -0
  257. package/dist/workers/index.d.ts.map +1 -0
  258. package/dist/workers/index.js +52 -0
  259. package/dist/workers/index.js.map +1 -0
  260. package/dist/workers/mcp-tools.d.ts +56 -0
  261. package/dist/workers/mcp-tools.d.ts.map +1 -0
  262. package/dist/workers/mcp-tools.js +359 -0
  263. package/dist/workers/mcp-tools.js.map +1 -0
  264. package/dist/workers/phase-executors.d.ts +22 -0
  265. package/dist/workers/phase-executors.d.ts.map +1 -0
  266. package/dist/workers/phase-executors.js +445 -0
  267. package/dist/workers/phase-executors.js.map +1 -0
  268. package/dist/workers/resource-governor.d.ts +75 -0
  269. package/dist/workers/resource-governor.d.ts.map +1 -0
  270. package/dist/workers/resource-governor.js +187 -0
  271. package/dist/workers/resource-governor.js.map +1 -0
  272. package/dist/workers/ruvector-integration.d.ts +163 -0
  273. package/dist/workers/ruvector-integration.d.ts.map +1 -0
  274. package/dist/workers/ruvector-integration.js +543 -0
  275. package/dist/workers/ruvector-integration.js.map +1 -0
  276. package/dist/workers/ruvector-native-integration.d.ts +91 -0
  277. package/dist/workers/ruvector-native-integration.d.ts.map +1 -0
  278. package/dist/workers/ruvector-native-integration.js +254 -0
  279. package/dist/workers/ruvector-native-integration.js.map +1 -0
  280. package/dist/workers/trigger-detector.d.ts +68 -0
  281. package/dist/workers/trigger-detector.d.ts.map +1 -0
  282. package/dist/workers/trigger-detector.js +281 -0
  283. package/dist/workers/trigger-detector.js.map +1 -0
  284. package/dist/workers/types.d.ts +145 -0
  285. package/dist/workers/types.d.ts.map +1 -0
  286. package/dist/workers/types.js +6 -0
  287. package/dist/workers/types.js.map +1 -0
  288. package/dist/workers/worker-agent-integration.d.ts +140 -0
  289. package/dist/workers/worker-agent-integration.d.ts.map +1 -0
  290. package/dist/workers/worker-agent-integration.js +471 -0
  291. package/dist/workers/worker-agent-integration.js.map +1 -0
  292. package/dist/workers/worker-benchmarks.d.ts +88 -0
  293. package/dist/workers/worker-benchmarks.d.ts.map +1 -0
  294. package/dist/workers/worker-benchmarks.js +452 -0
  295. package/dist/workers/worker-benchmarks.js.map +1 -0
  296. package/dist/workers/worker-registry.d.ts +85 -0
  297. package/dist/workers/worker-registry.d.ts.map +1 -0
  298. package/dist/workers/worker-registry.js +547 -0
  299. package/dist/workers/worker-registry.js.map +1 -0
  300. package/docs/embeddings/EMBEDDING_GEOMETRY.md +935 -0
  301. package/package.json +27 -9
  302. package/scripts/postinstall.js +45 -4
  303. package/wasm/reasoningbank/reasoningbank_wasm.js +1 -1
  304. package/wasm/reasoningbank/reasoningbank_wasm_bg.js +54 -54
  305. package/wasm/reasoningbank/reasoningbank_wasm_bg.wasm +0 -0
  306. package/wasm/reasoningbank/reasoningbank_wasm_bg.wasm.d.ts +4 -3
  307. package/.claude/agents/test-neural.md +0 -14
  308. /package/.claude/agents/analysis/{code-review/analyze-code-quality.md → analyze-code-quality.md} +0 -0
  309. /package/.claude/agents/architecture/{system-design/arch-system-design.md → arch-system-design.md} +0 -0
  310. /package/.claude/agents/data/{ml/data-ml-model.md → data-ml-model.md} +0 -0
  311. /package/.claude/agents/development/{backend/dev-backend-api.md → dev-backend-api.md} +0 -0
  312. /package/.claude/agents/devops/{ci-cd/ops-cicd-github.md → ops-cicd-github.md} +0 -0
  313. /package/.claude/agents/documentation/{api-docs/docs-api-openapi.md → docs-api-openapi.md} +0 -0
  314. /package/.claude/agents/specialized/{mobile/spec-mobile-react-native.md → spec-mobile-react-native.md} +0 -0
  315. /package/.claude/agents/testing/{validation/production-validator.md → production-validator.md} +0 -0
  316. /package/.claude/agents/testing/{unit/tdd-london-swarm.md → tdd-london-swarm.md} +0 -0
@@ -0,0 +1,497 @@
1
+ /**
2
+ * Consolidated Phase System
3
+ *
4
+ * Eliminates redundancy between phase-executors.ts and ruvector-native-integration.ts
5
+ * by providing a unified phase registry that:
6
+ * 1. Uses native implementations as primary (faster, SIMD-optimized)
7
+ * 2. Falls back to legacy implementations if needed
8
+ * 3. Shares the cached ONNX embedder across all phases
9
+ */
10
+ import { DEFAULT_FILE_FILTER } from './custom-worker-config.js';
11
+ import { getCachedOnnxEmbedder } from '../utils/model-cache.js';
12
+ export function createUnifiedContext() {
13
+ return {
14
+ files: [],
15
+ patterns: [],
16
+ bytes: 0,
17
+ dependencies: new Map(),
18
+ metrics: {},
19
+ embeddings: new Map(),
20
+ vectors: new Map(),
21
+ phaseData: new Map(),
22
+ vulnerabilities: []
23
+ };
24
+ }
25
+ const unifiedExecutors = new Map();
26
+ export function registerUnifiedPhase(type, executor) {
27
+ unifiedExecutors.set(type, executor);
28
+ }
29
+ export function getUnifiedPhase(type) {
30
+ return unifiedExecutors.get(type);
31
+ }
32
+ export function listUnifiedPhases() {
33
+ return Array.from(unifiedExecutors.keys());
34
+ }
35
+ // ============================================================================
36
+ // Core Phases (Consolidated - No Duplication)
37
+ // ============================================================================
38
+ // FILE DISCOVERY - Single implementation
39
+ registerUnifiedPhase('file-discovery', async (workerContext, phaseContext, options) => {
40
+ const { glob } = await import('glob');
41
+ const filter = { ...DEFAULT_FILE_FILTER, ...options };
42
+ const patterns = options.patterns || filter.include || ['**/*.{ts,js,tsx,jsx}'];
43
+ const ignore = options.ignore || filter.exclude || ['node_modules/**', 'dist/**', '.git/**'];
44
+ try {
45
+ const allFiles = [];
46
+ for (const pattern of patterns) {
47
+ const files = await glob(pattern, {
48
+ cwd: process.cwd(),
49
+ ignore,
50
+ absolute: true,
51
+ nodir: true,
52
+ maxDepth: filter.maxDepth || 10
53
+ });
54
+ allFiles.push(...files);
55
+ }
56
+ // Deduplicate and limit
57
+ phaseContext.files = [...new Set(allFiles)].slice(0, filter.maxFiles || 500);
58
+ phaseContext.metrics['files_discovered'] = phaseContext.files.length;
59
+ return {
60
+ success: true,
61
+ data: { filesFound: phaseContext.files.length, patterns },
62
+ files: phaseContext.files
63
+ };
64
+ }
65
+ catch (error) {
66
+ return {
67
+ success: false,
68
+ data: {},
69
+ error: error instanceof Error ? error.message : 'File discovery failed'
70
+ };
71
+ }
72
+ });
73
+ // PATTERN EXTRACTION - Single implementation
74
+ registerUnifiedPhase('pattern-extraction', async (workerContext, phaseContext, options) => {
75
+ const fs = await import('fs/promises');
76
+ const patterns = [];
77
+ const extractors = [
78
+ { regex: /(?:export\s+)?(?:async\s+)?function\s+(\w+)/g, type: 'function' },
79
+ { regex: /(?:export\s+)?class\s+(\w+)/g, type: 'class' },
80
+ { regex: /(?:export\s+)?interface\s+(\w+)/g, type: 'interface' },
81
+ { regex: /(?:export\s+)?type\s+(\w+)\s*=/g, type: 'type' },
82
+ { regex: /(?:const|let|var)\s+(\w+)\s*=/g, type: 'variable' },
83
+ { regex: /import\s+.*?from\s+['"]([^'"]+)['"]/g, type: 'import' },
84
+ { regex: /TODO:?\s*(.+?)$/gm, type: 'todo' },
85
+ { regex: /FIXME:?\s*(.+?)$/gm, type: 'fixme' }
86
+ ];
87
+ const maxFiles = Math.min(phaseContext.files.length, 100);
88
+ let bytesProcessed = 0;
89
+ for (let i = 0; i < maxFiles; i++) {
90
+ const file = phaseContext.files[i];
91
+ try {
92
+ const content = await fs.readFile(file, 'utf-8');
93
+ bytesProcessed += content.length;
94
+ for (const { regex } of extractors) {
95
+ const matches = content.matchAll(regex);
96
+ for (const match of matches) {
97
+ patterns.push(match[1] || match[0]);
98
+ }
99
+ }
100
+ }
101
+ catch {
102
+ // Skip unreadable files
103
+ }
104
+ }
105
+ phaseContext.patterns.push(...patterns);
106
+ phaseContext.bytes += bytesProcessed;
107
+ phaseContext.metrics['patterns_found'] = patterns.length;
108
+ return {
109
+ success: true,
110
+ data: {
111
+ patternsFound: patterns.length,
112
+ bytesProcessed,
113
+ samplePatterns: [...new Set(patterns)].slice(0, 20)
114
+ },
115
+ patterns: phaseContext.patterns
116
+ };
117
+ });
118
+ // EMBEDDING GENERATION - Single implementation using cached embedder
119
+ registerUnifiedPhase('embedding-generation', async (workerContext, phaseContext, options) => {
120
+ const embedder = await getCachedOnnxEmbedder();
121
+ if (!embedder) {
122
+ return {
123
+ success: false,
124
+ data: {},
125
+ error: 'ONNX embedder not available - install ruvector for SIMD-accelerated embeddings'
126
+ };
127
+ }
128
+ const textsToEmbed = phaseContext.patterns.slice(0, 100);
129
+ let embeddingsGenerated = 0;
130
+ const startTime = Date.now();
131
+ for (const text of textsToEmbed) {
132
+ if (text.length > 3 && text.length < 500) {
133
+ try {
134
+ const embedding = await embedder.embed?.(text)
135
+ || await embedder.encode?.(text)
136
+ || await embedder.generate?.(text);
137
+ if (embedding) {
138
+ const vector = embedding instanceof Float32Array
139
+ ? embedding
140
+ : new Float32Array(embedding);
141
+ phaseContext.embeddings.set(text, vector);
142
+ embeddingsGenerated++;
143
+ }
144
+ }
145
+ catch {
146
+ // Skip failed embeddings
147
+ }
148
+ }
149
+ }
150
+ const durationMs = Date.now() - startTime;
151
+ phaseContext.metrics['embeddings_generated'] = embeddingsGenerated;
152
+ phaseContext.metrics['embedding_latency_ms'] = durationMs;
153
+ return {
154
+ success: true,
155
+ data: {
156
+ embeddingsGenerated,
157
+ dimension: 384,
158
+ durationMs,
159
+ throughputPerSec: embeddingsGenerated > 0 ? (embeddingsGenerated / (durationMs / 1000)).toFixed(1) : '0',
160
+ usingSIMD: true
161
+ }
162
+ };
163
+ });
164
+ // VECTOR STORAGE - Single implementation
165
+ registerUnifiedPhase('vector-storage', async (workerContext, phaseContext, options) => {
166
+ let vectorsStored = 0;
167
+ for (const [key, embedding] of phaseContext.embeddings) {
168
+ phaseContext.vectors.set(key, Array.from(embedding));
169
+ vectorsStored++;
170
+ }
171
+ phaseContext.metrics['vectors_stored'] = vectorsStored;
172
+ return {
173
+ success: true,
174
+ data: {
175
+ vectorsStored,
176
+ indexSize: vectorsStored,
177
+ dimension: 384
178
+ }
179
+ };
180
+ });
181
+ // SECURITY ANALYSIS - Single comprehensive implementation
182
+ registerUnifiedPhase('security-analysis', async (workerContext, phaseContext, options) => {
183
+ const fs = await import('fs/promises');
184
+ const securityPatterns = [
185
+ // High severity
186
+ { pattern: /password\s*[:=]\s*['"][^'"]+['"]/gi, type: 'hardcoded-password', severity: 'high' },
187
+ { pattern: /api[_-]?key\s*[:=]\s*['"][^'"]+['"]/gi, type: 'hardcoded-api-key', severity: 'high' },
188
+ { pattern: /secret\s*[:=]\s*['"][^'"]+['"]/gi, type: 'hardcoded-secret', severity: 'high' },
189
+ { pattern: /private[_-]?key\s*[:=]\s*['"][^'"]+['"]/gi, type: 'hardcoded-private-key', severity: 'high' },
190
+ { pattern: /bearer\s+[a-zA-Z0-9_-]+/gi, type: 'exposed-token', severity: 'high' },
191
+ // Medium severity
192
+ { pattern: /eval\s*\(/g, type: 'eval-usage', severity: 'medium' },
193
+ { pattern: /innerHTML\s*=/g, type: 'xss-risk', severity: 'medium' },
194
+ { pattern: /dangerouslySetInnerHTML/g, type: 'xss-risk', severity: 'medium' },
195
+ { pattern: /child_process.*exec/g, type: 'command-injection-risk', severity: 'medium' },
196
+ { pattern: /\$\{.*\}/g, type: 'template-injection', severity: 'medium' },
197
+ { pattern: /document\.(write|cookie)/g, type: 'dom-manipulation', severity: 'medium' },
198
+ // Low severity
199
+ { pattern: /console\.(log|debug|info)/g, type: 'console-output', severity: 'low' },
200
+ { pattern: /process\.env\.\w+/g, type: 'env-usage', severity: 'low' },
201
+ { pattern: /TODO.*security|FIXME.*security/gi, type: 'security-todo', severity: 'low' }
202
+ ];
203
+ const vulnerabilities = [];
204
+ const maxFiles = Math.min(phaseContext.files.length, 100);
205
+ for (let i = 0; i < maxFiles; i++) {
206
+ const file = phaseContext.files[i];
207
+ try {
208
+ const content = await fs.readFile(file, 'utf-8');
209
+ const lines = content.split('\n');
210
+ for (let lineNum = 0; lineNum < lines.length; lineNum++) {
211
+ const line = lines[lineNum];
212
+ for (const { pattern, type, severity } of securityPatterns) {
213
+ pattern.lastIndex = 0; // Reset regex
214
+ if (pattern.test(line)) {
215
+ vulnerabilities.push({
216
+ type,
217
+ file: file.split('/').pop() || file,
218
+ line: lineNum + 1,
219
+ severity
220
+ });
221
+ }
222
+ }
223
+ }
224
+ }
225
+ catch {
226
+ // Skip unreadable files
227
+ }
228
+ }
229
+ phaseContext.vulnerabilities.push(...vulnerabilities);
230
+ phaseContext.metrics['vulnerabilities_found'] = vulnerabilities.length;
231
+ const summary = {
232
+ high: vulnerabilities.filter(v => v.severity === 'high').length,
233
+ medium: vulnerabilities.filter(v => v.severity === 'medium').length,
234
+ low: vulnerabilities.filter(v => v.severity === 'low').length
235
+ };
236
+ return {
237
+ success: true,
238
+ data: {
239
+ vulnerabilities: vulnerabilities.slice(0, 30),
240
+ summary,
241
+ filesScanned: maxFiles
242
+ },
243
+ patterns: vulnerabilities.map(v => `[${v.severity}] ${v.type}`)
244
+ };
245
+ });
246
+ // COMPLEXITY ANALYSIS - Single implementation
247
+ registerUnifiedPhase('complexity-analysis', async (workerContext, phaseContext, options) => {
248
+ const fs = await import('fs/promises');
249
+ const complexityMarkers = [
250
+ /\bif\s*\(/g,
251
+ /\belse\s+if\s*\(/g,
252
+ /\belse\s*\{/g,
253
+ /\bfor\s*\(/g,
254
+ /\bwhile\s*\(/g,
255
+ /\bdo\s*\{/g,
256
+ /\bswitch\s*\(/g,
257
+ /\bcase\s+/g,
258
+ /\bcatch\s*\(/g,
259
+ /\?\s*.*:/g, // Ternary
260
+ /&&|\|\|/g, // Logical operators
261
+ /\?\./g // Optional chaining
262
+ ];
263
+ const fileComplexity = [];
264
+ let totalComplexity = 0;
265
+ let totalLines = 0;
266
+ const maxFiles = Math.min(phaseContext.files.length, 100);
267
+ for (let i = 0; i < maxFiles; i++) {
268
+ const file = phaseContext.files[i];
269
+ try {
270
+ const content = await fs.readFile(file, 'utf-8');
271
+ const lines = content.split('\n').length;
272
+ let complexity = 1; // Base complexity
273
+ for (const marker of complexityMarkers) {
274
+ const matches = content.match(marker);
275
+ if (matches) {
276
+ complexity += matches.length;
277
+ }
278
+ }
279
+ fileComplexity.push({
280
+ file: file.split('/').pop() || file,
281
+ complexity,
282
+ lines
283
+ });
284
+ totalComplexity += complexity;
285
+ totalLines += lines;
286
+ }
287
+ catch {
288
+ // Skip unreadable files
289
+ }
290
+ }
291
+ fileComplexity.sort((a, b) => b.complexity - a.complexity);
292
+ phaseContext.metrics['total_complexity'] = totalComplexity;
293
+ phaseContext.metrics['total_lines'] = totalLines;
294
+ phaseContext.metrics['avg_complexity'] = maxFiles > 0 ? totalComplexity / maxFiles : 0;
295
+ return {
296
+ success: true,
297
+ data: {
298
+ avgComplexity: maxFiles > 0 ? (totalComplexity / maxFiles).toFixed(1) : '0',
299
+ totalLines,
300
+ filesAnalyzed: maxFiles,
301
+ highComplexityFiles: fileComplexity.filter(f => f.complexity > 20).length,
302
+ topFiles: fileComplexity.slice(0, 10)
303
+ }
304
+ };
305
+ });
306
+ // DEPENDENCY DISCOVERY - Single implementation
307
+ registerUnifiedPhase('dependency-discovery', async (workerContext, phaseContext, options) => {
308
+ const fs = await import('fs/promises');
309
+ const dependencies = new Map();
310
+ const importPatterns = [
311
+ /import\s+.*?from\s+['"]([^'"]+)['"]/g,
312
+ /require\s*\(\s*['"]([^'"]+)['"]\s*\)/g,
313
+ /import\s*\(\s*['"]([^'"]+)['"]\s*\)/g
314
+ ];
315
+ const maxFiles = Math.min(phaseContext.files.length, 100);
316
+ let bytesProcessed = 0;
317
+ for (let i = 0; i < maxFiles; i++) {
318
+ const file = phaseContext.files[i];
319
+ const fileName = file.split('/').pop() || file;
320
+ const fileDeps = [];
321
+ try {
322
+ const content = await fs.readFile(file, 'utf-8');
323
+ bytesProcessed += content.length;
324
+ for (const pattern of importPatterns) {
325
+ const matches = content.matchAll(pattern);
326
+ for (const match of matches) {
327
+ const dep = match[1];
328
+ if (!fileDeps.includes(dep)) {
329
+ fileDeps.push(dep);
330
+ }
331
+ }
332
+ }
333
+ if (fileDeps.length > 0) {
334
+ dependencies.set(fileName, fileDeps);
335
+ }
336
+ }
337
+ catch {
338
+ // Skip unreadable files
339
+ }
340
+ }
341
+ // Merge into context
342
+ for (const [file, deps] of dependencies) {
343
+ phaseContext.dependencies.set(file, deps);
344
+ }
345
+ phaseContext.bytes += bytesProcessed;
346
+ phaseContext.metrics['dependencies_found'] = dependencies.size;
347
+ return {
348
+ success: true,
349
+ data: {
350
+ filesWithDeps: dependencies.size,
351
+ totalDeps: Array.from(dependencies.values()).reduce((sum, deps) => sum + deps.length, 0),
352
+ bytesProcessed
353
+ }
354
+ };
355
+ });
356
+ // SUMMARIZATION - Single implementation
357
+ registerUnifiedPhase('summarization', async (workerContext, phaseContext, options) => {
358
+ return {
359
+ success: true,
360
+ data: {
361
+ summary: {
362
+ filesAnalyzed: phaseContext.files.length,
363
+ patternsFound: phaseContext.patterns.length,
364
+ uniquePatterns: [...new Set(phaseContext.patterns)].length,
365
+ bytesProcessed: phaseContext.bytes,
366
+ embeddingsGenerated: phaseContext.embeddings.size,
367
+ vectorsStored: phaseContext.vectors.size,
368
+ vulnerabilitiesFound: phaseContext.vulnerabilities.length,
369
+ dependencyFiles: phaseContext.dependencies.size
370
+ },
371
+ metrics: phaseContext.metrics
372
+ }
373
+ };
374
+ });
375
+ // ============================================================================
376
+ // Additional Phases (Not duplicated)
377
+ // ============================================================================
378
+ // API DISCOVERY
379
+ registerUnifiedPhase('api-discovery', async (workerContext, phaseContext, options) => {
380
+ const fs = await import('fs/promises');
381
+ const apis = [];
382
+ const apiPatterns = [
383
+ /app\.(get|post|put|delete|patch)\s*\(\s*['"]([^'"]+)['"]/gi,
384
+ /router\.(get|post|put|delete|patch)\s*\(\s*['"]([^'"]+)['"]/gi,
385
+ /@(Get|Post|Put|Delete|Patch)\s*\(\s*['"]([^'"]+)['"]/gi,
386
+ /fetch\s*\(\s*['"]([^'"]+)['"]/gi
387
+ ];
388
+ for (const file of phaseContext.files.slice(0, 100)) {
389
+ try {
390
+ const content = await fs.readFile(file, 'utf-8');
391
+ for (const pattern of apiPatterns) {
392
+ const matches = content.matchAll(pattern);
393
+ for (const match of matches) {
394
+ apis.push({
395
+ method: match[1]?.toUpperCase() || 'GET',
396
+ path: match[2],
397
+ file: file.split('/').pop() || file
398
+ });
399
+ }
400
+ }
401
+ }
402
+ catch {
403
+ // Skip
404
+ }
405
+ }
406
+ return {
407
+ success: true,
408
+ data: { apis: apis.slice(0, 50), totalApis: apis.length }
409
+ };
410
+ });
411
+ // TODO EXTRACTION
412
+ registerUnifiedPhase('todo-extraction', async (workerContext, phaseContext, options) => {
413
+ const fs = await import('fs/promises');
414
+ const todos = [];
415
+ const todoPatterns = [
416
+ { pattern: /\/\/\s*TODO:?\s*(.+?)$/gm, type: 'TODO' },
417
+ { pattern: /\/\/\s*FIXME:?\s*(.+?)$/gm, type: 'FIXME' },
418
+ { pattern: /\/\/\s*HACK:?\s*(.+?)$/gm, type: 'HACK' },
419
+ { pattern: /\/\/\s*XXX:?\s*(.+?)$/gm, type: 'XXX' },
420
+ { pattern: /\/\*\s*TODO:?\s*(.+?)\*\//gm, type: 'TODO' }
421
+ ];
422
+ for (const file of phaseContext.files.slice(0, 100)) {
423
+ try {
424
+ const content = await fs.readFile(file, 'utf-8');
425
+ const lines = content.split('\n');
426
+ for (let lineNum = 0; lineNum < lines.length; lineNum++) {
427
+ const line = lines[lineNum];
428
+ for (const { pattern, type } of todoPatterns) {
429
+ pattern.lastIndex = 0;
430
+ const match = pattern.exec(line);
431
+ if (match) {
432
+ todos.push({
433
+ type,
434
+ text: match[1].trim(),
435
+ file: file.split('/').pop() || file,
436
+ line: lineNum + 1
437
+ });
438
+ }
439
+ }
440
+ }
441
+ }
442
+ catch {
443
+ // Skip
444
+ }
445
+ }
446
+ return {
447
+ success: true,
448
+ data: {
449
+ todos: todos.slice(0, 50),
450
+ counts: {
451
+ TODO: todos.filter(t => t.type === 'TODO').length,
452
+ FIXME: todos.filter(t => t.type === 'FIXME').length,
453
+ HACK: todos.filter(t => t.type === 'HACK').length
454
+ }
455
+ },
456
+ patterns: todos.map(t => `[${t.type}] ${t.text}`)
457
+ };
458
+ });
459
+ // ============================================================================
460
+ // Unified Pipeline Runner
461
+ // ============================================================================
462
+ export async function runUnifiedPipeline(workerContext, phases, options = {}) {
463
+ const startTime = Date.now();
464
+ const context = createUnifiedContext();
465
+ const results = {};
466
+ const executedPhases = [];
467
+ for (const phaseName of phases) {
468
+ const executor = unifiedExecutors.get(phaseName);
469
+ if (!executor) {
470
+ console.warn(`Unknown phase: ${phaseName}`);
471
+ continue;
472
+ }
473
+ try {
474
+ const result = await executor(workerContext, context, options);
475
+ results[phaseName] = result;
476
+ executedPhases.push(phaseName);
477
+ if (!result.success) {
478
+ console.warn(`Phase ${phaseName} failed:`, result.error);
479
+ }
480
+ }
481
+ catch (error) {
482
+ results[phaseName] = {
483
+ success: false,
484
+ data: {},
485
+ error: error instanceof Error ? error.message : String(error)
486
+ };
487
+ }
488
+ }
489
+ return {
490
+ success: Object.values(results).every(r => r.success),
491
+ phases: executedPhases,
492
+ context,
493
+ results,
494
+ duration: Date.now() - startTime
495
+ };
496
+ }
497
+ //# sourceMappingURL=consolidated-phases.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"consolidated-phases.js","sourceRoot":"","sources":["../../src/workers/consolidated-phases.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAGH,OAAO,EAAiC,mBAAmB,EAAE,MAAM,2BAA2B,CAAC;AAC/F,OAAO,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AAkBhE,MAAM,UAAU,oBAAoB;IAClC,OAAO;QACL,KAAK,EAAE,EAAE;QACT,QAAQ,EAAE,EAAE;QACZ,KAAK,EAAE,CAAC;QACR,YAAY,EAAE,IAAI,GAAG,EAAE;QACvB,OAAO,EAAE,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M,CAAC,OAAO,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC;QACrD,MAAM,EAAE,cAAc;QACtB,OAAO;QACP,OAAO;QACP,QAAQ,EAAE,IAAI,CAAC,GAAG,EAAE,GAAG,SAAS;KACjC,CAAC;AACJ,CAAC","sourcesContent":["/**\n * Consolidated Phase System\n *\n * Eliminates redundancy between phase-executors.ts and ruvector-native-integration.ts\n * by providing a unified phase registry that:\n * 1. Uses native implementations as primary (faster, SIMD-optimized)\n * 2. Falls back to legacy implementations if needed\n * 3. Shares the cached ONNX embedder across all phases\n */\n\nimport { WorkerContext } from './types.js';\nimport { PhaseResult, FileFilterConfig, DEFAULT_FILE_FILTER } from './custom-worker-config.js';\nimport { getCachedOnnxEmbedder } from '../utils/model-cache.js';\n\n// ============================================================================\n// Unified Phase Context\n// ============================================================================\n\nexport interface UnifiedPhaseContext {\n files: string[];\n patterns: string[];\n bytes: number;\n dependencies: Map<string, string[]>;\n metrics: Record<string, number>;\n embeddings: Map<string, Float32Array>;\n vectors: Map<string, number[]>;\n phaseData: Map<string, Record<string, unknown>>;\n vulnerabilities: Array<{ type: string; file: string; line: number; severity: string }>;\n}\n\nexport function createUnifiedContext(): UnifiedPhaseContext {\n return {\n files: [],\n patterns: [],\n bytes: 0,\n dependencies: new Map(),\n metrics: {},\n embeddings: new Map(),\n vectors: new Map(),\n phaseData: new Map(),\n vulnerabilities: []\n };\n}\n\n// ============================================================================\n// Unified Phase Executor\n// ============================================================================\n\nexport type UnifiedPhaseExecutor = (\n workerContext: WorkerContext,\n phaseContext: UnifiedPhaseContext,\n options: Record<string, unknown>\n) => Promise<PhaseResult>;\n\nconst unifiedExecutors = new Map<string, UnifiedPhaseExecutor>();\n\nexport function registerUnifiedPhase(type: string, executor: UnifiedPhaseExecutor): void {\n unifiedExecutors.set(type, executor);\n}\n\nexport function getUnifiedPhase(type: string): UnifiedPhaseExecutor | undefined {\n return unifiedExecutors.get(type);\n}\n\nexport function listUnifiedPhases(): string[] {\n return Array.from(unifiedExecutors.keys());\n}\n\n// ============================================================================\n// Core Phases (Consolidated - No Duplication)\n// ============================================================================\n\n// FILE DISCOVERY - Single implementation\nregisterUnifiedPhase('file-discovery', async (workerContext, phaseContext, options) => {\n const { glob } = await import('glob');\n const filter = { ...DEFAULT_FILE_FILTER, ...options } as FileFilterConfig;\n const patterns = (options.patterns as string[]) || filter.include || ['**/*.{ts,js,tsx,jsx}'];\n const ignore = (options.ignore as string[]) || filter.exclude || ['node_modules/**', 'dist/**', '.git/**'];\n\n try {\n const allFiles: string[] = [];\n for (const pattern of patterns) {\n const files = await glob(pattern, {\n cwd: process.cwd(),\n ignore,\n absolute: true,\n nodir: true,\n maxDepth: filter.maxDepth || 10\n });\n allFiles.push(...files);\n }\n\n // Deduplicate and limit\n phaseContext.files = [...new Set(allFiles)].slice(0, filter.maxFiles || 500);\n phaseContext.metrics['files_discovered'] = phaseContext.files.length;\n\n return {\n success: true,\n data: { filesFound: phaseContext.files.length, patterns },\n files: phaseContext.files\n };\n } catch (error) {\n return {\n success: false,\n data: {},\n error: error instanceof Error ? error.message : 'File discovery failed'\n };\n }\n});\n\n// PATTERN EXTRACTION - Single implementation\nregisterUnifiedPhase('pattern-extraction', async (workerContext, phaseContext, options) => {\n const fs = await import('fs/promises');\n const patterns: string[] = [];\n\n const extractors = [\n { regex: /(?:export\\s+)?(?:async\\s+)?function\\s+(\\w+)/g, type: 'function' },\n { regex: /(?:export\\s+)?class\\s+(\\w+)/g, type: 'class' },\n { regex: /(?:export\\s+)?interface\\s+(\\w+)/g, type: 'interface' },\n { regex: /(?:export\\s+)?type\\s+(\\w+)\\s*=/g, type: 'type' },\n { regex: /(?:const|let|var)\\s+(\\w+)\\s*=/g, type: 'variable' },\n { regex: /import\\s+.*?from\\s+['\"]([^'\"]+)['\"]/g, type: 'import' },\n { regex: /TODO:?\\s*(.+?)$/gm, type: 'todo' },\n { regex: /FIXME:?\\s*(.+?)$/gm, type: 'fixme' }\n ];\n\n const maxFiles = Math.min(phaseContext.files.length, 100);\n let bytesProcessed = 0;\n\n for (let i = 0; i < maxFiles; i++) {\n const file = phaseContext.files[i];\n try {\n const content = await fs.readFile(file, 'utf-8');\n bytesProcessed += content.length;\n\n for (const { regex } of extractors) {\n const matches = content.matchAll(regex);\n for (const match of matches) {\n patterns.push(match[1] || match[0]);\n }\n }\n } catch {\n // Skip unreadable files\n }\n }\n\n phaseContext.patterns.push(...patterns);\n phaseContext.bytes += bytesProcessed;\n phaseContext.metrics['patterns_found'] = patterns.length;\n\n return {\n success: true,\n data: {\n patternsFound: patterns.length,\n bytesProcessed,\n samplePatterns: [...new Set(patterns)].slice(0, 20)\n },\n patterns: phaseContext.patterns\n };\n});\n\n// EMBEDDING GENERATION - Single implementation using cached embedder\nregisterUnifiedPhase('embedding-generation', async (workerContext, phaseContext, options) => {\n const embedder = await getCachedOnnxEmbedder();\n\n if (!embedder) {\n return {\n success: false,\n data: {},\n error: 'ONNX embedder not available - install ruvector for SIMD-accelerated embeddings'\n };\n }\n\n const textsToEmbed = phaseContext.patterns.slice(0, 100);\n let embeddingsGenerated = 0;\n const startTime = Date.now();\n\n for (const text of textsToEmbed) {\n if (text.length > 3 && text.length < 500) {\n try {\n const embedding = await embedder.embed?.(text)\n || await embedder.encode?.(text)\n || await embedder.generate?.(text);\n\n if (embedding) {\n const vector = embedding instanceof Float32Array\n ? embedding\n : new Float32Array(embedding);\n phaseContext.embeddings.set(text, vector);\n embeddingsGenerated++;\n }\n } catch {\n // Skip failed embeddings\n }\n }\n }\n\n const durationMs = Date.now() - startTime;\n phaseContext.metrics['embeddings_generated'] = embeddingsGenerated;\n phaseContext.metrics['embedding_latency_ms'] = durationMs;\n\n return {\n success: true,\n data: {\n embeddingsGenerated,\n dimension: 384,\n durationMs,\n throughputPerSec: embeddingsGenerated > 0 ? (embeddingsGenerated / (durationMs / 1000)).toFixed(1) : '0',\n usingSIMD: true\n }\n };\n});\n\n// VECTOR STORAGE - Single implementation\nregisterUnifiedPhase('vector-storage', async (workerContext, phaseContext, options) => {\n let vectorsStored = 0;\n\n for (const [key, embedding] of phaseContext.embeddings) {\n phaseContext.vectors.set(key, Array.from(embedding));\n vectorsStored++;\n }\n\n phaseContext.metrics['vectors_stored'] = vectorsStored;\n\n return {\n success: true,\n data: {\n vectorsStored,\n indexSize: vectorsStored,\n dimension: 384\n }\n };\n});\n\n// SECURITY ANALYSIS - Single comprehensive implementation\nregisterUnifiedPhase('security-analysis', async (workerContext, phaseContext, options) => {\n const fs = await import('fs/promises');\n\n const securityPatterns = [\n // High severity\n { pattern: /password\\s*[:=]\\s*['\"][^'\"]+['\"]/gi, type: 'hardcoded-password', severity: 'high' },\n { pattern: /api[_-]?key\\s*[:=]\\s*['\"][^'\"]+['\"]/gi, type: 'hardcoded-api-key', severity: 'high' },\n { pattern: /secret\\s*[:=]\\s*['\"][^'\"]+['\"]/gi, type: 'hardcoded-secret', severity: 'high' },\n { pattern: /private[_-]?key\\s*[:=]\\s*['\"][^'\"]+['\"]/gi, type: 'hardcoded-private-key', severity: 'high' },\n { pattern: /bearer\\s+[a-zA-Z0-9_-]+/gi, type: 'exposed-token', severity: 'high' },\n // Medium severity\n { pattern: /eval\\s*\\(/g, type: 'eval-usage', severity: 'medium' },\n { pattern: /innerHTML\\s*=/g, type: 'xss-risk', severity: 'medium' },\n { pattern: /dangerouslySetInnerHTML/g, type: 'xss-risk', severity: 'medium' },\n { pattern: /child_process.*exec/g, type: 'command-injection-risk', severity: 'medium' },\n { pattern: /\\$\\{.*\\}/g, type: 'template-injection', severity: 'medium' },\n { pattern: /document\\.(write|cookie)/g, type: 'dom-manipulation', severity: 'medium' },\n // Low severity\n { pattern: /console\\.(log|debug|info)/g, type: 'console-output', severity: 'low' },\n { pattern: /process\\.env\\.\\w+/g, type: 'env-usage', severity: 'low' },\n { pattern: /TODO.*security|FIXME.*security/gi, type: 'security-todo', severity: 'low' }\n ];\n\n const vulnerabilities: typeof phaseContext.vulnerabilities = [];\n const maxFiles = Math.min(phaseContext.files.length, 100);\n\n for (let i = 0; i < maxFiles; i++) {\n const file = phaseContext.files[i];\n try {\n const content = await fs.readFile(file, 'utf-8');\n const lines = content.split('\\n');\n\n for (let lineNum = 0; lineNum < lines.length; lineNum++) {\n const line = lines[lineNum];\n for (const { pattern, type, severity } of securityPatterns) {\n pattern.lastIndex = 0; // Reset regex\n if (pattern.test(line)) {\n vulnerabilities.push({\n type,\n file: file.split('/').pop() || file,\n line: lineNum + 1,\n severity\n });\n }\n }\n }\n } catch {\n // Skip unreadable files\n }\n }\n\n phaseContext.vulnerabilities.push(...vulnerabilities);\n phaseContext.metrics['vulnerabilities_found'] = vulnerabilities.length;\n\n const summary = {\n high: vulnerabilities.filter(v => v.severity === 'high').length,\n medium: vulnerabilities.filter(v => v.severity === 'medium').length,\n low: vulnerabilities.filter(v => v.severity === 'low').length\n };\n\n return {\n success: true,\n data: {\n vulnerabilities: vulnerabilities.slice(0, 30),\n summary,\n filesScanned: maxFiles\n },\n patterns: vulnerabilities.map(v => `[${v.severity}] ${v.type}`)\n };\n});\n\n// COMPLEXITY ANALYSIS - Single implementation\nregisterUnifiedPhase('complexity-analysis', async (workerContext, phaseContext, options) => {\n const fs = await import('fs/promises');\n\n const complexityMarkers = [\n /\\bif\\s*\\(/g,\n /\\belse\\s+if\\s*\\(/g,\n /\\belse\\s*\\{/g,\n /\\bfor\\s*\\(/g,\n /\\bwhile\\s*\\(/g,\n /\\bdo\\s*\\{/g,\n /\\bswitch\\s*\\(/g,\n /\\bcase\\s+/g,\n /\\bcatch\\s*\\(/g,\n /\\?\\s*.*:/g, // Ternary\n /&&|\\|\\|/g, // Logical operators\n /\\?\\./g // Optional chaining\n ];\n\n const fileComplexity: Array<{ file: string; complexity: number; lines: number }> = [];\n let totalComplexity = 0;\n let totalLines = 0;\n\n const maxFiles = Math.min(phaseContext.files.length, 100);\n\n for (let i = 0; i < maxFiles; i++) {\n const file = phaseContext.files[i];\n try {\n const content = await fs.readFile(file, 'utf-8');\n const lines = content.split('\\n').length;\n let complexity = 1; // Base complexity\n\n for (const marker of complexityMarkers) {\n const matches = content.match(marker);\n if (matches) {\n complexity += matches.length;\n }\n }\n\n fileComplexity.push({\n file: file.split('/').pop() || file,\n complexity,\n lines\n });\n\n totalComplexity += complexity;\n totalLines += lines;\n } catch {\n // Skip unreadable files\n }\n }\n\n fileComplexity.sort((a, b) => b.complexity - a.complexity);\n\n phaseContext.metrics['total_complexity'] = totalComplexity;\n phaseContext.metrics['total_lines'] = totalLines;\n phaseContext.metrics['avg_complexity'] = maxFiles > 0 ? totalComplexity / maxFiles : 0;\n\n return {\n success: true,\n data: {\n avgComplexity: maxFiles > 0 ? (totalComplexity / maxFiles).toFixed(1) : '0',\n totalLines,\n filesAnalyzed: maxFiles,\n highComplexityFiles: fileComplexity.filter(f => f.complexity > 20).length,\n topFiles: fileComplexity.slice(0, 10)\n }\n };\n});\n\n// DEPENDENCY DISCOVERY - Single implementation\nregisterUnifiedPhase('dependency-discovery', async (workerContext, phaseContext, options) => {\n const fs = await import('fs/promises');\n const dependencies = new Map<string, string[]>();\n\n const importPatterns = [\n /import\\s+.*?from\\s+['\"]([^'\"]+)['\"]/g,\n /require\\s*\\(\\s*['\"]([^'\"]+)['\"]\\s*\\)/g,\n /import\\s*\\(\\s*['\"]([^'\"]+)['\"]\\s*\\)/g\n ];\n\n const maxFiles = Math.min(phaseContext.files.length, 100);\n let bytesProcessed = 0;\n\n for (let i = 0; i < maxFiles; i++) {\n const file = phaseContext.files[i];\n const fileName = file.split('/').pop() || file;\n const fileDeps: string[] = [];\n\n try {\n const content = await fs.readFile(file, 'utf-8');\n bytesProcessed += content.length;\n\n for (const pattern of importPatterns) {\n const matches = content.matchAll(pattern);\n for (const match of matches) {\n const dep = match[1];\n if (!fileDeps.includes(dep)) {\n fileDeps.push(dep);\n }\n }\n }\n\n if (fileDeps.length > 0) {\n dependencies.set(fileName, fileDeps);\n }\n } catch {\n // Skip unreadable files\n }\n }\n\n // Merge into context\n for (const [file, deps] of dependencies) {\n phaseContext.dependencies.set(file, deps);\n }\n\n phaseContext.bytes += bytesProcessed;\n phaseContext.metrics['dependencies_found'] = dependencies.size;\n\n return {\n success: true,\n data: {\n filesWithDeps: dependencies.size,\n totalDeps: Array.from(dependencies.values()).reduce((sum, deps) => sum + deps.length, 0),\n bytesProcessed\n }\n };\n});\n\n// SUMMARIZATION - Single implementation\nregisterUnifiedPhase('summarization', async (workerContext, phaseContext, options) => {\n return {\n success: true,\n data: {\n summary: {\n filesAnalyzed: phaseContext.files.length,\n patternsFound: phaseContext.patterns.length,\n uniquePatterns: [...new Set(phaseContext.patterns)].length,\n bytesProcessed: phaseContext.bytes,\n embeddingsGenerated: phaseContext.embeddings.size,\n vectorsStored: phaseContext.vectors.size,\n vulnerabilitiesFound: phaseContext.vulnerabilities.length,\n dependencyFiles: phaseContext.dependencies.size\n },\n metrics: phaseContext.metrics\n }\n };\n});\n\n// ============================================================================\n// Additional Phases (Not duplicated)\n// ============================================================================\n\n// API DISCOVERY\nregisterUnifiedPhase('api-discovery', async (workerContext, phaseContext, options) => {\n const fs = await import('fs/promises');\n const apis: Array<{ method: string; path: string; file: string }> = [];\n\n const apiPatterns = [\n /app\\.(get|post|put|delete|patch)\\s*\\(\\s*['\"]([^'\"]+)['\"]/gi,\n /router\\.(get|post|put|delete|patch)\\s*\\(\\s*['\"]([^'\"]+)['\"]/gi,\n /@(Get|Post|Put|Delete|Patch)\\s*\\(\\s*['\"]([^'\"]+)['\"]/gi,\n /fetch\\s*\\(\\s*['\"]([^'\"]+)['\"]/gi\n ];\n\n for (const file of phaseContext.files.slice(0, 100)) {\n try {\n const content = await fs.readFile(file, 'utf-8');\n for (const pattern of apiPatterns) {\n const matches = content.matchAll(pattern);\n for (const match of matches) {\n apis.push({\n method: match[1]?.toUpperCase() || 'GET',\n path: match[2],\n file: file.split('/').pop() || file\n });\n }\n }\n } catch {\n // Skip\n }\n }\n\n return {\n success: true,\n data: { apis: apis.slice(0, 50), totalApis: apis.length }\n };\n});\n\n// TODO EXTRACTION\nregisterUnifiedPhase('todo-extraction', async (workerContext, phaseContext, options) => {\n const fs = await import('fs/promises');\n const todos: Array<{ type: string; text: string; file: string; line: number }> = [];\n\n const todoPatterns = [\n { pattern: /\\/\\/\\s*TODO:?\\s*(.+?)$/gm, type: 'TODO' },\n { pattern: /\\/\\/\\s*FIXME:?\\s*(.+?)$/gm, type: 'FIXME' },\n { pattern: /\\/\\/\\s*HACK:?\\s*(.+?)$/gm, type: 'HACK' },\n { pattern: /\\/\\/\\s*XXX:?\\s*(.+?)$/gm, type: 'XXX' },\n { pattern: /\\/\\*\\s*TODO:?\\s*(.+?)\\*\\//gm, type: 'TODO' }\n ];\n\n for (const file of phaseContext.files.slice(0, 100)) {\n try {\n const content = await fs.readFile(file, 'utf-8');\n const lines = content.split('\\n');\n\n for (let lineNum = 0; lineNum < lines.length; lineNum++) {\n const line = lines[lineNum];\n for (const { pattern, type } of todoPatterns) {\n pattern.lastIndex = 0;\n const match = pattern.exec(line);\n if (match) {\n todos.push({\n type,\n text: match[1].trim(),\n file: file.split('/').pop() || file,\n line: lineNum + 1\n });\n }\n }\n }\n } catch {\n // Skip\n }\n }\n\n return {\n success: true,\n data: {\n todos: todos.slice(0, 50),\n counts: {\n TODO: todos.filter(t => t.type === 'TODO').length,\n FIXME: todos.filter(t => t.type === 'FIXME').length,\n HACK: todos.filter(t => t.type === 'HACK').length\n }\n },\n patterns: todos.map(t => `[${t.type}] ${t.text}`)\n };\n});\n\n// ============================================================================\n// Unified Pipeline Runner\n// ============================================================================\n\nexport async function runUnifiedPipeline(\n workerContext: WorkerContext,\n phases: string[],\n options: Record<string, unknown> = {}\n): Promise<{\n success: boolean;\n phases: string[];\n context: UnifiedPhaseContext;\n results: Record<string, PhaseResult>;\n duration: number;\n}> {\n const startTime = Date.now();\n const context = createUnifiedContext();\n const results: Record<string, PhaseResult> = {};\n const executedPhases: string[] = [];\n\n for (const phaseName of phases) {\n const executor = unifiedExecutors.get(phaseName);\n if (!executor) {\n console.warn(`Unknown phase: ${phaseName}`);\n continue;\n }\n\n try {\n const result = await executor(workerContext, context, options);\n results[phaseName] = result;\n executedPhases.push(phaseName);\n\n if (!result.success) {\n console.warn(`Phase ${phaseName} failed:`, result.error);\n }\n } catch (error) {\n results[phaseName] = {\n success: false,\n data: {},\n error: error instanceof Error ? error.message : String(error)\n };\n }\n }\n\n return {\n success: Object.values(results).every(r => r.success),\n phases: executedPhases,\n context,\n results,\n duration: Date.now() - startTime\n };\n}\n"]}