agentic-flow 2.0.2 → 2.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude/agents/test-neural.md +14 -0
- package/.claude/settings.json +9 -133
- package/README.md +622 -1862
- package/dist/.tsbuildinfo +1 -1
- package/dist/billing/mcp/tools.js +0 -1
- package/dist/billing/mcp/tools.js.map +1 -1
- package/dist/cli/commands/hooks.d.ts.map +1 -1
- package/dist/cli/commands/hooks.js +4 -79
- package/dist/cli/commands/hooks.js.map +1 -1
- package/dist/cli-proxy.js +1 -89
- package/dist/cli-proxy.js.map +1 -1
- package/dist/core/agentdb-fast.js +3 -3
- package/dist/core/agentdb-fast.js.map +1 -1
- package/dist/core/agentdb-wrapper-enhanced.d.ts.map +1 -1
- package/dist/core/agentdb-wrapper-enhanced.js +4 -20
- package/dist/core/agentdb-wrapper-enhanced.js.map +1 -1
- package/dist/core/agentdb-wrapper.d.ts +2 -3
- package/dist/core/agentdb-wrapper.d.ts.map +1 -1
- package/dist/core/agentdb-wrapper.js +1 -15
- package/dist/core/agentdb-wrapper.js.map +1 -1
- package/dist/core/attention-native.d.ts +0 -4
- package/dist/core/attention-native.d.ts.map +1 -1
- package/dist/core/attention-native.js +2 -14
- package/dist/core/attention-native.js.map +1 -1
- package/dist/federation/SecurityManager.d.ts +2 -11
- package/dist/federation/SecurityManager.d.ts.map +1 -1
- package/dist/federation/SecurityManager.js +17 -50
- package/dist/federation/SecurityManager.js.map +1 -1
- package/dist/federation/integrations/supabase-adapter-debug.js +3 -3
- package/dist/federation/integrations/supabase-adapter-debug.js.map +1 -1
- package/dist/hooks/swarm-learning-optimizer.js +5 -5
- package/dist/hooks/swarm-learning-optimizer.js.map +1 -1
- package/dist/intelligence/IntelligenceStore.d.ts +26 -35
- package/dist/intelligence/IntelligenceStore.d.ts.map +1 -1
- package/dist/intelligence/IntelligenceStore.js +123 -308
- package/dist/intelligence/IntelligenceStore.js.map +1 -1
- package/dist/intelligence/RuVectorIntelligence.d.ts +1 -26
- package/dist/intelligence/RuVectorIntelligence.d.ts.map +1 -1
- package/dist/intelligence/RuVectorIntelligence.js +10 -49
- package/dist/intelligence/RuVectorIntelligence.js.map +1 -1
- package/dist/intelligence/agent-booster-enhanced.d.ts +0 -1
- package/dist/intelligence/agent-booster-enhanced.d.ts.map +1 -1
- package/dist/intelligence/agent-booster-enhanced.js +3 -24
- package/dist/intelligence/agent-booster-enhanced.js.map +1 -1
- package/dist/intelligence/index.d.ts +3 -29
- package/dist/intelligence/index.d.ts.map +1 -1
- package/dist/intelligence/index.js +3 -13
- package/dist/intelligence/index.js.map +1 -1
- package/dist/mcp/claudeFlowSdkServer.d.ts.map +1 -1
- package/dist/mcp/claudeFlowSdkServer.js +3 -9
- package/dist/mcp/claudeFlowSdkServer.js.map +1 -1
- package/dist/mcp/fastmcp/tools/hooks/intelligence-bridge.js +5 -5
- package/dist/mcp/fastmcp/tools/hooks/intelligence-bridge.js.map +1 -1
- package/dist/mcp/fastmcp/tools/swarm/init.d.ts.map +1 -1
- package/dist/mcp/fastmcp/tools/swarm/init.js +7 -36
- package/dist/mcp/fastmcp/tools/swarm/init.js.map +1 -1
- package/dist/mcp/fastmcp/tools/swarm/spawn.d.ts.map +1 -1
- package/dist/mcp/fastmcp/tools/swarm/spawn.js +8 -47
- package/dist/mcp/fastmcp/tools/swarm/spawn.js.map +1 -1
- package/dist/mcp/tools/agent-booster-tools.d.ts +1 -1
- package/dist/mcp/tools/agent-booster-tools.d.ts.map +1 -1
- package/dist/mcp/tools/agent-booster-tools.js +4 -10
- package/dist/mcp/tools/agent-booster-tools.js.map +1 -1
- package/dist/mcp/tools/sona-tools.d.ts.map +1 -1
- package/dist/mcp/tools/sona-tools.js +0 -6
- package/dist/mcp/tools/sona-tools.js.map +1 -1
- package/dist/optimizations/agent-booster-migration.d.ts.map +1 -1
- package/dist/optimizations/agent-booster-migration.js +2 -5
- package/dist/optimizations/agent-booster-migration.js.map +1 -1
- package/dist/proxy/anthropic-to-openrouter.js.map +1 -1
- package/dist/proxy/anthropic-to-requesty.js.map +1 -1
- package/dist/proxy/quic-proxy.d.ts +1 -0
- package/dist/proxy/quic-proxy.d.ts.map +1 -1
- package/dist/proxy/quic-proxy.js +2 -2
- package/dist/proxy/quic-proxy.js.map +1 -1
- package/dist/reasoningbank/AdvancedMemory.js +1 -1
- package/dist/reasoningbank/AdvancedMemory.js.map +1 -1
- package/dist/reasoningbank/HybridBackend.d.ts.map +1 -1
- package/dist/reasoningbank/HybridBackend.js +5 -2
- package/dist/reasoningbank/HybridBackend.js.map +1 -1
- package/dist/reasoningbank/backend-selector.d.ts +1 -11
- package/dist/reasoningbank/backend-selector.d.ts.map +1 -1
- package/dist/reasoningbank/backend-selector.js +5 -45
- package/dist/reasoningbank/backend-selector.js.map +1 -1
- package/dist/reasoningbank/core/consolidate.d.ts.map +1 -1
- package/dist/reasoningbank/core/consolidate.js +45 -113
- package/dist/reasoningbank/core/consolidate.js.map +1 -1
- package/dist/reasoningbank/index-new.d.ts +6 -1
- package/dist/reasoningbank/index-new.d.ts.map +1 -1
- package/dist/reasoningbank/index-new.js +6 -1
- package/dist/reasoningbank/index-new.js.map +1 -1
- package/dist/reasoningbank/index.d.ts +6 -2
- package/dist/reasoningbank/index.d.ts.map +1 -1
- package/dist/reasoningbank/index.js +6 -2
- package/dist/reasoningbank/index.js.map +1 -1
- package/dist/reasoningbank/utils/embeddings.d.ts +0 -1
- package/dist/reasoningbank/utils/embeddings.d.ts.map +1 -1
- package/dist/reasoningbank/utils/embeddings.js +26 -53
- package/dist/reasoningbank/utils/embeddings.js.map +1 -1
- package/dist/router/index.d.ts +17 -0
- package/dist/router/index.d.ts.map +1 -0
- package/dist/router/index.js +19 -0
- package/dist/router/index.js.map +1 -0
- package/dist/router/providers/onnx-local-optimized.d.ts +0 -2
- package/dist/router/providers/onnx-local-optimized.d.ts.map +1 -1
- package/dist/router/providers/onnx-local-optimized.js +0 -10
- package/dist/router/providers/onnx-local-optimized.js.map +1 -1
- package/dist/router/providers/onnx-local.d.ts +0 -1
- package/dist/router/providers/onnx-local.d.ts.map +1 -1
- package/dist/router/providers/onnx-local.js +5 -22
- package/dist/router/providers/onnx-local.js.map +1 -1
- package/dist/services/embedding-service.js.map +1 -1
- package/dist/services/sona-agent-training.d.ts +0 -1
- package/dist/services/sona-agent-training.d.ts.map +1 -1
- package/dist/services/sona-agent-training.js.map +1 -1
- package/dist/services/sona-agentdb-integration.d.ts.map +1 -1
- package/dist/services/sona-agentdb-integration.js +6 -9
- package/dist/services/sona-agentdb-integration.js.map +1 -1
- package/dist/services/sona-service.d.ts.map +1 -1
- package/dist/services/sona-service.js +5 -6
- package/dist/services/sona-service.js.map +1 -1
- package/dist/utils/cli.d.ts +1 -1
- package/dist/utils/cli.d.ts.map +1 -1
- package/dist/utils/cli.js +0 -21
- package/dist/utils/cli.js.map +1 -1
- package/package.json +7 -19
- package/scripts/postinstall.js +4 -45
- package/wasm/reasoningbank/reasoningbank_wasm_bg.js +2 -2
- package/wasm/reasoningbank/reasoningbank_wasm_bg.wasm +0 -0
- package/.claude/agents/.claude-flow/metrics/agent-metrics.json +0 -1
- package/.claude/agents/.claude-flow/metrics/performance.json +0 -87
- package/.claude/agents/.claude-flow/metrics/task-metrics.json +0 -10
- package/.claude/skills/.claude-flow/metrics/agent-metrics.json +0 -1
- package/.claude/skills/.claude-flow/metrics/performance.json +0 -87
- package/.claude/skills/.claude-flow/metrics/task-metrics.json +0 -10
- package/.claude/skills/agentic-flow-quickstart/skill.md +0 -69
- package/.claude/skills/hooks-automation/skill.md +0 -155
- package/.claude/skills/memory-patterns/skill.md +0 -110
- package/.claude/skills/skill-builder/.claude-flow/metrics/agent-metrics.json +0 -1
- package/.claude/skills/skill-builder/.claude-flow/metrics/performance.json +0 -87
- package/.claude/skills/skill-builder/.claude-flow/metrics/task-metrics.json +0 -10
- package/.claude/skills/sparc-methodology/skill.md +0 -137
- package/.claude/skills/swarm-coordination/skill.md +0 -94
- package/.claude/skills/worker-benchmarks/skill.md +0 -135
- package/.claude/skills/worker-integration/skill.md +0 -154
- package/.claude/statusline.mjs +0 -109
- package/.claude/statusline.sh +0 -71
- package/dist/agentdb/benchmarks/comprehensive-benchmark.js +0 -664
- package/dist/agentdb/benchmarks/frontier-benchmark.js +0 -419
- package/dist/agentdb/benchmarks/reflexion-benchmark.js +0 -370
- package/dist/agentdb/cli/agentdb-cli.js +0 -717
- package/dist/agentdb/controllers/CausalMemoryGraph.js +0 -322
- package/dist/agentdb/controllers/CausalRecall.js +0 -281
- package/dist/agentdb/controllers/EmbeddingService.d.ts +0 -37
- package/dist/agentdb/controllers/EmbeddingService.d.ts.map +0 -1
- package/dist/agentdb/controllers/EmbeddingService.js +0 -119
- package/dist/agentdb/controllers/EmbeddingService.js.map +0 -1
- package/dist/agentdb/controllers/ExplainableRecall.js +0 -387
- package/dist/agentdb/controllers/NightlyLearner.js +0 -382
- package/dist/agentdb/controllers/ReflexionMemory.js +0 -239
- package/dist/agentdb/controllers/SkillLibrary.js +0 -276
- package/dist/agentdb/controllers/frontier-index.js +0 -9
- package/dist/agentdb/controllers/index.js +0 -8
- package/dist/agentdb/optimizations/BatchOperations.js +0 -198
- package/dist/agentdb/optimizations/QueryOptimizer.js +0 -225
- package/dist/agentdb/optimizations/index.js +0 -7
- package/dist/agentdb/tests/frontier-features.test.js +0 -665
- package/dist/benchmarks/embeddings-benchmark.d.ts +0 -38
- package/dist/benchmarks/embeddings-benchmark.d.ts.map +0 -1
- package/dist/benchmarks/embeddings-benchmark.js +0 -282
- package/dist/benchmarks/embeddings-benchmark.js.map +0 -1
- package/dist/cli/commands/embeddings.d.ts +0 -12
- package/dist/cli/commands/embeddings.d.ts.map +0 -1
- package/dist/cli/commands/embeddings.js +0 -386
- package/dist/cli/commands/embeddings.js.map +0 -1
- package/dist/cli/commands/init.d.ts +0 -8
- package/dist/cli/commands/init.d.ts.map +0 -1
- package/dist/cli/commands/init.js +0 -514
- package/dist/cli/commands/init.js.map +0 -1
- package/dist/cli/commands/workers.d.ts +0 -9
- package/dist/cli/commands/workers.d.ts.map +0 -1
- package/dist/cli/commands/workers.js +0 -991
- package/dist/cli/commands/workers.js.map +0 -1
- package/dist/cli/skills-manager.js +0 -1297
- package/dist/cli/update-message.js +0 -175
- package/dist/embeddings/index.d.ts +0 -17
- package/dist/embeddings/index.d.ts.map +0 -1
- package/dist/embeddings/index.js +0 -17
- package/dist/embeddings/index.js.map +0 -1
- package/dist/embeddings/neural-substrate.d.ts +0 -206
- package/dist/embeddings/neural-substrate.d.ts.map +0 -1
- package/dist/embeddings/neural-substrate.js +0 -629
- package/dist/embeddings/neural-substrate.js.map +0 -1
- package/dist/embeddings/optimized-embedder.d.ts +0 -103
- package/dist/embeddings/optimized-embedder.d.ts.map +0 -1
- package/dist/embeddings/optimized-embedder.js +0 -730
- package/dist/embeddings/optimized-embedder.js.map +0 -1
- package/dist/examples/embedding-geometry.d.ts +0 -105
- package/dist/examples/embedding-geometry.d.ts.map +0 -1
- package/dist/examples/embedding-geometry.js +0 -528
- package/dist/examples/embedding-geometry.js.map +0 -1
- package/dist/memory/SharedMemoryPool.d.ts +0 -129
- package/dist/memory/SharedMemoryPool.d.ts.map +0 -1
- package/dist/memory/SharedMemoryPool.js +0 -243
- package/dist/memory/SharedMemoryPool.js.map +0 -1
- package/dist/memory/index.d.ts +0 -8
- package/dist/memory/index.d.ts.map +0 -1
- package/dist/memory/index.js +0 -7
- package/dist/memory/index.js.map +0 -1
- package/dist/proxy/http3-proxy-old.js +0 -331
- package/dist/proxy/proxy/anthropic-to-gemini.js +0 -439
- package/dist/proxy/utils/logger.js +0 -59
- package/dist/reasoningbank/agentdb-adapter.js +0 -125
- package/dist/reasoningbank/core/database.js +0 -250
- package/dist/reasoningbank/core/memory-engine.js +0 -335
- package/dist/swarm/ipfs-swarm.d.ts +0 -265
- package/dist/swarm/ipfs-swarm.d.ts.map +0 -1
- package/dist/swarm/ipfs-swarm.js +0 -508
- package/dist/swarm/ipfs-swarm.js.map +0 -1
- package/dist/swarm/p2p-free-swarm.d.ts +0 -344
- package/dist/swarm/p2p-free-swarm.d.ts.map +0 -1
- package/dist/swarm/p2p-free-swarm.js +0 -603
- package/dist/swarm/p2p-free-swarm.js.map +0 -1
- package/dist/swarm/real-p2p-swarm.d.ts +0 -183
- package/dist/swarm/real-p2p-swarm.d.ts.map +0 -1
- package/dist/swarm/real-p2p-swarm.js +0 -469
- package/dist/swarm/real-p2p-swarm.js.map +0 -1
- package/dist/utils/adaptive-pool-sizing.js +0 -414
- package/dist/utils/agentdbCommands.js +0 -175
- package/dist/utils/circular-rate-limiter.js +0 -391
- package/dist/utils/dynamic-compression.js +0 -298
- package/dist/utils/http2-multiplexing.js +0 -319
- package/dist/utils/index.d.ts +0 -6
- package/dist/utils/index.d.ts.map +0 -1
- package/dist/utils/index.js +0 -6
- package/dist/utils/index.js.map +0 -1
- package/dist/utils/lazy-auth.js +0 -311
- package/dist/utils/model-cache.d.ts +0 -61
- package/dist/utils/model-cache.d.ts.map +0 -1
- package/dist/utils/model-cache.js +0 -176
- package/dist/utils/model-cache.js.map +0 -1
- package/dist/utils/server-push.js +0 -251
- package/dist/utils/suppress-warnings.d.ts +0 -19
- package/dist/utils/suppress-warnings.d.ts.map +0 -1
- package/dist/utils/suppress-warnings.js +0 -59
- package/dist/utils/suppress-warnings.js.map +0 -1
- package/dist/utils/zero-copy-buffer.js +0 -286
- package/dist/workers/consolidated-phases.d.ts +0 -40
- package/dist/workers/consolidated-phases.d.ts.map +0 -1
- package/dist/workers/consolidated-phases.js +0 -497
- package/dist/workers/consolidated-phases.js.map +0 -1
- package/dist/workers/custom-worker-config.d.ts +0 -133
- package/dist/workers/custom-worker-config.d.ts.map +0 -1
- package/dist/workers/custom-worker-config.js +0 -215
- package/dist/workers/custom-worker-config.js.map +0 -1
- package/dist/workers/custom-worker-factory.d.ts +0 -89
- package/dist/workers/custom-worker-factory.d.ts.map +0 -1
- package/dist/workers/custom-worker-factory.js +0 -404
- package/dist/workers/custom-worker-factory.js.map +0 -1
- package/dist/workers/dispatch-service.d.ts +0 -123
- package/dist/workers/dispatch-service.d.ts.map +0 -1
- package/dist/workers/dispatch-service.js +0 -1024
- package/dist/workers/dispatch-service.js.map +0 -1
- package/dist/workers/hooks-integration.d.ts +0 -79
- package/dist/workers/hooks-integration.d.ts.map +0 -1
- package/dist/workers/hooks-integration.js +0 -286
- package/dist/workers/hooks-integration.js.map +0 -1
- package/dist/workers/index.d.ts +0 -42
- package/dist/workers/index.d.ts.map +0 -1
- package/dist/workers/index.js +0 -52
- package/dist/workers/index.js.map +0 -1
- package/dist/workers/mcp-tools.d.ts +0 -56
- package/dist/workers/mcp-tools.d.ts.map +0 -1
- package/dist/workers/mcp-tools.js +0 -359
- package/dist/workers/mcp-tools.js.map +0 -1
- package/dist/workers/phase-executors.d.ts +0 -22
- package/dist/workers/phase-executors.d.ts.map +0 -1
- package/dist/workers/phase-executors.js +0 -445
- package/dist/workers/phase-executors.js.map +0 -1
- package/dist/workers/resource-governor.d.ts +0 -75
- package/dist/workers/resource-governor.d.ts.map +0 -1
- package/dist/workers/resource-governor.js +0 -187
- package/dist/workers/resource-governor.js.map +0 -1
- package/dist/workers/ruvector-integration.d.ts +0 -163
- package/dist/workers/ruvector-integration.d.ts.map +0 -1
- package/dist/workers/ruvector-integration.js +0 -543
- package/dist/workers/ruvector-integration.js.map +0 -1
- package/dist/workers/ruvector-native-integration.d.ts +0 -91
- package/dist/workers/ruvector-native-integration.d.ts.map +0 -1
- package/dist/workers/ruvector-native-integration.js +0 -254
- package/dist/workers/ruvector-native-integration.js.map +0 -1
- package/dist/workers/trigger-detector.d.ts +0 -68
- package/dist/workers/trigger-detector.d.ts.map +0 -1
- package/dist/workers/trigger-detector.js +0 -281
- package/dist/workers/trigger-detector.js.map +0 -1
- package/dist/workers/types.d.ts +0 -145
- package/dist/workers/types.d.ts.map +0 -1
- package/dist/workers/types.js +0 -6
- package/dist/workers/types.js.map +0 -1
- package/dist/workers/worker-agent-integration.d.ts +0 -140
- package/dist/workers/worker-agent-integration.d.ts.map +0 -1
- package/dist/workers/worker-agent-integration.js +0 -471
- package/dist/workers/worker-agent-integration.js.map +0 -1
- package/dist/workers/worker-benchmarks.d.ts +0 -88
- package/dist/workers/worker-benchmarks.d.ts.map +0 -1
- package/dist/workers/worker-benchmarks.js +0 -452
- package/dist/workers/worker-benchmarks.js.map +0 -1
- package/dist/workers/worker-registry.d.ts +0 -85
- package/dist/workers/worker-registry.d.ts.map +0 -1
- package/dist/workers/worker-registry.js +0 -547
- package/dist/workers/worker-registry.js.map +0 -1
- package/docs/.claude-flow/metrics/agent-metrics.json +0 -1
- package/docs/.claude-flow/metrics/performance.json +0 -87
- package/docs/.claude-flow/metrics/task-metrics.json +0 -10
- package/docs/embeddings/EMBEDDING_GEOMETRY.md +0 -935
- /package/.claude/agents/analysis/{analyze-code-quality.md → code-review/analyze-code-quality.md} +0 -0
- /package/.claude/agents/architecture/{arch-system-design.md → system-design/arch-system-design.md} +0 -0
- /package/.claude/agents/data/{data-ml-model.md → ml/data-ml-model.md} +0 -0
- /package/.claude/agents/development/{dev-backend-api.md → backend/dev-backend-api.md} +0 -0
- /package/.claude/agents/devops/{ops-cicd-github.md → ci-cd/ops-cicd-github.md} +0 -0
- /package/.claude/agents/documentation/{docs-api-openapi.md → api-docs/docs-api-openapi.md} +0 -0
- /package/.claude/agents/specialized/{spec-mobile-react-native.md → mobile/spec-mobile-react-native.md} +0 -0
- /package/.claude/agents/testing/{tdd-london-swarm.md → unit/tdd-london-swarm.md} +0 -0
- /package/.claude/agents/testing/{production-validator.md → validation/production-validator.md} +0 -0
|
@@ -1,1024 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* WorkerDispatchService - Dispatches and manages background workers
|
|
3
|
-
*
|
|
4
|
-
* Integrates with RuVector ecosystem:
|
|
5
|
-
* - SONA: Self-learning trajectory tracking
|
|
6
|
-
* - ReasoningBank: Pattern storage and memory retrieval
|
|
7
|
-
* - HNSW: Vector indexing for semantic search
|
|
8
|
-
*/
|
|
9
|
-
import { EventEmitter } from 'events';
|
|
10
|
-
import { getWorkerRegistry } from './worker-registry.js';
|
|
11
|
-
import { getResourceGovernor } from './resource-governor.js';
|
|
12
|
-
import { getTriggerDetector } from './trigger-detector.js';
|
|
13
|
-
import { getRuVectorWorkerIntegration, createRuVectorWorkerContext } from './ruvector-integration.js';
|
|
14
|
-
import { customWorkerManager } from './custom-worker-factory.js';
|
|
15
|
-
export class WorkerDispatchService extends EventEmitter {
|
|
16
|
-
registry;
|
|
17
|
-
governor;
|
|
18
|
-
detector;
|
|
19
|
-
ruvector;
|
|
20
|
-
runningWorkers = new Map();
|
|
21
|
-
workerImplementations = new Map();
|
|
22
|
-
constructor() {
|
|
23
|
-
super();
|
|
24
|
-
this.registry = getWorkerRegistry();
|
|
25
|
-
this.governor = getResourceGovernor();
|
|
26
|
-
this.detector = getTriggerDetector();
|
|
27
|
-
this.ruvector = getRuVectorWorkerIntegration();
|
|
28
|
-
this.registerDefaultWorkers();
|
|
29
|
-
// Initialize RuVector in background
|
|
30
|
-
this.ruvector.initialize().catch(err => {
|
|
31
|
-
console.warn('[WorkerDispatch] RuVector init failed:', err);
|
|
32
|
-
});
|
|
33
|
-
}
|
|
34
|
-
/**
|
|
35
|
-
* Dispatch a worker based on trigger
|
|
36
|
-
*/
|
|
37
|
-
async dispatch(trigger, topic, sessionId) {
|
|
38
|
-
// Check if we can spawn
|
|
39
|
-
const canSpawn = this.governor.canSpawn(trigger);
|
|
40
|
-
if (!canSpawn.allowed) {
|
|
41
|
-
throw new Error(`Cannot spawn worker: ${canSpawn.reason}`);
|
|
42
|
-
}
|
|
43
|
-
// Create worker entry
|
|
44
|
-
const workerId = this.registry.create(trigger, sessionId, topic);
|
|
45
|
-
// Get worker info
|
|
46
|
-
const workerInfo = this.registry.get(workerId);
|
|
47
|
-
if (!workerInfo) {
|
|
48
|
-
throw new Error('Failed to create worker entry');
|
|
49
|
-
}
|
|
50
|
-
// Register with governor
|
|
51
|
-
this.governor.register(workerInfo);
|
|
52
|
-
// Create abort controller
|
|
53
|
-
const abortController = new AbortController();
|
|
54
|
-
this.runningWorkers.set(workerId, abortController);
|
|
55
|
-
// Start worker in background
|
|
56
|
-
this.executeWorker(workerId, trigger, topic, sessionId, abortController.signal);
|
|
57
|
-
this.emit('worker:spawned', { workerId, trigger, topic, sessionId });
|
|
58
|
-
return workerId;
|
|
59
|
-
}
|
|
60
|
-
/**
|
|
61
|
-
* Detect triggers in prompt and dispatch workers
|
|
62
|
-
* @param parallel - Enable parallel dispatch for better batch performance (default: true)
|
|
63
|
-
*/
|
|
64
|
-
async dispatchFromPrompt(prompt, sessionId, options = {}) {
|
|
65
|
-
const triggers = this.detector.detect(prompt);
|
|
66
|
-
const { parallel = true } = options;
|
|
67
|
-
if (parallel && triggers.length > 1) {
|
|
68
|
-
// Parallel dispatch for better batch performance
|
|
69
|
-
const results = await Promise.allSettled(triggers.map(trigger => this.dispatch(trigger.keyword, trigger.topic, sessionId)));
|
|
70
|
-
const workerIds = [];
|
|
71
|
-
results.forEach((result, index) => {
|
|
72
|
-
if (result.status === 'fulfilled') {
|
|
73
|
-
workerIds.push(result.value);
|
|
74
|
-
}
|
|
75
|
-
else {
|
|
76
|
-
console.warn(`Failed to dispatch ${triggers[index].keyword}:`, result.reason);
|
|
77
|
-
}
|
|
78
|
-
});
|
|
79
|
-
return { triggers, workerIds };
|
|
80
|
-
}
|
|
81
|
-
// Sequential dispatch (fallback)
|
|
82
|
-
const workerIds = [];
|
|
83
|
-
for (const trigger of triggers) {
|
|
84
|
-
try {
|
|
85
|
-
const workerId = await this.dispatch(trigger.keyword, trigger.topic, sessionId);
|
|
86
|
-
workerIds.push(workerId);
|
|
87
|
-
}
|
|
88
|
-
catch (error) {
|
|
89
|
-
console.warn(`Failed to dispatch ${trigger.keyword}:`, error);
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
return { triggers, workerIds };
|
|
93
|
-
}
|
|
94
|
-
/**
|
|
95
|
-
* Execute worker in background with RuVector integration
|
|
96
|
-
*/
|
|
97
|
-
async executeWorker(workerId, trigger, topic, sessionId, signal) {
|
|
98
|
-
const startTime = Date.now();
|
|
99
|
-
// Update status to running
|
|
100
|
-
this.registry.updateStatus(workerId, 'running');
|
|
101
|
-
this.governor.update(workerId, { status: 'running', startedAt: startTime });
|
|
102
|
-
// Initialize RuVector trajectory tracking
|
|
103
|
-
let ruvectorContext = null;
|
|
104
|
-
let phaseStartTime = startTime;
|
|
105
|
-
let currentPhaseDeposits = 0;
|
|
106
|
-
try {
|
|
107
|
-
ruvectorContext = await createRuVectorWorkerContext({
|
|
108
|
-
workerId,
|
|
109
|
-
trigger,
|
|
110
|
-
topic,
|
|
111
|
-
sessionId,
|
|
112
|
-
startTime,
|
|
113
|
-
signal,
|
|
114
|
-
onProgress: () => { },
|
|
115
|
-
onMemoryDeposit: () => { }
|
|
116
|
-
});
|
|
117
|
-
}
|
|
118
|
-
catch (e) {
|
|
119
|
-
// RuVector is optional - continue without it
|
|
120
|
-
}
|
|
121
|
-
// Create context with RuVector-enhanced callbacks
|
|
122
|
-
const context = {
|
|
123
|
-
workerId,
|
|
124
|
-
trigger,
|
|
125
|
-
topic,
|
|
126
|
-
sessionId,
|
|
127
|
-
startTime,
|
|
128
|
-
signal,
|
|
129
|
-
onProgress: async (progress, phase) => {
|
|
130
|
-
const now = Date.now();
|
|
131
|
-
const phaseDuration = now - phaseStartTime;
|
|
132
|
-
this.registry.updateStatus(workerId, 'running', { progress, currentPhase: phase });
|
|
133
|
-
this.governor.update(workerId, { progress, currentPhase: phase });
|
|
134
|
-
this.emit('worker:progress', { workerId, progress, phase });
|
|
135
|
-
// Record phase in RuVector trajectory
|
|
136
|
-
if (ruvectorContext) {
|
|
137
|
-
try {
|
|
138
|
-
await ruvectorContext.recordStep(phase, {
|
|
139
|
-
duration: phaseDuration,
|
|
140
|
-
memoryDeposits: currentPhaseDeposits,
|
|
141
|
-
successRate: Math.min(1, progress / 100)
|
|
142
|
-
});
|
|
143
|
-
}
|
|
144
|
-
catch (e) {
|
|
145
|
-
// Best effort
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
// Reset phase tracking
|
|
149
|
-
phaseStartTime = now;
|
|
150
|
-
currentPhaseDeposits = 0;
|
|
151
|
-
},
|
|
152
|
-
onMemoryDeposit: (key) => {
|
|
153
|
-
currentPhaseDeposits++;
|
|
154
|
-
this.registry.incrementMemoryDeposits(workerId, key);
|
|
155
|
-
this.emit('worker:deposit', { workerId, key });
|
|
156
|
-
}
|
|
157
|
-
};
|
|
158
|
-
try {
|
|
159
|
-
// Get worker implementation
|
|
160
|
-
const implementation = this.workerImplementations.get(trigger);
|
|
161
|
-
if (!implementation) {
|
|
162
|
-
throw new Error(`No implementation for worker type: ${trigger}`);
|
|
163
|
-
}
|
|
164
|
-
// Find relevant patterns from previous runs
|
|
165
|
-
if (ruvectorContext) {
|
|
166
|
-
try {
|
|
167
|
-
const patterns = await ruvectorContext.findPatterns(3);
|
|
168
|
-
if (patterns.length > 0) {
|
|
169
|
-
this.emit('worker:patterns', { workerId, patterns });
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
catch (e) {
|
|
173
|
-
// Best effort
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
// Execute worker
|
|
177
|
-
const results = await implementation(context);
|
|
178
|
-
// Complete RuVector trajectory and trigger learning
|
|
179
|
-
if (ruvectorContext) {
|
|
180
|
-
try {
|
|
181
|
-
const learningResult = await ruvectorContext.complete(results);
|
|
182
|
-
this.emit('worker:learning', { workerId, ...learningResult });
|
|
183
|
-
}
|
|
184
|
-
catch (e) {
|
|
185
|
-
// Best effort
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
// Update status with actual results data
|
|
189
|
-
this.registry.updateStatus(workerId, 'complete', {
|
|
190
|
-
results: results.data
|
|
191
|
-
});
|
|
192
|
-
this.governor.unregister(workerId);
|
|
193
|
-
this.emit('worker:complete', { workerId, results, duration: Date.now() - startTime });
|
|
194
|
-
}
|
|
195
|
-
catch (error) {
|
|
196
|
-
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
197
|
-
// Complete trajectory with failure
|
|
198
|
-
if (ruvectorContext) {
|
|
199
|
-
try {
|
|
200
|
-
await ruvectorContext.complete({
|
|
201
|
-
status: signal.aborted ? 'cancelled' : 'failed',
|
|
202
|
-
data: { error: errorMessage },
|
|
203
|
-
completedPhases: 0,
|
|
204
|
-
totalPhases: 1,
|
|
205
|
-
memoryKeys: [],
|
|
206
|
-
duration: Date.now() - startTime
|
|
207
|
-
});
|
|
208
|
-
}
|
|
209
|
-
catch (e) {
|
|
210
|
-
// Best effort
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
// Check if aborted
|
|
214
|
-
if (signal.aborted) {
|
|
215
|
-
this.registry.updateStatus(workerId, 'cancelled', { error: 'Worker cancelled' });
|
|
216
|
-
}
|
|
217
|
-
else {
|
|
218
|
-
this.registry.updateStatus(workerId, 'failed', { error: errorMessage });
|
|
219
|
-
}
|
|
220
|
-
this.governor.unregister(workerId);
|
|
221
|
-
this.emit('worker:error', { workerId, error: errorMessage });
|
|
222
|
-
}
|
|
223
|
-
finally {
|
|
224
|
-
this.runningWorkers.delete(workerId);
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
|
-
/**
|
|
228
|
-
* Get worker status
|
|
229
|
-
*/
|
|
230
|
-
getStatus(workerId) {
|
|
231
|
-
return this.registry.get(workerId);
|
|
232
|
-
}
|
|
233
|
-
/**
|
|
234
|
-
* Get all workers
|
|
235
|
-
*/
|
|
236
|
-
getAllWorkers(sessionId) {
|
|
237
|
-
return this.registry.getAll({ sessionId });
|
|
238
|
-
}
|
|
239
|
-
/**
|
|
240
|
-
* Get active workers
|
|
241
|
-
*/
|
|
242
|
-
getActiveWorkers(sessionId) {
|
|
243
|
-
return this.registry.getActive(sessionId);
|
|
244
|
-
}
|
|
245
|
-
/**
|
|
246
|
-
* Cancel a running worker
|
|
247
|
-
*/
|
|
248
|
-
cancel(workerId) {
|
|
249
|
-
const controller = this.runningWorkers.get(workerId);
|
|
250
|
-
if (!controller) {
|
|
251
|
-
return false;
|
|
252
|
-
}
|
|
253
|
-
controller.abort();
|
|
254
|
-
return true;
|
|
255
|
-
}
|
|
256
|
-
/**
|
|
257
|
-
* Wait for worker completion
|
|
258
|
-
*/
|
|
259
|
-
async awaitCompletion(workerId, timeout = 300000) {
|
|
260
|
-
return new Promise((resolve) => {
|
|
261
|
-
const checkInterval = setInterval(() => {
|
|
262
|
-
const worker = this.registry.get(workerId);
|
|
263
|
-
if (!worker) {
|
|
264
|
-
clearInterval(checkInterval);
|
|
265
|
-
resolve(null);
|
|
266
|
-
return;
|
|
267
|
-
}
|
|
268
|
-
if (['complete', 'failed', 'cancelled', 'timeout'].includes(worker.status)) {
|
|
269
|
-
clearInterval(checkInterval);
|
|
270
|
-
resolve(worker);
|
|
271
|
-
}
|
|
272
|
-
}, 500);
|
|
273
|
-
// Timeout
|
|
274
|
-
setTimeout(() => {
|
|
275
|
-
clearInterval(checkInterval);
|
|
276
|
-
resolve(this.registry.get(workerId));
|
|
277
|
-
}, timeout);
|
|
278
|
-
});
|
|
279
|
-
}
|
|
280
|
-
/**
|
|
281
|
-
* Register a worker implementation
|
|
282
|
-
*/
|
|
283
|
-
registerWorker(trigger, implementation) {
|
|
284
|
-
this.workerImplementations.set(trigger, implementation);
|
|
285
|
-
}
|
|
286
|
-
/**
|
|
287
|
-
* Register a custom worker from definition
|
|
288
|
-
*/
|
|
289
|
-
registerCustomWorker(worker) {
|
|
290
|
-
const name = worker.definition.name;
|
|
291
|
-
// Create implementation that delegates to the custom worker
|
|
292
|
-
const implementation = async (context) => {
|
|
293
|
-
const result = await worker.execute(context);
|
|
294
|
-
return {
|
|
295
|
-
success: result.success,
|
|
296
|
-
data: result.data,
|
|
297
|
-
status: result.success ? 'complete' : 'failed',
|
|
298
|
-
completedPhases: worker.definition.phases.length,
|
|
299
|
-
totalPhases: worker.definition.phases.length,
|
|
300
|
-
memoryKeys: [],
|
|
301
|
-
duration: result.data.executionTimeMs || 0
|
|
302
|
-
};
|
|
303
|
-
};
|
|
304
|
-
// Register main name
|
|
305
|
-
this.registerWorker(name, implementation);
|
|
306
|
-
// Register aliases
|
|
307
|
-
for (const trigger of worker.definition.triggers || []) {
|
|
308
|
-
this.registerWorker(trigger.toLowerCase(), implementation);
|
|
309
|
-
}
|
|
310
|
-
// Also add to trigger detector
|
|
311
|
-
this.detector.registerTrigger({
|
|
312
|
-
keyword: name,
|
|
313
|
-
priority: worker.definition.priority || 'medium',
|
|
314
|
-
description: worker.definition.description,
|
|
315
|
-
timeout: worker.definition.timeout || 120000,
|
|
316
|
-
cooldown: worker.definition.cooldown || 5000,
|
|
317
|
-
topicExtractor: worker.definition.topicExtractor
|
|
318
|
-
? new RegExp(worker.definition.topicExtractor, 'i')
|
|
319
|
-
: undefined
|
|
320
|
-
});
|
|
321
|
-
}
|
|
322
|
-
/**
|
|
323
|
-
* Load and register custom workers from config file
|
|
324
|
-
*/
|
|
325
|
-
async loadCustomWorkers(configPath) {
|
|
326
|
-
const count = await customWorkerManager.loadFromConfig(configPath);
|
|
327
|
-
// Register each loaded worker
|
|
328
|
-
for (const worker of customWorkerManager.list()) {
|
|
329
|
-
this.registerCustomWorker(worker);
|
|
330
|
-
}
|
|
331
|
-
return count;
|
|
332
|
-
}
|
|
333
|
-
/**
|
|
334
|
-
* Check if a trigger has a custom worker
|
|
335
|
-
*/
|
|
336
|
-
hasCustomWorker(trigger) {
|
|
337
|
-
return customWorkerManager.get(trigger) !== undefined;
|
|
338
|
-
}
|
|
339
|
-
/**
|
|
340
|
-
* Get available custom worker presets
|
|
341
|
-
*/
|
|
342
|
-
getCustomWorkerPresets() {
|
|
343
|
-
return customWorkerManager.listPresets();
|
|
344
|
-
}
|
|
345
|
-
/**
|
|
346
|
-
* Register default worker implementations
|
|
347
|
-
*/
|
|
348
|
-
registerDefaultWorkers() {
|
|
349
|
-
// Import worker implementations
|
|
350
|
-
this.registerWorker('ultralearn', this.createUltralearnWorker());
|
|
351
|
-
this.registerWorker('optimize', this.createOptimizeWorker());
|
|
352
|
-
this.registerWorker('consolidate', this.createConsolidateWorker());
|
|
353
|
-
this.registerWorker('predict', this.createPredictWorker());
|
|
354
|
-
this.registerWorker('audit', this.createAuditWorker());
|
|
355
|
-
this.registerWorker('map', this.createMapWorker());
|
|
356
|
-
this.registerWorker('preload', this.createPreloadWorker());
|
|
357
|
-
this.registerWorker('deepdive', this.createDeepdiveWorker());
|
|
358
|
-
this.registerWorker('document', this.createDocumentWorker());
|
|
359
|
-
this.registerWorker('refactor', this.createRefactorWorker());
|
|
360
|
-
this.registerWorker('benchmark', this.createBenchmarkWorker());
|
|
361
|
-
this.registerWorker('testgaps', this.createTestgapsWorker());
|
|
362
|
-
}
|
|
363
|
-
// Worker implementations
|
|
364
|
-
createUltralearnWorker() {
|
|
365
|
-
return async (context) => {
|
|
366
|
-
const { onProgress, onMemoryDeposit, signal, topic } = context;
|
|
367
|
-
const phases = ['discovery', 'analysis', 'relationship', 'vectorization', 'summarization', 'indexing'];
|
|
368
|
-
const memoryKeys = [];
|
|
369
|
-
for (let i = 0; i < phases.length; i++) {
|
|
370
|
-
if (signal.aborted)
|
|
371
|
-
throw new Error('Aborted');
|
|
372
|
-
const phase = phases[i];
|
|
373
|
-
onProgress(Math.round((i / phases.length) * 100), phase);
|
|
374
|
-
// Simulate work with actual operations
|
|
375
|
-
await this.executePhase('ultralearn', phase, topic, context);
|
|
376
|
-
const key = `ultralearn/${topic}/${phase}`;
|
|
377
|
-
memoryKeys.push(key);
|
|
378
|
-
onMemoryDeposit(key);
|
|
379
|
-
}
|
|
380
|
-
// Get real analysis results
|
|
381
|
-
const analysisResults = this.phaseResults.get(context.workerId) || { files: [], patterns: [], bytes: 0 };
|
|
382
|
-
this.phaseResults.delete(context.workerId); // Clean up
|
|
383
|
-
return {
|
|
384
|
-
status: 'complete',
|
|
385
|
-
data: {
|
|
386
|
-
topic,
|
|
387
|
-
phases: phases.length,
|
|
388
|
-
files_analyzed: analysisResults.files.length,
|
|
389
|
-
patterns_found: analysisResults.patterns.length,
|
|
390
|
-
bytes_processed: analysisResults.bytes,
|
|
391
|
-
sample_patterns: analysisResults.patterns.slice(0, 5)
|
|
392
|
-
},
|
|
393
|
-
completedPhases: phases.length,
|
|
394
|
-
totalPhases: phases.length,
|
|
395
|
-
memoryKeys,
|
|
396
|
-
duration: Date.now() - context.startTime
|
|
397
|
-
};
|
|
398
|
-
};
|
|
399
|
-
}
|
|
400
|
-
createOptimizeWorker() {
|
|
401
|
-
return async (context) => {
|
|
402
|
-
const { onProgress, onMemoryDeposit, signal, topic } = context;
|
|
403
|
-
const phases = ['pattern-analysis', 'bottleneck-detect', 'cache-warmup', 'route-optimize'];
|
|
404
|
-
const memoryKeys = [];
|
|
405
|
-
for (let i = 0; i < phases.length; i++) {
|
|
406
|
-
if (signal.aborted)
|
|
407
|
-
throw new Error('Aborted');
|
|
408
|
-
const phase = phases[i];
|
|
409
|
-
onProgress(Math.round((i / phases.length) * 100), phase);
|
|
410
|
-
await this.executePhase('optimize', phase, topic, context);
|
|
411
|
-
const key = `optimize/${context.sessionId}/${phase}`;
|
|
412
|
-
memoryKeys.push(key);
|
|
413
|
-
onMemoryDeposit(key);
|
|
414
|
-
}
|
|
415
|
-
const analysisResults = this.phaseResults.get(context.workerId) || { files: [], patterns: [], bytes: 0 };
|
|
416
|
-
this.phaseResults.delete(context.workerId);
|
|
417
|
-
return {
|
|
418
|
-
status: 'complete',
|
|
419
|
-
data: {
|
|
420
|
-
optimized: true,
|
|
421
|
-
files_analyzed: analysisResults.files.length,
|
|
422
|
-
patterns_found: analysisResults.patterns.length,
|
|
423
|
-
bytes_processed: analysisResults.bytes
|
|
424
|
-
},
|
|
425
|
-
completedPhases: phases.length,
|
|
426
|
-
totalPhases: phases.length,
|
|
427
|
-
memoryKeys,
|
|
428
|
-
duration: Date.now() - context.startTime
|
|
429
|
-
};
|
|
430
|
-
};
|
|
431
|
-
}
|
|
432
|
-
createConsolidateWorker() {
|
|
433
|
-
return async (context) => {
|
|
434
|
-
const { onProgress, onMemoryDeposit, signal } = context;
|
|
435
|
-
const phases = ['inventory', 'similarity', 'merge', 'prune', 'reindex'];
|
|
436
|
-
const memoryKeys = [];
|
|
437
|
-
for (let i = 0; i < phases.length; i++) {
|
|
438
|
-
if (signal.aborted)
|
|
439
|
-
throw new Error('Aborted');
|
|
440
|
-
const phase = phases[i];
|
|
441
|
-
onProgress(Math.round((i / phases.length) * 100), phase);
|
|
442
|
-
await this.executePhase('consolidate', phase, null, context);
|
|
443
|
-
const key = `consolidate/report/${Date.now()}`;
|
|
444
|
-
memoryKeys.push(key);
|
|
445
|
-
onMemoryDeposit(key);
|
|
446
|
-
}
|
|
447
|
-
const analysisResults = this.phaseResults.get(context.workerId) || { files: [], patterns: [], bytes: 0 };
|
|
448
|
-
this.phaseResults.delete(context.workerId);
|
|
449
|
-
return {
|
|
450
|
-
status: 'complete',
|
|
451
|
-
data: {
|
|
452
|
-
consolidated: true,
|
|
453
|
-
files_analyzed: analysisResults.files.length,
|
|
454
|
-
patterns_found: analysisResults.patterns.length,
|
|
455
|
-
bytes_processed: analysisResults.bytes
|
|
456
|
-
},
|
|
457
|
-
completedPhases: phases.length,
|
|
458
|
-
totalPhases: phases.length,
|
|
459
|
-
memoryKeys,
|
|
460
|
-
duration: Date.now() - context.startTime
|
|
461
|
-
};
|
|
462
|
-
};
|
|
463
|
-
}
|
|
464
|
-
createPredictWorker() {
|
|
465
|
-
return async (context) => {
|
|
466
|
-
const { onProgress, onMemoryDeposit, signal, topic } = context;
|
|
467
|
-
const phases = ['context-gather', 'pattern-match', 'predict', 'preload'];
|
|
468
|
-
const memoryKeys = [];
|
|
469
|
-
for (let i = 0; i < phases.length; i++) {
|
|
470
|
-
if (signal.aborted)
|
|
471
|
-
throw new Error('Aborted');
|
|
472
|
-
const phase = phases[i];
|
|
473
|
-
onProgress(Math.round((i / phases.length) * 100), phase);
|
|
474
|
-
await this.executePhase('predict', phase, topic, context);
|
|
475
|
-
const key = `predict/${context.sessionId}/${phase}`;
|
|
476
|
-
memoryKeys.push(key);
|
|
477
|
-
onMemoryDeposit(key);
|
|
478
|
-
}
|
|
479
|
-
const analysisResults = this.phaseResults.get(context.workerId) || { files: [], patterns: [], bytes: 0 };
|
|
480
|
-
this.phaseResults.delete(context.workerId);
|
|
481
|
-
return {
|
|
482
|
-
status: 'complete',
|
|
483
|
-
data: {
|
|
484
|
-
predictions: analysisResults.patterns,
|
|
485
|
-
files_analyzed: analysisResults.files.length,
|
|
486
|
-
patterns_found: analysisResults.patterns.length,
|
|
487
|
-
bytes_processed: analysisResults.bytes
|
|
488
|
-
},
|
|
489
|
-
completedPhases: phases.length,
|
|
490
|
-
totalPhases: phases.length,
|
|
491
|
-
memoryKeys,
|
|
492
|
-
duration: Date.now() - context.startTime
|
|
493
|
-
};
|
|
494
|
-
};
|
|
495
|
-
}
|
|
496
|
-
createAuditWorker() {
|
|
497
|
-
return async (context) => {
|
|
498
|
-
const { onProgress, onMemoryDeposit, signal, topic } = context;
|
|
499
|
-
const phases = ['inventory', 'static-analysis', 'dependency-scan', 'secret-detection', 'vulnerability-check'];
|
|
500
|
-
const memoryKeys = [];
|
|
501
|
-
for (let i = 0; i < phases.length; i++) {
|
|
502
|
-
if (signal.aborted)
|
|
503
|
-
throw new Error('Aborted');
|
|
504
|
-
const phase = phases[i];
|
|
505
|
-
onProgress(Math.round((i / phases.length) * 100), phase);
|
|
506
|
-
await this.executePhase('audit', phase, topic, context);
|
|
507
|
-
const key = `audit/${Date.now()}/${phase}`;
|
|
508
|
-
memoryKeys.push(key);
|
|
509
|
-
onMemoryDeposit(key);
|
|
510
|
-
}
|
|
511
|
-
const analysisResults = this.phaseResults.get(context.workerId) || { files: [], patterns: [], bytes: 0 };
|
|
512
|
-
this.phaseResults.delete(context.workerId);
|
|
513
|
-
// Extract potential vulnerabilities from patterns
|
|
514
|
-
const vulnerabilities = analysisResults.patterns.filter(p => p.includes('POTENTIAL SECRET') || p.includes('password') || p.includes('api_key'));
|
|
515
|
-
return {
|
|
516
|
-
status: 'complete',
|
|
517
|
-
data: {
|
|
518
|
-
vulnerabilities,
|
|
519
|
-
riskLevel: vulnerabilities.length > 0 ? 'medium' : 'low',
|
|
520
|
-
files_analyzed: analysisResults.files.length,
|
|
521
|
-
patterns_found: analysisResults.patterns.length,
|
|
522
|
-
bytes_processed: analysisResults.bytes
|
|
523
|
-
},
|
|
524
|
-
completedPhases: phases.length,
|
|
525
|
-
totalPhases: phases.length,
|
|
526
|
-
memoryKeys,
|
|
527
|
-
duration: Date.now() - context.startTime
|
|
528
|
-
};
|
|
529
|
-
};
|
|
530
|
-
}
|
|
531
|
-
createMapWorker() {
|
|
532
|
-
return async (context) => {
|
|
533
|
-
const { onProgress, onMemoryDeposit, signal, topic } = context;
|
|
534
|
-
const phases = ['file-discovery', 'import-analysis', 'graph-build', 'cycle-detection', 'layer-analysis'];
|
|
535
|
-
const memoryKeys = [];
|
|
536
|
-
for (let i = 0; i < phases.length; i++) {
|
|
537
|
-
if (signal.aborted)
|
|
538
|
-
throw new Error('Aborted');
|
|
539
|
-
const phase = phases[i];
|
|
540
|
-
onProgress(Math.round((i / phases.length) * 100), phase);
|
|
541
|
-
await this.executePhase('map', phase, topic, context);
|
|
542
|
-
const key = `map/${topic || 'full'}/${phase}`;
|
|
543
|
-
memoryKeys.push(key);
|
|
544
|
-
onMemoryDeposit(key);
|
|
545
|
-
}
|
|
546
|
-
const analysisResults = this.phaseResults.get(context.workerId) || { files: [], patterns: [], bytes: 0 };
|
|
547
|
-
this.phaseResults.delete(context.workerId);
|
|
548
|
-
return {
|
|
549
|
-
status: 'complete',
|
|
550
|
-
data: {
|
|
551
|
-
graph: { nodes: analysisResults.files.length },
|
|
552
|
-
cycles: [],
|
|
553
|
-
files_analyzed: analysisResults.files.length,
|
|
554
|
-
patterns_found: analysisResults.patterns.length,
|
|
555
|
-
bytes_processed: analysisResults.bytes
|
|
556
|
-
},
|
|
557
|
-
completedPhases: phases.length,
|
|
558
|
-
totalPhases: phases.length,
|
|
559
|
-
memoryKeys,
|
|
560
|
-
duration: Date.now() - context.startTime
|
|
561
|
-
};
|
|
562
|
-
};
|
|
563
|
-
}
|
|
564
|
-
createPreloadWorker() {
|
|
565
|
-
return async (context) => {
|
|
566
|
-
const { onProgress, onMemoryDeposit, signal, topic } = context;
|
|
567
|
-
const phases = ['identify', 'fetch', 'cache'];
|
|
568
|
-
const memoryKeys = [];
|
|
569
|
-
for (let i = 0; i < phases.length; i++) {
|
|
570
|
-
if (signal.aborted)
|
|
571
|
-
throw new Error('Aborted');
|
|
572
|
-
const phase = phases[i];
|
|
573
|
-
onProgress(Math.round((i / phases.length) * 100), phase);
|
|
574
|
-
await this.executePhase('preload', phase, topic, context);
|
|
575
|
-
const key = `preload/${topic}/${phase}`;
|
|
576
|
-
memoryKeys.push(key);
|
|
577
|
-
onMemoryDeposit(key);
|
|
578
|
-
}
|
|
579
|
-
const analysisResults = this.phaseResults.get(context.workerId) || { files: [], patterns: [], bytes: 0 };
|
|
580
|
-
this.phaseResults.delete(context.workerId);
|
|
581
|
-
return {
|
|
582
|
-
status: 'complete',
|
|
583
|
-
data: {
|
|
584
|
-
preloaded: analysisResults.files.slice(0, 10),
|
|
585
|
-
files_analyzed: analysisResults.files.length,
|
|
586
|
-
patterns_found: analysisResults.patterns.length,
|
|
587
|
-
bytes_processed: analysisResults.bytes
|
|
588
|
-
},
|
|
589
|
-
completedPhases: phases.length,
|
|
590
|
-
totalPhases: phases.length,
|
|
591
|
-
memoryKeys,
|
|
592
|
-
duration: Date.now() - context.startTime
|
|
593
|
-
};
|
|
594
|
-
};
|
|
595
|
-
}
|
|
596
|
-
createDeepdiveWorker() {
|
|
597
|
-
return async (context) => {
|
|
598
|
-
const { onProgress, onMemoryDeposit, signal, topic } = context;
|
|
599
|
-
const phases = ['locate', 'trace-calls', 'build-graph', 'analyze-depth', 'summarize'];
|
|
600
|
-
const memoryKeys = [];
|
|
601
|
-
for (let i = 0; i < phases.length; i++) {
|
|
602
|
-
if (signal.aborted)
|
|
603
|
-
throw new Error('Aborted');
|
|
604
|
-
const phase = phases[i];
|
|
605
|
-
onProgress(Math.round((i / phases.length) * 100), phase);
|
|
606
|
-
await this.executePhase('deepdive', phase, topic, context);
|
|
607
|
-
const key = `deepdive/${topic}/${phase}`;
|
|
608
|
-
memoryKeys.push(key);
|
|
609
|
-
onMemoryDeposit(key);
|
|
610
|
-
}
|
|
611
|
-
const analysisResults = this.phaseResults.get(context.workerId) || { files: [], patterns: [], bytes: 0 };
|
|
612
|
-
this.phaseResults.delete(context.workerId);
|
|
613
|
-
return {
|
|
614
|
-
status: 'complete',
|
|
615
|
-
data: {
|
|
616
|
-
callGraph: { nodes: analysisResults.files.length },
|
|
617
|
-
depth: 5,
|
|
618
|
-
files_analyzed: analysisResults.files.length,
|
|
619
|
-
patterns_found: analysisResults.patterns.length,
|
|
620
|
-
bytes_processed: analysisResults.bytes
|
|
621
|
-
},
|
|
622
|
-
completedPhases: phases.length,
|
|
623
|
-
totalPhases: phases.length,
|
|
624
|
-
memoryKeys,
|
|
625
|
-
duration: Date.now() - context.startTime
|
|
626
|
-
};
|
|
627
|
-
};
|
|
628
|
-
}
|
|
629
|
-
createDocumentWorker() {
|
|
630
|
-
return async (context) => {
|
|
631
|
-
const { onProgress, onMemoryDeposit, signal, topic } = context;
|
|
632
|
-
const phases = ['analyze', 'template', 'generate', 'format'];
|
|
633
|
-
const memoryKeys = [];
|
|
634
|
-
for (let i = 0; i < phases.length; i++) {
|
|
635
|
-
if (signal.aborted)
|
|
636
|
-
throw new Error('Aborted');
|
|
637
|
-
const phase = phases[i];
|
|
638
|
-
onProgress(Math.round((i / phases.length) * 100), phase);
|
|
639
|
-
await this.executePhase('document', phase, topic, context);
|
|
640
|
-
const key = `document/${topic}/${phase}`;
|
|
641
|
-
memoryKeys.push(key);
|
|
642
|
-
onMemoryDeposit(key);
|
|
643
|
-
}
|
|
644
|
-
const analysisResults = this.phaseResults.get(context.workerId) || { files: [], patterns: [], bytes: 0 };
|
|
645
|
-
this.phaseResults.delete(context.workerId);
|
|
646
|
-
return {
|
|
647
|
-
status: 'complete',
|
|
648
|
-
data: {
|
|
649
|
-
documented: true,
|
|
650
|
-
files_analyzed: analysisResults.files.length,
|
|
651
|
-
patterns_found: analysisResults.patterns.length,
|
|
652
|
-
bytes_processed: analysisResults.bytes
|
|
653
|
-
},
|
|
654
|
-
completedPhases: phases.length,
|
|
655
|
-
totalPhases: phases.length,
|
|
656
|
-
memoryKeys,
|
|
657
|
-
duration: Date.now() - context.startTime
|
|
658
|
-
};
|
|
659
|
-
};
|
|
660
|
-
}
|
|
661
|
-
createRefactorWorker() {
|
|
662
|
-
return async (context) => {
|
|
663
|
-
const { onProgress, onMemoryDeposit, signal, topic } = context;
|
|
664
|
-
const phases = ['complexity', 'duplication', 'coupling', 'suggestions'];
|
|
665
|
-
const memoryKeys = [];
|
|
666
|
-
for (let i = 0; i < phases.length; i++) {
|
|
667
|
-
if (signal.aborted)
|
|
668
|
-
throw new Error('Aborted');
|
|
669
|
-
const phase = phases[i];
|
|
670
|
-
onProgress(Math.round((i / phases.length) * 100), phase);
|
|
671
|
-
await this.executePhase('refactor', phase, topic, context);
|
|
672
|
-
const key = `refactor/${topic}/${phase}`;
|
|
673
|
-
memoryKeys.push(key);
|
|
674
|
-
onMemoryDeposit(key);
|
|
675
|
-
}
|
|
676
|
-
const analysisResults = this.phaseResults.get(context.workerId) || { files: [], patterns: [], bytes: 0 };
|
|
677
|
-
this.phaseResults.delete(context.workerId);
|
|
678
|
-
return {
|
|
679
|
-
status: 'complete',
|
|
680
|
-
data: {
|
|
681
|
-
suggestions: analysisResults.patterns.filter(p => p.includes('complexity')),
|
|
682
|
-
files_analyzed: analysisResults.files.length,
|
|
683
|
-
patterns_found: analysisResults.patterns.length,
|
|
684
|
-
bytes_processed: analysisResults.bytes
|
|
685
|
-
},
|
|
686
|
-
completedPhases: phases.length,
|
|
687
|
-
totalPhases: phases.length,
|
|
688
|
-
memoryKeys,
|
|
689
|
-
duration: Date.now() - context.startTime
|
|
690
|
-
};
|
|
691
|
-
};
|
|
692
|
-
}
|
|
693
|
-
createBenchmarkWorker() {
|
|
694
|
-
return async (context) => {
|
|
695
|
-
const { onProgress, onMemoryDeposit, signal, topic } = context;
|
|
696
|
-
const phases = ['discover', 'instrument', 'execute', 'analyze', 'report'];
|
|
697
|
-
const memoryKeys = [];
|
|
698
|
-
for (let i = 0; i < phases.length; i++) {
|
|
699
|
-
if (signal.aborted)
|
|
700
|
-
throw new Error('Aborted');
|
|
701
|
-
const phase = phases[i];
|
|
702
|
-
onProgress(Math.round((i / phases.length) * 100), phase);
|
|
703
|
-
await this.executePhase('benchmark', phase, topic, context);
|
|
704
|
-
const key = `benchmark/${topic}/${phase}`;
|
|
705
|
-
memoryKeys.push(key);
|
|
706
|
-
onMemoryDeposit(key);
|
|
707
|
-
}
|
|
708
|
-
const analysisResults = this.phaseResults.get(context.workerId) || { files: [], patterns: [], bytes: 0 };
|
|
709
|
-
this.phaseResults.delete(context.workerId);
|
|
710
|
-
return {
|
|
711
|
-
status: 'complete',
|
|
712
|
-
data: {
|
|
713
|
-
benchmarks: analysisResults.patterns,
|
|
714
|
-
files_analyzed: analysisResults.files.length,
|
|
715
|
-
patterns_found: analysisResults.patterns.length,
|
|
716
|
-
bytes_processed: analysisResults.bytes
|
|
717
|
-
},
|
|
718
|
-
completedPhases: phases.length,
|
|
719
|
-
totalPhases: phases.length,
|
|
720
|
-
memoryKeys,
|
|
721
|
-
duration: Date.now() - context.startTime
|
|
722
|
-
};
|
|
723
|
-
};
|
|
724
|
-
}
|
|
725
|
-
createTestgapsWorker() {
|
|
726
|
-
return async (context) => {
|
|
727
|
-
const { onProgress, onMemoryDeposit, signal, topic } = context;
|
|
728
|
-
const phases = ['coverage', 'paths', 'criticality', 'suggestions'];
|
|
729
|
-
const memoryKeys = [];
|
|
730
|
-
for (let i = 0; i < phases.length; i++) {
|
|
731
|
-
if (signal.aborted)
|
|
732
|
-
throw new Error('Aborted');
|
|
733
|
-
const phase = phases[i];
|
|
734
|
-
onProgress(Math.round((i / phases.length) * 100), phase);
|
|
735
|
-
await this.executePhase('testgaps', phase, topic, context);
|
|
736
|
-
const key = `testgaps/${topic}/${phase}`;
|
|
737
|
-
memoryKeys.push(key);
|
|
738
|
-
onMemoryDeposit(key);
|
|
739
|
-
}
|
|
740
|
-
const analysisResults = this.phaseResults.get(context.workerId) || { files: [], patterns: [], bytes: 0 };
|
|
741
|
-
this.phaseResults.delete(context.workerId);
|
|
742
|
-
// Extract test-related patterns
|
|
743
|
-
const testPatterns = analysisResults.patterns.filter(p => p.includes('test'));
|
|
744
|
-
return {
|
|
745
|
-
status: 'complete',
|
|
746
|
-
data: {
|
|
747
|
-
gaps: analysisResults.patterns.filter(p => !p.includes('test')),
|
|
748
|
-
coverage: testPatterns.length > 0 ? (testPatterns.length / Math.max(1, analysisResults.files.length) * 100) : 0,
|
|
749
|
-
files_analyzed: analysisResults.files.length,
|
|
750
|
-
patterns_found: analysisResults.patterns.length,
|
|
751
|
-
bytes_processed: analysisResults.bytes
|
|
752
|
-
},
|
|
753
|
-
completedPhases: phases.length,
|
|
754
|
-
totalPhases: phases.length,
|
|
755
|
-
memoryKeys,
|
|
756
|
-
duration: Date.now() - context.startTime
|
|
757
|
-
};
|
|
758
|
-
};
|
|
759
|
-
}
|
|
760
|
-
// Shared state for phase execution
|
|
761
|
-
phaseResults = new Map();
|
|
762
|
-
/**
|
|
763
|
-
* Execute a worker phase with REAL file analysis (pure JS, no native bindings)
|
|
764
|
-
*/
|
|
765
|
-
async executePhase(worker, phase, topic, context) {
|
|
766
|
-
const fs = await import('fs/promises');
|
|
767
|
-
const path = await import('path');
|
|
768
|
-
const { glob } = await import('glob');
|
|
769
|
-
// Get or create phase results for this worker
|
|
770
|
-
const key = context.workerId;
|
|
771
|
-
if (!this.phaseResults.has(key)) {
|
|
772
|
-
this.phaseResults.set(key, { files: [], patterns: [], bytes: 0 });
|
|
773
|
-
}
|
|
774
|
-
const results = this.phaseResults.get(key);
|
|
775
|
-
// Dynamic phase execution with REAL operations
|
|
776
|
-
const executors = {
|
|
777
|
-
// Discovery phases - REAL file discovery
|
|
778
|
-
'discovery': async () => {
|
|
779
|
-
const pattern = topic
|
|
780
|
-
? `**/*${topic.replace(/[^a-zA-Z0-9]/g, '*')}*.{ts,js,tsx,jsx}`
|
|
781
|
-
: '**/*.{ts,js,tsx,jsx}';
|
|
782
|
-
const files = await glob(pattern, {
|
|
783
|
-
cwd: process.cwd(),
|
|
784
|
-
ignore: ['node_modules/**', 'dist/**', '.git/**'],
|
|
785
|
-
maxDepth: 5
|
|
786
|
-
});
|
|
787
|
-
results.files = files.slice(0, 100); // Limit to 100 files
|
|
788
|
-
},
|
|
789
|
-
'file-discovery': async () => {
|
|
790
|
-
const files = await glob('**/*.{ts,js,tsx,jsx}', {
|
|
791
|
-
cwd: process.cwd(),
|
|
792
|
-
ignore: ['node_modules/**', 'dist/**'],
|
|
793
|
-
maxDepth: 4
|
|
794
|
-
});
|
|
795
|
-
results.files = files.slice(0, 100);
|
|
796
|
-
},
|
|
797
|
-
'inventory': async () => {
|
|
798
|
-
const files = await glob('**/*.{ts,js,tsx,jsx,json,md}', {
|
|
799
|
-
cwd: process.cwd(),
|
|
800
|
-
ignore: ['node_modules/**', 'dist/**'],
|
|
801
|
-
maxDepth: 3
|
|
802
|
-
});
|
|
803
|
-
results.files = files.slice(0, 200);
|
|
804
|
-
},
|
|
805
|
-
'locate': async () => {
|
|
806
|
-
if (topic && results.files.length === 0) {
|
|
807
|
-
const files = await glob(`**/*${topic}*.{ts,js}`, {
|
|
808
|
-
cwd: process.cwd(),
|
|
809
|
-
ignore: ['node_modules/**'],
|
|
810
|
-
maxDepth: 5
|
|
811
|
-
});
|
|
812
|
-
results.files = files.slice(0, 50);
|
|
813
|
-
}
|
|
814
|
-
},
|
|
815
|
-
// Analysis phases - REAL file analysis
|
|
816
|
-
'analysis': async () => {
|
|
817
|
-
for (const file of results.files.slice(0, 20)) {
|
|
818
|
-
try {
|
|
819
|
-
const content = await fs.readFile(path.join(process.cwd(), file), 'utf-8');
|
|
820
|
-
results.bytes += content.length;
|
|
821
|
-
// Extract patterns
|
|
822
|
-
const patterns = this.extractPatterns(content, topic);
|
|
823
|
-
results.patterns.push(...patterns);
|
|
824
|
-
}
|
|
825
|
-
catch { /* file read error */ }
|
|
826
|
-
}
|
|
827
|
-
},
|
|
828
|
-
'static-analysis': async () => {
|
|
829
|
-
for (const file of results.files.slice(0, 30)) {
|
|
830
|
-
try {
|
|
831
|
-
const content = await fs.readFile(path.join(process.cwd(), file), 'utf-8');
|
|
832
|
-
results.bytes += content.length;
|
|
833
|
-
// Count functions, classes, exports
|
|
834
|
-
const funcCount = (content.match(/function\s+\w+|=>\s*{|\(\)\s*{/g) || []).length;
|
|
835
|
-
const classCount = (content.match(/class\s+\w+/g) || []).length;
|
|
836
|
-
if (funcCount > 0)
|
|
837
|
-
results.patterns.push(`${file}: ${funcCount} functions`);
|
|
838
|
-
if (classCount > 0)
|
|
839
|
-
results.patterns.push(`${file}: ${classCount} classes`);
|
|
840
|
-
}
|
|
841
|
-
catch { /* file read error */ }
|
|
842
|
-
}
|
|
843
|
-
},
|
|
844
|
-
'pattern-analysis': async () => {
|
|
845
|
-
for (const file of results.files.slice(0, 25)) {
|
|
846
|
-
try {
|
|
847
|
-
const content = await fs.readFile(path.join(process.cwd(), file), 'utf-8');
|
|
848
|
-
results.bytes += content.length;
|
|
849
|
-
const patterns = this.extractPatterns(content, topic);
|
|
850
|
-
results.patterns.push(...patterns);
|
|
851
|
-
}
|
|
852
|
-
catch { /* file read error */ }
|
|
853
|
-
}
|
|
854
|
-
},
|
|
855
|
-
'import-analysis': async () => {
|
|
856
|
-
for (const file of results.files.slice(0, 30)) {
|
|
857
|
-
try {
|
|
858
|
-
const content = await fs.readFile(path.join(process.cwd(), file), 'utf-8');
|
|
859
|
-
const imports = content.match(/import\s+.*from\s+['"][^'"]+['"]/g) || [];
|
|
860
|
-
const requires = content.match(/require\s*\(\s*['"][^'"]+['"]\s*\)/g) || [];
|
|
861
|
-
results.patterns.push(...imports.slice(0, 5), ...requires.slice(0, 5));
|
|
862
|
-
results.bytes += content.length;
|
|
863
|
-
}
|
|
864
|
-
catch { /* file read error */ }
|
|
865
|
-
}
|
|
866
|
-
},
|
|
867
|
-
'complexity': async () => {
|
|
868
|
-
for (const file of results.files.slice(0, 15)) {
|
|
869
|
-
try {
|
|
870
|
-
const content = await fs.readFile(path.join(process.cwd(), file), 'utf-8');
|
|
871
|
-
const lines = content.split('\n').length;
|
|
872
|
-
const ifCount = (content.match(/\bif\s*\(/g) || []).length;
|
|
873
|
-
const loopCount = (content.match(/\b(for|while)\s*\(/g) || []).length;
|
|
874
|
-
const complexity = ifCount + loopCount * 2;
|
|
875
|
-
if (complexity > 10) {
|
|
876
|
-
results.patterns.push(`${file}: complexity=${complexity} (${lines} lines)`);
|
|
877
|
-
}
|
|
878
|
-
results.bytes += content.length;
|
|
879
|
-
}
|
|
880
|
-
catch { /* file read error */ }
|
|
881
|
-
}
|
|
882
|
-
},
|
|
883
|
-
// Build phases - REAL graph building
|
|
884
|
-
'graph-build': async () => {
|
|
885
|
-
const graph = {};
|
|
886
|
-
for (const file of results.files.slice(0, 30)) {
|
|
887
|
-
try {
|
|
888
|
-
const content = await fs.readFile(path.join(process.cwd(), file), 'utf-8');
|
|
889
|
-
const imports = (content.match(/from\s+['"]\.\/[^'"]+['"]/g) || [])
|
|
890
|
-
.map(i => i.replace(/from\s+['"]\.\//g, '').replace(/['"]/g, ''));
|
|
891
|
-
graph[file] = imports;
|
|
892
|
-
results.bytes += content.length;
|
|
893
|
-
}
|
|
894
|
-
catch { /* file read error */ }
|
|
895
|
-
}
|
|
896
|
-
results.patterns.push(`Built dependency graph: ${Object.keys(graph).length} nodes`);
|
|
897
|
-
},
|
|
898
|
-
'trace-calls': async () => {
|
|
899
|
-
for (const file of results.files.slice(0, 20)) {
|
|
900
|
-
try {
|
|
901
|
-
const content = await fs.readFile(path.join(process.cwd(), file), 'utf-8');
|
|
902
|
-
const calls = content.match(/\w+\s*\([^)]*\)/g) || [];
|
|
903
|
-
results.patterns.push(`${file}: ${calls.length} function calls`);
|
|
904
|
-
results.bytes += content.length;
|
|
905
|
-
}
|
|
906
|
-
catch { /* file read error */ }
|
|
907
|
-
}
|
|
908
|
-
},
|
|
909
|
-
// Detection phases - REAL security scanning
|
|
910
|
-
'secret-detection': async () => {
|
|
911
|
-
const secretPatterns = [
|
|
912
|
-
/api[_-]?key\s*[:=]\s*['"][^'"]+['"]/gi,
|
|
913
|
-
/password\s*[:=]\s*['"][^'"]+['"]/gi,
|
|
914
|
-
/secret\s*[:=]\s*['"][^'"]+['"]/gi,
|
|
915
|
-
/token\s*[:=]\s*['"][^'"]+['"]/gi
|
|
916
|
-
];
|
|
917
|
-
for (const file of results.files.slice(0, 50)) {
|
|
918
|
-
try {
|
|
919
|
-
const content = await fs.readFile(path.join(process.cwd(), file), 'utf-8');
|
|
920
|
-
for (const pattern of secretPatterns) {
|
|
921
|
-
const matches = content.match(pattern);
|
|
922
|
-
if (matches) {
|
|
923
|
-
results.patterns.push(`POTENTIAL SECRET in ${file}: ${matches.length} matches`);
|
|
924
|
-
}
|
|
925
|
-
}
|
|
926
|
-
results.bytes += content.length;
|
|
927
|
-
}
|
|
928
|
-
catch { /* file read error */ }
|
|
929
|
-
}
|
|
930
|
-
},
|
|
931
|
-
'dependency-scan': async () => {
|
|
932
|
-
try {
|
|
933
|
-
const pkgPath = path.join(process.cwd(), 'package.json');
|
|
934
|
-
const pkg = JSON.parse(await fs.readFile(pkgPath, 'utf-8'));
|
|
935
|
-
const deps = { ...pkg.dependencies, ...pkg.devDependencies };
|
|
936
|
-
results.patterns.push(`Found ${Object.keys(deps).length} dependencies`);
|
|
937
|
-
results.bytes += JSON.stringify(deps).length;
|
|
938
|
-
}
|
|
939
|
-
catch { /* no package.json */ }
|
|
940
|
-
},
|
|
941
|
-
// Test phases - REAL coverage analysis
|
|
942
|
-
'coverage': async () => {
|
|
943
|
-
const testFiles = await glob('**/*.{test,spec}.{ts,js,tsx,jsx}', {
|
|
944
|
-
cwd: process.cwd(),
|
|
945
|
-
ignore: ['node_modules/**']
|
|
946
|
-
});
|
|
947
|
-
results.patterns.push(`Found ${testFiles.length} test files`);
|
|
948
|
-
for (const file of testFiles.slice(0, 20)) {
|
|
949
|
-
try {
|
|
950
|
-
const content = await fs.readFile(path.join(process.cwd(), file), 'utf-8');
|
|
951
|
-
const tests = (content.match(/\b(it|test|describe)\s*\(/g) || []).length;
|
|
952
|
-
results.patterns.push(`${file}: ${tests} test cases`);
|
|
953
|
-
results.bytes += content.length;
|
|
954
|
-
}
|
|
955
|
-
catch { /* file read error */ }
|
|
956
|
-
}
|
|
957
|
-
},
|
|
958
|
-
// Default for other phases
|
|
959
|
-
'vectorization': async () => { results.patterns.push('Vectorization complete (JS fallback)'); },
|
|
960
|
-
'indexing': async () => { results.patterns.push(`Indexed ${results.files.length} files`); },
|
|
961
|
-
'summarize': async () => { results.patterns.push(`Summary: ${results.patterns.length} patterns found`); },
|
|
962
|
-
'report': async () => { results.patterns.push('Report generated'); }
|
|
963
|
-
};
|
|
964
|
-
const executor = executors[phase];
|
|
965
|
-
if (executor) {
|
|
966
|
-
await executor();
|
|
967
|
-
}
|
|
968
|
-
else {
|
|
969
|
-
// Generic fallback - still do some work
|
|
970
|
-
await new Promise(r => setTimeout(r, 50));
|
|
971
|
-
}
|
|
972
|
-
// Store results in context for later retrieval
|
|
973
|
-
context.analysisResults = results;
|
|
974
|
-
}
|
|
975
|
-
/**
|
|
976
|
-
* Extract code patterns related to a topic
|
|
977
|
-
*/
|
|
978
|
-
extractPatterns(content, topic) {
|
|
979
|
-
const patterns = [];
|
|
980
|
-
const lines = content.split('\n');
|
|
981
|
-
for (let i = 0; i < lines.length; i++) {
|
|
982
|
-
const line = lines[i];
|
|
983
|
-
// Look for topic mentions
|
|
984
|
-
if (topic && line.toLowerCase().includes(topic.toLowerCase())) {
|
|
985
|
-
patterns.push(`Line ${i + 1}: ${line.trim().slice(0, 80)}`);
|
|
986
|
-
}
|
|
987
|
-
// Look for common patterns
|
|
988
|
-
if (line.match(/TODO|FIXME|HACK|XXX/i)) {
|
|
989
|
-
patterns.push(`TODO at line ${i + 1}: ${line.trim().slice(0, 60)}`);
|
|
990
|
-
}
|
|
991
|
-
}
|
|
992
|
-
return patterns.slice(0, 10); // Limit patterns per file
|
|
993
|
-
}
|
|
994
|
-
/**
|
|
995
|
-
* Get dashboard statistics including RuVector integration
|
|
996
|
-
*/
|
|
997
|
-
getStats() {
|
|
998
|
-
const registryStats = this.registry.getStats();
|
|
999
|
-
const availability = this.governor.getAvailability();
|
|
1000
|
-
const ruvectorStats = this.ruvector.getStats();
|
|
1001
|
-
return {
|
|
1002
|
-
active: availability.usedSlots,
|
|
1003
|
-
byStatus: registryStats.byStatus,
|
|
1004
|
-
byTrigger: registryStats.byTrigger,
|
|
1005
|
-
availability,
|
|
1006
|
-
ruvector: ruvectorStats
|
|
1007
|
-
};
|
|
1008
|
-
}
|
|
1009
|
-
/**
|
|
1010
|
-
* Get RuVector integration instance for advanced operations
|
|
1011
|
-
*/
|
|
1012
|
-
getRuVectorIntegration() {
|
|
1013
|
-
return this.ruvector;
|
|
1014
|
-
}
|
|
1015
|
-
}
|
|
1016
|
-
// Singleton instance
|
|
1017
|
-
let instance = null;
|
|
1018
|
-
export function getWorkerDispatchService() {
|
|
1019
|
-
if (!instance) {
|
|
1020
|
-
instance = new WorkerDispatchService();
|
|
1021
|
-
}
|
|
1022
|
-
return instance;
|
|
1023
|
-
}
|
|
1024
|
-
//# sourceMappingURL=dispatch-service.js.map
|