UNPKG

@sema-agent/core

Version:

Stateless, task-oriented AI agent core

58 lines (57 loc) • 3.4 kB
/** * The judged-read port's vocabulary (`ToolExecuteContext.judgedReads`): what a caller tool that declares a read target * (`ToolPathTarget`, `access: "read"`) is handed per call by the file read station — the one way it reads a file the model named. */ import type { FileError, FileKind, Result } from "../internal/harness.js"; /** * One target of a caller tool's declared read, as the file read station judged it for this call: the element's spelling, the * canonical key the station judged it at, and the one way the tool reads it. The port holds targets only once the station's * judgment of the WHOLE call has landed and let it through (no element refused; an outside one only when its question was * answered yes); a call whose judgment did not land is `not_judged`. `open` * judges the key again with the call's tables (the read-deny table, the roots — a target outside them only when the call's * question about it was answered yes — the read face), binds the object there (`openBound`) and judges the key once more, then * hands over the HELD object. It never resolves the spelling against a working directory that moved since the judgment. Refusals * are results, never throws: `permission_denied` (the judgment refuses), `not_supported` (this environment cannot hold the object — * the target is not read by name instead), `precondition_failed` (the key no longer names the object it named), any other code * the environment's own answer. */ export interface JudgedRead { readonly spelled: string; readonly key: string; open(signal?: AbortSignal): Promise<Result<JudgedFile, FileError>>; } /** The object a {@link JudgedRead} holds: every answer is about it or is a refusal. A directory lists only the entries the read-deny * table does not withhold (`omitted` counts the withheld ones). The tool closes it. */ export interface JudgedFile { readonly key: string; readonly identity: string; readonly kind: "file" | "directory"; size(): Promise<Result<number, FileError>>; /** The whole file, never more than `max` bytes (a larger file is refused, `invalid`). */ readBytes(max: number, signal?: AbortSignal): Promise<Result<Uint8Array, FileError>>; list(signal?: AbortSignal): Promise<Result<{ readonly entries: readonly { readonly name: string; readonly kind: FileKind; }[]; readonly omitted: number; readonly more: number; }, FileError>>; close(): Promise<void>; } /** * Why a call of a tool that declares a read target has no judged targets (CLOSED set): `no_read_station` — the leg mounts no file read * station (a leg with no workspace): nothing on it judges a read the model names; `not_judged` — the leg's station holds no * judgment of this whole call that let it through (a call that reached the tool without passing the gate; a judgment that does not answer before * the gate's deadline refuses the call, `read_unestablished`, and the tool does not run). Either way the tool reads nothing. The words as a * list: `JUDGED_READS_UNAVAILABLE`. */ export type JudgedReadsUnavailable = "no_read_station" | "not_judged"; /** `ToolExecuteContext.judgedReads`. */ export type JudgedReads = { readonly kind: "judged"; readonly targets: readonly JudgedRead[]; } | { readonly kind: "unavailable"; readonly reason: JudgedReadsUnavailable; };