/** * Public SDK daemon control API — @cleocode/core. * * Exposes programmatic equivalents of every `cleo daemon ` CLI * command so SDK-only consumers (no CLI) can manage the daemon lifecycle * without spawning child processes. * * All functions are thin wrappers over the low-level primitives in * `./daemon.ts` (sentient daemon) and `../gc/daemon.ts` (GC daemon). * The install/uninstall path delegates to `install-daemon-service.mjs` in * the `@cleocode/cleo` package (resolved dynamically to avoid circular deps). * * Usage: * ```ts * import { installDaemon, getDaemonStatus, startDaemon } from '@cleocode/core'; * * await installDaemon({ scope: 'user', superviseStudio: true }); * const status = await getDaemonStatus(projectRoot); * await startDaemon(projectRoot); * ``` * * @public * @task T1683 */ import { type BootstrapDaemonOptions, type SentientStatus } from './daemon.js'; /** * Options for {@link installDaemon}. * * @public */ export interface InstallDaemonOptions { /** * Service scope. Currently only `'user'` is supported (user-level systemd unit * or launchd plist). System-level service registration is not yet implemented. * @default 'user' */ scope?: 'user' | 'system'; /** * Whether the daemon should supervise the Cleo Studio web server. * Stored in `~/.cleo/config.json` as `daemon.superviseStudio`. * @default true */ superviseStudio?: boolean; } /** * Result of {@link installDaemon} / {@link uninstallDaemon} / {@link updateDaemon}. * * @public */ export interface DaemonInstallResult { /** Whether the operation succeeded. */ success: boolean; /** Platform on which the operation ran. */ platform: string; /** Path to the installed/removed service file, or null. */ filePath: string | null; /** Human-readable outcome message. */ message: string; } /** * Status snapshot returned by {@link getDaemonStatus}. * * Combines GC daemon status and sentient daemon status into a unified view. * * @public */ export interface DaemonStatus { /** Whether the sentient daemon process is alive. */ running: boolean; /** PID of the sentient daemon, or null if stopped. */ pid: number | null; /** ISO-8601 timestamp of daemon start, or null. */ uptime: string | null; /** ISO-8601 timestamp of the last sentient tick, or null. */ lastHygieneRun: string | null; /** ISO-8601 timestamp of the last cross-project hygiene run, or null. */ lastDreamCycle: string | null; /** Whether the daemon supervises the Studio web server. */ supervisesStudio: boolean; /** Current status of the Studio child process. */ studioStatus: SentientStatus['studioStatus']; /** Full sentient status snapshot for detailed inspection. */ sentient: SentientStatus; } /** * Install the CLEO daemon as a user-level system service. * * Writes a systemd user unit (Linux / WSL) or launchd plist (macOS) and * activates it so the daemon auto-starts on login. * * Idempotent: re-running does not restart a running service unless the * generated unit content changed. * * Programmatic equivalent of `cleo daemon install`. * * @param opts - Optional install options (scope, Studio supervision flag). * @returns DaemonInstallResult with success/failure details. * * @example * ```ts * import { installDaemon } from '@cleocode/core'; * * const result = await installDaemon({ scope: 'user', superviseStudio: true }); * if (result.success) console.log('Daemon installed:', result.filePath); * ``` * * @public */ export declare function installDaemon(opts?: InstallDaemonOptions): Promise; /** * Uninstall the CLEO daemon system service. * * Disables the unit/plist and removes the service file from disk. * Idempotent: safe to run even when the service is not installed. * * Programmatic equivalent of `cleo daemon uninstall`. * * @returns DaemonInstallResult with removed file path (when applicable). * * @public */ export declare function uninstallDaemon(): Promise; /** * Update the CLEO daemon system service (idempotent re-install). * * Re-runs install: regenerates the unit/plist with current binary paths and * configuration, writing only when the content changed. Safe to call on every * `npm install -g @cleocode/cleo` upgrade. * * Programmatic equivalent of running `cleo daemon install` on an already-installed * service. * * @param opts - Optional options (same as {@link installDaemon}). * @returns DaemonInstallResult. * * @public */ export declare function updateDaemon(opts?: InstallDaemonOptions): Promise; /** * Start the CLEO sentient daemon as a detached background process. * * Programmatic equivalent of `cleo daemon start`. * * @param projectRoot - Absolute path to the project root (contains `.cleo/`) * @param opts - Optional bootstrap options (Studio supervision, etc.) * @returns PID of the spawned daemon process. * * @example * ```ts * import { startDaemon } from '@cleocode/core'; * * const { pid } = await startDaemon('/my/project'); * console.log(`Daemon started (PID ${pid})`); * ``` * * @public */ export declare function startDaemon(projectRoot: string, opts?: Pick): Promise<{ pid: number; statePath: string; logPath: string; }>; /** * Stop the CLEO sentient daemon. * * Flips the kill-switch and delivers SIGTERM to the daemon process. * The daemon cascades SIGTERM to the Studio child (T1683 §graceful-shutdown). * * Programmatic equivalent of `cleo daemon stop`. * * @param projectRoot - Absolute path to the project root * @param reason - Optional diagnostic reason stored in sentient-state.json * @returns Stop result with pid and outcome message. * * @public */ export declare function stopDaemon(projectRoot: string, reason?: string): Promise<{ stopped: boolean; pid: number | null; reason: string; }>; /** * Get the current status of the CLEO daemon. * * Returns a unified snapshot combining sentient + GC daemon state. * * Programmatic equivalent of `cleo daemon status`. * * @param projectRoot - Absolute path to the project root * @returns DaemonStatus snapshot. * * @example * ```ts * import { getDaemonStatus } from '@cleocode/core'; * * const status = await getDaemonStatus('/my/project'); * if (status.running) { * console.log(`Daemon is running (PID ${status.pid})`); * console.log(`Studio: ${status.studioStatus}`); * } * ``` * * @public */ export declare function getDaemonStatus(projectRoot: string): Promise; //# sourceMappingURL=daemon-api.d.ts.map