Remove the entire multi-rig routing engine (routes.go, route resolution, prefix-based dispatch) and cross-rig commands (move, refile). All bd commands now operate on the local rig only. Deleted: internal/routing/routes.go, cmd/bd/move.go, cmd/bd/refile.go, and 5 associated test files. Simplified: routed.go, close.go, create.go, dep.go, gate.go, list.go, ready.go, promote.go, show.go, show_display.go. Retained: contributor routing (routing.go, routing_read.go) is unchanged. Resolves: bd-8hc5 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
224 lines
6.5 KiB
Go
224 lines
6.5 KiB
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"os"
|
|
"os/signal"
|
|
"strings"
|
|
"syscall"
|
|
"time"
|
|
|
|
"github.com/steveyegge/beads/internal/types"
|
|
"github.com/steveyegge/beads/internal/ui"
|
|
)
|
|
|
|
// displayShowIssue displays a single issue (reusable for watch mode).
|
|
// Matches the full bd show output: header, metadata, content, labels, deps, comments.
|
|
func displayShowIssue(ctx context.Context, issueID string) {
|
|
displayShowIssueReturn(ctx, issueID)
|
|
}
|
|
|
|
// singleIssueSnapshot builds a comparable string from a single issue's state
|
|
// so we can detect when the issue has changed between poll cycles.
|
|
func singleIssueSnapshot(issue *types.Issue) string {
|
|
return fmt.Sprintf("%s:%s:%d", issue.ID, issue.Status, issue.UpdatedAt.UnixNano())
|
|
}
|
|
|
|
// watchIssue polls for changes to an issue and auto-refreshes the display (GH#654).
|
|
// Uses polling instead of fsnotify because Dolt stores data in a server-side
|
|
// database, not files — file watchers never fire.
|
|
func watchIssue(ctx context.Context, issueID string) {
|
|
// Initial display and snapshot
|
|
issue := displayShowIssueReturn(ctx, issueID)
|
|
if issue == nil {
|
|
return
|
|
}
|
|
lastSnapshot := singleIssueSnapshot(issue)
|
|
|
|
fmt.Fprintf(os.Stderr, "\nWatching for changes... (Press Ctrl+C to exit)\n")
|
|
|
|
// Handle Ctrl+C — deferred Stop prevents signal handler leak
|
|
sigChan := make(chan os.Signal, 1)
|
|
signal.Notify(sigChan, os.Interrupt, syscall.SIGTERM)
|
|
defer signal.Stop(sigChan)
|
|
|
|
pollInterval := 2 * time.Second
|
|
ticker := time.NewTicker(pollInterval)
|
|
defer ticker.Stop()
|
|
|
|
for {
|
|
select {
|
|
case <-sigChan:
|
|
fmt.Fprintf(os.Stderr, "\nStopped watching.\n")
|
|
return
|
|
case <-ticker.C:
|
|
issue := fetchIssue(ctx, issueID)
|
|
if issue == nil {
|
|
continue
|
|
}
|
|
snap := singleIssueSnapshot(issue)
|
|
if snap != lastSnapshot {
|
|
lastSnapshot = snap
|
|
displayShowIssue(ctx, issueID)
|
|
fmt.Fprintf(os.Stderr, "\nWatching for changes... (Press Ctrl+C to exit)\n")
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// fetchIssue retrieves a single issue by ID, returning nil on error.
|
|
func fetchIssue(ctx context.Context, issueID string) *types.Issue {
|
|
result, err := resolveAndGetIssueWithRouting(ctx, store, issueID)
|
|
if result != nil {
|
|
defer result.Close()
|
|
}
|
|
if err != nil || result == nil || result.Issue == nil {
|
|
return nil
|
|
}
|
|
return result.Issue
|
|
}
|
|
|
|
// displayShowIssueReturn displays a single issue and returns it for snapshot use.
|
|
func displayShowIssueReturn(ctx context.Context, issueID string) *types.Issue {
|
|
result, err := resolveAndGetIssueWithRouting(ctx, store, issueID)
|
|
if result != nil {
|
|
defer result.Close()
|
|
}
|
|
if err != nil {
|
|
fmt.Fprintf(os.Stderr, "Error fetching issue: %v\n", err)
|
|
return nil
|
|
}
|
|
if result == nil || result.Issue == nil {
|
|
fmt.Printf("Issue not found: %s\n", issueID)
|
|
return nil
|
|
}
|
|
issue := result.Issue
|
|
issueStore := result.Store
|
|
|
|
// Display the issue header and metadata
|
|
fmt.Println(formatIssueHeader(issue))
|
|
fmt.Println(formatIssueMetadata(issue))
|
|
|
|
// Content sections (matches standard bd show order)
|
|
if issue.Description != "" {
|
|
fmt.Printf("\n%s\n%s\n", ui.RenderBold("DESCRIPTION"), ui.RenderMarkdown(issue.Description))
|
|
}
|
|
if issue.Design != "" {
|
|
fmt.Printf("\n%s\n%s\n", ui.RenderBold("DESIGN"), ui.RenderMarkdown(issue.Design))
|
|
}
|
|
if issue.Notes != "" {
|
|
fmt.Printf("\n%s\n%s\n", ui.RenderBold("NOTES"), ui.RenderMarkdown(issue.Notes))
|
|
}
|
|
if issue.AcceptanceCriteria != "" {
|
|
fmt.Printf("\n%s\n%s\n", ui.RenderBold("ACCEPTANCE CRITERIA"), ui.RenderMarkdown(issue.AcceptanceCriteria))
|
|
}
|
|
|
|
// Labels
|
|
labels, _ := issueStore.GetLabels(ctx, issue.ID)
|
|
if len(labels) > 0 {
|
|
fmt.Printf("\n%s %s\n", ui.RenderBold("LABELS:"), strings.Join(labels, ", "))
|
|
}
|
|
|
|
// Dependencies (what this issue depends on)
|
|
relatedSeen := make(map[string]*types.IssueWithDependencyMetadata)
|
|
depsWithMeta, _ := issueStore.GetDependenciesWithMetadata(ctx, issue.ID)
|
|
|
|
if len(depsWithMeta) > 0 {
|
|
var blocks, parent, discovered []*types.IssueWithDependencyMetadata
|
|
for _, dep := range depsWithMeta {
|
|
switch dep.DependencyType {
|
|
case types.DepBlocks:
|
|
blocks = append(blocks, dep)
|
|
case types.DepParentChild:
|
|
parent = append(parent, dep)
|
|
case types.DepRelated, types.DepRelatesTo:
|
|
relatedSeen[dep.ID] = dep
|
|
case types.DepDiscoveredFrom:
|
|
discovered = append(discovered, dep)
|
|
default:
|
|
blocks = append(blocks, dep)
|
|
}
|
|
}
|
|
if len(parent) > 0 {
|
|
fmt.Printf("\n%s\n", ui.RenderBold("PARENT"))
|
|
for _, dep := range parent {
|
|
fmt.Println(formatDependencyLine("↑", dep))
|
|
}
|
|
}
|
|
if len(blocks) > 0 {
|
|
fmt.Printf("\n%s\n", ui.RenderBold("DEPENDS ON"))
|
|
for _, dep := range blocks {
|
|
fmt.Println(formatDependencyLine("→", dep))
|
|
}
|
|
}
|
|
if len(discovered) > 0 {
|
|
fmt.Printf("\n%s\n", ui.RenderBold("DISCOVERED FROM"))
|
|
for _, dep := range discovered {
|
|
fmt.Println(formatDependencyLine("◊", dep))
|
|
}
|
|
}
|
|
}
|
|
|
|
// Dependents (what depends on this issue)
|
|
dependentsWithMeta, _ := issueStore.GetDependentsWithMetadata(ctx, issue.ID)
|
|
if len(dependentsWithMeta) > 0 {
|
|
var blocks, children, discovered []*types.IssueWithDependencyMetadata
|
|
for _, dep := range dependentsWithMeta {
|
|
switch dep.DependencyType {
|
|
case types.DepBlocks:
|
|
blocks = append(blocks, dep)
|
|
case types.DepParentChild:
|
|
children = append(children, dep)
|
|
case types.DepRelated, types.DepRelatesTo:
|
|
relatedSeen[dep.ID] = dep
|
|
case types.DepDiscoveredFrom:
|
|
discovered = append(discovered, dep)
|
|
default:
|
|
blocks = append(blocks, dep)
|
|
}
|
|
}
|
|
if len(children) > 0 {
|
|
fmt.Printf("\n%s\n", ui.RenderBold("CHILDREN"))
|
|
for _, dep := range children {
|
|
fmt.Println(formatDependencyLine("↳", dep))
|
|
}
|
|
}
|
|
if len(blocks) > 0 {
|
|
fmt.Printf("\n%s\n", ui.RenderBold("BLOCKS"))
|
|
for _, dep := range blocks {
|
|
fmt.Println(formatDependencyLine("←", dep))
|
|
}
|
|
}
|
|
if len(discovered) > 0 {
|
|
fmt.Printf("\n%s\n", ui.RenderBold("DISCOVERED"))
|
|
for _, dep := range discovered {
|
|
fmt.Println(formatDependencyLine("◊", dep))
|
|
}
|
|
}
|
|
}
|
|
|
|
// Related (bidirectional, deduplicated)
|
|
if len(relatedSeen) > 0 {
|
|
fmt.Printf("\n%s\n", ui.RenderBold("RELATED"))
|
|
for _, dep := range relatedSeen {
|
|
fmt.Println(formatDependencyLine("↔", dep))
|
|
}
|
|
}
|
|
|
|
// Comments
|
|
comments, _ := issueStore.GetIssueComments(ctx, issue.ID)
|
|
if len(comments) > 0 {
|
|
fmt.Printf("\n%s\n", ui.RenderBold("COMMENTS"))
|
|
for _, comment := range comments {
|
|
fmt.Printf(" %s %s\n", ui.RenderMuted(comment.CreatedAt.UTC().Format("2006-01-02 15:04")), comment.Author)
|
|
rendered := ui.RenderMarkdown(comment.Text)
|
|
for _, line := range strings.Split(strings.TrimRight(rendered, "\n"), "\n") {
|
|
fmt.Printf(" %s\n", line)
|
|
}
|
|
}
|
|
}
|
|
|
|
fmt.Println()
|
|
return issue
|
|
}
|