From 2c7037b9b72c81feadd4dcdc212ce6abafed35fe Mon Sep 17 00:00:00 2001 From: uroma Date: Mon, 19 Jan 2026 19:03:27 +0000 Subject: [PATCH] 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 --- public/claude-ide/terminal.js | 29 ++++++++++++++++++++++------- services/terminal-service.js | 6 ------ 2 files changed, 22 insertions(+), 13 deletions(-) diff --git a/public/claude-ide/terminal.js b/public/claude-ide/terminal.js index 77fd1c88..3a4ff5e0 100644 --- a/public/claude-ide/terminal.js +++ b/public/claude-ide/terminal.js @@ -631,28 +631,35 @@ class TerminalManager { * Waits for terminal to be ready before sending command */ async launchCommand(terminalId, command) { + console.log(`[TerminalManager] launchCommand: terminalId=${terminalId}, command="${command.trim()}"`); + // 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); 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'); return; } + console.log(`[TerminalManager] Terminal ${terminalId} is ready! Sending command.`); + const terminal = this.terminals.get(terminalId); 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; } // Send command to terminal - terminal.ws.send(JSON.stringify({ + const message = JSON.stringify({ type: 'input', 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 */ handleTerminalMessage(terminalId, message) { + console.log(`[TerminalManager] Received message from backend: type="${message.type}", terminalId="${terminalId}"`, message); + 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) { case 'ready': - console.log(`[TerminalManager] Terminal ${terminalId} ready`); + console.log(`[TerminalManager] ✅ Ready message received for ${terminalId}, PTY is initialized`); break; case 'data': @@ -894,6 +906,9 @@ class TerminalManager { // Update mode display this.updateModeDisplay(terminalId, message.mode); break; + + default: + console.log(`[TerminalManager] Unknown message type: ${message.type}`); } } diff --git a/services/terminal-service.js b/services/terminal-service.js index dfd92ed6..014f7efb 100644 --- a/services/terminal-service.js +++ b/services/terminal-service.js @@ -109,12 +109,6 @@ class TerminalService { 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) ws.on('message', (data) => { try {