abso flag: list, flip and audit a server's feature flags Version 261 of shared· readspeed· Oct 15 (2026-10-15 19:49 UTC) · Not checked
A 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.
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). 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. abso flag log [--limit N]: the server's record of changes, newest first: when, who, which flag where, old to new, and why. The 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.
Tests: client/test/flag-command.test.ts. Visitor folders refuse flag (visitor.test.ts).
Version 260 · Files at version 261
4 files, 319 lines added, 0 removed.
--- /dev/null
+++ b/client/src/flag-commands.ts
@@ -0,0 +1,151 @@
1 + // abso flag: read, flip and audit a server's feature flags, with no deploy. Each flag has its values, a safe default, 2 + // and a line of what it gates; a value is set for the whole server, one project, or one person. The server decides who 3 + // 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 4 + // header and only to a server ABSO_ADMIN_SERVERS names, and never printed. 5 + import { type Parsed, str, UsageError } from "./args.ts"; 6 + import { type Env, type Output, open } from "./commands.ts"; 7 + import type { Config } from "./config.ts"; 8 + import { fromEnv } from "./env-names.ts"; 9 + import { adminGoesTo, adminToken } from "./key-admin.ts"; 10 + import { shortWhen } from "./times.ts"; 12 + /** One flag as GET /admin/flags answers it: what it takes and gates, and where it's set. */ 13 + export interface ListedFlag { 14 + readonly values: readonly string[]; 15 + readonly safe: string; 16 + readonly what: string; 17 + readonly stagingOnly?: boolean; 18 + readonly env?: string; 19 + readonly projects?: Readonly<Record<string, string>>; 20 + readonly people?: Readonly<Record<string, string>>; 23 + export type FlagScope = { readonly env: true } | { readonly project: string } | { readonly person: string }; 25 + /** One change as GET /admin/flags/audit answers it. */ 26 + export interface FlagChange { 29 + readonly flag: string; 30 + readonly scope: FlagScope; 31 + readonly old: string | null; 32 + readonly new: string | null; 33 + readonly why: string; 37 + '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>]'; 39 + /** The admin token when there is one for this server, else none: a server that takes an owner's key answers without it. */ 40 + export function adminFor(server: string, env: Readonly<Record<string, string | undefined>>): string | undefined { 41 + if (!adminGoesTo(server, fromEnv(env, "ADMIN_SERVERS"))) return undefined; 43 + return adminToken(env); 49 + function scrub(text: string, secrets: readonly string[]): string { 50 + let out = text.replace(/abso_sk_[A-Za-z0-9_-]+/g, "[redacted]"); 51 + for (const secret of secrets) if (secret.length > 0) out = out.split(secret).join("[redacted]"); 55 + async function call(config: Config, admin: string | undefined, path: string, body?: unknown): Promise<unknown> { 56 + const secrets = [admin ?? "", config.token ?? ""].filter((s) => s.length > 0); 57 + let response: Response; 59 + response = await fetch(`${config.server.replace(/\/+$/, "")}${path}`, { 60 + method: body === undefined ? "GET" : "POST", 62 + ...(config.token ? { authorization: `Bearer ${config.token}` } : {}), 63 + ...(admin ? { "x-abso-admin": admin } : {}), 64 + ...(body === undefined ? {} : { "content-type": "application/json" }), 66 + ...(body === undefined ? {} : { body: JSON.stringify(body) }), 67 + signal: AbortSignal.timeout(30_000), 70 + throw new UsageError(scrub(err instanceof Error ? err.message : String(err), secrets)); 72 + const text = await response.text(); 75 + parsed = JSON.parse(text); 77 + throw new UsageError( 78 + response.ok ? "the server's answer was not JSON" : scrub(text.slice(0, 500), secrets) || `${response.status}`, 82 + const error = (parsed as { error?: unknown }).error; 83 + if (response.status === 404) throw new UsageError(`${config.server} keeps no feature flags`); 84 + throw new UsageError(scrub(typeof error === "string" ? error : `the server answered ${response.status}`, secrets)); 89 + /** Where a value is set, in words: "here", "project game", "person:p1". */ 90 + export function scopeWords(scope: FlagScope): string { 91 + return "project" in scope ? `project ${scope.project}` : "person" in scope ? scope.person : "here"; 94 + /** What abso flag list prints: each flag, what it takes, its safe value, and every place it's set. */ 95 + export function flagListText(flags: Readonly<Record<string, ListedFlag>>): string { 96 + const names = Object.keys(flags).sort(); 97 + if (names.length === 0) return "No flags."; 100 + const f = flags[name]!; 102 + `${name}: ${f.env ?? `${f.safe} (unset)`}. Takes ${f.values.join(", ")}; safe ${f.safe}${f.stagingOnly ? "; staging only" : ""}.`, 104 + ...Object.entries(f.projects ?? {}).map(([p, v]) => ` project ${p}: ${v}`), 105 + ...Object.entries(f.people ?? {}).map(([p, v]) => ` ${p}: ${v}`), 111 + /** One audited change in a line: when, who, which flag where, old to new, and why. */ 112 + export function changeText(c: FlagChange, now: number = Date.now()): string { 113 + return `${shortWhen(Date.parse(c.at), now)} ${c.by} ${c.flag} ${scopeWords(c.scope)}: ${c.old ?? "unset"} to ${c.new ?? "unset"}. "${c.why}"`; 116 + export async function runFlag(args: Parsed, env: Env): Promise<Output> { 117 + const [sub = "list", flag, value, ...extra] = args.positionals; 118 + const { config } = open(env); 119 + const admin = adminFor(config.server, env.env); 120 + if (sub === "list" && flag === undefined) { 121 + const body = (await call(config, admin, "/admin/flags")) as { 123 + flags: Record<string, ListedFlag>; 125 + return { text: `${flagListText(body.flags)}\n`, json: { ...body } }; 127 + if (sub === "log" && flag === undefined) { 128 + const limit = str(args, "limit") ?? "20"; 129 + if (!/^[0-9]{1,3}$/.test(limit) || Number(limit) < 1) throw new UsageError("--limit is a number from 1 to 999"); 130 + const body = (await call(config, admin, `/admin/flags/audit?limit=${limit}`)) as { changes: FlagChange[] }; 131 + const text = body.changes.length === 0 ? "No changes yet." : body.changes.map((c) => changeText(c)).join("\n"); 132 + return { text: `${text}\n`, json: { ...body } }; 134 + const setting = sub === "set" && flag !== undefined && value !== undefined && extra.length === 0; 135 + const unsetting = sub === "unset" && flag !== undefined && value === undefined; 136 + if (!setting && !unsetting) throw new UsageError(USAGE); 137 + const why = str(args, "why"); 138 + if (why === undefined || why.trim().length < 3) throw new UsageError('every change says why: --why "..."'); 139 + const project = str(args, "project"); 140 + const person = str(args, "person"); 141 + if (project !== undefined && person !== undefined) 142 + throw new UsageError("a value is set for a project or a person, not both"); 143 + if (person !== undefined && !person.startsWith("person:")) throw new UsageError("--person is person:<id>"); 144 + const body = (await call(config, admin, `/admin/flags/${encodeURIComponent(flag!)}`, { 145 + value: setting ? value : null, 147 + ...(project === undefined ? {} : { project }), 148 + ...(person === undefined ? {} : { person }), 149 + })) as { revision: number; change: FlagChange }; 150 + return { text: `${changeText(body.change)}\n`, json: { ...body } }; --- a/client/src/main.ts
+++ b/client/src/main.ts
@@ -43,6 +43,7 @@
43 43 import { doctor, doctorText, plainError, realProbe, whoami } from "./doctor.ts"; 44 44 import { runDraftSync, runLand, runSwitch } from "./drafts.ts"; 45 45 import { runExport } from "./export.ts"; 46 + import { runFlag } from "./flag-commands.ts"; 46 47 import { runGroup, runGroups } from "./group-commands.ts"; 47 48 import { runBlame, runWhere, runWho, runWhy } from "./history.ts"; @@ -598,6 +599,14 @@
598 599 "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).", 599 600 run: runAutosettle, 603 + flags: { why: "string", project: "string", person: "string", limit: "string" }, 605 + '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>]', 607 + "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.", 602 611 flags: { version: "string", revoke: "boolean" }, 603 612 usage: "abso ci [<version>] | abso ci --revoke", --- /dev/null
+++ b/client/test/flag-command.test.ts
@@ -0,0 +1,158 @@
1 + // abso flag: a server's feature flags listed, flipped with a reason, and audited. The admin token goes only to a server 2 + // ABSO_ADMIN_SERVERS names; the folder's own key goes with every call, for a server that takes an owner's key. Every 3 + // test passes its own ABSO_ADMIN_TOKEN, so this machine's ~/.abso is never read. 4 + import assert from "node:assert/strict"; 5 + import { mkdirSync, mkdtempSync, writeFileSync } from "node:fs"; 6 + import { tmpdir } from "node:os"; 7 + import { join } from "node:path"; 8 + import { test } from "node:test"; 9 + import { parseArgs } from "../src/args.ts"; 10 + import { adminFor, changeText, type FlagChange, flagListText, type ListedFlag, runFlag } from "../src/flag-commands.ts"; 12 + const SERVER = "http://localhost:8787"; 13 + const KEY = "abso_sk_owner-key-value"; 14 + const ADMIN = "admin-token-value"; 15 + const FLAGS = { why: "string", project: "string", person: "string", limit: "string" } as const; 17 + function folder(): string { 18 + const root = mkdtempSync(join(tmpdir(), "abso-flag-")); 19 + mkdirSync(join(root, ".abso")); 20 + writeFileSync(join(root, ".abso", "config.json"), JSON.stringify({ server: SERVER, project: "abso", agent: "me" })); 33 + env: Record<string, string>, 34 + answer: { status: number; body: unknown }, 37 + const previous = globalThis.fetch; 38 + globalThis.fetch = (async (url, init) => { 41 + method: init?.method ?? "GET", 42 + headers: new Headers(init?.headers), 43 + ...(typeof init?.body === "string" ? { body: JSON.parse(init.body) } : {}), 45 + return new Response(JSON.stringify(answer.body), { status: answer.status }); 48 + const out = await runFlag(parseArgs("flag", argv, FLAGS), { 50 + env: { ABSO_TOKEN: KEY, ...env }, 53 + return { out, seen }; 55 + globalThis.fetch = previous; 59 + const change: FlagChange = { 60 + at: "2026-10-15T19:04:00.000Z", 61 + by: "key k_1, box b", 62 + flag: "autosettle-default", 63 + scope: { project: "game" }, 66 + why: "trying Settle on game", 69 + test("the admin token goes only to a server ABSO_ADMIN_SERVERS names, and is never needed to try", () => { 70 + assert.equal(adminFor(SERVER, { ABSO_ADMIN_TOKEN: ADMIN }), undefined, "no server named"); 71 + assert.equal(adminFor(SERVER, { ABSO_ADMIN_TOKEN: ADMIN, ABSO_ADMIN_SERVERS: "https://api.abso.dev" }), undefined); 72 + assert.equal(adminFor(SERVER, { ABSO_ADMIN_TOKEN: ADMIN, ABSO_ADMIN_SERVERS: SERVER }), ADMIN); 75 + test("list says each flag's value, what it takes, its safe value, what it gates, and every place it's set", () => { 76 + const flags: Record<string, ListedFlag> = { 77 + "byoc-demo": { values: ["on", "off"], safe: "on", what: "The BYOC demo page.", stagingOnly: true }, 78 + "autosettle-default": { 79 + values: ["off", "advise", "settle"], 81 + what: "Auto-settle's mode for an unpicked project.", 83 + projects: { game: "settle" }, 84 + people: { "person:p1": "off" }, 90 + "autosettle-default: advise. Takes off, advise, settle; safe off.", 91 + " Auto-settle's mode for an unpicked project.", 92 + " project game: settle", 94 + "byoc-demo: on (unset). Takes on, off; safe on; staging only.", 95 + " The BYOC demo page.", 98 + assert.equal(flagListText({}), "No flags."); 101 + test("a change in a line: when, who, which flag where, old to new, and why", () => { 103 + changeText(change, Date.parse("2026-10-15T20:00:00Z")), 104 + '19:04 UTC key k_1, box b autosettle-default project game: unset to settle. "trying Settle on game"', 106 + assert.match(changeText({ ...change, scope: { env: true }, old: "settle", new: null }), / here: settle to unset\./); 109 + test("set posts the value, scope and reason with the folder's key; the admin token only where it may go", async () => { 110 + const { out, seen } = await run( 111 + ["set", "autosettle-default", "settle", "--project", "game", "--why", "trying Settle on game"], 112 + { ABSO_ADMIN_TOKEN: ADMIN }, 113 + { status: 200, body: { revision: 3, change } }, 115 + assert.equal(seen.length, 1); 116 + assert.equal(seen[0]!.url, `${SERVER}/admin/flags/autosettle-default`); 117 + assert.equal(seen[0]!.method, "POST"); 118 + assert.deepEqual(seen[0]!.body, { value: "settle", why: "trying Settle on game", project: "game" }); 119 + assert.equal(seen[0]!.headers.get("authorization"), `Bearer ${KEY}`); 120 + assert.equal(seen[0]!.headers.get("x-abso-admin"), null, "ABSO_ADMIN_SERVERS doesn't name it"); 121 + assert.match(out.text, /unset to settle/); 122 + const named = await run( 123 + ["unset", "autosettle-default", "--why", "back to the default"], 124 + { ABSO_ADMIN_TOKEN: ADMIN, ABSO_ADMIN_SERVERS: SERVER }, 125 + { status: 200, body: { revision: 4, change: { ...change, scope: { env: true }, old: "advise", new: null } } }, 127 + assert.equal(named.seen[0]!.headers.get("x-abso-admin"), ADMIN); 128 + assert.deepEqual(named.seen[0]!.body, { value: null, why: "back to the default" }); 131 + test("a change without a reason, or for a project and a person both, is refused before anything is sent", async () => { 132 + for (const argv of [ 133 + ["set", "autosettle-default", "advise"], 134 + ["set", "autosettle-default", "advise", "--why", "x"], 135 + ["set", "autosettle-default", "advise", "--why", "both", "--project", "a", "--person", "person:b"], 136 + ["set", "autosettle-default", "advise", "--why", "bad person", "--person", "p1"], 137 + ["unset", "autosettle-default", "advise", "--why", "too many words"], 138 + ["flip", "autosettle-default"], 140 + const seen: Seen[] = []; 141 + await assert.rejects(run(argv, {}, { status: 200, body: {} }, seen), argv.join(" ")); 142 + assert.equal(seen.length, 0, argv.join(" ")); 146 + test("the server's refusal is said in its words, with no credential in it", async () => { 147 + await assert.rejects( 148 + run(["list"], {}, { status: 403, body: { error: "flags take the admin token here" } }), 149 + /flags take the admin token here/, 151 + await assert.rejects( 152 + run(["log"], {}, { status: 400, body: { error: `bad ${KEY}` } }), 153 + (e: Error) => !e.message.includes(KEY) && /\[redacted\]/.test(e.message), 155 + const { out, seen } = await run(["log", "--limit", "5"], {}, { status: 200, body: { changes: [change] } }); 156 + assert.equal(seen[0]!.url, `${SERVER}/admin/flags/audit?limit=5`); 157 + assert.match(out.text, /trying Settle on game/); --- a/client/test/visitor.test.ts
+++ b/client/test/visitor.test.ts
@@ -62,6 +62,7 @@