优化: 清理无意义注释(走查编号前缀/过时历史标注/死代码注释)

This commit is contained in:
lxy
2026-08-15 18:05:43 +08:00
parent 5a4c821629
commit 5ac815b9ca
137 changed files with 735 additions and 737 deletions
+20 -20
View File
@@ -33,7 +33,7 @@ use crate::state::AllowedDirs;
pub(crate) const MAX_LIST_RESULTS: usize = 50;
/// run_command 默认超时(秒)。LLM 可在 args timeout_secs 覆盖此默认值。
/// 提取为常量便于在超时标注处引用同一来源(F-260616-04)。
/// 提取为常量便于在超时标注处引用同一来源。
///
/// tool_registry 拆分:run_command handler 迁声明式(tools/file.rs),复用本常量保单真相源
/// (避免字面量 60 漂移),故 pub(crate) 暴露给 tools 子模块。
@@ -48,7 +48,7 @@ pub(crate) const MAX_RUN_COMMAND_TIMEOUT_SECS: u64 = 600;
/// AE-2025-03(路径 B):audit.rs 挂起审批前预读旧文件复用此函数生成 diff,
/// 供前端审批卡即时预览(write_file 审批不再只看裸 content)。故 pub(crate)。
///
/// BUG-260617-07: LCS DP 表 O(n*m) 内存,两文件均>1000 行时 DP 表可达数百 MB
/// LCS DP 表 O(n*m) 内存,两文件均>1000 行时 DP 表可达数百 MB
/// (5000×5000×8B≈200MB)。虽然 1MB 字节上限能挡住多数情况,但短行高密度的源码
/// (大量空行/单字符行)仍可能突破。改:两文件均>1000 行时跳过 LCS,退化为
/// 「删旧全量 + 增新全量」朴素行对比 + 截断提示。朴素对比 O(n+m) 内存,安全。
@@ -118,7 +118,7 @@ pub(crate) fn generate_diff(old: &str, new: &str) -> String {
/// 验证文件路径:禁止访问系统敏感目录 + 防路径遍历绕过
///
/// 安全要点(BUG-260617-03):
/// 安全要点
/// 1. **先 URL 解码**再检查——防 `%2e%2e` / `%2f` 等 URL 编码绕过 `..` 检测。
/// LLM / 外部输入可能传编码串,若直接做字符串 `..` 检查会被 `%2e%2e` 骗过,
/// 解码后再走分段归一化校验。
@@ -151,7 +151,7 @@ pub(crate) fn validate_path(path: &str) -> anyhow::Result<()> {
if crate::state::is_in_system_blacklist(&PathBuf::from(&normalized)) {
anyhow::bail!("禁止访问敏感系统目录");
}
// F-260620: AppData 不再硬拦(原 `lower.contains("\\appdata\\")` 一刀切致用户授权后仍拒)。
// AppData 不再硬拦(原 `lower.contains("\\appdata\\")` 一刀切致用户授权后仍拒)。
// AppData 走白名单流程(is_authorized/check_path_authorization):默认不在白名单 → 弹 DirAuthDialog
// → 用户显式授权(once/always)→ 放行。真正敏感凭据(.ssh/.aws/.gnupg)由 is_in_system_blacklist
// 硬拦(授权也不放,防凭据泄漏),AppData 内应用数据(DBeaver Scripts/项目配置等)归用户自治——
@@ -180,7 +180,7 @@ pub(crate) fn truncate_output(s: &str, max: usize) -> (String, bool) {
}
// ============================================================
// patch_file 三模式共用底层(F-260617-01)
// patch_file 三模式共用底层
//
// 三模式互斥(old_text 精确匹配 / replace_lines 行号区间 / anchor 锚点),
// 后两者均归约为「按行号区间 [start, end](1-based 含首尾)替换为 new_text」,
@@ -407,7 +407,7 @@ pub(crate) fn resolve_workspace_path_with_allowed(
resolve_workspace_path_impl(path, allowed)
}
/// AE-2025-04:mod.rs trust_key_for 计算 write_file 的 TrustKey 目录粒度时复用本函数
/// mod.rs trust_key_for 计算 write_file 的 TrustKey 目录粒度时复用本函数
/// 归一化路径(去 .. / symlink 逃逸)。pub(crate) wrapper 转调私有 impl,保持原私有函数
/// 可见性边界(不暴露给 crate 外,但允许同 crate ai 模块 mod.rs 调用)。
///
@@ -631,7 +631,7 @@ fn register_local_proxy_tools(
/// 数据层 AI 工具注册(25 个持 db 的 CRUD/状态机/工作流/知识图谱工具)——从 build_ai_tool_registry 抽出。
///
/// 工具闭包捕获 `db: &Arc<Database>` Arc 重建 Repo(列表/创建/更新/删除/状态推进/工作流/任务关联)。
/// 例外:run_workflow handler 防御返回 Err(CR-52),不持 db 不 clone,真正执行经
/// 例外:run_workflow handler 防御返回 Err,不持 db 不 clone,真正执行经
/// ai_approve → run_workflow_inner 另走完整 State 路径。
///
/// 知识图谱 Phase 1(2026-06-26):新增 register_task_graph_tools 子函数(6 工具:task_link CRUD
@@ -641,7 +641,7 @@ fn register_local_proxy_tools(
/// 知识图谱 Phase 3(2026-06-27):register_task_graph_tools 增 add_project_service(Medium)/
/// list_project_services(Low 只读) 项目基础设施配置,data 层 25→27。
///
/// SMELL-P0-2:抽自原 build_ai_tool_registry 1091 行单函数(数据+文件混合)。
/// 抽自原 build_ai_tool_registry 1091 行单函数(数据+文件混合)。
/// 18 个 register 调用【原样移入】,零行为变更,仅机械搬运。
///
/// SMELL-P0-2 续拆(2026-06-19):18 工具按业务表细分为 5 子函数:
@@ -761,7 +761,7 @@ fn register_trash_tools(registry: &mut AiToolRegistry, db: &Arc<Database>) {
}
/// 文件系统类 AI 工具注册(命令执行/读/列/写/改/元/追加/删/移/搜)——不持 db,纯文件系统操作。
/// 从 build_ai_tool_registry 抽出(SMELL-P0-2:1091行单函数拆分,build 1090→~390 行)。
/// 从 build_ai_tool_registry 抽出1091行单函数拆分,build 1090→~390 行)。
///
/// F-260619-03 Phase A: 各文件工具闭包捕获 `allowed_dirs: Arc<RwLock<AllowedDirs>>`,
/// handler 执行时 read lock 取白名单快照,resolve_workspace_path_with_allowed 校验动态白名单。
@@ -852,11 +852,11 @@ pub(crate) fn list_dir_recursive<'a>(
continue;
}
// 临时文件(.bak/.tmp-write 等)也不返回:write_file 原子写过程的副产物,
// 崩溃/中断会留孤儿文件,泄漏进 list_directory 噪化 AI 上下文(CR-260615-03)。
// 崩溃/中断会留孤儿文件,泄漏进 list_directory 噪化 AI 上下文。
if skip_noise && is_noise_file(&name) {
continue;
}
// FR-S8:用 file_type() 不跟随 symlink——entry.metadata() 会解析符号链接目标,
// 用 file_type() 不跟随 symlink——entry.metadata() 会解析符号链接目标,
// 经 workspace 内 symlink 即可泄露外部目标的 size/类型,且递归会进入 symlink 指向的 workspace 外目录
let file_type = entry.file_type().await?;
let is_symlink = file_type.is_symlink();
@@ -929,7 +929,7 @@ pub(crate) fn tool_display_hint(name: &str) -> Option<&'static str> {
"create_idea" => Some("捕获灵感"),
"update_task" => Some("修改任务"),
// advance_task 不在此轻量映射:让 build_approval_reason 走 display_hint_for_tool
// 模板(含 target_status 详情),否则轻量命中"推进任务状态"丢失目标态信息(UX-260618-14)
// 模板(含 target_status 详情),否则轻量命中"推进任务状态"丢失目标态信息
"run_workflow" => Some("触发工作流"),
"delete_task" => Some("删除任务"),
"update_idea" => Some("修改灵感"),
@@ -948,7 +948,7 @@ pub(crate) fn is_noise_dir(name: &str) -> bool {
const NOISE_DIRS: &[&str] = &[
".git", "node_modules", "target", "dist", "build",
".next", ".cache", "__pycache__", ".venv", "venv", ".idea",
".trash", // delete_file 软删除回收站(F-260615-16),不污染 list_directory
".trash", // delete_file 软删除回收站,不污染 list_directory
];
NOISE_DIRS.contains(&name)
}
@@ -964,7 +964,7 @@ pub(crate) fn is_noise_file(name: &str) -> bool {
}
// ============================================================
// grep 工具底层(F-260621)
// grep 工具底层
//
// FileGrepHit 单文件命中聚合:line_matches 按行号升序。output_mode 分派时:
// - content: 展平 line_matches 为 matches[{file,line,content,context?}]
@@ -1101,7 +1101,7 @@ pub(crate) fn grep_recursive<'a>(
}
continue;
}
// 文件处理(BUG-260625-01:提取为 grep_one_file,grep handler 单文件路径复用同一逻辑)
// 文件处理提取为 grep_one_file,grep handler 单文件路径复用同一逻辑)
grep_one_file(&path, &file_name, re, glob, output_mode, context_lines, max_results, out, total, truncated).await?;
}
Ok(())
@@ -1109,7 +1109,7 @@ pub(crate) fn grep_recursive<'a>(
}
/// 单文件 grep:读 + 二进制检测 + 行匹配,收集命中到 out。
/// 提取自 grep_recursive 循环体(BUG-260625-01),供 grep handler 单文件路径复用——
/// 提取自 grep_recursive 循环体,供 grep handler 单文件路径复用——
/// grep 命令行原生支持单文件,LLM 常传文件路径而非目录,旧实现直接 read_dir 文件路径报 os error 267。
/// files_with_matches:文件级命中(content/count 不收集行详情);content/count:行级命中,达 max_results 截断。
pub(crate) async fn grep_one_file(
@@ -1317,7 +1317,7 @@ mod tests {
let registry = build_ai_tool_registry(&db, &allowed_dirs, PathBuf::from(""), make_test_get_app_config_ctx(&db), make_test_local_proxy_ctx());
// 总量基线:41(27 data + 13 file + 1 http)。拆分前后必须一致。
// F-260621: file 层 10→11(新增 grep 跨文件内容搜索工具)。
// file 层 10→11(新增 grep 跨文件内容搜索工具)。
// L1 环境感知(设计 §2.1): file 层 11→12(新增 detect_environment 环境探测工具)。
// AST 代码智能(7c2e3b2): file 层 12→13(新增 read_symbol 符号解析,治 read_file 全文回灌 prompt 爆)。
// 知识图谱 Phase 1(2026-06-26): data 层 18→24(新增 register_task_graph_tools 6 工具:
@@ -1332,7 +1332,7 @@ mod tests {
// register_git_tools 3 个)
// Git 写工具(2026-06-29): data 层 31→34(新增 git_commit/git_branch/git_merge,
// register_git_tools 3→6)
// BUG-2026-07-07: 修正 baseline 计数(原写死 41 与实际 48 不符,HEAD 上即失败)。
// 修正 baseline 计数(原写死 41 与实际 48 不符,HEAD 上即失败)。
// 48 = 34 data + 13 file + 1 http。data 34 含 6 知识图谱 + 2 基础设施 + 1 module + 6 git。
// update_idea/delete_idea(2026-08-01): data 层 34→36(补 AI 改/删灵感专用工具,
// idea_repo.update_field / soft_delete 早已具备,工具层此前缺失致 AI 误用 update_task)。
@@ -1780,7 +1780,7 @@ mod tests {
}
// ============================================================
// patch_file 三模式共用底层测试(F-260617-01)
// patch_file 三模式共用底层测试
// 纯函数 apply_line_range / resolve_anchor_to_lines,不依赖 fs/async/锁。
// handler 闭包内的三模式分派/互斥校验逻辑由参数解析+这两个函数组合而成,
// 故覆盖纯函数即覆盖 replace_lines/anchor 两模式核心;old_text 模式逻辑
@@ -1942,7 +1942,7 @@ mod tests {
}
// ============================================================
// grep 工具测试(F-260621)
// grep 工具测试
//
// compile_glob_to_regex:纯函数,无 fs 依赖。
// grep_recursive:递归遍历临时目录树,覆盖基本匹配/正则/大小写/glob/噪音跳过/截断。