/** * Create each directory, or say plainly which one could not be created and * why. Returns null when all exist. Exported for tests. */ export declare function prepareInstallDirs(dirs: string[]): string | null; /** * Read PID from file. Returns null if file doesn't exist or is invalid. */ export declare function readPid(): number | null; /** * Write current process PID to file. */ export declare function writePid(): void; /** * Remove PID file. */ export declare function removePid(): void; /** * Check if another daemon is already running. * Returns the PID if running, null if not. */ export declare function checkRunning(): number | null; export declare function getLogPath(): string; /** * Rotate a log file if it exceeds maxSizeBytes. * Rotation: file → file.1 → file.2 → ... → file.{maxFiles} (deleted) * Returns true if rotation occurred. */ export declare function rotateLog(filePath: string, maxSizeBytes?: number, maxFiles?: number): boolean; /** * Record the bound port and pid in daemon.meta so clients (HQ, CLI, scripts) * can discover the daemon without hardcoding a port. Called after the HTTP * server has actually bound, and ONLY by the daemon — see daemonMeta.ts for why * a plain `--http` run advertising here broke every hook on the machine. * * Refuses to take discovery from a live process that is not us. Two daemons * cannot both be "the" daemon, and the loser of that race used to be whichever * one started first, silently. Returns false when it declined. */ export declare function setDaemonPort(port: number): boolean; /** * Withdraw our advertisement on the way out, so a clean shutdown does not leave * clients dialling a port we are no longer serving. Only clears an entry that * is ours — a successor that already took over must not be erased. */ export declare function clearDaemonPort(): void; /** * Check for crash loop. Returns true if safe to start, false if should exit. * Exits process with code 0 if crash loop detected (tells launchd to stop). */ export declare function checkCrashLoop(): boolean; /** * Reset crash count after healthy running period. * Call once after successful startup. */ export declare function scheduleHealthReset(): void; /** * Clear crash counter (for --reset-crashes CLI flag). */ export declare function resetCrashes(): void; /** * Install signal handlers for graceful shutdown. * Returns a promise that resolves when shutdown is requested. */ export declare function installShutdownHandlers(cleanup: () => Promise): void; /** * Ask launchd whether the agent is actually loaded. * * This is the only trustworthy signal. `launchctl load` exits 0 even when it * fails, which is what let install report success for months (ISS-0127). */ export declare function isLaunchdLoaded(): boolean; /** * Fill in the launchd plist template. Split out from `installLaunchd` so the * substitution can be tested without touching launchctl or ~/Library. */ export declare function renderPlist(options?: { port?: number; }): { plist: string; serverPath: string; port: number; }; /** * Install the launchd plist so the daemon auto-starts on login. */ export declare function installLaunchd(options?: { port?: number; }): { installed: boolean; path: string; message: string; }; /** * Uninstall the launchd plist and stop the daemon. */ export declare function uninstallLaunchd(): { uninstalled: boolean; message: string; }; /** * Get daemon status. */ export declare function daemonStatus(): { running: boolean; pid: number | null; pidFile: string; logFile: string; launchd: boolean; launchdPlist: boolean; port: number | null; }; export interface DaemonAgent { id: string; capabilities: string[]; connectedAt: string; lastHeartbeat: string; status: 'active' | 'busy' | 'idle'; currentTask?: string; allowedFacades?: string[]; tier?: 'core' | 'pro' | 'apps'; } export declare class AgentRegistry { private agents; register(init: { id: string; capabilities?: string[]; allowedFacades?: string[]; tier?: 'core' | 'pro' | 'apps'; }): DaemonAgent; heartbeat(agentId: string, update?: { status?: 'active' | 'busy' | 'idle'; currentTask?: string; }): DaemonAgent | null; disconnect(agentId: string): boolean; get(agentId: string): DaemonAgent | undefined; list(): DaemonAgent[]; sweepStale(staleMs?: number): string[]; get count(): number; toJSON(): object[]; } /** * Handle daemon subcommands: install, uninstall, status. * Returns true if a subcommand was handled (and process should exit). */ export declare function handleDaemonSubcommand(args: string[]): boolean; //# sourceMappingURL=daemon.d.ts.map