feat: add restart subcommands to witness and refinery (gt-9kc2)
- Add `gt witness restart <rig>` command (stop + start) - Add `gt refinery restart [rig]` command (stop + start) - Add self-cycling documentation to refinery template - Clarify that restarts are daemon-managed, not shell loops 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -98,6 +98,21 @@ Examples:
|
||||
RunE: runRefineryAttach,
|
||||
}
|
||||
|
||||
var refineryRestartCmd = &cobra.Command{
|
||||
Use: "restart [rig]",
|
||||
Short: "Restart the refinery",
|
||||
Long: `Restart the Refinery for a rig.
|
||||
|
||||
Stops the current session (if running) and starts a fresh one.
|
||||
If rig is not specified, infers it from the current directory.
|
||||
|
||||
Examples:
|
||||
gt refinery restart gastown
|
||||
gt refinery restart # infer rig from cwd`,
|
||||
Args: cobra.MaximumNArgs(1),
|
||||
RunE: runRefineryRestart,
|
||||
}
|
||||
|
||||
func init() {
|
||||
// Start flags
|
||||
refineryStartCmd.Flags().BoolVar(&refineryForeground, "foreground", false, "Run in foreground (default: background)")
|
||||
@@ -111,6 +126,7 @@ func init() {
|
||||
// Add subcommands
|
||||
refineryCmd.AddCommand(refineryStartCmd)
|
||||
refineryCmd.AddCommand(refineryStopCmd)
|
||||
refineryCmd.AddCommand(refineryRestartCmd)
|
||||
refineryCmd.AddCommand(refineryStatusCmd)
|
||||
refineryCmd.AddCommand(refineryQueueCmd)
|
||||
refineryCmd.AddCommand(refineryAttachCmd)
|
||||
@@ -383,3 +399,31 @@ func runRefineryAttach(cmd *cobra.Command, args []string) error {
|
||||
// Attach to session using exec to properly forward TTY
|
||||
return attachToTmuxSession(sessionID)
|
||||
}
|
||||
|
||||
func runRefineryRestart(cmd *cobra.Command, args []string) error {
|
||||
rigName := ""
|
||||
if len(args) > 0 {
|
||||
rigName = args[0]
|
||||
}
|
||||
|
||||
mgr, _, rigName, err := getRefineryManager(rigName)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
fmt.Printf("Restarting refinery for %s...\n", rigName)
|
||||
|
||||
// Stop if running (ignore ErrNotRunning)
|
||||
if err := mgr.Stop(); err != nil && err != refinery.ErrNotRunning {
|
||||
return fmt.Errorf("stopping refinery: %w", err)
|
||||
}
|
||||
|
||||
// Start fresh
|
||||
if err := mgr.Start(false); err != nil {
|
||||
return fmt.Errorf("starting refinery: %w", err)
|
||||
}
|
||||
|
||||
fmt.Printf("%s Refinery restarted for %s\n", style.Bold.Render("✓"), rigName)
|
||||
fmt.Printf(" %s\n", style.Dim.Render("Use 'gt refinery attach' to connect"))
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -78,6 +78,19 @@ If the witness is not running, this will start it first.`,
|
||||
RunE: runWitnessAttach,
|
||||
}
|
||||
|
||||
var witnessRestartCmd = &cobra.Command{
|
||||
Use: "restart <rig>",
|
||||
Short: "Restart the witness",
|
||||
Long: `Restart the Witness for a rig.
|
||||
|
||||
Stops the current session (if running) and starts a fresh one.
|
||||
|
||||
Examples:
|
||||
gt witness restart gastown`,
|
||||
Args: cobra.ExactArgs(1),
|
||||
RunE: runWitnessRestart,
|
||||
}
|
||||
|
||||
func init() {
|
||||
// Start flags
|
||||
witnessStartCmd.Flags().BoolVar(&witnessForeground, "foreground", false, "Run in foreground (default: background)")
|
||||
@@ -88,6 +101,7 @@ func init() {
|
||||
// Add subcommands
|
||||
witnessCmd.AddCommand(witnessStartCmd)
|
||||
witnessCmd.AddCommand(witnessStopCmd)
|
||||
witnessCmd.AddCommand(witnessRestartCmd)
|
||||
witnessCmd.AddCommand(witnessStatusCmd)
|
||||
witnessCmd.AddCommand(witnessAttachCmd)
|
||||
|
||||
@@ -341,3 +355,41 @@ func runWitnessAttach(cmd *cobra.Command, args []string) error {
|
||||
attachCmd.Stderr = os.Stderr
|
||||
return attachCmd.Run()
|
||||
}
|
||||
|
||||
func runWitnessRestart(cmd *cobra.Command, args []string) error {
|
||||
rigName := args[0]
|
||||
|
||||
mgr, r, err := getWitnessManager(rigName)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
fmt.Printf("Restarting witness for %s...\n", rigName)
|
||||
|
||||
// Kill tmux session if it exists
|
||||
t := tmux.NewTmux()
|
||||
sessionName := witnessSessionName(rigName)
|
||||
running, _ := t.HasSession(sessionName)
|
||||
if running {
|
||||
if err := t.KillSession(sessionName); err != nil {
|
||||
fmt.Printf("%s Warning: failed to kill session: %v\n", style.Dim.Render("⚠"), err)
|
||||
}
|
||||
}
|
||||
|
||||
// Update state file to stopped
|
||||
_ = mgr.Stop()
|
||||
|
||||
// Start fresh
|
||||
created, err := ensureWitnessSession(rigName, r)
|
||||
if err != nil {
|
||||
return fmt.Errorf("starting witness: %w", err)
|
||||
}
|
||||
|
||||
if created {
|
||||
_ = mgr.Start(false) // Mark as running in state file
|
||||
}
|
||||
|
||||
fmt.Printf("%s Witness restarted for %s\n", style.Bold.Render("✓"), rigName)
|
||||
fmt.Printf(" %s\n", style.Dim.Render("Use 'gt witness attach' to connect"))
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -225,6 +225,8 @@ func (m *Manager) Start(foreground bool) error {
|
||||
}
|
||||
|
||||
// Start Claude agent with full permissions (like polecats)
|
||||
// NOTE: No gt prime injection needed - SessionStart hook handles it automatically
|
||||
// Restarts are handled by daemon via LIFECYCLE mail, not shell loops
|
||||
command := "claude --dangerously-skip-permissions"
|
||||
if err := t.SendKeys(sessionID, command); err != nil {
|
||||
// Clean up the session on failure
|
||||
@@ -232,13 +234,6 @@ func (m *Manager) Start(foreground bool) error {
|
||||
return fmt.Errorf("starting Claude agent: %w", err)
|
||||
}
|
||||
|
||||
// Wait for Claude to start (pane command changes from shell to node)
|
||||
// NOTE: No gt prime injection needed - SessionStart hook handles it automatically
|
||||
shells := []string{"bash", "zsh", "sh", "fish", "tcsh", "ksh"}
|
||||
if err := t.WaitForCommand(sessionID, shells, 15*time.Second); err != nil {
|
||||
fmt.Fprintf(m.output, "Warning: Timeout waiting for Claude to start: %v\n", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@@ -134,6 +134,37 @@ RIGHT (sequential rebase):
|
||||
|
||||
After every merge, main moves. Next branch MUST rebase on new baseline.
|
||||
|
||||
## Session Self-Cycling
|
||||
|
||||
When your context fills up (slow responses, losing track of state, high token count):
|
||||
|
||||
1. **Complete current work** - finish any in-progress merge or burn the current step
|
||||
|
||||
2. **Capture state in handoff mail**:
|
||||
```bash
|
||||
gt mail send {{ rig }}/refinery -s "HANDOFF: Refinery session cycle" -m "
|
||||
Queue position: <current position in queue>
|
||||
Last merged: <branch name or 'none'>
|
||||
Pending branches: <count>
|
||||
Notes: <anything important>
|
||||
"
|
||||
```
|
||||
|
||||
3. **Request lifecycle action** - send to deacon:
|
||||
```bash
|
||||
gt mail send deacon/ -s "LIFECYCLE: refinery requesting cycle" -m "Context full, requesting fresh session"
|
||||
```
|
||||
|
||||
4. **Set state flag** (if state.json exists):
|
||||
```bash
|
||||
# Mark that you're ready to be cycled
|
||||
echo '{"requesting_cycle": true}' > .runtime/refinery-state.json
|
||||
```
|
||||
|
||||
5. **Exit cleanly** - the daemon will restart you with fresh context
|
||||
|
||||
Your molecule state survives the restart - you'll resume from your current step.
|
||||
|
||||
## Nondeterministic Idempotence
|
||||
|
||||
The Refinery uses molecule-based handoff:
|
||||
|
||||
Reference in New Issue
Block a user