/**
 * Deployment Service
 *
 * Infrastructure service that manages local dev server deployments.
 * Holds an in-memory Map of active deployments keyed by targetId AND
 * persists deployment records to the `dev_servers` SQLite table so that
 * running dev servers survive page reloads and server restarts.
 *
 * On startup, call `recoverAll()` to reconcile the DB with actual
 * process state (clean up dead PIDs, re-adopt live ones).
 */
import { spawn } from 'node:child_process';
import type Database from 'better-sqlite3';
import type { IDeploymentService, DeploymentStatus, DeploymentStatusEntry, LogEntry } from '../../../application/ports/output/services/deployment-service.interface.js';
import { detectDevScript } from './detect-dev-script.js';
export interface DeploymentServiceDeps {
    spawn: typeof spawn;
    detectDevScript: typeof detectDevScript;
    kill: (pid: number, signal: NodeJS.Signals | string) => void;
    isAlive: (pid: number) => boolean;
}
export declare class DeploymentService implements IDeploymentService {
    private readonly deployments;
    private readonly deps;
    private readonly emitter;
    private db;
    constructor(deps?: Partial<DeploymentServiceDeps>);
    /**
     * Inject the database connection. Called from DI container after DB is ready.
     */
    setDatabase(db: Database.Database): void;
    /**
     * Recover dev servers from the database on startup.
     *
     * Three recovery strategies based on process state:
     * 1. Alive + Ready (has URL) → re-adopt, then validate URL asynchronously
     * 2. Alive + Booting (no URL) → kill orphan and re-spawn (can't re-attach stdout)
     * 3. Dead → re-spawn if target directory still exists
     *
     * After sync recovery, fires off async URL health checks for re-adopted
     * processes. Zombies (alive but not serving) are killed and re-spawned.
     *
     * All re-spawns are wrapped in try/catch so one failure doesn't block others.
     */
    recoverAll(): void;
    /**
     * Start a deployment for the given target.
     * If a deployment already exists for this target, it is stopped first.
     */
    start(targetId: string, targetPath: string, targetType?: string): void;
    /**
     * Get the current deployment status for a target.
     * Checks in-memory Map first, then falls back to DB for recovered deployments.
     * Validates PID liveness — cleans up if dead.
     */
    getStatus(targetId: string): DeploymentStatus | null;
    /**
     * List all tracked deployments with live processes.
     *
     * Merges in-memory entries with any DB rows not yet re-adopted. Any
     * dead processes encountered are cleaned up (both in-memory and DB).
     */
    listAll(): DeploymentStatusEntry[];
    /**
     * Stop a deployment gracefully: SIGTERM → poll → SIGKILL.
     */
    stop(targetId: string): Promise<void>;
    /**
     * Force-stop all tracked deployments immediately (for daemon shutdown).
     */
    stopAll(): void;
    /**
     * Get the accumulated log buffer for a deployment.
     */
    getLogs(targetId: string): LogEntry[] | null;
    /**
     * Subscribe to real-time log events.
     */
    on(event: 'log', handler: (entry: LogEntry) => void): void;
    /**
     * Unsubscribe from real-time log events.
     */
    off(event: 'log', handler: (entry: LogEntry) => void): void;
    private dbUpsert;
    private dbUpdateState;
    private dbDelete;
    private dbFind;
    private dbFindAll;
    private killProcess;
    /**
     * Attach a line-buffered listener on stdout or stderr that calls parsePort
     * and accumulates log entries.
     */
    private attachOutputListener;
    private pollUntilDead;
    private waitForExit;
    /**
     * Async health check for a recovered entry. Probes the URL port via TCP.
     * If the port is not responding (zombie process), kills and re-spawns.
     * Fire-and-forget — errors are logged, never thrown.
     */
    private validateAndRespawn;
    /**
     * TCP connect probe to check if a URL's port is accepting connections.
     * Returns true if the port responds within 2 seconds, false otherwise.
     */
    private probePort;
}
//# sourceMappingURL=deployment.service.d.ts.map