mirror of
https://github.com/aiclientproxy/proxycast.git
synced 2026-09-24 23:10:56 +08:00
fix: 构建 workspace 目录 4 层健康防护体系,彻底解决路径缺失问题
## 根本原因 workspace_create 只写 DB 不建目录,导致任何主题(小说/文章/海报等) 切换到目录已被删除/外置磁盘未挂载的 workspace 后,发送消息必然报错, 且旧提示语引导用户去不存在的"工作区设置"页面。 ## 4 层防护 **L1 创建时(workspace_create)** - 建 workspace 前调 ensure_workspace_root_ready,目录不存在则自动创建 **L2 启动/切换时(useWorkspace + useProjects)** - refresh/setDefault/projects_refresh 时调 workspace_ensure_ready - 静默自动修复已知 workspace 的缺失目录 **L3 发消息前(aster_agent_cmd)** - aster_session_create + aster_agent_chat_stream 各自调 ensure_workspace_root_ready - 能自动创建则创建并继续,无法创建则返回语义化错误 **L4 主动检查 + 兜底 UI(AgentChatPage + CrashRecoveryPanel)** - 打开任意项目时主动调 workspace_ensure_ready,失败时显示 amber banner - 发送失败也显示 amber banner,"重新选择目录"按钮处理两种场景 - CrashRecoveryPanel 新增 workspace-path-missing 场景识别与蓝色修复按钮 ## 新增功能 - WorkspaceUpdate.root_path:支持通过 API 修改 workspace 根目录 - workspace_ensure_ready / workspace_ensure_default_ready:Tauri 健康检查命令 - workspace_health_service.rs:独立服务模块,含详细诊断信息 - AppCrashBoundary / CrashRecoveryPanel:通用 React 错误边界与恢复面板 - workspaceHealthTelemetry.ts:localStorage 修复历史记录(最多 50 条) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 4.6
parent
16b48bad36
commit
2d00911c28
@@ -18,3 +18,4 @@ pub mod sysinfo_service;
|
||||
pub mod update_check_service;
|
||||
pub mod update_window;
|
||||
pub mod web_search_prompt_service;
|
||||
pub mod workspace_health_service;
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
use std::path::Path;
|
||||
|
||||
/// 确保 workspace 根目录可用。
|
||||
///
|
||||
/// 返回值:
|
||||
/// - `Ok(true)`: 目录原本不存在,已自动创建
|
||||
/// - `Ok(false)`: 目录已存在且可用
|
||||
/// - `Err(...)`: 路径非法/无权限等不可恢复错误
|
||||
pub fn ensure_workspace_root_ready(workspace_root: &Path) -> Result<bool, String> {
|
||||
if workspace_root.exists() {
|
||||
if workspace_root.is_dir() {
|
||||
return Ok(false);
|
||||
}
|
||||
return Err(format!(
|
||||
"Workspace 路径存在但不是目录: {}。请删除同名文件或重新选择目录。",
|
||||
workspace_root.to_string_lossy()
|
||||
));
|
||||
}
|
||||
|
||||
std::fs::create_dir_all(workspace_root).map_err(|error| {
|
||||
let path_str = workspace_root.to_string_lossy();
|
||||
let hint = workspace_root
|
||||
.parent()
|
||||
.map(|parent| {
|
||||
if !parent.exists() {
|
||||
format!("父目录 '{}' 不存在", parent.display())
|
||||
} else if std::fs::metadata(parent)
|
||||
.map(|metadata| metadata.permissions().readonly())
|
||||
.unwrap_or(false)
|
||||
{
|
||||
format!("父目录 '{}' 无写入权限", parent.display())
|
||||
} else {
|
||||
format!("错误: {error}")
|
||||
}
|
||||
})
|
||||
.unwrap_or_else(|| format!("错误: {error}"));
|
||||
format!(
|
||||
"Workspace 路径不存在,且自动创建失败: {path_str}。{hint}。请重新选择一个有效的本地目录。"
|
||||
)
|
||||
})?;
|
||||
|
||||
Ok(true)
|
||||
}
|
||||
Reference in New Issue
Block a user