UNPKG

@sema-agent/core

Version:

Stateless, task-oriented AI agent core

111 lines (110 loc) • 9.8 kB
/** * The allow layer's one law for an inside peer's question (`a2a_inside`): a grant clears it only when it is BOUND to the identity stamp * the peer's registration carries now (`A2aServerSpec.fingerprint`). A grant without a stamp, or with another one — given before the * registration changed — does not clear it, whatever it matches; the question then goes to a person (or the classifier, or the mode) * like any other, and the member's disclosure says why (`identity_changed` / `unbound`). The stamp is compared as written; the engine * mints no stamp and stores none here — it only compares the one a grant carries with the one the registration carries. * * Which grants can carry a stamp: an allow-list entry (`{ rule, peerFingerprint }`, the request's or the deployment's list) and a stored * rule's adds (`RuleAdd.peerFingerprint`, any live add's). A skill's `allowed-tools` and a hook's `allow` carry none, so they never clear * it. Several grants of one member reaching the call: any one bound to the current stamp clears it — a list's entries and a person's * stored rows are read alike, whichever the list or the store holds first. Whether anything ELSE in the question refuses a clear (an explicit ask rule, a mark, a governance verdict, a hook's ask) is the * class set's answer without `a2a_inside` ({@link import("./ask-origin.js").boundGrantMayClear}), read once by the caller. * * The stored whole-peer row is the relaxation's own form and clears nothing else ({@link standsOnWholePeerRow}): on an outside peer it is * written and reached, never a clear, whatever the call's question is. * * Where a stamp comes from: the registration's own `fingerprint`, and nothing the engine computes. The gate reads it off the peers the * leg mounted ({@link a2aInsidePeerReader}); every stamp the engine WRITES — on the whole-peer candidate of an inside peer's card, and so * on the add its redemption lands — and every binding word a listed row carries is read off the deployment's mounted-peers seat * ({@link seatStampOf}) through the same lookup. No seat, no stamp. */ import type { AllowEntryHit } from "./allow-entry.js"; import type { AllowListGrant, AllowRuleBinding, AllowRuleShadowReason } from "./allow-rule-shadow.js"; import type { PersistedRuleHitRule } from "./hooks.js"; import { type RuleOffer } from "./permission-rule-model.js"; import type { A2aServerSpec } from "./types.js"; /** Is the peer's skill relaxed as an inside destination on this leg: registered `inside`, and the deployment did not isolate its * peers (`RunnerDeps.a2a.isolatePeers` keeps every peer's skill under the operator's egress mandate, an inside one's included). * The ONE predicate the mount's axis and the gate's {@link a2aInsidePeerReader} read. */ export declare function a2aInsideRelaxed(spec: A2aServerSpec, isolatePeers: boolean): boolean; /** The peer an inside question is about, as the gate's bound-grant law reads it: its name and the identity stamp its registration * carries ({@link A2aServerSpec.fingerprint}). */ export interface A2aInsidePeer { readonly peer: string; readonly fingerprint: string; } /** * Which inside peer a call goes to, per tool name, for a list of declared peers (a leg's: the preparation door's snapshot, the list the * leg materialized; or the deployment's mounted-peers seat) — read the way the destination is read (the mint's prefix; one peer per * prefix, the peer's name compared as written): a tool of a peer {@link a2aInsideRelaxed} relaxes answers that peer and its stamp; any * other tool — an outside peer's, an isolated leg's, a tool that is no peer's — answers nothing. An inside registration without a stamp * is never mounted (`config.a2a_inside_incomplete`), so no call reaches one. */ export declare function a2aInsidePeerReader(declared: readonly A2aServerSpec[] | undefined, isolatePeers: boolean): (toolName: string) => A2aInsidePeer | undefined; /** The one lookup of a tool name's peer among a list of declared peers: the mint's own prefix, each peer projected once. */ export declare function declaredPeerReader<T>(declared: readonly A2aServerSpec[] | undefined, project: (spec: A2aServerSpec) => T | undefined): (toolName: string) => T | undefined; /** The deployment's mounted-peers seat (`createPermissionRuleStoreProvider({ a2aPeers })`): the A2A peers as they are registered now, * read each time a stamp is to be written or a binding said. */ export type MountedPeersSeat = () => readonly A2aServerSpec[]; /** * The identity stamp the engine writes for a name under an A2A peer — a call's skill name (`a2a__<peer>__<skill>`) or a rule's peer * (`a2a__<peer>`): the stamp the mounted-peers seat declares now for that peer when it registers it inside the boundary, read through * the gate's own lookup ({@link a2aInsidePeerReader}) — or none: no seat, a peer the seat does not register inside (or registers with a * stamp no stored add could carry), a name under no peer. The ONE source of every stamp the engine writes and of every binding word. * A seat that cannot be read — it throws, it answers no list, an element is no registration with a name — throws * `config.invalid_argument`: the write that needed it is refused, never landed without its stamp. */ export declare function seatStampOf(seat: MountedPeersSeat | undefined, name: string): A2aInsidePeer | undefined; /** The card offer for a call on an inside peer's skill — the whole-peer rule bound to the stamp the seat declares now * ({@link seatStampOf}, {@link suggestRuleForPeer}) — or none: no stamp can be written for it. The one mint the ask-time card and the * approval record take. */ export declare function insidePeerOfferOf(seat: MountedPeersSeat | undefined, toolName: string): Extract<RuleOffer, { kind: "single"; }> | undefined; /** The binding a stored allow row carries against an inside peer's current stamp, read off its live adds' stamps: `current` (one of * them is the stamp), `identity_changed` (it carries stamps, none of them this one), `unbound` (it carries none). The one reading the * stored member's clearance ({@link boundStoredGrantOf}) and a listed row's binding word take. */ export declare function storedRowBindingOf(stamps: readonly string[] | undefined, fingerprint: string): AllowRuleBinding; /** What the law says about one member's match: it clears — on the entries bound to the current stamp, their positions in the list the * run received and their common provenance (a list's), or the stored rows it stands on (`rules`, a person's) — or it does not, with the * binding reason where the binding is the whole reason. */ export type BoundGrantReading = { readonly clears: true; readonly entries: readonly string[]; readonly positions?: readonly number[]; readonly grant?: AllowListGrant; readonly rules?: readonly PersistedRuleHitRule[]; } | { readonly clears: false; readonly reason?: AllowRuleShadowReason; readonly entries?: readonly string[]; }; /** * A LIST member's match (`RunnerDeps.allowedTools`, `TaskSpec.allowedTools`): each matched entry covers the call on its own, so the match * clears on the entries bound to `fingerprint` — and only on those (the clearance names them, not the unbound ones beside them). * `mayClear`: nothing else in the question refuses a clear. */ export declare function boundListGrantOf(hit: AllowEntryHit, fingerprint: string, mayClear: boolean): BoundGrantReading; /** * A person's STORED rules — the coverage set the lane answered (`rules`), and every stored allow row that reaches the call on its own * and carries a stamp (`bound`, {@link import("./hooks.js").PersistedRuleHit.bound}) — read as the list's law reads its entries: the * set stands together, so it clears when every rule of it has a live add bound to `fingerprint`; each row of `bound` covers the call on * its own, so the match clears, too, on the rows bound to `fingerprint` — and only on those (the clearance names them). Several rows * reaching one call: any one bound to the current stamp clears it, whichever of them the store lists first. */ export declare function boundStoredGrantOf(rules: readonly PersistedRuleHitRule[], bound: readonly PersistedRuleHitRule[], fingerprint: string, mayClear: boolean): BoundGrantReading; /** * Does a person's stored allow set stand on a WHOLE-PEER row (`a2a__<peer>`, or its other spelling `a2a__<peer>__*`)? That row is the * inside relaxation's own form — "do not ask me again about this peer" — so it clears an inside peer's question (bound, above) and no * other: on any other call it reaches (an outside peer's, an isolated deployment's inside one) it is written and reached, and disclosed as * a match that could not clear, never a clear. A row naming one skill is not this form. The row is read by its TEXT, as the rule syntax * reads it ({@link parseRuleText}): a lane's answer carries a rule's text and none of its fields, and a host's own lane may hand any * spelling the syntax reads as the whole-peer row (`a2a__<peer>(*)`, `a2a__<peer>__*()`). The engine's own lane serves no allow row whose * text and stored fields disagree — the store's read leaves such a row out (`EffectivePermissionRules.droppedRows`) — so for its rows the * text is what the fields the allow judgment read say: one reading. */ export declare function standsOnWholePeerRow(rules: readonly PersistedRuleHitRule[]): boolean; /** A member whose grants carry no stamp (a skill's `allowed-tools`): never bound. A hook's `allow` is not read here — the class row * refuses it beside `a2a_inside` whatever its words, so the binding is not its reason. */ export declare function unboundGrantOf(mayClear: boolean): BoundGrantReading;