@sema-agent/core
Version:
Stateless, task-oriented AI agent core
55 lines (54 loc) • 4.11 kB
TypeScript
/**
* Who a permission-rule bucket belongs to: the owner type, its discriminant words, the one reading of an owner from a
* value the engine did not just build, and the one equality between two owners.
*
* The faces that read an owner out of data — the two adoption markers read back from disk, the two adoption entries'
* source, a stored approval record's identity and the consent entries' `owner` option — read it through
* {@link readRuleOwner}, so the source an adoption entry writes into its marker is one that marker's reader reads back (the markers and
* the entries' source through {@link readRecordedRuleOwner}, which reads a principal arm as a stored name is read).
* Its run-time imports are the two import-free judges — the record judge and the principal-name judge — because the root
* adoption marker reader, which every file store loads, depends on this module and is kept free of the rule store's own imports.
*/
import type { AssertAllKeysHandled } from "./ask-origin.js";
/**
* Who a rule bucket belongs to, as a STRUCTURAL position.
*
* Identity absence is spelled as a distinct union member, never as a sentinel string flowing through
* `forPrincipal` — every consumer of a principal string is an identity surface, and a made-up name on an
* identity surface is indistinguishable from a real one downstream. Cloud sync and cloud tickets accept
* ONLY the `principal` kind: syncing is an authenticated act, and a local-owner bucket has no cloud home
* until it is adopted (`adoptFilePermissionRuleStore`).
*
* A memory layer's owner is read the same way: the identity-less owner is this `local-owner` arm, and its layer
* keeps an opaque key, never a `user:` key (`@contract memory.identity_absence.opaque_key`, scope-contract.ts).
*/
export type RuleOwner = {
kind: "principal";
principal: string;
} | {
kind: "local-owner";
};
/** The owner discriminants as a value: the `kind` words of {@link RuleOwner}, both directions fenced at compile time
* ({@link RuleOwnerKindsCoverEveryArm} / {@link RuleOwnerArmsCoverEveryKind}). */
export declare const RULE_OWNER_KINDS: readonly ["principal", "local-owner"];
/** Compile fence: an arm whose `kind` is not in {@link RULE_OWNER_KINDS} turns the argument into that word. */
export type RuleOwnerKindsCoverEveryArm = AssertAllKeysHandled<Exclude<RuleOwner["kind"], (typeof RULE_OWNER_KINDS)[number]>>;
/** Compile fence, the other direction: a word in {@link RULE_OWNER_KINDS} that no arm carries. */
export type RuleOwnerArmsCoverEveryKind = AssertAllKeysHandled<Exclude<(typeof RULE_OWNER_KINDS)[number], RuleOwner["kind"]>>;
/** Do two owners name the same bucket? */
export declare function sameRuleOwner(a: RuleOwner, b: RuleOwner): boolean;
/**
* Read an owner from a value the engine did not just build, or `undefined` when it is not one: not a plain record (an
* object whose prototype is `Object.prototype` or none, so no member comes from a prototype it was given), a `kind`
* outside {@link RULE_OWNER_KINDS}, or a `principal` arm whose name is not a principal name ({@link principalNameOf}: an
* identity-less bucket is the `local-owner` kind, never a blank name). Fail-closed: a caller treats `undefined` as
* "owns nothing" or refuses — never as either arm. The answer is a fresh object holding only the members the type
* declares; `kind` and `principal` are each read once.
*/
export declare function readRuleOwner(raw: unknown): RuleOwner | undefined;
/** {@link readRuleOwner} for an owner a store already holds or a move names as its SOURCE — an adoption marker read back, an adoption's or
* a re-key's `from`: its principal arm is read by {@link recordedPrincipalNameOf} (a name an earlier release admitted still reads, so its
* bucket can be found and moved). Everything else is read as {@link readRuleOwner} reads it. */
export declare function readRecordedRuleOwner(raw: unknown): RuleOwner | undefined;
/** An owner as an operator's sentence names it: `principal "<name>"`, or `the local owner`. */
export declare function ruleOwnerText(owner: RuleOwner): string;