From f3c0967f41d63ef4f5947cf37981f36a7e2d7949 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BB=9D=E5=B0=98?= <237809796@qq.com> Date: Sun, 14 Jun 2026 17:16:28 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D:=20AR-3=20=E5=AE=A1=E6=89=B9?= =?UTF-8?q?=20reason=20=E6=9F=A5=E9=A1=B9=E7=9B=AE=E5=90=8D=E6=8B=BC?= =?UTF-8?q?=E5=AF=B9=E8=B1=A1=E5=90=8D=EF=BC=88=E7=94=A8=E6=88=B7=E5=86=8D?= =?UTF-8?q?=E5=8F=8D=E9=A6=88=20P0=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit build_approval_reason 改 async + 接收 db,对 delete/restore/purge/update/bind/create_task 的 id/project_id 查 ProjectRepo.get_by_id 拼「项目名」(id=x)(原只拼裸 id,用户反馈'只返回 ID 不知道是什么数据') 新增 resolve_project_label helper;process_tool_calls 调用改 await 来源 aichat审查报告 第二章 + 用户 2026-06-14 再反馈;cargo 0 err --- ...-CRUD模式.md => SQLite-CRUD模式-2026-06-12.md} | 0 ...uri-IPC模式.md => Tauri-IPC模式-2026-06-12.md} | 0 ...应机制.md => B-03-人工审批响应机制-2026-06-14.md} | 0 ...e1架构决策.md => Phase1架构决策-2026-06-12.md} | 0 ...oncept.md => aichat信息密度构想-2026-06-14.md} | 0 ...2026-06-14.md => aichat审查报告-2026-06-14.md} | 0 ...oncept.md => aichat异步审批构想-2026-06-14.md} | 0 ...业务系统设计.md => 业务系统设计-2026-06-12.md} | 0 ...产品定位调整.md => 产品定位调整-2026-06-12.md} | 0 ...端类型对齐.md => 前后端类型对齐-2026-06-12.md} | 0 ...功能决策记录.md => 功能决策记录-2026-06-14.md} | 0 ...记录-归档.md => 功能决策记录-归档-2026-06-14.md} | 0 ...证裁决报告.md => 对抗论证裁决报告-2026-06-12.md} | 0 ...文档记录规范.md => 文档记录规范-2026-06-14.md} | 0 .../{经验记录.md => 经验记录-2026-06-14.md} | 0 ...约自检机制.md => 规格契约自检机制-2026-06-14.md} | 0 ...集成模块.md => df-ai-AI集成模块-2026-06-12.md} | 0 ...识库.md => df-knowledge-知识库-2026-06-14.md} | 0 ...点集合.md => df-nodes-节点集合-2026-06-12.md} | 0 ...-存储层.md => df-storage-存储层-2026-06-12.md} | 0 ...引擎.md => df-workflow-工作流引擎-2026-06-12.md} | 0 ...抗式评估.md => 想法探索-对抗式评估-2026-06-12.md} | 0 ...实施.md => DEVFLOW-1.CRUD层实施-2026-06-12.md} | 0 ...实施.md => DEVFLOW-2.IPC桥接实施-2026-06-12.md} | 0 ...施.md => DEVFLOW-3.Store对接实施-2026-06-12.md} | 0 ...端验证.md => DEVFLOW-4.端到端验证-2026-06-12.md} | 0 ...View改造指南.md => View改造指南-2026-06-12.md} | 0 ...e1任务清单.md => Phase1任务清单-2026-06-12.md} | 0 .../{Phase2计划.md => Phase2计划-2026-06-12.md} | 0 .../{使用手册.md => 使用手册-2026-06-12.md} | 0 src-tauri/src/commands/ai/audit.rs | 64 ++++++++++++++----- 31 files changed, 49 insertions(+), 15 deletions(-) rename docs/01-技术文档/{SQLite-CRUD模式.md => SQLite-CRUD模式-2026-06-12.md} (100%) rename docs/01-技术文档/{Tauri-IPC模式.md => Tauri-IPC模式-2026-06-12.md} (100%) rename docs/02-架构设计/{B-03-人工审批响应机制.md => B-03-人工审批响应机制-2026-06-14.md} (100%) rename docs/02-架构设计/{Phase1架构决策.md => Phase1架构决策-2026-06-12.md} (100%) rename docs/02-架构设计/{aichat-info-density-concept.md => aichat信息密度构想-2026-06-14.md} (100%) rename docs/02-架构设计/{aichat-review-2026-06-14.md => aichat审查报告-2026-06-14.md} (100%) rename docs/02-架构设计/{aichat-async-approval-concept.md => aichat异步审批构想-2026-06-14.md} (100%) rename docs/02-架构设计/{业务系统设计.md => 业务系统设计-2026-06-12.md} (100%) rename docs/02-架构设计/{产品定位调整.md => 产品定位调整-2026-06-12.md} (100%) rename docs/02-架构设计/{前后端类型对齐.md => 前后端类型对齐-2026-06-12.md} (100%) rename docs/02-架构设计/{功能决策记录.md => 功能决策记录-2026-06-14.md} (100%) rename docs/02-架构设计/{功能决策记录-归档.md => 功能决策记录-归档-2026-06-14.md} (100%) rename docs/02-架构设计/{对抗论证裁决报告.md => 对抗论证裁决报告-2026-06-12.md} (100%) rename docs/02-架构设计/{文档记录规范.md => 文档记录规范-2026-06-14.md} (100%) rename docs/02-架构设计/{经验记录.md => 经验记录-2026-06-14.md} (100%) rename docs/02-架构设计/{规格契约自检机制.md => 规格契约自检机制-2026-06-14.md} (100%) rename docs/03-模块文档/{df-ai-AI集成模块.md => df-ai-AI集成模块-2026-06-12.md} (100%) rename docs/03-模块文档/{df-knowledge-知识库.md => df-knowledge-知识库-2026-06-14.md} (100%) rename docs/03-模块文档/{df-nodes-节点集合.md => df-nodes-节点集合-2026-06-12.md} (100%) rename docs/03-模块文档/{df-storage-存储层.md => df-storage-存储层-2026-06-12.md} (100%) rename docs/03-模块文档/{df-workflow-工作流引擎.md => df-workflow-工作流引擎-2026-06-12.md} (100%) rename docs/03-模块文档/{想法探索-对抗式评估.md => 想法探索-对抗式评估-2026-06-12.md} (100%) rename docs/04-功能迭代/{DEVFLOW-1.CRUD层实施.md => DEVFLOW-1.CRUD层实施-2026-06-12.md} (100%) rename docs/04-功能迭代/{DEVFLOW-2.IPC桥接实施.md => DEVFLOW-2.IPC桥接实施-2026-06-12.md} (100%) rename docs/04-功能迭代/{DEVFLOW-3.Store对接实施.md => DEVFLOW-3.Store对接实施-2026-06-12.md} (100%) rename docs/04-功能迭代/{DEVFLOW-4.端到端验证.md => DEVFLOW-4.端到端验证-2026-06-12.md} (100%) rename docs/06-前端开发/{View改造指南.md => View改造指南-2026-06-12.md} (100%) rename docs/07-项目管理/{Phase1任务清单.md => Phase1任务清单-2026-06-12.md} (100%) rename docs/07-项目管理/{Phase2计划.md => Phase2计划-2026-06-12.md} (100%) rename docs/08-用户指南/{使用手册.md => 使用手册-2026-06-12.md} (100%) diff --git a/docs/01-技术文档/SQLite-CRUD模式.md b/docs/01-技术文档/SQLite-CRUD模式-2026-06-12.md similarity index 100% rename from docs/01-技术文档/SQLite-CRUD模式.md rename to docs/01-技术文档/SQLite-CRUD模式-2026-06-12.md diff --git a/docs/01-技术文档/Tauri-IPC模式.md b/docs/01-技术文档/Tauri-IPC模式-2026-06-12.md similarity index 100% rename from docs/01-技术文档/Tauri-IPC模式.md rename to docs/01-技术文档/Tauri-IPC模式-2026-06-12.md diff --git a/docs/02-架构设计/B-03-人工审批响应机制.md b/docs/02-架构设计/B-03-人工审批响应机制-2026-06-14.md similarity index 100% rename from docs/02-架构设计/B-03-人工审批响应机制.md rename to docs/02-架构设计/B-03-人工审批响应机制-2026-06-14.md diff --git a/docs/02-架构设计/Phase1架构决策.md b/docs/02-架构设计/Phase1架构决策-2026-06-12.md similarity index 100% rename from docs/02-架构设计/Phase1架构决策.md rename to docs/02-架构设计/Phase1架构决策-2026-06-12.md diff --git a/docs/02-架构设计/aichat-info-density-concept.md b/docs/02-架构设计/aichat信息密度构想-2026-06-14.md similarity index 100% rename from docs/02-架构设计/aichat-info-density-concept.md rename to docs/02-架构设计/aichat信息密度构想-2026-06-14.md diff --git a/docs/02-架构设计/aichat-review-2026-06-14.md b/docs/02-架构设计/aichat审查报告-2026-06-14.md similarity index 100% rename from docs/02-架构设计/aichat-review-2026-06-14.md rename to docs/02-架构设计/aichat审查报告-2026-06-14.md diff --git a/docs/02-架构设计/aichat-async-approval-concept.md b/docs/02-架构设计/aichat异步审批构想-2026-06-14.md similarity index 100% rename from docs/02-架构设计/aichat-async-approval-concept.md rename to docs/02-架构设计/aichat异步审批构想-2026-06-14.md diff --git a/docs/02-架构设计/业务系统设计.md b/docs/02-架构设计/业务系统设计-2026-06-12.md similarity index 100% rename from docs/02-架构设计/业务系统设计.md rename to docs/02-架构设计/业务系统设计-2026-06-12.md diff --git a/docs/02-架构设计/产品定位调整.md b/docs/02-架构设计/产品定位调整-2026-06-12.md similarity index 100% rename from docs/02-架构设计/产品定位调整.md rename to docs/02-架构设计/产品定位调整-2026-06-12.md diff --git a/docs/02-架构设计/前后端类型对齐.md b/docs/02-架构设计/前后端类型对齐-2026-06-12.md similarity index 100% rename from docs/02-架构设计/前后端类型对齐.md rename to docs/02-架构设计/前后端类型对齐-2026-06-12.md diff --git a/docs/02-架构设计/功能决策记录.md b/docs/02-架构设计/功能决策记录-2026-06-14.md similarity index 100% rename from docs/02-架构设计/功能决策记录.md rename to docs/02-架构设计/功能决策记录-2026-06-14.md diff --git a/docs/02-架构设计/功能决策记录-归档.md b/docs/02-架构设计/功能决策记录-归档-2026-06-14.md similarity index 100% rename from docs/02-架构设计/功能决策记录-归档.md rename to docs/02-架构设计/功能决策记录-归档-2026-06-14.md diff --git a/docs/02-架构设计/对抗论证裁决报告.md b/docs/02-架构设计/对抗论证裁决报告-2026-06-12.md similarity index 100% rename from docs/02-架构设计/对抗论证裁决报告.md rename to docs/02-架构设计/对抗论证裁决报告-2026-06-12.md diff --git a/docs/02-架构设计/文档记录规范.md b/docs/02-架构设计/文档记录规范-2026-06-14.md similarity index 100% rename from docs/02-架构设计/文档记录规范.md rename to docs/02-架构设计/文档记录规范-2026-06-14.md diff --git a/docs/02-架构设计/经验记录.md b/docs/02-架构设计/经验记录-2026-06-14.md similarity index 100% rename from docs/02-架构设计/经验记录.md rename to docs/02-架构设计/经验记录-2026-06-14.md diff --git a/docs/02-架构设计/规格契约自检机制.md b/docs/02-架构设计/规格契约自检机制-2026-06-14.md similarity index 100% rename from docs/02-架构设计/规格契约自检机制.md rename to docs/02-架构设计/规格契约自检机制-2026-06-14.md diff --git a/docs/03-模块文档/df-ai-AI集成模块.md b/docs/03-模块文档/df-ai-AI集成模块-2026-06-12.md similarity index 100% rename from docs/03-模块文档/df-ai-AI集成模块.md rename to docs/03-模块文档/df-ai-AI集成模块-2026-06-12.md diff --git a/docs/03-模块文档/df-knowledge-知识库.md b/docs/03-模块文档/df-knowledge-知识库-2026-06-14.md similarity index 100% rename from docs/03-模块文档/df-knowledge-知识库.md rename to docs/03-模块文档/df-knowledge-知识库-2026-06-14.md diff --git a/docs/03-模块文档/df-nodes-节点集合.md b/docs/03-模块文档/df-nodes-节点集合-2026-06-12.md similarity index 100% rename from docs/03-模块文档/df-nodes-节点集合.md rename to docs/03-模块文档/df-nodes-节点集合-2026-06-12.md diff --git a/docs/03-模块文档/df-storage-存储层.md b/docs/03-模块文档/df-storage-存储层-2026-06-12.md similarity index 100% rename from docs/03-模块文档/df-storage-存储层.md rename to docs/03-模块文档/df-storage-存储层-2026-06-12.md diff --git a/docs/03-模块文档/df-workflow-工作流引擎.md b/docs/03-模块文档/df-workflow-工作流引擎-2026-06-12.md similarity index 100% rename from docs/03-模块文档/df-workflow-工作流引擎.md rename to docs/03-模块文档/df-workflow-工作流引擎-2026-06-12.md diff --git a/docs/03-模块文档/想法探索-对抗式评估.md b/docs/03-模块文档/想法探索-对抗式评估-2026-06-12.md similarity index 100% rename from docs/03-模块文档/想法探索-对抗式评估.md rename to docs/03-模块文档/想法探索-对抗式评估-2026-06-12.md diff --git a/docs/04-功能迭代/DEVFLOW-1.CRUD层实施.md b/docs/04-功能迭代/DEVFLOW-1.CRUD层实施-2026-06-12.md similarity index 100% rename from docs/04-功能迭代/DEVFLOW-1.CRUD层实施.md rename to docs/04-功能迭代/DEVFLOW-1.CRUD层实施-2026-06-12.md diff --git a/docs/04-功能迭代/DEVFLOW-2.IPC桥接实施.md b/docs/04-功能迭代/DEVFLOW-2.IPC桥接实施-2026-06-12.md similarity index 100% rename from docs/04-功能迭代/DEVFLOW-2.IPC桥接实施.md rename to docs/04-功能迭代/DEVFLOW-2.IPC桥接实施-2026-06-12.md diff --git a/docs/04-功能迭代/DEVFLOW-3.Store对接实施.md b/docs/04-功能迭代/DEVFLOW-3.Store对接实施-2026-06-12.md similarity index 100% rename from docs/04-功能迭代/DEVFLOW-3.Store对接实施.md rename to docs/04-功能迭代/DEVFLOW-3.Store对接实施-2026-06-12.md diff --git a/docs/04-功能迭代/DEVFLOW-4.端到端验证.md b/docs/04-功能迭代/DEVFLOW-4.端到端验证-2026-06-12.md similarity index 100% rename from docs/04-功能迭代/DEVFLOW-4.端到端验证.md rename to docs/04-功能迭代/DEVFLOW-4.端到端验证-2026-06-12.md diff --git a/docs/06-前端开发/View改造指南.md b/docs/06-前端开发/View改造指南-2026-06-12.md similarity index 100% rename from docs/06-前端开发/View改造指南.md rename to docs/06-前端开发/View改造指南-2026-06-12.md diff --git a/docs/07-项目管理/Phase1任务清单.md b/docs/07-项目管理/Phase1任务清单-2026-06-12.md similarity index 100% rename from docs/07-项目管理/Phase1任务清单.md rename to docs/07-项目管理/Phase1任务清单-2026-06-12.md diff --git a/docs/07-项目管理/Phase2计划.md b/docs/07-项目管理/Phase2计划-2026-06-12.md similarity index 100% rename from docs/07-项目管理/Phase2计划.md rename to docs/07-项目管理/Phase2计划-2026-06-12.md diff --git a/docs/08-用户指南/使用手册.md b/docs/08-用户指南/使用手册-2026-06-12.md similarity index 100% rename from docs/08-用户指南/使用手册.md rename to docs/08-用户指南/使用手册-2026-06-12.md diff --git a/src-tauri/src/commands/ai/audit.rs b/src-tauri/src/commands/ai/audit.rs index 138ea7d..21d773c 100644 --- a/src-tauri/src/commands/ai/audit.rs +++ b/src-tauri/src/commands/ai/audit.rs @@ -7,7 +7,7 @@ use tauri::{AppHandle, Emitter}; use df_ai::ai_tools::{AiToolRegistry, RiskLevel}; use df_ai::provider::ChatMessage; -use df_storage::crud::AiToolExecutionRepo; +use df_storage::crud::{AiToolExecutionRepo, ProjectRepo}; use df_storage::db::Database; use df_storage::models::AiToolExecutionRecord; @@ -38,45 +38,79 @@ pub(crate) fn risk_from_str(s: &str) -> Option { } } +/// 查项目可读标签:id → "「项目名」(id=x)",查不到回退 "(id=x)",空 id 返回空串。 +/// +/// AR-3:审批卡片需显示对象名而非裸 id(用户反馈"只返回 ID 不知道是什么数据")。 +async fn resolve_project_label(db: &Arc, id: &str) -> String { + if id.is_empty() { + return String::new(); + } + let repo = ProjectRepo::new(db); + match repo.get_by_id(id).await { + Ok(Some(p)) => format!("「{}」(id={})", p.name, id), + _ => format!("(id={})", id), + } +} + /// 拼审批 reason:按工具名 + args 取可读字段,让用户知道"审批要做什么"。 /// /// 主要审批工具特化(带对象名/标识): -/// - delete_project/restore_project/purge_project → "删除/恢复/清除项目"+id -/// - update_project → "修改项目"+field -/// - bind_directory → "绑定目录"+path -/// - create_task → "创建任务"+title;create_project → "创建项目"+name;create_idea → "捕获灵感"+title -/// - run_workflow → "运行工作流"+name +/// - delete_project/restore_project/purge_project → 查项目名拼"删除项目「名」(id=x)" +/// - update_project → 查项目名 + field +/// - bind_directory → path + 查项目名 +/// - create_task → title + 查 project_id 项目名;create_project → name;create_idea → title +/// - run_workflow → name /// args 无可读字段或工具未特化时,fallback 原 risk 模板(含风险等级提示)。 -fn build_approval_reason(tool_name: &str, args: &serde_json::Value, risk_level: RiskLevel) -> String { +async fn build_approval_reason( + tool_name: &str, + args: &serde_json::Value, + risk_level: RiskLevel, + db: &Arc, +) -> String { let s = |key: &str| args.get(key).and_then(|v| v.as_str()).unwrap_or(""); let detail = match tool_name { "delete_project" => { let id = s("id"); - if !id.is_empty() { format!("删除项目(ID: {})", id) } else { String::new() } + if !id.is_empty() { format!("删除项目{}", resolve_project_label(db, id).await) } else { String::new() } } "restore_project" => { let id = s("id"); - if !id.is_empty() { format!("从回收站恢复项目(ID: {})", id) } else { String::new() } + if !id.is_empty() { format!("从回收站恢复项目{}", resolve_project_label(db, id).await) } else { String::new() } } "purge_project" => { let id = s("id"); - if !id.is_empty() { format!("永久删除项目及关联数据,不可恢复(ID: {})", id) } else { String::new() } + if !id.is_empty() { format!("永久删除项目及关联数据,不可恢复{}", resolve_project_label(db, id).await) } else { String::new() } } "update_project" => { + let id = s("id"); let field = s("field"); - if !field.is_empty() { format!("修改项目字段「{}」", field) } else { String::new() } + if !id.is_empty() { + format!("修改项目{}字段「{}」", resolve_project_label(db, id).await, field) + } else if !field.is_empty() { + format!("修改项目字段「{}」", field) + } else { String::new() } } "bind_directory" => { + let id = s("id"); let path = s("path"); - if !path.is_empty() { format!("绑定目录:{}", path) } else { String::new() } + if !path.is_empty() && !id.is_empty() { + format!("绑定目录:{}(项目{})", path, resolve_project_label(db, id).await) + } else if !path.is_empty() { + format!("绑定目录:{}", path) + } else { String::new() } } "create_task" => { let title = s("title"); - if !title.is_empty() { format!("创建任务:{}", title) } else { String::new() } + let pid = s("project_id"); + if !title.is_empty() && !pid.is_empty() { + format!("创建任务:{}(项目{})", title, resolve_project_label(db, pid).await) + } else if !title.is_empty() { + format!("创建任务:{}", title) + } else { String::new() } } "create_project" => { let name = s("name"); - if !name.is_empty() { format!("创建项目:{}", name) } else { String::new() } + if !name.is_empty() { format!("创建项目:「{}」", name) } else { String::new() } } "create_idea" => { let title = s("title"); @@ -241,7 +275,7 @@ pub(crate) async fn process_tool_calls( recovered: false, }); session.messages.push(ChatMessage::tool_result(&draft.id, "需要用户审批,等待确认")); - let reason = build_approval_reason(&draft.name, &args, risk_level); + let reason = build_approval_reason(&draft.name, &args, risk_level, db).await; let _ = app_handle.emit("ai-chat-event", AiChatEvent::AiApprovalRequired { id: draft.id.clone(), name: draft.name.clone(),