import { z } from "zod";
/**
 * Idempotency keys for local dispatches (`phren dispatch local ... --idempotency-key`).
 * A reservation is written to a temp file and published with `link`, which is
 * atomic and fails with EEXIST: an empty or half-written file is never a
 * reservation another caller can reclaim. Every update or delete checks the
 * owner nonce. The per-key mutex is in-process because only the Hook server
 * process mutates key records; the CLI reaches it through Hook routes.
 */
export declare const IDEMPOTENCY_TTL_MS: number;
/** A reservation that has not reached "launched" is interrupted after this. */
export declare const LAUNCH_INTERRUPTED_MS: number;
export declare const idempotencyKeySchema: z.ZodString;
declare const phaseSchema: z.ZodEnum<{
    failed: "failed";
    launched: "launched";
    launching: "launching";
    reserved: "reserved";
}>;
declare const recordSchema: z.ZodObject<{
    key: z.ZodString;
    dispatchId: z.ZodString;
    owner: z.ZodString;
    createdAt: z.ZodString;
    phase: z.ZodEnum<{
        failed: "failed";
        launched: "launched";
        launching: "launching";
        reserved: "reserved";
    }>;
    project: z.ZodOptional<z.ZodString>;
    harness: z.ZodOptional<z.ZodString>;
    label: z.ZodOptional<z.ZodString>;
    computer: z.ZodOptional<z.ZodString>;
    cloneDir: z.ZodOptional<z.ZodString>;
    gitConfigFile: z.ZodOptional<z.ZodString>;
    agentTokenFile: z.ZodOptional<z.ZodString>;
    workerFile: z.ZodOptional<z.ZodString>;
    startingToken: z.ZodOptional<z.ZodString>;
    cancelRequestedAt: z.ZodOptional<z.ZodString>;
}, z.core.$strict>;
export type IdempotencyRecord = z.infer<typeof recordSchema>;
export type IdempotencyPhase = z.infer<typeof phaseSchema>;
export declare const idempotencyKeyFile: (key: string) => string;
/** Called by the Hook server before it handles dispatches. */
export declare function markHookServerProcess(): void;
/** Delete lock and reclaim files left by an older Hook or a crash. */
export declare function cleanupIdempotencyLocks(): Promise<void>;
export type KeyReservation = {
    reserved: true;
    record: IdempotencyRecord;
} | {
    reserved: false;
    record: IdempotencyRecord;
};
export interface KeySeed {
    project?: string;
    harness?: string;
    label?: string;
    computer?: string;
    cloneDir?: string;
    gitConfigFile?: string;
    agentTokenFile?: string;
    workerFile?: string;
    startingToken?: string;
}
/** Reserve `key` for this caller, with its dispatch id, atomically. */
export declare function reserveIdempotencyKey(key: string, dispatchId: string, owner: string, seed?: KeySeed, now?: number): Promise<KeyReservation>;
/** Move the reservation's phase. False when this caller no longer owns it. */
export declare function updateIdempotencyPhase(key: string, owner: string, phase: IdempotencyPhase): Promise<boolean>;
/** Run under the key's in-process mutex, with the current reservation record. */
export declare function withIdempotencyKeyLock<T>(key: string, run: (record: IdempotencyRecord | undefined, save: (record: IdempotencyRecord) => Promise<void>) => Promise<T>): Promise<T>;
/** Record a cancellation on the reservation itself, under its mutex, before any receipt exists. */
export declare function requestIdempotencyCancel(key: string, now?: number): Promise<IdempotencyRecord | undefined>;
/** Release a reservation this caller owns and never launched. */
export declare function releaseIdempotencyKey(key: string, owner: string): Promise<boolean>;
/** The live record for a key, or undefined when there is none or it expired. */
export declare function findIdempotencyKey(key: string): Promise<IdempotencyRecord | undefined>;
/** Every live reservation, for reconciliation on Hook start. */
export declare function listIdempotencyRecords(): Promise<IdempotencyRecord[]>;
/** Wait for the reserving caller to name its dispatch. Undefined when the key disappears or the wait runs out. */
export declare function waitForIdempotencyKey(key: string, timeoutMs?: number): Promise<IdempotencyRecord | undefined>;
/** A branch slug for a key: `agent/<key-slug>` or `agent/<dispatch id>` when there is no key. */
export declare function worktreeBranchFor(key: string | undefined, dispatchId: string): string;
export {};
