Lines 11–17 at 318 (were 11–16 at 232)
1111import { UsageError } from "./args.ts"; 1212import { type MachineServers, machineServers, TOKEN_SERVERS, tokenGoesTo, trustedList } from "./core.ts"; 1313import { fromEnv } from "./env-names.ts"; 14+import { isLocal, storeDir } from "./local-store.ts"; 1415import { homeFile, stateDir } from "./state-dir.ts"; 1617/** What .avcs/config.json holds. */ Lines 28–41 at 318 (were 27–36 at 232)
2728 * routes anyone can read and sends no credential. It has no agent; its config holds server, project and this. 2930 readonly visitor?: boolean; 31+ /** A local project's store (abso init --local --store), when it isn't the machine's own: ABSO_STORE or the OS data folder. */ 32+ readonly store?: string; 3235export interface Config extends Settings { 3336 readonly token?: string; 37+ /** For a local project (server "local"): the store folder its history is in, or undefined when there's none to use. */ 38+ readonly localStore?: string; 3641export function configPath(root: string): string { Lines 53–63 at 318 (were 48–54 at 232)
51−export function readConfig(root: string, env: Readonly<Record<string, string | undefined>> = process.env): Config {
56+export function readConfig( 58+ env: Readonly<Record<string, string | undefined>> = process.env, 5261 const raw = JSON.parse(readFileSync(configPath(root), "utf8")) as Partial<Settings>; 5362 if (raw.visitor === true) { 5463 for (const key of ["server", "project"] as const) { Lines 69–83 at 318 (were 60–70 at 232)
6069 for (const key of ["server", "project", "agent"] as const) { 6170 if (typeof raw[key] !== "string" || raw[key] === "") throw new Error(`${configPath(root)} has no "${key}"`); 63− const token = tokenFor(raw.server!, env, root);
72+ // A local project's calls never leave this process, so no credential goes with them. 73+ const local = isLocal(raw.server); 74+ const token = local ? undefined : tokenFor(raw.server!, env, root, tokenFileOk); 6576 server: raw.server!, 6677 project: raw.project!, 79+ ...(typeof raw.store === "string" && raw.store !== "" ? { store: raw.store } : {}), 80+ ...(local ? { localStore: storeDir(env, raw.store, root) } : {}), 6881 ...(typeof raw.follow === "string" && raw.follow !== "" ? { follow: raw.follow } : {}), 6982 ...(raw.reader === true ? { reader: true } : {}), 7083 ...(token ? { token } : {}), Lines 111–117 at 318 (were 98–103 at 232)
100113 env: Readonly<Record<string, string | undefined>> = process.env, 114+ tokenFileOk = false, 101115): { kind: "agent key" | "shared token" | "pipeline run key" | "none"; id: string | null } { 102116 const key = readKeyFile(root); Lines 120–126 at 318 (were 106–112 at 232)
107121 if (fromEnv(env, "TOKEN")) return { kind: "shared token", id: null }; 108122 if (fromEnv(env, "KEY_FILE")) return { kind: "pipeline run key", id: null }; 109− return { kind: readToken(env) ? "shared token" : "none", id: null };
123+ return { kind: tokenFileOk && tokenFile() ? "shared token" : "none", id: null }; 112126interface StoredKey { Lines 192–226 at 318 (were 178–195 at 232)
179193 env: Readonly<Record<string, string | undefined>> = process.env, 195+ tokenFileOk = false, 181196): string | undefined { 183198 const key = readKeyFile(root); 199+ // A folder with a key signs in with that key and nothing else, even when the server refuses it. 200+ if (!key && existsSync(keyPath(root))) 201+ throw new UsageError( 202+ `this folder's key file (${keyPath(root)}) can't be read, so abso sends nothing; abso key install puts a key back`, 185205 if (originOf(key.server) !== originOf(server)) 186206 throw new UsageError("this folder's key was issued for a different server, so abso will not send it"); 190− const token = fromEnv(env, "TOKEN")?.trim() || runKey(env) || readToken(env);
191− const trusted = trustedServers(env);
192− if (token === undefined || tokenGoesTo(server, trusted)) return token;
210+ return trustedToken( 213+ fromEnv(env, "TOKEN")?.trim() || runKey(env) || (tokenFileOk ? readToken(env) : undefined), 217+/** The token as given, if abso may send it to this server; refused, in words, if not. */ 218+export function trustedToken( 220+ env: Readonly<Record<string, string | undefined>>, 221+ token: string | undefined, 222+): string | undefined { 223+ if (token === undefined || tokenGoesTo(server, trustedServers(env))) return token; 193224 throw new UsageError( 194225 `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. ` + 195226 `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.`, Lines 266–276 at 318 (were 235–240 at 232)
269+/** This machine's token file (~/.abso/token, else ~/.avcs/token), or none. Read only for a command given --token-file. */ 270+export function tokenFile(): string | undefined { 271+ return readToken({}); 238274/** ABSO_TOKEN if set, else ~/.abso/token, else ~/.avcs/token, else none. */ 239275export function readToken(env: Readonly<Record<string, string | undefined>> = process.env): string | undefined { 240276 const fromVar = fromEnv(env, "TOKEN"); Lines 284–300 at 318 (were 248–257 at 232)
249285export function writeConfig(root: string, settings: Settings): void { 250286 mkdirSync(stateDir(root), { recursive: true }); 251− const { server, project, agent, follow, reader, visitor } = settings;
287+ const { server, project, agent, follow, reader, visitor, store } = settings; 252288 const written = visitor 253289 ? { server, project, visitor: true } 254− : { server, project, agent, ...(follow ? { follow } : {}), ...(reader ? { reader: true } : {}) };
294+ ...(follow ? { follow } : {}), 295+ ...(reader ? { reader: true } : {}), 296+ ...(store ? { store } : {}), 255298 writeFileSync(configPath(root), `${JSON.stringify(written, null, 2)}\n`); 256299 excludeFromGit(root);