@sema-agent/core
Version:
Stateless, task-oriented AI agent core
99 lines (98 loc) • 9.07 kB
JavaScript
import { codedRefusal } from "./thrown-value.js";
function presentAt(at, steps) {
if (steps.length === 0)
return at !== undefined;
if (at === null || (typeof at !== "object" && typeof at !== "function"))
return false;
const [step, ...rest] = steps;
if (!step.endsWith("[]"))
return presentAt(Reflect.get(at, step), rest);
const items = Reflect.get(at, step.slice(0, -2));
return Array.isArray(items) && items.some((item) => presentAt(item, rest));
}
export function retiredKeyOf(bag, table) {
for (const [key, replacement] of Object.entries(table)) {
if (presentAt(bag, key.split(".")))
return { key, replacement };
}
return undefined;
}
export function assertNoRetiredKeys(bag, table, owner) {
const hit = retiredKeyOf(bag, table);
if (hit !== undefined)
throw retiredKeyRefusal(hit, owner);
}
export function retiredKeyRefusal(hit, owner) {
return codedRefusal(owner === "TaskSpec" ? "config.spec_retired_key" : "config.deps_retired_key", `${owner}.${hit.key} is retired and is not read by this engine — ${hit.replacement}. Refused rather than ignored: a seat that is silently dropped reads to the deployment as wired.`);
}
export const RETIRED_HOOKS_REPLACEMENT = 'the callback seats are `mods` registrations now — register the extension on `RunnerDeps.mods` (a deployment\'s) or `TaskSpec.mods` (a task\'s), hung on the `classic.*` events (`classic.PreToolUse`, `classic.PostToolUse`, `classic.PostToolBatch`, `classic.UserPromptSubmit`, `classic.Stop`, `classic.SubagentStop`, …); a callback that denied is a handler answering `{ action: "deny", message }`';
const SUMMARY_ON_MAIN_MODEL = "the compaction summary always runs on the task's main model and reuses the main request (same system prompt, tools and messages, one instruction appended), so no separate summary model, no window-safety tolerance and no fallback budget remain — drop the key";
export const RETIRED_TASK_SPEC_KEYS = Object.freeze({
hooks: RETIRED_HOOKS_REPLACEMENT,
autoModeRequested: 'the permission mode is one key now — write `permissionMode: "auto"`',
approverPosture: 'a posture never authorized anything; drop the key (the engine renders the posture from the effective mode). Releasing asks is a separate decision: `permissionMode: "bypassPermissions"`',
"attachments.planModeReminder": "the read-only planning posture is stated whenever the leg's mode is `plan` (first turn, every 5 turns, and an exit frame when it ends) — drop the key",
promptProvider: "a task changes prompt text through overlays: its role text is `systemPrompt` (it replaces the role base `promptRole` selects), its added block `appendSystemPrompt`, the minimal form `promptForm: \"minimal\"`; anything else is a `prompt.compose` registration on the task's own `mods` answering `{ overlays }` (an already-assembled prompt is refused, never passed through)",
promptProfile: 'the prompt\'s shape is the `lean_prompt` trait now — write `promptLean: false` for the long (classic) shape, `promptLean: true` (or nothing, on a model that declares `lean_prompt`) for the lean one',
rewindFiles: "capture needs no request (first-touch tracking is on whenever `RunnerDeps.fileHistoryStore` is wired and neither `RunnerDeps.fileHistoryCapture` nor `TaskSpec.fileHistory` turns it off); to restore files with the conversation write `resumeAt` + `restoreFiles: true`, for a code-only restore `rewindFilesTo` — drop the key",
compactionModel: SUMMARY_ON_MAIN_MODEL,
projectId: "a leg's project is one seat now — write `project: { id }` (the same UUID, as `TaskSpec.project.id`); the project's texts (`name`, `description`, `instructions`, `files`) ride that seat beside it",
});
export const RETIRED_SKILLS_SEAT_KEYS = Object.freeze({
"skills[].manifest": "a skill's tools are its `allowedTools` / `disallowedTools` now — an allow-rule and a deny-rule source for the run the skill is activated in, never a fence; move `manifest.allowTools` to `allowedTools`. To fence tools write deny rules (or a delegated agent definition's `allowTools`); to fence write paths use session `allowDirs`",
});
export const RETIRED_COMPACTION_SEAT_KEYS = Object.freeze({
enabled: "compaction is switched by two seats now — `autoCompact` (the passes the engine starts by itself: the turn-boundary pass at the window threshold, a prompt-too-long or guard recovery pass, the end-of-task summary) and `manualCompact` (the passes a caller asks for: `TaskStream.compact`, `Runner.compactSession`, `$.session.compact`). Write the seat you mean; `enabled: false` switched off both",
clampTolerance: SUMMARY_ON_MAIN_MODEL,
});
export const RETIRED_COMPACT_SESSION_KEYS = Object.freeze({
compactionModel: SUMMARY_ON_MAIN_MODEL,
});
export const RETIRED_MAYBE_COMPACT_KEYS = Object.freeze({
compactionModel: SUMMARY_ON_MAIN_MODEL,
fallbackBudget: SUMMARY_ON_MAIN_MODEL,
onWindowSafety: SUMMARY_ON_MAIN_MODEL,
});
export const RETIRED_INSTRUCTION_FAMILY_KEYS = Object.freeze({
rulesDir: 'the rules directories are one list now — write `rulesDirs: [".claude/rules"]` (each directory listed is read, in the order written)',
"alternate.rulesDir": 'the second family\'s rules directories are one list now — write `alternate.rulesDirs: [".claude/rules"]` (each directory listed is read, in the order written)',
"hostRules[].paths": "a host text's condition is read from the text itself now — put the globs in its frontmatter (`paths:`) and mark the entry `rule: true` (a text from a rules directory); an entry without `rule: true` is delivered on every load, its frontmatter dropped",
});
export const RETIRED_TOOL_SPEC_KEYS = Object.freeze({
descriptionClassic: 'a description\'s other forms are `descriptionVariants` now — the long form is `{ id: "classic", traits: { noneOf: ["lean_prompt"] }, text }`, chosen at mount by the run\'s prompt traits',
});
export const RETIRED_MODEL_KEYS = Object.freeze({
promptGuidance: "a model selects prompt text by its traits now — declare them in `Model.promptTraits` (the reference's capability names, or a deployment's own `x-<namespace>-<name>`); text meant for one model is an overlay (a center artifact's `add` to the `behavior` band, or a `prompt.compose` registration) whose `when.traits.allOf` names that trait",
});
export const RETIRED_TOOL_POLICY_KEYS = Object.freeze({
writeTargetGuard: "the guarded write targets are stated as rows now — `ToolPolicy.writeGuardRows`, an async provider of the one path table's `PathGuardRow`s the leg's ONE write judgment reads for every writer the policy cannot see as a call (the shell's file commands). A wrapper carries it through `wrapToolPolicy`, which reads every member a policy declares",
});
export const RETIRED_SHELL_READ_BOUNDARY_KEYS = Object.freeze({
writeProtectionJudge: 'the station asks ONE write judgment, `ShellReadBoundary.writeTargetJudge`, over the write-protection table and the deployment\'s guarded write rows together — it answers `"protected"`, `"guarded"` or `undefined`, not a boolean',
writeTargetGuard: 'the deployment\'s guarded write rows join the same one judgment, `ShellReadBoundary.writeTargetJudge` (`"guarded"` for a target a `ToolPolicy.writeGuardRows` row covers) — the boundary has no second write seat',
});
const GUARDS_ARE_ENGINE_FINDINGS = "state `requiresRealApproval: true` for a person's confirmation — the integrity guards are the engine's findings, carried on its attestation record (install the engine's guard policy for one)";
export const RETIRED_DECISION_MEMBERS = Object.freeze({
reason: 'rename it to "message" (the one text field a decision carries)',
guard: GUARDS_ARE_ENGINE_FINDINGS,
guards: GUARDS_ARE_ENGINE_FINDINGS,
foldedAskClasses: "the classes of the asks a policy fold collapsed ride the engine's attestation record that combinePolicies writes (a spread of its answer keeps the record); a policy does not state them",
});
export function assertNoRetiredToolPolicyKeys(policy) {
if (policy === undefined || policy === null)
return;
const isRecord = typeof policy === "object" && !Array.isArray(policy);
if (isRecord)
assertNoRetiredKeys(policy, RETIRED_TOOL_POLICY_KEYS, "ToolPolicy");
const check = isRecord ? policy.check : undefined;
if (typeof check !== "function") {
const got = typeof policy !== "object" ? typeof policy : Array.isArray(policy) ? "an array" : `an object whose check is ${check === null ? "null" : typeof check}`;
const e = new Error(`ToolPolicy must be an object whose \`check\` is a function (got ${got}) — a policy the engine cannot call is refused rather than run as no policy; omit the seat for none.`);
e.code = "config.invalid_argument";
e.detail = { field: "ToolPolicy" };
throw e;
}
}
export function assertNoRetiredShellReadBoundaryKeys(boundary) {
assertNoRetiredKeys(boundary, RETIRED_SHELL_READ_BOUNDARY_KEYS, "ShellReadBoundary");
}