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:
@@ -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}`);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user