Skip to content

abso-core

Public

abso is version control for agents: the client, the engine and a server you can run on your own Cloudflare account.

Check passed
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=41&format=json
859 linesFirst import 87% · pinch 9% · infra-split 2% · review 1% · devops 1%Last change infra-split in version 37, 20 versions changed it

You're reading version 41. The newest is 318, and 39 versions since then changed this file. Go to the newestCompare with 318

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.
3
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 { newsBlockLines, newsShown, TOKEN_SERVERS } from "./core.ts";
41import { runDraftSync, runLand, runSwitch } from "./drafts.ts";
42import { runExport } from "./export.ts";
43import { runBlame, runWhere, runWho, runWhy } from "./history.ts";
44import { runAnswer, runAsk, runIssue, runIssues, runSearch, runWaiting } from "./issues.ts";
45import { adminToken, issuedPublic, keyList, keyListText, keyNew, keyRevoke } from "./key-admin.ts";
46import { initInOrg, runOrg, runOrgs } from "./orgs.ts";
47import { runUnqueue } from "./queue.ts";
48import { runNote, runNotes, runReview } from "./review.ts";
49import { installSkill, SKILL, skillPath } from "./skill.ts";
50import { runAmend, runDrop, runFollow, runLabel, runLabels, runPluck } from "./versions.ts";
51import { runVisibility } from "./visibility-commands.ts";
53interface CommandDef {
54 readonly flags: FlagSpec;
55 readonly usage: string;
56 readonly about: string;
57 /** Stop reading options at the first word (for `run <command...>`). */
58 readonly rest?: boolean;
59 readonly run: (args: Parsed, env: Env) => Promise<Output>;
62/** The server login, box and logout act on: --server, the folder's, or outside a folder abso.dev's (TOKEN_SERVERS[0]). */
63export function boxServer(args: Parsed, env: Pick<Env, "cwd">): string {
64 const flag = str(args, "server");
65 if (flag) return flag;
66 const root = findRoot(env.cwd);
67 if (!root) return TOKEN_SERVERS[0]!;
68 return (JSON.parse(readFileSync(configPath(root), "utf8")) as { server: string }).server;
71async function runKeyInstall(args: Parsed, env: Env): Promise<Output> {
72 // With --server, the folder is the one named (or here), before it is joined: findRoot
73 // could find a parent agent's folder and pin the key there.
74 const server = str(args, "server");
75 const root = server ? resolve(env.cwd, str(args, "dir") ?? ".") : findRoot(env.cwd);
76 if (!root)
77 throw new UsageError("abso key install runs inside an agent's folder, or takes --server <url> before abso join");
78 const stdin = await new Promise<string>((done, reject) => {
79 const chunks: Buffer[] = [];
80 process.stdin.on("data", (c) => chunks.push(c as Buffer));
81 process.stdin.on("end", () => done(Buffer.concat(chunks).toString("utf8")));
82 process.stdin.on("error", reject);
83 });
84 const { id } = installKey(root, stdin, server);
85 return { text: `Installed agent key ${id}.`, json: { installed: id } };
88const COMMANDS: Readonly<Record<string, CommandDef>> = {
89 init: {
90 flags: { server: "string", project: "string", agent: "string", "as-is": "boolean", org: "string" },
91 usage: "abso init [folder] --server <url> --project <name> --agent <name> [--as-is] [--org <org>]",
92 about:
93 "Create a project on the server from a folder's text files. The folder becomes that agent's folder. It writes a starting .absoignore, 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). --org <org> makes it an organization's project: for now that is done on the website, and abso says where.",
94 run: (args, env) => {
95 const org = str(args, "org");
96 return org === undefined ? runInit(args, env) : initInOrg(org, boxServer(args, env));
97 },
98 },
99 key: {
100 flags: {
101 server: "string",
102 dir: "string",
103 project: "string",
104 agent: "string",
105 expires: "string",
106 role: "string",
107 print: "boolean",
108 },
109 usage:
110 "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>]",
111 about:
112 "install reads {key, id} from stdin into .abso/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 ~/.abso/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.",
113 run: async (args, env) => {
114 const sub = args.positionals[0];
115 if (sub === "install" && args.positionals.length === 1) return runKeyInstall(args, env);
116 const serverFlag = str(args, "server");
117 const root = serverFlag ? resolve(env.cwd, str(args, "dir") ?? ".") : findRoot(env.cwd);
118 if (!root) throw new UsageError("abso key runs inside an agent's folder, or takes --server <url>");
119 let config: ReturnType<typeof readConfig>;
120 try {
121 config = readConfig(root, env.env);
122 } catch {
123 config = {
124 server: serverFlag ?? "",
125 project: str(args, "project") ?? "",
126 agent: "admin",
127 token: readToken(env.env),
128 };
129 }
130 if (serverFlag) config = { ...config, server: serverFlag };
131 const admin = adminToken(env.env);
132 if (sub === "new" && args.positionals.length === 2) {
133 const server = str(args, "server") ?? config.server;
134 const project = str(args, "project") ?? config.project;
135 const expires = str(args, "expires");
136 const role = str(args, "role");
137 if (role !== undefined && role !== "owner" && role !== "writer" && role !== "reader")
138 throw new UsageError("--role is owner, writer or reader");
139 const issued = await keyNew({ ...config, server }, admin, args.positionals[1]!, project, expires, role);
140 const print = bool(args, "print");
141 const shown = issuedPublic(issued, print);
142 if (!print) {
143 const dir = str(args, "server") ? resolve(env.cwd, str(args, "dir") ?? ".") : root;
144 installKey(dir, JSON.stringify({ key: issued.key, id: issued.id }), server);
145 }
146 return {
147 text: print ? `${JSON.stringify({ key: issued.key, id: issued.id })}\n` : `Made ${issued.id}.\n`,
148 json: shown,
149 };
150 }
151 if (sub === "list" && args.positionals.length === 1) {
152 const agent = str(args, "agent");
153 const project = str(args, "project") ?? config.project;
154 const keys = await keyList({ ...config, server: str(args, "server") ?? config.server }, admin, agent, project);
155 return { text: `${keyListText(keys)}\n`, json: { keys } };
156 }
157 if (sub === "revoke" && args.positionals.length === 2) {
158 const project = str(args, "project") ?? config.project;
159 const id = args.positionals[1]!;
160 const revoked = await keyRevoke(
161 { ...config, server: str(args, "server") ?? config.server },
162 admin,
163 id,
164 project,
165 );
166 return { text: revoked ? `Revoked ${id}.\n` : `No key ${id}.\n`, json: { id, revoked } };
167 }
168 throw new UsageError("abso key install | abso key new <agent> | abso key list | abso key revoke <id>");
169 },
170 },
171 login: {
172 flags: { server: "string" },
173 usage: "abso login [--server <url>]",
174 about:
175 "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, or https://api.abso.dev outside a folder.",
176 run: async (args, env) => {
177 const server = boxServer(args, env);
178 const record = await login(server, { say: (line) => process.stderr.write(`${line}\n`) });
179 return {
180 text: `This box is signed in. ${boxText(record, server).split("\n").slice(1).join(" ")}`,
181 json: { box: boxPublic(record) },
182 };
183 },
184 },
185 box: {
186 flags: { server: "string" },
187 usage: "abso box [--server <url>]",
188 about:
189 "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.",
190 run: async (args, env) => {
191 const server = boxServer(args, env);
192 const record = readBox(server);
193 return { text: boxText(record, server), json: { box: boxPublic(record) } };
194 },
195 },
196 logout: {
197 flags: { server: "string" },
198 usage: "abso logout [--server <url>]",
199 about:
200 "End this box's sign-in on the server and forget it here. Keys its agents already have stop working with it.",
201 run: async (args, env) => {
202 const server = boxServer(args, env);
203 const record = readBox(server);
204 if (!record) return { text: `This box isn't signed in to ${server}.`, json: { loggedOut: false } };
205 const ended = await logout(record);
206 return {
207 text: ended
208 ? `Signed this box out of ${record.server}.`
209 : `Forgot this box's sign-in here, but ${record.server} couldn't be reached to end it. Revoke the box on the website.`,
210 json: { loggedOut: true, ended },
211 };
212 },
213 },
214 orgs: {
215 flags: { server: "string" },
216 usage: "abso orgs [--server <url>]",
217 about:
218 "Your organizations and your role in each, and invitations waiting for you. It reads as the person who approved this box's sign-in (abso login).",
219 run: (args, env) => runOrgs(boxServer(args, env)),
220 },
221 org: {
222 flags: {
223 server: "string",
224 name: "string",
225 invite: "string",
226 as: "string",
227 role: "string",
228 remove: "string",
229 leave: "boolean",
230 members: "string",
231 "projects-by": "string",
232 },
233 usage:
234 "abso org <name> [--invite <person>|link [--as owner] | --role <person>=owner|member | --remove <person> | --leave | --members read|write | --projects-by members|owners] | abso org new <name> [--name <shown name>]",
235 about:
236 "An organization: its projects, people, open invites and settings, as the person who approved this box's sign-in sees them (people and settings only to members). One change at a time. Changes and abso org new are made on the website for now, and abso says where.",
237 run: (args, env) => runOrg(args, boxServer(args, env)),
238 },
239 skill: {
240 flags: { dir: "string" },
241 usage: "abso skill install [--dir <skills folder>] | abso skill show",
242 about:
243 "The abso skill for Claude Code: how to work in an abso folder, and what never to share. install writes it to ~/.claude/skills/abso/SKILL.md (--dir names another skills folder) and changes no settings; run it again after updating abso. show prints it.",
244 run: async (args, env) => {
245 const [verb, ...more] = args.positionals;
246 if (verb === "show" && more.length === 0) return { text: SKILL, json: { skill: SKILL } };
247 if (verb !== "install" || more.length > 0)
248 throw new UsageError("abso skill install [--dir <skills folder>] | abso skill show");
249 const path = skillPath(str(args, "dir"), env.cwd);
250 const done = installSkill(path);
251 const said = { installed: "Installed", updated: "Updated", current: "Already current:" }[done];
252 return {
253 text: `${said} the abso skill at ${path}. New Claude Code sessions load it.`,
254 json: { path, done },
255 };
256 },
257 },
258 join: {
259 flags: { server: "string", agent: "string", dir: "string", reader: "boolean" },
260 usage: "abso join <project> --agent <name> --server <url> [--dir <folder>] [--reader]",
261 about:
262 "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.",
263 run: runJoin,
264 },
265 record: {
266 flags: { all: "boolean", binary: "string" },
267 usage: "abso record [--all]",
268 about:
269 "Send every file that changed since the server last heard about it (--all: every file). For edits the hook did not see.",
270 run: runRecord,
271 },
272 publish: {
273 flags: {
274 message: "string",
275 binary: "string",
276 "as-is": "boolean",
277 check: "optional",
278 box: "string",
279 wait: "string",
280 "no-wait": "boolean",
281 done: "boolean",
282 },
283 usage: 'abso publish -m "<why>" [--as-is] [--check ["<command>"]] [--wait <seconds> | --no-wait] [--done]',
284 about:
285 '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.',
286 run: runPublish,
287 },
288 bisect: {
289 flags: { good: "string", bad: "string", box: "string" },
290 usage: "abso bisect [--good <version>] [--bad <version>] -- <program> <arg...>",
291 about:
292 "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.",
293 rest: true,
294 run: runBisect,
295 },
296 reader: {
297 flags: {},
298 usage: "abso reader on|off",
299 about:
300 "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.",
301 run: runReader,
302 },
303 settle: {
304 flags: { yours: "boolean", theirs: "boolean", both: "boolean" },
305 usage: "abso settle <file...> --yours|--theirs|--both",
306 about:
307 "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.",
308 run: runSettle,
309 },
310 sync: {
311 flags: { verbose: "boolean", full: "boolean" },
312 usage: "abso sync [--full]",
313 about:
314 "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.",
315 run: runSync,
316 },
317 run: {
318 flags: {
319 detach: "boolean",
320 replace: "boolean",
321 fresh: "boolean",
322 parallel: "boolean",
323 at: "string",
324 files: "string",
325 fetch: "string",
326 box: "string",
327 with: "string",
328 quiet: "boolean",
329 },
330 usage:
331 'abso run [--detach] [--replace] [--fresh] [--box <name>] [--at <version> [--files <glob>]] <command...> | abso run ... -- <program> <arg...> | abso run --parallel "<command>" "<command>"...',
332 about:
333 "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). abso'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.",
334 rest: true,
335 run: runRun,
336 },
337 serve: {
338 flags: { version: "string", build: "string", out: "string" },
339 usage: 'abso serve [--version <n>] [--build "<command>"] [--out <folder>]',
340 about:
341 "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.",
342 run: runServe,
343 },
344 mv: {
345 flags: {},
346 usage: "abso mv <from> <to>",
347 about:
348 "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 abso, 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.",
349 run: runMv,
350 },
351 review: {
352 flags: { since: "string" },
353 usage: "abso review [<id> | v<version> | <agent>] [--since <position|2h>]",
354 about:
355 "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.",
356 run: runReview,
357 },
358 note: {
359 flags: {
360 object: "boolean",
361 read: "boolean",
362 draft: "string",
363 at: "string",
364 reply: "string",
365 close: "string",
366 resolved: "boolean",
367 withdrawn: "boolean",
368 },
369 usage:
370 'abso note <file>:<line>[-<line>] "<text>" [--object | --read] [--draft <agent> | --at <version>] | abso note --reply <id> "<text>" | abso note --close <id> --resolved|--withdrawn',
371 about:
372 "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.",
373 run: runNote,
374 },
375 notes: {
376 flags: { change: "string", all: "boolean" },
377 usage: "abso notes [file] [--change <id>] [--all]",
378 about:
379 "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.",
380 run: runNotes,
381 },
382 issues: {
383 flags: {
384 open: "boolean",
385 status: "string",
386 agent: "string",
387 parent: "string",
388 label: "string",
389 labels: "boolean",
390 drafts: "boolean",
391 },
392 usage:
393 "abso issues [--open] [--status <status>] [--agent <agent>] [--parent <N>] [--label <l,l>] | abso issues --labels",
394 about:
395 "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: abso 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.",
396 run: runIssues,
397 },
398 issue: {
399 flags: {
400 comment: "string",
401 object: "string",
402 drop: "boolean",
403 reopen: "boolean",
404 done: "boolean",
405 "done-by": "string",
406 title: "string",
407 description: "string",
408 parent: "string",
409 lines: "string",
410 agent: "string",
411 "blocked-by": "string",
412 notify: "string",
413 quiet: "boolean",
414 label: "string",
415 unlabel: "string",
416 open: "boolean",
417 delete: "boolean",
418 attach: "string",
419 "copy-to": "string",
420 clean: "string",
421 "dry-run": "boolean",
422 "save-attachments": "string",
423 },
424 usage:
425 'abso issue <N> --save-attachments <folder> | abso issue <N> --copy-to <project> [--clean <file>] [--dry-run] | abso issue <N> [--comment "..." [--attach <file,file>] | --object "..." | --drop | --reopen | --done [--done-by <version>]] | abso 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] | abso issue new "<title>" [--description "..."] [--parent <N>] [--lines <file>:<from>-<to>@<version>] [--agent <agent>] [--blocked-by <N,N>] [--notify <who,who>] [--label <l,l>] [--attach <file,file>]',
426 about:
427 "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. abso 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. --attach shot.png,after.png puts images on a new issue or a comment (png, jpeg, gif or webp, 10 MB each; the server checks the type by the bytes and takes out metadata such as where a photo was taken. An svg, up to 1 MB, is drawn as a png, and its own file is kept as a download, on servers that take svg), and prints each one's id for the text to point at; the issue's page lists them with a link, and --save-attachments <folder> saves every one on the issue and its comments there as <id>-<name> (an svg's own file too), outside the abso folder or where abso leaves files out. --copy-to <project> copies the issue into another project, with its comments, answered asks and labels, each keeping its author and time; --dry-run shows what would go and writes nothing, and --clean <file> gives cleaned texts by source id as JSON ({title, description, comments: [{id, text}], asks: [{id, question, answer}]}; a comment left out of a given list isn't copied). Copying out of a project on a live server takes an owner of that project. abso issue draft \"<title>\" [the same fields] saves a draft instead: yours alone, with no number and no news; abso issue draft <D> [fields] changes it, --open opens it as an issue, --delete deletes it.",
428 run: runIssue,
429 },
430 ask: {
431 flags: {
432 issue: "string",
433 review: "boolean",
434 task: "boolean",
435 due: "string",
436 blocks: "string",
437 options: "string",
438 withdraw: "string",
439 note: "string",
440 attach: "string",
441 },
442 usage:
443 'abso ask <who> "<question>" [--issue <N>] [--review | --task] [--due <YYYY-MM-DD>] [--blocks <N,N>] [--options "A|B|C"] [--attach <file,file>] | abso ask --withdraw <ask> [--note "why"]',
444 about:
445 "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. --attach sends files with the question, as on an issue. --withdraw takes back an ask you made that no longer needs an answer: it leaves their waiting list, stops holding the issue, keeps your --note as why, and they hear it.",
446 run: runAsk,
447 },
448 search: {
449 flags: { limit: "string" },
450 usage: 'abso search "<words>" [--limit <N>]',
451 about:
452 "The project's issues that match, best first: by their words, and by what they mean where the server has meaning search on, so an issue worded differently from your search still turns up. #N or N puts issue N first. Each hit says where it matched; one only meaning search found says by meaning.",
453 run: runSearch,
454 },
455 waiting: {
456 flags: { of: "string", mine: "boolean" },
457 usage: "abso waiting [--of <agent or person:id>] [--mine]",
458 about:
459 "The open asks, soonest due first: every one, those of someone (--of), or those of you (--mine). --mine also lists your publishes still in the merge queue and where each stands; the outcome comes as news.",
460 run: runWaiting,
461 },
462 answer: {
463 flags: { option: "string", note: "string", done: "boolean", attach: "string" },
464 usage:
465 'abso answer <ask> "<words>" | abso answer <ask> --option <N> [--note "..."] | abso answer <ask> --done [--note "..."], each with [--attach <file,file>]',
466 about:
467 "Answer an ask of you, in your own words, by picking an option (by number or text), or, for a task, with --done. --attach sends files with the answer. The asker hears it.",
468 run: runAnswer,
469 },
470 unqueue: {
471 flags: {},
472 usage: "abso unqueue",
473 about:
474 "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).",
475 run: runUnqueue,
476 },
477 visibility: {
478 flags: { yes: "boolean" },
479 usage: "abso visibility [public|private] [--yes]",
480 about:
481 "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).",
482 run: runVisibility,
483 },
484 ci: {
485 flags: { version: "string", revoke: "boolean" },
486 usage: "abso ci [<version>] | abso ci --revoke",
487 about:
488 "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.",
489 run: runCi,
490 },
491 shot: {
492 flags: {
493 out: "string",
494 wait: "string",
495 size: "string",
496 box: "string",
497 eval: "string",
498 click: "string",
499 mouse: "string",
500 at: "string",
501 scale: "string",
502 region: "string",
503 text: "boolean",
504 tree: "boolean",
505 interactive: "boolean",
506 depth: "string",
507 find: "string",
508 "max-chars": "string",
509 image: "boolean",
510 },
511 usage:
512 '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>]',
513 about:
514 "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.",
515 run: runShot,
516 },
517 prep: {
518 flags: { forget: "boolean", box: "string" },
519 usage: 'abso prep [--box <name>] "<setup command>" | abso prep --forget',
520 about:
521 "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.",
522 rest: true,
523 run: runPrep,
524 },
525 fetch: {
526 flags: { box: "string" },
527 usage: "abso fetch [--box <name>] <glob...>",
528 about:
529 "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.",
530 run: runFetch,
531 },
532 pause: {
533 flags: {},
534 usage: "abso pause",
535 about:
536 "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).",
537 run: runPause,
538 },
539 resume: {
540 flags: {},
541 usage: "abso resume",
542 about: "End abso pause. Changes made while paused go at the next record.",
543 run: runResume,
544 },
545 logs: {
546 flags: { box: "string" },
547 usage: "abso logs [--box <name>] <run id>",
548 about:
549 "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.",
550 run: runLogs,
551 },
552 status: {
553 flags: { short: "boolean" },
554 usage: "abso status [--short]",
555 about:
556 "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.",
557 run: runStatus,
558 },
559 switch: {
560 flags: { carry: "boolean", verbose: "boolean" },
561 usage: "abso switch <draft> | abso switch -c <new draft> | abso switch shared",
562 about:
563 "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.",
564 run: runSwitch,
565 },
566 land: {
567 flags: { message: "string" },
568 usage: 'abso land -m "<why>"',
569 about:
570 "Land your named draft in shared, as one unit. Refused only on a collision with work that landed in shared since the draft began.",
571 run: runLand,
572 },
573 "draft-sync": {
574 flags: {},
575 usage: "abso draft-sync",
576 about: "Move your named draft onto shared's newest version, then bring that into this folder.",
577 run: runDraftSync,
578 },
579 diff: {
580 flags: { draft: "string" },
581 usage: "abso diff [file...] | abso diff <from> <to> [file...] [--draft <name>]",
582 about:
583 "Your unpublished changes, line by line, as git prints them (records first). With two versions: what changed between them in this space.",
584 run: runDiff,
585 },
586 restore: {
587 flags: { all: "boolean" },
588 usage: "abso restore <file...> | abso restore <file>:<line>[-<line>] | abso restore --all",
589 about:
590 "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.",
591 run: runRestore,
592 },
593 export: {
594 flags: { version: "string", keep: "string" },
595 usage: "abso export <dir> [--version <N>] [--keep <glob>]",
596 about:
597 "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 .absoignore leaves out; .avcs-export.json there names the version.",
598 run: runExport,
599 },
600 files: {
601 flags: { draft: "string", version: "string" },
602 usage: "abso files [glob...] [--draft <name>] [--version <N>]",
603 about:
604 "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).",
605 run: runFiles,
606 },
607 log: {
608 flags: { limit: "string", before: "string", draft: "string", since: "string", by: "string", count: "boolean" },
609 usage:
610 "abso log [file] [-n <count>] [--before <version>] [--draft <name>] [--since <version|30m|2h|1d|date>] [--by <agent,...>] [--count]",
611 about:
612 "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. --before <version> starts below that version, so any stretch of history can be listed; the end of the list names the --before for the next older ones. --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.",
613 run: runLog,
614 },
615 show: {
616 flags: { draft: "string" },
617 usage: "abso show <version> | abso show <version>:<file> [--draft <name>]",
618 about: "One version: who published it, why, and its diff. With :<file>, that file's text as it was then.",
619 run: runShow,
620 },
621 announce: {
622 flags: { to: "string" },
623 usage: "abso announce [--to <agent,agent>] <text>",
624 about:
625 "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.",
626 run: runAnnounce,
627 },
628 start: {
629 flags: { done: "boolean", issue: "string" },
630 usage: 'abso start "<what>" [files...] [--issue <n>] | abso start --done',
631 about:
632 "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.",
633 run: runStart,
634 },
635 news: {
636 flags: {},
637 usage: "abso news",
638 about:
639 "The news waiting for you: collisions, changed definitions, moved lines and announcements. Each item comes once.",
640 run: runNews,
641 },
642 "fix-eol": {
643 flags: {},
644 usage: "abso fix-eol",
645 about:
646 "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.",
647 run: runFixEol,
648 },
649 who: {
650 flags: {},
651 usage: "abso who <file...>",
652 about:
653 "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.",
654 run: runWho,
655 },
656 where: {
657 flags: {},
658 usage: "abso where",
659 about: "Who is working where: each file with unpublished changes, whose they are, and which lines.",
660 run: runWhere,
661 },
662 blame: {
663 flags: { from: "string", to: "string", version: "string", draft: "string", mine: "boolean" },
664 usage: "abso blame <file> [--from <n>] [--to <n>] [--version <n>] [--draft <name> | --mine]",
665 about:
666 "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 *.",
667 run: runBlame,
668 },
669 why: {
670 flags: { draft: "string", mine: "boolean" },
671 usage: "abso why <file>:<line> [--draft <name> | --mine]",
672 about:
673 "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.",
674 run: runWhy,
675 },
676 drop: {
677 flags: { message: "string", "with-dependents": "boolean" },
678 usage: 'abso drop <version...> -m "<why>" [--with-dependents]',
679 about:
680 "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.",
681 run: runDrop,
682 },
683 pluck: {
684 flags: { message: "string", "with-dependencies": "boolean" },
685 usage: 'abso pluck <draft> <version...> -m "<why>" [--with-dependencies]',
686 about:
687 "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.",
688 run: runPluck,
689 },
690 amend: {
691 flags: { message: "string" },
692 usage: 'abso amend -m "<new message>"',
693 about:
694 "Correct the message of your newest publish in this space. Only the message changes; the log keeps the original.",
695 run: runAmend,
696 },
697 label: {
698 flags: { version: "string", remove: "boolean" },
699 usage: "abso label <name> [--version <n>] [--remove]",
700 about:
701 "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.",
702 run: runLabel,
703 },
704 labels: {
705 flags: {},
706 usage: "abso labels",
707 about: "Every label and the versions it marks.",
708 run: runLabels,
709 },
710 follow: {
711 flags: { none: "boolean" },
712 usage: "abso follow <label> | abso follow --none",
713 about:
714 "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.",
715 run: runFollow,
716 },
717 "check-ignore": {
718 flags: {},
719 usage: "abso check-ignore <path...>",
720 about:
721 "Whether abso leaves each path out, and which line of which ignore file decided (git's rules, for .gitignore and .absoignore).",
722 run: runCheckIgnore,
723 },
724 pipeline: {
725 flags: { on: "string", space: "string", pipeline: "string", every: "string" },
726 usage:
727 "abso pipeline check [file] [--on publish|draft|green|land|hand|schedule [--space <name>] [--pipeline <name>] [--every <when>]]",
728 about:
729 "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.",
730 // Loaded only here, so the yaml package it needs can't stop every other command
731 // when a checkout lacks it (abso issue 168).
732 run: async (args, env) => {
733 let mod: typeof import("./pipeline-commands.ts");
734 try {
735 mod = await import("./pipeline-commands.ts");
736 } catch (e) {
737 if ((e as { code?: string }).code === "ERR_MODULE_NOT_FOUND")
738 throw new UsageError(
739 `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`,
740 );
741 throw e;
742 }
743 return mod.runPipeline(args, env);
744 },
745 },
746};
748function help(): string {
749 return [
750 "abso: version control for agents. This is its command-line client.",
751 "",
752 ...Object.values(COMMANDS).flatMap((c) => [` ${c.usage}`, ` ${c.about}`]),
753 " abso hook",
754 " The Claude Code PostToolUse hook. Reads the hook JSON on stdin; never fails.",
755 " abso mcp",
756 " 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 abso -- node <repo>/client/abso.ts mcp.",
757 " abso --version",
758 " This client's version and commit, and the abso mods installed on this machine.",
759 "",
760 "Every command takes --json. Settings live in .abso/config.json (.avcs/config.json in a folder from before the rename). The token comes from ABSO_TOKEN, or else ~/.abso/token (or ~/.avcs/token from before).",
761 ].join("\n");
764export interface MainResult {
765 readonly stdout: string;
766 readonly stderr: string;
767 readonly exit: number;
768 /** What --json prints, whether or not it was asked for (abso mcp answers with both). */
769 readonly data?: Record<string, unknown>;
772/** The commands, for abso mcp: each tool is one of them. */
773export function commandTable(): Readonly<
774 Record<string, { readonly flags: FlagSpec; readonly usage: string; readonly about: string }>
775> {
776 return COMMANDS;
779function newsBlock(news: readonly string[]): string[] {
780 return newsBlockLines(news.map((n) => newsShown(n)));
783export async function main(argv: readonly string[], env: Env): Promise<MainResult> {
784 const command = argv[0];
785 const json = argv.includes("--json") && command !== "run" && command !== "logs";
786 if (command === undefined || command === "help" || command === "--help" || command === "-h") {
787 return { stdout: `${help()}\n`, stderr: "", exit: EXIT.ok };
788 }
789 try {
790 if (command === "--version") {
791 // Loaded only here: it runs git, and no other command needs it.
792 const { versionReport } = await import("./install.ts");
793 const { newerCommitNote } = await import("./client-version.ts");
794 const report = versionReport(env.env);
795 const root = findRoot(env.cwd);
796 let behind: string | undefined;
797 if (root) {
798 try {
799 const server = (JSON.parse(readFileSync(configPath(root), "utf8")) as { server?: string }).server;
800 if (server) behind = await newerCommitNote(server);
801 } catch {}
802 }
803 return {
804 stdout: json
805 ? `${JSON.stringify({ ok: true, command: "version", ...report.json, ...(behind ? { serverBehind: behind } : {}) }, null, 2)}\n`
806 : `${report.text}${behind ? `\n${behind}` : ""}\n`,
807 stderr: "",
808 exit: EXIT.ok,
809 };
810 }
811 const def = COMMANDS[command];
812 if (!def)
813 throw new UsageError(
814 `unknown command ${JSON.stringify(command)}; the commands are ${Object.keys(COMMANDS).join(", ")}, hook`,
815 );
816 const parsed = parseArgs(command, argv.slice(1), withBodyFiles(command, def.flags), def.rest);
817 if (bool(parsed, "help")) {
818 const files = bodyFilesHelp(command, def.flags);
819 return { stdout: `${def.usage}\n ${def.about}\n${files ? ` ${files}\n` : ""}`, stderr: "", exit: EXIT.ok };
820 }
821 const args = readBodyFiles(command, parsed, env.cwd, env.readStdin);
822 takeNews(); // what an earlier call in this process left (tests run many)
823 const out = await def.run(args, env);
824 const exit = out.exit ?? EXIT.ok;
825 // Every command that took news while recording prints it (#37, News Report).
826 const news = takeNews();
827 const data = {
828 ok: exit === EXIT.ok,
829 command,
830 ...out.json,
831 ...(news.length > 0 && !("news" in out.json) ? { news } : {}),
832 };
833 if (json || bool(args, "json")) return { stdout: `${JSON.stringify(data, null, 2)}\n`, stderr: "", exit, data };
834 // run, logs and bisect: stdout is the box command's, and may be piped; news goes to stderr there (#37).
835 const boxOut = command === "run" || command === "logs" || command === "bisect";
836 const text = [...(out.text === "" ? [] : [out.text.replace(/\n$/, "")]), ...(boxOut ? [] : newsBlock(news))].join(
837 "\n",
838 );
839 const errText = boxOut && news.length > 0 ? `${newsBlock(news).join("\n")}\n` : "";
840 return { stdout: text === "" ? "" : `${text}\n`, stderr: errText, exit, data };
841 } catch (err) {
842 const e = err as Error;
843 const code = err instanceof UsageError ? "usage" : err instanceof ApiError ? "server" : "error";
844 const message =
845 err instanceof UsageError || err instanceof ApiError ? e.message : `${e.message}${e.stack ? `\n${e.stack}` : ""}`;
846 // The server refusing (409) is like a collision: exit 2, not a failure.
847 const exit = err instanceof ApiError && err.status === 409 ? EXIT.refused : EXIT.error;
848 // News taken before the failure still shows.
849 const news = takeNews();
850 const data = { ok: false, command, error: { code, message }, ...(news.length > 0 ? { news } : {}) };
851 if (json) return { stdout: `${JSON.stringify(data, null, 2)}\n`, stderr: "", exit, data };
852 return {
853 stdout: news.length > 0 ? `${newsBlock(news).join("\n")}\n` : "",
854 stderr: `abso ${command}: ${message}\n`,
855 exit,
856 data,
857 };
858 }