Merge fix/spawn-beads-path: add gt nudge command

Key changes:
- Add gt nudge command for reliable Claude session messaging
- spawn.go now uses NudgeSession instead of SendKeysDebounced
- Fix templates test to match actual deacon template text

🤖 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-20 13:30:30 -08:00
5 changed files with 469 additions and 395 deletions

52
internal/cmd/nudge.go Normal file
View File

@@ -0,0 +1,52 @@
package cmd
import (
"fmt"
"github.com/spf13/cobra"
"github.com/steveyegge/gastown/internal/tmux"
)
func init() {
rootCmd.AddCommand(nudgeCmd)
}
var nudgeCmd = &cobra.Command{
Use: "nudge <session> <message>",
Short: "Send a message to a Claude session reliably",
Long: `Sends a message to a tmux session running Claude Code.
Uses a reliable delivery pattern:
1. Sends text in literal mode (-l flag)
2. Waits 500ms for paste to complete
3. Sends Enter as a separate command
This is the ONLY way to send messages to Claude sessions.
Do not use raw tmux send-keys elsewhere.`,
Args: cobra.ExactArgs(2),
RunE: runNudge,
}
func runNudge(cmd *cobra.Command, args []string) error {
session := args[0]
message := args[1]
t := tmux.NewTmux()
// Verify session exists
exists, err := t.HasSession(session)
if err != nil {
return fmt.Errorf("checking session: %w", err)
}
if !exists {
return fmt.Errorf("session %q not found", session)
}
// Send message with reliable pattern
if err := t.NudgeSession(session, message); err != nil {
return fmt.Errorf("nudging session: %w", err)
}
fmt.Printf("✓ Nudged %s\n", session)
return nil
}

View File

@@ -338,11 +338,11 @@ func runSpawn(cmd *cobra.Command, args []string) error {
style.Bold.Render("✓"),
style.Dim.Render(fmt.Sprintf("gt session at %s/%s", rigName, polecatName)))
// Send direct nudge to start working - don't rely on hooks or witness coordination
// Send direct nudge to start working using reliable NudgeSession
// The polecat has a work assignment in its inbox; just tell it to check
sessionName := sessMgr.SessionName(polecatName)
nudgeMsg := fmt.Sprintf("You have a work assignment. Run 'gt mail inbox' to see it, then start working on issue %s.", assignmentID)
if err := t.SendKeysDebounced(sessionName, nudgeMsg, 500); err != nil {
if err := t.NudgeSession(sessionName, nudgeMsg); err != nil {
fmt.Printf(" %s\n", style.Dim.Render(fmt.Sprintf("Warning: could not nudge polecat: %v", err)))
} else {
fmt.Printf(" %s\n", style.Dim.Render("Polecat nudged to start working"))

View File

@@ -99,7 +99,7 @@ func TestRenderRole_Deacon(t *testing.T) {
if !strings.Contains(output, "/test/town") {
t.Error("output missing town root")
}
if !strings.Contains(output, "Health-Check Orchestrator") {
if !strings.Contains(output, "Health Orchestrator") {
t.Error("output missing role description")
}
if !strings.Contains(output, "Wake Cycle") {

View File

@@ -176,6 +176,27 @@ func (t *Tmux) SendKeysDelayedDebounced(session, keys string, preDelayMs, deboun
return t.SendKeysDebounced(session, keys, debounceMs)
}
// NudgeSession sends a message to a Claude Code session reliably.
// This is the canonical way to send messages to Claude sessions.
// Uses: literal mode + 500ms debounce + separate Enter.
// Verification is the Witness's job (AI), not this function.
func (t *Tmux) NudgeSession(session, message string) error {
// 1. Send text in literal mode (handles special characters)
if _, err := t.run("send-keys", "-t", session, "-l", message); err != nil {
return err
}
// 2. Wait 500ms for paste to complete (tested, required)
time.Sleep(500 * time.Millisecond)
// 3. Send Enter as separate command (key to reliability)
if _, err := t.run("send-keys", "-t", session, "Enter"); err != nil {
return err
}
return nil
}
// GetPaneCommand returns the current command running in a pane.
// Returns "bash", "zsh", "claude", "node", etc.
func (t *Tmux) GetPaneCommand(session string) (string, error) {