@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,300 @@
1
+ export const TREASURY_PERMISSIONS = [
2
+ { index: 250, name: "TREASURY_NEW", description: "Create new Treasury", governed_operation: "treasury::new", active: true },
3
+ { index: 251, name: "TREASURY_DESCRIPTION", description: "Modify Treasury description", governed_operation: "treasury::description_set", active: true },
4
+ { index: 252, name: "TREASURY_DEPOSIT", description: "Internal deposit (Permission path)", governed_operation: "treasury::deposit", active: true },
5
+ { index: 253, name: "TREASURY_RECEIVE", description: "Receive CoinWrapper into balance", governed_operation: "treasury::receive", active: true },
6
+ { index: 254, name: "TREASURY_WITHDRAW", description: "Internal withdraw (Permission path, fixed amount)", governed_operation: "treasury::withdraw", active: true },
7
+ { index: 255, name: "TREASURY_EXTERNAL_DEPOSIT_GUARD", description: "Manage external deposit Guard list (add/remove/clear)", governed_operation: "treasury::external_deposit_guard_add/remove/clear", active: true },
8
+ { index: 256, name: "TREASURY_EXTERNAL_WITHDRAW_GUARD", description: "Manage external withdraw Guard list (add/remove/clear)", governed_operation: "treasury::external_withdraw_guard_add/remove/clear", active: true },
9
+ { index: 257, name: "TREASURY_OWNER_RECEIVE", description: "Owner receive (unwrap received objects, send to Permission owner)", governed_operation: "treasury::owner_receive / owner_receive_object", active: true },
10
+ { index: 258, name: "TREASURY_UM", description: "Set UM (User Manager = Contact object)", governed_operation: "treasury::um_set / um_none", active: true },
11
+ { index: -1, name: "TREASURY_EXTERNAL_DEPOSIT_RESERVED", description: "RESERVED — external_deposit uses Guard + Passport, does NOT call permission::check", governed_operation: "treasury::external_deposit (Guard path)", active: false },
12
+ { index: -1, name: "TREASURY_EXTERNAL_WITHDRAW_RESERVED", description: "RESERVED — external_withdraw uses Guard + Passport, does NOT call permission::check", governed_operation: "treasury::external_withdraw (Guard path)", active: false },
13
+ ];
14
+ export const TREASURY_SCENES = [
15
+ {
16
+ id: "treasury_fund_collection",
17
+ name: "Team fund collection (internal deposit + receive)",
18
+ coin_type_category: "generic",
19
+ permission_index_range: "250-254",
20
+ builtin_indexes: TREASURY_PERMISSIONS.filter(p => [250, 251, 252, 253, 254].includes(p.index)),
21
+ owner_operations: ["um_set (258)", "owner_receive (257)", "permission transfer"],
22
+ admin_operations: ["description_set (251)"],
23
+ permission_index_operations: [
24
+ "treasury::deposit (252)",
25
+ "treasury::receive (253)",
26
+ ],
27
+ external_operations: [],
28
+ guard_list_mutable_after_publish: true,
29
+ common_patterns: [
30
+ "Owner-only deposit: TREASURY_DEPOSIT (252) granted to team finance",
31
+ "Receive automation: TREASURY_RECEIVE (253) for CoinWrapper intake",
32
+ "No external Guard: all deposits via Permission path",
33
+ "inflow accumulates total team contributions",
34
+ ],
35
+ irreversibility: {
36
+ deposit: "reversible",
37
+ withdraw: "irreversible",
38
+ external_deposit: "reversible",
39
+ external_withdraw: "irreversible",
40
+ owner_receive: "irreversible",
41
+ },
42
+ cross_object_collaboration: [
43
+ "Allocator.sharing.who=Entity → Treasury address (fund inflow)",
44
+ "Treasury.receive (253) converts CoinWrapper to balance",
45
+ ],
46
+ recommended_templates: ["T-T-01", "T-T-06"],
47
+ },
48
+ {
49
+ id: "treasury_external_ops",
50
+ name: "External deposit / withdraw with Guard protection",
51
+ coin_type_category: "generic",
52
+ permission_index_range: "255-256",
53
+ builtin_indexes: TREASURY_PERMISSIONS.filter(p => [255, 256].includes(p.index)),
54
+ owner_operations: ["external_deposit_guard_add/remove/clear (255)", "external_withdraw_guard_add/remove/clear (256)"],
55
+ admin_operations: [],
56
+ permission_index_operations: [
57
+ "treasury::external_deposit_guard_* (255)",
58
+ "treasury::external_withdraw_guard_* (256)",
59
+ ],
60
+ external_operations: [
61
+ "treasury::external_deposit (Guard + Passport, no Permission)",
62
+ "treasury::external_withdraw (Guard + Passport, no Permission)",
63
+ ],
64
+ guard_list_mutable_after_publish: true,
65
+ common_patterns: [
66
+ "Whitelist external deposit: external_deposit_guard with identifier=None",
67
+ "Capped external withdraw: external_withdraw_guard with identifier=amount field",
68
+ "Pair external ops with Guard for zero-Permission external access",
69
+ "store_from_id tracks order/business ID for audit trail",
70
+ ],
71
+ irreversibility: {
72
+ deposit: "reversible",
73
+ withdraw: "irreversible",
74
+ external_deposit: "reversible",
75
+ external_withdraw: "irreversible",
76
+ owner_receive: "irreversible",
77
+ },
78
+ cross_object_collaboration: [
79
+ "Guard object referenced by external_deposit_guard / external_withdraw_guard",
80
+ "Passport object required for every external_deposit / external_withdraw call",
81
+ ],
82
+ recommended_templates: ["T-T-03", "T-T-04"],
83
+ },
84
+ {
85
+ id: "treasury_guard_protection",
86
+ name: "Guard-protected Treasury (asymmetric identifier design)",
87
+ coin_type_category: "generic",
88
+ permission_index_range: "255-256",
89
+ builtin_indexes: TREASURY_PERMISSIONS.filter(p => [255, 256].includes(p.index)),
90
+ owner_operations: ["external_deposit_guard management (255)", "external_withdraw_guard management (256)"],
91
+ admin_operations: [],
92
+ permission_index_operations: [
93
+ "treasury::external_deposit_guard_add (255)",
94
+ "treasury::external_withdraw_guard_add (256)",
95
+ ],
96
+ external_operations: [
97
+ "external_deposit via Guard (identifier: Option<u8> — None means no amount limit)",
98
+ "external_withdraw via Guard (identifier: u8 — REQUIRED, no None option)",
99
+ ],
100
+ guard_list_mutable_after_publish: true,
101
+ common_patterns: [
102
+ "Asymmetric identifier: deposit optional, withdraw required",
103
+ "Deposit amount from Coin itself; withdraw amount from Guard submission",
104
+ "upsert semantics: add updates existing guard, else appends",
105
+ "external_deposit splits coin if value > guard-specified amount",
106
+ ],
107
+ irreversibility: {
108
+ deposit: "reversible",
109
+ withdraw: "irreversible",
110
+ external_deposit: "reversible",
111
+ external_withdraw: "irreversible",
112
+ owner_receive: "irreversible",
113
+ },
114
+ cross_object_collaboration: [
115
+ "Guard table item value type must be number (is_number_type) for identifier",
116
+ "Guard table item value type must be address-compatible for store_from_id",
117
+ ],
118
+ recommended_templates: ["T-T-03"],
119
+ },
120
+ {
121
+ id: "treasury_permission_sharing",
122
+ name: "Treasury shared with Service via common Permission",
123
+ coin_type_category: "generic",
124
+ permission_index_range: "250-258",
125
+ builtin_indexes: TREASURY_PERMISSIONS.filter(p => p.active),
126
+ owner_operations: ["um_set (258)", "owner_receive (257)"],
127
+ admin_operations: ["description_set (251)"],
128
+ permission_index_operations: [
129
+ "treasury::deposit (252) + service::publish (311) on same Permission",
130
+ "treasury::withdraw (254) + service::compensation_fund_withdraw (315)",
131
+ ],
132
+ external_operations: [],
133
+ guard_list_mutable_after_publish: true,
134
+ common_patterns: [
135
+ "Shared Permission: Treasury + Service reference same Permission object",
136
+ "Unified admin list: single admin team manages both Service and Treasury",
137
+ "Simplifies key management: one Permission object per business unit",
138
+ ],
139
+ irreversibility: {
140
+ deposit: "reversible",
141
+ withdraw: "irreversible",
142
+ external_deposit: "reversible",
143
+ external_withdraw: "irreversible",
144
+ owner_receive: "irreversible",
145
+ },
146
+ cross_object_collaboration: [
147
+ "Service.compensation_fund (parallel design, NOT a Treasury)",
148
+ "Service.order_allocator → Treasury as Entity target",
149
+ ],
150
+ recommended_templates: ["T-T-04", "T-T-05"],
151
+ },
152
+ {
153
+ id: "treasury_um_delegation",
154
+ name: "UM delegation (User Manager = Contact object)",
155
+ coin_type_category: "generic",
156
+ permission_index_range: "258",
157
+ builtin_indexes: TREASURY_PERMISSIONS.filter(p => p.index === 258),
158
+ owner_operations: ["um_set (258)", "um_none (258)"],
159
+ admin_operations: [],
160
+ permission_index_operations: [
161
+ "treasury::um_set (258)",
162
+ "treasury::um_none (258)",
163
+ ],
164
+ external_operations: [],
165
+ guard_list_mutable_after_publish: true,
166
+ common_patterns: [
167
+ "Owner-only UM: TREASURY_UM (258) restricted to owner (assert_owner)",
168
+ "UM is a Contact object address, not a regular user address",
169
+ "UM ≠ admin: UM is for contact management, not permission management",
170
+ "um_none revokes UM and disaffiliates from Registrar",
171
+ ],
172
+ irreversibility: {
173
+ deposit: "reversible",
174
+ withdraw: "irreversible",
175
+ external_deposit: "reversible",
176
+ external_withdraw: "irreversible",
177
+ owner_receive: "irreversible",
178
+ },
179
+ cross_object_collaboration: [
180
+ "Contact object referenced by Treasury.um",
181
+ "Registrar.affiliation / disaffiliation tracks UM-Treasury binding",
182
+ ],
183
+ recommended_templates: ["T-T-01"],
184
+ },
185
+ {
186
+ id: "treasury_owner_receive",
187
+ name: "Owner receive (unwrap & forward to Permission owner)",
188
+ coin_type_category: "generic",
189
+ permission_index_range: "257",
190
+ builtin_indexes: TREASURY_PERMISSIONS.filter(p => p.index === 257),
191
+ owner_operations: ["owner_receive (257)", "owner_receive_object (257)"],
192
+ admin_operations: [],
193
+ permission_index_operations: [
194
+ "treasury::owner_receive (257)",
195
+ "treasury::owner_receive_object (257)",
196
+ ],
197
+ external_operations: [],
198
+ guard_list_mutable_after_publish: true,
199
+ common_patterns: [
200
+ "Forward received assets: CoinWrapper unwrapped, sent to Permission.owner",
201
+ "Does NOT write to history (direct forward, no Record entry)",
202
+ "Used when Treasury should not retain received assets",
203
+ "owner_receive_object handles non-coin objects too",
204
+ ],
205
+ irreversibility: {
206
+ deposit: "reversible",
207
+ withdraw: "irreversible",
208
+ external_deposit: "reversible",
209
+ external_withdraw: "irreversible",
210
+ owner_receive: "irreversible",
211
+ },
212
+ cross_object_collaboration: [
213
+ "Permission.owner is the recipient (resolved at tx time)",
214
+ "Received objects come from Allocator / Arbitration.fees_transfer / external deposits",
215
+ ],
216
+ recommended_templates: ["T-T-06"],
217
+ },
218
+ ];
219
+ export const TREASURY_LEDGER_VERSION = "1.0.0";
220
+ export function getScenesByHostObject(_host) {
221
+ return TREASURY_SCENES;
222
+ }
223
+ export function findSceneById(id) {
224
+ return TREASURY_SCENES.find(s => s.id === id);
225
+ }
226
+ export function findSceneByPermissionIndex(index) {
227
+ for (const scene of TREASURY_SCENES) {
228
+ if (scene.builtin_indexes.some(p => p.index === index && p.active))
229
+ return scene;
230
+ }
231
+ return undefined;
232
+ }
233
+ export function getBuiltinPermissionByIndex(index) {
234
+ return TREASURY_PERMISSIONS.find(p => p.index === index && p.active);
235
+ }
236
+ export function isBuiltinTreasuryPermission(index) {
237
+ return getBuiltinPermissionByIndex(index) !== undefined;
238
+ }
239
+ export function getActiveBuiltinPermissions() {
240
+ return TREASURY_PERMISSIONS.filter(p => p.active);
241
+ }
242
+ export function getReservedBuiltinPermissions() {
243
+ return TREASURY_PERMISSIONS.filter(p => !p.active);
244
+ }
245
+ export function inferSceneFromIntent(intent) {
246
+ const lower = intent.toLowerCase();
247
+ if (lower.includes("um") || lower.includes("delegate") || lower.includes("user manager")) {
248
+ return findSceneById("treasury_um_delegation");
249
+ }
250
+ if (lower.includes("owner_receive") || lower.includes("owner receive") || lower.includes("forward")) {
251
+ return findSceneById("treasury_owner_receive");
252
+ }
253
+ if (lower.includes("external") || lower.includes("guard")) {
254
+ if (lower.includes("deposit")) {
255
+ return findSceneById("treasury_external_ops");
256
+ }
257
+ if (lower.includes("withdraw")) {
258
+ return findSceneById("treasury_external_ops");
259
+ }
260
+ return findSceneById("treasury_guard_protection");
261
+ }
262
+ if (lower.includes("service") || lower.includes("share")) {
263
+ return findSceneById("treasury_permission_sharing");
264
+ }
265
+ if (lower.includes("deposit") || lower.includes("receive") || lower.includes("fund") || lower.includes("collect")) {
266
+ return findSceneById("treasury_fund_collection");
267
+ }
268
+ return undefined;
269
+ }
270
+ export function getTreasuryScenesCount() {
271
+ return TREASURY_SCENES.length;
272
+ }
273
+ export function getMoveFunctionsForPermissionIndex(index) {
274
+ const map = {
275
+ 250: ["treasury::new", "treasury::new_with_passport"],
276
+ 251: ["treasury::description_set", "treasury::description_set_with_passport"],
277
+ 252: ["treasury::deposit", "treasury::deposit_with_passport"],
278
+ 253: ["treasury::receive", "treasury::receive_with_passport"],
279
+ 254: ["treasury::withdraw", "treasury::withdraw_with_passport"],
280
+ 255: [
281
+ "treasury::external_deposit_guard_add",
282
+ "treasury::external_deposit_guard_add_with_passport",
283
+ "treasury::external_deposit_guard_remove",
284
+ "treasury::external_deposit_guard_remove_with_passport",
285
+ "treasury::external_deposit_guard_clear",
286
+ "treasury::external_deposit_guard_clear_with_passport",
287
+ ],
288
+ 256: [
289
+ "treasury::external_withdraw_guard_add",
290
+ "treasury::external_withdraw_guard_add_with_passport",
291
+ "treasury::external_withdraw_guard_remove",
292
+ "treasury::external_withdraw_guard_remove_with_passport",
293
+ "treasury::external_withdraw_guard_clear",
294
+ "treasury::external_withdraw_guard_clear_with_passport",
295
+ ],
296
+ 257: ["treasury::owner_receive", "treasury::owner_receive_object"],
297
+ 258: ["treasury::um_set", "treasury::um_set_with_passport", "treasury::um_none", "treasury::um_none_with_passport"],
298
+ };
299
+ return map[index] ?? [];
300
+ }
@@ -0,0 +1,163 @@
1
+ export interface TreasuryIntentPuzzle {
2
+ action: "create" | "deposit" | "withdraw" | "external_deposit" | "external_withdraw" | "receive" | "owner_receive" | "manage_guard" | "set_um" | "set_description";
3
+ coin_type?: string;
4
+ purpose: "team_fund" | "compensation_lock" | "revenue_collection" | "project_budget" | "customer_service_pool" | "fee_sink" | "refund_pool" | "custom";
5
+ rule_sentence: string;
6
+ failure_conditions: string[];
7
+ }
8
+ export interface TreasuryBindingPuzzle {
9
+ host_object: "Treasury";
10
+ type_parameter: string;
11
+ associated_permission: string;
12
+ associated_um?: string | null;
13
+ sharing_with_allocator: boolean;
14
+ sharing_with_arbitration: boolean;
15
+ sharing_with_service: boolean;
16
+ }
17
+ export interface TreasuryDataSourcePuzzle {
18
+ permission_object: string;
19
+ coin_source: {
20
+ type: "balance";
21
+ value: string;
22
+ } | {
23
+ type: "coin_object";
24
+ address: string;
25
+ } | {
26
+ type: "received";
27
+ received_objects: string[];
28
+ };
29
+ external_deposit_guards: AmountFromDepositGuardPuzzle[];
30
+ external_withdraw_guards: AmountFromWithdrawGuardPuzzle[];
31
+ passport_submissions?: {
32
+ guard_address: string;
33
+ identifier: number;
34
+ value_type: "number" | "address";
35
+ value: string | number;
36
+ }[];
37
+ }
38
+ export interface AmountFromDepositGuardPuzzle {
39
+ guard: string;
40
+ identifier?: number | null;
41
+ store_from_id?: number | null;
42
+ }
43
+ export interface AmountFromWithdrawGuardPuzzle {
44
+ guard: string;
45
+ identifier: number;
46
+ store_from_id?: number | null;
47
+ }
48
+ export type TreasuryOperation = {
49
+ type: "deposit";
50
+ coin: {
51
+ balance: string;
52
+ } | {
53
+ coin_object: string;
54
+ };
55
+ via: "permission" | "external_guard";
56
+ guard?: string;
57
+ payment_info: {
58
+ remark?: string;
59
+ index: number;
60
+ };
61
+ } | {
62
+ type: "withdraw";
63
+ amount: {
64
+ fixed: string;
65
+ } | {
66
+ by_external_withdraw_guard: string;
67
+ };
68
+ recipient: string;
69
+ payment_info: {
70
+ remark?: string;
71
+ index: number;
72
+ };
73
+ } | {
74
+ type: "receive";
75
+ received: string[] | "recently";
76
+ } | {
77
+ type: "owner_receive";
78
+ received: string[] | "recently";
79
+ } | {
80
+ type: "external_deposit_guard_op";
81
+ op: "add" | "set" | "remove" | "clear";
82
+ guards?: AmountFromDepositGuardPuzzle[] | string[];
83
+ } | {
84
+ type: "external_withdraw_guard_op";
85
+ op: "add" | "set" | "remove" | "clear";
86
+ guards?: AmountFromWithdrawGuardPuzzle[] | string[];
87
+ } | {
88
+ type: "description_set";
89
+ description: string;
90
+ } | {
91
+ type: "um_set";
92
+ um: string | null;
93
+ };
94
+ export interface TreasuryOperationPuzzle {
95
+ operations: TreasuryOperation[];
96
+ }
97
+ export interface TreasuryLogicPuzzle {
98
+ access_control_flow: {
99
+ path: "permission" | "external_guard" | "owner_receive";
100
+ permission_index?: number;
101
+ guard_address?: string;
102
+ passport_required: boolean;
103
+ }[];
104
+ fund_flow: {
105
+ from: "caller" | "balance" | "received";
106
+ to: "balance" | "recipient" | "permission_owner";
107
+ amount_source: "fixed" | "guard_identifier" | "coin_value" | "received_value";
108
+ }[];
109
+ history_record: {
110
+ op: "Withdraw" | "Deposit" | "Receive";
111
+ signer: string;
112
+ external_guard: string | null;
113
+ store_from_id: string | null;
114
+ }[];
115
+ }
116
+ export interface TreasuryConstraintChecklist {
117
+ F_T_01_description_length_le_4000: boolean;
118
+ F_T_02_external_deposit_guard_count_le_100: boolean;
119
+ F_T_03_external_withdraw_guard_count_le_200: boolean;
120
+ F_T_04_external_withdraw_guard_identifier_required: boolean;
121
+ F_T_05_guard_identifier_is_number_type: boolean;
122
+ F_T_06_store_from_id_address_compatible: boolean;
123
+ F_T_07_external_deposit_amount_sufficient: boolean;
124
+ F_T_08_external_withdraw_amount_le_balance: boolean;
125
+ F_T_09_withdraw_fixed_amount_le_balance: boolean;
126
+ F_T_10_external_guard_in_list: boolean;
127
+ F_T_11_coin_type_matches_type_parameter: boolean;
128
+ F_T_12_um_is_contact_object: boolean;
129
+ F_T_13_permission_index_matches_move: boolean;
130
+ }
131
+ export type TreasuryPuzzleDimension = "A" | "B" | "C" | "D" | "E" | "F";
132
+ export interface TreasuryPuzzle {
133
+ intent?: TreasuryIntentPuzzle;
134
+ binding?: TreasuryBindingPuzzle;
135
+ data_source?: TreasuryDataSourcePuzzle;
136
+ operations?: TreasuryOperationPuzzle;
137
+ logic?: TreasuryLogicPuzzle;
138
+ constraints?: TreasuryConstraintChecklist;
139
+ }
140
+ export interface TreasuryPuzzleCompleteness {
141
+ dimensions: TreasuryPuzzleDimension[];
142
+ missing: TreasuryPuzzleDimension[];
143
+ missing_details: {
144
+ dimension: TreasuryPuzzleDimension;
145
+ reason: string;
146
+ }[];
147
+ complete: boolean;
148
+ next_step: string;
149
+ }
150
+ export declare function initPuzzleFromIntent(intent: Partial<TreasuryIntentPuzzle>): TreasuryPuzzle;
151
+ export declare function checkPuzzleCompleteness(puzzle: TreasuryPuzzle): TreasuryPuzzleCompleteness;
152
+ export interface TreasuryConstraintViolation {
153
+ constraint_id: string;
154
+ severity: "CRITICAL" | "HIGH" | "MEDIUM" | "LOW";
155
+ message: string;
156
+ current_value?: string | number;
157
+ limit?: string | number;
158
+ }
159
+ export declare const MAX_EXTERNAL_DEPOSIT_GUARD_COUNT = 100;
160
+ export declare const MAX_EXTERNAL_WITHDRAW_GUARD_COUNT = 200;
161
+ export declare const MAX_DESCRIPTION_LENGTH = 4000;
162
+ export declare function validateConstraints(puzzle: TreasuryPuzzle): TreasuryConstraintViolation[];
163
+ export declare function generateConfirmationText(puzzle: TreasuryPuzzle): string;
@@ -0,0 +1,216 @@
1
+ export function initPuzzleFromIntent(intent) {
2
+ const puzzle = {};
3
+ if (intent.action || intent.rule_sentence) {
4
+ puzzle.intent = {
5
+ action: intent.action ?? "create",
6
+ coin_type: intent.coin_type,
7
+ purpose: intent.purpose ?? "custom",
8
+ rule_sentence: intent.rule_sentence ?? "",
9
+ failure_conditions: intent.failure_conditions ?? [],
10
+ };
11
+ }
12
+ puzzle.constraints = {
13
+ F_T_01_description_length_le_4000: true,
14
+ F_T_02_external_deposit_guard_count_le_100: true,
15
+ F_T_03_external_withdraw_guard_count_le_200: true,
16
+ F_T_04_external_withdraw_guard_identifier_required: true,
17
+ F_T_05_guard_identifier_is_number_type: true,
18
+ F_T_06_store_from_id_address_compatible: true,
19
+ F_T_07_external_deposit_amount_sufficient: true,
20
+ F_T_08_external_withdraw_amount_le_balance: true,
21
+ F_T_09_withdraw_fixed_amount_le_balance: true,
22
+ F_T_10_external_guard_in_list: true,
23
+ F_T_11_coin_type_matches_type_parameter: true,
24
+ F_T_12_um_is_contact_object: true,
25
+ F_T_13_permission_index_matches_move: true,
26
+ };
27
+ return puzzle;
28
+ }
29
+ export function checkPuzzleCompleteness(puzzle) {
30
+ const missing = [];
31
+ const missing_details = [];
32
+ if (!puzzle.intent) {
33
+ missing.push("A");
34
+ missing_details.push({ dimension: "A", reason: "Intent not specified (action + rule_sentence)" });
35
+ }
36
+ else if (!puzzle.intent.rule_sentence) {
37
+ missing.push("A");
38
+ missing_details.push({ dimension: "A", reason: "rule_sentence is empty" });
39
+ }
40
+ if (!puzzle.binding) {
41
+ missing.push("B");
42
+ missing_details.push({ dimension: "B", reason: "Binding not specified (type_parameter + permission)" });
43
+ }
44
+ else if (!puzzle.binding.type_parameter) {
45
+ missing.push("B");
46
+ missing_details.push({ dimension: "B", reason: "type_parameter (Coin type T) missing" });
47
+ }
48
+ else if (!puzzle.binding.associated_permission) {
49
+ missing.push("B");
50
+ missing_details.push({ dimension: "B", reason: "associated_permission missing" });
51
+ }
52
+ if (!puzzle.data_source && puzzle.intent?.action === "create") {
53
+ missing.push("C");
54
+ missing_details.push({ dimension: "C", reason: "Data source not specified (permission + coin_source + guards)" });
55
+ }
56
+ if (!puzzle.operations) {
57
+ missing.push("D");
58
+ missing_details.push({ dimension: "D", reason: "Operations not enumerated" });
59
+ }
60
+ if (!puzzle.logic) {
61
+ missing.push("E");
62
+ missing_details.push({ dimension: "E", reason: "Logic flow (access_control + fund_flow + history) not defined" });
63
+ }
64
+ if (!puzzle.constraints) {
65
+ missing.push("F");
66
+ missing_details.push({ dimension: "F", reason: "Constraints not checked" });
67
+ }
68
+ return {
69
+ dimensions: ["A", "B", "C", "D", "E", "F"],
70
+ missing,
71
+ missing_details,
72
+ complete: missing.length === 0,
73
+ next_step: missing.length === 0
74
+ ? "Puzzle complete — ready for confirmation text generation"
75
+ : `Next: complete dimension ${missing[0]} — ${missing_details[0].reason}`,
76
+ };
77
+ }
78
+ export const MAX_EXTERNAL_DEPOSIT_GUARD_COUNT = 100;
79
+ export const MAX_EXTERNAL_WITHDRAW_GUARD_COUNT = 200;
80
+ export const MAX_DESCRIPTION_LENGTH = 4000;
81
+ export function validateConstraints(puzzle) {
82
+ const violations = [];
83
+ if (puzzle.operations?.operations) {
84
+ for (const op of puzzle.operations.operations) {
85
+ if (op.type === "description_set" && op.description.length > MAX_DESCRIPTION_LENGTH) {
86
+ violations.push({
87
+ constraint_id: "F-T-01",
88
+ severity: "HIGH",
89
+ message: `Description length ${op.description.length} exceeds MAX_DESCRIPTION_LENGTH ${MAX_DESCRIPTION_LENGTH}`,
90
+ current_value: op.description.length,
91
+ limit: MAX_DESCRIPTION_LENGTH,
92
+ });
93
+ }
94
+ }
95
+ }
96
+ if (puzzle.data_source && puzzle.data_source.external_deposit_guards.length > MAX_EXTERNAL_DEPOSIT_GUARD_COUNT) {
97
+ violations.push({
98
+ constraint_id: "F-T-02",
99
+ severity: "HIGH",
100
+ message: `external_deposit_guard count ${puzzle.data_source.external_deposit_guards.length} exceeds ${MAX_EXTERNAL_DEPOSIT_GUARD_COUNT}`,
101
+ current_value: puzzle.data_source.external_deposit_guards.length,
102
+ limit: MAX_EXTERNAL_DEPOSIT_GUARD_COUNT,
103
+ });
104
+ }
105
+ if (puzzle.data_source && puzzle.data_source.external_withdraw_guards.length > MAX_EXTERNAL_WITHDRAW_GUARD_COUNT) {
106
+ violations.push({
107
+ constraint_id: "F-T-03",
108
+ severity: "HIGH",
109
+ message: `external_withdraw_guard count ${puzzle.data_source.external_withdraw_guards.length} exceeds ${MAX_EXTERNAL_WITHDRAW_GUARD_COUNT}`,
110
+ current_value: puzzle.data_source.external_withdraw_guards.length,
111
+ limit: MAX_EXTERNAL_WITHDRAW_GUARD_COUNT,
112
+ });
113
+ }
114
+ if (puzzle.data_source) {
115
+ for (const g of puzzle.data_source.external_withdraw_guards) {
116
+ if (g.identifier === undefined || g.identifier === null) {
117
+ violations.push({
118
+ constraint_id: "F-T-04",
119
+ severity: "HIGH",
120
+ message: `external_withdraw_guard ${g.guard} missing required identifier (u8)`,
121
+ });
122
+ }
123
+ }
124
+ }
125
+ if (puzzle.logic?.access_control_flow) {
126
+ for (const flow of puzzle.logic.access_control_flow) {
127
+ if (flow.permission_index !== undefined) {
128
+ if (flow.permission_index > 258 && flow.permission_index < 1000) {
129
+ violations.push({
130
+ constraint_id: "F-T-13",
131
+ severity: "CRITICAL",
132
+ message: `Permission index ${flow.permission_index} is in the 259-999 range; active Treasury indexes are 250-258. Possible R-T-01 residual.`,
133
+ current_value: flow.permission_index,
134
+ limit: "250-258",
135
+ });
136
+ }
137
+ }
138
+ }
139
+ }
140
+ return violations;
141
+ }
142
+ export function generateConfirmationText(puzzle) {
143
+ const lines = [];
144
+ lines.push("═══ Treasury Confirmation ═══");
145
+ lines.push("");
146
+ if (puzzle.intent) {
147
+ lines.push(`Action: ${puzzle.intent.action}`);
148
+ if (puzzle.intent.coin_type)
149
+ lines.push(`Coin type: ${puzzle.intent.coin_type}`);
150
+ lines.push(`Purpose: ${puzzle.intent.purpose}`);
151
+ lines.push(`Rule: ${puzzle.intent.rule_sentence}`);
152
+ if (puzzle.intent.failure_conditions.length > 0) {
153
+ lines.push("Failure conditions:");
154
+ for (const fc of puzzle.intent.failure_conditions)
155
+ lines.push(` - ${fc}`);
156
+ }
157
+ lines.push("");
158
+ }
159
+ if (puzzle.binding) {
160
+ lines.push("─ Binding ──────────────");
161
+ lines.push(`Host object: ${puzzle.binding.host_object}`);
162
+ lines.push(`Type parameter (T): ${puzzle.binding.type_parameter}`);
163
+ lines.push(`Associated Permission: ${puzzle.binding.associated_permission}`);
164
+ if (puzzle.binding.associated_um !== undefined) {
165
+ lines.push(`UM: ${puzzle.binding.associated_um ?? "(none)"}`);
166
+ }
167
+ lines.push(`Sharing with Allocator: ${puzzle.binding.sharing_with_allocator}`);
168
+ lines.push(`Sharing with Arbitration: ${puzzle.binding.sharing_with_arbitration}`);
169
+ lines.push(`Sharing with Service: ${puzzle.binding.sharing_with_service}`);
170
+ lines.push("");
171
+ }
172
+ if (puzzle.data_source) {
173
+ lines.push("─ Data Source ──────────────");
174
+ lines.push(`Permission: ${puzzle.data_source.permission_object}`);
175
+ lines.push(`Coin source: ${JSON.stringify(puzzle.data_source.coin_source)}`);
176
+ if (puzzle.data_source.external_deposit_guards.length > 0) {
177
+ lines.push(`External deposit guards (${puzzle.data_source.external_deposit_guards.length}):`);
178
+ for (const g of puzzle.data_source.external_deposit_guards) {
179
+ lines.push(` guard=${g.guard}, identifier=${g.identifier ?? "None"}, store_from_id=${g.store_from_id ?? "None"}`);
180
+ }
181
+ }
182
+ if (puzzle.data_source.external_withdraw_guards.length > 0) {
183
+ lines.push(`External withdraw guards (${puzzle.data_source.external_withdraw_guards.length}):`);
184
+ for (const g of puzzle.data_source.external_withdraw_guards) {
185
+ lines.push(` guard=${g.guard}, identifier=${g.identifier} (required), store_from_id=${g.store_from_id ?? "None"}`);
186
+ }
187
+ }
188
+ lines.push("");
189
+ }
190
+ if (puzzle.operations && puzzle.operations.operations.length > 0) {
191
+ lines.push("─ Operations ──────────────");
192
+ for (const op of puzzle.operations.operations)
193
+ lines.push(` - ${JSON.stringify(op)}`);
194
+ lines.push("");
195
+ }
196
+ if (puzzle.logic) {
197
+ lines.push("─ Logic ──────────────");
198
+ lines.push("Access control flow:");
199
+ for (const f of puzzle.logic.access_control_flow) {
200
+ lines.push(` path=${f.path}, perm_idx=${f.permission_index ?? "N/A"}, guard=${f.guard_address ?? "N/A"}, passport=${f.passport_required}`);
201
+ }
202
+ lines.push("Fund flow:");
203
+ for (const f of puzzle.logic.fund_flow) {
204
+ lines.push(` from=${f.from}, to=${f.to}, amount_source=${f.amount_source}`);
205
+ }
206
+ lines.push("");
207
+ }
208
+ const violations = validateConstraints(puzzle);
209
+ if (violations.length > 0) {
210
+ lines.push("─ Constraint Violations ──────────────");
211
+ for (const v of violations)
212
+ lines.push(` [${v.severity}] ${v.constraint_id}: ${v.message}`);
213
+ lines.push("");
214
+ }
215
+ return lines.join("\n");
216
+ }