Skip to content

Commit 5c34709

Browse files
committed
```
feat(index): 优化索引面板UI样式并增强路径规范化处理 - 为ZhiIndexPanel组件添加最小高度约束,优化布局稳定性 - 改进header区域的flex布局,支持换行显示 - 调整统计卡片网格布局为固定4列,提升视觉一致性 - 更新统计卡片颜色主题,使用更柔和的色调 - 增加元素间距,改善界面呼吸感 - 重构purge_project_index_records函数,增强错误处理机制 - 添加路径规范化功能,提高路径匹配准确性 - 优化JSON文件读写逻辑,增加解析失败时的恢复机制 - 改进日志输出,提供更详细的调试信息 - 修复全量重建时索引清理失败的错误提示问题 ```
1 parent f6d1dd7 commit 5c34709

File tree

2 files changed

+75
-34
lines changed

2 files changed

+75
-34
lines changed

src/frontend/components/popup/ZhiIndexPanel.vue

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,7 @@ function handleOpenDetail() {
350350
align-items: center;
351351
justify-content: space-between;
352352
padding: 10px 14px;
353+
min-height: 40px;
353354
cursor: pointer;
354355
transition: background 0.2s;
355356
}
@@ -361,7 +362,9 @@ function handleOpenDetail() {
361362
.header-left {
362363
display: flex;
363364
align-items: center;
365+
flex-wrap: wrap;
364366
gap: 6px;
367+
row-gap: 4px;
365368
font-size: 12px;
366369
}
367370
@@ -403,12 +406,13 @@ function handleOpenDetail() {
403406
.panel-content {
404407
padding: 0 14px 14px;
405408
border-top: 1px solid rgba(255, 255, 255, 0.06);
409+
min-height: 120px;
406410
}
407411
408412
/* 统计卡片网格 */
409413
.stats-grid {
410414
display: grid;
411-
grid-template-columns: repeat(auto-fit, minmax(60px, 1fr));
415+
grid-template-columns: repeat(4, minmax(0, 1fr));
412416
gap: 8px;
413417
margin-top: 12px;
414418
}
@@ -424,15 +428,15 @@ function handleOpenDetail() {
424428
}
425429
426430
.stat-card--success .stat-value {
427-
color: #4ade80;
431+
color: #86efac;
428432
}
429433
430434
.stat-card--info .stat-value {
431-
color: #60a5fa;
435+
color: #93c5fd;
432436
}
433437
434438
.stat-card--error .stat-value {
435-
color: #f87171;
439+
color: #fca5a5;
436440
}
437441
438442
.stat-value {
@@ -453,6 +457,7 @@ function handleOpenDetail() {
453457
display: flex;
454458
align-items: center;
455459
justify-content: space-between;
460+
gap: 12px;
456461
margin-top: 12px;
457462
padding-top: 10px;
458463
border-top: 1px solid rgba(255, 255, 255, 0.06);

src/rust/mcp/tools/acemcp/commands.rs

Lines changed: 66 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -603,7 +603,8 @@ pub async fn trigger_acemcp_index_update(project_root_path: String) -> Result<St
603603
pub async fn trigger_acemcp_index_rebuild(project_root_path: String) -> Result<String, String> {
604604
// 先清理本地索引记录(projects.json + projects_status.json)
605605
// 全量重建不主动停止文件监听,避免影响自动索引
606-
purge_project_index_records(&project_root_path, false)?;
606+
purge_project_index_records(&project_root_path, false)
607+
.map_err(|e| format!("全量重建前清理索引记录失败: {}", e))?;
607608

608609
// 再触发索引更新(全量重建)
609610
AcemcpTool::trigger_index_update(project_root_path)
@@ -703,6 +704,10 @@ pub fn stop_all_watching() -> Result<(), String> {
703704
// 辅助函数:规范化路径 key(去除扩展路径前缀,统一使用正斜杠)
704705
fn normalize_path_key(path: &str) -> String {
705706
let mut normalized = path.to_string();
707+
// 尝试规范化路径(失败则保持原样)
708+
if let Ok(canon) = std::path::PathBuf::from(path).canonicalize() {
709+
normalized = canon.to_string_lossy().to_string();
710+
}
706711
// 去除 Windows 扩展长度路径前缀
707712
if normalized.starts_with("\\\\?\\") {
708713
normalized = normalized[4..].to_string();
@@ -736,8 +741,19 @@ fn purge_project_index_records(project_root_path: &str, stop_watching: bool) ->
736741
// 1. 从 projects.json 中删除项目的 blob 列表
737742
let projects_path = data_dir.join("projects.json");
738743
if projects_path.exists() {
739-
if let Ok(data) = fs::read_to_string(&projects_path) {
740-
if let Ok(mut projects) = serde_json::from_str::<HashMap<String, Vec<String>>>(&data) {
744+
match fs::read_to_string(&projects_path) {
745+
Ok(data) => {
746+
let mut needs_write = false;
747+
let mut projects: HashMap<String, Vec<String>> = match serde_json::from_str(&data) {
748+
Ok(val) => val,
749+
Err(e) => {
750+
log::warn!("[purge_project_index_records] projects.json 解析失败,将重置文件: {}", e);
751+
needs_write = true;
752+
projects_deleted = true;
753+
HashMap::new()
754+
}
755+
};
756+
741757
let existing_keys: Vec<&String> = projects.keys().collect();
742758
log::info!("[purge_project_index_records] projects.json 中现有项目: {:?}", existing_keys);
743759

@@ -748,14 +764,23 @@ fn purge_project_index_records(project_root_path: &str, stop_watching: bool) ->
748764
if let Some(key) = key_to_remove {
749765
log::info!("[purge_project_index_records] 找到匹配的 key: {}", key);
750766
projects.remove(&key);
751-
if let Ok(new_data) = serde_json::to_string_pretty(&projects) {
752-
let _ = fs::write(&projects_path, new_data);
753-
log::info!("[purge_project_index_records] ✓ 已从 projects.json 删除项目: {}", key);
754-
projects_deleted = true;
755-
}
767+
needs_write = true;
768+
projects_deleted = true;
769+
} else if needs_write {
770+
log::warn!("[purge_project_index_records] 未找到匹配项目,但 projects.json 已被重置");
756771
} else {
757772
log::warn!("[purge_project_index_records] ✗ 在 projects.json 中未找到匹配的项目,规范化路径: {}", normalized_root);
758773
}
774+
775+
if needs_write {
776+
let new_data = serde_json::to_string_pretty(&projects)
777+
.map_err(|e| format!("序列化 projects.json 失败: {} (路径: {})", e, projects_path.display()))?;
778+
fs::write(&projects_path, new_data)
779+
.map_err(|e| format!("写入 projects.json 失败: {} (路径: {})", e, projects_path.display()))?;
780+
}
781+
}
782+
Err(e) => {
783+
return Err(format!("读取 projects.json 失败: {} (路径: {})", e, projects_path.display()));
759784
}
760785
}
761786
} else {
@@ -765,31 +790,42 @@ fn purge_project_index_records(project_root_path: &str, stop_watching: bool) ->
765790
// 2. 从 projects_status.json 中删除项目状态
766791
let status_path = data_dir.join("projects_status.json");
767792
if status_path.exists() {
768-
if let Ok(data) = fs::read_to_string(&status_path) {
769-
if let Ok(mut status) = serde_json::from_str::<serde_json::Value>(&data) {
770-
if let Some(projects) = status.get_mut("projects") {
771-
if let Some(map) = projects.as_object_mut() {
772-
let existing_keys: Vec<&String> = map.keys().collect();
773-
log::info!("[purge_project_index_records] projects_status.json 中现有项目: {:?}", existing_keys);
774-
775-
let key_to_remove: Option<String> = map.keys()
776-
.find(|k| normalize_path_key(k) == normalized_root)
777-
.cloned();
778-
779-
if let Some(key) = key_to_remove {
780-
log::info!("[purge_project_index_records] 找到匹配的 key: {}", key);
781-
map.remove(&key);
782-
if let Ok(new_data) = serde_json::to_string_pretty(&status) {
783-
let _ = fs::write(&status_path, new_data);
784-
log::info!("[purge_project_index_records] ✓ 已从 projects_status.json 删除项目: {}", key);
785-
status_deleted = true;
786-
}
787-
} else {
788-
log::warn!("[purge_project_index_records] ✗ 在 projects_status.json 中未找到匹配的项目,规范化路径: {}", normalized_root);
789-
}
793+
match fs::read_to_string(&status_path) {
794+
Ok(data) => {
795+
let mut needs_write = false;
796+
let mut status: ProjectsIndexStatus = match serde_json::from_str(&data) {
797+
Ok(val) => val,
798+
Err(e) => {
799+
log::warn!("[purge_project_index_records] projects_status.json 解析失败,将重置文件: {}", e);
800+
needs_write = true;
801+
status_deleted = true;
802+
ProjectsIndexStatus::default()
790803
}
804+
};
805+
806+
let existing_keys: Vec<&String> = status.projects.keys().collect();
807+
log::info!("[purge_project_index_records] projects_status.json 中现有项目: {:?}", existing_keys);
808+
809+
if status.projects.remove(&normalized_root).is_some() {
810+
needs_write = true;
811+
status_deleted = true;
812+
log::info!("[purge_project_index_records] ✓ 已从 projects_status.json 删除项目: {}", normalized_root);
813+
} else if needs_write {
814+
log::warn!("[purge_project_index_records] 未找到匹配项目,但 projects_status.json 已被重置");
815+
} else {
816+
log::warn!("[purge_project_index_records] ✗ 在 projects_status.json 中未找到匹配的项目,规范化路径: {}", normalized_root);
817+
}
818+
819+
if needs_write {
820+
let new_data = serde_json::to_string_pretty(&status)
821+
.map_err(|e| format!("序列化 projects_status.json 失败: {} (路径: {})", e, status_path.display()))?;
822+
fs::write(&status_path, new_data)
823+
.map_err(|e| format!("写入 projects_status.json 失败: {} (路径: {})", e, status_path.display()))?;
791824
}
792825
}
826+
Err(e) => {
827+
return Err(format!("读取 projects_status.json 失败: {} (路径: {})", e, status_path.display()));
828+
}
793829
}
794830
} else {
795831
log::warn!("[purge_project_index_records] projects_status.json 文件不存在: {:?}", status_path);

0 commit comments

Comments
 (0)