@code-yeongyu/senpi
Version:
Coding agent CLI with read, bash, edit, write tools and session management
52 lines • 3.88 kB
TypeScript
import { type Stats } from "node:fs";
import { type MovedBreadcrumb } from "./breadcrumb.ts";
import { type PathPlatform } from "./path-match.ts";
export interface MovedPath {
/** The directory holding the breadcrumb (the old data root). */
readonly oldRoot: string;
readonly movedTo: string;
readonly mappedPath: string;
}
export declare const MAX_HOPS = 3;
/** A breadcrumb or marker is a few hundred bytes; anything larger is not one and is never read. */
export declare const MAX_TRUST_FILE_BYTES: number;
/** One small JSON file the guard may trust, re-read only when it changed; `undefined` when absent, unreadable or untrusted. */
export declare function readJsonFileSync(file: string): unknown;
export declare function readJsonFileAsync(file: string): Promise<unknown>;
export declare const breadcrumbFile: (dir: string) => string;
export declare const homeMarkerFile: (movedTo: string) => string;
/**
* Every OmO desktop data home lives under the user's home (`~/.omo/desktop`, `~/.omo-app`; plan 1.1), so a
* breadcrumb naming anywhere else is ignored before the walk touches that folder: a committed or planted breadcrumb
* can never make the guard open a network or automount path. `homes` holds the home as `os.homedir()` spells it and
* as its realpath, so a desktop that writes `movedTo` realpath'd on a host whose `$HOME` is a symlink (or macOS
* `/tmp` vs `/private/tmp`) still names a home under the user's.
*/
export declare function movedToInHome(dir: string, breadcrumb: MovedBreadcrumb, homes: readonly string[], platform: PathPlatform): boolean;
/**
* Whether the folder holding a matched breadcrumb may hold one (sixth review LOW-1): on POSIX a directory this user owns
* that nobody else can write, so a breadcrumb linked or written into a shared folder such as `/tmp` is ignored, while
* the owner's own breadcrumb keeps working with extra hard links (backups made with `cp -al` or `rsync --link-dest`).
* `stats` follows a symlink only at a legacy root directly under the home: when the path's canonicalization fails the
* walk meets a symlinked old root (`~/.t3`) by its own spelling, and the owner and mode of the folder it names decide
* (seventh review LOW-B); nobody else can repoint a link inside the user's own home. Anywhere else `stats` is the
* link's own `lstat`, so a symlink is refused: another user could repoint it between the breadcrumb read and this
* check. A folder that could not be examined is untrusted. Windows has no uid/mode to check.
*/
export declare function trustedFolder(dir: string, stats: Stats | undefined): boolean;
export declare function parsedBreadcrumb(dir: string, raw: unknown): MovedBreadcrumb | undefined;
/**
* A breadcrumb is bound to a real desktop home: `movedTo` lies outside the breadcrumb's folder and holds the
* desktop's ownership marker with the breadcrumb's `homeId`. The marker is immutable and its `origin.from` names only
* a home's first source, so a later hop cannot be checked against it; the binding is the homeId (plan section 2).
*/
export declare function trustedBreadcrumb(dir: string, breadcrumb: MovedBreadcrumb, markerRaw: unknown, platform: PathPlatform): MovedBreadcrumb | undefined;
/** The listed prefix `canonical` lies under, with its mapped path; the caller still checks the prefix is not live again. */
export declare function movedMatch(dir: string, breadcrumb: MovedBreadcrumb, canonical: string, platform: PathPlatform): {
readonly prefix: readonly string[];
readonly moved: MovedPath;
} | undefined;
/** A worktree prefix that holds its own `.git` again belongs to whoever re-created it (a later T3 Code worktree). */
export declare const gitEntryOf: (oldRoot: string, prefix: readonly string[]) => string | undefined;
export declare function movedPathReason(moved: MovedPath): string;
//# sourceMappingURL=breadcrumb-trust.d.ts.map