@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,644 @@
1
+ import { USER_DEFINED_PERM_INDEX_START, MAX_NODE_COUNT } from "./onchain-constants.js";
2
+ export const MACHINE_RISK_RULES = [
3
+ {
4
+ id: "R-M1-01",
5
+ name: "No entry point",
6
+ category: "structural",
7
+ severity: "critical",
8
+ description: "Machine has no Pair with prev_node='' (no entry point). Workflow cannot start.",
9
+ detection: "Check if any pair has prev_node === ''",
10
+ recommendation: "Add at least one Pair with prev_node='' to serve as entry point.",
11
+ auto_fixable: false,
12
+ related_constraint: "MC-S-01",
13
+ },
14
+ {
15
+ id: "R-M1-02",
16
+ name: "No terminal node",
17
+ category: "structural",
18
+ severity: "critical",
19
+ description: "Machine has no terminal node (all nodes have outgoing Pairs). Workflow never completes.",
20
+ detection: "Check if any node has no outgoing Pair",
21
+ recommendation: "Designate at least one node as terminal (no outgoing Pair) and bind Allocator to it.",
22
+ auto_fixable: false,
23
+ related_constraint: "MC-S-02",
24
+ },
25
+ {
26
+ id: "R-M1-03",
27
+ name: "Dead-end node (non-terminal)",
28
+ category: "structural",
29
+ severity: "medium",
30
+ description: "Non-terminal node has no outgoing Pair. Workflow stalls at this node.",
31
+ detection: "Find nodes with no outgoing Pair that are not intended terminals",
32
+ recommendation: "Add outgoing Pair or designate as terminal with Allocator.",
33
+ auto_fixable: false,
34
+ },
35
+ {
36
+ id: "R-M1-04",
37
+ name: "Orphaned node",
38
+ category: "structural",
39
+ severity: "high",
40
+ description: "Node has no incoming Pair (except entry). Unreachable.",
41
+ detection: "Find non-entry nodes with no incoming Pair",
42
+ recommendation: "Add Pair from existing node to this orphaned node, or remove it.",
43
+ auto_fixable: false,
44
+ related_constraint: "MC-S-03",
45
+ },
46
+ {
47
+ id: "R-M1-05",
48
+ name: "Dead branch (competing Pair always loses)",
49
+ category: "structural",
50
+ severity: "high",
51
+ description: "A competing Pair's threshold can never be met because users always prefer another path.",
52
+ detection: "Analyze threshold achievability across competing Pairs",
53
+ recommendation: "Make thresholds balanced, or remove the dead branch.",
54
+ auto_fixable: false,
55
+ related_constraint: "MC-S-04",
56
+ },
57
+ {
58
+ id: "R-M1-06",
59
+ name: "Cycle in DAG",
60
+ category: "structural",
61
+ severity: "critical",
62
+ description: "Workflow has a cycle. Nodes reference each other circularly.",
63
+ detection: "DFS cycle detection",
64
+ recommendation: "Break the cycle by removing one Pair.",
65
+ auto_fixable: false,
66
+ related_constraint: "MC-S-05",
67
+ },
68
+ {
69
+ id: "R-M1-07",
70
+ name: "Exceeds MAX_NODE_COUNT (100)",
71
+ category: "structural",
72
+ severity: "critical",
73
+ description: "Node count exceeds on-chain limit. Publish will fail.",
74
+ detection: `nodes.length > ${MAX_NODE_COUNT}`,
75
+ recommendation: "Reduce node count or split into multiple Machines.",
76
+ auto_fixable: false,
77
+ related_constraint: "MC-C-01",
78
+ },
79
+ {
80
+ id: "R-M1-08",
81
+ name: "Exceeds MAX_NODE_PAIR_COUNT (40)",
82
+ category: "structural",
83
+ severity: "high",
84
+ description: "A single node's Pairs exceed on-chain limit. Publish will fail.",
85
+ detection: "Find node where pairs.length > 40",
86
+ recommendation: "Split node or simplify branches to reduce Pair count per node.",
87
+ auto_fixable: false,
88
+ related_constraint: "MC-C-02",
89
+ },
90
+ {
91
+ id: "R-M1-09",
92
+ name: "Exceeds MAX_FORWARD_COUNT (20)",
93
+ category: "structural",
94
+ severity: "high",
95
+ description: "A single Pair's Forwards exceed on-chain limit. Publish will fail.",
96
+ detection: "Find Pair where forwards.length > 20",
97
+ recommendation: "Split Pair or merge Forwards to reduce Forward count per Pair.",
98
+ auto_fixable: false,
99
+ related_constraint: "MC-C-03",
100
+ },
101
+ {
102
+ id: "R-M1-10",
103
+ name: "Duplicate node name",
104
+ category: "structural",
105
+ severity: "critical",
106
+ description: "Two nodes have the same name. On-chain will reject.",
107
+ detection: "Find duplicate names in nodes array",
108
+ recommendation: "Rename one of the duplicates.",
109
+ auto_fixable: false,
110
+ related_constraint: "MC-C-04",
111
+ },
112
+ {
113
+ id: "R-M2-01",
114
+ name: "Guard not created",
115
+ category: "guard_integration",
116
+ severity: "critical",
117
+ description: "Forward references a Guard that is not yet created on-chain. Forward execution will fail Guard verification.",
118
+ detection: "Check forward.guard against published_guards set",
119
+ recommendation: "Create the Guard object before publishing this Machine.",
120
+ auto_fixable: false,
121
+ related_constraint: "MC-C-09",
122
+ },
123
+ {
124
+ id: "R-M2-02",
125
+ name: "Guard not tested via gen_passport",
126
+ category: "guard_integration",
127
+ severity: "high",
128
+ description: "Guard has not been tested via gen_passport. Guard may have bugs, cannot be fixed after publish.",
129
+ detection: "Check testnet test records for this Guard",
130
+ recommendation: "Run gen_passport on testnet before binding to Machine.",
131
+ auto_fixable: false,
132
+ },
133
+ {
134
+ id: "R-M2-03",
135
+ name: "Guard + Machine immutability deadlock",
136
+ category: "guard_integration",
137
+ severity: "critical",
138
+ description: "After Machine publish, a Guard bug is discovered. Guard is immutable (cannot be fixed), Machine is immutable (cannot be rebound).",
139
+ detection: "Verify all Guards tested before Machine publish",
140
+ recommendation: "Keep Machine unpublished until all Guards are verified.",
141
+ auto_fixable: false,
142
+ },
143
+ {
144
+ id: "R-M2-04",
145
+ name: "retained_submission index mismatch",
146
+ category: "guard_integration",
147
+ severity: "high",
148
+ description: "Forward's retained_submission key does not correspond to Guard table b_submission=true entry. Retained data fails or is incorrect.",
149
+ detection: "Cross-check forward.retained_submission against Guard table entries",
150
+ recommendation: "Align retained_submission key with Guard table b_submission=true identifier.",
151
+ auto_fixable: true,
152
+ related_constraint: "MC-C-11",
153
+ },
154
+ {
155
+ id: "R-M2-05",
156
+ name: "Guard reentry risk",
157
+ category: "guard_integration",
158
+ severity: "high",
159
+ description: "Guard lacks anti-reentry mechanism (see Guard R-X1-14). Risk of duplicate execution or vote manipulation.",
160
+ detection: "For each Guard scene, verify anti-reentry Guard is configured (see Guard semantic layer R-X1-14)",
161
+ recommendation: "Add anti-reentry Guard for each scenario (see Guard semantic layer R-X1-14).",
162
+ auto_fixable: false,
163
+ },
164
+ {
165
+ id: "R-M2-06",
166
+ name: "Guard scene mismatch",
167
+ category: "guard_integration",
168
+ severity: "medium",
169
+ description: "Forward's bound Guard scene does not match Forward's business (e.g., Forward uses reward_guard instead of machine_forward_guard).",
170
+ detection: "Cross-check Guard scene against Forward business purpose",
171
+ recommendation: "Use the correct Guard scene (machine_forward_guard).",
172
+ auto_fixable: false,
173
+ },
174
+ {
175
+ id: "R-M2-07",
176
+ name: "Cross-Machine Guard dependency cycle",
177
+ category: "guard_integration",
178
+ severity: "critical",
179
+ description: "Machine A depends on Machine B (via Guard), B depends on A. Circular dependency.",
180
+ detection: "Identify cross-Machine Guard references and detect cycles",
181
+ recommendation: "Ensure cross-Machine dependencies are unidirectional.",
182
+ auto_fixable: false,
183
+ },
184
+ {
185
+ id: "R-M2-08",
186
+ name: "Guard references unpublished object",
187
+ category: "guard_integration",
188
+ severity: "high",
189
+ description: "Guard table references an object (e.g., Service) that is not yet published.",
190
+ detection: "Cross-check Guard table object references against published objects set",
191
+ recommendation: "Use P16 circular reference pattern (name instead of address), or publish referenced objects first.",
192
+ auto_fixable: false,
193
+ },
194
+ {
195
+ id: "R-M3-01",
196
+ name: "Forward without permission",
197
+ category: "permission",
198
+ severity: "critical",
199
+ description: "Forward has neither namedOperator nor permissionIndex. Cannot be executed.",
200
+ detection: "Check each forward has at least one of namedOperator or permissionIndex",
201
+ recommendation: "Set namedOperator='' for OrderHolder, or set permissionIndex.",
202
+ auto_fixable: false,
203
+ related_constraint: "MC-C-07",
204
+ },
205
+ {
206
+ id: "R-M3-02",
207
+ name: "permissionIndex out of bounds",
208
+ category: "permission",
209
+ severity: "critical",
210
+ description: "Forward's permissionIndex >= Permission.indices.length. Execution will fail.",
211
+ detection: "Check permission_index < Permission.indices.length",
212
+ recommendation: "Use a valid permission index or extend Permission.indices.",
213
+ auto_fixable: false,
214
+ related_constraint: "MC-C-08",
215
+ },
216
+ {
217
+ id: "R-M3-03",
218
+ name: "Permission rotation failure",
219
+ category: "permission",
220
+ severity: "high",
221
+ description: "Permission object updated, indices order changed. Original permissionIndex now points to wrong permission.",
222
+ detection: "Detect Permission object update that reorders indices",
223
+ recommendation: "Use custom Permission; document index meanings; avoid frequent Permission updates.",
224
+ auto_fixable: false,
225
+ },
226
+ {
227
+ id: "R-M3-04",
228
+ name: "OrderHolder misuse",
229
+ category: "permission",
230
+ severity: "medium",
231
+ description: "namedOperator='' used in non-customer-operation scenarios. Non-intended personnel gain operation permission.",
232
+ detection: "Find Forwards with namedOperator='' on non-customer-operation nodes",
233
+ recommendation: "Clarify ''=OrderHolder (customer), not 'anyone'. Use namedOperator for specific roles.",
234
+ auto_fixable: false,
235
+ },
236
+ {
237
+ id: "R-M3-05",
238
+ name: "NamedOperator not assigned at Progress creation",
239
+ category: "permission",
240
+ severity: "high",
241
+ description: "Forward expects namedOperator role but Progress doesn't have it assigned. " +
242
+ "Note: MCP API layer supports progress_new.progress_namedOperator (SDK translates to namedOperator_add), " +
243
+ "but Move layer progress::new does NOT accept it (see 06 §14.5).",
244
+ detection: "Verify progress_namedOperator is provided in Progress creation",
245
+ recommendation: "Pass progress_namedOperator in progress_new, or call namedOperator_add separately.",
246
+ auto_fixable: false,
247
+ },
248
+ {
249
+ id: "R-M3-06",
250
+ name: "Permission game imbalance",
251
+ category: "permission",
252
+ severity: "medium",
253
+ description: "One party has excessive permission, can unilaterally advance workflow. Game theory imbalance.",
254
+ detection: "Analyze permission distribution across parties",
255
+ recommendation: "Use dual-signature (threshold=2) or multi-signature mechanism to balance power.",
256
+ auto_fixable: false,
257
+ },
258
+ {
259
+ id: "R-M3-07",
260
+ name: "Permission combination OR semantic misuse",
261
+ category: "permission",
262
+ severity: "medium",
263
+ description: "Both namedOperator and permissionIndex set, but OR semantic not understood. More people than expected can execute Forward.",
264
+ detection: "Find Forwards with both namedOperator and permissionIndex set",
265
+ recommendation: "Clarify that when both permissions are non-null, it is OR relation (either can execute).",
266
+ auto_fixable: false,
267
+ },
268
+ {
269
+ id: "R-M3-08",
270
+ name: "permissionIndex below USER_DEFINED_PERM_INDEX_START (1000)",
271
+ category: "permission",
272
+ severity: "critical",
273
+ description: "Forward's permissionIndex < 1000. On-chain constant USER_DEFINED_PERM_INDEX_START = 1000 " +
274
+ "in permission.move reserves indexes 0-999 for built-in permissions. Using index < 1000 " +
275
+ "causes confusion with built-in permissions and is a hard on-chain constraint (see doc 06 §4.4).",
276
+ detection: "Check each forward with permission_index < 1000",
277
+ recommendation: "Use permission_index >= 1000 (e.g., 1000, 1001, 1002, ...). Reserve 0-999 for built-in permissions.",
278
+ auto_fixable: false,
279
+ related_constraint: "MC-C-08",
280
+ },
281
+ {
282
+ id: "R-M4-01",
283
+ name: "No backup before publish",
284
+ category: "immutability",
285
+ severity: "high",
286
+ description: "machineNode2file export not created before publish. Cannot restore if publish fails.",
287
+ detection: "Check backup_created flag",
288
+ recommendation: "Run machineNode2file before publish to create backup.",
289
+ auto_fixable: true,
290
+ related_constraint: "MC-P-02",
291
+ },
292
+ {
293
+ id: "R-M4-02",
294
+ name: "No testnet verification before mainnet",
295
+ category: "immutability",
296
+ severity: "medium",
297
+ description: "Directly publishing to mainnet without testnet verification. Potential bugs may cause fund loss.",
298
+ detection: "Check network === 'mainnet' && !testnet_test_passed",
299
+ recommendation: "Test on testnet first. Verify Progress runs end-to-end.",
300
+ auto_fixable: false,
301
+ related_constraint: "MC-P-03",
302
+ },
303
+ {
304
+ id: "R-M4-03",
305
+ name: "Guards not all created before publish",
306
+ category: "immutability",
307
+ severity: "critical",
308
+ description: "Some Forward.guard is still null, but design requires Guard. Cannot add Guard after publish (immutability deadlock).",
309
+ detection: "Check if all required Guards are created and bound",
310
+ recommendation: "Create and bind all Guards before publishing Machine.",
311
+ auto_fixable: false,
312
+ },
313
+ {
314
+ id: "R-M4-04",
315
+ name: "Publish order incorrect",
316
+ category: "immutability",
317
+ severity: "critical",
318
+ description: "Attempting to publish Machine before creating Guards. Guards cannot bind to already-published Machine.",
319
+ detection: "Verify dependency order: Permission → Machine(unpublished) → Guard → bind → publish",
320
+ recommendation: "Follow dependency order: Permission → Machine(unpublished) → Guard → bind → publish.",
321
+ auto_fixable: false,
322
+ },
323
+ {
324
+ id: "R-M4-05",
325
+ name: "Allocation not configured",
326
+ category: "immutability",
327
+ severity: "medium",
328
+ description: "Terminal node not mapped to Allocator. Funds cannot be distributed after workflow completes.",
329
+ detection: "Check if terminal nodes have Allocator mapping",
330
+ recommendation: "Configure Allocator for each terminal node.",
331
+ auto_fixable: false,
332
+ },
333
+ {
334
+ id: "R-M4-06",
335
+ name: "clear operation without backup",
336
+ category: "immutability",
337
+ severity: "high",
338
+ description: "Executing node clear before exporting backup. All node data lost, cannot recover.",
339
+ detection: "Check if machineNode2file backup created before clear operation",
340
+ recommendation: "Run machineNode2file backup before any clear operation.",
341
+ auto_fixable: true,
342
+ },
343
+ {
344
+ id: "R-M5-01",
345
+ name: "Service not created",
346
+ category: "environment",
347
+ severity: "high",
348
+ description: "Machine design complete but Service not created. Machine cannot bind to Service.",
349
+ detection: "Check if Service object is in published_services set",
350
+ recommendation: "Create Service first, then design/publish Machine.",
351
+ auto_fixable: false,
352
+ },
353
+ {
354
+ id: "R-M5-02",
355
+ name: "Permission object mismatch",
356
+ category: "environment",
357
+ severity: "high",
358
+ description: "Machine's Permission differs from Service's Permission. Permission organization inconsistent, may cause operation failure.",
359
+ detection: "Cross-check Machine's Permission against Service's Permission",
360
+ recommendation: "Use the same Permission for Machine and Service (or explicitly document different organizations).",
361
+ auto_fixable: false,
362
+ },
363
+ {
364
+ id: "R-M5-03",
365
+ name: "Allocation configuration incomplete",
366
+ category: "environment",
367
+ severity: "high",
368
+ description: "Service's order_allocators not configured or misconfigured. Terminal node funds cannot be distributed.",
369
+ detection: "Check if Service.order_allocators is configured for each terminal node",
370
+ recommendation: "Configure Service.order_allocators, one Allocator per terminal node.",
371
+ auto_fixable: false,
372
+ },
373
+ {
374
+ id: "R-M5-04",
375
+ name: "Reward object not created",
376
+ category: "environment",
377
+ severity: "medium",
378
+ description: "Reward incentive scenario referenced but Reward object not created.",
379
+ detection: "Check if Reward object is in published_rewards set",
380
+ recommendation: "Create Reward object first, then design Guard.",
381
+ auto_fixable: false,
382
+ },
383
+ {
384
+ id: "R-M5-05",
385
+ name: "Arbitration object not created",
386
+ category: "environment",
387
+ severity: "medium",
388
+ description: "Arbitration scenario referenced but Arbitration object not created.",
389
+ detection: "Check if Arbitration object is in published_arbitrations set",
390
+ recommendation: "Create Arbitration object first.",
391
+ auto_fixable: false,
392
+ },
393
+ {
394
+ id: "R-M5-06",
395
+ name: "Cross-Machine dependency not published",
396
+ category: "environment",
397
+ severity: "critical",
398
+ description: "Machine A depends on Machine B, but B is not published. Guard query for Machine B's Progress will fail. " +
399
+ "Dependency verification: indirect via progress::new -> assert_published (see 06 §14.6).",
400
+ detection: "Check machine_ref against published_machines set",
401
+ recommendation: "Ensure upstream Machine is published first.",
402
+ auto_fixable: false,
403
+ },
404
+ {
405
+ id: "R-M5-07",
406
+ name: "Repository not created",
407
+ category: "environment",
408
+ severity: "medium",
409
+ description: "Guard references Repository but not created. Guard query will fail.",
410
+ detection: "Check repository_ref against published repositories set",
411
+ recommendation: "Create and publish Repository first. Note: consensus_repositories is declarative-only (see 06 §14.4).",
412
+ auto_fixable: false,
413
+ },
414
+ {
415
+ id: "R-M5-08",
416
+ name: "Object dependency table incomplete",
417
+ category: "environment",
418
+ severity: "low",
419
+ description: "Project object dependency table missing some objects. Design decisions based on incomplete information.",
420
+ detection: "Scan project environment for missing object references",
421
+ recommendation: "Use machine-context.ts to scan complete project environment.",
422
+ auto_fixable: false,
423
+ },
424
+ ];
425
+ export function assessMachineRisks(machine, context) {
426
+ const detected = [];
427
+ detected.push(...checkStructuralRisks(machine));
428
+ detected.push(...checkGuardIntegrationRisks(machine, context));
429
+ detected.push(...checkPermissionRisks(machine));
430
+ detected.push(...checkImmutabilityRisks(machine, context));
431
+ detected.push(...checkEnvironmentRisks(machine, context));
432
+ const summary = {
433
+ critical: detected.filter((r) => r.severity === "critical").length,
434
+ high: detected.filter((r) => r.severity === "high").length,
435
+ medium: detected.filter((r) => r.severity === "medium").length,
436
+ low: detected.filter((r) => r.severity === "low").length,
437
+ };
438
+ let overall_level = "low";
439
+ if (summary.critical > 0)
440
+ overall_level = "critical";
441
+ else if (summary.high > 0)
442
+ overall_level = "high";
443
+ else if (summary.medium > 0)
444
+ overall_level = "medium";
445
+ else if (summary.low > 0)
446
+ overall_level = "low";
447
+ let recommendation;
448
+ if (summary.critical > 0) {
449
+ recommendation = "do_not_publish";
450
+ }
451
+ else if (summary.high > 2) {
452
+ recommendation = "fix_first";
453
+ }
454
+ else {
455
+ recommendation = "publish";
456
+ }
457
+ return {
458
+ overall_level,
459
+ detected_risks: detected,
460
+ summary,
461
+ recommendation,
462
+ };
463
+ }
464
+ function checkStructuralRisks(machine) {
465
+ const risks = [];
466
+ const hasEntry = machine.pairs.some((p) => p.prev_node === "");
467
+ if (!hasEntry) {
468
+ risks.push(makeRisk("R-M1-01", "No Pair with prev_node='' found. Workflow cannot start."));
469
+ }
470
+ const allPrevNodesForTerminal = new Set(machine.pairs.map((p) => p.prev_node).filter((n) => n !== ""));
471
+ const allNodes = new Set(machine.nodes.map((n) => n.name));
472
+ const terminals = [...allNodes].filter((n) => !allPrevNodesForTerminal.has(n));
473
+ if (terminals.length === 0) {
474
+ risks.push(makeRisk("R-M1-02", "No terminal node found. Workflow never completes."));
475
+ }
476
+ const entryNodes = new Set(machine.pairs.filter((p) => p.prev_node === "").map((p) => p.next_node));
477
+ const allPrevNodes = new Set(machine.pairs.map((p) => p.prev_node).filter((n) => n !== ""));
478
+ for (const node of machine.nodes) {
479
+ if (!entryNodes.has(node.name) && !allPrevNodes.has(node.name)) {
480
+ const hasIncoming = machine.pairs.some((p) => p.next_node === node.name);
481
+ if (!hasIncoming) {
482
+ risks.push(makeRisk("R-M1-04", `Node "${node.name}" is orphaned (no incoming Pair).`));
483
+ }
484
+ }
485
+ }
486
+ if (machine.nodes.length > MAX_NODE_COUNT) {
487
+ risks.push(makeRisk("R-M1-07", `Node count ${machine.nodes.length} exceeds MAX_NODE_COUNT (${MAX_NODE_COUNT}).`));
488
+ }
489
+ const pairsPerNode = new Map();
490
+ for (const p of machine.pairs) {
491
+ pairsPerNode.set(p.next_node, (pairsPerNode.get(p.next_node) ?? 0) + 1);
492
+ }
493
+ for (const [nodeName, pairCount] of pairsPerNode) {
494
+ if (pairCount > 40) {
495
+ risks.push(makeRisk("R-M1-08", `Node "${nodeName}" has ${pairCount} Pairs, exceeds MAX_NODE_PAIR_COUNT (40).`));
496
+ }
497
+ }
498
+ for (const pair of machine.pairs) {
499
+ if (pair.forwards.length > 20) {
500
+ risks.push(makeRisk("R-M1-09", `Pair (${pair.prev_node} -> ${pair.next_node}) has ${pair.forwards.length} Forwards, exceeds MAX_FORWARD_COUNT (20).`));
501
+ }
502
+ }
503
+ const nodeNames = machine.nodes.map((n) => n.name);
504
+ const duplicates = nodeNames.filter((name, idx) => nodeNames.indexOf(name) !== idx);
505
+ if (duplicates.length > 0) {
506
+ risks.push(makeRisk("R-M1-10", `Duplicate node names: ${[...new Set(duplicates)].join(", ")}`));
507
+ }
508
+ return risks;
509
+ }
510
+ function checkGuardIntegrationRisks(machine, context) {
511
+ const risks = [];
512
+ for (const pair of machine.pairs) {
513
+ for (const fwd of pair.forwards) {
514
+ if (fwd.guard && !context.published_guards.has(fwd.guard)) {
515
+ risks.push(makeRisk("R-M2-01", `Forward "${fwd.name}" references Guard "${fwd.guard}" not in published_guards.`));
516
+ }
517
+ if (fwd.retained_submission && !fwd.guard) {
518
+ risks.push(makeRisk("R-M2-04", `Forward "${fwd.name}" has retained_submission but no Guard. retained_submission requires a Guard.`));
519
+ }
520
+ }
521
+ }
522
+ return risks;
523
+ }
524
+ function checkPermissionRisks(machine) {
525
+ const risks = [];
526
+ for (const pair of machine.pairs) {
527
+ for (const fwd of pair.forwards) {
528
+ const hasNamed = fwd.named_operator !== undefined && fwd.named_operator !== null;
529
+ const hasPerm = fwd.permission_index !== undefined && fwd.permission_index !== null;
530
+ if (!hasNamed && !hasPerm) {
531
+ risks.push(makeRisk("R-M3-01", `Forward "${fwd.name}" in Pair (${pair.prev_node} -> ${pair.next_node}) has no permission.`));
532
+ }
533
+ }
534
+ }
535
+ for (const pair of machine.pairs) {
536
+ for (const fwd of pair.forwards) {
537
+ const hasNamed = fwd.named_operator !== undefined && fwd.named_operator !== null;
538
+ const hasPerm = fwd.permission_index !== undefined && fwd.permission_index !== null;
539
+ if (hasNamed && hasPerm) {
540
+ risks.push(makeRisk("R-M3-07", `Forward "${fwd.name}" in Pair (${pair.prev_node} -> ${pair.next_node}) has both namedOperator and permissionIndex (OR semantic).`));
541
+ }
542
+ }
543
+ }
544
+ for (const pair of machine.pairs) {
545
+ for (const fwd of pair.forwards) {
546
+ if (fwd.permission_index !== undefined &&
547
+ fwd.permission_index !== null &&
548
+ fwd.permission_index < USER_DEFINED_PERM_INDEX_START) {
549
+ risks.push(makeRisk("R-M3-08", `Forward "${fwd.name}" in Pair (${pair.prev_node} -> ${pair.next_node}) ` +
550
+ `has permission_index=${fwd.permission_index} < ${USER_DEFINED_PERM_INDEX_START}. ` +
551
+ `Indexes 0-999 are reserved for built-in permissions.`));
552
+ }
553
+ }
554
+ }
555
+ return risks;
556
+ }
557
+ function checkImmutabilityRisks(machine, context) {
558
+ const risks = [];
559
+ if (context.network === "mainnet" && !context.testnet_test_passed) {
560
+ risks.push(makeRisk("R-M4-02", "Mainnet publish attempted without testnet test passing."));
561
+ }
562
+ const referencedGuards = new Set();
563
+ for (const pair of machine.pairs) {
564
+ for (const fwd of pair.forwards) {
565
+ if (fwd.guard)
566
+ referencedGuards.add(fwd.guard);
567
+ }
568
+ }
569
+ const missingGuards = [...referencedGuards].filter((g) => !context.published_guards.has(g));
570
+ if (missingGuards.length > 0) {
571
+ risks.push(makeRisk("R-M4-03", `Guards not all created before publish. Missing: ${missingGuards.join(", ")}`));
572
+ }
573
+ return risks;
574
+ }
575
+ function checkEnvironmentRisks(machine, context) {
576
+ const risks = [];
577
+ const referencedGuards = new Set();
578
+ for (const pair of machine.pairs) {
579
+ for (const fwd of pair.forwards) {
580
+ if (fwd.guard)
581
+ referencedGuards.add(fwd.guard);
582
+ }
583
+ }
584
+ const missingGuards = [...referencedGuards].filter((g) => !context.published_guards.has(g));
585
+ if (missingGuards.length > 0) {
586
+ risks.push(makeRisk("R-M5-08", `Object dependency table incomplete. Missing Guards: ${missingGuards.join(", ")}`));
587
+ }
588
+ return risks;
589
+ }
590
+ function makeRisk(ruleId, detail) {
591
+ const rule = MACHINE_RISK_RULES.find((r) => r.id === ruleId);
592
+ if (!rule) {
593
+ return {
594
+ rule_id: ruleId,
595
+ name: "Unknown",
596
+ severity: "low",
597
+ detail,
598
+ recommendation: "Investigate manually.",
599
+ auto_fixable: false,
600
+ };
601
+ }
602
+ return {
603
+ rule_id: rule.id,
604
+ name: rule.name,
605
+ severity: rule.severity,
606
+ detail,
607
+ recommendation: rule.recommendation,
608
+ auto_fixable: rule.auto_fixable,
609
+ };
610
+ }
611
+ export function getRiskRulesByCategory(category) {
612
+ return MACHINE_RISK_RULES.filter((r) => r.category === category);
613
+ }
614
+ export function getRiskRuleById(id) {
615
+ return MACHINE_RISK_RULES.find((r) => r.id === id);
616
+ }
617
+ export function getRiskRulesBySeverity(severity) {
618
+ return MACHINE_RISK_RULES.filter((r) => r.severity === severity);
619
+ }
620
+ export function getAutoFixableRules() {
621
+ return MACHINE_RISK_RULES.filter((r) => r.auto_fixable);
622
+ }
623
+ export function getRiskSummary(assessment) {
624
+ const lines = [
625
+ `Overall Risk Level: ${assessment.overall_level.toUpperCase()}`,
626
+ `Recommendation: ${assessment.recommendation}`,
627
+ "",
628
+ "Summary:",
629
+ ` Critical: ${assessment.summary.critical}`,
630
+ ` High: ${assessment.summary.high}`,
631
+ ` Medium: ${assessment.summary.medium}`,
632
+ ` Low: ${assessment.summary.low}`,
633
+ "",
634
+ "Detected Risks:",
635
+ ];
636
+ for (const risk of assessment.detected_risks) {
637
+ lines.push(` [${risk.severity.toUpperCase()}] ${risk.rule_id}: ${risk.name}`);
638
+ lines.push(` Detail: ${risk.detail}`);
639
+ lines.push(` Fix: ${risk.recommendation}`);
640
+ }
641
+ return lines.join("\n");
642
+ }
643
+ export const MACHINE_RISK_VERSION = "1.0.0";
644
+ export const MACHINE_RISK_RULES_COUNT = MACHINE_RISK_RULES.length;