refactor(output): simplify title-length semantics and default to 255

This commit is contained in:
Pablo LION 2026-02-26 19:46:27 +01:00
commit 332b4f457b
5 changed files with 31 additions and 11 deletions

View file

@ -24,17 +24,15 @@ func formatFeedbackIDParen(id, title string) string {
}
// applyTitleConfig applies the output.title-length config to a title string.
// Returns empty string when titles should be hidden.
// Returns empty string when titles should be hidden (<= 0).
func applyTitleConfig(title string) string {
if title == "" {
return ""
}
maxLen := config.GetInt("output.title-length")
switch {
case maxLen == 0:
case maxLen <= 0:
return "" // hide titles
case maxLen < 0:
return title // full title
default:
return truncateTitle(title, maxLen)
}

View file

@ -9,6 +9,8 @@ import (
"github.com/steveyegge/beads/internal/types"
)
const defaultTitleLength = 255
func TestFormatFeedbackID(t *testing.T) {
// Ensure config is initialized with defaults
config.ResetForTesting()
@ -34,7 +36,7 @@ func TestFormatFeedbackID(t *testing.T) {
t.Run("title-length=0 hides title", func(t *testing.T) {
config.Set("output.title-length", 0)
t.Cleanup(func() { config.Set("output.title-length", -1) })
t.Cleanup(func() { config.Set("output.title-length", defaultTitleLength) })
got := formatFeedbackID("bd-abc", "Add user authentication")
if got != "bd-abc" {
@ -44,7 +46,7 @@ func TestFormatFeedbackID(t *testing.T) {
t.Run("title-length truncates with ellipsis", func(t *testing.T) {
config.Set("output.title-length", 10)
t.Cleanup(func() { config.Set("output.title-length", -1) })
t.Cleanup(func() { config.Set("output.title-length", defaultTitleLength) })
got := formatFeedbackID("bd-abc", "Add user authentication")
want := "bd-abc — Add user …"
@ -55,7 +57,7 @@ func TestFormatFeedbackID(t *testing.T) {
t.Run("title within limit not truncated", func(t *testing.T) {
config.Set("output.title-length", 50)
t.Cleanup(func() { config.Set("output.title-length", -1) })
t.Cleanup(func() { config.Set("output.title-length", defaultTitleLength) })
got := formatFeedbackID("bd-abc", "Short title")
want := "bd-abc — Short title"
@ -89,7 +91,7 @@ func TestFormatFeedbackIDParen(t *testing.T) {
t.Run("title-length=0 hides title", func(t *testing.T) {
config.Set("output.title-length", 0)
t.Cleanup(func() { config.Set("output.title-length", -1) })
t.Cleanup(func() { config.Set("output.title-length", defaultTitleLength) })
got := formatFeedbackIDParen("bd-abc", "Write tests")
if got != "bd-abc" {
@ -124,7 +126,7 @@ func TestApplyTitleConfig(t *testing.T) {
t.Run("unicode truncation is rune-safe", func(t *testing.T) {
config.Set("output.title-length", 3)
t.Cleanup(func() { config.Set("output.title-length", -1) })
t.Cleanup(func() { config.Set("output.title-length", defaultTitleLength) })
// 4-rune title: truncated to 2 runes + ellipsis (maxLen-1 reserves space for …)
got := applyTitleConfig("日本語文")
@ -133,4 +135,14 @@ func TestApplyTitleConfig(t *testing.T) {
t.Errorf("got %q, want %q", got, want)
}
})
t.Run("negative values hide title", func(t *testing.T) {
config.Set("output.title-length", -1)
t.Cleanup(func() { config.Set("output.title-length", defaultTitleLength) })
got := applyTitleConfig("Hidden title")
if got != "" {
t.Errorf("got %q, want empty", got)
}
})
}

View file

@ -45,6 +45,11 @@ func createConfigYaml(beadsDir string, noDbMode bool, prefix string) error {
# Enable JSON output by default
# json: false
# Feedback title formatting for mutating commands (create/update/close/dep/edit)
# 0 = hide titles, N > 0 = truncate to N characters
# output:
# title-length: 255
# Default actor for audit trails (overridden by BD_ACTOR or --actor)
# actor: ""

View file

@ -199,6 +199,11 @@ directory:
packages/agency: agency
packages/io: io
# Feedback title formatting for mutating commands (GH#1384)
# 0 = hide titles, N > 0 = truncate to N characters
output:
title-length: 255
# Cross-project dependency resolution (bd-h807)
# Maps project names to paths for resolving external: blocked_by references
# Paths can be relative (from cwd) or absolute

View file

@ -198,8 +198,8 @@ func Initialize() error {
// Output configuration (GH#1384)
// Controls title display in command feedback messages.
// -1 = full title, 0 = hide title, N > 0 = truncate to N chars with "…"
v.SetDefault("output.title-length", -1)
// 0 = hide title, N > 0 = truncate to N chars with "…"
v.SetDefault("output.title-length", 255)
// External projects for cross-project dependency resolution (bd-h807)
// Maps project names to paths for resolving external: blocked_by references