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