Repository navigation
Description
laws: the tree tells the truth about itself — three shapes it currently does not
Consolidates #621, #570 and #477. Three issues, filed a day apart by three sessions,
that all end in the same place: a structural law test on the pull-request gate, plus the
small change that makes the tree pass it. scripts/laws.sh finds a law by its import
(go/ast / go/parser) and runs the lot in about twenty seconds, so a law written that way
is on the gate the day it lands — which makes these one lane's afternoon rather than three
open issues.
Each child is closed with a pointer here and stays readable; every child's evidence and
acceptance is reproduced in full below.
1. #621 — one rune-safe clip helper, instead of the same two lines in every package
Cutting a string at a byte ceiling and backing off to a rune boundary is spelled locally
in package after package. It is the same two lines every time —
for cut > 0 && !utf8.RuneStart(s[cut]) { cut-- } — under a different name each time. PR
#607 added a copy with a comment naming its siblings; the comment is the tell that this
wants one home.
The issue listed eleven sites at dev 4c08cd3b. Re-counted at dev@95a0d0a9b it is
seventeen, and there are now TWO local re-spellings of the stdlib predicate, not one — so
the premise (it spreads) is confirmed by the interval:
| file:line | name |
|---|---|
internal/plan/graph.go:1252 |
clipRunes |
internal/search/search.go:631 |
clip |
internal/tui3/reveal.go:245 |
cutUTF8 |
internal/resident/revise.go:542 |
clipEventBytes |
internal/exec/trace.go:492 |
snip |
internal/furrow/furrow.go:504 |
(inline) |
internal/furrow/furrow.go:510 |
isRuneStart — a local re-spelling of utf8.RuneStart |
internal/session/loop.go:2717 |
(inline) |
internal/session/loop.go:2751 |
(inline) |
internal/session/loop.go:2761 |
utf8RuneStart — a local re-spelling of utf8.RuneStart |
internal/session/caption.go:210 |
walks forward |
internal/session/checkpoint.go:2425 |
walks forward |
internal/session/jobs.go:1370 |
walks forward, []byte |
internal/session/toolcompact.go:320, 331 |
both directions |
internal/session/toolhint.go:347 |
walks forward |
internal/session/tools_watch.go:811 |
walks forward |
internal/session/principal_audit.go:228 |
walks forward |
internal/session/prompt.go:359 |
backs off |
Ask: one shared home — a tiny leaf package with no aforge imports (e.g. internal/textcut),
or an existing leaf util package the tree already depends on. It needs both directions
(back off a cut index, walk a start index forward) and both string and []byte. Each
site keeps its own name and its own decoration (ellipsis, TrimSpace, byte count, ⏎
folding) and calls into the shared boundary walk for the two lines that are identical. Delete
session.utf8RuneStart and furrow.isRuneStart in favour of utf8.RuneStart.
Then the law: walk the tree and fail on a !utf8.RuneStart( loop, or an equivalent
&0xC0 != 0x80, outside the shared package.
Acceptance: not a behaviour change — all existing tests green, and the new law goes red
when a local copy is re-introduced in any package.
2. #570 — a comment that states a law is checked against the code beside it
The law: this codebase comments heavily and deliberately, and an ALL-CAPS sentence in a
comment is how a law is stated (CLAUDE.md, Design laws the codebase enforces). Today
nothing reads those sentences. go build, go test and every structural law test look
at code, and prose can assert anything over code that does the opposite.
What happened. In the aforge-as-worker trial (bench/worker-trial/REPORT.md on
trial/aforge-as-worker, ranking at a6f21294), three of the four false claims the worker
produced were comments asserting a law over code that did not implement it, and nothing
caught them:
- shaped: a re-ask names the rule the answer broke and repairs a quotation without asking the whole verdict again #515 run 1 — a comment reading
THE RULE IT NAMES IS THE CONSTANT, never a duplicated prose stringaboveprose.go:115, which builds"The rule your answer broke: " + string(RepairReshaped).RepairReshapedisRepairKind = "reshaped"(prose.go:36), a
journal kind, not a rule. The changelog entry repeated the claim. Comment, changelog
and code all agreed with each other and none agreed with what the code does. - shaped: a re-ask names the rule the answer broke and repairs a quotation without asking the whole verdict again #515 run 3 — a comment citing
quoteDestination("the tag thatquoteDestination
carries"), a symbol that exists nowhere in the tree (grep -rn quoteDestinationis
empty). - tasks: the list is ordered by which conversation was touched last, not by the work's own facts #520 — an itemised "five items green" claim over a package (
internal/tui3) the run
had never executed; two of the five were red.
The fourth false claim (#550) is prose in a finish message — the same shape, one layer up.
#537 is the mirror image on the gate's side: evidence invented in prose over a tree that had
not changed.
Fix shape — a structural law test under internal/, in the house style
(internal/guard/sweep_test.go, internal/guard/lockdefer_test.go,
internal/thread/thread_test.go are the models):
- Every ALL-CAPS law comment (a comment sentence whose leading words are capitals) must
either name the test that pins it — aTest…identifier that exists in the same
package or is resolvable in the tree — or every identifier it names in backticks or
CamelCase must exist in the same package (constant, function, type). A law comment that
names nothing checkable is reported byfile:linewith the sentence, the way the goroutine
sweep reports its sites. - A comment mentioning a symbol that does not exist anywhere is a failure on its own,
regardless of case — that is what catchesquoteDestination. - The itemised-green shape is out of reach for a comment sweep and belongs to leaf: done without the check the brief named, and no line saying none was run #550's law.
Keep it small and low-complexity: one walk with go/parser in parser.ParseComments mode,
one regexp for the law shape, one symbol table per package from the same parse. Allowlist
by file:line, never by pattern, and keep it empty at landing.
3. #477 — the per-leaf contract is read by every leaf and written by nobody
jobPlans.putContract (cmd/aforge/chat.go:4144) is the only writer into
jobPlans.contracts, and nothing calls it. Re-verified at dev@95a0d0a9b: still no
caller — the only occurrence of the name in the tree is its own definition and doc comment.
staticcheck -checks U1000 -tests=false ./cmd/aforge/ # names jobPlans.putContract unused
Its reader is live: takeContract → leafContract → the Contract field handed to
every leaf (grep the names, line numbers drift). So on the aforge do path every leaf asks
for its contract and can only ever receive "".
Either the per-leaf working method — the contract the planner writes for a one-leaf job, as
the surrounding prose describes it — is a feature that silently stopped being written when
its writer's caller went, in which case leaves have been running without the working method
the design says they get; or the map and its reader are a leftover and should go together.
This was not folded into #469's dead-road sweep because deciding which is a judgment about
a live behaviour, not dead code.
Acceptance — one of the two, and it is the owner's call:
- Written: the contract is written on the
dopath at the seam where the plan is
settled, and a real-model run (flash) shows a leaf receiving a non-empty contract in its
journal; a test pins the writer to the reader. - Removed:
contracts,putContract,takeContract,leafContractand the leaf's
Contractfield go together, with any manual claim about a per-leaf working method
removed in the same PR (the manual law), andstaticcheck -checks U1000 -tests=false ./cmd/aforge/no longer names them.
Note: this is the same shape as #476, which was closed 2026-09-10 — its three dead dials
turned out to have been decided already (EnsurePersistedAPIKey deleted, BriefAfter wired
to a settings row, the doctor's watchdog live on the leaf path). #477 is the one that was
not decided, because its reader is on the live path.
Acceptance for this issue
- One shared rune-boundary helper; seventeen local copies and two local re-spellings of
utf8.RuneStartgone; a law that goes red when a copy comes back. - A comment law under
internal/, on the gate by itsgo/parserimport, empty allowlist at
landing, reporting byfile:line. - do: the per-leaf contract is read by every leaf and written by nobody — jobPlans.putContract has no caller on the live path #477 decided either way by the owner, and the chosen half landed with the manual
changed in the same commit if the claim moves. make test-lawsstays inside its ~20 second budget with all three added — a law that
decides slowly is a law that gets skipped.
Drafted with CodeAF · reviewed and owned by the author
Activity
AbirAbbas commentedon Sep 16, 2026
Closing as not planned. The three remaining local rune-clip loops (
internal/search,internal/furrow,internal/plan/graph.go) and the unwrittencontractsregistry incmd/codeaf/chat.goare real, but they are hygiene rather than behaviour, and #621 already took the ten packages that mattered. A structural law for a helper nobody is asked to reuse is a gate for its own sake. Delete the dead registry when next in that file.