@sema-agent/core
Version:
Stateless, task-oriented AI agent core
104 lines (103 loc) • 8.15 kB
TypeScript
/** The configuration directory's name below a home: the one segment the deny tables spell the agent's own settings under. */
export declare const AGENT_CONFIG_DIR_SEGMENT = ".sema";
/** The code a declared root that names no directory is refused with, wherever it is declared. */
export declare const AGENT_CONFIG_DIR_INVALID_CODE = "config.agent_config_dir_invalid";
/** A run (the `/`-separated segments of a deny row, home word already removed) read below the configuration directory:
* `.sema/settings.json` ⇒ `settings.json`, `.sema` ⇒ `""`, and `undefined` for a run that does not open with the
* directory's name. The first segment is compared as the row compares it (ASCII-case-insensitive unless the row opts out).
*
* @contract agent_config_dir.one_reading — which rows a declared configuration root relocates is decided HERE and nowhere
* else: a row that opens with the `.sema` segment names its tail below the root, in the read placement, in the always-on
* write-protection table and in the opt-in deny set alike; the root adds a place and never moves the default one, a row that
* does not open with that segment keeps its place, and a face with a list of its own of "the rows that relocate" is a fork
* of this sentence, not a variant of it. */
export declare function agentConfigDirTail(run: string, caseSensitive?: boolean): string | undefined;
/** The segments of a declared root in lexical normal form — what a path's leading segments are compared with. */
export declare function agentConfigDirSegments(dir: string): string[];
/** The code a declared HOME that names no directory is refused with (the caller's home, `TaskSpec.agentHomeDirs`). */
export declare const AGENT_HOME_DIR_INVALID_CODE = "config.agent_home_dir_invalid";
/**
* The two kinds of directory a host or a caller declares for the deny tables to place rows at — one check, one sentence
* shape, one code each:
* · `config` — a configuration root (`RunnerDeps.agentConfigDir`, `TaskSpec.agentConfigDirs`): the rows that open with the
* configuration directory's name are also placed below it ({@link agentConfigDirTail});
* · `home` — a home directory of the CALLER (`TaskSpec.agentHomeDirs`): the home-anchored read deny rows (`~/…`) are also
* placed below it, beside the homes the engine's own environment declares.
*/
export type DeclaredDirKind = "config" | "home";
/** A DEPLOYMENT's declared directory (`RunnerDeps.agentConfigDir`, `createSensitivePathPolicy`'s `agentConfigDir`) as given
* (`undefined` = none declared), or a refusal: its shape ({@link shapedDeclaredDir}), no such directory, not a directory, not
* readable. Looked at on the host's own file system — the host that declares it is the host that keeps it. A directory a TASK
* declares is the caller's, and is looked at where the run's tools are ({@link judgeTaskDeclaredDirs}). */
export declare function checkedDeclaredDir(kind: DeclaredDirKind, value: unknown, seat: string): string | undefined;
/** A task's directories (`TaskSpec.agentConfigDirs` / `agentHomeDirs`) judged on the host's own file system — where a leg has no
* execution environment to ask (no tools run: the host is the only machine there is) — the reading every build before 7.70.0 gave
* a first start. */
export declare function assertTaskDeclaredDirsOnHost(spec: {
readonly agentConfigDirs?: unknown;
readonly agentHomeDirs?: unknown;
}): void;
/** What the run's execution environment answers about one declared directory — the subset of its file system a judgment needs. */
export interface DeclaredDirEnv {
canonicalPath(path: string): Promise<{
ok: true;
value: string;
} | {
ok: false;
error: {
code: string;
message: string;
};
}>;
fileInfo(path: string): Promise<{
ok: true;
value: {
kind: string;
};
} | {
ok: false;
error: {
code: string;
message: string;
};
}>;
}
/**
* Judge the directories a TASK declares (`TaskSpec.agentConfigDirs` / `agentHomeDirs`, by index) where the run's tools are — the
* run's execution environment, which may be another machine than the engine's (a device, a remote environment): asked ONCE, when a
* run first starts. A directory the environment is sure is not there (not found, a file) refuses the run, with the same code and
* sentences as every declared-directory refusal; one it cannot answer about (a permission, a loop, an environment error) is placed
* by its spelling — a row placed at a path nothing is under guards nothing and costs nothing — and said through `unverified`.
*
* @contract agent_config_dir.existence_once — a declared directory's existence is asked of the execution environment once, at a
* run's first start; the task door, a workflow script's entry and a resume judge its shape only, and a resume places the directories
* it is given (re-stated or recorded) by their spelling.
*/
export declare function judgeTaskDeclaredDirs(kind: DeclaredDirKind, list: readonly string[] | undefined, seat: string, env: DeclaredDirEnv, unverified: (entry: string, reason: string) => void,
/** `refuse` at a first start; `place` on a resume — a directory gone since is placed by its spelling and said, never refused. */
absent?: "refuse" | "place"): Promise<void>;
/** The declared configuration root as given (`undefined` = none declared, the default location) — {@link checkedDeclaredDir}
* for the `config` kind. */
export declare function checkedAgentConfigDir(value: string | undefined, seat: string): string | undefined;
/** The task layer's seat for a kind (`TaskSpec.agentConfigDirs`, `TaskSpec.agentHomeDirs`) as its caller wrote it: absent, or
* a list whose every entry has the shape ({@link checkedDeclaredDirEntry}), each named by its index — the same code, the same
* sentences. A value that is not a list is refused under the same code (it would otherwise be read letter by letter). Every
* index is read, a hole too. Returns nothing: the leg reads the seat itself. */
export declare function assertTaskDeclaredDirs(kind: DeclaredDirKind, value: unknown, seat: string): void;
/** The clamp table's task-layer door for a kind's list: {@link assertTaskDeclaredDirs} under the row's owner label. */
export declare function declaredDirDoor(kind: DeclaredDirKind): (value: unknown, owner: string) => void;
/** The clamp table's entry law for a kind's list: `undefined` ⇔ the one entry check accepts the entry, else its refusal
* sentence (labelled with `owner`). */
export declare function declaredDirEntryLaw(kind: DeclaredDirKind): (entry: unknown, owner: string) => string | undefined;
/** The identity two declared directories fold by — every place that asks "is this the same declared directory" (the clamp
* table's union, the leg mint's sources, a caller home beside the engine's own) reads this one: a trailing slash, a `.`
* segment and a doubled separator fold away; a `..` segment does NOT ({@link foldRedundantPathSegments}): `a/link/..` and `a`
* are different directories when `link` is a symlink, and folding them would drop one of two declared places. Two spellings
* of one directory that survive this fold are both kept, and the row is placed at it twice — over-keeping costs nothing. */
export declare function declaredDirIdentity(dir: string): string;
/** A recorded list (`CheckpointState.agentConfigDirs` / `agentHomeDirs`) as a resume reads it: absent, or a list of absolute
* path strings — the shape a mint writes. Existence is not asked: it is the declaring moment's check (a typo guard), and a
* directory removed since is still placed at its spelling (a placement reads "no such directory" as nothing below it). A
* value of another shape is a damaged row, refused under the kind's code. Every index is read, a hole too (a store that
* keeps the row as an object, not JSON, can carry one). */
export declare function recordedDeclaredDirs(kind: DeclaredDirKind, value: unknown, seat: string): readonly string[] | undefined;