* feat(stats): count the rows the default listing suppresses
bd status counts the issues table; bd list hides gates and templates on
account of what they are. The two therefore disagree, and nothing
reconciles them: a teardown driven by bd list leaves a gate behind and
status reports a total the operator cannot account for from any listing.
Break the suppressed rows out as their own counts. TotalIssues keeps
counting the database, which is what a command titled "Issue Database
Status" should report; these say how much of that total no default
listing will show. Every backend's statistics path funnels through
ScanIssueCountsInTx, so one query serves all of them.
Infra types need no counterpart here: they live on the wisp plane, which
this query does not read.
* fix(status): disclose the counted rows bd list will not show
bd status reported "Total Issues: 2" for a workspace whose every listing
showed one, because gates and templates are suppressed from a default
bd list. Nothing connected the two numbers, so the remainder read as a
phantom -- most visibly after a teardown driven by bd list, which leaves
its gates behind and then cannot see them.
Report the suppressed rows under the summary they qualify, naming the
flag that reveals each kind. The breakdown is printed rather than a
single hidden-total, since a template gate would otherwise be counted
twice. Nothing is printed when there is nothing suppressed.
Stacked on the statistics counts that make this reportable.
* docs(api): put gate_issues and template_issues on the Statistics schema
The Statistics schema is pinned to types.Statistics, so the two new
counts were on the wire the moment the struct grew them, and
TestWireTagBijection fails the openapi gate until the spec says so:
Go fields with no spec property: [gate_issues template_issues]
Document both as a breakdown of total_issues rather than an addition to
it — they count rows the default `bd list` suppresses, which
total_issues already includes — and warn against summing them, since a
row can be both a gate and a template.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
* fix(status): give --assigned the same disclosure, and test the behavior
Three points from review.
1. `bd status --assigned` never printed the line. AssigneeStats does not
go through ScanIssueCountsInTx - it folds one actor's rows through
workapi.FoldStatsAssigneeSummary, which left both new fields zero. That
route's filter sets only Assignee, so IsTemplate stays nil and the
actor's gates and protos really ARE in those rows while
`bd list --assignee` suppresses both: the same reconciliation gap, one
scope down. The fold now counts them, and its doc says they are set
deliberately rather than borrowed from a workspace-wide answer.
2. The infra-type suppression is now explained rather than asserted away,
and the answer is that a durable infra row is NOT unreachable, so the
third breakdown is filed as GH#6439 rather than dismissed. Both the
plane routing and the listing's exclusions read the workspace-configured
types.infra set, and writing that key only invalidates a cache
(dolt/config.go) - it never moves rows already written. So durable rows
created while a type was not infra stay durable once it becomes one, and
a type evicted from the set creates durable rows outright, which the
create contract already pins ("evicted infra type",
issue_operations_contract.go). Counting them needs that configured set,
which ScanIssueCountsInTx - portable SQL with no config seam, called
from six backend sites - cannot reach; guessing with the built-in names
would be wrong in exactly the workspaces where it matters.
suppressedTypeSummary's doc now carries that reasoning.
3. The behavior itself had no test - both existing cases exercised a pure
string formatter, and would pass with the render call site deleted. Now:
- TestRenderStatusEmitsTheSuppressedRowsLine captures renderStatus's
stdout, asserts the line and both parts, and asserts it sits after the
totals it reconciles rather than in the extended block. It fails with
the call site removed ("renderStatus did not emit the disclosure
line"), plus a companion asserting the line is absent when there is
nothing to disclose.
- Three conformance cases in stats_reporter_contract.go, wired into all
three role wirings (dolt, embeddeddolt, uow), so the new SQL is
checked cross-backend rather than at one call site:
BreaksOutTheRowsTheDefaultListingSuppresses (with the negative rows a
loose predicate would also move), BreaksOutAGateThatIsAlsoATemplate
(the two suppressions are independent, so a proto's gate step counts
in both), and AssigneeStatsBreaksOutTheSuppressedRows for the fold.
statsReporterCounts and assertStatsReporterDelta carry the two fields.
All three are behavioral reds against zeroed counts, not compile
errors:
GateIssues moved by 0 (0 -> 0), want 1
TemplateIssues moved by 0 (0 -> 0), want 1
GateIssues = 0, want 1 - the actor's gate is in this answer but
not in `bd list --assignee`
4. Nit: pluralCount takes both spellings instead of appending "s", so a
caller with an irregular plural is not silently mis-served.
Also adds the CHANGELOG entry the behavior change was missing, including
the GH#6439 gap.
Reported-by: bee-ghosttrack
Agent-Signature: claude-code-opus-5-unknown-reasoning on behalf of Harry Miller
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
* fix(conformance): declare the new stats cases in the order the table runs them
TestRoleContractCasesCoverEveryContractCase checks more than coverage: the
roleContractCases table has to list cases in the order their contract file
DECLARES them, because that is the order the unit-of-work leg's runners use
and the order its config-writing cases depend on.
I declared all three new cases together, then registered the assignee one
with the other assignee cases in the table, so the two orders disagreed:
roleContractCases is out of declaration order at position 449: table
has RunStatsReporterAStatusOutsideTheTalliesIsCountedOnlyInTotal,
source has RunStatsReporterAssigneeStatsBreaksOutTheSuppressedRows
Fixed by moving the declaration rather than the table entry, since the
assignee case belongs beside the other assignee-scoped ones anyway - the
grouping the table already had was the correct one. Caught by CI because I
ran go vet over backend/conformance but not its tests; both now pass.
Agent-Signature: claude-code-opus-5-unknown-reasoning on behalf of Harry Miller
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
* docs(changelog): move this PR's entry under [Unreleased]
The 1.3.0 cut renamed the old [Unreleased] block, so the entry this branch
added there now merges cleanly into the released [1.3.0] section (#6643).
Agent-Signature: claude-code-opus-5-5-unknown-reasoning on behalf of Harry Miller
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
* fix(status): complete the disclosure's remedy and pin its population
Maintainer review fixes for PR #5763 (adopt-pr iteration 1). Four of the
five review findings taken; the nit is declined with its measurement.
Finding 2 (minor, gate impact minor) - the printed remedy was incomplete.
The two counters come from the same scan as TotalIssues and are status-blind
with it, but the flags they named lift only the TYPE exclusion, so a CLOSED
gate was counted while `bd list --include-gates` still would not show it.
Gates are closed as the work they guard completes, so that is the ordinary
case rather than an edge.
Took the "complete the hint" arm over the "scope the counters" arm. Every
other field ScanIssueCountsInTx fills is workspace-wide; the disclosure
exists to account for TotalIssues, a database number printed three lines
above it; and scoping these two to the listing's population would leave them
explaining nothing about the total they are broken out of. `--all` "replaces
the status exclusions only" and lifts no type exclusion of its own
(backend/conformance/reader_contract.go:487), so the two flags together are
exactly the remedy. Recorded the population in the types.go field comment,
the status.go doc, and the CHANGELOG, which printed the old example verbatim.
Finding 3 (minor) - the three new conformance cases seeded only open rows,
so a backend counting over every status and one counting only the listing's
population returned identical numbers on all of them. Added a closed gate and
a closed proto to the first case. Proved it now decides the question: scoping
both SQL SUMs with `AND status <> 'closed'` reds exactly that case
("GateIssues moved by 1 (0 -> 1), want 2") while the all-open sibling
BreaksOutAGateThatIsAlsoATemplate stays green.
Finding 4 (minor) - the normative role doc in issueops/statsreporter.go
enumerated only the six prior counts. Added the two to that scan's bullet and
corrected two statements this PR had falsified: the headline "six counts of
one set", and the AssigneeStats bullet's "the fold ... tallies the five
statuses and nothing else", which stopped being true when the fold gained the
two increments.
Finding 1 (minor, gate impact minor) - ran `make bazel-sync`. It proposed
exactly one line, `+ "status_suppressed_test.go"` in cmd/bd/BUILD.bazel, and
nothing else, confirmed by porcelain rather than by bazel-sync-check.
Generator-owned, not hand-edited.
Finding 5 (nit) - declined. The three helpers already in package main
(pluralIssue, pluralize, plural) all DERIVE the "s" and cannot render a
caller-chosen pair; the tree's one two-form helper, pluralWord, is unexported
in internal/storage/issueops, and exporting it so a CLI string could reach it
would add exported surface to a storage role for a cosmetic. Recorded that
trade in pluralCount's doc comment instead.
Validation: `go build ./...` and `go vet` (6 pkgs) clean, gofmt clean,
`git diff --check` clean; cmd/bd 4/4 named PASS, internal/httpapi
TestWireTagBijection|TestSpec* PASS, internal/workapi PASS,
internal/storage/uow TestStatsReporterContract 18/18 subtests PASS. Both new
pins are mutation-proved: reverting `--all` reds all four table cases, both
flag subtests and the render-path pin, while the absence assertion stays
green.
Not done here: the PR body carries the same stale example line
("1 gate (--include-gates)"). Review iterations do not touch the PR surface,
so that correction is stamped for finalize.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
Co-authored-by: Gas City Adopt-PR <adopt-pr@gascity.local>
273 lines
11 KiB
Go
273 lines
11 KiB
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"strings"
|
|
|
|
"github.com/spf13/cobra"
|
|
"github.com/steveyegge/beads/internal/metrics"
|
|
"github.com/steveyegge/beads/internal/types"
|
|
"github.com/steveyegge/beads/internal/ui"
|
|
"github.com/steveyegge/beads/issueops"
|
|
)
|
|
|
|
// StatusOutput represents the complete status output
|
|
type StatusOutput struct {
|
|
Summary *types.Statistics `json:"summary"`
|
|
BlockedCountSkipped bool `json:"blocked_count_skipped,omitempty"`
|
|
RecentActivity *RecentActivitySummary `json:"recent_activity,omitempty"`
|
|
}
|
|
|
|
// RecentActivitySummary represents activity from git history
|
|
type RecentActivitySummary struct {
|
|
HoursTracked int `json:"hours_tracked"`
|
|
CommitCount int `json:"commit_count"`
|
|
IssuesCreated int `json:"issues_created"`
|
|
IssuesClosed int `json:"issues_closed"`
|
|
IssuesUpdated int `json:"issues_updated"`
|
|
IssuesReopened int `json:"issues_reopened"`
|
|
TotalChanges int `json:"total_changes"`
|
|
}
|
|
|
|
var statusCmd = &cobra.Command{
|
|
Use: "status",
|
|
GroupID: "views",
|
|
Aliases: []string{"stats"},
|
|
Short: "Show issue database overview and statistics",
|
|
Long: `Show a quick snapshot of the issue database state and statistics.
|
|
|
|
This command provides a summary of issue counts by state (open, in_progress,
|
|
blocked, closed), ready work, extended statistics (pinned issues,
|
|
average lead time), and recent activity over the last 24 hours from git history.
|
|
|
|
Similar to how 'git status' shows working tree state, 'bd status' gives you
|
|
a quick overview of your issue database without needing multiple queries.
|
|
|
|
Use cases:
|
|
- Quick project health check
|
|
- Onboarding for new contributors
|
|
- Integration with shell prompts or CI/CD
|
|
- Daily standup reference
|
|
- Fast CI status checks that don't need blocked-count accuracy
|
|
|
|
Examples:
|
|
bd status # Show summary with activity
|
|
bd status --no-activity # Skip git activity (faster)
|
|
bd status --no-blocked # Skip slow blocked-count scan (faster)
|
|
bd stats --no-blocked --json # JSON output without blocked count
|
|
bd status --json # JSON format output
|
|
bd status --assigned # Show issues assigned to current user
|
|
bd stats # Alias for bd status`,
|
|
SilenceUsage: true,
|
|
SilenceErrors: true,
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
evt := metrics.NewCommandEvent("status")
|
|
defer func() {
|
|
if c := metrics.Global(); c != nil {
|
|
c.CloseEventAndAdd(evt)
|
|
}
|
|
}()
|
|
|
|
showAssigned, _ := cmd.Flags().GetBool("assigned")
|
|
noActivity, _ := cmd.Flags().GetBool("no-activity")
|
|
noBlocked, _ := cmd.Flags().GetBool("no-blocked")
|
|
jsonFormat, _ := cmd.Flags().GetBool("json")
|
|
|
|
if jsonFormat {
|
|
jsonOutput = true
|
|
}
|
|
|
|
reporter, err := openStatsReporter()
|
|
if err != nil {
|
|
return HandleErrorRespectJSON("%v", err)
|
|
}
|
|
|
|
var result issueops.StatsResult
|
|
if showAssigned {
|
|
// --no-blocked is not consulted here, and never was: an
|
|
// assignee-scoped summary computes both numbers by a route that has
|
|
// no fast path (issueops.StatsReporter.AssigneeStats).
|
|
result, err = reporter.AssigneeStats(rootCtx, issueops.AssigneeStatsRequest{Assignee: actor})
|
|
} else {
|
|
result, err = reporter.Stats(rootCtx, issueops.StatsRequest{SkipBlocked: noBlocked})
|
|
if err == nil && noBlocked && result.Summary.BlockedIssues != nil {
|
|
// Derived from the ANSWER rather than from the route: the two
|
|
// routes differ on it today (the unit-of-work seam publishes no
|
|
// no-blocked query), and a backend that gains one stops printing
|
|
// this without an edit here.
|
|
fmt.Fprintln(os.Stderr, "warning: this backend has no --no-blocked fast path; the full blocked-count query ran")
|
|
}
|
|
}
|
|
if err != nil {
|
|
return HandleErrorRespectJSON("%v", err)
|
|
}
|
|
|
|
var recentActivity *RecentActivitySummary
|
|
if !noActivity {
|
|
recentActivity = getGitActivity(24)
|
|
}
|
|
|
|
return renderStatus(&result.Summary, recentActivity)
|
|
},
|
|
}
|
|
|
|
// openStatsReporter hands back the summary role for whichever route this
|
|
// invocation is on, each through its own capability accessor.
|
|
func openStatsReporter() (issueops.StatsReporter, error) {
|
|
if usesProxiedServer() {
|
|
return proxiedStatsReporter()
|
|
}
|
|
return store.StatsReporter()
|
|
}
|
|
|
|
// suppressedTypeSummary describes the counted rows that a default bd list will
|
|
// not show, so the totals above can be reconciled against a listing instead of
|
|
// looking like a phantom.
|
|
//
|
|
// THE REMEDY IT PRINTS NAMES TWO FLAGS, not one, because the default listing
|
|
// applies its TYPE and its STATUS suppressions independently. These counts
|
|
// come from the same scan as TotalIssues and are status-blind with it: a
|
|
// CLOSED gate is in GateIssues. `bd list --include-gates` would still not show
|
|
// that row, because the default ExcludeStatus of closed and pinned
|
|
// (internal/workapi/list.go) is lifted only by --all - which "replaces the
|
|
// status exclusions only" and lifts no type exclusion of its own, pinned as
|
|
// that phrase in backend/conformance/reader_contract.go. So the type flag on
|
|
// its own is a remedy that reproduces the number only in a workspace whose
|
|
// gates and protos all happen to still be open, and gates are closed as the
|
|
// work they guard completes. Naming both flags is what makes the printed
|
|
// remedy actually reconcile; a hint that does not is the same silent
|
|
// disagreement this line exists to remove, one level down.
|
|
//
|
|
// It names two of the three type-based suppressions a default listing applies.
|
|
// The third - the infra types, which applyTypeSuppressions
|
|
// (internal/workapi/list.go) adds to ExcludeTypes independently of the wisp
|
|
// plane bit - is NOT here, and not because a durable infra row is unreachable.
|
|
// It is reachable: the plane routing and the listing's exclusions both read the
|
|
// WORKSPACE-CONFIGURED types.infra set, and changing that set only invalidates
|
|
// a cache (internal/storage/dolt/config.go) - it never moves rows already
|
|
// written. So durable rows created while a type was not infra stay in the
|
|
// issues plane once it becomes one, and a type evicted from the set creates
|
|
// durable rows outright (pinned by the create contract in
|
|
// backend/conformance/issue_operations_contract.go). Counting them therefore
|
|
// needs that configured set, which ScanIssueCountsInTx - pure portable SQL with
|
|
// no config seam - cannot reach. Tracked separately rather than guessed at
|
|
// here with the built-in names, which would be wrong in exactly the workspaces
|
|
// where it matters.
|
|
func suppressedTypeSummary(stats *types.Statistics) string {
|
|
var parts []string
|
|
if stats.GateIssues > 0 {
|
|
parts = append(parts, fmt.Sprintf("%s (--include-gates --all)", pluralCount(stats.GateIssues, "gate", "gates")))
|
|
}
|
|
if stats.TemplateIssues > 0 {
|
|
parts = append(parts, fmt.Sprintf("%s (--include-templates --all)", pluralCount(stats.TemplateIssues, "template", "templates")))
|
|
}
|
|
return strings.Join(parts, ", ")
|
|
}
|
|
|
|
// pluralCount renders a count with the right one of two spellings. Both forms
|
|
// are passed in rather than derived by appending "s", so a caller with an
|
|
// irregular plural is not silently mis-served.
|
|
//
|
|
// It is not a fourth spelling of the three helpers already in package main:
|
|
// pluralIssue, pluralize and plural all DERIVE the "s" and so cannot render a
|
|
// caller-chosen pair. The tree's one two-form helper, pluralWord in
|
|
// internal/storage/issueops/lease.go, is unexported in a storage package, and
|
|
// exporting it so a CLI string could reach it would add exported surface to a
|
|
// storage role for a cosmetic. That file's own doc comment records the same
|
|
// trade from the other side - it carries whole words because the issueops
|
|
// plural() covers only the "s" case - so one two-form helper per package is
|
|
// the established shape here.
|
|
func pluralCount(n int, singular, plural string) string {
|
|
if n == 1 {
|
|
return fmt.Sprintf("%d %s", n, singular)
|
|
}
|
|
return fmt.Sprintf("%d %s", n, plural)
|
|
}
|
|
|
|
func renderStatus(stats *types.Statistics, recentActivity *RecentActivitySummary) error {
|
|
output := &StatusOutput{
|
|
Summary: stats,
|
|
BlockedCountSkipped: stats.BlockedIssues == nil,
|
|
RecentActivity: recentActivity,
|
|
}
|
|
|
|
if jsonOutput {
|
|
return outputJSON(output)
|
|
}
|
|
|
|
// Human-readable colorized output using semantic ui package
|
|
fmt.Printf("\n%s Issue Database Status\n\n", ui.RenderAccent("📊"))
|
|
fmt.Printf("Summary:\n")
|
|
fmt.Printf(" Total Issues: %d\n", stats.TotalIssues)
|
|
fmt.Printf(" Open: %s\n", ui.RenderPass(fmt.Sprintf("%d", stats.OpenIssues)))
|
|
fmt.Printf(" In Progress: %s\n", ui.RenderWarn(fmt.Sprintf("%d", stats.InProgressIssues)))
|
|
// Skip-state is derived from the data itself (nil BlockedIssues/ReadyIssues),
|
|
// not the --no-blocked flag: --assigned recomputes fully-populated stats even
|
|
// when --no-blocked was also passed, so the flag alone would misrender those
|
|
// as skipped.
|
|
if stats.BlockedIssues == nil {
|
|
fmt.Printf(" Blocked: %s\n", ui.MutedStyle.Render("(skipped)"))
|
|
} else if *stats.BlockedIssues > 0 {
|
|
fmt.Printf(" Blocked: %s\n", ui.RenderFail(fmt.Sprintf("%d", *stats.BlockedIssues)))
|
|
} else {
|
|
fmt.Printf(" Blocked: %d\n", *stats.BlockedIssues)
|
|
}
|
|
fmt.Printf(" Closed: %d\n", stats.ClosedIssues)
|
|
if stats.ReadyIssues == nil {
|
|
fmt.Printf(" Ready to Work: %s\n", ui.MutedStyle.Render("(skipped)"))
|
|
} else {
|
|
fmt.Printf(" Ready to Work: %s\n", ui.RenderPass(fmt.Sprintf("%d", *stats.ReadyIssues)))
|
|
}
|
|
|
|
if suppressed := suppressedTypeSummary(stats); suppressed != "" {
|
|
fmt.Printf(" Not shown by bd list: %s\n", suppressed)
|
|
}
|
|
|
|
// Extended statistics (only show if non-zero)
|
|
hasExtended := stats.PinnedIssues > 0 ||
|
|
stats.EpicsEligibleForClosure > 0 || stats.AverageLeadTime > 0
|
|
if hasExtended {
|
|
fmt.Printf("\nExtended:\n")
|
|
if stats.PinnedIssues > 0 {
|
|
fmt.Printf(" Pinned: %d\n", stats.PinnedIssues)
|
|
}
|
|
if stats.EpicsEligibleForClosure > 0 {
|
|
fmt.Printf(" Epics Ready to Close: %s\n", ui.RenderPass(fmt.Sprintf("%d", stats.EpicsEligibleForClosure)))
|
|
}
|
|
if stats.AverageLeadTime > 0 {
|
|
fmt.Printf(" Avg Lead Time: %.1f hours\n", stats.AverageLeadTime)
|
|
}
|
|
}
|
|
|
|
if recentActivity != nil {
|
|
fmt.Printf("\nRecent Activity (last %d hours):\n", recentActivity.HoursTracked)
|
|
fmt.Printf(" Commits: %d\n", recentActivity.CommitCount)
|
|
fmt.Printf(" Total Changes: %d\n", recentActivity.TotalChanges)
|
|
fmt.Printf(" Issues Created: %d\n", recentActivity.IssuesCreated)
|
|
fmt.Printf(" Issues Closed: %d\n", recentActivity.IssuesClosed)
|
|
fmt.Printf(" Issues Reopened: %d\n", recentActivity.IssuesReopened)
|
|
fmt.Printf(" Issues Updated: %d\n", recentActivity.IssuesUpdated)
|
|
}
|
|
|
|
fmt.Printf("\nFor more details, use 'bd list' to see individual issues.\n")
|
|
fmt.Println()
|
|
|
|
return nil
|
|
}
|
|
|
|
// getGitActivity returns recent activity statistics.
|
|
// Previously calculated from git log of issues.jsonl; now returns nil
|
|
// as activity tracking has moved to Dolt-native queries.
|
|
func getGitActivity(_ int) *RecentActivitySummary {
|
|
return nil
|
|
}
|
|
|
|
func init() {
|
|
statusCmd.Flags().Bool("all", false, "Show all issues (default behavior)")
|
|
statusCmd.Flags().Bool("assigned", false, "Show issues assigned to current user")
|
|
statusCmd.Flags().Bool("no-activity", false, "Skip git activity summary (faster)")
|
|
statusCmd.Flags().Bool("no-blocked", false, "Skip blocked-count computation (faster on large rigs; not supported in proxied-server mode)")
|
|
// Note: --json flag is defined as a persistent flag in main.go, not here
|
|
rootCmd.AddCommand(statusCmd)
|
|
}
|