Implement three-tier config architecture (gt-k1lr tasks 1-5)

**Architecture changes:**
- Renamed `.gastown/` → `.runtime/` for runtime state (gitignored)
- Added `settings/` directory for rig behavioral config (git-tracked)
- Added `mayor/config.json` for town-level config (MayorConfig type)
- Separated RigConfig (identity) from RigSettings (behavioral)

**File location changes:**
- Town runtime: `~/.gastown/*` → `~/.runtime/*`
- Rig runtime: `<rig>/.gastown/*` → `<rig>/.runtime/*`
- Rig config: `<rig>/.gastown/config.json` → `<rig>/settings/config.json`
- Namepool state: `namepool.json` → `namepool-state.json`

**New types:**
- MayorConfig: town-level behavioral config
- RigSettings: rig behavioral config (merge_queue, theme, namepool)
- RigConfig now identity-only (name, git_url, beads, created_at)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Steve Yegge
2025-12-22 01:22:27 -08:00
parent f16ce2d634
commit 97e0535bfe
20 changed files with 449 additions and 201 deletions

View File

@@ -79,9 +79,9 @@ const HQGitignore = `# Gas Town HQ .gitignore
**/crew/
# =============================================================================
# Rig runtime state directories
# Runtime state directories (gitignored ephemeral data)
# =============================================================================
**/.gastown/
**/.runtime/
# =============================================================================
# Rig .beads symlinks (point to ignored mayor/rig/.beads, recreated on setup)

View File

@@ -480,7 +480,7 @@ func setRequestingState(role Role, action HandoffAction, townRoot string) error
}
default:
// For other roles, use a generic location
stateFile = filepath.Join(townRoot, ".gastown", "agent-state.json")
stateFile = filepath.Join(townRoot, ".runtime", "agent-state.json")
}
// Ensure directory exists

View File

@@ -10,6 +10,7 @@ import (
"github.com/spf13/cobra"
"github.com/steveyegge/gastown/internal/beads"
"github.com/steveyegge/gastown/internal/config"
"github.com/steveyegge/gastown/internal/git"
"github.com/steveyegge/gastown/internal/style"
"github.com/steveyegge/gastown/internal/workspace"
@@ -397,33 +398,17 @@ func filterMRsByTarget(mrs []*beads.Issue, targetBranch string) []*beads.Issue {
return result
}
// getTestCommand returns the test command from rig config.
// getTestCommand returns the test command from rig settings.
func getTestCommand(rigPath string) string {
configPath := filepath.Join(rigPath, "config.json")
data, err := os.ReadFile(configPath)
settingsPath := filepath.Join(rigPath, "settings", "config.json")
settings, err := config.LoadRigSettings(settingsPath)
if err != nil {
// Try .gastown/config.json as fallback
configPath = filepath.Join(rigPath, ".gastown", "config.json")
data, err = os.ReadFile(configPath)
if err != nil {
return ""
}
}
var rawConfig struct {
MergeQueue struct {
TestCommand string `json:"test_command"`
} `json:"merge_queue"`
TestCommand string `json:"test_command"` // Legacy fallback
}
if err := json.Unmarshal(data, &rawConfig); err != nil {
return ""
}
if rawConfig.MergeQueue.TestCommand != "" {
return rawConfig.MergeQueue.TestCommand
if settings.MergeQueue != nil && settings.MergeQueue.TestCommand != "" {
return settings.MergeQueue.TestCommand
}
return rawConfig.TestCommand
return ""
}
// runTestCommand executes a test command in the given directory.

View File

@@ -104,9 +104,9 @@ func runNamepool(cmd *cobra.Command, args []string) error {
}
// Check if configured
configPath := filepath.Join(rigPath, ".gastown", "config.json")
if cfg, err := config.LoadRigConfig(configPath); err == nil && cfg.Namepool != nil {
fmt.Printf("(configured in .gastown/config.json)\n")
settingsPath := filepath.Join(rigPath, "settings", "config.json")
if settings, err := config.LoadRigSettings(settingsPath); err == nil && settings.Namepool != nil {
fmt.Printf("(configured in settings/config.json)\n")
}
return nil
@@ -271,39 +271,31 @@ func detectCurrentRigWithPath() (string, string) {
return "", ""
}
// saveRigNamepoolConfig saves the namepool config to rig config.
// saveRigNamepoolConfig saves the namepool config to rig settings.
func saveRigNamepoolConfig(rigPath, theme string, customNames []string) error {
configPath := filepath.Join(rigPath, ".gastown", "config.json")
settingsPath := filepath.Join(rigPath, "settings", "config.json")
// Load existing config or create new
var cfg *config.RigConfig
cfg, err := config.LoadRigConfig(configPath)
// Load existing settings or create new
var settings *config.RigSettings
settings, err := config.LoadRigSettings(settingsPath)
if err != nil {
// Create new config if not found
// Create new settings if not found
if os.IsNotExist(err) || strings.Contains(err.Error(), "not found") {
cfg = &config.RigConfig{
Type: "rig",
Version: config.CurrentRigConfigVersion,
}
settings = config.NewRigSettings()
} else {
return fmt.Errorf("loading config: %w", err)
return fmt.Errorf("loading settings: %w", err)
}
}
// Set namepool
cfg.Namepool = &config.NamepoolConfig{
settings.Namepool = &config.NamepoolConfig{
Style: theme,
Names: customNames,
}
// Ensure directory exists
if err := os.MkdirAll(filepath.Dir(configPath), 0755); err != nil {
return err
}
// Save
if err := config.SaveRigConfig(configPath, cfg); err != nil {
return fmt.Errorf("saving config: %w", err)
// Save (creates directory if needed)
if err := config.SaveRigSettings(settingsPath, settings); err != nil {
return fmt.Errorf("saving settings: %w", err)
}
return nil

View File

@@ -715,7 +715,7 @@ func acquireIdentityLock(ctx RoleContext) error {
fmt.Printf("To resolve:\n")
fmt.Printf(" 1. Find the other session and close it, OR\n")
fmt.Printf(" 2. Run: gt doctor --fix (cleans stale locks)\n")
fmt.Printf(" 3. If lock is stale: rm %s/.gastown/agent.lock\n", ctx.WorkDir)
fmt.Printf(" 3. If lock is stale: rm %s/.runtime/agent.lock\n", ctx.WorkDir)
fmt.Println()
return fmt.Errorf("cannot claim identity %s/%s: %w", ctx.Rig, ctx.Polecat, err)

View File

@@ -147,7 +147,7 @@ type SwarmStore struct {
// LoadSwarmStore loads swarm state from disk.
func LoadSwarmStore(rigPath string) (*SwarmStore, error) {
storePath := filepath.Join(rigPath, ".gastown", "swarms.json")
storePath := filepath.Join(rigPath, ".runtime", "swarms.json")
store := &SwarmStore{
path: storePath,
Swarms: make(map[string]*swarm.Swarm),

View File

@@ -78,7 +78,7 @@ func runTheme(cmd *cobra.Command, args []string) error {
fmt.Printf("Theme: %s (%s)\n", theme.Name, theme.Style())
// Show if it's configured vs default
if configured := loadRigTheme(rigName); configured != "" {
fmt.Printf("(configured in .gastown/config.json)\n")
fmt.Printf("(configured in settings/config.json)\n")
} else {
fmt.Printf("(default, based on rig name hash)\n")
}
@@ -254,8 +254,8 @@ func getThemeForRig(rigName string) tmux.Theme {
// getThemeForRole returns the theme for a specific role in a rig.
// Resolution order:
// 1. Per-rig role override (rig/.gastown/config.json)
// 2. Global role default (mayor/town.json)
// 1. Per-rig role override (rig/settings/config.json)
// 2. Global role default (mayor/config.json)
// 3. Built-in role defaults (witness=rust, refinery=plum)
// 4. Rig theme (config or hash-based)
func getThemeForRole(rigName, role string) tmux.Theme {
@@ -263,10 +263,10 @@ func getThemeForRole(rigName, role string) tmux.Theme {
// 1. Check per-rig role override
if townRoot != "" {
configPath := filepath.Join(townRoot, rigName, ".gastown", "config.json")
if cfg, err := config.LoadRigConfig(configPath); err == nil {
if cfg.Theme != nil && cfg.Theme.RoleThemes != nil {
if themeName, ok := cfg.Theme.RoleThemes[role]; ok {
settingsPath := filepath.Join(townRoot, rigName, "settings", "config.json")
if settings, err := config.LoadRigSettings(settingsPath); err == nil {
if settings.Theme != nil && settings.Theme.RoleThemes != nil {
if themeName, ok := settings.Theme.RoleThemes[role]; ok {
if theme := tmux.GetThemeByName(themeName); theme != nil {
return *theme
}
@@ -275,12 +275,12 @@ func getThemeForRole(rigName, role string) tmux.Theme {
}
}
// 2. Check global role default (town config)
// 2. Check global role default (mayor config)
if townRoot != "" {
townConfigPath := filepath.Join(townRoot, "mayor", "town.json")
if townCfg, err := config.LoadTownConfig(townConfigPath); err == nil {
if townCfg.Theme != nil && townCfg.Theme.RoleDefaults != nil {
if themeName, ok := townCfg.Theme.RoleDefaults[role]; ok {
mayorConfigPath := filepath.Join(townRoot, "mayor", "config.json")
if mayorCfg, err := config.LoadMayorConfig(mayorConfigPath); err == nil {
if mayorCfg.Theme != nil && mayorCfg.Theme.RoleDefaults != nil {
if themeName, ok := mayorCfg.Theme.RoleDefaults[role]; ok {
if theme := tmux.GetThemeByName(themeName); theme != nil {
return *theme
}
@@ -301,26 +301,26 @@ func getThemeForRole(rigName, role string) tmux.Theme {
return getThemeForRig(rigName)
}
// loadRigTheme loads the theme name from rig config.
// loadRigTheme loads the theme name from rig settings.
func loadRigTheme(rigName string) string {
townRoot, err := workspace.FindFromCwd()
if err != nil || townRoot == "" {
return ""
}
configPath := filepath.Join(townRoot, rigName, ".gastown", "config.json")
cfg, err := config.LoadRigConfig(configPath)
settingsPath := filepath.Join(townRoot, rigName, "settings", "config.json")
settings, err := config.LoadRigSettings(settingsPath)
if err != nil {
return ""
}
if cfg.Theme != nil && cfg.Theme.Name != "" {
return cfg.Theme.Name
if settings.Theme != nil && settings.Theme.Name != "" {
return settings.Theme.Name
}
return ""
}
// saveRigTheme saves the theme name to rig config.
// saveRigTheme saves the theme name to rig settings.
func saveRigTheme(rigName, themeName string) error {
townRoot, err := workspace.FindFromCwd()
if err != nil {
@@ -330,31 +330,28 @@ func saveRigTheme(rigName, themeName string) error {
return fmt.Errorf("not in a Gas Town workspace")
}
configPath := filepath.Join(townRoot, rigName, ".gastown", "config.json")
settingsPath := filepath.Join(townRoot, rigName, "settings", "config.json")
// Load existing config or create new
var cfg *config.RigConfig
cfg, err = config.LoadRigConfig(configPath)
// Load existing settings or create new
var settings *config.RigSettings
settings, err = config.LoadRigSettings(settingsPath)
if err != nil {
// Create new config if not found
// Create new settings if not found
if os.IsNotExist(err) || strings.Contains(err.Error(), "not found") {
cfg = &config.RigConfig{
Type: "rig",
Version: config.CurrentRigConfigVersion,
}
settings = config.NewRigSettings()
} else {
return fmt.Errorf("loading config: %w", err)
return fmt.Errorf("loading settings: %w", err)
}
}
// Set theme
cfg.Theme = &config.ThemeConfig{
settings.Theme = &config.ThemeConfig{
Name: themeName,
}
// Save
if err := config.SaveRigConfig(configPath, cfg); err != nil {
return fmt.Errorf("saving config: %w", err)
if err := config.SaveRigSettings(settingsPath, settings); err != nil {
return fmt.Errorf("saving settings: %w", err)
}
return nil