@hyperscale0/hsx 1.0.0-beta.1 → 1.0.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 (255) hide show
  1. package/CHANGELOG.md +58 -9
  2. package/LICENSING.md +3 -3
  3. package/README.md +39 -149
  4. package/TRADEMARKS.md +4 -4
  5. package/bin/hsx.ts +2 -0
  6. package/dist/bin/hsx.js +2 -0
  7. package/dist/bin/hsx.js.map +1 -1
  8. package/dist/src/ast.d.ts +135 -10
  9. package/dist/src/ast.d.ts.map +1 -1
  10. package/dist/src/ast.js +24 -0
  11. package/dist/src/ast.js.map +1 -1
  12. package/dist/src/cli.d.ts +4 -1
  13. package/dist/src/cli.d.ts.map +1 -1
  14. package/dist/src/cli.js +172 -16
  15. package/dist/src/cli.js.map +1 -1
  16. package/dist/src/compile.d.ts +42 -7
  17. package/dist/src/compile.d.ts.map +1 -1
  18. package/dist/src/compile.js +82 -16
  19. package/dist/src/compile.js.map +1 -1
  20. package/dist/src/cost.d.ts +78 -0
  21. package/dist/src/cost.d.ts.map +1 -0
  22. package/dist/src/cost.js +369 -0
  23. package/dist/src/cost.js.map +1 -0
  24. package/dist/src/diagnostics.d.ts +11 -0
  25. package/dist/src/diagnostics.d.ts.map +1 -0
  26. package/dist/src/diagnostics.js +420 -0
  27. package/dist/src/diagnostics.js.map +1 -0
  28. package/dist/src/emit.d.ts +34 -0
  29. package/dist/src/emit.d.ts.map +1 -0
  30. package/dist/src/emit.js +137 -0
  31. package/dist/src/emit.js.map +1 -0
  32. package/dist/src/entry-overrides.d.ts +17 -3
  33. package/dist/src/entry-overrides.d.ts.map +1 -1
  34. package/dist/src/entry-overrides.js +180 -35
  35. package/dist/src/entry-overrides.js.map +1 -1
  36. package/dist/src/format.d.ts +10 -0
  37. package/dist/src/format.d.ts.map +1 -0
  38. package/dist/src/format.js +183 -0
  39. package/dist/src/format.js.map +1 -0
  40. package/dist/src/index.d.ts +11 -4
  41. package/dist/src/index.d.ts.map +1 -1
  42. package/dist/src/index.js +10 -3
  43. package/dist/src/index.js.map +1 -1
  44. package/dist/src/ir.d.ts +66 -0
  45. package/dist/src/ir.d.ts.map +1 -0
  46. package/dist/src/ir.js +15 -0
  47. package/dist/src/ir.js.map +1 -0
  48. package/dist/src/lex.d.ts +9 -1
  49. package/dist/src/lex.d.ts.map +1 -1
  50. package/dist/src/lex.js +50 -4
  51. package/dist/src/lex.js.map +1 -1
  52. package/dist/src/limits.d.ts +2 -3
  53. package/dist/src/limits.d.ts.map +1 -1
  54. package/dist/src/limits.js +2 -3
  55. package/dist/src/limits.js.map +1 -1
  56. package/dist/src/lsp/server.d.ts +32 -0
  57. package/dist/src/lsp/server.d.ts.map +1 -0
  58. package/dist/src/lsp/server.js +391 -0
  59. package/dist/src/lsp/server.js.map +1 -0
  60. package/dist/src/modules.d.ts +38 -0
  61. package/dist/src/modules.d.ts.map +1 -0
  62. package/dist/src/modules.js +368 -0
  63. package/dist/src/modules.js.map +1 -0
  64. package/dist/src/parse.d.ts.map +1 -1
  65. package/dist/src/parse.js +590 -17
  66. package/dist/src/parse.js.map +1 -1
  67. package/dist/src/std-bundle.d.ts +2 -0
  68. package/dist/src/std-bundle.d.ts.map +1 -0
  69. package/dist/src/std-bundle.js +88 -0
  70. package/dist/src/std-bundle.js.map +1 -0
  71. package/dist/src/std-library.d.ts +5 -0
  72. package/dist/src/std-library.d.ts.map +1 -0
  73. package/dist/src/std-library.js +9 -0
  74. package/dist/src/std-library.js.map +1 -0
  75. package/dist/src/typecheck.d.ts +8 -0
  76. package/dist/src/typecheck.d.ts.map +1 -0
  77. package/dist/src/typecheck.js +2958 -0
  78. package/dist/src/typecheck.js.map +1 -0
  79. package/dist/src/version.d.ts +4 -15
  80. package/dist/src/version.d.ts.map +1 -1
  81. package/dist/src/version.js +4 -15
  82. package/dist/src/version.js.map +1 -1
  83. package/docs/README.md +26 -0
  84. package/docs/guide/01-first-program.md +24 -0
  85. package/docs/guide/02-money.md +25 -0
  86. package/docs/guide/03-instruments.md +22 -0
  87. package/docs/guide/04-lifecycles.md +25 -0
  88. package/docs/guide/05-fees-and-splits.md +45 -0
  89. package/docs/guide/06-schedules.md +22 -0
  90. package/docs/guide/07-composition.md +46 -0
  91. package/docs/guide/08-writing-a-module.md +26 -0
  92. package/docs/guide/09-cost.md +24 -0
  93. package/docs/guide/10-diagnostics.md +27 -0
  94. package/docs/llms-full.txt +1739 -0
  95. package/docs/llms.txt +45 -0
  96. package/docs/playground.md +54 -0
  97. package/docs/reference/cli.md +35 -0
  98. package/docs/reference/diagnostics.md +619 -0
  99. package/docs/reference/grammar.md +39 -0
  100. package/docs/reference/std/advance.md +35 -0
  101. package/docs/reference/std/cancellable_booking.md +35 -0
  102. package/docs/reference/std/captured_payment.md +43 -0
  103. package/docs/reference/std/conditional_disbursement.md +33 -0
  104. package/docs/reference/std/credit_facility.md +35 -0
  105. package/docs/reference/std/held_payment.md +64 -0
  106. package/docs/reference/std/instant_transfer.md +30 -0
  107. package/docs/reference/std/metered.md +27 -0
  108. package/docs/reference/std/pooled_split.md +26 -0
  109. package/docs/reference/std/premium_forward.md +39 -0
  110. package/docs/reference/std/reconciled_payout.md +33 -0
  111. package/docs/reference/std/recurring_collection.md +25 -0
  112. package/docs/reference/std/rotating_pool.md +42 -0
  113. package/docs/reference/std/scheduled.md +51 -0
  114. package/docs/reference/std/security_deposit.md +46 -0
  115. package/docs/reference/std/settlement_batch.md +42 -0
  116. package/docs/reference/std/swap.md +46 -0
  117. package/docs/reference/std/threshold_pool.md +47 -0
  118. package/docs/reference/std/weighted_distribution.md +39 -0
  119. package/docs/reference/types.md +20 -0
  120. package/docs/reference/udl-output.md +13 -0
  121. package/docs/sessions/2026-09-02-two-instruments.hsx +21 -0
  122. package/docs/sessions/2026-09-02-two-instruments.md +41 -0
  123. package/examples/01-first-program/README.md +45 -0
  124. package/examples/01-first-program/tip-jar.hsx +17 -0
  125. package/examples/02-imports-and-archetypes/README.md +96 -0
  126. package/examples/02-imports-and-archetypes/photo-booth.hsx +37 -0
  127. package/examples/03-diagnostics/README.md +68 -0
  128. package/examples/03-diagnostics/corner-shop-fixed.hsx +22 -0
  129. package/examples/03-diagnostics/corner-shop.hsx +19 -0
  130. package/examples/04-complete-product/README.md +84 -0
  131. package/examples/04-complete-product/study-hall.hsx +67 -0
  132. package/examples/05-watch-club/README.md +9 -0
  133. package/examples/05-watch-club/watch-club.hsx +124 -0
  134. package/examples/README.md +18 -0
  135. package/examples/advance/README.md +3 -0
  136. package/examples/advance/advance.hsx +13 -0
  137. package/examples/advance/advance.udl +339 -0
  138. package/examples/cancellable_booking/README.md +3 -0
  139. package/examples/cancellable_booking/cancellable_booking.hsx +14 -0
  140. package/examples/cancellable_booking/cancellable_booking.udl +391 -0
  141. package/examples/captured_payment/README.md +3 -0
  142. package/examples/captured_payment/captured_payment.hsx +21 -0
  143. package/examples/captured_payment/captured_payment.udl +677 -0
  144. package/examples/conditional_disbursement/README.md +3 -0
  145. package/examples/conditional_disbursement/conditional_disbursement.hsx +17 -0
  146. package/examples/conditional_disbursement/conditional_disbursement.udl +412 -0
  147. package/examples/cost-table.json +386 -0
  148. package/examples/credit_facility/README.md +3 -0
  149. package/examples/credit_facility/credit_facility.hsx +27 -0
  150. package/examples/credit_facility/credit_facility.udl +1373 -0
  151. package/examples/held_payment/README.md +3 -0
  152. package/examples/held_payment/held_payment.hsx +13 -0
  153. package/examples/held_payment/held_payment.udl +507 -0
  154. package/examples/instant_transfer/README.md +3 -0
  155. package/examples/instant_transfer/instant_transfer.hsx +16 -0
  156. package/examples/instant_transfer/instant_transfer.udl +364 -0
  157. package/examples/metered/README.md +3 -0
  158. package/examples/metered/metered.hsx +13 -0
  159. package/examples/metered/metered.udl +247 -0
  160. package/examples/pooled_split/README.md +3 -0
  161. package/examples/pooled_split/pooled_split.hsx +15 -0
  162. package/examples/pooled_split/pooled_split.udl +425 -0
  163. package/examples/premium_forward/README.md +3 -0
  164. package/examples/premium_forward/premium_forward.hsx +19 -0
  165. package/examples/premium_forward/premium_forward.udl +594 -0
  166. package/examples/reconciled_payout/README.md +3 -0
  167. package/examples/reconciled_payout/reconciled_payout.hsx +13 -0
  168. package/examples/reconciled_payout/reconciled_payout.udl +303 -0
  169. package/examples/recurring_collection/README.md +3 -0
  170. package/examples/recurring_collection/recurring_collection.hsx +21 -0
  171. package/examples/recurring_collection/recurring_collection.udl +1130 -0
  172. package/examples/rotating_pool/README.md +3 -0
  173. package/examples/rotating_pool/rotating_pool.hsx +18 -0
  174. package/examples/rotating_pool/rotating_pool.udl +4352 -0
  175. package/examples/scheduled/README.md +3 -0
  176. package/examples/scheduled/scheduled.hsx +12 -0
  177. package/examples/scheduled/scheduled.udl +335 -0
  178. package/examples/security_deposit/README.md +3 -0
  179. package/examples/security_deposit/security_deposit.hsx +21 -0
  180. package/examples/security_deposit/security_deposit.udl +293 -0
  181. package/examples/settlement_batch/README.md +3 -0
  182. package/examples/settlement_batch/settlement_batch.hsx +19 -0
  183. package/examples/settlement_batch/settlement_batch.udl +753 -0
  184. package/examples/swap/README.md +3 -0
  185. package/examples/swap/swap.hsx +19 -0
  186. package/examples/swap/swap.udl +876 -0
  187. package/examples/threshold_pool/README.md +3 -0
  188. package/examples/threshold_pool/threshold_pool.hsx +16 -0
  189. package/examples/threshold_pool/threshold_pool.udl +667 -0
  190. package/examples/weighted_distribution/README.md +3 -0
  191. package/examples/weighted_distribution/weighted_distribution.hsx +20 -0
  192. package/examples/weighted_distribution/weighted_distribution.udl +337 -0
  193. package/package.json +27 -6
  194. package/skills/hsx/SKILL.md +483 -0
  195. package/src/ast.ts +193 -9
  196. package/src/cli.ts +191 -20
  197. package/src/compile.ts +160 -23
  198. package/src/cost.ts +579 -0
  199. package/src/diagnostics.ts +442 -0
  200. package/src/emit.ts +201 -0
  201. package/src/entry-overrides.ts +263 -48
  202. package/src/format.ts +261 -0
  203. package/src/index.ts +34 -4
  204. package/src/ir.ts +99 -0
  205. package/src/lex.ts +59 -4
  206. package/src/limits.ts +2 -3
  207. package/src/lsp/server.ts +460 -0
  208. package/src/modules.ts +446 -0
  209. package/src/parse.ts +655 -21
  210. package/src/std-bundle.ts +91 -0
  211. package/src/std-library.ts +12 -0
  212. package/src/typecheck.ts +3876 -0
  213. package/src/version.ts +4 -16
  214. package/std/SEMANTICS.md +130 -0
  215. package/std/settlements/advance.hsx +177 -0
  216. package/std/settlements/cancellable_booking.hsx +87 -0
  217. package/std/settlements/captured_payment.hsx +144 -0
  218. package/std/settlements/conditional_disbursement.hsx +185 -0
  219. package/std/settlements/credit_facility.hsx +167 -0
  220. package/std/settlements/held_payment.hsx +578 -0
  221. package/std/settlements/index.hsx +3 -0
  222. package/std/settlements/instant_transfer.hsx +190 -0
  223. package/std/settlements/metered.hsx +67 -0
  224. package/std/settlements/pooled_split.hsx +68 -0
  225. package/std/settlements/premium_forward.hsx +257 -0
  226. package/std/settlements/reconciled_payout.hsx +77 -0
  227. package/std/settlements/recurring_collection.hsx +27 -0
  228. package/std/settlements/rotating_pool.hsx +252 -0
  229. package/std/settlements/scheduled.hsx +641 -0
  230. package/std/settlements/security_deposit.hsx +166 -0
  231. package/std/settlements/settlement_batch.hsx +122 -0
  232. package/std/settlements/swap.hsx +1114 -0
  233. package/std/settlements/threshold_pool.hsx +221 -0
  234. package/std/settlements/weighted_distribution.hsx +141 -0
  235. package/dist/src/archetypes.d.ts +0 -17
  236. package/dist/src/archetypes.d.ts.map +0 -1
  237. package/dist/src/archetypes.js +0 -327
  238. package/dist/src/archetypes.js.map +0 -1
  239. package/dist/src/check.d.ts +0 -12
  240. package/dist/src/check.d.ts.map +0 -1
  241. package/dist/src/check.js +0 -1910
  242. package/dist/src/check.js.map +0 -1
  243. package/dist/src/lower.d.ts +0 -146
  244. package/dist/src/lower.d.ts.map +0 -1
  245. package/dist/src/lower.js +0 -4570
  246. package/dist/src/lower.js.map +0 -1
  247. package/dist/src/model.d.ts +0 -467
  248. package/dist/src/model.d.ts.map +0 -1
  249. package/dist/src/model.js +0 -15
  250. package/dist/src/model.js.map +0 -1
  251. package/spec/hsx-ir.schema.json +0 -920
  252. package/src/archetypes.ts +0 -340
  253. package/src/check.ts +0 -2938
  254. package/src/lower.ts +0 -5416
  255. package/src/model.ts +0 -519
@@ -0,0 +1,1739 @@
1
+ <!-- Generated by scripts/docs/build.ts for HSX 1.0.0. Do not edit. -->
2
+
3
+ # HSX full documentation
4
+
5
+ # Your first program
6
+
7
+ An HSX file declares one program, the parties that take part, and the instruments that define its money rules. A settlement applies a standard-library instrument. The compiler checks the application and emits canonical UDL with an origin map and a cost manifest.
8
+
9
+ This program sends a tip from a listener to a host:
10
+
11
+ ```hsx
12
+ program tip_jar "Tip jar"
13
+ import { instant_transfer } from "std/settlements"
14
+ party listener: person
15
+ party host: business
16
+ settlement tip = instant_transfer {
17
+ payer: listener
18
+ payee: host
19
+ amount: tipAmount: money(SAR)
20
+ fees { listener: 1% }
21
+ }
22
+ ```
23
+
24
+ `tipAmount` is an input field measured in SAR minor units. The settlement becomes an instrument named `tip` in the UDL document.
25
+
26
+ A port declares a decision that an external caller may supply. The port names the parties allowed to answer and may define a typed input shape. Use a port only when the selected instrument accepts a condition parameter.
27
+
28
+ After package installation, run `npx hsx check product.hsx` while editing and `npx hsx build product.hsx --out product.udl.json` when the program passes. In a repository checkout, run `bun install` once, then use `bun run bin/hsx.ts check product.hsx` and `bun run bin/hsx.ts build product.hsx --out product.udl.json`.
29
+
30
+ # Money
31
+
32
+ HSX indexes money by currency. `money<SAR>` is the field type inside a general instrument. `amount: total: money(SAR)` binds a settlement parameter to a new SAR money field. Values use integer minor units, so `1250` means SAR 12.50.
33
+
34
+ Money of different currencies never unifies. Percent literals use basis-point precision: `2%` is 200 basis points and `2.5%` is 250 basis points. The compiler floors percentage-derived minor units and assigns any declared remainder according to the selected instrument.
35
+
36
+ Money is linear. A computed amount must be consumed exactly once. This invalid general-form program uses `rest` twice, so the compiler reports `HSX1201`:
37
+
38
+ ```hsx expect=HSX1201
39
+ program duplicated_money "Duplicated money"
40
+ party buyer: person
41
+ instrument invoice {
42
+ fields { amount: money<SAR>; }
43
+ lifecycle { states created paid; initial created; on pay: created -> paid; }
44
+ parties { payer: buyer; }
45
+ action create { steps: []; }
46
+ action pay {
47
+ computes remainder rest { amount_ref: total; on_zero: refuse; total_path: fields.amount; }
48
+ moves: [{ amount: rest; }, { amount: rest; }]
49
+ steps: []
50
+ }
51
+ }
52
+ ```
53
+
54
+ Do not use free arithmetic to repair a linearity refusal. Choose a standard-library split, fee, or derived-amount form that states where every minor unit goes.
55
+
56
+ # Instruments
57
+
58
+ Start with the standard library. Import a settlement module by export name from `std/settlements`, then apply it under a local settlement name. The local name becomes the emitted instrument id.
59
+
60
+ ```hsx
61
+ program equipment_hire "Equipment hire"
62
+ import { scheduled } from "std/settlements"
63
+ party renter: person
64
+ party owner: business
65
+ settlement installments = scheduled {
66
+ payer: renter
67
+ payee: owner
68
+ amount: hirePrice: money(SAR)
69
+ count: 2
70
+ every: P30D
71
+ first_due: firstPaymentAt
72
+ }
73
+ ```
74
+
75
+ Required parameters state the instrument's core contract. Optional parameters add bounded behavior such as a deadline, cancellation allocation, fee, or policy. Omit an optional block when the product does not need it. Do not pass an empty block as a substitute unless the module documents that form.
76
+
77
+ The generated standard-library reference lists every module, parameter, action, port, and emitted clause. Read that page before choosing a module. Prefer one module that already states the required lifecycle over a custom instrument with copied mechanics.
78
+
79
+ # Lifecycles
80
+
81
+ A lifecycle lists every state, names one initial state, and declares action transitions. Every reachable nonterminal state must have a bounded exit or be explicitly parked for a caller action. Actions hold the money moves and other typed clauses that occur on a transition.
82
+
83
+ ```hsx
84
+ program approvals "Approvals"
85
+ instrument approval {
86
+ title: "Approval"
87
+ summary: "A bounded approval decision"
88
+ fields {}
89
+ lifecycle {
90
+ states pending approved rejected;
91
+ initial pending;
92
+ on approve: pending -> approved;
93
+ on reject: pending -> rejected;
94
+ }
95
+ action create { steps: []; moves: []; }
96
+ action approve { steps: []; moves: []; }
97
+ action reject { steps: []; moves: []; }
98
+ }
99
+ ```
100
+
101
+ Standard-library instruments bind ports to caller decisions. A deadline appears as stored date data and a `due` clause on the action that may run at that date. An unwind states how a failed or cancelled path drains held value. The compiler refuses a reachable exit that strands money.
102
+
103
+ Keep lifecycle changes additive after composition. Add a new action or state when old instances can still obey the previous contract. Do not rename a state or tighten an active transition in place.
104
+
105
+ # Fees and splits
106
+
107
+ Standard-library payment modules accept bounded fee forms. A payer fee sits on top of the principal. A payee fee is carved from the payout. A fee may be an exact percentage, an immutable money field, or a finite tier table when the module accepts it.
108
+
109
+ ```hsx
110
+ program lesson_market "Lesson market"
111
+ import { instant_transfer, pooled_split } from "std/settlements"
112
+ party student: person
113
+ party tutor: business
114
+ party assistant: business
115
+ party school: business
116
+ settlement lesson = instant_transfer {
117
+ payer: student
118
+ payee: tutor
119
+ amount: lessonFee: money(SAR)
120
+ fees { student: 1%, tutor: 8% }
121
+ }
122
+ settlement payout = pooled_split {
123
+ payer: school
124
+ amount: weeklyPool: money(SAR)
125
+ payout_due: payoutAt
126
+ split { tutor: 60%, assistant: 40%, remainder_to: tutor }
127
+ }
128
+ ```
129
+
130
+ Every percentage partition must total 100 percent. `pooled_split` distributes a pool among named recipients and sends integer-division residue to `remainder_to`. `security_deposit` can bind a decided claim amount and return the unused remainder. `weighted_distribution` records bounded entitlement rows before it snapshots a distribution.
131
+
132
+ `cancellable_booking` uses `quote` and `commit` when a fee must be shown before it can move money. Its `cancel` action prices a penalty from the time left before `starts_at`, freezes the price and the fields named by `fixes`, and gives the offer a bounded life. Its `confirm` action commits that exact quote. Expiry or a changed frozen field refuses the commit instead of repricing it silently.
133
+
134
+ ```hsx
135
+ program studio_booking "Studio booking"
136
+ import { cancellable_booking } from "std/settlements"
137
+ party guest: person
138
+ party studio: business
139
+ settlement session = cancellable_booking {
140
+ guest: guest
141
+ host: studio
142
+ amount: sessionPrice: money(SAR)
143
+ starts_at: startsAt
144
+ late_penalty_bps: 5000
145
+ late_within: P2D
146
+ early_penalty_bps: 1000
147
+ offer_life: PT30M
148
+ }
149
+ ```
150
+
151
+ # Schedules
152
+
153
+ HSX schedules are finite. A literal `count`, an interval, and a first due date let the compiler expand installments at compile time. The monthly obligation form can instead use a caller-controlled end condition, but it must name the drain action that ends future liability.
154
+
155
+ ```hsx
156
+ program installments "Installments"
157
+ import { scheduled } from "std/settlements"
158
+ party buyer: person
159
+ party seller: business
160
+ settlement plan = scheduled {
161
+ payer: buyer
162
+ payee: seller
163
+ amount: totalAmount: money(SAR)
164
+ count: 3
165
+ every: P30D
166
+ first_due: firstDueAt
167
+ }
168
+ ```
169
+
170
+ `scheduled` handles finite installments and obligation schedules. `recurring_collection` records collection periods without inventing money movement. `rotating_pool` expands a fixed roster and cycle count. `settlement_batch` closes on a stored date before calculation, approval, instruction, acknowledgement, and reconciliation actions.
171
+
172
+ General modules may use a comprehension over a compile-time integer or finite list. Runtime-dependent bounds are refused. An expansion may contain at most 256 generated rows.
173
+
174
+ # Composition
175
+
176
+ One program can apply several instruments. Each instrument keeps its own lifecycle and fields. References connect them through typed ids instead of shared mutable state.
177
+
178
+ ```hsx
179
+ program studio_sales "Studio sales"
180
+ import { instant_transfer, scheduled } from "std/settlements"
181
+ party buyer: person
182
+ party studio: business
183
+ settlement purchase = instant_transfer {
184
+ payer: buyer
185
+ payee: studio
186
+ amount: purchasePrice: money(SAR)
187
+ fees { buyer: 1% }
188
+ }
189
+ settlement installments = scheduled {
190
+ payer: buyer
191
+ payee: studio
192
+ amount: servicePrice: money(SAR)
193
+ count: 2
194
+ every: P30D
195
+ first_due: firstPaymentAt
196
+ }
197
+ ```
198
+
199
+ A general instrument declares a `ref<target>` field when an instance must point to another instrument. Cross-instrument clauses bind against the target's declared fields, actions, and lifecycle states after the full module graph resolves. A missing target or incompatible field reports a typed diagnostic before UDL emission.
200
+
201
+ Keep each money route in one instrument. Connect instruments with evidence and references. Do not move an amount through an untyped text field.
202
+
203
+ `reconciled_payout` composes a payout instruction with one explicit expectation about the bank debit that follows. Its `reconcile` clause binds the expected amount, currency, direction, payout reference, evidence source, match law, and deadline. A match settles the payout. A missed or mismatched expectation creates the declared break child, so the composition retains the exception as contract data.
204
+
205
+ ```hsx
206
+ program supplier_payment "Supplier payment"
207
+ import { reconciled_payout } from "std/settlements"
208
+ party treasury: business
209
+ party supplier: business
210
+ settlement payout = reconciled_payout {
211
+ payer: treasury
212
+ beneficiary: supplier
213
+ amount: netPayable: money(SAR)
214
+ beneficiary_ref: supplierBeneficiaryId
215
+ settle_by: settleBy
216
+ matched_within: 100
217
+ matched_ceiling: 500
218
+ }
219
+ ```
220
+
221
+ # Writing a module
222
+
223
+ A module is ordinary HSX source. It declares a dotted module name and exports templates, types, constants, subjects, or applications. The compiler does not branch on a standard-library module name.
224
+
225
+ ```hsx
226
+ program approval_example "Approval example"
227
+ instrument approval() {
228
+ title: "Approval"
229
+ summary: "A reusable approval lifecycle"
230
+ fields {}
231
+ lifecycle {
232
+ states pending approved;
233
+ initial pending;
234
+ on approve: pending -> approved;
235
+ }
236
+ action create { steps: []; moves: []; }
237
+ action approve { steps: []; moves: []; }
238
+ }
239
+ instrument review = approval()
240
+ ```
241
+
242
+ A parameter list makes an instrument a template, including an empty list. A concrete instrument without a parameter list emits directly when its file compiles. Export only the declarations that callers need.
243
+
244
+ Imported exports carry the local declarations they reference. Identical declarations unify. Conflicting declarations report `HSX1009`. Keep module parameters typed, keep loops finite, and use UDL clause vocabulary for instrument and action mechanics.
245
+
246
+ Publish a module only after compiling it directly and through an importing program. Compare the canonical UDL bytes from both paths when the exported application should be identical.
247
+
248
+ # Cost
249
+
250
+ Compilation emits a deterministic cost manifest beside the UDL document. The manifest pins the cost-table version and effective digest. It records fixed structural cost, action effect rows, payer, settlement policy, meters, per-event prices, and any basis-point volume price.
251
+
252
+ ```hsx
253
+ program direct_sale "Direct sale"
254
+ import { instant_transfer } from "std/settlements"
255
+ party buyer: person
256
+ party seller: business
257
+ settlement sale = instant_transfer {
258
+ payer: buyer
259
+ payee: seller
260
+ amount: saleAmount: money(SAR)
261
+ fees { buyer: 1% }
262
+ }
263
+ ```
264
+
265
+ Read an action line as `instrument.action`, followed by the effect signature and its count. The payer tells whether the product or end customer bears the row. `perEventMinor` prices one occurrence in the cost table's billing currency. A row with `bps` also names a volume meter.
266
+
267
+ The monthly estimate is an expression over declared meter variables. Billing supplies observed readings to that frozen expression. Recomposition emits a new manifest for the next commercial snapshot. It does not rewrite a prior manifest.
268
+
269
+ An effect without a price row reports `HSX1301`. An invalid price reports `HSX1302`. A missing cost table also reports `HSX1301`. Use the single rate card shipped at `examples/cost-table.json`; do not create a second table for documentation.
270
+
271
+ Do not confuse an action `quote` with the commercial cost manifest. `cancellable_booking.cancel` quotes a customer-visible cancellation penalty and `confirm` commits it. The compiler counts an instrument that carries a quote as unwind work because an expired or abandoned offer still needs bounded cleanup. The cost manifest prices that runtime work from the shipped rate card. It does not replace, spend, or alter the quoted financial amount.
272
+
273
+ # Diagnostics
274
+
275
+ An HSX diagnostic carries a stable code, severity, stage, source line and column, message, and fix. Match automation on the code. Treat the message as explanation rather than a stable interface.
276
+
277
+ The stages locate the refusal:
278
+
279
+ - `parse` means the source did not form valid declarations or expressions.
280
+ - `bind` means an import, name, port, or reference did not resolve.
281
+ - `typecheck` and `check` mean the program formed but violated a type or language law.
282
+ - `lower` means the typed program could not emit valid UDL.
283
+
284
+ Use one loop: compile, find the first error code in the diagnostics reference, apply its stated fix, and compile again. Do not suppress the diagnostic or alter generated UDL by hand.
285
+
286
+ ```hsx
287
+ program repaired_transfer "Repaired transfer"
288
+ import { instant_transfer } from "std/settlements"
289
+ party sender: person
290
+ party recipient: business
291
+ settlement transfer = instant_transfer {
292
+ payer: sender
293
+ payee: recipient
294
+ amount: transferAmount: money(SAR)
295
+ fees { sender: 1% }
296
+ }
297
+ ```
298
+
299
+ Exit code `0` means the command accepted the program. Exit code `1` means compilation refused it. Exit code `2` means the invocation or file operation failed. `hsx explain HSX1201` prints the catalog entry for one code.
300
+
301
+ # CLI
302
+
303
+ ```text
304
+ hsx 1.0.0, the HSX compiler
305
+
306
+ Usage:
307
+ hsx check <file.hsx> [--strict]
308
+ hsx build <file.hsx> [--out <file.json>] [--strict]
309
+ hsx cost <file.hsx> [--json] [--out <file.json>] [--strict]
310
+ hsx explain <HSX####>
311
+ hsx format <file.hsx>
312
+ hsx lsp
313
+ hsx --version
314
+ hsx --help
315
+
316
+ Commands:
317
+ check Compile and report diagnostics. Prints nothing when the program is clean.
318
+ build Compile and write canonical UDL as JSON.
319
+ cost Compile and print the version-pinned cost manifest as a table or JSON.
320
+ explain Print one diagnostic title, fix, and source example.
321
+ format Print the source in the one canonical HSX style.
322
+ lsp Run the language server over stdin and stdout.
323
+
324
+ Options:
325
+ --json Print the cost manifest as JSON instead of a table.
326
+ --out <file> Write build or cost JSON to this path instead of stdout.
327
+ --strict Treat warning-severity diagnostics as failures.
328
+
329
+ Exit codes:
330
+ 0 the program compiled (verdict valid, or warning without --strict)
331
+ 1 the program was refused (verdict invalid, or warning with --strict)
332
+ 2 the command line or the input file could not be used
333
+ ```
334
+
335
+ # Diagnostics
336
+
337
+ Use `hsx explain HSX####` for the same catalog entry.
338
+
339
+ ## HSX1000: Missing file declaration
340
+
341
+ Stage: `typecheck`
342
+
343
+ Fix: Add one program header or module declaration.
344
+
345
+ No source-only witness exists. The compiler host or lowering input must supply the invalid value.
346
+
347
+ ## HSX1001: Unbound name
348
+
349
+ Stage: `bind`
350
+
351
+ Fix: Declare or import the name before using it.
352
+
353
+ ```hsx expect=HSX1001
354
+ program catalog_probe "Catalog probe"
355
+ instrument probe = missing()
356
+ ```
357
+
358
+ ## HSX1002: Duplicate program declaration
359
+
360
+ Stage: `typecheck`
361
+
362
+ Fix: Keep exactly one program declaration.
363
+
364
+ ```hsx expect=HSX1002
365
+ program catalog_probe "Catalog probe"
366
+ instrument probe {
367
+ fields {}
368
+ lifecycle { states created; initial created; }
369
+ action create { steps: []; }
370
+
371
+ }
372
+ program second "Second"
373
+ ```
374
+
375
+ ## HSX1003: Invalid declaration name
376
+
377
+ Stage: `typecheck`
378
+
379
+ Fix: Use lowercase snake_case for program and instrument names.
380
+
381
+ ```hsx expect=HSX1003
382
+ program NotSnake "Catalog probe"
383
+ ```
384
+
385
+ ## HSX1004: Duplicate declaration
386
+
387
+ Stage: `typecheck`
388
+
389
+ Fix: Keep one declaration or give each declaration a distinct name.
390
+
391
+ ```hsx expect=HSX1004
392
+ program catalog_probe "Catalog probe"
393
+ instrument probe {
394
+ fields {}
395
+ lifecycle { states created; initial created; }
396
+ action create { steps: []; }
397
+
398
+ }
399
+ instrument probe { fields {}; lifecycle { states created; initial created; }; action create { steps: []; }; }
400
+ ```
401
+
402
+ ## HSX1005: Invalid field name
403
+
404
+ Stage: `typecheck`
405
+
406
+ Fix: Rename the field in lower camelCase.
407
+
408
+ No source-only witness exists. The parser normalizes every accepted field spelling before typechecking.
409
+
410
+ ## HSX1006: Invalid module import
411
+
412
+ Stage: `bind`
413
+
414
+ Fix: Resolve one module that exports each imported name exactly once.
415
+
416
+ No source-only witness exists. This refusal requires a compiler-host module resolver result.
417
+
418
+ ## HSX1007: Invalid cross-instrument reference
419
+
420
+ Stage: `typecheck`
421
+
422
+ Fix: Name an existing target instrument in the ref type.
423
+
424
+ ```hsx expect=HSX1007
425
+ program catalog_probe "Catalog probe"
426
+ instrument probe {
427
+ fields { parentId { type: ref; description: "Parent"; } }
428
+ lifecycle { states created; initial created; }
429
+ action create { steps: []; }
430
+ }
431
+ ```
432
+
433
+ ## HSX1008: Invalid subject or decision port
434
+
435
+ Stage: `typecheck`
436
+
437
+ Fix: Complete the declaration and bind every referenced decision port.
438
+
439
+ ```hsx expect=HSX1008
440
+ program catalog_probe "Catalog probe"
441
+ instrument probe {
442
+ fields {}
443
+ lifecycle { states created; initial created; }
444
+ action create { steps: []; }
445
+
446
+ }
447
+ subject vehicle { title: "Vehicle"; }
448
+ ```
449
+
450
+ ## HSX1009: Imported declaration collision
451
+
452
+ Stage: `bind`
453
+
454
+ Fix: Rename the importer-owned declaration or the module-local declaration.
455
+
456
+ No source-only witness exists. This refusal requires declarations returned by a compiler-host module resolver.
457
+
458
+ ## HSX1010: Wrong type-argument count
459
+
460
+ Stage: `typecheck`
461
+
462
+ Fix: Supply exactly the type arguments declared by the instrument function.
463
+
464
+ ```hsx expect=HSX1010
465
+ program catalog_probe "Catalog probe"
466
+ export instrument template<C>() { fields {}; lifecycle { states created; initial created; }; action create { steps: []; }; }
467
+ instrument probe = template<SAR, USD>()
468
+ ```
469
+
470
+ ## HSX1011: Missing required argument
471
+
472
+ Stage: `typecheck`
473
+
474
+ Fix: Pass every required instrument-function argument.
475
+
476
+ ```hsx expect=HSX1011
477
+ program catalog_probe "Catalog probe"
478
+ export instrument template(value: text) { fields {}; lifecycle { states created; initial created; }; action create { steps: []; }; }
479
+ instrument probe = template()
480
+ ```
481
+
482
+ ## HSX1012: Unknown named argument
483
+
484
+ Stage: `typecheck`
485
+
486
+ Fix: Remove the argument or use a parameter declared by the instrument function.
487
+
488
+ ```hsx expect=HSX1012
489
+ program catalog_probe "Catalog probe"
490
+ export instrument template() { fields {}; lifecycle { states created; initial created; }; action create { steps: []; }; }
491
+ instrument probe = template(typo: true)
492
+ ```
493
+
494
+ ## HSX1013: Duplicate named argument
495
+
496
+ Stage: `typecheck`
497
+
498
+ Fix: Pass each named argument once.
499
+
500
+ ```hsx expect=HSX1013
501
+ program catalog_probe "Catalog probe"
502
+ export instrument template(value: text) { fields {}; lifecycle { states created; initial created; }; action create { steps: []; }; }
503
+ instrument probe = template(value: "one", value: "two")
504
+ ```
505
+
506
+ ## HSX1014: JSON supplied as HSX
507
+
508
+ Stage: `parse`
509
+
510
+ Fix: Replace the JSON object with HSX declarations.
511
+
512
+ ```hsx expect=HSX1014
513
+ { "hsx": 1 }
514
+ ```
515
+
516
+ ## HSX1015: Invalid composed program identity
517
+
518
+ Stage: `typecheck`
519
+
520
+ Fix: Give the composed program a bounded product id and title.
521
+
522
+ No source-only witness exists. This refusal requires a compiler-host published catalog.
523
+
524
+ ## HSX1016: Empty published composition
525
+
526
+ Stage: `typecheck`
527
+
528
+ Fix: Select at least one published instrument with use.
529
+
530
+ No source-only witness exists. This refusal requires a compiler-host published catalog.
531
+
532
+ ## HSX1017: Duplicate published instrument
533
+
534
+ Stage: `typecheck`
535
+
536
+ Fix: Keep one use declaration for each published instrument.
537
+
538
+ No source-only witness exists. This refusal requires a compiler-host published catalog.
539
+
540
+ ## HSX1018: Unavailable published instrument
541
+
542
+ Stage: `typecheck`
543
+
544
+ Fix: Use an instrument id from the supplied published catalog.
545
+
546
+ ```hsx expect=HSX1018
547
+ program catalog_probe "Catalog probe"
548
+ use missing
549
+ ```
550
+
551
+ ## HSX1020: Invalid public action name
552
+
553
+ Stage: `typecheck`
554
+
555
+ Fix: Expose each action once under a distinct lower camelCase name.
556
+
557
+ No source-only witness exists. This refusal requires a compiler-host published catalog.
558
+
559
+ ## HSX1021: Invalid exposed action
560
+
561
+ Stage: `typecheck`
562
+
563
+ Fix: Expose an action on an explicitly used published instrument.
564
+
565
+ No source-only witness exists. This refusal requires a compiler-host published catalog.
566
+
567
+ ## HSX1022: Authored instrument in a composition
568
+
569
+ Stage: `typecheck`
570
+
571
+ Fix: Publish the instrument separately, then select it with use.
572
+
573
+ No source-only witness exists. This refusal requires a compiler-host published catalog.
574
+
575
+ ## HSX1023: Invalid required-field list
576
+
577
+ Stage: `typecheck`
578
+
579
+ Fix: List declared, non-optional field names once each.
580
+
581
+ ```hsx expect=HSX1023
582
+ program catalog_probe "Catalog probe"
583
+ instrument probe {
584
+ fields {}
585
+ lifecycle { states created; initial created; }
586
+ action create { steps: []; }
587
+ required: missing;
588
+ }
589
+ ```
590
+
591
+ ## HSX1101: Currency mismatch
592
+
593
+ Stage: `typecheck`
594
+
595
+ Fix: Use the declared currency because money values never coerce.
596
+
597
+ ```hsx expect=HSX1101
598
+ program catalog_probe "Catalog probe"
599
+ instrument probe {
600
+ fields {}
601
+ lifecycle { states created; initial created; }
602
+ action create { steps: []; }
603
+
604
+ }
605
+ const fee: money<SAR> = USD 1.00
606
+ ```
607
+
608
+ ## HSX1102: Money precision exceeds minor units
609
+
610
+ Stage: `typecheck`
611
+
612
+ Fix: Round the literal to the currency's minor-unit precision.
613
+
614
+ ```hsx expect=HSX1102
615
+ program catalog_probe "Catalog probe"
616
+ instrument probe {
617
+ fields {}
618
+ lifecycle { states created; initial created; }
619
+ action create { steps: []; }
620
+
621
+ }
622
+ const fee: money<SAR> = SAR 1.001
623
+ ```
624
+
625
+ ## HSX1103: Invalid numeric value
626
+
627
+ Stage: `typecheck`
628
+
629
+ Fix: Use an integer, percent, bps, or valid fixed-money binding.
630
+
631
+ ```hsx expect=HSX1103
632
+ program catalog_probe "Catalog probe"
633
+ instrument probe {
634
+ fields {}
635
+ lifecycle { states created; initial created; }
636
+ action create { steps: []; }
637
+ summary: 1.5;
638
+ }
639
+ ```
640
+
641
+ ## HSX1104: Value has the wrong type
642
+
643
+ Stage: `typecheck`
644
+
645
+ Fix: Pass the type declared by the parameter or UDL slot.
646
+
647
+ ```hsx expect=HSX1104
648
+ program catalog_probe "Catalog probe"
649
+ instrument probe {
650
+ fields {}
651
+ lifecycle { states created; initial created; }
652
+ action create { steps: []; }
653
+ summary: money(SAR, 2500);
654
+ }
655
+ ```
656
+
657
+ ## HSX1110: Unsupported parameter combination
658
+
659
+ Stage: `typecheck`
660
+
661
+ Fix: Choose a supported compile-time parameter combination.
662
+
663
+ ```hsx expect=HSX1110
664
+ program catalog_probe "Catalog probe"
665
+ export instrument template() {
666
+ unsupported { message: "Not supported"; fix: "Choose another form"; }
667
+ fields {}
668
+ lifecycle { states created; initial created; }
669
+ action create { steps: []; }
670
+ }
671
+ instrument probe = template()
672
+ ```
673
+
674
+ ## HSX1201: Linear money consumed more than once
675
+
676
+ Stage: `typecheck`
677
+
678
+ Fix: Leave exactly one sink for each produced money value.
679
+
680
+ ```hsx expect=HSX1201
681
+ program catalog_probe "Catalog probe"
682
+ instrument probe {
683
+ fields {}
684
+ lifecycle { states created; initial created; }
685
+ action create { steps: []; }
686
+ fields { amount: money<SAR>; }
687
+ action pay { computes remainder rest { amount_ref: total; on_zero: refuse; total_path: fields.amount; }; moves: [{ amount: rest; }, { amount: rest; }]; }
688
+ }
689
+ ```
690
+
691
+ ## HSX1202: Linear money is unconsumed
692
+
693
+ Stage: `typecheck`
694
+
695
+ Fix: Route each produced money value to one explicit sink.
696
+
697
+ ```hsx expect=HSX1202
698
+ program catalog_probe "Catalog probe"
699
+ instrument probe {
700
+ fields {}
701
+ lifecycle { states created; initial created; }
702
+ action create { steps: []; }
703
+ fields { amount: money<SAR>; }
704
+ action pay { computes remainder rest { amount_ref: total; on_zero: refuse; total_path: fields.amount; }; }
705
+ }
706
+ ```
707
+
708
+ ## HSX1301: Missing cost-table price
709
+
710
+ Stage: `typecheck`
711
+
712
+ Fix: Supply a versioned cost table with a row for every emitted effect.
713
+
714
+ ```hsx expect=HSX1301
715
+ program catalog_probe "Catalog probe"
716
+ instrument probe {
717
+ fields {}
718
+ lifecycle { states created; initial created; }
719
+ action create { steps: []; }
720
+
721
+ }
722
+ ```
723
+
724
+ ## HSX1302: Invalid cost-table row
725
+
726
+ Stage: `typecheck`
727
+
728
+ Fix: Use non-negative integer prices and a supported settlement timing.
729
+
730
+ No source-only witness exists. This refusal requires a malformed compiler-host cost table.
731
+
732
+ ## HSX1303: Invalid cost-table currency
733
+
734
+ Stage: `typecheck`
735
+
736
+ Fix: Use the supported uppercase cost-table currency.
737
+
738
+ No source-only witness exists. This refusal requires an invalid compiler-host cost-table currency.
739
+
740
+ ## HSX1401: Unbounded action
741
+
742
+ Stage: `typecheck`
743
+
744
+ Fix: Replace runtime iteration with a bounded compile-time comprehension.
745
+
746
+ ```hsx expect=HSX1401
747
+ program catalog_probe "Catalog probe"
748
+ instrument probe {
749
+ fields {}
750
+ lifecycle { states created; initial created; }
751
+ action create { steps: []; }
752
+ action run { while { condition: true; }; }
753
+ }
754
+ ```
755
+
756
+ ## HSX1402: Missing lifecycle
757
+
758
+ Stage: `typecheck`
759
+
760
+ Fix: Declare lifecycle states and an initial state.
761
+
762
+ ```hsx expect=HSX1402
763
+ program catalog_probe "Catalog probe"
764
+ instrument probe { fields {}; action create { steps: []; }; }
765
+ ```
766
+
767
+ ## HSX1403: Runtime comprehension bound
768
+
769
+ Stage: `typecheck`
770
+
771
+ Fix: Use an integer literal or literal finite list as the bound.
772
+
773
+ ```hsx expect=HSX1403
774
+ program catalog_probe "Catalog probe"
775
+ export instrument template(count: integer) {
776
+ fields {}
777
+ lifecycle { states created; initial created; }
778
+ action create { steps: []; }
779
+ for item in count { action run_[item] { steps: []; } }
780
+ }
781
+ instrument probe = template(count: runtimeCount: integer)
782
+ ```
783
+
784
+ ## HSX1404: Comprehension expansion limit
785
+
786
+ Stage: `typecheck`
787
+
788
+ Fix: Reduce the fixed expansion to the compiler limit.
789
+
790
+ ```hsx expect=HSX1404
791
+ program catalog_probe "Catalog probe"
792
+ instrument probe {
793
+ fields {}
794
+ lifecycle { states created; initial created; }
795
+ action create { steps: []; }
796
+ for item in 257 { action run_[item] { steps: []; } }
797
+ }
798
+ ```
799
+
800
+ ## HSX1405: Invalid compile-time selection
801
+
802
+ Stage: `typecheck`
803
+
804
+ Fix: Give compile-time conditions and unsupported branches fixed blocks.
805
+
806
+ ```hsx expect=HSX1405
807
+ program catalog_probe "Catalog probe"
808
+ export instrument template() { unsupported: true; fields {}; lifecycle { states created; initial created; }; action create { steps: []; }; }
809
+ instrument probe = template()
810
+ ```
811
+
812
+ ## HSX1406: Invalid companion instrument
813
+
814
+ Stage: `typecheck`
815
+
816
+ Fix: Construct each companion with a compile-time id.
817
+
818
+ ```hsx expect=HSX1406
819
+ program catalog_probe "Catalog probe"
820
+ export instrument template() {
821
+ fields {}
822
+ lifecycle { states created; initial created; }
823
+ action create { steps: []; }
824
+ instruments { invalid: true; }
825
+ }
826
+ instrument probe = template()
827
+ ```
828
+
829
+ ## HSX1501: Unknown UDL clause
830
+
831
+ Stage: `typecheck`
832
+
833
+ Fix: Use a clause exported by the targeted UDL vocabulary.
834
+
835
+ ```hsx expect=HSX1501
836
+ program catalog_probe "Catalog probe"
837
+ instrument probe {
838
+ fields {}
839
+ lifecycle { states created; initial created; }
840
+ action create { steps: []; }
841
+ unknown_clause: true;
842
+ }
843
+ ```
844
+
845
+ ## HSX1502: Program emits no instruments
846
+
847
+ Stage: `typecheck`
848
+
849
+ Fix: Declare or instantiate at least one instrument.
850
+
851
+ ```hsx expect=HSX1502
852
+ program catalog_probe "Catalog probe"
853
+ ```
854
+
855
+ ## HSX1503: Missing fields block
856
+
857
+ Stage: `typecheck`
858
+
859
+ Fix: Add a fields block, even when it is empty.
860
+
861
+ ```hsx expect=HSX1503
862
+ program catalog_probe "Catalog probe"
863
+ instrument probe { lifecycle { states created; initial created; }; action create { steps: []; }; }
864
+ ```
865
+
866
+ ## HSX1504: Missing create action
867
+
868
+ Stage: `typecheck`
869
+
870
+ Fix: Add an action create block.
871
+
872
+ ```hsx expect=HSX1504
873
+ program catalog_probe "Catalog probe"
874
+ instrument probe { fields {}; lifecycle { states created; initial created; }; }
875
+ ```
876
+
877
+ ## HSX1505: Repeated single-valued clause
878
+
879
+ Stage: `typecheck`
880
+
881
+ Fix: Keep one occurrence of the clause.
882
+
883
+ ```hsx expect=HSX1505
884
+ program catalog_probe "Catalog probe"
885
+ instrument probe {
886
+ fields {}
887
+ lifecycle { states created; initial created; }
888
+ action create { steps: []; }
889
+ title: "First"; title: "Second";
890
+ }
891
+ ```
892
+
893
+ ## HSX1506: Conflicting public action settings
894
+
895
+ Stage: `typecheck`
896
+
897
+ Fix: Keep either public: none or a public action name.
898
+
899
+ ```hsx expect=HSX1506
900
+ program catalog_probe "Catalog probe"
901
+ instrument probe {
902
+ fields {}
903
+ lifecycle { states created; initial created; }
904
+ action create { steps: []; }
905
+ action finish { public: none; public_action: finishProbe; steps: []; }
906
+ }
907
+ ```
908
+
909
+ ## HSX1507: Invalid application metadata
910
+
911
+ Stage: `typecheck`
912
+
913
+ Fix: Keep contract mechanics in the parameterized instrument.
914
+
915
+ ```hsx expect=HSX1507
916
+ program catalog_probe "Catalog probe"
917
+ export instrument template() { fields {}; lifecycle { states created; initial created; }; action create { steps: []; }; }
918
+ instrument probe = template() { fields: {}; }
919
+ ```
920
+
921
+ ## HSX1601: Invalid UDL shape
922
+
923
+ Stage: `lower`
924
+
925
+ Fix: Correct the named clause so it matches the targeted UDL definition.
926
+
927
+ No source-only witness exists. Typed source cannot bypass the checker to emit an invalid UDL shape.
928
+
929
+ ## HSX1602: Invalid UDL semantics
930
+
931
+ Stage: `lower`
932
+
933
+ Fix: Correct the named clause so it satisfies the targeted UDL law.
934
+
935
+ No source-only witness exists. Typed source cannot bypass the checker to emit invalid UDL semantics.
936
+
937
+ ## HSX1603: Unresolved compiler marker
938
+
939
+ Stage: `lower`
940
+
941
+ Fix: Correct compile-time block keys or parameter bindings.
942
+
943
+ ```hsx expect=HSX1603
944
+ program catalog_probe "Catalog probe"
945
+ instrument probe {
946
+ fields {}
947
+ lifecycle { states created; initial created; }
948
+ action create { steps: []; }
949
+ title: "__hsx_none__";
950
+ }
951
+ ```
952
+
953
+ # Grammar vocabulary
954
+
955
+ The parser is hand-written. This page records the exported lexer vocabulary, the UDL clause vocabulary it binds, and the current standard-library module names.
956
+
957
+ ## Keywords
958
+
959
+ `action`, `as`, `asset`, `commit`, `const`, `expect`, `expose`, `expires`, `export`, `from`, `import`, `instrument`, `module`, `party`, `port`, `program`, `quote`, `rate`, `reconcile`, `settlement`, `subject`, `type`, `use`
960
+
961
+ ## Punctuation
962
+
963
+ `{`, `}`, `(`, `)`, `[`, `]`, `:`, `,`, `;`, `=`, `|`, `.`, `<`, `>`, `?` and `->`
964
+
965
+ ## Typed clause spellings
966
+
967
+ `agent description`, `capture input`, `commit`, `quote`, `decided amount`, `deadline`, `decision`, `computes distribute`, `description`, `due`, `earnable`, `event name`, `examples`, `input`, `moves`, `payout`, `port`, `principal`, `public action`, `reconcile`, `computes remainder`, `requires aggregate`, `requires checks`, `requires drained`, `requires exposure`, `requires refs`, `sandbox failure point`, `sets at`, `computes signed_sum`, `steps`, `summary`, `updates`, `notify`, `agent description`, `aggregate invariants`, `caller parked states`, `description`, `dials`, `distinct parties`, `computes derived`, `computes fees`, `id prefix`, `nav`, `partitions`, `subject`, `summary`, `surface visibility`, `template id`, `title`, `update`
968
+
969
+ ## Standard-library modules
970
+
971
+ - `advance`
972
+ - `cancellable_booking`
973
+ - `captured_payment`
974
+ - `conditional_disbursement`
975
+ - `credit_facility`
976
+ - `held_payment`
977
+ - `instant_transfer`
978
+ - `metered`
979
+ - `pooled_split`
980
+ - `premium_forward`
981
+ - `reconciled_payout`
982
+ - `recurring_collection`
983
+ - `rotating_pool`
984
+ - `scheduled`
985
+ - `security_deposit`
986
+ - `settlement_batch`
987
+ - `swap`
988
+ - `threshold_pool`
989
+ - `weighted_distribution`
990
+
991
+ # advance
992
+
993
+ Source: [`std/settlements/advance.hsx`](../../../std/settlements/advance.hsx)
994
+
995
+ ## Export
996
+
997
+ `advance<C>`
998
+
999
+ ## Parameters
1000
+
1001
+ - `funder: party`
1002
+ - `to: party`
1003
+ - `amount: money<C>`
1004
+ - `fee: optional<percent>`
1005
+ - `count: optional<integer>`
1006
+ - `every: optional<text>`
1007
+ - `first_due: optional<date>`
1008
+ - `against: optional<ref>`
1009
+
1010
+ ## Decision ports
1011
+
1012
+ None.
1013
+
1014
+ ## Actions and clauses
1015
+
1016
+ | Action | Clauses lowered |
1017
+ | --------------------- | ------------------------------------------------ |
1018
+ | `create` | `agent description`, `moves`, `steps`, `summary` |
1019
+ | `disburse` | `agent description`, `moves`, `steps`, `summary` |
1020
+ | `settle` | `agent description`, `moves`, `steps`, `summary` |
1021
+ | `create` | `agent description`, `moves`, `steps`, `summary` |
1022
+ | `disburse` | `agent description`, `moves`, `steps`, `summary` |
1023
+ | `collect_repayment_1` | `due`, `moves`, `steps`, `summary` |
1024
+
1025
+ # cancellable_booking
1026
+
1027
+ Source: [`std/settlements/cancellable_booking.hsx`](../../../std/settlements/cancellable_booking.hsx)
1028
+
1029
+ ## Export
1030
+
1031
+ `cancellable_booking<C>`
1032
+
1033
+ ## Parameters
1034
+
1035
+ - `guest: party`
1036
+ - `host: party`
1037
+ - `amount: money<C>`
1038
+ - `starts_at: date`
1039
+ - `late_penalty_bps: integer`
1040
+ - `late_within: text`
1041
+ - `early_penalty_bps: integer`
1042
+ - `offer_life: text`
1043
+
1044
+ ## Decision ports
1045
+
1046
+ None.
1047
+
1048
+ ## Actions and clauses
1049
+
1050
+ | Action | Clauses lowered |
1051
+ | ---------- | ---------------------------------------------------------- |
1052
+ | `create` | `agent description`, `moves`, `steps`, `summary` |
1053
+ | `take` | `agent description`, `moves`, `steps`, `summary` |
1054
+ | `complete` | `due`, `moves`, `steps`, `summary` |
1055
+ | `cancel` | `agent description`, `moves`, `quote`, `steps`, `summary` |
1056
+ | `confirm` | `agent description`, `commit`, `moves`, `steps`, `summary` |
1057
+ | `retain` | `agent description`, `moves`, `steps`, `summary` |
1058
+
1059
+ # captured_payment
1060
+
1061
+ Source: [`std/settlements/captured_payment.hsx`](../../../std/settlements/captured_payment.hsx)
1062
+
1063
+ ## Export
1064
+
1065
+ `captured_payment<C>`
1066
+
1067
+ ## Parameters
1068
+
1069
+ - `payer: party`
1070
+ - `payee: party`
1071
+ - `amount: money<C>`
1072
+ - `reserve_until: date`
1073
+ - `correction: condition`
1074
+ - `external_reversal: condition`
1075
+ - `capture_mode: text`
1076
+ - `correction_mode: text`
1077
+ - `negative_position: text`
1078
+ - `timeout: text`
1079
+ - `derived_amount: optional<block>`
1080
+
1081
+ ## Decision ports
1082
+
1083
+ - `correction`
1084
+ - `external_reversal`
1085
+
1086
+ ## Actions and clauses
1087
+
1088
+ | Action | Clauses lowered |
1089
+ | ------------------ | -------------------------------------------------------------------------------------------- |
1090
+ | `create` | `agent description`, `moves`, `steps`, `summary` |
1091
+ | `authorize` | `agent description`, `moves`, `steps`, `summary` |
1092
+ | `capture` | `agent description`, `deadline`, `description`, `input`, `moves`, `steps`, `summary` |
1093
+ | `capture_more` | `agent description`, `deadline`, `description`, `input`, `moves`, `steps`, `summary` |
1094
+ | `settle` | `agent description`, `deadline`, `moves`, `steps`, `summary` |
1095
+ | `void` | `agent description`, `moves`, `steps`, `summary` |
1096
+ | `expire` | `due`, `moves`, `steps`, `summary` |
1097
+ | `settle_on_expiry` | `due`, `moves`, `steps`, `summary` |
1098
+ | `correction_name` | `agent description`, `moves`, `port`, `steps`, `summary` |
1099
+ | `reversal_name` | `agent description`, `deadline`, `description`, `input`, `moves`, `port`, `steps`, `summary` |
1100
+
1101
+ # conditional_disbursement
1102
+
1103
+ Source: [`std/settlements/conditional_disbursement.hsx`](../../../std/settlements/conditional_disbursement.hsx)
1104
+
1105
+ ## Export
1106
+
1107
+ `conditional_disbursement<C>`
1108
+
1109
+ ## Parameters
1110
+
1111
+ - `source: party`
1112
+ - `destination: party`
1113
+ - `cap: money<C>`
1114
+ - `amount: money<C>`
1115
+ - `decision: condition`
1116
+ - `reopen_policy: text`
1117
+ - `recovery_policy: text`
1118
+
1119
+ ## Decision ports
1120
+
1121
+ - `decision`
1122
+
1123
+ ## Actions and clauses
1124
+
1125
+ | Action | Clauses lowered |
1126
+ | --------- | ------------------------------------------------------------------------------------------------- |
1127
+ | `create` | `agent description`, `moves`, `steps`, `summary` |
1128
+ | `deny` | `agent description`, `capture input`, `description`, `input`, `moves`, `port`, `steps`, `summary` |
1129
+ | `create` | `agent description`, `moves`, `steps`, `summary` |
1130
+ | `approve` | `agent description`, `capture input`, `description`, `input`, `moves`, `port`, `steps`, `summary` |
1131
+ | `pay` | `agent description`, `moves`, `steps`, `summary` |
1132
+
1133
+ # credit_facility
1134
+
1135
+ Source: [`std/settlements/credit_facility.hsx`](../../../std/settlements/credit_facility.hsx)
1136
+
1137
+ ## Export
1138
+
1139
+ `credit_facility<C>`
1140
+
1141
+ ## Parameters
1142
+
1143
+ - `lender: party`
1144
+ - `borrower: party`
1145
+ - `draw_destination: party`
1146
+ - `limit: money<C>`
1147
+ - `expires_at: date`
1148
+ - `obligation: ref`
1149
+ - `availability_policy: text`
1150
+ - `expiry_policy: text`
1151
+ - `close_policy: text`
1152
+
1153
+ ## Decision ports
1154
+
1155
+ None.
1156
+
1157
+ ## Actions and clauses
1158
+
1159
+ | Action | Clauses lowered |
1160
+ | --------- | ------------------------------------------------ |
1161
+ | `create` | `agent description`, `moves`, `steps`, `summary` |
1162
+ | `freeze` | `due`, `moves`, `steps`, `summary` |
1163
+ | `close` | `agent description`, `moves`, `steps`, `summary` |
1164
+ | `create` | `agent description`, `moves`, `steps`, `summary` |
1165
+ | `resolve` | `agent description`, `moves`, `steps`, `summary` |
1166
+
1167
+ # held_payment
1168
+
1169
+ Source: [`std/settlements/held_payment.hsx`](../../../std/settlements/held_payment.hsx)
1170
+
1171
+ ## Export
1172
+
1173
+ `held_payment<C>`
1174
+
1175
+ ## Parameters
1176
+
1177
+ - `payer: party`
1178
+ - `payee: party`
1179
+ - `amount: money<C>`
1180
+ - `release: condition`
1181
+ - `fees: optional<block>`
1182
+ - `on_cancel: optional<block>`
1183
+ - `derived_amount: optional<block>`
1184
+ - `release_to: optional<party>`
1185
+ - `whole_amount: optional<block>`
1186
+ - `release_action: optional<text>`
1187
+ - `whole_fee: optional<money<C>>`
1188
+ - `reference: optional<text>`
1189
+ - `upstream: optional<ref>`
1190
+ - `id_prefix_override: optional<text>`
1191
+
1192
+ ## Decision ports
1193
+
1194
+ - `release`
1195
+
1196
+ ## Actions and clauses
1197
+
1198
+ | Action | Clauses lowered |
1199
+ | --------------------- | --------------------------------------------------------------------------------------------- |
1200
+ | `fund_piece_2` | `agent description`, `moves`, `steps`, `summary` |
1201
+ | `fund_piece_3` | `agent description`, `moves`, `steps`, `summary` |
1202
+ | `collect_service_fee` | `agent description`, `moves`, `steps`, `summary` |
1203
+ | `release_piece_2` | `agent description`, `moves`, `steps`, `summary` |
1204
+ | `release_piece_3` | `agent description`, `moves`, `steps`, `summary` |
1205
+ | `refund_piece_2` | `agent description`, `moves`, `steps`, `summary` |
1206
+ | `refund_piece_3` | `agent description`, `moves`, `steps`, `summary` |
1207
+ | `unfund_piece_1` | `agent description`, `moves`, `steps`, `summary` |
1208
+ | `unfund_piece_2` | `agent description`, `moves`, `steps`, `summary` |
1209
+ | `unfund_piece_3` | `agent description`, `moves`, `steps`, `summary` |
1210
+ | `create` | `agent description`, `moves`, `steps`, `summary` |
1211
+ | `fund_piece_1` | `agent description`, `moves`, `steps`, `summary` |
1212
+ | `release_name` | `agent description`, `deadline`, `description`, `input`, `moves`, `port`, `steps`, `summary` |
1213
+ | `release_on_deadline` | `due`, `moves`, `steps`, `summary` |
1214
+ | `cancel` | `agent description`, `deadline`, `moves`, `steps`, `summary` |
1215
+ | `fund_piece_2` | `agent description`, `moves`, `steps`, `summary` |
1216
+ | `release_piece_2` | `agent description`, `moves`, `steps`, `summary` |
1217
+ | `unfund_piece_1` | `agent description`, `moves`, `steps`, `summary` |
1218
+ | `fund_piece_2` | `agent description`, `moves`, `steps`, `summary` |
1219
+ | `release_piece_2` | `agent description`, `moves`, `steps`, `summary` |
1220
+ | `refund_piece_2` | `agent description`, `moves`, `steps`, `summary` |
1221
+ | `unfund_piece_1` | `agent description`, `moves`, `steps`, `summary` |
1222
+ | `abandon` | `agent description`, `moves`, `steps`, `summary` |
1223
+ | `create` | `agent description`, `moves`, `steps`, `summary` |
1224
+ | `fund` | `agent description`, `moves`, `sandbox failure point`, `steps`, `summary` |
1225
+ | `release_action` | `agent description`, `deadline`, `moves`, `port`, `sandbox failure point`, `steps`, `summary` |
1226
+ | `release_on_deadline` | `due`, `event name`, `moves`, `steps`, `summary` |
1227
+ | `cancel` | `agent description`, `deadline`, `event name`, `moves`, `steps`, `summary` |
1228
+ | `abandon` | `agent description`, `moves`, `steps`, `summary` |
1229
+
1230
+ # instant_transfer
1231
+
1232
+ Source: [`std/settlements/instant_transfer.hsx`](../../../std/settlements/instant_transfer.hsx)
1233
+
1234
+ ## Export
1235
+
1236
+ `instant_transfer<C>`
1237
+
1238
+ ## Parameters
1239
+
1240
+ - `payer: party`
1241
+ - `payee: party`
1242
+ - `amount: money<C>`
1243
+ - `fees: optional<block>`
1244
+ - `derived_amount: optional<block>`
1245
+
1246
+ ## Decision ports
1247
+
1248
+ None.
1249
+
1250
+ ## Actions and clauses
1251
+
1252
+ | Action | Clauses lowered |
1253
+ | --------------------- | ------------------------------------------------ |
1254
+ | `create` | `agent description`, `moves`, `steps`, `summary` |
1255
+ | `pay_piece_1` | `agent description`, `moves`, `steps`, `summary` |
1256
+ | `pay_piece_2` | `agent description`, `moves`, `steps`, `summary` |
1257
+ | `collect_service_fee` | `agent description`, `moves`, `steps`, `summary` |
1258
+
1259
+ # metered
1260
+
1261
+ Source: [`std/settlements/metered.hsx`](../../../std/settlements/metered.hsx)
1262
+
1263
+ ## Export
1264
+
1265
+ `metered`
1266
+
1267
+ ## Parameters
1268
+
1269
+ - `payer: party`
1270
+ - `payee: party`
1271
+ - `close_by: date`
1272
+ - `rates: unknown`
1273
+
1274
+ ## Decision ports
1275
+
1276
+ None.
1277
+
1278
+ ## Actions and clauses
1279
+
1280
+ | Action | Clauses lowered |
1281
+ | -------------- | --------------------------------------- |
1282
+ | `create` | `agent description`, `steps`, `summary` |
1283
+ | `close_period` | `due`, `steps`, `summary` |
1284
+
1285
+ # pooled_split
1286
+
1287
+ Source: [`std/settlements/pooled_split.hsx`](../../../std/settlements/pooled_split.hsx)
1288
+
1289
+ ## Export
1290
+
1291
+ `pooled_split<C>`
1292
+
1293
+ ## Parameters
1294
+
1295
+ - `payer: party`
1296
+ - `amount: money<C>`
1297
+ - `payout_due: date`
1298
+ - `split: block`
1299
+
1300
+ ## Decision ports
1301
+
1302
+ None.
1303
+
1304
+ ## Actions and clauses
1305
+
1306
+ | Action | Clauses lowered |
1307
+ | -------- | ------------------------------------------------ |
1308
+ | `create` | `agent description`, `moves`, `steps`, `summary` |
1309
+
1310
+ # premium_forward
1311
+
1312
+ Source: [`std/settlements/premium_forward.hsx`](../../../std/settlements/premium_forward.hsx)
1313
+
1314
+ ## Export
1315
+
1316
+ `premium_forward<C>`
1317
+
1318
+ ## Parameters
1319
+
1320
+ - `payer: party`
1321
+ - `carrier: party`
1322
+ - `amount: money<C>`
1323
+ - `bind: condition`
1324
+ - `commission: percent`
1325
+ - `policy_ref: optional<text>`
1326
+ - `renewal_due: optional<date>`
1327
+ - `endorsement: optional<condition>`
1328
+
1329
+ ## Decision ports
1330
+
1331
+ - `bind`
1332
+ - `endorsement`
1333
+
1334
+ ## Actions and clauses
1335
+
1336
+ | Action | Clauses lowered |
1337
+ | ----------------- | ---------------------------------------------------------------------------------------- |
1338
+ | `create` | `agent description`, `steps`, `summary` |
1339
+ | `fund_piece_1` | `agent description`, `moves`, `steps`, `summary` |
1340
+ | `fund_piece_2` | `agent description`, `moves`, `steps`, `summary` |
1341
+ | `bind` | `agent description`, `description`, `input`, `moves`, `port`, `steps`, `summary` |
1342
+ | `forward_piece_2` | `agent description`, `moves`, `steps`, `summary` |
1343
+ | `unfund_piece_1` | `agent description`, `moves`, `steps`, `summary` |
1344
+ | `abandon` | `agent description`, `steps`, `summary` |
1345
+ | `endorsement` | `agent description`, `capture input`, `description`, `input`, `port`, `steps`, `summary` |
1346
+ | `lapse` | `due`, `steps`, `summary` |
1347
+
1348
+ # reconciled_payout
1349
+
1350
+ Source: [`std/settlements/reconciled_payout.hsx`](../../../std/settlements/reconciled_payout.hsx)
1351
+
1352
+ ## Export
1353
+
1354
+ `reconciled_payout<C>`
1355
+
1356
+ ## Parameters
1357
+
1358
+ - `payer: party`
1359
+ - `beneficiary: party`
1360
+ - `amount: money<C>`
1361
+ - `beneficiary_ref: text`
1362
+ - `settle_by: date`
1363
+ - `matched_within: integer`
1364
+ - `matched_ceiling: integer`
1365
+
1366
+ ## Decision ports
1367
+
1368
+ None.
1369
+
1370
+ ## Actions and clauses
1371
+
1372
+ | Action | Clauses lowered |
1373
+ | ---------- | ---------------------------------------------------------- |
1374
+ | `create` | `agent description`, `moves`, `steps`, `summary` |
1375
+ | `instruct` | `agent description`, `moves`, `payout`, `steps`, `summary` |
1376
+ | `settle` | `due`, `moves`, `reconcile`, `steps`, `summary` |
1377
+ | `create` | `agent description`, `moves`, `steps`, `summary` |
1378
+ | `carry` | `agent description`, `moves`, `steps`, `summary` |
1379
+
1380
+ # recurring_collection
1381
+
1382
+ Source: [`std/settlements/recurring_collection.hsx`](../../../std/settlements/recurring_collection.hsx)
1383
+
1384
+ ## Export
1385
+
1386
+ `recurring_collection`
1387
+
1388
+ ## Parameters
1389
+
1390
+ - `marker: optional<text>`
1391
+
1392
+ ## Decision ports
1393
+
1394
+ None.
1395
+
1396
+ ## Actions and clauses
1397
+
1398
+ | Action | Clauses lowered |
1399
+ | --------- | --------------------------------------- |
1400
+ | `create` | `agent description`, `steps`, `summary` |
1401
+ | `collect` | `agent description`, `steps`, `summary` |
1402
+ | `end` | `agent description`, `steps`, `summary` |
1403
+
1404
+ # rotating_pool
1405
+
1406
+ Source: [`std/settlements/rotating_pool.hsx`](../../../std/settlements/rotating_pool.hsx)
1407
+
1408
+ ## Export
1409
+
1410
+ `rotating_pool<C>`
1411
+
1412
+ ## Parameters
1413
+
1414
+ - `members: optional<list<party>>`
1415
+ - `contribution: money<C>`
1416
+ - `count: integer`
1417
+ - `every: optional<text>`
1418
+ - `first_due: date`
1419
+ - `payout_order: optional<list<party>>`
1420
+ - `default_policy: optional<text>`
1421
+ - `guarantee_policy: optional<text>`
1422
+ - `guarantor: optional<party>`
1423
+ - `exit_policy: optional<text>`
1424
+ - `memo: optional<text>`
1425
+ - `membership: optional<block>`
1426
+
1427
+ ## Decision ports
1428
+
1429
+ None.
1430
+
1431
+ ## Actions and clauses
1432
+
1433
+ | Action | Clauses lowered |
1434
+ | ---------- | ------------------------------------------------- |
1435
+ | `create` | `agent description`, `moves`, `steps`, `summary` |
1436
+ | `cancel` | `agent description`, `moves`, `steps`, `summary` |
1437
+ | `activate` | `agent description`, `moves`, `steps`, `summary` |
1438
+ | `create` | `agent description`, `moves`, `steps`, `summary` |
1439
+ | `close` | `agent description`, `moves`, `steps`, `summary` |
1440
+ | `create` | `agent description`, `examples`, `moves`, `steps` |
1441
+ | `activate` | `due`, `examples`, `moves`, `steps` |
1442
+ | `disband` | `agent description`, `examples`, `moves`, `steps` |
1443
+ | `close` | `agent description`, `examples`, `moves`, `steps` |
1444
+
1445
+ # scheduled
1446
+
1447
+ Source: [`std/settlements/scheduled.hsx`](../../../std/settlements/scheduled.hsx)
1448
+
1449
+ ## Export
1450
+
1451
+ `scheduled<C>`
1452
+
1453
+ ## Parameters
1454
+
1455
+ - `payer: party`
1456
+ - `payee: party`
1457
+ - `amount: money<C>`
1458
+ - `count: optional<integer>`
1459
+ - `every: text`
1460
+ - `first_due: date`
1461
+ - `mode: optional<text>`
1462
+ - `debtor: optional<party>`
1463
+ - `advance_to: optional<party>`
1464
+ - `until: optional<condition>`
1465
+ - `month_end: optional<text>`
1466
+ - `period_liability: optional<text>`
1467
+ - `termination_drain: optional<text>`
1468
+ - `mandate: optional<condition>`
1469
+ - `derived_amount: optional<unknown>`
1470
+
1471
+ ## Decision ports
1472
+
1473
+ - `until`
1474
+ - `mandate`
1475
+
1476
+ ## Actions and clauses
1477
+
1478
+ | Action | Clauses lowered |
1479
+ | ------------------- | ------------------------------------------------------------------------------------------------- |
1480
+ | `create` | `agent description`, `steps`, `summary` |
1481
+ | `create` | `agent description`, `moves`, `steps`, `summary` |
1482
+ | `approve` | `agent description`, `steps`, `summary` |
1483
+ | `advance` | `agent description`, `moves`, `steps`, `summary` |
1484
+ | `delinquent_action` | `due`, `sets at`, `steps`, `summary` |
1485
+ | `complete` | `due`, `steps`, `summary` |
1486
+ | `write_off` | `agent description`, `steps`, `summary` |
1487
+ | `create` | `agent description`, `steps`, `summary` |
1488
+ | `repay` | `agent description`, `capture input`, `description`, `input`, `moves`, `port`, `steps`, `summary` |
1489
+ | `refund` | `agent description`, `moves`, `steps`, `summary` |
1490
+ | `create` | `agent description`, `steps`, `summary` |
1491
+ | `open_period` | `due`, `steps`, `summary` |
1492
+ | `collect_period` | `agent description`, `capture input`, `description`, `input`, `moves`, `port`, `steps`, `summary` |
1493
+ | `until` | `agent description`, `capture input`, `description`, `input`, `port`, `steps`, `summary` |
1494
+
1495
+ # security_deposit
1496
+
1497
+ Source: [`std/settlements/security_deposit.hsx`](../../../std/settlements/security_deposit.hsx)
1498
+
1499
+ ## Export
1500
+
1501
+ `security_deposit<C>`
1502
+
1503
+ ## Parameters
1504
+
1505
+ - `payer: party`
1506
+ - `holder: party`
1507
+ - `amount: money<C>`
1508
+ - `claim: optional<condition>`
1509
+ - `return: optional<condition>`
1510
+ - `claim_amount: optional<block>`
1511
+ - `deadline: optional<date>`
1512
+ - `claim_to: optional<party>`
1513
+ - `return_to: optional<party>`
1514
+ - `memo: optional<text>`
1515
+ - `claim_input: optional<block>`
1516
+ - `claim_capture: optional<block>`
1517
+ - `fund_failure_point: optional<text>`
1518
+ - `id_prefix_override: optional<text>`
1519
+
1520
+ ## Decision ports
1521
+
1522
+ - `claim`
1523
+ - `return`
1524
+
1525
+ ## Actions and clauses
1526
+
1527
+ | Action | Clauses lowered |
1528
+ | --------------- | ---------------------------------------------------------------------------------------------------------------- |
1529
+ | `create` | `agent description`, `moves`, `steps`, `summary` |
1530
+ | `place_deposit` | `agent description`, `moves`, `steps`, `summary` |
1531
+ | `claim_name` | `agent description`, `description`, `input`, `moves`, `port`, `steps`, `summary` |
1532
+ | `return_name` | `agent description`, `moves`, `steps`, `summary` |
1533
+ | `create` | `agent description`, `deadline`, `moves`, `steps`, `summary` |
1534
+ | `fund` | `agent description`, `deadline`, `moves`, `sandbox failure point`, `steps`, `summary` |
1535
+ | `claim` | `agent description`, `capture input`, `deadline`, `decided amount`, `input`, `moves`, `port`, `steps`, `summary` |
1536
+ | `return` | `agent description`, `deadline`, `moves`, `port`, `steps`, `summary` |
1537
+ | `expire` | `due`, `moves`, `steps`, `summary` |
1538
+ | `cancel` | `agent description`, `moves`, `steps`, `summary` |
1539
+
1540
+ # settlement_batch
1541
+
1542
+ Source: [`std/settlements/settlement_batch.hsx`](../../../std/settlements/settlement_batch.hsx)
1543
+
1544
+ ## Export
1545
+
1546
+ `settlement_batch<C>`
1547
+
1548
+ ## Parameters
1549
+
1550
+ - `settlement_account: party`
1551
+ - `source_capture_refs: text`
1552
+ - `fee_entries: text`
1553
+ - `external_reversal_offsets: text`
1554
+ - `close_trigger: date`
1555
+ - `payout_destination: party`
1556
+ - `negative_position: text`
1557
+ - `payout_acknowledgement: condition`
1558
+ - `payout_beneficiary_ref: text`
1559
+
1560
+ ## Decision ports
1561
+
1562
+ - `payout_acknowledgement`
1563
+
1564
+ ## Actions and clauses
1565
+
1566
+ | Action | Clauses lowered |
1567
+ | ------------------------ | ------------------------------------------------------------------------------------------------- |
1568
+ | `create` | `agent description`, `moves`, `steps`, `summary` |
1569
+ | `close` | `due`, `moves`, `steps`, `summary` |
1570
+ | `calculate` | `agent description`, `computes signed_sum`, `moves`, `steps`, `summary` |
1571
+ | `approve` | `agent description`, `moves`, `steps`, `summary` |
1572
+ | `instruct` | `agent description`, `moves`, `payout`, `steps`, `summary` |
1573
+ | `payout_acknowledgement` | `agent description`, `capture input`, `description`, `input`, `moves`, `port`, `steps`, `summary` |
1574
+ | `reconcile` | `due`, `moves`, `reconcile`, `steps`, `summary` |
1575
+ | `create` | `agent description`, `moves`, `steps`, `summary` |
1576
+ | `accrue` | `agent description`, `moves`, `steps`, `summary` |
1577
+ | `create` | `agent description`, `moves`, `steps`, `summary` |
1578
+ | `adjust` | `agent description`, `moves`, `steps`, `summary` |
1579
+ | `correct` | `agent description`, `moves`, `steps`, `summary` |
1580
+
1581
+ # swap
1582
+
1583
+ Source: [`std/settlements/swap.hsx`](../../../std/settlements/swap.hsx)
1584
+
1585
+ ## Export
1586
+
1587
+ `swap<C>`
1588
+
1589
+ ## Parameters
1590
+
1591
+ - `between: list<party>`
1592
+ - `amounts: block`
1593
+ - `fees: block`
1594
+ - `release: condition`
1595
+ - `dispute: condition`
1596
+ - `side_names: optional<block>`
1597
+ - `lifecycle_state_order: optional<list<text>>`
1598
+ - `action_bindings: optional<block>`
1599
+ - `parked_states: optional<block>`
1600
+ - `fixed_prefix: optional<text>`
1601
+
1602
+ ## Decision ports
1603
+
1604
+ - `release`
1605
+ - `dispute`
1606
+
1607
+ ## Actions and clauses
1608
+
1609
+ | Action | Clauses lowered |
1610
+ | --------- | --------------------------------------------------------------------------------------------------------------------------- |
1611
+ | `abandon` | `agent description`, `moves`, `public action`, `steps`, `summary` |
1612
+ | `cancel` | `agent description`, `moves`, `public action`, `steps`, `summary` |
1613
+ | `create` | `agent description`, `moves`, `public action`, `steps`, `summary` |
1614
+ | `dispute` | `agent description`, `deadline`, `moves`, `port`, `public action`, `steps`, `summary` |
1615
+ | `fund` | `agent description`, `moves`, `public action`, `steps`, `summary` |
1616
+ | `post` | `due`, `moves`, `steps`, `summary` |
1617
+ | `release` | `agent description`, `moves`, `port`, `public action`, `sets at`, `steps`, `summary` |
1618
+ | `create` | `agent description`, `moves`, `public action`, `steps`, `summary` |
1619
+ | `fund` | `agent description`, `event name`, `moves`, `public action`, `sandbox failure point`, `steps`, `summary` |
1620
+ | `release` | `agent description`, `event name`, `moves`, `port`, `public action`, `sandbox failure point`, `sets at`, `steps`, `summary` |
1621
+ | `post` | `due`, `event name`, `moves`, `steps`, `summary` |
1622
+ | `dispute` | `agent description`, `deadline`, `event name`, `moves`, `port`, `public action`, `steps`, `summary` |
1623
+ | `cancel` | `agent description`, `event name`, `moves`, `public action`, `steps`, `summary` |
1624
+ | `abandon` | `agent description`, `event name`, `moves`, `public action`, `steps`, `summary` |
1625
+
1626
+ # threshold_pool
1627
+
1628
+ Source: [`std/settlements/threshold_pool.hsx`](../../../std/settlements/threshold_pool.hsx)
1629
+
1630
+ ## Export
1631
+
1632
+ `threshold_pool<C>`
1633
+
1634
+ ## Parameters
1635
+
1636
+ - `contributor: optional<party>`
1637
+ - `beneficiary: optional<party>`
1638
+ - `target: money<C>`
1639
+ - `commitment: money<C>`
1640
+ - `max_contributors: optional<integer>`
1641
+ - `close_by: date`
1642
+ - `close_policy: optional<text>`
1643
+ - `overfund_policy: optional<text>`
1644
+ - `cancel_policy: optional<text>`
1645
+ - `fail_policy: optional<text>`
1646
+ - `beneficiary_account: optional<account<C>>`
1647
+ - `memo: optional<text>`
1648
+ - `contribution_instrument: optional<block>`
1649
+ - `wording: optional<block>`
1650
+
1651
+ ## Decision ports
1652
+
1653
+ None.
1654
+
1655
+ ## Actions and clauses
1656
+
1657
+ | Action | Clauses lowered |
1658
+ | ---------- | ------------------------------------------------- |
1659
+ | `create` | `agent description`, `moves`, `steps`, `summary` |
1660
+ | `activate` | `due`, `moves`, `steps`, `summary` |
1661
+ | `fail` | `due`, `moves`, `steps`, `summary` |
1662
+ | `close` | `agent description`, `moves`, `steps`, `summary` |
1663
+ | `create` | `agent description`, `moves`, `steps`, `summary` |
1664
+ | `cancel` | `agent description`, `moves`, `steps`, `summary` |
1665
+ | `collect` | `agent description`, `moves`, `steps`, `summary` |
1666
+ | `refund` | `agent description`, `moves`, `steps`, `summary` |
1667
+ | `create` | `agent description`, `examples`, `moves`, `steps` |
1668
+ | `activate` | `due`, `examples`, `moves`, `steps` |
1669
+ | `fail` | `due`, `examples`, `moves`, `steps` |
1670
+ | `close` | `agent description`, `examples`, `moves`, `steps` |
1671
+
1672
+ # weighted_distribution
1673
+
1674
+ Source: [`std/settlements/weighted_distribution.hsx`](../../../std/settlements/weighted_distribution.hsx)
1675
+
1676
+ ## Export
1677
+
1678
+ `weighted_distribution<C>`
1679
+
1680
+ ## Parameters
1681
+
1682
+ - `source: party`
1683
+ - `recipient: party`
1684
+ - `amount: money<C>`
1685
+ - `record_at: date`
1686
+ - `weight: optional<money<C>>`
1687
+ - `max_recipients: optional<integer>`
1688
+ - `snapshot: optional<condition>`
1689
+ - `rounding_policy: optional<text>`
1690
+ - `withholding_policy: optional<text>`
1691
+ - `correction_policy: optional<text>`
1692
+ - `flat: optional<block>`
1693
+ - `id_prefix_override: optional<text>`
1694
+
1695
+ ## Decision ports
1696
+
1697
+ - `snapshot`
1698
+
1699
+ ## Actions and clauses
1700
+
1701
+ | Action | Clauses lowered |
1702
+ | ---------- | ------------------------------------------------------------------------------------------------- |
1703
+ | `create` | `agent description`, `moves`, `steps`, `summary` |
1704
+ | `snapshot` | `agent description`, `capture input`, `description`, `input`, `moves`, `port`, `steps`, `summary` |
1705
+ | `create` | `agent description`, `moves`, `steps`, `summary` |
1706
+ | `payout` | `agent description`, `computes distribute`, `moves`, `steps`, `summary` |
1707
+ | `create` | `agent description`, `moves`, `requires refs`, `steps`, `summary` |
1708
+ | `payout` | `computes distribute`, `due`, `moves`, `steps`, `summary` |
1709
+
1710
+ # Types
1711
+
1712
+ HSX checks types before it emits UDL. Money and account values carry a currency parameter, and no implicit currency conversion exists.
1713
+
1714
+ | Kind | Meaning |
1715
+ | ----------- | -------------------------------------------------------------------- |
1716
+ | `account` | A currency-indexed ledger account reference. |
1717
+ | `boolean` | A compile-time or stored true or false value. |
1718
+ | `bps` | An integer basis-point value. |
1719
+ | `condition` | A declared decision port. |
1720
+ | `date` | A stored date-time string checked by UDL. |
1721
+ | `integer` | A bounded whole number. |
1722
+ | `money` | A currency-indexed minor-unit amount. |
1723
+ | `party` | A declared program party. |
1724
+ | `percent` | An exact percentage with basis-point precision. |
1725
+ | `ref` | A typed reference to another instrument. |
1726
+ | `text` | A finite string value. |
1727
+ | `unknown` | An internal checker result that source must resolve before lowering. |
1728
+
1729
+ # UDL output
1730
+
1731
+ An accepted compile returns three artifacts.
1732
+
1733
+ | Artifact | Contents |
1734
+ | -------------- | ----------------------------------------------------------------------------------- |
1735
+ | `document` | The canonical UDL object. Serialize it with `serializeUdl` from `@hyperscale0/udl`. |
1736
+ | `originMap` | Canonical UDL paths mapped to authored HSX spans. |
1737
+ | `costManifest` | The deterministic manifest pinned to the supplied rate card. |
1738
+
1739
+ Canonical UDL sorts object keys, preserves array order, uses two-space JSON indentation, and ends with one line feed.