import { ChildProcess } from 'node:child_process'; import { ProcessResult, ProcessRunOptions, ProcessRunner } from '../../utils/types.js'; /** POSIX/Node signal name accepted by `child.kill` and `process.kill`. */ type ProcessSignal = Extract[0], string>; /** * Resolve Windows `taskkill.exe` from the trusted System32 directory rather than * searching cwd/PATH (where a workspace-controlled binary could hijack timeout or * cancellation kills with the server's environment). */ export declare function resolveWindowsTaskkillPath(env?: Record): string; /** Minimal result shape returned by `spawnSync` for `taskkill.exe`. */ export interface TaskkillOutcome { error?: Error; status: number | null; } /** * Terminate a Windows process tree via the trusted `taskkill.exe`, bounded by * `WINDOWS_TASKKILL_TIMEOUT_MS`. Falls back to `fallbackKill()` if `taskkill` * fails to launch, times out, or exits non-zero. */ export declare function killWindowsProcessTree(pid: number, fallbackKill: () => boolean, runTaskkill?: (command: string, args: string[], options: { stdio: 'ignore'; windowsHide: true; timeout: number; }) => TaskkillOutcome, env?: Record): TreeTerminationOutcome; export type TreeTerminationOutcome = 'terminated' | 'leader_only' | 'skipped_leader_exited' | 'group_gone' | 'not_started' | 'failed'; /** Optional platform/DI overrides for {@link killProcessTree} (used in cross-platform tests). */ export interface KillProcessTreeOptions { platform?: typeof process.platform; runTaskkill?: (command: string, args: string[], options: { stdio: 'ignore'; windowsHide: true; timeout: number; }) => TaskkillOutcome; env?: Record; } /** * Terminate a child process and its descendants. * POSIX: children are spawned as process-group leaders (`detached: true`), so * signaling `-pid` stops grandchildren too (e.g. build workers spawned by the SDK). * Windows: `detached` creates a console window, so children stay attached and * `taskkill.exe /T /F` from System32 ends the tree. If the Windows leader has * already exited, `taskkill.exe` is skipped (the PID may be reused) and * `'skipped_leader_exited'` is returned so the caller never claims SIGKILL and * warns that a descendant may still be alive. */ export declare function killProcessTree(child: ChildProcess, signal?: ProcessSignal, options?: KillProcessTreeOptions): TreeTerminationOutcome; /** * Spawns child processes to execute CLI commands. * * Responsibilities: * - shell-free execution (injection defense — see H1), * - no input: stdin stays open and the runner never writes to it (it never * answers prompts), * - a timeout that terminates the child and resolves with the buffered *partial* * output (rather than discarding it) plus a non-zero exit code (P0.2), * - propagation of an external abort signal so an MCP client can cancel a * long-running command (P0.3), * - bounded stdout/stderr retention to protect memory and token budget (P0.4). */ /** Test/DI options for {@link NodeProcessRunner}. */ export interface NodeProcessRunnerOptions { defaultTimeoutMs?: number; overrideTimeoutMs?: number; maxOutputChars?: number; /** Grace window (ms) to wait for child stdio to close after failed or skipped tree termination. */ failedTreeKillCloseGraceMs?: number; /** Process-tree termination hook. */ terminateTree?: (child: ChildProcess, signal: ProcessSignal) => TreeTerminationOutcome; } export declare class NodeProcessRunner implements ProcessRunner { private readonly defaultTimeoutMs; private readonly overrideTimeoutMs?; private readonly maxOutputChars; private readonly failedTreeKillCloseGraceMs; private readonly terminateTree; /** * @param options Test/DI overrides. `overrideTimeoutMs` (an operator global * override sourced from `FLUENT_MCP_COMMAND_TIMEOUT_MS`) wins over any * per-call timeout; `defaultTimeoutMs` is the fallback when a call omits one. * Both default from `config.servicenowSdk`. `maxOutputChars` caps retained * output per stream; a call may raise its stdout cap (`maxStdoutChars`). */ constructor(options?: NodeProcessRunnerOptions); /** * Resolve the effective timeout for a call. Operator override wins over the * per-call value, which wins over the configured default. A budget a timer * cannot hold is capped at `MAX_TIMER_DELAY_MS`: budgets are derived from * caller values (exec `timeoutMs` up to 2^31 - 1 plus 60 s of headroom, * download/transform `timeoutSeconds` × 1000), and Node fires an oversized * timer after 1 ms, which killed such a command at once. */ private resolveTimeout; run(command: string, args?: string[], cwd?: string, timeoutMs?: number, signal?: AbortSignal, runOptions?: ProcessRunOptions): Promise; /** * Assemble a ProcessResult from the bounded buffers, optionally appending a * status note to stderr (used for timeout/cancellation/external signals). */ private buildResult; } export {}; //# sourceMappingURL=processRunner.d.ts.map