gitgram/aitimemachine/beads/cmd/bd/show_display.go
caelum0x 49b183818c Unify gitgram + aitimemachine into the monorepo (de-submodule) and merge vendored engines
Convert gitgram/ and aitimemachine/ from embedded git repos (which showed as
opaque submodule gitlinks on GitHub) into fully-tracked first-party content.

AITM now merges its 7 vendored repos as first-party engines:
- memory: beads (Go task DAG) + context7 (docs SDK), unified into saved_contexts
- git: vendored C git (bundled binary) + gitnexus (in-process code intelligence)
- agentic: a2a (@a2a-js/sdk) + pal (AITM-managed Python subprocess)

Includes the full session's product build: Gitgram web/mobile/backend features,
AITM website/CLI/MCP, the unified memory layer, engine build tooling
(scripts/build-engines.sh, Dockerfile, CI), docs (README, ENGINES.md, ARCHITECTURE.md),
and extensive test suites.

Build artifacts, node_modules, external/, and gemini-cli are gitignored.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-23 14:14:09 +03:00

226 lines
6.6 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"
"github.com/steveyegge/beads/internal/uimd"
)
// 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"), uimd.RenderMarkdown(issue.Description))
}
if issue.Design != "" {
fmt.Printf("\n%s\n%s\n", ui.RenderBold("DESIGN"), uimd.RenderMarkdown(issue.Design))
}
if issue.Notes != "" {
fmt.Printf("\n%s\n%s\n", ui.RenderBold("NOTES"), uimd.RenderMarkdown(issue.Notes))
}
if issue.AcceptanceCriteria != "" {
fmt.Printf("\n%s\n%s\n", ui.RenderBold("ACCEPTANCE CRITERIA"), uimd.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 := uimd.RenderMarkdown(comment.Text)
for _, line := range strings.Split(strings.TrimRight(rendered, "\n"), "\n") {
fmt.Printf(" %s\n", line)
}
}
}
fmt.Println()
return issue
}