{"file":"client/src/modes.ts","version":318,"total":149,"from":1,"to":149,"lines":[{"n":1,"text":"// The executable bit and symbolic links (#27, contract 7d49f0a).","atom":"a0","author":"init","version":0},{"n":2,"text":"//","atom":"a0","author":"init","version":0},{"n":3,"text":"// The server holds each file's mode beside its text: whether it is","atom":"a0","author":"init","version":0},{"n":4,"text":"// executable, and whether it is a symbolic link (whose text is \"\"). The client","atom":"a0","author":"init","version":0},{"n":5,"text":"// keeps the modes it knows in .avcs/modes.json, as it keeps the known copy of","atom":"a0","author":"init","version":0},{"n":6,"text":"// the text, and sends only what changed.","atom":"a0","author":"init","version":0},{"n":7,"text":"//","atom":"a0","author":"init","version":0},{"n":8,"text":"// Windows has no executable bit, so there (like git's core.fileMode=false)","atom":"a0","author":"init","version":0},{"n":9,"text":"// the bit is never read from disk: a file keeps the bit the server has. A","atom":"a0","author":"init","version":0},{"n":10,"text":"// link is never followed. Where a link can't be made (Windows without the","atom":"a0","author":"init","version":0},{"n":11,"text":"// right to make links), the client writes a plain file holding the target,","atom":"a0","author":"init","version":0},{"n":12,"text":"// as git does with core.symlinks=false, and that file counts as the link.","atom":"a0","author":"init","version":0},{"n":13,"text":"","atom":"a0","author":"init","version":0},{"n":14,"text":"import {","atom":"a0","author":"init","version":0},{"n":15,"text":"\tchmodSync,","atom":"a0","author":"init","version":0},{"n":16,"text":"\tlstatSync,","atom":"a0","author":"init","version":0},{"n":17,"text":"\tmkdirSync,","atom":"a0","author":"init","version":0},{"n":18,"text":"\treadFileSync,","atom":"a0","author":"init","version":0},{"n":19,"text":"\treadlinkSync,","atom":"a0","author":"init","version":0},{"n":20,"text":"\tstatSync,","atom":"a0","author":"init","version":0},{"n":21,"text":"\tsymlinkSync,","atom":"a0","author":"init","version":0},{"n":22,"text":"\tunlinkSync,","atom":"a0","author":"init","version":0},{"n":23,"text":"\twriteFileSync,","atom":"a0","author":"init","version":0},{"n":24,"text":"} from \"node:fs\";","atom":"a0","author":"init","version":0},{"n":25,"text":"import { dirname, join } from \"node:path\";","atom":"a0","author":"init","version":0},{"n":26,"text":"import { readText, writeFileAtomic } from \"./folder.ts\";","atom":"a0","author":"init","version":0},{"n":27,"text":"import { stateDir } from \"./state-dir.ts\";","atom":"a111","author":"review","version":17},{"n":28,"text":"","atom":"a0","author":"init","version":0},{"n":29,"text":"/** A change to a file's mode: only the fields given change. */","atom":"a0","author":"init","version":0},{"n":30,"text":"export interface Mode {","atom":"a0","author":"init","version":0},{"n":31,"text":"\treadonly exec?: boolean;","atom":"a0","author":"init","version":0},{"n":32,"text":"\treadonly link?: string | null;","atom":"a0","author":"init","version":0},{"n":33,"text":"}","atom":"a0","author":"init","version":0},{"n":34,"text":"export type Modes = Readonly<Record<string, Mode>>;","atom":"a0","author":"init","version":0},{"n":35,"text":"","atom":"a0","author":"init","version":0},{"n":36,"text":"/** A file's whole mode. */","atom":"a0","author":"init","version":0},{"n":37,"text":"export interface FullMode {","atom":"a0","author":"init","version":0},{"n":38,"text":"\treadonly exec: boolean;","atom":"a0","author":"init","version":0},{"n":39,"text":"\treadonly link: string | null;","atom":"a0","author":"init","version":0},{"n":40,"text":"}","atom":"a0","author":"init","version":0},{"n":41,"text":"","atom":"a0","author":"init","version":0},{"n":42,"text":"export const PLAIN: FullMode = { exec: false, link: null };","atom":"a0","author":"init","version":0},{"n":43,"text":"","atom":"a0","author":"init","version":0},{"n":44,"text":"/** Whether this disk keeps the executable bit (git's core.fileMode). */","atom":"a0","author":"init","version":0},{"n":45,"text":"export const FILE_MODE = process.platform !== \"win32\";","atom":"a0","author":"init","version":0},{"n":46,"text":"","atom":"a0","author":"init","version":0},{"n":47,"text":"const MODES_FILE = \"modes.json\";","atom":"a0","author":"init","version":0},{"n":48,"text":"","atom":"a0","author":"init","version":0},{"n":49,"text":"function modesPath(root: string): string {","atom":"a0","author":"init","version":0},{"n":50,"text":"\treturn join(stateDir(root), MODES_FILE);","atom":"a111","author":"review","version":17},{"n":51,"text":"}","atom":"a0","author":"init","version":0},{"n":52,"text":"","atom":"a0","author":"init","version":0},{"n":53,"text":"/** The modes the server has, as far as the client knows: only files that are executable or links. */","atom":"a0","author":"init","version":0},{"n":54,"text":"export function readKnownModes(root: string): Map<string, FullMode> {","atom":"a0","author":"init","version":0},{"n":55,"text":"\ttry {","atom":"a0","author":"init","version":0},{"n":56,"text":"\t\tconst raw = JSON.parse(readFileSync(modesPath(root), \"utf8\")) as Record<string, Partial<FullMode>>;","atom":"a0","author":"init","version":0},{"n":57,"text":"\t\treturn new Map(","atom":"a0","author":"init","version":0},{"n":58,"text":"\t\t\tObject.entries(raw).map(([rel, m]) => [","atom":"a0","author":"init","version":0},{"n":59,"text":"\t\t\t\trel,","atom":"a0","author":"init","version":0},{"n":60,"text":"\t\t\t\t{ exec: m.exec === true, link: typeof m.link === \"string\" ? m.link : null },","atom":"a0","author":"init","version":0},{"n":61,"text":"\t\t\t]),","atom":"a0","author":"init","version":0},{"n":62,"text":"\t\t);","atom":"a0","author":"init","version":0},{"n":63,"text":"\t} catch {","atom":"a0","author":"init","version":0},{"n":64,"text":"\t\treturn new Map();","atom":"a0","author":"init","version":0},{"n":65,"text":"\t}","atom":"a0","author":"init","version":0},{"n":66,"text":"}","atom":"a0","author":"init","version":0},{"n":67,"text":"","atom":"a0","author":"init","version":0},{"n":68,"text":"export function writeKnownModes(root: string, modes: ReadonlyMap<string, FullMode>): void {","atom":"a0","author":"init","version":0},{"n":69,"text":"\tconst out: Record<string, Partial<FullMode>> = {};","atom":"a0","author":"init","version":0},{"n":70,"text":"\tfor (const [rel, m] of [...modes].sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0))) {","atom":"a0","author":"init","version":0},{"n":71,"text":"\t\tif (m.exec || m.link !== null)","atom":"a0","author":"init","version":0},{"n":72,"text":"\t\t\tout[rel] = { ...(m.exec ? { exec: true } : {}), ...(m.link !== null ? { link: m.link } : {}) };","atom":"a0","author":"init","version":0},{"n":73,"text":"\t}","atom":"a0","author":"init","version":0},{"n":74,"text":"\twriteFileAtomic(modesPath(root), `${JSON.stringify(out, null, 1)}\\n`);","atom":"a0","author":"init","version":0},{"n":75,"text":"}","atom":"a0","author":"init","version":0},{"n":76,"text":"","atom":"a0","author":"init","version":0},{"n":77,"text":"/** Fold mode changes (only the fields given) into the known modes; a deleted file loses its entry. */","atom":"a0","author":"init","version":0},{"n":78,"text":"export function foldModes(known: Map<string, FullMode>, modes: Modes, deleted: Iterable<string> = []): void {","atom":"a0","author":"init","version":0},{"n":79,"text":"\tfor (const [rel, m] of Object.entries(modes)) {","atom":"a0","author":"init","version":0},{"n":80,"text":"\t\tconst was = known.get(rel) ?? PLAIN;","atom":"a0","author":"init","version":0},{"n":81,"text":"\t\tknown.set(rel, { exec: m.exec ?? was.exec, link: m.link === undefined ? was.link : m.link });","atom":"a0","author":"init","version":0},{"n":82,"text":"\t}","atom":"a0","author":"init","version":0},{"n":83,"text":"\tfor (const rel of deleted) known.delete(rel);","atom":"a0","author":"init","version":0},{"n":84,"text":"}","atom":"a0","author":"init","version":0},{"n":85,"text":"","atom":"a0","author":"init","version":0},{"n":86,"text":"/** What a path holds, judged as the server sees it; undefined when it is gone. `text` is undefined for a binary file. */","atom":"a0","author":"init","version":0},{"n":87,"text":"export interface OnDisk {","atom":"a0","author":"init","version":0},{"n":88,"text":"\treadonly text: string | undefined;","atom":"a0","author":"init","version":0},{"n":89,"text":"\treadonly exec: boolean;","atom":"a0","author":"init","version":0},{"n":90,"text":"\treadonly link: string | null;","atom":"a0","author":"init","version":0},{"n":91,"text":"\t/** A plain file standing in for a link that couldn't be made. */","atom":"a0","author":"init","version":0},{"n":92,"text":"\treadonly standIn: boolean;","atom":"a0","author":"init","version":0},{"n":93,"text":"}","atom":"a0","author":"init","version":0},{"n":94,"text":"","atom":"a0","author":"init","version":0},{"n":95,"text":"export function onDisk(path: string, known: FullMode = PLAIN): OnDisk | undefined {","atom":"a0","author":"init","version":0},{"n":96,"text":"\tlet st;","atom":"a0","author":"init","version":0},{"n":97,"text":"\ttry {","atom":"a0","author":"init","version":0},{"n":98,"text":"\t\tst = lstatSync(path);","atom":"a0","author":"init","version":0},{"n":99,"text":"\t} catch {","atom":"a0","author":"init","version":0},{"n":100,"text":"\t\treturn undefined;","atom":"a0","author":"init","version":0},{"n":101,"text":"\t}","atom":"a0","author":"init","version":0},{"n":102,"text":"\tif (st.isSymbolicLink())","atom":"a0","author":"init","version":0},{"n":103,"text":"\t\treturn { text: \"\", exec: known.exec, link: readlinkSync(path).replace(/\\\\/g, \"/\"), standIn: false };","atom":"a0","author":"init","version":0},{"n":104,"text":"\tif (known.link !== null) {","atom":"a0","author":"init","version":0},{"n":105,"text":"\t\t// A stand-in: the file holds the target; editing it changes the target, as in git.","atom":"a0","author":"init","version":0},{"n":106,"text":"\t\tconst raw = readText(path);","atom":"a0","author":"init","version":0},{"n":107,"text":"\t\tif (raw !== undefined) return { text: \"\", exec: known.exec, link: raw.replace(/\\r?\\n$/, \"\"), standIn: true };","atom":"a0","author":"init","version":0},{"n":108,"text":"\t}","atom":"a0","author":"init","version":0},{"n":109,"text":"\treturn { text: readText(path), exec: FILE_MODE ? (st.mode & 0o111) !== 0 : known.exec, link: null, standIn: false };","atom":"a0","author":"init","version":0},{"n":110,"text":"}","atom":"a0","author":"init","version":0},{"n":111,"text":"","atom":"a0","author":"init","version":0},{"n":112,"text":"/** The fields of `now` that differ from `was`, or undefined when none do. */","atom":"a0","author":"init","version":0},{"n":113,"text":"export function modeChange(was: FullMode, now: FullMode): Mode | undefined {","atom":"a0","author":"init","version":0},{"n":114,"text":"\tconst out: { exec?: boolean; link?: string | null } = {};","atom":"a0","author":"init","version":0},{"n":115,"text":"\tif (now.exec !== was.exec) out.exec = now.exec;","atom":"a0","author":"init","version":0},{"n":116,"text":"\tif (now.link !== was.link) out.link = now.link;","atom":"a0","author":"init","version":0},{"n":117,"text":"\treturn Object.keys(out).length === 0 ? undefined : out;","atom":"a0","author":"init","version":0},{"n":118,"text":"}","atom":"a0","author":"init","version":0},{"n":119,"text":"","atom":"a0","author":"init","version":0},{"n":120,"text":"/**","atom":"a0","author":"init","version":0},{"n":121,"text":" * Put a file's mode on disk: make the link (or its stand-in), or set the","atom":"a0","author":"init","version":0},{"n":122,"text":" * executable bit where the disk keeps it. The file's text is already written.","atom":"a0","author":"init","version":0},{"n":123,"text":" */","atom":"a0","author":"init","version":0},{"n":124,"text":"export function applyMode(path: string, mode: FullMode): void {","atom":"a0","author":"init","version":0},{"n":125,"text":"\tif (mode.link !== null) {","atom":"a0","author":"init","version":0},{"n":126,"text":"\t\ttry {","atom":"a0","author":"init","version":0},{"n":127,"text":"\t\t\tunlinkSync(path);","atom":"a0","author":"init","version":0},{"n":128,"text":"\t\t} catch {","atom":"a0","author":"init","version":0},{"n":129,"text":"\t\t\t// Not there yet.","atom":"a0","author":"init","version":0},{"n":130,"text":"\t\t}","atom":"a0","author":"init","version":0},{"n":131,"text":"\t\tmkdirSync(dirname(path), { recursive: true });","atom":"a0","author":"init","version":0},{"n":132,"text":"\t\ttry {","atom":"a0","author":"init","version":0},{"n":133,"text":"\t\t\tsymlinkSync(mode.link, path);","atom":"a0","author":"init","version":0},{"n":134,"text":"\t\t} catch (err) {","atom":"a0","author":"init","version":0},{"n":135,"text":"\t\t\tconst code = (err as NodeJS.ErrnoException).code;","atom":"a0","author":"init","version":0},{"n":136,"text":"\t\t\tif (code !== \"EPERM\" && code !== \"EACCES\" && code !== \"ENOTSUP\") throw err;","atom":"a0","author":"init","version":0},{"n":137,"text":"\t\t\twriteFileSync(path, mode.link);","atom":"a0","author":"init","version":0},{"n":138,"text":"\t\t}","atom":"a0","author":"init","version":0},{"n":139,"text":"\t\treturn;","atom":"a0","author":"init","version":0},{"n":140,"text":"\t}","atom":"a0","author":"init","version":0},{"n":141,"text":"\tif (!FILE_MODE) return;","atom":"a0","author":"init","version":0},{"n":142,"text":"\ttry {","atom":"a0","author":"init","version":0},{"n":143,"text":"\t\tconst bits = statSync(path).mode & 0o777;","atom":"a0","author":"init","version":0},{"n":144,"text":"\t\tconst want = mode.exec ? bits | ((bits & 0o444) >> 2) : bits & ~0o111;","atom":"a0","author":"init","version":0},{"n":145,"text":"\t\tif (want !== bits) chmodSync(path, want);","atom":"a0","author":"init","version":0},{"n":146,"text":"\t} catch {","atom":"a0","author":"init","version":0},{"n":147,"text":"\t\t// Gone, or not ours to change.","atom":"a0","author":"init","version":0},{"n":148,"text":"\t}","atom":"a0","author":"init","version":0},{"n":149,"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":"a111","author":"review","message":"","time":1791522261912,"timeIso":"2026-10-09T05:04:21.912Z","publish":{"draft":null,"version":17,"agent":"review","message":"New folders keep their state in .abso/, and the machine's sign-in, servers and admin token are read from ~/.abso/ first, then ~/.avcs/. A folder made before, with only .avcs/, is untouched: it keeps working, is never half-moved, and no older client or mod loses it. stateDir(root) and homeFile/homeWritePath are in the new client/src/state-dir.ts and replace the old AVCS_DIR constant everywhere. abso login writes only to ~/.abso/ and leaves ~/.avcs/ alone; logout removes both copies. The edit mod and the view mod read either folder. .abso is skipped like .avcs (including its odd spellings), the git exclude names whichever folder is in use, and the messages name .abso. Not changed: avcs.json (the server reads that name, so abso.json needs the server to learn it first), .avcsignore, env var names and wire headers. Tests: 709 run, 708 pass (one is skipped), including new ones for the folder choice, the home-file order and box sign-in; biome ci has no errors.","time":1791522270512,"timeIso":"2026-10-09T05:04:30.512Z"}}]}