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/view-changes.ts?draft=login-timeout&format=json
67 linesFirst import 100%0 versions changed it
1import type { View } from "../../src/engine/index.ts";
2import { ProjectError } from "./project-error.ts";
3import type { FileChange, Mode, Modes } from "./project-types.ts";
4
5/** The listed files whose text differs between two views, before and after. */
6export function changesBetween(before: View, after: View, files: Iterable<string>): FileChange[] {
7 const out: FileChange[] = [];
8 for (const path of [...new Set(files)].toSorted()) {
9 const b = before.hasFile(path) ? before.text(path) : null;
10 const a = after.hasFile(path) ? after.text(path) : null;
11 const mode = modeChange(before, after, path);
12 const bb = before.attrs(path).blob;
13 const ab = after.attrs(path).blob;
14 const blob = bb !== ab ? { before: bb, after: ab } : undefined;
15 if (a !== b || mode || blob)
16 out.push({ path, before: b, after: a, ...(mode ? { mode } : {}), ...(blob ? { blob } : {}) });
17 }
18 return out;
21/** Whether a file differs between two views: its text, its mode, or its blob (what changesBetween lists). */
22export function differs(before: View, after: View, path: string): boolean {
23 const had = before.hasFile(path);
24 if (had !== after.hasFile(path)) return true;
25 if (had && !before.sameText(path, after)) return true;
26 const b = before.attrs(path);
27 const a = after.attrs(path);
28 return b.exec !== a.exec || b.link !== a.link || b.blob !== a.blob;
31/** A file's executable bit and link target, before and after, when either changed. */
32export function modeChange(before: View, after: View, path: string): { before: Mode; after: Mode } | undefined {
33 const b = before.attrs(path);
34 const a = after.attrs(path);
35 if (b.exec === a.exec && b.link === a.link) return undefined;
36 return { before: { exec: b.exec, link: b.link }, after: { exec: a.exec, link: a.link } };
39/** Every executable file and link in a view. */
40export function modesOf(view: View): Modes {
41 const out: Modes = {};
42 for (const path of view.paths()) {
43 const a = view.attrs(path);
44 if (a.exec || a.link !== null)
45 out[path] = { ...(a.exec ? { exec: true } : {}), ...(a.link !== null ? { link: a.link } : {}) };
46 }
47 return out;
50export function checkModes(modes: unknown): Modes {
51 if (typeof modes !== "object" || modes === null || Array.isArray(modes))
52 throw new ProjectError("bad-request", "modes must be {path: {exec, link}}");
53 for (const [path, m] of Object.entries(modes as Record<string, unknown>)) {
54 const mode = m as Mode;
55 if (typeof m !== "object" || m === null) throw new ProjectError("bad-request", `${path}: a mode is {exec?, link?}`);
56 if (mode.exec !== undefined && typeof mode.exec !== "boolean")
57 throw new ProjectError("bad-request", `${path}: exec is true or false`);
58 if (
59 mode.link !== undefined &&
60 mode.link !== null &&
61 (typeof mode.link !== "string" || mode.link === "" || /[\n\r]/.test(mode.link))
62 ) {
63 throw new ProjectError("bad-request", `${path}: link is a target path or null`);
64 }
65 }
66 return modes as Modes;