- MCP
- blame on this site's /mcp
- CLI
- abso blame client/hooks/register.ts --version 270 --json
- JSON
- /christopher/abso-core/blame/client/hooks/register.ts?version=270&format=json
412 linesFirst import 92% · review 6% · box-grants 1% · pinch 1% · rename 1%Last change box-grants in version 270,
412 lines from 6 changes in 6 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";
36import { 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 }>();
92/** How often to ask for news without an edit (announcements reach an agent that isn't editing). */
93const NEWS_POLL_MS = 30_000;
94/** The abso folder this chat works in: the session's folder, or the first edited file's. */
95let newsRoot: string | undefined;
96let polling = false;
97/** Each folder's rules from git's own files, kept as long as the folder lookup. */
98const gitSetups = new Map<string, { git: GitIgnoreSetup; at: number }>();
100export const register: Register = (on) => {
101 on("session.start", async ($, e, next) => {
102 $.clock.every(TICK_MS, () => {
103 if (draining || jobs.length === 0) return;
104 draining = true;
105 void drain($).finally(() => {
106 draining = false;
107 });
108 });
109 // Outside an abso folder each tick only reads a variable.
110 newsRoot = await findRoot($, `${slash(await $.session.cwd())}/.`).catch(() => undefined);
111 $.clock.every(NEWS_POLL_MS, () => {
112 if (polling || newsRoot === undefined) return;
113 polling = true;
114 void pollNews($, newsRoot).finally(() => {
115 polling = false;
116 });
117 });
118 return next(e);
119 });
121 on("tool.call", { tool: TOOLS }, async ($, e, next) => {
122 const ran = await next(e);
123 try {
124 if (ran.deny !== undefined || ran.isError) return ran;
125 const input = e as unknown as Record<string, unknown>;
126 const raw = input.file_path ?? input.notebook_path;
127 if (typeof raw !== "string" || raw === "") return ran;
128 // The model may pass a path relative to the session's folder; the host resolves it.
129 const path = slash(
130 /^([A-Za-z]:)?[\\/]/.test(raw) ? raw : ((await $.fs.stat(raw, { resolve: true })).realPath ?? raw),
131 );
132 const root = await findRoot($, path);
133 if (root === undefined) return ran;
134 newsRoot ??= root;
135 const rel = path.slice(root.length + 1);
136 const text = await readOr($, path);
137 const job: Job = {
138 root,
139 rel,
140 tool: String(input.tool),
141 input: Object.fromEntries(
142 Object.entries(input).filter(
143 ([k]) => k !== "tool" && k !== "tool_use_id" && k !== "agentId" && k !== "consent",
144 ),
145 ),
146 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.Compare147 ...(text?.includes("\u0000")
init0Start the project148 ? { nul: { at: text.indexOf("\u0000"), line: text.slice(0, text.indexOf("\u0000")).split("\n").length } }
149 : {}),
150 agentId: typeof input.agentId === "string" ? input.agentId : undefined,
151 queuedAt: await $.clock.now(),
152 };
153 jobs.push(job);
154 const waitingNews = pendingNews.get(job.agentId ?? "");
155 if (waitingNews !== undefined) {
156 pendingNews.delete(job.agentId ?? "");
157 return { ...ran, context: [...(ran.context ?? []), ...waitingNews] };
158 }
159 } catch {
160 // Never into the chat. The next `abso record` catches up.
161 }
162 return ran;
163 });
164};
166/** Send the waiting jobs one at a time, oldest first. */
167async function drain($: Engine): Promise<void> {
168 for (let job = jobs.shift(); job !== undefined; job = jobs.shift()) await run($, job);
169}
171async function run($: Engine, job: Job): Promise<void> {
172 const started = await $.clock.now().catch(() => job.queuedAt);
173 let outcome: string;
174 let news: readonly string[] = [];
175 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.Compare176 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.Compare178 } else if (/"reader"\s*:\s*true/.test((await readOr($, `${await stateOf($, job.root)}/config.json`)) ?? "")) {
180 } else if (await ignored($, job.root, job.rel)) {
181 outcome = "skipped: ignored path";
182 } else if (await isLink($, job.root, job.rel)) {
183 outcome = "skipped: a link (or a file standing in for one); abso record sends links";
184 } else {
185 const who: Who = { session: await $.session.id(), ...(job.agentId ? { subagent: job.agentId } : {}) };
186 const sent = await send($, job, who);
187 outcome = sent.outcome;
188 news = sent.news;
189 }
190 } catch (err) {
191 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.Compare192 await $.fs.write(`${await stateOf($, job.root)}/known/${job.rel}`, FORGOTTEN).catch(() => {});
194 const done = await $.clock.now().catch(() => started);
195 await log(
196 $,
197 job.root,
198 `${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}`,
199 );
200 const context = newsContext(news);
201 if (context === undefined) return;
202 // For anything that shows news later (the avcs-view mod reads it).
203 const at = new Date(done).toISOString();
204 await log($, job.root, news.map((n) => `${at}\t${n}`).join("\n"), "news.log");
205 try {
206 await $.session.append({
207 message: { type: "user", content: [{ type: "text", text: context }] },
208 ...(job.agentId ? { agentId: job.agentId } : {}),
209 });
210 } catch {
211 // Older Claude Code has no append; the agent's next edit carries it instead.
212 const key = job.agentId ?? "";
213 pendingNews.set(key, [...(pendingNews.get(key) ?? []), context]);
214 }
215}
217/** Ask for the news waiting for this agent (announcements, collisions) and hand it to the model. */
218async function pollNews($: Engine, root: string): Promise<void> {
219 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).Compare220 // While this seat holds its news stream (abso news --stream or --follow, abso 690), the stream wakes the chat.
221 const mark = await readOr($, `${await stateOf($, root)}/news-stream.json`);
222 if (mark !== undefined) {
223 const until = Number((JSON.parse(mark) as { until?: unknown }).until);
224 if (Number.isFinite(until) && until > (await $.clock.now())) return;
225 }
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.Compare226 const config = JSON.parse(await $.fs.read(`${await stateOf($, root)}/config.json`)) as {
228 project: string;
229 agent: string;
230 };
231 const bearer = await token($, config.server);
232 const r = await $.http.fetch(
233 `${config.server.replace(/\/+$/, "")}/p/${encodeURIComponent(config.project)}/a/${encodeURIComponent(config.agent)}/news`,
234 {
235 method: "POST",
236 headers: {
237 "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.Compare238 "x-abso-client": CLIENT,
240 },
241 body: "{}",
242 },
243 );
244 if (!r.ok) return;
245 const news = ((JSON.parse(r.text) as { news?: readonly string[] }).news ?? []).filter(
246 (n) => typeof n === "string" && n.trim() !== "",
247 );
248 const context = newsContext(news);
249 if (context === undefined) return;
250 const at = new Date(await $.clock.now()).toISOString();
251 await log($, root, news.map((n) => `${at}\t${n}`).join("\n"), "news.log");
252 try {
253 await $.session.append({ message: { type: "user", content: [{ type: "text", text: context }] } });
254 } catch (err) {
255 // It rides on the next edit's result instead; say why in the log.
256 await log($, root, `${at}\tnews\t-\tcould not append (${(err as Error).message}); the next edit carries it`);
257 pendingNews.set("", [...(pendingNews.get("") ?? []), context]);
258 }
259 } catch {
260 // The next poll, edit or abso command picks it up; nothing is lost on the server.
261 }
262}
264async function readOr($: Engine, path: string): Promise<string | undefined> {
265 try {
266 return await $.fs.read(path);
267 } catch {
268 return undefined;
269 }
270}
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.Compare272/** 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.) */
273async function stateOf($: Engine, root: string): Promise<string> {
274 return (await $.fs.exists(`${root}/.abso/config.json`)) ? `${root}/.abso` : `${root}/.avcs`;
275}
277/** A file under the user's home: ~/.abso/<name>, else the older ~/.avcs/<name>. */
278async function readHome($: Engine, home: string, name: string): Promise<string | undefined> {
279 return (await readOr($, `${slash(home)}/.abso/${name}`)) ?? (await readOr($, `${slash(home)}/.avcs/${name}`));
280}
init0Start the project282/** Whether the server has this path as a symbolic link (.avcs/modes.json, written by the client). */
283async 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.Compare284 const raw = await readOr($, `${await stateOf($, root)}/modes.json`);
286 try {
287 const modes = JSON.parse(raw) as Record<string, { link?: unknown }>;
288 return typeof modes[rel]?.link === "string";
289 } catch {
290 return false;
291 }
292}
294/** The client's ignore rules (src/core.ts), reading only the ignore files above the path. */
295async function ignored($: Engine, root: string, rel: string): Promise<boolean> {
296 const now = await $.clock.now();
297 let setup = gitSetups.get(root);
298 if (!setup || now - setup.at >= ROOT_CACHE_MS) {
299 const home = (await $.env.get("HOME")) ?? (await $.env.get("USERPROFILE"));
300 const xdgConfigHome = await $.env.get("XDG_CONFIG_HOME");
301 const git = await readAll(gitIgnoreSetup(root, { home, ...(xdgConfigHome ? { xdgConfigHome } : {}) }), (p) =>
302 readOr($, p),
303 );
304 setup = { git, at: now };
305 gitSetups.set(root, setup);
306 }
307 const files = new Map<string, string | undefined>();
308 for (const f of ignoreFilesFor(rel)) files.set(f, await readOr($, `${root}/${f}`));
309 return makeIgnore((f) => files.get(f), setup.git)(rel, false);
310}
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.Compare312/** The nearest folder above the file that has .abso/config.json (or .avcs/config.json from before the rename), cached per folder. */
init0Start the project313async function findRoot($: Engine, path: string): Promise<string | undefined> {
314 const start = path.slice(0, path.lastIndexOf("/"));
315 const now = await $.clock.now();
316 const hit = roots.get(start);
317 if (hit && now - hit.at < ROOT_CACHE_MS) return hit.root;
318 let found: string | undefined;
319 let dir = start;
320 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.Compare321 if ((await $.fs.exists(`${dir}/.abso/config.json`)) || (await $.fs.exists(`${dir}/.avcs/config.json`))) {
323 break;
324 }
325 const up = dir.slice(0, dir.lastIndexOf("/"));
326 if (up === dir || up === "" || /^[A-Za-z]:$/.test(up)) break;
327 dir = up;
328 }
329 roots.set(start, { root: found, at: now });
330 return found;
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/** 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 project334async function token($: Engine, server: string): Promise<string | undefined> {
335 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.Compare336 const machine = machineServers(home ? await readHome($, home, "servers.json") : undefined);
init0Start the project337 if (!tokenGoesTo(server, trustedList(await $.env.get("AVCS_TRUSTED_SERVERS"), machine))) return undefined;
338 const env = await $.env.get("AVCS_TOKEN");
339 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.Compare340 return home ? (await readHome($, home, "token"))?.trim() || undefined : undefined;
343async function send($: Engine, job: Job, who: Who): Promise<{ outcome: string; news: readonly string[] }> {
344 const { root, rel } = job;
345 // 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.Compare346 if (lockHeld(await readOr($, `${await stateOf($, root)}/${LOCK_FILE}`), Date.now()))
init0Start the project347 return { outcome: "skipped: another abso command is changing this folder; abso record sends it", news: [] };
348 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.Compare349 const knownPath = `${await stateOf($, root)}/known/${rel}`;
351 if (disk === undefined) {
352 if (job.nul !== undefined && knownRaw !== undefined && !looksBinary(knownRaw)) {
353 // 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.Compare354 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 project355 return { outcome: `not sent: a NUL byte at line ${job.nul.line}`, news: [warning] };
356 }
357 return { outcome: "skipped: file is missing or not text; abso record catches up", news: [] };
358 }
359 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.Compare361 const config = JSON.parse(await $.fs.read(`${await stateOf($, root)}/config.json`)) as {
363 project: string;
364 agent: string;
365 };
366 const bearer = await token($, config.server);
367 const post = async (action: string, payload: unknown): Promise<Answer> => {
368 const url = `${config.server.replace(/\/+$/, "")}/p/${encodeURIComponent(config.project)}/a/${encodeURIComponent(config.agent)}/${action}`;
369 const r = await $.http.fetch(url, {
370 method: "POST",
371 headers: {
372 "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.Compare373 "x-abso-client": CLIENT,
375 },
376 body: JSON.stringify(payload),
377 });
378 if (!r.ok) throw new Error(`${action} answered ${r.status}: ${r.text.slice(0, 300)}`);
379 return JSON.parse(r.text) as Answer;
380 };
382 const body: EditBody | undefined = editBody(job.tool, job.input, rel, known, disk, who);
383 if (body !== undefined) {
384 const answer = await post("edit", body);
385 if (answer.ok) {
386 await remember($, knownPath, disk);
387 return { outcome: body.content !== undefined ? "sent write" : "sent edit", news: heardFrom(answer) };
388 }
389 if (answer.reason !== "out of step") throw new Error(`edit refused: ${answer.reason}`);
390 }
391 const answer = await post("record", { files: { [rel]: disk }, ...who });
392 if (!answer.ok) throw new Error(`record refused: ${answer.reason ?? "no reason given"}`);
393 await remember($, knownPath, disk);
394 return { outcome: body === undefined ? "sent whole file" : "out of step; sent whole file", news: heardFrom(answer) };
395}
397/** Keep the known copy in step. */
398async function remember($: Engine, knownPath: string, text: string): Promise<void> {
399 await $.fs.write(knownPath, text);
400}
402/** One line per edit in .avcs/hook.log (or another log there), as the command hook writes, kept under LOG_LIMIT. */
403async function log($: Engine, root: string, line: string, file = "hook.log"): Promise<void> {
404 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.Compare405 const path = `${await stateOf($, root)}/${file}`;
407 if (text.length > LOG_LIMIT) text = text.slice(text.indexOf("\n", text.length - LOG_LIMIT / 2) + 1);
408 await $.fs.write(path, text);
409 } catch {
410 // Logging is best effort.
411 }
412}