UNPKG

@sema-agent/core

Version:

Stateless, task-oriented AI agent core

49 lines (48 loc) • 3.04 kB
import { type ModBusSide } from "./events.js"; import { type ModUses } from "./registration.js"; /** The two manifests, by their path inside the package (`/`-separated on every platform). */ export declare const MOD_PACKAGE_FILES: Readonly<{ readonly plugin: ".claude-plugin/plugin.json"; readonly hooks: "hooks/hooks.json"; }>; /** What the host hands the reader: never read from the package. */ export interface ModPackageSource { /** The bytes of `.claude-plugin/plugin.json` and of `hooks/hooks.json`. */ readonly plugin: Uint8Array; readonly hooks: Uint8Array; /** Reads the hooks module, named by its path inside the package (`hooks/…`, `/`-separated); asked once, after both manifests * are judged. It IS the containment: it must refuse a path that leaves the package directory, a link included — the reader * judges the name's form only, never where the bytes came from. What it throws comes out as thrown. */ readonly readModule: (path: string) => Uint8Array | Promise<Uint8Array>; /** The bus the host reads the package for. */ readonly side: ModBusSide; /** The digest the host pinned: other bytes are refused (`detail.digest { expected, actual }`) before a module byte is handed * out. A match proves the bytes are the pinned ones, nothing more: the digest is not admission. */ readonly expectDigest?: string; } /** A member of a manifest the reader does not read, by its name as written. */ export interface ModPackageUnreadMember { readonly file: string; readonly name: string; } /** A package read: its facts as it states them, and the bytes they were read from. */ export interface ModPackageRead { /** `plugin.json`'s `name` as stated (the kernel's screen judges it at admission). */ readonly name: unknown; /** `hooks.json`'s `uses`: every item selects a name on the host's side, one at least of that side's own. */ readonly uses: ModUses; /** `hooks.json`'s `contract` as stated: the importing copy compares it with its own `KERNEL_CONTRACT_VERSION`. */ readonly contract: unknown; /** The members of the two files the reader does not read (`plugin.json`'s first, each in its parsed object's key order; a member * of `hooks.json`'s `uses` other than `events` and `calls` by its dotted name, `uses.<name>`, after that file's own). */ readonly unread: readonly ModPackageUnreadMember[]; /** The hooks module's path inside the package (as `readModule` was asked for it) and its bytes, those the digest was taken over. */ readonly modulePath: string; readonly module: Uint8Array; /** The sha256 (lowercase hex) of the newline-joined sha256 of `plugin.json`, `hooks.json` and the module, in that order. */ readonly digest: string; } /** Read a package from its bytes; see the file's head. */ export declare function readModPackage(source: ModPackageSource): Promise<ModPackageRead>; /** A value's kind for a sentence — never a string's text. */ export declare function kind(v: unknown): string;