@chenmk/superflow 0.4.0 → 0.5.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 (242) hide show
  1. package/INSTALL.en.md +58 -12
  2. package/INSTALL.md +62 -33
  3. package/README.md +181 -54
  4. package/README.zh-CN.md +158 -51
  5. package/assets/brand/managed-review-loop.png +0 -0
  6. package/assets/manifest.json +10 -5
  7. package/assets/scripts/superflow-coding-ready.mjs +135 -0
  8. package/assets/scripts/superflow-dependency-update-hook.sh +81 -8
  9. package/assets/scripts/superflow-document-audit.mjs +240 -0
  10. package/assets/scripts/superflow-environment-preflight.mjs +398 -0
  11. package/assets/scripts/superflow-hook-guard.sh +40 -1
  12. package/assets/scripts/superflow-managed-command-guard.py +309 -0
  13. package/assets/scripts/superflow-managed-executor-preflight.mjs +421 -0
  14. package/assets/scripts/superflow-managed-owner-verification.sh +117 -0
  15. package/assets/scripts/superflow-managed-work-check.mjs +287 -26
  16. package/assets/scripts/superflow-managed-work-guard.sh +6 -92
  17. package/assets/skills/superflow-clarify/SKILL.md +14 -0
  18. package/assets/skills/superflow-design/SKILL.md +38 -13
  19. package/assets/skills/superflow-docs/SKILL.md +93 -2
  20. package/assets/skills/superflow-pipeline/SKILL.md +167 -10
  21. package/assets/skills/superflow-pipeline/references/batch-prompt-template.md +17 -9
  22. package/assets/skills/superflow-pipeline/references/document-readiness.md +157 -0
  23. package/assets/skills/superflow-pipeline/references/document-templates.md +9 -5
  24. package/assets/skills/superflow-pipeline/references/feature-gated-workflow.md +14 -0
  25. package/assets/skills/superflow-pipeline/references/implementation-prompt-template.md +20 -11
  26. package/assets/skills/superflow-pipeline/references/managed-work.md +123 -15
  27. package/assets/skills/superflow-pipeline/references/orchestration.md +2 -2
  28. package/assets/skills/superflow-pipeline/references/p0-baseline-template.md +3 -2
  29. package/assets/skills/superflow-pipeline/references/quality-gate.md +7 -5
  30. package/assets/skills/superflow-pipeline/references/reviewer-checklist.md +7 -0
  31. package/assets/skills/superflow-pipeline/scripts/superflow-guard.sh +205 -9
  32. package/assets/skills/superflow-pipeline/scripts/superflow-handoff.sh +7 -4
  33. package/assets/skills/superflow-requirement-review/SKILL.md +178 -0
  34. package/assets/skills/superflow-requirement-review/agents/openai.yaml +4 -0
  35. package/assets/skills-en/superflow-clarify/SKILL.md +17 -0
  36. package/assets/skills-en/superflow-design/SKILL.md +31 -12
  37. package/assets/skills-en/superflow-docs/SKILL.md +99 -0
  38. package/assets/skills-en/superflow-pipeline/SKILL.md +163 -9
  39. package/assets/skills-en/superflow-pipeline/references/batch-prompt-template.md +4 -0
  40. package/assets/skills-en/superflow-pipeline/references/document-readiness.md +125 -0
  41. package/assets/skills-en/superflow-pipeline/references/document-templates.md +10 -0
  42. package/assets/skills-en/superflow-pipeline/references/feature-gated-workflow.md +7 -0
  43. package/assets/skills-en/superflow-pipeline/references/implementation-prompt-template.md +7 -0
  44. package/assets/skills-en/superflow-pipeline/references/managed-work.md +160 -10
  45. package/assets/skills-en/superflow-pipeline/references/quality-gate.md +12 -0
  46. package/assets/skills-en/superflow-pipeline/references/reviewer-checklist.md +7 -0
  47. package/assets/skills-en/superflow-pipeline/scripts/superflow-guard.sh +205 -9
  48. package/assets/skills-en/superflow-pipeline/scripts/superflow-handoff.sh +7 -4
  49. package/assets/skills-en/superflow-requirement-review/SKILL.md +99 -0
  50. package/assets/skills-en/superflow-requirement-review/agents/openai.yaml +4 -0
  51. package/dist/app/cli.js +64 -9
  52. package/dist/app/cli.js.map +1 -1
  53. package/dist/app/commands/change-guard.js +19 -2
  54. package/dist/app/commands/change-guard.js.map +1 -1
  55. package/dist/app/commands/check.js +107 -45
  56. package/dist/app/commands/check.js.map +1 -1
  57. package/dist/app/commands/docs.js +7 -3
  58. package/dist/app/commands/docs.js.map +1 -1
  59. package/dist/app/commands/doctor.js +174 -198
  60. package/dist/app/commands/doctor.js.map +1 -1
  61. package/dist/app/commands/eval.js +64 -0
  62. package/dist/app/commands/eval.js.map +1 -0
  63. package/dist/app/commands/implement.js +7 -3
  64. package/dist/app/commands/implement.js.map +1 -1
  65. package/dist/app/commands/init.js +12 -24
  66. package/dist/app/commands/init.js.map +1 -1
  67. package/dist/app/commands/mcp.js +167 -0
  68. package/dist/app/commands/mcp.js.map +1 -0
  69. package/dist/app/commands/pipeline.js +652 -18
  70. package/dist/app/commands/pipeline.js.map +1 -1
  71. package/dist/app/commands/requirement-review.js +6 -0
  72. package/dist/app/commands/requirement-review.js.map +1 -0
  73. package/dist/app/commands/status.js +66 -3
  74. package/dist/app/commands/status.js.map +1 -1
  75. package/dist/app/commands/uninstall.js +3 -3
  76. package/dist/app/commands/uninstall.js.map +1 -1
  77. package/dist/app/commands/update.js +83 -9
  78. package/dist/app/commands/update.js.map +1 -1
  79. package/dist/domains/agent.js +3 -11
  80. package/dist/domains/agent.js.map +1 -1
  81. package/dist/domains/config/cli-help.js +54 -12
  82. package/dist/domains/config/cli-help.js.map +1 -1
  83. package/dist/domains/config/i18n.js +6 -8
  84. package/dist/domains/config/i18n.js.map +1 -1
  85. package/dist/domains/config/manifest.js +0 -3
  86. package/dist/domains/config/manifest.js.map +1 -1
  87. package/dist/domains/deps.js +68 -7
  88. package/dist/domains/deps.js.map +1 -1
  89. package/dist/domains/managed-work/completion-policy.js +174 -0
  90. package/dist/domains/managed-work/completion-policy.js.map +1 -0
  91. package/dist/domains/managed-work/context-manifest.js +208 -0
  92. package/dist/domains/managed-work/context-manifest.js.map +1 -0
  93. package/dist/domains/managed-work/contract.js +135 -4
  94. package/dist/domains/managed-work/contract.js.map +1 -1
  95. package/dist/domains/managed-work/control-signals.js +34 -0
  96. package/dist/domains/managed-work/control-signals.js.map +1 -0
  97. package/dist/domains/managed-work/control.js +628 -0
  98. package/dist/domains/managed-work/control.js.map +1 -0
  99. package/dist/domains/managed-work/evaluation.js +497 -0
  100. package/dist/domains/managed-work/evaluation.js.map +1 -0
  101. package/dist/domains/managed-work/evidence-path.js +14 -0
  102. package/dist/domains/managed-work/evidence-path.js.map +1 -0
  103. package/dist/domains/managed-work/execution-contract.js +167 -0
  104. package/dist/domains/managed-work/execution-contract.js.map +1 -0
  105. package/dist/domains/managed-work/executor-policy.js +65 -0
  106. package/dist/domains/managed-work/executor-policy.js.map +1 -0
  107. package/dist/domains/managed-work/failure.js +65 -0
  108. package/dist/domains/managed-work/failure.js.map +1 -0
  109. package/dist/domains/managed-work/host-review.js +77 -0
  110. package/dist/domains/managed-work/host-review.js.map +1 -0
  111. package/dist/domains/managed-work/human-messages.js +31 -0
  112. package/dist/domains/managed-work/human-messages.js.map +1 -0
  113. package/dist/domains/managed-work/input.js +29 -3
  114. package/dist/domains/managed-work/input.js.map +1 -1
  115. package/dist/domains/managed-work/journal.js +77 -3
  116. package/dist/domains/managed-work/journal.js.map +1 -1
  117. package/dist/domains/managed-work/lock.js +67 -1
  118. package/dist/domains/managed-work/lock.js.map +1 -1
  119. package/dist/domains/managed-work/notifications.js +0 -15
  120. package/dist/domains/managed-work/notifications.js.map +1 -1
  121. package/dist/domains/managed-work/pair-admission.js +108 -0
  122. package/dist/domains/managed-work/pair-admission.js.map +1 -0
  123. package/dist/domains/managed-work/prompts.js +257 -22
  124. package/dist/domains/managed-work/prompts.js.map +1 -1
  125. package/dist/domains/managed-work/redaction.js +90 -0
  126. package/dist/domains/managed-work/redaction.js.map +1 -0
  127. package/dist/domains/managed-work/review-convergence.js +41 -0
  128. package/dist/domains/managed-work/review-convergence.js.map +1 -0
  129. package/dist/domains/managed-work/review-facts.js +181 -0
  130. package/dist/domains/managed-work/review-facts.js.map +1 -0
  131. package/dist/domains/managed-work/rule-selection.js +84 -0
  132. package/dist/domains/managed-work/rule-selection.js.map +1 -0
  133. package/dist/domains/managed-work/runner.js +1967 -175
  134. package/dist/domains/managed-work/runner.js.map +1 -1
  135. package/dist/domains/managed-work/schemas.js +72 -2
  136. package/dist/domains/managed-work/schemas.js.map +1 -1
  137. package/dist/domains/managed-work/service.js +82 -13
  138. package/dist/domains/managed-work/service.js.map +1 -1
  139. package/dist/domains/managed-work/state.js +195 -5
  140. package/dist/domains/managed-work/state.js.map +1 -1
  141. package/dist/domains/managed-work/storage.js +66 -24
  142. package/dist/domains/managed-work/storage.js.map +1 -1
  143. package/dist/domains/managed-work/types.js +12 -9
  144. package/dist/domains/managed-work/types.js.map +1 -1
  145. package/dist/domains/managed-work/verification-categories.js +39 -0
  146. package/dist/domains/managed-work/verification-categories.js.map +1 -0
  147. package/dist/domains/managed-work/verification-policy.js +116 -0
  148. package/dist/domains/managed-work/verification-policy.js.map +1 -0
  149. package/dist/domains/managed-work/wait.js +21 -3
  150. package/dist/domains/managed-work/wait.js.map +1 -1
  151. package/dist/domains/managed-work/workspace-binding.js +133 -0
  152. package/dist/domains/managed-work/workspace-binding.js.map +1 -0
  153. package/dist/domains/sdd-readiness.js +44 -0
  154. package/dist/domains/sdd-readiness.js.map +1 -0
  155. package/dist/domains/skill/deploy.js +0 -6
  156. package/dist/domains/skill/deploy.js.map +1 -1
  157. package/dist/domains/skill/scripts.js +0 -8
  158. package/dist/domains/skill/scripts.js.map +1 -1
  159. package/dist/domains/state.js +1 -2
  160. package/dist/domains/state.js.map +1 -1
  161. package/dist/mcp/runtime-identity.js +21 -0
  162. package/dist/mcp/runtime-identity.js.map +1 -0
  163. package/dist/mcp/server.js +369 -0
  164. package/dist/mcp/server.js.map +1 -0
  165. package/dist/platform/agent-process.js +499 -38
  166. package/dist/platform/agent-process.js.map +1 -1
  167. package/dist/platform/executable.js +28 -0
  168. package/dist/platform/executable.js.map +1 -0
  169. package/dist/platform/paths.js +1 -17
  170. package/dist/platform/paths.js.map +1 -1
  171. package/dist/platform/process-tree.js +44 -0
  172. package/dist/platform/process-tree.js.map +1 -0
  173. package/dist/platform/process.js +1 -1
  174. package/dist/platform/process.js.map +1 -1
  175. package/package.json +17 -7
  176. package/scripts/check-design-principles.mjs +107 -0
  177. package/scripts/check-managed-work-design.mjs +507 -0
  178. package/scripts/clean-dist.js +9 -0
  179. package/scripts/ensure-bin-modes.js +11 -0
  180. package/scripts/preinstall.js +57 -0
  181. package/dist/cli/index.js +0 -193
  182. package/dist/cli/index.js.map +0 -1
  183. package/dist/commands/archive.js +0 -6
  184. package/dist/commands/archive.js.map +0 -1
  185. package/dist/commands/clarify.js +0 -6
  186. package/dist/commands/clarify.js.map +0 -1
  187. package/dist/commands/design.js +0 -28
  188. package/dist/commands/design.js.map +0 -1
  189. package/dist/commands/docs.js +0 -6
  190. package/dist/commands/docs.js.map +0 -1
  191. package/dist/commands/doctor.js +0 -494
  192. package/dist/commands/doctor.js.map +0 -1
  193. package/dist/commands/implement.js +0 -6
  194. package/dist/commands/implement.js.map +0 -1
  195. package/dist/commands/init.js +0 -520
  196. package/dist/commands/init.js.map +0 -1
  197. package/dist/commands/pipeline.js +0 -6
  198. package/dist/commands/pipeline.js.map +0 -1
  199. package/dist/commands/scan.js +0 -63
  200. package/dist/commands/scan.js.map +0 -1
  201. package/dist/commands/status.js +0 -173
  202. package/dist/commands/status.js.map +0 -1
  203. package/dist/commands/uninstall.js +0 -214
  204. package/dist/commands/uninstall.js.map +0 -1
  205. package/dist/commands/update.js +0 -193
  206. package/dist/commands/update.js.map +0 -1
  207. package/dist/commands/verify.js +0 -6
  208. package/dist/commands/verify.js.map +0 -1
  209. package/dist/core/assets.js +0 -27
  210. package/dist/core/assets.js.map +0 -1
  211. package/dist/core/cli-help.js +0 -98
  212. package/dist/core/cli-help.js.map +0 -1
  213. package/dist/core/context.js +0 -123
  214. package/dist/core/context.js.map +0 -1
  215. package/dist/core/dependencies.js +0 -146
  216. package/dist/core/dependencies.js.map +0 -1
  217. package/dist/core/detect.js +0 -64
  218. package/dist/core/detect.js.map +0 -1
  219. package/dist/core/i18n.js +0 -105
  220. package/dist/core/i18n.js.map +0 -1
  221. package/dist/core/integrity.js +0 -46
  222. package/dist/core/integrity.js.map +0 -1
  223. package/dist/core/manifest.js +0 -21
  224. package/dist/core/manifest.js.map +0 -1
  225. package/dist/core/prompts.js +0 -20
  226. package/dist/core/prompts.js.map +0 -1
  227. package/dist/core/registry.js +0 -134
  228. package/dist/core/registry.js.map +0 -1
  229. package/dist/core/rules.js +0 -17
  230. package/dist/core/rules.js.map +0 -1
  231. package/dist/core/scripts.js +0 -48
  232. package/dist/core/scripts.js.map +0 -1
  233. package/dist/core/skill-check.js +0 -32
  234. package/dist/core/skill-check.js.map +0 -1
  235. package/dist/core/skills.js +0 -62
  236. package/dist/core/skills.js.map +0 -1
  237. package/dist/core/state.js +0 -54
  238. package/dist/core/state.js.map +0 -1
  239. package/dist/utils/path.js +0 -11
  240. package/dist/utils/path.js.map +0 -1
  241. package/dist/utils/shell.js +0 -29
  242. package/dist/utils/shell.js.map +0 -1
@@ -322,6 +322,103 @@ change_has_field_status_risk() {
322
322
  "$CHANGE_DIR"/*.md "$CHANGE_DIR"/**/*.md 2>/dev/null
323
323
  }
324
324
 
325
+ change_has_database_change() {
326
+ if grep -Eiq '^[[:space:]]*database:[[:space:]]*false([[:space:]]*#.*)?$' "$CHANGE_DIR/.openspec.yaml" 2>/dev/null; then
327
+ return 1
328
+ fi
329
+ if grep -Eiq '^[[:space:]]*database:[[:space:]]*true([[:space:]]*#.*)?$' "$CHANGE_DIR/.openspec.yaml" 2>/dev/null; then
330
+ return 0
331
+ fi
332
+ grep -RIEiq \
333
+ 'database_change[[:space:]]*:[[:space:]]*true|数据库变更.{0,8}(是|需要|包含)|ALTER[[:space:]]+TABLE|CREATE[[:space:]]+TABLE|ADD[[:space:]]+(COLUMN|INDEX|KEY|CONSTRAINT)|(^|[^不未无])新增.{0,12}(表|字段|索引|约束)|(^|[^不未无])(历史数据|初始化数据).{0,12}(迁移|回填)|schema[ -]migration|database[ -]migration|add.{0,12}(table|column|index|constraint)' \
334
+ "$CHANGE_DIR/proposal.md" \
335
+ "$CHANGE_DIR/api.md" \
336
+ "$CHANGE_DIR/design.md" \
337
+ "$CHANGE_DIR/tasks.md" \
338
+ "$CHANGE_DIR/database-contract.md" \
339
+ "$CHANGE_DIR/spec.md" \
340
+ "$CHANGE_DIR"/specs/*/spec.md 2>/dev/null
341
+ }
342
+
343
+ require_frozen_release_sql() {
344
+ local release_sql="$CHANGE_DIR/release-sql.md"
345
+ local output
346
+
347
+ require_file release-sql.md
348
+ [[ -f "$release_sql" ]] || return 0
349
+
350
+ output="$(mktemp)"
351
+ if ! python3 - "$release_sql" >"$output" 2>&1 <<'PY'
352
+ import hashlib
353
+ import re
354
+ import sys
355
+ from pathlib import Path
356
+
357
+ path = Path(sys.argv[1])
358
+ text = path.read_text(encoding="utf-8")
359
+ errors = []
360
+
361
+ front_match = re.match(r"\A---\n(.*?)\n---(?:\n|\Z)", text, re.S)
362
+ front = front_match.group(1) if front_match else ""
363
+ if not front_match:
364
+ errors.append("front matter is missing")
365
+
366
+ def field(name):
367
+ match = re.search(rf"(?m)^{re.escape(name)}:\s*(.*?)\s*$", front)
368
+ return match.group(1).strip().strip('"\'') if match else ""
369
+
370
+ if field("database_change").lower() != "true":
371
+ errors.append("database_change must be true")
372
+
373
+ target = field("target_sql_path")
374
+ if not target or not target.lower().endswith(".sql"):
375
+ errors.append("target_sql_path must be an exact .sql path")
376
+ if re.search(r"[<>{}]|testN|version|待定|pending", target, re.I):
377
+ errors.append("target_sql_path contains a placeholder")
378
+
379
+ if field("copy_policy").lower() != "verbatim":
380
+ errors.append("copy_policy must be verbatim")
381
+
382
+ declared_hash = field("sql_sha256").lower()
383
+ if not re.fullmatch(r"[0-9a-f]{64}", declared_hash):
384
+ errors.append("sql_sha256 must be a 64-character lowercase SHA-256")
385
+
386
+ blocks = re.findall(r"```sql[^\n]*\n(.*?)\n```", text, re.S | re.I)
387
+ if len(blocks) != 1:
388
+ errors.append("release-sql.md must contain exactly one sql code block")
389
+ else:
390
+ payload = blocks[0].replace("\r\n", "\n").replace("\r", "\n").rstrip("\n") + "\n"
391
+ actual_hash = hashlib.sha256(payload.encode("utf-8")).hexdigest()
392
+ if declared_hash and actual_hash != declared_hash:
393
+ errors.append(
394
+ f"sql_sha256 mismatch: declared={declared_hash} actual={actual_hash}"
395
+ )
396
+ executable = re.sub(r"/\*.*?\*/|--[^\n]*", "", payload, flags=re.S)
397
+ if not re.search(
398
+ r"\b(CREATE|ALTER|DROP|INSERT|UPDATE|DELETE|MERGE|TRUNCATE|CALL)\b",
399
+ executable,
400
+ re.I,
401
+ ):
402
+ errors.append("sql block has no executable schema/data change statement")
403
+ if not re.search(r"\b(SELECT|SHOW|CALL)\b", executable, re.I):
404
+ errors.append("sql block has no executable verification statement")
405
+
406
+ if errors:
407
+ print("; ".join(errors))
408
+ sys.exit(1)
409
+ PY
410
+ then
411
+ issues+=("frozen release SQL invalid: $(tr '\n' ' ' < "$output" | sed -E 's/[[:space:]]+/ /g')")
412
+ fi
413
+ rm -f "$output"
414
+
415
+ require_grep 'release-sql\.md' design.md "frozen release SQL design reference"
416
+ require_grep 'release-sql\.md' tasks.md "frozen release SQL task reference"
417
+ require_grep 'release-sql\.md' sdd-quality-gate.md "frozen release SQL quality-gate reference"
418
+ require_grep '原样复制|verbatim' tasks.md "verbatim SQL copy task"
419
+ require_grep '原样复制|verbatim' sdd-quality-gate.md "verbatim SQL copy quality gate"
420
+ }
421
+
325
422
  change_has_external_enum_risk() {
326
423
  grep -RIEiq \
327
424
  'BEM|payOrigin|payMode|支付来源|支付方式|财务口径|第三方枚举|第三方字段|third[- ]party enum|source system|SDK.*枚举|枚举.*SDK' \
@@ -352,6 +449,12 @@ change_all_docs_without_complexity_budget() {
352
449
  }
353
450
 
354
451
  change_has_external_config_risk() {
452
+ if grep -Eiq '^[[:space:]]*external_config:[[:space:]]*false([[:space:]]*#.*)?$' "$CHANGE_DIR/.openspec.yaml" 2>/dev/null; then
453
+ return 1
454
+ fi
455
+ if grep -Eiq '^[[:space:]]*external_config:[[:space:]]*true([[:space:]]*#.*)?$' "$CHANGE_DIR/.openspec.yaml" 2>/dev/null; then
456
+ return 0
457
+ fi
355
458
  local content
356
459
  content="$(change_contract_docs_without_complexity_budget)"
357
460
  grep -Eiq \
@@ -360,6 +463,12 @@ change_has_external_config_risk() {
360
463
  }
361
464
 
362
465
  change_has_concurrency_idempotency_risk() {
466
+ if grep -Eiq '^[[:space:]]*concurrency:[[:space:]]*false([[:space:]]*#.*)?$' "$CHANGE_DIR/.openspec.yaml" 2>/dev/null; then
467
+ return 1
468
+ fi
469
+ if grep -Eiq '^[[:space:]]*concurrency:[[:space:]]*true([[:space:]]*#.*)?$' "$CHANGE_DIR/.openspec.yaml" 2>/dev/null; then
470
+ return 0
471
+ fi
363
472
  grep -RIEiq \
364
473
  '并发|批量下发|批量开通|批量续费|重复提交|重复回调|重复消费|重复下发|幂等|竞态|原子占用|concurren|idempoten|race condition|duplicate (request|callback|consumption|delivery)|atomic claim' \
365
474
  "$CHANGE_DIR/proposal.md" \
@@ -371,6 +480,12 @@ change_has_concurrency_idempotency_risk() {
371
480
  }
372
481
 
373
482
  change_has_money_precision_risk() {
483
+ if grep -Eiq '^[[:space:]]*money:[[:space:]]*false([[:space:]]*#.*)?$' "$CHANGE_DIR/.openspec.yaml" 2>/dev/null; then
484
+ return 1
485
+ fi
486
+ if grep -Eiq '^[[:space:]]*money:[[:space:]]*true([[:space:]]*#.*)?$' "$CHANGE_DIR/.openspec.yaml" 2>/dev/null; then
487
+ return 0
488
+ fi
374
489
  grep -RIEiq \
375
490
  '金额|费用|价格|优惠|折扣|抵扣|退款|分账|支付|发票|余额|电费|服务费|套餐结算|比例分摊|明细分配|尾差|精度|舍入|(^|[^[:alnum:]_])(amount|fee|fees|price|discount|deduction|refund|payment|invoice|balance|proration|allocation|reconciliation|rounding)([^[:alnum:]_]|$)|revenue sharing|profit sharing|split payment|serviceFee|chargeFee|totalAmount|actualAmount|payAmount|refundAmount|discountAmount|invoiceAmount|balanceAmount' \
376
491
  "$CHANGE_DIR/proposal.md" \
@@ -381,6 +496,53 @@ change_has_money_precision_risk() {
381
496
  "$CHANGE_DIR"/specs/*/spec.md 2>/dev/null
382
497
  }
383
498
 
499
+ change_has_source_fact_risk() {
500
+ grep -RIEiq \
501
+ '现有|现行|遗留|数据库|数据表|表关系|Mapper|XML|跨仓|跨服务|真实入口|小程序|H5|existing|current behavior|legacy|database|table relationship|cross[- ](repo|service)|crosses services|real entry|mini[- ]program' \
502
+ "$CHANGE_DIR/proposal.md" \
503
+ "$CHANGE_DIR/api.md" \
504
+ "$CHANGE_DIR/design.md" \
505
+ "$CHANGE_DIR/tests.md" \
506
+ "$CHANGE_DIR/spec.md" \
507
+ "$CHANGE_DIR"/specs/*/spec.md 2>/dev/null
508
+ }
509
+
510
+ change_has_cardinality_conflict_signal() {
511
+ grep -RIEiq \
512
+ 'List[<((]|orderIds|batchInsert|批量插入|一对多|one[- ]to[- ]many|关系表' \
513
+ "$CHANGE_DIR"/*.md "$CHANGE_DIR"/**/*.md 2>/dev/null
514
+ }
515
+
516
+ require_source_fact_audit() {
517
+ require_file source-code-audit.md
518
+ require_grep '源码事实冻结卡|Source Fact Freeze Card' source-code-audit.md "source fact freeze card"
519
+ require_grep '业务结论|Business conclusion' source-code-audit.md "source fact business conclusion"
520
+ require_grep 'understand.*定位|understand.*locator' source-code-audit.md "understand-anything locator evidence"
521
+ require_grep '数据模型|Data model' source-code-audit.md "source fact data model"
522
+ require_grep '所有写入方|All writers' source-code-audit.md "all writers inventory"
523
+ require_grep '真实用户入口|Real user entr' source-code-audit.md "real user entry"
524
+ require_grep '当前调用方|Current callers' source-code-audit.md "current callers"
525
+ require_grep '遗留冲突|Legacy conflict' source-code-audit.md "legacy conflict"
526
+ require_grep 'DB.*(必查|核查|跳过|未执行|reason)|数据库.*(必查|核查|跳过|未执行|原因)|DB (check|required|skip|reason)' source-code-audit.md "DB check or skip reason"
527
+ require_grep '结论等级|Conclusion level' source-code-audit.md "conclusion level"
528
+ require_grep 'owner.*(决策|decision)|决策.*owner' source-code-audit.md "owner decision boundary"
529
+ require_grep 'current|现行入口' source-code-audit.md "current evidence classification"
530
+ require_grep 'legacy|遗留入口' source-code-audit.md "legacy evidence classification"
531
+ require_grep 'unmounted|无前端调用' source-code-audit.md "unmounted evidence classification"
532
+ require_grep 'data-model-only|仅数据模型可表达' source-code-audit.md "data-model-only evidence classification"
533
+ require_grep 'owner-confirmed|owner 已确认' source-code-audit.md "owner-confirmed evidence classification"
534
+ require_grep 'blocked|阻塞' source-code-audit.md "blocked evidence classification"
535
+ require_grep '(证据分类|Evidence classifications).*(current|现行).*(legacy|遗留).*(unmounted|无前端调用).*(data-model-only|仅数据模型可表达).*(owner-confirmed|owner 已确认).*(blocked|阻塞)' source-code-audit.md "complete evidence classification set"
536
+ require_grep '提问资格门禁|Question Eligibility Gate' source-code-audit.md "question eligibility gate"
537
+ require_grep '源码检索|Source search' source-code-audit.md "source search evidence"
538
+ require_grep 'Mapper.*SQL|SQL.*Mapper' source-code-audit.md "Mapper and SQL search evidence"
539
+ require_grep '前端.*小程序.*H5|Frontend.*mini[- ]program.*H5' source-code-audit.md "frontend mini-program H5 caller search"
540
+ require_grep 'sibling.*repo|兄弟仓|关联仓' source-code-audit.md "sibling repository search"
541
+ if change_has_cardinality_conflict_signal; then
542
+ require_grep '冲突审计|Conflict Audit' source-code-audit.md "cardinality conflict audit"
543
+ fi
544
+ }
545
+
384
546
  change_has_fx_precision_risk() {
385
547
  grep -RIEiq \
386
548
  '汇率|换汇|外汇|币种转换|跨币种|兑换率|(^|[^[:alnum:]_])(exchange rate|fx rate|currency conversion|cross.currency|base currency|quote currency)([^[:alnum:]_]|$)' \
@@ -400,8 +562,10 @@ change_has_architecture_boundary_risk() {
400
562
  <<< "$content"
401
563
  }
402
564
 
403
- first_prompt_rel() {
404
- find "$CHANGE_DIR" -path '*/prompt/*.md' -type f | head -n 1 | sed "s#^$CHANGE_DIR/##"
565
+ prompt_rels() {
566
+ find "$CHANGE_DIR" -path '*/prompt/*.md' -type f -print \
567
+ | LC_ALL=C sort \
568
+ | sed "s#^$CHANGE_DIR/##"
405
569
  }
406
570
 
407
571
  require_any_prompt() {
@@ -411,7 +575,7 @@ require_any_prompt() {
411
575
  }
412
576
 
413
577
  require_prompt_set() {
414
- local task_count prompt_count non_index_prompt_count
578
+ local task_count prompt_count non_index_prompt_count prompt_rel document
415
579
  require_file prompt/implementation.md
416
580
  task_count="$(grep -E '^[[:space:]]*-[[:space:]]+\[[ xX]\]' "$CHANGE_DIR/tasks.md" 2>/dev/null | wc -l | tr -d ' ')"
417
581
  prompt_count="$(find "$CHANGE_DIR/prompt" -maxdepth 1 -type f -name '*.md' 2>/dev/null | wc -l | tr -d ' ')"
@@ -422,9 +586,15 @@ require_prompt_set() {
422
586
  if [[ "$prompt_count" -eq 0 ]]; then
423
587
  issues+=("missing prompt/*.md files")
424
588
  fi
425
- if [[ -f "$CHANGE_DIR/tasks.md" ]] && ! grep -Riq 'prompt/.*\.md' "$CHANGE_DIR/tasks.md" "$CHANGE_DIR/traceability-matrix.md" "$CHANGE_DIR/sdd-quality-gate.md" "$CHANGE_DIR/test-report.md" 2>/dev/null; then
426
- issues+=("prompt files are not cross-linked from tasks/traceability/quality gate/test-report")
427
- fi
589
+ for document in tasks.md traceability-matrix.md sdd-quality-gate.md test-report.md; do
590
+ [[ -f "$CHANGE_DIR/$document" ]] || continue
591
+ while IFS= read -r prompt_rel; do
592
+ if ! grep -Fq "]($prompt_rel)" "$CHANGE_DIR/$document" \
593
+ && ! grep -Fq "](./$prompt_rel)" "$CHANGE_DIR/$document"; then
594
+ issues+=("$document does not link $prompt_rel")
595
+ fi
596
+ done < <(prompt_rels)
597
+ done
428
598
  }
429
599
 
430
600
  require_external_enum_contract() {
@@ -571,11 +741,27 @@ case "$PHASE" in
571
741
  require_grep 'RED|红绿|GREEN' tests.md "RED/GREEN test contract"
572
742
  require_grep 'curl|Postman|Newman|pytest|RestAssured|自动化命令' tests.md "interface automation command"
573
743
  require_grep 'handoff_hash|sdd-context|上下文包|防漂移' sdd-quality-gate.md "handoff/context-drift gate"
744
+ if change_has_database_change; then
745
+ require_frozen_release_sql
746
+ fi
574
747
  workflow="$(state_get workflow)"
575
748
  if [[ "$workflow" == "full" ]]; then
749
+ require_file requirement-review.md
750
+ require_grep '^review_verdict:[[:space:]]*PASS[[:space:]]*$' requirement-review.md "requirement reverse review PASS verdict"
751
+ require_grep '^implementation_readiness:[[:space:]]*READY[[:space:]]*$' requirement-review.md "requirement review implementation readiness"
752
+ require_grep '^open_blockers:[[:space:]]*0[[:space:]]*$' requirement-review.md "requirement reverse review has no open blockers"
753
+ require_grep '^open_external_contracts:[[:space:]]*0[[:space:]]*$' requirement-review.md "requirement review has no open external contracts"
754
+ require_grep '^open_source_investigations:[[:space:]]*0[[:space:]]*$' requirement-review.md "requirement review has no open source investigations"
755
+ require_grep '^open_owner_decisions:[[:space:]]*0[[:space:]]*$' requirement-review.md "requirement review has no open owner decisions"
756
+ require_grep '闭环矩阵|Closure Matrix' requirement-review.md "requirement review closure matrix"
757
+ require_grep '评审发现|Review Findings' requirement-review.md "requirement review findings"
758
+ require_grep '未关闭阻塞项|Open Blockers' requirement-review.md "requirement review open blocker ledger"
576
759
  require_minimal_design_review design.md "complexity reduction review"
577
760
  require_grep '复杂度减法评审|反过度设计评审|Minimal Design Review|Complexity Reduction Review' sdd-quality-gate.md "complexity reduction quality gate"
578
761
  require_minimal_design_pass sdd-quality-gate.md
762
+ if change_has_source_fact_risk; then
763
+ require_source_fact_audit
764
+ fi
579
765
  fi
580
766
  if change_has_external_enum_risk; then
581
767
  require_external_enum_contract api.md "external enum binding contract"
@@ -610,6 +796,9 @@ case "$PHASE" in
610
796
  require_handoff_current
611
797
  require_beta_handoff_structure
612
798
  require_hash_recorded
799
+ if change_has_database_change; then
800
+ require_frozen_release_sql
801
+ fi
613
802
  workflow="$(state_get workflow)"
614
803
  if [[ "$workflow" == "full" ]]; then
615
804
  require_minimal_design_review design.md "complexity reduction review"
@@ -652,11 +841,14 @@ case "$PHASE" in
652
841
  require_handoff_current
653
842
  require_beta_handoff_structure
654
843
  require_hash_recorded
844
+ if change_has_database_change; then
845
+ require_frozen_release_sql
846
+ fi
655
847
  require_any_prompt
656
848
  require_prompt_set
657
849
  require_grep 'OpenSpec/SDD|设计事实源|canonical|事实源' design.md "canonical source boundary"
658
- prompt_rel="$(first_prompt_rel)"
659
- if [[ -n "${prompt_rel:-}" ]]; then
850
+ while IFS= read -r prompt_rel; do
851
+ [[ -n "${prompt_rel:-}" ]] || continue
660
852
  require_grep 'Superpower 技术详设继承|Superpower 执行策略继承|technical_design|源码级 HOW' "$prompt_rel" "prompt Superpower strategy inheritance"
661
853
  technical_design_rel="$(state_get technical_design)"
662
854
  if [[ -n "${technical_design_rel:-}" && "$technical_design_rel" != "null" ]]; then
@@ -678,7 +870,11 @@ case "$PHASE" in
678
870
  fi
679
871
  fi
680
872
  require_grep '上下文防漂移|handoff_hash|sdd-context' "$prompt_rel" "prompt context drift inheritance"
681
- fi
873
+ if change_has_database_change; then
874
+ require_grep 'release-sql\.md' "$prompt_rel" "prompt frozen release SQL reference"
875
+ require_grep '原样复制|verbatim|sql_sha256' "$prompt_rel" "prompt verbatim SQL copy contract"
876
+ fi
877
+ done < <(prompt_rels)
682
878
  require_state_value build_mode "build_mode"
683
879
  require_state_value isolation "isolation"
684
880
  require_state_value tdd_mode "tdd_mode"
@@ -244,10 +244,13 @@ sync_state() {
244
244
  "$state_sh" set "$CHANGE_DIR" context_compression "$context_compression"
245
245
  "$state_sh" set "$CHANGE_DIR" handoff_context .sdd/handoff/sdd-context.json
246
246
  "$state_sh" set "$CHANGE_DIR" handoff_hash "$context_hash"
247
- technical_design_rel="$(
248
- find "$CHANGE_DIR/docs/superpowers/specs" -maxdepth 1 -type f -name '*.md' 2>/dev/null \
249
- | sort | head -n 1 | sed "s#^$CHANGE_DIR/##"
250
- )"
247
+ technical_design_rel=""
248
+ if [[ -d "$CHANGE_DIR/docs/superpowers/specs" ]]; then
249
+ technical_design_rel="$(
250
+ find "$CHANGE_DIR/docs/superpowers/specs" -maxdepth 1 -type f -name '*.md' \
251
+ | sort | head -n 1 | sed "s#^$CHANGE_DIR/##"
252
+ )"
253
+ fi
251
254
  if [[ -n "$technical_design_rel" ]]; then
252
255
  "$state_sh" set "$CHANGE_DIR" technical_design "$technical_design_rel"
253
256
  fi
@@ -0,0 +1,178 @@
1
+ ---
2
+ name: superflow-requirement-review
3
+ description: 对已澄清或已形成 OpenSpec/SDD 草案的需求和设计执行源码驱动的反向评审,主动发现闭环缺口、事实冲突、遗漏场景、过度设计、欠设计、API/UI/DB/tests 漂移及不可验证合同,并推动整改和复审闭环。Use when the user asks for 需求评审、反向评审、挑战需求、找遗漏、查错误、检查可测性、评审设计是否走偏、检查过度设计,或要求在 Superflow docs/design/implementation 前做独立审查。
4
+ ---
5
+
6
+ # Superflow Requirement Review
7
+
8
+ 对当前 OpenSpec change 进行独立、对抗式但基于证据的反向评审。评审不是旁路建议:
9
+ 阻塞级问题必须回写并修正文档,复审通过后才能离开 docs 阶段。
10
+
11
+ ## 边界
12
+
13
+ - 在复杂需求完成逐功能澄清、形成可评审文档草案后使用。
14
+ - 不替代 `superflow-clarify` 的 owner 决策确认,也不替代源码、Mapper/SQL、DB 和
15
+ 真实调用方核查。
16
+ - 不创建平行需求体系;产物必须落在当前 `openspec/changes/<change>/`。
17
+ - 不只输出意见清单。发现成立的问题后,必须修正 canonical 文档并复审。
18
+ - 不为了“解决遗漏”增加没有真实需求或复用证据的表、接口、服务、缓存和状态。
19
+
20
+ ## 必须读取
21
+
22
+ 按当前任务范围读取:
23
+
24
+ - 原始需求索引:`source-ingestion.md`、`feature-inventory.md`、`feature-gates.md`
25
+ - 合同:`proposal.md`、`api.md`、`specs/**/spec.md`、`design.md`
26
+ - 证据:`source-code-audit.md`、`database-contract.md`、`release-sql.md`
27
+ - 交付:`tasks.md`、`tests.md`、`traceability-matrix.md`、
28
+ `review-checklist.md`、`sdd-quality-gate.md`、`test-report.md`
29
+ - 当前源码、Mapper/XML、真实前端/小程序/H5 调用方、sibling repo,以及必要的
30
+ 只读数据库证据
31
+
32
+ 缺少某类文件时记录为评审发现,不得凭聊天记忆补结论。
33
+
34
+ ## 评审流程
35
+
36
+ ### 1. 冻结评审基线
37
+
38
+ 记录 change、当前 phase、需求来源、功能范围、handoff hash 和已确认/待确认决策。
39
+ 一次只评审一个已冻结功能;不得把下一功能的问题混入当前结论。
40
+
41
+ ### 2. 建立证据资格
42
+
43
+ 先完成平台影响面发现,再回到源码、Mapper/SQL、真实调用方和必要的只读 DB。
44
+ understand-anything 只作定位。将证据标记为 `current`、`legacy`、`unmounted`、
45
+ `data-model-only`、`owner-confirmed` 或 `blocked`。
46
+
47
+ 仓库和数据库能查明的事实不得转问用户。只有 owner 取舍才进入澄清,并且一次只问
48
+ 一个决策问题。
49
+
50
+ 所有未决项先按解决责任分类,禁止统一写成“外部待确认”:
51
+
52
+ - `SOURCE_INVESTIGATION`:源码、依赖、配置、日志或只读数据库可以查明。评审者必须
53
+ 继续调查,未查完不得退出评审,也不得转问用户。
54
+ - `OWNER_DECISION`:存在两个以上成立方案,需要产品或业务 owner 取舍。返回
55
+ `superflow-clarify`,一次只问一个问题。
56
+ - `EXTERNAL_CONTRACT`:第三方请求/响应、签名、幂等、枚举、回调或跨服务责任合同。
57
+ 只要会改变 API、SQL、状态机、安全实现或测试断言,就属于实现阻塞项,必须取得
58
+ 合同证据后才能 PASS;“已在文档标记 Blocked”不算关闭。
59
+ - `EXECUTION_EVIDENCE`:已经冻结实现合同,仅等待部署、真实调用、迁移或运行证据。
60
+ 可以留在 tests/test-report 阻塞交付,但不得伪装成合同未知项。
61
+
62
+ ### 3. 六向反查
63
+
64
+ 逐项从结果反推前提,不能只沿设计正向复述:
65
+
66
+ 1. **业务闭环**:输入、触发、前置条件、处理、输出、异常、恢复、取消/重复动作。
67
+ 2. **源码事实**:真实入口、全部写入方、读取/过滤方、遗留能力、跨仓消费者、DB样本。
68
+ 3. **合同一致性**:PRD/截图、UI、API、DTO/VO、DB、状态枚举、SQL、tests 和 tasks。
69
+ 4. **失败与边界**:越权、并发、幂等、超时、不确定结果、乱序回调、部分失败、脏数据。
70
+ 5. **复杂度减法**:重复字段、平行接口、无必要 Service、缓存/MQ/定时任务、推测性兼容。
71
+ 6. **可交付性**:每条需求是否有实现任务、RED/GREEN、真实入口、DB/log证据和验收口径。
72
+
73
+ 涉及数据库时必须使用 `superflow-table-impact-analysis`,或在不可用时按同等规则降级
74
+ 执行并记录原因。
75
+
76
+ ### 4. 记录发现
77
+
78
+ 创建或更新当前 change 的 `requirement-review.md`:
79
+
80
+ ```markdown
81
+ ---
82
+ change: <change-name>
83
+ review_verdict: BLOCKED
84
+ implementation_readiness: BLOCKED
85
+ open_blockers: <number>
86
+ open_external_contracts: <number>
87
+ open_source_investigations: <number>
88
+ open_owner_decisions: <number>
89
+ ---
90
+
91
+ # 需求反向评审
92
+
93
+ ## 评审基线
94
+ - change:
95
+ - phase:
96
+ - 功能范围:
97
+ - 来源与证据:
98
+ - handoff hash:
99
+
100
+ ## 闭环矩阵
101
+ | 功能点 | 输入/触发 | 处理 | 输出 | 异常 | 恢复/重复 | 证据 | 结论 |
102
+ |---|---|---|---|---|---|---|---|
103
+
104
+ ## 评审发现
105
+ | ID | 等级 | 维度 | 位置 | 问题 | 证据 | 影响 | 最小修正 | 状态 |
106
+ |---|---|---|---|---|---|---|---|---|
107
+
108
+ ## 未关闭阻塞项
109
+ | ID | 分类 | 影响的实现合同 | 解决责任 | 下一证据/问题 | 状态 |
110
+ |---|---|---|---|---|---|
111
+
112
+ ## 过度设计与欠设计
113
+ | 设计项 | 现有复用 | 必要性 | 删除/保留结论 | 证据 |
114
+ |---|---|---|---|---|
115
+
116
+ ## 复审结论
117
+ - BLOCKED / PASS
118
+ - 未关闭发现:
119
+ - 已修正文档:
120
+ - 仍需 owner 决策:
121
+ ```
122
+
123
+ 等级只能使用:
124
+
125
+ - `BLOCKER`:需求事实、API/DB/状态、安全、真实入口或验收合同错误,阻塞推进。
126
+ - `IMPORTANT`:高概率造成遗漏、返工或不可测,必须在 docs 阶段修正。
127
+ - `SUGGESTION`:不影响合同正确性的改进建议,可由 owner 决定。
128
+
129
+ ### 5. 整改
130
+
131
+ 每个成立的 `BLOCKER/IMPORTANT` 必须:
132
+
133
+ 1. 修正原始 canonical 文档,而不是只修改 `requirement-review.md`。
134
+ 2. 同步 API、design、spec、SQL、tasks、tests、traceability 和 quality gate 中受影响项。
135
+ 3. 记录“问题 → 修正文件 → 测试/证据”的闭环。
136
+ 4. 若修正改变 owner 已确认合同,停止并回到 `superflow-clarify`。
137
+
138
+ ### 6. 独立复审
139
+
140
+ 整改后重新从需求来源和源码证据检查,不以“文档已经修改”为通过依据。
141
+
142
+ 通过条件:
143
+
144
+ - 所有 `BLOCKER/IMPORTANT` 已关闭并有文件与测试证据。
145
+ - 没有未解释的 UI/API/DB/SQL/status/tests 漂移。
146
+ - 复杂度减法结论成立,没有无证据的新抽象。
147
+ - `SOURCE_INVESTIGATION` 已穷尽并回写证据,数量为0。
148
+ - owner 决策均已记录,`OWNER_DECISION` 数量为0。
149
+ - 会改变实现的 `EXTERNAL_CONTRACT` 已取得证据并冻结,数量为0;仅写成
150
+ `Blocked`、分配 owner 或列入任务不算关闭。
151
+ - 剩余项只能是不会改变实现合同的 `EXECUTION_EVIDENCE`,并已进入测试/发布门禁。
152
+ - `requirement-review.md` 结论为 `PASS`。
153
+ - front matter 精确记录 `review_verdict: PASS`、`implementation_readiness: READY`、
154
+ `open_blockers: 0`、`open_external_contracts: 0`、
155
+ `open_source_investigations: 0` 和 `open_owner_decisions: 0`。
156
+
157
+ ### 7. 刷新门禁
158
+
159
+ 文档修正后刷新 handoff,并运行 docs guard 与 OpenSpec strict validate。将
160
+ `requirement-review.md` 路径、复审结论和未关闭项同步到 `sdd-quality-gate.md` 与
161
+ `test-report.md`。
162
+
163
+ ## 禁止项
164
+
165
+ - 禁止只按文档文字评审而不核源码和真实入口。
166
+ - 禁止把数据模型可表达能力当成当前产品行为。
167
+ - 禁止用“字段非空、接口200、编译通过”替代业务语义正确。
168
+ - 禁止为了覆盖边界而虚构默认值、fallback、状态或兼容层。
169
+ - 禁止把评审结果落到其他流程目录,导致 OpenSpec change 无法追踪。
170
+ - 禁止未关闭阻塞问题却将 docs/design 标为通过。
171
+ - 禁止以“文档已记录”“已有 owner”“待联调”关闭会改变实现的外部合同。
172
+ - 禁止 `review_verdict: PASS` 与 `implementation_readiness: BLOCKED` 并存。
173
+
174
+ ## Handoff
175
+
176
+ 评审通过后继续当前 Superflow 阶段;若发现 owner 决策缺失,返回
177
+ `superflow-clarify`;若发现文档合同缺失,返回 `superflow-docs` 并在修正后再次执行
178
+ 本 skill。
@@ -0,0 +1,4 @@
1
+ interface:
2
+ display_name: "Superflow 需求反向评审"
3
+ short_description: "基于源码反查需求与设计缺口并推动整改复审闭环"
4
+ default_prompt: "使用 $superflow-requirement-review 对当前 OpenSpec 需求和设计执行反向评审并闭环整改。"
@@ -23,6 +23,21 @@ any full SDD document or implementation prompt is generated.
23
23
  - Do not freeze a feature from product text or understand-anything output alone
24
24
  when code impact is relevant. Current source, Mapper/XML, database samples,
25
25
  API contracts, or real consumer entry points must confirm the design.
26
+ - For features that depend on existing behavior, table relationships, or call
27
+ chains, create a `source-code-audit.md` Source Fact Freeze Card before
28
+ freezing: `Business conclusion | understand-anything locator | Data model |
29
+ All writers | Real user entry | Current callers | Legacy conflict | DB check
30
+ required | Conclusion level | owner decision`. Treat understand-anything only
31
+ as a locator and confirm every conclusion in source, Mapper/SQL, current
32
+ callers, or read-only DB evidence.
33
+ - Classify evidence as `current`, `legacy`, `unmounted`, `data-model-only`,
34
+ `owner-confirmed`, or `blocked`. If `List`, `orderIds`, `batchInsert`, or a
35
+ one-to-many relation exists while the real UI/mini-program/H5 submits one
36
+ item, add a Conflict Audit and do not infer current batch behavior.
37
+ - Before asking the user, record a Question Eligibility Gate covering source,
38
+ Mapper/SQL, frontend/mini-program/H5 callers, sibling repositories, and the
39
+ DB check or skip reason. Do not ask the user for facts discoverable from the
40
+ repository or read-only data; ask only for owner-intent decisions.
26
41
  - When the feature depends on existing code relationships, field ownership,
27
42
  table joins, data permissions, status transitions, or upstream/downstream
28
43
  calls, verify the relationship before freezing with current evidence:
@@ -81,6 +96,8 @@ Create or update these files in the active OpenSpec change directory:
81
96
  - `ui-contract.md`: page fields, controls, buttons, list columns, dropdowns, API/DTO/DB mapping.
82
97
  - `gap-analysis.md`: UI/document/source gaps and over-design risks.
83
98
  - `spec-freeze-review.md`: freeze card for the current feature.
99
+ - `source-code-audit.md`: source fact freeze card, evidence classifications,
100
+ conflict audit, and question eligibility gate.
84
101
  - Platform impact evidence in one of the above documents: discovery method,
85
102
  understand-anything index status when available, analyzed platform scope,
86
103
  impacted modules/interfaces/tables, regression risks, source/DB/API
@@ -21,6 +21,12 @@ Superpowers own source-level HOW without weakening OpenSpec/SDD contracts.
21
21
 
22
22
  ## Preconditions
23
23
 
24
+ - When the change modifies a database schema, index, constraint, seed data, or
25
+ historical data, `release-sql.md` must already contain the complete executable
26
+ release SQL, an exact target `.sql` path, `copy_policy: verbatim`, and a valid
27
+ `sql_sha256`. Source-level HOW design must not defer SQL design to an
28
+ implementation prompt.
29
+
24
30
  - `proposal.md`, `api.md`, `design.md`, `tasks.md`, `tests.md`,
25
31
  `traceability-matrix.md`, `sdd-quality-gate.md`, and `test-report.md` exist.
26
32
  - `.sdd/state.yaml` exists and is in `phase: design`. If still `docs`, run:
@@ -38,15 +44,21 @@ Superpowers own source-level HOW without weakening OpenSpec/SDD contracts.
38
44
 
39
45
  1. Read `.sdd/handoff/sdd-context.md` plus original `api.md`, `design.md`,
40
46
  `tasks.md`, and `tests.md`.
41
- 2. If design discussion is still evolving, maintain
47
+ 2. For a database change, verify `release-sql.md` before source-level HOW
48
+ design: one complete executable SQL block, exact destination, normalized
49
+ SHA-256, pre/post checks, and explicit verbatim-copy references in
50
+ `design.md`, `tasks.md`, and `sdd-quality-gate.md`. Any unresolved type,
51
+ default, index, migration rule, or target path returns to
52
+ `$superflow-docs`; it must not be deferred to `$superflow-implement`.
53
+ 3. If design discussion is still evolving, maintain
42
54
  `.sdd/handoff/brainstorm-summary.md` with confirmed, candidate, pending, and
43
55
  rejected items. Do not create final technical design from memory only.
44
- 3. Use Superpowers `brainstorming` or equivalent deep design reasoning to
56
+ 4. Use Superpowers `brainstorming` or equivalent deep design reasoning to
45
57
  decide source-level HOW.
46
- 4. Write:
58
+ 5. Write:
47
59
  `docs/superpowers/specs/YYYY-MM-DD-<change-id>-technical-design.md`
48
60
  using `../superflow-pipeline/references/superpower-technical-design-template.md`.
49
- 5. Complete `Minimal Design Review` before expanding source-level HOW. For
61
+ 6. Complete `Minimal Design Review` before expanding source-level HOW. For
50
62
  every new table, field, API, service/component, abstraction, cache,
51
63
  async/MQ/event flow, scheduled job, or compatibility layer, prove existing
52
64
  reuse options, necessity, and why the simplest direct implementation is
@@ -56,7 +68,7 @@ Superpowers own source-level HOW without weakening OpenSpec/SDD contracts.
56
68
  premature caches, and async compensation without measured need. Record
57
69
  retained and removed counts; unresolved simpler alternatives keep the
58
70
  design blocked.
59
- 6. For cross-repository, service-to-service, SDK, MQ, scheduler, device,
71
+ 7. For cross-repository, service-to-service, SDK, MQ, scheduler, device,
60
72
  callback, third-party, mini-program, gateway, or adapter changes, include
61
73
  `Architecture Boundary And Call Direction`. Prove owner module, call
62
74
  direction, existing entry/exit points, proposed entry/exit points, evidence
@@ -64,7 +76,7 @@ Superpowers own source-level HOW without weakening OpenSpec/SDD contracts.
64
76
  adapter/protocol translator/device gateway into a business-entry
65
77
  orchestrator, stop and return to `$superflow-docs` unless the OpenSpec/SDD
66
78
  contract explicitly grants that ownership with approval evidence.
67
- 7. For third-party platforms/tools, SDKs, MQ/Kafka, callbacks, payment
79
+ 8. For third-party platforms/tools, SDKs, MQ/Kafka, callbacks, payment
68
80
  gateways, cloud services, or other external integrations, include
69
81
  `External Integration Configuration And Deployment Contract`. Inventory
70
82
  every endpoint, app/tenant/project ID, Topic, Tag, Consumer Group,
@@ -76,7 +88,7 @@ Superpowers own source-level HOW without weakening OpenSpec/SDD contracts.
76
88
  auto-creation or pre-existing resources must not be treated as proof that
77
89
  production will provision them. Missing production provisioning evidence
78
90
  blocks design completion.
79
- 8. For concurrent requests, batch issue/activation/renewal, duplicate callbacks,
91
+ 9. For concurrent requests, batch issue/activation/renewal, duplicate callbacks,
80
92
  duplicate consumption, or repeated external delivery, include
81
93
  `Concurrency And Idempotency Ownership`. Use a stable business idempotency
82
94
  key and an application-layer atomic claim in a short transaction; persist
@@ -86,10 +98,17 @@ Superpowers own source-level HOW without weakening OpenSpec/SDD contracts.
86
98
  optional fallback with proven natural uniqueness, historical cleanup,
87
99
  NULL/soft-delete semantics, and a conflict contract. Check-then-insert,
88
100
  process-local locks, and random IDs alone are blocked.
89
- 9. For field/status/enum/sync changes, include `Field And Status Reverse
101
+ When the selected design is version-based optimistic locking, record the
102
+ exact database atomic compare-and-set statement and affected-row decision:
103
+ the update predicate contains both the stable row identity and expected
104
+ version; a zero-row result distinguishes missing data from version conflict.
105
+ The TDD plan references the `tests.md` concurrent stale-version case proving
106
+ one winner, one conflict, and one increment. Do not defer this decision to
107
+ the managed Executor prompt.
108
+ 10. For field/status/enum/sync changes, include `Field And Status Reverse
90
109
  Impact` and prove writers, readers, filters, derived sync paths, consumers,
91
110
  and tests. Direct setter-only design is blocked.
92
- 10. For amount, fee, discount, deduction, refund, sharing, payment, invoice,
111
+ 11. For amount, fee, discount, deduction, refund, sharing, payment, invoice,
93
112
  balance, electricity fee, service fee, package settlement, proration,
94
113
  allocation, reconciliation, or financial display changes,
95
114
  include `Money Precision Boundary`. Prove calculation-state fields,
@@ -108,12 +127,12 @@ Superpowers own source-level HOW without weakening OpenSpec/SDD contracts.
108
127
  level and policy source, deterministic residual strategy with stable
109
128
  tie-breaker, and positive/zero/negative evidence. For FX changes, freeze the
110
129
  directional rate metadata and one canonical conversion path.
111
- 11. Record state:
130
+ 12. Record state:
112
131
  ```bash
113
132
  ../superflow-pipeline/scripts/superflow-state.sh set <change-dir> technical_design docs/superpowers/specs/YYYY-MM-DD-<change-id>-technical-design.md
114
133
  ../superflow-pipeline/scripts/superflow-state.sh set <change-dir> design_doc design.md
115
134
  ```
116
- 12. Update `design.md` with `Superpowers Technical Design Handoff`, update
135
+ 13. Update `design.md` with `Superpowers Technical Design Handoff`, update
117
136
  `sdd-quality-gate.md` with the technical design path and hash, then run
118
137
  `../superflow-pipeline/scripts/superflow-handoff.sh <change-dir> --refresh`.
119
138
  If the guard reports a stale or missing hash, record the printed hash in
@@ -121,7 +140,7 @@ Superpowers own source-level HOW without weakening OpenSpec/SDD contracts.
121
140
  `--refresh` again. Do not set `design_doc` to the Superpowers document;
122
141
  `design_doc` is the OpenSpec/SDD contract design, while `technical_design`
123
142
  is the Superpowers HOW document.
124
- 13. Run:
143
+ 14. Run:
125
144
  ```bash
126
145
  ../superflow-pipeline/scripts/superflow-yaml-validate.sh <change-dir>
127
146
  ../superflow-pipeline/scripts/superflow-guard.sh <change-dir> design --apply