import type { LoopHookCallFacts, LoopWakeRoute } from "../../core/extensions/runner.ts";
import type { SessionEntry } from "../../core/session-manager.ts";
/** A message a loop hook sent during its call, for the loop to send with the same options. */
export interface SentLoopMessage {
    readonly message: Parameters<LoopHookCallFacts["sendMessage"]>[0];
    readonly options?: Parameters<LoopHookCallFacts["sendMessage"]>[1];
}
/** An entry a loop hook appended during its call, for the loop to append to its own session (session port, write). */
export interface AppendedLoopEntry {
    readonly customType: string;
    readonly data?: unknown;
}
/** A user message a loop hook sent during its call, for the loop to send with the same options (session port, write). */
export interface SentLoopUserMessage {
    readonly content: Parameters<LoopHookCallFacts["sendUserMessage"]>[0];
    readonly options?: Parameters<LoopHookCallFacts["sendUserMessage"]>[1];
}
/**
 * The session port's read half (r3 N2): the loop facts a call carries beyond the session's id. The loop owns the
 * session; it sends its current leaf and the entries THIS hand authored earlier in the session (the ones it appended
 * from {@link LoopHookEffects.entries}), after the last compaction only. A hand never sees entries the loop authored.
 */
export interface CarriedSession {
    readonly leafId: string | null;
    readonly handEntries: readonly SessionEntry[];
}
/** What a loop-hook call's handlers did beyond their result, which the loop does in turn (session port, write). */
export interface LoopHookEffects {
    readonly sent: SentLoopMessage[];
    readonly notices: LoopNotice[];
    readonly entries: AppendedLoopEntry[];
    readonly userMessages: SentLoopUserMessage[];
}
/** What a loop-hook call binds its handlers' facts to: the loop session's state the call carries. */
export interface LoopHookCallBinding {
    readonly sessionId: string;
    readonly cwd: string;
    /** The loop's idle state the call carries. */
    readonly idle: boolean;
    /** The session port's read half, when the call carries it (an `agent_end` does). */
    readonly carried?: CarriedSession;
    /**
     * Whether the loop's turn has ended by this call (an `agent_end`): after the call, its work sees the session idle until
     * the loop starts another call for that session, as a local session is idle after a turn until the next one starts.
     */
    readonly endsTurn?: boolean;
}
/** A notice a loop hook showed during its call, for the loop to show on its own UI. */
export interface LoopNotice {
    readonly message: string;
    readonly type?: Parameters<LoopHookCallFacts["notify"]>[1];
}
/**
 * The loop facts a hand's runner sees during one loop-hook call (S33): the loop session's id, read-only (no transcript
 * path: the transcript lives where the loop runs), the session port (the read half the call carries, and writes the
 * loop applies to its own session: `appendEntry`, `sendUserMessage`), the call's own abort signal, and idle (a
 * forwarded `before_agent_start` starts a turn from idle). Outside the call no loop-side member is bound. After the call
 * ended, its work keeps what {@link LoopHookCallEndedError} lists; the session's identity is bound to the call only.
 */
export interface LoopHookCall {
    /** The facts of the loop-hook call in progress in this async context; none outside one. */
    current(): LoopHookCallFacts | undefined;
    /**
     * The sender of the call whose work runs in this async context, also after that call ended: a message sent then
     * goes to the call's late route (on a hand, a durable wake to the loop), in order.
     */
    sender(): LoopHookCallFacts["sendMessage"] | undefined;
    /** The call's session writes (`appendEntry`, `sendUserMessage`) for its work, routed like {@link sender}. */
    writer(): Pick<LoopHookCallFacts, "appendEntry" | "sendUserMessage"> | undefined;
    /** Runs `dispatch` as the call bound to `binding`; `effects` collects what its handlers send, notify and write. */
    run<T>(binding: LoopHookCallBinding, dispatch: (effects: LoopHookEffects) => Promise<T>): Promise<T>;
}
/**
 * Where a call's effects go once that call ended, for its loop session (brain/hand split H3): on a hand, the durable
 * wake outbox, so they reach the loop at least once whether or not the session makes another call, and never through a
 * reply that may be lost. A held Stop's stop-state entries and its block follow-up travel this way too, so a block from
 * an idle loop's Stop wakes that loop. Late work never throws into the user's hook code.
 */
export type LateLoopRoute = (sessionId: string) => LoopWakeRoute;
export declare function createLoopHookCall(late: LateLoopRoute): LoopHookCall;
/**
 * The deliberate refusal after a loop-hook call ended (option A): the loop session's identity (`getSessionId`,
 * `getSessionFile`, `getCwd`) is bound to that call only, so reading it from a kept context afterwards throws this
 * instead of answering. The session the call carried (`getLeafId`, `reduceHistory`) stays readable by the call's own
 * work (its async context: a Stop it held for background work), and refused from any other context. Every other member
 * keeps working: late writes, messages and notices go to the call's late route; the signal stays aborted; idle keeps
 * its value, except that after a call that ended the loop's turn it answers idle until the loop starts another call.
 */
export declare class LoopHookCallEndedError extends Error {
    readonly name = "LoopHookCallEndedError";
    /** The member that was read, e.g. `sessionManager.getSessionId`. */
    readonly member: string;
    constructor(member: string);
}
//# sourceMappingURL=loop-hook-call.d.ts.map