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=155&format=json
1,021 linesFirst import 68% · pinch 15% · speed 9% · rename 5% · infra-split 1% · codex-mac-1 1% · Last change speed in version 155, 40 versions changed it

You're reading version 155. The newest is 318, and 19 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, loginRequest, 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 { clientVersion } from "./client-version.ts";
15import {
16 type Env,
17 EXIT,
18 type Output,
19 runBisect,
20 runFetch,
21 runFixEol,
22 runInit,
23 runJoin,
24 runLogs,
25 runMv,
26 runPause,
27 runPrep,
28 runPublish,
29 runReader,
30 runRecord,
31 runResume,
32 runRun,
33 runServe,
34 runSettle,
35 runShot,
36 runStatus,
37 runSync,
38 takeNews,
39} from "./commands.ts";
40import { configPath, findRoot, installKey, isVisitor, readConfig, readToken } from "./config.ts";
41import { newsBlockLines, newsShown, TOKEN_SERVERS } from "./core.ts";
42import { checkServer, doctor, doctorText, plainError, realProbe, whoami } from "./doctor.ts";
43import { runDraftSync, runLand, runSwitch } from "./drafts.ts";
44import { runExport } from "./export.ts";
45import { runBlame, runWhere, runWho, runWhy } from "./history.ts";
46import { runAck, runAnswer, runAsk, runIssue, runIssues, runReply, runSearch, runWaiting } from "./issues.ts";
47import { adminToken, issuedPublic, keyList, keyListText, keyNew, keyRevoke } from "./key-admin.ts";
48import { browserSkip, openInBrowser } from "./open-browser.ts";
49import { initInOrg, runOrg, runOrgs } from "./orgs.ts";
50import { runUnqueue } from "./queue.ts";
51import { runNote, runNotes, runReview } from "./review.ts";
52import { checkFolderServer, localRefusal, serverFlag, serverHelp, serverUse } from "./server-choice.ts";
53import { installSkill, SKILL, skillPath } from "./skill.ts";
54import { colorsPass, terminalText } from "./terminal-text.ts";
55import { runAmend, runDrop, runFollow, runLabel, runLabels, runPluck } from "./versions.ts";
56import { runVisibility } from "./visibility-commands.ts";
57import { checkVisitor } from "./visitor.ts";
59interface CommandDef {
60 readonly flags: FlagSpec;
61 readonly usage: string;
62 readonly about: string;
63 /** Stop reading options at the first word (for `run <command...>`). */
64 readonly rest?: boolean;
65 readonly run: (args: Parsed, env: Env) => Promise<Output>;
68/** The server login, box and logout act on: --server, the folder's, or outside a folder abso.dev's (TOKEN_SERVERS[0]). */
69export function boxServer(args: Parsed, env: Pick<Env, "cwd">): string {
70 const flag = str(args, "server");
71 if (flag) return flag;
72 const root = findRoot(env.cwd);
73 if (!root) return TOKEN_SERVERS[0]!;
74 return (JSON.parse(readFileSync(configPath(root), "utf8")) as { server: string }).server;
77async function runKeyInstall(args: Parsed, env: Env): Promise<Output> {
78 // With --server, the folder is the one named (or here), before it is joined: findRoot
79 // could find a parent agent's folder and pin the key there.
80 const server = str(args, "server");
81 const root = server ? resolve(env.cwd, str(args, "dir") ?? ".") : findRoot(env.cwd);
82 if (!root)
83 throw new UsageError("abso key install runs inside an agent's folder, or takes --server <url> before abso join");
84 const stdin = await new Promise<string>((done, reject) => {
85 const chunks: Buffer[] = [];
86 process.stdin.on("data", (c) => chunks.push(c as Buffer));
87 process.stdin.on("end", () => done(Buffer.concat(chunks).toString("utf8")));
88 process.stdin.on("error", reject);
89 });
90 const { id } = installKey(root, stdin, server);
91 return { text: `Installed agent key ${id}.`, json: { installed: id } };
94const COMMANDS: Readonly<Record<string, CommandDef>> = {
95 init: {
96 flags: { server: "string", project: "string", agent: "string", "as-is": "boolean", org: "string" },
97 usage: "abso init [folder] --project <name> --agent <name> [--as-is] [--org <org>]",
98 about:
99 "Create a project on the server from a folder's text files (the server is chosen as abso join chooses it). 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.",
100 run: (args, env) => {
101 const org = str(args, "org");
102 return org === undefined ? runInit(args, env) : initInOrg(org, boxServer(args, env));
103 },
104 },
105 key: {
106 flags: {
107 server: "string",
108 dir: "string",
109 project: "string",
110 agent: "string",
111 expires: "string",
112 role: "string",
113 print: "boolean",
114 },
115 usage:
116 "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>]",
117 about:
118 "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.",
119 run: async (args, env) => {
120 const sub = args.positionals[0];
121 if (sub === "install" && args.positionals.length === 1) return runKeyInstall(args, env);
122 const serverFlag = str(args, "server");
123 const root = serverFlag ? resolve(env.cwd, str(args, "dir") ?? ".") : findRoot(env.cwd);
124 if (!root) throw new UsageError("abso key runs inside an agent's folder, or takes --server <url>");
125 let config: ReturnType<typeof readConfig>;
126 try {
127 config = readConfig(root, env.env);
128 } catch {
129 config = {
130 server: serverFlag ?? "",
131 project: str(args, "project") ?? "",
132 agent: "admin",
133 token: readToken(env.env),
134 };
135 }
136 if (serverFlag) config = { ...config, server: serverFlag };
137 const admin = adminToken(env.env);
138 if (sub === "new" && args.positionals.length === 2) {
139 const server = str(args, "server") ?? config.server;
140 const project = str(args, "project") ?? config.project;
141 const expires = str(args, "expires");
142 const role = str(args, "role");
143 if (role !== undefined && role !== "owner" && role !== "writer" && role !== "reader")
144 throw new UsageError("--role is owner, writer or reader");
145 const issued = await keyNew({ ...config, server }, admin, args.positionals[1]!, project, expires, role);
146 const print = bool(args, "print");
147 const shown = issuedPublic(issued, print);
148 if (!print) {
149 const dir = str(args, "server") ? resolve(env.cwd, str(args, "dir") ?? ".") : root;
150 installKey(dir, JSON.stringify({ key: issued.key, id: issued.id }), server);
151 }
152 return {
153 text: print ? `${JSON.stringify({ key: issued.key, id: issued.id })}\n` : `Made ${issued.id}.\n`,
154 json: shown,
155 };
156 }
157 if (sub === "list" && args.positionals.length === 1) {
158 const agent = str(args, "agent");
159 const project = str(args, "project") ?? config.project;
160 const keys = await keyList({ ...config, server: str(args, "server") ?? config.server }, admin, agent, project);
161 return { text: `${keyListText(keys)}\n`, json: { keys } };
162 }
163 if (sub === "revoke" && args.positionals.length === 2) {
164 const project = str(args, "project") ?? config.project;
165 const id = args.positionals[1]!;
166 const revoked = await keyRevoke(
167 { ...config, server: str(args, "server") ?? config.server },
168 admin,
169 id,
170 project,
171 );
172 return { text: revoked ? `Revoked ${id}.\n` : `No key ${id}.\n`, json: { id, revoked } };
173 }
174 throw new UsageError("abso key install | abso key new <agent> | abso key list | abso key revoke <id>");
175 },
176 },
177 login: {
178 flags: {
179 server: "string",
180 "no-browser": "boolean",
181 projects: "string",
182 role: "string",
183 "max-agents": "string",
184 days: "string",
185 },
186 usage:
187 "abso login [--no-browser] [--projects <name,name>] [--role <reader|writer|owner>] [--max-agents <1-50>] [--days <1-90>]",
188 about:
189 "Sign this box in once: it opens the approve page in your browser with the code filled in, prints the link and the code too, 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. No browser opens with --no-browser or ABSO_NO_BROWSER, over SSH, under CI, or on Linux without a display.",
190 run: async (args, env) => {
191 const server = boxServer(args, env);
192 const open =
193 bool(args, "no-browser") || browserSkip(env.env, process.platform) !== null
194 ? undefined
195 : (url: string) => openInBrowser(url);
196 const record = await login(server, {
197 request: loginRequest(args),
198 say: (line) => process.stderr.write(terminalText(`${line}\n`, colorsPass(process.stderr, env.env))),
199 open,
200 });
201 return {
202 text: `This box is signed in. ${boxText(record, server).split("\n").slice(1).join(" ")}`,
203 json: { box: boxPublic(record) },
204 };
205 },
206 },
207 box: {
208 flags: { server: "string" },
209 usage: "abso box",
210 about:
211 "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.",
212 run: async (args, env) => {
213 const server = boxServer(args, env);
214 const record = readBox(server);
215 return { text: boxText(record, server), json: { box: boxPublic(record) } };
216 },
217 },
218 whoami: {
219 flags: { server: "string" },
220 usage: "abso whoami",
221 about:
222 "Who and where you're signed in: this box's sign-in, as the server sees it (so a revoked one shows), its projects, roles and expiry, and this folder's project, agent and kind of key. Never a credential. The server is --server, else ABSO_SERVER, else this folder's, else the one this box signed in to with abso login, else https://api.abso.dev.",
223 run: async (args, env) => {
224 const out = await whoami(checkServer(str(args, "server"), env.cwd, env.env), env.cwd, env.env, realProbe());
225 return { text: out.text, json: out.json };
226 },
227 },
228 doctor: {
229 flags: { server: "string" },
230 usage: "abso doctor",
231 about:
232 "Checks what commands need, one line each: Node's version, that the server answers, this box's sign-in (present, unexpired, accepted), and this folder's key against its project. A failed check says what to do next, and the exit is 1. Never prints a credential. It picks the server as whoami does.",
233 run: async (args, env) => {
234 const checks = await doctor(
235 checkServer(str(args, "server"), env.cwd, env.env),
236 env.cwd,
237 env.env,
238 realProbe(),
239 str(args, "server") !== undefined,
240 );
241 const failed = checks.some((c) => c.result === "fail");
242 return { text: doctorText(checks), json: { checks }, ...(failed ? { exit: EXIT.error } : {}) };
243 },
244 },
245 logout: {
246 flags: { server: "string" },
247 usage: "abso logout",
248 about:
249 "End this box's sign-in on the server and forget it here. Keys its agents already have stop working with it.",
250 run: async (args, env) => {
251 const server = boxServer(args, env);
252 const record = readBox(server);
253 if (!record) return { text: `This box isn't signed in to ${server}.`, json: { loggedOut: false } };
254 const ended = await logout(record);
255 return {
256 text: ended
257 ? `Signed this box out of ${record.server}.`
258 : `Forgot this box's sign-in here, but ${record.server} couldn't be reached to end it. Revoke the box on the website.`,
259 json: { loggedOut: true, ended },
260 };
261 },
262 },
263 orgs: {
264 flags: { server: "string" },
265 usage: "abso orgs",
266 about:
267 "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).",
268 run: (args, env) => runOrgs(boxServer(args, env)),
269 },
270 org: {
271 flags: {
272 server: "string",
273 name: "string",
274 invite: "string",
275 as: "string",
276 role: "string",
277 remove: "string",
278 leave: "boolean",
279 members: "string",
280 "projects-by": "string",
281 },
282 usage:
283 "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>]",
284 about:
285 "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.",
286 run: (args, env) => runOrg(args, boxServer(args, env)),
287 },
288 skill: {
289 flags: { dir: "string" },
290 usage: "abso skill install [--dir <skills folder>] | abso skill show",
291 about:
292 "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.",
293 run: async (args, env) => {
294 const [verb, ...more] = args.positionals;
295 if (verb === "show" && more.length === 0) return { text: SKILL, json: { skill: SKILL } };
296 if (verb !== "install" || more.length > 0)
297 throw new UsageError("abso skill install [--dir <skills folder>] | abso skill show");
298 const path = skillPath(str(args, "dir"), env.cwd);
299 const done = installSkill(path);
300 const said = { installed: "Installed", updated: "Updated", current: "Already current:" }[done];
301 return {
302 text: `${said} the abso skill at ${path}. New Claude Code sessions load it.`,
303 json: { path, done },
304 };
305 },
306 },
307 join: {
308 flags: { server: "string", agent: "string", dir: "string", reader: "boolean" },
309 usage: "abso join <project> [--agent <name>] [--dir <folder>] [--reader]",
310 about:
311 "Join a project as a new agent and write its shared files into a folder: --dir, else here when this folder is empty, else ./<project> (which has to be new or empty). Without --agent the agent is named after this box (the name abso login gave it, lower-cased), or the next free <name>-2, <name>-3; that needs the box signed in with abso login. The server is --server, else ABSO_SERVER, else the one this box signed in to with abso login, else https://api.abso.dev. --reader joins as a reader: it reads everything and records nothing, and the server refuses its edits, records and pushes. With --reader and no sign-in, a public project is joined to read signed out: the folder holds only its settings, sends no sign-in, and runs status, log, show, files, blame, why, where, issues, issue and search; every other command is refused.",
312 run: runJoin,
313 },
314 record: {
315 flags: { all: "boolean", binary: "string" },
316 usage: "abso record [--all]",
317 about:
318 "Send every file that changed since the server last heard about it (--all: every file). For edits the hook did not see.",
319 run: runRecord,
320 },
321 push: {
322 flags: {
323 message: "string",
324 binary: "string",
325 "as-is": "boolean",
326 check: "optional",
327 box: "string",
328 wait: "string",
329 "no-wait": "boolean",
330 done: "boolean",
331 },
332 usage: 'abso push -m "<why>" [--as-is] [--check ["<command>"]] [--wait <seconds> | --no-wait] [--done]',
333 about:
334 'Record, then add your draft to shared. Refused when it collides with work pushed since your last pull, or when lines a pull showed changed on both sides are still untouched (--as-is pushes both sides\' lines anyway). --check "<command>" (e.g. --check "npm run typecheck") first pulls, then runs the command in your box on your draft with newest shared, and pushes 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 push to shared is queued and lands only once the project\'s check passes on shared with it on top: push waits up to 100 s for that (--wait <seconds> changes it, --no-wait returns at once), then says it landed (exit 0), was turned back 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 pushed: this push finishes that work.',
335 run: runPublish,
336 },
337 bisect: {
338 flags: { good: "string", bad: "string", box: "string" },
339 usage: "abso bisect [--good <version>] [--bad <version>] -- <program> <arg...>",
340 about:
341 "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.",
342 rest: true,
343 run: runBisect,
344 },
345 reader: {
346 flags: {},
347 usage: "abso reader on|off",
348 about:
349 "Make this folder's agent a reader, which reads everything and records nothing (the server refuses its edits, records and pushes), or a writer again. Refused while it has unpushed or parked work.",
350 run: runReader,
351 },
352 settle: {
353 flags: { yours: "boolean", theirs: "boolean", both: "boolean" },
354 usage: "abso settle <file...> --yours|--theirs|--both",
355 about:
356 "Settle the collisions a pull 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.",
357 run: runSettle,
358 },
359 pull: {
360 flags: { verbose: "boolean", full: "boolean" },
361 usage: "abso pull [--full]",
362 about:
363 "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 pull.",
364 run: runSync,
365 },
366 run: {
367 flags: {
368 detach: "boolean",
369 replace: "boolean",
370 fresh: "boolean",
371 parallel: "boolean",
372 at: "string",
373 files: "string",
374 fetch: "string",
375 box: "string",
376 with: "string",
377 quiet: "boolean",
378 },
379 usage:
380 'abso run [--detach] [--replace] [--fresh] [--box <name>] [--at <version> [--files <glob>]] <command...> | abso run ... -- <program> <arg...> | abso run --parallel "<command>" "<command>"...',
381 about:
382 "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.",
383 rest: true,
384 run: runRun,
385 },
386 serve: {
387 flags: { version: "string", build: "string", out: "string" },
388 usage: 'abso serve [--version <n>] [--build "<command>"] [--out <folder>]',
389 about:
390 "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.",
391 run: runServe,
392 },
393 mv: {
394 flags: {},
395 usage: "abso mv <from> <to>",
396 about:
397 "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 push.",
398 run: runMv,
399 },
400 review: {
401 flags: { since: "string" },
402 usage: "abso review [<id> | v<version> | <agent>] [--since <position|2h>]",
403 about:
404 "Review is reading what landed. 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 push), 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.",
405 run: runReview,
406 },
407 note: {
408 flags: {
409 object: "boolean",
410 read: "boolean",
411 draft: "string",
412 at: "string",
413 reply: "string",
414 close: "string",
415 resolved: "boolean",
416 withdrawn: "boolean",
417 },
418 usage:
419 'abso note <file>:<line>[-<line>] "<text>" [--object | --read] [--draft <agent> | --at <version>] | abso note --reply <id> "<text>" | abso note --close <id> --resolved|--withdrawn',
420 about:
421 "A note on lines: 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 unpushed 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.",
422 run: runNote,
423 },
424 notes: {
425 flags: { change: "string", all: "boolean" },
426 usage: "abso notes [file] [--change <id>] [--all]",
427 about:
428 "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.",
429 run: runNotes,
430 },
431 issues: {
432 flags: {
433 open: "boolean",
434 status: "string",
435 agent: "string",
436 parent: "string",
437 label: "string",
438 labels: "boolean",
439 drafts: "boolean",
440 },
441 usage:
442 "abso issues [--open] [--status <status>] [--agent <agent>] [--parent <N>] [--label <l,l>] | abso issues --labels",
443 about:
444 "The project's issues, 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 push --done closes it.",
445 run: runIssues,
446 },
447 issue: {
448 flags: {
449 comment: "string",
450 object: "string",
451 drop: "boolean",
452 reopen: "boolean",
453 done: "boolean",
454 "done-by": "string",
455 title: "string",
456 description: "string",
457 parent: "string",
458 lines: "string",
459 agent: "string",
460 "blocked-by": "string",
461 notify: "string",
462 quiet: "boolean",
463 label: "string",
464 unlabel: "string",
465 open: "boolean",
466 delete: "boolean",
467 attach: "string",
468 "copy-to": "string",
469 clean: "string",
470 "dry-run": "boolean",
471 "save-attachments": "string",
472 },
473 usage:
474 '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>]',
475 about:
476 "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. A comment holds up to 4000 characters: a longer --comment (or --comment-file) goes up in parts, split at paragraph breaks and each starting (1/3), (2/3) and so on, and a longer --object is refused before anything is sent. --drop drops it. --reopen opens a dropped issue again. --done marks it done by hand, and --done-by <version> names the pushed version that did it. push --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.",
477 run: runIssue,
478 },
479 ask: {
480 flags: {
481 issue: "string",
482 review: "boolean",
483 task: "boolean",
484 due: "string",
485 blocks: "string",
486 options: "string",
487 withdraw: "string",
488 note: "string",
489 attach: "string",
490 },
491 usage:
492 'abso ask <who> "<question>" [--issue <N>] [--review | --task] [--due <YYYY-MM-DD>] [--blocks <N,N>] [--options "A|B|C"] [--attach <file,file>] | abso ask <N> | abso ask --withdraw <ask> [--note "why"]',
493 about:
494 "Ask an agent, or a person (person:<id>), something; they hear it. Who must be one of the project's agents or members; a name that isn't is refused, with the closest one suggested. abso ask <N> shows ask N, open or closed, with its whole thread, its answer and whose turn it is. 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.",
495 run: runAsk,
496 },
497 search: {
498 flags: { limit: "string" },
499 usage: 'abso search "<words>" [--limit <N>]',
500 about:
501 "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.",
502 run: runSearch,
503 },
504 waiting: {
505 flags: { of: "string", mine: "boolean", asked: "boolean" },
506 usage: "abso waiting [--of <agent or person:id>] [--mine] [--asked]",
507 about:
508 "The open asks, soonest due first: every one, those waiting on someone (--of), or those waiting on you (--mine), each with its newest reply. An ask waits on the one asked until they answer, or on the asker after a reply with --question, until the asker replies. --mine also lists your pushes still in the merge queue and where each stands; the outcome comes as news. --asked lists the asks you sent instead, open ones first, then the latest answered.",
509 run: runWaiting,
510 },
511 answer: {
512 flags: { option: "string", note: "string", done: "boolean", attach: "string" },
513 usage:
514 'abso answer <ask> "<words>" | abso answer <ask> --option <N> [--note "..."] | abso answer <ask> --done [--note "..."], each with [--attach <file,file>]',
515 about:
516 "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.",
517 run: runAnswer,
518 },
519 ack: {
520 flags: {},
521 usage: 'abso ack <ask> ["<note>"]',
522 about:
523 "Acknowledge an ask of you without answering it yet: it's the first reply in its thread. The asker hears it, with your note, and the ask stays open. abso reply adds more; abso answer closes it later.",
524 run: runAck,
525 },
526 reply: {
527 flags: { question: "boolean" },
528 usage: 'abso reply <ask> "<words>" [--question]',
529 about:
530 'Add to an ask\'s thread, as its asker or the one asked, open or closed: "ok, let me check", what you found, a follow-up. The other side hears it, and the ask stays as it is; abso answer still closes it. --question, from the one asked, asks the asker something back: the ask waits on them until they reply. On a public project, anyone can read the thread.',
531 run: runReply,
532 },
533 unqueue: {
534 flags: {},
535 usage: "abso unqueue",
536 about:
537 "Take back your pushes still waiting in the merge queue: their changes stay in your draft, unpushed. Refused while one is being checked; it lands or is turned back within a few minutes (abso drop takes it back after it lands).",
538 run: runUnqueue,
539 },
540 visibility: {
541 flags: { yes: "boolean" },
542 usage: "abso visibility [public|private] [--yes]",
543 about:
544 "Whether the project is public. 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).",
545 run: runVisibility,
546 },
547 ci: {
548 flags: { version: "string", revoke: "boolean" },
549 usage: "abso ci [<version>] | abso ci --revoke",
550 about:
551 "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.",
552 run: runCi,
553 },
554 shot: {
555 flags: {
556 out: "string",
557 wait: "string",
558 size: "string",
559 box: "string",
560 eval: "string",
561 click: "string",
562 mouse: "string",
563 at: "string",
564 scale: "string",
565 region: "string",
566 text: "boolean",
567 tree: "boolean",
568 interactive: "boolean",
569 depth: "string",
570 find: "string",
571 "max-chars": "string",
572 image: "boolean",
573 },
574 usage:
575 '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>]',
576 about:
577 "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.",
578 run: runShot,
579 },
580 prep: {
581 flags: { forget: "boolean", box: "string" },
582 usage: 'abso prep [--box <name>] "<setup command>" | abso prep --forget',
583 about:
584 "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.",
585 rest: true,
586 run: runPrep,
587 },
588 fetch: {
589 flags: { box: "string" },
590 usage: "abso fetch [--box <name>] <glob...>",
591 about:
592 "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.",
593 run: runFetch,
594 },
595 pause: {
596 flags: {},
597 usage: "abso pause",
598 about:
599 "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).",
600 run: runPause,
601 },
602 resume: {
603 flags: {},
604 usage: "abso resume",
605 about: "End abso pause. Changes made while paused go at the next record.",
606 run: runResume,
607 },
608 logs: {
609 flags: { box: "string" },
610 usage: "abso logs [--box <name>] <run id>",
611 about:
612 "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.",
613 run: runLogs,
614 },
615 status: {
616 flags: { short: "boolean" },
617 usage: "abso status [--short]",
618 about:
619 "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), +unpushed when it holds changes not yet pushed, and +queued when a push of yours waits in the merge queue.",
620 run: runStatus,
621 },
622 switch: {
623 flags: { carry: "boolean", verbose: "boolean" },
624 usage: "abso switch <draft> | abso switch -c <new draft> | abso switch shared",
625 about:
626 "Move this folder to a named draft, or back to shared. Your unpushed changes are parked where you leave and come back when you return; -c carries them into a new draft instead.",
627 run: runSwitch,
628 },
629 land: {
630 flags: { message: "string" },
631 usage: 'abso land -m "<why>"',
632 about:
633 "Land your named draft in shared, as one unit. Refused only on a collision with work that landed in shared since the draft began.",
634 run: runLand,
635 },
636 "draft-pull": {
637 flags: {},
638 usage: "abso draft-pull",
639 about: "Move your named draft onto shared's newest version, then bring that into this folder.",
640 run: runDraftSync,
641 },
642 diff: {
643 flags: { draft: "string", agent: "string" },
644 usage: "abso diff [file...] [--agent <name>] | abso diff <from> <to> [file...] [--draft <name>]",
645 about:
646 "Your unpushed changes, line by line, as git prints them (records first). --agent <name>: that agent's recorded, unpushed changes instead, to review them; it changes nothing. With two versions: what changed between them in this space.",
647 run: runDiff,
648 },
649 restore: {
650 flags: { all: "boolean" },
651 usage: "abso restore <file...> | abso restore <file>:<line>[-<line>] | abso restore --all",
652 about:
653 "Discard your unpushed 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.",
654 run: runRestore,
655 },
656 export: {
657 flags: { version: "string", keep: "string" },
658 usage: "abso export <dir> [--version <N>] [--keep <glob>]",
659 about:
660 "Write one pushed 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.",
661 run: runExport,
662 },
663 files: {
664 flags: { draft: "string", version: "string" },
665 usage: "abso files [glob...] [--draft <name>] [--version <N>]",
666 about:
667 "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).",
668 run: runFiles,
669 },
670 log: {
671 flags: { limit: "string", before: "string", draft: "string", since: "string", by: "string", count: "boolean" },
672 usage:
673 "abso log [file] [-n <count>] [--before <version>] [--draft <name>] [--since <version|30m|2h|1d|date>] [--by <agent,...>] [--count]",
674 about:
675 "The pushed 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.",
676 run: runLog,
677 },
678 show: {
679 flags: { draft: "string" },
680 usage: "abso show <version> | abso show <version>:<file> [--draft <name>]",
681 about: "One version: who pushed it, why, and its diff. With :<file>, that file's text as it was then.",
682 run: runShow,
683 },
684 announce: {
685 flags: { to: "string" },
686 usage: "abso announce [--to <agent,agent>] <text>",
687 about:
688 "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.",
689 run: runAnnounce,
690 },
691 start: {
692 flags: { done: "boolean", issue: "string" },
693 usage: 'abso start "<what>" [files...] [--issue <n>] | abso start --done',
694 about:
695 "Say what you are starting on, before your first edit, so abso where shows it to everyone. Names who already has unpushed changes in those files, and tells them. Nothing is locked; pushing ends the note.",
696 run: runStart,
697 },
698 news: {
699 flags: {},
700 usage: "abso news",
701 about:
702 "The news waiting for you: collisions, changed definitions, moved lines and announcements. Each item comes once.",
703 run: runNews,
704 },
705 "fix-eol": {
706 flags: {},
707 usage: "abso fix-eol",
708 about:
709 "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.",
710 run: runFixEol,
711 },
712 who: {
713 flags: {},
714 usage: "abso who <file...>",
715 about:
716 "For each file: who last changed it, who has unpushed changes in it (and where), and whose abso start note names it. Ask before you start in someone's file.",
717 run: runWho,
718 },
719 where: {
720 flags: {},
721 usage: "abso where",
722 about: "Who is working where: each file with unpushed changes, whose they are, and which lines.",
723 run: runWhere,
724 },
725 blame: {
726 flags: { from: "string", to: "string", version: "string", draft: "string", mine: "boolean" },
727 usage: "abso blame <file> [--from <n>] [--to <n>] [--version <n>] [--draft <name> | --mine]",
728 about:
729 "Who wrote each line of the file as shared has it (or had it at --version), and the push that brought it in. --draft reads a named draft; --mine reads your own view, marking your unpushed lines with *.",
730 run: runBlame,
731 },
732 why: {
733 flags: { draft: "string", mine: "boolean" },
734 usage: "abso why <file>:<line> [--draft <name> | --mine]",
735 about:
736 "Why one line of shared (or of a named draft, or your own view) is the way it is: its change, its push, its reasons, and any collision it settled.",
737 run: runWhy,
738 },
739 drop: {
740 flags: { message: "string", "with-dependents": "boolean" },
741 usage: 'abso drop <version...> -m "<why>" [--with-dependents]',
742 about:
743 "Take pushed 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.",
744 run: runDrop,
745 },
746 pluck: {
747 flags: { message: "string", "with-dependencies": "boolean" },
748 usage: 'abso pluck <draft> <version...> -m "<why>" [--with-dependencies]',
749 about:
750 "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.",
751 run: runPluck,
752 },
753 amend: {
754 flags: { message: "string" },
755 usage: 'abso amend -m "<new message>"',
756 about:
757 "Correct the message of your newest push in this space. Only the message changes; the log keeps the original.",
758 run: runAmend,
759 },
760 label: {
761 flags: { version: "string", remove: "boolean" },
762 usage: "abso label <name> [--version <n>] [--remove]",
763 about:
764 "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.",
765 run: runLabel,
766 },
767 labels: {
768 flags: {},
769 usage: "abso labels",
770 about: "Every label and the versions it marks.",
771 run: runLabels,
772 },
773 follow: {
774 flags: { none: "boolean" },
775 usage: "abso follow <label> | abso follow --none",
776 about:
777 "Make this folder follow a label: every pull takes it to the newest version of shared with that label, not the newest version. --none goes back to following shared.",
778 run: runFollow,
779 },
780 "check-ignore": {
781 flags: {},
782 usage: "abso check-ignore <path...>",
783 about:
784 "Whether abso leaves each path out, and which line of which ignore file decided (git's rules, for .gitignore and .absoignore).",
785 run: runCheckIgnore,
786 },
787 pipeline: {
788 flags: { on: "string", space: "string", pipeline: "string", every: "string", log: "string" },
789 usage:
790 "abso pipeline check [file] [--on push|draft|green|land|hand|schedule [--space <name>] [--pipeline <name>] [--every <when>]] | abso pipeline runs [<run>] [--log <pipeline.job>]",
791 about:
792 "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. abso pipeline runs asks the server what the project's pipelines did: the runs, newest first; with a run's number, its jobs (state, why, exit, time, an npm or deploy job's phase); with --log <pipeline.job>, that job's output.",
793 // Loaded only here, so the yaml package it needs can't stop every other command
794 // when a checkout lacks it (abso issue 168).
795 run: async (args, env) => {
796 let mod: typeof import("./pipeline-commands.ts");
797 try {
798 mod = await import("./pipeline-commands.ts");
799 } catch (e) {
800 if ((e as { code?: string }).code === "ERR_MODULE_NOT_FOUND")
801 throw new UsageError(
802 `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`,
803 );
804 throw e;
805 }
806 return mod.runPipeline(args, env);
807 },
808 },
809};
811const HELP_INTRO = "abso: version control for agents. This is its command-line client.";
812const HELP_NOTE =
813 "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). " +
814 "Every command that talks to a server takes --server <url>; one that works only on this machine (skill, check-ignore, pause, resume, fix-eol) doesn't. In a joined folder --server must be the folder's own server: another is refused, never swapped in. An explicit --server is used as given, and no setting redirects it.";
816/** A command's flags: its own, and --server for every command that talks to a server (server-choice.ts). */
817function flagsOf(name: string, def: CommandDef): FlagSpec {
818 return serverUse(name) === "local" ? def.flags : { ...def.flags, server: "string" };
821/** Every command as help shows it, in order: the table's, then the three it doesn't hold. */
822function helpEntries(): { name: string; usage: string; about: string; flags: FlagSpec; server?: string }[] {
823 return [
824 ...Object.entries(COMMANDS).map(([name, c]) => {
825 const server = serverHelp(name);
826 return { name, usage: c.usage, about: c.about, flags: flagsOf(name, c), ...(server ? { server } : {}) };
827 }),
828 {
829 name: "hook",
830 usage: "abso hook",
831 about: "The Claude Code PostToolUse hook. Reads the hook JSON on stdin; never fails.",
832 flags: {},
833 },
834 {
835 name: "mcp",
836 usage: "abso mcp",
837 about:
838 "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 -- abso mcp (on Windows, claude mcp add abso -- cmd /c abso mcp).",
839 flags: {},
840 },
841 {
842 name: "--version",
843 usage: "abso --version",
844 about: "This client's version and commit, and the abso mods installed on this machine.",
845 flags: {},
846 },
847 ];
850function help(): string {
851 const entries = helpEntries().flatMap((c) => [
852 ` ${c.usage}`,
853 ` ${c.about}`,
854 ...(c.server ? [` ${c.server}`] : []),
855 ]);
856 return [HELP_INTRO, "", ...entries, "", HELP_NOTE].join("\n");
859/**
860 * help --json: the same entries as data, for a command reference built from the client itself. A flag is
861 * "string" (takes a value), "boolean" (stands alone) or "optional" (a value that may be left off); every
862 * command also takes --json and --help.
863 */
864function helpJson(): Record<string, unknown> {
865 return {
866 ok: true,
867 command: "help",
868 version: clientVersion(),
869 intro: HELP_INTRO,
870 note: HELP_NOTE,
871 commands: helpEntries(),
872 };
875export interface MainResult {
876 readonly stdout: string;
877 readonly stderr: string;
878 readonly exit: number;
879 /** What --json prints, whether or not it was asked for (abso mcp answers with both). */
880 readonly data?: Record<string, unknown>;
883/** The commands, for abso mcp: each tool is one of them. */
884export function commandTable(): Readonly<
885 Record<string, { readonly flags: FlagSpec; readonly usage: string; readonly about: string }>
886> {
887 return Object.fromEntries(Object.entries(COMMANDS).map(([name, c]) => [name, { ...c, flags: flagsOf(name, c) }]));
890function newsBlock(news: readonly string[]): string[] {
891 return newsBlockLines(news.map((n) => newsShown(n)));
894/** Whether this folder's calls carry a key or token, for how a refusal is worded. False when that can't be told. */
895function carriesCredential(env: Env): boolean {
896 try {
897 const root = findRoot(env.cwd);
898 return root ? readConfig(root, env.env).token !== undefined : readToken(env.env) !== undefined;
899 } catch {
900 return false;
901 }
904/** git's forms of push and pull that abso doesn't have (#427): one plain line naming the abso way. */
905function gitOnlyForm(command: string, words: readonly string[]): string | undefined {
906 const has = (...forms: string[]) => words.some((w) => forms.some((f) => w === f || w.startsWith(`${f}=`)));
907 if (command === "push" && has("-f", "--force", "--force-with-lease", "--force-if-includes"))
908 return "abso push has no --force: nothing overwrites shared. When a push is refused, abso pull brings in the other side and abso settle keeps yours, theirs or both.";
909 if (command === "push" && has("-u", "--set-upstream", "--all", "--tags"))
910 return "abso push has no upstreams, branches or tags: it adds your draft to shared. A named draft is abso switch <name>; a label is abso label.";
911 if (command === "pull" && has("--rebase", "-r", "--no-rebase", "--ff-only", "--ff", "--no-ff", "--squash"))
912 return "abso pull has no --rebase or merge modes: it always brings shared under your draft, and lines changed on both sides are listed for abso settle.";
913 return undefined;
916export async function main(argv: readonly string[], env: Env): Promise<MainResult> {
917 const command = argv[0];
918 const json = argv.includes("--json") && command !== "run" && command !== "logs";
919 if (command === undefined || command === "help" || command === "--help" || command === "-h") {
920 if (json) {
921 const data = helpJson();
922 return { stdout: `${JSON.stringify(data, null, 2)}\n`, stderr: "", exit: EXIT.ok, data };
923 }
924 return { stdout: `${help()}\n`, stderr: "", exit: EXIT.ok };
925 }
926 try {
927 if (command === "--version") {
928 // Loaded only here: it runs git, and no other command needs it.
929 const { versionReport } = await import("./install.ts");
930 const { newerClientNote } = await import("./client-version.ts");
931 const report = versionReport(env.env);
932 const root = findRoot(env.cwd);
933 let behind: string | undefined;
934 if (root) {
935 try {
936 const server = (JSON.parse(readFileSync(configPath(root), "utf8")) as { server?: string }).server;
937 if (server) behind = await newerClientNote(server);
938 } catch {}
939 }
940 return {
941 stdout: json
942 ? `${JSON.stringify({ ok: true, command: "version", ...report.json, ...(behind ? { serverBehind: behind } : {}) }, null, 2)}\n`
943 : `${report.text}${behind ? `\n${behind}` : ""}\n`,
944 stderr: "",
945 exit: EXIT.ok,
946 };
947 }
948 const def = COMMANDS[command];
949 if (!def)
950 throw new UsageError(
951 `unknown command ${JSON.stringify(command)}; the commands are ${Object.keys(COMMANDS).join(", ")}, hook, mcp`,
952 );
953 const gitOnly = gitOnlyForm(command, argv.slice(1));
954 if (gitOnly) throw new UsageError(gitOnly);
955 const use = serverUse(command);
956 const words = argv.includes("--") ? argv.slice(1, argv.indexOf("--")) : argv.slice(1);
957 if (use === "local" && words.some((w) => w === "--server" || w.startsWith("--server=")))
958 throw new UsageError(localRefusal(command));
959 const parsed = parseArgs(command, argv.slice(1), withBodyFiles(command, flagsOf(command, def)), def.rest);
960 if ((command === "push" || command === "pull") && parsed.positionals.length > 0)
961 throw new UsageError(
962 `abso ${command} takes no remote or branch: it ${command === "push" ? "adds your draft to shared" : "brings shared into this folder"}. A named draft is abso switch <name>.`,
963 );
964 if (bool(parsed, "help")) {
965 const files = bodyFilesHelp(command, def.flags);
966 const server = serverHelp(command);
967 return {
968 stdout: `${def.usage}\n ${def.about}\n${server ? ` ${server}\n` : ""}${files ? ` ${files}\n` : ""}`,
969 stderr: "",
970 exit: EXIT.ok,
971 };
972 }
973 // --server is checked before anything is read or sent: a bad value, or (for a command on a joined folder)
974 // a server that isn't the folder's own, is refused here.
975 const named = use === "local" ? undefined : serverFlag(parsed);
976 if (named !== undefined && use === "folder") checkFolderServer(command, named, env.cwd);
977 // A folder that reads signed out runs its reads and nothing else, refused before any call.
978 const root = findRoot(env.cwd);
979 if (root !== undefined && isVisitor(root)) checkVisitor(command, parsed, readConfig(root, env.env).project);
980 const args = readBodyFiles(command, parsed, env.cwd, env.readStdin);
981 takeNews(); // what an earlier call in this process left (tests run many)
982 const out = await def.run(args, named === undefined ? env : { ...env, server: named });
983 const exit = out.exit ?? EXIT.ok;
984 // Every command that took news while recording prints it (#37, News Report).
985 const news = takeNews();
986 const data = {
987 ok: exit === EXIT.ok,
988 command,
989 ...out.json,
990 ...(news.length > 0 && !("news" in out.json) ? { news } : {}),
991 };
992 if (json || bool(args, "json")) return { stdout: `${JSON.stringify(data, null, 2)}\n`, stderr: "", exit, data };
993 // run, logs and bisect: stdout is the box command's, and may be piped; news goes to stderr there (#37).
994 const boxOut = command === "run" || command === "logs" || command === "bisect";
995 const text = [...(out.text === "" ? [] : [out.text.replace(/\n$/, "")]), ...(boxOut ? [] : newsBlock(news))].join(
996 "\n",
997 );
998 const errText = boxOut && news.length > 0 ? `${newsBlock(news).join("\n")}\n` : "";
999 return { stdout: text === "" ? "" : `${text}\n`, stderr: errText, exit, data };
1000 } catch (err) {
1001 const e = err as Error;
1002 const code = err instanceof UsageError ? "usage" : err instanceof ApiError ? "server" : "error";
1003 const message =
1004 plainError(err, carriesCredential(env)) ??
1005 (err instanceof UsageError || err instanceof ApiError
1006 ? e.message
1007 : `${e.message}${e.stack ? `\n${e.stack}` : ""}`);
1008 // The server refusing (409) is like a collision: exit 2, not a failure.
1009 const exit = err instanceof ApiError && err.status === 409 ? EXIT.refused : EXIT.error;
1010 // News taken before the failure still shows.
1011 const news = takeNews();
1012 const data = { ok: false, command, error: { code, message }, ...(news.length > 0 ? { news } : {}) };
1013 if (json) return { stdout: `${JSON.stringify(data, null, 2)}\n`, stderr: "", exit, data };
1014 return {
1015 stdout: news.length > 0 ? `${newsBlock(news).join("\n")}\n` : "",
1016 stderr: `abso ${command}: ${message}\n`,
1017 exit,
1018 data,
1019 };