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,679 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Agent Transparency System Implementation
|
|
3
|
+
*
|
|
4
|
+
* Core transparency system providing real-time monitoring, event streaming,
|
|
5
|
+
* and hierarchy visualization for V2 multi-level agent coordination.
|
|
6
|
+
*
|
|
7
|
+
* @module coordination/v2/transparency/transparency-system
|
|
8
|
+
*/ import { EventEmitter } from 'events';
|
|
9
|
+
import { v4 as uuidv4 } from 'uuid';
|
|
10
|
+
import { Logger } from '../../../core/logger.js';
|
|
11
|
+
/**
|
|
12
|
+
* Transparency System Implementation
|
|
13
|
+
*
|
|
14
|
+
* Provides comprehensive visibility into multi-level agent operations:
|
|
15
|
+
* - Real-time agent hierarchy tracking
|
|
16
|
+
* - Agent lifecycle event streaming
|
|
17
|
+
* - Performance monitoring and alerting
|
|
18
|
+
* - Resource allocation transparency
|
|
19
|
+
*/ export class TransparencySystem extends EventEmitter {
|
|
20
|
+
logger = new Logger({
|
|
21
|
+
level: 'info',
|
|
22
|
+
format: 'text',
|
|
23
|
+
destination: 'console'
|
|
24
|
+
});
|
|
25
|
+
config;
|
|
26
|
+
isInitialized = false;
|
|
27
|
+
isMonitoring = false;
|
|
28
|
+
// Agent tracking
|
|
29
|
+
agentHierarchy = new Map();
|
|
30
|
+
agentStatuses = new Map();
|
|
31
|
+
agentPerformanceMetrics = new Map();
|
|
32
|
+
// Event storage
|
|
33
|
+
lifecycleEvents = [];
|
|
34
|
+
eventListeners = new Set();
|
|
35
|
+
// Monitoring intervals
|
|
36
|
+
metricsUpdateInterval;
|
|
37
|
+
heartbeatInterval;
|
|
38
|
+
// Performance tracking
|
|
39
|
+
performanceThresholds = {
|
|
40
|
+
maxExecutionTimeMs: 300000,
|
|
41
|
+
maxMemoryUsage: 512 * 1024 * 1024,
|
|
42
|
+
maxTokenUsageRate: 100,
|
|
43
|
+
maxPauseLatencyMs: 50,
|
|
44
|
+
maxCpuUsage: 80
|
|
45
|
+
};
|
|
46
|
+
constructor(){
|
|
47
|
+
super();
|
|
48
|
+
this.config = this.getDefaultConfig();
|
|
49
|
+
}
|
|
50
|
+
// ===========================
|
|
51
|
+
// System Lifecycle
|
|
52
|
+
// ===========================
|
|
53
|
+
async initialize(config = {}) {
|
|
54
|
+
if (this.isInitialized) {
|
|
55
|
+
this.logger.warn('TransparencySystem already initialized');
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
this.config = {
|
|
59
|
+
...this.getDefaultConfig(),
|
|
60
|
+
...config
|
|
61
|
+
};
|
|
62
|
+
this.logger.info('Initializing TransparencySystem', this.config);
|
|
63
|
+
// Initialize event storage
|
|
64
|
+
this.lifecycleEvents = [];
|
|
65
|
+
this.agentHierarchy.clear();
|
|
66
|
+
this.agentStatuses.clear();
|
|
67
|
+
this.agentPerformanceMetrics.clear();
|
|
68
|
+
this.isInitialized = true;
|
|
69
|
+
this.emit('initialized');
|
|
70
|
+
this.logger.info('TransparencySystem initialized successfully');
|
|
71
|
+
}
|
|
72
|
+
async startMonitoring() {
|
|
73
|
+
if (!this.isInitialized) {
|
|
74
|
+
throw new Error('TransparencySystem not initialized');
|
|
75
|
+
}
|
|
76
|
+
if (this.isMonitoring) {
|
|
77
|
+
this.logger.warn('TransparencySystem monitoring already started');
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
this.logger.info('Starting transparency monitoring');
|
|
81
|
+
// Start metrics update interval
|
|
82
|
+
this.metricsUpdateInterval = setInterval(()=>this.updateMetrics(), this.config.metricsUpdateIntervalMs);
|
|
83
|
+
// Start heartbeat monitoring
|
|
84
|
+
this.heartbeatInterval = setInterval(()=>this.checkAgentHeartbeats(), this.config.heartbeatIntervalMs);
|
|
85
|
+
this.isMonitoring = true;
|
|
86
|
+
this.emit('monitoringStarted');
|
|
87
|
+
this.logger.info('Transparency monitoring started');
|
|
88
|
+
}
|
|
89
|
+
async stopMonitoring() {
|
|
90
|
+
if (!this.isMonitoring) {
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
this.logger.info('Stopping transparency monitoring');
|
|
94
|
+
// Clear intervals
|
|
95
|
+
if (this.metricsUpdateInterval) {
|
|
96
|
+
clearInterval(this.metricsUpdateInterval);
|
|
97
|
+
this.metricsUpdateInterval = undefined;
|
|
98
|
+
}
|
|
99
|
+
if (this.heartbeatInterval) {
|
|
100
|
+
clearInterval(this.heartbeatInterval);
|
|
101
|
+
this.heartbeatInterval = undefined;
|
|
102
|
+
}
|
|
103
|
+
this.isMonitoring = false;
|
|
104
|
+
this.emit('monitoringStopped');
|
|
105
|
+
this.logger.info('Transparency monitoring stopped');
|
|
106
|
+
}
|
|
107
|
+
async cleanup() {
|
|
108
|
+
this.logger.info('Cleaning up TransparencySystem');
|
|
109
|
+
await this.stopMonitoring();
|
|
110
|
+
// Clear all data
|
|
111
|
+
this.lifecycleEvents = [];
|
|
112
|
+
this.agentHierarchy.clear();
|
|
113
|
+
this.agentStatuses.clear();
|
|
114
|
+
this.agentPerformanceMetrics.clear();
|
|
115
|
+
this.eventListeners.clear();
|
|
116
|
+
this.removeAllListeners();
|
|
117
|
+
this.isInitialized = false;
|
|
118
|
+
this.logger.info('TransparencySystem cleanup complete');
|
|
119
|
+
}
|
|
120
|
+
// ===========================
|
|
121
|
+
// Agent Registration & Tracking
|
|
122
|
+
// ===========================
|
|
123
|
+
/**
|
|
124
|
+
* Register agent with transparency system
|
|
125
|
+
*
|
|
126
|
+
* Called when agent is spawned in coordinator
|
|
127
|
+
*/ registerAgent(agent, parentAgentId) {
|
|
128
|
+
const hierarchyNode = {
|
|
129
|
+
agentId: agent.agentId,
|
|
130
|
+
type: agent.type,
|
|
131
|
+
level: this.calculateAgentLevel(agent.agentId, parentAgentId),
|
|
132
|
+
parentAgentId,
|
|
133
|
+
childAgentIds: [],
|
|
134
|
+
priority: agent.priority,
|
|
135
|
+
state: agent.state,
|
|
136
|
+
sessionId: agent.sessionId,
|
|
137
|
+
createdAt: new Date(),
|
|
138
|
+
lastStateChange: new Date(),
|
|
139
|
+
tokensUsed: 0,
|
|
140
|
+
tokenBudget: agent.metadata.tokenBudget || 10000,
|
|
141
|
+
isPaused: agent.isPaused,
|
|
142
|
+
metadata: agent.metadata,
|
|
143
|
+
metrics: {
|
|
144
|
+
spawnTimeMs: 0,
|
|
145
|
+
totalExecutionTimeMs: 0,
|
|
146
|
+
pauseCount: 0,
|
|
147
|
+
resumeCount: 0,
|
|
148
|
+
checkpointCount: 0
|
|
149
|
+
},
|
|
150
|
+
currentTask: undefined,
|
|
151
|
+
waitingFor: [],
|
|
152
|
+
completedDependencies: []
|
|
153
|
+
};
|
|
154
|
+
this.agentHierarchy.set(agent.agentId, hierarchyNode);
|
|
155
|
+
// Initialize agent status
|
|
156
|
+
const status = {
|
|
157
|
+
agentId: agent.agentId,
|
|
158
|
+
state: agent.state,
|
|
159
|
+
isPaused: agent.isPaused,
|
|
160
|
+
activity: 'Spawned',
|
|
161
|
+
progress: 0,
|
|
162
|
+
tokensUsed: 0,
|
|
163
|
+
tokenUsageRate: 0,
|
|
164
|
+
memoryUsage: 0,
|
|
165
|
+
cpuUsage: 0,
|
|
166
|
+
lastHeartbeat: new Date(),
|
|
167
|
+
recentErrors: []
|
|
168
|
+
};
|
|
169
|
+
this.agentStatuses.set(agent.agentId, status);
|
|
170
|
+
// Update parent's child list
|
|
171
|
+
if (parentAgentId && this.agentHierarchy.has(parentAgentId)) {
|
|
172
|
+
const parent = this.agentHierarchy.get(parentAgentId);
|
|
173
|
+
parent.childAgentIds.push(agent.agentId);
|
|
174
|
+
}
|
|
175
|
+
// Record lifecycle event
|
|
176
|
+
this.recordLifecycleEvent({
|
|
177
|
+
eventId: uuidv4(),
|
|
178
|
+
timestamp: new Date(),
|
|
179
|
+
agentId: agent.agentId,
|
|
180
|
+
eventType: 'spawned',
|
|
181
|
+
eventData: {
|
|
182
|
+
metadata: agent.metadata
|
|
183
|
+
},
|
|
184
|
+
level: hierarchyNode.level,
|
|
185
|
+
parentAgentId,
|
|
186
|
+
sessionId: agent.sessionId,
|
|
187
|
+
tokensUsed: 0,
|
|
188
|
+
performanceImpact: {}
|
|
189
|
+
});
|
|
190
|
+
this.emit('agentRegistered', {
|
|
191
|
+
agentId: agent.agentId,
|
|
192
|
+
hierarchyNode
|
|
193
|
+
});
|
|
194
|
+
this.notifyHierarchyChange('agent_added', agent.agentId, hierarchyNode);
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* Update agent state
|
|
198
|
+
*
|
|
199
|
+
* Called when agent state changes
|
|
200
|
+
*/ updateAgentState(agentId, newState, reason) {
|
|
201
|
+
const hierarchyNode = this.agentHierarchy.get(agentId);
|
|
202
|
+
const status = this.agentStatuses.get(agentId);
|
|
203
|
+
if (!hierarchyNode || !status) {
|
|
204
|
+
this.logger.warn(`Agent ${agentId} not found in transparency tracking`);
|
|
205
|
+
return;
|
|
206
|
+
}
|
|
207
|
+
const previousState = hierarchyNode.state;
|
|
208
|
+
hierarchyNode.state = newState;
|
|
209
|
+
hierarchyNode.lastStateChange = new Date();
|
|
210
|
+
status.state = newState;
|
|
211
|
+
// Update activity based on state
|
|
212
|
+
status.activity = this.getActivityForState(newState, reason);
|
|
213
|
+
// Record lifecycle event
|
|
214
|
+
this.recordLifecycleEvent({
|
|
215
|
+
eventId: uuidv4(),
|
|
216
|
+
timestamp: new Date(),
|
|
217
|
+
agentId,
|
|
218
|
+
eventType: 'state_changed',
|
|
219
|
+
eventData: {
|
|
220
|
+
previousState,
|
|
221
|
+
newState,
|
|
222
|
+
reason
|
|
223
|
+
},
|
|
224
|
+
level: hierarchyNode.level,
|
|
225
|
+
parentAgentId: hierarchyNode.parentAgentId,
|
|
226
|
+
sessionId: hierarchyNode.sessionId,
|
|
227
|
+
tokensUsed: hierarchyNode.tokensUsed,
|
|
228
|
+
performanceImpact: {}
|
|
229
|
+
});
|
|
230
|
+
this.emit('agentStateChanged', {
|
|
231
|
+
agentId,
|
|
232
|
+
previousState,
|
|
233
|
+
newState
|
|
234
|
+
});
|
|
235
|
+
this.notifyStateChange(agentId, previousState, newState);
|
|
236
|
+
}
|
|
237
|
+
/**
|
|
238
|
+
* Update agent token usage
|
|
239
|
+
*
|
|
240
|
+
* Called when agent consumes tokens
|
|
241
|
+
*/ updateTokenUsage(agentId, tokensUsed) {
|
|
242
|
+
const hierarchyNode = this.agentHierarchy.get(agentId);
|
|
243
|
+
const status = this.agentStatuses.get(agentId);
|
|
244
|
+
if (!hierarchyNode || !status) {
|
|
245
|
+
return;
|
|
246
|
+
}
|
|
247
|
+
const previousTokens = hierarchyNode.tokensUsed;
|
|
248
|
+
hierarchyNode.tokensUsed = tokensUsed;
|
|
249
|
+
status.tokensUsed = tokensUsed;
|
|
250
|
+
// Calculate token usage rate
|
|
251
|
+
const timeDelta = Date.now() - status.lastHeartbeat.getTime();
|
|
252
|
+
if (timeDelta > 0) {
|
|
253
|
+
status.tokenUsageRate = (tokensUsed - previousTokens) / (timeDelta / 1000);
|
|
254
|
+
}
|
|
255
|
+
// Check performance thresholds
|
|
256
|
+
this.checkPerformanceThresholds(agentId);
|
|
257
|
+
}
|
|
258
|
+
// ===========================
|
|
259
|
+
// Hierarchy Visualization
|
|
260
|
+
// ===========================
|
|
261
|
+
async getAgentHierarchy() {
|
|
262
|
+
return Array.from(this.agentHierarchy.values());
|
|
263
|
+
}
|
|
264
|
+
async getAgentsAtLevel(level) {
|
|
265
|
+
return Array.from(this.agentHierarchy.values()).filter((agent)=>agent.level === level);
|
|
266
|
+
}
|
|
267
|
+
async getChildAgents(parentAgentId) {
|
|
268
|
+
const parent = this.agentHierarchy.get(parentAgentId);
|
|
269
|
+
if (!parent) {
|
|
270
|
+
return [];
|
|
271
|
+
}
|
|
272
|
+
return parent.childAgentIds.map((childId)=>this.agentHierarchy.get(childId)).filter(Boolean);
|
|
273
|
+
}
|
|
274
|
+
async getRootAgents() {
|
|
275
|
+
return Array.from(this.agentHierarchy.values()).filter((agent)=>!agent.parentAgentId);
|
|
276
|
+
}
|
|
277
|
+
// ===========================
|
|
278
|
+
// Real-time Monitoring
|
|
279
|
+
// ===========================
|
|
280
|
+
async getAllAgentStatuses() {
|
|
281
|
+
return Array.from(this.agentStatuses.values());
|
|
282
|
+
}
|
|
283
|
+
async getAgentStatus(agentId) {
|
|
284
|
+
const status = this.agentStatuses.get(agentId);
|
|
285
|
+
if (!status) {
|
|
286
|
+
throw new Error(`Agent ${agentId} not found`);
|
|
287
|
+
}
|
|
288
|
+
return status;
|
|
289
|
+
}
|
|
290
|
+
async getActiveAgents() {
|
|
291
|
+
return Array.from(this.agentStatuses.values()).filter((status)=>!status.isPaused && status.state !== 'terminated');
|
|
292
|
+
}
|
|
293
|
+
async getPausedAgents() {
|
|
294
|
+
return Array.from(this.agentStatuses.values()).filter((status)=>status.isPaused);
|
|
295
|
+
}
|
|
296
|
+
// ===========================
|
|
297
|
+
// Event Streaming
|
|
298
|
+
// ===========================
|
|
299
|
+
async getRecentEvents(limit = 100, eventType) {
|
|
300
|
+
let events = [
|
|
301
|
+
...this.lifecycleEvents
|
|
302
|
+
].reverse();
|
|
303
|
+
if (eventType) {
|
|
304
|
+
events = events.filter((event)=>event.eventType === eventType);
|
|
305
|
+
}
|
|
306
|
+
return events.slice(0, limit);
|
|
307
|
+
}
|
|
308
|
+
async getAgentEvents(agentId, limit = 50) {
|
|
309
|
+
const events = this.lifecycleEvents.filter((event)=>event.agentId === agentId).reverse();
|
|
310
|
+
return events.slice(0, limit);
|
|
311
|
+
}
|
|
312
|
+
async getEventsInTimeRange(startTime, endTime, limit = 100) {
|
|
313
|
+
const events = this.lifecycleEvents.filter((event)=>event.timestamp >= startTime && event.timestamp <= endTime).reverse();
|
|
314
|
+
return events.slice(0, limit);
|
|
315
|
+
}
|
|
316
|
+
// ===========================
|
|
317
|
+
// Metrics & Analytics
|
|
318
|
+
// ===========================
|
|
319
|
+
async getTransparencyMetrics() {
|
|
320
|
+
const agents = Array.from(this.agentHierarchy.values());
|
|
321
|
+
const statuses = Array.from(this.agentStatuses.values());
|
|
322
|
+
// Calculate agents by level
|
|
323
|
+
const agentsByLevel = {};
|
|
324
|
+
agents.forEach((agent)=>{
|
|
325
|
+
agentsByLevel[agent.level] = (agentsByLevel[agent.level] || 0) + 1;
|
|
326
|
+
});
|
|
327
|
+
// Calculate agents by state
|
|
328
|
+
const agentsByState = {};
|
|
329
|
+
agents.forEach((agent)=>{
|
|
330
|
+
agentsByState[agent.state] = (agentsByState[agent.state] || 0) + 1;
|
|
331
|
+
});
|
|
332
|
+
// Calculate agents by type
|
|
333
|
+
const agentsByType = {};
|
|
334
|
+
agents.forEach((agent)=>{
|
|
335
|
+
agentsByType[agent.type] = (agentsByType[agent.type] || 0) + 1;
|
|
336
|
+
});
|
|
337
|
+
// Calculate total tokens
|
|
338
|
+
const totalTokensConsumed = agents.reduce((sum, agent)=>sum + agent.tokensUsed, 0);
|
|
339
|
+
const totalTokensSaved = this.calculateTokensSaved();
|
|
340
|
+
// Calculate performance metrics
|
|
341
|
+
const executionTimes = agents.map((agent)=>agent.metrics.totalExecutionTimeMs);
|
|
342
|
+
const averageExecutionTimeMs = executionTimes.length > 0 ? executionTimes.reduce((sum, time)=>sum + time, 0) / executionTimes.length : 0;
|
|
343
|
+
// Calculate failure rate
|
|
344
|
+
const terminatedAgents = agents.filter((agent)=>agent.state === 'terminated').length;
|
|
345
|
+
const failureRate = agents.length > 0 ? terminatedAgents / agents.length * 100 : 0;
|
|
346
|
+
// Calculate hierarchy depth
|
|
347
|
+
const hierarchyDepth = Math.max(...agents.map((agent)=>agent.level), 0);
|
|
348
|
+
// Calculate dependency resolution rate
|
|
349
|
+
const totalDependencies = agents.reduce((sum, agent)=>sum + agent.waitingFor.length + agent.completedDependencies.length, 0);
|
|
350
|
+
const completedDependencies = agents.reduce((sum, agent)=>sum + agent.completedDependencies.length, 0);
|
|
351
|
+
const dependencyResolutionRate = totalDependencies > 0 ? completedDependencies / totalDependencies * 100 : 100;
|
|
352
|
+
// Event stream statistics
|
|
353
|
+
const eventTypes = {};
|
|
354
|
+
this.lifecycleEvents.forEach((event)=>{
|
|
355
|
+
eventTypes[event.eventType] = (eventTypes[event.eventType] || 0) + 1;
|
|
356
|
+
});
|
|
357
|
+
const recentEvents = this.lifecycleEvents.filter((event)=>Date.now() - event.timestamp.getTime() < 60000 // Last minute
|
|
358
|
+
);
|
|
359
|
+
const eventsPerSecond = recentEvents.length / 60;
|
|
360
|
+
return {
|
|
361
|
+
totalAgents: agents.length,
|
|
362
|
+
agentsByLevel,
|
|
363
|
+
agentsByState,
|
|
364
|
+
agentsByType,
|
|
365
|
+
totalTokensConsumed,
|
|
366
|
+
totalTokensSaved,
|
|
367
|
+
averageExecutionTimeMs,
|
|
368
|
+
failureRate,
|
|
369
|
+
averagePauseResumeLatencyMs: this.calculateAveragePauseResumeLatency(),
|
|
370
|
+
hierarchyDepth,
|
|
371
|
+
dependencyResolutionRate,
|
|
372
|
+
eventStreamStats: {
|
|
373
|
+
totalEvents: this.lifecycleEvents.length,
|
|
374
|
+
eventsPerSecond,
|
|
375
|
+
eventTypes
|
|
376
|
+
}
|
|
377
|
+
};
|
|
378
|
+
}
|
|
379
|
+
async getAgentPerformanceMetrics(agentId) {
|
|
380
|
+
const hierarchyNode = this.agentHierarchy.get(agentId);
|
|
381
|
+
const status = this.agentStatuses.get(agentId);
|
|
382
|
+
if (!hierarchyNode || !status) {
|
|
383
|
+
throw new Error(`Agent ${agentId} not found`);
|
|
384
|
+
}
|
|
385
|
+
return {
|
|
386
|
+
agentId,
|
|
387
|
+
executionMetrics: hierarchyNode.metrics,
|
|
388
|
+
currentPerformance: {
|
|
389
|
+
tokenUsageRate: status.tokenUsageRate,
|
|
390
|
+
memoryUsage: status.memoryUsage,
|
|
391
|
+
cpuUsage: status.cpuUsage,
|
|
392
|
+
progress: status.progress
|
|
393
|
+
},
|
|
394
|
+
tokenMetrics: {
|
|
395
|
+
totalUsed: hierarchyNode.tokensUsed,
|
|
396
|
+
budget: hierarchyNode.tokenBudget,
|
|
397
|
+
utilizationRate: hierarchyNode.tokenBudget > 0 ? hierarchyNode.tokensUsed / hierarchyNode.tokenBudget * 100 : 0
|
|
398
|
+
},
|
|
399
|
+
stateMetrics: {
|
|
400
|
+
totalStateChanges: this.lifecycleEvents.filter((event)=>event.agentId === agentId && event.eventType === 'state_changed').length,
|
|
401
|
+
pauseCount: hierarchyNode.metrics.pauseCount,
|
|
402
|
+
resumeCount: hierarchyNode.metrics.resumeCount,
|
|
403
|
+
checkpointCount: hierarchyNode.metrics.checkpointCount
|
|
404
|
+
},
|
|
405
|
+
errorMetrics: {
|
|
406
|
+
totalErrors: status.recentErrors.length,
|
|
407
|
+
criticalErrors: status.recentErrors.filter((e)=>e.severity === 'critical').length,
|
|
408
|
+
recentErrors: status.recentErrors.slice(-5)
|
|
409
|
+
}
|
|
410
|
+
};
|
|
411
|
+
}
|
|
412
|
+
async getHierarchyAnalytics() {
|
|
413
|
+
const agents = Array.from(this.agentHierarchy.values());
|
|
414
|
+
const rootAgents = agents.filter((agent)=>!agent.parentAgentId);
|
|
415
|
+
// Calculate depth
|
|
416
|
+
const depth = Math.max(...agents.map((agent)=>agent.level), 0);
|
|
417
|
+
// Calculate branching factor
|
|
418
|
+
const parentAgents = agents.filter((agent)=>agent.childAgentIds.length > 0);
|
|
419
|
+
const totalChildren = parentAgents.reduce((sum, agent)=>sum + agent.childAgentIds.length, 0);
|
|
420
|
+
const branchingFactor = parentAgents.length > 0 ? totalChildren / parentAgents.length : 0;
|
|
421
|
+
// Calculate balance (standard deviation of children per parent)
|
|
422
|
+
const childCounts = parentAgents.map((agent)=>agent.childAgentIds.length);
|
|
423
|
+
const avgChildren = branchingFactor;
|
|
424
|
+
const variance = childCounts.reduce((sum, count)=>{
|
|
425
|
+
return sum + Math.pow(count - avgChildren, 2);
|
|
426
|
+
}, 0) / (parentAgents.length || 1);
|
|
427
|
+
const balance = Math.max(0, 100 - Math.sqrt(variance));
|
|
428
|
+
// Calculate efficiency (active agents vs total agents)
|
|
429
|
+
const activeAgents = agents.filter((agent)=>!agent.isPaused && agent.state !== 'terminated').length;
|
|
430
|
+
const efficiency = agents.length > 0 ? activeAgents / agents.length * 100 : 0;
|
|
431
|
+
return {
|
|
432
|
+
depth,
|
|
433
|
+
branchingFactor,
|
|
434
|
+
balance,
|
|
435
|
+
efficiency
|
|
436
|
+
};
|
|
437
|
+
}
|
|
438
|
+
// ===========================
|
|
439
|
+
// Event Listeners
|
|
440
|
+
// ===========================
|
|
441
|
+
async registerEventListener(listener) {
|
|
442
|
+
this.eventListeners.add(listener);
|
|
443
|
+
this.logger.debug('Transparency event listener registered');
|
|
444
|
+
}
|
|
445
|
+
async unregisterEventListener(listener) {
|
|
446
|
+
this.eventListeners.delete(listener);
|
|
447
|
+
this.logger.debug('Transparency event listener unregistered');
|
|
448
|
+
}
|
|
449
|
+
// ===========================
|
|
450
|
+
// Private Helper Methods
|
|
451
|
+
// ===========================
|
|
452
|
+
getDefaultConfig() {
|
|
453
|
+
return {
|
|
454
|
+
enableRealTimeMonitoring: true,
|
|
455
|
+
enableEventStreaming: true,
|
|
456
|
+
eventRetentionHours: 24,
|
|
457
|
+
metricsUpdateIntervalMs: 5000,
|
|
458
|
+
heartbeatIntervalMs: 10000,
|
|
459
|
+
enablePerformanceTracking: true,
|
|
460
|
+
enableDependencyTracking: true,
|
|
461
|
+
maxEventsInMemory: 10000,
|
|
462
|
+
enableHierarchyNotifications: true
|
|
463
|
+
};
|
|
464
|
+
}
|
|
465
|
+
calculateAgentLevel(agentId, parentAgentId) {
|
|
466
|
+
if (!parentAgentId) {
|
|
467
|
+
return 1; // Root level
|
|
468
|
+
}
|
|
469
|
+
const parent = this.agentHierarchy.get(parentAgentId);
|
|
470
|
+
if (parent) {
|
|
471
|
+
return parent.level + 1;
|
|
472
|
+
}
|
|
473
|
+
return 2; // Default to level 2 if parent not found
|
|
474
|
+
}
|
|
475
|
+
getActivityForState(state, reason) {
|
|
476
|
+
const stateActivities = {
|
|
477
|
+
idle: 'Idle',
|
|
478
|
+
active: 'Executing task',
|
|
479
|
+
paused: 'Paused',
|
|
480
|
+
terminated: 'Terminated',
|
|
481
|
+
error: 'Error state',
|
|
482
|
+
completing: 'Completing task',
|
|
483
|
+
checkpointing: 'Creating checkpoint',
|
|
484
|
+
waiting_for_dependency: 'Waiting for dependency'
|
|
485
|
+
};
|
|
486
|
+
let activity = stateActivities[state] || 'Unknown state';
|
|
487
|
+
if (reason) {
|
|
488
|
+
activity += ` (${reason})`;
|
|
489
|
+
}
|
|
490
|
+
return activity;
|
|
491
|
+
}
|
|
492
|
+
recordLifecycleEvent(event) {
|
|
493
|
+
this.lifecycleEvents.push(event);
|
|
494
|
+
// Enforce event retention limit
|
|
495
|
+
if (this.lifecycleEvents.length > this.config.maxEventsInMemory) {
|
|
496
|
+
const excess = this.lifecycleEvents.length - this.config.maxEventsInMemory;
|
|
497
|
+
this.lifecycleEvents.splice(0, excess);
|
|
498
|
+
}
|
|
499
|
+
// Notify listeners
|
|
500
|
+
this.eventListeners.forEach((listener)=>{
|
|
501
|
+
if (listener.onLifecycleEvent) {
|
|
502
|
+
try {
|
|
503
|
+
listener.onLifecycleEvent(event);
|
|
504
|
+
} catch (error) {
|
|
505
|
+
this.logger.error('Error in lifecycle event listener', error);
|
|
506
|
+
}
|
|
507
|
+
}
|
|
508
|
+
});
|
|
509
|
+
this.emit('lifecycleEvent', event);
|
|
510
|
+
}
|
|
511
|
+
notifyHierarchyChange(type, agentId, data) {
|
|
512
|
+
if (!this.config.enableHierarchyNotifications) {
|
|
513
|
+
return;
|
|
514
|
+
}
|
|
515
|
+
this.eventListeners.forEach((listener)=>{
|
|
516
|
+
if (listener.onHierarchyChange) {
|
|
517
|
+
try {
|
|
518
|
+
listener.onHierarchyChange({
|
|
519
|
+
type,
|
|
520
|
+
agentId,
|
|
521
|
+
data
|
|
522
|
+
});
|
|
523
|
+
} catch (error) {
|
|
524
|
+
this.logger.error('Error in hierarchy change listener', error);
|
|
525
|
+
}
|
|
526
|
+
}
|
|
527
|
+
});
|
|
528
|
+
this.emit('hierarchyChange', {
|
|
529
|
+
type,
|
|
530
|
+
agentId,
|
|
531
|
+
data
|
|
532
|
+
});
|
|
533
|
+
}
|
|
534
|
+
notifyStateChange(agentId, previousState, newState) {
|
|
535
|
+
const timestamp = new Date();
|
|
536
|
+
this.eventListeners.forEach((listener)=>{
|
|
537
|
+
if (listener.onAgentStateChange) {
|
|
538
|
+
try {
|
|
539
|
+
listener.onAgentStateChange({
|
|
540
|
+
agentId,
|
|
541
|
+
previousState,
|
|
542
|
+
newState,
|
|
543
|
+
timestamp
|
|
544
|
+
});
|
|
545
|
+
} catch (error) {
|
|
546
|
+
this.logger.error('Error in state change listener', error);
|
|
547
|
+
}
|
|
548
|
+
}
|
|
549
|
+
});
|
|
550
|
+
this.emit('agentStateChange', {
|
|
551
|
+
agentId,
|
|
552
|
+
previousState,
|
|
553
|
+
newState,
|
|
554
|
+
timestamp
|
|
555
|
+
});
|
|
556
|
+
}
|
|
557
|
+
updateMetrics() {
|
|
558
|
+
if (!this.isMonitoring) {
|
|
559
|
+
return;
|
|
560
|
+
}
|
|
561
|
+
this.getTransparencyMetrics().then((metrics)=>{
|
|
562
|
+
this.eventListeners.forEach((listener)=>{
|
|
563
|
+
if (listener.onMetricsUpdate) {
|
|
564
|
+
try {
|
|
565
|
+
listener.onMetricsUpdate(metrics);
|
|
566
|
+
} catch (error) {
|
|
567
|
+
this.logger.error('Error in metrics update listener', error);
|
|
568
|
+
}
|
|
569
|
+
}
|
|
570
|
+
});
|
|
571
|
+
this.emit('metricsUpdate', metrics);
|
|
572
|
+
}).catch((error)=>{
|
|
573
|
+
this.logger.error('Error updating transparency metrics', error);
|
|
574
|
+
});
|
|
575
|
+
}
|
|
576
|
+
checkAgentHeartbeats() {
|
|
577
|
+
const now = new Date();
|
|
578
|
+
const staleThreshold = this.config.heartbeatIntervalMs * 3; // 3 intervals
|
|
579
|
+
this.agentStatuses.forEach((status, agentId)=>{
|
|
580
|
+
const timeSinceHeartbeat = now.getTime() - status.lastHeartbeat.getTime();
|
|
581
|
+
if (timeSinceHeartbeat > staleThreshold) {
|
|
582
|
+
// Agent hasn't sent heartbeat recently
|
|
583
|
+
status.recentErrors.push({
|
|
584
|
+
timestamp: now,
|
|
585
|
+
error: `Agent heartbeat timeout (${Math.round(timeSinceHeartbeat / 1000)}s)`,
|
|
586
|
+
severity: 'warning'
|
|
587
|
+
});
|
|
588
|
+
// Keep only recent errors
|
|
589
|
+
if (status.recentErrors.length > 10) {
|
|
590
|
+
status.recentErrors.splice(0, status.recentErrors.length - 10);
|
|
591
|
+
}
|
|
592
|
+
}
|
|
593
|
+
});
|
|
594
|
+
}
|
|
595
|
+
checkPerformanceThresholds(agentId) {
|
|
596
|
+
const status = this.agentStatuses.get(agentId);
|
|
597
|
+
if (!status) {
|
|
598
|
+
return;
|
|
599
|
+
}
|
|
600
|
+
const alerts = [];
|
|
601
|
+
// Check token usage rate
|
|
602
|
+
if (status.tokenUsageRate > this.performanceThresholds.maxTokenUsageRate) {
|
|
603
|
+
alerts.push({
|
|
604
|
+
metric: 'tokenUsageRate',
|
|
605
|
+
value: status.tokenUsageRate,
|
|
606
|
+
threshold: this.performanceThresholds.maxTokenUsageRate,
|
|
607
|
+
severity: status.tokenUsageRate > this.performanceThresholds.maxTokenUsageRate * 1.5 ? 'critical' : 'warning'
|
|
608
|
+
});
|
|
609
|
+
}
|
|
610
|
+
// Check memory usage
|
|
611
|
+
if (status.memoryUsage > this.performanceThresholds.maxMemoryUsage) {
|
|
612
|
+
alerts.push({
|
|
613
|
+
metric: 'memoryUsage',
|
|
614
|
+
value: status.memoryUsage,
|
|
615
|
+
threshold: this.performanceThresholds.maxMemoryUsage,
|
|
616
|
+
severity: 'critical'
|
|
617
|
+
});
|
|
618
|
+
}
|
|
619
|
+
// Check CPU usage
|
|
620
|
+
if (status.cpuUsage > this.performanceThresholds.maxCpuUsage) {
|
|
621
|
+
alerts.push({
|
|
622
|
+
metric: 'cpuUsage',
|
|
623
|
+
value: status.cpuUsage,
|
|
624
|
+
threshold: this.performanceThresholds.maxCpuUsage,
|
|
625
|
+
severity: status.cpuUsage > 95 ? 'critical' : 'warning'
|
|
626
|
+
});
|
|
627
|
+
}
|
|
628
|
+
// Notify listeners of performance alerts
|
|
629
|
+
alerts.forEach((alert)=>{
|
|
630
|
+
this.eventListeners.forEach((listener)=>{
|
|
631
|
+
if (listener.onPerformanceAlert) {
|
|
632
|
+
try {
|
|
633
|
+
listener.onPerformanceAlert({
|
|
634
|
+
agentId,
|
|
635
|
+
...alert
|
|
636
|
+
});
|
|
637
|
+
} catch (error) {
|
|
638
|
+
this.logger.error('Error in performance alert listener', error);
|
|
639
|
+
}
|
|
640
|
+
}
|
|
641
|
+
});
|
|
642
|
+
this.emit('performanceAlert', {
|
|
643
|
+
agentId,
|
|
644
|
+
...alert
|
|
645
|
+
});
|
|
646
|
+
});
|
|
647
|
+
}
|
|
648
|
+
calculateTokensSaved() {
|
|
649
|
+
const pausedAgents = Array.from(this.agentStatuses.values()).filter((status)=>status.isPaused);
|
|
650
|
+
return pausedAgents.reduce((total, status)=>{
|
|
651
|
+
const timeSincePause = Date.now() - status.lastHeartbeat.getTime();
|
|
652
|
+
const estimatedTokensSaved = status.tokenUsageRate * timeSincePause / 1000;
|
|
653
|
+
return total + Math.max(0, estimatedTokensSaved);
|
|
654
|
+
}, 0);
|
|
655
|
+
}
|
|
656
|
+
calculateAveragePauseResumeLatencyMs() {
|
|
657
|
+
const events = this.lifecycleEvents.filter((event)=>event.eventType === 'paused' || event.eventType === 'resumed');
|
|
658
|
+
if (events.length < 2) {
|
|
659
|
+
return 0;
|
|
660
|
+
}
|
|
661
|
+
// Pair pause/resume events and calculate latencies
|
|
662
|
+
const latencies = [];
|
|
663
|
+
const pauseEvents = new Map();
|
|
664
|
+
events.forEach((event)=>{
|
|
665
|
+
if (event.eventType === 'paused') {
|
|
666
|
+
pauseEvents.set(event.agentId, event);
|
|
667
|
+
} else if (event.eventType === 'resumed') {
|
|
668
|
+
const pauseEvent = pauseEvents.get(event.agentId);
|
|
669
|
+
if (pauseEvent && event.performanceImpact.duration) {
|
|
670
|
+
latencies.push(event.performanceImpact.duration);
|
|
671
|
+
}
|
|
672
|
+
pauseEvents.delete(event.agentId);
|
|
673
|
+
}
|
|
674
|
+
});
|
|
675
|
+
return latencies.length > 0 ? latencies.reduce((sum, latency)=>sum + latency, 0) / latencies.length : 0;
|
|
676
|
+
}
|
|
677
|
+
}
|
|
678
|
+
|
|
679
|
+
//# sourceMappingURL=transparency-system.js.map
|