import type { FSWatcher } from "node:fs"; import { type RateLimitRule } from "../identity/RateLimiter.js"; import type { SecurityEvents } from "./SecurityEvents.js"; /** Why the executor stopped taking new work. */ export type HaltTrigger = "OPERATOR" | "HALT_FILE" | "POSTURE_DRIFT" | "AUTH_FAILURE_SPIKE" | "EGRESS_REFUSAL_SPIKE" | "CLOCK_SKEW" | "AUDIT_CHAIN_BROKEN" | "EFFECT_MISMATCH"; export interface HaltState { readonly halted: boolean; readonly trigger: HaltTrigger | null; /** An operator's words, or the trigger's own code; never anything from a request. */ readonly reason: string | null; readonly since: string | null; } export interface HaltSwitchOptions { readonly events: SecurityEvents; /** A file whose presence halts the executor, watched and polled; none when null. */ readonly haltFile?: string | null; /** `/`: how many door refusals in a window halt the executor. */ readonly authFailures?: RateLimitRule | null; readonly egressRefusals?: RateLimitRule | null; readonly posture?: { readonly degraded: boolean; }; readonly clock?: () => Date; readonly fileExists?: (path: string) => boolean; readonly pollSeconds?: number; /** * How the halt file's directory is followed. The default is `fs.watch`; a * test supplies its own so the error path, and the failure to watch at * all, are reachable without a filesystem that misbehaves on demand. */ readonly watchDirectory?: (path: string, onChange: () => void) => FSWatcher; } /** * The stop. It is deliberately easy to reach and deliberately hard to * leave: an operator halts with a reason, a file halts by existing, and a * spike of refusals at the door, a refused outbound request, a posture * drift, a clock that cannot be trusted or a broken evidence chain halt on * their own. While halted, the executor takes no new work; what is already * in flight finishes and is journaled, because abandoning a dispatch is how * an outcome becomes unknown. * * Resuming is an operator's act with a reason, and it is refused while the * cause still stands: the halt file still there, a posture drift still * standing, an attempt whose outcome nobody knows. A process that starts * with the halt file present starts halted. * * A spike threshold is reachable from the agent zone by design: a * compromised caller that floods the door with bad credentials stops the * executor rather than being ignored. That is the fail-closed choice, and * the threshold is configurable for institutions that would rather not. */ export declare class HaltSwitch { private readonly options; private state; private readonly limits; private readonly clock; private readonly exists; private readonly haltFile; private readonly authFailures; private readonly egressRefusals; private readonly pollMs; private readonly watchDirectory; /** The one thing `start()` leaves behind, so stopping is one call. */ private readonly stopper; private watcher; private cancelPoll; constructor(options: HaltSwitchOptions); get current(): HaltState; get halted(): boolean; /** Whether this switch is following a halt file right now. */ get following(): boolean; /** The halt file decides the starting state, so a restart does not undo a halt. */ assertAtStartup(): HaltState; /** Follows the halt file while running: created halts, removed only allows a resume. */ start(): () => void; stop(): void; /** One look at the halt file; for the interval, the watcher, and tests. */ check(): void; halt(trigger: HaltTrigger, reason: string): HaltState; /** * Lets work through again, on an operator's word and with a reason. It is * refused while the cause stands: the code says which cause, so the * operator fixes that rather than retrying. * * It is refused too while `unknownAttempts` (the count * `GET /v1/control/open-attempts` reports) is above zero * (`UNKNOWN_ATTEMPTS_OPEN`): the next proposal would be made against a state * nobody has reconciled. An operator who has resolved them against the * provider's own records, which this process cannot see, gives `override`, * a reason of their own, which is recorded beside the resume. */ resume(reason: string, unknownAttempts?: number, override?: string | null): { readonly resumed: boolean; readonly code: string | null; }; /** One refusal at the door; the window's threshold halts the executor. */ recordAuthFailure(): void; /** One outbound request the egress policy refused; the window's threshold halts. */ recordEgressRefusal(): void; private recordSpike; private haltFilePresent; } //# sourceMappingURL=HaltSwitch.d.ts.map