import type { GovernanceRetryClass } from "./governance-codes.js";
import type { RewindMoved } from "./terminal-cause.js";
import { type FileHistoryRetentionPolicy } from "./file-history-retention.js";
import type { ExecutionEnv, SessionRowExpectation } from "../internal/harness-types.js";
/** rel path of `child` under `root` in "/" form (win root) / verbatim form (posix root); null when not under.
 *  Fold "\" only under a WIN-family root ({@link isWinFormPath}); a POSIX tree may legally contain literal
 *  backslashes in FILE NAMES, and folding them would corrupt both the track key and the restore target. */
declare function relUnder(root: string, child: string): string | null;
/** Join root + a "/"-form relPath using the ROOT's native separator (keys stay family-consistent). */
declare function joinUnder(root: string, rel: string): string;
/** The parent directory of an addressed path, as a pure family-aware string op (no host node:path). */
declare function parentDirOf(absPath: string): string | undefined;
/** The re-join verdict of {@link resolveTrackKey}: an absolute path to operate on, or a NAMED
 *  refusal (the fail-closed arm — a recorded key that would escape `root` is never coerced into
 *  something writable) carrying the restore ledger's class for it. A-082 idx5: named so the fence can be part of the public surface. */
export type FileHistoryTrackKeyResolution = {
    ok: true;
    abs: string;
} | {
    ok: false;
    reason: string;
    class: "key_unresolvable";
};
/**
 * Why a restore declined a file it could reach — the `class` of every {@link FileHistoryRestoreResult.refused}
 * row, named by the arm that decided the refusal (the shared env half and key resolver below, or a backend's
 * own base-unavailable arm) and copied by the backend, never re-derived from the reason text:
 *  · `link_safety` — the object at the path is not the regular file the record describes (a symlink, a
 *    directory or other kind), its parent chain no longer resolves to the recorded identity, or a guarded
 *    write found the path changed under it;
 *  · `base_unavailable` — the first touch recorded that the path's pre-edit bytes could not be read (DV-14),
 *    so there is no pristine version to write;
 *  · `key_unresolvable` — the recorded key cannot be re-joined against this root (it would escape it, or it
 *    came from another path family and is absolute or ambiguous here);
 *  · `recorded_elsewhere` — the version was recorded under another directory than the one this rewind would write
 *    or delete in (its place, {@link placeOfParentViaEnv}), and that directory lies under the root this rewind is
 *    handed (the session's earlier leg worked in a directory below or above this one); the row's `recordedUnder` names
 *    that directory. A version recorded under a directory OUTSIDE this rewind's root is not refused: it is left as it is
 *    (`leftAsIs`, class `recorded_outside_root`) — unless the same rewind restores another file that lies, by its real
 *    path, under the root it was recorded under and outside its own root, which refuses it with this word too;
 *  · `place_unrecorded` — the version records no place (it was recorded before places were kept, by a store that
 *    does not keep them, or it was imported: a place never crosses the export door), so where it belongs cannot be
 *    told; a host that knows where such versions were recorded names it on the rewind (`unplacedHistoryRecordedUnder`). The row's
 *    sentence says the way out as a fact about the host, never as that input's name: a host whose own wire takes the directory under
 *    another key renders its way out from this `class`;
 *  · `changed_since_plan` — the restore was about to write or delete a file its plan did not see that way (the file's
 *    bytes or absence, or the version to restore, differ from what the plan read just before; or the plan did not plan to
 *    move it): another writer changed it between the two ({@link planFileHistoryRestore}). What is there now stays; a rewind
 *    planned again restores it as it then stands.
 * Damage to the store's own records (a missing version record, a missing or corrupt blob) is not a refusal
 * in any backend: it is a `failed` row. A consumer reads the class as an OPEN set (a later release may add a word)
 * and branches on it, never on the reason text.
 */
export declare const FILE_HISTORY_REFUSAL_CLASSES: readonly ["link_safety", "base_unavailable", "key_unresolvable", "recorded_elsewhere", "place_unrecorded", "changed_since_plan"];
export type FileHistoryRefusalClass = (typeof FILE_HISTORY_REFUSAL_CLASSES)[number];
/**
 * Why a rewind LEFT a tracked file as it is without counting it refused or failed — the `class` of a {@link FileHistoryLeftAsIsFile}
 * row (`leftAsIs` on a restore, on a preview, on `rewind.restore_failed`'s detail). A CLOSED set, one word per reason; what a row of
 * any class means is the member's own: the file was neither written nor deleted, it is not in `files` / `filesChanged`, it is not an
 * outcome (a restore whose every other file converged is `complete`), and a later rewind of the same kind leaves it again.
 *  · `frozen_history` — the entry's history is frozen ({@link fileHistoryEntryFrozen}): a version of the file was recorded through a
 *    link on its key's path, so the key names one file and its history another; no boundary reads it, no rewind writes or deletes
 *    it, no export carries it.
 *  · `recorded_outside_root` — the version the rewind would restore was recorded under a directory outside the root this rewind is
 *    handed (the session's earlier leg worked there, or this fork's source did; that directory may since have been deleted), and
 *    the file there no longer holds it: this rewind neither writes nor deletes it there nor at its own root ({@link
 *    applyFileRestoreViaEnv}); a rewind handed the root it was recorded under (its old root: `place` with its key's directory
 *    segments taken off) restores it. Also, when the session being rewound is a fork (its row carries `forkedFrom` other than its
 *    own id), every file whose real path lies outside the rewind's root is left as it is under this class — neither written,
 *    deleted nor re-moded — whether inherited from its source or edited by the fork itself, so a person can restore it by hand or
 *    from the source session. Its `place` is the file's own directory.
 * A row is listed only when the restore moved nothing in what it speaks for — a `recorded_outside_root` row the part of its old
 * root outside the rewind's own root (no file there is written, deleted or re-moded by the same restore, under any key), a
 * `frozen_history` row its file, which no key of the same restore writes, deletes or re-modes (another key that would is held
 * before it does and refused `link_safety`); otherwise it is refused instead — `recorded_elsewhere` for `recorded_outside_root`,
 * `link_safety` for a `frozen_history` row whose file another key would have moved (both rows then say neither key wrote it).
 * A consumer branches on the class, never on the reason text.
 */
export declare const FILE_HISTORY_LEFT_AS_IS_CLASSES: readonly ["frozen_history", "recorded_outside_root"];
export type FileHistoryLeftAsIsClass = (typeof FILE_HISTORY_LEFT_AS_IS_CLASSES)[number];
/**
 * One file a rewind left as it is ({@link FILE_HISTORY_LEFT_AS_IS_CLASSES}): `path` is its key (as on a `files` row), `place` the
 * directory (absolute real path) its history records that this rewind does not land on — a path on the machine that recorded it,
 * which two sentences name beside the key, read off this row (a run's `restore_left_as_is` note and the person's
 * `rewind.file_left_as_is` notice: "<key> (in <place>)"); no ledger line, notice `detail`, envelope or model-facing text carries it —
 * `class` why, `reason` the row's own sentence for a person (it names no path).
 */
export interface FileHistoryLeftAsIsFile {
    path: string;
    place: string;
    class: FileHistoryLeftAsIsClass;
    reason: string;
    /** {@link FileHistoryRewindFile.outsideRoot}, read off `place`: whether the file lies outside the root this rewind is handed — for
     *  `recorded_outside_root` always `true`; for `frozen_history` the fact (a link inside the root that led out of it ⇒ `true`, one that
     *  led to another directory inside it ⇒ `false`). On every row the engine answers; a store's own rows leave it out. */
    outsideRoot?: boolean;
}
/** The path family a track key was MINTED under — the half a bare key string cannot carry. */
export type FileHistoryKeyFamily = "posix" | "win";
/**
 * A track key's SELF-DESCRIPTION (design/381 §3 amendment, closing the A-082 r2 registered
 * residual): a key is a bare string, so it carries the shape it was minted in but never the family
 * it was minted under. Recorded beside every tracked path and carried by the session-sync envelope,
 * so a graph that arrives from ANOTHER MACHINE can be judged at the door instead of silently
 * re-joining under the local root as an oddly-named in-root file.
 */
export interface FileHistoryTrackKeyDescriptor {
    /** `"root-relative"` = re-join against the CURRENT root; `"absolute"` = restore where captured. */
    kind: "root-relative" | "absolute";
    family: FileHistoryKeyFamily;
}
/**
 * Whether an entry travels with its history into another session: a fork's or a deletion cascade's carry (`adoptScope`) and an
 * export (`exportHistory`) take only the entries under a ROOT-RELATIVE key. An absolute-key entry is a file this session edited
 * outside its root, or a second file whose root-relative name another directory's file already keys; carried, it would restore
 * the source's file where the source still works, and an import door refuses it. So, carried and imported histories aside, an
 * absolute key in a history is that session's own edit. **Exported under the "MUST reuse" clause**: a backend that carries or
 * exports an absolute-key entry keeps the write into the source's file.
 */
export declare function fileHistoryEntryTravels(key: FileHistoryTrackKeyDescriptor): boolean;
/**
 * Whether a tracked entry is FROZEN, judged from the entry alone — its key and the places its versions record — so a boundary, a
 * rewind, an export and the read-only check ({@link listFrozenFileHistoryEntries}) give one answer whatever the root a leg is
 * handed and whatever the tree holds now. Frozen = a ROOT-RELATIVE key one of whose versions records a place (its parent's real
 * path, {@link placeOfParentViaEnv}) whose last segments are not the key's own directories: when that version was recorded the
 * key's path ran through a link (an engine ≤ 7.68.1 recorded the real parent of a key a link inside the root led out of it; a
 * host's own `trackEdit` of a path through a link did the same before a key followed the file's real path,
 * {@link trackKeyForEdit}). The key then names one file and its history another, so neither side is trusted: a boundary does not
 * read the file (the entry keeps its last version), a rewind neither writes nor deletes it (the restore lists it in `leftAsIs`,
 * class `frozen_history`), and an export leaves the entry and its bytes out (`frozenEntryKeys`). An absolute key is never frozen
 * (it is its own place), nor is a key directly under its root, nor a version that records no place. Directories are compared
 * folded the way a case- and normalization-insensitive volume compares names. Answers the `leftAsIs` row without its `path` —
 * the class, the place that does not match and the sentence for a person (it names no path) — `undefined` when the entry is not
 * frozen. **Exported under the "MUST reuse" clause**, for every backend's `snapshot` (through {@link resolveTrackedFile}),
 * `restore` (a hit is `leftAsIs.push({ path: key, ...hit })`, before any env call) and `exportHistory`.
 */
export declare function fileHistoryEntryFrozen(entry: {
    readonly key: string;
    /** The key's self-description; absent (a record minted before it was kept) = read as an export declares it: POSIX-family, and
     *  absolute exactly when the key is absolute in that family — no root is consulted, so every seat reads the entry alike. */
    readonly desc: FileHistoryTrackKeyDescriptor | undefined;
    readonly versions: ReadonlyArray<{
        readonly parentIdent?: string;
    }>;
}): (Omit<FileHistoryLeftAsIsFile, "path"> & {
    class: "frozen_history";
}) | undefined;
/**
 * What a restore to a boundary converges ONE tracked entry to ({@link fileHistoryTargetOf}): the version's bytes (by their content
 * address — fetching and checking them is the store's), the version's deletion marker (`absent`), no version at all because the
 * entry was tracked after the boundary and its pristine base was never captured (`base_unavailable`, refused), a frozen entry (left
 * as it is: the `leftAsIs` row without its `path`), or a version the entry's chain does not hold (`record_missing`, store integrity).
 */
export type FileHistoryTarget = {
    readonly kind: "bytes";
    readonly version: number;
    readonly hash: string;
    readonly mode?: number;
    readonly parentIdent?: string;
} | {
    readonly kind: "absent";
    readonly version: number;
    readonly parentIdent?: string;
} | {
    readonly kind: "base_unavailable";
} | ({
    readonly kind: "frozen";
} & Omit<FileHistoryLeftAsIsFile, "path">) | {
    readonly kind: "record_missing";
    readonly version: number;
};
/**
 * THE target a restore to a boundary converges an entry to, judged from the entry and the boundary's mapping alone — no env, no root,
 * no bytes read. In order: a frozen entry ({@link fileHistoryEntryFrozen}) is left as it is; otherwise the version the boundary maps
 * the entry to, or — an entry tracked after the boundary (`versionAtBoundary` undefined) — its pristine v1, which an entry whose base
 * was never captured does not have (`base_unavailable`); that version's record (`record_missing` when the chain does not hold it); its
 * deletion marker (`absent`) or its bytes' address (`bytes`, with the mode and place it records).
 * **Exported under the "MUST reuse" clause**: every backend's `restore` takes each entry's target here and acts on it — the caller's
 * abort is judged after the frozen arm and before every other (a frozen entry is listed even under an abort, as before any env call),
 * the key is then resolved against the root, and the bytes are fetched and checked — and so does its `readBoundaries`, so the targets a
 * reader is shown are the ones a restore converges to.
 */
export declare function fileHistoryTargetOf(entry: {
    readonly key: string;
    /** The key's self-description as {@link fileHistoryEntryFrozen} reads it (absent = a record minted before it was kept). */
    readonly desc: FileHistoryTrackKeyDescriptor | undefined;
    readonly baseAvailable: boolean;
    readonly versions: ReadonlyArray<{
        readonly version: number;
        readonly blobHash: string | null;
        readonly mode?: number;
        readonly parentIdent?: string;
    }>;
}, versionAtBoundary: number | undefined): FileHistoryTarget;
/** One tracked entry as a boundary reads it ({@link FileHistoryStore.readBoundaries}): its key, the key's self-description (a record
 *  that predates it declares the shape its key was recorded in, POSIX-family), and its {@link fileHistoryTargetOf} answer. */
export interface FileHistoryBoundaryEntry {
    readonly key: string;
    readonly keyDesc: FileHistoryTrackKeyDescriptor;
    readonly target: FileHistoryTarget;
}
/** One boundary's answer in {@link FileHistoryStore.readBoundaries}: its entries; `boundary: null` = no such boundary (never made, or
 *  reaped: exactly when `restore` answers `not_found`); `ok: false` = the boundary is there and cannot be read, or the tracked set it
 *  reads cannot be read or judged (`restore_failed`, with the fault's permanence when the store judged one). */
export type FileHistoryBoundaryReadResult = {
    readonly ok: true;
    readonly boundary: null;
} | {
    readonly ok: true;
    readonly boundary: {
        readonly entries: readonly FileHistoryBoundaryEntry[];
    };
} | {
    readonly ok: false;
    readonly error: FileHistoryError;
};
/** {@link FileHistoryStore.readBoundaries}' answer: one key per distinct id asked, each valued with the answer that id gets asked
 *  alone; `ok: false` only when the call cannot tell which of the ids are boundaries at all. */
export type FileHistoryBoundariesReadResult = {
    readonly ok: true;
    readonly boundaries: ReadonlyMap<string, FileHistoryBoundaryReadResult>;
} | {
    readonly ok: false;
    readonly error: FileHistoryError;
};
/**
 * Whether a version's recorded `parentIdent` travels with an exported history. A place (an absolute path: the directory the
 * version was recorded under) does not — it names a directory on the machine that recorded it, a boundary re-reads a tracked
 * file at its place, and so an import door refuses an envelope that carries one, exactly as it refuses an absolute key. The
 * root-relative form an older engine recorded travels (no engine reads it as a place). **Exported under the "MUST reuse"
 * clause**: a backend's export leaves out every `parentIdent` this answers `false` for, or the importing door refuses its
 * envelope whole.
 */
export declare function fileHistoryParentIdentTravels(parentIdent: string): boolean;
/** The family of a root — the one place a backend asks "which family am I operating in?". */
export declare function trackKeyFamilyOf(root: string): FileHistoryKeyFamily;
/**
 * {@link trackKeyOf} plus the self-description a backend must record with it. Mint through THIS and
 * a graph stays judgeable after it crosses machines; mint through the bare key alone and the
 * provenance is gone for good (the residual this closes).
 */
export declare function describeTrackKey(root: string, absPath: string): {
    key: string;
} & FileHistoryTrackKeyDescriptor;
/**
 * Track-key coordinate (design/381 DV-6, the CC `wZu` relativization ported to the trusted task
 * root): a path under `root` is recorded root-RELATIVE (a restore re-joins it on the leg's root, and
 * writes there only when that is the place the version records), a path outside `root` is recorded
 * verbatim-absolute.
 *
 * **Exported as part of the "MUST reuse, NOT re-implement" set** (A-082 idx5, the same §3 分工
 * clause that governs the two env halves): every backend mints keys from the `(absPath, root)` pair
 * `trackEdit`/`snapshot` hand it and re-joins them in `restore`, so this pair — not the env halves —
 * is where a hand-rolled backend re-introduces path escape. The escape check lives INSIDE the pair
 * (mint refuses to record an ambiguous rel form; {@link resolveTrackKey} refuses an unsafe recorded
 * one), so a backend that calls them cannot re-open the hole, and one that re-derives them must
 * re-derive the family-conditional bare-drive rule and the '..' fail-closed arm correctly on its own.
 */
export declare function trackKeyOf(root: string, absPath: string): string;
/**
 * Re-join a recorded track key against the CURRENT root (identity for absolute keys) — the
 * {@link trackKeyOf} mirror, exported under the same "MUST reuse" clause. A key that would escape
 * the root is REFUSED by name, never coerced: `{ok:false}` is the fail-closed arm a backend must
 * surface as a per-file `refused` row, not silently drop.
 *
 * CROSS-FAMILY PROVENANCE (A-082 codex r2, registered in slice 1 — CLOSED here in slice 2 exactly as
 * that note prescribed). A key is a bare STRING: it carries the shape it was minted in, never the
 * FAMILY it was minted under. Every key minted against this scope's own root resolves by the mirror
 * above — but a scope carried in from another machine (the {@link FileHistoryExport} envelope,
 * `adoptScope` across hosts) can hold a key whose family differs from the current root's, and under
 * a POSIX root a win-absolute record (`D:\other\x`) used to re-join UNDER the root as an oddly-named
 * in-root file (contained, never traversal — but not the file the record meant). The closure is the
 * §3 amendment the note named: a SELF-DESCRIBING key ({@link FileHistoryTrackKeyDescriptor}: kind +
 * source family) recorded beside every tracked path and carried by the versioned envelope, judged
 * HERE through the optional `minted` argument. Omit it and this function is byte-identical to
 * before; pass it and a foreign-family record is refused by name instead of coerced.
 */
export declare function resolveTrackKey(root: string, key: string, minted?: FileHistoryTrackKeyDescriptor): FileHistoryTrackKeyResolution;
/** The file-history failure codes, spelled once: {@link FileHistoryError}'s `code` is derived from this tuple (each
 *  word is documented there). A host that recognizes a code in failure text, or keeps a code in a store, reads this
 *  value rather than keeping its own list. */
export declare const FILE_HISTORY_ERROR_CODES: readonly ["track_failed", "snapshot_failed", "restore_failed", "adopt_failed", "not_found", "aborted", "unsupported_format", "conflict", "too_large"];
/** Where a {@link FileHistorySizeLimit} comes from: `"store_option"` = the store was configured with it (the bundled stores'
 *  `maxBlobBytes`); `"backend"` = the storage medium's own bound, which the store read from it (a database's packet limit). A
 *  CLOSED SET with one home, registered in `docs/CLOSED-SETS.md`. */
export declare const FILE_HISTORY_LIMIT_SOURCES: readonly ["store_option", "backend"];
export type FileHistoryLimitSource = (typeof FILE_HISTORY_LIMIT_SOURCES)[number];
/** The bound a `too_large` refusal names: the most bytes ONE stored copy of a file may hold (a copy of exactly this many is stored),
 *  and where the bound comes from. */
export interface FileHistorySizeLimit {
    readonly bytes: number;
    readonly source: FileHistoryLimitSource;
}
/**
 * THE `too_large` refusal — the one mint every store answers it with (a backend of another kind included): `code` `too_large`,
 * `permanence` `terminal` (the same bytes never fit under the same bound), `limit` the bound and its source, and a sentence naming
 * what was refused, its size and the bound — no stored content. `size` is the refused copy's byte length.
 */
export declare function fileHistoryTooLarge(input: {
    readonly what: string;
    readonly size: number;
    readonly limit: FileHistorySizeLimit;
}): FileHistoryError;
/** A bundled store's `maxBlobBytes` option, read once at construction: absent = no bound; else a safe integer, 0 or more — any other
 *  value is refused there (`config.invalid_argument`), never read as "no bound". */
export declare function readMaxBlobBytes(owner: string, value: unknown): number | undefined;
/** A bundled store's judgment of one copy it is about to store under its `maxBlobBytes`: `undefined` = it fits (a copy of exactly
 *  the bound fits), else the {@link fileHistoryTooLarge} refusal. Measured in bytes, never characters. */
export declare function blobOverStoreLimit(bytes: Uint8Array, maxBlobBytes: number | undefined, what: string): FileHistoryError | undefined;
/** A refusal as a verb's failed answer (`undefined` stays `undefined`). */
export declare function overLimit(error: FileHistoryError | undefined): {
    readonly ok: false;
    readonly error: FileHistoryError;
} | undefined;
export interface FileHistoryError {
    /** `not_found` = no boundary for that (scope, entryId) — an absence, never a fault (a boundary that is there
     *  but cannot be read is the verb's `*_failed` with the fault); `aborted` = the signal fired (or the
     *  fencing discarded a timed-out attempt); `conflict` = a HISTORY-PRESERVATION law refused the call:
     *  doing it would discard or overwrite history that is not the caller's — `adoptScope` / `importHistory`
     *  onto a target that holds history of its own (the non-destructive-target law), or `annulTrack` of a
     *  record that is no longer just the caller's own mint (a boundary froze it, it grew past its first
     *  version, another edit was served it, or the proof read found the file moved or the base-unavailable
     *  marker standing). It is never a fault, and it is never "could not judge": a verb that cannot JUDGE its
     *  law (an unreadable graph, a listing that fails, a proof read that cannot re-read the path) answers its
     *  own `*_failed` (or `aborted`) with the fault. A caller reads `conflict` as "the law answered; the history
     *  stands" — the engine's fork-carry seat says nothing on it because the only verb that seat calls is
     *  `adoptScope`, whose `conflict` is the target law alone, so an adoption that failed for any OTHER
     *  reason (a corrupt source graph, a blob it cannot reach, a consumed-id ledger it cannot carry, a target
     *  whose history cannot be judged) must NOT wear this
     *  code or the failure disappears into that silence — those are `adopt_failed`, which the
     *  ADOPTION FAMILY shares: `importHistory` publishes under the same target law and answers the
     *  same code for the same non-conflict failures — a source that cannot supply a referenced blob (it is
     *  absent, its read throws, or its bytes do not hash to their address), a target whose history cannot
     *  be judged, a fault in staging or publishing a good graph (the disk refusing it) — and `exportHistory`
     *  answers it for a history it cannot read whole. `unsupported_format` is the import DOOR's refusal and
     *  nothing else: a foreign-epoch or wrong-version envelope, or an envelope whose content the closed sets
     *  (or the backend's own record-naming rules) cannot hold, refused before any blob is fetched; `too_large` = one copy of a file
     *  the verb would store (a first touch's pristine bytes, a boundary's capture, an imported or exchanged blob) is over the store's
     *  bound — the call commits nothing (no record, no boundary, no imported graph; a copy an earlier file of the same call already
     *  wrote is not referenced by anything this call commits, as after any failed attempt), `limit` says the bound and where it comes from, `permanence` is `terminal`
     *  ({@link fileHistoryTooLarge}, the one mint); the rest name the verb that failed. */
    code: (typeof FILE_HISTORY_ERROR_CODES)[number];
    message: string;
    /** On `too_large`, and only there: the bound the copy is over ({@link FileHistorySizeLimit}). */
    limit?: FileHistorySizeLimit;
    /** The backend's judgment of a FAULT — it could not do what it was asked — as a {@link GovernanceRetryClass}
     *  word (the words are defined there, once). Stated whenever the backend knows: from a caught error's code,
     *  or from a state it found itself (a damaged record is `terminal`). Absent when it does not know, and on an
     *  outcome that is not a fault (an absent boundary's `not_found`, the empty-target law, an abort). Every
     *  reader — the engine's edit refusal, the rewind disclosure, a failed rewind task's `terminal.detail`, a
     *  host's metrics — reads this cell, never the message text. */
    permanence?: GovernanceRetryClass;
}
/** A fault's judgment as the member a {@link FileHistoryError} spreads in: `{ permanence }` when judged, `{}`
 *  when not — so an unjudged failure carries no `permanence` member at all. */
export type FileHistoryFault = {
    readonly permanence?: GovernanceRetryClass;
};
/** The bundled backends' ONE reading of a caught value — by its `code` member only, never its message. A string `code`
 *  that is exactly one of fourteen errno words is judged, `{ permanence }`: `"terminal"` for `EACCES` / `EPERM` (no
 *  permission), `EROFS` (a read-only mount), `ENAMETOOLONG` (a name the filesystem cannot hold), `EFBIG` (a file size it
 *  cannot hold), `ENOTDIR` / `EISDIR` (a file where a directory belongs, or the reverse); `"transient"` for `EAGAIN` /
 *  `EWOULDBLOCK` / `EBUSY` (contention), `EINTR` (an interrupted call), `ETIMEDOUT` (a timed-out one), `EMFILE` / `ENFILE`
 *  (exhausted descriptors). Anything else is not judged and answers `{}` — an object with no `permanence` member at all:
 *  another code (`ENOENT`; `ENOSPC`, `EDQUOT` and `ENOMEM` on purpose — whether anything frees a full disk, a quota or
 *  the memory is not the store's to know; a lower-case spelling; a code of another system), a `code` that is no string, a
 *  value with no `code` (a plain `Error`, a string, `null`, `undefined`), and a `code` whose read throws. The member is
 *  read through the prototype chain and the call never throws; each call answers a new object. */
export declare function caughtFault(caught: unknown): FileHistoryFault;
/** A record the backend found damaged (unparseable, the wrong shape, failing its own digest): no retry
 *  repairs it. */
export declare const DAMAGED_RECORD: FileHistoryFault;
/**
 * The `Error` the engine hands `RunnerDeps.onError` on every `phase: "rewind"` delivery: `code` and
 * `permanence` are the failure's own, read the same way as on a {@link FileHistoryError}; `message` is the
 * engine's sentence about it (not the store's text). A failure the engine itself observed carries the same
 * shape: a timed-out capture is `aborted`; a backend that threw instead of answering is the verb's own
 * `*_failed` code with no `permanence` and the thrown value as the standard `Error.cause`.
 */
export declare class FileHistoryStoreError extends Error implements Pick<FileHistoryError, "code" | "permanence"> {
    readonly code: FileHistoryError["code"];
    readonly permanence?: FileHistoryError["permanence"];
    constructor(failure: Pick<FileHistoryError, "code" | "permanence">, message: string, thrown?: {
        value: unknown;
    });
}
export type FileHistoryResult = {
    ok: true;
} | {
    ok: false;
    error: FileHistoryError;
};
/**
 * {@link FileHistoryStore.trackEdit}'s answer. `minted` is the ANNUL HANDLE in boolean form (#491):
 * true = THIS call created the first-touch record, so the caller may {@link
 * FileHistoryStore.annulTrack} it if the edit that record was minted for never lands; false = the
 * path was already tracked (a cheap no-op), and annulling would destroy a record some EARLIER edit
 * legitimately owns. A backend that cannot tell answers `false` — the safe side (a stale record is
 * a cowork hazard, but discarding someone else's pristine baseline is worse).
 */
export type FileHistoryTrackResult = {
    ok: true;
    minted: boolean;
} | {
    ok: false;
    error: FileHistoryError;
};
/** {@link FileHistoryStore.exportHistory}'s answer: the envelope, `null` = nothing to export (the one meaning of
 *  `null`), or a history that cannot be read whole — `adopt_failed` with the fault, naming what cannot be read. */
export type FileHistoryExportResult = {
    ok: true;
    history: FileHistoryExport | null;
} | {
    ok: false;
    error: FileHistoryError;
};
/**
 * Three-state discriminant + full per-file ledger on EVERY arm (design/381 DV-15). Refusals are
 * never folded into benign skips; `base_unavailable` (DV-14) is a refusal reason.
 */
export type FileHistoryRestoreResult = {
    /** `"complete"` = every target applied or identical; `"partial"` = ≥1 refused or failed, others
     *  applied; `"failed"` = the operation itself could not run (e.g. no such boundary). */
    outcome: "complete" | "partial" | "failed";
    /** Track keys written or deleted (the converged set). */
    filesChanged: string[];
    /** Track keys already equal to the target (untouched — content-hash proven, never mtime). */
    identicalSkipped: string[];
    /** Per-file security/consistency refusals (skipped, counted, never failing the whole restore); `class` is
     *  the reading of why ({@link FileHistoryRefusalClass}), `reason` the sentence for a person (a consumer branches on
     *  `class` only). `recordedUnder` — on a `recorded_elsewhere` row — is the directory the version was recorded under, its
     *  absolute real path (where a person goes to rewind it); `action` is what the restore would have done there. A store
     *  that does not pass them through answers the row without them. */
    refused: Array<{
        path: string;
        reason: string;
        class: FileHistoryRefusalClass;
        recordedUnder?: string;
        action?: "write" | "delete";
    }>;
    /** Per-file operational failures (env write/remove errors, aborts after k writes). */
    failed: Array<{
        path: string;
        reason: string;
    }>;
    /** Files whose recorded POSIX mode could not be re-applied (env without the optional mode face). */
    modeNotPreserved?: number;
    /** Present on outcome:"failed" (operation-level cause) and optionally on "partial". */
    error?: FileHistoryError;
    /** Every file the restore wrote, deleted or refused, one row each ({@link FileHistoryRewindFile}) — minted by the engine
     *  (`Runner.rewindFiles`, a run's restore) from what the restore did, never by a store. Absent = an engine that does not
     *  answer per-file facts (an older one), which is not "nothing was refused". */
    files?: FileHistoryRewindFile[];
    /** The tracked files this restore LEFT as they are, one row each with its class ({@link FileHistoryLeftAsIsFile},
     *  {@link FILE_HISTORY_LEFT_AS_IS_CLASSES}) — apart from `filesChanged`, `identicalSkipped`, `refused`, `failed` and `files`,
     *  and never counted in `outcome` or in a run's whole-or-nothing judgment, whatever the class: a row here is not a refusal a
     *  later rewind of the same kind could clear. `complete` with `leftAsIs` rows is a whole restore of everything else. Absent =
     *  none (or a store that does not judge it). */
    leftAsIs?: FileHistoryLeftAsIsFile[];
};
/**
 * One file of a rewind, as the engine answers it beside the counts and lists (`files` on a preview and on a restore): `path`
 * is the key the history records the file under — its name relative to the root it was recorded against, or its absolute
 * path when that relative name was already the key of a file at another place; `targetPath` is the absolute path THIS rewind
 * writes or deletes for it (the key joined on this leg's root; an absolute key is its own) — on a refused row, where it would
 * have landed, which is the other half of why it was refused (`refused.recordedUnder` is the first half). `filesChanged`,
 * `refused` and `failed` stay as they are; `files` is the same rewind file by file.
 */
export interface FileHistoryRewindFile {
    path: string;
    targetPath: string;
    /** What the rewind does at `targetPath`; on a refused row, what it would have done (absent when the store did not say). */
    action?: "write" | "delete";
    refused?: {
        class: FileHistoryRefusalClass;
        reason: string;
        recordedUnder?: string;
    };
    /** A file the restore wrote or deleted (`action`) that the store then answered as failed (its `failed` row's reason): the
     *  write landed, so it is named here. */
    failed?: {
        reason: string;
    };
    /** Whether the file this row speaks for lies outside the root this rewind is handed (a file the session edited outside it, under
     *  its absolute key; a key that would escape it; a key spelled through a link inside the root that leads out of it) — read where
     *  the file really lies: the real path the shared restore step's own preflight stated for `targetPath` (its directory's real path
     *  joined with the leaf) when the restore went through that step, else `targetPath` itself; the same containment reading the
     *  restore judges a recorded directory with ({@link outsideRootOf}); whatever the row's action, refusal or failure. A machine bit
     *  for a shell (no directory is named beside it; the path stays `targetPath`, as addressed). On every row the engine answers
     *  (`true` or `false`); absent = an engine before 7.69.0, which does not say — never "inside". */
    outsideRoot?: boolean;
}
/** What a rewind tells the restore beyond its coordinates ({@link FileHistoryStore.restore}'s last argument). */
export interface FileHistoryRestoreOptions {
    /**
     * The directory this session's OLDER versions were recorded under — the ones that record no place (recorded before
     * places were kept). Given, such a version is read as recorded at this directory plus the parent it names relative to
     * its root, and goes through the same comparison as every other version: converged only where this rewind lands it,
     * else left as it is (`recorded_outside_root`) when that directory lies outside the rewind's root, refused
     * `recorded_elsewhere` when it lies under it. Not given, it is refused `place_unrecorded`. A version that records its place never
     * reads it. An absolute path, read in the rewind's env (its real path), stated by a host that knows where the session's
     * legs ran before (a transcript that stamps each turn's directory) — not a promise, a fact of the same standing as the
     * root the host hands a leg. It asserts where THIS HISTORY was recorded: filled with the current leg's root by default
     * while the history was recorded elsewhere, it writes the older versions by relative key at the current root — the very
     * shape the recorded place exists to refuse. A directory that no longer exists is a legitimate answer (it was deleted
     * since): its files are read like any other version recorded there (left as they are outside the rewind's root).
     */
    unplacedHistoryRecordedUnder?: string;
}
/** The word a host writes for `unplacedHistoryRecordedUnder` (on `TaskSpec` and `Runner.rewindFiles`, never on a store's own `restore`)
 *  when the directory this session's older versions were recorded under is this rewind's own root — the root the engine joins the
 *  session's keys on (a session that works in a tree of its own: that tree), which a host does not have to know or spell: the host
 *  states the fact, the engine supplies the path. */
export declare const UNPLACED_AT_REWIND_ROOT = "rewind_root";
/** The restore's options as the store is handed them at `root` (the rewind's own root, the one its keys are joined on): the word
 *  {@link UNPLACED_AT_REWIND_ROOT} read as that root; any other value as it is. Every seat that hands options to a store asks this. */
export declare function restoreOptionsAt(options: FileHistoryRestoreOptions | undefined, root: string): FileHistoryRestoreOptions | undefined;
export interface FileHistoryDiffStats {
    filesChanged: string[];
    insertions: number;
    deletions: number;
    /** The preview file by file ({@link FileHistoryRewindFile}), refused rows included — the projection of the very plan a
     *  restore would carry out. Absent = an engine that does not answer per-file facts. */
    files?: FileHistoryRewindFile[];
    /** The files the restore would leave as they are, with their class — the plan's own `leftAsIs`
     *  ({@link FileHistoryRestoreResult.leftAsIs}). Absent = none. */
    leftAsIs?: FileHistoryLeftAsIsFile[];
    /** The plan's refused rows and its failed rows — {@link FileHistoryRestoreResult.refused} / `failed`, the restore's own members,
     *  row for row: what the restore would decline, and what it could not judge or reach before any write (a version record or a
     *  blob the store cannot read, an aborted attempt). A preview with both empty is a complete plan (`leftAsIs` rows do not make it
     *  incomplete). Absent = an engine that does not answer them — never "none". */
    refused?: FileHistoryRestoreResult["refused"];
    failed?: FileHistoryRestoreResult["failed"];
}
/** `Runner.rewindFiles`' request — the out-of-run code-only rewind (the reference's `rewind_files` control request). */
export interface RewindFilesRequest {
    /** The session whose history is converged. It must exist. Its files are converged where its runs recorded them: a session
     *  that works in its own tree (`TaskSpec.workspace`) in that tree, never the base checkout; a checkout that cannot be resolved
     *  (record unreadable, released, tree gone) refuses with the session checkout's code and nothing moved. */
    sessionId: string;
    /** The boundary key: the entry id of the person's input that opened a turn (its run's first row of a person's
     *  input; an engine entry ahead of it, such as a task notification, is not one) — the id space `TaskSpec.rewindFilesTo`
     *  addresses ("the files as they were when that turn began"). An entry with no boundary of its own refuses, and so does an
     *  entry the session's own log does not hold (an id that was erased and created again does not rewind to the earlier
     *  occupant's turns) — both `rewind_snapshot.unresolvable`, with nothing moved. */
    to: string;
    /** Preview only: the working tree is not written (a fork whose history was never carried may have its carry
     *  completed — the same carry the session's next run performs). */
    dryRun?: boolean;
    /** Caller cancel for the restore. */
    signal?: AbortSignal;
    /** {@link FileHistoryRestoreOptions.unplacedHistoryRecordedUnder}, for this rewind (preview and restore alike) — or the word
     *  `"rewind_root"`: this rewind's own root, which the engine supplies (as `TaskSpec.unplacedHistoryRecordedUnder` reads it). */
    unplacedHistoryRecordedUnder?: string;
    /** The occupant the caller read the session as: `{ row: { owner, incarnation } }` (a `SessionHead` serves as `row`) — the
     *  session under `sessionId` must still be that row (`sessionRowMatches` on the acquired session), or nothing is rewound and
     *  the answer is `resume.session_not_found`. `row: null` and `log` are refused (`rewind.invalid_spec`). Absent ⇒ any
     *  session under the id. The same member, read the same way, as `CompactSessionRequest.expect`. */
    expect?: SessionRowExpectation;
    /** The directory the session works in, stated by the caller: an absolute host path (`isAbsoluteHostPath`,
     *  `@sema-agent/primitives` — the judgment an Agent call's explicit `cwd` meets; anything else is `rewind.invalid_spec`). It is
     *  handed to the factory as `ExecutionEnvFactoryContext.requestedCwd`, and the env is held to it before anything is read or
     *  written: no factory ⇒ `config.cwd_unsupported`; outside a declared `RunnerDeps.rootPath` ⇒ `config.cwd_outside_root`; an
     *  env that stands elsewhere ⇒ `config.cwd_not_honored`. Absent ⇒ the factory attaches to the workspace it holds for the
     *  session (and refuses, its own refusal passed through, when it holds none). */
    cwd?: string;
    /** `CompactSessionRequest.holder`'s member on the file rewind (its request door answers a bad value `rewind.invalid_spec`). This verb writes no session entry, so the holder fences its session side only: the
     *  files themselves move through the history store on the execution environment, which no session fence reaches — the host's own
     *  grant (its run row) guards that part. */
    holder?: string;
}
/** `Runner.rewindFiles`' answer. A refusal is a thrown `Error` carrying a `code`. */
export type RewindFilesResult = 
/** The preview is the restore PLANNED (the store's own `restore` on a view of the env that performs no write), and it is
 *  always there: a plan that failed as a whole is the restore's own refusal,
 *  thrown — `rewind.restore_failed` with the store's `code` and `permanence` on its `detail`, exactly as the restore would
 *  answer it (an entry with no boundary: `rewind_snapshot.unresolvable`). `refused` and `failed` are the plan's rows (both
 *  empty = a complete plan); `leftAsIs` the files it would leave as they are. `filesChanged` lists only the files that would
 *  change: a preview whose every file is refused or left answers it empty with zero counts too — empty `filesChanged`, zero
 *  counts, no `files`, `refused`, `failed` or `leftAsIs` row is "nothing would change". */
{
    dryRun: true;
    preview: FileHistoryDiffStats & Required<Pick<FileHistoryDiffStats, "refused" | "failed">> & {
        files: Array<FileHistoryRewindFile & {
            outsideRoot: boolean;
        }>;
        leftAsIs?: Array<FileHistoryLeftAsIsFile & {
            outsideRoot: boolean;
        }>;
    };
}
/** The store's ledger as it answered: `complete`, or `partial` with every refused / failed file on it; either with the files it
 *  left as they are (`leftAsIs`, each with its class). Every `files` and `leftAsIs` row states `outsideRoot`. */
 | {
    dryRun: false;
    restore: FileHistoryRestoreResult & {
        outcome: "complete" | "partial";
        files: Array<FileHistoryRewindFile & {
            outsideRoot: boolean;
        }>;
        leftAsIs?: Array<FileHistoryLeftAsIsFile & {
            outsideRoot: boolean;
        }>;
    };
};
/** The line-diff bound (see {@link countRestoreLineDiff}): a pair whose edit distance exceeds this
 *  is counted as a whole-file replacement. Public so a preview UI can state what it is showing. */
export declare const FILE_HISTORY_DIFF_LINE_BUDGET = 2000;
/** Whether bytes are BINARY for line arithmetic: a NUL byte anywhere — nothing else is judged. The one judgment
 *  {@link countRestoreLineDiff} counts by (a row's `lines.uncounted: "binary"`). It is not the judgment of a row's texts: the
 *  engine also omits as `binary` a side whose bytes are not UTF-8 (`changesSideOf`), so a host does not decide with this whether a
 *  text can be shown. */
export declare function bytesAreBinary(bytes: Uint8Array): boolean;
/**
 * The per-file line arithmetic behind a rewind's preview ({@link planFileHistoryRestore}) — ONE rule, because "how much will this
 * rewind change" is a claim, and two readers answering it differently would be two claims.
 *
 * `undefined` on either side means "does not exist" (a creation or a deletion), so every arm of the
 * restore is expressible: bytes → bytes is a line diff, absent → bytes is a pure insertion, bytes →
 * absent a pure deletion.
 *
 * TWO HONESTY BOUNDS, both stated rather than tuned in silence:
 *  · BINARY content (a NUL byte anywhere) contributes 0/0 while still being reported as CHANGED —
 *    "lines" is not a fact about a binary file, and printing a number derived from stray `\n` bytes
 *    would be inventing one.
 *  · Beyond {@link FILE_HISTORY_DIFF_LINE_BUDGET} the greedy diff STOPS and the pair is counted as a
 *    whole-file replacement (every current line deleted, every target line inserted). That is not a
 *    fallback to a worse estimate so much as the shape such a pair actually has — a diff that large
 *    IS a rewrite — and it keeps a preview from turning into an O(N·M) walk over two big files.
 */
export declare function countRestoreLineDiff(current: Uint8Array | undefined, target: Uint8Array | undefined): {
    insertions: number;
    deletions: number;
};
/**
 * Versioned session-sync envelope; `formatVersion` is the refuse-not-coerce gate (design/381 §5.3).
 * COMPLETE-state export: the tracked set and EVERY retained version record travel — including v1
 * records no surviving boundary references (they are restore()'s pristine fallback and reap()
 * retains them independently) and the parent-identity guards (root-relative under root) that
 * restore's preflight needs. An import that received only boundary references could neither run the
 * parent-chain check nor serve a tracked-later-than-target restore; round-trip-after-reap is a
 * contract-kit test.
 */
export interface FileHistoryExport {
    formatVersion: "file-history/1";
    tracked: Array<{
        /** Root-relative when captured under the task root, verbatim-absolute otherwise. */
        relOrAbsPath: string;
        /**
         * The key's SELF-DESCRIPTION (§3 amendment, A-082 r2). A bare key string cannot say which
         * family minted it, so a graph that crosses machines was previously re-joined against the local
         * root on a guess. Both members travel with every path and the import door refuses an envelope
         * whose values are outside the closed sets (refuse-not-coerce, same posture as `formatVersion`);
         * {@link resolveTrackKey} then judges each foreign-family key at restore time.
         */
        keyKind: FileHistoryTrackKeyDescriptor["kind"];
        keyFamily: FileHistoryKeyFamily;
        /**
         * DV-14: false ⇒ the pristine base could not be captured (durable base-unavailable marker); the
         * chain then starts above v1 and restore-below-base must keep refusing after import. Travels
         * with the graph; never inferred.
         */
        baseAvailable: boolean;
        /** Full retained chain (v1 first iff baseAvailable). `blobHash:null` = existed-not marker. `parentIdent`: never a place
         *  ({@link fileHistoryParentIdentTravels} — the door refuses one); an older engine's root-relative form only, which no
         *  engine reads as a place, so an imported version records no place. */
        versions: Array<{
            version: number;
            blobHash: string | null;
            mode?: number;
            parentIdent?: string;
            backupTime: string;
        }>;
    }>;
    boundaries: Array<{
        entryId: string;
        files: Array<{
            relOrAbsPath: string;
            version: number;
        }>;
    }>;
    /**
     * How many of the exported history's files were left out because they stand under an absolute key
     * ({@link fileHistoryEntryTravels}: edited outside the session's directory, or a second file whose relative name another
     * directory's file keys) — their restore points do not travel with the session. A count only, never their paths (they are
     * the source machine's). Absent = none left out, or an exporter from before this member. Not part of the envelope's
     * identity ({@link fileHistoryExportDigest}).
     */
    absoluteEntriesOmitted?: number;
    /**
     * The keys of the exported history's files that were left out because their history is frozen ({@link fileHistoryEntryFrozen}:
     * a version of the file was recorded through a link on its key's path) — the entry, its versions and their bytes do not travel;
     * the key (a root-relative name, never a machine path) is listed so the receiving side can say which files did not come along.
     * Absent = none, or an exporter from before this member. The import door judges its shape and records nothing of it; not part of
     * the envelope's identity ({@link fileHistoryExportDigest}).
     */
    frozenEntryKeys?: string[];
}
/**
 * The IDENTITY of an envelope — sha256 over its canonical (sorted) form, so the same graph digests
 * the same however a backend ordered its rows. It is what makes `importHistory`'s idempotent
 * re-publish decidable WITHOUT extra bookkeeping: a target already holding a graph that digests
 * equal to the incoming one is the SAME import arriving twice (ok), while any other non-empty target
 * is locally-grown history the import must never overwrite (typed `conflict`). Exported under the
 * "MUST reuse" clause: two backends that computed identity differently would disagree about which
 * retries are safe.
 */
export declare function fileHistoryExportDigest(data: FileHistoryExport): string;
/**
 * The import DOOR's structural judgment, shared by every backend (a second implementation is a second
 * opinion about what is safe to accept): the envelope must carry THIS format version and every row
 * must be shaped and self-described from the closed sets — `unsupported_format` otherwise, never a
 * coercion and never a throw (a payload that cannot be read is refused in the same word). Backends call
 * this BEFORE fetching a single blob, so a foreign-epoch payload costs nothing and changes nothing, and
 * `unsupported_format` is a word only this door (and a backend's own record-naming rule) says.
 */
export declare function validateFileHistoryExport(data: FileHistoryExport): FileHistoryResult;
/**
 * design/381 §3 — per-edited-file rewind history (CC FileHistory topology).
 *
 * Replaces the E19 whole-tree FileSnapshotStore. Three verbs mirror the reference module:
 * `trackEdit` (backup-before-first-edit), `snapshot` (version the tracked set at a turn boundary),
 * `restore` (converge ONLY the tracked set to a recorded boundary).
 *
 * Store discipline (contract-kit enforced):
 * - NEVER throw: every failure is encoded in the returned result (FileSystem posture).
 * - snapshot MUST NOT fail the caller's turn: a failed boundary capture degrades to "no boundary"
 *   with disclosure (onError phase:"rewind"). trackEdit is DIFFERENT (DV-14): its `{ok:false}`
 *   means "no durable first-touch state exists" and the CALLER's default policy is to REFUSE the
 *   edit (typed, loud) — silently proceeding would let a post-recovery retry mint already-modified
 *   bytes as pristine v1. Any proceed-unprotected policy is an explicit, adjudicated caller arm,
 *   never the store's own behavior.
 * - Structurally out of scope: files the agent never edited. No store method may enumerate, read,
 *   or write ANY path outside the tracked set plus its recorded restore targets. (The cowork
 *   guarantee lives HERE, as a contract clause.)
 * - BOUNDED by default: one boundary per turn, forever, is unbounded growth. Both bundled backends
 *   trim their own scope after each commit (see {@link FileHistoryStore.reap} for the rule, the
 *   default and the host override); an out-of-tree backend owes its own bound or an explicit
 *   statement that the host must schedule the GC.
 */
export interface FileHistoryStore {
    /**
     * Backup `absPath`'s CURRENT state before an agent edit (first touch per scope only; later calls
     * are cheap no-ops). The first touch is ONE atomic durable record — pristine blob+record,
     * existence=false marker (rewind of an agent-CREATED file deletes it), or base-unavailable marker
     * (DV-14). Reads bytes via `env` (remote-safe); stores them host-side. `root` is the trusted task
     * root: paths under it are recorded root-RELATIVE, paths outside it verbatim-absolute
     * ({@link trackKeyForEdit}); the version's place is recorded in the same frame.
     * `{ok:false}` = NO durable first-touch state was persisted — see the discipline block: the
     * caller's default is to REFUSE the edit (DV-14), because proceeding leaves the path
     * indistinguishable from never-touched. `{ok:true, minted}` — see {@link FileHistoryTrackResult}:
     * `minted:true` means this call created the record, which is what makes {@link annulTrack} legal
     * for it (#491).
     */
    trackEdit(scope: string, absPath: string, env: ExecutionEnv, root: string, signal?: AbortSignal): Promise<FileHistoryTrackResult>;
    /**
     * Discard the first-touch record `trackEdit` MINTED for `absPath` — the compensating verb for the
     * one ordering the topology cannot avoid (#491): the pre-image capture must run BEFORE the write,
     * so a write that then fails (a lost create race, ENOSPC, EACCES, a read-only mount) leaves a
     * record for an edit that never happened. Left standing, an `existed-not` v1 makes an untouched
     * path a rewind DELETE target: whoever writes those bytes next — the user, a peer process — gets
     * them removed by a restore that reports `complete`, which is precisely the structural
     * out-of-scope guarantee this contract opens with. So the record must be retractable.
     *
     * Discipline (contract-kit enforced): NEVER-throw like every other verb, and no env IO AT ALL
     * unless the caller asks for the proof read below. Retraction is legal ONLY while the record is
     * still exactly what `trackEdit` minted — a record referenced by ANY committed boundary, or one that has grown
     * past its first version, is REFUSED (typed `conflict`) and left intact, because history that a
     * boundary already froze is no longer the caller's to withdraw. An absent record is an idempotent
     * `{ok:true}` (the retry path). Callers annul ONLY what their own `trackEdit` reported as
     * `minted:true`: a path that was already tracked belongs to the edit that first touched it, and
     * discarding that baseline would be the fake-pristine hole DV-14 exists to weld shut.
     *
     * `verify` is the EVIDENCE arm (adversarial round 2). A caller whose write failed with a code the
     * FileSystem contract defines as "nothing was written" (`already_exists`, `precondition_failed`, `target_unavailable`)
     * has proof and passes nothing. Every other failure — a plain write is not contractually atomic,
     * so ENOSPC, a dying transport or a thrown backend may have TRUNCATED the file before reporting —
     * must hand an `env` here: the store then re-reads the path ONCE and retracts only if the world
     * still matches what the mint recorded (bytes still absent for an existed-not mint, still the same
     * hash for a captured one). A file that changed keeps its record, because the alternative is
     * deleting the only baseline of a file the agent really did modify — damage rewind could no longer
     * reach, which is strictly worse than a stale record. Every refusal above is the history-preservation
     * law (`conflict`, see {@link FileHistoryError.code}); a proof read that cannot re-read the path at all
     * judged nothing, and keeps the record with `track_failed` (`aborted` when the signal fired) instead.
     */
    annulTrack(scope: string, absPath: string, root: string, verify?: {
        env: ExecutionEnv;
        signal?: AbortSignal;
    }): Promise<FileHistoryResult>;
    /**
     * Record a history boundary keyed by `entryId` — the TURN'S OWN initial session entry, minted
     * after that entry is appended and BEFORE any tool executes, so the boundary means "file state
     * when `entryId`'s turn began" (≡ the reference's user-message-uuid snapshot; every turn
     * incarnation appends a fresh entry, so keys never alias across re-branches from the same fork
     * point). For each tracked file: re-stat via `env`; unchanged (metadata may prove inequality,
     * content hash proves equality — DV-13: never mtime) ⇒ reference the prior version; changed ⇒
     * store a new version; missing ⇒ record a deletion marker. Zero directory-tree traversal, zero
     * size gate. Idempotent per (scope, entryId) over COMMITTED boundaries.
     *
     * Commit visibility + fencing + CAPTURE LEASE (contract-kit enforced): a boundary becomes visible
     * to canRestore/restore ONLY after its complete version mapping is durable. Each attempt is
     * FENCED (a timed-out/aborted attempt may never commit — {@link boundaryPublishVerdict}, no grace
     * threshold), and the boundary's capture window is a LEASE that the caller closes before the
     * first tool executes: after lease close, a fresh CAPTURE (any env read) for that entryId is
     * refused — a retry may only PUBLISH a mapping whose bytes were fully captured before close.
     * The close is NOT persisted and the store has no close verb (design/381 §10 S-6): close is the
     * calling Runner's in-process discipline; after a crash the new process has no capture path for
     * the old entryId (its own prepare mints only its own turn's boundary), and abandoned staging is
     * judged by COMPLETENESS alone — complete ⇒ publishable, incomplete ⇒ abandoned (that turn has no
     * boundary) — with ZERO env reads on the retry path. A turn whose pre-turn capture failed simply
     * has no boundary (disclosed; the reference behaves the same) — there is NO mid-turn re-capture,
     * because re-reading after edits would publish post-turn bytes under a pre-turn key. An entryId
     * whose boundary was COMMITTED and later REAPED is closed by the same law and for the same reason
     * (see {@link FileHistoryStore.reap}): it refuses typed with zero env reads rather than
     * re-capturing a world that has moved on. Retention can therefore make a boundary unavailable,
     * but never wrong.
     */
    snapshot(scope: string, entryId: string, env: ExecutionEnv, root: string, signal?: AbortSignal): Promise<FileHistoryResult>;
    /**
     * Converge ONLY the tracked set to the boundary `entryId`: for each tracked file, target-version
     * bytes ⇒ write via `env` (the guarded-write arm and the symlink/parent-chain/kind preflights are
     * the design/381 slice-3 preflight family, `applyFileRestoreViaEnv`; an env without the guarded write
     * converges ADVISORY on the TOCTOU axis, stated, never overclaimed); deletion marker ⇒ remove;
     * identical ⇒ untouched; tracked-later-than-target ⇒ fall back to its v1 (pristine) version, and a base-unavailable path (DV-14) is REFUSED with reason
     * `base_unavailable` (left at its current state — never overwritten with a fake baseline).
     * Per-file refusals SKIP that file and are counted, never failing the whole restore (CC form).
     * Paths recorded relative to `root` re-join against the CURRENT root, and a version is converged there only when that is
     * the place it was recorded at (`applyFileRestoreViaEnv`: `recorded_elsewhere` / `place_unrecorded` otherwise, and a version
     * recorded outside `root` is left as it is — its `left` arm, which the backend lists in `leftAsIs`); `options`
     * ({@link FileHistoryRestoreOptions}) is handed to that half as it is — a store that does not forward it leaves every
     * version with no place refused.
     *
     * Partial outcome is FIRST-CLASS with a three-state discriminant and the per-file ledger always
     * travels: applied / identicalSkipped / refused / failed are SEPARATE columns (a security refusal
     * must never hide inside a benign skip count), so a caller can distinguish "nothing was mutated"
     * from "the env died after k writes". Restore is per-file idempotent (identical files skip), so
     * the documented recovery for a partial outcome is: re-run the same restore; it converges. There
     * is NO all-or-nothing guarantee and none is claimed. Task-level policy on `"partial"` lives in
     * the CALLER (prepare defaults to fail-loud; see DV-15). A boundary never made is `not_found` and
     * touches NOTHING — no file read or written, an empty ledger — since the engine's refusal of a
     * rewind without a boundary is exactly this answer (the contract kit checks the bytes).
     *
     * The engine also PLANS with this verb: it calls it with a view of `env` that reads the disk and performs no write or
     * delete (each answers ok), and reads the plan's ledger as the preview and as the all-or-nothing gate. So `restore`
     * changes nothing of the store's own records — a call is a read of the store, the writes are the env's — and reaches the
     * working tree only through `env`.
     */
    restore(scope: string, entryId: string, env: ExecutionEnv, root: string, signal?: AbortSignal, options?: FileHistoryRestoreOptions): Promise<FileHistoryRestoreResult>;
    /** Whether (scope, entryId) has a USABLE boundary: `false` both for one never made and for one that is there but
     *  cannot be read — `restore` is the verb that says which (`not_found` / `restore_failed` with the fault). */
    canRestore(scope: string, entryId: string): Promise<boolean>;
    /**
     * OPTIONAL. The tracked set as each of the boundaries `entryIds` reads it, in one call that reads the tracked set once (a reader of
     * many checkpoints pays for the history once). `boundaries` holds exactly one key per DISTINCT id asked — an id asked twice is one
     * key, an empty list is an empty map — and each value is the answer that id gets asked alone: per tracked entry — root-relative AND
     * absolute keys, frozen ones included: the whole history, not an export's projection — its key, its self-description and its
     * {@link fileHistoryTargetOf} answer (the target `restore` converges it to), in key order; `{ ok: true, boundary: null }` exactly
     * when `restore` would answer `not_found` (never made, reaped); `{ ok: false }` exactly when the boundary is there and cannot be
     * read, or the tracked set it reads cannot be read or judged — `restore`'s `restore_failed`, with its permanence (an id that is no
     * boundary still reads `null` then, and the call still answers `ok: true`). A read of the store: no env, no write, no bytes (a target names its bytes by their address; they come from
     * `blobExchange.get`). The whole answer is `{ ok: false }` only when the call cannot tell which of the ids are boundaries at all.
     * Never throws. Absent ⇒ this store cannot answer what changed between two checkpoints.
     */
    readBoundaries?(scope: string, entryIds: readonly string[]): Promise<FileHistoryBoundariesReadResult>;
    /**
     * GC: drop boundaries in `scope` not in `keepEntryIds`; then drop version records (and content
     * blobs) referenced by NO surviving boundary — EXCEPT v1 records AND base-unavailable markers
     * (DV-14), which are retained while the scope lives (the pristine fallback and its explicit
     * refusal state are both part of the graph). Returns the number of boundaries dropped.
     *
     * WHO CALLS IT (design/381 §片2 — the bound is the backend's, not a chore left to the host): both
     * bundled backends drive this verb THEMSELVES. Every committed boundary is followed by a
     * retention pass that trims the scope to the newest
     * {@link import("./file-history-retention.js").DEFAULT_FILE_HISTORY_BOUNDARY_KEEP} boundaries —
     * an engine default a deployment overrides through the store's own `retention` option, including
     * `keep: "unbounded"` to switch the self-trim off and take the schedule back. The pass is
     * best-effort by construction (a GC failure never fails the turn that triggered it) and it only
     * ever removes boundaries the caller could not name any more anyway.
     *
     * A backend outside this repo therefore owes ONE of two things, and silence is neither: its own
     * bound (this verb, driven from its own commit path), or a documented statement that the host
     * must schedule `reap`. An unbounded boundary graph is not a tuning choice — one boundary per
     * turn, forever, is a disk that fills with no line anywhere admitting it would.
     *
     * WHAT THE SELF-TRIM DOES NOT COVER, said here rather than left to be discovered: it runs at a
     * COMMIT, so a graph that arrives whole — `adoptScope`, `importHistory` — is published whole and
     * comes under the bound at that scope's next commit, not before. That is deliberate rather than
     * an oversight (round 2 raised it): both verbs promise all-or-nothing visibility of the graph the
     * caller handed over, and trimming during publication would silently discard history the host
     * explicitly asked to transfer. The overshoot is bounded by the envelope the host chose, which is
     * a different thing from the per-turn source this bound exists to stop.
     *
     * A REAPED entryId IS SPENT (adversarial review — a law this verb acquired the day anything
     * started calling it): dropping a boundary must not hand its key back. Until boundaries could be
     * dropped, the committed mapping was itself the record that an entryId had been consumed, and
     * `snapshot`'s idempotent short-circuit read it; a store that forgot a reaped id would let a
     * later `snapshot` for that key take the CAPTURE path and publish post-turn bytes under a
     * pre-turn key. Both bundled backends therefore tombstone what they reap and refuse a later
     * capture of it, typed and with zero env reads. The ledger is IDS, not mappings, and it is
     * unbounded — stated plainly because a bound's own residue growing forever would be a poor joke:
     * one id string per boundary ever reaped, against the complete tracked-set mapping each of those
     * boundaries used to carry. It is the cheap part of what the bound throws away, by two orders of
     * magnitude, and it is what makes the bound safe rather than merely small.
     *
     * Concurrency is unchanged and stays the caller's to reason about: a pass that runs while another
     * entryId's capture is parked at an env read may drop a version that capture staged, and that
     * capture then refuses TYPED (its turn has no boundary) rather than publishing a dangling
     * reference — the arm the commit paths already validate for.
     */
    reap(scope: string, keepEntryIds: string[]): Promise<number>;
    /**
     * Erase the WHOLE scope — every boundary, every version record INCLUDING the v1 pristine baselines `reap` keeps while a scope
     * lives, its consumed-id ledger — and the blobs no other scope references: the session-tree cascade's leg for a deleted session
     * (the scope is the session row's history scope, `fileHistoryScopeOf(sessionId, incarnation)`;
     * {@link import("./retention.js").RETENTION_CASCADE}). Answers how many boundaries and version
     * records it removed (a damaged record is erased all the same and counts once; a scope with no history answers 0, so a repeat
     * is harmless). The scope then reads as one that never had
     * history: an id registered again later starts a new one. Refused (thrown, `conflict`) while THIS store runs a write of the scope
     * — a capture, a first-touch record, a retraction or an import, counted from the call, so one parked before its first record is
     * counted — since a cascade runs on a session with no leg running; another process's writes are the caller's precondition to
     * hold. A store fault throws: a deletion face that cannot delete is loud, never a quiet 0 — the blob pass included, so a backend
     * that cannot collect every blob only the scope referenced (another scope's history it cannot judge, a blob that will not unlink)
     * throws after the records are gone, and a repeat runs that pass again. OPTIONAL: absent ⇒ this store cannot complete a session
     * deletion (only `reap` remains, which keeps the baselines), and the deployment owns that gap.
     */
    deleteBySession?(scope: string): Promise<number>;
    /**
     * The operator's erase of a session whose head cannot be read (the session store refuses its head read): its occupant cannot be read,
     * so its scope cannot be named — this erases EVERY scope the store holds that belongs to the session id, as {@link deleteBySession}
     * erases one: the bare id and each occupant's address, each scope read back by `readFileHistoryScope` (a scope whose `sessionId` is
     * the id), never a prefix match — an id the session id is a prefix of (`s1x` for `s1`) or one that carries a `~` of its own is
     * another id. Answers the total of what {@link deleteBySession} answers per scope (0 when the id holds no history, so a repeat is
     * harmless); refused and thrown as it is (a write in flight on one of the scopes, a store fault). A scope whose name the store
     * cannot read back cannot be judged and fails the call (thrown) before anything is erased. Never an owner's request and never called
     * by an automatic path: the session-tree cascade calls it in place of {@link deleteBySession} for such a session (the leg's
     * `unreadable` verb, {@link import("./retention.js").RETENTION_CASCADE}), after the forks have been carried from the source
     * addresses their own rows record. OPTIONAL: absent ⇒ that cascade refuses the session before its first destructive call.
     */
    deleteUnreadableSessionHistory?(sessionId: string): Promise<number>;
    /**
     * Cross-session carry (CC copyFileHistoryForResume): make `toScope` see `fromScope`'s boundaries
     * + versions (content-addressed backends copy references, zero bytes). Same-scope call is a
     * no-op. ATOMIC-VISIBILITY, same law as snapshot: the WHOLE adopted graph (tracked set, every
     * version incl. base-availability state, every referenced blob) is staged and verified, then
     * published in one step — `toScope` either sees the complete history or none of it. A
     * failed/partial adopt publishes NOTHING; the resume still proceeds (same availability posture as
     * the reference's tolerated partial copy, without the half-visible graph) and the failure is
     * disclosed. EMPTY-TARGET ONLY: adoption is refused (loud, typed `conflict`) once `toScope` has
     * ANY history of its own — adoption's seat is the fork/resume boundary BEFORE the new session's
     * first turn; a retry after the target has begun writing would need a destructive merge
     * (version-number collisions, overwritten target history) that this contract deliberately
     * forbids. Retry while the target is still empty is idempotent and repairs abandoned staging.
     *
     * WHO CALLS IT — THE ENGINE DOES, since design/381 slice 3, and the seat is worth knowing because
     * it decides WHEN this verb runs against your backend. `prepareTask` carries a forked session's
     * history on the first turn it prepares for it, keyed on the LINEAGE FACT
     * (`SessionMetadata.forkedFrom`) rather than on the code path that forked — so the Agent tool's
     * fork route, `warmResume`, and a deployment that forks a session and then runs a task on it all
     * reach the same seat. It runs BEFORE the restore seat, so the very first task on a fork may
     * itself ask to restore files to a pre-fork boundary. The lineage fact is the fork row's whole
     * cell: the source id AND the occupant of it the fork was cut from (`SessionMetadata.forkedFromIncarnation`),
     * which together are the source's history scope: `fromScope` = `fileHistoryScopeOf(forkedFrom, forkedFromIncarnation)`,
     * `toScope` = the fork's own `fileHistoryScopeOf(forkId, incarnation)`. The carry is lazy — it can run long after
     * the fork — and reads no row of the source: an id created again since holds another occupant, whose history is at
     * another address. A fork row that records no source occupant has no source address, which means NO call, one
     * `onError` disclosure (`adopt_failed`, phase `"rewind"`), and a fork that starts with its own history.
     *
     * The empty-target law is what makes that safe to attempt rather than schedule: a scope that
     * already holds history answers the typed `conflict`, which at that seat MEANS "already carried,
     * or grown its own" and is treated as a no-op. Only a non-conflict failure is disclosed
     * (`onError` phase `"rewind"`), because that one is a carry the deployment expected and did not
     * get. A failed carry never blocks the fork's run.
     *
     * A HOST MAY STILL CALL IT — the engine's seat covers sessions the engine prepares, and a
     * deployment that copies history between scopes for its own reasons (a migration, a scope rename)
     * is calling the same verb under the same law. The session-deletion cascade is one such caller: before it deletes a
     * session's history it carries that history into each of the session's forks, with the same `conflict` reading (a fork that
     * already received it, or has grown its own, is done) ({@link import("./retention.js").RETENTION_CASCADE}'s file-history row). What a MISSED carry gets is degraded, not broken,
     * and it is worth naming precisely: the new scope starts EMPTY, so nothing the old one tracked is
     * restorable from it. A rewind aimed at a pre-fork boundary answers "no boundary" (honest, typed)
     * instead of converging those files, and the new lineage's own first touch of a path records THAT
     * path's then-current bytes as its pristine v1 — a correct baseline for the new lineage, just not
     * the old one's history. Nothing is silently mis-restored; the carry simply does not happen.
     */
    adoptScope(fromScope: string, toScope: string): Promise<FileHistoryResult>;
    /**
     * Session-sync export/import (2c), versioned envelope — see {@link FileHistoryExport}. Optional.
     * importHistory obeys the SAME atomic-visibility + staged-verify law as adoptScope: every
     * referenced blob fetched and integrity-checked, then the scope's graph published in one step; a
     * mid-import failure publishes nothing. NON-DESTRUCTIVE TARGET LAW (same family as adoptScope): a
     * first import requires an EMPTY target graph; a retry is legal only while the target is still
     * empty OR already holds a graph with the exact same import identity/digest (pure idempotent
     * re-publish). A non-empty target with any other content ⇒ typed `conflict` refusal — atomic
     * visibility prevents half-graphs, this law prevents publishing the WRONG complete graph over
     * locally-grown history. A target whose history cannot be judged ⇒ `adopt_failed`, before any blob is
     * fetched; a source that cannot supply a referenced blob — absent, its read throws, or bytes that fail
     * their content address — ⇒ `adopt_failed`, and so is a fault in staging or publishing the graph.
     * `unsupported_format` is the door's refusal alone ({@link validateFileHistoryExport}, before any blob
     * is fetched). `exportHistory` answers a
     * {@link FileHistoryExportResult}: the whole graph, `null` for nothing to export, or `adopt_failed` with the
     * fault for a history it cannot read whole (an unreadable tracked set, boundaries that cannot be judged) —
     * never a partial graph, and never a `null` that hides a fault.
     */
    /**
     * NO `dispose` / lifecycle verb, and that is a decision rather than an omission (design/381 slice 3,
     * the R-6 review candidate — recorded here because the next reader will otherwise wonder). The case
     * for one: a directly-constructed file backend holds no store lock, so the single-writer premise is
     * enforced only where a deployment assembles the backend (its data-root LOCK), and a `dispose`
     * would let a store hold a lease and release it. The case against, which won:
     *  · every verb here is self-contained — a store holds no cross-call resource, so `dispose` would be
     *    an obligation on EVERY backend (a SQL twin included) in order to serve one backend's optional
     *    locking;
     *  · a lock released by a verb nobody is required to call fails WORSE than no lock: a crash leaves a
     *    stale lease that blocks a store which today simply works, and the recovery is manual;
     *  · the single-writer premise is the deployment's to make. The assembled backend is where it is
     *    enforced, and a directly-constructed store is the same "I know what I am doing" path every
     *    sibling file store in this family offers.
     * A deployment that needs cross-process exclusion takes the assembled backend, or brings its own.
     */
    exportHistory?(scope: string): Promise<FileHistoryExportResult>;
    importHistory?(scope: string, data: FileHistoryExport, srcGetBlob: (hash: string) => Promise<Uint8Array | undefined>): Promise<FileHistoryResult>;
    /**
     * The store's blob exchange — how another machine's bytes come in ahead of an import, go out to a puller, and are
     * asked about — as one optional member group ({@link FileHistoryBlobExchange}): present ⇒ all three of its members;
     * absent ⇒ this store exchanges no blobs (it can still import, from a source the caller reads). Read through
     * {@link fileHistoryBlobExchangeOf}, which refuses a group with a member missing. A puller hands
     * `blobExchange.get` to {@link importHistory} as its `srcGetBlob`.
     */
    readonly blobExchange?: FileHistoryBlobExchange;
}
/**
 * {@link FileHistoryStore.blobExchange}: one capability, three members.
 *
 *  - `put(hash, bytes)` stores bytes under their content address. The store checks the address itself — bytes whose
 *    sha256 is not `hash` are refused (`adopt_failed`, `permanence: "terminal"`) and nothing is stored — and records
 *    the blob present the same way a capture records one. Bytes a `put` stores that no history references yet are kept
 *    through the store's routine collection until its grace window runs out, counted from the latest `put` of the same
 *    bytes; erasing a session's history (`deleteBySession` / `deleteUnreadableSessionHistory`) does not wait for it.
 *    Idempotent. (Both bundled stores: the window is {@link FILE_HISTORY_UNREFERENCED_BLOB_GRACE_MS}.)
 *  - `get(hash)` answers the bytes, or `undefined` when the store does not hold them.
 *  - `has(hashes)` answers which of `hashes` the store holds, from its own index — no bytes are read.
 */
export interface FileHistoryBlobExchange {
    put(hash: string, bytes: Uint8Array): Promise<FileHistoryResult>;
    get(hash: string): Promise<Uint8Array | undefined>;
    has(hashes: readonly string[]): Promise<ReadonlySet<string>>;
}
/**
 * How long both bundled stores' ROUTINE collection (the blob pass after `reap`) keeps a blob no retained version references: one
 * hour, counted from the blob's first write or its latest `blobExchange.put`. It covers bytes put ahead of an import that has not
 * been published yet, and bytes a capture wrote that its commit has not referenced yet; bytes a reaped version left behind are as
 * old as their first write and go at once once that is past the window. Erasing a session's history does not wait for it.
 */
export declare const FILE_HISTORY_UNREFERENCED_BLOB_GRACE_MS = 3600000;
/** Whether `hash` is a content address a bundled store can hold: a lowercase hex sha256. Anything else is held by no store. */
export declare function isBlobAddress(hash: unknown): hash is string;
/** The bundled stores' one judge of a `blobExchange.put`: `undefined` when `bytes` hash to `hash`, else the refusal the contract
 *  names (`adopt_failed`, terminal — no retry makes the bytes hash differently), with nothing stored. */
export declare function blobPutRefusal(hash: unknown, bytes: unknown): (FileHistoryResult & {
    ok: false;
}) | undefined;
/**
 * The store's blob exchange, read as one capability: `undefined` when the store carries no `blobExchange`; its three
 * members, bound, when it carries the whole group; a refusal (`config.invalid_argument`) when the group is not an
 * object or a member is missing or not a function. The group is the only reading: no other member of the store says
 * anything about the capability.
 */
export declare function fileHistoryBlobExchangeOf(store: FileHistoryStore): FileHistoryBlobExchange | undefined;
/**
 * design/381 §3 + §10 T-5 — the FENCING judge for a boundary-capture attempt, exposed as a
 * direct-callable function (the G6b grey-box seat) and used by every in-tree backend as the single
 * commit gate: an attempt whose signal fired — timeout or abort, no matter how close to completion
 * the capture got — may NEVER publish its mapping. ABSOLUTE, no grace threshold (§10 T-5: "无宽限
 * 期" — the verdict has no time axis at all): a late-completing capture may have read bytes AFTER
 * the lease closed (post-edit bytes), and publishing them under the pre-turn key is exactly the
 * poisoning the fence exists to stop.
 */
export declare function boundaryPublishVerdict(attempt: {
    aborted: boolean;
}): {
    publish: true;
} | {
    publish: false;
    reason: "aborted";
};
/** One captured state of one file, as read through the env (the shared capture half). */
export type FileBackupCapture = 
/** `mode` = the env's POSIX permission bits when it HAS that face (design/381 DV-8); absent when
 *  the env cannot express them — never fabricated, so a restore can tell "this mode was recorded
 *  and could not be applied" from "there was never a mode to keep". */
{
    state: "file";
    bytes: Uint8Array;
    hash: string;
    mode?: number;
    parentIdent?: string;
} | {
    state: "absent";
    parentIdent?: string;
} | {
    state: "aborted";
}
/** Non-ENOENT read failure: the file may exist but its bytes are not capturable right now. */
 | {
    state: "unreadable";
    cause: string;
};
/**
 * Where a boundary re-reads a tracked file, and whether it may. A frozen entry ({@link fileHistoryEntryFrozen}) is HELD and never
 * read, whatever the tree holds now. An entry that records a place is read at the key's last segment
 * under that place as it stands ({@link placeAsItStands}) — never "the key under whichever root this leg was handed" (a session
 * handed another root must not read a same-named file there into its history: it never touched it, and a rewind would write it
 * back) — and is HELD (not read; the boundary keeps its last version) when the place no longer resolves to itself or the file
 * there is a symbolic link. An entry that records none (an older engine's, an imported one) is read at the key under `root` only
 * when that path, links followed, lies under `root`'s real path; else it is held, and nothing is read or recorded: a value a
 * history carries never makes a capture read outside the root. **Exported under the "MUST reuse" clause**, for every backend's
 * `snapshot`.
 */
export declare function resolveTrackedFile(env: ExecutionEnv, root: string, key: string, versions: ReadonlyArray<{
    readonly parentIdent?: string;
}>, minted?: FileHistoryTrackKeyDescriptor, signal?: AbortSignal): Promise<{
    ok: true;
    abs: string;
} | {
    ok: true;
    held: string;
} | {
    ok: false;
    reason: string;
    class: "key_unresolvable";
}>;
/**
 * The key a first touch tracks `absPath` under, given the store's tracked set (`entryOf`). ONE KEY LAW: a file is keyed by its REAL
 * path — its parent's real path ({@link placeOfParentViaEnv}) and its name — against the root's real path, the key the engine's own
 * write tools hand a store; so a path spelled through a link inside the root is keyed where the link leads (under the root: the
 * real relative name; out of it: the real absolute path), and no entry's key and recorded place can disagree
 * ({@link fileHistoryEntryFrozen}). A path whose real path cannot be read is keyed as spelled. Then: the file's own absolute path
 * when the store already tracks it there (an edit from a leg whose root did not hold it, a second file as below, or — under the
 * spelling it is handed — an entry recorded before keys followed real paths) — one file, one entry; the root-relative name it is
 * handed in, when the store tracks it under that name and not under its real one, that entry is not frozen and stands where the
 * file does (recorded before keys followed real paths, or before a case- or normalization-insensitive volume renamed one of its
 * directories in place); else {@link describeTrackKey}'s,
 * unless that root-relative key is already the key of a file at ANOTHER place (the session was handed another root since, and both
 * roots hold a file at that relative path) — then this file's own absolute path, so two files never share one entry (the first
 * one's history and the second one's edits would otherwise be one chain, and the second one's edits would be recorded nowhere). An
 * entry with no place keeps its key (who it is cannot be told). **Exported under the "MUST reuse" clause**, for every backend's
 * `trackEdit`; {@link trackKeyForAnnul} is its retraction twin.
 */
export declare function trackKeyForEdit(env: ExecutionEnv, root: string, absPath: string, entryOf: (key: string) => {
    readonly versions: ReadonlyArray<{
        readonly parentIdent?: string;
    }>;
} | undefined, signal?: AbortSignal): Promise<{
    key: string;
} & FileHistoryTrackKeyDescriptor>;
/**
 * The key a retraction names `absPath` by — the same choice the edit made. With the proof read's `env` (`annulTrack`'s `verify`) it
 * is {@link trackKeyForEdit}'s own answer over the tracked set (`proof.entryOf`), real path and all. Without it the retraction does
 * no env IO, so it reads the tracked set alone: the file's own absolute entry when the store holds one, else {@link trackKeyOf}'s —
 * which names the record a touch made only when the path was handed spelled as it really is (the engine's own seat hands real
 * paths both times); a path spelled through a link names nothing there, and the retraction answers it absent.
 */
export declare function trackKeyForAnnul(root: string, absPath: string, has: (key: string) => boolean): string;
export declare function trackKeyForAnnul(root: string, absPath: string, has: (key: string) => boolean, proof: {
    env: ExecutionEnv;
    signal?: AbortSignal;
    entryOf: (key: string) => {
        readonly versions: ReadonlyArray<{
            readonly parentIdent?: string;
        }>;
    } | undefined;
}): Promise<string>;
/** The boundary's re-version judgment on the PLACE axis, the {@link modeProvenDifferent} sibling: a capture whose place differs
 *  from the last version's (or whose last version records none) is versioned again even when its bytes are identical, so every
 *  boundary after an upgrade stands on versions that name their place. A capture with no readable place proves nothing. */
export declare function placeProvenDifferent(recorded: string | undefined, current: string | undefined): boolean;
/**
 * Capture ONE file's current state through the ExecutionEnv — **the env-operating half every
 * backend MUST reuse** (design/381 §3 分工, the E19 captureManifest condition carried forward:
 * re-implementing it per backend is how symlink-escape/fail-closed bugs come back). Used by
 * `trackEdit` (first-touch pristine) and `snapshot` (per-file re-read). The read's absence answers
 * are the absent signal — no entry, nothing under a parent that is not a directory (a recorded
 * directory replaced by a file), a name the filesystem cannot hold (`isAbsence`, the one reading of
 * an absence); the read itself is the authoritative existence probe — a separate stat would only
 * re-open the same race one window later. The version's PLACE rides the same frame as its
 * `parentIdent` ({@link placeOfParentViaEnv}: the parent's absolute real path), omitted only when it
 * cannot be read — a version with no place is refused by a restore unless the rewind names where such
 * versions were recorded, never converged on a guess. `_root` stays in the signature every backend calls.
 */
export declare function captureFileBackupViaEnv(env: ExecutionEnv, absPath: string, _root: string, signal?: AbortSignal): Promise<FileBackupCapture>;
/**
 * The retraction PROOF READ (design/381 #491 + adversarial round 2), shared by every backend so the
 * evidence rule cannot drift: does the path still look exactly as the first touch recorded it? An
 * existed-not mint requires the path to still be absent; a captured mint requires the same content
 * hash. Anything else — including an unreadable path — leaves the record standing, because the only
 * failure this arm exists to distinguish is "the write never landed" from "the write may have
 * changed the file". A base-unavailable marker is REFUSED here rather than waved through
 * (adversarial round 3): it carries no bytes to compare, but the marker itself is the durable
 * refusal state that stops a later touch from minting already-modified bytes as pristine — erasing
 * it on an ambiguous failure re-opens exactly the DV-14 hole it exists to close. It stays
 * retractable through the `"proven"` path, which needs no evidence read at all.
 *
 * THREE verdicts, because a backend answers them three ways: `unchanged` retracts; `kept` is the
 * history-preservation law keeping the record (`conflict`); `unjudged` is a read that never happened —
 * the path could not be re-read, or the signal fired — so nothing was judged and the record stays with
 * the verb's own failure (`track_failed`, or `aborted` when `aborted` is true), never with the law's word.
 */
export type FileHistoryMintProof = {
    verdict: "unchanged";
} | {
    verdict: "kept";
    reason: string;
} | {
    verdict: "unjudged";
    reason: string;
    aborted: boolean;
};
export declare function worldStillMatchesMint(env: ExecutionEnv, absPath: string, root: string, baseAvailable: boolean, mintedBlobHash: string | null, signal?: AbortSignal): Promise<FileHistoryMintProof>;
/** A backend's ONE mapping of a proof that did not say `unchanged` onto the annul verb's failure — the two
 *  bundled backends call it, and an out-of-tree backend reuses it with the proof read itself. */
export declare function annulProofFailure(proof: Exclude<FileHistoryMintProof, {
    verdict: "unchanged";
}>, absPath: string): FileHistoryResult & {
    ok: false;
};
/**
 * DV-13's metadata rule applied to the MODE axis (design/381 slice 3), and it is a rule about
 * EVIDENCE rather than about equality: metadata may prove two states DIFFERENT, never the same. Two
 * known-and-unequal modes are a proven difference, so the file is versioned again even though its
 * bytes are identical (the permission bit is part of the state a rewind restores). An UNKNOWN mode
 * on either side proves nothing and must not manufacture a version — which is also what keeps a
 * graph captured before this field existed from re-versioning its whole tracked set on the first
 * boundary after an upgrade.
 */
export declare function modeProvenDifferent(recorded: number | undefined, current: number | undefined): boolean;
/** The target one file must converge to (bytes+hash, or "must not exist"). */
export type FileRestoreTarget = {
    bytes: Uint8Array;
    hash: string;
} | {
    absent: true;
};
/**
 * The recorded facts the slice-3 preflight judges the current world against, plus the abort signal
 * (design/381 §6 slice 3). Every member is OPTIONAL on purpose: a record captured by an env without
 * the mode face, or without canonicalization, carries neither — and a guard with nothing recorded to
 * compare must degrade to "no opinion", never to a fabricated expectation.
 */
export interface FileRestoreApplyOptions {
    /** The task root the recorded key was re-joined against (the key's coordinate; the place check reads absolute places). */
    root: string;
    /** The place recorded WITH the version being restored ({@link placeOfParentViaEnv}; a root-relative or absent one names none). */
    parentIdent?: string;
    /** The POSIX mode recorded with the version being restored (design/381 DV-8). */
    mode?: number;
    signal?: AbortSignal;
    /** The rewind's {@link FileHistoryRestoreOptions.unplacedHistoryRecordedUnder}, handed on by the backend as it is. */
    unplacedHistoryRecordedUnder?: string;
}
export type FileRestoreApplyOutcome = 
/** `modeNotPreserved` rides the two NON-refusal arms: the bytes converged but the recorded mode
 *  could not be re-applied (no env mode face, or the env refused/failed the change). A disclosure,
 *  never a failure — the file's CONTENT is what the restore promised. */
{
    outcome: "applied";
    modeNotPreserved?: true;
} | {
    outcome: "identical";
    modeNotPreserved?: true;
}
/** A refusal this half decides: about the object at the path (its kind, a guarded write's precondition, the recorded
 *  place having moved or become a link, a file the rewind holds because a frozen row names it — `link_safety`), or about where
 *  the version belongs (`recorded_elsewhere`, with
 *  `recordedUnder`; `place_unrecorded`), or about the file having changed since the restore's plan read it
 *  (`changed_since_plan`). `action` = what converging would have done. A backend copies all of it into the ledger row. */
 | {
    outcome: "refused";
    reason: string;
    class: "link_safety" | "recorded_elsewhere" | "place_unrecorded" | "changed_since_plan";
    recordedUnder?: string;
    action?: "write" | "delete";
}
/** The version belongs to a directory outside the rewind's root and the file there no longer holds it: nothing is written or
 *  deleted, here or there. A backend lists it as it is — `leftAsIs.push({ path: key, ...left })` — never as a refusal or a
 *  failure (it carries no top-level `reason`, so a backend that has not taken this arm does not compile its failure push). */
 | {
    outcome: "left";
    left: Omit<FileHistoryLeftAsIsFile, "path"> & {
        class: "recorded_outside_root";
    };
} | {
    outcome: "failed";
    reason: string;
};
/**
 * Converge ONE file to `target` through the ExecutionEnv — **the env-operating + security half
 * every backend MUST reuse** (design/381 §3 分工). skip-if-identical is content-hash proven (DV-13:
 * metadata may only ever prove INEQUALITY, never equality; mtime is never consulted), so an
 * identical file is untouched (no write, no mtime churn). Deletion markers remove the current file
 * (ENOENT tolerated = already converged).
 *
 * THE PREFLIGHT FAMILY (design/381 slice 3, DV-6 — the env-level approximation of the reference's
 * fd-level `O_NOFOLLOW` + dev/ino re-check, ordered cheapest-refusal-first). Every arm SKIPS the
 * one file and is counted; none of them fails the whole restore:
 *  · KIND — the addressed object (no-follow `fileInfo`) must be a regular file or absent. A symlink
 *    at the leaf is refused rather than followed: the recorded bytes belong to the file the agent
 *    edited, not to whatever a link now points at. A directory/socket/FIFO in its place is the same
 *    refusal for the same reason.
 *  · PLACE — a version is converged only where it was recorded: the place of the path (its parent's
 *    absolute real path, {@link placeOfParentViaEnv}) must equal the place the version records. A
 *    version recorded under another directory (a later leg handed another root, a fork handed
 *    another root, a history carried or cascaded from another session, a moved or copied root) is
 *    never written here — and the file at its own place already holding it is a convergence with
 *    nothing to do (`identical`). Otherwise: a place OUTSIDE `root` (real paths) is a directory this
 *    rewind does not work in, so the file is left as it is (`left`, class `recorded_outside_root`,
 *    its `place`), not refused — a rewind handed the root it was recorded under restores it (and the whole restore refuses
 *    it after all when it restores another file under that root outside its own, `withRewindFiles`); a place under `root`
 *    (an earlier leg's directory below or above this one) is refused `recorded_elsewhere` with
 *    `recordedUnder`, and so is every such version when `root`'s real path cannot be read. A recorded place that now
 *    resolves elsewhere itself (an ancestor swapped for a link) is `link_safety`, and nothing is
 *    written through it. A version that records no place (an older engine's, or an imported one) is
 *    read as recorded under `unplacedHistoryRecordedUnder` (with the key's own parent below it) when
 *    the rewind names one, and is otherwise refused
 *    `place_unrecorded`. A directory deleted since (the recreate arm) has the same place — the
 *    nearest existing ancestor's real path with the rest appended — so it is recreated.
 *  · HOLD — once the preflight has read where the file really lies, the rewind's env view is asked whether it holds that file (a
 *    frozen row's file, {@link RestoreHolds}); a held file is refused `link_safety` with the view's sentence, before any write,
 *    delete or change of mode. An env that is not the engine's view holds nothing.
 *  · AS PLANNED — once the file's current bytes are read, the view is told what this half found there and would converge it to
 *    ({@link notePlannedState}): a planning view records it; the view of the restore that carries the plan out answers a refusal
 *    (`changed_since_plan`) when the plan read the same file otherwise, or never reached it — before any write, delete or change
 *    of mode. A file already converged needs none and is `identical`, whatever the plan read.
 *
 * THE WRITE uses `env.writeFileGuarded` when the env has it — one atomic verify-and-write whose
 * expectation names the addressed path and forbids following a leaf link, so the window between
 * this preflight and the write is closed at the backend. An env WITHOUT it falls back to plain
 * `env.writeFile` and the convergence is then ADVISORY on the TOCTOU axis: the preflight above is a
 * check-then-act, and a sufficiently fast racer can still swap the leaf in between. Stated here
 * because the alternative — a two-step emulation behind an atomic-looking face — is exactly what
 * that capability's own contract forbids.
 *
 * MODE (DV-8): a recorded mode is re-applied through the optional `setFileMode` face after the
 * bytes land (and on an otherwise-identical file whose mode drifted, which IS a convergence). An env
 * without the face — or one that refuses the change — yields `modeNotPreserved`, disclosed by the
 * caller's ledger; it never turns a successful content restore into a failure.
 */
export declare function applyFileRestoreViaEnv(env: ExecutionEnv, absPath: string, target: FileRestoreTarget, opts: FileRestoreApplyOptions): Promise<FileRestoreApplyOutcome>;
interface FileHistoryVersionRecord {
    version: number;
    /** Content-addressed blob hash, or null = "did not exist at this point" (existed-not marker —
     *  serves both the pre-creation v1 arm and later deletion arms). */
    blobHash: string | null;
    mode?: number;
    parentIdent?: string;
    backupTime: string;
}
interface TrackedFileState {
    /** DV-14: false ⇒ the pristine base could not be captured; a durable refusal state, not an
     *  absence — versions then start ABOVE v1 and v1 is never minted later. */
    baseAvailable: boolean;
    /** The key's self-description (§3 amendment): recorded at the mint so a graph that later crosses
     *  machines can be judged instead of guessed. */
    keyDesc: FileHistoryTrackKeyDescriptor;
    /** Set when a LATER trackEdit for this path was served (answered `minted:false`) — that lane is
     *  now relying on this record as its own pre-edit baseline, so the original minter may no longer
     *  retract it (adversarial round 1: two lanes racing one path, the first failing its write, would
     *  otherwise delete the baseline the SECOND lane's successful edit depends on). */
    observedByLaterTouch?: boolean;
    versions: FileHistoryVersionRecord[];
}
/** One staged per-file outcome of a capture attempt (commit assigns version numbers atomically). */
type StagedFileCapture = {
    kind: "unchanged";
    version: number;
} | {
    kind: "changed";
    blobHash: string | null;
    mode?: number;
    parentIdent?: string;
};
/**
 * In-memory, content-addressed reference {@link FileHistoryStore}. Blobs are deduplicated by sha256
 * ACROSS all scopes and versions (a file unchanged between boundaries stores zero new bytes); each
 * tracked file keeps a version chain, each boundary a complete `trackKey → version` mapping over
 * the tracked set as of its mint. Single-process (the default-deps reference; the durable
 * file-backed impl is design/381 slice 2).
 *
 * Grey-box fault seams (design/381 §7 C7 / §10 T-4): `persistFirstTouch` and `publishBoundary` are
 * `protected` COMMIT points — a test subclass overrides one to throw and the public verb answers
 * the typed `{ok:false}` the contract promises (the store itself still never throws).
 *
 * RETENTION is built in (design/381 §片2): each committed boundary is followed by a trim back to
 * {@link import("./file-history-retention.js").DEFAULT_FILE_HISTORY_BOUNDARY_KEEP} newest boundaries per scope, overridable through
 * {@link InMemoryFileHistoryStoreOptions.retention}. Even a single-process reference store needs
 * it — a long-lived process IS the unbounded case.
 */
export interface InMemoryFileHistoryStoreOptions {
    /** design/381 §片2 — the built-in boundary bound and its override. Omitted ⇒ the engine default
     *  ({@link import("./file-history-retention.js").DEFAULT_FILE_HISTORY_BOUNDARY_KEEP}); a malformed policy is REFUSED here, at the wiring
     *  site, rather than silently becoming a different policy inside a GC pass nobody watches. */
    retention?: FileHistoryRetentionPolicy;
    /** The clock the store ages unreferenced blobs by (milliseconds; {@link FILE_HISTORY_UNREFERENCED_BLOB_GRACE_MS}). Omitted ⇒
     *  `Date.now`; a value that is not a function is refused here. */
    now?: () => number;
    /** The most bytes one stored copy of a file may hold ({@link readMaxBlobBytes}): a copy over it is refused `too_large`
     *  ({@link blobOverStoreLimit}) at every verb that would store it — `trackEdit`, `snapshot`, `importHistory`, `blobExchange.put` —
     *  with nothing of the call committed. Omitted ⇒ no bound. */
    maxBlobBytes?: number;
}
export declare class InMemoryFileHistoryStore implements FileHistoryStore {
    private readonly scopes;
    /** Resolved boundary cap, or `null` for the explicit `"unbounded"` opt-out (host owns the GC). */
    private readonly boundaryKeep;
    private readonly blobs;
    /** sha256(hex) → when the blob was first written or last put through the exchange — its age for routine collection. */
    private readonly blobAt;
    private readonly now;
    /** Blob hashes written by an in-flight capture BEFORE its commit — a racing reap must treat them
     *  as live (same MAJOR-1 posture as the retired whole-tree store). REFCOUNTED, not a set
     *  (adversarial round): two concurrent captures can lease the same new hash, and the first
     *  attempt's release must not strip the second attempt's liveness. */
    private readonly inFlightBlobs;
    /** Per scope, the history writes (`trackEdit`, `annulTrack`, `snapshot`, `importHistory`) this store is running, from call to
     *  settle: `deleteBySession` refuses while a scope has one, an import still fetching its blobs included. */
    private readonly writers;
    constructor(options?: InMemoryFileHistoryStoreOptions);
    /** {@link InMemoryFileHistoryStoreOptions.maxBlobBytes}, as read at construction. */
    private readonly maxBlobBytes;
    /** The bundled exchange ({@link FileHistoryBlobExchange}) over this store's own blobs. A `put` (re)starts the blob's age. */
    readonly blobExchange: FileHistoryBlobExchange;
    /** Keep a captured or imported blob (dedup by address): its age starts at its first write. */
    private holdBlob;
    /**
     * The RETENTION pass, run after a boundary commits (design/381 §片2 — see {@link FileHistoryStore.reap}
     * for why the backend owns this rather than the host). Boundaries are an insertion-ordered map
     * here, so commit order is exact and the selection needs no clock.
     *
     * Never throws and never fails the commit that triggered it: the boundary is already published and
     * a GC that could not run is a graph that is merely larger than its bound — the strictly safer of
     * the two failure directions, and the same posture the reference implementation's own eviction has.
     */
    private applyBoundaryRetention;
    private leaseBlob;
    private releaseBlob;
    private scope;
    /** PROTECTED COMMIT SEAM (fault-injectable): durably record one path's first-touch state.
     *  Synchronous single assignment = the "ONE atomic durable record" of DV-14 for this backend. */
    protected persistFirstTouch(scope: string, key: string, state: TrackedFileState): void;
    /** PROTECTED COMMIT SEAM (fault-injectable): publish a captured boundary in ONE synchronous step
     *  — version records + mapping become visible together or not at all (atomic visibility). */
    protected publishBoundary(scope: string, entryId: string, staged: Map<string, StagedFileCapture>): void;
    /** One history write of `scope`, counted in {@link writers} for its whole run. */
    private writing;
    trackEdit(scope: string, absPath: string, env: ExecutionEnv, root: string, signal?: AbortSignal): Promise<FileHistoryTrackResult>;
    private trackEditCounted;
    annulTrack(scope: string, absPath: string, root: string, verify?: {
        env: ExecutionEnv;
        signal?: AbortSignal;
    }): Promise<FileHistoryResult>;
    private annulTrackCounted;
    snapshot(scope: string, entryId: string, env: ExecutionEnv, root: string, signal?: AbortSignal): Promise<FileHistoryResult>;
    private snapshotCounted;
    restore(scope: string, entryId: string, env: ExecutionEnv, root: string, signal?: AbortSignal, options?: FileHistoryRestoreOptions): Promise<FileHistoryRestoreResult>;
    canRestore(scope: string, entryId: string): Promise<boolean>;
    /** {@link FileHistoryStore.readBoundaries}: the tracked set as each boundary asked reads it, each entry's target from the one
     *  function `restore` takes it from; one key per distinct id. `null` on exactly the arm `restore` answers `not_found`. */
    readBoundaries(scope: string, entryIds: readonly string[]): Promise<FileHistoryBoundariesReadResult>;
    reap(scope: string, keepEntryIds: string[]): Promise<number>;
    deleteBySession(scope: string): Promise<number>;
    deleteUnreadableSessionHistory(sessionId: string): Promise<number>;
    /** Blob GC: live = referenced by ANY scope's retained version records, or in-flight. `byAge` — the routine pass after `reap` —
     *  keeps an unreferenced blob younger than {@link FILE_HISTORY_UNREFERENCED_BLOB_GRACE_MS}; an erase collects every unreferenced
     *  blob. Synchronous (no await), so it runs atomically vs an in-flight capture parked at an await. */
    private collectBlobs;
    adoptScope(fromScope: string, toScope: string): Promise<FileHistoryResult>;
    exportHistory(scope: string): Promise<FileHistoryExportResult>;
    /** The export projection as a SYNCHRONOUS function — the import's final claim needs to compare a
     *  target's identity without yielding (see the publish step). */
    private exportOf;
    importHistory(scope: string, data: FileHistoryExport, srcGetBlob: (hash: string) => Promise<Uint8Array | undefined>): Promise<FileHistoryResult>;
    private importHistoryCounted;
    /** The import body inside the blob lease (see {@link importHistory}). */
    private importStaged;
}
/** One mutation a restore asked of the env: the absolute path as addressed, what it did there (`bytes` on a planned write), and
 *  `real` — the same path as it really lies, read by the shared restore half's own preflight ({@link noteRealPath}); absent when
 *  the mutation did not come through that half (its real place was never read). */
interface EnvMutation {
    readonly at: string;
    readonly real?: string;
    readonly action: "write" | "delete" | "mode";
    readonly bytes?: Uint8Array;
}
/** A mutation the shared restore half was about to make and did not, because the view holds its file ({@link RestoreHolds}): the
 *  path as addressed, its real path, and the held file it lands on (as the frozen row names it). */
interface HeldMutation {
    readonly at: string;
    readonly real: string;
    readonly file: string;
}
/** What a view saw of one restore: the mutations it recorded (performed or planned), the ones it held, and the real path the shared
 *  restore half stated for each path it was about to mutate and the view did not hold (`told`: addressed → real, whether or not the
 *  mutation then landed). */
interface RestoreSeen {
    readonly mutations: readonly EnvMutation[];
    readonly held: readonly HeldMutation[];
    readonly told: ReadonlyMap<string, string>;
    /** On a WITNESSING view: how many mutations (a write, a delete, a change of mode, a directory made) the restore asked of the env,
     *  and how many of them answered done — whatever their path. A held mutation, and one the view refused itself, was never asked.
     *  Zero on a planning view, which asks the env for none. */
    readonly asked: {
        readonly issued: number;
        readonly done: number;
    };
    /** On a PLANNING view: what the shared restore half found at each path it read and would converge it to ({@link notePlannedState}),
     *  the first state per path — the plan a restore is then held to. */
    readonly states: ReadonlyMap<string, string>;
}
/** Whether a witnessed restore moved the working tree ({@link RewindMoved}), read off its view's {@link RestoreSeen.asked}: one done
 *  ⇒ `"some"`; asked and none done ⇒ `"unknown"` (a failed write may have written part); none asked ⇒ `"none"`. */
export declare function restoreMovedOf(seen: Pick<RestoreSeen, "asked">): RewindMoved;
/**
 * The files a restore must not move under ANY key: the file of every frozen row it lists ({@link fileHistoryEntryFrozen} — the
 * row's recorded place joined with its key's last segment, the store's own composition), keyed by its spelling folded the way the
 * frozen judgment folds a directory ({@link foldedFile}), with the keys of the frozen rows that name it. A frozen entry is never
 * written through its link; another key that resolves to the same file (the file's real-path key an engine minted after the
 * upgrade, or a key spelled through another link to it) would land a version that may not be the turn's, so it is held too, before
 * it writes — and the frozen row with it ({@link leftOnlyWhereUntouched}). Two files whose names differ only in letter case are one
 * file here, on a volume that tells them apart too: such a pair is held (not written, named), never written on a guess.
 */
export type RestoreHolds = ReadonlyMap<string, {
    readonly file: string;
    readonly frozenKeys: readonly string[];
}>;
/** A view of `env` that performs every call and records the mutations a restore made through it; it holds the files `holds` names
 *  (a plan's, {@link FileHistoryRestorePlan.holds}), refuses a file the plan read otherwise (`planned`, its
 *  {@link FileHistoryRestorePlan.states}), and when `leaveOutsideRoot` is given (a forked session's rewind root) leaves every file
 *  outside that root as it is and refuses unplaced mutations. */
export declare function witnessEnvOf(env: ExecutionEnv, holds?: RestoreHolds, planned?: ReadonlyMap<string, string>, leaveOutsideRoot?: string): {
    env: ExecutionEnv;
} & RestoreSeen;
/** A restore as the engine answers it: its rows, each stating `outsideRoot`. */
type AnsweredRestore = FileHistoryRestoreResult & {
    files: Array<FileHistoryRewindFile & {
        outsideRoot: boolean;
    }>;
    leftAsIs?: Array<FileHistoryLeftAsIsFile & {
        outsideRoot: boolean;
    }>;
};
/** Where a rewind at `root` lands a key: the key resolved on the root; a key the restore could not join on it (it would escape it,
 *  refused `key_unresolvable`) where it would have landed — the key joined on the root as written, an absolute path like every other. */
export declare function rewindTargetOf(root: string): (key: string) => string;
/**
 * THE pairing of a restore's mutations with one of its file rows — the rewind's answer (a row's `action`, a failed row's landed
 * write) and every reader of a plan's {@link FileHistoryRestorePlan.changes} pair here: the mutations addressed at the row's
 * `targetPath`, as addressed. A backend re-joins each key with {@link resolveTrackKey} and converges it through
 * {@link applyFileRestoreViaEnv} (both under the "MUST reuse" clause), so the mutations it asks are addressed at its rows'
 * `targetPath`; one that spells a path another way (relative, `./`, a doubled separator, another letter case) pairs no row with it.
 * Built once over the mutations (each row's lookup is one map read), in the order the restore asked them.
 */
export declare function mutationIndexOf<M extends {
    readonly at: string;
}>(mutations: readonly M[]): (targetPath: string) => readonly M[];
/** `restored` with its per-file answer ({@link FileHistoryRewindFile}), read off what the restore asked of its view (the mutations
 *  and the held ones), and every row's `outsideRoot` judged against `root` (the root the rewind is handed: its real path) where the
 *  file really lies: the real path the shared restore half stated for the path it addressed (`told`, whether the mutation then landed,
 *  failed or was refused by the env; or `held`), else the path as resolved on the root — so a key spelled through a link inside the
 *  root that leads out of it is outside, as the run's `restore_outside_root` note reads it off these rows. A left row lies in its
 *  `place` (a real path). */
export declare function withRewindFiles(storeAnswer: FileHistoryRestoreResult, seen: RestoreSeen, root: string): AnsweredRestore;
/** A restore PLANNED (see the section header): the ledger the store answered on a view that performs no write, with its files,
 *  and the preview — the line arithmetic of the writes and deletes it asked for, and the plan's own rows (`files`, `refused`,
 *  `failed`, `leftAsIs`). */
export interface FileHistoryRestorePlan {
    readonly restore: AnsweredRestore;
    readonly diffStats: FileHistoryDiffStats & Required<Pick<FileHistoryDiffStats, "refused" | "failed">> & Pick<AnsweredRestore, "files" | "leftAsIs">;
    /** The files the restore holds ({@link RestoreHolds}: its frozen rows' files) — what the plan held, and what the restore that
     *  carries it out holds ({@link witnessEnvOf}). Empty when the restore lists no frozen row. */
    readonly holds: RestoreHolds;
    /** What the plan read at each path it reached and would converge it to ({@link RestoreSeen.states}) — what the restore that carries it
     *  out holds every write, delete and change of mode to ({@link witnessEnvOf}): a file found otherwise, or never reached by the plan, is
     *  refused `changed_since_plan`. */
    readonly states: ReadonlyMap<string, string>;
    /** The keys of the restore's frozen rows (sorted) when the plan also asked a mutation whose real path the shared restore half did
     *  not read (the store converged a file another way, or through an env it wrapped): which file such a write lands on cannot be
     *  told, so it cannot be held — a seat refuses the whole restore before any file moves. Absent otherwise. */
    readonly unheld?: readonly string[];
    /** True when the plan is for a forked session (`forkedSession`) and asked a mutation whose real path the shared restore half did
     *  not read: where such a write lands cannot be told, so a seat refuses the whole restore before any file moves. Absent otherwise. */
    readonly unplacedForFork?: true;
    /** The plan's mutations one by one, in the order the restore asked them, with what the preview's arithmetic read of each: a
     *  write's or a delete's current file (`current`: {@link FileHistoryPlannedCurrent}, `undefined` when it could not be read — no
     *  lines then) and its lines (current → target; `diffStats`' `insertions` / `deletions` are their sums); a change of mode alone
     *  reads nothing. The one computation a reader of "this boundary against the working tree" reads. */
    readonly changes: readonly FileHistoryPlannedChange[];
}
/** One mutation of a {@link FileHistoryRestorePlan}: the path as the restore addressed it (`at`, the row's `targetPath`), what it
 *  would do there, and — for a write or a delete — the bytes it would write (`target`, absent for a delete), the current file the
 *  arithmetic read and the lines it counted. */
export type FileHistoryPlannedChange = {
    readonly at: string;
    readonly action: "mode";
} | {
    readonly at: string;
    readonly action: "write" | "delete";
    readonly target?: Uint8Array;
    readonly current: undefined;
} | {
    readonly at: string;
    readonly action: "write" | "delete";
    readonly target?: Uint8Array;
    readonly current: FileHistoryPlannedCurrent;
    readonly lines: {
        readonly insertions: number;
        readonly deletions: number;
    };
};
/** The current file a planned write or delete was counted against: none there (`null`); or there — its size and whether its bytes are
 *  binary ({@link bytesAreBinary}). A plan keeps no current bytes: it holds each file only while it counts it (and hands it to the
 *  caller's `readCurrent` then, when one is passed). */
export type FileHistoryPlannedCurrent = null | {
    readonly size: number;
    readonly binary: boolean;
};
/**
 * THE plan of a restore — the preview, the run's all-or-nothing gate and the hold every restore performs under: the store's own
 * `restore` on a view of the env that performs no write. The files of the frozen rows it lists are held ({@link RestoreHolds}); when
 * a planned mutation lands on one, the store plans again on a view that holds them (the shared restore half refuses that key before it
 * writes, the frozen row is refused with it), and that second pass is the plan. A restore that lists no frozen row plans once, as
 * before; so does one no planned mutation reaches.
 */
export declare function planFileHistoryRestore(store: Pick<FileHistoryStore, "restore">, input: {
    scope: string;
    entryId: string;
    env: ExecutionEnv;
    root: string;
    signal?: AbortSignal;
    /** The rewind's options as the request states them: the word {@link UNPLACED_AT_REWIND_ROOT} is read as `root` here ({@link restoreOptionsAt}). */
    options?: FileHistoryRestoreOptions;
    /** Whether the session being rewound has a provenance (its row carries `forkedFrom`, other than its own id): when `true`, a
     *  rewind neither writes, deletes nor re-modes any file whose real path lies outside `root` — each such file is left as it is
     *  (`leftAsIs`, class `recorded_outside_root`) and an unplaced mutation is refused. Absent = `false`. */
    forkedSession?: boolean;
    /** Called once for each planned write (with the bytes it would write) or delete (`target` null) whose current file the arithmetic
     *  read (`current` null: none there), in the order the restore asked them, while the plan holds those bytes — it keeps none after. */
    readCurrent?: (at: string, current: Uint8Array | null, target: Uint8Array | null) => void;
}): Promise<FileHistoryRestorePlan>;
/**
 * The read-only check for frozen history ({@link fileHistoryEntryFrozen}): which tracked files of a session's history a boundary no
 * longer reads and a rewind leaves as they are. Answered from the store's own export ({@link FileHistoryStore.exportHistory}, its
 * `frozenEntryKeys`): it changes nothing, reads nothing but the store, and needs no root — the judgment is the entry's own. `scope`
 * is the session's history scope (`fileHistoryScopeOf(sessionId, incarnation)`). Answers `{ keys }`, sorted; empty = none (a scope
 * with no history included). A store without `exportHistory` cannot be checked (thrown, `config.invalid_argument`); a history the
 * store cannot read whole throws the export's own failure ({@link FileHistoryStoreError}: its `code`, its `permanence`).
 */
export declare function listFrozenFileHistoryEntries(store: Pick<FileHistoryStore, "exportHistory">, scope: string): Promise<{
    readonly keys: readonly string[];
}>;
/** Test-only window (family-aware path-coordinate pins + the DV-6 track-key coordinate): pure
 *  helpers whose behavior carries a fence/restore invariant. Not re-exported from src/index.ts. */
export declare const __testables: {
    joinUnder: typeof joinUnder;
    relUnder: typeof relUnder;
    stripTrailSep: (p: string) => string;
    trackKeyOf: typeof trackKeyOf;
    resolveTrackKey: typeof resolveTrackKey;
    parentDirOf: typeof parentDirOf;
};
export {};
