@wowok/agent-mcp 2.4.3 → 2.5.1

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 (317) hide show
  1. package/dist/config/runtime.d.ts +4 -0
  2. package/dist/config/runtime.js +29 -5
  3. package/dist/harness/auto-escalation.d.ts +27 -0
  4. package/dist/harness/auto-escalation.js +68 -0
  5. package/dist/index.js +21 -0
  6. package/dist/knowledge/allocation-confirm.d.ts +115 -0
  7. package/dist/knowledge/allocation-confirm.js +534 -0
  8. package/dist/knowledge/allocation-context.d.ts +58 -0
  9. package/dist/knowledge/allocation-context.js +249 -0
  10. package/dist/knowledge/allocation-ledger.d.ts +67 -0
  11. package/dist/knowledge/allocation-ledger.js +463 -0
  12. package/dist/knowledge/allocation-puzzle.d.ts +135 -0
  13. package/dist/knowledge/allocation-puzzle.js +298 -0
  14. package/dist/knowledge/allocation-risk.d.ts +78 -0
  15. package/dist/knowledge/allocation-risk.js +568 -0
  16. package/dist/knowledge/allocation-templates.d.ts +38 -0
  17. package/dist/knowledge/allocation-templates.js +970 -0
  18. package/dist/knowledge/allocation-translation.d.ts +72 -0
  19. package/dist/knowledge/allocation-translation.js +585 -0
  20. package/dist/knowledge/arb-risk.d.ts +37 -0
  21. package/dist/knowledge/arb-risk.js +210 -0
  22. package/dist/knowledge/arbitration-confirm.d.ts +135 -0
  23. package/dist/knowledge/arbitration-confirm.js +559 -0
  24. package/dist/knowledge/arbitration-context.d.ts +81 -0
  25. package/dist/knowledge/arbitration-context.js +505 -0
  26. package/dist/knowledge/arbitration-ledger.d.ts +62 -0
  27. package/dist/knowledge/arbitration-ledger.js +521 -0
  28. package/dist/knowledge/arbitration-puzzle.d.ts +84 -0
  29. package/dist/knowledge/arbitration-puzzle.js +304 -0
  30. package/dist/knowledge/arbitration-risk.d.ts +112 -0
  31. package/dist/knowledge/arbitration-risk.js +433 -0
  32. package/dist/knowledge/arbitration-templates.d.ts +38 -0
  33. package/dist/knowledge/arbitration-templates.js +276 -0
  34. package/dist/knowledge/arbitration-translation.d.ts +91 -0
  35. package/dist/knowledge/arbitration-translation.js +487 -0
  36. package/dist/knowledge/bridge-risk.d.ts +36 -0
  37. package/dist/knowledge/bridge-risk.js +263 -0
  38. package/dist/knowledge/contact-risk.d.ts +32 -0
  39. package/dist/knowledge/contact-risk.js +200 -0
  40. package/dist/knowledge/demand-confirm.d.ts +32 -0
  41. package/dist/knowledge/demand-confirm.js +206 -0
  42. package/dist/knowledge/demand-risk.d.ts +30 -0
  43. package/dist/knowledge/demand-risk.js +240 -0
  44. package/dist/knowledge/demand-translation.d.ts +55 -0
  45. package/dist/knowledge/demand-translation.js +354 -0
  46. package/dist/knowledge/deployment-scanner.d.ts +63 -0
  47. package/dist/knowledge/deployment-scanner.js +762 -0
  48. package/dist/knowledge/examples-scanner-cli.d.ts +1 -0
  49. package/dist/knowledge/examples-scanner-cli.js +26 -0
  50. package/dist/knowledge/examples-scanner.d.ts +121 -0
  51. package/dist/knowledge/examples-scanner.js +825 -0
  52. package/dist/knowledge/flywheel-loop.d.ts +3 -0
  53. package/dist/knowledge/flywheel-loop.js +32 -3
  54. package/dist/knowledge/glossary.js +3 -1
  55. package/dist/knowledge/guard-confirm.d.ts +86 -0
  56. package/dist/knowledge/guard-confirm.js +406 -0
  57. package/dist/knowledge/guard-context.d.ts +56 -0
  58. package/dist/knowledge/guard-context.js +287 -0
  59. package/dist/knowledge/guard-design-patterns.d.ts +37 -0
  60. package/dist/knowledge/guard-design-patterns.js +257 -0
  61. package/dist/knowledge/guard-puzzle.js +3 -2
  62. package/dist/knowledge/guard-risk.d.ts +1 -1
  63. package/dist/knowledge/guard-risk.js +12 -14
  64. package/dist/knowledge/guard-templates.js +1 -1
  65. package/dist/knowledge/guard-translation.js +6 -5
  66. package/dist/knowledge/index.d.ts +342 -0
  67. package/dist/knowledge/index.js +344 -0
  68. package/dist/knowledge/machine-confirm.d.ts +102 -0
  69. package/dist/knowledge/machine-confirm.js +559 -0
  70. package/dist/knowledge/machine-context.d.ts +160 -0
  71. package/dist/knowledge/machine-context.js +812 -0
  72. package/dist/knowledge/machine-ledger.d.ts +41 -0
  73. package/dist/knowledge/machine-ledger.js +315 -0
  74. package/dist/knowledge/machine-puzzle.d.ts +206 -0
  75. package/dist/knowledge/machine-puzzle.js +494 -0
  76. package/dist/knowledge/machine-risk.d.ts +75 -0
  77. package/dist/knowledge/machine-risk.js +644 -0
  78. package/dist/knowledge/machine-templates.d.ts +92 -0
  79. package/dist/knowledge/machine-templates.js +1592 -0
  80. package/dist/knowledge/machine-topology.d.ts +57 -0
  81. package/dist/knowledge/machine-topology.js +234 -0
  82. package/dist/knowledge/machine-translation.d.ts +96 -0
  83. package/dist/knowledge/machine-translation.js +513 -0
  84. package/dist/knowledge/mcp-schema-audit-cli.d.ts +1 -0
  85. package/dist/knowledge/mcp-schema-audit-cli.js +45 -0
  86. package/dist/knowledge/mcp-schema-audit.d.ts +90 -0
  87. package/dist/knowledge/mcp-schema-audit.js +772 -0
  88. package/dist/knowledge/onchain-constants.d.ts +4 -0
  89. package/dist/knowledge/onchain-constants.js +35 -0
  90. package/dist/knowledge/order-confirm.d.ts +115 -0
  91. package/dist/knowledge/order-confirm.js +573 -0
  92. package/dist/knowledge/order-context.d.ts +66 -0
  93. package/dist/knowledge/order-context.js +390 -0
  94. package/dist/knowledge/order-ledger.d.ts +69 -0
  95. package/dist/knowledge/order-ledger.js +341 -0
  96. package/dist/knowledge/order-puzzle.d.ts +159 -0
  97. package/dist/knowledge/order-puzzle.js +255 -0
  98. package/dist/knowledge/order-risk.d.ts +66 -0
  99. package/dist/knowledge/order-risk.js +653 -0
  100. package/dist/knowledge/order-templates.d.ts +50 -0
  101. package/dist/knowledge/order-templates.js +368 -0
  102. package/dist/knowledge/order-translation.d.ts +78 -0
  103. package/dist/knowledge/order-translation.js +550 -0
  104. package/dist/knowledge/passport-confirm.d.ts +130 -0
  105. package/dist/knowledge/passport-confirm.js +531 -0
  106. package/dist/knowledge/passport-context.d.ts +59 -0
  107. package/dist/knowledge/passport-context.js +306 -0
  108. package/dist/knowledge/passport-ledger.d.ts +48 -0
  109. package/dist/knowledge/passport-ledger.js +282 -0
  110. package/dist/knowledge/passport-puzzle.d.ts +108 -0
  111. package/dist/knowledge/passport-puzzle.js +333 -0
  112. package/dist/knowledge/passport-risk.d.ts +70 -0
  113. package/dist/knowledge/passport-risk.js +450 -0
  114. package/dist/knowledge/passport-templates.d.ts +40 -0
  115. package/dist/knowledge/passport-templates.js +568 -0
  116. package/dist/knowledge/passport-translation.d.ts +68 -0
  117. package/dist/knowledge/passport-translation.js +516 -0
  118. package/dist/knowledge/payment-risk.d.ts +33 -0
  119. package/dist/knowledge/payment-risk.js +182 -0
  120. package/dist/knowledge/permission-confirm.d.ts +110 -0
  121. package/dist/knowledge/permission-confirm.js +426 -0
  122. package/dist/knowledge/permission-context.d.ts +58 -0
  123. package/dist/knowledge/permission-context.js +224 -0
  124. package/dist/knowledge/permission-ledger.d.ts +38 -0
  125. package/dist/knowledge/permission-ledger.js +403 -0
  126. package/dist/knowledge/permission-puzzle.d.ts +122 -0
  127. package/dist/knowledge/permission-puzzle.js +173 -0
  128. package/dist/knowledge/permission-risk.d.ts +76 -0
  129. package/dist/knowledge/permission-risk.js +411 -0
  130. package/dist/knowledge/permission-templates.d.ts +38 -0
  131. package/dist/knowledge/permission-templates.js +234 -0
  132. package/dist/knowledge/permission-translation.d.ts +57 -0
  133. package/dist/knowledge/permission-translation.js +350 -0
  134. package/dist/knowledge/personal-risk.d.ts +36 -0
  135. package/dist/knowledge/personal-risk.js +212 -0
  136. package/dist/knowledge/progress-confirm.d.ts +108 -0
  137. package/dist/knowledge/progress-confirm.js +456 -0
  138. package/dist/knowledge/progress-context.d.ts +123 -0
  139. package/dist/knowledge/progress-context.js +452 -0
  140. package/dist/knowledge/progress-ledger.d.ts +63 -0
  141. package/dist/knowledge/progress-ledger.js +327 -0
  142. package/dist/knowledge/progress-puzzle.d.ts +82 -0
  143. package/dist/knowledge/progress-puzzle.js +219 -0
  144. package/dist/knowledge/progress-risk.d.ts +74 -0
  145. package/dist/knowledge/progress-risk.js +461 -0
  146. package/dist/knowledge/progress-templates.d.ts +38 -0
  147. package/dist/knowledge/progress-templates.js +228 -0
  148. package/dist/knowledge/progress-translation.d.ts +52 -0
  149. package/dist/knowledge/progress-translation.js +401 -0
  150. package/dist/knowledge/proof-confirm.d.ts +31 -0
  151. package/dist/knowledge/proof-confirm.js +187 -0
  152. package/dist/knowledge/proof-risk.d.ts +33 -0
  153. package/dist/knowledge/proof-risk.js +207 -0
  154. package/dist/knowledge/proof-translation.d.ts +52 -0
  155. package/dist/knowledge/proof-translation.js +283 -0
  156. package/dist/knowledge/registrar-risk.d.ts +34 -0
  157. package/dist/knowledge/registrar-risk.js +217 -0
  158. package/dist/knowledge/repository-confirm.d.ts +36 -0
  159. package/dist/knowledge/repository-confirm.js +242 -0
  160. package/dist/knowledge/repository-risk.d.ts +40 -0
  161. package/dist/knowledge/repository-risk.js +312 -0
  162. package/dist/knowledge/repository-translation.d.ts +58 -0
  163. package/dist/knowledge/repository-translation.js +422 -0
  164. package/dist/knowledge/resource-risk.d.ts +32 -0
  165. package/dist/knowledge/resource-risk.js +157 -0
  166. package/dist/knowledge/reward-confirm.d.ts +113 -0
  167. package/dist/knowledge/reward-confirm.js +496 -0
  168. package/dist/knowledge/reward-context.d.ts +127 -0
  169. package/dist/knowledge/reward-context.js +504 -0
  170. package/dist/knowledge/reward-ledger.d.ts +96 -0
  171. package/dist/knowledge/reward-ledger.js +502 -0
  172. package/dist/knowledge/reward-puzzle.d.ts +97 -0
  173. package/dist/knowledge/reward-puzzle.js +288 -0
  174. package/dist/knowledge/reward-risk.d.ts +84 -0
  175. package/dist/knowledge/reward-risk.js +545 -0
  176. package/dist/knowledge/reward-translation.d.ts +58 -0
  177. package/dist/knowledge/reward-translation.js +501 -0
  178. package/dist/knowledge/safety-rules.js +11 -3
  179. package/dist/knowledge/scenario-modes.d.ts +53 -0
  180. package/dist/knowledge/scenario-modes.js +302 -0
  181. package/dist/knowledge/service-confirm.d.ts +152 -0
  182. package/dist/knowledge/service-confirm.js +699 -0
  183. package/dist/knowledge/service-context.d.ts +66 -0
  184. package/dist/knowledge/service-context.js +403 -0
  185. package/dist/knowledge/service-ledger.d.ts +71 -0
  186. package/dist/knowledge/service-ledger.js +609 -0
  187. package/dist/knowledge/service-puzzle.d.ts +158 -0
  188. package/dist/knowledge/service-puzzle.js +236 -0
  189. package/dist/knowledge/service-risk.d.ts +108 -0
  190. package/dist/knowledge/service-risk.js +615 -0
  191. package/dist/knowledge/service-templates.d.ts +39 -0
  192. package/dist/knowledge/service-templates.js +418 -0
  193. package/dist/knowledge/service-translation.d.ts +103 -0
  194. package/dist/knowledge/service-translation.js +622 -0
  195. package/dist/knowledge/tools-reference.d.ts +17 -0
  196. package/dist/knowledge/tools-reference.js +151 -0
  197. package/dist/knowledge/treasury-confirm.d.ts +133 -0
  198. package/dist/knowledge/treasury-confirm.js +512 -0
  199. package/dist/knowledge/treasury-context.d.ts +64 -0
  200. package/dist/knowledge/treasury-context.js +363 -0
  201. package/dist/knowledge/treasury-ledger.d.ts +42 -0
  202. package/dist/knowledge/treasury-ledger.js +300 -0
  203. package/dist/knowledge/treasury-puzzle.d.ts +163 -0
  204. package/dist/knowledge/treasury-puzzle.js +216 -0
  205. package/dist/knowledge/treasury-risk.d.ts +86 -0
  206. package/dist/knowledge/treasury-risk.js +440 -0
  207. package/dist/knowledge/treasury-templates.d.ts +38 -0
  208. package/dist/knowledge/treasury-templates.js +316 -0
  209. package/dist/knowledge/treasury-translation.d.ts +78 -0
  210. package/dist/knowledge/treasury-translation.js +498 -0
  211. package/dist/knowledge/util-risk.d.ts +30 -0
  212. package/dist/knowledge/util-risk.js +135 -0
  213. package/dist/project/business-puzzle.d.ts +47 -0
  214. package/dist/project/business-puzzle.js +372 -0
  215. package/dist/project/deployment-doc.d.ts +61 -0
  216. package/dist/project/deployment-doc.js +432 -0
  217. package/dist/project/risk-aggregator.d.ts +50 -0
  218. package/dist/project/risk-aggregator.js +280 -0
  219. package/dist/project/substep-trace.d.ts +130 -0
  220. package/dist/project/substep-trace.js +332 -0
  221. package/dist/schema/call/allocation.d.ts +34 -34
  222. package/dist/schema/call/arbitration.d.ts +141 -141
  223. package/dist/schema/call/base.d.ts +386 -386
  224. package/dist/schema/call/base.js +3 -3
  225. package/dist/schema/call/bridge-handler.d.ts +5 -2
  226. package/dist/schema/call/bridge.d.ts +159 -159
  227. package/dist/schema/call/contact.d.ts +110 -110
  228. package/dist/schema/call/demand.d.ts +76 -76
  229. package/dist/schema/call/handler.d.ts +2 -3
  230. package/dist/schema/call/handler.js +1 -1
  231. package/dist/schema/call/machine.d.ts +58 -58
  232. package/dist/schema/call/order.d.ts +98 -110
  233. package/dist/schema/call/permission-handler.d.ts +5 -0
  234. package/dist/schema/call/permission-handler.js +54 -0
  235. package/dist/schema/call/permission.d.ts +108 -108
  236. package/dist/schema/call/personal.d.ts +14 -14
  237. package/dist/schema/call/progress.d.ts +57 -72
  238. package/dist/schema/call/progress.js +7 -4
  239. package/dist/schema/call/proof.d.ts +18 -18
  240. package/dist/schema/call/proof.js +12 -7
  241. package/dist/schema/call/repository.d.ts +154 -154
  242. package/dist/schema/call/reward.d.ts +55 -55
  243. package/dist/schema/call/service.d.ts +231 -231
  244. package/dist/schema/call/treasury.d.ts +93 -93
  245. package/dist/schema/config/index.d.ts +178 -5
  246. package/dist/schema/config/index.js +52 -1
  247. package/dist/schema/local/index.d.ts +3554 -836
  248. package/dist/schema/local/index.js +2 -1
  249. package/dist/schema/messenger/index.d.ts +162 -162
  250. package/dist/schema/operations.d.ts +1058 -1074
  251. package/dist/schema/operations.js +7 -1
  252. package/dist/schema/project/index.d.ts +1412 -6
  253. package/dist/schema/project/index.js +441 -3
  254. package/dist/schema/query/index.d.ts +672 -672
  255. package/dist/schema/schema-query/index.d.ts +23 -3
  256. package/dist/schema/schema-query/index.js +13 -2
  257. package/dist/schema/sync-layer4.d.ts +21 -0
  258. package/dist/schema/sync-layer4.js +261 -0
  259. package/dist/schema/trust/index.d.ts +26 -26
  260. package/dist/schemas/account_operation.output.json +718 -0
  261. package/dist/schemas/config_operation.output.json +173 -0
  262. package/dist/schemas/index.json +9 -1
  263. package/dist/schemas/local_info_operation.output.json +718 -0
  264. package/dist/schemas/local_mark_operation.output.json +718 -0
  265. package/dist/schemas/onchain_operations.output.json +3 -2
  266. package/dist/schemas/onchain_operations.schema.json +1809 -336
  267. package/dist/schemas/onchain_operations_allocation.schema.json +2 -1
  268. package/dist/schemas/onchain_operations_arbitration.schema.json +2 -1
  269. package/dist/schemas/onchain_operations_contact.schema.json +2 -1
  270. package/dist/schemas/onchain_operations_demand.schema.json +2 -1
  271. package/dist/schemas/onchain_operations_gen_passport.schema.json +878 -872
  272. package/dist/schemas/onchain_operations_gen_proof.schema.json +273 -0
  273. package/dist/schemas/onchain_operations_guard.schema.json +578 -579
  274. package/dist/schemas/onchain_operations_machine.schema.json +2 -1
  275. package/dist/schemas/onchain_operations_order.schema.json +13 -9
  276. package/dist/schemas/onchain_operations_payment.schema.json +0 -514
  277. package/dist/schemas/onchain_operations_permission.schema.json +0 -514
  278. package/dist/schemas/onchain_operations_personal.schema.json +0 -514
  279. package/dist/schemas/onchain_operations_progress.schema.json +14 -10
  280. package/dist/schemas/onchain_operations_proof.schema.json +699 -0
  281. package/dist/schemas/onchain_operations_repository.schema.json +2 -1
  282. package/dist/schemas/onchain_operations_reward.schema.json +2 -1
  283. package/dist/schemas/onchain_operations_service.schema.json +2 -1
  284. package/dist/schemas/onchain_operations_treasury.schema.json +2 -1
  285. package/dist/schemas/onchain_table_data.schema.json +32 -1
  286. package/dist/schemas/project_operation.output.json +918 -0
  287. package/dist/schemas/project_operation.schema.json +474 -3
  288. package/dist/schemas/query_toolkit.output.json +14906 -6
  289. package/dist/schemas/schema_query.output.json +38 -1
  290. package/dist/telemetry/index.d.ts +1 -1
  291. package/dist/tools/handlers/config.d.ts +1 -1
  292. package/dist/tools/handlers/config.js +21 -18
  293. package/dist/tools/handlers/file-export.d.ts +2 -2
  294. package/dist/tools/handlers/local.d.ts +3 -30
  295. package/dist/tools/handlers/local.js +14 -3
  296. package/dist/tools/handlers/messenger.d.ts +1 -1
  297. package/dist/tools/handlers/messenger.js +2 -1
  298. package/dist/tools/handlers/onchain.d.ts +1 -1
  299. package/dist/tools/handlers/onchain.js +24 -22
  300. package/dist/tools/handlers/project.d.ts +1 -1
  301. package/dist/tools/handlers/project.js +262 -18
  302. package/dist/tools/handlers/query.d.ts +4 -4
  303. package/dist/tools/handlers/schema-query.d.ts +1 -1
  304. package/dist/tools/handlers/schema-query.js +21 -20
  305. package/dist/tools/handlers/trust.d.ts +1 -1
  306. package/dist/tools/handlers/trust.js +2 -2
  307. package/dist/tools/handlers/wip.d.ts +1 -1
  308. package/dist/tools/handlers/wip.js +1 -1
  309. package/dist/tools/index.d.ts +1 -1
  310. package/dist/tools/index.js +96 -25
  311. package/dist/tools/rules-hook.d.ts +1 -1
  312. package/dist/tools/rules-hook.js +3 -2
  313. package/dist/tools/shared.d.ts +13 -22
  314. package/dist/tools/types.d.ts +5 -5
  315. package/dist/tools/wrap.d.ts +10 -2
  316. package/dist/tools/wrap.js +212 -0
  317. package/package.json +3 -3
@@ -0,0 +1,298 @@
1
+ import { MAX_ALLOCATOR_COUNT, ALLOCATION_MAX_SHARING_COUNT, RATE_TOTAL_FULL, } from "./allocation-ledger.js";
2
+ export function initPuzzleFromIntent(intent) {
3
+ const puzzle = {};
4
+ if (intent.action || intent.distribution_goal || intent.trigger_condition) {
5
+ puzzle.intent = {
6
+ action: intent.action ?? "create",
7
+ host_context: intent.host_context ?? "service_order_allocators",
8
+ trigger_condition: intent.trigger_condition ?? "",
9
+ distribution_goal: intent.distribution_goal ?? "",
10
+ failure_conditions: intent.failure_conditions ?? [],
11
+ };
12
+ }
13
+ puzzle.constraints = {
14
+ F_A_01_allocator_count_le_100: true,
15
+ F_A_02_sharing_count_le_100: true,
16
+ F_A_03_sharing_mode_valid: true,
17
+ F_A_04_at_most_1_surplus_per_allocator: true,
18
+ F_A_05_pure_rate_sum_eq_10000: true,
19
+ F_A_06_rate_plus_surplus_sum_le_10000: true,
20
+ F_A_07_amount_sum_ge_threshold: true,
21
+ F_A_08_amount_sum_le_max: true,
22
+ F_A_09_balance_ge_threshold_at_alloc: true,
23
+ F_A_10_payment_info_present: true,
24
+ F_A_11_allocators_not_empty: true,
25
+ F_A_12_order_at_most_1_allocation: true,
26
+ F_A_13_guard_identifier_is_address: true,
27
+ F_A_14_guard_addresses_unique: true,
28
+ F_A_15_order_allocators_immutable_after_publish: true,
29
+ };
30
+ return puzzle;
31
+ }
32
+ export function checkPuzzleCompleteness(puzzle) {
33
+ const missing = [];
34
+ const missing_details = [];
35
+ if (!puzzle.intent) {
36
+ missing.push("A");
37
+ missing_details.push({ dimension: "A", reason: "Intent not specified (action + distribution_goal)" });
38
+ }
39
+ else if (!puzzle.intent.distribution_goal) {
40
+ missing.push("A");
41
+ missing_details.push({ dimension: "A", reason: "distribution_goal is empty" });
42
+ }
43
+ else if (!puzzle.intent.host_context) {
44
+ missing.push("A");
45
+ missing_details.push({ dimension: "A", reason: "host_context (trigger source) must be specified" });
46
+ }
47
+ if (!puzzle.binding) {
48
+ missing.push("B");
49
+ missing_details.push({ dimension: "B", reason: "Binding not specified (coin_type + guard_objects)" });
50
+ }
51
+ else if (!puzzle.binding.coin_type) {
52
+ missing.push("B");
53
+ missing_details.push({ dimension: "B", reason: "coin_type is missing" });
54
+ }
55
+ else if (puzzle.binding.guard_objects.length === 0) {
56
+ missing.push("B");
57
+ missing_details.push({ dimension: "B", reason: "guard_objects list is empty — at least 1 Guard required" });
58
+ }
59
+ if (!puzzle.data_source && puzzle.intent?.action === "create") {
60
+ missing.push("C");
61
+ missing_details.push({ dimension: "C", reason: "Data source not specified (allocators_config + payment_info)" });
62
+ }
63
+ else if (puzzle.data_source && puzzle.data_source.allocators_config.allocators.length === 0) {
64
+ missing.push("C");
65
+ missing_details.push({ dimension: "C", reason: "allocators_config.allocators is empty" });
66
+ }
67
+ if (!puzzle.operations) {
68
+ missing.push("D");
69
+ missing_details.push({ dimension: "D", reason: "Operations not enumerated" });
70
+ }
71
+ if (!puzzle.logic) {
72
+ missing.push("E");
73
+ missing_details.push({ dimension: "E", reason: "Logic flow (7-step alloc) not defined" });
74
+ }
75
+ if (!puzzle.constraints) {
76
+ missing.push("F");
77
+ missing_details.push({ dimension: "F", reason: "Constraints not checked" });
78
+ }
79
+ return {
80
+ dimensions: ["A", "B", "C", "D", "E", "F"],
81
+ missing,
82
+ missing_details,
83
+ complete: missing.length === 0,
84
+ next_step: missing.length === 0
85
+ ? "Puzzle complete — ready for confirmation text generation"
86
+ : `Next: complete dimension ${missing[0]} — ${missing_details[0].reason}`,
87
+ };
88
+ }
89
+ export function validateConstraints(puzzle) {
90
+ const violations = [];
91
+ if (!puzzle.data_source)
92
+ return violations;
93
+ const cfg = puzzle.data_source.allocators_config;
94
+ if (cfg.allocators.length > MAX_ALLOCATOR_COUNT) {
95
+ violations.push({
96
+ constraint_id: "F-A-01",
97
+ severity: "CRITICAL",
98
+ message: `Allocator count ${cfg.allocators.length} exceeds MAX_ALLOCATOR_COUNT ${MAX_ALLOCATOR_COUNT}`,
99
+ current_value: cfg.allocators.length,
100
+ limit: MAX_ALLOCATOR_COUNT,
101
+ related_move_error: "EALLOCATOR_COUNT_EXCEEDED (2)",
102
+ });
103
+ }
104
+ if (cfg.allocators.length === 0) {
105
+ violations.push({
106
+ constraint_id: "F-A-11",
107
+ severity: "CRITICAL",
108
+ message: "allocators.allocators is empty — at least 1 Allocator required",
109
+ related_move_error: "EALLOCATORS_EMPTY (8) / ENO_ALLOCATOR (3)",
110
+ });
111
+ }
112
+ const guardAddrs = cfg.allocators.map(a => a.guard);
113
+ const uniqueGuards = new Set(guardAddrs);
114
+ if (uniqueGuards.size !== guardAddrs.length) {
115
+ violations.push({
116
+ constraint_id: "F-A-14",
117
+ severity: "MEDIUM",
118
+ message: `Duplicate Guard addresses in allocators (${guardAddrs.length} entries, ${uniqueGuards.size} unique) — alloc_by_guard address match only hits the first, subsequent duplicate Allocators are never reachable`,
119
+ });
120
+ }
121
+ for (const allocator of cfg.allocators) {
122
+ if (allocator.sharing.length > ALLOCATION_MAX_SHARING_COUNT) {
123
+ violations.push({
124
+ constraint_id: "F-A-02",
125
+ severity: "CRITICAL",
126
+ message: `Allocator ${allocator.guard} has ${allocator.sharing.length} sharing entries, exceeds MAX_SHARING_COUNT ${ALLOCATION_MAX_SHARING_COUNT}`,
127
+ current_value: allocator.sharing.length,
128
+ limit: ALLOCATION_MAX_SHARING_COUNT,
129
+ related_move_error: "ESHARING_COUNT_EXCEEDED (10)",
130
+ });
131
+ }
132
+ for (const s of allocator.sharing) {
133
+ if (!["Amount", "Rate", "Surplus"].includes(s.mode)) {
134
+ violations.push({
135
+ constraint_id: "F-A-03",
136
+ severity: "CRITICAL",
137
+ message: `Invalid sharing mode: ${s.mode}`,
138
+ related_move_error: "ESHARING_MODE_INVALID (11)",
139
+ });
140
+ }
141
+ }
142
+ const surplusCount = allocator.sharing.filter(s => s.mode === "Surplus").length;
143
+ if (surplusCount > 1) {
144
+ violations.push({
145
+ constraint_id: "F-A-04",
146
+ severity: "HIGH",
147
+ message: `Allocator ${allocator.guard} has ${surplusCount} Surplus sharing — at most 1 allowed`,
148
+ current_value: surplusCount,
149
+ limit: 1,
150
+ related_move_error: "EMULTIPLE_SURPLUS (5)",
151
+ });
152
+ }
153
+ const rateSum = allocator.sharing
154
+ .filter(s => s.mode === "Rate")
155
+ .reduce((sum, s) => sum + Number(s.sharing), 0);
156
+ const hasSurplus = surplusCount > 0;
157
+ if (!hasSurplus && rateSum > 0 && rateSum !== RATE_TOTAL_FULL) {
158
+ violations.push({
159
+ constraint_id: "F-A-05",
160
+ severity: "HIGH",
161
+ message: `Pure Rate mode (no Surplus) sum ${rateSum} != ${RATE_TOTAL_FULL}`,
162
+ current_value: rateSum,
163
+ limit: RATE_TOTAL_FULL,
164
+ related_move_error: "ERATE_NOT_10000 (4)",
165
+ });
166
+ }
167
+ if (hasSurplus && rateSum > RATE_TOTAL_FULL) {
168
+ violations.push({
169
+ constraint_id: "F-A-06",
170
+ severity: "HIGH",
171
+ message: `Rate + Surplus mode sum ${rateSum} > ${RATE_TOTAL_FULL}`,
172
+ current_value: rateSum,
173
+ limit: RATE_TOTAL_FULL,
174
+ related_move_error: "ERATE_EXCEEDS_10000 (6)",
175
+ });
176
+ }
177
+ const amountSum = allocator.sharing
178
+ .filter(s => s.mode === "Amount")
179
+ .reduce((sum, s) => sum + Number(s.sharing), 0);
180
+ const threshold = Number(cfg.threshold);
181
+ if (amountSum > 0 && amountSum < threshold) {
182
+ violations.push({
183
+ constraint_id: "F-A-07",
184
+ severity: "HIGH",
185
+ message: `Amount sum ${amountSum} < threshold ${threshold}`,
186
+ current_value: amountSum,
187
+ limit: threshold,
188
+ related_move_error: "EAMOUNT_BELOW_THRESHOLD (12)",
189
+ });
190
+ }
191
+ if (allocator.max != null && amountSum > Number(allocator.max)) {
192
+ violations.push({
193
+ constraint_id: "F-A-08",
194
+ severity: "MEDIUM",
195
+ message: `Amount sum ${amountSum} > max ${Number(allocator.max)}`,
196
+ current_value: amountSum,
197
+ limit: Number(allocator.max),
198
+ related_move_error: "EAMOUNT_EXCEEDS_MAX (13)",
199
+ });
200
+ }
201
+ const guardIdSharing = allocator.sharing.find(s => typeof s.who === "object" && "GuardIdentifier" in s.who);
202
+ if (guardIdSharing) {
203
+ }
204
+ }
205
+ return violations;
206
+ }
207
+ export function generateConfirmationText(puzzle) {
208
+ const lines = [];
209
+ lines.push("═══ Allocation Confirmation ═══");
210
+ lines.push("");
211
+ if (puzzle.intent) {
212
+ lines.push(`Action: ${puzzle.intent.action}`);
213
+ lines.push(`Host context: ${puzzle.intent.host_context}`);
214
+ lines.push(`Trigger: ${puzzle.intent.trigger_condition}`);
215
+ lines.push(`Distribution goal: ${puzzle.intent.distribution_goal}`);
216
+ if (puzzle.intent.failure_conditions.length > 0) {
217
+ lines.push("Failure conditions:");
218
+ for (const fc of puzzle.intent.failure_conditions)
219
+ lines.push(` - ${fc}`);
220
+ }
221
+ lines.push("");
222
+ }
223
+ if (puzzle.binding) {
224
+ lines.push("─ Binding ──────────────");
225
+ lines.push(`Coin type: ${puzzle.binding.coin_type}`);
226
+ if (puzzle.binding.host_service)
227
+ lines.push(`Host Service: ${puzzle.binding.host_service}`);
228
+ if (puzzle.binding.host_arbitration)
229
+ lines.push(`Host Arbitration: ${puzzle.binding.host_arbitration}`);
230
+ if (puzzle.binding.bound_order)
231
+ lines.push(`Bound Order: ${puzzle.binding.bound_order}`);
232
+ if (puzzle.binding.trigger_node)
233
+ lines.push(`Trigger node: ${puzzle.binding.trigger_node}`);
234
+ lines.push(`Guard objects (${puzzle.binding.guard_objects.length}): ${puzzle.binding.guard_objects.join(", ")}`);
235
+ lines.push(`Payment info source: ${puzzle.binding.payment_info_source}`);
236
+ lines.push("");
237
+ }
238
+ if (puzzle.data_source) {
239
+ const cfg = puzzle.data_source.allocators_config;
240
+ lines.push("─ Data Source ──────────────");
241
+ lines.push(`Description: ${cfg.description}`);
242
+ lines.push(`Threshold: ${cfg.threshold}`);
243
+ lines.push(`Allocators: ${cfg.allocators.length}`);
244
+ cfg.allocators.forEach((a, i) => {
245
+ lines.push(` [${i}] guard=${a.guard}, sharing=${a.sharing.length} items, fix=${a.fix ?? "0"}, max=${a.max ?? "null"}`);
246
+ a.sharing.forEach((s, j) => {
247
+ lines.push(` (${j}) who=${JSON.stringify(s.who)}, sharing=${s.sharing}, mode=${s.mode}`);
248
+ });
249
+ });
250
+ lines.push(`Payment info for_object: ${puzzle.data_source.payment_info.for_object}`);
251
+ lines.push(`Coin source: ${puzzle.data_source.coin_source}`);
252
+ lines.push("");
253
+ }
254
+ if (puzzle.logic) {
255
+ lines.push("─ Logic ──────────────");
256
+ lines.push(`Guard matching: ${puzzle.logic.guard_matching_strategy}`);
257
+ lines.push(`alloc() flow (${puzzle.logic.alloc_flow.length} steps):`);
258
+ for (const step of puzzle.logic.alloc_flow) {
259
+ lines.push(` ${step.step}. ${step.action}: ${step.description}`);
260
+ }
261
+ lines.push("");
262
+ }
263
+ const violations = validateConstraints(puzzle);
264
+ if (violations.length > 0) {
265
+ lines.push("─ Constraint Violations ──────────────");
266
+ for (const v of violations) {
267
+ lines.push(` [${v.severity}] ${v.constraint_id}: ${v.message}`);
268
+ }
269
+ lines.push("");
270
+ }
271
+ return lines.join("\n");
272
+ }
273
+ export function buildDefaultAllocFlow() {
274
+ return [
275
+ { step: 1, action: "pre_check", description: "assert balance >= threshold, payment_info.is_some(), allocators not empty" },
276
+ { step: 2, action: "guard_lookup", description: "iterate allocators[], locate alloc.guard == alloc_by_guard address; on hit call passport::result_for_guard hard verification (failure aborts E_VERIFY_FAILED)" },
277
+ { step: 3, action: "rate_base_calc", description: "total_rates = max - fix (if max) else balance - fix" },
278
+ { step: 4, action: "sharing_distribution", description: "iterate sharing[], split by mode (Amount/Rate/Surplus placeholder)" },
279
+ { step: 5, action: "surplus_distribution", description: "withdraw_all to surplus_recipient (if any)" },
280
+ { step: 6, action: "recipient_resolution", description: "resolve address from GuardIdentifier(passport) / Entity(static) / Signer(tx sender)" },
281
+ { step: 7, action: "payment_creation", description: "create Payment object, push to self.payment vector" },
282
+ ];
283
+ }
284
+ export function buildDefaultRecipientRules() {
285
+ return [
286
+ { recipient_type: "GuardIdentifier", resolution_source: "passport_table", safety_level: "safe" },
287
+ { recipient_type: "Entity", resolution_source: "static_address", safety_level: "safe" },
288
+ { recipient_type: "Signer", resolution_source: "tx_sender", safety_level: "dangerous" },
289
+ ];
290
+ }
291
+ export function buildDefaultLogicPuzzle() {
292
+ return {
293
+ alloc_flow: buildDefaultAllocFlow(),
294
+ guard_matching_strategy: "caller_specified_guard",
295
+ recipient_resolution_rules: buildDefaultRecipientRules(),
296
+ };
297
+ }
298
+ export const ALLOCATION_PUZZLE_VERSION = "1.0.0";
@@ -0,0 +1,78 @@
1
+ import { ALLOCATION_ERROR_CODES, type AllocationScene } from "./allocation-ledger.js";
2
+ export type AllocationRiskLevel = "CRITICAL" | "HIGH" | "MEDIUM" | "LOW";
3
+ export type AllocationRiskCategory = "structural" | "semantic" | "authority" | "lifecycle" | "cross_object";
4
+ export interface AllocationRisk {
5
+ id: string;
6
+ level: AllocationRiskLevel;
7
+ category: AllocationRiskCategory;
8
+ title: string;
9
+ description: string;
10
+ affected_stakeholders: AllocationStakeholder[];
11
+ scenario: string;
12
+ mitigation: string;
13
+ evidence?: string;
14
+ related_move_error?: string;
15
+ related_guard_risk?: string;
16
+ auto_fixable: boolean;
17
+ }
18
+ export type AllocationStakeholder = "owner" | "allocator" | "recipient" | "service_provider" | "system";
19
+ export interface AllocationRiskRule {
20
+ id: string;
21
+ category: AllocationRiskCategory;
22
+ trigger: string;
23
+ check: (ctx: AllocationRiskCheckContext) => AllocationRisk | null;
24
+ }
25
+ export interface AllocationRiskCheckContext {
26
+ object?: string | null;
27
+ allocators_config?: {
28
+ description?: string;
29
+ threshold: string | number;
30
+ allocators: {
31
+ guard: string;
32
+ sharing: {
33
+ who: {
34
+ GuardIdentifier: number;
35
+ } | {
36
+ Entity: string;
37
+ } | {
38
+ Signer: "signer";
39
+ };
40
+ sharing: string | number;
41
+ mode: "Amount" | "Rate" | "Surplus";
42
+ }[];
43
+ fix?: string | number;
44
+ max?: string | number | null;
45
+ }[];
46
+ };
47
+ operation_type?: "create" | "receive" | "alloc_by_guard" | "query";
48
+ coin_type?: string;
49
+ has_payment_info?: boolean;
50
+ trigger_source?: "service_order_allocators" | "arbitration_fees" | "standalone";
51
+ host_service_published?: boolean;
52
+ host_service_permission?: string;
53
+ referenced_treasuries_permissions?: Record<string, string>;
54
+ guard_signer_bindings?: Record<string, boolean>;
55
+ guard_has_time_lock?: Record<string, boolean>;
56
+ passport_identifier_types?: Record<number, string>;
57
+ has_fallback_allocator?: boolean;
58
+ guard_conditions_mutually_exclusive?: boolean;
59
+ bound_order?: string;
60
+ order_already_has_allocation?: boolean;
61
+ }
62
+ export declare const ALLOCATION_RISK_VERSION = "1.0.0";
63
+ export declare function getAllRiskRules(): AllocationRiskRule[];
64
+ export declare function getRiskRulesCount(): number;
65
+ export declare function getRiskRulesByCategory(category: AllocationRiskCategory): AllocationRiskRule[];
66
+ export interface AllocationRiskAssessment {
67
+ summary: string;
68
+ scene?: AllocationScene;
69
+ risks: AllocationRisk[];
70
+ overall_risk: AllocationRiskLevel;
71
+ risks_by_category: Partial<Record<AllocationRiskCategory, number>>;
72
+ risks_by_level: Partial<Record<AllocationRiskLevel, number>>;
73
+ stakeholder_advice: Partial<Record<AllocationStakeholder, string[]>>;
74
+ needs_human_review: boolean;
75
+ blocks_publish: boolean;
76
+ }
77
+ export declare function assessAllocationRisks(ctx: AllocationRiskCheckContext): AllocationRiskAssessment;
78
+ export { ALLOCATION_ERROR_CODES };