feat(doctor): add custom types check and centralize BeadsCustomTypes

- Add BeadsCustomTypes constant ("agent,role,rig,convoy,slot") to avoid
  hardcoded strings scattered across the codebase
- Add CustomTypesCheck to gt doctor that verifies Gas Town custom types
  are registered with beads, with --fix support
- Register custom types during gt init (best-effort, skips if no beads)
- Update install.go, rig_check.go, and rig/manager.go to use the constant

This ensures consistent type registration across all code paths and
catches misconfigured beads databases via gt doctor.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
gastown/crew/george
2026-01-09 13:19:48 -08:00
committed by Steve Yegge
parent 86739556c2
commit 61b561a540
7 changed files with 179 additions and 8 deletions

View File

@@ -3,10 +3,12 @@ package cmd
import (
"fmt"
"os"
"os/exec"
"path/filepath"
"strings"
"github.com/spf13/cobra"
"github.com/steveyegge/gastown/internal/constants"
"github.com/steveyegge/gastown/internal/git"
"github.com/steveyegge/gastown/internal/rig"
"github.com/steveyegge/gastown/internal/style"
@@ -80,6 +82,16 @@ func runInit(cmd *cobra.Command, args []string) error {
fmt.Printf(" ✓ Updated .git/info/exclude\n")
}
// Register custom beads types for Gas Town (agent, role, rig, convoy, slot).
// This is best-effort: if beads isn't installed or DB doesn't exist, we skip.
// The doctor check will catch missing types later.
if err := registerCustomTypes(cwd); err != nil {
fmt.Printf(" %s Could not register custom types: %v\n",
style.Dim.Render("⚠"), err)
} else {
fmt.Printf(" ✓ Registered custom beads types\n")
}
fmt.Printf("\n%s Rig initialized with %d directories.\n",
style.Bold.Render("✓"), created)
fmt.Println()
@@ -127,3 +139,34 @@ func updateGitExclude(repoPath string) error {
// Write back
return os.WriteFile(excludePath, append(content, []byte(additions)...), 0644)
}
// registerCustomTypes registers Gas Town custom issue types with beads.
// This is best-effort: returns nil if beads isn't available or DB doesn't exist.
// Handles gracefully: beads not installed, no .beads directory, or config errors.
func registerCustomTypes(workDir string) error {
// Check if bd command is available
if _, err := exec.LookPath("bd"); err != nil {
return nil // beads not installed, skip silently
}
// Check if .beads directory exists
beadsDir := filepath.Join(workDir, ".beads")
if _, err := os.Stat(beadsDir); os.IsNotExist(err) {
return nil // no beads DB yet, skip silently
}
// Try to set custom types
cmd := exec.Command("bd", "config", "set", "types.custom", constants.BeadsCustomTypes)
cmd.Dir = workDir
output, err := cmd.CombinedOutput()
if err != nil {
// Check for common expected errors
outStr := string(output)
if strings.Contains(outStr, "not initialized") ||
strings.Contains(outStr, "no such file") {
return nil // DB not initialized, skip silently
}
return fmt.Errorf("%s", strings.TrimSpace(outStr))
}
return nil
}