UNPKG

@sema-agent/core

Version:

Stateless, task-oriented AI agent core

88 lines (87 loc) • 5.31 kB
/** The run's IN-FLIGHT read-root grant: the one place a screened grant ({@link ReadRootGrantScreen}) widens the read * directories (through the hands phase's {@link GrantReadRoot}, built by {@link readRootGrantOver}) — for the rest of * the session as a session rule written through the consent record, or for the rest of this run on the run's live * read set — the one composer of the two notices; the grant judges by the store-isolation rule ({@link rootAdmittingArtifactStore}). */ import type { ExecutionEnv } from "../../internal/harness.js"; import type { ReadRootGrantCandidate } from "../types.js"; import type { ReadRootGrantLasts, ReadRootGrantScreen } from "../read-root-grant-screen.js"; import { type RunnerDeps } from "../types.js"; /** The run's cell holding the local artifact store a granted root must never admit (its physical path, as the * Artifact phase resolved it): minted with the grant by the hands phase, written by the Artifact phase (the one * reader of the hosting seat) once the declaration validates. */ export interface ArtifactStoreRef { current: string | undefined; } /** Why the run's station applied no grant: the spelling did not resolve (or its lookup was cut), it no longer * resolves to itself (a directory swapped for a link while the card waited), or it would admit the local artifact * store (the store-isolation rule the Artifact phase judges its mount by). */ type GrantRefusal = "unresolvable" | "resolves_elsewhere" | "admits_artifact_store"; /** The card a grant answered, as the session rule's consent record names it. */ export interface GrantedCard { readonly toolCallId: string; readonly boundInputHash?: string; } /** The run's seat for one session read-root rule: `kept` — the run's one predicate (`PersonPathRows.sessionRowOwner`), read * where a card is minted — and `write`, through the consent record (`redeemSessionReadRoot`, which reads the predicate once * more, synchronously before it takes the writer). Absent on a run with no rule store. */ export interface SessionReadRootWriter { kept(): boolean; write(dir: string, card: GrantedCard, signal: AbortSignal): Promise<{ readonly landed: true; } | { readonly landed: false; readonly reason: string; readonly committed: "no" | "unknown"; }>; } /** What one granted candidate became: the directory held (`root`) and for how long (`lasts`) — `kept` says why a * session-long grant landed for the run only, `unconfirmed` that the session rule's write may have landed all the same — * or the station's refusal. */ export type GrantApplied = { ok: true; root: string; lasts: ReadRootGrantLasts; kept?: string; unconfirmed?: true; } | { ok: false; reason: GrantRefusal; cause: string; }; /** The hands phase's grant station. */ export interface GrantReadRoot { /** How long a grant of `candidate` can last on the card being minted now — the `lasts` it carries: `"session"` for a * directory while the run keeps session rules (read at this moment), `"run"` for one exact path or on any other run. */ lastsFor(candidate: ReadRootGrantCandidate): ReadRootGrantLasts; /** Apply one granted candidate for `lasts` (the card's own offer, as the resolver screened it): the offered spelling must * still be its own canonical form and must not admit the local artifact store; then a session-long grant is the session rule * (written once, through the consent record), and a grant for the run — or a session rule that was not written — ONE * deduplicated push onto the run's live read set. Nothing is applied once `signal` has fired (a late lookup never widens); * `onWriting` hears the moment a session rule's write begins, after which a cut cannot promise that nothing was kept. */ apply(candidate: ReadRootGrantCandidate, lasts: ReadRootGrantLasts, card: GrantedCard, signal: AbortSignal, onWriting?: () => void): Promise<GrantApplied>; } /** The hands phase's {@link GrantReadRoot} over the run's live root arrays: the two checks, then the session rule * (`session`) or ONE deduplicated push onto `readRoots` (the live read set every read face reads per call); the write roots * are only consulted for the dedup, never widened. */ export declare function readRootGrantOver(seats: { env: Pick<ExecutionEnv, "canonicalPath">; writeRoots: readonly string[]; readRoots: string[]; artifactStore: ArtifactStoreRef; session?: SessionReadRootWriter; }): GrantReadRoot; /** Act on one screened grant: `granted` widens through `grant` (absent on a station that cannot widen — an inherited * ask, a hands-less leg) and is announced; every other outcome changes nothing and is announced too — never silent. * Returns a promise ONLY while a grant is applied, so an answer with no grant costs no extra event-loop turn. */ export declare function settleReadRootGrant(screen: ReadRootGrantScreen | undefined, grant: GrantReadRoot | undefined, at: { toolName: string; toolCallId: string; checkpointId: string; sessionId: string; runId: string; taskId: string; onNotice: RunnerDeps["onNotice"]; signal?: AbortSignal; boundInputHash?: string; }): Promise<void> | undefined; export {};