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