/** * Daemon Service Types - Type definitions for cross-platform service management */ import type { Writable } from 'node:stream'; export type GatewayServiceEnv = Record; export interface GatewayServiceInstallArgs { env: GatewayServiceEnv; stdout?: Writable; stderr?: Writable; programArguments: string[]; workingDirectory?: string; environment?: Record; description?: string; } export interface GatewayServiceControlArgs { env: GatewayServiceEnv; stdout?: Writable; stderr?: Writable; disable?: boolean; } export interface GatewayServiceEnvArgs { env?: GatewayServiceEnv; } export type GatewayServiceStatus = 'running' | 'stopped' | 'unknown'; export interface GatewayServiceRuntime { status: GatewayServiceStatus; pid?: number; lastExitStatus?: number; } export interface GatewayServiceCommandConfig { programArguments: string[]; workingDirectory?: string; environment?: Record; sourcePath?: string; } export interface GatewayServiceState { installed: boolean; loaded: boolean; running: boolean; env: GatewayServiceEnv; command: GatewayServiceCommandConfig | null; runtime?: GatewayServiceRuntime; } export type GatewayServiceRestartTask = 'restarted' | 'scheduled'; export interface GatewayServiceRestartResult { task: GatewayServiceRestartTask; } export type StartRepairIssueCode = 'version-mismatch' | 'temporary-program' | 'missing-program'; export interface GatewayServiceStartRepairIssue { code: StartRepairIssueCode; message: string; } export type GatewayServiceStartTask = 'started' | 'scheduled' | 'missing-install' | 'repair-required'; export interface GatewayServiceStartResult { task: GatewayServiceStartTask; state: GatewayServiceState; issues?: GatewayServiceStartRepairIssue[]; } export type DaemonAction = 'install' | 'uninstall' | 'start' | 'stop' | 'restart'; export interface DaemonActionResponse { ok: boolean; action: DaemonAction; result?: string; message?: string; error?: string; hints?: string[]; warnings?: string[]; service?: { label: string; loaded: boolean; loadedText: string; notLoadedText: string; }; } export interface DaemonLifecycleOptions { json?: boolean; wait?: string; disable?: boolean; } export interface DaemonInstallOptions { port?: string | number; runtime?: string; token?: string; force?: boolean; json?: boolean; } export interface GatewayService { /** Unique label for the service */ label: string; /** Text when service is loaded */ loadedText: string; /** Text when service is not loaded */ notLoadedText: string; /** Install service */ install: (args: GatewayServiceInstallArgs) => Promise; /** Uninstall service */ uninstall: (args: GatewayServiceControlArgs) => Promise; /** Stop service */ stop: (args: GatewayServiceControlArgs) => Promise; /** Restart service (returns task for restart health checks) */ restart: (args: GatewayServiceControlArgs) => Promise; /** Check if service is loaded/installed */ isLoaded: (args: GatewayServiceEnvArgs) => Promise; /** Read service runtime status */ readRuntime: (env?: GatewayServiceEnv) => Promise; /** Read command configuration */ readCommand: (env?: GatewayServiceEnv) => Promise; } export interface DaemonInstallResult { success: boolean; serviceName?: string; error?: string; } export interface DaemonActionResult { success: boolean; detail?: string; }