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

@@ -6,6 +6,7 @@ import (
"sort"
"github.com/spf13/cobra"
"github.com/steveyegge/gastown/internal/workspace"
)
// townCycleSession is the --session flag for town next/prev commands.
@@ -13,9 +14,32 @@ import (
// correct, so we pass the session name explicitly via #{session_name} expansion.
var townCycleSession string
// Town-level sessions that participate in cycling (mayor, deacon).
// These are the session names without the "gt-" prefix.
var townLevelSessions = []string{"gt-mayor", "gt-deacon"}
// getTownLevelSessions returns the town-level session names for the current workspace.
// Returns empty slice if workspace cannot be determined.
func getTownLevelSessions() []string {
mayorSession, errMayor := getMayorSessionName()
deaconSession, errDeacon := getDeaconSessionName()
if errMayor != nil || errDeacon != nil {
return nil
}
return []string{mayorSession, deaconSession}
}
// isTownLevelSession checks if the given session name is a town-level session.
func isTownLevelSession(sessionName string) bool {
townRoot, err := workspace.FindFromCwd()
if err != nil || townRoot == "" {
return false
}
townName, err := workspace.GetTownName(townRoot)
if err != nil {
return false
}
mayorSession, _ := getMayorSessionName()
deaconSession, _ := getDeaconSessionName()
_ = townName // used for session name generation
return sessionName == mayorSession || sessionName == deaconSession
}
func init() {
rootCmd.AddCommand(townCmd)
@@ -78,15 +102,7 @@ func cycleTownSession(direction int, sessionOverride string) error {
}
// Check if current session is a town-level session
isTownSession := false
for _, s := range townLevelSessions {
if s == currentSession {
isTownSession = true
break
}
}
if !isTownSession {
if !isTownLevelSession(currentSession) {
// Not a town session - no cycling, just stay put
return nil
}
@@ -145,6 +161,12 @@ func findRunningTownSessions() ([]string, error) {
return nil, fmt.Errorf("listing tmux sessions: %w", err)
}
// Get town-level session names
townLevelSessions := getTownLevelSessions()
if townLevelSessions == nil {
return nil, fmt.Errorf("cannot determine town-level sessions")
}
var running []string
for _, line := range splitLines(string(out)) {
if line == "" {