{"draft":null,"from":2,"to":318,"files":[{"path":"client/src/state-dir.ts","added":67,"removed":0,"diff":"--- /dev/null\n+++ b/client/src/state-dir.ts\n@@ -0,0 +1,67 @@\n+// Where abso keeps its state (the rename from avcs). Reading takes .abso/ first, then .avcs/, so a folder in\n+// either works. A new folder is made with .abso/ unless an edit mod installed here is from before the rename:\n+// such a mod looks only for .avcs/config.json, and would stop recording a .abso/ folder's edits without a word.\n+// So a new folder gets .avcs/ while any installed mod is older than MOD_KNOWS_ABSO, and .abso/ otherwise.\n+// The user's files are written to ~/.abso/ (an older client that can't find them says so: it isn't silent).\n+// Nothing here imports from the rest of the client, so any module can use this.\n+\n+import { existsSync, readFileSync } from \"node:fs\";\n+import { homedir } from \"node:os\";\n+import { join } from \"node:path\";\n+\n+export const STATE_DIR = \".abso\";\n+export const OLD_STATE_DIR = \".avcs\";\n+const STATE_DIRS = [STATE_DIR, OLD_STATE_DIR] as const;\n+\n+/** A folder's state folder: whichever has a config.json (.abso first), else whichever exists, else the new folder's name (newFolderDir). */\n+export function stateDir(root: string): string {\n+\tfor (const name of STATE_DIRS) if (existsSync(join(root, name, \"config.json\"))) return join(root, name);\n+\tfor (const name of STATE_DIRS) if (existsSync(join(root, name))) return join(root, name);\n+\treturn join(root, newFolderDir());\n+}\n+\n+/** The first mod version whose hooks look for .abso/config.json as well as .avcs/config.json. */\n+export const MOD_KNOWS_ABSO = [0, 2, 0] as const;\n+\n+/** Every name a mod has been installed under, in Claude Code's skills folder. */\n+const MOD_NAMES = [\"avcs\", \"avcs-view\", \"abso\", \"abso-view\", \"abso-hooks\"] as const;\n+\n+function versionAtLeast(version: string, min: readonly number[]): boolean {\n+\tconst parts = version.split(\"+\")[0]!.split(\".\").map(Number);\n+\tfor (let i = 0; i < min.length; i++) {\n+\t\tconst have = parts[i] ?? 0;\n+\t\tif (have !== min[i]) return have > min[i]!;\n+\t}\n+\treturn true;\n+}\n+\n+/** What a new folder is made with: .abso, unless an installed mod is older than the rename (see the top). */\n+export function newFolderDir(env: Readonly<Record<string, string | undefined>> = process.env): string {\n+\tconst skills = join(env.CLAUDE_CONFIG_DIR || join(homedir(), \".claude\"), \"skills\");\n+\tfor (const name of MOD_NAMES) {\n+\t\tif (!existsSync(join(skills, name))) continue; // not installed\n+\t\tlet version: unknown;\n+\t\ttry {\n+\t\t\tversion = (JSON.parse(readFileSync(join(skills, name, \".avcs-install.json\"), \"utf8\")) as { version?: unknown })\n+\t\t\t\t.version;\n+\t\t} catch {\n+\t\t\treturn OLD_STATE_DIR; // installed, but no readable record: count it as old\n+\t\t}\n+\t\tif (typeof version !== \"string\" || !versionAtLeast(version, MOD_KNOWS_ABSO)) return OLD_STATE_DIR;\n+\t}\n+\treturn STATE_DIR;\n+}\n+\n+/** A file under the user's home to read: ~/.abso/<parts>, else the old ~/.avcs/<parts> when only that exists, else the new place. */\n+export function homeFile(home: string, ...parts: string[]): string {\n+\tfor (const name of STATE_DIRS) {\n+\t\tconst path = join(home, name, ...parts);\n+\t\tif (existsSync(path)) return path;\n+\t}\n+\treturn join(home, STATE_DIR, ...parts);\n+}\n+\n+/** 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. */\n+export function homeWritePath(home: string, ...parts: string[]): string {\n+\treturn join(home, STATE_DIR, ...parts);\n+}"}],"unmatched":[]}