|
| 1 | +# Templates 目录结构差异分析 |
| 2 | + |
| 3 | +## ❌ 问题:文档与实现不一致 |
| 4 | + |
| 5 | +### 📄 文档建议的结构 (`spec-template.md.j2` Line 415-429) |
| 6 | + |
| 7 | +**按 specification system source 组织**: |
| 8 | + |
| 9 | +``` |
| 10 | +templates/ |
| 11 | +├── [library-spec-1]/ # 例如: generic/ |
| 12 | +│ ├── commands/ # Slash Commands from this specification system |
| 13 | +│ │ └── [command-name].md |
| 14 | +│ └── templates/ # Entity/workflow templates from this system |
| 15 | +│ └── [template-name].yaml |
| 16 | +├── [library-spec-2]/ # 例如: spec-kit/ |
| 17 | +│ ├── commands/ |
| 18 | +│ └── templates/ |
| 19 | +└── [custom]/ # 例如: mcp/ (from protocol) |
| 20 | + ├── commands/ |
| 21 | + └── templates/ |
| 22 | +``` |
| 23 | + |
| 24 | +**设计理念**: |
| 25 | +- ✅ 按来源分组(library vs custom) |
| 26 | +- ✅ 清晰的命名空间隔离 |
| 27 | +- ✅ 体现规范组合性(Specification Composability) |
| 28 | +- ✅ 易于理解来源和用途 |
| 29 | + |
| 30 | +**文档示例 (MCP-Speckit)**: |
| 31 | +``` |
| 32 | +templates/ |
| 33 | +├── generic/ # From library/generic |
| 34 | +│ ├── commands/ |
| 35 | +│ │ ├── init.md |
| 36 | +│ │ └── validate.md |
| 37 | +│ └── templates/ |
| 38 | +│ └── basic-spec.yaml |
| 39 | +├── spec-kit/ # From library/sdd/spec-kit |
| 40 | +│ ├── commands/ |
| 41 | +│ │ ├── plan.md |
| 42 | +│ │ └── implement.md |
| 43 | +│ └── templates/ |
| 44 | +│ └── toolkit-spec.yaml |
| 45 | +└── mcp/ # Custom (from protocol/001-mcp-protocol) |
| 46 | + ├── commands/ |
| 47 | + │ ├── show-protocol.md |
| 48 | + │ ├── get-template.md |
| 49 | + │ └── validate-server.md |
| 50 | + └── templates/ |
| 51 | + ├── basic-server.yaml |
| 52 | + ├── advanced-server.yaml |
| 53 | + └── tool-definition.yaml |
| 54 | +``` |
| 55 | + |
| 56 | +--- |
| 57 | + |
| 58 | +### 💻 实际实现的结构 (`generator.py` Line 257-269) |
| 59 | + |
| 60 | +**扁平化组织**: |
| 61 | + |
| 62 | +```python |
| 63 | +# Line 260: 模板文件直接在 templates/ 根目录 |
| 64 | +output_template = f"templates/{template_name}" |
| 65 | + |
| 66 | +# Line 266: 命令文件在 templates/commands/ 统一目录 |
| 67 | +output_command = f"templates/commands/{command_name}" |
| 68 | +``` |
| 69 | + |
| 70 | +**实际生成的结构**: |
| 71 | +``` |
| 72 | +templates/ |
| 73 | +├── specify-template.md # 直接在根目录,没有 source 分组 |
| 74 | +├── plan-template.md # 直接在根目录 |
| 75 | +├── validate-template.md # 直接在根目录 |
| 76 | +└── commands/ # 所有命令混在一起 |
| 77 | + ├── specify.md # 来自 generic/greenfield |
| 78 | + ├── plan.md # 来自 spec-kit |
| 79 | + ├── proposal.md # 来自 openspec |
| 80 | + └── validate.md # 来自 generic/greenfield |
| 81 | +``` |
| 82 | + |
| 83 | +**问题**: |
| 84 | +- ❌ 无法区分来源(generic vs spec-kit vs custom) |
| 85 | +- ❌ 命名冲突风险(不同 source 可能有同名命令) |
| 86 | +- ❌ 与文档承诺的结构不符 |
| 87 | +- ❌ 不符合"按 specification system source 组织"的设计原则 |
| 88 | + |
| 89 | +--- |
| 90 | + |
| 91 | +## 📊 具体差异对比 |
| 92 | + |
| 93 | +| 方面 | 文档建议 | 实际实现 | 影响 | |
| 94 | +|------|---------|---------|------| |
| 95 | +| **组织原则** | 按 source 分组 | 扁平化 | ❌ 不符合设计理念 | |
| 96 | +| **目录结构** | `templates/{source}/commands/` | `templates/commands/` | ❌ 无法区分来源 | |
| 97 | +| **模板位置** | `templates/{source}/templates/` | `templates/` | ❌ 混在根目录 | |
| 98 | +| **命名冲突** | 隔离(不同 source 可同名) | 可能冲突 | ❌ 风险增加 | |
| 99 | +| **可组合性** | 体现规范组合 | 无法体现 | ❌ 设计理念丢失 | |
| 100 | +| **用户理解** | 清晰来源和职责 | 混乱不清 | ❌ 学习曲线增加 | |
| 101 | + |
| 102 | +--- |
| 103 | + |
| 104 | +## 🔍 根本原因 |
| 105 | + |
| 106 | +### generator.py 中的简化逻辑 |
| 107 | + |
| 108 | +```python |
| 109 | +# Line 248-269: 循环处理 slash_commands |
| 110 | +for sc in meta_spec.slash_commands: |
| 111 | + source = f"library/{sc.source}" |
| 112 | + |
| 113 | + # 从 source 读取 |
| 114 | + source_template = f"{source}/templates/{template_name}.j2" |
| 115 | + source_command = f"{source}/commands/{command_name}.j2" |
| 116 | + |
| 117 | + # 但输出时丢弃了 source 信息! |
| 118 | + output_template = f"templates/{template_name}" # ❌ 扁平化 |
| 119 | + output_command = f"templates/commands/{command_name}" # ❌ 扁平化 |
| 120 | +``` |
| 121 | + |
| 122 | +**问题**: 输出路径没有保留 `source` 信息。 |
| 123 | + |
| 124 | +--- |
| 125 | + |
| 126 | +## ✅ 建议的修复方案 |
| 127 | + |
| 128 | +### 方案 1: 保留 source 层次结构(推荐) |
| 129 | + |
| 130 | +**修改 generator.py**: |
| 131 | + |
| 132 | +```python |
| 133 | +for sc in meta_spec.slash_commands: |
| 134 | + source = f"library/{sc.source}" |
| 135 | + |
| 136 | + # 保留 source 信息 |
| 137 | + output_template = f"templates/{sc.source}/templates/{template_name}" |
| 138 | + output_command = f"templates/{sc.source}/commands/{command_name}" |
| 139 | +``` |
| 140 | + |
| 141 | +**修复后的结构**: |
| 142 | +``` |
| 143 | +templates/ |
| 144 | +├── generic/ |
| 145 | +│ ├── commands/ |
| 146 | +│ │ ├── specify.md |
| 147 | +│ │ └── validate.md |
| 148 | +│ └── templates/ |
| 149 | +│ ├── specify-template.md |
| 150 | +│ └── validate-template.md |
| 151 | +├── spec-kit/ |
| 152 | +│ ├── commands/ |
| 153 | +│ │ ├── plan.md |
| 154 | +│ │ └── implement.md |
| 155 | +│ └── templates/ |
| 156 | +│ ├── plan-template.md |
| 157 | +│ └── implement-template.md |
| 158 | +└── custom/ # 如果有 protocol-derived commands |
| 159 | + ├── commands/ |
| 160 | + │ └── show-protocol.md |
| 161 | + └── templates/ |
| 162 | + └── server-template.yaml |
| 163 | +``` |
| 164 | + |
| 165 | +**优点**: |
| 166 | +- ✅ 符合文档设计 |
| 167 | +- ✅ 清晰的命名空间 |
| 168 | +- ✅ 体现规范组合性 |
| 169 | +- ✅ 避免命名冲突 |
| 170 | + |
| 171 | +**风险**: |
| 172 | +- ⚠️ 破坏性变更(需要更新版本) |
| 173 | +- ⚠️ 已有 speckit 的迁移 |
| 174 | + |
| 175 | +--- |
| 176 | + |
| 177 | +### 方案 2: 更新文档以匹配实现 |
| 178 | + |
| 179 | +**修改 spec-template.md.j2**: |
| 180 | + |
| 181 | +将推荐结构改为: |
| 182 | +``` |
| 183 | +templates/ |
| 184 | +├── {command1}-template.md # 模板文件 |
| 185 | +├── {command2}-template.md |
| 186 | +└── commands/ # 所有 Slash Commands |
| 187 | + ├── {command1}.md |
| 188 | + └── {command2}.md |
| 189 | +``` |
| 190 | + |
| 191 | +**优点**: |
| 192 | +- ✅ 简单快速 |
| 193 | +- ✅ 不破坏现有代码 |
| 194 | + |
| 195 | +**缺点**: |
| 196 | +- ❌ 放弃设计理念 |
| 197 | +- ❌ 无法体现规范组合性 |
| 198 | +- ❌ 可能有命名冲突 |
| 199 | + |
| 200 | +--- |
| 201 | + |
| 202 | +## 🎯 推荐决策 |
| 203 | + |
| 204 | +### 建议:采用方案 1(保留 source 层次结构) |
| 205 | + |
| 206 | +**理由**: |
| 207 | +1. **设计一致性**: 文档描述的"按 specification system source 组织"是核心设计理念 |
| 208 | +2. **可扩展性**: 支持多个 library 的组合使用 |
| 209 | +3. **清晰性**: 用户可以清楚地看到每个命令来自哪个 specification system |
| 210 | +4. **避免冲突**: 不同 source 可以有同名命令而不冲突 |
| 211 | + |
| 212 | +**实施步骤**: |
| 213 | +1. ✅ 修改 `generator.py` (Line 260, 266) |
| 214 | +2. ✅ 更新测试用例 |
| 215 | +3. ✅ 添加版本升级指南 |
| 216 | +4. ✅ 更新 CHANGELOG (MAJOR version bump: 0.3.0 → 1.0.0) |
| 217 | + |
| 218 | +--- |
| 219 | + |
| 220 | +## 📝 相关文件 |
| 221 | + |
| 222 | +- `src/metaspec/generator.py` (Line 257-269) - 实现代码 |
| 223 | +- `src/metaspec/templates/meta/templates/spec-template.md.j2` (Line 409-455) - 文档规范 |
| 224 | +- `src/metaspec/templates/meta/sdd/commands/specify.md.j2` (Line 1468-1494) - 开发指南 |
| 225 | + |
| 226 | +--- |
| 227 | + |
| 228 | +## ⏰ 发现时间 |
| 229 | + |
| 230 | +2025-11-08 (Version 0.3.0 发布后) |
| 231 | + |
| 232 | +--- |
| 233 | + |
| 234 | +## 🚨 影响评估 |
| 235 | + |
| 236 | +**当前状态**: |
| 237 | +- ✅ 功能正常工作(能生成 speckit) |
| 238 | +- ❌ 结构与文档不符 |
| 239 | +- ❌ 可能导致用户困惑 |
| 240 | +- ❌ 无法体现核心设计理念 |
| 241 | + |
| 242 | +**修复优先级**: **P0 (Critical)** |
| 243 | + |
| 244 | +**原因**: 这是核心架构设计问题,影响框架的可理解性和可扩展性。 |
| 245 | + |
0 commit comments