UNPKG

@sema-agent/core

Version:

Stateless, task-oriented AI agent core

67 lines (66 loc) • 4.9 kB
import type { WorkflowGovernanceBaseline } from "../core/types.js"; /** * design/98 §6.3 — the ONE reading of "is this governance baseline usable", shared by the deployment * CAPABILITY predicate (`workflowsCapability`, which drives the surfaced `/workflows` affordance AND * the orchestration-prompt injection) and the MOUNT-time validator (`createRunWorkflowTool`, which * refuses loudly with a code). The reading is a receipt ({@link receiveGovernanceBaseline}): the baseline * read once, whole, and judged once — the mount's children are built from the copy it returns, the * capability predicate reads its verdict. * * Why one function rather than two agreeing predicates: this seam split three times inside one * release window, each time one level deeper. First the capability tested `!== undefined` while the * mount tested truthiness (a JSON `null` announced workflows the tool never mounted). Then both * tested the container while the mount refused an unusable `base` SLOT (`{ base: null }` announced * workflows that hard-failed every opted-in task). Then the slot readings agreed but the mount * additionally refused a malformed `worktreeBase` and malformed face lists — the same split again, * one field further in. Two predicates that must "stay in agreement" are a standing invitation to * drift; the only shape that cannot drift is a single function both call. * * The contract: {@link governanceBaselineProblem} returns `null` when the mount would SUCCEED, and * a describable problem when the mount would REFUSE. Every mount-time refusal must be reachable * from here, so a deployment is never told it has workflows it cannot actually run. */ export interface GovernanceBaselineProblem { /** Which slot/field is wrong, in the spelling a deployment configures (`base.excludeTools`). */ readonly where: string; /** What was found there, for the operator-facing message (`null`, `a string`, `an array`). */ readonly found: string; /** What the slot must hold instead, for the same message (`a spec object`, `an array of tool names`). */ readonly expected: string; /** The coded refusal the mount raises for this problem: the baseline's own two codes, or the code of the door that judges the * member (a spec member the engine does not read, a member whose read throws, a server or peer declaration its door refuses). */ readonly code: string; } /** The one word `WorkflowGovernanceBaseline.workflowModelAllowlist` takes besides a list of names: the names a script may * pick are the entries of the catalog the leg runs under (see `workflowModelNamesOf`). */ export declare const WORKFLOW_MODELS_FOLLOW_CATALOG = "catalog"; /** Name a bad value WITHOUT throwing on it (a bigint / cyclic object / poisoned `toJSON` must not * crash the describer and cost the refusal its name). */ export declare function describeBaselineValue(v: unknown): string; /** The judgment above as a guard, for a reader of the names: a value the mount refuses is no allowlist at all. */ export declare function isWellFormedModelAllowlist(v: unknown): v is readonly string[] | typeof WORKFLOW_MODELS_FOLLOW_CATALOG | null | undefined; /** What one read of a governance baseline answered: the copy every reader takes, or the problem the mount refuses for. */ export type GovernanceBaselineReceipt = { readonly baseline: WorkflowGovernanceBaseline; } | { readonly problem: GovernanceBaselineProblem; }; /** * The single validity reading, as a receipt: the baseline read once, whole, and judged once. What the mount builds its children from, * what the Workflow tool records it carries and what the capability predicate reads are this one copy — a member changed on the * deployment's object afterwards reaches none of them (the next mount reads it again). * * `base` is the control plane every script-spawned child inherits, so a non-object there refuses: * ungoverned is spelled by not configuring `workflowGovernanceBaseline` at all, never by an * unusable anchor. `worktreeBase` is the optional overlay whose documented absence means "base * governs every child" — `null`/absent is that absence, any other non-object is garbage and refuses * rather than impersonating either absence or an overlay. A slot member its door refuses refuses the * baseline, by that door's code ({@link receiveSlot}). */ export declare function receiveGovernanceBaseline(baseline: unknown): GovernanceBaselineReceipt; /** The receipt's verdict: `null` ⇒ the mount would succeed ⇒ the capability may be announced. */ export declare function governanceBaselineProblem(baseline: unknown): GovernanceBaselineProblem | null; /** The mount's refusal, minted from the shared reading so the message and the code have one home. */ export declare function governanceBaselineError(p: GovernanceBaselineProblem): Error & { code: string; };