debug: add comprehensive logging for terminal command flow

Phase 1 of systematic debugging: Gather evidence

Added detailed logging to trace the complete command flow:
- launchCommand: Shows when called, terminalId, command, WebSocket state
- waitForTerminalReady: Shows waiting period and ready state
- handleTerminalMessage: Shows all messages from backend with details
- WebSocket message content logged before sending

Also fixed duplicate 'ready' message (removed line 113-116).

Now when user creates "Claude Code CLI" terminal, console will show:
1. launchCommand called with terminalId and command
2. Waiting for terminal ready
3. Ready message received (or timeout)
4. Command sent to WebSocket
5. All backend messages logged

This will reveal exactly where the flow breaks.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
uroma
2026-01-19 19:03:27 +00:00
Unverified
parent d834a64d62
commit 2c7037b9b7
2 changed files with 22 additions and 13 deletions

View File

@@ -631,28 +631,35 @@ class TerminalManager {
* Waits for terminal to be ready before sending command * Waits for terminal to be ready before sending command
*/ */
async launchCommand(terminalId, command) { async launchCommand(terminalId, command) {
console.log(`[TerminalManager] launchCommand: terminalId=${terminalId}, command="${command.trim()}"`);
// Wait for terminal to be ready (max 5 seconds) // Wait for terminal to be ready (max 5 seconds)
console.log(`[TerminalManager] Waiting for terminal ${terminalId} to be ready...`);
const ready = await this.waitForTerminalReady(terminalId, 5000); const ready = await this.waitForTerminalReady(terminalId, 5000);
if (!ready) { if (!ready) {
console.error('[TerminalManager] Terminal not ready for command launch (timeout)'); console.error(`[TerminalManager] Terminal ${terminalId} NOT ready (timeout after 5s)`);
showToast('Terminal not ready. Please try again.', 'error'); showToast('Terminal not ready. Please try again.', 'error');
return; return;
} }
console.log(`[TerminalManager] Terminal ${terminalId} is ready! Sending command.`);
const terminal = this.terminals.get(terminalId); const terminal = this.terminals.get(terminalId);
if (!terminal || !terminal.ws || terminal.ws.readyState !== WebSocket.OPEN) { if (!terminal || !terminal.ws || terminal.ws.readyState !== WebSocket.OPEN) {
console.error('[TerminalManager] Terminal not ready for command launch (WebSocket not connected)'); console.error(`[TerminalManager] Cannot send - WebSocket not ready. terminal=${!!terminal}, ws=${!!terminal?.ws}, state=${terminal?.ws?.readyState}`);
return; return;
} }
// Send command to terminal // Send command to terminal
terminal.ws.send(JSON.stringify({ const message = JSON.stringify({
type: 'input', type: 'input',
data: command data: command
})); });
console.log(`[TerminalManager] Sending to WebSocket: ${message}`);
terminal.ws.send(message);
console.log(`[TerminalManager] Launched command in terminal ${terminalId}: ${command.trim()}`); console.log(`[TerminalManager] Command sent to terminal ${terminalId}: ${command.trim()}`);
} }
/** /**
@@ -869,13 +876,18 @@ class TerminalManager {
* Handle terminal message from WebSocket * Handle terminal message from WebSocket
*/ */
handleTerminalMessage(terminalId, message) { handleTerminalMessage(terminalId, message) {
console.log(`[TerminalManager] Received message from backend: type="${message.type}", terminalId="${terminalId}"`, message);
const terminal = this.terminals.get(terminalId); const terminal = this.terminals.get(terminalId);
if (!terminal) return; if (!terminal) {
console.error(`[TerminalManager] Cannot handle message - terminal ${terminalId} not found in map`);
return;
}
switch (message.type) { switch (message.type) {
case 'ready': case 'ready':
console.log(`[TerminalManager] Terminal ${terminalId} ready`); console.log(`[TerminalManager] ✅ Ready message received for ${terminalId}, PTY is initialized`);
break; break;
case 'data': case 'data':
@@ -894,6 +906,9 @@ class TerminalManager {
// Update mode display // Update mode display
this.updateModeDisplay(terminalId, message.mode); this.updateModeDisplay(terminalId, message.mode);
break; break;
default:
console.log(`[TerminalManager] Unknown message type: ${message.type}`);
} }
} }

View File

@@ -109,12 +109,6 @@ class TerminalService {
console.log(`[TerminalService] WebSocket connected for terminal ${terminalId}`); console.log(`[TerminalService] WebSocket connected for terminal ${terminalId}`);
// Send ready message to client to indicate PTY is ready for input
ws.send(JSON.stringify({
type: 'ready',
terminalId: terminalId
}));
// Handle incoming messages from client (user input) // Handle incoming messages from client (user input)
ws.on('message', (data) => { ws.on('message', (data) => {
try { try {