import { type PersistentCoordinatorOptions } from "./persistence.ts"; import { MutationPermitRegistry, type MutationPermit } from "./permits.ts"; import { type ExecutionOwner, type ExternalMutationModel, type ScopedContentEvidence, type VersionCommitMode } from "./types.ts"; export type { ExternalMutationModel, ScopedContentEvidence, VersionCommitMode } from "./types.ts"; export type { MutationPermit } from "./permits.ts"; export type WriteIntentStatus = "pending" | "committed-content" | "committed-generation" | "aborted-restored" | "dirty-unknown" | "reconciled"; export interface WriteIntentRecord { journalVersion: 1; intentId: string; resourceDomainId: string; providerInstanceId?: string; scopes: ScopedContentEvidence[]; owner: ExecutionOwner; beforeGeneration: number; intentSequence: number; commitGeneration?: number; journalEpoch: number; commitMode: VersionCommitMode; externalMutation: ExternalMutationModel; status: WriteIntentStatus; restorableSnapshotArtifactIds?: string[]; terminalReason?: string; authorizationPrincipalId?: string; authorizationScopeRoot?: string; } export interface RecoverPendingOptions { /** * Return true only when the exact execution owner still holds a live * mutation lease. The callback runs while the journal mutex is held so a * writer cannot create a new intent between the liveness check and the WAL * recovery append. */ isOwnerActive?: (owner: ExecutionOwner) => boolean | Promise; /** Trusted resource backend hook. Return exact before=after evidence only * after restoring every scope from durable pre-state artifacts. */ recoverKnownClean?: (intent: WriteIntentRecord) => Promise<{ scopes: readonly ScopedContentEvidence[]; reason: string; restorableSnapshotArtifactIds?: readonly string[]; } | undefined>; } export interface PrepareWriteIntent { resourceDomainId: string; providerInstanceId?: string; scopes: ScopedContentEvidence[]; owner: ExecutionOwner; /** Optional external CAS assertion. Omit for ordinary writers so generation * sampling and intent creation occur under one journal mutex. */ beforeGeneration?: number; commitMode: VersionCommitMode; externalMutation: ExternalMutationModel; /** Durable pre-state artifacts captured before permit activation. */ restorableSnapshotArtifactIds?: readonly string[]; /** Host-authenticated principal; flow JSON cannot supply this value. */ authorizationPrincipalId?: string; authorizationScopeRoot?: string; permitTtlMs?: number; } export interface CommitWriteIntentOptions { /** Last-moment synchronous validation after permit checks and before WAL. */ preCommitGuard?: () => void; } interface IntentWalRecord { journalVersion: 1; type: "write-intent"; ts: string; intent: WriteIntentRecord; } interface CommitContentWalRecord { journalVersion: 1; type: "write-commit-content"; ts: string; intentId: string; resourceDomainId: string; commitGeneration: number; scopes: ScopedContentEvidence[]; restorableSnapshotArtifactIds?: string[]; } interface CommitGenerationWalRecord { journalVersion: 1; type: "write-commit-generation"; ts: string; intentId: string; resourceDomainId: string; commitGeneration: number; } interface UnknownWalRecord { journalVersion: 1; type: "write-unknown"; ts: string; intentId: string; resourceDomainId: string; reason: string; } interface AbortRestoredWalRecord { journalVersion: 1; type: "write-abort-restored"; ts: string; intentId: string; resourceDomainId: string; reason: string; scopes: ScopedContentEvidence[]; restorableSnapshotArtifactIds?: string[]; } interface ReconcileWalRecord { journalVersion: 1; type: "write-reconcile"; ts: string; resourceDomainId: string; reconcileGeneration: number; intentIds: string[]; reason: string; } export type JournalWalRecord = IntentWalRecord | CommitContentWalRecord | CommitGenerationWalRecord | AbortRestoredWalRecord | UnknownWalRecord | ReconcileWalRecord; export interface JournalManagerOptions extends PersistentCoordinatorOptions { journalEpoch: number; permitRegistry?: MutationPermitRegistry; } export interface PreparedMutation { intent: WriteIntentRecord; permit: MutationPermit; } export interface RecoveryResult { recoveredIntentIds: string[]; restoredIntentIds: string[]; dirtyDomains: string[]; } export interface ReconciliationResult { resourceDomainId: string; previousGeneration: number; generation: number; reconciledIntentIds: string[]; } export declare class JournalStateError extends Error { readonly code = "TFWS_JOURNAL_STATE"; constructor(message: string); } export declare class WriteIntentJournal { #private; readonly walPath: string; readonly journalEpoch: number; readonly permits: MutationPermitRegistry; readonly now: () => number; constructor(options: JournalManagerOptions); prepare(input: PrepareWriteIntent): Promise; /** Verify durable pending intents and atomically CAS all permits to active. */ activate(permits: readonly MutationPermit[], owner: ExecutionOwner): Promise; assertActive(permit: MutationPermit, owner: ExecutionOwner): Promise; commitGeneration(intentId: string, options?: CommitWriteIntentOptions): Promise; commitContent(intentId: string, scopes: readonly ScopedContentEvidence[], restorableSnapshotArtifactIds?: readonly string[], options?: CommitWriteIntentOptions): Promise; markUnknown(intentId: string, reason: string): Promise; /** * Settle an active mutation without advancing the resource generation after * the caller has restored every admitted scope to its exact pre-state. * This is a known-clean terminal state, not reconciliation: callers must * provide content evidence proving `beforeContentId === afterContentId` for * every originally admitted scope. */ abortRestored(intentId: string, scopes: readonly ScopedContentEvidence[], reason: string, restorableSnapshotArtifactIds?: readonly string[]): Promise; /** Explicitly acknowledge the current external filesystem state for one * resource domain. Callers must hold an exclusive whole-domain lease; this * method serializes the durable decision and advances the generation so no * earlier observation can be reused as the reconciled state. */ reconcileDomain(resourceDomainId: string, reason: string): Promise; /** Startup recovery: a stale taskflow-managed content intent may first be * restored by its trusted resource backend. Every other fsynced intent * without a terminal WAL record becomes dirty-unknown before reuse. */ recoverPending(reason?: string, options?: RecoverPendingOptions): Promise; getIntent(intentId: string): Promise; getDomainGeneration(resourceDomainId: string): Promise; listIntents(): Promise; } //# sourceMappingURL=journal.d.ts.map