@chenmk/superflow 0.2.4 → 0.2.5
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.
- package/assets/skills/superflow-design/SKILL.md +22 -3
- package/assets/skills/superflow-docs/SKILL.md +16 -0
- package/assets/skills/superflow-implement/SKILL.md +17 -0
- package/assets/skills/superflow-pipeline/SKILL.md +18 -0
- package/assets/skills/superflow-pipeline/references/batch-prompt-template.md +17 -0
- package/assets/skills/superflow-pipeline/references/implementation-prompt-template.md +20 -0
- package/assets/skills/superflow-pipeline/references/money-precision-algorithms.md +85 -0
- package/assets/skills/superflow-pipeline/references/quality-gate.md +1 -0
- package/assets/skills/superflow-pipeline/references/reviewer-checklist.md +17 -1
- package/assets/skills/superflow-pipeline/references/superpower-technical-design-template.md +49 -0
- package/assets/skills/superflow-pipeline/references/test-execution-template.md +16 -0
- package/assets/skills/superflow-pipeline/scripts/superflow-guard.sh +88 -0
- package/assets/skills/superflow-verify/SKILL.md +16 -1
- package/assets/skills-en/superflow-design/SKILL.md +22 -3
- package/assets/skills-en/superflow-docs/SKILL.md +16 -0
- package/assets/skills-en/superflow-implement/SKILL.md +10 -0
- package/assets/skills-en/superflow-pipeline/SKILL.md +10 -0
- package/assets/skills-en/superflow-pipeline/references/batch-prompt-template.md +12 -0
- package/assets/skills-en/superflow-pipeline/references/implementation-prompt-template.md +16 -0
- package/assets/skills-en/superflow-pipeline/references/money-precision-algorithms.md +96 -0
- package/assets/skills-en/superflow-pipeline/references/quality-gate.md +9 -0
- package/assets/skills-en/superflow-pipeline/references/reviewer-checklist.md +15 -0
- package/assets/skills-en/superflow-pipeline/references/superpower-technical-design-template.md +49 -0
- package/assets/skills-en/superflow-pipeline/references/test-execution-template.md +18 -0
- package/assets/skills-en/superflow-pipeline/scripts/superflow-guard.sh +88 -0
- package/assets/skills-en/superflow-verify/SKILL.md +16 -1
- package/package.json +1 -1
|
@@ -64,12 +64,31 @@ Impact` and prove writers, readers, filters, derived sync paths, consumers,
|
|
|
64
64
|
owner confirmation, unresolved handling, and test evidence. A request
|
|
65
65
|
succeeding or a field being non-null is not enough; unconfirmed values are
|
|
66
66
|
blockers and must be returned to `$superflow-docs` or the user.
|
|
67
|
-
8.
|
|
67
|
+
8. For amount, fee, discount, deduction, refund, sharing, payment, invoice,
|
|
68
|
+
balance, electricity fee, service fee, package settlement, proration,
|
|
69
|
+
allocation, reconciliation, or financial display changes,
|
|
70
|
+
include `Money Precision Boundary`. Prove calculation-state fields,
|
|
71
|
+
settlement/display-state fields, rounding boundary, scale, rounding mode,
|
|
72
|
+
allocation/reconciliation rule, and tests covering half-cent or residual
|
|
73
|
+
cases. If the design rounds money before later slicing, proration,
|
|
74
|
+
aggregation, discounting, or allocation, stop and redesign the calculation
|
|
75
|
+
boundary. When an additive identity has an authoritative total, the design
|
|
76
|
+
must calculate only N-1 components independently and derive the final
|
|
77
|
+
complement as `authoritative total - sum(other components)`. Independently
|
|
78
|
+
calculating and rounding all components before rebuilding the total is
|
|
79
|
+
blocked. A claimed exception must name the actual source of truth and owner
|
|
80
|
+
evidence. Read
|
|
81
|
+
`../superflow-pipeline/references/money-precision-algorithms.md` and also
|
|
82
|
+
freeze the exact representation, currency/minor-unit boundary, rounding
|
|
83
|
+
level and policy source, deterministic residual strategy with stable
|
|
84
|
+
tie-breaker, and positive/zero/negative evidence. For FX changes, freeze the
|
|
85
|
+
directional rate metadata and one canonical conversion path.
|
|
86
|
+
9. Record state:
|
|
68
87
|
```bash
|
|
69
88
|
../superflow-pipeline/scripts/superflow-state.sh set <change-dir> technical_design docs/superpowers/specs/YYYY-MM-DD-<change-id>-technical-design.md
|
|
70
89
|
../superflow-pipeline/scripts/superflow-state.sh set <change-dir> design_doc design.md
|
|
71
90
|
```
|
|
72
|
-
|
|
91
|
+
10. Update `design.md` with `Superpowers Technical Design Handoff`, update
|
|
73
92
|
`sdd-quality-gate.md` with the technical design path and hash, then run
|
|
74
93
|
`../superflow-pipeline/scripts/superflow-handoff.sh <change-dir> --refresh`.
|
|
75
94
|
If the guard reports a stale or missing hash, record the printed hash in
|
|
@@ -77,7 +96,7 @@ Impact` and prove writers, readers, filters, derived sync paths, consumers,
|
|
|
77
96
|
`--refresh` again. Do not set `design_doc` to the Superpowers document;
|
|
78
97
|
`design_doc` is the OpenSpec/SDD contract design, while `technical_design`
|
|
79
98
|
is the Superpowers HOW document.
|
|
80
|
-
|
|
99
|
+
11. Run:
|
|
81
100
|
|
|
82
101
|
```bash
|
|
83
102
|
../superflow-pipeline/scripts/superflow-yaml-validate.sh <change-dir>
|
|
@@ -85,6 +85,17 @@ Binding` with:
|
|
|
85
85
|
不确定项/阻塞处理 | 测试证据`. Unconfirmed values are blockers; do not
|
|
86
86
|
invent numeric values, origin/source values, display meanings, or fallback
|
|
87
87
|
mappings.
|
|
88
|
+
- For amount, fee, discount, deduction, refund, sharing, payment, invoice,
|
|
89
|
+
balance, electricity/service fee, package settlement, proration, allocation,
|
|
90
|
+
reconciliation, or financial display changes, `sdd-quality-gate.md` must
|
|
91
|
+
declare `Money Precision Boundary` as blocking. `tests.md` and the
|
|
92
|
+
`test-report.md` skeleton must reserve half-cent, residual, or multi-detail
|
|
93
|
+
cases and reconciliation evidence. Do not freeze docs that allow intermediate
|
|
94
|
+
money to be rounded before later slicing, aggregation, discounting, or
|
|
95
|
+
allocation. For additive identities, docs must name the authoritative total,
|
|
96
|
+
independently calculated N-1 components, and the final complement formula:
|
|
97
|
+
`authoritative total - sum(other components)`. Do not allow every component
|
|
98
|
+
to be calculated and rounded independently before rebuilding the total.
|
|
88
99
|
- For low-freedom implementation handoff, docs include the five hard gates:
|
|
89
100
|
field semantic contract, write-through persistence closure, real-entry call
|
|
90
101
|
chain, no-fallback/no-guessing boundary, and pre-coding agent self-check. If
|
|
@@ -302,6 +313,11 @@ test-report证据位置`.
|
|
|
302
313
|
`RED 失败证据`, `GREEN 通过证据`, `接口自动化证据`, `DB 核查证据`,
|
|
303
314
|
`日志核查证据`, `未自动化/阻塞用例`, and `Partially verified 边界`.
|
|
304
315
|
Each section must reference concrete `tests.md` case IDs.
|
|
316
|
+
- For money-related changes, `test-report.md` must also include `Money Precision
|
|
317
|
+
Boundary` evidence: original calculation inputs and precision, actual rounding
|
|
318
|
+
boundary and mode, half-cent/residual/multi-detail cases, and reconciliation
|
|
319
|
+
of original, discount, actual/refund, and allocated totals. Evidence must show
|
|
320
|
+
which total was authoritative and which complement was derived by subtraction.
|
|
305
321
|
- `sdd-quality-gate.md` must include blocking checks for:
|
|
306
322
|
executable tests frozen, RED/GREEN expectations present, interface automation
|
|
307
323
|
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
|
|
@@ -402,6 +402,23 @@ SDD 设计、评审、实现 prompt 和测试报告中,字段/状态/枚举/
|
|
|
402
402
|
- 兜底让异常数据、缺失字段、旧错误状态静默通过,且没有暴露机制,阻塞。
|
|
403
403
|
- 无法证明字段值符合业务语义时,必须标记 `Blocked`,不得冻结设计或生成实现 prompt。
|
|
404
404
|
|
|
405
|
+
### 金额精度边界门禁(阻塞级)
|
|
406
|
+
|
|
407
|
+
凡涉及金额、费用、优惠、抵扣、退款、分账、支付、发票、余额、电费、服务费、
|
|
408
|
+
套餐结算、比例分摊、明细分配、对账或财务展示,必须从 docs、技术详设、实现
|
|
409
|
+
prompt、代码评审、测试到 verify 继承同一份 `Money Precision Boundary`。
|
|
410
|
+
|
|
411
|
+
- 最终结算/持久化/支付/开票/导出/展示边界前保留计算态原始精度。
|
|
412
|
+
- 禁止提前 `setScale(2)` 后继续切片、分摊、汇总、抵扣或反推单价。
|
|
413
|
+
- 多明细必须用确定性规则处理尾差,分配合计必须等于目标金额。
|
|
414
|
+
- 存在加法恒等式且总额是真源时,只允许独立计算 N-1 个组成项;最后一个组成项
|
|
415
|
+
必须按 `权威总额 - 其余组成项合计` 差额反推。禁止所有组成项分别计算、分别
|
|
416
|
+
舍入后再相加重建权威总额。
|
|
417
|
+
- tests.md 和 test-report.md 必须覆盖半分、尾差或多明细场景,并证明原始金额、
|
|
418
|
+
优惠金额、实付/退款金额和分配合计满足合同恒等式。
|
|
419
|
+
- 缺少权威总额、差额反推公式、舍入边界、scale/rounding mode、分配规则或对账
|
|
420
|
+
证据时标记 `Blocked`。不适用差额反推时必须写明真实真源和 owner 证据。
|
|
421
|
+
|
|
405
422
|
### 低自由度研发 Agent 五项硬门禁(阻塞级)
|
|
406
423
|
|
|
407
424
|
面向低能力或高自由发挥风险的研发 agent,SDD 文档必须把可猜测空间压到最低。
|
|
@@ -828,6 +845,7 @@ Load only the reference needed for the current phase:
|
|
|
828
845
|
- OpenSpec format: `references/openspec-format.md`
|
|
829
846
|
- Document quality: `references/quality-standards.md`
|
|
830
847
|
- Quality gate: `references/quality-gate.md`
|
|
848
|
+
- 金额精度算法基线:`references/money-precision-algorithms.md`
|
|
831
849
|
- Batch prompt split: `references/batch-split-guide.md`
|
|
832
850
|
- Batch prompt template: `references/batch-prompt-template.md`
|
|
833
851
|
- Implementation orchestration: `references/orchestration.md`
|
|
@@ -181,6 +181,23 @@ Superpowers 技术详设复制 `外部枚举绑定确认` / `External Enum Bindi
|
|
|
181
181
|
禁止用请求成功、值非空或字段存在替代外部枚举业务语义确认。未确认的外部枚举、
|
|
182
182
|
支付来源、财务展示含义或兜底映射,必须停止并报告 `Blocked`。
|
|
183
183
|
|
|
184
|
+
## 金额精度边界继承(强制)
|
|
185
|
+
|
|
186
|
+
如果本批涉及金额、费用、优惠、抵扣、退款、分账、支付、发票、余额、电费、
|
|
187
|
+
服务费、套餐结算、比例分摊、明细分配、对账或财务展示,必须从 Superpowers
|
|
188
|
+
技术详设复制 `Money Precision Boundary`。
|
|
189
|
+
|
|
190
|
+
| 恒等式/权威总额 | 精确类型/构造 | 币种/渠道最小单位 | 舍入层级/mode/来源 | 分配策略/tie-breaker | 差额反推 | 审计证据 | 正负边界测试 |
|
|
191
|
+
| ---------------- | ------------- | ----------------- | -------------------- | --------------------- | -------- | -------- | ------------ |
|
|
192
|
+
| 原始=优惠+实付/原始金额 | BigDecimal/字符串 | CNY/最小单位 | 整单/HALF_UP/合同 | 最大余数/业务主键 | 实付=原始-优惠 | 舍入前后/尾差接收方 | 半分/尾差/退款 |
|
|
193
|
+
|
|
194
|
+
中间计算不得提前舍入后继续切片、分摊、汇总或抵扣;多明细必须确定性处理尾差,
|
|
195
|
+
并在 test-report.md 证明原始金额、优惠金额、实付金额和分配合计满足合同恒等式。
|
|
196
|
+
存在权威总额时,只独立计算 N-1 个组成项,最后一个组成项按权威总额减去其余
|
|
197
|
+
组成项合计差额反推;禁止所有组成项分别计算、分别舍入后重建总额。必须继承
|
|
198
|
+
`money-precision-algorithms.md` 的币种单位、舍入来源、稳定排序、负数对称和条件性
|
|
199
|
+
汇率合同。
|
|
200
|
+
|
|
184
201
|
## SDD 门禁激活(第一步,在所有编码工作之前执行)
|
|
185
202
|
|
|
186
203
|
本机已配置 Codex Hooks,会在 Edit/Write 时自动拦截。你必须按以下顺序激活:
|
|
@@ -148,6 +148,26 @@ Superpowers 技术详设复制 `外部枚举绑定确认` / `External Enum Bindi
|
|
|
148
148
|
禁止用请求成功、值非空或字段存在替代外部枚举业务语义确认。未确认的外部枚举、
|
|
149
149
|
支付来源、财务展示含义或兜底映射,必须停止并报告 `Blocked`。
|
|
150
150
|
|
|
151
|
+
### 1.2 金额精度边界继承
|
|
152
|
+
|
|
153
|
+
如果本批涉及金额、费用、优惠、抵扣、退款、分账、支付、发票、余额、电费、
|
|
154
|
+
服务费、套餐结算、比例分摊、明细分配、对账或财务展示,必须从 Superpowers
|
|
155
|
+
技术详设复制 `Money Precision Boundary`,并在编码前填写:
|
|
156
|
+
|
|
157
|
+
| 恒等式/权威总额 | 精确类型/构造 | 币种/内部与渠道单位 | 舍入层级/scale/mode/来源 | 分配策略/稳定 tie-breaker | 差额反推公式 | 舍入前后/尾差接收方 | 正数/零/退款测试 |
|
|
158
|
+
| ---------------- | ------------- | ------------------- | ------------------------- | ------------------------- | ------------ | --------------------- | ---------------- |
|
|
159
|
+
| 原始=优惠+实付/原始金额 | BigDecimal/字符串 | CNY/计算 scale/最小单位 | 整单/2/HALF_UP/合同 | 最大余数/业务主键 | 实付=原始-优惠 | \_\_\_\_ | TC-\_\_\_\_ |
|
|
160
|
+
|
|
161
|
+
计算态必须保留原始费率、数量、乘积、比例和分配精度,只能在已确认的结算、
|
|
162
|
+
持久化、支付、开票、导出或展示边界统一舍入。禁止先 `setScale(2)` 再继续切片、
|
|
163
|
+
分摊、汇总、抵扣或反推单价。多明细分配必须确定性处理尾差,并证明原始金额、
|
|
164
|
+
优惠金额、实付金额和分配合计满足合同恒等式。存在加法恒等式且总额是真源时,
|
|
165
|
+
只能独立计算 N-1 个组成项,最后一个组成项必须按“权威总额减去其余组成项合计”
|
|
166
|
+
差额反推;禁止所有组成项分别计算、分别舍入后再相加重建权威总额。缺少证据时
|
|
167
|
+
停止并报告 `Blocked`。同时读取 `money-precision-algorithms.md`;禁止默认所有币种
|
|
168
|
+
两位小数、从 `double` 构造金额或用数据库隐式舍入代替业务合同。汇率场景还要
|
|
169
|
+
继承 base/quote、汇率来源与时间、唯一换算路径及目标结算单位。
|
|
170
|
+
|
|
151
171
|
### 2. 写入闭环
|
|
152
172
|
|
|
153
173
|
凡本批涉及回填、落库、绑定、持久化、快照、同步、状态推进,必须填写:
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
# 金额精度算法基线
|
|
2
|
+
|
|
3
|
+
金额正确性不是“统一保留两位小数”,而是表示、币种单位、计算、舍入、分配、
|
|
4
|
+
汇率、存储和审计共同构成的合同。涉及金额的技术详设、实现提示、评审和验证必须
|
|
5
|
+
应用本基线;若法律、财税、清算机构或支付渠道另有规则,以有证据的外部合同为准。
|
|
6
|
+
|
|
7
|
+
## 1. 精确表示与单位
|
|
8
|
+
|
|
9
|
+
- 计算态使用十进制精确类型(如 Java `BigDecimal`、JSR 354 `MonetaryAmount`)
|
|
10
|
+
或带明确币种的整数最小单位。禁止用二进制 `float`/`double` 表示或计算金额。
|
|
11
|
+
- 从字符串、整数最小单位或精确数据库值构造十进制金额;禁止从 `double` 构造。
|
|
12
|
+
- 每个金额合同必须携带币种、金额单位和 scale。不得假定所有币种都是两位小数;
|
|
13
|
+
同时区分 ISO 4217 小数位、内部计算 scale、结算 scale 和支付渠道最小单位。
|
|
14
|
+
- 对外转换为整数最小单位时,只在适配器边界转换,并校验范围、溢出和渠道规则。
|
|
15
|
+
- 数据库使用 `DECIMAL`/`NUMERIC`,代码、DDL、Mapper 和 API 的 precision/scale
|
|
16
|
+
必须一致。数据库写入时的隐式截断或舍入不能代替业务舍入合同。
|
|
17
|
+
|
|
18
|
+
## 2. 舍入策略矩阵
|
|
19
|
+
|
|
20
|
+
每个舍入点必须声明:业务层级(明细/订单/发票/支付/展示)、输入精度、输出
|
|
21
|
+
scale、rounding mode、币种或现金最小增量、规则来源。禁止全局默认 `HALF_UP`,
|
|
22
|
+
也禁止在同一恒等式中混用“逐行舍入”和“汇总后舍入”而没有对账规则。
|
|
23
|
+
|
|
24
|
+
- 除法必须显式声明精度和 rounding mode;预期精确的运算可用 `UNNECESSARY`
|
|
25
|
+
作为断言,使非整除或意外舍入直接失败。
|
|
26
|
+
- 中间费率、数量、乘积、比例和汇率保留计算精度,只在合同指定的结算边界舍入。
|
|
27
|
+
- `CEILING`、`FLOOR` 等模式对负数含义不同;退款、冲正、负数分摊必须单独验证,
|
|
28
|
+
不能用正数用例推断。
|
|
29
|
+
- 税额和发票必须冻结逐行或整单口径,只实现一个权威路径;若外部合同允许另一
|
|
30
|
+
口径,差异必须进入显式调节或对账规则。
|
|
31
|
+
|
|
32
|
+
## 3. 权威总额与差额反推
|
|
33
|
+
|
|
34
|
+
若合同存在 `总额 = 组成项 1 + ... + 组成项 N`,先识别权威总额。只独立计算
|
|
35
|
+
N-1 个组成项,最后一项按 `权威总额 - 其余组成项合计` 差额反推。禁止所有组成
|
|
36
|
+
项分别计算、分别舍入后相加重建权威总额。确实不适用时,必须记录真实权威来源和
|
|
37
|
+
owner 证据。
|
|
38
|
+
|
|
39
|
+
## 4. 比例分配与尾差
|
|
40
|
+
|
|
41
|
+
比例分配必须先计算高精度理想份额,再量化到结算最小单位:
|
|
42
|
+
|
|
43
|
+
1. 将权威总额转换为目标最小单位,得到必须守恒的整数总量。
|
|
44
|
+
2. 计算各明细高精度理想份额及基础分配额。
|
|
45
|
+
3. 计算 `剩余单位 = 权威总额单位 - 基础分配单位合计`。
|
|
46
|
+
4. 每次分配一个最小单位,直到剩余为零。
|
|
47
|
+
5. 明确确定性策略和稳定 tie-breaker(同余数时按业务主键等稳定字段排序)。
|
|
48
|
+
|
|
49
|
+
默认优先使用最大余数法:按被截去余数从大到小补单位;退款或负数按相同绝对
|
|
50
|
+
排序规则对称扣减。合同也可指定最大金额、最后一行等策略,但必须说明依据,不能
|
|
51
|
+
依赖数据库自然顺序。必须验证合计守恒、顺序稳定、重复执行幂等。
|
|
52
|
+
|
|
53
|
+
## 5. 汇率换算
|
|
54
|
+
|
|
55
|
+
- 汇率是带方向的数据:记录 base/quote 币种、来源、时间点、有效期和精度。
|
|
56
|
+
- 禁止提前截断或舍入汇率;存在权威方向汇率时,不用其倒数构造替代汇率。
|
|
57
|
+
- 冻结唯一换算路径;跨币种中转使用合同指定的基准币种和顺序,最终仅在目标
|
|
58
|
+
结算边界按目标币种或渠道单位舍入。
|
|
59
|
+
- 往返换算只能验证合同容差,不能当作精确恒等式。
|
|
60
|
+
|
|
61
|
+
## 6. 审计与验证
|
|
62
|
+
|
|
63
|
+
金额证据至少记录原始输入、公式/版本、币种与单位、舍入前值、舍入策略、舍入后
|
|
64
|
+
值、尾差和尾差接收方;汇率场景另记录汇率元数据。测试至少覆盖正数、零、负数/
|
|
65
|
+
退款、半最小单位、非整除、多明细、并列余数、极值/溢出和重复执行。
|
|
66
|
+
|
|
67
|
+
核心不变量:
|
|
68
|
+
|
|
69
|
+
- 权威总额始终等于组成项合计。
|
|
70
|
+
- 分配结果始终等于目标结算金额。
|
|
71
|
+
- 相同输入、策略版本和稳定排序始终产生相同结果。
|
|
72
|
+
- 持久化、API 和支付渠道转换不会静默改变金额。
|
|
73
|
+
|
|
74
|
+
## 官方依据
|
|
75
|
+
|
|
76
|
+
- ISO 4217 currency codes:<https://www.iso.org/iso-4217-currency-codes.html>
|
|
77
|
+
- JSR 354 Money and Currency API:<https://www.jcp.org/en/jsr/detail?id=354>
|
|
78
|
+
- Java `BigDecimal`:<https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/math/BigDecimal.html>
|
|
79
|
+
- MySQL exact-value `DECIMAL`:<https://dev.mysql.com/doc/refman/en/fixed-point-types.html>
|
|
80
|
+
- PostgreSQL exact `numeric`:<https://www.postgresql.org/docs/15/datatype-numeric.html>
|
|
81
|
+
- Stripe smallest currency unit:<https://docs.stripe.com/api/payment_intents/object>
|
|
82
|
+
- Adyen currency minor units:<https://docs.adyen.com/development-resources/currency-codes/>
|
|
83
|
+
- EU conversion and rounding rules:<https://eur-lex.europa.eu/legal-content/EN/TXT/?uri=CELEX%3A31997R1103>
|
|
84
|
+
- HMRC VAT rounding:<https://www.gov.uk/hmrc-internal-manuals/vat-trader-records/vatrec12030>
|
|
85
|
+
- SAP allocation residual strategies:<https://help.sap.com/docs/PRODUCT_ID/56471df1959f4cfd9e3bf7a6d2d5be42/56a2dfe71e8b2ea1e10000000a42189c.html>
|
|
@@ -62,6 +62,7 @@
|
|
|
62
62
|
| 44 | **上下文防漂移 handoff** | **所有进入实现的任务强制** | `.sdd/handoff/sdd-context.md`、`.json`、`.sha256` 和 `.sdd/state.yaml` 已生成;design.md、sdd-quality-gate.md、prompt、test-report 记录同一 handoff_hash;`superflow-guard.sh <change-dir> docs` 通过 |
|
|
63
63
|
| 45 | **SDD 状态机字段** | **所有进入实现的任务强制** | `.sdd/state.yaml` 包含 workflow、phase、handoff_hash、build_mode、isolation、tdd_mode、review_mode、verify_mode、implementation_prompt、verification_report、archived;`superflow-state.sh status/next/recover` 输出一致 |
|
|
64
64
|
| 46 | **外部枚举绑定确认** | **涉及第三方、SDK、BEM/停车、支付退款、财务展示、来源字段、状态同步或外部字典时强制** | api.md、sdd-quality-gate.md 和 Superpowers 技术详设包含 `外部枚举绑定确认` / `External Enum Binding`,列出 `业务字段 | 本系统真源字段/枚举 | 外部系统字段 | 外部枚举/字典值 | 展示文案/业务语义/财务语义 | 取值来源 | owner/确认时间 | 不确定项/阻塞处理 | 测试证据`;不得用请求成功、值非空或字段存在替代业务语义确认;未确认时必须阻塞 |
|
|
65
|
+
| 47 | **金额精度边界** | **涉及金额、费用、优惠、抵扣、退款、分账、支付、发票、余额、电费、服务费、套餐结算、比例分摊、明细分配、对账或财务展示时强制** | Superpowers 技术详设包含 `Money Precision Boundary` 及金额恒等式、权威总额、独立计算项、差额反推项与公式、计算态来源、中间精度、舍入边界、scale/rounding mode、分配/对账规则、禁止提前舍入点和测试证据;存在加法恒等式且总额是真源时,最后一个组成项必须由权威总额减去其余组成项合计得到,禁止所有组成项分别计算和舍入后重建总额;测试必须覆盖半分、尾差或多明细分配场景 |
|
|
65
66
|
|
|
66
67
|
### 文档完整性强制检查(新增,全部项目必做)
|
|
67
68
|
|
|
@@ -133,12 +133,28 @@
|
|
|
133
133
|
| 54 | 真实入口日志闭环 | 检查服务日志 | 从入口日志到业务校验、DB 查询、外部调用或异常返回有同一 trace/业务单号串联 |
|
|
134
134
|
| 55 | 泛化失败归因 | 检查外部错误、业务日志和 DB 旁证 | 外部平台泛化失败时未直接写通过;已区分外部阻塞、合同漂移、代码异常 |
|
|
135
135
|
|
|
136
|
+
## 金额精度检查
|
|
137
|
+
|
|
138
|
+
| # | 检查项 | 检查方法 | 通过标准 |
|
|
139
|
+
|---|--------|----------|----------|
|
|
140
|
+
| 56 | 计算态与结算态分离 | 检查金额计算链和技术详设 | 最终边界前保留原始费率、数量、乘积和比例精度,未提前舍入后继续计算 |
|
|
141
|
+
| 57 | 舍入边界明确 | 检查 `setScale`、`RoundingMode`、DB/API/展示转换 | 每个舍入点都有合同依据、scale 和 rounding mode,不存在隐式 double/float 精度损失 |
|
|
142
|
+
| 58 | 分配与尾差确定性 | 检查比例分摊、明细拆分、退款和优惠分配 | 尾差按确定性规则落到明确明细,分配合计等于目标金额 |
|
|
143
|
+
| 59 | 金额证据闭环 | 检查 tests.md 和 test-report.md | 覆盖半分、尾差或多明细场景,并证明原始金额、优惠金额、实付/退款金额及分配合计满足合同恒等式 |
|
|
144
|
+
| 60 | 权威总额与恒等式 | 检查金额合同和真源证据 | 明确哪个总额是合同真源,以及总额与各组成项之间的加法恒等式;不适用时有真实真源和 owner 证据 |
|
|
145
|
+
| 61 | 差额反推算法 | 检查金额组成项计算代码 | 存在权威总额时只独立计算 N-1 个组成项,最后一个组成项由权威总额减去其余组成项合计得到;未分别计算和舍入所有组成项后重建总额 |
|
|
146
|
+
| 62 | 币种与最小单位 | 检查 DTO、适配器、支付渠道和数据库 | 未默认两位小数;内部 scale、ISO/渠道最小单位及转换边界明确,整数转换有溢出校验 |
|
|
147
|
+
| 63 | 舍入策略来源 | 检查逐行/整单/发票/支付边界 | 每个舍入点有层级、scale、mode 和合同来源,未全局硬编码同一策略 |
|
|
148
|
+
| 64 | 最大余数与稳定排序 | 检查多明细分配 | 高精度理想份额量化后逐最小单位分配尾差,同余数按稳定业务键排序,不依赖数据库自然顺序 |
|
|
149
|
+
| 65 | 负数与退款对称性 | 检查退款、冲正和负数分摊 | 正数、零、负数/退款均有证据,明确 `CEILING`/`FLOOR` 等模式的符号差异 |
|
|
150
|
+
| 66 | 汇率路径与元数据 | 检查跨币种换算 | base/quote、来源、时间、精度和唯一换算路径明确,只在目标结算边界舍入 |
|
|
151
|
+
|
|
136
152
|
## 检查记录格式
|
|
137
153
|
|
|
138
154
|
```
|
|
139
155
|
批次评审报告:P{n} - {名称}
|
|
140
156
|
|
|
141
|
-
检查项总数:
|
|
157
|
+
检查项总数:66
|
|
142
158
|
通过:X 项
|
|
143
159
|
未通过:X 项
|
|
144
160
|
不适用:X 项
|
|
@@ -107,6 +107,52 @@ successful request, non-null value, or "field exists" proof is not enough. Do
|
|
|
107
107
|
not invent numeric enum values, source/origin values, financial display
|
|
108
108
|
semantics, fallback values, or compatibility mappings without owner approval.
|
|
109
109
|
|
|
110
|
+
## Money Precision Boundary
|
|
111
|
+
|
|
112
|
+
Use this whenever the change involves amount, fee, discount, deduction, refund,
|
|
113
|
+
sharing, payment, invoice, balance, electricity fee, service fee, package
|
|
114
|
+
settlement, proration, allocation, reconciliation, or financial display.
|
|
115
|
+
|
|
116
|
+
| Amount identity | Authoritative total | Exact type/construction | Currency and unit | Calculation-state source | Rounding level/boundary | Scale/mode/source | Allocation strategy/tie-breaker | Complement derivation | Audit evidence | Test evidence |
|
|
117
|
+
| --------------- | ------------------- | ----------------------- | ----------------- | ------------------------ | ----------------------- | ----------------- | ------------------------------- | --------------------- | -------------- | ------------- |
|
|
118
|
+
| `original = discount + actual` | `original` | `<BigDecimal from string>` | `<CNY; internal scale; provider minor unit>` | `<rate * quantity>` | `<order/payment adapter>` | `<2/HALF_UP/contract>` | `<largest remainder/business key>` | `actual = original - discount` | `<pre/post round; residual recipient>` | `<positive/zero/refund/half-unit/tied residual IDs>` |
|
|
119
|
+
|
|
120
|
+
Use `money-precision-algorithms.md` to complete the contract. State the exact
|
|
121
|
+
decimal representation and construction source; currency and ISO/provider
|
|
122
|
+
minor-unit boundary; rounding level, mode, and policy source; deterministic
|
|
123
|
+
residual strategy and stable tie-breaker; negative/refund symmetry; persistence
|
|
124
|
+
precision/scale and overflow checks. Never assume every currency has two
|
|
125
|
+
decimal places or use database implicit conversion as the rounding policy.
|
|
126
|
+
|
|
127
|
+
For FX changes, additionally record:
|
|
128
|
+
|
|
129
|
+
| Base/quote | Rate source/time | Rate precision | Canonical path | Target unit/rounding | Round-trip tolerance | Evidence |
|
|
130
|
+
| ---------- | ---------------- | -------------- | -------------- | -------------------- | -------------------- | -------- |
|
|
131
|
+
| `<base/quote>` | `<source/timestamp>` | `<scale>` | `<direct/triangulated order>` | `<currency/provider rule>` | `<contract tolerance>` | `<case IDs>` |
|
|
132
|
+
|
|
133
|
+
Required precision checks:
|
|
134
|
+
|
|
135
|
+
```bash
|
|
136
|
+
rg -ni "setScale|round|RoundingMode|BigDecimal|double|float|money\\(" <source-and-test-paths>
|
|
137
|
+
rg -ni "amount|fee|price|discount|deduction|refund|pay|invoice|balance|serviceFee|chargeFee" <source-and-test-paths>
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
The design must separate calculation-state money from settlement/display-state
|
|
141
|
+
money. Intermediate calculations must keep original rate, product, proportion,
|
|
142
|
+
process evidence, and allocation precision. Round only at explicit outbound
|
|
143
|
+
boundaries such as settlement posting, persistence fields that require cents,
|
|
144
|
+
payment/fiscal interfaces, invoices, exports, or display. For multi-detail
|
|
145
|
+
allocation, compute the high-precision target first, then distribute the final
|
|
146
|
+
rounded amount deterministically so totals match and identities such as
|
|
147
|
+
`original = discount + actual` hold. When an additive identity exists and its
|
|
148
|
+
total is the authoritative source, calculate only the required N-1 components
|
|
149
|
+
independently and derive the final complement as `authoritative total - sum(other
|
|
150
|
+
components)`. Do not independently calculate and round every component and then
|
|
151
|
+
rebuild the authoritative total. If complement derivation is not applicable,
|
|
152
|
+
record why, identify the actual source of truth, and provide owner evidence.
|
|
153
|
+
Do not calculate later slices, discounts, ratios, or unit prices from
|
|
154
|
+
already-rounded money.
|
|
155
|
+
|
|
110
156
|
## Execution Architecture
|
|
111
157
|
|
|
112
158
|
- Worker boundaries:
|
|
@@ -144,6 +190,9 @@ semantics, fallback values, or compatibility mappings without owner approval.
|
|
|
144
190
|
that only shows "can call through this module" is not ready.
|
|
145
191
|
- For field/status changes, prove reverse impact before coding: writers,
|
|
146
192
|
readers, filters, derived sync paths, external consumers, and tests.
|
|
193
|
+
- For money changes, prove the precision boundary before coding: calculation
|
|
194
|
+
state, settlement/display state, final rounding point, allocation rule, and
|
|
195
|
+
half-cent/residual tests.
|
|
147
196
|
- Do not invent API fields, DB columns, status semantics, fallback behavior, or
|
|
148
197
|
acceptance criteria.
|
|
149
198
|
- Keep unresolved source facts as blockers. Do not convert them to guesses.
|
|
@@ -98,6 +98,22 @@ Controller、mock endpoint、绕过鉴权端点只能填写 `Mock only` 或 `测
|
|
|
98
98
|
HTTP 200、字段非空、mock-only、DB-only、`BUILD SUCCESS`、`Tests are skipped`
|
|
99
99
|
都不能单独作为接口通过证据。
|
|
100
100
|
|
|
101
|
+
## 4.4 金额精度边界证据
|
|
102
|
+
|
|
103
|
+
涉及金额计算、结算、比例分摊、明细分配、优惠抵扣、退款、支付、开票或财务展示时
|
|
104
|
+
必须填写:
|
|
105
|
+
|
|
106
|
+
| 用例 ID | 恒等式/权威总额 | 币种/最小单位 | 差额反推 | 舍入前/后 | 策略/尾差接收方 | 正数/零/退款/并列余数 | 对账结论 |
|
|
107
|
+
| ------- | ---------------- | ------------- | -------- | ----------- | ----------------- | --------------------- | -------- |
|
|
108
|
+
| TC-M01 | 原始=优惠+实付/原始金额 | CNY/分 | 实付=原始-优惠 | ____/____ | 最大余数/____ | ____ | 一致/阻塞 |
|
|
109
|
+
|
|
110
|
+
必须证明计算态在最终边界前未提前舍入,并证明原始金额、优惠金额、实付金额、退款金额
|
|
111
|
+
或分配合计满足设计合同。存在权威总额时,还必须证明最后一个组成项确实由权威总额
|
|
112
|
+
减去其余组成项合计得到,而不是所有组成项分别计算和舍入。只验证最终展示两位
|
|
113
|
+
小数,不足以证明金额精度正确。证据还必须包含币种、渠道最小单位、舍入前值、
|
|
114
|
+
舍入后值、尾差接收方,以及正数、零、负数/退款、并列余数和幂等验证。汇率场景
|
|
115
|
+
另附 base/quote、汇率来源和目标结算舍入证据。
|
|
116
|
+
|
|
101
117
|
## 5. 详细结果
|
|
102
118
|
|
|
103
119
|
### 5.1 通过的测试
|
|
@@ -259,6 +259,28 @@ change_has_external_enum_risk() {
|
|
|
259
259
|
"$CHANGE_DIR"/specs/*/spec.md 2>/dev/null
|
|
260
260
|
}
|
|
261
261
|
|
|
262
|
+
change_has_money_precision_risk() {
|
|
263
|
+
grep -RIEiq \
|
|
264
|
+
'金额|费用|价格|优惠|折扣|抵扣|退款|分账|支付|发票|余额|电费|服务费|套餐结算|比例分摊|明细分配|尾差|精度|舍入|(^|[^[: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' \
|
|
265
|
+
"$CHANGE_DIR/proposal.md" \
|
|
266
|
+
"$CHANGE_DIR/api.md" \
|
|
267
|
+
"$CHANGE_DIR/design.md" \
|
|
268
|
+
"$CHANGE_DIR/tests.md" \
|
|
269
|
+
"$CHANGE_DIR/spec.md" \
|
|
270
|
+
"$CHANGE_DIR"/specs/*/spec.md 2>/dev/null
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
change_has_fx_precision_risk() {
|
|
274
|
+
grep -RIEiq \
|
|
275
|
+
'汇率|换汇|外汇|币种转换|跨币种|兑换率|(^|[^[:alnum:]_])(exchange rate|fx rate|currency conversion|cross.currency|base currency|quote currency)([^[:alnum:]_]|$)' \
|
|
276
|
+
"$CHANGE_DIR/proposal.md" \
|
|
277
|
+
"$CHANGE_DIR/api.md" \
|
|
278
|
+
"$CHANGE_DIR/design.md" \
|
|
279
|
+
"$CHANGE_DIR/tests.md" \
|
|
280
|
+
"$CHANGE_DIR/spec.md" \
|
|
281
|
+
"$CHANGE_DIR"/specs/*/spec.md 2>/dev/null
|
|
282
|
+
}
|
|
283
|
+
|
|
262
284
|
change_has_architecture_boundary_risk() {
|
|
263
285
|
grep -RIEiq \
|
|
264
286
|
'跨仓|跨服务|sibling|SDK|MQ|topic|consumer|scheduler|定时|device|设备|callback|回调|third[- ]party|第三方|mini[- ]program|小程序|gateway|网关|adapter|适配|protocol|协议|interconnect|互联互通|调用链|入口|出口' \
|
|
@@ -303,6 +325,60 @@ require_external_enum_contract() {
|
|
|
303
325
|
require_grep '不确定|阻塞|blocker|unknown|待确认' "$path" "$label unresolved/blocker column"
|
|
304
326
|
}
|
|
305
327
|
|
|
328
|
+
require_money_precision_contract() {
|
|
329
|
+
local path="$1"
|
|
330
|
+
local label="$2"
|
|
331
|
+
require_grep 'Money Precision Boundary|金额精度边界' "$path" "$label"
|
|
332
|
+
require_grep '计算态|calculation.state|calculation source|intermediate precision' "$path" "$label calculation state"
|
|
333
|
+
require_grep '结算态|展示态|settlement|display.state|rounding boundary' "$path" "$label settlement/display boundary"
|
|
334
|
+
require_grep 'scale|rounding mode|RoundingMode|舍入模式' "$path" "$label scale and rounding mode"
|
|
335
|
+
require_grep '分配|对账|allocation|reconciliation|residual|尾差' "$path" "$label allocation/reconciliation rule"
|
|
336
|
+
require_grep '权威总额|真源总额|authoritative total|source.of.truth total' "$path" "$label authoritative total"
|
|
337
|
+
require_grep '差额反推|总额.*减|authoritative total.*minus|derive.*complement|complement amount' "$path" "$label complement derivation"
|
|
338
|
+
require_grep '禁止.*分别计算|不得.*分别计算|禁止.*独立.*舍入|do not.*independently|must not.*calculate.*separately' "$path" "$label independent calculation prohibition"
|
|
339
|
+
require_grep '禁止提前舍入|不得提前.*舍入|forbidden early rounding|do not.*round' "$path" "$label forbidden early rounding"
|
|
340
|
+
require_grep '半分|尾差|多明细|half.cent|residual|multi.detail' "$path" "$label boundary test evidence"
|
|
341
|
+
require_grep 'BigDecimal|MonetaryAmount|整数最小单位|integer minor unit|exact decimal' "$path" "$label exact representation"
|
|
342
|
+
require_grep '禁止.*(float|double)|不得.*(float|double)|never.*(float|double)|do not.*(float|double)' "$path" "$label binary floating-point prohibition"
|
|
343
|
+
require_grep '币种|currency' "$path" "$label currency contract"
|
|
344
|
+
require_grep '最小单位|minor unit|provider unit|渠道单位' "$path" "$label minor-unit boundary"
|
|
345
|
+
require_grep '舍入层级|舍入点|rounding level|rounding point|明细.*整单|line.level.*aggregate' "$path" "$label rounding level"
|
|
346
|
+
require_grep '规则来源|合同依据|policy source|contract source' "$path" "$label rounding policy source"
|
|
347
|
+
require_grep '最大余数|largest remainder|稳定.*排序|stable tie.break|业务主键' "$path" "$label deterministic residual tie-breaker"
|
|
348
|
+
require_grep '正数.*零.*负数|正数.*退款|positive.*zero.*negative|positive.*refund' "$path" "$label signed-value evidence"
|
|
349
|
+
require_grep '舍入前.*舍入后|pre.round.*post.round' "$path" "$label rounding audit evidence"
|
|
350
|
+
require_grep 'DECIMAL|NUMERIC|数据库.*不适用|持久化.*不适用|persistence.*not applicable' "$path" "$label persistence precision contract"
|
|
351
|
+
if change_has_fx_precision_risk; then
|
|
352
|
+
require_grep 'base/quote|基础币种.*目标币种|基准币种.*报价币种' "$path" "$label FX direction"
|
|
353
|
+
require_grep '汇率来源|rate source' "$path" "$label FX source"
|
|
354
|
+
require_grep '汇率.*时间|rate.*timestamp|rate.*effective' "$path" "$label FX timestamp"
|
|
355
|
+
require_grep '唯一换算路径|权威换算路径|canonical conversion path|canonical path' "$path" "$label FX canonical path"
|
|
356
|
+
require_grep '目标.*结算.*舍入|target.*settlement.*round' "$path" "$label FX target rounding"
|
|
357
|
+
fi
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
require_money_precision_evidence() {
|
|
361
|
+
local path="$1"
|
|
362
|
+
local label="$2"
|
|
363
|
+
require_grep 'Money Precision Boundary|金额精度边界' "$path" "$label"
|
|
364
|
+
require_grep '半分|尾差|多明细|half.cent|residual|multi.detail' "$path" "$label boundary cases"
|
|
365
|
+
require_grep '原始金额|优惠金额|实付金额|分配合计|对账|original.*discount.*actual|allocated total|reconciliation' "$path" "$label reconciliation evidence"
|
|
366
|
+
require_grep '权威总额|真源总额|authoritative total' "$path" "$label authoritative total evidence"
|
|
367
|
+
require_grep '差额反推|总额.*减|authoritative total.*minus|derive.*complement|complement amount' "$path" "$label complement derivation evidence"
|
|
368
|
+
require_grep '币种|currency' "$path" "$label currency evidence"
|
|
369
|
+
require_grep '最小单位|minor unit|provider unit|渠道单位' "$path" "$label minor-unit reconciliation"
|
|
370
|
+
require_grep '正数.*零.*负数|正数.*退款|positive.*zero.*negative|positive.*refund' "$path" "$label signed-value cases"
|
|
371
|
+
require_grep '舍入前.*舍入后|pre.round.*post.round' "$path" "$label rounding audit evidence"
|
|
372
|
+
require_grep '尾差接收方|residual recipient' "$path" "$label residual audit evidence"
|
|
373
|
+
require_grep '并列余数|tied remainder' "$path" "$label tied-residual cases"
|
|
374
|
+
require_grep '幂等|idempoten' "$path" "$label allocation idempotence"
|
|
375
|
+
if change_has_fx_precision_risk; then
|
|
376
|
+
require_grep 'base/quote|基础币种.*目标币种|基准币种.*报价币种' "$path" "$label FX direction evidence"
|
|
377
|
+
require_grep '汇率来源|rate source' "$path" "$label FX source evidence"
|
|
378
|
+
require_grep '目标.*结算.*舍入|target.*settlement.*round' "$path" "$label FX target rounding evidence"
|
|
379
|
+
fi
|
|
380
|
+
}
|
|
381
|
+
|
|
306
382
|
transition_event=""
|
|
307
383
|
|
|
308
384
|
if [[ -x "$VALIDATE" && -f "$CHANGE_DIR/.sdd/state.yaml" ]]; then
|
|
@@ -336,6 +412,9 @@ case "$PHASE" in
|
|
|
336
412
|
require_external_enum_contract api.md "external enum binding contract"
|
|
337
413
|
require_external_enum_contract sdd-quality-gate.md "external enum binding quality gate"
|
|
338
414
|
fi
|
|
415
|
+
if change_has_money_precision_risk; then
|
|
416
|
+
require_grep 'Money Precision Boundary|金额精度边界' sdd-quality-gate.md "money precision quality gate"
|
|
417
|
+
fi
|
|
339
418
|
require_markdown_links_valid
|
|
340
419
|
transition_event="docs-complete"
|
|
341
420
|
;;
|
|
@@ -371,6 +450,9 @@ case "$PHASE" in
|
|
|
371
450
|
if change_has_external_enum_risk; then
|
|
372
451
|
require_external_enum_contract "$technical_design_rel" "external enum binding matrix"
|
|
373
452
|
fi
|
|
453
|
+
if change_has_money_precision_risk; then
|
|
454
|
+
require_money_precision_contract "$technical_design_rel" "money precision boundary"
|
|
455
|
+
fi
|
|
374
456
|
fi
|
|
375
457
|
fi
|
|
376
458
|
require_grep 'Superpowers Technical Design Handoff|Superpower 技术详设|technical_design|源码级 HOW' design.md "Superpowers technical design handoff"
|
|
@@ -399,6 +481,9 @@ case "$PHASE" in
|
|
|
399
481
|
if change_has_external_enum_risk; then
|
|
400
482
|
require_external_enum_contract "$prompt_rel" "prompt external enum binding inheritance"
|
|
401
483
|
fi
|
|
484
|
+
if change_has_money_precision_risk; then
|
|
485
|
+
require_money_precision_contract "$prompt_rel" "prompt money precision inheritance"
|
|
486
|
+
fi
|
|
402
487
|
fi
|
|
403
488
|
require_grep '上下文防漂移|handoff_hash|sdd-context' "$prompt_rel" "prompt context drift inheritance"
|
|
404
489
|
fi
|
|
@@ -427,6 +512,9 @@ case "$PHASE" in
|
|
|
427
512
|
if change_has_external_enum_risk; then
|
|
428
513
|
require_grep 'External Enum Binding|外部枚举绑定|第三方字段语义绑定|外部展示|展示文案|业务语义|财务语义|BEM|真实入口' test-report.md "external enum binding runtime evidence"
|
|
429
514
|
fi
|
|
515
|
+
if change_has_money_precision_risk; then
|
|
516
|
+
require_money_precision_evidence test-report.md "money precision runtime evidence"
|
|
517
|
+
fi
|
|
430
518
|
require_test_report_lint
|
|
431
519
|
require_markdown_links_valid
|
|
432
520
|
if [[ "$(state_get verification_report)" == "" || "$(state_get verification_report)" == "null" ]]; then
|
|
@@ -43,6 +43,16 @@ Use `.sdd/state.yaml` `verify_mode` after `scale`.
|
|
|
43
43
|
prove the complete evidence chain: source/Mapper/XML, DB when needed, real
|
|
44
44
|
entry point, interface automation, logs, SQL sync, and consumer behavior.
|
|
45
45
|
|
|
46
|
+
Money-related changes always require full verification of
|
|
47
|
+
`Money Precision Boundary`: original calculation inputs and intermediate precision, the actual
|
|
48
|
+
rounding boundary and mode, half-cent/residual/multi-detail cases, deterministic
|
|
49
|
+
allocation, and reconciliation identities. A final two-decimal display value
|
|
50
|
+
or unit-test-only evidence is not sufficient.
|
|
51
|
+
For additive identities, verification must prove which total was authoritative,
|
|
52
|
+
which N-1 components were calculated independently, and which final complement
|
|
53
|
+
was derived as `authoritative total - sum(other components)`. Evidence that all
|
|
54
|
+
components were independently calculated and rounded is a failure.
|
|
55
|
+
|
|
46
56
|
## Required Superpowers
|
|
47
57
|
|
|
48
58
|
Immediately load and apply these Superpowers when available:
|
|
@@ -94,7 +104,12 @@ Before pass:
|
|
|
94
104
|
delivery or branch closeout.
|
|
95
105
|
5. Code review findings are either fixed or explicitly recorded with accepted
|
|
96
106
|
risk.
|
|
97
|
-
6.
|
|
107
|
+
6. For money-related changes, `test-report.md` records the `Money Precision
|
|
108
|
+
Boundary` cases and proves original, discount, actual/refund, and allocated
|
|
109
|
+
totals reconcile without early rounding. For additive identities it also
|
|
110
|
+
records the authoritative total and the subtraction used to derive the final
|
|
111
|
+
complement.
|
|
112
|
+
7. Branch/worktree status is handled and `.sdd/state.yaml` has:
|
|
98
113
|
`branch_status: handled`.
|
|
99
114
|
|
|
100
115
|
Only then run:
|
|
@@ -57,12 +57,31 @@ Superpowers own source-level HOW without weakening OpenSpec/SDD contracts.
|
|
|
57
57
|
6. For field/status/enum/sync changes, include `Field And Status Reverse
|
|
58
58
|
Impact` and prove writers, readers, filters, derived sync paths, consumers,
|
|
59
59
|
and tests. Direct setter-only design is blocked.
|
|
60
|
-
7.
|
|
60
|
+
7. For amount, fee, discount, deduction, refund, sharing, payment, invoice,
|
|
61
|
+
balance, electricity fee, service fee, package settlement, proration,
|
|
62
|
+
allocation, reconciliation, or financial display changes,
|
|
63
|
+
include `Money Precision Boundary`. Prove calculation-state fields,
|
|
64
|
+
settlement/display-state fields, rounding boundary, scale, rounding mode,
|
|
65
|
+
allocation/reconciliation rule, and tests covering half-cent or residual
|
|
66
|
+
cases. If the design rounds money before later slicing, proration,
|
|
67
|
+
aggregation, discounting, or allocation, stop and redesign the calculation
|
|
68
|
+
boundary. When an additive identity has an authoritative total, the design
|
|
69
|
+
must calculate only N-1 components independently and derive the final
|
|
70
|
+
complement as `authoritative total - sum(other components)`. Independently
|
|
71
|
+
calculating and rounding all components before rebuilding the total is
|
|
72
|
+
blocked. A claimed exception must name the actual source of truth and owner
|
|
73
|
+
evidence. Read
|
|
74
|
+
`../superflow-pipeline/references/money-precision-algorithms.md` and also
|
|
75
|
+
freeze the exact representation, currency/minor-unit boundary, rounding
|
|
76
|
+
level and policy source, deterministic residual strategy with stable
|
|
77
|
+
tie-breaker, and positive/zero/negative evidence. For FX changes, freeze the
|
|
78
|
+
directional rate metadata and one canonical conversion path.
|
|
79
|
+
8. Record state:
|
|
61
80
|
```bash
|
|
62
81
|
../superflow-pipeline/scripts/superflow-state.sh set <change-dir> technical_design docs/superpowers/specs/YYYY-MM-DD-<change-id>-technical-design.md
|
|
63
82
|
../superflow-pipeline/scripts/superflow-state.sh set <change-dir> design_doc design.md
|
|
64
83
|
```
|
|
65
|
-
|
|
84
|
+
9. Update `design.md` with `Superpowers Technical Design Handoff`, update
|
|
66
85
|
`sdd-quality-gate.md` with the technical design path and hash, then run
|
|
67
86
|
`../superflow-pipeline/scripts/superflow-handoff.sh <change-dir> --refresh`.
|
|
68
87
|
If the guard reports a stale or missing hash, record the printed hash in
|
|
@@ -70,7 +89,7 @@ Superpowers own source-level HOW without weakening OpenSpec/SDD contracts.
|
|
|
70
89
|
`--refresh` again. Do not set `design_doc` to the Superpowers document;
|
|
71
90
|
`design_doc` is the OpenSpec/SDD contract design, while `technical_design`
|
|
72
91
|
is the Superpowers HOW document.
|
|
73
|
-
|
|
92
|
+
10. Run:
|
|
74
93
|
```bash
|
|
75
94
|
../superflow-pipeline/scripts/superflow-yaml-validate.sh <change-dir>
|
|
76
95
|
../superflow-pipeline/scripts/superflow-guard.sh <change-dir> design --apply
|
|
@@ -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 amount, fee, discount, deduction, refund, sharing, payment, invoice,
|
|
80
|
+
balance, electricity/service fee, package settlement, proration, allocation,
|
|
81
|
+
reconciliation, or financial display changes, `sdd-quality-gate.md` must
|
|
82
|
+
declare `Money Precision Boundary` as blocking. `tests.md` and the
|
|
83
|
+
`test-report.md` skeleton must reserve half-cent, residual, or multi-detail
|
|
84
|
+
cases and reconciliation evidence. Do not freeze docs that allow intermediate
|
|
85
|
+
money to be rounded before later slicing, aggregation, discounting, or
|
|
86
|
+
allocation. For additive identities, docs must name the authoritative total,
|
|
87
|
+
independently calculated N-1 components, and the final complement formula:
|
|
88
|
+
`authoritative total - sum(other components)`. Do not allow every component
|
|
89
|
+
to be calculated and rounded independently before rebuilding the total.
|
|
79
90
|
- For low-freedom implementation handoff, docs include the five hard gates:
|
|
80
91
|
field semantic contract, write-through persistence closure, real-entry call
|
|
81
92
|
chain, no-fallback/no-guessing boundary, and pre-coding agent self-check. If
|
|
@@ -293,6 +304,11 @@ Use references only as needed:
|
|
|
293
304
|
`RED failure evidence`, `GREEN pass evidence`, `interface automation evidence`, `DB evidence`,
|
|
294
305
|
`log evidence`, `manual/blocking cases`, and `Partially verified boundary`.
|
|
295
306
|
Each section must reference concrete `tests.md` case IDs.
|
|
307
|
+
- For money-related changes, `test-report.md` must also include `Money Precision
|
|
308
|
+
Boundary` evidence: original calculation inputs and precision, actual rounding
|
|
309
|
+
boundary and mode, half-cent/residual/multi-detail cases, and reconciliation
|
|
310
|
+
of original, discount, actual/refund, and allocated totals. Evidence must show
|
|
311
|
+
which total was authoritative and which complement was derived by subtraction.
|
|
296
312
|
- `sdd-quality-gate.md` must include blocking checks for:
|
|
297
313
|
executable tests frozen, RED/GREEN expectations present, interface automation
|
|
298
314
|
commands present, DB/log assertions present, and mock/skipped cases excluded
|
|
@@ -60,6 +60,14 @@ Every implementation prompt must include these sections:
|
|
|
60
60
|
DTO, converter, SQL, scheduled job, MQ, callback, and sibling repo references.
|
|
61
61
|
- Field semantic contract: source field, source meaning, target field, target
|
|
62
62
|
meaning, equivalence, evidence anchor, forbidden usage, and owner for unknowns.
|
|
63
|
+
- Money precision boundary when monetary behavior changes: calculation-state
|
|
64
|
+
source and intermediate precision, settlement/display boundary, scale and
|
|
65
|
+
rounding mode, forbidden early rounding, deterministic residual allocation,
|
|
66
|
+
authoritative total, complement derivation as `authoritative total -
|
|
67
|
+
sum(other components)`, and half-cent or multi-detail reconciliation evidence.
|
|
68
|
+
It also inherits `money-precision-algorithms.md`: exact representation,
|
|
69
|
+
currency/provider minor units, rounding policy source, stable residual
|
|
70
|
+
tie-breaker, signed-value evidence, and conditional FX metadata.
|
|
63
71
|
- Write-loop verification: business action, setter/assignment, converter, mapper
|
|
64
72
|
insert/update, DB column, downstream reader, consumer entry, SQL check, test
|
|
65
73
|
case.
|
|
@@ -99,6 +107,8 @@ Block prompt generation or execution when any of these are missing:
|
|
|
99
107
|
- handoff files and matching hash;
|
|
100
108
|
- technical_design for full workflow;
|
|
101
109
|
- field/status reverse impact matrix when risky fields or states are touched;
|
|
110
|
+
- money precision boundary when monetary calculation, settlement, allocation,
|
|
111
|
+
reconciliation, or financial display is touched;
|
|
102
112
|
- architecture boundary and call-direction matrix for cross-service or external
|
|
103
113
|
flows;
|
|
104
114
|
- executable tests.md commands for L3/L4 or real-entry requirements;
|
|
@@ -120,6 +120,15 @@ The workflow must preserve these gates:
|
|
|
120
120
|
removal rules.
|
|
121
121
|
- Field/status reverse impact analysis for IDs, statuses, enums, payment,
|
|
122
122
|
online/offline, sync markers, external state, or persisted behavior.
|
|
123
|
+
- Money Precision Boundary for monetary calculation, settlement, allocation,
|
|
124
|
+
reconciliation, or financial display. Preserve calculation-state precision
|
|
125
|
+
until the confirmed final boundary, forbid early rounding, define scale and
|
|
126
|
+
rounding mode plus deterministic residual handling, and require half-cent or
|
|
127
|
+
multi-detail reconciliation evidence across design, prompts, review, tests,
|
|
128
|
+
and verify. When an additive identity has an authoritative total, calculate
|
|
129
|
+
only N-1 components independently and derive the final complement as
|
|
130
|
+
`authoritative total - sum(other components)`; never round every component
|
|
131
|
+
independently and rebuild the authoritative total.
|
|
123
132
|
- Architecture boundary and call-direction analysis for multi-repo, service,
|
|
124
133
|
SDK, MQ, scheduler, callback, gateway, adapter, device, or third-party flows.
|
|
125
134
|
- SQL risk review before implementation for DB changes.
|
|
@@ -169,3 +178,4 @@ Use the reference files in this skill directory as templates:
|
|
|
169
178
|
- references/dirty-worktree.md
|
|
170
179
|
- references/subagent-progress.md
|
|
171
180
|
- references/superpower-technical-design-template.md
|
|
181
|
+
- references/money-precision-algorithms.md
|
|
@@ -24,6 +24,16 @@ review-checklist.md, sdd-quality-gate.md, test-report.md, and technical design.
|
|
|
24
24
|
- Do not change forbidden files or root aggregate docs from a worker batch.
|
|
25
25
|
- Use TDD: record RED failure before GREEN success.
|
|
26
26
|
- Do not mark mock-only or unit-only evidence as real integration.
|
|
27
|
+
- For monetary changes, inherit `Money Precision Boundary`, retain
|
|
28
|
+
calculation-state precision until the confirmed settlement/display boundary,
|
|
29
|
+
record scale and rounding mode, forbid early rounding before slicing or
|
|
30
|
+
allocation, and define deterministic residual handling. For additive
|
|
31
|
+
identities, calculate only N-1 components independently and derive the final
|
|
32
|
+
complement as `authoritative total - sum(other components)`; do not calculate
|
|
33
|
+
and round every component independently.
|
|
34
|
+
- Inherit `money-precision-algorithms.md`: exact decimal construction, currency
|
|
35
|
+
and provider minor units, rounding policy source, deterministic residual
|
|
36
|
+
tie-breaker, signed-value tests, and conditional FX conversion metadata.
|
|
27
37
|
|
|
28
38
|
## Implementation Steps
|
|
29
39
|
|
|
@@ -44,5 +54,7 @@ log check, and hook commands.
|
|
|
44
54
|
- Real-entry evidence
|
|
45
55
|
- DB/log evidence
|
|
46
56
|
- Hook evidence
|
|
57
|
+
- Money precision evidence: half-cent/residual/multi-detail cases and
|
|
58
|
+
reconciliation of original, discount, actual, and allocated totals
|
|
47
59
|
- Deviations
|
|
48
60
|
- Blockers
|
|
@@ -23,6 +23,18 @@ Superpowers technical design is canonical for source-level HOW and execution.
|
|
|
23
23
|
- Field semantic contract checked.
|
|
24
24
|
- Write-loop checked.
|
|
25
25
|
- No-fallback boundary confirmed.
|
|
26
|
+
- Money Precision Boundary copied from the technical design when monetary
|
|
27
|
+
behavior changes. Keep calculation-state precision until the confirmed
|
|
28
|
+
settlement/display boundary, record scale and rounding mode, forbid early
|
|
29
|
+
rounding, and define deterministic residual allocation. For additive
|
|
30
|
+
identities, name the authoritative total, calculate only N-1 components
|
|
31
|
+
independently, and derive the complement as `authoritative total - sum(other
|
|
32
|
+
components)`. Do not calculate and round every component independently.
|
|
33
|
+
- Read `money-precision-algorithms.md`; inherit exact decimal construction,
|
|
34
|
+
currency and provider minor units, rounding level/mode/policy source,
|
|
35
|
+
residual strategy and stable tie-breaker, pre/post-round audit, and
|
|
36
|
+
positive/zero/negative tests. FX changes also inherit base/quote metadata,
|
|
37
|
+
rate source/time, canonical path, and target settlement rounding.
|
|
26
38
|
- RED test executed.
|
|
27
39
|
- Allowed and forbidden files confirmed.
|
|
28
40
|
- Blockers listed.
|
|
@@ -32,3 +44,7 @@ Superpowers technical design is canonical for source-level HOW and execution.
|
|
|
32
44
|
Do not claim completion until build/test, real-entry execution, DB/log evidence,
|
|
33
45
|
test-report update, and SuperBridge Flow hook scripts pass or are marked blocked
|
|
34
46
|
with concrete reasons.
|
|
47
|
+
|
|
48
|
+
For monetary changes, completion also requires half-cent, residual, or
|
|
49
|
+
multi-detail allocation tests and reconciliation evidence proving that original,
|
|
50
|
+
discount, actual, and allocated totals satisfy the contract identities.
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
# Money Precision Algorithm Baseline
|
|
2
|
+
|
|
3
|
+
Money correctness is a contract across representation, currency units,
|
|
4
|
+
calculation, rounding, allocation, FX, persistence, and audit. Apply this
|
|
5
|
+
baseline to monetary design, implementation prompts, review, and verification.
|
|
6
|
+
An evidenced legal, tax, settlement, or provider contract takes precedence.
|
|
7
|
+
|
|
8
|
+
## Exact representation and units
|
|
9
|
+
|
|
10
|
+
- Use an exact decimal type such as Java `BigDecimal`, JSR 354
|
|
11
|
+
`MonetaryAmount`, or integer minor units coupled with an explicit currency.
|
|
12
|
+
Never represent or calculate money with binary `float` or `double`.
|
|
13
|
+
- Construct decimals from strings, exact integers, or exact database values,
|
|
14
|
+
never from a `double`.
|
|
15
|
+
- Every amount contract declares currency, unit, and scale. Never assume two
|
|
16
|
+
decimal places. Distinguish ISO 4217 minor units, internal calculation scale,
|
|
17
|
+
settlement scale, and provider-specific minor units.
|
|
18
|
+
- Convert to integer minor units only at an adapter boundary, with provider
|
|
19
|
+
rule, range, and overflow checks.
|
|
20
|
+
- Persist money as `DECIMAL` or `NUMERIC`. Code, DDL, mapper, and API
|
|
21
|
+
precision/scale must agree. Implicit database conversion is not a business
|
|
22
|
+
rounding policy.
|
|
23
|
+
|
|
24
|
+
## Rounding policy matrix
|
|
25
|
+
|
|
26
|
+
Every rounding point declares its business level, input precision, output
|
|
27
|
+
scale, rounding mode, currency or cash increment, and policy source. Do not
|
|
28
|
+
apply global `HALF_UP`, or mix line-level and aggregate-level rounding inside
|
|
29
|
+
one identity without an explicit reconciliation rule.
|
|
30
|
+
|
|
31
|
+
- Division declares precision and rounding mode. Use `UNNECESSARY` as an
|
|
32
|
+
assertion where an exact result is required.
|
|
33
|
+
- Retain rate, quantity, product, ratio, and FX precision until a contracted
|
|
34
|
+
settlement boundary.
|
|
35
|
+
- Negative values change the meaning of modes such as `CEILING` and `FLOOR`.
|
|
36
|
+
Test refunds and reversals explicitly instead of inferring from positives.
|
|
37
|
+
- Freeze either line-level or invoice-level tax rounding as the authoritative
|
|
38
|
+
path. Route any permitted alternative through an explicit adjustment rule.
|
|
39
|
+
|
|
40
|
+
## Authoritative totals and complement derivation
|
|
41
|
+
|
|
42
|
+
For `total = component 1 + ... + component N`, identify the authoritative
|
|
43
|
+
total, calculate only N-1 components independently, and derive the final
|
|
44
|
+
component as `authoritative total - sum(other components)`. Never calculate and
|
|
45
|
+
round all components independently and then rebuild the authoritative total.
|
|
46
|
+
|
|
47
|
+
## Allocation and residual units
|
|
48
|
+
|
|
49
|
+
Calculate high-precision ideal shares, then quantize at the settlement unit:
|
|
50
|
+
|
|
51
|
+
1. Express the authoritative target in integer settlement units.
|
|
52
|
+
2. Calculate ideal shares and base allocations.
|
|
53
|
+
3. Compute `residual units = target units - sum(base allocation units)`.
|
|
54
|
+
4. Assign one unit at a time until the residual reaches zero.
|
|
55
|
+
5. Use a declared strategy and stable tie-breaker such as a business key.
|
|
56
|
+
|
|
57
|
+
Prefer the largest-remainder method for neutral proportional allocation. Apply
|
|
58
|
+
the same absolute ordering symmetrically to refunds and negative totals.
|
|
59
|
+
Largest-value or last-row policies are allowed only when the contract requires
|
|
60
|
+
them. Never depend on database natural order. Prove conservation, stable order,
|
|
61
|
+
and idempotence.
|
|
62
|
+
|
|
63
|
+
## FX conversion
|
|
64
|
+
|
|
65
|
+
- Treat an FX rate as directional data with base/quote currencies, source,
|
|
66
|
+
timestamp, validity, and precision.
|
|
67
|
+
- Never truncate or round the rate early. Do not synthesize an inverse when a
|
|
68
|
+
canonical directional rate exists.
|
|
69
|
+
- Freeze one conversion path. For triangulation, use the contracted reference
|
|
70
|
+
currency and operation order, then round only at the target settlement unit.
|
|
71
|
+
- Round-trip conversion is a tolerance check, not an exact identity.
|
|
72
|
+
|
|
73
|
+
## Audit and verification
|
|
74
|
+
|
|
75
|
+
Record raw inputs, formula/version, currency/unit, pre-round value, policy,
|
|
76
|
+
post-round value, residual, and residual recipient. Record FX metadata when
|
|
77
|
+
applicable. Test positive, zero, negative/refund, half-unit, non-terminating
|
|
78
|
+
division, multi-detail, tied remainders, overflow, and repeated execution.
|
|
79
|
+
|
|
80
|
+
Required invariants: authoritative total equals component sum; allocations
|
|
81
|
+
equal the settlement target; identical inputs, policy version, and stable order
|
|
82
|
+
produce identical outputs; persistence, API, and provider conversions do not
|
|
83
|
+
silently change money.
|
|
84
|
+
|
|
85
|
+
## Primary references
|
|
86
|
+
|
|
87
|
+
- ISO 4217: <https://www.iso.org/iso-4217-currency-codes.html>
|
|
88
|
+
- JSR 354: <https://www.jcp.org/en/jsr/detail?id=354>
|
|
89
|
+
- Java `BigDecimal`: <https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/math/BigDecimal.html>
|
|
90
|
+
- MySQL `DECIMAL`: <https://dev.mysql.com/doc/refman/en/fixed-point-types.html>
|
|
91
|
+
- PostgreSQL `numeric`: <https://www.postgresql.org/docs/15/datatype-numeric.html>
|
|
92
|
+
- Stripe minor units: <https://docs.stripe.com/api/payment_intents/object>
|
|
93
|
+
- Adyen minor units: <https://docs.adyen.com/development-resources/currency-codes/>
|
|
94
|
+
- EU conversion rules: <https://eur-lex.europa.eu/legal-content/EN/TXT/?uri=CELEX%3A31997R1103>
|
|
95
|
+
- HMRC VAT rounding: <https://www.gov.uk/hmrc-internal-manuals/vat-trader-records/vatrec12030>
|
|
96
|
+
- SAP allocation residuals: <https://help.sap.com/docs/PRODUCT_ID/56471df1959f4cfd9e3bf7a6d2d5be42/56a2dfe71e8b2ea1e10000000a42189c.html>
|
|
@@ -16,6 +16,15 @@
|
|
|
16
16
|
- Field/status reverse impact matrix exists when risky fields or states change.
|
|
17
17
|
- Architecture boundary and call-direction matrix exists for cross-service or
|
|
18
18
|
external flows.
|
|
19
|
+
- Money precision boundary exists when amount, fee, discount, deduction,
|
|
20
|
+
refund, sharing, payment, invoice, balance, electricity fee, service fee,
|
|
21
|
+
package settlement, proration, allocation, reconciliation, or financial
|
|
22
|
+
display changes. It must separate calculation state from settlement/display
|
|
23
|
+
state, forbid early rounding, and include half-cent, residual, or
|
|
24
|
+
multi-detail allocation evidence. For additive identities, it must name the
|
|
25
|
+
authoritative total and derive the final complement as `authoritative total -
|
|
26
|
+
sum(other components)` instead of calculating and rounding every component
|
|
27
|
+
independently.
|
|
19
28
|
- SQL risk review exists for DB changes.
|
|
20
29
|
- No fallback or guesswork is allowed without explicit owner approval.
|
|
21
30
|
|
|
@@ -5,6 +5,21 @@
|
|
|
5
5
|
- Is handoff_hash current and repeated in prompts/report?
|
|
6
6
|
- Did Superpowers technical design cover source-level HOW?
|
|
7
7
|
- Were field/status and architecture-boundary risks checked?
|
|
8
|
+
- For monetary changes, were calculation and settlement states separated, were
|
|
9
|
+
scale and rounding mode explicit, and was early rounding rejected?
|
|
10
|
+
- Do half-cent, residual, and multi-detail tests prove deterministic allocation
|
|
11
|
+
and reconciliation of original, discount, actual/refund, and allocated totals?
|
|
12
|
+
- For additive identities, is the authoritative total explicit, with only N-1
|
|
13
|
+
components calculated independently and the final complement derived as
|
|
14
|
+
`authoritative total - sum(other components)`?
|
|
15
|
+
- Reject designs that calculate and round every component independently before
|
|
16
|
+
rebuilding an authoritative total.
|
|
17
|
+
- Are exact decimal construction, currency and provider minor units, rounding
|
|
18
|
+
level/policy source, and persistence precision explicit?
|
|
19
|
+
- Does allocation use a declared residual strategy and stable tie-breaker, with
|
|
20
|
+
positive, zero, negative/refund, tied-remainder, and idempotence evidence?
|
|
21
|
+
- For FX, are base/quote, source/time, canonical path, and target settlement
|
|
22
|
+
rounding explicit, without early rate rounding or synthesized inverses?
|
|
8
23
|
- Are SQL changes reviewed and tied to total version SQL when needed?
|
|
9
24
|
- Are RED/GREEN evidence and real-entry evidence present?
|
|
10
25
|
- Are mock-only results clearly labeled?
|
package/assets/skills-en/superflow-pipeline/references/superpower-technical-design-template.md
CHANGED
|
@@ -83,6 +83,52 @@ third-party adapters, and sibling repos when the table or DTO is shared.
|
|
|
83
83
|
The technical design must say which references are intentionally unchanged and
|
|
84
84
|
why. A change is not ready when only the direct setter/writer is designed.
|
|
85
85
|
|
|
86
|
+
## Money Precision Boundary
|
|
87
|
+
|
|
88
|
+
Use this whenever the change involves amount, fee, discount, deduction, refund,
|
|
89
|
+
sharing, payment, invoice, balance, electricity fee, service fee, package
|
|
90
|
+
settlement, proration, allocation, reconciliation, or financial display.
|
|
91
|
+
|
|
92
|
+
| Amount identity | Authoritative total | Exact type/construction | Currency and unit | Calculation-state source | Rounding level/boundary | Scale/mode/source | Allocation strategy/tie-breaker | Complement derivation | Audit evidence | Test evidence |
|
|
93
|
+
|---|---|---|---|---|---|---|---|---|---|---|
|
|
94
|
+
| `original = discount + actual` | `original` | `<BigDecimal from string>` | `<currency; internal scale; provider minor unit>` | `<rate * quantity>` | `<order/payment adapter>` | `<scale/mode/contract>` | `<largest remainder/business key>` | `actual = original - discount` | `<pre/post round; residual recipient>` | `<positive/zero/refund/half-unit/tied residual IDs>` |
|
|
95
|
+
|
|
96
|
+
Use `money-precision-algorithms.md` to complete the contract. State exact
|
|
97
|
+
representation and construction; currency and ISO/provider minor-unit boundary;
|
|
98
|
+
rounding level, mode, and policy source; residual strategy and stable
|
|
99
|
+
tie-breaker; negative/refund symmetry; persistence precision/scale and overflow
|
|
100
|
+
checks. Never assume every currency has two decimals or treat implicit database
|
|
101
|
+
conversion as the rounding policy.
|
|
102
|
+
|
|
103
|
+
For FX changes, additionally record:
|
|
104
|
+
|
|
105
|
+
| Base/quote | Rate source/time | Rate precision | Canonical path | Target unit/rounding | Round-trip tolerance | Evidence |
|
|
106
|
+
|---|---|---|---|---|---|---|
|
|
107
|
+
| `<base/quote>` | `<source/timestamp>` | `<scale>` | `<direct/triangulated order>` | `<currency/provider rule>` | `<contract tolerance>` | `<case IDs>` |
|
|
108
|
+
|
|
109
|
+
Required precision checks:
|
|
110
|
+
|
|
111
|
+
```bash
|
|
112
|
+
rg -ni "setScale|round|RoundingMode|BigDecimal|double|float|money\\(" <source-and-test-paths>
|
|
113
|
+
rg -ni "amount|fee|price|discount|deduction|refund|pay|invoice|balance|serviceFee|chargeFee" <source-and-test-paths>
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
The design must separate calculation-state money from settlement/display-state
|
|
117
|
+
money. Intermediate calculations must keep original rate, product, proportion,
|
|
118
|
+
process evidence, and allocation precision. Round only at explicit outbound
|
|
119
|
+
boundaries such as settlement posting, persistence fields that require cents,
|
|
120
|
+
payment/fiscal interfaces, invoices, exports, or display. For multi-detail
|
|
121
|
+
allocation, compute the high-precision target first, then distribute the final
|
|
122
|
+
rounded amount deterministically so totals match and identities such as
|
|
123
|
+
`original = discount + actual` hold. When an additive identity exists and its
|
|
124
|
+
total is the authoritative source, calculate only the required N-1 components
|
|
125
|
+
independently and derive the final complement as `authoritative total - sum(other
|
|
126
|
+
components)`. Do not independently calculate and round every component and then
|
|
127
|
+
rebuild the authoritative total. If complement derivation is not applicable,
|
|
128
|
+
record why, identify the actual source of truth, and provide owner evidence.
|
|
129
|
+
Do not calculate later slices, discounts, ratios, or unit prices from
|
|
130
|
+
already-rounded money.
|
|
131
|
+
|
|
86
132
|
## Execution Architecture
|
|
87
133
|
|
|
88
134
|
- Worker boundaries:
|
|
@@ -119,6 +165,9 @@ why. A change is not ready when only the direct setter/writer is designed.
|
|
|
119
165
|
that only shows "can call through this module" is not ready.
|
|
120
166
|
- For field/status changes, prove reverse impact before coding: writers,
|
|
121
167
|
readers, filters, derived sync paths, external consumers, and tests.
|
|
168
|
+
- For money changes, prove the precision boundary before coding: calculation
|
|
169
|
+
state, settlement/display state, final rounding point, allocation rule, and
|
|
170
|
+
half-cent/residual tests.
|
|
122
171
|
- Do not invent API fields, DB columns, status semantics, fallback behavior, or
|
|
123
172
|
acceptance criteria.
|
|
124
173
|
- Keep unresolved source facts as blockers. Do not convert them to guesses.
|
|
@@ -20,3 +20,21 @@
|
|
|
20
20
|
- Result:
|
|
21
21
|
- Evidence:
|
|
22
22
|
- Blocker if not executed:
|
|
23
|
+
|
|
24
|
+
## Money Precision Boundary Evidence
|
|
25
|
+
|
|
26
|
+
Required when monetary calculation, settlement, proration, allocation,
|
|
27
|
+
reconciliation, or financial display changes:
|
|
28
|
+
|
|
29
|
+
| Case | Identity/authoritative total | Currency/minor unit | Complement | Pre/post round | Strategy/residual recipient | Positive/zero/refund/tied residual | Reconciliation |
|
|
30
|
+
|---|---|---|---|---|---|---|---|
|
|
31
|
+
| TC-M01 | `original = discount + actual` / `original` | CNY/minor unit | `actual = original - discount` | | largest remainder / | | pass/blocked |
|
|
32
|
+
|
|
33
|
+
Prove that calculation-state values were not rounded before the confirmed final
|
|
34
|
+
boundary and that original, discount, actual, refund, and allocated totals obey
|
|
35
|
+
the design contract. When an authoritative total exists, prove the final
|
|
36
|
+
component was derived by subtraction instead of independently calculated and
|
|
37
|
+
rounded. Record currency, provider minor unit, pre/post-round values, residual
|
|
38
|
+
recipient, and positive/zero/negative or refund, tied remainder, and idempotent
|
|
39
|
+
recalculation evidence. FX cases also record base/quote, rate source, and target
|
|
40
|
+
settlement rounding. A two-decimal display assertion alone is insufficient.
|
|
@@ -248,6 +248,28 @@ change_has_field_status_risk() {
|
|
|
248
248
|
"$CHANGE_DIR"/*.md "$CHANGE_DIR"/**/*.md 2>/dev/null
|
|
249
249
|
}
|
|
250
250
|
|
|
251
|
+
change_has_money_precision_risk() {
|
|
252
|
+
grep -RIEiq \
|
|
253
|
+
'(^|[^[:alnum:]_])(amount|fee|fees|price|discount|deduction|refund|payment|invoice|balance|proration|allocation|reconciliation|residual|precision|rounding)([^[:alnum:]_]|$)|revenue sharing|profit sharing|split payment|electricity fee|service fee|package settlement|serviceFee|chargeFee|totalAmount|actualAmount|payAmount|refundAmount|discountAmount|invoiceAmount|balanceAmount' \
|
|
254
|
+
"$CHANGE_DIR/proposal.md" \
|
|
255
|
+
"$CHANGE_DIR/api.md" \
|
|
256
|
+
"$CHANGE_DIR/design.md" \
|
|
257
|
+
"$CHANGE_DIR/tests.md" \
|
|
258
|
+
"$CHANGE_DIR/spec.md" \
|
|
259
|
+
"$CHANGE_DIR"/specs/*/spec.md 2>/dev/null
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
change_has_fx_precision_risk() {
|
|
263
|
+
grep -RIEiq \
|
|
264
|
+
'(^|[^[:alnum:]_])(exchange rate|fx rate|currency conversion|cross.currency|base currency|quote currency)([^[:alnum:]_]|$)' \
|
|
265
|
+
"$CHANGE_DIR/proposal.md" \
|
|
266
|
+
"$CHANGE_DIR/api.md" \
|
|
267
|
+
"$CHANGE_DIR/design.md" \
|
|
268
|
+
"$CHANGE_DIR/tests.md" \
|
|
269
|
+
"$CHANGE_DIR/spec.md" \
|
|
270
|
+
"$CHANGE_DIR"/specs/*/spec.md 2>/dev/null
|
|
271
|
+
}
|
|
272
|
+
|
|
251
273
|
change_has_architecture_boundary_risk() {
|
|
252
274
|
grep -RIEiq \
|
|
253
275
|
'cross-repo|cross-service|sibling|SDK|MQ|topic|consumer|scheduler|scheduled|device|callback|third[- ]party|mini[- ]program|gateway|adapter|protocol|interconnect|call chain|entry|exit' \
|
|
@@ -281,6 +303,60 @@ require_prompt_set() {
|
|
|
281
303
|
fi
|
|
282
304
|
}
|
|
283
305
|
|
|
306
|
+
require_money_precision_contract() {
|
|
307
|
+
local path="$1"
|
|
308
|
+
local label="$2"
|
|
309
|
+
require_grep 'Money Precision Boundary' "$path" "$label"
|
|
310
|
+
require_grep 'calculation.state|calculation source|intermediate precision' "$path" "$label calculation state"
|
|
311
|
+
require_grep 'settlement|display.state|rounding boundary' "$path" "$label settlement/display boundary"
|
|
312
|
+
require_grep 'scale|rounding mode|RoundingMode' "$path" "$label scale and rounding mode"
|
|
313
|
+
require_grep 'allocation|reconciliation|residual' "$path" "$label allocation/reconciliation rule"
|
|
314
|
+
require_grep 'authoritative total|source.of.truth total' "$path" "$label authoritative total"
|
|
315
|
+
require_grep 'authoritative total.*minus|derive.*complement|complement amount' "$path" "$label complement derivation"
|
|
316
|
+
require_grep 'do not.*independently|must not.*calculate.*separately' "$path" "$label independent calculation prohibition"
|
|
317
|
+
require_grep 'forbidden early rounding|do not.*round' "$path" "$label forbidden early rounding"
|
|
318
|
+
require_grep 'half.cent|residual|multi.detail' "$path" "$label boundary test evidence"
|
|
319
|
+
require_grep 'BigDecimal|MonetaryAmount|integer minor unit|exact decimal' "$path" "$label exact representation"
|
|
320
|
+
require_grep 'never.*(float|double)|do not.*(float|double)' "$path" "$label binary floating-point prohibition"
|
|
321
|
+
require_grep 'currency' "$path" "$label currency contract"
|
|
322
|
+
require_grep 'minor unit|provider unit' "$path" "$label minor-unit boundary"
|
|
323
|
+
require_grep 'rounding level|rounding point|line.level.*aggregate' "$path" "$label rounding level"
|
|
324
|
+
require_grep 'policy source|contract source' "$path" "$label rounding policy source"
|
|
325
|
+
require_grep 'largest remainder|stable tie.break|business key' "$path" "$label deterministic residual tie-breaker"
|
|
326
|
+
require_grep 'positive.*zero.*negative|positive.*refund' "$path" "$label signed-value evidence"
|
|
327
|
+
require_grep 'pre.round.*post.round' "$path" "$label rounding audit evidence"
|
|
328
|
+
require_grep 'DECIMAL|NUMERIC|persistence.*not applicable' "$path" "$label persistence precision contract"
|
|
329
|
+
if change_has_fx_precision_risk; then
|
|
330
|
+
require_grep 'base/quote|base currency.*quote currency' "$path" "$label FX direction"
|
|
331
|
+
require_grep 'rate source' "$path" "$label FX source"
|
|
332
|
+
require_grep 'rate.*timestamp|rate.*effective' "$path" "$label FX timestamp"
|
|
333
|
+
require_grep 'canonical conversion path|canonical path' "$path" "$label FX canonical path"
|
|
334
|
+
require_grep 'target.*settlement.*round' "$path" "$label FX target rounding"
|
|
335
|
+
fi
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
require_money_precision_evidence() {
|
|
339
|
+
local path="$1"
|
|
340
|
+
local label="$2"
|
|
341
|
+
require_grep 'Money Precision Boundary' "$path" "$label"
|
|
342
|
+
require_grep 'half.cent|residual|multi.detail' "$path" "$label boundary cases"
|
|
343
|
+
require_grep 'original.*discount.*actual|allocated total|reconciliation' "$path" "$label reconciliation evidence"
|
|
344
|
+
require_grep 'authoritative total' "$path" "$label authoritative total evidence"
|
|
345
|
+
require_grep 'authoritative total.*minus|derive.*complement|complement amount' "$path" "$label complement derivation evidence"
|
|
346
|
+
require_grep 'currency' "$path" "$label currency evidence"
|
|
347
|
+
require_grep 'minor unit|provider unit' "$path" "$label minor-unit reconciliation"
|
|
348
|
+
require_grep 'positive.*zero.*negative|positive.*refund' "$path" "$label signed-value cases"
|
|
349
|
+
require_grep 'pre.round.*post.round' "$path" "$label rounding audit evidence"
|
|
350
|
+
require_grep 'residual recipient' "$path" "$label residual audit evidence"
|
|
351
|
+
require_grep 'tied remainder' "$path" "$label tied-residual cases"
|
|
352
|
+
require_grep 'idempoten' "$path" "$label allocation idempotence"
|
|
353
|
+
if change_has_fx_precision_risk; then
|
|
354
|
+
require_grep 'base/quote|base currency.*quote currency' "$path" "$label FX direction evidence"
|
|
355
|
+
require_grep 'rate source' "$path" "$label FX source evidence"
|
|
356
|
+
require_grep 'target.*settlement.*round' "$path" "$label FX target rounding evidence"
|
|
357
|
+
fi
|
|
358
|
+
}
|
|
359
|
+
|
|
284
360
|
transition_event=""
|
|
285
361
|
|
|
286
362
|
if [[ -x "$VALIDATE" && -f "$CHANGE_DIR/.sdd/state.yaml" ]]; then
|
|
@@ -310,6 +386,9 @@ case "$PHASE" in
|
|
|
310
386
|
require_grep 'RED|red-green|GREEN' tests.md "RED/GREEN test contract"
|
|
311
387
|
require_grep 'curl|Postman|Newman|pytest|RestAssured|automation command' tests.md "interface automation command"
|
|
312
388
|
require_grep 'handoff_hash|sdd-context|context package|anti-drift' sdd-quality-gate.md "handoff/context-drift gate"
|
|
389
|
+
if change_has_money_precision_risk; then
|
|
390
|
+
require_grep 'Money Precision Boundary' sdd-quality-gate.md "money precision quality gate"
|
|
391
|
+
fi
|
|
313
392
|
require_markdown_links_valid
|
|
314
393
|
transition_event="docs-complete"
|
|
315
394
|
;;
|
|
@@ -342,6 +421,9 @@ case "$PHASE" in
|
|
|
342
421
|
if change_has_field_status_risk; then
|
|
343
422
|
require_grep 'Field And Status Reverse Impact|Field And Status Reverse Impact|write point.*read|read/filter points|derived/sync points' "$technical_design_rel" "field/status reverse impact matrix"
|
|
344
423
|
fi
|
|
424
|
+
if change_has_money_precision_risk; then
|
|
425
|
+
require_money_precision_contract "$technical_design_rel" "money precision boundary"
|
|
426
|
+
fi
|
|
345
427
|
fi
|
|
346
428
|
fi
|
|
347
429
|
require_grep 'Superpowers Technical Design Handoff|Superpowers Technical Design|technical_design|source-level HOW' design.md "Superpowers technical design handoff"
|
|
@@ -367,6 +449,9 @@ case "$PHASE" in
|
|
|
367
449
|
if change_has_field_status_risk; then
|
|
368
450
|
require_grep 'Field And Status Reverse Impact|Field And Status Reverse Impact|read/filter points|derived/sync points' "$prompt_rel" "prompt field/status reverse impact inheritance"
|
|
369
451
|
fi
|
|
452
|
+
if change_has_money_precision_risk; then
|
|
453
|
+
require_money_precision_contract "$prompt_rel" "prompt money precision inheritance"
|
|
454
|
+
fi
|
|
370
455
|
fi
|
|
371
456
|
require_grep 'context anti-drift|handoff_hash|sdd-context' "$prompt_rel" "prompt context drift inheritance"
|
|
372
457
|
fi
|
|
@@ -392,6 +477,9 @@ case "$PHASE" in
|
|
|
392
477
|
require_grep 'interface automation|curl|Postman|Newman|pytest|RestAssured' test-report.md "interface automation evidence"
|
|
393
478
|
require_grep 'DB|database|SELECT|SHOW CREATE' test-report.md "DB evidence"
|
|
394
479
|
require_grep 'superflow-verify-integration|superflow-delivery-check|superflow-test-report-lint' test-report.md "SuperBridge Flow hook/script evidence"
|
|
480
|
+
if change_has_money_precision_risk; then
|
|
481
|
+
require_money_precision_evidence test-report.md "money precision runtime evidence"
|
|
482
|
+
fi
|
|
395
483
|
require_test_report_lint
|
|
396
484
|
require_markdown_links_valid
|
|
397
485
|
if [[ "$(state_get verification_report)" == "" || "$(state_get verification_report)" == "null" ]]; then
|
|
@@ -43,6 +43,16 @@ Use `.sdd/state.yaml` `verify_mode` after `scale`.
|
|
|
43
43
|
prove the complete evidence chain: source/Mapper/XML, DB when needed, real
|
|
44
44
|
entry point, interface automation, logs, SQL sync, and consumer behavior.
|
|
45
45
|
|
|
46
|
+
Money-related changes always require full verification of
|
|
47
|
+
`Money Precision Boundary`: original calculation inputs and intermediate precision, the actual
|
|
48
|
+
rounding boundary and mode, half-cent/residual/multi-detail cases, deterministic
|
|
49
|
+
allocation, and reconciliation identities. A final two-decimal display value
|
|
50
|
+
or unit-test-only evidence is not sufficient.
|
|
51
|
+
For additive identities, verification must prove which total was authoritative,
|
|
52
|
+
which N-1 components were calculated independently, and which final complement
|
|
53
|
+
was derived as `authoritative total - sum(other components)`. Evidence that all
|
|
54
|
+
components were independently calculated and rounded is a failure.
|
|
55
|
+
|
|
46
56
|
## Required Superpowers
|
|
47
57
|
|
|
48
58
|
Immediately load and apply these Superpowers when available:
|
|
@@ -94,7 +104,12 @@ Before pass:
|
|
|
94
104
|
delivery or branch closeout.
|
|
95
105
|
5. Code review findings are either fixed or explicitly recorded with accepted
|
|
96
106
|
risk.
|
|
97
|
-
6.
|
|
107
|
+
6. For money-related changes, `test-report.md` records the `Money Precision
|
|
108
|
+
Boundary` cases and proves original, discount, actual/refund, and allocated
|
|
109
|
+
totals reconcile without early rounding. For additive identities it also
|
|
110
|
+
records the authoritative total and the subtraction used to derive the final
|
|
111
|
+
complement.
|
|
112
|
+
7. Branch/worktree status is handled and `.sdd/state.yaml` has:
|
|
98
113
|
`branch_status: handled`.
|
|
99
114
|
|
|
100
115
|
Only then run:
|