@kunlv/atdc 1.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 (222) hide show
  1. package/AGENTS.md +58 -0
  2. package/GO.md +245 -0
  3. package/bin/add-command.py +144 -0
  4. package/bin/atdc.js +460 -0
  5. package/bin/cls.js +98 -0
  6. package/central/link.sh +60 -0
  7. package/central/ticket_center_server/.handoffs/TASK-238389_QYinVipLimit.md +128 -0
  8. package/central/ticket_center_server/.test_plans/TASK-227254-SupportMembership-self-test-plan.md +566 -0
  9. package/central/ticket_center_server/.test_plans/task-238389-qyin-vip-limit-self-test-plan.md +210 -0
  10. package/commands/claude/atd.md +3 -0
  11. package/commands/claude/atdc/1-spec.md +5 -0
  12. package/commands/claude/atdc/1-update.md +5 -0
  13. package/commands/claude/atdc/2-qa.md +3 -0
  14. package/commands/claude/atdc/3-impl-skip-spec.md +5 -0
  15. package/commands/claude/atdc/3-impl.md +3 -0
  16. package/commands/claude/atdc/4-verify.md +3 -0
  17. package/commands/claude/atdc/5-done.md +3 -0
  18. package/commands/claude/atdc/add-command.md +4 -0
  19. package/commands/claude/atdc/add-to-hc.md +3 -0
  20. package/commands/claude/atdc/analysis-cls-log.md +4 -0
  21. package/commands/claude/atdc/article.md +6 -0
  22. package/commands/claude/atdc/bugfix.md +4 -0
  23. package/commands/claude/atdc/code-simplifier.md +8 -0
  24. package/commands/claude/atdc/commit.md +4 -0
  25. package/commands/claude/atdc/compound.md +5 -0
  26. package/commands/claude/atdc/context.md +3 -0
  27. package/commands/claude/atdc/diagnose.md +8 -0
  28. package/commands/claude/atdc/git-guardrails.md +18 -0
  29. package/commands/claude/atdc/grill-with-docs.md +8 -0
  30. package/commands/claude/atdc/handoff.md +8 -0
  31. package/commands/claude/atdc/health.md +3 -0
  32. package/commands/claude/atdc/learn.md +4 -0
  33. package/commands/claude/atdc/review.md +10 -0
  34. package/commands/claude/atdc/search.md +4 -0
  35. package/commands/claude/atdc/strategy.md +3 -0
  36. package/commands/claude/atdc/table2xlsx.md +4 -0
  37. package/commands/claude/atdc/test-plan.md +5 -0
  38. package/commands/claude/atdc/travel-planner.md +4 -0
  39. package/commands/claude/atdc/xlsx2sql-insert.md +4 -0
  40. package/commands/claude/atdc/xlsx2sql-update.md +4 -0
  41. package/commands/claude/atdc/zoom-out.md +8 -0
  42. package/commands/codex/atdc/SKILL.md +8 -0
  43. package/commands/codex/atdc-1-spec/SKILL.md +8 -0
  44. package/commands/codex/atdc-1-update/SKILL.md +8 -0
  45. package/commands/codex/atdc-2-qa/SKILL.md +8 -0
  46. package/commands/codex/atdc-3-impl/SKILL.md +8 -0
  47. package/commands/codex/atdc-3-impl-skip-spec/SKILL.md +8 -0
  48. package/commands/codex/atdc-4-verify/SKILL.md +8 -0
  49. package/commands/codex/atdc-5-done/SKILL.md +8 -0
  50. package/commands/codex/atdc-add-command/SKILL.md +7 -0
  51. package/commands/codex/atdc-add-to-hc/SKILL.md +8 -0
  52. package/commands/codex/atdc-analysis-cls-log/SKILL.md +5 -0
  53. package/commands/codex/atdc-article/SKILL.md +8 -0
  54. package/commands/codex/atdc-bugfix/SKILL.md +5 -0
  55. package/commands/codex/atdc-code-simplifier/SKILL.md +7 -0
  56. package/commands/codex/atdc-commit/SKILL.md +7 -0
  57. package/commands/codex/atdc-compound/SKILL.md +8 -0
  58. package/commands/codex/atdc-context/SKILL.md +8 -0
  59. package/commands/codex/atdc-diagnose/SKILL.md +9 -0
  60. package/commands/codex/atdc-git-guardrails/SKILL.md +19 -0
  61. package/commands/codex/atdc-grill-with-docs/SKILL.md +9 -0
  62. package/commands/codex/atdc-handoff/SKILL.md +9 -0
  63. package/commands/codex/atdc-health/SKILL.md +8 -0
  64. package/commands/codex/atdc-learn/SKILL.md +7 -0
  65. package/commands/codex/atdc-review/SKILL.md +49 -0
  66. package/commands/codex/atdc-search/SKILL.md +5 -0
  67. package/commands/codex/atdc-strategy/SKILL.md +8 -0
  68. package/commands/codex/atdc-table2xlsx/SKILL.md +8 -0
  69. package/commands/codex/atdc-test-plan/SKILL.md +13 -0
  70. package/commands/codex/atdc-travel-planner/SKILL.md +7 -0
  71. package/commands/codex/atdc-xlsx2sql-insert/SKILL.md +8 -0
  72. package/commands/codex/atdc-xlsx2sql-update/SKILL.md +8 -0
  73. package/commands/codex/atdc-zoom-out/SKILL.md +9 -0
  74. package/commands/cursor/atdc/SKILL.md +8 -0
  75. package/commands/cursor/atdc-1-spec/SKILL.md +8 -0
  76. package/commands/cursor/atdc-1-update/SKILL.md +8 -0
  77. package/commands/cursor/atdc-2-qa/SKILL.md +8 -0
  78. package/commands/cursor/atdc-3-impl/SKILL.md +8 -0
  79. package/commands/cursor/atdc-3-impl-skip-spec/SKILL.md +8 -0
  80. package/commands/cursor/atdc-4-verify/SKILL.md +8 -0
  81. package/commands/cursor/atdc-5-done/SKILL.md +8 -0
  82. package/commands/cursor/atdc-add-command/SKILL.md +7 -0
  83. package/commands/cursor/atdc-add-to-hc/SKILL.md +8 -0
  84. package/commands/cursor/atdc-analysis-cls-log/SKILL.md +5 -0
  85. package/commands/cursor/atdc-article/SKILL.md +8 -0
  86. package/commands/cursor/atdc-bugfix/SKILL.md +5 -0
  87. package/commands/cursor/atdc-code-simplifier/SKILL.md +7 -0
  88. package/commands/cursor/atdc-commit/SKILL.md +7 -0
  89. package/commands/cursor/atdc-compound/SKILL.md +8 -0
  90. package/commands/cursor/atdc-context/SKILL.md +8 -0
  91. package/commands/cursor/atdc-diagnose/SKILL.md +8 -0
  92. package/commands/cursor/atdc-git-guardrails/SKILL.md +18 -0
  93. package/commands/cursor/atdc-grill-with-docs/SKILL.md +8 -0
  94. package/commands/cursor/atdc-handoff/SKILL.md +8 -0
  95. package/commands/cursor/atdc-health/SKILL.md +8 -0
  96. package/commands/cursor/atdc-learn/SKILL.md +7 -0
  97. package/commands/cursor/atdc-review/SKILL.md +49 -0
  98. package/commands/cursor/atdc-search/SKILL.md +5 -0
  99. package/commands/cursor/atdc-strategy/SKILL.md +8 -0
  100. package/commands/cursor/atdc-table2xlsx/SKILL.md +8 -0
  101. package/commands/cursor/atdc-test-plan/SKILL.md +7 -0
  102. package/commands/cursor/atdc-travel-planner/SKILL.md +7 -0
  103. package/commands/cursor/atdc-xlsx2sql-insert/SKILL.md +8 -0
  104. package/commands/cursor/atdc-xlsx2sql-update/SKILL.md +8 -0
  105. package/commands/cursor/atdc-zoom-out/SKILL.md +8 -0
  106. package/commands/opencode/atd.md +6 -0
  107. package/commands/opencode/atdc/1-spec.md +8 -0
  108. package/commands/opencode/atdc/1-update.md +8 -0
  109. package/commands/opencode/atdc/2-qa.md +6 -0
  110. package/commands/opencode/atdc/3-impl-skip-spec.md +8 -0
  111. package/commands/opencode/atdc/3-impl.md +6 -0
  112. package/commands/opencode/atdc/4-verify.md +6 -0
  113. package/commands/opencode/atdc/5-done.md +6 -0
  114. package/commands/opencode/atdc/add-command.md +6 -0
  115. package/commands/opencode/atdc/add-to-hc.md +6 -0
  116. package/commands/opencode/atdc/analysis-cls-log.md +6 -0
  117. package/commands/opencode/atdc/article.md +6 -0
  118. package/commands/opencode/atdc/bugfix.md +6 -0
  119. package/commands/opencode/atdc/code-simplifier.md +8 -0
  120. package/commands/opencode/atdc/commit.md +6 -0
  121. package/commands/opencode/atdc/compound.md +8 -0
  122. package/commands/opencode/atdc/context.md +6 -0
  123. package/commands/opencode/atdc/diagnose.md +8 -0
  124. package/commands/opencode/atdc/git-guardrails.md +18 -0
  125. package/commands/opencode/atdc/grill-with-docs.md +8 -0
  126. package/commands/opencode/atdc/handoff.md +8 -0
  127. package/commands/opencode/atdc/health.md +6 -0
  128. package/commands/opencode/atdc/learn.md +6 -0
  129. package/commands/opencode/atdc/review.md +7 -0
  130. package/commands/opencode/atdc/search.md +6 -0
  131. package/commands/opencode/atdc/strategy.md +6 -0
  132. package/commands/opencode/atdc/table2xlsx.md +6 -0
  133. package/commands/opencode/atdc/test-plan.md +6 -0
  134. package/commands/opencode/atdc/travel-planner.md +6 -0
  135. package/commands/opencode/atdc/xlsx2sql-insert.md +6 -0
  136. package/commands/opencode/atdc/xlsx2sql-update.md +6 -0
  137. package/commands/opencode/atdc/zoom-out.md +8 -0
  138. package/config/cls-defaults.json +19 -0
  139. package/hooks/atd-archive.sh +86 -0
  140. package/hooks/atd-state.sh +165 -0
  141. package/hooks/evidence-hook.sh +88 -0
  142. package/hooks/evidence-log.sh +54 -0
  143. package/hooks/guardrails.sh +65 -0
  144. package/hooks/handoff-compress.sh +104 -0
  145. package/hooks/phase-guard.sh +134 -0
  146. package/hooks/phase-write-guard.sh +96 -0
  147. package/hooks/ponytail-fix.sh +179 -0
  148. package/hooks/ponytail-guard.sh +66 -0
  149. package/hooks/ponytail-scan.sh +62 -0
  150. package/install.sh +276 -0
  151. package/package.json +20 -0
  152. package/packages/cls/bin/cls.js +146 -0
  153. package/packages/cls/config/defaults.json +17 -0
  154. package/packages/cls/mcp/server.js +142 -0
  155. package/packages/cls/package.json +29 -0
  156. package/packages/cls/scripts/postinstall.js +19 -0
  157. package/packages/cls/src/client.js +262 -0
  158. package/prompts/1-spec.md +271 -0
  159. package/prompts/1-update.md +198 -0
  160. package/prompts/2-qa.md +164 -0
  161. package/prompts/3-impl-bugfix.md +271 -0
  162. package/prompts/3-impl.md +419 -0
  163. package/prompts/4-verify.md +160 -0
  164. package/prompts/5-done.md +227 -0
  165. package/prompts/6-article.md +571 -0
  166. package/prompts/X-add-command.md +60 -0
  167. package/prompts/X-add-to-hc.md +178 -0
  168. package/prompts/X-analysis-cls-log.md +68 -0
  169. package/prompts/X-bugfix.md +10 -0
  170. package/prompts/X-code-simplifier.md +38 -0
  171. package/prompts/X-commit.md +116 -0
  172. package/prompts/X-compound.md +188 -0
  173. package/prompts/X-context-scan.md +101 -0
  174. package/prompts/X-diagnose.md +116 -0
  175. package/prompts/X-grill-with-docs.md +120 -0
  176. package/prompts/X-handoff.md +80 -0
  177. package/prompts/X-health.md +78 -0
  178. package/prompts/X-learn.md +151 -0
  179. package/prompts/X-review.md +417 -0
  180. package/prompts/X-search.md +74 -0
  181. package/prompts/X-strategy.md +95 -0
  182. package/prompts/X-table2xlsx.md +46 -0
  183. package/prompts/X-test-plan.md +436 -0
  184. package/prompts/X-travel-planner.md +22 -0
  185. package/prompts/X-xlsx2sql-insert.md +34 -0
  186. package/prompts/X-xlsx2sql-update.md +40 -0
  187. package/prompts/X-zoom-out.md +119 -0
  188. package/reference/diagnose-loop.md +66 -0
  189. package/reference/gates.md +90 -0
  190. package/reference/git-guardrails.md +71 -0
  191. package/reference/guards.md +275 -0
  192. package/reference/learn.md +100 -0
  193. package/reference/memory.md +190 -0
  194. package/reference/risk.md +74 -0
  195. package/reference/tdd.md +40 -0
  196. package/scripts/svg2png.js +46 -0
  197. package/src/cls/client.js +244 -0
  198. package/src/constants.js +49 -0
  199. package/src/evidence/ai-draft-metrics.js +157 -0
  200. package/src/evidence/canvas.js +184 -0
  201. package/src/evidence/index.js +98 -0
  202. package/src/evidence/sink-events.js +165 -0
  203. package/src/evidence/stage-timing.js +112 -0
  204. package/src/installers/claude.js +79 -0
  205. package/src/installers/codex.js +62 -0
  206. package/src/installers/opencode.js +72 -0
  207. package/src/manifest/ponytail-patterns.json +185 -0
  208. package/src/mcp/cls-mcp-server.js +142 -0
  209. package/src/utils.js +79 -0
  210. package/src/validators/state-validate.js +123 -0
  211. package/templates/.phase-state.json +13 -0
  212. package/templates/adr.md +62 -0
  213. package/templates/changelog.md +21 -0
  214. package/templates/concepts.md +35 -0
  215. package/templates/design.md +47 -0
  216. package/templates/handoff.md +64 -0
  217. package/templates/learn-skill.md +43 -0
  218. package/templates/progress.json +17 -0
  219. package/templates/proposal.md +29 -0
  220. package/templates/solution.md +36 -0
  221. package/templates/strategy.md +39 -0
  222. package/templates/tasks.md +41 -0
@@ -0,0 +1,419 @@
1
+ # prompts/3-impl · 执行
2
+
3
+ 从此文件读取后直接开始执行,无需用户再次确认。
4
+
5
+ ---
6
+
7
+ ## 🔴 Step -1:规则加载(不读 = 不得执行)
8
+
9
+ **先 Read 以下 3 个文件,缺一不可。读完才进 Step 0。**
10
+
11
+ ```
12
+ Read @atdc/reference/guards.md → R1-R8 硬性拦截 + B5 Ponytail 8 级梯
13
+ Read @atdc/reference/gates.md → Gate 1-4 质量门禁
14
+ Read @atdc/reference/tdd.md → RED→GREEN→REFACTOR 完整循环
15
+ Read @atdc/reference/risk.md → 风险评分算法(R5/R7 所需)
16
+ ```
17
+
18
+ > 以下所有 Step 引用的规则均来自上述 3 个文件。
19
+ > 如果 Step 中提到 R5/B5/Gate 3 但未被加载到 context → 回退到 Step -1 重新加载。
20
+
21
+ > **Token 节约原则**
22
+ > - bash 命令加 `| grep -E "PASS|FAIL|ok|error"` 过滤噪声
23
+ > - 找符号定义/调用方优先用 CodeGraph(`codegraph_search`/`codegraph_callers`),禁止 `grep -rn`
24
+ > - 读文件用 `sed -n 'N,Mp'` 精确定位,不 `cat` 全文
25
+ > - 大文件分析用 `ctx_execute_file`,不直接 Read
26
+
27
+ ---
28
+
29
+ ## Step 0:恢复断点
30
+
31
+ ```bash
32
+ cat openspec/changes/<name>/.progress.json 2>/dev/null
33
+ ```
34
+
35
+ - 存在且 `status != "completed"` → 报告进度(completedTasks / currentStep),询问"从断点继续 / 从头开始"
36
+ - 不存在 → 创建初始 `.progress.json`:
37
+
38
+ ```json
39
+ {
40
+ "change": "<name>",
41
+ "status": "in-progress",
42
+ "mode": "direct",
43
+ "currentStep": "gate-check",
44
+ "completedTasks": [],
45
+ "failedAt": null,
46
+ "failedReason": null,
47
+ "startedAt": "<ISO datetime>",
48
+ "updatedAt": "<ISO datetime>",
49
+ "traceability": [],
50
+ "gateResults": { "gate1": null, "gate2": null, "gate3": null, "gate4": null }
51
+ }
52
+ ```
53
+
54
+ 同时确保 `.phase-state.json` phase 已推进到 build(1-spec 结束后应已到 build,如未推进则手动更新):
55
+
56
+ ```bash
57
+ python3 -c "
58
+ import json
59
+ with open('openspec/changes/<name>/.phase-state.json') as f: d = json.load(f)
60
+ if d.get('phase') != 'build':
61
+ d['phase'] = 'build'
62
+ with open('openspec/changes/<name>/.phase-state.json','w') as f: json.dump(d,f,indent=2)
63
+ "
64
+ # PostToolUse hook 检测到 phase 变更为 build → 自动记录 phase_transition 事件
65
+ ```
66
+
67
+ ---
68
+
69
+ ## Step 1:R1 前置检查(硬性拦截)
70
+
71
+ ```bash
72
+ ls openspec/changes/<name>/proposal.md openspec/changes/<name>/tasks.md openspec/changes/<name>/design.md 2>&1
73
+ ls openspec/changes/<name>/specs/*/spec.md 2>&1
74
+ ```
75
+
76
+ 任一缺失 → 停止,输出缺少哪些文件,提示先补充再执行。
77
+
78
+ > **🔒 Harness 加固**:R1 检查通过后,运行 `atdc guard build` 做脚本级硬性验证。
79
+ > 该命令会再次确认 4 类文件完整性,不通过则 `[HARD STOP]` 并返回非 0,AI 不得跳过。
80
+
81
+ ### Step 1a:Evidence 系统初始化
82
+
83
+ 每次执行开始前,记录 intake 事件和初始 draft snapshot:
84
+
85
+ ```bash
86
+ atdc evidence record <name> intake --phase=open --mode=<full/tweak/hotfix>
87
+ atdc evidence metrics <name> --snapshot
88
+ ```
89
+
90
+ > evidence 系统自动写入 `openspec/changes/<name>/.evidence/` 目录。
91
+
92
+ ### Step 1.5:Ponytail Guard(硬性拦截)
93
+
94
+ > **复杂级 change** → 严格模式(发现 P0/P1 违规则 `[HARD STOP]`)
95
+ > **标准级/简级** → 警告模式(输出建议,可跳过)
96
+
97
+ ```bash
98
+ # 严格模式(默认用于复杂级)
99
+ atdc ponytail guard --strict
100
+
101
+ # 警告模式(用于简级/标准级)
102
+ atdc ponytail guard --warn
103
+ ```
104
+
105
+ > 发现 P0 违规(CRUD 模板 ≥10 / RPC 模板 ≥3 / DI 样板 ≥5)→ `[HARD STOP]`,必须先 `atdc ponytail fix` 修复再继续
106
+ > 跳过检查:`PONYTAIL_SKIP=1 atdc guard build`(不推荐)
107
+
108
+ > ⚠️ **CLI 不可用时的降级**:若 `which atdc` 返回空,Step 1.5 的 P0/P1 项目级扫描可跳过(无 CLI 无法执行),但 **Step 5b2 的 L4-L7 手动梯级检查不得跳过**。AI 必须通过 CodeGraph / grep 手动完成 5b2 的逐函数检查,不能因为 Step 1.5 跳过就把整套 Ponytail 标记为「已跳过」。
109
+
110
+ ---
111
+
112
+ ## Step 2:复杂度分级 + 执行模式选择
113
+
114
+ ### 2a. 复杂度评估
115
+
116
+ 统计 tasks.md 中 `### N.` 标题数量,并判断是否跨层改动(DB/缓存/路由/公共接口变更):
117
+
118
+ | 维度 | 简单 | 标准 | 复杂 |
119
+ | ----- | --- | --- | ---- |
120
+ | 任务数 | ≤ 1 | 2-5 | > 5 |
121
+ | 跨层改动 | 无 | 无或有 | 有 |
122
+ | 任务间依赖 | 无 | 有或无 | 有依赖链 |
123
+ | 破坏性变更 | 无 | 无 | 有 |
124
+
125
+ **分级规则**(从高到低匹配,命中即止):
126
+ - 命中任意 **复杂** 维度 → **复杂级**
127
+ - 任务数 > 0 且全部命中 **简单** 维度 → **简级**
128
+ - 其余 → **标准级**
129
+
130
+ ### 2b. 执行模式选择
131
+
132
+ | 任务数 | 模式 |
133
+ | --------- | -------------------------------- |
134
+ | ≤ 5 | 直通模式(tasks.md 即执行计划) |
135
+ | > 5 | 详细计划模式(先生成 bridge-manifest.json) |
136
+ | 用户说"直通" | 强制直通 |
137
+ | 用户说"详细计划" | 强制详细 |
138
+
139
+ ### 2c. 各级别跳步规则
140
+
141
+ 根据复杂度级别,以下步骤可跳过:
142
+
143
+ | 步骤 | 简级 | 标准级 | 复杂级 |
144
+ |------|------|--------|--------|
145
+ | Step 3 Gate 1 Spec 质量 | ⏭️ 跳过(1-spec 已验证) | ✅ 执行 | ✅ 执行 |
146
+ | Step 4 Gate 2 追溯矩阵 | ⏭️ 跳过 | ✅ 执行 | ✅ 执行 |
147
+ | Step 5d TDD | ⏭️ 跳过 | ✅ 执行 | ✅ 执行 |
148
+ | Step 5b2 R6 SQL/缓存检查 | 按需(涉及 SQL/Redis 时执行) | ✅ 执行 | ✅ 执行 |
149
+ | Step 6 C3 验证 | ✅ 编译 + Checklist | ✅ 全量验证 | ✅ 全量验证 |
150
+ | Step 7 C2 人工 Review | ✅ 执行 | ✅ 执行 | ✅ 执行 |
151
+ | Step 8 归档 | ✅ 执行 | ✅ 执行 | ✅ 执行 |
152
+
153
+ > **简级说明**:≤1 个任务 + 无跨层改动 = 改动极小(如加字段、改文案),TDD 收益低于成本。
154
+ > 但 C2(人工 review)和 C3(编译验证)不可跳过。
155
+
156
+ 宣布:`"检测到 N 个任务,复杂度:<简级/标准级/复杂级>,使用 <直通/详细计划> 模式,跳过:<步骤列表>"` 后继续。
157
+
158
+ ---
159
+
160
+ ## Step 3:Gate 1 — Spec 质量检查
161
+
162
+ 详细规则见 `@atdc/reference/gates.md`。
163
+
164
+ 扫描 `openspec/changes/<name>/specs/` 下所有 spec.md:
165
+ - 弱需求(含 should/might/可能 而非 SHALL/MUST)
166
+ - 缺 Given/When/Then 验收标准的场景
167
+ - 缺 sad path 的 happy path
168
+ - 缺边界场景(空值/超限/并发/降级)
169
+
170
+ 输出报告,有问题询问用户是否继续。
171
+
172
+ ---
173
+
174
+ ## Step 4:Gate 2 — 追溯矩阵
175
+
176
+ 生成 `openspec/changes/<name>/.progress.json` 的 `traceability` 字段,映射:
177
+ `spec 需求 → task → 测试文件 → 实现文件`
178
+
179
+ 报告:需求遗漏 / 隐性需求 / 缺测试覆盖 / 野代码风险。
180
+
181
+ ---
182
+
183
+ ## Step 5:逐任务执行
184
+
185
+ > 🔒 git-guardrails 检查(一次性提醒):
186
+ > ```bash
187
+ > ls -la .git/hooks/pre-push 2>/dev/null && echo "✅ git-guardrails 已激活" || echo "⚠️ git-guardrails 未安装。建议运行:bash ~/atdc/install.sh"
188
+ > ```
189
+
190
+ 每个任务按以下顺序执行:
191
+
192
+ ### 5a. R4 文件边界检查(执行前)
193
+
194
+ 确认任务有 `**Files**:` 字段且不为空。缺失则停止:
195
+ ```
196
+ ❌ [R4] 任务 N 缺少 Files 声明,请补充后继续。
197
+ ```
198
+
199
+ ### 5b0. 全景分析(可选,仅涉及陌生模块时触发)
200
+
201
+ 若本任务 `**Files**:` 涉及 ≥ 3 个文件,或包含 CONTEXT.md 中未记录的模块:
202
+ > 本任务涉及 <N> 个模块(<列表>)。是否需要全景分析?
203
+ > - 说 `zoom` → 执行 `/atdc:zoom-out`:
204
+ > 1. 分析目标代码在系统架构中的位置
205
+ > 2. 识别上下游依赖和间接影响
206
+ > 3. 检查是否与 CONTEXT.md 中的模块边界一致
207
+ > - 说 `继续` → 跳过,直接写代码
208
+
209
+ > **触发条件**:`**Files**` > 2 个 或 涉及 CONTEXT.md 未记录的目录时显示。
210
+
211
+ ### 5b. 沿用抽象(写代码前)
212
+
213
+ 识别本任务需要实现的能力,**按优先级使用以下工具查找已有实现**:
214
+
215
+ **1. Semble 语义搜索(推荐首选,直接返回代码片段)**:
216
+ ```
217
+ /atdc:search "<描述你需要的功能>"
218
+ ```
219
+ 或用 MCP 工具直接调用 `mcp__semble__search`。Semble 理解自然语言语义,比关键词 grep 更精准,且直接返回代码片段(无需再 Read 文件)。
220
+
221
+ **2. CodeGraph 结构化搜索(查调用关系、精确符号名)**:
222
+ ```
223
+ codegraph_search "<关键词>"
224
+ codegraph_callers "<FunctionName>"
225
+ ```
226
+
227
+ **3. grep 降级兜底(仅前两者无结果时)**:
228
+ ```
229
+ grep -rn "<关键词>" --include="*.go" . | grep -v "_test.go" | grep -v vendor
230
+ ```
231
+
232
+ - 找到 → 沿用,SUMMARY.md 注明"沿用: <路径>"
233
+ - 未找到 → 新建,SUMMARY.md 注明"新增抽象: <名称>"
234
+
235
+ ### 5b2. Ponytail 检查(每次新建文件/函数前,强制执行)
236
+
237
+ > 🔴 **本步不依赖 atdc CLI,AI MUST 手动执行。即使 Step 1.5(CLI guard)因 atdc 未安装而跳过,本步也绝对不得跳过。**
238
+
239
+ > 💡 **L2-L5 检测加速**:用 Semble search 快速验证"项目内有没有类似实现"。
240
+ > 例:`semble search "filter by whitelist" .` → 直接返回已有 `filterByWhitelist` 代码块。
241
+ > 语义搜索比逐一 grep 关键词高效 10x+。
242
+
243
+ 在 5b 找到已有实现后,再跑 Ponytail 8 级梯(详见 `@atdc/reference/guards.md` B5)。
244
+
245
+ **强制规则**:
246
+ - 每次 `write` 操作用到新文件 → 检查 8 级梯
247
+ - 检测到同一模式出现 ≥3 次(参考 18 种模式速查表)→ **暂停,先提取泛型/公共模式**
248
+ - 梯级通过 → 代码注释标注 `// Ponytail L{N}: <理由>`
249
+ - 跳过梯级直接写代码 → Gate 3 不通过
250
+
251
+ **L4 强制检查清单**(每次写新函数前必查):
252
+ 1. `codegraph_search "<函数名关键词>"` — 是否有同名/同义函数已存在?
253
+ 2. `codegraph_callers "<依赖的接口>"` — 调用方是如何用的?是否有更优的调用模式(如 `WithContext` vs `Group`)?
254
+ 3. 新函数是否只是已有函数的薄封装?是 → 直接委托已有函数,不新建
255
+
256
+ **代码注释规范**:
257
+ ```go
258
+ // Ponytail L2: stdlib covers — use slices.Contains instead of custom Contains[T]
259
+ // Ponytail L4: reuse existing — callLocalRPC[T] already defined
260
+ // Ponytail L6: extracted generic — filterByWhitelist[T] covers 3 duplicates
261
+ // Ponytail L7: minimal interface — OrderPayer has 2 methods, not 30-method IOrder
262
+ ```
263
+
264
+ **自动扫描**(每次 git add 前):
265
+ ```bash
266
+ # 检查是否有 ≥10 个同构 CRUD
267
+ codegraph_search "func.*Find.*ctx.Context" --kind=method | wc -l
268
+ # 检查是否有 ≥5 个 Register
269
+ grep -rn "func Register" service/biz/ --include="*.go" | wc -l
270
+ # 检查是否有 ≥3 个 RPC post
271
+ grep -rn "httpclient.Post" service/rpc/ --include="*.go" | wc -l
272
+ ```
273
+
274
+ ### 5b3. R6 SQL 性能与缓存安全检查(写代码前)
275
+
276
+ 若任务涉及 SQL 查询或 Redis 写入(详见 `@atdc/reference/guards.md` R6),必须在写代码前执行检查:
277
+
278
+ 1. 识别任务中涉及的所有 SQL 操作和 Redis 写入点
279
+ 2. 逐项执行 R6-6a(慢查检查)和 R6-6b(大 Key 检查)
280
+ 3. 有风险 → 输出检查报告,**暂停等用户确认方案后继续**
281
+ 4. 无风险 → 继续
282
+
283
+ ### 5c. R5 破坏性变更检查(写代码前)
284
+
285
+ 若即将删除 ≥5 行 / 修改公共函数签名 / 删除接口:
286
+
287
+ **1. CodeGraph 扫描直接调用方**:
288
+ ```
289
+ codegraph_callers "<SymbolName>"
290
+ codegraph_impact "<SymbolName>"
291
+ ```
292
+
293
+ **2. Semble find_related 补盲区**(发现语义相似但无直接调用关系的关联代码):
294
+ ```
295
+ semble find-related <file> <line> .
296
+ ```
297
+ > CodeGraph impact 只追踪调用边。接口语义变更(如返回值格式、错误码含义)可能影响无直接调用的下游。
298
+ > Semble find_related 可发现这些语义关联的代码块。
299
+
300
+ **3. grep 降级兜底**(仅前两者无结果时):
301
+ ```
302
+ grep -rn "<SymbolName>" --include="*.go" . | grep -v "_test.go" | grep -v vendor
303
+ ```
304
+
305
+ 展示引用列表 + Semble 发现的语义关联代码,等用户确认后才能继续。
306
+
307
+ ### 5d. R2 TDD(Gate 3)
308
+
309
+ 1. 先写 `_test.go`,测试函数含 `// Intent: <为什么这个行为重要>`
310
+ 2. 确认测试编译通过(RED):`go build ./... 2>&1 | head -5`
311
+ 3. 写实现,测试通过(GREEN):`go test ./<pkg>/... 2>&1 | grep -E "PASS|FAIL|ok"`
312
+ 4. 重构(REFACTOR)
313
+
314
+ > ⚠️ RED 阶段测试失败重试 ≥ 2 次 → 不盲目猜测,自动切入诊断模式(遵循 `/atdc:diagnose` 6 阶段循环):
315
+ > 1. 复现:确认失败的测试命令和完整错误输出
316
+ > 2. 最小化:隔离到最小失败单元(单个测试/单个函数)
317
+ > 3. 假设:列出 ≥ 2 个可能的根因,按概率排序
318
+ > 4. 插桩:在关键路径添加日志/断点验证假设
319
+ > 5. 修复:确认根因后修复(仅改必要代码)
320
+ > 6. 回归:运行全量相关测试确保不引入新问题
321
+ >
322
+ > 详见 `reference/diagnose-loop.md`。最多 3 轮诊断,3 轮后输出诊断报告并暂停等用户决策。
323
+
324
+ ### 5e. R4 越界检查(执行后)
325
+
326
+ ```bash
327
+ git diff --name-only HEAD
328
+ ```
329
+ 对比实际修改文件 vs `**Files**:` 声明,有越界文件则停止等用户确认。
330
+
331
+ ### 5f. 更新进度
332
+
333
+ ```bash
334
+ # 更新 .progress.json 的 completedTasks
335
+ ```
336
+
337
+ ### 5f2. 记录 Evidence 事件
338
+
339
+ 每完成一个任务后,记录 evidence 事件:
340
+
341
+ ```bash
342
+ atdc evidence record <name> task_complete --phase=build --task=<task-id> --files="<changed-files>"
343
+ ```
344
+
345
+ > evidence 事件自动写入 `openspec/changes/<name>/.evidence/events/`,供后续 Canvas 和度量使用。
346
+
347
+ ### 5g. Test Gap 快速检查(复杂级/标准级执行)
348
+
349
+ 每个任务完成后,对本次任务新增/修改的函数做轻量测试覆盖检查:
350
+
351
+ ```
352
+ codegraph_callers "<NewOrModifiedFunction>"
353
+ ```
354
+
355
+ 检查返回的调用方中是否包含测试文件。**不阻塞执行**,仅记录到进度:
356
+
357
+ ```
358
+ 📊 Task N 测试覆盖:
359
+ ✅ loginHandler → TestLoginHandler
360
+ ❌ validateToken → 无测试调用方(建议补充)
361
+ ```
362
+
363
+ 简级任务跳过此步骤(参见 Step 2c 跳步规则)。
364
+
365
+ ---
366
+
367
+ ## Step 5.5:Harness 门禁(进入 C3 前)
368
+
369
+ > **🔒 Harness 加固**:全部任务完成后、C3 验证前,运行 `atdc guard verify` 做脚本级硬性验证。
370
+ > 该命令检查 tasks.md 无未勾选项 + verification_report 已设置,不通过则 `[HARD STOP]` 并返回非 0。
371
+ > 此检查**不得跳过**,即使 AI 自认为全部完成也必须运行。
372
+
373
+ ### Step 5.5b:记录 Gate 检查证据
374
+
375
+ ```bash
376
+ atdc evidence record <name> gate_check --phase=build --gate=guard_verify --result=passed
377
+ ```
378
+
379
+ ---
380
+
381
+ ## Step 6:C3 验证(Gate 4)
382
+
383
+ 逐条验证 tasks.md 的 `## Verification Checklist`:
384
+
385
+ - 所有 SHALL/MUST 有对应实现和测试
386
+ - `git diff --name-only` 对比追溯矩阵,无主变更需用户确认
387
+ - 检查是否有绕过领域约束的直接操作(参考 AGENTS.md/CLAUDE.md)
388
+ - 运行测试:`go test ./<pkg>/... 2>&1 | grep -E "PASS|FAIL|ok|SKIP"` (不用 -v,只看结论)
389
+
390
+ 验证失败 → 先诊断后修复(遵循 `/atdc:diagnose`):
391
+ 1. 输出失败项的具体错误和上下文
392
+ 2. 按 6 阶段诊断循环定位根因(复现 → 最小化 → 假设 → 插桩 → 修复 → 回归)
393
+ 3. 针对性修复 → 重新验证
394
+ 4. 最多 3 轮诊断,3 轮后输出诊断报告并暂停等用户决策
395
+
396
+ ---
397
+
398
+ ## Step 7:C2 人工 Code Review
399
+
400
+ 暂停,输出:
401
+ ```
402
+ 🔍 C2 Code Review 等待审查:
403
+
404
+ 变更文件:
405
+ <git diff --name-only 列表>
406
+
407
+ Gate 4 结果:
408
+ <无主变更列表 / 领域规则检查结果>
409
+
410
+ 请审查后回复"通过"或提出修改意见。
411
+ ```
412
+
413
+ 有修改意见 → 修复 → 重新展示,直到用户确认通过。
414
+
415
+ ---
416
+
417
+ ## Step 8:归档
418
+
419
+ **Read `@atdc/prompts/5-done.md`**(其 Step -1 会加载 memory.md 规则),然后执行归档流程。
@@ -0,0 +1,160 @@
1
+ # prompts/4-verify · C3 验证
2
+
3
+ ---
4
+
5
+ ## 🔴 Step -1:规则加载(不读 = 不得执行)
6
+
7
+ ```
8
+ Read @atdc/reference/risk.md → 风险评分算法(Step 0 评分所需)
9
+ ```
10
+
11
+ > **Token 节约**:运行测试用 `go test ./<pkg>/... 2>&1 | grep -E "PASS|FAIL|ok"`,不加 `-v`
12
+
13
+ ---
14
+
15
+ ## Step 0:风险评级
16
+
17
+ ### 0a. 检查是否有 Review 报告
18
+
19
+ ```bash
20
+ cat openspec/changes/<name>/review-report.md 2>/dev/null && echo "---EXISTS---" || echo "[无 review 报告]"
21
+ ```
22
+
23
+ 如有 review 报告,直接读取风险评分。
24
+
25
+ ### 0b. 无 Review 报告时自动计算风险评分
26
+
27
+ ### 0c. Ponytail 变更检查(检测新增过度工程化)
28
+
29
+ ```bash
30
+ # 扫描本次变更是否引入新的过度工程化代码
31
+ atdc ponytail scan --diff 2>/dev/null || echo "[Ponytail scan skipped]"
32
+ ```
33
+
34
+ > 如果发现新增 P2 模式 → 记录到验证报告,建议在下次迭代修复
35
+ > 如果发现新增 P0/P1 模式 → **暂停**,提醒用户当前 diff 在重复已有模式
36
+
37
+ ---
38
+
39
+ ```
40
+ codegraph_impact "<SymbolName>" depth=2
41
+ ```
42
+
43
+ 按 `@atdc/reference/risk.md` 算出总分(4-12 分),确定风险等级:
44
+
45
+ | 总分 | 等级 | 验证严格度 |
46
+ |------|------|-----------|
47
+ | 4-6 | 🟢 低风险 | 增量验证(只跑变更相关的测试) |
48
+ | 7-9 | 🟡 中风险 | 标准验证(跑变更模块的全量测试) |
49
+ | 10-12 | 🔴 高风险 | 全量验证(全量测试 + 受影响流程 E2E + 人工二次确认) |
50
+
51
+ 宣布:`"风险等级:🟢/🟡/🔴(<分数>/12),验证严格度:<增量/标准/全量>"`
52
+
53
+ ---
54
+
55
+ ## Step 1:逐条检查 Verification Checklist
56
+
57
+ 读取 `openspec/changes/<name>/tasks.md` 的 `## Verification Checklist`:
58
+
59
+ ```bash
60
+ grep "- \[ \]" openspec/changes/<name>/tasks.md
61
+ ```
62
+
63
+ 对每条 SHALL/MUST:
64
+ 1. 找到对应实现文件,确认代码存在(优先用 `codegraph_search` 定位,而非 `grep`)
65
+ 2. 运行测试确认通过:`go test ./<pkg>/... 2>&1 | grep -E "PASS|FAIL|ok"`
66
+ 3. 打勾 `- [x]`
67
+
68
+ **按风险等级调整测试范围**:
69
+ - 🟢 低风险:只跑变更包的测试 `go test ./<changed-pkg>/...`
70
+ - 🟡 中风险:跑变更模块及直接依赖模块的测试
71
+ - 🔴 高风险:全量测试 `go test ./...`
72
+
73
+ ---
74
+
75
+ ## Step 2:Gate 4 — 实现一致性 + Test Gap
76
+
77
+ ```bash
78
+ git diff --name-only HEAD
79
+ ```
80
+
81
+ 对比追溯矩阵(`.progress.json` 的 `traceability`):
82
+ - 不在矩阵中的变更文件 → 标为"无主变更",列出等用户确认
83
+ - 检查 AGENTS.md/CLAUDE.md 中的领域约束是否被绕过
84
+
85
+ ### 2a. Test Gap 最终检查
86
+
87
+ 对每个变更文件中的新增/修改函数:
88
+
89
+ ```
90
+ codegraph_callers "<FunctionName>"
91
+ ```
92
+
93
+ 检查返回的调用方中是否包含测试文件。汇总 3-impl 执行中记录的覆盖情况:
94
+
95
+ ```
96
+ 📊 最终测试覆盖汇总
97
+
98
+ ✅ 已覆盖:N 个函数
99
+ ❌ 未覆盖:M 个函数(列出)
100
+
101
+ 🔴 高风险变更中未覆盖的函数必须补充测试。
102
+ 🟡 中风险变更中未覆盖的函数建议补充。
103
+ 🟢 低风险变更中未覆盖的函数可接受。
104
+ ```
105
+
106
+ 🔴 高风险 + 未覆盖 → **阻塞**,必须补充测试后才能继续。
107
+
108
+ ---
109
+
110
+ ## Step 3:报告
111
+
112
+ ```
113
+ 📋 C3 验证报告
114
+
115
+ 风险等级:🟢/🟡/🔴(<分数>/12)
116
+ 验证严格度:<增量/标准/全量>
117
+
118
+ ✅ 通过:N 条 SHALL/MUST
119
+ ❌ 未通过:
120
+ - [ ] <需求描述> → <原因>
121
+
122
+ ⚠️ 无主变更:<文件列表>
123
+ 📊 测试覆盖:已覆盖 N / 未覆盖 M
124
+
125
+ 是否修复后重新验证?[是 / 跳过]
126
+ ```
127
+
128
+ 验证失败 → 自动修复 → 重新验证(最多 3 轮)。
129
+
130
+ 全部通过后:
131
+
132
+ ---
133
+
134
+ ## Step 3.5:Session Reflection — 检测 golden path
135
+
136
+ > C3 验证刚完成,整个 change 的执行路径还 fresh。趁现在反思:**这次有没有学到值得沉淀的东西?**
137
+
138
+ 1. 检查 `.progress.json` 的 `failedAt` / `failedReason` 字段:
139
+ ```bash
140
+ python3 -c "
141
+ import json
142
+ with open('openspec/changes/<name>/.progress.json') as f:
143
+ d = json.load(f)
144
+ print('failedAt:', d.get('failedAt'))
145
+ print('failedReason:', d.get('failedReason'))
146
+ "
147
+ ```
148
+
149
+ 2. 若有失败记录 → 说明本次 change 涉及超过 2 次尝试的操作 → 触发 `/atdc:learn --auto`(静默模式,不交互)
150
+
151
+ 3. 无失败记录但涉及非显而易见操作 → 提示用户:
152
+ ```
153
+ 💡 本次 change 执行过程中是否学到了值得沉淀的路径?
154
+ - 说"learn"或"/atdc:learn" → 手动触发 golden path 检测
155
+ - 说"继续" → 跳过,进入归档
156
+ ```
157
+
158
+ 4. 无特殊操作 → 静默跳过,然后 **Read `@atdc/prompts/5-done.md`** 进入归档。
159
+
160
+ > 若触发 learn,完成后继续 **Read 5-done.md**。