From 550e525554c40c60ec8b8e413173627744922c5a Mon Sep 17 00:00:00 2001 From: iven Date: Fri, 10 Apr 2026 23:24:32 +0800 Subject: [PATCH] =?UTF-8?q?fix(ui):=20=E5=AE=A1=E8=AE=A1=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=20=E2=80=94=20=E8=B7=AF=E5=BE=84=E8=A7=84=E8=8C=83=E5=8C=96/Sk?= =?UTF-8?q?illInfo=E7=B1=BB=E5=9E=8B/=E5=88=86=E9=A1=B5offset/=E5=88=9D?= =?UTF-8?q?=E5=A7=8B=E5=8A=A0=E8=BD=BD/=E6=98=BE=E7=A4=BA=E7=BB=9F?= =?UTF-8?q?=E4=B8=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - workspace.rs: canonicalize() 解析 '..' 和符号链接 - Workspace.tsx: 组件挂载时调用 loadDirStats + 统一 KB 显示 - configStore: SkillInfo 接口补充 category 字段 + 空数组回退注释 - securityStore: localStorage 审计日志添加 offset 分页支持 --- desktop/src-tauri/src/kernel_commands/workspace.rs | 9 ++++++--- desktop/src/components/Settings/Workspace.tsx | 8 +++++--- desktop/src/store/configStore.ts | 3 +++ desktop/src/store/securityStore.ts | 7 ++++--- 4 files changed, 18 insertions(+), 9 deletions(-) diff --git a/desktop/src-tauri/src/kernel_commands/workspace.rs b/desktop/src-tauri/src/kernel_commands/workspace.rs index e12f08f..cf3774c 100644 --- a/desktop/src-tauri/src/kernel_commands/workspace.rs +++ b/desktop/src-tauri/src/kernel_commands/workspace.rs @@ -13,20 +13,23 @@ pub struct DirStats { #[tauri::command] pub async fn workspace_dir_stats(path: String) -> Result { let dir = Path::new(&path); - if !dir.exists() { + + // Canonicalize to resolve '..' components and symlinks + let canonical = dir.canonicalize().unwrap_or_else(|_| dir.to_path_buf()); + if !canonical.exists() { return Ok(DirStats { file_count: 0, total_size: 0, }); } - if !dir.is_dir() { + if !canonical.is_dir() { return Err(format!("{} is not a directory", path)); } let mut file_count: u64 = 0; let mut total_size: u64 = 0; - let entries = std::fs::read_dir(dir).map_err(|e| format!("Failed to read dir: {}", e))?; + let entries = std::fs::read_dir(&canonical).map_err(|e| format!("Failed to read dir: {}", e))?; for entry in entries.flatten() { if let Ok(metadata) = entry.metadata() { if metadata.is_file() { diff --git a/desktop/src/components/Settings/Workspace.tsx b/desktop/src/components/Settings/Workspace.tsx index 997677e..8103dba 100644 --- a/desktop/src/components/Settings/Workspace.tsx +++ b/desktop/src/components/Settings/Workspace.tsx @@ -26,7 +26,9 @@ export function Workspace() { }, []); useEffect(() => { - setProjectDir(quickConfig.workspaceDir || workspaceInfo?.path || '~/.zclaw/zclaw-workspace'); + const dir = quickConfig.workspaceDir || workspaceInfo?.path || '~/.zclaw/zclaw-workspace'; + setProjectDir(dir); + loadDirStats(dir); }, [quickConfig.workspaceDir, workspaceInfo?.path]); const handleWorkspaceBlur = async () => { @@ -86,8 +88,8 @@ export function Workspace() {
当前解析路径:{workspaceInfo?.resolvedPath || projectDir}
文件数:{dirStats?.fileCount ?? workspaceInfo?.fileCount ?? 0} - {dirStats && `,大小:${(dirStats.totalSize / 1024).toFixed(1)} KB`} - {!dirStats && workspaceInfo?.totalSize ? `,大小:${workspaceInfo.totalSize} bytes` : ''} + {((dirStats?.totalSize ?? workspaceInfo?.totalSize ?? 0) > 0) && + `,大小:${(((dirStats?.totalSize ?? workspaceInfo?.totalSize) ?? 0) / 1024).toFixed(1)} KB`}
diff --git a/desktop/src/store/configStore.ts b/desktop/src/store/configStore.ts index 3a2b4b4..4151bab 100644 --- a/desktop/src/store/configStore.ts +++ b/desktop/src/store/configStore.ts @@ -81,6 +81,7 @@ export interface SkillInfo { capabilities?: string[]; tags?: string[]; mode?: string; + category?: string; triggers?: Array<{ type: string; pattern?: string }>; actions?: Array<{ type: string; params?: Record }>; enabled?: boolean; @@ -455,6 +456,8 @@ export const useConfigStore = create((set if (client) { try { const result = await client.listSkills(); + // Empty array from client may indicate connected-but-load-failure; + // fall through to direct Tauri invoke as recovery path if (result?.skills && result.skills.length > 0) { set({ skillsCatalog: result.skills }); if (result.extraDirs) { diff --git a/desktop/src/store/securityStore.ts b/desktop/src/store/securityStore.ts index 91fb3ef..ed367f7 100644 --- a/desktop/src/store/securityStore.ts +++ b/desktop/src/store/securityStore.ts @@ -309,10 +309,11 @@ export const useSecurityStore = create((set, get) => ({ })); } - // Sort by timestamp descending and apply limit + // Sort by timestamp descending and apply pagination allLogs.sort((a, b) => new Date(b.timestamp).getTime() - new Date(a.timestamp).getTime()); - const limited = opts?.limit ? allLogs.slice(0, opts.limit) : allLogs; - set({ auditLogs: limited, auditLogsLoading: false }); + const offset = opts?.offset ?? 0; + const paginated = opts?.limit ? allLogs.slice(offset, offset + opts.limit) : allLogs.slice(offset); + set({ auditLogs: paginated, auditLogsLoading: false }); } catch { set({ auditLogsLoading: false }); }