{"version":261,"agent":"readspeed","message":"abso flag: list, flip and audit a server's feature flags\n\nA server can keep feature flags: switches it reads while it runs, so a gate changes with no deploy. abso flag is the command for them.\n\n- abso flag [list]: each flag, the values it takes, its safe default, what it gates, and where it's set (the whole server, a project, or a person).\n- abso flag set <flag> <value> --why \"...\" [--project <name> | --person person:<id>]: sets a value; abso flag unset takes it away. A change without --why, or for a project and a person both, is refused before anything is sent.\n- abso flag log [--limit N]: the server's record of changes, newest first: when, who, which flag where, old to new, and why.\n\nThe server decides who may. The folder's own key goes with every call. The admin token is read from ABSO_ADMIN_TOKEN or ~/.abso/admin-token, sent only to a server ABSO_ADMIN_SERVERS names, and never printed; credentials are scrubbed from any error.\n\nTests: client/test/flag-command.test.ts. Visitor folders refuse flag (visitor.test.ts).","time":1792093797980,"timeIso":"2026-10-15T19:49:57.980Z","changes":8,"change":4017,"files":["client/src/flag-commands.ts","client/src/main.ts","client/test/flag-command.test.ts","client/test/visitor.test.ts"],"draft":null,"diff":[{"path":"client/src/flag-commands.ts","added":151,"removed":0,"diff":"--- /dev/null\n+++ b/client/src/flag-commands.ts\n@@ -0,0 +1,151 @@\n+// abso flag: read, flip and audit a server's feature flags, with no deploy. Each flag has its values, a safe default,\n+// and a line of what it gates; a value is set for the whole server, one project, or one person. The server decides who\n+// may: its admin token always, and an owner's key where it says so. The admin token is read at run time, sent only as a\n+// header and only to a server ABSO_ADMIN_SERVERS names, and never printed.\n+import { type Parsed, str, UsageError } from \"./args.ts\";\n+import { type Env, type Output, open } from \"./commands.ts\";\n+import type { Config } from \"./config.ts\";\n+import { fromEnv } from \"./env-names.ts\";\n+import { adminGoesTo, adminToken } from \"./key-admin.ts\";\n+import { shortWhen } from \"./times.ts\";\n+\n+/** One flag as GET /admin/flags answers it: what it takes and gates, and where it's set. */\n+export interface ListedFlag {\n+\treadonly values: readonly string[];\n+\treadonly safe: string;\n+\treadonly what: string;\n+\treadonly stagingOnly?: boolean;\n+\treadonly env?: string;\n+\treadonly projects?: Readonly<Record<string, string>>;\n+\treadonly people?: Readonly<Record<string, string>>;\n+}\n+\n+export type FlagScope = { readonly env: true } | { readonly project: string } | { readonly person: string };\n+\n+/** One change as GET /admin/flags/audit answers it. */\n+export interface FlagChange {\n+\treadonly at: string;\n+\treadonly by: string;\n+\treadonly flag: string;\n+\treadonly scope: FlagScope;\n+\treadonly old: string | null;\n+\treadonly new: string | null;\n+\treadonly why: string;\n+}\n+\n+const USAGE =\n+\t'abso flag [list] | abso flag log [--limit N] | abso flag set <flag> <value> --why \"...\" [--project <name> | --person person:<id>] | abso flag unset <flag> --why \"...\" [--project <name> | --person person:<id>]';\n+\n+/** The admin token when there is one for this server, else none: a server that takes an owner's key answers without it. */\n+export function adminFor(server: string, env: Readonly<Record<string, string | undefined>>): string | undefined {\n+\tif (!adminGoesTo(server, fromEnv(env, \"ADMIN_SERVERS\"))) return undefined;\n+\ttry {\n+\t\treturn adminToken(env);\n+\t} catch {\n+\t\treturn undefined;\n+\t}\n+}\n+\n+function scrub(text: string, secrets: readonly string[]): string {\n+\tlet out = text.replace(/abso_sk_[A-Za-z0-9_-]+/g, \"[redacted]\");\n+\tfor (const secret of secrets) if (secret.length > 0) out = out.split(secret).join(\"[redacted]\");\n+\treturn out;\n+}\n+\n+async function call(config: Config, admin: string | undefined, path: string, body?: unknown): Promise<unknown> {\n+\tconst secrets = [admin ?? \"\", config.token ?? \"\"].filter((s) => s.length > 0);\n+\tlet response: Response;\n+\ttry {\n+\t\tresponse = await fetch(`${config.server.replace(/\\/+$/, \"\")}${path}`, {\n+\t\t\tmethod: body === undefined ? \"GET\" : \"POST\",\n+\t\t\theaders: {\n+\t\t\t\t...(config.token ? { authorization: `Bearer ${config.token}` } : {}),\n+\t\t\t\t...(admin ? { \"x-abso-admin\": admin } : {}),\n+\t\t\t\t...(body === undefined ? {} : { \"content-type\": \"application/json\" }),\n+\t\t\t},\n+\t\t\t...(body === undefined ? {} : { body: JSON.stringify(body) }),\n+\t\t\tsignal: AbortSignal.timeout(30_000),\n+\t\t});\n+\t} catch (err) {\n+\t\tthrow new UsageError(scrub(err instanceof Error ? err.message : String(err), secrets));\n+\t}\n+\tconst text = await response.text();\n+\tlet parsed: unknown;\n+\ttry {\n+\t\tparsed = JSON.parse(text);\n+\t} catch {\n+\t\tthrow new UsageError(\n+\t\t\tresponse.ok ? \"the server's answer was not JSON\" : scrub(text.slice(0, 500), secrets) || `${response.status}`,\n+\t\t);\n+\t}\n+\tif (!response.ok) {\n+\t\tconst error = (parsed as { error?: unknown }).error;\n+\t\tif (response.status === 404) throw new UsageError(`${config.server} keeps no feature flags`);\n+\t\tthrow new UsageError(scrub(typeof error === \"string\" ? error : `the server answered ${response.status}`, secrets));\n+\t}\n+\treturn parsed;\n+}\n+\n+/** Where a value is set, in words: \"here\", \"project game\", \"person:p1\". */\n+export function scopeWords(scope: FlagScope): string {\n+\treturn \"project\" in scope ? `project ${scope.project}` : \"person\" in scope ? scope.person : \"here\";\n+}\n+\n+/** What abso flag list prints: each flag, what it takes, its safe value, and every place it's set. */\n+export function flagListText(flags: Readonly<Record<string, ListedFlag>>): string {\n+\tconst names = Object.keys(flags).sort();\n+\tif (names.length === 0) return \"No flags.\";\n+\treturn names\n+\t\t.map((name) => {\n+\t\t\tconst f = flags[name]!;\n+\t\t\treturn [\n+\t\t\t\t`${name}: ${f.env ?? `${f.safe} (unset)`}. Takes ${f.values.join(\", \")}; safe ${f.safe}${f.stagingOnly ? \"; staging only\" : \"\"}.`,\n+\t\t\t\t`  ${f.what}`,\n+\t\t\t\t...Object.entries(f.projects ?? {}).map(([p, v]) => `  project ${p}: ${v}`),\n+\t\t\t\t...Object.entries(f.people ?? {}).map(([p, v]) => `  ${p}: ${v}`),\n+\t\t\t].join(\"\\n\");\n+\t\t})\n+\t\t.join(\"\\n\");\n+}\n+\n+/** One audited change in a line: when, who, which flag where, old to new, and why. */\n+export function changeText(c: FlagChange, now: number = Date.now()): string {\n+\treturn `${shortWhen(Date.parse(c.at), now)}  ${c.by}  ${c.flag} ${scopeWords(c.scope)}: ${c.old ?? \"unset\"} to ${c.new ?? \"unset\"}. \"${c.why}\"`;\n+}\n+\n+export async function runFlag(args: Parsed, env: Env): Promise<Output> {\n+\tconst [sub = \"list\", flag, value, ...extra] = args.positionals;\n+\tconst { config } = open(env);\n+\tconst admin = adminFor(config.server, env.env);\n+\tif (sub === \"list\" && flag === undefined) {\n+\t\tconst body = (await call(config, admin, \"/admin/flags\")) as {\n+\t\t\trevision: number;\n+\t\t\tflags: Record<string, ListedFlag>;\n+\t\t};\n+\t\treturn { text: `${flagListText(body.flags)}\\n`, json: { ...body } };\n+\t}\n+\tif (sub === \"log\" && flag === undefined) {\n+\t\tconst limit = str(args, \"limit\") ?? \"20\";\n+\t\tif (!/^[0-9]{1,3}$/.test(limit) || Number(limit) < 1) throw new UsageError(\"--limit is a number from 1 to 999\");\n+\t\tconst body = (await call(config, admin, `/admin/flags/audit?limit=${limit}`)) as { changes: FlagChange[] };\n+\t\tconst text = body.changes.length === 0 ? \"No changes yet.\" : body.changes.map((c) => changeText(c)).join(\"\\n\");\n+\t\treturn { text: `${text}\\n`, json: { ...body } };\n+\t}\n+\tconst setting = sub === \"set\" && flag !== undefined && value !== undefined && extra.length === 0;\n+\tconst unsetting = sub === \"unset\" && flag !== undefined && value === undefined;\n+\tif (!setting && !unsetting) throw new UsageError(USAGE);\n+\tconst why = str(args, \"why\");\n+\tif (why === undefined || why.trim().length < 3) throw new UsageError('every change says why: --why \"...\"');\n+\tconst project = str(args, \"project\");\n+\tconst person = str(args, \"person\");\n+\tif (project !== undefined && person !== undefined)\n+\t\tthrow new UsageError(\"a value is set for a project or a person, not both\");\n+\tif (person !== undefined && !person.startsWith(\"person:\")) throw new UsageError(\"--person is person:<id>\");\n+\tconst body = (await call(config, admin, `/admin/flags/${encodeURIComponent(flag!)}`, {\n+\t\tvalue: setting ? value : null,\n+\t\twhy,\n+\t\t...(project === undefined ? {} : { project }),\n+\t\t...(person === undefined ? {} : { person }),\n+\t})) as { revision: number; change: FlagChange };\n+\treturn { text: `${changeText(body.change)}\\n`, json: { ...body } };\n+}"},{"path":"client/src/main.ts","added":9,"removed":0,"diff":"--- a/client/src/main.ts\n+++ b/client/src/main.ts\n@@ -43,6 +43,7 @@\n import { doctor, doctorText, plainError, realProbe, whoami } from \"./doctor.ts\";\n import { runDraftSync, runLand, runSwitch } from \"./drafts.ts\";\n import { runExport } from \"./export.ts\";\n+import { runFlag } from \"./flag-commands.ts\";\n import { runGroup, runGroups } from \"./group-commands.ts\";\n import { runBlame, runWhere, runWho, runWhy } from \"./history.ts\";\n import {\n@@ -598,6 +599,14 @@\n \t\t\t\"What the server does with a held push (abso-core 23). With no word, says which. advise: each collision comes back with a model's pick (keep yours, keep theirs, keep both, or leave it to an agent), how sure it is, and why; the agent still settles. settle: when the model is at least --at sure about every collision, your abso settles it and pushes again by itself, saying so in the message; anything less sure stays held, with the advice. off: held pushes come back as they always have. New projects start on advise. Changing it takes the project owner's key (on staging, the shared token works too). ABSO_AUTOSETTLE=off on a machine makes its abso settle nothing by itself. abso autosettle history lists the held pushes the model advised on, newest first, with what it said and what was then kept; history <id> shows one, with its calls to the model (--json has each request and answer).\",\n \t\trun: runAutosettle,\n \t},\n+\tflag: {\n+\t\tflags: { why: \"string\", project: \"string\", person: \"string\", limit: \"string\" },\n+\t\tusage:\n+\t\t\t'abso flag [list] | abso flag log [--limit N] | abso flag set <flag> <value> --why \"...\" [--project <name> | --person person:<id>] | abso flag unset <flag> --why \"...\" [--project <name> | --person person:<id>]',\n+\t\tabout:\n+\t\t\t\"The server's feature flags: switches flipped while it runs, with no deploy. list shows each flag, the values it takes, its safe default, what it gates, and where it's set. set gives it a value for the whole server, or for one --project or --person; unset takes that value away. Each change says --why, and the server keeps who, when, the old and new value, and why; log shows those changes, newest first. A read takes the person's value, then the project's, then the whole server's, then the safe one. The server decides who may: its admin token, read from ABSO_ADMIN_TOKEN or ~/.abso/admin-token and sent only to a server ABSO_ADMIN_SERVERS names, and an owner's key where the server takes one. An agent does not flip a flag unless a person on the project says so.\",\n+\t\trun: runFlag,\n+\t},\n \tci: {\n \t\tflags: { version: \"string\", revoke: \"boolean\" },\n \t\tusage: \"abso ci [<version>] | abso ci --revoke\","},{"path":"client/test/flag-command.test.ts","added":158,"removed":0,"diff":"--- /dev/null\n+++ b/client/test/flag-command.test.ts\n@@ -0,0 +1,158 @@\n+// abso flag: a server's feature flags listed, flipped with a reason, and audited. The admin token goes only to a server\n+// ABSO_ADMIN_SERVERS names; the folder's own key goes with every call, for a server that takes an owner's key. Every\n+// test passes its own ABSO_ADMIN_TOKEN, so this machine's ~/.abso is never read.\n+import assert from \"node:assert/strict\";\n+import { mkdirSync, mkdtempSync, writeFileSync } from \"node:fs\";\n+import { tmpdir } from \"node:os\";\n+import { join } from \"node:path\";\n+import { test } from \"node:test\";\n+import { parseArgs } from \"../src/args.ts\";\n+import { adminFor, changeText, type FlagChange, flagListText, type ListedFlag, runFlag } from \"../src/flag-commands.ts\";\n+\n+const SERVER = \"http://localhost:8787\";\n+const KEY = \"abso_sk_owner-key-value\";\n+const ADMIN = \"admin-token-value\";\n+const FLAGS = { why: \"string\", project: \"string\", person: \"string\", limit: \"string\" } as const;\n+\n+function folder(): string {\n+\tconst root = mkdtempSync(join(tmpdir(), \"abso-flag-\"));\n+\tmkdirSync(join(root, \".abso\"));\n+\twriteFileSync(join(root, \".abso\", \"config.json\"), JSON.stringify({ server: SERVER, project: \"abso\", agent: \"me\" }));\n+\treturn root;\n+}\n+\n+interface Seen {\n+\turl: string;\n+\tmethod: string;\n+\theaders: Headers;\n+\tbody?: unknown;\n+}\n+\n+async function run(\n+\targv: string[],\n+\tenv: Record<string, string>,\n+\tanswer: { status: number; body: unknown },\n+\tseen: Seen[] = [],\n+) {\n+\tconst previous = globalThis.fetch;\n+\tglobalThis.fetch = (async (url, init) => {\n+\t\tseen.push({\n+\t\t\turl: String(url),\n+\t\t\tmethod: init?.method ?? \"GET\",\n+\t\t\theaders: new Headers(init?.headers),\n+\t\t\t...(typeof init?.body === \"string\" ? { body: JSON.parse(init.body) } : {}),\n+\t\t});\n+\t\treturn new Response(JSON.stringify(answer.body), { status: answer.status });\n+\t}) as typeof fetch;\n+\ttry {\n+\t\tconst out = await runFlag(parseArgs(\"flag\", argv, FLAGS), {\n+\t\t\tcwd: folder(),\n+\t\t\tenv: { ABSO_TOKEN: KEY, ...env },\n+\t\t\twrite: () => {},\n+\t\t});\n+\t\treturn { out, seen };\n+\t} finally {\n+\t\tglobalThis.fetch = previous;\n+\t}\n+}\n+\n+const change: FlagChange = {\n+\tat: \"2026-10-15T19:04:00.000Z\",\n+\tby: \"key k_1, box b\",\n+\tflag: \"autosettle-default\",\n+\tscope: { project: \"game\" },\n+\told: null,\n+\tnew: \"settle\",\n+\twhy: \"trying Settle on game\",\n+};\n+\n+test(\"the admin token goes only to a server ABSO_ADMIN_SERVERS names, and is never needed to try\", () => {\n+\tassert.equal(adminFor(SERVER, { ABSO_ADMIN_TOKEN: ADMIN }), undefined, \"no server named\");\n+\tassert.equal(adminFor(SERVER, { ABSO_ADMIN_TOKEN: ADMIN, ABSO_ADMIN_SERVERS: \"https://api.abso.dev\" }), undefined);\n+\tassert.equal(adminFor(SERVER, { ABSO_ADMIN_TOKEN: ADMIN, ABSO_ADMIN_SERVERS: SERVER }), ADMIN);\n+});\n+\n+test(\"list says each flag's value, what it takes, its safe value, what it gates, and every place it's set\", () => {\n+\tconst flags: Record<string, ListedFlag> = {\n+\t\t\"byoc-demo\": { values: [\"on\", \"off\"], safe: \"on\", what: \"The BYOC demo page.\", stagingOnly: true },\n+\t\t\"autosettle-default\": {\n+\t\t\tvalues: [\"off\", \"advise\", \"settle\"],\n+\t\t\tsafe: \"off\",\n+\t\t\twhat: \"Auto-settle's mode for an unpicked project.\",\n+\t\t\tenv: \"advise\",\n+\t\t\tprojects: { game: \"settle\" },\n+\t\t\tpeople: { \"person:p1\": \"off\" },\n+\t\t},\n+\t};\n+\tassert.equal(\n+\t\tflagListText(flags),\n+\t\t[\n+\t\t\t\"autosettle-default: advise. Takes off, advise, settle; safe off.\",\n+\t\t\t\"  Auto-settle's mode for an unpicked project.\",\n+\t\t\t\"  project game: settle\",\n+\t\t\t\"  person:p1: off\",\n+\t\t\t\"byoc-demo: on (unset). Takes on, off; safe on; staging only.\",\n+\t\t\t\"  The BYOC demo page.\",\n+\t\t].join(\"\\n\"),\n+\t);\n+\tassert.equal(flagListText({}), \"No flags.\");\n+});\n+\n+test(\"a change in a line: when, who, which flag where, old to new, and why\", () => {\n+\tassert.equal(\n+\t\tchangeText(change, Date.parse(\"2026-10-15T20:00:00Z\")),\n+\t\t'19:04 UTC  key k_1, box b  autosettle-default project game: unset to settle. \"trying Settle on game\"',\n+\t);\n+\tassert.match(changeText({ ...change, scope: { env: true }, old: \"settle\", new: null }), / here: settle to unset\\./);\n+});\n+\n+test(\"set posts the value, scope and reason with the folder's key; the admin token only where it may go\", async () => {\n+\tconst { out, seen } = await run(\n+\t\t[\"set\", \"autosettle-default\", \"settle\", \"--project\", \"game\", \"--why\", \"trying Settle on game\"],\n+\t\t{ ABSO_ADMIN_TOKEN: ADMIN },\n+\t\t{ status: 200, body: { revision: 3, change } },\n+\t);\n+\tassert.equal(seen.length, 1);\n+\tassert.equal(seen[0]!.url, `${SERVER}/admin/flags/autosettle-default`);\n+\tassert.equal(seen[0]!.method, \"POST\");\n+\tassert.deepEqual(seen[0]!.body, { value: \"settle\", why: \"trying Settle on game\", project: \"game\" });\n+\tassert.equal(seen[0]!.headers.get(\"authorization\"), `Bearer ${KEY}`);\n+\tassert.equal(seen[0]!.headers.get(\"x-abso-admin\"), null, \"ABSO_ADMIN_SERVERS doesn't name it\");\n+\tassert.match(out.text, /unset to settle/);\n+\tconst named = await run(\n+\t\t[\"unset\", \"autosettle-default\", \"--why\", \"back to the default\"],\n+\t\t{ ABSO_ADMIN_TOKEN: ADMIN, ABSO_ADMIN_SERVERS: SERVER },\n+\t\t{ status: 200, body: { revision: 4, change: { ...change, scope: { env: true }, old: \"advise\", new: null } } },\n+\t);\n+\tassert.equal(named.seen[0]!.headers.get(\"x-abso-admin\"), ADMIN);\n+\tassert.deepEqual(named.seen[0]!.body, { value: null, why: \"back to the default\" });\n+});\n+\n+test(\"a change without a reason, or for a project and a person both, is refused before anything is sent\", async () => {\n+\tfor (const argv of [\n+\t\t[\"set\", \"autosettle-default\", \"advise\"],\n+\t\t[\"set\", \"autosettle-default\", \"advise\", \"--why\", \"x\"],\n+\t\t[\"set\", \"autosettle-default\", \"advise\", \"--why\", \"both\", \"--project\", \"a\", \"--person\", \"person:b\"],\n+\t\t[\"set\", \"autosettle-default\", \"advise\", \"--why\", \"bad person\", \"--person\", \"p1\"],\n+\t\t[\"unset\", \"autosettle-default\", \"advise\", \"--why\", \"too many words\"],\n+\t\t[\"flip\", \"autosettle-default\"],\n+\t]) {\n+\t\tconst seen: Seen[] = [];\n+\t\tawait assert.rejects(run(argv, {}, { status: 200, body: {} }, seen), argv.join(\" \"));\n+\t\tassert.equal(seen.length, 0, argv.join(\" \"));\n+\t}\n+});\n+\n+test(\"the server's refusal is said in its words, with no credential in it\", async () => {\n+\tawait assert.rejects(\n+\t\trun([\"list\"], {}, { status: 403, body: { error: \"flags take the admin token here\" } }),\n+\t\t/flags take the admin token here/,\n+\t);\n+\tawait assert.rejects(\n+\t\trun([\"log\"], {}, { status: 400, body: { error: `bad ${KEY}` } }),\n+\t\t(e: Error) => !e.message.includes(KEY) && /\\[redacted\\]/.test(e.message),\n+\t);\n+\tconst { out, seen } = await run([\"log\", \"--limit\", \"5\"], {}, { status: 200, body: { changes: [change] } });\n+\tassert.equal(seen[0]!.url, `${SERVER}/admin/flags/audit?limit=5`);\n+\tassert.match(out.text, /trying Settle on game/);\n+});"},{"path":"client/test/visitor.test.ts","added":1,"removed":0,"diff":"--- a/client/test/visitor.test.ts\n+++ b/client/test/visitor.test.ts\n@@ -62,6 +62,7 @@\n \t\"unqueue\",\n \t\"visibility\",\n \t\"autosettle\",\n+\t\"flag\",\n \t\"ci\",\n \t\"shot\",\n \t\"prep\","}],"ci":null}