@wowok/agent-mcp 2.7.1 → 2.7.2

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 (375) hide show
  1. package/dist/config/index.js +1 -1
  2. package/dist/config/runtime.js +1 -238
  3. package/dist/customer/customer-advice.js +1 -130
  4. package/dist/customer/index.js +1 -11
  5. package/dist/customer/industry-risks.js +1 -438
  6. package/dist/customer/info-puzzle.js +1 -681
  7. package/dist/customer/order-monitor.js +1 -328
  8. package/dist/customer/order-strategy.js +1 -373
  9. package/dist/customer/post-purchase.js +1 -351
  10. package/dist/customer/preorder-compare.js +1 -34
  11. package/dist/customer/reminder-system.js +1 -316
  12. package/dist/customer/risk-assessment.js +1 -397
  13. package/dist/customer/types.js +1 -13
  14. package/dist/customer/user-preferences.js +1 -460
  15. package/dist/evaluation/arbitration-game.d.ts +9 -2
  16. package/dist/evaluation/arbitration-game.js +1 -48
  17. package/dist/evaluation/builtins/demand-match.js +1 -153
  18. package/dist/evaluation/builtins/index.js +1 -10
  19. package/dist/evaluation/builtins/service-risk.js +1 -55
  20. package/dist/evaluation/capability.js +1 -13
  21. package/dist/evaluation/composer.js +1 -40
  22. package/dist/evaluation/engine.js +1 -175
  23. package/dist/evaluation/extract.js +1 -115
  24. package/dist/evaluation/game-strategy.d.ts +27 -0
  25. package/dist/evaluation/game-strategy.js +1 -0
  26. package/dist/evaluation/gap.js +1 -100
  27. package/dist/evaluation/index.d.ts +1 -0
  28. package/dist/evaluation/index.js +1 -11
  29. package/dist/evaluation/node-game.d.ts +31 -3
  30. package/dist/evaluation/node-game.js +1 -57
  31. package/dist/evaluation/region.js +1 -36
  32. package/dist/evaluation/types.d.ts +1 -0
  33. package/dist/evaluation/types.js +1 -1
  34. package/dist/evaluation/user-injection.js +1 -27
  35. package/dist/experience/experience-reuse.js +1 -103
  36. package/dist/experience/index.js +1 -5
  37. package/dist/experience/intent-distill.js +1 -83
  38. package/dist/experience/realtime-feedback.js +1 -94
  39. package/dist/experience/types.js +1 -1
  40. package/dist/experience/user-profile.js +1 -171
  41. package/dist/extensions/business-modules.js +1 -287
  42. package/dist/extensions/capability-manifest.js +1 -781
  43. package/dist/extensions/constraint-registry.js +1 -198
  44. package/dist/extensions/index.js +1 -6
  45. package/dist/extensions/metric-registry.js +1 -257
  46. package/dist/extensions/mode-evaluator.js +1 -170
  47. package/dist/extensions/modes.js +1 -499
  48. package/dist/extensions/registry.js +1 -717
  49. package/dist/extensions/types.js +1 -1
  50. package/dist/harness/auto-escalation.js +1 -68
  51. package/dist/harness/checkpoint.js +1 -129
  52. package/dist/harness/index.js +1 -78
  53. package/dist/harness/plan.js +1 -315
  54. package/dist/harness/recover.js +1 -139
  55. package/dist/harness/types.js +1 -1
  56. package/dist/harness/verify.js +1 -237
  57. package/dist/index.js +1 -273
  58. package/dist/intent/enrich.js +1 -67
  59. package/dist/intent/index.js +1 -60
  60. package/dist/intent/matcher.js +1 -81
  61. package/dist/intent/store.js +1 -55
  62. package/dist/intent/types.js +1 -10
  63. package/dist/knowledge/acquisition-flywheel.js +1 -192
  64. package/dist/knowledge/allocation-confirm.js +1 -534
  65. package/dist/knowledge/allocation-context.js +1 -249
  66. package/dist/knowledge/allocation-ledger.js +1 -463
  67. package/dist/knowledge/allocation-puzzle.js +1 -298
  68. package/dist/knowledge/allocation-risk.js +1 -568
  69. package/dist/knowledge/allocation-templates.js +1 -970
  70. package/dist/knowledge/allocation-translation.js +1 -585
  71. package/dist/knowledge/arb-risk.js +1 -210
  72. package/dist/knowledge/arbitration-confirm.js +1 -559
  73. package/dist/knowledge/arbitration-context.js +1 -505
  74. package/dist/knowledge/arbitration-ledger.js +1 -521
  75. package/dist/knowledge/arbitration-puzzle.js +1 -304
  76. package/dist/knowledge/arbitration-risk.js +1 -423
  77. package/dist/knowledge/arbitration-templates.js +1 -276
  78. package/dist/knowledge/arbitration-translation.js +1 -487
  79. package/dist/knowledge/arbitration-trust.js +1 -117
  80. package/dist/knowledge/audit-rules.js +1 -141
  81. package/dist/knowledge/bridge-risk.js +1 -263
  82. package/dist/knowledge/contact-risk.js +1 -200
  83. package/dist/knowledge/contact-templates.js +1 -60
  84. package/dist/knowledge/demand-confirm.js +1 -206
  85. package/dist/knowledge/demand-matching.js +1 -132
  86. package/dist/knowledge/demand-risk.js +1 -240
  87. package/dist/knowledge/demand-translation.js +1 -354
  88. package/dist/knowledge/deployment-scanner.js +1 -823
  89. package/dist/knowledge/dynamic-pricing.js +1 -87
  90. package/dist/knowledge/examples-scanner-cli.js +1 -26
  91. package/dist/knowledge/examples-scanner.js +1 -843
  92. package/dist/knowledge/flywheel-loop.js +1 -404
  93. package/dist/knowledge/fund-layer.js +1 -973
  94. package/dist/knowledge/glossary.js +1 -211
  95. package/dist/knowledge/guard-confirm.js +1 -406
  96. package/dist/knowledge/guard-context.js +1 -287
  97. package/dist/knowledge/guard-design-patterns.js +1 -360
  98. package/dist/knowledge/guard-ledger.js +1 -260
  99. package/dist/knowledge/guard-lint.js +1 -670
  100. package/dist/knowledge/guard-migration.js +1 -228
  101. package/dist/knowledge/guard-puzzle.js +1 -805
  102. package/dist/knowledge/guard-render.js +1 -700
  103. package/dist/knowledge/guard-risk.js +1 -1879
  104. package/dist/knowledge/guard-submission-prompt.js +1 -171
  105. package/dist/knowledge/guard-templates.js +1 -1105
  106. package/dist/knowledge/guard-translation.js +1 -1119
  107. package/dist/knowledge/index.js +1 -436
  108. package/dist/knowledge/industry-evolution.js +1 -323
  109. package/dist/knowledge/industry-generalizer.js +1 -381
  110. package/dist/knowledge/industry-registry.js +1 -174
  111. package/dist/knowledge/intent-metrics.d.ts +4 -3
  112. package/dist/knowledge/intent-metrics.js +1 -566
  113. package/dist/knowledge/machine-confirm.js +1 -559
  114. package/dist/knowledge/machine-context.js +1 -833
  115. package/dist/knowledge/machine-ledger.js +1 -338
  116. package/dist/knowledge/machine-puzzle.js +1 -494
  117. package/dist/knowledge/machine-render.js +1 -565
  118. package/dist/knowledge/machine-risk.js +1 -669
  119. package/dist/knowledge/machine-templates.js +1 -1597
  120. package/dist/knowledge/machine-topology.js +1 -234
  121. package/dist/knowledge/machine-translation.js +1 -513
  122. package/dist/knowledge/mcp-schema-audit-cli.js +1 -45
  123. package/dist/knowledge/mcp-schema-audit.js +1 -777
  124. package/dist/knowledge/onchain-constants.js +1 -35
  125. package/dist/knowledge/order-confirm.js +1 -573
  126. package/dist/knowledge/order-context.js +1 -390
  127. package/dist/knowledge/order-ledger.js +1 -341
  128. package/dist/knowledge/order-puzzle.js +1 -255
  129. package/dist/knowledge/order-risk.js +1 -653
  130. package/dist/knowledge/order-templates.js +1 -368
  131. package/dist/knowledge/order-translation.js +1 -550
  132. package/dist/knowledge/overrides-loader.js +1 -65
  133. package/dist/knowledge/passport-confirm.js +1 -531
  134. package/dist/knowledge/passport-context.js +1 -306
  135. package/dist/knowledge/passport-ledger.js +1 -282
  136. package/dist/knowledge/passport-puzzle.js +1 -333
  137. package/dist/knowledge/passport-risk.js +1 -450
  138. package/dist/knowledge/passport-templates.js +1 -568
  139. package/dist/knowledge/passport-translation.js +1 -516
  140. package/dist/knowledge/payment-risk.js +1 -249
  141. package/dist/knowledge/permission-confirm.js +1 -426
  142. package/dist/knowledge/permission-context.js +1 -224
  143. package/dist/knowledge/permission-ledger.js +1 -403
  144. package/dist/knowledge/permission-puzzle.js +1 -173
  145. package/dist/knowledge/permission-risk.js +1 -411
  146. package/dist/knowledge/permission-templates.js +1 -234
  147. package/dist/knowledge/permission-translation.js +1 -350
  148. package/dist/knowledge/personal-risk.js +1 -212
  149. package/dist/knowledge/process-model.js +1 -160
  150. package/dist/knowledge/progress-confirm.js +1 -456
  151. package/dist/knowledge/progress-context.js +1 -452
  152. package/dist/knowledge/progress-ledger.js +1 -330
  153. package/dist/knowledge/progress-puzzle.js +1 -219
  154. package/dist/knowledge/progress-risk.js +1 -461
  155. package/dist/knowledge/progress-templates.js +1 -228
  156. package/dist/knowledge/progress-translation.js +1 -405
  157. package/dist/knowledge/proof-confirm.js +1 -187
  158. package/dist/knowledge/proof-risk.js +1 -207
  159. package/dist/knowledge/proof-translation.js +1 -283
  160. package/dist/knowledge/registrar-risk.js +1 -217
  161. package/dist/knowledge/repository-confirm.js +1 -286
  162. package/dist/knowledge/repository-risk.js +1 -373
  163. package/dist/knowledge/repository-translation.js +1 -445
  164. package/dist/knowledge/reputation-rules.js +1 -99
  165. package/dist/knowledge/resource-risk.js +1 -157
  166. package/dist/knowledge/reward-confirm.js +1 -526
  167. package/dist/knowledge/reward-context.js +1 -504
  168. package/dist/knowledge/reward-ledger.js +1 -502
  169. package/dist/knowledge/reward-puzzle.js +1 -300
  170. package/dist/knowledge/reward-risk.js +1 -627
  171. package/dist/knowledge/reward-templates.js +1 -197
  172. package/dist/knowledge/reward-translation.js +1 -501
  173. package/dist/knowledge/safety-rules.js +1 -404
  174. package/dist/knowledge/scenario-modes.js +1 -321
  175. package/dist/knowledge/service-confirm.js +1 -807
  176. package/dist/knowledge/service-context.js +1 -403
  177. package/dist/knowledge/service-ledger.js +1 -609
  178. package/dist/knowledge/service-puzzle.js +1 -236
  179. package/dist/knowledge/service-risk.js +1 -651
  180. package/dist/knowledge/service-templates.js +1 -456
  181. package/dist/knowledge/service-translation.js +1 -622
  182. package/dist/knowledge/template-registry.js +1 -353
  183. package/dist/knowledge/tool-constraints.js +1 -195
  184. package/dist/knowledge/tools-reference.js +1 -178
  185. package/dist/knowledge/treasury-confirm.js +1 -512
  186. package/dist/knowledge/treasury-context.js +1 -363
  187. package/dist/knowledge/treasury-ledger.js +1 -300
  188. package/dist/knowledge/treasury-puzzle.js +1 -216
  189. package/dist/knowledge/treasury-risk.js +1 -440
  190. package/dist/knowledge/treasury-templates.js +1 -358
  191. package/dist/knowledge/treasury-translation.js +1 -498
  192. package/dist/knowledge/trust-metrics.js +1 -198
  193. package/dist/knowledge/util-risk.js +1 -135
  194. package/dist/loop-engineering/aggregate.js +1 -132
  195. package/dist/loop-engineering/context-collect.js +1 -83
  196. package/dist/loop-engineering/diagnose.js +1 -273
  197. package/dist/loop-engineering/improve.js +1 -405
  198. package/dist/loop-engineering/index.js +1 -4
  199. package/dist/loop-engineering/pipeline.js +1 -56
  200. package/dist/mode-market/index.js +1 -3
  201. package/dist/mode-market/registry.js +1 -124
  202. package/dist/mode-market/review.js +1 -214
  203. package/dist/mode-market/submission.js +1 -85
  204. package/dist/participation/collaborator-interest.d.ts +23 -0
  205. package/dist/participation/collaborator-interest.js +1 -0
  206. package/dist/participation/customer-interest.d.ts +25 -0
  207. package/dist/participation/customer-interest.js +1 -0
  208. package/dist/participation/merchant-interest.js +1 -100
  209. package/dist/participation/radar-core.d.ts +13 -3
  210. package/dist/participation/radar-core.js +1 -269
  211. package/dist/participation/supplier-interest.d.ts +25 -0
  212. package/dist/participation/supplier-interest.js +1 -0
  213. package/dist/persona/analyzer.js +1 -66
  214. package/dist/persona/bridge.js +1 -86
  215. package/dist/persona/defaults.js +1 -195
  216. package/dist/persona/experience-bridge.js +1 -23
  217. package/dist/persona/index.js +1 -71
  218. package/dist/persona/model.js +1 -111
  219. package/dist/persona/store.js +1 -62
  220. package/dist/persona/types.d.ts +3 -1
  221. package/dist/persona/types.js +1 -5
  222. package/dist/project/business-puzzle.js +1 -383
  223. package/dist/project/context-assembly.js +1 -254
  224. package/dist/project/deployment-bridge.js +1 -120
  225. package/dist/project/deployment-doc.js +1 -1126
  226. package/dist/project/edit-planner.js +1 -1342
  227. package/dist/project/evaluation.js +1 -2011
  228. package/dist/project/game-theory.js +1 -177
  229. package/dist/project/graph-builder.js +1 -656
  230. package/dist/project/graph.js +1 -340
  231. package/dist/project/handlers.js +1 -1784
  232. package/dist/project/index.d.ts +1 -0
  233. package/dist/project/index.js +1 -301
  234. package/dist/project/intent-analyzer.js +1 -149
  235. package/dist/project/machine-nodes.js +1 -36
  236. package/dist/project/merchant-guide.js +1 -264
  237. package/dist/project/migration.js +1 -125
  238. package/dist/project/mode-actions.js +1 -309
  239. package/dist/project/namespace.js +1 -206
  240. package/dist/project/participation-radar.js +1 -428
  241. package/dist/project/pipeline-actions.js +1 -109
  242. package/dist/project/project-store.js +1 -422
  243. package/dist/project/query.js +1 -153
  244. package/dist/project/reverse-mapping.d.ts +34 -0
  245. package/dist/project/reverse-mapping.js +1 -0
  246. package/dist/project/risk-aggregator.js +1 -295
  247. package/dist/project/rollback-policy.js +1 -290
  248. package/dist/project/semantic-assembler.js +1 -345
  249. package/dist/project/semantic-graph.js +1 -292
  250. package/dist/project/stage-gate.js +1 -369
  251. package/dist/project/substep-trace.js +1 -332
  252. package/dist/project/task-tracker.js +1 -78
  253. package/dist/role/derivation.d.ts +18 -0
  254. package/dist/role/derivation.js +1 -0
  255. package/dist/role/index.d.ts +5 -0
  256. package/dist/role/index.js +1 -0
  257. package/dist/role/model.d.ts +8 -0
  258. package/dist/role/model.js +1 -0
  259. package/dist/role/resolution.d.ts +11 -0
  260. package/dist/role/resolution.js +1 -0
  261. package/dist/role/types.d.ts +11 -0
  262. package/dist/role/types.js +1 -0
  263. package/dist/rules.js +1 -52
  264. package/dist/safety/confirm-gate.js +1 -88
  265. package/dist/safety/index.js +1 -3
  266. package/dist/safety/preview.js +1 -52
  267. package/dist/schema/call/allocation.js +1 -34
  268. package/dist/schema/call/arbitration.js +1 -113
  269. package/dist/schema/call/base.d.ts +15 -15
  270. package/dist/schema/call/base.js +1 -370
  271. package/dist/schema/call/bridge-handler.js +1 -265
  272. package/dist/schema/call/bridge.d.ts +7 -7
  273. package/dist/schema/call/bridge.js +1 -458
  274. package/dist/schema/call/contact.js +1 -37
  275. package/dist/schema/call/demand.js +1 -47
  276. package/dist/schema/call/guard.js +1 -161
  277. package/dist/schema/call/handler.js +1 -322
  278. package/dist/schema/call/index.js +1 -20
  279. package/dist/schema/call/machine.js +1 -193
  280. package/dist/schema/call/order.js +1 -35
  281. package/dist/schema/call/payment.js +1 -37
  282. package/dist/schema/call/permission-handler.js +1 -54
  283. package/dist/schema/call/permission.js +1 -105
  284. package/dist/schema/call/personal.js +1 -78
  285. package/dist/schema/call/progress.js +1 -47
  286. package/dist/schema/call/proof.js +1 -33
  287. package/dist/schema/call/repository.js +1 -77
  288. package/dist/schema/call/reward.js +1 -30
  289. package/dist/schema/call/semantic.js +1 -1679
  290. package/dist/schema/call/service.js +1 -184
  291. package/dist/schema/call/treasury.js +1 -71
  292. package/dist/schema/common/index.js +1 -407
  293. package/dist/schema/config/index.js +1 -68
  294. package/dist/schema/evaluation/index.d.ts +213 -16
  295. package/dist/schema/evaluation/index.js +1 -356
  296. package/dist/schema/index.js +1 -17
  297. package/dist/schema/intent-radar/index.d.ts +13 -13
  298. package/dist/schema/intent-radar/index.js +1 -89
  299. package/dist/schema/local/index.d.ts +21 -21
  300. package/dist/schema/local/index.js +1 -927
  301. package/dist/schema/local/wip.js +1 -187
  302. package/dist/schema/messenger/index.d.ts +7 -7
  303. package/dist/schema/messenger/index.js +1 -475
  304. package/dist/schema/operations.d.ts +7 -7
  305. package/dist/schema/operations.js +1 -520
  306. package/dist/schema/persona/index.d.ts +54 -54
  307. package/dist/schema/persona/index.js +1 -148
  308. package/dist/schema/project/index.d.ts +94 -48
  309. package/dist/schema/project/index.js +1 -2057
  310. package/dist/schema/query/index.d.ts +423 -7
  311. package/dist/schema/query/index.js +1 -1646
  312. package/dist/schema/schema-query/index.js +1 -104
  313. package/dist/schema/schema-version.js +1 -76
  314. package/dist/schema/sync-layer4.js +1 -286
  315. package/dist/schema/task-status.js +1 -36
  316. package/dist/schema/trust/index.js +1 -314
  317. package/dist/schema/utils/guard-parser.js +1 -419
  318. package/dist/schema/utils/guard-query-utils.js +1 -46
  319. package/dist/schema/utils/node-parser.js +1 -369
  320. package/dist/schema/utils/object-type-utils.js +1 -35
  321. package/dist/schema/utils/permission-index-utils.js +1 -7
  322. package/dist/schema/utils/permission-machine-check.js +1 -121
  323. package/dist/schema/utils/skills-recommendation.js +1 -77
  324. package/dist/schema-query/index.js +1 -810
  325. package/dist/schemas/account_operation.output.json +5 -2
  326. package/dist/schemas/bridge_operation.output.json +5 -2
  327. package/dist/schemas/evaluation_operation.output.json +112 -7
  328. package/dist/schemas/evaluation_operation.schema.json +93 -6
  329. package/dist/schemas/index.json +1 -1
  330. package/dist/schemas/intent_radar.output.json +4 -1
  331. package/dist/schemas/intent_radar.schema.json +4 -1
  332. package/dist/schemas/local_info_operation.output.json +5 -2
  333. package/dist/schemas/local_mark_operation.output.json +5 -2
  334. package/dist/schemas/messenger_operation.output.json +5 -2
  335. package/dist/schemas/onchain_events.output.json +5 -2
  336. package/dist/schemas/onchain_operations.output.json +5 -2
  337. package/dist/schemas/onchain_operations.schema.json +4 -4
  338. package/dist/schemas/onchain_operations_allocation.schema.json +1 -1
  339. package/dist/schemas/onchain_operations_machine.schema.json +2 -2
  340. package/dist/schemas/onchain_operations_service.schema.json +1 -1
  341. package/dist/schemas/onchain_table_data.output.json +6 -3
  342. package/dist/schemas/persona_operation.output.json +4 -1
  343. package/dist/schemas/persona_operation.schema.json +4 -1
  344. package/dist/schemas/project_operation.output.json +28 -8
  345. package/dist/schemas/query_toolkit.output.json +8 -5
  346. package/dist/schemas/wowok_buildin_info.output.json +132 -0
  347. package/dist/schemas/wowok_buildin_info.schema.json +14 -0
  348. package/dist/telemetry/index.js +1 -112
  349. package/dist/telemetry/redact.js +1 -23
  350. package/dist/telemetry/storage.js +1 -80
  351. package/dist/tools/handlers/bridge.js +1 -1
  352. package/dist/tools/handlers/config.js +1 -74
  353. package/dist/tools/handlers/evaluation.js +1 -123
  354. package/dist/tools/handlers/file-export.js +1 -90
  355. package/dist/tools/handlers/intent-radar.js +1 -76
  356. package/dist/tools/handlers/local.js +1 -53
  357. package/dist/tools/handlers/messenger.js +1 -188
  358. package/dist/tools/handlers/onchain.js +1 -1180
  359. package/dist/tools/handlers/persona.js +1 -89
  360. package/dist/tools/handlers/project.js +1 -211
  361. package/dist/tools/handlers/query.js +1 -434
  362. package/dist/tools/handlers/schema-query.js +1 -176
  363. package/dist/tools/handlers/task-status.js +1 -26
  364. package/dist/tools/handlers/trust.js +1 -380
  365. package/dist/tools/handlers/wip.js +1 -90
  366. package/dist/tools/index.js +1 -1382
  367. package/dist/tools/retry.js +1 -85
  368. package/dist/tools/rules-hook.js +1 -23
  369. package/dist/tools/shared.js +1 -130
  370. package/dist/tools/types.js +1 -1
  371. package/dist/tools/upgrade-check.d.ts +19 -0
  372. package/dist/tools/upgrade-check.js +1 -0
  373. package/dist/tools/wip-deploy-assist.js +1 -306
  374. package/dist/tools/wrap.js +1 -500
  375. package/package.json +4 -2
@@ -1,700 +1 @@
1
- function categorizeNodeType(type) {
2
- if (type.startsWith("logic_"))
3
- return "decision";
4
- if (type === "context")
5
- return "context";
6
- if (type === "identifier")
7
- return "leaf";
8
- if (type === "query")
9
- return "query";
10
- if (type.startsWith("calc_") || type.startsWith("convert_"))
11
- return "computation";
12
- if (type.startsWith("vec_"))
13
- return "computation";
14
- if (type.startsWith("query_reward_") || type.startsWith("query_progress_"))
15
- return "query";
16
- return "computation";
17
- }
18
- function shortNodeLabel(node) {
19
- const t = node.type;
20
- switch (t) {
21
- case "logic_and": return "AND";
22
- case "logic_or": return "OR";
23
- case "logic_not": return "NOT";
24
- case "logic_equal": return "==";
25
- case "logic_as_u256_equal": return "==#";
26
- case "logic_as_u256_greater": return ">";
27
- case "logic_as_u256_greater_or_equal": return ">=";
28
- case "logic_as_u256_lesser": return "<";
29
- case "logic_as_u256_lesser_or_equal": return "<=";
30
- case "logic_string_contains": return "contains";
31
- case "logic_string_nocase_contains": return "contains~";
32
- case "logic_string_nocase_equal": return "==~";
33
- case "calc_number_add": return "+";
34
- case "calc_number_subtract": return "-";
35
- case "calc_number_multiply": return "*";
36
- case "calc_number_divide": return "/";
37
- case "calc_number_mod": return "%";
38
- case "calc_string_length": return "len";
39
- case "calc_string_contains": return "contains";
40
- case "calc_string_nocase_contains": return "contains~";
41
- case "calc_string_nocase_equal": return "==~";
42
- case "calc_string_indexof": return "indexOf";
43
- case "calc_string_nocase_indexof": return "indexOf~";
44
- case "convert_number_address": return "→Addr";
45
- case "convert_address_number": return "→Num";
46
- case "convert_number_string": return "→Str";
47
- case "convert_string_number": return "→Num";
48
- case "convert_safe_u8": return "→U8";
49
- case "convert_safe_u16": return "→U16";
50
- case "convert_safe_u32": return "→U32";
51
- case "convert_safe_u64": return "→U64";
52
- case "convert_safe_u128": return "→U128";
53
- case "convert_safe_u256": return "→U256";
54
- case "value_type": return "typeOf";
55
- case "vec_length": return "len";
56
- case "vec_contains_bool": return "∈?";
57
- case "vec_contains_address": return "∈?";
58
- case "vec_contains_string": return "∈?";
59
- case "vec_contains_string_nocase": return "∈?~";
60
- case "vec_contains_number": return "∈?";
61
- case "vec_indexof_bool": return "idx";
62
- case "vec_indexof_address": return "idx";
63
- case "vec_indexof_string": return "idx";
64
- case "vec_indexof_string_nocase": return "idx~";
65
- case "vec_indexof_number": return "idx";
66
- case "query":
67
- return `Q:${typeof node.query === "number" ? `#${node.query}` : node.query}`;
68
- case "query_reward_record_count": return "reward.count";
69
- case "query_reward_record_exists": return "reward.exists";
70
- case "query_reward_record_find": return "reward.find";
71
- case "query_progress_history_find": return "history.find";
72
- case "query_progress_history_session_find": return "session.find";
73
- case "query_progress_history_session_forward_find": return "forward.find";
74
- case "query_progress_history_session_count": return "session.count";
75
- case "query_progress_history_session_forward_count": return "forward.count";
76
- case "query_progress_history_session_forward_retained_submission_count":
77
- return "retained.count";
78
- case "identifier":
79
- return `id[${node.identifier ?? "?"}]`;
80
- case "context":
81
- return node.context ?? "ctx";
82
- default:
83
- return t;
84
- }
85
- }
86
- let nodeIdCounter = 0;
87
- function makeNodeId(prefix) {
88
- nodeIdCounter++;
89
- return `${prefix}_${nodeIdCounter}`;
90
- }
91
- function sanitizeMermaidLabel(text) {
92
- if (/[<>"\[\]{}()|&]/.test(text)) {
93
- return `"${text.replace(/"/g, "'")}"`;
94
- }
95
- return text;
96
- }
97
- const GUARD_NODE_COLORS = {
98
- control: { fill: "#3b82f6", stroke: "#1e40af" },
99
- decision: { fill: "#f59e0b", stroke: "#92400e" },
100
- computation: { fill: "#8b5cf6", stroke: "#6d28d9" },
101
- query: { fill: "#06b6d4", stroke: "#0e7490" },
102
- leaf: { fill: "#6b7280", stroke: "#374151" },
103
- context: { fill: "#10b981", stroke: "#065f46" },
104
- };
105
- function colorCategoryForNodeType(type) {
106
- if (type === "logic_and" || type === "logic_or")
107
- return "control";
108
- if (type === "logic_not" || type.startsWith("logic_"))
109
- return "decision";
110
- if (type.startsWith("calc_") || type.startsWith("convert_") || type.startsWith("vec_"))
111
- return "computation";
112
- if (type === "query" || type.startsWith("query_"))
113
- return "query";
114
- if (type === "identifier")
115
- return "leaf";
116
- if (type === "context")
117
- return "context";
118
- return "computation";
119
- }
120
- export function renderGuardMermaid(root, options) {
121
- const colored = options?.colored !== false;
122
- nodeIdCounter = 0;
123
- const lines = ["flowchart TD"];
124
- if (colored) {
125
- lines.push(" %% Color Legend (BehaviorTree.CPP-inspired semantic roles):");
126
- lines.push(" %% blue #3b82f6 - control (logic_and, logic_or)");
127
- lines.push(" %% amber #f59e0b - decision (logic_not, comparisons)");
128
- lines.push(" %% purple #8b5cf6 - computation (calc_*, convert_*, vec_*)");
129
- lines.push(" %% cyan #06b6d4 - query (query, query_*)");
130
- lines.push(" %% gray #6b7280 - leaf (identifier)");
131
- lines.push(" %% green #10b981 - context (Signer, Clock, Guard)");
132
- lines.push(" %% Node shapes: {}=decision, []=computation/query, ([])=leaf, {{}}=context");
133
- }
134
- const nodeDecls = [];
135
- const edgeLines = [];
136
- const nodeColorMap = [];
137
- function walk(node, parentId, edgeLabel) {
138
- const id = makeNodeId("n");
139
- const category = categorizeNodeType(node.type);
140
- const label = shortNodeLabel(node);
141
- let shapeOpen = "[", shapeClose = "]";
142
- switch (category) {
143
- case "decision":
144
- shapeOpen = "{";
145
- shapeClose = "}";
146
- break;
147
- case "context":
148
- shapeOpen = "{{";
149
- shapeClose = "}}";
150
- break;
151
- case "leaf":
152
- shapeOpen = "([";
153
- shapeClose = "])";
154
- break;
155
- case "query":
156
- case "computation":
157
- default:
158
- shapeOpen = "[";
159
- shapeClose = "]";
160
- break;
161
- }
162
- nodeDecls.push(`${id}${shapeOpen}${sanitizeMermaidLabel(label)}${shapeClose}`);
163
- nodeColorMap.push({ id, type: node.type });
164
- if (parentId) {
165
- if (edgeLabel) {
166
- edgeLines.push(` ${parentId} --> ${id}: ${sanitizeMermaidLabel(edgeLabel)}`);
167
- }
168
- else {
169
- edgeLines.push(` ${parentId} --> ${id}`);
170
- }
171
- }
172
- if (node.nodes && Array.isArray(node.nodes)) {
173
- node.nodes.forEach((child, i) => {
174
- walk(child, id, `[${i}]`);
175
- });
176
- }
177
- if (node.node) {
178
- walk(node.node, id, "child");
179
- }
180
- if (node.nodeLeft) {
181
- walk(node.nodeLeft, id, "left");
182
- }
183
- if (node.nodeRight) {
184
- walk(node.nodeRight, id, "right");
185
- }
186
- if (node.parameters && Array.isArray(node.parameters)) {
187
- node.parameters.forEach((child, i) => {
188
- walk(child, id, `param[${i}]`);
189
- });
190
- }
191
- if (node.historyIdx)
192
- walk(node.historyIdx, id, "historyIdx");
193
- if (node.sessionIdx)
194
- walk(node.sessionIdx, id, "sessionIdx");
195
- if (node.forwardIdx)
196
- walk(node.forwardIdx, id, "forwardIdx");
197
- if (node.where)
198
- walk(node.where, id, "where");
199
- if (node.find)
200
- walk(node.find, id, "find");
201
- if (node.objectLeft)
202
- walk(node.objectLeft, id, "objLeft");
203
- if (node.objectRight)
204
- walk(node.objectRight, id, "objRight");
205
- if (node.recipient)
206
- walk(node.recipient, id, "recipient");
207
- return id;
208
- }
209
- walk(root);
210
- lines.push(...nodeDecls.map(d => ` ${d}`));
211
- lines.push(...edgeLines);
212
- if (colored) {
213
- lines.push("");
214
- lines.push(" %% Node colors (BehaviorTree.CPP-inspired semantic roles)");
215
- for (const { id, type } of nodeColorMap) {
216
- const category = colorCategoryForNodeType(type);
217
- const color = GUARD_NODE_COLORS[category];
218
- lines.push(` style ${id} fill:${color.fill},stroke:${color.stroke},color:#fff`);
219
- }
220
- }
221
- return lines.join("\n");
222
- }
223
- export function renderGuardTreeIndented(input) {
224
- const { root, table, guardName, guardAddress, rely } = input;
225
- const lines = [];
226
- function describeLeaf(node) {
227
- const t = node.type;
228
- if (t === "identifier") {
229
- const tableEntry = table?.find(e => e.identifier === node.identifier);
230
- const nameHint = tableEntry?.name ? ` "${tableEntry.name}"` : "";
231
- return `identifier[${node.identifier ?? "?"}]${nameHint}`;
232
- }
233
- if (t === "context") {
234
- return `context(${node.context ?? "?"})`;
235
- }
236
- if (t === "query") {
237
- const witness = node.object?.convert_witness;
238
- const objId = node.object?.identifier;
239
- const witnessStr = witness !== undefined ? `, witness=${witness}` : "";
240
- const objStr = objId !== undefined ? `, id[${objId}]` : "";
241
- const paramStr = node.parameters && node.parameters.length > 0
242
- ? `, params=[${node.parameters.map(p => shortNodeLabel(p)).join(", ")}]`
243
- : "";
244
- return `query(${typeof node.query === "number" ? `#${node.query}` : node.query}${objStr}${witnessStr}${paramStr})`;
245
- }
246
- return shortNodeLabel(node);
247
- }
248
- function walk(node, depth, label) {
249
- const indent = " ".repeat(depth);
250
- const prefix = depth === 0 ? "- " : "- ";
251
- const labelStr = label ? `${label}: ` : "";
252
- const isLeaf = !node.nodes && !node.node && !node.nodeLeft && !node.nodeRight
253
- && !node.parameters?.length && !node.historyIdx && !node.sessionIdx
254
- && !node.forwardIdx && !node.where && !node.find && !node.objectLeft
255
- && !node.objectRight && !node.recipient;
256
- if (isLeaf) {
257
- lines.push(`${indent}${prefix}${labelStr}${describeLeaf(node)}`);
258
- }
259
- else {
260
- lines.push(`${indent}${prefix}${labelStr}${node.type}`);
261
- }
262
- if (node.nodes && Array.isArray(node.nodes)) {
263
- node.nodes.forEach((child, i) => walk(child, depth + 1, `child[${i}]`));
264
- }
265
- if (node.node) {
266
- walk(node.node, depth + 1, "child");
267
- }
268
- if (node.nodeLeft) {
269
- walk(node.nodeLeft, depth + 1, "left");
270
- }
271
- if (node.nodeRight) {
272
- walk(node.nodeRight, depth + 1, "right");
273
- }
274
- if (node.parameters && Array.isArray(node.parameters)) {
275
- node.parameters.forEach((child, i) => walk(child, depth + 1, `param[${i}]`));
276
- }
277
- if (node.historyIdx)
278
- walk(node.historyIdx, depth + 1, "historyIdx");
279
- if (node.sessionIdx)
280
- walk(node.sessionIdx, depth + 1, "sessionIdx");
281
- if (node.forwardIdx)
282
- walk(node.forwardIdx, depth + 1, "forwardIdx");
283
- if (node.where)
284
- walk(node.where, depth + 1, "where");
285
- if (node.find)
286
- walk(node.find, depth + 1, "find");
287
- if (node.objectLeft)
288
- walk(node.objectLeft, depth + 1, "objLeft");
289
- if (node.objectRight)
290
- walk(node.objectRight, depth + 1, "objRight");
291
- if (node.recipient)
292
- walk(node.recipient, depth + 1, "recipient");
293
- }
294
- lines.push("# Guard Tree Definition");
295
- lines.push("");
296
- if (guardName) {
297
- lines.push(`**Guard:** ${guardName}`);
298
- }
299
- if (guardAddress) {
300
- lines.push(`**Address:** ${guardAddress}`);
301
- }
302
- if (table) {
303
- lines.push(`**Table Entries:** ${table.length}`);
304
- }
305
- if (rely && rely.guards.length > 0) {
306
- lines.push(`**Rely:** ${rely.guards.length} guard(s)${rely.logic_or ? " (logic_or)" : " (logic_and)"}`);
307
- }
308
- lines.push("");
309
- lines.push("## Root");
310
- walk(root, 0);
311
- if (table && table.length > 0) {
312
- lines.push("");
313
- lines.push("## Table");
314
- lines.push("");
315
- lines.push("| identifier | b_submission | value_type | value | name |");
316
- lines.push("|------------|-------------|------------|-------|------|");
317
- for (const entry of table) {
318
- const rawVal = entry.value === undefined ? "-" : String(entry.value);
319
- const val = rawVal.replace(/\|/g, "\\|").replace(/\n/g, " ");
320
- const name = entry.name ?? "-";
321
- lines.push(`| ${entry.identifier} | ${entry.b_submission} | ${entry.value_type} | ${val} | ${name} |`);
322
- }
323
- lines.push("");
324
- lines.push("## Table JSON");
325
- lines.push("");
326
- lines.push("```json");
327
- lines.push(JSON.stringify(table, null, 2));
328
- lines.push("```");
329
- }
330
- if (rely && rely.guards.length > 0) {
331
- lines.push("");
332
- lines.push("## Rely");
333
- lines.push("");
334
- lines.push(`Logic: ${rely.logic_or ? "OR" : "AND"}`);
335
- for (const g of rely.guards) {
336
- lines.push(`- ${g}`);
337
- }
338
- }
339
- lines.push("");
340
- lines.push("## JSON Definition");
341
- lines.push("");
342
- lines.push("```json");
343
- lines.push(JSON.stringify({ root, table, guardName, guardAddress, rely }, null, 2));
344
- lines.push("```");
345
- return lines.join("\n");
346
- }
347
- export function parseGuardTreeIndented(text) {
348
- const errors = [];
349
- const jsonBlocks = text.matchAll(/```json\s*\n([\s\S]*?)```/g);
350
- let lastJsonBlock = null;
351
- for (const match of jsonBlocks) {
352
- lastJsonBlock = match[1];
353
- }
354
- if (lastJsonBlock) {
355
- try {
356
- const data = JSON.parse(lastJsonBlock.trim());
357
- if (data && typeof data === "object") {
358
- if ("root" in data && data.root && typeof data.root === "object" && "type" in data.root) {
359
- return { success: true, data: data.root, errors: [] };
360
- }
361
- if ("type" in data) {
362
- return { success: true, data, errors: [] };
363
- }
364
- }
365
- }
366
- catch (e) {
367
- errors.push(`JSON code block parse error: ${e.message}`);
368
- }
369
- }
370
- const lines = text.split("\n").filter(l => l.trim().startsWith("- "));
371
- if (lines.length === 0) {
372
- return { success: false, errors: ["No outline entries found. Use '- ' prefixed lines or a JSON code block."] };
373
- }
374
- const stack = [];
375
- let root = null;
376
- function getDepth(line) {
377
- const match = line.match(/^(\s*)- /);
378
- return match ? match[1].length / 2 : 0;
379
- }
380
- function parseLine(line) {
381
- const content = line.replace(/^\s*- /, "").trim();
382
- const labelMatch = content.match(/^([^:]+):\s*(.*)$/);
383
- const label = labelMatch ? labelMatch[1].trim() : undefined;
384
- const rest = labelMatch ? labelMatch[2].trim() : content;
385
- const idMatch = rest.match(/^identifier\[(\d+)\](?:\s+"(.+)")?$/);
386
- if (idMatch) {
387
- return {
388
- label,
389
- node: { type: "identifier", identifier: parseInt(idMatch[1], 10) },
390
- };
391
- }
392
- const ctxMatch = rest.match(/^context\((\w+)\)$/);
393
- if (ctxMatch) {
394
- return { label, node: { type: "context", context: ctxMatch[1] } };
395
- }
396
- const queryMatch = rest.match(/^query\((.+?)\)$/);
397
- if (queryMatch) {
398
- const inner = queryMatch[1];
399
- const parts = inner.split(",").map(s => s.trim());
400
- const queryName = parts[0].replace(/^#/, "");
401
- const isNumeric = /^\d+$/.test(queryName);
402
- const node = {
403
- type: "query",
404
- query: isNumeric ? parseInt(queryName, 10) : queryName,
405
- };
406
- for (const part of parts.slice(1)) {
407
- const idPart = part.match(/^id\[(\d+)\]$/);
408
- if (idPart) {
409
- node.object = { identifier: parseInt(idPart[1], 10) };
410
- }
411
- const witnessPart = part.match(/^witness=(\d+)$/);
412
- if (witnessPart) {
413
- node.object = { ...(node.object || {}), convert_witness: parseInt(witnessPart[1], 10) };
414
- }
415
- }
416
- return { label, node };
417
- }
418
- return { label, node: { type: rest } };
419
- }
420
- for (const line of lines) {
421
- const depth = getDepth(line);
422
- const { label, node } = parseLine(line);
423
- if (depth === 0) {
424
- root = node;
425
- stack.length = 0;
426
- stack.push({ node, depth });
427
- }
428
- else {
429
- while (stack.length > 0 && stack[stack.length - 1].depth >= depth) {
430
- stack.pop();
431
- }
432
- const parent = stack[stack.length - 1];
433
- if (!parent) {
434
- errors.push(`Orphaned node at depth ${depth}: ${line}`);
435
- continue;
436
- }
437
- if (label) {
438
- const childIdxMatch = label.match(/^child\[(\d+)\]$/);
439
- const paramIdxMatch = label.match(/^param\[(\d+)\]$/);
440
- if (childIdxMatch) {
441
- if (!parent.node.nodes)
442
- parent.node.nodes = [];
443
- parent.node.nodes.push(node);
444
- }
445
- else if (paramIdxMatch) {
446
- if (!parent.node.parameters)
447
- parent.node.parameters = [];
448
- parent.node.parameters.push(node);
449
- }
450
- else if (label === "child") {
451
- parent.node.node = node;
452
- }
453
- else if (label === "left") {
454
- parent.node.nodeLeft = node;
455
- }
456
- else if (label === "right") {
457
- parent.node.nodeRight = node;
458
- }
459
- else if (label === "historyIdx") {
460
- parent.node.historyIdx = node;
461
- }
462
- else if (label === "sessionIdx") {
463
- parent.node.sessionIdx = node;
464
- }
465
- else if (label === "forwardIdx") {
466
- parent.node.forwardIdx = node;
467
- }
468
- else if (label === "where") {
469
- parent.node.where = node;
470
- }
471
- else if (label === "find") {
472
- parent.node.find = node;
473
- }
474
- else if (label === "objLeft") {
475
- parent.node.objectLeft = node;
476
- }
477
- else if (label === "objRight") {
478
- parent.node.objectRight = node;
479
- }
480
- else if (label === "recipient") {
481
- parent.node.recipient = node;
482
- }
483
- }
484
- stack.push({ node, depth });
485
- }
486
- }
487
- if (!root) {
488
- return { success: false, errors: ["No root node found in outline."] };
489
- }
490
- return { success: true, data: root, errors };
491
- }
492
- export function renderGuardAscii(input) {
493
- const { root, table, guardName, guardAddress, rely } = input;
494
- const lines = [];
495
- if (guardName)
496
- lines.push(`Guard: ${guardName}`);
497
- if (guardAddress)
498
- lines.push(`Address: ${guardAddress}`);
499
- if (guardName || guardAddress)
500
- lines.push("");
501
- function describeNode(node) {
502
- const t = node.type;
503
- const baseLabel = shortNodeLabel(node);
504
- if (t === "identifier") {
505
- const tableEntry = table?.find(e => e.identifier === node.identifier);
506
- const typeStr = tableEntry ? ` [${typeof tableEntry.value_type === "string" ? tableEntry.value_type : `type=${tableEntry.value_type}`}]` : "";
507
- const valueStr = (tableEntry && tableEntry.value !== undefined && !tableEntry.b_submission)
508
- ? `, value=${String(tableEntry.value)}` : "";
509
- const submissionStr = tableEntry?.b_submission ? " (submission)" : "";
510
- return `${baseLabel}${typeStr}${valueStr}${submissionStr}`;
511
- }
512
- if (t === "context") {
513
- return `${baseLabel} [${node.context ?? "?"}]`;
514
- }
515
- if (t === "query") {
516
- const witness = node.object?.convert_witness;
517
- const witnessStr = witness !== undefined ? `, witness=${witness}` : "";
518
- return `${baseLabel}${witnessStr}`;
519
- }
520
- return baseLabel;
521
- }
522
- function collectChildren(node) {
523
- const children = [];
524
- if (node.nodes && Array.isArray(node.nodes)) {
525
- node.nodes.forEach((child, i) => children.push({ node: child, label: `child[${i}]` }));
526
- }
527
- if (node.node)
528
- children.push({ node: node.node, label: "child" });
529
- if (node.nodeLeft)
530
- children.push({ node: node.nodeLeft, label: "left" });
531
- if (node.nodeRight)
532
- children.push({ node: node.nodeRight, label: "right" });
533
- if (node.parameters && Array.isArray(node.parameters)) {
534
- node.parameters.forEach((child, i) => children.push({ node: child, label: `param[${i}]` }));
535
- }
536
- if (node.historyIdx)
537
- children.push({ node: node.historyIdx, label: "historyIdx" });
538
- if (node.sessionIdx)
539
- children.push({ node: node.sessionIdx, label: "sessionIdx" });
540
- if (node.forwardIdx)
541
- children.push({ node: node.forwardIdx, label: "forwardIdx" });
542
- if (node.where)
543
- children.push({ node: node.where, label: "where" });
544
- if (node.find)
545
- children.push({ node: node.find, label: "find" });
546
- if (node.objectLeft)
547
- children.push({ node: node.objectLeft, label: "objLeft" });
548
- if (node.objectRight)
549
- children.push({ node: node.objectRight, label: "objRight" });
550
- if (node.recipient)
551
- children.push({ node: node.recipient, label: "recipient" });
552
- return children;
553
- }
554
- function walk(node, prefix, isLast, edgeLabel) {
555
- const connector = isLast ? "└─ " : "├─ ";
556
- const labelStr = edgeLabel ? `${edgeLabel}: ` : "";
557
- lines.push(`${prefix}${connector}${labelStr}${describeNode(node)}`);
558
- const children = collectChildren(node);
559
- const childPrefix = prefix + (isLast ? " " : "│ ");
560
- children.forEach((child, i) => {
561
- walk(child.node, childPrefix, i === children.length - 1, child.label);
562
- });
563
- }
564
- lines.push(describeNode(root));
565
- const children = collectChildren(root);
566
- children.forEach((child, i) => {
567
- walk(child.node, "", i === children.length - 1, child.label);
568
- });
569
- if (table && table.length > 0) {
570
- lines.push("");
571
- lines.push("Table:");
572
- for (const entry of table) {
573
- const typeStr = typeof entry.value_type === "string" ? entry.value_type : `type=${entry.value_type}`;
574
- const valueStr = (entry.value !== undefined && !entry.b_submission) ? `, value=${String(entry.value)}` : "";
575
- const submissionStr = entry.b_submission ? " (submission)" : "";
576
- const nameStr = entry.name ? ` "${entry.name}"` : "";
577
- lines.push(` id[${entry.identifier}]${nameStr}: ${typeStr}${valueStr}${submissionStr}`);
578
- }
579
- }
580
- if (rely && rely.guards.length > 0) {
581
- lines.push("");
582
- lines.push(`Rely (${rely.logic_or ? "OR" : "AND"}):`);
583
- for (const g of rely.guards) {
584
- lines.push(` - ${g}`);
585
- }
586
- }
587
- return lines.join("\n");
588
- }
589
- export function renderGuardMarkmap(input) {
590
- const { root, table, guardName, guardAddress, rely } = input;
591
- const lines = [];
592
- const title = guardName ? `Guard: ${guardName}` : "Guard";
593
- lines.push(`# ${title}`);
594
- if (guardAddress)
595
- lines.push("");
596
- if (guardAddress)
597
- lines.push(`**Address:** ${guardAddress}`);
598
- lines.push("");
599
- function heading(depth, text) {
600
- return `${"#".repeat(Math.min(depth + 1, 6))} ${text}`;
601
- }
602
- function describeNode(node) {
603
- const t = node.type;
604
- const baseLabel = shortNodeLabel(node);
605
- if (t === "identifier") {
606
- const tableEntry = table?.find(e => e.identifier === node.identifier);
607
- const typeStr = tableEntry ? ` [${typeof tableEntry.value_type === "string" ? tableEntry.value_type : `type=${tableEntry.value_type}`}]` : "";
608
- const valueStr = (tableEntry && tableEntry.value !== undefined && !tableEntry.b_submission)
609
- ? `, value=${String(tableEntry.value)}` : "";
610
- const submissionStr = tableEntry?.b_submission ? " (submission)" : "";
611
- return `${baseLabel}${typeStr}${valueStr}${submissionStr}`;
612
- }
613
- if (t === "context") {
614
- return `${baseLabel} [${node.context ?? "?"}]`;
615
- }
616
- if (t === "query") {
617
- const witness = node.object?.convert_witness;
618
- const witnessStr = witness !== undefined ? `, witness=${witness}` : "";
619
- return `${baseLabel}${witnessStr}`;
620
- }
621
- return baseLabel;
622
- }
623
- function walk(node, depth, edgeLabel) {
624
- const labelStr = edgeLabel ? `${edgeLabel}: ` : "";
625
- lines.push(heading(depth, `${labelStr}${describeNode(node)}`));
626
- if (node.nodes && Array.isArray(node.nodes)) {
627
- node.nodes.forEach((child, i) => walk(child, depth + 1, `child[${i}]`));
628
- }
629
- if (node.node)
630
- walk(node.node, depth + 1, "child");
631
- if (node.nodeLeft)
632
- walk(node.nodeLeft, depth + 1, "left");
633
- if (node.nodeRight)
634
- walk(node.nodeRight, depth + 1, "right");
635
- if (node.parameters && Array.isArray(node.parameters)) {
636
- node.parameters.forEach((child, i) => walk(child, depth + 1, `param[${i}]`));
637
- }
638
- if (node.historyIdx)
639
- walk(node.historyIdx, depth + 1, "historyIdx");
640
- if (node.sessionIdx)
641
- walk(node.sessionIdx, depth + 1, "sessionIdx");
642
- if (node.forwardIdx)
643
- walk(node.forwardIdx, depth + 1, "forwardIdx");
644
- if (node.where)
645
- walk(node.where, depth + 1, "where");
646
- if (node.find)
647
- walk(node.find, depth + 1, "find");
648
- if (node.objectLeft)
649
- walk(node.objectLeft, depth + 1, "objLeft");
650
- if (node.objectRight)
651
- walk(node.objectRight, depth + 1, "objRight");
652
- if (node.recipient)
653
- walk(node.recipient, depth + 1, "recipient");
654
- }
655
- lines.push(heading(1, "Root"));
656
- walk(root, 2);
657
- if (table && table.length > 0) {
658
- lines.push("");
659
- lines.push("## Table");
660
- for (const entry of table) {
661
- const typeStr = typeof entry.value_type === "string" ? entry.value_type : `type=${entry.value_type}`;
662
- const valueStr = (entry.value !== undefined && !entry.b_submission) ? `, value=${String(entry.value)}` : "";
663
- const submissionStr = entry.b_submission ? " (submission)" : "";
664
- const nameStr = entry.name ? ` "${entry.name}"` : "";
665
- lines.push(`- id[${entry.identifier}]${nameStr}: ${typeStr}${valueStr}${submissionStr}`);
666
- }
667
- }
668
- if (rely && rely.guards.length > 0) {
669
- lines.push("");
670
- lines.push(`## Rely (${rely.logic_or ? "OR" : "AND"})`);
671
- for (const g of rely.guards) {
672
- lines.push(`- ${g}`);
673
- }
674
- }
675
- return lines.join("\n");
676
- }
677
- export function parseGuardTableJSON(text) {
678
- const sectionMatch = text.match(/##\s*Table JSON[^\n]*\n\s*```json\s*\n([\s\S]*?)```/i);
679
- if (!sectionMatch)
680
- return null;
681
- try {
682
- const data = JSON.parse(sectionMatch[1].trim());
683
- if (!Array.isArray(data))
684
- return null;
685
- return data.filter((entry) => {
686
- return entry && typeof entry === "object" &&
687
- typeof entry.identifier === "number" &&
688
- typeof entry.b_submission === "boolean";
689
- }).map((entry) => ({
690
- identifier: entry.identifier,
691
- name: entry.name,
692
- value_type: entry.value_type,
693
- b_submission: entry.b_submission,
694
- value: entry.value,
695
- }));
696
- }
697
- catch {
698
- return null;
699
- }
700
- }
1
+ function categorizeNodeType(a){if(a['startsWith']('logic_'))return'decision';if(a==='context')return'context';if(a==='identifier')return'leaf';if(a==='query')return'query';if(a['startsWith']('calc_')||a['startsWith']('convert_'))return'computation';if(a['startsWith']('vec_'))return'computation';if(a['startsWith']('query_reward_')||a['startsWith']('query_progress_'))return'query';return'computation';}function shortNodeLabel(a){const b=a['type'];switch(b){case'logic_and':return'AND';case'logic_or':return'OR';case'logic_not':return'NOT';case'logic_equal':return'==';case'logic_as_u256_equal':return'==#';case'logic_as_u256_greater':return'>';case'logic_as_u256_greater_or_equal':return'>=';case'logic_as_u256_lesser':return'<';case'logic_as_u256_lesser_or_equal':return'<=';case'logic_string_contains':return'contains';case'logic_string_nocase_contains':return'contains~';case'logic_string_nocase_equal':return'==~';case'calc_number_add':return'+';case'calc_number_subtract':return'-';case'calc_number_multiply':return'*';case'calc_number_divide':return'/';case'calc_number_mod':return'%';case'calc_string_length':return'len';case'calc_string_contains':return'contains';case'calc_string_nocase_contains':return'contains~';case'calc_string_nocase_equal':return'==~';case'calc_string_indexof':return'indexOf';case'calc_string_nocase_indexof':return'indexOf~';case'convert_number_address':return'→Addr';case'convert_address_number':return'→Num';case'convert_number_string':return'→Str';case'convert_string_number':return'→Num';case'convert_safe_u8':return'→U8';case'convert_safe_u16':return'→U16';case'convert_safe_u32':return'→U32';case'convert_safe_u64':return'→U64';case'convert_safe_u128':return'→U128';case'convert_safe_u256':return'→U256';case'value_type':return'typeOf';case'vec_length':return'len';case'vec_contains_bool':return'∈?';case'vec_contains_address':return'∈?';case'vec_contains_string':return'∈?';case'vec_contains_string_nocase':return'∈?~';case'vec_contains_number':return'∈?';case'vec_indexof_bool':return'idx';case'vec_indexof_address':return'idx';case'vec_indexof_string':return'idx';case'vec_indexof_string_nocase':return'idx~';case'vec_indexof_number':return'idx';case'query':return'Q:'+(typeof a['query']==='number'?'#'+a['query']:a['query']);case'query_reward_record_count':return'reward.count';case'query_reward_record_exists':return'reward.exists';case'query_reward_record_find':return'reward.find';case'query_progress_history_find':return'history.find';case'query_progress_history_session_find':return'session.find';case'query_progress_history_session_forward_find':return'forward.find';case'query_progress_history_session_count':return'session.count';case'query_progress_history_session_forward_count':return'forward.count';case'query_progress_history_session_forward_retained_submission_count':return'retained.count';case'identifier':return'id['+(a['identifier']??'?')+']';case'context':return a['context']??'ctx';default:return b;}}let nodeIdCounter=0x0;function makeNodeId(a){return nodeIdCounter++,a+'_'+nodeIdCounter;}function sanitizeMermaidLabel(a){if(/[<>"\[\]{}()|&]/['test'](a))return'\x22'+a['replace'](/"/g,'\x27')+'\x22';return a;}const GUARD_NODE_COLORS={'control':{'fill':'#3b82f6','stroke':'#1e40af'},'decision':{'fill':'#f59e0b','stroke':'#92400e'},'computation':{'fill':'#8b5cf6','stroke':'#6d28d9'},'query':{'fill':'#06b6d4','stroke':'#0e7490'},'leaf':{'fill':'#6b7280','stroke':'#374151'},'context':{'fill':'#10b981','stroke':'#065f46'}};function colorCategoryForNodeType(a){if(a==='logic_and'||a==='logic_or')return'control';if(a==='logic_not'||a['startsWith']('logic_'))return'decision';if(a['startsWith']('calc_')||a['startsWith']('convert_')||a['startsWith']('vec_'))return'computation';if(a==='query'||a['startsWith']('query_'))return'query';if(a==='identifier')return'leaf';if(a==='context')return'context';return'computation';}export function renderGuardMermaid(a,b){const c=b?.['colored']!==![];nodeIdCounter=0x0;const d=['flowchart\x20TD'];c&&(d['push']('\x20\x20%%\x20Color\x20Legend\x20(BehaviorTree.CPP-inspired\x20semantic\x20roles):'),d['push']('\x20\x20%%\x20\x20\x20blue\x20\x20\x20#3b82f6\x20-\x20control\x20\x20\x20\x20\x20(logic_and,\x20logic_or)'),d['push']('\x20\x20%%\x20\x20\x20amber\x20\x20#f59e0b\x20-\x20decision\x20\x20\x20\x20(logic_not,\x20comparisons)'),d['push']('\x20\x20%%\x20\x20\x20purple\x20#8b5cf6\x20-\x20computation\x20(calc_*,\x20convert_*,\x20vec_*)'),d['push']('\x20\x20%%\x20\x20\x20cyan\x20\x20\x20#06b6d4\x20-\x20query\x20\x20\x20\x20\x20\x20\x20(query,\x20query_*)'),d['push']('\x20\x20%%\x20\x20\x20gray\x20\x20\x20#6b7280\x20-\x20leaf\x20\x20\x20\x20\x20\x20\x20\x20(identifier)'),d['push']('\x20\x20%%\x20\x20\x20green\x20\x20#10b981\x20-\x20context\x20\x20\x20\x20\x20(Signer,\x20Clock,\x20Guard)'),d['push']('\x20\x20%%\x20Node\x20shapes:\x20{}=decision,\x20[]=computation/query,\x20([])=leaf,\x20{{}}=context'));const e=[],f=[],g=[];function h(i,j,k){const l=makeNodeId('n'),m=categorizeNodeType(i['type']),n=shortNodeLabel(i);let o='[',p=']';switch(m){case'decision':o='{',p='}';break;case'context':o='{{',p='}}';break;case'leaf':o='([',p='])';break;case'query':case'computation':default:o='[',p=']';break;}e['push'](''+l+o+sanitizeMermaidLabel(n)+p),g['push']({'id':l,'type':i['type']});j&&(k?f['push']('\x20\x20'+j+'\x20-->\x20'+l+':\x20'+sanitizeMermaidLabel(k)):f['push']('\x20\x20'+j+'\x20-->\x20'+l));i['nodes']&&Array['isArray'](i['nodes'])&&i['nodes']['forEach']((q,r)=>{h(q,l,'['+r+']');});i['node']&&h(i['node'],l,'child');i['nodeLeft']&&h(i['nodeLeft'],l,'left');i['nodeRight']&&h(i['nodeRight'],l,'right');i['parameters']&&Array['isArray'](i['parameters'])&&i['parameters']['forEach']((q,r)=>{h(q,l,'param['+r+']');});if(i['historyIdx'])h(i['historyIdx'],l,'historyIdx');if(i['sessionIdx'])h(i['sessionIdx'],l,'sessionIdx');if(i['forwardIdx'])h(i['forwardIdx'],l,'forwardIdx');if(i['where'])h(i['where'],l,'where');if(i['find'])h(i['find'],l,'find');if(i['objectLeft'])h(i['objectLeft'],l,'objLeft');if(i['objectRight'])h(i['objectRight'],l,'objRight');if(i['recipient'])h(i['recipient'],l,'recipient');return l;}h(a),d['push'](...e['map'](i=>'\x20\x20'+i)),d['push'](...f);if(c){d['push'](''),d['push']('\x20\x20%%\x20Node\x20colors\x20(BehaviorTree.CPP-inspired\x20semantic\x20roles)');for(const {id:i,type:j}of g){const k=colorCategoryForNodeType(j),l=GUARD_NODE_COLORS[k];d['push']('\x20\x20style\x20'+i+'\x20fill:'+l['fill']+',stroke:'+l['stroke']+',color:#fff');}}return d['join']('\x0a');}export function renderGuardTreeIndented(a){const {root:b,table:c,guardName:d,guardAddress:e,rely:f}=a,h=[];function i(k){const l=k['type'];if(l==='identifier'){const m=c?.['find'](o=>o['identifier']===k['identifier']),n=m?.['name']?'\x20\x22'+m['name']+'\x22':'';return'identifier['+(k['identifier']??'?')+']'+n;}if(l==='context')return'context('+(k['context']??'?')+')';if(l==='query'){const o=k['object']?.['convert_witness'],p=k['object']?.['identifier'],q=o!==undefined?',\x20witness='+o:'',r=p!==undefined?',\x20id['+p+']':'',s=k['parameters']&&k['parameters']['length']>0x0?',\x20params=['+k['parameters']['map'](u=>shortNodeLabel(u))['join'](',\x20')+']':'';return'query('+(typeof k['query']==='number'?'#'+k['query']:k['query'])+r+q+s+')';}return shortNodeLabel(k);}function j(k,l,m){const n='\x20\x20'['repeat'](l),o=l===0x0?'-\x20':'-\x20',p=m?m+':\x20':'',q=!k['nodes']&&!k['node']&&!k['nodeLeft']&&!k['nodeRight']&&!k['parameters']?.['length']&&!k['historyIdx']&&!k['sessionIdx']&&!k['forwardIdx']&&!k['where']&&!k['find']&&!k['objectLeft']&&!k['objectRight']&&!k['recipient'];q?h['push'](''+n+o+p+i(k)):h['push'](''+n+o+p+k['type']);k['nodes']&&Array['isArray'](k['nodes'])&&k['nodes']['forEach']((r,s)=>j(r,l+0x1,'child['+s+']'));k['node']&&j(k['node'],l+0x1,'child');k['nodeLeft']&&j(k['nodeLeft'],l+0x1,'left');k['nodeRight']&&j(k['nodeRight'],l+0x1,'right');k['parameters']&&Array['isArray'](k['parameters'])&&k['parameters']['forEach']((r,s)=>j(r,l+0x1,'param['+s+']'));if(k['historyIdx'])j(k['historyIdx'],l+0x1,'historyIdx');if(k['sessionIdx'])j(k['sessionIdx'],l+0x1,'sessionIdx');if(k['forwardIdx'])j(k['forwardIdx'],l+0x1,'forwardIdx');if(k['where'])j(k['where'],l+0x1,'where');if(k['find'])j(k['find'],l+0x1,'find');if(k['objectLeft'])j(k['objectLeft'],l+0x1,'objLeft');if(k['objectRight'])j(k['objectRight'],l+0x1,'objRight');if(k['recipient'])j(k['recipient'],l+0x1,'recipient');}h['push']('#\x20Guard\x20Tree\x20Definition'),h['push']('');d&&h['push']('**Guard:**\x20'+d);e&&h['push']('**Address:**\x20'+e);c&&h['push']('**Table\x20Entries:**\x20'+c['length']);f&&f['guards']['length']>0x0&&h['push']('**Rely:**\x20'+f['guards']['length']+'\x20guard(s)'+(f['logic_or']?'\x20(logic_or)':'\x20(logic_and)'));h['push'](''),h['push']('##\x20Root'),j(b,0x0);if(c&&c['length']>0x0){h['push'](''),h['push']('##\x20Table'),h['push'](''),h['push']('|\x20identifier\x20|\x20b_submission\x20|\x20value_type\x20|\x20value\x20|\x20name\x20|'),h['push']('|------------|-------------|------------|-------|------|');for(const k of c){const l=k['value']===undefined?'-':String(k['value']),m=l['replace'](/\|/g,'\x5c|')['replace'](/\n/g,'\x20'),n=k['name']??'-';h['push']('|\x20'+k['identifier']+'\x20|\x20'+k['b_submission']+'\x20|\x20'+k['value_type']+'\x20|\x20'+m+'\x20|\x20'+n+'\x20|');}h['push'](''),h['push']('##\x20Table\x20JSON'),h['push'](''),h['push']('```json'),h['push'](JSON['stringify'](c,null,0x2)),h['push']('```');}if(f&&f['guards']['length']>0x0){h['push'](''),h['push']('##\x20Rely'),h['push'](''),h['push']('Logic:\x20'+(f['logic_or']?'OR':'AND'));for(const o of f['guards']){h['push']('-\x20'+o);}}return h['push'](''),h['push']('##\x20JSON\x20Definition'),h['push'](''),h['push']('```json'),h['push'](JSON['stringify']({'root':b,'table':c,'guardName':d,'guardAddress':e,'rely':f},null,0x2)),h['push']('```'),h['join']('\x0a');}export function parseGuardTreeIndented(a){const b=[],c=a['matchAll'](/```json\s*\n([\s\S]*?)```/g);let d=null;for(const k of c){d=k[0x1];}if(d)try{const l=JSON['parse'](d['trim']());if(l&&typeof l==='object'){if('root'in l&&l['root']&&typeof l['root']==='object'&&'type'in l['root'])return{'success':!![],'data':l['root'],'errors':[]};if('type'in l)return{'success':!![],'data':l,'errors':[]};}}catch(m){b['push']('JSON\x20code\x20block\x20parse\x20error:\x20'+m['message']);}const f=a['split']('\x0a')['filter'](n=>n['trim']()['startsWith']('-\x20'));if(f['length']===0x0)return{'success':![],'errors':['No\x20outline\x20entries\x20found.\x20Use\x20\x27-\x20\x27\x20prefixed\x20lines\x20or\x20a\x20JSON\x20code\x20block.']};const g=[];let h=null;function i(n){const o=n['match'](/^(\s*)- /);return o?o[0x1]['length']/0x2:0x0;}function j(n){const o=n['replace'](/^\s*- /,'')['trim'](),p=o['match'](/^([^:]+):\s*(.*)$/),q=p?p[0x1]['trim']():undefined,r=p?p[0x2]['trim']():o,s=r['match'](/^identifier\[(\d+)\](?:\s+"(.+)")?$/);if(s)return{'label':q,'node':{'type':'identifier','identifier':parseInt(s[0x1],0xa)}};const t=r['match'](/^context\((\w+)\)$/);if(t)return{'label':q,'node':{'type':'context','context':t[0x1]}};const u=r['match'](/^query\((.+?)\)$/);if(u){const v=u[0x1],w=v['split'](',')['map'](A=>A['trim']()),x=w[0x0]['replace'](/^#/,''),y=/^\d+$/['test'](x),z={'type':'query','query':y?parseInt(x,0xa):x};for(const A of w['slice'](0x1)){const B=A['match'](/^id\[(\d+)\]$/);B&&(z['object']={'identifier':parseInt(B[0x1],0xa)});const C=A['match'](/^witness=(\d+)$/);C&&(z['object']={...z['object']||{},'convert_witness':parseInt(C[0x1],0xa)});}return{'label':q,'node':z};}return{'label':q,'node':{'type':r}};}for(const n of f){const o=i(n),{label:p,node:q}=j(n);if(o===0x0)h=q,g['length']=0x0,g['push']({'node':q,'depth':o});else{while(g['length']>0x0&&g[g['length']-0x1]['depth']>=o){g['pop']();}const r=g[g['length']-0x1];if(!r){b['push']('Orphaned\x20node\x20at\x20depth\x20'+o+':\x20'+n);continue;}if(p){const s=p['match'](/^child\[(\d+)\]$/),t=p['match'](/^param\[(\d+)\]$/);if(s){if(!r['node']['nodes'])r['node']['nodes']=[];r['node']['nodes']['push'](q);}else{if(t){if(!r['node']['parameters'])r['node']['parameters']=[];r['node']['parameters']['push'](q);}else{if(p==='child')r['node']['node']=q;else{if(p==='left')r['node']['nodeLeft']=q;else{if(p==='right')r['node']['nodeRight']=q;else{if(p==='historyIdx')r['node']['historyIdx']=q;else{if(p==='sessionIdx')r['node']['sessionIdx']=q;else{if(p==='forwardIdx')r['node']['forwardIdx']=q;else{if(p==='where')r['node']['where']=q;else{if(p==='find')r['node']['find']=q;else{if(p==='objLeft')r['node']['objectLeft']=q;else{if(p==='objRight')r['node']['objectRight']=q;else p==='recipient'&&(r['node']['recipient']=q);}}}}}}}}}}}}g['push']({'node':q,'depth':o});}}if(!h)return{'success':![],'errors':['No\x20root\x20node\x20found\x20in\x20outline.']};return{'success':!![],'data':h,'errors':b};}export function renderGuardAscii(a){const {root:b,table:c,guardName:d,guardAddress:e,rely:f}=a,h=[];if(d)h['push']('Guard:\x20'+d);if(e)h['push']('Address:\x20'+e);if(d||e)h['push']('');function i(m){const n=m['type'],o=shortNodeLabel(m);if(n==='identifier'){const p=c?.['find'](u=>u['identifier']===m['identifier']),q=p?'\x20['+(typeof p['value_type']==='string'?p['value_type']:'type='+p['value_type'])+']':'',r=p&&p['value']!==undefined&&!p['b_submission']?',\x20value='+String(p['value']):'',s=p?.['b_submission']?'\x20(submission)':'';return''+o+q+r+s;}if(n==='context')return o+'\x20['+(m['context']??'?')+']';if(n==='query'){const u=m['object']?.['convert_witness'],v=u!==undefined?',\x20witness='+u:'';return''+o+v;}return o;}function j(m){const n=[];m['nodes']&&Array['isArray'](m['nodes'])&&m['nodes']['forEach']((o,p)=>n['push']({'node':o,'label':'child['+p+']'}));if(m['node'])n['push']({'node':m['node'],'label':'child'});if(m['nodeLeft'])n['push']({'node':m['nodeLeft'],'label':'left'});if(m['nodeRight'])n['push']({'node':m['nodeRight'],'label':'right'});m['parameters']&&Array['isArray'](m['parameters'])&&m['parameters']['forEach']((o,p)=>n['push']({'node':o,'label':'param['+p+']'}));if(m['historyIdx'])n['push']({'node':m['historyIdx'],'label':'historyIdx'});if(m['sessionIdx'])n['push']({'node':m['sessionIdx'],'label':'sessionIdx'});if(m['forwardIdx'])n['push']({'node':m['forwardIdx'],'label':'forwardIdx'});if(m['where'])n['push']({'node':m['where'],'label':'where'});if(m['find'])n['push']({'node':m['find'],'label':'find'});if(m['objectLeft'])n['push']({'node':m['objectLeft'],'label':'objLeft'});if(m['objectRight'])n['push']({'node':m['objectRight'],'label':'objRight'});if(m['recipient'])n['push']({'node':m['recipient'],'label':'recipient'});return n;}function k(m,n,o,p){const q=o?'└─\x20':'├─\x20',r=p?p+':\x20':'';h['push'](''+n+q+r+i(m));const s=j(m),t=n+(o?'\x20\x20\x20':'│\x20\x20');s['forEach']((u,v)=>{k(u['node'],t,v===s['length']-0x1,u['label']);});}h['push'](i(b));const l=j(b);l['forEach']((m,n)=>{k(m['node'],'',n===l['length']-0x1,m['label']);});if(c&&c['length']>0x0){h['push'](''),h['push']('Table:');for(const m of c){const n=typeof m['value_type']==='string'?m['value_type']:'type='+m['value_type'],o=m['value']!==undefined&&!m['b_submission']?',\x20value='+String(m['value']):'',p=m['b_submission']?'\x20(submission)':'',q=m['name']?'\x20\x22'+m['name']+'\x22':'';h['push']('\x20\x20id['+m['identifier']+']'+q+':\x20'+n+o+p);}}if(f&&f['guards']['length']>0x0){h['push'](''),h['push']('Rely\x20('+(f['logic_or']?'OR':'AND')+'):');for(const r of f['guards']){h['push']('\x20\x20-\x20'+r);}}return h['join']('\x0a');}export function renderGuardMarkmap(a){const {root:b,table:c,guardName:d,guardAddress:e,rely:f}=a,h=[],i=d?'Guard:\x20'+d:'Guard';h['push']('#\x20'+i);if(e)h['push']('');if(e)h['push']('**Address:**\x20'+e);h['push']('');function j(m,n){return'#'['repeat'](Math['min'](m+0x1,0x6))+'\x20'+n;}function k(m){const n=m['type'],o=shortNodeLabel(m);if(n==='identifier'){const p=c?.['find'](u=>u['identifier']===m['identifier']),q=p?'\x20['+(typeof p['value_type']==='string'?p['value_type']:'type='+p['value_type'])+']':'',r=p&&p['value']!==undefined&&!p['b_submission']?',\x20value='+String(p['value']):'',s=p?.['b_submission']?'\x20(submission)':'';return''+o+q+r+s;}if(n==='context')return o+'\x20['+(m['context']??'?')+']';if(n==='query'){const u=m['object']?.['convert_witness'],v=u!==undefined?',\x20witness='+u:'';return''+o+v;}return o;}function l(m,n,o){const p=o?o+':\x20':'';h['push'](j(n,''+p+k(m)));m['nodes']&&Array['isArray'](m['nodes'])&&m['nodes']['forEach']((q,r)=>l(q,n+0x1,'child['+r+']'));if(m['node'])l(m['node'],n+0x1,'child');if(m['nodeLeft'])l(m['nodeLeft'],n+0x1,'left');if(m['nodeRight'])l(m['nodeRight'],n+0x1,'right');m['parameters']&&Array['isArray'](m['parameters'])&&m['parameters']['forEach']((q,r)=>l(q,n+0x1,'param['+r+']'));if(m['historyIdx'])l(m['historyIdx'],n+0x1,'historyIdx');if(m['sessionIdx'])l(m['sessionIdx'],n+0x1,'sessionIdx');if(m['forwardIdx'])l(m['forwardIdx'],n+0x1,'forwardIdx');if(m['where'])l(m['where'],n+0x1,'where');if(m['find'])l(m['find'],n+0x1,'find');if(m['objectLeft'])l(m['objectLeft'],n+0x1,'objLeft');if(m['objectRight'])l(m['objectRight'],n+0x1,'objRight');if(m['recipient'])l(m['recipient'],n+0x1,'recipient');}h['push'](j(0x1,'Root')),l(b,0x2);if(c&&c['length']>0x0){h['push'](''),h['push']('##\x20Table');for(const m of c){const n=typeof m['value_type']==='string'?m['value_type']:'type='+m['value_type'],o=m['value']!==undefined&&!m['b_submission']?',\x20value='+String(m['value']):'',p=m['b_submission']?'\x20(submission)':'',q=m['name']?'\x20\x22'+m['name']+'\x22':'';h['push']('-\x20id['+m['identifier']+']'+q+':\x20'+n+o+p);}}if(f&&f['guards']['length']>0x0){h['push'](''),h['push']('##\x20Rely\x20('+(f['logic_or']?'OR':'AND')+')');for(const r of f['guards']){h['push']('-\x20'+r);}}return h['join']('\x0a');}export function parseGuardTableJSON(a){const b=a['match'](/##\s*Table JSON[^\n]*\n\s*```json\s*\n([\s\S]*?)```/i);if(!b)return null;try{const c=JSON['parse'](b[0x1]['trim']());if(!Array['isArray'](c))return null;return c['filter'](d=>{return d&&typeof d==='object'&&typeof d['identifier']==='number'&&typeof d['b_submission']==='boolean';})['map'](d=>({'identifier':d['identifier'],'name':d['name'],'value_type':d['value_type'],'b_submission':d['b_submission'],'value':d['value']}));}catch{return null;}}