census: retired envelopes (@coverage <dir> -) for a deleted directory
An overlay may retire a pinned envelope with "@coverage <dir> -". The scan now lists every directory it walks, and the census fails while a retired envelope's directory is still in the tree, test files only or not. A later pin ends the retirement. Plan: claims cleanup R0, task 1.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
4 files changed,
+197
−3
docs/superpowers/plans/2026-10-25-claims-cleanup-r0.md+72 −0internal/provision/census_propose_test.go+1 −0internal/provision/census_removal_test.go+86 −0internal/provision/plan14_root_reads_test.go+38 −3
diff --git a/docs/superpowers/plans/2026-10-25-claims-cleanup-r0.md b/docs/superpowers/plans/2026-10-25-claims-cleanup-r0.md| new file mode 100644 |
| index 000000000..6d5fe8efd |
| --- /dev/null |
| +++ b/docs/superpowers/plans/2026-10-25-claims-cleanup-r0.md |
| @@ -0,0 +1,72 @@ |
| +# Claims cleanup R0: census removal plumbing |
| + |
| +> **For agentic workers:** REQUIRED SUB-SKILL: Use superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (`- [ ]`) syntax for tracking. |
| + |
| +**Goal:** A deleted unit, frozen declaration or package directory passes the census with an overlay `make census-propose` writes and a reviewer's approval; changed and new reads still fail. |
| + |
| +**Architecture:** Test code only, all in `internal/provision`. The scan records every directory it walks, the inventory learns a retired envelope (`@coverage <dir> -`), census-propose treats an absent unit or directory as the approval class `removed`, and J4 drops a row the full chain removed once its declaration is gone. |
| + |
| +**Tech Stack:** Go tests in `internal/provision`; the TSV census chain under `internal/provision/testdata`. |
| + |
| +**Spec:** Paul's ruling 1 on amadan #280 (2026-10-25); `docs/superpowers/plans/2026-10-25-claims-cleanup.md` row R0; `docs/superpowers/notes/claims-inventory.md` §4 R0 and §5 (on design-live-moves-ha). |
| + |
| +## Global Constraints |
| + |
| +- Production code unchanged. Only `*_test.go`, testdata and AGENTS.md. |
| +- The seal chain stays append-only: no existing overlay or seal is edited. |
| +- `new`, `reads` and `other` stay decisions census-propose refuses. |
| +- Run census tests under `nice -n 19`, serially, only `internal/provision`. |
| +- AGENTS.md prose: short sentences, no em dashes. |
| + |
| +## Review Focus |
| + |
| +- A unit still declared but reading nothing is not a deletion: it stays a decision (new class `quiet`), never `removed`. |
| +- A directory that lost its scanned files but still exists (tests or testdata left) is not retired: `quiet`, a decision. |
| +- A retired envelope whose directory comes back fails the census, even if the directory holds only test files. |
| +- A generated `@removed` row must not tolerate the declaration coming back without reads (the zddr3 H3 rule would): it requires absence. |
| +- J4 must not stop checking a row the chain removed while its declaration is still in the tree. |
| + |
| +--- |
| + |
| +### Task 1: Retired envelopes |
| + |
| +**Files:** Modify `internal/provision/plan14_root_reads_test.go` (`rootReadScan`, `rootReadProduction`, `rootReadInventory`, `loadRootReadInventory`, `compareRootReads`); `census_propose_test.go` (`cloneRootReadInventory`). Test: `plan14_root_reads_test.go`. |
| + |
| +**Interfaces:** |
| +- Produces: `rootReadScan.Dirs map[string]bool` (every walked directory, slash-relative, "." for the root); `rootReadInventory.Retired map[string]bool`; directive `@coverage<TAB><dir><TAB>-` (delta only; refused for an envelope not pinned); compare error `retired root source envelope still present <dir>` when `Dirs == nil || Dirs[dir]`. |
| + |
| +- [ ] Test `TestPlan14RetiredEnvelope`: an overlay `@coverage internal/gone -` loaded on an inventory pinning `internal/gone` leaves no discrepancy for a scan without that directory; the same scan with `Dirs["internal/gone"]` fails with "retired root source envelope still present"; the directive in a base file, or for an unpinned directory, fails to load; a later `@coverage internal/gone <hash>` clears the retirement. |
| +- [ ] Run it, see it fail; implement; run it, see it pass. |
| +- [ ] Commit; advance the amadan task. |
| + |
| +### Task 2: `removed` as an approval in census-propose |
| + |
| +**Files:** Modify `internal/provision/census_propose_test.go`, `plan14_root_reads_test.go` (`checkRootReadDeclarations`). Test: `census_propose_internal_test.go`. |
| + |
| +**Interfaces:** |
| +- Consumes: Task 1's `Dirs`, `Retired`, the `-` directive. |
| +- Produces: class `censusQuiet = "quiet"` (a decision); `censusRemoved` approvable; `censusChange.Absent`; `rootReadAbsentRemoval(removal string) bool`, true for a removal whose basis is `census-ruling-<name>;absent;...`; such a removal fails while the declaration exists, unlike the H3 retire rule. |
| +- Overlay rows for a removed unit: `@remove<TAB>file<TAB>unit` when classified; for a frozen unit not already removed, `@removed<TAB>file<TAB>unit<TAB><owner><TAB>census-ruling-<NAME>;absent;basis=<claim or "deleted: declaration and sites absent from the tree">`, owner the row's task when it is a kept family, else `H3`. A retired directory: `@coverage<TAB>dir<TAB>-`. Claims for removed units are optional. |
| + |
| +- [ ] Tests: `TestCensusClassifiesARemovedUnit` keeps `removed` and now also wants `Absent`; `TestCensusClassifiesAQuietUnit` (declared, no reads: `quiet`); `TestCensusProposalRetiresADeletedPackage` (fixture deletes a legacy frozen unit, an authority unit and their directory: the overlay loads, leaves the census clean, keeps the seal, and the card lists both units, their dispositions and the retired envelope); `TestCensusProposalRefusesADeletionWithAChangedRead` (same deletion plus a `reads` change or a new unit elsewhere: refused as a decision); `TestCensusAbsentRemovalNeedsAbsence` (after the generated overlay, the unit's declaration back without reads fails; back with reads fails; the directory back fails). |
| +- [ ] Run, see them fail; implement; run, see them pass, with the existing census-propose tests. |
| +- [ ] Commit; advance the amadan task. |
| + |
| +### Task 3: J4 retires a family's rows with its witnesses |
| + |
| +**Files:** Modify `internal/provision/plan14_input_inventory_test.go`. Test: same file. |
| + |
| +**Interfaces:** |
| +- Produces: `inputRetired(inv, full rootReadInventory, declared map[string]bool, key string) bool`: true when the full chain no longer carries the row and the tree declares no such unit. `TestPlan14RootInputInventoryCoverage` skips retired rows. `rootReadDeclared(root string) (map[string]bool, error)` names every declaration as the census does, without type-checking. |
| + |
| +- [ ] Test `TestPlan14J4RetiresAFamily`: family A's every row retired and its witnesses gone: no failure; one surviving A row and a witness gone: fails "missing"; a surviving row with no production caller still fails; a row removed from the chain whose declaration is still in the tree is still checked. |
| +- [ ] Run, see it fail; implement; run it and the J4 coverage test. |
| +- [ ] Commit; advance the amadan task. |
| + |
| +### Task 4: AGENTS.md, the experiment, and the gate |
| + |
| +**Files:** Modify `AGENTS.md` ("The census"). |
| + |
| +- [ ] Describe `removed` as an approval class, `quiet` as a decision, and the envelope retirement. |
| +- [ ] Experiment (not committed): delete `internal/sim/hostlife`, run census-propose with an empty CLAIMS file, run `TestPlan14RootReadCensus`, restore with `git checkout -- internal/sim/hostlife` plus removing the generated files by exact path, confirm `git status` is clean. |
| +- [ ] `go vet ./internal/provision/`, the census and census-propose tests, `GOOS=darwin` and `GOOS=windows go build ./...`; push; `amadan ci status carlos/platform -branch claims-cleanup-r0`. |
diff --git a/internal/provision/census_propose_test.go b/internal/provision/census_propose_test.go| index 415fa5501..3edcdadfe 100644 |
| --- a/internal/provision/census_propose_test.go |
| +++ b/internal/provision/census_propose_test.go |
| @@ -415,6 +415,7 @@ func cloneRootReadInventory(inv rootReadInventory) rootReadInventory { |
| out.Frozen = cloneMap(inv.Frozen) |
| out.Removed = cloneMap(inv.Removed) |
| out.Coverage = cloneMap(inv.Coverage) |
| + out.Retired = cloneMap(inv.Retired) |
| out.Legacy = cloneMap(inv.Legacy) |
| return out |
| } |
diff --git a/internal/provision/census_removal_test.go b/internal/provision/census_removal_test.go| new file mode 100644 |
| index 000000000..cb463d1f0 |
| --- /dev/null |
| +++ b/internal/provision/census_removal_test.go |
| @@ -0,0 +1,86 @@ |
| +package provision |
| + |
| +// Census removals (claims cleanup R0; Paul's ruling 1 on #280, 2026-10-25): |
| +// a removed unit, a retired frozen declaration and a deleted directory's |
| +// envelope are approvals when the scan proves them absent, since a deletion |
| +// cannot add a read. These tests pin the retired envelope, the generated |
| +// removal rows and what still fails. |
| + |
| +import ( |
| + "os" |
| + "path/filepath" |
| + "strings" |
| + "testing" |
| +) |
| + |
| +func writeOverlay(t *testing.T, body string) string { |
| + t.Helper() |
| + path := filepath.Join(t.TempDir(), "overlay.tsv") |
| + if err := os.WriteFile(path, []byte(body), 0o644); err != nil { |
| + t.Fatal(err) |
| + } |
| + return path |
| +} |
| + |
| +// @coverage <dir> - retires the envelope of a directory that is gone. It |
| +// is refused while the directory is still in the tree, even holding only |
| +// tests, and a later pin brings the envelope back. |
| +func TestPlan14RetiredEnvelope(t *testing.T) { |
| + pinned := func() rootReadInventory { |
| + return rootReadInventory{Entries: map[string]classifiedRootRead{}, Coverage: map[string]string{"internal/gone": strings.Repeat("c", 64), "internal/kept": strings.Repeat("d", 64)}, Fields: ""} |
| + } |
| + scan := rootReadScan{Coverage: map[string]string{"internal/kept": strings.Repeat("d", 64)}, Dirs: map[string]bool{".": true, "internal": true, "internal/kept": true}} |
| + |
| + inv := pinned() |
| + if errs := compareRootReads(scan, inv); len(errs) != 1 || !strings.Contains(errs[0], "stale root source envelope internal/gone") { |
| + t.Fatalf("before the retirement: %v", errs) |
| + } |
| + if err := loadRootReadInventory(writeOverlay(t, "@coverage\tinternal/gone\t-\n"), &inv, true); err != nil { |
| + t.Fatal(err) |
| + } |
| + if errs := compareRootReads(scan, inv); len(errs) != 0 { |
| + t.Fatalf("retired envelope of a deleted directory: %v", errs) |
| + } |
| + |
| + // The directory is still there (only tests left, say): refused. |
| + present := scan |
| + present.Dirs = map[string]bool{".": true, "internal": true, "internal/kept": true, "internal/gone": true} |
| + if errs := compareRootReads(present, inv); len(errs) != 1 || errs[0] != "retired root source envelope still present internal/gone" { |
| + t.Fatalf("retired envelope of a present directory: %v", errs) |
| + } |
| + // A scan that walked no directories proves nothing. |
| + unwalked := scan |
| + unwalked.Dirs = nil |
| + if errs := compareRootReads(unwalked, inv); len(errs) != 1 { |
| + t.Fatalf("retired envelope with no directory list: %v", errs) |
| + } |
| + // The directory back with source: changed, and still retired. |
| + back := present |
| + back.Coverage = map[string]string{"internal/kept": strings.Repeat("d", 64), "internal/gone": strings.Repeat("e", 64)} |
| + if errs := compareRootReads(back, inv); len(errs) != 2 { |
| + t.Fatalf("retired directory back with source: %v", errs) |
| + } |
| + // A later pin ends the retirement. |
| + if err := loadRootReadInventory(writeOverlay(t, "@coverage\tinternal/gone\t"+strings.Repeat("e", 64)+"\n"), &inv, true); err != nil { |
| + t.Fatal(err) |
| + } |
| + if errs := compareRootReads(back, inv); len(errs) != 0 { |
| + t.Fatalf("re-pinned envelope: %v", errs) |
| + } |
| + |
| + for name, tc := range map[string]struct { |
| + body string |
| + delta bool |
| + }{ |
| + "in the base": {"@coverage\tinternal/gone\t-\n", false}, |
| + "of an unpinned dir": {"@coverage\tinternal/never\t-\n", true}, |
| + "twice in one overlay": {"@coverage\tinternal/gone\t-\n@coverage\tinternal/gone\t-\n", true}, |
| + } { |
| + t.Run(name, func(t *testing.T) { |
| + inv := pinned() |
| + if err := loadRootReadInventory(writeOverlay(t, tc.body), &inv, tc.delta); err == nil { |
| + t.Fatal("retirement loaded") |
| + } |
| + }) |
| + } |
| +} |
diff --git a/internal/provision/plan14_root_reads_test.go b/internal/provision/plan14_root_reads_test.go| index 72cc46997..0d4748a8e 100644 |
| --- a/internal/provision/plan14_root_reads_test.go |
| +++ b/internal/provision/plan14_root_reads_test.go |
| @@ -28,6 +28,10 @@ type rootReadScan struct { |
| Entries []rootReadEntry |
| Coverage map[string]string |
| Fields []string |
| + // Dirs is every directory the scan walked, holding scanned source or |
| + // not: a retired envelope (@coverage <dir> -) is refused while its |
| + // directory is here. |
| + Dirs map[string]bool |
| } |
| // Match names conservatively, including method values, aliases and writes. |
| @@ -159,7 +163,7 @@ func rootReadTyped(root string) (map[string]string, map[string]bool, error) { |
| } |
| func rootReadProduction(root string) (rootReadScan, error) { |
| - out := rootReadScan{Coverage: map[string]string{}, Declarations: map[string]string{}} |
| + out := rootReadScan{Coverage: map[string]string{}, Declarations: map[string]string{}, Dirs: map[string]bool{}} |
| typed, active, err := rootReadTyped(root) |
| if err != nil { |
| return out, err |
| @@ -188,6 +192,11 @@ func rootReadProduction(root string) (rootReadScan, error) { |
| if p != root && (strings.HasPrefix(d.Name(), ".") || strings.HasPrefix(d.Name(), "_") || d.Name() == "testdata") { |
| return filepath.SkipDir |
| } |
| + rel, e := filepath.Rel(root, p) |
| + if e != nil { |
| + return e |
| + } |
| + out.Dirs[filepath.ToSlash(rel)] = true |
| return nil |
| } |
| if !strings.HasSuffix(p, ".go") || strings.HasSuffix(p, "_test.go") { |
| @@ -392,8 +401,11 @@ type rootReadInventory struct { |
| Removed map[string]string |
| Entries map[string]classifiedRootRead |
| Coverage map[string]string |
| - Fields string |
| - Legacy map[string]bool |
| + // Retired is every envelope a "@coverage <dir> -" retired: its |
| + // directory must stay out of the tree. |
| + Retired map[string]bool |
| + Fields string |
| + Legacy map[string]bool |
| } |
| func loadRootReadInventory(path string, inv *rootReadInventory, delta bool) error { |
| @@ -461,7 +473,24 @@ func loadRootReadInventory(path string, inv *rootReadInventory, delta bool) erro |
| return fmt.Errorf("%s:%d: coverage", path, i+1) |
| } |
| key = "@coverage:" + col[1] |
| + if col[2] == "-" { |
| + // A retired envelope (claims cleanup R0): the directory is |
| + // gone, which compareRootReads checks against the scan. |
| + if !delta { |
| + return fmt.Errorf("%s:%d: an envelope is retired only by an overlay", path, i+1) |
| + } |
| + if _, ok := inv.Coverage[col[1]]; !ok { |
| + return fmt.Errorf("%s:%d: retirement of unknown envelope %s", path, i+1, col[1]) |
| + } |
| + delete(inv.Coverage, col[1]) |
| + if inv.Retired == nil { |
| + inv.Retired = map[string]bool{} |
| + } |
| + inv.Retired[col[1]] = true |
| + break |
| + } |
| inv.Coverage[col[1]] = col[2] |
| + delete(inv.Retired, col[1]) |
| case "@remove": |
| if !delta || len(col) != 3 { |
| return fmt.Errorf("%s:%d: removal", path, i+1) |
| @@ -577,6 +606,12 @@ func compareRootReads(got rootReadScan, want rootReadInventory) []string { |
| errs = append(errs, "stale root source envelope "+dir) |
| } |
| } |
| + // A scan that lists no directories cannot prove one gone. |
| + for dir := range want.Retired { |
| + if got.Dirs == nil || got.Dirs[dir] { |
| + errs = append(errs, "retired root source envelope still present "+dir) |
| + } |
| + } |
| if strings.Join(got.Fields, ",") != want.Fields { |
| errs = append(errs, "changed registry schema") |
| } |