diff --git a/internal/cmd/rig_helpers.go b/internal/cmd/rig_helpers.go index 3a097aa0..d577aa1d 100644 --- a/internal/cmd/rig_helpers.go +++ b/internal/cmd/rig_helpers.go @@ -2,9 +2,9 @@ package cmd import ( "fmt" - "path/filepath" "github.com/steveyegge/gastown/internal/config" + "github.com/steveyegge/gastown/internal/constants" "github.com/steveyegge/gastown/internal/git" "github.com/steveyegge/gastown/internal/rig" "github.com/steveyegge/gastown/internal/workspace" @@ -19,7 +19,7 @@ func getRig(rigName string) (string, *rig.Rig, error) { return "", nil, fmt.Errorf("not in a Gas Town workspace: %w", err) } - rigsConfigPath := filepath.Join(townRoot, "mayor", "rigs.json") + rigsConfigPath := constants.MayorRigsPath(townRoot) rigsConfig, err := config.LoadRigsConfig(rigsConfigPath) if err != nil { rigsConfig = &config.RigsConfig{Rigs: make(map[string]config.RigEntry)} diff --git a/internal/cmd/status.go b/internal/cmd/status.go index f453343d..3542abb2 100644 --- a/internal/cmd/status.go +++ b/internal/cmd/status.go @@ -8,6 +8,7 @@ import ( "github.com/spf13/cobra" "github.com/steveyegge/gastown/internal/config" + "github.com/steveyegge/gastown/internal/constants" "github.com/steveyegge/gastown/internal/crew" "github.com/steveyegge/gastown/internal/git" "github.com/steveyegge/gastown/internal/rig" @@ -68,7 +69,7 @@ func runStatus(cmd *cobra.Command, args []string) error { } // Load town config - townConfigPath := filepath.Join(townRoot, "mayor", "town.json") + townConfigPath := constants.MayorTownPath(townRoot) townConfig, err := config.LoadTownConfig(townConfigPath) if err != nil { // Try to continue without config @@ -76,7 +77,7 @@ func runStatus(cmd *cobra.Command, args []string) error { } // Load rigs config - rigsConfigPath := filepath.Join(townRoot, "mayor", "rigs.json") + rigsConfigPath := constants.MayorRigsPath(townRoot) rigsConfig, err := config.LoadRigsConfig(rigsConfigPath) if err != nil { // Empty config if file doesn't exist diff --git a/internal/constants/constants.go b/internal/constants/constants.go new file mode 100644 index 00000000..723dbc2a --- /dev/null +++ b/internal/constants/constants.go @@ -0,0 +1,138 @@ +// Package constants defines shared constant values used throughout Gas Town. +// Centralizing these magic strings improves maintainability and consistency. +package constants + +// Directory names within a Gas Town workspace. +const ( + // DirMayor is the directory containing mayor configuration and state. + DirMayor = "mayor" + + // DirPolecats is the directory containing polecat worktrees. + DirPolecats = "polecats" + + // DirCrew is the directory containing crew workspaces. + DirCrew = "crew" + + // DirRefinery is the directory containing the refinery clone. + DirRefinery = "refinery" + + // DirWitness is the directory containing witness state. + DirWitness = "witness" + + // DirRig is the subdirectory containing the actual git clone. + DirRig = "rig" + + // DirBeads is the beads database directory. + DirBeads = ".beads" + + // DirGastown is the per-rig runtime state directory. + DirGastown = ".gastown" +) + +// File names for configuration and state. +const ( + // FileRigsJSON is the rig registry file in mayor/. + FileRigsJSON = "rigs.json" + + // FileTownJSON is the town configuration file in mayor/. + FileTownJSON = "town.json" + + // FileStateJSON is the agent state file. + FileStateJSON = "state.json" + + // FileConfigJSON is the general config file. + FileConfigJSON = "config.json" + + // FileConfigYAML is the beads config file. + FileConfigYAML = "config.yaml" +) + +// Git branch names. +const ( + // BranchMain is the default main branch name. + BranchMain = "main" + + // BranchBeadsSync is the branch used for beads synchronization. + BranchBeadsSync = "beads-sync" + + // BranchPolecatPrefix is the prefix for polecat work branches. + BranchPolecatPrefix = "polecat/" + + // BranchIntegrationPrefix is the prefix for integration branches. + BranchIntegrationPrefix = "integration/" +) + +// Tmux session names. +const ( + // SessionMayor is the tmux session name for the mayor. + SessionMayor = "gt-mayor" + + // SessionDeacon is the tmux session name for the deacon. + SessionDeacon = "gt-deacon" + + // SessionPrefix is the prefix for all Gas Town tmux sessions. + SessionPrefix = "gt-" +) + +// Agent role names. +const ( + // RoleMayor is the mayor agent role. + RoleMayor = "mayor" + + // RoleWitness is the witness agent role. + RoleWitness = "witness" + + // RoleRefinery is the refinery agent role. + RoleRefinery = "refinery" + + // RolePolecat is the polecat agent role. + RolePolecat = "polecat" + + // RoleCrew is the crew agent role. + RoleCrew = "crew" + + // RoleDeacon is the deacon agent role. + RoleDeacon = "deacon" +) + +// Path helpers construct common paths. + +// MayorRigsPath returns the path to rigs.json within a town root. +func MayorRigsPath(townRoot string) string { + return townRoot + "/" + DirMayor + "/" + FileRigsJSON +} + +// MayorTownPath returns the path to town.json within a town root. +func MayorTownPath(townRoot string) string { + return townRoot + "/" + DirMayor + "/" + FileTownJSON +} + +// MayorStatePath returns the path to mayor state.json within a town root. +func MayorStatePath(townRoot string) string { + return townRoot + "/" + DirMayor + "/" + FileStateJSON +} + +// RigMayorPath returns the path to mayor/rig within a rig. +func RigMayorPath(rigPath string) string { + return rigPath + "/" + DirMayor + "/" + DirRig +} + +// RigBeadsPath returns the path to mayor/rig/.beads within a rig. +func RigBeadsPath(rigPath string) string { + return rigPath + "/" + DirMayor + "/" + DirRig + "/" + DirBeads +} + +// RigPolecatsPath returns the path to polecats/ within a rig. +func RigPolecatsPath(rigPath string) string { + return rigPath + "/" + DirPolecats +} + +// RigCrewPath returns the path to crew/ within a rig. +func RigCrewPath(rigPath string) string { + return rigPath + "/" + DirCrew +} + +// GastownPath returns the path to .gastown/ within a rig. +func GastownPath(rigPath string) string { + return rigPath + "/" + DirGastown +} diff --git a/internal/daemon/daemon.go b/internal/daemon/daemon.go index f5b9aa9d..e8936109 100644 --- a/internal/daemon/daemon.go +++ b/internal/daemon/daemon.go @@ -15,6 +15,7 @@ import ( "github.com/steveyegge/gastown/internal/beads" "github.com/steveyegge/gastown/internal/config" + "github.com/steveyegge/gastown/internal/constants" "github.com/steveyegge/gastown/internal/git" "github.com/steveyegge/gastown/internal/keepalive" "github.com/steveyegge/gastown/internal/rig" @@ -388,8 +389,8 @@ func (d *Daemon) pokeDeacon() { // pokeMayor sends a heartbeat to the Mayor session. func (d *Daemon) pokeMayor() { - const mayorSession = "gt-mayor" - const agentID = "mayor" + mayorSession := constants.SessionMayor + agentID := constants.RoleMayor running, err := d.tmux.HasSession(mayorSession) if err != nil { @@ -484,7 +485,7 @@ func (d *Daemon) pokeWitnesses() { // Falls back to directory scanning if rigs.json is not available. func (d *Daemon) discoverRigs() []*rig.Rig { // Load rigs config from mayor/rigs.json - rigsConfigPath := filepath.Join(d.config.TownRoot, "mayor", "rigs.json") + rigsConfigPath := constants.MayorRigsPath(d.config.TownRoot) rigsConfig, err := config.LoadRigsConfig(rigsConfigPath) if err != nil { // Try fallback: scan town directory for rig directories