fix: Make Mayor/Deacon session names include town name

Session names `gt-mayor` and `gt-deacon` were hardcoded, causing tmux
session name collisions when running multiple towns simultaneously.

Changed to `gt-{town}-mayor` and `gt-{town}-deacon` format (e.g.,
`gt-ai-mayor`) to allow concurrent multi-town operation.

Key changes:
- session.MayorSessionName() and DeaconSessionName() now take townName param
- Added workspace.GetTownName() helper to load town name from config
- Updated all callers in cmd/, daemon/, doctor/, mail/, rig/, templates/
- Updated tests with new session name format
- Bead IDs remain unchanged (already scoped by .beads/ directory)

Fixes #60

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
markov-kernel
2026-01-03 21:21:00 +01:00
parent 7f9795f630
commit e7145cfd77
46 changed files with 4772 additions and 1615 deletions

View File

@@ -7,6 +7,9 @@ import (
"os/exec"
"path/filepath"
"strings"
"github.com/steveyegge/gastown/internal/session"
"github.com/steveyegge/gastown/internal/workspace"
)
// LifecycleHygieneCheck detects and cleans up stale lifecycle state.
@@ -139,7 +142,7 @@ func (c *LifecycleHygieneCheck) checkStateFiles(ctx *CheckContext) int {
if strings.HasPrefix(key, "requesting_") {
if boolVal, ok := val.(bool); ok && boolVal {
// Found a stuck flag - verify session is actually healthy
if c.isSessionHealthy(sf.identity) {
if c.isSessionHealthy(sf.identity, ctx.TownRoot) {
c.stuckStateFiles = append(c.stuckStateFiles, stuckState{
stateFile: sf.path,
identity: sf.identity,
@@ -225,8 +228,8 @@ func (c *LifecycleHygieneCheck) findStateFiles(townRoot string) []stateFileInfo
}
// isSessionHealthy checks if the tmux session for this identity exists and is running.
func (c *LifecycleHygieneCheck) isSessionHealthy(identity string) bool {
sessionName := identityToSessionName(identity)
func (c *LifecycleHygieneCheck) isSessionHealthy(identity, townRoot string) bool {
sessionName := identityToSessionName(identity, townRoot)
if sessionName == "" {
return false
}
@@ -237,10 +240,15 @@ func (c *LifecycleHygieneCheck) isSessionHealthy(identity string) bool {
}
// identityToSessionName converts an identity to its tmux session name.
func identityToSessionName(identity string) string {
func identityToSessionName(identity, townRoot string) string {
switch identity {
case "mayor":
return "gt-mayor"
if townRoot != "" {
if townName, err := workspace.GetTownName(townRoot); err == nil {
return session.MayorSessionName(townName)
}
}
return "" // Cannot generate session name without town root
default:
if strings.HasSuffix(identity, "-witness") ||
strings.HasSuffix(identity, "-refinery") ||

View File

@@ -8,7 +8,9 @@ import (
"regexp"
"strings"
"github.com/steveyegge/gastown/internal/session"
"github.com/steveyegge/gastown/internal/tmux"
"github.com/steveyegge/gastown/internal/workspace"
)
// OrphanSessionCheck detects orphaned tmux sessions that don't match
@@ -55,24 +57,31 @@ func (c *OrphanSessionCheck) Run(ctx *CheckContext) *CheckResult {
// Get list of valid rigs
validRigs := c.getValidRigs(ctx.TownRoot)
// Get dynamic session names for mayor/deacon
var mayorSession, deaconSession string
if townName, err := workspace.GetTownName(ctx.TownRoot); err == nil {
mayorSession = session.MayorSessionName(townName)
deaconSession = session.DeaconSessionName(townName)
}
// Check each session
var orphans []string
var validCount int
for _, session := range sessions {
if session == "" {
for _, sess := range sessions {
if sess == "" {
continue
}
// Only check gt-* sessions (Gas Town sessions)
if !strings.HasPrefix(session, "gt-") {
if !strings.HasPrefix(sess, "gt-") {
continue
}
if c.isValidSession(session, validRigs) {
if c.isValidSession(sess, validRigs, mayorSession, deaconSession) {
validCount++
} else {
orphans = append(orphans, session)
orphans = append(orphans, sess)
}
}
@@ -166,27 +175,27 @@ func (c *OrphanSessionCheck) getValidRigs(townRoot string) []string {
// isValidSession checks if a session name matches expected Gas Town patterns.
// Valid patterns:
// - gt-mayor
// - gt-deacon
// - gt-{town}-mayor (dynamic based on town name)
// - gt-{town}-deacon (dynamic based on town name)
// - gt-<rig>-witness
// - gt-<rig>-refinery
// - gt-<rig>-<polecat> (where polecat is any name)
//
// Note: We can't verify polecat names without reading state, so we're permissive.
func (c *OrphanSessionCheck) isValidSession(session string, validRigs []string) bool {
// gt-mayor is always valid
if session == "gt-mayor" {
func (c *OrphanSessionCheck) isValidSession(sess string, validRigs []string, mayorSession, deaconSession string) bool {
// Mayor session is always valid (dynamic name based on town)
if mayorSession != "" && sess == mayorSession {
return true
}
// gt-deacon is always valid
if session == "gt-deacon" {
// Deacon session is always valid (dynamic name based on town)
if deaconSession != "" && sess == deaconSession {
return true
}
// For rig-specific sessions, extract rig name
// Pattern: gt-<rig>-<role>
parts := strings.SplitN(session, "-", 3)
parts := strings.SplitN(sess, "-", 3)
if len(parts) < 3 {
// Invalid format - must be gt-<rig>-<something>
return false

View File

@@ -5,7 +5,9 @@ import (
"os/exec"
"strings"
"github.com/steveyegge/gastown/internal/session"
"github.com/steveyegge/gastown/internal/tmux"
"github.com/steveyegge/gastown/internal/workspace"
)
// LinkedPaneCheck detects tmux sessions that share panes,
@@ -83,11 +85,17 @@ func (c *LinkedPaneCheck) Run(ctx *CheckContext) *CheckResult {
}
}
// Cache for Fix (exclude gt-mayor since we don't want to kill it)
// Cache for Fix (exclude mayor session since we don't want to kill it)
// Get dynamic mayor session name
var mayorSession string
if townName, err := workspace.GetTownName(ctx.TownRoot); err == nil {
mayorSession = session.MayorSessionName(townName)
}
c.linkedSessions = nil
for session := range linkedSessionSet {
if session != "gt-mayor" {
c.linkedSessions = append(c.linkedSessions, session)
for sess := range linkedSessionSet {
if mayorSession == "" || sess != mayorSession {
c.linkedSessions = append(c.linkedSessions, sess)
}
}
@@ -108,7 +116,7 @@ func (c *LinkedPaneCheck) Run(ctx *CheckContext) *CheckResult {
}
}
// Fix kills sessions with linked panes (except gt-mayor).
// Fix kills sessions with linked panes (except mayor session).
// The daemon will recreate them with independent panes.
func (c *LinkedPaneCheck) Fix(ctx *CheckContext) error {
if len(c.linkedSessions) == 0 {