/** * Append-Only Trace Store * * Aggregates run data over time to build institutional memory. Every governed * run's routing decision, cost, failure class, and outcome is appended to a * local JSONL trace file. Data is NEVER overwritten — only appended. * * The trace store feeds: * - classifyRoute() with historicalDirectSuccessRate from real past runs * - Cost prediction models with actual spend data * - Failure pattern detection across runs * - Team analytics and optimization recommendations * * Storage: `/_martin/trace-log.jsonl` (one JSON object per line) */ export interface TraceEntry { /** ISO-8601 timestamp */ timestamp: string; /** Unique loop identifier */ loopId: string; /** The objective that was governed */ objective: string; /** Which engine executed the run */ engine: string; /** Route selected by classifyRoute */ selectedRoute: "direct" | "manager" | "consensus"; /** Route classifier confidence (0-1) */ routeConfidence: number; /** Budget allocated (USD) */ budgetUsd: number; /** Actual spend (USD) */ actualCostUsd: number; /** Pre-work burn percentage */ preWorkBurnPct: number; /** Number of attempts */ attempts: number; /** Final loop status */ status: string; /** Final lifecycle state */ lifecycleState: string; /** Failure class of last attempt (if failed) */ failureClass?: string; /** Whether verification passed */ verificationPassed: boolean; /** Number of files changed */ filesChanged: number; /** Working directory (hashed for privacy) */ workspaceHash: string; } export interface TraceAggregation { totalRuns: number; directRuns: number; managerRuns: number; consensusRuns: number; directSuccessRate: number; managerSuccessRate: number; averageCostUsd: number; averagePreWorkBurnPct: number; totalSpendUsd: number; totalSavedUsd: number; topFailureClasses: Array<{ failureClass: string; count: number; }>; averageAttemptsPerRun: number; lastUpdated: string; } /** * Append a trace entry to the local trace store. Never overwrites. */ export declare function appendTraceEntry(runsRoot: string, entry: TraceEntry): Promise; /** * Read all trace entries from the local trace store. */ export declare function readTraceEntries(runsRoot: string): Promise; /** * Aggregate trace entries into summary statistics. * Used by classifyRoute() to get historicalDirectSuccessRate. */ export declare function aggregateTraces(entries: TraceEntry[]): TraceAggregation; /** * Get the historical direct success rate for use in route classification. * Returns undefined if insufficient data (< 5 runs). */ export declare function getHistoricalDirectSuccessRate(runsRoot: string): Promise;