import type { Duplex } from "node:stream"; import { z } from "zod"; /** Env var naming the inherited relay fd. Set by the guest init; absent everywhere else * (Fargate, self-hosted daemon), where the worker env-boots as always. */ export declare const RELAY_FD_ENV = "BOARDWALK_IDENTITY_RELAY_FD"; /** Max bytes of one relay line — the wire protocol's 32 MiB frame cap, mirrored in-guest. * An oversized line costs the connection (LF framing cannot resynchronize past it), which * for this relay means a hard bootstrap failure. Measured in UTF-16 code units, which for * this ASCII-JSON wire is the byte count; the cap is a guard, not exact accounting. */ export declare const MAX_RELAY_LINE_BYTES: number; /** The identity payload — the env contract's fields, as JSON instead of env vars. */ export declare const relayIdentitySchema: z.ZodObject<{ run_id: z.ZodString; control_plane_url: z.ZodString; run_token: z.ZodString; api_token: z.ZodOptional; task_cpu_units: z.ZodOptional; byo_providers: z.ZodOptional; env: z.ZodOptional>; }, z.core.$strip>; export type RelayIdentity = z.infer; /** The init→worker halves of the post-identity relay: `wake` resolves a frozen suspending * seam (payload: the wake-inject body, verbatim), `suspend_abort` tells a parked seam the * snapshot attempt failed and it should fall back to holding. */ export interface RelayChannelHandlers { onWake(payload: unknown): void; onSuspendAbort(payload: unknown): void; } /** The worker→init halves: ask to be frozen (payload: the suspend-request body — reason, * wake summary, opaque broker signal), and confirm a wake landed (init then acks its host). */ export interface RelayChannel { sendSuspendRequest(payload: unknown): void; sendWakeAccepted(): void; } /** * Read the relay fd from `env`, deleting the key (bootstrap-only plumbing; run code has no * business seeing it). Returns null when unset — the normal env-boot path. */ export declare function relayFdFromEnv(env: NodeJS.ProcessEnv): number | null; /** * Map a relayed identity onto `env` for `capturePlatformContext`. User env lands FIRST and * the platform keys LAST, so nothing user-supplied can shadow a platform value. */ export declare function applyIdentityToEnv(identity: RelayIdentity, env: NodeJS.ProcessEnv): void; /** The worker_ready diagnostics — supplied by the worker (init cannot know these), * forwarded verbatim by the guest init. Best-effort, never load-bearing. */ export interface WorkerDiagnostics { worker_version?: string; node_version: string; sdk_version?: string; } /** Collect the worker_ready diagnostics. Version lookups are best-effort: the runner's own * package.json sits two levels above this module in both the src and published dist * layouts; the SDK's is reachable only if its exports expose ./package.json. */ export declare function workerDiagnostics(): WorkerDiagnostics; /** One end of the init↔worker relay. Wraps any Duplex so tests run over in-memory streams. */ export declare class IdentityRelay { private readonly stream; private buffer; private closed; private failure; private wake; private readonly onData; constructor(stream: Duplex); private fail; /** Announce the pre-identity park (with the diagnostics payload when provided). * Init forwards this as the base-snapshot gate. */ announceReady(diagnostics?: WorkerDiagnostics): void; /** * Block until init relays the run identity. THIS is the point the base snapshot freezes: * everything before it is generic warm-up shared by every run; everything after belongs * to one run. Unknown message types are ignored (forward-compatible), malformed lines are * logged and skipped (init is trusted; a torn line must not kill PID 1's only worker), but * a malformed IDENTITY payload is a hard error — same as a missing env var today. */ awaitIdentity(): Promise; /** Confirm capture. Init acks its host only after this arrives. */ acceptIdentity(): void; /** * Attach the post-identity consumer: the suspend/wake channel (the same fd, the same JSON * lines). From here the relay dispatches init→worker messages to the handlers — * `wake` (resolve a frozen seam) and `suspend_abort` (the seam falls back to holding) — * and the returned channel sends the worker→init halves (`suspend_request`, * `wake_accepted`). Unknown types are ignored (forward-compatible); malformed lines are * logged and skipped, exactly as pre-identity. Call once, after {@link acceptIdentity}. */ openChannel(handlers: RelayChannelHandlers): RelayChannel; private pumpChannel; private writeLine; private readLine; } /** * Open the relay over the inherited fd. Wrapping the fd in a net.Socket also marks it * close-on-exec (libuv does this on adoption), so subprocesses the run later spawns cannot * inherit the relay and speak to init. */ export declare function connectIdentityRelayFd(fd: number): IdentityRelay;