/** * Kill-switch checker for Tier-3 merge-ritual steps. * * Provides a lightweight, fs.watch-backed cache of the `killSwitch` field in * `.cleo/sentient-state.json`. Every Tier-3 step-transition calls * {@link checkKillSwitch} to abort the ritual immediately if the operator has * activated the kill switch. * * Design notes: * - A module-level cache (`cachedKillSwitch`) is updated by the watcher so that * synchronous read pressure on the state file is near-zero during a running * ritual. The watcher fires on file change events and re-reads the JSON. * - Debounce of 100 ms is applied so rapid successive writes (e.g. atomic * tmp-rename) don't cause thundering re-reads. * - `startKillSwitchWatcher` is idempotent — calling it multiple times * replaces the previous watcher. The returned function closes the watcher. * - `__setKillSwitchForTest` bypasses disk entirely for unit tests. * * State-file shape: * ```json * { * "killSwitch": true, * "activatedAt": "2026-04-20T00:00:00.000Z", // optional * "activatedBy": "operator" // optional * } * ``` * * @see ADR-054 — Sentient Loop Tier-1/Tier-3 * @task T1027 */ /** * Labels for each transition point in the Tier-3 10-step merge ritual. * * The ritual steps are: * 1. pre-pick — before cherry-pick selection * 2. post-pick — after cherry-pick selection * 3. pre-spawn — before worker agent is spawned * 4. post-spawn — after worker agent completes * 5. pre-verify — before evidence gates are checked * 6. post-verify — after all gates pass * 7. pre-sign — before Ed25519 receipt is signed * 8. post-sign — after signing completes * 9. pre-merge — before `git merge --ff-only` * 10. post-merge — after merge succeeds (operator must manually revert if * the kill switch fires here) */ export type StepLabel = 'pre-pick' | 'post-pick' | 'pre-spawn' | 'post-spawn' | 'pre-verify' | 'post-verify' | 'pre-sign' | 'post-sign' | 'pre-merge' | 'post-merge'; /** * Thrown by {@link checkKillSwitch} when the kill switch is active. * * Callers in the Tier-3 ritual should propagate this error up to the ritual * runner, which logs the abort and exits cleanly. */ export declare class KillSwitchActivatedError extends Error { /** The step at which the kill switch was detected. */ readonly step: StepLabel; /** ISO-8601 timestamp at which the kill was detected (now). */ readonly killedAt: string; /** * @param step - The ritual step where the kill switch was detected. * @param killedAt - ISO-8601 timestamp of detection. */ constructor(step: StepLabel, killedAt: string); } /** * Check the kill switch at a ritual step boundary. * * Reads the cached value set by the watcher. If no watcher is running (cache * is `undefined`), falls back to a one-shot file read. Throws * {@link KillSwitchActivatedError} immediately if the flag is `true`. * * Call this at EVERY step-transition in the Tier-3 merge ritual. * * @param step - The ritual step at which the check is performed. * @param stateFile - Optional absolute path to `sentient-state.json`. * Defaults to `/.cleo/sentient-state.json`. * @throws {KillSwitchActivatedError} When the kill switch is active. */ export declare function checkKillSwitch(step: StepLabel, stateFile?: string): Promise; /** * Start the fs.watch singleton watcher on `sentient-state.json`. * * The watcher keeps {@link cachedKillSwitch} up to date so that * {@link checkKillSwitch} never needs to hit the disk mid-ritual. Changes * are debounced by 100 ms to handle atomic tmp-then-rename writes. * * Calling this function replaces any previously registered watcher (the old * watcher is closed first). * * @param stateFile - Absolute path to `sentient-state.json`. * Defaults to `/.cleo/sentient-state.json`. * @returns An unsubscribe function that closes the watcher and resets the * cache. Call this during process shutdown or test teardown. */ export declare function startKillSwitchWatcher(stateFile?: string): () => void; /** * Override the cached kill-switch value for unit tests. * * Bypasses disk I/O and the fs.watch watcher entirely. Call with `false` * in `afterEach` to restore a clean state between test cases. * * @param value - The kill-switch value to inject into the cache. * * @internal */ export declare function __setKillSwitchForTest(value: boolean): void; /** * Reset the module-level kill-switch cache to `undefined`. * * Used in test teardown when tests exercise the disk-read fallback path and * need to ensure subsequent tests start with a clean (uncached) state. * Distinct from {@link __setKillSwitchForTest} which sets a concrete value. * * @internal */ export declare function __resetKillSwitchCacheForTest(): void; //# sourceMappingURL=kill-switch.d.ts.map