fix(respawn): use screen -X stuff for reliable input delivery

When writing to an attached PTY connected to screen, the input doesn't
reliably reach Claude CLI. This fix uses `screen -X stuff` command to
send input directly to the screen session, bypassing the PTY attachment.

Research findings:
- Claude CLI uses Ink (React for CLI) for terminal UI
- Ink's parseKeypress detects \r as key.return (Enter)
- screen -X stuff with $'...' syntax reliably sends literal characters

Changes:
- Add ScreenManager.sendInput() using screen -X stuff
- Modify Session.write() to prefer screen -X stuff when available
- Keep \r as Enter key (what Ink expects for key.return)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
arkon
2026-01-19 15:33:04 +01:00
co-authored by Claude Opus 4.5
parent 39c4a15ff3
commit a0fc82222f
3 changed files with 37 additions and 4 deletions
+22
View File
@@ -457,4 +457,26 @@ export class ScreenManager extends EventEmitter {
return false;
}
}
// Send input directly to screen session using screen -X stuff
// This bypasses the attached PTY and sends input directly to the screen
sendInput(sessionId: string, input: string): boolean {
const screen = this.screens.get(sessionId);
if (!screen) {
return false;
}
try {
// Use screen -X stuff with $'...' syntax to send literal characters
// \r (carriage return) is what Claude CLI expects for Enter
execSync(`screen -S ${screen.screenName} -X stuff $'${input.replace(/'/g, "'\\''")}'`, {
encoding: 'utf-8',
timeout: 5000
});
return true;
} catch (err) {
console.error('[ScreenManager] Failed to send input:', err);
return false;
}
}
}