import type { WorkspaceBoundary } from "./boundary.js"; import { type CheckpointStore } from "./checkpoint.js"; import type { ExecutionMode, PolicyDecision, RecoveryClass, RollbackCapability, TransactionId } from "./types.js"; export type WorkspaceEdit = { kind: "create_file"; path: string; content: string; } | { kind: "replace_file"; path: string; content: string; expectedSha256?: string; } | { kind: "delete_file"; path: string; } | { kind: "create_directory"; path: string; } | { kind: "delete_directory"; path: string; }; export interface ValidationGate { id: string; /** command identity / human label */ label: string; run: (() => Promise<{ exitCode: number; outputArtifact: string; }>) | null; } export type TransactionStage = "prepared" | "checkpointed" | "applied" | "validating" | "validated" | "confirmed" | "rolled_back" | "recovery_required"; export interface TransactionRecord { transactionId: TransactionId; workspaceId: string; runId?: string; mode: ExecutionMode; createdAt: number; policy: PolicyDecision | null; checkpointId?: string; stage: TransactionStage; appliedPaths: string[]; /** sha of the transaction-intended post-state per path. */ appliedSha: Record; output?: { created: string[]; modified: string[]; deleted: string[]; bytesChanged: number; }; validation?: { command: string; exitCode: number; outputArtifact: string; durationMs: number; timedOut: boolean; aborted: boolean; result: "passed" | "failed" | "skipped" | "timed_out" | "aborted"; }; rollbackCapability: RollbackCapability; } export interface ApplyResult { changed: { path: string; sha256: string | null; }[]; bytesChanged: number; } export interface RollbackResult { status: "rolled_back" | "conflict" | "nothing_to_do"; conflicts: RollbackConflict[]; restored: string[]; } export interface RollbackConflict { path: string; expectedTransactionSha: string | null; currentSha: string; checkpointSha: string | null; message: string; } export declare class TransactionError extends Error { readonly code: string; constructor(code: string, message: string); } /** * Transactional edit batches over the workspace. * * Lifecycle: begin → checkpoint → apply → validate → confirm | rollback → * release. All target paths are resolved/validated up-front. Partial apply * triggers rollback. Validation gates run before confirmation and failed * validation rolls back (rollback is idempotent). Drift caused by unrelated * post-transaction user edits is reported as a structured conflict rather than * silently overwritten. */ export declare class WorkspaceTransactionManager { readonly storageDir: string; private readonly boundary; private readonly checkpoints; constructor(storageDir: string, boundary: WorkspaceBoundary, checkpoints: CheckpointStore); private txPath; begin(workspaceId: string, opts: { runId?: string; mode: ExecutionMode; policy: PolicyDecision | null; rollbackCapability?: RollbackCapability; }): Promise; /** Plan-mode preview: reports intended effect with zero physical mutation. */ preview(edits: WorkspaceEdit[]): Promise<{ created: string[]; modified: string[]; deleted: string[]; bytesChanged: number; }>; resolvePaths(edits: WorkspaceEdit[]): Promise; checkpoint(record: TransactionRecord, editPaths: string[]): Promise; /** * Apply a batch of edits deterministically. Order: create_directory first, * then create_file/replace_file, then delete_file, then delete_directory. * Returns hash results. Drift/expectedSha preconditions abort safely. */ apply(record: TransactionRecord, edits: WorkspaceEdit[]): Promise; validate(record: TransactionRecord, gate: ValidationGate): Promise; confirm(record: TransactionRecord): Promise; persist(record: TransactionRecord): Promise; read(id: TransactionId): Promise; list(): Promise; /** * Drift-aware rollback. Restores prior state from the checkpoint without * overwriting unrelated post-transaction user changes. */ rollback(record: TransactionRecord): Promise; /** Classify an interrupted transaction at startup/resume. */ classify(id: TransactionId): Promise; } //# sourceMappingURL=transaction.d.ts.map