beads/website/versioned_docs/version-1.0.5/cli-reference/count.md
Julian Knutsen e8ae7a291a
feat(count): add --include-infra for exact bd list cardinality parity (#4389)
* feat(count): add --include-infra for exact bd list cardinality parity

bd count hardcoded filter.SkipWisps=true (9a29a158f, Q2 SQL-COUNT rewrite),
so it only counted the durable issues table. bd list --include-infra merges
the wisps table — including no_history beads, which are durable work — so no
count invocation could match a list cardinality. On the production gascity
rig store that meant bd count --type task = 23,777 vs a list --include-infra
cardinality of 33,601: a 29% undercount that blocks Gas City from
implementing an exact Counter over the bd CLI (its bounded-read pagination
needs Total to be exact).

Changes:

- cmd/bd/count.go: new --include-infra flag mirroring bd list's flag.
  applyCountIncludeInfra reproduces the buildListFilter defaults that
  determine list's cardinality under --include-infra: wisps merge
  (SkipWisps=false), template exclusion (IsTemplate=false), default gate
  exclusion unless --type gate, and infra-type routing to the ephemeral
  tier using the store-configured infra set. Without the flag the filter
  construction is unchanged (SkipWisps=true), keeping the widely-scripted
  default byte-identical.
- internal/storage/{dolt,embeddeddolt}/counts.go: CountIssues now delegates
  to issueops.CountIssuesInTx (extended with the query param) instead of a
  hardcoded SELECT COUNT(*) FROM issues, so SkipWisps/Ephemeral routing
  matches SearchIssuesInTx. CountIssuesInTx previously had no production
  callers.
- internal/storage/issueops/count.go: CountIssuesByGroupInTx now honors
  SkipWisps/Ephemeral with the same merge semantics, so --by-* grouped
  counts under --include-infra report merged buckets instead of
  silently-wrong durable-only numbers.
- Tests (TDD): cmd/bd/count_filter_test.go pins the count filter against
  buildListFilter field-by-field; internal/storage/dolt/
  count_include_wisps_test.go asserts CountIssues == len(SearchIssues) for
  the trap filters (templates, no_history, ephemeral) and merged grouped
  counts; cmd/bd/count_embedded_test.go adds CLI-level count==list parity.
- Docs: regenerated CLI reference (also picks up pre-existing dep/import
  help-text drift so scripts/check-doc-flags.sh passes) and one pre-existing
  gofmt fix in issueops/search.go for ci-pr-lint.

Verification on the production gascity rig store (read-only):

  bd count --include-infra --type task  = 33,601
  bd list  --include-infra --type task --all --json --limit 0 | len = 33,601
  bd count --include-infra              = 42,631  (list equivalent: 42,631)
  bd count --include-infra --status open = 1,969  (list equivalent: 1,969)
  bd count --include-infra --by-type    : total 42,631, task bucket 33,601
  bd count --type task (no flag)        = 23,777  (stock bd 1.0.5: 23,777)

Gates: make ci-pr-core (go test -race -short), ci-pr-policy, ci-pr-lint,
go vet ./..., embedded count/list suites, full dolt + embeddeddolt
storage packages.

Fixes #4387

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

* fix(cli): write-intent routing for all mutating commands; count ephemeral parity; pin bulk dep cycle gate

Adopt-PR review fixes for PR #4389 on top of the pre-review CI repair.

Routed write surface (#4141, bd-6dnrw.32, GH#3231): bd-6dnrw.32 gave
read-only opens a real read-only path, which silently broke routed sibling
writes -- prefix-routed resolution opened the target read-only, so a mutating
command on a routes.jsonl-routed ID failed with "store is read-only". The
earlier CI repair restored update/comment/comments add/note/reopen; review
found the rest of the mutating surface still broken. Write intent now covers
every prefix-routed mutating command: assign, priority, tag, edit, delete
(single + batch), close (resolveCloseTargets), human respond/dismiss, link,
and dep add/--blocks/remove/bulk (via a new resolveIDWithRoutingForWrite).
The source issue's store opens writable so the write commits on the target
head; read paths, dependency-target ID resolution, dep tree, and contributor
auto-routing stay read-only, preserving the bd-6dnrw.32/GH#3231 guarantee
that routed reads never mutate a foreign project's history. Regression test
TestEmbeddedRoutedMutatingSiblingWritesCommitTargetHead pins assign/tag/
dep add/delete/close routed writes committing on the target head.

Count ephemeral parity (GH#4387): CountIssuesInTx returned the wisps count
unconditionally for an Ephemeral=true filter, while SearchIssuesInTx falls
through to the durable issues table when the wisps tier is empty. The scalar
fall-through landed first, but review (attempt 2) found the same fall-through
missing from the two sibling functions, so grouped counts and count-projection
searches still dropped a durable issues-table row flagged ephemeral=1:
CountIssuesByGroupInTx returned empty buckets while the scalar Total fell
through (sum(groups) != Total), and SearchIssuesWithCountsInTx returned nil
where SearchIssues returned the row. CountIssuesByGroupInTx and
SearchIssuesWithCountsInTx now mirror the scalar/list fall-through, so
bd count --include-infra --by-* and bd search --counts --include-infra match
bd list cardinality when only durable rows match. The scalar fall-through
comment is corrected to describe the durable ephemeral=1 defensive state
(a promoted bead carries ephemeral=0, so it never reaches this branch).
Regression tests TestCountIssuesEphemeralFallsThroughToDurable (scalar),
TestCountIssuesByGroupEphemeralFallsThroughToDurable (grouped), and
TestSearchIssuesWithCountsEphemeralFallsThroughToDurable (counts projection)
pin count==len(list) for that case; the merge path documents that list is the
disjoint-table corruption detector.

Bulk dep cycle gate (bd-6dnrw.8): unchanged from the pre-review repair --
TestEmbeddedDepBulkNoCycleCheckKeepsWholeGraphGate pins the whole-graph
cycle gate on bulk --no-cycle-check adds.

Validation (worktree, BEADS_TEST_EMBEDDED_DOLT=1, -tags gms_pure_go):
routed-write and count-parity regression tests pass; TestEmbeddedDep*,
cross-rig routing, dep/close/delete/link CLI suites, and the count
CLI/issueops suites pass; go build, go vet, gofmt, git diff --check clean.

Validation (attempt 2, grouped + counts-projection fall-through): go build
(issueops, dolt, cmd/bd) and go vet (issueops, dolt) clean; git diff --check
clean. The Dolt count/list parity suite passes against an isolated Dolt test
container (TestCountIssuesMergedMatchesSearch, the three ephemeral
fall-through regressions, TestCountIssuesByGroupIncludesWisps,
TestPR4107SearchIssuesWithCountsEphemeralFalseIncludesNoHistoryOnly); all
three fall-through regressions were verified failing on the pre-fix tree.
Embedded-engine fixtures that need the CGO/ICU build are exercised by the
GitHub PR workflow.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

---------

Co-authored-by: CI Bot <ci@beads.test>
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
2026-06-13 04:14:28 -07:00

3.2 KiB

id title slug sidebar_position
count bd count /cli-reference/count 999

Generated from bd help --doc count

bd count

Count issues matching the specified filters.

By default, returns the total count of issues matching the filters. Use --by-* flags to group counts by different attributes.

Examples: bd count # Count all issues bd count --status open # Count open issues bd count --by-status # Group count by status bd count --by-priority # Group count by priority bd count --by-type # Group count by issue type bd count --by-assignee # Group count by assignee bd count --by-label # Group count by label bd count --assignee alice --by-status # Count alice's issues by status bd count --include-infra # Count issues + wisps tier (matches 'bd list --include-infra --all' cardinality)

bd count [flags]

Flags:

  -a, --assignee string         Filter by assignee
      --by-assignee             Group count by assignee
      --by-label                Group count by label
      --by-priority             Group count by priority
      --by-status               Group count by status
      --by-type                 Group count by issue type
      --closed-after string     Filter issues closed after date (YYYY-MM-DD or RFC3339)
      --closed-before string    Filter issues closed before date (YYYY-MM-DD or RFC3339)
      --created-after string    Filter issues created after date (YYYY-MM-DD or RFC3339)
      --created-before string   Filter issues created before date (YYYY-MM-DD or RFC3339)
      --desc-contains string    Filter by description substring
      --empty-description       Filter issues with empty description
      --id string               Filter by specific issue IDs (comma-separated)
      --include-infra           Include infrastructure beads and the wisps tier (matches 'bd list --include-infra --all' cardinality)
  -l, --label strings           Filter by labels (AND: must have ALL)
      --label-any strings       Filter by labels (OR: must have AT LEAST ONE)
      --no-assignee             Filter issues with no assignee
      --no-labels               Filter issues with no labels
      --notes-contains string   Filter by notes substring
  -p, --priority int            Filter by priority (0-4: 0=critical, 1=high, 2=medium, 3=low, 4=backlog)
      --priority-max int        Filter by maximum priority (inclusive)
      --priority-min int        Filter by minimum priority (inclusive)
  -s, --status string           Filter by stored status (open, in_progress, blocked, deferred, closed). Note: dependency-blocked issues use 'bd blocked'
      --title string            Filter by title text (case-insensitive substring match)
      --title-contains string   Filter by title substring
  -t, --type string             Filter by type (bug, feature, task, epic, chore, decision, merge-request, molecule, gate)
      --updated-after string    Filter issues updated after date (YYYY-MM-DD or RFC3339)
      --updated-before string   Filter issues updated before date (YYYY-MM-DD or RFC3339)