{"file":"client/src/install.ts","version":2,"draft":"login-timeout","total":581,"from":1,"to":581,"lines":[{"n":1,"text":"// Installing a mod without breaking the sessions that run it (#29). The avcs","atom":"a0","author":"init","version":0},{"n":2,"text":"// mod and avcs-view are folders in Claude Code's skills folder, which every","atom":"a0","author":"init","version":0},{"n":3,"text":"// session on the machine loads when it starts (an open chat keeps the mod it","atom":"a0","author":"init","version":0},{"n":4,"text":"// started with, #37). So an install (client/install-mod.ts, client/install-view.ts):","atom":"a0","author":"init","version":0},{"n":5,"text":"//","atom":"a0","author":"init","version":0},{"n":6,"text":"//  1. Stages the new files in a temp folder. plugin.json's version gets the","atom":"a0","author":"init","version":0},{"n":7,"text":"//     last commit that changed the mod's own files (0.1.0+702c616, or","atom":"a0","author":"init","version":0},{"n":8,"text":"//     0.1.0+702c616.dirty when they differ from it), and hooks/stamp.ts says","atom":"a0","author":"init","version":0},{"n":9,"text":"//     the same, so the mod sends it with each call to the server","atom":"a0","author":"init","version":0},{"n":10,"text":"//     (X-Abso-Client). A commit that changes none of them changes nothing to","atom":"a495","author":"pinch","version":54},{"n":11,"text":"//     install, and nothing to restart for.","atom":"a0","author":"init","version":0},{"n":12,"text":"//  2. Checks the staged copy: `claude plugin validate`, then the mod's own","atom":"a0","author":"init","version":0},{"n":13,"text":"//     tests in Claude Code's plugin test kit. If either fails, nothing in the","atom":"a0","author":"init","version":0},{"n":14,"text":"//     installed folder changes.","atom":"a0","author":"init","version":0},{"n":15,"text":"//  3. Keeps each installed file as <file>.prev, then moves each new file into","atom":"a0","author":"init","version":0},{"n":16,"text":"//     place with a rename, so no session reads a half-written file: what the","atom":"a0","author":"init","version":0},{"n":17,"text":"//     hook imports first, plugin.json last. If a rename fails, the files","atom":"a0","author":"init","version":0},{"n":18,"text":"//     already moved are put back.","atom":"a0","author":"init","version":0},{"n":19,"text":"//","atom":"a0","author":"init","version":0},{"n":20,"text":"// The renames follow each other within a few milliseconds, but a session can","atom":"a0","author":"init","version":0},{"n":21,"text":"// still start between two of them. With what the hook imports going in","atom":"a0","author":"init","version":0},{"n":22,"text":"// first, a new hook never loads without its imports; a core.ts that drops an","atom":"a0","author":"init","version":0},{"n":23,"text":"// export the old hook uses can fail that one start, and a restart after the","atom":"a0","author":"init","version":0},{"n":24,"text":"// install brings the whole new mod.","atom":"a0","author":"init","version":0},{"n":25,"text":"//","atom":"a0","author":"init","version":0},{"n":26,"text":"// A rollback swaps the .prev files back in, and the files it replaces become","atom":"a0","author":"init","version":0},{"n":27,"text":"// the .prev ones, so a second rollback undoes the first. .avcs-install.json","atom":"a0","author":"init","version":0},{"n":28,"text":"// in the mod's folder says what is installed and what the .prev files hold.","atom":"a0","author":"init","version":0},{"n":29,"text":"// `avcs --version` reports the installed mods (versionReport).","atom":"a0","author":"init","version":0},{"n":30,"text":"","atom":"a0","author":"init","version":0},{"n":31,"text":"import { spawnSync } from \"node:child_process\";","atom":"a0","author":"init","version":0},{"n":32,"text":"import {","atom":"a0","author":"init","version":0},{"n":33,"text":"\tcloseSync,","atom":"a0","author":"init","version":0},{"n":34,"text":"\tcopyFileSync,","atom":"a0","author":"init","version":0},{"n":35,"text":"\texistsSync,","atom":"a0","author":"init","version":0},{"n":36,"text":"\tmkdirSync,","atom":"a0","author":"init","version":0},{"n":37,"text":"\tmkdtempSync,","atom":"a0","author":"init","version":0},{"n":38,"text":"\topenSync,","atom":"a0","author":"init","version":0},{"n":39,"text":"\treadFileSync,","atom":"a0","author":"init","version":0},{"n":40,"text":"\trenameSync,","atom":"a0","author":"init","version":0},{"n":41,"text":"\trmdirSync,","atom":"a0","author":"init","version":0},{"n":42,"text":"\trmSync,","atom":"a0","author":"init","version":0},{"n":43,"text":"\tstatSync,","atom":"a0","author":"init","version":0},{"n":44,"text":"\twriteFileSync,","atom":"a0","author":"init","version":0},{"n":45,"text":"} from \"node:fs\";","atom":"a0","author":"init","version":0},{"n":46,"text":"import { homedir, tmpdir } from \"node:os\";","atom":"a0","author":"init","version":0},{"n":47,"text":"import { dirname, join, resolve } from \"node:path\";","atom":"a0","author":"init","version":0},{"n":48,"text":"import { CLIENT_DIR, clientPlace, clientVersion, headCommit } from \"./client-version.ts\";","atom":"a419","author":"speed","version":43},{"n":49,"text":"","atom":"a0","author":"init","version":0},{"n":50,"text":"export interface ModSpec {","atom":"a0","author":"init","version":0},{"n":51,"text":"\t/** The mod's name, as its plugin.json has it. */","atom":"a0","author":"init","version":0},{"n":52,"text":"\treadonly name: string;","atom":"a0","author":"init","version":0},{"n":53,"text":"\t/** The folder its files come from. */","atom":"a0","author":"init","version":0},{"n":54,"text":"\treadonly from: string;","atom":"a0","author":"init","version":0},{"n":55,"text":"\t/** Its files, relative to `from`, in the order they go into place: what the hook imports first, plugin.json last. */","atom":"a0","author":"init","version":0},{"n":56,"text":"\treadonly files: readonly string[];","atom":"a0","author":"init","version":0},{"n":57,"text":"\t/** Its tests for the plugin test kit, relative to `from`: staged for the check, never installed. */","atom":"a0","author":"init","version":0},{"n":58,"text":"\treadonly test?: string;","atom":"a0","author":"init","version":0},{"n":59,"text":"}","atom":"a0","author":"init","version":0},{"n":60,"text":"","atom":"a0","author":"init","version":0},{"n":61,"text":"/** One install, as .avcs-install.json records it. */","atom":"a0","author":"init","version":0},{"n":62,"text":"export interface Install {","atom":"a0","author":"init","version":0},{"n":63,"text":"\treadonly version: string;","atom":"a0","author":"init","version":0},{"n":64,"text":"\t/** In the order they went into place. */","atom":"a0","author":"init","version":0},{"n":65,"text":"\treadonly files: readonly string[];","atom":"a0","author":"init","version":0},{"n":66,"text":"\treadonly from: string;","atom":"a0","author":"init","version":0},{"n":67,"text":"\treadonly at: string;","atom":"a0","author":"init","version":0},{"n":68,"text":"}","atom":"a0","author":"init","version":0},{"n":69,"text":"","atom":"a0","author":"init","version":0},{"n":70,"text":"export interface InstallRecord extends Install {","atom":"a0","author":"init","version":0},{"n":71,"text":"\treadonly mod: string;","atom":"a0","author":"init","version":0},{"n":72,"text":"\t/** What the .prev files hold. */","atom":"a0","author":"init","version":0},{"n":73,"text":"\treadonly prev?: Install;","atom":"a0","author":"init","version":0},{"n":74,"text":"\t/** Set while files are being moved into place; still set means an install stopped midway. */","atom":"a0","author":"init","version":0},{"n":75,"text":"\treadonly moving?: string;","atom":"a0","author":"init","version":0},{"n":76,"text":"}","atom":"a0","author":"init","version":0},{"n":77,"text":"","atom":"a0","author":"init","version":0},{"n":78,"text":"export interface Installed {","atom":"a0","author":"init","version":0},{"n":79,"text":"\t/** False when the folder already had exactly these files. */","atom":"a0","author":"init","version":0},{"n":80,"text":"\treadonly changed: boolean;","atom":"a0","author":"init","version":0},{"n":81,"text":"\treadonly version: string;","atom":"a0","author":"init","version":0},{"n":82,"text":"\t/** The version the .prev files now hold. */","atom":"a0","author":"init","version":0},{"n":83,"text":"\treadonly previous: string | undefined;","atom":"a0","author":"init","version":0},{"n":84,"text":"\treadonly files: number;","atom":"a0","author":"init","version":0},{"n":85,"text":"}","atom":"a0","author":"init","version":0},{"n":86,"text":"","atom":"a0","author":"init","version":0},{"n":87,"text":"export interface InstallOptions {","atom":"a0","author":"init","version":0},{"n":88,"text":"\t/** The mod's folder: in the skills folder, or a scratch folder. */","atom":"a0","author":"init","version":0},{"n":89,"text":"\treadonly target: string;","atom":"a0","author":"init","version":0},{"n":90,"text":"\t/** Checks a staged copy of the mod: undefined when it passes, else why not. */","atom":"a0","author":"init","version":0},{"n":91,"text":"\treadonly check: (dir: string) => string | undefined;","atom":"a0","author":"init","version":0},{"n":92,"text":"\t/** For tests: the commit to stamp (null: none), instead of asking git. */","atom":"a0","author":"init","version":0},{"n":93,"text":"\treadonly commit?: string | null;","atom":"a0","author":"init","version":0},{"n":94,"text":"\t/** For tests: the rename that moves each file into place. */","atom":"a0","author":"init","version":0},{"n":95,"text":"\treadonly rename?: (from: string, to: string) => void;","atom":"a0","author":"init","version":0},{"n":96,"text":"\treadonly now?: Date;","atom":"a0","author":"init","version":0},{"n":97,"text":"}","atom":"a0","author":"init","version":0},{"n":98,"text":"","atom":"a0","author":"init","version":0},{"n":99,"text":"const RECORD = \".avcs-install.json\";","atom":"a0","author":"init","version":0},{"n":100,"text":"const LOCK = \".avcs-install.lock\";","atom":"a0","author":"init","version":0},{"n":101,"text":"const MANIFEST = \".claude-plugin/plugin.json\";","atom":"a0","author":"init","version":0},{"n":102,"text":"const STAMP_FILE = \"hooks/stamp.ts\";","atom":"a0","author":"init","version":0},{"n":103,"text":"/** A lock older than this was left by an install that died. */","atom":"a0","author":"init","version":0},{"n":104,"text":"const STALE_LOCK_MS = 10 * 60_000;","atom":"a0","author":"init","version":0},{"n":105,"text":"","atom":"a0","author":"init","version":0},{"n":106,"text":"const at = (dir: string, rel: string, suffix = \"\") => join(dir, ...rel.split(\"/\")) + suffix;","atom":"a0","author":"init","version":0},{"n":107,"text":"","atom":"a0","author":"init","version":0},{"n":108,"text":"/** The abso mod: what the hook imports first, plugin.json last. src/core.ts is the only client file it imports. */","atom":"a0","author":"init","version":0},{"n":109,"text":"export const AVCS_MOD: ModSpec = {","atom":"a0","author":"init","version":0},{"n":110,"text":"\tname: \"abso-hooks\",","atom":"a399","author":"review","version":40},{"n":111,"text":"\tfrom: CLIENT_DIR,","atom":"a0","author":"init","version":0},{"n":112,"text":"\tfiles: [\"src/core.ts\", \"hooks/stamp.ts\", \"hooks/register.ts\", \"hooks/hooks.json\", \".claude-plugin/plugin.json\"],","atom":"a0","author":"init","version":0},{"n":113,"text":"\ttest: \"hooks/register.test.ts\",","atom":"a0","author":"init","version":0},{"n":114,"text":"};","atom":"a0","author":"init","version":0},{"n":115,"text":"","atom":"a0","author":"init","version":0},{"n":116,"text":"/** The abso-view mod (#12), from client/view. */","atom":"a399","author":"review","version":40},{"n":117,"text":"export const VIEW_MOD: ModSpec = {","atom":"a0","author":"init","version":0},{"n":118,"text":"\tname: \"abso-view\",","atom":"a399","author":"review","version":40},{"n":119,"text":"\tfrom: join(CLIENT_DIR, \"view\"),","atom":"a0","author":"init","version":0},{"n":120,"text":"\tfiles: [\"types/index.d.ts\", \"hooks/stamp.ts\", \"hooks/register.tsx\", \"hooks/hooks.json\", \".claude-plugin/plugin.json\"],","atom":"a0","author":"init","version":0},{"n":121,"text":"\ttest: \"hooks/register.test.ts\",","atom":"a0","author":"init","version":0},{"n":122,"text":"};","atom":"a0","author":"init","version":0},{"n":123,"text":"","atom":"a0","author":"init","version":0},{"n":124,"text":"/** The skills folders the mods had before the rename; an install moves them out of the way (see retireOldMod). */","atom":"a399","author":"review","version":40},{"n":125,"text":"export const OLD_MOD_NAMES: Readonly<Record<string, string>> = { \"abso-hooks\": \"avcs\", \"abso-view\": \"avcs-view\" };","atom":"a399","author":"review","version":40},{"n":126,"text":"","atom":"a399","author":"review","version":40},{"n":127,"text":"/** Where Claude Code's skills folder keeps a mod. */","atom":"a0","author":"init","version":0},{"n":128,"text":"export const skillsFolder = (name: string, env: Readonly<Record<string, string | undefined>> = process.env) =>","atom":"a0","author":"init","version":0},{"n":129,"text":"\tjoin(env.CLAUDE_CONFIG_DIR || join(homedir(), \".claude\"), \"skills\", name);","atom":"a0","author":"init","version":0},{"n":130,"text":"","atom":"a0","author":"init","version":0},{"n":131,"text":"export const modInstalled = (env: Readonly<Record<string, string | undefined>> = process.env) =>","atom":"a0","author":"init","version":0},{"n":132,"text":"\texistsSync(at(skillsFolder(AVCS_MOD.name, env), MANIFEST)) ||","atom":"a399","author":"review","version":40},{"n":133,"text":"\texistsSync(at(skillsFolder(OLD_MOD_NAMES[AVCS_MOD.name]!, env), MANIFEST));","atom":"a399","author":"review","version":40},{"n":134,"text":"","atom":"a399","author":"review","version":40},{"n":135,"text":"/**","atom":"a399","author":"review","version":40},{"n":136,"text":" * After the new mod is in, the folder it replaces (skills/avcs, skills/avcs-view) would load beside it, so it","atom":"a399","author":"review","version":40},{"n":137,"text":" * is moved, not deleted, to ~/.abso/retired-mods/<name>-<stamp>. Returns where it went, or undefined when there was none.","atom":"a399","author":"review","version":40},{"n":138,"text":" */","atom":"a399","author":"review","version":40},{"n":139,"text":"export function retireOldMod(","atom":"a399","author":"review","version":40},{"n":140,"text":"\tspec: ModSpec,","atom":"a399","author":"review","version":40},{"n":141,"text":"\tenv: Readonly<Record<string, string | undefined>> = process.env,","atom":"a399","author":"review","version":40},{"n":142,"text":"\tnow: Date = new Date(),","atom":"a399","author":"review","version":40},{"n":143,"text":"): string | undefined {","atom":"a399","author":"review","version":40},{"n":144,"text":"\tconst old = OLD_MOD_NAMES[spec.name];","atom":"a399","author":"review","version":40},{"n":145,"text":"\tif (old === undefined) return undefined;","atom":"a399","author":"review","version":40},{"n":146,"text":"\tconst from = skillsFolder(old, env);","atom":"a399","author":"review","version":40},{"n":147,"text":"\tif (!existsSync(from)) return undefined;","atom":"a399","author":"review","version":40},{"n":148,"text":"\tconst to = join(homedir(), \".abso\", \"retired-mods\", `${old}-${now.toISOString().replace(/[:.]/g, \"-\")}`);","atom":"a399","author":"review","version":40},{"n":149,"text":"\tmkdirSync(dirname(to), { recursive: true });","atom":"a399","author":"review","version":40},{"n":150,"text":"\trenameRetrying(from, to);","atom":"a399","author":"review","version":40},{"n":151,"text":"\treturn to;","atom":"a399","author":"review","version":40},{"n":152,"text":"}","atom":"a399","author":"review","version":40},{"n":153,"text":"","atom":"a0","author":"init","version":0},{"n":154,"text":"/** The version an install of `spec` gets: plugin.json's, plus the last commit that changed its files (and .dirty when they differ from it). */","atom":"a0","author":"init","version":0},{"n":155,"text":"export function versionFor(spec: ModSpec, commit?: string | null): string {","atom":"a0","author":"init","version":0},{"n":156,"text":"\tconst manifest = JSON.parse(readFileSync(at(spec.from, MANIFEST), \"utf8\")) as { version?: unknown };","atom":"a0","author":"init","version":0},{"n":157,"text":"\tconst base = String(manifest.version ?? \"0.0.0\").split(\"+\")[0]!;","atom":"a0","author":"init","version":0},{"n":158,"text":"\tconst c = commit === undefined ? modCommit(spec) : commit;","atom":"a0","author":"init","version":0},{"n":159,"text":"\treturn c ? `${base}+${c}` : base;","atom":"a0","author":"init","version":0},{"n":160,"text":"}","atom":"a0","author":"init","version":0},{"n":161,"text":"","atom":"a0","author":"init","version":0},{"n":162,"text":"function modCommit(spec: ModSpec): string | null {","atom":"a0","author":"init","version":0},{"n":163,"text":"\tconst git = (...args: string[]) => spawnSync(\"git\", [\"-C\", spec.from, ...args], { encoding: \"utf8\" });","atom":"a0","author":"init","version":0},{"n":164,"text":"\tconst last = git(\"log\", \"-1\", \"--format=%H\", \"--\", ...spec.files);","atom":"a0","author":"init","version":0},{"n":165,"text":"\tif (last.status !== 0 || !/^[0-9a-f]{40}/.test(last.stdout)) return null;","atom":"a0","author":"init","version":0},{"n":166,"text":"\tconst changed = git(\"status\", \"--porcelain\", \"--\", ...spec.files).stdout.trim() !== \"\";","atom":"a0","author":"init","version":0},{"n":167,"text":"\treturn `${last.stdout.slice(0, 7)}${changed ? \".dirty\" : \"\"}`;","atom":"a0","author":"init","version":0},{"n":168,"text":"}","atom":"a0","author":"init","version":0},{"n":169,"text":"","atom":"a420","author":"speed","version":43},{"n":170,"text":"/** A file changed this close to when an answer was kept can't be told apart from one changed just after it. */","atom":"a420","author":"speed","version":43},{"n":171,"text":"const RACY_MS = 2_000;","atom":"a420","author":"speed","version":43},{"n":172,"text":"","atom":"a420","author":"speed","version":43},{"n":173,"text":"interface KeptModCommit {","atom":"a420","author":"speed","version":43},{"n":174,"text":"\treadonly head: string;","atom":"a420","author":"speed","version":43},{"n":175,"text":"\treadonly files: readonly string[];","atom":"a420","author":"speed","version":43},{"n":176,"text":"\treadonly at: number;","atom":"a420","author":"speed","version":43},{"n":177,"text":"\treadonly commit: string | null;","atom":"a420","author":"speed","version":43},{"n":178,"text":"}","atom":"a420","author":"speed","version":43},{"n":179,"text":"","atom":"a420","author":"speed","version":43},{"n":180,"text":"/**","atom":"a420","author":"speed","version":43},{"n":181,"text":" * modCommit for the version report, which `abso status` asks on every run: it runs git twice per mod, so","atom":"a420","author":"speed","version":43},{"n":182,"text":" * the answer is kept in ~/.abso/mod-commits.json. A kept answer holds while the checkout's commit (read","atom":"a420","author":"speed","version":43},{"n":183,"text":" * from .git, without git) and each of the mod's files (size, modified time, inode) are as they were, and","atom":"a420","author":"speed","version":43},{"n":184,"text":" * every file was changed clearly before the answer was kept; anything else asks git again. Outside a git","atom":"a424","author":"speed","version":43},{"n":185,"text":" * checkout there is no commit, and git isn't run at all.","atom":"a424","author":"speed","version":43},{"n":186,"text":" */","atom":"a420","author":"speed","version":43},{"n":187,"text":"export function keptModCommit(spec: ModSpec, home: string = homedir()): string | null {","atom":"a420","author":"speed","version":43},{"n":188,"text":"\tconst head = headCommit(spec.from);","atom":"a420","author":"speed","version":43},{"n":189,"text":"\tif (head === undefined) return null;","atom":"a424","author":"speed","version":43},{"n":190,"text":"\tconst at = Date.now();","atom":"a420","author":"speed","version":43},{"n":191,"text":"\tconst files = spec.files.map((rel) => {","atom":"a420","author":"speed","version":43},{"n":192,"text":"\t\ttry {","atom":"a420","author":"speed","version":43},{"n":193,"text":"\t\t\tconst s = statSync(join(spec.from, ...rel.split(\"/\")));","atom":"a420","author":"speed","version":43},{"n":194,"text":"\t\t\treturn `${s.size}:${s.mtimeMs}:${s.ino}`;","atom":"a420","author":"speed","version":43},{"n":195,"text":"\t\t} catch {","atom":"a420","author":"speed","version":43},{"n":196,"text":"\t\t\treturn \"-\";","atom":"a420","author":"speed","version":43},{"n":197,"text":"\t\t}","atom":"a420","author":"speed","version":43},{"n":198,"text":"\t});","atom":"a420","author":"speed","version":43},{"n":199,"text":"\tconst newest = Math.max(...files.map((f) => (f === \"-\" ? 0 : Number(f.split(\":\")[1]))));","atom":"a424","author":"speed","version":43},{"n":200,"text":"\tconst path = join(home, \".abso\", \"mod-commits.json\");","atom":"a420","author":"speed","version":43},{"n":201,"text":"\tconst key = `${resolve(spec.from)}|${spec.files.join(\"|\")}`;","atom":"a420","author":"speed","version":43},{"n":202,"text":"\tlet kept: Record<string, KeptModCommit> = {};","atom":"a420","author":"speed","version":43},{"n":203,"text":"\ttry {","atom":"a420","author":"speed","version":43},{"n":204,"text":"\t\tconst parsed = JSON.parse(readFileSync(path, \"utf8\")) as { format?: unknown; mods?: unknown };","atom":"a420","author":"speed","version":43},{"n":205,"text":"\t\tif (parsed.format === 1 && typeof parsed.mods === \"object\" && parsed.mods !== null)","atom":"a420","author":"speed","version":43},{"n":206,"text":"\t\t\tkept = parsed.mods as Record<string, KeptModCommit>;","atom":"a420","author":"speed","version":43},{"n":207,"text":"\t} catch {}","atom":"a420","author":"speed","version":43},{"n":208,"text":"\tconst was = kept[key];","atom":"a420","author":"speed","version":43},{"n":209,"text":"\tif (","atom":"a420","author":"speed","version":43},{"n":210,"text":"\t\twas !== undefined &&","atom":"a420","author":"speed","version":43},{"n":211,"text":"\t\twas.head === head &&","atom":"a420","author":"speed","version":43},{"n":212,"text":"\t\tArray.isArray(was.files) &&","atom":"a420","author":"speed","version":43},{"n":213,"text":"\t\twas.files.join() === files.join() &&","atom":"a420","author":"speed","version":43},{"n":214,"text":"\t\tnewest < was.at - RACY_MS","atom":"a420","author":"speed","version":43},{"n":215,"text":"\t)","atom":"a420","author":"speed","version":43},{"n":216,"text":"\t\treturn was.commit;","atom":"a420","author":"speed","version":43},{"n":217,"text":"\tconst commit = modCommit(spec);","atom":"a420","author":"speed","version":43},{"n":218,"text":"\ttry {","atom":"a420","author":"speed","version":43},{"n":219,"text":"\t\tmkdirSync(dirname(path), { recursive: true });","atom":"a420","author":"speed","version":43},{"n":220,"text":"\t\tconst next = `${path}.${process.pid}.tmp`;","atom":"a420","author":"speed","version":43},{"n":221,"text":"\t\twriteFileSync(next, JSON.stringify({ format: 1, mods: { ...kept, [key]: { head, files, at, commit } } }));","atom":"a420","author":"speed","version":43},{"n":222,"text":"\t\trenameSync(next, path);","atom":"a420","author":"speed","version":43},{"n":223,"text":"\t} catch {","atom":"a420","author":"speed","version":43},{"n":224,"text":"\t\t// Best effort: the next run asks git again.","atom":"a420","author":"speed","version":43},{"n":225,"text":"\t}","atom":"a420","author":"speed","version":43},{"n":226,"text":"\treturn commit;","atom":"a420","author":"speed","version":43},{"n":227,"text":"}","atom":"a420","author":"speed","version":43},{"n":228,"text":"","atom":"a0","author":"init","version":0},{"n":229,"text":"/** The files to install, stamped with `version`, in install order. */","atom":"a0","author":"init","version":0},{"n":230,"text":"function filesFor(spec: ModSpec, version: string): Map<string, Buffer> {","atom":"a0","author":"init","version":0},{"n":231,"text":"\tif (!/^[\\w.+-]+$/.test(version)) throw new Error(`can't stamp the version ${JSON.stringify(version)}`);","atom":"a0","author":"init","version":0},{"n":232,"text":"\tconst out = new Map<string, Buffer>();","atom":"a0","author":"init","version":0},{"n":233,"text":"\tfor (const rel of spec.files) {","atom":"a0","author":"init","version":0},{"n":234,"text":"\t\tlet data = readFileSync(at(spec.from, rel));","atom":"a0","author":"init","version":0},{"n":235,"text":"\t\tif (rel === MANIFEST) {","atom":"a0","author":"init","version":0},{"n":236,"text":"\t\t\tconst manifest = JSON.parse(data.toString(\"utf8\")) as Record<string, unknown>;","atom":"a0","author":"init","version":0},{"n":237,"text":"\t\t\tdata = Buffer.from(`${JSON.stringify({ ...manifest, version }, null, 2)}\\n`);","atom":"a0","author":"init","version":0},{"n":238,"text":"\t\t} else if (rel === STAMP_FILE) {","atom":"a0","author":"init","version":0},{"n":239,"text":"\t\t\tconst text = data.toString(\"utf8\");","atom":"a0","author":"init","version":0},{"n":240,"text":"\t\t\tconst stamped = text.replace(/(STAMP[^=\\n]*=\\s*)undefined/, `$1'${version}'`);","atom":"a0","author":"init","version":0},{"n":241,"text":"\t\t\tif (stamped === text) throw new Error(`${rel} has no \"STAMP ... = undefined\" line to stamp`);","atom":"a0","author":"init","version":0},{"n":242,"text":"\t\t\tdata = Buffer.from(stamped);","atom":"a0","author":"init","version":0},{"n":243,"text":"\t\t}","atom":"a0","author":"init","version":0},{"n":244,"text":"\t\tout.set(rel, data);","atom":"a0","author":"init","version":0},{"n":245,"text":"\t}","atom":"a0","author":"init","version":0},{"n":246,"text":"\treturn out;","atom":"a0","author":"init","version":0},{"n":247,"text":"}","atom":"a0","author":"init","version":0},{"n":248,"text":"","atom":"a0","author":"init","version":0},{"n":249,"text":"function readRecord(target: string): InstallRecord | undefined {","atom":"a0","author":"init","version":0},{"n":250,"text":"\ttry {","atom":"a0","author":"init","version":0},{"n":251,"text":"\t\treturn JSON.parse(readFileSync(join(target, RECORD), \"utf8\")) as InstallRecord;","atom":"a0","author":"init","version":0},{"n":252,"text":"\t} catch {","atom":"a0","author":"init","version":0},{"n":253,"text":"\t\treturn undefined;","atom":"a0","author":"init","version":0},{"n":254,"text":"\t}","atom":"a0","author":"init","version":0},{"n":255,"text":"}","atom":"a0","author":"init","version":0},{"n":256,"text":"","atom":"a0","author":"init","version":0},{"n":257,"text":"function writeRecord(target: string, record: InstallRecord): void {","atom":"a0","author":"init","version":0},{"n":258,"text":"\twriteFileSync(join(target, `${RECORD}.next`), `${JSON.stringify(record, null, 2)}\\n`);","atom":"a0","author":"init","version":0},{"n":259,"text":"\trenameRetrying(join(target, `${RECORD}.next`), join(target, RECORD));","atom":"a0","author":"init","version":0},{"n":260,"text":"}","atom":"a0","author":"init","version":0},{"n":261,"text":"","atom":"a0","author":"init","version":0},{"n":262,"text":"/** What is installed now. A folder from before .avcs-install.json: the spec's files that are there. */","atom":"a0","author":"init","version":0},{"n":263,"text":"function installedNow(spec: ModSpec, target: string, record: InstallRecord | undefined): Install | undefined {","atom":"a0","author":"init","version":0},{"n":264,"text":"\tconst files = (record?.files ?? spec.files).filter((rel) => existsSync(at(target, rel)));","atom":"a0","author":"init","version":0},{"n":265,"text":"\tif (files.length === 0) return undefined;","atom":"a0","author":"init","version":0},{"n":266,"text":"\tif (record) return { version: record.version, files, from: record.from, at: record.at };","atom":"a0","author":"init","version":0},{"n":267,"text":"\tlet version = \"unknown\";","atom":"a0","author":"init","version":0},{"n":268,"text":"\ttry {","atom":"a0","author":"init","version":0},{"n":269,"text":"\t\tversion = String(","atom":"a0","author":"init","version":0},{"n":270,"text":"\t\t\t(JSON.parse(readFileSync(at(target, MANIFEST), \"utf8\")) as { version?: unknown }).version ?? version,","atom":"a0","author":"init","version":0},{"n":271,"text":"\t\t);","atom":"a0","author":"init","version":0},{"n":272,"text":"\t} catch {}","atom":"a0","author":"init","version":0},{"n":273,"text":"\treturn { version, files, from: \"unknown\", at: \"unknown\" };","atom":"a0","author":"init","version":0},{"n":274,"text":"}","atom":"a0","author":"init","version":0},{"n":275,"text":"","atom":"a0","author":"init","version":0},{"n":276,"text":"/** Sleeps without an event loop, between tries of a rename. */","atom":"a0","author":"init","version":0},{"n":277,"text":"function pause(ms: number): void {","atom":"a0","author":"init","version":0},{"n":278,"text":"\tAtomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, ms);","atom":"a0","author":"init","version":0},{"n":279,"text":"}","atom":"a0","author":"init","version":0},{"n":280,"text":"","atom":"a0","author":"init","version":0},{"n":281,"text":"/** A rename, tried for about a second while Windows says another process has the file open. */","atom":"a0","author":"init","version":0},{"n":282,"text":"function renameRetrying(from: string, to: string): void {","atom":"a0","author":"init","version":0},{"n":283,"text":"\tfor (let i = 0; ; i++) {","atom":"a0","author":"init","version":0},{"n":284,"text":"\t\ttry {","atom":"a0","author":"init","version":0},{"n":285,"text":"\t\t\trenameSync(from, to);","atom":"a0","author":"init","version":0},{"n":286,"text":"\t\t\treturn;","atom":"a0","author":"init","version":0},{"n":287,"text":"\t\t} catch (err) {","atom":"a0","author":"init","version":0},{"n":288,"text":"\t\t\tconst code = (err as NodeJS.ErrnoException).code ?? \"\";","atom":"a0","author":"init","version":0},{"n":289,"text":"\t\t\tif (i >= 20 || ![\"EPERM\", \"EBUSY\", \"EACCES\"].includes(code)) throw err;","atom":"a0","author":"init","version":0},{"n":290,"text":"\t\t\tpause(50);","atom":"a0","author":"init","version":0},{"n":291,"text":"\t\t}","atom":"a0","author":"init","version":0},{"n":292,"text":"\t}","atom":"a0","author":"init","version":0},{"n":293,"text":"}","atom":"a0","author":"init","version":0},{"n":294,"text":"","atom":"a0","author":"init","version":0},{"n":295,"text":"/** Holds the mod folder's lock while fn runs. */","atom":"a0","author":"init","version":0},{"n":296,"text":"function locked<T>(target: string, fn: () => T): T {","atom":"a0","author":"init","version":0},{"n":297,"text":"\tconst file = join(target, LOCK);","atom":"a0","author":"init","version":0},{"n":298,"text":"\ttry {","atom":"a0","author":"init","version":0},{"n":299,"text":"\t\tif (Date.now() - statSync(file).mtimeMs > STALE_LOCK_MS) rmSync(file, { force: true });","atom":"a0","author":"init","version":0},{"n":300,"text":"\t} catch {}","atom":"a0","author":"init","version":0},{"n":301,"text":"\ttry {","atom":"a0","author":"init","version":0},{"n":302,"text":"\t\tcloseSync(openSync(file, \"wx\"));","atom":"a0","author":"init","version":0},{"n":303,"text":"\t} catch {","atom":"a0","author":"init","version":0},{"n":304,"text":"\t\tthrow new Error(`another install is running in ${target} (it holds ${LOCK}; if none is, delete that file)`);","atom":"a0","author":"init","version":0},{"n":305,"text":"\t}","atom":"a0","author":"init","version":0},{"n":306,"text":"\ttry {","atom":"a0","author":"init","version":0},{"n":307,"text":"\t\treturn fn();","atom":"a0","author":"init","version":0},{"n":308,"text":"\t} finally {","atom":"a0","author":"init","version":0},{"n":309,"text":"\t\trmSync(file, { force: true });","atom":"a0","author":"init","version":0},{"n":310,"text":"\t}","atom":"a0","author":"init","version":0},{"n":311,"text":"}","atom":"a0","author":"init","version":0},{"n":312,"text":"","atom":"a0","author":"init","version":0},{"n":313,"text":"/**","atom":"a0","author":"init","version":0},{"n":314,"text":" * Moves `next` into place in the mod's folder, keeping the files that were","atom":"a0","author":"init","version":0},{"n":315,"text":" * there as .prev files. Each file goes in with a rename, in `next`'s order;","atom":"a0","author":"init","version":0},{"n":316,"text":" * if one fails, the ones already moved are put back and the error is thrown.","atom":"a0","author":"init","version":0},{"n":317,"text":" */","atom":"a0","author":"init","version":0},{"n":318,"text":"function moveIn(","atom":"a0","author":"init","version":0},{"n":319,"text":"\tspec: ModSpec,","atom":"a0","author":"init","version":0},{"n":320,"text":"\ttarget: string,","atom":"a0","author":"init","version":0},{"n":321,"text":"\tnext: ReadonlyMap<string, Buffer>,","atom":"a0","author":"init","version":0},{"n":322,"text":"\tinstall: Install,","atom":"a0","author":"init","version":0},{"n":323,"text":"\trename: (from: string, to: string) => void,","atom":"a0","author":"init","version":0},{"n":324,"text":"): Install | undefined {","atom":"a0","author":"init","version":0},{"n":325,"text":"\tconst record = readRecord(target);","atom":"a0","author":"init","version":0},{"n":326,"text":"\tconst current = installedNow(spec, target, record);","atom":"a0","author":"init","version":0},{"n":327,"text":"\t// After an install that stopped midway, the folder is a mix and the .prev files still hold the last whole install.","atom":"a0","author":"init","version":0},{"n":328,"text":"\tconst prev = record?.moving ? record.prev : current;","atom":"a0","author":"init","version":0},{"n":329,"text":"\tif (!record?.moving) {","atom":"a0","author":"init","version":0},{"n":330,"text":"\t\tfor (const rel of new Set([...(record?.prev?.files ?? []), ...(current?.files ?? [])]))","atom":"a0","author":"init","version":0},{"n":331,"text":"\t\t\trmSync(at(target, rel, \".prev\"), { force: true });","atom":"a0","author":"init","version":0},{"n":332,"text":"\t\tfor (const rel of current?.files ?? []) copyFileSync(at(target, rel), at(target, rel, \".prev\"));","atom":"a0","author":"init","version":0},{"n":333,"text":"\t}","atom":"a0","author":"init","version":0},{"n":334,"text":"\tconst before: InstallRecord = { mod: spec.name, ...(current ?? install), ...(prev ? { prev } : {}) };","atom":"a0","author":"init","version":0},{"n":335,"text":"\twriteRecord(target, { ...before, moving: install.version });","atom":"a0","author":"init","version":0},{"n":336,"text":"","atom":"a0","author":"init","version":0},{"n":337,"text":"\tconst moved: string[] = [];","atom":"a0","author":"init","version":0},{"n":338,"text":"\ttry {","atom":"a0","author":"init","version":0},{"n":339,"text":"\t\tfor (const [rel, data] of next) {","atom":"a0","author":"init","version":0},{"n":340,"text":"\t\t\tmkdirSync(dirname(at(target, rel)), { recursive: true });","atom":"a0","author":"init","version":0},{"n":341,"text":"\t\t\twriteFileSync(at(target, rel, \".next\"), data);","atom":"a0","author":"init","version":0},{"n":342,"text":"\t\t}","atom":"a0","author":"init","version":0},{"n":343,"text":"\t\tfor (const rel of next.keys()) {","atom":"a0","author":"init","version":0},{"n":344,"text":"\t\t\trename(at(target, rel, \".next\"), at(target, rel));","atom":"a0","author":"init","version":0},{"n":345,"text":"\t\t\tmoved.push(rel);","atom":"a0","author":"init","version":0},{"n":346,"text":"\t\t}","atom":"a0","author":"init","version":0},{"n":347,"text":"\t} catch (err) {","atom":"a0","author":"init","version":0},{"n":348,"text":"\t\tfor (const rel of moved.reverse()) {","atom":"a0","author":"init","version":0},{"n":349,"text":"\t\t\tif (prev?.files.includes(rel)) {","atom":"a0","author":"init","version":0},{"n":350,"text":"\t\t\t\tcopyFileSync(at(target, rel, \".prev\"), at(target, rel, \".next\"));","atom":"a0","author":"init","version":0},{"n":351,"text":"\t\t\t\trenameRetrying(at(target, rel, \".next\"), at(target, rel));","atom":"a0","author":"init","version":0},{"n":352,"text":"\t\t\t} else {","atom":"a0","author":"init","version":0},{"n":353,"text":"\t\t\t\trmSync(at(target, rel), { force: true });","atom":"a0","author":"init","version":0},{"n":354,"text":"\t\t\t}","atom":"a0","author":"init","version":0},{"n":355,"text":"\t\t}","atom":"a0","author":"init","version":0},{"n":356,"text":"\t\tfor (const rel of next.keys()) rmSync(at(target, rel, \".next\"), { force: true });","atom":"a0","author":"init","version":0},{"n":357,"text":"\t\tif (current) writeRecord(target, before);","atom":"a0","author":"init","version":0},{"n":358,"text":"\t\telse rmSync(join(target, RECORD), { force: true });","atom":"a0","author":"init","version":0},{"n":359,"text":"\t\tthrow err;","atom":"a0","author":"init","version":0},{"n":360,"text":"\t}","atom":"a0","author":"init","version":0},{"n":361,"text":"\t// Files the old install had and this one doesn't.","atom":"a0","author":"init","version":0},{"n":362,"text":"\tfor (const rel of current?.files ?? []) if (!next.has(rel)) rmSync(at(target, rel), { force: true });","atom":"a0","author":"init","version":0},{"n":363,"text":"\twriteRecord(target, { mod: spec.name, ...install, ...(prev ? { prev } : {}) });","atom":"a0","author":"init","version":0},{"n":364,"text":"\treturn prev;","atom":"a0","author":"init","version":0},{"n":365,"text":"}","atom":"a0","author":"init","version":0},{"n":366,"text":"","atom":"a0","author":"init","version":0},{"n":367,"text":"/** Whether the folder holds exactly `next`. */","atom":"a0","author":"init","version":0},{"n":368,"text":"function holds(target: string, files: readonly string[], next: ReadonlyMap<string, Buffer>): boolean {","atom":"a0","author":"init","version":0},{"n":369,"text":"\treturn (","atom":"a0","author":"init","version":0},{"n":370,"text":"\t\tfiles.length === next.size && files.every((rel) => next.get(rel)?.equals(readFileSync(at(target, rel))) ?? false)","atom":"a0","author":"init","version":0},{"n":371,"text":"\t);","atom":"a0","author":"init","version":0},{"n":372,"text":"}","atom":"a0","author":"init","version":0},{"n":373,"text":"","atom":"a0","author":"init","version":0},{"n":374,"text":"/** Removes the folders a first install made, if they are empty. */","atom":"a0","author":"init","version":0},{"n":375,"text":"function removeEmpty(target: string, files: Iterable<string>): void {","atom":"a0","author":"init","version":0},{"n":376,"text":"\tconst dirs = new Set<string>();","atom":"a0","author":"init","version":0},{"n":377,"text":"\tfor (const rel of files) for (let d = dirname(at(target, rel)); d.length > target.length; d = dirname(d)) dirs.add(d);","atom":"a0","author":"init","version":0},{"n":378,"text":"\tfor (const d of [...dirs, target].sort((a, b) => b.length - a.length)) {","atom":"a0","author":"init","version":0},{"n":379,"text":"\t\ttry {","atom":"a0","author":"init","version":0},{"n":380,"text":"\t\t\trmdirSync(d);","atom":"a0","author":"init","version":0},{"n":381,"text":"\t\t} catch {}","atom":"a0","author":"init","version":0},{"n":382,"text":"\t}","atom":"a0","author":"init","version":0},{"n":383,"text":"}","atom":"a0","author":"init","version":0},{"n":384,"text":"","atom":"a0","author":"init","version":0},{"n":385,"text":"/** Installs the mod from `spec.from` into `options.target` (see the top of this file). */","atom":"a0","author":"init","version":0},{"n":386,"text":"export function installMod(spec: ModSpec, options: InstallOptions): Installed {","atom":"a0","author":"init","version":0},{"n":387,"text":"\tconst target = resolve(options.target);","atom":"a0","author":"init","version":0},{"n":388,"text":"\tconst version = versionFor(spec, options.commit);","atom":"a0","author":"init","version":0},{"n":389,"text":"\tconst next = filesFor(spec, version);","atom":"a0","author":"init","version":0},{"n":390,"text":"\tconst existed = existsSync(target);","atom":"a0","author":"init","version":0},{"n":391,"text":"\tmkdirSync(target, { recursive: true });","atom":"a0","author":"init","version":0},{"n":392,"text":"\ttry {","atom":"a0","author":"init","version":0},{"n":393,"text":"\t\treturn locked(target, () => {","atom":"a0","author":"init","version":0},{"n":394,"text":"\t\t\tconst record = readRecord(target);","atom":"a0","author":"init","version":0},{"n":395,"text":"\t\t\tconst current = installedNow(spec, target, record);","atom":"a0","author":"init","version":0},{"n":396,"text":"\t\t\tif (!record?.moving && current && holds(target, current.files, next)) {","atom":"a0","author":"init","version":0},{"n":397,"text":"\t\t\t\treturn { changed: false, version, previous: record?.prev?.version, files: next.size };","atom":"a0","author":"init","version":0},{"n":398,"text":"\t\t\t}","atom":"a0","author":"init","version":0},{"n":399,"text":"\t\t\tconst staged = mkdtempSync(join(tmpdir(), `${spec.name}-install-`));","atom":"a0","author":"init","version":0},{"n":400,"text":"\t\t\ttry {","atom":"a0","author":"init","version":0},{"n":401,"text":"\t\t\t\tfor (const [rel, data] of next) {","atom":"a0","author":"init","version":0},{"n":402,"text":"\t\t\t\t\tmkdirSync(dirname(at(staged, rel)), { recursive: true });","atom":"a0","author":"init","version":0},{"n":403,"text":"\t\t\t\t\twriteFileSync(at(staged, rel), data);","atom":"a0","author":"init","version":0},{"n":404,"text":"\t\t\t\t}","atom":"a0","author":"init","version":0},{"n":405,"text":"\t\t\t\tconst why = options.check(staged);","atom":"a0","author":"init","version":0},{"n":406,"text":"\t\t\t\tif (why !== undefined) throw new Error(`the staged copy failed its check, so nothing was changed:\\n${why}`);","atom":"a0","author":"init","version":0},{"n":407,"text":"\t\t\t} finally {","atom":"a0","author":"init","version":0},{"n":408,"text":"\t\t\t\trmSync(staged, { recursive: true, force: true });","atom":"a0","author":"init","version":0},{"n":409,"text":"\t\t\t}","atom":"a0","author":"init","version":0},{"n":410,"text":"\t\t\tconst install: Install = {","atom":"a0","author":"init","version":0},{"n":411,"text":"\t\t\t\tversion,","atom":"a0","author":"init","version":0},{"n":412,"text":"\t\t\t\tfiles: [...next.keys()],","atom":"a0","author":"init","version":0},{"n":413,"text":"\t\t\t\tfrom: spec.from,","atom":"a0","author":"init","version":0},{"n":414,"text":"\t\t\t\tat: (options.now ?? new Date()).toISOString(),","atom":"a0","author":"init","version":0},{"n":415,"text":"\t\t\t};","atom":"a0","author":"init","version":0},{"n":416,"text":"\t\t\tconst prev = moveIn(spec, target, next, install, options.rename ?? renameRetrying);","atom":"a0","author":"init","version":0},{"n":417,"text":"\t\t\treturn { changed: true, version, previous: prev?.version, files: next.size };","atom":"a0","author":"init","version":0},{"n":418,"text":"\t\t});","atom":"a0","author":"init","version":0},{"n":419,"text":"\t} catch (err) {","atom":"a0","author":"init","version":0},{"n":420,"text":"\t\t// A first install that didn't happen leaves no folder behind.","atom":"a0","author":"init","version":0},{"n":421,"text":"\t\tif (!existed) removeEmpty(target, next.keys());","atom":"a0","author":"init","version":0},{"n":422,"text":"\t\tthrow err;","atom":"a0","author":"init","version":0},{"n":423,"text":"\t}","atom":"a0","author":"init","version":0},{"n":424,"text":"}","atom":"a0","author":"init","version":0},{"n":425,"text":"","atom":"a0","author":"init","version":0},{"n":426,"text":"/** Puts the install kept in the .prev files back; the one it replaces becomes the .prev one. */","atom":"a0","author":"init","version":0},{"n":427,"text":"export function rollbackMod(spec: ModSpec, options: Pick<InstallOptions, \"target\" | \"rename\" | \"now\">): Installed {","atom":"a0","author":"init","version":0},{"n":428,"text":"\tconst target = resolve(options.target);","atom":"a0","author":"init","version":0},{"n":429,"text":"\tif (!existsSync(target)) throw new Error(`nothing is installed in ${target}`);","atom":"a0","author":"init","version":0},{"n":430,"text":"\treturn locked(target, () => {","atom":"a0","author":"init","version":0},{"n":431,"text":"\t\tconst record = readRecord(target);","atom":"a0","author":"init","version":0},{"n":432,"text":"\t\tconst prev = record?.prev;","atom":"a0","author":"init","version":0},{"n":433,"text":"\t\tif (!prev) throw new Error(`no earlier install is kept in ${target}`);","atom":"a0","author":"init","version":0},{"n":434,"text":"\t\tconst missing = prev.files.filter((rel) => !existsSync(at(target, rel, \".prev\")));","atom":"a0","author":"init","version":0},{"n":435,"text":"\t\tif (missing.length > 0)","atom":"a0","author":"init","version":0},{"n":436,"text":"\t\t\tthrow new Error(","atom":"a0","author":"init","version":0},{"n":437,"text":"\t\t\t\t`the earlier install's ${missing.join(\", \")} ${missing.length === 1 ? \"is\" : \"are\"} missing from ${target}`,","atom":"a0","author":"init","version":0},{"n":438,"text":"\t\t\t);","atom":"a0","author":"init","version":0},{"n":439,"text":"\t\tconst next = new Map(prev.files.map((rel) => [rel, readFileSync(at(target, rel, \".prev\"))]));","atom":"a0","author":"init","version":0},{"n":440,"text":"\t\tconst kept = moveIn(spec, target, next, prev, options.rename ?? renameRetrying);","atom":"a0","author":"init","version":0},{"n":441,"text":"\t\treturn { changed: true, version: prev.version, previous: kept?.version, files: next.size };","atom":"a0","author":"init","version":0},{"n":442,"text":"\t});","atom":"a0","author":"init","version":0},{"n":443,"text":"}","atom":"a0","author":"init","version":0},{"n":444,"text":"","atom":"a0","author":"init","version":0},{"n":445,"text":"/** `claude plugin validate`, then the mod's own tests in Claude Code's plugin test kit, on a staged copy. */","atom":"a0","author":"init","version":0},{"n":446,"text":"export function checkWithClaude(spec: ModSpec): (dir: string) => string | undefined {","atom":"a0","author":"init","version":0},{"n":447,"text":"\t// claude is a .cmd on Windows, so it runs through the shell; the folder is quoted.","atom":"a0","author":"init","version":0},{"n":448,"text":"\tconst claude = (what: string, dir: string) =>","atom":"a0","author":"init","version":0},{"n":449,"text":"\t\tspawnSync(`claude plugin ${what} \"${dir}\"`, { shell: true, encoding: \"utf8\", timeout: 180_000 });","atom":"a0","author":"init","version":0},{"n":450,"text":"\tconst tail = (r: { stdout: string; stderr: string }) =>","atom":"a0","author":"init","version":0},{"n":451,"text":"\t\t`${r.stdout ?? \"\"}${r.stderr ?? \"\"}`.trim().split(\"\\n\").slice(-15).join(\"\\n\");","atom":"a0","author":"init","version":0},{"n":452,"text":"\treturn (dir) => {","atom":"a0","author":"init","version":0},{"n":453,"text":"\t\tconst valid = claude(\"validate\", dir);","atom":"a0","author":"init","version":0},{"n":454,"text":"\t\tif (valid.status !== 0) return `claude plugin validate failed (--unchecked skips the check):\\n${tail(valid)}`;","atom":"a0","author":"init","version":0},{"n":455,"text":"\t\tif (spec.test === undefined) return undefined;","atom":"a0","author":"init","version":0},{"n":456,"text":"\t\tcopyFileSync(at(spec.from, spec.test), at(dir, spec.test));","atom":"a0","author":"init","version":0},{"n":457,"text":"\t\tconst tests = claude(\"test\", dir);","atom":"a0","author":"init","version":0},{"n":458,"text":"\t\tif (tests.status !== 0) return `the mod's tests failed on the staged copy:\\n${tail(tests)}`;","atom":"a0","author":"init","version":0},{"n":459,"text":"\t\treturn undefined;","atom":"a0","author":"init","version":0},{"n":460,"text":"\t};","atom":"a0","author":"init","version":0},{"n":461,"text":"}","atom":"a0","author":"init","version":0},{"n":462,"text":"","atom":"a0","author":"init","version":0},{"n":463,"text":"/** The installers' command line: [folder] [--rollback] [--unchecked]. */","atom":"a0","author":"init","version":0},{"n":464,"text":"export function runInstaller(","atom":"a0","author":"init","version":0},{"n":465,"text":"\tspec: ModSpec,","atom":"a0","author":"init","version":0},{"n":466,"text":"\tscript: string,","atom":"a0","author":"init","version":0},{"n":467,"text":"\tdefaultTarget: string,","atom":"a0","author":"init","version":0},{"n":468,"text":"\targv: readonly string[] = process.argv.slice(2),","atom":"a0","author":"init","version":0},{"n":469,"text":"): void {","atom":"a0","author":"init","version":0},{"n":470,"text":"\tconst options = argv.filter((a) => a.startsWith(\"--\"));","atom":"a0","author":"init","version":0},{"n":471,"text":"\tconst folders = argv.filter((a) => !a.startsWith(\"--\"));","atom":"a0","author":"init","version":0},{"n":472,"text":"\tconst unknown = options.find((o) => o !== \"--rollback\" && o !== \"--unchecked\");","atom":"a0","author":"init","version":0},{"n":473,"text":"\tif (unknown !== undefined || folders.length > 1) {","atom":"a0","author":"init","version":0},{"n":474,"text":"\t\tconsole.error(","atom":"a0","author":"init","version":0},{"n":475,"text":"\t\t\t`usage: node client/${script} [folder] [--rollback] [--unchecked]${unknown ? ` (unknown option ${unknown})` : \"\"}`,","atom":"a0","author":"init","version":0},{"n":476,"text":"\t\t);","atom":"a0","author":"init","version":0},{"n":477,"text":"\t\tprocess.exit(2);","atom":"a0","author":"init","version":0},{"n":478,"text":"\t}","atom":"a0","author":"init","version":0},{"n":479,"text":"\tconst target = resolve(folders[0] ?? defaultTarget);","atom":"a0","author":"init","version":0},{"n":480,"text":"\ttry {","atom":"a0","author":"init","version":0},{"n":481,"text":"\t\tif (options.includes(\"--rollback\")) {","atom":"a0","author":"init","version":0},{"n":482,"text":"\t\t\tconst r = rollbackMod(spec, { target });","atom":"a0","author":"init","version":0},{"n":483,"text":"\t\t\tconsole.log(","atom":"a0","author":"init","version":0},{"n":484,"text":"\t\t\t\t`Rolled the ${spec.name} mod back to ${r.version} in ${target}. ${r.previous ? `${r.previous} is kept; --rollback again puts it back. ` : \"\"}Restart open chats to load it.`,","atom":"a0","author":"init","version":0},{"n":485,"text":"\t\t\t);","atom":"a0","author":"init","version":0},{"n":486,"text":"\t\t\treturn;","atom":"a0","author":"init","version":0},{"n":487,"text":"\t\t}","atom":"a0","author":"init","version":0},{"n":488,"text":"\t\tconst unchecked = options.includes(\"--unchecked\");","atom":"a0","author":"init","version":0},{"n":489,"text":"\t\tconst r = installMod(spec, { target, check: unchecked ? () => undefined : checkWithClaude(spec) });","atom":"a0","author":"init","version":0},{"n":490,"text":"\t\t// Only for the real skills folder: an install to another folder leaves the old mod alone.","atom":"a399","author":"review","version":40},{"n":491,"text":"\t\tconst retired = target === resolve(skillsFolder(spec.name)) ? retireOldMod(spec) : undefined;","atom":"a399","author":"review","version":40},{"n":492,"text":"\t\tif (retired) console.log(`Moved the old ${OLD_MOD_NAMES[spec.name]} mod out of the skills folder, to ${retired}.`);","atom":"a399","author":"review","version":40},{"n":493,"text":"\t\tif (!r.changed) {","atom":"a0","author":"init","version":0},{"n":494,"text":"\t\t\tconsole.log(`The ${spec.name} mod ${r.version} is already installed in ${target}; nothing changed.`);","atom":"a0","author":"init","version":0},{"n":495,"text":"\t\t\treturn;","atom":"a0","author":"init","version":0},{"n":496,"text":"\t\t}","atom":"a0","author":"init","version":0},{"n":497,"text":"\t\tconst kept = r.previous ? ` The one it replaced (${r.previous}) is kept; --rollback puts it back.` : \"\";","atom":"a0","author":"init","version":0},{"n":498,"text":"\t\tconsole.log(","atom":"a0","author":"init","version":0},{"n":499,"text":"\t\t\t`Installed the ${spec.name} mod ${r.version} in ${target} (${r.files} files${unchecked ? \", unchecked\" : \", validated and tested first\"}).${kept} New chats load it; restart open ones to load it.`,","atom":"a0","author":"init","version":0},{"n":500,"text":"\t\t);","atom":"a0","author":"init","version":0},{"n":501,"text":"\t} catch (err) {","atom":"a0","author":"init","version":0},{"n":502,"text":"\t\tconsole.error(","atom":"a0","author":"init","version":0},{"n":503,"text":"\t\t\t`The ${spec.name} mod was not ${options.includes(\"--rollback\") ? \"rolled back\" : \"installed\"}: ${(err as Error).message}`,","atom":"a0","author":"init","version":0},{"n":504,"text":"\t\t);","atom":"a0","author":"init","version":0},{"n":505,"text":"\t\tprocess.exit(1);","atom":"a0","author":"init","version":0},{"n":506,"text":"\t}","atom":"a0","author":"init","version":0},{"n":507,"text":"}","atom":"a0","author":"init","version":0},{"n":508,"text":"","atom":"a0","author":"init","version":0},{"n":509,"text":"export interface ModInstall {","atom":"a0","author":"init","version":0},{"n":510,"text":"\treadonly name: string;","atom":"a0","author":"init","version":0},{"n":511,"text":"\treadonly folder: string;","atom":"a0","author":"init","version":0},{"n":512,"text":"\t/** Undefined when it isn't installed. */","atom":"a0","author":"init","version":0},{"n":513,"text":"\treadonly version: string | undefined;","atom":"a0","author":"init","version":0},{"n":514,"text":"\t/** When it was installed (mods installed before .avcs-install.json have none). */","atom":"a0","author":"init","version":0},{"n":515,"text":"\treadonly at: string | undefined;","atom":"a0","author":"init","version":0},{"n":516,"text":"\t/** What an install from this client would stamp now. */","atom":"a0","author":"init","version":0},{"n":517,"text":"\treadonly current: string;","atom":"a0","author":"init","version":0},{"n":518,"text":"}","atom":"a0","author":"init","version":0},{"n":519,"text":"","atom":"a0","author":"init","version":0},{"n":520,"text":"/** `avcs --version`: this client, and the mods installed on this machine, compared with this client's. */","atom":"a0","author":"init","version":0},{"n":521,"text":"export function versionReport(env: Readonly<Record<string, string | undefined>>): {","atom":"a0","author":"init","version":0},{"n":522,"text":"\ttext: string;","atom":"a0","author":"init","version":0},{"n":523,"text":"\tjson: Record<string, unknown>;","atom":"a0","author":"init","version":0},{"n":524,"text":"} {","atom":"a0","author":"init","version":0},{"n":525,"text":"\tconst client = clientVersion();","atom":"a0","author":"init","version":0},{"n":526,"text":"\tconst lines = [`abso ${client} (${clientPlace()})`];","atom":"a0","author":"init","version":0},{"n":527,"text":"\tconst mods: ModInstall[] = [];","atom":"a0","author":"init","version":0},{"n":528,"text":"\tfor (const [spec, installer] of [","atom":"a0","author":"init","version":0},{"n":529,"text":"\t\t[AVCS_MOD, \"install-mod.ts\"],","atom":"a0","author":"init","version":0},{"n":530,"text":"\t\t[VIEW_MOD, \"install-view.ts\"],","atom":"a0","author":"init","version":0},{"n":531,"text":"\t] as const) {","atom":"a0","author":"init","version":0},{"n":532,"text":"\t\tconst folder = skillsFolder(spec.name, env);","atom":"a0","author":"init","version":0},{"n":533,"text":"\t\tconst field = (rel: string, key: string): string | undefined => {","atom":"a0","author":"init","version":0},{"n":534,"text":"\t\t\ttry {","atom":"a0","author":"init","version":0},{"n":535,"text":"\t\t\t\tconst value = (JSON.parse(readFileSync(at(folder, rel), \"utf8\")) as Record<string, unknown>)[key];","atom":"a0","author":"init","version":0},{"n":536,"text":"\t\t\t\treturn typeof value === \"string\" ? value : undefined;","atom":"a0","author":"init","version":0},{"n":537,"text":"\t\t\t} catch {","atom":"a0","author":"init","version":0},{"n":538,"text":"\t\t\t\treturn undefined;","atom":"a0","author":"init","version":0},{"n":539,"text":"\t\t\t}","atom":"a0","author":"init","version":0},{"n":540,"text":"\t\t};","atom":"a0","author":"init","version":0},{"n":541,"text":"\t\tconst m: ModInstall = {","atom":"a0","author":"init","version":0},{"n":542,"text":"\t\t\tname: spec.name,","atom":"a0","author":"init","version":0},{"n":543,"text":"\t\t\tfolder,","atom":"a0","author":"init","version":0},{"n":544,"text":"\t\t\tversion: field(MANIFEST, \"version\"),","atom":"a0","author":"init","version":0},{"n":545,"text":"\t\t\tat: field(RECORD, \"at\"),","atom":"a0","author":"init","version":0},{"n":546,"text":"\t\t\tcurrent: (() => {","atom":"a0","author":"init","version":0},{"n":547,"text":"\t\t\t\ttry {","atom":"a0","author":"init","version":0},{"n":548,"text":"\t\t\t\t\treturn versionFor(spec, keptModCommit(spec));","atom":"a424","author":"speed","version":43},{"n":549,"text":"\t\t\t\t} catch {","atom":"a0","author":"init","version":0},{"n":550,"text":"\t\t\t\t\treturn \"not in this copy\";","atom":"a0","author":"init","version":0},{"n":551,"text":"\t\t\t\t}","atom":"a0","author":"init","version":0},{"n":552,"text":"\t\t\t})(),","atom":"a0","author":"init","version":0},{"n":553,"text":"\t\t};","atom":"a0","author":"init","version":0},{"n":554,"text":"\t\tmods.push(m);","atom":"a0","author":"init","version":0},{"n":555,"text":"\t\tif (m.version === undefined) {","atom":"a0","author":"init","version":0},{"n":556,"text":"\t\t\tlines.push(`the ${m.name} mod: not installed (node client/${installer})`);","atom":"a0","author":"init","version":0},{"n":557,"text":"\t\t\tcontinue;","atom":"a0","author":"init","version":0},{"n":558,"text":"\t\t}","atom":"a0","author":"init","version":0},{"n":559,"text":"\t\tconst when = m.at ? `, installed ${m.at.slice(0, 16).replace(\"T\", \" \")} UTC` : \"\";","atom":"a0","author":"init","version":0},{"n":560,"text":"\t\tconst behind =","atom":"a0","author":"init","version":0},{"n":561,"text":"\t\t\tm.version === m.current ? \"\" : `; this client has ${m.current}: node client/${installer} installs it`;","atom":"a0","author":"init","version":0},{"n":562,"text":"\t\tlines.push(`the ${m.name} mod: ${m.version} in ${m.folder}${when}${behind}`);","atom":"a0","author":"init","version":0},{"n":563,"text":"\t}","atom":"a0","author":"init","version":0},{"n":564,"text":"\treturn { text: lines.join(\"\\n\"), json: { client, folder: CLIENT_DIR, mods } };","atom":"a0","author":"init","version":0},{"n":565,"text":"}","atom":"a0","author":"init","version":0},{"n":566,"text":"","atom":"a0","author":"init","version":0},{"n":567,"text":"/**","atom":"a0","author":"init","version":0},{"n":568,"text":" * For `abso status` (abso issue 41: every chat ran a mod a day behind main,","atom":"a0","author":"init","version":0},{"n":569,"text":" * and only `--version` would have said so): each installed mod this client","atom":"a0","author":"init","version":0},{"n":570,"text":" * would install differently. Says nothing unless this client knows its mod's","atom":"a0","author":"init","version":0},{"n":571,"text":" * commit (a git checkout, as the shared one is) and the installed one has one.","atom":"a0","author":"init","version":0},{"n":572,"text":" */","atom":"a0","author":"init","version":0},{"n":573,"text":"export function modsBehindText(env: Readonly<Record<string, string | undefined>>): string[] {","atom":"a0","author":"init","version":0},{"n":574,"text":"\tconst installers: Record<string, string> = { [AVCS_MOD.name]: \"install-mod.ts\", [VIEW_MOD.name]: \"install-view.ts\" };","atom":"a0","author":"init","version":0},{"n":575,"text":"\treturn (versionReport(env).json.mods as ModInstall[])","atom":"a0","author":"init","version":0},{"n":576,"text":"\t\t.filter((m) => m.version?.includes(\"+\") && /\\+[0-9a-f]{7}$/.test(m.current) && m.version !== m.current)","atom":"a0","author":"init","version":0},{"n":577,"text":"\t\t.map(","atom":"a0","author":"init","version":0},{"n":578,"text":"\t\t\t(m) =>","atom":"a0","author":"init","version":0},{"n":579,"text":"\t\t\t\t`The ${m.name} mod installed on this machine is ${m.version}, and this client has ${m.current}: node client/${installers[m.name]} installs it (new chats load it).`,","atom":"a0","author":"init","version":0},{"n":580,"text":"\t\t);","atom":"a0","author":"init","version":0},{"n":581,"text":"}","atom":"a0","author":"init","version":0}],"atoms":[{"atom":"a0","author":"init","message":"Start the project","time":1791506895507,"timeIso":"2026-10-09T00:48:15.507Z","publish":{"draft":null,"version":0,"agent":"init","message":"Start the project","time":1791506895507,"timeIso":"2026-10-09T00:48:15.507Z"}},{"atom":"a399","author":"review","message":"","time":1791549456768,"timeIso":"2026-10-09T12:37:36.768Z","publish":{"draft":null,"version":40,"agent":"review","message":"Mods: the hooks mod is abso-hooks and the view mod abso-view; an install moves the old skills/avcs and skills/avcs-view folders to ~/.abso/retired-mods (moved, not deleted); the hook stands down for either name; status checks either. Tests cover the move.","time":1791549457128,"timeIso":"2026-10-09T12:37:37.128Z"}},{"atom":"a419","author":"speed","message":"","time":1791555878302,"timeIso":"2026-10-09T14:24:38.302Z","publish":{"draft":null,"version":43,"agent":"speed","message":"status: keep each mod's commit between runs (~/.abso/mod-commits.json), keyed on the checkout's commit read from .git and each mod file's size, time and inode, so status runs no git while nothing moved; files changed too recently to trust are asked again; outside a git checkout git isn't run","time":1791556436079,"timeIso":"2026-10-09T14:33:56.079Z"}},{"atom":"a420","author":"speed","message":"","time":1791555880396,"timeIso":"2026-10-09T14:24:40.396Z","publish":{"draft":null,"version":43,"agent":"speed","message":"status: keep each mod's commit between runs (~/.abso/mod-commits.json), keyed on the checkout's commit read from .git and each mod file's size, time and inode, so status runs no git while nothing moved; files changed too recently to trust are asked again; outside a git checkout git isn't run","time":1791556436079,"timeIso":"2026-10-09T14:33:56.079Z"}},{"atom":"a424","author":"speed","message":"","time":1791556104322,"timeIso":"2026-10-09T14:28:24.322Z","publish":{"draft":null,"version":43,"agent":"speed","message":"status: keep each mod's commit between runs (~/.abso/mod-commits.json), keyed on the checkout's commit read from .git and each mod file's size, time and inode, so status runs no git while nothing moved; files changed too recently to trust are asked again; outside a git checkout git isn't run","time":1791556436079,"timeIso":"2026-10-09T14:33:56.079Z"}},{"atom":"a495","author":"pinch","message":"","time":1791586659806,"timeIso":"2026-10-09T22:57:39.806Z","publish":{"draft":null,"version":54,"agent":"pinch","message":"The client and the edit mods send and read X-Abso-* headers only (Client, Name, Run-Key, Kind, Admin; Run, Box, Prep from answers). Servers have read X-Abso-* beside the old names for a while and answer under both, so this works with any current server.","time":1791586669845,"timeIso":"2026-10-09T22:57:49.845Z"}}]}