/**
 * One authority snapshot per command (omo-relay-daemon#307). A host-mode delegated line runs inside a
 * `CommandAuthority`: its first role check takes the one `Atomics.load` of the captured incarnation's word, every later
 * check in the same command reuses it, and the responses that command produces carry the receipt
 * `authority: {exec, incarnation, epoch, roles}` when the forwarder numbered the record with `relayExec`.
 */
import { AsyncLocalStorage } from "node:async_hooks";
import type { DelegationDescriptor } from "./delegation-record.ts";
export interface AuthorityReceipt {
    readonly exec: number;
    readonly incarnation: number | null;
    readonly epoch: number | null;
    /** The effective roles the command's role checks read, or null when it consulted none. */
    readonly roles: readonly string[] | null;
}
export declare class CommandAuthority {
    readonly connection: string | undefined;
    readonly descriptor: DelegationDescriptor | undefined;
    readonly exec: number | undefined;
    /** A worker command of an older incarnation than the one it retained: every role check reads retired. */
    private readonly stale;
    private snapshot;
    private consulted;
    constructor(connection: string | undefined, descriptor: DelegationDescriptor | undefined, exec: number | undefined, stale?: boolean);
    get incarnation(): number | undefined;
    private state;
    /** Whether `claim` (this command's incarnation's claim) grants `role`, read from the one snapshot. */
    has(role: string, claim: readonly string[] | undefined): boolean;
    receipt(): AuthorityReceipt | undefined;
}
export declare const commandAuthority: AsyncLocalStorage<CommandAuthority>;
/**
 * Runs `create` outside any command's authority. On Node, a Worker (and every MessagePort) runs its listeners in the
 * async context it was constructed in, so a session worker created by a role-bound command would otherwise stamp that
 * command's receipt onto every later response it forwards. Anything long-lived a command creates is built through this.
 */
export declare function outsideCommand<T>(create: () => T): T;
/**
 * Adds the running command's receipt to a response addressed to that command's connection. A response that already
 * has a top-level `authority` (a worker's own, stamped where it ran) is never overwritten.
 */
export declare function withReceipt<T extends object>(record: T, target: string | undefined): T;
/**
 * Takes the forwarder's `relayExec` out of a host-mode record before anything else sees it: a positive safe integer,
 * absent, or `"malformed"` for any other value.
 */
export declare function takeRelayExec(record: unknown): number | undefined | "malformed";
//# sourceMappingURL=command-authority.d.ts.map