* wy-j2upyy: render the derived GATED decoration on bd show and bd list
A bead an open gate blocks is excluded from `bd ready` but rendered
`[P2 · OPEN]` by `bd show` and with a plain ○ by `bd list`, so the human
surfaces disagreed with the readiness query.
The decoration is DERIVED, never stored: no status write, no --status
filter change, no existing JSON field reshaped.
- internal/types/gated.go: IsActiveGate, the ONE predicate — a gate-typed
dependency reached over a blocking edge (blocks / conditional-blocks /
waits-for) whose status is neither closed nor pinned. That is the
is_blocked recompute's blocking leg restricted to gates, so a rendered
GATED and a `bd ready` exclusion cannot disagree. GateDescription /
GateReason own the reason's round trip with `bd gate create`.
- bd show: `[P2 · OPEN · GATED]` plus one `Gated by: <id> (<type>[:
<reason>][, awaiting <await-id>])` line per gate, beside Deferred:. The
dependency read the DEPENDS ON section already made is hoisted, so the
decoration costs no extra query.
- bd list: ⊘ in the glyph column (circle family, distinct from ○ and ❄),
and a legend entry when the page carries one. Batched by id set —
at most two extra queries per listing, one in the tree view where the
edge map is already loaded.
- --json: additive `gated_by: [{id,type,reason}]` on the detail view,
omitted when empty; documented in the OpenAPI IssueDetails schema.
Tests (red first): cmd/bd/gated_render_embedded_test.go drives real
bd show/list/--json over an embedded rig — gated, resolved, deferred+gated,
JSON additivity — plus pure unit tests for the predicate and formatters.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
* wy-j2upyy: document the additive gated_by field in the JSON schema reference
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
* wy-j2upyy: cover the flat list route's own batched gate read
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
* wy-j2upyy: make GATED the readiness rule's gate clause, both halves
The adversarial review found the "one predicate shared with bd ready" claim
false on two axes, and both were reproducible by hand:
BLOCKER 1 — waits-for is not the status rule. The is_blocked recompute applies
"target not closed and not pinned" only to its blocks / conditional-blocks
legs; the waits-for leg goes through waitsForGateBlockedSQL, a fanout over the
target's open parent-child children (or an also_blocks spawner). A plain
`bd dep add X G -t waits-for` onto an open childless gate therefore leaves X
in `bd ready` while every new surface called it GATED. Mirroring that leg in
Go would be a second implementation of a rule the database owns, so the edge
clause now names the two legs it really mirrors (types.IsGateEdge) and the
test that pinned the wrong direction is flipped.
BLOCKER 2 — the subject half was missing and spelled three different ways.
unmarkAllBlockedSQL forces is_blocked=0 for a closed or pinned subject
whatever its edges say, so `bd ready` never withholds one on a gate's account;
show and workapi filtered nothing, cmd/bd/gated.go filtered closed only, and
list_format.go filtered closed at two more sites. A force-closed bead rendered
[CLOSED · GATED] with gated_by on show while list showed a plain row — show
and list disagreeing about one bead, which is the drift this was meant to
prevent. The clause is now types.SubjectCanBeGated, asked once in
types.GatesHolding (which replaces ActiveGates and takes the subject) and once
in the listing helper that has no hydrated deps; the formatters re-ask the SAME
exported predicate rather than inventing a fourth spelling.
SHOULD 3 — agent mode computed the gate reads and threw them away, in every
CLAUDE_CODE seat, i.e. the population that filed the bug. Decorating it is the
real fix, so gatesByIssueID now returns the gate IDS and formatAgentIssue
carries "gated by: <id>" in the parenthetical it already prints. A gate is
also a blocker, so its id appears under both "blocked by" and "gated by": the
first says what to wait on, the second says which of those nobody can clear by
doing more work. --long and --format render no gate and no longer pay for the
reads.
NOTE 5 — a pinned+gated row kept ⊘ instead of 📌; with the subject clause a
pinned bead is not gated at all, so the pin survives by construction.
NOTE 6 — the cost comments claimed "two queries" / "exactly ONE"; the id-set
readers are a few round trips each. The bound that is real (per page, never
per row) is what the comments now say.
Tests, red-first: the flipped waits-for case; TestGatesHoldingSubjectStatus and
TestSubjectCanBeGated (open/in_progress/deferred yes, closed/pinned/nil no);
TestFormatIssueCompactGated and TestFormatAgentIssueGated; and four embedded
arms — a waits-for edge that bd ready lists and no surface decorates, a
force-closed subject and a pinned subject that render nothing and publish no
gated_by, and the agent line naming its gate. Each was watched to fail against
the pre-fix predicate before it passed.
Ran: go test ./internal/types/ -run 'TestGateIsHolding|TestGatesHolding|
TestSubjectCanBeGated|TestGateDescriptionRoundTrip|TestGateRefsProjection';
go test ./cmd/bd/ -run 'TestFormat*Gated|TestFormatIssueCompact*|
TestFormatDependencyInfoWithParent|TestListRoles*|TestDisplayPrettyList*';
BEADS_TEST_EMBEDDED_DOLT=1 go test ./cmd/bd/ -run TestEmbeddedGatedRendering
(11/11 subtests); gofmt -l (empty), go vet and golangci-lint on cmd/bd,
internal/types, internal/ui, internal/workapi; scripts/ci/pr-policy.sh.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
* wy-j2upyy: render GATED on the proxied `bd show` text route
SHOULD 4 of the review, and required for this rig: the constellation runs
proxied-server, where `bd show --json` already carried gated_by (uow
issue_reader -> workapi.BuildIssueDetails) while the TEXT renderer called the
plain formatters. The same bead read two ways from the same server disagreed.
proxiedRenderIssue now hoists the outgoing-edge read it already did for the
DEPENDS ON section above the header — the gates are the gate-typed subset of
that very set, so the decoration costs no extra query — and passes them to
formatIssueHeaderWithGates / formatIssueMetadataWithGates. The proxied LIST
routes were wired in the previous commit.
TestProxiedServerGatedRendering covers all five text surfaces plus the JSON
one beside them (header + Gated by line, pretty glyph, compact glyph + "gated
by", agent line, and a closed subject that renders nothing). Watched red first
with the proxied decoration stubbed out: four of six subtests failed, and the
--json arm passed, which is exactly the asymmetry the review reported.
Ran: BEADS_TEST_PROXIED_SERVER=1 go test ./cmd/bd/
-run TestProxiedServerGatedRendering -count=1 (6/6, 37.8s).
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
* wy-j2upyy: put cmd/bd/state.go on the shared "Reason:" marker
NOTE 7 of the review: types' gateReasonMarker was not gate-private —
cmd/bd/state.go wrote the same "\n\nReason: " into state-change EVENT
descriptions from its own literal. No live collision (events are not
gate-typed), but the constant's doc claimed GateReason returns "" for every
gate not made by `bd gate create`, and that is false for any description
carrying the marker.
The previous commit exported the constant as types.ReasonMarker, reworded
GateReason to say what the pair really guarantees (a round trip, not a
provenance check) and pinned the honest behavior in
TestGateDescriptionRoundTrip. This commit is the second writer: state.go now
builds its event description from the same constant, so the two cannot drift
apart by accident.
Ran: go build ./...; go test ./internal/types/ -run TestGateDescriptionRoundTrip
-count=1; gofmt -l cmd/bd/state.go (empty); go vet ./cmd/bd/.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
* wy-j2upyy: alias types.GateRef in package backend
gated_by on IssueDetails makes GateRef reachable from the public backend
contract; TestPublicSurfaceComplete requires every such type to carry an
alias here.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
* wy-j2upyy: build(bazel): register gated.go and its tests in cmd/bd and internal/types
The rebase onto e766da5ed carried the new source files but not their
BUILD.bazel entries, so every Bazel lane failed to compile internal/types
(undefined: GateRef). This is CI's own bazel-sync patch for 9ad7eb96c3,
applied unchanged.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
* wy-j2upyy: compute gated_by AFTER the dependencies read in BuildIssueDetails
The be-lpi merge (#6352) moved src.Dependencies() below the cardinality
counts so the unresolvable-edge delta reads count-first. That hunk merged
cleanly, which left details.GatedBy computed on the still-nil slice, and
both CI shards' show_json…carries_gated_by subtests went red (PR Risk
Embedded Dolt Cmd 20/20, Proxied Dolt Cmd 4/15 at d21237f3dc).
Move the GatedBy line to directly after details.Dependencies = deps, still
before the BriefDeps trim that rewrites the slice, and pin the ordering with
a workapi unit test over both DetailSource seams and BriefDeps on/off (red
on the pre-fix code, green after).
Ran: go test ./internal/workapi; go vet ./internal/workapi;
BEADS_TEST_EMBEDDED_DOLT=1 go test ./cmd/bd -run TestEmbeddedGatedRendering;
BEADS_TEST_PROXIED_SERVER=1 go test ./cmd/bd -run TestProxiedServerGatedRendering.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
* ci: register #6606's gated-rendering tests and gated_by wire shape with main's generated gates
Maintainer fixup for adopt-pr #6606. The adopted head merges the PR head
(c43eb567d2) into main (800d43eb8d). The PR's merge-base (02f05340f6)
predates three generated artifacts on main that every PR adding a cmd/bd
tier test or a wire member has to keep current, so the merged tree is red
on them even though the PR's own CI cannot see them:
- .github/scripts/embedded-cmd-test-shards.txt: the Bazel-only 50-shard
block must name every TestEmbedded* test exactly once, or
TestCmdEmbeddedShardManifestGeneratorNotStale fails `go test ./scripts/`.
`gen_embedded_cmd_shard_manifest.py 50 --weights=duration --write`
(incremental) placed TestEmbeddedGatedRendering on shard 16 and moved
no existing assignment; the frozen 20-shard block is untouched.
- .github/scripts/proxied-cmd-test-shards.txt: likewise for the 30-shard
block and TestProxiedServerGatedRendering (shard 2), via
`gen_proxied_shard_manifest.py 30 --weights=duration --write`, so
TestProxiedShardManifestGeneratorNotStale passes.
- internal/httpapi/wireshape/testdata/golden.json: TestWireShapeDigest
(#7182) pins every response member. `go run
./internal/httpapi/wireshape/cmd/gendigest` recorded the PR's new
IssueDetails.gated_by array and its id/type/reason members as four pure
additions (+25/-0), so no wire_revision bump is owed.
The PR's own files are unchanged.
Agent-Signature: claude-code-claude-opus-5-5-max on behalf of Gas City Adopt-PR
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* docs(gated): state gated_by one way, mark --watch as undecorated, fix stale refs
Review follow-ups for #6606. Comment and doc text only; no behavior change.
- gated_by is now documented in one direction. internal/types/types.go,
internal/types/gated.go and docs/reference/json-schema.md said the list
is nonempty EXACTLY when `bd ready` withholds the issue on a gate's
account. Only one direction holds: the is_blocked recompute also blocks
a child whose parent is blocked (its parent-child legs), so a child of a
gated parent leaves `bd ready` with an empty gated_by. All three now say
"nonempty means withheld", as the OpenAPI text already did, and name the
parent-child case.
- bd list --watch passes a nil gated map on both routes
(runListProxiedWatch, displayWatchedIssueList), so a bead the one-shot
listing marks with the gated glyph keeps its plain status glyph while
watched. Watch is out of this PR's scope; the three call sites now say
so instead of reading as a forgotten argument.
- show_format.go named types.ActiveGates, which does not exist; the
predicate is types.GatesHolding.
- gated.go's best-effort note compared the gate read with `bd list`'s
blocking annotation, which only the direct route swallows. It now scopes
that comparison to the direct route and names the proxied route's
failing read (A-blk-1).
- proxiedGatedIssueIDsOwnUOW now notes that its unit of work is a second
snapshot, so one render can name a just-resolved gate under "blocked by:"
but not "gated by:".
Agent-Signature: claude-code-claude-opus-5-5-max on behalf of Gas City Adopt-PR
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* fix(list): hydrate proxied gate candidates from both planes (bd-p8k7dm)
The proxied list resolved gate candidates through the use case's
GetIssuesByIDs, which reads the issues table only, while the edges it
resolved came from GetForIssueIDs, which reads both dependency tables.
A wisp gate (`bd mol wisp` clones a formula's gates as wisps, held to a
wisp step by a blocks edge) therefore hydrated to nothing. Its step
listed undecorated in pretty, --flat and agent output while `bd show`,
`--json` and `bd ready` called it gated.
Read the wisps beside the issues, the two-plane idiom
ready_proxied_server.go and uowMolReader already use. A failed wisps
read keeps the durable candidates. Correct the cost-bound comment that
claimed the id-set readers partition the planes on both routes.
Tests: a wisp-step + wisp-gate case in TestProxiedServerGatedRendering
and TestEmbeddedGatedRendering asserts the pretty, --flat and
CLAUDE_CODE=1 rows of `bd list --include-ephemeral`, and
TestProxiedGatedIssueIDsHydratesBothPlanes pins both planes plus the
failed-wisps-read fallback.
Agent-Signature: claude-code-claude-opus-5-5-max on behalf of Gas City Adopt-PR
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
Co-authored-by: Eddie the Engineer <adopt-pr@gascity.com>
337 lines
13 KiB
Go
337 lines
13 KiB
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"fmt"
|
|
"strings"
|
|
"time"
|
|
|
|
"github.com/steveyegge/beads/internal/storage"
|
|
"github.com/steveyegge/beads/internal/timeparsing"
|
|
"github.com/steveyegge/beads/internal/types"
|
|
"github.com/steveyegge/beads/internal/ui"
|
|
)
|
|
|
|
// parseTimeFlag parses time strings using the layered time parsing architecture.
|
|
// Supports compact durations (+6h, -1d), natural language (tomorrow, next monday),
|
|
// and absolute formats (2006-01-02, RFC3339).
|
|
func parseTimeFlag(s string) (time.Time, error) {
|
|
return timeparsing.ParseRelativeTime(s, time.Now())
|
|
}
|
|
|
|
// pinIndicator returns a pushpin emoji prefix for pinned issues
|
|
func pinIndicator(issue *types.Issue) string {
|
|
if issue.Pinned {
|
|
return "📌 "
|
|
}
|
|
return ""
|
|
}
|
|
|
|
// Priority tags for pretty output - simple text, semantic colors applied via ui package
|
|
// Design principle: only P0/P1 get color for attention, P2-P4 are neutral
|
|
func renderPriorityTag(priority int) string {
|
|
return ui.RenderPriority(priority)
|
|
}
|
|
|
|
// renderStatusIcon returns the status icon with semantic coloring applied
|
|
// Delegates to the shared ui.RenderStatusIcon for consistency across commands
|
|
func renderStatusIcon(status types.Status) string {
|
|
return ui.RenderStatusIcon(string(status))
|
|
}
|
|
|
|
// formatPrettyIssue formats a single issue for pretty output
|
|
// Uses semantic colors: status icon colored, priority P0/P1 colored, rest neutral
|
|
func formatPrettyIssue(issue *types.Issue) string {
|
|
return formatPrettyIssueGated(issue, nil)
|
|
}
|
|
|
|
// formatPrettyIssueGated is formatPrettyIssue with the derived gate marker
|
|
// (wy-j2upyy): when an open gate blocks the issue, the glyph column carries
|
|
// ⊘ instead of the stored status's icon. The rest of the row is untouched,
|
|
// and the stored status is untouched — this is a decoration over the same
|
|
// predicate `bd ready` filters on, so the listing stops disagreeing with it.
|
|
//
|
|
// The marker OUTRANKS the status icon, including ❄: one column can hold one
|
|
// glyph, and of the two reasons the work cannot start, the gate is the one a
|
|
// reader cannot discover from the row's own fields. It never outranks 📌,
|
|
// because types.SubjectCanBeGated refuses a pinned subject outright — a pinned
|
|
// bead is out of `bd ready` on its own account, not the gate's.
|
|
//
|
|
// gatedBy is the gate ids the ONE predicate selected (gatesByIssueID); the
|
|
// SubjectCanBeGated re-check is the same clause, not a second rule, and is
|
|
// here so a caller that hands over a stale map cannot invent a decoration.
|
|
func formatPrettyIssueGated(issue *types.Issue, gatedBy []string) string {
|
|
// Use shared helpers from ui package
|
|
statusIcon := ui.RenderStatusIcon(string(issue.Status))
|
|
if len(gatedBy) > 0 && types.SubjectCanBeGated(issue) {
|
|
statusIcon = ui.StatusBlockedStyle.Render(ui.StatusIconGated)
|
|
}
|
|
priorityTag := renderPriorityTag(issue.Priority)
|
|
|
|
// Type badge - only show for notable types
|
|
typeBadge := ""
|
|
switch issue.IssueType {
|
|
case "epic":
|
|
typeBadge = ui.TypeEpicStyle.Render("[epic]") + " "
|
|
case "bug":
|
|
typeBadge = ui.TypeBugStyle.Render("[bug]") + " "
|
|
}
|
|
|
|
// Format: STATUS_ICON ID PRIORITY [Type] Title
|
|
// Closed issues: entire line is muted
|
|
if issue.Status == types.StatusClosed {
|
|
return fmt.Sprintf("%s %s %s %s%s",
|
|
statusIcon,
|
|
ui.RenderMuted(issue.ID),
|
|
ui.RenderMuted(fmt.Sprintf("P%d", issue.Priority)),
|
|
ui.RenderMuted(string(issue.IssueType)),
|
|
ui.RenderMuted(" "+issue.Title))
|
|
}
|
|
|
|
return fmt.Sprintf("%s %s %s %s%s", statusIcon, issue.ID, priorityTag, typeBadge, issue.Title)
|
|
}
|
|
|
|
// formatPrettyIssueWithContext formats an issue with optional parent epic annotation
|
|
func formatPrettyIssueWithContext(issue *types.Issue, parentEpic string) string {
|
|
base := formatPrettyIssue(issue)
|
|
if parentEpic == "" {
|
|
return base
|
|
}
|
|
return base + " " + ui.RenderMuted("← "+parentEpic)
|
|
}
|
|
|
|
// formatIssueLong formats a single issue in long format to a buffer.
|
|
// When labelsSkipped is true (AD-02 --skip-labels), the Labels: line shows
|
|
// "(suppressed by --skip-labels)" instead of the (empty) hydration result.
|
|
func formatIssueLong(buf *strings.Builder, issue *types.Issue, labels []string, labelsSkipped bool) {
|
|
status := string(issue.Status)
|
|
if status == "closed" {
|
|
line := fmt.Sprintf("%s%s [P%d] [%s] %s\n %s",
|
|
pinIndicator(issue), issue.ID, issue.Priority,
|
|
issue.IssueType, status, issue.Title)
|
|
buf.WriteString(ui.RenderClosedLine(line))
|
|
buf.WriteString("\n")
|
|
} else {
|
|
buf.WriteString(fmt.Sprintf("%s%s [%s] [%s] %s\n",
|
|
pinIndicator(issue),
|
|
ui.RenderID(issue.ID),
|
|
ui.RenderPriority(issue.Priority),
|
|
ui.RenderType(string(issue.IssueType)),
|
|
ui.RenderStatus(status)))
|
|
buf.WriteString(fmt.Sprintf(" %s\n", issue.Title))
|
|
}
|
|
if issue.Assignee != "" {
|
|
buf.WriteString(fmt.Sprintf(" Assignee: %s\n", issue.Assignee))
|
|
}
|
|
// This is the one text rendering in the tree that prints a field --brief
|
|
// drops, so it is the one that has to say so. Keyed off the ROW, not off
|
|
// the flag: IsLitePartial travels with the issue, so a row that arrived
|
|
// projected reads the same here whichever door set it. Without this the
|
|
// listing is indistinguishable from one whose issues have no description,
|
|
// which is the ambiguity the flag is otherwise careful to avoid.
|
|
if issue.IsLitePartial {
|
|
buf.WriteString(" Description: (omitted by --brief)\n")
|
|
} else if desc := strings.TrimSpace(issue.Description); desc != "" {
|
|
buf.WriteString(" Description:\n")
|
|
for _, line := range strings.Split(desc, "\n") {
|
|
buf.WriteString(fmt.Sprintf(" %s\n", line))
|
|
}
|
|
}
|
|
if labelsSkipped {
|
|
buf.WriteString(" Labels: (suppressed by --skip-labels)\n")
|
|
} else if len(labels) > 0 {
|
|
buf.WriteString(fmt.Sprintf(" Labels: %v\n", labels))
|
|
}
|
|
if hasCustomMetadata(issue) {
|
|
if n := countMetadataKeys(issue); n > 0 {
|
|
buf.WriteString(fmt.Sprintf(" Metadata: %d keys\n", n))
|
|
} else {
|
|
buf.WriteString(" Metadata: set\n")
|
|
}
|
|
}
|
|
buf.WriteString("\n")
|
|
}
|
|
|
|
// formatAgentIssue formats a single issue in ultra-compact agent mode format
|
|
// Output: "ID: Title" with optional dependency info
|
|
// "(parent: X, blocked by: Y, blocks: Z, gated by: G)"
|
|
//
|
|
// Agent mode has no glyph column, so the gate rides in the parenthetical the
|
|
// line already carries (wy-j2upyy). It is the seat that most needs it:
|
|
// ui.IsAgentMode() is true whenever CLAUDE_CODE is set, and an agent reading a
|
|
// plain row cannot tell startable work from work a human has to release.
|
|
func formatAgentIssue(buf *strings.Builder, issue *types.Issue, blockedBy, blocks []string, parent string, gatedBy []string) {
|
|
depInfo := formatDependencyInfo(blockedBy, blocks, parent, gatedBy)
|
|
if depInfo != "" {
|
|
buf.WriteString(fmt.Sprintf("%s: %s %s\n", issue.ID, issue.Title, depInfo))
|
|
} else {
|
|
buf.WriteString(fmt.Sprintf("%s: %s\n", issue.ID, issue.Title))
|
|
}
|
|
}
|
|
|
|
// formatDependencyInfo formats dependency info for list output.
|
|
// Parent-child deps are shown as "parent: X" (structural), separate from "blocked by" (blocking). (bd-hcxu)
|
|
// Returns "(parent: X, blocked by: Y, blocks: Z, gated by: G)" or "" if no dependencies.
|
|
//
|
|
// A gate is also a blocker, so its id appears under BOTH "blocked by" and
|
|
// "gated by". The repetition is the point: "blocked by" says what to wait on,
|
|
// "gated by" says which of those is a gate — work nobody can start by doing
|
|
// more work. The clause is present exactly when the ONE predicate selected a
|
|
// gate (types.GateIsHolding + types.SubjectCanBeGated).
|
|
func formatDependencyInfo(blockedBy, blocks []string, parent string, gatedBy []string) string {
|
|
if len(blockedBy) == 0 && len(blocks) == 0 && parent == "" && len(gatedBy) == 0 {
|
|
return ""
|
|
}
|
|
|
|
var parts []string
|
|
if parent != "" {
|
|
parts = append(parts, fmt.Sprintf("parent: %s", parent))
|
|
}
|
|
if len(blockedBy) > 0 {
|
|
parts = append(parts, fmt.Sprintf("blocked by: %s", strings.Join(blockedBy, ", ")))
|
|
}
|
|
if len(blocks) > 0 {
|
|
parts = append(parts, fmt.Sprintf("blocks: %s", strings.Join(blocks, ", ")))
|
|
}
|
|
if len(gatedBy) > 0 {
|
|
parts = append(parts, fmt.Sprintf("gated by: %s", strings.Join(gatedBy, ", ")))
|
|
}
|
|
return "(" + strings.Join(parts, ", ") + ")"
|
|
}
|
|
|
|
// buildBlockingMaps builds maps of blocking dependencies from dependency records.
|
|
// Returns three maps: blockedByMap[issueID] = []IDs that block this issue,
|
|
// blocksMap[issueID] = []IDs that this issue blocks (excluding parent-child),
|
|
// and childrenMap[issueID] = []IDs that are children of this issue.
|
|
// Only includes dependencies where AffectsReadyWork() is true (blocks, parent-child, etc.)
|
|
//
|
|
// closedIDs is an optional set of issue IDs known to be closed. When provided,
|
|
// closed blockers are excluded from blockedByMap so that "blocked by" annotations
|
|
// only show active (open) blockers. This prevents stale annotations like
|
|
// "(blocked by: X)" when X has already been closed.
|
|
func buildBlockingMaps(allDeps map[string][]*types.Dependency, closedIDs map[string]bool) (blockedByMap, blocksMap, childrenMap map[string][]string) {
|
|
blockedByMap = make(map[string][]string)
|
|
blocksMap = make(map[string][]string)
|
|
childrenMap = make(map[string][]string)
|
|
|
|
for issueID, deps := range allDeps {
|
|
for _, dep := range deps {
|
|
// Only include blocking dependencies
|
|
if !dep.Type.AffectsReadyWork() {
|
|
continue
|
|
}
|
|
// Skip closed blockers in "blocked by" annotations — the dependency
|
|
// record is preserved, but a closed blocker no longer blocks work.
|
|
isClosed := closedIDs != nil && closedIDs[dep.DependsOnID]
|
|
if !isClosed {
|
|
blockedByMap[issueID] = append(blockedByMap[issueID], dep.DependsOnID)
|
|
}
|
|
// Separate parent-child from blocking relationships
|
|
if dep.Type == types.DepParentChild {
|
|
childrenMap[dep.DependsOnID] = append(childrenMap[dep.DependsOnID], issueID)
|
|
} else if !isClosed {
|
|
blocksMap[dep.DependsOnID] = append(blocksMap[dep.DependsOnID], issueID)
|
|
}
|
|
}
|
|
}
|
|
return blockedByMap, blocksMap, childrenMap
|
|
}
|
|
|
|
// getClosedBlockerIDs collects all unique blocker IDs from dependency records
|
|
// and returns the subset that are closed or unreachable. This is used to filter
|
|
// stale "blocked by" annotations in bd list output.
|
|
func getClosedBlockerIDs(ctx context.Context, s storage.DoltStorage, allDeps map[string][]*types.Dependency) map[string]bool {
|
|
// Collect unique blocker IDs
|
|
blockerIDs := make(map[string]bool)
|
|
for _, deps := range allDeps {
|
|
for _, dep := range deps {
|
|
if dep.Type.AffectsReadyWork() {
|
|
blockerIDs[dep.DependsOnID] = true
|
|
}
|
|
}
|
|
}
|
|
|
|
closedIDs := make(map[string]bool)
|
|
for id := range blockerIDs {
|
|
issue, err := s.GetIssue(ctx, id)
|
|
if err != nil || issue == nil {
|
|
// Treat missing or unreachable blockers as resolved — a blocker
|
|
// that cannot be fetched cannot block work, matching the behavior
|
|
// of computeBlockedIDs which only considers active issues.
|
|
closedIDs[id] = true
|
|
continue
|
|
}
|
|
if issue.Status == types.StatusClosed {
|
|
closedIDs[id] = true
|
|
}
|
|
}
|
|
return closedIDs
|
|
}
|
|
|
|
// formatIssueCompact formats a single issue in compact format to a buffer
|
|
// Uses status icons for better scanability - consistent with bd graph
|
|
// Format: [icon] [pin] ID [Priority] [Type] @assignee [labels] - Title (parent: X, blocked by: Y, blocks: Z)
|
|
func formatIssueCompact(buf *strings.Builder, issue *types.Issue, labels []string, blockedBy, blocks []string, parent string, gatedBy []string) {
|
|
labelsStr := ""
|
|
if len(labels) > 0 {
|
|
labelsStr = fmt.Sprintf(" %v", labels)
|
|
}
|
|
assigneeStr := ""
|
|
if issue.Assignee != "" {
|
|
assigneeStr = fmt.Sprintf(" @%s", issue.Assignee)
|
|
}
|
|
|
|
// Format dependency info
|
|
depInfo := formatDependencyInfo(blockedBy, blocks, parent, gatedBy)
|
|
if depInfo != "" {
|
|
depInfo = " " + depInfo
|
|
}
|
|
|
|
// Get styled status icon — override to blocked when issue has open blockers (GH#2858)
|
|
statusIcon := renderStatusIcon(issue.Status)
|
|
if len(blockedBy) > 0 && issue.Status == types.StatusOpen {
|
|
statusIcon = renderStatusIcon(types.StatusBlocked)
|
|
}
|
|
// A gate is a blocker a reader cannot see in the row, so it takes the
|
|
// column back off ● (wy-j2upyy). Same predicate as the tree view's glyph.
|
|
if len(gatedBy) > 0 && types.SubjectCanBeGated(issue) {
|
|
statusIcon = ui.StatusBlockedStyle.Render(ui.StatusIconGated)
|
|
}
|
|
|
|
if issue.Status == types.StatusClosed {
|
|
// Closed issues: entire line muted (fades visually)
|
|
line := fmt.Sprintf("%s %s%s [P%d] [%s]%s%s - %s%s",
|
|
statusIcon, pinIndicator(issue), issue.ID, issue.Priority,
|
|
issue.IssueType, assigneeStr, labelsStr, issue.Title, depInfo)
|
|
buf.WriteString(ui.RenderClosedLine(line))
|
|
buf.WriteString("\n")
|
|
} else {
|
|
// Active issues: status icon + semantic colors for priority/type
|
|
buf.WriteString(fmt.Sprintf("%s %s%s [%s] [%s]%s%s - %s%s\n",
|
|
statusIcon,
|
|
pinIndicator(issue),
|
|
ui.RenderID(issue.ID),
|
|
ui.RenderPriority(issue.Priority),
|
|
ui.RenderType(string(issue.IssueType)),
|
|
assigneeStr, labelsStr, issue.Title, depInfo))
|
|
}
|
|
}
|
|
|
|
// hasCustomMetadata returns true if the issue has non-empty custom metadata.
|
|
func hasCustomMetadata(issue *types.Issue) bool {
|
|
if len(issue.Metadata) == 0 {
|
|
return false
|
|
}
|
|
trimmed := strings.TrimSpace(string(issue.Metadata))
|
|
return trimmed != "{}" && trimmed != "null"
|
|
}
|
|
|
|
// countMetadataKeys returns the number of top-level keys in the issue's metadata JSON.
|
|
func countMetadataKeys(issue *types.Issue) int {
|
|
var data map[string]json.RawMessage
|
|
if err := json.Unmarshal(issue.Metadata, &data); err != nil {
|
|
return 0
|
|
}
|
|
return len(data)
|
|
}
|