kynjal-cli 4.0.0 → 4.0.1
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/dist/src/appliance/gguf-engine.d.ts +91 -0
- package/dist/src/appliance/gguf-engine.d.ts.map +1 -0
- package/dist/src/appliance/gguf-engine.js +286 -525
- package/dist/src/appliance/gguf-engine.js.map +1 -1
- package/dist/src/appliance/ruvllm-bridge.d.ts +102 -0
- package/dist/src/appliance/ruvllm-bridge.d.ts.map +1 -0
- package/dist/src/appliance/ruvllm-bridge.js +203 -403
- package/dist/src/appliance/ruvllm-bridge.js.map +1 -1
- package/dist/src/appliance/rvfa-builder.d.ts +44 -0
- package/dist/src/appliance/rvfa-builder.d.ts.map +1 -0
- package/dist/src/appliance/rvfa-builder.js +154 -208
- package/dist/src/appliance/rvfa-builder.js.map +1 -1
- package/dist/src/appliance/rvfa-distribution.d.ts +97 -0
- package/dist/src/appliance/rvfa-distribution.d.ts.map +1 -0
- package/dist/src/appliance/rvfa-distribution.js +260 -423
- package/dist/src/appliance/rvfa-distribution.js.map +1 -1
- package/dist/src/appliance/rvfa-format.d.ts +111 -0
- package/dist/src/appliance/rvfa-format.d.ts.map +1 -0
- package/dist/src/appliance/rvfa-format.js +128 -200
- package/dist/src/appliance/rvfa-format.js.map +1 -1
- package/dist/src/appliance/rvfa-runner.d.ts +69 -0
- package/dist/src/appliance/rvfa-runner.d.ts.map +1 -0
- package/dist/src/appliance/rvfa-runner.js +168 -304
- package/dist/src/appliance/rvfa-runner.js.map +1 -1
- package/dist/src/appliance/rvfa-signing.d.ts +123 -0
- package/dist/src/appliance/rvfa-signing.d.ts.map +1 -0
- package/dist/src/appliance/rvfa-signing.js +173 -295
- package/dist/src/appliance/rvfa-signing.js.map +1 -1
- package/dist/src/benchmarks/pretrain/index.d.ts +58 -0
- package/dist/src/benchmarks/pretrain/index.d.ts.map +1 -0
- package/dist/src/benchmarks/pretrain/index.js +331 -542
- package/dist/src/benchmarks/pretrain/index.js.map +1 -1
- package/dist/src/commands/agent.js +574 -697
- package/dist/src/commands/agent.js.map +1 -1
- package/dist/src/commands/analyze.js +1218 -1548
- package/dist/src/commands/analyze.js.map +1 -1
- package/dist/src/commands/appliance-advanced.js +158 -267
- package/dist/src/commands/appliance-advanced.js.map +1 -1
- package/dist/src/commands/appliance.js +318 -493
- package/dist/src/commands/appliance.js.map +1 -1
- package/dist/src/commands/benchmark.js +372 -523
- package/dist/src/commands/benchmark.js.map +1 -1
- package/dist/src/commands/claims.js +274 -364
- package/dist/src/commands/claims.js.map +1 -1
- package/dist/src/commands/cleanup.js +113 -157
- package/dist/src/commands/cleanup.js.map +1 -1
- package/dist/src/commands/completions.js +477 -118
- package/dist/src/commands/completions.js.map +1 -1
- package/dist/src/commands/config.js +237 -303
- package/dist/src/commands/config.js.map +1 -1
- package/dist/src/commands/daemon.js +487 -596
- package/dist/src/commands/daemon.js.map +1 -1
- package/dist/src/commands/deployment.js +194 -275
- package/dist/src/commands/deployment.js.map +1 -1
- package/dist/src/commands/doctor.js +504 -686
- package/dist/src/commands/doctor.js.map +1 -1
- package/dist/src/commands/embeddings.js +1293 -1543
- package/dist/src/commands/embeddings.js.map +1 -1
- package/dist/src/commands/guidance.js +449 -596
- package/dist/src/commands/guidance.js.map +1 -1
- package/dist/src/commands/hive-mind.js +854 -938
- package/dist/src/commands/hive-mind.js.map +1 -1
- package/dist/src/commands/hooks.js +3112 -3519
- package/dist/src/commands/hooks.js.map +1 -1
- package/dist/src/commands/index.d.ts +115 -0
- package/dist/src/commands/index.d.ts.map +1 -0
- package/dist/src/commands/index.js +126 -308
- package/dist/src/commands/index.js.map +1 -1
- package/dist/src/commands/init.js +788 -940
- package/dist/src/commands/init.js.map +1 -1
- package/dist/src/commands/issues.js +383 -558
- package/dist/src/commands/issues.js.map +1 -1
- package/dist/src/commands/mcp.js +493 -605
- package/dist/src/commands/mcp.js.map +1 -1
- package/dist/src/commands/memory.js +833 -1026
- package/dist/src/commands/memory.js.map +1 -1
- package/dist/src/commands/migrate.js +282 -347
- package/dist/src/commands/migrate.js.map +1 -1
- package/dist/src/commands/neural.js +1289 -1563
- package/dist/src/commands/neural.js.map +1 -1
- package/dist/src/commands/performance.js +497 -643
- package/dist/src/commands/performance.js.map +1 -1
- package/dist/src/commands/plugins.js +668 -841
- package/dist/src/commands/plugins.js.map +1 -1
- package/dist/src/commands/process.js +392 -447
- package/dist/src/commands/process.js.map +1 -1
- package/dist/src/commands/progress.js +162 -256
- package/dist/src/commands/progress.js.map +1 -1
- package/dist/src/commands/providers.js +150 -220
- package/dist/src/commands/providers.js.map +1 -1
- package/dist/src/commands/route.js +520 -665
- package/dist/src/commands/route.js.map +1 -1
- package/dist/src/commands/ruvector/backup.js +505 -651
- package/dist/src/commands/ruvector/backup.js.map +1 -1
- package/dist/src/commands/ruvector/benchmark.js +349 -401
- package/dist/src/commands/ruvector/benchmark.js.map +1 -1
- package/dist/src/commands/ruvector/import.js +224 -266
- package/dist/src/commands/ruvector/import.js.map +1 -1
- package/dist/src/commands/ruvector/index.js +37 -75
- package/dist/src/commands/ruvector/index.js.map +1 -1
- package/dist/src/commands/ruvector/init.js +336 -359
- package/dist/src/commands/ruvector/init.js.map +1 -1
- package/dist/src/commands/ruvector/migrate.js +335 -322
- package/dist/src/commands/ruvector/migrate.js.map +1 -1
- package/dist/src/commands/ruvector/optimize.js +375 -431
- package/dist/src/commands/ruvector/optimize.js.map +1 -1
- package/dist/src/commands/ruvector/setup.js +703 -117
- package/dist/src/commands/ruvector/setup.js.map +1 -1
- package/dist/src/commands/ruvector/status.js +364 -419
- package/dist/src/commands/ruvector/status.js.map +1 -1
- package/dist/src/commands/security.js +485 -608
- package/dist/src/commands/security.js.map +1 -1
- package/dist/src/commands/session.js +504 -626
- package/dist/src/commands/session.js.map +1 -1
- package/dist/src/commands/start.js +267 -364
- package/dist/src/commands/start.js.map +1 -1
- package/dist/src/commands/status.js +380 -486
- package/dist/src/commands/status.js.map +1 -1
- package/dist/src/commands/swarm.js +408 -488
- package/dist/src/commands/swarm.js.map +1 -1
- package/dist/src/commands/task.js +423 -538
- package/dist/src/commands/task.js.map +1 -1
- package/dist/src/commands/transfer-store.js +322 -412
- package/dist/src/commands/transfer-store.js.map +1 -1
- package/dist/src/commands/update.js +196 -291
- package/dist/src/commands/update.js.map +1 -1
- package/dist/src/commands/workflow.js +386 -486
- package/dist/src/commands/workflow.js.map +1 -1
- package/dist/src/config-adapter.d.ts +15 -0
- package/dist/src/config-adapter.d.ts.map +1 -0
- package/dist/src/config-adapter.js +38 -39
- package/dist/src/config-adapter.js.map +1 -1
- package/dist/src/index.d.ts +77 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +309 -411
- package/dist/src/index.js.map +1 -1
- package/dist/src/infrastructure/in-memory-repositories.d.ts +68 -0
- package/dist/src/infrastructure/in-memory-repositories.d.ts.map +1 -0
- package/dist/src/infrastructure/in-memory-repositories.js +246 -507
- package/dist/src/infrastructure/in-memory-repositories.js.map +1 -1
- package/dist/src/init/claudemd-generator.d.ts +25 -0
- package/dist/src/init/claudemd-generator.d.ts.map +1 -0
- package/dist/src/init/claudemd-generator.js +368 -78
- package/dist/src/init/claudemd-generator.js.map +1 -1
- package/dist/src/init/executor.d.ts +41 -0
- package/dist/src/init/executor.d.ts.map +1 -0
- package/dist/src/init/executor.js +1307 -996
- package/dist/src/init/executor.js.map +1 -1
- package/dist/src/init/helpers-generator.d.ts +60 -0
- package/dist/src/init/helpers-generator.d.ts.map +1 -0
- package/dist/src/init/helpers-generator.js +657 -12
- package/dist/src/init/helpers-generator.js.map +1 -1
- package/dist/src/init/index.d.ts +1 -1
- package/dist/src/init/index.d.ts.map +1 -1
- package/dist/src/init/index.js +1 -1
- package/dist/src/init/index.js.map +1 -1
- package/dist/src/init/mcp-generator.js +33 -37
- package/dist/src/init/mcp-generator.js.map +1 -1
- package/dist/src/init/settings-generator.js +76 -77
- package/dist/src/init/settings-generator.js.map +1 -1
- package/dist/src/init/statusline-generator.js +801 -3
- package/dist/src/init/statusline-generator.js.map +1 -1
- package/dist/src/init/types.d.ts +1 -1
- package/dist/src/init/types.d.ts.map +1 -1
- package/dist/src/init/types.js +76 -59
- package/dist/src/init/types.js.map +1 -1
- package/dist/src/mcp-client.d.ts +92 -0
- package/dist/src/mcp-client.d.ts.map +1 -0
- package/dist/src/mcp-client.js +81 -125
- package/dist/src/mcp-client.js.map +1 -1
- package/dist/src/mcp-server.d.ts +161 -0
- package/dist/src/mcp-server.d.ts.map +1 -0
- package/dist/src/mcp-server.js +470 -757
- package/dist/src/mcp-server.js.map +1 -1
- package/dist/src/mcp-tools/agent-tools.js +391 -492
- package/dist/src/mcp-tools/agent-tools.js.map +1 -1
- package/dist/src/mcp-tools/agentdb-tools.js +332 -533
- package/dist/src/mcp-tools/agentdb-tools.js.map +1 -1
- package/dist/src/mcp-tools/analyze-tools.js +172 -236
- package/dist/src/mcp-tools/analyze-tools.js.map +1 -1
- package/dist/src/mcp-tools/auto-install.d.ts +83 -0
- package/dist/src/mcp-tools/auto-install.d.ts.map +1 -0
- package/dist/src/mcp-tools/auto-install.js +80 -142
- package/dist/src/mcp-tools/auto-install.js.map +1 -1
- package/dist/src/mcp-tools/browser-tools.js +252 -375
- package/dist/src/mcp-tools/browser-tools.js.map +1 -1
- package/dist/src/mcp-tools/claims-tools.js +473 -565
- package/dist/src/mcp-tools/claims-tools.js.map +1 -1
- package/dist/src/mcp-tools/config-tools.js +197 -272
- package/dist/src/mcp-tools/config-tools.js.map +1 -1
- package/dist/src/mcp-tools/coordination-tools.js +500 -572
- package/dist/src/mcp-tools/coordination-tools.js.map +1 -1
- package/dist/src/mcp-tools/daa-tools.js +286 -364
- package/dist/src/mcp-tools/daa-tools.js.map +1 -1
- package/dist/src/mcp-tools/embeddings-tools.js +582 -693
- package/dist/src/mcp-tools/embeddings-tools.js.map +1 -1
- package/dist/src/mcp-tools/github-tools.js +260 -311
- package/dist/src/mcp-tools/github-tools.js.map +1 -1
- package/dist/src/mcp-tools/hive-mind-tools.js +573 -640
- package/dist/src/mcp-tools/hive-mind-tools.js.map +1 -1
- package/dist/src/mcp-tools/hooks-tools.js +2215 -2648
- package/dist/src/mcp-tools/hooks-tools.js.map +1 -1
- package/dist/src/mcp-tools/memory-tools.js +350 -505
- package/dist/src/mcp-tools/memory-tools.js.map +1 -1
- package/dist/src/mcp-tools/neural-tools.js +315 -412
- package/dist/src/mcp-tools/neural-tools.js.map +1 -1
- package/dist/src/mcp-tools/performance-tools.js +420 -480
- package/dist/src/mcp-tools/performance-tools.js.map +1 -1
- package/dist/src/mcp-tools/progress-tools.js +204 -278
- package/dist/src/mcp-tools/progress-tools.js.map +1 -1
- package/dist/src/mcp-tools/ruvllm-tools.js +163 -279
- package/dist/src/mcp-tools/ruvllm-tools.js.map +1 -1
- package/dist/src/mcp-tools/security-tools.js +297 -429
- package/dist/src/mcp-tools/security-tools.js.map +1 -1
- package/dist/src/mcp-tools/session-tools.js +185 -234
- package/dist/src/mcp-tools/session-tools.js.map +1 -1
- package/dist/src/mcp-tools/swarm-tools.js +207 -260
- package/dist/src/mcp-tools/swarm-tools.js.map +1 -1
- package/dist/src/mcp-tools/system-tools.js +276 -325
- package/dist/src/mcp-tools/system-tools.js.map +1 -1
- package/dist/src/mcp-tools/task-tools.js +270 -336
- package/dist/src/mcp-tools/task-tools.js.map +1 -1
- package/dist/src/mcp-tools/terminal-tools.js +148 -196
- package/dist/src/mcp-tools/terminal-tools.js.map +1 -1
- package/dist/src/mcp-tools/transfer-tools.js +186 -333
- package/dist/src/mcp-tools/transfer-tools.js.map +1 -1
- package/dist/src/mcp-tools/types.d.ts +31 -0
- package/dist/src/mcp-tools/types.d.ts.map +1 -0
- package/dist/src/mcp-tools/wasm-agent-tools.js +133 -280
- package/dist/src/mcp-tools/wasm-agent-tools.js.map +1 -1
- package/dist/src/mcp-tools/workflow-tools.js +405 -450
- package/dist/src/mcp-tools/workflow-tools.js.map +1 -1
- package/dist/src/memory/ewc-consolidation.d.ts +295 -0
- package/dist/src/memory/ewc-consolidation.d.ts.map +1 -0
- package/dist/src/memory/ewc-consolidation.js +190 -303
- package/dist/src/memory/ewc-consolidation.js.map +1 -1
- package/dist/src/memory/intelligence.d.ts +338 -0
- package/dist/src/memory/intelligence.d.ts.map +1 -0
- package/dist/src/memory/intelligence.js +569 -794
- package/dist/src/memory/intelligence.js.map +1 -1
- package/dist/src/memory/memory-bridge.d.ts +407 -0
- package/dist/src/memory/memory-bridge.d.ts.map +1 -0
- package/dist/src/memory/memory-bridge.js +1170 -1640
- package/dist/src/memory/memory-bridge.js.map +1 -1
- package/dist/src/memory/memory-initializer.d.ts +412 -0
- package/dist/src/memory/memory-initializer.d.ts.map +1 -0
- package/dist/src/memory/memory-initializer.js +1836 -1851
- package/dist/src/memory/memory-initializer.js.map +1 -1
- package/dist/src/memory/sona-optimizer.d.ts +227 -0
- package/dist/src/memory/sona-optimizer.d.ts.map +1 -0
- package/dist/src/memory/sona-optimizer.js +199 -329
- package/dist/src/memory/sona-optimizer.js.map +1 -1
- package/dist/src/output.d.ts +2 -2
- package/dist/src/output.d.ts.map +1 -1
- package/dist/src/output.js +242 -272
- package/dist/src/output.js.map +1 -1
- package/dist/src/parser.d.ts +51 -0
- package/dist/src/parser.d.ts.map +1 -0
- package/dist/src/parser.js +140 -187
- package/dist/src/parser.js.map +1 -1
- package/dist/src/plugins/manager.d.ts +133 -0
- package/dist/src/plugins/manager.d.ts.map +1 -0
- package/dist/src/plugins/manager.js +285 -521
- package/dist/src/plugins/manager.js.map +1 -1
- package/dist/src/plugins/store/discovery.d.ts +88 -0
- package/dist/src/plugins/store/discovery.d.ts.map +1 -0
- package/dist/src/plugins/store/discovery.js +271 -358
- package/dist/src/plugins/store/discovery.js.map +1 -1
- package/dist/src/plugins/store/index.d.ts +76 -0
- package/dist/src/plugins/store/index.d.ts.map +1 -0
- package/dist/src/plugins/store/index.js +48 -105
- package/dist/src/plugins/store/index.js.map +1 -1
- package/dist/src/plugins/store/search.d.ts +46 -0
- package/dist/src/plugins/store/search.d.ts.map +1 -0
- package/dist/src/plugins/store/search.js +69 -107
- package/dist/src/plugins/store/search.js.map +1 -1
- package/dist/src/plugins/store/types.d.ts +274 -0
- package/dist/src/plugins/store/types.d.ts.map +1 -0
- package/dist/src/plugins/tests/demo-plugin-store.js +113 -160
- package/dist/src/plugins/tests/demo-plugin-store.js.map +1 -1
- package/dist/src/plugins/tests/standalone-test.js +172 -223
- package/dist/src/plugins/tests/standalone-test.js.map +1 -1
- package/dist/src/plugins/tests/test-plugin-store.js +190 -228
- package/dist/src/plugins/tests/test-plugin-store.js.map +1 -1
- package/dist/src/production/circuit-breaker.d.ts +101 -0
- package/dist/src/production/circuit-breaker.d.ts.map +1 -0
- package/dist/src/production/circuit-breaker.js +62 -126
- package/dist/src/production/circuit-breaker.js.map +1 -1
- package/dist/src/production/error-handler.d.ts +92 -0
- package/dist/src/production/error-handler.d.ts.map +1 -0
- package/dist/src/production/error-handler.js +86 -156
- package/dist/src/production/error-handler.js.map +1 -1
- package/dist/src/production/monitoring.d.ts +161 -0
- package/dist/src/production/monitoring.d.ts.map +1 -0
- package/dist/src/production/monitoring.js +139 -220
- package/dist/src/production/monitoring.js.map +1 -1
- package/dist/src/production/rate-limiter.d.ts +80 -0
- package/dist/src/production/rate-limiter.d.ts.map +1 -0
- package/dist/src/production/rate-limiter.js +74 -93
- package/dist/src/production/rate-limiter.js.map +1 -1
- package/dist/src/production/retry.d.ts +48 -0
- package/dist/src/production/retry.d.ts.map +1 -0
- package/dist/src/production/retry.js +75 -167
- package/dist/src/production/retry.js.map +1 -1
- package/dist/src/prompt.d.ts +44 -0
- package/dist/src/prompt.d.ts.map +1 -0
- package/dist/src/prompt.js +436 -560
- package/dist/src/prompt.js.map +1 -1
- package/dist/src/runtime/headless.d.ts +60 -0
- package/dist/src/runtime/headless.d.ts.map +1 -0
- package/dist/src/runtime/headless.js +197 -286
- package/dist/src/runtime/headless.js.map +1 -1
- package/dist/src/ruvector/agent-wasm.d.ts +182 -0
- package/dist/src/ruvector/agent-wasm.d.ts.map +1 -0
- package/dist/src/ruvector/agent-wasm.js +156 -351
- package/dist/src/ruvector/agent-wasm.js.map +1 -1
- package/dist/src/ruvector/ast-analyzer.d.ts +67 -0
- package/dist/src/ruvector/ast-analyzer.d.ts.map +1 -0
- package/dist/src/ruvector/ast-analyzer.js +145 -232
- package/dist/src/ruvector/ast-analyzer.js.map +1 -1
- package/dist/src/ruvector/coverage-router.d.ts +160 -0
- package/dist/src/ruvector/coverage-router.d.ts.map +1 -0
- package/dist/src/ruvector/coverage-router.js +287 -419
- package/dist/src/ruvector/coverage-router.js.map +1 -1
- package/dist/src/ruvector/coverage-tools.js +56 -101
- package/dist/src/ruvector/coverage-tools.js.map +1 -1
- package/dist/src/ruvector/diff-classifier.d.ts +175 -0
- package/dist/src/ruvector/diff-classifier.d.ts.map +1 -0
- package/dist/src/ruvector/diff-classifier.js +324 -451
- package/dist/src/ruvector/diff-classifier.js.map +1 -1
- package/dist/src/ruvector/enhanced-model-router.d.ts +146 -0
- package/dist/src/ruvector/enhanced-model-router.d.ts.map +1 -0
- package/dist/src/ruvector/enhanced-model-router.js +260 -336
- package/dist/src/ruvector/enhanced-model-router.js.map +1 -1
- package/dist/src/ruvector/flash-attention.d.ts +195 -0
- package/dist/src/ruvector/flash-attention.d.ts.map +1 -0
- package/dist/src/ruvector/flash-attention.js +223 -254
- package/dist/src/ruvector/flash-attention.js.map +1 -1
- package/dist/src/ruvector/graph-analyzer.d.ts +187 -0
- package/dist/src/ruvector/graph-analyzer.d.ts.map +1 -0
- package/dist/src/ruvector/graph-analyzer.js +486 -680
- package/dist/src/ruvector/graph-analyzer.js.map +1 -1
- package/dist/src/ruvector/index.d.ts +40 -0
- package/dist/src/ruvector/index.d.ts.map +1 -0
- package/dist/src/ruvector/index.js +36 -106
- package/dist/src/ruvector/index.js.map +1 -1
- package/dist/src/ruvector/lora-adapter.d.ts +218 -0
- package/dist/src/ruvector/lora-adapter.d.ts.map +1 -0
- package/dist/src/ruvector/lora-adapter.js +155 -248
- package/dist/src/ruvector/lora-adapter.js.map +1 -1
- package/dist/src/ruvector/model-router.d.ts +220 -0
- package/dist/src/ruvector/model-router.d.ts.map +1 -0
- package/dist/src/ruvector/model-router.js +175 -248
- package/dist/src/ruvector/model-router.js.map +1 -1
- package/dist/src/ruvector/moe-router.d.ts +206 -0
- package/dist/src/ruvector/moe-router.d.ts.map +1 -0
- package/dist/src/ruvector/moe-router.js +228 -286
- package/dist/src/ruvector/moe-router.js.map +1 -1
- package/dist/src/ruvector/q-learning-router.d.ts +211 -0
- package/dist/src/ruvector/q-learning-router.d.ts.map +1 -0
- package/dist/src/ruvector/q-learning-router.js +257 -338
- package/dist/src/ruvector/q-learning-router.js.map +1 -1
- package/dist/src/ruvector/ruvllm-wasm.d.ts +179 -0
- package/dist/src/ruvector/ruvllm-wasm.d.ts.map +1 -0
- package/dist/src/ruvector/ruvllm-wasm.js +270 -434
- package/dist/src/ruvector/ruvllm-wasm.js.map +1 -1
- package/dist/src/ruvector/semantic-router.d.ts +77 -0
- package/dist/src/ruvector/semantic-router.d.ts.map +1 -0
- package/dist/src/ruvector/semantic-router.js +60 -67
- package/dist/src/ruvector/semantic-router.js.map +1 -1
- package/dist/src/ruvector/vector-db.d.ts +69 -0
- package/dist/src/ruvector/vector-db.d.ts.map +1 -0
- package/dist/src/ruvector/vector-db.js +119 -205
- package/dist/src/ruvector/vector-db.js.map +1 -1
- package/dist/src/services/agentic-flow-bridge.d.ts +50 -0
- package/dist/src/services/agentic-flow-bridge.d.ts.map +1 -0
- package/dist/src/services/agentic-flow-bridge.js +32 -105
- package/dist/src/services/agentic-flow-bridge.js.map +1 -1
- package/dist/src/services/claim-service.d.ts +204 -0
- package/dist/src/services/claim-service.d.ts.map +1 -0
- package/dist/src/services/claim-service.js +615 -940
- package/dist/src/services/claim-service.js.map +1 -1
- package/dist/src/services/container-worker-pool.d.ts +197 -0
- package/dist/src/services/container-worker-pool.d.ts.map +1 -0
- package/dist/src/services/container-worker-pool.js +398 -666
- package/dist/src/services/container-worker-pool.js.map +1 -1
- package/dist/src/services/headless-worker-executor.d.ts +304 -0
- package/dist/src/services/headless-worker-executor.d.ts.map +1 -0
- package/dist/src/services/headless-worker-executor.js +441 -467
- package/dist/src/services/headless-worker-executor.js.map +1 -1
- package/dist/src/services/index.d.ts +4 -4
- package/dist/src/services/index.d.ts.map +1 -1
- package/dist/src/services/index.js +4 -4
- package/dist/src/services/index.js.map +1 -1
- package/dist/src/services/registry-api.d.ts +58 -0
- package/dist/src/services/registry-api.d.ts.map +1 -0
- package/dist/src/services/registry-api.js +92 -200
- package/dist/src/services/registry-api.js.map +1 -1
- package/dist/src/services/ruvector-training.d.ts +222 -0
- package/dist/src/services/ruvector-training.d.ts.map +1 -0
- package/dist/src/services/ruvector-training.js +257 -337
- package/dist/src/services/ruvector-training.js.map +1 -1
- package/dist/src/services/worker-daemon.d.ts +228 -0
- package/dist/src/services/worker-daemon.d.ts.map +1 -0
- package/dist/src/services/worker-daemon.js +591 -849
- package/dist/src/services/worker-daemon.js.map +1 -1
- package/dist/src/services/worker-queue.d.ts +194 -0
- package/dist/src/services/worker-queue.d.ts.map +1 -0
- package/dist/src/services/worker-queue.js +331 -548
- package/dist/src/services/worker-queue.js.map +1 -1
- package/dist/src/suggest.d.ts +53 -0
- package/dist/src/suggest.d.ts.map +1 -0
- package/dist/src/suggest.js +45 -55
- package/dist/src/suggest.js.map +1 -1
- package/dist/src/transfer/anonymization/index.js +29 -37
- package/dist/src/transfer/anonymization/index.js.map +1 -1
- package/dist/src/transfer/deploy-seraphine.js +128 -155
- package/dist/src/transfer/deploy-seraphine.js.map +1 -1
- package/dist/src/transfer/export.d.ts +25 -0
- package/dist/src/transfer/export.d.ts.map +1 -0
- package/dist/src/transfer/export.js +84 -142
- package/dist/src/transfer/export.js.map +1 -1
- package/dist/src/transfer/index.d.ts +1 -1
- package/dist/src/transfer/index.d.ts.map +1 -1
- package/dist/src/transfer/index.js +0 -2
- package/dist/src/transfer/index.js.map +1 -1
- package/dist/src/transfer/ipfs/client.d.ts +109 -0
- package/dist/src/transfer/ipfs/client.d.ts.map +1 -0
- package/dist/src/transfer/ipfs/client.js +187 -337
- package/dist/src/transfer/ipfs/client.js.map +1 -1
- package/dist/src/transfer/ipfs/upload.d.ts +95 -0
- package/dist/src/transfer/ipfs/upload.d.ts.map +1 -0
- package/dist/src/transfer/ipfs/upload.js +288 -434
- package/dist/src/transfer/ipfs/upload.js.map +1 -1
- package/dist/src/transfer/models/seraphine.d.ts +72 -0
- package/dist/src/transfer/models/seraphine.d.ts.map +1 -0
- package/dist/src/transfer/models/seraphine.js +55 -55
- package/dist/src/transfer/models/seraphine.js.map +1 -1
- package/dist/src/transfer/serialization/cfp.d.ts +49 -0
- package/dist/src/transfer/serialization/cfp.d.ts.map +1 -0
- package/dist/src/transfer/serialization/cfp.js +30 -31
- package/dist/src/transfer/serialization/cfp.js.map +1 -1
- package/dist/src/transfer/storage/gcs.d.ts +82 -0
- package/dist/src/transfer/storage/gcs.d.ts.map +1 -0
- package/dist/src/transfer/storage/gcs.js +165 -232
- package/dist/src/transfer/storage/gcs.js.map +1 -1
- package/dist/src/transfer/store/discovery.d.ts +84 -0
- package/dist/src/transfer/store/discovery.d.ts.map +1 -0
- package/dist/src/transfer/store/discovery.js +239 -349
- package/dist/src/transfer/store/discovery.js.map +1 -1
- package/dist/src/transfer/store/download.d.ts +70 -0
- package/dist/src/transfer/store/download.d.ts.map +1 -0
- package/dist/src/transfer/store/download.js +243 -365
- package/dist/src/transfer/store/download.js.map +1 -1
- package/dist/src/transfer/store/index.d.ts +84 -0
- package/dist/src/transfer/store/index.d.ts.map +1 -0
- package/dist/src/transfer/store/index.js +63 -130
- package/dist/src/transfer/store/index.js.map +1 -1
- package/dist/src/transfer/store/publish.d.ts +76 -0
- package/dist/src/transfer/store/publish.d.ts.map +1 -0
- package/dist/src/transfer/store/publish.js +184 -258
- package/dist/src/transfer/store/publish.js.map +1 -1
- package/dist/src/transfer/store/registry.js +50 -72
- package/dist/src/transfer/store/registry.js.map +1 -1
- package/dist/src/transfer/store/search.d.ts +54 -0
- package/dist/src/transfer/store/search.d.ts.map +1 -0
- package/dist/src/transfer/store/search.js +64 -96
- package/dist/src/transfer/store/search.js.map +1 -1
- package/dist/src/transfer/store/tests/standalone-test.js +174 -231
- package/dist/src/transfer/store/tests/standalone-test.js.map +1 -1
- package/dist/src/transfer/test-seraphine.js +95 -130
- package/dist/src/transfer/test-seraphine.js.map +1 -1
- package/dist/src/transfer/tests/test-store.js +194 -239
- package/dist/src/transfer/tests/test-store.js.map +1 -1
- package/dist/src/transfer/types.d.ts +245 -0
- package/dist/src/transfer/types.d.ts.map +1 -0
- package/dist/src/types.d.ts +198 -0
- package/dist/src/types.d.ts.map +1 -0
- package/dist/src/types.js +26 -55
- package/dist/src/types.js.map +1 -1
- package/dist/src/update/checker.d.ts +34 -0
- package/dist/src/update/checker.d.ts.map +1 -0
- package/dist/src/update/checker.js +106 -183
- package/dist/src/update/checker.js.map +1 -1
- package/dist/src/update/executor.d.ts +32 -0
- package/dist/src/update/executor.d.ts.map +1 -0
- package/dist/src/update/executor.js +135 -198
- package/dist/src/update/executor.js.map +1 -1
- package/dist/src/update/index.d.ts +33 -0
- package/dist/src/update/index.d.ts.map +1 -0
- package/dist/src/update/index.js +38 -85
- package/dist/src/update/index.js.map +1 -1
- package/dist/src/update/rate-limiter.d.ts +20 -0
- package/dist/src/update/rate-limiter.d.ts.map +1 -0
- package/dist/src/update/rate-limiter.js +19 -31
- package/dist/src/update/rate-limiter.js.map +1 -1
- package/dist/src/update/validator.d.ts +17 -0
- package/dist/src/update/validator.d.ts.map +1 -0
- package/dist/src/update/validator.js +38 -64
- package/dist/src/update/validator.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
|
@@ -15,99 +15,28 @@
|
|
|
15
15
|
* - Volume mounting for workspace access
|
|
16
16
|
* - Network isolation per worker type
|
|
17
17
|
*/
|
|
18
|
-
var __extends = (this && this.__extends) || (function () {
|
|
19
|
-
var extendStatics = function (d, b) {
|
|
20
|
-
extendStatics = Object.setPrototypeOf ||
|
|
21
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
22
|
-
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
23
|
-
return extendStatics(d, b);
|
|
24
|
-
};
|
|
25
|
-
return function (d, b) {
|
|
26
|
-
if (typeof b !== "function" && b !== null)
|
|
27
|
-
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
28
|
-
extendStatics(d, b);
|
|
29
|
-
function __() { this.constructor = d; }
|
|
30
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
31
|
-
};
|
|
32
|
-
})();
|
|
33
|
-
var __assign = (this && this.__assign) || function () {
|
|
34
|
-
__assign = Object.assign || function(t) {
|
|
35
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
36
|
-
s = arguments[i];
|
|
37
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
38
|
-
t[p] = s[p];
|
|
39
|
-
}
|
|
40
|
-
return t;
|
|
41
|
-
};
|
|
42
|
-
return __assign.apply(this, arguments);
|
|
43
|
-
};
|
|
44
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
45
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
46
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
47
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
48
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
49
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
50
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
51
|
-
});
|
|
52
|
-
};
|
|
53
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
54
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
55
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
56
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
57
|
-
function step(op) {
|
|
58
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
59
|
-
while (_) try {
|
|
60
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
61
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
62
|
-
switch (op[0]) {
|
|
63
|
-
case 0: case 1: t = op; break;
|
|
64
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
65
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
66
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
67
|
-
default:
|
|
68
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
69
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
70
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
71
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
72
|
-
if (t[2]) _.ops.pop();
|
|
73
|
-
_.trys.pop(); continue;
|
|
74
|
-
}
|
|
75
|
-
op = body.call(thisArg, _);
|
|
76
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
77
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
78
|
-
}
|
|
79
|
-
};
|
|
80
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
81
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
82
|
-
if (ar || !(i in from)) {
|
|
83
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
84
|
-
ar[i] = from[i];
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
88
|
-
};
|
|
89
18
|
import { EventEmitter } from 'events';
|
|
90
19
|
import { spawn, exec } from 'child_process';
|
|
91
20
|
import { promisify } from 'util';
|
|
92
21
|
import { existsSync, mkdirSync } from 'fs';
|
|
93
22
|
import { join } from 'path';
|
|
94
|
-
|
|
23
|
+
const execAsync = promisify(exec);
|
|
95
24
|
// ============================================
|
|
96
25
|
// Constants
|
|
97
26
|
// ============================================
|
|
98
|
-
|
|
27
|
+
const DEFAULT_CONFIG = {
|
|
99
28
|
maxContainers: 3,
|
|
100
29
|
minContainers: 1,
|
|
101
30
|
image: 'ghcr.io/ruvnet/claude-flow-headless:latest',
|
|
102
31
|
resources: {
|
|
103
32
|
cpus: '2',
|
|
104
|
-
memory: '4g'
|
|
33
|
+
memory: '4g',
|
|
105
34
|
},
|
|
106
35
|
healthCheckIntervalMs: 30000,
|
|
107
|
-
idleTimeoutMs: 300000,
|
|
36
|
+
idleTimeoutMs: 300000, // 5 minutes
|
|
108
37
|
workspacePath: '/workspace',
|
|
109
38
|
statePath: '.claude-flow/container-pool',
|
|
110
|
-
defaultSandbox: 'strict'
|
|
39
|
+
defaultSandbox: 'strict',
|
|
111
40
|
};
|
|
112
41
|
// ============================================
|
|
113
42
|
// ContainerWorkerPool Class
|
|
@@ -115,24 +44,26 @@ var DEFAULT_CONFIG = {
|
|
|
115
44
|
/**
|
|
116
45
|
* ContainerWorkerPool - Manages Docker containers for headless worker execution
|
|
117
46
|
*/
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
47
|
+
export class ContainerWorkerPool extends EventEmitter {
|
|
48
|
+
config;
|
|
49
|
+
projectRoot;
|
|
50
|
+
containers = new Map();
|
|
51
|
+
taskQueue = [];
|
|
52
|
+
healthCheckTimer;
|
|
53
|
+
idleCheckTimer;
|
|
54
|
+
dockerAvailable = null;
|
|
55
|
+
initialized = false;
|
|
56
|
+
isShuttingDown = false;
|
|
57
|
+
exitHandlersRegistered = false;
|
|
58
|
+
constructor(projectRoot, config) {
|
|
59
|
+
super();
|
|
60
|
+
this.projectRoot = projectRoot;
|
|
61
|
+
this.config = { ...DEFAULT_CONFIG, ...config };
|
|
130
62
|
// Ensure state directory exists
|
|
131
|
-
|
|
63
|
+
const stateDir = join(projectRoot, this.config.statePath);
|
|
132
64
|
if (!existsSync(stateDir)) {
|
|
133
65
|
mkdirSync(stateDir, { recursive: true });
|
|
134
66
|
}
|
|
135
|
-
return _this;
|
|
136
67
|
}
|
|
137
68
|
// ============================================
|
|
138
69
|
// Public API
|
|
@@ -140,523 +71,382 @@ var ContainerWorkerPool = /** @class */ (function (_super) {
|
|
|
140
71
|
/**
|
|
141
72
|
* Initialize the container pool
|
|
142
73
|
*/
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
// Create minimum containers
|
|
168
|
-
return [4 /*yield*/, this.scaleToMinimum()];
|
|
169
|
-
case 3:
|
|
170
|
-
// Create minimum containers
|
|
171
|
-
_b.sent();
|
|
172
|
-
// Start health check timer
|
|
173
|
-
this.startHealthChecks();
|
|
174
|
-
// Start idle check timer
|
|
175
|
-
this.startIdleChecks();
|
|
176
|
-
// Register exit handlers for cleanup
|
|
177
|
-
this.registerExitHandlers();
|
|
178
|
-
this.initialized = true;
|
|
179
|
-
this.emit('initialized', { containers: this.containers.size });
|
|
180
|
-
return [2 /*return*/, true];
|
|
181
|
-
}
|
|
182
|
-
});
|
|
183
|
-
});
|
|
184
|
-
};
|
|
74
|
+
async initialize() {
|
|
75
|
+
if (this.initialized) {
|
|
76
|
+
return true;
|
|
77
|
+
}
|
|
78
|
+
// Check Docker availability
|
|
79
|
+
this.dockerAvailable = await this.checkDockerAvailable();
|
|
80
|
+
if (!this.dockerAvailable) {
|
|
81
|
+
this.emit('warning', { message: 'Docker not available - container pool disabled' });
|
|
82
|
+
return false;
|
|
83
|
+
}
|
|
84
|
+
// Pull image if needed
|
|
85
|
+
await this.ensureImage();
|
|
86
|
+
// Create minimum containers
|
|
87
|
+
await this.scaleToMinimum();
|
|
88
|
+
// Start health check timer
|
|
89
|
+
this.startHealthChecks();
|
|
90
|
+
// Start idle check timer
|
|
91
|
+
this.startIdleChecks();
|
|
92
|
+
// Register exit handlers for cleanup
|
|
93
|
+
this.registerExitHandlers();
|
|
94
|
+
this.initialized = true;
|
|
95
|
+
this.emit('initialized', { containers: this.containers.size });
|
|
96
|
+
return true;
|
|
97
|
+
}
|
|
185
98
|
/**
|
|
186
99
|
* Register process exit handlers to clean up containers
|
|
187
100
|
*/
|
|
188
|
-
|
|
189
|
-
var _this = this;
|
|
101
|
+
registerExitHandlers() {
|
|
190
102
|
if (this.exitHandlersRegistered)
|
|
191
103
|
return;
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
return [4 /*yield*/, this.shutdown()];
|
|
198
|
-
case 1:
|
|
199
|
-
_a.sent();
|
|
200
|
-
_a.label = 2;
|
|
201
|
-
case 2: return [2 /*return*/];
|
|
202
|
-
}
|
|
203
|
-
});
|
|
204
|
-
}); };
|
|
104
|
+
const cleanup = async () => {
|
|
105
|
+
if (!this.isShuttingDown) {
|
|
106
|
+
await this.shutdown();
|
|
107
|
+
}
|
|
108
|
+
};
|
|
205
109
|
process.once('SIGTERM', cleanup);
|
|
206
110
|
process.once('SIGINT', cleanup);
|
|
207
111
|
process.once('beforeExit', cleanup);
|
|
208
112
|
this.exitHandlersRegistered = true;
|
|
209
|
-
}
|
|
113
|
+
}
|
|
210
114
|
/**
|
|
211
115
|
* Execute a worker in a container
|
|
212
116
|
*/
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
return [2 /*return*/, new Promise(function (resolve, reject) {
|
|
244
|
-
_this.taskQueue.push({
|
|
245
|
-
options: options,
|
|
246
|
-
resolve: resolve,
|
|
247
|
-
reject: reject,
|
|
248
|
-
queuedAt: new Date()
|
|
249
|
-
});
|
|
250
|
-
_this.emit('taskQueued', {
|
|
251
|
-
workerType: options.workerType,
|
|
252
|
-
queuePosition: _this.taskQueue.length
|
|
253
|
-
});
|
|
254
|
-
})];
|
|
255
|
-
}
|
|
117
|
+
async execute(options) {
|
|
118
|
+
if (!this.initialized) {
|
|
119
|
+
await this.initialize();
|
|
120
|
+
}
|
|
121
|
+
if (!this.dockerAvailable) {
|
|
122
|
+
return this.createErrorResult(options.workerType, 'Docker not available');
|
|
123
|
+
}
|
|
124
|
+
// Try to get a ready container
|
|
125
|
+
const container = this.getReadyContainer();
|
|
126
|
+
if (container) {
|
|
127
|
+
return this.executeInContainer(container, options);
|
|
128
|
+
}
|
|
129
|
+
// No ready containers - check if we can create more
|
|
130
|
+
if (this.containers.size < this.config.maxContainers) {
|
|
131
|
+
const newContainer = await this.createContainer();
|
|
132
|
+
if (newContainer) {
|
|
133
|
+
return this.executeInContainer(newContainer, options);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
// Queue the task
|
|
137
|
+
return new Promise((resolve, reject) => {
|
|
138
|
+
this.taskQueue.push({
|
|
139
|
+
options,
|
|
140
|
+
resolve,
|
|
141
|
+
reject,
|
|
142
|
+
queuedAt: new Date(),
|
|
143
|
+
});
|
|
144
|
+
this.emit('taskQueued', {
|
|
145
|
+
workerType: options.workerType,
|
|
146
|
+
queuePosition: this.taskQueue.length,
|
|
256
147
|
});
|
|
257
148
|
});
|
|
258
|
-
}
|
|
149
|
+
}
|
|
259
150
|
/**
|
|
260
151
|
* Scale pool for batch execution
|
|
261
152
|
*/
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
}
|
|
276
|
-
return [4 /*yield*/, Promise.all(createPromises)];
|
|
277
|
-
case 1:
|
|
278
|
-
_a.sent();
|
|
279
|
-
this.emit('scaled', { from: currentSize, to: this.containers.size });
|
|
280
|
-
_a.label = 2;
|
|
281
|
-
case 2: return [2 /*return*/];
|
|
282
|
-
}
|
|
283
|
-
});
|
|
284
|
-
});
|
|
285
|
-
};
|
|
153
|
+
async scaleForBatch(workerCount) {
|
|
154
|
+
const targetSize = Math.min(workerCount, this.config.maxContainers);
|
|
155
|
+
const currentSize = this.containers.size;
|
|
156
|
+
if (targetSize > currentSize) {
|
|
157
|
+
const toCreate = targetSize - currentSize;
|
|
158
|
+
const createPromises = [];
|
|
159
|
+
for (let i = 0; i < toCreate; i++) {
|
|
160
|
+
createPromises.push(this.createContainer());
|
|
161
|
+
}
|
|
162
|
+
await Promise.all(createPromises);
|
|
163
|
+
this.emit('scaled', { from: currentSize, to: this.containers.size });
|
|
164
|
+
}
|
|
165
|
+
}
|
|
286
166
|
/**
|
|
287
167
|
* Get pool status
|
|
288
168
|
*/
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
var containers = Array.from(this.containers.values());
|
|
169
|
+
getStatus() {
|
|
170
|
+
const containers = Array.from(this.containers.values());
|
|
292
171
|
return {
|
|
293
172
|
totalContainers: containers.length,
|
|
294
|
-
readyContainers: containers.filter(
|
|
295
|
-
busyContainers: containers.filter(
|
|
296
|
-
unhealthyContainers: containers.filter(
|
|
173
|
+
readyContainers: containers.filter(c => c.state === 'ready').length,
|
|
174
|
+
busyContainers: containers.filter(c => c.state === 'busy').length,
|
|
175
|
+
unhealthyContainers: containers.filter(c => c.state === 'unhealthy').length,
|
|
297
176
|
queuedTasks: this.taskQueue.length,
|
|
298
|
-
containers
|
|
299
|
-
dockerAvailable:
|
|
300
|
-
lastHealthCheck: undefined
|
|
177
|
+
containers,
|
|
178
|
+
dockerAvailable: this.dockerAvailable ?? false,
|
|
179
|
+
lastHealthCheck: undefined, // Will be set by health check
|
|
301
180
|
};
|
|
302
|
-
}
|
|
181
|
+
}
|
|
303
182
|
/**
|
|
304
183
|
* Shutdown the pool
|
|
305
184
|
*/
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
Promise.all(terminatePromises),
|
|
340
|
-
new Promise(function (resolve) { return setTimeout(resolve, 30000); }),
|
|
341
|
-
])];
|
|
342
|
-
case 1:
|
|
343
|
-
// Wait for all containers with 30s timeout
|
|
344
|
-
_d.sent();
|
|
345
|
-
this.initialized = false;
|
|
346
|
-
this.emit('shutdown', {});
|
|
347
|
-
return [2 /*return*/];
|
|
348
|
-
}
|
|
349
|
-
});
|
|
350
|
-
});
|
|
351
|
-
};
|
|
185
|
+
async shutdown() {
|
|
186
|
+
if (this.isShuttingDown)
|
|
187
|
+
return;
|
|
188
|
+
this.isShuttingDown = true;
|
|
189
|
+
// Stop timers
|
|
190
|
+
if (this.healthCheckTimer) {
|
|
191
|
+
clearInterval(this.healthCheckTimer);
|
|
192
|
+
this.healthCheckTimer = undefined;
|
|
193
|
+
}
|
|
194
|
+
if (this.idleCheckTimer) {
|
|
195
|
+
clearInterval(this.idleCheckTimer);
|
|
196
|
+
this.idleCheckTimer = undefined;
|
|
197
|
+
}
|
|
198
|
+
// Reject queued tasks
|
|
199
|
+
for (const task of this.taskQueue) {
|
|
200
|
+
task.reject(new Error('Pool shutting down'));
|
|
201
|
+
}
|
|
202
|
+
this.taskQueue = [];
|
|
203
|
+
// Terminate all containers with timeout
|
|
204
|
+
const terminatePromises = [];
|
|
205
|
+
for (const [id] of this.containers) {
|
|
206
|
+
terminatePromises.push(this.terminateContainer(id).catch(() => {
|
|
207
|
+
// Ignore errors during shutdown
|
|
208
|
+
}));
|
|
209
|
+
}
|
|
210
|
+
// Wait for all containers with 30s timeout
|
|
211
|
+
await Promise.race([
|
|
212
|
+
Promise.all(terminatePromises),
|
|
213
|
+
new Promise(resolve => setTimeout(resolve, 30000)),
|
|
214
|
+
]);
|
|
215
|
+
this.initialized = false;
|
|
216
|
+
this.emit('shutdown', {});
|
|
217
|
+
}
|
|
352
218
|
// ============================================
|
|
353
219
|
// Private Methods - Container Lifecycle
|
|
354
220
|
// ============================================
|
|
355
221
|
/**
|
|
356
222
|
* Check if Docker is available (async)
|
|
357
223
|
*/
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
return [4 /*yield*/, execAsync('docker info', { timeout: 10000 })];
|
|
369
|
-
case 2:
|
|
370
|
-
_b.sent();
|
|
371
|
-
return [2 /*return*/, true];
|
|
372
|
-
case 3:
|
|
373
|
-
_a = _b.sent();
|
|
374
|
-
return [2 /*return*/, false];
|
|
375
|
-
case 4: return [2 /*return*/];
|
|
376
|
-
}
|
|
377
|
-
});
|
|
378
|
-
});
|
|
379
|
-
};
|
|
224
|
+
async checkDockerAvailable() {
|
|
225
|
+
try {
|
|
226
|
+
await execAsync('docker --version', { timeout: 5000 });
|
|
227
|
+
await execAsync('docker info', { timeout: 10000 });
|
|
228
|
+
return true;
|
|
229
|
+
}
|
|
230
|
+
catch {
|
|
231
|
+
return false;
|
|
232
|
+
}
|
|
233
|
+
}
|
|
380
234
|
/**
|
|
381
235
|
* Ensure the container image exists (async)
|
|
382
236
|
*/
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
case 3:
|
|
400
|
-
_b.trys.push([3, 5, , 6]);
|
|
401
|
-
return [4 /*yield*/, execAsync("docker pull " + this.config.image, { timeout: 300000 })];
|
|
402
|
-
case 4:
|
|
403
|
-
_b.sent();
|
|
404
|
-
return [3 /*break*/, 6];
|
|
405
|
-
case 5:
|
|
406
|
-
error_1 = _b.sent();
|
|
407
|
-
this.emit('warning', { message: "Failed to pull image: " + error_1 });
|
|
408
|
-
return [3 /*break*/, 6];
|
|
409
|
-
case 6: return [3 /*break*/, 7];
|
|
410
|
-
case 7: return [2 /*return*/];
|
|
411
|
-
}
|
|
412
|
-
});
|
|
413
|
-
});
|
|
414
|
-
};
|
|
237
|
+
async ensureImage() {
|
|
238
|
+
try {
|
|
239
|
+
await execAsync(`docker image inspect ${this.config.image}`, { timeout: 10000 });
|
|
240
|
+
}
|
|
241
|
+
catch {
|
|
242
|
+
// Image not found, try to pull
|
|
243
|
+
this.emit('imagePull', { image: this.config.image });
|
|
244
|
+
try {
|
|
245
|
+
await execAsync(`docker pull ${this.config.image}`, { timeout: 300000 });
|
|
246
|
+
}
|
|
247
|
+
catch (error) {
|
|
248
|
+
this.emit('warning', { message: `Failed to pull image: ${error}` });
|
|
249
|
+
// Continue anyway - might work with local image
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
}
|
|
415
253
|
/**
|
|
416
254
|
* Create a new container
|
|
417
255
|
*/
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
_b = _a[_i], key = _b[0], value = _b[1];
|
|
453
|
-
if (value) {
|
|
454
|
-
args.push('-e', key + "=" + value);
|
|
455
|
-
}
|
|
456
|
-
}
|
|
457
|
-
// Add network if specified
|
|
458
|
-
if (this.config.network) {
|
|
459
|
-
args.push('--network', this.config.network);
|
|
460
|
-
}
|
|
461
|
-
// Add image and entrypoint to keep container running
|
|
462
|
-
args.push(this.config.image, 'tail', '-f', '/dev/null');
|
|
463
|
-
return [4 /*yield*/, execAsync("docker " + args.join(' '), { timeout: 60000 })];
|
|
464
|
-
case 2:
|
|
465
|
-
stdout = (_c.sent()).stdout;
|
|
466
|
-
containerId = stdout.trim();
|
|
467
|
-
containerInfo.state = 'ready';
|
|
468
|
-
this.emit('containerCreated', { id: id, name: name, containerId: containerId });
|
|
469
|
-
return [2 /*return*/, containerInfo];
|
|
470
|
-
case 3:
|
|
471
|
-
error_2 = _c.sent();
|
|
472
|
-
this.containers["delete"](id);
|
|
473
|
-
this.emit('containerError', { id: id, error: String(error_2) });
|
|
474
|
-
return [2 /*return*/, null];
|
|
475
|
-
case 4: return [2 /*return*/];
|
|
256
|
+
async createContainer() {
|
|
257
|
+
const id = `cf-worker-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`;
|
|
258
|
+
const name = `claude-flow-worker-${id}`;
|
|
259
|
+
const containerInfo = {
|
|
260
|
+
id,
|
|
261
|
+
name,
|
|
262
|
+
state: 'creating',
|
|
263
|
+
createdAt: new Date(),
|
|
264
|
+
executionCount: 0,
|
|
265
|
+
healthCheckFailures: 0,
|
|
266
|
+
};
|
|
267
|
+
this.containers.set(id, containerInfo);
|
|
268
|
+
this.emit('containerCreating', { id, name });
|
|
269
|
+
try {
|
|
270
|
+
// Build docker run command
|
|
271
|
+
const args = [
|
|
272
|
+
'run', '-d',
|
|
273
|
+
'--name', name,
|
|
274
|
+
'--cpus', this.config.resources.cpus,
|
|
275
|
+
'--memory', this.config.resources.memory,
|
|
276
|
+
'-v', `${this.projectRoot}:${this.config.workspacePath}:ro`,
|
|
277
|
+
'-v', `${join(this.projectRoot, this.config.statePath)}:/root/.claude-flow`,
|
|
278
|
+
'-w', this.config.workspacePath,
|
|
279
|
+
];
|
|
280
|
+
// Add environment variables
|
|
281
|
+
const env = {
|
|
282
|
+
...this.config.env,
|
|
283
|
+
ANTHROPIC_API_KEY: process.env.ANTHROPIC_API_KEY || '',
|
|
284
|
+
CLAUDE_CODE_HEADLESS: 'true',
|
|
285
|
+
CLAUDE_CODE_SANDBOX_MODE: this.config.defaultSandbox,
|
|
286
|
+
};
|
|
287
|
+
for (const [key, value] of Object.entries(env)) {
|
|
288
|
+
if (value) {
|
|
289
|
+
args.push('-e', `${key}=${value}`);
|
|
476
290
|
}
|
|
477
|
-
}
|
|
478
|
-
|
|
479
|
-
|
|
291
|
+
}
|
|
292
|
+
// Add network if specified
|
|
293
|
+
if (this.config.network) {
|
|
294
|
+
args.push('--network', this.config.network);
|
|
295
|
+
}
|
|
296
|
+
// Add image and entrypoint to keep container running
|
|
297
|
+
args.push(this.config.image, 'tail', '-f', '/dev/null');
|
|
298
|
+
// Create the container (async)
|
|
299
|
+
const { stdout } = await execAsync(`docker ${args.join(' ')}`, { timeout: 60000 });
|
|
300
|
+
const containerId = stdout.trim();
|
|
301
|
+
containerInfo.state = 'ready';
|
|
302
|
+
this.emit('containerCreated', { id, name, containerId });
|
|
303
|
+
return containerInfo;
|
|
304
|
+
}
|
|
305
|
+
catch (error) {
|
|
306
|
+
this.containers.delete(id);
|
|
307
|
+
this.emit('containerError', { id, error: String(error) });
|
|
308
|
+
return null;
|
|
309
|
+
}
|
|
310
|
+
}
|
|
480
311
|
/**
|
|
481
312
|
* Terminate a container (async)
|
|
482
313
|
*/
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
return
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
case 2:
|
|
498
|
-
_b.sent();
|
|
499
|
-
return [3 /*break*/, 4];
|
|
500
|
-
case 3:
|
|
501
|
-
_a = _b.sent();
|
|
502
|
-
return [3 /*break*/, 4];
|
|
503
|
-
case 4:
|
|
504
|
-
this.containers["delete"](id);
|
|
505
|
-
this.emit('containerTerminated', { id: id, name: container.name });
|
|
506
|
-
return [2 /*return*/];
|
|
507
|
-
}
|
|
508
|
-
});
|
|
509
|
-
});
|
|
510
|
-
};
|
|
314
|
+
async terminateContainer(id) {
|
|
315
|
+
const container = this.containers.get(id);
|
|
316
|
+
if (!container)
|
|
317
|
+
return;
|
|
318
|
+
container.state = 'terminated';
|
|
319
|
+
try {
|
|
320
|
+
await execAsync(`docker rm -f ${container.name}`, { timeout: 30000 });
|
|
321
|
+
}
|
|
322
|
+
catch {
|
|
323
|
+
// Ignore removal errors
|
|
324
|
+
}
|
|
325
|
+
this.containers.delete(id);
|
|
326
|
+
this.emit('containerTerminated', { id, name: container.name });
|
|
327
|
+
}
|
|
511
328
|
/**
|
|
512
329
|
* Get a ready container
|
|
513
330
|
*/
|
|
514
|
-
|
|
515
|
-
for (
|
|
516
|
-
var container = _a[_i];
|
|
331
|
+
getReadyContainer() {
|
|
332
|
+
for (const container of this.containers.values()) {
|
|
517
333
|
if (container.state === 'ready') {
|
|
518
334
|
return container;
|
|
519
335
|
}
|
|
520
336
|
}
|
|
521
337
|
return null;
|
|
522
|
-
}
|
|
338
|
+
}
|
|
523
339
|
/**
|
|
524
340
|
* Scale to minimum containers
|
|
525
341
|
*/
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
createPromises.push(this.createContainer());
|
|
538
|
-
}
|
|
539
|
-
return [4 /*yield*/, Promise.all(createPromises)];
|
|
540
|
-
case 1:
|
|
541
|
-
_a.sent();
|
|
542
|
-
_a.label = 2;
|
|
543
|
-
case 2: return [2 /*return*/];
|
|
544
|
-
}
|
|
545
|
-
});
|
|
546
|
-
});
|
|
547
|
-
};
|
|
342
|
+
async scaleToMinimum() {
|
|
343
|
+
const current = this.containers.size;
|
|
344
|
+
const needed = this.config.minContainers - current;
|
|
345
|
+
if (needed > 0) {
|
|
346
|
+
const createPromises = [];
|
|
347
|
+
for (let i = 0; i < needed; i++) {
|
|
348
|
+
createPromises.push(this.createContainer());
|
|
349
|
+
}
|
|
350
|
+
await Promise.all(createPromises);
|
|
351
|
+
}
|
|
352
|
+
}
|
|
548
353
|
// ============================================
|
|
549
354
|
// Private Methods - Execution
|
|
550
355
|
// ============================================
|
|
551
356
|
/**
|
|
552
357
|
* Execute worker in a specific container
|
|
553
358
|
*/
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
result.durationMs = Date.now() - startTime;
|
|
597
|
-
this.emit('executionError', result);
|
|
598
|
-
// Process queue
|
|
599
|
-
this.processQueue();
|
|
600
|
-
return [2 /*return*/, result];
|
|
601
|
-
case 4: return [2 /*return*/];
|
|
602
|
-
}
|
|
603
|
-
});
|
|
604
|
-
});
|
|
605
|
-
};
|
|
359
|
+
async executeInContainer(container, options) {
|
|
360
|
+
const startTime = Date.now();
|
|
361
|
+
const executionId = `${options.workerType}_${startTime}_${Math.random().toString(36).slice(2, 8)}`;
|
|
362
|
+
container.state = 'busy';
|
|
363
|
+
container.workerType = options.workerType;
|
|
364
|
+
container.lastUsedAt = new Date();
|
|
365
|
+
this.emit('executionStart', { executionId, containerId: container.id, workerType: options.workerType });
|
|
366
|
+
try {
|
|
367
|
+
// Build the command to run inside container
|
|
368
|
+
const command = this.buildWorkerCommand(options);
|
|
369
|
+
// Execute in container with timeout
|
|
370
|
+
const timeoutMs = options.timeoutMs || 300000;
|
|
371
|
+
const output = await this.execInContainer(container.name, command, timeoutMs);
|
|
372
|
+
container.state = 'ready';
|
|
373
|
+
container.executionCount++;
|
|
374
|
+
const result = {
|
|
375
|
+
success: true,
|
|
376
|
+
output: output,
|
|
377
|
+
parsedOutput: this.tryParseJson(output),
|
|
378
|
+
durationMs: Date.now() - startTime,
|
|
379
|
+
model: options.model || 'sonnet',
|
|
380
|
+
sandboxMode: options.sandbox || this.config.defaultSandbox,
|
|
381
|
+
workerType: options.workerType,
|
|
382
|
+
timestamp: new Date(),
|
|
383
|
+
executionId,
|
|
384
|
+
};
|
|
385
|
+
this.emit('executionComplete', result);
|
|
386
|
+
// Process queue
|
|
387
|
+
this.processQueue();
|
|
388
|
+
return result;
|
|
389
|
+
}
|
|
390
|
+
catch (error) {
|
|
391
|
+
container.state = 'ready';
|
|
392
|
+
const result = this.createErrorResult(options.workerType, error instanceof Error ? error.message : String(error));
|
|
393
|
+
result.executionId = executionId;
|
|
394
|
+
result.durationMs = Date.now() - startTime;
|
|
395
|
+
this.emit('executionError', result);
|
|
396
|
+
// Process queue
|
|
397
|
+
this.processQueue();
|
|
398
|
+
return result;
|
|
399
|
+
}
|
|
400
|
+
}
|
|
606
401
|
/**
|
|
607
402
|
* Execute command in container
|
|
608
403
|
*/
|
|
609
|
-
|
|
610
|
-
return
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
child.on('error', function (error) {
|
|
649
|
-
clearTimeout(timeout);
|
|
650
|
-
reject(error);
|
|
651
|
-
});
|
|
652
|
-
})];
|
|
404
|
+
async execInContainer(containerName, command, timeoutMs) {
|
|
405
|
+
return new Promise((resolve, reject) => {
|
|
406
|
+
const args = ['exec', containerName, ...command];
|
|
407
|
+
const child = spawn('docker', args, {
|
|
408
|
+
stdio: ['pipe', 'pipe', 'pipe'],
|
|
409
|
+
});
|
|
410
|
+
let stdout = '';
|
|
411
|
+
let stderr = '';
|
|
412
|
+
let timedOut = false;
|
|
413
|
+
const timeout = setTimeout(() => {
|
|
414
|
+
timedOut = true;
|
|
415
|
+
child.kill('SIGTERM');
|
|
416
|
+
setTimeout(() => {
|
|
417
|
+
if (!child.killed) {
|
|
418
|
+
child.kill('SIGKILL');
|
|
419
|
+
}
|
|
420
|
+
}, 5000);
|
|
421
|
+
}, timeoutMs);
|
|
422
|
+
child.stdout?.on('data', (data) => {
|
|
423
|
+
stdout += data.toString();
|
|
424
|
+
});
|
|
425
|
+
child.stderr?.on('data', (data) => {
|
|
426
|
+
stderr += data.toString();
|
|
427
|
+
});
|
|
428
|
+
child.on('close', (code) => {
|
|
429
|
+
clearTimeout(timeout);
|
|
430
|
+
if (timedOut) {
|
|
431
|
+
reject(new Error(`Execution timed out after ${timeoutMs}ms`));
|
|
432
|
+
return;
|
|
433
|
+
}
|
|
434
|
+
if (code !== 0) {
|
|
435
|
+
reject(new Error(stderr || `Process exited with code ${code}`));
|
|
436
|
+
return;
|
|
437
|
+
}
|
|
438
|
+
resolve(stdout);
|
|
439
|
+
});
|
|
440
|
+
child.on('error', (error) => {
|
|
441
|
+
clearTimeout(timeout);
|
|
442
|
+
reject(error);
|
|
653
443
|
});
|
|
654
444
|
});
|
|
655
|
-
}
|
|
445
|
+
}
|
|
656
446
|
/**
|
|
657
447
|
* Build worker command for container execution
|
|
658
448
|
*/
|
|
659
|
-
|
|
449
|
+
buildWorkerCommand(options) {
|
|
660
450
|
// Use npx to run claude-flow daemon trigger
|
|
661
451
|
return [
|
|
662
452
|
'npx', 'claude-flow@v3alpha',
|
|
@@ -664,188 +454,130 @@ var ContainerWorkerPool = /** @class */ (function (_super) {
|
|
|
664
454
|
'-w', options.workerType,
|
|
665
455
|
'--headless',
|
|
666
456
|
];
|
|
667
|
-
}
|
|
457
|
+
}
|
|
668
458
|
/**
|
|
669
459
|
* Process queued tasks
|
|
670
460
|
*/
|
|
671
|
-
|
|
461
|
+
processQueue() {
|
|
672
462
|
while (this.taskQueue.length > 0) {
|
|
673
|
-
|
|
463
|
+
const container = this.getReadyContainer();
|
|
674
464
|
if (!container)
|
|
675
465
|
break;
|
|
676
|
-
|
|
466
|
+
const task = this.taskQueue.shift();
|
|
677
467
|
if (task) {
|
|
678
468
|
this.executeInContainer(container, task.options)
|
|
679
|
-
.then(task.resolve)
|
|
469
|
+
.then(task.resolve)
|
|
470
|
+
.catch(task.reject);
|
|
680
471
|
}
|
|
681
472
|
}
|
|
682
|
-
}
|
|
473
|
+
}
|
|
683
474
|
// ============================================
|
|
684
475
|
// Private Methods - Health & Maintenance
|
|
685
476
|
// ============================================
|
|
686
477
|
/**
|
|
687
478
|
* Start health check timer
|
|
688
479
|
*/
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
switch (_a.label) {
|
|
694
|
-
case 0: return [4 /*yield*/, this.runHealthChecks()];
|
|
695
|
-
case 1:
|
|
696
|
-
_a.sent();
|
|
697
|
-
return [2 /*return*/];
|
|
698
|
-
}
|
|
699
|
-
});
|
|
700
|
-
}); }, this.config.healthCheckIntervalMs);
|
|
480
|
+
startHealthChecks() {
|
|
481
|
+
this.healthCheckTimer = setInterval(async () => {
|
|
482
|
+
await this.runHealthChecks();
|
|
483
|
+
}, this.config.healthCheckIntervalMs);
|
|
701
484
|
this.healthCheckTimer.unref();
|
|
702
|
-
}
|
|
485
|
+
}
|
|
703
486
|
/**
|
|
704
487
|
* Run health checks on all containers
|
|
705
488
|
*/
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
if (container.state === 'terminated')
|
|
718
|
-
return [3 /*break*/, 10];
|
|
719
|
-
_d.label = 2;
|
|
720
|
-
case 2:
|
|
721
|
-
_d.trys.push([2, 9, , 10]);
|
|
722
|
-
return [4 /*yield*/, execAsync("docker inspect -f '{{.State.Running}}' " + container.name, { timeout: 10000 })];
|
|
723
|
-
case 3:
|
|
724
|
-
stdout = (_d.sent()).stdout;
|
|
725
|
-
output = stdout.trim();
|
|
726
|
-
if (!(output !== 'true')) return [3 /*break*/, 7];
|
|
727
|
-
container.healthCheckFailures++;
|
|
728
|
-
if (!(container.healthCheckFailures >= 3)) return [3 /*break*/, 6];
|
|
489
|
+
async runHealthChecks() {
|
|
490
|
+
for (const [id, container] of this.containers) {
|
|
491
|
+
if (container.state === 'terminated')
|
|
492
|
+
continue;
|
|
493
|
+
try {
|
|
494
|
+
// Check if container is running (async)
|
|
495
|
+
const { stdout } = await execAsync(`docker inspect -f '{{.State.Running}}' ${container.name}`, { timeout: 10000 });
|
|
496
|
+
const output = stdout.trim();
|
|
497
|
+
if (output !== 'true') {
|
|
498
|
+
container.healthCheckFailures++;
|
|
499
|
+
if (container.healthCheckFailures >= 3) {
|
|
729
500
|
container.state = 'unhealthy';
|
|
730
|
-
this.emit('containerUnhealthy', { id
|
|
731
|
-
// Remove and replace
|
|
732
|
-
return [4 /*yield*/, this.terminateContainer(id)];
|
|
733
|
-
case 4:
|
|
501
|
+
this.emit('containerUnhealthy', { id, name: container.name });
|
|
734
502
|
// Remove and replace
|
|
735
|
-
|
|
736
|
-
if (
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
_d.label = 6;
|
|
741
|
-
case 6: return [3 /*break*/, 8];
|
|
742
|
-
case 7:
|
|
743
|
-
container.healthCheckFailures = 0;
|
|
744
|
-
_d.label = 8;
|
|
745
|
-
case 8: return [3 /*break*/, 10];
|
|
746
|
-
case 9:
|
|
747
|
-
_c = _d.sent();
|
|
748
|
-
container.healthCheckFailures++;
|
|
749
|
-
return [3 /*break*/, 10];
|
|
750
|
-
case 10:
|
|
751
|
-
_i++;
|
|
752
|
-
return [3 /*break*/, 1];
|
|
753
|
-
case 11:
|
|
754
|
-
this.emit('healthCheckComplete', { containers: this.containers.size });
|
|
755
|
-
return [2 /*return*/];
|
|
503
|
+
await this.terminateContainer(id);
|
|
504
|
+
if (this.containers.size < this.config.minContainers) {
|
|
505
|
+
await this.createContainer();
|
|
506
|
+
}
|
|
507
|
+
}
|
|
756
508
|
}
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
509
|
+
else {
|
|
510
|
+
container.healthCheckFailures = 0;
|
|
511
|
+
}
|
|
512
|
+
}
|
|
513
|
+
catch {
|
|
514
|
+
container.healthCheckFailures++;
|
|
515
|
+
}
|
|
516
|
+
}
|
|
517
|
+
this.emit('healthCheckComplete', { containers: this.containers.size });
|
|
518
|
+
}
|
|
760
519
|
/**
|
|
761
520
|
* Start idle check timer
|
|
762
521
|
*/
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
switch (_a.label) {
|
|
768
|
-
case 0: return [4 /*yield*/, this.runIdleChecks()];
|
|
769
|
-
case 1:
|
|
770
|
-
_a.sent();
|
|
771
|
-
return [2 /*return*/];
|
|
772
|
-
}
|
|
773
|
-
});
|
|
774
|
-
}); }, 60000); // Check every minute
|
|
522
|
+
startIdleChecks() {
|
|
523
|
+
this.idleCheckTimer = setInterval(async () => {
|
|
524
|
+
await this.runIdleChecks();
|
|
525
|
+
}, 60000); // Check every minute
|
|
775
526
|
this.idleCheckTimer.unref();
|
|
776
|
-
}
|
|
527
|
+
}
|
|
777
528
|
/**
|
|
778
529
|
* Terminate idle containers above minimum
|
|
779
530
|
*/
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
if (!(_i < toTerminate_1.length)) return [3 /*break*/, 4];
|
|
796
|
-
container = toTerminate_1[_i];
|
|
797
|
-
lastUsed = ((_a = container.lastUsedAt) === null || _a === void 0 ? void 0 : _a.getTime()) || container.createdAt.getTime();
|
|
798
|
-
if (!(now - lastUsed > this.config.idleTimeoutMs)) return [3 /*break*/, 3];
|
|
799
|
-
return [4 /*yield*/, this.terminateContainer(container.id)];
|
|
800
|
-
case 2:
|
|
801
|
-
_b.sent();
|
|
802
|
-
this.emit('containerIdleTerminated', { id: container.id, name: container.name });
|
|
803
|
-
_b.label = 3;
|
|
804
|
-
case 3:
|
|
805
|
-
_i++;
|
|
806
|
-
return [3 /*break*/, 1];
|
|
807
|
-
case 4: return [2 /*return*/];
|
|
808
|
-
}
|
|
809
|
-
});
|
|
810
|
-
});
|
|
811
|
-
};
|
|
531
|
+
async runIdleChecks() {
|
|
532
|
+
const now = Date.now();
|
|
533
|
+
const readyContainers = Array.from(this.containers.values())
|
|
534
|
+
.filter(c => c.state === 'ready')
|
|
535
|
+
.sort((a, b) => (a.lastUsedAt?.getTime() || 0) - (b.lastUsedAt?.getTime() || 0));
|
|
536
|
+
// Keep minimum containers
|
|
537
|
+
const toTerminate = readyContainers.slice(this.config.minContainers);
|
|
538
|
+
for (const container of toTerminate) {
|
|
539
|
+
const lastUsed = container.lastUsedAt?.getTime() || container.createdAt.getTime();
|
|
540
|
+
if (now - lastUsed > this.config.idleTimeoutMs) {
|
|
541
|
+
await this.terminateContainer(container.id);
|
|
542
|
+
this.emit('containerIdleTerminated', { id: container.id, name: container.name });
|
|
543
|
+
}
|
|
544
|
+
}
|
|
545
|
+
}
|
|
812
546
|
// ============================================
|
|
813
547
|
// Private Methods - Utilities
|
|
814
548
|
// ============================================
|
|
815
549
|
/**
|
|
816
550
|
* Try to parse JSON from output
|
|
817
551
|
*/
|
|
818
|
-
|
|
552
|
+
tryParseJson(output) {
|
|
819
553
|
try {
|
|
820
|
-
|
|
554
|
+
const jsonMatch = output.match(/\{[\s\S]*\}/);
|
|
821
555
|
if (jsonMatch) {
|
|
822
556
|
return JSON.parse(jsonMatch[0]);
|
|
823
557
|
}
|
|
824
558
|
return JSON.parse(output.trim());
|
|
825
559
|
}
|
|
826
|
-
catch
|
|
560
|
+
catch {
|
|
827
561
|
return undefined;
|
|
828
562
|
}
|
|
829
|
-
}
|
|
563
|
+
}
|
|
830
564
|
/**
|
|
831
565
|
* Create an error result
|
|
832
566
|
*/
|
|
833
|
-
|
|
567
|
+
createErrorResult(workerType, error) {
|
|
834
568
|
return {
|
|
835
569
|
success: false,
|
|
836
570
|
output: '',
|
|
837
571
|
durationMs: 0,
|
|
838
572
|
model: 'unknown',
|
|
839
573
|
sandboxMode: this.config.defaultSandbox,
|
|
840
|
-
workerType
|
|
574
|
+
workerType,
|
|
841
575
|
timestamp: new Date(),
|
|
842
|
-
executionId:
|
|
843
|
-
error
|
|
576
|
+
executionId: `error_${Date.now()}`,
|
|
577
|
+
error,
|
|
844
578
|
};
|
|
845
|
-
}
|
|
846
|
-
|
|
847
|
-
}(EventEmitter));
|
|
848
|
-
export { ContainerWorkerPool };
|
|
579
|
+
}
|
|
580
|
+
}
|
|
849
581
|
// Export default
|
|
850
582
|
export default ContainerWorkerPool;
|
|
851
583
|
//# sourceMappingURL=container-worker-pool.js.map
|