/** * audit-logger.ts — Structured audit logging for cross-extension RPC operations. * * Records every RPC call with: timestamp, caller identity, operation, * parameters, outcome (success/error), and duration. Entries are written * via the shared `logger` and emitted as telemetry events so external * consumers can subscribe. * * The in-memory ring buffer keeps the last N entries (configurable via * `AuditLoggerConfig.maxEntries`) for programmatic inspection and the * `/agents` diagnostic menu. */ export type AuditOperation = "ping" | "spawn" | "stop" | "sessionUsage" | "swarmHealth"; export type AuditOutcome = "success" | "error" | "rate_limited" | "unauthorized"; export interface AuditEntry { /** ISO-8601 timestamp of the RPC call. */ timestamp: string; /** Authenticated extension identity (or "legacy" when auth is unavailable). */ extensionId: string; /** Human-readable extension name, if available. */ extensionName?: string; /** RPC operation that was invoked. */ operation: AuditOperation; /** Outcome of the call. */ outcome: AuditOutcome; /** Wall-clock duration of the handler in milliseconds. */ durationMs: number; /** Operation-specific metadata (agent type, agent id, error message, etc.). */ metadata?: Record; } export interface AuditLoggerConfig { /** Maximum number of entries kept in the in-memory ring buffer (default 200). */ maxEntries?: number; /** When `true`, suppress logger output (telemetry events still fire). */ silent?: boolean; } /** (Re)configure the audit logger. Safe to call multiple times. */ export declare function configureAuditLogger(config: AuditLoggerConfig): void; /** Record a completed RPC call. */ export declare function recordAudit(entry: AuditEntry): void; /** Return a shallow copy of the current audit log (oldest → newest). */ export declare function getAuditLog(): readonly AuditEntry[]; /** Return only entries matching a given operation. */ export declare function getAuditLogByOperation(operation: AuditOperation): readonly AuditEntry[]; /** Return only entries from a given extension. */ export declare function getAuditLogByExtension(extensionId: string): readonly AuditEntry[]; /** Clear the in-memory buffer (useful in tests). */ export declare function clearAuditLog(): void; /** Reset to defaults (useful in tests). */ export declare function resetAuditLogger(): void;