debug: add visual debug panel and comprehensive logging

- Added debug panel in terminal view that shows all terminal activity
- Added debugLog() method to TerminalManager for consistent logging
- Updated connectTerminal, handleTerminalMessage, launchCommand, createTerminal, initializeXTerm with detailed logging
- Enhanced backend logging for WebSocket messages and close codes
- Logs now show both to console and visual debug panel

This should help diagnose the terminal command execution issue without
requiring browser console access.
This commit is contained in:
uroma
2026-01-19 19:12:18 +00:00
Unverified
parent 2c7037b9b7
commit a7d2f37219
6 changed files with 128 additions and 32 deletions

View File

@@ -100,6 +100,7 @@ class TerminalService {
const terminal = this.terminals.get(terminalId);
if (!terminal) {
console.error(`[TerminalService] TERMINAL NOT FOUND: ${terminalId}`);
ws.close(1008, 'Terminal not found');
return;
}
@@ -108,14 +109,18 @@ class TerminalService {
terminal.lastActivity = new Date().toISOString();
console.log(`[TerminalService] WebSocket connected for terminal ${terminalId}`);
console.log(`[TerminalService] Terminal info - workingDir: ${terminal.workingDir}, mode: ${terminal.mode}`);
// Handle incoming messages from client (user input)
ws.on('message', (data) => {
console.log(`[TerminalService] Message received from ${terminalId}: ${data.toString()}`);
try {
const message = JSON.parse(data);
console.log(`[TerminalService] Parsed message type: ${message.type}`);
if (message.type === 'input') {
// User typed something - send to PTY
console.log(`[TerminalService] Writing to PTY: "${message.data.replace(/\n/g, '\\n')}"`);
terminal.pty.write(message.data);
terminal.lastActivity = new Date().toISOString();
@@ -125,6 +130,7 @@ class TerminalService {
}
} else if (message.type === 'resize') {
// Handle terminal resize
console.log(`[TerminalService] Resize to ${message.cols}x${message.rows}`);
terminal.pty.resize(message.cols, message.rows);
}
} catch (error) {
@@ -160,8 +166,8 @@ class TerminalService {
});
// Handle WebSocket close
ws.on('close', () => {
console.log(`[TerminalService] WebSocket closed for terminal ${terminalId}`);
ws.on('close', (code, reason) => {
console.log(`[TerminalService] WebSocket closed for terminal ${terminalId} - code: ${code}, reason: ${reason || 'none'}`);
// Don't kill PTY immediately - allow reconnection
// PTY will be killed after timeout or explicit close
@@ -173,12 +179,15 @@ class TerminalService {
});
// Send initial welcome message
ws.send(JSON.stringify({
const readyMessage = JSON.stringify({
type: 'ready',
terminalId,
workingDir: terminal.workingDir,
mode: terminal.mode
}));
});
console.log(`[TerminalService] Sending ready message to ${terminalId}: ${readyMessage}`);
ws.send(readyMessage);
console.log(`[TerminalService] Ready message sent successfully`);
}
/**