UNPKG

@sema-agent/core

Version:

Stateless, task-oriented AI agent core

99 lines (98 loc) • 7.58 kB
import type { ShellReadVerdict } from "../tools/fs/shell-read-check.js"; import { type ShellReadDisposition } from "../tools/fs/shell-read-judge.js"; import type { GatePass } from "./runner/gate-exit.js"; import type { PermissionResult } from "./tool-policy.js"; import { type ConfinedCall } from "./ask-origin.js"; import { type ShellCommandShape } from "./shell-run-candidates.js"; import type { StartedShell } from "../shell/lex.js"; /** One station answer, received and read: what a reader acts on (`kind`) and the answer it acts on (`verdict` — the engine's own * copy, received once). `unbelieved`: the station's answer was not received or contradicted its own finding, and `verdict` is the * engine's refusal of it (its sentence names the station's words only where they are words of the closed sets — nothing a station * spelled reaches the model), reported once on the call's lane ({@link StationAnswerCall.report}). */ export interface StationAnswerReading { readonly kind: ShellReadDisposition | "silence"; readonly verdict: ShellReadVerdict; readonly unbelieved?: true; } /** The call a reader reads an answer for: its name (the refusal names it), its id, and the lane a station's failure is reported on * (absent ⇒ unreported — the resumed leg reads the engine's own stations). */ export interface StationAnswerCall { readonly toolName: string; readonly toolCallId?: string; readonly report?: (err: Error) => void; } /** * Receive and read a station's answer — the ONE reading for every reader. The answer is received whole ({@link receivedAnswer}: * the engine's one receipt for a caller's object, then each member by its kind — none of the caller's code runs) into the engine's * copy every later read is of; an answer that is not received (an accessor, a member its prototype or a non-enumerable property * supplies, a Proxy anywhere in it, a word that is no string, a mark that is not `true`, not an object) is not believed. Then, in order: * · `refuse` stands, whatever beside it: no reading is stricter; * · the station's SILENCE — the finding `unanswered`, or nothing found (`none`) beside a silence mark (`environmentSilent`, * `rowsUnread`): the station made no finding, whatever disposition it spelled beside it (the engine's own station spells a * vouch beside unread rows as `unanswered`); * · a disposition the decision table does not give the finding on any seat, under any form of the question * ({@link dispositionsOfRow}) — a `vouch` beside a deny hit, an ask beside one, a word outside the closed sets — is NOT believed: * the station's answer contradicts its own finding, and the reader refuses the call; * · otherwise the disposition, as the table gives it. * A silence mark beside a finding the station DID make is not the silence: it classes that finding's question * ({@link silencedBy}). */ export declare function readStationAnswer(answer: ShellReadVerdict, call: StationAnswerCall): StationAnswerReading; /** The ask `d` with the silence a station's answer carries, each its own class on the question it keeps or mints: unread rows are a * rule that could not be read (the rule lane's class); the finding `unanswered` is, unless rows are unread, the environment's silence — * the station's check that did not finish (the guard `unfinished_check`, attested on the ask's record for `call` beside the guards it * already carries) — and the marks only pick whose. Either is a question only a person answers (the real-approval bit, which each * class explains); `probe` follows the finding. Whether a person was already required on the ask the check went silent over is the * call's own fact (`pass.silencePersonRequired`), kept on the gate's pass and on no decision. No silence ⇒ `d` itself. */ export declare function silencedBy<D extends Extract<PermissionResult, { action: "ask"; }>>(d: D, verdict: ShellReadVerdict, call: { readonly toolCallId: string; readonly toolName: string; }, pass?: Pick<GatePass, "silencePersonRequired">): D; /** The deny rows ONE call may meet, as a confined Runner's mode point reads them: any row at all (`any`: either face, the built-in * tiers among them) and a row that guards WRITES (`guardsWrites`: the write face's rows), on the table the call's judgment started * with or on the one in force now (`person-path-rows.ts` `confinedDenyRowsOf`) — and whether a write-face ask row stands there * (`writeAsk`, PRESENT-IFF one does), which guards a command's writes only under a mode that counts such rows (`writeAskRowsCountNow`). */ export interface ConfinedDenyRows { readonly any: boolean; readonly guardsWrites: boolean; readonly writeAsk?: true; } /** The gate's `confined` seat (`ToolGateInput.confined`) — PRESENT ⇔ the Runner declares its shape (`RunnerDeps.deploymentShape`). */ export interface ConfinedSeat { /** The call's declared destination, on these arguments, stays on the leg's hands. */ readonly staysOnHands: (args: unknown) => boolean; /** Asking for `bypassPermissions` now would run the leg under it (the leg's own mode fold). */ readonly bypassArmed: () => boolean; /** The deny rows the call may meet. */ readonly denyRows: () => ConfinedDenyRows; } /** The allow layer's read-only reading of ONE shell call's arguments — its last member's (gate-lanes.ts) and a confined Runner's mode * point's ({@link confinedCallOf}), one reading: the command under the command rule's primary parameter, read by the one lexer; * read-only only where it is a string, not put in the background by the parameter (`run_in_background: true` is `cmd &`, a process * that outlives the approval-time reading) and the read-only tables prove it at `cwd`. */ export declare function readOnlyShellCall(shell: StartedShell, args: unknown, cwd: string | undefined): { readonly readOnly: true; readonly command: string; readonly shape: ShellCommandShape; } | { readonly readOnly: false; readonly shape?: ShellCommandShape; }; /** What a confined Runner lends the mode point for one call ({@link ConfinedCall}) — nothing where the gate holds no seat (no shape * declared): the silence's fact on the call's pass (none ⇒ a person required), the call's destination on the arguments that run, * what the unfinished check left unseen (the gate put the station's fallback in its place ⇒ no row at all may stand; the station * answered ⇒ no row that guards writes, or the command read-only at `cwd`), and the leg's mode fold for a bypass request. */ export declare function confinedCallOf(seat: ConfinedSeat | undefined, pass: Pick<GatePass, "silencePersonRequired" | "shellReadFallback" | "req">, args: unknown, cwd: string | undefined): { readonly confined?: ConfinedCall; }; /** The station's SILENCE ({@link readStationAnswer}), applied once, before any disposition arm: a station — a host-mounted one * included — may spell `vouch`, `mandated` or `ordinary` beside it, and no word vouches for what nobody judged. A deny stands; an * ask keeps its words and gains the silence's class; an allow becomes the silence's question (`ask.message`), one only a person * answers. Nothing is admitted, no `probe` is stamped and no grant is offered — the station made no finding. */ export declare function applyUnansweredSilence(pass: GatePass, verdict: ShellReadVerdict, ask: { readonly message: string; readonly account: string | undefined; readonly tightenedBy: "shell_gate" | "safety"; }): void;