dev-manager-tauri/.blueprint/modules/blueprint-governance.md
lanrtop f4ff83d94e feat(governance): 规则分发跨工具化——AGENTS.md 成为蓝图工作流单一来源
sync_blueprint_rules 改为双文件写入:
- AGENTS.md:完整蓝图工作流 MANAGED 块(开放标准,Qwen/Cursor/Copilot 均读),
  措辞去 Claude 专属化("Claude 应做的"→"AI 应做的",技能引用改为通用流程描述)
- CLAUDE.md:MANAGED 块瘦身为 @AGENTS.md 薄引用(保留 version marker,
  版本检测不受影响),内容永不分叉
- 抽 upsert_managed_block 公共 helper(created/updated/appended 三态),
  附 tempdir 单元测试;SyncResult 新增 agents_md_action

背景:批量同步后发现所有项目只落 CLAUDE.md,跨工具内容被锁进单一工具
私有文件,违反宪章「跨工具单一来源 = AGENTS.md」。
下次批量同步时全部项目自动迁移到新结构(marker 机制天然幂等)。

Rules-Applied: R01, R07
2026-07-02 19:49:22 +09:00

86 lines
5.4 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

---
id: blueprint-governance
name: 蓝图治理
status: done
progress: 100
---
## 概述
将 dev-manager-tauri 的 `.blueprint/CONVENTIONS.md` 和 CLAUDE.md 蓝图区块作为唯一权威来源,向所有托管项目分发和同步规则,确保跨项目规则一致性。
## 决策记录
- CONVENTIONS.md 加 YAML frontmatter 版本号,应用以此判断是否需要同步
- CLAUDE.md 用 `<!-- BLUEPRINT_MANAGED_START -->` / `<!-- BLUEPRINT_MANAGED_END -->` 标记管理区,应用只替换标记内内容,不动项目自有内容
- 无 CLAUDE.md 时生成初始文件;有 CLAUDE.md 但无 MANAGED 区时追加到末尾
- MASTER_CONVENTIONS 通过 `include_str!()` 在编译时嵌入,保证 binary 自包含
- BlueprintStatus 四状态none / rules_outdated / content_stale / synced
## 任务卡
### ✅ CONVENTIONS.md 版本化
- status: done
- complexity: S
- files: .blueprint/CONVENTIONS.md
- acceptance: frontmatter 加 version 和 updated 字段,格式为 semver如 1.0.0
### ✅ CLAUDE.md 模板定义
- status: done
- complexity: S
- files: src-tauri/src/commands/blueprint.rs
- acceptance: 在 Rust 中定义 CLAUDE.md MANAGED 区的标准内容模板,内容涵盖:蓝图飞轮流程、读取 manifest 指令、任务卡派发规则;模板版本与 CONVENTIONS.md 同步
### ✅ get_blueprint_status command
- status: done
- complexity: M
- files: src-tauri/src/commands/blueprint.rs, src-tauri/src/lib.rs, src/lib/commands.ts
- acceptance: 接收项目路径返回四种状态之一none / rules_outdated / content_stale / synced判断依据.blueprint/ 是否存在、CONVENTIONS.md 版本是否匹配 master、CLAUDE.md 是否有 MANAGED 区且版本匹配
### ✅ sync_blueprint_rules command
- status: done
- complexity: M
- files: src-tauri/src/commands/blueprint.rs, src-tauri/src/lib.rs, src/lib/commands.ts
- acceptance: 接收项目路径,执行三步:(1) 覆盖写入最新 CONVENTIONS.md(2) 检测 CLAUDE.md 是否存在及 MANAGED 区状态,按三种情况(无文件/无区块/版本旧)分别处理;(3) 返回操作摘要
### ✅ 批量同步所有项目规则
- status: done
- complexity: S
- files: src/components/settings/SettingsPage.tsx
- acceptance: 设置页提供「同步所有项目蓝图规则」按钮,调用 sync_blueprint_rules 遍历所有已注册项目,返回每个项目的同步结果摘要
### ✅ 用户版 CONVENTIONS 存储层初始化
- status: done
- complexity: S
- files: src-tauri/src/commands/blueprint.rs, src-tauri/src/lib.rs
- acceptance: 新增 `USER_CONVENTIONS_DIR: OnceLock<PathBuf>``init_user_conventions_dir(app_data_dir)`,在 lib.rs setup() 中紧跟 db::init 调用;`effective_conventions_content() -> String` 优先读 app_data_dir/conventions/CONVENTIONS.md文件不存在时 fallback 到编译时内置;`effective_conventions_version() -> String` 从 effective 内容解析 frontmatter version
### ✅ 用户版 CONVENTIONS 读写 command
- status: done
- complexity: M
- files: src-tauri/src/commands/blueprint.rs, src-tauri/src/lib.rs, src/lib/commands.ts
- depends: blueprint-governance
- acceptance: 新增三个 command(1) `get_user_conventions_status` 返回 `{ source: "builtin"|"user", version, content, builtin_version, outdated_from_builtin }`(2) `save_user_conventions(content)` 从 frontmatter 解析版本(失败时返回错误),写入用户版文件,清除 effective 内容缓存,自动触发遍历所有项目的 sync_blueprint_rules返回 `{ version, synced_count }`(3) `reset_conventions_to_builtin` 删除用户版文件并清除缓存;三个 command 注册到 invoke_handlerTS 封装完成
### ✅ sync/梦核/summary 切换为 effective 内容
- status: done
- complexity: S
- files: src-tauri/src/commands/blueprint.rs
- depends: blueprint-governance
- acceptance: `sync_blueprint_rules`、`generate_muhe_prompt`、`conventions_rules_summary`、`claude_managed_template` 全部改用 `effective_conventions_content()``effective_conventions_version()`,不再直接引用 MASTER_CONVENTIONS 常量;有用户版时分发用户版,无用户版时 fallback 内置版,行为与改前一致
### ✅ GovernancePanel 规则编辑器 UI
- status: done
- complexity: M
- files: src/components/dashboard/BlueprintModal.tsx, src/lib/commands.ts
- depends: blueprint-governance
- acceptance: GovernancePanel 新增规则来源 badge「内置基线 vX.X.X」或「用户自定义 vX.X.X」新增「应用梦核建议」区域文本框用于粘贴新 CONVENTIONS 内容 + 确认按钮,确认后调用 save_user_conventions成功显示「已同步 N 个项目」;有用户版时显示「重置为基线」按钮,调用 reset_conventions_to_builtin 后来源恢复为内置
### ✅ 跨工具规则分发AGENTS.md 单一来源
- status: done
- complexity: M
- files: src-tauri/src/commands/blueprint.rs, src/lib/commands.ts
- acceptance: sync_blueprint_rules 将完整蓝图工作流 MANAGED 块写入 AGENTS.md开放标准Qwen/Cursor/Copilot 均读),措辞去 Claude 专属化CLAUDE.md 的 MANAGED 块瘦身为 @AGENTS.md 引用(保留 version marker 使版本检测不受影响);两文件共用 upsert helpercreated/updated/appended 三态helper 有 tempdir 单元测试SyncResult 新增 agents_md_action 字段cargo test + typecheck 通过
> 背景:批量同步后用户发现所有项目只落了 CLAUDE.md——跨工具内容被锁进单一工具私有文件违反宪章「跨工具单一来源 = AGENTS.md」。