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:
Steve Yegge
2025-12-19 01:48:59 -08:00
parent 717bc89132
commit 231d6e92e0
7 changed files with 393 additions and 133 deletions

View File

@@ -40,11 +40,11 @@ var polecatListCmd = &cobra.Command{
Short: "List polecats in a rig",
Long: `List polecats in a rig or all rigs.
Output:
- Name
- State (idle/active/working/done/stuck)
- Current issue (if any)
- Session status (running/stopped)
In the ephemeral model, polecats exist only while working. The list shows
all currently active polecats with their states:
- working: Actively working on an issue
- done: Completed work, waiting for cleanup
- stuck: Needs assistance
Examples:
gt polecat list gastown
@@ -85,10 +85,13 @@ Example:
var polecatWakeCmd = &cobra.Command{
Use: "wake <rig>/<polecat>",
Short: "Mark polecat as active (ready for work)",
Long: `Mark polecat as active (ready for work).
Short: "(Deprecated) Resume a polecat to working state",
Long: `Resume a polecat to working state.
Transitions: idle → active
DEPRECATED: In the ephemeral model, polecats are created fresh for each task
via 'gt spawn'. This command is kept for backward compatibility.
Transitions: done → working
Example:
gt polecat wake gastown/Toast`,
@@ -98,11 +101,14 @@ Example:
var polecatSleepCmd = &cobra.Command{
Use: "sleep <rig>/<polecat>",
Short: "Mark polecat as idle (not available)",
Long: `Mark polecat as idle (not available).
Short: "(Deprecated) Mark polecat as done",
Long: `Mark polecat as done.
Transitions: active → idle
Fails if session is running (stop first).
DEPRECATED: In the ephemeral model, polecats use 'gt handoff' when complete,
which triggers automatic cleanup by the Witness. This command is kept for
backward compatibility.
Transitions: working → done
Example:
gt polecat sleep gastown/Toast`,
@@ -224,11 +230,11 @@ func runPolecatList(cmd *cobra.Command, args []string) error {
}
if len(allPolecats) == 0 {
fmt.Println("No polecats found.")
fmt.Println("No active polecats found.")
return nil
}
fmt.Printf("%s\n\n", style.Bold.Render("Polecats"))
fmt.Printf("%s\n\n", style.Bold.Render("Active Polecats"))
for _, p := range allPolecats {
// Session indicator
sessionStatus := style.Dim.Render("○")
@@ -236,9 +242,15 @@ func runPolecatList(cmd *cobra.Command, args []string) error {
sessionStatus = style.Success.Render("●")
}
// Normalize state for display (legacy idle/active → working)
displayState := p.State
if p.State == polecat.StateIdle || p.State == polecat.StateActive {
displayState = polecat.StateWorking
}
// State color
stateStr := string(p.State)
switch p.State {
stateStr := string(displayState)
switch displayState {
case polecat.StateWorking:
stateStr = style.Info.Render(stateStr)
case polecat.StateStuck:
@@ -316,6 +328,9 @@ func runPolecatRemove(cmd *cobra.Command, args []string) error {
}
func runPolecatWake(cmd *cobra.Command, args []string) error {
fmt.Println(style.Warning.Render("DEPRECATED: Use 'gt spawn' to create fresh polecats instead"))
fmt.Println()
rigName, polecatName, err := parseAddress(args[0])
if err != nil {
return err
@@ -330,11 +345,14 @@ func runPolecatWake(cmd *cobra.Command, args []string) error {
return fmt.Errorf("waking polecat: %w", err)
}
fmt.Printf("%s Polecat %s is now active.\n", style.SuccessPrefix, polecatName)
fmt.Printf("%s Polecat %s is now working.\n", style.SuccessPrefix, polecatName)
return nil
}
func runPolecatSleep(cmd *cobra.Command, args []string) error {
fmt.Println(style.Warning.Render("DEPRECATED: Use 'gt handoff' from within a polecat session instead"))
fmt.Println()
rigName, polecatName, err := parseAddress(args[0])
if err != nil {
return err
@@ -350,13 +368,13 @@ func runPolecatSleep(cmd *cobra.Command, args []string) error {
sessMgr := session.NewManager(t, r)
running, _ := sessMgr.IsRunning(polecatName)
if running {
return fmt.Errorf("session is running. Stop it first with: gt session stop %s/%s", rigName, polecatName)
return fmt.Errorf("session is running. Use 'gt handoff' from the polecat session, or stop it with: gt session stop %s/%s", rigName, polecatName)
}
if err := mgr.Sleep(polecatName); err != nil {
return fmt.Errorf("sleeping polecat: %w", err)
return fmt.Errorf("marking polecat as done: %w", err)
}
fmt.Printf("%s Polecat %s is now idle.\n", style.SuccessPrefix, polecatName)
fmt.Printf("%s Polecat %s is now done.\n", style.SuccessPrefix, polecatName)
return nil
}