import { EngineTurnHoldNotices, type HeldItem } from "./engine-turn-hold-notices.ts";
import type { CustomMessage } from "./messages.ts";
import type { HistoryReducer } from "./session-history-reduce.ts";
import type { SessionEntry } from "./session-manager.ts";
export type HoldKind = "unattended" | "session_hold" | "run_fence" | "inherited_hold";
export type HoldReleaseCause = "input" | "resume_session" | "run_resume" | "run_cancelled" | "node_cancelled" | "session_close";
export interface SessionHold {
    kind: HoldKind;
    key: string;
    since: string;
    data?: unknown;
    sourceCounts: Record<string, number>;
}
export type SessionHoldEvent = {
    type: "session_paused";
    pauseSeq: number;
    kind: HoldKind;
    at: string;
    noticeCount: number;
    persisted: boolean;
} | {
    type: "session_resumed";
    pauseSeq: number;
    cause: HoldReleaseCause;
    at: string;
} | {
    type: "session_notice";
    noticeIds: string[];
    noticeCount: number;
    disposition: "notice_persisted" | "model_consumed";
};
/** Scan only ledger entries without materializing a compacted session's transcript. */
export declare const engineTurnHoldHistory: HistoryReducer<SessionEntry[]>;
export declare function engineWakeSource(customType: string): string;
/** One session-scoped hold ledger, independent of the transcript leaf. */
export declare class EngineTurnHold {
    private records;
    private readonly notices;
    private pauseSeq;
    /** The seq of the newest hold that pauses the session, which `session_paused` announced (senpi#6900). */
    private announcedSeq;
    private released;
    private releaseBarrier;
    private goalDeferred;
    private generationValue;
    private attended;
    /** A `session_paused` is out with no `session_resumed` yet; a replayed held ledger counts as paused. */
    private pauseOpen;
    private readonly append;
    private readonly notify;
    private readonly emit;
    constructor(entries: readonly SessionEntry[], unattended: boolean, append: (type: string, data: unknown) => unknown, notify: (message: string) => void, emit: (event: SessionHoldEvent) => void);
    /** A run fence alone holds only wakes tagged with its run (senpi#3811), so it does not hold the session. */
    isHeld(): boolean;
    get fences(): SessionHold[];
    get held(): boolean;
    get awaitingInput(): boolean;
    get generation(): number;
    get releasing(): boolean;
    invalidate(): void;
    attend(): void;
    get holds(): SessionHold[];
    /** The seq of the newest hold added on this session; a hold's own seq is the value read right after it was added. */
    get currentPauseSeq(): number;
    /**
     * Whether a Resume quoting `expectedSeq` has seen every hold that pauses the session. Run fences raise the seq
     * without pausing anything, so a seq from before a fence, up to the current one, is still current (senpi#6900).
     */
    isCurrentPauseSeq(expectedSeq: number): boolean;
    getHold(key: string): SessionHold | undefined;
    get sources(): Record<string, number>;
    get noticeCount(): number;
    start(): void;
    addHold(kind: HoldKind, opts?: {
        key?: string;
        data?: unknown;
    }): void;
    release(keys: string[], cause: HoldReleaseCause): void;
    holdsSource(source: string): boolean;
    note(source: string, message?: CustomMessage): void;
    /**
     * A held itemized batch, written all-or-nothing: each item becomes its own notice with its own `session_notice`
     * event, and a failed write throws with no item kept (senpi#3811 design 4.5).
     */
    noteItems(items: readonly HeldItem[]): Array<{
        itemId: string;
        noticeId: string;
        entryId: string;
    }>;
    messages(): ReturnType<EngineTurnHoldNotices["messages"]>;
    releaseAll(cause: HoldReleaseCause): Record<string, number>;
    /** Undo a release whose input never reached admission: lower the barrier and keep every held wake held. */
    abandonRelease(): void;
    rejectInput(): void;
    consume(source: string, deliveredIds?: readonly string[]): boolean;
    finish(): Record<string, number>;
    private get stopped();
    private showNotice;
    private writeFailed;
}
//# sourceMappingURL=engine-turn-hold.d.ts.map