UNPKG

@sema-agent/core

Version:

Stateless, task-oriented AI agent core

79 lines (78 loc) • 5.32 kB
/** * What the Bash tool shows of a failed command's own output: the capture every failure arm that shows output reads (the * ran-then-cut codes and the outcome-unknown ones), and the one outcome-unknown result (#4740 / #4743). Its own module so the * shell tool's file does not grow with a concern both families share. */ import type { ExecutionEnv, ExecutionErrorCode } from "../../internal/harness.js"; import { type BackgroundShellErrorCode } from "../../core/background-shell.js"; /** What the Bash leg itself saw the command stream through the environment's callbacks, per stream: the leg's own bounded tails, each * already marked where its head was dropped (`markTruncated`). */ export interface StreamedOutput { readonly stdout: string; readonly stderr: string; } /** * What a failed command wrote before its failure: the environment's capture — or, when the environment attached none (neither * member is a string), what the leg saw it stream (`streamed`) — clipped as the clean exit clips it, preserved on disk first when * either stream overflows (same condition and shape as the clean-exit leg — see writeShellOverflowFile's docstring re: what * "preserved" does and does not guarantee), and joined into the sections the caller fences (`delimitUntrusted`), so process output * cannot self-declare a second headline or a fake section marker. */ export declare function capturedBeforeFailure(env: ExecutionEnv, error: { readonly partialStdout?: unknown; readonly partialStderr?: unknown; }, streamed?: StreamedOutput): Promise<{ stdout: string; stderr: string; captured: string; overflowFile: string | undefined; }>; /** The word a failed background start's card carries: the environment's own when it is one of the background face's closed set * (`BACKGROUND_SHELL_ERROR_CODES`), else `unknown` — and `onOutside` is told (the reader announces the breach). */ export declare function backgroundFailureWord(code: unknown, onOutside: () => void): BackgroundShellErrorCode | "unknown"; /** * A state word (`suspended`, `auth_failed`) answered before the command wrote anything: the command did NOT run, and the two states * need DIFFERENT model behaviour from the generic "did not run" template — a paused workspace needs the TASK resumed (retrying the * command in this leg can never succeed), a rejected credential needs an operator (retrying burns the attempt budget and can lock * the account). Returned results, not the structural throw: the dead-cwd diagnosis probes the workspace, and probing a * paused / unauthenticated environment just fails again with the same word. `card` is the reader's (`code`). */ export declare function stateNotStartedResult(word: ExecutionErrorCode, toolName: string, message: string | undefined, card: Record<string, unknown>): { content: string; details: Record<string, unknown>; isError: true; }; /** * The account of a state word (`suspended`, `auth_failed`) that arrived while the command ran — it had written output, so it started * and its outcome is not known. The state's own way out stays (resume the task / an operator fixes the credential); the outcome * sentence follows it ({@link outcomeUnknownResult}). The word is no breach: a workspace can be paused and a credential revoked * mid-command. Answers the `lead` and the card's flag. */ export declare function stateWhileRunning(word: ExecutionErrorCode, message: string | undefined): [lead: string, flags: Record<string, unknown>]; /** Where a command of the model's shell that the environment answered with its own refusal (a deployment's `env.` code) is told: the * leg's seat (`core/runner/restore-seat.ts`), which ends the leg at the turn's end. */ export type EnvRefusalNote = (failure: Error & { readonly code: `env.${string}`; }) => void; /** * The account of a command the environment refused itself on (a deployment's own `env.` code): whether the command ran is not known (the * environment may have gone after it was handed over), so it goes to the outcome-unknown result with this lead and the card flag * `envRefused`; the leg's seat is told first (`note`, absent for a host's own toolkit). */ export declare function envRefusedLead(failure: { readonly message: string; }, code: `env.${string}`, note: EnvRefusalNote | undefined): [lead: string, flags: Record<string, unknown>]; /** * A failure that leaves the outcome unknown: the reader's account (`lead`, bounded by its caller), the one outcome sentence after it * (`withOutcomeNote`), then what the command wrote before it — a device that streamed half a build before its connection dropped * leaves that half as the only record of how far it got. The card carries the failure's word (the reading's); the sentence does not, * except the lead of a deployment's own `env.` code ({@link envRefusedLead}), which names it. */ export declare function outcomeUnknownResult(env: ExecutionEnv, failure: { readonly partialStdout?: unknown; readonly partialStderr?: unknown; }, word: ExecutionErrorCode | `env.${string}`, toolName: string, lead: string, flags: Record<string, unknown>, readOnly: boolean | undefined, streamed: StreamedOutput | undefined): Promise<{ content: string; details: Record<string, unknown>; isError: true; }>;