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

Versions 52 to 318

Compare

+102 −0 in 1 place
new file, 102 lines
1+import type { SqliteStorage } from "./engine-project.ts";
2+import type { StoredGitBytes } from "./git-object-bytes.ts";
3+import { decodeGitPack, type PackInflater } from "./git-pack-decode.ts";
4+import { GitPackResolver } from "./git-pack-resolver.ts";
5+import { GitPackSpool } from "./git-pack-spool.ts";
6+
7+/** One clone's temporary pack store. The caller must dispose it in finally. */
8+export class GitDiskIntake {
9+ /** Cold object construction only, before any intake or reader is created. */
10+ static recover(storage: SqliteStorage): void {
11+ // Constructors establish scratch tables only; they do not alter project state.
12+ const resolver = new GitPackResolver(storage, 0);
13+ storage.transactionSync(() => {
14+ GitPackSpool.recover(storage);
15+ storage.sql.exec("DELETE FROM git_pack_resolve");
16+ storage.sql.exec("DELETE FROM git_object_bytes");
17+ storage.sql.exec("DELETE FROM git_object_meta");
18+ storage.sql.exec("DELETE FROM git_object_budget");
19+ });
20+ resolver.dispose();
21+ }
22+ private readonly spool: GitPackSpool;
23+ private readonly resolver: GitPackResolver;
24+ private readonly maxPackBytes: number;
25+ private state: "new" | "loading" | "ready" | "closed" = "new";
26+ constructor(storage: SqliteStorage, maxPackBytes: number, maxObjectBytes: number, maxDecodedBytes = maxPackBytes) {
27+ if (!Number.isSafeInteger(maxPackBytes) || maxPackBytes < 32) throw Error("invalid pack limit");
28+ this.maxPackBytes = maxPackBytes;
29+ this.resolver = new GitPackResolver(storage, maxObjectBytes, maxDecodedBytes);
30+ this.spool = new GitPackSpool(storage);
31+ }
32+ attach(cache: object): void {
33+ const key = Symbol.for("abso.git.disk-pack");
34+ if (key in cache) throw Error("Git disk intake already attached");
35+ Object.defineProperty(cache, key, { value: this });
36+ }
37+ async ingest(
38+ chunks: AsyncIterable<Uint8Array> | Iterable<Uint8Array> | AsyncIterator<Uint8Array>,
39+ createInflater: () => PackInflater,
40+ ): Promise<void> {
41+ if (this.state !== "new") throw Error("Git disk intake already used");
42+ this.state = "loading";
43+ const iterator =
44+ Symbol.asyncIterator in chunks
45+ ? chunks[Symbol.asyncIterator]()
46+ : Symbol.iterator in chunks
47+ ? chunks[Symbol.iterator]()
48+ : chunks;
49+ try {
50+ const source = {
51+ [Symbol.asyncIterator]: () => ({
52+ next: async () => iterator.next(),
53+ return: async () => (iterator.return ? iterator.return() : { done: true as const, value: undefined }),
54+ }),
55+ };
56+ await this.spool.ingest(source, this.maxPackBytes);
57+ if (this.state !== "loading") throw Error("Git disk intake closed during download");
58+ decodeGitPack(this.spool, this.resolver, createInflater);
59+ this.spool.dispose();
60+ this.state = "ready";
61+ } catch (error) {
62+ try {
63+ await iterator.return?.();
64+ } catch {
65+ /* Preserve the intake failure. */
66+ }
67+ this.dispose();
68+ throw error;
69+ }
70+ }
71+ bytes(oid: string): StoredGitBytes | undefined {
72+ if (this.state === "closed") throw Error("Git disk intake is closed");
73+ if (this.state !== "ready") return undefined;
74+ return this.resolver.find(oid);
75+ }
76+ read(oid: string): { format: "content"; type: string; object: Buffer } | undefined {
77+ const stored = this.bytes(oid);
78+ if (!stored) return undefined;
79+ // Existing Git consumers require one complete object. This does not claim
80+ // bounded blob consumption; it removes whole-pack retention and caching.
81+ const object = Buffer.alloc(stored.byteLength);
82+ for (let at = 0; at < stored.byteLength; at += 65536) {
83+ object.set(stored.read(at, Math.min(65536, stored.byteLength - at)), at);
84+ }
85+ return { format: "content", type: stored.type, object };
86+ }
87+ assertReady(): void {
88+ if (this.state !== "ready") throw Error("Git disk intake was not used by the installed runtime");
89+ }
90+ [Symbol.dispose](): void {
91+ this.dispose();
92+ }
93+ dispose(): void {
94+ if (this.state === "closed") return;
95+ this.state = "closed";
96+ try {
97+ this.resolver.dispose();
98+ } finally {
99+ this.spool.dispose();
100+ }
101+ }
102+}
MCP
compare on this site's /mcp
CLI
abso diff 52 318 server/src/git-disk-intake.ts --json
JSON
/christopher/abso-core/compare/52..318?file=server%2Fsrc%2Fgit-disk-intake.ts&format=json