universal-dev-standards 5.0.0-rc.8 → 5.0.0

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 (355) hide show
  1. package/bin/uds.js +5 -3
  2. package/bundled/ai/standards/acceptance-criteria-traceability.ai.yaml +178 -0
  3. package/bundled/ai/standards/agent-dispatch.ai.yaml +69 -0
  4. package/bundled/ai/standards/ai-command-behavior.ai.yaml +45 -0
  5. package/bundled/ai/standards/api-design-standards.ai.yaml +192 -0
  6. package/bundled/ai/standards/branch-completion.ai.yaml +82 -0
  7. package/bundled/ai/standards/change-batching-standards.ai.yaml +195 -0
  8. package/bundled/ai/standards/database-standards.ai.yaml +220 -0
  9. package/bundled/ai/standards/error-codes.ai.yaml +37 -2
  10. package/bundled/ai/standards/git-worktree.ai.yaml +77 -0
  11. package/bundled/ai/standards/logging.ai.yaml +21 -2
  12. package/bundled/ai/standards/model-selection.ai.yaml +81 -0
  13. package/bundled/ai/standards/pipeline-integration-standards.ai.yaml +184 -0
  14. package/bundled/ai/standards/systematic-debugging.ai.yaml +73 -0
  15. package/bundled/ai/standards/verification-evidence.ai.yaml +84 -0
  16. package/bundled/ai/standards/workflow-enforcement.ai.yaml +253 -0
  17. package/bundled/core/acceptance-criteria-traceability.md +293 -0
  18. package/bundled/core/agent-dispatch.md +149 -0
  19. package/bundled/core/ai-command-behavior.md +239 -0
  20. package/bundled/core/api-design-standards.md +938 -0
  21. package/bundled/core/branch-completion.md +158 -0
  22. package/bundled/core/change-batching-standards.md +257 -0
  23. package/bundled/core/checkin-standards.md +43 -6
  24. package/bundled/core/database-standards.md +828 -0
  25. package/bundled/core/error-code-standards.md +228 -2
  26. package/bundled/core/forward-derivation-standards.md +54 -2
  27. package/bundled/core/git-worktree.md +131 -0
  28. package/bundled/core/model-selection.md +153 -0
  29. package/bundled/core/pipeline-integration-standards.md +230 -0
  30. package/bundled/core/systematic-debugging.md +156 -0
  31. package/bundled/core/testing-standards.md +49 -39
  32. package/bundled/core/verification-evidence.md +172 -0
  33. package/bundled/core/workflow-enforcement.md +132 -0
  34. package/bundled/locales/zh-CN/CLAUDE.md +2 -2
  35. package/bundled/locales/zh-CN/README.md +4 -4
  36. package/bundled/locales/zh-CN/SECURITY.md +92 -0
  37. package/bundled/locales/zh-CN/core/acceptance-criteria-traceability.md +301 -0
  38. package/bundled/locales/zh-CN/core/acceptance-test-driven-development.md +47 -0
  39. package/bundled/locales/zh-CN/core/accessibility-standards.md +124 -0
  40. package/bundled/locales/zh-CN/core/agent-dispatch.md +113 -0
  41. package/bundled/locales/zh-CN/core/ai-agreement-standards.md +103 -0
  42. package/bundled/locales/zh-CN/core/ai-command-behavior.md +247 -0
  43. package/bundled/locales/zh-CN/core/api-design-standards.md +946 -0
  44. package/bundled/locales/zh-CN/core/behavior-driven-development.md +48 -0
  45. package/bundled/locales/zh-CN/core/branch-completion.md +112 -0
  46. package/bundled/locales/zh-CN/core/change-batching-standards.md +265 -0
  47. package/bundled/locales/zh-CN/core/checkin-standards.md +43 -5
  48. package/bundled/locales/zh-CN/core/context-aware-loading.md +106 -0
  49. package/bundled/locales/zh-CN/core/database-standards.md +836 -0
  50. package/bundled/locales/zh-CN/core/deployment-standards.md +80 -0
  51. package/bundled/locales/zh-CN/core/error-code-standards.md +2 -2
  52. package/bundled/locales/zh-CN/core/forward-derivation-standards.md +493 -0
  53. package/bundled/locales/zh-CN/core/git-worktree.md +101 -0
  54. package/bundled/locales/zh-CN/core/model-selection.md +112 -0
  55. package/bundled/locales/zh-CN/core/performance-standards.md +104 -0
  56. package/bundled/locales/zh-CN/core/pipeline-integration-standards.md +238 -0
  57. package/bundled/locales/zh-CN/core/project-context-memory.md +124 -0
  58. package/bundled/locales/zh-CN/core/requirement-engineering.md +49 -0
  59. package/bundled/locales/zh-CN/core/security-standards.md +100 -0
  60. package/bundled/locales/zh-CN/core/systematic-debugging.md +106 -0
  61. package/bundled/locales/zh-CN/core/test-governance.md +116 -0
  62. package/bundled/locales/zh-CN/core/testing-standards.md +392 -156
  63. package/bundled/locales/zh-CN/core/verification-evidence.md +118 -0
  64. package/bundled/locales/zh-CN/core/virtual-organization-standards.md +104 -0
  65. package/bundled/locales/zh-CN/core/workflow-enforcement.md +132 -0
  66. package/bundled/locales/zh-CN/docs/CHEATSHEET.md +27 -1
  67. package/bundled/locales/zh-CN/docs/CLI-INIT-OPTIONS.md +9 -1
  68. package/bundled/locales/zh-CN/docs/FEATURE-REFERENCE.md +37 -9
  69. package/bundled/locales/zh-CN/docs/USER-MANUAL.md +652 -0
  70. package/bundled/locales/zh-CN/integrations/github-copilot/copilot-instructions.md +1 -1
  71. package/bundled/locales/zh-CN/integrations/openspec/AGENTS.md +29 -4
  72. package/bundled/locales/zh-CN/integrations/spec-kit/AGENTS.md +143 -72
  73. package/bundled/locales/zh-CN/skills/ac-coverage-assistant/SKILL.md +126 -0
  74. package/bundled/locales/zh-CN/skills/api-design-assistant/SKILL.md +100 -0
  75. package/bundled/locales/zh-CN/skills/brainstorm-assistant/SKILL.md +119 -0
  76. package/bundled/locales/zh-CN/skills/ci-cd-assistant/SKILL.md +82 -0
  77. package/bundled/locales/zh-CN/skills/commands/ac-coverage.md +97 -0
  78. package/bundled/locales/zh-CN/skills/commands/api-design.md +94 -0
  79. package/bundled/locales/zh-CN/skills/commands/atdd.md +163 -0
  80. package/bundled/locales/zh-CN/skills/commands/audit.md +77 -0
  81. package/bundled/locales/zh-CN/skills/commands/bdd.md +1 -1
  82. package/bundled/locales/zh-CN/skills/commands/brainstorm.md +87 -0
  83. package/bundled/locales/zh-CN/skills/commands/changelog.md +63 -0
  84. package/bundled/locales/zh-CN/skills/commands/check.md +219 -0
  85. package/bundled/locales/zh-CN/skills/commands/checkin.md +61 -0
  86. package/bundled/locales/zh-CN/skills/commands/ci-cd.md +77 -0
  87. package/bundled/locales/zh-CN/skills/commands/commit.md +81 -0
  88. package/bundled/locales/zh-CN/skills/commands/config.md +207 -0
  89. package/bundled/locales/zh-CN/skills/commands/coverage.md +74 -0
  90. package/bundled/locales/zh-CN/skills/commands/database.md +78 -0
  91. package/bundled/locales/zh-CN/skills/commands/derive-all.md +58 -0
  92. package/bundled/locales/zh-CN/skills/commands/derive-atdd.md +54 -0
  93. package/bundled/locales/zh-CN/skills/commands/derive-bdd.md +53 -0
  94. package/bundled/locales/zh-CN/skills/commands/derive-tdd.md +54 -0
  95. package/bundled/locales/zh-CN/skills/commands/derive.md +78 -0
  96. package/bundled/locales/zh-CN/skills/commands/dev-workflow.md +119 -0
  97. package/bundled/locales/zh-CN/skills/commands/discover.md +86 -0
  98. package/bundled/locales/zh-CN/skills/commands/docgen.md +67 -0
  99. package/bundled/locales/zh-CN/skills/commands/docs.md +65 -0
  100. package/bundled/locales/zh-CN/skills/commands/durable.md +87 -0
  101. package/bundled/locales/zh-CN/skills/commands/guide.md +52 -0
  102. package/bundled/locales/zh-CN/skills/commands/incident.md +92 -0
  103. package/bundled/locales/zh-CN/skills/commands/init.md +272 -0
  104. package/bundled/locales/zh-CN/skills/commands/methodology.md +1 -1
  105. package/bundled/locales/zh-CN/skills/commands/metrics.md +73 -0
  106. package/bundled/locales/zh-CN/skills/commands/migrate.md +92 -0
  107. package/bundled/locales/zh-CN/skills/commands/pr.md +80 -0
  108. package/bundled/locales/zh-CN/skills/commands/refactor.md +1 -1
  109. package/bundled/locales/zh-CN/skills/commands/release.md +62 -0
  110. package/bundled/locales/zh-CN/skills/commands/requirement.md +54 -0
  111. package/bundled/locales/zh-CN/skills/commands/reverse-bdd.md +47 -0
  112. package/bundled/locales/zh-CN/skills/commands/reverse-sdd.md +51 -0
  113. package/bundled/locales/zh-CN/skills/commands/reverse-tdd.md +51 -0
  114. package/bundled/locales/zh-CN/skills/commands/reverse.md +63 -0
  115. package/bundled/locales/zh-CN/skills/commands/review.md +50 -0
  116. package/bundled/locales/zh-CN/skills/commands/scan.md +76 -0
  117. package/bundled/locales/zh-CN/skills/commands/sdd-retro.md +40 -0
  118. package/bundled/locales/zh-CN/skills/commands/sdd.md +379 -0
  119. package/bundled/locales/zh-CN/skills/commands/security.md +75 -0
  120. package/bundled/locales/zh-CN/skills/commands/tdd.md +111 -0
  121. package/bundled/locales/zh-CN/skills/commands/update.md +337 -0
  122. package/bundled/locales/zh-CN/skills/commit-standards/SKILL.md +1 -2
  123. package/bundled/locales/zh-CN/skills/database-assistant/SKILL.md +97 -0
  124. package/bundled/locales/zh-CN/skills/dev-workflow-guide/SKILL.md +145 -0
  125. package/bundled/locales/zh-CN/skills/durable-execution-assistant/SKILL.md +84 -0
  126. package/bundled/locales/zh-CN/skills/incident-response-assistant/SKILL.md +107 -0
  127. package/bundled/locales/zh-CN/skills/metrics-dashboard-assistant/SKILL.md +67 -0
  128. package/bundled/locales/zh-CN/skills/migration-assistant/SKILL.md +77 -0
  129. package/bundled/locales/zh-CN/skills/pr-automation-assistant/SKILL.md +90 -0
  130. package/bundled/locales/zh-CN/skills/security-assistant/SKILL.md +79 -0
  131. package/bundled/locales/zh-CN/skills/security-scan-assistant/SKILL.md +72 -0
  132. package/bundled/locales/zh-CN/skills/spec-driven-dev/SKILL.md +73 -10
  133. package/bundled/locales/zh-CN/skills/spec-driven-dev/guide.md +267 -122
  134. package/bundled/locales/zh-TW/CLAUDE.md +2 -2
  135. package/bundled/locales/zh-TW/README.md +4 -4
  136. package/bundled/locales/zh-TW/SECURITY.md +92 -0
  137. package/bundled/locales/zh-TW/core/acceptance-criteria-traceability.md +301 -0
  138. package/bundled/locales/zh-TW/core/acceptance-test-driven-development.md +47 -0
  139. package/bundled/locales/zh-TW/core/accessibility-standards.md +84 -0
  140. package/bundled/locales/zh-TW/core/agent-dispatch.md +89 -0
  141. package/bundled/locales/zh-TW/core/ai-agreement-standards.md +87 -0
  142. package/bundled/locales/zh-TW/core/ai-command-behavior.md +247 -0
  143. package/bundled/locales/zh-TW/core/api-design-standards.md +946 -0
  144. package/bundled/locales/zh-TW/core/behavior-driven-development.md +63 -0
  145. package/bundled/locales/zh-TW/core/branch-completion.md +76 -0
  146. package/bundled/locales/zh-TW/core/change-batching-standards.md +265 -0
  147. package/bundled/locales/zh-TW/core/checkin-standards.md +39 -5
  148. package/bundled/locales/zh-TW/core/context-aware-loading.md +86 -0
  149. package/bundled/locales/zh-TW/core/database-standards.md +836 -0
  150. package/bundled/locales/zh-TW/core/deployment-standards.md +66 -0
  151. package/bundled/locales/zh-TW/core/error-code-standards.md +230 -4
  152. package/bundled/locales/zh-TW/core/forward-derivation-standards.md +62 -2
  153. package/bundled/locales/zh-TW/core/git-worktree.md +104 -0
  154. package/bundled/locales/zh-TW/core/model-selection.md +83 -0
  155. package/bundled/locales/zh-TW/core/performance-standards.md +84 -0
  156. package/bundled/locales/zh-TW/core/pipeline-integration-standards.md +238 -0
  157. package/bundled/locales/zh-TW/core/project-context-memory.md +79 -0
  158. package/bundled/locales/zh-TW/core/requirement-engineering.md +79 -0
  159. package/bundled/locales/zh-TW/core/security-standards.md +74 -0
  160. package/bundled/locales/zh-TW/core/systematic-debugging.md +95 -0
  161. package/bundled/locales/zh-TW/core/test-governance.md +88 -0
  162. package/bundled/locales/zh-TW/core/testing-standards.md +309 -86
  163. package/bundled/locales/zh-TW/core/verification-evidence.md +94 -0
  164. package/bundled/locales/zh-TW/core/virtual-organization-standards.md +88 -0
  165. package/bundled/locales/zh-TW/core/workflow-enforcement.md +132 -0
  166. package/bundled/locales/zh-TW/docs/CHEATSHEET.md +27 -1
  167. package/bundled/locales/zh-TW/docs/CLI-INIT-OPTIONS.md +9 -1
  168. package/bundled/locales/zh-TW/docs/FEATURE-REFERENCE.md +37 -9
  169. package/bundled/locales/zh-TW/docs/USER-MANUAL.md +652 -0
  170. package/bundled/locales/zh-TW/integrations/github-copilot/copilot-instructions.md +1 -1
  171. package/bundled/locales/zh-TW/integrations/openspec/AGENTS.md +29 -4
  172. package/bundled/locales/zh-TW/integrations/spec-kit/AGENTS.md +142 -71
  173. package/bundled/locales/zh-TW/skills/ac-coverage-assistant/SKILL.md +127 -0
  174. package/bundled/locales/zh-TW/skills/ai-friendly-architecture/SKILL.md +1 -4
  175. package/bundled/locales/zh-TW/skills/ai-instruction-standards/SKILL.md +1 -4
  176. package/bundled/locales/zh-TW/skills/api-design-assistant/SKILL.md +97 -0
  177. package/bundled/locales/zh-TW/skills/atdd-assistant/SKILL.md +1 -4
  178. package/bundled/locales/zh-TW/skills/audit-assistant/SKILL.md +1 -4
  179. package/bundled/locales/zh-TW/skills/bdd-assistant/SKILL.md +1 -4
  180. package/bundled/locales/zh-TW/skills/brainstorm-assistant/SKILL.md +1 -4
  181. package/bundled/locales/zh-TW/skills/changelog-guide/SKILL.md +1 -4
  182. package/bundled/locales/zh-TW/skills/checkin-assistant/SKILL.md +1 -4
  183. package/bundled/locales/zh-TW/skills/ci-cd-assistant/SKILL.md +79 -0
  184. package/bundled/locales/zh-TW/skills/code-review-assistant/SKILL.md +1 -4
  185. package/bundled/locales/zh-TW/skills/commands/ac-coverage.md +95 -0
  186. package/bundled/locales/zh-TW/skills/commands/api-design.md +92 -0
  187. package/bundled/locales/zh-TW/skills/commands/atdd.md +167 -0
  188. package/bundled/locales/zh-TW/skills/commands/audit.md +75 -0
  189. package/bundled/locales/zh-TW/skills/commands/bdd.md +1 -1
  190. package/bundled/locales/zh-TW/skills/commands/brainstorm.md +91 -0
  191. package/bundled/locales/zh-TW/skills/commands/changelog.md +67 -0
  192. package/bundled/locales/zh-TW/skills/commands/check.md +223 -0
  193. package/bundled/locales/zh-TW/skills/commands/checkin.md +65 -0
  194. package/bundled/locales/zh-TW/skills/commands/ci-cd.md +75 -0
  195. package/bundled/locales/zh-TW/skills/commands/commit.md +85 -0
  196. package/bundled/locales/zh-TW/skills/commands/config.md +211 -0
  197. package/bundled/locales/zh-TW/skills/commands/coverage.md +78 -0
  198. package/bundled/locales/zh-TW/skills/commands/database.md +76 -0
  199. package/bundled/locales/zh-TW/skills/commands/derive-all.md +62 -0
  200. package/bundled/locales/zh-TW/skills/commands/derive-atdd.md +58 -0
  201. package/bundled/locales/zh-TW/skills/commands/derive-bdd.md +54 -0
  202. package/bundled/locales/zh-TW/skills/commands/derive-tdd.md +55 -0
  203. package/bundled/locales/zh-TW/skills/commands/derive.md +79 -0
  204. package/bundled/locales/zh-TW/skills/commands/dev-workflow.md +120 -0
  205. package/bundled/locales/zh-TW/skills/commands/discover.md +87 -0
  206. package/bundled/locales/zh-TW/skills/commands/docgen.md +68 -0
  207. package/bundled/locales/zh-TW/skills/commands/docs.md +66 -0
  208. package/bundled/locales/zh-TW/skills/commands/durable.md +85 -0
  209. package/bundled/locales/zh-TW/skills/commands/guide.md +51 -0
  210. package/bundled/locales/zh-TW/skills/commands/incident.md +90 -0
  211. package/bundled/locales/zh-TW/skills/commands/init.md +273 -0
  212. package/bundled/locales/zh-TW/skills/commands/methodology.md +1 -1
  213. package/bundled/locales/zh-TW/skills/commands/metrics.md +71 -0
  214. package/bundled/locales/zh-TW/skills/commands/migrate.md +90 -0
  215. package/bundled/locales/zh-TW/skills/commands/pr.md +78 -0
  216. package/bundled/locales/zh-TW/skills/commands/refactor.md +1 -1
  217. package/bundled/locales/zh-TW/skills/commands/release.md +63 -0
  218. package/bundled/locales/zh-TW/skills/commands/requirement.md +61 -0
  219. package/bundled/locales/zh-TW/skills/commands/reverse-bdd.md +54 -0
  220. package/bundled/locales/zh-TW/skills/commands/reverse-sdd.md +58 -0
  221. package/bundled/locales/zh-TW/skills/commands/reverse-tdd.md +58 -0
  222. package/bundled/locales/zh-TW/skills/commands/reverse.md +70 -0
  223. package/bundled/locales/zh-TW/skills/commands/review.md +57 -0
  224. package/bundled/locales/zh-TW/skills/commands/scan.md +74 -0
  225. package/bundled/locales/zh-TW/skills/commands/sdd-retro.md +47 -0
  226. package/bundled/locales/zh-TW/skills/commands/sdd.md +362 -0
  227. package/bundled/locales/zh-TW/skills/commands/security.md +73 -0
  228. package/bundled/locales/zh-TW/skills/commands/tdd.md +115 -0
  229. package/bundled/locales/zh-TW/skills/commands/update.md +326 -0
  230. package/bundled/locales/zh-TW/skills/commit-standards/SKILL.md +2 -6
  231. package/bundled/locales/zh-TW/skills/database-assistant/SKILL.md +94 -0
  232. package/bundled/locales/zh-TW/skills/dev-workflow-guide/SKILL.md +140 -0
  233. package/bundled/locales/zh-TW/skills/docs-generator/SKILL.md +1 -4
  234. package/bundled/locales/zh-TW/skills/documentation-guide/SKILL.md +1 -4
  235. package/bundled/locales/zh-TW/skills/durable-execution-assistant/SKILL.md +81 -0
  236. package/bundled/locales/zh-TW/skills/error-code-guide/SKILL.md +1 -4
  237. package/bundled/locales/zh-TW/skills/forward-derivation/SKILL.md +1 -4
  238. package/bundled/locales/zh-TW/skills/git-workflow-guide/SKILL.md +1 -4
  239. package/bundled/locales/zh-TW/skills/incident-response-assistant/SKILL.md +104 -0
  240. package/bundled/locales/zh-TW/skills/logging-guide/SKILL.md +1 -4
  241. package/bundled/locales/zh-TW/skills/methodology-system/SKILL.md +1 -4
  242. package/bundled/locales/zh-TW/skills/metrics-dashboard-assistant/SKILL.md +64 -0
  243. package/bundled/locales/zh-TW/skills/migration-assistant/SKILL.md +74 -0
  244. package/bundled/locales/zh-TW/skills/pr-automation-assistant/SKILL.md +87 -0
  245. package/bundled/locales/zh-TW/skills/project-discovery/SKILL.md +1 -4
  246. package/bundled/locales/zh-TW/skills/refactoring-assistant/SKILL.md +1 -4
  247. package/bundled/locales/zh-TW/skills/release-standards/SKILL.md +1 -4
  248. package/bundled/locales/zh-TW/skills/requirement-assistant/SKILL.md +1 -4
  249. package/bundled/locales/zh-TW/skills/reverse-engineer/SKILL.md +1 -4
  250. package/bundled/locales/zh-TW/skills/security-assistant/SKILL.md +76 -0
  251. package/bundled/locales/zh-TW/skills/security-scan-assistant/SKILL.md +69 -0
  252. package/bundled/locales/zh-TW/skills/spec-driven-dev/SKILL.md +74 -14
  253. package/bundled/locales/zh-TW/skills/spec-driven-dev/guide.md +243 -98
  254. package/bundled/locales/zh-TW/skills/tdd-assistant/SKILL.md +1 -4
  255. package/bundled/locales/zh-TW/skills/test-coverage-assistant/SKILL.md +1 -4
  256. package/bundled/locales/zh-TW/skills/testing-guide/SKILL.md +1 -5
  257. package/bundled/skills/README.md +11 -0
  258. package/bundled/skills/ac-coverage-assistant/SKILL.md +127 -0
  259. package/bundled/skills/ai-collaboration-standards/SKILL.md +10 -0
  260. package/bundled/skills/ai-friendly-architecture/SKILL.md +10 -0
  261. package/bundled/skills/ai-instruction-standards/SKILL.md +10 -0
  262. package/bundled/skills/api-design-assistant/SKILL.md +119 -0
  263. package/bundled/skills/atdd-assistant/SKILL.md +7 -0
  264. package/bundled/skills/bdd-assistant/SKILL.md +7 -0
  265. package/bundled/skills/brainstorm-assistant/SKILL.md +7 -0
  266. package/bundled/skills/checkin-assistant/SKILL.md +7 -0
  267. package/bundled/skills/ci-cd-assistant/SKILL.md +97 -0
  268. package/bundled/skills/code-review-assistant/SKILL.md +7 -0
  269. package/bundled/skills/commands/README.md +70 -0
  270. package/bundled/skills/commands/ac-coverage.md +135 -0
  271. package/bundled/skills/commands/api-design.md +86 -0
  272. package/bundled/skills/commands/atdd.md +69 -0
  273. package/bundled/skills/commands/audit.md +69 -0
  274. package/bundled/skills/commands/bdd.md +101 -0
  275. package/bundled/skills/commands/brainstorm.md +45 -0
  276. package/bundled/skills/commands/changelog.md +34 -0
  277. package/bundled/skills/commands/check.md +52 -1
  278. package/bundled/skills/commands/checkin.md +46 -0
  279. package/bundled/skills/commands/ci-cd.md +69 -0
  280. package/bundled/skills/commands/commit.md +79 -0
  281. package/bundled/skills/commands/config.md +48 -0
  282. package/bundled/skills/commands/coverage.md +53 -0
  283. package/bundled/skills/commands/database.md +70 -0
  284. package/bundled/skills/commands/derive-all.md +40 -0
  285. package/bundled/skills/commands/derive-atdd.md +33 -0
  286. package/bundled/skills/commands/derive-bdd.md +39 -0
  287. package/bundled/skills/commands/derive-tdd.md +40 -0
  288. package/bundled/skills/commands/derive.md +47 -0
  289. package/bundled/skills/commands/dev-workflow.md +104 -7
  290. package/bundled/skills/commands/discover.md +39 -0
  291. package/bundled/skills/commands/docgen.md +35 -0
  292. package/bundled/skills/commands/docs.md +40 -0
  293. package/bundled/skills/commands/durable.md +79 -0
  294. package/bundled/skills/commands/incident.md +84 -0
  295. package/bundled/skills/commands/init.md +55 -0
  296. package/bundled/skills/commands/methodology.md +72 -0
  297. package/bundled/skills/commands/metrics.md +65 -0
  298. package/bundled/skills/commands/migrate.md +84 -0
  299. package/bundled/skills/commands/pr.md +72 -0
  300. package/bundled/skills/commands/refactor.md +51 -0
  301. package/bundled/skills/commands/release.md +60 -0
  302. package/bundled/skills/commands/requirement.md +38 -0
  303. package/bundled/skills/commands/reverse-bdd.md +34 -0
  304. package/bundled/skills/commands/reverse-sdd.md +42 -0
  305. package/bundled/skills/commands/reverse-tdd.md +40 -0
  306. package/bundled/skills/commands/reverse.md +41 -0
  307. package/bundled/skills/commands/review.md +39 -0
  308. package/bundled/skills/commands/scan.md +68 -0
  309. package/bundled/skills/commands/sdd-retro.md +48 -0
  310. package/bundled/skills/commands/sdd.md +220 -0
  311. package/bundled/skills/commands/security.md +67 -0
  312. package/bundled/skills/commands/tdd.md +101 -0
  313. package/bundled/skills/commands/update.md +61 -0
  314. package/bundled/skills/commit-standards/SKILL.md +8 -2
  315. package/bundled/skills/database-assistant/SKILL.md +118 -0
  316. package/bundled/skills/dev-workflow-guide/SKILL.md +53 -7
  317. package/bundled/skills/dev-workflow-guide/workflow-phases.md +24 -0
  318. package/bundled/skills/durable-execution-assistant/SKILL.md +116 -0
  319. package/bundled/skills/forward-derivation/SKILL.md +7 -0
  320. package/bundled/skills/incident-response-assistant/SKILL.md +132 -0
  321. package/bundled/skills/methodology-system/SKILL.md +24 -2
  322. package/bundled/skills/metrics-dashboard-assistant/SKILL.md +109 -0
  323. package/bundled/skills/migration-assistant/SKILL.md +119 -0
  324. package/bundled/skills/pr-automation-assistant/SKILL.md +114 -0
  325. package/bundled/skills/project-discovery/SKILL.md +7 -0
  326. package/bundled/skills/refactoring-assistant/SKILL.md +7 -0
  327. package/bundled/skills/release-standards/SKILL.md +7 -0
  328. package/bundled/skills/requirement-assistant/SKILL.md +7 -0
  329. package/bundled/skills/reverse-engineer/SKILL.md +7 -0
  330. package/bundled/skills/security-assistant/SKILL.md +105 -0
  331. package/bundled/skills/security-scan-assistant/SKILL.md +96 -0
  332. package/bundled/skills/spec-driven-dev/SKILL.md +84 -4
  333. package/bundled/skills/spec-driven-dev/guide.md +156 -22
  334. package/bundled/skills/tdd-assistant/SKILL.md +7 -0
  335. package/bundled/skills/test-coverage-assistant/SKILL.md +11 -0
  336. package/bundled/skills/testing-guide/SKILL.md +23 -0
  337. package/package.json +1 -1
  338. package/src/commands/check.js +154 -8
  339. package/src/commands/config.js +231 -104
  340. package/src/commands/init.js +23 -3
  341. package/src/commands/update.js +250 -25
  342. package/src/config/ai-agent-paths.js +16 -0
  343. package/src/config/workflow-definitions.js +184 -0
  344. package/src/core/constants.js +6 -0
  345. package/src/flows/init-flow.js +23 -6
  346. package/src/i18n/messages.js +51 -3
  347. package/src/installers/integration-installer.js +67 -2
  348. package/src/installers/manifest-installer.js +1 -0
  349. package/src/installers/standards-installer.js +3 -2
  350. package/src/prompts/init.js +50 -3
  351. package/src/reconciler/manifest-migrator.js +2 -2
  352. package/src/reconciler/plan-executor.js +11 -0
  353. package/src/utils/integration-generator.js +327 -14
  354. package/src/utils/workflow-gate.js +292 -0
  355. package/standards-registry.json +160 -5
@@ -0,0 +1,946 @@
1
+ ---
2
+ source: ../../../core/api-design-standards.md
3
+ source_version: 1.0.0
4
+ translation_version: 1.0.0
5
+ last_synced: 2026-03-23
6
+ status: current
7
+ ---
8
+
9
+ # API 设计标准
10
+
11
+ > **语言**: [English](../../../core/api-design-standards.md) | 简体中文
12
+
13
+ > 版本: 1.0.0 | 最后更新: 2026-03-18
14
+
15
+ **适用范围**: 所有软件项目
16
+ **范畴**: universal
17
+ **业界标准**: OpenAPI 3.x, JSON:API 1.1, Google API Design Guide, RFC 7231 (HTTP 语义)
18
+ **参考资料**: [openapis.org](https://www.openapis.org/), [jsonapi.org](https://jsonapi.org/), [Google API Design Guide](https://cloud.google.com/apis/design), [RFC 7231](https://datatracker.ietf.org/doc/html/rfc7231)
19
+
20
+ ---
21
+
22
+ ## 目的
23
+
24
+ 本标准定义设计、构建与维护 API 的全面性指南。涵盖 REST、GraphQL 及 gRPC 范式,提供资源命名、版本控制、分页、错误处理、身份验证与文档撰写的一致性模式。
25
+
26
+ **参考标准**:
27
+ - [OpenAPI Specification 3.x](https://spec.openapis.org/oas/v3.1.0)
28
+ - [JSON:API 1.1](https://jsonapi.org/format/)
29
+ - [Google API Design Guide](https://cloud.google.com/apis/design)
30
+ - [RFC 7231 — HTTP 语义](https://datatracker.ietf.org/doc/html/rfc7231)
31
+ - [RFC 7807 — HTTP API 问题详情](https://datatracker.ietf.org/doc/html/rfc7807)
32
+
33
+ ---
34
+
35
+ ## REST 设计原则
36
+
37
+ ### 资源命名
38
+
39
+ | 规则 | 正确 | 错误 |
40
+ |------|------|------|
41
+ | **使用名词,非动词** | `/users` | `/getUsers` |
42
+ | **使用复数名词** | `/articles` | `/article` |
43
+ | **使用 kebab-case** | `/user-profiles` | `/userProfiles`, `/user_profiles` |
44
+ | **使用小写** | `/orders` | `/Orders` |
45
+ | **嵌套表示关联** | `/users/123/orders` | `/getUserOrders?userId=123` |
46
+ | **最多 2 层嵌套** | `/users/123/orders` | `/users/123/orders/456/items/789/details` |
47
+
48
+ ### HTTP 动词
49
+
50
+ | 动词 | 用途 | 请求主体 | 幂等性 | 安全性 |
51
+ |------|------|---------|--------|--------|
52
+ | **GET** | 获取资源 | 无 | 是 | 是 |
53
+ | **POST** | 创建新资源 | 有 | 否 | 否 |
54
+ | **PUT** | 完整替代资源 | 有 | 是 | 否 |
55
+ | **PATCH** | 部分更新资源 | 有 | 否 | 否 |
56
+ | **DELETE** | 移除资源 | 选用 | 是 | 否 |
57
+ | **HEAD** | 与 GET 相同但不含主体 | 无 | 是 | 是 |
58
+ | **OPTIONS** | 描述通信选项 | 无 | 是 | 是 |
59
+
60
+ ### HTTP 状态码
61
+
62
+ #### 成功 (2xx)
63
+
64
+ | 代码 | 意义 | 使用时机 |
65
+ |------|------|---------|
66
+ | **200 OK** | 一般成功 | GET、PUT、PATCH、含主体的 DELETE |
67
+ | **201 Created** | 资源已创建 | POST(包含 `Location` 头部) |
68
+ | **202 Accepted** | 请求已接受,异步处理中 | 长时间执行的操作 |
69
+ | **204 No Content** | 成功但无主体 | DELETE、无响应主体的 PUT |
70
+
71
+ #### 客户端错误 (4xx)
72
+
73
+ | 代码 | 意义 | 使用时机 |
74
+ |------|------|---------|
75
+ | **400 Bad Request** | 格式错误的请求 | 无效 JSON、缺少必要字段 |
76
+ | **401 Unauthorized** | 需要身份验证 | 无 token、token 过期 |
77
+ | **403 Forbidden** | 权限不足 | 有效 token,角色不符 |
78
+ | **404 Not Found** | 资源不存在 | 无效的资源 ID |
79
+ | **405 Method Not Allowed** | 不支持的 HTTP 方法 | 对只读端点使用 POST |
80
+ | **409 Conflict** | 状态冲突 | 重复创建、版本冲突 |
81
+ | **422 Unprocessable Entity** | 验证错误 | 有效 JSON 但不符业务逻辑 |
82
+ | **429 Too Many Requests** | 超过速率限制 | 包含 `Retry-After` 头部 |
83
+
84
+ #### 服务器错误 (5xx)
85
+
86
+ | 代码 | 意义 | 使用时机 |
87
+ |------|------|---------|
88
+ | **500 Internal Server Error** | 非预期服务器错误 | 未处理的异常 |
89
+ | **502 Bad Gateway** | 上游服务错误 | 依赖服务故障 |
90
+ | **503 Service Unavailable** | 暂时无法使用 | 维护、过载 |
91
+ | **504 Gateway Timeout** | 上游超时 | 依赖服务超时 |
92
+
93
+ ---
94
+
95
+ ## URL 结构
96
+
97
+ ### 基础 URL 格式
98
+
99
+ ```
100
+ https://api.example.com/v1/resources
101
+ ```
102
+
103
+ | 组成元素 | 惯例 | 范例 |
104
+ |----------|------|------|
105
+ | **协议** | 必须使用 HTTPS | `https://` |
106
+ | **子域名** | 使用 `api.` 前缀 | `api.example.com` |
107
+ | **版本** | 路径前缀 | `/v1/` |
108
+ | **资源** | 复数名词、kebab-case | `/user-profiles` |
109
+
110
+ ### 资源层级
111
+
112
+ ```
113
+ # 集合
114
+ GET /users
115
+
116
+ # 特定资源
117
+ GET /users/123
118
+
119
+ # 子资源集合(1 层嵌套)
120
+ GET /users/123/orders
121
+
122
+ # 特定子资源(2 层嵌套 — 上限)
123
+ GET /users/123/orders/456
124
+
125
+ # 避免更深层嵌套 — 使用顶层搭配筛选
126
+ GET /order-items?order_id=456
127
+ ```
128
+
129
+ ### 资源操作
130
+
131
+ 对于非 CRUD 操作,使用子资源动作:
132
+
133
+ ```
134
+ # 可接受的动作模式
135
+ POST /users/123/activate
136
+ POST /orders/456/cancel
137
+ POST /reports/generate
138
+
139
+ # 避免动词式 URL
140
+ POST /activateUser # 错误
141
+ POST /cancelOrder # 错误
142
+ ```
143
+
144
+ ---
145
+
146
+ ## API 版本控制策略
147
+
148
+ ### 比较矩阵
149
+
150
+ | 策略 | 范例 | 优点 | 缺点 |
151
+ |------|------|------|------|
152
+ | **URL 路径** | `/v1/users` | 明确、易于路由、可缓存 | URL 污染、较难迁移 |
153
+ | **头部** | `Accept-Version: v1` | 干净的 URL | 隐藏、不易在浏览器测试 |
154
+ | **查询参数** | `/users?v=1` | 易于新增 | 容易忽略、缓存问题 |
155
+ | **内容协商** | `Accept: application/vnd.api.v1+json` | 符合标准 | 复杂、难以发现 |
156
+
157
+ ### 决策指南
158
+
159
+ ```
160
+ 是否需要同时支持多个版本?
161
+ ├── 是 → URL 路径版本控制(最明确)
162
+ └── 否 → 是否优先考虑干净的 URL?
163
+ ├── 是 → 头部版本控制
164
+ └── 否 → URL 路径版本控制(较简单)
165
+ ```
166
+
167
+ ### 建议方式:URL 路径版本控制
168
+
169
+ ```
170
+ https://api.example.com/v1/users
171
+ https://api.example.com/v2/users
172
+ ```
173
+
174
+ ### 版本生命周期
175
+
176
+ | 阶段 | 持续时间 | 动作 |
177
+ |------|----------|------|
178
+ | **现行** | 积极开发中 | 完整支持、新功能 |
179
+ | **支持中** | 后继版本发布后 6-12 个月 | 仅限错误修复、安全修补 |
180
+ | **已弃用** | 3-6 个月通知期 | Sunset 头部、迁移指南 |
181
+ | **已终止** | 弃用期结束后 | 返回 410 Gone 与迁移信息 |
182
+
183
+ ### 弃用头部
184
+
185
+ ```http
186
+ Sunset: Sat, 01 Jan 2028 00:00:00 GMT
187
+ Deprecation: true
188
+ Link: <https://api.example.com/v2/docs>; rel="successor-version"
189
+ ```
190
+
191
+ ---
192
+
193
+ ## 请求/响应标准
194
+
195
+ ### 内容头部
196
+
197
+ ```http
198
+ # 请求
199
+ Content-Type: application/json
200
+ Accept: application/json
201
+
202
+ # 响应
203
+ Content-Type: application/json; charset=utf-8
204
+ ```
205
+
206
+ ### JSON 命名惯例
207
+
208
+ | 惯例 | 使用于 | 范例 |
209
+ |------|--------|------|
210
+ | **camelCase** | JSON 属性 | `firstName`, `createdAt` |
211
+ | **kebab-case** | URL 路径 | `/user-profiles` |
212
+ | **snake_case** | 查询参数 | `?sort_by=created_at` |
213
+
214
+ ### 标准响应封装
215
+
216
+ ```json
217
+ {
218
+ "data": {
219
+ "id": "123",
220
+ "type": "user",
221
+ "attributes": {
222
+ "firstName": "John",
223
+ "lastName": "Doe",
224
+ "email": "john@example.com",
225
+ "createdAt": "2026-03-18T10:30:00Z"
226
+ }
227
+ },
228
+ "meta": {
229
+ "requestId": "req-abc-123",
230
+ "timestamp": "2026-03-18T10:30:00Z"
231
+ }
232
+ }
233
+ ```
234
+
235
+ ### 集合响应封装
236
+
237
+ ```json
238
+ {
239
+ "data": [
240
+ { "id": "1", "type": "user", "attributes": { "firstName": "John" } },
241
+ { "id": "2", "type": "user", "attributes": { "firstName": "Jane" } }
242
+ ],
243
+ "meta": {
244
+ "totalCount": 150,
245
+ "page": 1,
246
+ "pageSize": 20,
247
+ "requestId": "req-abc-124"
248
+ },
249
+ "links": {
250
+ "self": "/v1/users?page=1&limit=20",
251
+ "next": "/v1/users?page=2&limit=20",
252
+ "last": "/v1/users?page=8&limit=20"
253
+ }
254
+ }
255
+ ```
256
+
257
+ ### 日期/时间格式
258
+
259
+ - 一律使用 **ISO 8601** 格式:`2026-03-18T10:30:00Z`
260
+ - API 响应一律使用 **UTC** 时区
261
+ - 接受含时区的输入,转换为 UTC 存储
262
+
263
+ ---
264
+
265
+ ## 分页
266
+
267
+ ### 策略比较
268
+
269
+ | 策略 | 适用场景 | 优点 | 缺点 |
270
+ |------|----------|------|------|
271
+ | **偏移量式** | 简单列表、有页码的 UI | 易于实现、可跳至特定页 | 数据变动时不一致、大数据集性能差 |
272
+ | **游标式** | 实时动态、大数据集 | 一致性佳、性能好 | 无法跳页、游标不透明 |
273
+ | **键集式** | 已排序的大数据集 | 性能极佳 | 需要稳定排序键 |
274
+
275
+ ### 偏移量式分页
276
+
277
+ ```
278
+ GET /v1/users?page=2&limit=20
279
+ ```
280
+
281
+ ```json
282
+ {
283
+ "data": [...],
284
+ "meta": {
285
+ "page": 2,
286
+ "limit": 20,
287
+ "totalCount": 150,
288
+ "totalPages": 8
289
+ },
290
+ "links": {
291
+ "first": "/v1/users?page=1&limit=20",
292
+ "prev": "/v1/users?page=1&limit=20",
293
+ "self": "/v1/users?page=2&limit=20",
294
+ "next": "/v1/users?page=3&limit=20",
295
+ "last": "/v1/users?page=8&limit=20"
296
+ }
297
+ }
298
+ ```
299
+
300
+ ### 游标式分页
301
+
302
+ ```
303
+ GET /v1/events?limit=20&cursor=eyJpZCI6MTAwfQ==
304
+ ```
305
+
306
+ ```json
307
+ {
308
+ "data": [...],
309
+ "meta": {
310
+ "limit": 20,
311
+ "hasMore": true
312
+ },
313
+ "links": {
314
+ "self": "/v1/events?limit=20",
315
+ "next": "/v1/events?limit=20&cursor=eyJpZCI6MTIwfQ=="
316
+ }
317
+ }
318
+ ```
319
+
320
+ ### 默认值
321
+
322
+ | 参数 | 默认值 | 上限 |
323
+ |------|--------|------|
324
+ | `page` | 1 | - |
325
+ | `limit` / `page_size` | 20 | 100 |
326
+ | `cursor` | null(从头开始) | - |
327
+
328
+ ---
329
+
330
+ ## 筛选、排序与字段选择
331
+
332
+ ### 筛选
333
+
334
+ ```
335
+ # 简单相等
336
+ GET /v1/users?status=active
337
+
338
+ # 括号表示法(推荐用于复杂筛选)
339
+ GET /v1/users?filter[status]=active&filter[role]=admin
340
+
341
+ # 范围筛选
342
+ GET /v1/orders?filter[created_at][gte]=2026-01-01&filter[created_at][lte]=2026-03-18
343
+
344
+ # 多值(逗号分隔)
345
+ GET /v1/users?filter[role]=admin,editor
346
+ ```
347
+
348
+ ### 排序
349
+
350
+ ```
351
+ # 升序(默认)
352
+ GET /v1/users?sort=created_at
353
+
354
+ # 降序(加 - 前缀)
355
+ GET /v1/users?sort=-created_at
356
+
357
+ # 多字段排序(逗号分隔)
358
+ GET /v1/users?sort=-created_at,last_name
359
+ ```
360
+
361
+ ### 字段选择(稀疏字段集)
362
+
363
+ ```
364
+ # 选择特定字段
365
+ GET /v1/users?fields=id,first_name,email
366
+
367
+ # 依资源类型选择字段(JSON:API 风格)
368
+ GET /v1/articles?fields[article]=title,body&fields[author]=name
369
+ ```
370
+
371
+ ### 搜索
372
+
373
+ ```
374
+ # 全文搜索
375
+ GET /v1/users?q=john+doe
376
+
377
+ # 范围搜索
378
+ GET /v1/users?search[name]=john&search[email]=example.com
379
+ ```
380
+
381
+ ---
382
+
383
+ ## 身份验证模式
384
+
385
+ ### 决策矩阵
386
+
387
+ | 方法 | 适用场景 | 复杂度 | 安全等级 |
388
+ |------|----------|--------|----------|
389
+ | **API Key** | 服务器对服务器、内部 API | 低 | 中 |
390
+ | **OAuth 2.0** | 第三方访问、用户授权委派 | 高 | 高 |
391
+ | **JWT Bearer** | 无状态验证、微服务 | 中 | 高 |
392
+ | **mTLS** | 服务网格、零信任 | 高 | 极高 |
393
+
394
+ ### API Key
395
+
396
+ ```http
397
+ # 头部(建议方式)
398
+ Authorization: ApiKey sk_live_abc123def456
399
+
400
+ # 查询参数(避免使用 — 会记录在服务器日志中)
401
+ GET /v1/users?api_key=sk_live_abc123def456
402
+ ```
403
+
404
+ ### OAuth 2.0 流程
405
+
406
+ | 流程 | 适用场景 | 客户端类型 |
407
+ |------|----------|-----------|
408
+ | **Authorization Code + PKCE** | 网页应用、移动应用 | 公开 |
409
+ | **Client Credentials** | 机器对机器 | 机密 |
410
+ | **Device Code** | IoT、CLI 工具 | 公开(受限输入) |
411
+ | **Refresh Token** | 长期有效的会话 | 任何 |
412
+
413
+ ### JWT Bearer Token
414
+
415
+ ```http
416
+ Authorization: Bearer eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9...
417
+ ```
418
+
419
+ **JWT 最佳实践:**
420
+
421
+ | 规则 | 要求 |
422
+ |------|------|
423
+ | **算法** | RS256 或 ES256(非对称) |
424
+ | **Access token TTL** | 最多 15 分钟 |
425
+ | **Refresh token TTL** | 7-30 天 |
426
+ | **Payload** | 绝不包含敏感数据(密码、PII) |
427
+ | **验证** | 一律验证签名、发行者、受众、到期时间 |
428
+ | **撤销** | 维护 token 黑名单或使用短期 token |
429
+
430
+ ---
431
+
432
+ ## 速率限制
433
+
434
+ ### 标准头部
435
+
436
+ ```http
437
+ X-RateLimit-Limit: 1000
438
+ X-RateLimit-Remaining: 994
439
+ X-RateLimit-Reset: 1711036800
440
+ ```
441
+
442
+ | 头部 | 说明 |
443
+ |------|------|
444
+ | `X-RateLimit-Limit` | 窗口内允许的最大请求数 |
445
+ | `X-RateLimit-Remaining` | 当前窗口内剩余的请求数 |
446
+ | `X-RateLimit-Reset` | 窗口重置的 Unix 时间戳 |
447
+ | `Retry-After` | 重试前等待的秒数(用于 429) |
448
+
449
+ ### 速率限制层级
450
+
451
+ | 层级 | 限制 | 窗口 | 适用场景 |
452
+ |------|------|------|----------|
453
+ | **免费** | 100 请求 | 1 小时 | 公开/匿名 |
454
+ | **基本** | 1,000 请求 | 1 小时 | 已验证用户 |
455
+ | **专业** | 10,000 请求 | 1 小时 | 付费客户 |
456
+ | **企业** | 自定义 | 自定义 | 协商的 SLA |
457
+
458
+ ### 429 响应
459
+
460
+ ```json
461
+ {
462
+ "type": "https://api.example.com/errors/rate-limit-exceeded",
463
+ "title": "Rate Limit Exceeded",
464
+ "status": 429,
465
+ "detail": "You have exceeded the rate limit of 1000 requests per hour.",
466
+ "instance": "/v1/users",
467
+ "retryAfter": 3600
468
+ }
469
+ ```
470
+
471
+ ### 速率限制策略
472
+
473
+ | 策略 | 说明 | 适用场景 |
474
+ |------|------|----------|
475
+ | **固定窗口** | 在固定时间段内计算请求数 | 简单实现 |
476
+ | **滑动窗口** | 滚动式时间窗口 | 更精确的限制 |
477
+ | **令牌桶** | 以稳定速率补充令牌 | 允许突发流量 |
478
+ | **漏桶** | 以固定速率处理请求 | 平滑流量 |
479
+
480
+ ---
481
+
482
+ ## 错误响应格式
483
+
484
+ ### RFC 7807 问题详情
485
+
486
+ 所有错误响应必须遵循 [RFC 7807](https://datatracker.ietf.org/doc/html/rfc7807) Problem Details 格式:
487
+
488
+ ```json
489
+ {
490
+ "type": "https://api.example.com/errors/validation-error",
491
+ "title": "Validation Error",
492
+ "status": 422,
493
+ "detail": "The request body contains invalid fields.",
494
+ "instance": "/v1/users",
495
+ "errors": [
496
+ {
497
+ "field": "email",
498
+ "code": "INVALID_FORMAT",
499
+ "message": "Must be a valid email address."
500
+ },
501
+ {
502
+ "field": "age",
503
+ "code": "OUT_OF_RANGE",
504
+ "message": "Must be between 0 and 150."
505
+ }
506
+ ],
507
+ "traceId": "req-abc-123"
508
+ }
509
+ ```
510
+
511
+ ### 必要字段
512
+
513
+ | 字段 | 类型 | 说明 |
514
+ |------|------|------|
515
+ | `type` | URI | 错误文档的参考连结 |
516
+ | `title` | string | 简短、人类可读的摘要 |
517
+ | `status` | integer | HTTP 状态码 |
518
+ | `detail` | string | 针对此特定情况的人类可读说明 |
519
+
520
+ ### 选用字段
521
+
522
+ | 字段 | 类型 | 说明 |
523
+ |------|------|------|
524
+ | `instance` | URI | 造成错误的请求 URI |
525
+ | `errors` | array | 字段层级的验证错误 |
526
+ | `traceId` | string | 用于调试的请求追踪标识码 |
527
+
528
+ ### 常见错误类型
529
+
530
+ ```json
531
+ // 身份验证错误 (401)
532
+ {
533
+ "type": "https://api.example.com/errors/authentication-required",
534
+ "title": "Authentication Required",
535
+ "status": 401,
536
+ "detail": "A valid access token is required to access this resource."
537
+ }
538
+
539
+ // 授权错误 (403)
540
+ {
541
+ "type": "https://api.example.com/errors/insufficient-permissions",
542
+ "title": "Insufficient Permissions",
543
+ "status": 403,
544
+ "detail": "You do not have permission to delete this resource."
545
+ }
546
+
547
+ // 找不到资源 (404)
548
+ {
549
+ "type": "https://api.example.com/errors/resource-not-found",
550
+ "title": "Resource Not Found",
551
+ "status": 404,
552
+ "detail": "User with ID '999' does not exist."
553
+ }
554
+ ```
555
+
556
+ ---
557
+
558
+ ## GraphQL 设计原则
559
+
560
+ ### Schema 设计
561
+
562
+ ```graphql
563
+ # 类型使用 PascalCase
564
+ type User {
565
+ id: ID!
566
+ firstName: String!
567
+ lastName: String!
568
+ email: String!
569
+ createdAt: DateTime!
570
+ orders(first: Int, after: String): OrderConnection!
571
+ }
572
+
573
+ # 使用描述性的 input 类型
574
+ input CreateUserInput {
575
+ firstName: String!
576
+ lastName: String!
577
+ email: String!
578
+ }
579
+
580
+ # mutation 使用动词前缀
581
+ type Mutation {
582
+ createUser(input: CreateUserInput!): CreateUserPayload!
583
+ updateUser(id: ID!, input: UpdateUserInput!): UpdateUserPayload!
584
+ deleteUser(id: ID!): DeleteUserPayload!
585
+ }
586
+
587
+ # Payload 类型含 userErrors
588
+ type CreateUserPayload {
589
+ user: User
590
+ userErrors: [UserError!]!
591
+ }
592
+
593
+ type UserError {
594
+ field: [String!]
595
+ message: String!
596
+ code: UserErrorCode!
597
+ }
598
+ ```
599
+
600
+ ### 命名惯例
601
+
602
+ | 元素 | 惯例 | 范例 |
603
+ |------|------|------|
604
+ | **类型** | PascalCase | `UserProfile` |
605
+ | **字段** | camelCase | `firstName` |
606
+ | **枚举** | SCREAMING_SNAKE_CASE | `ORDER_STATUS` |
607
+ | **枚举值** | SCREAMING_SNAKE_CASE | `IN_PROGRESS` |
608
+ | **Mutation** | 动词 + 名词 | `createUser`, `updateOrder` |
609
+ | **Query** | 名词或名词片语 | `user`, `allUsers` |
610
+ | **Input 类型** | 动作 + 名词 + `Input` | `CreateUserInput` |
611
+ | **Payload 类型** | 动作 + 名词 + `Payload` | `CreateUserPayload` |
612
+
613
+ ### Relay 风格分页(Connections)
614
+
615
+ ```graphql
616
+ type Query {
617
+ users(first: Int, after: String, last: Int, before: String): UserConnection!
618
+ }
619
+
620
+ type UserConnection {
621
+ edges: [UserEdge!]!
622
+ pageInfo: PageInfo!
623
+ totalCount: Int!
624
+ }
625
+
626
+ type UserEdge {
627
+ node: User!
628
+ cursor: String!
629
+ }
630
+
631
+ type PageInfo {
632
+ hasNextPage: Boolean!
633
+ hasPreviousPage: Boolean!
634
+ startCursor: String
635
+ endCursor: String
636
+ }
637
+ ```
638
+
639
+ ### 错误处理
640
+
641
+ ```json
642
+ {
643
+ "data": {
644
+ "createUser": {
645
+ "user": null,
646
+ "userErrors": [
647
+ {
648
+ "field": ["input", "email"],
649
+ "message": "Email is already in use.",
650
+ "code": "TAKEN"
651
+ }
652
+ ]
653
+ }
654
+ }
655
+ }
656
+ ```
657
+
658
+ ---
659
+
660
+ ## gRPC 服务设计
661
+
662
+ ### Proto 文件惯例
663
+
664
+ ```protobuf
665
+ syntax = "proto3";
666
+
667
+ package example.user.v1;
668
+
669
+ option go_package = "example.com/api/user/v1;userv1";
670
+ option java_package = "com.example.api.user.v1";
671
+
672
+ // UserService 管理用户帐号。
673
+ service UserService {
674
+ // GetUser 依 ID 返回单一用户。
675
+ rpc GetUser(GetUserRequest) returns (GetUserResponse);
676
+
677
+ // ListUsers 返回分页的用户清单。
678
+ rpc ListUsers(ListUsersRequest) returns (ListUsersResponse);
679
+
680
+ // CreateUser 创建新的用户帐号。
681
+ rpc CreateUser(CreateUserRequest) returns (CreateUserResponse);
682
+
683
+ // UpdateUser 更新现有用户。
684
+ rpc UpdateUser(UpdateUserRequest) returns (UpdateUserResponse);
685
+
686
+ // DeleteUser 移除用户帐号。
687
+ rpc DeleteUser(DeleteUserRequest) returns (google.protobuf.Empty);
688
+ }
689
+
690
+ message GetUserRequest {
691
+ string user_id = 1;
692
+ }
693
+
694
+ message GetUserResponse {
695
+ User user = 1;
696
+ }
697
+
698
+ message ListUsersRequest {
699
+ int32 page_size = 1;
700
+ string page_token = 2;
701
+ string filter = 3;
702
+ string order_by = 4;
703
+ }
704
+
705
+ message ListUsersResponse {
706
+ repeated User users = 1;
707
+ string next_page_token = 2;
708
+ int32 total_size = 3;
709
+ }
710
+
711
+ message User {
712
+ string user_id = 1;
713
+ string first_name = 2;
714
+ string last_name = 3;
715
+ string email = 4;
716
+ google.protobuf.Timestamp created_at = 5;
717
+ }
718
+ ```
719
+
720
+ ### 命名惯例
721
+
722
+ | 元素 | 惯例 | 范例 |
723
+ |------|------|------|
724
+ | **包** | `company.service.version` | `example.user.v1` |
725
+ | **服务** | PascalCase + `Service` | `UserService` |
726
+ | **RPC 方法** | PascalCase 动词 + 名词 | `GetUser`, `ListUsers` |
727
+ | **消息** | PascalCase | `GetUserRequest` |
728
+ | **字段** | snake_case | `user_id`, `first_name` |
729
+ | **枚举** | PascalCase 类型、UPPER 值 | `Status`, `ACTIVE` |
730
+
731
+ ### gRPC 错误码对应
732
+
733
+ | gRPC 代码 | HTTP 对应 | 说明 |
734
+ |-----------|----------|------|
735
+ | `OK` | 200 | 成功 |
736
+ | `INVALID_ARGUMENT` | 400 | 客户端指定了无效的参数 |
737
+ | `UNAUTHENTICATED` | 401 | 缺少或无效的身份验证 |
738
+ | `PERMISSION_DENIED` | 403 | 权限不足 |
739
+ | `NOT_FOUND` | 404 | 资源不存在 |
740
+ | `ALREADY_EXISTS` | 409 | 资源已存在 |
741
+ | `FAILED_PRECONDITION` | 412 | 因系统状态而拒绝操作 |
742
+ | `RESOURCE_EXHAUSTED` | 429 | 速率限制或配额超出 |
743
+ | `INTERNAL` | 500 | 内部服务器错误 |
744
+ | `UNAVAILABLE` | 503 | 服务不可用 |
745
+ | `DEADLINE_EXCEEDED` | 504 | 操作超时 |
746
+
747
+ ---
748
+
749
+ ## API 文档要求
750
+
751
+ ### OpenAPI 规格要求
752
+
753
+ 每个 REST API 必须具备 OpenAPI 3.x 规格,包含:
754
+
755
+ | 区段 | 必要 | 说明 |
756
+ |------|------|------|
757
+ | `info` | 是 | 标题、版本、描述、联系方式 |
758
+ | `servers` | 是 | 所有环境的基础 URL |
759
+ | `paths` | 是 | 所有端点及其操作 |
760
+ | `components/schemas` | 是 | 所有请求/响应 schema |
761
+ | `components/securitySchemes` | 是 | 身份验证方法 |
762
+ | `security` | 是 | 默认安全需求 |
763
+ | `tags` | 建议 | 端点的逻辑分组 |
764
+
765
+ ### 文档检查清单
766
+
767
+ - [ ] 每个端点都有摘要与描述
768
+ - [ ] 所有参数都记载了类型、范例和限制条件
769
+ - [ ] POST/PUT/PATCH 提供请求主体范例
770
+ - [ ] 记载所有可能的响应代码与范例
771
+ - [ ] 指定每个端点的身份验证需求
772
+ - [ ] 记载速率限制
773
+ - [ ] 记载分页参数
774
+ - [ ] 记载错误响应格式与范例
775
+
776
+ ### OpenAPI 范例
777
+
778
+ ```yaml
779
+ openapi: 3.1.0
780
+ info:
781
+ title: User Management API
782
+ version: 1.0.0
783
+ description: API for managing user accounts
784
+ contact:
785
+ email: api-support@example.com
786
+
787
+ servers:
788
+ - url: https://api.example.com/v1
789
+ description: Production
790
+ - url: https://api.staging.example.com/v1
791
+ description: Staging
792
+
793
+ paths:
794
+ /users:
795
+ get:
796
+ summary: List all users
797
+ operationId: listUsers
798
+ tags: [Users]
799
+ parameters:
800
+ - name: page
801
+ in: query
802
+ schema:
803
+ type: integer
804
+ default: 1
805
+ - name: limit
806
+ in: query
807
+ schema:
808
+ type: integer
809
+ default: 20
810
+ maximum: 100
811
+ responses:
812
+ '200':
813
+ description: Successfully retrieved users
814
+ content:
815
+ application/json:
816
+ schema:
817
+ $ref: '#/components/schemas/UserListResponse'
818
+ '401':
819
+ $ref: '#/components/responses/Unauthorized'
820
+ '429':
821
+ $ref: '#/components/responses/RateLimited'
822
+ ```
823
+
824
+ ---
825
+
826
+ ## 安全考量
827
+
828
+ ### 传输安全
829
+
830
+ | 要求 | 标准 |
831
+ |------|------|
832
+ | **HTTPS** | 所有 API 端点皆为必要 |
833
+ | **TLS 版本** | TLS 1.2 最低要求,TLS 1.3 建议 |
834
+ | **HSTS** | 包含 `Strict-Transport-Security` 头部 |
835
+ | **凭证** | 有效的凭证,生产环境不使用自签凭证 |
836
+
837
+ ### CORS 配置
838
+
839
+ ```http
840
+ Access-Control-Allow-Origin: https://app.example.com
841
+ Access-Control-Allow-Methods: GET, POST, PUT, PATCH, DELETE, OPTIONS
842
+ Access-Control-Allow-Headers: Content-Type, Authorization, X-Request-ID
843
+ Access-Control-Max-Age: 86400
844
+ Access-Control-Allow-Credentials: true
845
+ ```
846
+
847
+ | 规则 | 要求 |
848
+ |------|------|
849
+ | **不使用通配符(`*`)搭配 credentials** | 指定确切的来源 |
850
+ | **限制方法** | 仅允许需要的 HTTP 方法 |
851
+ | **限制头部** | 仅允许需要的自定义头部 |
852
+ | **预检缓存** | 设定 `Max-Age` 以减少 OPTIONS 请求 |
853
+
854
+ ### 输入验证
855
+
856
+ | 规则 | 实现方式 |
857
+ |------|----------|
858
+ | **验证所有输入** | 服务器端验证所有参数 |
859
+ | **使用允许清单** | 根据已知的正确模式验证 |
860
+ | **限制请求大小** | 设定 `Content-Length` 限制(例如 1 MB) |
861
+ | **消毒输出** | 防止响应中的注入攻击 |
862
+ | **参数化查询** | 绝不将用户输入串接到查询中 |
863
+
864
+ ### API 安全头部
865
+
866
+ ```http
867
+ X-Content-Type-Options: nosniff
868
+ X-Frame-Options: DENY
869
+ Cache-Control: no-store
870
+ Content-Security-Policy: default-src 'none'
871
+ ```
872
+
873
+ ---
874
+
875
+ ## 快速参考卡
876
+
877
+ ### URL 模式
878
+
879
+ ```
880
+ [VERB] https://api.{domain}/v{N}/{resources}/{id}/{sub-resources}/{id}
881
+ ```
882
+
883
+ ### 响应结构
884
+
885
+ ```
886
+ 成功 → { data, meta, links }
887
+ 错误 → { type, title, status, detail, errors, traceId }
888
+ ```
889
+
890
+ ### 必要头部
891
+
892
+ | 方向 | 头部 | 值 |
893
+ |------|------|-----|
894
+ | 请求 | `Content-Type` | `application/json` |
895
+ | 请求 | `Accept` | `application/json` |
896
+ | 请求 | `Authorization` | `Bearer {token}` |
897
+ | 响应 | `X-RateLimit-Limit` | `1000` |
898
+ | 响应 | `X-RateLimit-Remaining` | `994` |
899
+ | 响应 | `X-Request-ID` | `req-abc-123` |
900
+
901
+ ### HTTP 动词速查表
902
+
903
+ | 动作 | 动词 | URL | 状态码 |
904
+ |------|------|-----|--------|
905
+ | 列表 | GET | `/users` | 200 |
906
+ | 读取 | GET | `/users/123` | 200 |
907
+ | 创建 | POST | `/users` | 201 |
908
+ | 完整更新 | PUT | `/users/123` | 200 |
909
+ | 部分更新 | PATCH | `/users/123` | 200 |
910
+ | 删除 | DELETE | `/users/123` | 204 |
911
+
912
+ ---
913
+
914
+ ## 相关标准
915
+
916
+ - [错误码标准](error-code-standards.md) - 错误码惯例与目录
917
+ - [安全标准](security-standards.md) - 身份验证、授权与安全实践
918
+ - [日志标准](logging-standards.md) - API 请求/响应日志
919
+ - [测试标准](testing-standards.md) - API 测试策略
920
+ - [文档撰写标准](documentation-writing-standards.md) - 撰写 API 文档
921
+
922
+ ---
923
+
924
+ ## 版本历史
925
+
926
+ | 版本 | 日期 | 变更 |
927
+ |------|------|------|
928
+ | 1.0.0 | 2026-03-18 | 初始版本 |
929
+
930
+ ---
931
+
932
+ ## 参考资料
933
+
934
+ - [OpenAPI Specification](https://www.openapis.org/)
935
+ - [JSON:API Specification](https://jsonapi.org/)
936
+ - [Google API Design Guide](https://cloud.google.com/apis/design)
937
+ - [RFC 7231 — HTTP/1.1 Semantics and Content](https://datatracker.ietf.org/doc/html/rfc7231)
938
+ - [RFC 7807 — Problem Details for HTTP APIs](https://datatracker.ietf.org/doc/html/rfc7807)
939
+ - [Microsoft REST API Guidelines](https://github.com/microsoft/api-guidelines)
940
+ - [Zalando RESTful API Guidelines](https://opensource.zalando.com/restful-api-guidelines/)
941
+
942
+ ---
943
+
944
+ ## 授权
945
+
946
+ 本标准以 [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/) 授权发布。