@chongyan/autospec 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (243) hide show
  1. package/LICENSE +21 -0
  2. package/README.en.md +472 -0
  3. package/README.md +476 -0
  4. package/bin/autospec.js +3 -0
  5. package/knowledge/README.md +144 -0
  6. package/knowledge/checklists/code.md +182 -0
  7. package/knowledge/checklists/design.md +196 -0
  8. package/knowledge/checklists/release.md +70 -0
  9. package/knowledge/checklists/requirement.md +169 -0
  10. package/knowledge/checklists/test.md +46 -0
  11. package/knowledge/config/README.en.md +44 -0
  12. package/knowledge/config/README.md +44 -0
  13. package/knowledge/config/role-composition.yaml +98 -0
  14. package/knowledge/config/role-extensions.yaml +140 -0
  15. package/knowledge/config/skill-compositions.yaml +142 -0
  16. package/knowledge/config/team-stage.yaml +95 -0
  17. package/knowledge/config/team-tasks.yaml +139 -0
  18. package/knowledge/config/team-triggers.yaml +198 -0
  19. package/knowledge/config/validation-patterns.yaml +137 -0
  20. package/knowledge/domain/README.md +115 -0
  21. package/knowledge/domain/flows/README.md +194 -0
  22. package/knowledge/domain/glossary.md +143 -0
  23. package/knowledge/domain/rules.md +138 -0
  24. package/knowledge/environment/README.en.md +36 -0
  25. package/knowledge/environment/README.md +87 -0
  26. package/knowledge/environment/component-knowledge.md +316 -0
  27. package/knowledge/environment/detection-patterns.yaml +502 -0
  28. package/knowledge/environment/middleware-knowledge.md +237 -0
  29. package/knowledge/environment/template-registry.md +321 -0
  30. package/knowledge/guides/domain-driven-design.md +345 -0
  31. package/knowledge/guides/knowledge-management.md +369 -0
  32. package/knowledge/guides/requirement-engineering.md +329 -0
  33. package/knowledge/guides/stages/ai-effect-evaluator.md +93 -0
  34. package/knowledge/guides/stages/code-implementer.md +205 -0
  35. package/knowledge/guides/stages/code-reviewer.md +111 -0
  36. package/knowledge/guides/stages/consistency-checker.md +177 -0
  37. package/knowledge/guides/stages/design-planner.md +401 -0
  38. package/knowledge/guides/stages/design-reviewer.md +83 -0
  39. package/knowledge/guides/stages/integration-test-runner.md +105 -0
  40. package/knowledge/guides/stages/release-checker.md +205 -0
  41. package/knowledge/guides/stages/requirement-analyzer.md +195 -0
  42. package/knowledge/guides/stages/requirement-reviewer.md +83 -0
  43. package/knowledge/guides/stages/security-reviewer.md +89 -0
  44. package/knowledge/guides/stages/test-context-analyzer.md +250 -0
  45. package/knowledge/guides/stages/test-generator.md +241 -0
  46. package/knowledge/guides/stages/test-planner.md +183 -0
  47. package/knowledge/guides/stages/test-reviewer.md +76 -0
  48. package/knowledge/guides/stages/unit-test-runner.md +83 -0
  49. package/knowledge/guides/support/ai-agent-analyzer.md +362 -0
  50. package/knowledge/guides/support/ai-anomaly-analyzer.md +213 -0
  51. package/knowledge/guides/support/ai-artifact-evaluator.md +192 -0
  52. package/knowledge/guides/support/ai-capability-analyzer.md +193 -0
  53. package/knowledge/guides/support/ai-component-analyzer.md +169 -0
  54. package/knowledge/guides/support/ai-data-validator.md +276 -0
  55. package/knowledge/guides/support/ai-evaluation-planner.md +374 -0
  56. package/knowledge/guides/support/ai-path-evaluator.md +274 -0
  57. package/knowledge/guides/support/ai-pipeline-evaluator.md +219 -0
  58. package/knowledge/guides/support/ai-rag-analyzer.md +339 -0
  59. package/knowledge/guides/support/ai-task-assessor.md +418 -0
  60. package/knowledge/guides/support/ai-test-diagnostics.md +133 -0
  61. package/knowledge/guides/support/complexity-assessor.md +268 -0
  62. package/knowledge/guides/support/component-discovery.md +183 -0
  63. package/knowledge/guides/support/environment-scanner.md +207 -0
  64. package/knowledge/guides/support/environment-validator.md +207 -0
  65. package/knowledge/guides/support/knowledge-generator.md +234 -0
  66. package/knowledge/guides/support/methodology-extractor.md +55 -0
  67. package/knowledge/guides/support/pipeline-protocol.md +438 -0
  68. package/knowledge/guides/support/practice-logger.md +359 -0
  69. package/knowledge/guides/support/scope-inference.md +174 -0
  70. package/knowledge/guides/support/skill-distiller.md +91 -0
  71. package/knowledge/guides/support/skill-updater.md +45 -0
  72. package/knowledge/guides/support/skill-validator.md +72 -0
  73. package/knowledge/guides/support/team-orchestrator.md +323 -0
  74. package/knowledge/guides/support/tech-stack-analyzer.md +139 -0
  75. package/knowledge/guides/support/test-runner.md +254 -0
  76. package/knowledge/guides/system-design.md +352 -0
  77. package/knowledge/organization/ai-native-team.md +318 -0
  78. package/knowledge/organization/team-metrics.md +228 -0
  79. package/knowledge/principles/constitution.md +134 -0
  80. package/knowledge/principles/core-principles.md +368 -0
  81. package/knowledge/principles/design-philosophy.md +877 -0
  82. package/knowledge/principles/evolution.md +553 -0
  83. package/knowledge/process/01-requirement.md +113 -0
  84. package/knowledge/process/02-design.md +123 -0
  85. package/knowledge/process/03-implementation.md +90 -0
  86. package/knowledge/process/04-review.md +80 -0
  87. package/knowledge/process/05-testing.md +90 -0
  88. package/knowledge/process/06-delivery.md +88 -0
  89. package/knowledge/process/README.en.md +38 -0
  90. package/knowledge/process/README.md +48 -0
  91. package/knowledge/process/ai-sdlc.md +475 -0
  92. package/knowledge/process/overview.md +319 -0
  93. package/knowledge/standards/code-review.md +876 -0
  94. package/knowledge/standards/coding-style.md +940 -0
  95. package/knowledge/standards/data-consistency.md +1085 -0
  96. package/knowledge/standards/document-versioning.md +210 -0
  97. package/knowledge/standards/risk-detection.md +186 -0
  98. package/knowledge/templates/ai-evaluation.md +150 -0
  99. package/knowledge/templates/api-design.md +117 -0
  100. package/knowledge/templates/database-design.md +132 -0
  101. package/knowledge/templates/domain-driven-design.md +321 -0
  102. package/knowledge/templates/product-proposal.md +201 -0
  103. package/knowledge/templates/system-design.md +227 -0
  104. package/knowledge/templates/task-breakdown.md +107 -0
  105. package/knowledge/templates/test-case.md +170 -0
  106. package/package.json +53 -0
  107. package/plugins/.claude-plugin/plugin.json +134 -0
  108. package/plugins/agents/roles/ai-engineer.md +129 -0
  109. package/plugins/agents/roles/backend-engineer.md +165 -0
  110. package/plugins/agents/roles/ceo.md +94 -0
  111. package/plugins/agents/roles/data-engineer.md +135 -0
  112. package/plugins/agents/roles/devops-engineer.md +181 -0
  113. package/plugins/agents/roles/frontend-engineer.md +129 -0
  114. package/plugins/agents/roles/product-owner.md +98 -0
  115. package/plugins/agents/roles/quality-engineer.md +129 -0
  116. package/plugins/agents/roles/security-engineer.md +180 -0
  117. package/plugins/agents/roles/tech-lead.md +97 -0
  118. package/plugins/agents/support/blind-comparator.md +88 -0
  119. package/plugins/agents/support/consistency-checker.md +103 -0
  120. package/plugins/agents/support/failure-diagnostician.md +141 -0
  121. package/plugins/agents/support/independent-reviewer.md +80 -0
  122. package/plugins/agents/support/safety-auditor.md +121 -0
  123. package/plugins/agents/support/skill-benchmarker.md +86 -0
  124. package/plugins/agents/support/skill-forger.md +105 -0
  125. package/plugins/agents/support/stage-gate-evaluator.md +121 -0
  126. package/plugins/agents/support/test-coverage-reviewer.md +73 -0
  127. package/plugins/benchmarks/templates/README.md +44 -0
  128. package/plugins/benchmarks/templates/commands/explore-template.yaml +48 -0
  129. package/plugins/benchmarks/templates/pipeline/agile-template.yaml +84 -0
  130. package/plugins/benchmarks/templates/pipeline/waterfall-template.yaml +106 -0
  131. package/plugins/benchmarks/templates/skills/requirement-analyzer-template.yaml +48 -0
  132. package/plugins/commands/README.en.md +96 -0
  133. package/plugins/commands/README.md +96 -0
  134. package/plugins/commands/apply.md +191 -0
  135. package/plugins/commands/archive.md +76 -0
  136. package/plugins/commands/env-export.md +79 -0
  137. package/plugins/commands/env-sync.md +640 -0
  138. package/plugins/commands/env-template.md +223 -0
  139. package/plugins/commands/env-update.md +264 -0
  140. package/plugins/commands/env-validate.md +176 -0
  141. package/plugins/commands/env.md +79 -0
  142. package/plugins/commands/explore.md +76 -0
  143. package/plugins/commands/field-evolve.md +536 -0
  144. package/plugins/commands/memory.md +249 -0
  145. package/plugins/commands/project-evolve.md +821 -0
  146. package/plugins/commands/propose.md +93 -0
  147. package/plugins/commands/review.md +140 -0
  148. package/plugins/commands/run.md +224 -0
  149. package/plugins/commands/status.md +62 -0
  150. package/plugins/commands/validate.md +108 -0
  151. package/plugins/hooks/README.en.md +56 -0
  152. package/plugins/hooks/README.md +56 -0
  153. package/plugins/hooks/ai-project-guard.js +329 -0
  154. package/plugins/hooks/artifact-evaluation-hook.js +237 -0
  155. package/plugins/hooks/constitution-guard.js +211 -0
  156. package/plugins/hooks/environment-autocommit.js +264 -0
  157. package/plugins/hooks/environment-manager.js +778 -0
  158. package/plugins/hooks/execution-tracker.js +354 -0
  159. package/plugins/hooks/frozen-zone-guard.js +140 -0
  160. package/plugins/hooks/layer1-validator.js +423 -0
  161. package/plugins/hooks/lib/artifact-evaluator.js +414 -0
  162. package/plugins/hooks/lib/benchmarks/change-detector.js +390 -0
  163. package/plugins/hooks/lib/benchmarks/evaluator.js +605 -0
  164. package/plugins/hooks/lib/benchmarks/integration-example.js +169 -0
  165. package/plugins/hooks/lib/data-and-ai-detector.js +275 -0
  166. package/plugins/hooks/lib/detection-pattern-loader.js +865 -0
  167. package/plugins/hooks/lib/directory-discovery.js +395 -0
  168. package/plugins/hooks/lib/environment-config-loader.js +341 -0
  169. package/plugins/hooks/lib/environment-detector.js +553 -0
  170. package/plugins/hooks/lib/environment-evolver.js +564 -0
  171. package/plugins/hooks/lib/environment-registry.js +813 -0
  172. package/plugins/hooks/lib/execution-path.js +427 -0
  173. package/plugins/hooks/lib/hook-error-recorder.js +245 -0
  174. package/plugins/hooks/lib/hook-logger.js +538 -0
  175. package/plugins/hooks/lib/hook-runner.js +97 -0
  176. package/plugins/hooks/lib/hook-runner.sh +44 -0
  177. package/plugins/hooks/lib/hook-state-manager.js +480 -0
  178. package/plugins/hooks/lib/memory-extractor.js +377 -0
  179. package/plugins/hooks/lib/memory-manager.js +673 -0
  180. package/plugins/hooks/lib/metrics-analyzer.js +489 -0
  181. package/plugins/hooks/lib/project-evolution/auto-fixer.js +511 -0
  182. package/plugins/hooks/lib/project-evolution/memory-manager.js +346 -0
  183. package/plugins/hooks/lib/project-evolution/pattern-detector.js +476 -0
  184. package/plugins/hooks/lib/project-evolution/semantic-indexer.js +480 -0
  185. package/plugins/hooks/lib/project-structure-detector.js +326 -0
  186. package/plugins/hooks/lib/rollback-tracker.js +346 -0
  187. package/plugins/hooks/lib/source-code-scanner.js +596 -0
  188. package/plugins/hooks/lib/technology-stack-detector.js +374 -0
  189. package/plugins/hooks/lib/test-failure-analyzer.js +375 -0
  190. package/plugins/hooks/lib/test-failure-fixer.js +268 -0
  191. package/plugins/hooks/lib/trace-context.js +277 -0
  192. package/plugins/hooks/lib/validation-patterns.js +415 -0
  193. package/plugins/hooks/memory-sync.js +171 -0
  194. package/plugins/hooks/pipeline-observer.js +413 -0
  195. package/plugins/hooks/scope-sentinel.js +204 -0
  196. package/plugins/hooks/trace-initialization.js +169 -0
  197. package/plugins/memory/templates/code-quality.yaml +149 -0
  198. package/plugins/memory/templates/multi-system.yaml +155 -0
  199. package/plugins/memory/templates/team-habits.yaml +119 -0
  200. package/plugins/memory/templates/testing.yaml +121 -0
  201. package/plugins/skills/README.en.md +47 -0
  202. package/plugins/skills/README.md +104 -0
  203. package/plugins/skills/benchmark-executor/README.md +93 -0
  204. package/plugins/skills/benchmark-executor/SKILL.md +647 -0
  205. package/plugins/skills/benchmark-generator/SKILL.md +349 -0
  206. package/plugins/skills/delivery-stage/SKILL.md +203 -0
  207. package/plugins/skills/design-stage/SKILL.md +216 -0
  208. package/plugins/skills/evolution-process/SKILL.md +291 -0
  209. package/plugins/skills/exploration-phase/SKILL.md +133 -0
  210. package/plugins/skills/implementation-stage/SKILL.md +179 -0
  211. package/plugins/skills/layer1-validation/SKILL.md +79 -0
  212. package/plugins/skills/pending-dashboard/SKILL.md +109 -0
  213. package/plugins/skills/project-evolution/SKILL.md +847 -0
  214. package/plugins/skills/requirement-stage/SKILL.md +183 -0
  215. package/plugins/skills/skill-forge/SKILL.md +223 -0
  216. package/plugins/skills/skill-forge/references/description-guide.md +92 -0
  217. package/plugins/skills/skill-forge/references/quality-rubric.md +104 -0
  218. package/plugins/skills/skill-forge/references/skill-template.md +106 -0
  219. package/plugins/skills/startup-guard/SKILL.md +38 -0
  220. package/plugins/skills/testing-stage/SKILL.md +195 -0
  221. package/scripts/cli/global-init.js +288 -0
  222. package/scripts/cli/global.js +324 -0
  223. package/scripts/cli/index.js +55 -0
  224. package/scripts/cli/init.js +382 -0
  225. package/scripts/cli/list.js +69 -0
  226. package/scripts/cli/org.js +340 -0
  227. package/scripts/cli/update.js +44 -0
  228. package/scripts/config/commands.config.js +145 -0
  229. package/scripts/config/hooks.config.js +197 -0
  230. package/scripts/evolution/evolution-router.js +273 -0
  231. package/scripts/evolution/evolution-signal-collector.js +307 -0
  232. package/scripts/evolution/knowledge-loader.js +346 -0
  233. package/scripts/evolution/marketplace.js +317 -0
  234. package/scripts/evolution/version-manager.js +371 -0
  235. package/scripts/install/agents.js +106 -0
  236. package/scripts/install/commands.js +133 -0
  237. package/scripts/install/constants.js +424 -0
  238. package/scripts/install/hook-logger.js +536 -0
  239. package/scripts/install/hooks.js +110 -0
  240. package/scripts/install/index.js +39 -0
  241. package/scripts/install/skills.js +95 -0
  242. package/scripts/postinstall.js +25 -0
  243. package/scripts/state.js +376 -0
@@ -0,0 +1,254 @@
1
+ ---
2
+ name: test-runner
3
+ description: 运行项目测试并收集结果,为 field-evolve 和 validate 命令提供数据支撑
4
+ type: skill
5
+ ---
6
+
7
+ # 测试运行器
8
+
9
+ ## 定位
10
+
11
+ 运行项目的编译、测试、Lint 等确定性验证,收集执行结果供 AI 分析。
12
+
13
+ ---
14
+
15
+ ## 支持的验证类型
16
+
17
+ ### 1. 编译检查
18
+
19
+ | 语言/框架 | 命令 |
20
+ |----------|------|
21
+ | Node.js/TypeScript | `npm run build` 或 `tsc --noEmit` |
22
+ | Java/Maven | `mvn compile` |
23
+ | Java/Gradle | `./gradlew compileJava` |
24
+ | Python | `python -m py_compile` 或无(解释型) |
25
+ | Go | `go build ./...` |
26
+ | Rust | `cargo build` |
27
+
28
+ ### 2. 单元测试
29
+
30
+ | 语言/框架 | 命令 |
31
+ |----------|------|
32
+ | Node.js/Jest | `npm test` 或 `npx jest` |
33
+ | Node.js/Vitest | `npm test` 或 `npx vitest run` |
34
+ | Node.js/Mocha | `npm test` 或 `npx mocha` |
35
+ | Python/pytest | `pytest` |
36
+ | Python/unittest | `python -m unittest` |
37
+ | Java/Maven | `mvn test` |
38
+ | Java/Gradle | `./gradlew test` |
39
+ | Go | `go test ./...` |
40
+ | Rust | `cargo test` |
41
+
42
+ ### 3. Lint 检查
43
+
44
+ | 语言/框架 | 命令 |
45
+ |----------|------|
46
+ | JavaScript/ESLint | `npm run lint` 或 `npx eslint .` |
47
+ | TypeScript/ESLint | `npx eslint . --ext .ts,.tsx` |
48
+ | Python/Flake8 | `flake8 .` |
49
+ | Python/Pylint | `pylint **/*.py` |
50
+ | Java/Checkstyle | `mvn checkstyle:check` |
51
+ | Go/golint | `golint ./...` |
52
+ | Rust/Clippy | `cargo clippy` |
53
+
54
+ ### 4. 类型检查
55
+
56
+ | 语言/框架 | 命令 |
57
+ |----------|------|
58
+ | TypeScript | `tsc --noEmit` |
59
+ | Python/mypy | `mypy .` |
60
+ | Go | 内置于编译 |
61
+ | Rust | 内置于编译 |
62
+
63
+ ---
64
+
65
+ ## 输出格式
66
+
67
+ 测试结果输出到 `.autospec/runtime/test-result.json`:
68
+
69
+ ```json
70
+ {
71
+ "timestamp": "2024-01-15T10:30:00Z",
72
+ "project": {
73
+ "name": "my-project",
74
+ "techStack": "Node.js/TypeScript",
75
+ "subsystems": [
76
+ {
77
+ "name": "backend",
78
+ "path": "backend",
79
+ "type": "backend"
80
+ },
81
+ {
82
+ "name": "frontend",
83
+ "path": "frontend",
84
+ "type": "frontend"
85
+ }
86
+ ]
87
+ },
88
+ "results": {
89
+ "compile": {
90
+ "status": "pass",
91
+ "duration": 5.2,
92
+ "output": "...",
93
+ "errors": []
94
+ },
95
+ "test": {
96
+ "status": "fail",
97
+ "duration": 12.5,
98
+ "output": "...",
99
+ "summary": {
100
+ "total": 50,
101
+ "passed": 47,
102
+ "failed": 3,
103
+ "skipped": 0
104
+ },
105
+ "coverage": {
106
+ "lines": 78.5,
107
+ "branches": 65.2,
108
+ "functions": 82.1
109
+ },
110
+ "failures": [
111
+ {
112
+ "file": "tests/auth.test.ts",
113
+ "name": "should authenticate user",
114
+ "line": 45,
115
+ "message": "Expected status 200 but got 401",
116
+ "stack": "Error: Expected status 200..."
117
+ }
118
+ ]
119
+ },
120
+ "lint": {
121
+ "status": "pass",
122
+ "duration": 2.1,
123
+ "output": "...",
124
+ "warnings": [
125
+ {
126
+ "file": "src/utils/helper.ts",
127
+ "line": 15,
128
+ "rule": "no-unused-vars",
129
+ "message": "'temp' is declared but never used"
130
+ }
131
+ ]
132
+ },
133
+ "typecheck": {
134
+ "status": "pass",
135
+ "duration": 3.5,
136
+ "output": "...",
137
+ "errors": []
138
+ }
139
+ },
140
+ "overall": {
141
+ "status": "fail",
142
+ "passedChecks": ["compile", "lint", "typecheck"],
143
+ "failedChecks": ["test"]
144
+ }
145
+ }
146
+ ```
147
+
148
+ ---
149
+
150
+ ## 执行步骤
151
+
152
+ ### Step 1: 确定技术栈
153
+
154
+ ```
155
+ 1. 读取 .autospec/runtime/config.json
156
+ 2. 获取 techStack 和 subsystems 信息
157
+ 3. 确定要执行的验证类型
158
+ ```
159
+
160
+ ### Step 2: 执行验证
161
+
162
+ ```
163
+ 对每个子系统(或单系统):
164
+ 1. 执行编译检查
165
+ 2. 编译通过后执行单元测试
166
+ 3. 执行 Lint 检查
167
+ 4. 执行类型检查(如适用)
168
+ ```
169
+
170
+ ### Step 3: 收集结果
171
+
172
+ ```
173
+ 1. 捕获命令输出
174
+ 2. 解析测试结果
175
+ 3. 提取覆盖率数据(如有)
176
+ 4. 收集错误和警告信息
177
+ ```
178
+
179
+ ### Step 4: 汇总报告
180
+
181
+ ```
182
+ 1. 合并各子系统结果
183
+ 2. 计算总体状态
184
+ 3. 输出到 .autospec/runtime/test-result.json
185
+ ```
186
+
187
+ ---
188
+
189
+ ## 命令检测逻辑
190
+
191
+ 自动检测项目使用的测试框架:
192
+
193
+ ```javascript
194
+ // 检测 Jest
195
+ if (exists('jest.config.js') ||
196
+ packageJson.devDependencies?.jest) {
197
+ testCommand = 'npx jest --json --outputFile=test-result.json'
198
+ }
199
+
200
+ // 检测 Vitest
201
+ if (exists('vitest.config.ts') ||
202
+ packageJson.devDependencies?.vitest) {
203
+ testCommand = 'npx vitest run --reporter=json'
204
+ }
205
+
206
+ // 检测 pytest
207
+ if (exists('pytest.ini') ||
208
+ exists('pyproject.toml') && contains('[tool.pytest')) {
209
+ testCommand = 'pytest --json-report'
210
+ }
211
+ ```
212
+
213
+ ---
214
+
215
+ ## 错误处理
216
+
217
+ | 场景 | 处理方式 |
218
+ |------|---------|
219
+ | 命令不存在 | 跳过该检查,记录警告 |
220
+ | 超时 | 默认 5 分钟,可配置 |
221
+ | 内存不足 | 建议用户增加资源 |
222
+ | 权限不足 | 建议用户检查权限 |
223
+
224
+ ---
225
+
226
+ ## 多系统支持
227
+
228
+ 对于多子系统项目:
229
+
230
+ ```
231
+ 1. 按子系统顺序执行(backend → frontend → ...)
232
+ 2. 每个子系统独立收集结果
233
+ 3. 汇总时标记各子系统状态
234
+ 4. 一个子系统失败不影响其他子系统执行
235
+ ```
236
+
237
+ ---
238
+
239
+ ## 注意事项
240
+
241
+ 1. **性能优化**:
242
+ - 并行执行独立的检查
243
+ - 使用增量测试(如支持)
244
+ - 缓存编译结果
245
+
246
+ 2. **结果解析**:
247
+ - 支持多种测试框架的输出格式
248
+ - 提取覆盖率数据
249
+ - 解析错误堆栈
250
+
251
+ 3. **环境隔离**:
252
+ - 不修改项目文件
253
+ - 结果输出到 .autospec/runtime/
254
+ - 清理临时文件
@@ -0,0 +1,352 @@
1
+ # 系统设计指南
2
+
3
+ > **版本**: v1.0
4
+ > **最后更新**: 2026-03-26
5
+ > **基于**: 业界系统设计最佳实践 / 结构化设计方法
6
+ > **适用范围**: 所有系统设计场景
7
+
8
+ ---
9
+
10
+ ## 目标
11
+
12
+ 基于 proposal.md 或用户描述的需求,进行两步生成系统设计文档(design.md)。
13
+
14
+ ---
15
+
16
+ ## 两步生成法
17
+
18
+ ### 设计哲学
19
+
20
+ **Phase 1: 大纲生成** → **Phase 2: 逐个细化**
21
+
22
+ ```
23
+ Phase 1 (大纲) Phase 2 (详设)
24
+ ↓ ↓
25
+ 功能点列表 逐个功能点写详设
26
+ 全部标记 - [ ] 每完成一个打钩 - [x]
27
+ ↓ ↓
28
+ 用户确认方向 进度可视化
29
+ ```
30
+
31
+ ### 优势
32
+
33
+ 1. **避免整体返工**: 用户先确认大纲方向,再细化
34
+ 2. **可中断**: 逐个细化可中断,完成部分可直接使用
35
+ 3. **进度可视化**: 用户随时知道完成度
36
+ 4. **即时反馈**: 每完成一个功能点即可 review
37
+
38
+ ---
39
+
40
+ ## 设计文档模板结构
41
+
42
+ ```markdown
43
+ # Design: {需求名}/{系统名}
44
+
45
+ ## 1. 项目背景
46
+ **目标**: {一句话描述}
47
+ **参与人**: PM: xx, 开发:xx, 测试:xx
48
+ **相关文档**: [proposal.md](../proposal.md)
49
+
50
+ ## 2. 业务用例
51
+ [Mermaid flowchart - 从 proposal 中提取本系统相关用例]
52
+
53
+ ## 3. 功能设计
54
+
55
+ ### 3.1 功能点列表
56
+ - [ ] **FP-01**: {功能点 1 名称} - {简要描述}
57
+ - [ ] **FP-02**: {功能点 2 名称} - {简要描述}
58
+ - [ ] **FP-03**: {功能点 3 名称} - {简要描述}
59
+
60
+ ### 3.2 详细设计
61
+
62
+ #### 3.2.1 FP-01: {功能点 1 名称}
63
+ > ⏳ 待细化
64
+
65
+ #### 3.2.2 FP-02: {功能点 2 名称}
66
+ > ⏳ 待细化
67
+
68
+ #### 3.2.3 FP-03: {功能点 3 名称}
69
+ > ⏳ 待细化
70
+
71
+ ## 4. 领域模型 (可选)
72
+ ## 5. 发布依赖 (涉及共享组件/依赖库变更时必须)
73
+ ## 6. 风险分析 (可选)
74
+ ```
75
+
76
+ ---
77
+
78
+ ## 设计原则
79
+
80
+ ### 1. 描述方法职责,不平铺实现代码
81
+
82
+ **错误示例**:
83
+ ```markdown
84
+ ### 3.2.1 FP-01: 创建订单
85
+
86
+ 实现代码:
87
+ ```java
88
+ public Order createOrder(OrderRequest request) {
89
+ // 1. 参数校验
90
+ if (request == null) {
91
+ throw new IllegalArgumentException("请求不能为空");
92
+ }
93
+ // 2. 查询用户
94
+ User user = userRepository.findById(request.getUserId());
95
+ // ... 更多实现
96
+ }
97
+ ```
98
+ ```
99
+
100
+ **正确示例**:
101
+ ```markdown
102
+ ### 3.2.1 FP-01: 创建订单
103
+
104
+ **职责**: 接收订单创建请求,校验参数后创建订单记录
105
+
106
+ **输入**: OrderRequest (userId, productId, amount)
107
+
108
+ **处理**:
109
+ 1. 参数校验(非空、格式、业务规则)
110
+ 2. 用户存在性校验
111
+ 3. 库存预占
112
+ 4. 创建订单记录,状态为"待支付"
113
+ 5. 发送订单创建事件
114
+
115
+ **输出**: Order (orderId, status, createTime)
116
+
117
+ **异常**:
118
+ - IllegalArgumentException: 参数校验失败
119
+ - UserNotFoundException: 用户不存在
120
+ - StockNotEnoughException: 库存不足
121
+ ```
122
+
123
+ ### 2. 功能点职责清晰不重叠
124
+
125
+ **错误示例**:
126
+ ```markdown
127
+ #### FP-01: 用户注册
128
+ 处理用户注册请求,验证手机号,发送验证码,创建用户记录
129
+
130
+ #### FP-02: 发送验证码
131
+ 接收手机号,生成验证码,发送短信,存储验证码
132
+ ```
133
+ 问题:FP-01 和 FP-02 职责重叠,"发送验证码"逻辑重复
134
+
135
+ **正确示例**:
136
+ ```markdown
137
+ #### FP-01: 用户注册
138
+ 处理用户注册请求,调用 FP-02 发送验证码,创建用户记录
139
+
140
+ #### FP-02: 发送验证码
141
+ 接收手机号,生成验证码,发送短信,存储验证码(供 FP-01 和其他场景调用)
142
+ ```
143
+
144
+ ### 3. 开关/配置只加必要的
145
+
146
+ **原则**:
147
+ - 能由调用方控制的不在本系统加开关
148
+ - 新增配置必须有明确的业务场景
149
+ - 避免过度配置导致维护成本
150
+
151
+ **错误示例**:
152
+ ```markdown
153
+ 新增 DRM 配置:
154
+ - enableOrderCreate: 是否开启订单创建
155
+ - enableOrderUpdate: 是否开启订单更新
156
+ - enableOrderDelete: 是否开启订单删除
157
+ - logLevel: 日志级别
158
+ - timeout: 超时时间
159
+ - retryCount: 重试次数
160
+ ```
161
+
162
+ **正确示例**:
163
+ ```markdown
164
+ 新增 DRM 配置:
165
+ - orderCreateEnabled: 订单创建开关(用于应急降级)
166
+ ```
167
+
168
+ ### 4. 共享组件/依赖库变更必须说明
169
+
170
+ 涉及共享组件(SPI/Facade/依赖库)模型变更时,必须说明:
171
+
172
+ | 字段 | 说明 |
173
+ |------|------|
174
+ | Maven 坐标 | groupId:artifactId |
175
+ | 当前版本 | 当前使用的版本 |
176
+ | 升级版本 | 计划升级的版本 |
177
+ | 变更内容 | 具体变更了什么 |
178
+ | 需升级的系统 | 哪些系统需要同步升级 |
179
+
180
+ ---
181
+
182
+ ## 详细设计单点模板
183
+
184
+ ```markdown
185
+ ### 3.2.{N} FP-{NN}: {功能点名称}
186
+
187
+ **概述**
188
+ {功能点的业务目标和实现思路}
189
+
190
+ **流程图** (可选)
191
+ ```mermaid
192
+ sequenceDiagram
193
+ participant U as 用户/上游
194
+ participant S as 本系统
195
+ participant D as 下游系统
196
+
197
+ U->>S: 1. 请求描述
198
+ S->>D: 2. 调用下游
199
+ D-->>S: 3. 返回结果
200
+ S-->>U: 4. 响应
201
+ ```
202
+
203
+ **下游交互** (可选)
204
+ {描述与下游系统的交互细节}
205
+
206
+ **对外接口** (可选)
207
+ {描述对外提供的接口定义}
208
+
209
+ **异常处理** (可选)
210
+ {描述异常处理逻辑}
211
+
212
+ **业务规则** (可选)
213
+ {描述涉及的业务规则}
214
+ ```
215
+
216
+ ---
217
+
218
+ ## 设计文档质量检查
219
+
220
+ ### Phase 1 检查点
221
+
222
+ - [ ] 项目背景填写完整
223
+ - [ ] 业务用例图从 proposal 正确提取
224
+ - [ ] 功能点列表完整,覆盖 proposal 所有功能
225
+ - [ ] 功能点命名清晰,职责单一
226
+ - [ ] 详细设计章节占位符正确
227
+
228
+ ### Phase 2 检查点
229
+
230
+ - [ ] 所有功能点已标记为 `[x]` 完成
231
+ - [ ] 每个功能点都有详细设计内容
232
+ - [ ] 流程图可正常渲染
233
+ - [ ] 与 proposal.md 业务流程一致
234
+ - [ ] 遵循系统架构规范
235
+
236
+ ### 设计原则检查
237
+
238
+ - [ ] 无实现代码平铺(方法设计只描述职责、入参、输出)
239
+ - [ ] 功能点职责不重叠(无多个功能点重复描述同一逻辑)
240
+ - [ ] 开关/配置无过度设计
241
+ - [ ] 新增配置与项目已有配置声明方式一致
242
+ - [ ] 共享组件/依赖库模型变更已说明版本升级方案
243
+
244
+ ---
245
+
246
+ ## 领域模型设计指南
247
+
248
+ ### 4.1 模型设计
249
+
250
+ 使用 Mermaid classDiagram 描述领域模型:
251
+
252
+ ```mermaid
253
+ classDiagram
254
+ class Order {
255
+ +Long orderId
256
+ +String userId
257
+ +OrderStatus status
258
+ +Money amount
259
+ +confirm()
260
+ +cancel()
261
+ }
262
+ class OrderStatus {
263
+ <<enumeration>>
264
+ INIT
265
+ PAYING
266
+ SUCCESS
267
+ CANCELLED
268
+ }
269
+ Order --> OrderStatus
270
+ ```
271
+
272
+ ### 4.2 状态机
273
+
274
+ 使用 Mermaid stateDiagram 描述状态流转:
275
+
276
+ ```mermaid
277
+ stateDiagram-v2
278
+ [*] --> INIT: 创建订单
279
+ INIT --> PAYING: 发起支付
280
+ PAYING --> SUCCESS: 支付成功
281
+ PAYING --> CANCELLED: 支付失败/超时
282
+ CANCELLED --> [*]
283
+ SUCCESS --> [*]
284
+ ```
285
+
286
+ ### 4.3 数据库设计
287
+
288
+ 使用 Mermaid erDiagram 或表格描述:
289
+
290
+ ```mermaid
291
+ erDiagram
292
+ USER ||--o{ ORDER : places
293
+ ORDER ||--|{ ORDER_ITEM : contains
294
+ PRODUCT ||--o{ ORDER_ITEM : included_in
295
+ ```
296
+
297
+ ---
298
+
299
+ ## 多系统设计指南
300
+
301
+ ### 设计文档组织
302
+
303
+ ```
304
+ requirements/{业务域}/{需求}/
305
+ ├── proposal.md # 整体需求提案
306
+ └── design/
307
+ ├── overview.md # 整体架构设计
308
+ ├── backend.md # 后端系统设计
309
+ ├── frontend.md # 前端系统设计
310
+ ├── ai.md # AI/模型设计(如需要)
311
+ └── data.md # 数据管道设计(如需要)
312
+ ```
313
+
314
+ ### 设计顺序
315
+
316
+ **有依赖关系的系统**:
317
+ 1. 先设计被依赖的系统(如后端 API)
318
+ 2. 再设计调用方系统(如前端、移动端)
319
+
320
+ **可并行的系统**:
321
+ 1. 先定义契约(API Schema、数据 Schema)
322
+ 2. 各系统基于契约并行设计
323
+
324
+ ### 跨系统设计检查
325
+
326
+ - [ ] 系统间接口定义清晰
327
+ - [ ] 数据一致性方案明确
328
+ - [ ] 超时/重试/降级策略一致
329
+ - [ ] 错误码定义统一
330
+ - [ ] 监控指标对齐
331
+
332
+ ---
333
+
334
+ ## 最佳实践
335
+
336
+ 1. **两步生成**: Phase 1 大纲 → Phase 2 详设,避免整体返工
337
+ 2. **流程图优先**: 能用图表达的不用文字
338
+ 3. **职责单一**: 每个功能点职责清晰不重叠
339
+ 4. **领域模型**: 核心业务逻辑内聚到领域对象
340
+ 5. **状态机**: 复杂状态流转用状态图描述
341
+ 6. **多系统**: 先契约后实现,支持并行设计
342
+ 7. **发布依赖**: 涉及共享组件/依赖库必须说明升级方案
343
+
344
+ ---
345
+
346
+ ## 参考资料
347
+
348
+ - [design 模板](../templates/design.md)
349
+ - [design 检查清单](../checklists/design.md)
350
+ - [设计哲学 - 两步生成](../principles/design-philosophy.md#核心设计模式)
351
+ - [编码规范](../standards/coding-style.md)
352
+ - [数据一致性规范](../standards/data-consistency.md)