fix(sling): Set BEADS_DIR for accessing hq-* beads from polecat worktree

When running bd update commands for hq-* beads from a polecat worktree,
the redirect mechanism only exposes gt-* beads. This fix sets BEADS_DIR
to the town-level .beads directory so hq-* beads are accessible.

Also adds NewWithBeadsDir() constructor to beads package for explicit
cross-database access when needed.
This commit is contained in:
kustrun
2026-01-02 22:54:20 +01:00
parent 58e7c96936
commit a0a47676f9
2 changed files with 62 additions and 37 deletions

View File

@@ -209,7 +209,8 @@ type SyncStatus struct {
// Beads wraps bd CLI operations for a working directory.
type Beads struct {
workDir string
workDir string
beadsDir string // Optional BEADS_DIR override for cross-database access
}
// New creates a new Beads wrapper for the given directory.
@@ -217,6 +218,12 @@ func New(workDir string) *Beads {
return &Beads{workDir: workDir}
}
// NewWithBeadsDir creates a Beads wrapper with an explicit BEADS_DIR.
// This is needed when running from a polecat worktree but accessing town-level beads.
func NewWithBeadsDir(workDir, beadsDir string) *Beads {
return &Beads{workDir: workDir, beadsDir: beadsDir}
}
// run executes a bd command and returns stdout.
func (b *Beads) run(args ...string) ([]byte, error) {
// Use --no-daemon for faster read operations (avoids daemon IPC overhead)
@@ -225,6 +232,11 @@ func (b *Beads) run(args ...string) ([]byte, error) {
cmd := exec.Command("bd", fullArgs...)
cmd.Dir = b.workDir
// Set BEADS_DIR if specified (enables cross-database access)
if b.beadsDir != "" {
cmd.Env = append(os.Environ(), "BEADS_DIR="+b.beadsDir)
}
var stdout, stderr bytes.Buffer
cmd.Stdout = &stdout
cmd.Stderr = &stderr