UNPKG

@sema-agent/core

Version:

Stateless, task-oriented AI agent core

70 lines (69 loc) • 4.99 kB
/** * The skill seats of the mods bus (`SkillSpec.mods`), admitted with the leg's other registrations on the task seat. Theirs alone: * · the SCOPE RECORD — which skill each registration belongs to and which skills are active on the leg (opened by the grant * table's activation write, or by a resumed leg's frozen scopes; closed with the run that holds the record); * · two VIEWS of the leg bus: the leg's own raises take a skill's handlers only while its scope is open (presence counts them * always, so what prepare arms is armed for a scope that opens later); the STANDING chain never holds them — what the leg * hands its descendants, and what guards every call unconditionally; * · the SEAT RULE — a skill carries hooks, `classic.*` events only (a method event's chain is dispatched inside the kernel, * where no scope is read). */ import type { SkillSpec } from "../agent-definition.js"; import type { EngineDollar } from "./dollar.js"; import { type ModBus, type ModRegistration } from "./kernel/index.js"; /** The leg's record of its skills' scopes, as the activation write point and the park read it. */ export interface SkillScopes { /** Open `skill`'s scope on this leg: from now to the run's end its registrations take part in the leg's raises. */ open(skill: string): void; /** The active skills that carry registrations, sorted — what a park freezes (`undefined` = none). */ frozen(): string[] | undefined; } /** The record, with the readings the views take. */ export interface ScopeRecord extends SkillScopes { /** The skill a registration (by name) belongs to, or undefined for a registration of no skill. */ ownerOf(registration: string): string | undefined; isOpen(skill: string): boolean; /** Whether any skill of the leg carries a registration (none ⇒ both views are the bus itself). */ carries(): boolean; } /** The registrations the leg's skills carry, in the skills' order, and which skill each belongs to. */ export interface SkillSeats { readonly registrations: readonly ModRegistration<EngineDollar>[]; readonly owners: ReadonlyMap<string, string>; } /** * Read the leg's skills (the skills seat's copy) into their registrations, each READ ONCE into a frozen copy of its members * (`register` still runs with the host's object as `this`): the name the scope owns it by is the very name the kernel admits * it under, and the `uses` the seat rule judges is the very `uses` the kernel holds its `on` to. The seat rule is judged here, * before admission — so no handler of a refused registration ever runs, not even on another registration's `plugin.register`. * Anything else about a registration (its shape, its tier, a duplicate name) is the admission's screen, given the copy. */ export declare function skillSeatsOf(skills: readonly Pick<SkillSpec, "name" | "mods">[] | undefined): SkillSeats; /** * Mint the leg's scope record; `reopened` = the scopes a resumed leg's park froze (open from the start). What a park freezes: * every open scope of a skill that carries registrations on this leg, and every scope this leg reopened (a reopened skill * stays recorded whatever the resumed definition carries — the next resume may restore its hooks). A plain skill's * activation is not recorded: the hooks a skill brings are the ones its definition carried when it was active. */ export declare function skillScopeRecord(owners: ReadonlyMap<string, string>, reopened: readonly string[] | undefined): ScopeRecord; /** * Read a park's frozen skill scopes (`CheckpointState.skillScopes`): absent ⇒ none; a list of skill names ⇒ those (copied by * index, once); anything else ⇒ `undefined`, a damaged section — the resume screen refuses it before the claim, never read as * "no scope" (that would resume the run with the skills' hooks silently shut). */ export declare function readFrozenSkillScopes(section: unknown): readonly string[] | undefined; /** A resumed leg's reopened scopes off its checkpoint state; throws on a damaged section (the screen refused it pre-claim). */ export declare function frozenSkillScopesOf(state: { readonly skillScopes?: unknown; } | undefined): readonly string[] | undefined; /** * The leg's own raises over the admitted bus: a skill's handler takes part only while its scope is open; presence * (`hasHandlers`, `mounted`) counts it always. With no skill registration, the bus itself. */ export declare function scopedLegBus(bus: ModBus, record: ScopeRecord): ModBus; /** * The leg's STANDING chain, over the leg bus: every registration that takes part on every raise — a skill's handlers are * absent from it, from presence and from every dispatch. Two readers: what the leg hands its descendants (the screening * constraint is minted over it; the chain identity is its), and what guards every call of the leg unconditionally. */ export declare function standingBus(leg: ModBus, record: ScopeRecord): ModBus;