- MCP
- blame on this site's /mcp
- CLI
- abso blame client/hooks/register.ts --json
- JSON
- /christopher/abso-core/blame/client/hooks/register.ts?format=json
473 linesFirst import 78% · pinch 11% · review 5% · box-grants 5% · rename 1%Last change pinch in version 293,
473 lines from 14 changes in 9 versions.
2// Write or NotebookEdit in an abso folder, it sends the change into the
3// agent's draft, and hands any news back to the model.
4//
5// The agent never waits for it. The hook takes a snapshot of the file and
6// returns; a queue in this module then sends the edits in the order they were
7// made, each judged against its own snapshot (src/core.ts makes the same
8// decisions as `abso hook`). News reaches the model as a row the engine
9// appends, read at the model's next request.
10//
11// Outside an abso folder it costs one cached lookup. It never throws into a
12// chat: on any error it logs to .avcs/hook.log and forgets the file's known
rename100abso publish is now abso push, abso sync is now abso pull (abso 427)
Commands, help, flags, messages, MCP tool names and descriptions, hook text, README, SKILL.md and tests say push and pull; "shared" stays the noun ("Pushed version N"). No aliases, no notices. A queued push that was "pulled" is now "turned back", so pull means one thing.
push -f/--force/-u/--all/--tags and pull --rebase/--ff-only/--squash refuse with one plain line naming the abso way; push and pull take no remote or branch.
Kept as stored: log entry kinds (publish, sync, pulled), HTTP route paths, the pipeline trigger on: publish, the yours (unpublished) marker, npm-publish.Compare13// copy, so the next `abso record` (push and pull run one) sends it whole.
15import type { Register } from "claude-code";
16import {
17 type EditBody,
18 editBody,
19 type GitIgnoreSetup,
20 gitIgnoreSetup,
21 ignoreFilesFor,
22 LOCK_FILE,
23 lockHeld,
24 looksBinary,
25 machineServers,
26 makeIgnore,
27 newsContext,
28 normalize,
29 readAll,
30 spellingText,
31 tokenGoesTo,
32 trustedList,
33 uncomposedText,
34 type Who,
35} from "../src/core.ts";
pinch293Local 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.Compare36import { HOOK_COMMAND, STAMP } from "./stamp.ts";
38const TOOLS = ["Edit", "MultiEdit", "Write", "NotebookEdit"];
39/** A known copy holding a NUL byte reads as no known copy (the client treats it as binary). */
40const FORGOTTEN = "\u0000";
41const LOG_LIMIT = 256 * 1024;
42/** How long a folder's "is this in an abso folder" answer is kept. */
43const ROOT_CACHE_MS = 30_000;
44/** Sent with each call, so the server can tell which mod, from which commit, made it (#29). */
45const CLIENT = `avcs-mod/${STAMP ?? "checkout"}`;
47type Engine = Parameters<Parameters<Register>[0]>[2] extends never ? never : any;
49interface Answer {
50 readonly ok: boolean;
51 readonly reason?: string;
52 readonly news?: readonly string[];
53 /** Another spelling of an existing file, recorded as it (#49). */
54 readonly spelling?: readonly { path: string; existing: string }[];
55 /** New names not in composed Unicode form (#49). */
56 readonly uncomposed?: readonly string[];
57}
59/** The answer's news, with the spelling warnings (#49) the agent should hear too. */
60function heardFrom(answer: Answer): readonly string[] {
61 return [
62 ...(answer.news ?? []),
63 ...(answer.spelling ?? []).map(spellingText),
64 ...(answer.uncomposed ?? []).map(uncomposedText),
65 ];
66}
68interface Job {
69 readonly root: string;
70 readonly rel: string;
71 readonly tool: string;
72 readonly input: Readonly<Record<string, unknown>>;
73 /** The file right after this edit, in the server's form (undefined: missing or not text). */
74 readonly snapshot: string | undefined;
75 /** Where a NUL byte is, when the edit left one (the file then reads as binary). */
76 readonly nul?: { readonly line: number; readonly at: number };
77 readonly agentId: string | undefined;
78 readonly queuedAt: number;
79}
81const slash = (p: string) => p.replace(/\\/g, "/");
83// Module state: the jobs waiting to be sent, in order, and the folder lookup cache.
84// Sending outlives the edit's own hook, so a timer started in session.start
85// sends the waiting jobs; while there are none, each tick only checks a list.
86const jobs: Job[] = [];
87/** News that couldn't be appended, by agent ('' for the main chat), for the next edit's result. */
88const pendingNews = new Map<string, string[]>();
89let draining = false;
90const TICK_MS = 150;
91const roots = new Map<string, { root: string | undefined; at: number }>();
box-grants272abso-hooks mod: ask for news every 5 minutes, not 30 seconds, and not at all in a chat with no tool call for 10 minutes (its next tool call starts it again). Prod abso's object reset under the load of every chat asking every 30 seconds (Agent VCS, 5:10 PM CT). abso announce says so. Tests: node client/test-mods.ts.Compare92/**
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 */
97const NEWS_POLL_MS = 5 * 60_000;
98const IDLE_MS = 10 * 60_000;
99/** When this chat last made a tool call (or started). */
100let activeAt = 0;
init0Start the project101/** The abso folder this chat works in: the session's folder, or the first edited file's. */
102let newsRoot: string | undefined;
103let polling = false;
104/** Each folder's rules from git's own files, kept as long as the folder lookup. */
105const gitSetups = new Map<string, { git: GitIgnoreSetup; at: number }>();
107export const register: Register = (on) => {
108 on("session.start", async ($, e, next) => {
109 $.clock.every(TICK_MS, () => {
110 if (draining || jobs.length === 0) return;
111 draining = true;
112 void drain($).finally(() => {
113 draining = false;
114 });
115 });
116 // Outside an abso folder each tick only reads a variable.
117 newsRoot = await findRoot($, `${slash(await $.session.cwd())}/.`).catch(() => undefined);
box-grants272abso-hooks mod: ask for news every 5 minutes, not 30 seconds, and not at all in a chat with no tool call for 10 minutes (its next tool call starts it again). Prod abso's object reset under the load of every chat asking every 30 seconds (Agent VCS, 5:10 PM CT). abso announce says so. Tests: node client/test-mods.ts.Compare118 activeAt = await $.clock.now();
119 $.clock.every(NEWS_POLL_MS, async () => {
box-grants272abso-hooks mod: ask for news every 5 minutes, not 30 seconds, and not at all in a chat with no tool call for 10 minutes (its next tool call starts it again). Prod abso's object reset under the load of every chat asking every 30 seconds (Agent VCS, 5:10 PM CT). abso announce says so. Tests: node client/test-mods.ts.Compare121 if ((await $.clock.now()) - activeAt >= IDLE_MS) return;
123 void pollNews($, newsRoot).finally(() => {
124 polling = false;
125 });
126 });
box-grants272abso-hooks mod: ask for news every 5 minutes, not 30 seconds, and not at all in a chat with no tool call for 10 minutes (its next tool call starts it again). Prod abso's object reset under the load of every chat asking every 30 seconds (Agent VCS, 5:10 PM CT). abso announce says so. Tests: node client/test-mods.ts.Compare127 return next(e);
128 });
130 on("tool.call", async ($, e, next) => {
131 activeAt = await $.clock.now();
133 });
135 on("tool.call", { tool: TOOLS }, async ($, e, next) => {
136 const ran = await next(e);
137 try {
138 if (ran.deny !== undefined || ran.isError) return ran;
139 const input = e as unknown as Record<string, unknown>;
140 const raw = input.file_path ?? input.notebook_path;
141 if (typeof raw !== "string" || raw === "") return ran;
142 // The model may pass a path relative to the session's folder; the host resolves it.
143 const path = slash(
144 /^([A-Za-z]:)?[\\/]/.test(raw) ? raw : ((await $.fs.stat(raw, { resolve: true })).realPath ?? raw),
145 );
146 const root = await findRoot($, path);
147 if (root === undefined) return ran;
148 newsRoot ??= root;
149 const rel = path.slice(root.length + 1);
150 const text = await readOr($, path);
151 const job: Job = {
152 root,
153 rel,
154 tool: String(input.tool),
155 input: Object.fromEntries(
156 Object.entries(input).filter(
157 ([k]) => k !== "tool" && k !== "tool_use_id" && k !== "agentId" && k !== "consent",
158 ),
159 ),
160 snapshot: text === undefined || looksBinary(text) ? undefined : normalize(text),
pinch78Biome is silent: about 90 hints cleared. String joins as templates, dotted keys, unused imports, variables and a private method removed, optional chains (one kept boolean with === true), the preset field instead of the deprecated recommended. Two rules off where they don't fit: noExplicitAny in the hook modules, whose engine types come from the host, and noTemplateCurlyInString in tests, which hold source text as data.Compare161 ...(text?.includes("\u0000")
init0Start the project162 ? { nul: { at: text.indexOf("\u0000"), line: text.slice(0, text.indexOf("\u0000")).split("\n").length } }
163 : {}),
164 agentId: typeof input.agentId === "string" ? input.agentId : undefined,
165 queuedAt: await $.clock.now(),
166 };
167 jobs.push(job);
168 const waitingNews = pendingNews.get(job.agentId ?? "");
169 if (waitingNews !== undefined) {
170 pendingNews.delete(job.agentId ?? "");
171 return { ...ran, context: [...(ran.context ?? []), ...waitingNews] };
172 }
173 } catch {
174 // Never into the chat. The next `abso record` catches up.
175 }
176 return ran;
177 });
178};
180/** Send the waiting jobs one at a time, oldest first. */
181async function drain($: Engine): Promise<void> {
182 for (let job = jobs.shift(); job !== undefined; job = jobs.shift()) await run($, job);
183}
pinch287Local projects: abso init --local keeps a project's history on this machine, with no server, sign-in or network
A local folder's calls never leave the process. The client runs the open server's own router and project object (server/src) in-process, over Node's built-in SQLite. It's the same engine with the same answers, so what the commands print matches a server.
- abso init --local [--project <name>] [--agent <name>] [--store <folder>] makes the project, and abso join <project> --local adds a folder. After that, record, push, pull, log, blame and the held collisions work as usual. The folder's config says "server": "local".
- Where the store lives: --store (kept in the folder's config; a store inside the folder is left out of its files through .absoignore), else ABSO_STORE, else this user's data folder: %LOCALAPPDATA%\abso\store, ~/Library/Application Support/abso/store, or $XDG_DATA_HOME/abso/store. Nothing needs a writable home folder when ABSO_STORE or --store is set.
- Each project is <store>/<project>/project.sqlite. Every call runs in one SQLite write transaction, which is the store's lock: other processes wait for it, and a process that dies mid-call keeps nothing half-written. A process reloads the project only when SQLite's data_version shows another process wrote.
- No credential goes with a local folder's calls. The edit mod leaves local folders alone, so abso record sends their edits. Issues, asks and news aren't in local projects yet.
- Needs Node 22.13 or later (node:sqlite); its experimental warning is kept out of the output. Run as .ts, a module hook supplies the Durable Object base class (client/src/durable-object-stand-in.ts); the build aliases cloudflare:workers to the same file. client/src/local-server.mjs, with its .d.mts, keeps the client's typecheck out of server/src, which has its own.
- Each command closes the store files it opened.
Tests: local (8, with fetch replaced by one that throws: init, record, push, join, pull, log, blame, a held collision, --store inside the folder, refusals), plus failed-start, install, caller, doctor, lost-pull, help, body-files: 60 pass; tsc clean. The bundle built with the alias runs init, push and log locally.Compare185/** A local project's folder (abso init --local): its config names no server. */
186const LOCAL_FOLDER = /"server"\s*:\s*"local"/;
pinch293Local 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.Compare187/** How long abso hook may take on a local project's edit: it waits up to two minutes for the store's lock. */
188const LOCAL_HOOK_MS = 150_000;
pinch287Local projects: abso init --local keeps a project's history on this machine, with no server, sign-in or network
A local folder's calls never leave the process. The client runs the open server's own router and project object (server/src) in-process, over Node's built-in SQLite. It's the same engine with the same answers, so what the commands print matches a server.
- abso init --local [--project <name>] [--agent <name>] [--store <folder>] makes the project, and abso join <project> --local adds a folder. After that, record, push, pull, log, blame and the held collisions work as usual. The folder's config says "server": "local".
- Where the store lives: --store (kept in the folder's config; a store inside the folder is left out of its files through .absoignore), else ABSO_STORE, else this user's data folder: %LOCALAPPDATA%\abso\store, ~/Library/Application Support/abso/store, or $XDG_DATA_HOME/abso/store. Nothing needs a writable home folder when ABSO_STORE or --store is set.
- Each project is <store>/<project>/project.sqlite. Every call runs in one SQLite write transaction, which is the store's lock: other processes wait for it, and a process that dies mid-call keeps nothing half-written. A process reloads the project only when SQLite's data_version shows another process wrote.
- No credential goes with a local folder's calls. The edit mod leaves local folders alone, so abso record sends their edits. Issues, asks and news aren't in local projects yet.
- Needs Node 22.13 or later (node:sqlite); its experimental warning is kept out of the output. Run as .ts, a module hook supplies the Durable Object base class (client/src/durable-object-stand-in.ts); the build aliases cloudflare:workers to the same file. client/src/local-server.mjs, with its .d.mts, keeps the client's typecheck out of server/src, which has its own.
- Each command closes the store files it opened.
Tests: local (8, with fetch replaced by one that throws: init, record, push, join, pull, log, blame, a held collision, --store inside the folder, refusals), plus failed-start, install, caller, doctor, lost-pull, help, body-files: 60 pass; tsc clean. The bundle built with the alias runs init, push and log locally.Compare189
191 const started = await $.clock.now().catch(() => job.queuedAt);
192 let outcome: string;
193 let news: readonly string[] = [];
pinch293Local 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.Compare194 /** 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;
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.Compare197 if ((await readOr($, `${await stateOf($, job.root)}/paused`)) !== undefined) {
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.Compare199 } else if (/"reader"\s*:\s*true/.test((await readOr($, `${await stateOf($, job.root)}/config.json`)) ?? "")) {
pinch287Local projects: abso init --local keeps a project's history on this machine, with no server, sign-in or network
A local folder's calls never leave the process. The client runs the open server's own router and project object (server/src) in-process, over Node's built-in SQLite. It's the same engine with the same answers, so what the commands print matches a server.
- abso init --local [--project <name>] [--agent <name>] [--store <folder>] makes the project, and abso join <project> --local adds a folder. After that, record, push, pull, log, blame and the held collisions work as usual. The folder's config says "server": "local".
- Where the store lives: --store (kept in the folder's config; a store inside the folder is left out of its files through .absoignore), else ABSO_STORE, else this user's data folder: %LOCALAPPDATA%\abso\store, ~/Library/Application Support/abso/store, or $XDG_DATA_HOME/abso/store. Nothing needs a writable home folder when ABSO_STORE or --store is set.
- Each project is <store>/<project>/project.sqlite. Every call runs in one SQLite write transaction, which is the store's lock: other processes wait for it, and a process that dies mid-call keeps nothing half-written. A process reloads the project only when SQLite's data_version shows another process wrote.
- No credential goes with a local folder's calls. The edit mod leaves local folders alone, so abso record sends their edits. Issues, asks and news aren't in local projects yet.
- Needs Node 22.13 or later (node:sqlite); its experimental warning is kept out of the output. Run as .ts, a module hook supplies the Durable Object base class (client/src/durable-object-stand-in.ts); the build aliases cloudflare:workers to the same file. client/src/local-server.mjs, with its .d.mts, keeps the client's typecheck out of server/src, which has its own.
- Each command closes the store files it opened.
Tests: local (8, with fetch replaced by one that throws: init, record, push, join, pull, log, blame, a held collision, --store inside the folder, refusals), plus failed-start, install, caller, doctor, lost-pull, help, body-files: 60 pass; tsc clean. The bundle built with the alias runs init, push and log locally.Compare201 } else if (LOCAL_FOLDER.test((await readOr($, `${await stateOf($, job.root)}/config.json`)) ?? "")) {
pinch293Local 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.Compare202 ({ outcome, context: handed } = await handToClient($, job));
204 outcome = "skipped: ignored path";
205 } else if (await isLink($, job.root, job.rel)) {
206 outcome = "skipped: a link (or a file standing in for one); abso record sends links";
207 } else {
208 const who: Who = { session: await $.session.id(), ...(job.agentId ? { subagent: job.agentId } : {}) };
209 const sent = await send($, job, who);
210 outcome = sent.outcome;
211 news = sent.news;
212 }
213 } catch (err) {
214 outcome = `error: ${(err as Error).message}`;
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.Compare215 await $.fs.write(`${await stateOf($, job.root)}/known/${job.rel}`, FORGOTTEN).catch(() => {});
217 const done = await $.clock.now().catch(() => started);
218 await log(
219 $,
220 job.root,
221 `${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}`,
222 );
pinch293Local 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.Compare223 const context = handed ?? newsContext(news);
225 // For anything that shows news later (the avcs-view mod reads it).
226 const at = new Date(done).toISOString();
pinch293Local 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.Compare227 if (news.length > 0) await log($, job.root, news.map((n) => `${at}\t${n}`).join("\n"), "news.log");
229 await $.session.append({
230 message: { type: "user", content: [{ type: "text", text: context }] },
231 ...(job.agentId ? { agentId: job.agentId } : {}),
232 });
233 } catch {
234 // Older Claude Code has no append; the agent's next edit carries it instead.
235 const key = job.agentId ?? "";
236 pendingNews.set(key, [...(pendingNews.get(key) ?? []), context]);
237 }
pinch293Local 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.Compare238}
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 */
244async 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 };
277/** Ask for the news waiting for this agent (announcements, collisions) and hand it to the model. */
278async function pollNews($: Engine, root: string): Promise<void> {
279 try {
box-grants270abso 690: while a seat holds its news stream, the abso-hooks mod's 30-second news poll stands down. abso news --stream marks the folder (.abso/news-stream.json) for the Monitor's 30 minutes plus the ticket's minute; --follow renews the mark on open and at each 45-second ping. The poll asks again once the mark runs out. Tests: client/test/news-stream.test.ts, client/hooks/register.test.ts (node client/test-mods.ts).Compare280 // 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 }
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.Compare286 const config = JSON.parse(await $.fs.read(`${await stateOf($, root)}/config.json`)) as {
288 project: string;
289 agent: string;
290 };
pinch287Local projects: abso init --local keeps a project's history on this machine, with no server, sign-in or network
A local folder's calls never leave the process. The client runs the open server's own router and project object (server/src) in-process, over Node's built-in SQLite. It's the same engine with the same answers, so what the commands print matches a server.
- abso init --local [--project <name>] [--agent <name>] [--store <folder>] makes the project, and abso join <project> --local adds a folder. After that, record, push, pull, log, blame and the held collisions work as usual. The folder's config says "server": "local".
- Where the store lives: --store (kept in the folder's config; a store inside the folder is left out of its files through .absoignore), else ABSO_STORE, else this user's data folder: %LOCALAPPDATA%\abso\store, ~/Library/Application Support/abso/store, or $XDG_DATA_HOME/abso/store. Nothing needs a writable home folder when ABSO_STORE or --store is set.
- Each project is <store>/<project>/project.sqlite. Every call runs in one SQLite write transaction, which is the store's lock: other processes wait for it, and a process that dies mid-call keeps nothing half-written. A process reloads the project only when SQLite's data_version shows another process wrote.
- No credential goes with a local folder's calls. The edit mod leaves local folders alone, so abso record sends their edits. Issues, asks and news aren't in local projects yet.
- Needs Node 22.13 or later (node:sqlite); its experimental warning is kept out of the output. Run as .ts, a module hook supplies the Durable Object base class (client/src/durable-object-stand-in.ts); the build aliases cloudflare:workers to the same file. client/src/local-server.mjs, with its .d.mts, keeps the client's typecheck out of server/src, which has its own.
- Each command closes the store files it opened.
Tests: local (8, with fetch replaced by one that throws: init, record, push, join, pull, log, blame, a held collision, --store inside the folder, refusals), plus failed-start, install, caller, doctor, lost-pull, help, body-files: 60 pass; tsc clean. The bundle built with the alias runs init, push and log locally.Compare291 if (config.server === "local") return;
293 const r = await $.http.fetch(
294 `${config.server.replace(/\/+$/, "")}/p/${encodeURIComponent(config.project)}/a/${encodeURIComponent(config.agent)}/news`,
295 {
296 method: "POST",
297 headers: {
298 "content-type": "application/json",
pinch54The client and the edit mods send and read X-Abso-* headers only (Client, Name, Run-Key, Kind, Admin; Run, Box, Prep from answers). Servers have read X-Abso-* beside the old names for a while and answer under both, so this works with any current server.Compare299 "x-abso-client": CLIENT,
301 },
302 body: "{}",
303 },
304 );
305 if (!r.ok) return;
306 const news = ((JSON.parse(r.text) as { news?: readonly string[] }).news ?? []).filter(
307 (n) => typeof n === "string" && n.trim() !== "",
308 );
309 const context = newsContext(news);
310 if (context === undefined) return;
311 const at = new Date(await $.clock.now()).toISOString();
312 await log($, root, news.map((n) => `${at}\t${n}`).join("\n"), "news.log");
313 try {
314 await $.session.append({ message: { type: "user", content: [{ type: "text", text: context }] } });
315 } catch (err) {
316 // It rides on the next edit's result instead; say why in the log.
317 await log($, root, `${at}\tnews\t-\tcould not append (${(err as Error).message}); the next edit carries it`);
318 pendingNews.set("", [...(pendingNews.get("") ?? []), context]);
319 }
320 } catch {
321 // The next poll, edit or abso command picks it up; nothing is lost on the server.
322 }
323}
325async function readOr($: Engine, path: string): Promise<string | undefined> {
326 try {
327 return await $.fs.read(path);
328 } catch {
329 return undefined;
330 }
331}
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.Compare333/** 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.) */
334async 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>. */
339async 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}
init0Start the project343/** Whether the server has this path as a symbolic link (.avcs/modes.json, written by the client). */
344async function isLink($: Engine, root: string, rel: string): Promise<boolean> {
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.Compare345 const raw = await readOr($, `${await stateOf($, root)}/modes.json`);
347 try {
348 const modes = JSON.parse(raw) as Record<string, { link?: unknown }>;
349 return typeof modes[rel]?.link === "string";
350 } catch {
351 return false;
352 }
353}
355/** The client's ignore rules (src/core.ts), reading only the ignore files above the path. */
356async function ignored($: Engine, root: string, rel: string): Promise<boolean> {
357 const now = await $.clock.now();
358 let setup = gitSetups.get(root);
359 if (!setup || now - setup.at >= ROOT_CACHE_MS) {
360 const home = (await $.env.get("HOME")) ?? (await $.env.get("USERPROFILE"));
361 const xdgConfigHome = await $.env.get("XDG_CONFIG_HOME");
362 const git = await readAll(gitIgnoreSetup(root, { home, ...(xdgConfigHome ? { xdgConfigHome } : {}) }), (p) =>
363 readOr($, p),
364 );
365 setup = { git, at: now };
366 gitSetups.set(root, setup);
367 }
368 const files = new Map<string, string | undefined>();
369 for (const f of ignoreFilesFor(rel)) files.set(f, await readOr($, `${root}/${f}`));
370 return makeIgnore((f) => files.get(f), setup.git)(rel, false);
371}
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.Compare373/** The nearest folder above the file that has .abso/config.json (or .avcs/config.json from before the rename), cached per folder. */
init0Start the project374async function findRoot($: Engine, path: string): Promise<string | undefined> {
375 const start = path.slice(0, path.lastIndexOf("/"));
376 const now = await $.clock.now();
377 const hit = roots.get(start);
378 if (hit && now - hit.at < ROOT_CACHE_MS) return hit.root;
379 let found: string | undefined;
380 let dir = start;
381 while (dir.includes("/")) {
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.Compare382 if ((await $.fs.exists(`${dir}/.abso/config.json`)) || (await $.fs.exists(`${dir}/.avcs/config.json`))) {
384 break;
385 }
386 const up = dir.slice(0, dir.lastIndexOf("/"));
387 if (up === dir || up === "" || /^[A-Za-z]:$/.test(up)) break;
388 dir = up;
389 }
390 roots.set(start, { root: found, at: now });
391 return found;
392}
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.Compare394/** 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). */
init0Start the project395async function token($: Engine, server: string): Promise<string | undefined> {
396 const home = (await $.env.get("USERPROFILE")) ?? (await $.env.get("HOME"));
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.Compare397 const machine = machineServers(home ? await readHome($, home, "servers.json") : undefined);
init0Start the project398 if (!tokenGoesTo(server, trustedList(await $.env.get("AVCS_TRUSTED_SERVERS"), machine))) return undefined;
399 const env = await $.env.get("AVCS_TOKEN");
400 if (env) return env.trim();
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.Compare401 return home ? (await readHome($, home, "token"))?.trim() || undefined : undefined;
404async function send($: Engine, job: Job, who: Who): Promise<{ outcome: string; news: readonly string[] }> {
405 const { root, rel } = job;
406 // While an abso command changes the folder's records, leave the known copy alone: the next record sends the file (#51).
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.Compare407 if (lockHeld(await readOr($, `${await stateOf($, root)}/${LOCK_FILE}`), Date.now()))
init0Start the project408 return { outcome: "skipped: another abso command is changing this folder; abso record sends it", news: [] };
409 const disk = job.snapshot;
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.Compare410 const knownPath = `${await stateOf($, root)}/known/${rel}`;
412 if (disk === undefined) {
413 if (job.nul !== undefined && knownRaw !== undefined && !looksBinary(knownRaw)) {
414 // A text file an edit left with a NUL byte: tell the agent now, not forty minutes later (#25).
rename100abso publish is now abso push, abso sync is now abso pull (abso 427)
Commands, help, flags, messages, MCP tool names and descriptions, hook text, README, SKILL.md and tests say push and pull; "shared" stays the noun ("Pushed version N"). No aliases, no notices. A queued push that was "pulled" is now "turned back", so pull means one thing.
push -f/--force/-u/--all/--tags and pull --rebase/--ff-only/--squash refuse with one plain line naming the abso way; push and pull take no remote or branch.
Kept as stored: log entry kinds (publish, sync, pulled), HTTP route paths, the pipeline trigger on: publish, the yours (unpublished) marker, npm-publish.Compare415 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.`;
init0Start the project416 return { outcome: `not sent: a NUL byte at line ${job.nul.line}`, news: [warning] };
417 }
418 return { outcome: "skipped: file is missing or not text; abso record catches up", news: [] };
419 }
420 const known = knownRaw === undefined || looksBinary(knownRaw) ? undefined : knownRaw;
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.Compare422 const config = JSON.parse(await $.fs.read(`${await stateOf($, root)}/config.json`)) as {
424 project: string;
425 agent: string;
426 };
427 const bearer = await token($, config.server);
428 const post = async (action: string, payload: unknown): Promise<Answer> => {
429 const url = `${config.server.replace(/\/+$/, "")}/p/${encodeURIComponent(config.project)}/a/${encodeURIComponent(config.agent)}/${action}`;
430 const r = await $.http.fetch(url, {
431 method: "POST",
432 headers: {
433 "content-type": "application/json",
pinch54The client and the edit mods send and read X-Abso-* headers only (Client, Name, Run-Key, Kind, Admin; Run, Box, Prep from answers). Servers have read X-Abso-* beside the old names for a while and answer under both, so this works with any current server.Compare434 "x-abso-client": CLIENT,
436 },
437 body: JSON.stringify(payload),
438 });
439 if (!r.ok) throw new Error(`${action} answered ${r.status}: ${r.text.slice(0, 300)}`);
440 return JSON.parse(r.text) as Answer;
441 };
443 const body: EditBody | undefined = editBody(job.tool, job.input, rel, known, disk, who);
444 if (body !== undefined) {
445 const answer = await post("edit", body);
446 if (answer.ok) {
447 await remember($, knownPath, disk);
448 return { outcome: body.content !== undefined ? "sent write" : "sent edit", news: heardFrom(answer) };
449 }
450 if (answer.reason !== "out of step") throw new Error(`edit refused: ${answer.reason}`);
451 }
452 const answer = await post("record", { files: { [rel]: disk }, ...who });
453 if (!answer.ok) throw new Error(`record refused: ${answer.reason ?? "no reason given"}`);
454 await remember($, knownPath, disk);
455 return { outcome: body === undefined ? "sent whole file" : "out of step; sent whole file", news: heardFrom(answer) };
456}
458/** Keep the known copy in step. */
459async function remember($: Engine, knownPath: string, text: string): Promise<void> {
460 await $.fs.write(knownPath, text);
461}
463/** One line per edit in .avcs/hook.log (or another log there), as the command hook writes, kept under LOG_LIMIT. */
464async function log($: Engine, root: string, line: string, file = "hook.log"): Promise<void> {
465 try {
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.Compare466 const path = `${await stateOf($, root)}/${file}`;
468 if (text.length > LOG_LIMIT) text = text.slice(text.indexOf("\n", text.length - LOG_LIMIT / 2) + 1);
469 await $.fs.write(path, text);
470 } catch {
471 // Logging is best effort.
472 }
473}