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 {