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 client/src/blobs.ts --json
JSON
/christopher/abso-core/blame/client/src/blobs.ts?format=json
65 linesFirst import 94% · review 6%Last change review in version 28,

65 lines from 3 changes in 3 versions.

init0Start the project1// Binary files (#27): content-addressed blobs. The server keeps a binary
2// file's bytes by their SHA-256 (PUT and GET /p/:project/blobs/<sha256>), and
3// the file in the graph points at that hash. The client keeps the hash it
4// knows for each binary file in .avcs/blobs.json, as it keeps the known copy
5// of a text file, and uploads only a hash the server hasn't been told about.
6
7import { createHash } from "node:crypto";
8import { readFileSync, statSync } from "node:fs";
9import { join } from "node:path";
10import { writeFileAtomic } from "./folder.ts";
review17New folders keep their state in .abso/, and the machine's sign-in, servers and admin token are read from ~/.abso/ first, then ~/.avcs/. A folder made before, with only .avcs/, is untouched: it keeps working, is never half-moved, and no older client or mod loses it. stateDir(root) and homeFile/homeWritePath are in the new client/src/state-dir.ts and replace the old AVCS_DIR constant everywhere. abso login writes only to ~/.abso/ and leaves ~/.avcs/ alone; logout removes both copies. The edit mod and the view mod read either folder. .abso is skipped like .avcs (including its odd spellings), the git exclude names whichever folder is in use, and the messages name .abso. Not changed: avcs.json (the server reads that name, so abso.json needs the server to learn it first), .avcsignore, env var names and wire headers. Tests: 709 run, 708 pass (one is skipped), including new ones for the folder choice, the home-file order and box sign-in; biome ci has no errors.Compare11import { stateDir } from "./state-dir.ts";
init0Start the project12
13/** The server's limit for one file's bytes. */
14export const MAX_BLOB_BYTES = 20 * 1024 * 1024;
16const BLOBS_FILE = "blobs.json";
18export function sha256(bytes: Uint8Array): string {
19 return createHash("sha256").update(bytes).digest("hex");
22/**
23 * Whether normalized text is the file the server keeps whole under `sha`
review28Client: abso.json is the project file (avcs.json still read; a new project gets abso.json unless it has either); new folders get .abso when no installed mod is older than 0.2.0; both mods are 0.2.0 (abso 253, 224)Compare24 * (#46): a text file matching abso.json's "whole", or over 1 MB, is stored
init0Start the project25 * like a binary file, by the hash of its text with LF endings. The client
26 * keeps that hash in blobs.json, and the file on disk stays text.
27 */
28export function keptWholeAs(text: string, sha: string | undefined): boolean {
29 return sha !== undefined && sha256(Buffer.from(text, "utf8")) === sha;
32/** A file's bytes and their hash, or undefined when it is gone; `tooBig` when over the server's limit (bytes not read). */
33export function blobOf(
34 path: string,
35): { sha: string; bytes: Uint8Array; size: number } | { tooBig: true; size: number } | undefined {
36 try {
37 const size = statSync(path).size;
38 if (size > MAX_BLOB_BYTES) return { tooBig: true, size };
39 const bytes = readFileSync(path);
40 return { sha: sha256(bytes), bytes, size };
41 } catch {
42 return undefined;
43 }
46/** The binary files the server has, as far as the client knows: path -> sha256. */
47export function readKnownBlobs(root: string): Map<string, string> {
48 try {
49 return new Map(
review17New folders keep their state in .abso/, and the machine's sign-in, servers and admin token are read from ~/.abso/ first, then ~/.avcs/. A folder made before, with only .avcs/, is untouched: it keeps working, is never half-moved, and no older client or mod loses it. stateDir(root) and homeFile/homeWritePath are in the new client/src/state-dir.ts and replace the old AVCS_DIR constant everywhere. abso login writes only to ~/.abso/ and leaves ~/.avcs/ alone; logout removes both copies. The edit mod and the view mod read either folder. .abso is skipped like .avcs (including its odd spellings), the git exclude names whichever folder is in use, and the messages name .abso. Not changed: avcs.json (the server reads that name, so abso.json needs the server to learn it first), .avcsignore, env var names and wire headers. Tests: 709 run, 708 pass (one is skipped), including new ones for the folder choice, the home-file order and box sign-in; biome ci has no errors.Compare50 Object.entries(JSON.parse(readFileSync(join(stateDir(root), BLOBS_FILE), "utf8")) as Record<string, string>),
init0Start the project51 );
52 } catch {
53 return new Map();
54 }
57export function writeKnownBlobs(root: string, blobs: ReadonlyMap<string, string>): void {
58 const sorted = Object.fromEntries([...blobs].sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0)));
review17New folders keep their state in .abso/, and the machine's sign-in, servers and admin token are read from ~/.abso/ first, then ~/.avcs/. A folder made before, with only .avcs/, is untouched: it keeps working, is never half-moved, and no older client or mod loses it. stateDir(root) and homeFile/homeWritePath are in the new client/src/state-dir.ts and replace the old AVCS_DIR constant everywhere. abso login writes only to ~/.abso/ and leaves ~/.avcs/ alone; logout removes both copies. The edit mod and the view mod read either folder. .abso is skipped like .avcs (including its odd spellings), the git exclude names whichever folder is in use, and the messages name .abso. Not changed: avcs.json (the server reads that name, so abso.json needs the server to learn it first), .avcsignore, env var names and wire headers. Tests: 709 run, 708 pass (one is skipped), including new ones for the folder choice, the home-file order and box sign-in; biome ci has no errors.Compare59 writeFileAtomic(join(stateDir(root), BLOBS_FILE), `${JSON.stringify(sorted, null, 1)}\n`);
init0Start the project60}
62/** Short form of a hash for people: the first 12 hex digits. */
63export function shortSha(sha: string | null | undefined): string {
64 return sha ? sha.slice(0, 12) : "(none)";