claude-flow-novice 1.6.1 → 1.6.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude/agents/cfn-loop/product-owner.md +54 -4
- package/.claude/commands/cfn-claude-sync.md +303 -0
- package/.claude/commands/cfn-loop-epic.md +290 -0
- package/.claude/commands/cfn-loop-single.md +168 -0
- package/.claude/commands/cfn-loop-sprints.md +384 -0
- package/.claude/commands/cfn-loop.md +180 -0
- package/.claude/commands/metrics-summary.md +58 -0
- package/.claude/commands/parse-epic.md +357 -0
- package/.claude/settings.json +4 -4
- package/.claude/settings.local.json +9 -2
- package/.claude-flow-novice/.claude/agents/cfn-loop/product-owner.md +792 -0
- package/.claude-flow-novice/dist/mcp/server.js +21 -2
- package/.claude-flow-novice/dist/src/api/claude-client.js +138 -3
- package/.claude-flow-novice/dist/src/api/claude-client.js.map +1 -1
- package/.claude-flow-novice/dist/src/cfn-loop/phase-orchestrator-example.js +1 -1
- package/.claude-flow-novice/dist/src/cfn-loop/scope-control.js +247 -0
- package/.claude-flow-novice/dist/src/cfn-loop/scope-control.js.map +1 -0
- package/.claude-flow-novice/dist/src/cli/commands/swarm.js +32 -15
- package/.claude-flow-novice/dist/src/cli/commands/swarm.js.map +1 -1
- package/.claude-flow-novice/dist/src/cli/commands/transparency.js +455 -0
- package/.claude-flow-novice/dist/src/cli/commands/transparency.js.map +1 -0
- package/.claude-flow-novice/dist/src/cli/simple-commands/init/templates/CLAUDE.md +129 -13
- package/.claude-flow-novice/dist/src/components/visualizations/index.js +9 -0
- package/.claude-flow-novice/dist/src/components/visualizations/index.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/adapters/v1-coordinator-adapter.js +462 -0
- package/.claude-flow-novice/dist/src/coordination/adapters/v1-coordinator-adapter.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/config-translator.js +248 -0
- package/.claude-flow-novice/dist/src/coordination/config-translator.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/coordination-toggle.js +287 -0
- package/.claude-flow-novice/dist/src/coordination/coordination-toggle.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/distributed-consensus.js +68 -9
- package/.claude-flow-novice/dist/src/coordination/distributed-consensus.js.map +1 -1
- package/.claude-flow-novice/dist/src/coordination/feature-flags.js +166 -0
- package/.claude-flow-novice/dist/src/coordination/feature-flags.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/queen-agent.js +18 -4
- package/.claude-flow-novice/dist/src/coordination/queen-agent.js.map +1 -1
- package/.claude-flow-novice/dist/src/coordination/role-assignment.js +6 -110
- package/.claude-flow-novice/dist/src/coordination/role-assignment.js.map +1 -1
- package/.claude-flow-novice/dist/src/coordination/v2/cache/artifact-cache-optimizer.js +632 -0
- package/.claude-flow-novice/dist/src/coordination/v2/cache/artifact-cache-optimizer.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/v2/cache/index.js +11 -0
- package/.claude-flow-novice/dist/src/coordination/v2/cache/index.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/v2/checkpoints/checkpoint-compressor.js +318 -0
- package/.claude-flow-novice/dist/src/coordination/v2/checkpoints/checkpoint-compressor.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/v2/coordinators/cascading-shutdown.example.js +364 -0
- package/.claude-flow-novice/dist/src/coordination/v2/coordinators/cascading-shutdown.example.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/v2/coordinators/cascading-shutdown.js +492 -0
- package/.claude-flow-novice/dist/src/coordination/v2/coordinators/cascading-shutdown.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/v2/coordinators/hierarchical-coordinator.js +786 -0
- package/.claude-flow-novice/dist/src/coordination/v2/coordinators/hierarchical-coordinator.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/v2/coordinators/index.js +16 -0
- package/.claude-flow-novice/dist/src/coordination/v2/coordinators/index.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/v2/coordinators/parent-child-manager.js +342 -0
- package/.claude-flow-novice/dist/src/coordination/v2/coordinators/parent-child-manager.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/v2/coordinators/swarm-coordinator-v2.js +601 -0
- package/.claude-flow-novice/dist/src/coordination/v2/coordinators/swarm-coordinator-v2.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/v2/core/help-request-metrics.js +211 -0
- package/.claude-flow-novice/dist/src/coordination/v2/core/help-request-metrics.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/v2/core/index.js +1 -0
- package/.claude-flow-novice/dist/src/coordination/v2/core/index.js.map +1 -1
- package/.claude-flow-novice/dist/src/coordination/v2/core/message-broker.js +365 -6
- package/.claude-flow-novice/dist/src/coordination/v2/core/message-broker.js.map +1 -1
- package/.claude-flow-novice/dist/src/coordination/v2/core/resource-manager-safe.js +478 -0
- package/.claude-flow-novice/dist/src/coordination/v2/core/resource-manager-safe.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/v2/core/state-machine-config.js +5 -2
- package/.claude-flow-novice/dist/src/coordination/v2/core/state-machine-config.js.map +1 -1
- package/.claude-flow-novice/dist/src/coordination/v2/core/state-machine.js +189 -0
- package/.claude-flow-novice/dist/src/coordination/v2/core/state-machine.js.map +1 -1
- package/.claude-flow-novice/dist/src/coordination/v2/deadlock/deadlock-detector.js +424 -0
- package/.claude-flow-novice/dist/src/coordination/v2/deadlock/deadlock-detector.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/v2/deadlock/index.js +9 -0
- package/.claude-flow-novice/dist/src/coordination/v2/deadlock/index.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/v2/deadlock/resource-manager.js +669 -0
- package/.claude-flow-novice/dist/src/coordination/v2/deadlock/resource-manager.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/v2/dependency/artifact-storage.js +451 -0
- package/.claude-flow-novice/dist/src/coordination/v2/dependency/artifact-storage.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/v2/dependency/cycle-detector.js +271 -0
- package/.claude-flow-novice/dist/src/coordination/v2/dependency/cycle-detector.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/v2/dependency/dependency-graph.js +335 -0
- package/.claude-flow-novice/dist/src/coordination/v2/dependency/dependency-graph.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/v2/dependency/dependency-manager.js +439 -0
- package/.claude-flow-novice/dist/src/coordination/v2/dependency/dependency-manager.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/v2/dependency/dependency-request.js +92 -0
- package/.claude-flow-novice/dist/src/coordination/v2/dependency/dependency-request.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/v2/dependency/index.js +21 -0
- package/.claude-flow-novice/dist/src/coordination/v2/dependency/index.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/v2/dependency/topological-sort.js +223 -0
- package/.claude-flow-novice/dist/src/coordination/v2/dependency/topological-sort.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/v2/help-system/help-coordinator.js +436 -0
- package/.claude-flow-novice/dist/src/coordination/v2/help-system/help-coordinator.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/v2/help-system/help-matcher.js +278 -0
- package/.claude-flow-novice/dist/src/coordination/v2/help-system/help-matcher.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/v2/help-system/help-request-handler.js +317 -0
- package/.claude-flow-novice/dist/src/coordination/v2/help-system/help-request-handler.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/v2/help-system/help-request.js +273 -0
- package/.claude-flow-novice/dist/src/coordination/v2/help-system/help-request.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/v2/help-system/index.js +15 -0
- package/.claude-flow-novice/dist/src/coordination/v2/help-system/index.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/v2/help-system/waiting-agent-pool.js +512 -0
- package/.claude-flow-novice/dist/src/coordination/v2/help-system/waiting-agent-pool.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/v2/index.js +6 -0
- package/.claude-flow-novice/dist/src/coordination/v2/index.js.map +1 -1
- package/.claude-flow-novice/dist/src/coordination/v2/integration/help-deadlock-integration.js +557 -0
- package/.claude-flow-novice/dist/src/coordination/v2/integration/help-deadlock-integration.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/v2/integration/index.js +14 -0
- package/.claude-flow-novice/dist/src/coordination/v2/integration/index.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/v2/integration/message-bus-completion-integration.example.js +212 -0
- package/.claude-flow-novice/dist/src/coordination/v2/integration/message-bus-completion-integration.example.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/v2/integration/message-bus-completion-integration.js +552 -0
- package/.claude-flow-novice/dist/src/coordination/v2/integration/message-bus-completion-integration.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/v2/memory/dependency-storage.js +367 -0
- package/.claude-flow-novice/dist/src/coordination/v2/memory/dependency-storage.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/v2/memory/index.js +1 -0
- package/.claude-flow-novice/dist/src/coordination/v2/memory/index.js.map +1 -1
- package/.claude-flow-novice/dist/src/coordination/v2/messaging/channel.js +371 -0
- package/.claude-flow-novice/dist/src/coordination/v2/messaging/channel.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/v2/messaging/channels/dependency-channel.js +355 -0
- package/.claude-flow-novice/dist/src/coordination/v2/messaging/channels/dependency-channel.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/v2/messaging/channels/help-channel.js +424 -0
- package/.claude-flow-novice/dist/src/coordination/v2/messaging/channels/help-channel.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/v2/messaging/channels/index.js +16 -0
- package/.claude-flow-novice/dist/src/coordination/v2/messaging/channels/index.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/v2/messaging/channels/state-channel.js +295 -0
- package/.claude-flow-novice/dist/src/coordination/v2/messaging/channels/state-channel.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/v2/messaging/channels/task-channel.js +411 -0
- package/.claude-flow-novice/dist/src/coordination/v2/messaging/channels/task-channel.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/v2/messaging/index.js +14 -0
- package/.claude-flow-novice/dist/src/coordination/v2/messaging/index.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/v2/messaging/message-bus.js +387 -0
- package/.claude-flow-novice/dist/src/coordination/v2/messaging/message-bus.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/v2/messaging/message-persistence.js +589 -0
- package/.claude-flow-novice/dist/src/coordination/v2/messaging/message-persistence.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/v2/messaging/message-router.js +444 -0
- package/.claude-flow-novice/dist/src/coordination/v2/messaging/message-router.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/v2/sdk/checkpoint-manager.js +29 -8
- package/.claude-flow-novice/dist/src/coordination/v2/sdk/checkpoint-manager.js.map +1 -1
- package/.claude-flow-novice/dist/src/coordination/v2/sdk/help-coordinator.js +470 -0
- package/.claude-flow-novice/dist/src/coordination/v2/sdk/help-coordinator.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/v2/sdk/hierarchical-background-integration.js +450 -0
- package/.claude-flow-novice/dist/src/coordination/v2/sdk/hierarchical-background-integration.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/v2/sdk/index.js +5 -0
- package/.claude-flow-novice/dist/src/coordination/v2/sdk/index.js.map +1 -1
- package/.claude-flow-novice/dist/src/coordination/v2/sdk/multi-level-control.js +545 -0
- package/.claude-flow-novice/dist/src/coordination/v2/sdk/multi-level-control.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/v2/sdk/query-controller.js +44 -0
- package/.claude-flow-novice/dist/src/coordination/v2/sdk/query-controller.js.map +1 -1
- package/.claude-flow-novice/dist/src/coordination/v2/sdk/query-message-integration.js +415 -0
- package/.claude-flow-novice/dist/src/coordination/v2/sdk/query-message-integration.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/v2/sdk/session-pool-optimizer.js +615 -0
- package/.claude-flow-novice/dist/src/coordination/v2/sdk/session-pool-optimizer.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/v2/security/payload-validator.js +259 -0
- package/.claude-flow-novice/dist/src/coordination/v2/security/payload-validator.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/v2/transparency/index.js +17 -0
- package/.claude-flow-novice/dist/src/coordination/v2/transparency/index.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/v2/transparency/transparency-integration.js +357 -0
- package/.claude-flow-novice/dist/src/coordination/v2/transparency/transparency-integration.js.map +1 -0
- package/.claude-flow-novice/dist/src/coordination/v2/transparency/transparency-system.js +679 -0
- package/.claude-flow-novice/dist/src/coordination/v2/transparency/transparency-system.js.map +1 -0
- package/.claude-flow-novice/dist/src/core/agent-manager.js +30 -0
- package/.claude-flow-novice/dist/src/core/agent-manager.js.map +1 -1
- package/.claude-flow-novice/dist/src/mcp/server.js +21 -2
- package/.claude-flow-novice/dist/src/mcp/server.js.map +1 -1
- package/.claude-flow-novice/dist/src/observability/metrics-counter.js +268 -0
- package/.claude-flow-novice/dist/src/observability/metrics-counter.js.map +1 -0
- package/.claude-flow-novice/dist/src/observability/metrics-storage.js +265 -0
- package/.claude-flow-novice/dist/src/observability/metrics-storage.js.map +1 -0
- package/.claude-flow-novice/dist/src/observability/telemetry.js +26 -0
- package/.claude-flow-novice/dist/src/observability/telemetry.js.map +1 -1
- package/.claude-flow-novice/dist/src/providers/tiered-router.js +64 -10
- package/.claude-flow-novice/dist/src/providers/tiered-router.js.map +1 -1
- package/.claude-flow-novice/dist/src/providers/zai-provider.js +196 -97
- package/.claude-flow-novice/dist/src/providers/zai-provider.js.map +1 -1
- package/.claude-flow-novice/dist/src/slash-commands/cfn-claude-sync.js +533 -0
- package/.claude-flow-novice/dist/src/slash-commands/index.js +5 -0
- package/.claude-flow-novice/dist/src/slash-commands/metrics-summary-class.js +74 -0
- package/.claude-flow-novice/dist/src/slash-commands/metrics-summary.js +335 -0
- package/.claude-flow-novice/dist/src/slash-commands/register-all-commands.js +12 -0
- package/.claude-flow-novice/dist/src/verification/checkpoint-compression-demo.js +96 -0
- package/.claude-flow-novice/dist/src/verification/checkpoint-compression-demo.js.map +1 -0
- package/.claude-flow-novice/dist/src/verification/checkpoint-compression.js +406 -0
- package/.claude-flow-novice/dist/src/verification/checkpoint-compression.js.map +1 -0
- package/.claude-flow-novice/dist/src/verification/checkpoint-manager.js +35 -5
- package/.claude-flow-novice/dist/src/verification/checkpoint-manager.js.map +1 -1
- package/.claude-flow-novice/dist/src/web/api/config/api-config.js +186 -0
- package/.claude-flow-novice/dist/src/web/api/config/api-config.js.map +1 -0
- package/.claude-flow-novice/dist/src/web/api/middleware/auth.js +205 -0
- package/.claude-flow-novice/dist/src/web/api/middleware/auth.js.map +1 -0
- package/.claude-flow-novice/dist/src/web/api/middleware/cache.js +262 -0
- package/.claude-flow-novice/dist/src/web/api/middleware/cache.js.map +1 -0
- package/.claude-flow-novice/dist/src/web/api/middleware/error-handler.js +250 -0
- package/.claude-flow-novice/dist/src/web/api/middleware/error-handler.js.map +1 -0
- package/.claude-flow-novice/dist/src/web/api/middleware/request-logger.js +217 -0
- package/.claude-flow-novice/dist/src/web/api/middleware/request-logger.js.map +1 -0
- package/.claude-flow-novice/dist/src/web/api/middleware/validation.js +325 -0
- package/.claude-flow-novice/dist/src/web/api/middleware/validation.js.map +1 -0
- package/.claude-flow-novice/dist/src/web/api/routes/events.js +465 -0
- package/.claude-flow-novice/dist/src/web/api/routes/events.js.map +1 -0
- package/.claude-flow-novice/dist/src/web/api/routes/hierarchy.js +302 -0
- package/.claude-flow-novice/dist/src/web/api/routes/hierarchy.js.map +1 -0
- package/.claude-flow-novice/dist/src/web/api/routes/index.js +14 -0
- package/.claude-flow-novice/dist/src/web/api/routes/index.js.map +1 -0
- package/.claude-flow-novice/dist/src/web/api/routes/metrics.js +561 -0
- package/.claude-flow-novice/dist/src/web/api/routes/metrics.js.map +1 -0
- package/.claude-flow-novice/dist/src/web/api/routes/status.js +450 -0
- package/.claude-flow-novice/dist/src/web/api/routes/status.js.map +1 -0
- package/.claude-flow-novice/dist/src/web/api/server.js +451 -0
- package/.claude-flow-novice/dist/src/web/api/server.js.map +1 -0
- package/.claude-flow-novice/dist/src/web/dashboard/hooks/useWebSocket.js +385 -0
- package/.claude-flow-novice/dist/src/web/dashboard/hooks/useWebSocket.js.map +1 -0
- package/.claude-flow-novice/dist/src/web/dashboard/index.js +87 -0
- package/.claude-flow-novice/dist/src/web/dashboard/index.js.map +1 -0
- package/.claude-flow-novice/dist/src/web/dashboard/types.js +6 -0
- package/.claude-flow-novice/dist/src/web/dashboard/types.js.map +1 -0
- 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 +29 -0
- package/README.md +27 -0
- package/config/hooks/post-edit-pipeline.js +36 -2
- package/examples/metrics-counter-demo.ts +106 -0
- package/examples/persistent-metrics-demo.ts +83 -0
- package/examples/phase-5-multi-level-control.ts +282 -0
- package/examples/session-pool-optimizer-example.ts +311 -0
- package/package.json +15 -3
- package/scripts/check-routing-stats.cjs +122 -0
- package/scripts/pre-publish-validation.cjs +212 -0
- package/scripts/test-provider-routing.cjs +228 -0
- package/scripts/test-routing-telemetry.cjs +147 -0
- package/scripts/test-zai-10k.cjs +81 -0
- package/scripts/test-zai-api.cjs +191 -0
- package/scripts/test-zai-diagnostic.cjs +151 -0
- package/scripts/test-zai-final.cjs +128 -0
- package/scripts/test-zai-with-env.cjs +85 -0
- package/scripts/validate-coordination-cli.js +69 -0
- package/scripts/validate-coordination-toggle-integration.cjs +501 -0
- package/src/cli/simple-commands/init/templates/CLAUDE.md +29 -0
- package/src/observability/metrics-counter.ts +347 -0
- package/src/observability/metrics-storage.ts +356 -0
- package/src/observability/telemetry.ts +658 -0
- package/src/slash-commands/cfn-claude-sync.js +533 -0
- package/src/slash-commands/index.js +5 -0
- package/src/slash-commands/metrics-summary-class.js +74 -0
- package/src/slash-commands/metrics-summary.js +335 -0
- package/src/slash-commands/register-all-commands.js +12 -0
|
@@ -0,0 +1,545 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Phase 5 - Sprint 5.2: Multi-Level Agent Control
|
|
3
|
+
*
|
|
4
|
+
* Implements pause/inject/resume from Level 0 to any child level:
|
|
5
|
+
* - Parent can pause any descendant at any level
|
|
6
|
+
* - Inject commands to paused agents (modify state, update tasks)
|
|
7
|
+
* - Resume agents from Level 0 supervisor
|
|
8
|
+
* - Propagate control commands down hierarchy with <100ms latency
|
|
9
|
+
*
|
|
10
|
+
* @module coordination/v2/sdk/multi-level-control
|
|
11
|
+
*/ import { EventEmitter } from 'node:events';
|
|
12
|
+
import { Logger } from '../../../core/logger.js';
|
|
13
|
+
import { generateId } from '../../../utils/helpers.js';
|
|
14
|
+
// ============================================================================
|
|
15
|
+
// Types and Interfaces
|
|
16
|
+
// ============================================================================
|
|
17
|
+
/**
|
|
18
|
+
* Command types that can be injected into paused agents
|
|
19
|
+
*/ export var InjectedCommandType = /*#__PURE__*/ function(InjectedCommandType) {
|
|
20
|
+
/** Modify agent internal state */ InjectedCommandType["STATE_UPDATE"] = "state_update";
|
|
21
|
+
/** Assign new task to agent */ InjectedCommandType["TASK_UPDATE"] = "task_update";
|
|
22
|
+
/** Update agent priority */ InjectedCommandType["PRIORITY_UPDATE"] = "priority_update";
|
|
23
|
+
/** Modify agent metadata */ InjectedCommandType["METADATA_UPDATE"] = "metadata_update";
|
|
24
|
+
/** Custom command with arbitrary payload */ InjectedCommandType["CUSTOM"] = "custom";
|
|
25
|
+
return InjectedCommandType;
|
|
26
|
+
}({});
|
|
27
|
+
// ============================================================================
|
|
28
|
+
// Multi-Level Control Integration Layer
|
|
29
|
+
// ============================================================================
|
|
30
|
+
/**
|
|
31
|
+
* MultiLevelController - Enables Level 0 to control any descendant
|
|
32
|
+
*
|
|
33
|
+
* Integrates QueryController (pause/resume) with HierarchicalCoordinator
|
|
34
|
+
* (hierarchy management) to provide:
|
|
35
|
+
* - Pause any agent at any level from Level 0
|
|
36
|
+
* - Inject commands into paused agents
|
|
37
|
+
* - Resume agents with injected commands applied
|
|
38
|
+
* - <100ms latency for control operations
|
|
39
|
+
*/ export class MultiLevelController extends EventEmitter {
|
|
40
|
+
logger;
|
|
41
|
+
config;
|
|
42
|
+
queryController;
|
|
43
|
+
hierarchicalCoordinator;
|
|
44
|
+
/** Command injection queue per agent */ commandQueues;
|
|
45
|
+
/** Agent level cache for fast lookups */ agentLevelCache;
|
|
46
|
+
/** Control operation metrics */ metrics;
|
|
47
|
+
constructor(queryController, config = {}){
|
|
48
|
+
super();
|
|
49
|
+
this.logger = new Logger({
|
|
50
|
+
level: 'info',
|
|
51
|
+
format: 'text',
|
|
52
|
+
destination: 'console'
|
|
53
|
+
});
|
|
54
|
+
this.config = {
|
|
55
|
+
maxControlLatencyMs: 100,
|
|
56
|
+
enableCommandQueue: true,
|
|
57
|
+
maxQueuedCommands: 50,
|
|
58
|
+
enableLogging: config.enableLogging ?? true,
|
|
59
|
+
...config
|
|
60
|
+
};
|
|
61
|
+
this.queryController = queryController;
|
|
62
|
+
this.commandQueues = new Map();
|
|
63
|
+
this.agentLevelCache = new Map();
|
|
64
|
+
this.metrics = this.initializeMetrics();
|
|
65
|
+
this.logger.info('MultiLevelController initialized', {
|
|
66
|
+
maxControlLatencyMs: this.config.maxControlLatencyMs,
|
|
67
|
+
enableCommandQueue: this.config.enableCommandQueue
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Register hierarchical coordinator for level tracking
|
|
72
|
+
*/ registerHierarchicalCoordinator(coordinator) {
|
|
73
|
+
this.hierarchicalCoordinator = coordinator;
|
|
74
|
+
// Build agent level cache from hierarchy
|
|
75
|
+
if (coordinator && typeof coordinator.getHierarchyStructure === 'function') {
|
|
76
|
+
const hierarchy = coordinator.getHierarchyStructure();
|
|
77
|
+
for (const agent of hierarchy.agents){
|
|
78
|
+
this.agentLevelCache.set(agent.id, agent.level);
|
|
79
|
+
}
|
|
80
|
+
this.logger.info('Hierarchical coordinator registered', {
|
|
81
|
+
totalAgents: hierarchy.agents.length,
|
|
82
|
+
hierarchyDepth: hierarchy.depth
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Update agent level cache when hierarchy changes
|
|
88
|
+
*/ updateAgentLevel(agentId, level) {
|
|
89
|
+
this.agentLevelCache.set(agentId, level);
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Get agent hierarchy level (cached)
|
|
93
|
+
*/ getAgentLevel(agentId) {
|
|
94
|
+
// Try cache first
|
|
95
|
+
const cachedLevel = this.agentLevelCache.get(agentId);
|
|
96
|
+
if (cachedLevel !== undefined) {
|
|
97
|
+
return cachedLevel;
|
|
98
|
+
}
|
|
99
|
+
// Fallback to hierarchical coordinator lookup
|
|
100
|
+
if (this.hierarchicalCoordinator) {
|
|
101
|
+
const agentStatus = this.hierarchicalCoordinator.getAgentStatus(agentId);
|
|
102
|
+
if (agentStatus) {
|
|
103
|
+
this.agentLevelCache.set(agentId, agentStatus.level);
|
|
104
|
+
return agentStatus.level;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
// Default to Level 0 if not found
|
|
108
|
+
return 0;
|
|
109
|
+
}
|
|
110
|
+
// ============================================================================
|
|
111
|
+
// Multi-Level Control Operations (Level 0 → Level N)
|
|
112
|
+
// ============================================================================
|
|
113
|
+
/**
|
|
114
|
+
* Pause agent at any level from Level 0 parent
|
|
115
|
+
*
|
|
116
|
+
* @param parentAgentId - Parent issuing the pause (Level 0 supervisor)
|
|
117
|
+
* @param targetAgentId - Child agent to pause (any level)
|
|
118
|
+
* @param reason - Reason for pause
|
|
119
|
+
* @returns Control operation result
|
|
120
|
+
*/ async pauseChildAgent(parentAgentId, targetAgentId, reason) {
|
|
121
|
+
const startTime = Date.now();
|
|
122
|
+
try {
|
|
123
|
+
const targetLevel = this.getAgentLevel(targetAgentId);
|
|
124
|
+
// Use QueryController to pause agent
|
|
125
|
+
await this.queryController.pauseAgent(targetAgentId, reason ?? `Paused by parent ${parentAgentId}`);
|
|
126
|
+
const latencyMs = Date.now() - startTime;
|
|
127
|
+
// Update metrics
|
|
128
|
+
this.updateControlMetrics(latencyMs);
|
|
129
|
+
this.metrics.totalPauses++;
|
|
130
|
+
const result = {
|
|
131
|
+
operation: 'pause',
|
|
132
|
+
success: true,
|
|
133
|
+
agentId: targetAgentId,
|
|
134
|
+
level: targetLevel,
|
|
135
|
+
latencyMs,
|
|
136
|
+
data: {
|
|
137
|
+
parentAgentId,
|
|
138
|
+
reason
|
|
139
|
+
}
|
|
140
|
+
};
|
|
141
|
+
if (this.config.enableLogging) {
|
|
142
|
+
this.logger.info('Agent paused from parent', {
|
|
143
|
+
parentAgentId,
|
|
144
|
+
targetAgentId,
|
|
145
|
+
level: targetLevel,
|
|
146
|
+
latencyMs
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
this.emit('agent:paused', result);
|
|
150
|
+
return result;
|
|
151
|
+
} catch (error) {
|
|
152
|
+
const latencyMs = Date.now() - startTime;
|
|
153
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
154
|
+
this.logger.error('Failed to pause child agent', {
|
|
155
|
+
parentAgentId,
|
|
156
|
+
targetAgentId,
|
|
157
|
+
error: errorMessage
|
|
158
|
+
});
|
|
159
|
+
return {
|
|
160
|
+
operation: 'pause',
|
|
161
|
+
success: false,
|
|
162
|
+
agentId: targetAgentId,
|
|
163
|
+
level: this.getAgentLevel(targetAgentId),
|
|
164
|
+
latencyMs,
|
|
165
|
+
error: errorMessage
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Inject command into paused agent at any level
|
|
171
|
+
*
|
|
172
|
+
* Commands are queued and applied when agent resumes.
|
|
173
|
+
* This allows parents to modify child state, assign tasks, update priorities.
|
|
174
|
+
*
|
|
175
|
+
* @param parentAgentId - Parent issuing the command
|
|
176
|
+
* @param targetAgentId - Child agent to receive command
|
|
177
|
+
* @param commandType - Type of command to inject
|
|
178
|
+
* @param payload - Command payload
|
|
179
|
+
* @param immediate - Execute immediately vs queue for resume
|
|
180
|
+
* @returns Injection result
|
|
181
|
+
*/ async injectCommand(parentAgentId, targetAgentId, commandType, payload, immediate = false) {
|
|
182
|
+
const startTime = Date.now();
|
|
183
|
+
try {
|
|
184
|
+
const targetLevel = this.getAgentLevel(targetAgentId);
|
|
185
|
+
// Verify agent is paused
|
|
186
|
+
const session = await this.queryController.getAgentSession(targetAgentId);
|
|
187
|
+
if (!session.isPaused && !immediate) {
|
|
188
|
+
throw new Error(`Agent ${targetAgentId} must be paused before command injection`);
|
|
189
|
+
}
|
|
190
|
+
// Create injected command
|
|
191
|
+
const command = {
|
|
192
|
+
id: generateId('cmd'),
|
|
193
|
+
type: commandType,
|
|
194
|
+
payload,
|
|
195
|
+
issuedBy: parentAgentId,
|
|
196
|
+
targetAgentId,
|
|
197
|
+
targetLevel,
|
|
198
|
+
timestamp: new Date(),
|
|
199
|
+
immediate
|
|
200
|
+
};
|
|
201
|
+
// Queue command for agent
|
|
202
|
+
if (this.config.enableCommandQueue) {
|
|
203
|
+
this.queueCommand(targetAgentId, command);
|
|
204
|
+
}
|
|
205
|
+
// Apply command to agent session metadata
|
|
206
|
+
await this.applyCommandToSession(session, command);
|
|
207
|
+
const latencyMs = Date.now() - startTime;
|
|
208
|
+
// Update metrics
|
|
209
|
+
this.updateControlMetrics(latencyMs);
|
|
210
|
+
this.metrics.totalInjections++;
|
|
211
|
+
const result = {
|
|
212
|
+
success: true,
|
|
213
|
+
commandId: command.id,
|
|
214
|
+
agentId: targetAgentId,
|
|
215
|
+
level: targetLevel,
|
|
216
|
+
latencyMs
|
|
217
|
+
};
|
|
218
|
+
if (this.config.enableLogging) {
|
|
219
|
+
this.logger.info('Command injected', {
|
|
220
|
+
commandId: command.id,
|
|
221
|
+
commandType,
|
|
222
|
+
parentAgentId,
|
|
223
|
+
targetAgentId,
|
|
224
|
+
level: targetLevel,
|
|
225
|
+
latencyMs,
|
|
226
|
+
immediate
|
|
227
|
+
});
|
|
228
|
+
}
|
|
229
|
+
this.emit('command:injected', {
|
|
230
|
+
command,
|
|
231
|
+
result
|
|
232
|
+
});
|
|
233
|
+
return result;
|
|
234
|
+
} catch (error) {
|
|
235
|
+
const latencyMs = Date.now() - startTime;
|
|
236
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
237
|
+
this.logger.error('Failed to inject command', {
|
|
238
|
+
parentAgentId,
|
|
239
|
+
targetAgentId,
|
|
240
|
+
commandType,
|
|
241
|
+
error: errorMessage
|
|
242
|
+
});
|
|
243
|
+
return {
|
|
244
|
+
success: false,
|
|
245
|
+
commandId: '',
|
|
246
|
+
agentId: targetAgentId,
|
|
247
|
+
level: this.getAgentLevel(targetAgentId),
|
|
248
|
+
latencyMs,
|
|
249
|
+
error: errorMessage
|
|
250
|
+
};
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
/**
|
|
254
|
+
* Resume agent from Level 0 parent
|
|
255
|
+
*
|
|
256
|
+
* Applies all queued commands and resumes agent execution.
|
|
257
|
+
*
|
|
258
|
+
* @param parentAgentId - Parent issuing the resume
|
|
259
|
+
* @param targetAgentId - Child agent to resume
|
|
260
|
+
* @param checkpointId - Optional checkpoint to resume from
|
|
261
|
+
* @returns Control operation result
|
|
262
|
+
*/ async resumeChildAgent(parentAgentId, targetAgentId, checkpointId) {
|
|
263
|
+
const startTime = Date.now();
|
|
264
|
+
try {
|
|
265
|
+
const targetLevel = this.getAgentLevel(targetAgentId);
|
|
266
|
+
// Apply queued commands before resume
|
|
267
|
+
const queuedCommands = this.getQueuedCommands(targetAgentId);
|
|
268
|
+
if (queuedCommands.length > 0) {
|
|
269
|
+
const session = await this.queryController.getAgentSession(targetAgentId);
|
|
270
|
+
for (const command of queuedCommands){
|
|
271
|
+
await this.applyCommandToSession(session, command);
|
|
272
|
+
}
|
|
273
|
+
// Clear command queue
|
|
274
|
+
this.clearCommandQueue(targetAgentId);
|
|
275
|
+
if (this.config.enableLogging) {
|
|
276
|
+
this.logger.debug('Applied queued commands before resume', {
|
|
277
|
+
agentId: targetAgentId,
|
|
278
|
+
commandCount: queuedCommands.length
|
|
279
|
+
});
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
// Resume agent via QueryController
|
|
283
|
+
await this.queryController.resumeAgent(targetAgentId, checkpointId);
|
|
284
|
+
const latencyMs = Date.now() - startTime;
|
|
285
|
+
// Update metrics
|
|
286
|
+
this.updateControlMetrics(latencyMs);
|
|
287
|
+
this.metrics.totalResumes++;
|
|
288
|
+
const result = {
|
|
289
|
+
operation: 'resume',
|
|
290
|
+
success: true,
|
|
291
|
+
agentId: targetAgentId,
|
|
292
|
+
level: targetLevel,
|
|
293
|
+
latencyMs,
|
|
294
|
+
data: {
|
|
295
|
+
parentAgentId,
|
|
296
|
+
checkpointId,
|
|
297
|
+
appliedCommands: queuedCommands.length
|
|
298
|
+
}
|
|
299
|
+
};
|
|
300
|
+
if (this.config.enableLogging) {
|
|
301
|
+
this.logger.info('Agent resumed from parent', {
|
|
302
|
+
parentAgentId,
|
|
303
|
+
targetAgentId,
|
|
304
|
+
level: targetLevel,
|
|
305
|
+
latencyMs,
|
|
306
|
+
appliedCommands: queuedCommands.length
|
|
307
|
+
});
|
|
308
|
+
}
|
|
309
|
+
this.emit('agent:resumed', result);
|
|
310
|
+
return result;
|
|
311
|
+
} catch (error) {
|
|
312
|
+
const latencyMs = Date.now() - startTime;
|
|
313
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
314
|
+
this.logger.error('Failed to resume child agent', {
|
|
315
|
+
parentAgentId,
|
|
316
|
+
targetAgentId,
|
|
317
|
+
error: errorMessage
|
|
318
|
+
});
|
|
319
|
+
return {
|
|
320
|
+
operation: 'resume',
|
|
321
|
+
success: false,
|
|
322
|
+
agentId: targetAgentId,
|
|
323
|
+
level: this.getAgentLevel(targetAgentId),
|
|
324
|
+
latencyMs,
|
|
325
|
+
error: errorMessage
|
|
326
|
+
};
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
/**
|
|
330
|
+
* Cascade control operation to all descendants
|
|
331
|
+
*
|
|
332
|
+
* Propagates pause/resume down the hierarchy tree.
|
|
333
|
+
*
|
|
334
|
+
* @param parentAgentId - Root parent issuing cascade
|
|
335
|
+
* @param operation - Operation to cascade
|
|
336
|
+
* @returns Array of control operation results
|
|
337
|
+
*/ async cascadeControlOperation(parentAgentId, operation) {
|
|
338
|
+
const results = [];
|
|
339
|
+
if (!this.hierarchicalCoordinator) {
|
|
340
|
+
this.logger.warn('Cannot cascade without hierarchical coordinator');
|
|
341
|
+
return results;
|
|
342
|
+
}
|
|
343
|
+
const parentAgent = this.hierarchicalCoordinator.getAgentStatus(parentAgentId);
|
|
344
|
+
if (!parentAgent) {
|
|
345
|
+
this.logger.warn('Parent agent not found in hierarchy', {
|
|
346
|
+
parentAgentId
|
|
347
|
+
});
|
|
348
|
+
return results;
|
|
349
|
+
}
|
|
350
|
+
// Get all descendants (DFS traversal)
|
|
351
|
+
const descendants = await this.getAllDescendants(parentAgentId);
|
|
352
|
+
if (this.config.enableLogging) {
|
|
353
|
+
this.logger.info('Cascading control operation', {
|
|
354
|
+
parentAgentId,
|
|
355
|
+
operation,
|
|
356
|
+
descendantCount: descendants.length
|
|
357
|
+
});
|
|
358
|
+
}
|
|
359
|
+
// Apply operation to all descendants in parallel
|
|
360
|
+
const operations = descendants.map(async (descendantId)=>{
|
|
361
|
+
if (operation === 'pause') {
|
|
362
|
+
return await this.pauseChildAgent(parentAgentId, descendantId, `Cascaded from ${parentAgentId}`);
|
|
363
|
+
} else {
|
|
364
|
+
return await this.resumeChildAgent(parentAgentId, descendantId);
|
|
365
|
+
}
|
|
366
|
+
});
|
|
367
|
+
results.push(...await Promise.all(operations));
|
|
368
|
+
this.emit('control:cascaded', {
|
|
369
|
+
parentAgentId,
|
|
370
|
+
operation,
|
|
371
|
+
results
|
|
372
|
+
});
|
|
373
|
+
return results;
|
|
374
|
+
}
|
|
375
|
+
// ============================================================================
|
|
376
|
+
// Command Queue Management
|
|
377
|
+
// ============================================================================
|
|
378
|
+
/**
|
|
379
|
+
* Queue command for paused agent
|
|
380
|
+
*/ queueCommand(agentId, command) {
|
|
381
|
+
let queue = this.commandQueues.get(agentId);
|
|
382
|
+
if (!queue) {
|
|
383
|
+
queue = [];
|
|
384
|
+
this.commandQueues.set(agentId, queue);
|
|
385
|
+
}
|
|
386
|
+
// Enforce max queue size
|
|
387
|
+
if (queue.length >= this.config.maxQueuedCommands) {
|
|
388
|
+
this.logger.warn('Command queue full, removing oldest command', {
|
|
389
|
+
agentId,
|
|
390
|
+
maxQueueSize: this.config.maxQueuedCommands
|
|
391
|
+
});
|
|
392
|
+
queue.shift();
|
|
393
|
+
}
|
|
394
|
+
queue.push(command);
|
|
395
|
+
}
|
|
396
|
+
/**
|
|
397
|
+
* Get queued commands for agent
|
|
398
|
+
*/ getQueuedCommands(agentId) {
|
|
399
|
+
return this.commandQueues.get(agentId) ?? [];
|
|
400
|
+
}
|
|
401
|
+
/**
|
|
402
|
+
* Clear command queue for agent
|
|
403
|
+
*/ clearCommandQueue(agentId) {
|
|
404
|
+
this.commandQueues.delete(agentId);
|
|
405
|
+
}
|
|
406
|
+
/**
|
|
407
|
+
* Apply command to agent session
|
|
408
|
+
*/ async applyCommandToSession(session, command) {
|
|
409
|
+
// Store command in session metadata for agent to process
|
|
410
|
+
if (!session.metadata.injectedCommands) {
|
|
411
|
+
session.metadata.injectedCommands = [];
|
|
412
|
+
}
|
|
413
|
+
session.metadata.injectedCommands.push({
|
|
414
|
+
commandId: command.id,
|
|
415
|
+
type: command.type,
|
|
416
|
+
payload: command.payload,
|
|
417
|
+
issuedBy: command.issuedBy,
|
|
418
|
+
timestamp: command.timestamp
|
|
419
|
+
});
|
|
420
|
+
// Apply command effects based on type
|
|
421
|
+
switch(command.type){
|
|
422
|
+
case "state_update":
|
|
423
|
+
if (command.payload.state) {
|
|
424
|
+
session.state = command.payload.state;
|
|
425
|
+
}
|
|
426
|
+
break;
|
|
427
|
+
case "priority_update":
|
|
428
|
+
if (command.payload.priority !== undefined) {
|
|
429
|
+
session.priority = command.payload.priority;
|
|
430
|
+
}
|
|
431
|
+
break;
|
|
432
|
+
case "metadata_update":
|
|
433
|
+
if (command.payload.metadata) {
|
|
434
|
+
session.metadata = {
|
|
435
|
+
...session.metadata,
|
|
436
|
+
...command.payload.metadata
|
|
437
|
+
};
|
|
438
|
+
}
|
|
439
|
+
break;
|
|
440
|
+
case "task_update":
|
|
441
|
+
case "custom":
|
|
442
|
+
break;
|
|
443
|
+
default:
|
|
444
|
+
this.logger.warn('Unknown command type', {
|
|
445
|
+
type: command.type
|
|
446
|
+
});
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
// ============================================================================
|
|
450
|
+
// Hierarchy Traversal Helpers
|
|
451
|
+
// ============================================================================
|
|
452
|
+
/**
|
|
453
|
+
* Get all descendants of an agent (DFS)
|
|
454
|
+
*/ async getAllDescendants(agentId) {
|
|
455
|
+
const descendants = [];
|
|
456
|
+
if (!this.hierarchicalCoordinator) {
|
|
457
|
+
return descendants;
|
|
458
|
+
}
|
|
459
|
+
const agent = this.hierarchicalCoordinator.getAgentStatus(agentId);
|
|
460
|
+
if (!agent) {
|
|
461
|
+
return descendants;
|
|
462
|
+
}
|
|
463
|
+
// DFS traversal
|
|
464
|
+
const stack = [
|
|
465
|
+
...agent.childIds
|
|
466
|
+
];
|
|
467
|
+
while(stack.length > 0){
|
|
468
|
+
const childId = stack.pop();
|
|
469
|
+
descendants.push(childId);
|
|
470
|
+
const child = this.hierarchicalCoordinator.getAgentStatus(childId);
|
|
471
|
+
if (child && child.childIds.length > 0) {
|
|
472
|
+
stack.push(...child.childIds);
|
|
473
|
+
}
|
|
474
|
+
}
|
|
475
|
+
return descendants;
|
|
476
|
+
}
|
|
477
|
+
// ============================================================================
|
|
478
|
+
// Metrics and Monitoring
|
|
479
|
+
// ============================================================================
|
|
480
|
+
/**
|
|
481
|
+
* Update control operation metrics
|
|
482
|
+
*/ updateControlMetrics(latencyMs) {
|
|
483
|
+
const totalOps = this.metrics.totalPauses + this.metrics.totalInjections + this.metrics.totalResumes;
|
|
484
|
+
this.metrics.averageControlLatencyMs = (this.metrics.averageControlLatencyMs * totalOps + latencyMs) / (totalOps + 1);
|
|
485
|
+
this.metrics.maxControlLatencyMs = Math.max(this.metrics.maxControlLatencyMs, latencyMs);
|
|
486
|
+
// Warn if exceeding latency target
|
|
487
|
+
if (latencyMs > this.config.maxControlLatencyMs) {
|
|
488
|
+
this.logger.warn('Control operation exceeded latency target', {
|
|
489
|
+
latencyMs,
|
|
490
|
+
targetMs: this.config.maxControlLatencyMs
|
|
491
|
+
});
|
|
492
|
+
}
|
|
493
|
+
}
|
|
494
|
+
/**
|
|
495
|
+
* Get control operation metrics
|
|
496
|
+
*/ getMetrics() {
|
|
497
|
+
return {
|
|
498
|
+
...this.metrics,
|
|
499
|
+
latencyTargetMs: this.config.maxControlLatencyMs,
|
|
500
|
+
withinTarget: this.metrics.averageControlLatencyMs <= this.config.maxControlLatencyMs
|
|
501
|
+
};
|
|
502
|
+
}
|
|
503
|
+
/**
|
|
504
|
+
* Get queued commands count for agent
|
|
505
|
+
*/ getQueuedCommandsCount(agentId) {
|
|
506
|
+
return this.commandQueues.get(agentId)?.length ?? 0;
|
|
507
|
+
}
|
|
508
|
+
/**
|
|
509
|
+
* Cleanup - clear all queues and caches
|
|
510
|
+
*/ async cleanup() {
|
|
511
|
+
this.commandQueues.clear();
|
|
512
|
+
this.agentLevelCache.clear();
|
|
513
|
+
this.removeAllListeners();
|
|
514
|
+
this.logger.info('MultiLevelController cleaned up');
|
|
515
|
+
}
|
|
516
|
+
// ============================================================================
|
|
517
|
+
// Private Helpers
|
|
518
|
+
// ============================================================================
|
|
519
|
+
initializeMetrics() {
|
|
520
|
+
return {
|
|
521
|
+
totalPauses: 0,
|
|
522
|
+
totalInjections: 0,
|
|
523
|
+
totalResumes: 0,
|
|
524
|
+
averageControlLatencyMs: 0,
|
|
525
|
+
maxControlLatencyMs: 0
|
|
526
|
+
};
|
|
527
|
+
}
|
|
528
|
+
}
|
|
529
|
+
// ============================================================================
|
|
530
|
+
// Factory Functions
|
|
531
|
+
// ============================================================================
|
|
532
|
+
/**
|
|
533
|
+
* Create multi-level controller with QueryController
|
|
534
|
+
*/ export function createMultiLevelController(queryController, config) {
|
|
535
|
+
return new MultiLevelController(queryController, config);
|
|
536
|
+
}
|
|
537
|
+
/**
|
|
538
|
+
* Create multi-level controller with hierarchical coordinator integration
|
|
539
|
+
*/ export function createMultiLevelControllerWithHierarchy(queryController, hierarchicalCoordinator, config) {
|
|
540
|
+
const controller = new MultiLevelController(queryController, config);
|
|
541
|
+
controller.registerHierarchicalCoordinator(hierarchicalCoordinator);
|
|
542
|
+
return controller;
|
|
543
|
+
} // Types are already exported inline above - no duplicate export needed
|
|
544
|
+
|
|
545
|
+
//# sourceMappingURL=multi-level-control.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../../src/coordination/v2/sdk/multi-level-control.ts"],"names":["EventEmitter","Logger","generateId","InjectedCommandType","MultiLevelController","logger","config","queryController","hierarchicalCoordinator","commandQueues","agentLevelCache","metrics","level","format","destination","maxControlLatencyMs","enableCommandQueue","maxQueuedCommands","enableLogging","Map","initializeMetrics","info","registerHierarchicalCoordinator","coordinator","getHierarchyStructure","hierarchy","agent","agents","set","id","totalAgents","length","hierarchyDepth","depth","updateAgentLevel","agentId","getAgentLevel","cachedLevel","get","undefined","agentStatus","getAgentStatus","pauseChildAgent","parentAgentId","targetAgentId","reason","startTime","Date","now","targetLevel","pauseAgent","latencyMs","updateControlMetrics","totalPauses","result","operation","success","data","emit","error","errorMessage","Error","message","String","injectCommand","commandType","payload","immediate","session","getAgentSession","isPaused","command","type","issuedBy","timestamp","queueCommand","applyCommandToSession","totalInjections","commandId","resumeChildAgent","checkpointId","queuedCommands","getQueuedCommands","clearCommandQueue","debug","commandCount","resumeAgent","totalResumes","appliedCommands","cascadeControlOperation","results","warn","parentAgent","descendants","getAllDescendants","descendantCount","operations","map","descendantId","push","Promise","all","queue","maxQueueSize","shift","delete","metadata","injectedCommands","state","priority","stack","childIds","childId","pop","child","totalOps","averageControlLatencyMs","Math","max","targetMs","getMetrics","latencyTargetMs","withinTarget","getQueuedCommandsCount","cleanup","clear","removeAllListeners","createMultiLevelController","createMultiLevelControllerWithHierarchy","controller"],"mappings":"AAAA;;;;;;;;;;CAUC,GAED,SAASA,YAAY,QAAQ,cAAc;AAC3C,SAASC,MAAM,QAAQ,0BAA0B;AACjD,SAASC,UAAU,QAAQ,4BAA4B;AAKvD,+EAA+E;AAC/E,uBAAuB;AACvB,+EAA+E;AAE/E;;CAEC,GACD,OAAO,IAAA,AAAKC,6CAAAA;IACV,gCAAgC;IAEhC,6BAA6B;IAE7B,0BAA0B;IAE1B,0BAA0B;IAE1B,0CAA0C;WAThCA;MAWX;AA4ED,+EAA+E;AAC/E,wCAAwC;AACxC,+EAA+E;AAE/E;;;;;;;;;CASC,GACD,OAAO,MAAMC,6BAA6BJ;IACvBK,OAAe;IACfC,OAA0C;IAEnDC,gBAAiC;IACjCC,wBAAkD;IAE1D,sCAAsC,GACtC,AAAQC,cAA8C;IAEtD,uCAAuC,GACvC,AAAQC,gBAAqC;IAE7C,8BAA8B,GAC9B,AAAQC,QAMN;IAEF,YACEJ,eAAgC,EAChCD,SAA2C,CAAC,CAAC,CAC7C;QACA,KAAK;QAEL,IAAI,CAACD,MAAM,GAAG,IAAIJ,OAAO;YACvBW,OAAO;YACPC,QAAQ;YACRC,aAAa;QACf;QAEA,IAAI,CAACR,MAAM,GAAG;YACZS,qBAAqB;YACrBC,oBAAoB;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
8
|
import { Logger } from '../../../core/logger.js';
|
|
9
9
|
import { generateId } from '../../../utils/helpers.js';
|
|
10
|
+
import { HelpCoordinator } from '../help-system/help-coordinator.js';
|
|
11
|
+
import { AgentState as AgentStateEnum } from '../core/agent-state.js';
|
|
10
12
|
/**
|
|
11
13
|
* QueryController - Manages agent lifecycle with zero-cost pause/resume
|
|
12
14
|
*
|
|
@@ -27,6 +29,7 @@ import { generateId } from '../../../utils/helpers.js';
|
|
|
27
29
|
coordinatorMetrics;
|
|
28
30
|
ready;
|
|
29
31
|
startTime;
|
|
32
|
+
/** Help coordinator for agent helper registration */ helpCoordinator;
|
|
30
33
|
constructor(config = {}){
|
|
31
34
|
super();
|
|
32
35
|
this.logger = new Logger({
|
|
@@ -49,6 +52,8 @@ import { generateId } from '../../../utils/helpers.js';
|
|
|
49
52
|
this.coordinatorMetrics = this.initializeCoordinatorMetrics();
|
|
50
53
|
this.ready = false;
|
|
51
54
|
this.startTime = Date.now();
|
|
55
|
+
// Initialize help coordinator for agent helper registration
|
|
56
|
+
this.helpCoordinator = new HelpCoordinator();
|
|
52
57
|
this.logger.info('QueryController initialized', {
|
|
53
58
|
maxConcurrentAgents: this.config.maxConcurrentAgents,
|
|
54
59
|
enableDynamicAllocation: this.config.enableDynamicAllocation
|
|
@@ -363,12 +368,19 @@ import { generateId } from '../../../utils/helpers.js';
|
|
|
363
368
|
}
|
|
364
369
|
}
|
|
365
370
|
/**
|
|
371
|
+
* Get help coordinator instance for external access
|
|
372
|
+
*/ getHelpCoordinator() {
|
|
373
|
+
return this.helpCoordinator;
|
|
374
|
+
}
|
|
375
|
+
/**
|
|
366
376
|
* Cleanup - terminate all sessions
|
|
367
377
|
*/ async cleanup() {
|
|
368
378
|
this.logger.info('Cleaning up query controller', {
|
|
369
379
|
totalSessions: this.sessions.size,
|
|
370
380
|
pausedAgents: this.getPausedSessions().length
|
|
371
381
|
});
|
|
382
|
+
// Clear help coordinator
|
|
383
|
+
this.helpCoordinator.clear();
|
|
372
384
|
this.sessions.clear();
|
|
373
385
|
this.checkpoints.clear();
|
|
374
386
|
this.resourceAllocations.clear();
|
|
@@ -421,6 +433,23 @@ import { generateId } from '../../../utils/helpers.js';
|
|
|
421
433
|
};
|
|
422
434
|
// Store agent
|
|
423
435
|
this.agents.set(agentId, agent);
|
|
436
|
+
// Register as helper if capabilities provided
|
|
437
|
+
if (config.metadata?.capabilities && Array.isArray(config.metadata.capabilities)) {
|
|
438
|
+
const agentProfile = {
|
|
439
|
+
agentId,
|
|
440
|
+
type: config.type,
|
|
441
|
+
state: agent.state,
|
|
442
|
+
capabilities: config.metadata.capabilities,
|
|
443
|
+
priority,
|
|
444
|
+
workload: 0.0,
|
|
445
|
+
metadata: config.metadata
|
|
446
|
+
};
|
|
447
|
+
this.helpCoordinator.registerAgent(agentProfile);
|
|
448
|
+
this.logger.debug('Agent registered as helper', {
|
|
449
|
+
agentId,
|
|
450
|
+
capabilities: config.metadata.capabilities.map((c)=>c.name)
|
|
451
|
+
});
|
|
452
|
+
}
|
|
424
453
|
// Update coordinator metrics
|
|
425
454
|
this.coordinatorMetrics.totalAgentsSpawned++;
|
|
426
455
|
this.coordinatorMetrics.activeAgents++;
|
|
@@ -450,6 +479,8 @@ import { generateId } from '../../../utils/helpers.js';
|
|
|
450
479
|
await this.interrupt(agent.sessionId, reason ?? 'Manual pause');
|
|
451
480
|
// Update agent state
|
|
452
481
|
agent.isPaused = true;
|
|
482
|
+
// Update help coordinator state
|
|
483
|
+
this.helpCoordinator.updateAgentState(agentId, AgentStateEnum.PAUSED);
|
|
453
484
|
// Update coordinator metrics
|
|
454
485
|
this.coordinatorMetrics.activeAgents--;
|
|
455
486
|
this.coordinatorMetrics.pausedAgents++;
|
|
@@ -471,6 +502,8 @@ import { generateId } from '../../../utils/helpers.js';
|
|
|
471
502
|
await this.resumeSessionAt(agent.sessionId, messageUUID, 'Resume from coordinator');
|
|
472
503
|
// Update agent state
|
|
473
504
|
agent.isPaused = false;
|
|
505
|
+
// Update help coordinator state (resumed agents go to IDLE or WORKING)
|
|
506
|
+
this.helpCoordinator.updateAgentState(agentId, agent.state);
|
|
474
507
|
// Update coordinator metrics
|
|
475
508
|
this.coordinatorMetrics.pausedAgents--;
|
|
476
509
|
this.coordinatorMetrics.activeAgents++;
|
|
@@ -486,6 +519,11 @@ import { generateId } from '../../../utils/helpers.js';
|
|
|
486
519
|
if (!agent.isPaused) {
|
|
487
520
|
await this.createCheckpoint(agentId, `Termination: ${reason ?? 'Manual termination'}`);
|
|
488
521
|
}
|
|
522
|
+
// Unregister helper if registered
|
|
523
|
+
this.helpCoordinator.unregisterAgent(agentId);
|
|
524
|
+
this.logger.debug('Agent unregistered from help coordinator', {
|
|
525
|
+
agentId
|
|
526
|
+
});
|
|
489
527
|
// Remove agent
|
|
490
528
|
this.agents.delete(agentId);
|
|
491
529
|
// Remove session
|
|
@@ -661,6 +699,12 @@ import { generateId } from '../../../utils/helpers.js';
|
|
|
661
699
|
this.updateTokenUsageInternal(agentId, tokensUsed);
|
|
662
700
|
// Update coordinator metrics
|
|
663
701
|
this.coordinatorMetrics.totalTokensUsed += tokensUsed;
|
|
702
|
+
// Update help coordinator workload (tokens used / budget)
|
|
703
|
+
const allocation = this.resourceAllocations.get(agentId);
|
|
704
|
+
if (allocation) {
|
|
705
|
+
const workload = Math.min(1.0, allocation.currentUsage / allocation.tokenBudget);
|
|
706
|
+
this.helpCoordinator.updateAgentWorkload(agentId, workload);
|
|
707
|
+
}
|
|
664
708
|
}
|
|
665
709
|
// ===========================
|
|
666
710
|
// Private Helpers
|