feat(dashboard): CLI settings UI and Smart Context support

- Add CLI Settings section with Prompt Format selector
- Add Smart Context toggle and Max Files dropdown
- Update smart-search with output_mode (full/files_only/count)
- Add smart-context module for keyword extraction
- Improve Status page styling (remove card wrappers)
- Add i18n translations for new settings

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
catlog22
2025-12-13 17:28:39 +08:00
parent 675aff26ff
commit 32217f87fd
7 changed files with 500 additions and 57 deletions

View File

@@ -8,6 +8,10 @@ let semanticStatus = { available: false };
let defaultCliTool = 'gemini';
let promptConcatFormat = localStorage.getItem('ccw-prompt-format') || 'plain'; // plain, yaml, json
// Smart Context settings
let smartContextEnabled = localStorage.getItem('ccw-smart-context') === 'true';
let smartContextMaxFiles = parseInt(localStorage.getItem('ccw-smart-context-max-files') || '10', 10);
// ========== Initialization ==========
function initCliStatus() {
// Load CLI status on init
@@ -235,12 +239,36 @@ function renderCliStatus() {
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>
<span class="cli-setting-value">SQLite</span>
</div>
<p class="cli-setting-desc">CLI history stored in SQLite with FTS search</p>
</div>
<div class="cli-setting-item">
<label class="cli-setting-label">
<i data-lucide="sparkles" class="w-3 h-3"></i>
Smart Context
</label>
<div class="cli-setting-control">
<label class="cli-toggle">
<input type="checkbox" ${smartContextEnabled ? 'checked' : ''} onchange="setSmartContextEnabled(this.checked)">
<span class="cli-toggle-slider"></span>
</label>
</div>
<p class="cli-setting-desc">Auto-analyze prompt and add relevant file paths</p>
</div>
<div class="cli-setting-item ${!smartContextEnabled ? 'disabled' : ''}">
<label class="cli-setting-label">
<i data-lucide="files" class="w-3 h-3"></i>
Max Context Files
</label>
<div class="cli-setting-control">
<select class="cli-setting-select" onchange="setSmartContextMaxFiles(this.value)" ${!smartContextEnabled ? 'disabled' : ''}>
<option value="5" ${smartContextMaxFiles === 5 ? 'selected' : ''}>5 files</option>
<option value="10" ${smartContextMaxFiles === 10 ? 'selected' : ''}>10 files</option>
<option value="20" ${smartContextMaxFiles === 20 ? 'selected' : ''}>20 files</option>
</select>
</div>
<p class="cli-setting-desc">History storage: SQLite for search, JSON for portability</p>
<p class="cli-setting-desc">Maximum files to include in smart context</p>
</div>
</div>
</div>
@@ -280,20 +308,23 @@ function setPromptFormat(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');
function setSmartContextEnabled(enabled) {
smartContextEnabled = enabled;
localStorage.setItem('ccw-smart-context', enabled.toString());
// Re-render the appropriate settings panel
if (typeof renderCliSettingsSection === 'function') {
renderCliSettingsSection();
} else {
renderCliStatus();
}
showRefreshToast(`Smart Context ${enabled ? 'enabled' : 'disabled'}`, 'success');
}
// Expose to window for select onchange
window.setStorageBackend = setStorageBackendSetting;
function setSmartContextMaxFiles(max) {
smartContextMaxFiles = parseInt(max, 10);
localStorage.setItem('ccw-smart-context-max-files', max);
showRefreshToast(`Smart Context max files set to ${max}`, 'success');
}
async function refreshAllCliStatus() {
await Promise.all([loadCliToolStatus(), loadCodexLensStatus()]);

View File

@@ -200,6 +200,15 @@ const i18n = {
'cli.codexLensDescFull': 'Full-text code search engine',
'cli.semanticDesc': 'AI-powered code understanding',
'cli.semanticDescFull': 'Natural language code search',
'cli.settings': 'CLI Execution Settings',
'cli.promptFormat': 'Prompt Format',
'cli.promptFormatDesc': 'Format for multi-turn conversation concatenation',
'cli.storageBackend': 'Storage Backend',
'cli.storageBackendDesc': 'CLI history stored in SQLite with FTS search',
'cli.smartContext': 'Smart Context',
'cli.smartContextDesc': 'Auto-analyze prompt and add relevant file paths',
'cli.maxContextFiles': 'Max Context Files',
'cli.maxContextFilesDesc': 'Maximum files to include in smart context',
// CCW Install
'ccw.install': 'CCW Install',
@@ -711,6 +720,15 @@ const i18n = {
'cli.codexLensDescFull': '全文代码搜索引擎',
'cli.semanticDesc': 'AI 驱动的代码理解',
'cli.semanticDescFull': '自然语言代码搜索',
'cli.settings': 'CLI 调用设置',
'cli.promptFormat': '提示词格式',
'cli.promptFormatDesc': '多轮对话拼接格式',
'cli.storageBackend': '存储后端',
'cli.storageBackendDesc': 'CLI 历史使用 SQLite 存储,支持全文搜索',
'cli.smartContext': '智能上下文',
'cli.smartContextDesc': '自动分析提示词并添加相关文件路径',
'cli.maxContextFiles': '最大上下文文件数',
'cli.maxContextFilesDesc': '智能上下文包含的最大文件数',
// CCW Install
'ccw.install': 'CCW 安装',