carlos / platform Public

plan: domain registration 2a, domains at the account level

Spec rev 4 §11 folded into Plan 2 (§11.8), split as 2a; 2b keeps the
reconcile, apex reconverge and alerts. Includes the round 1 review brief.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev d6352683aeb241bbd716327f0f2b06fad49272af parent 12158f4
2 files changed, +378 −0
  • docs/superpowers/plans/2026-11-19-domain-registration-2a-account-domains.md +300 −0
  • docs/superpowers/reviews/CODEX-REVIEW-BRIEF-domains-plan-2a.md +78 −0
diff --git a/docs/superpowers/plans/2026-11-19-domain-registration-2a-account-domains.md b/docs/superpowers/plans/2026-11-19-domain-registration-2a-account-domains.md
new file mode 100644
index 000000000..63e2ad7c0
--- /dev/null
+++ b/docs/superpowers/plans/2026-11-19-domain-registration-2a-account-domains.md
@@ -0,0 +1,300 @@
+# Domain registration, Plan 2a: domains at the account level Implementation Plan
+
+> **For agentic workers:** REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (`- [ ]`) syntax for tracking.
+
+**Goal:** An account gets a **Domains** page listing every domain it uses (bought here or registered elsewhere), buys a domain in three steps with or without an app, keeps saved contacts, and points a bought domain at an app later.
+
+**Architecture:** The purchase, registration and contact tables already live in console.db (`internal/console/domainstore.go`, migrated from `store.go:793`); what ties them to an app is the SQL gate classification (`store_gate.go:231`), the per-app mutation in `purchaseMutation` (`domainbuy.go:414`) and the app-scoped doors. This plan makes `app` optional on a purchase, adds saved contacts and a registrant snapshot per registration, derives "registered elsewhere" cards from the existing claims, and moves the doors to `/a/{sqid}/domains/...` with redirects from the old app-scoped URLs. No new storage location and no data move.
+
+**Tech Stack:** Go, modernc SQLite (console.db), `html/template` console pages built from the mockup kit, `golang.org/x/net/publicsuffix`, the existing `registrar`, `zonehost`, `billing` seams.
+
+**Spec:** `docs/superpowers/specs/2026-11-01-domain-registration-design.md`, revision 4. §11 is this plan; read §11 whole, plus §4.1, §5.1 and §5.3. Plan 1 (`docs/superpowers/plans/2026-11-01-domain-registration-1-buy.md`) built the engine this plan changes.
+
+**Plans in this series:** 1 buy (merged 20c867c, live). **2a account-level domains (this plan).** 2b keep it working: daily registrar reconcile, apex reconverge on edge-set change, balance alert, nameserver setup check verb, registrant email verification (§4.4), contact 429 not final, log the registry message on code 399. 3 renewals. 4 customer records, change owner, transfer out. Transfers in (R7) come after Plan 3 as a spec revision; their entry point is the "Registered elsewhere" card this plan builds.
+
+**Switch-on:** the Domains page and nav item are visible to every account on merge (no flag): "registered elsewhere" cards need nothing configured. Buying keeps Plan 1's switch (`domainBuyReady`), already on for dev and flagship. Roll dev first, then flagship with the next release.
+
+## Global Constraints
+
+- Spec §11 wins over earlier sections where they disagree (spec status line).
+- Storage finding, recorded in the spec by Task 2: §11.1 says Plan 1 keeps purchases "in its app's own database"; they are in console.db. §11.7's "move to the account store" therefore means: reclassify, add columns and tables, backfill. Purchase IDs, states and URLs keep working (old URLs redirect, Task 9).
+- Every money and registration rule from Plan 1 stands unchanged: no money without a registration, no registration without an authorised payment, an ambiguous answer is never a failure, registrar-side auto-renew OFF (spec §5.1, §5.5).
+- **Editing a saved contact never changes a registration (R12).** A saved contact's registrar handle is used as-is and never passed to `Registrar.EnsureContact` again: the Openprovider adapter updates an existing handle in place when the name matches (`internal/registrar/openprovider/client.go:136-155`). An edit clears the handle; the next purchase with that contact mints a new one with `EnsureContact(ctx, "", c)`.
+- Permissions (§11.7, my calls marked): every account member sees the Domains page and a domain's page. Owners only: buy, saved contacts (list, add, edit, remove), point a bought domain at an app, add an address under a bought domain (my call: these move or extend a paid domain), and the purchase card. "Add a domain you own" and its addresses use the existing attach door's own permission for the chosen app.
+- Every new route joins the route registers listed in Task 9's Files (the route-census tests fail otherwise).
+- No registrar or DNS host name in any customer-facing string. Every new string lives in a `*_copy.go` file as a draft, replaced by the copy pass (Task 11). Copy house rules: no em or en dashes, curly quotes in prose, `cli.`/`door.` keys lower case with no final full stop.
+- Renewals do not exist until Plan 3. Nothing in this plan says or implies a domain "renews"; the Renewal card shows the expiry date and next year's price only, and the auto-renew switch ships with Plan 3 (my call: a switch that changes nothing would mislead).
+- Zero new steady-state S3 requests. The Domains page reads claims through the existing cache (`s.claims.ListWithUnread`, `claimcache.go:95`), never a fresh bucket list per request.
+- Writing Go here (AGENTS.md): every function with a `ctx` passes it on; no `time.Sleep` in tests; `errors.Is`/`As`; no function over 300 lines or file over 3,000 (`make code-health` before pushing).
+- Review budget (AGENTS.md stopping rules): Astra per-task review only on Tasks 4, 6, 7 and 9 (money flow, termination, claim ownership, security gates); Fable joins Astra on Task 6 and the whole-branch review. At most three rounds each; stop at the first round with no P1.
+- Local verification: only the touched packages' tests with `-run` (AGENTS.md "Targeted local tests"; no full suites on docs-t1). CI runs everything.
+
+## Review Focus
+
+1. **The chosen app is purged while the purchase is in flight** (spec C3). Expected: payment and registration finish, the purchase reaches `done` with `App` empty, no claim is written, the zone holds no apex or `www` records, and the purchase card says the domain is ready to point at an app. Test in Task 4: `TestPurchaseAppPurgedMidwayFinishesUnpointed`.
+2. **An app holding a bought domain's addresses is purged** (spec C2). Expected: the app's custom-domain claims are released, the card shows the domain with no addresses and "Point at an app", and pointing it at another app of the same account then succeeds. Tests in Task 6: `TestPurgeReleasesTheAppsDomainClaims` and Task 7: `TestPointAfterPurgeSucceeds`.
+3. **A saved contact is edited after a domain was registered with it.** Expected: the registration's registrant and handle are unchanged; the next purchase with the edited contact calls `EnsureContact` with an empty handle and stores the new handle on the contact. Test in Task 4: `TestEditedContactMintsNewHandleOldRegistrationUntouched`.
+4. **One domain's addresses sit on several apps, some in Trash, plus platform names.** Expected: one card for the registrable domain, one row per address naming its app, Trash shown as a state chip, the app's own `*.<apps-domain>` names absent, and `shop.example.co.uk` grouped under itself, never under `example.co.uk`. Test in Task 5: `TestAccountDomainsGroupsByRegistrableDomain`.
+5. **Pointing a bought domain at an app while another app of the same account holds `www`** (or a member of another account holds it). Expected: the same account's claim moves to the new app (detach, then attach); another account's claim refuses with the neutral `domains.ErrHostUnavailable` refusal and nothing is detached. Test in Task 7: `TestPointMovesOwnAccountClaimRefusesForeign`.
+
+---
+
+### Task 1: UX pass in the mockup kit
+
+The approved mockups (`docs/superpowers/mockups/domains-account/`) predate the kit and use their own CSS; AGENTS.md ("Console mockups use the kit", "Every UI change gets a UX pass") requires the screens redrawn in the kit before copy review and build.
+
+**Files:**
+- Create: `docs/superpowers/mockups/domains-account-kit/overview.html`, `buy-name.html`, `buy-app.html`, `buy-pay.html`, `domain-bought.html`, `domain-elsewhere.html`, `contacts.html`, `purchase-card.html` (each from `docs/console-mockup-kit/shell.html`, components from `docs/console-styleguide.md`)
+
+- [ ] **Step 1:** Draw each screen in the kit, following the approved layouts (overview option A; three buy steps; domain page cards in §11.6 order; the contacts view placed on the Domains page, my call: a "Saved contacts" section below the cards, owners only). The purchase card keeps Plan 1's step list (0c2ab2e) and adds the "ready to point at an app" end state.
+- [ ] **Step 2:** UX pass: each screen at 390 px and desktop, light and dark; lead with state (chips for "Bought here", "Registered elsewhere", attach state, "In Trash"; expiry as a date tile). Run the `impeccable` critique and distill passes; fix what reads badly.
+- [ ] **Step 3:** Commit `mockups: domains at the account level, redrawn in the kit`, push, and post the mockup paths on the branch's amadan discussion for Paul to look at. Tasks 2-7 do not wait on his look; Tasks 8-9 do.
+
+### Task 2: Store: saved contacts, registrant snapshot, app-less purchases
+
+**Files:**
+- Modify: `internal/console/domainstore.go`, `internal/console/domainstore_test.go`
+- Modify: `internal/console/store_gate.go:231` (and the NonApp block at `:277-278`)
+- Modify: `docs/superpowers/specs/2026-11-01-domain-registration-design.md` (§11.7: add the storage implementation note from Global Constraints)
+
+**Interfaces:**
+- Produces:
+ ```go
+ type SavedContact struct {
+ ID string // "dc_" + 12 random hex
+ AccountID int64
+ Contact registrar.Contact
+ Handle string // registrar handle; "" until a purchase mints one, cleared by Edit
+ LastUsed, CreatedAt time.Time
+ }
+ func (s *Store) SavedContacts(accountID int64) ([]SavedContact, error) // LastUsed desc, then CreatedAt desc
+ func (s *Store) SavedContact(accountID int64, id string) (*SavedContact, error) // nil, nil when missing or another account's
+ func (s *Store) AddSavedContact(accountID int64, c registrar.Contact, now time.Time) (SavedContact, error) // c.Validate() first
+ func (s *Store) EditSavedContact(accountID int64, id string, c registrar.Contact) error // replaces Contact, sets Handle ""
+ func (s *Store) RemoveSavedContact(accountID int64, id string) error // list only; registrations keep their snapshot
+ func (s *Store) UseSavedContact(accountID int64, id, handle string, now time.Time) error // sets Handle when empty, LastUsed = now
+ func (s *Store) DomainRegistrations(accountID int64) ([]DomainRegistration, error) // by domain
+ func (s *Store) DomainRegistrationFor(accountID int64, domain string) (*DomainRegistration, error) // nil, nil when not this account's
+ func (s *Store) AccountDomainPurchases(accountID int64) ([]DomainPurchase, error) // non-terminal, newest first
+ func (s *Store) RegistrationCount(accountID int64) (int, error)
+ // DomainRegistration gains:
+ Registrant registrar.Contact // snapshot at registration; never changed by a contact edit
+ // purchaseDetails gains:
+ ContactID string
+ ```
+ Schema: `domain_saved_contacts(id TEXT PRIMARY KEY, account_id INTEGER NOT NULL, contact TEXT NOT NULL, handle TEXT NOT NULL DEFAULT '', last_used INTEGER NOT NULL DEFAULT 0, created_at INTEGER NOT NULL)` with an index on `account_id`; `ALTER TABLE domain_registrations ADD COLUMN registrant TEXT NOT NULL DEFAULT '{}'` (the existing duplicate-column tolerant loop). Gate: `domain_purchases` gains `FreeWhenNoApp: true`; `domain_saved_contacts` is NonApp ("saved registrant contacts and handles, keyed by account; names no app").
+ One-time backfills inside `migrateDomains`, idempotent: each `domain_contacts` row becomes a saved contact (same handle, `last_used = updated_at`) unless the account already has one with an equal contact; each registration with `registrant = '{}'` takes the `Contact` from the `details` of its account's purchase for that domain in state `done`, `captured` or `unpaid`. `domain_contacts` stays in place, no longer read or written after Task 4.
+
+- [ ] **Step 1: Write failing tests:** `TestSavedContactsOrderAndAccountScope` (two accounts; `SavedContact` with another account's ID returns nil; order by LastUsed then CreatedAt), `TestEditSavedContactClearsHandle`, `TestUseSavedContactKeepsExistingHandle` (a second `UseSavedContact` with a different handle leaves the first), `TestMigrateDomainsBackfillsContactsAndRegistrant` (seed a `domain_contacts` row, a done purchase with a contact and a registration with `'{}'`; migrate twice; one saved contact with the old handle; registrant equals the purchase contact), `TestAppLessPurchaseRowAllowedByGate` (with the gate armed in the test harness the other `FreeWhenNoApp` test uses, `cli_tokens`'s: find it with `git grep -n FreeWhenNoApp -- '*_test.go'`, an `app=''` purchase inserts).
+- [ ] **Step 2: Run** `go test ./internal/console/ -run 'SavedContact|MigrateDomains|AppLessPurchase'`; expect FAIL.
+- [ ] **Step 3: Implement**, and the spec note.
+- [ ] **Step 4: Run**; expect PASS. Also `go test ./internal/console/ -run 'StoreGate|ClaimSQL'` (the gate's own classification tests).
+- [ ] **Step 5: Commit** `console: saved domain contacts, registrant snapshot, app-less purchases`.
+
+### Task 3: Zone host: empty managed sets and extra names
+
+**Files:**
+- Modify: `internal/zonehost/zonehost.go`, `internal/zonehost/zonehost_test.go`, `internal/zonehost/zonehosttest/fake.go`
+- Modify: `internal/zonehost/route53zones/route53.go`, `internal/zonehost/route53zones/route53_test.go`
+
+**Interfaces:**
+- Produces: `ManagedSet` gains `Names []string` (full hostnames strictly under the zone, each written as an ALIAS A to the apex, `EvaluateTargetHealth: true`). `Validate()` now accepts an empty set (no apex, `WWW` false, no `Names`, no TXT): that is an unpointed zone; `WWW` or any `Names` without apex targets is refused. `SetManaged` refuses a name not under `z.Domain` and deletes any managed record not in `m`. Managed, for the Route 53 adapter: apex A sets, any A record that is an ALIAS to the zone apex, and the challenge TXT names (customer records in Plan 4 are never ALIAS records, so the rule keeps them separate).
+
+- [ ] **Step 1: Write failing tests:** `TestManagedSetValidateEmptyAndNames` (empty valid; `WWW` without apex refused; `Names` without apex refused), `TestFakeSetManagedEmptyClearsApex`, `TestSetManagedWritesNamesAsApexAlias` (`docs.shop.example` → ALIAS A to `shop.example.`), `TestSetManagedRefusesNameOutsideZone` (`docs.other.example`), `TestSetManagedEmptyDeletesApexWWWAndNames`.
+- [ ] **Step 2: Run** `go test ./internal/zonehost/... -run 'ManagedSet|SetManaged'`; expect FAIL.
+- [ ] **Step 3: Implement.**
+- [ ] **Step 4: Run**; expect PASS.
+- [ ] **Step 5: Commit** `zonehost: unpointed zones and extra names aliased to the apex`.
+
+### Task 4: Purchase engine: optional app, saved contacts, app gone (risky: per-task review)
+
+**Files:**
+- Modify: `internal/console/domainbuy.go`, `internal/console/domainbuy_test.go`, `internal/console/apidomainbuy.go`, `internal/console/appdomainbuy.go` (callers of `startDomainPurchase` only; their doors move in Task 9)
+
+**Interfaces:**
+- Consumes: Task 2 store methods; Task 3 `ManagedSet`.
+- Produces:
+ ```go
+ type purchaseContact struct {
+ ID string // a saved contact of the account
+ New *registrar.Contact // or a new one, saved by the purchase
+ } // exactly one set
+ func (s *Server) startDomainPurchase(ctx context.Context, acct *Account, app, name string, contact purchaseContact, principal string, confirmed domainreg.Quote) (*DomainPurchase, string, *domainreg.Quote, *doorRefusal)
+ // app "" is "Not yet" (§11.4). A non-empty app must be one of AppsIn(acct.ID), as today.
+ func (s *Server) purchaseManagedSet(ctx context.Context, p *DomainPurchase) (zonehost.ManagedSet, error)
+ // App "": the empty set. Otherwise today's apex/www/challenge set.
+ ```
+ Behaviour changes, each its own CAS transition as in Plan 1:
+ - Start: `contact.New` → `AddSavedContact`, its ID goes in `details.ContactID`. `contact.ID` not the account's → 422 `code:"contact"`. The paid-plan rule and daily cap apply whether or not an app is chosen (§11.4).
+ - Checkout step (`purchaseCheckoutStep`, replacing the `DomainContact`/`SetDomainContact` read and write): the saved contact has a handle → `OwnerHandle = handle`, no registrar call. No handle → `EnsureContact(ctx, "", c)`, then `UseSavedContact(id, handle, now)`. `UseSavedContact` also runs (LastUsed only) when the handle existed.
+ - `authorised` step: `SetManaged(zone, purchaseManagedSet(p))`.
+ - `registered` → `registeredPurchase` stores `Registrant` = the saved contact's `Contact` at that moment.
+ - `captured` step: `App == ""` → `done`, no attach. App not in `AppsIn(acct.ID)` (purged or in Trash, my call: Trash counts as gone here because attaching to a trashed app would serve nothing) → `SetManaged(zone, ManagedSet{})`, then `done` with `App = ""` and `Reason = "app_gone"`.
+ - `purchaseMutation`: `App == ""` runs `call` directly (no app mutation; the row is `FreeWhenNoApp`). With an app, unchanged. A purchase whose app is unset by the `captured` step does so inside that app's mutation, like every other step.
+
+- [ ] **Step 1: Write failing tests** on `newPurchaseFixture`: `TestPurchaseWithoutAppRegistersAndAttachesNothing` (reaches `done`; registration row with registrant; no claim for apex or `www`; zone's managed set empty), `TestPurchaseAppPurgedMidwayFinishesUnpointed` (remove the app from the store after `registered`; reaches `done`, `App` empty, `Reason` `app_gone`, managed set empty, payment captured once), `TestPurchaseSavedContactWithHandleSkipsRegistrar` (fake registrar `Calls` has no contact call), `TestEditedContactMintsNewHandleOldRegistrationUntouched` (buy with contact A, edit A, buy a second domain with A: the second purchase's `OwnerHandle` differs, the first registration's `Registrant` and the first purchase's `OwnerHandle` are unchanged, and the fake saw `EnsureContact` with an empty handle), `TestPurchaseOtherAccountsContactRefused`, `TestStartWithoutAppStillNeedsPaidPlanAndCap`. Existing Plan 1 engine tests must keep passing with `purchaseContact{New: &c}` in place of the old contact argument.
+- [ ] **Step 2: Run** `go test ./internal/console/ -run 'TestPurchase|TestStart|TestEditedContact'`; expect the new tests to FAIL.
+- [ ] **Step 3: Implement.**
+- [ ] **Step 4: Run** the same, plus `-run 'DomainBuy|APIDomain'`; expect PASS.
+- [ ] **Step 5: Commit** `console: purchases with no app, saved contacts, unpointed finish`.
+- [ ] **Step 6: Astra task review** (money flow and termination). Brief from `docs/superpowers/reviews/REVIEW-BRIEF-TEMPLATE.md`, naming the R12 invariant and the Plan 1 money rules.
+
+### Task 5: The account's domains, assembled
+
+**Files:**
+- Create: `internal/console/accountdomains.go`, `internal/console/accountdomains_test.go`
+
+**Interfaces:**
+- Consumes: Task 2 (`DomainRegistrations`, `AccountDomainPurchases`); `s.claims.ListWithUnread`; `s.store.AppsIncludingTrashIn` and `AppsIn` (`store.go:2053-2078`); `s.customDomain(host, sqid)` (`plancaps.go:253`); the attach state the app's Settings → Domains tab shows (`settingsDomains`, `appsettings.go:782`).
+- Produces:
+ ```go
+ type domainAddress struct {
+ Host, App string
+ AppInTrash bool
+ State string // the attach state (live, pending-dns, ...), as the app's Domains tab shows it
+ }
+ type domainCard struct {
+ Domain string // registrable domain (eTLD+1), A-label
+ Registration *DomainRegistration // nil: registered elsewhere
+ Purchase *DomainPurchase // a non-terminal purchase for this domain, if any
+ Addresses []domainAddress // sorted: apex, www, then by host
+ }
+ func (s *Server) accountDomains(ctx context.Context, acct *Account) ([]domainCard, error) // sorted by Domain
+ func (s *Server) accountDomain(ctx context.Context, acct *Account, domain string) (*domainCard, error) // nil, nil when the account has no such card
+ ```
+ Rules: addresses come from claims with `Account == acct.Sqid`, an app in `AppsIncludingTrashIn`, and `customDomain(strings.TrimPrefix(host, "*."), sqid)` true; the card key is `publicsuffix.EffectiveTLDPlusOne` of the host without `*.`. Registrations and live purchases add cards with no addresses when nothing is attached. Unread claims (the cache's `unread` set) make the call return an error rather than a short list. State is computed once per app that has addresses, never per address.
+
+- [ ] **Step 1: Write failing tests:** `TestAccountDomainsGroupsByRegistrableDomain` (Review Focus 4: claims for `shop.example`, `www.shop.example` on app `a`, `docs.shop.example` on app `b` in Trash, `kass.<apps-domain>` platform name, `shop.example.co.uk`, another account's `other.example`; exactly two cards, rows and chips as stated), `TestAccountDomainsBoughtWithoutAddresses` (a registration with no claims is a card with `Registration` set and no addresses), `TestAccountDomainsShowsLivePurchase`, `TestAccountDomainsUnreadClaimsIsError`, `TestAccountDomainOtherAccountIsNil`.
+- [ ] **Step 2: Run** `go test ./internal/console/ -run AccountDomain`; expect FAIL.
+- [ ] **Step 3: Implement.**
+- [ ] **Step 4: Run**; expect PASS.
+- [ ] **Step 5: Commit** `console: an account's domains, bought and registered elsewhere`.
+
+### Task 6: Purge releases domain claims; account deletion refused while holding registrations (risky: per-task review)
+
+Today the claims-off purge (`purgeAppWithLifetimes`, `lifetimes_purge.go:40`) leaves the app's custom-domain claims in the bucket, so the hosts stay held by an app that no longer exists and no other app of the account can attach them. Spec C2 needs them released at purge.
+
+**Files:**
+- Modify: `internal/console/lifetimes_purge.go`, its test file (`git grep -ln purgeAppWithLifetimes -- '*_test.go'`)
+- Modify: `internal/console/ownership.go:161` (`deletionRefused`) and `:790` (`Store.DeleteAccount`), plus any other account-deletion door (`git grep -n 'DeleteAccount(' -- '*.go'`), and `internal/console/ownership_test.go`
+
+**Interfaces:**
+- Consumes: `s.detachDomainClaim(ctx, host, account, app)` (`claim_alias.go:201`), `RegistrationCount` and `AccountDomainPurchases` (Task 2).
+- Produces: purge detaches every claim whose `Account` and `App` match the purged app (custom domains only; platform names follow their existing path), after the app's rows are gone and before the purge reports done; a detach error leaves the purge retryable, as its other steps do. Account deletion refuses, before anything is deleted, when `RegistrationCount > 0` or a non-terminal purchase exists, naming the domains in the flash (copy draft in `domainbuy_copy.go`), and `Store.DeleteAccount` re-checks inside its transaction.
+
+- [ ] **Step 1: Write failing tests:** `TestPurgeReleasesTheAppsDomainClaims` (claims for `shop.example` and `www.shop.example` on the purged app, `blog.example` on a live app of the same account: the first two gone, the third untouched), `TestPurgeDomainDetachIsRetryable` (fake store fails the first delete; a second purge pass finishes), `TestAccountDeletionRefusedWhileHoldingRegistrations` (flash names the domain; account row still present), `TestAccountDeletionRefusedWithLivePurchase`, `TestStoreDeleteAccountRechecksRegistrations`.
+- [ ] **Step 2: Run** `go test ./internal/console/ -run 'PurgeReleases|PurgeDomainDetach|AccountDeletionRefused|StoreDeleteAccount'`; expect FAIL.
+- [ ] **Step 3: Implement.**
+- [ ] **Step 4: Run**; expect PASS. Also `-run 'Purge|Trash|DeleteAccount'` for the existing purge and deletion tests.
+- [ ] **Step 5: Commit** `console: purge releases domain claims; accounts holding domains cannot be deleted`.
+- [ ] **Step 6: Astra and Fable task review** (termination: purge and account deletion).
+
+### Task 7: Point a bought domain at an app; add an address (risky: per-task review)
+
+**Files:**
+- Create: `internal/console/domainpoint.go`, `internal/console/domainpoint_test.go`
+
+**Interfaces:**
+- Consumes: Task 3 (`ManagedSet.Names`), Task 5 (`accountDomain`), `attachDomain` (`domainattach.go:112`), `detachDomain` (`domainattach.go:390`), `s.cfg.DomainApex` / static fallback as Plan 1's `authorised` step uses, `domainChallenge`.
+- Produces:
+ ```go
+ func (s *Server) pointBoughtDomain(ctx context.Context, acct *Account, domain, app, principal string) *doorRefusal
+ func (s *Server) addBoughtAddress(ctx context.Context, acct *Account, domain, host, app, principal string) *doorRefusal
+ ```
+ `pointBoughtDomain`: the domain must be one of the account's registrations (otherwise the neutral not-found refusal) and `app` one of `AppsIn`. For the apex and `www`: if a claim exists for the same account on another app, `detachDomain` it from that app first; another account's claim refuses with `domains.ErrHostUnavailable`'s neutral refusal before anything changes. Then `SetManaged` with the apex set, `WWW: true`, existing `Names`, and challenge TXT when `DomainProof`; then `attachDomain` for both. `addBoughtAddress`: `host` must be strictly under `domain` and not the apex or `www`; adds `host` to the zone's `Names`, then attaches it to `app`. Both run under the account's domain mutex (a `sync.Mutex` per account ID held in the Server, my call: two pointing calls for one domain must not interleave their SetManaged writes).
+
+- [ ] **Step 1: Write failing tests:** `TestPointUnpointedDomainWritesApexAndAttaches`, `TestPointMovesOwnAccountClaimRefusesForeign` (Review Focus 5), `TestPointAfterPurgeSucceeds` (with Task 6's purge), `TestPointNotOwnedDomainIsNeutralNotFound`, `TestAddAddressAliasesNameAndAttaches`, `TestAddAddressRefusesApexWWWAndOutsideDomain`.
+- [ ] **Step 2: Run** `go test ./internal/console/ -run 'TestPoint|TestAddAddress'`; expect FAIL.
+- [ ] **Step 3: Implement.**
+- [ ] **Step 4: Run**; expect PASS.
+- [ ] **Step 5: Commit** `console: point a bought domain at an app; add an address under it`.
+- [ ] **Step 6: Astra task review** (claim ownership across apps and accounts).
+
+### Task 8: Domains nav item, overview page and a domain's page
+
+Waits on Paul's look at Task 1 (or his "go on" on the discussion).
+
+**Files:**
+- Create: `internal/console/accountdomainspage.go`, `internal/console/accountdomainspage_test.go`, `internal/console/templates/account_domains.html`, `internal/console/templates/account_domain.html`, `internal/console/accountdomains_copy.go`
+- Modify: `internal/console/mobilenav.go:37-54` (insert `{Key: "domains", Label: "Domains", Href: "/a/<sqid>/domains"}` between Apps and Fleet), `internal/console/templates/navindex.html` (`index_icon` branch for `domains`), `internal/console/routedecls.go`
+- Modify: `internal/console/templates/app_settings.html:80-120` (link "All domains" to the account page; "Buy a domain" to `/a/{sqid}/domains/buy?app=<app>`)
+
+**Interfaces:**
+- Consumes: Task 5; `domainGuidance(host, s.dnsTargets(ctx))` (`view.go:182`) for registered-elsewhere records; the catalog's renew price for the account's currency (`DomainCatalog.TLDs[tld].Renew[currency]`).
+- Produces routes (members; `p.ActiveNav = "domains"`):
+ - `GET /a/{sqid}/domains` → overview: one card per `domainCard`; header chip "Bought here" or "Registered elsewhere", an in-flight purchase links to its card; bought cards show the expiry date and next year's price; page actions "Buy a domain" (owners, when `domainBuyReady`) and "Add a domain you own" (asks for the app and host, posts to the existing app attach door). Owners also see the Saved contacts section (Task 9 builds its forms; this task renders the list).
+ - `GET /a/{sqid}/domains/{domain}` → the domain's page in §11.6 order: Addresses (each with app and state, "Add address" for owners on bought domains); for bought domains Renewal (expiry, price, the card on file and "Change card" to the billing page, no switch) and Registered to (the registrant snapshot, no Change owner); DNS records shows the managed-records line only (customer records are Plan 4); no Transfer out card yet. Registered elsewhere: Addresses plus the records to set at the other registrar. An unknown or other account's domain → 404.
+ - Accounts whose list is empty show an empty state with the two actions.
+
+- [ ] **Step 1: Write failing tests:** `TestDomainsNavBetweenAppsAndFleet`, `TestDomainsOverviewCards` (one bought card with expiry and price, one elsewhere card with two app rows and a Trash chip), `TestDomainsOverviewMemberSeesNoBuyOrContacts`, `TestDomainPageBoughtCardsInOrder`, `TestDomainPageElsewhereShowsRecordsToSet`, `TestDomainPageOtherAccount404`, `TestAppSettingsLinksToAccountDomains`.
+- [ ] **Step 2: Run** `go test ./internal/console/ -run 'DomainsNav|DomainsOverview|DomainPage|AppSettingsLinks'`; expect FAIL.
+- [ ] **Step 3: Implement** against the Task 1 kit mockups; strings from `accountdomains_copy.go` (drafts).
+- [ ] **Step 4: Run**; expect PASS. Also `go test ./internal/console/ -run 'Styleguide|Nav'`.
+- [ ] **Step 5: Commit** `console: Domains page and a domain's own page`.
+
+### Task 9: Three-step buy, saved contacts and pointing in the browser (risky: per-task review)
+
+**Files:**
+- Create: `internal/console/accountdomainbuy.go`, `internal/console/accountdomainbuy_test.go`, `internal/console/templates/account_domain_buy.html`
+- Modify: `internal/console/appdomainbuy.go` (old app-scoped GET routes redirect), `internal/console/routedecls.go`, `internal/console/accountdomains_copy.go`
+- Modify the route registers: `internal/console/linkedpolicy.go:73-80`, `claim_invariant_fixtures_test.go:2522-2528`, `claim_invariant_probes_read_test.go:256-258`, `svcroutes_test.go:238`, `apilinks_test.go:489`, `docs/parity.md:108`
+
+**Interfaces:**
+- Consumes: Tasks 2, 4, 7; `domainBuyBrowserGate`'s checks (owner, CSRF on POST, `domainBuyReady`, `allowDomains`), generalised to the account (no app in the path).
+- Produces routes (owners, CSRF on every POST):
+ - `GET /a/{sqid}/domains/buy?step=name|app|pay&name=&app=` and `POST /a/{sqid}/domains/buy/check` (step 1 → quote → step 2), `POST /a/{sqid}/domains/buy` (step 3 → `startDomainPurchase` → Checkout). Step state travels in the query and hidden fields; the quote is re-checked at pay (Plan 1's `price_changed` path). `app=` preselects (from app Settings) and stays changeable; "Not yet" is `app=` empty with `notyet=1` so an empty value is never a silent default.
+ - `GET /a/{sqid}/domains/purchases/{id}` and `.../status` (the Plan 1 card and JSON, account-scoped; another account's ID → 404 identical to unknown). Old `GET /a/{sqid}/apps/{app}/domains/purchases/{id}[/status]` and `GET .../apps/{app}/domains/buy` → 303 to the new paths (status keeps working for open pages: 303 is followed by `fetch`).
+ - `POST /a/{sqid}/domains/contacts` (add), `POST /a/{sqid}/domains/contacts/{id}` (edit), `POST /a/{sqid}/domains/contacts/{id}/remove`.
+ - `POST /a/{sqid}/domains/{domain}/point` (`app`), `POST /a/{sqid}/domains/{domain}/addresses` (`host`, `app`).
+ - Step 3's "Registered to" is a searchable list of saved contacts with the most recently used preselected, ending with "Add a new contact" (fields in place, saved by the purchase).
+
+- [ ] **Step 1: Write failing tests:** `TestAccountBuyThreeStepsToCheckout` (name → app → pay; Checkout created with the chosen app), `TestAccountBuyNotYetNeedsExplicitChoice` (empty `app` without `notyet=1` re-shows step 2), `TestAccountBuyMemberAndServiceTokenRefused`, `TestAccountBuyCSRFRequired`, `TestOldPurchaseURLsRedirect`, `TestPurchaseCardOtherAccount404`, `TestContactsEditRemoveOwnerOnly`, `TestPointDoorOwnerOnlyAndCSRF`.
+- [ ] **Step 2: Run** `go test ./internal/console/ -run 'AccountBuy|OldPurchaseURLs|PurchaseCard|ContactsEdit|PointDoor'`; expect FAIL.
+- [ ] **Step 3: Implement**; strings in `accountdomains_copy.go` (drafts).
+- [ ] **Step 4: Run**; expect PASS. Also the register tests: `go test ./internal/console/ -run 'SvcRoutes|APILinks|ClaimInvariant|LinkedPolicy'`.
+- [ ] **Step 5: Commit** `console: three-step buy, saved contacts and pointing at the account`.
+- [ ] **Step 6: Astra task review** (security gates: owner checks, CSRF, neutral 404s, redirects).
+
+### Task 10: CLI and its API doors
+
+**Files:**
+- Modify: `internal/console/apidomainbuy.go`, `internal/console/apidomainbuy_test.go`, `internal/console/routedecls.go` (+ the registers from Task 9)
+- Modify: `domains_cli.go` (usage, `list` without `--app`), `domains_buy_cli.go`, `domains_buy_cli_test.go`, `domains_buy_copy.go`, `apimode.go` (beside `postDomainPurchase` at `:5011`)
+- Create: `domains_account_cli.go`, `domains_account_cli_test.go`
+
+**Interfaces:**
+- Consumes: Tasks 2, 4, 5, 7.
+- Produces API (persons only, `domainBuyAPIGate`'s checks; list is members, the rest owners):
+ - `GET /api/cli/accounts/{account}/domains` → `{"domains":[{"domain","bought":bool,"expires"?,"purchase"?:{"id","state"},"addresses":[{"host","app","in_trash","state"}]}]}`.
+ - `POST /api/cli/accounts/{account}/domains/purchases` body gains `"contact_id"`; `"app"` may be `""` only with `"not_yet": true`, else 422 `code:"app"`.
+ - `POST /api/cli/accounts/{account}/domains/{domain}/point` `{"app"}`; `POST .../domains/{domain}/addresses` `{"host","app"}`.
+ - `GET|POST /api/cli/accounts/{account}/domains/contacts`, `PUT|DELETE .../contacts/{id}`.
+- Produces CLI:
+ - `carlos domains buy <name> (--app <a> | --not-yet) [--contact <id> | --contact-file f]`: neither `--app` nor `--not-yet` is a usage error (my call: an unpointed domain is never a silent default). With neither contact flag, the most recently used saved contact is used and named in the confirm line; none saved falls back to Plan 1's prompt.
+ - `carlos domains list` without `--app`: the account overview, one block per domain, its addresses indented. With `--app`: unchanged.
+ - `carlos domains point <domain> --app <a>`; `carlos domains point <domain> --host docs.<domain> --app <a>` adds an address.
+ - `carlos domains contacts [list | add --file f | edit <id> --file f | remove <id>]`.
+
+- [ ] **Step 1: Write failing tests:** API: `TestAPIDomainsListGroups`, `TestAPIPurchaseNotYetExplicit`, `TestAPIContactsOwnerOnly`, `TestAPIPointOtherAccount404`. CLI (httptest + `newTestSession`): `TestDomainsBuyNeedsAppOrNotYet`, `TestDomainsBuyUsesLastContactAndNamesIt`, `TestDomainsListAccountOverview`, `TestDomainsPointPrintsState`, `TestDomainsContactsRoundTrip`.
+- [ ] **Step 2: Run** `go test ./internal/console/ -run 'TestAPIDomains|TestAPIPurchase|TestAPIContacts|TestAPIPoint'` and `go test . -run 'TestDomainsBuy|TestDomainsList|TestDomainsPoint|TestDomainsContacts'`; expect FAIL.
+- [ ] **Step 3: Implement**; strings in `domains_buy_copy.go` (drafts).
+- [ ] **Step 4: Run**; expect PASS. `GOOS=darwin go build ./...` and `GOOS=windows go build ./...` (the CI cross-compile gate).
+- [ ] **Step 5: Commit** `cli: account-wide domains list, buy without an app, point, contacts`.
+
+### Task 11: Copy pass
+
+**Files:**
+- Create: `docs/superpowers/specs/LUNA-COPY-BRIEF-DOMAINS-2A.md`, then `LUNA-COPY-RESULT-DOMAINS-2A.md`
+- Modify: `internal/console/accountdomains_copy.go`, `internal/console/domainbuy_copy.go`, `domains_buy_copy.go`, `approved_domains_buy_copy_test.go`
+
+- [ ] **Step 1:** Write the brief: every new or changed key with where it appears (screen and kit mockup path), and the facts that must stay true: the customer is the registrant; editing a contact changes future purchases only; nothing renews yet (no "renews" wording); "Not yet" means paid and registered but not serving; no registrar or DNS host names.
+- [ ] **Step 2:** Run the Luna pass (delegated copy review, as Plan 1's Task 11); apply the result table verbatim.
+- [ ] **Step 3:** Pin approved strings; run `go test . ./internal/console/ -run Approved`; expect PASS.
+- [ ] **Step 4: Commit** `domains: approved copy (Luna pass DOMAINS-2A)`.
+
+### Task 12: Merge, roll and witness
+
+- [ ] **Step 1:** Whole-branch review: Astra and Fable on one brief (REVIEW-BRIEF-TEMPLATE, round history carried); `make code-health`; CI green on amadan.
+- [ ] **Step 2:** Merge (squash, subject under 80 characters), release and roll dev first per the release recipe; flagship with the next release, after its GO.
+- [ ] **Step 3: Witness on dev**, recorded on the discussion with timestamps: the Domains page for an account with a registered-elsewhere domain on two apps; a "Not yet" purchase (Stripe test card) reaching `done` with an empty zone; `carlos domains point` to `wakecheck` and the apex reaching `live`; a saved-contact edit followed by a second purchase showing a new handle and the first registrant unchanged.
+- [ ] **Step 4: Witness on flagship** after its roll: the Domains page for Paul's account and one existing bought domain's page (registrant shown, expiry and price, no switch).
diff --git a/docs/superpowers/reviews/CODEX-REVIEW-BRIEF-domains-plan-2a.md b/docs/superpowers/reviews/CODEX-REVIEW-BRIEF-domains-plan-2a.md
new file mode 100644
index 000000000..da92db19a
--- /dev/null
+++ b/docs/superpowers/reviews/CODEX-REVIEW-BRIEF-domains-plan-2a.md
@@ -0,0 +1,78 @@
+# Review brief: domain registration Plan 2a (domains at the account level), round 1 of 3
+
+Repo carlos/platform, branch `plan-domains-2b`, commit named in the reviewer's prompt.
+Under review: `docs/superpowers/plans/2026-11-19-domain-registration-2a-account-domains.md`.
+Authorities: `docs/superpowers/specs/2026-11-01-domain-registration-design.md`
+(revision 4, approved, merged 0b3098c; §11 is what this plan builds), Plan 1
+`docs/superpowers/plans/2026-11-01-domain-registration-1-buy.md` (merged
+20c867c), `AGENTS.md`. Do not review against unmerged branches; if this work
+needs one, say so as a P1 and stop.
+
+You are an independent reviewer. Read the plan, then the code it names, and
+check every claim against that code. You are reading it as the builder: an
+engineer who has not seen this codebase will implement each task from its
+text alone.
+
+## Fixed: do not re-argue
+
+- Paul's rulings R1-R12 in the spec (§3, §11.2) and the builder-check calls
+ B1-B4, C1-C3 (§10, §11.10). Report only mechanisms that fail to honour them.
+- The split of Plan 2 into 2a (this) and 2b (reconcile, apex reconverge,
+ alerts), and transfers in coming after Plan 3.
+- The host lifecycle claim work is shelved (`CARLOS_HOST_CLAIM` inert in
+ production); the SQL gate and `claimAppMutation` paths must still compile
+ and stay correct, but are not the production path.
+
+## What to check
+
+1. The plan's storage finding: purchases, registrations and contacts are
+ already in console.db, and only the gate (`store_gate.go:231`), the
+ per-app mutation (`domainbuy.go:414`) and the doors are app-bound. Is
+ anything else app-bound that the plan misses?
+2. R12: editing a saved contact must never change a registration. Check the
+ plan's rule against `internal/registrar/openprovider/client.go:136-155`
+ and every path that calls `EnsureContact` or reads `domain_contacts`.
+3. Task 4: optional app and "app gone" handling in the purchase state
+ machine. Can any path now take money without a registration, register
+ without an authorised payment, or attach to an app the account no longer
+ has? Is `purchaseMutation` with an empty app safe?
+4. Task 6: releasing a purged app's claims (`lifetimes_purge.go`), and the
+ account-deletion refusal. Is the purge change correct and retryable, does
+ it touch claims it should not (platform names, aliases, catch-alls,
+ another app's), and is every account-deletion door covered?
+5. Task 7: moving a claim between apps of one account; never touching
+ another account's claim; ordering of SetManaged and attach; the
+ per-account mutex.
+6. Task 9 and 10: owner and CSRF gates, neutral 404s, the old-URL
+ redirects, and the route registers (would a census test fail?).
+7. Task right-sizing, interface consistency between tasks, and whether each
+ step lets the builder write exactly one reasonable thing.
+
+## Severity
+
+- **P1**: unsafe, would not compile, a test fails, or it would not work.
+ Blocks merge.
+- **P2**: wrong or missing. Fixed without reopening this review. (The
+ census, and review of any newly changed security, root, termination
+ or production-storage behaviour, still check the fix; see AGENTS.md,
+ "Stopping rules".)
+- **P3**: clarity or polish. Goes on a follow-up list; never a reason for
+ another round.
+
+A P1 states its failure scenario and the evidence (file:line). Do not
+raise a P2 to P1 to keep the review open.
+
+## Output
+
+Findings ranked P1, P2, P3. Each gives the section or task, the problem,
+the evidence (file:line, verified), the failure scenario, a concrete
+fix and the invariant or trust boundary it breaks (that is its fault
+family). End with exactly one verdict:
+
+- **READY**: no P1 and no P2.
+- **READY AFTER FIXES**: no P1. The listed P2s are fixed without another
+ round.
+- **NOT READY**: one or more P1s, listed.
+
+Do not edit files. Do not spawn Anthropic-model reviewers or subagents of
+your own. Do not run the full test suites.