@hyperscale0/hsx 2.4.0 → 3.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 (249) hide show
  1. package/CHANGELOG.md +2 -400
  2. package/README.md +3 -92
  3. package/dist/src/ast.d.ts +99 -310
  4. package/dist/src/ast.d.ts.map +1 -1
  5. package/dist/src/ast.js +16 -69
  6. package/dist/src/ast.js.map +1 -1
  7. package/dist/src/cli.d.ts +6 -19
  8. package/dist/src/cli.d.ts.map +1 -1
  9. package/dist/src/cli.js +76 -315
  10. package/dist/src/cli.js.map +1 -1
  11. package/dist/src/compile.d.ts +23 -73
  12. package/dist/src/compile.d.ts.map +1 -1
  13. package/dist/src/compile.js +1113 -148
  14. package/dist/src/compile.js.map +1 -1
  15. package/dist/src/cost.d.ts +8 -77
  16. package/dist/src/cost.d.ts.map +1 -1
  17. package/dist/src/cost.js +13 -422
  18. package/dist/src/cost.js.map +1 -1
  19. package/dist/src/format.d.ts +8 -7
  20. package/dist/src/format.d.ts.map +1 -1
  21. package/dist/src/format.js +9 -175
  22. package/dist/src/format.js.map +1 -1
  23. package/dist/src/headers.d.ts +35 -0
  24. package/dist/src/headers.d.ts.map +1 -0
  25. package/dist/src/headers.js +108 -0
  26. package/dist/src/headers.js.map +1 -0
  27. package/dist/src/index.d.ts +6 -12
  28. package/dist/src/index.d.ts.map +1 -1
  29. package/dist/src/index.js +4 -9
  30. package/dist/src/index.js.map +1 -1
  31. package/dist/src/lex.d.ts +8 -28
  32. package/dist/src/lex.d.ts.map +1 -1
  33. package/dist/src/lex.js +88 -146
  34. package/dist/src/lex.js.map +1 -1
  35. package/dist/src/parse.d.ts +4 -17
  36. package/dist/src/parse.d.ts.map +1 -1
  37. package/dist/src/parse.js +402 -1040
  38. package/dist/src/parse.js.map +1 -1
  39. package/dist/src/std-bundle.d.ts.map +1 -1
  40. package/dist/src/std-bundle.js +12 -20
  41. package/dist/src/std-bundle.js.map +1 -1
  42. package/dist/src/std-library.d.ts +1 -1
  43. package/dist/src/std-library.d.ts.map +1 -1
  44. package/dist/src/std-library.js +1 -5
  45. package/dist/src/std-library.js.map +1 -1
  46. package/dist/src/tunables.d.ts +7 -0
  47. package/dist/src/tunables.d.ts.map +1 -0
  48. package/dist/src/tunables.js +26 -0
  49. package/dist/src/tunables.js.map +1 -0
  50. package/dist/src/version.d.ts +2 -4
  51. package/dist/src/version.d.ts.map +1 -1
  52. package/dist/src/version.js +2 -4
  53. package/dist/src/version.js.map +1 -1
  54. package/docs/README.md +179 -41
  55. package/docs/headers.md +44 -0
  56. package/examples/cost-table.json +99 -751
  57. package/examples/library.hsx +59 -0
  58. package/package.json +9 -17
  59. package/src/ast.ts +82 -441
  60. package/src/cli.ts +77 -362
  61. package/src/compile.ts +1535 -247
  62. package/src/cost.ts +28 -671
  63. package/src/format.ts +12 -256
  64. package/src/headers.ts +126 -0
  65. package/src/index.ts +7 -39
  66. package/src/lex.ts +99 -195
  67. package/src/parse.ts +403 -1209
  68. package/src/std-bundle.ts +12 -20
  69. package/src/std-library.ts +2 -7
  70. package/src/tunables.ts +31 -0
  71. package/src/version.ts +2 -5
  72. package/std/approvals.hsx +17 -0
  73. package/std/cards.hsx +63 -0
  74. package/std/collections.hsx +31 -0
  75. package/std/escrow.hsx +43 -0
  76. package/std/financing.hsx +372 -0
  77. package/std/insurance.hsx +59 -0
  78. package/std/lending.hsx +115 -0
  79. package/std/marketplace.hsx +24 -0
  80. package/std/money.hsx +195 -0
  81. package/std/savings.hsx +44 -0
  82. package/std/travel.hsx +98 -0
  83. package/std/wallet.hsx +41 -0
  84. package/dist/src/diagnostics.d.ts +0 -13
  85. package/dist/src/diagnostics.d.ts.map +0 -1
  86. package/dist/src/diagnostics.js +0 -587
  87. package/dist/src/diagnostics.js.map +0 -1
  88. package/dist/src/emit.d.ts +0 -51
  89. package/dist/src/emit.d.ts.map +0 -1
  90. package/dist/src/emit.js +0 -192
  91. package/dist/src/emit.js.map +0 -1
  92. package/dist/src/entry-overrides.d.ts +0 -58
  93. package/dist/src/entry-overrides.d.ts.map +0 -1
  94. package/dist/src/entry-overrides.js +0 -284
  95. package/dist/src/entry-overrides.js.map +0 -1
  96. package/dist/src/ir.d.ts +0 -73
  97. package/dist/src/ir.d.ts.map +0 -1
  98. package/dist/src/ir.js +0 -15
  99. package/dist/src/ir.js.map +0 -1
  100. package/dist/src/limits.d.ts +0 -23
  101. package/dist/src/limits.d.ts.map +0 -1
  102. package/dist/src/limits.js +0 -23
  103. package/dist/src/limits.js.map +0 -1
  104. package/dist/src/lsp/server.d.ts +0 -32
  105. package/dist/src/lsp/server.d.ts.map +0 -1
  106. package/dist/src/lsp/server.js +0 -391
  107. package/dist/src/lsp/server.js.map +0 -1
  108. package/dist/src/modules.d.ts +0 -38
  109. package/dist/src/modules.d.ts.map +0 -1
  110. package/dist/src/modules.js +0 -372
  111. package/dist/src/modules.js.map +0 -1
  112. package/dist/src/typecheck.d.ts +0 -8
  113. package/dist/src/typecheck.d.ts.map +0 -1
  114. package/dist/src/typecheck.js +0 -4131
  115. package/dist/src/typecheck.js.map +0 -1
  116. package/docs/guide/01-first-program.md +0 -24
  117. package/docs/guide/02-money.md +0 -25
  118. package/docs/guide/03-instruments.md +0 -93
  119. package/docs/guide/04-lifecycles.md +0 -40
  120. package/docs/guide/05-fees-and-splits.md +0 -45
  121. package/docs/guide/06-schedules.md +0 -26
  122. package/docs/guide/07-composition.md +0 -52
  123. package/docs/guide/08-writing-a-module.md +0 -85
  124. package/docs/guide/09-cost.md +0 -24
  125. package/docs/guide/10-diagnostics.md +0 -27
  126. package/docs/llms-full.txt +0 -3684
  127. package/docs/llms.txt +0 -44
  128. package/docs/piece-plans.md +0 -120
  129. package/docs/playground.md +0 -55
  130. package/docs/reference/cli.md +0 -36
  131. package/docs/reference/diagnostics.md +0 -901
  132. package/docs/reference/grammar.md +0 -38
  133. package/docs/reference/std/advance.md +0 -112
  134. package/docs/reference/std/cancellable_booking.md +0 -159
  135. package/docs/reference/std/captured_payment.md +0 -115
  136. package/docs/reference/std/conditional_disbursement.md +0 -101
  137. package/docs/reference/std/credit_facility.md +0 -108
  138. package/docs/reference/std/held_payment.md +0 -173
  139. package/docs/reference/std/instant_transfer.md +0 -97
  140. package/docs/reference/std/metered.md +0 -89
  141. package/docs/reference/std/pooled_split.md +0 -95
  142. package/docs/reference/std/premium_forward.md +0 -119
  143. package/docs/reference/std/reconciled_payout.md +0 -103
  144. package/docs/reference/std/rotating_pool.md +0 -130
  145. package/docs/reference/std/scheduled.md +0 -136
  146. package/docs/reference/std/security_deposit.md +0 -138
  147. package/docs/reference/std/settlement_batch.md +0 -123
  148. package/docs/reference/std/swap.md +0 -133
  149. package/docs/reference/std/threshold_pool.md +0 -138
  150. package/docs/reference/std/weighted_distribution.md +0 -135
  151. package/docs/reference/types.md +0 -61
  152. package/docs/reference/udl-output.md +0 -13
  153. package/examples/01-first-program/README.md +0 -45
  154. package/examples/01-first-program/tip-jar.hsx +0 -17
  155. package/examples/02-imports-and-modules/README.md +0 -96
  156. package/examples/02-imports-and-modules/photo-booth.hsx +0 -37
  157. package/examples/03-diagnostics/README.md +0 -68
  158. package/examples/03-diagnostics/corner-shop-fixed.hsx +0 -22
  159. package/examples/03-diagnostics/corner-shop.hsx +0 -19
  160. package/examples/04-complete-product/README.md +0 -84
  161. package/examples/04-complete-product/study-hall.hsx +0 -67
  162. package/examples/05-authored-instrument/README.md +0 -5
  163. package/examples/05-authored-instrument/payment.hsx +0 -37
  164. package/examples/05-watch-club/README.md +0 -6
  165. package/examples/05-watch-club/watch-club.hsx +0 -123
  166. package/examples/README.md +0 -48
  167. package/examples/advance/README.md +0 -3
  168. package/examples/advance/advance.hsx +0 -13
  169. package/examples/advance/advance.udl +0 -367
  170. package/examples/cancellable_booking/README.md +0 -3
  171. package/examples/cancellable_booking/cancellable_booking.hsx +0 -14
  172. package/examples/cancellable_booking/cancellable_booking.udl +0 -413
  173. package/examples/captured_payment/README.md +0 -3
  174. package/examples/captured_payment/captured_payment.hsx +0 -17
  175. package/examples/captured_payment/captured_payment.udl +0 -686
  176. package/examples/conditional_disbursement/README.md +0 -3
  177. package/examples/conditional_disbursement/conditional_disbursement.hsx +0 -15
  178. package/examples/conditional_disbursement/conditional_disbursement.udl +0 -418
  179. package/examples/credit_facility/README.md +0 -3
  180. package/examples/credit_facility/credit_facility.hsx +0 -24
  181. package/examples/credit_facility/credit_facility.udl +0 -1396
  182. package/examples/held_payment/README.md +0 -3
  183. package/examples/held_payment/held_payment.hsx +0 -13
  184. package/examples/held_payment/held_payment.udl +0 -569
  185. package/examples/instant_transfer/README.md +0 -3
  186. package/examples/instant_transfer/instant_transfer.hsx +0 -16
  187. package/examples/instant_transfer/instant_transfer.udl +0 -376
  188. package/examples/metered/README.md +0 -3
  189. package/examples/metered/metered.hsx +0 -13
  190. package/examples/metered/metered.udl +0 -253
  191. package/examples/pooled_split/README.md +0 -3
  192. package/examples/pooled_split/pooled_split.hsx +0 -15
  193. package/examples/pooled_split/pooled_split.udl +0 -432
  194. package/examples/premium_forward/README.md +0 -3
  195. package/examples/premium_forward/premium_forward.hsx +0 -19
  196. package/examples/premium_forward/premium_forward.udl +0 -604
  197. package/examples/reconciled_payout/README.md +0 -3
  198. package/examples/reconciled_payout/reconciled_payout.hsx +0 -13
  199. package/examples/reconciled_payout/reconciled_payout.udl +0 -312
  200. package/examples/rotating_pool/README.md +0 -3
  201. package/examples/rotating_pool/rotating_pool.hsx +0 -18
  202. package/examples/rotating_pool/rotating_pool.udl +0 -4370
  203. package/examples/scheduled/README.md +0 -3
  204. package/examples/scheduled/scheduled.hsx +0 -12
  205. package/examples/scheduled/scheduled.udl +0 -355
  206. package/examples/security_deposit/README.md +0 -3
  207. package/examples/security_deposit/security_deposit.hsx +0 -21
  208. package/examples/security_deposit/security_deposit.udl +0 -320
  209. package/examples/settlement_batch/README.md +0 -3
  210. package/examples/settlement_batch/settlement_batch.hsx +0 -19
  211. package/examples/settlement_batch/settlement_batch.udl +0 -757
  212. package/examples/swap/README.md +0 -3
  213. package/examples/swap/swap.hsx +0 -19
  214. package/examples/swap/swap.udl +0 -892
  215. package/examples/threshold_pool/README.md +0 -3
  216. package/examples/threshold_pool/threshold_pool.hsx +0 -16
  217. package/examples/threshold_pool/threshold_pool.udl +0 -680
  218. package/examples/weighted_distribution/README.md +0 -3
  219. package/examples/weighted_distribution/weighted_distribution.hsx +0 -20
  220. package/examples/weighted_distribution/weighted_distribution.udl +0 -348
  221. package/skills/hsx/SKILL.md +0 -449
  222. package/src/diagnostics.ts +0 -620
  223. package/src/emit.ts +0 -282
  224. package/src/entry-overrides.ts +0 -428
  225. package/src/ir.ts +0 -113
  226. package/src/limits.ts +0 -22
  227. package/src/lsp/server.ts +0 -460
  228. package/src/modules.ts +0 -452
  229. package/src/typecheck.ts +0 -5381
  230. package/std/SEMANTICS.md +0 -44
  231. package/std/money_flows/advance.hsx +0 -235
  232. package/std/money_flows/cancellable_booking.hsx +0 -402
  233. package/std/money_flows/captured_payment.hsx +0 -220
  234. package/std/money_flows/conditional_disbursement.hsx +0 -226
  235. package/std/money_flows/credit_facility.hsx +0 -214
  236. package/std/money_flows/held_payment.hsx +0 -812
  237. package/std/money_flows/index.hsx +0 -4
  238. package/std/money_flows/instant_transfer.hsx +0 -231
  239. package/std/money_flows/metered.hsx +0 -104
  240. package/std/money_flows/pooled_split.hsx +0 -109
  241. package/std/money_flows/premium_forward.hsx +0 -307
  242. package/std/money_flows/reconciled_payout.hsx +0 -119
  243. package/std/money_flows/rotating_pool.hsx +0 -305
  244. package/std/money_flows/scheduled.hsx +0 -599
  245. package/std/money_flows/security_deposit.hsx +0 -248
  246. package/std/money_flows/settlement_batch.hsx +0 -173
  247. package/std/money_flows/swap.hsx +0 -1192
  248. package/std/money_flows/threshold_pool.hsx +0 -307
  249. package/std/money_flows/weighted_distribution.hsx +0 -237
@@ -1 +1 @@
1
- {"version":3,"file":"std-bundle.js","sourceRoot":"","sources":["../../src/std-bundle.ts"],"names":[],"mappings":"AAAA,oEAAoE;AAEpE,MAAM,CAAC,MAAM,iBAAiB,GAAgC,IAAI,GAAG,CAAiB;IACpF,CAAC,cAAc,EAAE,26SAA26S,CAAC;IAC77S,CAAC,yBAAyB,EAAE,ytWAAytW,CAAC;IACtvW,CAAC,qCAAqC,EAAE,0jgCAA0jgC,CAAC;IACnmgC,CAAC,kCAAkC,EAAE,4pdAA4pd,CAAC;IAClsd,CAAC,0CAA0C,EAAE,shSAAshS,CAAC;IACpkS,CAAC,iCAAiC,EAAE,s8QAAs8Q,CAAC;IAC3+Q,CAAC,8BAA8B,EAAE,g73EAAg73E,CAAC;IACl93E,CAAC,uBAAuB,EAAE,8JAA8J,CAAC;IACzL,CAAC,kCAAkC,EAAE,k7fAAk7f,CAAC;IACx9f,CAAC,yBAAyB,EAAE,siIAAsiI,CAAC;IACnkI,CAAC,8BAA8B,EAAE,slOAAslO,CAAC;IACxnO,CAAC,iCAAiC,EAAE,wucAAwuc,CAAC;IAC7wc,CAAC,mCAAmC,EAAE,4hSAA4hS,CAAC;IACnkS,CAAC,+BAA+B,EAAE,ohwBAAohwB,CAAC;IACvjwB,CAAC,2BAA2B,EAAE,gu2BAAgu2B,CAAC;IAC/v2B,CAAC,kCAAkC,EAAE,+0eAA+0e,CAAC;IACr3e,CAAC,kCAAkC,EAAE,s2dAAs2d,CAAC;IAC54d,CAAC,sBAAsB,EAAE,kxuCAAkxuC,CAAC;IAC5yuC,CAAC,gCAAgC,EAAE,ktpBAAktpB,CAAC;IACtvpB,CAAC,uCAAuC,EAAE,mtgBAAmtgB,CAAC;CAC/vgB,CAAC,CAAC"}
1
+ {"version":3,"file":"std-bundle.js","sourceRoot":"","sources":["../../src/std-bundle.ts"],"names":[],"mappings":"AAAA,oEAAoE;AAEpE,MAAM,CAAC,MAAM,iBAAiB,GAAgC,IAAI,GAAG,CAAiB;IACpF,CAAC,eAAe,EAAE,u8BAAu8B,CAAC;IAC19B,CAAC,WAAW,EAAE,i5GAAi5G,CAAC;IACh6G,CAAC,iBAAiB,EAAE,suEAAsuE,CAAC;IAC3vE,CAAC,YAAY,EAAE,66DAA66D,CAAC;IAC77D,CAAC,eAAe,EAAE,inhCAAinhC,CAAC;IACpohC,CAAC,eAAe,EAAE,ojGAAojG,CAAC;IACvkG,CAAC,aAAa,EAAE,ohPAAohP,CAAC;IACriP,CAAC,iBAAiB,EAAE,ujCAAujC,CAAC;IAC5kC,CAAC,WAAW,EAAE,2tWAA2tW,CAAC;IAC1uW,CAAC,aAAa,EAAE,qmGAAqmG,CAAC;IACtnG,CAAC,YAAY,EAAE,0zLAA0zL,CAAC;IAC10L,CAAC,YAAY,EAAE,w1DAAw1D,CAAC;CACz2D,CAAC,CAAC"}
@@ -1,5 +1,5 @@
1
1
  export interface StandardLibrary {
2
- readonly source: (specifier: string, name: string) => string | undefined;
2
+ source(header: string): string | undefined;
3
3
  }
4
4
  export declare const bundledStandardLibrary: StandardLibrary;
5
5
  //# sourceMappingURL=std-library.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"std-library.d.ts","sourceRoot":"","sources":["../../src/std-library.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,eAAe;IAC9B,QAAQ,CAAC,MAAM,EAAE,CAAC,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,KAAK,MAAM,GAAG,SAAS,CAAC;CAC1E;AAED,eAAO,MAAM,sBAAsB,EAAE,eAKpC,CAAC"}
1
+ {"version":3,"file":"std-library.d.ts","sourceRoot":"","sources":["../../src/std-library.ts"],"names":[],"mappings":"AACA,MAAM,WAAW,eAAe;IAC9B,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAAC;CAC5C;AACD,eAAO,MAAM,sBAAsB,EAAE,eAEpC,CAAC"}
@@ -1,9 +1,5 @@
1
1
  import { BUNDLED_STD_FILES } from "./std-bundle.js";
2
2
  export const bundledStandardLibrary = {
3
- source(specifier, name) {
4
- if (specifier !== "std/money_flows")
5
- return undefined;
6
- return BUNDLED_STD_FILES.get(`money_flows/${name}.hsx`);
7
- },
3
+ source: (header) => BUNDLED_STD_FILES.get(`${header}.hsx`),
8
4
  };
9
5
  //# sourceMappingURL=std-library.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"std-library.js","sourceRoot":"","sources":["../../src/std-library.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AAMpD,MAAM,CAAC,MAAM,sBAAsB,GAAoB;IACrD,MAAM,CAAC,SAAiB,EAAE,IAAY;QACpC,IAAI,SAAS,KAAK,iBAAiB;YAAE,OAAO,SAAS,CAAC;QACtD,OAAO,iBAAiB,CAAC,GAAG,CAAC,eAAe,IAAI,MAAM,CAAC,CAAC;IAC1D,CAAC;CACF,CAAC"}
1
+ {"version":3,"file":"std-library.js","sourceRoot":"","sources":["../../src/std-library.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AAIpD,MAAM,CAAC,MAAM,sBAAsB,GAAoB;IACrD,MAAM,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC,iBAAiB,CAAC,GAAG,CAAC,GAAG,MAAM,MAAM,CAAC;CAC3D,CAAC"}
@@ -0,0 +1,7 @@
1
+ import type { Expr } from "./ast.ts";
2
+ /** Bounds use UDL units: minor units, basis points and milliseconds. */
3
+ export declare function tunableBounds(type: Expr): {
4
+ minimum: number | string;
5
+ maximum: number | string;
6
+ } | undefined;
7
+ //# sourceMappingURL=tunables.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tunables.d.ts","sourceRoot":"","sources":["../../src/tunables.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,UAAU,CAAC;AAErC,wEAAwE;AACxE,wBAAgB,aAAa,CAC3B,IAAI,EAAE,IAAI,GACT;IAAE,OAAO,EAAE,MAAM,GAAG,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAAA;CAAE,GAAG,SAAS,CAyBpE"}
@@ -0,0 +1,26 @@
1
+ /** Bounds use UDL units: minor units, basis points and milliseconds. */
2
+ export function tunableBounds(type) {
3
+ const name = type.kind === "call" || type.kind === "type"
4
+ ? type.name
5
+ : type.kind === "name"
6
+ ? type.value
7
+ : "";
8
+ if (name === "money")
9
+ return { minimum: "0", maximum: "999999999999999999" };
10
+ if (name === "percent")
11
+ return { minimum: 0, maximum: 10000 };
12
+ if (name === "duration")
13
+ return { minimum: 1, maximum: Number.MAX_SAFE_INTEGER };
14
+ if (name !== "integer")
15
+ return;
16
+ if (type.kind === "call") {
17
+ const numbers = type.args.map((arg) => arg.kind === "number" ? Number(arg.value) : NaN);
18
+ if (numbers.length !== 2 ||
19
+ numbers.some((value) => !Number.isSafeInteger(value)) ||
20
+ numbers[0] > numbers[1])
21
+ throw new Error("integer tunable needs a minimum and maximum");
22
+ return { minimum: numbers[0], maximum: numbers[1] };
23
+ }
24
+ return { minimum: 0, maximum: Number.MAX_SAFE_INTEGER };
25
+ }
26
+ //# sourceMappingURL=tunables.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tunables.js","sourceRoot":"","sources":["../../src/tunables.ts"],"names":[],"mappings":"AAEA,wEAAwE;AACxE,MAAM,UAAU,aAAa,CAC3B,IAAU;IAEV,MAAM,IAAI,GACR,IAAI,CAAC,IAAI,KAAK,MAAM,IAAI,IAAI,CAAC,IAAI,KAAK,MAAM;QAC1C,CAAC,CAAC,IAAI,CAAC,IAAI;QACX,CAAC,CAAC,IAAI,CAAC,IAAI,KAAK,MAAM;YACpB,CAAC,CAAC,IAAI,CAAC,KAAK;YACZ,CAAC,CAAC,EAAE,CAAC;IACX,IAAI,IAAI,KAAK,OAAO;QAAE,OAAO,EAAE,OAAO,EAAE,GAAG,EAAE,OAAO,EAAE,oBAAoB,EAAE,CAAC;IAC7E,IAAI,IAAI,KAAK,SAAS;QAAE,OAAO,EAAE,OAAO,EAAE,CAAC,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC;IAC9D,IAAI,IAAI,KAAK,UAAU;QACrB,OAAO,EAAE,OAAO,EAAE,CAAC,EAAE,OAAO,EAAE,MAAM,CAAC,gBAAgB,EAAE,CAAC;IAC1D,IAAI,IAAI,KAAK,SAAS;QAAE,OAAO;IAC/B,IAAI,IAAI,CAAC,IAAI,KAAK,MAAM,EAAE,CAAC;QACzB,MAAM,OAAO,GAAG,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CACpC,GAAG,CAAC,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,GAAG,CAChD,CAAC;QACF,IACE,OAAO,CAAC,MAAM,KAAK,CAAC;YACpB,OAAO,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,MAAM,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;YACrD,OAAO,CAAC,CAAC,CAAE,GAAG,OAAO,CAAC,CAAC,CAAE;YAEzB,MAAM,IAAI,KAAK,CAAC,6CAA6C,CAAC,CAAC;QACjE,OAAO,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC,CAAE,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC,CAAE,EAAE,CAAC;IACxD,CAAC;IACD,OAAO,EAAE,OAAO,EAAE,CAAC,EAAE,OAAO,EAAE,MAAM,CAAC,gBAAgB,EAAE,CAAC;AAC1D,CAAC"}
@@ -1,5 +1,3 @@
1
- /** Package version reported by the command line. */
2
- export declare const HSX_VERSION = "2.4.0";
3
- /** Canonical UDL contract version emitted by this compiler. */
4
- export declare const HSX_TARGET_UDL_VERSION = 1;
1
+ export declare const HSX_VERSION = "3.0.0";
2
+ export declare const HSX_TARGET_UDL_VERSION = 3;
5
3
  //# sourceMappingURL=version.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":"AAAA,oDAAoD;AACpD,eAAO,MAAM,WAAW,UAAU,CAAC;AAEnC,+DAA+D;AAC/D,eAAO,MAAM,sBAAsB,IAAI,CAAC"}
1
+ {"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,WAAW,UAAU,CAAC;AACnC,eAAO,MAAM,sBAAsB,IAAI,CAAC"}
@@ -1,5 +1,3 @@
1
- /** Package version reported by the command line. */
2
- export const HSX_VERSION = "2.4.0";
3
- /** Canonical UDL contract version emitted by this compiler. */
4
- export const HSX_TARGET_UDL_VERSION = 1;
1
+ export const HSX_VERSION = "3.0.0";
2
+ export const HSX_TARGET_UDL_VERSION = 3;
5
3
  //# sourceMappingURL=version.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":"AAAA,oDAAoD;AACpD,MAAM,CAAC,MAAM,WAAW,GAAG,OAAO,CAAC;AAEnC,+DAA+D;AAC/D,MAAM,CAAC,MAAM,sBAAsB,GAAG,CAAC,CAAC"}
1
+ {"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,WAAW,GAAG,OAAO,CAAC;AACnC,MAAM,CAAC,MAAM,sBAAsB,GAAG,CAAC,CAAC"}
package/docs/README.md CHANGED
@@ -1,41 +1,179 @@
1
- # HSX documentation
2
-
3
- Read the guide in order. Every HSX program in it runs through the compiler in
4
- the package test suite.
5
-
6
- 1. [Your first program](./guide/01-first-program.md)
7
- 2. [Money](./guide/02-money.md)
8
- 3. [Instruments](./guide/03-instruments.md)
9
- 4. [Lifecycles](./guide/04-lifecycles.md)
10
- 5. [Fees and splits](./guide/05-fees-and-splits.md)
11
- 6. [Schedules](./guide/06-schedules.md)
12
- 7. [Composition](./guide/07-composition.md)
13
- 8. [Writing a module](./guide/08-writing-a-module.md)
14
- 9. [Cost](./guide/09-cost.md)
15
- 10. [Diagnostics](./guide/10-diagnostics.md)
16
-
17
- The generated [reference](./reference/) follows the compiler, UDL vocabulary,
18
- and standard-library files. Run `bun run generate` in a source checkout to
19
- build references, the embedded standard library and playground examples. Package
20
- builds and prepack do this automatically. These outputs are ignored by git;
21
- `bun run docs:build` compiles guide examples and validates documentation links.
22
-
23
- The [browser playground](./playground.md) provides a static editing surface with
24
- live compilation, diagnostics inspection, and example programs. The hosted
25
- playground is served at https://hyperscale0.ai/playground.
26
-
27
- [Compose actions over a piece plan](./piece-plans.md) is a worked excerpt, not
28
- a standalone program: it shows the `piece_plan`, `piece_stage`, `calls` and
29
- `action_library` clauses inside an instrument.
30
-
31
- ## Examples and tooling
32
-
33
- - [Standard library examples](../examples/README.md)
34
- - [Browser playground](./playground.md)
35
- - [VS Code extension](../editors/vscode/README.md)
36
-
37
- ## Agent references
38
-
39
- Agents can start with [llms.txt](./llms.txt) or load the
40
- [HSX skill](../skills/hsx/SKILL.md). [llms-full.txt](./llms-full.txt) combines
41
- the guide and generated reference in reading order.
1
+ # HSX 3
2
+
3
+ A program declares parties and objects from headers. Currency defaults to SAR.
4
+ A party binds its account and optional role at admission. A program never carries
5
+ account ids, reference filters, credentials or bank beneficiary ids.
6
+
7
+ ```hsx
8
+ program shop "Shop"
9
+ use marketplace
10
+ use escrow
11
+ party buyer: person
12
+ party seller: business
13
+ listing = marketplace.listing { seller: seller }
14
+ order = marketplace.order { listing: listing, buyer: buyer }
15
+ sale = escrow.hold {
16
+ payer: buyer, payee: seller, for: order, accept_within: 48h
17
+ fee { seller: 1% cap 750 SAR, tax: 15% }
18
+ dispute { refund_after: return_verified }
19
+ }
20
+ ```
21
+
22
+ The header defines the available policies. The company chooses percentages, amounts, durations,
23
+ parties and typed references. `funds: sale` links the stored records through the
24
+ library's declared reference type. References can name a child, such as
25
+ `receipt: plan.settlement`. A header tunable declared `ref<T>[]` accepts one object or a list of up to 16
26
+ objects of type T. `on: [plan_3, plan_6]` creates one late-charge or collections
27
+ policy. Its references can point into either plan; selections can span both.
28
+ A plain `ref<T>` accepts one object only.
29
+ Imports are `use header`; there are no file imports, macros or executable strings.
30
+
31
+ Amounts use `750 SAR`; percentages use `2.5%`; durations use `48h`, `3d`, or `1w`.
32
+ Dates use `2026-11-28` or a timestamp with an explicit offset. Money has at most two
33
+ decimal places and percentages at most two. The compiler uses integer minor units
34
+ and basis points. Fee and tax calculations round down. Split percentages sum to
35
+ 100%; the last declared recipient receives the rounding remainder. Finite
36
+ schedules use positions 1 through n and put the division remainder in position 1.
37
+ Tax binds `programTax`. Fees default to `programOperator`. Fine, recovery and
38
+ residual destinations are party tunables. Unused `programFines` and `programCosts`
39
+ bindings are omitted.
40
+
41
+ Every action is public with a generated camelCase name: `createSale`,
42
+ `acceptSale`. `expose sale.accept as acceptDelivery` renames it;
43
+ `hide sale.refund` removes it from the public API. Visibility grants no authority.
44
+ Parent and clock actions still require their executor principal. Exposure paths
45
+ can name children: `hide plan.payment.refund`.
46
+
47
+ Accounts use cash or claim books. A move stays in one book. `account of buyer`
48
+ aliases the default cash account; `account of self` provisions an owned account.
49
+ `account(lender, cash, "capital")` binds a named account.
50
+ `account(buyer, claim, contra, "debt")` declares the borrower's claim contra account.
51
+ `account(seller, cash, external, "bank")` binds the executor-managed bank destination.
52
+ Outstanding debt is an account balance. The library pairs cash repayment with
53
+ claim reduction and represents receipts as immutable child records. Cash and loss
54
+ shares round down; the declared residual account receives leftover minor units.
55
+
56
+ The four transfer instructions are create, reserve, post and void under
57
+ `internal_transfer`. A captured transfer exposes reserved, posted, settled,
58
+ reversed or voided status. Voided means a released reservation. Settled means
59
+ provider confirmation, not an internal account balance change.
60
+
61
+ For a new record type, declare `instrument name { fields { ... } lifecycle { ... }
62
+ action create { ... } }`. Fields are `money`, `account of buyer`, `ref<order>`,
63
+ `date`, `duration`, `text`, `integer`, `percent`, `boolean`, `enum(a, b)` or
64
+ `list(date, 12)`. `?` makes a field optional; `= value` fixes a constant or a typed
65
+ calculation. Actions declare `input { reason: text }`. Headers and expert records
66
+ write ordered requirements and moves as expressions:
67
+
68
+ ```hsx
69
+ requires self.payer == self.order.buyer
70
+ requires self.order in [placed]
71
+ requires approval by underwriter
72
+ moves self.price from payer to self.held
73
+ moves self.price from self.held to payee fee fee
74
+ ```
75
+
76
+ Comparisons accept `==`, `!=`, `<`, `<=`, `>` and `>=`. A path beginning with
77
+ `self`, `input` or `party` is a field operand; a quoted string, amount or number is
78
+ a literal. `requires unique "order" on [self.order]` fixes an identity namespace.
79
+ `requires count of { instrument: child, reference: "parent", anchor: self.id,
80
+ states: [pending], limit: 12 } == 12` checks a typed selection; `sum "amount" of`
81
+ uses the same selection syntax. `invariants` accepts these requirement expressions.
82
+ `requires hours self.now between 8 and 20 timezone "Asia/Riyadh"` checks local hours.
83
+ `requires evidence self.payer family registry check ownership result verified
84
+ maxAge 1d` requires a recent completed provider check.
85
+
86
+ `moves reserve amount from payer to payee capture receipt` reserves a transfer;
87
+ `moves post self.receipt` posts it and `moves void self.receipt` releases it.
88
+ `moves amount from payer shares shares` expands a declared split. Optional `fee`,
89
+ `capture` and `key` modifiers follow a move in that order. Repeated clauses keep
90
+ their declaration order. The JSON-like clause form remains accepted and lowers
91
+ to the same [UDL clauses](../../udl/spec/README.md).
92
+ They cannot add kernel instructions. `at(list, position)` reads a dated list;
93
+ `aggregate(selection, "amount")` sums selected money; `ratio(amount, weight, total)`
94
+ floors a weighted share. `records` declares child types. `invoke` can create a child
95
+ with typed input in the same transaction.
96
+
97
+ An `approval` tunable binds a party and emits a decision record for each gated
98
+ action, including child actions. `approval: underwriter` needs no separate object.
99
+ Generated records are named `<object>_<action>_decision`; child names retain their
100
+ object prefix. `requires approval by approver for approve is declined` reuses the
101
+ approve decision for a declined branch. Decisions keep the target action's typed
102
+ material input and expiry. `approvals.decision` remains available to attach an
103
+ explicit decision to an action without a library approval tunable. A decision
104
+ alone does not add a requirement to that action. Approval declarations with
105
+ `input: "material"` infer immutable material fields from the target action's input.
106
+ The compiler removes branches excluded by fixed enum tunables. An invalid program reports its source line
107
+ and a correction. No artifact is returned with diagnostics.
108
+
109
+ ## Financing policies
110
+
111
+ `financing.installments` keeps principal and fixed flat profit as claims from
112
+ activation. The company chooses where funding goes and when profit becomes earned.
113
+ All choices use accounts, calculations and moves in the same two books.
114
+
115
+ | Tunable | Default | Selected behavior |
116
+ | ---------------------------------- | ------------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
117
+ | `disburse_to` | `funds` | `funds` pays down payment and principal into the hold and confirms it. `borrower` credits principal to the borrower's balance. |
118
+ | `profit_earned` | `on_payment` | `on_payment` collects unearned profit on payment. `by_schedule` moves unearned claims to earned claims at each slice's date. `at_disbursement` makes that move at activation. Cash arrives only on payment. |
119
+ | `apply` | `fines_profit_principal` | Collect assessed fines by overdue date, then evidenced costs, profit and principal. `principal_profit` collects principal then profit. `pro_rata` uses the slice's fixed principal:profit ratio, caps each side by its collectible balance, and assigns the remainder without stranding cash. |
120
+ | `payoff_rebate` | `100%` | Reverse this share of unearned profit to borrower debt. Collect the remainder and all earned profit with outstanding principal. |
121
+ | `late_charge.fines_to` | `programOperator` | Receive fine cash and fund its refunds. |
122
+ | `late_charge.costs_to` | `programOperator` | Receive evidenced recovery cash and fund its refunds. |
123
+ | `collections.case.fee` | `20%` | After payment succeeds, transfer this share of the payment amount from plan capital to the agency. |
124
+ | `lending.distribution.residual_to` | `programOperator` | Receive the cash remainder and own the claim loss remainder after weighted distribution. |
125
+
126
+ Each slice owns separate unearned and earned claim accounts. Scheduled recognition
127
+ uses a dated child record so a partial payment cannot disable the maturity clock.
128
+ A normal payment collects only earned profit for the schedule and disbursement
129
+ choices; payoff can also collect non-rebated unearned profit. Partial fines and
130
+ costs stay assessed until their receivable reaches zero. Immutable receipts let
131
+ a refund restore only what that payment collected. The plan's payment receipt
132
+ records actual principal and profit after all ordered collections finish.
133
+ Write-off moves principal and earned profit claims to loss and reverses unearned
134
+ profit to debt. There is no provision policy or write-off tunable.
135
+
136
+ ## Header branches and bounds
137
+
138
+ A header may select action clauses at compile time:
139
+
140
+ ```hsx
141
+ when disburse_to is borrower {
142
+ moves self.principal from self.capital to self.borrower
143
+ }
144
+ ```
145
+
146
+ `when <enum tunable> is <value>` accepts requirements, calculations, moves and
147
+ invocations, including nested branches. The compiler emits only the selected
148
+ clauses and preserves their order within each UDL phase. Lifecycle and actor
149
+ clauses stay outside branches. Calculations and requirements run before moves;
150
+ invocations run after moves. A collections fee therefore uses an internal action
151
+ invoked after payment. Clock and parent actions have no public API name.
152
+
153
+ `integer(1, 366)` declares an inclusive tunable bound. The compiler-owned manifest
154
+ publishes enum values, numeric minima and maxima, and cross-tunable constraints.
155
+ Bounds use minor units for money, basis points for percentages and milliseconds
156
+ for durations. Money spans 0 through 999999999999999999 minor units; percentages
157
+ span 0 through 10000 basis points. Durations start at 1 millisecond. Integers
158
+ default to 0 through 9007199254740991 unless their declaration narrows the range. For example, `constraints { contact_from: less_than(contact_until) }`
159
+ requires a valid hours interval. `at_most` and `greater_than` are also supported.
160
+ A refusal names the tunable. Empty `all(type)` selections lower to zero aggregates
161
+ or no invocations, so a plan does not require a late-charge object.
162
+
163
+ The permutation spec builds a dependency-closed program per object. It takes each
164
+ enum value and the minimum, default or example value, and a large numeric value.
165
+ It uses the full product through 512 cases and pair coverage above that. Invalid
166
+ bound combinations must refuse with a named diagnostic. Valid cases must produce
167
+ valid UDL and retain public names on every caller action. This proves compilation,
168
+ not executed balances or bank settlement.
169
+
170
+ Build with `hsx build company.hsx --out company.udl.json`; check with
171
+ `hsx check company.hsx`; print instruction counts with `hsx cost company.hsx`.
172
+ Print the compiler-owned object manifest with `hsx headers --json`.
173
+ The compiler API is `compile(source)`. A valid result contains `artifacts.document`,
174
+ `costManifest` and source origins. Instruction counts are not bank tariffs or a
175
+ promise of provider execution cost.
176
+
177
+ The [header inventory](headers.md) is generated from the declarations. The
178
+ [executable inventory](../examples/library.hsx) exercises every public object.
179
+ The [playground](../playground/index.html) compiles locally in the browser.
@@ -0,0 +1,44 @@
1
+ # Header inventory
2
+
3
+ Each company selects library policies through typed tunables.
4
+ `ref<T>[]` accepts one reference or up to 16 references as one policy. `approval` accepts a party and generates the required decision records.
5
+
6
+ | Object | Tunables |
7
+ | ---------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
8
+ | money.transfer | `payer: party`, `payee: party`, `amount: money = runtime` |
9
+ | money.hold | `payer: party`, `payee: party`, `amount: money = runtime` |
10
+ | money.split | `payer: party`, `amount: money = runtime`, `shares: split = { programOperator: 100% }` |
11
+ | money.schedule | `payer: party`, `payee: party`, `amount: money = runtime`, `count: integer(1, 366) = 12` |
12
+ | money.pool | `payer: party`, `payee: party`, `target: money`, `closes: date` |
13
+ | money.swap | `first: party`, `second: party`, `first_amount: money`, `second_amount: money`, `expires: date` |
14
+ | money.deposit | `payer: party`, `payee: party`, `amount: money`, `expires: date`, `approval: approval` |
15
+ | money.payout | `payer: party`, `payee: party`, `amount: money = runtime`, `reconcile_within: duration = 3d` |
16
+ | money.metered | `payer: party`, `payee: party`, `unit_price: money`, `units: integer = 1`, `fee: fee = { seller: 0% }` |
17
+ | money.batch | `payer: party`, `payee: party`, `closes: date`, `approval: approval`, `reconcile_within: duration = 3d` |
18
+ | marketplace.listing | `seller: party` |
19
+ | marketplace.order | `listing: ref<marketplace.listing>`, `buyer: party` |
20
+ | escrow.hold | `payer: party`, `payee: party`, `for: ref<marketplace.order>`, `accept_within: duration = 48h`, `fee: fee = { seller: 0%, tax: 0% }`, `dispute: policy = { refund_after: return_verified }` |
21
+ | wallet.balance | `holder: party`, `spend_limit: money = 100000 SAR` |
22
+ | wallet.spend | `wallet: ref<wallet.balance>`, `payee: party` |
23
+ | financing.installments | `months: integer(1, 366)`, `profit: percent`, `disburse_to: enum(funds, borrower) = funds`, `profit_earned: enum(on_payment, by_schedule, at_disbursement) = on_payment`, `apply: enum(fines_profit_principal, principal_profit, pro_rata) = fines_profit_principal`, `payoff_rebate: percent = 100%`, `down_payment: percent = 0%`, `funds: ref`, `approval: approval`, `borrower: party = party(person)`, `capital: party = programOperator`, `profit_to: party = programOperator`, `limits: ref<financing.limits> = object(financing.limits)` |
24
+ | financing.late_charge | `on: ref<financing.installments>[]`, `grace: duration = 3d`, `fine: money = 50 SAR`, `cap: money = 25 SAR`, `fines_to: party = programOperator`, `costs_to: party = programOperator`, `approval: approval = programOperator`, `borrower: party = party(person)` |
25
+ | financing.limits | `per_borrower: money`, `portfolio: money`, `borrower: party = party(person)`, `active_plans: integer = 1` |
26
+ | financing.credit_line | `borrower: party`, `lender: party`, `limit: money`, `expires: date` |
27
+ | financing.advance | `line: ref<financing.credit_line>`, `amount: money = runtime` |
28
+ | lending.round | `borrower: party`, `capital: party`, `plan: ref<financing.installments> = object(financing.installments)`, `months: integer(1, 366) = 3`, `profit: percent = 3%`, `minimum_ticket: money = 100 SAR`, `investor_cap: percent = 20%`, `commitments: ref<lending.commitment> = object(lending.commitment)` |
29
+ | lending.commitment | `round: ref<lending.round>`, `wallet: ref<wallet.balance>`, `investor: party = party(person)` |
30
+ | lending.distribution | `round: ref<lending.round>`, `receipt: ref`, `commitments: ref<lending.commitment> = object(lending.commitment)`, `mode: enum(cash, loss) = cash`, `residual_to: party = programOperator`, `fee: percent = 1%`, `tax: percent = 15%` |
31
+ | insurance.cover | `holder: party`, `insurer: party`, `commission: percent = 0%`, `covers: ref`, `premium: money = runtime` |
32
+ | insurance.claim | `cover: ref<insurance.cover>`, `approved_by: approval` |
33
+ | approvals.decision | `for: ref`, `approved_by: party`, `action: text = "approve"` |
34
+ | collections.case | `on: ref<financing.installments>[]`, `agency: approval`, `overdue: duration = 3d`, `fee: percent = 20%` |
35
+ | collections.contact | `case: ref<collections.case>[]`, `agency: party`, `max_contacts: integer = 10`, `window: duration = 30d`, `contact_from: integer(0, 23) = 8`, `contact_until: integer(1, 23) = 20`, `timezone: text = "Asia/Riyadh"`; contact_from less_than contact_until |
36
+ | travel.package | `price: money`, `supplier_cost: money`, `departure: date`; supplier_cost at_most price |
37
+ | travel.booking | `package: ref<travel.package>`, `buyer: party`, `supplier: approval`, `cover: ref<insurance.cover>`, `deposit: percent = 30%`, `balance_before: duration = 14d`, `confirm_within: duration = 24h`, `tax: percent = 15%`, `early_before: duration = 30d`, `middle_before: duration = 15d`, `middle_penalty: percent = 10%`, `late_penalty: percent = 30%`; early_before greater_than middle_before |
38
+ | cards.cardholder | `holder: party` |
39
+ | cards.card | `holder: ref<cards.cardholder>`, `spend_limit: money` |
40
+ | cards.authorization | `card: ref<cards.card>`, `merchant: party`, `approval: approval` |
41
+ | cards.transaction | `authorization: ref<cards.authorization>` |
42
+ | cards.dispute | `transaction: ref<cards.transaction>`, `approved_by: approval`, `within: duration = 90d` |
43
+ | savings.circle | `contribution: money`, `members: integer(1, 366)`, `starts: date`, `memberships: ref<savings.membership> = object(savings.membership)` |
44
+ | savings.membership | `circle: ref<savings.circle>`, `member: party` |