@sema-agent/core
Version:
Stateless, task-oriented AI agent core
61 lines (60 loc) • 5.01 kB
TypeScript
/**
* THE account of the entries of a restricting tool table that name a tool the engine retired with NO successor to write
* (`TeamCreate`, `TaskOutput`, … — the retirement table's `removed` and `folded` lines, `RETIRED_TOOL_NAMES`): the sentence and the data
* of the retired-name notice (audience `user`; code {@link POLICY_NAME_REFUSAL_CODE}). Such a name reaches no tool in any roster, now or later, and never did anything a
* rewrite could restore, so every restricting table leaves the entry out, goes on, and says so ONCE in these words — the engine's own tables (a
* tool policy's `deny` / `ask`, a task's tool-name lists, a skill's `disallowed-tools`) through `retiredToolNameNotice`
* (`runner/sub-agent-deny-lists.ts`, the engine's mint), a table the host owns and the engine never reads through
* `retiredToolNameAccount` (`retired-host-table-account.ts`: the host mints its own notice from the pure account). This module holds the words and the
* data and reads no entry; the one reader and the one question (`compileAllowList`, then `isRetiredLeftOut`) are `allow-entry.ts`'s.
* A name the engine RENAMED (it has a successor the entry used to guard), an unprefixed namespace and an unmintable segment are not here:
* leaving such an entry out would widen the surface, so every table still refuses them.
*/
import type { EngineNotice } from "./engine-notice.js";
/** The code of the policy-name refusal and of the retired-name notice — the one spelling their mints and every problem they list carry. */
export declare const POLICY_NAME_REFUSAL_CODE = "config.legacy_tool_name";
/** The tables the account is told for, by the words the trace already gives the first three: the run's own policy (`caller_policy`), the stored
* rules of its session, the rules an ancestor's session handed it; the lists the engine reads beside the policy — a task's tool-name lists
* (`task_selector`: `excludeTools`, a definition's or a delegation tool's `denyTools`) and a skill's `disallowed-tools` (`skill_table`); and
* `host_table`, a restricting table the HOST owns and the engine never reads (`settings.permissions.neverAuto`). */
export type PolicyNameLayer = "caller_policy" | "session_rules" | "ancestor_session_rules" | "task_selector" | "skill_table" | "host_table";
/** One entry of a restricting list (`deny` / `ask`) that names a tool the engine retired with no successor to write: the name matches nothing in
* any roster, so its table leaves the entry out and says so instead of refusing the run. `guidance` is the retirement table's own line for the
* name; `source` names the list when a layer holds more than one (a task's list, a skill, a host table), carried into the sentence and the detail. */
export interface RetiredPolicyEntry {
readonly field: "deny" | "ask";
readonly entry: string;
readonly layer: PolicyNameLayer;
readonly guidance: string;
readonly source?: string;
}
/** The words and the data of the account of a table's retired entries — everything of the notice but its code, its audience, its minter and the
* session it is told to. */
export interface RetiredToolNameAccount {
readonly message: string;
readonly detail: {
readonly layer: PolicyNameLayer;
readonly entries: ReadonlyArray<{
field: "deny" | "ask";
entry: string;
layer: PolicyNameLayer;
guidance: string;
source?: string;
}>;
readonly total: number;
};
}
/** How many entries one account lists; the rest are counted in `detail.total`. Entries are names from the retirement table (a name outside it is
* not retired), so each is short; the bound keeps the coded detail inside the terminal's element budget. */
export declare const RETIRED_NOTICE_ENTRIES_SHOWN = 32;
/** The sentence and the detail of `entries` (unique by (field, entry, source) in scan order, at most {@link RETIRED_NOTICE_ENTRIES_SHOWN} in the
* detail, `total` counts every one). */
export declare function accountOfRetired(layer: PolicyNameLayer, entries: readonly RetiredPolicyEntry[]): RetiredToolNameAccount;
/**
* The notice for the entries of one restricting table that name a retired tool (code {@link POLICY_NAME_REFUSAL_CODE}, audience `user` — the person who wrote
* the entry believes it guards a tool): the table left them out, they reach no tool in any roster, and the run goes on. Minted here and nowhere else
* by the engine. `detail: { layer, entries: [{ field, entry, layer, guidance, source? }], total, sessionId }` — `entries` are unique by (field, entry,
* source) in scan order, at most {@link RETIRED_NOTICE_ENTRIES_SHOWN}, `total` counts every one. The entries that name a tool the engine renamed
* are not here: their names have a successor, the entry guarded it, and every table still refuses them.
*/
export declare function retiredToolNameNotice(layer: PolicyNameLayer, entries: readonly RetiredPolicyEntry[], sessionId: string): EngineNotice;