/** * Host side of the resident in-distro agent. * * One {@link WslAgent} instance owns one long-lived `wsl.exe` process per * distro. The lifetime rules, in order of importance: * * 1. **Correctness before speed.** Any agent failure is answered by at most * one rebuild; the requests that were in flight ride it ONLY when their * first execution provably changed nothing (the read-only FS ops). A * command or a write that was in flight has UNKNOWN state — replaying it * would run non-idempotent work twice or report a create that actually * succeeded as a refusal — so it fails instead, and the caller re-reads * before retrying. A failure that spends the rebuild leaves the agent * `dead` with a bounded revival: the next call after a 2/4/8-second backoff * gets a fresh transport and its own single rebuild; after three deaths the * state is permanent and every call rejects with a restart remedy. While * dead, calls reject with {@link AgentUnavailableError} — the executor's cue * to fall back to the one-shot `wsl.exe` path it shipped with, so the worst * case of the agent is "today's behaviour, plus one failed round trip". * 2. **The in-distro timeout is the real one.** The EXEC frame carries the * timeout in whole seconds and the agent SIGTERMs the child itself, so a * timed-out command dies where it lives instead of leaving an orphan * behind a dead `wsl.exe`. The host-side watchdog is armed on the agent's * `ACK` — the dequeue signal — so it measures EXECUTION, never the queue * wait: a short-budget request queued behind a long one can no longer * kill the shared transport for a stall that was never its own. A second, * much looser ceiling starts when the frame is WRITTEN: a resident that * stays alive but never dequeues the request (a wedged `wait`, a blocked * pipe) otherwise stranded it, and the serial queue behind it, forever. It * still catches an agent that accepted a request and then stopped answering * at all. * 3. **Idle agents go away.** `idleMs` after the last exchange the process is * killed; the next call starts a fresh one. WSL VMs are shared, but every * process is a promise someone has to keep. * * The transport is injectable so the lifecycle and the fallback decision are * unit-testable without a distro. * * This is a TypeScript source built to `lib/agent.js`; edit THIS file and run * `pnpm run build` — the artifact under `lib/` is generated, and `pnpm test` * fails when it drifts. * * @module dsh-plugin-wsl-env/agent */ import type { ChildProcess } from "node:child_process"; /** One settled command result, as `exec` resolves it. */ interface ExecResult { /** The command's exit status. */ exitCode: number; /** Captured stdout. */ stdout: Buffer; /** Captured stderr. */ stderr: Buffer; /** Which streams the capture cap cut. */ truncated: { stdout: boolean; stderr: boolean; }; /** * Protocol 7's FS refusal token (`notfound`, `stale`, …), present only on a * failed FS op answered with the structured FSERR line. FS consumers map it * onto `FsErrorCode` directly; command results never carry one. */ reason?: string; } /** * One request in flight on an agent: its frame, its settlement callbacks, and * the ACK-armed watchdog. */ interface PendingRequest { /** The request id, as the agent echoes it. */ id: string; /** The request's numeric sequence; newer requests have a larger one. */ seq: number; /** Which metric bucket this request belongs to. */ kind: "fs" | "exec"; /** When the request was submitted, for the queue measurement. */ sentAt: number; /** When the agent ACKed it, for the execution measurement. */ ackedAt?: number; /** Whether the metrics recorded this request's settle. */ measured: boolean; /** The frame lines (kept so a rebuild can re-send). */ lines: string[]; /** Settles a RES. */ resolve: (result: ExecResult) => void; /** Settles a failure. */ reject: (error: Error) => void; /** The ACK-armed watchdog timer. */ watchdog: NodeJS.Timeout | null; /** The caller's cancellation, when any. */ signal: AbortSignal | null; /** The abort listener, for removal. */ onAbort: (() => void) | null; /** Arms `watchdog`; null when the request carries no timeout. */ armWatchdog: (() => void) | null; /** Whether the agent has ACKed this request (it is the running one). */ started: boolean; /** Whether the request frame has been sent to the agent. */ sent: boolean; /** The caller cancelled it; a sent entry stays until the agent answers. */ cancelled: boolean; /** The caller was already settled; a late answer only cleans up. */ settled: boolean; /** Whether the agent has answered (RES or ERR); a late signal is then unsafe. */ answered: boolean; /** The delayed cancel signal, so it can be dropped when the request settles. */ signalTimer: NodeJS.Timeout | null; /** * The frame-written watchdog timer: a resident that never ACKs is wedged, * and the ACK-armed watchdog alone would never start. */ dispatchWatchdog: NodeJS.Timeout | null; } /** Per-kind request metrics. */ interface RequestMetrics { /** Requests that settled (successful, failed or cancelled). */ requests: number; /** Total queue wait (submission -> ACK), ms. */ queueMs: number; /** Largest single queue wait, ms. */ queueMaxMs: number; /** Total execution time (ACK -> settle), ms. */ execMs: number; /** Largest single execution time, ms. */ execMaxMs: number; /** Settled with an error (not cancellation). */ failed: number; /** Cancelled by the caller. */ cancelled: number; /** Rejected before tracking: queue full, already aborted, or send failed. */ rejected: number; } /** A read-only snapshot of the resident's lifecycle, for diagnostics. */ export interface AgentStatus { /** The distro served. */ distro: string; /** Lifecycle state. */ state: "idle" | "starting" | "ready" | "dead"; /** The HELLO pid, when one is known and addressable. */ pid: number | undefined; /** The last failure, if any. */ lastError: string; /** Deaths observed; the revival budget is spent after {@link MAX_REVIVALS}. */ deaths: number; /** Requests currently in flight. */ pending: number; } /** The agent's cumulative request metrics. */ interface AgentMetrics { /** FS frames. */ fs: RequestMetrics; /** EXEC frames (commands, ping). */ exec: RequestMetrics; /** Peak number of pending requests. */ inFlightMax: number; } /** The entry an async preparation may select before the first spawn. */ interface WslAgentPrepared { /** The agent entrypoint (the shell script or the native cache path). */ scriptPath: string; /** The HELLO digest to verify. */ expectedDigest?: string; /** Whether USR1 can reach the agent (false for the native KILL-frame path). */ signalable?: boolean; /** Whether the agent handles only one request at a time. */ serialRequests?: boolean; /** The process factory for this entry. */ spawnTransport?: (options: { wslPath: string; distro: string; scriptPath: string; argvPrefix: string[]; leaseMs: number; }) => ChildProcess; } /** * The Windows environment the transport starts from, pinned. * * Spawned bare, `wsl.exe` would inherit this process's whole environment — and * the `WSLENV` variable riding along decides which of those names are * FORWARDED into the distro, where every model command inherits them. Dev * machines routinely route secrets that way (`WSLENV=GITHUB_TOKEN/u` is the * documented example), so the resident's env is built from scratch instead: * the Windows essentials `wsl.exe` itself needs, the managed `DSH_*` facts, * and a `WSLENV` that names only those managed entries — preserving their * original forwarding flags. Nothing else on the Windows side can reach a * model command. * * Deliberately NOT here: the executor's `forwardEnv` names. They ride the * one-shot path's WSLENV (`spawnSpec` builds it per call); the resident path * has never forwarded them, and this pin keeps that posture instead of * widening it silently. * * @param parent - this process's environment. * @returns the pinned environment for `wsl.exe`. */ export declare function pinnedWindowsEnv(parent: Record): Record; /** * The spawn environment for one resident, with the client lease folded in. * The pinned environment forwards only the managed `DSH_` namespace, and it * forwards exactly the names the parent `WSLENV` lists — so the lease rides * both: the value on the variable, the name on `WSLENV`. A non-positive * lease leaves the environment as the pin built it (the script treats an * unset variable as no lease). * * @param env - the pinned environment. * @param leaseMs - the agent's client lease in ms; 0 disables. * @returns the environment to spawn with. */ export declare function agentLeaseEnv(env: Record, leaseMs: number): Record; /** The resident agent for one distro. */ export declare class WslAgent { /** The distro this agent serves. */ distro: string; /** The agent script as a Linux path inside the distro (see {@link spawnDefault}). */ scriptPath: string; /** The `wsl.exe` path. */ wslPath: string; /** Arguments between `wsl.exe --exec` and the `sh script` pair. */ argvPrefix: string[]; /** Idle shutdown delay; 0 disables. */ idleMs: number; /** The sha256 of the agent script as this package shipped it. */ expectedDigest: string | undefined; /** * Hard ceiling on one stdout protocol line; a longer line is a broken or * hostile agent, not data to hold — readline used to accumulate it all. */ frameCapBytes: number; /** The injectable process factory, when the caller supplied one. */ configuredSpawn: ((options: { wslPath: string; distro: string; scriptPath: string; argvPrefix: string[]; leaseMs: number; }) => ChildProcess) | undefined; /** The explicit lease, when the caller supplied one (independent of idleMs). */ configuredLease: number | undefined; /** The injectable signal sender, when the caller supplied one. */ configuredSignal: ((options: { wslPath: string; distro: string; pid: number; signal: NodeJS.Signals; }) => void) | undefined; /** The agent shell's PID from its HELLO, when a second wsl.exe can address it. */ agentPid: number | undefined; /** * Whether a second `wsl.exe` can deliver `USR1` to the agent's HELLO pid. * True for the plain agent; false for a resident inside a PID namespace. A * session runtime has a prefix (scope + mounts) but no PID namespace, so it * opts in explicitly. */ signalable: boolean; /** Whether requests must wait on the host until the previous answer. */ serialRequests: boolean; /** The maximum requests allowed in flight on this resident. */ maxPending: number; /** How long a written frame may await the agent's ACK. */ dispatchTimeoutMs: number; /** The live resident process, when any. */ process: ChildProcess | null; /** The lifecycle state. */ state: "idle" | "starting" | "ready" | "dead"; /** The protocol version the resident announced in HELLO (0 before one). */ protocolVersion: number; /** The capabilities the resident advertised in HELLO (`conc`, `batch`). */ caps: Set; /** The in-flight start, shared by concurrent callers. */ startPromise: Promise | null; /** The in-flight start's settler, so close() can fail a start it interrupts. */ startSettler: ((error?: unknown) => void) | null; /** The next request id. */ nextRequestId: number; /** The requests in flight, keyed by their current id. */ pending: Map; /** The newest request the agent has ACKed; a cancel older than this is stale. */ lastAckedSeq: number; /** Whether the one permitted rebuild has been spent. */ rebuildUsed: boolean; /** Deaths observed; each one past the first consumes the revival budget. */ deaths: number; /** When the next revival may start, epoch ms; 0 when not waiting. */ deadUntil: number; /** The first revival delay; tests shorten it. */ revivalBackoffMs: number; /** The idle-shutdown timer. */ idleTimer: NodeJS.Timeout | null; /** The last failure, for `unavailableReason` and log messages. */ lastError: string; /** Cumulative request metrics; see {@link metrics}. */ requestMetrics: AgentMetrics; /** The optional async preparation hook. */ prepare: (() => Promise) | undefined; /** * @param config - the agent configuration. */ constructor(config: { /** The distro this agent serves. */ distro: string; /** * The agent script as a Linux path inside the distro (see * {@link spawnDefault}). */ scriptPath: string; /** The `wsl.exe` path. */ wslPath?: string; /** Idle shutdown delay; 0 disables. */ idleMs?: number; /** * The client lease in ms, independent of `idleMs`. A session runtime holds * the agent for the session's lifetime (no idle close) but still wants the * lease's last-resort self-termination; a positive value here overrides the * idle-derived lease. */ leaseMs?: number; /** * The sha256 of the agent script as this package shipped it; a HELLO whose * digest differs is refused the same way a version mismatch is (the script * is read in place, so a stale or half-synced runtime copy is the failure * this catches). */ expectedDigest?: string; /** * Arguments inserted between `wsl.exe --exec` and the `sh script` pair — * the confinement wrapper (`bwrap … --`) a confined agent runs its whole * lifetime under, so every filesystem op it performs is kernel-enforced. * Empty for the plain agent. */ argvPrefix?: string[]; /** * Whether a second `wsl.exe` can signal the agent's pid. Defaults to * "true when the argv prefix is empty": the plain agent shares the distro's * PID namespace, a confined resident does not, and a session runtime has a * prefix but no PID namespace and must opt in. */ signalable?: boolean; /** Whether the agent handles only one request at a time; defaults to shell behavior. */ serialRequests?: boolean; /** Hard ceiling in bytes on one stdout protocol line; defaults to {@link MAX_FRAME_BYTES}. */ frameCapBytes?: number; /** * How long a written frame may await the agent's ACK before the transport * is killed. Defaults to {@link DISPATCH_TIMEOUT_MS}; tests shorten it. */ dispatchTimeoutMs?: number; /** Injectable process factory for tests. */ spawnTransport?: (options: { wslPath: string; distro: string; scriptPath: string; argvPrefix: string[]; leaseMs: number; }) => ChildProcess; /** * Injectable out-of-band signal delivery for tests. The real path spawns a * second `wsl.exe` to send USR1 to the agent's PID. */ signalTransport?: (options: { wslPath: string; distro: string; pid: number; signal: NodeJS.Signals; }) => void; /** * Maximum requests in flight on one resident; a submission past it is * refused instead of growing the request map without bound. */ maxPending?: number; /** Optional async preparation selecting the entry before the first spawn. */ prepare?: () => Promise; /** The first revival delay in ms; doubles per death. Tests shorten it. */ revivalBackoffMs?: number; }); /** * Whether the agent is permanently out — the executor's fallback cue. * * @returns true once the rebuild budget is spent. */ get unavailable(): boolean; /** Human-readable reason for the last transition to `dead`, for logging. */ get unavailableReason(): string; /** * Enter the dead state and schedule the next bounded revival attempt. * * The delay doubles per death (2 s, 4 s, 8 s, … capped at 30 s). After * {@link MAX_REVIVALS} deaths the state stays permanent and the refusal * carries the restart remedy. */ markDead(): void; /** * A read-only lifecycle snapshot for diagnostics. Includes the live pid, the * last failure and the remaining revival budget; it never starts or stops * anything. * * @returns the status snapshot. */ status(): AgentStatus; /** * Start the process and wait for the handshake. Re-entrant: concurrent * callers share the one start. * * @returns resolved once the state is `ready`. */ start(): Promise; /** * Apply an async preparation entry to this agent before the first spawn. * * @param entry - the selected entry. */ private applyPrepared; /** * Spawn the process and run the handshake. * * @returns resolved once the state is `ready`. */ private beginStart; /** * The transport's failure and exit wiring, in the order the spawn attaches * it: a spawn error, the stdin EPIPE guard, the handshake stderr tail, the * exit handler, the stdout reader, then the diagnostic stderr reader. * * @param child - the freshly spawned transport. * @param current - whether this child is still the current generation. * @param settleStart - the handshake settler. * @param handshakeTimer - the handshake watchdog. */ private wireAgentProcess; /** * The stdout line splitter: a bounded buffer instead of readline, which * accumulates an over-long line whole before anyone can object — exactly the * unbounded-capture hole. Protocol lines are ASCII by construction (ids, * numbers, base64), so chunk-boundary decoding is not a concern. * * @param child - the transport to read. * @param current - whether this child is still the current generation. * @param settleStart - the handshake settler. * @param handshakeTimer - the handshake watchdog. */ private readAgentOutput; /** * One stdout line from the agent. The first must be a matching HELLO. * * @param line - one protocol line, terminator stripped. * @param settleStart - the handshake settler. * @param handshakeTimer - the handshake watchdog. */ private handleLine; /** * The agent named itself. A refusal settles BEFORE killing: the exit event * must not overwrite the real reason with the generic handshake message (the * fake transports emit exit synchronously inside kill(); a real wsl.exe races * it). * * @param message - the agent's HELLO. * @param settleStart - the handshake settler. * @param handshakeTimer - the handshake watchdog. */ private acceptHandshake; /** * Why this HELLO is refused, or undefined when it is accepted: the name and * version window first, then the digest of the script the distro actually * read. * * @param message - the agent's HELLO. * @returns the refusal reason, or undefined when the handshake is accepted. */ private handshakeRefusal; /** * The agent dequeued this request: start its own budget clock NOW. Armed * here instead of at submission, a queued request can no longer time out on * a queue it never chose to join — and its watchdog can never kill the * shared transport for a stall that was never its own. A request cancelled * while it was queued is killed only now, when it is the one running. * * @param message - the agent's ACK. */ private acceptAck; /** * Take the entry an answer settles, running the bookkeeping every answer * shares: mark it answered, release its timers, drop it from the map, and * move the queue on. An answer for an entry the caller already gave up on is * noise: it cleans up and settles nothing. * * @param id - the request id the answer names. * @returns the entry to settle, or undefined when there is nothing to settle. */ private takeAnswered; /** * Settle a normal answer. A cancelled request keeps its entry only until this * answer arrives. * * @param message - the agent's RES. */ private settleResult; /** * Protocol 7's structured FS refusal: settle the pending FS request with the * reason preserved, so the adapter maps the code directly instead of sniffing * a synthesized stderr line. * * @param message - the agent's FSERR. */ private settleFsError; /** * A refused request. A cwd rejection is the command's own failure, not the * agent's — it becomes a CwdError so the execution layer can report it * exactly like the one-shot path's relay text. A `spawn` rejection is the * same class of failure on the native agent (it cannot distinguish a missing * workdir), so it gets its own class and the executor retries it one-shot. * * @param message - the agent's ERR. */ private settleAgentError; /** * The process died. Requests in flight ride exactly one rebuild; a second * death is permanent. * * @param child - the process that exited. * @param code - the exit code, null when killed by a signal. * @param signalName - the killing signal, null on a normal exit. */ private handleProcessExit; /** * Sort the requests a dead transport left behind into the three fates the * one rebuild allows. Only provably read-only FS requests ride it: whatever * their first execution did, it changed nothing. A command or a write that * was in flight has UNKNOWN state — replaying it would run non-idempotent * work a second time, or report a guarded create that actually succeeded as a * refusal — so it fails with that fact instead. An aborted or unsent entry * was already answered, or never ran, and settles locally. * * @param carrying - the entries taken off the map before the rebuild. * @returns the entries that ride the rebuild. */ private partitionForRebuild; /** * Start the rebuild and hand it the replayable requests under fresh ids. * A stale watchdog must not survive the rebuild: its closure kills * `this.process`, which is by then the NEW transport. * * @param relayable - the requests `partitionForRebuild` cleared to replay. */ private relayOverRebuild; /** * Fail every entry still on the map: the second death is permanent. * * @param message - the reason, already stored as `lastError`. */ private rejectAllPending; /** * Register one request's pending entry and write its frame: the shared * request machinery (abort, submission, the ACK-armed watchdog). The * watchdog is deliberately NOT armed here — it starts at the agent's * dequeue `ACK`, so time spent queued behind an earlier request never * spends this request's budget and never kills the shared transport for a * stall that was not its own. * * @param request - the request to register. */ private track; /** * Build one pending entry: the caller's settle wrappers (which record the * metric once) and, when the request carries a budget, the stuck-request * watchdog armed by the agent's ACK. * * @param request - the request being tracked. * @param kind - the metric bucket, with the caller's default resolved. * @returns the entry, not yet registered. */ private newPendingRequest; /** * Wire the caller's abort. An unsent request dies immediately; a sent one * writes the KILL frame and, when the request is running, arms the signal * that interrupts the command where it lives. * * @param pending - the tracked request. * @param signal - the caller's cancellation. */ private attachCancellation; /** * Send a tracked request, recording dispatch before synchronous responses. * A written frame starts the dispatch watchdog: the ACK that arms the * execution budget is not guaranteed to arrive at all. * * @param pending - the request to send. * @returns whether the frame was written. */ private sendPending; /** * Arm the frame-written watchdog: a resident that stays alive without * dequeuing the request is a wedged transport, not a slow command. * * @param pending - the sent request. */ private armDispatchWatchdog; /** * Release the frame-written watchdog once the ACK proves the resident * dequeued the request. * * @param pending - the acknowledged request. */ private releaseDispatchWatchdog; /** Dispatch the next shell request only after the preceding answer. */ private dispatchQueued; /** * Run one command inside the distro through the agent. * * @param request - the execution request. * @returns the settled result. * @throws {AgentUnavailableError} when the agent is out for this process. */ exec({ cwd, argv, timeoutMs, maxOutputBytes, env, stdin, signal }: { /** Linux path to run in. */ cwd: string; /** The argv, already bwrap-wrapped when the caller confines. */ argv: string[]; /** * In-distro timeout, whole seconds upward, measured from the agent's * dequeue ACK; `<= 0` or omitted means none. Queue time ahead of the * dispatch is never counted. */ timeoutMs?: number; /** * Extra environment for this request only; values lose trailing newlines * (protocol limitation). */ env?: Record; /** * Per-stream capture ceiling the agent enforces (carried on the EXEC * frame); the RES line reports which streams were cut. 0 (the default) * keeps the unbounded capture. */ maxOutputBytes?: number; /** * The child's entire stdin, delivered before its first read (protocol * v6); the child sees EOF at the payload's end. Omitted or empty keeps * the v5 shape — an empty stdin and immediate EOF. Note the shell agent * decodes the payload through command substitution, which strips * trailing newlines; the native agent delivers the bytes verbatim. */ stdin?: Uint8Array; /** Cancels the request, sending KILL if it was already dispatched. */ signal?: AbortSignal; }): Promise<{ exitCode: number; stdout: Buffer; stderr: Buffer; truncated: { stdout: boolean; stderr: boolean; }; }>; /** * Run one filesystem-substrate op inside the distro through the agent. * Responses reuse the EXEC `ACK`/`RES` lines, so cancellation and the * watchdog are exactly the command path's. The rebuild relay differs by op: * a read-only op rides a rebuild, a `write` in flight fails with an * unknown-state error instead of being replayed. * * @param request - the filesystem request. * @returns the settled result. * @throws {AgentUnavailableError} when the agent is out for this process. */ fs({ op, args, timeoutMs, signal }: { /** * Op name (`stat`, `lstat`, `list`, `realpath`, `read`, `write`), * dispatched by `agent/wsl-agent.sh`. */ op: string; /** Op arguments; each rides one base64 line. */ args: string[]; /** * In-distro timeout, whole seconds upward, measured from the agent's * dequeue ACK; `<= 0` or omitted means none. */ timeoutMs?: number; /** Cancels the request, sending KILL if it was already dispatched. */ signal?: AbortSignal; }): Promise<{ exitCode: number; stdout: Buffer; stderr: Buffer; reason?: string; }>; /** * Run one batched FS frame (protocol 7): the ordered ops execute in one * worker and the resolution is ONE result whose stdout is the per-op * record stream (`OK |` / `BAD ||`). The host sends * this only to a resident that advertised `batch`; `DistroFs` gates it. * * @param request - the batch request. * @returns the settled batch result. */ fsb({ ops, timeoutMs, signal }: { /** The ordered ops, each `{ op, args }` in the FS vocabulary. */ ops: Array<{ op: string; args: string[]; }>; /** In-distro timeout from the dequeue ACK; `<= 0` means none. */ timeoutMs?: number; /** Cancels the request, sending KILL if it was already dispatched. */ signal?: AbortSignal; }): Promise<{ exitCode: number; stdout: Buffer; stderr: Buffer; reason?: string; }>; /** * Liveness probe, also used to warm the agent up. * * @param signal - cancels the wait. * @returns resolved on PONG. */ ping(signal?: AbortSignal): Promise; /** * The cumulative request metrics: queue wait (submission -> ACK) and execution * time (ACK -> settle) per request kind, plus the peak in-flight count. * * @returns a snapshot the caller can keep. */ metrics(): AgentMetrics; /** Reset the cumulative metrics (diagnostics/probes). */ resetMetrics(): void; /** * The metric bucket for a request kind. * @param kind - fs or exec. * @returns the bucket. */ private kindMetrics; /** * Record a request that never entered the pending map. * @param kind - the bucket. */ private noteRejected; /** * Record the dequeue ACK: the request's queue wait. * @param pending - the request. */ private recordAck; /** * Record a settle: the requests count, the execution time (or the queue wait * for a request that never ACKed), and the outcome. * @param pending - the request. * @param error - the failure, when any. */ private recordSettle; /** * Deliver an out-of-band signal to the resident shell. The serial stdin loop * cannot consume a frame while a command runs, so cancellation is a signal; * a second `wsl.exe` is the only channel that reaches the agent while it is * blocked in `wait`. * * Only an agent that shares the distro's PID namespace is addressable: the * plain agent, or a session runtime (its prefix is a scope plus mounts, but * no PID namespace). A confined resident runs inside a PID namespace whose * PIDs do not exist in the distro, so signalling its HELLO PID could hit an * unrelated process; there the KILL frame remains the (delayed) fallback. * * @param signal - the signal to deliver (`SIGUSR1` is the cancel trap). */ private signalAgent; /** * Shut the agent down: SHUTDOWN first, then kill after a short grace. The * agent becomes reusable — a later `exec` starts a fresh process. * * @returns resolved once the process is gone. */ close(): Promise; /** * Release the host's ends of a dead child's stdio. A descendant that * inherited a pipe's write end would otherwise keep the read side — and the * fd — open until that descendant exits; the agent's own helpers are * redirected at their spawn sites, but the host must not depend on it. * * @param child - the process whose streams are being released. */ private teardownStreams; /** * Write one frame to the live process. * * @param lines - the frame lines to write. * @returns whether the frame was written. */ private writeLines; /** * Write one frame to a specific process, tolerating a dead pipe. * * @param child - the process being shut down. * @param lines - the lines to write. */ private writeLinesSafe; /** Restart the idle-shutdown countdown. */ private rearmIdleTimer; /** * Detach an entry's timer and abort listener. * * @param pending - the entry to clear. */ private clearPending; /** * Deliver the out-of-band cancel signal after a short grace, and only while * the request it was meant for is still the agent's current one. * * The signal has no request id: it interrupts whatever command the agent is * blocked in. A timeout request is usually already being killed by the * in-distro watcher, so an immediate signal can land after the agent moved * on — the next request then dies with exit 138 (SIGUSR1) and looks * `completed`. A newer ACK means the agent has answered the old request, so * the signal is dropped; an answered request is dropped too. * * @param pending - the cancelled request. */ private armCancelSignal; } /** * Rewrite the request id inside a stored frame so a resent request does not * collide with ids the new process has already seen. * * @param lines - the stored frame. * @param newId - the new request id. * @returns the relabelled frame. */ export declare function relabelFrame(lines: string[], newId: string): string[]; export default WslAgent;