- MCP
- code on this site's /mcp
- CLI
- none: the JSON below is the answer
- JSON
- /christopher/abso-core/files/client/src/state-dir.ts?format=json
67 linesreview 96% · pinch 3% · First import 1%Last change review in version 40, 5 versions changed it
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.
8import { existsSync, readFileSync } from "node:fs";
9import { homedir } from "node:os";
10import { join } from "node:path";
12export const STATE_DIR = ".abso";
13export const OLD_STATE_DIR = ".avcs";
14const 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). */
17export 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. */
24export const MOD_KNOWS_ABSO = [0, 2, 0] as const;
26/** Every name a mod has been installed under, in Claude Code's skills folder. */
27const MOD_NAMES = ["avcs", "avcs-view", "abso", "abso-view", "abso-hooks"] as const;
29function 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). */
39export 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. */
56export 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. */
65export function homeWritePath(home: string, ...parts: string[]): string {
66 return join(home, STATE_DIR, ...parts);
67}