@hyperscale0/hsx 2.1.1 → 2.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (109) hide show
  1. package/CHANGELOG.md +28 -7
  2. package/dist/src/cli.d.ts +1 -1
  3. package/dist/src/cli.d.ts.map +1 -1
  4. package/dist/src/cli.js +39 -5
  5. package/dist/src/cli.js.map +1 -1
  6. package/dist/src/compile.d.ts +0 -1
  7. package/dist/src/compile.d.ts.map +1 -1
  8. package/dist/src/compile.js +15 -1
  9. package/dist/src/compile.js.map +1 -1
  10. package/dist/src/cost.d.ts +3 -3
  11. package/dist/src/cost.d.ts.map +1 -1
  12. package/dist/src/cost.js +22 -12
  13. package/dist/src/cost.js.map +1 -1
  14. package/dist/src/parse.d.ts.map +1 -1
  15. package/dist/src/parse.js +10 -14
  16. package/dist/src/parse.js.map +1 -1
  17. package/dist/src/std-bundle.d.ts.map +1 -1
  18. package/dist/src/std-bundle.js +20 -84
  19. package/dist/src/std-bundle.js.map +1 -1
  20. package/dist/src/typecheck.d.ts.map +1 -1
  21. package/dist/src/typecheck.js +171 -39
  22. package/dist/src/typecheck.js.map +1 -1
  23. package/dist/src/version.d.ts +1 -1
  24. package/dist/src/version.js +1 -1
  25. package/docs/README.md +4 -2
  26. package/docs/guide/01-first-program.md +1 -1
  27. package/docs/guide/06-schedules.md +5 -1
  28. package/docs/guide/08-writing-a-module.md +48 -0
  29. package/docs/llms-full.txt +1928 -421
  30. package/docs/llms.txt +2 -3
  31. package/docs/reference/cli.md +6 -5
  32. package/docs/reference/diagnostics.md +9 -9
  33. package/docs/reference/grammar.md +2 -3
  34. package/docs/reference/std/advance.md +94 -17
  35. package/docs/reference/std/cancellable_booking.md +138 -17
  36. package/docs/reference/std/captured_payment.md +96 -24
  37. package/docs/reference/std/conditional_disbursement.md +82 -14
  38. package/docs/reference/std/credit_facility.md +89 -16
  39. package/docs/reference/std/held_payment.md +155 -55
  40. package/docs/reference/std/instant_transfer.md +79 -12
  41. package/docs/reference/std/metered.md +71 -9
  42. package/docs/reference/std/pooled_split.md +76 -7
  43. package/docs/reference/std/premium_forward.md +100 -20
  44. package/docs/reference/std/reconciled_payout.md +84 -14
  45. package/docs/reference/std/rotating_pool.md +112 -24
  46. package/docs/reference/std/scheduled.md +117 -32
  47. package/docs/reference/std/security_deposit.md +119 -27
  48. package/docs/reference/std/settlement_batch.md +105 -24
  49. package/docs/reference/std/swap.md +113 -26
  50. package/docs/reference/std/threshold_pool.md +120 -29
  51. package/docs/reference/std/weighted_distribution.md +117 -21
  52. package/docs/reference/types.md +15 -15
  53. package/docs/reference/udl-output.md +6 -6
  54. package/examples/01-first-program/README.md +1 -1
  55. package/examples/{02-imports-and-archetypes → 02-imports-and-modules}/README.md +1 -1
  56. package/examples/{02-imports-and-archetypes → 02-imports-and-modules}/photo-booth.hsx +1 -1
  57. package/examples/04-complete-product/README.md +1 -1
  58. package/examples/05-authored-instrument/README.md +5 -0
  59. package/examples/05-authored-instrument/payment.hsx +37 -0
  60. package/examples/05-watch-club/watch-club.hsx +0 -1
  61. package/examples/README.md +1 -2
  62. package/examples/advance/advance.udl +29 -6
  63. package/examples/cancellable_booking/cancellable_booking.udl +19 -0
  64. package/examples/captured_payment/captured_payment.hsx +0 -4
  65. package/examples/captured_payment/captured_payment.udl +6 -0
  66. package/examples/conditional_disbursement/conditional_disbursement.hsx +0 -2
  67. package/examples/conditional_disbursement/conditional_disbursement.udl +4 -0
  68. package/examples/cost-table.json +136 -8
  69. package/examples/credit_facility/credit_facility.hsx +0 -3
  70. package/examples/credit_facility/credit_facility.udl +17 -1
  71. package/examples/held_payment/held_payment.udl +16 -0
  72. package/examples/instant_transfer/instant_transfer.udl +6 -0
  73. package/examples/metered/metered.udl +5 -1
  74. package/examples/pooled_split/pooled_split.udl +4 -0
  75. package/examples/premium_forward/premium_forward.udl +4 -0
  76. package/examples/reconciled_payout/reconciled_payout.udl +7 -0
  77. package/examples/rotating_pool/rotating_pool.udl +8 -0
  78. package/examples/scheduled/scheduled.udl +18 -3
  79. package/examples/security_deposit/security_deposit.udl +13 -0
  80. package/examples/settlement_batch/settlement_batch.udl +4 -0
  81. package/examples/swap/swap.udl +10 -0
  82. package/examples/threshold_pool/threshold_pool.udl +11 -0
  83. package/examples/weighted_distribution/weighted_distribution.udl +9 -0
  84. package/package.json +10 -10
  85. package/skills/hsx/SKILL.md +2 -36
  86. package/src/cli.ts +41 -5
  87. package/src/compile.ts +14 -6
  88. package/src/cost.ts +13 -16
  89. package/src/parse.ts +15 -10
  90. package/src/std-bundle.ts +21 -88
  91. package/src/typecheck.ts +207 -34
  92. package/src/version.ts +1 -1
  93. package/std/SEMANTICS.md +33 -128
  94. package/std/money_flows/advance.hsx +39 -26
  95. package/std/money_flows/cancellable_booking.hsx +275 -8
  96. package/std/money_flows/captured_payment.hsx +1 -9
  97. package/std/money_flows/conditional_disbursement.hsx +0 -6
  98. package/std/money_flows/credit_facility.hsx +0 -9
  99. package/std/money_flows/held_payment.hsx +39 -1
  100. package/std/money_flows/index.hsx +2 -1
  101. package/std/money_flows/metered.hsx +1 -5
  102. package/std/money_flows/scheduled.hsx +29 -119
  103. package/std/money_flows/threshold_pool.hsx +40 -5
  104. package/std/money_flows/weighted_distribution.hsx +47 -5
  105. package/docs/reference/std/recurring_collection.md +0 -25
  106. package/examples/recurring_collection/README.md +0 -3
  107. package/examples/recurring_collection/recurring_collection.hsx +0 -21
  108. package/examples/recurring_collection/recurring_collection.udl +0 -1135
  109. package/std/money_flows/recurring_collection.hsx +0 -72
package/docs/llms.txt CHANGED
@@ -1,8 +1,8 @@
1
- <!-- Generated by scripts/docs/build.ts for HSX 2.1.1. Do not edit. -->
1
+ <!-- Generated by scripts/docs/build.ts for HSX 2.2.0. Do not edit. -->
2
2
 
3
3
  # HSX documentation
4
4
 
5
- > Repository guide and generated compiler reference for HSX 2.1.1.
5
+ > Repository guide and generated compiler reference for HSX 2.2.0.
6
6
 
7
7
  ## Guide
8
8
 
@@ -35,7 +35,6 @@
35
35
  [pooled_split](reference/std/pooled_split.md): Standard-library module.
36
36
  [premium_forward](reference/std/premium_forward.md): Standard-library module.
37
37
  [reconciled_payout](reference/std/reconciled_payout.md): Standard-library module.
38
- [recurring_collection](reference/std/recurring_collection.md): Standard-library module.
39
38
  [rotating_pool](reference/std/rotating_pool.md): Standard-library module.
40
39
  [scheduled](reference/std/scheduled.md): Standard-library module.
41
40
  [security_deposit](reference/std/security_deposit.md): Standard-library module.
@@ -1,14 +1,14 @@
1
- <!-- Generated by scripts/docs/build.ts for HSX 2.1.1. Do not edit. -->
1
+ <!-- Generated by scripts/docs/build.ts for HSX 2.2.0. Do not edit. -->
2
2
 
3
3
  # CLI
4
4
 
5
5
  ```text
6
- hsx 2.1.1, the HSX compiler
6
+ hsx 2.2.0, the HSX compiler
7
7
 
8
8
  Usage:
9
- hsx check <file.hsx> [--strict]
10
- hsx build <file.hsx> [--out <file.json>] [--strict]
11
- hsx cost <file.hsx> [--json] [--out <file.json>] [--strict]
9
+ hsx check <file.hsx> [--catalog <catalog.udl>] [--strict]
10
+ hsx build <file.hsx> [--catalog <catalog.udl>] [--out <file.json>] [--strict]
11
+ hsx cost <file.hsx> [--catalog <catalog.udl>] [--json] [--out <file.json>] [--strict]
12
12
  hsx explain <HSX####>
13
13
  hsx format <file.hsx>
14
14
  hsx lsp
@@ -24,6 +24,7 @@ Commands:
24
24
  lsp Run the language server over stdin and stdout.
25
25
 
26
26
  Options:
27
+ --catalog <file> Read the published instrument catalogue as canonical UDL JSON.
27
28
  --json Print the cost manifest as JSON instead of a table.
28
29
  --out <file> Write build or cost JSON to this path instead of stdout.
29
30
  --strict Treat warning-severity diagnostics as failures.
@@ -1,4 +1,4 @@
1
- <!-- Generated by scripts/docs/build.ts for HSX 2.1.1. Do not edit. -->
1
+ <!-- Generated by scripts/docs/build.ts for HSX 2.2.0. Do not edit. -->
2
2
 
3
3
  # Diagnostics
4
4
 
@@ -39,7 +39,7 @@ instrument probe {
39
39
  agent_description: "Create a probe instance.";
40
40
  steps: [];
41
41
  }
42
-
42
+
43
43
  }
44
44
  program second "Second"
45
45
  ```
@@ -70,7 +70,7 @@ instrument probe {
70
70
  agent_description: "Create a probe instance.";
71
71
  steps: [];
72
72
  }
73
-
73
+
74
74
  }
75
75
  instrument probe { fields {}; lifecycle { states created; initial created; }; action create { steps: []; }; }
76
76
  ```
@@ -122,7 +122,7 @@ instrument probe {
122
122
  agent_description: "Create a probe instance.";
123
123
  steps: [];
124
124
  }
125
-
125
+
126
126
  }
127
127
  subject vehicle { title: "Vehicle"; }
128
128
  ```
@@ -340,7 +340,7 @@ instrument probe {
340
340
  agent_description: "Create a probe instance.";
341
341
  steps: [];
342
342
  }
343
-
343
+
344
344
  }
345
345
  const fee: money<SAR> = USD 1.00
346
346
  ```
@@ -361,7 +361,7 @@ instrument probe {
361
361
  agent_description: "Create a probe instance.";
362
362
  steps: [];
363
363
  }
364
-
364
+
365
365
  }
366
366
  const fee: money<SAR> = SAR 1.001
367
367
  ```
@@ -481,7 +481,7 @@ instrument probe {
481
481
  agent_description: "Create a probe instance.";
482
482
  steps: [];
483
483
  }
484
-
484
+
485
485
  }
486
486
  ```
487
487
 
@@ -517,7 +517,7 @@ instrument probe {
517
517
  agent_description: "Create a probe instance.";
518
518
  steps: [];
519
519
  }
520
-
520
+
521
521
  }
522
522
  ```
523
523
 
@@ -537,7 +537,7 @@ instrument probe {
537
537
  agent_description: "Create a probe instance.";
538
538
  steps: [];
539
539
  }
540
-
540
+
541
541
  }
542
542
  ```
543
543
 
@@ -1,4 +1,4 @@
1
- <!-- Generated by scripts/docs/build.ts for HSX 2.1.1. Do not edit. -->
1
+ <!-- Generated by scripts/docs/build.ts for HSX 2.2.0. Do not edit. -->
2
2
 
3
3
  # Grammar vocabulary
4
4
 
@@ -14,7 +14,7 @@ The parser is hand-written. This page records the exported lexer vocabulary, the
14
14
 
15
15
  ## Typed clause spellings
16
16
 
17
- `action library`, `agent description`, `calls`, `capture input`, `commit`, `quote`, `decided amount`, `deadline`, `decision`, `computes distribute`, `description`, `due`, `earnable`, `event name`, `examples`, `input`, `moves`, `payout`, `piece plan`, `piece stage`, `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`, `journeys`, `nav`, `partitions`, `subject`, `summary`, `surface visibility`, `template id`, `title`, `update`
17
+ `funding`, `receipt distribution`, `requires allocation`, `allocation`, `contributions`, `allocate`, `contribution stage`, `date order`, `unique`, `transitions refs`, `action library`, `agent description`, `calls`, `requires input`, `engine owned`, `capture engine`, `capture input`, `commit`, `quote`, `decided amount`, `deadline`, `decision`, `computes distribute`, `description`, `due`, `earnable`, `event name`, `examples`, `input`, `moves`, `payout`, `piece plan`, `piece stage`, `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 binding`, `template id`, `title`, `update`, `request authority`
18
18
 
19
19
  ## Standard-library modules
20
20
 
@@ -29,7 +29,6 @@ The parser is hand-written. This page records the exported lexer vocabulary, the
29
29
  - `pooled_split`
30
30
  - `premium_forward`
31
31
  - `reconciled_payout`
32
- - `recurring_collection`
33
32
  - `rotating_pool`
34
33
  - `scheduled`
35
34
  - `security_deposit`
@@ -1,4 +1,4 @@
1
- <!-- Generated by scripts/docs/build.ts for HSX 2.1.1. Do not edit. -->
1
+ <!-- Generated by scripts/docs/build.ts for HSX 2.2.0. Do not edit. -->
2
2
 
3
3
  # advance
4
4
 
@@ -10,14 +10,91 @@ Source: [`std/money_flows/advance.hsx`](../../../std/money_flows/advance.hsx)
10
10
 
11
11
  ## Parameters
12
12
 
13
- - `funder: party`
14
- - `to: party`
15
- - `amount: money<C>`
16
- - `fee: optional<percent>`
17
- - `count: optional<integer>`
18
- - `every: optional<text>`
19
- - `first_due: optional<date>`
20
- - `against: optional<ref>`
13
+ | Parameter | Type | Required | Meaning |
14
+ | --- | --- | --- | --- |
15
+ | `funder` | `party` | Yes | The party providing the upfront capital. |
16
+ | `to` | `party` | Yes | The party receiving the advance and responsible for repayment. |
17
+ | `amount` | `money<C>` | Yes | Total advanced principal in minor units of currency `C`. |
18
+ | `fee` | `optional<percent>` | No | Optional markup percentage fee charged on the advance (basis points precision). |
19
+ | `count` | `optional<integer>` | No | Optional number of scheduled installment repayments. |
20
+ | `every` | `optional<text>` | No | Optional recurrence duration between installments (e.g. `"P30D"`). |
21
+ | `first_due` | `optional<date>` | No | Optional date for the first installment repayment. |
22
+ | `against` | `optional<ref>` | No | Optional reference to a hold instrument whose release will be carved to repay the advance. |
23
+ | `repayment_source` | `optional<party>` | No | Optional party repaying when distinct from the capital recipient. |
24
+ | `profit_to` | `optional<party>` | No | Optional recipient of profit, separated from principal repayments. |
25
+ | `dated` | `optional<boolean>` | No | Require an explicit signed date for each repayment instead of duration offsets. |
26
+
27
+ Required means required by the template signature. A selected mode may also need parameters marked optional; the guidance below describes those combinations.
28
+
29
+ ## Module guidance
30
+
31
+ Upfront capital disbursement repaid by carving future held payment releases or over scheduled installments.
32
+
33
+ ### Purpose
34
+
35
+ `advance` provides working capital, merchant cash advances, or contractor pre-funding from a funder to a recipient.
36
+ Repayment occurs either automatically by intercepting (carving) releases from a linked escrow hold (`against`),
37
+ or over calendar-anchored installment repayments (`count`, `every`, `first_due`).
38
+
39
+ ### Selection guidance
40
+
41
+ - vs `credit_facility`: `advance` disburses a single upfront lump-sum principal that is repaid over time.
42
+ `credit_facility` establishes a reusable revolving credit line with multiple draws up to a limit,
43
+ where repayments restore available borrowing capacity.
44
+ - vs `conditional_disbursement`: `advance` expects repayment of the advanced principal plus optional fees.
45
+ `conditional_disbursement` disburses non-repayable grants, claims, or milestone payments against external evidence.
46
+ - vs `held_payment`: `held_payment` holds customer funds in escrow until delivery. An `advance` can carve repayments
47
+ directly out of a `held_payment`'s release using `against`.
48
+
49
+ ### Parameters
50
+
51
+ - `funder`: The party providing the upfront capital.
52
+ - `to`: The party receiving the advance and responsible for repayment.
53
+ - `amount`: Total advanced principal in minor units of currency `C`.
54
+ - `fee`: Optional markup percentage fee charged on the advance (basis points precision).
55
+ - `count`: Optional number of scheduled installment repayments.
56
+ - `every`: Optional recurrence duration between installments (e.g. `"P30D"`).
57
+ - `first_due`: Optional date for the first installment repayment.
58
+ - `repayment_source`: Optional party repaying when distinct from the capital recipient.
59
+ - `profit_to`: Optional recipient of profit, separated from principal repayments.
60
+ - `dated`: Require an explicit signed date for each repayment instead of duration offsets.
61
+ - `against`: Optional reference to a hold instrument whose release will be carved to repay the advance.
62
+
63
+ ### Decision ports
64
+
65
+ None. Repayment is driven by linked hold releases or scheduled calendar dates.
66
+
67
+ ### Example
68
+
69
+ ```hsx
70
+ program advance_example "Advance example"
71
+ import { advance } from "std/money_flows"
72
+ party funder: business
73
+ party recipient: business
74
+ settlement advance_payment = advance {
75
+ funder: funder
76
+ to: recipient
77
+ amount: principal: money(SAR)
78
+ fee: 2.5%
79
+ count: 2
80
+ every: P30D
81
+ first_due: firstDueAt
82
+ }
83
+ ```
84
+
85
+ ## Declared clauses
86
+
87
+ - `agent description`
88
+ - `description`
89
+ - `due`
90
+ - `id prefix`
91
+ - `moves`
92
+ - `partitions`
93
+ - `steps`
94
+ - `summary`
95
+ - `title`
96
+
97
+ This inventory covers all branches and nested instruments in the module. The selected parameters determine which clauses and actions the compiler emits. Indexed action names expand over the declared finite list.
21
98
 
22
99
  ## Decision ports
23
100
 
@@ -25,11 +102,11 @@ None.
25
102
 
26
103
  ## Actions and clauses
27
104
 
28
- | Action | Clauses lowered |
29
- | --------------------- | ------------------------------------------------ |
30
- | `create` | `agent description`, `moves`, `steps`, `summary` |
31
- | `disburse` | `agent description`, `moves`, `steps`, `summary` |
32
- | `settle` | `agent description`, `moves`, `steps`, `summary` |
33
- | `create` | `agent description`, `moves`, `steps`, `summary` |
34
- | `disburse` | `agent description`, `moves`, `steps`, `summary` |
35
- | `collect_repayment_1` | `due`, `moves`, `steps`, `summary` |
105
+ | Action | Clauses lowered |
106
+ | --- | --- |
107
+ | `create` | `agent description`, `moves`, `steps`, `summary` |
108
+ | `disburse` | `agent description`, `moves`, `steps`, `summary` |
109
+ | `settle` | `agent description`, `moves`, `steps`, `summary` |
110
+ | `create` | `agent description`, `moves`, `steps`, `summary` |
111
+ | `disburse` | `agent description`, `moves`, `steps`, `summary` |
112
+ | `collect_repayment_[i]` | `agent description`, `due`, `moves`, `steps`, `summary` |
@@ -1,4 +1,4 @@
1
- <!-- Generated by scripts/docs/build.ts for HSX 2.1.1. Do not edit. -->
1
+ <!-- Generated by scripts/docs/build.ts for HSX 2.2.0. Do not edit. -->
2
2
 
3
3
  # cancellable_booking
4
4
 
@@ -10,14 +10,124 @@ Source: [`std/money_flows/cancellable_booking.hsx`](../../../std/money_flows/can
10
10
 
11
11
  ## Parameters
12
12
 
13
- - `guest: party`
14
- - `host: party`
15
- - `amount: money<C>`
16
- - `starts_at: date`
17
- - `late_penalty_bps: integer`
18
- - `late_within: text`
19
- - `early_penalty_bps: integer`
20
- - `offer_life: text`
13
+ | Parameter | Type | Required | Meaning |
14
+ | --- | --- | --- | --- |
15
+ | `guest` | `optional<party>` | No | The booking customer paying the fee and receiving refunds. |
16
+ | `host` | `optional<party>` | No | The service provider receiving the payout or retained cancellation penalty. |
17
+ | `amount` | `optional<money<C>>` | No | Total booking price in minor units of currency `C`. |
18
+ | `starts_at` | `optional<date>` | No | Stored ISO 8601 date when the booking begins. |
19
+ | `late_penalty_bps` | `optional<integer>` | No | Penalty in basis points applied when cancelling within the late window. |
20
+ | `late_within` | `optional<text>` | No | ISO 8601 duration defining the late window before `starts_at` (e.g. `"P2D"` for 2 days). |
21
+ | `early_penalty_bps` | `optional<integer>` | No | Penalty in basis points applied when cancelling before the late window. |
22
+ | `offer_life` | `optional<text>` | No | ISO 8601 duration defining how long a quoted cancellation offer remains valid (e.g. `"PT30M"`). |
23
+ | `cancel_bands` | `optional<list<block>>` | No | Supply cancel_bands to select deposit/balance custody instead of quoted cancellation. |
24
+ | `price_value` | `optional<text>` | No | price_value and supplier_cost fix the price; deposit_bps derives the deposit. |
25
+ | `supplier_cost` | `optional<text>` | No | price_value and supplier_cost fix the price; deposit_bps derives the deposit. |
26
+ | `departure` | `optional<text>` | No | balance_before and confirmation_window are positive fixed durations relative to departure. |
27
+ | `balance_before` | `optional<text>` | No | balance_before and confirmation_window are positive fixed durations relative to departure. |
28
+ | `confirmation_window` | `optional<text>` | No | balance_before and confirmation_window are positive fixed durations relative to departure. |
29
+ | `unpaid_band` | `optional<integer>` | No | The unpaid_band index selects a retained deposit policy. |
30
+ | `acceptance` | `optional<block>` | No | acceptance optionally supplies an aggregate gate. |
31
+ | `deposit_bps` | `optional<integer>` | No | price_value and supplier_cost fix the price; deposit_bps derives the deposit. |
32
+ | `tax_bps` | `optional<integer>` | No | tax_bps applies to margin after the supplier share. |
33
+ | `authority_type` | `optional<text>` | No | authority_type and supplier_role bind release to a consumed confirmation decision. |
34
+ | `supplier_role` | `optional<text>` | No | authority_type and supplier_role bind release to a consumed confirmation decision. |
35
+
36
+ Required means required by the template signature. A selected mode may also need parameters marked optional; the guidance below describes those combinations.
37
+
38
+ ## Module guidance
39
+
40
+ Time-anchored reservation holding booking funds in escrow with dynamically quoted cancellation penalties.
41
+
42
+ ### Purpose
43
+
44
+ `cancellable_booking` holds booking fees in escrow from a guest for a host until a scheduled start date.
45
+ It fits hospitality, travel reservations, studio rentals, event tickets, and appointments where guests
46
+ can cancel prior to start, but cancellation penalties depend on how close to the start date cancellation occurs.
47
+
48
+ ### Selection guidance
49
+
50
+ - vs `held_payment`: Both hold money in escrow and both quote a cancellation before it is spent.
51
+ `cancellable_booking` prices the penalty against the time left before `starts_at`, so the charge moves
52
+ as the start approaches; `held_payment` has no start date and quotes one flat charge.
53
+ Choose `cancellable_booking` whenever cancellation fees are time-sensitive.
54
+ - vs `security_deposit`: `security_deposit` holds funds to cover damages claimed by the holder.
55
+ `cancellable_booking` holds the service fee itself and releases to the host upon `starts_at` or refunds net of penalty.
56
+
57
+ ### Parameters
58
+
59
+ - `guest`: The booking customer paying the fee and receiving refunds.
60
+ - `host`: The service provider receiving the payout or retained cancellation penalty.
61
+ - `amount`: Total booking price in minor units of currency `C`.
62
+ - `starts_at`: Stored ISO 8601 date when the booking begins.
63
+ - `late_penalty_bps`: Penalty in basis points applied when cancelling within the late window.
64
+ - `late_within`: ISO 8601 duration defining the late window before `starts_at` (e.g. `"P2D"` for 2 days).
65
+ - `early_penalty_bps`: Penalty in basis points applied when cancelling before the late window.
66
+ - `offer_life`: ISO 8601 duration defining how long a quoted cancellation offer remains valid (e.g. `"PT30M"`).
67
+
68
+ ### Decision ports
69
+
70
+ None. Action transitions are driven by guest API calls (`take`, `cancel`, `confirm`) and scheduled completion (`complete` due at `starts_at`).
71
+
72
+ ### Example
73
+
74
+ ```hsx
75
+ program studio_booking "Studio booking"
76
+ import { cancellable_booking } from "std/money_flows"
77
+ party guest: person
78
+ party studio: business
79
+ settlement studio_session = cancellable_booking {
80
+ guest: guest
81
+ host: studio
82
+ amount: sessionPrice: money(SAR)
83
+ starts_at: startsAt
84
+ late_penalty_bps: 5000
85
+ late_within: "P2D"
86
+ early_penalty_bps: 1000
87
+ offer_life: "PT30M"
88
+ }
89
+ ```
90
+
91
+ ### Finite cancellation bands
92
+
93
+ Supply cancel_bands to select deposit/balance custody instead of quoted cancellation.
94
+ Each band has name, refund (full, balance or none), starts_at after the first band,
95
+ and supplier_bps when money is retained. The unpaid_band index selects a retained
96
+ deposit policy. Omit it to return the deposit; a full-refund band also returns it. price_value and supplier_cost fix the price; deposit_bps derives
97
+ the deposit. balance_before and confirmation_window are positive fixed durations
98
+ relative to departure. tax_bps applies to margin after the supplier share.
99
+ authority_type and supplier_role bind release to a consumed confirmation decision.
100
+ acceptance optionally supplies an aggregate gate. All actions are private until
101
+ expose selects them. Ordered band starts and deadlines prevent a late sweep from
102
+ extending an earlier band's cancellation rights. Full timeout refund returns price.
103
+ Seven derivations suffice for three bands; larger finite policies use up to the
104
+ UDL bound of 64 derived amounts. shift_date(date, duration, "before") subtracts a
105
+ fixed duration; omitting the direction adds it. Invalid dates or durations refuse.
106
+
107
+ ## Declared clauses
108
+
109
+ - `agent description`
110
+ - `caller parked states`
111
+ - `commit`
112
+ - `deadline`
113
+ - `description`
114
+ - `distinct parties`
115
+ - `due`
116
+ - `id prefix`
117
+ - `input`
118
+ - `moves`
119
+ - `partitions`
120
+ - `port`
121
+ - `quote`
122
+ - `requires drained`
123
+ - `sandbox failure point`
124
+ - `steps`
125
+ - `summary`
126
+ - `title`
127
+ - `unique`
128
+ - `updates`
129
+
130
+ This inventory covers all branches and nested instruments in the module. The selected parameters determine which clauses and actions the compiler emits. Indexed action names expand over the declared finite list.
21
131
 
22
132
  ## Decision ports
23
133
 
@@ -25,11 +135,22 @@ None.
25
135
 
26
136
  ## Actions and clauses
27
137
 
28
- | Action | Clauses lowered |
29
- | ---------- | ------------------------------------------------------------------------- |
30
- | `create` | `agent description`, `moves`, `steps`, `summary` |
31
- | `take` | `agent description`, `moves`, `sandbox failure point`, `steps`, `summary` |
32
- | `complete` | `due`, `moves`, `steps`, `summary` |
33
- | `cancel` | `agent description`, `moves`, `quote`, `steps`, `summary` |
34
- | `confirm` | `agent description`, `commit`, `moves`, `steps`, `summary` |
35
- | `retain` | `agent description`, `moves`, `steps`, `summary` |
138
+ | Action | Clauses lowered |
139
+ | --- | --- |
140
+ | `create` | `agent description`, `moves`, `steps`, `summary` |
141
+ | `take` | `agent description`, `moves`, `sandbox failure point`, `steps`, `summary` |
142
+ | `complete` | `due`, `moves`, `steps`, `summary` |
143
+ | `cancel` | `agent description`, `moves`, `quote`, `steps`, `summary` |
144
+ | `confirm` | `agent description`, `commit`, `moves`, `steps`, `summary` |
145
+ | `retain` | `agent description`, `moves`, `steps`, `summary` |
146
+ | `create` | `agent description`, `deadline`, `steps`, `unique` |
147
+ | `deposit` | `agent description`, `deadline`, `moves`, `port`, `steps` |
148
+ | `expire` | `agent description`, `due`, `requires drained`, `steps` |
149
+ | `[balance_action]` | `agent description`, `deadline`, `moves`, `port`, `steps` |
150
+ | `[open_action]` | `agent description`, `due`, `steps` |
151
+ | `[cancel_action]` | `agent description`, `deadline`, `moves`, `port`, `steps` |
152
+ | `cancel_unpaid` | `agent description`, `due`, `moves`, `steps` |
153
+ | `await_confirmation` | `agent description`, `due`, `steps` |
154
+ | `confirm` | `agent description`, `deadline`, `input`, `steps`, `updates` |
155
+ | `release` | `agent description`, `moves`, `steps` |
156
+ | `refund_unconfirmed` | `agent description`, `due`, `moves`, `steps` |
@@ -1,4 +1,4 @@
1
- <!-- Generated by scripts/docs/build.ts for HSX 2.1.1. Do not edit. -->
1
+ <!-- Generated by scripts/docs/build.ts for HSX 2.2.0. Do not edit. -->
2
2
 
3
3
  # captured_payment
4
4
 
@@ -10,17 +10,89 @@ Source: [`std/money_flows/captured_payment.hsx`](../../../std/money_flows/captur
10
10
 
11
11
  ## Parameters
12
12
 
13
- - `payer: party`
14
- - `payee: party`
15
- - `amount: money<C>`
16
- - `reserve_until: date`
17
- - `correction: condition`
18
- - `external_reversal: condition`
19
- - `capture_mode: text`
20
- - `correction_mode: text`
21
- - `negative_position: text`
22
- - `timeout: text`
23
- - `derived_amount: optional<block>`
13
+ | Parameter | Type | Required | Meaning |
14
+ | --- | --- | --- | --- |
15
+ | `payer` | `party` | Yes | Party whose account balance is reserved during authorization. |
16
+ | `payee` | `party` | Yes | Beneficiary party capturing authorized funds. |
17
+ | `amount` | `money<C>` | Yes | Maximum authorized reservation in minor units of currency `C`. |
18
+ | `reserve_until` | `date` | Yes | Expiration date for the authorization hold. |
19
+ | `correction` | `condition` | Yes | Condition port allowing post-settlement amount corrections. |
20
+ | `external_reversal` | `condition` | Yes | Condition port allowing external processor chargebacks/reversals. |
21
+ | `derived_amount` | `optional<block>` | No | Optional block declaring percentage fee calculation. |
22
+
23
+ Required means required by the template signature. A selected mode may also need parameters marked optional; the guidance below describes those combinations.
24
+
25
+ ## Module guidance
26
+
27
+ Two-phase authorization and capture payment flow for card and merchant processing.
28
+
29
+ ### Purpose
30
+
31
+ `captured_payment` reserves funds against a payer's account and allows the payee to capture the authorized
32
+ balance in one or multiple slices before a reservation expiry date (`reserve_until`). It fits ecommerce checkouts,
33
+ card processing, hotel authorizations, and pay-at-pump fuel payments where final amounts vary or settle later.
34
+
35
+ ### Selection guidance
36
+
37
+ - vs `instant_transfer`: `instant_transfer` immediately transfers money from payer to payee in a single irreversible
38
+ step without reservation or settlement delays. `captured_payment` separates authorization from capture, allowing
39
+ incremental captures, voids, amount corrections via the `correction` port, and external network reversals via `external_reversal`.
40
+ - vs `held_payment`: `held_payment` holds the full amount in third-party escrow pending release. `captured_payment`
41
+ reserves funds directly on payer balance and settles incrementally directly to payee.
42
+
43
+ ### Parameters
44
+
45
+ - `payer`: Party whose account balance is reserved during authorization.
46
+ - `payee`: Beneficiary party capturing authorized funds.
47
+ - `amount`: Maximum authorized reservation in minor units of currency `C`.
48
+ - `reserve_until`: Expiration date for the authorization hold.
49
+ - `correction`: Condition port allowing post-settlement amount corrections.
50
+ - `external_reversal`: Condition port allowing external processor chargebacks/reversals.
51
+ - `derived_amount`: Optional block declaring percentage fee calculation.
52
+
53
+ ### Decision ports
54
+
55
+ - `correction`: Condition allowing payee or processor to submit an amount correction after settlement.
56
+ - `external_reversal`: Condition allowing bank or card network to execute an external reversal.
57
+
58
+ ### Example
59
+
60
+ ```hsx
61
+ program captured_payment_example "Captured payment example"
62
+ import { captured_payment } from "std/money_flows"
63
+ party payer: person
64
+ party payee: business
65
+ settlement card_payment = captured_payment {
66
+ payer: payer
67
+ payee: payee
68
+ amount: authorizedAmount: money(SAR)
69
+ reserve_until: reserveUntil
70
+ correction: port correct_capture
71
+ external_reversal: port reverse_capture within P14D
72
+ }
73
+ port correct_capture { allowed: [payee] }
74
+ port reverse_capture {
75
+ allowed: [payee]
76
+ shape: { externalReference: text }
77
+ }
78
+ ```
79
+
80
+ ## Declared clauses
81
+
82
+ - `agent description`
83
+ - `capture input`
84
+ - `deadline`
85
+ - `description`
86
+ - `due`
87
+ - `input`
88
+ - `moves`
89
+ - `port`
90
+ - `sandbox failure point`
91
+ - `steps`
92
+ - `summary`
93
+ - `title`
94
+
95
+ This inventory covers all branches and nested instruments in the module. The selected parameters determine which clauses and actions the compiler emits. Indexed action names expand over the declared finite list.
24
96
 
25
97
  ## Decision ports
26
98
 
@@ -29,15 +101,15 @@ Source: [`std/money_flows/captured_payment.hsx`](../../../std/money_flows/captur
29
101
 
30
102
  ## Actions and clauses
31
103
 
32
- | Action | Clauses lowered |
33
- | ------------------ | ------------------------------------------------------------------------------------------------------------- |
34
- | `create` | `agent description`, `moves`, `steps`, `summary` |
35
- | `authorize` | `agent description`, `moves`, `sandbox failure point`, `steps`, `summary` |
36
- | `capture` | `agent description`, `deadline`, `description`, `input`, `moves`, `sandbox failure point`, `steps`, `summary` |
37
- | `capture_more` | `agent description`, `deadline`, `description`, `input`, `moves`, `steps`, `summary` |
38
- | `settle` | `agent description`, `deadline`, `moves`, `steps`, `summary` |
39
- | `void` | `agent description`, `moves`, `steps`, `summary` |
40
- | `expire` | `due`, `moves`, `steps`, `summary` |
41
- | `settle_on_expiry` | `due`, `moves`, `steps`, `summary` |
42
- | `correction_name` | `agent description`, `capture input`, `input`, `moves`, `port`, `steps`, `summary` |
43
- | `reversal_name` | `agent description`, `capture input`, `deadline`, `input`, `moves`, `port`, `steps`, `summary` |
104
+ | Action | Clauses lowered |
105
+ | --- | --- |
106
+ | `create` | `agent description`, `moves`, `steps`, `summary` |
107
+ | `authorize` | `agent description`, `moves`, `sandbox failure point`, `steps`, `summary` |
108
+ | `capture` | `agent description`, `deadline`, `description`, `input`, `moves`, `sandbox failure point`, `steps`, `summary` |
109
+ | `capture_more` | `agent description`, `deadline`, `description`, `input`, `moves`, `steps`, `summary` |
110
+ | `settle` | `agent description`, `deadline`, `moves`, `steps`, `summary` |
111
+ | `void` | `agent description`, `moves`, `steps`, `summary` |
112
+ | `expire` | `due`, `moves`, `steps`, `summary` |
113
+ | `settle_on_expiry` | `due`, `moves`, `steps`, `summary` |
114
+ | `[correction_name]` | `agent description`, `capture input`, `input`, `moves`, `port`, `steps`, `summary` |
115
+ | `[reversal_name]` | `agent description`, `capture input`, `deadline`, `input`, `moves`, `port`, `steps`, `summary` |