From 3c4190597f9f3cd73dc0227f069d508970895f27 Mon Sep 17 00:00:00 2001 From: kustrun Date: Fri, 2 Jan 2026 20:14:31 +0100 Subject: [PATCH] fix(session): Set BEADS_DIR to town-level beads for polecat hooks Polecats need access to town-level beads (hq- prefix) for hooks and convoys. Update session manager to set BEADS_DIR to town root .beads/ instead of rig-level .beads/. Also update mail.go's findLocalBeadsDir() to respect the BEADS_DIR environment variable, which is necessary for polecats using redirect-based beads access. --- internal/cmd/mail.go | 17 +++++++++++++++++ internal/session/manager.go | 9 ++++++--- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/internal/cmd/mail.go b/internal/cmd/mail.go index 2138d982..5e76f916 100644 --- a/internal/cmd/mail.go +++ b/internal/cmd/mail.go @@ -925,7 +925,24 @@ func findMailWorkDir() (string, error) { // findLocalBeadsDir finds the nearest .beads directory by walking up from CWD. // Used for project work (molecules, issue creation) that uses clone beads. +// +// Priority: +// 1. BEADS_DIR environment variable (set by session manager for polecats) +// 2. Walk up from CWD looking for .beads directory +// +// Polecats use redirect-based beads access, so their worktree doesn't have a full +// .beads directory. The session manager sets BEADS_DIR to the correct location. func findLocalBeadsDir() (string, error) { + // Check BEADS_DIR environment variable first (set by session manager for polecats). + // This is important for polecats that use redirect-based beads access. + if beadsDir := os.Getenv("BEADS_DIR"); beadsDir != "" { + // BEADS_DIR points directly to the .beads directory, return its parent + if _, err := os.Stat(beadsDir); err == nil { + return filepath.Dir(beadsDir), nil + } + } + + // Fallback: walk up from CWD cwd, err := os.Getwd() if err != nil { return "", err diff --git a/internal/session/manager.go b/internal/session/manager.go index c80c0643..5b85056f 100644 --- a/internal/session/manager.go +++ b/internal/session/manager.go @@ -148,9 +148,12 @@ func (m *Manager) Start(polecat string, opts StartOptions) error { } // CRITICAL: Set beads environment for worktree polecats (non-fatal: session works without) - // Polecats share the rig's beads directory (at rig root, not mayor/rig) - // BEADS_NO_DAEMON=1 prevents daemon from committing to wrong branch - beadsDir := filepath.Join(m.rig.Path, ".beads") + // Polecats need access to TOWN-level beads (parent of rig) for hooks and convoys. + // Town beads use hq- prefix and store hooks, mail, and cross-rig coordination. + // BEADS_NO_DAEMON=1 prevents daemon from committing to wrong branch. + // Using town-level beads ensures gt prime and bd commands can find hooked work. + townRoot := filepath.Dir(m.rig.Path) // Town root is parent of rig directory + beadsDir := filepath.Join(townRoot, ".beads") _ = m.tmux.SetEnvironment(sessionID, "BEADS_DIR", beadsDir) _ = m.tmux.SetEnvironment(sessionID, "BEADS_NO_DAEMON", "1") _ = m.tmux.SetEnvironment(sessionID, "BEADS_AGENT_NAME", fmt.Sprintf("%s/%s", m.rig.Name, polecat))