@wowok/agent-mcp 2.4.3 → 2.5.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 (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 +1392 -6
  253. package/dist/schema/project/index.js +426 -2
  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 +1802 -313
  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 +584 -70
  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 +2 -1
  277. package/dist/schemas/onchain_operations_permission.schema.json +2 -1
  278. package/dist/schemas/onchain_operations_personal.schema.json +2 -1
  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 +879 -0
  287. package/dist/schemas/project_operation.schema.json +473 -2
  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 +258 -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 +55 -8
  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,534 @@
1
+ import { MAX_ALLOCATOR_COUNT, ALLOCATION_MAX_SHARING_COUNT, RATE_TOTAL_FULL, ALLOCATION_ERROR_CODES, isSignerRecipient, isEntityRecipient, } from "./allocation-ledger.js";
2
+ import { assessAllocationRisks, } from "./allocation-risk.js";
3
+ export const ALLOCATION_PUBLISH_CHECKLIST = [
4
+ { id: "C-A-01", description: "Allocator count <= MAX_ALLOCATOR_COUNT (100)", passed: false, message: "" },
5
+ { id: "C-A-02", description: "Sharing count per Allocator <= MAX_SHARING_COUNT (100)", passed: false, message: "" },
6
+ { id: "C-A-03", description: "At most 1 Surplus sharing per Allocator (EMULTIPLE_SURPLUS)", passed: false, message: "" },
7
+ { id: "C-A-04", description: "Pure Rate mode sum(rates) == 10000 (ERATE_NOT_10000) OR Rate+Surplus sum <= 10000 (ERATE_EXCEEDS_10000)", passed: false, message: "" },
8
+ { id: "C-A-05", description: "Pure Amount mode sum(fix) >= threshold (EAMOUNT_BELOW_THRESHOLD)", passed: false, message: "" },
9
+ { id: "C-A-06", description: "Amount sum(fix) <= max when max is set (EAMOUNT_EXCEEDS_MAX)", passed: false, message: "" },
10
+ { id: "C-A-07", description: "allocators[].guard unique within the same Allocators (F-A-14)", passed: false, message: "" },
11
+ { id: "C-A-08", description: "Guard addresses valid (0x prefix, length >= 40)", passed: false, message: "" },
12
+ { id: "C-A-09", description: "Entity addresses valid (0x prefix, length >= 40)", passed: false, message: "" },
13
+ { id: "C-A-10", description: "Signer recipients have Guard Signer binding (R-A-2-01 CRITICAL theft risk)", passed: false, message: "" },
14
+ { id: "C-A-11", description: "payment_info present (required at alloc() time — ENO_PAYMENT_INFO)", passed: false, message: "" },
15
+ { id: "C-A-12", description: "coin type matches type_parameter (EINSUFFICIENT_BALANCE if mismatch)", passed: false, message: "" },
16
+ ];
17
+ function isValidAddress(s) {
18
+ return typeof s === "string" && s.startsWith("0x") && s.length >= 40;
19
+ }
20
+ function runStaticChecklist(input) {
21
+ const items = ALLOCATION_PUBLISH_CHECKLIST.map(c => ({ ...c }));
22
+ const data = input.allocation_json;
23
+ const isCreate = data.object !== null &&
24
+ data.object !== undefined &&
25
+ typeof data.object === "object" &&
26
+ !Array.isArray(data.object);
27
+ if (!isCreate) {
28
+ for (const item of items)
29
+ item.passed = true;
30
+ if (typeof data.object === "string") {
31
+ const objValid = isValidAddress(data.object);
32
+ items.find(i => i.id === "C-A-08").passed = objValid;
33
+ items.find(i => i.id === "C-A-08").message = objValid ? "" : `Allocation object address ${data.object} invalid`;
34
+ }
35
+ if (data.alloc_by_guard !== undefined) {
36
+ const guardValid = isValidAddress(data.alloc_by_guard);
37
+ items.find(i => i.id === "C-A-09").passed = guardValid;
38
+ items.find(i => i.id === "C-A-09").message = guardValid ? "" : `alloc_by_guard address ${data.alloc_by_guard} invalid`;
39
+ }
40
+ return { all_passed: items.every(i => i.passed), items };
41
+ }
42
+ const allocatorsData = data.allocators;
43
+ if (!allocatorsData) {
44
+ for (const item of items) {
45
+ if (item.id.startsWith("C-A-0")) {
46
+ item.passed = false;
47
+ item.message = "Missing required field: allocators";
48
+ }
49
+ else {
50
+ item.passed = true;
51
+ }
52
+ }
53
+ return { all_passed: false, items };
54
+ }
55
+ const allocators = allocatorsData.allocators;
56
+ const ca01 = items.find(i => i.id === "C-A-01");
57
+ ca01.passed = allocators.length <= MAX_ALLOCATOR_COUNT;
58
+ ca01.message = ca01.passed ? "" : `Allocator count ${allocators.length} > ${MAX_ALLOCATOR_COUNT}`;
59
+ let ca02Ok = true;
60
+ let ca02Msg = "";
61
+ for (let i = 0; i < allocators.length; i++) {
62
+ if (allocators[i].sharing.length > ALLOCATION_MAX_SHARING_COUNT) {
63
+ ca02Ok = false;
64
+ ca02Msg = `Allocator ${i} sharing count ${allocators[i].sharing.length} > ${ALLOCATION_MAX_SHARING_COUNT}`;
65
+ break;
66
+ }
67
+ }
68
+ const ca02 = items.find(i => i.id === "C-A-02");
69
+ ca02.passed = ca02Ok;
70
+ ca02.message = ca02Msg;
71
+ let ca03Ok = true;
72
+ let ca03Msg = "";
73
+ for (let i = 0; i < allocators.length; i++) {
74
+ const surplusCount = allocators[i].sharing.filter(s => s.mode === "Surplus").length;
75
+ if (surplusCount > 1) {
76
+ ca03Ok = false;
77
+ ca03Msg = `Allocator ${i} has ${surplusCount} Surplus (max 1 allowed)`;
78
+ break;
79
+ }
80
+ }
81
+ const ca03 = items.find(i => i.id === "C-A-03");
82
+ ca03.passed = ca03Ok;
83
+ ca03.message = ca03Msg;
84
+ let ca04Ok = true;
85
+ let ca04Msg = "";
86
+ for (let i = 0; i < allocators.length; i++) {
87
+ const a = allocators[i];
88
+ const rateSum = a.sharing
89
+ .filter(s => s.mode === "Rate")
90
+ .reduce((sum, s) => sum + Number(s.sharing), 0);
91
+ const hasSurplus = a.sharing.some(s => s.mode === "Surplus");
92
+ const hasRate = a.sharing.some(s => s.mode === "Rate");
93
+ if (hasRate && !hasSurplus && rateSum !== RATE_TOTAL_FULL) {
94
+ ca04Ok = false;
95
+ ca04Msg = `Allocator ${i} pure Rate sum ${rateSum} != ${RATE_TOTAL_FULL}`;
96
+ break;
97
+ }
98
+ if (hasRate && hasSurplus && rateSum > RATE_TOTAL_FULL) {
99
+ ca04Ok = false;
100
+ ca04Msg = `Allocator ${i} Rate+Surplus sum ${rateSum} > ${RATE_TOTAL_FULL}`;
101
+ break;
102
+ }
103
+ }
104
+ const ca04 = items.find(i => i.id === "C-A-04");
105
+ ca04.passed = ca04Ok;
106
+ ca04.message = ca04Msg;
107
+ let ca05Ok = true;
108
+ let ca05Msg = "";
109
+ const threshold = Number(allocatorsData.threshold);
110
+ for (let i = 0; i < allocators.length; i++) {
111
+ const a = allocators[i];
112
+ const hasRate = a.sharing.some(s => s.mode === "Rate");
113
+ const hasSurplus = a.sharing.some(s => s.mode === "Surplus");
114
+ const amountSum = a.sharing
115
+ .filter(s => s.mode === "Amount")
116
+ .reduce((sum, s) => sum + Number(s.sharing), 0);
117
+ if (!hasRate && !hasSurplus && amountSum > 0 && amountSum < threshold) {
118
+ ca05Ok = false;
119
+ ca05Msg = `Allocator ${i} pure Amount sum ${amountSum} < threshold ${threshold}`;
120
+ break;
121
+ }
122
+ }
123
+ const ca05 = items.find(i => i.id === "C-A-05");
124
+ ca05.passed = ca05Ok;
125
+ ca05.message = ca05Msg;
126
+ let ca06Ok = true;
127
+ let ca06Msg = "";
128
+ for (let i = 0; i < allocators.length; i++) {
129
+ const a = allocators[i];
130
+ if (a.max == null)
131
+ continue;
132
+ const amountSum = a.sharing
133
+ .filter(s => s.mode === "Amount")
134
+ .reduce((sum, s) => sum + Number(s.sharing), 0);
135
+ if (amountSum > Number(a.max)) {
136
+ ca06Ok = false;
137
+ ca06Msg = `Allocator ${i} Amount sum ${amountSum} > max ${Number(a.max)}`;
138
+ break;
139
+ }
140
+ }
141
+ const ca06 = items.find(i => i.id === "C-A-06");
142
+ ca06.passed = ca06Ok;
143
+ ca06.message = ca06Msg;
144
+ const guardSet = new Set();
145
+ let ca07Ok = true;
146
+ let ca07Msg = "";
147
+ for (let i = 0; i < allocators.length; i++) {
148
+ if (guardSet.has(allocators[i].guard)) {
149
+ ca07Ok = false;
150
+ ca07Msg = `Allocator ${i} guard ${allocators[i].guard} duplicates an earlier Allocator (F-A-14)`;
151
+ break;
152
+ }
153
+ guardSet.add(allocators[i].guard);
154
+ }
155
+ const ca07 = items.find(i => i.id === "C-A-07");
156
+ ca07.passed = ca07Ok;
157
+ ca07.message = ca07Msg;
158
+ let ca08Ok = true;
159
+ let ca08Msg = "";
160
+ for (let i = 0; i < allocators.length; i++) {
161
+ if (!isValidAddress(allocators[i].guard)) {
162
+ ca08Ok = false;
163
+ ca08Msg = `Allocator ${i} guard address ${allocators[i].guard} invalid`;
164
+ break;
165
+ }
166
+ }
167
+ const ca08 = items.find(i => i.id === "C-A-08");
168
+ ca08.passed = ca08Ok;
169
+ ca08.message = ca08Msg;
170
+ let ca09Ok = true;
171
+ let ca09Msg = "";
172
+ outer: for (let i = 0; i < allocators.length; i++) {
173
+ for (let j = 0; j < allocators[i].sharing.length; j++) {
174
+ const s = allocators[i].sharing[j];
175
+ if (isEntityRecipient(s.who)) {
176
+ const addr = s.who.Entity;
177
+ if (!isValidAddress(addr)) {
178
+ ca09Ok = false;
179
+ ca09Msg = `Allocator ${i} sharing ${j} Entity address ${addr} invalid`;
180
+ break outer;
181
+ }
182
+ }
183
+ }
184
+ }
185
+ const ca09 = items.find(i => i.id === "C-A-09");
186
+ ca09.passed = ca09Ok;
187
+ ca09.message = ca09Msg;
188
+ let ca10Ok = true;
189
+ let ca10Msg = "";
190
+ for (let i = 0; i < allocators.length; i++) {
191
+ const a = allocators[i];
192
+ const hasSigner = a.sharing.some(s => isSignerRecipient(s.who));
193
+ if (!hasSigner)
194
+ continue;
195
+ const bound = input.guard_signer_bindings?.[a.guard] === true;
196
+ if (!bound) {
197
+ ca10Ok = false;
198
+ ca10Msg = `Allocator ${i} (guard=${a.guard}) has Signer recipient but no Guard Signer binding — R-A-2-01 CRITICAL theft risk`;
199
+ break;
200
+ }
201
+ }
202
+ const ca10 = items.find(i => i.id === "C-A-10");
203
+ ca10.passed = ca10Ok;
204
+ ca10.message = ca10Msg;
205
+ const ca11 = items.find(i => i.id === "C-A-11");
206
+ ca11.passed = data.payment_info !== undefined && data.payment_info !== null;
207
+ ca11.message = ca11.passed ? "" : "payment_info missing — required at alloc() time (ENO_PAYMENT_INFO=9)";
208
+ const ca12 = items.find(i => i.id === "C-A-12");
209
+ const obj = data.object;
210
+ if (obj.type_parameter && data.coin) {
211
+ ca12.passed = true;
212
+ ca12.message = "";
213
+ }
214
+ else if (!obj.type_parameter) {
215
+ ca12.passed = false;
216
+ ca12.message = "type_parameter missing on object";
217
+ }
218
+ else {
219
+ ca12.passed = false;
220
+ ca12.message = "coin missing — required for create";
221
+ }
222
+ return {
223
+ all_passed: items.every(i => i.passed),
224
+ items,
225
+ };
226
+ }
227
+ function adaptRiskAssessment(input, _checklist) {
228
+ const ctx = {
229
+ object: typeof input.allocation_json.object === "string" ? input.allocation_json.object : null,
230
+ allocators_config: input.allocation_json.allocators,
231
+ operation_type: input.operation_type ?? "create",
232
+ has_payment_info: input.allocation_json.payment_info !== undefined,
233
+ host_service_published: true,
234
+ referenced_treasuries_permissions: input.referenced_treasuries_permissions,
235
+ guard_signer_bindings: input.guard_signer_bindings,
236
+ passport_identifier_types: input.passport_identifier_types,
237
+ guard_conditions_mutually_exclusive: input.guard_conditions_mutually_exclusive,
238
+ bound_order: input.bound_order,
239
+ order_already_has_allocation: input.order_already_has_allocation,
240
+ };
241
+ return assessAllocationRisks(ctx);
242
+ }
243
+ export const ALLOCATION_CONFIRMATION_QUESTIONS = [
244
+ {
245
+ id: "QA1",
246
+ question: "Are all Treasury / Entity recipient addresses correctly verified as trusted parties?",
247
+ requires_explicit_yes: true,
248
+ },
249
+ {
250
+ id: "QA2",
251
+ question: "If using multiple Allocators (caller-specified guard), are Guard conditions mutually exclusive to prevent caller confusion or silent lockup (alloc_by_guard silently returns on no match)?",
252
+ requires_explicit_yes: true,
253
+ related_risk_ids: ["R-A-4-02"],
254
+ },
255
+ {
256
+ id: "QA3",
257
+ question: "⚠️ If using sharing.who=Signer: is the Guard Signer binding verified (context(Signer)==authorized)? Signer without Guard binding = CRITICAL theft risk.",
258
+ requires_explicit_yes: true,
259
+ related_risk_ids: ["R-A-2-01"],
260
+ },
261
+ {
262
+ id: "QA4",
263
+ question: "If using Amount+Surplus hybrid (refund-first): is threshold set to refund amount (fix) to ensure balance covers the Amount distribution?",
264
+ requires_explicit_yes: true,
265
+ related_risk_ids: ["R-A-1-03"],
266
+ },
267
+ {
268
+ id: "QA5",
269
+ question: "Is payment_info correctly configured? alloc() will abort with ENO_PAYMENT_INFO (9) if missing.",
270
+ requires_explicit_yes: true,
271
+ related_risk_ids: ["R-A-5-02"],
272
+ },
273
+ {
274
+ id: "QA6",
275
+ question: "Has the Allocation been tested on testnet? Allocation is a 'passive object' — once created, allocators cannot be reconfigured.",
276
+ requires_explicit_yes: false,
277
+ },
278
+ ];
279
+ function processUserConfirmation(input, assessment) {
280
+ const questions = [...ALLOCATION_CONFIRMATION_QUESTIONS];
281
+ const hasSignerRecipient = input.allocation_json.allocators?.allocators.some(a => a.sharing.some(s => isSignerRecipient(s.who))) ?? false;
282
+ if (!hasSignerRecipient) {
283
+ const idx = questions.findIndex(q => q.id === "QA3");
284
+ if (idx >= 0)
285
+ questions.splice(idx, 1);
286
+ }
287
+ const allocatorCount = input.allocation_json.allocators?.allocators.length ?? 0;
288
+ if (allocatorCount <= 1) {
289
+ const idx = questions.findIndex(q => q.id === "QA2");
290
+ if (idx >= 0)
291
+ questions.splice(idx, 1);
292
+ }
293
+ const hasAmountSurplusHybrid = input.allocation_json.allocators?.allocators.some(a => a.sharing.some(s => s.mode === "Amount") && a.sharing.some(s => s.mode === "Surplus")) ?? false;
294
+ if (!hasAmountSurplusHybrid) {
295
+ const idx = questions.findIndex(q => q.id === "QA4");
296
+ if (idx >= 0)
297
+ questions.splice(idx, 1);
298
+ }
299
+ if (input.skip_user_confirmation) {
300
+ return {
301
+ questions_asked: questions,
302
+ responses: questions.map(q => ({ question_id: q.id, response: "yes" })),
303
+ all_confirmed: true,
304
+ };
305
+ }
306
+ return {
307
+ questions_asked: questions,
308
+ responses: [],
309
+ all_confirmed: false,
310
+ };
311
+ }
312
+ function verifyEnvironment(input) {
313
+ const checks = [];
314
+ if (typeof input.allocation_json.object === "string") {
315
+ checks.push({
316
+ name: "object_exists",
317
+ passed: true,
318
+ message: `Allocation object ${input.allocation_json.object} assumed to exist`,
319
+ });
320
+ }
321
+ if (input.allocation_json.alloc_by_guard) {
322
+ const guard = input.allocation_json.alloc_by_guard;
323
+ const allocators = input.allocation_json.allocators?.allocators ?? [];
324
+ const valid = isValidAddress(guard);
325
+ checks.push({
326
+ name: "alloc_by_guard_valid",
327
+ passed: valid,
328
+ message: valid
329
+ ? `Guard ${guard} address valid (SDK will verify it exists in allocators[].guard)`
330
+ : `Guard ${guard} address invalid`,
331
+ });
332
+ }
333
+ if (input.operation_type === "create") {
334
+ checks.push({
335
+ name: "signer_authorized",
336
+ passed: true,
337
+ message: "Signer must hold SERVICE_ORDER_ALLOCATOR=313 permission (or ARBITRATION_FEES_ALLOC=365 for arbitration fees)",
338
+ });
339
+ }
340
+ if (input.bound_order) {
341
+ const alreadyHas = input.order_already_has_allocation === true;
342
+ checks.push({
343
+ name: "order_allocation_1to1",
344
+ passed: !alreadyHas,
345
+ message: alreadyHas
346
+ ? `Order ${input.bound_order} already has an Allocation — E_ALLOCATION_ALREADY_SPECIFIED will abort`
347
+ : `Order ${input.bound_order} has no Allocation — 1:1 constraint satisfied`,
348
+ });
349
+ }
350
+ checks.push({
351
+ name: "testnet_test_recommended",
352
+ passed: true,
353
+ message: "Allocation is a 'passive object' — strongly recommend testnet test before mainnet deployment",
354
+ });
355
+ const allPassed = checks.every(c => c.passed);
356
+ return { passed: allPassed, checks };
357
+ }
358
+ export const ALLOCATION_CONFIRM_VERSION = "1.0.0";
359
+ export function runAllocationConfirmGate(input) {
360
+ const layersPassed = [];
361
+ const layersFailed = [];
362
+ const checklist = runStaticChecklist(input);
363
+ if (!checklist.all_passed) {
364
+ layersFailed.push("L1_checklist");
365
+ return {
366
+ status: "blocked_checklist",
367
+ checklist_result: checklist,
368
+ confirmation_text: generateConfirmationText(input, checklist),
369
+ block_reason: `Checklist failed: ${checklist.items.filter(i => !i.passed).map(i => i.id).join(", ")}`,
370
+ decision_record: {
371
+ timestamp: new Date().toISOString(),
372
+ gate_version: ALLOCATION_CONFIRM_VERSION,
373
+ final_status: "blocked_checklist",
374
+ layers_passed: layersPassed,
375
+ layers_failed: layersFailed,
376
+ },
377
+ };
378
+ }
379
+ layersPassed.push("L1_checklist");
380
+ const assessment = adaptRiskAssessment(input, checklist);
381
+ if (assessment.blocks_publish) {
382
+ layersFailed.push("L2_risk");
383
+ return {
384
+ status: "blocked_risk",
385
+ checklist_result: checklist,
386
+ risk_result: assessment,
387
+ confirmation_text: generateConfirmationText(input, checklist, assessment),
388
+ block_reason: `CRITICAL risks: ${assessment.risks.filter(r => r.level === "CRITICAL").map(r => r.id).join(", ")}`,
389
+ decision_record: {
390
+ timestamp: new Date().toISOString(),
391
+ gate_version: ALLOCATION_CONFIRM_VERSION,
392
+ final_status: "blocked_risk",
393
+ layers_passed: layersPassed,
394
+ layers_failed: layersFailed,
395
+ },
396
+ };
397
+ }
398
+ layersPassed.push("L2_risk");
399
+ const userConf = processUserConfirmation(input, assessment);
400
+ if (!userConf.all_confirmed) {
401
+ }
402
+ layersPassed.push("L3_user");
403
+ if (input.skip_environment_check) {
404
+ layersPassed.push("L4_environment");
405
+ }
406
+ else {
407
+ const env = verifyEnvironment(input);
408
+ if (!env.passed) {
409
+ layersFailed.push("L4_environment");
410
+ return {
411
+ status: "blocked_environment",
412
+ checklist_result: checklist,
413
+ risk_result: assessment,
414
+ user_confirmation: userConf,
415
+ environment_result: env,
416
+ confirmation_text: generateConfirmationText(input, checklist, assessment),
417
+ block_reason: `Environment check failed: ${env.checks.filter(c => !c.passed).map(c => c.name).join(", ")}`,
418
+ decision_record: {
419
+ timestamp: new Date().toISOString(),
420
+ gate_version: ALLOCATION_CONFIRM_VERSION,
421
+ final_status: "blocked_environment",
422
+ layers_passed: layersPassed,
423
+ layers_failed: layersFailed,
424
+ },
425
+ };
426
+ }
427
+ layersPassed.push("L4_environment");
428
+ }
429
+ return {
430
+ status: "approved",
431
+ checklist_result: checklist,
432
+ risk_result: assessment,
433
+ user_confirmation: userConf,
434
+ confirmation_text: generateConfirmationText(input, checklist, assessment),
435
+ decision_record: {
436
+ timestamp: new Date().toISOString(),
437
+ gate_version: ALLOCATION_CONFIRM_VERSION,
438
+ final_status: "approved",
439
+ layers_passed: layersPassed,
440
+ layers_failed: layersFailed,
441
+ },
442
+ };
443
+ }
444
+ function generateConfirmationText(input, checklist, assessment) {
445
+ const lines = [];
446
+ const data = input.allocation_json;
447
+ lines.push("═══ Allocation Confirmation ═══");
448
+ lines.push("");
449
+ const isCreate = data.object !== null &&
450
+ data.object !== undefined &&
451
+ typeof data.object === "object";
452
+ if (isCreate) {
453
+ const obj = data.object;
454
+ lines.push(`Allocation: NEW '${obj.name}' (${obj.type_parameter ?? "<missing>"})`);
455
+ }
456
+ else if (typeof data.object === "string") {
457
+ lines.push(`Allocation: OPERATE ${data.object}`);
458
+ }
459
+ lines.push("");
460
+ lines.push("─ Checklist ──────────────────");
461
+ for (const item of checklist.items) {
462
+ const mark = item.passed ? "✓" : "✗";
463
+ lines.push(` ${mark} ${item.id}: ${item.description}${item.message ? " — " + item.message : ""}`);
464
+ }
465
+ lines.push("");
466
+ if (assessment) {
467
+ lines.push("─ Risk Assessment ──────────────────");
468
+ lines.push(`Overall: ${assessment.overall_risk}`);
469
+ lines.push(`Detected: ${assessment.risks.length} risk(s)`);
470
+ for (const r of assessment.risks) {
471
+ lines.push(` [${r.level}] ${r.id}: ${r.title}`);
472
+ }
473
+ lines.push("");
474
+ }
475
+ lines.push("─ Operations ──────────────────");
476
+ if (isCreate && data.allocators) {
477
+ lines.push(`- Description: ${data.allocators.description}`);
478
+ lines.push(`- Threshold: ${data.allocators.threshold}`);
479
+ lines.push(`- Allocators: ${data.allocators.allocators.length}`);
480
+ data.allocators.allocators.forEach((a, i) => {
481
+ const surplusCount = a.sharing.filter(s => s.mode === "Surplus").length;
482
+ const rateSum = a.sharing.filter(s => s.mode === "Rate").reduce((sum, s) => sum + Number(s.sharing), 0);
483
+ const amountSum = a.sharing.filter(s => s.mode === "Amount").reduce((sum, s) => sum + Number(s.sharing), 0);
484
+ lines.push(` [${i}] guard=${a.guard}, sharing=${a.sharing.length} (Rate sum=${rateSum}, Amount sum=${amountSum}, Surplus=${surplusCount}), max=${a.max ?? "null"}`);
485
+ });
486
+ }
487
+ if (data.received_coins) {
488
+ lines.push(`- Receive: ${data.received_coins.received.length} CoinWrapper deposit(s)`);
489
+ }
490
+ if (data.alloc_by_guard) {
491
+ lines.push(`- Alloc by Guard: ${data.alloc_by_guard}`);
492
+ }
493
+ lines.push("");
494
+ lines.push("─ Error Code Reference ──────────────────");
495
+ lines.push(` EALLOCATORS_EMPTY=${ALLOCATION_ERROR_CODES.EALLOCATORS_EMPTY}, ENO_ALLOCATOR=${ALLOCATION_ERROR_CODES.ENO_ALLOCATOR}, ERATE_NOT_10000=${ALLOCATION_ERROR_CODES.ERATE_NOT_10000}`);
496
+ lines.push(` EMULTIPLE_SURPLUS=${ALLOCATION_ERROR_CODES.EMULTIPLE_SURPLUS}, ERATE_EXCEEDS_10000=${ALLOCATION_ERROR_CODES.ERATE_EXCEEDS_10000}, EINSUFFICIENT_BALANCE=${ALLOCATION_ERROR_CODES.EINSUFFICIENT_BALANCE}`);
497
+ lines.push(` ENO_PAYMENT_INFO=${ALLOCATION_ERROR_CODES.ENO_PAYMENT_INFO}, ESHARING_COUNT_EXCEEDED=${ALLOCATION_ERROR_CODES.ESHARING_COUNT_EXCEEDED}, EAMOUNT_BELOW_THRESHOLD=${ALLOCATION_ERROR_CODES.EAMOUNT_BELOW_THRESHOLD}`);
498
+ lines.push(` EAMOUNT_EXCEEDS_MAX=${ALLOCATION_ERROR_CODES.EAMOUNT_EXCEEDS_MAX}, EALLOCATOR_COUNT_EXCEEDED=${ALLOCATION_ERROR_CODES.EALLOCATOR_COUNT_EXCEEDED}`);
499
+ lines.push("");
500
+ return lines.join("\n");
501
+ }
502
+ export function progressiveAllocationCheck(input) {
503
+ const checklist = runStaticChecklist(input);
504
+ if (!checklist.all_passed) {
505
+ return {
506
+ stage: "checklist",
507
+ status: "fail",
508
+ message: `Checklist failed: ${checklist.items.filter(i => !i.passed).map(i => i.id).join(", ")}`,
509
+ next_action: "Fix failing checklist items (C-A-XX)",
510
+ };
511
+ }
512
+ const assessment = adaptRiskAssessment(input, checklist);
513
+ if (assessment.blocks_publish) {
514
+ return {
515
+ stage: "risk",
516
+ status: "fail",
517
+ message: `CRITICAL risks: ${assessment.risks.filter(r => r.level === "CRITICAL").map(r => r.id).join(", ")}`,
518
+ next_action: "Resolve CRITICAL risks (R-A-1-01 empty allocators, R-A-2-01 Signer theft) before proceeding",
519
+ };
520
+ }
521
+ if (assessment.needs_human_review) {
522
+ return {
523
+ stage: "confirmation",
524
+ status: "pending",
525
+ message: "Human review required for HIGH risks",
526
+ next_action: "Confirm risk acceptance (QA1 ~ QA6)",
527
+ };
528
+ }
529
+ return {
530
+ stage: "complete",
531
+ status: "pass",
532
+ message: "All checks passed",
533
+ };
534
+ }
@@ -0,0 +1,58 @@
1
+ import { type AllocationScene, type AllocationMode, type TriggerSource } from "./allocation-ledger.js";
2
+ import { type AllocationTemplate } from "./allocation-templates.js";
3
+ import { type SemanticToSchemaRule } from "./allocation-translation.js";
4
+ import { type AllocationRiskRule, type AllocationRiskAssessment, type AllocationStakeholder } from "./allocation-risk.js";
5
+ import { type AllocationPuzzle, type AllocationPuzzleCompleteness } from "./allocation-puzzle.js";
6
+ import { type ChecklistItem, type ConfirmationQuestion, type AllocationJsonForConfirm } from "./allocation-confirm.js";
7
+ export declare const ALLOCATION_CONTEXT_VERSION = "1.0.0";
8
+ export type AllocationInjectionMode = "initial_design" | "mid_design_review" | "pre_publish" | "post_publish_modify" | "stakeholder_review" | "apply_check";
9
+ export type AllocationStakeholderPerspective = AllocationStakeholder | "system";
10
+ export interface AllocationContextBundle {
11
+ version: string;
12
+ mode: AllocationInjectionMode;
13
+ stakeholder_perspective?: AllocationStakeholderPerspective;
14
+ matched_scene?: AllocationScene;
15
+ matched_template?: AllocationTemplate;
16
+ matched_pattern?: SemanticToSchemaRule;
17
+ puzzle_state?: AllocationPuzzle;
18
+ puzzle_completeness?: AllocationPuzzleCompleteness;
19
+ relevant_risks: AllocationRiskRule[];
20
+ risk_assessment?: AllocationRiskAssessment;
21
+ relevant_checklist: ChecklistItem[];
22
+ relevant_questions: ConfirmationQuestion[];
23
+ cross_object_refs: AllocationCrossObjectRef[];
24
+ onchain_constraints: AllocationOnchainConstraint[];
25
+ rendering_hints: AllocationRenderingHints;
26
+ }
27
+ export interface AllocationCrossObjectRef {
28
+ object: "Service" | "Order" | "Arbitration" | "Treasury" | "Guard" | "Passport" | "Progress" | "Machine" | "Payment";
29
+ field: string;
30
+ scene_id: string;
31
+ description: string;
32
+ }
33
+ export interface AllocationOnchainConstraint {
34
+ name: string;
35
+ value: string | number;
36
+ description: string;
37
+ }
38
+ export interface AllocationRenderingHints {
39
+ include_puzzle_template: boolean;
40
+ include_risk_details: boolean;
41
+ include_questions: boolean;
42
+ include_immutability_warning: boolean;
43
+ include_trigger_warning: boolean;
44
+ include_rate_overflow_warning: boolean;
45
+ max_length: number;
46
+ }
47
+ export interface BuildAllocationContextInput {
48
+ mode: AllocationInjectionMode;
49
+ intent?: string;
50
+ allocation_json?: AllocationJsonForConfirm;
51
+ stakeholder?: AllocationStakeholderPerspective;
52
+ target_trigger_source?: TriggerSource;
53
+ target_mode?: AllocationMode;
54
+ max_length?: number;
55
+ }
56
+ export declare function buildAllocationContext(input: BuildAllocationContextInput): AllocationContextBundle;
57
+ export declare function buildPromptFromAllocationContext(bundle: AllocationContextBundle): string;
58
+ export declare function getAllocationContextSummary(bundle: AllocationContextBundle): string;