From eed5cddc973d093b986aecf6e4c563541aaa76d6 Mon Sep 17 00:00:00 2001 From: beads/crew/emma Date: Sat, 17 Jan 2026 00:24:49 -0800 Subject: [PATCH] fix(sling): clear BEADS_DIR env var when creating auto-convoys When running from a crew workspace, BEADS_DIR is set to the rig's beads directory. This caused auto-convoy creation to fail because bd would use the rig's database (prefix=bd) instead of discovering the HQ database (prefix=hq) from the working directory. The fix clears BEADS_DIR from the environment when running bd commands for convoy creation, allowing bd to discover the correct database from the townBeads directory. Co-Authored-By: Claude Opus 4.5 --- internal/cmd/sling_convoy.go | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/internal/cmd/sling_convoy.go b/internal/cmd/sling_convoy.go index 8828aba8..00d76817 100644 --- a/internal/cmd/sling_convoy.go +++ b/internal/cmd/sling_convoy.go @@ -56,6 +56,26 @@ func isTrackedByConvoy(beadID string) string { return convoyID } +// filterEnvExcluding returns a copy of the environment with specified keys removed. +// This is used to prevent rig-specific environment variables from affecting +// commands that need to run in a different context (e.g., HQ beads). +func filterEnvExcluding(env []string, excludeKeys ...string) []string { + result := make([]string, 0, len(env)) + for _, e := range env { + exclude := false + for _, key := range excludeKeys { + if strings.HasPrefix(e, key+"=") { + exclude = true + break + } + } + if !exclude { + result = append(result, e) + } + } + return result +} + // createAutoConvoy creates an auto-convoy for a single issue and tracks it. // Returns the created convoy ID. func createAutoConvoy(beadID, beadTitle string) (string, error) { @@ -85,8 +105,13 @@ func createAutoConvoy(beadID, beadTitle string) (string, error) { createArgs = append(createArgs, "--force") } + // Clear BEADS_DIR so bd discovers the database from townBeads directory + // instead of using the rig's beads (which has a different prefix) + cleanEnv := filterEnvExcluding(os.Environ(), "BEADS_DIR") + createCmd := exec.Command("bd", append([]string{"--no-daemon"}, createArgs...)...) createCmd.Dir = townBeads + createCmd.Env = cleanEnv createCmd.Stderr = os.Stderr if err := createCmd.Run(); err != nil { @@ -98,6 +123,7 @@ func createAutoConvoy(beadID, beadTitle string) (string, error) { depArgs := []string{"--no-daemon", "dep", "add", convoyID, trackBeadID, "--type=tracks"} depCmd := exec.Command("bd", depArgs...) depCmd.Dir = townBeads + depCmd.Env = cleanEnv depCmd.Stderr = os.Stderr if err := depCmd.Run(); err != nil {