UNPKG

@sema-agent/core

Version:

Stateless, task-oriented AI agent core

86 lines (85 loc) • 7.04 kB
import { type PlatformPath } from "node:path"; /** * THE engine's data root — where it is, read one way by every reader: the file stores' root (`resolveDataRoot`), the memory * engine's root (`resolveMemoryEngineRoot`), the sensitive-path policy's own-data exemption and the transcript gate's default * directory all start from {@link dataRootSpelling}, and a host that wants to know where the root opens before it opens anything asks * {@link dataRootLocation} — never a copy of the rule. * * The spelling is the explicit value, else `AGENT_DATA_DIR`, else `~/.ai-agent`, in Unicode NFC (the reference normalizes its own * configuration home the same way): a name written decomposed and one written composed are one root, on a file system that tells * them apart (Linux) as on one that does not (macOS). No `~` is expanded and nothing is resolved here — a relative value is anchored * by the reader that opens it, at the process's directory. */ export declare function dataRootSpelling(explicit?: string): string; /** The data root as written, before NFC: the explicit value, else `AGENT_DATA_DIR`, else `<home>/.ai-agent` — the one rule * {@link dataRootSpelling} reads with this process's facts. Each default is read only when the value before it is absent (an * explicit root reads neither the environment nor the home directory). */ export declare function dataRootWrittenFrom(explicit: string | undefined, agentDataDir: () => string | undefined, home: () => string): string; /** * Where the data root opens — the physical path `resolveDataRoot` answers once it has made the directory — without making anything. * It is the one walk of the root ({@link walkedDataRoot}): links resolved, the names that do not exist yet appended as the directories * that would be made. Refused where the walk is refused, and the open refuses the same way: an empty value, an ordinary file on the * way, a link that leads nowhere (or loops back on itself). `anchor` places a relative root (see {@link walkedDataRoot}). * * @contract data_root.one_reading — for every value, `dataRootLocation(v)` is what `resolveDataRoot(v)` answers after it made the * directory, or both refuse. */ export declare function dataRootLocation(explicit?: string, anchor?: string): string; /** * The data root, walked once — what the preflight answers and what the open asks before it makes anything: `spelling` is the * value the open makes (the root's one spelling, {@link dataRootSpelling}, placed at the anchor when it is relative; with no anchor a * relative one is made at this process's directory, as the making always did), `location` is where it lands. A refusal of the walk is * thrown here, before anything is made. * * `anchor` is the directory a relative root is placed under — another process's working directory, for a host that reads, opens or * declares the root that process will open; absent, this process's directory. It is taken as given: its bytes are not normalized * (only the root's own segment is NFC) and it is walked like the rest, so a link in it is resolved; it is read, never made (one that * does not exist is refused `ENOENT`, one that is not a directory `ENOTDIR`). Refused `config.invalid_argument`: an anchor with no * root (a root read from `AGENT_DATA_DIR` or the home directory is not the caller's to place), and, for a relative root, an anchor * that is not a non-empty absolute path. An absolute root is not moved by an anchor and the anchor is not read at all, however it is * written: a caller that places every root it is handed at one directory hands the anchor with each, and an absolute root needs no * placing — as this process's directory does nothing to one. * * The walk is the kernel's order: from the spelling's own root, name by name, each prefix read by the kernel in one lookup, as the * making's lookup reads it (every link counted from the root, every directory a `..` leaves searched). A name that exists is entered; * one that does not is a directory to make, and every name after it is one too; a `..` takes back the last name to make, and once * none is left it is the kernel's `..` — so a `..` that comes back to a directory that exists goes on reading the disk, name by name. * Nothing is folded as text: a `..` after a link names the entry beside the link's target, as the kernel reads it. */ export declare function walkedDataRoot(explicit?: string, anchor?: string): { readonly spelling: string; readonly location: string; }; /** * How the walk reads an absolute spelling under a path flavor: the root it starts from — the flavor's own root of the spelling * (`/`; `C:\` or `C:/`; a UNC share's `\\server\share\`) — and the names after it, split at every separator the flavor has * (both `\` and `/` on Windows; only `/` on POSIX, where a backslash is a name character). */ export declare function walkSplitOf(abs: string, api: PlatformPath): { readonly root: string; readonly names: readonly string[]; }; /** A root written in a decomposed spelling whose data is not where the engine opens it ({@link dataRootSpellingSplitOf}). */ export type DataRootSpellingSplit = { readonly written: string; readonly opened: string; readonly state: "moved" | "both"; }; /** * {@link dataRootSpellingSplitOf}, to be told once per place per seat: `seat` is the notice seat the answer will be told on (a run's * `onNotice`); absent — or not a function, whose notices are printed as process lines — the process's default seat, once per process. * The place is the composed spelling's absolute location, resolved (so `/a/./b`, `/a/b/` and `/a/b` are one place), recorded in the engine's one record of what each seat was told * (`noticeOncePerSink`). `undefined` when there is no split, or this seat was already told about this place. `anchor` as the reader * takes it. */ export declare function splitSpellingOf(written: string, seat?: unknown, anchor?: string): DataRootSpellingSplit | undefined; /** * Whether a root written in a decomposed spelling has its data in a directory the engine does not open: the value as written and * its NFC spelling differ, and the directory under the written spelling exists — alone (`moved`: the engine opens the NFC one, * which does not exist yet) or beside the NFC one (`both`: the data is in two places). `undefined` otherwise (one spelling, or only * the NFC directory there; on a file system that does not tell the two spellings apart they are one directory). It only reads * (`stat`), keeps no state and says nothing — every call answers. A relative value is read at `anchor` (the memory root's own reading: * resolved, `..` folded), else at this process's directory; `anchor` as `dataRootLocation` takes it (a non-empty absolute path, kept * as given). Refused `config.invalid_argument`: a value that is not a string, a bad anchor. */ export declare function dataRootSpellingSplitOf(written: string, anchor?: string): DataRootSpellingSplit | undefined;