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

+102 −25 in 17 places
Lines 10–16 at 318 (were 10–16 at 2)
1010//
1111// Outside an abso folder it costs one cached lookup. It never throws into a
1212// chat: on any error it logs to .avcs/hook.log and forgets the file's known
13−// copy, so the next `abso record` (publish and sync run one) sends it whole.
13+// copy, so the next `abso record` (push and pull run one) sends it whole.
1414
1515import type { Register } from "claude-code";
1616import {
Lines 33–39 at 318 (were 33–39 at 2)
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 89–103 at 318 (were 89–96 at 2)
8989let draining = false;
9090const TICK_MS = 150;
9191const roots = new Map<string, { root: string | undefined; at: number }>();
92−/** How often to ask for news without an edit (announcements reach an agent that isn't editing). */
93−const NEWS_POLL_MS = 30_000;
92+/**
93+ * How often to ask for news without an edit (announcements reach an agent that isn't editing). Every 5 minutes, and
94+ * not at all in a chat that has made no tool call for IDLE_MS: prod abso's object reset under the load of every chat
95+ * asking every 30 seconds (2026-10-15). abso news --stream (abso 690) wakes a chat without asking.
96+ */
97+const NEWS_POLL_MS = 5 * 60_000;
98+const IDLE_MS = 10 * 60_000;
99+/** When this chat last made a tool call (or started). */
100+let activeAt = 0;
94101/** The abso folder this chat works in: the session's folder, or the first edited file's. */
95102let newsRoot: string | undefined;
96103let polling = false;
Lines 115–124 at 318 (were 108–115 at 2)
108115 });
109116 // Outside an abso folder each tick only reads a variable.
110117 newsRoot = await findRoot($, `${slash(await $.session.cwd())}/.`).catch(() => undefined);
111− $.clock.every(NEWS_POLL_MS, () => {
118+ activeAt = await $.clock.now();
119+ $.clock.every(NEWS_POLL_MS, async () => {
112120 if (polling || newsRoot === undefined) return;
121+ if ((await $.clock.now()) - activeAt >= IDLE_MS) return;
113122 polling = true;
114123 void pollNews($, newsRoot).finally(() => {
115124 polling = false;
Lines 127–137 at 318 (were 118–123 at 2)
118127 return next(e);
119128 });
120129
130+ on("tool.call", async ($, e, next) => {
131+ activeAt = await $.clock.now();
132+ return next(e);
133+ });
121135 on("tool.call", { tool: TOOLS }, async ($, e, next) => {
122136 const ran = await next(e);
123137 try {
Lines 158–164 at 318 (were 144–150 at 2)
144158 ),
145159 ),
146160 snapshot: text === undefined || looksBinary(text) ? undefined : normalize(text),
147− ...(text !== undefined && text.includes("\u0000")
161+ ...(text?.includes("\u0000")
148162 ? { nul: { at: text.indexOf("\u0000"), line: text.slice(0, text.indexOf("\u0000")).split("\n").length } }
149163 : {}),
150164 agentId: typeof input.agentId === "string" ? input.agentId : undefined,
Lines 182–205 at 318 (were 168–182 at 2)
168182 for (let job = jobs.shift(); job !== undefined; job = jobs.shift()) await run($, job);
169183}
170184
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;
171190async function run($: Engine, job: Job): Promise<void> {
172191 const started = await $.clock.now().catch(() => job.queuedAt);
173192 let outcome: string;
174193 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;
175196 try {
176− if ((await readOr($, `${job.root}/.avcs/paused`)) !== undefined) {
197+ if ((await readOr($, `${await stateOf($, job.root)}/paused`)) !== undefined) {
177198 outcome = "skipped: recording is paused (abso resume)";
178− } else if (/"reader"\s*:\s*true/.test((await readOr($, `${job.root}/.avcs/config.json`)) ?? "")) {
199+ } else if (/"reader"\s*:\s*true/.test((await readOr($, `${await stateOf($, job.root)}/config.json`)) ?? "")) {
179200 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));
180203 } else if (await ignored($, job.root, job.rel)) {
181204 outcome = "skipped: ignored path";
182205 } else if (await isLink($, job.root, job.rel)) {
Lines 212–218 at 318 (were 189–195 at 2)
189212 }
190213 } catch (err) {
191214 outcome = `error: ${(err as Error).message}`;
192− await $.fs.write(`${job.root}/.avcs/known/${job.rel}`, FORGOTTEN).catch(() => {});
215+ await $.fs.write(`${await stateOf($, job.root)}/known/${job.rel}`, FORGOTTEN).catch(() => {});
193216 }
194217 const done = await $.clock.now().catch(() => started);
195218 await log(
Lines 220–230 at 318 (were 197–207 at 2)
197220 job.root,
198221 `${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}`,
199222 );
200− const context = newsContext(news);
223+ const context = handed ?? newsContext(news);
201224 if (context === undefined) return;
202225 // For anything that shows news later (the avcs-view mod reads it).
203226 const at = new Date(done).toISOString();
204− 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");
205228 try {
206229 await $.session.append({
207230 message: { type: "user", content: [{ type: "text", text: context }] },
Lines 237–294 at 318 (were 214–227 at 2)
214237 }
215238}
216239
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+}
217277/** Ask for the news waiting for this agent (announcements, collisions) and hand it to the model. */
218278async function pollNews($: Engine, root: string): Promise<void> {
219279 try {
220− const config = JSON.parse(await $.fs.read(`${root}/.avcs/config.json`)) as {
280+ // While this seat holds its news stream (abso news --stream or --follow, abso 690), the stream wakes the chat.
281+ const mark = await readOr($, `${await stateOf($, root)}/news-stream.json`);
282+ if (mark !== undefined) {
283+ const until = Number((JSON.parse(mark) as { until?: unknown }).until);
284+ if (Number.isFinite(until) && until > (await $.clock.now())) return;
285+ }
286+ const config = JSON.parse(await $.fs.read(`${await stateOf($, root)}/config.json`)) as {
221287 server: string;
222288 project: string;
223289 agent: string;
224290 };
291+ if (config.server === "local") return;
225292 const bearer = await token($, config.server);
226293 const r = await $.http.fetch(
227294 `${config.server.replace(/\/+$/, "")}/p/${encodeURIComponent(config.project)}/a/${encodeURIComponent(config.agent)}/news`,
Lines 296–302 at 318 (were 229–235 at 2)
229296 method: "POST",
230297 headers: {
231298 "content-type": "application/json",
232− "x-avcs-client": CLIENT,
299+ "x-abso-client": CLIENT,
233300 ...(bearer ? { authorization: `Bearer ${bearer}` } : {}),
234301 },
235302 body: "{}",
Lines 330–348 at 318 (were 263–271 at 2)
263330 }
264331}
265332
333+/** A folder's state folder: .abso, or .avcs in a folder from before the rename. (A mod can't import the client's state-dir.ts.) */
334+async function stateOf($: Engine, root: string): Promise<string> {
335+ return (await $.fs.exists(`${root}/.abso/config.json`)) ? `${root}/.abso` : `${root}/.avcs`;
336+}
338+/** A file under the user's home: ~/.abso/<name>, else the older ~/.avcs/<name>. */
339+async function readHome($: Engine, home: string, name: string): Promise<string | undefined> {
340+ return (await readOr($, `${slash(home)}/.abso/${name}`)) ?? (await readOr($, `${slash(home)}/.avcs/${name}`));
341+}
266343/** Whether the server has this path as a symbolic link (.avcs/modes.json, written by the client). */
267344async function isLink($: Engine, root: string, rel: string): Promise<boolean> {
268− const raw = await readOr($, `${root}/.avcs/modes.json`);
345+ const raw = await readOr($, `${await stateOf($, root)}/modes.json`);
269346 if (raw === undefined) return false;
270347 try {
271348 const modes = JSON.parse(raw) as Record<string, { link?: unknown }>;
Lines 370–376 at 318 (were 293–299 at 2)
293370 return makeIgnore((f) => files.get(f), setup.git)(rel, false);
294371}
295372
296−/** The nearest folder above the file that has .avcs/config.json, cached per folder. */
373+/** The nearest folder above the file that has .abso/config.json (or .avcs/config.json from before the rename), cached per folder. */
297374async function findRoot($: Engine, path: string): Promise<string | undefined> {
298375 const start = path.slice(0, path.lastIndexOf("/"));
299376 const now = await $.clock.now();
Lines 379–385 at 318 (were 302–308 at 2)
302379 let found: string | undefined;
303380 let dir = start;
304381 while (dir.includes("/")) {
305− if (await $.fs.exists(`${dir}/.avcs/config.json`)) {
382+ if ((await $.fs.exists(`${dir}/.abso/config.json`)) || (await $.fs.exists(`${dir}/.avcs/config.json`))) {
306383 found = dir;
307384 break;
308385 }
Lines 391–425 at 318 (were 314–348 at 2)
314391 return found;
315392}
316393
317−/** AVCS_TOKEN if set, else ~/.avcs/token; none for a server the token may not go to (core.ts tokenGoesTo, with this machine's servers.json). */
394+/** AVCS_TOKEN if set, else ~/.abso/token, else ~/.avcs/token; none for a server the token may not go to (core.ts tokenGoesTo, with this machine's servers.json). */
318395async function token($: Engine, server: string): Promise<string | undefined> {
319396 const home = (await $.env.get("USERPROFILE")) ?? (await $.env.get("HOME"));
320− const machine = machineServers(home ? await readOr($, `${slash(home)}/.avcs/servers.json`) : undefined);
397+ const machine = machineServers(home ? await readHome($, home, "servers.json") : undefined);
321398 if (!tokenGoesTo(server, trustedList(await $.env.get("AVCS_TRUSTED_SERVERS"), machine))) return undefined;
322399 const env = await $.env.get("AVCS_TOKEN");
323400 if (env) return env.trim();
324− return home ? (await readOr($, `${slash(home)}/.avcs/token`))?.trim() || undefined : undefined;
401+ return home ? (await readHome($, home, "token"))?.trim() || undefined : undefined;
325402}
326403
327404async function send($: Engine, job: Job, who: Who): Promise<{ outcome: string; news: readonly string[] }> {
328405 const { root, rel } = job;
329406 // While an abso command changes the folder's records, leave the known copy alone: the next record sends the file (#51).
330− if (lockHeld(await readOr($, `${root}/.avcs/${LOCK_FILE}`), Date.now()))
407+ if (lockHeld(await readOr($, `${await stateOf($, root)}/${LOCK_FILE}`), Date.now()))
331408 return { outcome: "skipped: another abso command is changing this folder; abso record sends it", news: [] };
332409 const disk = job.snapshot;
333− const knownPath = `${root}/.avcs/known/${rel}`;
410+ const knownPath = `${await stateOf($, root)}/known/${rel}`;
334411 const knownRaw = await readOr($, knownPath);
335412 if (disk === undefined) {
336413 if (job.nul !== undefined && knownRaw !== undefined && !looksBinary(knownRaw)) {
337414 // A text file an edit left with a NUL byte: tell the agent now, not forty minutes later (#25).
338− const warning = `${rel} now has a NUL byte at line ${job.nul.line} (character ${job.nul.at}), so it reads as binary. abso will not send or publish it, and the other agents keep its last text, until the NUL is gone.`;
415+ const warning = `${rel} now has a NUL byte at line ${job.nul.line} (character ${job.nul.at}), so it reads as binary. abso will not send or push it, and the other agents keep its last text, until the NUL is gone.`;
339416 return { outcome: `not sent: a NUL byte at line ${job.nul.line}`, news: [warning] };
340417 }
341418 return { outcome: "skipped: file is missing or not text; abso record catches up", news: [] };
342419 }
343420 const known = knownRaw === undefined || looksBinary(knownRaw) ? undefined : knownRaw;
344421
345− const config = JSON.parse(await $.fs.read(`${root}/.avcs/config.json`)) as {
422+ const config = JSON.parse(await $.fs.read(`${await stateOf($, root)}/config.json`)) as {
346423 server: string;
347424 project: string;
348425 agent: string;
Lines 431–437 at 318 (were 354–360 at 2)
354431 method: "POST",
355432 headers: {
356433 "content-type": "application/json",
357− "x-avcs-client": CLIENT,
434+ "x-abso-client": CLIENT,
358435 ...(bearer ? { authorization: `Bearer ${bearer}` } : {}),
359436 },
360437 body: JSON.stringify(payload),
Lines 463–469 at 318 (were 386–392 at 2)
386463/** One line per edit in .avcs/hook.log (or another log there), as the command hook writes, kept under LOG_LIMIT. */
387464async function log($: Engine, root: string, line: string, file = "hook.log"): Promise<void> {
388465 try {
389− const path = `${root}/.avcs/${file}`;
466+ const path = `${await stateOf($, root)}/${file}`;
390467 let text = `${(await readOr($, path)) ?? ""}${line}\n`;
391468 if (text.length > LOG_LIMIT) text = text.slice(text.indexOf("\n", text.length - LOG_LIMIT / 2) + 1);
392469 await $.fs.write(path, text);
MCP
compare on this site's /mcp
CLI
abso diff 2 318 client/hooks/register.ts --json
JSON
/christopher/abso-core/compare/2..318?file=client%2Fhooks%2Fregister.ts&format=json