beads/cmd/bd/list_roles.go
CI Bot 67d38d2620 Trim this series' comments toward the repo's own density
Ten agents over 216 files, one directory-balanced group each, working to a
rubric that named what to cut (duplication narration, restatement of the next
line, the governing rule echoed in every command file, throat-clearing) and
what to keep (traps, invariants, security, tracker ids, behaviour changes, and
the "why a naive simplification destroys this assertion" rationale).

Net 1,523 lines. Density against this repo's own per-directory norm on main:

  cmd/bd              33.6% -> 27.3%   (main 10.7%)
  internal/storage    26.1% -> 23.1%   (main 14.1%)
  backend/conformance 34.0% -> 29.6%   (main 22.8%)
  internal/httpapi    30.9% -> 27.8%   (main 30.6%, now below)
  overall             34.7% -> 31.6%

Every agent landed at 18-25% rather than the 30% asked for, and every one gave
the same reason independently: what remained was on the keep list. Ten separate
judgements agreeing is the most useful result here — the prose is dense, but it
is mostly load-bearing, and the shortfall is the honest answer rather than a
failure to try.

TWO REVERTS, both to protect something worth more than the lines.

issueops/ is back to its pre-trim state, giving up 610 lines. The conformance
contracts cite the leaf docs BY LINE — "pins treewalker.go:52-66" — 155 times.
Trimming the cited files silently repointed those at whatever text moved into
those numbers, across agent boundaries so no agent could see it. A semantic
remapper recovered 141 of them, but 23 needed judgement and several landed on
struct fields. The leaf docs are the spec the contracts are written against;
they are the one place in this change where dense prose IS the deliverable, and
keeping them stable is worth more than the 610 lines. tree_walker_contract.go
and version_reconciler_contract.go went back for the same reason: an agent had
deleted a paragraph containing a citation, so positional restoration could not
align them.

After the reverts, exactly 5 citations point into a still-trimmed file and 2 of
those are weak — both in cmd/bd/config_guard_test.go, which this series never
touched and whose citations were already wrong on main (init.go:361 pointed at
a closing brace; the guard it names is at init.go:1499).

VERIFICATION. A guard strips every comment and all whitespace from each of the
193 modified files at HEAD and in the worktree and requires the two to be
byte-identical, so a code change cannot hide in a comment diff. It handles `//`
inside string and raw-string literals, and was tested against a deliberate code
change before being trusted. gofmt clean, go build, go vet, golangci-lint 0
issues, and the two AST-based tests that PARSE trimmed files — the timed
provider binding pin over claim.go and the serve database-source gate over
serve.go — both pass.

One real defect found while trimming: checkDatabaseSource's doc block ran into
`// sourceRoles is ...` with no blank line, so godoc attached thirty-one lines
of the wrong prose to func sourceRoles and left checkDatabaseSource
undocumented. Fixed by separating them.
2026-08-06 08:06:59 +00:00

91 lines
3.2 KiB
Go

package main
import (
"context"
"errors"
"fmt"
"github.com/steveyegge/beads/internal/storage"
"github.com/steveyegge/beads/internal/storage/uow"
"github.com/steveyegge/beads/internal/types"
"github.com/steveyegge/beads/issueops"
)
// The two seams `bd list` reaches its roles through, and the one projection its
// text renderings need. Both routes call these, so the page and its decoration
// come from one statement rather than two that happen to agree.
// listPageIssues projects a counted page onto the plain rows the text
// renderings take, keeping the page's ORDER. A nil row is dropped rather than
// dereferenced: the role promises none for a successful call, and a listing is
// not where a broken implementation should become a panic.
func listPageIssues(page issueops.IssuePage) ([]*types.Issue, bool) {
issues := make([]*types.Issue, 0, len(page.Items))
for _, row := range page.Items {
if row == nil || row.Issue == nil {
continue
}
issues = append(issues, row.Issue)
}
return issues, page.HasMore
}
// listBlocking is the decoration keyed the way the two formatters read it.
//
// The role answers with a SLICE in request order, because that is what an HTTP
// body needs. The formatters index by id, so the three maps are rebuilt at the
// front door, once per route, rather than in a role that would then have to
// promise three separate containers can never disagree.
type listBlocking struct {
blockedBy map[string][]string
blocks map[string][]string
parent map[string]string
}
func newListBlocking(result issueops.BlockingResult) listBlocking {
out := listBlocking{
blockedBy: make(map[string][]string, len(result.Items)),
blocks: make(map[string][]string, len(result.Items)),
parent: make(map[string]string, len(result.Items)),
}
for _, entry := range result.Items {
if len(entry.BlockedBy) > 0 {
out.blockedBy[entry.ID] = entry.BlockedBy
}
if len(entry.Blocks) > 0 {
out.blocks[entry.ID] = entry.Blocks
}
if entry.Parent != "" {
out.parent[entry.ID] = entry.Parent
}
}
return out
}
// annotateListBlocking is the DIRECT route's decoration read. It swallows every
// failure, including the accessor's, because that is what this route has always
// done: `bd list` renders the page undecorated rather than refusing to print it.
func annotateListBlocking(ctx context.Context, store storage.DoltStorage, ids []string) listBlocking {
annotator, err := store.BlockingAnnotator()
if err != nil {
return newListBlocking(issueops.BlockingResult{})
}
result, err := annotator.AnnotateBlocking(ctx, issueops.BlockingRequest{IDs: ids})
if err != nil {
return newListBlocking(issueops.BlockingResult{})
}
return newListBlocking(result)
}
// proxiedBlockingAnnotator hands back the guarded blocking-decoration surface
// for the proxied-server provider, through the provider's own accessor.
func proxiedBlockingAnnotator() (issueops.BlockingAnnotator, error) {
if uowProvider == nil {
return nil, errors.New("proxied-server UOW provider not initialized")
}
src, ok := uowProvider.(uow.BlockingAnnotatorSource)
if !ok {
return nil, fmt.Errorf("proxied-server provider %T does not offer the blocking-decoration surface", uowProvider)
}
return src.BlockingAnnotator()
}