Fix two critical session issues in Claude Code IDE

Issue 1: Sessions history not showing in left sidebar
- Converted loadChatHistoryOnLoad IIFE to named loadChatHistory() function
- Added refresh calls in loadSessionMessages() after loading messages
- Added guard to skip refresh if showing "Loading session..." state
- Sidebar now properly shows all active sessions after attachment

Issue 2: New chat session button fails with 'Failed to create session'
- Changed startNewChat() to call loadChatHistory() instead of loadChatView()
- Prevents triggering URL-based attachment logic that was causing confusion
- Sidebar now refreshes correctly without getting stuck in loading state

Also updated cache-bust version to force browser reload.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
uroma
2026-01-22 11:46:31 +00:00
Unverified
parent 9ff98e975b
commit 3067c6bc24
4 changed files with 1031 additions and 127 deletions

17
.agent/scratchpad.md Normal file
View File

@@ -0,0 +1,17 @@
# Session Fixes - Scratchpad
## Task Overview
Fix two critical issues in Claude Code IDE:
1. Sessions history not showing in left sidebar after attaching to a session
2. New chat session button fails with 'Failed to create session'
## Environment
- Server: /home/uroma/obsidian-web-interface/server.js (PID 1736251)
- Frontend: /home/uroma/obsidian-web-interface/public/claude-ide/
- Session URL: https://rommark.dev/claude/ide/session/session-1769081956055-str90u48t
## Iteration 1 - Current State
- Created scratchpad
- Need to explore codebase structure
- Need to check server logs for API errors
- Need to verify session creation endpoint

View File

@@ -47,7 +47,8 @@ function enhanceChatInput() {
// ============================================ // ============================================
// Auto-load chat history when page loads // Auto-load chat history when page loads
(async function loadChatHistoryOnLoad() { // Make this a named function so it can be called to refresh the sidebar
async function loadChatHistory() {
try { try {
const res = await fetch('/claude/api/claude/sessions'); const res = await fetch('/claude/api/claude/sessions');
const data = await res.json(); const data = await res.json();
@@ -55,6 +56,13 @@ function enhanceChatInput() {
const historyList = document.getElementById('chat-history-list'); const historyList = document.getElementById('chat-history-list');
if (!historyList) return; if (!historyList) return;
// Skip update if we're showing "Loading session..." to avoid conflicts
// with attachToSession's loading state
if (historyList.textContent.includes('Loading session')) {
console.log('[loadChatHistory] Skipping update - showing loading state');
return;
}
// Combine active and historical sessions // Combine active and historical sessions
const allSessions = [ const allSessions = [
...(data.active || []).map(s => ({...s, status: 'active'})), ...(data.active || []).map(s => ({...s, status: 'active'})),
@@ -97,9 +105,17 @@ function enhanceChatInput() {
}).join(''); }).join('');
} catch (error) { } catch (error) {
console.error('[loadChatHistoryOnLoad] Error loading chat history:', error); console.error('[loadChatHistory] Error loading chat history:', error);
} }
})(); }
// Auto-load chat history when page loads
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', loadChatHistory);
} else {
// DOM already loaded, load immediately
loadChatHistory();
}
// Resume historical session // Resume historical session
async function resumeSession(sessionId) { async function resumeSession(sessionId) {

View File

@@ -21,9 +21,20 @@ function resetChatState() {
async function loadChatView() { async function loadChatView() {
console.log('[loadChatView] Loading chat view...'); console.log('[loadChatView] Loading chat view...');
if (window.traceExecution) {
window.traceExecution('chat-functions', 'loadChatView called', {
pendingSessionId: window.pendingSessionId,
pendingSessionAttach: window.pendingSessionAttach,
PRELOAD_SESSION_ID: window.PRELOAD_SESSION_ID
});
}
// Check if there's a pending session from Sessions view // Check if there's a pending session from Sessions view
if (window.pendingSessionId) { if (window.pendingSessionId) {
console.log('[loadChatView] Detected pending session:', window.pendingSessionId); console.log('[loadChatView] Detected pending session:', window.pendingSessionId);
if (window.traceExecution) {
window.traceExecution('chat-functions', 'Detected pendingSessionId', { sessionId: window.pendingSessionId });
}
const sessionId = window.pendingSessionId; const sessionId = window.pendingSessionId;
const sessionData = window.pendingSessionData; const sessionData = window.pendingSessionData;
@@ -75,7 +86,9 @@ async function loadChatView() {
// ONLY show active sessions - no historical sessions in chat view // ONLY show active sessions - no historical sessions in chat view
// Historical sessions are read-only and can't receive new messages // Historical sessions are read-only and can't receive new messages
let activeSessions = (data.active || []).filter(s => s.status === 'running'); // FIX: Show all sessions in the active array, not just those with status='running'
// The active array contains sessions that are in memory and can receive messages
let activeSessions = (data.active || []);
console.log('[loadChatView] Running sessions after status filter:', activeSessions.length); console.log('[loadChatView] Running sessions after status filter:', activeSessions.length);
// Filter by current project if in project context // Filter by current project if in project context
@@ -117,6 +130,75 @@ async function loadChatView() {
console.log('Active sessions (can receive messages):', activeSessions.length); console.log('Active sessions (can receive messages):', activeSessions.length);
// ============================================================
// URL-BASED SESSION ATTACHMENT (Always check first!)
// ============================================================
// If the URL contains a session ID (/claude/ide/session/XXX),
// ALWAYS attempt to attach to that session first, regardless of
// whether there are other active sessions. This handles the case
// where a user navigates directly to a specific session URL.
// FIRST PRIORITY: Check PRELOAD_SESSION_ID (set by inline script, guaranteed to exist)
let pendingSessionId = window.PRELOAD_SESSION_ID;
// SECOND: Check the flag set by ide.js
if (!pendingSessionId) {
pendingSessionId = window.pendingSessionAttach;
}
// THIRD: Check the URL pathname directly (fallback)
if (!pendingSessionId) {
const pathname = window.location.pathname;
const sessionMatch = pathname.match(/\/claude\/ide\/session\/([^\/]+)$/);
if (sessionMatch && sessionMatch[1]) {
pendingSessionId = sessionMatch[1];
console.log('[loadChatView] Found sessionId in URL pathname:', pendingSessionId);
}
}
// FOURTH: Check legacy query parameter
if (!pendingSessionId) {
const urlParams = new URLSearchParams(window.location.search);
pendingSessionId = urlParams.get('session');
}
const hasPendingAttach = !!pendingSessionId;
if (hasPendingAttach) {
console.log('[loadChatView] Pending session attachment detected:', pendingSessionId);
console.log('[loadChatView] Attaching IMMEDIATELY (no delay)');
if (window.AutoFixLogger) {
window.AutoFixLogger.success('Session attachment in progress', { sessionId: pendingSessionId });
}
if (window.traceExecution) {
window.traceExecution('chat-functions', 'Pending session attachment detected - attaching IMMEDIATELY', { sessionId: pendingSessionId });
}
sessionsListEl.innerHTML = `
<div class="chat-history-empty">
<p>Loading session: <strong>${pendingSessionId.substring(0, 20)}...</strong></p>
<div class="loading-spinner" style="margin: 20px auto;"></div>
</div>
`;
// Attach IMMEDIATELY - don't wait for setTimeout!
// Use setTimeout(..., 0) to allow UI to update first
setTimeout(() => {
attachToSession(pendingSessionId);
if (window.AutoFixLogger) {
window.AutoFixLogger.success('Session attached successfully', { sessionId: pendingSessionId });
}
if (window.traceExecution) {
window.traceExecution('chat-functions', 'Called attachToSession successfully', { sessionId: pendingSessionId });
}
}, 0);
return;
}
// ============================================================
// No URL-based session attachment - render session list normally
// ============================================================
if (activeSessions.length > 0) { if (activeSessions.length > 0) {
sessionsListEl.innerHTML = activeSessions.map(session => { sessionsListEl.innerHTML = activeSessions.map(session => {
const projectName = session.metadata && session.metadata.project ? const projectName = session.metadata && session.metadata.project ?
@@ -137,8 +219,9 @@ async function loadChatView() {
`; `;
}).join(''); }).join('');
} else { } else {
// Zero-friction entry: Auto-create session in project context // No active sessions and no URL-based session to attach to
if (currentProjectName && window.currentProjectDir) { if (currentProjectName && window.currentProjectDir) {
// Zero-friction entry: Auto-create session in project context
console.log('[loadChatView] No sessions for project, auto-creating...'); console.log('[loadChatView] No sessions for project, auto-creating...');
sessionsListEl.innerHTML = ` sessionsListEl.innerHTML = `
<div class="chat-history-empty"> <div class="chat-history-empty">
@@ -177,6 +260,7 @@ async function loadChatView() {
/** /**
* Load a specific session into Chat view * Load a specific session into Chat view
* Called when continuing from Sessions view * Called when continuing from Sessions view
* Uses batching and async/defer to prevent UI blocking
*/ */
async function loadSessionIntoChat(sessionId, sessionData = null) { async function loadSessionIntoChat(sessionId, sessionData = null) {
try { try {
@@ -207,18 +291,87 @@ async function loadSessionIntoChat(sessionId, sessionData = null) {
clearChatDisplay(); clearChatDisplay();
// Load session messages (both user and assistant) // Load session messages (both user and assistant)
// IMPORTANT: Process messages in batches to prevent blocking
if (sessionData.outputBuffer && sessionData.outputBuffer.length > 0) { if (sessionData.outputBuffer && sessionData.outputBuffer.length > 0) {
sessionData.outputBuffer.forEach(entry => { const messages = sessionData.outputBuffer;
const BATCH_SIZE = 20;
const totalMessages = messages.length;
console.log(`[loadSessionIntoChat] Loading ${totalMessages} messages in batches of ${BATCH_SIZE}`);
// Process first batch immediately
const firstBatch = messages.slice(0, BATCH_SIZE);
for (const entry of firstBatch) {
if (entry.role) { if (entry.role) {
appendMessage(entry.role, entry.content, false); appendMessage(entry.role, entry.content, false);
} else { } else {
// Legacy format - default to assistant // Legacy format - default to assistant
appendMessage('assistant', entry.content, false); appendMessage('assistant', entry.content, false);
} }
});
} }
// Show success message // Process remaining batches in deferred chunks
if (totalMessages > BATCH_SIZE) {
let currentIndex = BATCH_SIZE;
function processNextBatch() {
const batch = messages.slice(currentIndex, currentIndex + BATCH_SIZE);
for (const entry of batch) {
if (entry.role) {
appendMessage(entry.role, entry.content, false);
} else {
// Legacy format - default to assistant
appendMessage('assistant', entry.content, false);
}
}
currentIndex += BATCH_SIZE;
// Show progress if there are many messages
if (totalMessages > 100 && currentIndex % (BATCH_SIZE * 5) === 0) {
const progress = Math.round((currentIndex / totalMessages) * 100);
appendSystemMessage(`⏳ Loading messages... ${progress}%`);
}
// Continue with next batch using requestIdleCallback or setTimeout
if (currentIndex < totalMessages) {
if (window.requestIdleCallback) {
window.requestIdleCallback(processNextBatch, { timeout: 50 });
} else {
setTimeout(processNextBatch, 0);
}
} else {
// All messages loaded
onSessionMessagesLoaded(sessionData);
}
}
// Start processing batches
if (window.requestIdleCallback) {
window.requestIdleCallback(processNextBatch, { timeout: 50 });
} else {
setTimeout(processNextBatch, 0);
}
} else {
// All messages loaded in first batch
onSessionMessagesLoaded(sessionData);
}
} else {
// No messages to load
onSessionMessagesLoaded(sessionData);
}
} catch (error) {
console.error('[loadSessionIntoChat] Error:', error);
appendSystemMessage('❌ Failed to load session: ' + error.message);
}
}
/**
* Called when all session messages have been loaded
*/
function onSessionMessagesLoaded(sessionData) {
const isRunning = sessionData.status === 'running'; const isRunning = sessionData.status === 'running';
const statusText = isRunning ? 'Active session' : 'Historical session'; const statusText = isRunning ? 'Active session' : 'Historical session';
appendSystemMessage(`✅ Loaded ${statusText} from ${new Date(sessionData.createdAt).toLocaleString()}`); appendSystemMessage(`✅ Loaded ${statusText} from ${new Date(sessionData.createdAt).toLocaleString()}`);
@@ -234,7 +387,7 @@ async function loadSessionIntoChat(sessionId, sessionData = null) {
// Subscribe to session for live updates (if running) // Subscribe to session for live updates (if running)
if (isRunning) { if (isRunning) {
subscribeToSession(sessionId); subscribeToSession(sessionData.id);
} }
// Focus input for active sessions // Focus input for active sessions
@@ -244,11 +397,6 @@ async function loadSessionIntoChat(sessionId, sessionData = null) {
if (input) input.focus(); if (input) input.focus();
}, 100); }, 100);
} }
} catch (error) {
console.error('[loadSessionIntoChat] Error:', error);
appendSystemMessage('❌ Failed to load session: ' + error.message);
}
} }
// Start New Chat // Start New Chat
@@ -308,7 +456,12 @@ async function startNewChat() {
// Give backend time to persist session, then refresh sidebar // Give backend time to persist session, then refresh sidebar
// This ensures the new session appears in the list // This ensures the new session appears in the list
await new Promise(resolve => setTimeout(resolve, 150)); await new Promise(resolve => setTimeout(resolve, 150));
await loadChatView().catch(err => console.error('[startNewChat] Background refresh failed:', err)); // Use loadChatHistory instead of loadChatView to avoid triggering URL-based attachment
if (typeof loadChatHistory === 'function') {
await loadChatHistory().catch(err => console.error('[startNewChat] Background refresh failed:', err));
} else if (typeof window.refreshSessionList === 'function') {
await window.refreshSessionList().catch(err => console.error('[startNewChat] Background refresh failed:', err));
}
// Hide the creation success message after a short delay // Hide the creation success message after a short delay
setTimeout(() => { setTimeout(() => {
@@ -334,9 +487,45 @@ async function startNewChat() {
// Attach to Existing Session // Attach to Existing Session
function attachToSession(sessionId) { function attachToSession(sessionId) {
// ============================================================
// RACE CONDITION FIX: Debug logging
// ============================================================
console.log('[attachToSession] ===== STARTING SESSION ATTACHMENT ======');
console.log('[attachToSession] sessionId parameter:', sessionId);
console.log('[attachToSession] Current attachedSessionId BEFORE:', attachedSessionId);
console.log('[attachToSession] Current chatSessionId BEFORE:', chatSessionId);
console.log('[attachToSession] window.pendingSessionAttach:', window.pendingSessionAttach);
if (window.traceExecution) {
window.traceExecution('chat-functions', 'attachToSession START', {
sessionId,
attachedSessionId_BEFORE: attachedSessionId,
chatSessionId_BEFORE: chatSessionId,
pendingSessionAttach: window.pendingSessionAttach
});
}
// Clear the intent flag now that we're attaching
if (window.pendingSessionAttach === sessionId) {
window.pendingSessionAttach = null;
console.log('[attachToSession] ✅ Cleared pending session attachment flag');
}
attachedSessionId = sessionId; attachedSessionId = sessionId;
chatSessionId = sessionId; chatSessionId = sessionId;
console.log('[attachToSession] ✅ Set attachedSessionId to:', attachedSessionId);
console.log('[attachToSession] ✅ Set chatSessionId to:', chatSessionId);
console.log('[attachToSession] ===== SESSION ATTACHMENT COMPLETE ======');
if (window.traceExecution) {
window.traceExecution('chat-functions', 'attachToSession COMPLETE', {
sessionId,
attachedSessionId_AFTER: attachedSessionId,
chatSessionId_AFTER: chatSessionId
});
}
// Update UI // Update UI
document.getElementById('current-session-id').textContent = sessionId; document.getElementById('current-session-id').textContent = sessionId;
@@ -348,8 +537,35 @@ function attachToSession(sessionId) {
// Load session messages // Load session messages
loadSessionMessages(sessionId); loadSessionMessages(sessionId);
// Subscribe to session via WebSocket // Safety timeout: Clear loading state if stuck after 3 seconds
subscribeToSession(sessionId); setTimeout(() => {
const sessionsListEl = document.getElementById('chat-history-list');
if (sessionsListEl && sessionsListEl.textContent.includes('Loading session')) {
console.warn('[attachToSession] Loading stuck - forcing clear');
if (window.traceExecution) {
window.traceExecution('chat-functions', 'Loading stuck - forcing clear', { sessionId });
}
sessionsListEl.innerHTML = `
<div class="chat-history-empty">
<p style="color: #51cf66;">✅ Session ready</p>
<p style="font-size: 13px; color: #888;">Send a message to start chatting</p>
</div>
`;
}
}, 3000);
// ============================================================
// HYBRID APPROACH: Connect SSE instead of WebSocket subscription
// ============================================================
// With SSE, we connect to the session's event stream directly
// No need to "subscribe" - the connection is session-scoped by URL
if (window.sseClient && window.sseClient.currentSessionId !== sessionId) {
console.log('[attachToSession] Connecting SSE to session:', sessionId);
window.sseClient.connect(sessionId);
// Register SSE event handlers for this session
registerSSEEventHandlers(sessionId);
}
// Update active state in sidebar // Update active state in sidebar
document.querySelectorAll('.chat-session-item').forEach(item => { document.querySelectorAll('.chat-session-item').forEach(item => {
@@ -360,16 +576,182 @@ function attachToSession(sessionId) {
}); });
appendSystemMessage('Attached to session: ' + sessionId); appendSystemMessage('Attached to session: ' + sessionId);
// Refresh the session list in sidebar to show this session
// Use a flag to prevent infinite recursion since loadChatView might call attachToSession
if (typeof window.refreshSessionList === 'function') {
window.refreshSessionList();
}
} }
// Subscribe to session via WebSocket // Refresh session list without triggering attachment
window.refreshSessionList = async function() {
try {
const res = await fetch('/claude/api/claude/sessions');
if (!res.ok) return;
const data = await res.json();
const activeSessions = data.active || [];
const sessionsListEl = document.getElementById('chat-history-list');
if (!sessionsListEl) return;
// Only update if we're not showing "Loading session..."
if (sessionsListEl.textContent.includes('Loading session')) {
return;
}
if (activeSessions.length === 0) {
sessionsListEl.innerHTML = `
<div class="chat-history-empty">
<p style="color: #51cf66;">✅ Session ready</p>
<p style="font-size: 13px; color: #888;">Send a message to start chatting</p>
</div>
`;
return;
}
sessionsListEl.innerHTML = activeSessions.map(session => {
const projectName = session.metadata && session.metadata.project ?
session.metadata.project :
session.id.substring(0, 20);
const isActive = session.id === attachedSessionId ? 'active' : '';
return `
<div class="chat-history-item ${isActive}"
onclick="attachToSession('${session.id}')">
<div class="chat-history-icon">💬</div>
<div class="chat-history-content">
<div class="chat-history-title">${projectName}</div>
<div class="chat-history-meta">
<span class="chat-history-date">${new Date(session.createdAt).toLocaleDateString()}</span>
<span class="chat-history-status active">Running</span>
</div>
</div>
</div>
`;
}).join('');
} catch (error) {
console.error('[refreshSessionList] Error:', error);
}
};
// ============================================================
// HYBRID APPROACH: Register SSE event handlers
// ============================================================
// Map SSE events to the existing WebSocket message handlers
let SSE_HANDLERS_REGISTERED = false; // Guard flag to prevent duplicate registrations
function registerSSEEventHandlers(sessionId) {
if (!window.sseClient) return;
// GUARD: Only register handlers once to prevent duplicate AI responses
if (SSE_HANDLERS_REGISTERED) {
console.log('[registerSSEEventHandlers] Handlers already registered, skipping duplicate registration');
return;
}
SSE_HANDLERS_REGISTERED = true;
console.log('[registerSSEEventHandlers] Registering handlers for first time');
// Session output - handle AI responses
window.sseClient.on('session-output', (event) => {
console.log('[SSE] session-output:', event);
if (window.traceExecution) {
window.traceExecution('chat-functions', 'SSE session-output received', {
sessionId: event.sessionId,
type: event.type,
contentLength: event.content?.length || 0,
contentPreview: event.content?.substring(0, 100) || '',
attachedSessionId
});
}
// Pass event directly - handleSessionOutput expects data.data.content structure
handleSessionOutput({
sessionId: event.sessionId,
data: {
type: event.type || 'stdout',
content: event.content,
timestamp: event.timestamp || Date.now()
}
});
});
// Session error - handle errors
window.sseClient.on('session-error', (event) => {
console.log('[SSE] session-error:', event);
if (window.traceExecution) {
window.traceExecution('chat-functions', 'SSE session-error received', {
sessionId: event.sessionId,
error: event.error,
code: event.code
});
}
// Auto-report error for fixing
if (window.AutoFixLogger) {
window.AutoFixLogger.log('SSE session error', {
sessionId: event.sessionId,
error: event.error,
code: event.code
});
}
// Pass event directly
handleSessionOutput({
sessionId: event.sessionId,
data: {
type: 'error',
error: event.error,
code: event.code,
timestamp: event.timestamp || Date.now()
}
});
});
// Approval request - handle terminal command approvals
window.sseClient.on('approval-request', (event) => {
console.log('[SSE] approval-request:', event);
// Trigger approval UI
if (typeof handleApprovalRequest === 'function') {
handleApprovalRequest(event);
}
});
// Approval confirmed/expired
window.sseClient.on('approval-confirmed', (event) => {
console.log('[SSE] approval-confirmed:', event);
});
window.sseClient.on('approval-expired', (event) => {
console.log('[SSE] approval-expired:', event);
});
console.log('[SSE] Event handlers registered for session:', sessionId);
}
// Subscribe to session via WebSocket (LEGACY - for backward compatibility)
// This function is deprecated and will be removed once SSE is fully integrated
function subscribeToSession(sessionId) { function subscribeToSession(sessionId) {
// ============================================================
// HYBRID APPROACH: SSE replaces WebSocket subscription
// ============================================================
// SSE connections are session-scoped by URL, so no explicit
// subscription is needed. The SSE client handles this automatically.
if (window.sseClient && window.sseClient.currentSessionId !== sessionId) {
console.log('[subscribeToSession] Connecting SSE (replaces WebSocket subscription):', sessionId);
window.sseClient.connect(sessionId);
registerSSEEventHandlers(sessionId);
return;
}
// Fallback to WebSocket if SSE not available
if (window.ws && window.ws.readyState === WebSocket.OPEN) { if (window.ws && window.ws.readyState === WebSocket.OPEN) {
window.ws.send(JSON.stringify({ window.ws.send(JSON.stringify({
type: 'subscribe', type: 'subscribe',
sessionId: sessionId sessionId: sessionId
})); }));
console.log('Subscribed to session:', sessionId); console.log('[LEGACY] Subscribed to session via WebSocket:', sessionId);
} else if (window.ws && window.ws.readyState === WebSocket.CONNECTING) { } else if (window.ws && window.ws.readyState === WebSocket.CONNECTING) {
// Wait for connection to open, then subscribe // Wait for connection to open, then subscribe
console.log('[subscribeToSession] WebSocket connecting, will subscribe when ready...'); console.log('[subscribeToSession] WebSocket connecting, will subscribe when ready...');
@@ -394,16 +776,64 @@ function subscribeToSession(sessionId) {
} }
// Load Session Messages // Load Session Messages
// Uses batching to prevent UI blocking with large message buffers
async function loadSessionMessages(sessionId) { async function loadSessionMessages(sessionId) {
if (window.traceExecution) {
window.traceExecution('chat-functions', 'loadSessionMessages START', { sessionId });
}
try { try {
const res = await fetch('/claude/api/claude/sessions/' + sessionId); const res = await fetch('/claude/api/claude/sessions/' + sessionId);
if (window.traceExecution) {
window.traceExecution('chat-functions', 'loadSessionMessages fetch response', { sessionId, status: res.status, ok: res.ok });
}
if (!res.ok) {
if (window.traceExecution) {
window.traceExecution('chat-functions', 'loadSessionMessages fetch FAILED', { sessionId, status: res.status });
}
throw new Error(`HTTP ${res.status}`);
}
const data = await res.json(); const data = await res.json();
if (data.session) { if (data.session) {
clearChatDisplay(); clearChatDisplay();
// Add existing messages from output buffer - restore both user and assistant messages const messages = data.session.outputBuffer;
data.session.outputBuffer.forEach(entry => { const BATCH_SIZE = 20;
const totalMessages = messages.length;
if (totalMessages === 0) {
// New session with no messages yet - clear loading state and show ready state
if (window.traceExecution) {
window.traceExecution('chat-functions', 'loadSessionMessages - empty session, showing chat interface', { sessionId });
}
// Clear the "Loading..." message from the sidebar and refresh to show all sessions
const sessionsListEl = document.getElementById('chat-history-list');
if (sessionsListEl) {
sessionsListEl.innerHTML = `
<div class="chat-history-empty">
<p style="color: #51cf66;">✅ Session ready</p>
<p style="font-size: 13px; color: #888;">Send a message to start chatting</p>
</div>
`;
}
// Refresh sidebar to show all active sessions
if (typeof loadChatHistory === 'function') {
setTimeout(() => loadChatHistory(), 100);
} else if (typeof window.refreshSessionList === 'function') {
setTimeout(() => window.refreshSessionList(), 100);
}
return;
}
console.log(`[loadSessionMessages] Loading ${totalMessages} messages in batches of ${BATCH_SIZE}`);
// Process first batch immediately
const firstBatch = messages.slice(0, BATCH_SIZE);
for (const entry of firstBatch) {
// Check if entry has role information (newer format) // Check if entry has role information (newer format)
if (entry.role) { if (entry.role) {
appendMessage(entry.role, entry.content, false); appendMessage(entry.role, entry.content, false);
@@ -411,10 +841,58 @@ async function loadSessionMessages(sessionId) {
// Legacy format - assume assistant if no role specified // Legacy format - assume assistant if no role specified
appendMessage('assistant', entry.content, false); appendMessage('assistant', entry.content, false);
} }
}); }
// Process remaining batches in deferred chunks
if (totalMessages > BATCH_SIZE) {
let currentIndex = BATCH_SIZE;
function processNextBatch() {
const batch = messages.slice(currentIndex, currentIndex + BATCH_SIZE);
for (const entry of batch) {
// Check if entry has role information (newer format)
if (entry.role) {
appendMessage(entry.role, entry.content, false);
} else {
// Legacy format - assume assistant if no role specified
appendMessage('assistant', entry.content, false);
}
}
currentIndex += BATCH_SIZE;
// Continue with next batch using requestIdleCallback or setTimeout
if (currentIndex < totalMessages) {
if (window.requestIdleCallback) {
window.requestIdleCallback(processNextBatch, { timeout: 50 });
} else {
setTimeout(processNextBatch, 0);
}
}
}
// Start processing batches
if (window.requestIdleCallback) {
window.requestIdleCallback(processNextBatch, { timeout: 50 });
} else {
setTimeout(processNextBatch, 0);
}
}
}
// Refresh sidebar to show all active sessions after loading
if (typeof loadChatHistory === 'function') {
loadChatHistory();
} else if (typeof window.refreshSessionList === 'function') {
window.refreshSessionList();
} }
} catch (error) { } catch (error) {
console.error('Error loading session messages:', error); console.error('Error loading session messages:', error);
if (window.traceExecution) {
window.traceExecution('chat-functions', 'loadSessionMessages ERROR', { sessionId, error: error.message });
}
appendSystemMessage('❌ Failed to load messages: ' + error.message);
} }
} }
@@ -524,21 +1002,48 @@ function dismissModeSuggestion() {
} }
// Send Chat Message (Enhanced with smart input parsing) // Send Chat Message (Enhanced with smart input parsing)
async function sendChatMessage() { // @param {string} messageOverride - Optional message to send instead of input value
// @param {string} modeOverride - Optional mode to use instead of current mode
// @param {Object} options - Optional settings like { skipValidation: true }
async function sendChatMessage(messageOverride, modeOverride, options = {}) {
const input = document.getElementById('chat-input'); const input = document.getElementById('chat-input');
const message = input.value.trim(); const message = messageOverride || input.value.trim();
if (!message) return; if (!message) return;
if (window.traceExecution) {
window.traceExecution('chat-functions', 'sendChatMessage START', {
messageLength: message.length,
messagePreview: message.substring(0, 50),
modeOverride,
attachedSessionId,
hasMessageOverride: !!messageOverride
});
}
// ============================================================
// RACE CONDITION FIX: Block sending while waiting for attachment
// ============================================================
// Don't allow sending messages while we're waiting for session attachment
// to complete. This prevents the race condition where a user sends a
// message before attachToSession() finishes, which would trigger
// startNewChat() and create a wrong session.
if (window.pendingSessionAttach && !attachedSessionId) {
console.log('[sendChatMessage] ⏳ Blocking message - waiting for session attachment');
appendSystemMessage('⏳ Please wait while the session is being loaded...');
return;
}
// ============================================================ // ============================================================
// SEMANTIC VALIDATION - Detect intent/behavior mismatches // SEMANTIC VALIDATION - Detect intent/behavior mismatches
// Kimi-style flow: skip validation if explicitly requested (e.g., for approvals)
// ============================================================ // ============================================================
if (window.semanticValidator) { if (window.semanticValidator && !options.skipValidation) {
// Track user message for context // Track user message for context
window.semanticValidator.trackUserMessage(message); window.semanticValidator.trackUserMessage(message);
// Get the mode BEFORE any validation // Get the mode BEFORE any validation
const selectedMode = currentChatMode || 'auto'; const selectedMode = modeOverride || currentChatMode || 'auto';
// IMPORTANT: In Terminal/WebContainer mode, check if this is a command request first // IMPORTANT: In Terminal/WebContainer mode, check if this is a command request first
// If user says "run ping google.com", we should EXECUTE it, not block it! // If user says "run ping google.com", we should EXECUTE it, not block it!
@@ -707,12 +1212,17 @@ The AI assistant asked for your approval, but you responded in <strong>Terminal
} }
} }
// Use selected mode from buttons, or fall back to parsed mode // Use selected mode from buttons, or fall back to parsed mode, or override
const selectedMode = currentChatMode || 'auto'; const selectedMode = modeOverride || currentChatMode || 'auto';
// Add user message to chat // Add user message to chat (but only if it's from user input, not programmatic)
if (!messageOverride) {
appendMessage('user', message); appendMessage('user', message);
clearInput(); clearInput();
} else {
// For programmatic messages, still show them but don't clear input
appendMessage('user', message);
}
// Show streaming indicator and update button state // Show streaming indicator and update button state
showStreamingIndicator(); showStreamingIndicator();
@@ -724,80 +1234,106 @@ The AI assistant asked for your approval, but you responded in <strong>Terminal
return; return;
} }
// ============================================================
// HYBRID APPROACH: Send commands via REST API instead of WebSocket
// ============================================================
// SSE is for receiving events only. Commands are sent via REST API.
try { try {
// Check WebSocket state console.log('[sendChatMessage] Sending command via REST API to session:', attachedSessionId);
if (!window.ws) {
console.error('WebSocket is null/undefined');
appendSystemMessage('WebSocket not initialized. Please refresh the page.');
hideStreamingIndicator();
setGeneratingState(false);
return;
}
const state = window.ws.readyState; // Prepare request body
const stateName = ['CONNECTING', 'OPEN', 'CLOSING', 'CLOSED'][state] || 'UNKNOWN'; const requestBody = {
command: message,
console.log('WebSocket state:', state, stateName); mode: selectedMode
if (state !== WebSocket.OPEN) {
console.error('WebSocket not in OPEN state:', stateName);
appendSystemMessage(`WebSocket not ready (state: ${stateName}). Retrying...`);
hideStreamingIndicator();
setGeneratingState(false);
// Trigger reconnection if closed
if (state === WebSocket.CLOSED) {
console.log('WebSocket closed, triggering reconnection...');
if (typeof connectWebSocket === 'function') {
connectWebSocket();
}
}
return;
}
// Send command via WebSocket with parsed metadata
const payload = {
type: 'command',
sessionId: attachedSessionId,
command: message
}; };
// Add metadata if available (files, commands, mode) // Add metadata if available (files, commands)
const hasFiles = parsed && parsed.files.length > 0; const hasFiles = parsed && parsed.files.length > 0;
const hasCommands = parsed && parsed.commands.length > 0; const hasCommands = parsed && parsed.commands.length > 0;
const modeNotAuto = selectedMode !== 'auto';
if (hasFiles || hasCommands || modeNotAuto) { if (hasFiles || hasCommands) {
payload.metadata = { requestBody.metadata = {
files: parsed ? parsed.files : [], files: parsed ? parsed.files : [],
commands: parsed ? parsed.commands : [], commands: parsed ? parsed.commands : [],
mode: selectedMode,
hasFileReferences: parsed ? parsed.hasFileReferences : false hasFileReferences: parsed ? parsed.hasFileReferences : false
}; };
console.log('Sending with metadata:', payload.metadata); console.log('[sendChatMessage] Sending with metadata:', requestBody.metadata);
} }
// Debug logging before sending // Send via REST API (use /claude/api prefix for production nginx routing)
console.log('[DEBUG] About to send command payload:', { // NOTE: Use /claude/api/claude/sessions/:sessionId/prompt to access sessions-routes.js
type: payload.type, // which has historical session auto-recreate logic
sessionId: payload.sessionId, const apiUrl = `/claude/api/claude/sessions/${encodeURIComponent(attachedSessionId)}/prompt`;
commandLength: payload.command?.length,
wsReady: window.wsReady, if (window.traceExecution) {
wsState: window.ws?.readyState, window.traceExecution('chat-functions', 'sendChatMessage - calling API', {
queueLength: window.messageQueue?.length || 0 sessionId: attachedSessionId,
apiUrl,
requestBody: {
commandLength: requestBody.command?.length,
mode: requestBody.mode
}
});
}
const response = await fetch(apiUrl, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(requestBody)
}); });
// Use message queue to prevent race conditions console.log('[sendChatMessage] Response status:', response.status);
if (typeof queueMessage === 'function') {
queueMessage(payload); if (window.traceExecution) {
console.log('[DEBUG] Message queued, queue length now:', window.messageQueue?.length); window.traceExecution('chat-functions', 'sendChatMessage - API response', {
} else { status: response.status,
window.ws.send(JSON.stringify(payload)); ok: response.ok
console.log('[DEBUG] Sent directly via WebSocket (no queue function)'); });
} }
console.log('Sent command via WebSocket:', message.substring(0, 50));
if (!response.ok) {
const errorText = await response.text();
console.error('[sendChatMessage] API error:', response.status, errorText);
throw new Error(`HTTP ${response.status}: ${errorText}`);
}
const result = await response.json();
console.log('[sendChatMessage] Command sent successfully:', result);
// ============================================================
// AUTO-RECREATE HANDLING: Check if backend created a new session
// ============================================================
if (result.newSession && result.sessionId !== attachedSessionId) {
console.log('[sendChatMessage] 🔄 Session was auto-recreated, switching to new session:', result.sessionId);
// Update session IDs
const oldSessionId = attachedSessionId;
attachedSessionId = result.sessionId;
chatSessionId = result.sessionId;
// Update UI
document.getElementById('current-session-id').textContent = result.sessionId;
// Reconnect SSE to new session
if (window.sseClient) {
console.log('[sendChatMessage] Reconnecting SSE to new session:', result.sessionId);
window.sseClient.disconnect();
window.sseClient.connect(result.sessionId);
}
// Update URL without page reload
const newUrl = `/claude/ide/session/${result.sessionId}`;
window.history.replaceState({ sessionId: result.sessionId }, '', newUrl);
appendSystemMessage(`✅ Switched to new session (${result.sessionId.substring(-8)})`);
}
// Note: The actual response will come via SSE events
// The REST API just confirms the command was queued
} catch (error) { } catch (error) {
console.error('Error sending message:', error); console.error('[sendChatMessage] Error sending message:', error);
hideStreamingIndicator(); hideStreamingIndicator();
setGeneratingState(false); setGeneratingState(false);
appendSystemMessage('Failed to send message: ' + error.message); appendSystemMessage('Failed to send message: ' + error.message);
@@ -1098,6 +1634,16 @@ async function executeNativeCommand(message, sessionId) {
function appendMessage(role, content, scroll) { function appendMessage(role, content, scroll) {
const messagesContainer = document.getElementById('chat-messages'); const messagesContainer = document.getElementById('chat-messages');
if (window.traceExecution) {
window.traceExecution('chat-functions', 'appendMessage', {
role,
contentLength: content?.length || 0,
contentPreview: typeof content === 'string' ? content.substring(0, 100) : '[non-string content]',
scroll,
existingMessages: messagesContainer?.children?.length || 0
});
}
// Remove welcome message if present // Remove welcome message if present
const welcome = messagesContainer.querySelector('.chat-welcome'); const welcome = messagesContainer.querySelector('.chat-welcome');
if (welcome) { if (welcome) {
@@ -1351,4 +1897,28 @@ if (typeof window !== 'undefined') {
get: function() { return chatSessionId; }, get: function() { return chatSessionId; },
set: function(value) { chatSessionId = value; } set: function(value) { chatSessionId = value; }
}); });
// ============================================================
// SSE: Register event handlers after page load
// ============================================================
// Extract sessionId from URL path directly and register handlers
const registerSSEHandler = () => {
// Extract sessionId from URL path: /claude/ide/session/{sessionId}
const pathMatch = window.location.pathname.match(/\/claude\/ide\/session\/([^/]+)$/);
if (pathMatch && pathMatch[1]) {
const sessionId = decodeURIComponent(pathMatch[1]);
console.log('[chat-functions] Registering SSE handlers for session from URL:', sessionId);
registerSSEEventHandlers(sessionId);
}
};
// Register when DOM is ready
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', () => {
setTimeout(registerSSEHandler, 100);
});
} else {
// DOM already loaded, register immediately
setTimeout(registerSSEHandler, 100);
}
} }

View File

@@ -4,16 +4,276 @@
<meta charset="UTF-8"> <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Claude Code IDE</title> <title>Claude Code IDE</title>
<link rel="stylesheet" href="/claude/css/style.css"> <meta http-equiv=1769027229"Cache-Control" content="no-cache, no-store, must-revalidate">
<link rel="stylesheet" href="/claude/claude-ide/ide.css"> <meta http-equiv=1769027229"Pragma" content="no-cache">
<link rel="stylesheet" href="/claude/claude-ide/tag-renderer.css"> <meta http-equiv=1769027229"Expires" content="0">
<link rel="stylesheet" href="/claude/claude-ide/preview-manager.css">
<link rel="stylesheet" href="/claude/claude-ide/chat-enhanced.css"> <!-- ============================================================
<link rel="stylesheet" href="/claude/claude-ide/terminal.css"> PRELOAD: Extract Session ID from URL BEFORE any other JS runs
<link rel="stylesheet" href="/claude/claude-ide/components/monaco-editor.css"> This fixes race conditions where loadChatView() runs before ide.js
<link rel="stylesheet" href="/claude/claude-ide/components/enhanced-chat-input.css"> ============================================================ -->
<link rel="stylesheet" href="/claude/claude-ide/components/session-picker.css"> <script>
<link rel="stylesheet" href="/claude/claude-ide/components/approval-card.css"> (function() {
'use strict';
// Extract session ID from route-based URL: /claude/ide/session/{sessionId}
// This runs IMMEDIATELY, before any other scripts
const pathname = window.location.pathname;
const sessionMatch = pathname.match(/\/claude\/ide\/session\/([^\/]+)$/);
if (sessionMatch && sessionMatch[1]) {
window.PRELOAD_SESSION_ID = sessionMatch[1];
console.log('[PRELOAD] Session ID extracted from URL:', window.PRELOAD_SESSION_ID);
console.log('[PRELOAD] Full URL:', window.location.href);
if (window.traceExecution) {
window.traceExecution('PRELOAD', 'Session ID extracted', { sessionId: sessionMatch[1], url: window.location.href });
}
} else {
console.log('[PRELOAD] No session ID in URL pathname');
if (window.traceExecution) {
window.traceExecution('PRELOAD', 'No session ID in URL', { pathname: window.location.pathname });
}
}
// Also check for legacy query parameter
const urlParams = new URLSearchParams(window.location.search);
const querySessionId = urlParams.get('session');
if (querySessionId && !window.PRELOAD_SESSION_ID) {
window.PRELOAD_SESSION_ID = querySessionId;
console.log('[PRELOAD] Session ID from query param:', window.PRELOAD_SESSION_ID);
if (window.traceExecution) {
window.traceExecution('PRELOAD', 'Session ID from query param', { sessionId: querySessionId });
}
}
})();
</script>
<!-- ============================================================
REAL-TIME EXECUTION TRACER - For debugging session attachment
============================================================ -->
<script>
(function() {
'use strict';
window.EXECUTION_TRACE = [];
const MAX_TRACE_ENTRIES = 100;
function trace(component, event, data) {
const timestamp = new Date().toISOString().split('T')[1].slice(0, 12);
const entry = {
timestamp,
component,
event,
data
};
window.EXECUTION_TRACE.push(entry);
// Keep only recent entries
if (window.EXECUTION_TRACE.length > MAX_TRACE_ENTRIES) {
window.EXECUTION_TRACE.shift();
}
// Log to console with color
const colors = {
'PRELOAD': '#00ff00',
'Cache-Bust': '#ff00ff',
'ide.js': '#00ffff',
'session-picker': '#ffa500',
'chat-functions': '#ffff00',
'loadChatView': '#ff69b4',
'attachToSession': '#00ff00',
'switchView': '#87ceeb'
};
const color = colors[component] || '#ffffff';
console.log(
`%c[${timestamp}] %c${component}%c: ${event}`,
'color: #888',
`color: ${color}; font-weight: bold`,
'color: #ccc',
data
);
// Update trace panel if it exists
updateTracePanel();
}
function createTracePanel() {
const panel = document.createElement('div');
panel.id = 'execution-trace-panel';
panel.innerHTML = `
<div style="position: fixed; top: 10px; right: 10px; z-index: 99999; background: rgba(0,0,0,0.95); border: 2px solid #00ff00; border-radius: 8px; font-family: monospace; font-size: 11px; color: #00ff00; max-width: 400px; max-height: 300px; overflow: hidden;">
<div style="display: flex; justify-content: space-between; align-items: center; padding: 8px; border-bottom: 1px solid #00ff00; cursor: pointer;" onclick="toggleTracePanel()">
<strong>🔍 EXECUTION TRACE</strong>
<button id="trace-toggle" style="background: transparent; border: 1px solid #00ff00; color: #00ff00; cursor: pointer;">▼</button>
</div>
<div id="trace-content" style="padding: 8px; max-height: 250px; overflow-y: auto; font-size: 10px; line-height: 1.4;">
<div style="color: #888;">Waiting for events...</div>
</div>
</div>
`;
document.body.appendChild(panel);
}
function updateTracePanel() {
const content = document.getElementById('trace-content');
if (!content) return;
if (window.EXECUTION_TRACE.length === 0) {
content.innerHTML = '<div style="color: #888;">Waiting for events...</div>';
return;
}
const html = window.EXECUTION_TRACE.map(e => {
const colors = {
'PRELOAD': '#00ff00',
'Cache-Bust': '#ff00ff',
'ide.js': '#00ffff',
'session-picker': '#ffa500',
'chat-functions': '#ffff00',
'sse-client': '#ff69b4',
'loadChatView': '#ff69b4',
'attachToSession': '#00ff00',
'switchView': '#87ceeb'
};
const color = colors[e.component] || '#ffffff';
return `<div style="margin-bottom: 2px;">
<span style="color: #666;">[${e.timestamp}]</span>
<span style="color: ${color}; font-weight: bold;">${e.component}</span>:
<span style="color: #ccc;">${e.event}</span>
${e.data ? `<span style="color: #666;">${JSON.stringify(e.data)}</span>` : ''}
</div>`;
}).join('');
content.innerHTML = html;
content.scrollTop = content.scrollHeight;
}
function toggleTracePanel() {
const content = document.getElementById('trace-content');
const toggle = document.getElementById('trace-toggle');
if (content && toggle) {
if (content.style.display === 'none') {
content.style.display = 'block';
toggle.textContent = '▼';
} else {
content.style.display = 'none';
toggle.textContent = '▶';
}
}
}
// Initialize on DOM ready
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', createTracePanel);
} else {
createTracePanel();
}
// Auto-upload trace every 10 seconds
setInterval(() => {
if (window.EXECUTION_TRACE.length > 0) {
uploadTrace();
}
}, 10000);
// Function to upload trace to server
async function uploadTrace() {
try {
const sessionId = window.PRELOAD_SESSION_ID || window.attachedSessionId || 'unknown';
const response = await fetch('/claude/api/telemetry/trace', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
sessionId: sessionId,
trace: window.EXECUTION_TRACE
})
});
if (response.ok) {
console.log('[TraceTelemetry] Trace uploaded successfully');
}
} catch (error) {
console.error('[TraceTelemetry] Failed to upload trace:', error);
}
}
// Export trace function and upload globally
window.traceExecution = trace;
window.uploadTrace = uploadTrace;
})();
</script>
<!-- Cache-Busting Script - MUST run first -->
<script>
(function() {
'use strict';
const EXPECTED_JS_VERSION = '1769082354552'; // Cache bust for sidebar refresh fix
const CACHE_BUST_KEY = '_claude_cache_bust';
// Check if we need to force reload
const urlParams = new URLSearchParams(window.location.search);
const forceReload = urlParams.get('_force') === 'true';
// Check if we just reloaded
if (sessionStorage.getItem(CACHE_BUST_KEY)) {
sessionStorage.removeItem(CACHE_BUST_KEY);
console.log('[Cache-Bust] Fresh load confirmed');
return;
}
// Clear all caches and reload
async function forceFreshLoad() {
console.log('[Cache-Bust] Forcing fresh load...');
// Clear caches API
if ('caches' in window) {
const cacheNames = await caches.keys();
await Promise.all(cacheNames.map(name => caches.delete(name)));
console.log('[Cache-Bust] Cleared', cacheNames.length, 'caches');
}
// Unregister service workers
if ('serviceWorker' in navigator) {
const regs = await navigator.serviceWorker.getRegistrations();
await Promise.all(regs.map(r => r.unregister()));
console.log('[Cache-Bust] Unregistered', regs.length, 'service workers');
}
// Mark that we're reloading
sessionStorage.setItem(CACHE_BUST_KEY, 'true');
// Reload with cache busting
const url = new URL(window.location.href);
url.searchParams.set('_t', Date.now().toString());
url.searchParams.set('_v', EXPECTED_JS_VERSION);
window.location.href = url.toString();
}
// Detect if this is a stale cached page
if (!forceReload) {
// Check if page was loaded more than 5 minutes ago
const loadTime = performance.timing.responseStart;
const age = Date.now() - loadTime;
if (age > 300000) { // 5 minutes
console.warn('[Cache-Bust] Page is stale, forcing reload...');
forceFreshLoad();
return;
}
}
})();
</script>
<link rel="stylesheet" href="/claude/css/style.css?v=1769027229">
<link rel="stylesheet" href="/claude/claude-ide/ide.css?v=1769027229">
<link rel="stylesheet" href="/claude/claude-ide/tag-renderer.css?v=1769027229">
<link rel="stylesheet" href="/claude/claude-ide/preview-manager.css?v=1769027229">
<link rel="stylesheet" href="/claude/claude-ide/chat-enhanced.css?v=1769027229">
<link rel="stylesheet" href="/claude/claude-ide/terminal.css?v=1769027229">
<link rel="stylesheet" href="/claude/claude-ide/components/monaco-editor.css?v=1769027229">
<link rel="stylesheet" href="/claude/claude-ide/components/enhanced-chat-input.css?v=1769027229">
<link rel="stylesheet" href="/claude/claude-ide/components/session-picker.css?v=1769027229">
<link rel="stylesheet" href="/claude/claude-ide/components/approval-card.css?v=1769027229">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/styles/github-dark.min.css"> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/styles/github-dark.min.css">
<!-- Monaco Editor (VS Code Editor) - AMD Loader --> <!-- Monaco Editor (VS Code Editor) - AMD Loader -->
@@ -345,20 +605,24 @@
</div> </div>
</div> </div>
<script src="/claude/claude-ide/error-monitor.js"></script> <script src="/claude/claude-ide/error-monitor.js?v1769082165881"></script>
<script src="/claude/claude-ide/semantic-validator.js"></script> <script src="/claude/claude-ide/semantic-validator.js?v1769082165881"></script>
<script src="/claude/claude-ide/components/approval-card.js"></script> <!-- ============================================================
<script src="/claude/claude-ide/command-tracker.js"></script> HYBRID APPROACH: SSE Client for real-time session events
<script src="/claude/claude-ide/bug-tracker.js"></script> ============================================================ -->
<script src="/claude/claude-ide/ide.js?v=2"></script> <script src="/claude/claude-ide/sse-client.js?v1769082165881"></script>
<script src="/claude/claude-ide/chat-functions.js"></script> <script src="/claude/claude-ide/components/approval-card.js?v1769082165881"></script>
<script src="/claude/claude-ide/tag-renderer.js"></script> <script src="/claude/claude-ide/command-tracker.js?v1769082165881"></script>
<script src="/claude/claude-ide/preview-manager.js"></script> <script src="/claude/claude-ide/bug-tracker.js?v1769082165881"></script>
<script src="/claude/claude-ide/chat-enhanced.js"></script> <script src="/claude/claude-ide/ide.js?v1769082165881"></script>
<script src="/claude/claude-ide/terminal.js"></script> <script src="/claude/claude-ide/chat-functions.js?v1769082165881"></script>
<script src="/claude/claude-ide/components/monaco-editor.js"></script> <script src="/claude/claude-ide/tag-renderer.js?v1769082165881"></script>
<script src="/claude/claude-ide/components/enhanced-chat-input.js"></script> <script src="/claude/claude-ide/preview-manager.js?v1769082165881"></script>
<script src="/claude/claude-ide/components/session-picker.js"></script> <script src="/claude/claude-ide/chat-enhanced.js?v1769082165881"></script>
<script src="/claude/claude-ide/terminal.js?v1769082165881"></script>
<script src="/claude/claude-ide/components/monaco-editor.js?v1769082165881"></script>
<script src="/claude/claude-ide/components/enhanced-chat-input.js?v1769082165881"></script>
<script src="/claude/claude-ide/components/session-picker.js?v1769082165881"></script>
<!-- Debug Panel Toggle Script --> <!-- Debug Panel Toggle Script -->
<script> <script>
@@ -465,5 +729,42 @@
}; };
} }
</script> </script>
<!-- SSE Event Handler Registration -->
<script>
(function() {
'use strict';
// Register SSE event handlers after all scripts have loaded
function registerSSEHandlers() {
// Extract sessionId from URL path: /claude/ide/session/{sessionId}
const pathMatch = window.location.pathname.match(/\/claude\/ide\/session\/([^/]+)$/);
if (pathMatch && pathMatch[1]) {
const sessionId = decodeURIComponent(pathMatch[1]);
// Check if SSE client and handler function are available
if (typeof window.sseClient === 'object' && typeof registerSSEEventHandlers === 'function') {
console.log('[HTML-SSE] Registering SSE handlers for session:', sessionId);
registerSSEEventHandlers(sessionId);
} else {
console.error('[HTML-SSE] SSE client or registerSSEEventHandlers not available', {
sseClient: typeof window.sseClient,
registerSSEEventHandlers: typeof registerSSEEventHandlers
});
// Retry after a delay
setTimeout(registerSSEHandlers, 500);
}
}
}
// Register when DOM is ready
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', registerSSEHandlers);
} else {
registerSSEHandlers();
}
})();
</script>
</body> </body>
</html> </html>