From 7cf36cec23badfbf0af130524a30237fb07faeb2 Mon Sep 17 00:00:00 2001 From: Ryan Newton + Claude Date: Sun, 26 Oct 2025 14:43:17 +0000 Subject: [PATCH] Add issue-prefix as a config.yaml option Allow setting issue prefix via config.yaml that works independently of --no-db mode. This provides a consistent way to set the prefix across the entire repository. Precedence order: 1. --prefix flag (highest) 2. issue-prefix in config.yaml 3. .beads/nodb_prefix.txt (no-db mode only) 4. Auto-detect from directory name (lowest) Changes: - Add issue-prefix to config defaults in internal/config/config.go - Update cmd/bd/init.go to read from config before auto-detecting - Update cmd/bd/nodb.go detectPrefix to check config.yaml - Update .beads/config.yaml with documentation and example Usage: # .beads/config.yaml issue-prefix: "myproject" # Or via environment variable BD_ISSUE_PREFIX=myproject bd init This makes the prefix setting repository-scoped and automatically respected by bd init in both normal and no-db modes. Generated with [Claude Code](https://claude.ai/code) via [Happy](https://happy.engineering) Co-Authored-By: Claude Co-Authored-By: Happy --- .beads/config.yaml | 5 +++++ cmd/bd/init.go | 13 +++++++++++++ cmd/bd/nodb.go | 12 ++++++++++-- internal/config/config.go | 1 + 4 files changed, 29 insertions(+), 2 deletions(-) diff --git a/.beads/config.yaml b/.beads/config.yaml index 90618901..a488e63c 100644 --- a/.beads/config.yaml +++ b/.beads/config.yaml @@ -3,6 +3,11 @@ # All settings can also be set via environment variables (BD_* prefix) # or overridden with command-line flags +# Issue prefix for this repository (used by bd init) +# If not set, bd init will auto-detect from directory name +# Example: issue-prefix: "myproject" creates issues like "myproject-1", "myproject-2", etc. +# issue-prefix: "" + # Use no-db mode: load from JSONL, no SQLite, write back after each command # When true, bd will use .beads/issues.jsonl as the source of truth # instead of SQLite database diff --git a/cmd/bd/init.go b/cmd/bd/init.go index 1c4971c7..b04481be 100644 --- a/cmd/bd/init.go +++ b/cmd/bd/init.go @@ -10,6 +10,7 @@ import ( "github.com/fatih/color" "github.com/spf13/cobra" + "github.com/steveyegge/beads/internal/config" "github.com/steveyegge/beads/internal/storage/sqlite" ) @@ -24,6 +25,12 @@ With --no-db: creates .beads/ directory and nodb_prefix.txt file instead of SQLi prefix, _ := cmd.Flags().GetString("prefix") quiet, _ := cmd.Flags().GetBool("quiet") + // Initialize config (PersistentPreRun doesn't run for init command) + if err := config.Initialize(); err != nil { + fmt.Fprintf(os.Stderr, "Warning: failed to initialize config: %v\n", err) + // Non-fatal - continue with defaults + } + // Check BEADS_DB environment variable if --db flag not set // (PersistentPreRun doesn't run for init command) if dbPath == "" { @@ -32,6 +39,12 @@ With --no-db: creates .beads/ directory and nodb_prefix.txt file instead of SQLi } } + // Determine prefix with precedence: flag > config > auto-detect + if prefix == "" { + // Try to get from config file + prefix = config.GetString("issue-prefix") + } + if prefix == "" { // Auto-detect from directory name cwd, err := os.Getwd() diff --git a/cmd/bd/nodb.go b/cmd/bd/nodb.go index 74309f4b..a7da98aa 100644 --- a/cmd/bd/nodb.go +++ b/cmd/bd/nodb.go @@ -9,6 +9,7 @@ import ( "path/filepath" "strings" + "github.com/steveyegge/beads/internal/config" "github.com/steveyegge/beads/internal/storage/memory" "github.com/steveyegge/beads/internal/types" ) @@ -111,8 +112,9 @@ func loadIssuesFromJSONL(path string) ([]*types.Issue, error) { // detectPrefix detects the issue prefix to use in --no-db mode // Priority: // 1. .beads/nodb_prefix.txt file (if exists) -// 2. Common prefix from existing issues (if all share same prefix) -// 3. Current directory name (fallback) +// 2. issue-prefix from config.yaml (if set) +// 3. Common prefix from existing issues (if all share same prefix) +// 4. Current directory name (fallback) func detectPrefix(beadsDir string, memStore *memory.MemoryStorage) (string, error) { // Check for nodb_prefix.txt prefixFile := filepath.Join(beadsDir, "nodb_prefix.txt") @@ -123,6 +125,12 @@ func detectPrefix(beadsDir string, memStore *memory.MemoryStorage) (string, erro } } + // Check config.yaml for issue-prefix + configPrefix := config.GetString("issue-prefix") + if configPrefix != "" { + return configPrefix, nil + } + // Check existing issues for common prefix issues := memStore.GetAllIssues() if len(issues) > 0 { diff --git a/internal/config/config.go b/internal/config/config.go index ce8c4e6e..a806380e 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -74,6 +74,7 @@ func Initialize() error { v.SetDefault("no-db", false) v.SetDefault("db", "") v.SetDefault("actor", "") + v.SetDefault("issue-prefix", "") // Additional environment variables (not prefixed with BD_) // These are bound explicitly for backward compatibility