UNPKG

@sema-agent/core

Version:

Stateless, task-oriented AI agent core

225 lines (224 loc) • 15.5 kB
/** * The prompt catalog's shape: every model-visible system-prompt text is one catalog MESSAGE, placed into * the system prompt by a catalog SECTION, and chosen among its VARIANTS by a closed selector (traits and * facts). Catalog entries are literal data — no closures — so the catalog is hashable as a whole and the * hash moves whenever any field of any entry moves. * * What stays code is a RENDERER (renderers.ts): a section whose bytes come from prepare-time inputs (the * role base the caller chose, the environment tail, the memory tail, the MCP instructions frame, the * reminder-mark declaration). Renderers carry a version; changing a renderer's output means bumping it. */ /** The band a placed message belongs to: a POLICY class (who may write it, which sink it reaches), never a position. * A section's position is its own `rank`. `event-copy` and `event-mechanism` hold the messages an event frame is worded * with (placed by the event registry's rows; the row's switch picks which), `engine` the engine's own messages * (`catalog/engine.ts`); none of the three is ever a manifest's or a description's section band. */ export type BandId = "role" | "scenario" | "task-append" | "behavior" | "core-behavior" | "constitution" | "discovery" | "environment" | "memory" | "event-copy" | "event-mechanism" | "engine"; /** The source classes that write a band through overlays; `bundled` is the catalog itself. */ export type OverlaySource = "center" | "deploy" | "task"; /** Whether `v` is one of a closed set's words — the one membership reading the selector vocabularies share. */ export declare function isWordOf<W extends string>(words: readonly W[], v: unknown): v is W; /** The four overlay operations (a closed set; docs/CLOSED-SETS.md). */ export declare const OVERLAY_OPS: readonly ["replace", "append", "add", "drop"]; export type OverlayOp = (typeof OVERLAY_OPS)[number]; export interface BandRow { readonly id: BandId; /** The policy class in words (the band table's first column). */ readonly policy: "overridable" | "add-only" | "overridable-restricted" | "locked" | "fact"; /** The ops each overlay source may apply in this band. All empty ⇒ the band is locked. */ readonly ops: Readonly<Record<OverlaySource, readonly OverlayOp[]>>; /** Where an `add` lands, when the band admits one. */ readonly addRank?: number; /** The one mods event whose answers may write this band (absent ⇒ no mods event writes it). */ readonly modsEvent?: "prompt.compose" | "prompt.section"; } /** The host role a run is assembled for — which role base `core/role.base` selects. Written by whoever builds the * task (`TaskSpec.promptRole`); absent ⇒ `general`. */ export declare const HOST_ROLES: readonly ["general", "code", "coordinator", "cowork"]; export type HostRole = (typeof HOST_ROLES)[number]; /** Membership test for {@link HostRole} — the one reading of "is this a role base the engine selects": the task door * (`TaskSpec.promptRole`) and the overlay grammar (`when.host.role`) both ask it. */ export declare function isHostRole(v: unknown): v is HostRole; /** The host form: `minimal` leaves the core-behavior band out (the locked bands stay). Written only by * `TaskSpec.promptForm`; absent ⇒ `standard`. */ export declare const HOST_FORMS: readonly ["standard", "minimal"]; export type HostForm = (typeof HOST_FORMS)[number]; export interface HostCondition { readonly role?: HostRole; readonly form?: HostForm; } /** * The model-capability traits a variant may be selected on, in two kinds: * - the reference's capability names that gate model-visible text, spelled as the reference spells them so an anchor * upgrade diffs mechanically (`IWs` cli321.js B[8878073,8878925) is the reference's whole capability list; its * members that gate no text we carry — effort, thinking, context-management, fast-mode and refusal-fallback bits, * host display switches, carriers the engine does not have, vendor product limitations — are not prompt traits); * - stand-ins for text the reference gates on the model id rather than on a capability (the per-version identity * texts and the research-capability note), named after the reference's section ids; and `read_before_edit`, the * reference's older models (its fixed id list) that a write tool still holds to a Read of the file first — the one * stand-in that also gates a tool's behavior: a run whose model lacks it lets Edit / Write change a file it has not * read when the model's own Read of it would be served with nobody asked, and its Edit / Write cards say so. * Which reference name is carried, which is not and why, and that the list follows the current anchor, is checked by * gate:prompt-trait-anchor (scripts/prompt-trait-anchor.json). A model declares the traits it would light * (`Model.promptTraits`; a host may copy the reference's declaration from `REFERENCE_MODEL_PROMPT_TRAITS`); the * engine never derives them from a model id. Order is meaning only for the artifact requirement list (`requiresOf`), * which lists the names it needs in this order, so a name is appended here, never inserted. */ export declare const PROMPT_TRAITS: readonly ["lean_prompt", "fable_5_mitigations", "thrifty_sonic", "turn_updates", "silent_turn_reminder", "amber_astrolabe", "bison_cairn", "larch_cistern", "haiku_5_5_early_stopping_guidance", "elapsed_time_reminder", "timed_silent_turn_reminder", "finishing_work_guidance", "memory_guidance", "fable_identity_5", "fable_identity_5_1", "fable_identity_5_2", "llm_rnd_capabilities", "read_before_edit"]; export type PromptTrait = (typeof PROMPT_TRAITS)[number]; /** * The reference's bundle capabilities and the carried traits each lights: the reference's member set less the names * this vocabulary does not carry (`kT` cli321.js B[13714690,13715686) reads its four member sets). A model may declare * a bundle by name; its effective trait set holds the bundle name and every member. No remote switch turns a member off * here: a deployment that wants one member off declares the members it wants. */ export declare const PROMPT_TRAIT_BUNDLES: Readonly<Record<"fable_5_1_prompt_bundle" | "opus_5_prompt_bundle" | "opus_5_5_prompt_bundle" | "fable_5_2_prompt_bundle", readonly PromptTrait[]>>; export type PromptTraitBundle = keyof typeof PROMPT_TRAIT_BUNDLES; /** * Trait groups a model holds at most one name of (bundle members counted): the per-version identity stand-ins, each a * different text about which model it is — the catalog takes the first variant whose condition holds, so a model * holding two would receive one of them by declaration order. The model door refuses such a model by name * (`config.prompt_trait_unknown`). */ export declare const PROMPT_TRAIT_EXCLUSIVE_GROUPS: readonly (readonly PromptTrait[])[]; /** A deployment's own trait: `x-<namespace>-<name>`. The engine checks the spelling and gives it no meaning — an * overlay whose `when.traits` names it is what makes it select anything. */ export type DeploymentPromptTrait = `x-${string}-${string}`; /** Every name a model may declare and an overlay's `when.traits` may name. */ export type PromptTraitName = PromptTrait | PromptTraitBundle | DeploymentPromptTrait; /** The names a bundled catalog variant may select on: the reference's (a deployment's own trait has no meaning in * the engine's text). */ export type CatalogPromptTrait = PromptTrait | PromptTraitBundle; /** The longest trait name the engine accepts. */ export declare const PROMPT_TRAIT_NAME_MAX = 64; /** Whether a value is a trait name — the one reading the model door (`Model.promptTraits`), the overlay grammar * (`when.traits`) and the artifact requirement check share: a reference trait, a bundle, or a deployment's own * `x-<namespace>-<name>` of at most {@link PROMPT_TRAIT_NAME_MAX} characters. */ export declare function isPromptTraitName(v: unknown): v is PromptTraitName; /** The members a trait name lights besides itself (a bundle's members; none for any other name). */ export declare function bundleMembersOf(name: PromptTraitName): readonly PromptTrait[]; /** The boolean facts a section admit or a variant `when` may test. All but the last three are runtime facts the * prepare phase produces; the last three are derived once (`catalogFactsOf`), so no `when` ever needs a disjunction: * `executionEnvironmentDeclared` from two of them, `workToolsAbsent` (the face leaves nothing for the work: no tool to act * through and none to hand the result out through) and `actingToolsAbsent` (no tool to act through) from the tool-face class. * An optional fact that is absent reads as `false`. */ export declare const PROMPT_FACT_NAMES: readonly ["policyEnabled", "hooksEnabled", "isolationEnabled", "readFaceOpen", "writeFaceOpen", "withinTaskCompactionEnabled", "supervisorEnabled", "orchestrationEnabled", "orchestrationDeferred", "awarenessEnabled", "goalEnabled", "worktreeIsolated", "teammateEnabled", "isSubagent", "memoryStoreAbsent", "skillToolMounted", "shellFirstSession", "executionEnvironmentDeclared", "workToolsAbsent", "actingToolsAbsent"]; export type PromptFactName = (typeof PROMPT_FACT_NAMES)[number]; /** The prompt facts a tool card's description variant may select on: the ones known where the cards are mounted (before the * assembly that forms the rest). */ export declare const TOOL_CARD_FACT_NAMES: readonly ["shellFirstSession"]; export type ToolCardFactName = (typeof TOOL_CARD_FACT_NAMES)[number]; /** A conjunction of fact equalities — the whole predicate language. No disjunction, no expressions. */ export type FactConjunction = Readonly<Partial<Record<PromptFactName, boolean>>>; /** The bundled catalog's two tool-face conjunctions, one spelling each. A message that words a leg left nothing to act through * differently carries the pair as two variants, one reading each — mutually exclusive, so which of the two holds never depends on * their order, and the message's first variant stays the text it had before the pair (what `catalogText` returns when no variant is * named). */ export declare const ACTING_FACE: FactConjunction; export declare const ANSWERING_FACE: FactConjunction; export interface TraitCondition { readonly allOf?: readonly PromptTraitName[]; readonly noneOf?: readonly PromptTraitName[]; } /** How a text relates to the reference. `cc` entries use the byte-span locator grammar the anchor gate resolves * (scripts/verify-anchor-claims.mjs): corpus file, byte span, and a backticked identifier that occurs in it. */ export interface Attribution { readonly form: "verbatim" | "adapted" | "sema-owned"; readonly cc?: readonly string[]; } export interface Variant { /** Reported in the manifest — one of the answers to "why this sentence". */ readonly id: string; readonly when: CatalogVariantWhen; readonly text: string; } /** A condition on the run's binding (`TaskSpec.promptBinding`, a deployment's scenario name): exactly one list. A run * with no binding is outside every `anyOf` and inside every `noneOf`. */ export type BindingCondition = { readonly anyOf: readonly string[]; readonly noneOf?: never; } | { readonly noneOf: readonly string[]; readonly anyOf?: never; }; /** The selector condition a variant (or an overlay) is chosen on: a conjunction over traits, host, facts and binding. */ export interface VariantWhen { readonly traits?: TraitCondition; readonly host?: HostCondition; readonly facts?: FactConjunction; readonly binding?: BindingCondition; } /** The condition a BUNDLED catalog variant is chosen on: a {@link VariantWhen} without the binding, its traits the * reference's. A binding and an `x-` trait are a deployment's own vocabulary (names the engine cannot know), so no * catalog variant can name one — the type refuses it where the catalog data is written. */ export type CatalogVariantWhen = Omit<VariantWhen, "binding" | "traits"> & { readonly traits?: { readonly allOf?: readonly CatalogPromptTrait[]; readonly noneOf?: readonly CatalogPromptTrait[]; }; }; export interface CatalogMessage { /** `core/<area>.<name>`. */ readonly id: string; /** Variants in declaration order; the first whose `when` holds is selected. None holds ⇒ the message is absent. */ readonly variants: readonly [Variant, ...Variant[]]; readonly attribution: Attribution; /** The message states a permission, refusal, authorization or boundary rule outside the locked bands: every * rendering of it is reviewed by a native reader before a release carries it (`reviewBeforeRelease`). */ readonly securityBearing?: true; } /** * The renderings a run's catalog text is read in. `canonical` is the catalog's own text (the variant as written); every * other word names a whole rendering of the catalog — a word is in this set only when the catalog carries a rendering of * every variant of every message in it. Written only by `TaskSpec.promptLocale`; absent ⇒ `canonical`. */ export declare const PROMPT_LOCALES: readonly ["canonical", "zh-Hans"]; export type PromptLocale = (typeof PROMPT_LOCALES)[number]; /** A locale that is a rendering of the catalog rather than its own text. */ export type RenderedLocale = Exclude<PromptLocale, "canonical">; /** One variant's rendering in one locale, bound to the source text it was written from. */ export interface LocaleRendering { /** `sha256:<hex>` of the variant text this rendering was written from. */ readonly sourceDigest: string; readonly text: string; } /** A locale's renderings: message id → variant id → rendering. */ export type LocalePack = Readonly<Record<string, Readonly<Record<string, LocaleRendering>>>>; /** The renderers the catalog may place by id — data here, so the catalog checks its sections without loading the * renderer code; renderers.ts holds the code and the version table, one row per id (its record type is total). */ export declare const RENDERER_IDS: readonly ["role-base", "mcp-instructions", "reminder-mark", "environment", "memory"]; export type RendererId = (typeof RENDERER_IDS)[number]; export type SectionBody = { readonly message: string; } /** One message per line, each with an optional line-level admit, joined by `joiner`. */ | { readonly lines: readonly { readonly message: string; readonly admit?: FactConjunction; }[]; readonly joiner: "\n" | "\n\n"; } | { readonly renderer: RendererId; }; export interface CatalogSection { /** `core/…` — the id the manifest, `context_usage` and the center tier read. */ readonly id: string; readonly band: BandId; /** Global emission order (unique). */ readonly rank: number; /** The `prompt.assembled` block view: adjacent sections sharing a block id merge into one block. */ readonly block: { readonly id: string; readonly joiner?: "\n" | "\n\n"; }; readonly admit?: FactConjunction; readonly body: SectionBody; } export interface PromptCatalog { readonly id: string; readonly bands: readonly BandRow[]; readonly messages: readonly CatalogMessage[]; readonly sections: readonly CatalogSection[]; /** One whole rendering per {@link RenderedLocale}: every variant of every message, each bound to its source text. */ readonly locales: Readonly<Record<RenderedLocale, LocalePack>>; }