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 2 to 318

Compare

+78 −15 in 6 places
Lines 3–12 at 318 (were 3–11 at 2)
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[] = [];
Lines 18–28 at 318 (were 17–27 at 2)
1718 const norm = (p: string) => p.replace(/\\/g, "/").replace(/^[A-Za-z]:/, "");
1819 on("session.start", (_$, e) => ({ cwd: (e as { cwd?: string }).cwd ?? "/w/p" }));
1920 on("session.cwd", () => ({ value: "/w/p" }));
20− on("fs.exists", (_$, e) => ({ value: inFolder && norm(e.path) === "/w/p/.avcs/config.json" }));
21+ on("fs.exists", (_$, e) => ({ value: inFolder && norm(e.path) === "/w/p/.abso/config.json" }));
2122 on("fs.read", (_$, e) => {
2223 const path = norm(e.path);
23− if (inFolder && path === "/w/p/.avcs/config.json")
24− return { value: JSON.stringify({ server: "https://avcs.test", project: "p", agent: "bob" }) };
24+ if (inFolder && path === "/w/p/.abso/config.json")
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 });
Lines 33–57 at 318 (were 32–53 at 2)
3233 on("http.fetch", (_$, e) => {
3334 asked.push(e.url);
3435 auth.push((e.init?.headers as Record<string, string> | undefined)?.authorization ?? "none");
35− clients.push(String((e.init?.headers as Record<string, string> | undefined)?.["x-avcs-client"]));
36+ clients.push(String((e.init?.headers as Record<string, string> | undefined)?.["x-abso-client"]));
3637 return { value: { status: 200, ok: true, headers: {}, text: JSON.stringify({ news: news.shift() ?? [] }) } };
3738 });
38− on("session.append", (_$, e) => {
39+ // The engine stores the row itself: a session.append hook passes it on and answers what next answered.
40+ on("session.append", (_$, e, next) => {
3941 appended.push((e.message.content as { text: string }[])[0]!.text);
40− return { value: { message: e.message, uuid: `u${appended.length}` } } as never;
42+ return next(e);
4143 });
44+ // Tools the chat calls run as asked.
45+ on("tool.call", () => ({ result: { isError: false, text: "ok" } }) as never);
4246 return { clock, asked, auth, clients, appended, written };
4347}
4448
45−test("the news poll asks every 30 seconds in an abso folder, and keeps each item once", async ($, on) => {
49+test("the news poll asks every 5 minutes in an abso folder, and keeps each item once", async ($, on) => {
4650 // The kit has no conversation to append to, so the append itself is checked in a live session (#25);
4751 // here: the poll's timing, the call, and the news log the view mod reads.
48− const w = world(on, true, [["Announcement from lead: stop publishing until v12 lands"], []]);
52+ const w = world(on, true, [["Announcement from lead: stop pushing until v12 lands"], []]);
4953 await $.session.start({ cwd: "/w/p" });
50− await w.clock.advance(29_000);
54+ await w.clock.advance(299_000);
5155 expect(w.asked).toEqual([]);
5256 await w.clock.advance(1_000);
5357 expect(w.asked).toEqual(["https://avcs.test/p/p/a/bob/news"]);
Lines 59–95 at 318 (were 55–66 at 2)
5559 expect(w.auth[0]).toBe("none");
5660 // Which mod asked: avcs-mod/<version> once installed, avcs-mod/checkout from a checkout (#29).
5761 expect(w.clients[0]).toMatch(/^avcs-mod\/(checkout|\d+\.\d+\.\d+(\+[\w.]+)?)$/);
58− await w.clock.advance(30_000);
62+ await $.tool.call({ tool: "Bash", command: "ls" } as never);
63+ await w.clock.advance(300_000);
5964 expect(w.asked).toHaveLength(2);
60− const log = w.written.get("/w/p/.avcs/news.log") ?? "";
65+ const log = w.written.get("/w/p/.abso/news.log") ?? "";
6166 expect(log.split("\n").filter((l) => l.includes("Announcement from lead"))).toHaveLength(1);
6267});
6368
69+test("while the seat holds its news stream (abso 690), the poll stands down, and asks again once the mark runs out", async ($, on) => {
70+ const w = world(on, true, [[], []]);
71+ w.written.set("/w/p/.abso/news-stream.json", JSON.stringify({ until: 1_000_000 + 400_000 }));
72+ await $.session.start({ cwd: "/w/p" });
73+ await w.clock.advance(300_000);
74+ expect(w.asked).toEqual([]);
75+ await $.tool.call({ tool: "Bash", command: "ls" } as never);
76+ await w.clock.advance(300_000);
77+ expect(w.asked).toEqual(["https://avcs.test/p/p/a/bob/news"]);
78+});
80+test("a chat with no tool call for 10 minutes stops asking for news; its next tool call starts it again", async ($, on) => {
81+ const w = world(on, true, [[], [], []]);
82+ await $.session.start({ cwd: "/w/p" });
83+ await w.clock.advance(300_000);
84+ expect(w.asked).toHaveLength(1);
85+ // Idle since the start: at 10 and 15 minutes it doesn't ask.
86+ await w.clock.advance(600_000);
87+ expect(w.asked).toHaveLength(1);
88+ await $.tool.call({ tool: "Read", file_path: "/w/p/a.ts" } as never);
89+ await w.clock.advance(300_000);
90+ expect(w.asked).toHaveLength(2);
91+});
6493test("outside an abso folder it never asks", async ($, on) => {
6594 const w = world(on, false, [["should not arrive"]]);
6695 await $.session.start({ cwd: "/w/p" });
Lines 100–108 at 318 (were 71–80 at 2)
71100
72101test("an edit that leaves a NUL byte in a text file is not sent, and the log says where", async ($, on) => {
73102 const w = world(on, true, []);
74− w.written.set("/w/p/.avcs/known/fuzz.ts", "one\ntwo\nthree\n");
103+ w.written.set("/w/p/.abso/known/fuzz.ts", "one\ntwo\nthree\n");
75104 w.written.set("/w/p/fuzz.ts", "one\ntwo\nth\u0000ree\n");
76105 on("fs.stat", () => ({ value: { realPath: "/w/p/fuzz.ts" } }) as never);
77− on("tool.call", () => ({ result: { isError: false, text: "ok" } }) as never);
78106 on("session.id", () => ({ value: "sess" }));
79107 await $.session.start({ cwd: "/w/p" });
80108 await $.tool.call({
Lines 112–152 at 318 (were 84–89 at 2)
84112 content: "one\ntwo\nth\u0000ree\n",
85113 } as never);
86114 await w.clock.advance(1_000);
87− expect(w.written.get("/w/p/.avcs/hook.log") ?? "").toContain("not sent: a NUL byte at line 3");
115+ expect(w.written.get("/w/p/.abso/hook.log") ?? "").toContain("not sent: a NUL byte at line 3");
88116 expect(w.asked.filter((u) => !u.endsWith("/news"))).toEqual([]);
89117});
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+});
MCP
compare on this site's /mcp
CLI
abso diff 2 318 client/hooks/register.test.ts --json
JSON
/christopher/abso-core/compare/2..318?file=client%2Fhooks%2Fregister.test.ts&format=json