import { type OrphanToolCall } from "../session-reconcile.js";
import type { Session } from "../session.js";
import type { TaskResult } from "../types.js";
import type { Prepared, RunnerDepsSeat, RunState } from "./contracts.js";
import type { LegWritesAtClose } from "./session-write-ledger.js";
import { type RewindAsker } from "./rewind-target.js";
export type ContinuesFrom = NonNullable<TaskResult["continuesFrom"]>;
/**
 * The calls a reconcile would close by appending (`closableByAppend`) when the session's leaf is `leafId` — read off the branch
 * from that leaf, as the wake reconcile reads the branch from the current one. Empty ⇔ a run that continues the session from
 * `leafId` appends nothing there before it takes its input in. The one reading of "a landing reconcile appends nothing to".
 */
export declare function closableByAppendAt(session: Pick<Session, "getBranch">, leafId: string): Promise<OrphanToolCall[]>;
/**
 * A rewind's landing is held to the same reading ({@link closableByAppendAt}): a landing where a call has no result is refused
 * `resume_at.open_tool_call`, nothing written — a run continued from there would first close it with a synthetic interruption. One
 * judgment for every entry that moves a leaf back: a run's `resumeAt` (either mode) and `Runner.rewindConversation` (its preview too).
 */
export declare function refuseOpenToolCallAt(session: Pick<Session, "getBranch">, leafId: string, target: string, asker: RewindAsker): Promise<void>;
/**
 * The one teardown bound the waits ahead of `done` share (the date anchor, the cross-boundary record, then the landing's branch
 * read — in that order: the record appends on the leaf the anchor leaves, and the read is of the leaf the close reads after both).
 * The first call starts it; each wait is granted an equal share of what is left among the waits from it to the read (`ahead`, itself
 * included), so a wait that answers early leaves the rest of its share to the ones after it, one that stalls costs only its share, and
 * together they delay `done` by one bound at most. With all three ahead the anchor waits at most a third of the bound, the record half
 * of what is left, the read all that is left.
 */
export declare function settleBound(): (ahead: number) => number;
/**
 * The two records the session's next leg reads that a leg owes at its end — the date anchor (a session's first leg; a leg whose date
 * or prompt head moved, or that read the memory store live: `owedDateAnchor`) and the cross-boundary leg-end record (a bit a child set after the leg's last exit, and what
 * the background tasks its task access reaches will deliver — read before the teardown's reaps stop any of them). The returned writer
 * runs once: the settle calls it ahead of the landing it reads, the teardown on a lane that threw before that. Best-effort: a write
 * that fails or does not answer inside its share of `bound` is reported (the cross-boundary lane reports its own store failures
 * and its own timeout) and leaves the run's terminal and its landing as they are.
 */
export declare function legEndRecords(prepared: Prepared, rs: RunState, runner: RunnerDepsSeat, bound: (ahead: number) => number): () => Promise<void>;
export interface SettledContinuesFromInput {
    /** What the leg's write view held when it closed (`LegWrites.close`). */
    closed: LegWritesAtClose;
    /** The run has not ended: the leg committed a durable park (any gate), or its resume put the approval back to pending. */
    runOpen: boolean;
    /** The leg's session (its branch is read from the leaf the leg left it on). */
    session: Pick<Session, "getBranch">;
    sessionId: string;
    /** The bound the two records already drew on (`settleBound`): the branch read, the last wait, gets all that is left of it, not a bound of its own. */
    bound: (ahead: number) => number;
    /** Where a landing that is not known settled says why (the value is then `unsettled`). */
    report: (err: unknown) => void;
}
/**
 * The reading of a leg that reached its settle, in this order: the run is still open ⇒ `run_open`; a write of the leg had not
 * settled at the close ⇒ `unsettled`; the leg landed no write ⇒ `nothing_taken_in`; one of its writes landed on a leaf other than
 * the one its previous write left (another writer moved the session between two of the leg's writes, so the branch at the leaf is
 * not this leg's conversation) ⇒ `unsettled`, said once; the conversation up to the leaf after its last landed write holds a call a
 * reconcile would close by appending ({@link closableByAppendAt}), or that branch cannot be read (a read that fails or does not
 * answer inside what is left of the bound) ⇒ `unsettled`; else that leaf. The first write is checked like the rest: its parent must
 * be the leaf the leg took the session at, so an entry another writer added after that — even before the leg read its context — is
 * not taken for the leg's.
 */
export declare function settledContinuesFrom(input: SettledContinuesFromInput): Promise<ContinuesFrom>;
/** The reading of a leg that ended in a throw before its settle: nothing written and nothing in flight ⇒ `nothing_taken_in`;
 *  anything else is not known settled ⇒ `unsettled`. */
export declare function unsettledLegContinuesFrom(closed: LegWritesAtClose): ContinuesFrom;
