/** * Slice topology observability — schema + emit (Slice A of v2.11.1). * * Public surface: * - `emitObservabilityEvent(event, options)` — fire-and-forget write * to `.peaks/_runtime//metrics/slices.jsonl`. * - `readObservabilityEvents(projectRoot, sessionId)` — schema-aware * reader that skips malformed lines and unknown schema versions * (per PRD Q3 forward-compat). * * Schema-versioned (schemaVersion: 1). The zod schema is the source of * truth for the wire format. `ts` and `sessionId` are required; the * caller is responsible for passing them (so each hook site has a * canonical session binding even when run in a sub-agent). * * Per PRD Q4, `emit` MUST NEVER throw or fail-loud. All error paths * collapse to `written: false` with a `reason` string so the caller can * log if it wants — but the calling hook site itself swallows the * result (fire-and-forget by convention). */ import { z } from 'zod'; export declare const OBSERVABILITY_SCHEMA_VERSION: 1; export declare const OBSERVABILITY_CATEGORIES: readonly ["slice-transition", "dispatch", "checkpoint", "mode-gate", "context-trigger", "post-compact"]; export type ObservabilityCategory = typeof OBSERVABILITY_CATEGORIES[number]; export declare const OBSERVABILITY_SUBAGENT_ROLES: readonly ["rd", "qa", "code-reviewer", "karpathy-reviewer", "peaks-security-audit", "peaks-perf-audit"]; export type ObservabilitySubagentRole = typeof OBSERVABILITY_SUBAGENT_ROLES[number]; export declare const ObservabilityEventSchema: z.ZodObject<{ schemaVersion: z.ZodLiteral<1>; ts: z.ZodString; sessionId: z.ZodString; category: z.ZodEnum<["slice-transition", "dispatch", "checkpoint", "mode-gate", "context-trigger", "post-compact"]>; sliceRid: z.ZodOptional; role: z.ZodOptional>; detail: z.ZodRecord; }, "strip", z.ZodTypeAny, { sessionId: string; schemaVersion: 1; ts: string; category: "slice-transition" | "dispatch" | "checkpoint" | "mode-gate" | "context-trigger" | "post-compact"; detail: Record; role?: "qa" | "rd" | "code-reviewer" | "karpathy-reviewer" | "peaks-security-audit" | "peaks-perf-audit" | undefined; sliceRid?: string | undefined; }, { sessionId: string; schemaVersion: 1; ts: string; category: "slice-transition" | "dispatch" | "checkpoint" | "mode-gate" | "context-trigger" | "post-compact"; detail: Record; role?: "qa" | "rd" | "code-reviewer" | "karpathy-reviewer" | "peaks-security-audit" | "peaks-perf-audit" | undefined; sliceRid?: string | undefined; }>; export type ObservabilityEvent = z.infer; export type EmitOptions = { /** Absolute path to the project root (where `.peaks/_runtime/` lives). */ projectRoot: string; }; export type EmitFailureReason = 'invalid-schema' | 'write-failed'; export type EmitResult = { /** True when the JSONL line was appended; false on any error path. */ written: boolean; /** Absolute path to the metrics file the event was written to (or would be). */ path: string; /** Set only when `written` is false. */ reason?: EmitFailureReason; }; /** * Append a single observability event to the session's JSONL metrics * file. Synchronous (small append, sub-ms in practice) and * fire-and-forget by construction — the caller never awaits, and the * function never throws. * * On success, also triggers the cross-session prune * (`pruneMetricsFiles`). The prune is best-effort and cheap when the * session count is below `MAX_METRICS_FILES`. */ export declare function emitObservabilityEvent(event: ObservabilityEvent, options: EmitOptions): EmitResult; /** * Read all events from a session's metrics file, skipping malformed * lines and any record whose `schemaVersion` does not match the * current `OBSERVABILITY_SCHEMA_VERSION` (forward-compat per Q3). * * Returns [] when the session has no metrics file yet. */ export declare function readObservabilityEvents(projectRoot: string, sessionId: string): ObservabilityEvent[]; /** * True when the candidate record validates against the current * schema (re-exported as a convenience for callers that already have * parsed JSON and want to skip forward-compat records). */ export declare function isCurrentSchemaVersion(record: unknown): record is ObservabilityEvent; export declare const OBSERVABILITY_CONSTANTS: { readonly SCHEMA_VERSION: 1; readonly CATEGORIES: readonly ["slice-transition", "dispatch", "checkpoint", "mode-gate", "context-trigger", "post-compact"]; readonly SUBAGENT_ROLES: readonly ["rd", "qa", "code-reviewer", "karpathy-reviewer", "peaks-security-audit", "peaks-perf-audit"]; };