import type { EvidenceCapsuleStore } from "./evidence-capsule.js"; import type { AcceptanceCompileGapCode, AcceptanceCompileResult } from "./acceptance-compiler.js"; import { type ChildTerminalIdentity, type ChildTerminalEvidence, type ChildTerminalDisposition } from "./child-terminal-reconciliation.js"; import type { TerminalRescueAcceptedBase } from "./terminal-rescue-policy.js"; import { type ValidationBudgetRequest, type ValidationBudgetDecision, type ValidationOutcome, type ValidationScope } from "./validation-budget.js"; import { type GoalEvidence, type GoalFlightEvent, type GoalFlightEventRecord, type GoalFlightState, type GoalValidationRetryAuthorization } from "./goal-bound.js"; export declare const RUN_FLIGHT_LEDGER_SCHEMA_VERSION: "0.1"; export declare const MAX_RUN_FLIGHT_EVENTS = 2048; export declare const MAX_RUN_FLIGHT_LEDGER_BYTES: number; export type FlightRole = "implementation" | "review" | "advice" | "rescue"; export type RecoveryKind = "normal_remediation" | "adaptive_probe" | "read_only_diagnosis" | "model_rescue"; export type FailureCategory = "infrastructure" | "authorization" | "contract" | "cancellation" | "implementation"; export type TerminalDisposition = "continue" | "succeeded" | "failed" | "cancelled"; export type FlightStage = "planning" | "route" | "unit" | "wave" | "candidate" | "cleanup" | "recovery"; export interface FlightBudgetLimits { readonly recovery_actions: number; readonly probe_iterations: number; readonly model_attempts: number; } export interface FlightBudgetCharge extends FlightBudgetLimits { readonly kind: "implementation" | RecoveryKind; } export interface FlightResourceBudget { readonly time_ms: number; readonly cost_usd: number; } export interface FlightResourceUsage { readonly time_ms: number | null; readonly cost_usd: number | null; } export interface FlightReferenceSet { readonly capsule_ids: readonly string[]; readonly artifact_ids: readonly string[]; } export interface FlightObservation { readonly stage: FlightStage; readonly duration_ms: number | null; readonly usage: { readonly input_tokens: number | null; readonly cache_read_tokens: number | null; readonly output_tokens: number | null; readonly provenance: "measured" | "provider_estimate" | "unknown"; }; readonly estimated_cost: { readonly usd: number | null; readonly provenance: "provider_estimate" | "calculated" | "unknown"; }; } export interface FabricWaveArtifactEvidence { readonly unit_id: string; readonly commit_sha: string; readonly change_fingerprint: string; readonly validation_fingerprint: string; } export interface FabricWaveSchedulerEvidence { readonly wave: number; readonly base_sha: string; readonly pending: readonly string[]; readonly completed: readonly string[]; readonly active: { readonly number: number; readonly base_sha: string; readonly unit_ids: readonly string[]; readonly lanes: Readonly>; } | null; readonly lane_affinity: Readonly>; } export interface FabricCandidateSnapshotEvidence { readonly authority_sha: string; readonly target_branch: string; readonly candidate_ref: string; readonly candidate_head: string; readonly wave_heads: readonly string[]; } interface EventBase { readonly at: string; } export interface ChildFlightState { readonly identity: ChildTerminalIdentity; readonly deadline_ms: number; readonly stop_trigger: "deadline_expired" | "explicit_cancellation" | null; readonly terminal: { readonly disposition: ChildTerminalDisposition; readonly fingerprint: string; } | null; } export interface DiagnosisLane { readonly lane_id: string; readonly diagnosis_id: string; readonly causal_class: string; } export interface DiagnosisSelection { readonly diagnosis_id: string; readonly capsule_id: string; readonly contract_id: string; readonly recovery_kind: Exclude; readonly proposal: string; readonly budget_request: FlightBudgetCharge; } export interface DiagnosisFlightState { readonly owner_root: string; readonly run_id: string; readonly swarm_id: string; readonly request_fingerprint: string; readonly unit_id: string; readonly failed_attempt_id: string; readonly candidate_id: string; readonly plan_id: string; readonly plan_binding_id: string; readonly source_capsule_id: string; readonly source_paths: readonly string[]; readonly deadline_ms: number; readonly lanes: readonly DiagnosisLane[]; readonly budget_charge: FlightBudgetCharge; readonly per_lane_resource_budget?: FlightResourceBudget; readonly dispatched: Readonly>; readonly findings: Readonly>; readonly selection: DiagnosisSelection | null; readonly executed_attempt_id: string | null; } export type RunFlightEvent = (EventBase & { readonly kind: "diagnosis.opened"; readonly swarm_id: string; readonly request_fingerprint: string; readonly owner_root: string; readonly unit_id: string; readonly failed_attempt_id: string; readonly candidate_id: string; readonly plan_id: string; readonly plan_binding_id: string; readonly source_capsule_id: string; readonly source_paths: readonly string[]; readonly deadline_ms: number; readonly lanes: readonly DiagnosisLane[]; readonly budget_charge: FlightBudgetCharge; readonly per_lane_resource_budget?: FlightResourceBudget; }) | (EventBase & { readonly kind: "diagnosis.dispatched"; readonly swarm_id: string; readonly lane_id: string; readonly call_id: string; }) | (EventBase & { readonly kind: "diagnosis.finished"; readonly swarm_id: string; readonly lane_id: string; readonly capsule_id: string | null; readonly verdict: "supported" | "excluded" | "unknown"; readonly observation: FlightObservation; }) | (EventBase & { readonly kind: "diagnosis.selected"; readonly swarm_id: string; readonly selection: DiagnosisSelection; }) | (EventBase & { readonly kind: "child.registered"; readonly identity: ChildTerminalIdentity; readonly deadline_ms: number; }) | (EventBase & { readonly kind: "child.stop-requested"; readonly identity: ChildTerminalIdentity; readonly trigger: "deadline_expired" | "explicit_cancellation"; }) | (EventBase & { readonly kind: "child.terminal"; readonly identity: ChildTerminalIdentity; readonly disposition: ChildTerminalDisposition; readonly evidence: ChildTerminalEvidence; }) | (EventBase & { readonly kind: "run.planned"; readonly run_id: string; readonly initial_candidate_id: string; readonly budget_limits: FlightBudgetLimits; readonly resource_budget_limits?: FlightResourceBudget; }) | (EventBase & { readonly kind: "plan.compiled"; readonly plan_id: string; readonly proposal_id: string; readonly decision: "accepted" | "rejected"; readonly gap_codes: readonly AcceptanceCompileGapCode[]; }) | (EventBase & { readonly kind: "fabric.wave.accepted"; readonly plan_id: string; readonly plan_binding_id: string; readonly wave_index: number; readonly from_candidate_id: string; readonly candidate_id: string; readonly artifacts: readonly FabricWaveArtifactEvidence[]; readonly scheduler_before: FabricWaveSchedulerEvidence; readonly scheduler_after: FabricWaveSchedulerEvidence; readonly candidate_snapshot: FabricCandidateSnapshotEvidence; }) | (EventBase & { readonly kind: "route.selected"; readonly route_id: string; readonly candidate_id: string; readonly role: FlightRole; readonly model: string; readonly variant: string | null; readonly reason: "planning" | "implementation" | RecoveryKind; }) | (EventBase & { readonly kind: "wave.opened"; readonly wave_id: string; readonly wave_index: number; readonly candidate_id: string; }) | (EventBase & { readonly kind: "unit.opened"; readonly unit_id: string; readonly wave_id: string; readonly candidate_id: string; readonly references: FlightReferenceSet; }) | (EventBase & { readonly kind: "attempt.started"; readonly attempt_id: string; readonly predecessor_attempt_id: string | null; readonly unit_id: string; readonly candidate_id: string; readonly route_id: string; readonly role: FlightRole; readonly selected_model: string; readonly selected_variant: string | null; readonly child_id: string | null; readonly call_id: string; readonly budget_charge: FlightBudgetCharge; readonly resource_budget_request?: FlightResourceBudget; readonly remediation_contract_id?: string; readonly terminal_rescue_contract?: TerminalRescueAcceptedBase; }) | (EventBase & { readonly kind: "attempt.finished"; readonly attempt_id: string; readonly observed_model: string | null; readonly observed_variant: string | null; readonly failure: { readonly category: FailureCategory; readonly code: string; } | null; readonly disposition: TerminalDisposition; readonly observation: FlightObservation; readonly references: FlightReferenceSet; }) | (EventBase & { readonly kind: "recovery.recorded"; readonly recovery_id: string; readonly failed_attempt_id: string; readonly kind_detail: RecoveryKind; readonly candidate_id: string; }) | (EventBase & { readonly kind: "validation.recorded"; readonly validation_id: string; readonly unit_id: string; readonly command_fingerprint: string; readonly result: "passed" | "failed"; readonly artifact_id: string | null; }) | (EventBase & { readonly kind: "validation.admission"; readonly reservation_id: string; readonly operation_id: string; readonly evidence_key: string; readonly scope: ValidationScope | null; readonly decision: "ALLOW" | "SKIP" | "DENY"; readonly reason: string; readonly consumed: number; readonly limit: number; readonly saved_ms?: number; }) | (EventBase & { readonly kind: "validation.settled"; readonly reservation_id: string; readonly operation_id: string; readonly evidence_key: string; readonly outcome: ValidationOutcome; readonly exit_code: number | null; readonly evidence_fingerprint?: string; readonly duration_ms?: number; readonly reason?: string; }) | (EventBase & { readonly kind: "unit.completed"; readonly unit_id: string; readonly disposition: "succeeded" | "failed"; }) | (EventBase & { readonly kind: "wave.completed"; readonly wave_id: string; readonly produced_candidate_id: string; readonly artifact_id: string; }) | (EventBase & { readonly kind: "candidate.advanced"; readonly from_candidate_id: string; readonly candidate_id: string; readonly wave_id: string; readonly artifact_id: string; }) | (EventBase & { readonly kind: "candidate.completed"; readonly candidate_id: string; readonly references: FlightReferenceSet; }) | (EventBase & { readonly kind: "cleanup.completed"; readonly run_id: string; readonly observation: FlightObservation; }) | (EventBase & { readonly kind: "run.completed"; readonly run_id: string; readonly disposition: "succeeded" | "failed" | "cancelled"; }); export type RunPlannedFlightEvent = Extract; export type PlanCompiledFlightEvent = Extract; export interface RunFlightLedgerInitialPrefixInput { readonly run_planned: RunPlannedFlightEvent; readonly plan_compiled: PlanCompiledFlightEvent; } export interface RunFlightEventRecord { readonly sequence: number; readonly previous_hash: string | null; readonly event_hash: string; readonly event: RunFlightEvent; } export interface RunFlightState { readonly diagnoses: readonly DiagnosisFlightState[]; readonly children: readonly ChildFlightState[]; readonly run_id: string | null; readonly current_candidate_id: string | null; readonly active_wave_id: string | null; readonly active_unit_id: string | null; readonly active_attempt_id: string | null; readonly last_attempt_id: string | null; readonly completed_wave_count: number; readonly budget_limits: FlightBudgetLimits | null; readonly budget_consumed: FlightBudgetLimits; readonly resource_budget_limits: FlightResourceBudget | null; readonly resource_budget_consumed: FlightResourceUsage; readonly resource_budget_reserved: FlightResourceUsage; readonly child_counts: Readonly>; readonly validation_reruns: number; readonly validation_budget: { readonly consumed: number; readonly reservations: number; readonly limit: number | null; readonly completed: number; readonly skipped: number; readonly rejected: number; readonly redundant_time_ms: number; }; readonly observations: readonly FlightObservation[]; readonly terminal_disposition: "succeeded" | "failed" | "cancelled" | null; readonly plan_decisions: readonly { readonly plan_id: string; readonly proposal_id: string; readonly decision: "accepted" | "rejected"; readonly gap_codes: readonly AcceptanceCompileGapCode[]; }[]; readonly accepted_fabric_waves: readonly Extract[]; } export type RunFlightLedgerErrorCode = "invalid" | "capacity" | "sequence" | "transition" | "budget" | "conflict"; export declare class RunFlightLedgerError extends Error { readonly code: RunFlightLedgerErrorCode; constructor(code: RunFlightLedgerErrorCode, message: string); } export interface ValidationSkipReconciliation { readonly unit_id: string; readonly source: string; readonly candidate: string; readonly command: readonly string[]; readonly evidence: readonly GoalEvidence[]; } export interface RunFlightEvidenceAccess { readonly store: EvidenceCapsuleStore; readonly declared_capsule_ids: readonly string[]; readonly authorized_source_paths: readonly string[]; } export declare function diagnosisContractHash(value: unknown): string; export declare function reconstructRunFlightLedger(records: readonly RunFlightEventRecord[]): RunFlightState; /** Compilation can precede run allocation; no execution budget is invented for planning evidence. */ export declare function createRunFlightPlanPrefix(event: PlanCompiledFlightEvent): readonly RunFlightEventRecord[]; export declare function appendRunFlightLedgerEvents(records: readonly RunFlightEventRecord[], events: readonly RunFlightEvent[]): readonly RunFlightEventRecord[]; export declare function createRunFlightLedgerInitialPrefix(input: unknown): readonly RunFlightEventRecord[]; export declare class RunFlightLedger { #private; private constructor(); static open(filePath: string, evidence: RunFlightEvidenceAccess): Promise; /** Root goal checkpoints share this owner and lock/write discipline without inventing a Git run. */ static openGoal(filePath: string): Promise; /** Read-only Career inventory: validates one existing goal ledger without opening another store. */ static readGoalFile(filePath: string): Promise<{ readonly records: readonly GoalFlightEventRecord[]; readonly state: GoalFlightState; }>; read(): Promise<{ readonly records: readonly RunFlightEventRecord[]; readonly state: RunFlightState; }>; append(event: RunFlightEvent): Promise; appendCompileResult(result: AcceptanceCompileResult, at: string): Promise; reserveValidation(request: ValidationBudgetRequest, limit: number, skipReconciliation?: ValidationSkipReconciliation): Promise; /** Internal operator retry path. Generic reserveValidation remains strict evidence-key dedupe. */ reserveInterruptedValidationRetry(request: ValidationBudgetRequest, limit: number, authorization: GoalValidationRetryAuthorization, skipReconciliation?: ValidationSkipReconciliation): Promise; settleValidation(reservation_id: string, request: ValidationBudgetRequest, outcome: ValidationOutcome, exit_code: number | null, duration_ms?: number): Promise; readGoal(): Promise<{ readonly records: readonly GoalFlightEventRecord[]; readonly state: GoalFlightState; }>; appendGoal(event: GoalFlightEvent): Promise; } export {};