/** * ProcessTransport — Spawns qodercli as a child process and * manages stdin/stdout communication using JSONL (JSON Lines) format. * * This is the primary transport for Node.js environments. It: * 1. Builds CLI arguments from the provided options * 2. Spawns the CLI process (or delegates to a custom spawner) * 3. Reads stdout line-by-line, parsing each as JSON * 4. Writes to stdin as JSON + newline * 5. Handles graceful shutdown: close stdin → wait → SIGTERM → wait → SIGKILL */ import type { QueryTransportProvider, Transport } from './transport.js'; import type { StdoutMessage } from '../types/control.js'; import type { SdkPluginConfig, ToolConfig } from '../types/common.js'; import type { PermissionMode } from '../types/permissions.js'; import type { McpServerConfigForProcessTransport, McpServerToolPolicy } from '../types/mcp.js'; import type { InternalAuthOptions } from '../types/auth.js'; import type { SecurityScanOptions, SpawnedProcess, SpawnOptions, SettingSource } from '../types/options.js'; import type { DiagnosticsSink } from './sdk-diagnostics.js'; export declare class QoderCliProcessError extends Error { readonly code: "QODER_CLI_PROCESS_ERROR"; readonly exitCode?: number | null; readonly signal?: NodeJS.Signals | null; readonly stderr?: string; constructor(message: string, options?: { exitCode?: number | null; signal?: NodeJS.Signals | null; stderr?: string; cause?: unknown; }); } /** * Options for configuring the ProcessTransport. * * These map 1:1 to the CLI flags and environment variables that the * qodercli understands. */ export interface ProcessTransportOptions { /** Path to the Qoder CLI executable (binary or script) */ pathToQoderCLIExecutable?: string; /** Override executable name (node, bun, deno) for script entry points */ executable?: string; /** Extra arguments prepended before the script path */ executableArgs?: string[]; /** Working directory for the spawned process */ cwd?: string; /** Custom environment variables (defaults to process.env) */ env?: Record; proxy?: string; /** * VPC private-deployment endpoint (CN deployments only). Written to the * `QODERCN_VPC_ENDPOINT` / `QODER_VPC_ENDPOINT` env var for the child. */ vpcEndpoint?: string; /** stderr handling mode */ stderr?: 'inherit' | 'pipe' | 'ignore'; /** Optional callback for child-process stderr output */ stderrHandler?: (data: string) => void; /** Abort controller */ abortController?: AbortController; /** * Grace period in milliseconds before terminating the process after stdin is closed. * Defaults to CLOSE_GRACE_MS. */ closeGraceMs?: number; /** Internal auth configuration (creates a one-shot payload file for the CLI) */ auth?: InternalAuthOptions; model?: string; /** Forward --debug to the CLI process. */ debug?: boolean; /** SDK-internal diagnostics sink. This is not forwarded to qodercli. */ diagnostics?: DiagnosticsSink; agent?: string; sessionId?: string; continue?: boolean; resume?: string; resumeSessionAt?: string; resumeDropsTurn?: string; forkSession?: boolean; persistSession?: boolean; maxTurns?: number; permissionMode?: PermissionMode; allowDangerouslySkipPermissions?: boolean; permissionPromptToolName?: string; /** SDK-internal: true when Options.canUseTool is present. */ canUseTool?: boolean; includePartialMessages?: boolean; includeHookEvents?: boolean; /** Request SDK-internal post-commit transcript frames from qodercli. */ sessionMirror?: boolean; allowedTools?: string[]; disallowedTools?: string[]; tools?: ToolsOption; toolConfig?: ToolConfig; extensions?: string[]; mcpServers?: Record; mcpToolPolicies?: Record; allowedMcpServerNames?: string[]; strictMcpConfig?: boolean; settings?: string | Record; securityScan?: SecurityScanOptions; settingSources?: SettingSource[]; additionalDirectories?: string[]; plugins?: SdkPluginConfig[]; enableFileCheckpointing?: boolean; /** * Extra `--` / `-- ` args to append to the CLI invocation. * Forwarded verbatim from `Options.extraArgs`. `null` value emits a bare flag * (no value); a string emits `--name value`. */ extraArgs?: Record; /** Custom spawner for the Qoder CLI process */ spawnQoderCLIProcess?: (options: SpawnOptions) => SpawnedProcess; /** * Called when the transport detects that authentication has expired * or become invalid (non-zero exit code with auth-related stderr). * Invoked at most once per session. */ onAuthExpired?: () => void; } type ToolsOption = string[] | { type: 'preset'; preset: 'qodercli'; }; export declare class ProcessTransport implements Transport, QueryTransportProvider { static readonly default: ProcessTransport; private process; private customHandle; private options; private ready; private closed; private initializePromise; private authExpiredFired; private pendingInput; private diagnostics?; private processExitError; private stderrTail; private launchOptionsBuilder; constructor(options?: ProcessTransportOptions); create(options: ProcessTransportOptions): Transport; /** * Build CLI arguments, resolve the executable, spawn the process, * and mark the transport as ready. */ initialize(): Promise; private _doInitialize; /** Write a JSON line to stdin. */ write(data: string): void; private writeReadyLine; private flushPendingInput; /** Whether the transport is ready to send/receive. */ isReady(): boolean; /** Signal that no more input will be sent (close stdin). */ endInput(): void; private endReadyInput; /** * Async generator that yields parsed JSON messages from stdout. * * Uses readline to split stdout into lines. Each non-empty line is * expected to be a complete JSON object (JSONL format). * * The generator completes when: * - The readline interface closes (process exited or stdout ended) * - The transport is closed */ readMessages(): AsyncGenerator; /** * Close the transport with graceful shutdown: * * 1. Close stdin (signal to CLI that no more input is coming) * 2. Wait CLOSE_GRACE_MS for the process to exit on its own * 3. Send SIGTERM * 4. Wait KILL_GRACE_MS for the process to exit * 5. Send SIGKILL if still running */ close(): void; private cleanupGeneratedSettings; /** * Get the underlying process PID, if available. */ get pid(): number | undefined; /** * Get the stdout stream from the process or custom handle. */ private getStdout; private appendStderr; private createSpawnError; private createProcessExitError; private getStderrTail; private waitForProcessExit; /** * Resolve the executable command and arguments. * * If the CLI path is a script file (.js/.mjs/.ts/.tsx/.jsx), we need * an interpreter (node/bun/deno). Otherwise the path is a native binary * and is used directly as the command. */ private resolveExecutable; /** Best-effort cleanup of the auth payload file and its parent directory. */ private cleanupAuthPayload; /** Fire `onAuthExpired` at most once per session. */ private fireAuthExpired; } export {};