004-entitlements — routine prompt
The prompt block below is this track's live driver: the CS-Hourly routine
reads ROADMAP's front track and follows that track's ROUTINE.md, so this
file is the prompt and edits here take effect on the next firing without
touching the trigger.
It inherits 003's protocol wholesale — batch loop, atomic claim refs, read /
verify / output budgets, worktree rule, track handoff. Each of those was
earned by a recorded failure on 002 and carried through 003 unchanged; they
are not re-derived here. What changes is the claim namespace (claim/004-*),
the read budget's file, the scoreboard, and the WORK shapes, which are 004's
five phases.
Advance capabilities + entitlements (004) by a BATCH of items, then stop.
BATCH LOOP: repeat {claim → build → verify → PR → merge → update
SESSION.md} item by item — one item per PR (revertible slices), each fully
merged before the next is claimed. Continue until the FIRST of:
- 4 items landed this run;
- the next item is a phase-scale block (a whole phase, one capability or one
call site per PR notwithstanding) — do its first shippable slice as one
item, then stop;
- the next item is blocked → one line in SESSION.md, stop;
- no unclaimed item remains, or remaining context is too small to land
another item cleanly (never start what you cannot merge).
Read budgets are paid ONCE per run; between items re-read nothing — only
`git fetch` + the claim check for the next item.
READ BUDGET (hard): read .station/jobs/004-entitlements/SESSION.md
from the top through the end of "Next", once per run, and stop there. Open
the charter, an ADR, plans/02-entitlements.md or the PHP reference only when
the claimed item names it. Trust SESSION.md's scoreboard line; re-run a gate
only after a diff that moves it. Re-deriving settled context is the run's
largest cost — spend it on the diff.
CI POLICY (settled — spend zero words on it): GitHub Actions here is
noise; the merge gate is local `npm run verify` exit 0, plus
`cd apps/api && go vet ./... && go test ./...` only if apps/api changed.
Green locally → merge the PR. Never re-run, mention, or "fix" Actions.
Canonical: ROADMAP.md "Standing policy".
CLAIM, THEN BUILD (002's protocol — the open-PR gate alone raced 8 times):
1. `git fetch origin` · list open PRs · `git ls-remote origin 'refs/heads/claim/*'`.
- An open 004 PR exists → resume and land THAT PR as the batch's first
item, then continue the loop.
- Else take the top item under "Next" whose `claim/004-<item-slug>` ref
is absent OR stale. Ref deletion returns 403 in the remote
environment, so claim refs accumulate: a claim ref with no open PR
and no branch commit newer than 3 hours is stale — treat it as free
and re-claim over it. A slug SESSION.md's Completed already records
is done, not in flight.
2. Claim atomically BEFORE writing any code:
git push origin origin/main:refs/heads/claim/004-<item-slug>
Rejected push = claimed between your list and your push → return to 1.
Only a successful push is a claim; a SESSION.md line is not.
3. When your PR merges, attempt to delete branch and claim ref once; a
403 is expected there, not a failure — move on.
Take ADR numbers only after `git fetch`, from origin/main's docs/decisions/.
WORK: fan out where the item is an enumeration, solo where it is not.
- Phase 00 mints capability keys from
.archives/removal-safe/references/php/cs-app-v7/.../available_plan_features.php —
for the subsystems this port actually has, never the PHP feature list
wholesale. A key is user-facing in the Admin Portal, so it goes through
docs/GLOSSARY.md before it is minted. The package is
packages/capabilities (ADR-0030: identity vocabularies are generated
packages; runtime data is served).
- Phase 01 resolves per plan from plans.settings beside PlanLimitService,
in its shape. DEFAULT DENY, and the omitted-key test says so.
- Phase 02 is the enforcement, one write path per PR, and it is gated on
the grandfathering audit having RUN — evidence first, switch second.
plan_level retires here: 12 references across 8 files → 0.
- Phase 03 puts capabilities on the admin plan form beside the quotas.
- Phase 04 shows entitlement to the user, in the catalogue surface 003's
registry derives.
- A new or widened gate is watched FAILING once on a deliberately broken
input, and the run that widened it records that in evidence/.
- TRACK HANDOFF: when every charter phase is closed and verified, the
next run's single item is to charter 005 from ROADMAP's table under
docs/guides/workstream.md — README, ROUTINE.md (inherit this
protocol), SESSION.md — scoped from ROADMAP's track section and
the named 001-renaissance plan; then mark 004 DONE on ROADMAP, and
subsequent runs work the new track. When 006 closes, drain ROADMAP's
"Standing repairs" the same way; when those are done, report completion
and recommend disabling the routine — do not invent scope.
Integrate and verify results yourself; never merge on an agent's word.
Any agent that writes ANYTHING runs in its own `git worktree`, never the
run's tree (an in-tree reviewer destroyed an uncommitted fix on 002); if
worktree tests resolve workspace packages, relink node_modules first — a
symlink into the run's tree reads the wrong files and false-passes.
VERIFY ONCE: while iterating, run only the touched tests
(`npx vitest run <files>`, `go test ./internal/<pkg>/...`) or the one gate
the item moves. Run `npm run verify` exactly once, when the diff is final,
immediately before the PR, plus `go vet ./... && go test ./...` in apps/api
if apps/api changed; if it fails, fix and re-run — never as a baseline,
progress check, or "before and after".
RULES THAT STAND: migrations at the next free number with .down.sql,
applied manually, never renumbered; handler → repository → database
layering, no business logic in handlers; APIResponse envelope; breaking
API changes under /api/v2/, never in place; frontend uses Studio
primitives and tokens only — nothing new in components/ui, no raw
colours; product vocabulary from docs/GLOSSARY.md; no adjacent cleanup —
one SESSION.md row instead. A capability that is loading or failed
resolves FALSE — never an accidental grant. Consequential product calls
become ADRs, never silent choices.
OUTPUT BUDGET (hard — the run's meaning is its diff, not its prose):
- New ADR only for a decision that constrains future work, ≤ 120 lines.
- SESSION.md Completed entries ≤ 8 lines, linking the ADR/PR.
- ≤ 3 new open-item rows per run, ≤ 3 lines each; a one-line fix in a
file already touched is fixed, not recorded.
- PR body ≤ 20 lines. Final report: one line per item landed (item, merge
commit, scoreboard before → after) + one line for what is next.
Close out per item: SESSION.md Completed entry + refresh "Next"; tick
ROADMAP.md's 004 row only when verification proved it. Conventional
Commit, PR to main, merge on local green.
Shape notes
- Inherited, not re-derived. The protocol above is 003's, which was 002's. The history behind each rule lives in 002's ROUTINE.md shape notes; a run that wants to change a rule reads that first, because each one is a fix for something that actually went wrong.
- The scoreboard is two numbers from source, so it cannot drift: the
plan_levelreference count (12 at baseline, driven to 0 by phase 02) andcheck:entitlement-parity's own closing sentence once phase 00 widens it to capabilities. "Before → after" in the report makes each run's contribution visible. - Evidence before enforcement. Phase 02 is the only phase here with an ordering constraint inside it: the grandfathering audit runs before the gate is flipped, because the number it produces decides whether the slice needs a migration, a notice, or both. A run that enforces first has destroyed the measurement.
- The riskiest thing this track can ship is a silent grant. Default deny, a false resolution while loading, and gate rule 2 (a capability with no enforcement call site fails the build) are the three places that is held.
Source: .station/jobs/004-entitlements/ROUTINE.md