/** * telemetry.ts — Structured event emitter for security, validation, and lifecycle events. * * Provides a lightweight pub/sub system for agent lifecycle events. * Fail-open: security events warn; routine lifecycle events are debug-only. */ /** Telemetry event types and their payloads */ export interface TelemetryEvents { "agent:loaded": { name: string; source: "project" | "global" | "embedded"; hash: string; enabled: boolean; }; "agent:validation-failed": { name: string; errors: string[]; }; "agent:unknown-tools": { name: string; tools: string[]; }; "agent:spawned": { type: string; parentType?: string; depth: number; budget?: number; }; "agent:completed": { type: string; duration: number; validatorResults?: { passed: boolean; summary: string; }[]; }; "rpc:audit": { timestamp: string; extensionId: string; extensionName?: string; operation: string; outcome: string; durationMs: number; metadata?: Record; }; /** * Emitted by `dispatch-history.ts` on every call to * `recordDispatchDecision(...)`. Lets downstream consumers (sentry, * splunk, the Go cinematic sidecar) reconstruct the same * single/swarm/crew + auto/explicit histogram that the in-memory * ring buffer feeds into `/agents → Health check`. Note the event * carries the resolved `kind` already (so a `auto → crew` decision * surfaces as `kind: "crew"` AND `configuredMode: "auto"` + * `source: "auto-heuristic"`), not the heuristic's intermediate * `analyzePrompt` output — consumers wanting the raw signals can * subscribe to a separate (not-yet-emitted) `subagent:dispatch_signals` * event if/when that becomes useful. */ "subagent:dispatch_decision": { kind: "single" | "swarm" | "crew"; configuredMode: "auto" | "single" | "swarm" | "crew"; source: "explicit" | "auto-heuristic"; promptLength: number; description: string; }; } /** Event names as a union type */ export type TelemetryEventName = keyof TelemetryEvents; /** Handler function type */ export type TelemetryHandler = (payload: TelemetryEvents[E]) => void; /** * Subscribe to a telemetry event. * Returns an unsubscribe function. */ export declare function onTelemetry(event: E, handler: TelemetryHandler): () => void; /** * Emit a telemetry event. * If no listeners are registered, security events warn and routine lifecycle * events are emitted at debug level only. */ export declare function emitTelemetry(event: E, payload: TelemetryEvents[E]): void; /** * Compute SHA-256 hash of a string (hex-encoded). * Used for agent content integrity logging. */ export declare function hashContent(content: string): Promise; /** * Synchronous hash using Node.js crypto (fallback for non-browser environments). * Used when async hash is not convenient. */ export declare function hashContentSync(content: string): string;