feat: implement ephemeral polecat model
This implements the ephemeral polecat model where polecats are spawned fresh for each task and deleted upon completion. Key changes: **Spawn (internal/cmd/spawn.go):** - Always create fresh worktree from main branch - Run bd init in new worktree to initialize beads - Remove --create flag (now implicit) - Replace stale polecats with fresh worktrees **Handoff (internal/cmd/handoff.go):** - Add rig/polecat detection from environment and tmux session - Send shutdown requests to correct witness (rig/witness) - Include polecat name in lifecycle request body **Witness (internal/witness/manager.go):** - Add mail checking in monitoring loop - Process LIFECYCLE shutdown requests - Implement full cleanup sequence: - Kill tmux session - Remove git worktree - Delete polecat branch **Polecat state machine (internal/polecat/types.go):** - Primary states: working, done, stuck - Deprecate idle/active (kept for backward compatibility) - New polecats start in working state - ClearIssue transitions to done (not idle) **Polecat commands (internal/cmd/polecat.go):** - Update list to show "Active Polecats" - Normalize legacy states for display - Add deprecation warnings to wake/sleep commands Closes gt-7ik 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -226,9 +226,12 @@ func getManager(role Role) string {
|
||||
case RoleMayor, RoleWitness:
|
||||
return "daemon/"
|
||||
case RolePolecat, RoleRefinery:
|
||||
// Would need rig context to determine witness address
|
||||
// For now, use a placeholder pattern
|
||||
return "<rig>/witness"
|
||||
// Detect rig from environment or working directory
|
||||
rigName := detectRigName()
|
||||
if rigName != "" {
|
||||
return rigName + "/witness"
|
||||
}
|
||||
return "witness/" // fallback
|
||||
case RoleCrew:
|
||||
return "human" // Crew is human-managed
|
||||
default:
|
||||
@@ -236,6 +239,41 @@ func getManager(role Role) string {
|
||||
}
|
||||
}
|
||||
|
||||
// detectRigName detects the rig name from environment or directory context.
|
||||
func detectRigName() string {
|
||||
// Check environment variable first
|
||||
if rig := os.Getenv("GT_RIG"); rig != "" {
|
||||
return rig
|
||||
}
|
||||
|
||||
// Try to detect from tmux session name (format: gt-<rig>-<polecat>)
|
||||
out, err := exec.Command("tmux", "display-message", "-p", "#{session_name}").Output()
|
||||
if err == nil {
|
||||
sessionName := strings.TrimSpace(string(out))
|
||||
if strings.HasPrefix(sessionName, "gt-") {
|
||||
parts := strings.SplitN(sessionName, "-", 3)
|
||||
if len(parts) >= 2 {
|
||||
return parts[1]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Try to detect from working directory
|
||||
cwd, err := os.Getwd()
|
||||
if err != nil {
|
||||
return ""
|
||||
}
|
||||
|
||||
// Look for "polecats" in path: .../rig/polecats/polecat/...
|
||||
if idx := strings.Index(cwd, "/polecats/"); idx != -1 {
|
||||
// Extract rig name from path before /polecats/
|
||||
rigPath := cwd[:idx]
|
||||
return filepath.Base(rigPath)
|
||||
}
|
||||
|
||||
return ""
|
||||
}
|
||||
|
||||
// sendHandoffMail sends a handoff message to ourselves for the successor to read.
|
||||
func sendHandoffMail(role Role, townRoot string) error {
|
||||
// Determine our address
|
||||
@@ -286,19 +324,26 @@ func sendLifecycleRequest(manager string, role Role, action HandoffAction, townR
|
||||
return nil
|
||||
}
|
||||
|
||||
// Get polecat name for identification
|
||||
polecatName := detectPolecatName()
|
||||
rigName := detectRigName()
|
||||
|
||||
subject := fmt.Sprintf("LIFECYCLE: %s requesting %s", role, action)
|
||||
body := fmt.Sprintf(`Lifecycle request from %s.
|
||||
|
||||
Action: %s
|
||||
Rig: %s
|
||||
Polecat: %s
|
||||
Time: %s
|
||||
|
||||
Please verify state and execute lifecycle action.
|
||||
`, role, action, time.Now().Format(time.RFC3339))
|
||||
`, role, action, rigName, polecatName, time.Now().Format(time.RFC3339))
|
||||
|
||||
// Send via bd mail (syntax: bd mail send <recipient> -s <subject> -m <body>)
|
||||
cmd := exec.Command("bd", "mail", "send", manager,
|
||||
"-s", subject,
|
||||
"-m", body,
|
||||
"--type", "task", // Mark as task requiring action
|
||||
)
|
||||
cmd.Dir = townRoot
|
||||
|
||||
@@ -309,6 +354,45 @@ Please verify state and execute lifecycle action.
|
||||
return nil
|
||||
}
|
||||
|
||||
// detectPolecatName detects the polecat name from environment or directory context.
|
||||
func detectPolecatName() string {
|
||||
// Check environment variable first
|
||||
if polecat := os.Getenv("GT_POLECAT"); polecat != "" {
|
||||
return polecat
|
||||
}
|
||||
|
||||
// Try to detect from tmux session name (format: gt-<rig>-<polecat>)
|
||||
out, err := exec.Command("tmux", "display-message", "-p", "#{session_name}").Output()
|
||||
if err == nil {
|
||||
sessionName := strings.TrimSpace(string(out))
|
||||
if strings.HasPrefix(sessionName, "gt-") {
|
||||
parts := strings.SplitN(sessionName, "-", 3)
|
||||
if len(parts) >= 3 {
|
||||
return parts[2]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Try to detect from working directory
|
||||
cwd, err := os.Getwd()
|
||||
if err != nil {
|
||||
return ""
|
||||
}
|
||||
|
||||
// Look for "polecats" in path: .../rig/polecats/polecat/...
|
||||
if idx := strings.Index(cwd, "/polecats/"); idx != -1 {
|
||||
// Extract polecat name from path after /polecats/
|
||||
remainder := cwd[idx+len("/polecats/"):]
|
||||
// Take first component
|
||||
if slashIdx := strings.Index(remainder, "/"); slashIdx != -1 {
|
||||
return remainder[:slashIdx]
|
||||
}
|
||||
return remainder
|
||||
}
|
||||
|
||||
return ""
|
||||
}
|
||||
|
||||
// setRequestingState updates state.json to indicate we're requesting lifecycle action.
|
||||
func setRequestingState(role Role, action HandoffAction, townRoot string) error {
|
||||
// Determine state file location based on role
|
||||
|
||||
Reference in New Issue
Block a user