@sema-agent/core
Version:
Stateless, task-oriented AI agent core
508 lines (507 loc) • 41.3 kB
TypeScript
import type { EditRewritten } from "./rewrite-rejudge.js";
import { type RetiredNameView } from "./tool-name-aliases.js";
import type { ToolCallRequest, ToolIdentity } from "./tool-policy.js";
import { type AllowListGrant, type AllowRuleMember, type AllowRuleShadow, type AllowRuleShadowReason } from "./allow-rule-shadow.js";
import { type RuleToolNameVerdict } from "@sema-agent/primitives";
import { type AdmissionPosture, type PathRuleBases, type PersistedRule } from "./permission-rule-model.js";
import { type AutoStripReason, type AutoStripRowReason } from "./auto-strip.js";
import { type AskClass, type AssertAllKeysHandled, type PermissionMode, type PersistedRuleMandate } from "./ask-origin.js";
import { type ToolNameListReading } from "./tool-name-list.js";
import { type EngineNotice } from "./engine-notice.js";
/** Why an entry grants (or refuses) nothing — the closed set the start-of-run notice names, for every list. `tool_name`: the
* entry's tool name is one the name judgment reads as stale against the run's roster (`verdict` says which); `near_miss`: the
* run mounts no tool of that exact name but mounts one that differs only by case (`currentName` is its spelling);
* `earlier_grammar`: a session's stored rules are written in an earlier rule grammar, in which the entry named no tool, or which
* read an entry this grammar reads as no rule (the session store's list reading, `compileSessionRuleBucket` — this reader never
* answers it). */
export declare const ALLOW_ENTRY_INERT_REASONS: readonly ["wildcard_all", "namespace_wildcard", "content_unsupported", "grammar", "tool_name", "near_miss", "earlier_grammar"];
export type AllowEntryInertReason = (typeof ALLOW_ENTRY_INERT_REASONS)[number];
/** The facts beside a reason: for `tool_name` / `near_miss` the judgment's word, the judgment's own one-line sentence when it has
* one (`guidance`, byte for byte — `retired` and `unmintable_segment` carry one, `unprefixed_namespace` none) and the spelling to
* write instead when there is one; for a list member that is not a string (`grammar`) the TYPE of the value (`a number`, `null`,
* `an object`…) — `entry` then holds {@link nonStringMemberLabel}, never the value. */
export interface AllowEntryInertDetail {
readonly verdict?: Exclude<RuleToolNameVerdict["kind"], "current">;
readonly guidance?: string;
readonly currentName?: string;
/** `tool_name` / `unmintable_segment` only: the refusal is the ALLOW-side ambiguity of an MCP name ({@link peerReadingsOf}), not a segment the mint never produces. */
readonly ambiguous?: true;
readonly valueType?: string;
/** Where the spelling of a `near_miss` comes from, when the station that read it reads more than the run's roster
* ({@link NearMissCarrier}); absent ⇒ the roster the run mounts. A sentence only — never a field of a wire detail. */
readonly carriedBy?: NearMissCarrier;
}
/** Who carries the spelling a near miss reads as another spelling of: the roster the run mounts, a delegation tool's pool, or
* only the engine's tool catalog (a tool the engine may mount, which this run's roster does not carry). */
export type NearMissCarrier = "run" | "pool" | "catalog";
/**
* How a list member that is not a string is named wherever a list's entries are named (the inert record's `entry`, the Skill
* card's binding): its TYPE, in a spelling no readable entry can have — a readable entry's name holds no whitespace and a
* name-only entry holds no parenthesis, and this label holds a space and none. It can equal only another entry that reads as
* nothing, so a binding that holds it never stands for an entry that grants or refuses.
*/
export declare function nonStringMemberLabel(value: unknown): string;
/** How a tool-name list's VALUE that is not a list stands as one entry (the same kind of spelling as {@link nonStringMemberLabel}: it
* reads as `grammar`): its TYPE, or that its entries could not be read — never the value. */
export declare function nonListValueLabel(read: Exclude<ToolNameListReading, {
kind: "entries";
}>): string;
/** One entry a list reads as nothing. */
export type AllowEntryInert = {
readonly entry: string;
readonly reason: AllowEntryInertReason;
} & AllowEntryInertDetail;
/**
* Does the reader read this entry as a tool the engine retired with NO successor (`removed` / `folded`: no `currentName`)? Such a name reaches no
* tool in any roster, now or later, and never did anything a rewrite could restore — so a RESTRICTING list (a task's tool-name list, a skill's
* `disallowed-tools`) leaves it out and says so in the retired-name notice instead of refusing; a name that was RENAMED has a successor, the
* entry guarded a tool that is still mounted, and stays refused. So does a name whose tool the roster carries under ANOTHER CASE (`TEAMCREATE`
* beside `TeamCreate`: the entry was written for that tool — the policy audit asks the same question): `roster` is the one the reader read
* the entry against; absent, no tool is known to be mounted. The one question the engine's tables put to the one reader's answer.
*/
export declare function isRetiredLeftOut(e: Pick<AllowEntryInert, "entry" | "reason" | "verdict" | "currentName">, roster: ReadonlySet<string> | undefined): boolean;
/** One entry the grammar reads (kind closed): a whole non-shell tool; a covering spelling — a set of tool names
* ({@link isCoveringRuleName}: a protocol peer, a glob over a protocol name's tool segment, and on a deny list a `*` anywhere in
* the name, `*` alone every tool); the whole shell tool; and one kind per rule grammar (`ruleToolGrammarOf`) — a shell command
* rule, a path rule, a name rule, a host rule — each the row the persisted grammar parses, its `behavior` the list's direction. */
export type CompiledAllowEntry = {
readonly kind: "tool";
readonly name: string;
} | {
readonly kind: "covering";
readonly pattern: string;
} | {
readonly kind: "shell";
readonly name: string;
} | {
readonly kind: "command";
readonly rule: PersistedRule;
} | {
readonly kind: "path";
readonly rule: PersistedRule;
} | {
readonly kind: "name";
readonly rule: PersistedRule;
} | {
readonly kind: "domain";
readonly rule: PersistedRule;
};
/**
* THE universe a ROOT-facing tool-name list is read against: every name the engine's catalog carries, and the names the reader knows
* are carried (`carried`). A list is root-facing when it bounds the tools of the run that holds it — the run's own `allowTools` /
* `excludeTools` (also the ceiling of its children), a tool policy's name lists, a session's stored rules — and its reader is that
* run (`carried`: its roster, the caller's own tools, and the exact names of the pools its reachable delegation tools declare and can
* list) or the store that writes the rules (`carried`: the tools its deployment declared). Another spelling of a carried name is
* always refused there, whatever a delegation tool injects per spawn: the run's own tools are known, and an entry that is a case
* twin of one of them names the other tool by mistake. A delegation tool's pool that cannot be listed carries nothing here.
*/
export declare function rootFacingToolNames(carried: Iterable<string>): Set<string>;
/** What one rule entry means under one direction ({@link readRuleEntry}): the row the grammar compiles it to, or the reason it
* reads as nothing with the facts a sentence about it names. */
export type RuleEntryReading = {
readonly kind: "row";
readonly compiled: CompiledAllowEntry;
} | ({
readonly kind: "inert";
readonly reason: AllowEntryInertReason;
} & AllowEntryInertDetail);
/**
* THE ONE READER of a rule entry — a member of an entry list in either direction: a skill's `allowed-tools` /
* `disallowed-tools`, a sub-agent's deny list, the request's and the deployment's `allowedTools`, a session's `toolDeny` /
* `toolAllow`. Every station that compiles, validates, compares or names such an entry reads this answer and no other.
* `roster` = the tool names the reader knows are mounted (aliases included): given, the entry's tool name is also read against
* it (a stale name, or one that differs from a mounted tool's only by case, reads as `tool_name` / `near_miss`); absent, the
* grammar alone is read — what a resume's pre-claim screen can read before the leg has a roster. `retiredNames` = the view of the
* leg the entry is read for (`legRetiredNameView`, computed once at its start; a store, which sees no leg, hands the view of its
* own roster): the ONE answer to whether a retired name reads as its successor — the roster never answers it. Absent, a retired
* name reads as written.
*/
export declare function readRuleEntry(raw: unknown, behavior: "allow" | "deny", roster?: ReadonlySet<string>, retiredNames?: RetiredNameView): RuleEntryReading;
/** The tool name a compiled entry speaks for — its tool, its covering spelling, or its rule's tool (what a name audit reads). */
export declare function compiledEntryName(compiled: CompiledAllowEntry): string;
/**
* Compile one list through {@link readRuleEntry}, entry by entry: the entries it reads and the ones it reads as nothing (each
* with its reason and, for a name the roster refuses, the judgment's word and the spelling to write). No entry changes how
* another is read: a `*` on an allow list grants nothing by itself (`wildcard_all`) and the entries beside it keep their
* reading; on a deny list it refuses every tool. `roster` and `retiredNames` as in {@link readRuleEntry}.
*/
export declare function compileAllowList(entries: readonly string[], behavior: "allow" | "deny", roster?: ReadonlySet<string>, retiredNames?: RetiredNameView): {
rows: Array<{
entry: string;
compiled: CompiledAllowEntry;
}>;
inert: AllowEntryInert[];
};
/**
* Does auto mode strip this allow entry for this call, and why (the one judgment, `auto-strip.ts`)? Read for every rule-shaped
* member — a list entry, and a person's stored row through {@link autoStrippedRule}; a hook's allow is not an entry and is never
* stripped. A stripped entry takes no part in the match (the reference removes it before matching), so it neither clears nor is
* disclosed as a match. The call's one fact the judgment reads: does it answer to the shell under any of its names. `undefined` ⇒ kept.
*/
export declare function autoStripReasonOf(compiled: CompiledAllowEntry, call: ToolCallRequest | undefined, allShell: boolean): AutoStripReason | undefined;
/** Is the entry stripped for the call ({@link autoStripReasonOf} answers a reason)? */
export declare function autoStripped(compiled: CompiledAllowEntry, call: ToolCallRequest | undefined, allShell: boolean): boolean;
/** THE strip as every allow member reads it, per call: only in `auto`, and then {@link autoStripped} under the leg's
* `classifyAllShell` declaration. The one place the mode is compared for the strip. */
export declare function strippedInAuto(compiled: CompiledAllowEntry, call: ToolCallRequest | undefined, mode: PermissionMode | undefined, allShell: boolean): boolean;
/** {@link autoStripReasonOf} over a person's stored ALLOW row in `mode`, read as its list twin ({@link entryOfRow}): a row is stripped
* exactly when the entry spelling the same rule is (a deny / ask row never is; a row no grammar reads has no twin and is not stripped
* here — the lane reads no allow it cannot parse). `undefined` ⇒ kept. */
export declare function autoStripReasonOfRow(rule: PersistedRule, call: ToolCallRequest, mode: PermissionMode | undefined, allShell: boolean): AutoStripReason | undefined;
/** Is the stored row stripped for the call ({@link autoStripReasonOfRow} answers a reason)? */
export declare function autoStrippedRule(rule: PersistedRule, call: ToolCallRequest, mode: PermissionMode | undefined, allShell: boolean): boolean;
/**
* The strip's reading of an allow-list entry judged WITHOUT a run — the reading a rule read face carries (`readFaceAutoStrip`): the
* entry read in the allow direction by the one reader ({@link readRuleEntry}; one that reads as nothing has no reading), no call (so
* a tool that answers to the shell under another name is not seen) and no leg declaration (so `classify_all_shell` is never the
* answer). `undefined` ⇒ auto mode uses the entry as written for a call of its own tool. A host marks a rule a person wrote (a
* settings `permissions.allow` entry) with it; a stored row carries the same reading as `EffectivePermissionRule.autoStrip`.
*/
export declare function allowEntryAutoStrip(entry: string): AutoStripRowReason | undefined;
/** Does the leg's spec declare that every shell entry is the classifier's in `auto` — the one reading of
* `TaskSpec.classifyAllShell` (its value is screened at the door: present ⇒ a boolean). */
export declare function classifiesAllShell(spec: {
readonly classifyAllShell?: boolean;
}): boolean;
/** One row a list matcher reads. `pathBases`: the anchors the row's RULE SET declares ({@link AllowListEntry}) — absent, the set
* declares none and its path rule reads at the list's installation ({@link AllowEntryJudgeContext.anchors}). */
export interface AllowEntryRow {
readonly behavior: "allow" | "deny";
readonly entry: string;
readonly compiled: CompiledAllowEntry;
readonly pathBases?: PathRuleBases;
/** A list member's identity stamp and provenance ({@link AllowListEntry}), as written; absent on every other row. */
readonly peerFingerprint?: string;
readonly grant?: AllowListGrant;
}
/** The facts a list's content row is judged under: the leg's root and session (which rows apply), the live working
* directory (where a command's `cd` lands), and the ANCHORS of the list's path rows — the leg the list was installed
* on (its root and environment home), which a row's own set declaration overrides word by word (`policyAnchors`, the one
* reading a deny / ask rule set's `pathBases` takes): a path row of a list never moves with a `cd`. `classifyAllShell`: the leg's
* declaration ({@link classifiesAllShell}) the auto strip reads ({@link strippedInAuto}); absent ⇒ the leg declared nothing. */
export interface AllowEntryJudgeContext {
readonly root: string | undefined;
readonly sessionId: string | undefined;
readonly liveCwd: () => string | undefined;
readonly anchors: PathRuleBases;
readonly classifyAllShell?: boolean;
/** Hears each entry of the list the strip took from a call that entry speaks for ({@link allowingRows}): the entry as written,
* the reason, the skill whose list held it (a skill's lane), and the call. Absent ⇒ nobody is told. */
readonly onAutoStripped?: (stripped: {
readonly entry: string;
readonly reason: AutoStripReason;
readonly skill?: string;
}, call: ToolCallRequest) => void;
}
/** Which of the call's names a list's NAME rows (a whole tool, a covering spelling) read: every name it answers to — a person's,
* a skill's or a session's list (the name written reaches the tool that answers to it, the reference's proxy expansion) — or the
* wire name alone: a list handed in at launch ({@link AllowEntryTable}, the reference's CLI-argument source, which it does not
* expand through an alias). */
export type ListNameReach = "every_name" | "wire_name";
/** For a list whose allow rows admitted no call ({@link judgeAllowEntries}): the first segment of the call's command no command
* row covers under `posture` — the word a refusal names; `undefined` when the call carries no command or no single segment is
* to blame (a line the matcher cannot read at all). The same walk the matcher took. */
export declare function uncoveredCommandSegment(rows: readonly AllowEntryRow[], req: ToolCallRequest, ctx: AllowEntryJudgeContext, posture: AdmissionPosture): string | undefined;
/** The list's first `behavior` row that names the tool WHOLE (a tool name, a covering spelling) and so speaks for every call of
* it, whatever the call carries — the list matcher's first step ({@link judgeAllowEntries}), and the whole-tool reading of a
* deny list (the model's tool table leaves such a tool out). */
export declare function wholeToolEntryOf<R extends AllowEntryRow>(rows: readonly R[], tool: ToolIdentity, behavior: "allow" | "deny", names?: ListNameReach): R | undefined;
/**
* The ONE list matcher, both directions — the rows that speak for the call, or undefined. A tool-name row first (the first
* that reaches the call); then the content rows, each family by the predicate the stored rows of that grammar meet:
* COMMAND — allow: the persisted allow matcher's coverage under the list's {@link AdmissionPosture} (the whole command, or each
* segment covered by a row — or, for a `grant` list, read-only by itself); deny: a row whose program run the call performs (the
* wide tightening reading; a call that cannot be read against the row is refused too). PATH — the persisted path adjudication
* (allow: the narrow reading, every view of the target inside what the row names; deny: any view reaching it). NAME / DOMAIN —
* the one predicate of each (the name the call names, the host it reaches — a deny row read on the protective reading, an allow
* row on the tool's own declared slot, `callHostTargetOf`; a mounted name tool's value resolved against the agent types the call's
* face carries, `nameRuleReach`); a closed-set tool's call naming no value is refused by a deny list's row of the tool and granted
* by no allow row (the persisted walk's reading, `nameValueAbsentReason`), a mounted tool's call whose face carries no values is
* refused by a deny list's row of the tool and granted by no allow row, and a call whose host cannot be read is refused by a deny
* list's host row and granted by no allow row (`adjudicatePersistedDomainRules`). A content row reaches the call under the words
* of its direction ({@link ruleWordsOf}: a deny under every name the call answers to, an allow under its wire name); a name row
* under the list's `names` ({@link ListNameReach}).
*/
export declare function judgeAllowEntries<R extends AllowEntryRow>(rows: readonly R[], req: ToolCallRequest, behavior: "allow" | "deny", ctx: AllowEntryJudgeContext, posture?: AdmissionPosture, names?: ListNameReach): readonly R[] | undefined;
/** The allow rows of a list, as the allow layer reads them in `mode`: the strip applied BEFORE the match (in `auto`). `told` hears
* each stripped row the call's judgment would have read (under the list's `names`), with its reason. */
export declare function allowingRows<R extends AllowEntryRow>(rows: readonly R[], req: ToolCallRequest, mode: PermissionMode | undefined, allShell: boolean, told?: (row: R, reason: AutoStripReason) => void, names?: ListNameReach): readonly R[];
/** The two sources {@link AllowEntryTable} holds (a skill's list is the skill table's). */
export type AllowEntrySource = "request" | "deployment";
/**
* One member of an allow list handed in at launch (`TaskSpec.allowedTools`, `RunnerDeps.allowedTools`): a rule — or a rule with
* the ANCHORS of the rule SET it belongs to, `pathBases`, the seat a deny / ask rule set declares
* (`PermissionRulePolicyOptions.pathBases`), read the same one way: each word the set declares, else the leg the list is installed
* on (`policyAnchors`). The members that declare the same anchors are one set — one settings layer's rules: `root` = that layer's
* root (the configuration directory for a user layer, the task root for a project or local layer) and `cwd` = the task root, so
* a user layer's `Read(/x)` allow reaches `<config>/x` and not `<task>/x`. A string declares nothing: its path rule reads at the
* anchors the list is installed with, as handed, as it always did — and a member that declares nothing is written as that
* string (an empty `pathBases` is refused). The anchors speak to a path rule only (a rule that names no path reads none of them).
*
* Two more optional members, written by whoever puts the entry on the list and read as written: `peerFingerprint` — the identity stamp
* of the A2A peer the entry grants, as its registration carried it when the grant was given (`A2aServerSpec.fingerprint`); an inside
* peer's question is cleared only by an entry bound to the stamp its registration carries now (`a2a-bound-grant.ts`) — and `grant`, who
* put it there ({@link AllowListGrant}), carried onto the clearance. An object member carries at least one of its three optional members.
*/
export type AllowListEntry = string | AllowListMember;
/** An allow list's object member ({@link AllowListEntry}). */
export interface AllowListMember {
readonly rule: string;
readonly pathBases?: PathRuleBases;
readonly peerFingerprint?: string;
readonly grant?: AllowListGrant;
}
/** One matched entry's binding: the entry as the list spells it, the identity stamp and provenance it carries, and — for an entry of the
* list the run received — its indices in that list. */
export interface AllowEntryBound {
readonly entry: string;
readonly peerFingerprint?: string;
readonly grant?: AllowListGrant;
readonly positions?: readonly number[];
}
/** What spoke for a call: the entries it stands on, as the list spells them, and — for entries of the list the run received —
* the index of every element of that list that is one of them (a string listed twice has both). `bound`: every entry of the list that
* reaches the call and carries a stamp or a provenance ({@link AllowEntryBound}), in list order — beside the ones `entries` names, since
* a whole-tool answer names only its first row; an entry not there carries neither (absent ⇒ none does — a host's own lane that never
* binds answers without it). */
export interface AllowEntryHit {
readonly entries: readonly string[];
readonly positions?: readonly number[];
readonly bound?: readonly AllowEntryBound[];
}
/** The face the gate reads one entry list through. */
export interface AllowEntryLane {
/** The allow layer's member: what grants this call in this mode, or undefined. */
allowing(req: ToolCallRequest, mode: PermissionMode | undefined): AllowEntryHit | undefined;
}
/** The gate inputs the two entry lists ride (a member group of `ToolGateInput`). Each is the allow layer's member for its
* source — read under the one consumption predicate beside a person's stored rows and a skill's list, clearing only what an
* allow rule may clear — with its attribution sink (`onAllowed` observes a call it cleared; never affects the outcome).
* Absent ⇒ that source has no rows. */
export interface AllowEntryGateSeats {
deploymentAllows?: AllowEntryLane & {
onAllowed?: (info: {
toolName: string;
toolCallId: string;
entries: readonly string[];
}) => void;
};
requestAllows?: AllowEntryLane & {
onAllowed?: (info: {
toolName: string;
toolCallId: string;
entries: readonly string[];
}) => void;
};
}
/**
* One source's allow rows, compiled once: the request's (prepare seeds it from the spec's snapshot and, in a delegated
* child, from the parent's capture) or the deployment's (compiled from the Runner's snapshot). Allow rows only — neither
* list has a deny side. Identity is the contract: prepare seeds it, the delegation capture and the gate's lane read it.
*/
export declare class AllowEntryTable {
private held;
/** The member key of every held row ({@link allowListMemberKey}: a rule and the anchors of its set). */
private readonly heldKeys;
/** Each member of the list the run RECEIVED for this source, by member key, with its indices in that list — what a hit's
* `positions` read. */
private receivedAt;
/** Write a list's rows (a member already held — the same rule in the same set — is not held twice). Returns the entries that
* read as nothing. `roster` as in {@link readRuleEntry}: a list the leg itself wrote is read against it, a carried one (a
* delegating parent's capture) is not. `received`: this list is the one the run received for the source (the request's
* `TaskSpec.allowedTools`, the deployment's `RunnerDeps.allowedTools`), the list a hit's positions are read in; a carried
* capture is not. `retiredNames`: the leg's view ({@link readRuleEntry}) — every list the leg holds, a carried one included,
* reads a retired name as the leg reads it. */
seed(entries: readonly AllowListEntry[], reading?: {
readonly roster?: ReadonlySet<string>;
readonly received?: true;
readonly retiredNames?: RetiredNameView;
}): readonly AllowEntryInert[];
/** The members held, as written (a copy) — what a delegated child is handed: a rule, with its set's anchors, its stamp and its
* provenance where the member carried them (the child reads its path rule at the same anchors, and its binding the same way). */
entries(): readonly AllowListEntry[];
/** Does the table hold a path row — must the leg read each call's target views for it? */
holdsPathRows(): boolean;
/** The lane over this table, bound to the leg's call facts. Both sources are lists handed in at launch: every row reaches the
* call under its wire name ({@link ListNameReach} `wire_name`). */
lane(ctx: AllowEntryJudgeContext): AllowEntryLane;
}
/**
* Seed one leg's request and deployment tables — a delegated child's captured request entries first (an entry that reads as
* nothing was announced where it was written, and is read without the roster for the same reason), then the leg's own list
* against `roster`; the deployment's grammar reading is announced once, at construction, so only its name readings
* (`tool_name`, `near_miss` — facts about THIS leg's roster) are announced here — and return the dead entries of the leg's
* OWN lists, the skills' beside the request's, for its one start-of-run notice. All three read a retired name under the leg's
* one view (`retiredNames`), the view its policies are matched under.
*/
export declare function seedAllowEntryTables(tables: {
readonly request: AllowEntryTable;
readonly deployment: AllowEntryTable;
}, lists: {
skillInert: ReadonlyArray<{
skill: string;
list: "allowed-tools" | "disallowed-tools";
} & AllowEntryInert>;
inherited: readonly AllowListEntry[] | undefined;
request: readonly AllowListEntry[] | undefined;
deployment: readonly AllowListEntry[] | undefined;
}, roster: ReadonlySet<string>, retiredNames: RetiredNameView): AllowEntryInertNote[];
/** The deployment's allow rules, read ONCE at construction: screened (a value that is not a list of strings refuses), frozen,
* and its dead entries announced once (no session). Returns the deps with the snapshot in place of the caller's list. */
export declare function withDeploymentAllowedTools<D extends {
readonly allowedTools?: readonly AllowListEntry[];
readonly onNotice?: ((n: EngineNotice) => void) | undefined;
}>(deps: D): D;
/** The code a list value that is not a list of strings refuses with — the policy compiler's family, with its issues. */
export declare const INVALID_PERMISSION_RULES_CODE = "config.invalid_permission_rules";
/** The two seats an allow list is handed over at — the library coordinates the refusal carries as `libraryOption`, each with the
* words the sentence says instead. */
declare const ALLOW_LIST_SEATS: {
readonly "TaskSpec.allowedTools": "the request's allow list";
readonly "RunnerDeps.allowedTools": "the deployment's allow list";
};
type AllowedToolsSeat = keyof typeof ALLOW_LIST_SEATS;
/**
* Screen and snapshot one `allowedTools` value (`seat` is the seat it was handed at; the sentence says it in words, the issues'
* `libraryOption` names it): absent ⇒ undefined; a list of {@link AllowListEntry} members ⇒ a frozen copy (the one read every
* later reader takes). Refused loudly, never dropped and never read as "no entries": a value that is not a list, or a member that
* is neither a string nor an object, with {@link INVALID_PERMISSION_RULES_CODE} and an issue per defect; an anchored member that
* cannot be received ({@link receiveAnchoredMember}) with `config.invalid_argument`; an anchored path rule whose set declares a
* base it cannot be read at — a relative spelling, one of no tree's family — with the code and issue (`unsupported.path_base`) a
* deny / ask rule set's declaration meets (`unusableDeclaredBase`, the one judgment).
*
* Exported from the package root: a host that takes an allow list in ahead of the run (an admission door) calls this with the seat the
* list will be handed at, and meets — at the door, in the same words and with the same `code` and `issues` — the refusal the run would
* answer at its start. It is the one judgment; the host writes no second one.
*/
export declare function screenAllowedToolsValue(value: unknown, seat: AllowedToolsSeat): readonly AllowListEntry[] | undefined;
/** The disclosure record for one member, minted from the entries it matched: each sanitized (deployment or model-authored
* text on a human trust boundary) and capped, the rest counted. */
export declare function allowRuleShadowOf(member: AllowRuleMember, entries: readonly string[], reason?: AllowRuleShadowReason): AllowRuleShadow;
/** A disclosure list with one more member's record folded in: ONE record per member — a member already disclosed gains the
* other record's entries after its own (every speaking, in reading order: two shown names that read alike are two speakers),
* the cap kept and the rest counted, and the more exact binding reason of the two (`identity_changed` over `unbound`); any other
* member is appended. Records are minted values already ({@link allowRuleShadowOf}). */
export declare function withAllowRuleShadow(list: readonly AllowRuleShadow[], shadow: AllowRuleShadow): AllowRuleShadow[];
/** Read a disclosure value off a decision WITHOUT trusting it (a policy's own value, an ancestor's): every record a known
* member with a list of strings, or nothing — a display member must never throw where a card is minted. */
export declare function readAllowRuleShadows(value: unknown): readonly AllowRuleShadow[] | undefined;
/** The ask class whose reason is not a row: `probe` is the class of a FINDING about this very call (the read station's, or a
* probe's), and only the ask's own account of it — its `probeReason` — can say which ({@link allowRuleShadowSentence}). */
export type AccountedClass = "probe";
/** Why a matched entry did not clear the ask, by the ask's class — one row per class that has a reason of its own, so a class
* added later is a compile error here rather than somebody else's reason on the card. Two facts the ask carries are read first,
* because they name the reason more exactly than a class shared by several: a table word (`mandate` — the exact mark) and the
* deployment's own authorship (`authoredBy`) — {@link allowRuleShadowSentence} is the reader that applies that order.
* Exported (frozen) so a host that renders the card's "why it was not cleared" half reads the engine's row, never a copy. A row says
* WHY only: whether a standing allow rule clears the question is the call's own answer (the headline, over its class set), which a
* row of one class cannot know — the set a call folds holds more than its word. */
export declare const SHADOW_REASON: Readonly<{
readonly content_question: "the call is the engine's own question to a person";
readonly hook: "an extension's screening asks about this call (a PreToolUse hook or a tool.check station) — the deployment's own screening is answered by a person";
readonly ancestor: "the task that delegated this one owns this question";
readonly dangerous_delete: "this removal targets a protected location (the filesystem root, a top-level directory, a home directory, or a workspace directory or one of its ancestors)";
readonly transcript_write: "this write targets the session transcript";
readonly org_rule: "an organization policy rule requires approval for this call";
readonly org_unreadable: "this deployment's organization policy cannot currently be read, so whether one of its rules forbids this call is unknown";
readonly rule_unreadable: "the person's standing permission rules cannot currently be read, so whether one of them forbids this call is unknown";
readonly call_unreadable: "this call cannot be read against a standing deny or ask rule that may govern it, so whether that rule forbids it is unknown";
readonly ask_rule: "an explicit ask rule matched this call (a person's or the deployment's ask-me-each-time outranks a standing allow rule)";
readonly denial_limit_fallback: "the auto-mode classifier refused too many calls in a row, so a person decides";
readonly classifier_no_ruling: "the auto-mode classifier could not judge this call, so a person decides";
readonly requires_user_interaction: "this tool's server declares that a call must be put to a person";
readonly cross_boundary: "this run executes on a device outside the deployment's trust boundary and the deployment is multi-tenant, so an org-side write — or, after an off-target read, a call bound for the device — is confirmed by the deployment's approver for this call: no automatic lane answers for it, and an allow the configuration gives (a blanket seat or a policy's answer) is refused";
readonly operator_forced: "this call arrived already marked as requiring confirmation (an earlier layer of this run, or the task that delegated it, judged it so), and that mark outranks an allow entry";
readonly shell_floor: "this deployment mandates per-call confirmation for shell commands (shellGate: always)";
readonly target_unresolved: "where this write leads on disk could not be determined (a link on the way could not be examined, or the environment could not resolve the target), so whether it lands on a guarded path is unknown; no automatic decider answers for it, though a wired approver seat can";
readonly write_protection_on_disk: "this write's target is on the deployment's write-protection table (the agent's own configuration is guarded one look per write)";
readonly write_protection: "this write's target is on the deployment's write-protection table (the agent's own configuration is guarded one look per write)";
readonly tool_marks_mcp: "this tool carries egress/irreversibility/interaction marks (a mandated confirmation)";
readonly tool_marks_a2a: "this tool carries egress/irreversibility/interaction marks (a mandated confirmation)";
readonly unfinished_check: "the check of what this command reads did not finish, so its safety checks did not run";
readonly policy_rra: "the deployment's policy requires a real approval for this call";
readonly sandbox_override: "this call asks to run outside the run's OS sandbox (dangerouslyDisableSandbox)";
readonly sandbox_network: "a command in the run's OS sandbox connects to a host its sandbox does not list";
readonly artifact_shared_read: "this read targets another task's shared artifact";
readonly mode: "the permission mode puts this question to a person";
readonly a2a_inside: "this peer is registered inside the trust boundary and accepts only a grant bound to its current identity stamp (the stamp its registration carries now)";
readonly unverifiable_delete: "this call arrived already marked as requiring confirmation (an earlier layer of this run, or the task that delegated it, judged it so), and that mark outranks an allow entry";
readonly unverifiable_shell_text: "this call arrived already marked as requiring confirmation (an earlier layer of this run, or the task that delegated it, judged it so), and that mark outranks an allow entry";
readonly unstated: "this call arrived already marked as requiring confirmation (an earlier layer of this run, or the task that delegated it, judged it so), and that mark outranks an allow entry";
readonly ordinary: "this call arrived already marked as requiring confirmation (an earlier layer of this run, or the task that delegated it, judged it so), and that mark outranks an allow entry";
}>;
/** The fence over the reason table: `never` while every class that has a reason of its own has a row. */
export type ShadowReasonTableCoversEveryClass = AssertAllKeysHandled<Exclude<AskClass, keyof typeof SHADOW_REASON | AccountedClass>>;
/**
* The disclosure in the sentence a PERSON reads — rendered where a card or a park row is minted, never onto the decision
* the classifier reads: "<members> match(es) this call but do(es) not clear the ask — <why>".
*/
export declare function allowRuleShadowSentence(shadows: readonly AllowRuleShadow[], ask: {
askClass?: AskClass;
mandate?: PersistedRuleMandate;
authoredBy?: "deployment";
probeReason?: string;
}): string;
/** The question a card asks when the decision carried no sentence of its own — the one fallback every approval request
* and every parked row of the gate's own lane shares. */
export declare const askFallbackMessage: (toolName: string) => string;
/** The provenance sentence an inherited card carries when the ancestor's ask brought no words of its own — the one spelling
* the inherited request mint, the frame join and the park of that ask (floated back unresolved) share. */
export declare const inheritedAskFallbackMessage: (toolName: string) => string;
/** The card's disclosure members off a surviving ask, minted at every station that builds an approval request and at the
* park twin that keeps the same members on the row: the sanitized records, the message with the sentence rendered onto
* it, the written ask rule the card stands for (relayed as written: a non-empty string or nothing), the approval-list mark
* (display only), and the outlet of a person's rewritten edit (the approved-edit pass's own member, whose form is the bytes the card presents). */
export declare function cardDisclosureOf(decision: {
message?: string;
allowRuleShadowed?: unknown;
askClass?: AskClass;
mandate?: PersistedRuleMandate;
authoredBy?: "deployment";
probeReason?: string;
editRewritten?: EditRewritten;
matchedAskRule?: unknown;
fromApprovalList?: unknown;
}, fallbackMessage: string): {
message: string;
allowRuleShadowed?: readonly AllowRuleShadow[];
editRewritten?: EditRewritten;
matchedAskRule?: string;
fromApprovalList?: true;
};
/** One entry that reads as nothing, and the list it came from (a skill's names the skill and which of its two lists). */
export type AllowEntryInertNote = ({
readonly source: "skill";
readonly skill: string;
readonly list: "allowed-tools" | "disallowed-tools";
} & AllowEntryInert) | ({
readonly source: AllowEntrySource;
} & AllowEntryInert);
/**
* A list entry spelled so a person reads what the engine read: the entry as a JSON string — quotes, backslashes and the usual
* escapes — with every character that prints as nothing, or as a space, written as `\uXXXX` (`\u{…}` beyond the BMP) and a
* run of spaces kept space by space. Uncapped and one-to-one (two entries never share a spelling), so a value that BINDS an
* entry may hold it ({@link renderListEntry} is this, capped for a sentence).
*/
export declare function spelledListEntry(entry: string): string;
/**
* THE ONE WRITER of a list entry into a sentence (the start-of-run notice, a skill's refusal and its decisions, a sub-agent
* list's refusals and advisories): {@link spelledListEntry}, capped on what is printed.
*/
export declare function renderListEntry(entry: string): string;
/**
* One entry that reads as nothing, as a person reads it: the entry as written (quoted, so a surrounding space shows) and why
* — the reason word, with the spelling to write when the reading has one. The one phrasing the start-of-run notice and a
* skill's refused activation share.
*/
export declare function inertEntryPhrase(e: AllowEntryInert): string;
/**
* The notices for entries this grammar reads as nothing — delivered only when one exists: once per prepared task for the
* skill and request lists (`sessionId` given), once per Runner for the deployment's list. The person whose list it is
* reads it (audience `user`). One fact, one code: allow-list entries that grant nothing are `config.entries_not_applied`, kind
* `allow_entry_inert` (the run goes on; an entry that grants nothing makes it ask more); `disallowed-tools` entries of a skill
* that refuse nothing are `config.skill_deny_unreadable` — the spelling of the refusal the skill's activation meets, since such a
* skill does not activate. Each is one frame over its own entries (before 7.70.0 both rode one `permission.allowed_tool_not_granted`).
*/
export declare function allowedToolsNotGrantedNotices(inert: readonly AllowEntryInertNote[], sessionId: string | undefined): EngineNotice[];
export {};