import type { GoalFlightState, GoalTerminalReceipt, GoalFlightEventRecord } from "../core/goal-bound.js"; import { type Debrief, type DebriefObservation } from "./sortie-debrief.ts"; import type { GoalReport } from "../core/goal-report.ts"; import { type SortieCareer } from "./sortie-career.ts"; export interface RunMetricsClient { readonly session?: { readonly get?: (request: { path: { id: string; }; query?: { directory?: string; }; }) => Promise; readonly children?: (request: { path: { id: string; }; query?: { directory?: string; }; }) => Promise; readonly messages?: (request: { path: { id: string; }; query?: { directory?: string; }; }) => Promise; }; } export interface RunMetricsWindow { readonly startedAt: string; readonly endedAt: string; } export interface RunMetrics { readonly durationMilliseconds: number | undefined; readonly tokens: number | undefined; readonly inputTokens: number | undefined; readonly outputTokens: number | undefined; readonly reasoningTokens: number | undefined; readonly cacheReadTokens: number | undefined; readonly cacheWriteTokens: number | undefined; readonly cost: number | undefined; readonly steps: number | undefined; readonly sessions: number | undefined; readonly cacheRatio: number | undefined; readonly roles: Readonly> | undefined; /** Optional for compatibility with older host snapshots. Collected in the existing history pass. */ readonly debrief?: DebriefObservation; } export interface RunRoleMetrics { readonly tokens: number; readonly inputTokens: number; readonly outputTokens: number; readonly reasoningTokens: number; readonly cacheReadTokens: number; readonly cacheWriteTokens: number; readonly cost: number | undefined; readonly steps: number; readonly cacheRatio: number | undefined; } export type SortieResultUnavailableReason = "acceptance-contract-unavailable" | "goal-clock-invalid" | "goal-usage-unavailable" | "host-metrics-unavailable" | "incomplete-host-coverage" | "matched-baseline-unavailable" | "milestone-unavailable" | "usable-milestone-unavailable" | "worker-overlap-unavailable"; export type SortieResultMetric = { readonly availability: "available"; readonly value: T; readonly provenance: "goal-receipt" | "goal-ledger" | "host-reported"; } | { readonly availability: "unavailable"; readonly value: null; readonly reason: SortieResultUnavailableReason; }; export type SortieProofStatus = "PASS" | "FAIL" | "UNPROVEN" | "NOT_REQUIRED" | "WAIVED"; export interface SortieResult { readonly schema_version: "0.1"; readonly result_id: readonly [goalID: string, terminalRevision: number]; readonly accounting_phase: "pre-terminal"; readonly as_of: string; readonly debrief?: Debrief; readonly career?: SortieCareer; readonly mission: { readonly status: "COMPLETED" | "INTERRUPTED" | "EXTERNAL_BLOCKER" | "USER_DECISION"; readonly stop_reason: GoalTerminalReceipt["stop_reason"]; }; readonly speed: { readonly goal_wall_ms: SortieResultMetric; readonly worker_execution_ms: SortieResultMetric; readonly execution_compression: SortieResultMetric; readonly first_verifiable_ms: SortieResultMetric; readonly first_usable_ms: SortieResultMetric; readonly bare_comparison: SortieResultMetric; }; readonly cost: { readonly total_tokens: SortieResultMetric; readonly cost_usd: SortieResultMetric; readonly model_steps: SortieResultMetric; readonly sessions: SortieResultMetric; }; readonly proof: { readonly overall: SortieProofStatus; readonly acceptance_fingerprint: string; readonly criteria: SortieResultMetric; readonly evidence_refs: readonly string[]; }; } type SortieGoalSnapshot = Pick; /** Builds a pure terminal snapshot from the durable goal receipt and already-observed host metrics. */ export declare function createSortieResult(receipt: GoalTerminalReceipt, goal: SortieGoalSnapshot, metrics: RunMetrics | undefined, asOf?: string, records?: readonly GoalFlightEventRecord[]): SortieResult; export type RunTerminalOutcome = "DONE" | "INTERRUPTED" | "BLOCKED" | "NEED_DECISION"; export declare function collectRunMetrics(client: RunMetricsClient | undefined, rootSessionID: string, directory?: string, now?: number, window?: RunMetricsWindow): Promise; export interface SortieResultPresentation { readonly implementation?: string; readonly pending?: string; readonly next?: string; readonly commit?: string; readonly statusSummary?: string; readonly stopReason?: string; } export declare function formatSortieResult(result: SortieResult, presentation?: SortieResultPresentation): string; export declare function formatRunMetrics(metrics: RunMetrics): string; export declare function isDoneTerminalText(text: string): boolean; export declare function terminalRunOutcome(text: string): RunTerminalOutcome | undefined; export declare function replaceTerminalStatus(text: string, replacement: string): string; export declare function replaceDoneTerminalStatus(text: string, replacement: string): string; export declare function sanitizeTerminalReport(text: string): string; export declare function insertRunMetrics(text: string, metrics: RunMetrics): string; export declare function insertSortieResult(text: string, result: SortieResult): string; export declare function createGoalReport(result: SortieResult, receipt: GoalTerminalReceipt): GoalReport; export {};