Add BD_AGENT_MODE for ultra-compact output
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 <noreply@anthropic.com>
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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/
|
||||
|
||||
@@ -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")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user