C2 plan: re-base the root-read census on code root runs
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 file changed,
+92
−0
docs/superpowers/plans/2026-10-26-census-rebase-c2.md+92 −0
diff --git a/docs/superpowers/plans/2026-10-26-census-rebase-c2.md b/docs/superpowers/plans/2026-10-26-census-rebase-c2.md| new file mode 100644 |
| index 000000000..7f67d2cd5 |
| --- /dev/null |
| +++ b/docs/superpowers/plans/2026-10-26-census-rebase-c2.md |
| @@ -0,0 +1,92 @@ |
| +# Census re-base (C2) 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:** The root-read census covers only code root runs. Agent-only, console-only and template edits stop needing census cards. The 117-overlay chain is archived behind one new base with a new seal. |
| + |
| +**Architecture:** J4's reference-graph builder (`inputPlatformCallers`, go/packages) is split into a builder and a walk. The census walks the linux graph from root's entry points instead of `main.go:main`, and filters the existing scanner's output to what it reaches. Envelopes hash the reachable declarations of a directory, not its whole files. A unit that leaves scope is a reviewer approval, like a deletion. Test code only; no production change. |
| + |
| +**Tech Stack:** Go 1.26, `golang.org/x/tools/go/packages`, `go/ast`, `go/types`. |
| + |
| +**Spec:** Paul's ruling 2 on amadan #280 (2026-10-25), his go on #404 (2026-10-26), `docs/superpowers/notes/claims-inventory.md` §5 option 2 on `design-live-moves-ha`. |
| + |
| +## Global Constraints |
| + |
| +- Test code, testdata and AGENTS.md only. No production code changes, no claim-code deletion. |
| +- Claim code stays in the tree and must not break the re-base. |
| +- Root code keeps the independent reviewer; decisions (`new`, `reads`, `quiet`, `other`) stay Paul's. |
| +- R0's `removed` class and `@coverage <dir> -` keep working unchanged. |
| +- No pattern deletes: `git mv` and `git rm` take exact paths. |
| +- Local tests: `internal/provision` only, `nice -n 19`, serial; builds for linux, darwin, windows; vet. |
| +- AGENTS.md: short sentences, no em dashes. |
| + |
| +## Design decisions (settled here) |
| + |
| +1. **Entry points.** Read from `internal/host/units/*.service`: a unit with no `User=` and no `DynamicUser=yes` runs as root. Each `/opt/carlos/carlos[.prev] <verb> [<sub>]` in its `Exec*=` lines (inline `sh -c` included) names a verb. Today: `adopt`, `instance-control`, `system` with `guard-exec`, `floor-allows-prev`, `apply`, `join`. Added by hand, with the reason in the code: the boot-time verbs user_data runs as root (`bootstrap`, `system install-channel`, `system host-env`). Hand-run claim verbs (`system files`, `guard-arm`, `journal-migrate`) are out: nothing runs them automatically. |
| +2. **Seeds.** `main.go:main` and `system.go:runSystem` are dispatchers. Walking one follows everything outside its verb switch (`switch cmd`, `switch verb`) and only the case clauses of root verbs. A root verb with no case label fails the census. Also seeded: every `init` and every function called in a package-level `var` initializer, in packages linked into the carlos binary. |
| +3. **Graph.** J4's graph for GOOS=linux (root runs on Linux only), unchanged: identifier references, interface dispatch to every implementer, `json.Unmarshal` to `UnmarshalJSON`, `//go:embed` to the embedded files. One rule on top for the root walk: a reached type also reaches its methods the standard library calls by name (`Error`, `String`, `Format`, `MarshalJSON`, `Read`, `Write`, `Close`, `ServeHTTP` and so on). No second graph. |
| +4. **Scope.** A Go unit is in scope when its declaration is reached. An external (unit file, shell, `.tf`, `.tftpl`, assembly) is in scope when a reached declaration embeds it, when it is under `infra/` (user_data and units run as root at boot; IAM decides who writes what root reads; rows say `root-input`), or when it sits in a directory holding a reached declaration. `scripts/` and `internal/sim` shell is out: developer tools. |
| +5. **Envelopes.** One per directory holding an in-scope unit or reached declaration. It hashes the reached declarations (doc comment included) and the in-scope externals of that directory, plus `go.mod`/`go.sum` for `.`. Whole-file envelopes would keep `internal/host` (agent and root) and `internal/console` (an `Error` method is reached) in the census, which the ruling takes out. |
| +6. **Leaving scope.** A classified unit still declared but no longer reached is class `left`, an approval: the reviewer confirms root's call went on the card, not behind reflection or a function value. The overlay writes `@remove` and, for a frozen declaration, `@removed ... census-ruling-<NAME>;left;basis=...`. That holds while the unit stays out of scope; a later hand row re-admits it. A directory leaving scope gets `@coverage <dir> left`. |
| +7. **Known loss.** Root reading a file the agent writes stays covered: the root read is in scope. What the agent writes there is out of the census and is the reviewer's job on root-facing paths. Seeding from root readers' input paths would need a data-flow graph; not built. |
| +8. **Migration.** The old base, overlays and manifest move to `testdata/archive/` (`git mv`, exact paths). They stay because J4's inventory (27 overlays to `activation-tools`) and the migration test read them. The new base `testdata/census-base.tsv` is the archived effective inventory filtered to scope: rows and `@legacy` fingerprints byte for byte, `@fields` as is, envelopes recomputed under rule 5. No `@removed` rows carry over: a deleted unit that came back and reads would be `new`. `testdata/plan14-root-reads-chain.tsv` starts empty. A test proves every base row equals its archived row. |
| +9. **J4.** Its inventory stays the archived 27 overlays. A surviving row in scope keeps the caller and witness checks; a row out of scope is reported (`left-scope`) and not checked. Live families come from the new chain. |
| + |
| +## Review Focus |
| + |
| +- A root unit whose ExecStart moves to a new verb: the census must fail, not lose the verb (Task 1 test `TestCensusScopeUnknownRootVerbFails`). |
| +- An agent-side edit that adds a method named like one root calls through an interface: the unit enters scope as `new` (Task 5 proof notes it in AGENTS.md). |
| +- A unit leaving and re-entering scope unchanged must not be blocked forever (Task 2 `TestCensusLeftUnitReadmitted`). |
| +- A frozen unit that leaves scope by a call hidden in a function value built outside root code: shows as `left`, a card, never silent (Task 2). |
| +- Main moving under the branch: merge, move main's new overlays into the archive, regenerate (Task 3 generator refuses a non-empty new manifest). |
| + |
| +--- |
| + |
| +### Task 1: Root scope from the units |
| + |
| +**Files:** |
| +- Create: `internal/provision/census_scope_test.go` |
| +- Modify: `internal/provision/plan14_input_inventory_test.go` (`inputPlatformCallers` uses the builder; J4 semantics unchanged) |
| + |
| +**Interfaces:** |
| +- Produces: `censusGraph(root, platform string) (*refGraph, error)` (cached per root and platform); `rootVerbs(root string) (map[string]map[string]bool, error)` (dispatcher key to allowed labels); `rootScopeOf(root string) (rootScope, error)` with `rootScope{Reached map[string]string; Externals map[string]bool; Dirs map[string]bool}`. |
| + |
| +- [ ] Tests on a fixture module: verbs from root units only (`User=carlos` and `DynamicUser=yes` excluded, `sh -c` parsed); a non-root case of a dispatcher is not reached; a root case is; an `init` and a var-initializer call are seeds; `Error` of a reached type is reached; an embedded unit file is in scope; `TestCensusScopeUnknownRootVerbFails`. |
| +- [ ] Implement; J4's existing tests pass unchanged. |
| +- [ ] Commit. |
| + |
| +### Task 2: Scoped scan, decl-level envelopes, class `left` |
| + |
| +**Files:** |
| +- Modify: `internal/provision/plan14_root_reads_test.go` (`rootReadScan` gains `Sources`, `Outside`; `rootReadScope`; `@coverage <dir> left`; left removals in `checkRootReadDeclarations`) |
| +- Modify: `internal/provision/census_propose_test.go` (`censusLeft`, card section and review question) |
| +- Test: `internal/provision/census_scope_test.go` |
| + |
| +**Interfaces:** |
| +- Produces: `rootReadScope(raw rootReadScan, s rootScope) rootReadScan`; `rootReadScoped(root string) (rootReadScan, error)`; class `censusLeft = "left"`; `censusLeftMark = "left"`. |
| + |
| +- [ ] Tests: `TestCensusLeftUnitIsAnApproval`, `TestCensusLeftEnvelope`, `TestCensusLeftUnitReadmitted`, `TestCensusLeftRemovalBlocksReentry`; R0 tests pass unchanged. |
| +- [ ] Implement, commit. |
| + |
| +### Task 3: Archive and new base |
| + |
| +**Files:** |
| +- Move: every `internal/provision/testdata/plan14-root-reads*.tsv` to `testdata/archive/` by exact path. |
| +- Create: `internal/provision/census_rebase_test.go` (archived chain replay, generator behind `CARLOS_CENSUS_REBASE=1`, `TestCensusRebaseCarriesDispositions`), `testdata/census-base.tsv`, empty `testdata/plan14-root-reads-chain.tsv`. |
| +- Modify: `plan14_root_reads_test.go` (`rootReadChainBefore` loads the new base under `rootReadBaseSeal`), `plan14_legacy_identity_test.go`, `plan14_p3_census_test.go` (archive paths). |
| + |
| +- [ ] Write the migration test, generate the base, `TestPlan14RootReadCensus` green, commit. |
| + |
| +### Task 4: J4 narrowed |
| + |
| +- [ ] Test: an out-of-scope surviving row with no caller is reported, not failed; an in-scope one still fails. Implement in `TestPlan14RootInputInventoryCoverage`; commit. |
| + |
| +### Task 5: Proofs through the real scanner |
| + |
| +**Files:** Create `internal/provision/census_rebase_proof_test.go`. |
| + |
| +- [ ] (a) console-only function and template edits pass; (b) a reachable unit's reads changing fails, a new reachable unit with reads fails; (c) a read moved from an out-of-scope helper into a root path fails; (d) a deletion passes through R0's proposal. Commit. |
| + |
| +### Task 6: AGENTS.md, runtime, CI |
| + |
| +- [ ] Rewrite "The census" for the new scope, listing today's in-scope directories; measure local runtime before and after; push; read CI. |