@sema-agent/core
Version:
Stateless, task-oriented AI agent core
67 lines (66 loc) • 5.32 kB
TypeScript
/**
* The persisted-rule BUCKETS a leg reads, and the one rule that binds them down a delegation tree:
*
* **a leg's ancestors read some kinds of persisted-rule bucket; the Runner the leg runs on must read the same kinds,
* or the leg is refused at prepare, naming what it lacks.**
*
* A leg reads persisted rules through ITS OWN Runner's seats (`RunnerDeps.permissionRuleStore` + `RunnerDeps.localOwnerRules`),
* never through the chain: a delegation tool mounted on a second Runner that carries neither ran the person's stored deny and ask
* rules nowhere, silently. The chain does not carry the rules (a second copy of them would be a second source); it carries which
* KINDS of bucket the legs above read — a fact that serializes and rides the checkpoint, never the store's identity (two store
* objects can answer for one bucket, and no identity survives a process boundary).
*
* Three kinds, read exactly as the rule lanes read them (`createPermissionRuleLanes`): a named person's bucket (a durable
* partition and a principal that is a name), the local owner's bucket (a durable partition, no principal, the declaration), and the
* org partition. A leg that reads none hands down nothing, so a chain whose legs wired no store carries no member and nothing is
* compared — byte for byte what such a chain did before.
*/
import type { PermissionRuleStoreProvider } from "./permission-rule-provider.js";
/** The kinds of persisted-rule bucket a leg's rule lanes read (each present member is `true`; absent ⇒ not read). Data: it rides
* the inherited gate's data half and the checkpoint's. */
export interface PersistedRuleBuckets {
/** A named person's bucket: a durable partition, read for a principal that is a name. */
readonly named?: true;
/** The local owner's bucket: a durable partition, read for a task with no principal under `RunnerDeps.localOwnerRules`. */
readonly localOwner?: true;
/** The org partition (the provider was composed with `org`). */
readonly org?: true;
}
/** A Runner's two rule seats, as the rule lanes take them (`RunnerDeps.permissionRuleStore`, `RunnerDeps.localOwnerRules`). */
export interface RuleBucketSeats {
provider: PermissionRuleStoreProvider | undefined;
localOwnerDeclared: boolean;
}
/** A leg's owner: its Runner's seats and its principal — the three facts `createPermissionRuleLanes` takes. */
export interface RuleBucketOwner extends RuleBucketSeats {
principal: string | undefined;
}
/** The kinds of bucket a Runner's seats CAN read, whoever the task is: a durable partition answers a named person's bucket; with the
* declaration and a provider that has the face, the local owner's; an org partition, the org's. `undefined` when none. */
export declare function bucketsReadableBy(seats: RuleBucketSeats): PersistedRuleBuckets | undefined;
/** The kinds a leg with this owner READS: of the kinds its Runner can read, the personal bucket its principal selects (a name ⇒ that
* person's; none ⇒ the local owner's) and the org partition. `undefined` when it reads none (no store, or an anonymous task on an
* undeclared deployment with no org partition). */
export declare function persistedRuleBucketsOf(owner: RuleBucketOwner): PersistedRuleBuckets | undefined;
/** Where a record of the kinds the legs above read comes from: the chain this leg was handed, or the checkpoint row it resumes. */
export type RuleBucketRecord = "chain" | "checkpoint";
/**
* A record as a chain or a checkpoint row carries it, read strictly — the one reader of both: absent ⇒ `undefined` (nothing to
* compare); the shape the engine writes (an object whose members are kinds, at least one, each `true`) ⇒ those kinds; anything else
* present — a member that is not `true`, a word that is no kind, an empty object, a value that is no object — is refused at prepare,
* loudly (`config.persisted_rule_bucket_missing`, `detail.unreadable` naming the record), rather than read as "the legs above read
* nothing", which would skip the comparison without a word.
*/
export declare function readRuleBuckets(value: unknown, record: RuleBucketRecord): PersistedRuleBuckets | undefined;
/** Both readings joined: every kind either one names (the chain's legs and this leg's own; a checkpoint's record and the live
* chain's — each read by {@link readRuleBuckets} first). */
export declare function joinRuleBuckets(a: PersistedRuleBuckets | undefined, b: PersistedRuleBuckets | undefined): PersistedRuleBuckets | undefined;
/**
* The rule itself, at prepare: every kind of bucket the leg's ancestors read (`ancestors`, the chain's record; absent ⇒ nothing is
* compared) that this leg's Runner cannot read (`bucketsReadableBy` — its seats, not its principal: a child whose own authorship pins
* another principal, a deployment baseline's or a trusted script's, reads that person's bucket on the same seats, which is the
* deployment's choice, not a wiring gap) refuses the
* leg, loudly (`config.persisted_rule_bucket_missing`, `detail.missing` the kinds it lacks), rather than running it with the person's
* stored deny and ask rules silently unapplied.
*/
export declare function refuseUnreadAncestorBuckets(ancestors: PersistedRuleBuckets | undefined, seats: RuleBucketSeats): void;