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.
This commit is contained in:
kustrun
2026-01-02 20:14:31 +01:00
parent 8133cc36b7
commit 3c4190597f
2 changed files with 23 additions and 3 deletions

View File

@@ -925,7 +925,24 @@ func findMailWorkDir() (string, error) {
// findLocalBeadsDir finds the nearest .beads directory by walking up from CWD. // findLocalBeadsDir finds the nearest .beads directory by walking up from CWD.
// Used for project work (molecules, issue creation) that uses clone beads. // 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) { 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() cwd, err := os.Getwd()
if err != nil { if err != nil {
return "", err return "", err

View File

@@ -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) // 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) // Polecats need access to TOWN-level beads (parent of rig) for hooks and convoys.
// BEADS_NO_DAEMON=1 prevents daemon from committing to wrong branch // Town beads use hq- prefix and store hooks, mail, and cross-rig coordination.
beadsDir := filepath.Join(m.rig.Path, ".beads") // 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_DIR", beadsDir)
_ = m.tmux.SetEnvironment(sessionID, "BEADS_NO_DAEMON", "1") _ = m.tmux.SetEnvironment(sessionID, "BEADS_NO_DAEMON", "1")
_ = m.tmux.SetEnvironment(sessionID, "BEADS_AGENT_NAME", fmt.Sprintf("%s/%s", m.rig.Name, polecat)) _ = m.tmux.SetEnvironment(sessionID, "BEADS_AGENT_NAME", fmt.Sprintf("%s/%s", m.rig.Name, polecat))