Agent pack
Feature flags (@blueforge-studio/flags)
The fleet's feature-flag package: reading, adding and testing flags — never setting one.
Verified 2026-10-11: package 0.1.0 is on packr (npm view returns it, latest = 0.1.0; I unpacked the tarball and read its README and exports);
CLI and operator docs read from forge-control main (44ab3e4c5): docs/reference/commands/forge-flags.md, docs/help/feature-flags.md, spec
docs/superpowers/specs/2026-09-30-feature-flags-service-design.md. UNVERIFIED: whether the service routes and DDL are deployed to production (docs say
"merged 2026-10-10", nothing says "live"); server-side scope resolution in code (only the spec describes it); that a flags:read key can be minted in prod.
Check with forge flags list / a real resolve call before telling anyone a flag is enforced.
Model
A flag has a definition (key UPPER_SNAKE, type bool|string|enum|number|json, compiled safe default, owner, protected, sidecar_overridable) and optional
operator values per scope: portfolio, project, app, each optionally per env. Most specific scope wins; a value says where it came from (source:
operator@<scope>[/<env>], sidecar@<sha>, compiled-default). A missing operator value is not a decision: defaults live in the definition. Percentage rollout is not in v1.
Every change is audited (who, old/new, reason). The service is central (forge-control hosting-api, /api/flags), not per-tenant data.
Reading a flag in an app (server-side)
import { defineFlags, createFlagClient } from '@blueforge-studio/flags'
export const flags = defineFlags({
PAYMENT_PLANS: { type: 'enum', values: ['off', 'trial_only', 'all'], default: 'off', maxStalenessMs: 60_000 },
BANNER: { type: 'bool', default: false },
})
const client = createFlagClient({ schema: flags, url: process.env.FORGE_API_URL!, key: process.env.FLAGS_READ_KEY!, app: 'lq-core', env: 'prod' })
await client.ready() // resolves, never rejects (2 s default timeout)
client.enum('PAYMENT_PLANS') // typed getters: bool / enum / number / string; client.get(k) -> { value, source, stale, ageMs }
await client.refresh() // force revalidation, e.g. at checkout
- Code against
FlagSource<D>(the real client and test fakes both implement it), not the concrete client. - Fail-closed: never throws at runtime. On failure it serves the last-known-good snapshot (
source: 'stale-cache',stale: true) until the staleness ceiling, then the compiled default ('compiled-default'). Ceiling = tightest of the flag'smaxStalenessMs, the server's per-flag value, else 15 min. Money flags:maxStalenessMs: 60_000. The only throws are startup misconfiguration (maxStalenessMs < 2 x pollIntervalMs, or a compiled default invalid for its own definition). - Values are re-validated against your compiled definition (type, enum membership, min/max); a bad server value falls back to the default. Unknown server keys are ignored.
- Polls every 30 s +/-20% with ETag; 401/403 counts as an outage (backs off 5 min).
get()is synchronous and cache-backed. Cache is in-memory unless you passcache.store. - The key is a project-scoped
flags:readkey, server env only. Mint withforge api-key create --project <slug> --name <n> --scope flags:read(aflags:readmint without--projectis refused; verified in forge-cli tests, not run). Never put it in a browser bundle, a log or a PR (tokens.md).
In the browser
@blueforge-studio/flags/client (React optional peer, >=18): const { status, get } = useFlags(flags) with status 'loading'|'ready'|'fallback'. It reads the app's own GET /api/flags, never hosting-api, and never holds
a key. Serve that route with flagsHandler(client, { expose: ['BANNER'] }): an explicit allowlist, never expose protected keys. Hiding UI is cosmetic; enforce server-side.
Changing a flag (operators; agents do not)
forge flags list | get | set | define | history (reference: forge-control docs/reference/commands/forge-flags.md). define needs forge >= 2.10.9 (earlier releases have no define; npm view @blueforge-studio/forge version to check).
forge flags get TRIAL_DAYS --project <slug> --app <slug> --env prod answers "why is this 14?" with the source.
forge flags set <KEY> <value> --scope portfolio|project|app [--project] [--app] [--env] --reason "..." [--if-match <version>].
| Flag kind | Who may change it |
|---|---|
Money-affecting (PAYMENT_PLANS, TRIAL_REQUIRES_CARD) |
platform-admin browser session only; operator and script API keys get 403 |
Protected (TRIAL_DAYS) |
platform operator (operator key or platform-admin session) |
| Everything else | project admin (project/app scope), operator for portfolio scope |
Creating a flag: forge flags define <KEY> --type bool|number|string|enum|json --default <v> --description "..." --reason "..." [--allowed a,b,c]. A project-bound flags:admin key may create non-protected definitions only
(no --owner, --protected, --money, --no-sidecar); protected and money definitions need the operator or a platform-admin session. A definition holds the default; it sets no operator value.
Project-bound keys (forge flags key create --project <slug> --name <n> --level read|write|admin) are minted by an operator; agents do not mint, hold or print them. A flags:write key sets project/app values of non-protected flags
(forge flags set with such a key needs forge >= 2.10.10: on 2.10.9 it fails at its definitions read; the fix is forge-control #2010. With a write key the CLI cannot read the definition, so it infers the value's type from the text and the server validates it: pass true/false, a number or JSON as such).
PAYMENT_PLANS=live needs a two-step confirmation (single-use token, 5 minute TTL). --reason (min 8 chars) is mandatory on protected flags and recorded immutably.
PAYMENT_PLANS is deliberately off at every scope by its compiled default (free plans only, decision 2026-10-02); turning trials on is a deliberate, audited set, never a seeded row.
Rules for agents
- Never change a flag value, and never handle a session cookie,
FORGE_SESSION_TOKENor an operator key. Reading (get,list,history) is fine;setis the operator's. - Do not seed or "document" operator values in code or migrations. A seeded row freezes a value as if an operator decided it (the spec calls this out for
PAYMENT_PLANS). - Pick a safe, fail-closed compiled default for every new flag (the off/least-privilege state), because that is what users get if the service is down.
- Test both states of a flag in the repo's own tests (use a
FlagSourcefake), and the fallback path. - Sidecar
flags:defaults are not read by the SDK yet (spec phase P3 is not built). Declaringflags:inblueforge.features.yml(schemas >= 0.30.0) records intent only; it enforces nothing today. - Do not claim a flag is "live" or "enforced" until you have seen the real resolve return it with the expected
source.
Decision (operator, 2026-10-11): ship risky changes behind a flag, as a pilot
Risky or revenue-affecting features ship behind a flag so they can be tested, rolled back and switched without a deploy. The operator decided this applies to a pilot subset of the fleet now, not blindly to all repos, because the flags service's production deployment is still unverified and a flag nobody enforces is worse than none.
- Pilot repos:
lq-core(the spec's canary, phase P5) andblueforge, plus any repo that already installs@blueforge-studio/flags. Where a repo is not on the list and does not use the SDK, say so in the PR; do not add a flag nothing enforces. - Widen from the pilot when (a) a real resolve call shows the expected
sourcein prod, (b) the lq-core canary has run a clean week (fallback events 0, healthy 304 ratio), and (c) the operator says so. Until then this is a pilot rule, not a fleet requirement. - Every new flag needs an owner and a removal plan. The spec has
ownerbut no expiry field (UNVERIFIED that none exists elsewhere), so put the removal condition in the flag's description.