Add project soft-delete with workspace archival
- Add delete button (×) to sidebar project list, shown on hover - Soft-delete: mark projects as deleted in DB instead of hard delete - Move workspace files to /app/data/deleted/ folder on deletion - Filter deleted projects from list query - Auto-select next project after deleting current one - Also includes agent prompt improvements for reverse proxy paths Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
10
src/agent.rs
10
src/agent.rs
@@ -474,8 +474,13 @@ fn build_planning_prompt(project_id: &str) -> String {
|
||||
- 工作目录是独立的项目工作区,Python venv 已预先激活(.venv/)\n\
|
||||
- 可用工具:bash、git、curl、uv\n\
|
||||
- 静态文件访问:/api/projects/{0}/files/{{filename}}\n\
|
||||
- 后台服务访问:/api/projects/{0}/app/\n\
|
||||
- 如果要构建 Web 应用,推荐 FastAPI + 前端 HTML,API 请求用相对路径 /api/projects/{0}/app/...\n\
|
||||
- 后台服务访问:/api/projects/{0}/app/(反向代理,路径会被转发到应用的 /)\n\
|
||||
\n\
|
||||
【重要】反向代理注意事项:\n\
|
||||
- 用户通过 /api/projects/{0}/app/ 访问应用,请求被代理到应用的 / 路径\n\
|
||||
- 因此前端 HTML 中的所有 API 请求必须使用【不带开头 / 的相对路径】\n\
|
||||
- 正确示例:fetch('todos') 或 fetch('./todos') 错误示例:fetch('/todos') 或 fetch('/api/todos')\n\
|
||||
- HTML 中的 <base> 标签不需要设置,只要不用绝对路径就行\n\
|
||||
\n\
|
||||
请使用中文回复。",
|
||||
project_id,
|
||||
@@ -505,6 +510,7 @@ fn build_execution_prompt(project_id: &str) -> String {
|
||||
- 使用 `uv add <包名>` 或 `pip install <包名>` 安装依赖\n\
|
||||
- 静态文件访问:/api/projects/{0}/files/{{filename}}\n\
|
||||
- 后台服务访问:/api/projects/{0}/app/(启动命令需监听 0.0.0.0:$PORT)\n\
|
||||
- 【重要】应用通过反向代理访问,前端 HTML/JS 中的 fetch/XHR 请求必须使用相对路径(如 fetch('todos')),绝对不能用 / 开头的路径(如 fetch('/todos')),否则会 404\n\
|
||||
\n\
|
||||
请使用中文回复。",
|
||||
project_id,
|
||||
|
||||
@@ -40,7 +40,7 @@ pub fn router(state: Arc<AppState>) -> Router {
|
||||
async fn list_projects(
|
||||
State(state): State<Arc<AppState>>,
|
||||
) -> ApiResult<Vec<Project>> {
|
||||
sqlx::query_as::<_, Project>("SELECT * FROM projects ORDER BY updated_at DESC")
|
||||
sqlx::query_as::<_, Project>("SELECT * FROM projects WHERE deleted = 0 ORDER BY updated_at DESC")
|
||||
.fetch_all(&state.db.pool)
|
||||
.await
|
||||
.map(Json)
|
||||
@@ -109,10 +109,30 @@ async fn delete_project(
|
||||
State(state): State<Arc<AppState>>,
|
||||
Path(id): Path<String>,
|
||||
) -> ApiResult<bool> {
|
||||
sqlx::query("DELETE FROM projects WHERE id = ?")
|
||||
// Soft delete: mark as deleted in DB
|
||||
let result = sqlx::query("UPDATE projects SET deleted = 1, updated_at = datetime('now') WHERE id = ? AND deleted = 0")
|
||||
.bind(&id)
|
||||
.execute(&state.db.pool)
|
||||
.await
|
||||
.map(|r| Json(r.rows_affected() > 0))
|
||||
.map_err(db_err)
|
||||
.map_err(db_err)?;
|
||||
|
||||
if result.rows_affected() == 0 {
|
||||
return Ok(Json(false));
|
||||
}
|
||||
|
||||
// Move workspace to deleted folder
|
||||
let src = std::path::PathBuf::from("/app/data/workspaces").join(&id);
|
||||
let dst_dir = std::path::PathBuf::from("/app/data/deleted");
|
||||
if src.exists() {
|
||||
if let Err(e) = tokio::fs::create_dir_all(&dst_dir).await {
|
||||
tracing::error!("Failed to create deleted dir: {}", e);
|
||||
} else {
|
||||
let dst = dst_dir.join(&id);
|
||||
if let Err(e) = tokio::fs::rename(&src, &dst).await {
|
||||
tracing::error!("Failed to move workspace to deleted: {}", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Ok(Json(true))
|
||||
}
|
||||
|
||||
@@ -94,6 +94,13 @@ impl Database {
|
||||
.execute(&self.pool)
|
||||
.await;
|
||||
|
||||
// Migration: add deleted column to projects
|
||||
let _ = sqlx::query(
|
||||
"ALTER TABLE projects ADD COLUMN deleted INTEGER NOT NULL DEFAULT 0"
|
||||
)
|
||||
.execute(&self.pool)
|
||||
.await;
|
||||
|
||||
sqlx::query(
|
||||
"CREATE TABLE IF NOT EXISTS timers (
|
||||
id TEXT PRIMARY KEY,
|
||||
@@ -120,6 +127,8 @@ pub struct Project {
|
||||
pub description: String,
|
||||
pub created_at: String,
|
||||
pub updated_at: String,
|
||||
#[serde(default)]
|
||||
pub deleted: bool,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, sqlx::FromRow)]
|
||||
|
||||
Reference in New Issue
Block a user