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
blame on this site's /mcp
CLI
abso blame server/src/ingest.ts --version 182 --json
JSON
/christopher/abso-core/blame/server/src/ingest.ts?version=182&format=json
266 linesspeed 61% · codex-capacity-chair 39%Last change codex-capacity-chair in version 178,

266 lines from 2 changes in 2 versions.

speed150Open server: the project Worker, Durable Object and Artifacts (issue 17)Compare1// In from plain git (#8, demo moment 5): commits a person pushed to the
2// project's Artifacts repo, read back for project.ingest. Every commit the
3// Worker pushes ends "abso-version: N" ("avcs-version: N" before the rename); the commits above the newest such
4// commit that haven't been taken in yet are the person's, and N is their base.
codex-capacity-chair178Use disk-backed Git intake behind disk-first switch; cleared in review ask 56Compare5import git, { type HttpClient } from "isomorphic-git";
speed150Open server: the project Worker, Durable Object and Artifacts (issue 17)Compare6import type { FileModes } from "../../worker/project/project-api.ts";
codex-capacity-chair178Use disk-backed Git intake behind disk-first switch; cleared in review ask 56Compare7import type { SqliteStorage } from "./engine-project.ts";
8import { gitBlobText, InvalidGitUtf8 } from "./git-blob-text.ts";
9import { GitDiskIntake } from "./git-disk-intake.ts";
10import { gitHttp } from "./git-http.ts";
speed150Open server: the project Worker, Durable Object and Artifacts (issue 17)Compare11import { MemoryFS } from "./memory-fs.ts";
12import { repoName } from "./push.ts";
codex-capacity-chair178Use disk-backed Git intake behind disk-first switch; cleared in review ask 56Compare14const http = gitHttp();
speed150Open server: the project Worker, Durable Object and Artifacts (issue 17)Compare16const EXEC = 0o100755;
17const LINK = 0o120000;
19/** How far back to look for the Worker's last commit. */
20const DEPTH = 50;
21const text = new TextDecoder("utf-8", { fatal: true, ignoreBOM: false });
23export interface PushedCommits {
24 /** main's head when read. */
25 head: string;
26 author: string;
27 base: number;
28 /** Oldest first, each with its whole tree as text and every file's mode. Binary files are left out. */
29 commits: {
30 sha: string;
31 message: string;
32 files: Record<string, string>;
33 modes: FileModes;
34 blobs: Record<string, string>;
35 }[];
36 /** Binary files over the blob limit, left out of the commits. */
37 tooBig: string[];
40export function absoVersion(message: string): number | undefined {
41 const m = /^(?:abso|avcs)-version: (\d+)\s*$/m.exec(message);
42 return m ? Number(m[1]) : undefined;
45async function readAccess(
46 artifacts: Artifacts,
47 project: string,
codex-capacity-chair178Use disk-backed Git intake behind disk-first switch; cleared in review ask 56Compare48): Promise<{
49 url: string;
50 onAuth: () => { username: string; password: string };
51} | null> {
speed150Open server: the project Worker, Durable Object and Artifacts (issue 17)Compare52 let repo: Awaited<ReturnType<Artifacts["get"]>>;
53 try {
54 repo = await artifacts.get(repoName(project));
55 } catch {
56 return null;
57 }
58 using r = repo;
59 const [info, token] = await Promise.all([r.info(), r.createToken("read", 600)]);
60 const password = token.plaintext.split("?expires=")[0]!;
61 return { url: info!.remote, onAuth: () => ({ username: "x", password }) };
64/** main's head on the project's repo, or null when there's no repo or no main yet. Cheap: one ref listing. */
65export async function remoteHead(artifacts: Artifacts, project: string): Promise<string | null> {
66 const access = await readAccess(artifacts, project);
67 if (!access) return null;
codex-capacity-chair178Use disk-backed Git intake behind disk-first switch; cleared in review ask 56Compare68 const refs = await git.listServerRefs({
speed150Open server: the project Worker, Durable Object and Artifacts (issue 17)Compare69 http,
codex-capacity-chair178Use disk-backed Git intake behind disk-first switch; cleared in review ask 56Compare70 url: access.url,
71 onAuth: access.onAuth,
72 prefix: "refs/heads/main",
73 });
speed150Open server: the project Worker, Durable Object and Artifacts (issue 17)Compare74 return refs.find((r) => r.ref === "refs/heads/main")?.oid ?? null;
77/**
78 * The commits pushed since `seen` (the last head this project handled), or
79 * none when every commit above the Worker's last one has been seen.
80 */
81/** Stores a binary file's bytes and answers their SHA-256, or null when they're over the limit. */
82export type StoreBlob = (bytes: Uint8Array) => Promise<string | null>;
codex-capacity-chair178Use disk-backed Git intake behind disk-first switch; cleared in review ask 56Compare83export type RetainFileChunks = (
84 files: Record<string, string>,
85 path: string,
86 chunks: Iterable<string>,
87 oid: string,
88) => void;
speed150Open server: the project Worker, Durable Object and Artifacts (issue 17)Compare89
90/**
91 * `oldBlob` gives shared's blob for a path: a binary file over the limit
92 * keeps it, since a path missing from a commit would mean the file was deleted.
93 */
94export async function pushedSince(
95 artifacts: Artifacts,
96 project: string,
97 seen: string | undefined,
98 storeBlob?: StoreBlob,
99 oldBlob: (path: string) => string | undefined = () => undefined,
codex-capacity-chair178Use disk-backed Git intake behind disk-first switch; cleared in review ask 56Compare100 retainFile: (files: Record<string, string>, path: string, body: string, oid?: string) => void = (
101 files,
102 path,
103 body,
104 ) => {
105 files[path] = body;
106 },
107 disk?: {
108 storage: SqliteStorage;
109 maxPackBytes: number;
110 maxObjectBytes: number;
111 maxDecodedBytes?: number;
112 http?: HttpClient;
113 retainFileChunks?: RetainFileChunks;
114 },
speed150Open server: the project Worker, Durable Object and Artifacts (issue 17)Compare115): Promise<PushedCommits | null> {
116 const access = await readAccess(artifacts, project);
117 if (!access) return null;
118 const fs = new MemoryFS();
119 const dir = "/repo";
codex-capacity-chair178Use disk-backed Git intake behind disk-first switch; cleared in review ask 56Compare120 using intake = disk
121 ? new GitDiskIntake(disk.storage, disk.maxPackBytes, disk.maxObjectBytes, disk.maxDecodedBytes)
122 : undefined;
123 const cache = disk ? {} : undefined;
124 if (intake && cache) intake.attach(cache);
speed150Open server: the project Worker, Durable Object and Artifacts (issue 17)Compare125 await git.clone({
126 fs,
codex-capacity-chair178Use disk-backed Git intake behind disk-first switch; cleared in review ask 56Compare127 cache,
128 http: disk?.http ?? http,
speed150Open server: the project Worker, Durable Object and Artifacts (issue 17)Compare129 dir,
130 url: access.url,
131 onAuth: access.onAuth,
132 ref: "main",
133 singleBranch: true,
134 depth: DEPTH,
135 noCheckout: true,
136 });
codex-capacity-chair178Use disk-backed Git intake behind disk-first switch; cleared in review ask 56Compare137 intake?.assertReady();
138 const log = await git.log({ fs, dir, cache, ref: "main", depth: DEPTH });
speed150Open server: the project Worker, Durable Object and Artifacts (issue 17)Compare139 if (log.length === 0) return null;
140 const head = log[0]!.oid;
141 const fresh: typeof log = [];
142 let base: number | undefined;
143 let past = false;
144 for (const c of log) {
145 if (c.oid === seen) past = true;
146 base = absoVersion(c.commit.message);
147 if (base !== undefined) break;
148 if (!past) fresh.unshift(c);
149 }
150 if (base === undefined) throw new Error(`no abso-version commit in main's last ${DEPTH} commits`);
151 const commits = [];
152 const tooBig = new Set<string>();
153 for (const c of fresh)
154 commits.push({
155 sha: c.oid,
156 message: c.commit.message.trim(),
codex-capacity-chair178Use disk-backed Git intake behind disk-first switch; cleared in review ask 56Compare157 ...(await treeText(
158 fs,
159 dir,
160 c.oid,
161 storeBlob,
162 tooBig,
163 oldBlob,
164 retainFile,
165 cache,
166 intake,
167 disk?.retainFileChunks,
168 )),
speed150Open server: the project Worker, Durable Object and Artifacts (issue 17)Compare169 });
codex-capacity-chair178Use disk-backed Git intake behind disk-first switch; cleared in review ask 56Compare170 return {
171 head,
172 author: fresh.at(-1)?.commit.author.name ?? "git",
173 base,
174 commits,
175 tooBig: [...tooBig],
176 };
speed150Open server: the project Worker, Durable Object and Artifacts (issue 17)Compare177}
179/**
180 * A commit's whole tree as text, and every file's mode: 100755 is exec, and
181 * a link (120000) is "" with its target in modes. Files that aren't UTF-8
182 * are left out.
183 */
codex-capacity-chair178Use disk-backed Git intake behind disk-first switch; cleared in review ask 56Compare184export async function treeText(
speed150Open server: the project Worker, Durable Object and Artifacts (issue 17)Compare185 fs: MemoryFS,
186 dir: string,
187 oid: string,
188 storeBlob: StoreBlob | undefined,
189 tooBig: Set<string>,
190 oldBlob: (path: string) => string | undefined,
codex-capacity-chair178Use disk-backed Git intake behind disk-first switch; cleared in review ask 56Compare191 retainFile: (files: Record<string, string>, path: string, body: string, oid?: string) => void,
192 cache: object = {},
193 intake?: GitDiskIntake,
194 retainFileChunks?: RetainFileChunks,
195): Promise<{
196 files: Record<string, string>;
197 modes: FileModes;
198 blobs: Record<string, string>;
199}> {
speed150Open server: the project Worker, Durable Object and Artifacts (issue 17)Compare200 const files: Record<string, string> = {};
201 const modes: FileModes = {};
202 const blobs: Record<string, string> = {};
203 await git.walk({
204 fs,
codex-capacity-chair178Use disk-backed Git intake behind disk-first switch; cleared in review ask 56Compare205 cache,
speed150Open server: the project Worker, Durable Object and Artifacts (issue 17)Compare206 dir,
207 trees: [git.TREE({ ref: oid })],
codex-capacity-chair178Use disk-backed Git intake behind disk-first switch; cleared in review ask 56Compare208 iterate: async (walk, children) => {
209 for (const child of children) await walk(child);
210 return [];
211 },
212 reduce: async () => undefined,
speed150Open server: the project Worker, Durable Object and Artifacts (issue 17)Compare213 map: async (path, [entry]) => {
214 if (!entry || path === ".") return true;
215 if ((await entry.type()) !== "blob") return true;
216 const mode = await entry.mode();
codex-capacity-chair178Use disk-backed Git intake behind disk-first switch; cleared in review ask 56Compare217 const blobOid = await entry.oid();
218 if (intake && retainFileChunks && mode !== LINK) {
219 const stored = intake.bytes(blobOid);
220 if (stored?.type !== "blob") throw Error("Git intake blob is missing");
221 let valid = true;
222 try {
223 // Validate before retaining: a late invalid byte must take the binary path.
224 for (const _ of gitBlobText(stored)) {
225 /* Retain no decoded text. */
226 }
227 } catch (error) {
228 if (!(error instanceof InvalidGitUtf8)) throw error;
229 valid = false;
230 }
231 if (valid) {
232 retainFileChunks(files, path, gitBlobText(stored), blobOid);
233 modes[path] = { exec: mode === EXEC, link: null };
234 return true;
235 }
236 }
speed150Open server: the project Worker, Durable Object and Artifacts (issue 17)Compare237 const bytes = await entry.content();
238 if (!bytes) return true;
239 let body: string;
240 try {
241 body = text.decode(bytes);
242 } catch {
243 // Binary (#27): the bytes go to the blob store, and the file is a pointer to them.
244 const sha = storeBlob ? await storeBlob(bytes) : null;
245 if (sha) {
246 blobs[path] = sha;
codex-capacity-chair178Use disk-backed Git intake behind disk-first switch; cleared in review ask 56Compare247 modes[path] = { exec: mode === EXEC, link: null };
speed150Open server: the project Worker, Durable Object and Artifacts (issue 17)Compare248 } else if (storeBlob) {
249 tooBig.add(path);
250 const kept = oldBlob(path);
251 if (kept) blobs[path] = kept;
252 }
253 return true;
254 }
255 if (mode === LINK) {
codex-capacity-chair178Use disk-backed Git intake behind disk-first switch; cleared in review ask 56Compare256 retainFile(files, path, "");
speed150Open server: the project Worker, Durable Object and Artifacts (issue 17)Compare257 modes[path] = { exec: false, link: body };
258 } else {
codex-capacity-chair178Use disk-backed Git intake behind disk-first switch; cleared in review ask 56Compare259 retainFile(files, path, body, blobOid);
speed150Open server: the project Worker, Durable Object and Artifacts (issue 17)Compare260 modes[path] = { exec: mode === EXEC, link: null };
261 }
262 return true;
263 },
264 });
265 return { files, modes, blobs };