import { type McpConfigTarget } from "./utils/mcp-configs.js";
/**
 * Patterns for identifying orphaned MCP-related processes to clean up on startup.
 *
 * IMPORTANT: This list must NOT include ".d3k/chrome-profiles" or any pattern
 * that would match Chrome instances from OTHER running d3k instances.
 * Each d3k instance handles its own profile cleanup via killExistingChromeWithProfile().
 *
 * @see cleanupOrphanedPlaywrightProcesses
 */
export declare const ORPHANED_PROCESS_CLEANUP_PATTERNS: readonly ["ms-playwright/mcp-chrome", "mcp-server-playwright"];
/**
 * Options for graceful process termination.
 */
export interface GracefulKillOptions {
    /** Process ID to terminate */
    pid: number;
    /** Delay in ms to wait for graceful shutdown (default: 500) */
    gracePeriodMs?: number;
    /** Function to send signals (for testing) */
    killFn?: (pid: number, signal: NodeJS.Signals | number) => void;
    /** Function to delay (for testing) */
    delayFn?: (ms: number) => Promise<void>;
    /** Optional debug logger */
    debugLog?: (msg: string) => void;
}
/**
 * Result of graceful kill operation.
 */
export interface GracefulKillResult {
    /** Whether the process was terminated */
    terminated: boolean;
    /** Whether graceful shutdown succeeded (SIGTERM was enough) */
    graceful: boolean;
    /** Whether force kill (SIGKILL) was needed */
    forcedKill: boolean;
}
/**
 * Gracefully terminate a process by first trying SIGTERM, waiting for graceful
 * shutdown, then falling back to SIGKILL if needed.
 *
 * This is important for processes like Next.js dev server that need to clean up
 * resources (like .next/dev/lock) before exiting.
 *
 * @param options - Kill options including PID and optional overrides for testing
 * @returns Result indicating how the process was terminated
 */
export declare function gracefulKillProcess(options: GracefulKillOptions): Promise<GracefulKillResult>;
interface DevEnvironmentOptions {
    port: string;
    mcpPort?: string;
    portMcp?: string;
    serverCommand: string;
    profileDir: string;
    logFile: string;
    debug?: boolean;
    serversOnly?: boolean;
    commandName: string;
    browser?: string;
    defaultPort?: string;
    framework?: "nextjs" | "svelte" | "other";
    userSetPort?: boolean;
    userSetMcpPort?: boolean;
    tail?: boolean;
    tui?: boolean;
    dateTimeFormat?: "local" | "utc";
    pluginReactScan?: boolean;
    chromeDevtoolsMcp?: boolean;
    disabledMcpConfigs?: McpConfigTarget[];
    debugPort?: number;
    headless?: boolean;
    withAgent?: string;
}
/**
 * Count active d3k instances by checking PID files in tmpdir.
 * Returns the count of running d3k processes (excluding the current one if specified).
 *
 * CRITICAL FOR PROCESS CLEANUP:
 * This function determines whether MCP server should be killed on shutdown.
 * Only the LAST d3k instance should kill the MCP server.
 *
 * @see handleShutdown - Uses this to decide MCP cleanup
 * @see SIGHUP handler - Uses this for synchronous MCP cleanup on tmux close
 */
export declare function countActiveD3kInstances(excludeCurrentPid?: boolean): number;
/**
 * Check if a server is actually listening and responding on a port.
 * Used for waiting for a dev server to start up.
 * Works in all environments including sandboxes by using HTTP requests.
 */
export interface ServerListeningResult {
    listening: boolean;
    https: boolean;
}
export declare function isServerListening(port: string | number): Promise<ServerListeningResult>;
export declare function tryHttpConnection(port: string | number): Promise<boolean>;
export declare function tryHttpsConnection(port: string | number): Promise<boolean>;
export declare function findAvailablePort(startPort: number): Promise<string>;
export declare function createPersistentLogFile(): string;
/**
 * Write session info for MCP server to discover.
 *
 * CRITICAL FOR PROCESS CLEANUP:
 * This writes the session.json file that contains chromePids and serverPid.
 * These PIDs are read during shutdown to kill the correct processes.
 *
 * The chromePids array is particularly important - it tracks which Chrome
 * processes belong to THIS d3k instance so we don't accidentally kill
 * Chrome instances from other d3k sessions.
 */
export declare function writeSessionInfo(projectName: string, logFilePath: string, appPort: string, mcpPort?: string, cdpUrl?: string | null, chromePids?: number[], serverCommand?: string, framework?: "nextjs" | "svelte" | "other", serverPid?: number): void;
/**
 * Get Chrome PIDs for a d3k session from the session.json file.
 *
 * CRITICAL FOR PROCESS CLEANUP:
 * Chrome PIDs are stored in session.json and used during shutdown to kill
 * the specific Chrome instances spawned by THIS d3k instance.
 *
 * The SIGHUP handler uses this to synchronously kill Chrome on tmux close
 * before the process terminates.
 *
 * @param projectName - The project name (used to locate session.json)
 * @returns Array of Chrome PIDs, or empty array if none found
 */
export declare function getSessionChromePids(projectName: string): number[];
export declare class DevEnvironment {
    private serverProcess;
    private mcpServerProcess;
    private cdpMonitor;
    private screencastManager;
    private logger;
    private outputProcessor;
    private options;
    private screenshotDir;
    private mcpPublicDir;
    private pidFile;
    private lockFile;
    private spinner;
    private version;
    private isShuttingDown;
    private serverStartTime;
    private healthCheckTimer;
    private tui;
    private portChangeMessage;
    private chromeDevtoolsSupported;
    private portDetected;
    private serverUsesHttps;
    private disabledMcpConfigSet;
    /** Returns "https" or "http" based on detected server protocol */
    private get serverProtocol();
    constructor(options: DevEnvironmentOptions);
    private checkPortsAvailable;
    private killMcpServer;
    private checkProcessHealth;
    private startHealthCheck;
    private stopHealthCheck;
    private configureMcpConfigs;
    start(): Promise<void>;
    private startServer;
    private acquireLock;
    private releaseLock;
    private detectPortChange;
    private debugLog;
    private showRecentLogs;
    private checkForCommonIssues;
    private startMcpServer;
    private waitForServer;
    private detectPackageManagerInDir;
    private installMcpServerDeps;
    private waitForMcpServer;
    private initializeD3KLog;
    private logD3K;
    private startCDPMonitoringSync;
    private startCDPMonitoring;
    private gracefulShutdown;
    private setupCleanupHandlers;
    private handleShutdown;
}
export declare function startDevEnvironment(options: DevEnvironmentOptions): Promise<void>;
export {};
//# sourceMappingURL=dev-environment.d.ts.map