claude-flow-novice 1.6.3 → 1.6.5
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/commands/parse-epic.js +180 -0
- package/.claude/settings.json +12 -2
- package/.claude/settings.local.json +4 -2
- package/.claude-flow-novice/dist/mcp/mcp-server-novice.js +37 -2
- package/.claude-flow-novice/dist/mcp/transports/base.js +5 -0
- package/.claude-flow-novice/dist/mcp/transports/base.js.map +1 -0
- package/.claude-flow-novice/dist/mcp/transports/http.js +414 -0
- package/.claude-flow-novice/dist/mcp/transports/http.js.map +1 -0
- package/.claude-flow-novice/dist/mcp/transports/stdio.js +217 -0
- package/.claude-flow-novice/dist/mcp/transports/stdio.js.map +1 -0
- package/.claude-flow-novice/dist/src/cli/commands/parse-epic.js +129 -0
- package/.claude-flow-novice/dist/src/cli/commands/parse-epic.js.map +1 -0
- package/.claude-flow-novice/dist/src/cli/index.js +3 -0
- package/.claude-flow-novice/dist/src/cli/index.js.map +1 -1
- package/.claude-flow-novice/dist/src/cli/utils/epic-parser.js +266 -0
- package/.claude-flow-novice/dist/src/cli/utils/epic-parser.js.map +1 -0
- package/.claude-flow-novice/dist/src/communication/message-bus.js +105 -2
- package/.claude-flow-novice/dist/src/communication/message-bus.js.map +1 -1
- package/.claude-flow-novice/dist/src/coordination/adapters/v1-coordinator-adapter.js +1 -1
- package/.claude-flow-novice/dist/src/coordination/adapters/v1-coordinator-adapter.js.map +1 -1
- package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/cache/artifact-cache-optimizer.js +632 -0
- package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/cache/artifact-cache-optimizer.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/cache/index.js +11 -0
- package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/cache/index.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/checkpoints/checkpoint-compressor.js +318 -0
- package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/checkpoints/checkpoint-compressor.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/completion/completion-detector.js +234 -0
- package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/completion/completion-detector.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/completion/hierarchical-detector.js +347 -0
- package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/completion/hierarchical-detector.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/completion/index.js +13 -0
- package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/completion/index.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/completion/lamport-clock.js +173 -0
- package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/completion/lamport-clock.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/completion/mesh-detector.js +526 -0
- package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/completion/mesh-detector.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/completion/sdk-completion-detector.js +443 -0
- package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/completion/sdk-completion-detector.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/completion/swarm-shutdown.js +366 -0
- package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/completion/swarm-shutdown.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/coordinator-factory.js +287 -0
- package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/coordinator-factory.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/coordinators/cascading-shutdown.example.js +364 -0
- package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/coordinators/cascading-shutdown.example.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/coordinators/cascading-shutdown.js +492 -0
- package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/coordinators/cascading-shutdown.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/coordinators/hierarchical-coordinator.js +786 -0
- package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/coordinators/hierarchical-coordinator.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/coordinators/index.js +16 -0
- package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/coordinators/index.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/coordinators/parent-child-manager.js +342 -0
- package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/coordinators/parent-child-manager.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/coordinators/swarm-coordinator-v2.js +601 -0
- package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/coordinators/swarm-coordinator-v2.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/core/agent-state.js +9 -0
- package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/core/agent-state.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/core/dead-letter-queue.js +413 -0
- package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/core/dead-letter-queue.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/core/dependency-graph.js +471 -0
- package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/core/dependency-graph.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/core/dependency-node.js +379 -0
- package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/core/dependency-node.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/core/dependency-resolver.js +335 -0
- package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/core/dependency-resolver.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/core/help-request-metrics.js +211 -0
- package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/core/help-request-metrics.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/core/index.js +33 -0
- package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/core/index.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/core/message-broker.js +920 -0
- package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/core/message-broker.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/core/message-router.js +385 -0
- package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/core/message-router.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/core/message.js +138 -0
- package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/core/message.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/core/resource-manager-safe.js +478 -0
- package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/core/resource-manager-safe.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/core/state-machine-config.js +358 -0
- package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/core/state-machine-config.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/core/state-machine.js +588 -0
- package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/core/state-machine.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/core/state-transition.js +153 -0
- package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/core/state-transition.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/core/task-scheduler.js +360 -0
- package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/core/task-scheduler.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/core/topic-manager.js +337 -0
- package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/core/topic-manager.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/deadlock/deadlock-detector.js +424 -0
- package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/deadlock/deadlock-detector.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/deadlock/index.js +9 -0
- package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/deadlock/index.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/deadlock/resource-manager.js +669 -0
- package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/deadlock/resource-manager.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/dependency/artifact-storage.js +451 -0
- package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/dependency/artifact-storage.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/dependency/cycle-detector.js +271 -0
- package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/dependency/cycle-detector.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/dependency/dependency-graph.js +335 -0
- package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/dependency/dependency-graph.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/dependency/dependency-manager.js +439 -0
- package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/dependency/dependency-manager.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/dependency/dependency-request.js +92 -0
- package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/dependency/dependency-request.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/dependency/index.js +21 -0
- package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/dependency/index.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/dependency/topological-sort.js +223 -0
- package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/dependency/topological-sort.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/help-system/help-coordinator.js +436 -0
- package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/help-system/help-coordinator.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/help-system/help-matcher.js +278 -0
- package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/help-system/help-matcher.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/help-system/help-request-handler.js +317 -0
- package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/help-system/help-request-handler.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/help-system/help-request.js +273 -0
- package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/help-system/help-request.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/help-system/index.js +15 -0
- package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/help-system/index.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/help-system/waiting-agent-pool.js +512 -0
- package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/help-system/waiting-agent-pool.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/index.js +67 -0
- package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/index.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/integration/help-deadlock-integration.js +557 -0
- package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/integration/help-deadlock-integration.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/integration/index.js +14 -0
- package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/integration/index.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/integration/message-bus-completion-integration.example.js +212 -0
- package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/integration/message-bus-completion-integration.example.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/integration/message-bus-completion-integration.js +552 -0
- package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/integration/message-bus-completion-integration.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/integration/state-machine-integration.js +635 -0
- package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/integration/state-machine-integration.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/interfaces/IArtifactStorage.js +28 -0
- package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/interfaces/IArtifactStorage.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/interfaces/ICoordinator.js +9 -0
- package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/interfaces/ICoordinator.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/interfaces/ISessionStore.js +25 -0
- package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/interfaces/ISessionStore.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/interfaces/index.js +14 -0
- package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/interfaces/index.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/memory/artifact-adapter.js +308 -0
- package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/memory/artifact-adapter.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/memory/completion-storage.js +439 -0
- package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/memory/completion-storage.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/memory/dependency-graph-storage.js +540 -0
- package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/memory/dependency-graph-storage.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/memory/dependency-storage.js +367 -0
- package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/memory/dependency-storage.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/memory/index.js +14 -0
- package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/memory/index.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/memory/message-storage.js +518 -0
- package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/memory/message-storage.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/memory/state-storage.js +377 -0
- package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/memory/state-storage.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/messaging/channel.js +371 -0
- package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/messaging/channel.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/messaging/channels/dependency-channel.js +355 -0
- package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/messaging/channels/dependency-channel.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/messaging/channels/help-channel.js +424 -0
- package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/messaging/channels/help-channel.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/messaging/channels/index.js +16 -0
- package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/messaging/channels/index.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/messaging/channels/state-channel.js +295 -0
- package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/messaging/channels/state-channel.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/messaging/channels/task-channel.js +411 -0
- package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/messaging/channels/task-channel.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/messaging/index.js +14 -0
- package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/messaging/index.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/messaging/message-bus.js +387 -0
- package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/messaging/message-bus.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/messaging/message-persistence.js +589 -0
- package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/messaging/message-persistence.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/messaging/message-router.js +444 -0
- package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/messaging/message-router.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/sdk/artifact-storage.js +560 -0
- package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/sdk/artifact-storage.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/sdk/background-orchestrator.js +335 -0
- package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/sdk/background-orchestrator.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/sdk/bash-output-monitor.js +104 -0
- package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/sdk/bash-output-monitor.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/sdk/checkpoint-manager.js +847 -0
- package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/sdk/checkpoint-manager.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/sdk/help-coordinator.js +470 -0
- package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/sdk/help-coordinator.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/sdk/hierarchical-background-integration.js +450 -0
- package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/sdk/hierarchical-background-integration.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/sdk/index.js +13 -0
- package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/sdk/index.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/sdk/message-bus-integration.js +625 -0
- package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/sdk/message-bus-integration.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/sdk/multi-level-control.js +545 -0
- package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/sdk/multi-level-control.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/sdk/query-controller.js +740 -0
- package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/sdk/query-controller.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/sdk/query-message-integration.js +415 -0
- package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/sdk/query-message-integration.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/sdk/session-pool-optimizer.js +615 -0
- package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/sdk/session-pool-optimizer.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/sdk/state-machine-integration.js +547 -0
- package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/sdk/state-machine-integration.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/sdk/state-sdk-integration.js +342 -0
- package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/sdk/state-sdk-integration.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/security/payload-validator.js +259 -0
- package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/security/payload-validator.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/truth/framework-registry.js +273 -0
- package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/truth/framework-registry.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/truth/index.js +8 -0
- package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/truth/index.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/truth/truth-config-manager.js +310 -0
- package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/truth/truth-config-manager.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/truth/truth-validator.js +218 -0
- package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/truth/truth-validator.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/types/sdk.js +9 -0
- package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/types/sdk.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/utils/index.js +6 -0
- package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/utils/index.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/utils/priority-queue.js +145 -0
- package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/utils/priority-queue.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/utils/sdk-helpers.js +122 -0
- package/.claude-flow-novice/dist/src/coordination/archives/v2-sdk-typescript/v2/utils/sdk-helpers.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/config-translator.js +17 -43
- package/.claude-flow-novice/dist/src/coordination/config-translator.js.map +1 -1
- package/.claude-flow-novice/dist/src/coordination/coordination-toggle.js +34 -76
- package/.claude-flow-novice/dist/src/coordination/coordination-toggle.js.map +1 -1
- package/.claude-flow-novice/dist/src/coordination/index.js +3 -0
- package/.claude-flow-novice/dist/src/coordination/index.js.map +1 -1
- package/.claude-flow-novice/dist/src/coordination/shared/core/agent-state.js +172 -0
- package/.claude-flow-novice/dist/src/coordination/shared/core/agent-state.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/shared/core/index.js +7 -0
- package/.claude-flow-novice/dist/src/coordination/shared/core/index.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/shared/index.js +19 -0
- package/.claude-flow-novice/dist/src/coordination/shared/index.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/shared/interfaces/ICoordinator.js +24 -0
- package/.claude-flow-novice/dist/src/coordination/shared/interfaces/ICoordinator.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/shared/interfaces/index.js +7 -0
- package/.claude-flow-novice/dist/src/coordination/shared/interfaces/index.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/shared/message-broker.js +920 -0
- package/.claude-flow-novice/dist/src/coordination/shared/message-broker.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/shared/message.js +138 -0
- package/.claude-flow-novice/dist/src/coordination/shared/message.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/shared/security/payload-validator.js +259 -0
- package/.claude-flow-novice/dist/src/coordination/shared/security/payload-validator.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/shared/transparency/index.js +17 -0
- package/.claude-flow-novice/dist/src/coordination/shared/transparency/index.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/shared/transparency/interfaces/transparency-system.js +19 -0
- package/.claude-flow-novice/dist/src/coordination/shared/transparency/interfaces/transparency-system.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/shared/transparency/transparency-integration.js +357 -0
- package/.claude-flow-novice/dist/src/coordination/shared/transparency/transparency-integration.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/shared/transparency/transparency-system.js +679 -0
- package/.claude-flow-novice/dist/src/coordination/shared/transparency/transparency-system.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/shared/types/index.js +7 -0
- package/.claude-flow-novice/dist/src/coordination/shared/types/index.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/shared/types/sdk.js +10 -0
- package/.claude-flow-novice/dist/src/coordination/shared/types/sdk.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/v1-transparency/interfaces/v1-transparency-system.js +12 -0
- package/.claude-flow-novice/dist/src/coordination/v1-transparency/interfaces/v1-transparency-system.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/v1-transparency/v1-to-v2-bridge.js +433 -0
- package/.claude-flow-novice/dist/src/coordination/v1-transparency/v1-to-v2-bridge.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/v1-transparency/v1-transparency-adapter.js +1468 -0
- package/.claude-flow-novice/dist/src/coordination/v1-transparency/v1-transparency-adapter.js.map +1 -0
- package/.claude-flow-novice/dist/src/feature-flags/core/FeatureFlagManager.js +52 -2
- package/.claude-flow-novice/dist/src/feature-flags/core/FeatureFlagManager.js.map +1 -1
- package/.claude-flow-novice/dist/src/mcp/mcp-server-novice.js +37 -2
- package/.claude-flow-novice/dist/src/mcp/session-manager.js +3 -1
- package/.claude-flow-novice/dist/src/mcp/session-manager.js.map +1 -1
- package/.claude-flow-novice/dist/src/monitoring/apm/apm-integration.js +5 -0
- package/.claude-flow-novice/dist/src/monitoring/apm/apm-integration.js.map +1 -1
- package/.claude-flow-novice/dist/src/providers/provider-manager.js +41 -6
- package/.claude-flow-novice/dist/src/providers/provider-manager.js.map +1 -1
- package/.claude-flow-novice/dist/src/providers/tiered-router.js +9 -17
- package/.claude-flow-novice/dist/src/providers/tiered-router.js.map +1 -1
- package/.claude-flow-novice/dist/src/utils/markdown-sanitizer.js +65 -41
- package/.claude-flow-novice/dist/src/utils/markdown-sanitizer.js.map +1 -1
- package/.claude-flow-novice/dist/src/web/api/server.js +1 -1
- package/.claude-flow-novice/dist/src/web/api/server.js.map +1 -1
- package/.claude-flow-novice/dist/src/workflows/progressive-rollout-manager.js +30 -0
- package/.claude-flow-novice/dist/src/workflows/progressive-rollout-manager.js.map +1 -1
- package/.claude-flow-novice/metrics.db +0 -0
- package/.claude-flow-novice/metrics.db-shm +0 -0
- package/.claude-flow-novice/metrics.db-wal +0 -0
- package/CLAUDE.md +72 -0
- package/config/hooks/post-edit-pipeline.js +68 -118
- package/config/hooks/pre-tool-memory-safety.js +209 -0
- package/package.json +7 -4
- package/scripts/cleanup-idle-sessions.sh +59 -0
- package/scripts/monitoring/alert-monitor.sh +220 -0
- package/scripts/monitoring/view-alerts.sh +307 -0
- package/scripts/test-provider-routing.cjs +7 -9
- package/scripts/test-zai-api.cjs +2 -2
- package/src/slash-commands/parse-epic.js +1 -1
- package/wiki/Provider-Routing.md +57 -69
- package/MEMORY_LEAK_ROOT_CAUSE.md +0 -149
|
@@ -0,0 +1,366 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Agent Coordination V2 - Swarm Shutdown Manager
|
|
3
|
+
*
|
|
4
|
+
* Graceful shutdown coordinator with cascading termination and checkpoint creation.
|
|
5
|
+
* Performance targets:
|
|
6
|
+
* - Shutdown latency: <500ms for swarms with 20 agents
|
|
7
|
+
* - Checkpoint creation: <50ms per agent
|
|
8
|
+
* - Background process cleanup: 100% coverage
|
|
9
|
+
*
|
|
10
|
+
* Features:
|
|
11
|
+
* - Pause all agents before shutdown (prevent token waste)
|
|
12
|
+
* - Create final completion checkpoint
|
|
13
|
+
* - Cascade shutdown (root → leaves DFS traversal)
|
|
14
|
+
* - Clean up background processes
|
|
15
|
+
* - Close SDK sessions gracefully
|
|
16
|
+
* - Emergency shutdown for critical errors
|
|
17
|
+
*
|
|
18
|
+
* @module coordination/v2/completion/swarm-shutdown
|
|
19
|
+
*/ import { EventEmitter } from 'events';
|
|
20
|
+
/**
|
|
21
|
+
* SwarmShutdown - Graceful swarm shutdown coordinator
|
|
22
|
+
*
|
|
23
|
+
* Manages orderly shutdown of multi-agent swarms with the following sequence:
|
|
24
|
+
* 1. Pause all active agents (zero token cost)
|
|
25
|
+
* 2. Create final completion checkpoint (optional)
|
|
26
|
+
* 3. Cascade shutdown from root to leaves (DFS)
|
|
27
|
+
* 4. Clean up background processes
|
|
28
|
+
* 5. Close SDK sessions
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* ```typescript
|
|
32
|
+
* const shutdown = new SwarmShutdown(queryController, backgroundOrchestrator, {
|
|
33
|
+
* maxShutdownTimeMs: 10000,
|
|
34
|
+
* createFinalCheckpoint: true,
|
|
35
|
+
* cascadeShutdown: true
|
|
36
|
+
* });
|
|
37
|
+
*
|
|
38
|
+
* // Graceful shutdown
|
|
39
|
+
* const result = await shutdown.shutdownSwarm(['agent-1', 'agent-2', 'agent-3']);
|
|
40
|
+
*
|
|
41
|
+
* // Emergency shutdown (no checkpoints, immediate)
|
|
42
|
+
* await shutdown.emergencyShutdown('Critical error detected');
|
|
43
|
+
* ```
|
|
44
|
+
*/ export class SwarmShutdown extends EventEmitter {
|
|
45
|
+
queryController;
|
|
46
|
+
backgroundOrchestrator;
|
|
47
|
+
config;
|
|
48
|
+
shutdownInProgress = false;
|
|
49
|
+
shutdownStartTime = 0;
|
|
50
|
+
constructor(queryController, backgroundOrchestrator, config){
|
|
51
|
+
super();
|
|
52
|
+
this.queryController = queryController;
|
|
53
|
+
this.backgroundOrchestrator = backgroundOrchestrator;
|
|
54
|
+
this.config = {
|
|
55
|
+
maxShutdownTimeMs: 10000,
|
|
56
|
+
createFinalCheckpoint: true,
|
|
57
|
+
cascadeShutdown: true,
|
|
58
|
+
agentGracePeriodMs: 500,
|
|
59
|
+
cleanupBackgroundProcesses: true,
|
|
60
|
+
perAgentTimeoutMs: 1000,
|
|
61
|
+
...config
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Graceful shutdown of entire swarm
|
|
66
|
+
*
|
|
67
|
+
* Performance target: <500ms for 20 agents
|
|
68
|
+
*
|
|
69
|
+
* @param agentIds - Array of agent IDs to shutdown
|
|
70
|
+
* @param reason - Shutdown reason for logging
|
|
71
|
+
* @returns Promise resolving to SwarmShutdownResult
|
|
72
|
+
*/ async shutdownSwarm(agentIds, reason = 'Graceful swarm shutdown') {
|
|
73
|
+
if (this.shutdownInProgress) {
|
|
74
|
+
throw new Error('Shutdown already in progress');
|
|
75
|
+
}
|
|
76
|
+
this.shutdownInProgress = true;
|
|
77
|
+
this.shutdownStartTime = Date.now();
|
|
78
|
+
const shutdownResult = {
|
|
79
|
+
success: true,
|
|
80
|
+
totalAgents: agentIds.length,
|
|
81
|
+
successfulShutdowns: 0,
|
|
82
|
+
failedShutdowns: 0,
|
|
83
|
+
totalLatencyMs: 0,
|
|
84
|
+
agentResults: [],
|
|
85
|
+
backgroundProcessesCleaned: 0,
|
|
86
|
+
shutdownAt: new Date()
|
|
87
|
+
};
|
|
88
|
+
this.emit('shutdown:started', {
|
|
89
|
+
agentCount: agentIds.length,
|
|
90
|
+
reason,
|
|
91
|
+
config: this.config
|
|
92
|
+
});
|
|
93
|
+
try {
|
|
94
|
+
// Step 1: Pause all active agents (prevents token waste)
|
|
95
|
+
await this.pauseAllAgents(agentIds, reason);
|
|
96
|
+
// Step 2: Shutdown agents in cascade order (root → leaves DFS)
|
|
97
|
+
if (this.config.cascadeShutdown && this.backgroundOrchestrator) {
|
|
98
|
+
shutdownResult.agentResults = await this.cascadeShutdown(agentIds, reason);
|
|
99
|
+
} else {
|
|
100
|
+
shutdownResult.agentResults = await this.parallelShutdown(agentIds, reason);
|
|
101
|
+
}
|
|
102
|
+
// Calculate metrics
|
|
103
|
+
shutdownResult.successfulShutdowns = shutdownResult.agentResults.filter((r)=>r.success).length;
|
|
104
|
+
shutdownResult.failedShutdowns = shutdownResult.agentResults.filter((r)=>!r.success).length;
|
|
105
|
+
shutdownResult.backgroundProcessesCleaned = shutdownResult.agentResults.reduce((sum, r)=>sum + r.backgroundProcessesTerminated, 0);
|
|
106
|
+
shutdownResult.success = shutdownResult.failedShutdowns === 0;
|
|
107
|
+
shutdownResult.totalLatencyMs = Date.now() - this.shutdownStartTime;
|
|
108
|
+
// Performance warning if exceeds target
|
|
109
|
+
if (shutdownResult.totalLatencyMs > 500 && agentIds.length <= 20) {
|
|
110
|
+
console.warn(`[SwarmShutdown] Shutdown latency ${shutdownResult.totalLatencyMs}ms exceeds 500ms target for ${agentIds.length} agents`);
|
|
111
|
+
}
|
|
112
|
+
this.emit('shutdown:completed', shutdownResult);
|
|
113
|
+
return shutdownResult;
|
|
114
|
+
} catch (error) {
|
|
115
|
+
shutdownResult.success = false;
|
|
116
|
+
shutdownResult.totalLatencyMs = Date.now() - this.shutdownStartTime;
|
|
117
|
+
this.emit('shutdown:failed', {
|
|
118
|
+
error: error instanceof Error ? error.message : String(error),
|
|
119
|
+
result: shutdownResult
|
|
120
|
+
});
|
|
121
|
+
throw error;
|
|
122
|
+
} finally{
|
|
123
|
+
this.shutdownInProgress = false;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Emergency shutdown - immediate termination without checkpoints
|
|
128
|
+
*
|
|
129
|
+
* Used for critical errors or forced shutdown.
|
|
130
|
+
*
|
|
131
|
+
* @param reason - Emergency shutdown reason
|
|
132
|
+
* @returns Promise resolving when shutdown complete
|
|
133
|
+
*/ async emergencyShutdown(reason) {
|
|
134
|
+
this.emit('shutdown:emergency', {
|
|
135
|
+
reason
|
|
136
|
+
});
|
|
137
|
+
const activeAgents = this.queryController.getActiveAgents();
|
|
138
|
+
const agentIds = activeAgents.map((a)=>a.agentId);
|
|
139
|
+
// Force shutdown without checkpoints
|
|
140
|
+
const originalCheckpointConfig = this.config.createFinalCheckpoint;
|
|
141
|
+
this.config.createFinalCheckpoint = false;
|
|
142
|
+
try {
|
|
143
|
+
await this.shutdownSwarm(agentIds, `EMERGENCY: ${reason}`);
|
|
144
|
+
} finally{
|
|
145
|
+
this.config.createFinalCheckpoint = originalCheckpointConfig;
|
|
146
|
+
}
|
|
147
|
+
// Cleanup all resources
|
|
148
|
+
await this.queryController.cleanup();
|
|
149
|
+
if (this.backgroundOrchestrator) {
|
|
150
|
+
await this.backgroundOrchestrator.cleanup();
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Pause all agents before shutdown (prevent token waste)
|
|
155
|
+
*
|
|
156
|
+
* @param agentIds - Agent IDs to pause
|
|
157
|
+
* @param reason - Pause reason
|
|
158
|
+
*/ async pauseAllAgents(agentIds, reason) {
|
|
159
|
+
const pauseStartTime = Date.now();
|
|
160
|
+
const pausePromises = agentIds.map(async (agentId)=>{
|
|
161
|
+
try {
|
|
162
|
+
const agent = this.queryController.getActiveAgents().find((a)=>a.agentId === agentId);
|
|
163
|
+
if (agent && !agent.isPaused) {
|
|
164
|
+
await this.queryController.pauseAgent(agentId, `Pre-shutdown pause: ${reason}`);
|
|
165
|
+
}
|
|
166
|
+
} catch (error) {
|
|
167
|
+
// Ignore pause errors - agent may already be paused or terminated
|
|
168
|
+
console.debug(`[SwarmShutdown] Failed to pause agent ${agentId}:`, error);
|
|
169
|
+
}
|
|
170
|
+
});
|
|
171
|
+
await Promise.all(pausePromises);
|
|
172
|
+
const pauseLatency = Date.now() - pauseStartTime;
|
|
173
|
+
this.emit('shutdown:agents-paused', {
|
|
174
|
+
agentCount: agentIds.length,
|
|
175
|
+
latencyMs: pauseLatency
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Cascade shutdown (root → leaves DFS traversal)
|
|
180
|
+
*
|
|
181
|
+
* Shuts down agents in dependency order to prevent orphaned processes.
|
|
182
|
+
*
|
|
183
|
+
* @param agentIds - Agent IDs to shutdown
|
|
184
|
+
* @param reason - Shutdown reason
|
|
185
|
+
* @returns Array of AgentShutdownResult
|
|
186
|
+
*/ async cascadeShutdown(agentIds, reason) {
|
|
187
|
+
const results = [];
|
|
188
|
+
// Build agent hierarchy from background orchestrator
|
|
189
|
+
const agentHierarchy = this.buildAgentHierarchy(agentIds);
|
|
190
|
+
// Shutdown in reverse order (deepest first - DFS)
|
|
191
|
+
const shutdownOrder = this.getShutdownOrder(agentHierarchy);
|
|
192
|
+
for (const agentId of shutdownOrder){
|
|
193
|
+
const result = await this.shutdownSingleAgent(agentId, reason);
|
|
194
|
+
results.push(result);
|
|
195
|
+
// Check if we've exceeded max shutdown time
|
|
196
|
+
if (Date.now() - this.shutdownStartTime > this.config.maxShutdownTimeMs) {
|
|
197
|
+
console.warn(`[SwarmShutdown] Max shutdown time ${this.config.maxShutdownTimeMs}ms exceeded, forcing remaining terminations`);
|
|
198
|
+
// Force shutdown remaining agents
|
|
199
|
+
const remaining = agentIds.filter((id)=>!results.some((r)=>r.agentId === id));
|
|
200
|
+
for (const remainingId of remaining){
|
|
201
|
+
results.push(await this.forceTerminateAgent(remainingId));
|
|
202
|
+
}
|
|
203
|
+
break;
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
return results;
|
|
207
|
+
}
|
|
208
|
+
/**
|
|
209
|
+
* Parallel shutdown (no dependency ordering)
|
|
210
|
+
*
|
|
211
|
+
* @param agentIds - Agent IDs to shutdown
|
|
212
|
+
* @param reason - Shutdown reason
|
|
213
|
+
* @returns Array of AgentShutdownResult
|
|
214
|
+
*/ async parallelShutdown(agentIds, reason) {
|
|
215
|
+
const shutdownPromises = agentIds.map((agentId)=>this.shutdownSingleAgent(agentId, reason));
|
|
216
|
+
return Promise.all(shutdownPromises);
|
|
217
|
+
}
|
|
218
|
+
/**
|
|
219
|
+
* Shutdown single agent with checkpoint creation
|
|
220
|
+
*
|
|
221
|
+
* Performance target: <50ms per agent
|
|
222
|
+
*
|
|
223
|
+
* @param agentId - Agent to shutdown
|
|
224
|
+
* @param reason - Shutdown reason
|
|
225
|
+
* @returns AgentShutdownResult
|
|
226
|
+
*/ async shutdownSingleAgent(agentId, reason) {
|
|
227
|
+
const startTime = Date.now();
|
|
228
|
+
const result = {
|
|
229
|
+
agentId,
|
|
230
|
+
success: false,
|
|
231
|
+
latencyMs: 0,
|
|
232
|
+
backgroundProcessesTerminated: 0
|
|
233
|
+
};
|
|
234
|
+
try {
|
|
235
|
+
// Create final checkpoint if enabled
|
|
236
|
+
if (this.config.createFinalCheckpoint) {
|
|
237
|
+
const checkpoint = await this.queryController.createCheckpoint(agentId, reason, {
|
|
238
|
+
shutdownTimestamp: Date.now(),
|
|
239
|
+
shutdownReason: reason
|
|
240
|
+
});
|
|
241
|
+
result.checkpoint = checkpoint;
|
|
242
|
+
}
|
|
243
|
+
// Terminate background processes for this agent
|
|
244
|
+
if (this.config.cleanupBackgroundProcesses && this.backgroundOrchestrator) {
|
|
245
|
+
const processes = this.backgroundOrchestrator.getAllProcesses().filter((p)=>p.agentId === agentId);
|
|
246
|
+
for (const process of processes){
|
|
247
|
+
await this.backgroundOrchestrator.terminateProcess(process.id);
|
|
248
|
+
result.backgroundProcessesTerminated++;
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
// Terminate agent session
|
|
252
|
+
await this.queryController.terminateAgent(agentId, reason);
|
|
253
|
+
result.success = true;
|
|
254
|
+
result.latencyMs = Date.now() - startTime;
|
|
255
|
+
// Performance warning if exceeds target
|
|
256
|
+
if (result.latencyMs > 50) {
|
|
257
|
+
console.warn(`[SwarmShutdown] Agent shutdown ${result.latencyMs}ms exceeds 50ms target for agent ${agentId}`);
|
|
258
|
+
}
|
|
259
|
+
this.emit('shutdown:agent-complete', result);
|
|
260
|
+
} catch (error) {
|
|
261
|
+
result.success = false;
|
|
262
|
+
result.error = error instanceof Error ? error.message : String(error);
|
|
263
|
+
result.latencyMs = Date.now() - startTime;
|
|
264
|
+
this.emit('shutdown:agent-failed', result);
|
|
265
|
+
}
|
|
266
|
+
return result;
|
|
267
|
+
}
|
|
268
|
+
/**
|
|
269
|
+
* Force terminate agent without checkpoints (emergency)
|
|
270
|
+
*
|
|
271
|
+
* @param agentId - Agent to force terminate
|
|
272
|
+
* @returns AgentShutdownResult
|
|
273
|
+
*/ async forceTerminateAgent(agentId) {
|
|
274
|
+
const startTime = Date.now();
|
|
275
|
+
try {
|
|
276
|
+
await this.queryController.terminateAgent(agentId, 'Forced termination');
|
|
277
|
+
return {
|
|
278
|
+
agentId,
|
|
279
|
+
success: true,
|
|
280
|
+
latencyMs: Date.now() - startTime,
|
|
281
|
+
backgroundProcessesTerminated: 0
|
|
282
|
+
};
|
|
283
|
+
} catch (error) {
|
|
284
|
+
return {
|
|
285
|
+
agentId,
|
|
286
|
+
success: false,
|
|
287
|
+
latencyMs: Date.now() - startTime,
|
|
288
|
+
backgroundProcessesTerminated: 0,
|
|
289
|
+
error: error instanceof Error ? error.message : String(error)
|
|
290
|
+
};
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
/**
|
|
294
|
+
* Build agent hierarchy from background orchestrator
|
|
295
|
+
*
|
|
296
|
+
* @param agentIds - Agent IDs to organize
|
|
297
|
+
* @returns Map of parent → children relationships
|
|
298
|
+
*/ buildAgentHierarchy(agentIds) {
|
|
299
|
+
const hierarchy = new Map();
|
|
300
|
+
if (!this.backgroundOrchestrator) {
|
|
301
|
+
return hierarchy;
|
|
302
|
+
}
|
|
303
|
+
const processes = this.backgroundOrchestrator.getAllProcesses();
|
|
304
|
+
for (const agentId of agentIds){
|
|
305
|
+
const agentProcesses = processes.filter((p)=>p.agentId === agentId);
|
|
306
|
+
for (const process of agentProcesses){
|
|
307
|
+
const children = this.backgroundOrchestrator.getChildProcesses(process.id);
|
|
308
|
+
if (children.length > 0) {
|
|
309
|
+
const childAgentIds = children.map((c)=>c.agentId).filter((id)=>agentIds.includes(id));
|
|
310
|
+
if (childAgentIds.length > 0) {
|
|
311
|
+
hierarchy.set(agentId, childAgentIds);
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
return hierarchy;
|
|
317
|
+
}
|
|
318
|
+
/**
|
|
319
|
+
* Get shutdown order using DFS (deepest first)
|
|
320
|
+
*
|
|
321
|
+
* @param hierarchy - Agent hierarchy map
|
|
322
|
+
* @returns Array of agent IDs in shutdown order
|
|
323
|
+
*/ getShutdownOrder(hierarchy) {
|
|
324
|
+
const visited = new Set();
|
|
325
|
+
const order = [];
|
|
326
|
+
const dfs = (agentId)=>{
|
|
327
|
+
if (visited.has(agentId)) {
|
|
328
|
+
return;
|
|
329
|
+
}
|
|
330
|
+
visited.add(agentId);
|
|
331
|
+
const children = hierarchy.get(agentId) || [];
|
|
332
|
+
for (const child of children){
|
|
333
|
+
dfs(child);
|
|
334
|
+
}
|
|
335
|
+
order.push(agentId);
|
|
336
|
+
};
|
|
337
|
+
// Find root agents (no parents)
|
|
338
|
+
const allAgents = new Set([
|
|
339
|
+
...hierarchy.keys(),
|
|
340
|
+
...Array.from(hierarchy.values()).flat()
|
|
341
|
+
]);
|
|
342
|
+
const childrenArrays = Array.from(hierarchy.values());
|
|
343
|
+
const children = new Set(childrenArrays.flat());
|
|
344
|
+
const roots = Array.from(allAgents).filter((id)=>!children.has(id));
|
|
345
|
+
// DFS from each root
|
|
346
|
+
for (const root of roots){
|
|
347
|
+
dfs(root);
|
|
348
|
+
}
|
|
349
|
+
// Reverse for deepest-first order
|
|
350
|
+
return order.reverse();
|
|
351
|
+
}
|
|
352
|
+
/**
|
|
353
|
+
* Check if shutdown is in progress
|
|
354
|
+
*/ isShutdownInProgress() {
|
|
355
|
+
return this.shutdownInProgress;
|
|
356
|
+
}
|
|
357
|
+
/**
|
|
358
|
+
* Get shutdown configuration
|
|
359
|
+
*/ getConfig() {
|
|
360
|
+
return {
|
|
361
|
+
...this.config
|
|
362
|
+
};
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
//# sourceMappingURL=swarm-shutdown.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../../../../src/coordination/archives/v2-sdk-typescript/v2/completion/swarm-shutdown.ts"],"names":["EventEmitter","SwarmShutdown","queryController","backgroundOrchestrator","config","shutdownInProgress","shutdownStartTime","maxShutdownTimeMs","createFinalCheckpoint","cascadeShutdown","agentGracePeriodMs","cleanupBackgroundProcesses","perAgentTimeoutMs","shutdownSwarm","agentIds","reason","Error","Date","now","shutdownResult","success","totalAgents","length","successfulShutdowns","failedShutdowns","totalLatencyMs","agentResults","backgroundProcessesCleaned","shutdownAt","emit","agentCount","pauseAllAgents","parallelShutdown","filter","r","reduce","sum","backgroundProcessesTerminated","console","warn","error","message","String","result","emergencyShutdown","activeAgents","getActiveAgents","map","a","agentId","originalCheckpointConfig","cleanup","pauseStartTime","pausePromises","agent","find","isPaused","pauseAgent","debug","Promise","all","pauseLatency","latencyMs","results","agentHierarchy","buildAgentHierarchy","shutdownOrder","getShutdownOrder","shutdownSingleAgent","push","remaining","id","some","remainingId","forceTerminateAgent","shutdownPromises","startTime","checkpoint","createCheckpoint","shutdownTimestamp","shutdownReason","processes","getAllProcesses","p","process","terminateProcess","terminateAgent","hierarchy","Map","agentProcesses","children","getChildProcesses","childAgentIds","c","includes","set","visited","Set","order","dfs","has","add","get","child","allAgents","keys","Array","from","values","flat","childrenArrays","roots","root","reverse","isShutdownInProgress","getConfig"],"mappings":"AAAA;;;;;;;;;;;;;;;;;;CAkBC,GAED,SAASA,YAAY,QAAQ,SAAS;AAiFtC;;;;;;;;;;;;;;;;;;;;;;;;CAwBC,GACD,OAAO,MAAMC,sBAAsBD;IACzBE,gBAAiC;IACjCC,uBAAgD;IAChDC,OAA4B;IAC5BC,qBAA8B,MAAM;IACpCC,oBAA4B,EAAE;IAEtC,YACEJ,eAAgC,EAChCC,sBAA+C,EAC/CC,MAAqC,CACrC;QACA,KAAK;QAEL,IAAI,CAACF,eAAe,GAAGA;QACvB,IAAI,CAACC,sBAAsB,GAAGA;QAC9B,IAAI,CAACC,MAAM,GAAG;YACZG,mBAAmB;YACnBC,uBAAuB;YACvBC,iBAAiB;YACjBC,oBAAoB;YACpBC,4BAA4B;YAC5BC,mBAAmB;YACnB,GAAGR,MAAM;QACX;IACF;IAEA;;;;;;;;GAQC,GACD,MAAMS,cACJC,QAAkB,EAClBC,SAAiB,yBAAyB,EACZ;QAC9B,IAAI,IAAI,CAACV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I,CAACH,WAAWvE,MAAM,CAACsC,CAAAA,KAAM,CAACmB,SAASU,GAAG,CAAC7B;QAE/D,qBAAqB;QACrB,KAAK,MAAMyC,QAAQD,MAAO;YACxBZ,IAAIa;QACN;QAEA,kCAAkC;QAClC,OAAOd,MAAMe,OAAO;IACtB;IAEA;;GAEC,GACDC,uBAAgC;QAC9B,OAAO,IAAI,CAAC7G,kBAAkB;IAChC;IAEA;;GAEC,GACD8G,YAAiC;QAC/B,OAAO;YAAE,GAAG,IAAI,CAAC/G,MAAM;QAAC;IAC1B;AACF"}
|
|
@@ -0,0 +1,287 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Agent Coordination V2 - CoordinatorFactory
|
|
3
|
+
*
|
|
4
|
+
* Factory pattern for auto-detecting and instantiating coordination modes (CLI/SDK/Hybrid).
|
|
5
|
+
* Enables seamless switching between coordination strategies based on environment.
|
|
6
|
+
*
|
|
7
|
+
* @module coordination/v2/coordinator-factory
|
|
8
|
+
*/ import { existsSync } from 'node:fs';
|
|
9
|
+
import { execSync } from 'node:child_process';
|
|
10
|
+
import { QueryController } from './sdk/query-controller.js';
|
|
11
|
+
import { Logger } from '../../core/logger.js';
|
|
12
|
+
/**
|
|
13
|
+
* CoordinatorFactory - Auto-detects coordination mode and instantiates coordinators
|
|
14
|
+
*
|
|
15
|
+
* Features:
|
|
16
|
+
* - Automatic mode detection based on environment
|
|
17
|
+
* - Validation of mode compatibility
|
|
18
|
+
* - Graceful degradation when capabilities missing
|
|
19
|
+
* - Polymorphic coordinator creation (returns ICoordinator)
|
|
20
|
+
*
|
|
21
|
+
* Coordination Modes:
|
|
22
|
+
* - **SDK**: Direct Anthropic SDK usage (requires ANTHROPIC_API_KEY)
|
|
23
|
+
* - **CLI**: Claude Code CLI execution (requires claude-code CLI)
|
|
24
|
+
* - **Hybrid**: Mixed CLI/SDK with seamless transitions (Week 2 feature)
|
|
25
|
+
* - **Auto**: Automatic detection (default)
|
|
26
|
+
*
|
|
27
|
+
* Mode Selection Priority:
|
|
28
|
+
* 1. Explicit mode from options.mode
|
|
29
|
+
* 2. Auto-detection: SDK > CLI > Hybrid
|
|
30
|
+
* 3. Fallback to SDK if no valid mode found
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* ```typescript
|
|
34
|
+
* // Auto-detect mode
|
|
35
|
+
* const coordinator = await CoordinatorFactory.create();
|
|
36
|
+
*
|
|
37
|
+
* // Explicit SDK mode
|
|
38
|
+
* const sdkCoordinator = await CoordinatorFactory.create({
|
|
39
|
+
* mode: 'sdk',
|
|
40
|
+
* apiKey: process.env.ANTHROPIC_API_KEY
|
|
41
|
+
* });
|
|
42
|
+
*
|
|
43
|
+
* // Validate environment before creation
|
|
44
|
+
* const capabilities = CoordinatorFactory.detectEnvironment();
|
|
45
|
+
* if (capabilities.validationErrors.length === 0) {
|
|
46
|
+
* const coordinator = await CoordinatorFactory.create({
|
|
47
|
+
* mode: capabilities.suggestedMode
|
|
48
|
+
* });
|
|
49
|
+
* }
|
|
50
|
+
* ```
|
|
51
|
+
*/ export class CoordinatorFactory {
|
|
52
|
+
static logger = new Logger({
|
|
53
|
+
level: 'info',
|
|
54
|
+
format: 'text',
|
|
55
|
+
destination: 'console'
|
|
56
|
+
});
|
|
57
|
+
/**
|
|
58
|
+
* Detect environment capabilities and suggest coordination mode
|
|
59
|
+
*
|
|
60
|
+
* Checks for:
|
|
61
|
+
* - ANTHROPIC_API_KEY environment variable
|
|
62
|
+
* - Claude Code CLI binary presence
|
|
63
|
+
* - CLI path validity
|
|
64
|
+
*
|
|
65
|
+
* @returns Environment capabilities and suggested mode
|
|
66
|
+
*/ static detectEnvironment() {
|
|
67
|
+
const capabilities = {
|
|
68
|
+
hasSDKCredentials: false,
|
|
69
|
+
hasCLI: false,
|
|
70
|
+
suggestedMode: 'sdk',
|
|
71
|
+
validationErrors: []
|
|
72
|
+
};
|
|
73
|
+
// Check for SDK credentials
|
|
74
|
+
const apiKey = process.env.ANTHROPIC_API_KEY;
|
|
75
|
+
if (apiKey && apiKey.trim().length > 0) {
|
|
76
|
+
capabilities.hasSDKCredentials = true;
|
|
77
|
+
// Validate API key format (starts with sk-ant-)
|
|
78
|
+
if (!apiKey.startsWith('sk-ant-')) {
|
|
79
|
+
capabilities.validationErrors.push('ANTHROPIC_API_KEY does not match expected format (should start with sk-ant-)');
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
// Check for Claude Code CLI
|
|
83
|
+
const cliPathEnv = process.env.CLAUDE_CODE_CLI;
|
|
84
|
+
if (cliPathEnv && existsSync(cliPathEnv)) {
|
|
85
|
+
capabilities.hasCLI = true;
|
|
86
|
+
capabilities.cliPath = cliPathEnv;
|
|
87
|
+
} else {
|
|
88
|
+
// Try to find claude-code in PATH
|
|
89
|
+
try {
|
|
90
|
+
const whichResult = execSync('which claude-code 2>/dev/null || where claude-code 2>NUL', {
|
|
91
|
+
encoding: 'utf-8',
|
|
92
|
+
stdio: [
|
|
93
|
+
'ignore',
|
|
94
|
+
'pipe',
|
|
95
|
+
'ignore'
|
|
96
|
+
]
|
|
97
|
+
}).trim();
|
|
98
|
+
if (whichResult) {
|
|
99
|
+
capabilities.hasCLI = true;
|
|
100
|
+
capabilities.cliPath = whichResult.split('\n')[0]; // Take first match
|
|
101
|
+
}
|
|
102
|
+
} catch {
|
|
103
|
+
// CLI not found in PATH
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
// Determine suggested mode based on capabilities
|
|
107
|
+
if (capabilities.hasSDKCredentials && !capabilities.hasCLI) {
|
|
108
|
+
capabilities.suggestedMode = 'sdk';
|
|
109
|
+
} else if (!capabilities.hasSDKCredentials && capabilities.hasCLI) {
|
|
110
|
+
capabilities.suggestedMode = 'cli';
|
|
111
|
+
} else if (capabilities.hasSDKCredentials && capabilities.hasCLI) {
|
|
112
|
+
capabilities.suggestedMode = 'hybrid';
|
|
113
|
+
} else {
|
|
114
|
+
capabilities.suggestedMode = 'sdk'; // Default fallback
|
|
115
|
+
capabilities.validationErrors.push('No coordination mode available: Missing both ANTHROPIC_API_KEY and Claude Code CLI');
|
|
116
|
+
}
|
|
117
|
+
return capabilities;
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Auto-detect coordination mode based on environment
|
|
121
|
+
*
|
|
122
|
+
* Priority:
|
|
123
|
+
* 1. SDK (if ANTHROPIC_API_KEY present)
|
|
124
|
+
* 2. CLI (if Claude Code CLI available)
|
|
125
|
+
* 3. Hybrid (if both available)
|
|
126
|
+
* 4. SDK (default fallback)
|
|
127
|
+
*
|
|
128
|
+
* @returns Detected coordination mode
|
|
129
|
+
*/ static detectMode() {
|
|
130
|
+
const capabilities = this.detectEnvironment();
|
|
131
|
+
return capabilities.suggestedMode;
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Validate mode compatibility with current environment
|
|
135
|
+
*
|
|
136
|
+
* Checks if requested mode can be used based on available credentials/tools.
|
|
137
|
+
*
|
|
138
|
+
* @param mode - Coordination mode to validate
|
|
139
|
+
* @returns True if mode is compatible, false otherwise
|
|
140
|
+
*/ static validateMode(mode) {
|
|
141
|
+
if (mode === 'auto') {
|
|
142
|
+
return true; // Auto mode always valid (falls back)
|
|
143
|
+
}
|
|
144
|
+
const capabilities = this.detectEnvironment();
|
|
145
|
+
switch(mode){
|
|
146
|
+
case 'sdk':
|
|
147
|
+
return capabilities.hasSDKCredentials;
|
|
148
|
+
case 'cli':
|
|
149
|
+
return capabilities.hasCLI;
|
|
150
|
+
case 'hybrid':
|
|
151
|
+
return capabilities.hasSDKCredentials && capabilities.hasCLI;
|
|
152
|
+
default:
|
|
153
|
+
return false;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Create coordinator instance based on mode
|
|
158
|
+
*
|
|
159
|
+
* Instantiates appropriate coordinator implementation:
|
|
160
|
+
* - SDK mode: QueryController (Anthropic SDK)
|
|
161
|
+
* - CLI mode: CLICoordinator (Week 1 implementation)
|
|
162
|
+
* - Hybrid mode: HybridCoordinator (Week 2 implementation)
|
|
163
|
+
* - Auto mode: Detects and creates appropriate coordinator
|
|
164
|
+
*
|
|
165
|
+
* @param options - Factory configuration options
|
|
166
|
+
* @returns Promise resolving to ICoordinator instance
|
|
167
|
+
* @throws Error if mode not implemented or environment incompatible
|
|
168
|
+
*
|
|
169
|
+
* @example
|
|
170
|
+
* ```typescript
|
|
171
|
+
* // Auto-detect mode
|
|
172
|
+
* const coordinator = await CoordinatorFactory.create();
|
|
173
|
+
*
|
|
174
|
+
* // Explicit SDK mode
|
|
175
|
+
* const coordinator = await CoordinatorFactory.create({
|
|
176
|
+
* mode: 'sdk',
|
|
177
|
+
* apiKey: 'sk-ant-...',
|
|
178
|
+
* maxConcurrentAgents: 5
|
|
179
|
+
* });
|
|
180
|
+
* ```
|
|
181
|
+
*/ static async create(options = {}) {
|
|
182
|
+
const startTime = Date.now();
|
|
183
|
+
// Determine effective mode
|
|
184
|
+
const requestedMode = options.mode === 'auto' || !options.mode ? this.detectMode() : options.mode;
|
|
185
|
+
this.logger.info('Creating coordinator', {
|
|
186
|
+
requestedMode: options.mode ?? 'auto',
|
|
187
|
+
detectedMode: requestedMode
|
|
188
|
+
});
|
|
189
|
+
// Validate mode compatibility
|
|
190
|
+
if (!this.validateMode(requestedMode)) {
|
|
191
|
+
const capabilities = this.detectEnvironment();
|
|
192
|
+
throw new Error(`Coordination mode '${requestedMode}' not available in current environment.\n` + `Validation errors: ${capabilities.validationErrors.join(', ')}\n` + `Suggested mode: ${capabilities.suggestedMode}`);
|
|
193
|
+
}
|
|
194
|
+
// Create coordinator based on mode
|
|
195
|
+
let coordinator;
|
|
196
|
+
switch(requestedMode){
|
|
197
|
+
case 'sdk':
|
|
198
|
+
coordinator = await this.createSDKCoordinator(options);
|
|
199
|
+
break;
|
|
200
|
+
case 'cli':
|
|
201
|
+
// CLICoordinator implementation scheduled for Week 1
|
|
202
|
+
throw new Error('CLI mode not yet implemented (Week 1 roadmap).\n' + 'Use SDK mode for now: CoordinatorFactory.create({ mode: "sdk" })');
|
|
203
|
+
case 'hybrid':
|
|
204
|
+
// HybridCoordinator implementation scheduled for Week 2
|
|
205
|
+
throw new Error('Hybrid mode not yet implemented (Week 2 roadmap).\n' + 'Use SDK mode for now: CoordinatorFactory.create({ mode: "sdk" })');
|
|
206
|
+
default:
|
|
207
|
+
throw new Error(`Unknown coordination mode: ${requestedMode}`);
|
|
208
|
+
}
|
|
209
|
+
// Initialize coordinator
|
|
210
|
+
await coordinator.initialize();
|
|
211
|
+
const initTime = Date.now() - startTime;
|
|
212
|
+
this.logger.info('Coordinator initialized', {
|
|
213
|
+
mode: requestedMode,
|
|
214
|
+
initTimeMs: initTime
|
|
215
|
+
});
|
|
216
|
+
return coordinator;
|
|
217
|
+
}
|
|
218
|
+
/**
|
|
219
|
+
* Create SDK coordinator instance (QueryController)
|
|
220
|
+
*
|
|
221
|
+
* @private
|
|
222
|
+
* @param options - Factory options
|
|
223
|
+
* @returns Promise resolving to QueryController instance
|
|
224
|
+
*/ static async createSDKCoordinator(options) {
|
|
225
|
+
// Get API key from options or environment
|
|
226
|
+
const apiKey = options.apiKey ?? process.env.ANTHROPIC_API_KEY;
|
|
227
|
+
if (!apiKey) {
|
|
228
|
+
throw new Error('SDK mode requires ANTHROPIC_API_KEY.\n' + 'Set environment variable: export ANTHROPIC_API_KEY=sk-ant-...\n' + 'Or pass via options: { apiKey: "sk-ant-..." }');
|
|
229
|
+
}
|
|
230
|
+
// Validate API key format
|
|
231
|
+
if (!apiKey.startsWith('sk-ant-')) {
|
|
232
|
+
throw new Error(`Invalid API key format. Expected format: sk-ant-..., got: ${apiKey.substring(0, 10)}...`);
|
|
233
|
+
}
|
|
234
|
+
// Configure QueryController
|
|
235
|
+
const config = {
|
|
236
|
+
maxConcurrentAgents: options.maxConcurrentAgents,
|
|
237
|
+
defaultTokenBudget: options.defaultTokenBudget,
|
|
238
|
+
enableDynamicAllocation: options.enableDynamicAllocation
|
|
239
|
+
};
|
|
240
|
+
this.logger.debug('Creating SDK coordinator (QueryController)', config);
|
|
241
|
+
return new QueryController(config);
|
|
242
|
+
}
|
|
243
|
+
/**
|
|
244
|
+
* Get capabilities summary for current environment
|
|
245
|
+
*
|
|
246
|
+
* Useful for debugging and environment validation.
|
|
247
|
+
*
|
|
248
|
+
* @returns Human-readable capabilities summary
|
|
249
|
+
*
|
|
250
|
+
* @example
|
|
251
|
+
* ```typescript
|
|
252
|
+
* console.log(CoordinatorFactory.getCapabilitiesSummary());
|
|
253
|
+
* // Output:
|
|
254
|
+
* // Environment Capabilities:
|
|
255
|
+
* // - SDK Credentials: ✓ (ANTHROPIC_API_KEY set)
|
|
256
|
+
* // - Claude Code CLI: ✗ (not found in PATH)
|
|
257
|
+
* // - Suggested Mode: sdk
|
|
258
|
+
* ```
|
|
259
|
+
*/ static getCapabilitiesSummary() {
|
|
260
|
+
const capabilities = this.detectEnvironment();
|
|
261
|
+
const lines = [
|
|
262
|
+
'Environment Capabilities:',
|
|
263
|
+
`- SDK Credentials: ${capabilities.hasSDKCredentials ? '✓' : '✗'} ${capabilities.hasSDKCredentials ? '(ANTHROPIC_API_KEY set)' : '(ANTHROPIC_API_KEY not set)'}`,
|
|
264
|
+
`- Claude Code CLI: ${capabilities.hasCLI ? '✓' : '✗'} ${capabilities.hasCLI ? `(found at ${capabilities.cliPath})` : '(not found in PATH)'}`,
|
|
265
|
+
`- Suggested Mode: ${capabilities.suggestedMode}`
|
|
266
|
+
];
|
|
267
|
+
if (capabilities.validationErrors.length > 0) {
|
|
268
|
+
lines.push('- Validation Errors:');
|
|
269
|
+
capabilities.validationErrors.forEach((err)=>{
|
|
270
|
+
lines.push(` * ${err}`);
|
|
271
|
+
});
|
|
272
|
+
}
|
|
273
|
+
return lines.join('\n');
|
|
274
|
+
}
|
|
275
|
+
/**
|
|
276
|
+
* Check if factory is ready to create coordinators
|
|
277
|
+
*
|
|
278
|
+
* Validates that at least one coordination mode is available.
|
|
279
|
+
*
|
|
280
|
+
* @returns True if factory can create coordinators
|
|
281
|
+
*/ static isReady() {
|
|
282
|
+
const capabilities = this.detectEnvironment();
|
|
283
|
+
return capabilities.hasSDKCredentials || capabilities.hasCLI;
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
//# sourceMappingURL=coordinator-factory.js.map
|