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
+11
View File
@@ -898,7 +898,18 @@ export class Session extends EventEmitter {
}
// Send input to the PTY (for interactive sessions)
// When using screen, prefers screen -X stuff for reliable input delivery
write(data: string): void {
// Try screen -X stuff first if we have a screen session
// This is more reliable for sending Enter key to Claude CLI
if (this._screenManager && this._screenSession) {
const success = this._screenManager.sendInput(this.id, data);
if (success) {
return;
}
// Fall through to PTY write if screen command failed
}
if (this.ptyProcess) {
this.ptyProcess.write(data);
}