import { CrtrError } from './errors.js'; import { type ExitCodeValue } from '../types.js'; import { ApiError } from '../api/index.js'; /** Set by the dispatcher when `--json` is present anywhere in argv. */ export declare function setJsonOutput(v: boolean): void; /** True when the caller asked for raw JSON instead of rendered prose. */ export declare function isJsonOutput(): boolean; /** Structured error payload. `error` is a stable code the agent branches on; * `next` is the recovery road sign. */ export interface ErrorPayload { error: string; message: string; received?: unknown; field?: string; /** Transport status of a failed backend call (configured CLIs). It is kept out * of `received` on purpose: `received` names the caller's offending VALUE, and * reporting an HTTP status there is a false claim about what was sent. */ http_status?: number; next: string; } /** A command-level failure: surfaces as the JSON response on stdout. */ export declare class InputError extends CrtrError { payload: ErrorPayload; constructor(payload: ErrorPayload, exitCode?: ExitCodeValue); } /** Read raw stdin to EOF. Returns empty string when stdin is a TTY (no pipe). * Called by the argv parser for leaves declaring a `stdin` parameter. */ export declare function readStdinRaw(): Promise; /** Best-effort, non-hanging peek at whatever stdin bytes are already * buffered — used ONLY to detect a positional/stdin conflict, never to * consume the leaf's actual required stdin body. Genuine piped/redirected * content (a heredoc, `< file`, `cat x |`) is fully written into the pipe * before this process starts reading, so it resolves within one tick; a * non-TTY stdin that's simply inherited and held open with nothing written * to it (e.g. a caller subprocess that never closes its own stdin) would * otherwise hang `readStdinRaw()` forever — this bounds that wait instead * of blocking the whole invocation on an ambiguous pipe. Returns '' on a * TTY (nothing can be piped) or once the bound elapses with no bytes. */ export declare function peekStdinRaw(timeoutMs?: number): Promise; /** Raw-JSON mirror of a single-shot response (the `--json` escape hatch). The * default path renders the result as prose instead — see render.ts. */ export declare function emit(obj: Record): void; /** One JSONL record. Call per event in a stream; partial reads stay parseable. */ export declare function emitLine(obj: Record): void; /** * Write to stdout and resolve true ONLY once the bytes are confirmed flushed to * a connected reader. Resolves false if the consumer is gone (EPIPE) or the * write fails. This is the reliable "the caller actually received it" signal: * use it to gate side effects that must only happen on genuine delivery (e.g. * acking a collected result). A killed process never resolves at all — also * safe, since the gated side effect then never runs. */ export declare function writeStdout(s: string): Promise; export declare function diag(message: string): void; /** Translate an `ApiError` into the clean CLI error a leaf should surface. * Three tiers, in priority order: * 1. Daemon-down (503 / `daemon_unavailable`) → a `network`-class `CrtrError` * so the exit code and next-hint match the operational failure it is. * 2. A server-thrown `InputError` round-trips its FULL structured payload * through `toErrorBody` into `ApiError.details` (`{error,message,next,…}`) — * reconstruct it verbatim so a gate/guard error (revive reopen-gate, push * worktree/finalization guard, …) surfaces byte-for-byte as the leaf raised * it before the re-plumb, preserving its SPECIFIC code + next. * 3. Otherwise map status→code (`STATUS_TO_CLI_CODE`) with the server message * and a caller-supplied-or-default `next`. */ export declare function apiErrorToCliError(err: ApiError, next?: string): CrtrError; /** Terminal error handler. Command-level failures (bad input, not-found, * ambiguous) surface as the JSON response on stdout so the caller parses one * contract. A daemon `ApiError` is translated to that same clean contract * (`apiErrorToCliError`) as a safety net for any leaf that lets it propagate. * Runtime/internal failures go to stderr as `{error:"internal"}` — raw traces * never reach the agent. Exits non-zero either way. */ export declare function handle(e: unknown): void;