@sema-agent/core
Version:
Stateless, task-oriented AI agent core
54 lines (53 loc) • 5.55 kB
TypeScript
/**
* THE AUTO STRIP's one judgment: whether auto mode stands an allow entry down — so it clears no call and the calls it names go to
* the classifier — and why. The reference implementation drops these allow rules from every source before matching in auto mode:
* the whole shell tool; a shell rule whose content is empty or all `*`; and a shell rule naming one of the programs that run
* arbitrary code ({@link AUTO_STRIPPED_PROGRAMS}) in one of five spellings — `X`, `X:*`, `X *`, `X*`, or `X -…*` (an option-led open
* tail; python's `-m dotted.module` is the one exception). Three adaptations the reference has no case for: a whole-tool entry is
* stripped when the call answers, under ANY of its names, to the shell (an alias reaches the same tool), a compound-prefix rule
* (`cd /tmp && npm run:*`) is judged by its final segment — the one left open, and a pattern rule (`node * x.js`, `nice python * y`)
* is stripped when the run it names — its program read past the launchers in front of it, by basename — could be one of those
* programs, or when that program word is itself open or cannot be read. A leg that declares `TaskSpec.classifyAllShell` widens the
* strip to EVERY shell entry — the reference's `autoMode.classifyAllShell`.
*
* Every reader takes this one function: the allow layer per call (`allow-entry.ts`, through the call's one fact it needs — does
* the call answer to the shell), and the rule read faces judged without a run (no call, no declaration) — the store's rows
* (`EffectivePermissionRule.autoStrip`) and a list entry (`allowEntryAutoStrip`). A leaf: it reads no lane and no store.
*/
import type { CompiledAllowEntry } from "./allow-entry.js";
import { type PersistedRule } from "./permission-rule-model.js";
/** The programs whose open allow rule the reference implementation drops in auto mode — its interpreter / launcher table
* plus the shells and the run-anything builtins. A program that only reaches the network is not here. */
export declare const AUTO_STRIPPED_PROGRAMS: readonly ["python", "python3", "python2", "node", "deno", "tsx", "ruby", "perl", "php", "lua", "npx", "bunx", "npm run", "yarn run", "pnpm run", "bun run", "bash", "sh", "ssh", "zsh", "fish", "eval", "exec", "env", "xargs", "sudo"];
/**
* Why auto mode stands an allow entry down — the strip's three cases, named: `whole_shell` (the entry reaches every shell
* command: the whole shell tool, a shell rule whose content is empty or all `*`, a whole-tool entry the call reaches the shell
* through under another name), `code_runner` (the entry opens a program that runs whatever code it is given —
* {@link AUTO_STRIPPED_PROGRAMS}, or a pattern whose run could be one), `classify_all_shell` (the leg declared
* `TaskSpec.classifyAllShell`: every shell entry stands down, whatever it names).
*/
export declare const AUTO_STRIP_REASONS: readonly ["whole_shell", "code_runner", "classify_all_shell"];
export type AutoStripReason = (typeof AUTO_STRIP_REASONS)[number];
/** The reasons a rule read face carries: judged without a run, so never the leg's declaration. */
export type AutoStripRowReason = Exclude<AutoStripReason, "classify_all_shell">;
/**
* Does auto mode stand this allow entry down, and why — `undefined` ⇒ kept. The one fact of the call it reads is whether the call
* answers to the shell under any of its names (`callAnswersToShell`; asked only where it decides, and `false` for a judgment
* without a call). `allShell`: the leg declared `TaskSpec.classifyAllShell` — every shell command rule stands down, whatever it
* names, and no entry of any kind clears a call that answers to the shell (the reference suspends every shell allow rule under that
* setting without reading its content; a path rule a shell-face tool's declared target reaches is one here).
*/
export declare function autoStripReasonOf(compiled: CompiledAllowEntry, callAnswersToShell: () => boolean, allShell: boolean): AutoStripReason | undefined;
/** The run-less reading a rule read face carries: no call, no declaration — so never `classify_all_shell`. */
export declare function readFaceAutoStrip(compiled: CompiledAllowEntry): AutoStripRowReason | undefined;
/** The list entry a stored row is the twin of: a whole-tool row is the whole tool (the shell's own kind on the shell face), every
* other row the content kind of its tool's grammar. A row is stripped exactly when the entry spelling the same rule is. */
export declare function entryOfRow(rule: PersistedRule): CompiledAllowEntry | undefined;
/** Does a stored row's TEXT read as an allow rule — the rows the person's lane can grant by (one that does not grants nothing in any
* mode, so auto mode takes nothing from it)? The row as that reading reads it, else `undefined`. */
export declare function storedAllowRowRead(rule: Pick<PersistedRule, "behavior" | "rule" | "scope" | "adds">): PersistedRule | undefined;
/** The read face's reading of a person's stored row ({@link readFaceAutoStrip} over the twin of the row its text reads as): an allow
* row whose text reads as an allow rule only — a deny / ask row is never stripped, and a row that grants nothing in any mode has
* nothing for auto mode to take. Read off the text, never the row's other fields, so a malformed row a foreign backend served
* answers `undefined` instead of failing the store's read. What `EffectivePermissionRule.autoStrip` carries. */
export declare function storedRowAutoStrip(rule: PersistedRule): AutoStripRowReason | undefined;