fix(init): respect BEADS_DIR environment variable (#1273)

* fix(sync): read sync.mode from yaml first, then database

bd config set sync.mode writes to config.yaml (because sync.* is a
yaml-only prefix), but GetSyncMode() only read from the database.

This caused dolt-native mode to be ignored - JSONL export still
happened because the database had no sync.mode value.

Now GetSyncMode() checks config.yaml first (via config.GetSyncMode()),
falling back to database for backward compatibility.

Fixes: oss-5ca279

* fix(init): respect BEADS_DIR environment variable

Problem:
- `bd init` ignored BEADS_DIR when checking for existing data
- `bd init` created database at CWD/.beads instead of BEADS_DIR
- Contributor wizard used ~/.beads-planning as default, ignoring BEADS_DIR

Solution:
- Add BEADS_DIR check in checkExistingBeadsData() (matches FindBeadsDir pattern)
- Compute beadsDirForInit early, before initDBPath determination
- Use BEADS_DIR as default in contributor wizard when set
- Preserve precedence: --db > BEADS_DB > BEADS_DIR > default

Impact:
- Users with BEADS_DIR set now get consistent behavior across all bd commands
- ACF-style fork tracking (external .beads directory) now works correctly

Fixes: steveyegge/beads#???

* fix(doctor): respect BEADS_DIR environment variable

Also updates documentation to reflect BEADS_DIR support in init and doctor.

Changes:
- doctor.go: Check BEADS_DIR before falling back to CWD
- doctor_test.go: Add tests for BEADS_DIR path resolution
- WORKTREES.md: Document simplified BEADS_DIR+init workflow
- CONTRIBUTOR_NAMESPACE_ISOLATION.md: Note init/doctor BEADS_DIR support

* test(init): add BEADS_DB > BEADS_DIR precedence test

Verifies that BEADS_DB env var takes precedence over BEADS_DIR
when both are set, ensuring the documented precedence order:
--db > BEADS_DB > BEADS_DIR > default

* chore: fill in GH#1277 placeholder in sync_mode comment
This commit is contained in:
Peter Chanthamynavong
2026-01-24 17:10:05 -08:00
committed by GitHub
parent 810192157c
commit b7d650bd8e
8 changed files with 674 additions and 94 deletions

View File

@@ -48,10 +48,17 @@ const (
TriggerChange = "change"
)
// GetSyncMode returns the configured sync mode from the database, defaulting to git-portable.
// This reads from storage.Storage (database), not config.yaml.
// For config.yaml access, use config.GetSyncMode() instead.
// GetSyncMode returns the configured sync mode, checking config.yaml first (where bd config set writes),
// then falling back to database. This fixes GH#1277 where yaml and database were inconsistent.
func GetSyncMode(ctx context.Context, s storage.Storage) string {
// First check config.yaml (where bd config set writes for sync.* keys)
yamlMode := config.GetSyncMode()
if yamlMode != "" && yamlMode != config.SyncModeGitPortable {
// Non-default value in yaml takes precedence
return string(yamlMode)
}
// Fall back to database (legacy path)
mode, err := s.GetConfig(ctx, SyncModeConfigKey)
if err != nil || mode == "" {
return SyncModeGitPortable