carlos / platform Public

spec: platform accounts that create and run customer accounts

Approved by Paul 2026-11-19. Platform accounts (operator-granted) create
ownerless customer accounts, mint short-lived per-customer credentials,
hand out claim links, and keep managing after a claim until the customer
leaves.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev 06603e71cb473cb9e671ebb02784fbc0498a7ceb parent ed6ae02
1 file changed, +417 −0
  • docs/superpowers/specs/2026-11-19-platform-accounts-design.md +417 −0

Intent

Human

<task-notification> <task-id>ae030a425373d7a37</task-id> <tool-use-id>toolu_01Rc6h5Amr4vpqWNdaCg5nNU</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/9284fe97-c7c7-4e03-80f2-87c51eb0406d/tasks/ae030a425373d7a37.output</output-file> <status>completed</status> <summary>Agent "Map accounts, creds, billing" finished</summary> <note>A task-notification fires each time this agent stops with no live background children of its own. The user can send it another message and resume it, so the same task-id may notify more than once.</note> <result>I've mapped all seven areas. The short answer: there are no managed accounts today. Every place an account is created, every invite, the billing setup and every credential assumes one human owner per account. No credential except a person's own login token can act in more than one account. Note: the sandbox kept failing because git worktrees were being created and removed while I searched, so I ran the remaining read-only `grep`/`sed` commands outside it. ## 1. Accounts **Schema.** The `accounts` table has `id` (an integer it is given, never autoincrement), `sqid` (unique), `name` (not unique) and `created_at` (`internal/console/store.go:216`). Later additions are `deleted_at` (`store.go:566`) and `tier` (`store.go:582`). There is no column for kind, platform, parent or payer. **How an id is made.** `domains.MintAccount` (`internal/domains/mint.go:219`) takes the highest id in any bucket manifest plus one, then claims it with a create-only write of `accounts/&lt;sqid&gt;/account.json` (`mint.go:92`). The manifest holds `{id, sqid, name, created_at, owner?, deleted_at?}` (`mint.go:26`). The sqid is `id + 23²` written in base 23 over the frozen alphabet `abcdefghjkmnpqrstuvwxyz` (`internal/domains/sqid.go:15,32`). Id 1 is the ops account (`mint.go:97`). **Every path that creates an account:** - **Signing in with no account:** `currentAccount` mints a personal account named after the person's address (`server.go:3169`). - **Browser "New account":** `POST /accounts/new` → `handleNewAccount` (`server.go:3392`). Session only, with the free-account cap. - **CLI while logged in:** `POST /auth/cli/accounts` → `handleCLINewAccount` (`authcli.go:2061`). It authenticates through `cliUser`, which only accepts a person, so a service credential gets a 401. - **Demo claim:** `demo_claim_target.go:78`. - All three console paths go through `mintAccount` (`server.go:3223`) → `Store.CreateAccount` (`store.go:1177`). That writes the account row, the owner membership and the sponsorship row in one transaction. `ownerAddress` is used only for that first owner membership, the last-account record and the audit line. - **CLI with `--owner` and no console** (`accounts.go:158`): writes the manifest straight to the bucket with `owner`, then a registry row. MintAccount accepts an empty owner and treats it as "ownerless" (`mint.go:212-223`), but the CLI refuses to run without an owner (`accounts.go:128`). - **Copying from the bucket:** `MaterializeAccounts` (`materialize.go:41`) runs on console start (`server.go:2254`) and on every `console member` command (`cmd/console/member.go:106`). It calls `EnsureAccount` (`store.go:1222`), which deliberately creates no membership. The manifest's owner is applied only the first time an account is seen (`materialize.go:175,186`; `AdoptManifestOwner` `store.go:1279`). **Can an account have zero owners?** Yes, in the data. `EnsureAccount` creates one on purpose, and an older manifest with no owner stays ownerless (`store.go:1202-1207`). But the code treats this as broken, not as a state to keep: - The comments call it "unadministrable" (`store.go:1174`). - With no membership there is no access at all; the `/a/{sqid}` gate resolves only through the viewer's memberships (`server.go:3290`). - `lastOwnerGuard` (`store.go:1582`) stops an account that has owners from ever dropping to zero. **Deletion.** Owners delete from the browser: `POST /a/{sqid}/delete` → `Store.DeleteAccount` (`ownership.go:819`). It refuses while the account still has apps or if it is the ops account. The row is marked deleted, never removed. `domains.TombstoneAccount` (`mint.go:268`) rewrites the manifest and clears `owner`. `ReapAccount` (`store.go:1801`) handles a manifest found already tombstoned. ## 2. Memberships and roles - **Table:** `memberships(account_id, address, role, added_at)`, primary key `(account_id, address)` (`store.go:224`). There are exactly two roles, `owner` and `member`. Every member is a Keymail address; no principal type other than an address can be a member. - **Invites:** `invites(token, account_id, address, invited_by, created_at, expires_at, accepted_at, seat_*)` (`store.go:237,637-643`). They last 7 days (`store.go:1142`) and at most 20 can be pending (`server.go:3611`). Only an owner signed in through the browser can invite (`handleInvite`, `server.go:3440`). There is no CLI or API door for invites. - **An invite cannot make someone an owner.** `acceptInviteTx` always inserts `RoleMember`, with the comment "owners are promoted deliberately" (`store.go:1733`). Accepting also requires a signed-in person who holds the invited address (`store.go:1720`). - **Becoming an owner** happens only two ways: - `TransferOwnership` (`ownership.go:766`): the current owner, signed in with a fresh sign-in check, picks someone who is already a member. The current owner is demoted in the same transaction. - `console member -add &lt;addr&gt; &lt;sqid&gt; -role owner`, run on the box (`cmd/console/member.go:19,190`). **Conflict:** a customer cannot simply be "invited as owner". With no owner present, nobody exists to send the invite or to transfer ownership. The one route that works today is the box-side `console member` command. ## 3. Service credentials **Table.** `cli_tokens` (`authstore.go:232`), with added columns `kind`, `account_id`, `app`, `role`, `name`, `revoked_at`, `rotated_at`, `rungs`, `credential_id`, `commands` and `scope` (`authstore.go:259-277`). Kinds (`authstore.go:372-374`): - `""`: a person's token, which expires after 90 days (`authstore.go:55`). - `"app"`: the older app token, read as role `instance`. - `"service"`: a service principal. **Roles** (`internal/svcrole/svcrole.go`): `publish`, `deploy`, `instance`, `operate`, `service`, `run`, `team`, `admin`. `Allow()` always adds `admin`; `run` is reachable only through `Exactly`, and `team` only through `Scoped`. - **Publish:** claim an app, ship, promote, roll back, hostnames, retire. - **Deploy (#229):** must name one app and its rungs, and can never be given `stable` (`apiservices.go:274-285`). It cannot reach app lifecycle, retention or domains. **Scope is one account, and optionally one app.** A `Principal` carries a single `AccountID` (`svcprincipal.go:52`). `serviceBinding` (`apicli.go:139`) and `apiPrincipalAccountSaying` (`apicli.go:245-252`) require the URL's account to equal the credential's bound sqid exactly. An app-scoped credential is refused anywhere except its own app (`apicli.go:74`), and creating an app (`apicli.go:396`). **Gates:** - `apiAccountApp` / `apiAccountAppBy` (`apicli.go:46,64`). - `instanceGate` (`apiinstances.go:102`) adds a per-token budget on top of `apiAccountApp`. - `cliRoute` (`authcli.go:448`) checks the role before the handler runs. An empty role set means no service credential gets in. **No credential spans several accounts** except a person's token, whose reach is the person's memberships, worked out on each request. The code states this on purpose: "the memberships of the human who minted it are irrelevant" (`apicli.go:183`). **Person-only doors** (empty role set, so closed to every service credential): - minting credentials: `POST /api/cli/services/{account}`, owner-gated through `apiOwnerAccount` (`authcli.go:1029`, `apiservices.go:167`); - enabling instances: `instances-manifest` (`authcli.go:716`); - domain check and purchase (`authcli.go:932-934`); - account plan, billing and store doors (`authcli.go:1081-1089`). **Login.** `carlos auth login` is a device flow: `/auth/cli/start`, then `/approve` by a signed-in person, then `/poll` (`authcli.go:545-551`). The result is a person token, never a service one. The person who minted a service credential is stored in `address` as the answerable human. **Conflicts:** - Only a person who owns the account can mint a credential, and a credential can never mint one. - No credential can create an account. - An account-scoped credential cannot reach a second account. ## 4. Operator doors There are three separate ideas of "operator": 1. **The `users.operator` bit** (`store.go:519`, `IsOperator` `store.go:2664`), set on the box with `console grant -operator &lt;addr&gt;` (`cmd/console/main.go:199`). It gates: - `accounts plan` (`apiaccountplan.go:45`), including `--sponsored`; - the billing problems and billing house doors (`apibilling.go:33`, `apibillinghouse.go`); - store entitlement (`apistore_entitlement.go:97`); - instance moves (`apiinstancemove.go:552`); - email pause (`apimail.go:1544`); - host claim (`apihostclaim.go:27`); - the economics pages (`economicspass.go:1300+`); - the browser operator pages through `operatorOnly` (`server.go:4123`). 2. **Owner of the ops account (id 1)** through `opsOwner` (`svcprincipal.go:613`). This lifts the free-account allowance and the daily app-create budget. 3. **`CARLOS_SYSTEM_OPERATORS`** (`cmd/console/main.go:1139`). Together with ops owners this forms `apiSystemRoller` (`apisystemupdate.go:146`) and `platformOperator`, the platform-domain door (`domainpolicy.go:119-139`). All three apply to people only. A service principal can never be an operator (`domainpolicy.go:137`). ## 5. Billing - **One Stripe customer and subscription per account.** `billing_accounts` (`billingstore.go:90`) is keyed by `account_id`, with unique `customer` and `subscription`. - **The Stripe customer's email is the account's first owner.** If there is none, it fails with `"billing: account has no owner"` (`billingcustomer.go:48-56`). **Conflict.** - **Only a signed-in owner can buy:** `billingOwner` (`billinghold.go:94`), which also refuses the ops account. - **What is billed** is a yearly plan subscription, plus packs and team seats (`billingchange.go:21`, `billingseats.go:18`). Usage is not billed as metered charges. It is measured only against caps: - `measureCaps` (`planmeasure.go:28`) reads usage statements per account by sqid; - the results are stored in `plan_cap_state`; - the billing page shows them (`billingusage.go`). - **`account_plans`** (`store.go:444,526-531`): `account_id`, `plan`, `packs`, `source`, `sponsored`, `reason`, `revision`, `published_revision`, `published_catalog`, `updated_by`, `updated_at`, `throttle`, `lapse_since`, `disabled`. - **Plan catalog** (`internal/plans/catalog.go:70-103`): a set of plans (each with paid, limits, packs, optional team, max members), a set of packs, ceilings, `DefaultPlan`, `FreeAccountsPerPerson` and `SponsorAccountsBefore`. Limits include running things, storage, email per day, bandwidth, PDF renders, custom domains, fleets and similar. - **Sponsorship** (`plansponsor.go`) is applied when an account is inserted, through `sponsorOnInsertTx`. Operators can also set `--sponsored` limits. - **Plan exemption:** `planExempt` (`planexempt.go:35`) covers only the ops account: no limits, no billing. - **House accounts:** an operator can set a "house" flag that applies a coupon at checkout (`apibillinghouse.go:10`). There is no way for one account to pay for another. Nothing like a payer or parent relationship exists. ## 6. Static sites **From the CLI.** `carlos deploy --kind static` (`deploy.go:139`): - `ensureDeployApp` (`deploy_first.go`) creates the app through `POST /api/cli/apps/{account}/new`, which needs Publish (`authcli.go:593`). An app-bound credential is refused there. - The release is shipped through `POST .../releases` (Publish or Deploy), then promoted. - With no host yet, `mintPlatformHost` (`deploy.go:1081`) calls `instances-manifest`, which is person-only, so this step fails for any CI credential. **The path a CI credential can use** is `POST .../domains` with `kind:"static"`. That writes the first route, and needs Publish or Instance (`authcli.go:931`, `apidomains.go:293`). There is also `new-temporary` (Publish). **So a CI credential needs:** account-scoped Publish to create apps, or Deploy (bound to one app) for later ships. **Custom domains.** `domainsGate` (`apidomains.go:257`) accepts any member or a bound Publish/Instance credential. On top of that sit the plan's `CustomDomains` cap (`plancaps.go:224`) and the control-plane refusal for services. Platform-zone hostnames need a person operator. Buying a domain is person-only. ## 7. Limits on creating accounts - **Free accounts per person:** `checkNewFreeAccount` (`plancaps.go:175`) counts free accounts the person owns. Ops owners are exempt, and the cap does nothing when the default plan is paid. - **Rate limits:** - CLI create: the `cli.write` budget, 30 per minute per person (`authcli.go:66`). - Browser create: none. - App creation: 10 per day per person (`authcli.go:122`) and 100 per day per service credential (`authcli.go:147`). - Credential minting: 120 per minute for service credentials (`authcli.go:152`). ## Conflicts to resolve 1. Every console path that creates an account requires a person owner (`CreateAccount` `store.go:1177`). The account-creation doors refuse service credentials (`cliUser`). 2. Ownerless accounts are treated as broken, and invites only grant member. Bringing in the customer as owner needs a new step that promotes them from an ownerless state. 3. Stripe customer setup fails with no owner (`billingcustomer.go:55`), and checkout is a door for a signed-in owner. 4. A `Principal` holds one `AccountID`. Acting across accounts would mean a new kind of principal, or minting a credential in each child account. Today a credential can't mint a credential, and minting needs a person who owns that child account. 5. There is no "payer" or "parent" link anywhere. Usage, caps and subscriptions are all per account. 6. The free-account cap counts per owner address. A platform account creating many accounts would trip it unless exempted, as ops owners are. 7. Static hosting on a fresh app needs `instances-manifest`, which is person-only. CI has to use `domains` with `kind:"static"`. 8. The name "managed" is already used for managed fleets: `managed_ops`, `managed_boxes` and related tables (`managedstore.go:84-88`).</result> <usage><subagent_tokens>196291</subagent_tokens><tool_uses>68</tool_uses><duration_ms>332429</duration_ms></usage> </task-notification>

Human

No, customers will sign up one by one.

Human

proceed

diff --git a/docs/superpowers/specs/2026-11-19-platform-accounts-design.md b/docs/superpowers/specs/2026-11-19-platform-accounts-design.md
new file mode 100644
index 000000000..590650fb9
--- /dev/null
+++ b/docs/superpowers/specs/2026-11-19-platform-accounts-design.md
@@ -0,0 +1,417 @@
+# Platform accounts: other apps create and run CARLOS accounts for their customers
+
+Rev 1, 2026-11-19. Draft for Paul's review, after a builder check. References
+are to `main` at `ed6ae029`. Code facts come from a read of that tree;
+file:line refs are starting points and some have drifted, so re-check each
+one against the code. Calls marked **(call)** are the author's, not Paul's.
+
+## 1. Why
+
+CARLOS should work as a platform layer underneath other products. Tito CMS
+is the first: it builds static websites for its customers and wants each
+customer's sites in **a CARLOS account of their own**, so that if a
+customer ever wants direct access, the sites are already separate and
+theirs. Most customers will never sign in to CARLOS at all; Tito CMS does
+everything on their behalf. Oficina Base wants the same thing for websites
+and apps.
+
+So: an operator grants an account **platform** status. That account can
+create **customer accounts** with no human in them, deploy into them, and
+pay for them. A customer may later be invited to claim their account, or
+never be.
+
+Paul's decisions in the brainstorm (2026-11-19):
+
+- D1. Customers are real accounts, not apps or instances inside the
+ platform's account.
+- D2. After a customer claims, the platform keeps managing: it can still
+ deploy, and it still pays. Leaving the platform is a separate, explicit
+ step that ends the platform's access and moves billing to the customer.
+- D3. Approach A: an explicit link from a customer account to its platform
+ account (below), not a robot owner and not nested sub-accounts.
+
+## 2. Goals, non-goals, anti-goals
+
+**Goals**
+
+- A platform's service credential can create customer accounts, list
+ them, and deploy static sites (and anything else Publish allows) into
+ them, with no person signing in.
+- A customer account with no owner is a normal, supported state while it
+ is linked.
+- The platform can hand a customer a claim link; accepting it makes that
+ person an owner of their account, with nothing copied or moved.
+- A claimed customer can leave the platform.
+- Customer accounts' usage is limited per customer and visible to the
+ platform; the platform, not the customer, is responsible for paying.
+- Works the same on Carloku (Paul is the operator) and on Tito's own
+ console (Tito is the operator and grants itself).
+
+**Non-goals for v1**
+
+- Self-serve platform sign-up or a priced platform plan. The operator
+ grants platform status by hand and agrees payment outside the console
+ (§8).
+- White-labelling. A customer who claims signs in to the console that runs
+ the platform (console.carloku.com, console.platform.tito.io) and sees
+ that console's brand. The platform delivers the claim link in its own
+ voice (§7).
+- Bringing an existing ordinary account under a platform.
+- A customer account that is itself a platform (no nesting).
+- Browser pages where platform staff act inside customer accounts. v1
+ platform access is API and CLI only, plus one read-only list (§10).
+- Metered or rolled-up invoices from the console to the platform.
+
+**Anti-goals** (failures even if everything else works)
+
+- A platform credential reaching any account that is not linked to it.
+- A credential issued for one customer touching another customer's
+ account (the #155 class of hole).
+- A platform locking out, removing or deleting a customer who has
+ claimed.
+- A customer being billed, or put on a paid plan, without acting
+ themselves.
+- An older console, after a rollback, reading platform state as wider
+ access than it grants.
+
+## 3. What exists today, and what it assumes
+
+From the code survey (all at `ed6ae029`):
+
+- **Accounts** are minted through `domains.MintAccount`
+ (`internal/domains/mint.go:219`): a create-only write of
+ `accounts/<sqid>/account.json`, then `Store.CreateAccount`
+ (`internal/console/store.go:1177`), which writes the row, the first
+ owner membership and the sponsorship row in one transaction. Every
+ console path that creates an account needs a signed-in person
+ (`handleCLINewAccount` via `cliUser`, `authcli.go:2061`). The manifest
+ is the durable record; `MaterializeAccounts` rebuilds rows from it
+ (`materialize.go:41`).
+- **Ownerless accounts** are possible in data (`EnsureAccount`,
+ `store.go:1202-1207`) but treated as broken: membership is
+ authorization, so nobody can reach one (`server.go:3290`).
+ `lastOwnerGuard` (`store.go:1582`) stops an owned account dropping to
+ zero owners.
+- **Memberships** are `owner` and `member`, keyed by email address.
+ Invites only ever grant `member` (`acceptInviteTx`, `store.go:1733`) and
+ only an owner signed in through the browser can send one
+ (`server.go:3440`).
+- **Service credentials** (`cli_tokens`, kinds `""`, `app`, `service`,
+ `authstore.go:372`) carry one `AccountID` (`svcprincipal.go:52`).
+ `serviceBinding` (`apicli.go:139`) requires the URL's account to equal
+ the credential's. Only a person who owns an account can mint one
+ (`apiservices.go:167`). No credential spans accounts or creates them.
+- **Operators** are people with the `users.operator` bit
+ (`store.go:2664`, `console grant -operator`). That bit gates
+ `accounts plan` (`apiaccountplan.go:45`) and the other operator doors.
+- **Billing** is one Stripe customer and subscription per account,
+ created with the first owner's address; it fails with no owner
+ (`billingcustomer.go:48-56`). Only a signed-in owner may buy
+ (`billinghold.go:94`). Usage is measured per account against caps
+ (`planmeasure.go:28`, `plan_cap_state`); there are no metered charges.
+ Plan rows live in `account_plans` with a `source` and `sponsored`
+ limits (`store.go:444`).
+- **Free-account cap**: `checkNewFreeAccount` (`plancaps.go:175`) counts
+ free accounts a person owns.
+- **Static sites from CI**: `carlos deploy --kind static` creates the app
+ with Publish (`authcli.go:593`), but its first-host step calls
+ `instances-manifest`, which is person-only (`deploy.go:1081`,
+ `authcli.go:716`). A service credential gets its first static route
+ through `POST .../domains` with `kind:"static"` (`apidomains.go:293`).
+- **Naming**: "managed" is taken by managed fleets (`managedstore.go`).
+ This feature uses **platform account** and **customer account**.
+
+## 4. Approaches considered
+
+- **A. Explicit link (chosen, D3).** A customer account records which
+ platform account it belongs to. Creation rights, credentials, limits,
+ billing responsibility, claim and leave all hang off that one fact.
+- **B. Robot owner.** The platform's service identity becomes an ordinary
+ owner of each customer account. Fewer new ideas, but billing still
+ needs a payer link, every rule that assumes owners are people has to
+ learn about robots, and "leave" becomes a special case of "remove an
+ owner". Rejected.
+- **C. Sub-accounts nested inside the platform account.** The customer's
+ sites would live in the platform's account, so claiming means moving
+ them out: the heavy freeze-export-rebuild path the demo claim uses.
+ That works against D1. Rejected.
+
+Within A there was a second choice: how a platform credential acts in a
+customer account.
+
+- **A1. Cross-account principal.** Teach `serviceBinding` that a platform
+ credential may act in any linked account. One credential, but the core
+ account gate changes for every door, and one leaked credential reaches
+ every customer.
+- **A2. Per-customer credentials, minted by the platform (chosen).** The
+ platform credential can only do platform things (create, list, mint,
+ claim links). To deploy, it asks for a short-lived credential bound to
+ one customer account. Existing gates stay exactly as they are, since
+ the minted credential is an ordinary one-account credential; a leak
+ reaches one customer for at most a day. Tito CMS can cache one per
+ customer.
+
+## 5. The model
+
+### 5.1 The platform grant
+
+An operator grants an account platform status. The grant holds:
+
+- `max_customers`: how many linked customer accounts it may have.
+- `plans`: the catalog plans it may put customer accounts on, and
+ `default_plan` among them.
+- `reason` and `granted_by`, for audit.
+- `state`: `active` or `revoked`.
+
+Revoking is an emergency off switch **(call)**: from the next request,
+the platform credential and every per-customer credential it minted are
+refused, including the read doors. Links stay, and the customers' sites
+keep serving. Customers who claimed keep their own access. What happens
+to each customer afterwards is the operator's decision (§9.3).
+
+**Scale (Paul, 2026-11-19):** customers sign up one by one; there is no
+bulk import. The existing account-id allocator (`NextAccountID`, which
+reads every manifest per mint) and start-time materialization stay as they
+are in v1. `max_customers` and a creation rate limit are the guard. If a
+platform ever needs bulk creation, replacing the allocator comes first.
+
+The ops account cannot be a platform, and a customer account cannot be a
+platform (no nesting). A platform account is otherwise an ordinary
+account with ordinary owners, members, plan and billing.
+
+### 5.2 The link
+
+A customer account carries `platform: <platform sqid>` in its bucket
+manifest, written at mint in the same create-only write, so the link
+survives a console rebuild through `MaterializeAccounts` like the owner
+does. The console mirrors it in an account column. Leaving rewrites the
+manifest without the field (§9).
+
+Rollback safety: a console that predates this ignores the field, so a
+linked account with no owner reads as ownerless and unreachable, which
+is narrower, not wider. Per-customer credentials use a **new token kind**
+(§6.2) so an older console refuses them outright rather than reading them
+as plain service credentials.
+
+### 5.3 Ownerless is normal while linked
+
+A linked account with zero owners is a supported state ("held by its
+platform"). Nothing about it is broken: the platform administers it
+through §6. `lastOwnerGuard` still applies once anyone has claimed.
+
+## 6. What the platform can do
+
+### 6.1 The platform credential
+
+A new service role, `platform`, minted by an owner of a platform account
+through the existing services door, in the platform account. It is never
+combined with other roles and never app-bound. It reaches only these new
+doors (all under the platform's own account, so `serviceBinding` holds
+unchanged):
+
+| Door | Does |
+|---|---|
+| `POST /api/cli/platform/{platform}/customers` | Create a customer account: name, optional plan (from the grant's `plans`), optional external reference (the platform's own customer id, unique per platform). Returns sqid. |
+| `GET /api/cli/platform/{platform}/customers` | List linked accounts: sqid, name, external ref, plan, claimed or not, usage against caps. |
+| `GET .../customers/{customer}` | One account, same fields. |
+| `PATCH .../customers/{customer}` | Rename, change plan within the grant. |
+| `POST .../customers/{customer}/credentials` | Mint a per-customer credential (§6.2). |
+| `POST .../customers/{customer}/claim-links` | Make a claim link (§7). |
+| `DELETE .../customers/{customer}` | Delete an **unclaimed** customer account, under the same rule owners have (no apps left, `ownership.go:819`). Refused once anyone has claimed. |
+
+The external reference lets Tito CMS create idempotently ("create or
+return the account for customer 4812") and is the answer to "which CARLOS
+account is this customer's" without Tito storing sqids.
+
+A person who owns the platform account can use the same doors with their
+own login, so the CLI works for platform staff too.
+
+### 6.2 Per-customer credentials
+
+Minted by §6.1 for one linked account, as a new `cli_tokens` kind
+`platform` with `account_id` = the customer and a `platform_account_id`
+column. Properties:
+
+- Role: Publish, account-wide in that one customer account (it must be
+ able to create apps). Optionally narrowed to Deploy on one app, as the
+ services door allows today.
+- Expiry: default 1 h, at most 24 h, set by the caller. These are the
+ first expiring service credentials; the token check must honour
+ `expires_at` for this kind.
+- Refused once the link ends (leave, release, deletion) or the grant is
+ revoked. This is checked on every request, not only when the credential
+ is minted.
+- Never able to mint credentials, change memberships, delete the
+ account, reach billing, or reach any person-only door. Existing role
+ tables already keep Publish off those; the builder confirms each.
+- Audit records the platform account and the platform credential's name
+ as the actor, so customers who claim see "Tito CMS deployed ..." in
+ their account's history.
+
+### 6.3 Static sites from a service credential
+
+A per-customer credential must be able to take a fresh static site from
+nothing to served. Today `carlos deploy --kind static` fails at the
+person-only `instances-manifest` step for any CI credential (§3). v1
+fixes the CLI path for service credentials (use the `domains`
+`kind:"static"` route, or open the first-host step to Publish), whichever
+the builder finds smaller. This is a fix any CI user benefits from, not a
+platform special case.
+
+Custom domains work as they do for any Publish credential, under the
+customer account's `CustomDomains` cap. Buying domains stays person-only.
+
+## 7. Claiming
+
+1. The platform asks for a claim link for a customer, naming the email
+ address it is for. The console returns a single-use link that expires
+ in 7 days. The console sends no email by default: the platform
+ delivers the link in its own voice. (An option to have the console
+ email it may come later.)
+2. The person opens the link, signs in to the console with that address
+ (existing email or Keymail sign-in), and confirms.
+3. They become an **owner** of the customer account. This is a new kind
+ of invite that grants owner and is only valid on a linked account. The
+ sign-in does not create the usual personal account for a first-time
+ person, as the demo claim already avoids it **(call)**.
+4. The claim is written to the account's bucket manifest, setting `owner`
+ to the claimant when it is empty **(call)**. A console rebuilt from the
+ bucket then sees a linked account that has an owner, so it is still
+ claimed, and the platform's delete door still refuses it. The rebuild
+ logic must apply a manifest owner that arrives after the account was
+ first seen, for linked accounts (`AdoptManifestOwner` today applies it
+ only the first time).
+5. The link stays. The platform keeps deploying and paying (D2).
+
+Several people can be made owners this way, and once there is an owner,
+the ordinary owner tools (invites, transfer) work as usual.
+
+After a claim the platform loses:
+
+- deleting the account (§6.1 refuses);
+- anything touching memberships (it never had it).
+
+It keeps creating apps, deploying, domains and plan changes within its
+grant.
+
+## 8. Limits and billing
+
+- Each customer account has its own plan row, `source = platform`, set
+ from the grant's `default_plan` or the plan the platform names. Caps,
+ grace and throttles work per customer account exactly as now, so one
+ busy customer cannot use up another's allowance.
+- Linked accounts never get a Stripe customer or subscription; checkout
+ and plan changes are refused to their owners with "Your plan is managed
+ by <platform name>." The platform changes plans through §6.1.
+- Linked accounts do not count towards anyone's free-account cap.
+- **Notices go to whoever pays (call).** Cap, grace and lapse notices for
+ a customer account go to the platform account's owners, whether the
+ customer has claimed or not. Customers can't act on them, since the
+ platform controls their plan. The notice clock (`afterGraceDue`,
+ `plangrace.go:139`) counts a notice to the platform's owners as a
+ notice, so storage denial and lapse steps work on unclaimed accounts
+ too. The messages are new copy and go through copy review. A platform
+ moving a customer to a lower plan goes through the same grace rules as
+ an owner doing it today.
+- **No purchases on linked accounts (call).** Buying a domain
+ (`domainbuy.go:207` creates a Stripe customer) is refused on linked
+ accounts in v1, for the platform and for claimed owners alike. A
+ customer who wants to buy one can leave first, or attach a domain
+ registered elsewhere.
+- **Who pays (v1):** the platform's payment for its customers' usage is
+ agreed between the platform and the operator outside the console. On
+ Carloku that is Paul's arrangement with the platform; on Tito's own
+ console it is Tito paying itself. The console's part is to make usage
+ visible: the list door returns each customer's usage against caps, and
+ the platform account page totals them (§10). A priced, self-serve
+ platform plan is a later feature.
+
+## 9. Leaving, and ending the link
+
+### 9.1 A claimed customer leaves
+
+An owner of a claimed customer account chooses "Leave <platform name>"
+on the account page, with a fresh sign-in, as for ownership transfer.
+In one step:
+
+- the link is removed (manifest rewritten without `platform`, keeping
+ `owner`, column cleared);
+- every per-customer credential for the account is revoked;
+- the plan row becomes the catalog's default plan, `source` default. If
+ that is free and the person is already at their free-account cap,
+ leaving is refused with a pointer to upgrade or remove an account first;
+- the platform is told (its list no longer shows the account; an event
+ for a webhook is out of scope for v1).
+
+From then on it is an ordinary account; if its usage exceeds the default
+plan, the ordinary grace and caps flow applies.
+
+### 9.2 The platform releases a claimed customer
+
+The platform may end the link to a claimed account itself (it stops
+serving that customer). Same effects as §9.1, and the owners are emailed
+that their account is now theirs to run and pay for. An unclaimed account
+cannot be released: it would have nobody in it. The platform deletes it
+instead.
+
+### 9.3 The operator
+
+The operator can see platforms and their customer counts, revoke a grant
+and re-grant it. **Operator release (call)**: a new operator door ends one
+customer's link with the same effects as §9.2. For an unclaimed account,
+the operator first adds an owner with the existing `console member`
+command (which must also write the manifest owner, as §7 does), or
+deletes the account. A platform account is never deleted while it has
+linked customers.
+
+## 10. What people see
+
+UX pass and copy review come before any of this ships (AGENTS.md,
+"Every UI change gets a UX pass").
+
+- **Platform account page:** a "Customers" section listing linked
+ accounts (name, external ref, plan, claimed, usage against caps) and
+ totals. Read-only in v1; platform staff cannot open a customer account
+ in the browser unless they are also members of it.
+- **Customer account page, after claim:** a plain statement that the
+ account is run by <platform name>, who pays for it, with "Leave" (§9.1).
+ Plan and billing controls are replaced by that statement.
+- **Operator:** platform grants visible on the operator account pages.
+- **CLI:** `carlos platform customers {create,list,show,update,delete}`,
+ `carlos platform credentials mint`, `carlos platform claim-link`, and
+ for operators `carlos accounts platform --account <sqid> --grant ...`
+ / `--revoke`.
+
+## 11. Slices
+
+1. **Platform layer:** the grant (operator door), the link, ownerless
+ linked accounts, the `platform` role and its create/list/show/update/
+ delete doors, per-customer credentials, the static-site fix (§6.3).
+ Witness: a platform credential creates a customer account and serves a
+ static site in it on dev, with no person signing in, and the
+ per-customer credential is refused on a second customer account.
+ Tito CMS can build on this alone.
+2. **Claim and leave:** claim links, owner-granting invites, customer
+ account page, leave and release, billing controls replaced on linked
+ accounts.
+3. **Visibility:** the platform account's Customers section with usage
+ totals; operator view.
+
+Each slice is dormant until the operator grants an account platform
+status, so each can merge on its own.
+
+## 12. Left to the builder
+
+- Table and column names, and whether the grant lives in its own table
+ or on `account_plans`.
+- The exact role table entries for the `platform` role and the new
+ doors, keeping every person-only door person-only.
+- Rate limits on customer creation and credential minting (start from
+ the existing service budgets, `authcli.go:147,152`).
+- Which of the two §6.3 fixes is smaller.
+- How the external reference is indexed and its allowed characters.
+- Census and witness tests, per the usual production-wired rule.
+- Whether an Admin service credential on the platform account reaches the
+ platform doors (suggested: no, as Run is kept out).
+- How per-customer credentials appear in a claimed customer's credential
+ list.