@hyperscale0/hsx 2.1.1 → 2.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (109) hide show
  1. package/CHANGELOG.md +28 -7
  2. package/dist/src/cli.d.ts +1 -1
  3. package/dist/src/cli.d.ts.map +1 -1
  4. package/dist/src/cli.js +39 -5
  5. package/dist/src/cli.js.map +1 -1
  6. package/dist/src/compile.d.ts +0 -1
  7. package/dist/src/compile.d.ts.map +1 -1
  8. package/dist/src/compile.js +15 -1
  9. package/dist/src/compile.js.map +1 -1
  10. package/dist/src/cost.d.ts +3 -3
  11. package/dist/src/cost.d.ts.map +1 -1
  12. package/dist/src/cost.js +22 -12
  13. package/dist/src/cost.js.map +1 -1
  14. package/dist/src/parse.d.ts.map +1 -1
  15. package/dist/src/parse.js +10 -14
  16. package/dist/src/parse.js.map +1 -1
  17. package/dist/src/std-bundle.d.ts.map +1 -1
  18. package/dist/src/std-bundle.js +20 -84
  19. package/dist/src/std-bundle.js.map +1 -1
  20. package/dist/src/typecheck.d.ts.map +1 -1
  21. package/dist/src/typecheck.js +171 -39
  22. package/dist/src/typecheck.js.map +1 -1
  23. package/dist/src/version.d.ts +1 -1
  24. package/dist/src/version.js +1 -1
  25. package/docs/README.md +4 -2
  26. package/docs/guide/01-first-program.md +1 -1
  27. package/docs/guide/06-schedules.md +5 -1
  28. package/docs/guide/08-writing-a-module.md +48 -0
  29. package/docs/llms-full.txt +1928 -421
  30. package/docs/llms.txt +2 -3
  31. package/docs/reference/cli.md +6 -5
  32. package/docs/reference/diagnostics.md +9 -9
  33. package/docs/reference/grammar.md +2 -3
  34. package/docs/reference/std/advance.md +94 -17
  35. package/docs/reference/std/cancellable_booking.md +138 -17
  36. package/docs/reference/std/captured_payment.md +96 -24
  37. package/docs/reference/std/conditional_disbursement.md +82 -14
  38. package/docs/reference/std/credit_facility.md +89 -16
  39. package/docs/reference/std/held_payment.md +155 -55
  40. package/docs/reference/std/instant_transfer.md +79 -12
  41. package/docs/reference/std/metered.md +71 -9
  42. package/docs/reference/std/pooled_split.md +76 -7
  43. package/docs/reference/std/premium_forward.md +100 -20
  44. package/docs/reference/std/reconciled_payout.md +84 -14
  45. package/docs/reference/std/rotating_pool.md +112 -24
  46. package/docs/reference/std/scheduled.md +117 -32
  47. package/docs/reference/std/security_deposit.md +119 -27
  48. package/docs/reference/std/settlement_batch.md +105 -24
  49. package/docs/reference/std/swap.md +113 -26
  50. package/docs/reference/std/threshold_pool.md +120 -29
  51. package/docs/reference/std/weighted_distribution.md +117 -21
  52. package/docs/reference/types.md +15 -15
  53. package/docs/reference/udl-output.md +6 -6
  54. package/examples/01-first-program/README.md +1 -1
  55. package/examples/{02-imports-and-archetypes → 02-imports-and-modules}/README.md +1 -1
  56. package/examples/{02-imports-and-archetypes → 02-imports-and-modules}/photo-booth.hsx +1 -1
  57. package/examples/04-complete-product/README.md +1 -1
  58. package/examples/05-authored-instrument/README.md +5 -0
  59. package/examples/05-authored-instrument/payment.hsx +37 -0
  60. package/examples/05-watch-club/watch-club.hsx +0 -1
  61. package/examples/README.md +1 -2
  62. package/examples/advance/advance.udl +29 -6
  63. package/examples/cancellable_booking/cancellable_booking.udl +19 -0
  64. package/examples/captured_payment/captured_payment.hsx +0 -4
  65. package/examples/captured_payment/captured_payment.udl +6 -0
  66. package/examples/conditional_disbursement/conditional_disbursement.hsx +0 -2
  67. package/examples/conditional_disbursement/conditional_disbursement.udl +4 -0
  68. package/examples/cost-table.json +136 -8
  69. package/examples/credit_facility/credit_facility.hsx +0 -3
  70. package/examples/credit_facility/credit_facility.udl +17 -1
  71. package/examples/held_payment/held_payment.udl +16 -0
  72. package/examples/instant_transfer/instant_transfer.udl +6 -0
  73. package/examples/metered/metered.udl +5 -1
  74. package/examples/pooled_split/pooled_split.udl +4 -0
  75. package/examples/premium_forward/premium_forward.udl +4 -0
  76. package/examples/reconciled_payout/reconciled_payout.udl +7 -0
  77. package/examples/rotating_pool/rotating_pool.udl +8 -0
  78. package/examples/scheduled/scheduled.udl +18 -3
  79. package/examples/security_deposit/security_deposit.udl +13 -0
  80. package/examples/settlement_batch/settlement_batch.udl +4 -0
  81. package/examples/swap/swap.udl +10 -0
  82. package/examples/threshold_pool/threshold_pool.udl +11 -0
  83. package/examples/weighted_distribution/weighted_distribution.udl +9 -0
  84. package/package.json +10 -10
  85. package/skills/hsx/SKILL.md +2 -36
  86. package/src/cli.ts +41 -5
  87. package/src/compile.ts +14 -6
  88. package/src/cost.ts +13 -16
  89. package/src/parse.ts +15 -10
  90. package/src/std-bundle.ts +21 -88
  91. package/src/typecheck.ts +207 -34
  92. package/src/version.ts +1 -1
  93. package/std/SEMANTICS.md +33 -128
  94. package/std/money_flows/advance.hsx +39 -26
  95. package/std/money_flows/cancellable_booking.hsx +275 -8
  96. package/std/money_flows/captured_payment.hsx +1 -9
  97. package/std/money_flows/conditional_disbursement.hsx +0 -6
  98. package/std/money_flows/credit_facility.hsx +0 -9
  99. package/std/money_flows/held_payment.hsx +39 -1
  100. package/std/money_flows/index.hsx +2 -1
  101. package/std/money_flows/metered.hsx +1 -5
  102. package/std/money_flows/scheduled.hsx +29 -119
  103. package/std/money_flows/threshold_pool.hsx +40 -5
  104. package/std/money_flows/weighted_distribution.hsx +47 -5
  105. package/docs/reference/std/recurring_collection.md +0 -25
  106. package/examples/recurring_collection/README.md +0 -3
  107. package/examples/recurring_collection/recurring_collection.hsx +0 -21
  108. package/examples/recurring_collection/recurring_collection.udl +0 -1135
  109. package/std/money_flows/recurring_collection.hsx +0 -72
@@ -1,4 +1,4 @@
1
- <!-- Generated by scripts/docs/build.ts for HSX 2.1.1. Do not edit. -->
1
+ <!-- Generated by scripts/docs/build.ts for HSX 2.2.0. Do not edit. -->
2
2
 
3
3
  # threshold_pool
4
4
 
@@ -10,20 +10,111 @@ Source: [`std/money_flows/threshold_pool.hsx`](../../../std/money_flows/threshol
10
10
 
11
11
  ## Parameters
12
12
 
13
- - `contributor: optional<party>`
14
- - `beneficiary: optional<party>`
15
- - `target: money<C>`
16
- - `commitment: money<C>`
17
- - `max_contributors: optional<integer>`
18
- - `close_by: date`
19
- - `close_policy: optional<text>`
20
- - `overfund_policy: optional<text>`
21
- - `cancel_policy: optional<text>`
22
- - `fail_policy: optional<text>`
23
- - `beneficiary_account: optional<account<C>>`
24
- - `memo: optional<text>`
25
- - `contribution_instrument: optional<block>`
26
- - `wording: optional<block>`
13
+ | Parameter | Type | Required | Meaning |
14
+ | --- | --- | --- | --- |
15
+ | `contributor` | `optional<party>` | No | The party representing individual contributors. |
16
+ | `beneficiary` | `optional<party>` | No | The beneficiary party receiving the settled pool if the target is met. |
17
+ | `target` | `money<C>` | Yes | Total target funding threshold in minor units of currency `C`. |
18
+ | `commitment` | `money<C>` | Yes | Binding name for individual contributor commitment amounts. |
19
+ | `max_contributors` | `optional<integer>` | No | Optional maximum count of admitted contributors. |
20
+ | `close_by` | `date` | Yes | Stored date deadline by which the target must be met. |
21
+ | `close_policy` | `optional<text>` | No | Policy determining pool close behavior (`threshold`). |
22
+ | `overfund_policy` | `optional<text>` | No | Policy on commitments exceeding the target (`reject`). |
23
+ | `cancel_policy` | `optional<text>` | No | Contributor withdrawal policy before close (`before_close`). |
24
+ | `fail_policy` | `optional<text>` | No | Refund policy if the pool fails to hit target (`whole_commitment_refund`). |
25
+ | `beneficiary_account` | `optional<account<C>>` | No | Optional direct account reference for the beneficiary. |
26
+ | `memo` | `optional<text>` | No | Optional memo text stored on the pool. |
27
+ | `contribution_instrument` | `optional<block>` | No | Optional custom contribution child instrument block. |
28
+ | `wording` | `optional<block>` | No | Optional custom UI wording block. |
29
+ | `funding_join` | `optional<block>` | No | funding_join configures the flat contribution-instrument mode for a priced obligation. |
30
+
31
+ Required means required by the template signature. A selected mode may also need parameters marked optional; the guidance below describes those combinations.
32
+
33
+ ## Module guidance
34
+
35
+ All-or-nothing capital accumulation pool collecting commitments toward a target amount before a close deadline.
36
+
37
+ ### Purpose
38
+
39
+ `threshold_pool` powers all-or-nothing crowdfunding, capital calls, collective purchasing, and consortium rounds.
40
+ Multiple contributors pledge commitments toward a monetary `target`. Commitments sit in escrow until the pool
41
+ reaches the target before `close_by` (activating and settling funds to the beneficiary), or fails (triggering full refunds).
42
+
43
+ ### Selection guidance
44
+
45
+ - vs `rotating_pool`: `threshold_pool` is all-or-nothing fundraising where many contributors fund a single beneficiary.
46
+ `rotating_pool` is a peer savings circle where members contribute identically in each cycle and rotate who receives the pot.
47
+ - vs `weighted_distribution`: `threshold_pool` pools funds inward from many contributors to one beneficiary.
48
+ `weighted_distribution` pays funds outward from one source pool to many weighted recipients.
49
+
50
+ ### Parameters
51
+
52
+ - `contributor`: The party representing individual contributors.
53
+ - `beneficiary`: The beneficiary party receiving the settled pool if the target is met.
54
+ - `target`: Total target funding threshold in minor units of currency `C`.
55
+ - `commitment`: Binding name for individual contributor commitment amounts.
56
+ - `max_contributors`: Optional maximum count of admitted contributors.
57
+ - `close_by`: Stored date deadline by which the target must be met.
58
+ - `close_policy`: Policy determining pool close behavior (`threshold`).
59
+ - `overfund_policy`: Policy on commitments exceeding the target (`reject`).
60
+ - `cancel_policy`: Contributor withdrawal policy before close (`before_close`).
61
+ - `fail_policy`: Refund policy if the pool fails to hit target (`whole_commitment_refund`).
62
+ - `beneficiary_account`: Optional direct account reference for the beneficiary.
63
+ - `memo`: Optional memo text stored on the pool.
64
+ - `contribution_instrument`: Optional custom contribution child instrument block.
65
+ - `wording`: Optional custom UI wording block.
66
+
67
+ ### Decision ports
68
+
69
+ None. Lifecycle transitions (`activate`, `fail`, `close`) are driven by target threshold evaluation and the `close_by` date.
70
+
71
+ ### Example
72
+
73
+ ```hsx
74
+ program capital_pool_example "Capital pool example"
75
+ import { threshold_pool } from "std/money_flows"
76
+ party contributor: person
77
+ party company: business
78
+ settlement round = threshold_pool {
79
+ contributor: contributor
80
+ beneficiary: company
81
+ target: targetAmount: money(SAR)
82
+ commitment: commitmentAmount: money(SAR)
83
+ max_contributors: 100
84
+ close_by: closeBy
85
+ close_policy: threshold
86
+ overfund_policy: reject
87
+ cancel_policy: before_close
88
+ fail_policy: whole_commitment_refund
89
+ }
90
+ ```
91
+
92
+ ### Funding join
93
+
94
+ funding_join configures the flat contribution-instrument mode for a priced
95
+ obligation. Opening freezes minimum ticket, investor cap, profit and schedule
96
+ terms. Closing binds the obligation, freezes committed ticket identities and
97
+ moves the principal once into its funding account. A ticket's engine-owned
98
+ collection action has no independent payment or clock trigger.
99
+
100
+ ## Declared clauses
101
+
102
+ - `agent description`
103
+ - `aggregate invariants`
104
+ - `caller parked states`
105
+ - `description`
106
+ - `due`
107
+ - `examples`
108
+ - `funding`
109
+ - `id prefix`
110
+ - `input`
111
+ - `moves`
112
+ - `steps`
113
+ - `summary`
114
+ - `title`
115
+ - `updates`
116
+
117
+ This inventory covers all branches and nested instruments in the module. The selected parameters determine which clauses and actions the compiler emits. Indexed action names expand over the declared finite list.
27
118
 
28
119
  ## Decision ports
29
120
 
@@ -31,17 +122,17 @@ None.
31
122
 
32
123
  ## Actions and clauses
33
124
 
34
- | Action | Clauses lowered |
35
- | ---------- | ------------------------------------------------- |
36
- | `create` | `agent description`, `moves`, `steps`, `summary` |
37
- | `activate` | `due`, `moves`, `steps`, `summary` |
38
- | `fail` | `due`, `moves`, `steps`, `summary` |
39
- | `close` | `agent description`, `moves`, `steps`, `summary` |
40
- | `create` | `agent description`, `moves`, `steps`, `summary` |
41
- | `cancel` | `agent description`, `moves`, `steps`, `summary` |
42
- | `collect` | `agent description`, `moves`, `steps`, `summary` |
43
- | `refund` | `agent description`, `moves`, `steps`, `summary` |
44
- | `create` | `agent description`, `examples`, `moves`, `steps` |
45
- | `activate` | `due`, `examples`, `moves`, `steps` |
46
- | `fail` | `due`, `examples`, `moves`, `steps` |
47
- | `close` | `agent description`, `examples`, `moves`, `steps` |
125
+ | Action | Clauses lowered |
126
+ | --- | --- |
127
+ | `create` | `agent description`, `moves`, `steps`, `summary` |
128
+ | `activate` | `due`, `moves`, `steps`, `summary` |
129
+ | `fail` | `due`, `moves`, `steps`, `summary` |
130
+ | `close` | `agent description`, `moves`, `steps`, `summary` |
131
+ | `create` | `agent description`, `moves`, `steps`, `summary` |
132
+ | `cancel` | `agent description`, `moves`, `steps`, `summary` |
133
+ | `collect` | `agent description`, `moves`, `steps`, `summary` |
134
+ | `refund` | `agent description`, `moves`, `steps`, `summary` |
135
+ | `create` | `agent description`, `examples`, `moves`, `steps` |
136
+ | `activate` | `due`, `examples`, `moves`, `steps` |
137
+ | `fail` | `due`, `examples`, `moves`, `steps` |
138
+ | `close` | `agent description`, `examples`, `funding`, `input`, `moves`, `steps`, `updates` |
@@ -1,4 +1,4 @@
1
- <!-- Generated by scripts/docs/build.ts for HSX 2.1.1. Do not edit. -->
1
+ <!-- Generated by scripts/docs/build.ts for HSX 2.2.0. Do not edit. -->
2
2
 
3
3
  # weighted_distribution
4
4
 
@@ -10,18 +10,113 @@ Source: [`std/money_flows/weighted_distribution.hsx`](../../../std/money_flows/w
10
10
 
11
11
  ## Parameters
12
12
 
13
- - `source: party`
14
- - `recipient: party`
15
- - `amount: money<C>`
16
- - `record_at: date`
17
- - `weight: optional<money<C>>`
18
- - `max_recipients: optional<integer>`
19
- - `snapshot: optional<condition>`
20
- - `rounding_policy: optional<text>`
21
- - `withholding_policy: optional<text>`
22
- - `correction_policy: optional<text>`
23
- - `flat: optional<block>`
24
- - `id_prefix_override: optional<text>`
13
+ | Parameter | Type | Required | Meaning |
14
+ | --- | --- | --- | --- |
15
+ | `source` | `optional<party>` | No | The funding party providing the distribution pool. |
16
+ | `recipient` | `optional<party>` | No | The party representing entitled recipients. |
17
+ | `amount` | `optional<money<C>>` | No | Total distribution pool in minor units of currency `C`. |
18
+ | `record_at` | `optional<date>` | No | Date when entitlement eligibility is established. |
19
+ | `weight` | `optional<money<C>>` | No | Binding name for individual recipient weight amounts. |
20
+ | `max_recipients` | `optional<integer>` | No | Exact number of entitlement rows required before snapshotting. |
21
+ | `snapshot` | `optional<condition>` | No | Port freezing the entitlement set against stored decision evidence. |
22
+ | `rounding_policy` | `optional<text>` | No | Mathematical rounding policy (`largest_remainder`). |
23
+ | `withholding_policy` | `optional<text>` | No | Tax or withholding policy (`refuse`). |
24
+ | `correction_policy` | `optional<text>` | No | Error correction policy (`new_distribution`). |
25
+ | `flat` | `optional<block>` | No | Optional flat distribution configuration block. |
26
+ | `receipts` | `optional<block>` | No | receipts selects repeated distributions from immutable allocation receipts. |
27
+ | `id_prefix_override` | `optional<text>` | No | Optional custom prefix for generated instrument IDs. |
28
+
29
+ Required means required by the template signature. A selected mode may also need parameters marked optional; the guidance below describes those combinations.
30
+
31
+ ## Module guidance
32
+
33
+ Frozen largest-remainder distribution splitting one pool across dynamic recipients by recorded weights.
34
+
35
+ ### Purpose
36
+
37
+ `weighted_distribution` distributes dividend pools, creator royalties, liquidation proceeds, and investment returns.
38
+ Child entitlement rows are recorded for each recipient with their respective weight. Once all recipients are recorded,
39
+ an evidence-backed snapshot freezes the entitlement set. Each recipient is then paid their exact largest-remainder
40
+ share such that all payouts sum exactly to `amount` without rounding leaks.
41
+
42
+ ### Selection guidance
43
+
44
+ - vs `pooled_split`: `weighted_distribution` handles dynamic recipient rosters recorded as child rows and frozen
45
+ via snapshot. `pooled_split` hardcodes a fixed set of recipients and static percentages at definition time.
46
+ - vs `settlement_batch`: `weighted_distribution` splits one funding pool out to many recipients.
47
+ `settlement_batch` aggregates many inbound charges and adjustments into a single net payout.
48
+
49
+ ### Parameters
50
+
51
+ - `source`: The funding party providing the distribution pool.
52
+ - `recipient`: The party representing entitled recipients.
53
+ - `amount`: Total distribution pool in minor units of currency `C`.
54
+ - `record_at`: Date when entitlement eligibility is established.
55
+ - `weight`: Binding name for individual recipient weight amounts.
56
+ - `max_recipients`: Exact number of entitlement rows required before snapshotting.
57
+ - `snapshot`: Port freezing the entitlement set against stored decision evidence.
58
+ - `rounding_policy`: Mathematical rounding policy (`largest_remainder`).
59
+ - `withholding_policy`: Tax or withholding policy (`refuse`).
60
+ - `correction_policy`: Error correction policy (`new_distribution`).
61
+ - `flat`: Optional flat distribution configuration block.
62
+ - `id_prefix_override`: Optional custom prefix for generated instrument IDs.
63
+
64
+ ### Decision ports
65
+
66
+ - `snapshot`: Port freezing the entitlement set with an evidence reference, preventing further entries.
67
+
68
+ ### Example
69
+
70
+ ```hsx
71
+ program weighted_distribution_example "Weighted distribution example"
72
+ import { weighted_distribution } from "std/money_flows"
73
+ party distribution_source: business
74
+ party recipient: business
75
+ settlement proceeds = weighted_distribution {
76
+ source: distribution_source
77
+ recipient: recipient
78
+ amount: distributableAmount: money(SAR)
79
+ weight: entitlementWeight: money(SAR)
80
+ max_recipients: 12
81
+ record_at: recordAt
82
+ snapshot: port snapshot_entitlements
83
+ rounding_policy: largest_remainder
84
+ withholding_policy: refuse
85
+ correction_policy: new_distribution
86
+ }
87
+ port snapshot_entitlements {
88
+ allowed: [distribution_source]
89
+ shape: { evidenceReference: text }
90
+ }
91
+ ```
92
+
93
+ ### Receipt-backed distributions
94
+
95
+ receipts selects repeated distributions from immutable allocation receipts.
96
+ It names round, receipt, path, mode (cash or loss), fee_bps and vat_bps.
97
+ The funding snapshot owns ticket weights and original wallet destinations.
98
+ Cash floors each ratio after fee and fee VAT; a named account receives residual.
99
+ Loss assigns principal by largest remainder without cash, fee or VAT.
100
+ Each receipt is consumed once; a new receipt may fund a new distribution record.
101
+ This mode does not use caller-entered weights or a once-only settled principal pool.
102
+
103
+ ## Declared clauses
104
+
105
+ - `agent description`
106
+ - `aggregate invariants`
107
+ - `capture input`
108
+ - `description`
109
+ - `due`
110
+ - `id prefix`
111
+ - `input`
112
+ - `moves`
113
+ - `port`
114
+ - `requires refs`
115
+ - `steps`
116
+ - `summary`
117
+ - `title`
118
+
119
+ This inventory covers all branches and nested instruments in the module. The selected parameters determine which clauses and actions the compiler emits. Indexed action names expand over the declared finite list.
25
120
 
26
121
  ## Decision ports
27
122
 
@@ -29,11 +124,12 @@ Source: [`std/money_flows/weighted_distribution.hsx`](../../../std/money_flows/w
29
124
 
30
125
  ## Actions and clauses
31
126
 
32
- | Action | Clauses lowered |
33
- | ---------- | ------------------------------------------------------------------------------------------------- |
34
- | `create` | `agent description`, `moves`, `steps`, `summary` |
35
- | `snapshot` | `agent description`, `capture input`, `description`, `input`, `moves`, `port`, `steps`, `summary` |
36
- | `create` | `agent description`, `moves`, `steps`, `summary` |
37
- | `payout` | `agent description`, `computes distribute`, `moves`, `steps`, `summary` |
38
- | `create` | `agent description`, `moves`, `requires refs`, `steps`, `summary` |
39
- | `payout` | `computes distribute`, `due`, `moves`, `steps`, `summary` |
127
+ | Action | Clauses lowered |
128
+ | --- | --- |
129
+ | `create` | `agent description`, `moves`, `steps`, `summary` |
130
+ | `[snapshot]` | `agent description`, `capture input`, `description`, `input`, `moves`, `port`, `steps`, `summary` |
131
+ | `create` | `agent description`, `moves`, `steps`, `summary` |
132
+ | `payout` | `agent description`, `moves`, `steps`, `summary` |
133
+ | `create` | `agent description`, `moves`, `requires refs`, `steps`, `summary` |
134
+ | `payout` | `due`, `moves`, `steps`, `summary` |
135
+ | `create` | `agent description`, `steps` |
@@ -1,20 +1,20 @@
1
- <!-- Generated by scripts/docs/build.ts for HSX 2.1.1. Do not edit. -->
1
+ <!-- Generated by scripts/docs/build.ts for HSX 2.2.0. Do not edit. -->
2
2
 
3
3
  # Types
4
4
 
5
5
  HSX checks types before it emits UDL. Money and account values carry a currency parameter, and no implicit currency conversion exists.
6
6
 
7
- | Kind | Meaning |
8
- | ----------- | -------------------------------------------------------------------- |
9
- | `account` | A currency-indexed ledger account reference. |
10
- | `boolean` | A compile-time or stored true or false value. |
11
- | `bps` | An integer basis-point value. |
12
- | `condition` | A declared decision port. |
13
- | `date` | A stored date-time string checked by UDL. |
14
- | `integer` | A bounded whole number. |
15
- | `money` | A currency-indexed minor-unit amount. |
16
- | `party` | A declared program party. |
17
- | `percent` | An exact percentage with basis-point precision. |
18
- | `ref` | A typed reference to another instrument. |
19
- | `text` | A finite string value. |
20
- | `unknown` | An internal checker result that source must resolve before lowering. |
7
+ | Kind | Meaning |
8
+ | --- | --- |
9
+ | `account` | A currency-indexed ledger account reference. |
10
+ | `boolean` | A compile-time or stored true or false value. |
11
+ | `bps` | An integer basis-point value. |
12
+ | `condition` | A declared decision port. |
13
+ | `date` | A stored date-time string checked by UDL. |
14
+ | `integer` | A bounded whole number. |
15
+ | `money` | A currency-indexed minor-unit amount. |
16
+ | `party` | A declared program party. |
17
+ | `percent` | An exact percentage with basis-point precision. |
18
+ | `ref` | A typed reference to another instrument. |
19
+ | `text` | A finite string value. |
20
+ | `unknown` | An internal checker result that source must resolve before lowering. |
@@ -1,13 +1,13 @@
1
- <!-- Generated by scripts/docs/build.ts for HSX 2.1.1. Do not edit. -->
1
+ <!-- Generated by scripts/docs/build.ts for HSX 2.2.0. Do not edit. -->
2
2
 
3
3
  # UDL output
4
4
 
5
5
  An accepted compile returns three artifacts.
6
6
 
7
- | Artifact | Contents |
8
- | -------------- | ----------------------------------------------------------------------------------- |
9
- | `document` | The canonical UDL object. Serialize it with `serializeUdl` from `@hyperscale0/udl`. |
10
- | `originMap` | Canonical UDL paths mapped to authored HSX spans. |
11
- | `costManifest` | The deterministic manifest pinned to the supplied rate card. |
7
+ | Artifact | Contents |
8
+ | --- | --- |
9
+ | `document` | The canonical UDL object. Serialize it with `serializeUdl` from `@hyperscale0/udl`. |
10
+ | `originMap` | Canonical UDL paths mapped to authored HSX spans. |
11
+ | `costManifest` | The deterministic manifest pinned to the supplied rate card. |
12
12
 
13
13
  Canonical UDL sorts object keys, preserves array order, uses two-space JSON indentation, and ends with one line feed.
@@ -27,7 +27,7 @@ payee, and both must be declared parties.
27
27
  `payee` name declared parties; `amount: tipAmount: money(SAR)` declares a
28
28
  field the instance stores, called `tipAmount`, holding an amount in SAR.
29
29
 
30
- That doubled colon reads oddly the first time. The archetype's parameter is
30
+ That doubled colon reads oddly the first time. The module's parameter is
31
31
  `amount`; its value is a typed binding, `tipAmount: money(SAR)`, which names
32
32
  the field AND its type. You choose the field name because it shows up in the
33
33
  generated API, and `amount` is HSX's word, not your product's.
@@ -1,4 +1,4 @@
1
- # 2 · Imports, settlement bricks, and the port
1
+ # 2 · Imports, modules, and the port
2
2
 
3
3
  [`photo-booth.hsx`](./photo-booth.hsx) is a photo-booth rental company. The
4
4
  renter pays up front, but the money does not reach the company until the booth
@@ -1,4 +1,4 @@
1
- // Imports, archetypes, and the decision port.
1
+ // Imports, modules, and the decision port.
2
2
  //
3
3
  // A photo-booth rental company. The renter pays up front, but the money sits
4
4
  // in escrow until the booth is delivered. The company's own backend answers
@@ -59,7 +59,7 @@ share does. Nobody's fraction of a halala goes missing, and nobody's is
59
59
  invented.
60
60
 
61
61
  A pool needs at least two recipients, and the funder cannot be one of them. A
62
- pool that distributes to one person is a transfer, and there is an archetype
62
+ pool that distributes to one person is a transfer, and there is an module
63
63
  for that.
64
64
 
65
65
  ## What it compiles to
@@ -0,0 +1,5 @@
1
+ # Authored payment
2
+
3
+ `payment.hsx` declares a payment with a bound internal transfer. The [module guide](../../docs/guide/08-writing-a-module.md#an-authored-action-that-moves-money) contains the same program. The docs builder compares the bytes and compiles it with the packaged cost table.
4
+
5
+ From the full repository root, run `bun open/hsx/bin/hsx.ts check open/hsx/examples/05-authored-instrument/payment.hsx`.
@@ -0,0 +1,37 @@
1
+ program authored_payment "Authored payment"
2
+
3
+ instrument payment {
4
+ agent_description: "Collect a stored payment once from its payer."
5
+ title: "Payment"
6
+ summary: "A payment with fixed payer and payee accounts"
7
+ fields {
8
+ payerAccountId: account<SAR>;
9
+ payeeAccountId: account<SAR>;
10
+ amount: money<SAR>;
11
+ }
12
+ parties { payer: payerAccountId; beneficiary: payeeAccountId; }
13
+ lifecycle {
14
+ states pending paid;
15
+ initial pending;
16
+ on pay: pending -> paid;
17
+ }
18
+ action create {
19
+ agent_description: "Open a pending payment without moving money."
20
+ steps: [];
21
+ moves: [];
22
+ }
23
+ action pay {
24
+ agent_description: "Move the stored amount from payer to payee."
25
+ steps: [];
26
+ moves: [{
27
+ bind: {
28
+ amount: { from: "instance", path: "fields.amount" }
29
+ currency: { from: "const", value: "SAR" }
30
+ sourceAccountId: { from: "instance", path: "fields.payerAccountId" }
31
+ destinationAccountId: { from: "instance", path: "fields.payeeAccountId" }
32
+ }
33
+ key: "payment_transfer"
34
+ operation: "internal_transfer.create"
35
+ }];
36
+ }
37
+ }
@@ -7,7 +7,6 @@ program watch_club "Watch club"
7
7
  import {
8
8
  security_deposit,
9
9
  instant_transfer,
10
- recurring_collection,
11
10
  scheduled,
12
11
  settlement_batch,
13
12
  swap
@@ -8,7 +8,7 @@ document byte for byte.
8
8
  The numbered examples provide end-to-end walkthroughs:
9
9
 
10
10
  - [01 · Your first program](01-first-program/README.md)
11
- - [02 · Imports and modules](02-imports-and-archetypes/README.md)
11
+ - [02 · Imports and modules](02-imports-and-modules/README.md)
12
12
  - [03 · Diagnostics](03-diagnostics/README.md)
13
13
  - [04 · Complete product](04-complete-product/README.md)
14
14
  - [05 · Watch club](05-watch-club/README.md)
@@ -28,7 +28,6 @@ Each money flow has a runnable example directory:
28
28
  - [pooled_split](pooled_split/README.md)
29
29
  - [premium_forward](premium_forward/README.md)
30
30
  - [reconciled_payout](reconciled_payout/README.md)
31
- - [recurring_collection](recurring_collection/README.md)
32
31
  - [rotating_pool](rotating_pool/README.md)
33
32
  - [scheduled](scheduled/README.md)
34
33
  - [security_deposit](security_deposit/README.md)
@@ -9,8 +9,10 @@
9
9
  ],
10
10
  "actions": {
11
11
  "collect_repayment_1": {
12
+ "agentDescription": "Collect repayment 1 once on its stored due anchor, returning principal to the funder and any separately routed profit to its recipient.",
12
13
  "due": {
13
- "field": "firstDueAt"
14
+ "field": "firstDueAt",
15
+ "offset": "P0D"
14
16
  },
15
17
  "effects": {
16
18
  "moves": [
@@ -73,6 +75,7 @@
73
75
  "summary": "Collect repayment 1 of 2"
74
76
  },
75
77
  "collect_repayment_2": {
78
+ "agentDescription": "Collect repayment 2 once on its stored due anchor, returning principal to the funder and any separately routed profit to its recipient.",
76
79
  "due": {
77
80
  "field": "firstDueAt",
78
81
  "offset": "P30D"
@@ -138,7 +141,7 @@
138
141
  "summary": "Collect repayment 2 of 2"
139
142
  },
140
143
  "create": {
141
- "agentDescription": "Open the advance row before any money moves. The caller supplies the principal, the fee amount, the repayable total, and the first repayment date. The repayment fields must partition the repayable total exactly. Nothing is disbursed here.",
144
+ "agentDescription": "Open the advance row before any money moves. The caller supplies the principal, the repayable total, and repayment dates. A declared fee derives the fee amount from principal. The repayment fields must partition the repayable total exactly. Nothing is disbursed here.",
142
145
  "moves": [],
143
146
  "publicAction": "createAdvancePayment",
144
147
  "steps": [],
@@ -203,6 +206,17 @@
203
206
  }
204
207
  },
205
208
  "agentDescription": "Reach for advance when the funder pays the recipient up front and is repaid afterwards, either out of a carved hold release or over scheduled repayments. Pick deposit for a refundable reservation and instant transfer when nobody repays the payer.",
209
+ "derivedAmounts": [
210
+ {
211
+ "field": "feeAmount",
212
+ "rounding": "floor",
213
+ "rule": {
214
+ "bps": 250,
215
+ "kind": "percentage_of"
216
+ },
217
+ "sourceField": "principal"
218
+ }
219
+ ],
206
220
  "description": "Advance: the funder disburses principal to the recipient, repaid over 2 scheduled repayments plus the funder's discount",
207
221
  "fields": {
208
222
  "currency": {
@@ -214,7 +228,7 @@
214
228
  },
215
229
  "feeAmount": {
216
230
  "description": "2.5% of principal, the funder's discount repaid on top of the advance",
217
- "pattern": "^[1-9][0-9]{0,17}$",
231
+ "pattern": "^(0|[1-9][0-9]{0,17})$",
218
232
  "type": "string",
219
233
  "x-hyperscale-currency": "SAR"
220
234
  },
@@ -258,13 +272,13 @@
258
272
  "x-hyperscale-currency": "SAR"
259
273
  },
260
274
  "repayment1Amount": {
261
- "description": "Repayment 1 of 2 (carries the integer-division remainder): about 33.34% of repayableAmount, collected on its own stored-date anchor",
275
+ "description": "Stored total for repayment 1",
262
276
  "pattern": "^[1-9][0-9]{0,17}$",
263
277
  "type": "string",
264
278
  "x-hyperscale-currency": "SAR"
265
279
  },
266
280
  "repayment2Amount": {
267
- "description": "Repayment 2 of 2: about 33.33% of repayableAmount, collected on its own stored-date anchor",
281
+ "description": "Stored total for repayment 2",
268
282
  "pattern": "^[1-9][0-9]{0,17}$",
269
283
  "type": "string",
270
284
  "x-hyperscale-currency": "SAR"
@@ -325,7 +339,6 @@
325
339
  "funderAccountId",
326
340
  "recipientAccountId",
327
341
  "principal",
328
- "feeAmount",
329
342
  "repayableAmount",
330
343
  "firstDueAt",
331
344
  "repayment1Amount",
@@ -333,6 +346,16 @@
333
346
  "currency"
334
347
  ],
335
348
  "summary": "Advance to recipient repaid over 2 anchors",
349
+ "templateBinding": {
350
+ "id": "advance",
351
+ "parameters": {
352
+ "against": false,
353
+ "count": 2,
354
+ "dated": false,
355
+ "profitTo": false,
356
+ "repaymentSource": false
357
+ }
358
+ },
336
359
  "title": "Advance payment"
337
360
  }
338
361
  ],
@@ -382,6 +382,25 @@
382
382
  "startsAt"
383
383
  ],
384
384
  "summary": "Booking the guest can cancel at a price they see before they agree to it",
385
+ "templateBinding": {
386
+ "id": "cancellable_booking",
387
+ "parameters": {
388
+ "acceptance": false,
389
+ "authorityType": false,
390
+ "balanceBefore": false,
391
+ "cancelBands": false,
392
+ "confirmationWindow": false,
393
+ "departure": false,
394
+ "depositBps": false,
395
+ "earlyPenaltyBps": 1000,
396
+ "latePenaltyBps": 5000,
397
+ "priceValue": false,
398
+ "supplierCost": false,
399
+ "supplierRole": false,
400
+ "taxBps": false,
401
+ "unpaidBand": false
402
+ }
403
+ },
385
404
  "title": "Studio session"
386
405
  }
387
406
  ],
@@ -9,10 +9,6 @@ settlement card_payment = captured_payment {
9
9
  reserve_until: reserveUntil
10
10
  correction: port correct_capture
11
11
  external_reversal: port reverse_capture within P14D
12
- capture_mode: partial_then_full
13
- correction_mode: full_only
14
- negative_position: reject
15
- timeout: reject
16
12
  }
17
13
  port correct_capture { allowed: [payee] }
18
14
  port reverse_capture {
@@ -669,6 +669,12 @@
669
669
  "currency"
670
670
  ],
671
671
  "summary": "Capture reservation from payer to payee",
672
+ "templateBinding": {
673
+ "id": "captured_payment",
674
+ "parameters": {
675
+ "derivedAmount": false
676
+ }
677
+ },
672
678
  "title": "Card payment"
673
679
  }
674
680
  ],
@@ -8,8 +8,6 @@ settlement claim_payment = conditional_disbursement {
8
8
  cap: policyLimit: money(SAR)
9
9
  amount: approvedAmount: money(SAR)
10
10
  decision: port approve_claim
11
- reopen_policy: refuse
12
- recovery_policy: separate_transfer
13
11
  }
14
12
  port approve_claim {
15
13
  allowed: [source]
@@ -138,6 +138,10 @@
138
138
  "policyLimit"
139
139
  ],
140
140
  "summary": "Capped disbursement to claimant",
141
+ "templateBinding": {
142
+ "id": "conditional_disbursement",
143
+ "parameters": {}
144
+ },
141
145
  "title": "Claim payment"
142
146
  },
143
147
  {