UNPKG

@sema-agent/core

Version:

Stateless, task-oriented AI agent core

239 lines (238 loc) • 29.5 kB
/** * The engine build's capability words — the one home for "this engine does X". A shell gates on a word, never on a * version number; the server projects the words it also wires onto its `/v1/capabilities`. * * A word is added in the release whose code makes it true and is never re-spelt; a word whose behaviour is retired * leaves the set in a breaking release. Each word: * - `inherit_env.own_credentials_withheld` — a child spawned on this host never inherits a name the deployment * declared as its own credential (`declareWithheldEnv`): `inheritedHostEnv` subtracts the list from every policy's * result (`"all"` and `"scrub"` alike), and an allow list naming one is refused (`inheritEnvPolicyProblem`; every * spawn throws it). The word speaks of INHERITANCE only: the engine process's own environment stays readable to * same-user processes on the host (`ps -E`), so a credential that never enters it remains the root fix. * - `inherit_env.own_credential_values_withheld` — a child spawned on this host never inherits an env entry whose * value equals a credential value the deployment declared or the engine holds: `declareWithheldEnv` takes one table * `{ names, values }`, the engine adds the credentials it takes in, where it receives them (a first-party brain's * `apiKey` and credential headers, a model entry's credential headers, a protocol peer's credential headers, the * memory distiller's chat seat key), and `inheritedHostEnv` subtracts every entry whose value is one, * compared whole, under every policy. A credential resolved per request (a per-model auth hook's answer) is not in * it: the host that resolves it declares it. The same inheritance-only reading as the word above. * - `mods.skill_seat` — a skill carries its own hooks: `SkillSpec.mods` registrations are admitted on every leg that loads * the skill and take part only while the skill is active there (from its activation to the run's end, a park and its * resume included); they are the leg's own (no delegated child dispatches them or is screened by them). * - `user_attachments.read_state` — a request de-duplicates a `path` attachment's copies, and only those * (`request-copy-projection.ts`; THE one statement of this word — the docs and the outcome type point here): a * `path` attachment frame in a request is its contents, or the "not repeated" sentence beside an earlier copy of the * same contents in that same request (an earlier frame, or a Read result; no write call to the file between, both * whole and non-empty), or — a whole frame of a file the leg seeded into its system prompt, unchanged — the "already * in your context" sentence, or a pointer sentence that says only that the contents are not included. The earlier * copy a "not repeated" sentence stands beside is always in that same request — never one a compaction summarized, * the stale-result clear emptied, the trim left out or an earlier request carried: the request's own view is judged * after they took what they took, so a frame whose earlier copy is gone carries the contents. A Read result is its * contents on every request — a repeated Read costs its contents — or the pointer sentence. Across the two carriers: * a Read, then an attachment of the same unchanged file ⇒ the frame is the "not repeated" sentence and the Read's * contents are in that same request; an attachment, then a Read of it ⇒ the Read is its contents and the frame is * as it was. A pointer sentence comes only from a de-duplication sentence an earlier release stored, or from a running * request whose irreducible core cannot hold the contents. A host-held entry (`content_text`) is sent as given, * every time. * - `user_attachments.instruction_access` — a delivered `path` attachment of a file the Read tool records (a text file, * a notebook) is an access for the instruction-file lane (`TaskSpec.instructionFamily`), as a Read of the same file * is: the levels between the task root and the attached file owe their declared members from the request that * carries the attachment — that request's load is handed the attachment's read key and its frames ride after the * attachment's (what the load's probe and frame bounds defer rides the next request) — and on later requests as any * access's do. A member of the family that is itself attached as a `path` entry is not loaded beside it, and while the * conversation holds it as it is now a later access in its directory adds no copy of it. No access: a `path` * attachment that was not attached (a read rule refused it, it could not be read or bound) and one the read state * does not record (a directory listing, an image, a PDF) — the directory's members come with the run's first access * there. Not promised: a host-held entry (`content_text`, `content_image`) is no access and stands for no file — a * member of the family the host sends as text is sent as given, and the lane loads the file as it would without it * (a root's member on the same request, a member below the root at the first access in its directory). The word * speaks of the engine only; whether a run reads a family at all is the request's declaration (the manifest's * `projectMemory`). * - `task.wake` — the engine reads `TaskSpec.wake` (`TASK_WAKE_SOURCES`, one word today: `parked_notifications`): * `runTask({ objective: "", wake })` opens a leg on the notifications parked for this session's occupant and on nothing * else, each handed to the model once, and a wake with nothing handed over ends `config.nothing_to_wake` before any model * request. An engine without the word refuses the key (`config.spec_unknown_key`), so a shell that wakes a session gates * on the word. * - `file_history.recorded_place` — the ENGINE's invariant, true wherever the engine runs: a file version records the directory it * was recorded under (its absolute real path) and a rewind (`Runner.rewindFiles`, `rewindFilesTo`, `resumeAt` + `restoreFiles`) * writes or deletes it only there — never anywhere else. How each other file is answered is read off its row's `class`, never * off this word: left as it is (`leftAsIs`: `recorded_outside_root`, and the other classes of `FILE_HISTORY_LEFT_AS_IS_CLASSES`) * or refused (`recorded_elsewhere` with `recordedUnder`; `place_unrecorded` for a version that records none); a run that does not * accept a partial restore moves nothing when its plan finds a file it would refuse (the restore is planned first) — a refusal met * only while it writes (`changed_since_plan`, a write the guarded check refused) comes after other files were restored, and that * run fails `rewind.restore_failed` on a partly restored tree, every file it wrote named; the preview and the restore answer * `files`, one row per file. It says nothing about whether a host takes the input below. * - `file_history.unplaced_recorded_under` — the engine reads `unplacedHistoryRecordedUnder` (on `TaskSpec` and on * `Runner.rewindFiles`): an absolute path, or the word `"rewind_root"` (the rewind's own root, supplied by the engine), under which * a version that records no place is read as recorded. A host projects this word only where its own surface takes the input — the * word for "this deployment accepts it" — apart from `file_history.recorded_place`, which holds either way. * - `ask.workflow_member` — an ask a workflow member raises (`AskRequest`; a question, `AskQuestionRequest`) and the pending * row its card lists as (`CheckpointSummary`) carry `workflowRunId` (the run's id, the one its progress frames and member rows carry) and * `workflowAgentLabel` (a display word, not unique, unbounded by the engine — never a key), together, and * `workflowStepAskedAgain: true` beside them when the call runs a step again that the run it resumes already took up (its * earlier card stopped waiting without a decision — expired or removed — or the same call completed there and the replay * stopped before it; no cause told; a step approved and not executed is not it). With the word, absence on * an ask reads "not a workflow member", absence of the bit "not such a re-ask"; a pending row that no longer reads * carries none of them (unknown). Without the word, absence means nothing. * - `task.fast_mode` — the engine reads `TaskSpec.fastMode` and `Model.fastMode` and answers `TaskStream.setFastMode`: * a main-loop request asks for fast speed where the request's model declares it, is re-sent at standard speed when the * provider pushes back (a session-wide cooldown, or that model refused for the session), and the reading * (`fastModeReadingOf`) rides `wiring_manifest.fastMode`, `TaskResult.fastMode` and `model.fast_mode_changed`. An engine * without the word refuses the spec key (`config.spec_unknown_key`), so a shell that offers a fast-mode toggle gates on it. * - `task.agent_config_dirs` — the engine reads `TaskSpec.agentConfigDirs` (the caller's configuration roots): below every root the * rows that name the configuration directory are placed exactly as below `RunnerDeps.agentConfigDir` — the read deny rows that * open with `~/.sema/` and the always-on write-protection table's `.sema` rows — on every read face (the structured tools and the * shell's read station) and every write face that table judges; the roots only add to the deployment's, ride every engine-built * child and are recorded on a parked row (`CheckpointState.agentConfigDirs`, reader word `agent_config_dirs`); the leg's manifest * says how many roots it holds and where each came from (`declaredPlaces.agentConfigDirs`). An engine without the word refuses * the key (`config.spec_unknown_key`), so a host on an attached engine gates on the word and, without it, declares the files by * name through `TaskSpec.readDenyPatterns`. * - `task.agent_home_dirs` — the engine reads `TaskSpec.agentHomeDirs` (the caller's homes): the home-anchored read deny rows * (`~/…`) are placed below every one beside the engine's own homes, on every read face, the list only adding (recorded as * `CheckpointState.agentHomeDirs`, reader word `agent_home_dirs`; manifest `declaredPlaces.agentHomeDirs`). Nothing else reads * the list: the engine looks for no configuration, skill, instruction or memory there. An engine without the word refuses the * key (`config.spec_unknown_key`). * - `task_notification.note_key` — every `task_notification` event this engine pushes states `noteKey`, the key of the event's * own notification (`taskNotificationDedupKey(notification)`, a root export), on every road a notification takes: the live * lane when it is accepted, the turn-open redelivery of one parked while the session sat idle, and so for each producer behind * them (a background agent, fork or shell, a terminal the registry settles for a stopped child, a workflow, a host's `notify`, * a letter, an inbox line or a notice of the session box, a wake leg's blocks, the lines that say what the pending store * dropped). Wherever the model is handed that notification, the row that hands it over (`message_committed`, `role: "user"`, * `origin: "queued_note"`) states the same `noteKey`, so a host joins a frame to its row by equality and never computes the key. * A frame the model is never handed (a `session.receive` station consumed it; the leg ended before a turn took it) has the key * and no row. With the word, a `task_notification` without `noteKey` is not this engine's push (a relay's, or a projection that * dropped the member). Without the word, the key's absence says nothing: a host decides on the word, not on a version number. * - `task.continues_from` — every result this engine hands carries `TaskResult.continuesFrom` (a composition's included), and a value it * hands is taken by `resumeAt` with the `at` mode: the next run then continues from where that call left its session, the request it * sends the one a run continued without a rewind would have sent. Two things are refused, writing nothing: a store that loads a bounded * window refuses a landing whose branch it does not hold whole (`resume_at.outside_window`), and a value whose session the store evicted * is `resume_at.not_found`. The word does not cover the files: `restoreFiles` with a value is refused (`rewind_snapshot.unresolvable` — the * file history keeps its boundaries under the entry that opened a run, never under where one ended), so a redo moves the conversation only. * A `none` value has no landing to hand. A shell gates a redo ("continue where this call ended") on the word, never on the member's presence. * - `execution_env.workspace_sync` — the engine calls an execution environment's `syncWorkspace(reason, { abortSignal })` seat when * the env carries one (`src/core/remote-env.ts`, the seat's own statement): `"turn_end"` once per turn where the agent would * otherwise stop, at a durable park before the workspace is suspended or its identity captured, and at a leg's end when its env is * not destroyed and a turn ran since the last sync; `"destroy"` before it destroys a leg's own env at the leg's end and before * `Runner.rewindFiles` lets go of the env it rewound. A workspace is never synced twice at once; each wait is bounded; a failure * never changes a run's result and is told (`workspace.sync_failed`). With the word, a host whose adapter carries the seat keeps * the workspace there — and stops keeping it inside its own `destroy()`, so one sync has one writer. Without the word the seat is * never called. * - `session.rewind_conversation` — the engine answers `Runner.rewindConversation({ sessionId, to, dryRun?, lastSeenInput?, expect?, * checkpointStore? })`: a session's leaf is put back along its current branch, before the turn `to` (the person's words that opened it, * on that branch) began, with no model call and no run, answering `{ dryRun, leafId, previousLeafId }` — with `dryRun: true` the same * judgments, refusals and answer, and nothing written; and "before a turn" is the parent of those words for the first turn too — the * verb, and a run's `resumeAt` + `resumeAtMode: "before"`, accept the session's first message, landing on its prompt pin (only a message that * is the log's root has nothing before it, `resume_at.before_root_unsupported`). A shell that offers "take back what I just sent" or a * rewind to the first message gates on the word; an engine without it has no such method and refuses the first message as a "before" * target. * - `session_changes.checkpoints` — the engine answers `Runner.readSessionChanges({ sessionId, source, contentOf?, cwd?, expect?, * signal? })` for three file-history sources: `checkpoints` (the session's checkpoints on its current branch since its latest * compaction, newest first, each paired with the next one — the newest with the working tree — paged by `limit` / `before`, a * damaged checkpoint its own item `history_unreadable`), `checkpoint` (one listed pair, with the texts `contentOf` names) and `since` * (a checkpoint against the working tree: the rewind preview's own plan, read checkpoint → working tree). A pair's `after.skipped` * counts the runs in between that recorded no checkpoint — the rows that say they opened their run (`legFirstInput`) — and is absent, * never 0, when a row in between does not say it or the store has no `readBoundaries` (which, with `blobExchange`, a pair needs: * else `store_cannot_read`). It reads with no lock, gate or frame — a leg running on the session does not refuse it — and writes * nothing, not even a fork's carry (a fork's entry from before its history was carried is `no_checkpoint`). The working tree is read * on the deployment's static env or, on a deployment with a factory, the factory's env for purpose `"read_changes"`, asked only once * `RunnerDeps.executionEnvFactoryHonorsReadChanges` is `true` (until then, or when the factory refuses the purpose, * `files_env_unsupported`). A shell that shows "what changed since this checkpoint" or the rewind list's per-turn changes gates on * the word. * - `instruction_family.external_includes` — the engine reads `TaskSpec.instructionFamily.externalIncludes` as the project's approvals, * one per file: `false` or a list of absolute paths, each a value of the engine's own `instructions.withheld` notice * (`outside_its_root`) for that file, sent back as it came — its `detail.target` (the file: the approval is bound to where it really * lies; send this) or its `detail.path` (the path: a link later pointed at another file outside takes the approval to that file). * `true` (no approval covers every file), any other value, an entry that is not a string and an entry within `maxApprovedPathChars` * that is not an absolute path in the family its spelling names (`isAbsoluteForFamily`: a relative one, `~/`, empty) or holds a NUL * are refused `config.invalid_argument` naming the field (every value the engine itself tells is taken); the entries * past the first `NESTED_MEMORY_LANE.limits.maxApprovedPaths` and one over `maxApprovedPathChars` (whatever it holds) are not read * as approvals (the operator is told once). Three host states, two engine readings: a list = the host holds the person's approval of these files, * `false` = the host holds the person's explicit "no", absent = the host says nothing (its record cannot be read, or an older host); * the engine reads `false`, an empty list and absent the same way — nothing approved — because it can only fail closed. A file the * instruction-file lane finds by itself (an `@` include, a rules directory's file) that really lies, links followed, outside the root it * was found under and the task root is approved when its key is the one a listed path resolves to — both through the engine's own * resolution (links followed, the volume's own spelling), so a path the host spelled another way that names the same file approves it * and one that names another file approves nothing (the file stays withheld and is told — once per (path, reason, target) per * session — with the `detail.target` to send next time). * Approved, it is judged by the model's own Read admission alone — not withheld as `outside_its_root` — and what the read roots or a * read rule refuse is told as `outside_roots` / `rule_denied` as for any file; the include depth bound is unchanged. The approval is * read when a request is prepared and applies from that request on: a host that learns of an `outside_its_root` notice lists its * `detail.target` on its NEXT request, and the run that was told keeps its reading; the engine stores nothing. An `outside_its_root` * notice carries `detail.target` (the key the lane's resolution gave the file — equal to `path` for a plain file named by its real * spelling) whenever that resolution named a key; no other reason carries it. * An `instructions.withheld` notice raised for a file the lane reached through an `@` include (any reason) also carries * `detail.includedBy` (the including file's resolved absolute path) and `detail.spelled` (the path after the `@` as the engine read it: * a `#fragment` dropped, `\ ` read as a space); a notice raised for a rules directory's file or a declared member carries neither. The * same probed path reached both ways is told once per reason, by whichever probe reached it first (the told-once ledger is keyed on * the probed path and the reason, and for `outside_its_root` the target) — except a refusal for lying outside the roots: a queued found file's approval is the widest of the * edges that reached it, and such a refusal is told when the load ends, by its widest edge, only for a file no edge read in that load. * The word speaks of the engine: whether a project has * approved is the host's question. A shell that offers to approve outside includes gates on the word; an engine without it refuses the * member as an unknown key (`config.invalid_argument`); with it, a host that sends `true` is refused, never read as approving every file. * - `instruction_family.host_text` — the engine takes the instruction texts the host holds (`TaskSpec.instructionFamily.hostRules`, each * `{ level, name, text, rule? }`, `level` `user` / `managed` / `project` / `local`) as the text on disk and reads it as a file's text is read: a text * with no `rule: true` (its frontmatter dropped, never a condition) rides every load of every leg — a leg with no hands included — ahead * of the task root's members, in the host's order, sent again only when it changed or left the conversation; `rule: true` with frontmatter * `paths:` rides when an accessed path matches (never on a leg with no hands). A text the host stops supplying, or that holds nothing * now, is withdrawn once. Its includes are followed only from a text whose `name` is an absolute path (`isAbsoluteHostPath`) on a leg * with hands — the user's level as if the project approved files outside the roots, the others by what `externalIncludes` approves — and no include of * any other text is followed: one that names a place (beside a text named by its path, under the home, an absolute path) is told * (`instructions.withheld` `unanchored`), a relative one in a text named by a label names none and no one is told, as a file's include * of a missing file. A `rule: true` text's `paths:` is told to the operator as a rules directory's file's is (over several lines, no * limit). Only a value of the wrong shape refuses the task; * a text past the first `NESTED_MEMORY_LANE.limits.maxHostRules` (the user is told, `too_many_texts`), one whose name an earlier entry * has, a name over `ABSOLUTE_HOST_PATH_MAX`, a text over the read bound, or a text whose name resolves (links followed) to a file the * lane holds or has on its way is not delivered (the operator is told). The retired `paths` member is refused (`config.spec_retired_key`). A host that * sends its user's and its upper directories' instruction files gates on the word; an engine without it reads `hostRules` the old way * (each entry needs `paths`, and a text with none is refused). * - `instruction_family.local_files` — the engine reads `TaskSpec.instructionFamily.localFiles`: the user's private names (the law of * `files`), read at every level whichever family is active and never counted by `alternate`'s condition, framed as user-private * text. A host that declares `CLAUDE.local.md` gates on the word (declaring it among `files` instead would make it count for the * `alternate` condition); an engine without it refuses the member as an unknown key (`config.invalid_argument`). * - `session_changes.git` — the engine answers `Runner.readSessionChanges` for `source: { kind: "git", base?: "head" }`: the session's * uncommitted changes against the commit HEAD names (resolved once per call and named in `before.commit`; the empty tree on an * unborn HEAD), read by git at the session's root (its own tree when it works in one), one row per changed file — untracked files by * name, a rename as one row — or `totals` past 500 files; both texts of the paths `contentOf` names, whole, within the same two * bounds as the history sources (a side, one call's budget), never cut. Every git start carries `--no-pager`, * `--no-optional-locks`, `-c diff.autoRefreshIndex=false` (no index refresh written) and `-c core.fsmonitor=` (empty), runs at most 5 s * and writes at most 4 MiB (else `git_failed`); a merge or rebase in progress is `repository_busy`, no work tree `not_a_repository`. * No program the repository's own configuration defines runs — not the file-system monitor, an external diff, textconv, a pager, a * hook (no start here runs one, none writes the index), nor a filter driver its local or worktree configuration (or a file either * includes) defines — read as git's later starts read configuration, then emptied on every one of them; a path such a driver governs * is `repository_filter`, not compared; a filter driver the user's or the system's configuration defines runs. The same env, lock and write statement as * `session_changes.checkpoints`. A shell that shows a session's uncommitted changes gates on the word. * - `artifact_host.libraries` — the engine reads `ArtifactHostCapabilities.libraries` (`src/core/artifact-host.ts`, the member's own * statement): at most 32 entries `{ url, sri, hint }` — an `https:` url with no user name or password, no two a browser fetches as * one (a `#fragment` is not fetched), the Subresource Integrity tokens at their exact length, a one-line hint of 1 – 200 * characters — and the Artifact tool's description names exactly those, or, with none declared, tells the model a page loads * nothing from elsewhere and puts everything inline. One bad entry refuses the whole Artifact mount (`config.artifact_host_invalid`, * the sentence naming the entry and repeating none of its url). An engine without the word ignores the member and says nothing * of libraries; a host that declares them gates on the word. * - `instruction_family.preview` — `WiringManifest.instructions` carries first-load `included` (`@`-included files) and `withheld` * (lane-discovered and host-text withholds, with `blockedAfterApproval` on `outside_its_root` when Read admission still refuses after * approval), and `Runner.previewInstructions(spec)` returns that identical object before any turn with no model call, session/read-state * write, checkpoint, or notice (coded refusal on invalid specs). A host that prompts for external includes before Turn 1 gates on the word. * - `brain.anthropic_oauth_bearer` — the Anthropic adapter gives a qualifying Bearer the header its protocol requires: a credential * whose value opens with `sk-ant-oat` rides as `Authorization: Bearer <value>` from the key seat while no header bag filled that * header (a bag's own `Authorization` stays the host's, the key then keeps `x-api-key`) or from an `Authorization` header itself, * and a request whose one `Authorization` header is such a Bearer carries `oauth-2025-04-20` in its `anthropic-beta` list; no * header that states a client identity is added, and a refusal is the run's terminal as the provider stated it (`auth` / * `rate_limit` / `invalid_request` with `provider_rejected`; re-sent only as any request is). The word says the * request's shape only: whether the endpoint accepts the credential, and whether the account may use it, it does not answer. A * shell may offer "a subscription token can be entered" on it, never "it works". * - `skills.proposal_seat` — the root export `createSkillProposalTool` builds the `ProposeSkill` tool a host mounts in * `TaskSpec.tools` (`src/tools/skill-proposal-tool.ts`, the statement): one call hands the proposed skill and the * engine-stated source (session, task, principal, the session's external-content state as the memory write path reads it) * to the host's `propose` seat and tells the model the outcome with the proposal id; a non-empty `allowed_tools` is refused * before the seat (no id is minted then) unless the host passed `allowToolGrants: true`; the run's own skills do not change. A shell offers a proposal review on the word; an engine without it has * no such tool. * - `read_deny.request_release` — the engine reads `TaskSpec.readDenyBuiltinExclude`: a request names the built-in read deny * row its deployment granted (`RunnerDeps.readDenyBuiltinRequestExcludable`; the one releasable row is * `"~/.sema/settings.json"`): the leg's Read tool reads that file, its shell and search tools still refuse it, and a structured * change of it is put to a person (refused with nobody to ask). A name the * deployment did not grant fails the run at its door (`config.invalid_argument`). An engine without the word refuses the key * (`config.spec_unknown_key`), so a host gates on the word. */ export declare const ENGINE_CAPABILITIES: readonly ["inherit_env.own_credentials_withheld", "inherit_env.own_credential_values_withheld", "mods.skill_seat", "user_attachments.read_state", "task.wake", "file_history.recorded_place", "ask.workflow_member", "task.fast_mode", "user_attachments.instruction_access", "task_notification.note_key", "task.continues_from", "execution_env.workspace_sync", "session.rewind_conversation", "instruction_family.external_includes", "instruction_family.host_text", "instruction_family.local_files", "instruction_family.preview", "session_changes.checkpoints", "session_changes.git", "task.agent_config_dirs", "task.agent_home_dirs", "artifact_host.libraries", "file_history.unplaced_recorded_under", "brain.anthropic_oauth_bearer", "skills.proposal_seat", "read_deny.request_release"]; /** One word of {@link ENGINE_CAPABILITIES}. */ export type EngineCapability = (typeof ENGINE_CAPABILITIES)[number];