fix: Add retry logic for Enter key send in NudgeSession/NudgePane (#53)
When sending messages to Claude sessions via tmux, the Enter key send could fail silently. This caused polecats to receive their initial prompt but never submit it - the message appeared in Claude's input area but Enter was never pressed. Add retry logic (up to 3 attempts with 200ms delays) for the Enter send step in both NudgeSession() and NudgePane(). This ensures message submission is more reliable even if tmux has transient issues. Fixes #41
This commit is contained in:
committed by
GitHub
parent
eabb1c5aa6
commit
047585866a
@@ -274,12 +274,19 @@ func (t *Tmux) NudgeSession(session, message string) error {
|
|||||||
// 2. Wait 500ms for paste to complete (tested, required)
|
// 2. Wait 500ms for paste to complete (tested, required)
|
||||||
time.Sleep(500 * time.Millisecond)
|
time.Sleep(500 * time.Millisecond)
|
||||||
|
|
||||||
// 3. Send Enter as separate command (key to reliability)
|
// 3. Send Enter with retry (critical for message submission)
|
||||||
if _, err := t.run("send-keys", "-t", session, "Enter"); err != nil {
|
var lastErr error
|
||||||
return err
|
for attempt := 0; attempt < 3; attempt++ {
|
||||||
|
if attempt > 0 {
|
||||||
|
time.Sleep(200 * time.Millisecond)
|
||||||
|
}
|
||||||
|
if _, err := t.run("send-keys", "-t", session, "Enter"); err != nil {
|
||||||
|
lastErr = err
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
return fmt.Errorf("failed to send Enter after 3 attempts: %w", lastErr)
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// NudgePane sends a message to a specific pane reliably.
|
// NudgePane sends a message to a specific pane reliably.
|
||||||
@@ -293,12 +300,19 @@ func (t *Tmux) NudgePane(pane, message string) error {
|
|||||||
// 2. Wait 500ms for paste to complete (tested, required)
|
// 2. Wait 500ms for paste to complete (tested, required)
|
||||||
time.Sleep(500 * time.Millisecond)
|
time.Sleep(500 * time.Millisecond)
|
||||||
|
|
||||||
// 3. Send Enter as separate command (key to reliability)
|
// 3. Send Enter with retry (critical for message submission)
|
||||||
if _, err := t.run("send-keys", "-t", pane, "Enter"); err != nil {
|
var lastErr error
|
||||||
return err
|
for attempt := 0; attempt < 3; attempt++ {
|
||||||
|
if attempt > 0 {
|
||||||
|
time.Sleep(200 * time.Millisecond)
|
||||||
|
}
|
||||||
|
if _, err := t.run("send-keys", "-t", pane, "Enter"); err != nil {
|
||||||
|
lastErr = err
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
return fmt.Errorf("failed to send Enter after 3 attempts: %w", lastErr)
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// AcceptBypassPermissionsWarning dismisses the Claude Code bypass permissions warning dialog.
|
// AcceptBypassPermissionsWarning dismisses the Claude Code bypass permissions warning dialog.
|
||||||
|
|||||||
Reference in New Issue
Block a user