import type { DockerRunnerOptions, Runner } from "../../process-runner/dist/index.js"; export interface LauncherFileSystem { readFile(path: string, encoding: BufferEncoding): Promise; readFileBytes?(path: string, start: number): Promise; writeFile(path: string, content: string, options?: { encoding?: BufferEncoding; flag?: string; mode?: number; }): Promise; mkdir(path: string, options?: { recursive?: boolean; }): Promise; rm(path: string, options?: { force?: boolean; recursive?: boolean; }): Promise; rename(sourcePath: string, destinationPath: string): Promise; stat(path: string): Promise<{ isFile(): boolean; mtimeMs: number; size?: number; dev?: number; ino?: number; }>; lstat(path: string): Promise<{ isSymbolicLink(): boolean; }>; readdir(path: string): Promise; appendFile(path: string, content: string): Promise; } export type ReadyCheck = { kind: "log-pattern"; pattern: string; } | { kind: "tcp"; port: number; host?: string; timeoutMs?: number; }; export type RestartPolicy = "never" | "on-failure" | "always"; export interface ProcessSpec { id: string; command: string; args?: string[]; cwd?: string; env?: Record; restart: RestartPolicy; maxRestarts?: number; backoffMs?: number; maxBackoffMs?: number; readyCheck?: ReadyCheck; logRetainCount?: number; docker?: DockerRunnerOptions; } export type ProcessStatus = "running" | "stopped" | "crashed" | "restarting"; export interface ProcessState { id: string; pid: number | null; status: ProcessStatus; runtime: "host" | "docker"; restartCount: number; lastExitCode: number | null; lastStartedAt: string | null; lastStoppedAt: string | null; command: string; args: string[]; } export interface SupervisorOptions { spec: ProcessSpec; stateDir: string; runner?: Runner; fs?: LauncherFileSystem; signal?: AbortSignal; startSettleMs?: number; onStatusChange?: (state: ProcessState) => void; onLog?: (line: string, stream: "stdout" | "stderr") => void; onError?: (error: unknown) => void; } export interface Supervisor { start(): Promise; stop(): Promise; restart(): Promise; getState(): ProcessState; } export interface StateStore { read(id: string): Promise; write(id: string, state: ProcessState): Promise; list(): Promise; remove(id: string): Promise; } export interface LogWriter { write(line: string, stream: "stdout" | "stderr"): Promise; rotate(): Promise; tail(stream: "stdout" | "stderr", lines?: number): Promise; close(): void; }