diff --git a/app.py b/app.py index e2d60b0..024a689 100644 --- a/app.py +++ b/app.py @@ -2310,7 +2310,9 @@ def parse_script_metadata(filepath): for line in f: line = line.strip() if line.startswith("# name:"): - metadata["name"] = line[7:].strip() + name_val = line[7:].strip() + if name_val: + metadata["name"] = name_val elif line.startswith("# desc:"): metadata["desc"] = line[7:].strip() elif line.startswith("# tag:"): @@ -2318,15 +2320,6 @@ def parse_script_metadata(filepath): elif line.startswith("# url:"): metadata["url"] = line[6:].strip() elif not line.startswith("#") and line: - if line.startswith('# name:'): - name_val = line[7:].strip() - if name_val: - metadata['name'] = name_val - elif line.startswith('# desc:'): - metadata['desc'] = line[7:].strip() - elif line.startswith('# tag:'): - metadata['tag'] = line[6:].strip() - elif not line.startswith('#') and line: break except Exception: # nosec B110 pass @@ -2464,6 +2457,31 @@ def clear_history(): pass with open(FAILED_HISTORY_FILE, 'w', encoding='utf-8') as f: pass + + # Clear execution logs + if os.path.exists(EXECUTION_LOG_DIR): + for filename in os.listdir(EXECUTION_LOG_DIR): + file_path = os.path.join(EXECUTION_LOG_DIR, filename) + try: + if os.path.isfile(file_path) or os.path.islink(file_path): + os.unlink(file_path) + elif os.path.isdir(file_path): + shutil.rmtree(file_path) + except Exception: + pass + + # Clear session logs + if os.path.exists(SESSION_LOG_DIR): + for filename in os.listdir(SESSION_LOG_DIR): + file_path = os.path.join(SESSION_LOG_DIR, filename) + try: + if os.path.isfile(file_path) or os.path.islink(file_path): + os.unlink(file_path) + elif os.path.isdir(file_path): + shutil.rmtree(file_path) + except Exception: + pass + return jsonify({ 'success': True, 'message': 'Execution history cleared successfully' diff --git a/ui/app.js b/ui/app.js index e4ccd0c..6a10f15 100644 --- a/ui/app.js +++ b/ui/app.js @@ -19,7 +19,9 @@ const API = { pr: '/api/git/pr', history: '/api/history', history_export: '/api/history/export', + history_clear: '/api/history/clear', kill: '/api/scripts/kill', + command_history_clear: '/api/command_history/clear', reliability_summary: '/api/reliability/summary', reliability_failures: '/api/reliability/failures', reliability_trends: '/api/reliability/trends', @@ -3526,9 +3528,9 @@ function bindEvents() { const historyOverlay = document.getElementById('history-modal-overlay'); const historyClose = document.getElementById('history-modal-close'); const historySearch = document.getElementById('history-search'); - const historyFilters = document.querySelectorAll('.history-filter'); const historyExportTxt = document.getElementById('history-export-txt'); const historyExportLog = document.getElementById('history-export-log'); + const btnClearHistory = document.getElementById('btn-clear-history'); if (historyClose) historyClose.addEventListener('click', closeHistoryViewer); if (historyOverlay) { @@ -3553,31 +3555,49 @@ function bindEvents() { if (historyExportTxt) historyExportTxt.addEventListener('click', () => exportExecutionHistory('txt')); if (historyExportLog) historyExportLog.addEventListener('click', () => exportExecutionHistory('log')); + const historyClearBtn = document.getElementById('history-clear-btn'); if (historyClearBtn) { historyClearBtn.addEventListener('click', async () => { - const confirmation = confirm('Are you sure you want to permanently clear your command history log?'); + const confirmation = confirm('Are you sure you want to permanently clear your command and execution history? This will delete all script and command run logs, and reset CLI command history. This action cannot be undone.'); if (!confirmation) return; try { - const response = await fetch('/api/command_history/clear', { + // Clear command history + const cmdRes = await fetch(API.command_history_clear, { method: 'POST', headers: { 'Content-Type': 'application/json' } }); - const result = await response.json(); + const cmdResult = await cmdRes.json(); - if (result.success) { - const targetDisplayList = document.getElementById('history-list'); - if (targetDisplayList) { - targetDisplayList.innerHTML = '
Command history cleared successfully.
'; - } - const targetSummaryWidget = document.getElementById('history-summary'); - if (targetSummaryWidget) { - targetSummaryWidget.innerHTML = ''; - } - notify('Command history cleared successfully!', 'success'); + // Clear execution history + const execRes = await fetch(API.history_clear, { + method: 'POST', + headers: { 'Content-Type': 'application/json' } + }); + const execResult = await execRes.json(); + + if (cmdResult.success && execResult.success) { + // Reset client-side state + state.cmdHistory = []; + state.cmdHistoryIndex = -1; + state.historyEntries = []; + state.historySummary = { + total: 0, + failed: 0, + successful: 0, + scripts: 0, + commands: 0 + }; + + // Re-render components + renderHistorySummary(state.historySummary); + renderHistoryEntries(state.historyEntries); + + notify('Command and execution history cleared successfully!', 'success'); } else { - notify('Server failed to clear history: ' + (result.error || 'Unknown error'), 'error'); + const errMsg = (cmdResult.error || execResult.error || 'Unknown error'); + notify('Server failed to clear history: ' + errMsg, 'error'); } } catch (err) { console.error('Error clearing history:', err);