/**
 * How a due scheduled prompt reaches its session: a `--exec` hook process, or a headless
 * `senpi -p --session` resume guarded against another process having that session open.
 */
import type { ScheduledJob } from "../core/extensions/builtin/schedule/types.ts";
/** What a delivery hook receives on stdin, one JSON object. */
export interface ScheduledPromptEvent {
    readonly type: "scheduled_prompt";
    readonly id: string;
    readonly sessionId: string;
    readonly sessionFile: string | null;
    readonly cwd: string;
    /** The prompt exactly as scheduled. */
    readonly prompt: string;
    /** The prompt with a one-line provenance header; what the default delivery sends. */
    readonly message: string;
    readonly dueAt: number;
    readonly firedAt: number;
    readonly everyMs: number | null;
    /** Occurrence number, starting at 1. */
    readonly fireCount: number;
}
export type DeliveryResult = {
    readonly ok: true;
} | {
    readonly ok: false;
    readonly error: string;
    /** Nothing was delivered because another live process holds the session: retry later, not a failure. */
    readonly sessionHeld?: true;
};
/** Called with the delivery process pid as soon as it exists, so the session lock can record it. */
export interface DeliveryContext {
    readonly onSpawn?: (pid: number) => Promise<void>;
}
export type Delivery = (event: ScheduledPromptEvent, context?: DeliveryContext) => Promise<DeliveryResult>;
/** Returns a reason to leave a due job pending for now (for example: its session is open elsewhere). */
export type DeferProbe = (job: ScheduledJob) => Promise<string | undefined>;
export declare function movedJobPaths(job: ScheduledJob): Pick<ScheduledJob, "sessionFile" | "cwd">;
/** Default-delivery guard: do not start a second writer on a session another process has open. */
export declare function deferWhileSessionOpen(job: ScheduledJob): Promise<string | undefined>;
export interface ProcessLaunch {
    readonly command: string;
    readonly args: readonly string[];
    readonly cwd?: string;
    readonly env?: NodeJS.ProcessEnv;
    readonly stdin?: string;
    /** win32: pass `args` to the process unquoted (a `cmd.exe /s /c "..."` command line). */
    readonly windowsVerbatimArguments?: boolean;
    /** An exit code meaning the session was held and nothing ran; only the senpi resume delivery sets it. */
    readonly sessionHeldExitCode?: number;
}
/**
 * POSIX gate: the delivery command only starts once the runner writes a line on fd 3, which it does
 * after the process is attached to the session lock. If the runner dies first, fd 3 closes, `read`
 * fails, and nothing is delivered.
 */
export declare const POSIX_GATE = "IFS= read -r _ <&3 || exit 75; exec 3<&-; exec \"$0\" \"$@\"";
/**
 * Runs one delivery process to completion; exit 0 means delivered. The process is registered via
 * `context.onSpawn` before it may do any work (POSIX: it leads its own process group and waits on a
 * gate); a failed registration kills it and fails the delivery. A timeout kills the whole tree, and
 * the result is only reported once the process has exited.
 */
export declare function runDeliveryProcess(launch: ProcessLaunch, timeoutMs: number, context?: DeliveryContext): Promise<DeliveryResult>;
/**
 * `--exec <command>`: a shell command receives the event as JSON on stdin. It inherits the runner's
 * environment (the operator chose both the command and the environment the runner starts with).
 */
export declare function execHookDelivery(command: string, timeoutMs: number): Delivery;
/**
 * Default delivery: resume the scheduling session headlessly (`senpi -p --session <file|id>`) in
 * its working directory, so the fired prompt runs as a new turn of that session.
 */
export declare function sessionResumeDelivery(senpi: {
    command: string;
    args: readonly string[];
}, timeoutMs: number): Delivery;
//# sourceMappingURL=schedule-delivery.d.ts.map