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.
75 lines
3.4 KiB
Go
75 lines
3.4 KiB
Go
package workapi
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
|
|
"github.com/steveyegge/beads/issueops"
|
|
)
|
|
|
|
// This file holds the shared, database-free half of issueops.Bootstrapper and
|
|
// issueops.InitVerifier: the keys the identity lives under, the request
|
|
// validation, and the normalization that makes the prefix a bootstrap stores
|
|
// the same string on every backend. It is pure so that three implementations
|
|
// decide through one body and the refusals pin without a database.
|
|
|
|
// The two keys a workspace's IDENTITY lives under.
|
|
//
|
|
// They are named here rather than spelled at each call site because a key
|
|
// spelled differently in one of the places that read them is an identity nothing
|
|
// else can find — which looks exactly like a database nobody ever initialized.
|
|
//
|
|
// These two and no others decide whether a substrate is bootstrapped at all,
|
|
// and either one of them present is what Bootstrapper.Bootstrap refuses over.
|
|
const (
|
|
// ConfigKeyIssuePrefix lives on the durable settings plane, which is where
|
|
// every other reader of the prefix already looks for it.
|
|
ConfigKeyIssuePrefix = "issue_prefix"
|
|
// MetadataKeyProjectID is the identity cross-project verification compares
|
|
// on connection. The leading underscore is historical and load-bearing:
|
|
// it is the spelling every existing workspace already carries.
|
|
MetadataKeyProjectID = "_project_id"
|
|
)
|
|
|
|
// NormalizeBootstrapPrefix returns the prefix as a bootstrap STORES it.
|
|
//
|
|
// The settings plane strips a trailing hyphen from this key. Doing it here
|
|
// instead of relying on that means BootstrapResult.Prefix and the value a later
|
|
// VerifyIdentity answers with are one value on every backend, including the
|
|
// unit-of-work one whose write does not pass through that plane's normalizer.
|
|
func NormalizeBootstrapPrefix(prefix string) string {
|
|
return strings.TrimRight(prefix, "-")
|
|
}
|
|
|
|
// ValidateBootstrapRequest refuses a bootstrap that cannot produce a usable
|
|
// workspace and returns the request as it will be WRITTEN.
|
|
//
|
|
// Every implementation validates through it BEFORE opening a transaction, which
|
|
// is what makes issueops.Bootstrapper's "a refusal writes nothing" true of the
|
|
// connection as well as of the keys.
|
|
func ValidateBootstrapRequest(req issueops.BootstrapRequest) (issueops.BootstrapRequest, error) {
|
|
req.Prefix = NormalizeBootstrapPrefix(req.Prefix)
|
|
if req.Prefix == "" {
|
|
return issueops.BootstrapRequest{}, fmt.Errorf("%w: bootstrap requires a non-empty issue prefix", issueops.ErrValidation)
|
|
}
|
|
if req.ProjectID == "" {
|
|
return issueops.BootstrapRequest{}, fmt.Errorf("%w: bootstrap requires a project id; this role does not mint one", issueops.ErrValidation)
|
|
}
|
|
return req, nil
|
|
}
|
|
|
|
// RefuseIdentifiedSubstrate turns the pair a bootstrap read into the refusal
|
|
// issueops.Bootstrapper promises, or nil when the substrate is free.
|
|
//
|
|
// EITHER MARKER IS ENOUGH. A substrate several rigs share carries a prefix one
|
|
// of them chose, and a bootstrap that overwrote it would rename every id the
|
|
// others are about to mint; a substrate carrying only a project id is either a
|
|
// server-provisioned one bd must adopt rather than stamp, or a bootstrap that
|
|
// failed partway, and bd cannot tell those apart. The error carries both values
|
|
// so its caller can.
|
|
func RefuseIdentifiedSubstrate(prefix, projectID string) error {
|
|
if prefix == "" && projectID == "" {
|
|
return nil
|
|
}
|
|
return &issueops.AlreadyIdentifiedError{Prefix: prefix, ProjectID: projectID}
|
|
}
|