@chenmk/superflow 0.2.3 → 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.
Files changed (30) hide show
  1. package/README.md +15 -0
  2. package/README.zh-CN.md +8 -0
  3. package/assets/skills/superflow-design/SKILL.md +22 -3
  4. package/assets/skills/superflow-docs/SKILL.md +16 -0
  5. package/assets/skills/superflow-implement/SKILL.md +17 -0
  6. package/assets/skills/superflow-pipeline/SKILL.md +18 -0
  7. package/assets/skills/superflow-pipeline/references/batch-prompt-template.md +17 -0
  8. package/assets/skills/superflow-pipeline/references/implementation-prompt-template.md +20 -0
  9. package/assets/skills/superflow-pipeline/references/money-precision-algorithms.md +85 -0
  10. package/assets/skills/superflow-pipeline/references/quality-gate.md +1 -0
  11. package/assets/skills/superflow-pipeline/references/reviewer-checklist.md +17 -1
  12. package/assets/skills/superflow-pipeline/references/superpower-technical-design-template.md +49 -0
  13. package/assets/skills/superflow-pipeline/references/test-execution-template.md +16 -0
  14. package/assets/skills/superflow-pipeline/scripts/superflow-guard.sh +88 -0
  15. package/assets/skills/superflow-verify/SKILL.md +16 -1
  16. package/assets/skills-en/superflow-design/SKILL.md +22 -3
  17. package/assets/skills-en/superflow-docs/SKILL.md +16 -0
  18. package/assets/skills-en/superflow-implement/SKILL.md +10 -0
  19. package/assets/skills-en/superflow-pipeline/SKILL.md +10 -0
  20. package/assets/skills-en/superflow-pipeline/references/batch-prompt-template.md +12 -0
  21. package/assets/skills-en/superflow-pipeline/references/implementation-prompt-template.md +16 -0
  22. package/assets/skills-en/superflow-pipeline/references/money-precision-algorithms.md +96 -0
  23. package/assets/skills-en/superflow-pipeline/references/quality-gate.md +9 -0
  24. package/assets/skills-en/superflow-pipeline/references/reviewer-checklist.md +15 -0
  25. package/assets/skills-en/superflow-pipeline/references/superpower-technical-design-template.md +49 -0
  26. package/assets/skills-en/superflow-pipeline/references/test-execution-template.md +18 -0
  27. package/assets/skills-en/superflow-pipeline/scripts/superflow-guard.sh +88 -0
  28. package/assets/skills-en/superflow-verify/SKILL.md +16 -1
  29. package/package.json +3 -1
  30. package/scripts/postinstall.js +56 -0
@@ -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. Record state:
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
- 8. Update `design.md` with `Superpowers Technical Design Handoff`, update
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
- 9. Run:
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?
@@ -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. Branch/worktree status is handled and `.sdd/state.yaml` has:
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:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@chenmk/superflow",
3
- "version": "0.2.3",
3
+ "version": "0.2.5",
4
4
  "description": "SuperBridge Flow workflow CLI for Claude Code, Codex, and OpenCode",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -27,6 +27,7 @@
27
27
  },
28
28
  "files": [
29
29
  "dist",
30
+ "scripts",
30
31
  "assets",
31
32
  "README.md",
32
33
  "README.zh-CN.md",
@@ -36,6 +37,7 @@
36
37
  "scripts": {
37
38
  "build": "tsc",
38
39
  "dev": "tsx watch src/cli/index.ts",
40
+ "postinstall": "node scripts/postinstall.js",
39
41
  "prepack": "npm run build",
40
42
  "prepublishOnly": "npm test && npm run build",
41
43
  "test": "vitest run",
@@ -0,0 +1,56 @@
1
+ #!/usr/bin/env node
2
+ import { readFileSync } from 'fs';
3
+ import { fileURLToPath, pathToFileURL } from 'url';
4
+ import { dirname, join } from 'path';
5
+
6
+ const __filename = fileURLToPath(import.meta.url);
7
+ const __dirname = dirname(__filename);
8
+ const pkgPath = join(__dirname, '..', 'package.json');
9
+ const pkg = JSON.parse(readFileSync(pkgPath, 'utf-8'));
10
+
11
+ const LANGUAGE_ZH = 'zh';
12
+ const LANGUAGE_EN = 'en';
13
+
14
+ export function isGlobalInstall(env = process.env) {
15
+ return env.npm_config_global === 'true';
16
+ }
17
+
18
+ export function resolveInstallLanguage(env = process.env) {
19
+ const lang = env.SUPERFLOW_LANG || env.LC_ALL || env.LANG || '';
20
+ const normalized = lang.toLowerCase();
21
+ if (normalized.includes('zh') || normalized.includes('cn')) return LANGUAGE_ZH;
22
+ if (normalized.includes('en')) return LANGUAGE_EN;
23
+ return LANGUAGE_ZH;
24
+ }
25
+
26
+ export function buildInstallMessage(version, language) {
27
+ if (language === LANGUAGE_ZH) {
28
+ return [
29
+ `✅ @chenmk/superflow v${version} 安装成功`,
30
+ '',
31
+ ' 快速开始:',
32
+ ' superflow init # 在当前项目初始化',
33
+ ' superflow --help # 查看全部命令',
34
+ ].join('\n');
35
+ }
36
+ return [
37
+ `✅ @chenmk/superflow v${version} installed successfully`,
38
+ '',
39
+ ' Quick start:',
40
+ ' superflow init # Initialize in current project',
41
+ ' superflow --help # Show all commands',
42
+ ].join('\n');
43
+ }
44
+
45
+ function printInstallMessage(version, language) {
46
+ console.log(buildInstallMessage(version, language));
47
+ }
48
+
49
+ export function runPostinstall(env = process.env) {
50
+ if (!isGlobalInstall(env)) return;
51
+ printInstallMessage(pkg.version, resolveInstallLanguage(env));
52
+ }
53
+
54
+ if (import.meta.url === pathToFileURL(process.argv[1]).href) {
55
+ runPostinstall();
56
+ }