Revert to simple gt-mayor/gt-deacon session names

Reverts the session naming changes from PR #70. Multi-town support
on a single machine is not a real use case - rigs provide project
isolation, and true isolation should use containers/VMs.

Changes:
- MayorSessionName() and DeaconSessionName() no longer take townName parameter
- ParseSessionName() handles simple gt-mayor and gt-deacon formats
- Removed Town field from AgentIdentity and AgentSession structs
- Updated all callers and tests

Generated with Claude Code

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
joe
2026-01-03 14:33:24 -08:00
committed by Steve Yegge
parent d3e47221ac
commit 4bcf50bf1c
23 changed files with 117 additions and 267 deletions

View File

@@ -35,7 +35,6 @@ type AgentSession struct {
Type AgentType Type AgentType
Rig string // For rig-specific agents Rig string // For rig-specific agents
AgentName string // e.g., crew name, polecat name AgentName string // e.g., crew name, polecat name
Town string // For mayor/deacon only (town name from session)
} }
// AgentTypeColors maps agent types to tmux color codes. // AgentTypeColors maps agent types to tmux color codes.
@@ -136,16 +135,13 @@ func categorizeSession(name string) *AgentSession {
session := &AgentSession{Name: name} session := &AgentSession{Name: name}
suffix := strings.TrimPrefix(name, "gt-") suffix := strings.TrimPrefix(name, "gt-")
// Town-level agents: gt-{town}-mayor, gt-{town}-deacon // Town-level agents: gt-mayor, gt-deacon (simple format, one per machine)
// Check if suffix ends with -mayor or -deacon (new format) if suffix == "mayor" {
if strings.HasSuffix(suffix, "-mayor") {
session.Type = AgentMayor session.Type = AgentMayor
session.Town = strings.TrimSuffix(suffix, "-mayor")
return session return session
} }
if strings.HasSuffix(suffix, "-deacon") { if suffix == "deacon" {
session.Type = AgentDeacon session.Type = AgentDeacon
session.Town = strings.TrimSuffix(suffix, "-deacon")
return session return session
} }

View File

@@ -21,18 +21,9 @@ import (
"github.com/steveyegge/gastown/internal/workspace" "github.com/steveyegge/gastown/internal/workspace"
) )
// getDeaconSessionName returns the Deacon session name for the current workspace. // getDeaconSessionName returns the Deacon session name.
// The session name includes the town name to avoid collisions between multiple HQs.
func getDeaconSessionName() (string, error) { func getDeaconSessionName() (string, error) {
townRoot, err := workspace.FindFromCwdOrError() return session.DeaconSessionName(), nil
if err != nil {
return "", fmt.Errorf("not in a Gas Town workspace: %w", err)
}
townName, err := workspace.GetTownName(townRoot)
if err != nil {
return "", err
}
return session.DeaconSessionName(townName), nil
} }
var deaconCmd = &cobra.Command{ var deaconCmd = &cobra.Command{
@@ -673,14 +664,8 @@ func runDeaconHealthCheck(cmd *cobra.Command, args []string) error {
return nil return nil
} }
// Get town name for session name generation
townName, err := workspace.GetTownName(townRoot)
if err != nil {
return fmt.Errorf("getting town name: %w", err)
}
// Get agent bead info before ping (for baseline) // Get agent bead info before ping (for baseline)
beadID, sessionName, err := agentAddressToIDs(agent, townName) beadID, sessionName, err := agentAddressToIDs(agent)
if err != nil { if err != nil {
return fmt.Errorf("invalid agent address: %w", err) return fmt.Errorf("invalid agent address: %w", err)
} }
@@ -787,14 +772,8 @@ func runDeaconForceKill(cmd *cobra.Command, args []string) error {
agent, remaining.Round(time.Second)) agent, remaining.Round(time.Second))
} }
// Get town name for session name generation
townName, err := workspace.GetTownName(townRoot)
if err != nil {
return fmt.Errorf("getting town name: %w", err)
}
// Get session name // Get session name
_, sessionName, err := agentAddressToIDs(agent, townName) _, sessionName, err := agentAddressToIDs(agent)
if err != nil { if err != nil {
return fmt.Errorf("invalid agent address: %w", err) return fmt.Errorf("invalid agent address: %w", err)
} }
@@ -1154,14 +1133,13 @@ func notifyMayorOfWitnessFailure(townRoot string, zombies []zombieInfo) {
// agentAddressToIDs converts an agent address to bead ID and session name. // agentAddressToIDs converts an agent address to bead ID and session name.
// Supports formats: "gastown/polecats/max", "gastown/witness", "deacon", "mayor" // Supports formats: "gastown/polecats/max", "gastown/witness", "deacon", "mayor"
// The townName parameter is required for mayor/deacon to generate correct session names. func agentAddressToIDs(address string) (beadID, sessionName string, err error) {
func agentAddressToIDs(address, townName string) (beadID, sessionName string, err error) {
switch address { switch address {
case "deacon": case "deacon":
sessName := session.DeaconSessionName(townName) sessName := session.DeaconSessionName()
return sessName, sessName, nil return sessName, sessName, nil
case "mayor": case "mayor":
sessName := session.MayorSessionName(townName) sessName := session.MayorSessionName()
return sessName, sessName, nil return sessName, sessName, nil
} }
@@ -1227,11 +1205,7 @@ func sendMail(townRoot, to, subject, body string) {
// updateAgentBeadState updates an agent bead's state. // updateAgentBeadState updates an agent bead's state.
func updateAgentBeadState(townRoot, agent, state, reason string) { func updateAgentBeadState(townRoot, agent, state, reason string) {
townName, err := workspace.GetTownName(townRoot) beadID, _, err := agentAddressToIDs(agent)
if err != nil {
return
}
beadID, _, err := agentAddressToIDs(agent, townName)
if err != nil { if err != nil {
return return
} }

View File

@@ -5,13 +5,13 @@ import (
) )
func TestAddressToAgentBeadID(t *testing.T) { func TestAddressToAgentBeadID(t *testing.T) {
townName := "ai"
tests := []struct { tests := []struct {
address string address string
expected string expected string
}{ }{
{"mayor", "gt-ai-mayor"}, // Mayor and deacon use simple session names (no town qualifier)
{"deacon", "gt-ai-deacon"}, {"mayor", "gt-mayor"},
{"deacon", "gt-deacon"},
{"gastown/witness", "gt-gastown-witness"}, {"gastown/witness", "gt-gastown-witness"},
{"gastown/refinery", "gt-gastown-refinery"}, {"gastown/refinery", "gt-gastown-refinery"},
{"gastown/alpha", "gt-gastown-polecat-alpha"}, {"gastown/alpha", "gt-gastown-polecat-alpha"},
@@ -25,9 +25,9 @@ func TestAddressToAgentBeadID(t *testing.T) {
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.address, func(t *testing.T) { t.Run(tt.address, func(t *testing.T) {
got := addressToAgentBeadID(tt.address, townName) got := addressToAgentBeadID(tt.address)
if got != tt.expected { if got != tt.expected {
t.Errorf("addressToAgentBeadID(%q, %q) = %q, want %q", tt.address, townName, got, tt.expected) t.Errorf("addressToAgentBeadID(%q) = %q, want %q", tt.address, got, tt.expected)
} }
}) })
} }

View File

@@ -261,8 +261,8 @@ func createMayorCLAUDEmd(hqRoot, townRoot string) error {
TownRoot: townRoot, TownRoot: townRoot,
TownName: townName, TownName: townName,
WorkDir: hqRoot, WorkDir: hqRoot,
MayorSession: session.MayorSessionName(townName), MayorSession: session.MayorSessionName(),
DeaconSession: session.DeaconSessionName(townName), DeaconSession: session.DeaconSessionName(),
} }
content, err := tmpl.RenderRole("mayor", data) content, err := tmpl.RenderRole("mayor", data)

View File

@@ -14,18 +14,9 @@ import (
"github.com/steveyegge/gastown/internal/workspace" "github.com/steveyegge/gastown/internal/workspace"
) )
// getMayorSessionName returns the Mayor session name for the current workspace. // getMayorSessionName returns the Mayor session name.
// The session name includes the town name to avoid collisions between multiple HQs.
func getMayorSessionName() (string, error) { func getMayorSessionName() (string, error) {
townRoot, err := workspace.FindFromCwdOrError() return session.MayorSessionName(), nil
if err != nil {
return "", fmt.Errorf("not in a Gas Town workspace: %w", err)
}
townName, err := workspace.GetTownName(townRoot)
if err != nil {
return "", err
}
return session.MayorSessionName(townName), nil
} }
var mayorCmd = &cobra.Command{ var mayorCmd = &cobra.Command{

View File

@@ -120,17 +120,11 @@ func runNudge(cmd *cobra.Command, args []string) error {
t := tmux.NewTmux() t := tmux.NewTmux()
// Get session names for this town
townName := ""
if townRoot != "" {
townName, _ = workspace.GetTownName(townRoot)
}
// Expand role shortcuts to session names // Expand role shortcuts to session names
// These shortcuts let users type "mayor" instead of "gt-{town}-mayor" // These shortcuts let users type "mayor" instead of "gt-mayor"
switch target { switch target {
case "mayor": case "mayor":
target = session.MayorSessionName(townName) target = session.MayorSessionName()
case "witness", "refinery": case "witness", "refinery":
// These need the current rig // These need the current rig
roleInfo, err := GetRole() roleInfo, err := GetRole()
@@ -149,7 +143,7 @@ func runNudge(cmd *cobra.Command, args []string) error {
// Special case: "deacon" target maps to the Deacon session // Special case: "deacon" target maps to the Deacon session
if target == "deacon" { if target == "deacon" {
deaconSession := session.DeaconSessionName(townName) deaconSession := session.DeaconSessionName()
// Check if Deacon session exists // Check if Deacon session exists
exists, err := t.HasSession(deaconSession) exists, err := t.HasSession(deaconSession)
if err != nil { if err != nil {
@@ -286,9 +280,6 @@ func runNudgeChannel(channelName, message string) error {
// Prefix message with sender // Prefix message with sender
prefixedMessage := fmt.Sprintf("[from %s] %s", sender, message) prefixedMessage := fmt.Sprintf("[from %s] %s", sender, message)
// Get town name for session names
townName, _ := workspace.GetTownName(townRoot)
// Get all running sessions for pattern matching // Get all running sessions for pattern matching
agents, err := getAgentSessions(true) agents, err := getAgentSessions(true)
if err != nil { if err != nil {
@@ -300,7 +291,7 @@ func runNudgeChannel(channelName, message string) error {
seenTargets := make(map[string]bool) seenTargets := make(map[string]bool)
for _, pattern := range patterns { for _, pattern := range patterns {
resolved := resolveNudgePattern(pattern, agents, townName) resolved := resolveNudgePattern(pattern, agents)
for _, sessionName := range resolved { for _, sessionName := range resolved {
if !seenTargets[sessionName] { if !seenTargets[sessionName] {
seenTargets[sessionName] = true seenTargets[sessionName] = true
@@ -362,15 +353,15 @@ func runNudgeChannel(channelName, message string) error {
// - Role: "*/witness" → all witness sessions // - Role: "*/witness" → all witness sessions
// - Special: "mayor", "deacon" → gt-{town}-mayor, gt-{town}-deacon // - Special: "mayor", "deacon" → gt-{town}-mayor, gt-{town}-deacon
// townName is used to generate the correct session names for mayor/deacon. // townName is used to generate the correct session names for mayor/deacon.
func resolveNudgePattern(pattern string, agents []*AgentSession, townName string) []string { func resolveNudgePattern(pattern string, agents []*AgentSession) []string {
var results []string var results []string
// Handle special cases // Handle special cases
switch pattern { switch pattern {
case "mayor": case "mayor":
return []string{session.MayorSessionName(townName)} return []string{session.MayorSessionName()}
case "deacon": case "deacon":
return []string{session.DeaconSessionName(townName)} return []string{session.DeaconSessionName()}
} }
// Parse pattern // Parse pattern
@@ -438,11 +429,8 @@ func shouldNudgeTarget(townRoot, targetAddress string, force bool) (bool, string
return true, "", nil return true, "", nil
} }
// Get town name for session name generation
townName, _ := workspace.GetTownName(townRoot)
// Try to determine agent bead ID from address // Try to determine agent bead ID from address
agentBeadID := addressToAgentBeadID(targetAddress, townName) agentBeadID := addressToAgentBeadID(targetAddress)
if agentBeadID == "" { if agentBeadID == "" {
// Can't determine agent bead, allow the nudge // Can't determine agent bead, allow the nudge
return true, "", nil return true, "", nil
@@ -467,13 +455,13 @@ func shouldNudgeTarget(townRoot, targetAddress string, force bool) (bool, string
// - "gastown/alpha" -> "gt-gastown-polecat-alpha" // - "gastown/alpha" -> "gt-gastown-polecat-alpha"
// //
// Returns empty string if the address cannot be converted. // Returns empty string if the address cannot be converted.
func addressToAgentBeadID(address, townName string) string { func addressToAgentBeadID(address string) string {
// Handle special cases // Handle special cases
switch address { switch address {
case "mayor": case "mayor":
return session.MayorSessionName(townName) return session.MayorSessionName()
case "deacon": case "deacon":
return session.DeaconSessionName(townName) return session.DeaconSessionName()
} }
// Parse rig/role format // Parse rig/role format

View File

@@ -5,10 +5,10 @@ import (
) )
func TestResolveNudgePattern(t *testing.T) { func TestResolveNudgePattern(t *testing.T) {
// Create test agent sessions // Create test agent sessions (no Town field for mayor/deacon anymore)
agents := []*AgentSession{ agents := []*AgentSession{
{Name: "gt-ai-mayor", Type: AgentMayor, Town: "ai"}, {Name: "gt-mayor", Type: AgentMayor},
{Name: "gt-ai-deacon", Type: AgentDeacon, Town: "ai"}, {Name: "gt-deacon", Type: AgentDeacon},
{Name: "gt-gastown-witness", Type: AgentWitness, Rig: "gastown"}, {Name: "gt-gastown-witness", Type: AgentWitness, Rig: "gastown"},
{Name: "gt-gastown-refinery", Type: AgentRefinery, Rig: "gastown"}, {Name: "gt-gastown-refinery", Type: AgentRefinery, Rig: "gastown"},
{Name: "gt-gastown-crew-max", Type: AgentCrew, Rig: "gastown", AgentName: "max"}, {Name: "gt-gastown-crew-max", Type: AgentCrew, Rig: "gastown", AgentName: "max"},
@@ -27,12 +27,12 @@ func TestResolveNudgePattern(t *testing.T) {
{ {
name: "mayor special case", name: "mayor special case",
pattern: "mayor", pattern: "mayor",
expected: []string{"gt-ai-mayor"}, expected: []string{"gt-mayor"},
}, },
{ {
name: "deacon special case", name: "deacon special case",
pattern: "deacon", pattern: "deacon",
expected: []string{"gt-ai-deacon"}, expected: []string{"gt-deacon"},
}, },
{ {
name: "specific witness", name: "specific witness",
@@ -86,10 +86,9 @@ func TestResolveNudgePattern(t *testing.T) {
}, },
} }
townName := "ai"
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(t *testing.T) {
got := resolveNudgePattern(tt.pattern, agents, townName) got := resolveNudgePattern(tt.pattern, agents)
if len(got) != len(tt.expected) { if len(got) != len(tt.expected) {
t.Errorf("resolveNudgePattern(%q) returned %d results, want %d: got %v, want %v", t.Errorf("resolveNudgePattern(%q) returned %d results, want %d: got %v, want %v",

View File

@@ -315,8 +315,8 @@ func outputPrimeContext(ctx RoleContext) error {
TownName: townName, TownName: townName,
WorkDir: ctx.WorkDir, WorkDir: ctx.WorkDir,
Polecat: ctx.Polecat, Polecat: ctx.Polecat,
MayorSession: session.MayorSessionName(townName), MayorSession: session.MayorSessionName(),
DeaconSession: session.DeaconSessionName(townName), DeaconSession: session.DeaconSessionName(),
} }
// Render and output // Render and output

View File

@@ -31,8 +31,8 @@ func TestCategorizeSessionRig(t *testing.T) {
{"gt-a-b", "a"}, // minimum valid {"gt-a-b", "a"}, // minimum valid
// Town-level agents (no rig) // Town-level agents (no rig)
{"gt-ai-mayor", ""}, {"gt-mayor", ""},
{"gt-ai-deacon", ""}, {"gt-deacon", ""},
} }
for _, tt := range tests { for _, tt := range tests {
@@ -68,8 +68,8 @@ func TestCategorizeSessionType(t *testing.T) {
{"gt-myrig-crew-user", AgentCrew}, {"gt-myrig-crew-user", AgentCrew},
// Town-level agents // Town-level agents
{"gt-ai-mayor", AgentMayor}, {"gt-mayor", AgentMayor},
{"gt-ai-deacon", AgentDeacon}, {"gt-deacon", AgentDeacon},
} }
for _, tt := range tests { for _, tt := range tests {

View File

@@ -117,15 +117,9 @@ func runThemeApply(cmd *cobra.Command, args []string) error {
// Determine current rig // Determine current rig
rigName := detectCurrentRig() rigName := detectCurrentRig()
// Get town name for session name comparison // Get session names for comparison
var mayorSession, deaconSession string mayorSession := session.MayorSessionName()
townRoot, err := workspace.FindFromCwd() deaconSession := session.DeaconSessionName()
if err == nil && townRoot != "" {
if townName, err := workspace.GetTownName(townRoot); err == nil {
mayorSession = session.MayorSessionName(townName)
deaconSession = session.DeaconSessionName(townName)
}
}
// Apply to matching sessions // Apply to matching sessions
applied := 0 applied := 0

View File

@@ -90,8 +90,8 @@ const (
) )
// Tmux session names. // Tmux session names.
// Note: Mayor and Deacon session names are now dynamic (include town name). // Mayor and Deacon use simple session names: gt-mayor, gt-deacon (one per machine).
// Use session.MayorSessionName(townName) and session.DeaconSessionName(townName). // Use session.MayorSessionName() and session.DeaconSessionName().
const ( const (
// SessionPrefix is the prefix for all Gas Town tmux sessions. // SessionPrefix is the prefix for all Gas Town tmux sessions.
SessionPrefix = "gt-" SessionPrefix = "gt-"

View File

@@ -22,7 +22,6 @@ import (
"github.com/steveyegge/gastown/internal/polecat" "github.com/steveyegge/gastown/internal/polecat"
"github.com/steveyegge/gastown/internal/session" "github.com/steveyegge/gastown/internal/session"
"github.com/steveyegge/gastown/internal/tmux" "github.com/steveyegge/gastown/internal/tmux"
"github.com/steveyegge/gastown/internal/workspace"
) )
// Daemon is the town-level background service. // Daemon is the town-level background service.
@@ -198,13 +197,7 @@ const DeaconRole = "deacon"
// getDeaconSessionName returns the Deacon session name for the daemon's town. // getDeaconSessionName returns the Deacon session name for the daemon's town.
func (d *Daemon) getDeaconSessionName() string { func (d *Daemon) getDeaconSessionName() string {
townName, err := workspace.GetTownName(d.config.TownRoot) return session.DeaconSessionName()
if err != nil {
// Fallback to legacy name if town config can't be loaded
d.logger.Printf("Warning: failed to get town name: %v, using fallback", err)
return "gt-deacon"
}
return session.DeaconSessionName(townName)
} }
// ensureBootRunning spawns Boot to triage the Deacon. // ensureBootRunning spawns Boot to triage the Deacon.

View File

@@ -14,7 +14,6 @@ import (
"github.com/steveyegge/gastown/internal/constants" "github.com/steveyegge/gastown/internal/constants"
"github.com/steveyegge/gastown/internal/session" "github.com/steveyegge/gastown/internal/session"
"github.com/steveyegge/gastown/internal/tmux" "github.com/steveyegge/gastown/internal/tmux"
"github.com/steveyegge/gastown/internal/workspace"
) )
// BeadsMessage represents a message from gt mail inbox --json. // BeadsMessage represents a message from gt mail inbox --json.
@@ -313,15 +312,9 @@ func (d *Daemon) identityToSession(identity string) string {
// Fallback: use default patterns based on role type // Fallback: use default patterns based on role type
switch parsed.RoleType { switch parsed.RoleType {
case "mayor": case "mayor":
if townName, err := workspace.GetTownName(d.config.TownRoot); err == nil { return session.MayorSessionName()
return session.MayorSessionName(townName)
}
return ""
case "deacon": case "deacon":
if townName, err := workspace.GetTownName(d.config.TownRoot); err == nil { return session.DeaconSessionName()
return session.DeaconSessionName(townName)
}
return ""
case "witness", "refinery": case "witness", "refinery":
return fmt.Sprintf("gt-%s-%s", parsed.RigName, parsed.RoleType) return fmt.Sprintf("gt-%s-%s", parsed.RigName, parsed.RoleType)
case "crew": case "crew":

View File

@@ -184,9 +184,10 @@ func TestIdentityToSession_Mayor(t *testing.T) {
d, cleanup := testDaemonWithTown(t, "ai") d, cleanup := testDaemonWithTown(t, "ai")
defer cleanup() defer cleanup()
// Mayor session name is now fixed (one per machine, no town qualifier)
result := d.identityToSession("mayor") result := d.identityToSession("mayor")
if result != "gt-ai-mayor" { if result != "gt-mayor" {
t.Errorf("identityToSession('mayor') = %q, expected 'gt-ai-mayor'", result) t.Errorf("identityToSession('mayor') = %q, expected 'gt-mayor'", result)
} }
} }

View File

@@ -9,7 +9,6 @@ import (
"strings" "strings"
"github.com/steveyegge/gastown/internal/session" "github.com/steveyegge/gastown/internal/session"
"github.com/steveyegge/gastown/internal/workspace"
) )
// LifecycleHygieneCheck detects and cleans up stale lifecycle state. // LifecycleHygieneCheck detects and cleans up stale lifecycle state.
@@ -243,12 +242,7 @@ func (c *LifecycleHygieneCheck) isSessionHealthy(identity, townRoot string) bool
func identityToSessionName(identity, townRoot string) string { func identityToSessionName(identity, townRoot string) string {
switch identity { switch identity {
case "mayor": case "mayor":
if townRoot != "" { return session.MayorSessionName()
if townName, err := workspace.GetTownName(townRoot); err == nil {
return session.MayorSessionName(townName)
}
}
return "" // Cannot generate session name without town root
default: default:
if strings.HasSuffix(identity, "-witness") || if strings.HasSuffix(identity, "-witness") ||
strings.HasSuffix(identity, "-refinery") || strings.HasSuffix(identity, "-refinery") ||

View File

@@ -10,7 +10,6 @@ import (
"github.com/steveyegge/gastown/internal/session" "github.com/steveyegge/gastown/internal/session"
"github.com/steveyegge/gastown/internal/tmux" "github.com/steveyegge/gastown/internal/tmux"
"github.com/steveyegge/gastown/internal/workspace"
) )
// OrphanSessionCheck detects orphaned tmux sessions that don't match // OrphanSessionCheck detects orphaned tmux sessions that don't match
@@ -57,12 +56,9 @@ func (c *OrphanSessionCheck) Run(ctx *CheckContext) *CheckResult {
// Get list of valid rigs // Get list of valid rigs
validRigs := c.getValidRigs(ctx.TownRoot) validRigs := c.getValidRigs(ctx.TownRoot)
// Get dynamic session names for mayor/deacon // Get session names for mayor/deacon
var mayorSession, deaconSession string mayorSession := session.MayorSessionName()
if townName, err := workspace.GetTownName(ctx.TownRoot); err == nil { deaconSession := session.DeaconSessionName()
mayorSession = session.MayorSessionName(townName)
deaconSession = session.DeaconSessionName(townName)
}
// Check each session // Check each session
var orphans []string var orphans []string

View File

@@ -7,7 +7,6 @@ import (
"github.com/steveyegge/gastown/internal/session" "github.com/steveyegge/gastown/internal/session"
"github.com/steveyegge/gastown/internal/tmux" "github.com/steveyegge/gastown/internal/tmux"
"github.com/steveyegge/gastown/internal/workspace"
) )
// LinkedPaneCheck detects tmux sessions that share panes, // LinkedPaneCheck detects tmux sessions that share panes,
@@ -86,11 +85,7 @@ func (c *LinkedPaneCheck) Run(ctx *CheckContext) *CheckResult {
} }
// Cache for Fix (exclude mayor session 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 mayorSession := session.MayorSessionName()
var mayorSession string
if townName, err := workspace.GetTownName(ctx.TownRoot); err == nil {
mayorSession = session.MayorSessionName(townName)
}
c.linkedSessions = nil c.linkedSessions = nil
for sess := range linkedSessionSet { for sess := range linkedSessionSet {

View File

@@ -13,7 +13,6 @@ import (
"github.com/steveyegge/gastown/internal/config" "github.com/steveyegge/gastown/internal/config"
"github.com/steveyegge/gastown/internal/session" "github.com/steveyegge/gastown/internal/session"
"github.com/steveyegge/gastown/internal/tmux" "github.com/steveyegge/gastown/internal/tmux"
"github.com/steveyegge/gastown/internal/workspace"
) )
// ErrUnknownList indicates a mailing list name was not found in configuration. // ErrUnknownList indicates a mailing list name was not found in configuration.
@@ -936,13 +935,7 @@ func (r *Router) GetMailbox(address string) (*Mailbox, error) {
// Uses send-keys to echo a visible banner to ensure notification is seen. // Uses send-keys to echo a visible banner to ensure notification is seen.
// Supports mayor/, rig/polecat, and rig/refinery addresses. // Supports mayor/, rig/polecat, and rig/refinery addresses.
func (r *Router) notifyRecipient(msg *Message) error { func (r *Router) notifyRecipient(msg *Message) error {
// Get town name for session name generation sessionID := addressToSessionID(msg.To)
var townName string
if r.townRoot != "" {
townName, _ = workspace.GetTownName(r.townRoot)
}
sessionID := addressToSessionID(msg.To, townName)
if sessionID == "" { if sessionID == "" {
return nil // Unable to determine session ID return nil // Unable to determine session ID
} }
@@ -959,21 +952,15 @@ func (r *Router) notifyRecipient(msg *Message) error {
// addressToSessionID converts a mail address to a tmux session ID. // addressToSessionID converts a mail address to a tmux session ID.
// Returns empty string if address format is not recognized. // Returns empty string if address format is not recognized.
func addressToSessionID(address, townName string) string { func addressToSessionID(address string) string {
// Mayor address: "mayor/" or "mayor" // Mayor address: "mayor/" or "mayor"
if strings.HasPrefix(address, "mayor") { if strings.HasPrefix(address, "mayor") {
if townName != "" { return session.MayorSessionName()
return session.MayorSessionName(townName)
}
return "" // Cannot generate session name without town name
} }
// Deacon address: "deacon/" or "deacon" // Deacon address: "deacon/" or "deacon"
if strings.HasPrefix(address, "deacon") { if strings.HasPrefix(address, "deacon") {
if townName != "" { return session.DeaconSessionName()
return session.DeaconSessionName(townName)
}
return "" // Cannot generate session name without town name
} }
// Rig-based address: "rig/target" // Rig-based address: "rig/target"

View File

@@ -87,14 +87,13 @@ func TestIsTownLevelAddress(t *testing.T) {
} }
func TestAddressToSessionID(t *testing.T) { func TestAddressToSessionID(t *testing.T) {
townName := "ai"
tests := []struct { tests := []struct {
address string address string
want string want string
}{ }{
{"mayor", "gt-ai-mayor"}, {"mayor", "gt-mayor"},
{"mayor/", "gt-ai-mayor"}, {"mayor/", "gt-mayor"},
{"deacon", "gt-ai-deacon"}, {"deacon", "gt-deacon"},
{"gastown/refinery", "gt-gastown-refinery"}, {"gastown/refinery", "gt-gastown-refinery"},
{"gastown/Toast", "gt-gastown-Toast"}, {"gastown/Toast", "gt-gastown-Toast"},
{"beads/witness", "gt-beads-witness"}, {"beads/witness", "gt-beads-witness"},
@@ -105,9 +104,9 @@ func TestAddressToSessionID(t *testing.T) {
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.address, func(t *testing.T) { t.Run(tt.address, func(t *testing.T) {
got := addressToSessionID(tt.address, townName) got := addressToSessionID(tt.address)
if got != tt.want { if got != tt.want {
t.Errorf("addressToSessionID(%q, %q) = %q, want %q", tt.address, townName, got, tt.want) t.Errorf("addressToSessionID(%q) = %q, want %q", tt.address, got, tt.want)
} }
}) })
} }

View File

@@ -21,7 +21,6 @@ const (
// AgentIdentity represents a parsed Gas Town agent identity. // AgentIdentity represents a parsed Gas Town agent identity.
type AgentIdentity struct { type AgentIdentity struct {
Role Role // mayor, deacon, witness, refinery, crew, polecat Role Role // mayor, deacon, witness, refinery, crew, polecat
Town string // town name (for mayor/deacon only)
Rig string // rig name (empty for mayor/deacon) Rig string // rig name (empty for mayor/deacon)
Name string // crew/polecat name (empty for mayor/deacon/witness/refinery) Name string // crew/polecat name (empty for mayor/deacon/witness/refinery)
} }
@@ -29,8 +28,8 @@ type AgentIdentity struct {
// ParseSessionName parses a tmux session name into an AgentIdentity. // ParseSessionName parses a tmux session name into an AgentIdentity.
// //
// Session name formats: // Session name formats:
// - gt-<town>-mayor → Role: mayor, Town: <town> // - gt-mayor → Role: mayor (one per machine)
// - gt-<town>-deacon → Role: deacon, Town: <town> // - gt-deacon → Role: deacon (one per machine)
// - gt-<rig>-witness → Role: witness, Rig: <rig> // - gt-<rig>-witness → Role: witness, Rig: <rig>
// - gt-<rig>-refinery → Role: refinery, Rig: <rig> // - gt-<rig>-refinery → Role: refinery, Rig: <rig>
// - gt-<rig>-crew-<name> → Role: crew, Rig: <rig>, Name: <name> // - gt-<rig>-crew-<name> → Role: crew, Rig: <rig>, Name: <name>
@@ -49,20 +48,18 @@ func ParseSessionName(session string) (*AgentIdentity, error) {
return nil, fmt.Errorf("invalid session name %q: empty after prefix", session) return nil, fmt.Errorf("invalid session name %q: empty after prefix", session)
} }
// Parse into parts // Check for simple town-level roles (no rig qualifier)
parts := strings.Split(suffix, "-") if suffix == "mayor" {
if len(parts) < 2 { return &AgentIdentity{Role: RoleMayor}, nil
return nil, fmt.Errorf("invalid session name %q: expected town-role or rig-role format", session) }
if suffix == "deacon" {
return &AgentIdentity{Role: RoleDeacon}, nil
} }
// Check for mayor/deacon (town-level roles with suffix marker) // Parse into parts for rig-level roles
if parts[len(parts)-1] == "mayor" { parts := strings.Split(suffix, "-")
town := strings.Join(parts[:len(parts)-1], "-") if len(parts) < 2 {
return &AgentIdentity{Role: RoleMayor, Town: town}, nil return nil, fmt.Errorf("invalid session name %q: expected rig-role format", session)
}
if parts[len(parts)-1] == "deacon" {
town := strings.Join(parts[:len(parts)-1], "-")
return &AgentIdentity{Role: RoleDeacon, Town: town}, nil
} }
// Check for witness/refinery (suffix markers) // Check for witness/refinery (suffix markers)
@@ -97,9 +94,9 @@ func ParseSessionName(session string) (*AgentIdentity, error) {
func (a *AgentIdentity) SessionName() string { func (a *AgentIdentity) SessionName() string {
switch a.Role { switch a.Role {
case RoleMayor: case RoleMayor:
return MayorSessionName(a.Town) return MayorSessionName()
case RoleDeacon: case RoleDeacon:
return DeaconSessionName(a.Town) return DeaconSessionName()
case RoleWitness: case RoleWitness:
return WitnessSessionName(a.Rig) return WitnessSessionName(a.Rig)
case RoleRefinery: case RoleRefinery:

View File

@@ -6,38 +6,23 @@ import (
func TestParseSessionName(t *testing.T) { func TestParseSessionName(t *testing.T) {
tests := []struct { tests := []struct {
name string name string
session string session string
wantRole Role wantRole Role
wantTown string wantRig string
wantRig string wantName string
wantName string wantErr bool
wantErr bool
}{ }{
// Town-level roles (mayor/deacon with town name) // Town-level roles (simple gt-mayor, gt-deacon)
{ {
name: "mayor simple town", name: "mayor",
session: "gt-ai-mayor", session: "gt-mayor",
wantRole: RoleMayor, wantRole: RoleMayor,
wantTown: "ai",
}, },
{ {
name: "mayor hyphenated town", name: "deacon",
session: "gt-my-town-mayor", session: "gt-deacon",
wantRole: RoleMayor,
wantTown: "my-town",
},
{
name: "deacon simple town",
session: "gt-alpha-deacon",
wantRole: RoleDeacon, wantRole: RoleDeacon,
wantTown: "alpha",
},
{
name: "deacon hyphenated town",
session: "gt-my-town-deacon",
wantRole: RoleDeacon,
wantTown: "my-town",
}, },
// Witness (simple rig) // Witness (simple rig)
@@ -138,9 +123,6 @@ func TestParseSessionName(t *testing.T) {
if got.Role != tt.wantRole { if got.Role != tt.wantRole {
t.Errorf("ParseSessionName(%q).Role = %v, want %v", tt.session, got.Role, tt.wantRole) t.Errorf("ParseSessionName(%q).Role = %v, want %v", tt.session, got.Role, tt.wantRole)
} }
if got.Town != tt.wantTown {
t.Errorf("ParseSessionName(%q).Town = %v, want %v", tt.session, got.Town, tt.wantTown)
}
if got.Rig != tt.wantRig { if got.Rig != tt.wantRig {
t.Errorf("ParseSessionName(%q).Rig = %v, want %v", tt.session, got.Rig, tt.wantRig) t.Errorf("ParseSessionName(%q).Rig = %v, want %v", tt.session, got.Rig, tt.wantRig)
} }
@@ -158,19 +140,14 @@ func TestAgentIdentity_SessionName(t *testing.T) {
want string want string
}{ }{
{ {
name: "mayor with town", name: "mayor",
identity: AgentIdentity{Role: RoleMayor, Town: "ai"}, identity: AgentIdentity{Role: RoleMayor},
want: "gt-ai-mayor", want: "gt-mayor",
}, },
{ {
name: "mayor hyphenated town", name: "deacon",
identity: AgentIdentity{Role: RoleMayor, Town: "my-town"}, identity: AgentIdentity{Role: RoleDeacon},
want: "gt-my-town-mayor", want: "gt-deacon",
},
{
name: "deacon with town",
identity: AgentIdentity{Role: RoleDeacon, Town: "alpha"},
want: "gt-alpha-deacon",
}, },
{ {
name: "witness", name: "witness",
@@ -253,8 +230,8 @@ func TestAgentIdentity_Address(t *testing.T) {
func TestParseSessionName_RoundTrip(t *testing.T) { func TestParseSessionName_RoundTrip(t *testing.T) {
// Test that parsing then reconstructing gives the same result // Test that parsing then reconstructing gives the same result
sessions := []string{ sessions := []string{
"gt-ai-mayor", "gt-mayor",
"gt-alpha-deacon", "gt-deacon",
"gt-gastown-witness", "gt-gastown-witness",
"gt-foo-bar-refinery", "gt-foo-bar-refinery",
"gt-gastown-crew-max", "gt-gastown-crew-max",

View File

@@ -12,17 +12,15 @@ import (
const Prefix = "gt-" const Prefix = "gt-"
// MayorSessionName returns the session name for the Mayor agent. // MayorSessionName returns the session name for the Mayor agent.
// The townName parameter allows multiple towns to run concurrently // One mayor per machine - multi-town requires containers/VMs for isolation.
// without tmux session name collisions. func MayorSessionName() string {
func MayorSessionName(townName string) string { return Prefix + "mayor"
return fmt.Sprintf("%s%s-mayor", Prefix, townName)
} }
// DeaconSessionName returns the session name for the Deacon agent. // DeaconSessionName returns the session name for the Deacon agent.
// The townName parameter allows multiple towns to run concurrently // One deacon per machine - multi-town requires containers/VMs for isolation.
// without tmux session name collisions. func DeaconSessionName() string {
func DeaconSessionName(townName string) string { return Prefix + "deacon"
return fmt.Sprintf("%s%s-deacon", Prefix, townName)
} }
// WitnessSessionName returns the session name for a rig's Witness agent. // WitnessSessionName returns the session name for a rig's Witness agent.

View File

@@ -8,42 +8,20 @@ import (
) )
func TestMayorSessionName(t *testing.T) { func TestMayorSessionName(t *testing.T) {
tests := []struct { // Mayor session name is now fixed (one per machine)
townName string want := "gt-mayor"
want string got := MayorSessionName()
}{ if got != want {
{"ai", "gt-ai-mayor"}, t.Errorf("MayorSessionName() = %q, want %q", got, want)
{"alpha", "gt-alpha-mayor"},
{"gastown", "gt-gastown-mayor"},
{"", "gt--mayor"}, // empty town name
}
for _, tt := range tests {
t.Run(tt.townName, func(t *testing.T) {
got := MayorSessionName(tt.townName)
if got != tt.want {
t.Errorf("MayorSessionName(%q) = %q, want %q", tt.townName, got, tt.want)
}
})
} }
} }
func TestDeaconSessionName(t *testing.T) { func TestDeaconSessionName(t *testing.T) {
tests := []struct { // Deacon session name is now fixed (one per machine)
townName string want := "gt-deacon"
want string got := DeaconSessionName()
}{ if got != want {
{"ai", "gt-ai-deacon"}, t.Errorf("DeaconSessionName() = %q, want %q", got, want)
{"alpha", "gt-alpha-deacon"},
{"gastown", "gt-gastown-deacon"},
{"", "gt--deacon"}, // empty town name
}
for _, tt := range tests {
t.Run(tt.townName, func(t *testing.T) {
got := DeaconSessionName(tt.townName)
if got != tt.want {
t.Errorf("DeaconSessionName(%q) = %q, want %q", tt.townName, got, tt.want)
}
})
} }
} }