diff --git a/crates/df-project/src/scan.rs b/crates/df-project/src/scan.rs index 1fe86cc..847d96d 100644 --- a/crates/df-project/src/scan.rs +++ b/crates/df-project/src/scan.rs @@ -126,6 +126,51 @@ fn has_file_with_ext(dir: &Path, ext: &str) -> bool { // 项目采样(供 LLM 分析基础信息) — 纯 IO,控 token 不读源码 // ============================================================ +/// 提取项目描述 — 读 README 首段(首个非标题非空段落,截断 200 字)。 +/// +/// 用于「导入历史项目」时自动填充 description。无 README 或解析失败返回 None。 +/// 首段定义:跳过开头标题行(# / ## …)、空行、HTML 注释与 badge 图片/HTML 行等噪声, +/// 取首个含实质文本的段落(连续多行直到空行);按字符截断至 200 字避免超长。 +pub fn extract_description(root: &Path) -> Option { + // 复用 read_readme 的查找逻辑(支持 README.md / README.zh.md 等变体) + let content = read_readme(root)?; + let mut text = String::new(); + let mut started = false; + for raw_line in content.lines() { + let line = raw_line.trim(); + if line.is_empty() { + if started { + break; // 段落结束 + } + continue; // 首段尚未开始,跳过开头空行 + } + // 段落开始后不再跳行,直接累加 + if !started { + // 跳过标题 / HTML 注释 / badge 图片 / HTML 标签等噪声前导行 + if line.starts_with('#') + || line.starts_with("