feat(refinery): Convert Refinery from Go polling to Claude agent
The Refinery now runs as a Claude agent in a tmux session instead of a Go-based polling loop. This aligns it with how polecats work and enables intelligent MR processing. Changes: - Modified refinery.Start() to spawn Claude session (not gt refinery --foreground) - Added gt refinery attach command for interactive access to refinery session - Updated refinery.md.tmpl with comprehensive Claude agent instructions - Added startup directive in gt prime for refinery role The --foreground mode is preserved for backwards compatibility but the default behavior now launches a Claude agent that can review diffs, run tests, handle conflicts, and notify workers via mail. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -409,6 +409,15 @@ func outputStartupDirective(ctx RoleContext) {
|
||||
fmt.Println("1. Check mail: `gt mail inbox`")
|
||||
fmt.Println("2. If assigned work, begin immediately")
|
||||
fmt.Println("3. If no work, announce ready and await assignment")
|
||||
case RoleRefinery:
|
||||
fmt.Println()
|
||||
fmt.Println("---")
|
||||
fmt.Println()
|
||||
fmt.Println("**STARTUP PROTOCOL**: You are the Refinery. Please:")
|
||||
fmt.Println("1. Check mail: `gt mail inbox`")
|
||||
fmt.Printf("2. Check merge queue: `gt refinery queue %s`\n", ctx.Rig)
|
||||
fmt.Println("3. If MRs pending, process them one at a time")
|
||||
fmt.Println("4. If no work, monitor for new MRs periodically")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@ import (
|
||||
"github.com/steveyegge/gastown/internal/refinery"
|
||||
"github.com/steveyegge/gastown/internal/rig"
|
||||
"github.com/steveyegge/gastown/internal/style"
|
||||
"github.com/steveyegge/gastown/internal/tmux"
|
||||
"github.com/steveyegge/gastown/internal/workspace"
|
||||
)
|
||||
|
||||
@@ -77,6 +78,20 @@ Lists all pending merge requests waiting to be processed.`,
|
||||
RunE: runRefineryQueue,
|
||||
}
|
||||
|
||||
var refineryAttachCmd = &cobra.Command{
|
||||
Use: "attach <rig>",
|
||||
Short: "Attach to refinery session",
|
||||
Long: `Attach to a running Refinery's Claude session.
|
||||
|
||||
Allows interactive access to the Refinery agent for debugging
|
||||
or manual intervention.
|
||||
|
||||
Examples:
|
||||
gt refinery attach gastown`,
|
||||
Args: cobra.ExactArgs(1),
|
||||
RunE: runRefineryAttach,
|
||||
}
|
||||
|
||||
func init() {
|
||||
// Start flags
|
||||
refineryStartCmd.Flags().BoolVar(&refineryForeground, "foreground", false, "Run in foreground (default: background)")
|
||||
@@ -92,6 +107,7 @@ func init() {
|
||||
refineryCmd.AddCommand(refineryStopCmd)
|
||||
refineryCmd.AddCommand(refineryStatusCmd)
|
||||
refineryCmd.AddCommand(refineryQueueCmd)
|
||||
refineryCmd.AddCommand(refineryAttachCmd)
|
||||
|
||||
rootCmd.AddCommand(refineryCmd)
|
||||
}
|
||||
@@ -315,3 +331,41 @@ func runRefineryQueue(cmd *cobra.Command, args []string) error {
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func runRefineryAttach(cmd *cobra.Command, args []string) error {
|
||||
rigName := args[0]
|
||||
|
||||
townRoot, err := workspace.FindFromCwdOrError()
|
||||
if err != nil {
|
||||
return fmt.Errorf("not in a Gas Town workspace: %w", err)
|
||||
}
|
||||
|
||||
// Session name follows the same pattern as refinery manager
|
||||
sessionID := fmt.Sprintf("gt-%s-refinery", rigName)
|
||||
|
||||
// Check if session exists
|
||||
t := tmux.NewTmux()
|
||||
running, err := t.HasSession(sessionID)
|
||||
if err != nil {
|
||||
return fmt.Errorf("checking session: %w", err)
|
||||
}
|
||||
if !running {
|
||||
return fmt.Errorf("refinery is not running for rig '%s'", rigName)
|
||||
}
|
||||
|
||||
// Verify rig exists
|
||||
rigsConfigPath := filepath.Join(townRoot, "mayor", "rigs.json")
|
||||
rigsConfig, err := config.LoadRigsConfig(rigsConfigPath)
|
||||
if err != nil {
|
||||
rigsConfig = &config.RigsConfig{Rigs: make(map[string]config.RigEntry)}
|
||||
}
|
||||
|
||||
g := git.NewGit(townRoot)
|
||||
rigMgr := rig.NewManager(townRoot, rigsConfig, g)
|
||||
if _, err := rigMgr.GetRig(rigName); err != nil {
|
||||
return fmt.Errorf("rig '%s' not found", rigName)
|
||||
}
|
||||
|
||||
// Attach to the session
|
||||
return t.AttachSession(sessionID)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user