@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,433 @@
1
+ import { MAX_VOTING_GUARD_COUNT, } from "@wowok/wowok";
2
+ import { isTerminalArbStatus, isValidArbStatusTransition, } from "./arbitration-ledger.js";
3
+ const R_AB_1_01 = {
4
+ id: "R-AB-1-01",
5
+ category: "structural",
6
+ trigger: "voting_guard count exceeds MAX_VOTING_GUARD_COUNT (50)",
7
+ check: (ctx) => {
8
+ if (!ctx.voting_guard)
9
+ return null;
10
+ if (ctx.voting_guard.op === "add" || ctx.voting_guard.op === "set") {
11
+ const newCount = ctx.voting_guard.op === "set"
12
+ ? ctx.voting_guard.guards.length
13
+ : (ctx.current_voting_guard_count ?? 0) + ctx.voting_guard.guards.length;
14
+ if (newCount > MAX_VOTING_GUARD_COUNT) {
15
+ return {
16
+ id: "R-AB-1-01",
17
+ level: "HIGH",
18
+ category: "structural",
19
+ title: "voting_guard count exceeds limit",
20
+ description: `voting_guard would have ${newCount} entries, exceeds MAX_VOTING_GUARD_COUNT ${MAX_VOTING_GUARD_COUNT}`,
21
+ affected_stakeholders: ["owner", "arbiter"],
22
+ scenario: "Adding too many voting guards",
23
+ mitigation: `Remove unused guards before adding new ones; max ${MAX_VOTING_GUARD_COUNT}`,
24
+ evidence: `count=${newCount}`,
25
+ };
26
+ }
27
+ }
28
+ return null;
29
+ },
30
+ };
31
+ const R_AB_1_02 = {
32
+ id: "R-AB-1-02",
33
+ category: "structural",
34
+ trigger: "Dispute fee below arbitration.fee threshold",
35
+ check: (ctx) => {
36
+ if (!ctx.dispute || ctx.current_arbitration_fee === undefined)
37
+ return null;
38
+ const feeRequired = typeof ctx.current_arbitration_fee === "string"
39
+ ? BigInt(ctx.current_arbitration_fee)
40
+ : BigInt(ctx.current_arbitration_fee);
41
+ const feeProvided = typeof ctx.dispute.fee === "object" && ctx.dispute.fee !== null && "balance" in ctx.dispute.fee
42
+ ? BigInt(ctx.dispute.fee.balance ?? 0)
43
+ : BigInt(0);
44
+ if (feeProvided < feeRequired) {
45
+ return {
46
+ id: "R-AB-1-02",
47
+ level: "CRITICAL",
48
+ category: "structural",
49
+ title: "Dispute fee insufficient (E_FEE_NOT_ENOUGH)",
50
+ description: `Provided fee ${feeProvided.toString()} < required ${feeRequired.toString()}`,
51
+ affected_stakeholders: ["disputant"],
52
+ scenario: "Filing dispute with insufficient fee",
53
+ mitigation: `Increase dispute.fee.balance to >= ${feeRequired.toString()}`,
54
+ evidence: `provided=${feeProvided.toString()}, required=${feeRequired.toString()}`,
55
+ };
56
+ }
57
+ return null;
58
+ },
59
+ };
60
+ const R_AB_1_03 = {
61
+ id: "R-AB-1-03",
62
+ category: "structural",
63
+ trigger: "Arbitration paused (bPaused=true) — dispute will fail with E_PAUSED",
64
+ check: (ctx) => {
65
+ if (ctx.dispute && ctx.current_bPaused === true) {
66
+ return {
67
+ id: "R-AB-1-03",
68
+ level: "HIGH",
69
+ category: "structural",
70
+ title: "Arbitration paused — cannot file dispute",
71
+ description: "Arbitration.bPaused=true; dispute() will abort with E_PAUSED",
72
+ affected_stakeholders: ["disputant"],
73
+ scenario: "Filing dispute against a paused Arbitration",
74
+ mitigation: "Call pause(false) (requires ARBITRATION_PAUSE=356) to resume",
75
+ evidence: `bPaused=true`,
76
+ };
77
+ }
78
+ return null;
79
+ },
80
+ };
81
+ const R_AB_1_04 = {
82
+ id: "R-AB-1-04",
83
+ category: "structural",
84
+ trigger: "voting_deadline in the past — vote will be rejected",
85
+ check: (ctx) => {
86
+ const deadline = ctx.confirm?.voting_deadline ?? ctx.voting_deadline_change?.voting_deadline;
87
+ if (deadline !== undefined && deadline !== null && ctx.current_timestamp_ms !== undefined) {
88
+ if (deadline < ctx.current_timestamp_ms) {
89
+ return {
90
+ id: "R-AB-1-04",
91
+ level: "HIGH",
92
+ category: "structural",
93
+ title: "voting_deadline in the past",
94
+ description: `Deadline ${deadline} is before current time ${ctx.current_timestamp_ms}`,
95
+ affected_stakeholders: ["voter", "arbiter"],
96
+ scenario: "Setting voting deadline to an already-elapsed timestamp",
97
+ mitigation: "Use a future timestamp (e.g. now + 7 days in ms)",
98
+ evidence: `deadline=${deadline}, now=${ctx.current_timestamp_ms}`,
99
+ };
100
+ }
101
+ }
102
+ return null;
103
+ },
104
+ };
105
+ const R_AB_2_01 = {
106
+ id: "R-AB-2-01",
107
+ category: "semantic",
108
+ trigger: "voting_guard misconfiguration — dispute cannot be resolved",
109
+ check: (ctx) => {
110
+ if (ctx.vote && ctx.vote.voting_guard) {
111
+ if (!ctx.current_voting_guard_addresses || ctx.current_voting_guard_addresses.length === 0) {
112
+ return {
113
+ id: "R-AB-2-01",
114
+ level: "HIGH",
115
+ category: "semantic",
116
+ title: "voting_guard misconfiguration — dispute cannot be resolved",
117
+ description: "vote.voting_guard provided but Arbitration.voting_guard is empty; E_VOTING_GUARD_NOT_FOUND will abort",
118
+ affected_stakeholders: ["voter", "arbiter", "disputant"],
119
+ scenario: "voting_guard misconfiguration prevents vote — dispute stuck",
120
+ mitigation: "Either add the Guard to voting_guard list (354) or use open vote() without voting_guard",
121
+ evidence: `vote.voting_guard=${ctx.vote.voting_guard}`,
122
+ };
123
+ }
124
+ if (!ctx.current_voting_guard_addresses.includes(ctx.vote.voting_guard)) {
125
+ return {
126
+ id: "R-AB-2-01",
127
+ level: "HIGH",
128
+ category: "semantic",
129
+ title: "voting_guard misconfiguration — dispute cannot be resolved",
130
+ description: `vote.voting_guard ${ctx.vote.voting_guard} not in Arbitration.voting_guard list`,
131
+ affected_stakeholders: ["voter", "arbiter", "disputant"],
132
+ scenario: "Voter's Guard not registered — vote will fail with E_VOTING_GUARD_NOT_FOUND",
133
+ mitigation: `Add guard ${ctx.vote.voting_guard} via voting_guard_add (354), or use a registered guard`,
134
+ evidence: `provided=${ctx.vote.voting_guard}, registered=${ctx.current_voting_guard_addresses.join(",")}`,
135
+ };
136
+ }
137
+ }
138
+ return null;
139
+ },
140
+ };
141
+ const R_AB_2_02 = {
142
+ id: "R-AB-2-02",
143
+ category: "semantic",
144
+ trigger: "usage_guard set but dispute without passport — E_NEED_PASSPORT",
145
+ check: (ctx) => {
146
+ if (ctx.dispute && ctx.current_voting_guard_addresses !== undefined) {
147
+ }
148
+ return null;
149
+ },
150
+ };
151
+ const R_AB_2_03 = {
152
+ id: "R-AB-2-03",
153
+ category: "semantic",
154
+ trigger: "VoteValue.GuardIdentifier with non-numeric Guard submission type",
155
+ check: (ctx) => {
156
+ if (ctx.voting_guard && (ctx.voting_guard.op === "add" || ctx.voting_guard.op === "set")) {
157
+ for (const g of ctx.voting_guard.guards) {
158
+ const vw = g.vote_weight;
159
+ if ("GuardIdentifier" in vw && vw.GuardIdentifier !== undefined) {
160
+ if (vw.GuardIdentifier > 255) {
161
+ return {
162
+ id: "R-AB-2-03",
163
+ level: "HIGH",
164
+ category: "semantic",
165
+ title: "GuardIdentifier index > u8::max (255)",
166
+ description: `GuardIdentifier ${vw.GuardIdentifier} exceeds u8 max (255)`,
167
+ affected_stakeholders: ["owner"],
168
+ scenario: "Setting GuardIdentifier index beyond u8 range",
169
+ mitigation: "Use GuardIdentifier index 0-255",
170
+ evidence: `identifier=${vw.GuardIdentifier}`,
171
+ };
172
+ }
173
+ }
174
+ if ("FixedValue" in vw && vw.FixedValue !== undefined) {
175
+ if (vw.FixedValue > 4294967295) {
176
+ return {
177
+ id: "R-AB-2-03",
178
+ level: "HIGH",
179
+ category: "semantic",
180
+ title: "FixedValue > u32::max (4294967295)",
181
+ description: `FixedValue ${vw.FixedValue} exceeds u32 max`,
182
+ affected_stakeholders: ["owner"],
183
+ scenario: "Setting FixedValue beyond u32 range",
184
+ mitigation: "Use FixedValue 0-4294967295",
185
+ evidence: `fixed=${vw.FixedValue}`,
186
+ };
187
+ }
188
+ }
189
+ }
190
+ }
191
+ return null;
192
+ },
193
+ };
194
+ const R_AB_3_01 = {
195
+ id: "R-AB-3-01",
196
+ category: "authority",
197
+ trigger: "Arbiter collusion — single voter controls >50% of total weight",
198
+ check: (ctx) => {
199
+ if (!ctx.voting_guard || ctx.voting_guard.op !== "add" && ctx.voting_guard.op !== "set")
200
+ return null;
201
+ const guards = ctx.voting_guard.guards;
202
+ if (guards.length < 2)
203
+ return null;
204
+ const fixedWeights = guards
205
+ .filter(g => "FixedValue" in g.vote_weight && g.vote_weight.FixedValue !== undefined)
206
+ .map(g => g.vote_weight.FixedValue);
207
+ if (fixedWeights.length === 0)
208
+ return null;
209
+ const total = fixedWeights.reduce((a, b) => a + b, 0);
210
+ const max = Math.max(...fixedWeights);
211
+ if (total > 0 && max / total > 0.5) {
212
+ return {
213
+ id: "R-AB-3-01",
214
+ level: "MEDIUM",
215
+ category: "authority",
216
+ title: "Arbiter collusion risk — single guard controls >50% weight",
217
+ description: `One voting_guard has ${max} of ${total} total weight (${((max / total) * 100).toFixed(1)}%)`,
218
+ affected_stakeholders: ["owner", "disputant"],
219
+ scenario: "Weighted voting with dominant arbiter — can single-handedly decide rulings",
220
+ mitigation: "Distribute weight more evenly, or require multi-arbiter consensus",
221
+ evidence: `max=${max}, total=${total}, ratio=${((max / total) * 100).toFixed(1)}%`,
222
+ };
223
+ }
224
+ return null;
225
+ },
226
+ };
227
+ const R_AB_3_02 = {
228
+ id: "R-AB-3-02",
229
+ category: "authority",
230
+ trigger: "Permission over-concentration — single admin (owner)",
231
+ check: (ctx) => {
232
+ if (ctx.builder) {
233
+ return {
234
+ id: "R-AB-3-02",
235
+ level: "HIGH",
236
+ category: "authority",
237
+ title: "Arbitration ownership transfer — IRREVERSIBLE",
238
+ description: `Transferring Arbitration to ${ctx.builder}; original owner loses all control permanently`,
239
+ affected_stakeholders: ["owner"],
240
+ scenario: "Transferring Arbitration ownership",
241
+ mitigation: "1) Verify new owner twice. 2) Confirm new owner has 350-368 permissions configured. 3) Coordinate before transfer.",
242
+ evidence: `new_owner=${ctx.builder}`,
243
+ };
244
+ }
245
+ return null;
246
+ },
247
+ };
248
+ const R_AB_3_03 = {
249
+ id: "R-AB-3-03",
250
+ category: "authority",
251
+ trigger: "ARBITRATION_ARBITRATION (359) granted to wide audience",
252
+ check: (ctx) => {
253
+ if (ctx.arbitration && !ctx.current_voting_guard_addresses?.length) {
254
+ return {
255
+ id: "R-AB-3-03",
256
+ level: "MEDIUM",
257
+ category: "authority",
258
+ title: "Ruling without voting_guard — single-arbiter can rule unchallenged",
259
+ description: "make_ruling (359) without voting_guard means any permission holder can unilaterally decide",
260
+ affected_stakeholders: ["disputant", "voter"],
261
+ scenario: "Single-arbiter Arbitration without consensus check",
262
+ mitigation: "Configure voting_guard (354) to require multi-arbiter consensus before ruling",
263
+ evidence: `voting_guard=empty`,
264
+ };
265
+ }
266
+ return null;
267
+ },
268
+ };
269
+ const R_AB_4_01 = {
270
+ id: "R-AB-4-01",
271
+ category: "lifecycle",
272
+ trigger: "Invalid Arb status transition (7-state flow violation)",
273
+ check: (ctx) => {
274
+ if (!ctx.current_arb_status || !ctx.expected_arb_status)
275
+ return null;
276
+ if (ctx.current_arb_status === ctx.expected_arb_status)
277
+ return null;
278
+ if (!isValidArbStatusTransition(ctx.current_arb_status, ctx.expected_arb_status)) {
279
+ return {
280
+ id: "R-AB-4-01",
281
+ level: "CRITICAL",
282
+ category: "lifecycle",
283
+ title: "Invalid Arb status transition",
284
+ description: `${ctx.current_arb_status} → ${ctx.expected_arb_status} is not a valid 7-state flow transition`,
285
+ affected_stakeholders: ["arbiter", "disputant"],
286
+ scenario: "Attempting operation out of order (e.g. vote before confirm)",
287
+ mitigation: "Follow the 7-state flow: Principal_confirming → Arbitrator_confirming → Voting → Arbitrated → Objectionable → Finished/Withdrawn",
288
+ evidence: `${ctx.current_arb_status} → ${ctx.expected_arb_status}`,
289
+ };
290
+ }
291
+ return null;
292
+ },
293
+ };
294
+ const R_AB_4_02 = {
295
+ id: "R-AB-4-02",
296
+ category: "lifecycle",
297
+ trigger: "Operation on terminal Arb status (Finished/Withdrawn)",
298
+ check: (ctx) => {
299
+ if (!ctx.current_arb_status)
300
+ return null;
301
+ if (isTerminalArbStatus(ctx.current_arb_status)) {
302
+ const allowedOpOnTerminal = ctx.arb_withdraw;
303
+ if (!allowedOpOnTerminal && (ctx.vote || ctx.confirm || ctx.arbitration || ctx.reset || ctx.feedback)) {
304
+ return {
305
+ id: "R-AB-4-02",
306
+ level: "HIGH",
307
+ category: "lifecycle",
308
+ title: "Operation on terminal Arb status — irreversible",
309
+ description: `Arb is in terminal status ${ctx.current_arb_status}; only arb_withdraw is allowed`,
310
+ affected_stakeholders: ["arbiter", "disputant"],
311
+ scenario: "Voting/ruling/reset on a Finished or Withdrawn Arb",
312
+ mitigation: "Open a new Arb case via dispute() if further arbitration is needed",
313
+ evidence: `status=${ctx.current_arb_status}`,
314
+ };
315
+ }
316
+ }
317
+ return null;
318
+ },
319
+ };
320
+ const R_AB_4_03 = {
321
+ id: "R-AB-4-03",
322
+ category: "lifecycle",
323
+ trigger: "reset operation — may indefinitely extend arbitration",
324
+ check: (ctx) => {
325
+ if (!ctx.reset)
326
+ return null;
327
+ return {
328
+ id: "R-AB-4-03",
329
+ level: "MEDIUM",
330
+ category: "lifecycle",
331
+ title: "reset operation — arbitration lifecycle extended",
332
+ description: `reset on Arb ${ctx.reset.arb} restarts lifecycle to Principal_confirming; feedback required`,
333
+ affected_stakeholders: ["arbiter", "disputant"],
334
+ scenario: "Disputant objects to ruling and resubmits materials",
335
+ mitigation: "Track reset count — consider capping resets to prevent abuse",
336
+ evidence: `arb=${ctx.reset.arb}`,
337
+ };
338
+ },
339
+ };
340
+ const R_AB_5_01 = {
341
+ id: "R-AB-5-01",
342
+ category: "cross_object",
343
+ trigger: "fees_alloc/fees_transfer unfair distribution — destination not verified",
344
+ check: (ctx) => {
345
+ if (!ctx.fees_transfer)
346
+ return null;
347
+ const dest = "allocation" in ctx.fees_transfer.to
348
+ ? `Allocation ${ctx.fees_transfer.to.allocation}`
349
+ : `Treasury ${ctx.fees_transfer.to.treasury}`;
350
+ return {
351
+ id: "R-AB-5-01",
352
+ level: "MEDIUM",
353
+ category: "cross_object",
354
+ title: "fees_alloc/fees_transfer — verify destination fairness",
355
+ description: `All Arbitration.balance will be transferred to ${dest}; ensure destination policy is fair to arbiters`,
356
+ affected_stakeholders: ["arbiter", "owner"],
357
+ scenario: "Distributing arbitration fees without verifying allocation rules",
358
+ mitigation: `Verify ${dest} has fair distribution policy; consider allocating to arbiters' Allocation`,
359
+ evidence: `dest=${dest}, remark=${ctx.fees_transfer.payment_remark}`,
360
+ };
361
+ },
362
+ };
363
+ const R_AB_5_02 = {
364
+ id: "R-AB-5-02",
365
+ category: "cross_object",
366
+ trigger: "Dispute filed but Order op permission not verified — E_OP_PERMISSION",
367
+ check: (ctx) => {
368
+ if (!ctx.dispute)
369
+ return null;
370
+ return {
371
+ id: "R-AB-5-02",
372
+ level: "HIGH",
373
+ category: "cross_object",
374
+ title: "Order op permission required for dispute",
375
+ description: `dispute on Order ${ctx.dispute.order} requires order::assert_op_permission; signer must have Order's dispute permission`,
376
+ affected_stakeholders: ["disputant"],
377
+ scenario: "Filing dispute without Order op permission",
378
+ mitigation: "Ensure signer has Order's dispute operation permission (custom index or builtin)",
379
+ evidence: `order=${ctx.dispute.order}`,
380
+ };
381
+ },
382
+ };
383
+ const ALL_RULES = [
384
+ R_AB_1_01, R_AB_1_02, R_AB_1_03, R_AB_1_04,
385
+ R_AB_2_01, R_AB_2_02, R_AB_2_03,
386
+ R_AB_3_01, R_AB_3_02, R_AB_3_03,
387
+ R_AB_4_01, R_AB_4_02, R_AB_4_03,
388
+ R_AB_5_01, R_AB_5_02,
389
+ ];
390
+ export const ARBITRATION_RISK_VERSION = "1.0.0";
391
+ export function getAllRiskRules() {
392
+ return [...ALL_RULES];
393
+ }
394
+ export function getRiskRulesCount() {
395
+ return ALL_RULES.length;
396
+ }
397
+ export function getRiskRulesByCategory(category) {
398
+ return ALL_RULES.filter(r => r.category === category);
399
+ }
400
+ export function assessArbitrationRisks(ctx) {
401
+ const risks = [];
402
+ for (const rule of ALL_RULES) {
403
+ const r = rule.check(ctx);
404
+ if (r)
405
+ risks.push(r);
406
+ }
407
+ const overall = risks.length === 0
408
+ ? "LOW"
409
+ : risks.some(r => r.level === "CRITICAL") ? "CRITICAL"
410
+ : risks.some(r => r.level === "HIGH") ? "HIGH"
411
+ : risks.some(r => r.level === "MEDIUM") ? "MEDIUM"
412
+ : "LOW";
413
+ const byCategory = {};
414
+ for (const r of risks) {
415
+ byCategory[r.category] = (byCategory[r.category] ?? 0) + 1;
416
+ }
417
+ const advice = {};
418
+ for (const r of risks) {
419
+ for (const s of r.affected_stakeholders) {
420
+ if (!advice[s])
421
+ advice[s] = [];
422
+ advice[s].push(`${r.id}: ${r.mitigation}`);
423
+ }
424
+ }
425
+ return {
426
+ summary: `Assessed ${risks.length} risk(s) across ${Object.keys(byCategory).length} categories`,
427
+ risks,
428
+ overall_risk: overall,
429
+ risks_by_category: byCategory,
430
+ stakeholder_advice: advice,
431
+ needs_human_review: risks.some(r => r.level === "CRITICAL" || r.level === "HIGH"),
432
+ };
433
+ }
@@ -0,0 +1,38 @@
1
+ export type TemplateParamType = "address" | "string" | "number" | "string[]" | "object";
2
+ export interface ArbitrationTemplateParam {
3
+ name: string;
4
+ type: TemplateParamType;
5
+ description: string;
6
+ required: boolean;
7
+ default?: string | number | string[] | object;
8
+ }
9
+ export interface ArbitrationTemplate {
10
+ id: string;
11
+ name: string;
12
+ description: string;
13
+ applicable_scenes: string[];
14
+ industry_tags: string[];
15
+ params: ArbitrationTemplateParam[];
16
+ body: (params: Record<string, string | number | string[] | object>) => object;
17
+ notes?: string[];
18
+ }
19
+ export declare const ARBITRATION_TEMPLATES: ArbitrationTemplate[];
20
+ export declare const ARBITRATION_TEMPLATES_VERSION = "1.0.0";
21
+ export declare function getAllTemplates(): ArbitrationTemplate[];
22
+ export declare function getTemplateById(id: string): ArbitrationTemplate | undefined;
23
+ export declare function getTemplatesByScene(sceneId: string): ArbitrationTemplate[];
24
+ export declare function getTemplatesByIndustry(industry: string): ArbitrationTemplate[];
25
+ export declare function suggestTemplateForScene(sceneId: string): ArbitrationTemplate | undefined;
26
+ export declare function listTemplates(): {
27
+ id: string;
28
+ name: string;
29
+ description: string;
30
+ scenes: string[];
31
+ }[];
32
+ export declare function fillTemplate(templateId: string, params: Record<string, string | number | string[] | object>): {
33
+ ok: true;
34
+ body: object;
35
+ } | {
36
+ ok: false;
37
+ error: string;
38
+ };