Skip to content

abso-core

Public

abso is version control for agents: the client, the engine and a server you can run on your own Cloudflare account.

Check passed
MCP
code on this site's /mcp
CLI
none: the JSON below is the answer
JSON
/christopher/abso-core/files/worker/project/path-rules.ts?version=2&format=json
66 linesFirst import 100%Last change First import in version 0, 1 version changed it

You're reading version 2. The newest is 318, and 2 versions since then changed this file. Go to the newestCompare with 318

1import { pathKey } from "./pathkey.ts";
2import { ProjectError } from "./project-error.ts";
3
4/**
5 * Why a path isn't canonical, or undefined when it is (#30). A canonical path
6 * is relative, uses forward slashes, and has no empty, "." or ".." segments,
7 * no control characters and no drive letter, so one file has one spelling.
8 * Otherwise "./harness/x" would slip past a filter on "harness/", and "../x"
9 * would escape the folder in every box that unpacks it. A ".git" segment would
10 * break the push to Artifacts.
11 */
12export function pathProblem(path: string): string | undefined {
13 if (typeof path !== "string" || path === "") return "a path must be a non-empty string";
14 if (/[\x00-\x1f\x7f]/.test(path)) return "a path may not hold control characters or line breaks";
15 if (path.includes("\\")) return "a path uses forward slashes, not backslashes";
16 if (path.startsWith("/")) return "a path is relative to the project, not absolute";
17 if (path.includes(":")) return "a path may not hold a colon (a drive letter, or a Windows stream like file::$DATA)";
18 // Every agent's disk must be able to hold it, Windows included, as the client screens (68f7a34).
19 if (/[<>"|?*]/.test(path)) return `a path may not hold < > " | ? or *, which Windows can't hold`;
20 for (const seg of path.split("/")) {
21 if (seg === "") return 'a path may not have empty segments (a leading, doubled or trailing "/")';
22 if (seg === "." || seg === "..") return `a path may not have "${seg}" segments`;
23 // By pathKey, so every spelling abso treats as one name counts (".GIT", ".gıt").
24 if (reservedKey(seg) === GIT_KEY) return "a path may not be under .git";
25 if (WINDOWS_DEVICE.test(seg.split(".")[0]!.trimEnd()))
26 return `"${seg}" is a Windows device name, which no Windows disk can hold as a file`;
27 // Windows drops a trailing dot or space, so ".git." is .git there.
28 if (/[. ]$/.test(seg)) return `"${seg}" ends in a dot or a space, which Windows drops`;
29 // A Windows short (8.3) name can be another file's second name: GIT~1 is .git (git's CVE-2019-1353).
30 if (/^[^.~ ]{1,6}~[0-9]{1,6}(\.[^. ]{1,3})?$/.test(seg))
31 return `"${seg}" looks like a Windows short name, which can be another file's second name`;
32 }
33 return undefined;
36/** Windows device names, with any extension, as the client refuses them (client/src/safety.ts). */
37const WINDOWS_DEVICE = /^(con|prn|aux|nul|com[0-9¹²³]|lpt[0-9¹²³]|conin\$|conout\$|clock\$)$/i;
38const GIT_KEY = pathKey(".git");
40/**
41 * A path part's key for comparing it against reserved names: pathKey, after
42 * dropping the characters HFS+ ignores in names, so ".g\u200Cit" is .git
43 * there (git's is_hfs_dotgit). Only for this comparison: U+200C and U+200D
44 * are ordinary characters in Persian and Indic names (Pinch Hitter).
45 */
46function reservedKey(seg: string): string {
47 return pathKey(seg.replace(/[\u200C-\u200F\u202A-\u202E\u206A-\u206F\uFEFF]/g, ""));
49const AVCS_KEY = pathKey(".avcs");
51/** For writes: the path must be canonical, and not under .avcs/ in any spelling, at any depth. */
52export function checkPath(path: string): void {
53 const problem = pathProblem(path);
54 if (problem) throw new ProjectError("bad-request", `bad file path ${JSON.stringify(path)}: ${problem}`);
55 // The client's settings stay in the agent's folder and are never published.
56 if (path.split("/").some((seg) => reservedKey(seg) === AVCS_KEY)) {
57 throw new ProjectError("bad-request", `${path} is under .avcs/, which stays in the agent's folder`);
58 }
61/** For reads (history, restore): any path a log may hold, canonical or from before #30. */
62export function checkReadPath(path: string): void {
63 if (typeof path !== "string" || path === "" || /[\n\r]/.test(path)) {
64 throw new ProjectError("bad-request", `bad file path ${JSON.stringify(path)}`);
65 }