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 8 to 318

Compare

+67 −0 in 1 place
new file, 67 lines
1+// Where abso keeps its state (the rename from avcs). Reading takes .abso/ first, then .avcs/, so a folder in
2+// either works. A new folder is made with .abso/ unless an edit mod installed here is from before the rename:
3+// such a mod looks only for .avcs/config.json, and would stop recording a .abso/ folder's edits without a word.
4+// So a new folder gets .avcs/ while any installed mod is older than MOD_KNOWS_ABSO, and .abso/ otherwise.
5+// The user's files are written to ~/.abso/ (an older client that can't find them says so: it isn't silent).
6+// Nothing here imports from the rest of the client, so any module can use this.
7+
8+import { existsSync, readFileSync } from "node:fs";
9+import { homedir } from "node:os";
10+import { join } from "node:path";
12+export const STATE_DIR = ".abso";
13+export const OLD_STATE_DIR = ".avcs";
14+const STATE_DIRS = [STATE_DIR, OLD_STATE_DIR] as const;
16+/** A folder's state folder: whichever has a config.json (.abso first), else whichever exists, else the new folder's name (newFolderDir). */
17+export function stateDir(root: string): string {
18+ for (const name of STATE_DIRS) if (existsSync(join(root, name, "config.json"))) return join(root, name);
19+ for (const name of STATE_DIRS) if (existsSync(join(root, name))) return join(root, name);
20+ return join(root, newFolderDir());
21+}
23+/** The first mod version whose hooks look for .abso/config.json as well as .avcs/config.json. */
24+export const MOD_KNOWS_ABSO = [0, 2, 0] as const;
26+/** Every name a mod has been installed under, in Claude Code's skills folder. */
27+const MOD_NAMES = ["avcs", "avcs-view", "abso", "abso-view", "abso-hooks"] as const;
29+function versionAtLeast(version: string, min: readonly number[]): boolean {
30+ const parts = version.split("+")[0]!.split(".").map(Number);
31+ for (let i = 0; i < min.length; i++) {
32+ const have = parts[i] ?? 0;
33+ if (have !== min[i]) return have > min[i]!;
34+ }
35+ return true;
36+}
38+/** What a new folder is made with: .abso, unless an installed mod is older than the rename (see the top). */
39+export function newFolderDir(env: Readonly<Record<string, string | undefined>> = process.env): string {
40+ const skills = join(env.CLAUDE_CONFIG_DIR || join(homedir(), ".claude"), "skills");
41+ for (const name of MOD_NAMES) {
42+ if (!existsSync(join(skills, name))) continue; // not installed
43+ let version: unknown;
44+ try {
45+ version = (JSON.parse(readFileSync(join(skills, name, ".avcs-install.json"), "utf8")) as { version?: unknown })
46+ .version;
47+ } catch {
48+ return OLD_STATE_DIR; // installed, but no readable record: count it as old
49+ }
50+ if (typeof version !== "string" || !versionAtLeast(version, MOD_KNOWS_ABSO)) return OLD_STATE_DIR;
51+ }
52+ return STATE_DIR;
53+}
55+/** A file under the user's home to read: ~/.abso/<parts>, else the old ~/.avcs/<parts> when only that exists, else the new place. */
56+export function homeFile(home: string, ...parts: string[]): string {
57+ for (const name of STATE_DIRS) {
58+ const path = join(home, name, ...parts);
59+ if (existsSync(path)) return path;
60+ }
61+ return join(home, STATE_DIR, ...parts);
62+}
64+/** Where to write a file under the user's home: always the new place. The old file is left as it is, for older clients and mods. */
65+export function homeWritePath(home: string, ...parts: string[]): string {
66+ return join(home, STATE_DIR, ...parts);
67+}
MCP
compare on this site's /mcp
CLI
abso diff 8 318 client/src/state-dir.ts --json
JSON
/christopher/abso-core/compare/8..318?file=client%2Fsrc%2Fstate-dir.ts&format=json