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,445 @@
1
+ /**
2
+ * Phase Executors - Composable analysis phases for custom workers
3
+ *
4
+ * REFACTORED: Core phases are now in consolidated-phases.ts to eliminate duplication.
5
+ * This module provides backwards compatibility and additional specialized phases.
6
+ */
7
+ import { createUnifiedContext, getUnifiedPhase, listUnifiedPhases } from './consolidated-phases.js';
8
+ export const createPhaseContext = createUnifiedContext;
9
+ const executors = new Map();
10
+ export function registerPhaseExecutor(type, executor) {
11
+ executors.set(type, executor);
12
+ }
13
+ export function getPhaseExecutor(type) {
14
+ // First check consolidated phases (primary)
15
+ const unified = getUnifiedPhase(type);
16
+ if (unified)
17
+ return unified;
18
+ // Then check local registry (specialized phases)
19
+ return executors.get(type);
20
+ }
21
+ export function listPhaseExecutors() {
22
+ const unifiedPhases = listUnifiedPhases();
23
+ const localPhases = Array.from(executors.keys());
24
+ return [...new Set([...unifiedPhases, ...localPhases])];
25
+ }
26
+ // ============================================================================
27
+ // Specialized Discovery Phases (not in consolidated)
28
+ // ============================================================================
29
+ registerPhaseExecutor('pattern-discovery', async (workerContext, phaseContext, options) => {
30
+ const fs = await import('fs/promises');
31
+ const path = await import('path');
32
+ const patterns = options.patterns || [];
33
+ const topic = workerContext.topic?.toLowerCase() || '';
34
+ const foundPatterns = [];
35
+ for (const file of phaseContext.files.slice(0, 50)) {
36
+ try {
37
+ const content = await fs.readFile(path.join(process.cwd(), file), 'utf-8');
38
+ phaseContext.bytes += content.length;
39
+ // Search for topic mentions
40
+ if (topic) {
41
+ const lines = content.split('\n');
42
+ lines.forEach((line, i) => {
43
+ if (line.toLowerCase().includes(topic)) {
44
+ foundPatterns.push(`${file}:${i + 1}: ${line.trim().slice(0, 80)}`);
45
+ }
46
+ });
47
+ }
48
+ // Search for custom patterns
49
+ for (const pattern of patterns) {
50
+ const regex = new RegExp(pattern, 'gi');
51
+ const matches = content.match(regex);
52
+ if (matches) {
53
+ foundPatterns.push(`${file}: ${matches.length} matches for "${pattern}"`);
54
+ }
55
+ }
56
+ }
57
+ catch { /* skip unreadable files */ }
58
+ }
59
+ phaseContext.patterns.push(...foundPatterns);
60
+ return {
61
+ success: true,
62
+ data: { patternsFound: foundPatterns.length },
63
+ patterns: foundPatterns
64
+ };
65
+ });
66
+ // dependency-discovery and api-discovery are now in consolidated-phases.ts
67
+ // ============================================================================
68
+ // Analysis Phases
69
+ // ============================================================================
70
+ registerPhaseExecutor('static-analysis', async (workerContext, phaseContext, options) => {
71
+ const fs = await import('fs/promises');
72
+ const path = await import('path');
73
+ const stats = {
74
+ functions: 0,
75
+ classes: 0,
76
+ exports: 0,
77
+ imports: 0,
78
+ comments: 0,
79
+ todos: 0
80
+ };
81
+ for (const file of phaseContext.files.slice(0, 50)) {
82
+ try {
83
+ const content = await fs.readFile(path.join(process.cwd(), file), 'utf-8');
84
+ phaseContext.bytes += content.length;
85
+ stats.functions += (content.match(/function\s+\w+|=>\s*{|\(\)\s*{/g) || []).length;
86
+ stats.classes += (content.match(/class\s+\w+/g) || []).length;
87
+ stats.exports += (content.match(/export\s+(default\s+)?(function|class|const|let|var)/g) || []).length;
88
+ stats.imports += (content.match(/import\s+/g) || []).length;
89
+ stats.comments += (content.match(/\/\/|\/\*|\*\//g) || []).length;
90
+ stats.todos += (content.match(/TODO|FIXME|HACK|XXX/gi) || []).length;
91
+ if (stats.todos > 0) {
92
+ const todoMatches = content.match(/\/\/\s*(TODO|FIXME|HACK|XXX):.*/gi) || [];
93
+ phaseContext.patterns.push(...todoMatches.slice(0, 5).map(t => `${file}: ${t.trim()}`));
94
+ }
95
+ }
96
+ catch { /* skip */ }
97
+ }
98
+ Object.entries(stats).forEach(([key, val]) => {
99
+ phaseContext.metrics[key] = val;
100
+ });
101
+ return {
102
+ success: true,
103
+ data: stats
104
+ };
105
+ });
106
+ // complexity-analysis and security-analysis are now in consolidated-phases.ts
107
+ registerPhaseExecutor('performance-analysis', async (workerContext, phaseContext, options) => {
108
+ const fs = await import('fs/promises');
109
+ const path = await import('path');
110
+ const warnings = [];
111
+ const perfPatterns = [
112
+ { pattern: /\.forEach\s*\(/gi, type: 'forEach-in-hot-path' },
113
+ { pattern: /JSON\.parse\s*\(.*JSON\.stringify/gi, type: 'deep-clone' },
114
+ { pattern: /new\s+RegExp\s*\(/gi, type: 'dynamic-regex' },
115
+ { pattern: /async\s+.*\.map\s*\(/gi, type: 'async-in-loop' },
116
+ { pattern: /await\s+.*\.forEach/gi, type: 'await-forEach' }
117
+ ];
118
+ for (const file of phaseContext.files.slice(0, 50)) {
119
+ try {
120
+ const content = await fs.readFile(path.join(process.cwd(), file), 'utf-8');
121
+ const lines = content.split('\n');
122
+ phaseContext.bytes += content.length;
123
+ lines.forEach((line, i) => {
124
+ for (const { pattern, type } of perfPatterns) {
125
+ pattern.lastIndex = 0;
126
+ if (pattern.test(line)) {
127
+ warnings.push({ file, type, line: i + 1 });
128
+ }
129
+ }
130
+ });
131
+ }
132
+ catch { /* skip */ }
133
+ }
134
+ phaseContext.patterns.push(...warnings.map(w => `[perf] ${w.type}: ${w.file}:${w.line}`));
135
+ phaseContext.metrics['perf_warnings'] = warnings.length;
136
+ return {
137
+ success: true,
138
+ data: { warnings, count: warnings.length }
139
+ };
140
+ });
141
+ registerPhaseExecutor('import-analysis', async (workerContext, phaseContext, options) => {
142
+ const fs = await import('fs/promises');
143
+ const path = await import('path');
144
+ const imports = {};
145
+ for (const file of phaseContext.files.slice(0, 100)) {
146
+ try {
147
+ const content = await fs.readFile(path.join(process.cwd(), file), 'utf-8');
148
+ phaseContext.bytes += content.length;
149
+ const importMatches = content.match(/from\s+['"]([^'"]+)['"]/g) || [];
150
+ for (const match of importMatches) {
151
+ const pkg = match.replace(/from\s+['"]/, '').replace(/['"]/, '');
152
+ imports[pkg] = (imports[pkg] || 0) + 1;
153
+ }
154
+ }
155
+ catch { /* skip */ }
156
+ }
157
+ const sorted = Object.entries(imports).sort((a, b) => b[1] - a[1]);
158
+ phaseContext.patterns.push(...sorted.slice(0, 10).map(([pkg, count]) => `${pkg}: ${count} imports`));
159
+ phaseContext.metrics['unique_imports'] = Object.keys(imports).length;
160
+ return {
161
+ success: true,
162
+ data: { imports: Object.fromEntries(sorted.slice(0, 20)) }
163
+ };
164
+ });
165
+ registerPhaseExecutor('type-analysis', async (workerContext, phaseContext, options) => {
166
+ const fs = await import('fs/promises');
167
+ const path = await import('path');
168
+ const types = [];
169
+ for (const file of phaseContext.files.filter(f => f.endsWith('.ts') || f.endsWith('.tsx')).slice(0, 50)) {
170
+ try {
171
+ const content = await fs.readFile(path.join(process.cwd(), file), 'utf-8');
172
+ phaseContext.bytes += content.length;
173
+ // Extract interfaces
174
+ const interfaces = content.match(/interface\s+(\w+)/g) || [];
175
+ types.push(...interfaces.map(i => ({
176
+ name: i.replace('interface ', ''),
177
+ file,
178
+ kind: 'interface'
179
+ })));
180
+ // Extract types
181
+ const typeAliases = content.match(/type\s+(\w+)\s*=/g) || [];
182
+ types.push(...typeAliases.map(t => ({
183
+ name: t.replace(/type\s+/, '').replace(/\s*=/, ''),
184
+ file,
185
+ kind: 'type'
186
+ })));
187
+ // Extract enums
188
+ const enums = content.match(/enum\s+(\w+)/g) || [];
189
+ types.push(...enums.map(e => ({
190
+ name: e.replace('enum ', ''),
191
+ file,
192
+ kind: 'enum'
193
+ })));
194
+ }
195
+ catch { /* skip */ }
196
+ }
197
+ phaseContext.patterns.push(...types.slice(0, 20).map(t => `${t.kind} ${t.name} (${t.file})`));
198
+ phaseContext.metrics['types_found'] = types.length;
199
+ return {
200
+ success: true,
201
+ data: { types, count: types.length }
202
+ };
203
+ });
204
+ // ============================================================================
205
+ // Pattern Extraction Phases (unique ones not in consolidated)
206
+ // ============================================================================
207
+ // pattern-extraction and todo-extraction are now in consolidated-phases.ts
208
+ registerPhaseExecutor('secret-detection', async (workerContext, phaseContext, options) => {
209
+ const fs = await import('fs/promises');
210
+ const path = await import('path');
211
+ const secrets = [];
212
+ const secretPatterns = [
213
+ { pattern: /api[_-]?key\s*[:=]\s*['"][^'"]{10,}['"]/gi, type: 'api-key' },
214
+ { pattern: /password\s*[:=]\s*['"][^'"]+['"]/gi, type: 'password' },
215
+ { pattern: /secret\s*[:=]\s*['"][^'"]{10,}['"]/gi, type: 'secret' },
216
+ { pattern: /token\s*[:=]\s*['"][^'"]{20,}['"]/gi, type: 'token' },
217
+ { pattern: /private[_-]?key/gi, type: 'private-key' },
218
+ { pattern: /-----BEGIN.*PRIVATE KEY-----/gi, type: 'pem-key' },
219
+ { pattern: /Bearer\s+[a-zA-Z0-9_-]{20,}/gi, type: 'bearer-token' },
220
+ { pattern: /ghp_[a-zA-Z0-9]{36}/gi, type: 'github-token' },
221
+ { pattern: /sk-[a-zA-Z0-9]{32,}/gi, type: 'openai-key' }
222
+ ];
223
+ for (const file of phaseContext.files.slice(0, 200)) {
224
+ // Skip common safe files
225
+ if (file.includes('.test.') || file.includes('.spec.') || file.includes('mock'))
226
+ continue;
227
+ try {
228
+ const content = await fs.readFile(path.join(process.cwd(), file), 'utf-8');
229
+ const lines = content.split('\n');
230
+ phaseContext.bytes += content.length;
231
+ lines.forEach((line, i) => {
232
+ for (const { pattern, type } of secretPatterns) {
233
+ pattern.lastIndex = 0;
234
+ if (pattern.test(line)) {
235
+ secrets.push({ file, line: i + 1, type });
236
+ }
237
+ }
238
+ });
239
+ }
240
+ catch { /* skip */ }
241
+ }
242
+ phaseContext.patterns.push(...secrets.map(s => `[SECRET] ${s.type} in ${s.file}:${s.line}`));
243
+ phaseContext.metrics['secrets_found'] = secrets.length;
244
+ return {
245
+ success: true,
246
+ data: {
247
+ secrets: secrets.slice(0, 20),
248
+ count: secrets.length,
249
+ riskLevel: secrets.length > 5 ? 'high' : secrets.length > 0 ? 'medium' : 'low'
250
+ }
251
+ };
252
+ });
253
+ registerPhaseExecutor('code-smell-detection', async (workerContext, phaseContext, options) => {
254
+ const fs = await import('fs/promises');
255
+ const path = await import('path');
256
+ const smells = [];
257
+ const smellPatterns = [
258
+ { pattern: /console\.(log|debug|info)\s*\(/gi, type: 'console-log' },
259
+ { pattern: /debugger;/gi, type: 'debugger' },
260
+ { pattern: /\/\/\s*@ts-ignore/gi, type: 'ts-ignore' },
261
+ { pattern: /any(?:\s|[,;>)\]])/gi, type: 'any-type' },
262
+ { pattern: /eslint-disable/gi, type: 'eslint-disable' },
263
+ { pattern: /\s{4,}function|\s{4,}=>/gi, type: 'deep-nesting' }
264
+ ];
265
+ for (const file of phaseContext.files.slice(0, 50)) {
266
+ try {
267
+ const content = await fs.readFile(path.join(process.cwd(), file), 'utf-8');
268
+ const lines = content.split('\n');
269
+ phaseContext.bytes += content.length;
270
+ lines.forEach((line, i) => {
271
+ for (const { pattern, type } of smellPatterns) {
272
+ pattern.lastIndex = 0;
273
+ if (pattern.test(line)) {
274
+ smells.push({ file, type, line: i + 1 });
275
+ }
276
+ }
277
+ });
278
+ }
279
+ catch { /* skip */ }
280
+ }
281
+ phaseContext.patterns.push(...smells.slice(0, 20).map(s => `[smell] ${s.type}: ${s.file}:${s.line}`));
282
+ phaseContext.metrics['code_smells'] = smells.length;
283
+ return {
284
+ success: true,
285
+ data: { smells: smells.slice(0, 30), count: smells.length }
286
+ };
287
+ });
288
+ // ============================================================================
289
+ // Build Phases
290
+ // ============================================================================
291
+ registerPhaseExecutor('graph-build', async (workerContext, phaseContext, options) => {
292
+ // Build on dependency-discovery results
293
+ const graph = {};
294
+ for (const [file, deps] of phaseContext.dependencies) {
295
+ graph[file] = deps;
296
+ }
297
+ const nodes = Object.keys(graph).length;
298
+ const edges = Object.values(graph).flat().length;
299
+ phaseContext.patterns.push(`Dependency graph: ${nodes} nodes, ${edges} edges`);
300
+ phaseContext.metrics['graph_nodes'] = nodes;
301
+ phaseContext.metrics['graph_edges'] = edges;
302
+ return {
303
+ success: true,
304
+ data: { nodes, edges, graph: Object.fromEntries(Object.entries(graph).slice(0, 20)) }
305
+ };
306
+ });
307
+ registerPhaseExecutor('call-graph', async (workerContext, phaseContext, options) => {
308
+ const fs = await import('fs/promises');
309
+ const path = await import('path');
310
+ const calls = {};
311
+ for (const file of phaseContext.files.slice(0, 30)) {
312
+ try {
313
+ const content = await fs.readFile(path.join(process.cwd(), file), 'utf-8');
314
+ phaseContext.bytes += content.length;
315
+ // Extract function definitions
316
+ const funcDefs = content.match(/(?:function\s+|const\s+|let\s+|var\s+)(\w+)\s*(?:=\s*(?:async\s*)?\([^)]*\)\s*=>|\s*=\s*function|\s*\([^)]*\)\s*{)/g) || [];
317
+ const funcNames = funcDefs.map(f => {
318
+ const match = f.match(/(?:function\s+|const\s+|let\s+|var\s+)(\w+)/);
319
+ return match ? match[1] : '';
320
+ }).filter(Boolean);
321
+ // Extract function calls
322
+ const funcCalls = content.match(/\b\w+\s*\(/g) || [];
323
+ const calledFuncs = funcCalls.map(c => c.replace(/\s*\(/, '')).filter(Boolean);
324
+ calls[file] = [...new Set(calledFuncs)];
325
+ }
326
+ catch { /* skip */ }
327
+ }
328
+ phaseContext.metrics['call_graph_files'] = Object.keys(calls).length;
329
+ return {
330
+ success: true,
331
+ data: { callGraph: calls }
332
+ };
333
+ });
334
+ registerPhaseExecutor('dependency-graph', async (workerContext, phaseContext, options) => {
335
+ // Alias for graph-build
336
+ return getPhaseExecutor('graph-build')(workerContext, phaseContext, options);
337
+ });
338
+ // ============================================================================
339
+ // Learning Phases
340
+ // ============================================================================
341
+ registerPhaseExecutor('vectorization', async (workerContext, phaseContext, options) => {
342
+ // Placeholder - actual vectorization happens in RuVector integration
343
+ phaseContext.patterns.push(`Vectorization: ${phaseContext.patterns.length} patterns ready`);
344
+ return {
345
+ success: true,
346
+ data: { patternsForVectorization: phaseContext.patterns.length }
347
+ };
348
+ });
349
+ // embedding-generation is now in consolidated-phases.ts with real ONNX implementation
350
+ registerPhaseExecutor('pattern-storage', async (workerContext, phaseContext, options) => {
351
+ // Placeholder - storage happens in RuVector/ReasoningBank
352
+ phaseContext.patterns.push(`Pattern storage: ${phaseContext.patterns.length} patterns`);
353
+ return {
354
+ success: true,
355
+ data: { patternsStored: phaseContext.patterns.length }
356
+ };
357
+ });
358
+ registerPhaseExecutor('sona-training', async (workerContext, phaseContext, options) => {
359
+ // Placeholder - SONA training happens in RuVector integration
360
+ phaseContext.patterns.push('SONA training triggered');
361
+ return {
362
+ success: true,
363
+ data: { sonaTrainingTriggered: true }
364
+ };
365
+ });
366
+ // ============================================================================
367
+ // Output Phases (summarization is in consolidated-phases.ts)
368
+ // ============================================================================
369
+ registerPhaseExecutor('report-generation', async (workerContext, phaseContext, options) => {
370
+ const report = {
371
+ workerId: workerContext.workerId,
372
+ trigger: workerContext.trigger,
373
+ topic: workerContext.topic,
374
+ timestamp: new Date().toISOString(),
375
+ summary: {
376
+ filesAnalyzed: phaseContext.files.length,
377
+ patternsFound: phaseContext.patterns.length,
378
+ bytesProcessed: phaseContext.bytes
379
+ },
380
+ metrics: phaseContext.metrics,
381
+ topPatterns: phaseContext.patterns.slice(0, 20),
382
+ phaseData: Object.fromEntries(phaseContext.phaseData)
383
+ };
384
+ return {
385
+ success: true,
386
+ data: { report }
387
+ };
388
+ });
389
+ registerPhaseExecutor('indexing', async (workerContext, phaseContext, options) => {
390
+ phaseContext.patterns.push(`Indexed ${phaseContext.files.length} files`);
391
+ return {
392
+ success: true,
393
+ data: { indexed: phaseContext.files.length }
394
+ };
395
+ });
396
+ // ============================================================================
397
+ // Execute Phase Pipeline
398
+ // ============================================================================
399
+ export async function executePhasePipeline(workerContext, phases, onProgress) {
400
+ const phaseContext = createPhaseContext();
401
+ const results = new Map();
402
+ const errors = [];
403
+ for (let i = 0; i < phases.length; i++) {
404
+ if (workerContext.signal.aborted) {
405
+ errors.push('Pipeline aborted');
406
+ break;
407
+ }
408
+ const phase = phases[i];
409
+ const phaseName = phase.name || phase.type;
410
+ onProgress?.(phaseName, Math.round((i / phases.length) * 100));
411
+ const executor = phase.type === 'custom' && phase.executor
412
+ ? async (ctx, pCtx, opts) => {
413
+ return phase.executor(ctx, opts);
414
+ }
415
+ : getPhaseExecutor(phase.type);
416
+ if (!executor) {
417
+ errors.push(`Unknown phase type: ${phase.type}`);
418
+ continue;
419
+ }
420
+ try {
421
+ const result = await Promise.race([
422
+ executor(workerContext, phaseContext, phase.options || {}),
423
+ new Promise((_, reject) => setTimeout(() => reject(new Error('Phase timeout')), phase.timeout || 60000))
424
+ ]);
425
+ results.set(phaseName, result);
426
+ phaseContext.phaseData.set(phaseName, result.data);
427
+ if (!result.success) {
428
+ errors.push(`Phase ${phaseName} failed: ${result.error || 'Unknown error'}`);
429
+ }
430
+ }
431
+ catch (error) {
432
+ const errMsg = error instanceof Error ? error.message : 'Phase execution failed';
433
+ errors.push(`Phase ${phaseName}: ${errMsg}`);
434
+ results.set(phaseName, { success: false, data: {}, error: errMsg });
435
+ }
436
+ }
437
+ onProgress?.('complete', 100);
438
+ return {
439
+ success: errors.length === 0,
440
+ phaseContext,
441
+ results,
442
+ errors
443
+ };
444
+ }
445
+ //# sourceMappingURL=phase-executors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"phase-executors.js","sourceRoot":"","sources":["../../src/workers/phase-executors.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH,OAAO,EAEL,oBAAoB,EACpB,eAAe,EACf,iBAAiB,EAClB,MAAM,0BAA0B,CAAC;AAIlC,MAAM,CAAC,MAAM,kBAAkB,GAAG,oBAAoB,CAAC;AAYvD,MAAM,SAAS,GAAG,IAAI,GAAG,EAAyB,CAAC;AAEnD,MAAM,UAAU,qBAAqB,CAAC,IAAY,EAAE,QAAuB;IACzE,SAAS,CAAC,GAAG,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;AAChC,CAAC;AAED,MAAM,UAAU,gBAAgB,CAAC,IAAY;IAC3C,4CAA4C;IAC5C,MAAM,OAAO,GAAG,eAAe,CAAC,IAAI,CAAC,CAAC;IACtC,IAAI,OAAO;QAAE,OAAO,OAAO,CAAC;IAC5B,iDAAiD;IACjD,OAAO,SAAS,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;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AC1D,IAAI,OAAO,CAAc,CAAC,CAAC,EAAE,MAAM,EAAE,EAAE,CACrC,UAAU,CAAC,GAAG,EAAE,CAAC,MAAM,CAAC,IAAI,KAAK,CAAC,eAAe,CAAC,CAAC,EAAE,KAAK,CAAC,OAAO,IAAI,KAAK,CAAC,CAC7E;aACF,CAAC,CAAC;YAEH,OAAO,CAAC,GAAG,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC;YAC/B,YAAY,CAAC,SAAS,CAAC,GAAG,CAAC,SAAS,EAAE,MAAM,CAAC,IAAI,CAAC,CAAC;YAEnD,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;gBACpB,MAAM,CAAC,IAAI,CAAC,SAAS,SAAS,YAAY,MAAM,CAAC,KAAK,IAAI,eAAe,EAAE,CAAC,CAAC;YAC/E,CAAC;QACH,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,MAAM,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,wBAAwB,CAAC;YACjF,MAAM,CAAC,IAAI,CAAC,SAAS,SAAS,KAAK,MAAM,EAAE,CAAC,CAAC;YAC7C,OAAO,CAAC,GAAG,CAAC,SAAS,EAAE,EAAE,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC,CAAC;QACtE,CAAC;IACH,CAAC;IAED,UAAU,EAAE,CAAC,UAAU,EAAE,GAAG,CAAC,CAAC;IAE9B,OAAO;QACL,OAAO,EAAE,MAAM,CAAC,MAAM,KAAK,CAAC;QAC5B,YAAY;QACZ,OAAO;QACP,MAAM;KACP,CAAC;AACJ,CAAC","sourcesContent":["/**\n * Phase Executors - Composable analysis phases for custom workers\n *\n * REFACTORED: Core phases are now in consolidated-phases.ts to eliminate duplication.\n * This module provides backwards compatibility and additional specialized phases.\n */\n\nimport { WorkerContext } from './types.js';\nimport { PhaseConfig, PhaseResult } from './custom-worker-config.js';\nimport {\n UnifiedPhaseContext,\n createUnifiedContext,\n getUnifiedPhase,\n listUnifiedPhases\n} from './consolidated-phases.js';\n\n// Re-export context types for backwards compatibility\nexport type PhaseContext = UnifiedPhaseContext;\nexport const createPhaseContext = createUnifiedContext;\n\n// ============================================================================\n// Phase Executor Registry - Delegates to consolidated phases\n// ============================================================================\n\nexport type PhaseExecutor = (\n workerContext: WorkerContext,\n phaseContext: PhaseContext,\n options: Record<string, unknown>\n) => Promise<PhaseResult>;\n\nconst executors = new Map<string, PhaseExecutor>();\n\nexport function registerPhaseExecutor(type: string, executor: PhaseExecutor): void {\n executors.set(type, executor);\n}\n\nexport function getPhaseExecutor(type: string): PhaseExecutor | undefined {\n // First check consolidated phases (primary)\n const unified = getUnifiedPhase(type);\n if (unified) return unified;\n // Then check local registry (specialized phases)\n return executors.get(type);\n}\n\nexport function listPhaseExecutors(): string[] {\n const unifiedPhases = listUnifiedPhases();\n const localPhases = Array.from(executors.keys());\n return [...new Set([...unifiedPhases, ...localPhases])];\n}\n\n// ============================================================================\n// Specialized Discovery Phases (not in consolidated)\n// ============================================================================\n\nregisterPhaseExecutor('pattern-discovery', async (workerContext, phaseContext, options) => {\n const fs = await import('fs/promises');\n const path = await import('path');\n const patterns = (options.patterns as string[]) || [];\n const topic = workerContext.topic?.toLowerCase() || '';\n\n const foundPatterns: string[] = [];\n\n for (const file of phaseContext.files.slice(0, 50)) {\n try {\n const content = await fs.readFile(path.join(process.cwd(), file), 'utf-8');\n phaseContext.bytes += content.length;\n\n // Search for topic mentions\n if (topic) {\n const lines = content.split('\\n');\n lines.forEach((line, i) => {\n if (line.toLowerCase().includes(topic)) {\n foundPatterns.push(`${file}:${i + 1}: ${line.trim().slice(0, 80)}`);\n }\n });\n }\n\n // Search for custom patterns\n for (const pattern of patterns) {\n const regex = new RegExp(pattern, 'gi');\n const matches = content.match(regex);\n if (matches) {\n foundPatterns.push(`${file}: ${matches.length} matches for \"${pattern}\"`);\n }\n }\n } catch { /* skip unreadable files */ }\n }\n\n phaseContext.patterns.push(...foundPatterns);\n return {\n success: true,\n data: { patternsFound: foundPatterns.length },\n patterns: foundPatterns\n };\n});\n\n// dependency-discovery and api-discovery are now in consolidated-phases.ts\n\n// ============================================================================\n// Analysis Phases\n// ============================================================================\n\nregisterPhaseExecutor('static-analysis', async (workerContext, phaseContext, options) => {\n const fs = await import('fs/promises');\n const path = await import('path');\n\n const stats = {\n functions: 0,\n classes: 0,\n exports: 0,\n imports: 0,\n comments: 0,\n todos: 0\n };\n\n for (const file of phaseContext.files.slice(0, 50)) {\n try {\n const content = await fs.readFile(path.join(process.cwd(), file), 'utf-8');\n phaseContext.bytes += content.length;\n\n stats.functions += (content.match(/function\\s+\\w+|=>\\s*{|\\(\\)\\s*{/g) || []).length;\n stats.classes += (content.match(/class\\s+\\w+/g) || []).length;\n stats.exports += (content.match(/export\\s+(default\\s+)?(function|class|const|let|var)/g) || []).length;\n stats.imports += (content.match(/import\\s+/g) || []).length;\n stats.comments += (content.match(/\\/\\/|\\/\\*|\\*\\//g) || []).length;\n stats.todos += (content.match(/TODO|FIXME|HACK|XXX/gi) || []).length;\n\n if (stats.todos > 0) {\n const todoMatches = content.match(/\\/\\/\\s*(TODO|FIXME|HACK|XXX):.*/gi) || [];\n phaseContext.patterns.push(...todoMatches.slice(0, 5).map(t => `${file}: ${t.trim()}`));\n }\n } catch { /* skip */ }\n }\n\n Object.entries(stats).forEach(([key, val]) => {\n phaseContext.metrics[key] = val;\n });\n\n return {\n success: true,\n data: stats\n };\n});\n\n// complexity-analysis and security-analysis are now in consolidated-phases.ts\n\nregisterPhaseExecutor('performance-analysis', async (workerContext, phaseContext, options) => {\n const fs = await import('fs/promises');\n const path = await import('path');\n\n const warnings: Array<{ file: string; type: string; line: number }> = [];\n const perfPatterns = [\n { pattern: /\\.forEach\\s*\\(/gi, type: 'forEach-in-hot-path' },\n { pattern: /JSON\\.parse\\s*\\(.*JSON\\.stringify/gi, type: 'deep-clone' },\n { pattern: /new\\s+RegExp\\s*\\(/gi, type: 'dynamic-regex' },\n { pattern: /async\\s+.*\\.map\\s*\\(/gi, type: 'async-in-loop' },\n { pattern: /await\\s+.*\\.forEach/gi, type: 'await-forEach' }\n ];\n\n for (const file of phaseContext.files.slice(0, 50)) {\n try {\n const content = await fs.readFile(path.join(process.cwd(), file), 'utf-8');\n const lines = content.split('\\n');\n phaseContext.bytes += content.length;\n\n lines.forEach((line, i) => {\n for (const { pattern, type } of perfPatterns) {\n pattern.lastIndex = 0;\n if (pattern.test(line)) {\n warnings.push({ file, type, line: i + 1 });\n }\n }\n });\n } catch { /* skip */ }\n }\n\n phaseContext.patterns.push(...warnings.map(w => `[perf] ${w.type}: ${w.file}:${w.line}`));\n phaseContext.metrics['perf_warnings'] = warnings.length;\n\n return {\n success: true,\n data: { warnings, count: warnings.length }\n };\n});\n\nregisterPhaseExecutor('import-analysis', async (workerContext, phaseContext, options) => {\n const fs = await import('fs/promises');\n const path = await import('path');\n\n const imports: Record<string, number> = {};\n\n for (const file of phaseContext.files.slice(0, 100)) {\n try {\n const content = await fs.readFile(path.join(process.cwd(), file), 'utf-8');\n phaseContext.bytes += content.length;\n\n const importMatches = content.match(/from\\s+['\"]([^'\"]+)['\"]/g) || [];\n for (const match of importMatches) {\n const pkg = match.replace(/from\\s+['\"]/, '').replace(/['\"]/, '');\n imports[pkg] = (imports[pkg] || 0) + 1;\n }\n } catch { /* skip */ }\n }\n\n const sorted = Object.entries(imports).sort((a, b) => b[1] - a[1]);\n phaseContext.patterns.push(...sorted.slice(0, 10).map(([pkg, count]) => `${pkg}: ${count} imports`));\n phaseContext.metrics['unique_imports'] = Object.keys(imports).length;\n\n return {\n success: true,\n data: { imports: Object.fromEntries(sorted.slice(0, 20)) }\n };\n});\n\nregisterPhaseExecutor('type-analysis', async (workerContext, phaseContext, options) => {\n const fs = await import('fs/promises');\n const path = await import('path');\n\n const types: Array<{ name: string; file: string; kind: string }> = [];\n\n for (const file of phaseContext.files.filter(f => f.endsWith('.ts') || f.endsWith('.tsx')).slice(0, 50)) {\n try {\n const content = await fs.readFile(path.join(process.cwd(), file), 'utf-8');\n phaseContext.bytes += content.length;\n\n // Extract interfaces\n const interfaces = content.match(/interface\\s+(\\w+)/g) || [];\n types.push(...interfaces.map(i => ({\n name: i.replace('interface ', ''),\n file,\n kind: 'interface'\n })));\n\n // Extract types\n const typeAliases = content.match(/type\\s+(\\w+)\\s*=/g) || [];\n types.push(...typeAliases.map(t => ({\n name: t.replace(/type\\s+/, '').replace(/\\s*=/, ''),\n file,\n kind: 'type'\n })));\n\n // Extract enums\n const enums = content.match(/enum\\s+(\\w+)/g) || [];\n types.push(...enums.map(e => ({\n name: e.replace('enum ', ''),\n file,\n kind: 'enum'\n })));\n } catch { /* skip */ }\n }\n\n phaseContext.patterns.push(...types.slice(0, 20).map(t => `${t.kind} ${t.name} (${t.file})`));\n phaseContext.metrics['types_found'] = types.length;\n\n return {\n success: true,\n data: { types, count: types.length }\n };\n});\n\n// ============================================================================\n// Pattern Extraction Phases (unique ones not in consolidated)\n// ============================================================================\n\n// pattern-extraction and todo-extraction are now in consolidated-phases.ts\n\nregisterPhaseExecutor('secret-detection', async (workerContext, phaseContext, options) => {\n const fs = await import('fs/promises');\n const path = await import('path');\n\n const secrets: Array<{ file: string; line: number; type: string }> = [];\n const secretPatterns = [\n { pattern: /api[_-]?key\\s*[:=]\\s*['\"][^'\"]{10,}['\"]/gi, type: 'api-key' },\n { pattern: /password\\s*[:=]\\s*['\"][^'\"]+['\"]/gi, type: 'password' },\n { pattern: /secret\\s*[:=]\\s*['\"][^'\"]{10,}['\"]/gi, type: 'secret' },\n { pattern: /token\\s*[:=]\\s*['\"][^'\"]{20,}['\"]/gi, type: 'token' },\n { pattern: /private[_-]?key/gi, type: 'private-key' },\n { pattern: /-----BEGIN.*PRIVATE KEY-----/gi, type: 'pem-key' },\n { pattern: /Bearer\\s+[a-zA-Z0-9_-]{20,}/gi, type: 'bearer-token' },\n { pattern: /ghp_[a-zA-Z0-9]{36}/gi, type: 'github-token' },\n { pattern: /sk-[a-zA-Z0-9]{32,}/gi, type: 'openai-key' }\n ];\n\n for (const file of phaseContext.files.slice(0, 200)) {\n // Skip common safe files\n if (file.includes('.test.') || file.includes('.spec.') || file.includes('mock')) continue;\n\n try {\n const content = await fs.readFile(path.join(process.cwd(), file), 'utf-8');\n const lines = content.split('\\n');\n phaseContext.bytes += content.length;\n\n lines.forEach((line, i) => {\n for (const { pattern, type } of secretPatterns) {\n pattern.lastIndex = 0;\n if (pattern.test(line)) {\n secrets.push({ file, line: i + 1, type });\n }\n }\n });\n } catch { /* skip */ }\n }\n\n phaseContext.patterns.push(...secrets.map(s => `[SECRET] ${s.type} in ${s.file}:${s.line}`));\n phaseContext.metrics['secrets_found'] = secrets.length;\n\n return {\n success: true,\n data: {\n secrets: secrets.slice(0, 20),\n count: secrets.length,\n riskLevel: secrets.length > 5 ? 'high' : secrets.length > 0 ? 'medium' : 'low'\n }\n };\n});\n\nregisterPhaseExecutor('code-smell-detection', async (workerContext, phaseContext, options) => {\n const fs = await import('fs/promises');\n const path = await import('path');\n\n const smells: Array<{ file: string; type: string; line: number }> = [];\n const smellPatterns = [\n { pattern: /console\\.(log|debug|info)\\s*\\(/gi, type: 'console-log' },\n { pattern: /debugger;/gi, type: 'debugger' },\n { pattern: /\\/\\/\\s*@ts-ignore/gi, type: 'ts-ignore' },\n { pattern: /any(?:\\s|[,;>)\\]])/gi, type: 'any-type' },\n { pattern: /eslint-disable/gi, type: 'eslint-disable' },\n { pattern: /\\s{4,}function|\\s{4,}=>/gi, type: 'deep-nesting' }\n ];\n\n for (const file of phaseContext.files.slice(0, 50)) {\n try {\n const content = await fs.readFile(path.join(process.cwd(), file), 'utf-8');\n const lines = content.split('\\n');\n phaseContext.bytes += content.length;\n\n lines.forEach((line, i) => {\n for (const { pattern, type } of smellPatterns) {\n pattern.lastIndex = 0;\n if (pattern.test(line)) {\n smells.push({ file, type, line: i + 1 });\n }\n }\n });\n } catch { /* skip */ }\n }\n\n phaseContext.patterns.push(...smells.slice(0, 20).map(s => `[smell] ${s.type}: ${s.file}:${s.line}`));\n phaseContext.metrics['code_smells'] = smells.length;\n\n return {\n success: true,\n data: { smells: smells.slice(0, 30), count: smells.length }\n };\n});\n\n// ============================================================================\n// Build Phases\n// ============================================================================\n\nregisterPhaseExecutor('graph-build', async (workerContext, phaseContext, options) => {\n // Build on dependency-discovery results\n const graph: Record<string, string[]> = {};\n\n for (const [file, deps] of phaseContext.dependencies) {\n graph[file] = deps;\n }\n\n const nodes = Object.keys(graph).length;\n const edges = Object.values(graph).flat().length;\n\n phaseContext.patterns.push(`Dependency graph: ${nodes} nodes, ${edges} edges`);\n phaseContext.metrics['graph_nodes'] = nodes;\n phaseContext.metrics['graph_edges'] = edges;\n\n return {\n success: true,\n data: { nodes, edges, graph: Object.fromEntries(Object.entries(graph).slice(0, 20)) }\n };\n});\n\nregisterPhaseExecutor('call-graph', async (workerContext, phaseContext, options) => {\n const fs = await import('fs/promises');\n const path = await import('path');\n\n const calls: Record<string, string[]> = {};\n\n for (const file of phaseContext.files.slice(0, 30)) {\n try {\n const content = await fs.readFile(path.join(process.cwd(), file), 'utf-8');\n phaseContext.bytes += content.length;\n\n // Extract function definitions\n const funcDefs = content.match(/(?:function\\s+|const\\s+|let\\s+|var\\s+)(\\w+)\\s*(?:=\\s*(?:async\\s*)?\\([^)]*\\)\\s*=>|\\s*=\\s*function|\\s*\\([^)]*\\)\\s*{)/g) || [];\n const funcNames = funcDefs.map(f => {\n const match = f.match(/(?:function\\s+|const\\s+|let\\s+|var\\s+)(\\w+)/);\n return match ? match[1] : '';\n }).filter(Boolean);\n\n // Extract function calls\n const funcCalls = content.match(/\\b\\w+\\s*\\(/g) || [];\n const calledFuncs = funcCalls.map(c => c.replace(/\\s*\\(/, '')).filter(Boolean);\n\n calls[file] = [...new Set(calledFuncs)];\n } catch { /* skip */ }\n }\n\n phaseContext.metrics['call_graph_files'] = Object.keys(calls).length;\n\n return {\n success: true,\n data: { callGraph: calls }\n };\n});\n\nregisterPhaseExecutor('dependency-graph', async (workerContext, phaseContext, options) => {\n // Alias for graph-build\n return getPhaseExecutor('graph-build')!(workerContext, phaseContext, options);\n});\n\n// ============================================================================\n// Learning Phases\n// ============================================================================\n\nregisterPhaseExecutor('vectorization', async (workerContext, phaseContext, options) => {\n // Placeholder - actual vectorization happens in RuVector integration\n phaseContext.patterns.push(`Vectorization: ${phaseContext.patterns.length} patterns ready`);\n return {\n success: true,\n data: { patternsForVectorization: phaseContext.patterns.length }\n };\n});\n\n// embedding-generation is now in consolidated-phases.ts with real ONNX implementation\n\nregisterPhaseExecutor('pattern-storage', async (workerContext, phaseContext, options) => {\n // Placeholder - storage happens in RuVector/ReasoningBank\n phaseContext.patterns.push(`Pattern storage: ${phaseContext.patterns.length} patterns`);\n return {\n success: true,\n data: { patternsStored: phaseContext.patterns.length }\n };\n});\n\nregisterPhaseExecutor('sona-training', async (workerContext, phaseContext, options) => {\n // Placeholder - SONA training happens in RuVector integration\n phaseContext.patterns.push('SONA training triggered');\n return {\n success: true,\n data: { sonaTrainingTriggered: true }\n };\n});\n\n// ============================================================================\n// Output Phases (summarization is in consolidated-phases.ts)\n// ============================================================================\n\nregisterPhaseExecutor('report-generation', async (workerContext, phaseContext, options) => {\n const report = {\n workerId: workerContext.workerId,\n trigger: workerContext.trigger,\n topic: workerContext.topic,\n timestamp: new Date().toISOString(),\n summary: {\n filesAnalyzed: phaseContext.files.length,\n patternsFound: phaseContext.patterns.length,\n bytesProcessed: phaseContext.bytes\n },\n metrics: phaseContext.metrics,\n topPatterns: phaseContext.patterns.slice(0, 20),\n phaseData: Object.fromEntries(phaseContext.phaseData)\n };\n\n return {\n success: true,\n data: { report }\n };\n});\n\nregisterPhaseExecutor('indexing', async (workerContext, phaseContext, options) => {\n phaseContext.patterns.push(`Indexed ${phaseContext.files.length} files`);\n return {\n success: true,\n data: { indexed: phaseContext.files.length }\n };\n});\n\n// ============================================================================\n// Execute Phase Pipeline\n// ============================================================================\n\nexport async function executePhasePipeline(\n workerContext: WorkerContext,\n phases: PhaseConfig[],\n onProgress?: (phase: string, progress: number) => void\n): Promise<{\n success: boolean;\n phaseContext: PhaseContext;\n results: Map<string, PhaseResult>;\n errors: string[];\n}> {\n const phaseContext = createPhaseContext();\n const results = new Map<string, PhaseResult>();\n const errors: string[] = [];\n\n for (let i = 0; i < phases.length; i++) {\n if (workerContext.signal.aborted) {\n errors.push('Pipeline aborted');\n break;\n }\n\n const phase = phases[i];\n const phaseName = phase.name || phase.type;\n\n onProgress?.(phaseName, Math.round((i / phases.length) * 100));\n\n const executor = phase.type === 'custom' && phase.executor\n ? async (ctx: WorkerContext, pCtx: PhaseContext, opts: Record<string, unknown>) => {\n return phase.executor!(ctx, opts);\n }\n : getPhaseExecutor(phase.type);\n\n if (!executor) {\n errors.push(`Unknown phase type: ${phase.type}`);\n continue;\n }\n\n try {\n const result = await Promise.race([\n executor(workerContext, phaseContext, phase.options || {}),\n new Promise<PhaseResult>((_, reject) =>\n setTimeout(() => reject(new Error('Phase timeout')), phase.timeout || 60000)\n )\n ]);\n\n results.set(phaseName, result);\n phaseContext.phaseData.set(phaseName, result.data);\n\n if (!result.success) {\n errors.push(`Phase ${phaseName} failed: ${result.error || 'Unknown error'}`);\n }\n } catch (error) {\n const errMsg = error instanceof Error ? error.message : 'Phase execution failed';\n errors.push(`Phase ${phaseName}: ${errMsg}`);\n results.set(phaseName, { success: false, data: {}, error: errMsg });\n }\n }\n\n onProgress?.('complete', 100);\n\n return {\n success: errors.length === 0,\n phaseContext,\n results,\n errors\n };\n}\n"]}
@@ -0,0 +1,75 @@
1
+ /**
2
+ * ResourceGovernor - Prevents resource exhaustion for background workers
3
+ */
4
+ import { WorkerId, WorkerTrigger, WorkerInfo, ResourceLimits, ResourceStats } from './types.js';
5
+ export declare class ResourceGovernor {
6
+ private limits;
7
+ private activeWorkers;
8
+ private timeouts;
9
+ constructor(limits?: Partial<ResourceLimits>);
10
+ /**
11
+ * Check if a new worker can be spawned
12
+ */
13
+ canSpawn(trigger: WorkerTrigger): {
14
+ allowed: boolean;
15
+ reason?: string;
16
+ };
17
+ /**
18
+ * Register a new worker
19
+ */
20
+ register(worker: WorkerInfo): void;
21
+ /**
22
+ * Update worker in tracking
23
+ */
24
+ update(workerId: WorkerId, updates: Partial<WorkerInfo>): void;
25
+ /**
26
+ * Unregister a worker
27
+ */
28
+ unregister(workerId: WorkerId): void;
29
+ /**
30
+ * Get resource statistics
31
+ */
32
+ getStats(): ResourceStats;
33
+ /**
34
+ * Get all active workers
35
+ */
36
+ getActiveWorkers(): WorkerInfo[];
37
+ /**
38
+ * Get a specific active worker
39
+ */
40
+ getWorker(workerId: WorkerId): WorkerInfo | undefined;
41
+ /**
42
+ * Check if a worker is active
43
+ */
44
+ isActive(workerId: WorkerId): boolean;
45
+ /**
46
+ * Get current limits
47
+ */
48
+ getLimits(): ResourceLimits;
49
+ /**
50
+ * Update limits
51
+ */
52
+ setLimits(limits: Partial<ResourceLimits>): void;
53
+ /**
54
+ * Force cleanup of a worker
55
+ */
56
+ forceCleanup(workerId: WorkerId): boolean;
57
+ /**
58
+ * Cleanup all workers (for shutdown)
59
+ */
60
+ cleanupAll(): void;
61
+ /**
62
+ * Get slot availability info
63
+ */
64
+ getAvailability(): {
65
+ totalSlots: number;
66
+ usedSlots: number;
67
+ availableSlots: number;
68
+ byTrigger: Record<string, {
69
+ used: number;
70
+ max: number;
71
+ }>;
72
+ };
73
+ }
74
+ export declare function getResourceGovernor(): ResourceGovernor;
75
+ //# sourceMappingURL=resource-governor.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resource-governor.d.ts","sourceRoot":"","sources":["../../src/workers/resource-governor.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,QAAQ,EAAE,aAAa,EAAE,UAAU,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAWhG,qBAAa,gBAAgB;IAC3B,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