diff --git a/src-tauri/src/commands/blueprint.rs b/src-tauri/src/commands/blueprint.rs index 79fe0f8..c1e088a 100644 --- a/src-tauri/src/commands/blueprint.rs +++ b/src-tauri/src/commands/blueprint.rs @@ -4,10 +4,24 @@ use std::path::Path; // ── 主节点:master CONVENTIONS.md 内容和版本(编译时嵌入)──────────────────── const MASTER_CONVENTIONS: &str = include_str!("../../../.blueprint/CONVENTIONS.md"); -const MASTER_CONVENTIONS_VERSION: &str = "1.4.2"; -// CLAUDE.md 蓝图管理区模板(版本与 CONVENTIONS 保持一致) -const CLAUDE_MANAGED_TEMPLATE: &str = r#" +/// 从 MASTER_CONVENTIONS frontmatter 自动解析版本号,无需手动维护常量。 +fn master_conventions_version() -> &'static str { + static VERSION: std::sync::OnceLock = std::sync::OnceLock::new(); + VERSION.get_or_init(|| { + for line in MASTER_CONVENTIONS.lines() { + if let Some(v) = line.strip_prefix("version: ") { + return v.trim().to_string(); + } + } + "unknown".to_string() + }) +} + +/// CLAUDE.md 蓝图管理区模板,版本号从 CONVENTIONS frontmatter 自动同步。 +fn claude_managed_template() -> String { + let ver = master_conventions_version(); + format!(r#" ## 项目蓝图 本项目使用 `.blueprint/` 目录维护项目全景架构图,驱动需求讨论和任务管理。 @@ -30,7 +44,8 @@ const CLAUDE_MANAGED_TEMPLATE: &str = r#""#; +"#) +} // ── manifest.yaml 对应结构 ─────────────────────────────────────────────────── @@ -896,7 +911,7 @@ pub fn get_blueprint_status(project_path: String) -> Result Result Result Result // 2. 处理 CLAUDE.md let claude_path = root.join("CLAUDE.md"); + let managed_template = claude_managed_template(); let claude_action = if !claude_path.exists() { // 创建新文件 - let content = format!("# {}\n\n{CLAUDE_MANAGED_TEMPLATE}\n", + let content = format!("# {}\n\n{managed_template}\n", root.file_name().and_then(|n| n.to_str()).unwrap_or("Project")); std::fs::write(&claude_path, content) .map_err(|e| format!("创建 CLAUDE.md 失败: {e}"))?; @@ -978,13 +994,13 @@ pub fn sync_blueprint_rules(project_path: String) -> Result if content.contains("