UNPKG

@sema-agent/core

Version:

Stateless, task-oriented AI agent core

148 lines (147 loc) • 9.71 kB
import { type AssertAllKeysHandled } from "./ask-origin.js"; import type { DecisionMember, PermissionResult } from "./tool-policy.js"; export declare const refusedOutOfContract: (message: string) => PermissionResult; /** Is `d` a refusal the engine itself minted (by object identity — a look-alike `deny` a caller built is not one)? The receipt's * answer is one of two things (the engine's refusal or its detached copy), and this tells them apart. */ export declare const isEngineRefusal: (d: unknown) => boolean; /** A decision's `decisionReason` — the closed set; the type is derived FROM this list, so a word added to either side is a * compile error rather than a drift between the type and the screen. Module-private (the package publishes the type). * `skill`: an active skill's list spoke — the allow layer's skill member cleared the call (`allowed-tools`), or this * run's deny row refused it (`disallowed-tools`); distinct from `rule` (a deployment policy) and `persisted_rule` (a * person's stored row) because the authority is the skill the run activated. `deployment_rule` / `request_rule`: an entry * of the deployment's `RunnerDeps.allowedTools` / of this run's `TaskSpec.allowedTools` cleared the call (the allow layer's * two entry-list members) — one word per author, so "who said this needs no asking" is read off the decision. */ declare const DECISION_REASONS: readonly ["rule", "mode", "hook", "safety", "classifier", "persisted_rule", "sandbox", "org_rule", "org_unavailable", "read_only", "skill", "deployment_rule", "request_rule"]; export type DecisionReason = (typeof DECISION_REASONS)[number]; /** The arms of the decision union that declare member `M`. */ type ArmOf<M extends DecisionMember> = PermissionResult extends infer U ? (U extends { action: infer A; } ? (M extends keyof U ? A : never) : never) : never; /** * Every member of the decision union with the ARMS that declare it — the one table the receipt's member list is read off * (`DECISION_MEMBERS`), fenced to the union both ways: `satisfies` admits no member and no arm the union lacks, and * {@link DecisionMemberArmsCoverTheUnion} no arm the union has and a row lacks. A present member on an arm outside its row is * out of contract like a word outside a closed set ({@link screenContractValues}): an ask's mark on an allow or a deny is a * decision that contradicts itself, and a consumer branching on the member would read the other arm's meaning. */ export declare const DECISION_MEMBER_ARMS: Readonly<{ readonly action: readonly ["allow", "ask", "deny"]; readonly updatedInput: readonly ["allow", "ask", "deny"]; readonly message: readonly ["allow", "ask", "deny"]; readonly decisionReason: readonly ["allow", "ask", "deny"]; readonly attestation: readonly ["allow", "ask", "deny"]; readonly requiresRealApproval: readonly ["ask"]; readonly denialLimitFallback: readonly ["ask"]; readonly classifierNoRuling: readonly ["ask"]; readonly allowRuleShadowed: readonly ["ask"]; readonly probeReason: readonly ["ask"]; readonly probeCause: readonly ["ask"]; readonly probeMandated: readonly ["ask"]; readonly crossBoundaryMandated: readonly ["ask"]; readonly mandated: readonly ["ask"]; readonly mandate: readonly ["ask"]; readonly probeReadRootCandidate: readonly ["ask"]; readonly matchedAskRule: readonly ["ask"]; readonly ruleEvidence: readonly ["ask"]; readonly segmentCoverage: readonly ["ask"]; readonly origin: readonly ["ask"]; readonly askClass: readonly ["ask"]; readonly classes: readonly ["ask"]; readonly askReasons: readonly ["ask"]; readonly ruleUnreadable: readonly ["ask"]; readonly authoredBy: readonly ["ask"]; readonly fromApprovalList: readonly ["ask"]; readonly editRewritten: readonly ["ask"]; }>; export type DecisionMemberArmsCoverTheUnion = AssertAllKeysHandled<{ [M in DecisionMember]: Exclude<ArmOf<M>, (typeof DECISION_MEMBER_ARMS)[M][number]>; }[DecisionMember]>; /** * The members a PreToolUse hook's answer carries beyond the decision's, with their arms — the hook seat's half of the member × * arm table, read by the same screen: `additionalContext` (the text appended for the model, any arm) and `questionCause` (WHY * the hook asked, {@link import("./ask-origin.js").HookQuestionCause} — the ask arm only). The hook seat's member list is the * decision's plus these. */ export declare const HOOK_SEAT_MEMBER_ARMS: Readonly<{ readonly additionalContext: readonly ["allow", "ask", "deny"]; readonly questionCause: readonly ["ask"]; }>; export type HookSeatMember = keyof typeof HOOK_SEAT_MEMBER_ARMS; /** * WHO writes each member of the decision union — one writer per fact, one table (fenced to the union like * {@link DECISION_MEMBER_ARMS}: a member the union gains without a row is a type error): * · `composer` — the policy's or hook's own statement about its question: received, and read as an input of the class derivation; * · `record` — the engine's attestation record (`attestation`): taken by reference after its brand check, read for its call; * · `stamp` — written by the gate after the receipt (the disclosed words of the classes the engine derives, the allow layer's * and the rule lane's accounts, the account of a finding a read station or a reversibility probe made): no composer writes one, * so a decision that states one is refused by name. */ export declare const DECISION_MEMBER_WRITERS: Readonly<{ readonly action: "composer"; readonly updatedInput: "composer"; readonly message: "composer"; readonly decisionReason: "composer"; readonly attestation: "record"; readonly requiresRealApproval: "composer"; readonly denialLimitFallback: "composer"; readonly classifierNoRuling: "composer"; readonly allowRuleShadowed: "stamp"; readonly probeReason: "stamp"; readonly probeCause: "composer"; readonly probeMandated: "composer"; readonly crossBoundaryMandated: "composer"; readonly mandated: "composer"; readonly mandate: "stamp"; readonly probeReadRootCandidate: "composer"; readonly matchedAskRule: "composer"; readonly ruleEvidence: "stamp"; readonly segmentCoverage: "stamp"; readonly origin: "stamp"; readonly askClass: "stamp"; readonly classes: "stamp"; readonly askReasons: "stamp"; readonly ruleUnreadable: "composer"; readonly authoredBy: "composer"; readonly fromApprovalList: "composer"; readonly editRewritten: "composer"; }>; export declare const RETIRED_WINDOW_MEMBER_DENY_MESSAGE: string; export declare const carriesRetiredWindow: (fallback: unknown) => boolean; /** * The VALUE screen over the engine's one-read record of a decision (never a second read of the caller's object): every * closed-set member holds a member of its set or is absent (`action` present), and the retired window is absent. The refusal * names the member and the set, one code for every arm. `undefined` is the receipt's spelling of absence. */ export declare function screenContractValues(contract: Record<string, unknown>, opts?: { skip?: ReadonlySet<string>; optional?: ReadonlySet<string>; }): PermissionResult | undefined; /** * The receipt of the records a decision nests, into the one-read record itself: each record that is PRESENT is received by * {@link receiveContract} (the decision's own function — an ordinary object, own enumerable data members, a prototype member * refused by name) and must hold every required member; a present value that is not an object, or a record missing a required * member, is refused by path. The engine's copy replaces the caller's record in `contract`, so no station reads the caller's * again. Returns the refusal, or `undefined` when every record is in contract. */ export declare function receiveNestedRecords(contract: Record<string, unknown>): PermissionResult | undefined; /** The nested records of an engine receipt, by path — frozen with the receipt, so a receipt handed back unread is the receipt. */ export declare function nestedRecordsOf(receipt: object): object[]; /** One level of the receipt, the same for the decision and each record it nests. The carrier is an ORDINARY object — it and * every object on its prototype chain are looked at for being a Proxy before any descriptor is asked for (a Proxy's traps are * the caller's code; the look invokes none of them) — so the receipt runs none of the carrier's code: a contract member is * absent or an own enumerable DATA property, its value taken off the descriptor (no read at all). Anything else refuses the * carrier, the member named by `path`: an accessor (never invoked), and a member the prototype or a non-enumerable property * supplies, unless the nearest descriptor holding it spells absence (an `undefined` data property). Descriptors are looked up * as OWN entries of the descriptor map, so a polluted `Object.prototype` names no member. Members outside the contract are * not looked at — but a retired one (`retired`) is refused by name when the carrier carries it by that same law. */ /** The receipt's own answers carry a `kind` discriminant as an own property: narrowing never asks the prototype chain (`in`) for a * word, so a polluted `Object.prototype` cannot answer for the receipt either. */ export type Received = { kind: "held"; held: Record<string, unknown>; } | { kind: "refused"; refused: PermissionResult; }; export declare function receiveContract(carrier: object, members: readonly string[], path: string, retired?: Readonly<Record<string, string>>): Received; export {};