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/init.ts?version=2&format=json
73 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

1// Create the project from its first files. Writes go through InitHost; today
2// the host is Project.
3
4import { type AttrSet, buildBase, canonicalText, type View } from "../../src/engine/index.ts";
5import { checkPath } from "./path-rules.ts";
6import { ProjectError } from "./project-error.ts";
7import { configProblem } from "./project-helpers.ts";
8import type { Entry, Modes, ProjectOptions } from "./project-types.ts";
9import { clashInPaths } from "./spelling.ts";
10import { checkModes } from "./view-changes.ts";
12/** What creating the project needs from a Project. */
13export interface InitHost {
14 initialized(): boolean;
15 readonly whole: ProjectOptions["whole"];
16 wholeOut(
17 files: Readonly<Record<string, string | null>>,
18 blobs: Readonly<Record<string, string>>,
19 view: View | undefined,
20 config?: string,
21 ): { files: Record<string, string | null>; blobs: Record<string, string> };
22 checkBlobs(blobs: unknown, files: object): Record<string, string>;
23 commit(entries: Entry[]): void;
26/** Create the project from its first files. */
27export function init(
28 host: InitHost,
29 files: Readonly<Record<string, string>>,
30 time: number,
31 modes: Modes = {},
32 blobs: Readonly<Record<string, string>> = {},
33): { version: 0; skipped: string[] } {
34 if (host.initialized()) throw new ProjectError("already-initialized", "the project already exists");
35 if (typeof files !== "object" || files === null) throw new ProjectError("bad-request", "init needs {files}");
36 const clash = clashInPaths([...new Set([...Object.keys(files), ...Object.keys(blobs)])].toSorted());
37 if (clash) throw new ProjectError("bad-request", `init: ${clash} (#49)`);
38 const config = typeof files["avcs.json"] === "string" ? configProblem(files["avcs.json"]) : undefined;
39 if (config) throw new ProjectError("bad-request", `init: avcs.json ${config}`);
40 if (host.whole) {
41 // The project file being created says which paths are whole (#46).
42 const config = typeof files["avcs.json"] === "string" ? files["avcs.json"] : undefined;
43 ({ files, blobs } = host.wholeOut(files, blobs, undefined, config) as {
44 files: Record<string, string>;
45 blobs: Record<string, string>;
46 });
47 }
48 const kept: Record<string, string> = {};
49 const attrs: AttrSet[] = [];
50 for (const [path, sha] of Object.entries(host.checkBlobs(blobs, files)).toSorted(([a], [b]) => (a < b ? -1 : 1))) {
51 attrs.push({ file: path, name: "blob", value: sha });
52 }
53 for (const path of Object.keys(files).toSorted()) {
54 checkPath(path);
55 const text = files[path];
56 if (typeof text !== "string") throw new ProjectError("bad-request", `${path}: file text must be a string`);
57 const canonical = canonicalText(text);
58 kept[path] = canonical;
59 // An empty file is kept by its exists attribute.
60 if (canonical === "" && typeof modes[path]?.link !== "string")
61 attrs.push({ file: path, name: "exists", value: "1" });
62 }
63 for (const path of Object.keys(checkModes(modes)).toSorted()) {
64 checkPath(path);
65 const m = modes[path]!;
66 if (m.exec === true) attrs.push({ file: path, name: "exec", value: "1" });
67 if (typeof m.link === "string") attrs.push({ file: path, name: "link", value: m.link });
68 }
69 const atom = buildBase(kept, { author: "init", message: "Start the project", time }, attrs);
70 const skipped: string[] = [];
71 host.commit([{ type: "init", atom, time }]);
72 return { version: 0, skipped };