{"draft":null,"from":175,"to":318,"files":[{"path":"client/src/config.ts","added":51,"removed":8,"diff":"--- a/client/src/config.ts\n+++ b/client/src/config.ts\n@@ -11,6 +11,7 @@\n import { UsageError } from \"./args.ts\";\n import { type MachineServers, machineServers, TOKEN_SERVERS, tokenGoesTo, trustedList } from \"./core.ts\";\n import { fromEnv } from \"./env-names.ts\";\n+import { isLocal, storeDir } from \"./local-store.ts\";\n import { homeFile, stateDir } from \"./state-dir.ts\";\n \n /** What .avcs/config.json holds. */\n@@ -27,10 +28,14 @@\n \t * routes anyone can read and sends no credential. It has no agent; its config holds server, project and this.\n \t */\n \treadonly visitor?: boolean;\n+\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. */\n+\treadonly store?: string;\n }\n \n export interface Config extends Settings {\n \treadonly token?: string;\n+\t/** For a local project (server \"local\"): the store folder its history is in, or undefined when there's none to use. */\n+\treadonly localStore?: string;\n }\n \n export function configPath(root: string): string {\n@@ -48,7 +53,11 @@\n \t}\n }\n \n-export function readConfig(root: string, env: Readonly<Record<string, string | undefined>> = process.env): Config {\n+export function readConfig(\n+\troot: string,\n+\tenv: Readonly<Record<string, string | undefined>> = process.env,\n+\ttokenFileOk = false,\n+): Config {\n \tconst raw = JSON.parse(readFileSync(configPath(root), \"utf8\")) as Partial<Settings>;\n \tif (raw.visitor === true) {\n \t\tfor (const key of [\"server\", \"project\"] as const) {\n@@ -60,11 +69,15 @@\n \tfor (const key of [\"server\", \"project\", \"agent\"] as const) {\n \t\tif (typeof raw[key] !== \"string\" || raw[key] === \"\") throw new Error(`${configPath(root)} has no \"${key}\"`);\n \t}\n-\tconst token = tokenFor(raw.server!, env, root);\n+\t// A local project's calls never leave this process, so no credential goes with them.\n+\tconst local = isLocal(raw.server);\n+\tconst token = local ? undefined : tokenFor(raw.server!, env, root, tokenFileOk);\n \treturn {\n \t\tserver: raw.server!,\n \t\tproject: raw.project!,\n \t\tagent: raw.agent!,\n+\t\t...(typeof raw.store === \"string\" && raw.store !== \"\" ? { store: raw.store } : {}),\n+\t\t...(local ? { localStore: storeDir(env, raw.store, root) } : {}),\n \t\t...(typeof raw.follow === \"string\" && raw.follow !== \"\" ? { follow: raw.follow } : {}),\n \t\t...(raw.reader === true ? { reader: true } : {}),\n \t\t...(token ? { token } : {}),\n@@ -98,6 +111,7 @@\n \troot: string,\n \tserver: string,\n \tenv: Readonly<Record<string, string | undefined>> = process.env,\n+\ttokenFileOk = false,\n ): { kind: \"agent key\" | \"shared token\" | \"pipeline run key\" | \"none\"; id: string | null } {\n \tconst key = readKeyFile(root);\n \tif (key) {\n@@ -106,7 +120,7 @@\n \t}\n \tif (fromEnv(env, \"TOKEN\")) return { kind: \"shared token\", id: null };\n \tif (fromEnv(env, \"KEY_FILE\")) return { kind: \"pipeline run key\", id: null };\n-\treturn { kind: readToken(env) ? \"shared token\" : \"none\", id: null };\n+\treturn { kind: tokenFileOk && tokenFile() ? \"shared token\" : \"none\", id: null };\n }\n \n interface StoredKey {\n@@ -178,18 +192,35 @@\n \tserver: string,\n \tenv: Readonly<Record<string, string | undefined>> = process.env,\n \troot?: string,\n+\ttokenFileOk = false,\n ): string | undefined {\n \tif (root) {\n \t\tconst key = readKeyFile(root);\n+\t\t// A folder with a key signs in with that key and nothing else, even when the server refuses it.\n+\t\tif (!key && existsSync(keyPath(root)))\n+\t\t\tthrow new UsageError(\n+\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`,\n+\t\t\t);\n \t\tif (key) {\n \t\t\tif (originOf(key.server) !== originOf(server))\n \t\t\t\tthrow new UsageError(\"this folder's key was issued for a different server, so abso will not send it\");\n \t\t\treturn key.key;\n \t\t}\n \t}\n-\tconst token = fromEnv(env, \"TOKEN\")?.trim() || runKey(env) || readToken(env);\n-\tconst trusted = trustedServers(env);\n-\tif (token === undefined || tokenGoesTo(server, trusted)) return token;\n+\treturn trustedToken(\n+\t\tserver,\n+\t\tenv,\n+\t\tfromEnv(env, \"TOKEN\")?.trim() || runKey(env) || (tokenFileOk ? readToken(env) : undefined),\n+\t);\n+}\n+\n+/** The token as given, if abso may send it to this server; refused, in words, if not. */\n+export function trustedToken(\n+\tserver: string,\n+\tenv: Readonly<Record<string, string | undefined>>,\n+\ttoken: string | undefined,\n+): string | undefined {\n+\tif (token === undefined || tokenGoesTo(server, trustedServers(env))) return token;\n \tthrow new UsageError(\n \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. ` +\n \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.`,\n@@ -235,6 +266,11 @@\n \treturn key;\n }\n \n+/** This machine's token file (~/.abso/token, else ~/.avcs/token), or none. Read only for a command given --token-file. */\n+export function tokenFile(): string | undefined {\n+\treturn readToken({});\n+}\n+\n /** ABSO_TOKEN if set, else ~/.abso/token, else ~/.avcs/token, else none. */\n export function readToken(env: Readonly<Record<string, string | undefined>> = process.env): string | undefined {\n \tconst fromVar = fromEnv(env, \"TOKEN\");\n@@ -248,10 +284,17 @@\n \n export function writeConfig(root: string, settings: Settings): void {\n \tmkdirSync(stateDir(root), { recursive: true });\n-\tconst { server, project, agent, follow, reader, visitor } = settings;\n+\tconst { server, project, agent, follow, reader, visitor, store } = settings;\n \tconst written = visitor\n \t\t? { server, project, visitor: true }\n-\t\t: { server, project, agent, ...(follow ? { follow } : {}), ...(reader ? { reader: true } : {}) };\n+\t\t: {\n+\t\t\t\tserver,\n+\t\t\t\tproject,\n+\t\t\t\tagent,\n+\t\t\t\t...(follow ? { follow } : {}),\n+\t\t\t\t...(reader ? { reader: true } : {}),\n+\t\t\t\t...(store ? { store } : {}),\n+\t\t\t};\n \twriteFileSync(configPath(root), `${JSON.stringify(written, null, 2)}\\n`);\n \texcludeFromGit(root);\n }"}],"unmatched":[]}