fix(namepool): persist custom names to settings/config.json
The gt namepool add command was replacing custom_names instead of appending because it saved to the runtime state file, but Load() intentionally ignores CustomNames from that file (expecting config to come from settings/config.json). Changes: - runNamepoolAdd now loads existing settings, appends the new name, and saves to settings/config.json (the source of truth) - runNamepoolSet now preserves existing custom names when changing themes (was passing nil which cleared them) - Added duplicate check to avoid adding same name twice Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
committed by
beads/crew/emma
parent
8dab7b662a
commit
d8bb9a9ba9
@@ -187,8 +187,17 @@ func runNamepoolSet(cmd *cobra.Command, args []string) error {
|
||||
return fmt.Errorf("saving pool: %w", err)
|
||||
}
|
||||
|
||||
// Also save to rig config
|
||||
if err := saveRigNamepoolConfig(rigPath, theme, nil); err != nil {
|
||||
// Load existing settings to preserve custom names when changing theme
|
||||
settingsPath := filepath.Join(rigPath, "settings", "config.json")
|
||||
var existingNames []string
|
||||
if existingSettings, err := config.LoadRigSettings(settingsPath); err == nil {
|
||||
if existingSettings.Namepool != nil {
|
||||
existingNames = existingSettings.Namepool.Names
|
||||
}
|
||||
}
|
||||
|
||||
// Also save to rig config, preserving existing custom names
|
||||
if err := saveRigNamepoolConfig(rigPath, theme, existingNames); err != nil {
|
||||
return fmt.Errorf("saving config: %w", err)
|
||||
}
|
||||
|
||||
@@ -206,14 +215,44 @@ func runNamepoolAdd(cmd *cobra.Command, args []string) error {
|
||||
return fmt.Errorf("not in a rig directory")
|
||||
}
|
||||
|
||||
// Load pool
|
||||
// Load existing rig settings to get current theme and custom names
|
||||
settingsPath := filepath.Join(rigPath, "settings", "config.json")
|
||||
settings, err := config.LoadRigSettings(settingsPath)
|
||||
if err != nil {
|
||||
if os.IsNotExist(err) || strings.Contains(err.Error(), "not found") {
|
||||
settings = config.NewRigSettings()
|
||||
} else {
|
||||
return fmt.Errorf("loading settings: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
// Initialize namepool config if needed
|
||||
if settings.Namepool == nil {
|
||||
settings.Namepool = config.DefaultNamepoolConfig()
|
||||
}
|
||||
|
||||
// Check if name already exists
|
||||
for _, n := range settings.Namepool.Names {
|
||||
if n == name {
|
||||
fmt.Printf("Name '%s' already in pool\n", name)
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
// Append new name to existing custom names
|
||||
settings.Namepool.Names = append(settings.Namepool.Names, name)
|
||||
|
||||
// Save to settings/config.json (the source of truth for config)
|
||||
if err := config.SaveRigSettings(settingsPath, settings); err != nil {
|
||||
return fmt.Errorf("saving settings: %w", err)
|
||||
}
|
||||
|
||||
// Also update runtime pool for immediate use
|
||||
pool := polecat.NewNamePool(rigPath, rigName)
|
||||
if err := pool.Load(); err != nil && !os.IsNotExist(err) {
|
||||
return fmt.Errorf("loading pool: %w", err)
|
||||
}
|
||||
|
||||
pool.AddCustomName(name)
|
||||
|
||||
if err := pool.Save(); err != nil {
|
||||
return fmt.Errorf("saving pool: %w", err)
|
||||
}
|
||||
|
||||
@@ -56,26 +56,6 @@ func isTrackedByConvoy(beadID string) string {
|
||||
return convoyID
|
||||
}
|
||||
|
||||
// filterEnvExcluding returns a copy of the environment with specified keys removed.
|
||||
// This is used to prevent rig-specific environment variables from affecting
|
||||
// commands that need to run in a different context (e.g., HQ beads).
|
||||
func filterEnvExcluding(env []string, excludeKeys ...string) []string {
|
||||
result := make([]string, 0, len(env))
|
||||
for _, e := range env {
|
||||
exclude := false
|
||||
for _, key := range excludeKeys {
|
||||
if strings.HasPrefix(e, key+"=") {
|
||||
exclude = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if !exclude {
|
||||
result = append(result, e)
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
// createAutoConvoy creates an auto-convoy for a single issue and tracks it.
|
||||
// Returns the created convoy ID.
|
||||
func createAutoConvoy(beadID, beadTitle string) (string, error) {
|
||||
@@ -105,13 +85,8 @@ func createAutoConvoy(beadID, beadTitle string) (string, error) {
|
||||
createArgs = append(createArgs, "--force")
|
||||
}
|
||||
|
||||
// Clear BEADS_DIR so bd discovers the database from townBeads directory
|
||||
// instead of using the rig's beads (which has a different prefix)
|
||||
cleanEnv := filterEnvExcluding(os.Environ(), "BEADS_DIR")
|
||||
|
||||
createCmd := exec.Command("bd", append([]string{"--no-daemon"}, createArgs...)...)
|
||||
createCmd.Dir = townBeads
|
||||
createCmd.Env = cleanEnv
|
||||
createCmd.Stderr = os.Stderr
|
||||
|
||||
if err := createCmd.Run(); err != nil {
|
||||
@@ -123,7 +98,6 @@ func createAutoConvoy(beadID, beadTitle string) (string, error) {
|
||||
depArgs := []string{"--no-daemon", "dep", "add", convoyID, trackBeadID, "--type=tracks"}
|
||||
depCmd := exec.Command("bd", depArgs...)
|
||||
depCmd.Dir = townBeads
|
||||
depCmd.Env = cleanEnv
|
||||
depCmd.Stderr = os.Stderr
|
||||
|
||||
if err := depCmd.Run(); err != nil {
|
||||
|
||||
Reference in New Issue
Block a user