import type { GoalRecord, TodoTreePolicyRecord } from "./events.js"; import type { StreamReadOptions } from "./log.js"; import type { GoalMutationReceiptState } from "../core/cas.js"; import type { GoalTodoClaimSettlementRecord, GoalTodoClaimValidationRecord, GoalTodoDelegationAttemptRecord, GoalTodoReturnedClaim } from "../core/claims.js"; import type { GoalTodoNode } from "../core/types.js"; export interface GoalStoreRevisions { readonly goal: number; readonly todos: number; } /** Claims/delegation side table keyed by attemptId (settlement: last wins). */ export interface GoalClaimsSideTable { readonly attempts: Readonly>; readonly claims: Readonly>; readonly validations: Readonly>; readonly settlements: Readonly>; } export declare function createEmptyClaimsSideTable(): GoalClaimsSideTable; export interface RestoredTodoGraph { readonly goalId: string; readonly revision: number; readonly nodes: readonly GoalTodoNode[]; readonly policy?: TodoTreePolicyRecord; } export interface RestoredGoalStore { readonly status: "ok"; readonly goalId: string; readonly goal: GoalRecord | undefined; readonly todoGraph: RestoredTodoGraph; readonly claims: GoalClaimsSideTable; readonly receipts: GoalMutationReceiptState; readonly revisions: GoalStoreRevisions; } export type RestoreDiagnosticCode = "revision_gap" | "revision_conflict" | "malformed_line" | "truncated_tail" | "unknown_schema" | "stream_too_large" | "receipt_conflict" | "snapshot_invalid" | "snapshot_missing" | "snapshot_lineage_mismatch" | "log_behind_snapshot" | "read_error"; export type RestoreStreamName = "goal" | "todos" | "claims" | "receipts" | "snapshot"; export interface RestoreDiagnostic { readonly code: RestoreDiagnosticCode; readonly stream: RestoreStreamName; readonly goalId: string; readonly line?: number; readonly expectedRevision?: number; readonly receivedRevision?: number; readonly message: string; readonly quarantinedTo?: string; } export interface RestoreBlockedResult { readonly status: "blocked"; readonly diagnostics: readonly RestoreDiagnostic[]; } export type RestoreGoalStoreResult = RestoredGoalStore | RestoreBlockedResult; interface ReceiptsOutcome { state: GoalMutationReceiptState; diagnostics: RestoreDiagnostic[]; } /** * Replay one goal's streams (plus the global CAS receipts). Returns ok with * the full live state, or blocked with diagnostics — never a partial apply. * A goal with no files on disk restores to a clean empty state. */ export declare function restoreGoalStore(stateDir: string, goalId: string, options?: StreamReadOptions): RestoreGoalStoreResult; export interface RestoreAllGoalsIndex { readonly goals: Readonly>; readonly receipts: ReceiptsOutcome; } /** * Index every goals/ directory. Stray entries (non-directories or * non-canonical goal ids) are skipped; the receipts stream is restored once * and its diagnostics merged into each goal's result, so a poisoned CAS * stream blocks every goal exactly like restoreGoalStore would. */ export declare function restoreAllGoals(stateDir: string, options?: StreamReadOptions): RestoreAllGoalsIndex; export {};