UNPKG

@sema-agent/core

Version:

Stateless, task-oriented AI agent core

87 lines (86 loc) • 8.03 kB
/** * The tool gate's PERSISTED-RULE arms — the pieces of the persisted-rule lane's consumption that are pure * functions of (the lane's answer, the standing decision), pulled out of the gate's lane station so the * station holds only the wiring: where the read happens, and where each arm is applied. * * What lives here: {@link applyPersistedTightening} — the DENY and ASK arms (a person's own standing * "never run this" and "ask me each time" rows, their settings' deny/ask lists imported into their store), * which the station applies to EVERY decision right after the org layer, and again on an approved edit's * bytes — and {@link disclosedRuleSet}, the display form both arms and the allow arm's disclosure use. The * lane's bounded READ and the ALLOW arm (a standing yes clearing a classify-tier ask) stay in the station: * the read closes over the gate input, and the allow arm is a conjunction over the gate's own state * (mandates, the org latch, the marked-call seat) rather than a function of the answer alone. */ import { type PermissionResult, type ToolCallRequest } from "./tool-policy.js"; import type { PersistedRuleAnswer, PersistedRuleHit, PersistedRuleHitRule } from "./hooks.js"; /** The lane's one read, normalized: at most one of `hit` / `unreadable` / `coverage` — save an ask `hit` beside the store form of * `unreadable` (a readable ask row reaching the call too: the call carries both) — the gate's reader produces it; the arms below read it. */ export interface PersistedRuleRead { readonly hit?: PersistedRuleHit; /** The lane could not answer: with `reason`, the CALL could not be read against the person's deny/ask rows; * without, a partition of the store (or all of it) could not be read — a deny / ask row inside it may forbid this call, * so no allow beside it is a yes (the lane has already folded that: an allow, a coverage or nothing reads as this). */ readonly unreadable?: true; /** The lexer's reason when the CALL could not be read against the person's deny/ask rows. */ readonly reason?: string; /** The store form's cause, when the lane said it: which partition(s) could not be read and why (closed reason words). */ readonly faults?: readonly RuleStoreFault[]; } import { type RuleStoreFault } from "./rule-store-fault.js"; /** The answers of one store read judged under each of a call's names, folded as one table folds its rows (deny > * unreadable > ask > allow > coverage > nothing); among equals the first (the wire name's) stands. */ export declare function strongestAnswer(answers: readonly PersistedRuleAnswer[]): PersistedRuleAnswer; /** Display form of a rule set (design/375 §5.1): every rule text is a DISPLAY value on a human trust * boundary, and the set must stay readable however large a lane makes it — each member rides * `inlineUntrusted` (200 cap, the same cap the durable leg's `RiskDescriptor.shadowedRule` carries), * at most FIVE are listed, and the rest are counted rather than dropped silently. */ export declare function disclosedRuleSet(rules: readonly PersistedRuleHitRule[]): string; /** * The persisted-rule lane's TIGHTENING arms — a person's own standing DENY and ASK rows — applied to * `decision`. The station runs this on EVERY decision, right after the org layer and in the same * posture: an allow from the policy fold is exactly what a deny row must be able to refuse, and a bare * ask is exactly what an ask row must be able to mark. Precedence across the person's rows is the * upstream arbiter's (deny > ask > allow), already resolved inside the lane's one verdict; precedence * across AUTHORITIES is org > personal (the org layer ran first, and a personal ask never loosens an * org outcome — it stamps a marker on an ask, or turns an allow into one). * · DENY — the call is refused outright, with `decisionReason: "persisted_rule"` (the same word the * lane's allow carries: one authority, one word) and the rule text disclosed through the display * transform; the STATION attributes the refusal (`tightened: "deny"` ⇒ it writes the pass's refusing * layer — the attribution is a station's word and lives in the station file). A path row's hit reports where * it met the call; with the face the call's own (`call`, the request the lane read), the deny carries that as its attested `pathDenial`, so every exit that * reads the deny (the gate's exit, the approved-edit re-check, a resumed leg's belt) mints the same card from the same fact. * · ASK — on an allow, a fresh ask is minted carrying `matchedAskRule` (the marker an explicit `ask` * permission rule stamps, so the ask's origin derives as `ask_rule`: the classifier never answers * it, the persisted ALLOW arm never clears it, and the rule-offer face reports `ask_rule_matched`); on an * ask, the row meets it by rank — an ask already carrying an explicit rule's marker keeps the slot and the row's class * rides its record as a folded class, an ask with none takes the row's marker — and the message names the rule — the standing question * outranks a remembered yes across lanes, exactly as the DSL's own order says within one; a deny * stays a deny. * · UNREADABLE CALL — the store was read, but the CALL could not be read against the person's standing * deny/ask rows (`reason` carries the lexer's word: an expansion where a rule reads a word, an * unterminated quote, a syntax error): whether a row forbids this call is unknown, so it fails CLOSED — * an allow tightens to an ask carrying `requiresRealApproval` (no automatic lane clears it; the gate * derives the origin `rule_store_unavailable` from its own record of the read), an ask acquires the * bit, a deny stays a deny. * · UNREADABLE STORE — a partition of the store (or all of it) could not be READ (`unreadable` without a `reason`): a deny * or ask row inside it may forbid this call and nobody can tell, so it fails CLOSED under the asking modes the same way — * an allow becomes an ask carrying `requiresRealApproval`, an ask acquires the bit, a deny stays a deny (the ask's class * row says which modes answer it without a person). A readable ask row that reaches the call too rides beside it (`hit`): its own * question is minted first and the store form's applied on it, so the call carries both classes and the stricter governs — an * unreadable store never turns a standing ask into a question the mode answers. Every call is in this state until a read succeeds again, whatever its tool — rules nobody could read are rules * whose tools nobody knows (a newer engine's grammar names rules for tools this one names none for), so the lane hands * this form for a call no rule grammar here speaks for too; it announces the skipped store once per run and reads again * on the next call. The two forms differ in WHICH fact the gate records and so in their class — the call form * `call_unreadable` (a person answers it under every mode), the store form `rule_unreadable` (the person's relaxed * mode answers it: auto mode's classifier, the bypass release) — and in the * resumed-call belt, which vetoes only the call form: a person already answered that call's question. * An allow hit (or no hit) returns the decision untouched: the allow arm is the station's. * * `seat` names whose ask row the hit is — the person's store (`persisted`, every lane's) or the task's permission policy * (`policy`: the shell read station's fact about a policy's `Read(<path>)` ask row, which the policy's own check cannot see on a * shell call): the same ask arm, the question naming the rule's own seat. */ export declare function applyPersistedTightening(decision: PermissionResult, read: PersistedRuleRead | undefined, call: ToolCallRequest, seat?: "persisted" | "policy"): { decision: PermissionResult; tightened?: "deny" | "ask" | "unreadable" | "store_unreadable"; };