carlos / platform Public

plan: billing dashboard 3, CARLOS-only platform cost

Spec section 4.5. Bills gain an additive basis (whole account, account
declared CARLOS-only, or carlos:deployment-tagged); one seam,
carlosPlatformCostUSD, answers only for a CARLOS-only basis and Plan 2
converts it to euros. Slice A (account mode, seam, Economics label,
manual-entry basis) serves Carloku; slice B (tag mode, tag activation
check, untagged listing, runbook) waits for a named user.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev c61c05f63aff8b3e816406f1358d5180b6ecc241 parent dd344d1
1 file changed, +262 −0
  • docs/superpowers/plans/2026-11-09-billing-dashboard-3-carlos-only-cost.md +262 −0
diff --git a/docs/superpowers/plans/2026-11-09-billing-dashboard-3-carlos-only-cost.md b/docs/superpowers/plans/2026-11-09-billing-dashboard-3-carlos-only-cost.md
new file mode 100644
index 000000000..84e638ced
--- /dev/null
+++ b/docs/superpowers/plans/2026-11-09-billing-dashboard-3-carlos-only-cost.md
@@ -0,0 +1,262 @@
+# Billing dashboard 3: CARLOS-only platform cost 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:** Every stored AWS bill says what it covers, and the console exposes one figure, the month's CARLOS-only platform cost, that is never the whole of a mixed AWS account.
+
+**Architecture:** `economics.Bill` gains an additive `basis` (and, for the tagged basis, the `deployment` tag value). The hourly `billPass` stamps it from a new console setting: either the AWS account is declared CARLOS-only (Carloku), or Cost Explorer is filtered to `carlos:deployment=<value>`, used only for months the cost allocation tag was active from day one. One method, `carlosPlatformCostUSD`, reads the stored bill and answers only for a CARLOS-only basis; Plan 2 converts it to euros. The Economics page and the manual-entry doors show and set the basis.
+
+**Tech Stack:** Go, the existing Cost Explorer seam (`internal/console/cepull.go`, aws-sdk-go-v2 `service/costexplorer` v1.67.5, already a dependency), `html/template`, OpenTofu (`infra/modules/region-host`). No new dependency.
+
+**Spec:** `docs/superpowers/specs/2026-11-09-billing-dashboard-design.md` §4.5, plus the parts of §2 (anti-goal "A total AWS cost that includes things that aren't CARLOS") and §7 ("The platform cost matches the CARLOS-only AWS figure, and the page says which basis it used") that name it. Paul, 2026-11-09: "Make sure the AWS bill stuff only takes CARLOS related resources into account and not the full AWS bill on the account. I think in the Carloku case, everything on the bill is CARLOS related, so that should be fine." Plans 1 and 2 of this spec are written beside this one; Plan 2 calls this plan's seam.
+
+## Global Constraints
+
+- Baseline: branch `design-billing-dashboard`, `dd344d1fa37b43a4ce5a260cd402a68bb954a5ba`. Unqualified `file:line` citations refer to it. New names below are this plan's decisions.
+- Wire shapes are additive (`AGENTS.md:431`). Bills written before this plan carry no `basis` and must still parse; a whole-account bill written after it must marshal byte-identically to one written before it (`omitempty` on both new keys).
+- Provider-neutral core (memory `provider-neutral-core`): `internal/economics` gains plain strings, no AWS import. Cost Explorer stays behind the existing `ceCosts` seam in `internal/console/cepull.go`. A deployment without AWS records bills by hand and declares their basis; nothing in this plan requires AWS.
+- Pages never call Cost Explorer (spec §2 anti-goal "A slow page"). Only `billPass` does.
+- No new bucket object and no new poll (memory `s3-requests-cost-money`). Steady-state request budget, nothing changing: S3 unchanged (`billPass` already reads two bill objects per hourly tick); Economics view in tag mode adds one GET of `infra/inventory.json` per view build (60 s cache, page-driven, not polled); Cost Explorer adds one `ListCostAllocationTags` per UTC day in tag mode only, plus one re-pull per month when the basis changes.
+- Copy: every human-facing string is in the copy table below and goes through the `copy-review` skill before it is written into a file. No em dashes in copy. Error fragments and CLI diagnostics are listed but are outside copy review (memory `copy-review-scope-human-text`).
+- No tenant names in code, tests or docs; the example deployment value is `production` (already used by `internal/awsmanaged/testdata/managed-console-policy.json`).
+- Census (`AGENTS.md:299`): `internal/economics/bill.go` is in the root binary's scope (`internal/provision/testdata/census-base-scope.txt:262`, reached through `internal/hostops/storage_classifier.go`), and so are the root package's `economics.go` and every non-Markdown file under `infra/`. Tasks 1, 4 and 5 change census scope; see "Census and cross-compile" below.
+- Stopping rules (`AGENTS.md:34`) and gate (`AGENTS.md:245`): targeted `go test -run` while iterating, default `GOCACHE`; `make test` and `go build ./...` once before handoff; CI runs `20-cross@5`.
+
+## Review Focus
+
+1. **The tag is not active, or became active mid-month.** A tag-filtered query then returns $0 or a part-month figure that reads as the CARLOS cost. Expected: that month is stored whole-account and hidden. Task 5 `TestBillPassTaggedNeedsActiveTag`.
+2. **The setting changes after bills exist.** A month already pulled, or already settled after day 3, keeps its old basis forever. Expected: one re-pull under the new basis, then the ordinary once-a-day and settle rules. Task 1 `TestBillPassRepullsOnBasisChange`.
+3. **A hand-entered bill on a mixed account.** An old CLI sends no basis. Expected: it is not counted as CARLOS-only unless the account is declared CARLOS-only or the operator says "tagged". Task 4 `TestEconomicsBillBasisDoors`.
+4. **AWS tax on the bill.** Revenue on the Billing pages is before tax (spec §4.3), so a whole-account cost with the `Tax` line in it would understate profit. Expected: the platform cost leaves out the `Tax` service line on every basis. Task 2 `TestCarlosPlatformCostBasis`.
+5. **An unknown or hand-edited `basis` value in the bucket.** Expected: read as whole-account (fail closed), never as CARLOS-only. Task 2 `TestCarlosPlatformCostBasis`, and the host-side classifier still admits the new keys (Task 1 `TestReviewedStorageBodiesBindIdentityAndScope` rows).
+
+---
+
+## What CARLOS tags today (read-only survey, 2026-11-09)
+
+| Resource | Created by | `carlos:deployment` today |
+|---|---|---|
+| Region HA group boxes (ASG instances via launch template) | `infra/modules/region-host/group.tf:19-23` | Yes, with `carlos:region` |
+| Managed fleet boxes and fleet buckets | `internal/awsmanaged/compute.go:197`, `storage.go:182` | Yes, but not wired into `cmd/console` yet (2b-2 building) |
+| Single region hosts (`aws_instance`), their volumes and EIPs, scanner and PDF hosts | `infra/modules/{region-host,scanner-host,pdf-host}/main.tf` | No (`Name` only) |
+| Deployment and data buckets | `infra/modules/deployment-buckets` | No |
+| Alarms, SNS, SQS, NLB, launch template | `infra/modules/region-host` | No |
+| Tenant object-store buckets | console, `internal/objstore/aws.go:294` | No |
+| Steering health checks | `internal/steering/route53.go` | No |
+| Hosted zones, NAT, anything else | private roots (`carloku-infrastructure`, `platform-infrastructure`) | No: neither local clone has `default_tags` or any `carlos:` tag |
+
+So a tag-filtered bill today would count almost nothing. Carloku's account is CARLOS-only (Paul), so it uses the account setting and needs no tagging. Dev's account (kass) is mixed and has no Cost Explorer grant (`enable_cost_explorer` is set only in `carloku-infrastructure/region-ie.tf:68`), so dev's costs stay hidden until someone tags and activates (Task 6 runbook, a production-infrastructure change that needs Paul's scoped approval per `AGENTS.md:119`).
+
+## Decisions
+
+- **Settings** (my call; spec §6 leaves the names to the builder). `CONSOLE_COST_ACCOUNT_CARLOS_ONLY=true` declares the whole AWS account CARLOS-only. `CONSOLE_COST_DEPLOYMENT_TAG=<value>` selects tag mode with that `carlos:deployment` value. Both set stops the console at boot, as do a non-boolean value and a tag value outside `^[A-Za-z0-9._:/=+@-]{1,256}$` (the same grammar as `internal/awsmanaged/compute.go:61`). Neither set: bills are still pulled whole-account for the Economics page, and the CARLOS-only figure is hidden. These are independent of 2b-2's `CARLOS_MANAGED_FLEET_DEPLOYMENT` (unmerged, `AGENTS.md:68` rule 4); defaulting one to the other is a follow-up.
+- **Stored basis values** (`internal/economics`): `""` the whole account, may hold more than CARLOS (every existing bill); `"account"` the whole account, declared CARLOS-only; `"tagged"` only resources tagged `carlos:deployment=<Deployment>`.
+- **Reading a bill** (`effectiveBillBasis`): a stored `account` or `tagged` stands, whatever the setting is now (it was true when pulled). A stored `""` reads as `account` while `CONSOLE_COST_ACCOUNT_CARLOS_ONLY` is on, since a whole-account figure from a CARLOS-only account is CARLOS-only. That is how Carloku's settled October bill counts without a re-pull. Anything else reads as `""`.
+- **Tag mode needs a live tag.** Each UTC day, at most once, the pull asks Cost Explorer `ListCostAllocationTags` for `carlos:deployment`. A month is pulled tagged only when the tag is `Active` and its `LastUpdatedDate` is on or before the month's first day; otherwise it is pulled whole-account with basis `""`. A failed status call (including AccessDenied, which a member account of an AWS Organization can get) also means whole-account. It is logged once and never latches `ceDisabled`.
+- **Tax.** `carlosPlatformCostUSD` subtracts the `Tax` service line (Cost Explorer's `SERVICE` value for tax) on every basis. A tag filter already excludes it; a whole-account bill does not.
+- **Per-service "Counts as CARLOS" checkboxes** (`Scenario.BillServices`, `templates/economics.html:209-221`) stay a modelling knob on the Economics page. They do not feed `carlosPlatformCostUSD`. A service-level pick cannot separate CARLOS from other EC2 in the same account.
+- **Manual entry.** The form, the API and the CLI take an optional basis: `tagged` or `account`. When it is absent the console uses `account` if the account is declared CARLOS-only, otherwise `""`. A manual `tagged` bill records the configured tag value, if any.
+- **Untagged CARLOS resources.** Tagging what the console creates at runtime (tenant buckets, steering health checks) needs new IAM (`s3:TagResource`, `route53:ChangeTagsForResource`) and census review, and no live deployment uses tag mode. It is a follow-up, not in this plan. This plan lists untagged resources on the Economics page (Task 6) and documents the operator steps.
+- **Slices.** Tasks 1-4 are slice A: account mode, the seam and the basis everywhere. Carloku sees it as soon as the setting is on. Tasks 5-6 are slice B: tag mode. Slice B has no live user today (rule 5, `AGENTS.md:74`), so it merges only once Paul names a switch-on (dev or Tito).
+
+## Copy table (through `copy-review` before Task 2; slice B rows before Task 5)
+
+| # | Where | Draft |
+|---|---|---|
+| C1 | basis label, tagged | `AWS, CARLOS-tagged only (carlos:deployment=%s)`; without a value: `AWS, CARLOS-tagged only` |
+| C2 | basis label, account | `AWS, whole account: CARLOS only` |
+| C3 | basis label, whole | `AWS, whole account: not only CARLOS` |
+| C4 | hint, whole, no setting | `This bill covers the whole AWS account, which may hold more than CARLOS. Set CONSOLE_COST_ACCOUNT_CARLOS_ONLY=true if the account runs only CARLOS, or CONSOLE_COST_DEPLOYMENT_TAG to count tagged resources only.` |
+| C5 | hint, whole, tag mode (slice B) | `The carlos:deployment cost allocation tag was not active for all of %s, so this bill covers the whole AWS account. Months that start after you activate the tag count tagged resources only.` |
+| C6 | hint, no bill | `No AWS bill on file for %s yet.` |
+| C7 | manual form | label `What this bill covers`; options `CARLOS-tagged resources only` / `The whole account, which runs only CARLOS` / `The whole account, CARLOS and other things` |
+| C8 | CLI `--basis` help | `what the total covers: tagged (CARLOS-tagged resources only) or account (the whole account, which runs only CARLOS)`; output line `basis: %s` |
+| C9 | untagged section (slice B) | heading `Not tagged for CARLOS`; note `%d resources in this AWS account have no carlos:deployment=%s tag, so their costs are left out. Tag the ones that belong to CARLOS.`; footer `Tags not checked: %d buckets, %d DNS zones, %d alarms.` |
+| C10 | `infra/modules/README.md` section "Counting only CARLOS in the AWS bill" | prose per Task 6, reviewed as a whole |
+| x | not reviewed (diagnostics) | boot: `console: CONSOLE_COST_ACCOUNT_CARLOS_ONLY and CONSOLE_COST_DEPLOYMENT_TAG are both set; choose one`; API 400: `basis must be tagged or account` |
+
+---
+
+### Task 1: Basis on the bill, the CARLOS-only account setting, and the pull
+
+**Risk/review:** production storage wire shape (bill objects in the deployment bucket) and census scope. Independent task review required (`AGENTS.md:65` rule 3), plus the census reviewer.
+
+**Files:**
+- Modify: `internal/economics/bill.go:5-24` (consts, two fields, doc comment that no longer claims attribution is only a dashboard knob), `internal/economics/bill_test.go`
+- Create: `internal/console/costscope.go`, `internal/console/costscope_test.go`, `cmd/console/costscope.go`, `cmd/console/costscope_test.go`
+- Modify: `internal/console/server.go:761` (Config field), `:1336` (seam type), `:1786` (NewServer validates); `cmd/console/main.go:507` (wire the setting); `internal/console/cepull.go:42,53` (seam takes `ceQuery`); `internal/console/economicspass.go:1072-1127` (`pullBillMonth`, `shouldSkipCEPull`); `internal/console/economicsbill_test.go` and `claim_invariant_probes_worker_test.go:157` (mechanical: closures take `ceQuery`); `internal/hostops/storage_classifier_test.go:36` (table rows only, no `hostops` source change)
+
+**Interfaces:**
+- Produces, `internal/economics`: `const BasisWholeAccount = ""`, `BasisAccount = "account"`, `BasisTagged = "tagged"`; `Bill.Basis string \`json:"basis,omitempty"\``; `Bill.Deployment string \`json:"deployment,omitempty"\`` (set only with `BasisTagged`). `Schema` stays 1.
+- Produces, `internal/console`: `type CostScope struct { AccountCarlosOnly bool }` (Task 5 adds `DeploymentTag string`); `func (c CostScope) Validate() error`; `Config.CostScope CostScope`; `type ceQuery struct { Start, End time.Time }` (Task 5 adds `TagValue string`); seam `ceCosts func(ctx context.Context, q ceQuery) (map[string]float64, error)`; `func (s *Server) resolveCECosts(ctx context.Context, q ceQuery) (map[string]float64, error)`; `func (s *Server) billBasisFor(ctx context.Context, start, end, now time.Time) (q ceQuery, basis, deployment string)`; `func shouldSkipCEPull(existing *economics.Bill, closedMonth bool, now time.Time, basis, deployment string) bool`.
+- Produces, `cmd/console`: `func costScopeFromEnv(getenv func(string) string) (console.CostScope, error)`; `main` calls it and `log.Fatalf`s on error.
+
+- [ ] **Step 1: Write the failing tests**
+ - `TestBillBasisWireShape` (`internal/economics`): `{"schema":1,"month":"2026-10","total_usd":5,"services":{},"source":"costexplorer"}` unmarshals with `Basis == ""`; marshalling a bill with `Basis: BasisWholeAccount` produces no `"basis"` and no `"deployment"` key; a `BasisTagged`/`"production"` bill round-trips both.
+ - `TestCostScopeFromEnv` (`cmd/console`): unset gives the zero scope; `"true"` gives `AccountCarlosOnly`; `"maybe"` errors with the variable's name in the message.
+ - `TestBillPassStampsBasis` (`internal/console`, fixture `newConsoleFixture`, `now := 2026-08-11T03:00Z`): with `fx.srv.cfg.CostScope = CostScope{AccountCarlosOnly: true}`, both `2026-08` and `2026-07` bills have `Basis == "account"`; with the zero scope both have `Basis == ""` and their raw JSON contains no `"basis"`.
+ - `TestBillPassRepullsOnBasisChange`: a zero-scope `billPass` (2 `ceCosts` calls); then set the account scope and run again the same UTC day: 2 more calls and both bills now `account`; a third run: 0 more calls. Separately, a `2026-07` bill stored with `PulledAt 2026-08-05` (settled) and `Basis ""` is re-pulled exactly once after the switch.
+ - In `TestReviewedStorageBodiesBindIdentityAndScope`, add rows `{"economics/bills/2026-10.json", \`{"schema":1,"month":"2026-10","source":"costexplorer","basis":"tagged","deployment":"production"}\`, true}` and the same without `basis`/`deployment`, `true`.
+- [ ] **Step 2: Run to verify they fail**
+ Run: `go test ./internal/economics ./cmd/console ./internal/console ./internal/hostops -run 'TestBillBasisWireShape|TestCostScopeFromEnv|TestBillPass(StampsBasis|RepullsOnBasisChange)|TestReviewedStorageBodiesBindIdentityAndScope' -count=1`
+ Expected: FAIL on undefined `Basis`, `CostScope`, `costScopeFromEnv`. The hostops rows fail with an unknown-field error until `bill.go` changes.
+- [ ] **Step 3: Implement**
+ `billBasisFor` returns `(ceQuery{start, end}, BasisAccount, "")` when `AccountCarlosOnly`, otherwise `(ceQuery{start, end}, BasisWholeAccount, "")`. `pullBillMonth` computes the basis before the skip check and stamps `Basis`/`Deployment` on the bill it writes. `shouldSkipCEPull` returns false when `existing.Basis != basis || existing.Deployment != deployment`, before its settle and same-day rules. Manual-wins in `upsertBill` is unchanged. `costScopeFromEnv` reads `CONSOLE_COST_ACCOUNT_CARLOS_ONLY` with `strconv.ParseBool` after `TrimSpace` (the `domainProof` shape, `cmd/console/main.go:1489`). Rewrite `bill.go`'s type comment: the pull is CARLOS-scoped by `Basis`, and `""` means whole account.
+- [ ] **Step 4: Run to verify they pass**, plus the existing bill tests: `go test ./internal/console -run 'TestBillPass|TestEconomics' -count=1`; expect PASS.
+- [ ] **Step 5: Census card.** `make census-card`; CLAIMS line `internal/economics/bill.go:Bill<TAB>two additive string fields and three consts; no read added`; `make census-propose NAME=<branch> CLAIMS=<file>`. If Plans 1-2 share this branch, add this line to that branch's single CLAIMS file instead.
+- [ ] **Step 6: Commit** `economics: record what each AWS bill covers`
+
+### Task 2: The platform-cost seam Plan 2 calls
+
+**Risk/review:** billing figures. Independent task review.
+
+**Files:**
+- Create: `internal/console/platformcost.go`, `internal/console/platformcost_test.go`
+
+**Interfaces:**
+- Consumes: Task 1's `economics.Basis*`, `Config.CostScope`; existing `func (s *Server) getBill(ctx context.Context, month string) (*economics.Bill, error)` (`economicspass.go:1129`).
+- Produces (Plan 2 calls these; names are final):
+ - `func (s *Server) carlosPlatformCostUSD(ctx context.Context, month string) (usd float64, basis string, ok bool)`. `month` is `"2006-01"`. `ok` is true only when the effective basis is `economics.BasisAccount` or `economics.BasisTagged`. `usd` is `TotalUSD - Services["Tax"]`. When `!ok`, `basis` is `economics.BasisWholeAccount` for a whole-account bill, or `costBasisMissing` when there is no readable bill (a read error is logged). One bucket GET per call, no cache. Plan 2 owns caching and the conversion: `platformCostEUR(month)` multiplies `usd` by its daily USD→EUR rate, passes `basis` through, and hides the figure when `!ok`.
+ - `const costBasisMissing = "missing"` (never stored).
+ - `func effectiveBillBasis(b economics.Bill, scope CostScope) string`.
+ - `func costBasisLabel(basis, deployment string) string`: copy C1 to C3.
+ - `func costBasisHint(scope CostScope, basis, month string) string`: C4 for `""`, C6 for `costBasisMissing`, `""` for a CARLOS-only basis. Task 5 adds C5. The Billing pages render this line in place of hidden costs (spec §4.5 "hidden behind a one-line explanation").
+ - `const billTaxService = "Tax"`.
+
+- [ ] **Step 0 (once, before this task): copy review.** Run the `copy-review` skill over rows C1-C4 and C6-C8 and wait for Paul's edits. Apply them verbatim; Tasks 2-4 use the approved strings.
+- [ ] **Step 1: Write the failing tests.** `TestCarlosPlatformCostBasis`, a table over stored bill × scope → `(usd, basis, ok)`:
+ - no object → `(0, "missing", false)`; unparseable object → `(0, "missing", false)`
+ - `""` bill, zero scope → `(0, "", false)`
+ - `""` bill, account scope, `Total 100`, `Services {"AmazonEC2":90,"Tax":10}` → `(90, "account", true)`
+ - `"account"` bill, zero scope → `ok` true, basis `account` (stored basis stands)
+ - `"tagged"`/`production` bill, zero scope → `ok` true, basis `tagged`
+ - `"bogus"` bill, account scope → `(0, "", false)` (fail closed: an unknown value is whole-account, and the account setting does not promote it)
+ - manual `""` bill, account scope → `ok` true, basis `account`
+
+ `TestCostBasisLabelAndHint` asserts C1 (with and without a value), C2, C3, C4 and C6 exactly as approved.
+- [ ] **Step 2: Run** `go test ./internal/console -run 'TestCarlosPlatformCostBasis|TestCostBasisLabelAndHint' -count=1`; expect FAIL (undefined).
+- [ ] **Step 3: Implement** the Interfaces above. In `effectiveBillBasis`, only `""` is promoted to `account` by the setting; `account` and `tagged` pass through; any other value returns `""`.
+- [ ] **Step 4: Run Step 2 again**; expect PASS.
+- [ ] **Step 5: Commit** `console: one CARLOS-only platform cost figure for Billing`
+
+### Task 3: The Economics page shows the basis
+
+**Risk/review:** UI only; covered by the whole-branch review.
+
+**Files:**
+- Modify: `internal/console/economicsview.go:45-100` (two fields), `:654` and `:677` (fill them), `internal/console/templates/economics.html:185-243`, `internal/console/economicspage_test.go`
+
+**Interfaces:**
+- Consumes: Task 2's `effectiveBillBasis`, `costBasisLabel`, `costBasisHint`.
+- Produces: `EconomicsView.BillBasisLabels map[string]string` (month → label) and `EconomicsView.BillBasisHints map[string]string` (month → hint, absent when there is none). Both are shared and read-only, like `Bills` (see `copyEconomicsView`, `:352`).
+
+- [ ] **Step 1: Write the failing test** `TestEconomicsPageShowsBillBasis`: seed a `2026-08` bill. With the account scope, `/fleet/economics?period=mtd` (an operator session, as in `economicspage_test.go:111`) contains C2 next to the bill table heading. With the zero scope it contains C3 and C4. A `tagged`/`production` bill shows C1 with `carlos:deployment=production`.
+- [ ] **Step 2: Run** `go test ./internal/console -run TestEconomicsPageShowsBillBasis -count=1`; expect FAIL.
+- [ ] **Step 3: Implement.** Fill both maps where `Bills` is assigned. In the template, add the label to the bill table's heading row (`:213`, after the source) and the hint as a `co-note` paragraph under the table. No new CSS classes (`docs/console-styleguide.md`).
+- [ ] **Step 4: Run Step 2 again and** `go test ./internal/console -run 'TestEconomics|TestConsoleStyleguideClassesExist' -count=1`; expect PASS.
+- [ ] **Step 5: Commit** `economics page: say what the AWS bill covers`
+
+### Task 4: Manual bills carry a basis (form, API, CLI)
+
+**Risk/review:** billing input doors and census (root package). The census reviewer covers `economics.go`; otherwise the whole-branch review.
+
+**Files:**
+- Modify: `internal/console/economicspass.go:1394` (`handleEconomicsBillSave`), `:1548` (`handleAPIEconomicsBill`), `templates/economics.html:227-242` (C7 select); `economics.go:31` (usage), `:232` (`economicsBillResult.Basis`), `:250` (`economicsBill` gains `basis string`), `:275` (`--basis` flag, output line); `economics_test.go:80`; `docs/site/cli.md:2689-2701`
+- Test: `internal/console/economicsbill_test.go`
+
+**Interfaces:**
+- Consumes: Task 1's basis consts and `Config.CostScope`.
+- Produces: `func (s *Server) manualBillBasis(raw string) (basis, deployment string, err error)` in `economicspass.go`. `""` gives the default (account if declared, else whole). `tagged` gives `BasisTagged` plus the configured tag value, or `""` before Task 5. `account` gives `BasisAccount`. Anything else is an error. API request gains `Basis string \`json:"basis,omitempty"\``. CLI: `func validBillBasis(s string) error` (accepts `""`, `tagged`, `account`); `func (s *apiSession) economicsBill(ctx context.Context, month string, total float64, services map[string]float64, basis string) (economicsBillResult, error)`.
+
+- [ ] **Step 1: Write the failing tests.**
+ - `TestEconomicsBillBasisDoors` (form and API, table): basis `tagged` stores `tagged`. No basis with the account scope stores `account`. No basis with the zero scope stores `""`. `bogus` gives the form 400 and the API 400 `basis must be tagged or account`, and nothing is written.
+ - Extend `TestAPISessionEconomicsBillWireShape`: with `basis "account"` the body carries `"basis":"account"`; with `""` the key is absent, so an older console sees the same body as before.
+ - `TestValidBillBasis`.
+- [ ] **Step 2: Run** `go test ./internal/console -run TestEconomicsBillBasisDoors -count=1` and `go test . -run 'TestAPISessionEconomicsBill|TestValidBillBasis' -count=1`; expect FAIL.
+- [ ] **Step 3: Implement.** The form's select defaults to the option that matches the scope (C7). The CLI prints `basis: <label>` using the stored basis (C8). Add `--basis` to the `cli.md` example paragraph; `internal/docsite` checks headings only, and none change.
+- [ ] **Step 4: Run Step 2 again**, plus `go test ./internal/docsite -count=1`; expect PASS.
+- [ ] **Step 5: Census.** Add `economics.go:economicsBill<TAB>request gains optional basis; no read added`, the same for `runEconomicsBill` and `economicsBillResult`; rerun `make census-propose` with the same NAME.
+- [ ] **Step 6: Commit** `economics bill: say what a hand-entered bill covers`
+
+**Slice A ends here.** Before merge: `make test`, `go build ./...`, whole-branch review, census verdict on #280. Switch-on for Carloku is below.
+
+### Task 5: Tag mode: filter Cost Explorer to `carlos:deployment`, only while the tag is live
+
+**Risk/review:** billing figures, the IAM grant on the console's role, census (`infra/`). Independent task review plus the census reviewer. Production IAM is changed only by a later apply that Paul approves.
+
+**Files:**
+- Modify: `internal/console/costscope.go`, `cmd/console/costscope.go` (+ tests); `internal/console/cepull.go` (filter, tag status); `internal/console/server.go:1336-1343` (seam and day cache fields); `internal/console/economicspass.go` (`billBasisFor` tag branch); `internal/console/platformcost.go` (`costBasisHint` C5); `infra/modules/region-host/main.tf:406-424` (comment and action), `infra/modules/region-host/variables.tf:203-207` (description)
+- Test: `internal/console/economicsbill_test.go`, `internal/console/cepull_test.go` (create)
+
+**Interfaces:**
+- Consumes: Tasks 1-2.
+- Produces:
+ - `CostScope.DeploymentTag string`. `Validate` refuses both settings at once and a value outside `^[A-Za-z0-9._:/=+@-]{1,256}$`. `costScopeFromEnv` reads `CONSOLE_COST_DEPLOYMENT_TAG`.
+ - `const costDeploymentTagKey = "carlos:deployment"`.
+ - `ceQuery.TagValue string` (`""` means the whole account).
+ - `func ceFilterFor(q ceQuery) *cetypes.Expression`: nil for `""`, otherwise `&cetypes.Expression{Tags: &cetypes.TagValues{Key: aws.String(costDeploymentTagKey), Values: []string{q.TagValue}, MatchOptions: []cetypes.MatchOption{cetypes.MatchOptionEquals}}}`. `realCECosts` sets `GetCostAndUsageInput.Filter` from it.
+ - Seam `ceTagStatus func(ctx context.Context) (active bool, since time.Time, err error)`; `func (s *Server) resolveCETagStatus(ctx context.Context, now time.Time) (active bool, since time.Time, err error)` caches the answer, error included, per UTC day (`ceTagDay string`, `ceTagActive bool`, `ceTagSince time.Time`, `ceTagErr error`; single goroutine, as `cepull.go:36` explains); `func (s *Server) realCETagStatus(ctx context.Context) (bool, time.Time, error)` calls `ListCostAllocationTags{TagKeys: []string{costDeploymentTagKey}}` on the shared client, logs a failure once (`ceTagWarnOnce`) and never calls `disableCE`.
+ - `func tagStatusFrom(out *costexplorer.ListCostAllocationTagsOutput) (active bool, since time.Time, err error)`: `Status == CostAllocationTagStatusActive`; `since` from `LastUpdatedDate`, parsed as RFC 3339, then `2006-01-02`; unparseable is an error; key absent is inactive.
+ - `billBasisFor` tag branch: `(ceQuery{start, end, tag}, BasisTagged, tag)` only when `active && err == nil && !since.After(start)`; otherwise the whole-account result with `BasisWholeAccount`.
+
+- [ ] **Step 0: copy review** of C5, C9 and C10, as Task 2 Step 0.
+- [ ] **Step 1: Write the failing tests.**
+ - `TestCostScopeFromEnv` adds: tag `production` sets it; `bad value!` errors; both settings error with the boot diagnostic.
+ - `TestBillPassTaggedFilter`: scope tag `production`, `ceTagStatus` active since `2026-01-01`. `ceCosts` sees `TagValue "production"` for both months; bills are `tagged`/`production`.
+ - `TestBillPassTaggedNeedsActiveTag` (table, `now 2026-08-11`): inactive → both `""` with `TagValue ""`. Active since `2026-08-05` → both `""`. Active since `2026-07-01` → both `tagged`. Active since `2026-07-15` → `2026-07` `""`, `2026-08` `tagged`. Status error (an AccessDenied-shaped `smithy.GenericAPIError`) → both `""`, and `fx.srv.ceDisabled` stays false.
+ - `TestBillPassTagStatusOncePerDay`: two passes the same UTC day call `ceTagStatus` once; the next day, once more.
+ - `TestCEFilterFor` and `TestTagStatusFrom` (`cepull_test.go`) with the exact values above.
+ - `TestCostBasisLabelAndHint` adds C5 for a `""` bill under tag scope.
+- [ ] **Step 2: Run** `go test ./internal/console ./cmd/console -run 'TestCostScopeFromEnv|TestBillPassTag|TestCEFilterFor|TestTagStatusFrom|TestCostBasisLabelAndHint' -count=1`; expect FAIL.
+- [ ] **Step 3: Implement** the Interfaces. In `main.tf` the grant becomes `Action = ["ce:GetCostAndUsage", "ce:ListCostAllocationTags"]`. Update the comment above it and the variable description ("Grant Cost Explorer reads (GetCostAndUsage, ListCostAllocationTags) so a console on this box can pull the monthly bill …"). The managed-fleets isolation list (`tests/managed_fleets/managed_fleets.tftest.hcl:384-400`) names no `ce:` action, so it still holds.
+- [ ] **Step 4: Run Step 2 again**; expect PASS. If `tofu` is installed: `tofu -chdir=infra/modules/region-host init -backend=false && tofu -chdir=infra/modules/region-host test`; expect PASS. Tofu tests are not in CI.
+- [ ] **Step 5: Census.** CLAIMS lines for `infra/modules/region-host/main.tf` (`envelope`: the console role may also list cost allocation tag status; no root read) and `variables.tf` (description only); rerun `make census-propose`.
+- [ ] **Step 6: Commit** `economics: count only carlos:deployment-tagged costs in tag mode`
+
+### Task 6: List what is not tagged, and the operator runbook
+
+**Risk/review:** UI and docs; whole-branch review.
+
+**Files:**
+- Create: `internal/console/costtags.go`, `internal/console/costtags_test.go`
+- Modify: `internal/console/economicsview.go` (three fields, filled only in tag mode), `templates/economics.html` (section after the bill table), `internal/console/economicspage_test.go`, `infra/modules/README.md` (new section after "Self-hosting from your own repo", `:162`; Markdown, outside census)
+
+**Interfaces:**
+- Consumes: `func (s *Server) loadInventory(ctx context.Context) (*infraview.Inventory, string)` (`infrapass.go:162`); Task 5's `CostScope.DeploymentTag`, `costDeploymentTagKey`.
+- Produces: `func untaggedCostResources(inv infraview.Inventory, deployment string) (untagged []infraview.Resource, unchecked map[string]int)`. Kinds whose tags the inventory reads and that cost money are `ec2:instance`, `ec2:volume`, `ec2:eip` and `infraview.KindOther`. One of these is untagged when `Tags[costDeploymentTagKey] != deployment`. Kinds whose tags the inventory does not read are `infraview.KindBucket`, `KindDNSZone` and `KindAlarm`; they are counted in `unchecked` by kind. Everything else is ignored (security groups, VPCs, subnets, IAM, records and certificates cost nothing themselves). Sort by kind, then ID. `EconomicsView.Untagged []infraview.Resource` (first 50), `UntaggedMore int`, `UntaggedUnchecked map[string]int`.
+
+- [ ] **Step 1: Write the failing tests.**
+ - `TestUntaggedCostResources`: an instance tagged `production` is excluded; one tagged `staging` is included; an untagged volume and an untagged `other` are included; a security group, a VPC and a role are ignored; 2 buckets, 1 zone and 3 alarms give `unchecked {"bucket":2,"dns_zone":1,"alarm":3}`; the order is stable.
+ - `TestEconomicsPageListsUntagged`: tag scope plus a seeded `infra/inventory.json` shows C9 and the rows; the zero or account scope shows no section and makes no inventory read (count `Get` calls on `infraview.InventoryKey` through `WrapReleases`).
+- [ ] **Step 2: Run** `go test ./internal/console -run 'TestUntaggedCostResources|TestEconomicsPageListsUntagged' -count=1`; expect FAIL.
+- [ ] **Step 3: Implement**, reading the inventory concurrently with the other reads in `buildEconomicsView` (`:439`), only when `DeploymentTag != ""`.
+- [ ] **Step 4: Write the runbook section** "Counting only CARLOS in the AWS bill" (C10, through copy review). Contents, in order:
+ 1. Choose: `CONSOLE_COST_ACCOUNT_CARLOS_ONLY=true` when the account runs nothing else, otherwise tag mode. With neither, the Billing pages hide costs.
+ 2. Tag mode: add `default_tags { tags = { "carlos:deployment" = "<name>" } }` to every `aws` provider block in the root, the default and each region alias. Read the plan: tag changes apply in place, but a root with `user_data` drift restarts boxes on a whole-root apply, so target. Group boxes are already tagged through their launch template.
+ 3. Tag what tofu does not make: tenant object-store buckets and steering health checks, with `aws resourcegroupstaggingapi tag-resources --resource-arn-list <arn>... --tags carlos:deployment=<name>`. The Economics page lists what is still untagged.
+ 4. Activate the tag from the paying (management) account: `aws ce update-cost-allocation-tags-status --cost-allocation-tags-status TagKey=carlos:deployment,Status=Active`. It can take up to a day to appear, and costs are tagged from activation onward. A month counts as tagged only if it starts on or after the activation date.
+ 5. Set `enable_cost_explorer = true` on the region-host that runs the console, which now also grants `ce:ListCostAllocationTags`. Then set `CONSOLE_COST_DEPLOYMENT_TAG=<name>` on the console and restart it.
+- [ ] **Step 5: Run Step 2 again**; expect PASS.
+- [ ] **Step 6: Commit** `economics: list resources the CARLOS tag misses`
+
+**Slice B ends here.** `make test`, `go build ./...`, whole-branch review, census verdict on #280.
+
+---
+
+## Census and cross-compile
+
+- In census scope: `internal/economics/bill.go` (Task 1), root `economics.go` (Task 4), `infra/modules/region-host/main.tf` and `variables.tf` (Task 5). None adds a root read. The host-side bill classifier (`internal/hostops/storage_classifier.go:145`) decodes into `economics.Bill` strictly, so a new binary admits the new keys with no `hostops` source change. A box running an older binary would refuse a bill carrying `basis`, which matters only where console writes pass through that classifier (claim mode, shelved). Roll boxes before the console, as usual (memory `roll-order-dev-first`). Brief a reviewer from the other family (Astra for a Claude author) with the card and record the verdict on #280.
+- Cross-compile: no OS-specific code. `cepull.go` uses the already-imported Cost Explorer client, and the CLI change is plain `flag`/`encoding/json`. `20-cross@5` covers darwin, windows and linux-arm64.
+- Not in census scope: `internal/console`, `cmd/console`, templates, Markdown.
+
+## Switch-on
+
+- **Slice A, Carloku (Paul named it, 2026-11-09).** After a release containing slice A rolls (dev first), set `CONSOLE_COST_ACCOUNT_CARLOS_ONLY=true` in the flagship console's environment, where `CONSOLE_DOMAIN_PROOF` lives, and restart the console. This is a production configuration change: ask Paul for the go at the roll. Check: `/fleet/economics` shows C2 for October and November, and October's figure equals the AWS Billing console's October total less tax (read-only check; profile per memory `aws-from-the-sandbox`). That is spec §7's "matches the CARLOS-only AWS figure" check.
+- **Dev:** no setting, so costs stay hidden. Dev has no Cost Explorer grant and a mixed account.
+- **Slice B:** merge when Paul names its first user (dev or Tito) and approves the scoped tagging and tag activation in that account.
+
+## Follow-ups (not in this plan)
+
+- Tag tenant object-store buckets (`internal/objstore/aws.go:294`) and steering health checks at creation when a tag is configured. This needs `s3:TagResource` and `route53:ChangeTagsForResource` on the console role, plus census review.
+- Default `CONSOLE_COST_DEPLOYMENT_TAG` from `CARLOS_MANAGED_FLEET_DEPLOYMENT` once 2b-2 merges.
+- AWS credits are inside `UnblendedCost` and lower the figure. If Paul wants gross cost, filter `RECORD_TYPE` later.