@sema-agent/core
Version:
Stateless, task-oriented AI agent core
64 lines (63 loc) • 5.72 kB
TypeScript
/**
* AN OBJECT PATH — `<rev>:<path>` (`git show HEAD:x`, `git cat-file -p :0:x`) — and the file of the working tree it names,
* which is what the deny rows are met at. The place is where git resolves the path (gitrevisions(7)):
* · spelled `./…` / `../…`, it is relative to the directory git starts in;
* · any other spelling is relative to the repository's TOP: the directory `--work-tree` names, else the one git's discovery
* finds walking up from where it starts — a filesystem fact ({@link repositoryTopOf}), read by the establishment where it
* has a filesystem, never by the plan;
* · git starts in the command's directory moved by each `-C` (git chdir()s to the spelling: the kernel's walk of it).
* Where git may be pointed at a repository by other means (`--git-dir`, `--bare`, a `GIT_*` variable the command's
* environment may carry — bound in the text, or received from the environment that runs it, `ExecutionEnv.receivedEnvNames`),
* where the text does not settle where git starts, or where the filesystem does not say, the top is any directory at or above
* where git starts: every ancestor meets the deny rows.
*/
import type { ExecutionEnv } from "../../internal/harness-types.js";
import { type ProgramRow } from "./program-read-model.js";
import { type PathFamily } from "./safety.js";
import type { Read } from "./shell-read-word.js";
/** What git's own options in front of the subcommand say about the repository an object path resolves in. */
export interface ObjectPathRepository {
/** Each `-C` value, in order (`undefined`: one the text does not settle). */
readonly moves: readonly (string | undefined)[];
/** The last `--work-tree` value (`null`: one the text does not settle). */
readonly workTree?: string | null;
/** `--git-dir` / `--bare`: the repository is named, and only its configuration knows its top. */
readonly named?: true;
}
/** How an object path's top is found: `discovered` — by git's discovery from where it starts; `unknown` — not from the text. */
export type RepositoryTop = "discovered" | "unknown";
/** {@link ObjectPathRepository} of the program's words in front of its subcommand, read by the program's own row. */
export declare function objectPathRepositoryOf(row: ProgramRow | undefined, globals: readonly Read[]): ObjectPathRepository;
/** Whether a command's environment may carry a variable git reads for its repository (any `GIT_*` name one of its parts holds;
* `all`: a part whose names are not known). */
export declare function mayCarryGitVariables(...names: readonly (Iterable<string> | "all")[]): boolean;
/** Where a process stands after it `chdir()`s to `spelling` from each of `bases` (git's `-C`, a launcher's working-directory
* option): the kernel's walk of the spelling, a `..` kept (`<base>/link/..` is the link target's parent, not `<base>`).
* `undefined` where the spelling resolves to no place from some base (`~user`, a namespace spelling the base's family refuses —
* a device spelling's drive stand-in is where it MAY lead, no place a process stands). */
export declare function chdirFrom(bases: readonly string[], spelling: string, homeDir: string | undefined): string[] | undefined;
/** Where a `chdir()` to `spelling` from `bases` MAY lead without naming a place ({@link chdirFrom}): a device spelling's drive
* stand-in from each base — the deny floor of a directory the text does not place, never a place a process stands. */
export declare function chdirMayLeadTo(bases: readonly string[], spelling: string, homeDir: string | undefined): string[];
/** The place of a RELATIVE object path: the directories it is relative to (`at`: where the command stands; `floor`: the deny
* floor of an unsettled `at`), and how its top is found where it is relative to the top. */
export declare function objectPathPlacement(spelled: string, repository: ObjectPathRepository | undefined, at: readonly string[] | "unmodelled", floor: readonly string[] | undefined, homeDir: string | undefined, variables: boolean): {
readonly bases: readonly string[] | "unmodelled";
readonly floorBases?: readonly string[];
readonly repositoryTop?: RepositoryTop;
};
/** Each directory, and every directory above it (its `..`-folded spelling's, a spelling that climbs kept beside them). */
export declare function everyAncestor(dirs: readonly string[]): string[];
/** What {@link repositoryTopOf} asks of the environment (the station's door, where it has one). */
export type RepositoryProbe = Pick<ExecutionEnv, "canonicalPath" | "fileInfo" | "readTextFile" | "readLink">;
/**
* The repository top git's discovery finds starting in `dir` (setup.c `setup_git_directory_gently_1`): walking up from the
* directory's canonical form, the first directory holding a `.git` DIRECTORY that is a repository (`HEAD` naming a ref or an
* object id, `objects/` and `refs/` directories) whose own `config` names no work tree. `undefined` wherever git's answer may be
* another directory, or the history it reads another directory's: a `.git` that is not such a directory — a `gitdir:` file or a
* link, which name a repository kept elsewhere (a linked work tree's, a submodule's, the home's own), or one git skips (an
* empty or broken one) and walks on from —, a directory that is itself a repository (a bare one, the inside of a `.git`), a
* configuration that may name the work tree, no repository at all, or a lookup the environment did not answer. Any reader of
* "which repository does git run in from here" reads it.
*/
export declare function repositoryTopOf(fs: RepositoryProbe, dir: string, family: PathFamily, signal?: AbortSignal): Promise<string | undefined>;