@wowok/agent-mcp 2.4.1 → 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 (348) 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.d.ts +2 -2
  6. package/dist/index.js +29 -1621
  7. package/dist/knowledge/allocation-confirm.d.ts +115 -0
  8. package/dist/knowledge/allocation-confirm.js +534 -0
  9. package/dist/knowledge/allocation-context.d.ts +58 -0
  10. package/dist/knowledge/allocation-context.js +249 -0
  11. package/dist/knowledge/allocation-ledger.d.ts +67 -0
  12. package/dist/knowledge/allocation-ledger.js +463 -0
  13. package/dist/knowledge/allocation-puzzle.d.ts +135 -0
  14. package/dist/knowledge/allocation-puzzle.js +298 -0
  15. package/dist/knowledge/allocation-risk.d.ts +78 -0
  16. package/dist/knowledge/allocation-risk.js +568 -0
  17. package/dist/knowledge/allocation-templates.d.ts +38 -0
  18. package/dist/knowledge/allocation-templates.js +970 -0
  19. package/dist/knowledge/allocation-translation.d.ts +72 -0
  20. package/dist/knowledge/allocation-translation.js +585 -0
  21. package/dist/knowledge/arb-risk.d.ts +37 -0
  22. package/dist/knowledge/arb-risk.js +210 -0
  23. package/dist/knowledge/arbitration-confirm.d.ts +135 -0
  24. package/dist/knowledge/arbitration-confirm.js +559 -0
  25. package/dist/knowledge/arbitration-context.d.ts +81 -0
  26. package/dist/knowledge/arbitration-context.js +505 -0
  27. package/dist/knowledge/arbitration-ledger.d.ts +62 -0
  28. package/dist/knowledge/arbitration-ledger.js +521 -0
  29. package/dist/knowledge/arbitration-puzzle.d.ts +84 -0
  30. package/dist/knowledge/arbitration-puzzle.js +304 -0
  31. package/dist/knowledge/arbitration-risk.d.ts +112 -0
  32. package/dist/knowledge/arbitration-risk.js +433 -0
  33. package/dist/knowledge/arbitration-templates.d.ts +38 -0
  34. package/dist/knowledge/arbitration-templates.js +276 -0
  35. package/dist/knowledge/arbitration-translation.d.ts +91 -0
  36. package/dist/knowledge/arbitration-translation.js +487 -0
  37. package/dist/knowledge/bridge-risk.d.ts +36 -0
  38. package/dist/knowledge/bridge-risk.js +263 -0
  39. package/dist/knowledge/contact-risk.d.ts +32 -0
  40. package/dist/knowledge/contact-risk.js +200 -0
  41. package/dist/knowledge/demand-confirm.d.ts +32 -0
  42. package/dist/knowledge/demand-confirm.js +206 -0
  43. package/dist/knowledge/demand-risk.d.ts +30 -0
  44. package/dist/knowledge/demand-risk.js +240 -0
  45. package/dist/knowledge/demand-translation.d.ts +55 -0
  46. package/dist/knowledge/demand-translation.js +354 -0
  47. package/dist/knowledge/deployment-scanner.d.ts +63 -0
  48. package/dist/knowledge/deployment-scanner.js +762 -0
  49. package/dist/knowledge/examples-scanner-cli.d.ts +1 -0
  50. package/dist/knowledge/examples-scanner-cli.js +26 -0
  51. package/dist/knowledge/examples-scanner.d.ts +121 -0
  52. package/dist/knowledge/examples-scanner.js +825 -0
  53. package/dist/knowledge/flywheel-loop.d.ts +3 -0
  54. package/dist/knowledge/flywheel-loop.js +32 -3
  55. package/dist/knowledge/glossary.js +3 -1
  56. package/dist/knowledge/guard-confirm.d.ts +86 -0
  57. package/dist/knowledge/guard-confirm.js +406 -0
  58. package/dist/knowledge/guard-context.d.ts +56 -0
  59. package/dist/knowledge/guard-context.js +287 -0
  60. package/dist/knowledge/guard-design-patterns.d.ts +37 -0
  61. package/dist/knowledge/guard-design-patterns.js +257 -0
  62. package/dist/knowledge/guard-ledger.js +14 -0
  63. package/dist/knowledge/guard-lint.d.ts +1 -0
  64. package/dist/knowledge/guard-lint.js +83 -3
  65. package/dist/knowledge/guard-migration.d.ts +48 -0
  66. package/dist/knowledge/guard-migration.js +228 -0
  67. package/dist/knowledge/guard-puzzle.js +3 -2
  68. package/dist/knowledge/guard-risk.d.ts +3 -1
  69. package/dist/knowledge/guard-risk.js +832 -64
  70. package/dist/knowledge/guard-templates.d.ts +1 -0
  71. package/dist/knowledge/guard-templates.js +278 -2
  72. package/dist/knowledge/guard-translation.js +6 -5
  73. package/dist/knowledge/index.d.ts +342 -0
  74. package/dist/knowledge/index.js +344 -0
  75. package/dist/knowledge/machine-confirm.d.ts +102 -0
  76. package/dist/knowledge/machine-confirm.js +559 -0
  77. package/dist/knowledge/machine-context.d.ts +160 -0
  78. package/dist/knowledge/machine-context.js +812 -0
  79. package/dist/knowledge/machine-ledger.d.ts +41 -0
  80. package/dist/knowledge/machine-ledger.js +315 -0
  81. package/dist/knowledge/machine-puzzle.d.ts +206 -0
  82. package/dist/knowledge/machine-puzzle.js +494 -0
  83. package/dist/knowledge/machine-risk.d.ts +75 -0
  84. package/dist/knowledge/machine-risk.js +644 -0
  85. package/dist/knowledge/machine-templates.d.ts +92 -0
  86. package/dist/knowledge/machine-templates.js +1592 -0
  87. package/dist/knowledge/machine-topology.d.ts +57 -0
  88. package/dist/knowledge/machine-topology.js +234 -0
  89. package/dist/knowledge/machine-translation.d.ts +96 -0
  90. package/dist/knowledge/machine-translation.js +513 -0
  91. package/dist/knowledge/mcp-schema-audit-cli.d.ts +1 -0
  92. package/dist/knowledge/mcp-schema-audit-cli.js +45 -0
  93. package/dist/knowledge/mcp-schema-audit.d.ts +90 -0
  94. package/dist/knowledge/mcp-schema-audit.js +772 -0
  95. package/dist/knowledge/onchain-constants.d.ts +4 -0
  96. package/dist/knowledge/onchain-constants.js +35 -0
  97. package/dist/knowledge/order-confirm.d.ts +115 -0
  98. package/dist/knowledge/order-confirm.js +573 -0
  99. package/dist/knowledge/order-context.d.ts +66 -0
  100. package/dist/knowledge/order-context.js +390 -0
  101. package/dist/knowledge/order-ledger.d.ts +69 -0
  102. package/dist/knowledge/order-ledger.js +341 -0
  103. package/dist/knowledge/order-puzzle.d.ts +159 -0
  104. package/dist/knowledge/order-puzzle.js +255 -0
  105. package/dist/knowledge/order-risk.d.ts +66 -0
  106. package/dist/knowledge/order-risk.js +653 -0
  107. package/dist/knowledge/order-templates.d.ts +50 -0
  108. package/dist/knowledge/order-templates.js +368 -0
  109. package/dist/knowledge/order-translation.d.ts +78 -0
  110. package/dist/knowledge/order-translation.js +550 -0
  111. package/dist/knowledge/passport-confirm.d.ts +130 -0
  112. package/dist/knowledge/passport-confirm.js +531 -0
  113. package/dist/knowledge/passport-context.d.ts +59 -0
  114. package/dist/knowledge/passport-context.js +306 -0
  115. package/dist/knowledge/passport-ledger.d.ts +48 -0
  116. package/dist/knowledge/passport-ledger.js +282 -0
  117. package/dist/knowledge/passport-puzzle.d.ts +108 -0
  118. package/dist/knowledge/passport-puzzle.js +333 -0
  119. package/dist/knowledge/passport-risk.d.ts +70 -0
  120. package/dist/knowledge/passport-risk.js +450 -0
  121. package/dist/knowledge/passport-templates.d.ts +40 -0
  122. package/dist/knowledge/passport-templates.js +568 -0
  123. package/dist/knowledge/passport-translation.d.ts +68 -0
  124. package/dist/knowledge/passport-translation.js +516 -0
  125. package/dist/knowledge/payment-risk.d.ts +33 -0
  126. package/dist/knowledge/payment-risk.js +182 -0
  127. package/dist/knowledge/permission-confirm.d.ts +110 -0
  128. package/dist/knowledge/permission-confirm.js +426 -0
  129. package/dist/knowledge/permission-context.d.ts +58 -0
  130. package/dist/knowledge/permission-context.js +224 -0
  131. package/dist/knowledge/permission-ledger.d.ts +38 -0
  132. package/dist/knowledge/permission-ledger.js +403 -0
  133. package/dist/knowledge/permission-puzzle.d.ts +122 -0
  134. package/dist/knowledge/permission-puzzle.js +173 -0
  135. package/dist/knowledge/permission-risk.d.ts +76 -0
  136. package/dist/knowledge/permission-risk.js +411 -0
  137. package/dist/knowledge/permission-templates.d.ts +38 -0
  138. package/dist/knowledge/permission-templates.js +234 -0
  139. package/dist/knowledge/permission-translation.d.ts +57 -0
  140. package/dist/knowledge/permission-translation.js +350 -0
  141. package/dist/knowledge/personal-risk.d.ts +36 -0
  142. package/dist/knowledge/personal-risk.js +212 -0
  143. package/dist/knowledge/progress-confirm.d.ts +108 -0
  144. package/dist/knowledge/progress-confirm.js +456 -0
  145. package/dist/knowledge/progress-context.d.ts +123 -0
  146. package/dist/knowledge/progress-context.js +452 -0
  147. package/dist/knowledge/progress-ledger.d.ts +63 -0
  148. package/dist/knowledge/progress-ledger.js +327 -0
  149. package/dist/knowledge/progress-puzzle.d.ts +82 -0
  150. package/dist/knowledge/progress-puzzle.js +219 -0
  151. package/dist/knowledge/progress-risk.d.ts +74 -0
  152. package/dist/knowledge/progress-risk.js +461 -0
  153. package/dist/knowledge/progress-templates.d.ts +38 -0
  154. package/dist/knowledge/progress-templates.js +228 -0
  155. package/dist/knowledge/progress-translation.d.ts +52 -0
  156. package/dist/knowledge/progress-translation.js +401 -0
  157. package/dist/knowledge/proof-confirm.d.ts +31 -0
  158. package/dist/knowledge/proof-confirm.js +187 -0
  159. package/dist/knowledge/proof-risk.d.ts +33 -0
  160. package/dist/knowledge/proof-risk.js +207 -0
  161. package/dist/knowledge/proof-translation.d.ts +52 -0
  162. package/dist/knowledge/proof-translation.js +283 -0
  163. package/dist/knowledge/registrar-risk.d.ts +34 -0
  164. package/dist/knowledge/registrar-risk.js +217 -0
  165. package/dist/knowledge/repository-confirm.d.ts +36 -0
  166. package/dist/knowledge/repository-confirm.js +242 -0
  167. package/dist/knowledge/repository-risk.d.ts +40 -0
  168. package/dist/knowledge/repository-risk.js +312 -0
  169. package/dist/knowledge/repository-translation.d.ts +58 -0
  170. package/dist/knowledge/repository-translation.js +422 -0
  171. package/dist/knowledge/resource-risk.d.ts +32 -0
  172. package/dist/knowledge/resource-risk.js +157 -0
  173. package/dist/knowledge/reward-confirm.d.ts +113 -0
  174. package/dist/knowledge/reward-confirm.js +496 -0
  175. package/dist/knowledge/reward-context.d.ts +127 -0
  176. package/dist/knowledge/reward-context.js +504 -0
  177. package/dist/knowledge/reward-ledger.d.ts +96 -0
  178. package/dist/knowledge/reward-ledger.js +502 -0
  179. package/dist/knowledge/reward-puzzle.d.ts +97 -0
  180. package/dist/knowledge/reward-puzzle.js +288 -0
  181. package/dist/knowledge/reward-risk.d.ts +84 -0
  182. package/dist/knowledge/reward-risk.js +545 -0
  183. package/dist/knowledge/reward-translation.d.ts +58 -0
  184. package/dist/knowledge/reward-translation.js +501 -0
  185. package/dist/knowledge/safety-rules.js +11 -3
  186. package/dist/knowledge/scenario-modes.d.ts +53 -0
  187. package/dist/knowledge/scenario-modes.js +302 -0
  188. package/dist/knowledge/service-confirm.d.ts +152 -0
  189. package/dist/knowledge/service-confirm.js +699 -0
  190. package/dist/knowledge/service-context.d.ts +66 -0
  191. package/dist/knowledge/service-context.js +403 -0
  192. package/dist/knowledge/service-ledger.d.ts +71 -0
  193. package/dist/knowledge/service-ledger.js +609 -0
  194. package/dist/knowledge/service-puzzle.d.ts +158 -0
  195. package/dist/knowledge/service-puzzle.js +236 -0
  196. package/dist/knowledge/service-risk.d.ts +108 -0
  197. package/dist/knowledge/service-risk.js +615 -0
  198. package/dist/knowledge/service-templates.d.ts +39 -0
  199. package/dist/knowledge/service-templates.js +418 -0
  200. package/dist/knowledge/service-translation.d.ts +103 -0
  201. package/dist/knowledge/service-translation.js +622 -0
  202. package/dist/knowledge/tools-reference.d.ts +17 -0
  203. package/dist/knowledge/tools-reference.js +151 -0
  204. package/dist/knowledge/treasury-confirm.d.ts +133 -0
  205. package/dist/knowledge/treasury-confirm.js +512 -0
  206. package/dist/knowledge/treasury-context.d.ts +64 -0
  207. package/dist/knowledge/treasury-context.js +363 -0
  208. package/dist/knowledge/treasury-ledger.d.ts +42 -0
  209. package/dist/knowledge/treasury-ledger.js +300 -0
  210. package/dist/knowledge/treasury-puzzle.d.ts +163 -0
  211. package/dist/knowledge/treasury-puzzle.js +216 -0
  212. package/dist/knowledge/treasury-risk.d.ts +86 -0
  213. package/dist/knowledge/treasury-risk.js +440 -0
  214. package/dist/knowledge/treasury-templates.d.ts +38 -0
  215. package/dist/knowledge/treasury-templates.js +316 -0
  216. package/dist/knowledge/treasury-translation.d.ts +78 -0
  217. package/dist/knowledge/treasury-translation.js +498 -0
  218. package/dist/knowledge/util-risk.d.ts +30 -0
  219. package/dist/knowledge/util-risk.js +135 -0
  220. package/dist/project/business-puzzle.d.ts +47 -0
  221. package/dist/project/business-puzzle.js +372 -0
  222. package/dist/project/deployment-doc.d.ts +61 -0
  223. package/dist/project/deployment-doc.js +432 -0
  224. package/dist/project/graph.d.ts +1 -0
  225. package/dist/project/graph.js +27 -1
  226. package/dist/project/index.d.ts +1 -0
  227. package/dist/project/index.js +39 -2
  228. package/dist/project/namespace.d.ts +11 -1
  229. package/dist/project/namespace.js +27 -2
  230. package/dist/project/query.d.ts +2 -0
  231. package/dist/project/query.js +56 -15
  232. package/dist/project/risk-aggregator.d.ts +50 -0
  233. package/dist/project/risk-aggregator.js +280 -0
  234. package/dist/project/substep-trace.d.ts +130 -0
  235. package/dist/project/substep-trace.js +332 -0
  236. package/dist/rules.d.ts +12 -0
  237. package/dist/rules.js +9 -0
  238. package/dist/schema/call/allocation.d.ts +44 -44
  239. package/dist/schema/call/arbitration.d.ts +141 -141
  240. package/dist/schema/call/base.d.ts +386 -386
  241. package/dist/schema/call/base.js +6 -6
  242. package/dist/schema/call/bridge-handler.d.ts +5 -2
  243. package/dist/schema/call/bridge.d.ts +159 -159
  244. package/dist/schema/call/contact.d.ts +110 -110
  245. package/dist/schema/call/demand.d.ts +76 -76
  246. package/dist/schema/call/handler.d.ts +2 -3
  247. package/dist/schema/call/handler.js +1 -1
  248. package/dist/schema/call/machine.d.ts +96 -96
  249. package/dist/schema/call/order.d.ts +98 -110
  250. package/dist/schema/call/permission-handler.d.ts +5 -0
  251. package/dist/schema/call/permission-handler.js +54 -0
  252. package/dist/schema/call/permission.d.ts +108 -108
  253. package/dist/schema/call/personal.d.ts +14 -14
  254. package/dist/schema/call/progress.d.ts +57 -72
  255. package/dist/schema/call/progress.js +7 -4
  256. package/dist/schema/call/proof.d.ts +18 -18
  257. package/dist/schema/call/proof.js +12 -7
  258. package/dist/schema/call/repository.d.ts +154 -154
  259. package/dist/schema/call/reward.d.ts +55 -55
  260. package/dist/schema/call/semantic.js +1 -1
  261. package/dist/schema/call/service.d.ts +238 -238
  262. package/dist/schema/call/treasury.d.ts +93 -93
  263. package/dist/schema/config/index.d.ts +178 -5
  264. package/dist/schema/config/index.js +52 -1
  265. package/dist/schema/local/index.d.ts +3554 -836
  266. package/dist/schema/local/index.js +2 -1
  267. package/dist/schema/messenger/index.d.ts +162 -162
  268. package/dist/schema/operations.d.ts +1102 -1118
  269. package/dist/schema/operations.js +7 -1
  270. package/dist/schema/project/index.d.ts +1392 -6
  271. package/dist/schema/project/index.js +426 -2
  272. package/dist/schema/query/index.d.ts +818 -818
  273. package/dist/schema/query/index.js +15 -9
  274. package/dist/schema/schema-query/index.d.ts +23 -3
  275. package/dist/schema/schema-query/index.js +13 -2
  276. package/dist/schema/sync-layer4.d.ts +21 -0
  277. package/dist/schema/sync-layer4.js +261 -0
  278. package/dist/schema/trust/index.d.ts +26 -26
  279. package/dist/schema/utils/guard-query-utils.d.ts +7 -0
  280. package/dist/schema/utils/guard-query-utils.js +14 -1
  281. package/dist/schemas/account_operation.output.json +718 -0
  282. package/dist/schemas/bridge_operation.output.json +1 -1
  283. package/dist/schemas/config_operation.output.json +173 -0
  284. package/dist/schemas/index.json +9 -1
  285. package/dist/schemas/local_info_operation.output.json +718 -0
  286. package/dist/schemas/local_mark_operation.output.json +718 -0
  287. package/dist/schemas/messenger_operation.output.json +1 -1
  288. package/dist/schemas/onchain_events.output.json +1 -1
  289. package/dist/schemas/onchain_operations.output.json +5 -4
  290. package/dist/schemas/onchain_operations.schema.json +1813 -333
  291. package/dist/schemas/onchain_operations_allocation.schema.json +9 -11
  292. package/dist/schemas/onchain_operations_arbitration.schema.json +2 -1
  293. package/dist/schemas/onchain_operations_contact.schema.json +2 -1
  294. package/dist/schemas/onchain_operations_demand.schema.json +2 -1
  295. package/dist/schemas/onchain_operations_gen_passport.schema.json +878 -872
  296. package/dist/schemas/onchain_operations_gen_proof.schema.json +273 -0
  297. package/dist/schemas/onchain_operations_guard.schema.json +584 -70
  298. package/dist/schemas/onchain_operations_machine.schema.json +4 -6
  299. package/dist/schemas/onchain_operations_order.schema.json +13 -9
  300. package/dist/schemas/onchain_operations_payment.schema.json +2 -1
  301. package/dist/schemas/onchain_operations_permission.schema.json +2 -1
  302. package/dist/schemas/onchain_operations_personal.schema.json +2 -1
  303. package/dist/schemas/onchain_operations_progress.schema.json +14 -10
  304. package/dist/schemas/onchain_operations_proof.schema.json +699 -0
  305. package/dist/schemas/onchain_operations_repository.schema.json +2 -1
  306. package/dist/schemas/onchain_operations_reward.schema.json +2 -1
  307. package/dist/schemas/onchain_operations_service.schema.json +4 -6
  308. package/dist/schemas/onchain_operations_treasury.schema.json +2 -1
  309. package/dist/schemas/onchain_table_data.output.json +6 -12
  310. package/dist/schemas/onchain_table_data.schema.json +32 -1
  311. package/dist/schemas/project_operation.output.json +879 -0
  312. package/dist/schemas/project_operation.schema.json +473 -2
  313. package/dist/schemas/query_toolkit.output.json +14906 -6
  314. package/dist/schemas/schema_query.output.json +38 -1
  315. package/dist/telemetry/index.d.ts +1 -1
  316. package/dist/tools/handlers/bridge.d.ts +1 -0
  317. package/dist/tools/handlers/bridge.js +1 -0
  318. package/dist/tools/handlers/config.d.ts +2 -0
  319. package/dist/tools/handlers/config.js +74 -0
  320. package/dist/tools/handlers/file-export.d.ts +3 -0
  321. package/dist/tools/handlers/file-export.js +90 -0
  322. package/dist/tools/handlers/local.d.ts +3 -0
  323. package/dist/tools/handlers/local.js +38 -0
  324. package/dist/tools/handlers/messenger.d.ts +16 -0
  325. package/dist/tools/handlers/messenger.js +188 -0
  326. package/dist/tools/handlers/onchain.d.ts +2 -0
  327. package/dist/tools/handlers/onchain.js +248 -0
  328. package/dist/tools/handlers/project.d.ts +2 -0
  329. package/dist/tools/handlers/project.js +293 -0
  330. package/dist/tools/handlers/query.d.ts +5 -0
  331. package/dist/tools/handlers/query.js +256 -0
  332. package/dist/tools/handlers/schema-query.d.ts +2 -0
  333. package/dist/tools/handlers/schema-query.js +93 -0
  334. package/dist/tools/handlers/trust.d.ts +2 -0
  335. package/dist/tools/handlers/trust.js +194 -0
  336. package/dist/tools/handlers/wip.d.ts +2 -0
  337. package/dist/tools/handlers/wip.js +44 -0
  338. package/dist/tools/index.d.ts +13 -0
  339. package/dist/tools/index.js +526 -0
  340. package/dist/tools/rules-hook.d.ts +2 -0
  341. package/dist/tools/rules-hook.js +23 -0
  342. package/dist/tools/shared.d.ts +20 -0
  343. package/dist/tools/shared.js +130 -0
  344. package/dist/tools/types.d.ts +35 -0
  345. package/dist/tools/types.js +1 -0
  346. package/dist/tools/wrap.d.ts +14 -0
  347. package/dist/tools/wrap.js +267 -0
  348. package/package.json +20 -6
@@ -0,0 +1,363 @@
1
+ import { USER_DEFINED_PERM_INDEX_START, MAX_ADMIN_COUNT, MAX_PERM_FOR_ENTITY, MAX_ENTITY_COUNT, } from "@wowok/wowok";
2
+ import { findSceneById, findSceneByPermissionIndex, inferSceneFromIntent, getActiveBuiltinPermissions, getReservedBuiltinPermissions, } from "./treasury-ledger.js";
3
+ import { getTemplatesByScene, } from "./treasury-templates.js";
4
+ import { matchSemanticPattern, } from "./treasury-translation.js";
5
+ import { getAllTreasuryRiskRules, assessTreasuryRisks, } from "./treasury-risk.js";
6
+ import { initPuzzleFromIntent, checkPuzzleCompleteness, MAX_EXTERNAL_DEPOSIT_GUARD_COUNT, MAX_EXTERNAL_WITHDRAW_GUARD_COUNT, MAX_DESCRIPTION_LENGTH, } from "./treasury-puzzle.js";
7
+ import { TREASURY_PUBLISH_CHECKLIST, TREASURY_CONFIRMATION_QUESTIONS, } from "./treasury-confirm.js";
8
+ export const TREASURY_CONTEXT_VERSION = "1.0.0";
9
+ export function buildTreasuryContext(input) {
10
+ const max_length = input.max_length ?? 4000;
11
+ let matched_scene;
12
+ if (input.intent) {
13
+ matched_scene = inferSceneFromIntent(input.intent);
14
+ }
15
+ else if (input.target_permission_index !== undefined) {
16
+ matched_scene = findSceneByPermissionIndex(input.target_permission_index);
17
+ }
18
+ if (!matched_scene && input.intent) {
19
+ matched_scene = findSceneById("treasury_fund_collection");
20
+ }
21
+ let matched_template;
22
+ if (matched_scene) {
23
+ const templates = getTemplatesByScene(matched_scene.id);
24
+ if (templates.length > 0)
25
+ matched_template = templates[0];
26
+ }
27
+ let matched_pattern;
28
+ if (input.intent) {
29
+ const patterns = matchSemanticPattern(input.intent);
30
+ if (patterns.length > 0)
31
+ matched_pattern = patterns[0];
32
+ }
33
+ let puzzle_state;
34
+ let puzzle_completeness;
35
+ if (input.mode === "initial_design" && input.intent) {
36
+ puzzle_state = initPuzzleFromIntent({ rule_sentence: input.intent });
37
+ puzzle_completeness = checkPuzzleCompleteness(puzzle_state);
38
+ }
39
+ const relevant_risks = filterRiskRules(input.mode, input.stakeholder, matched_scene);
40
+ let risk_assessment;
41
+ if ((input.mode === "pre_publish" || input.mode === "mid_design_review") && input.treasury_json) {
42
+ const ctx = {
43
+ object: typeof input.treasury_json.object === "string" ? input.treasury_json.object : null,
44
+ description: input.treasury_json.description,
45
+ deposit: input.treasury_json.deposit ? {
46
+ coin_balance: input.treasury_json.deposit.coin?.balance,
47
+ coin_object: input.treasury_json.deposit.coin?.coin_object,
48
+ by_external_deposit_guard: input.treasury_json.deposit.by_external_deposit_guard,
49
+ } : undefined,
50
+ withdraw: input.treasury_json.withdraw ? {
51
+ amount_fixed: input.treasury_json.withdraw.amount?.fixed,
52
+ amount_by_external_withdraw_guard: input.treasury_json.withdraw.amount?.by_external_withdraw_guard,
53
+ recipient: input.treasury_json.withdraw.recipient,
54
+ } : undefined,
55
+ external_deposit_guard: input.treasury_json.external_deposit_guard,
56
+ external_withdraw_guard: input.treasury_json.external_withdraw_guard,
57
+ owner_receive: input.treasury_json.owner_receive,
58
+ um: input.treasury_json.um,
59
+ type_parameter: input.type_parameter,
60
+ shared_with_service: input.shared_with_service,
61
+ shared_with_allocator: input.shared_with_allocator,
62
+ shared_with_arbitration: input.shared_with_arbitration,
63
+ current_permission_indexes_granted: input.current_permission_indexes_granted,
64
+ };
65
+ risk_assessment = assessTreasuryRisks(ctx);
66
+ }
67
+ const relevant_checklist = filterChecklist(input.mode);
68
+ const relevant_questions = filterQuestions(input.mode);
69
+ const relevant_builtin_permissions = matched_scene
70
+ ? matched_scene.builtin_indexes.filter(p => p.active)
71
+ : getActiveBuiltinPermissions();
72
+ const reserved_builtin_permissions = getReservedBuiltinPermissions();
73
+ const cross_object_refs = buildCrossObjectRefs(input.mode, matched_scene);
74
+ const onchain_constraints = buildOnchainConstraints();
75
+ const rendering_hints = buildRenderingHints(input.mode, max_length, !!input.treasury_json?.withdraw, !!input.treasury_json?.external_deposit_guard || !!input.treasury_json?.external_withdraw_guard, !!input.shared_with_service || !!input.shared_with_allocator || !!input.shared_with_arbitration);
76
+ return {
77
+ version: TREASURY_CONTEXT_VERSION,
78
+ mode: input.mode,
79
+ stakeholder_perspective: input.stakeholder,
80
+ matched_scene,
81
+ matched_template,
82
+ matched_pattern,
83
+ puzzle_state,
84
+ puzzle_completeness,
85
+ relevant_risks,
86
+ risk_assessment,
87
+ relevant_checklist,
88
+ relevant_questions,
89
+ relevant_builtin_permissions,
90
+ reserved_builtin_permissions,
91
+ cross_object_refs,
92
+ onchain_constraints,
93
+ rendering_hints,
94
+ };
95
+ }
96
+ function filterRiskRules(mode, stakeholder, scene) {
97
+ let rules = getAllTreasuryRiskRules();
98
+ if (mode === "initial_design") {
99
+ return rules.filter(r => r.category === "structural" || r.category === "authority");
100
+ }
101
+ if (mode === "pre_publish") {
102
+ return rules;
103
+ }
104
+ if (mode === "stakeholder_review" && stakeholder) {
105
+ if (stakeholder === "owner") {
106
+ return rules.filter(r => r.category === "authority" || r.category === "lifecycle");
107
+ }
108
+ if (stakeholder === "admin") {
109
+ return rules.filter(r => r.category === "structural" || r.category === "semantic");
110
+ }
111
+ if (stakeholder === "depositor") {
112
+ return rules.filter(r => r.id === "R-T-2-02" || r.id === "R-T-2-03" || r.category === "structural");
113
+ }
114
+ if (stakeholder === "withdrawer") {
115
+ return rules.filter(r => r.id === "R-T-4-01" || r.id === "R-T-4-02" || r.id === "R-T-3-01");
116
+ }
117
+ if (stakeholder === "external_operator") {
118
+ return rules.filter(r => r.id === "R-T-2-01" || r.id === "R-T-2-03" || r.id === "R-T-4-02");
119
+ }
120
+ if (stakeholder === "system") {
121
+ return rules.filter(r => r.category === "cross_object" || r.id === "R-T-0-01");
122
+ }
123
+ }
124
+ if (mode === "cross_object_check") {
125
+ return rules.filter(r => r.category === "cross_object");
126
+ }
127
+ return rules;
128
+ }
129
+ function filterChecklist(mode) {
130
+ if (mode === "initial_design") {
131
+ return TREASURY_PUBLISH_CHECKLIST.filter(i => ["C-T-01", "C-T-02", "C-T-03", "C-T-10"].includes(i.id));
132
+ }
133
+ return TREASURY_PUBLISH_CHECKLIST;
134
+ }
135
+ function filterQuestions(mode) {
136
+ if (mode === "pre_publish") {
137
+ return TREASURY_CONFIRMATION_QUESTIONS;
138
+ }
139
+ if (mode === "post_publish_modify") {
140
+ return TREASURY_CONFIRMATION_QUESTIONS.filter(q => q.id !== "QT1");
141
+ }
142
+ return [];
143
+ }
144
+ function buildCrossObjectRefs(mode, scene) {
145
+ const refs = [];
146
+ refs.push({
147
+ object: "Permission",
148
+ field: "permission",
149
+ description: "All Treasury write operations (except external_deposit/withdraw) require Permission authorization via indexes 250-258",
150
+ collaboration_type: "dependency",
151
+ });
152
+ refs.push({
153
+ object: "Registrar",
154
+ field: "registrar",
155
+ description: "Tracks affiliation between Treasury, Permission, and UM (Contact) objects",
156
+ collaboration_type: "dependency",
157
+ });
158
+ refs.push({
159
+ object: "Clock",
160
+ field: "clock",
161
+ description: "Provides timestamp for Record entries in history ParentTable",
162
+ collaboration_type: "dependency",
163
+ });
164
+ if (scene?.id === "treasury_external_ops" || scene?.id === "treasury_guard_protection" || mode === "cross_object_check") {
165
+ refs.push({
166
+ object: "Guard",
167
+ field: "external_deposit_guard / external_withdraw_guard",
168
+ description: "Guard objects referenced by external_*_guard lists; provide programmable access rules for external deposit/withdraw",
169
+ collaboration_type: "dependency",
170
+ });
171
+ refs.push({
172
+ object: "Passport",
173
+ field: "passport",
174
+ description: "Required for every external_deposit / external_withdraw call; carries submission values verified by Guard",
175
+ collaboration_type: "dependency",
176
+ });
177
+ }
178
+ refs.push({
179
+ object: "Allocator",
180
+ field: "sharing.who=Entity",
181
+ description: "Allocator can reference Treasury address as fund split target; Treasury.receive (253) converts CoinWrapper to balance",
182
+ collaboration_type: "referenced_by",
183
+ });
184
+ refs.push({
185
+ object: "Arbitration",
186
+ field: "fees_transfer",
187
+ description: "Arbitration.fees_transfer sends Payment to Treasury address; Treasury.receive (253) required to intake",
188
+ collaboration_type: "referenced_by",
189
+ });
190
+ refs.push({
191
+ object: "Service",
192
+ field: "compensation_fund (parallel design)",
193
+ description: "Service.compensation_fund is a parallel design (NOT a Treasury object); both are Balance<T> containers but implementation-independent",
194
+ collaboration_type: "parallel_design",
195
+ });
196
+ refs.push({
197
+ object: "Contact",
198
+ field: "um",
199
+ description: "Optional UM (User Manager) Contact object; manages user-tier information via Registrar affiliation",
200
+ collaboration_type: "dependency",
201
+ });
202
+ refs.push({
203
+ object: "Payment",
204
+ field: "history ParentTable",
205
+ description: "Every deposit/withdraw/receive creates a Payment object; Payment address is the key in history ParentTable",
206
+ collaboration_type: "dependency",
207
+ });
208
+ refs.push({
209
+ object: "CoinWrapper",
210
+ field: "receive",
211
+ description: "CoinWrapper is the received form of coins; Treasury.receive (253) unwraps CoinWrapper to balance",
212
+ collaboration_type: "dependency",
213
+ });
214
+ return refs;
215
+ }
216
+ function buildOnchainConstraints() {
217
+ return [
218
+ { name: "MAX_EXTERNAL_DEPOSIT_GUARD_COUNT", value: MAX_EXTERNAL_DEPOSIT_GUARD_COUNT, description: "Maximum external_deposit_guard entries (Treasury-specific, not yet in onchain-constants.ts)" },
219
+ { name: "MAX_EXTERNAL_WITHDRAW_GUARD_COUNT", value: MAX_EXTERNAL_WITHDRAW_GUARD_COUNT, description: "Maximum external_withdraw_guard entries (Treasury-specific, not yet in onchain-constants.ts)" },
220
+ { name: "MAX_DESCRIPTION_LENGTH", value: MAX_DESCRIPTION_LENGTH, description: "Maximum description length (shared across all objects)" },
221
+ { name: "USER_DEFINED_PERM_INDEX_START", value: USER_DEFINED_PERM_INDEX_START, description: "Custom permission indexes must be >= this value" },
222
+ { name: "MAX_ENTITY_COUNT", value: MAX_ENTITY_COUNT, description: "Maximum entities per Permission (shared)" },
223
+ { name: "MAX_PERM_FOR_ENTITY", value: MAX_PERM_FOR_ENTITY, description: "Maximum permission indexes per entity (shared)" },
224
+ { name: "MAX_ADMIN_COUNT", value: MAX_ADMIN_COUNT, description: "Maximum admins per Permission (shared)" },
225
+ ];
226
+ }
227
+ function buildRenderingHints(mode, max_length, hasWithdraw, hasExternalGuard, hasCrossObject) {
228
+ return {
229
+ include_puzzle_template: mode === "initial_design",
230
+ include_risk_details: mode === "pre_publish" || mode === "stakeholder_review" || mode === "mid_design_review",
231
+ include_questions: mode === "pre_publish",
232
+ include_irreversibility_warning: hasWithdraw,
233
+ include_external_guard_warning: hasExternalGuard,
234
+ include_cross_object_warning: hasCrossObject || mode === "cross_object_check",
235
+ max_length,
236
+ };
237
+ }
238
+ export function buildPromptFromTreasuryContext(bundle) {
239
+ const lines = [];
240
+ const h = bundle.rendering_hints;
241
+ lines.push(`═══ Treasury Context (mode: ${bundle.mode}) ═══`);
242
+ lines.push("");
243
+ if (bundle.stakeholder_perspective) {
244
+ lines.push(`Stakeholder perspective: ${bundle.stakeholder_perspective}`);
245
+ lines.push("");
246
+ }
247
+ if (bundle.matched_scene) {
248
+ lines.push(`Scene: ${bundle.matched_scene.name}`);
249
+ lines.push(`Scene ID: ${bundle.matched_scene.id}`);
250
+ lines.push(`Permission range: ${bundle.matched_scene.permission_index_range}`);
251
+ lines.push("");
252
+ }
253
+ if (bundle.matched_template) {
254
+ lines.push(`Suggested template: ${bundle.matched_template.id} — ${bundle.matched_template.name}`);
255
+ lines.push("");
256
+ }
257
+ if (h.include_puzzle_template && bundle.puzzle_completeness) {
258
+ const c = bundle.puzzle_completeness;
259
+ lines.push("─ Puzzle Completeness ──────────────");
260
+ lines.push(`Complete: ${c.complete ? "YES" : "NO"}`);
261
+ if (c.missing.length > 0) {
262
+ lines.push(`Missing: ${c.missing.join(", ")}`);
263
+ }
264
+ lines.push(`Next: ${c.next_step}`);
265
+ lines.push("");
266
+ }
267
+ if (h.include_risk_details && bundle.relevant_risks.length > 0) {
268
+ lines.push(`─ Relevant Risk Rules (${bundle.relevant_risks.length}) ──────────────`);
269
+ for (const r of bundle.relevant_risks.slice(0, 8)) {
270
+ lines.push(` ${r.id} — ${r.trigger}`);
271
+ }
272
+ if (bundle.relevant_risks.length > 8) {
273
+ lines.push(` ... and ${bundle.relevant_risks.length - 8} more`);
274
+ }
275
+ lines.push("");
276
+ }
277
+ if (bundle.risk_assessment) {
278
+ lines.push("─ Risk Assessment ──────────────");
279
+ lines.push(`Overall: ${bundle.risk_assessment.overall_risk}`);
280
+ lines.push(`Detected: ${bundle.risk_assessment.risks.length} risk(s)`);
281
+ for (const r of bundle.risk_assessment.risks.slice(0, 5)) {
282
+ lines.push(` [${r.level}] ${r.id}: ${r.title}`);
283
+ }
284
+ lines.push("");
285
+ }
286
+ if (bundle.relevant_builtin_permissions.length > 0) {
287
+ lines.push(`─ Builtin Treasury Permissions (active: ${bundle.relevant_builtin_permissions.length}) ──────────────`);
288
+ for (const p of bundle.relevant_builtin_permissions) {
289
+ lines.push(` [${p.index}] ${p.name}: ${p.description}`);
290
+ }
291
+ lines.push("");
292
+ }
293
+ if (bundle.reserved_builtin_permissions.length > 0) {
294
+ lines.push(`─ Reserved (no Permission index) ──────────────`);
295
+ for (const p of bundle.reserved_builtin_permissions) {
296
+ lines.push(` ${p.name}: ${p.description}`);
297
+ }
298
+ lines.push("");
299
+ }
300
+ if (h.include_irreversibility_warning) {
301
+ lines.push("⚠️ WITHDRAW OPERATION DETECTED — IRREVERSIBLE");
302
+ lines.push(" - withdraw (fixed) and external_withdraw cannot be undone");
303
+ lines.push(" - verify recipient address twice");
304
+ lines.push(" - ensure balance sufficiency");
305
+ lines.push("");
306
+ }
307
+ if (h.include_external_guard_warning) {
308
+ lines.push("⚠️ EXTERNAL GUARD MANAGEMENT — Verify Guard table fields");
309
+ lines.push(" - identifier must be number-type (u8/u16/u32/u64/u128/u256)");
310
+ lines.push(" - store_from_id must be address-compatible");
311
+ lines.push(" - external_withdraw_guard.identifier is REQUIRED (u8, not Option)");
312
+ lines.push(" - external_deposit_guard.identifier is Option<u8> (None = no amount limit)");
313
+ lines.push("");
314
+ }
315
+ if (h.include_cross_object_warning) {
316
+ lines.push("⚠️ CROSS-OBJECT COLLABORATION — Verify consistency");
317
+ lines.push(" - If shared with Service: verify Permission indexes 250-258 (Treasury) and 300-320 (Service) align");
318
+ lines.push(" - If referenced by Allocator/Arbitration: TREASURY_RECEIVE (253) must be granted for CoinWrapper intake");
319
+ lines.push("");
320
+ }
321
+ if (bundle.cross_object_refs.length > 0) {
322
+ lines.push(`─ Cross-Object References (${bundle.cross_object_refs.length}) ──────────────`);
323
+ for (const ref of bundle.cross_object_refs.slice(0, 6)) {
324
+ lines.push(` [${ref.collaboration_type}] ${ref.object}.${ref.field}`);
325
+ lines.push(` ${ref.description}`);
326
+ }
327
+ if (bundle.cross_object_refs.length > 6) {
328
+ lines.push(` ... and ${bundle.cross_object_refs.length - 6} more`);
329
+ }
330
+ lines.push("");
331
+ }
332
+ if (bundle.onchain_constraints.length > 0) {
333
+ lines.push("─ On-chain Constraints ──────────────");
334
+ for (const c of bundle.onchain_constraints) {
335
+ lines.push(` ${c.name} = ${c.value} — ${c.description}`);
336
+ }
337
+ lines.push("");
338
+ }
339
+ if (h.include_questions && bundle.relevant_questions.length > 0) {
340
+ lines.push("─ Confirmation Questions ──────────────");
341
+ for (const q of bundle.relevant_questions) {
342
+ const marker = q.requires_explicit_yes ? " ⚠️" : "";
343
+ lines.push(` ${q.id}${marker}: ${q.question}`);
344
+ }
345
+ lines.push("");
346
+ }
347
+ return lines.join("\n");
348
+ }
349
+ export function getTreasuryContextSummary(bundle) {
350
+ const parts = [
351
+ `mode=${bundle.mode}`,
352
+ `scene=${bundle.matched_scene?.id ?? "none"}`,
353
+ `risks=${bundle.relevant_risks.length}`,
354
+ `permissions=${bundle.relevant_builtin_permissions.length}`,
355
+ ];
356
+ if (bundle.stakeholder_perspective)
357
+ parts.push(`stakeholder=${bundle.stakeholder_perspective}`);
358
+ if (bundle.risk_assessment)
359
+ parts.push(`overall_risk=${bundle.risk_assessment.overall_risk}`);
360
+ if (bundle.matched_template)
361
+ parts.push(`template=${bundle.matched_template.id}`);
362
+ return parts.join(", ");
363
+ }
@@ -0,0 +1,42 @@
1
+ export interface TreasuryScene {
2
+ id: string;
3
+ name: string;
4
+ coin_type_category: "generic" | "native_sui" | "wrapped" | "stablecoin";
5
+ permission_index_range: string;
6
+ builtin_indexes: BuiltinTreasuryPermissionEntry[];
7
+ owner_operations: string[];
8
+ admin_operations: string[];
9
+ permission_index_operations: string[];
10
+ external_operations: string[];
11
+ guard_list_mutable_after_publish: boolean;
12
+ common_patterns: string[];
13
+ irreversibility: {
14
+ deposit: "reversible" | "irreversible";
15
+ withdraw: "reversible" | "irreversible";
16
+ external_deposit: "reversible" | "irreversible";
17
+ external_withdraw: "reversible" | "irreversible";
18
+ owner_receive: "reversible" | "irreversible";
19
+ };
20
+ cross_object_collaboration: string[];
21
+ recommended_templates: string[];
22
+ }
23
+ export interface BuiltinTreasuryPermissionEntry {
24
+ index: number;
25
+ name: string;
26
+ description: string;
27
+ governed_operation: string;
28
+ active: boolean;
29
+ }
30
+ export declare const TREASURY_PERMISSIONS: BuiltinTreasuryPermissionEntry[];
31
+ export declare const TREASURY_SCENES: TreasuryScene[];
32
+ export declare const TREASURY_LEDGER_VERSION = "1.0.0";
33
+ export declare function getScenesByHostObject(_host: "Treasury"): TreasuryScene[];
34
+ export declare function findSceneById(id: string): TreasuryScene | undefined;
35
+ export declare function findSceneByPermissionIndex(index: number): TreasuryScene | undefined;
36
+ export declare function getBuiltinPermissionByIndex(index: number): BuiltinTreasuryPermissionEntry | undefined;
37
+ export declare function isBuiltinTreasuryPermission(index: number): boolean;
38
+ export declare function getActiveBuiltinPermissions(): BuiltinTreasuryPermissionEntry[];
39
+ export declare function getReservedBuiltinPermissions(): BuiltinTreasuryPermissionEntry[];
40
+ export declare function inferSceneFromIntent(intent: string): TreasuryScene | undefined;
41
+ export declare function getTreasuryScenesCount(): number;
42
+ export declare function getMoveFunctionsForPermissionIndex(index: number): string[];