Skip to content

Commit 8d17fe0

Browse files
refactor: replace hardcoded role strings with constants in 8 files (gt-2e5q)
Replace 63 raw role string literals ("mayor", "deacon", "witness", "refinery", "polecat", "crew") with constants.Role* values across: - daemon/lifecycle.go (26 replacements) - cmd/mail_identity.go (12) - cmd/nudge.go (8) - cmd/handoff.go (8) - config/env.go (6) - runtime/runtime.go (1) - claude/settings.go (1) - gemini/settings.go (1) This is the first batch targeting the highest-density files. Remaining: 65 occurrences across 20 more files. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 7b98642 commit 8d17fe0

8 files changed

Lines changed: 89 additions & 80 deletions

File tree

internal/claude/settings.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import (
66
"fmt"
77
"os"
88
"path/filepath"
9+
10+
"github.com/steveyegge/gastown/internal/constants"
911
)
1012

1113
//go:embed config/*.json
@@ -27,7 +29,7 @@ const (
2729
// RoleTypeFor returns the RoleType for a given role name.
2830
func RoleTypeFor(role string) RoleType {
2931
switch role {
30-
case "polecat", "witness", "refinery", "deacon", "boot":
32+
case constants.RolePolecat, constants.RoleWitness, constants.RoleRefinery, constants.RoleDeacon, "boot":
3133
return Autonomous
3234
default:
3335
return Interactive

internal/cmd/handoff.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -586,13 +586,13 @@ func resolveRoleToSession(role string) (string, error) {
586586
}
587587

588588
switch strings.ToLower(role) {
589-
case "mayor", "may":
589+
case constants.RoleMayor, "may":
590590
return getMayorSessionName(), nil
591591

592-
case "deacon", "dea":
592+
case constants.RoleDeacon, "dea":
593593
return getDeaconSessionName(), nil
594594

595-
case "crew":
595+
case constants.RoleCrew:
596596
// Try to get rig and crew name from environment or cwd
597597
rig := os.Getenv("GT_RIG")
598598
crewName := os.Getenv("GT_CREW")
@@ -609,14 +609,14 @@ func resolveRoleToSession(role string) (string, error) {
609609
}
610610
return session.CrewSessionName(session.PrefixFor(rig), crewName), nil
611611

612-
case "witness", "wit":
612+
case constants.RoleWitness, "wit":
613613
rig := os.Getenv("GT_RIG")
614614
if rig == "" {
615615
return "", fmt.Errorf("cannot determine rig - set GT_RIG or run from rig context")
616616
}
617617
return session.WitnessSessionName(session.PrefixFor(rig)), nil
618618

619-
case "refinery", "ref":
619+
case constants.RoleRefinery, "ref":
620620
rig := os.Getenv("GT_RIG")
621621
if rig == "" {
622622
return "", fmt.Errorf("cannot determine rig - set GT_RIG or run from rig context")
@@ -640,7 +640,7 @@ func resolvePathToSession(path string) (string, error) {
640640
parts := strings.Split(path, "/")
641641

642642
// Handle <rig>/crew/<name> format
643-
if len(parts) == 3 && parts[1] == "crew" {
643+
if len(parts) == 3 && parts[1] == constants.RoleCrew {
644644
rig := parts[0]
645645
name := parts[2]
646646
return session.CrewSessionName(session.PrefixFor(rig), name), nil
@@ -661,11 +661,11 @@ func resolvePathToSession(path string) (string, error) {
661661

662662
// Check for known roles first
663663
switch secondLower {
664-
case "witness":
664+
case constants.RoleWitness:
665665
return session.WitnessSessionName(session.PrefixFor(rig)), nil
666-
case "refinery":
666+
case constants.RoleRefinery:
667667
return session.RefinerySessionName(session.PrefixFor(rig)), nil
668-
case "crew":
668+
case constants.RoleCrew:
669669
// Just "<rig>/crew" without a name - need more info
670670
return "", fmt.Errorf("crew path requires name: %s/crew/<name>", rig)
671671
case "polecats":

internal/cmd/mail_identity.go

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"path/filepath"
88
"strings"
99

10+
"github.com/steveyegge/gastown/internal/constants"
1011
"github.com/steveyegge/gastown/internal/workspace"
1112
)
1213

@@ -102,30 +103,30 @@ func detectSenderFromRole(role string) string {
102103

103104
// GT_ROLE is a simple role name, build the full address
104105
switch role {
105-
case "mayor":
106+
case constants.RoleMayor:
106107
return "mayor/"
107-
case "deacon":
108+
case constants.RoleDeacon:
108109
return "deacon/"
109-
case "polecat":
110+
case constants.RolePolecat:
110111
polecat := os.Getenv("GT_POLECAT")
111112
if rig != "" && polecat != "" {
112113
return fmt.Sprintf("%s/%s", rig, polecat)
113114
}
114115
// Fallback to cwd detection for polecats
115116
return detectSenderFromCwd()
116-
case "crew":
117+
case constants.RoleCrew:
117118
crew := os.Getenv("GT_CREW")
118119
if rig != "" && crew != "" {
119120
return fmt.Sprintf("%s/crew/%s", rig, crew)
120121
}
121122
// Fallback to cwd detection for crew
122123
return detectSenderFromCwd()
123-
case "witness":
124+
case constants.RoleWitness:
124125
if rig != "" {
125126
return fmt.Sprintf("%s/witness", rig)
126127
}
127128
return detectSenderFromCwd()
128-
case "refinery":
129+
case constants.RoleRefinery:
129130
if rig != "" {
130131
return fmt.Sprintf("%s/refinery", rig)
131132
}
@@ -232,23 +233,23 @@ func identityFromAgentFile(parsed agentIdentityFile) string {
232233
name := strings.TrimSpace(parsed.Name)
233234

234235
switch role {
235-
case "mayor":
236+
case constants.RoleMayor:
236237
return "mayor/"
237-
case "deacon":
238+
case constants.RoleDeacon:
238239
return "deacon/"
239-
case "witness":
240+
case constants.RoleWitness:
240241
if rig != "" {
241242
return fmt.Sprintf("%s/witness", rig)
242243
}
243-
case "refinery":
244+
case constants.RoleRefinery:
244245
if rig != "" {
245246
return fmt.Sprintf("%s/refinery", rig)
246247
}
247-
case "crew":
248+
case constants.RoleCrew:
248249
if rig != "" && name != "" {
249250
return fmt.Sprintf("%s/crew/%s", rig, name)
250251
}
251-
case "polecat":
252+
case constants.RolePolecat:
252253
if rig != "" && name != "" {
253254
return fmt.Sprintf("%s/polecats/%s", rig, name)
254255
}

internal/cmd/nudge.go

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"github.com/spf13/cobra"
1313
"github.com/steveyegge/gastown/internal/beads"
1414
"github.com/steveyegge/gastown/internal/config"
15+
"github.com/steveyegge/gastown/internal/constants"
1516
"github.com/steveyegge/gastown/internal/events"
1617
"github.com/steveyegge/gastown/internal/nudge"
1718
"github.com/steveyegge/gastown/internal/session"
@@ -292,9 +293,9 @@ func runNudge(cmd *cobra.Command, args []string) (retErr error) {
292293
// Expand role shortcuts to session names
293294
// These shortcuts let users type "mayor" instead of "gt-mayor"
294295
switch target {
295-
case "mayor":
296+
case constants.RoleMayor:
296297
target = session.MayorSessionName()
297-
case "witness", "refinery":
298+
case constants.RoleWitness, constants.RoleRefinery:
298299
// These need the current rig
299300
roleInfo, err := GetRole()
300301
if err != nil {
@@ -304,15 +305,15 @@ func runNudge(cmd *cobra.Command, args []string) (retErr error) {
304305
return fmt.Errorf("cannot determine rig for %s shortcut (not in a rig context)", target)
305306
}
306307
rigPrefix := session.PrefixFor(roleInfo.Rig)
307-
if target == "witness" {
308+
if target == constants.RoleWitness {
308309
target = session.WitnessSessionName(rigPrefix)
309310
} else {
310311
target = session.RefinerySessionName(rigPrefix)
311312
}
312313
}
313314

314315
// Special case: "deacon" target maps to the Deacon session
315-
if target == "deacon" {
316+
if target == constants.RoleDeacon {
316317
deaconSession := session.DeaconSessionName()
317318
// Check if Deacon session exists
318319
exists, err := t.HasSession(deaconSession)
@@ -552,9 +553,9 @@ func resolveNudgePattern(pattern string, agents []*AgentSession) []string {
552553

553554
// Handle special cases
554555
switch pattern {
555-
case "mayor":
556+
case constants.RoleMayor:
556557
return []string{session.MayorSessionName()}
557-
case "deacon":
558+
case constants.RoleDeacon:
558559
return []string{session.DeaconSessionName()}
559560
}
560561

@@ -685,9 +686,9 @@ func sessionNameToAddress(sessionName string) string {
685686
func addressToAgentBeadID(address string) string {
686687
// Handle special cases
687688
switch address {
688-
case "mayor":
689+
case constants.RoleMayor:
689690
return session.MayorSessionName()
690-
case "deacon":
691+
case constants.RoleDeacon:
691692
return session.DeaconSessionName()
692693
}
693694

@@ -705,9 +706,9 @@ func addressToAgentBeadID(address string) string {
705706
role := parts[1]
706707

707708
switch role {
708-
case "witness":
709+
case constants.RoleWitness:
709710
return session.WitnessSessionName(session.PrefixFor(rig))
710-
case "refinery":
711+
case constants.RoleRefinery:
711712
return session.RefinerySessionName(session.PrefixFor(rig))
712713
default:
713714
// Assume polecat

internal/config/env.go

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import (
77
"path/filepath"
88
"sort"
99
"strings"
10+
11+
"github.com/steveyegge/gastown/internal/constants"
1012
)
1113

1214
// AgentEnvConfig specifies the configuration for generating agent environment variables.
@@ -69,12 +71,12 @@ func AgentEnv(cfg AgentEnvConfig) map[string]string {
6971
// GT_ROLE is set in compound format (e.g., "beads/crew/jane") so that
7072
// beads can parse it without knowing about Gas Town role types.
7173
switch cfg.Role {
72-
case "mayor":
74+
case constants.RoleMayor:
7375
env["GT_ROLE"] = "mayor"
7476
env["BD_ACTOR"] = "mayor"
7577
env["GIT_AUTHOR_NAME"] = "mayor"
7678

77-
case "deacon":
79+
case constants.RoleDeacon:
7880
env["GT_ROLE"] = "deacon"
7981
env["BD_ACTOR"] = "deacon"
8082
env["GIT_AUTHOR_NAME"] = "deacon"
@@ -84,19 +86,19 @@ func AgentEnv(cfg AgentEnvConfig) map[string]string {
8486
env["BD_ACTOR"] = "deacon-boot"
8587
env["GIT_AUTHOR_NAME"] = "boot"
8688

87-
case "witness":
89+
case constants.RoleWitness:
8890
env["GT_ROLE"] = fmt.Sprintf("%s/witness", cfg.Rig)
8991
env["GT_RIG"] = cfg.Rig
9092
env["BD_ACTOR"] = fmt.Sprintf("%s/witness", cfg.Rig)
9193
env["GIT_AUTHOR_NAME"] = fmt.Sprintf("%s/witness", cfg.Rig)
9294

93-
case "refinery":
95+
case constants.RoleRefinery:
9496
env["GT_ROLE"] = fmt.Sprintf("%s/refinery", cfg.Rig)
9597
env["GT_RIG"] = cfg.Rig
9698
env["BD_ACTOR"] = fmt.Sprintf("%s/refinery", cfg.Rig)
9799
env["GIT_AUTHOR_NAME"] = fmt.Sprintf("%s/refinery", cfg.Rig)
98100

99-
case "polecat":
101+
case constants.RolePolecat:
100102
env["GT_ROLE"] = fmt.Sprintf("%s/polecats/%s", cfg.Rig, cfg.AgentName)
101103
env["GT_RIG"] = cfg.Rig
102104
env["GT_POLECAT"] = cfg.AgentName
@@ -108,7 +110,7 @@ func AgentEnv(cfg AgentEnvConfig) map[string]string {
108110
// contention leading to Dolt read-only mode (gt-5cc2p).
109111
env["BD_DOLT_AUTO_COMMIT"] = "off"
110112

111-
case "crew":
113+
case constants.RoleCrew:
112114
env["GT_ROLE"] = fmt.Sprintf("%s/crew/%s", cfg.Rig, cfg.AgentName)
113115
env["GT_RIG"] = cfg.Rig
114116
env["GT_CREW"] = cfg.AgentName
@@ -139,7 +141,7 @@ func AgentEnv(cfg AgentEnvConfig) map[string]string {
139141
}
140142

141143
// Set BEADS_AGENT_NAME for polecat/crew (uses same format as BD_ACTOR)
142-
if cfg.Role == "polecat" || cfg.Role == "crew" {
144+
if cfg.Role == constants.RolePolecat || cfg.Role == constants.RoleCrew {
143145
env["BEADS_AGENT_NAME"] = fmt.Sprintf("%s/%s", cfg.Rig, cfg.AgentName)
144146
}
145147

0 commit comments

Comments
 (0)