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

Versions 16 to 17

Compare

+18 −18 in 8 places
Lines 6–15 at 17 (were 6–14 at 16)
66
77import { chmodSync, existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
88import { homedir } from "node:os";
9−import { dirname, join, resolve } from "node:path";
9+import { basename, dirname, join, resolve } from "node:path";
1010import { UsageError } from "./args.ts";
1111import { type MachineServers, machineServers, TOKEN_SERVERS, tokenGoesTo, trustedList } from "./core.ts";
12+import { homeFile, stateDir } from "./state-dir.ts";
1213
1314/** What .avcs/config.json holds. */
1415export interface Settings {
Lines 26–36 at 17 (were 25–37 at 16)
2526 readonly token?: string;
2627}
2728
28−export const AVCS_DIR = ".avcs";
29−
3029export function configPath(root: string): string {
31− return join(root, AVCS_DIR, "config.json");
30+ return join(stateDir(root), "config.json");
3231}
3332
34−/** The nearest folder at or above `start` that has .avcs/config.json, or undefined. */
33+/** The nearest folder at or above `start` that has .abso/config.json (or .avcs/config.json, from before the rename), or undefined. */
3534export function findRoot(start: string): string | undefined {
3635 let dir = resolve(start);
3736 for (;;) {
Lines 91–97 at 17 (were 92–98 at 16)
9291}
9392
9493function keyPath(root: string): string {
95− return join(root, AVCS_DIR, "key");
94+ return join(stateDir(root), "key");
9695}
9796
9897function originOf(server: string): string {
Lines 125–131 at 17 (were 126–132 at 16)
126125 if (configured && serverFlag && originOf(configured) !== originOf(serverFlag))
127126 throw new UsageError(`this folder's server is ${configured}, not ${serverFlag}`);
128127 const server = configured ?? serverFlag;
129− if (!server) throw new UsageError("this folder has no .avcs/config.json yet: give --server <url>");
128+ if (!server) throw new UsageError("this folder has no .abso/config.json yet: give --server <url>");
130129 let parsed: { key?: unknown; id?: unknown };
131130 try {
132131 parsed = JSON.parse(stdin) as { key?: unknown; id?: unknown };
Lines 139–145 at 17 (were 140–146 at 16)
140139 !/^k_[0-9a-f]{8}$/.test(parsed.id)
141140 )
142141 throw new UsageError("stdin needs {key, id} from the staging issue route");
143− mkdirSync(join(root, AVCS_DIR), { recursive: true });
142+ mkdirSync(stateDir(root), { recursive: true });
144143 writeFileSync(keyPath(root), `${JSON.stringify({ server, key: parsed.key, id: parsed.id })}\n`, { mode: 0o600 });
145144 try {
146145 chmodSync(keyPath(root), 0o600);
Lines 166–181 at 17 (were 167–182 at 16)
167166 const trusted = trustedServers(env);
168167 if (token === undefined || tokenGoesTo(server, trusted)) return token;
169168 throw new UsageError(
170− `this folder's server is ${server}, and abso sends your token only to ${[...TOKEN_SERVERS, "this machine"].join(", ")}, and the servers ~/.avcs/servers.json or AVCS_TRUSTED_SERVERS name. ` +
171− `If ${server} is yours, name it in ~/.avcs/servers.json or AVCS_TRUSTED_SERVERS (comma-separated); if you didn't set it, someone else wrote .avcs/config.json.`,
169+ `this folder's server is ${server}, and abso sends your token only to ${[...TOKEN_SERVERS, "this machine"].join(", ")}, and the servers ~/.abso/servers.json or AVCS_TRUSTED_SERVERS name. ` +
170+ `If ${server} is yours, name it in ~/.abso/servers.json or AVCS_TRUSTED_SERVERS (comma-separated); if you didn't set it, someone else wrote .abso/config.json.`,
172171 );
173172}
174173
175174let machine: MachineServers | undefined;
176−/** This machine's servers (core.ts machineServers), from ~/.avcs/servers.json, read once. AVCS_SERVERS_FILE names another file (tests). */
175+/** This machine's servers (core.ts machineServers), from ~/.abso/servers.json (or ~/.abso/servers.json), read once. AVCS_SERVERS_FILE names another file (tests). */
177176export function readMachineServers(env: Readonly<Record<string, string | undefined>> = process.env): MachineServers {
178177 if (env.AVCS_SERVERS_FILE !== undefined) return machineServers(readOr(env.AVCS_SERVERS_FILE));
179− machine ??= machineServers(readOr(join(homedir(), AVCS_DIR, "servers.json")));
178+ machine ??= machineServers(readOr(homeFile(homedir(), "servers.json")));
180179 return machine;
181180}
182181const readOr = (path: string): string | undefined => {
Lines 191–208 at 17 (were 192–209 at 16)
192191 return trustedList(env.AVCS_TRUSTED_SERVERS, readMachineServers(env));
193192}
194193
195−/** AVCS_TOKEN if set, else ~/.avcs/token, else none. */
194+/** AVCS_TOKEN if set, else ~/.abso/token, else ~/.avcs/token, else none. */
196195export function readToken(env: Readonly<Record<string, string | undefined>> = process.env): string | undefined {
197196 if (env.AVCS_TOKEN) return env.AVCS_TOKEN.trim();
198197 try {
199− return readFileSync(join(homedir(), AVCS_DIR, "token"), "utf8").trim() || undefined;
198+ return readFileSync(homeFile(homedir(), "token"), "utf8").trim() || undefined;
200199 } catch {
201200 return undefined;
202201 }
203202}
204203
205204export function writeConfig(root: string, settings: Settings): void {
206− mkdirSync(join(root, AVCS_DIR), { recursive: true });
205+ mkdirSync(stateDir(root), { recursive: true });
207206 const { server, project, agent, follow, reader } = settings;
208207 writeFileSync(
209208 configPath(root),
Lines 211–224 at 17 (were 212–224 at 16)
212211 excludeFromGit(root);
213212}
214213
215−/** If the folder is a git repo, keep .avcs/ out of it (in .git/info/exclude, so .gitignore isn't changed). */
214+/** If the folder is a git repo, keep its state folder (.abso/, or .avcs/ in an older folder) out of it (in .git/info/exclude, so .gitignore isn't changed). */
216215function excludeFromGit(root: string): void {
217216 const git = join(root, ".git");
218217 if (!existsSync(join(git, "HEAD"))) return;
219218 const exclude = join(git, "info", "exclude");
220219 const text = existsSync(exclude) ? readFileSync(exclude, "utf8") : "";
221− if (text.split(/\r?\n/).some((line) => line.trim() === ".avcs/" || line.trim() === "/.avcs/")) return;
220+ const name = `${basename(stateDir(root))}/`;
221+ if (text.split(/\r?\n/).some((line) => line.trim() === name || line.trim() === `/${name}`)) return;
222222 mkdirSync(dirname(exclude), { recursive: true });
223− writeFileSync(exclude, `${text}${text === "" || text.endsWith("\n") ? "" : "\n"}/.avcs/\n`);
223+ writeFileSync(exclude, `${text}${text === "" || text.endsWith("\n") ? "" : "\n"}/${name}\n`);
224224}
MCP
compare on this site's /mcp
CLI
abso diff 16 17 client/src/config.ts --json
JSON
/christopher/abso-core/compare/16..17?file=client%2Fsrc%2Fconfig.ts&format=json