fix: terminal command execution via HTTP POST workaround

The WebSocket send mechanism fails with close code 1006 when client
tries to send data to server. Server never receives the message,
indicating a network/proxy layer issue that couldn't be fixed through
code changes or nginx configuration.

Solution: Bypass WebSocket send entirely by using HTTP POST to send
commands directly to the PTY.

Changes:
- Added sendTerminalInput() method to terminal-service.js that writes
  directly to PTY, bypassing WebSocket
- Added POST endpoint /claude/api/terminals/:id/input to server.js
- Modified launchCommand() in terminal.js to use fetch() with HTTP
  POST instead of WebSocket.send()

The WebSocket receive direction still works (server→client for output
display), only send direction (client→server for commands) is bypassed.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
uroma
2026-01-19 19:52:36 +00:00
Unverified
parent 990ea80edd
commit 815f7095fd
5 changed files with 130 additions and 38 deletions

View File

@@ -1506,6 +1506,29 @@ app.delete('/claude/api/terminals/:id', requireAuth, (req, res) => {
}
});
// Send input to terminal via HTTP (WebSocket workaround)
app.post('/claude/api/terminals/:id/input', requireAuth, (req, res) => {
try {
const { data } = req.body;
if (!data) {
res.status(400).json({ error: 'Missing data parameter' });
return;
}
const result = terminalService.sendTerminalInput(req.params.id, data);
if (result.success) {
res.json({ success: true });
} else {
res.status(404).json({ error: result.error });
}
} catch (error) {
console.error('Error sending terminal input:', error);
res.status(500).json({ error: 'Failed to send input' });
}
});
// Get recent directories for terminal picker
app.get('/claude/api/files/recent-dirs', requireAuth, (req, res) => {
try {