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.
134 lines
5 KiB
Go
134 lines
5 KiB
Go
package workapi
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
|
|
"github.com/steveyegge/beads/internal/types"
|
|
"github.com/steveyegge/beads/internal/utils"
|
|
"github.com/steveyegge/beads/issueops"
|
|
)
|
|
|
|
// countGroupColumns is the closed set issueops.CountByGroupRequest.GroupBy
|
|
// promises, mapped to what the storage seam calls each dimension. It exists so
|
|
// an unknown value is refused HERE, as ErrValidation, rather than reaching
|
|
// storage and coming back as an unclassifiable "unsupported groupBy" string.
|
|
var countGroupColumns = map[issueops.CountGroup]string{
|
|
issueops.CountGroupStatus: "status",
|
|
issueops.CountGroupPriority: "priority",
|
|
issueops.CountGroupType: "type",
|
|
issueops.CountGroupAssignee: "assignee",
|
|
issueops.CountGroupLabel: "label",
|
|
}
|
|
|
|
// ValidateCountGroup resolves a grouping dimension to the name the storage
|
|
// seam takes, refusing anything outside the published set with ErrValidation.
|
|
func ValidateCountGroup(group issueops.CountGroup) (string, error) {
|
|
column, ok := countGroupColumns[group]
|
|
if !ok {
|
|
return "", fmt.Errorf("invalid group '%s'. Valid values: status, priority, type, assignee, label%.0w",
|
|
group, issueops.ErrValidation)
|
|
}
|
|
return column, nil
|
|
}
|
|
|
|
// BuildCountFilter turns a count request into the storage-level filter: the
|
|
// single definition of what `bd count` means, which every implementation of
|
|
// issueops.Counter builds through.
|
|
//
|
|
// It is a SEPARATE builder rather than a call into BuildListFilter with the
|
|
// paging fields blanked out, because the two commands disagree about the
|
|
// default answer: a listing hides closed, pinned, template and gate rows, and a
|
|
// count hides none of them. The one place they must agree is --include-infra,
|
|
// pinned by a golden-style test comparing this builder's output against
|
|
// BuildListFilter's for the same request (count_test.go, GH#4387).
|
|
//
|
|
// cfg supplies the workspace's infra vocabulary and is only read under
|
|
// IncludeInfra; a zero ListConfig falls back to the default infra set.
|
|
func BuildCountFilter(in issueops.CountRequest, cfg ListConfig) (types.IssueFilter, error) {
|
|
filter := types.IssueFilter{
|
|
TitleSearch: in.TitleSearch,
|
|
TitleContains: in.TitleContains,
|
|
DescriptionContains: in.DescContains,
|
|
NotesContains: in.NotesContains,
|
|
CreatedAfter: in.CreatedAfter,
|
|
CreatedBefore: in.CreatedBefore,
|
|
UpdatedAfter: in.UpdatedAfter,
|
|
UpdatedBefore: in.UpdatedBefore,
|
|
ClosedAfter: in.ClosedAfter,
|
|
ClosedBefore: in.ClosedBefore,
|
|
EmptyDescription: in.EmptyDesc,
|
|
NoAssignee: in.NoAssignee,
|
|
NoLabels: in.NoLabels,
|
|
Priority: in.Priority,
|
|
PriorityMin: in.PriorityMin,
|
|
PriorityMax: in.PriorityMax,
|
|
}
|
|
|
|
// Status and IssueType are taken as written. Neither is validated against
|
|
// the workspace vocabulary: issueops.CountRequest promises an unrecognized
|
|
// name matches nothing rather than failing.
|
|
if in.Status != "" && in.Status != "all" {
|
|
status := types.Status(in.Status)
|
|
filter.Status = &status
|
|
}
|
|
if in.IssueType != "" {
|
|
issueType := types.IssueType(in.IssueType)
|
|
filter.IssueType = &issueType
|
|
}
|
|
if in.Assignee != "" {
|
|
assignee := in.Assignee
|
|
filter.Assignee = &assignee
|
|
}
|
|
|
|
// NormalizeLabels allocates its own slice, so the caller's Labels and
|
|
// LabelsAny are read and never written — the snapshot promise on
|
|
// issueops.Counter.
|
|
if labels := utils.NormalizeLabels(in.Labels); len(labels) > 0 {
|
|
filter.Labels = labels
|
|
}
|
|
if labelsAny := utils.NormalizeLabels(in.LabelsAny); len(labelsAny) > 0 {
|
|
filter.LabelsAny = labelsAny
|
|
}
|
|
if ids := utils.NormalizeLabels(strings.Split(in.IDFilter, ",")); len(ids) > 0 {
|
|
filter.IDs = ids
|
|
}
|
|
|
|
if in.IncludeInfra {
|
|
applyCountIncludeInfra(&filter, in.IssueType, cfg)
|
|
} else {
|
|
filter.SkipWisps = true
|
|
}
|
|
return filter, nil
|
|
}
|
|
|
|
// applyCountIncludeInfra switches the count filter to the wisps-inclusive mode
|
|
// of `bd list --include-infra` (GH#4387). It mirrors the BuildListFilter
|
|
// defaults that determine list's cardinality so that, for any filter set,
|
|
// `bd count --include-infra <filters>` returns exactly the number of rows
|
|
// `bd list --include-infra <filters> --all` materializes:
|
|
//
|
|
// - the wisps table is merged in (SkipWisps=false), picking up no_history
|
|
// beads and ephemeral wisps, like list's merge path;
|
|
// - template molecules are excluded (list's default);
|
|
// - gate beads are excluded unless requested via --type gate;
|
|
// - counting an infra type (agent/role/message, or the store-configured set)
|
|
// routes to the ephemeral wisps tier, like list's infra-type listing.
|
|
//
|
|
// A count without IncludeInfra never calls this and keeps its historical
|
|
// durable-only semantics.
|
|
func applyCountIncludeInfra(filter *types.IssueFilter, issueType string, cfg ListConfig) {
|
|
filter.SkipWisps = false
|
|
|
|
isTemplate := false
|
|
filter.IsTemplate = &isTemplate
|
|
|
|
if issueType != "gate" {
|
|
filter.ExcludeTypes = append(filter.ExcludeTypes, "gate")
|
|
}
|
|
|
|
if issueType != "" && cfg.IsInfra(issueType) {
|
|
ephemeral := true
|
|
filter.Ephemeral = &ephemeral
|
|
}
|
|
}
|