UNPKG

@sema-agent/core

Version:

Stateless, task-oriented AI agent core

118 lines (117 loc) • 8.48 kB
/** * The STATIC TOOL CATALOG (design/388 §2.1 "静态目录"): one row per built-in / synthetic tool DEFINITION * core owns — its wire name, the conditions core (or a host scenario factory) mounts it under, the * `details.type` cards it mints, and its declared FACE (family / boundary legs / axes / contract / path target / rule * vocabulary / render hints / policy bits). * * SINGLE SOURCE, TWO READERS. Each definition module spreads its row's `face` into the `ToolSpec` it * hands `defineTool` (`...TOOL_FACES.read`), so the face a tool declares at mount time IS the face * listed here — there is no second declaration to drift (a definition whose schema is built per mount leaves its row's rule * `params` to the static view, `mountRuleFace`). The effect roster (tool-roster.ts) reads every * axis off the MOUNTED INSTANCE; the static catalog (`describeToolCatalog()`) reads this table without * an env or a deps object. The conformance gate (test/tool-catalog-conformance.test.ts) proves the two * agree for every definition it can instantiate; the catalog completeness gate * (scripts/verify-tool-catalog.mjs) proves every `defineTool` site in src/ that mints a core-owned name * has a row here that declares a `family` — a missing declaration is a RED gate naming the file, never a * silent `"other"`. * * LEAF MODULE by design: it imports vocabulary types and one leaf constant module only. Every definition * module and every policy module that derives a name set from the catalog imports THIS file, so a * dependency from here back into a tool module would be a load-order cycle with a `const` table in it. * * Keyed by DEFINITION identity (`id`), not by name — the full and the read-only shell both answer to * `Bash`; a catalog predicate counts a name as a member when ANY row under that name matches. */ import type { ToolCatalogEntry, ToolFaceDeclaration } from "./tool-face.js"; /** The full shell's contract id — declared here (the leaf) and re-exported by fs-bash.ts. */ export declare const FULL_SHELL_CONTRACT_ID = "core.bash@1"; export declare const READONLY_SHELL_CONTRACT_ID = "core.bash_readonly@1"; /** Wire-name constants for definitions that had none (design/388 A-21: literals become references). */ export declare const TASK_CREATE_TOOL_NAME = "TaskCreate"; export declare const TASK_GET_TOOL_NAME = "TaskGet"; export declare const TASK_UPDATE_TOOL_NAME = "TaskUpdate"; export declare const TASK_LIST_TOOL_NAME = "TaskList"; export declare const TODO_WRITE_TOOL_NAME = "TodoWrite"; /** Reserved name of the injected structured-output tool (`StructuredOutput`). The name it retired, `submit_output`, resolves to * nothing: the retired-name table (`RETIRED_TOOL_NAMES`) only tells a caller this one. */ export declare const OUTPUT_TOOL_NAME = "StructuredOutput"; export declare const REFRESH_MCP_TOOLS_TOOL_NAME = "RefreshMcpTools"; export declare const ARTIFACT_TOOL_NAME = "Artifact"; /** * Every row. Order is documentation order (hands → delegation → scaffolds → memory → scheduler → host * scenarios); nothing reads the order. A row's rule `params` is its definition's FULLEST mount's scalar vocabulary, the * static view's (`catalogRuleFaceOf`); a row that declares none (StructuredOutput: its schema is each task's) can be judged * on a leg only. */ export declare const TOOL_CATALOG_ENTRIES: readonly ToolCatalogEntry[]; /** * `details.type` cards the ENGINE mints outside any tool definition — the protocol channels' result * cards and the fs boundary refusals (minted by the shared safety module on behalf of every fs tool). */ export declare const ENGINE_CARDS: Readonly<Record<string, string>>; /** * Each engine card's SKELETON — what rides `tool_end.structuredSkeleton` when the card itself is over the frame's card * bound: `type` plus the members named here, copied as the mint wrote them (a dotted name reaches into a nested object; * a member the card does not carry is simply absent). Only members whose size does not grow with content are named — * paths, ids, closed words, counts, digests — so a kind whose every other member is content has an empty row. One row per * card the engine mints, no row without one: the catalog refuses itself below otherwise. A caller-declared card has no * row; its skeleton is `{ type }`. */ export declare const CARD_SKELETONS: Readonly<Record<string, readonly string[]>>; /** The declared face of one definition, by definition id — what a definition module spreads into its spec. */ export declare function toolFace(id: string): ToolFaceDeclaration; /** Is `contract` a contract object the catalog minted for an engine definition ({@link toolFace}) — the one record of "the engine * declared this", which a value written by hand (the same id spelled out) is not. */ export declare function isCatalogContract(contract: unknown): boolean; /** * "Does this call dispatch to the ENGINE's own instance of one of these definitions?" — the one judge, read off the call's face: * one of the engine's own mount sites mounted the tool (`engineMounted`, the one identity a caller cannot wear), and the * contract it carries is the one the catalog gives one of `ids`. Never the name or the contract alone: a caller's tool can take * an engine name, and a contract id can be written by hand. False for every other call — a caller's or a protocol peer's tool, * a face rebuilt from a park row minted before the row recorded its mount site, a bare request (no face). A row minted since * carries the mount site its roster entry had at the park, so the pre-claim recheck of its edit reads this judge's answer at park time. */ export declare function engineMountedAs(ids: readonly string[]): (face: { readonly engineMounted?: true; readonly contractId: string; } | undefined) => boolean; /** Is this call's face the engine's own shell tool (either of its two mounts)? */ export declare const isEngineShellFace: (face: { readonly engineMounted?: true; readonly contractId: string; } | undefined) => boolean; /** Is this call's face one of the content-routing tools the engine mounts (question, answer, blocked report)? They route content, * act on nothing, and no stored rule governs them: the persisted-rule lane does not judge them and their card offers no rule. */ export declare const routesContent: (face: { readonly engineMounted?: true; readonly contractId: string; } | undefined) => boolean; /** * The rule face a definition whose schema is BUILT PER MOUNT puts on its instance: its row's primaries only (none ⇒ no rule * face). The row's `params` is the static view's vocabulary, the fullest mount's; a mount's own is read off the schema it * carries — whatever a summarizer, a host's capabilities or a host's own schema made it (`ruleFaceOfInstance`). */ export declare function mountRuleFace(id: string): { primaryParams: string[]; } | undefined; /** Definition-id → face, for the modules that spread one (`...TOOL_FACES.read`). Frozen: a face is data. */ export declare const TOOL_FACES: Readonly<Record<string, ToolFaceDeclaration>>; /** * The engine's own tool names, once each: every catalog entry the engine mounts itself (`source: "builtin"` — the hands, * the scaffolds, the memory tools, the background-task tools), whatever face or contract it is mounted under. A host that * must hand the engine a tool face with NO built-ins (`TaskSpec.excludeTools`, a shell's `--tools ""`) reads this set * instead of keeping a list of its own: the catalog is the one source, and a name the engine adds later lands here with it. */ export declare const ENGINE_BUILTIN_TOOL_NAMES: readonly string[]; /** * EVERY tool the catalog describes, once per wire name, with the other spellings it answers to — the engine's side of the one * universe a delegated child's tool-name lists govern (beside the tools the delegation tool hands it and the protocol tools * its spawning run mounts). The spawn reads this set rather than a list of its own: a definition a catalog row adds later is * governed the day it lands, whatever band mounts it. */ export declare const ENGINE_TOOLS: ReadonlyArray<{ readonly name: string; readonly aliases?: readonly string[]; }>; /** Is this name one the engine mounts itself ({@link ENGINE_BUILTIN_TOOL_NAMES})? A caller tool, an MCP tool or a skill tool is not. */ export declare function isEngineBuiltinToolName(name: string): boolean;