import { t as Diag } from "./diagnostics-D5jwc-q1.mjs"; import { u as TuiDaemonClientStartup } from "./startup-CarQxWwi.mjs"; import { spawn } from "node:child_process"; import { Context } from "@deepseek-ai/cordis"; //#region src/app/remote-process/daemon-launcher.d.ts /** Stable Loader row id / Cordis plugin name. */ declare const name = "pi-tui-daemon-launcher"; /** The daemon Coordinator only exists when the daemon backend published its service. */ declare const inject: string[]; /** The launcher-provided Profile facts the Coordinator needs (official shape). */ interface ProfileContextLike { readonly name: string; readonly dir: string; readonly home: string; readonly installAnchor: string; readonly cwd: string; } /** The one-shot public launch envelope encoded for the Client child. */ declare function encodeLaunchEnvelope(startup: TuiDaemonClientStartup): string; /** * Resolve the installed Client entry from THIS package root and prove its real * target is a regular file. A shared npm package, a root-owned system install * and a legal entry symlink are normal installs; only a missing or non-regular * target is a hard failure — never a fallback to a source tree or `tsx`. */ declare function resolveClientEntry(packageRoot: string): string; /** * Resolve this installed bundle's package root through the OFFICIAL profile * resolution. The launcher module itself may be reached through a symlinked * `dist`, so its own module URL is not a reliable package-root locator. * Exported for the M6 UX PR2 Direct-side admin port, which must reuse the SAME * official Profile resolution as this CLI path — never a second copy. */ declare function resolveProfilePackageRoot(profileDir: string): string; /** * Build the child environment at the ONE new-spawn boundary. Every inherited * `SPLIT_PROCESS_*` test/qualification injection is stripped first, then the * four required internal facts are set explicitly. The supervisor's own role / * Host-entry markers and the one-shot public selector are never propagated. */ declare function buildChildEnvironment(profileContext: ProfileContextLike, launchEnvelope: string, source?: NodeJS.ProcessEnv): NodeJS.ProcessEnv; /** Injectable spawn for a structural (L2/L3) test; production uses `child_process.spawn`. */ type SpawnImpl = typeof spawn; /** * The ONE child lifecycle. Idempotent start/dispose; a single settle drives the * launcher `appExit` exactly once. `dispose()` is the SINGLE stop owner: it is * driven by the row's fiber disposal (the official `runProfile` SIGTERM → shutdown * → fiber disposal path) and asks the live child to stop once. The Coordinator * installs NO second SIGTERM/SIGINT handler — a terminal SIGINT already reaches * the foreground child through the shared TTY group, and the parent's own SIGTERM * is the official shutdown's, so there is exactly one stop request. */ declare class DaemonCoordinator { private readonly spawnImpl; private readonly entry; private readonly env; private readonly appExit; private readonly diag; /** A sanitized human line for the supervisor TTY when the Client cannot be * spawned at all (never a JSON record, never a raw error/message/path). */ private readonly reportFatal; private readonly shutdownBudgetMs; private child; private childExit; private started; private disposed; private settled; private disposePromise; /** Test observation: how many children were actually spawned. */ spawnCount: number; constructor(options: { spawnImpl: SpawnImpl; entry: string; env: NodeJS.ProcessEnv; appExit: (code: number) => void; diag: Diag; reportFatal?: (line: string) => void; shutdownBudgetMs?: number; }); /** Spawn the ONE foreground Client. No-op after a prior start or dispose. */ start(): void; private settle; /** * The SINGLE stop owner, AWAITABLE. A spawn not yet started is cancelled; a * live child is asked to stop once (SIGTERM) and dispose() resolves only after * the child actually exited, so the parent Fiber disposer holds the child's * cleanup rather than the parent process exiting underneath it. The wait is * bounded to fit the official ~5s shutdown deadline; a child that does not exit * within it is escalated to SIGKILL and awaited briefly. Idempotent. */ dispose(): Promise; } /** The result of one management operation, as written to the real TTY. */ interface DaemonManagementResult { readonly code: number; readonly stdout: string; readonly stderr: string; } /** One management executor: the production one dynamically imports the control * module; a structural test supplies its own. */ type DaemonManagementExecutor = () => Promise; /** * The ONE management operation lifecycle. It runs at most once, writes its * output and requests `appExit` exactly once, and a fiber disposal before the * result settles suppresses both the output and the exit so a late result can * never surface after the supervisor has gone away. The operation itself is * bounded so a shutdown never waits indefinitely on a management action. */ declare class DaemonControlRunner { private readonly run; private readonly appExit; private readonly writeStdout; private readonly writeStderr; private readonly reportFatal; private readonly shutdownBudgetMs; /** The fixed result for an unexpected local throw; the daemon manager text * stays the default so its behavior is unchanged. */ private readonly fallback; private started; private disposed; private settled; private operation; /** Test observation: how many management operations actually started. */ runCount: number; constructor(options: { run: DaemonManagementExecutor; appExit: (code: number) => void; writeStdout?: (text: string) => void; writeStderr?: (text: string) => void; reportFatal?: (line: string) => void; shutdownBudgetMs?: number; fallback?: DaemonManagementResult; }); /** Start exactly one management operation. A no-op after a prior start/dispose. */ start(): void; /** Stop accepting a late result and bound the wait for an in-flight one. */ dispose(): Promise; } /** * Write a qualification dump to a SAFE, PRIVATE target: absolute path, a real * parent directory owned by this process user, NEVER overwriting an existing * file and never following a symlink; created 0600. Throws on any unsafe target * (mirrors the qualification record-sink contract in local-client-entry). */ declare function writeQualificationDump(target: string, text: string): void; /** A cancelable, Fiber-lifecycle-owned one-shot qualification dump scheduler. */ interface LoaderDumpScheduler { schedule(delayMs: number): void; flush(): void; dispose(): void; } declare function createLoaderDumpScheduler(produce: () => string, write: (text: string) => void): LoaderDumpScheduler; /** The production Coordinator row. A `client` launch spawns the ONE foreground * Client; a `control` launch runs ONE management operation. Both settle on the * real cold-ready commit and are owned by this row's Fiber. */ declare function apply(ctx: Context): void; //#endregion export { DaemonControlRunner, DaemonCoordinator, DaemonManagementExecutor, DaemonManagementResult, LoaderDumpScheduler, SpawnImpl, apply, buildChildEnvironment, createLoaderDumpScheduler, encodeLaunchEnvelope, inject, name, resolveClientEntry, resolveProfilePackageRoot, writeQualificationDump };