@hyperscale0/udl 2.2.0 → 2.4.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 (88) hide show
  1. package/CHANGELOG.md +38 -0
  2. package/README.md +5 -1
  3. package/conformance/invalid/invalid-journeys.expected.json +3 -19
  4. package/conformance/invalid/invalid-journeys.udl +47 -49
  5. package/conformance/valid/attested.expected.json +6 -0
  6. package/conformance/valid/attested.udl +251 -0
  7. package/conformance/valid/hand-edited.expected.json +1 -1
  8. package/conformance/valid/hand-edited.udl +1 -1
  9. package/conformance/valid/minimal.expected.json +1 -1
  10. package/conformance/valid/minimal.udl +0 -15
  11. package/conformance/valid/vocabulary.expected.json +6 -0
  12. package/conformance/valid/vocabulary.udl +1999 -0
  13. package/dist/allocation.d.ts +60 -0
  14. package/dist/allocation.d.ts.map +1 -0
  15. package/dist/allocation.js +177 -0
  16. package/dist/allocation.js.map +1 -0
  17. package/dist/diagnostics.d.ts +1 -31
  18. package/dist/diagnostics.d.ts.map +1 -1
  19. package/dist/diagnostics.js +0 -30
  20. package/dist/diagnostics.js.map +1 -1
  21. package/dist/distribution.d.ts +15 -0
  22. package/dist/distribution.d.ts.map +1 -0
  23. package/dist/distribution.js +49 -0
  24. package/dist/distribution.js.map +1 -0
  25. package/dist/effects.d.ts +0 -6
  26. package/dist/effects.d.ts.map +1 -1
  27. package/dist/effects.js +84 -22
  28. package/dist/effects.js.map +1 -1
  29. package/dist/evolution.d.ts +12 -0
  30. package/dist/evolution.d.ts.map +1 -1
  31. package/dist/evolution.js +42 -1
  32. package/dist/evolution.js.map +1 -1
  33. package/dist/finance.d.ts +18 -1
  34. package/dist/finance.d.ts.map +1 -1
  35. package/dist/finance.js +158 -27
  36. package/dist/finance.js.map +1 -1
  37. package/dist/index.d.ts +9 -3
  38. package/dist/index.d.ts.map +1 -1
  39. package/dist/index.js +6 -2
  40. package/dist/index.js.map +1 -1
  41. package/dist/instrument-references.d.ts +5 -0
  42. package/dist/instrument-references.d.ts.map +1 -0
  43. package/dist/instrument-references.js +69 -0
  44. package/dist/instrument-references.js.map +1 -0
  45. package/dist/limits.d.ts +3 -3
  46. package/dist/limits.d.ts.map +1 -1
  47. package/dist/limits.js +3 -7
  48. package/dist/limits.js.map +1 -1
  49. package/dist/reference.d.ts +3 -0
  50. package/dist/reference.d.ts.map +1 -0
  51. package/dist/reference.js +28 -0
  52. package/dist/reference.js.map +1 -0
  53. package/dist/schema.d.ts +1232 -83
  54. package/dist/schema.d.ts.map +1 -1
  55. package/dist/schema.js +398 -60
  56. package/dist/schema.js.map +1 -1
  57. package/dist/validation.d.ts +27 -1
  58. package/dist/validation.d.ts.map +1 -1
  59. package/dist/validation.js +327 -187
  60. package/dist/validation.js.map +1 -1
  61. package/dist/vocabulary.d.ts +23 -0
  62. package/dist/vocabulary.d.ts.map +1 -0
  63. package/dist/vocabulary.js +965 -0
  64. package/dist/vocabulary.js.map +1 -0
  65. package/docs/README.md +5 -1
  66. package/docs/funding-custody.md +165 -0
  67. package/docs/guide/09-schedules-and-allocation.md +130 -0
  68. package/docs/llms-full.txt +623 -101
  69. package/docs/llms.txt +1 -1
  70. package/docs/piece-plans.md +148 -0
  71. package/docs/reference/clauses.md +451 -63
  72. package/docs/reference/cli.md +3 -1
  73. package/docs/reference/diagnostics.md +33 -38
  74. package/package.json +5 -6
  75. package/spec/udl.schema.json +1095 -118
  76. package/src/allocation.ts +259 -0
  77. package/src/diagnostics.ts +0 -32
  78. package/src/distribution.ts +61 -0
  79. package/src/effects.ts +116 -22
  80. package/src/evolution.ts +63 -3
  81. package/src/finance.ts +218 -24
  82. package/src/index.ts +31 -3
  83. package/src/instrument-references.ts +98 -0
  84. package/src/limits.ts +3 -7
  85. package/src/reference.ts +31 -0
  86. package/src/schema.ts +417 -66
  87. package/src/validation.ts +452 -243
  88. package/src/vocabulary.ts +1508 -0
package/docs/llms.txt CHANGED
@@ -1,4 +1,4 @@
1
- <!-- Generated by scripts/docs/build.ts from @hyperscale0/udl 2.2.0. Edit the source, not llms.txt. -->
1
+ <!-- Generated by scripts/docs/build.ts from @hyperscale0/udl 2.4.0. Edit the source, not llms.txt. -->
2
2
 
3
3
  # UDL documentation
4
4
 
@@ -0,0 +1,148 @@
1
+ # Piece plans and private action composition
2
+
3
+ UDL preserves the authored graph and the order needed to interpret it.
4
+ `piecePlan` declares a finite partition, `pieceStage` names a stage, `calls`
5
+ binds private actions, and `actionLibrary` supplies their definitions. HSX
6
+ spells these clauses `piece_plan`, `piece_stage`, `calls` and `action_library`.
7
+ The shapes live in [`schema.ts`](../src/schema.ts); resolution and finance
8
+ validation live in [`validation.ts`](../src/validation.ts). The
9
+ [clause reference](reference/clauses.md) describes the complete vocabulary.
10
+
11
+ ## Worked sale example
12
+
13
+ The following decoded instrument fragment uses the sale settlement's price
14
+ partition and refund action. Add it to an instrument with its required
15
+ immutable fields, matching partition, lifecycle and captured escrow account.
16
+ It omits the surrounding document and other actions. It is formatted for
17
+ reading; canonical serialization sorts object keys and retains array order.
18
+
19
+ ```json
20
+ {
21
+ "piecePlan": {
22
+ "id": "price",
23
+ "total": "price",
24
+ "pieces": [
25
+ {
26
+ "id": "seller",
27
+ "amount": "piece1Amount",
28
+ "release_to": "sellerAccountId",
29
+ "refund_to": "buyerAccountId"
30
+ },
31
+ {
32
+ "id": "platform_fee",
33
+ "amount": "piece2Amount",
34
+ "release_to": "platformAccountId",
35
+ "refund_to": "buyerAccountId"
36
+ },
37
+ {
38
+ "id": "seller_cancel_fee",
39
+ "amount": "piece3Amount",
40
+ "release_to": "platformAccountId",
41
+ "refund_to": "sellerAccountId"
42
+ }
43
+ ],
44
+ "fund_order": ["seller", "platform_fee", "seller_cancel_fee"],
45
+ "release_order": ["platform_fee", "seller_cancel_fee"],
46
+ "refund_order": ["platform_fee", "seller_cancel_fee"],
47
+ "unfund_order": ["seller_cancel_fee", "platform_fee", "seller"]
48
+ },
49
+ "actionLibrary": {
50
+ "settlement_piece": {
51
+ "actionOrder": ["move"],
52
+ "actions": {
53
+ "move": {
54
+ "parameters": {
55
+ "piece": { "kind": "piece" },
56
+ "source": { "kind": "account" },
57
+ "destination": { "kind": "account" }
58
+ },
59
+ "principal": "api_key",
60
+ "approval": "inherit",
61
+ "recovery": "local",
62
+ "order": ["transfer"],
63
+ "calls": [],
64
+ "leaves": [
65
+ {
66
+ "id": "transfer",
67
+ "operation": "internal_transfer.create",
68
+ "bind": {
69
+ "amount": "$piece.amount",
70
+ "currency": "$piece.currency",
71
+ "sourceAccountId": "$source",
72
+ "destinationAccountId": "$destination"
73
+ },
74
+ "effects": [
75
+ { "kind": "moves", "signature": "moves.transfer.internal" }
76
+ ],
77
+ "evidence": "transferId"
78
+ }
79
+ ]
80
+ }
81
+ }
82
+ }
83
+ },
84
+ "actions": {
85
+ "refund_piece": {
86
+ "pieceStage": { "plan": "price", "stage": "refund" },
87
+ "calls": [
88
+ {
89
+ "id": "move_piece",
90
+ "action": "settlement_piece.move",
91
+ "bind": {
92
+ "piece": "$piece",
93
+ "source": "$instance.refs.escrowAccountId",
94
+ "destination": "$piece.refund_to"
95
+ }
96
+ }
97
+ ],
98
+ "steps": [],
99
+ "summary": "Refund a piece of a sale settlement"
100
+ }
101
+ }
102
+ }
103
+ ```
104
+
105
+ The containing instrument's `actionOrder` includes `refund_piece` at its
106
+ authored position. Both library `actionOrder` and private action `order` must
107
+ be exact permutations of their members. The stage derives a required
108
+ `pieceId` enum, here `platform_fee` or `seller_cancel_fee`. The selector does
109
+ not add another transfer; the private leaf moves its amount once.
110
+
111
+ For the sale's example amounts, `piece1Amount` is `245000`, `piece2Amount` is
112
+ `3750`, and `piece3Amount` is `1250`, all SAR minor units. They partition
113
+ `price` of `250000`. Cancellation's separate decision action returns the seller
114
+ piece to the buyer. The refund stage then returns `3750` to the buyer and pays
115
+ `1250` to the seller. Unfund follows its reverse order and returns every funded
116
+ piece to the buyer instead. The service fee stays outside the price partition.
117
+
118
+ `resolveUdlActionPlans` returns plans and issues. A plan identifies its action
119
+ and optional piece ID, with resolved effects and leaves. Each leaf retains
120
+ `originPath`, step, effects and evidence. Resolution expands static calls; it
121
+ does not replace the source graph in canonical UDL. A private library entry is
122
+ not a public action. [`refactor-clauses.spec.ts`](../test/refactor-clauses.spec.ts)
123
+ checks piece constraints, graph order, cycles, bindings, authority and evidence.
124
+
125
+ ## Conservation and diagnostics
126
+
127
+ UDL 2.3.0 checks funded amounts over piece progress. A partially funded path
128
+ must return only the pieces actually funded; selecting one piece is not proof
129
+ that a whole stage completed. For a piece plan, `expandPieceProgress` bounds the reachable lifecycle/progress
130
+ states at 256. Instruments without a piece plan use the separate action-plan
131
+ combination bound. These bounds belong to the proof, not to a runtime retry
132
+ loop. [`udl.spec.ts`](../test/udl.spec.ts) includes the stranded-funded-piece
133
+ refusal; [`validation.ts`](../src/validation.ts) owns the progress expansion.
134
+
135
+ [`diagnostics.ts`](../src/diagnostics.ts) defines the refusal codes:
136
+
137
+ | Code | Refusal | Repair |
138
+ | --------- | ---------------------- | ---------------------------------------------------------------------------------------- |
139
+ | `UDL4001` | Money graph violation | Balance each funded amount and close every hold on each lifecycle path |
140
+ | `UDL5013` | Piece stage violation | Select a declared plan/stage, valid ordered piece IDs and a call-based stage action |
141
+ | `UDL2010` | Action graph violation | Resolve targets and remove cycles, collisions or invalid order within depth/count limits |
142
+
143
+ A partition mismatch or incompatible immutable field is `UDL4002`. A typed
144
+ binding failure is `UDL2011`; an authority boundary is `UDL2012`; incomplete
145
+ effects or evidence are `UDL2013`. These failures are not permission to skip
146
+ the independent conservation oracle. Keep actions that need another principal,
147
+ independent approval or external recovery as separate calls at the public
148
+ boundary, not flattened private work.