- MCP
- blame on this site's /mcp
- CLI
- abso blame server/src/ingest.ts --json
- JSON
- /christopher/abso-core/blame/server/src/ingest.ts?format=json
275 linesspeed 59% · codex-capacity-chair 41%Last change codex-capacity-chair in version 183,
275 lines from 3 changes in 3 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[];
38}
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;
43}
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 }) };
62}
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({
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;
75}
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;
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;
codex-capacity-chair183Skip whole reads of binaries over the blob limit on disk intakeCompare112 maxBinaryBytes?: number;
codex-capacity-chair178Use disk-backed Git intake behind disk-first switch; cleared in review ask 56Compare113 http?: HttpClient;
114 retainFileChunks?: RetainFileChunks;
115 },
speed150Open server: the project Worker, Durable Object and Artifacts (issue 17)Compare116): Promise<PushedCommits | null> {
117 const access = await readAccess(artifacts, project);
118 if (!access) return null;
119 const fs = new MemoryFS();
120 const dir = "/repo";
codex-capacity-chair178Use disk-backed Git intake behind disk-first switch; cleared in review ask 56Compare121 using intake = disk
122 ? new GitDiskIntake(disk.storage, disk.maxPackBytes, disk.maxObjectBytes, disk.maxDecodedBytes)
123 : undefined;
124 const cache = disk ? {} : undefined;
125 if (intake && cache) intake.attach(cache);
speed150Open server: the project Worker, Durable Object and Artifacts (issue 17)Compare126 await git.clone({
127 fs,
codex-capacity-chair178Use disk-backed Git intake behind disk-first switch; cleared in review ask 56Compare128 cache,
129 http: disk?.http ?? http,
131 url: access.url,
132 onAuth: access.onAuth,
133 ref: "main",
134 singleBranch: true,
135 depth: DEPTH,
136 noCheckout: true,
137 });
codex-capacity-chair178Use disk-backed Git intake behind disk-first switch; cleared in review ask 56Compare138 intake?.assertReady();
139 const log = await git.log({ fs, dir, cache, ref: "main", depth: DEPTH });
speed150Open server: the project Worker, Durable Object and Artifacts (issue 17)Compare140 if (log.length === 0) return null;
141 const head = log[0]!.oid;
142 const fresh: typeof log = [];
143 let base: number | undefined;
144 let past = false;
145 for (const c of log) {
146 if (c.oid === seen) past = true;
147 base = absoVersion(c.commit.message);
148 if (base !== undefined) break;
149 if (!past) fresh.unshift(c);
150 }
151 if (base === undefined) throw new Error(`no abso-version commit in main's last ${DEPTH} commits`);
152 const commits = [];
153 const tooBig = new Set<string>();
154 for (const c of fresh)
155 commits.push({
156 sha: c.oid,
157 message: c.commit.message.trim(),
codex-capacity-chair178Use disk-backed Git intake behind disk-first switch; cleared in review ask 56Compare158 ...(await treeText(
159 fs,
160 dir,
161 c.oid,
162 storeBlob,
163 tooBig,
164 oldBlob,
165 retainFile,
166 cache,
167 intake,
168 disk?.retainFileChunks,
codex-capacity-chair183Skip whole reads of binaries over the blob limit on disk intakeCompare169 disk?.maxBinaryBytes,
codex-capacity-chair178Use disk-backed Git intake behind disk-first switch; cleared in review ask 56Compare170 )),
codex-capacity-chair178Use disk-backed Git intake behind disk-first switch; cleared in review ask 56Compare172 return {
173 head,
174 author: fresh.at(-1)?.commit.author.name ?? "git",
175 base,
176 commits,
177 tooBig: [...tooBig],
178 };
181/**
182 * A commit's whole tree as text, and every file's mode: 100755 is exec, and
183 * a link (120000) is "" with its target in modes. Files that aren't UTF-8
184 * are left out.
185 */
codex-capacity-chair178Use disk-backed Git intake behind disk-first switch; cleared in review ask 56Compare186export async function treeText(
speed150Open server: the project Worker, Durable Object and Artifacts (issue 17)Compare187 fs: MemoryFS,
188 dir: string,
189 oid: string,
190 storeBlob: StoreBlob | undefined,
191 tooBig: Set<string>,
192 oldBlob: (path: string) => string | undefined,
codex-capacity-chair178Use disk-backed Git intake behind disk-first switch; cleared in review ask 56Compare193 retainFile: (files: Record<string, string>, path: string, body: string, oid?: string) => void,
194 cache: object = {},
195 intake?: GitDiskIntake,
196 retainFileChunks?: RetainFileChunks,
codex-capacity-chair183Skip whole reads of binaries over the blob limit on disk intakeCompare197 maxBinaryBytes?: number,
codex-capacity-chair178Use disk-backed Git intake behind disk-first switch; cleared in review ask 56Compare198): Promise<{
199 files: Record<string, string>;
200 modes: FileModes;
201 blobs: Record<string, string>;
202}> {
speed150Open server: the project Worker, Durable Object and Artifacts (issue 17)Compare203 const files: Record<string, string> = {};
204 const modes: FileModes = {};
205 const blobs: Record<string, string> = {};
206 await git.walk({
207 fs,
codex-capacity-chair178Use disk-backed Git intake behind disk-first switch; cleared in review ask 56Compare208 cache,
210 trees: [git.TREE({ ref: oid })],
codex-capacity-chair178Use disk-backed Git intake behind disk-first switch; cleared in review ask 56Compare211 iterate: async (walk, children) => {
212 for (const child of children) await walk(child);
213 return [];
214 },
215 reduce: async () => undefined,
speed150Open server: the project Worker, Durable Object and Artifacts (issue 17)Compare216 map: async (path, [entry]) => {
217 if (!entry || path === ".") return true;
218 if ((await entry.type()) !== "blob") return true;
219 const mode = await entry.mode();
codex-capacity-chair178Use disk-backed Git intake behind disk-first switch; cleared in review ask 56Compare220 const blobOid = await entry.oid();
221 if (intake && retainFileChunks && mode !== LINK) {
222 const stored = intake.bytes(blobOid);
223 if (stored?.type !== "blob") throw Error("Git intake blob is missing");
224 let valid = true;
225 try {
226 // Validate before retaining: a late invalid byte must take the binary path.
227 for (const _ of gitBlobText(stored)) {
228 /* Retain no decoded text. */
229 }
230 } catch (error) {
231 if (!(error instanceof InvalidGitUtf8)) throw error;
232 valid = false;
233 }
234 if (valid) {
235 retainFileChunks(files, path, gitBlobText(stored), blobOid);
236 modes[path] = { exec: mode === EXEC, link: null };
codex-capacity-chair183Skip whole reads of binaries over the blob limit on disk intakeCompare237 return true;
238 }
239 if (storeBlob && maxBinaryBytes !== undefined && stored.byteLength > maxBinaryBytes) {
240 tooBig.add(path);
241 const kept = oldBlob(path);
242 if (kept) blobs[path] = kept;
codex-capacity-chair178Use disk-backed Git intake behind disk-first switch; cleared in review ask 56Compare243 return true;
244 }
245 }
speed150Open server: the project Worker, Durable Object and Artifacts (issue 17)Compare246 const bytes = await entry.content();
247 if (!bytes) return true;
248 let body: string;
249 try {
250 body = text.decode(bytes);
251 } catch {
252 // Binary (#27): the bytes go to the blob store, and the file is a pointer to them.
253 const sha = storeBlob ? await storeBlob(bytes) : null;
254 if (sha) {
255 blobs[path] = sha;
codex-capacity-chair178Use disk-backed Git intake behind disk-first switch; cleared in review ask 56Compare256 modes[path] = { exec: mode === EXEC, link: null };
speed150Open server: the project Worker, Durable Object and Artifacts (issue 17)Compare257 } else if (storeBlob) {
258 tooBig.add(path);
259 const kept = oldBlob(path);
260 if (kept) blobs[path] = kept;
261 }
262 return true;
263 }
264 if (mode === LINK) {
codex-capacity-chair178Use disk-backed Git intake behind disk-first switch; cleared in review ask 56Compare265 retainFile(files, path, "");
speed150Open server: the project Worker, Durable Object and Artifacts (issue 17)Compare266 modes[path] = { exec: false, link: body };
267 } else {
codex-capacity-chair178Use disk-backed Git intake behind disk-first switch; cleared in review ask 56Compare268 retainFile(files, path, body, blobOid);
speed150Open server: the project Worker, Durable Object and Artifacts (issue 17)Compare269 modes[path] = { exec: mode === EXEC, link: null };
270 }
271 return true;
272 },
273 });
274 return { files, modes, blobs };
275}