@sema-agent/core
Version:
Stateless, task-oriented AI agent core
75 lines (74 loc) • 5.46 kB
TypeScript
/**
* The leg's write-protection MOUNT — one compile, and the loud outlet for the reading it could not get.
*
* The always-on write-protection judge re-judges a table-missing spelling on its RESOLVED real target,
* which needs a filesystem to resolve in. A deployment that wires no execution environment (a tool-only
* or MCP-only host) hands it none, so the spelling becomes the whole judgment and a covered write that
* reaches a protected row only through an alias is cleared. That verdict is the judge's documented
* absence law and is deliberately unchanged here: the announcement dialect applies (announce, do not
* refuse) — refusing every covered write instead would break exactly the deployments this shape exists
* for, and the reference implementation falls back to the same spelling-only set when resolution is
* unavailable. What this seat removes is the SILENCE.
*
* Two readers, one compile: the gate station mounts `check`, and the leg's wiring manifest reports
* `targetView`. Compiling twice would be two judges free to disagree about the seats they were handed.
*
* The SECOND absence this seat carries is the per-judgment one: a judge that HAS its target view but
* whose environment could not answer a particular target drops that view and judges by the spelling alone.
* That is a run-time fact, so it cannot be announced at compile like the one above — but it is a fact about
* the ENVIRONMENT rather than about any one write, so it is announced from here, once per leg per reason,
* and carries no call identity. This is the leg-scoped home the dedupe needs: the judge is compiled once
* per leg and every judgment of the leg goes through the check minted here.
*/
import type { ExecutionEnv } from "../../internal/harness.js";
import { unionAddOnly } from "../child-clamp-seats.js";
import type { RunnerDeps } from "../runner-deps.js";
import type { TaskSpec } from "../task-spec.js";
import type { ToolRoster } from "../tool-roster.js";
import type { ToolPolicy } from "../tool-policy.js";
import { type ExemptFile, type ManagedCheckoutView, type WriteProtectionMount } from "../write-protect.js";
import type { ShellReadBoundary } from "../../tools/fs/shell-read-judge.js";
/** The leg's write judgment, read by its two readers: the gate's tighten over the always-on table (`mount`, absent when that
* table is empty) and the shell station's ONE question about each write target a command names (`judgeWriteTarget`, over
* the table and the chain's guarded write rows together; absent when neither has a row). */
export interface LegWriteProtection {
readonly mount: WriteProtectionMount | undefined;
readonly judgeWriteTarget: ShellReadBoundary["writeTargetJudge"];
}
/** The leg's write-guard seats: its one exempt root (the leg's single resolution of `RunnerDeps.memoryEngineDir`, the same
* list every policy adjudication of the leg is stamped with), the chain policies' guarded write rows, and the leg's current
* managed tree (`checkout`, read per judgment off the leg's one write-location reader — the write judgment's current-tree
* reading, `WriteProtectionCompileOptions.checkoutOf`). */
export interface LegWriteGuard {
readonly exemptRoots: readonly string[];
/** The engine's own files the table does not demote — the session plan file as the advertised-writable seat admitted it
* (absent when none was declared). */
readonly exemptFiles?: readonly ExemptFile[];
readonly rows: ToolPolicy["writeGuardRows"];
readonly checkout?: () => ReadonlyArray<ManagedCheckoutView> | undefined;
}
/** The leg's always-on table: the deployment's whole-table seat (absent ⇒ the default table, `[]` ⇒ opted out) UNION the
* request's own rows. Read off deps and spec alone — the mount compiles it, and a leg's mount plan reads, before any
* environment exists, whether it has rows. */
export declare function legWriteProtectionTable(deps: Pick<RunnerDeps, "writeProtectedPaths">, spec: Pick<TaskSpec, "writeProtectedAdditions">): ReturnType<typeof unionAddOnly<"writeProtectedAdditions">>;
export declare function mountWriteProtection(input: {
/** borrowed-readonly — the deployment seats: the table (`writeProtectedPaths`; absent ⇒ the default
* table, `[]` ⇒ opted out) and the operator sink. */
deps: Pick<RunnerDeps, "writeProtectedPaths" | "onNotice" | "deploymentShape">;
/** borrowed-readonly — the leg's configuration roots (`leg-caller-places.ts`, the leg's one mint: the deployment's root, the
* task's, a resumed row's) — the `.sema` rows are also placed below each. */
configRoots: readonly string[];
/** borrowed-readonly — the leg's one exempt root and the chain's guarded write rows ({@link LegWriteGuard}). */
guard: LegWriteGuard;
/** borrowed-readonly — the request's own rows (already judged at the task layer's door). */
spec: Pick<TaskSpec, "writeProtectedAdditions">;
/** The HANDS' environment, or `undefined` with no hands — the driver's own predicate, not a second
* reading of the env seats, so the judge sees exactly the environment the write tools do. */
env: ExecutionEnv | undefined;
/** The base a `base: "root"` write tool's relative spelling resolves against. */
rootPath: string;
/** The leg's minted roster — what actually MOUNTED. */
roster: ToolRoster;
sessionId: string;
runId: string;
}): LegWriteProtection;