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.
89 lines
3.5 KiB
Go
89 lines
3.5 KiB
Go
package httpapi
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
"net/http"
|
|
|
|
"github.com/steveyegge/beads/internal/httpapi/apigen"
|
|
"github.com/steveyegge/beads/issueops"
|
|
)
|
|
|
|
// handleBlockingAnnotations answers GET /v0/beads/dependencies/blocking.
|
|
//
|
|
// Everything below the wire is on issueops.BlockingAnnotator: which edge types
|
|
// count, which row's status decides an edge is live, that an unresolvable
|
|
// blocker still blocks, that a `parent-child` edge is the parent rather than a
|
|
// blocker, the order within each list and the de-duplication of a repeated id.
|
|
// What stays here is transport — decoding one repeatable parameter, the size
|
|
// bound, and an envelope whose element type is the role's own struct.
|
|
//
|
|
// The size bound is maxDependencyAnchors, shared with the stored-edge read
|
|
// beside it rather than given a constant of its own: the two operations bound
|
|
// the same thing for the same reason (the QUESTION, because neither answer has
|
|
// a cursor), they are asked about the same page of ids, and two numbers would
|
|
// mean a client could ask one of them about a page the other refuses.
|
|
func (s *Server) handleBlockingAnnotations(w http.ResponseWriter, r *http.Request) {
|
|
q := newQuery(r.URL.Query())
|
|
|
|
ids := q.list("issue_id")
|
|
if !s.acceptQuery(w, r, q) {
|
|
return
|
|
}
|
|
// Both bounds are checked here rather than left to the role, for the reason
|
|
// handleListDependencies gives: they are this operation's own limits, not
|
|
// statements about what a blocking annotation means, and the role answers an
|
|
// empty request with an empty result rather than a refusal.
|
|
if len(ids) == 0 {
|
|
requestInfo(r.Context()).refuse("issue_id")
|
|
s.fail(w, r, InvalidArgument("issue_id", ReasonInvalidValue, "name at least one issue_id"))
|
|
return
|
|
}
|
|
if len(ids) > maxDependencyAnchors {
|
|
requestInfo(r.Context()).refuse("issue_id")
|
|
s.fail(w, r, InvalidArgument("issue_id", ReasonInvalidValue,
|
|
fmt.Sprintf("at most %d issue_id values per request, got %d", maxDependencyAnchors, len(ids))))
|
|
return
|
|
}
|
|
|
|
annotator, err := s.blockingAnnotator(r)
|
|
if err != nil {
|
|
s.failErr(w, r, err)
|
|
return
|
|
}
|
|
result, err := annotator.AnnotateBlocking(r.Context(), issueops.BlockingRequest{IDs: ids})
|
|
if err != nil {
|
|
s.failBlockingErr(w, r, err)
|
|
return
|
|
}
|
|
writeJSON(w, wireBlocking(result))
|
|
}
|
|
|
|
// failBlockingErr answers a failed blocking annotation. The role's one
|
|
// request-validation refusal — an empty id — is the caller's own input and
|
|
// reaches the client as the 400 it is; everything else keeps going through the
|
|
// one mapping in problem.go. It classifies on the SENTINEL rather than on
|
|
// prose, as failEdgeReadErr does.
|
|
func (s *Server) failBlockingErr(w http.ResponseWriter, r *http.Request, err error) {
|
|
if !errors.Is(err, issueops.ErrValidation) {
|
|
s.failErr(w, r, err)
|
|
return
|
|
}
|
|
requestInfo(r.Context()).refuse("issue_id")
|
|
s.fail(w, r, InvalidArgument("issue_id", ReasonInvalidValue, err.Error()))
|
|
}
|
|
|
|
// wireBlocking projects the role's answer onto the generated envelope, whose
|
|
// element type is an ALIAS of the role's own struct — so this is a slice copy
|
|
// and nothing else. There is no second wire struct here and there must never be
|
|
// one.
|
|
//
|
|
// It exists for the one thing that is not free: the document says `items` is an
|
|
// empty array and never null, so the wire promise does not depend on the role
|
|
// keeping its own.
|
|
func wireBlocking(result issueops.BlockingResult) apigen.BlockingAnnotations {
|
|
if result.Items == nil {
|
|
return apigen.BlockingAnnotations{Items: []apigen.IssueBlocking{}}
|
|
}
|
|
return apigen.BlockingAnnotations{Items: result.Items}
|
|
}
|