fix(plugin): add BEADS_DIR env to Recorder bd commands

The Recorder calls bd commands but wasn't setting the BEADS_DIR
environment variable. This could cause plugin run beads to be
created in the wrong database when redirects are in play.

Fixes: gt-z4ct5

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
slit
2026-01-12 17:47:51 -08:00
committed by beads/crew/emma
parent c860112cf6
commit c99b004aeb

View File

@@ -8,6 +8,8 @@ import (
"os/exec"
"strings"
"time"
"github.com/steveyegge/gastown/internal/beads"
)
// RunResult represents the outcome of a plugin execution.
@@ -77,6 +79,9 @@ func (r *Recorder) RecordRun(record PluginRunRecord) (string, error) {
cmd := exec.Command("bd", args...) //nolint:gosec // G204: bd is a trusted internal tool
cmd.Dir = r.townRoot
// Set BEADS_DIR explicitly to prevent inherited env vars from causing
// prefix mismatches when redirects are in play.
cmd.Env = append(os.Environ(), "BEADS_DIR="+beads.ResolveBeadsDir(r.townRoot))
var stdout, stderr bytes.Buffer
cmd.Stdout = &stdout
@@ -140,7 +145,9 @@ func (r *Recorder) queryRuns(pluginName string, limit int, since string) ([]*Plu
cmd := exec.Command("bd", args...) //nolint:gosec // G204: bd is a trusted internal tool
cmd.Dir = r.townRoot
cmd.Env = os.Environ()
// Set BEADS_DIR explicitly to prevent inherited env vars from causing
// prefix mismatches when redirects are in play.
cmd.Env = append(os.Environ(), "BEADS_DIR="+beads.ResolveBeadsDir(r.townRoot))
var stdout, stderr bytes.Buffer
cmd.Stdout = &stdout