From bac6f084ff14677685305d88052d35741990dff5 Mon Sep 17 00:00:00 2001 From: Steve Yegge Date: Sun, 28 Dec 2025 12:59:54 -0800 Subject: [PATCH] Wire polecat-CLAUDE.md template into polecat spawn (gt-34mxx) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add installCLAUDETemplate() to Manager that: - Reads templates/polecat-CLAUDE.md from rig root - Substitutes {{rig}} and {{name}} with actual values - Writes to polecats//CLAUDE.md Called from both Add() and Recreate() after worktree creation. Non-fatal if template is missing. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 --- internal/polecat/manager.go | 40 +++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/internal/polecat/manager.go b/internal/polecat/manager.go index fc2f400a..11963357 100644 --- a/internal/polecat/manager.go +++ b/internal/polecat/manager.go @@ -5,6 +5,7 @@ import ( "fmt" "os" "path/filepath" + "strings" "time" "github.com/steveyegge/gastown/internal/beads" @@ -153,6 +154,11 @@ func (m *Manager) Add(name string) (*Polecat, error) { return nil, fmt.Errorf("creating worktree: %w", err) } + // Install polecat CLAUDE.md template (non-fatal if template missing) + if err := m.installCLAUDETemplate(polecatPath, name); err != nil { + fmt.Printf("Warning: could not install CLAUDE.md template: %v\n", err) + } + // Set up shared beads: polecat uses rig's .beads via redirect file. // This eliminates git sync overhead - all polecats share one database. if err := m.setupSharedBeads(polecatPath); err != nil { @@ -344,6 +350,11 @@ func (m *Manager) Recreate(name string, force bool) (*Polecat, error) { return nil, fmt.Errorf("creating fresh worktree: %w", err) } + // Install polecat CLAUDE.md template (non-fatal if template missing) + if err := m.installCLAUDETemplate(polecatPath, name); err != nil { + fmt.Printf("Warning: could not install CLAUDE.md template: %v\n", err) + } + // Set up shared beads if err := m.setupSharedBeads(polecatPath); err != nil { fmt.Printf("Warning: could not set up shared beads: %v\n", err) @@ -647,6 +658,35 @@ func (m *Manager) loadFromBeads(name string) (*Polecat, error) { }, nil } +// installCLAUDETemplate copies the polecat CLAUDE.md template into the worktree. +// Template variables {{rig}} and {{name}} are substituted with actual values. +// This provides polecats with context about their role and available commands. +func (m *Manager) installCLAUDETemplate(polecatPath, name string) error { + // Read template from rig's templates directory + templatePath := filepath.Join(m.rig.Path, "templates", "polecat-CLAUDE.md") + content, err := os.ReadFile(templatePath) + if err != nil { + if os.IsNotExist(err) { + // Template doesn't exist - this is fine, just skip + return nil + } + return fmt.Errorf("reading template: %w", err) + } + + // Substitute template variables + output := string(content) + output = strings.ReplaceAll(output, "{{rig}}", m.rig.Name) + output = strings.ReplaceAll(output, "{{name}}", name) + + // Write to polecat's CLAUDE.md + claudePath := filepath.Join(polecatPath, "CLAUDE.md") + if err := os.WriteFile(claudePath, []byte(output), 0644); err != nil { + return fmt.Errorf("writing CLAUDE.md: %w", err) + } + + return nil +} + // setupSharedBeads creates a redirect file so the polecat uses the rig's shared .beads database. // This eliminates the need for git sync between polecat clones - all polecats share one database. //