@sema-agent/core
Version:
Stateless, task-oriented AI agent core
128 lines (127 loc) • 10.2 kB
TypeScript
/**
* The byte floor's one adapter: the read-deny table a call judges with, as the {@link ReadFloor} its command
* start carries to the environment the command runs in.
*
* One table, two readers. The shell read station judges what a command NAMES (its operands, its expansions, a
* recursive read's root — never the tree below a root, the zero-friction reading); the environment judges what a process
* OPENS. Both read the same rows through the same judgment: this module derives nothing — the rows are the ones the
* engine's refusals cite (`readDenySeat`) and the judgment is the table's own `matchPath`, read off the table the call
* is pinned to (`seatForCall`). A floor never loosens the station: what the station refuses never starts.
*
* The floor is the run's, never the start's: every start a table owner makes carries the floor its seat answers for that
* start — a call's own pinned table, else the owner's base table — whether or not the start's output reaches the model.
* A floor is pinned at the start ({@link readFloorSeat}) and carries the identity of the compiled table it stands on
* (`ReadFloor.id`, minted where the table is compiled): one id, one judgment.
*
* Whether the environment KEEPS the floor is its declaration (`capabilities.keepsReadFloor`), judged once per table
* owner by {@link judgeReadFloorKept}: a non-empty table on an environment that does not keep it is refused when the
* deployment requires the floor, and otherwise announced to the session's user when the caller brought rows of its own.
*/
import type { ExecutionEnv, ReadFloor } from "../../internal/harness-types.js";
import { type EngineNotice, type NoticeTold } from "../../core/engine-notice.js";
import { type NormalizedReadDenyEntry, type ReadDenyBuiltinConfig, type ReadDenyEntry, type ReadDenyMatcher } from "./read-deny.js";
/** The floor ONE command start carries, read at the start off the table it judges with — a tool call's own (`toolCallId`),
* else the owner's base table (`undefined`: a start that is no call's, such as a git bookkeeping command or a probe whose
* lines enter the prompt) — `undefined` when that table holds no row (an empty table keeps nothing, and the start then
* carries no floor: the options are the ones a start took before the floor existed). Throws when the table cannot be
* read now (a call's tables that failed to compile, the run's newest still compiling, a partition of the person's rows
* unread): the start is refused. */
export type ReadFloorSeat = (toolCallId: string | undefined) => ReadFloor | undefined;
/** The seat over a table owner's deny table (the run's, or a library-direct band's own); `undefined` for no table. Built
* once per owner; every start the owner makes reads its floor through it, at the start. */
export declare function readFloorSeat(table: ReadDenyMatcher | undefined): ReadFloorSeat | undefined;
/** The value gate of the floor requirement (`RunnerDeps.readDenyFloorRequired`, mirrored on `HandsToolkitOptions`), the one
* gate of every door that admits it: a boolean, or absent (`undefined`, read as "not required"); anything else refuses
* (`config.read_face_seat`), because a requirement that cannot be read is no requirement and must not read as one side. */
export declare function screenReadDenyFloorRequired(value: unknown, seat: string): boolean | undefined;
/** The code a non-empty read-deny table on an environment that does not keep the byte floor carries: the session user's notice
* (its audience row is `user`; told when the caller brought rows), and the prepare refusal when the deployment requires the
* floor — one fact, one word, two loudness dialects. */
export declare const READ_DENY_FLOOR_UNKEPT = "config.read_deny_floor_unkept";
/** The person's notice of {@link READ_DENY_FLOOR_UNKEPT}: one sentence (<= 240 characters) stating that files on the read-deny
* list can still be opened by recursive command reads here and who can change it (the deployment operator), with row counts and
* ids carried only in `detail` ({@link ReadFloorRows}). On macOS the engine's OS confinement keeps the floor where it applies. */
export declare function readDenyFloorUnkeptNotice(platform?: NodeJS.Platform): string;
/**
* The floor requirement's refusal, as ONE function of three facts: the environment the table's commands start in, whether the
* deployment requires the floor, and how many rows the table holds — every row, the deployment's own as well as the caller's
* ({@link ReadFloorRows}). A refusal (code {@link READ_DENY_FLOOR_UNKEPT}) when the floor is required, the table holds a row and
* the environment does not declare that it keeps the floor; `undefined` otherwise. Two doors ask it: the run's prepare with the
* table it compiled ({@link judgeReadFloorKept}), and the task-start doors with what the deployment's seats answer before a session
* is acquired — the environment known at assembly and the rows its seats hold as written. Rows only ever join a table, so the
* second door refuses only runs the first would; the sentence names no count so the two say it alike.
*/
export declare function readDenyFloorRefusal(facts: {
readonly env: Pick<ExecutionEnv, "capabilities">;
readonly required: boolean;
readonly rows: number;
}): (Error & {
code: string;
}) | undefined;
/**
* The rows of one judged table by whose they are. A row is the DEPLOYMENT's when the owner's deployment seats name it on their
* own — the active built-in tiers and the deployment's patterns ({@link deploymentReadDenyEntries}), compared as the table folds
* its entries (pattern and case); every other row is the CALLER's: the request's patterns, a resumed row's pattern the deployment
* no longer names, the deny permission rules, the person's rules. A row both name is the deployment's (it stands without the
* caller). Each row is of exactly one kind, so `rowCount` — the table's authoritative count, the rows its refusals cite — is
* their sum.
*/
export interface ReadFloorRows {
readonly rowCount: number;
readonly callerRowCount: number;
readonly deploymentRowCount: number;
}
/** The segment rows a table owner's deployment seats name on their own, normalized by the table's one compiler: the active
* built-in tiers (`builtin`, the deployment's configuration of them) and the deployment's patterns. Bad values throw as the
* table's own compile does. */
export declare function deploymentReadDenyEntries(patterns: readonly ReadDenyEntry[] | undefined, builtin: ReadDenyBuiltinConfig | undefined): readonly NormalizedReadDenyEntry[];
/** What {@link judgeReadFloorKept} is handed: the table's owner states the environment, its table, the floor its own engine
* starts carry off that table (the base table's), whether the deployment requires the floor, and the rows its deployment
* names ({@link deploymentReadDenyEntries}). */
export interface ReadFloorJudgment {
readonly env: Pick<ExecutionEnv, "capabilities">;
readonly table: ReadDenyMatcher | undefined;
readonly floor: ReadFloor | undefined;
readonly required: boolean;
/** The segment rows the owner's deployment seats name ({@link ReadFloorRows}); `[]` = every row of the table is the caller's. */
readonly deployment: readonly NormalizedReadDenyEntry[];
readonly onNotice: ((notice: EngineNotice) => void) | undefined;
/** The run the judgment is for, carried on the notice (a library-direct band has none). */
readonly attribution?: {
readonly sessionId?: string;
readonly runId?: string;
};
/** The owner's session's told record (a run's: every table it compiles, and every later run of the session): the notice is
* told once per session, by the delivery throat; a refusal is never recorded. Absent ⇒ every judgment says it. */
readonly told?: NoticeTold;
}
/**
* The ONE judgment of whether a table owner's byte floor is kept, taken where the table is compiled: the Runner's prepare
* for a run (each delegated child on its own environment), a library-direct hand band for the table it compiles itself —
* never a band handed the Runner's face. Judged on the table's AUTHORITATIVE row count, the rows its refusals cite:
* · no row ⇒ nothing to keep, no judgment;
* · rows, and no floor for the owner's engine starts to carry ⇒ an engine defect, refused loudly (the starts would run with
* fewer rows than the table holds);
* · rows, on an environment that declares it keeps the floor ⇒ nothing to say;
* · rows, on one that does not: `required` ⇒ refused with {@link READ_DENY_FLOOR_UNKEPT} (every row counts, the deployment's
* own too); otherwise, when the CALLER brought rows ({@link ReadFloorRows}), that word as a `user`-audience notice (once per
* session where the owner has a told record) — a recursive read under a root still reads the rows below it there, so the
* notice is no protection. Rows that are all the deployment's are the deployment's to hear (its own lines and logs), not the
* session user's: no notice, and nothing recorded as told.
*
* Answers the table's rows when the floor is unkept for it (the last arm, said, already told or not the user's to hear), else
* `false`: the owner's record of the fact for its own run, which the notice — told once per session — is not.
*/
export declare function judgeReadFloorKept(j: ReadFloorJudgment): ReadFloorRows | false;
/** A leg's latch over the judgments of every table it compiles: the unkept judgment with the most caller rows (the later on a
* tie), so a record that counts caller rows is one whose leg met the notice's condition. Never turns back to `false`. */
export declare function latchReadFloor(held: ReadFloorRows | false, judged: ReadFloorRows | false): ReadFloorRows | false;
/** The result's seat of an unkept floor (`TaskResult.readDenyFloor`) off a leg's latch, to spread: no member when the floor was kept. */
export declare function readDenyFloorSeat(latch: ReadFloorRows | false | undefined): {
readDenyFloor?: {
kept: false;
rowCount: number;
callerRowCount: number;
deploymentRowCount: number;
};
};