feat: Enhance CodexLens indexing and search capabilities with new CLI options and improved error handling

This commit is contained in:
catlog22
2025-12-19 15:10:37 +08:00
parent c7ced2bfbb
commit 2f0cce0089
18 changed files with 480 additions and 128 deletions

View File

@@ -177,11 +177,20 @@ function renderIndexCard() {
</table>
</div>
<div class="mt-4 flex justify-between items-center gap-2">
<button onclick="initCodexLensIndex()"
class="text-xs px-3 py-1.5 bg-primary/10 text-primary hover:bg-primary/20 rounded transition-colors flex items-center gap-1.5">
<i data-lucide="database" class="w-3.5 h-3.5"></i>
${t('index.initCurrent') || 'Init Current Project'}
</button>
<div class="flex items-center gap-2">
<button onclick="initCodexLensIndex('vector')"
class="text-xs px-3 py-1.5 bg-primary/10 text-primary hover:bg-primary/20 rounded transition-colors flex items-center gap-1.5"
title="${t('index.vectorDesc') || 'Semantic search with embeddings'}">
<i data-lucide="sparkles" class="w-3.5 h-3.5"></i>
${t('index.vectorIndex') || 'Vector'}
</button>
<button onclick="initCodexLensIndex('normal')"
class="text-xs px-3 py-1.5 bg-muted text-muted-foreground hover:bg-muted/80 rounded transition-colors flex items-center gap-1.5"
title="${t('index.normalDesc') || 'Fast full-text search only'}">
<i data-lucide="file-text" class="w-3.5 h-3.5"></i>
${t('index.normalIndex') || 'FTS'}
</button>
</div>
<button onclick="cleanAllIndexesConfirm()"
class="text-xs px-3 py-1.5 bg-destructive/10 text-destructive hover:bg-destructive/20 rounded transition-colors flex items-center gap-1.5">
<i data-lucide="trash" class="w-3.5 h-3.5"></i>

View File

@@ -322,6 +322,10 @@ const i18n = {
'index.cleanFailed': 'Clean failed',
'index.cleanAllConfirm': 'Are you sure you want to clean ALL indexes? This cannot be undone.',
'index.cleanAllSuccess': 'All indexes cleaned',
'index.vectorIndex': 'Vector',
'index.normalIndex': 'FTS',
'index.vectorDesc': 'Semantic search with embeddings',
'index.normalDesc': 'Fast full-text search only',
// Semantic Search Configuration
'semantic.settings': 'Semantic Search Settings',
@@ -343,6 +347,12 @@ const i18n = {
'lang.disableSuccess': 'Chinese response disabled',
'lang.enableFailed': 'Failed to enable Chinese response',
'lang.disableFailed': 'Failed to disable Chinese response',
'lang.windows': 'Windows Platform',
'lang.windowsDesc': 'Enable Windows path format guidelines in global CLAUDE.md',
'lang.windowsEnableSuccess': 'Windows platform guidelines enabled',
'lang.windowsDisableSuccess': 'Windows platform guidelines disabled',
'lang.windowsEnableFailed': 'Failed to enable Windows platform guidelines',
'lang.windowsDisableFailed': 'Failed to disable Windows platform guidelines',
'cli.promptFormat': 'Prompt Format',
'cli.promptFormatDesc': 'Format for multi-turn conversation concatenation',
'cli.storageBackend': 'Storage Backend',
@@ -1597,6 +1607,10 @@ const i18n = {
'index.cleanFailed': '清理失败',
'index.cleanAllConfirm': '确定要清理所有索引吗?此操作无法撤销。',
'index.cleanAllSuccess': '所有索引已清理',
'index.vectorIndex': '向量索引',
'index.normalIndex': '全文索引',
'index.vectorDesc': '语义搜索(含嵌入向量)',
'index.normalDesc': '快速全文搜索',
// Semantic Search 配置
'semantic.settings': '语义搜索设置',
@@ -1618,6 +1632,12 @@ const i18n = {
'lang.disableSuccess': '中文回复已禁用',
'lang.enableFailed': '启用中文回复失败',
'lang.disableFailed': '禁用中文回复失败',
'lang.windows': 'Windows 平台规范',
'lang.windowsDesc': '在全局 CLAUDE.md 中启用 Windows 路径格式规范',
'lang.windowsEnableSuccess': 'Windows 平台规范已启用',
'lang.windowsDisableSuccess': 'Windows 平台规范已禁用',
'lang.windowsEnableFailed': '启用 Windows 平台规范失败',
'lang.windowsDisableFailed': '禁用 Windows 平台规范失败',
'cli.promptFormat': '提示词格式',
'cli.promptFormatDesc': '多轮对话拼接格式',
'cli.storageBackend': '存储后端',

View File

@@ -512,6 +512,8 @@ function renderCcwSection() {
// ========== Language Settings State ==========
var chineseResponseEnabled = false;
var chineseResponseLoading = false;
var windowsPlatformEnabled = false;
var windowsPlatformLoading = false;
// ========== Language Settings Section ==========
async function loadLanguageSettings() {
@@ -528,6 +530,20 @@ async function loadLanguageSettings() {
}
}
async function loadWindowsPlatformSettings() {
try {
var response = await fetch('/api/language/windows-platform');
if (!response.ok) throw new Error('Failed to load Windows platform settings');
var data = await response.json();
windowsPlatformEnabled = data.enabled || false;
return data;
} catch (err) {
console.error('Failed to load Windows platform settings:', err);
windowsPlatformEnabled = false;
return { enabled: false, guidelinesExists: false };
}
}
async function toggleChineseResponse(enabled) {
if (chineseResponseLoading) return;
chineseResponseLoading = true;
@@ -560,6 +576,38 @@ async function toggleChineseResponse(enabled) {
}
}
async function toggleWindowsPlatform(enabled) {
if (windowsPlatformLoading) return;
windowsPlatformLoading = true;
try {
var response = await fetch('/api/language/windows-platform', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ enabled: enabled })
});
if (!response.ok) {
var errData = await response.json();
throw new Error(errData.error || 'Failed to update setting');
}
var data = await response.json();
windowsPlatformEnabled = data.enabled;
// Update UI
renderLanguageSettingsSection();
// Show toast
showRefreshToast(enabled ? t('lang.windowsEnableSuccess') : t('lang.windowsDisableSuccess'), 'success');
} catch (err) {
console.error('Failed to toggle Windows platform:', err);
showRefreshToast(enabled ? t('lang.windowsEnableFailed') : t('lang.windowsDisableFailed'), 'error');
} finally {
windowsPlatformLoading = false;
}
}
async function renderLanguageSettingsSection() {
var container = document.getElementById('language-settings-section');
if (!container) return;
@@ -568,13 +616,16 @@ async function renderLanguageSettingsSection() {
if (!chineseResponseEnabled && !chineseResponseLoading) {
await loadLanguageSettings();
}
if (!windowsPlatformEnabled && !windowsPlatformLoading) {
await loadWindowsPlatformSettings();
}
var settingsHtml = '<div class="section-header">' +
'<div class="section-header-left">' +
'<h3><i data-lucide="languages" class="w-4 h-4"></i> ' + t('lang.settings') + '</h3>' +
'</div>' +
'</div>' +
'<div class="cli-settings-grid" style="grid-template-columns: 1fr;">' +
'<div class="cli-settings-grid" style="grid-template-columns: 1fr 1fr;">' +
'<div class="cli-setting-item">' +
'<label class="cli-setting-label">' +
'<i data-lucide="message-square-text" class="w-3 h-3"></i>' +
@@ -591,6 +642,22 @@ async function renderLanguageSettingsSection() {
'</div>' +
'<p class="cli-setting-desc">' + t('lang.chineseDesc') + '</p>' +
'</div>' +
'<div class="cli-setting-item">' +
'<label class="cli-setting-label">' +
'<i data-lucide="monitor" class="w-3 h-3"></i>' +
t('lang.windows') +
'</label>' +
'<div class="cli-setting-control">' +
'<label class="cli-toggle">' +
'<input type="checkbox"' + (windowsPlatformEnabled ? ' checked' : '') + ' onchange="toggleWindowsPlatform(this.checked)"' + (windowsPlatformLoading ? ' disabled' : '') + '>' +
'<span class="cli-toggle-slider"></span>' +
'</label>' +
'<span class="cli-setting-status ' + (windowsPlatformEnabled ? 'enabled' : 'disabled') + '">' +
(windowsPlatformEnabled ? t('lang.enabled') : t('lang.disabled')) +
'</span>' +
'</div>' +
'<p class="cli-setting-desc">' + t('lang.windowsDesc') + '</p>' +
'</div>' +
'</div>';
container.innerHTML = settingsHtml;

View File

@@ -554,8 +554,11 @@ async function deleteModel(profile) {
/**
* Initialize CodexLens index with bottom floating progress bar
* @param {string} indexType - 'vector' (with embeddings) or 'normal' (FTS only)
*/
function initCodexLensIndex() {
function initCodexLensIndex(indexType) {
indexType = indexType || 'vector';
// Remove existing progress bar if any
closeCodexLensIndexModal();
@@ -563,6 +566,7 @@ function initCodexLensIndex() {
var progressBar = document.createElement('div');
progressBar.id = 'codexlensIndexFloating';
progressBar.className = 'fixed bottom-0 left-0 right-0 z-50 bg-card border-t border-border shadow-lg transform transition-transform duration-300';
var indexTypeLabel = indexType === 'vector' ? 'Vector' : 'FTS';
progressBar.innerHTML =
'<div class="max-w-4xl mx-auto px-4 py-3">' +
'<div class="flex items-center justify-between gap-4">' +
@@ -570,7 +574,7 @@ function initCodexLensIndex() {
'<div class="animate-spin w-5 h-5 border-2 border-primary border-t-transparent rounded-full flex-shrink-0" id="codexlensIndexSpinner"></div>' +
'<div class="flex-1 min-w-0">' +
'<div class="flex items-center gap-2">' +
'<span class="font-medium text-sm">' + t('codexlens.indexing') + '</span>' +
'<span class="font-medium text-sm">' + t('codexlens.indexing') + ' (' + indexTypeLabel + ')</span>' +
'<span class="text-xs text-muted-foreground" id="codexlensIndexPercent">0%</span>' +
'</div>' +
'<div class="text-xs text-muted-foreground truncate" id="codexlensIndexStatus">' + t('codexlens.preparingIndex') + '</div>' +
@@ -590,14 +594,16 @@ function initCodexLensIndex() {
document.body.appendChild(progressBar);
if (window.lucide) lucide.createIcons();
// Start indexing
startCodexLensIndexing();
// Start indexing with specified type
startCodexLensIndexing(indexType);
}
/**
* Start the indexing process
* @param {string} indexType - 'vector' or 'normal'
*/
async function startCodexLensIndexing() {
async function startCodexLensIndexing(indexType) {
indexType = indexType || 'vector';
var statusText = document.getElementById('codexlensIndexStatus');
var progressBar = document.getElementById('codexlensIndexProgressBar');
var percentText = document.getElementById('codexlensIndexPercent');
@@ -629,11 +635,11 @@ async function startCodexLensIndexing() {
}
try {
console.log('[CodexLens] Starting index for:', projectPath);
console.log('[CodexLens] Starting index for:', projectPath, 'type:', indexType);
var response = await fetch('/api/codexlens/init', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ path: projectPath })
body: JSON.stringify({ path: projectPath, indexType: indexType })
});
var result = await response.json();