@sema-agent/core
Version:
Stateless, task-oriented AI agent core
56 lines (55 loc) • 4.2 kB
TypeScript
import { type ModRegistrationTier } from "./kernel/index.js";
import { type ReferencePackageRecord } from "./reference-package.js";
import type { EngineModRegistration } from "./classic-events.js";
/** The host's facts about a package it loads: never read from the package itself. */
export interface ModPackageHost {
/** The tier the host seats it in (a deployment seat requires one; the task seat takes `user` or none). */
readonly tier?: ModRegistrationTier;
/** The host's provenance label, handed to admission and carried on the admission record as given (its form is the kernel's). */
readonly provenance?: string;
/** The values handed to the package's `register(on, options)`. */
readonly options?: unknown;
/** The package digest the host pinned (lowercase hex): a package whose bytes give another is refused, `detail.digest
* { expected, actual }`, before anything of it is imported. A match proves only that the bytes are the pinned ones — it is not
* admission: which package may run in this process is the host's decision, made before it asks for one. */
readonly expectDigest?: string;
/**
* The host declares that this process serves one principal: whoever runs in it is the one person the process belongs to. A
* package of the reference plugin form (its `hooks/hooks.json` states no `contract`) loads only where this is `true` — its
* code is shared by every run of the process — and is refused before any of its code runs where it is absent or `false`.
* The engine cannot check it: who reports it, on what facts, is the host's. A package of the engine's own form reads none of it.
*/
readonly singlePrincipal?: boolean;
}
/** A member of `plugin.json` or `hooks.json` this reader does not read: the package loaded without it. */
export interface ModPackageUnreadKey {
/** The file it stands in, relative to the package (`.claude-plugin/plugin.json` or `hooks/hooks.json`, `/`-separated on every platform). */
readonly file: string;
/** The member's name, spelled as a foreign line: one line, the name whole up to 60 characters (a longer one: its first 60
* and the cut mark; the fence's defusing of a sentinel such as `<<<` may lengthen what is kept). Never its value. */
readonly key: string;
}
/** A package read into a registration, with the identity of the bytes it was read from. */
export interface ModPackageRegistration extends EngineModRegistration {
/**
* The sha256 (lowercase hex) of the three files the reader read, in this order — `plugin.json`, `hooks.json`, the
* hooks module — taken as the newline-joined sha256 of each file's bytes. One changed byte in any of the three changes
* it. The module is imported from those bytes, so this names the module that runs; what its code loads beyond them (an
* absolute URL, a file it reads) is not among them.
*/
readonly digest: string;
/** The members of the two files the reader does not read (`plugin.json`'s first, each in its parsed object's key order),
* each also told as a `mods.package_key_unread` notice. Present iff there is one. */
readonly unread?: readonly ModPackageUnreadKey[];
/** `"reference"` where the package is of the reference plugin form (its `hooks.json` states no `contract`): its `register`
* replays what the package's own register hung once, at its load, and it carries `failure: "skip"`. Present iff it is. */
readonly form?: "reference";
}
/** Read the package at `dir` into a registration the host seats in `RunnerDeps.mods` or `TaskSpec.mods`. */
export declare function loadModPackage(dir: string, host?: ModPackageHost): Promise<ModPackageRegistration>;
/**
* A reference-form package's record (phase one's exit, not a root export): the same load as `loadModPackage` — the form, the host's
* bit, the reader, the import and the one register run — ending at the record its registration replays. A package of the engine's
* own form is refused here before anything of it is imported.
*/
export declare function readReferencePackageRecord(dir: string, host?: ModPackageHost): Promise<ReferencePackageRecord>;