Skip to content
Toolkit

004-entitlements — a plan says what it includes, and the server checks

Status: DONE · Chartered: 2026-08-28 · Closed: 2026-08-28 · Close-out: reports/CLOSE.md

Problem

The system can count things and cannot gate anything. Stated with evidence in .station/jobs/001-renaissance/plans/02-entitlements.md, which this track supersedes for tracking; the analysis there stands and is not restated here. The four findings that shape the phases:

  1. No boolean capability exists anywhere. All fifteen plan keys are numeric quotas (Audit 02-D2). There is no "may use premium themes", no "may use AI tools", no "may use pro blocks" — nothing a plan can include rather than count.
  2. plan_level is decorative. All 85 block types carry free/pro/ultimate, the picker renders PRO/ULT badges from it, and the create path checks nothing. 12 references across 8 files is the baseline this track drives to zero.
  3. The enum cannot map to real plans. plan_level lives only in block_types.go; plans are admin-created rows with arbitrary names. Themes and templates carry no plan reference at all, only is_enabled.
  4. A badge that gates nothing is the shape of the defect, and it is the shape the gate must make unrepeatable — not a mistake to correct once.

What is already built and needs consuming, not building: feature_flags is complete, targeted per plan and wired to a real consumer (ADR-0011); PlanLimitService already resolves quotas per user with typed limit errors, so a capability check belongs beside it in the same shape; plans.settings is JSONB and the admin API already writes it (ADR-0013); and the block registry carries an entitlement field end to end — wrong type, right plumbing.

Objective

An operator expresses from the Admin Portal what any plan includes — how many and which — and the server enforces it on the write path. A premium theme, an AI tool or a pro block is granted to a plan without a code change. Nothing user-visible claims an entitlement the server does not check, and plan_level is gone.

Phases

PhaseWhatDone when
00 — VocabularyMint the capability keys as packages/capabilities (ADR-0030), from available_plan_features.php in the PHP reference tree — for the subsystems this port actually has — through docs/GLOSSARY.md, which capability names go through because they are user-facing in the Admin PortalThe package ships and check:entitlement-parity reads it; every minted key has a recorded default and a reason
01 — ResolutionCapabilities resolve per plan from plans.settings, beside PlanLimitService and in its shape. Default deny, including a plan whose settings omit the keyA Go test asserts the omitted-key default and says so; resolution is one call site, not a pattern
02 — EnforcementThe write path checks the capability and returns the plan-limit error shape; plan_level retired (12 → 0). Grandfathering first: existing rows of a now-gated type stay readable, editable and deletable — only creation is blockedThe gate's rule 4 (no surviving plan_level) passes unconditionally, and the grandfathering audit ran before the switch was flipped
03 — ControlsQuotas and capabilities editable on the admin plan formAn operator grants a capability and it takes effect for a user on that plan without a deploy — the 02-D3 proof, live
04 — Show itThe catalogue surface says what the current plan includes, what it does not, and what upgrading changesGating reads as a product feature rather than an enforcement mechanism; every badge on screen derives from a resolved capability

Phases 00–03 are independent of everything outside this track. Phase 04 renders into the catalogue surface 003's registry already derives.

Out of scope

Billing, pricing, checkout and proration — this track decides what a plan contains, never what it costs. Per-user overrides (a real need, a separate design). Usage metering and soft limits: quotas stay hard counts. The affiliate commission percentage in plan_settings — related shape, unrelated concern. Anything that would make a second gating mechanism: decision 005 answered replace, so plan_level is retired rather than complemented.

Verification

Gate — scripts/check-entitlement-parity.mjs (exists, for flags; this track widens it). It must fail CI when:

  1. A capability is referenced in the client — badge, lock state, upgrade prompt — with no entry in the registry.
  2. A capability exists in the registry with no server-side enforcement call site. This is the rule that makes 02-D2 unrepeatable: a badge without a gate becomes a build failure, not a discovery three audits later.
  3. A block type, theme or template declares an entitlement the registry does not define.
  4. Any surviving reference to plan_level after phase 02. Unconditional.

Observed failing once on a deliberately broken input, per docs/guides/workstream.md — every gate here is.

Tests. Go: capability resolution including the omitted key (default deny, asserted as such); enforcement returning the plan-limit error shape, table-driven from the registry so a new gated resource without a test fails the suite; grandfathering, which is the contract with existing users. Unit: badges derive from a resolved capability, never a tier string; a resolution that is loading or failed is false, never an accidental grant. Live E2E per new surface — entitlement-block-create.spec.ts (the API refuses, the UI shows the upgrade path, the row count is asserted) and the plan-form half of admin-plan-settings.spec.ts.

Evidence. evidence/grandfathering-audit.md — how many existing rows would violate the new gates, by user and plan, captured before enforcement ships. Non-negotiable: that number decides whether phase 02 needs a migration, a notice, or both. The queries exist from 001's quota half, where the answer on a stock database was zero. Plus evidence/capability-registry.md (every capability minted, its default, its enforcement call site) and evidence/verification-runs.md.

Merge policy: the standing policy on ROADMAP.md.

Risks

RiskMitigation
Enforcing a gate never enforced breaks existing users — someone on a free plan has "ultimate" blocks live todayPhase 02 grandfathers existing rows and the audit query runs before the switch is flipped. A release-note event, not a silent change
Capability sprawl — a hundred booleans nobody can reason aboutRegistry-defined with a parity gate, reviewed as a product surface, named through the glossary
Two gating mechanisms survivingDecision 005 is answered (replace); rule 4 is unconditional
Resolution becomes a hot pathResolve at session load, cache with the existing Cacher, treat changes as eventually consistent within the TTL

Source: .station/jobs/004-entitlements/README.md

Library