{"file":"client/src/config.ts","version":318,"total":312,"from":1,"to":312,"lines":[{"n":1,"text":"// The folder's settings (.avcs/config.json), finding the folder that holds","atom":"a0","author":"init","version":0},{"n":2,"text":"// them, and the token.","atom":"a0","author":"init","version":0},{"n":3,"text":"//","atom":"a0","author":"init","version":0},{"n":4,"text":"// The token is never in the folder: it comes from the ABSO_TOKEN environment","atom":"a201","author":"review","version":27},{"n":5,"text":"// variable, or else from ~/.avcs/token, outside every repo. A pipeline run's","atom":"a802","author":"pinch","version":95},{"n":6,"text":"// key comes from the file ABSO_KEY_FILE names, and is only ever held in memory.","atom":"a802","author":"pinch","version":95},{"n":7,"text":"","atom":"a0","author":"init","version":0},{"n":8,"text":"import { chmodSync, existsSync, mkdirSync, readFileSync, writeFileSync } from \"node:fs\";","atom":"a0","author":"init","version":0},{"n":9,"text":"import { homedir } from \"node:os\";","atom":"a0","author":"init","version":0},{"n":10,"text":"import { basename, dirname, join, resolve } from \"node:path\";","atom":"a100","author":"review","version":17},{"n":11,"text":"import { UsageError } from \"./args.ts\";","atom":"a0","author":"init","version":0},{"n":12,"text":"import { type MachineServers, machineServers, TOKEN_SERVERS, tokenGoesTo, trustedList } from \"./core.ts\";","atom":"a0","author":"init","version":0},{"n":13,"text":"import { fromEnv } from \"./env-names.ts\";","atom":"a201","author":"review","version":27},{"n":14,"text":"import { isLocal, storeDir } from \"./local-store.ts\";","atom":"a2820","author":"pinch","version":287},{"n":15,"text":"import { homeFile, stateDir } from \"./state-dir.ts\";","atom":"a100","author":"review","version":17},{"n":16,"text":"","atom":"a0","author":"init","version":0},{"n":17,"text":"/** What .avcs/config.json holds. */","atom":"a0","author":"init","version":0},{"n":18,"text":"export interface Settings {","atom":"a0","author":"init","version":0},{"n":19,"text":"\treadonly server: string;","atom":"a0","author":"init","version":0},{"n":20,"text":"\treadonly project: string;","atom":"a0","author":"init","version":0},{"n":21,"text":"\treadonly agent: string;","atom":"a0","author":"init","version":0},{"n":22,"text":"\t/** A label the folder follows (abso follow): every sync moves it to the newest version with that label. */","atom":"a0","author":"init","version":0},{"n":23,"text":"\treadonly follow?: string;","atom":"a0","author":"init","version":0},{"n":24,"text":"\t/** A reader folder (abso join --reader, #37): it reads everything and records nothing; the server refuses its records too. */","atom":"a0","author":"init","version":0},{"n":25,"text":"\treadonly reader?: boolean;","atom":"a0","author":"init","version":0},{"n":26,"text":"\t/**","atom":"a766","author":"pinch","version":86},{"n":27,"text":"\t * A visitor folder (abso join <project> --reader with no sign-in, for a public project): it reads through the","atom":"a766","author":"pinch","version":86},{"n":28,"text":"\t * routes anyone can read and sends no credential. It has no agent; its config holds server, project and this.","atom":"a766","author":"pinch","version":86},{"n":29,"text":"\t */","atom":"a766","author":"pinch","version":86},{"n":30,"text":"\treadonly visitor?: boolean;","atom":"a766","author":"pinch","version":86},{"n":31,"text":"\t/** A local project's store (abso init --local --store), when it isn't the machine's own: ABSO_STORE or the OS data folder. */","atom":"a2820","author":"pinch","version":287},{"n":32,"text":"\treadonly store?: string;","atom":"a2820","author":"pinch","version":287},{"n":33,"text":"}","atom":"a0","author":"init","version":0},{"n":34,"text":"","atom":"a0","author":"init","version":0},{"n":35,"text":"export interface Config extends Settings {","atom":"a0","author":"init","version":0},{"n":36,"text":"\treadonly token?: string;","atom":"a0","author":"init","version":0},{"n":37,"text":"\t/** For a local project (server \"local\"): the store folder its history is in, or undefined when there's none to use. */","atom":"a2820","author":"pinch","version":287},{"n":38,"text":"\treadonly localStore?: string;","atom":"a2820","author":"pinch","version":287},{"n":39,"text":"}","atom":"a0","author":"init","version":0},{"n":40,"text":"","atom":"a0","author":"init","version":0},{"n":41,"text":"export function configPath(root: string): string {","atom":"a0","author":"init","version":0},{"n":42,"text":"\treturn join(stateDir(root), \"config.json\");","atom":"a100","author":"review","version":17},{"n":43,"text":"}","atom":"a0","author":"init","version":0},{"n":44,"text":"","atom":"a0","author":"init","version":0},{"n":45,"text":"/** The nearest folder at or above `start` that has .abso/config.json (or .avcs/config.json, from before the rename), or undefined. */","atom":"a100","author":"review","version":17},{"n":46,"text":"export function findRoot(start: string): string | undefined {","atom":"a0","author":"init","version":0},{"n":47,"text":"\tlet dir = resolve(start);","atom":"a0","author":"init","version":0},{"n":48,"text":"\tfor (;;) {","atom":"a0","author":"init","version":0},{"n":49,"text":"\t\tif (existsSync(configPath(dir))) return dir;","atom":"a0","author":"init","version":0},{"n":50,"text":"\t\tconst up = dirname(dir);","atom":"a0","author":"init","version":0},{"n":51,"text":"\t\tif (up === dir) return undefined;","atom":"a0","author":"init","version":0},{"n":52,"text":"\t\tdir = up;","atom":"a0","author":"init","version":0},{"n":53,"text":"\t}","atom":"a0","author":"init","version":0},{"n":54,"text":"}","atom":"a0","author":"init","version":0},{"n":55,"text":"","atom":"a0","author":"init","version":0},{"n":56,"text":"export function readConfig(","atom":"a2684","author":"readspeed","version":268},{"n":57,"text":"\troot: string,","atom":"a2684","author":"readspeed","version":268},{"n":58,"text":"\tenv: Readonly<Record<string, string | undefined>> = process.env,","atom":"a2684","author":"readspeed","version":268},{"n":59,"text":"\ttokenFileOk = false,","atom":"a2710","author":"readspeed","version":271},{"n":60,"text":"): Config {","atom":"a2684","author":"readspeed","version":268},{"n":61,"text":"\tconst raw = JSON.parse(readFileSync(configPath(root), \"utf8\")) as Partial<Settings>;","atom":"a0","author":"init","version":0},{"n":62,"text":"\tif (raw.visitor === true) {","atom":"a766","author":"pinch","version":86},{"n":63,"text":"\t\tfor (const key of [\"server\", \"project\"] as const) {","atom":"a766","author":"pinch","version":86},{"n":64,"text":"\t\t\tif (typeof raw[key] !== \"string\" || raw[key] === \"\") throw new Error(`${configPath(root)} has no \"${key}\"`);","atom":"a766","author":"pinch","version":86},{"n":65,"text":"\t\t}","atom":"a766","author":"pinch","version":86},{"n":66,"text":"\t\t// No token and no key, whatever the environment or the folder holds: a visitor sends no credential.","atom":"a766","author":"pinch","version":86},{"n":67,"text":"\t\treturn { server: raw.server!, project: raw.project!, agent: \"\", visitor: true };","atom":"a766","author":"pinch","version":86},{"n":68,"text":"\t}","atom":"a766","author":"pinch","version":86},{"n":69,"text":"\tfor (const key of [\"server\", \"project\", \"agent\"] as const) {","atom":"a0","author":"init","version":0},{"n":70,"text":"\t\tif (typeof raw[key] !== \"string\" || raw[key] === \"\") throw new Error(`${configPath(root)} has no \"${key}\"`);","atom":"a0","author":"init","version":0},{"n":71,"text":"\t}","atom":"a0","author":"init","version":0},{"n":72,"text":"\t// A local project's calls never leave this process, so no credential goes with them.","atom":"a2820","author":"pinch","version":287},{"n":73,"text":"\tconst local = isLocal(raw.server);","atom":"a2820","author":"pinch","version":287},{"n":74,"text":"\tconst token = local ? undefined : tokenFor(raw.server!, env, root, tokenFileOk);","atom":"a2820","author":"pinch","version":287},{"n":75,"text":"\treturn {","atom":"a0","author":"init","version":0},{"n":76,"text":"\t\tserver: raw.server!,","atom":"a0","author":"init","version":0},{"n":77,"text":"\t\tproject: raw.project!,","atom":"a0","author":"init","version":0},{"n":78,"text":"\t\tagent: raw.agent!,","atom":"a0","author":"init","version":0},{"n":79,"text":"\t\t...(typeof raw.store === \"string\" && raw.store !== \"\" ? { store: raw.store } : {}),","atom":"a2820","author":"pinch","version":287},{"n":80,"text":"\t\t...(local ? { localStore: storeDir(env, raw.store, root) } : {}),","atom":"a2820","author":"pinch","version":287},{"n":81,"text":"\t\t...(typeof raw.follow === \"string\" && raw.follow !== \"\" ? { follow: raw.follow } : {}),","atom":"a0","author":"init","version":0},{"n":82,"text":"\t\t...(raw.reader === true ? { reader: true } : {}),","atom":"a0","author":"init","version":0},{"n":83,"text":"\t\t...(token ? { token } : {}),","atom":"a0","author":"init","version":0},{"n":84,"text":"\t};","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":"/** Whether the folder is a visitor's: it reads signed out and sends no credential. Read straight from its config. */","atom":"a766","author":"pinch","version":86},{"n":88,"text":"export function isVisitor(root: string): boolean {","atom":"a766","author":"pinch","version":86},{"n":89,"text":"\ttry {","atom":"a766","author":"pinch","version":86},{"n":90,"text":"\t\treturn (JSON.parse(readFileSync(configPath(root), \"utf8\")) as { visitor?: unknown }).visitor === true;","atom":"a766","author":"pinch","version":86},{"n":91,"text":"\t} catch {","atom":"a766","author":"pinch","version":86},{"n":92,"text":"\t\treturn false;","atom":"a766","author":"pinch","version":86},{"n":93,"text":"\t}","atom":"a766","author":"pinch","version":86},{"n":94,"text":"}","atom":"a766","author":"pinch","version":86},{"n":95,"text":"","atom":"a766","author":"pinch","version":86},{"n":96,"text":"/** Whether the folder is a reader (#37): records nothing. Read straight from its config, for the paths that only need this. */","atom":"a0","author":"init","version":0},{"n":97,"text":"export function isReader(root: string): boolean {","atom":"a0","author":"init","version":0},{"n":98,"text":"\ttry {","atom":"a0","author":"init","version":0},{"n":99,"text":"\t\treturn (JSON.parse(readFileSync(configPath(root), \"utf8\")) as { reader?: unknown }).reader === true;","atom":"a0","author":"init","version":0},{"n":100,"text":"\t} catch {","atom":"a0","author":"init","version":0},{"n":101,"text":"\t\treturn false;","atom":"a0","author":"init","version":0},{"n":102,"text":"\t}","atom":"a0","author":"init","version":0},{"n":103,"text":"}","atom":"a0","author":"init","version":0},{"n":104,"text":"","atom":"a0","author":"init","version":0},{"n":105,"text":"/**","atom":"a0","author":"init","version":0},{"n":106,"text":" * The token for `server`, refusing a server it may not go to (core.ts","atom":"a0","author":"init","version":0},{"n":107,"text":" * tokenGoesTo): a folder's config names its server, and anyone can write one.","atom":"a0","author":"init","version":0},{"n":108,"text":" */","atom":"a0","author":"init","version":0},{"n":109,"text":"/** What status may say about the credential. Never the key or the token. */","atom":"a0","author":"init","version":0},{"n":110,"text":"export function credentialLabel(","atom":"a0","author":"init","version":0},{"n":111,"text":"\troot: string,","atom":"a0","author":"init","version":0},{"n":112,"text":"\tserver: string,","atom":"a0","author":"init","version":0},{"n":113,"text":"\tenv: Readonly<Record<string, string | undefined>> = process.env,","atom":"a0","author":"init","version":0},{"n":114,"text":"\ttokenFileOk = false,","atom":"a2710","author":"readspeed","version":271},{"n":115,"text":"): { kind: \"agent key\" | \"shared token\" | \"pipeline run key\" | \"none\"; id: string | null } {","atom":"a802","author":"pinch","version":95},{"n":116,"text":"\tconst key = readKeyFile(root);","atom":"a0","author":"init","version":0},{"n":117,"text":"\tif (key) {","atom":"a0","author":"init","version":0},{"n":118,"text":"\t\tif (originOf(key.server) !== originOf(server)) return { kind: \"none\", id: null };","atom":"a0","author":"init","version":0},{"n":119,"text":"\t\treturn { kind: \"agent key\", id: key.id };","atom":"a0","author":"init","version":0},{"n":120,"text":"\t}","atom":"a0","author":"init","version":0},{"n":121,"text":"\tif (fromEnv(env, \"TOKEN\")) return { kind: \"shared token\", id: null };","atom":"a802","author":"pinch","version":95},{"n":122,"text":"\tif (fromEnv(env, \"KEY_FILE\")) return { kind: \"pipeline run key\", id: null };","atom":"a802","author":"pinch","version":95},{"n":123,"text":"\treturn { kind: tokenFileOk && tokenFile() ? \"shared token\" : \"none\", id: null };","atom":"a2710","author":"readspeed","version":271},{"n":124,"text":"}","atom":"a0","author":"init","version":0},{"n":125,"text":"","atom":"a0","author":"init","version":0},{"n":126,"text":"interface StoredKey {","atom":"a0","author":"init","version":0},{"n":127,"text":"\tserver: string;","atom":"a0","author":"init","version":0},{"n":128,"text":"\tkey: string;","atom":"a0","author":"init","version":0},{"n":129,"text":"\tid: string;","atom":"a0","author":"init","version":0},{"n":130,"text":"}","atom":"a0","author":"init","version":0},{"n":131,"text":"","atom":"a0","author":"init","version":0},{"n":132,"text":"function keyPath(root: string): string {","atom":"a0","author":"init","version":0},{"n":133,"text":"\treturn join(stateDir(root), \"key\");","atom":"a100","author":"review","version":17},{"n":134,"text":"}","atom":"a0","author":"init","version":0},{"n":135,"text":"","atom":"a0","author":"init","version":0},{"n":136,"text":"function originOf(server: string): string {","atom":"a0","author":"init","version":0},{"n":137,"text":"\ttry {","atom":"a0","author":"init","version":0},{"n":138,"text":"\t\treturn new URL(server).origin;","atom":"a0","author":"init","version":0},{"n":139,"text":"\t} catch {","atom":"a0","author":"init","version":0},{"n":140,"text":"\t\treturn server;","atom":"a0","author":"init","version":0},{"n":141,"text":"\t}","atom":"a0","author":"init","version":0},{"n":142,"text":"}","atom":"a0","author":"init","version":0},{"n":143,"text":"","atom":"a0","author":"init","version":0},{"n":144,"text":"function readKeyFile(root: string): StoredKey | undefined {","atom":"a0","author":"init","version":0},{"n":145,"text":"\ttry {","atom":"a0","author":"init","version":0},{"n":146,"text":"\t\tconst raw = JSON.parse(readFileSync(keyPath(root), \"utf8\")) as Partial<StoredKey>;","atom":"a0","author":"init","version":0},{"n":147,"text":"\t\tif (typeof raw.server !== \"string\" || typeof raw.key !== \"string\" || typeof raw.id !== \"string\") return undefined;","atom":"a0","author":"init","version":0},{"n":148,"text":"\t\tif (!raw.key.startsWith(\"abso_sk_\") || !/^k_[0-9a-f]{8}$/.test(raw.id)) return undefined;","atom":"a0","author":"init","version":0},{"n":149,"text":"\t\treturn { server: raw.server, key: raw.key, id: raw.id };","atom":"a0","author":"init","version":0},{"n":150,"text":"\t} catch {","atom":"a0","author":"init","version":0},{"n":151,"text":"\t\treturn undefined;","atom":"a0","author":"init","version":0},{"n":152,"text":"\t}","atom":"a0","author":"init","version":0},{"n":153,"text":"}","atom":"a0","author":"init","version":0},{"n":154,"text":"","atom":"a0","author":"init","version":0},{"n":155,"text":"/**","atom":"a0","author":"init","version":0},{"n":156,"text":" * Writes `.avcs/key` from the JSON the staging issue route printed (`{key, id}`),","atom":"a0","author":"init","version":0},{"n":157,"text":" * pinned to this folder's server, or to `serverFlag` in a folder not joined yet.","atom":"a0","author":"init","version":0},{"n":158,"text":" * Reads stdin. Prints nothing that contains the key.","atom":"a0","author":"init","version":0},{"n":159,"text":" */","atom":"a0","author":"init","version":0},{"n":160,"text":"export function installKey(root: string, stdin: string, serverFlag?: string): { id: string } {","atom":"a0","author":"init","version":0},{"n":161,"text":"\tconst configured = existsSync(configPath(root))","atom":"a0","author":"init","version":0},{"n":162,"text":"\t\t? (JSON.parse(readFileSync(configPath(root), \"utf8\")) as { server?: string }).server","atom":"a0","author":"init","version":0},{"n":163,"text":"\t\t: undefined;","atom":"a0","author":"init","version":0},{"n":164,"text":"\tif (configured && serverFlag && originOf(configured) !== originOf(serverFlag))","atom":"a0","author":"init","version":0},{"n":165,"text":"\t\tthrow new UsageError(`this folder's server is ${configured}, not ${serverFlag}`);","atom":"a0","author":"init","version":0},{"n":166,"text":"\tconst server = configured ?? serverFlag;","atom":"a0","author":"init","version":0},{"n":167,"text":"\tif (!server) throw new UsageError(\"this folder has no .abso/config.json yet: give --server <url>\");","atom":"a100","author":"review","version":17},{"n":168,"text":"\tlet parsed: { key?: unknown; id?: unknown };","atom":"a0","author":"init","version":0},{"n":169,"text":"\ttry {","atom":"a0","author":"init","version":0},{"n":170,"text":"\t\tparsed = JSON.parse(stdin) as { key?: unknown; id?: unknown };","atom":"a0","author":"init","version":0},{"n":171,"text":"\t} catch {","atom":"a0","author":"init","version":0},{"n":172,"text":"\t\tthrow new UsageError(\"abso key install reads {key, id} as JSON from stdin\");","atom":"a0","author":"init","version":0},{"n":173,"text":"\t}","atom":"a0","author":"init","version":0},{"n":174,"text":"\tif (","atom":"a0","author":"init","version":0},{"n":175,"text":"\t\ttypeof parsed.key !== \"string\" ||","atom":"a0","author":"init","version":0},{"n":176,"text":"\t\t!parsed.key.startsWith(\"abso_sk_\") ||","atom":"a0","author":"init","version":0},{"n":177,"text":"\t\ttypeof parsed.id !== \"string\" ||","atom":"a0","author":"init","version":0},{"n":178,"text":"\t\t!/^k_[0-9a-f]{8}$/.test(parsed.id)","atom":"a0","author":"init","version":0},{"n":179,"text":"\t)","atom":"a0","author":"init","version":0},{"n":180,"text":"\t\tthrow new UsageError(\"stdin needs {key, id} from the staging issue route\");","atom":"a0","author":"init","version":0},{"n":181,"text":"\tmkdirSync(stateDir(root), { recursive: true });","atom":"a100","author":"review","version":17},{"n":182,"text":"\twriteFileSync(keyPath(root), `${JSON.stringify({ server, key: parsed.key, id: parsed.id })}\\n`, { mode: 0o600 });","atom":"a0","author":"init","version":0},{"n":183,"text":"\ttry {","atom":"a0","author":"init","version":0},{"n":184,"text":"\t\tchmodSync(keyPath(root), 0o600);","atom":"a0","author":"init","version":0},{"n":185,"text":"\t} catch {","atom":"a0","author":"init","version":0},{"n":186,"text":"\t\t// Windows has no owner-only mode. The file is still under .avcs/, which abso never records.","atom":"a0","author":"init","version":0},{"n":187,"text":"\t}","atom":"a0","author":"init","version":0},{"n":188,"text":"\treturn { id: parsed.id };","atom":"a0","author":"init","version":0},{"n":189,"text":"}","atom":"a0","author":"init","version":0},{"n":190,"text":"","atom":"a0","author":"init","version":0},{"n":191,"text":"export function tokenFor(","atom":"a0","author":"init","version":0},{"n":192,"text":"\tserver: string,","atom":"a0","author":"init","version":0},{"n":193,"text":"\tenv: Readonly<Record<string, string | undefined>> = process.env,","atom":"a0","author":"init","version":0},{"n":194,"text":"\troot?: string,","atom":"a0","author":"init","version":0},{"n":195,"text":"\ttokenFileOk = false,","atom":"a2710","author":"readspeed","version":271},{"n":196,"text":"): string | undefined {","atom":"a0","author":"init","version":0},{"n":197,"text":"\tif (root) {","atom":"a0","author":"init","version":0},{"n":198,"text":"\t\tconst key = readKeyFile(root);","atom":"a0","author":"init","version":0},{"n":199,"text":"\t\t// A folder with a key signs in with that key and nothing else, even when the server refuses it.","atom":"a2710","author":"readspeed","version":271},{"n":200,"text":"\t\tif (!key && existsSync(keyPath(root)))","atom":"a2710","author":"readspeed","version":271},{"n":201,"text":"\t\t\tthrow new UsageError(","atom":"a2710","author":"readspeed","version":271},{"n":202,"text":"\t\t\t\t`this folder's key file (${keyPath(root)}) can't be read, so abso sends nothing; abso key install puts a key back`,","atom":"a2710","author":"readspeed","version":271},{"n":203,"text":"\t\t\t);","atom":"a2710","author":"readspeed","version":271},{"n":204,"text":"\t\tif (key) {","atom":"a0","author":"init","version":0},{"n":205,"text":"\t\t\tif (originOf(key.server) !== originOf(server))","atom":"a0","author":"init","version":0},{"n":206,"text":"\t\t\t\tthrow new UsageError(\"this folder's key was issued for a different server, so abso will not send it\");","atom":"a0","author":"init","version":0},{"n":207,"text":"\t\t\treturn key.key;","atom":"a0","author":"init","version":0},{"n":208,"text":"\t\t}","atom":"a0","author":"init","version":0},{"n":209,"text":"\t}","atom":"a0","author":"init","version":0},{"n":210,"text":"\treturn trustedToken(","atom":"a2684","author":"readspeed","version":268},{"n":211,"text":"\t\tserver,","atom":"a2684","author":"readspeed","version":268},{"n":212,"text":"\t\tenv,","atom":"a2684","author":"readspeed","version":268},{"n":213,"text":"\t\tfromEnv(env, \"TOKEN\")?.trim() || runKey(env) || (tokenFileOk ? readToken(env) : undefined),","atom":"a2684","author":"readspeed","version":268},{"n":214,"text":"\t);","atom":"a2684","author":"readspeed","version":268},{"n":215,"text":"}","atom":"a2684","author":"readspeed","version":268},{"n":216,"text":"","atom":"a2684","author":"readspeed","version":268},{"n":217,"text":"/** The token as given, if abso may send it to this server; refused, in words, if not. */","atom":"a2684","author":"readspeed","version":268},{"n":218,"text":"export function trustedToken(","atom":"a2684","author":"readspeed","version":268},{"n":219,"text":"\tserver: string,","atom":"a2684","author":"readspeed","version":268},{"n":220,"text":"\tenv: Readonly<Record<string, string | undefined>>,","atom":"a2684","author":"readspeed","version":268},{"n":221,"text":"\ttoken: string | undefined,","atom":"a2684","author":"readspeed","version":268},{"n":222,"text":"): string | undefined {","atom":"a2684","author":"readspeed","version":268},{"n":223,"text":"\tif (token === undefined || tokenGoesTo(server, trustedServers(env))) return token;","atom":"a2684","author":"readspeed","version":268},{"n":224,"text":"\tthrow new UsageError(","atom":"a0","author":"init","version":0},{"n":225,"text":"\t\t`this folder's server is ${server}, and abso sends your token only to ${[...TOKEN_SERVERS, \"this machine\"].join(\", \")}, and the servers ~/.abso/servers.json or ABSO_TRUSTED_SERVERS name. ` +","atom":"a201","author":"review","version":27},{"n":226,"text":"\t\t\t`If ${server} is yours, name it in ~/.abso/servers.json or ABSO_TRUSTED_SERVERS (comma-separated); if you didn't set it, someone else wrote .abso/config.json.`,","atom":"a201","author":"review","version":27},{"n":227,"text":"\t);","atom":"a0","author":"init","version":0},{"n":228,"text":"}","atom":"a0","author":"init","version":0},{"n":229,"text":"","atom":"a0","author":"init","version":0},{"n":230,"text":"let machine: MachineServers | undefined;","atom":"a0","author":"init","version":0},{"n":231,"text":"/** This machine's servers (core.ts machineServers), from ~/.abso/servers.json (or the older ~/.avcs/servers.json), read once. ABSO_SERVERS_FILE names another file (tests). */","atom":"a201","author":"review","version":27},{"n":232,"text":"export function readMachineServers(env: Readonly<Record<string, string | undefined>> = process.env): MachineServers {","atom":"a0","author":"init","version":0},{"n":233,"text":"\tif (fromEnv(env, \"SERVERS_FILE\") !== undefined) return machineServers(readOr(fromEnv(env, \"SERVERS_FILE\") as string));","atom":"a201","author":"review","version":27},{"n":234,"text":"\tmachine ??= machineServers(readOr(homeFile(homedir(), \"servers.json\")));","atom":"a100","author":"review","version":17},{"n":235,"text":"\treturn machine;","atom":"a0","author":"init","version":0},{"n":236,"text":"}","atom":"a0","author":"init","version":0},{"n":237,"text":"const readOr = (path: string): string | undefined => {","atom":"a0","author":"init","version":0},{"n":238,"text":"\ttry {","atom":"a0","author":"init","version":0},{"n":239,"text":"\t\treturn readFileSync(path, \"utf8\");","atom":"a0","author":"init","version":0},{"n":240,"text":"\t} catch {","atom":"a0","author":"init","version":0},{"n":241,"text":"\t\treturn undefined;","atom":"a0","author":"init","version":0},{"n":242,"text":"\t}","atom":"a0","author":"init","version":0},{"n":243,"text":"};","atom":"a0","author":"init","version":0},{"n":244,"text":"","atom":"a0","author":"init","version":0},{"n":245,"text":"/** The servers the token may go to beyond abso's own: ABSO_TRUSTED_SERVERS, then this machine's servers.json. */","atom":"a201","author":"review","version":27},{"n":246,"text":"export function trustedServers(env: Readonly<Record<string, string | undefined>> = process.env): string {","atom":"a0","author":"init","version":0},{"n":247,"text":"\treturn trustedList(fromEnv(env, \"TRUSTED_SERVERS\"), readMachineServers(env));","atom":"a201","author":"review","version":27},{"n":248,"text":"}","atom":"a802","author":"pinch","version":95},{"n":249,"text":"","atom":"a802","author":"pinch","version":95},{"n":250,"text":"/**","atom":"a802","author":"pinch","version":95},{"n":251,"text":" * A pipeline run's key, from the file ABSO_KEY_FILE names (the runner writes it, mode 600, holding the bare key).","atom":"a802","author":"pinch","version":95},{"n":252,"text":" * Read each time and kept in memory only; nothing abso writes or prints holds it, errors included.","atom":"a802","author":"pinch","version":95},{"n":253,"text":" */","atom":"a802","author":"pinch","version":95},{"n":254,"text":"export function runKey(env: Readonly<Record<string, string | undefined>> = process.env): string | undefined {","atom":"a802","author":"pinch","version":95},{"n":255,"text":"\tconst path = fromEnv(env, \"KEY_FILE\");","atom":"a802","author":"pinch","version":95},{"n":256,"text":"\tif (!path) return undefined;","atom":"a802","author":"pinch","version":95},{"n":257,"text":"\tlet text: string;","atom":"a802","author":"pinch","version":95},{"n":258,"text":"\ttry {","atom":"a802","author":"pinch","version":95},{"n":259,"text":"\t\ttext = readFileSync(path, \"utf8\");","atom":"a802","author":"pinch","version":95},{"n":260,"text":"\t} catch {","atom":"a802","author":"pinch","version":95},{"n":261,"text":"\t\tthrow new UsageError(`ABSO_KEY_FILE names ${path}, which abso can't read`);","atom":"a802","author":"pinch","version":95},{"n":262,"text":"\t}","atom":"a802","author":"pinch","version":95},{"n":263,"text":"\tconst key = text.trim();","atom":"a802","author":"pinch","version":95},{"n":264,"text":"\tif (!/^abso_sk_[A-Za-z0-9_-]+$/.test(key))","atom":"a802","author":"pinch","version":95},{"n":265,"text":"\t\tthrow new UsageError(`ABSO_KEY_FILE names ${path}, which doesn't hold an abso key`);","atom":"a802","author":"pinch","version":95},{"n":266,"text":"\treturn key;","atom":"a802","author":"pinch","version":95},{"n":267,"text":"}","atom":"a2684","author":"readspeed","version":268},{"n":268,"text":"","atom":"a2684","author":"readspeed","version":268},{"n":269,"text":"/** This machine's token file (~/.abso/token, else ~/.avcs/token), or none. Read only for a command given --token-file. */","atom":"a2710","author":"readspeed","version":271},{"n":270,"text":"export function tokenFile(): string | undefined {","atom":"a2684","author":"readspeed","version":268},{"n":271,"text":"\treturn readToken({});","atom":"a2684","author":"readspeed","version":268},{"n":272,"text":"}","atom":"a0","author":"init","version":0},{"n":273,"text":"","atom":"a0","author":"init","version":0},{"n":274,"text":"/** ABSO_TOKEN if set, else ~/.abso/token, else ~/.avcs/token, else none. */","atom":"a201","author":"review","version":27},{"n":275,"text":"export function readToken(env: Readonly<Record<string, string | undefined>> = process.env): string | undefined {","atom":"a0","author":"init","version":0},{"n":276,"text":"\tconst fromVar = fromEnv(env, \"TOKEN\");","atom":"a201","author":"review","version":27},{"n":277,"text":"\tif (fromVar) return fromVar.trim();","atom":"a201","author":"review","version":27},{"n":278,"text":"\ttry {","atom":"a0","author":"init","version":0},{"n":279,"text":"\t\treturn readFileSync(homeFile(homedir(), \"token\"), \"utf8\").trim() || undefined;","atom":"a100","author":"review","version":17},{"n":280,"text":"\t} catch {","atom":"a0","author":"init","version":0},{"n":281,"text":"\t\treturn undefined;","atom":"a0","author":"init","version":0},{"n":282,"text":"\t}","atom":"a0","author":"init","version":0},{"n":283,"text":"}","atom":"a0","author":"init","version":0},{"n":284,"text":"","atom":"a0","author":"init","version":0},{"n":285,"text":"export function writeConfig(root: string, settings: Settings): void {","atom":"a0","author":"init","version":0},{"n":286,"text":"\tmkdirSync(stateDir(root), { recursive: true });","atom":"a100","author":"review","version":17},{"n":287,"text":"\tconst { server, project, agent, follow, reader, visitor, store } = settings;","atom":"a2820","author":"pinch","version":287},{"n":288,"text":"\tconst written = visitor","atom":"a766","author":"pinch","version":86},{"n":289,"text":"\t\t? { server, project, visitor: true }","atom":"a766","author":"pinch","version":86},{"n":290,"text":"\t\t: {","atom":"a2820","author":"pinch","version":287},{"n":291,"text":"\t\t\t\tserver,","atom":"a2820","author":"pinch","version":287},{"n":292,"text":"\t\t\t\tproject,","atom":"a2820","author":"pinch","version":287},{"n":293,"text":"\t\t\t\tagent,","atom":"a2820","author":"pinch","version":287},{"n":294,"text":"\t\t\t\t...(follow ? { follow } : {}),","atom":"a2820","author":"pinch","version":287},{"n":295,"text":"\t\t\t\t...(reader ? { reader: true } : {}),","atom":"a2820","author":"pinch","version":287},{"n":296,"text":"\t\t\t\t...(store ? { store } : {}),","atom":"a2820","author":"pinch","version":287},{"n":297,"text":"\t\t\t};","atom":"a2820","author":"pinch","version":287},{"n":298,"text":"\twriteFileSync(configPath(root), `${JSON.stringify(written, null, 2)}\\n`);","atom":"a766","author":"pinch","version":86},{"n":299,"text":"\texcludeFromGit(root);","atom":"a0","author":"init","version":0},{"n":300,"text":"}","atom":"a0","author":"init","version":0},{"n":301,"text":"","atom":"a0","author":"init","version":0},{"n":302,"text":"/** If the folder is a git repo, keep its state folder (.abso/, or .avcs/ in an older folder) out of it (in .git/info/exclude, so .gitignore isn't changed). */","atom":"a100","author":"review","version":17},{"n":303,"text":"function excludeFromGit(root: string): void {","atom":"a0","author":"init","version":0},{"n":304,"text":"\tconst git = join(root, \".git\");","atom":"a0","author":"init","version":0},{"n":305,"text":"\tif (!existsSync(join(git, \"HEAD\"))) return;","atom":"a0","author":"init","version":0},{"n":306,"text":"\tconst exclude = join(git, \"info\", \"exclude\");","atom":"a0","author":"init","version":0},{"n":307,"text":"\tconst text = existsSync(exclude) ? readFileSync(exclude, \"utf8\") : \"\";","atom":"a0","author":"init","version":0},{"n":308,"text":"\tconst name = `${basename(stateDir(root))}/`;","atom":"a100","author":"review","version":17},{"n":309,"text":"\tif (text.split(/\\r?\\n/).some((line) => line.trim() === name || line.trim() === `/${name}`)) return;","atom":"a100","author":"review","version":17},{"n":310,"text":"\tmkdirSync(dirname(exclude), { recursive: true });","atom":"a0","author":"init","version":0},{"n":311,"text":"\twriteFileSync(exclude, `${text}${text === \"\" || text.endsWith(\"\\n\") ? \"\" : \"\\n\"}/${name}\\n`);","atom":"a100","author":"review","version":17},{"n":312,"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":"a100","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"}},{"atom":"a201","author":"review","message":"","time":1791533506483,"timeIso":"2026-10-09T08:11:46.483Z","publish":{"draft":null,"version":27,"agent":"review","message":"Client: ABSO_ environment names (AVCS_ still read), .absoignore (.avcsignore still read), .abso-export.json, shot files; READMEs say abso (abso 224)","time":1791533840174,"timeIso":"2026-10-09T08:17:20.174Z"}},{"atom":"a766","author":"pinch","message":"","time":1791616755509,"timeIso":"2026-10-10T07:19:15.509Z","publish":{"draft":null,"version":86,"agent":"pinch","message":"Read a public project signed out: abso join <project> --reader with no sign-in makes a folder that reads it. The folder holds only its settings (server, project, visitor), sends no sign-in whatever the environment or the box holds, follows no redirect, and runs status, log, show, files, blame, why, where, issues, issue and search; every other command is refused before any call, from an allow-list a new command has to join. join answers a private project and a missing one alike, by the status answer's code alone. Tests in client/test/visitor.test.ts.","time":1791616980022,"timeIso":"2026-10-10T07:23:00.022Z"}},{"atom":"a802","author":"pinch","message":"","time":1791638383830,"timeIso":"2026-10-10T13:19:43.830Z","publish":{"draft":null,"version":95,"agent":"pinch","message":"Pipeline run key: when ABSO_KEY_FILE names a file holding an agent key and no token or folder key is set, the client sends that key (only to servers a token may go to), keeps it in memory only, and never prints it. abso join takes the agent from ABSO_AGENT for such a key; status and doctor name it as a pipeline run's key.","time":1791639382910,"timeIso":"2026-10-10T13:36:22.910Z"}},{"atom":"a2684","author":"readspeed","message":"","time":1792100173165,"timeIso":"2026-10-15T21:36:13.165Z","publish":{"draft":null,"version":268,"agent":"readspeed","message":"abso init and join sign in with the box sign-in; ~/.abso/token only with --token-file\n\nBefore, abso init used ~/.abso/token whenever the file existed, ahead of the box sign-in. So a project could be made with whatever credential happened to be in that file, without the agent knowing. abso join with --agent fell back to the same file.\n\n- init signs in with the box sign-in when there is one. A token named in the environment (ABSO_TOKEN, or a pipeline run's ABSO_KEY_FILE) is used as given.\n- ~/.abso/token is used only with the new --token-file flag, on init and on join, and never by itself. Without the flag and with nothing else to sign in with, init refuses before it makes anything (\"~/.abso/token is used only with --token-file\"), and so does join's sign-in error.\n- --token-file is refused in a folder that already has a key.\n- Both say what they sign in with before they make or join anything: \"this box's sign-in, b_...\", \"a new key from this box's sign-in\", \"this folder's key\", \"ABSO_TOKEN\", or \"the token file, ~/.abso/token, as --token-file asks\".\n- config.ts: trustedToken and tokenFile are exported, and readConfig takes tokenFileOk (default true, so other commands are unchanged).\n\nTests: client/test/init-credential.test.ts (4). With a token file and a box sign-in, init sends only the box's credential. With only a token file, init is refused and no project is made. With --token-file, init and join use the file and say so. All client tests pass (440).\n\nCloses issue 25.","time":1792100173679,"timeIso":"2026-10-15T21:36:13.679Z"}},{"atom":"a2710","author":"readspeed","message":"","time":1792101952909,"timeIso":"2026-10-15T22:05:52.909Z","publish":{"draft":null,"version":271,"agent":"readspeed","message":"No command picks up a credential from a file nobody asked for\n\nFollows \"abso init signs in with the box sign-in\" (issue 25), and applies it to every command.\n\n- A folder with a key signs in with that key and nothing else: not ABSO_TOKEN, not ~/.abso/token, even when the server refuses the key. A key file that can't be read is now an error (\"abso key install puts a key back\") instead of a quiet fall back to another credential.\n- With no key, a command signs in with ABSO_TOKEN (or a pipeline run's ABSO_KEY_FILE). This machine's ~/.abso/token is used only by a command given --token-file, which every command that talks to a server now takes. Without it, a refused call says \"You're not signed in. Run abso login, then abso join <project>. ~/.abso/token is used only with --token-file.\" abso doctor says the same about a token file it finds unused. The edit hook and MCP tools never read it.\n- The admin token (ABSO_ADMIN_TOKEN, or ~/.abso/admin-token) is read only by abso key and abso flag. Each says \"Using the admin token, from ...\" every time it uses it. A test holds that no other module reads the file.\n\nWhat changes for you: a folder with no key that relied on ~/.abso/token needs --token-file on each command, or ABSO_TOKEN, or a key (abso login, then abso join).\n\nTests: client/test/token-file.test.ts (3, new); client/test/client.test.ts's MCP check covers --token-file. All client tests pass (443).","time":1792101955290,"timeIso":"2026-10-15T22:05:55.290Z"}},{"atom":"a2820","author":"pinch","message":"","time":1792119773277,"timeIso":"2026-10-16T03:02:53.277Z","publish":{"draft":null,"version":287,"agent":"pinch","message":"Local projects: abso init --local keeps a project's history on this machine, with no server, sign-in or network\n\nA local folder's calls never leave the process. The client runs the open server's own router and project object (server/src) in-process, over Node's built-in SQLite. It's the same engine with the same answers, so what the commands print matches a server.\n\n- abso init --local [--project <name>] [--agent <name>] [--store <folder>] makes the project, and abso join <project> --local adds a folder. After that, record, push, pull, log, blame and the held collisions work as usual. The folder's config says \"server\": \"local\".\n- Where the store lives: --store (kept in the folder's config; a store inside the folder is left out of its files through .absoignore), else ABSO_STORE, else this user's data folder: %LOCALAPPDATA%\\abso\\store, ~/Library/Application Support/abso/store, or $XDG_DATA_HOME/abso/store. Nothing needs a writable home folder when ABSO_STORE or --store is set.\n- Each project is <store>/<project>/project.sqlite. Every call runs in one SQLite write transaction, which is the store's lock: other processes wait for it, and a process that dies mid-call keeps nothing half-written. A process reloads the project only when SQLite's data_version shows another process wrote.\n- No credential goes with a local folder's calls. The edit mod leaves local folders alone, so abso record sends their edits. Issues, asks and news aren't in local projects yet.\n- Needs Node 22.13 or later (node:sqlite); its experimental warning is kept out of the output. Run as .ts, a module hook supplies the Durable Object base class (client/src/durable-object-stand-in.ts); the build aliases cloudflare:workers to the same file. client/src/local-server.mjs, with its .d.mts, keeps the client's typecheck out of server/src, which has its own.\n- Each command closes the store files it opened.\n\nTests: local (8, with fetch replaced by one that throws: init, record, push, join, pull, log, blame, a held collision, --store inside the folder, refusals), plus failed-start, install, caller, doctor, lost-pull, help, body-files: 60 pass; tsc clean. The bundle built with the alias runs init, push and log locally.","time":1792119778236,"timeIso":"2026-10-16T03:02:58.236Z"}}]}