import type { PowerInhibitClass, PowerPlatformSeam } from './types.js'; /** The ruling's honest-split line when a lid-switch block is not grantable. */ export declare const LID_SWITCH_HONEST_SPLIT = "idle sleep blocked; lid-close suspend is controlled by your OS here"; export interface PowerInhibitorView { readonly held: boolean; readonly grantedClasses: readonly PowerInhibitClass[]; readonly deniedClasses: readonly PowerInhibitClass[]; } /** The full state the contract serves (surfaces render the chip from this). */ export interface PowerState { readonly platform: string; readonly work: PowerInhibitorView & { /** The live reasons the inhibitor is held ("held because X"). */ readonly reasons: readonly string[]; readonly heldSince: number | null; readonly capMinutes: number; /** When the hard cap will force-release the WORK inhibitor (never the toggle). */ readonly capExpiresAt: number | null; /** True when the cap fired and released a still-working inhibitor (honest). */ readonly capExpired: boolean; }; readonly keepAwake: PowerInhibitorView & { readonly enabled: boolean; /** The honest-split note when part of the requested coverage was refused. */ readonly note: string | null; }; } export interface PowerSleepEdgeHooks { /** Checkpoint what's checkpointable, runs on PrepareForSleep(true). */ readonly onSleep?: (() => void | Promise) | undefined; /** Catch-up: re-arm timers, reconnect, deliver missed receipts, runs on wake. */ readonly onWake?: (() => void | Promise) | undefined; } export interface PowerManagerOptions { readonly seam: PowerPlatformSeam; /** Live config reads (power.* keys); absent keys use the shipped defaults. */ readonly readConfig?: ((key: string) => unknown) | undefined; /** Persist the keep-awake toggle (power.keepAwake) when set over the wire. */ readonly writeConfig?: ((key: string, value: boolean) => void) | undefined; /** * Subscribe to live config changes (ConfigManager.subscribe shape). When * present, a power.keepAwake change, from any writer, including an external * settings edit, applies LIVE, not just at start(). */ readonly subscribeConfig?: ((key: string, cb: (newValue: unknown) => void) => () => void) | undefined; /** Emits the state-change event surfaces subscribe the chip to. */ readonly onStateChanged?: ((state: PowerState) => void) | undefined; /** * Process exit/signal hook registration seam (injectable for tests). * Default registers on the real `process`. The registered cleanup releases * every held inhibitor so the out-of-process inhibit children die with us, * an exiting daemon must never leave a hold blocking host sleep. */ readonly registerProcessExitHooks?: ((cleanup: () => void) => () => void) | undefined; readonly now?: (() => number) | undefined; } export declare class PowerManager { private readonly options; private readonly workReasons; private workHandle; private workHeldSince; private workCapTimer; private workCapExpired; private keepAwakeHandle; private keepAwakeEnabled; private readonly sleepHooks; private unsubscribeSleepEdge; private unsubscribeKeepAwakeConfig; private unregisterExitHooks; /** Serializes acquire/release transitions so async seam calls never race. */ private transition; constructor(options: PowerManagerOptions); private now; private readBool; private capMinutes; /** * Start: reap dead-owner orphan inhibitors, register exit/signal cleanup, * apply the persisted keep-awake toggle, watch the sleep edge, and subscribe * keep-awake to live config changes. */ start(): Promise; stop(): Promise; /** * Release every held inhibitor NOW, without awaiting, for process-exit * paths where only synchronous work runs. The seam handles kill their * inhibit children synchronously before their first await, so the children * are signalled even from an 'exit' handler. */ releaseAllHoldsNow(): void; /** Register sleep-edge hooks (checkpoint on sleep, catch-up on wake). */ onSleepEdge(hooks: PowerSleepEdgeHooks): () => void; /** * Hold the work inhibitor for a named piece of real work. Idempotent per id; * the state lists every live reason. No-op when power.inhibitWhileWorking * is off or the platform has no inhibitor support. */ holdWork(id: string, reason: string): void; /** Release one named work hold; the inhibitor drops when the last drains. */ releaseWork(id: string): void; /** * The owner toggle: daemon-held keep-awake, independent of work state. * Persisted (power.keepAwake) so it survives restarts and surface closes. */ setKeepAwake(enabled: boolean, options?: { persist?: boolean; }): Promise; /** The state the contract serves; surfaces render the always-visible chip from it. */ getState(): PowerState; private enqueue; private reconcileWork; /** The hard cap: a wedged hold cannot pin the host awake forever. */ private armWorkCap; private handleSleepEdge; private emitState; } //# sourceMappingURL=manager.d.ts.map