Skip to content

Commit 83c45bb

Browse files
emmettclaude
andcommitted
fix(namepool): read polecat_names from rig config.json as fallback + warn on missing theme
NewManager only read namepool config from settings/config.json. If that file was missing but the rig's config.json had polecat_names configured, the names were ignored and ThemeForRig hash was used instead. Now checks rig config.json for polecat_names when settings/config.json has no namepool config. Also logs a warning when a configured theme name can't be resolved (instead of silently falling back to default). Fixes: #3594 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent c7c5202 commit 83c45bb

4 files changed

Lines changed: 57 additions & 2 deletions

File tree

internal/polecat/manager.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,8 +176,13 @@ func NewManager(r *rig.Rig, g *git.Git, t *tmux.Tmux) *Manager {
176176
settings.Namepool.MaxBeforeNumbering,
177177
)
178178
} else {
179-
// Use defaults
180-
pool = NewNamePool(r.Path, r.Name)
179+
// Fallback: check rig-level config.json for polecat_names
180+
// (pool-init and gt rig config write namepool config here).
181+
if rigCfg, rcErr := rig.LoadRigConfig(r.Path); rcErr == nil && len(rigCfg.PolecatNames) > 0 {
182+
pool = NewNamePoolWithConfig(r.Path, r.Name, "", rigCfg.PolecatNames, 0)
183+
} else {
184+
pool = NewNamePool(r.Path, r.Name)
185+
}
181186
}
182187

183188
// Set town root for custom theme resolution in getNames()

internal/polecat/manager_test.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,32 @@ func TestAgentBeadID_Deterministic(t *testing.T) {
275275
}
276276
}
277277

278+
func TestNewManager_NamepoolFromRigConfig(t *testing.T) {
279+
townRoot := t.TempDir()
280+
rigPath := filepath.Join(townRoot, "myrig")
281+
if err := os.MkdirAll(rigPath, 0755); err != nil {
282+
t.Fatal(err)
283+
}
284+
285+
// Write rig config.json with polecat_names (no settings/config.json)
286+
rigConfig := `{"polecat_names": ["alpha", "beta", "gamma"]}`
287+
if err := os.WriteFile(filepath.Join(rigPath, "config.json"), []byte(rigConfig), 0644); err != nil {
288+
t.Fatal(err)
289+
}
290+
291+
r := &rig.Rig{Name: "myrig", Path: rigPath}
292+
m := NewManager(r, git.NewGit(rigPath), nil)
293+
pool := m.GetNamePool()
294+
295+
name, err := pool.Allocate()
296+
if err != nil {
297+
t.Fatalf("Allocate error: %v", err)
298+
}
299+
if name != "alpha" {
300+
t.Errorf("expected first name from rig config (alpha), got %q", name)
301+
}
302+
}
303+
278304
// Note: State persistence tests removed - state is now derived from beads assignee field.
279305
// Integration tests should verify beads-based state management.
280306

internal/polecat/namepool.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ func (p *NamePool) getNames() []string {
174174
if resolved, err := ResolveThemeNames(p.townRoot, p.Theme); err == nil {
175175
names = resolved
176176
} else {
177+
fmt.Fprintf(os.Stderr, "Warning: namepool theme %q not found (not built-in, no custom theme file); using default\n", p.Theme)
177178
names = BuiltinThemes[DefaultTheme]
178179
}
179180
} else {

internal/polecat/namepool_test.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1228,3 +1228,26 @@ func TestGetNames_FallbackOnDeletedThemeFile(t *testing.T) {
12281228
t.Errorf("expected fallback to default theme (furiosa), got %s", name)
12291229
}
12301230
}
1231+
1232+
func TestGetNames_UnresolvableTheme_FallsBackToDefault(t *testing.T) {
1233+
tmpDir := t.TempDir()
1234+
1235+
pool := NewNamePoolWithConfig(tmpDir, "testrig", "nonexistent-theme", nil, 10)
1236+
pool.SetTownRoot(tmpDir)
1237+
1238+
name, err := pool.Allocate()
1239+
if err != nil {
1240+
t.Fatalf("Allocate error: %v", err)
1241+
}
1242+
defaultNames := BuiltinThemes[DefaultTheme]
1243+
found := false
1244+
for _, dn := range defaultNames {
1245+
if dn == name {
1246+
found = true
1247+
break
1248+
}
1249+
}
1250+
if !found {
1251+
t.Errorf("expected name from default theme, got %q", name)
1252+
}
1253+
}

0 commit comments

Comments
 (0)