@chenmk/superflow 0.2.4 → 0.3.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 (61) hide show
  1. package/README.md +4 -1
  2. package/README.zh-CN.md +1 -0
  3. package/assets/manifest.json +3 -1
  4. package/assets/prompts/superflow-clarify.md +6 -0
  5. package/assets/prompts/superflow-pipeline.md +8 -0
  6. package/assets/scripts/superflow-archive-command-hook.sh +80 -0
  7. package/assets/scripts/superflow-delivery-check.sh +23 -4
  8. package/assets/skills/superflow-archive/SKILL.md +5 -0
  9. package/assets/skills/superflow-clarify/SKILL.md +26 -7
  10. package/assets/skills/superflow-design/SKILL.md +46 -5
  11. package/assets/skills/superflow-docs/SKILL.md +27 -0
  12. package/assets/skills/superflow-implement/SKILL.md +17 -0
  13. package/assets/skills/superflow-pipeline/SKILL.md +47 -0
  14. package/assets/skills/superflow-pipeline/references/api-design-template.md +11 -0
  15. package/assets/skills/superflow-pipeline/references/batch-prompt-template.md +44 -0
  16. package/assets/skills/superflow-pipeline/references/implementation-prompt-template.md +48 -0
  17. package/assets/skills/superflow-pipeline/references/money-precision-algorithms.md +85 -0
  18. package/assets/skills/superflow-pipeline/references/quality-gate.md +3 -0
  19. package/assets/skills/superflow-pipeline/references/reviewer-checklist.md +17 -1
  20. package/assets/skills/superflow-pipeline/references/superpower-technical-design-template.md +90 -0
  21. package/assets/skills/superflow-pipeline/references/test-execution-template.md +26 -0
  22. package/assets/skills/superflow-pipeline/scripts/superflow-guard.sh +231 -0
  23. package/assets/skills/superflow-verify/SKILL.md +23 -1
  24. package/assets/skills-en/superflow-archive/SKILL.md +6 -0
  25. package/assets/skills-en/superflow-clarify/SKILL.md +26 -7
  26. package/assets/skills-en/superflow-design/SKILL.md +45 -4
  27. package/assets/skills-en/superflow-docs/SKILL.md +27 -0
  28. package/assets/skills-en/superflow-implement/SKILL.md +10 -0
  29. package/assets/skills-en/superflow-pipeline/SKILL.md +38 -0
  30. package/assets/skills-en/superflow-pipeline/references/api-design-template.md +13 -0
  31. package/assets/skills-en/superflow-pipeline/references/batch-prompt-template.md +28 -0
  32. package/assets/skills-en/superflow-pipeline/references/implementation-prompt-template.md +33 -0
  33. package/assets/skills-en/superflow-pipeline/references/money-precision-algorithms.md +96 -0
  34. package/assets/skills-en/superflow-pipeline/references/quality-gate.md +26 -0
  35. package/assets/skills-en/superflow-pipeline/references/reviewer-checklist.md +15 -0
  36. package/assets/skills-en/superflow-pipeline/references/superpower-technical-design-template.md +95 -0
  37. package/assets/skills-en/superflow-pipeline/references/test-execution-template.md +30 -0
  38. package/assets/skills-en/superflow-pipeline/scripts/superflow-guard.sh +231 -0
  39. package/assets/skills-en/superflow-verify/SKILL.md +24 -1
  40. package/dist/app/commands/archive.js +7 -3
  41. package/dist/app/commands/archive.js.map +1 -1
  42. package/dist/app/commands/change-guard.js +27 -0
  43. package/dist/app/commands/change-guard.js.map +1 -0
  44. package/dist/app/commands/design.js +2 -20
  45. package/dist/app/commands/design.js.map +1 -1
  46. package/dist/app/commands/init.js +1 -5
  47. package/dist/app/commands/init.js.map +1 -1
  48. package/dist/app/commands/update.js +2 -5
  49. package/dist/app/commands/update.js.map +1 -1
  50. package/dist/app/commands/verify.js +7 -3
  51. package/dist/app/commands/verify.js.map +1 -1
  52. package/dist/domains/config/context.js +1 -5
  53. package/dist/domains/config/context.js.map +1 -1
  54. package/dist/domains/deps.js +1 -5
  55. package/dist/domains/deps.js.map +1 -1
  56. package/dist/domains/hook.js +1 -0
  57. package/dist/domains/hook.js.map +1 -1
  58. package/dist/platform/assets.js +9 -0
  59. package/dist/platform/assets.js.map +1 -0
  60. package/package.json +3 -2
  61. package/scripts/release-notes-check.js +102 -0
package/README.md CHANGED
@@ -206,7 +206,10 @@ hook registration is not enabled for OpenCode yet; use `/superflow-*` commands
206
206
  to run workflow gates explicitly.
207
207
 
208
208
  For large requirements, ask the agent to read one section or one feature at a
209
- time. SuperBridge Flow will route through clarification, OpenSpec docs,
209
+ time. The total router automatically uses embedded deep clarification when a
210
+ feature needs an owner decision; it investigates available facts first and asks
211
+ one decision at a time with a recommendation. Clear, bounded work continues
212
+ without an interview. SuperBridge Flow then routes through OpenSpec docs,
210
213
  Superpowers technical design, implementation prompts, verification, and archive.
211
214
 
212
215
  ## Automatic Update Checks
package/README.zh-CN.md CHANGED
@@ -121,6 +121,7 @@ superflow init
121
121
  - Superpowers 负责 HOW:源码级技术详设、TDD/RED 顺序、团队分工、worktree/端口并行、review/tester 编排和验证闭环。
122
122
  - 完整流程是 `docs -> design -> implement -> verify -> archive`。Superpowers 技术详设落到 `docs/superpowers/specs/*-technical-design.md`,并记录到 `.sdd/state.yaml` 的 `technical_design`,避免长会话压缩后漂移。
123
123
  - Codex 侧通常用自然语言或 `$superflow-pipeline` 触发;Claude Code 侧可以直接用 `/superflow-pipeline`、`/superflow-docs`、`/superflow-design` 等 slash command。
124
+ - 只说一句话触发总路由时,遇到需要业务负责人选择的关键分歧,SuperFlow 会在 clarify 阶段自动进入深度澄清:先查代码和已有资料能确认的事实,再一次只问一个决策问题,并给出推荐方案与影响。明确、范围小的改动不会被强行拉进问答流程。
124
125
  - 飞书、语雀等在线文档读取工具不内置在 SuperBridge Flow CLI 中;可自行用 `lark-cli` 等外部工具读取,再通过 `/superflow-pipeline` 或 `$superflow-pipeline` 分段分析指定小节。
125
126
 
126
127
  ## 命令
@@ -29,6 +29,7 @@
29
29
  "superflow-hook-guard.sh",
30
30
  "superflow-dependency-update-hook.sh",
31
31
  "superflow-integration-evidence-hook.sh",
32
+ "superflow-archive-command-hook.sh",
32
33
  "superflow-test-report-lint.py",
33
34
  "install-sql-pre-commit.sh",
34
35
  "sync-settings-json.py"
@@ -45,7 +46,8 @@
45
46
  "superflow-dependency-update-hook.sh",
46
47
  "superflow-sql-sync-hook.py",
47
48
  "superflow-delivery-check.sh",
48
- "superflow-integration-evidence-hook.sh"
49
+ "superflow-integration-evidence-hook.sh",
50
+ "superflow-archive-command-hook.sh"
49
51
  ],
50
52
  "agentHooks": {
51
53
  "claude": ["claude-auto-backup-hook.sh"],
@@ -8,3 +8,9 @@ Use the `superflow-clarify` skill for this request.
8
8
  Read the requested source in bounded sections, freeze one feature or section at
9
9
  a time, and stop for missing product/API/DB facts before OpenSpec artifacts are
10
10
  created.
11
+
12
+ If the total router selected embedded deep clarification, establish facts from
13
+ the repository and supplied sources before asking. Ask one unresolved owner
14
+ decision at a time, include a recommended answer and consequence, wait for the
15
+ response, and record the result in the existing brainstorm handoff before moving
16
+ on. Do not turn clear, bounded work into an interview.
@@ -9,5 +9,13 @@ Route the work through the correct SuperBridge Flow phase. OpenSpec owns WHAT
9
9
  and contracts; Superpowers owns source-level HOW. Preserve handoff state and run
10
10
  the required SuperBridge Flow guards before phase transitions.
11
11
 
12
+ When the request has unresolved decisions that need owner intent, competing
13
+ approaches, unclear source of truth, unclear acceptance behavior, or cross-system
14
+ responsibility, enter the embedded deep-clarification mode of
15
+ `superflow-clarify`. Investigate repository-verifiable facts first, then ask one
16
+ decision question at a time with a recommended answer and consequence. Keep the
17
+ decision record in the existing brainstorm handoff. Do not require the user to
18
+ invoke another command, and do not use this mode for a clear bounded change.
19
+
12
20
  Input: treat the argument after `/superflow-pipeline` as the requirement,
13
21
  document path, or change description.
@@ -0,0 +1,80 @@
1
+ #!/bin/bash
2
+ # Blocks direct OpenSpec/Superflow archive commands that bypass lifecycle gates.
3
+
4
+ set -u
5
+
6
+ INPUT=$(cat)
7
+
8
+ read_json_field() {
9
+ local field="$1"
10
+ printf '%s' "$INPUT" | python3 -c "
11
+ import json, sys
12
+ try:
13
+ data = json.load(sys.stdin)
14
+ except Exception:
15
+ print('')
16
+ raise SystemExit
17
+ tool_input = data.get('tool_input', {})
18
+ print(tool_input.get('$field') or tool_input.get('cmd') or '')
19
+ " 2>/dev/null
20
+ }
21
+
22
+ COMMAND=$(read_json_field command)
23
+ [ -n "$COMMAND" ] || exit 0
24
+
25
+ CHANGE=$(printf '%s' "$COMMAND" | python3 -c '
26
+ import shlex, sys
27
+
28
+ try:
29
+ tokens = shlex.split(sys.stdin.read())
30
+ except ValueError:
31
+ raise SystemExit
32
+
33
+ for index in range(len(tokens) - 1):
34
+ binary = tokens[index].rsplit("/", 1)[-1]
35
+ if binary not in {"openspec", "superflow"} or tokens[index + 1] != "archive":
36
+ continue
37
+ skip_value = False
38
+ for token in tokens[index + 2:]:
39
+ if skip_value:
40
+ skip_value = False
41
+ continue
42
+ if token in {"--store", "--agent"}:
43
+ skip_value = True
44
+ continue
45
+ if token.startswith("-"):
46
+ continue
47
+ print(token)
48
+ raise SystemExit
49
+ ' 2>/dev/null)
50
+
51
+ [ -n "$CHANGE" ] || exit 0
52
+
53
+ CWD=$(read_json_field cwd)
54
+ [ -n "$CWD" ] || CWD=$(pwd)
55
+ REPO_ROOT=$(git -C "$CWD" rev-parse --show-toplevel 2>/dev/null) || exit 0
56
+
57
+ if [ -d "$CWD/$CHANGE" ]; then
58
+ CHANGE_DIR="$CWD/$CHANGE"
59
+ else
60
+ CHANGE_DIR="$REPO_ROOT/openspec/changes/$CHANGE"
61
+ fi
62
+
63
+ [ -d "$CHANGE_DIR" ] || exit 0
64
+
65
+ ARCHIVE_SCRIPT=${SUPERFLOW_ARCHIVE_SCRIPT:-$HOME/.codex/skills/superflow-pipeline/scripts/superflow-archive.sh}
66
+ if [ ! -x "$ARCHIVE_SCRIPT" ]; then
67
+ echo "[Superflow 归档门禁] 归档脚本不存在或不可执行:$ARCHIVE_SCRIPT" >&2
68
+ exit 2
69
+ fi
70
+
71
+ if ! "$ARCHIVE_SCRIPT" "$CHANGE_DIR" --dry-run; then
72
+ cat <<'BLOCK_MSG' >&2
73
+ [Superflow 归档门禁] 归档门禁未通过,已阻止直接归档。
74
+ 请先完成 tasks、test-report、测试环境证据、verify 状态和归档确认;
75
+ 不要用 openspec archive 绕过 Superflow 生命周期。
76
+ BLOCK_MSG
77
+ exit 2
78
+ fi
79
+
80
+ exit 0
@@ -52,27 +52,46 @@ if [ -z "$CHANGED" ]; then
52
52
  exit 0
53
53
  fi
54
54
 
55
+ ACTIVE_SDD_CHANGED=$(printf '%s\n' "$CHANGED" | grep -Ev \
56
+ '(^|/)(doc/)?openspec/changes/archive/' || true)
57
+
55
58
  SDD_ACTIVE=0
56
59
  if [ -f "$REPO_ROOT/.sdd-enforced" ]; then
57
60
  SDD_ACTIVE=1
58
61
  fi
59
62
 
63
+ if [ "$SDD_ACTIVE" -eq 0 ]; then
64
+ ACTIVE_STATE=$(find "$REPO_ROOT/openspec/changes" \
65
+ -path '*/archive/*' -prune -o \
66
+ -path '*/.sdd/state.yaml' -type f -print 2>/dev/null \
67
+ | while IFS= read -r state; do
68
+ phase=$(awk -F':' '$1=="phase"{gsub(/^[ \t]+|[ \t]+$/, "", $2); print $2}' "$state")
69
+ archived=$(awk -F':' '$1=="archived"{gsub(/^[ \t]+|[ \t]+$/, "", $2); print $2}' "$state")
70
+ if [ "$archived" != "true" ] && { [ "$phase" = "implement" ] || [ "$phase" = "verify" ]; }; then
71
+ printf '%s\n' "$state"
72
+ fi
73
+ done | head -n 1)
74
+ if [ -n "$ACTIVE_STATE" ]; then
75
+ SDD_ACTIVE=1
76
+ fi
77
+ fi
78
+
60
79
  RUNTIME_CHANGED=$(printf '%s\n' "$CHANGED" | grep -E \
61
80
  '(^|/)src/main/.*\.(java|xml|yml|yaml|properties)$|(^|/)mapper/.*\.xml$|(^|/)sql/.*\.sql$' || true)
62
81
 
63
82
  CODE_RUNTIME_CHANGED=$(printf '%s\n' "$CHANGED" | grep -E \
64
83
  '(^|/)src/main/.*\.(java|xml|yml|yaml|properties)$|(^|/)mapper/.*\.xml$' || true)
65
84
 
66
- P_DIRS=$(printf '%s\n' "$CHANGED" | sed -nE \
85
+ P_DIRS=$(printf '%s\n' "$ACTIVE_SDD_CHANGED" | sed -nE \
67
86
  's#^(.*embedded-changes/(p[0-9]+[^/]*))/.*$#\1#p' | sort -u)
68
87
 
69
- REPORTS=$(printf '%s\n' "$CHANGED" | grep -E \
88
+ REPORTS=$(printf '%s\n' "$ACTIVE_SDD_CHANGED" | grep -E \
70
89
  '(^|/)embedded-changes/p[0-9][^/]*/test-report\.md$|(^|/)test-report\.md$' || true)
71
90
 
72
- AGGREGATE_DOCS=$(printf '%s\n' "$CHANGED" | grep -E \
91
+ AGGREGATE_DOCS=$(printf '%s\n' "$ACTIVE_SDD_CHANGED" | grep -E \
73
92
  '(^|/)openspec/changes/[^/]+/(tasks|test-report|traceability-matrix|sdd-quality-gate|tests)\.md$|(^|/)doc/openspec/changes/[^/]+/(tasks|test-report|traceability-matrix|sdd-quality-gate|tests)\.md$' || true)
74
93
 
75
- SDD_DOCS_CHANGED=$(printf '%s\n' "$CHANGED" | grep -E \
94
+ SDD_DOCS_CHANGED=$(printf '%s\n' "$ACTIVE_SDD_CHANGED" | grep -E \
76
95
  '(^|/)(doc/)?openspec/changes/|(^|/)embedded-changes/p[0-9]' || true)
77
96
 
78
97
  AGGREGATE_ALLOWED=0
@@ -14,6 +14,9 @@ do not mark archived until the user confirms final closeout.
14
14
  - `phase: archive`.
15
15
  - `verify_result: pass`.
16
16
  - `verification_report` points to an existing report.
17
+ - Every checkbox in `tasks.md` is checked.
18
+ - The verification report contains `验证结果: PASS` and `归档就绪: PASS`.
19
+ - `branch_status: handled` and `verified_at` are recorded.
17
20
  - `superflow-state.sh recover <change-dir>` gives a coherent archive recovery action.
18
21
 
19
22
  ## Procedure
@@ -42,6 +45,8 @@ do not mark archived until the user confirms final closeout.
42
45
  the user explicitly accepts the boundary.
43
46
  - Do not use archive to hide missing API, DB, hook, SQL, test-report, or real
44
47
  integration evidence.
48
+ - Never call `openspec archive` directly to bypass the lifecycle gate. The
49
+ installed archive-command hook blocks that path when native hooks are active.
45
50
  - In a standard `openspec/changes/<name>` layout, archive must use OpenSpec
46
51
  archive semantics so delta specs are merged and the change is moved to
47
52
  `openspec/changes/archive/`. State-only archive is only a fallback for
@@ -50,6 +50,15 @@ any full SDD document or implementation prompt is generated.
50
50
  external input. If semantics are unclear, mark the feature blocked instead of
51
51
  inventing a fallback.
52
52
  - Process one feature at a time, in product-document order.
53
+ - When the pipeline selected embedded deep-clarification mode, investigate facts
54
+ from the repository, source documents, configuration, tests, logs, and tools
55
+ before asking. Ask the user only about an unresolved decision that needs owner
56
+ intent; do not ask for facts that can be found locally.
57
+ - In embedded deep-clarification mode, ask exactly one decision question at a
58
+ time. Include the recommended answer and its important consequence, wait for
59
+ the answer, then record the result before asking the next question. Do not
60
+ create SDD artifacts or implementation prompts while a current-feature
61
+ decision remains pending.
53
62
  - For long PRDs, Lark/Feishu exports, screenshots, or mixed product docs, do
54
63
  not read the whole document and generate all tasks in one pass. First create
55
64
  a source index, then process one bounded section or feature at a time. Each
@@ -85,6 +94,10 @@ Create or update these files in the active OpenSpec change directory:
85
94
  - Business semantic evidence when status/enum/sync/default behavior is involved:
86
95
  source-of-truth field, enum mapping, consumer interpretation, business basis,
87
96
  explicitly rejected fallback/default choices, and unresolved owner questions.
97
+ - Deep-clarification decision evidence when this mode is active: each question,
98
+ recommendation, user decision, consequence, and the resulting
99
+ `confirmed`/`candidate`/`pending`/`rejected` entry in
100
+ `.sdd/handoff/brainstorm-summary.md`.
88
101
 
89
102
  Use the detailed workflow in:
90
103
 
@@ -127,14 +140,20 @@ Use the detailed workflow in:
127
140
  If a proposed default, fallback, old-value retention, or null conversion is
128
141
  not explicitly approved by the requirement or owner, mark it rejected and do
129
142
  not include it in the design.
130
- 11. Ask only current-feature clarification questions.
131
- 12. Wait for programmer confirmation.
132
- 13. Draft a rough API contract: path, action, core request, core response. Field types can be approximate.
133
- 14. Wait for programmer confirmation of the rough API.
134
- 15. Produce a precise API section with field names, types, requiredness, defaults, enums, errors, examples, and curl.
135
- 16. Mark the feature as `已冻结` only when understanding, rough API, precise API,
143
+ 11. If embedded deep-clarification mode is active, resolve one decision at a
144
+ time. For each question, state the recommended answer and consequence, wait
145
+ for the programmer response, then update
146
+ `.sdd/handoff/brainstorm-summary.md` under `confirmed`, `candidate`,
147
+ `pending`, or `rejected`. Stop asking once only repository-verifiable facts
148
+ remain.
149
+ 12. Ask only any remaining current-feature clarification questions.
150
+ 13. Wait for programmer confirmation.
151
+ 14. Draft a rough API contract: path, action, core request, core response. Field types can be approximate.
152
+ 15. Wait for programmer confirmation of the rough API.
153
+ 16. Produce a precise API section with field names, types, requiredness, defaults, enums, errors, examples, and curl.
154
+ 17. Mark the feature as `已冻结` only when understanding, rough API, precise API,
136
155
  and validation data needs are confirmed or explicitly blocked.
137
- 17. Only after the current feature is frozen or blocked, move to the next
156
+ 18. Only after the current feature is frozen or blocked, move to the next
138
157
  indexed feature. Do not batch-confirm multiple features from memory or a
139
158
  compressed chat summary.
140
159
 
@@ -54,22 +54,63 @@ Superpowers own source-level HOW without weakening OpenSpec/SDD contracts.
54
54
  adapter/protocol translator/device gateway into a business-entry
55
55
  orchestrator, stop and return to `$superflow-docs` unless the OpenSpec/SDD
56
56
  contract explicitly grants that ownership with approval evidence.
57
- 6. For field/status/enum/sync changes, include `Field And Status Reverse
57
+ 6. For third-party platforms/tools, SDKs, MQ/Kafka, callbacks, payment
58
+ gateways, cloud services, or other external integrations, include
59
+ `External Integration Configuration And Deployment Contract`. Inventory
60
+ every endpoint, app/tenant/project ID, Topic, Tag, Consumer Group,
61
+ namespace, webhook, ACL/role, feature switch, timeout, and credential
62
+ reference. Prove the source and injection/provisioning method for local,
63
+ test, and production environments, plus owner, creation timing, readiness
64
+ check, rollback, and unresolved blockers. Runtime values and server-side
65
+ resources must not exist only as hard-coded annotations/constants. Test
66
+ auto-creation or pre-existing resources must not be treated as proof that
67
+ production will provision them. Missing production provisioning evidence
68
+ blocks design completion.
69
+ 7. For concurrent requests, batch issue/activation/renewal, duplicate callbacks,
70
+ duplicate consumption, or repeated external delivery, include
71
+ `Concurrency And Idempotency Ownership`. Use a stable business idempotency
72
+ key and an application-layer atomic claim in a short transaction; persist
73
+ `PENDING` before the external call, release database locks before calling
74
+ externally, model success/failure/uncertain states, and reuse the original
75
+ business code on retry. A unique index is not the default and may only be an
76
+ optional fallback with proven natural uniqueness, historical cleanup,
77
+ NULL/soft-delete semantics, and a conflict contract. Check-then-insert,
78
+ process-local locks, and random IDs alone are blocked.
79
+ 8. For field/status/enum/sync changes, include `Field And Status Reverse
58
80
  Impact` and prove writers, readers, filters, derived sync paths, consumers,
59
81
  and tests. Direct setter-only design is blocked.
60
- 7. For third-party, SDK, BEM/parking, payment/refund, financial display,
82
+ 9. For third-party, SDK, BEM/parking, payment/refund, financial display,
61
83
  source/origin, status sync, or external dictionary fields, include
62
84
  `External Enum Binding`. Prove local source fields/enums, external fields,
63
85
  external enum values, display/business/financial meaning, source evidence,
64
86
  owner confirmation, unresolved handling, and test evidence. A request
65
87
  succeeding or a field being non-null is not enough; unconfirmed values are
66
88
  blockers and must be returned to `$superflow-docs` or the user.
67
- 8. Record state:
89
+ 10. For amount, fee, discount, deduction, refund, sharing, payment, invoice,
90
+ balance, electricity fee, service fee, package settlement, proration,
91
+ allocation, reconciliation, or financial display changes,
92
+ include `Money Precision Boundary`. Prove calculation-state fields,
93
+ settlement/display-state fields, rounding boundary, scale, rounding mode,
94
+ allocation/reconciliation rule, and tests covering half-cent or residual
95
+ cases. If the design rounds money before later slicing, proration,
96
+ aggregation, discounting, or allocation, stop and redesign the calculation
97
+ boundary. When an additive identity has an authoritative total, the design
98
+ must calculate only N-1 components independently and derive the final
99
+ complement as `authoritative total - sum(other components)`. Independently
100
+ calculating and rounding all components before rebuilding the total is
101
+ blocked. A claimed exception must name the actual source of truth and owner
102
+ evidence. Read
103
+ `../superflow-pipeline/references/money-precision-algorithms.md` and also
104
+ freeze the exact representation, currency/minor-unit boundary, rounding
105
+ level and policy source, deterministic residual strategy with stable
106
+ tie-breaker, and positive/zero/negative evidence. For FX changes, freeze the
107
+ directional rate metadata and one canonical conversion path.
108
+ 11. Record state:
68
109
  ```bash
69
110
  ../superflow-pipeline/scripts/superflow-state.sh set <change-dir> technical_design docs/superpowers/specs/YYYY-MM-DD-<change-id>-technical-design.md
70
111
  ../superflow-pipeline/scripts/superflow-state.sh set <change-dir> design_doc design.md
71
112
  ```
72
- 9. Update `design.md` with `Superpowers Technical Design Handoff`, update
113
+ 12. Update `design.md` with `Superpowers Technical Design Handoff`, update
73
114
  `sdd-quality-gate.md` with the technical design path and hash, then run
74
115
  `../superflow-pipeline/scripts/superflow-handoff.sh <change-dir> --refresh`.
75
116
  If the guard reports a stale or missing hash, record the printed hash in
@@ -77,7 +118,7 @@ Impact` and prove writers, readers, filters, derived sync paths, consumers,
77
118
  `--refresh` again. Do not set `design_doc` to the Superpowers document;
78
119
  `design_doc` is the OpenSpec/SDD contract design, while `technical_design`
79
120
  is the Superpowers HOW document.
80
- 10. Run:
121
+ 13. Run:
81
122
 
82
123
  ```bash
83
124
  ../superflow-pipeline/scripts/superflow-yaml-validate.sh <change-dir>
@@ -76,6 +76,17 @@ For complex requirements, verify these before writing docs:
76
76
  If the docs only prove that a value exists, is non-null, or lets the request
77
77
  succeed, stop and return to `$superflow-clarify`. If fallback/default/keep-old-value
78
78
  behavior is proposed without explicit requirement or owner approval, stop.
79
+ - For third-party platforms/tools, SDKs, MQ/Kafka, callbacks, payment gateways,
80
+ cloud services, or other external integrations, `api.md` and
81
+ `sdd-quality-gate.md` must include `外部集成配置与部署合同` / `External
82
+ Integration Configuration And Deployment Contract`. Inventory endpoints,
83
+ app/tenant/project IDs, Topic/Tag/Consumer Group, namespace, webhook,
84
+ ACL/role, feature switches, timeout, and credential references across local,
85
+ test, and production environments. Record injection/provisioning method,
86
+ runtime owner, provisioning owner/time, readiness evidence, rollback, secret
87
+ handling, and blockers. Environment-dependent values must not be hard-coded;
88
+ test auto-creation or existing test resources do not prove production
89
+ readiness. Missing production provisioning evidence blocks document freeze.
79
90
  - For third-party, SDK, BEM/parking, payment/refund, financial display,
80
91
  source/origin, status sync, or external dictionary/enum fields, `api.md` and
81
92
  `sdd-quality-gate.md` must include `外部枚举绑定确认` / `External Enum
@@ -85,6 +96,17 @@ Binding` with:
85
96
  不确定项/阻塞处理 | 测试证据`. Unconfirmed values are blockers; do not
86
97
  invent numeric values, origin/source values, display meanings, or fallback
87
98
  mappings.
99
+ - For amount, fee, discount, deduction, refund, sharing, payment, invoice,
100
+ balance, electricity/service fee, package settlement, proration, allocation,
101
+ reconciliation, or financial display changes, `sdd-quality-gate.md` must
102
+ declare `Money Precision Boundary` as blocking. `tests.md` and the
103
+ `test-report.md` skeleton must reserve half-cent, residual, or multi-detail
104
+ cases and reconciliation evidence. Do not freeze docs that allow intermediate
105
+ money to be rounded before later slicing, aggregation, discounting, or
106
+ allocation. For additive identities, docs must name the authoritative total,
107
+ independently calculated N-1 components, and the final complement formula:
108
+ `authoritative total - sum(other components)`. Do not allow every component
109
+ to be calculated and rounded independently before rebuilding the total.
88
110
  - For low-freedom implementation handoff, docs include the five hard gates:
89
111
  field semantic contract, write-through persistence closure, real-entry call
90
112
  chain, no-fallback/no-guessing boundary, and pre-coding agent self-check. If
@@ -302,6 +324,11 @@ test-report证据位置`.
302
324
  `RED 失败证据`, `GREEN 通过证据`, `接口自动化证据`, `DB 核查证据`,
303
325
  `日志核查证据`, `未自动化/阻塞用例`, and `Partially verified 边界`.
304
326
  Each section must reference concrete `tests.md` case IDs.
327
+ - For money-related changes, `test-report.md` must also include `Money Precision
328
+ Boundary` evidence: original calculation inputs and precision, actual rounding
329
+ boundary and mode, half-cent/residual/multi-detail cases, and reconciliation
330
+ of original, discount, actual/refund, and allocated totals. Evidence must show
331
+ which total was authoritative and which complement was derived by subtraction.
305
332
  - `sdd-quality-gate.md` must include blocking checks for:
306
333
  executable tests frozen, RED/GREEN expectations present, interface automation
307
334
  commands present, DB/log assertions present, and mock/skipped cases excluded
@@ -111,6 +111,23 @@ Before implementation phase can exit:
111
111
  source, Mapper XML, entities, DTO/VO, SQL, scheduled jobs, MQ/event consumers,
112
112
  callbacks, third-party adapters, shared SDK/tables, and sibling repos when
113
113
  applicable. A prompt that only changes the direct setter/writer is blocked.
114
+ - When a task changes money, fees, discounts, deductions, refunds, sharing,
115
+ payments, invoices, balances, electricity/service fees, package settlement,
116
+ proration, allocation, reconciliation, or financial display, every prompt
117
+ must include "金额精度边界继承". It must copy the technical design
118
+ `Money Precision Boundary`, keep calculation-state precision until the
119
+ confirmed settlement/display boundary, forbid early `setScale(2)` before
120
+ later slicing or aggregation, and require deterministic residual allocation.
121
+ For additive identities with an authoritative total, the prompt must compute
122
+ only N-1 components independently and derive the final complement as
123
+ `authoritative total - sum(other components)`; calculating and rounding all
124
+ components independently is blocked.
125
+ It must inherit `money-precision-algorithms.md`: exact decimal construction,
126
+ currency/provider minor units, rounding level and policy source,
127
+ deterministic residual tie-breaker, pre/post-round audit, signed-value tests,
128
+ and conditional FX metadata.
129
+ RED/GREEN coverage must include half-cent, residual, or multi-detail cases
130
+ and prove reconciliation identities in `test-report.md`.
114
131
  - Every implementation prompt must include a "上下文防漂移与状态继承" section.
115
132
  It must link `.sdd/handoff/sdd-context.md` as a clickable Markdown link,
116
133
  record the exact `handoff_hash`, and require Worker/Tester/Reviewer to read
@@ -11,6 +11,12 @@ This is the lightweight SDD router. Do not load the whole SDD process when a sma
11
11
 
12
12
  - Use `$openspec-explore` when the user is still thinking through a requirement,
13
13
  wants to compare options, or needs codebase investigation before a change.
14
+ - Route to `$superflow-clarify` in embedded deep-clarification mode when the
15
+ user explicitly asks for rigorous questioning, or when a bounded feature has
16
+ unresolved owner decisions, mutually exclusive approaches, unclear source of
17
+ truth, unclear acceptance behavior, or cross-system responsibility. This is
18
+ a mode inside the normal clarify phase, not a separate command the user must
19
+ remember.
14
20
  - Use `$superflow-clarify` only when product inputs are complex and must be frozen one
15
21
  feature at a time before creating OpenSpec artifacts.
16
22
  - Long PRDs, Lark/Feishu exports, screenshot-heavy requirements, and mixed
@@ -49,6 +55,29 @@ This is the lightweight SDD router. Do not load the whole SDD process when a sma
49
55
  SQL change, status field, Mapper/XML query, or cross-repo shared table affects
50
56
  database-backed behavior.
51
57
 
58
+ ## Embedded Deep Clarification
59
+
60
+ When the router selects embedded deep clarification, follow these rules inside
61
+ `$superflow-clarify`:
62
+
63
+ - Do not activate it for a clear, bounded hotfix or tweak whose intended behavior
64
+ and acceptance result are already evidenced. Do not turn routine work into an
65
+ interview.
66
+ - Explore facts that can be established from the requirement, repository,
67
+ configuration, tests, logs, or available tools before asking the user. Ask only
68
+ for a decision the user or owner must make.
69
+ - Ask exactly one decision question at a time. State the recommended option and
70
+ its important consequence, then wait for the answer before the next question.
71
+ - After each answer, update `.sdd/handoff/brainstorm-summary.md` with
72
+ `confirmed`, `candidate`, `pending`, and `rejected` entries. Do not rely on
73
+ chat memory for a resolved decision.
74
+ - Do not create or change proposal, spec, design, tasks, tests, or implementation
75
+ artifacts until all decisions that affect the current feature are confirmed or
76
+ explicitly marked blocked.
77
+ - Exit deep clarification once only repository-verifiable facts remain and the
78
+ user confirms the current feature understanding. Continue through the existing
79
+ clarify workflow without invoking an external skill dependency.
80
+
52
81
  ## Non-Negotiable Rules
53
82
 
54
83
  ### 上下文防漂移与状态门禁(阻塞级)
@@ -402,6 +431,23 @@ SDD 设计、评审、实现 prompt 和测试报告中,字段/状态/枚举/
402
431
  - 兜底让异常数据、缺失字段、旧错误状态静默通过,且没有暴露机制,阻塞。
403
432
  - 无法证明字段值符合业务语义时,必须标记 `Blocked`,不得冻结设计或生成实现 prompt。
404
433
 
434
+ ### 金额精度边界门禁(阻塞级)
435
+
436
+ 凡涉及金额、费用、优惠、抵扣、退款、分账、支付、发票、余额、电费、服务费、
437
+ 套餐结算、比例分摊、明细分配、对账或财务展示,必须从 docs、技术详设、实现
438
+ prompt、代码评审、测试到 verify 继承同一份 `Money Precision Boundary`。
439
+
440
+ - 最终结算/持久化/支付/开票/导出/展示边界前保留计算态原始精度。
441
+ - 禁止提前 `setScale(2)` 后继续切片、分摊、汇总、抵扣或反推单价。
442
+ - 多明细必须用确定性规则处理尾差,分配合计必须等于目标金额。
443
+ - 存在加法恒等式且总额是真源时,只允许独立计算 N-1 个组成项;最后一个组成项
444
+ 必须按 `权威总额 - 其余组成项合计` 差额反推。禁止所有组成项分别计算、分别
445
+ 舍入后再相加重建权威总额。
446
+ - tests.md 和 test-report.md 必须覆盖半分、尾差或多明细场景,并证明原始金额、
447
+ 优惠金额、实付/退款金额和分配合计满足合同恒等式。
448
+ - 缺少权威总额、差额反推公式、舍入边界、scale/rounding mode、分配规则或对账
449
+ 证据时标记 `Blocked`。不适用差额反推时必须写明真实真源和 owner 证据。
450
+
405
451
  ### 低自由度研发 Agent 五项硬门禁(阻塞级)
406
452
 
407
453
  面向低能力或高自由发挥风险的研发 agent,SDD 文档必须把可猜测空间压到最低。
@@ -828,6 +874,7 @@ Load only the reference needed for the current phase:
828
874
  - OpenSpec format: `references/openspec-format.md`
829
875
  - Document quality: `references/quality-standards.md`
830
876
  - Quality gate: `references/quality-gate.md`
877
+ - 金额精度算法基线:`references/money-precision-algorithms.md`
831
878
  - Batch prompt split: `references/batch-split-guide.md`
832
879
  - Batch prompt template: `references/batch-prompt-template.md`
833
880
  - Implementation orchestration: `references/orchestration.md`
@@ -439,6 +439,14 @@ D. 复用某个已有接口的数据权限规则,请指定参考接口
439
439
  | --- | -------- | -------- | -------- | ---------------------------------- | ------------- | ----------------------- | -------------------------------- | -------------------------- |
440
440
  | 1 | XX SDK | Java SDK | 1.2.3 | 页面表单提交 -> DTO -> SDK Request | appId: 应用ID | {"code":0,"data":{...}} | {"code":500,"message":"timeout"} | 记录阻塞证据,标记外部阻塞 |
441
441
 
442
+ ### 外部集成配置与部署合同
443
+
444
+ 涉及第三方平台/工具、SDK、MQ/Kafka、回调、支付渠道或云服务时必须填写。
445
+
446
+ | 外部依赖/资源 | 配置项/资源名 | 本地来源/创建方式 | 测试来源/创建方式 | 生产来源/创建方式 | 注入/创建方式 | 运行 owner | 创建 owner/时点 | 就绪证据 | 回滚方式 | 密钥处理 | 阻塞项 |
447
+ | ------------- | ------------- | ----------------- | ----------------- | ----------------- | ------------- | ---------- | --------------- | -------- | -------- | -------- | ------ |
448
+ | TDMQ | Consumer Group | 自动/手工/IaC | 已存在/自动创建 | 运维发版前预创建 | 配置/Secret/IaC/控制台 | ydt-energy | 运维/发版前 | 控制台/API/消息轨迹 | 禁用消费/版本回滚 | 仅记录 Secret 引用 | 无/Blocked |
449
+
442
450
  ### 外部枚举绑定确认
443
451
 
444
452
  涉及第三方、SDK、BEM/停车系统、支付/退款、财务展示、来源字段、状态同步、
@@ -452,6 +460,9 @@ D. 复用某个已有接口的数据权限规则,请指定参考接口
452
460
  ### 外部依赖红线
453
461
 
454
462
  - SDK 参数来源必须写明,不得凭字段名猜测含义。
463
+ - 环境相关 endpoint、资源名、标识、凭据、ACL 和运行开关不得只硬编码在注解、常量或业务代码中。
464
+ - 测试环境自动创建、历史资源已存在或应用本地启动成功,不得作为生产资源已就绪的证据。
465
+ - Topic、Consumer Group、namespace、webhook、应用/租户 ID 等服务端资源必须明确生产创建 owner、创建时点、就绪检查和回滚方式;缺失时阻塞发布。
455
466
  - SDK 版本变更必须记录原因和影响范围。
456
467
  - 真实环境可用时,不得仅用 mock 代替。必须在 tests.md 记录真实请求/响应。
457
468
  - 外部服务不可用时,只能标记为"外部阻塞"或"Mock 验证",不得宣称真实链路通过。
@@ -181,6 +181,50 @@ Superpowers 技术详设复制 `外部枚举绑定确认` / `External Enum Bindi
181
181
  禁止用请求成功、值非空或字段存在替代外部枚举业务语义确认。未确认的外部枚举、
182
182
  支付来源、财务展示含义或兜底映射,必须停止并报告 `Blocked`。
183
183
 
184
+ ## 外部集成配置与部署合同(强制)
185
+
186
+ 如果本批涉及第三方平台/工具、SDK、MQ/Kafka、回调、支付渠道或云服务,必须从
187
+ api.md / sdd-quality-gate.md / Superpowers 技术详设复制
188
+ `外部集成配置与部署合同` / `External Integration Configuration And Deployment Contract`。
189
+
190
+ | 外部依赖/资源 | 配置项/资源名 | 本地来源/创建方式 | 测试来源/创建方式 | 生产来源/创建方式 | 注入/创建方式 | 运行 owner | 创建 owner/时点 | 就绪证据 | 回滚 | 密钥处理 | 阻塞项 |
191
+ | ------------- | ------------- | ----------------- | ----------------- | ----------------- | ------------- | ---------- | --------------- | -------- | ---- | -------- | ------ |
192
+ | \_\_\_\_ | \_\_\_\_ | \_\_\_\_ | \_\_\_\_ | \_\_\_\_ | 配置/Secret/IaC/控制台 | \_\_\_\_ | \_\_\_\_ | \_\_\_\_ | \_\_\_\_ | 仅引用 | 无/Blocked |
193
+
194
+ 环境相关配置和服务端资源不得只硬编码在注解、常量或业务代码中。测试自动创建或
195
+ 历史资源存在不能证明生产就绪;缺少生产创建与验证证据时必须停止并报告 `Blocked`。
196
+
197
+ ## 并发与幂等归属(强制)
198
+
199
+ 如果本批涉及并发、批量下发/开通/续费、重复提交/回调/消费或重复外部调用,必须从
200
+ sdd-quality-gate.md / Superpowers 技术详设复制 `Concurrency And Idempotency Ownership`。
201
+
202
+ | 场景 | 业务幂等键 | 原子占用 owner | 应用层原子占用 | 短事务边界 | 状态流转 | 重试复用编码 | 外部调用边界 | 不确定结果处理 | 唯一索引角色 | 测试证据 |
203
+ | ---- | ---------- | -------------- | ---------------- | ---------- | -------- | ------------ | ------------ | -------------- | ------------ | -------- |
204
+ | ____ | ____ | ____ | 锁定 owner 后写 PENDING | 独立提交 | PENDING/SUCCESS/FAILED | 复用原业务单号 | 提交后调用 | 阻止重复并对账 | 非默认/可选兜底 | 并发/重复/重试 |
205
+
206
+ 默认采用应用层原子占用:稳定业务幂等键、短事务占用并落 `PENDING`、提交并释放锁后
207
+ 再调用外部系统。禁止“先查再插”、单进程锁、随机单号和外部调用期间持有长事务。
208
+ 唯一索引不是默认方案,只有自然唯一、历史清理、NULL/软删除和冲突合同明确后才可
209
+ 作为数据库兜底。结果不确定时必须阻止重复调用并进入可追踪对账。
210
+
211
+ ## 金额精度边界继承(强制)
212
+
213
+ 如果本批涉及金额、费用、优惠、抵扣、退款、分账、支付、发票、余额、电费、
214
+ 服务费、套餐结算、比例分摊、明细分配、对账或财务展示,必须从 Superpowers
215
+ 技术详设复制 `Money Precision Boundary`。
216
+
217
+ | 恒等式/权威总额 | 精确类型/构造 | 币种/渠道最小单位 | 舍入层级/mode/来源 | 分配策略/tie-breaker | 差额反推 | 审计证据 | 正负边界测试 |
218
+ | ---------------- | ------------- | ----------------- | -------------------- | --------------------- | -------- | -------- | ------------ |
219
+ | 原始=优惠+实付/原始金额 | BigDecimal/字符串 | CNY/最小单位 | 整单/HALF_UP/合同 | 最大余数/业务主键 | 实付=原始-优惠 | 舍入前后/尾差接收方 | 半分/尾差/退款 |
220
+
221
+ 中间计算不得提前舍入后继续切片、分摊、汇总或抵扣;多明细必须确定性处理尾差,
222
+ 并在 test-report.md 证明原始金额、优惠金额、实付金额和分配合计满足合同恒等式。
223
+ 存在权威总额时,只独立计算 N-1 个组成项,最后一个组成项按权威总额减去其余
224
+ 组成项合计差额反推;禁止所有组成项分别计算、分别舍入后重建总额。必须继承
225
+ `money-precision-algorithms.md` 的币种单位、舍入来源、稳定排序、负数对称和条件性
226
+ 汇率合同。
227
+
184
228
  ## SDD 门禁激活(第一步,在所有编码工作之前执行)
185
229
 
186
230
  本机已配置 Codex Hooks,会在 Edit/Write 时自动拦截。你必须按以下顺序激活:
@@ -148,6 +148,54 @@ Superpowers 技术详设复制 `外部枚举绑定确认` / `External Enum Bindi
148
148
  禁止用请求成功、值非空或字段存在替代外部枚举业务语义确认。未确认的外部枚举、
149
149
  支付来源、财务展示含义或兜底映射,必须停止并报告 `Blocked`。
150
150
 
151
+ ### 1.2 外部集成配置与部署合同
152
+
153
+ 如果本批涉及第三方平台/工具、SDK、MQ/Kafka、回调、支付渠道或云服务,必须从
154
+ api.md / sdd-quality-gate.md / Superpowers 技术详设复制 `外部集成配置与部署合同`:
155
+
156
+ | 外部依赖/资源 | 配置项/资源名 | 本地来源/创建方式 | 测试来源/创建方式 | 生产来源/创建方式 | 注入/创建方式 | 运行 owner | 创建 owner/时点 | 就绪证据 | 回滚 | 密钥处理 | 阻塞项 |
157
+ | ------------- | ------------- | ----------------- | ----------------- | ----------------- | ------------- | ---------- | --------------- | -------- | ---- | -------- | ------ |
158
+ | \_\_\_\_ | \_\_\_\_ | \_\_\_\_ | \_\_\_\_ | \_\_\_\_ | 配置/Secret/IaC/控制台 | \_\_\_\_ | \_\_\_\_ | \_\_\_\_ | \_\_\_\_ | 仅引用 | 无/Blocked |
159
+
160
+ 环境相关配置和服务端资源不得只硬编码在注解、常量或业务代码中。测试自动创建、
161
+ 测试历史资源存在或应用本地启动成功,不能证明生产已就绪;缺少生产创建 owner、
162
+ 创建时点、就绪证据或回滚方式时,必须停止并报告 `Blocked`。
163
+
164
+ ### 1.2.1 并发与幂等归属
165
+
166
+ 如果本批涉及并发、批量下发/开通/续费、重复提交/回调/消费或重复外部调用,必须
167
+ 从 sdd-quality-gate.md / Superpowers 技术详设复制 `Concurrency And Idempotency
168
+ Ownership` / `并发与幂等归属`:
169
+
170
+ | 场景 | 业务幂等键 | 原子占用 owner | 应用层原子占用 | 短事务边界 | 状态流转 | 重试复用编码 | 外部调用边界 | 不确定结果处理 | 唯一索引角色 | 测试证据 |
171
+ | ---- | ---------- | -------------- | ---------------- | ---------- | -------- | ------------ | ------------ | -------------- | ------------ | -------- |
172
+ | ____ | ____ | ____ | 锁定 owner 后写 PENDING | 独立提交 | PENDING/SUCCESS/FAILED | 复用原业务单号 | 提交后调用 | 阻止重复并对账 | 非默认/可选兜底 | 并发/重复/重试 |
173
+
174
+ 默认使用应用层原子占用和稳定业务幂等键,在短事务内持久化 `PENDING` 后提交,释放
175
+ 数据库锁再调用外部系统;重试复用原业务编码,结果不确定时阻止重复并进入对账。
176
+ 禁止“先查再插”、单进程锁、随机单号或跨外部调用的长事务。唯一索引不是默认方案,
177
+ 只有自然唯一、历史数据清理、NULL/软删除和冲突处理合同明确后才可作为可选兜底。
178
+
179
+ ### 1.3 金额精度边界继承
180
+
181
+ 如果本批涉及金额、费用、优惠、抵扣、退款、分账、支付、发票、余额、电费、
182
+ 服务费、套餐结算、比例分摊、明细分配、对账或财务展示,必须从 Superpowers
183
+ 技术详设复制 `Money Precision Boundary`,并在编码前填写:
184
+
185
+ | 恒等式/权威总额 | 精确类型/构造 | 币种/内部与渠道单位 | 舍入层级/scale/mode/来源 | 分配策略/稳定 tie-breaker | 差额反推公式 | 舍入前后/尾差接收方 | 正数/零/退款测试 |
186
+ | ---------------- | ------------- | ------------------- | ------------------------- | ------------------------- | ------------ | --------------------- | ---------------- |
187
+ | 原始=优惠+实付/原始金额 | BigDecimal/字符串 | CNY/计算 scale/最小单位 | 整单/2/HALF_UP/合同 | 最大余数/业务主键 | 实付=原始-优惠 | \_\_\_\_ | TC-\_\_\_\_ |
188
+
189
+ 计算态必须保留原始费率、数量、乘积、比例和分配精度,只能在已确认的结算、
190
+ 持久化、支付、开票、导出或展示边界统一舍入。禁止先 `setScale(2)` 再继续切片、
191
+ 分摊、汇总、抵扣或反推单价。多明细分配必须确定性处理尾差,并证明原始金额、
192
+ 优惠金额、实付金额和分配合计满足合同恒等式。存在加法恒等式且总额是真源时,
193
+ 只能独立计算 N-1 个组成项,最后一个组成项必须按“权威总额减去其余组成项合计”
194
+ 差额反推;禁止所有组成项分别计算、分别舍入后再相加重建权威总额。缺少证据时
195
+ 停止并报告 `Blocked`。同时读取 `money-precision-algorithms.md`;禁止默认所有币种
196
+ 两位小数、从 `double` 构造金额或用数据库隐式舍入代替业务合同。汇率场景还要
197
+ 继承 base/quote、汇率来源与时间、唯一换算路径及目标结算单位。
198
+
151
199
  ### 2. 写入闭环
152
200
 
153
201
  凡本批涉及回填、落库、绑定、持久化、快照、同步、状态推进,必须填写: