From 5f29d17cfed9da9aeb33be7308c9caf836509ed5 Mon Sep 17 00:00:00 2001 From: Kunal Keshari Pattanaik Date: Thu, 4 Jun 2026 12:56:04 +0530 Subject: [PATCH 1/2] Remove duplicate terminal session functions --- ui/app.js | 219 ------------------------------------------------------ 1 file changed, 219 deletions(-) diff --git a/ui/app.js b/ui/app.js index 03fe20d..1f80fc4 100644 --- a/ui/app.js +++ b/ui/app.js @@ -2498,225 +2498,6 @@ function updateAutoScrollBtn(termId, isOn) { persistWorkspace(); } -function clearCli() { - const termBody = getTerminalBody(state.activeTerminalId); - if (termBody) { - termBody.innerHTML = '
$ Terminal cleared.
'; - } - document.getElementById('run-status').textContent = ''; - document.getElementById('run-status').className = 'run-status'; - document.getElementById('resource-panel').style.display = 'none'; - - if (state.runningScripts && state.runningScripts[state.activeTerminalId] && state.runningScripts[state.activeTerminalId].status !== 'running') { - state.runningScripts[state.activeTerminalId].status = 'idle'; - updateProgressTrackerUI(); - } -} - -// ─── Session Persistence ────────────────────────────────── - -async function saveSession() { - const sessionData = { - sessionId: state.sessionId || generateUUID(), - timestamp: Date.now(), - - terminals: state.terminals.map(id => { - const body = - document.getElementById(`terminal-body-${id}`) || - (id === 1 - ? document.getElementById('terminal-body') - : null); - - if (!body) return null; - - const lines = Array.from( - body.querySelectorAll('.cli-output-block') - ) - .slice(-100) - .map(el => ({ - text: el.textContent, - className: el.className.replace( - 'cli-output-block ', - '' - ) - })); - - return { - id, - lines - }; - }).filter(t => t !== null), - - activeTerminalId: state.activeTerminalId, - nextTerminalId: state.nextTerminalId, - - cmdHistory: state.cmdHistory, - cmdHistoryIndex: state.cmdHistoryIndex, - - unlockedScripts: serializeUnlockedScripts() - }; - - try { - await fetch('/api/sessions/save', { - method: 'POST', - headers: { - 'Content-Type': 'application/json' - }, - body: JSON.stringify({ - session: sessionData - }) - }); - - state.sessionId = sessionData.sessionId; - state.lastSaveTimestamp = Date.now(); - - } catch (e) { - console.error('Failed to save session:', e); - } -} - - -function generateUUID() { - return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx' - .replace(/[xy]/g, c => { - const r = Math.random() * 16 | 0; - const v = c === 'x' - ? r - : (r & 0x3 | 0x8); - - return v.toString(16); - }); -} - - -let saveSessionTimeout = null; - -function saveSessionDebounced() { - if (saveSessionTimeout) { - clearTimeout(saveSessionTimeout); - } - - saveSessionTimeout = setTimeout(() => { - saveSession(); - }, 2000); -} - - -async function restoreSession() { - try { - const res = await fetch('/api/sessions/restore'); - const data = await res.json(); - - if (!data.success || !data.session) { - return; - } - - const session = data.session; - - state.sessionId = session.sessionId || null; - - const terminalIds = session.terminals?.map(t => t.id); - state.terminals = terminalIds?.length ? terminalIds : [1]; - - state.activeTerminalId = - session.activeTerminalId || 1; - - state.nextTerminalId = - Math.max(...state.terminals) + 1; - - state.cmdHistory = - session.cmdHistory || []; - - state.cmdHistoryIndex = - session.cmdHistoryIndex || -1; - - restoreUnlockedScripts(session.unlockedScripts); - - const existingTabs = - document.querySelectorAll('.cli-tab'); - - existingTabs.forEach(tab => { - if (tab.id !== 'tab-btn-1') { - tab.remove(); - } - }); - - const existingBodies = - document.querySelectorAll('.cli-body'); - - existingBodies.forEach(body => { - if (body.id !== 'terminal-body') { - body.remove(); - } - }); - - for (const term of session.terminals || []) { - - if (term.id !== 1) { - // Create terminal DOM directly with the saved ID - // instead of calling addTerminal() which would - // corrupt state.nextTerminalId and state.terminals - const tabsContainer = document.getElementById('cli-tabs'); - const tabBtn = document.createElement('div'); - tabBtn.className = 'cli-tab'; - tabBtn.id = `tab-btn-${term.id}`; - tabBtn.innerHTML = ` - - - - - - Terminal ${term.id} - `; - tabBtn.onclick = () => switchTerminal(term.id); - tabsContainer.insertBefore(tabBtn, document.getElementById('btn-add-tab')); - - const bodyContainer = document.createElement('div'); - bodyContainer.className = 'cli-body'; - bodyContainer.setAttribute('role', 'log'); - bodyContainer.setAttribute('aria-live', 'polite'); - bodyContainer.id = `terminal-body-${term.id}`; - bodyContainer.style.display = 'none'; - - document.getElementById('cli-area').insertBefore( - bodyContainer, - document.querySelector('.cli-input-bar') - ); - } - - const body = - document.getElementById(`terminal-body-${term.id}`) || - (term.id === 1 - ? document.getElementById('terminal-body') - : null); - - if (!body) continue; - - body.innerHTML = ''; - - for (const line of term.lines || []) { - const div = document.createElement('div'); - - div.className = - `cli-output-block ${line.className}`; - - div.textContent = line.text; - - body.appendChild(div); - } - } - - switchTerminal(state.activeTerminalId); - - console.log('Session restored successfully'); - - } catch (e) { - console.error('Failed to restore session:', e); - } -} - -// ─── Terminal Tabs ─── - function addTerminal() { const id = state.nextTerminalId++; state.terminals.push(id); From c203f39e5a698908cb80dd7a0adf7d01ada5a031 Mon Sep 17 00:00:00 2001 From: Kunal Keshari Pattanaik Date: Thu, 4 Jun 2026 19:18:18 +0530 Subject: [PATCH 2/2] Log history cleanup failures for security scan --- app.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app.py b/app.py index ba877de..1d96a4a 100644 --- a/app.py +++ b/app.py @@ -2566,8 +2566,8 @@ def clear_history(): os.unlink(file_path) elif os.path.isdir(file_path): shutil.rmtree(file_path) - except Exception: - pass + except Exception as e: + logger.warning("Failed to remove execution log %s: %s", file_path, e) # Clear session logs if os.path.exists(SESSION_LOG_DIR): @@ -2578,8 +2578,8 @@ def clear_history(): os.unlink(file_path) elif os.path.isdir(file_path): shutil.rmtree(file_path) - except Exception: - pass + except Exception as e: + logger.warning("Failed to remove session log %s: %s", file_path, e) return jsonify({ 'success': True,