From b45e68c5ceae24e6cebbf7bab4630e53bd4f67c2 Mon Sep 17 00:00:00 2001 From: Steve Yegge Date: Tue, 30 Dec 2025 15:59:11 -0800 Subject: [PATCH] Add BD_AGENT_MODE for ultra-compact output MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adds agent-optimized output mode for `bd list` triggered by: - BD_AGENT_MODE=1 environment variable (explicit) - CLAUDE_CODE environment variable (auto-detect) Agent mode provides: - Ultra-compact format: just "ID: Title" per line - Lower default limit (20 vs 50) for context efficiency - No colors, no emojis, no pager - Defaults to open/in_progress only (existing behavior) (bd-x2ht) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 --- cmd/bd/list.go | 27 +++++++++++++++++++++++++-- internal/ui/styles.go | 18 ++++++++++++++++++ internal/ui/styles_test.go | 23 +++++++++++++++++++++++ 3 files changed, 66 insertions(+), 2 deletions(-) diff --git a/cmd/bd/list.go b/cmd/bd/list.go index 4b14e2a8..1446f85b 100644 --- a/cmd/bd/list.go +++ b/cmd/bd/list.go @@ -333,6 +333,12 @@ func formatIssueLong(buf *strings.Builder, issue *types.Issue, labels []string) buf.WriteString("\n") } +// formatAgentIssue formats a single issue in ultra-compact agent mode format +// Output: just "ID: Title" - no colors, no emojis, no brackets +func formatAgentIssue(buf *strings.Builder, issue *types.Issue) { + buf.WriteString(fmt.Sprintf("%s: %s\n", issue.ID, issue.Title)) +} + // formatIssueCompact formats a single issue in compact format to a buffer func formatIssueCompact(buf *strings.Builder, issue *types.Issue, labels []string) { labelsStr := "" @@ -451,9 +457,12 @@ var listCmd = &cobra.Command{ // Handle limit: --limit 0 means unlimited (explicit override) // Otherwise use the value (default 50 or user-specified) + // Agent mode uses lower default (20) for context efficiency effectiveLimit := limit if cmd.Flags().Changed("limit") && limit == 0 { effectiveLimit = 0 // Explicit unlimited + } else if !cmd.Flags().Changed("limit") && ui.IsAgentMode() { + effectiveLimit = 20 // Agent mode default } filter := types.IssueFilter{ @@ -743,7 +752,14 @@ var listCmd = &cobra.Command{ // Build output in buffer for pager support (bd-jdz3) var buf strings.Builder - if longFormat { + if ui.IsAgentMode() { + // Agent mode: ultra-compact, no colors, no pager + for _, issue := range issues { + formatAgentIssue(&buf, issue) + } + fmt.Print(buf.String()) + return + } else if longFormat { // Long format: multi-line with details buf.WriteString(fmt.Sprintf("\nFound %d issues:\n\n", len(issues))) for _, issue := range issues { @@ -859,7 +875,14 @@ var listCmd = &cobra.Command{ // Build output in buffer for pager support (bd-jdz3) var buf strings.Builder - if longFormat { + if ui.IsAgentMode() { + // Agent mode: ultra-compact, no colors, no pager + for _, issue := range issues { + formatAgentIssue(&buf, issue) + } + fmt.Print(buf.String()) + return + } else if longFormat { // Long format: multi-line with details buf.WriteString(fmt.Sprintf("\nFound %d issues:\n\n", len(issues))) for _, issue := range issues { diff --git a/internal/ui/styles.go b/internal/ui/styles.go index eded5ed4..d697453a 100644 --- a/internal/ui/styles.go +++ b/internal/ui/styles.go @@ -4,6 +4,7 @@ package ui import ( "fmt" + "os" "strings" "github.com/charmbracelet/lipgloss" @@ -17,6 +18,23 @@ func init() { } } +// IsAgentMode returns true if the CLI is running in agent-optimized mode. +// This is triggered by: +// - BD_AGENT_MODE=1 environment variable (explicit) +// - CLAUDE_CODE environment variable (auto-detect Claude Code) +// +// Agent mode provides ultra-compact output optimized for LLM context windows. +func IsAgentMode() bool { + if os.Getenv("BD_AGENT_MODE") == "1" { + return true + } + // Auto-detect Claude Code environment + if os.Getenv("CLAUDE_CODE") != "" { + return true + } + return false +} + // Ayu theme color palette // Dark: https://terminalcolors.com/themes/ayu/dark/ // Light: https://terminalcolors.com/themes/ayu/light/ diff --git a/internal/ui/styles_test.go b/internal/ui/styles_test.go index 4576316a..23dcf00c 100644 --- a/internal/ui/styles_test.go +++ b/internal/ui/styles_test.go @@ -152,3 +152,26 @@ func TestRenderCommandAndCategoryAreUppercaseSafe(t *testing.T) { t.Fatalf("command output missing text: %q", cmd) } } + +func TestIsAgentMode(t *testing.T) { + // Test default (no env vars) - t.Setenv automatically restores after test + t.Setenv("BD_AGENT_MODE", "") + t.Setenv("CLAUDE_CODE", "") + if IsAgentMode() { + t.Fatal("expected false with no env vars") + } + + // Test BD_AGENT_MODE=1 + t.Setenv("BD_AGENT_MODE", "1") + t.Setenv("CLAUDE_CODE", "") + if !IsAgentMode() { + t.Fatal("expected true with BD_AGENT_MODE=1") + } + + // Test CLAUDE_CODE auto-detection + t.Setenv("BD_AGENT_MODE", "") + t.Setenv("CLAUDE_CODE", "something") + if !IsAgentMode() { + t.Fatal("expected true with CLAUDE_CODE set") + } +}