{"file":"client/src/key-admin.ts","version":318,"total":153,"from":1,"to":153,"lines":[{"n":1,"text":"// abso key new, list and revoke (abso issue 116). The admin token is read at","atom":"a0","author":"init","version":0},{"n":2,"text":"// run time and sent only as a header. It is never an argument and never printed.","atom":"a0","author":"init","version":0},{"n":3,"text":"","atom":"a0","author":"init","version":0},{"n":4,"text":"import { readFileSync } from \"node:fs\";","atom":"a0","author":"init","version":0},{"n":5,"text":"import { homedir } from \"node:os\";","atom":"a0","author":"init","version":0},{"n":6,"text":"import { UsageError } from \"./args.ts\";","atom":"a0","author":"init","version":0},{"n":7,"text":"import type { Config } from \"./config.ts\";","atom":"a0","author":"init","version":0},{"n":8,"text":"import { fromEnv } from \"./env-names.ts\";","atom":"a210","author":"review","version":27},{"n":9,"text":"import { homeFile } from \"./state-dir.ts\";","atom":"a108","author":"review","version":17},{"n":10,"text":"","atom":"a0","author":"init","version":0},{"n":11,"text":"function originOf(server: string): string {","atom":"a0","author":"init","version":0},{"n":12,"text":"\ttry {","atom":"a0","author":"init","version":0},{"n":13,"text":"\t\treturn new URL(server).origin;","atom":"a0","author":"init","version":0},{"n":14,"text":"\t} catch {","atom":"a0","author":"init","version":0},{"n":15,"text":"\t\treturn server;","atom":"a0","author":"init","version":0},{"n":16,"text":"\t}","atom":"a0","author":"init","version":0},{"n":17,"text":"}","atom":"a0","author":"init","version":0},{"n":18,"text":"","atom":"a0","author":"init","version":0},{"n":19,"text":"/** The admin token goes only to a server named in ABSO_ADMIN_SERVERS (comma-separated): none is built in. */","atom":"a210","author":"review","version":27},{"n":20,"text":"export function adminGoesTo(server: string, extra = \"\"): boolean {","atom":"a0","author":"init","version":0},{"n":21,"text":"\tconst allowed = [","atom":"a0","author":"init","version":0},{"n":22,"text":"\t\t...extra","atom":"a0","author":"init","version":0},{"n":23,"text":"\t\t\t.split(\",\")","atom":"a0","author":"init","version":0},{"n":24,"text":"\t\t\t.map((s) => s.trim())","atom":"a0","author":"init","version":0},{"n":25,"text":"\t\t\t.filter((s) => s !== \"\"),","atom":"a0","author":"init","version":0},{"n":26,"text":"\t];","atom":"a0","author":"init","version":0},{"n":27,"text":"\tconst origin = originOf(server);","atom":"a0","author":"init","version":0},{"n":28,"text":"\treturn allowed.some((s) => originOf(s) === origin);","atom":"a0","author":"init","version":0},{"n":29,"text":"}","atom":"a0","author":"init","version":0},{"n":30,"text":"","atom":"a0","author":"init","version":0},{"n":31,"text":"export function adminToken(env: Readonly<Record<string, string | undefined>> = process.env): string {","atom":"a0","author":"init","version":0},{"n":32,"text":"\tconst fromVar = fromEnv(env, \"ADMIN_TOKEN\")?.trim();","atom":"a210","author":"review","version":27},{"n":33,"text":"\tif (fromVar) return fromVar;","atom":"a210","author":"review","version":27},{"n":34,"text":"\ttry {","atom":"a0","author":"init","version":0},{"n":35,"text":"\t\tconst fromFile = readFileSync(homeFile(homedir(), \"admin-token\"), \"utf8\").trim();","atom":"a108","author":"review","version":17},{"n":36,"text":"\t\tif (fromFile) return fromFile;","atom":"a0","author":"init","version":0},{"n":37,"text":"\t} catch {}","atom":"a0","author":"init","version":0},{"n":38,"text":"\tthrow new UsageError(\"abso key needs the admin token in ABSO_ADMIN_TOKEN or ~/.abso/admin-token\");","atom":"a210","author":"review","version":27},{"n":39,"text":"}","atom":"a0","author":"init","version":0},{"n":40,"text":"","atom":"a0","author":"init","version":0},{"n":41,"text":"/** What an admin command says each time it uses the admin token, and where it came from. Never the token. */","atom":"a2713","author":"readspeed","version":271},{"n":42,"text":"export function adminTokenWords(env: Readonly<Record<string, string | undefined>> = process.env): string {","atom":"a2713","author":"readspeed","version":271},{"n":43,"text":"\treturn `Using the admin token, from ${fromEnv(env, \"ADMIN_TOKEN\")?.trim() ? \"ABSO_ADMIN_TOKEN\" : \"~/.abso/admin-token\"}.`;","atom":"a2713","author":"readspeed","version":271},{"n":44,"text":"}","atom":"a2713","author":"readspeed","version":271},{"n":45,"text":"","atom":"a2713","author":"readspeed","version":271},{"n":46,"text":"function scrub(text: string, secrets: readonly string[]): string {","atom":"a0","author":"init","version":0},{"n":47,"text":"\tlet out = text.replace(/abso_sk_[A-Za-z0-9_-]+/g, \"[redacted]\");","atom":"a0","author":"init","version":0},{"n":48,"text":"\tfor (const secret of secrets) if (secret.length > 0) out = out.split(secret).join(\"[redacted]\");","atom":"a0","author":"init","version":0},{"n":49,"text":"\treturn out;","atom":"a0","author":"init","version":0},{"n":50,"text":"}","atom":"a0","author":"init","version":0},{"n":51,"text":"","atom":"a0","author":"init","version":0},{"n":52,"text":"async function call(config: Config, admin: string, method: \"GET\" | \"POST\", path: string): Promise<unknown> {","atom":"a0","author":"init","version":0},{"n":53,"text":"\tif (!adminGoesTo(config.server, fromEnv(process.env, \"ADMIN_SERVERS\")))","atom":"a210","author":"review","version":27},{"n":54,"text":"\t\tthrow new UsageError(","atom":"a0","author":"init","version":0},{"n":55,"text":"\t\t\t`abso key will not send the admin token to ${config.server}; ABSO_ADMIN_SERVERS names the servers it may go to`,","atom":"a210","author":"review","version":27},{"n":56,"text":"\t\t);","atom":"a0","author":"init","version":0},{"n":57,"text":"\tconst secrets = [admin, config.token ?? \"\"].filter((s) => s.length > 0);","atom":"a0","author":"init","version":0},{"n":58,"text":"\tlet response: Response;","atom":"a0","author":"init","version":0},{"n":59,"text":"\ttry {","atom":"a0","author":"init","version":0},{"n":60,"text":"\t\tresponse = await fetch(`${config.server.replace(/\\/+$/, \"\")}${path}`, {","atom":"a0","author":"init","version":0},{"n":61,"text":"\t\t\tmethod,","atom":"a0","author":"init","version":0},{"n":62,"text":"\t\t\theaders: {","atom":"a0","author":"init","version":0},{"n":63,"text":"\t\t\t\t...(config.token ? { authorization: `Bearer ${config.token}` } : {}),","atom":"a0","author":"init","version":0},{"n":64,"text":"\t\t\t\t\"x-abso-admin\": admin,","atom":"a496","author":"pinch","version":54},{"n":65,"text":"\t\t\t},","atom":"a0","author":"init","version":0},{"n":66,"text":"\t\t\tsignal: AbortSignal.timeout(30_000),","atom":"a0","author":"init","version":0},{"n":67,"text":"\t\t});","atom":"a0","author":"init","version":0},{"n":68,"text":"\t} catch (err) {","atom":"a0","author":"init","version":0},{"n":69,"text":"\t\tthrow new UsageError(scrub(err instanceof Error ? err.message : String(err), secrets));","atom":"a0","author":"init","version":0},{"n":70,"text":"\t}","atom":"a0","author":"init","version":0},{"n":71,"text":"\tconst text = await response.text();","atom":"a0","author":"init","version":0},{"n":72,"text":"\tif (!response.ok)","atom":"a0","author":"init","version":0},{"n":73,"text":"\t\tthrow new UsageError(scrub(text.slice(0, 500) || `the server answered ${response.status}`, secrets));","atom":"a0","author":"init","version":0},{"n":74,"text":"\ttry {","atom":"a0","author":"init","version":0},{"n":75,"text":"\t\treturn JSON.parse(text) as unknown;","atom":"a0","author":"init","version":0},{"n":76,"text":"\t} catch {","atom":"a0","author":"init","version":0},{"n":77,"text":"\t\tthrow new UsageError(\"the server's answer was not JSON\");","atom":"a0","author":"init","version":0},{"n":78,"text":"\t}","atom":"a0","author":"init","version":0},{"n":79,"text":"}","atom":"a0","author":"init","version":0},{"n":80,"text":"","atom":"a0","author":"init","version":0},{"n":81,"text":"export interface IssuedKey {","atom":"a0","author":"init","version":0},{"n":82,"text":"\tid: string;","atom":"a0","author":"init","version":0},{"n":83,"text":"\tkey: string;","atom":"a0","author":"init","version":0},{"n":84,"text":"\tagent: string;","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 async function keyNew(","atom":"a0","author":"init","version":0},{"n":88,"text":"\tconfig: Config,","atom":"a0","author":"init","version":0},{"n":89,"text":"\tadmin: string,","atom":"a0","author":"init","version":0},{"n":90,"text":"\tagent: string,","atom":"a0","author":"init","version":0},{"n":91,"text":"\tproject = config.project,","atom":"a0","author":"init","version":0},{"n":92,"text":"\texpires?: string,","atom":"a0","author":"init","version":0},{"n":93,"text":"\trole?: \"owner\" | \"writer\" | \"reader\",","atom":"a0","author":"init","version":0},{"n":94,"text":"): Promise<IssuedKey> {","atom":"a0","author":"init","version":0},{"n":95,"text":"\tconst query = `project=${encodeURIComponent(project)}&agent=${encodeURIComponent(agent)}${expires ? `&expires=${encodeURIComponent(expires)}` : \"\"}${role ? `&role=${role}` : \"\"}`;","atom":"a0","author":"init","version":0},{"n":96,"text":"\tconst body = (await call(config, admin, \"POST\", `/admin/agent-keys?${query}`)) as Partial<IssuedKey>;","atom":"a0","author":"init","version":0},{"n":97,"text":"\tif (typeof body.id !== \"string\" || typeof body.key !== \"string\")","atom":"a0","author":"init","version":0},{"n":98,"text":"\t\tthrow new UsageError(\"the server did not return a key\");","atom":"a0","author":"init","version":0},{"n":99,"text":"\treturn { id: body.id, key: body.key, agent: typeof body.agent === \"string\" ? body.agent : agent };","atom":"a0","author":"init","version":0},{"n":100,"text":"}","atom":"a0","author":"init","version":0},{"n":101,"text":"","atom":"a0","author":"init","version":0},{"n":102,"text":"/** What `abso key new` may show. The key is included only with --print. */","atom":"a0","author":"init","version":0},{"n":103,"text":"export function issuedPublic(issued: IssuedKey, print: boolean): { id: string; agent: string; key?: string } {","atom":"a0","author":"init","version":0},{"n":104,"text":"\treturn print ? { id: issued.id, agent: issued.agent, key: issued.key } : { id: issued.id, agent: issued.agent };","atom":"a0","author":"init","version":0},{"n":105,"text":"}","atom":"a0","author":"init","version":0},{"n":106,"text":"","atom":"a0","author":"init","version":0},{"n":107,"text":"export interface ListedKey {","atom":"a0","author":"init","version":0},{"n":108,"text":"\tid: string;","atom":"a0","author":"init","version":0},{"n":109,"text":"\tagent: string;","atom":"a0","author":"init","version":0},{"n":110,"text":"\tissuedBy: string;","atom":"a0","author":"init","version":0},{"n":111,"text":"\tat: number;","atom":"a0","author":"init","version":0},{"n":112,"text":"\tlastUsed: number | null;","atom":"a0","author":"init","version":0},{"n":113,"text":"\trevokedAt: number | null;","atom":"a0","author":"init","version":0},{"n":114,"text":"\texpiresAt?: number | null;","atom":"a0","author":"init","version":0},{"n":115,"text":"}","atom":"a0","author":"init","version":0},{"n":116,"text":"","atom":"a0","author":"init","version":0},{"n":117,"text":"export async function keyList(","atom":"a0","author":"init","version":0},{"n":118,"text":"\tconfig: Config,","atom":"a0","author":"init","version":0},{"n":119,"text":"\tadmin: string,","atom":"a0","author":"init","version":0},{"n":120,"text":"\tagent?: string,","atom":"a0","author":"init","version":0},{"n":121,"text":"\tproject = config.project,","atom":"a0","author":"init","version":0},{"n":122,"text":"): Promise<ListedKey[]> {","atom":"a0","author":"init","version":0},{"n":123,"text":"\tconst query = `project=${encodeURIComponent(project)}${agent ? `&agent=${encodeURIComponent(agent)}` : \"\"}`;","atom":"a0","author":"init","version":0},{"n":124,"text":"\tconst body = (await call(config, admin, \"GET\", `/admin/agent-keys?${query}`)) as { keys?: ListedKey[] };","atom":"a0","author":"init","version":0},{"n":125,"text":"\treturn body.keys ?? [];","atom":"a0","author":"init","version":0},{"n":126,"text":"}","atom":"a0","author":"init","version":0},{"n":127,"text":"","atom":"a0","author":"init","version":0},{"n":128,"text":"export async function keyRevoke(config: Config, admin: string, id: string, project = config.project): Promise<boolean> {","atom":"a0","author":"init","version":0},{"n":129,"text":"\tconst body = (await call(","atom":"a0","author":"init","version":0},{"n":130,"text":"\t\tconfig,","atom":"a0","author":"init","version":0},{"n":131,"text":"\t\tadmin,","atom":"a0","author":"init","version":0},{"n":132,"text":"\t\t\"POST\",","atom":"a0","author":"init","version":0},{"n":133,"text":"\t\t`/admin/agent-keys/revoke?project=${encodeURIComponent(project)}&id=${encodeURIComponent(id)}`,","atom":"a0","author":"init","version":0},{"n":134,"text":"\t)) as { revoked?: boolean };","atom":"a0","author":"init","version":0},{"n":135,"text":"\treturn body.revoked === true;","atom":"a0","author":"init","version":0},{"n":136,"text":"}","atom":"a0","author":"init","version":0},{"n":137,"text":"","atom":"a0","author":"init","version":0},{"n":138,"text":"/** What `abso key list` prints. The key's value is not a field, so it cannot appear. */","atom":"a0","author":"init","version":0},{"n":139,"text":"export function keyListText(keys: readonly ListedKey[]): string {","atom":"a0","author":"init","version":0},{"n":140,"text":"\tif (keys.length === 0) return \"No keys.\";","atom":"a0","author":"init","version":0},{"n":141,"text":"\treturn keys","atom":"a0","author":"init","version":0},{"n":142,"text":"\t\t.map((k) => {","atom":"a0","author":"init","version":0},{"n":143,"text":"\t\t\tconst when = new Date(k.at).toISOString().slice(0, 16).replace(\"T\", \" \");","atom":"a0","author":"init","version":0},{"n":144,"text":"\t\t\tconst used =","atom":"a0","author":"init","version":0},{"n":145,"text":"\t\t\t\tk.lastUsed === null","atom":"a0","author":"init","version":0},{"n":146,"text":"\t\t\t\t\t? \"never used\"","atom":"a0","author":"init","version":0},{"n":147,"text":"\t\t\t\t\t: `last used ${new Date(k.lastUsed).toISOString().slice(0, 16).replace(\"T\", \" \")}`;","atom":"a0","author":"init","version":0},{"n":148,"text":"\t\t\tconst until = k.expiresAt ? `, until ${new Date(k.expiresAt).toISOString().slice(0, 10)}` : \"\";","atom":"a0","author":"init","version":0},{"n":149,"text":"\t\t\tconst state = k.revokedAt === null ? used : \"revoked\";","atom":"a0","author":"init","version":0},{"n":150,"text":"\t\t\treturn `${k.id}  ${k.agent}  ${k.issuedBy}  ${when}  ${state}${until}`;","atom":"a0","author":"init","version":0},{"n":151,"text":"\t\t})","atom":"a0","author":"init","version":0},{"n":152,"text":"\t\t.join(\"\\n\");","atom":"a0","author":"init","version":0},{"n":153,"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":"a108","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":"a210","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":"a496","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"}},{"atom":"a2713","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"}}]}