/** * Keep the computer from idle-sleeping while the agent works. * * Autopilot cycles, task sweeps and long runs die halfway when a laptop idles * into system sleep. This holds an OS power assertion for as long as any agent * work is in flight. Only idle SYSTEM sleep is prevented — the display may * still turn off, and an explicit sleep (lid close, menu) still wins. * * No native dependencies: each platform's own tool holds the assertion in a * child process, and the assertion dies with that child. * * - macOS: `caffeinate -i -w ` — exits by itself when our process dies. * - Linux: `systemd-inhibit --what=idle:sleep … tail --pid= -f /dev/null` * — the inhibitor lock lives as long as `tail`, which exits when our process * dies. Spawned as its own process group so release kills both. No * systemd-inhibit (non-systemd distro) → logged no-op. * - Windows: a hidden PowerShell that P/Invokes `SetThreadExecutionState( * ES_CONTINUOUS | ES_SYSTEM_REQUIRED)` and then `Wait-Process`es our PID. * The execution state is per-thread, so it is cleared when that process ends. * * Reference-counted: overlapping runs (several windows, a run plus a Ken reply, * background sub-agents) share one OS assertion, which is dropped when the last * holder releases. */ /** A platform tool invocation, always an argv array — never a shell string. */ export interface KeepAwakeCommand { command: string; args: string[]; } /** The spawned assertion holder, abstracted so tests can inject a fake. */ export interface KeepAwakeProcess { /** Terminate the holder (and its children). Must be safe to call twice. */ stop(): void; /** Called once when the holder exits for any reason. */ onExit(listener: () => void): void; /** Called when the holder fails to spawn (e.g. ENOENT: tool missing). */ onError(listener: (error: NodeJS.ErrnoException) => void): void; } export type KeepAwakeSpawner = (command: KeepAwakeCommand) => KeepAwakeProcess; type KeepAwakeLog = (level: "INFO" | "WARN", message: string, data?: Record) => void; export interface KeepAwakeOptions { platform?: NodeJS.Platform; /** The process the assertion is tied to. Defaults to `process.pid`. */ pid?: number; /** Initial state of the `keepAwake` setting. Defaults to true. */ enabled?: boolean; spawner?: KeepAwakeSpawner; log?: KeepAwakeLog; /** Registers a synchronous last-chance cleanup. Defaults to `process.once("exit")`. */ onProcessExit?: (cleanup: () => void) => void; } /** The OS tool that holds an idle-sleep assertion tied to `pid`, or null if none. */ export declare function keepAwakeCommand(platform: NodeJS.Platform, pid: number): KeepAwakeCommand | null; /** Real spawner: argv array, no shell, hidden window, stdio ignored. */ export declare function spawnKeepAwakeProcess(cmd: KeepAwakeCommand): KeepAwakeProcess; /** Reference-counted holder of one OS idle-sleep assertion. */ export declare class KeepAwake { private readonly holds; private nextId; private enabled; private child; /** The platform tool is missing — permanently a no-op for this process. */ private unavailable; /** The holder died on its own; don't respawn until holders drop to zero. */ private suspended; private exitHookInstalled; private readonly platform; private readonly pid; private readonly spawner; private readonly logLine; private readonly onProcessExit; constructor(options?: KeepAwakeOptions); /** Hold the assertion until the returned release runs. Release is idempotent. */ acquire(reason: string): () => void; /** Apply the `keepAwake` setting live; outstanding holds survive a toggle. */ setEnabled(enabled: boolean): void; get isEnabled(): boolean; get holderCount(): number; /** True while an OS assertion holder process is running. */ get asserting(): boolean; /** Drop every hold and the OS assertion (shutdown). */ dispose(): void; private sync; private startChild; private stopChild; private markUnavailable; } export {};