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
show on this site's /mcp
CLI
abso show 293 --json
JSON
/christopher/abso-core/versions/293?format=json

Local projects: the abso mod hands their edits to abso hook. The installer stamps the mod with the command that runs its checkout's abso hook (node, client/abso.ts); in a local project's folder the mod runs it with the edit, as Claude Code's command hook would, and passes its news to the chat. A mod installed before this one still skips local folders, and init says so.

of shared·pinch··Not checked

Version 292 · Files at version 293

6 files, 141 lines added, 14 removed.

--- a/client/hooks/register.test.ts
+++ b/client/hooks/register.test.ts
@@ -3,9 +3,10 @@
33
44import type { On } from "claude-code";
55import { expect, mock, test } from "claude-code/testing";
6+import { HOOK_COMMAND } from "./stamp.ts";
67
78/** The world beneath the mod: a chat in /w/p, an abso folder when `inFolder`, and a server with `news` waiting. */
8−function world(on: On, inFolder: boolean, news: string[][]) {
9+function world(on: On, inFolder: boolean, news: string[][], server = "https://avcs.test") {
910 mock.env(on, { AVCS_TOKEN: "test-token" });
1011 const clock = mock.clock(on, { now: 1_000_000 });
1112 const asked: string[] = [];
@@ -21,7 +22,7 @@
2122 on("fs.read", (_$, e) => {
2223 const path = norm(e.path);
2324 if (inFolder && path === "/w/p/.abso/config.json")
24− return { value: JSON.stringify({ server: "https://avcs.test", project: "p", agent: "bob" }) };
25+ return { value: JSON.stringify({ server, project: "p", agent: "bob" }) };
2526 if (written.has(path)) return { value: written.get(path)! };
2627 return { deny: `ENOENT: ${path}` };
2728 });
@@ -114,3 +115,38 @@
114115 expect(w.written.get("/w/p/.abso/hook.log") ?? "").toContain("not sent: a NUL byte at line 3");
115116 expect(w.asked.filter((u) => !u.endsWith("/news"))).toEqual([]);
116117});
119+test("a local project's edit goes to abso hook as Claude Code's command hook would get it, and its news to the chat", async ($, on) => {
120+ const w = world(on, true, [], "local");
121+ w.written.set("/w/p/notes.md", "hello\n");
122+ on("fs.stat", () => ({ value: { realPath: "/w/p/notes.md" } }) as never);
123+ on("session.id", () => ({ value: "sess" }));
124+ const ran: { argv: readonly string[]; stdin?: string; env?: Record<string, string> }[] = [];
125+ const context = "abso: Announcement from lead: hold pushes";
126+ on("process.run", (_$, e) => {
127+ ran.push({ argv: e.argv, stdin: e.init?.stdin, env: e.init?.env });
128+ const stdout = JSON.stringify({ hookSpecificOutput: { hookEventName: "PostToolUse", additionalContext: context } });
129+ return { value: { exitCode: 0, stdout, stderr: "" } } as never;
130+ });
131+ await $.session.start({ cwd: "/w/p" });
132+ await $.tool.call({ tool: "Write", tool_use_id: "t1", file_path: "/w/p/notes.md", content: "hello\n" } as never);
133+ await w.clock.advance(1_000);
134+ // A local project has no server to call: nothing goes over the network.
135+ expect(w.asked.filter((u) => !u.endsWith("/news"))).toEqual([]);
136+ const log = w.written.get("/w/p/.abso/hook.log") ?? "";
137+ if (HOOK_COMMAND === undefined) {
138+ // Loaded from a checkout, the mod has no client to hand it to.
139+ expect(ran).toEqual([]);
140+ expect(log).toContain("skipped: a local project");
141+ return;
142+ }
143+ expect(ran).toHaveLength(1);
144+ expect(ran[0]!.argv).toEqual(HOOK_COMMAND);
145+ expect(ran[0]!.env).toEqual({ ABSO_HOOK_FORCE: "1" });
146+ const input = JSON.parse(ran[0]!.stdin ?? "{}") as Record<string, unknown>;
147+ expect(input.session_id).toBe("sess");
148+ expect(input.tool_name).toBe("Write");
149+ expect((input.tool_input as Record<string, unknown>).file_path).toBe("/w/p/notes.md");
150+ expect(log).toContain("handed to abso hook");
151+ expect(w.appended).toEqual([context]);
152+});
--- a/client/hooks/register.ts
+++ b/client/hooks/register.ts
@@ -33,7 +33,7 @@
3333 uncomposedText,
3434 type Who,
3535} from "../src/core.ts";
36−import { STAMP } from "./stamp.ts";
36+import { HOOK_COMMAND, STAMP } from "./stamp.ts";
3737
3838const TOOLS = ["Edit", "MultiEdit", "Write", "NotebookEdit"];
3939/** A known copy holding a NUL byte reads as no known copy (the client treats it as binary). */
@@ -184,19 +184,22 @@
184184
185185/** A local project's folder (abso init --local): its config names no server. */
186186const LOCAL_FOLDER = /"server"\s*:\s*"local"/;
187+/** How long abso hook may take on a local project's edit: it waits up to two minutes for the store's lock. */
188+const LOCAL_HOOK_MS = 150_000;
187189
188190async function run($: Engine, job: Job): Promise<void> {
189191 const started = await $.clock.now().catch(() => job.queuedAt);
190192 let outcome: string;
191193 let news: readonly string[] = [];
194+ /** What abso hook handed back for the agent, on a local project's edit (it keeps the news log itself). */
195+ let handed: string | undefined;
192196 try {
193197 if ((await readOr($, `${await stateOf($, job.root)}/paused`)) !== undefined) {
194198 outcome = "skipped: recording is paused (abso resume)";
195199 } else if (/"reader"\s*:\s*true/.test((await readOr($, `${await stateOf($, job.root)}/config.json`)) ?? "")) {
196200 outcome = "skipped: this folder is a reader";
197201 } else if (LOCAL_FOLDER.test((await readOr($, `${await stateOf($, job.root)}/config.json`)) ?? "")) {
198− // A local project's history is in a store on this machine, which only the abso command opens.
199− outcome = "skipped: a local project; abso record sends its edits";
202+ ({ outcome, context: handed } = await handToClient($, job));
200203 } else if (await ignored($, job.root, job.rel)) {
201204 outcome = "skipped: ignored path";
202205 } else if (await isLink($, job.root, job.rel)) {
@@ -217,11 +220,11 @@
217220 job.root,
218221 `${new Date(job.queuedAt).toISOString()}\t${job.tool}\t${job.rel}\t${outcome}\t${done - started}ms sending, ${started - job.queuedAt}ms queued (in process, async)\t${CLIENT}`,
219222 );
220− const context = newsContext(news);
223+ const context = handed ?? newsContext(news);
221224 if (context === undefined) return;
222225 // For anything that shows news later (the avcs-view mod reads it).
223226 const at = new Date(done).toISOString();
224− await log($, job.root, news.map((n) => `${at}\t${n}`).join("\n"), "news.log");
227+ if (news.length > 0) await log($, job.root, news.map((n) => `${at}\t${n}`).join("\n"), "news.log");
225228 try {
226229 await $.session.append({
227230 message: { type: "user", content: [{ type: "text", text: context }] },
@@ -234,6 +237,43 @@
234237 }
235238}
236239
240+/**
241+ * A local project's history is in a store on this machine that only the abso command opens, so its edits go to
242+ * `abso hook` from the checkout this mod was installed from, as Claude Code's command hook would run it.
243+ */
244+async function handToClient($: Engine, job: Job): Promise<{ outcome: string; context?: string }> {
245+ if (HOOK_COMMAND === undefined || HOOK_COMMAND.length === 0)
246+ return {
247+ outcome:
248+ "skipped: a local project, and this mod has no abso to hand it to (install-mod.ts adds one); abso record sends it",
249+ };
250+ const hookInput = {
251+ session_id: await $.session.id(),
252+ cwd: slash(await $.session.cwd()),
253+ tool_name: job.tool,
254+ tool_input: job.input,
255+ ...(job.agentId ? { agent_id: job.agentId } : {}),
256+ };
257+ const ran = await $.process.run(HOOK_COMMAND, {
258+ cwd: job.root,
259+ env: { ABSO_HOOK_FORCE: "1" },
260+ stdin: JSON.stringify(hookInput),
261+ timeoutMs: LOCAL_HOOK_MS,
262+ });
263+ if (ran.exitCode !== 0) throw new Error(`abso hook exited ${ran.exitCode}: ${ran.stderr.trim().split("\n").at(-1)}`);
264+ // It prints Claude Code's JSON when it has news for the agent, and nothing otherwise.
265+ const out = ran.stdout.trim();
266+ const context =
267+ out === ""
268+ ? undefined
269+ : (JSON.parse(out) as { hookSpecificOutput?: { additionalContext?: unknown } }).hookSpecificOutput
270+ ?.additionalContext;
271+ return {
272+ outcome: "handed to abso hook (a local project; its own line is just above)",
273+ ...(typeof context === "string" ? { context } : {}),
274+ };
275+}
237277/** Ask for the news waiting for this agent (announcements, collisions) and hand it to the model. */
238278async function pollNews($: Engine, root: string): Promise<void> {
239279 try {
--- a/client/hooks/stamp.ts
+++ b/client/hooks/stamp.ts
@@ -3,3 +3,9 @@
33// this file with the version it installs: plugin.json's, plus the commit
44// (0.1.0+702c616). Loaded straight from a checkout, it stays undefined.
55export const STAMP: string | undefined = undefined;
6+
7+// The command that runs `abso hook` from the checkout the mod was installed
8+// from, as [node, client/abso.ts, "hook"]; the installer writes it too. A
9+// local project's history is in a store on this machine that only the abso
10+// command opens, so the mod hands those edits to it.
11+export const HOOK_COMMAND: readonly string[] | undefined = undefined;
--- a/client/src/install.ts
+++ b/client/src/install.ts
@@ -94,6 +94,8 @@
9494 /** For tests: the rename that moves each file into place. */
9595 readonly rename?: (from: string, to: string) => void;
9696 readonly now?: Date;
97+ /** For tests: the command stamped as HOOK_COMMAND, instead of this client's own `abso hook`. */
98+ readonly hookCommand?: readonly string[];
9799}
98100
99101const RECORD = ".avcs-install.json";
@@ -132,6 +134,15 @@
132134 existsSync(at(skillsFolder(AVCS_MOD.name, env), MANIFEST)) ||
133135 existsSync(at(skillsFolder(OLD_MOD_NAMES[AVCS_MOD.name]!, env), MANIFEST));
134136
137+/** Whether the installed abso mod hands a local project's edits to abso hook: it was installed with a HOOK_COMMAND. */
138+export function modHandsLocal(env: Readonly<Record<string, string | undefined>> = process.env): boolean {
139+ try {
140+ return /HOOK_COMMAND[^=\n]*=\s*\[/.test(readFileSync(at(skillsFolder(AVCS_MOD.name, env), STAMP_FILE), "utf8"));
141+ } catch {
142+ return false;
143+ }
144+}
135146/**
136147 * After the new mod is in, the folder it replaces (skills/avcs, skills/avcs-view) would load beside it, so it
137148 * is moved, not deleted, to ~/.abso/retired-mods/<name>-<stamp>. Returns where it went, or undefined when there was none.
@@ -226,8 +237,11 @@
226237 return commit;
227238}
228239
229−/** The files to install, stamped with `version`, in install order. */
230−function filesFor(spec: ModSpec, version: string): Map<string, Buffer> {
240+/** The command that runs this checkout's `abso hook`: what the mod hands a local project's edits to. */
241+export const hookCommand = (): readonly string[] => [process.execPath, join(CLIENT_DIR, "abso.ts"), "hook"];
243+/** The files to install, stamped with `version` (and HOOK_COMMAND, where a stamp.ts has it), in install order. */
244+function filesFor(spec: ModSpec, version: string, hook: readonly string[] = hookCommand()): Map<string, Buffer> {
231245 if (!/^[\w.+-]+$/.test(version)) throw new Error(`can't stamp the version ${JSON.stringify(version)}`);
232246 const out = new Map<string, Buffer>();
233247 for (const rel of spec.files) {
@@ -239,7 +253,9 @@
239253 const text = data.toString("utf8");
240254 const stamped = text.replace(/(STAMP[^=\n]*=\s*)undefined/, `$1'${version}'`);
241255 if (stamped === text) throw new Error(`${rel} has no "STAMP ... = undefined" line to stamp`);
242− data = Buffer.from(stamped);
256+ data = Buffer.from(
257+ stamped.replace(/(HOOK_COMMAND[^=\n]*=\s*)undefined/, (_, head: string) => head + JSON.stringify(hook)),
258+ );
243259 }
244260 out.set(rel, data);
245261 }
@@ -386,7 +402,7 @@
386402export function installMod(spec: ModSpec, options: InstallOptions): Installed {
387403 const target = resolve(options.target);
388404 const version = versionFor(spec, options.commit);
389− const next = filesFor(spec, version);
405+ const next = filesFor(spec, version, options.hookCommand);
390406 const existed = existsSync(target);
391407 mkdirSync(target, { recursive: true });
392408 try {
--- a/client/src/join-commands.ts
+++ b/client/src/join-commands.ts
@@ -32,7 +32,7 @@
3232import { elsewhereText } from "./doctor.ts";
3333import { fromEnv } from "./env-names.ts";
3434import { clearKnown, loadIgnore, readFolder, writeKnown } from "./folder.ts";
35−import { installerCommand, modInstalled } from "./install.ts";
35+import { installerCommand, modHandsLocal, modInstalled } from "./install.ts";
3636import { LOCAL, NO_STORE, storeDir } from "./local-store.ts";
3737import { type FullMode, foldModes, writeKnownModes } from "./modes.ts";
3838import { initInOrg, siteOf } from "./orgs.ts";
@@ -538,8 +538,14 @@
538538}
539539
540540function hookHint(env: Readonly<Record<string, string | undefined>>, local = false): string {
541− // The mod sends each edit to the folder's server itself, and a local project has none.
542− if (local) return "abso record sends the edits made here: the abso mod doesn't record local projects yet.";
541+ // A local project has no server: the mod hands its edits to abso hook, when it was installed with one to hand them to.
542+ if (local) {
543+ if (modHandsLocal(env))
544+ return "Edits made by Claude Code here are recorded by the abso mod on this machine, through abso hook. Anything else: abso record.";
545+ if (modInstalled(env) && !builtCopy())
546+ return `abso record sends the edits made here: the abso mod on this machine is older than local projects. ${installerCommand("install-mod.ts")} updates it, and new chats load it.`;
547+ return "abso record sends the edits made here, whoever made them.";
548+ }
543549 if (modInstalled(env))
544550 return "Edits made by Claude Code here are recorded by the abso mod on this machine, signed in as this folder. Anything else: abso record.";
545551 // A built copy (the npm package) has no installer to point at (abso-core 18).
--- a/client/test/install.test.ts
+++ b/client/test/install.test.ts
@@ -26,6 +26,7 @@
2626import { clientVersion, headCommit } from "../src/client-version.ts";
2727import {
2828 AVCS_MOD,
29+ hookCommand,
2930 installerCommand,
3031 installMod,
3132 keptModCommit,
@@ -114,6 +115,28 @@
114115 );
115116 });
116117
118+ it("stamps the command that runs this client's abso hook, where stamp.ts has a HOOK_COMMAND line", () => {
119+ const spec = source({
120+ "hooks/stamp.ts":
121+ "export const STAMP: string | undefined = undefined\nexport const HOOK_COMMAND: readonly string[] | undefined = undefined\n",
122+ });
123+ const target = join(temp(), "avcs");
124+ installMod(spec, {
125+ target,
126+ check: pass,
127+ commit: "702c616",
128+ hookCommand: ["C:\\node.exe", "C:\\abso\\client\\abso.ts", "hook"],
129+ });
130+ assert.equal(
131+ read(target, "hooks/stamp.ts"),
132+ "export const STAMP: string | undefined = '0.1.0+702c616'\n" +
133+ 'export const HOOK_COMMAND: readonly string[] | undefined = ["C:\\\\node.exe","C:\\\\abso\\\\client\\\\abso.ts","hook"]\n',
134+ );
135+ // By default, this checkout's own: the node running it and client/abso.ts.
136+ assert.deepEqual(hookCommand().slice(0, 1), [process.execPath]);
137+ assert.match(hookCommand()[1]!, /client[\\/]abso\.ts$/);
138+ });
117140 it("moves the files in by rename, what the hook imports first and plugin.json last", () => {
118141 const spec = source();
119142 const target = join(temp(), "avcs");