mirror of
https://github.com/catlog22/Claude-Code-Workflow.git
synced 2026-02-13 02:41:50 +08:00
feat: Implement SQLite storage for CLI execution history
- Introduced a new SQLite-based storage backend for managing CLI execution history. - Added `CliHistoryStore` class to handle conversation records and turns with efficient queries. - Migrated existing JSON history files to the new SQLite format. - Updated CLI executor to use asynchronous and synchronous methods for saving and loading conversations. - Enhanced execution history retrieval with support for filtering by tool, status, and search terms. - Added prompt concatenation utilities to build multi-turn prompts in various formats (plain, YAML, JSON). - Implemented batch deletion of conversations and improved error handling for database operations.
This commit is contained in:
@@ -2127,6 +2127,148 @@
|
||||
border-top: 1px solid hsl(var(--border));
|
||||
}
|
||||
|
||||
/* ========================================
|
||||
* Batch Delete & Multi-Select Styles
|
||||
* ======================================== */
|
||||
|
||||
/* Delete Dropdown */
|
||||
.history-delete-dropdown {
|
||||
position: relative;
|
||||
display: inline-block;
|
||||
}
|
||||
|
||||
.delete-dropdown-menu {
|
||||
display: none;
|
||||
position: absolute;
|
||||
top: 100%;
|
||||
right: 0;
|
||||
z-index: 50;
|
||||
min-width: 180px;
|
||||
padding: 0.375rem;
|
||||
background: hsl(var(--card));
|
||||
border: 1px solid hsl(var(--border));
|
||||
border-radius: 0.5rem;
|
||||
box-shadow: 0 4px 16px hsl(var(--foreground) / 0.1);
|
||||
margin-top: 0.25rem;
|
||||
}
|
||||
|
||||
.delete-dropdown-menu.show {
|
||||
display: block;
|
||||
}
|
||||
|
||||
.delete-dropdown-menu button {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
width: 100%;
|
||||
padding: 0.5rem 0.625rem;
|
||||
border: none;
|
||||
background: transparent;
|
||||
color: hsl(var(--foreground));
|
||||
font-size: 0.75rem;
|
||||
text-align: left;
|
||||
cursor: pointer;
|
||||
border-radius: 0.375rem;
|
||||
transition: all 0.15s ease;
|
||||
}
|
||||
|
||||
.delete-dropdown-menu button:hover {
|
||||
background: hsl(var(--hover));
|
||||
}
|
||||
|
||||
.delete-dropdown-menu button i {
|
||||
color: hsl(var(--muted-foreground));
|
||||
}
|
||||
|
||||
.delete-dropdown-menu .delete-all-btn {
|
||||
color: hsl(var(--destructive));
|
||||
}
|
||||
|
||||
.delete-dropdown-menu .delete-all-btn i {
|
||||
color: hsl(var(--destructive));
|
||||
}
|
||||
|
||||
.delete-dropdown-menu .delete-all-btn:hover {
|
||||
background: hsl(var(--destructive) / 0.1);
|
||||
}
|
||||
|
||||
.dropdown-divider {
|
||||
height: 1px;
|
||||
margin: 0.375rem 0;
|
||||
background: hsl(var(--border));
|
||||
}
|
||||
|
||||
/* Batch Actions Bar */
|
||||
.history-batch-actions {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.625rem;
|
||||
padding: 0.75rem 1rem;
|
||||
background: hsl(var(--primary) / 0.08);
|
||||
border: 1px solid hsl(var(--primary) / 0.2);
|
||||
border-radius: 0.5rem;
|
||||
margin-bottom: 1rem;
|
||||
}
|
||||
|
||||
.batch-select-count {
|
||||
font-size: 0.8125rem;
|
||||
font-weight: 600;
|
||||
color: hsl(var(--primary));
|
||||
margin-right: auto;
|
||||
}
|
||||
|
||||
.btn-danger {
|
||||
background: hsl(var(--destructive));
|
||||
color: hsl(var(--destructive-foreground));
|
||||
border-color: hsl(var(--destructive));
|
||||
}
|
||||
|
||||
.btn-danger:hover:not(:disabled) {
|
||||
opacity: 0.9;
|
||||
}
|
||||
|
||||
.btn-danger:disabled {
|
||||
opacity: 0.5;
|
||||
cursor: not-allowed;
|
||||
}
|
||||
|
||||
/* Multi-Select Checkbox */
|
||||
.history-checkbox-wrapper {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 2rem;
|
||||
height: 2rem;
|
||||
margin-right: 0.75rem;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.history-checkbox {
|
||||
width: 1.125rem;
|
||||
height: 1.125rem;
|
||||
cursor: pointer;
|
||||
accent-color: hsl(var(--primary));
|
||||
}
|
||||
|
||||
/* Selected Item State */
|
||||
.history-item-selected {
|
||||
background: hsl(var(--primary) / 0.08) !important;
|
||||
border-color: hsl(var(--primary) / 0.3) !important;
|
||||
}
|
||||
|
||||
/* Turn Badge for History List */
|
||||
.history-turn-badge {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 0.25rem;
|
||||
font-size: 0.625rem;
|
||||
font-weight: 600;
|
||||
padding: 0.1875rem 0.5rem;
|
||||
background: hsl(var(--primary) / 0.12);
|
||||
color: hsl(var(--primary));
|
||||
border-radius: 9999px;
|
||||
}
|
||||
|
||||
/* ========================================
|
||||
* Multi-Turn Conversation Styles
|
||||
* ======================================== */
|
||||
@@ -2199,7 +2341,7 @@
|
||||
color: hsl(var(--muted-foreground));
|
||||
}
|
||||
|
||||
/* Turn Divider */
|
||||
/* Turn Divider (legacy) */
|
||||
.cli-turn-divider {
|
||||
border: none;
|
||||
border-top: 1px dashed hsl(var(--border));
|
||||
@@ -2210,3 +2352,284 @@
|
||||
.cli-detail-error-section .cli-detail-error {
|
||||
max-height: 100px;
|
||||
}
|
||||
|
||||
/* ========================================
|
||||
* Enhanced Multi-Turn Display
|
||||
* ======================================== */
|
||||
|
||||
/* Turn Section */
|
||||
.cli-turn-section {
|
||||
padding: 0.75rem;
|
||||
border-radius: 0.5rem;
|
||||
background: hsl(var(--background));
|
||||
border: 1px solid hsl(var(--border));
|
||||
}
|
||||
|
||||
.cli-turn-section.cli-turn-latest {
|
||||
border-color: hsl(var(--primary) / 0.3);
|
||||
background: hsl(var(--primary) / 0.03);
|
||||
}
|
||||
|
||||
/* Turn Header */
|
||||
.cli-turn-header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
margin-bottom: 0.75rem;
|
||||
padding-bottom: 0.5rem;
|
||||
border-bottom: 1px solid hsl(var(--border));
|
||||
flex-wrap: wrap;
|
||||
gap: 0.5rem;
|
||||
}
|
||||
|
||||
.cli-turn-marker {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
}
|
||||
|
||||
.cli-turn-number {
|
||||
font-size: 0.8125rem;
|
||||
font-weight: 600;
|
||||
color: hsl(var(--primary));
|
||||
}
|
||||
|
||||
.cli-turn-latest-badge {
|
||||
font-size: 0.5625rem;
|
||||
font-weight: 600;
|
||||
padding: 0.125rem 0.375rem;
|
||||
background: hsl(var(--success) / 0.12);
|
||||
color: hsl(var(--success));
|
||||
border-radius: 9999px;
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.03em;
|
||||
}
|
||||
|
||||
.cli-turn-meta {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.75rem;
|
||||
font-size: 0.6875rem;
|
||||
color: hsl(var(--muted-foreground));
|
||||
}
|
||||
|
||||
.cli-turn-meta span {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.25rem;
|
||||
}
|
||||
|
||||
.cli-turn-time i,
|
||||
.cli-turn-duration i {
|
||||
color: hsl(var(--muted-foreground) / 0.7);
|
||||
}
|
||||
|
||||
/* Turn Body */
|
||||
.cli-turn-body {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.75rem;
|
||||
}
|
||||
|
||||
/* Section Labels */
|
||||
.cli-prompt-section h4 {
|
||||
color: hsl(var(--primary));
|
||||
}
|
||||
|
||||
.cli-prompt-section h4 i {
|
||||
color: hsl(var(--primary));
|
||||
}
|
||||
|
||||
.cli-output-section h4 {
|
||||
color: hsl(var(--success));
|
||||
}
|
||||
|
||||
.cli-output-section h4 i {
|
||||
color: hsl(var(--success));
|
||||
}
|
||||
|
||||
/* Turn Connector (visual line between turns) */
|
||||
.cli-turn-connector {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
padding: 0.25rem 0;
|
||||
}
|
||||
|
||||
.cli-turn-line {
|
||||
width: 2px;
|
||||
height: 1.5rem;
|
||||
background: linear-gradient(
|
||||
to bottom,
|
||||
hsl(var(--border)),
|
||||
hsl(var(--primary) / 0.3),
|
||||
hsl(var(--border))
|
||||
);
|
||||
border-radius: 1px;
|
||||
}
|
||||
|
||||
/* Truncated Notice */
|
||||
.cli-truncated-notice {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.375rem;
|
||||
font-size: 0.75rem;
|
||||
color: hsl(var(--warning));
|
||||
margin-top: 0.5rem;
|
||||
padding: 0.375rem 0.625rem;
|
||||
background: hsl(var(--warning) / 0.08);
|
||||
border-radius: 0.25rem;
|
||||
}
|
||||
|
||||
.cli-truncated-notice i {
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
/* Turn Badge with Icon */
|
||||
.cli-turn-badge {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 0.25rem;
|
||||
}
|
||||
|
||||
.cli-turn-badge i {
|
||||
width: 12px;
|
||||
height: 12px;
|
||||
}
|
||||
|
||||
/* ========================================
|
||||
* Conversation View Toggle
|
||||
* ======================================== */
|
||||
|
||||
/* View Toggle Bar */
|
||||
.cli-view-toggle {
|
||||
display: flex;
|
||||
gap: 0.5rem;
|
||||
margin-bottom: 1rem;
|
||||
padding: 0.5rem;
|
||||
background: hsl(var(--muted) / 0.3);
|
||||
border-radius: 0.5rem;
|
||||
}
|
||||
|
||||
.cli-view-toggle .btn {
|
||||
flex: 1;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.cli-view-toggle .btn.active {
|
||||
background: hsl(var(--primary));
|
||||
color: hsl(var(--primary-foreground));
|
||||
border-color: hsl(var(--primary));
|
||||
}
|
||||
|
||||
/* Concatenated Prompt Section */
|
||||
.cli-concat-section {
|
||||
margin-top: 1rem;
|
||||
}
|
||||
|
||||
.cli-concat-format-selector {
|
||||
display: flex;
|
||||
gap: 0.375rem;
|
||||
margin-bottom: 0.75rem;
|
||||
}
|
||||
|
||||
.cli-concat-format-selector .btn-xs {
|
||||
padding: 0.25rem 0.625rem;
|
||||
font-size: 0.6875rem;
|
||||
}
|
||||
|
||||
.cli-concat-output {
|
||||
max-height: 400px;
|
||||
overflow-y: auto;
|
||||
font-size: 0.75rem;
|
||||
white-space: pre-wrap;
|
||||
word-break: break-word;
|
||||
}
|
||||
|
||||
/* Button Sizes */
|
||||
.btn-xs {
|
||||
padding: 0.25rem 0.5rem;
|
||||
font-size: 0.6875rem;
|
||||
border-radius: 0.25rem;
|
||||
}
|
||||
|
||||
/* ========================================
|
||||
* CLI Settings Section
|
||||
* ======================================== */
|
||||
|
||||
.cli-settings-section {
|
||||
margin-top: 1.5rem;
|
||||
padding-top: 1.25rem;
|
||||
border-top: 1px solid hsl(var(--border));
|
||||
}
|
||||
|
||||
.cli-settings-header {
|
||||
margin-bottom: 1rem;
|
||||
}
|
||||
|
||||
.cli-settings-header h4 {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
font-size: 0.875rem;
|
||||
font-weight: 600;
|
||||
color: hsl(var(--foreground));
|
||||
}
|
||||
|
||||
.cli-settings-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
|
||||
gap: 1rem;
|
||||
}
|
||||
|
||||
.cli-setting-item {
|
||||
padding: 0.875rem;
|
||||
background: hsl(var(--muted) / 0.3);
|
||||
border: 1px solid hsl(var(--border));
|
||||
border-radius: 0.5rem;
|
||||
}
|
||||
|
||||
.cli-setting-label {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.375rem;
|
||||
font-size: 0.75rem;
|
||||
font-weight: 600;
|
||||
color: hsl(var(--foreground));
|
||||
margin-bottom: 0.5rem;
|
||||
}
|
||||
|
||||
.cli-setting-label i {
|
||||
color: hsl(var(--primary));
|
||||
}
|
||||
|
||||
.cli-setting-control {
|
||||
margin-bottom: 0.375rem;
|
||||
}
|
||||
|
||||
.cli-setting-select {
|
||||
width: 100%;
|
||||
padding: 0.5rem 0.625rem;
|
||||
font-size: 0.75rem;
|
||||
background: hsl(var(--background));
|
||||
border: 1px solid hsl(var(--border));
|
||||
border-radius: 0.375rem;
|
||||
color: hsl(var(--foreground));
|
||||
cursor: pointer;
|
||||
transition: all 0.15s ease;
|
||||
}
|
||||
|
||||
.cli-setting-select:hover {
|
||||
border-color: hsl(var(--primary) / 0.5);
|
||||
}
|
||||
|
||||
.cli-setting-select:focus {
|
||||
outline: none;
|
||||
border-color: hsl(var(--primary));
|
||||
box-shadow: 0 0 0 2px hsl(var(--primary) / 0.1);
|
||||
}
|
||||
|
||||
.cli-setting-desc {
|
||||
font-size: 0.6875rem;
|
||||
color: hsl(var(--muted-foreground));
|
||||
line-height: 1.4;
|
||||
}
|
||||
|
||||
@@ -180,66 +180,106 @@ async function showExecutionDetail(executionId, sourceDir) {
|
||||
const latestStatus = isConversation ? conversation.latest_status : conversation.status;
|
||||
const createdAt = isConversation ? conversation.created_at : conversation.timestamp;
|
||||
|
||||
// Build turns HTML
|
||||
// Build turns HTML with improved multi-turn display
|
||||
let turnsHtml = '';
|
||||
if (isConversation && conversation.turns.length > 0) {
|
||||
turnsHtml = conversation.turns.map((turn, idx) => `
|
||||
<div class="cli-turn-section">
|
||||
<div class="cli-turn-header">
|
||||
<span class="cli-turn-number">Turn ${turn.turn}</span>
|
||||
<span class="cli-turn-status status-${turn.status}">${turn.status}</span>
|
||||
<span class="cli-turn-duration">${formatDuration(turn.duration_ms)}</span>
|
||||
</div>
|
||||
<div class="cli-detail-section">
|
||||
<h4><i data-lucide="message-square"></i> Prompt</h4>
|
||||
<pre class="cli-detail-prompt">${escapeHtml(turn.prompt)}</pre>
|
||||
</div>
|
||||
${turn.output.stdout ? `
|
||||
<div class="cli-detail-section">
|
||||
<h4><i data-lucide="terminal"></i> Output</h4>
|
||||
<pre class="cli-detail-output">${escapeHtml(turn.output.stdout)}</pre>
|
||||
turnsHtml = conversation.turns.map((turn, idx) => {
|
||||
const isFirst = idx === 0;
|
||||
const isLast = idx === conversation.turns.length - 1;
|
||||
const turnTime = new Date(turn.timestamp).toLocaleTimeString();
|
||||
const statusIcon = turn.status === 'success' ? 'check-circle' :
|
||||
turn.status === 'timeout' ? 'clock' : 'x-circle';
|
||||
|
||||
return `
|
||||
<div class="cli-turn-section ${isLast ? 'cli-turn-latest' : ''}">
|
||||
<div class="cli-turn-header">
|
||||
<div class="cli-turn-marker">
|
||||
<span class="cli-turn-number">${isFirst ? '▶' : '↳'} Turn ${turn.turn}</span>
|
||||
${isLast ? '<span class="cli-turn-latest-badge">Latest</span>' : ''}
|
||||
</div>
|
||||
<div class="cli-turn-meta">
|
||||
<span class="cli-turn-time"><i data-lucide="clock" class="w-3 h-3"></i> ${turnTime}</span>
|
||||
<span class="cli-turn-status status-${turn.status}">
|
||||
<i data-lucide="${statusIcon}" class="w-3 h-3"></i> ${turn.status}
|
||||
</span>
|
||||
<span class="cli-turn-duration">${formatDuration(turn.duration_ms)}</span>
|
||||
</div>
|
||||
</div>
|
||||
` : ''}
|
||||
${turn.output.stderr ? `
|
||||
<div class="cli-detail-section cli-detail-error-section">
|
||||
<h4><i data-lucide="alert-triangle"></i> Errors</h4>
|
||||
<pre class="cli-detail-error">${escapeHtml(turn.output.stderr)}</pre>
|
||||
<div class="cli-turn-body">
|
||||
<div class="cli-detail-section cli-prompt-section">
|
||||
<h4><i data-lucide="user" class="w-3.5 h-3.5"></i> User Prompt</h4>
|
||||
<pre class="cli-detail-prompt">${escapeHtml(turn.prompt)}</pre>
|
||||
</div>
|
||||
${turn.output.stdout ? `
|
||||
<div class="cli-detail-section cli-output-section">
|
||||
<h4><i data-lucide="bot" class="w-3.5 h-3.5"></i> Assistant Response</h4>
|
||||
<pre class="cli-detail-output">${escapeHtml(turn.output.stdout)}</pre>
|
||||
</div>
|
||||
` : ''}
|
||||
${turn.output.stderr ? `
|
||||
<div class="cli-detail-section cli-detail-error-section">
|
||||
<h4><i data-lucide="alert-triangle" class="w-3.5 h-3.5"></i> Errors</h4>
|
||||
<pre class="cli-detail-error">${escapeHtml(turn.output.stderr)}</pre>
|
||||
</div>
|
||||
` : ''}
|
||||
${turn.output.truncated ? `
|
||||
<p class="cli-truncated-notice">
|
||||
<i data-lucide="info" class="w-3 h-3"></i>
|
||||
Output was truncated due to size.
|
||||
</p>
|
||||
` : ''}
|
||||
</div>
|
||||
` : ''}
|
||||
${turn.output.truncated ? `
|
||||
<p class="text-warning" style="font-size: 0.75rem; margin-top: 0.5rem;">
|
||||
<i data-lucide="info" class="w-3 h-3" style="display: inline;"></i>
|
||||
Output was truncated due to size.
|
||||
</p>
|
||||
` : ''}
|
||||
</div>
|
||||
`).join('<hr class="cli-turn-divider">');
|
||||
</div>
|
||||
`;
|
||||
}).join('<div class="cli-turn-connector"><div class="cli-turn-line"></div></div>');
|
||||
} else {
|
||||
// Legacy single execution format
|
||||
const detail = conversation;
|
||||
turnsHtml = `
|
||||
<div class="cli-detail-section">
|
||||
<h4><i data-lucide="message-square"></i> Prompt</h4>
|
||||
<pre class="cli-detail-prompt">${escapeHtml(detail.prompt)}</pre>
|
||||
<div class="cli-turn-section">
|
||||
<div class="cli-turn-body">
|
||||
<div class="cli-detail-section cli-prompt-section">
|
||||
<h4><i data-lucide="user" class="w-3.5 h-3.5"></i> User Prompt</h4>
|
||||
<pre class="cli-detail-prompt">${escapeHtml(detail.prompt)}</pre>
|
||||
</div>
|
||||
${detail.output.stdout ? `
|
||||
<div class="cli-detail-section cli-output-section">
|
||||
<h4><i data-lucide="bot" class="w-3.5 h-3.5"></i> Assistant Response</h4>
|
||||
<pre class="cli-detail-output">${escapeHtml(detail.output.stdout)}</pre>
|
||||
</div>
|
||||
` : ''}
|
||||
${detail.output.stderr ? `
|
||||
<div class="cli-detail-section cli-detail-error-section">
|
||||
<h4><i data-lucide="alert-triangle" class="w-3.5 h-3.5"></i> Errors</h4>
|
||||
<pre class="cli-detail-error">${escapeHtml(detail.output.stderr)}</pre>
|
||||
</div>
|
||||
` : ''}
|
||||
${detail.output.truncated ? `
|
||||
<p class="cli-truncated-notice">
|
||||
<i data-lucide="info" class="w-3 h-3"></i>
|
||||
Output was truncated due to size.
|
||||
</p>
|
||||
` : ''}
|
||||
</div>
|
||||
</div>
|
||||
${detail.output.stdout ? `
|
||||
`;
|
||||
}
|
||||
|
||||
// Build concatenated prompt view (for multi-turn conversations)
|
||||
let concatenatedPromptHtml = '';
|
||||
if (isConversation && conversation.turns.length > 1) {
|
||||
concatenatedPromptHtml = `
|
||||
<div class="cli-concat-section" id="concatPromptSection" style="display: none;">
|
||||
<div class="cli-detail-section">
|
||||
<h4><i data-lucide="terminal"></i> Output</h4>
|
||||
<pre class="cli-detail-output">${escapeHtml(detail.output.stdout)}</pre>
|
||||
<h4><i data-lucide="layers" class="w-3.5 h-3.5"></i> Concatenated Prompt (sent to CLI)</h4>
|
||||
<div class="cli-concat-format-selector">
|
||||
<button class="btn btn-xs ${true ? 'btn-primary' : 'btn-outline'}" onclick="switchConcatFormat('plain', '${executionId}')">Plain</button>
|
||||
<button class="btn btn-xs btn-outline" onclick="switchConcatFormat('yaml', '${executionId}')">YAML</button>
|
||||
<button class="btn btn-xs btn-outline" onclick="switchConcatFormat('json', '${executionId}')">JSON</button>
|
||||
</div>
|
||||
<pre class="cli-detail-output cli-concat-output" id="concatPromptOutput">${escapeHtml(buildConcatenatedPrompt(conversation, 'plain'))}</pre>
|
||||
</div>
|
||||
` : ''}
|
||||
${detail.output.stderr ? `
|
||||
<div class="cli-detail-section">
|
||||
<h4><i data-lucide="alert-triangle"></i> Errors</h4>
|
||||
<pre class="cli-detail-error">${escapeHtml(detail.output.stderr)}</pre>
|
||||
</div>
|
||||
` : ''}
|
||||
${detail.output.truncated ? `
|
||||
<p class="text-warning" style="font-size: 0.75rem; margin-top: 0.5rem;">
|
||||
<i data-lucide="info" class="w-3 h-3" style="display: inline;"></i>
|
||||
Output was truncated due to size.
|
||||
</p>
|
||||
` : ''}
|
||||
</div>
|
||||
`;
|
||||
}
|
||||
|
||||
@@ -247,7 +287,7 @@ async function showExecutionDetail(executionId, sourceDir) {
|
||||
<div class="cli-detail-header">
|
||||
<div class="cli-detail-info">
|
||||
<span class="cli-tool-tag cli-tool-${conversation.tool}">${conversation.tool}</span>
|
||||
${turnCount > 1 ? `<span class="cli-turn-badge">${turnCount} turns</span>` : ''}
|
||||
${turnCount > 1 ? `<span class="cli-turn-badge"><i data-lucide="messages-square" class="w-3 h-3"></i> ${turnCount} turns</span>` : ''}
|
||||
<span class="cli-detail-status status-${latestStatus}">${latestStatus}</span>
|
||||
<span class="text-muted-foreground">${formatDuration(totalDuration)}</span>
|
||||
</div>
|
||||
@@ -255,21 +295,41 @@ async function showExecutionDetail(executionId, sourceDir) {
|
||||
<span><i data-lucide="cpu" class="w-3 h-3"></i> ${conversation.model || 'default'}</span>
|
||||
<span><i data-lucide="toggle-right" class="w-3 h-3"></i> ${conversation.mode}</span>
|
||||
<span><i data-lucide="calendar" class="w-3 h-3"></i> ${new Date(createdAt).toLocaleString()}</span>
|
||||
<span><i data-lucide="hash" class="w-3 h-3"></i> ${executionId.split('-')[0]}</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="cli-turns-container">
|
||||
${turnCount > 1 ? `
|
||||
<div class="cli-view-toggle">
|
||||
<button class="btn btn-sm btn-outline active" onclick="toggleConversationView('turns')">
|
||||
<i data-lucide="list" class="w-3.5 h-3.5"></i> Per-Turn View
|
||||
</button>
|
||||
<button class="btn btn-sm btn-outline" onclick="toggleConversationView('concat')">
|
||||
<i data-lucide="layers" class="w-3.5 h-3.5"></i> Concatenated View
|
||||
</button>
|
||||
</div>
|
||||
` : ''}
|
||||
<div class="cli-turns-container" id="turnsContainer">
|
||||
${turnsHtml}
|
||||
</div>
|
||||
${concatenatedPromptHtml}
|
||||
<div class="cli-detail-actions">
|
||||
<button class="btn btn-sm btn-outline" onclick="copyConversationId('${executionId}')">
|
||||
<i data-lucide="copy" class="w-3.5 h-3.5"></i> Copy ID
|
||||
</button>
|
||||
${turnCount > 1 ? `
|
||||
<button class="btn btn-sm btn-outline" onclick="copyConcatenatedPrompt('${executionId}')">
|
||||
<i data-lucide="clipboard-copy" class="w-3.5 h-3.5"></i> Copy Full Prompt
|
||||
</button>
|
||||
` : ''}
|
||||
<button class="btn btn-sm btn-outline btn-danger" onclick="confirmDeleteExecution('${executionId}'); closeModal();">
|
||||
<i data-lucide="trash-2" class="w-3.5 h-3.5"></i> Delete
|
||||
</button>
|
||||
</div>
|
||||
`;
|
||||
|
||||
// Store conversation data for format switching
|
||||
window._currentConversation = conversation;
|
||||
|
||||
showModal('Conversation Detail', modalContent);
|
||||
}
|
||||
|
||||
@@ -354,6 +414,169 @@ async function copyConversationId(conversationId) {
|
||||
}
|
||||
}
|
||||
|
||||
// ========== Concatenated Prompt Functions ==========
|
||||
|
||||
/**
|
||||
* Build concatenated prompt from conversation turns
|
||||
* Formats: plain, yaml, json
|
||||
*/
|
||||
function buildConcatenatedPrompt(conversation, format) {
|
||||
if (!conversation || !conversation.turns || conversation.turns.length === 0) {
|
||||
return '';
|
||||
}
|
||||
|
||||
const turns = conversation.turns;
|
||||
|
||||
switch (format) {
|
||||
case 'yaml':
|
||||
return buildYamlPrompt(conversation);
|
||||
case 'json':
|
||||
return buildJsonPrompt(conversation);
|
||||
case 'plain':
|
||||
default:
|
||||
return buildPlainPrompt(conversation);
|
||||
}
|
||||
}
|
||||
|
||||
function buildPlainPrompt(conversation) {
|
||||
const parts = [];
|
||||
parts.push('=== CONVERSATION HISTORY ===');
|
||||
parts.push('');
|
||||
|
||||
for (const turn of conversation.turns) {
|
||||
parts.push('--- Turn ' + turn.turn + ' ---');
|
||||
parts.push('USER:');
|
||||
parts.push(turn.prompt);
|
||||
parts.push('');
|
||||
parts.push('ASSISTANT:');
|
||||
parts.push(turn.output.stdout || '[No output]');
|
||||
parts.push('');
|
||||
}
|
||||
|
||||
parts.push('=== NEW REQUEST ===');
|
||||
parts.push('');
|
||||
parts.push('[Your next prompt here]');
|
||||
|
||||
return parts.join('\n');
|
||||
}
|
||||
|
||||
function buildYamlPrompt(conversation) {
|
||||
const lines = [];
|
||||
lines.push('context:');
|
||||
lines.push(' tool: ' + conversation.tool);
|
||||
lines.push(' model: ' + (conversation.model || 'default'));
|
||||
lines.push(' mode: ' + conversation.mode);
|
||||
lines.push('');
|
||||
lines.push('conversation:');
|
||||
|
||||
for (const turn of conversation.turns) {
|
||||
lines.push(' - turn: ' + turn.turn);
|
||||
lines.push(' timestamp: ' + turn.timestamp);
|
||||
lines.push(' status: ' + turn.status);
|
||||
lines.push(' user: |');
|
||||
turn.prompt.split('\n').forEach(function(line) {
|
||||
lines.push(' ' + line);
|
||||
});
|
||||
lines.push(' assistant: |');
|
||||
(turn.output.stdout || '[No output]').split('\n').forEach(function(line) {
|
||||
lines.push(' ' + line);
|
||||
});
|
||||
lines.push('');
|
||||
}
|
||||
|
||||
lines.push('new_request: |');
|
||||
lines.push(' [Your next prompt here]');
|
||||
|
||||
return lines.join('\n');
|
||||
}
|
||||
|
||||
function buildJsonPrompt(conversation) {
|
||||
const data = {
|
||||
context: {
|
||||
tool: conversation.tool,
|
||||
model: conversation.model || 'default',
|
||||
mode: conversation.mode
|
||||
},
|
||||
conversation: conversation.turns.map(function(turn) {
|
||||
return {
|
||||
turn: turn.turn,
|
||||
timestamp: turn.timestamp,
|
||||
status: turn.status,
|
||||
user: turn.prompt,
|
||||
assistant: turn.output.stdout || '[No output]'
|
||||
};
|
||||
}),
|
||||
new_request: '[Your next prompt here]'
|
||||
};
|
||||
return JSON.stringify(data, null, 2);
|
||||
}
|
||||
|
||||
/**
|
||||
* Toggle between per-turn and concatenated views
|
||||
*/
|
||||
function toggleConversationView(view) {
|
||||
var turnsContainer = document.getElementById('turnsContainer');
|
||||
var concatSection = document.getElementById('concatPromptSection');
|
||||
var buttons = document.querySelectorAll('.cli-view-toggle button');
|
||||
|
||||
if (view === 'concat') {
|
||||
if (turnsContainer) turnsContainer.style.display = 'none';
|
||||
if (concatSection) concatSection.style.display = 'block';
|
||||
buttons.forEach(function(btn, idx) {
|
||||
btn.classList.toggle('active', idx === 1);
|
||||
});
|
||||
} else {
|
||||
if (turnsContainer) turnsContainer.style.display = 'block';
|
||||
if (concatSection) concatSection.style.display = 'none';
|
||||
buttons.forEach(function(btn, idx) {
|
||||
btn.classList.toggle('active', idx === 0);
|
||||
});
|
||||
}
|
||||
|
||||
if (window.lucide) lucide.createIcons();
|
||||
}
|
||||
|
||||
/**
|
||||
* Switch concatenation format (plain/yaml/json)
|
||||
*/
|
||||
function switchConcatFormat(format, executionId) {
|
||||
var conversation = window._currentConversation;
|
||||
if (!conversation) return;
|
||||
|
||||
var output = document.getElementById('concatPromptOutput');
|
||||
if (output) {
|
||||
output.textContent = buildConcatenatedPrompt(conversation, format);
|
||||
}
|
||||
|
||||
// Update button states
|
||||
var buttons = document.querySelectorAll('.cli-concat-format-selector button');
|
||||
buttons.forEach(function(btn) {
|
||||
var btnFormat = btn.textContent.toLowerCase();
|
||||
btn.className = 'btn btn-xs ' + (btnFormat === format ? 'btn-primary' : 'btn-outline');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Copy concatenated prompt to clipboard
|
||||
*/
|
||||
async function copyConcatenatedPrompt(executionId) {
|
||||
var conversation = window._currentConversation;
|
||||
if (!conversation) {
|
||||
showRefreshToast('Conversation not found', 'error');
|
||||
return;
|
||||
}
|
||||
|
||||
var prompt = buildConcatenatedPrompt(conversation, 'plain');
|
||||
if (navigator.clipboard) {
|
||||
try {
|
||||
await navigator.clipboard.writeText(prompt);
|
||||
showRefreshToast('Full prompt copied to clipboard', 'success');
|
||||
} catch (err) {
|
||||
showRefreshToast('Failed to copy', 'error');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ========== Helpers ==========
|
||||
function formatDuration(ms) {
|
||||
if (ms >= 60000) {
|
||||
|
||||
@@ -6,6 +6,7 @@ let cliToolStatus = { gemini: {}, qwen: {}, codex: {} };
|
||||
let codexLensStatus = { ready: false };
|
||||
let semanticStatus = { available: false };
|
||||
let defaultCliTool = 'gemini';
|
||||
let promptConcatFormat = localStorage.getItem('ccw-prompt-format') || 'plain'; // plain, yaml, json
|
||||
|
||||
// ========== Initialization ==========
|
||||
function initCliStatus() {
|
||||
@@ -207,6 +208,44 @@ function renderCliStatus() {
|
||||
</div>
|
||||
` : '';
|
||||
|
||||
// CLI Settings section
|
||||
const settingsHtml = `
|
||||
<div class="cli-settings-section">
|
||||
<div class="cli-settings-header">
|
||||
<h4><i data-lucide="settings" class="w-3.5 h-3.5"></i> Settings</h4>
|
||||
</div>
|
||||
<div class="cli-settings-grid">
|
||||
<div class="cli-setting-item">
|
||||
<label class="cli-setting-label">
|
||||
<i data-lucide="layers" class="w-3 h-3"></i>
|
||||
Prompt Format
|
||||
</label>
|
||||
<div class="cli-setting-control">
|
||||
<select class="cli-setting-select" onchange="setPromptFormat(this.value)">
|
||||
<option value="plain" ${promptConcatFormat === 'plain' ? 'selected' : ''}>Plain Text</option>
|
||||
<option value="yaml" ${promptConcatFormat === 'yaml' ? 'selected' : ''}>YAML</option>
|
||||
<option value="json" ${promptConcatFormat === 'json' ? 'selected' : ''}>JSON</option>
|
||||
</select>
|
||||
</div>
|
||||
<p class="cli-setting-desc">Format for multi-turn conversation concatenation</p>
|
||||
</div>
|
||||
<div class="cli-setting-item">
|
||||
<label class="cli-setting-label">
|
||||
<i data-lucide="database" class="w-3 h-3"></i>
|
||||
Storage Backend
|
||||
</label>
|
||||
<div class="cli-setting-control">
|
||||
<select class="cli-setting-select" onchange="setStorageBackend(this.value)">
|
||||
<option value="sqlite" ${storageBackend === 'sqlite' ? 'selected' : ''}>SQLite (Recommended)</option>
|
||||
<option value="json" ${storageBackend === 'json' ? 'selected' : ''}>JSON Files</option>
|
||||
</select>
|
||||
</div>
|
||||
<p class="cli-setting-desc">History storage: SQLite for search, JSON for portability</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
|
||||
container.innerHTML = `
|
||||
<div class="cli-status-header">
|
||||
<h3><i data-lucide="terminal" class="w-4 h-4"></i> CLI Tools</h3>
|
||||
@@ -219,6 +258,7 @@ function renderCliStatus() {
|
||||
${codexLensHtml}
|
||||
${semanticHtml}
|
||||
</div>
|
||||
${settingsHtml}
|
||||
`;
|
||||
|
||||
// Initialize Lucide icons
|
||||
@@ -234,6 +274,27 @@ function setDefaultCliTool(tool) {
|
||||
showRefreshToast(`Default CLI tool set to ${tool}`, 'success');
|
||||
}
|
||||
|
||||
function setPromptFormat(format) {
|
||||
promptConcatFormat = format;
|
||||
localStorage.setItem('ccw-prompt-format', format);
|
||||
showRefreshToast(`Prompt format set to ${format.toUpperCase()}`, 'success');
|
||||
}
|
||||
|
||||
function setStorageBackendSetting(backend) {
|
||||
storageBackend = backend;
|
||||
localStorage.setItem('ccw-storage-backend', backend);
|
||||
// Notify server about backend change
|
||||
fetch('/api/cli/settings', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ storageBackend: backend })
|
||||
}).catch(err => console.error('Failed to update backend setting:', err));
|
||||
showRefreshToast(`Storage backend set to ${backend === 'sqlite' ? 'SQLite' : 'JSON'}`, 'success');
|
||||
}
|
||||
|
||||
// Expose to window for select onchange
|
||||
window.setStorageBackend = setStorageBackendSetting;
|
||||
|
||||
async function refreshAllCliStatus() {
|
||||
await Promise.all([loadCliToolStatus(), loadCodexLensStatus()]);
|
||||
renderCliStatus();
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
// CLI History View
|
||||
// Standalone view for CLI execution history with resume support
|
||||
// Standalone view for CLI execution history with batch delete support
|
||||
|
||||
// ========== Multi-Select State ==========
|
||||
var selectedExecutions = new Set();
|
||||
var isMultiSelectMode = false;
|
||||
|
||||
// ========== Rendering ==========
|
||||
async function renderCliHistoryView() {
|
||||
@@ -47,20 +51,32 @@ async function renderCliHistoryView() {
|
||||
exec.status === 'timeout' ? 'warning' : 'error';
|
||||
var duration = formatDuration(exec.duration_ms);
|
||||
var timeAgo = getTimeAgo(new Date(exec.timestamp));
|
||||
var isResume = exec.prompt_preview && exec.prompt_preview.includes('[Resume session');
|
||||
var isSelected = selectedExecutions.has(exec.id);
|
||||
|
||||
// Turn count badge for multi-turn conversations
|
||||
var turnBadge = exec.turn_count && exec.turn_count > 1
|
||||
? '<span class="history-turn-badge"><i data-lucide="messages-square" class="w-3 h-3"></i> ' + exec.turn_count + '</span>'
|
||||
: '';
|
||||
|
||||
var sourceDirHtml = exec.sourceDir && exec.sourceDir !== '.'
|
||||
? '<span class="history-source-dir"><i data-lucide="folder" class="w-3 h-3"></i> ' + escapeHtml(exec.sourceDir) + '</span>'
|
||||
: '';
|
||||
|
||||
var resumeBadge = isResume ? '<span class="history-resume-badge"><i data-lucide="rotate-ccw" class="w-3 h-3"></i></span>' : '';
|
||||
// Multi-select checkbox
|
||||
var checkboxHtml = isMultiSelectMode
|
||||
? '<div class="history-checkbox-wrapper" onclick="event.stopPropagation(); toggleExecutionSelection(\'' + exec.id + '\')">' +
|
||||
'<input type="checkbox" class="history-checkbox" ' + (isSelected ? 'checked' : '') + ' tabindex="-1">' +
|
||||
'</div>'
|
||||
: '';
|
||||
|
||||
historyHtml += '<div class="history-item' + (isResume ? ' history-item-resume' : '') + '" onclick="showExecutionDetail(\'' + exec.id + (exec.sourceDir ? '\',\'' + escapeHtml(exec.sourceDir) : '') + '\')">' +
|
||||
historyHtml += '<div class="history-item' + (isSelected ? ' history-item-selected' : '') + '" ' +
|
||||
'onclick="' + (isMultiSelectMode ? 'toggleExecutionSelection(\'' + exec.id + '\')' : 'showExecutionDetail(\'' + exec.id + (exec.sourceDir ? '\',\'' + escapeHtml(exec.sourceDir) : '') + '\')') + '">' +
|
||||
checkboxHtml +
|
||||
'<div class="history-item-main">' +
|
||||
'<div class="history-item-header">' +
|
||||
'<span class="history-tool-tag tool-' + exec.tool + '">' + exec.tool + '</span>' +
|
||||
'<span class="history-mode-tag">' + (exec.mode || 'analysis') + '</span>' +
|
||||
resumeBadge +
|
||||
turnBadge +
|
||||
sourceDirHtml +
|
||||
'<span class="history-status ' + statusClass + '">' +
|
||||
'<i data-lucide="' + statusIcon + '" class="w-3.5 h-3.5"></i>' +
|
||||
@@ -75,9 +91,6 @@ async function renderCliHistoryView() {
|
||||
'</div>' +
|
||||
'</div>' +
|
||||
'<div class="history-item-actions">' +
|
||||
'<button class="btn-icon btn-resume" onclick="event.stopPropagation(); promptResumeExecution(\'' + exec.id + '\', \'' + exec.tool + '\')" title="Resume">' +
|
||||
'<i data-lucide="play" class="w-4 h-4"></i>' +
|
||||
'</button>' +
|
||||
'<button class="btn-icon" onclick="event.stopPropagation(); showExecutionDetail(\'' + exec.id + '\')" title="View Details">' +
|
||||
'<i data-lucide="eye" class="w-4 h-4"></i>' +
|
||||
'</button>' +
|
||||
@@ -90,6 +103,26 @@ async function renderCliHistoryView() {
|
||||
historyHtml += '</div>';
|
||||
}
|
||||
|
||||
// Build batch actions bar
|
||||
var batchActionsHtml = '';
|
||||
if (isMultiSelectMode) {
|
||||
batchActionsHtml = '<div class="history-batch-actions">' +
|
||||
'<span class="batch-select-count">' + selectedExecutions.size + ' selected</span>' +
|
||||
'<button class="btn btn-sm btn-outline" onclick="selectAllExecutions()">' +
|
||||
'<i data-lucide="check-square" class="w-3.5 h-3.5"></i> Select All' +
|
||||
'</button>' +
|
||||
'<button class="btn btn-sm btn-outline" onclick="clearExecutionSelection()">' +
|
||||
'<i data-lucide="square" class="w-3.5 h-3.5"></i> Clear' +
|
||||
'</button>' +
|
||||
'<button class="btn btn-sm btn-danger" onclick="confirmBatchDelete()" ' + (selectedExecutions.size === 0 ? 'disabled' : '') + '>' +
|
||||
'<i data-lucide="trash-2" class="w-3.5 h-3.5"></i> Delete Selected' +
|
||||
'</button>' +
|
||||
'<button class="btn btn-sm btn-outline" onclick="exitMultiSelectMode()">' +
|
||||
'<i data-lucide="x" class="w-3.5 h-3.5"></i> Cancel' +
|
||||
'</button>' +
|
||||
'</div>';
|
||||
}
|
||||
|
||||
container.innerHTML = '<div class="history-view">' +
|
||||
'<div class="history-header">' +
|
||||
'<div class="history-header-left">' +
|
||||
@@ -108,11 +141,36 @@ async function renderCliHistoryView() {
|
||||
'<option value="qwen"' + (cliHistoryFilter === 'qwen' ? ' selected' : '') + '>Qwen</option>' +
|
||||
'<option value="codex"' + (cliHistoryFilter === 'codex' ? ' selected' : '') + '>Codex</option>' +
|
||||
'</select>' +
|
||||
// Batch delete dropdown
|
||||
'<div class="history-delete-dropdown">' +
|
||||
'<button class="btn-icon" onclick="toggleDeleteDropdown(event)" title="Delete Options">' +
|
||||
'<i data-lucide="trash" class="w-4 h-4"></i>' +
|
||||
'</button>' +
|
||||
'<div class="delete-dropdown-menu" id="deleteDropdownMenu">' +
|
||||
'<button onclick="enterMultiSelectMode()">' +
|
||||
'<i data-lucide="check-square" class="w-3.5 h-3.5"></i> Multi-select Delete' +
|
||||
'</button>' +
|
||||
'<button onclick="confirmDeleteByTool(\'gemini\')">' +
|
||||
'<i data-lucide="trash-2" class="w-3.5 h-3.5"></i> Delete All Gemini' +
|
||||
'</button>' +
|
||||
'<button onclick="confirmDeleteByTool(\'qwen\')">' +
|
||||
'<i data-lucide="trash-2" class="w-3.5 h-3.5"></i> Delete All Qwen' +
|
||||
'</button>' +
|
||||
'<button onclick="confirmDeleteByTool(\'codex\')">' +
|
||||
'<i data-lucide="trash-2" class="w-3.5 h-3.5"></i> Delete All Codex' +
|
||||
'</button>' +
|
||||
'<div class="dropdown-divider"></div>' +
|
||||
'<button class="delete-all-btn" onclick="confirmDeleteAll()">' +
|
||||
'<i data-lucide="alert-triangle" class="w-3.5 h-3.5"></i> Delete All History' +
|
||||
'</button>' +
|
||||
'</div>' +
|
||||
'</div>' +
|
||||
'<button class="btn-icon" onclick="refreshCliHistoryView()" title="Refresh">' +
|
||||
'<i data-lucide="refresh-cw" class="w-4 h-4"></i>' +
|
||||
'</button>' +
|
||||
'</div>' +
|
||||
'</div>' +
|
||||
batchActionsHtml +
|
||||
historyHtml +
|
||||
'</div>';
|
||||
|
||||
@@ -144,79 +202,136 @@ async function refreshCliHistoryView() {
|
||||
showRefreshToast('History refreshed', 'success');
|
||||
}
|
||||
|
||||
// ========== Resume Execution ==========
|
||||
function promptResumeExecution(executionId, tool) {
|
||||
var modalContent = '<div class="resume-modal">' +
|
||||
'<p>Resume this ' + tool + ' session with an optional continuation prompt:</p>' +
|
||||
'<textarea id="resumePromptInput" class="resume-prompt-input" placeholder="Continue from where we left off... (optional)" rows="3"></textarea>' +
|
||||
'<div class="resume-modal-actions">' +
|
||||
'<button class="btn btn-outline" onclick="closeModal()">Cancel</button>' +
|
||||
'<button class="btn btn-primary" onclick="executeResume(\'' + executionId + '\', \'' + tool + '\')">' +
|
||||
'<i data-lucide="play" class="w-4 h-4"></i> Resume' +
|
||||
'</button>' +
|
||||
'</div>' +
|
||||
'</div>';
|
||||
|
||||
showModal('Resume Session', modalContent);
|
||||
// ========== Multi-Select Functions ==========
|
||||
function toggleDeleteDropdown(event) {
|
||||
event.stopPropagation();
|
||||
var menu = document.getElementById('deleteDropdownMenu');
|
||||
if (menu) {
|
||||
menu.classList.toggle('show');
|
||||
// Close on outside click
|
||||
if (menu.classList.contains('show')) {
|
||||
setTimeout(function() {
|
||||
document.addEventListener('click', closeDeleteDropdown);
|
||||
}, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async function executeResume(executionId, tool) {
|
||||
var promptInput = document.getElementById('resumePromptInput');
|
||||
var additionalPrompt = promptInput ? promptInput.value.trim() : 'Continue from previous session';
|
||||
function closeDeleteDropdown() {
|
||||
var menu = document.getElementById('deleteDropdownMenu');
|
||||
if (menu) menu.classList.remove('show');
|
||||
document.removeEventListener('click', closeDeleteDropdown);
|
||||
}
|
||||
|
||||
closeModal();
|
||||
showRefreshToast('Resuming session...', 'info');
|
||||
function enterMultiSelectMode() {
|
||||
closeDeleteDropdown();
|
||||
isMultiSelectMode = true;
|
||||
selectedExecutions.clear();
|
||||
renderCliHistoryView();
|
||||
}
|
||||
|
||||
function exitMultiSelectMode() {
|
||||
isMultiSelectMode = false;
|
||||
selectedExecutions.clear();
|
||||
renderCliHistoryView();
|
||||
}
|
||||
|
||||
function toggleExecutionSelection(executionId) {
|
||||
if (selectedExecutions.has(executionId)) {
|
||||
selectedExecutions.delete(executionId);
|
||||
} else {
|
||||
selectedExecutions.add(executionId);
|
||||
}
|
||||
renderCliHistoryView();
|
||||
}
|
||||
|
||||
function selectAllExecutions() {
|
||||
var filteredHistory = cliHistorySearch
|
||||
? cliExecutionHistory.filter(function(exec) {
|
||||
return exec.prompt_preview.toLowerCase().includes(cliHistorySearch.toLowerCase()) ||
|
||||
exec.tool.toLowerCase().includes(cliHistorySearch.toLowerCase());
|
||||
})
|
||||
: cliExecutionHistory;
|
||||
|
||||
filteredHistory.forEach(function(exec) {
|
||||
selectedExecutions.add(exec.id);
|
||||
});
|
||||
renderCliHistoryView();
|
||||
}
|
||||
|
||||
function clearExecutionSelection() {
|
||||
selectedExecutions.clear();
|
||||
renderCliHistoryView();
|
||||
}
|
||||
|
||||
// ========== Batch Delete Functions ==========
|
||||
function confirmBatchDelete() {
|
||||
var count = selectedExecutions.size;
|
||||
if (count === 0) return;
|
||||
|
||||
if (confirm('Delete ' + count + ' selected execution' + (count > 1 ? 's' : '') + '? This action cannot be undone.')) {
|
||||
batchDeleteExecutions(Array.from(selectedExecutions));
|
||||
}
|
||||
}
|
||||
|
||||
function confirmDeleteByTool(tool) {
|
||||
closeDeleteDropdown();
|
||||
var toolExecutions = cliExecutionHistory.filter(function(exec) { return exec.tool === tool; });
|
||||
var count = toolExecutions.length;
|
||||
|
||||
if (count === 0) {
|
||||
showRefreshToast('No ' + tool + ' executions to delete', 'info');
|
||||
return;
|
||||
}
|
||||
|
||||
if (confirm('Delete all ' + count + ' ' + tool + ' execution' + (count > 1 ? 's' : '') + '? This action cannot be undone.')) {
|
||||
var ids = toolExecutions.map(function(exec) { return exec.id; });
|
||||
batchDeleteExecutions(ids);
|
||||
}
|
||||
}
|
||||
|
||||
function confirmDeleteAll() {
|
||||
closeDeleteDropdown();
|
||||
var count = cliExecutionHistory.length;
|
||||
|
||||
if (count === 0) {
|
||||
showRefreshToast('No executions to delete', 'info');
|
||||
return;
|
||||
}
|
||||
|
||||
if (confirm('Delete ALL ' + count + ' execution' + (count > 1 ? 's' : '') + '? This action cannot be undone.')) {
|
||||
var ids = cliExecutionHistory.map(function(exec) { return exec.id; });
|
||||
batchDeleteExecutions(ids);
|
||||
}
|
||||
}
|
||||
|
||||
async function batchDeleteExecutions(ids) {
|
||||
showRefreshToast('Deleting ' + ids.length + ' executions...', 'info');
|
||||
|
||||
try {
|
||||
var response = await fetch('/api/cli/execute', {
|
||||
var response = await fetch('/api/cli/batch-delete', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({
|
||||
tool: tool,
|
||||
prompt: additionalPrompt,
|
||||
resume: executionId // execution ID to resume from
|
||||
path: projectPath,
|
||||
ids: ids
|
||||
})
|
||||
});
|
||||
|
||||
var result = await response.json();
|
||||
|
||||
if (result.success) {
|
||||
showRefreshToast('Session resumed successfully', 'success');
|
||||
// Refresh history to show new execution
|
||||
await refreshCliHistoryView();
|
||||
showRefreshToast('Deleted ' + result.deleted + ' execution' + (result.deleted > 1 ? 's' : ''), 'success');
|
||||
// Exit multi-select mode and refresh
|
||||
isMultiSelectMode = false;
|
||||
selectedExecutions.clear();
|
||||
await loadCliHistory();
|
||||
renderCliHistoryView();
|
||||
} else {
|
||||
showRefreshToast('Resume failed: ' + (result.error || 'Unknown error'), 'error');
|
||||
showRefreshToast('Delete failed: ' + (result.error || 'Unknown error'), 'error');
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('Resume failed:', err);
|
||||
showRefreshToast('Resume failed: ' + err.message, 'error');
|
||||
}
|
||||
}
|
||||
|
||||
async function resumeLastSession(tool) {
|
||||
showRefreshToast('Resuming last ' + (tool || '') + ' session...', 'info');
|
||||
|
||||
try {
|
||||
var response = await fetch('/api/cli/execute', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({
|
||||
tool: tool || 'gemini',
|
||||
prompt: 'Continue from previous session',
|
||||
resume: true // true = resume last session
|
||||
})
|
||||
});
|
||||
|
||||
var result = await response.json();
|
||||
|
||||
if (result.success) {
|
||||
showRefreshToast('Session resumed successfully', 'success');
|
||||
await refreshCliHistoryView();
|
||||
} else {
|
||||
showRefreshToast('Resume failed: ' + (result.error || 'Unknown error'), 'error');
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('Resume failed:', err);
|
||||
showRefreshToast('Resume failed: ' + err.message, 'error');
|
||||
console.error('Batch delete failed:', err);
|
||||
showRefreshToast('Delete failed: ' + err.message, 'error');
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user