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=260&format=json
1,128 linesFirst import 60% · pinch 12% · speed 9% · approvals-page 6% · rename 4% · groups 3% · Last change approvals-page in version 259, 49 versions changed it

You're reading version 260. The newest is 318, and 10 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 { runAutosettle } from "./autosettle-commands.ts";
10import { bodyFilesHelp, readBodyFiles, withBodyFiles } from "./body-files.ts";
11import { boxName, boxPublic, boxText, login, loginRequest, logout, originOf, readBox } from "./box.ts";
12import { runDiff, runFiles, runLog, runRestore, runShow } from "./changes.ts";
13import { runCheckIgnore } from "./check-ignore.ts";
14import { runCi } from "./ci.ts";
15import { clientVersion } from "./client-version.ts";
16import {
17 type Env,
18 EXIT,
19 type Output,
20 runBisect,
21 runFetch,
22 runFixEol,
23 runInit,
24 runJoin,
25 runLogs,
26 runMv,
27 runPause,
28 runPrep,
29 runPublish,
30 runReader,
31 runRecord,
32 runResume,
33 runRun,
34 runServe,
35 runSettle,
36 runShot,
37 runStatus,
38 runSync,
39 takeNews,
40} from "./commands.ts";
41import { configPath, findRoot, installKey, isVisitor, readConfig, readToken } from "./config.ts";
42import { newsBlockLines, newsShown } from "./core.ts";
43import { doctor, doctorText, plainError, realProbe, whoami } from "./doctor.ts";
44import { runDraftSync, runLand, runSwitch } from "./drafts.ts";
45import { runExport } from "./export.ts";
46import { runGroup, runGroups } from "./group-commands.ts";
47import { runBlame, runWhere, runWho, runWhy } from "./history.ts";
48import {
49 openIssues,
50 runAck,
51 runAnswer,
52 runAsk,
53 runIssue,
54 runIssues,
55 runReply,
56 runSearch,
57 runWaiting,
58} from "./issues.ts";
59import { adminToken, issuedPublic, keyList, keyListText, keyNew, keyRevoke } from "./key-admin.ts";
60import { browserSkip, openInBrowser } from "./open-browser.ts";
61import { runOrg, runOrgs } from "./orgs.ts";
62import { runUnqueue } from "./queue.ts";
63import { runNote, runNotes, runReview } from "./review.ts";
64import {
65 checkFolderServer,
66 chooseServer,
67 localRefusal,
68 SERVER_ORDER,
69 serverFlag,
70 serverHelp,
71 serverUse,
72} from "./server-choice.ts";
73import { installSkill, SKILL, skillPath } from "./skill.ts";
74import { colorsPass, terminalText } from "./terminal-text.ts";
75import { runAmend, runDrop, runFollow, runLabel, runLabels, runPluck } from "./versions.ts";
76import { runVisibility } from "./visibility-commands.ts";
77import { checkVisitor } from "./visitor.ts";
79interface CommandDef {
80 readonly flags: FlagSpec;
81 readonly usage: string;
82 readonly about: string;
83 /** Stop reading options at the first word (for `run <command...>`). */
84 readonly rest?: boolean;
85 readonly run: (args: Parsed, env: Env) => Promise<Output>;
88/** The server login, box, logout, orgs, org, whoami and doctor act on, in the order every command picks one (server-choice.ts). */
89export function boxServer(args: Parsed, env: Pick<Env, "cwd" | "env">): string {
90 return chooseServer(serverFlag(args), env.cwd, env.env);
93async function runKeyInstall(args: Parsed, env: Env): Promise<Output> {
94 // With --server, the folder is the one named (or here), before it is joined: findRoot
95 // could find a parent agent's folder and pin the key there.
96 const server = str(args, "server");
97 const root = server ? resolve(env.cwd, str(args, "dir") ?? ".") : findRoot(env.cwd);
98 if (!root)
99 throw new UsageError("abso key install runs inside an agent's folder, or takes --server <url> before abso join");
100 const stdin = await new Promise<string>((done, reject) => {
101 const chunks: Buffer[] = [];
102 process.stdin.on("data", (c) => chunks.push(c as Buffer));
103 process.stdin.on("end", () => done(Buffer.concat(chunks).toString("utf8")));
104 process.stdin.on("error", reject);
105 });
106 const { id } = installKey(root, stdin, server);
107 return { text: `Installed agent key ${id}.`, json: { installed: id } };
110const COMMANDS: Readonly<Record<string, CommandDef>> = {
111 init: {
112 flags: {
113 server: "string",
114 project: "string",
115 agent: "string",
116 "as-is": "boolean",
117 org: "string",
118 public: "boolean",
119 private: "boolean",
120 },
121 usage: "abso init [folder] --project <name> [--agent <name>] [--as-is] [--org <org>] [--public|--private]",
122 about:
123 "Create a project on the server from a folder's text files The folder becomes that agent's folder. It writes a starting .absoignore, and, when the folder has no avcs.json and package.json gives a check or a build to guess, an avcs.json (setup, check, build and out): what the server's CI runs on each new version of shared. Without one, CI runs what it can guess itself, or nothing. --as-is writes neither: the folder goes up exactly as it is (an import). On a server this box is signed in to (abso login, approving all your projects), the project is made as you, the way the website's New project makes it: you own it, it's private unless you say --public, and the folder joins it at once with its own key (--agent names it; else the box's name). --org <org> makes it that organization's project. Elsewhere it needs --agent and the server's token.",
124 run: (args, env) => runInit(args, env),
125 },
126 key: {
127 flags: {
128 server: "string",
129 dir: "string",
130 project: "string",
131 agent: "string",
132 expires: "string",
133 role: "string",
134 print: "boolean",
135 },
136 usage:
137 "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>]",
138 about:
139 "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.",
140 run: async (args, env) => {
141 const sub = args.positionals[0];
142 if (sub === "install" && args.positionals.length === 1) return runKeyInstall(args, env);
143 const serverFlag = str(args, "server");
144 const root = serverFlag ? resolve(env.cwd, str(args, "dir") ?? ".") : findRoot(env.cwd);
145 if (!root) throw new UsageError("abso key runs inside an agent's folder, or takes --server <url>");
146 let config: ReturnType<typeof readConfig>;
147 try {
148 config = readConfig(root, env.env);
149 } catch {
150 config = {
151 server: serverFlag ?? "",
152 project: str(args, "project") ?? "",
153 agent: "admin",
154 token: readToken(env.env),
155 };
156 }
157 if (serverFlag) config = { ...config, server: serverFlag };
158 const admin = adminToken(env.env);
159 if (sub === "new" && args.positionals.length === 2) {
160 const server = str(args, "server") ?? config.server;
161 const project = str(args, "project") ?? config.project;
162 const expires = str(args, "expires");
163 const role = str(args, "role");
164 if (role !== undefined && role !== "owner" && role !== "writer" && role !== "reader")
165 throw new UsageError("--role is owner, writer or reader");
166 const issued = await keyNew({ ...config, server }, admin, args.positionals[1]!, project, expires, role);
167 const print = bool(args, "print");
168 const shown = issuedPublic(issued, print);
169 if (!print) {
170 const dir = str(args, "server") ? resolve(env.cwd, str(args, "dir") ?? ".") : root;
171 installKey(dir, JSON.stringify({ key: issued.key, id: issued.id }), server);
172 }
173 return {
174 text: print ? `${JSON.stringify({ key: issued.key, id: issued.id })}\n` : `Made ${issued.id}.\n`,
175 json: shown,
176 };
177 }
178 if (sub === "list" && args.positionals.length === 1) {
179 const agent = str(args, "agent");
180 const project = str(args, "project") ?? config.project;
181 const keys = await keyList({ ...config, server: str(args, "server") ?? config.server }, admin, agent, project);
182 return { text: `${keyListText(keys)}\n`, json: { keys } };
183 }
184 if (sub === "revoke" && args.positionals.length === 2) {
185 const project = str(args, "project") ?? config.project;
186 const id = args.positionals[1]!;
187 const revoked = await keyRevoke(
188 { ...config, server: str(args, "server") ?? config.server },
189 admin,
190 id,
191 project,
192 );
193 return { text: revoked ? `Revoked ${id}.\n` : `No key ${id}.\n`, json: { id, revoked } };
194 }
195 throw new UsageError("abso key install | abso key new <agent> | abso key list | abso key revoke <id>");
196 },
197 },
198 login: {
199 flags: {
200 server: "string",
201 "no-browser": "boolean",
202 "no-ask": "boolean",
203 projects: "string",
204 role: "string",
205 days: "string",
206 },
207 usage:
208 "abso login [--no-browser] [--no-ask] [--projects <name,name>] [--role <reader|writer|owner>] [--days <1-90>]",
209 about:
210 "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 long. 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. No browser opens with --no-browser or ABSO_NO_BROWSER, over SSH, under CI, or on Linux without a display. In an agent's folder on the same server, it also asks a person in that project to approve it (the person who approved the agent's box, else the project's owners), as an abso ask, so nobody has to relay the code; the box can then be granted that project at no more than the agent's own role. --no-ask shows the code only.",
211 run: async (args, env) => {
212 const server = boxServer(args, env);
213 const open =
214 bool(args, "no-browser") || browserSkip(env.env, process.platform) !== null
215 ? undefined
216 : (url: string) => openInBrowser(url);
217 const record = await login(server, {
218 ask: bool(args, "no-ask") ? undefined : loginAsk(server, env),
219 request: loginRequest(args),
220 say: (line) => process.stderr.write(terminalText(`${line}\n`, colorsPass(process.stderr, env.env))),
221 open,
222 });
223 return {
224 text: `This box is signed in. ${boxText(record, server).split("\n").slice(1).join(" ")}`,
225 json: { box: boxPublic(record) },
226 };
227 },
228 },
229 box: {
230 flags: { server: "string" },
231 usage: "abso box",
232 about:
233 "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.",
234 run: async (args, env) => {
235 const server = boxServer(args, env);
236 const record = readBox(server);
237 return { text: boxText(record, server), json: { box: boxPublic(record) } };
238 },
239 },
240 whoami: {
241 flags: { server: "string" },
242 usage: "abso whoami",
243 about:
244 "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.",
245 run: async (args, env) => {
246 const out = await whoami(boxServer(args, env), env.cwd, env.env, realProbe());
247 return { text: out.text, json: out.json };
248 },
249 },
250 doctor: {
251 flags: { server: "string" },
252 usage: "abso doctor",
253 about:
254 "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.",
255 run: async (args, env) => {
256 const checks = await doctor(boxServer(args, env), env.cwd, env.env, realProbe());
257 const failed = checks.some((c) => c.result === "fail");
258 return { text: doctorText(checks), json: { checks }, ...(failed ? { exit: EXIT.error } : {}) };
259 },
260 },
261 logout: {
262 flags: { server: "string" },
263 usage: "abso logout",
264 about:
265 "End this box's sign-in on the server and forget it here. Keys its agents already have stop working with it.",
266 run: async (args, env) => {
267 const server = boxServer(args, env);
268 const record = readBox(server);
269 if (!record) return { text: `This box isn't signed in to ${server}.`, json: { loggedOut: false } };
270 const ended = await logout(record);
271 return {
272 text: ended
273 ? `Signed this box out of ${record.server}.`
274 : `Forgot this box's sign-in here, but ${record.server} couldn't be reached to end it. Revoke the box on the website.`,
275 json: { loggedOut: true, ended },
276 };
277 },
278 },
279 orgs: {
280 flags: { server: "string" },
281 usage: "abso orgs",
282 about:
283 "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).",
284 run: (args, env) => runOrgs(boxServer(args, env)),
285 },
286 org: {
287 flags: {
288 server: "string",
289 name: "string",
290 invite: "string",
291 as: "string",
292 role: "string",
293 remove: "string",
294 leave: "boolean",
295 members: "string",
296 "projects-by": "string",
297 },
298 usage:
299 "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>]",
300 about:
301 "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. abso org new makes one as that person, from a box approved for all their projects; other changes are made on the website, and abso says where.",
302 run: (args, env) => runOrg(args, boxServer(args, env)),
303 },
304 skill: {
305 flags: { dir: "string" },
306 usage: "abso skill install [--dir <skills folder>] | abso skill show",
307 about:
308 "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.",
309 run: async (args, env) => {
310 const [verb, ...more] = args.positionals;
311 if (verb === "show" && more.length === 0) return { text: SKILL, json: { skill: SKILL } };
312 if (verb !== "install" || more.length > 0)
313 throw new UsageError("abso skill install [--dir <skills folder>] | abso skill show");
314 const path = skillPath(str(args, "dir"), env.cwd);
315 const done = installSkill(path);
316 const said = { installed: "Installed", updated: "Updated", current: "Already current:" }[done];
317 return {
318 text: `${said} the abso skill at ${path}. New Claude Code sessions load it.`,
319 json: { path, done },
320 };
321 },
322 },
323 join: {
324 flags: { server: "string", agent: "string", dir: "string", reader: "boolean" },
325 usage: "abso join <project> [--agent <name>] [--dir <folder>] [--reader]",
326 about:
327 "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. --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.",
328 run: runJoin,
329 },
330 record: {
331 flags: { all: "boolean", binary: "string" },
332 usage: "abso record [--all]",
333 about:
334 "Send every file that changed since the server last heard about it (--all: every file). For edits the hook did not see.",
335 run: runRecord,
336 },
337 push: {
338 flags: {
339 message: "string",
340 binary: "string",
341 "as-is": "boolean",
342 check: "optional",
343 box: "string",
344 wait: "string",
345 "no-wait": "boolean",
346 done: "boolean",
347 },
348 usage: 'abso push -m "<why>" [--as-is] [--check ["<command>"]] [--wait <seconds> | --no-wait] [--done]',
349 about:
350 '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.',
351 run: runPublish,
352 },
353 bisect: {
354 flags: { good: "string", bad: "string", box: "string" },
355 usage: "abso bisect [--good <version>] [--bad <version>] -- <program> <arg...>",
356 about:
357 "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.",
358 rest: true,
359 run: runBisect,
360 },
361 reader: {
362 flags: {},
363 usage: "abso reader on|off",
364 about:
365 "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.",
366 run: runReader,
367 },
368 settle: {
369 flags: { yours: "boolean", theirs: "boolean", both: "boolean" },
370 usage: "abso settle <file...> --yours|--theirs|--both",
371 about:
372 "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.",
373 run: runSettle,
374 },
375 pull: {
376 flags: { verbose: "boolean", full: "boolean" },
377 usage: "abso pull [--full]",
378 about:
379 "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.",
380 run: runSync,
381 },
382 run: {
383 flags: {
384 detach: "boolean",
385 replace: "boolean",
386 fresh: "boolean",
387 parallel: "boolean",
388 at: "string",
389 files: "string",
390 fetch: "string",
391 box: "string",
392 with: "string",
393 quiet: "boolean",
394 },
395 usage:
396 'abso run [--detach] [--replace] [--fresh] [--box <name>] [--at <version> [--files <glob>]] <command...> | abso run ... -- <program> <arg...> | abso run --parallel "<command>" "<command>"...',
397 about:
398 "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.",
399 rest: true,
400 run: runRun,
401 },
402 serve: {
403 flags: { version: "string", build: "string", out: "string" },
404 usage: 'abso serve [--version <n>] [--build "<command>"] [--out <folder>]',
405 about:
406 "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.",
407 run: runServe,
408 },
409 mv: {
410 flags: {},
411 usage: "abso mv <from> <to>",
412 about:
413 "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.",
414 run: runMv,
415 },
416 review: {
417 flags: { since: "string" },
418 usage: "abso review [<id> | v<version> | <agent>] [--since <position|2h>]",
419 about:
420 "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.",
421 run: runReview,
422 },
423 note: {
424 flags: {
425 object: "boolean",
426 read: "boolean",
427 draft: "string",
428 at: "string",
429 reply: "string",
430 close: "string",
431 resolved: "boolean",
432 withdrawn: "boolean",
433 },
434 usage:
435 'abso note <file>:<line>[-<line>] "<text>" [--object | --read] [--draft <agent> | --at <version>] | abso note --reply <id> "<text>" | abso note --close <id> --resolved|--withdrawn',
436 about:
437 "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.",
438 run: runNote,
439 },
440 notes: {
441 flags: { change: "string", all: "boolean" },
442 usage: "abso notes [file] [--change <id>] [--all]",
443 about:
444 "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.",
445 run: runNotes,
446 },
447 issues: {
448 flags: {
449 open: "boolean",
450 status: "string",
451 agent: "string",
452 parent: "string",
453 label: "string",
454 labels: "boolean",
455 drafts: "boolean",
456 },
457 usage:
458 "abso issues [--open] [--status <status>] [--agent <agent>] [--parent <N>] [--label <l,l>] | abso issues --labels",
459 about:
460 "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.",
461 run: runIssues,
462 },
463 issue: {
464 flags: {
465 comment: "string",
466 object: "string",
467 drop: "boolean",
468 reopen: "boolean",
469 done: "boolean",
470 "done-by": "string",
471 title: "string",
472 description: "string",
473 parent: "string",
474 lines: "string",
475 agent: "string",
476 "blocked-by": "string",
477 notify: "string",
478 quiet: "boolean",
479 label: "string",
480 unlabel: "string",
481 open: "boolean",
482 delete: "boolean",
483 attach: "string",
484 "copy-to": "string",
485 clean: "string",
486 "dry-run": "boolean",
487 "save-attachments": "string",
488 },
489 usage:
490 '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>]',
491 about:
492 "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.",
493 run: runIssue,
494 },
495 ask: {
496 flags: {
497 issue: "string",
498 review: "boolean",
499 task: "boolean",
500 due: "string",
501 blocks: "string",
502 options: "string",
503 withdraw: "string",
504 note: "string",
505 attach: "string",
506 },
507 usage:
508 '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"]',
509 about:
510 "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.",
511 run: runAsk,
512 },
513 search: {
514 flags: { limit: "string" },
515 usage: 'abso search "<words>" [--limit <N>]',
516 about:
517 "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.",
518 run: runSearch,
519 },
520 waiting: {
521 flags: { of: "string", mine: "boolean", asked: "boolean" },
522 usage: "abso waiting [--of <agent or person:id>] [--mine] [--asked]",
523 about:
524 "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.",
525 run: runWaiting,
526 },
527 answer: {
528 flags: { option: "string", note: "string", done: "boolean", attach: "string" },
529 usage:
530 'abso answer <ask> "<words>" | abso answer <ask> --option <N> [--note "..."] | abso answer <ask> --done [--note "..."], each with [--attach <file,file>]',
531 about:
532 "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.",
533 run: runAnswer,
534 },
535 ack: {
536 flags: {},
537 usage: 'abso ack <ask> ["<note>"]',
538 about:
539 "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.",
540 run: runAck,
541 },
542 reply: {
543 flags: { question: "boolean" },
544 usage: 'abso reply <ask> "<words>" [--question]',
545 about:
546 '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.',
547 run: runReply,
548 },
549 groups: {
550 flags: {},
551 usage: "abso groups",
552 about:
553 "The project's groups you can see: named sets of agents and people, each with one shared history. A private group shows only to its members and the project's owners. abso group <name> reads one.",
554 run: runGroups,
555 },
556 group: {
557 flags: {
558 post: "string",
559 reply: "string",
560 news: "string",
561 except: "string",
562 join: "boolean",
563 leave: "boolean",
564 add: "string",
565 remove: "string",
566 rename: "string",
567 private: "optional",
568 joinable: "string",
569 closed: "boolean",
570 before: "string",
571 limit: "string",
572 kind: "string",
573 },
574 usage:
575 'abso group <name> [--post "<words>" [--reply <N>] [--news all|none|<names> | --except <names>]] [--join | --leave | --add <who> | --remove <who> | --rename <name> | --private on|off | --joinable on|off] [--before <N>] [--limit <N>] [--kind message|member|settings] | abso group new <name> [--private] [--closed] [--add <names>]',
576 about:
577 "A group: its settings, members and history, newest first (--before reads further back, --kind filters). --post adds a message, with news for every other member unless --news names some, --except leaves some out, or --news none keeps it in the history only. A retry never posts twice. --join and --leave are yours to do any time, for a joinable group; a private one is joined only by its exact name. Its maker and the project's owners add, remove, rename and switch private and joinable. abso group new makes one, with you in it; --closed means members are added rather than joining. A reader may make, join and post in groups too.",
578 run: runGroup,
579 },
580 unqueue: {
581 flags: {},
582 usage: "abso unqueue",
583 about:
584 "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).",
585 run: runUnqueue,
586 },
587 visibility: {
588 flags: { yes: "boolean" },
589 usage: "abso visibility [public|private] [--yes]",
590 about:
591 "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).",
592 run: runVisibility,
593 },
594 autosettle: {
595 flags: { at: "string" },
596 usage: "abso autosettle [off|advise|settle] [--at 0.3-0.95] | abso autosettle history [<id>]",
597 about:
598 "What the server does with a held push (abso-core 23). With no word, says which. advise: each collision comes back with a model's pick (keep yours, keep theirs, keep both, or leave it to an agent), how sure it is, and why; the agent still settles. settle: when the model is at least --at sure about every collision, your abso settles it and pushes again by itself, saying so in the message; anything less sure stays held, with the advice. off: held pushes come back as they always have. New projects start on advise. Changing it takes the project owner's key (on staging, the shared token works too). ABSO_AUTOSETTLE=off on a machine makes its abso settle nothing by itself. abso autosettle history lists the held pushes the model advised on, newest first, with what it said and what was then kept; history <id> shows one, with its calls to the model (--json has each request and answer).",
599 run: runAutosettle,
600 },
601 ci: {
602 flags: { version: "string", revoke: "boolean" },
603 usage: "abso ci [<version>] | abso ci --revoke",
604 about:
605 "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.",
606 run: runCi,
607 },
608 shot: {
609 flags: {
610 out: "string",
611 wait: "string",
612 size: "string",
613 box: "string",
614 eval: "string",
615 click: "string",
616 mouse: "string",
617 at: "string",
618 scale: "string",
619 region: "string",
620 text: "boolean",
621 tree: "boolean",
622 interactive: "boolean",
623 depth: "string",
624 find: "string",
625 "max-chars": "string",
626 image: "boolean",
627 },
628 usage:
629 '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>]',
630 about:
631 "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.",
632 run: runShot,
633 },
634 prep: {
635 flags: { forget: "boolean", box: "string" },
636 usage: 'abso prep [--box <name>] "<setup command>" | abso prep --forget',
637 about:
638 "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.",
639 rest: true,
640 run: runPrep,
641 },
642 fetch: {
643 flags: { box: "string" },
644 usage: "abso fetch [--box <name>] <glob...>",
645 about:
646 "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.",
647 run: runFetch,
648 },
649 pause: {
650 flags: {},
651 usage: "abso pause",
652 about:
653 "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).",
654 run: runPause,
655 },
656 resume: {
657 flags: {},
658 usage: "abso resume",
659 about: "End abso pause. Changes made while paused go at the next record.",
660 run: runResume,
661 },
662 logs: {
663 flags: { box: "string" },
664 usage: "abso logs [--box <name>] <run id>",
665 about:
666 "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.",
667 run: runLogs,
668 },
669 status: {
670 flags: { short: "boolean" },
671 usage: "abso status [--short]",
672 about:
673 "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.",
674 run: runStatus,
675 },
676 switch: {
677 flags: { carry: "boolean", verbose: "boolean" },
678 usage: "abso switch <draft> | abso switch -c <new draft> | abso switch shared",
679 about:
680 "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.",
681 run: runSwitch,
682 },
683 land: {
684 flags: { message: "string" },
685 usage: 'abso land -m "<why>"',
686 about:
687 "Land your named draft in shared, as one unit. Refused only on a collision with work that landed in shared since the draft began.",
688 run: runLand,
689 },
690 "draft-pull": {
691 flags: {},
692 usage: "abso draft-pull",
693 about: "Move your named draft onto shared's newest version, then bring that into this folder.",
694 run: runDraftSync,
695 },
696 diff: {
697 flags: { draft: "string", agent: "string" },
698 usage: "abso diff [file...] [--agent <name>] | abso diff <from> <to> [file...] [--draft <name>]",
699 about:
700 "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.",
701 run: runDiff,
702 },
703 restore: {
704 flags: { all: "boolean" },
705 usage: "abso restore <file...> | abso restore <file>:<line>[-<line>] | abso restore --all",
706 about:
707 "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.",
708 run: runRestore,
709 },
710 export: {
711 flags: { version: "string", keep: "string", without: "string" },
712 usage: "abso export <dir> [--version <N>] [--without <version,...>] [--keep <glob>]",
713 about:
714 "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. --without 37,38 writes the version of shared with those earlier versions left out, and names them there too; shared doesn't change, and it is refused, naming the chain, when a version it keeps builds on one left out.",
715 run: runExport,
716 },
717 files: {
718 flags: { draft: "string", version: "string" },
719 usage: "abso files [glob...] [--draft <name>] [--version <N>]",
720 about:
721 "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).",
722 run: runFiles,
723 },
724 log: {
725 flags: { limit: "string", before: "string", draft: "string", since: "string", by: "string", count: "boolean" },
726 usage:
727 "abso log [file] [-n <count>] [--before <version>] [--draft <name>] [--since <version|30m|2h|1d|date>] [--by <agent,...>] [--count]",
728 about:
729 "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.",
730 run: runLog,
731 },
732 show: {
733 flags: { draft: "string", without: "string" },
734 usage: "abso show <version> | abso show <version>:<file> [--draft <name>] [--without <version,...>]",
735 about:
736 "One version: who pushed it, why, and its diff. With :<file>, that file's text as it was then. --without 37,38 shows the version of shared with those earlier versions left out: what differs, and with :<file> that file. Shared doesn't change. Refused, naming the chain, when a version it keeps builds on one left out.",
737 run: runShow,
738 },
739 announce: {
740 flags: { to: "string" },
741 usage: "abso announce [--to <agent,agent>] <text>",
742 about:
743 "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.",
744 run: runAnnounce,
745 },
746 start: {
747 flags: { done: "boolean", issue: "string" },
748 usage: 'abso start "<what>" [files...] [--issue <n>] | abso start --done',
749 about:
750 "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.",
751 run: runStart,
752 },
753 news: {
754 flags: {},
755 usage: "abso news",
756 about:
757 "The news waiting for you: collisions, changed definitions, moved lines and announcements. Each item comes once.",
758 run: runNews,
759 },
760 "fix-eol": {
761 flags: {},
762 usage: "abso fix-eol",
763 about:
764 "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.",
765 run: runFixEol,
766 },
767 who: {
768 flags: {},
769 usage: "abso who <file...>",
770 about:
771 "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.",
772 run: runWho,
773 },
774 where: {
775 flags: {},
776 usage: "abso where",
777 about: "Who is working where: each file with unpushed changes, whose they are, and which lines.",
778 run: runWhere,
779 },
780 blame: {
781 flags: { from: "string", to: "string", version: "string", draft: "string", mine: "boolean" },
782 usage: "abso blame <file> [--from <n>] [--to <n>] [--version <n>] [--draft <name> | --mine]",
783 about:
784 "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 *.",
785 run: runBlame,
786 },
787 why: {
788 flags: { draft: "string", mine: "boolean", at: "string", all: "boolean" },
789 usage: "abso why <file>:<line> [--at <version>] [--all] [--draft <name> | --mine]",
790 about:
791 "Why one line of shared (or of a named draft, or your own view) is the way it is: the newest change to what it does, its push, its reasons, any collision it settled, and the line's earlier changes, newest first. Changes that only touched formatting (whitespace, line wrapping, quotes, trailing commas) are skipped, and why says which; --all shows them too. A line imported from git names its commit, and #N in it names the old repository's issue when abso.json's \"gitIssues\" says where those are. --at <version> reads the line as shared (or the draft) had it then, as blame --version does.",
792 run: runWhy,
793 },
794 drop: {
795 flags: { message: "string", "with-dependents": "boolean" },
796 usage: 'abso drop <version...> -m "<why>" [--with-dependents]',
797 about:
798 "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.",
799 run: runDrop,
800 },
801 pluck: {
802 flags: { message: "string", "with-dependencies": "boolean" },
803 usage: 'abso pluck <draft> <version...> -m "<why>" [--with-dependencies]',
804 about:
805 "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.",
806 run: runPluck,
807 },
808 amend: {
809 flags: { message: "string" },
810 usage: 'abso amend -m "<new message>"',
811 about:
812 "Correct the message of your newest push in this space. Only the message changes; the log keeps the original.",
813 run: runAmend,
814 },
815 label: {
816 flags: { version: "string", remove: "boolean" },
817 usage: "abso label <name> [--version <n>] [--remove]",
818 about:
819 "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.",
820 run: runLabel,
821 },
822 labels: {
823 flags: {},
824 usage: "abso labels",
825 about: "Every label and the versions it marks.",
826 run: runLabels,
827 },
828 follow: {
829 flags: { none: "boolean" },
830 usage: "abso follow <label> | abso follow --none",
831 about:
832 "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.",
833 run: runFollow,
834 },
835 "check-ignore": {
836 flags: {},
837 usage: "abso check-ignore <path...>",
838 about:
839 "Whether abso leaves each path out, and which line of which ignore file decided (git's rules, for .gitignore and .absoignore).",
840 run: runCheckIgnore,
841 },
842 pipeline: {
843 flags: { on: "string", space: "string", pipeline: "string", every: "string", log: "string" },
844 usage:
845 "abso pipeline check [file] [--on push|draft|green|land|hand|schedule [--space <name>] [--pipeline <name>] [--every <when>]] | abso pipeline runs [<run>] [--log <pipeline.job>]",
846 about:
847 "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.",
848 // Loaded only here, so the yaml package it needs can't stop every other command
849 // when a checkout lacks it (abso issue 168).
850 run: async (args, env) => {
851 let mod: typeof import("./pipeline-commands.ts");
852 try {
853 mod = await import("./pipeline-commands.ts");
854 } catch (e) {
855 if ((e as { code?: string }).code === "ERR_MODULE_NOT_FOUND")
856 throw new UsageError(
857 `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`,
858 );
859 throw e;
860 }
861 return mod.runPipeline(args, env);
862 },
863 },
864};
866const HELP_INTRO = "abso: version control for agents. This is its command-line client.";
867const HELP_NOTE =
868 "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). " +
869 "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. The server is " +
870 SERVER_ORDER +
871 ": which servers this box is signed in to plays no part.";
873/** A command's flags: its own, and --server for every command that talks to a server (server-choice.ts). */
874function flagsOf(name: string, def: CommandDef): FlagSpec {
875 return serverUse(name) === "local" ? def.flags : { ...def.flags, server: "string" };
878/** Every command as help shows it, in order: the table's, then the three it doesn't hold. */
879function helpEntries(): { name: string; usage: string; about: string; flags: FlagSpec; server?: string }[] {
880 return [
881 ...Object.entries(COMMANDS).map(([name, c]) => {
882 const server = serverHelp(name);
883 return { name, usage: c.usage, about: c.about, flags: flagsOf(name, c), ...(server ? { server } : {}) };
884 }),
885 {
886 name: "hook",
887 usage: "abso hook",
888 about: "The Claude Code PostToolUse hook. Reads the hook JSON on stdin; never fails.",
889 flags: {},
890 },
891 {
892 name: "mcp",
893 usage: "abso mcp",
894 about:
895 "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).",
896 flags: {},
897 },
898 {
899 name: "--version",
900 usage: "abso --version",
901 about: "This client's version and commit, and the abso mods installed on this machine.",
902 flags: {},
903 },
904 ];
907function help(): string {
908 const entries = helpEntries().flatMap((c) => [
909 ` ${c.usage}`,
910 ` ${c.about}`,
911 ...(c.server ? [` ${c.server}`] : []),
912 ]);
913 return [HELP_INTRO, "", ...entries, "", HELP_NOTE].join("\n");
916/**
917 * help --json: the same entries as data, for a command reference built from the client itself. A flag is
918 * "string" (takes a value), "boolean" (stands alone) or "optional" (a value that may be left off); every
919 * command also takes --json and --help.
920 */
921function helpJson(): Record<string, unknown> {
922 return {
923 ok: true,
924 command: "help",
925 version: clientVersion(),
926 intro: HELP_INTRO,
927 note: HELP_NOTE,
928 commands: helpEntries(),
929 };
932export interface MainResult {
933 readonly stdout: string;
934 readonly stderr: string;
935 readonly exit: number;
936 /** What --json prints, whether or not it was asked for (abso mcp answers with both). */
937 readonly data?: Record<string, unknown>;
940/** The commands, for abso mcp: each tool is one of them. */
941export function commandTable(): Readonly<
942 Record<string, { readonly flags: FlagSpec; readonly usage: string; readonly about: string }>
943> {
944 return Object.fromEntries(Object.entries(COMMANDS).map(([name, c]) => [name, { ...c, flags: flagsOf(name, c) }]));
947function newsBlock(news: readonly string[]): string[] {
948 return newsBlockLines(news.map((n) => newsShown(n)));
951/** Whether this folder's calls carry a key or token, for how a refusal is worded. False when that can't be told. */
952function carriesCredential(env: Env): boolean {
953 try {
954 const root = findRoot(env.cwd);
955 return root ? readConfig(root, env.env).token !== undefined : readToken(env.env) !== undefined;
956 } catch {
957 return false;
958 }
961/** git's forms of push and pull that abso doesn't have (#427): one plain line naming the abso way. */
962function gitOnlyForm(command: string, words: readonly string[]): string | undefined {
963 const has = (...forms: string[]) => words.some((w) => forms.some((f) => w === f || w.startsWith(`${f}=`)));
964 if (command === "push" && has("-f", "--force", "--force-with-lease", "--force-if-includes"))
965 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.";
966 if (command === "push" && has("-u", "--set-upstream", "--all", "--tags"))
967 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.";
968 if (command === "pull" && has("--rebase", "-r", "--no-rebase", "--ff-only", "--ff", "--no-ff", "--squash"))
969 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.";
970 return undefined;
973export async function main(argv: readonly string[], env: Env): Promise<MainResult> {
974 const command = argv[0];
975 const json = argv.includes("--json") && command !== "run" && command !== "logs";
976 if (command === undefined || command === "help" || command === "--help" || command === "-h") {
977 if (json) {
978 const data = helpJson();
979 return { stdout: `${JSON.stringify(data, null, 2)}\n`, stderr: "", exit: EXIT.ok, data };
980 }
981 return { stdout: `${help()}\n`, stderr: "", exit: EXIT.ok };
982 }
983 try {
984 if (command === "--version") {
985 // Loaded only here: it runs git, and no other command needs it.
986 const { versionReport } = await import("./install.ts");
987 const { newerClientNote } = await import("./client-version.ts");
988 const report = versionReport(env.env);
989 const root = findRoot(env.cwd);
990 let behind: string | undefined;
991 if (root) {
992 try {
993 const server = (JSON.parse(readFileSync(configPath(root), "utf8")) as { server?: string }).server;
994 if (server) behind = await newerClientNote(server);
995 } catch {}
996 }
997 return {
998 stdout: json
999 ? `${JSON.stringify({ ok: true, command: "version", ...report.json, ...(behind ? { serverBehind: behind } : {}) }, null, 2)}\n`
1000 : `${report.text}${behind ? `\n${behind}` : ""}\n`,
1001 stderr: "",
1002 exit: EXIT.ok,
1003 };
1005 const def = COMMANDS[command];
1006 if (!def)
1007 throw new UsageError(
1008 `unknown command ${JSON.stringify(command)}; the commands are ${Object.keys(COMMANDS).join(", ")}, hook, mcp`,
1009 );
1010 const gitOnly = gitOnlyForm(command, argv.slice(1));
1011 if (gitOnly) throw new UsageError(gitOnly);
1012 const use = serverUse(command);
1013 const words = argv.includes("--") ? argv.slice(1, argv.indexOf("--")) : argv.slice(1);
1014 if (use === "local" && words.some((w) => w === "--server" || w.startsWith("--server=")))
1015 throw new UsageError(localRefusal(command));
1016 const parsed = parseArgs(command, argv.slice(1), withBodyFiles(command, flagsOf(command, def)), def.rest);
1017 if ((command === "push" || command === "pull") && parsed.positionals.length > 0)
1018 throw new UsageError(
1019 `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>.`,
1020 );
1021 if (bool(parsed, "help")) {
1022 const files = bodyFilesHelp(command, def.flags);
1023 const server = serverHelp(command);
1024 return {
1025 stdout: `${def.usage}\n ${def.about}\n${server ? ` ${server}\n` : ""}${files ? ` ${files}\n` : ""}`,
1026 stderr: "",
1027 exit: EXIT.ok,
1028 };
1030 // --server is checked before anything is read or sent: a bad value, or (for a command on a joined folder)
1031 // a server that isn't the folder's own, is refused here.
1032 const named = use === "local" ? undefined : serverFlag(parsed);
1033 if (named !== undefined && use === "folder") checkFolderServer(command, named, env.cwd);
1034 // A folder that reads signed out runs its reads and nothing else, refused before any call.
1035 const root = findRoot(env.cwd);
1036 if (root !== undefined && isVisitor(root)) checkVisitor(command, parsed, readConfig(root, env.env).project);
1037 const args = readBodyFiles(command, parsed, env.cwd, env.readStdin);
1038 takeNews(); // what an earlier call in this process left (tests run many)
1039 const out = await def.run(args, named === undefined ? env : { ...env, server: named });
1040 const exit = out.exit ?? EXIT.ok;
1041 // Every command that took news while recording prints it (#37, News Report).
1042 const news = takeNews();
1043 const data = {
1044 ok: exit === EXIT.ok,
1045 command,
1046 ...out.json,
1047 ...(news.length > 0 && !("news" in out.json) ? { news } : {}),
1048 };
1049 if (json || bool(args, "json")) return { stdout: `${JSON.stringify(data, null, 2)}\n`, stderr: "", exit, data };
1050 // run, logs and bisect: stdout is the box command's, and may be piped; news goes to stderr there (#37).
1051 const boxOut = command === "run" || command === "logs" || command === "bisect";
1052 const text = [...(out.text === "" ? [] : [out.text.replace(/\n$/, "")]), ...(boxOut ? [] : newsBlock(news))].join(
1053 "\n",
1054 );
1055 const errText = boxOut && news.length > 0 ? `${newsBlock(news).join("\n")}\n` : "";
1056 return { stdout: text === "" ? "" : `${text}\n`, stderr: errText, exit, data };
1057 } catch (err) {
1058 const e = err as Error;
1059 const code = err instanceof UsageError ? "usage" : err instanceof ApiError ? "server" : "error";
1060 const message =
1061 plainError(err, carriesCredential(env)) ??
1062 (err instanceof UsageError || err instanceof ApiError
1063 ? e.message
1064 : `${e.message}${e.stack ? `\n${e.stack}` : ""}`);
1065 // The server refusing (409) is like a collision: exit 2, not a failure.
1066 const exit = err instanceof ApiError && err.status === 409 ? EXIT.refused : EXIT.error;
1067 // News taken before the failure still shows.
1068 const news = takeNews();
1069 const data = { ok: false, command, error: { code, message }, ...(news.length > 0 ? { news } : {}) };
1070 if (json) return { stdout: `${JSON.stringify(data, null, 2)}\n`, stderr: "", exit, data };
1071 return {
1072 stdout: news.length > 0 ? `${newsBlock(news).join("\n")}\n` : "",
1073 stderr: `abso ${command}: ${message}\n`,
1074 exit,
1075 data,
1076 };
1080/**
1081 * abso 684: in an agent's folder on this same server, the ask `abso login` makes of a person in that project, so nobody
1082 * relays the code. The folder's agent key proves the agent; the device code proves the sign-in is this client's own.
1083 * Null outside such a folder, or when nobody could be asked: login then shows the code alone.
1084 */
1085function loginAsk(server: string, env: Env): NonNullable<Parameters<typeof login>[1]["ask"]> | undefined {
1086 const root = findRoot(env.cwd);
1087 if (root === undefined || isVisitor(root)) return undefined;
1088 const config = readConfig(root, env.env);
1089 if (config.token === undefined || originOf(config.server) !== originOf(server)) return undefined;
1090 return async ({ device, user }) => {
1091 const asked = await fetch(`${originOf(server)}/login/ask`, {
1092 method: "POST",
1093 headers: { "content-type": "application/json", authorization: `Bearer ${config.token}` },
1094 body: JSON.stringify({ project: config.project, agent: config.agent, device_code: device, user_code: user }),
1095 });
1096 const body = (await asked.json().catch(() => ({}))) as {
1097 error?: string;
1098 people?: string[];
1099 expires_at?: string;
1100 request_url?: string;
1101 role?: string;
1102 };
1103 if (!asked.ok || !Array.isArray(body.people) || typeof body.request_url !== "string") return null;
1104 const expiresAt = Date.parse(body.expires_at ?? "");
1105 const { api } = openIssues(env);
1106 const when = new Intl.DateTimeFormat("en-US", { timeZone: "America/Chicago", hour: "numeric", minute: "2-digit" });
1107 const question = `Please sign in my box "${boxName()}" for ${config.project}, as at most ${body.role}. It expires at ${when.format(new Date(expiresAt))} CT. Approve or deny: ${body.request_url}`;
1108 const asks: number[] = [];
1109 for (const of of body.people) asks.push((await api.ask({ of, question })).id);
1110 const first = asks[0];
1111 if (first !== undefined)
1112 await fetch(`${originOf(server)}/login/ask/link`, {
1113 method: "POST",
1114 headers: { "content-type": "application/json" },
1115 body: JSON.stringify({ device_code: device, ask: first }),
1116 });
1117 return {
1118 project: config.project,
1119 who: body.people.length === 1 ? "the person who approved this agent's box" : `the owners of ${config.project}`,
1120 asks,
1121 expiresAt,
1122 role: body.role ?? "writer",
1123 withdraw: async () => {
1124 for (const id of asks) await api.withdraw(id, { note: "The sign-in ran out; nothing was granted." });
1125 },
1126 };
1127 };