import { WorkspaceManifestMap, type PathManifest, type WorkspacePaths } from "./workspace-manifest.js"; import type { WorkspaceRestoreDiagnostic } from "./workspace-restore-diagnostics.js"; export type SnapshotEntry = { kind: "dir"; } | { kind: "file"; mode: number; hash: string; } | { kind: "symlink"; target: string; }; export interface DirectorySnapshot { exclude: string[]; entries: Map | WorkspaceManifestMap; ignoredPaths?: WorkspacePaths; } export interface LegacySerializedDirectorySnapshot { version: 1; exclude: string[]; entries: Array<[string, SnapshotEntry]>; } export type SerializedDirectorySnapshot = LegacySerializedDirectorySnapshot | { version: 2; exclude: string[]; entries: PathManifest; ignoredPaths?: WorkspacePaths; }; export declare function disposeDirectorySnapshot(snapshot: DirectorySnapshot | null): Promise; /** Call only after the controller validates a persisted manifest's path and digest. */ export declare function openDirectorySnapshot(value: Extract): DirectorySnapshot; export declare function serializeDirectorySnapshot(snapshot: DirectorySnapshot): SerializedDirectorySnapshot; export declare function parseDirectorySnapshot(value: unknown): DirectorySnapshot | null; export declare function directorySnapshotSha256(snapshot: DirectorySnapshot): string; export type DirectoryMergeLockOperation = "agent_directory_prepare" | "agent_directory_release" | "agent_directory_collect" | "agent_directory_checkpoint" | "agent_directory_handoff"; /** * The stable `code` a lock-timeout error carries, so a caller can identify it * without matching on the error message text (the message embeds the lock * directory path). */ export declare const WORKSPACE_RESTORE_LOCK_TIMEOUT_CODE = "ERR_WORKSPACE_RESTORE_LOCK_TIMEOUT"; /** * The closed set of codes a failed workspace restore can carry off the * sandbox. Every code is safe to store on a run record readable by any * same-company actor: none embeds a filesystem path, a raw error message, or * a process id. */ export type WorkspaceRestoreFailureCode = "restore_permission_denied" | "restore_lock_timeout" | "restore_unsafe_archive" | "restore_failed"; /** * The outcome of one workspace restore. `ok: true` on a clean restore. `ok: * false` carries one allowlisted {@link WorkspaceRestoreFailureCode} — never a * raw error, a path, or a process id. */ export type WorkspaceRestoreOutcome = { readonly ok: true; } | { readonly ok: false; readonly code: WorkspaceRestoreFailureCode; readonly diagnostic?: WorkspaceRestoreDiagnostic; }; /** * Classifies a caught workspace-restore error into one allowlisted code. Maps * `EACCES` and `EPERM` to a permission failure, the merge-lock timeout * (matched by {@link WORKSPACE_RESTORE_LOCK_TIMEOUT_CODE}, never by the error * message text) to a lock-timeout failure, and every other error to a generic * failure. The known Daytona confinement diagnostic also identifies unsafe * archives across plugin transports that retain only a message. Never returns * raw messages, paths or process IDs. */ export declare function classifyWorkspaceRestoreFailure(error: unknown): WorkspaceRestoreFailureCode; /** * The fixed, allowlisted line an ACP adapter writes to the run log when a * workspace restore fails. Every call site must pass this to `onLog` instead * of the caught error's own message: the caught error can carry a host * filesystem path or the lock owner's process id, and the run log is * readable by any same-company actor. Never add the code's raw * `Error.message` to this text. */ export declare function describeWorkspaceRestoreFailure(code: WorkspaceRestoreFailureCode): string; export declare function withDirectoryMergeLock(targetDir: string, fn: (canonicalTargetDir: string) => Promise, env?: NodeJS.ProcessEnv, diagnosticOperation?: DirectoryMergeLockOperation, waitMs?: number): Promise; export declare function captureDirectorySnapshot(rootDir: string, options?: { exclude?: string[]; ignoredPaths?: WorkspacePaths; diskBacked?: boolean; }): Promise; /** A disk-backed subset for independent nested-repository merges. */ export declare function selectDirectorySnapshot(snapshot: DirectorySnapshot, options: { prefix?: string; omit?: string[]; exclude: string[]; ignoredPaths?: WorkspacePaths; }): Promise; export declare class DirectoryMergeConflict extends Error { readonly paths: string[]; readonly code = "DIRECTORY_MERGE_CONFLICT"; constructor(paths: string[]); } /** Preflight the entire delta before writing. Identical replays are safe after * an interrupted apply; unrelated edits are left alone. No history is retained. */ export declare function directoryMergeConflicts(baseline: DirectorySnapshot, source: DirectorySnapshot, current: DirectorySnapshot): string[]; export declare function mergeDirectoryWithBaseline(input: { baseline: DirectorySnapshot; sourceDir: string; targetDir: string; conflictPolicy?: "reject"; beforeApply?: () => Promise; afterApply?: () => Promise; /** Caller holds the target's writer lock and validated an immutable sparse * source. Unchanged entries need no payload and are never copied. */ snapshots?: { source: DirectorySnapshot; current: DirectorySnapshot; }; }): Promise; export declare function directoryEntryMatchesBaseline(rootDir: string, relative: string, baselineEntry: SnapshotEntry): Promise; //# sourceMappingURL=workspace-restore-merge.d.ts.map