From 64678bcb345e2d9bf5f51be8f7922294f2e15c14 Mon Sep 17 00:00:00 2001 From: matt wilkie Date: Wed, 8 Apr 2026 15:55:37 -0700 Subject: [PATCH] fix: show diverged-history guidance on auto-push failure (#3138) * fix: show diverged-history guidance on auto-push failure When dolt auto-push fails with a 'no common ancestor' error, the user only sees a cryptic warning. The explicit 'bd dolt push' and 'bd dolt pull' commands already detect this and print recovery guidance via printDivergedHistoryGuidance(), but the auto-push path did not. Now auto-push also calls isDivergedHistoryErr() and prints the same actionable recovery options (bootstrap, force-push, or re-init). Amp-Thread-ID: https://ampcode.com/threads/T-019d6ee7-e46d-74f8-8b6e-2a0fc1b2d4d7 Co-authored-by: Amp * fix: store secret config keys in config.yaml, not Dolt DB Keys like github.token and linear.api_key were stored in the Dolt database's config table. When auto-push sends that data to a GitHub remote, GitHub's push protection blocks the push because it detects embedded secrets in the Dolt data files. Fix: add github.token and linear.api_key to YamlOnlyKeys so they're written to .beads/config.yaml (local-only, gitignored) instead of the Dolt database. Update the read paths in getGitHubConfigValue() and getLinearConfig() to check YAML config first for these keys. Amp-Thread-ID: https://ampcode.com/threads/T-019d6ee7-e46d-74f8-8b6e-2a0fc1b2d4d7 Co-authored-by: Amp --------- Co-authored-by: Amp --- cmd/bd/dolt_autopush.go | 3 +++ cmd/bd/github.go | 16 ++++++++++++++++ cmd/bd/linear.go | 15 +++++++++++++++ cmd/bd/store_reopen_test.go | 13 ++++++------- internal/config/yaml_config.go | 6 ++++++ internal/config/yaml_config_test.go | 5 ++++- 6 files changed, 50 insertions(+), 8 deletions(-) diff --git a/cmd/bd/dolt_autopush.go b/cmd/bd/dolt_autopush.go index 82130d2db..de0a99ea6 100644 --- a/cmd/bd/dolt_autopush.go +++ b/cmd/bd/dolt_autopush.go @@ -142,6 +142,9 @@ func maybeAutoPush(ctx context.Context) { if err := st.Push(ctx); err != nil { if !isQuiet() && !jsonOutput { fmt.Fprintf(os.Stderr, "Warning: dolt auto-push failed: %v\n", err) + if isDivergedHistoryErr(err) { + printDivergedHistoryGuidance("push") + } } debug.Logf("dolt auto-push: push error: %v\n", err) return diff --git a/cmd/bd/github.go b/cmd/bd/github.go index c9f2a9c46..b44638f0b 100644 --- a/cmd/bd/github.go +++ b/cmd/bd/github.go @@ -187,6 +187,22 @@ func getGitHubConfig() GitHubConfig { // getGitHubConfigValue reads a GitHub configuration value from store or environment. func getGitHubConfigValue(ctx context.Context, key string) string { + // Secret keys (e.g. github.token) are stored in config.yaml, not the + // Dolt database, to avoid leaking secrets when pushing to remotes. + if config.IsYamlOnlyKey(key) { + if value := config.GetString(key); value != "" { + return value + } + // Fall back to environment variable + envKey := githubConfigToEnvVar(key) + if envKey != "" { + if value := os.Getenv(envKey); value != "" { + return value + } + } + return "" + } + // Try to read from store (works in direct mode) if store != nil { value, _ := store.GetConfig(ctx, key) diff --git a/cmd/bd/linear.go b/cmd/bd/linear.go index e60838a9f..83c025b5a 100644 --- a/cmd/bd/linear.go +++ b/cmd/bd/linear.go @@ -557,6 +557,21 @@ func maskAPIKey(key string) string { // getLinearConfig reads a Linear configuration value. Returns the value and its source. // Priority: project config > environment variable. func getLinearConfig(ctx context.Context, key string) (value string, source string) { + // Secret keys (e.g. linear.api_key) are stored in config.yaml, not the + // Dolt database, to avoid leaking secrets when pushing to remotes. + if config.IsYamlOnlyKey(key) { + if value := config.GetString(key); value != "" { + return value, "project config (config.yaml)" + } + envKey := linearConfigToEnvVar(key) + if envKey != "" { + if value := os.Getenv(envKey); value != "" { + return value, fmt.Sprintf("environment variable (%s)", envKey) + } + } + return "", "" + } + // Try to read from store (works in direct mode) if store != nil { value, _ = store.GetConfig(ctx, key) // Best effort: empty value is valid fallback diff --git a/cmd/bd/store_reopen_test.go b/cmd/bd/store_reopen_test.go index a7539d56c..d80655083 100644 --- a/cmd/bd/store_reopen_test.go +++ b/cmd/bd/store_reopen_test.go @@ -151,6 +151,9 @@ func TestResolveCommandBeadsDir_NoCWDFallbackForExplicitPath(t *testing.T) { } func TestGetGitHubConfigValue_UsesMetadataWhenStoreNil(t *testing.T) { + // github.token is now a YAML-only key (not stored in Dolt DB) to avoid + // leaking secrets when pushing to remotes. Test that the env-var fallback + // still works when the store is nil. originalStore := store originalDBPath := dbPath defer func() { @@ -159,14 +162,10 @@ func TestGetGitHubConfigValue_UsesMetadataWhenStoreNil(t *testing.T) { }() ctx := context.Background() - testDBPath := filepath.Join(t.TempDir(), "dolt") - testStore := newTestStoreIsolatedDB(t, testDBPath, "cfg") - if err := testStore.SetConfig(ctx, "github.token", "ghp_test_token"); err != nil { - t.Fatalf("SetConfig: %v", err) - } - store = nil - dbPath = testDBPath + dbPath = "" + + t.Setenv("GITHUB_TOKEN", "ghp_test_token") if got := getGitHubConfigValue(ctx, "github.token"); got != "ghp_test_token" { t.Fatalf("getGitHubConfigValue() = %q, want %q", got, "ghp_test_token") diff --git a/internal/config/yaml_config.go b/internal/config/yaml_config.go index 4fcda5da6..3d03cddf2 100644 --- a/internal/config/yaml_config.go +++ b/internal/config/yaml_config.go @@ -65,6 +65,12 @@ var YamlOnlyKeys = map[string]bool{ // Dolt server settings "dolt.idle-timeout": true, // Idle auto-stop timeout (default "30m", "0" disables) "dolt.shared-server": true, // Shared Dolt server at ~/.beads/shared-server/ (GH#2377) + + // Secrets: tokens and API keys must NOT be stored in the Dolt database + // because that data is pushed to remotes, triggering secret-scanning + // blocks on GitHub. Store them in local config.yaml instead. + "github.token": true, + "linear.api_key": true, } // IsYamlOnlyKey returns true if the given key should be stored in config.yaml diff --git a/internal/config/yaml_config_test.go b/internal/config/yaml_config_test.go index f8b35f525..81a555173 100644 --- a/internal/config/yaml_config_test.go +++ b/internal/config/yaml_config_test.go @@ -37,10 +37,13 @@ func TestIsYamlOnlyKey(t *testing.T) { {"backup.git-repo", true}, {"backup.future-key", true}, // prefix match + // Secret keys (stored in yaml to avoid leaking via Dolt push) + {"github.token", true}, + {"linear.api_key", true}, + // Non-yaml keys (should return false) {"jira.url", false}, {"jira.project", false}, - {"linear.api_key", false}, {"github.org", false}, {"custom.setting", false}, {"status.custom", false},