UNPKG

@sema-agent/core

Version:

Stateless, task-oriented AI agent core

97 lines (96 loc) • 6.51 kB
import type { ExecutionEnv } from "../internal/harness.js"; import { type PersistedRule } from "./permission-rule-model.js"; import type { SessionCallGrantOffer } from "./session-call-grant-screen.js"; /** The match word of a call grant row — a member of `PERSISTED_RULE_MATCHES`. */ export declare const CALL_GRANT_MATCH: "call"; /** One resolved program file, by the four members a later call must meet again. */ export interface CallGrantProgram { readonly path: string; readonly id: string; readonly size: number; readonly mtimeMs: number; } /** One segment of a bound call. */ export interface CallGrantSegment { /** The canonical directory the segment runs in. */ readonly at: string; readonly program: CallGrantProgram | { readonly builtin: string; }; /** An interpreter's script: its canonical path, its bytes' digest, and the digest of the interpreter's source files in its directory tree. */ readonly script?: { readonly path: string; readonly sha256: string; readonly tree: string; }; /** An inline-code word's digest (`node -e <code>`): display and identity both — the text form already binds the word. */ readonly inline?: string; /** The canonical path of each file redirection target, in source order. */ readonly writes: readonly string[]; } /** The binding a call grant row carries as its `command`: the canonical JSON (sorted keys, no white space) of this shape, `v: 1`. * A CONTRACT, so a reader that cannot call this package at run time can read a listed row: these keys and no others, every path * absolute, every digest 64 lowercase hex digits ({@link readCallGrantBinding} is the engine's own reading of it, and * {@link sessionCallGrantOfRow} projects it onto the card's members). A later version changes `v`. */ export interface CallGrantBinding { readonly v: 1; /** The canonical directory the call starts in. */ readonly cwd: string; /** `text`: `digest` is the folded command's; `argv`: the single run's words, the holes masked. */ readonly form: "text" | "argv"; readonly digest: string; readonly segments: readonly CallGrantSegment[]; /** Word positions (of the single run) that may name another file, each inside its directory. Empty in the `text` form. */ readonly holes: readonly { readonly at: number; readonly dir: string; }[]; } /** The environment and places one reading takes. `env` is read live (its declared members are getters on some backends). */ export interface CallBindingSeat { /** The shell that runs the call's text (the leg's start): a text another shell runs is never read as a whole, so it binds nothing. */ readonly shell: import("../shell/lex.js").StartedShell; readonly env: Pick<ExecutionEnv, "canonicalPath" | "fileInfo" | "readBinaryFile" | "listDir" | "cdPath"> & { readonly fileIdentity?: ExecutionEnv["fileIdentity"]; readonly readLink?: ExecutionEnv["readLink"]; readonly searchPath?: ExecutionEnv["searchPath"]; readonly receivedEnvNames?: ExecutionEnv["receivedEnvNames"]; readonly configuredStartupFileNames?: ExecutionEnv["configuredStartupFileNames"]; }; /** The call's working directory (the run's live tracked one). */ readonly cwd: string | undefined; /** The run's workspace roots (canonical): a script, and an operand hole's file, must lie inside one. */ readonly roots: readonly string[]; } /** The canonical text of a binding — what a row stores as its `command`. */ export declare function callGrantCommandOf(binding: CallGrantBinding): string; /** The rule text of a call grant row (its identity in the session): the digest of its binding. */ export declare function callGrantRuleTextOf(command: string): string; type Unbindable = { readonly unbindable: string; }; /** The binding a person's grant of this call would store, or why the call has none. */ export declare function bindCall(command: unknown, seat: CallBindingSeat, signal?: AbortSignal): Promise<CallGrantBinding | Unbindable>; /** Does a stored binding admit this call — the same reading of it, member for member, each hole's file inside its directory? * A reading that fails is no admission (the call is then judged as if the grant were not there), never an error. */ export declare function callGrantAdmits(binding: CallGrantBinding, command: unknown, seat: CallBindingSeat, signal?: AbortSignal): Promise<boolean>; /** The person's lane's one use of call grant rows: the first row of `rows` that is an allow of the call, under one of its granting * command words (`words`), of THIS session, whose stored binding reads and whose text is that binding's digest, and that `judge` * says meets this command now. Each row is judged on its own; one that cannot be judged admits nothing. No judge ⇒ none. */ export declare function callGrantRowAdmitting(rows: readonly PersistedRule[], call: { readonly words: readonly string[]; readonly sessionId: string | undefined; readonly command: unknown; readonly judge: ((binding: CallGrantBinding, command: string) => Promise<boolean>) | undefined; }): Promise<PersistedRule | undefined>; /** The binding a stored `command` spells — `undefined` for anything that is not one (its canonical text, every member well-formed). */ export declare function readCallGrantBinding(command: unknown): CallGrantBinding | undefined; /** The store's re-projection of a call grant row: an allow of the shell tool, in a session scope, whose command is a binding's * canonical text and whose text is that command's digest. Anything else is damage (refused, never repaired). */ export declare function callGrantRowFault(r: Pick<PersistedRule, "behavior" | "rule" | "tool" | "match" | "command" | "scope">): "invalid_rule_text" | "metadata_mismatch" | undefined; /** The option a binding offers (`session-call-grant-screen.ts` holds the card's half: the option's shape and the answer's screen). */ export declare function offerOfBinding(b: CallGrantBinding): SessionCallGrantOffer; /** The card's members for a listed session row (`effective({ sessionId }).rules`) — the same projection of the same binding, so a * rule page shows what the card showed. `undefined` for a row that is no call grant (or one whose binding does not read). */ export declare function sessionCallGrantOfRow(row: Pick<PersistedRule, "match" | "rule" | "command">): SessionCallGrantOffer | undefined; export {};