/** * Invocation mode dispatch for spawn-runner. * * Pure function `buildInvocationCommand` transforms a SpawnArgs + agent name * into a concrete host command based on the invocation mode (local, docker, * ssh, k8s). Split out of spawn-runner.ts for file-size hygiene — no * behavior change. */ import type { SpawnArgs } from './adapter.js'; import type { InvocationMode } from './invocation.js'; /** Result of applying an invocation mode to a SpawnArgs. */ export interface InvocationCommand { /** The process to spawn on the host machine. */ command: string; /** Arguments passed to the host process. */ args: string[]; /** Environment variables for the host process (union of host-inherited + inline). */ env: Record; /** Working directory for the host process. */ cwd: string; /** Initial stdin (forwarded verbatim). */ stdin?: string; /** Whether the host process requires shell mode. */ shell: boolean; } /** * Transform a SpawnArgs + agent name into an InvocationCommand based on the * invocation mode. This is a pure function — no subprocess is started. * * Modes: * - local — returns spawnArgs unchanged (env merged). * - docker — `docker run --rm -i [-v cwd:/workspace] [-w /workspace] [-e K=V]* `. * - ssh — `ssh [-p N] [-i key] [user@]host -- cd && `. * - k8s — `kubectl [--context C] [-n NS] exec -i -- `. */ export declare function buildInvocationCommand(mode: InvocationMode | undefined, spawnArgs: SpawnArgs, agent: string): InvocationCommandWithCleanup; /** * Describe the k8s cleanup action the caller should perform on abort/exit. * For ephemeral `kubectl run --rm` invocations we still emit a best-effort * `kubectl delete pod --grace-period=0` so abandoned pods don't linger when * the local ssh/kubectl client is killed before `--rm` fires. */ export interface K8sCleanup { readonly command: 'kubectl'; readonly args: readonly string[]; } /** Cleanup attached to an InvocationCommand built in k8s-ephemeral mode. */ export interface InvocationCommandWithCleanup extends InvocationCommand { readonly cleanup?: K8sCleanup; } /** Fire-and-forget a cleanup command (detached, stdio ignored, unref'd). */ export declare function runCleanupDetached(cleanup: K8sCleanup): void;