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

Compare

+94 −5 in 9 places
Lines 3–12 at 318 (were 3–11 at 286)
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 22–28 at 318 (were 21–27 at 286)
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 });
Lines 115–152 at 318 (were 114–116 at 286)
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+});
Lines 33–39 at 318 (were 33–39 at 286)
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). */
Lines 182–205 at 318 (were 182–196 at 286)
182182 for (let job = jobs.shift(); job !== undefined; job = jobs.shift()) await run($, job);
183183}
184184
185+/** A local project's folder (abso init --local): its config names no server. */
186+const 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;
185190async function run($: Engine, job: Job): Promise<void> {
186191 const started = await $.clock.now().catch(() => job.queuedAt);
187192 let outcome: string;
188193 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;
189196 try {
190197 if ((await readOr($, `${await stateOf($, job.root)}/paused`)) !== undefined) {
191198 outcome = "skipped: recording is paused (abso resume)";
192199 } else if (/"reader"\s*:\s*true/.test((await readOr($, `${await stateOf($, job.root)}/config.json`)) ?? "")) {
193200 outcome = "skipped: this folder is a reader";
201+ } else if (LOCAL_FOLDER.test((await readOr($, `${await stateOf($, job.root)}/config.json`)) ?? "")) {
202+ ({ outcome, context: handed } = await handToClient($, job));
194203 } else if (await ignored($, job.root, job.rel)) {
195204 outcome = "skipped: ignored path";
196205 } else if (await isLink($, job.root, job.rel)) {
Lines 220–230 at 318 (were 211–221 at 286)
211220 job.root,
212221 `${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}`,
213222 );
214− const context = newsContext(news);
223+ const context = handed ?? newsContext(news);
215224 if (context === undefined) return;
216225 // For anything that shows news later (the avcs-view mod reads it).
217226 const at = new Date(done).toISOString();
218− 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");
219228 try {
220229 await $.session.append({
221230 message: { type: "user", content: [{ type: "text", text: context }] },
Lines 237–279 at 318 (were 228–233 at 286)
228237 }
229238}
230239
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+}
231277/** Ask for the news waiting for this agent (announcements, collisions) and hand it to the model. */
232278async function pollNews($: Engine, root: string): Promise<void> {
233279 try {
Lines 288–294 at 318 (were 242–247 at 286)
242288 project: string;
243289 agent: string;
244290 };
291+ if (config.server === "local") return;
245292 const bearer = await token($, config.server);
246293 const r = await $.http.fetch(
247294 `${config.server.replace(/\/+$/, "")}/p/${encodeURIComponent(config.project)}/a/${encodeURIComponent(config.agent)}/news`,
Lines 3–11 at 318 (were 3–5 at 286)
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;
MCP
compare on this site's /mcp
CLI
abso diff 286 318 client/hooks --json
JSON
/christopher/abso-core/compare/286..318?file=client%2Fhooks&format=json