UNPKG

agentfootprint

Version:

The explainable agent framework — backtrack a wrong answer to the exact context that caused it (evidence, not guesses). Built on footprintjs.

68 lines (67 loc) • 3.24 kB
/** * What both code adapters hand back about a run's output — bounded, and saying * so — and the one check of a command's options. * * One implementation, because the two promises it keeps are the port's, not an * adapter's: a cut is always stated (`truncated`), and a command's result says * only what the backend reported (no exit status is ever made up). */ import type { CodeCommandOptions, CodeCommandResult, CodeTruncation } from '../../provider-contract/types.js'; export { isHighSurrogate, isLowSurrogate, utf8Length } from '../../lib/utf8.js'; /** stdout and stderr after the cut, and what the cut took. */ export interface BoundedOutput { readonly stdout: string; readonly stderr: string; /** Present IFF something was cut — an empty object here would read as * "truncation happened, magnitude unknown". */ readonly truncated?: CodeTruncation; } /** * Cut each stream to `max` characters, saying whether — and from how much — it * cut. * * `overflowed` names a stream the BACKEND already cut (a child whose output * passed its buffer ceiling): that stream is marked cut even when it fits * `max`, and `ofChars` is left out, because the length before that cut was * never seen — a number here would understate it. */ export declare function boundOutput(stdout: string, stderr: string, max: number, overflowed?: 'stdout' | 'stderr'): BoundedOutput; /** What a backend reported about one command, before the bound. */ export interface CommandReport { readonly stdout: string; readonly stderr: string; /** Only when the backend reported one. */ readonly exitCode?: number; /** Only when the backend reported one. */ readonly isError?: boolean; /** A stream the backend itself cut before handing it over. */ readonly overflowed?: 'stdout' | 'stderr'; /** The signal that ended the command before it exited, when known. */ readonly terminatedBy?: string; } /** A command's options, checked once. */ export interface CommandBounds { readonly maxOutputChars: number; readonly timeoutMs?: number; readonly signal?: AbortSignal; readonly checkpoint?: string; } /** * The result of one command: bounded output, and every other field copied * from the report only when the report had it. * * `checkpointSeen` is read over the WHOLE stdout, before the cut — a marker * printed after `maxOutputChars` characters is the common case, not the edge. */ export declare function commandResult(report: CommandReport, bounds: CommandBounds): CodeCommandResult; /** Did `stdout` hold `line` as one whole line (a trailing `\r` allowed)? */ export declare function printedLine(stdout: string, line: string): boolean; /** * Check a command and its options, or throw a `TypeError` naming the option. * * The message never repeats the command: it is caller data, and an error is * the one place nobody expects to have to scrub. */ export declare function commandBounds(command: unknown, options: CodeCommandOptions | undefined, runnerMaxOutputChars: number): CommandBounds; /** Bytes of a staged or returned payload: a string's UTF-8 length, bytes as they are. */ export declare function payloadBytes(data: string | Uint8Array): number;