@sema-agent/core
Version:
Stateless, task-oriented AI agent core
50 lines (49 loc) • 4.01 kB
TypeScript
/**
* The REMOVAL ACTIONS — ONE closed table, per program row: how its argv removes, read by both faces a removal meets: the removal
* guard (`removal-targets.ts`: does it remove a protected location) and the write face (`shell-read-write-targets.ts`: where does
* what it removes land — inside the write roots or not). `operands`: it removes its operands (`rm`, `rmdir`, with or without a
* recursive option — removing an empty home or the task root is still removing it; the reference implementation's
* dangerous-removal arm reads these two). `walk`: where its `-delete` is written it removes entries below each starting point,
* the starting point included where nothing is left in it ({@link walkRemovalStarts}); the removal guard asks where the
* `-delete` reaches EVERY entry there — no test in front of it narrows it (`find … -delete`, `find-actions.ts`: the line `rm`
* draws, `rm -rf ./*` and not `rm -rf ./build/*`). A command a program HANDS ON is a command of its own and is judged by this
* same table on both faces: `find`'s `-exec` family (the planner reads each as a nested command line, `{}` standing for the
* entries the action reaches) and `xargs` (a launcher: the program it runs is the segment's own program). The read station's
* fold reads the table too (`shell-read-judge.ts`): a target a removal program removes ({@link removesTarget}), and the starting
* points of a `find` whose output a pipe hands to a stream-fed remover (`piped-removal.ts`).
*/
import { type FindWord } from "./find-actions.js";
import { type ProgramRow } from "./program-read-model.js";
import type { ReadCandidate, ShellReadSegment } from "./shell-read-plan.js";
export declare const SHELL_REMOVAL_ACTIONS: Readonly<{
readonly rm: "operands";
readonly rmdir: "operands";
readonly find: "walk";
}>;
type RemovalActionTable = typeof SHELL_REMOVAL_ACTIONS;
export type ShellRemovalCommand = {
readonly [K in keyof RemovalActionTable]: RemovalActionTable[K] extends "operands" ? K : never;
}[keyof RemovalActionTable];
/** The table's row for a program row's key (`undefined`: the program removes nothing by this table). */
export declare const removalActionOf: (key: string) => RemovalActionTable[keyof RemovalActionTable] | undefined;
/** The programs that remove their OPERANDS (the table's `operands` rows). */
export declare const SHELL_REMOVAL_COMMANDS: readonly ShellRemovalCommand[];
/**
* The starting points a `walk` row's argv (the words after the program word) removes in: where a `-delete` is written, each
* starting point the command names (`[]`: it names none — the walk starts where the program stands); `undefined` where the row is
* no walk, no `-delete` is written, or the starting points are read from a file (none of them is in the command).
*/
export declare function walkRemovalStarts(row: ProgramRow, words: readonly FindWord[]): readonly FindWord[] | undefined;
/**
* The WRITE targets of a removal walk on the write face ({@link walkRemovalStarts} of the segment's program): each starting point
* it removes in, as the plan placed its word (an operand, BSD's `-f PATH`, a word of a program the deployment did not list), or —
* where it names none — the directory the program
* starts in. The write face writes each where it lands and at its entry: the walk removes below the place a link there leads to
* where `-H` / `-L` follow it, and the link itself where they do not.
*/
export declare function walkRemovalTargetsOf(segment: ShellReadSegment): ReadCandidate[];
/** Is `candidate` a target the segment's program REMOVES by this table — an operand of an `operands` row (a word of the program
* itself: not a redirection target, not a launcher's option value), or a starting point a `walk` row's `-delete` removes in
* ({@link walkRemovalTargetsOf}; not a file an output action such as `-fprint` writes)? */
export declare function removesTarget(segment: ShellReadSegment, candidate: ReadCandidate): boolean;
export {};