/** * Typed error results for the cockpit MCP tool boundary. * * Every tool returns `ToolResult` — either `ToolOkResult` (status: 'ok') * or `ToolErrorResult` (status: 'error'). Bare thrown exceptions never reach * the JSON-RPC transport; `wrapToolBoundary` converts them into an * `internal`-class error result. * * `mapCockpitExitToToolError` translates the `CockpitExit` codes used by the * CLI verbs (1 = transport, 2 = argument/parse, 3 = gate refusal) into * discriminated tool-error classes. */ import { type CockpitExit } from '../exit.js'; export type ErrorClass = 'invalid-args' | 'wrong-kind' | 'unknown-gate' | 'not-an-epic' | 'gate-refusal' | 'transport' | 'invalid-cursor' | 'not-worker' | 'contended' | 'scope-not-found' | 'internal'; export interface ToolOkResult { status: 'ok'; data: T; } export interface ToolErrorResult { status: 'error'; class: ErrorClass; detail: string; hint?: string; } export type ToolResult = ToolOkResult | ToolErrorResult; /** Map a `CockpitExit` from the CLI verb into a typed tool-error result. */ export declare function mapCockpitExitToToolError(exit: CockpitExit): ToolErrorResult; /** * Wrap a tool handler so that any thrown Error (including `CockpitExit`) * becomes a typed `ToolErrorResult`. The MCP transport never sees an * uncaught throw from a wrapped handler. */ export declare function wrapToolBoundary(fn: () => Promise>): Promise>; /** * #928 — Envelope-mapping helper. * * Translates the CLI verb's `RunMergeResult` (`{ exitCode, stdout }`) into the * MCP `ToolResult` envelope. THIS TABLE IS THE TRANSPORT CONTRACT (Q4 → B): * any new `reason` string introduced in `runMerge` must appear here, or fall * through to `class: 'invalid-args'` (which is loud enough for tests to catch). * * Mapping (see data-model.md §toMcpResult): * exit=0 → ok, data: parsed * exit=2 + reason='pr-number' → wrong-kind (with `hint`) * exit=2 + reason∈{unresolved, ambiguous-resolution, pr-is-draft, checks-failing} * → gate-refusal * exit=2 + other/missing reason → invalid-args * exit=3 → gate-refusal * exit=1 → transport * exit≥4 → internal * non-JSON stdout → internal */ export declare function toMcpResult(cliJsonStdout: string, exitCode: number): ToolResult; //# sourceMappingURL=errors.d.ts.map