// CLI History Component // Displays execution history with filtering, search, and delete // ========== CLI History State ========== let cliExecutionHistory = []; let cliHistoryFilter = null; // Filter by tool let cliHistorySearch = ''; // Search query let cliHistoryLimit = 50; // ========== Data Loading ========== async function loadCliHistory(options = {}) { try { const { limit = cliHistoryLimit, tool = cliHistoryFilter, status = null } = options; let url = `/api/cli/history?path=${encodeURIComponent(projectPath)}&limit=${limit}`; if (tool) url += `&tool=${tool}`; if (status) url += `&status=${status}`; const response = await fetch(url); if (!response.ok) throw new Error('Failed to load CLI history'); const data = await response.json(); cliExecutionHistory = data.executions || []; return data; } catch (err) { console.error('Failed to load CLI history:', err); return { executions: [], total: 0, count: 0 }; } } async function loadExecutionDetail(executionId) { try { const url = `/api/cli/execution?path=${encodeURIComponent(projectPath)}&id=${encodeURIComponent(executionId)}`; const response = await fetch(url); if (!response.ok) throw new Error('Execution not found'); return await response.json(); } catch (err) { console.error('Failed to load execution detail:', err); return null; } } // ========== Rendering ========== function renderCliHistory() { const container = document.getElementById('cli-history-panel'); if (!container) return; // Filter by search query const filteredHistory = cliHistorySearch ? cliExecutionHistory.filter(exec => exec.prompt_preview.toLowerCase().includes(cliHistorySearch.toLowerCase()) || exec.tool.toLowerCase().includes(cliHistorySearch.toLowerCase()) ) : cliExecutionHistory; if (cliExecutionHistory.length === 0) { container.innerHTML = `
No executions yet
No matching results
${escapeHtml(detail.prompt)}
${escapeHtml(detail.output.stdout)}
${escapeHtml(detail.output.stderr)}
Output was truncated due to size.
` : ''}