@sema-agent/core
Version:
Stateless, task-oriented AI agent core
163 lines (162 loc) • 12.8 kB
TypeScript
/**
* UNC under the win family: two leading separators, a host, a share — either separator, as `path.win32`
* reads it. The ONE UNC recognizer behind `isAbsoluteForFamily`, `pathIdentityOf` and `joinForFamily`
* (tools/fs/safety.ts), the symlink-chain reader (core/path-identity.ts) and the engine's own chain walk
* (engine/execution-env/symlink-chain.ts).
*/
export declare function isUncSpelling(p: string): boolean;
/**
* The drive path a drive's administrative share names, read with the host left unasked, or `undefined` — with every drive
* path's names read as Win32 trims them ({@link belowTheRoot}: `C:\Users\u.` and `C:\Users\u ` are `C:\Users\u`). A UNC
* (`\\host\share\…`) whose share is a drive's administrative share `X$` (either case) names that drive on WHICHEVER machine the
* host is: `\\h\c$\rest` ⇒ `C:\rest` — whether `h` is this machine (its loopback address, its own name, an alias) only the
* environment knows. The DOS device spellings of a location are read as Win32 reads them: `\\?\UNC\…` is the UNC it prefixes
* ({@link stripWin32ExtendedPrefix}); a `\\.\` path, with the device prefix as its root, names a drive when its first segment
* is one (`\\.\C:\rest` ⇒ `C:\rest`; a bare `\\.\C:` is the volume's raw device and stays unread), or a UNC this rule reads
* when it is `UNC`. Only the ROOT is read: what lies below it is kept as written ({@link belowTheRoot}) — a `..` there is each
* reader's to take, as it is in the drive spelling — but for a `..` that would climb above the root, which the root itself
* answers: a share holds it at the share (`\\h\c$\..\x` ⇒ `C:\x`), and a `\\.\` path whose `..` would leave the volume stays
* unread. `undefined` for every other spelling: any other share (which directory a share maps is the server's to say), a volume
* named another way (`\\.\Volume{…}`, `\\?\GLOBALROOT\…`), and a spelling of the POSIX family — `family`, the tree's where
* the reader knows it, else the spelling's own (a tightening judgment reads spellings no tree placed): on POSIX `//h/c$/x` is
* an ordinary path, on a win tree it is the share.
*
* It names a location the spelling MAY be, never the one it is: no tree places a path at it, no allow reads it, and no
* judgment reads it where a hit could make its answer looser. It turns "no row" into a row (the one judgment of guarded rows,
* where the views as read answer nothing), finds more rows below a root (the read-deny table's relations) and more protected
* locations (the removal guard's key) — never a proof that a command left one, never the place a command stands — and it gives
* a device spelling the namespace screen refuses a drive stand-in (the shell station's one placement function), read where
* that word's own reading tightens.
*/
export declare function localDriveSpellingOf(p: string, family?: PathFamily): string | undefined;
/** A Win32 device-namespace spelling (`\\.\…`, either separator): a location no tree places — the namespace screen refuses it,
* and where the engine reads a drive out of one (the shell station's stand-in) that drive is its own reading, not the word's. */
export declare function isDeviceSpelling(p: string): boolean;
/** A Win32 namespace prefix spelled with ANY forward slash (`//?/`, `//?\`, `/\?\`, `\\/./`, …) is the SAME namespace after
* Win32's own normalization — only the verbatim all-backslash spelling disables it — so it is folded whole to its backslash
* twin, never read as a UNC with host `?` or `.`. Every other spelling is returned as is. */
export declare function win32NamespacePrefixFolded(p: string): string;
/** The two spelling families a tree can be in. Read from the ROOT's spelling (the cwd's when a deployment
* supplies no root) — never from `process.platform`: the exec env may be remote and of the other family. */
export type PathFamily = "win" | "posix";
/** The family of a call's tree; `undefined` when the call declares neither root nor cwd (a treeless call
* gets no family invented for it — see `pathIdentityOf` (tools/fs/safety.ts) for what it can still read). */
export declare function pathFamilyOf(bases: {
readonly root: string;
readonly cwd?: string | undefined;
}): PathFamily;
export declare function pathFamilyOf(bases: {
readonly root?: string | undefined;
readonly cwd: string;
}): PathFamily;
export declare function pathFamilyOf(bases: {
readonly root?: string | undefined;
readonly cwd?: string | undefined;
}): PathFamily | undefined;
/** Where a reading takes its family from: a tree's ({@link PathFamily}), or `"own"` — an address with no tree to place
* it reads its OWN spelling as the family source (the {@link pathFamilyOf} of that spelling), so a treeless `C:\x` and a
* treeless `/x` are each read in their own family rather than one of them being declared relative. */
export type PathFamilySource = PathFamily | "own";
/** The family a {@link PathFamilySource} names for one spelling. */
export declare function familyFor(source: PathFamilySource, p: string): PathFamily;
/**
* FULLY QUALIFIED under the family — the ONE absoluteness predicate. win: drive-rooted (`C:\`/`C:/`) or UNC (a host AND a
* share: a bare `\\x` names no share and is no address) — a `/x` / `\x` is rooted-not-qualified and joins the base's drive
* or share root (`joinForFamily`, tools/fs/safety.ts), a `C:rel` is drive-relative. posix: `/`-rooted. `"own"`: the spelling's own
* family ({@link familyFor}) — the reading of an address no tree places.
*/
export declare function isAbsoluteForFamily(family: PathFamilySource, p: string): boolean;
export declare const WIN_RESERVED_RE: RegExp;
/**
* Windows-FAMILY spelling of a path (the canonicalizer judges the UNC family by the same rule): drive-rooted
* (`C:\…`/`C:/…`), UNC-backslash (`\\host\share`), or a
* RELATIVE path using `\` as its separator. Never keyed on `process.platform` — the exec env may be remote
* and of the other family than the host. A `/`-rooted path is POSIX-form even when a file NAME inside it
* contains a literal backslash (legal on POSIX), and `//host/share` is therefore POSIX-form too — which is
* the whole point: on POSIX that spelling is an ordinary absolute path, not a network share.
*
* This is the ONE definition of the win-family spelling; every reader of the family imports it rather than a private twin.
*/
export declare function isWinFormPath(p: string): boolean;
/**
* A comparison key's drive letter, lower-cased: `C:/x` reads `c:/x` and a bare `C:` reads `c:`, because a Windows drive letter
* is not case-sensitive while the rest of the spelling keeps its case (a POSIX root's directories differ by case). Only a
* spelling that opens with a letter, the colon and then `/` or the end is touched: `C:x` (drive-relative), a `\` form (the
* caller folds `\` to `/` first, for a win-form spelling only) and every other spelling come back as given.
*/
export declare function foldDriveLetter(p: string): string;
/** A drive letter and its colon with nothing after them (`C:`) — the drive named without a directory, which
* {@link isDriveAbsoluteSpelling} (`C:\`, `C:/`) does not read as an absolute path. */
export declare function isBareDriveSpelling(p: string): boolean;
/** The separator to REJOIN with, matching the path's native family (Node accepts `/` on win32, but we
* keep keys family-consistent so one file can't get two map keys via mixed separators). */
export declare function nativeSepOf(p: string): string;
/**
* Purely LEXICAL path normalization: collapse repeated separators, drop `.` segments, and
* resolve `..` against the preceding segment. No filesystem access, no cwd: this is a spelling
* normalizer, not a resolver. (Deliberately NOT the new-path canonicalizer's job — that one walks the real
* filesystem precisely because folding `..` lexically across a SYMLINKED parent is unsound. Use this one
* only where the question is "are these two strings the same name", never "which file is this".)
*
* It exists because the device blocklist (`isBlockedDevicePath`, tools/fs/safety.ts) is an exact-string membership test, and `//dev/zero`,
* `/dev/./zero` and `/dev/../dev/zero` all name the device `/dev/zero` to the kernel while spelling it
* three different ways. Callers that match a device list against a raw argument must normalize first or
* the list is a spelling filter rather than a device filter.
*
* Coverage — the union of every fold the callers need, held once here rather than re-implemented per
* consumer:
* · POSIX absolute — `/a/./b` → `/a/b`; `/..` is `/`, matching the kernel.
* · drive-letter (`C:\a\..\b`) and UNC (`\\host\share\..\x`) — prefix preserved, folding applies
* to the tail only, and the REJOIN uses the path's own native separator so one file cannot acquire
* two keys by separator form.
* · RELATIVE — stays relative (`dev/zero` therefore still never matches an absolute device entry:
* `dev/zero` under some other directory is an ordinary file), and a leading `..` is KEPT rather than
* popped into nothing — dropping it would move the path.
*
* FAMILY-awareness is the part a private copy tends to get wrong. A backslash is a separator only in a
* win-form path; in a POSIX path it is an ordinary filename character, and an unconditional `\`→`/`
* fold rewrites a POSIX file literally named `a\..\b` into a different location before the boundary
* check ever sees it — in both directions: false refusal and false allow.
*/
export declare function normalizeAbsPathLexically(p: string): string;
/**
* The READ-leg fold: removes `.` segments and duplicate
* separators ONLY — transformations that name the SAME file on every real filesystem, symlinks
* included. `..` is deliberately KEPT: `a/../x` and `x` are different files when `a` is a symlink,
* and this function's callers go on to OPEN the result (fileInfo/readText), not just to mint a
* comparison key. Ask "which file is this" here; ask "are these two strings the same name" with
* {@link normalizeAbsPathLexically}.
*/
export declare function foldRedundantPathSegments(p: string): string;
/**
* Strip the Win32 EXTENDED-LENGTH prefix, lexically and with zero I/O:
* · `\\?\C:\x` → `C:\x` (ordinary drive path — probes and resolves normally)
* · `\\?\UNC\host\share` → `\\host\share` (ordinary UNC — the share anchor becomes REAL, so the
* share-boundary fold below actually guards it; before
* this, `?`/`UNC` were read as host/share and `..` could
* climb out of the true share)
* Anything else (no prefix, or a non-mappable body like `\\?\Volume{…}`/`\\?\GLOBALROOT\…`) returns
* UNCHANGED — those bodies name object-manager objects with no DOS-path equivalent, and stripping
* just the prefix would mint a RELATIVE spelling (`Volume{…}\x`) that resolves against the cwd,
* silently redirecting the operation to an unrelated in-root file. Kept verbatim, the spelling still
* starts `\\` and canonicalizeTarget refuses it by name (fail closed). Strictly backslash-anchored
* (`\\?\` verbatim): Windows itself only honors the verbatim prefix in that spelling, and a
* `/`-rooted lookalike is POSIX content in this module's family convention.
*/
export declare function stripWin32ExtendedPrefix(p: string): string;
/**
* The MISSING tail of a not-yet-created target below its deepest existing ancestor `canonical`, applied the way the kernel
* applies it once the write creates what is missing — as far as nothing on the way can be a link. Below the first missing
* name nothing exists, so there a `.` or a separator run names the same place and a `..` cancels the missing name before
* it. A `..` that cancels the LAST missing name, or climbs past it (to the canonical prefix's parent — its lexical parent, a
* canonical path holding no link; a root is its own), lands in a directory that EXISTS: the names after it are the
* filesystem's to answer for again (one of them may be a link), so the rest comes back as an address to probe (`reprobe`),
* never folded on. Otherwise the key carries no `.` / `..` segment: one file, one key (the same file spelled again once it
* exists keys through `canonicalPath`, and lands here). The tree's one tail rule: the fs throat's walk over an environment
* (tools/fs/safety.ts) and the host's own physical-path mint (`physicalPathOfExisting`, core/physical-path.ts) both apply it.
*/
export declare function rejoinMissingTail(canonical: string, tail: readonly string[], family: PathFamily): {
readonly key: string;
} | {
readonly reprobe: string;
};