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

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

View File

@@ -9,20 +9,35 @@ func TestParseSessionName(t *testing.T) {
name string
session string
wantRole Role
wantTown string
wantRig string
wantName string
wantErr bool
}{
// Global roles (no rig)
// Town-level roles (mayor/deacon with town name)
{
name: "mayor",
session: "gt-mayor",
name: "mayor simple town",
session: "gt-ai-mayor",
wantRole: RoleMayor,
wantTown: "ai",
},
{
name: "deacon",
session: "gt-deacon",
name: "mayor hyphenated town",
session: "gt-my-town-mayor",
wantRole: RoleMayor,
wantTown: "my-town",
},
{
name: "deacon simple town",
session: "gt-alpha-deacon",
wantRole: RoleDeacon,
wantTown: "alpha",
},
{
name: "deacon hyphenated town",
session: "gt-my-town-deacon",
wantRole: RoleDeacon,
wantTown: "my-town",
},
// Witness (simple rig)
@@ -104,7 +119,7 @@ func TestParseSessionName(t *testing.T) {
wantErr: true,
},
{
name: "just prefix",
name: "just prefix single segment",
session: "gt-x",
wantErr: true,
},
@@ -123,6 +138,9 @@ func TestParseSessionName(t *testing.T) {
if 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 {
t.Errorf("ParseSessionName(%q).Rig = %v, want %v", tt.session, got.Rig, tt.wantRig)
}
@@ -140,14 +158,19 @@ func TestAgentIdentity_SessionName(t *testing.T) {
want string
}{
{
name: "mayor",
identity: AgentIdentity{Role: RoleMayor},
want: "gt-mayor",
name: "mayor with town",
identity: AgentIdentity{Role: RoleMayor, Town: "ai"},
want: "gt-ai-mayor",
},
{
name: "deacon",
identity: AgentIdentity{Role: RoleDeacon},
want: "gt-deacon",
name: "mayor hyphenated town",
identity: AgentIdentity{Role: RoleMayor, Town: "my-town"},
want: "gt-my-town-mayor",
},
{
name: "deacon with town",
identity: AgentIdentity{Role: RoleDeacon, Town: "alpha"},
want: "gt-alpha-deacon",
},
{
name: "witness",
@@ -230,22 +253,22 @@ func TestAgentIdentity_Address(t *testing.T) {
func TestParseSessionName_RoundTrip(t *testing.T) {
// Test that parsing then reconstructing gives the same result
sessions := []string{
"gt-mayor",
"gt-deacon",
"gt-ai-mayor",
"gt-alpha-deacon",
"gt-gastown-witness",
"gt-foo-bar-refinery",
"gt-gastown-crew-max",
"gt-gastown-morsov",
}
for _, session := range sessions {
t.Run(session, func(t *testing.T) {
identity, err := ParseSessionName(session)
for _, sess := range sessions {
t.Run(sess, func(t *testing.T) {
identity, err := ParseSessionName(sess)
if err != nil {
t.Fatalf("ParseSessionName(%q) error = %v", session, err)
t.Fatalf("ParseSessionName(%q) error = %v", sess, err)
}
if got := identity.SessionName(); got != session {
t.Errorf("Round-trip failed: ParseSessionName(%q).SessionName() = %q", session, got)
if got := identity.SessionName(); got != sess {
t.Errorf("Round-trip failed: ParseSessionName(%q).SessionName() = %q", sess, got)
}
})
}

View File

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

View File

@@ -8,18 +8,42 @@ import (
)
func TestMayorSessionName(t *testing.T) {
want := "gt-mayor"
got := MayorSessionName()
if got != want {
t.Errorf("MayorSessionName() = %q, want %q", got, want)
tests := []struct {
townName string
want string
}{
{"ai", "gt-ai-mayor"},
{"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) {
want := "gt-deacon"
got := DeaconSessionName()
if got != want {
t.Errorf("DeaconSessionName() = %q, want %q", got, want)
tests := []struct {
townName string
want string
}{
{"ai", "gt-ai-deacon"},
{"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)
}
})
}
}