- MCP
- code on this site's /mcp
- CLI
- none: the JSON below is the answer
- JSON
- /christopher/abso-core/files/client/src/main.ts?version=2&format=json
786 linesFirst import 99% · infra-split 1%Last change infra-split in version 1, 2 versions changed it
You're reading version 2. The newest is 318, and 57 versions since then changed this file.
1// The command table and the dispatcher. main() returns what to print and the
2// exit code instead of printing, so tests can call it directly.
4import { readFileSync } from "node:fs";
5import { resolve } from "node:path";
6import { runAnnounce, runNews, runStart } from "./announce.ts";
7import { ApiError } from "./api.ts";
8import { bool, type FlagSpec, type Parsed, parseArgs, str, UsageError } from "./args.ts";
9import { bodyFilesHelp, readBodyFiles, withBodyFiles } from "./body-files.ts";
10import { boxPublic, boxText, login, logout, readBox } from "./box.ts";
11import { runDiff, runFiles, runLog, runRestore, runShow } from "./changes.ts";
12import { runCheckIgnore } from "./check-ignore.ts";
13import { runCi } from "./ci.ts";
14import {
15 type Env,
16 EXIT,
17 type Output,
18 runBisect,
19 runFetch,
20 runFixEol,
21 runInit,
22 runJoin,
23 runLogs,
24 runMv,
25 runPause,
26 runPrep,
27 runPublish,
28 runReader,
29 runRecord,
30 runResume,
31 runRun,
32 runServe,
33 runSettle,
34 runShot,
35 runStatus,
36 runSync,
37 takeNews,
38} from "./commands.ts";
39import { configPath, findRoot, installKey, readConfig, readToken } from "./config.ts";
40import { runDraftSync, runLand, runSwitch } from "./drafts.ts";
41import { runExport } from "./export.ts";
42import { runBlame, runWhere, runWho, runWhy } from "./history.ts";
43import { runAnswer, runAsk, runIssue, runIssues, runWaiting } from "./issues.ts";
44import { adminToken, issuedPublic, keyList, keyListText, keyNew, keyRevoke } from "./key-admin.ts";
45import { runUnqueue } from "./queue.ts";
46import { runNote, runNotes, runReview } from "./review.ts";
47import { runAmend, runDrop, runFollow, runLabel, runLabels, runPluck } from "./versions.ts";
48import { runVisibility } from "./visibility-commands.ts";
50interface CommandDef {
51 readonly flags: FlagSpec;
52 readonly usage: string;
53 readonly about: string;
54 /** Stop reading options at the first word (for `run <command...>`). */
55 readonly rest?: boolean;
56 readonly run: (args: Parsed, env: Env) => Promise<Output>;
57}
59/** The server login, box and logout act on: --server, or the folder's. */
60function boxServer(args: Parsed, env: Env): string {
61 const flag = str(args, "server");
62 if (flag) return flag;
63 const root = findRoot(env.cwd);
64 if (!root) throw new UsageError("give --server <url>, or run this inside an agent's folder");
65 return (JSON.parse(readFileSync(configPath(root), "utf8")) as { server: string }).server;
66}
68async function runKeyInstall(args: Parsed, env: Env): Promise<Output> {
69 // With --server, the folder is the one named (or here), before it is joined: findRoot
70 // could find a parent agent's folder and pin the key there.
71 const server = str(args, "server");
72 const root = server ? resolve(env.cwd, str(args, "dir") ?? ".") : findRoot(env.cwd);
73 if (!root)
74 throw new UsageError("abso key install runs inside an agent's folder, or takes --server <url> before abso join");
75 const stdin = await new Promise<string>((done, reject) => {
76 const chunks: Buffer[] = [];
77 process.stdin.on("data", (c) => chunks.push(c as Buffer));
78 process.stdin.on("end", () => done(Buffer.concat(chunks).toString("utf8")));
79 process.stdin.on("error", reject);
80 });
81 const { id } = installKey(root, stdin, server);
82 return { text: `Installed agent key ${id}.`, json: { installed: id } };
83}
85const COMMANDS: Readonly<Record<string, CommandDef>> = {
86 init: {
87 flags: { server: "string", project: "string", agent: "string", "as-is": "boolean" },
88 usage: "abso init [folder] --server <url> --project <name> --agent <name> [--as-is]",
89 about:
90 "Create a project on the server from a folder's text files. The folder becomes that agent's folder. It writes a starting .avcsignore, and, when the folder has no avcs.json and package.json gives a check or a build to guess, an avcs.json (setup, check, build and out): what the server's CI runs on each new version of shared. Without one, CI runs what it can guess itself, or nothing. --as-is writes neither: the folder goes up exactly as it is (an import).",
91 run: runInit,
92 },
93 key: {
94 flags: {
95 server: "string",
96 dir: "string",
97 project: "string",
98 agent: "string",
99 expires: "string",
100 role: "string",
101 print: "boolean",
102 },
103 usage:
104 "abso key install [--server <url> [--dir <folder>]] | abso key new <agent> [--server <url> [--dir <folder>]] [--project <name>] [--expires <Nd>] [--role owner|writer|reader] [--print] | abso key list [--agent <name>] [--project <name>] | abso key revoke <id> [--project <name>]",
105 about:
106 "install reads {key, id} from stdin into .avcs/key. With --server, it writes it into a folder not joined yet, so abso join there signs in with the key. new writes the key into that folder and prints only the id; its role is writer unless --role says otherwise (a reader only reads; a writer writes on its own agent's routes; an owner also skips or revokes CI, resumes the queue, syncs git and exports); --print writes the key to stdout instead. list and revoke never print a key. These three read the admin token from AVCS_ADMIN_TOKEN or ~/.avcs/admin-token and send it only to a server named in AVCS_ADMIN_SERVERS. An agent does not run them unless a person on the project says so.",
107 run: async (args, env) => {
108 const sub = args.positionals[0];
109 if (sub === "install" && args.positionals.length === 1) return runKeyInstall(args, env);
110 const serverFlag = str(args, "server");
111 const root = serverFlag ? resolve(env.cwd, str(args, "dir") ?? ".") : findRoot(env.cwd);
112 if (!root) throw new UsageError("abso key runs inside an agent's folder, or takes --server <url>");
113 let config: ReturnType<typeof readConfig>;
114 try {
115 config = readConfig(root, env.env);
116 } catch {
117 config = {
118 server: serverFlag ?? "",
119 project: str(args, "project") ?? "",
120 agent: "admin",
121 token: readToken(env.env),
122 };
123 }
124 if (serverFlag) config = { ...config, server: serverFlag };
125 const admin = adminToken(env.env);
126 if (sub === "new" && args.positionals.length === 2) {
127 const server = str(args, "server") ?? config.server;
128 const project = str(args, "project") ?? config.project;
129 const expires = str(args, "expires");
130 const role = str(args, "role");
131 if (role !== undefined && role !== "owner" && role !== "writer" && role !== "reader")
132 throw new UsageError("--role is owner, writer or reader");
133 const issued = await keyNew({ ...config, server }, admin, args.positionals[1]!, project, expires, role);
134 const print = bool(args, "print");
135 const shown = issuedPublic(issued, print);
136 if (!print) {
137 const dir = str(args, "server") ? resolve(env.cwd, str(args, "dir") ?? ".") : root;
138 installKey(dir, JSON.stringify({ key: issued.key, id: issued.id }), server);
139 }
140 return {
141 text: print ? `${JSON.stringify({ key: issued.key, id: issued.id })}\n` : `Made ${issued.id}.\n`,
142 json: shown,
143 };
144 }
145 if (sub === "list" && args.positionals.length === 1) {
146 const agent = str(args, "agent");
147 const project = str(args, "project") ?? config.project;
148 const keys = await keyList({ ...config, server: str(args, "server") ?? config.server }, admin, agent, project);
149 return { text: `${keyListText(keys)}\n`, json: { keys } };
150 }
151 if (sub === "revoke" && args.positionals.length === 2) {
152 const project = str(args, "project") ?? config.project;
153 const id = args.positionals[1]!;
154 const revoked = await keyRevoke(
155 { ...config, server: str(args, "server") ?? config.server },
156 admin,
157 id,
158 project,
159 );
160 return { text: revoked ? `Revoked ${id}.\n` : `No key ${id}.\n`, json: { id, revoked } };
161 }
162 throw new UsageError("abso key install | abso key new <agent> | abso key list | abso key revoke <id>");
163 },
164 },
165 login: {
166 flags: { server: "string" },
167 usage: "abso login [--server <url>]",
168 about:
169 "Sign this box in once (abso issue 108): it shows a code and a link, and waits while a person approves the code on the website, choosing the projects, the highest role and how many agents. Then abso join in any of those projects gives each agent its own key, with no approval. The box's sign-in is kept in your user folder, never in a project folder, and is never printed. Without --server, the folder's server.",
170 run: async (args, env) => {
171 const server = boxServer(args, env);
172 const record = await login(server, { say: (line) => process.stderr.write(`${line}\n`) });
173 return {
174 text: `This box is signed in. ${boxText(record, server).split("\n").slice(1).join(" ")}`,
175 json: { box: boxPublic(record) },
176 };
177 },
178 },
179 box: {
180 flags: { server: "string" },
181 usage: "abso box [--server <url>]",
182 about:
183 "What this box's sign-in allows: its projects, the highest role its agents may have, how many agents it has made and may make, and when it expires. Never the credential.",
184 run: async (args, env) => {
185 const server = boxServer(args, env);
186 const record = readBox(server);
187 return { text: boxText(record, server), json: { box: boxPublic(record) } };
188 },
189 },
190 logout: {
191 flags: { server: "string" },
192 usage: "abso logout [--server <url>]",
193 about:
194 "End this box's sign-in on the server and forget it here. Keys its agents already have stop working with it.",
195 run: async (args, env) => {
196 const server = boxServer(args, env);
197 const record = readBox(server);
198 if (!record) return { text: `This box isn't signed in to ${server}.`, json: { loggedOut: false } };
199 const ended = await logout(record);
200 return {
201 text: ended
202 ? `Signed this box out of ${record.server}.`
203 : `Forgot this box's sign-in here, but ${record.server} couldn't be reached to end it. Revoke the box on the website.`,
204 json: { loggedOut: true, ended },
205 };
206 },
207 },
208 join: {
209 flags: { server: "string", agent: "string", dir: "string", reader: "boolean" },
210 usage: "abso join <project> --agent <name> --server <url> [--dir <folder>] [--reader]",
211 about:
212 "Join a project as a new agent and write its shared files into the folder (default: here). --reader joins as a reader: it reads everything and records nothing, and the server refuses its edits, records and publishes.",
213 run: runJoin,
214 },
215 record: {
216 flags: { all: "boolean", binary: "string" },
217 usage: "abso record [--all]",
218 about:
219 "Send every file that changed since the server last heard about it (--all: every file). For edits the hook did not see.",
220 run: runRecord,
221 },
222 publish: {
223 flags: {
224 message: "string",
225 binary: "string",
226 "as-is": "boolean",
227 check: "optional",
228 box: "string",
229 wait: "string",
230 "no-wait": "boolean",
231 done: "boolean",
232 },
233 usage: 'abso publish -m "<why>" [--as-is] [--check ["<command>"]] [--wait <seconds> | --no-wait] [--done]',
234 about:
235 'Record, then add your draft to shared. Refused when it collides with work published since your last sync, or when lines a sync showed changed on both sides are still untouched (--as-is publishes both sides\' lines anyway). --check "<command>" (e.g. --check "npm run typecheck") first syncs, then runs the command in your box on your draft with newest shared, and publishes only if it exits 0, so two changes that each pass alone can\'t turn shared red. --check alone runs the "build" and then the "check" in the project\'s avcs.json (your draft\'s copy), as the server does on each new version. With the merge queue on ("queue": true in avcs.json), a publish to shared is queued and lands only once the project\'s check passes on shared with it on top: publish waits up to 100 s for that (--wait <seconds> changes it, --no-wait returns at once), then says it landed (exit 0), was pulled with the check\'s output (exit 2, its changes still in your draft), or is still queued (exit 3; the outcome comes as news). --check alone is skipped then, since the queue runs the check. --done takes your start note back once it\'s published: this publish finishes that work.',
236 run: runPublish,
237 },
238 bisect: {
239 flags: { good: "string", bad: "string", box: "string" },
240 usage: "abso bisect [--good <version>] [--bad <version>] -- <program> <arg...>",
241 about:
242 "The first version where a check fails: runs it in your box at versions of your folder's space (as abso run --at does) and prints that version, its author and message. --bad is the newest by default; without --good it steps back in doubling steps until one passes, then halves the gap. A run that exits 0 passes; exit 125 means it can't be tested (as in git bisect run), so that version is skipped, and if skips leave the answer open it names the range. About log2(versions) runs; your folder is never touched.",
243 rest: true,
244 run: runBisect,
245 },
246 reader: {
247 flags: {},
248 usage: "abso reader on|off",
249 about:
250 "Make this folder's agent a reader, which reads everything and records nothing (the server refuses its edits, records and publishes), or a writer again. Refused while it has unpublished or parked work.",
251 run: runReader,
252 },
253 settle: {
254 flags: { yours: "boolean", theirs: "boolean", both: "boolean" },
255 usage: "abso settle <file...> --yours|--theirs|--both",
256 about:
257 "Settle the collisions a sync marked in these files: each marker block becomes your lines, theirs, or both (yours first), then it records. abso status lists the files with markers.",
258 run: runSettle,
259 },
260 sync: {
261 flags: { verbose: "boolean", full: "boolean" },
262 usage: "abso sync [--full]",
263 about:
264 "Record, then bring shared's new work into the folder. Lines changed on both sides are listed as collisions to settle. --full writes any file of yours the folder is missing, not only what changed since your last sync.",
265 run: runSync,
266 },
267 run: {
268 flags: {
269 detach: "boolean",
270 replace: "boolean",
271 fresh: "boolean",
272 parallel: "boolean",
273 at: "string",
274 files: "string",
275 fetch: "string",
276 box: "string",
277 with: "string",
278 quiet: "boolean",
279 },
280 usage:
281 'abso run [--detach] [--replace] [--fresh] [--box <name>] [--at <version> [--files <glob>]] <command...> | abso run ... -- <program> <arg...> | abso run --parallel "<command>" "<command>"...',
282 about:
283 "Send the folder to this agent's box, run the command there, and stream its output back. Exits with the command's code. After --, each word goes to the program exactly as typed (quotes, backslashes, regex text); without --, the words are one shell command. The box's stderr comes out on stderr. --detach starts it and prints its id without waiting. While a run is still going in the box, a new one is refused (409, naming it), since it would replace the files under it; --replace stops the old one first. --parallel runs each quoted command at once in the box (one upload), labels each line [1], [2], ..., ends with each one's exit code, and exits with the worst. --at <version> runs that version of the folder's space instead of the folder (for bisecting); with --files <glob>, only the matching files are taken from that version. The folder is never touched. --fetch <glob>[,<glob>...] brings matching files from the box's /w back after the run (see abso fetch); several globs go in one argument, comma-separated (--fetch 'shots/*.png,out/*.json'), as for --files and --with. The box's /w is replaced by your folder on every run; the rest of the box (/tmp, ~/.cache, /w/node_modules) lasts between runs until the box stops (idle 30 minutes, or restarted). avcs's own notices go to stderr, apart from the command's output; --quiet drops them (the command's own stderr still comes through). --with <box path>=<local path>[,...] adds files (or a folder's files) for this run only: they go to the box and are never written to your folder or recorded, for an A/B run that leaves the project alone. --box <name> (or AVCS_BOX=<name>) runs in another box of yours, with its own /w and state, so a subagent's runs and yours don't wait on each other; logs and fetch take --box too. After abso prep, a fresh box starts from the prep; --fresh starts this run from the plain image instead.",
284 rest: true,
285 run: runRun,
286 },
287 serve: {
288 flags: { version: "string", build: "string", out: "string" },
289 usage: 'abso serve [--version <n>] [--build "<command>"] [--out <folder>]',
290 about:
291 "A preview of one version of shared (the newest by default) at a stable URL that needs no token, for playing a fixed build in a browser with no local server and no sound on this machine. The server builds it once per version (npm ci, then vite build --base ./ into dist; --build and --out change that) and keeps the newest 10 builds. Asking again for a built version answers at once.",
292 run: runServe,
293 },
294 mv: {
295 flags: {},
296 usage: "abso mv <from> <to>",
297 about:
298 "Move a file in your draft, its lines keeping their history (as git mv), recorded as a move rather than guessed from the folder. The way to change a file's case: README.md and readme.md are one file in avcs, and a write under another spelling goes to the existing one, with a warning that names abso mv. It reaches shared with your next publish.",
299 run: runMv,
300 },
301 review: {
302 flags: { since: "string" },
303 usage: "abso review [<id> | v<version> | <agent>] [--since <position|2h>]",
304 about:
305 "Review is reading what landed (#44). With no change: the changes with anything new since you last looked, newest first (a change is one start note's work, a named draft's, or a lone publish), and the mark moves on; --since 2h (or a log position) looks further back without moving it. With a change id, v<version> (the change holding that version of shared) or an agent (its newest change): that change's page, with what it set out to do, its versions, what it settled, its reviewers and its notes.",
306 run: runReview,
307 },
308 note: {
309 flags: {
310 object: "boolean",
311 read: "boolean",
312 draft: "string",
313 at: "string",
314 reply: "string",
315 close: "string",
316 resolved: "boolean",
317 withdrawn: "boolean",
318 },
319 usage:
320 'abso note <file>:<line>[-<line>] "<text>" [--object | --read] [--draft <agent> | --at <version>] | abso note --reply <id> "<text>" | abso note --close <id> --resolved|--withdrawn',
321 about:
322 "A note on lines (#44): it sits on those lines and follows them as the file changes. The lines' authors and the change's agent hear it as news. The line numbers are as your folder shows the file (it records first); --draft <agent> notes their unpublished work as their draft shows it, --at <version> a version of shared. --object asks for a fix (it shows as addressed once all its lines change); --read says you read it, telling nobody. --reply answers a note; --close closes one of yours.",
323 run: runNote,
324 },
325 notes: {
326 flags: { change: "string", all: "boolean" },
327 usage: "abso notes [file] [--change <id>] [--all]",
328 about:
329 "The open notes, on a file or a change, with their replies and where their lines are now. --all includes closed, addressed and outdated ones.",
330 run: runNotes,
331 },
332 issues: {
333 flags: {
334 open: "boolean",
335 status: "string",
336 agent: "string",
337 parent: "string",
338 label: "string",
339 labels: "boolean",
340 drafts: "boolean",
341 },
342 usage:
343 "avcs issues [--open] [--status <status>] [--agent <agent>] [--parent <N>] [--label <l,l>] | avcs issues --labels",
344 about:
345 "The project's issues (#54), most recently updated first, each with its status, agents, labels, versions and who it waits on. --label keeps the issues with every label named (friction, say); --labels lists the labels in use, with how many issues are open under each; --drafts lists your drafts. A status comes from the work: avcs start --issue N puts an issue In progress, an open ask makes it Blocked (or In review, for a review), and publish --done closes it.",
346 run: runIssues,
347 },
348 issue: {
349 flags: {
350 comment: "string",
351 object: "string",
352 drop: "boolean",
353 reopen: "boolean",
354 done: "boolean",
355 "done-by": "string",
356 title: "string",
357 description: "string",
358 parent: "string",
359 lines: "string",
360 agent: "string",
361 "blocked-by": "string",
362 notify: "string",
363 quiet: "boolean",
364 label: "string",
365 unlabel: "string",
366 open: "boolean",
367 delete: "boolean",
368 },
369 usage:
370 'avcs issue <N> [--comment "..." | --object "..." | --drop | --reopen | --done [--done-by <version>]] | avcs issue <N> [--title "..."] [--description "..."] [--parent <N|none>] [--agent <agent|none>] [--blocked-by <N,N|none>] [--label <l,l>] [--unlabel <l,l>] [--notify <who,who> | --quiet] | avcs issue new "<title>" [--description "..."] [--parent <N>] [--lines <file>:<from>-<to>@<version>] [--agent <agent>] [--blocked-by <N,N>] [--notify <who,who>] [--label <l,l>]',
371 about:
372 "One issue: its description, Agent, Blocked by, labels, asks, comments, edits, sub-issues and watchers. --comment comments on it and --object objects; its agents hear either. --drop drops it. --reopen opens a dropped issue again. --done marks it done by hand, and --done-by <version> names the published version that did it. publish --done still marks it done too. --title, --description, --parent, --agent and --blocked-by edit it, and the edit tells its watchers (who opened it, its Agent and agents, its Reviewer, whoever was named in Notify, and whoever commented); --notify tells more people, --quiet tells nobody. --label adds labels and --unlabel takes them off (friction, area:client: lower-case letters, digits and - _ . :); a label-only edit tells nobody unless --notify names people. An issue is Blocked until each issue it's blocked by is Done. avcs issue new opens one; --lines ties it to lines at a version of shared, --agent says who it's for, --notify tells people now, and --label labels it. avcs issue draft \"<title>\" [the same fields] saves a draft instead: yours alone, with no number and no news; avcs issue draft <D> [fields] changes it, --open opens it as an issue, --delete deletes it.",
373 run: runIssue,
374 },
375 ask: {
376 flags: { issue: "string", review: "boolean", task: "boolean", due: "string", blocks: "string", options: "string" },
377 usage:
378 'avcs ask <who> "<question>" [--issue <N>] [--review | --task] [--due <YYYY-MM-DD>] [--blocks <N,N>] [--options "A|B|C"]',
379 about:
380 "Ask an agent, or a person (person:<id>), something; they hear it. On an issue, it holds the issue at Blocked (In review for --review) until answered. --task asks for something done instead of an answer; --options gives the choices; --blocks names the issues waiting on it.",
381 run: runAsk,
382 },
383 waiting: {
384 flags: { of: "string", mine: "boolean" },
385 usage: "avcs waiting [--of <agent or person:id>] [--mine]",
386 about: "The open asks, soonest due first: every one, those of someone (--of), or those of you (--mine).",
387 run: runWaiting,
388 },
389 answer: {
390 flags: { option: "string", note: "string", done: "boolean" },
391 usage:
392 'avcs answer <ask> "<words>" | avcs answer <ask> --option <N> [--note "..."] | avcs answer <ask> --done [--note "..."]',
393 about:
394 "Answer an ask of you, in your own words, by picking an option (by number or text), or, for a task, with --done. The asker hears it.",
395 run: runAnswer,
396 },
397 unqueue: {
398 flags: {},
399 usage: "abso unqueue",
400 about:
401 "Take back your publishes still waiting in the merge queue: their changes stay in your draft, unpublished. Refused while one is being checked; it lands or is pulled within a few minutes (abso drop takes it back after it lands).",
402 run: runUnqueue,
403 },
404 visibility: {
405 flags: { yes: "boolean" },
406 usage: "abso visibility [public|private] [--yes]",
407 about:
408 "Whether the project is public (abso issue 152). With no word, says which. public, with --yes, lets anyone read it, signed in or not: files, versions, drafts, notes, Issues, people's names, CI as pass or fail; never keys, CI logs, preview links or boxes. private makes it members-only again. Switching takes the project owner's key (on staging, the shared token works too).",
409 run: runVisibility,
410 },
411 ci: {
412 flags: { version: "string", revoke: "boolean" },
413 usage: "abso ci [<version>] | abso ci --revoke",
414 about:
415 "The project's CI: the server runs avcs.json's setup, build and check on each new version of shared, one job at a time on the newest. abso ci says whether shared is green or red (and since which version, by whom, once a bisect finds it), what is being checked, and the preview link of the newest passing build, which needs no token. abso ci <version> shows that version's job: which step failed, its exit code, and the end of its output. status says the same in a line, and log marks each version of shared. --revoke ends every preview link handed out so far and makes a new one.",
416 run: runCi,
417 },
418 shot: {
419 flags: {
420 out: "string",
421 wait: "string",
422 size: "string",
423 box: "string",
424 eval: "string",
425 click: "string",
426 mouse: "string",
427 at: "string",
428 scale: "string",
429 region: "string",
430 text: "boolean",
431 tree: "boolean",
432 interactive: "boolean",
433 depth: "string",
434 find: "string",
435 "max-chars": "string",
436 image: "boolean",
437 },
438 usage:
439 'abso shot ["/<path>?<query>"] [--scale 0.1-1] [--region x0,y0,x1,y1] [--text] [--tree [--interactive] [--depth N]] [--find "<text>"] [--max-chars N] [--image] [--at <version>] [--eval "<js>"] [--click "x,y[@ms];ref_N[@ms]"] [--mouse x,y|ref_N] [--out <file.png>] [--wait <ms>] [--size <w>x<h>]',
440 about:
441 "A look at your folder's game, taken in your box: it runs the project's vite dev server and Playwright on that page (default /, a 1280x720 page). Images cost tokens, so read without one when you can: --text prints the page's visible text, --tree its elements (role, name, a ref like ref_12, and its box in page pixels; --interactive only what can be clicked or typed in; --depth N levels), and --find \"<text>\" the elements matching some text; each is capped at --max-chars (default 5000). With none of those, or with --image, it writes a PNG to .avcs/shots/ (never recorded) or --out, and prints its pixel size and about how many tokens reading it costs (width x height / 750). --scale 0.5 halves the width and height (a quarter of the tokens); --region x0,y0,x1,y1 takes part of the page at full detail; they combine. Coordinates are always the page's, whatever the scale or region. To set up a state first, --eval runs JavaScript in the page and --click clicks points (x,y or ref_N; several separated by ;; @ms waits first), in that order, a second after load and two frames after the eval; --mouse x,y or ref_N leaves the pointer there (for hover cards); then it waits --wait ms (default 3000) and looks. It prints --eval's result, page errors and the first 30 console messages. Refs come from --tree or --find on the same page in the same state. --at <version> looks at that version of your folder's space instead of the folder (as abso run --at). Needs vite and playwright in the project's devDependencies; abso prep with npx --no-install playwright install chromium makes it fast.",
442 run: runShot,
443 },
444 prep: {
445 flags: { forget: "boolean", box: "string" },
446 usage: 'abso prep [--box <name>] "<setup command>" | abso prep --forget',
447 about:
448 "Set up your box once and keep it: sends the folder, runs the setup command (npm ci, npx playwright install chromium, a build) in a fresh box of the current image, and saves the box. From then on every fresh box (after a deploy, 30 idle minutes, or a new run's restart) starts from it, with node_modules, ~/.cache and /tmp as the setup left them; /w is still replaced by your folder on each run, apart from node_modules. abso run says when the prep is set aside (a newer box image) or out of date (package-lock.json changed): run abso prep again then. --forget drops it.",
449 rest: true,
450 run: runPrep,
451 },
452 fetch: {
453 flags: { box: "string" },
454 usage: "abso fetch [--box <name>] <glob...>",
455 about:
456 "Files the last run left in the box's /w (bash globs: out/*.png, **/*.log), written into the folder, but only where abso ignores them, so a fetched file never becomes an edit; the rest are named and left alone. /w is replaced on the next run, and everything goes when the box stops.",
457 run: runFetch,
458 },
459 pause: {
460 flags: {},
461 usage: "abso pause",
462 about:
463 "Send nothing from this folder until abso resume: the edit hook skips, abso record refuses, other commands don't record first. For swapping files in by hand (abso run --at usually does it better).",
464 run: runPause,
465 },
466 resume: {
467 flags: {},
468 usage: "abso resume",
469 about: "End abso pause. Changes made while paused go at the next record.",
470 run: runResume,
471 },
472 logs: {
473 flags: { box: "string" },
474 usage: "abso logs [--box <name>] <run id>",
475 about:
476 "A run's output from its start (stdout and stderr apart), for as long as the box keeps it, waiting until it ends. Exits with its code. For abso run --detach, or a run whose connection was lost.",
477 run: runLogs,
478 },
479 status: {
480 flags: { short: "boolean" },
481 usage: "abso status [--short]",
482 about:
483 "The shared version, whether shared is green or red by the project's CI (abso ci has more), who waits in the merge queue, every agent's base and draft, and what in this folder is not yet recorded. --short prints one word for stamping a build: the version this folder is on (214), with the named draft (coast@3), +unpublished when it holds changes not yet published, and +queued when a publish of yours waits in the merge queue.",
484 run: runStatus,
485 },
486 switch: {
487 flags: { carry: "boolean", verbose: "boolean" },
488 usage: "abso switch <draft> | abso switch -c <new draft> | abso switch shared",
489 about:
490 "Move this folder to a named draft, or back to shared. Your unpublished changes are parked where you leave and come back when you return; -c carries them into a new draft instead.",
491 run: runSwitch,
492 },
493 land: {
494 flags: { message: "string" },
495 usage: 'abso land -m "<why>"',
496 about:
497 "Land your named draft in shared, as one unit. Refused only on a collision with work that landed in shared since the draft began.",
498 run: runLand,
499 },
500 "draft-sync": {
501 flags: {},
502 usage: "abso draft-sync",
503 about: "Move your named draft onto shared's newest version, then bring that into this folder.",
504 run: runDraftSync,
505 },
506 diff: {
507 flags: { draft: "string" },
508 usage: "abso diff [file...] | abso diff <from> <to> [file...] [--draft <name>]",
509 about:
510 "Your unpublished changes, line by line, as git prints them (records first). With two versions: what changed between them in this space.",
511 run: runDiff,
512 },
513 restore: {
514 flags: { all: "boolean" },
515 usage: "abso restore <file...> | abso restore <file>:<line>[-<line>] | abso restore --all",
516 about:
517 "Discard your unpublished changes to those files (--all: to every file), like git restore. The files go back to how your space has them. <file>:<lines> puts back only the changes that touch those lines (numbered as abso diff shows the file now) and keeps your other changes to it.",
518 run: runRestore,
519 },
520 export: {
521 flags: { version: "string", keep: "string" },
522 usage: "abso export <dir> [--version <N>] [--keep <glob>]",
523 about:
524 "Write one published version of this folder's space (the newest unless --version) into a folder of its own, for a build that doesn't move. The folder must be empty, an earlier export (which it replaces, keeping node_modules and what --keep names), or one .avcsignore leaves out; .avcs-export.json there names the version.",
525 run: runExport,
526 },
527 files: {
528 flags: { draft: "string", version: "string" },
529 usage: "abso files [glob...] [--draft <name>] [--version <N>]",
530 about:
531 "The files your folder should hold (your view), marking any it's missing. With --draft or --version: that space's files at that version (--draft shared for shared).",
532 run: runFiles,
533 },
534 log: {
535 flags: { limit: "string", draft: "string", since: "string", by: "string", count: "boolean" },
536 usage:
537 "abso log [file] [-n <count>] [--draft <name>] [--since <version|30m|2h|1d|date>] [--by <agent,...>] [--count]",
538 about:
539 "The published versions of this folder's space (shared or a named draft), newest first: who, when, why and which files, and for shared, whether the version passed CI's check (abso ci). With a file: only the versions that changed it. --since takes a version (the versions after it), a span back from now (30m, 2h, 1d), a clock time today (20:00) or a date and time; --by keeps one agent's versions (or several, comma-separated); --count prints versions and files per agent instead of the list.",
540 run: runLog,
541 },
542 show: {
543 flags: { draft: "string" },
544 usage: "abso show <version> | abso show <version>:<file> [--draft <name>]",
545 about: "One version: who published it, why, and its diff. With :<file>, that file's text as it was then.",
546 run: runShow,
547 },
548 announce: {
549 flags: { to: "string" },
550 usage: "abso announce [--to <agent,agent>] <text>",
551 about:
552 "Tell the project's other agents (or those named) something. Each gets it once, as news on their next edit or the mod's next check.",
553 run: runAnnounce,
554 },
555 start: {
556 flags: { done: "boolean", issue: "string" },
557 usage: 'abso start "<what>" [files...] [--issue <n>] | abso start --done',
558 about:
559 "Say what you are starting on, before your first edit, so abso where shows it to everyone. Names who already has unpublished changes in those files, and tells them. Nothing is locked; publishing ends the note.",
560 run: runStart,
561 },
562 news: {
563 flags: {},
564 usage: "abso news",
565 about:
566 "The news waiting for you: collisions, changed definitions, moved lines and announcements. Each item comes once.",
567 run: runNews,
568 },
569 "fix-eol": {
570 flags: {},
571 usage: "abso fix-eol",
572 about:
573 "Rewrite the files that differ from what abso recorded only in line endings (CRLF here) with LF, as recorded. Their text is unchanged, so nothing is recorded; abso status stops listing them.",
574 run: runFixEol,
575 },
576 who: {
577 flags: {},
578 usage: "abso who <file...>",
579 about:
580 "For each file: who last changed it, who has unpublished changes in it (and where), and whose abso start note names it. Ask before you start in someone's file.",
581 run: runWho,
582 },
583 where: {
584 flags: {},
585 usage: "abso where",
586 about: "Who is working where: each file with unpublished changes, whose they are, and which lines.",
587 run: runWhere,
588 },
589 blame: {
590 flags: { from: "string", to: "string", version: "string", draft: "string", mine: "boolean" },
591 usage: "abso blame <file> [--from <n>] [--to <n>] [--version <n>] [--draft <name> | --mine]",
592 about:
593 "Who wrote each line of the file as shared has it (or had it at --version), and the publish that brought it in. --draft reads a named draft; --mine reads your own view, marking your unpublished lines with *.",
594 run: runBlame,
595 },
596 why: {
597 flags: { draft: "string", mine: "boolean" },
598 usage: "abso why <file>:<line> [--draft <name> | --mine]",
599 about:
600 "Why one line of shared (or of a named draft, or your own view) is the way it is: its change, its publish, its reasons, and any collision it settled.",
601 run: runWhy,
602 },
603 drop: {
604 flags: { message: "string", "with-dependents": "boolean" },
605 usage: 'abso drop <version...> -m "<why>" [--with-dependents]',
606 about:
607 "Take published versions back out of shared, as a new version: like git revert. History keeps them. Refused when later versions build on them, unless --with-dependents drops those too.",
608 run: runDrop,
609 },
610 pluck: {
611 flags: { message: "string", "with-dependencies": "boolean" },
612 usage: 'abso pluck <draft> <version...> -m "<why>" [--with-dependencies]',
613 about:
614 "Take some versions of a named draft into shared, as one version, leaving the draft as it is: like git cherry-pick. Refused when they build on other versions of the draft, unless --with-dependencies takes those too.",
615 run: runPluck,
616 },
617 amend: {
618 flags: { message: "string" },
619 usage: 'abso amend -m "<new message>"',
620 about:
621 "Correct the message of your newest publish in this space. Only the message changes; the log keeps the original.",
622 run: runAmend,
623 },
624 label: {
625 flags: { version: "string", remove: "boolean" },
626 usage: "abso label <name> [--version <n>] [--remove]",
627 about:
628 "Put a label on a version of shared (the newest by default), or take it off: like a git tag. A label can mark more than one version.",
629 run: runLabel,
630 },
631 labels: {
632 flags: {},
633 usage: "abso labels",
634 about: "Every label and the versions it marks.",
635 run: runLabels,
636 },
637 follow: {
638 flags: { none: "boolean" },
639 usage: "abso follow <label> | abso follow --none",
640 about:
641 "Make this folder follow a label: every sync takes it to the newest version of shared with that label, not the newest version. --none goes back to following shared.",
642 run: runFollow,
643 },
644 "check-ignore": {
645 flags: {},
646 usage: "abso check-ignore <path...>",
647 about:
648 "Whether abso leaves each path out, and which line of which ignore file decided (git's rules, for .gitignore and .avcsignore).",
649 run: runCheckIgnore,
650 },
651 pipeline: {
652 flags: { on: "string", space: "string", pipeline: "string", every: "string" },
653 usage:
654 "abso pipeline check [file] [--on publish|draft|green|land|hand|schedule [--space <name>] [--pipeline <name>] [--every <when>]]",
655 about:
656 "Read the folder's pipeline file (abso.yml, abso.yaml or avcs.json, or the file named) and say what's wrong with it, place by place: a cycle in needs, a job that doesn't exist, secrets a draft could reach, a key it doesn't know. Exits 1 when it has problems. With --on, it says which pipelines that event starts (in shared, or --space), with their jobs in waves that can run side by side, and why each other pipeline doesn't start. It reads only the file.",
657 // Loaded only here, so the yaml package it needs can't stop every other command
658 // when a checkout lacks it (abso issue 168).
659 run: async (args, env) => {
660 let mod: typeof import("./pipeline-commands.ts");
661 try {
662 mod = await import("./pipeline-commands.ts");
663 } catch (e) {
664 if ((e as { code?: string }).code === "ERR_MODULE_NOT_FOUND")
665 throw new UsageError(
666 `abso pipeline needs a package this copy of abso doesn't have installed (${(e as Error).message.split("\n")[0]}); run npm install where abso is installed`,
667 );
668 throw e;
669 }
670 return mod.runPipeline(args, env);
671 },
672 },
673};
675function help(): string {
676 return [
677 "avcs: the client for the agent-first version control server.",
678 "",
679 ...Object.values(COMMANDS).flatMap((c) => [` ${c.usage}`, ` ${c.about}`]),
680 " abso hook",
681 " The Claude Code PostToolUse hook. Reads the hook JSON on stdin; never fails.",
682 " abso mcp",
683 " An MCP server on stdin and stdout: the reading commands and the everyday writing ones as tools, answering with the same text as here. Add it with claude mcp add avcs -- node <repo>/client/avcs.ts mcp.",
684 " avcs --version",
685 " This client's version and commit, and the abso mods installed on this machine.",
686 "",
687 "Every command takes --json. Settings live in .avcs/config.json. The token comes from AVCS_TOKEN, or else ~/.avcs/token.",
688 ].join("\n");
689}
691export interface MainResult {
692 readonly stdout: string;
693 readonly stderr: string;
694 readonly exit: number;
695 /** What --json prints, whether or not it was asked for (abso mcp answers with both). */
696 readonly data?: Record<string, unknown>;
697}
699/** The commands, for abso mcp: each tool is one of them. */
700export function commandTable(): Readonly<
701 Record<string, { readonly flags: FlagSpec; readonly usage: string; readonly about: string }>
702> {
703 return COMMANDS;
704}
706function newsBlock(news: readonly string[]): string[] {
707 return news.length === 0 ? [] : ["News:", ...news.map((n) => ` ${n}`)];
708}
710export async function main(argv: readonly string[], env: Env): Promise<MainResult> {
711 const command = argv[0];
712 const json = argv.includes("--json") && command !== "run" && command !== "logs";
713 if (command === undefined || command === "help" || command === "--help" || command === "-h") {
714 return { stdout: `${help()}\n`, stderr: "", exit: EXIT.ok };
715 }
716 try {
717 if (command === "--version") {
718 // Loaded only here: it runs git, and no other command needs it.
719 const { versionReport } = await import("./install.ts");
720 const { newerCommitNote } = await import("./client-version.ts");
721 const report = versionReport(env.env);
722 const root = findRoot(env.cwd);
723 let behind: string | undefined;
724 if (root) {
725 try {
726 const server = (JSON.parse(readFileSync(configPath(root), "utf8")) as { server?: string }).server;
727 if (server) behind = await newerCommitNote(server);
728 } catch {}
729 }
730 return {
731 stdout: json
732 ? `${JSON.stringify({ ok: true, command: "version", ...report.json, ...(behind ? { serverBehind: behind } : {}) }, null, 2)}\n`
733 : `${report.text}${behind ? `\n${behind}` : ""}\n`,
734 stderr: "",
735 exit: EXIT.ok,
736 };
737 }
738 const def = COMMANDS[command];
739 if (!def)
740 throw new UsageError(
741 `unknown command ${JSON.stringify(command)}; the commands are ${Object.keys(COMMANDS).join(", ")}, hook`,
742 );
743 const parsed = parseArgs(command, argv.slice(1), withBodyFiles(command, def.flags), def.rest);
744 if (bool(parsed, "help")) {
745 const files = bodyFilesHelp(command, def.flags);
746 return { stdout: `${def.usage}\n ${def.about}\n${files ? ` ${files}\n` : ""}`, stderr: "", exit: EXIT.ok };
747 }
748 const args = readBodyFiles(command, parsed, env.cwd, env.readStdin);
749 takeNews(); // what an earlier call in this process left (tests run many)
750 const out = await def.run(args, env);
751 const exit = out.exit ?? EXIT.ok;
752 // Every command that took news while recording prints it (#37, News Report).
753 const news = takeNews();
754 const data = {
755 ok: exit === EXIT.ok,
756 command,
757 ...out.json,
758 ...(news.length > 0 && !("news" in out.json) ? { news } : {}),
759 };
760 if (json || bool(args, "json")) return { stdout: `${JSON.stringify(data, null, 2)}\n`, stderr: "", exit, data };
761 // run, logs and bisect: stdout is the box command's, and may be piped; news goes to stderr there (#37, Builder 3).
762 const boxOut = command === "run" || command === "logs" || command === "bisect";
763 const text = [...(out.text === "" ? [] : [out.text.replace(/\n$/, "")]), ...(boxOut ? [] : newsBlock(news))].join(
764 "\n",
765 );
766 const errText = boxOut && news.length > 0 ? `${newsBlock(news).join("\n")}\n` : "";
767 return { stdout: text === "" ? "" : `${text}\n`, stderr: errText, exit, data };
768 } catch (err) {
769 const e = err as Error;
770 const code = err instanceof UsageError ? "usage" : err instanceof ApiError ? "server" : "error";
771 const message =
772 err instanceof UsageError || err instanceof ApiError ? e.message : `${e.message}${e.stack ? `\n${e.stack}` : ""}`;
773 // The server refusing (409) is like a collision: exit 2, not a failure.
774 const exit = err instanceof ApiError && err.status === 409 ? EXIT.refused : EXIT.error;
775 // News taken before the failure still shows.
776 const news = takeNews();
777 const data = { ok: false, command, error: { code, message }, ...(news.length > 0 ? { news } : {}) };
778 if (json) return { stdout: `${JSON.stringify(data, null, 2)}\n`, stderr: "", exit, data };
779 return {
780 stdout: news.length > 0 ? `${newsBlock(news).join("\n")}\n` : "",
781 stderr: `abso ${command}: ${message}\n`,
782 exit,
783 data,
784 };
785 }
786}