@wowok/agent-mcp 2.7.0 → 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 (427) 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.d.ts +5 -1
  13. package/dist/customer/risk-assessment.js +1 -397
  14. package/dist/customer/types.js +1 -13
  15. package/dist/customer/user-preferences.js +1 -460
  16. package/dist/evaluation/arbitration-game.d.ts +23 -0
  17. package/dist/evaluation/arbitration-game.js +1 -0
  18. package/dist/evaluation/builtins/demand-match.d.ts +15 -0
  19. package/dist/evaluation/builtins/demand-match.js +1 -0
  20. package/dist/evaluation/builtins/index.d.ts +3 -0
  21. package/dist/evaluation/builtins/index.js +1 -0
  22. package/dist/evaluation/builtins/service-risk.d.ts +6 -0
  23. package/dist/evaluation/builtins/service-risk.js +1 -0
  24. package/dist/evaluation/capability.d.ts +50 -0
  25. package/dist/evaluation/capability.js +1 -0
  26. package/dist/evaluation/composer.d.ts +13 -0
  27. package/dist/evaluation/composer.js +1 -0
  28. package/dist/evaluation/engine.d.ts +18 -0
  29. package/dist/evaluation/engine.js +1 -0
  30. package/dist/evaluation/extract.d.ts +30 -0
  31. package/dist/evaluation/extract.js +1 -0
  32. package/dist/evaluation/game-strategy.d.ts +27 -0
  33. package/dist/evaluation/game-strategy.js +1 -0
  34. package/dist/evaluation/gap.d.ts +2 -0
  35. package/dist/evaluation/gap.js +1 -0
  36. package/dist/evaluation/index.d.ts +12 -0
  37. package/dist/evaluation/index.js +1 -0
  38. package/dist/evaluation/node-game.d.ts +62 -0
  39. package/dist/evaluation/node-game.js +1 -0
  40. package/dist/evaluation/region.d.ts +10 -0
  41. package/dist/evaluation/region.js +1 -0
  42. package/dist/evaluation/types.d.ts +77 -0
  43. package/dist/evaluation/types.js +1 -0
  44. package/dist/evaluation/user-injection.d.ts +6 -0
  45. package/dist/evaluation/user-injection.js +1 -0
  46. package/dist/examples/education-contact-create.json +40 -0
  47. package/dist/examples/freelance-contact-create.json +40 -0
  48. package/dist/examples/insurance-machine-create.json +1 -1
  49. package/dist/examples/insurance-service-allocators.json +1 -1
  50. package/dist/examples/machine-publish.json +1 -1
  51. package/dist/examples/rental-ziroom-service-create.json +1 -1
  52. package/dist/examples/retail-adv-guard-messenger-proof-create.json +1 -1
  53. package/dist/examples/retail-myshop-service-create.json +1 -1
  54. package/dist/examples/retail-myshop-service-customer-required.json +1 -1
  55. package/dist/examples/subscription-contact-create.json +40 -0
  56. package/dist/examples/threebody-machine-create.json +1 -1
  57. package/dist/examples/travel-machine-create.json +1 -1
  58. package/dist/examples/travel-service-create.json +1 -1
  59. package/dist/experience/experience-reuse.js +1 -103
  60. package/dist/experience/index.js +1 -5
  61. package/dist/experience/intent-distill.js +1 -83
  62. package/dist/experience/realtime-feedback.js +1 -94
  63. package/dist/experience/types.js +1 -1
  64. package/dist/experience/user-profile.js +1 -171
  65. package/dist/extensions/business-modules.js +1 -287
  66. package/dist/extensions/capability-manifest.js +1 -781
  67. package/dist/extensions/constraint-registry.js +1 -198
  68. package/dist/extensions/index.js +1 -6
  69. package/dist/extensions/metric-registry.js +1 -257
  70. package/dist/extensions/mode-evaluator.js +1 -170
  71. package/dist/extensions/modes.js +1 -499
  72. package/dist/extensions/registry.js +1 -717
  73. package/dist/extensions/types.js +1 -1
  74. package/dist/harness/auto-escalation.js +1 -68
  75. package/dist/harness/checkpoint.js +1 -129
  76. package/dist/harness/index.js +1 -78
  77. package/dist/harness/plan.js +1 -276
  78. package/dist/harness/recover.js +1 -139
  79. package/dist/harness/types.js +1 -1
  80. package/dist/harness/verify.js +1 -237
  81. package/dist/index.js +1 -273
  82. package/dist/intent/enrich.d.ts +1 -0
  83. package/dist/intent/enrich.js +1 -0
  84. package/dist/intent/index.d.ts +23 -0
  85. package/dist/intent/index.js +1 -0
  86. package/dist/intent/matcher.d.ts +2 -0
  87. package/dist/intent/matcher.js +1 -0
  88. package/dist/intent/store.d.ts +19 -0
  89. package/dist/intent/store.js +1 -0
  90. package/dist/intent/types.d.ts +33 -0
  91. package/dist/intent/types.js +1 -0
  92. package/dist/knowledge/acquisition-flywheel.js +1 -192
  93. package/dist/knowledge/allocation-confirm.js +1 -534
  94. package/dist/knowledge/allocation-context.js +1 -249
  95. package/dist/knowledge/allocation-ledger.js +1 -463
  96. package/dist/knowledge/allocation-puzzle.js +1 -298
  97. package/dist/knowledge/allocation-risk.js +1 -568
  98. package/dist/knowledge/allocation-templates.js +1 -970
  99. package/dist/knowledge/allocation-translation.js +1 -585
  100. package/dist/knowledge/arb-risk.js +1 -210
  101. package/dist/knowledge/arbitration-confirm.js +1 -559
  102. package/dist/knowledge/arbitration-context.js +1 -505
  103. package/dist/knowledge/arbitration-ledger.js +1 -521
  104. package/dist/knowledge/arbitration-puzzle.js +1 -304
  105. package/dist/knowledge/arbitration-risk.js +1 -433
  106. package/dist/knowledge/arbitration-templates.js +1 -276
  107. package/dist/knowledge/arbitration-translation.js +1 -487
  108. package/dist/knowledge/arbitration-trust.js +1 -117
  109. package/dist/knowledge/audit-rules.js +1 -141
  110. package/dist/knowledge/bridge-risk.js +1 -263
  111. package/dist/knowledge/contact-risk.js +1 -200
  112. package/dist/knowledge/contact-templates.d.ts +27 -0
  113. package/dist/knowledge/contact-templates.js +1 -0
  114. package/dist/knowledge/demand-confirm.js +1 -206
  115. package/dist/knowledge/demand-matching.js +1 -132
  116. package/dist/knowledge/demand-risk.js +1 -240
  117. package/dist/knowledge/demand-translation.js +1 -354
  118. package/dist/knowledge/deployment-scanner.js +1 -823
  119. package/dist/knowledge/dynamic-pricing.js +1 -87
  120. package/dist/knowledge/examples-scanner-cli.js +1 -26
  121. package/dist/knowledge/examples-scanner.js +1 -825
  122. package/dist/knowledge/flywheel-loop.js +1 -404
  123. package/dist/knowledge/fund-layer.js +1 -973
  124. package/dist/knowledge/glossary.js +1 -211
  125. package/dist/knowledge/guard-confirm.js +1 -406
  126. package/dist/knowledge/guard-context.js +1 -287
  127. package/dist/knowledge/guard-design-patterns.js +1 -360
  128. package/dist/knowledge/guard-ledger.js +1 -260
  129. package/dist/knowledge/guard-lint.js +1 -670
  130. package/dist/knowledge/guard-migration.js +1 -228
  131. package/dist/knowledge/guard-puzzle.js +1 -805
  132. package/dist/knowledge/guard-render.js +1 -700
  133. package/dist/knowledge/guard-risk.js +1 -1879
  134. package/dist/knowledge/guard-submission-prompt.js +1 -171
  135. package/dist/knowledge/guard-templates.js +1 -1105
  136. package/dist/knowledge/guard-translation.js +1 -1119
  137. package/dist/knowledge/index.js +1 -436
  138. package/dist/knowledge/industry-evolution.js +1 -323
  139. package/dist/knowledge/industry-generalizer.js +1 -381
  140. package/dist/knowledge/industry-registry.js +1 -174
  141. package/dist/knowledge/intent-metrics.d.ts +4 -3
  142. package/dist/knowledge/intent-metrics.js +1 -566
  143. package/dist/knowledge/machine-confirm.js +1 -559
  144. package/dist/knowledge/machine-context.js +1 -833
  145. package/dist/knowledge/machine-ledger.js +1 -338
  146. package/dist/knowledge/machine-puzzle.js +1 -494
  147. package/dist/knowledge/machine-render.js +1 -565
  148. package/dist/knowledge/machine-risk.js +1 -670
  149. package/dist/knowledge/machine-templates.js +1 -1597
  150. package/dist/knowledge/machine-topology.js +1 -234
  151. package/dist/knowledge/machine-translation.js +1 -513
  152. package/dist/knowledge/mcp-schema-audit-cli.js +1 -45
  153. package/dist/knowledge/mcp-schema-audit.d.ts +1 -1
  154. package/dist/knowledge/mcp-schema-audit.js +1 -773
  155. package/dist/knowledge/onchain-constants.js +1 -35
  156. package/dist/knowledge/order-confirm.js +1 -573
  157. package/dist/knowledge/order-context.js +1 -390
  158. package/dist/knowledge/order-ledger.js +1 -341
  159. package/dist/knowledge/order-puzzle.js +1 -255
  160. package/dist/knowledge/order-risk.js +1 -653
  161. package/dist/knowledge/order-templates.js +1 -368
  162. package/dist/knowledge/order-translation.js +1 -550
  163. package/dist/knowledge/overrides-loader.js +1 -65
  164. package/dist/knowledge/passport-confirm.js +1 -531
  165. package/dist/knowledge/passport-context.js +1 -306
  166. package/dist/knowledge/passport-ledger.js +1 -282
  167. package/dist/knowledge/passport-puzzle.js +1 -333
  168. package/dist/knowledge/passport-risk.js +1 -450
  169. package/dist/knowledge/passport-templates.js +1 -568
  170. package/dist/knowledge/passport-translation.js +1 -516
  171. package/dist/knowledge/payment-risk.js +1 -249
  172. package/dist/knowledge/permission-confirm.js +1 -426
  173. package/dist/knowledge/permission-context.js +1 -224
  174. package/dist/knowledge/permission-ledger.js +1 -403
  175. package/dist/knowledge/permission-puzzle.js +1 -173
  176. package/dist/knowledge/permission-risk.js +1 -411
  177. package/dist/knowledge/permission-templates.js +1 -234
  178. package/dist/knowledge/permission-translation.js +1 -350
  179. package/dist/knowledge/personal-risk.js +1 -212
  180. package/dist/knowledge/process-model.js +1 -160
  181. package/dist/knowledge/progress-confirm.js +1 -456
  182. package/dist/knowledge/progress-context.js +1 -452
  183. package/dist/knowledge/progress-ledger.js +1 -330
  184. package/dist/knowledge/progress-puzzle.js +1 -219
  185. package/dist/knowledge/progress-risk.js +1 -461
  186. package/dist/knowledge/progress-templates.js +1 -228
  187. package/dist/knowledge/progress-translation.js +1 -405
  188. package/dist/knowledge/proof-confirm.js +1 -187
  189. package/dist/knowledge/proof-risk.js +1 -207
  190. package/dist/knowledge/proof-translation.js +1 -283
  191. package/dist/knowledge/registrar-risk.js +1 -217
  192. package/dist/knowledge/repository-confirm.js +1 -286
  193. package/dist/knowledge/repository-risk.js +1 -373
  194. package/dist/knowledge/repository-translation.js +1 -445
  195. package/dist/knowledge/reputation-rules.js +1 -99
  196. package/dist/knowledge/resource-risk.js +1 -157
  197. package/dist/knowledge/reward-confirm.js +1 -526
  198. package/dist/knowledge/reward-context.js +1 -504
  199. package/dist/knowledge/reward-ledger.js +1 -502
  200. package/dist/knowledge/reward-puzzle.js +1 -300
  201. package/dist/knowledge/reward-risk.js +1 -627
  202. package/dist/knowledge/reward-templates.js +1 -197
  203. package/dist/knowledge/reward-translation.js +1 -501
  204. package/dist/knowledge/safety-rules.js +1 -404
  205. package/dist/knowledge/scenario-modes.js +1 -321
  206. package/dist/knowledge/service-confirm.js +1 -807
  207. package/dist/knowledge/service-context.js +1 -403
  208. package/dist/knowledge/service-ledger.js +1 -609
  209. package/dist/knowledge/service-puzzle.js +1 -236
  210. package/dist/knowledge/service-risk.js +1 -615
  211. package/dist/knowledge/service-templates.js +1 -456
  212. package/dist/knowledge/service-translation.js +1 -622
  213. package/dist/knowledge/template-registry.d.ts +1 -1
  214. package/dist/knowledge/template-registry.js +1 -341
  215. package/dist/knowledge/tool-constraints.js +1 -195
  216. package/dist/knowledge/tools-reference.js +1 -155
  217. package/dist/knowledge/treasury-confirm.js +1 -512
  218. package/dist/knowledge/treasury-context.js +1 -363
  219. package/dist/knowledge/treasury-ledger.js +1 -300
  220. package/dist/knowledge/treasury-puzzle.js +1 -216
  221. package/dist/knowledge/treasury-risk.js +1 -440
  222. package/dist/knowledge/treasury-templates.js +1 -358
  223. package/dist/knowledge/treasury-translation.js +1 -498
  224. package/dist/knowledge/trust-metrics.js +1 -198
  225. package/dist/knowledge/util-risk.js +1 -135
  226. package/dist/loop-engineering/aggregate.js +1 -132
  227. package/dist/loop-engineering/context-collect.js +1 -83
  228. package/dist/loop-engineering/diagnose.js +1 -273
  229. package/dist/loop-engineering/improve.js +1 -405
  230. package/dist/loop-engineering/index.js +1 -4
  231. package/dist/loop-engineering/pipeline.js +1 -56
  232. package/dist/mode-market/index.js +1 -3
  233. package/dist/mode-market/registry.js +1 -124
  234. package/dist/mode-market/review.js +1 -214
  235. package/dist/mode-market/submission.js +1 -85
  236. package/dist/participation/collaborator-interest.d.ts +23 -0
  237. package/dist/participation/collaborator-interest.js +1 -0
  238. package/dist/participation/customer-interest.d.ts +25 -0
  239. package/dist/participation/customer-interest.js +1 -0
  240. package/dist/participation/merchant-interest.js +1 -100
  241. package/dist/participation/radar-core.d.ts +13 -3
  242. package/dist/participation/radar-core.js +1 -269
  243. package/dist/participation/supplier-interest.d.ts +25 -0
  244. package/dist/participation/supplier-interest.js +1 -0
  245. package/dist/persona/analyzer.d.ts +16 -0
  246. package/dist/persona/analyzer.js +1 -0
  247. package/dist/persona/bridge.d.ts +5 -0
  248. package/dist/persona/bridge.js +1 -0
  249. package/dist/persona/defaults.d.ts +4 -0
  250. package/dist/persona/defaults.js +1 -0
  251. package/dist/persona/experience-bridge.d.ts +3 -0
  252. package/dist/persona/experience-bridge.js +1 -0
  253. package/dist/persona/index.d.ts +18 -0
  254. package/dist/persona/index.js +1 -0
  255. package/dist/persona/model.d.ts +7 -0
  256. package/dist/persona/model.js +1 -0
  257. package/dist/persona/store.d.ts +19 -0
  258. package/dist/persona/store.js +1 -0
  259. package/dist/persona/types.d.ts +45 -0
  260. package/dist/persona/types.js +1 -0
  261. package/dist/project/business-puzzle.js +1 -383
  262. package/dist/project/context-assembly.js +1 -254
  263. package/dist/project/deployment-bridge.js +1 -120
  264. package/dist/project/deployment-doc.js +1 -1126
  265. package/dist/project/edit-planner.js +1 -1342
  266. package/dist/project/evaluation.js +1 -2011
  267. package/dist/project/game-theory.js +1 -177
  268. package/dist/project/graph-builder.js +1 -656
  269. package/dist/project/graph.js +1 -340
  270. package/dist/project/handlers.d.ts +5 -0
  271. package/dist/project/handlers.js +1 -1762
  272. package/dist/project/index.d.ts +1 -0
  273. package/dist/project/index.js +1 -301
  274. package/dist/project/intent-analyzer.js +1 -149
  275. package/dist/project/machine-nodes.js +1 -36
  276. package/dist/project/merchant-guide.js +1 -264
  277. package/dist/project/migration.js +1 -125
  278. package/dist/project/mode-actions.js +1 -309
  279. package/dist/project/namespace.js +1 -206
  280. package/dist/project/participation-radar.js +1 -428
  281. package/dist/project/pipeline-actions.js +1 -109
  282. package/dist/project/project-store.js +1 -422
  283. package/dist/project/query.js +1 -153
  284. package/dist/project/reverse-mapping.d.ts +34 -0
  285. package/dist/project/reverse-mapping.js +1 -0
  286. package/dist/project/risk-aggregator.js +1 -295
  287. package/dist/project/rollback-policy.js +1 -290
  288. package/dist/project/semantic-assembler.js +1 -345
  289. package/dist/project/semantic-graph.js +1 -245
  290. package/dist/project/stage-gate.js +1 -369
  291. package/dist/project/substep-trace.js +1 -332
  292. package/dist/project/task-tracker.js +1 -78
  293. package/dist/role/derivation.d.ts +18 -0
  294. package/dist/role/derivation.js +1 -0
  295. package/dist/role/index.d.ts +5 -0
  296. package/dist/role/index.js +1 -0
  297. package/dist/role/model.d.ts +8 -0
  298. package/dist/role/model.js +1 -0
  299. package/dist/role/resolution.d.ts +11 -0
  300. package/dist/role/resolution.js +1 -0
  301. package/dist/role/types.d.ts +11 -0
  302. package/dist/role/types.js +1 -0
  303. package/dist/rules.d.ts +2 -0
  304. package/dist/rules.js +1 -9
  305. package/dist/safety/confirm-gate.js +1 -88
  306. package/dist/safety/index.js +1 -3
  307. package/dist/safety/preview.js +1 -52
  308. package/dist/schema/call/allocation.js +1 -34
  309. package/dist/schema/call/arbitration.js +1 -113
  310. package/dist/schema/call/base.d.ts +15 -15
  311. package/dist/schema/call/base.js +1 -370
  312. package/dist/schema/call/bridge-handler.js +1 -265
  313. package/dist/schema/call/bridge.d.ts +7 -7
  314. package/dist/schema/call/bridge.js +1 -458
  315. package/dist/schema/call/contact.js +1 -37
  316. package/dist/schema/call/demand.js +1 -47
  317. package/dist/schema/call/guard.js +1 -161
  318. package/dist/schema/call/handler.js +1 -322
  319. package/dist/schema/call/index.js +1 -20
  320. package/dist/schema/call/machine.js +1 -193
  321. package/dist/schema/call/order.js +1 -35
  322. package/dist/schema/call/payment.js +1 -37
  323. package/dist/schema/call/permission-handler.js +1 -54
  324. package/dist/schema/call/permission.js +1 -105
  325. package/dist/schema/call/personal.js +1 -78
  326. package/dist/schema/call/progress.js +1 -47
  327. package/dist/schema/call/proof.js +1 -33
  328. package/dist/schema/call/repository.js +1 -77
  329. package/dist/schema/call/reward.js +1 -30
  330. package/dist/schema/call/semantic.js +1 -1657
  331. package/dist/schema/call/service.js +1 -178
  332. package/dist/schema/call/treasury.js +1 -71
  333. package/dist/schema/common/index.js +1 -407
  334. package/dist/schema/config/index.js +1 -68
  335. package/dist/schema/evaluation/index.d.ts +4436 -0
  336. package/dist/schema/evaluation/index.js +1 -0
  337. package/dist/schema/index.d.ts +4 -0
  338. package/dist/schema/index.js +1 -13
  339. package/dist/schema/intent-radar/index.d.ts +284 -0
  340. package/dist/schema/intent-radar/index.js +1 -0
  341. package/dist/schema/local/index.d.ts +21 -21
  342. package/dist/schema/local/index.js +1 -927
  343. package/dist/schema/local/wip.js +1 -187
  344. package/dist/schema/messenger/index.d.ts +7 -7
  345. package/dist/schema/messenger/index.js +1 -475
  346. package/dist/schema/operations.d.ts +7 -7
  347. package/dist/schema/operations.js +1 -520
  348. package/dist/schema/persona/index.d.ts +1985 -0
  349. package/dist/schema/persona/index.js +1 -0
  350. package/dist/schema/project/index.d.ts +96 -50
  351. package/dist/schema/project/index.js +1 -2057
  352. package/dist/schema/query/index.d.ts +423 -7
  353. package/dist/schema/query/index.js +1 -1640
  354. package/dist/schema/schema-query/index.js +1 -104
  355. package/dist/schema/schema-version.js +1 -76
  356. package/dist/schema/sync-layer4.d.ts +1 -1
  357. package/dist/schema/sync-layer4.js +1 -282
  358. package/dist/schema/task-status.d.ts +168 -0
  359. package/dist/schema/task-status.js +1 -0
  360. package/dist/schema/trust/index.js +1 -314
  361. package/dist/schema/utils/guard-parser.js +1 -419
  362. package/dist/schema/utils/guard-query-utils.js +1 -46
  363. package/dist/schema/utils/node-parser.js +1 -369
  364. package/dist/schema/utils/object-type-utils.js +1 -35
  365. package/dist/schema/utils/permission-index-utils.js +1 -7
  366. package/dist/schema/utils/permission-machine-check.js +1 -121
  367. package/dist/schema/utils/skills-recommendation.js +1 -77
  368. package/dist/schema-query/index.js +1 -810
  369. package/dist/schemas/account_operation.output.json +5 -2
  370. package/dist/schemas/bridge_operation.output.json +5 -2
  371. package/dist/schemas/evaluation_operation.output.json +782 -0
  372. package/dist/schemas/evaluation_operation.schema.json +990 -0
  373. package/dist/schemas/index.json +25 -1
  374. package/dist/schemas/intent_radar.output.json +232 -0
  375. package/dist/schemas/intent_radar.schema.json +138 -0
  376. package/dist/schemas/local_info_operation.output.json +5 -2
  377. package/dist/schemas/local_mark_operation.output.json +5 -2
  378. package/dist/schemas/messenger_operation.output.json +5 -2
  379. package/dist/schemas/onchain_events.output.json +5 -2
  380. package/dist/schemas/onchain_operations.output.json +5 -2
  381. package/dist/schemas/onchain_operations.schema.json +6 -6
  382. package/dist/schemas/onchain_operations_allocation.schema.json +1 -1
  383. package/dist/schemas/onchain_operations_machine.schema.json +2 -2
  384. package/dist/schemas/onchain_operations_service.schema.json +3 -3
  385. package/dist/schemas/onchain_table_data.output.json +6 -3
  386. package/dist/schemas/persona_operation.output.json +392 -0
  387. package/dist/schemas/persona_operation.schema.json +250 -0
  388. package/dist/schemas/project_operation.output.json +28 -8
  389. package/dist/schemas/query_task_status.output.json +115 -0
  390. package/dist/schemas/query_task_status.schema.json +24 -0
  391. package/dist/schemas/query_toolkit.output.json +9 -6
  392. package/dist/schemas/trust_score.schema.json +1 -1
  393. package/dist/schemas/wowok_buildin_info.output.json +132 -0
  394. package/dist/schemas/wowok_buildin_info.schema.json +14 -0
  395. package/dist/telemetry/index.js +1 -112
  396. package/dist/telemetry/redact.js +1 -23
  397. package/dist/telemetry/storage.js +1 -80
  398. package/dist/tools/handlers/bridge.js +1 -1
  399. package/dist/tools/handlers/config.js +1 -74
  400. package/dist/tools/handlers/evaluation.d.ts +2 -0
  401. package/dist/tools/handlers/evaluation.js +1 -0
  402. package/dist/tools/handlers/file-export.js +1 -90
  403. package/dist/tools/handlers/intent-radar.d.ts +2 -0
  404. package/dist/tools/handlers/intent-radar.js +1 -0
  405. package/dist/tools/handlers/local.js +1 -53
  406. package/dist/tools/handlers/messenger.js +1 -188
  407. package/dist/tools/handlers/onchain.js +1 -1082
  408. package/dist/tools/handlers/persona.d.ts +4 -0
  409. package/dist/tools/handlers/persona.js +1 -0
  410. package/dist/tools/handlers/project.js +1 -211
  411. package/dist/tools/handlers/query.js +1 -434
  412. package/dist/tools/handlers/schema-query.js +1 -176
  413. package/dist/tools/handlers/task-status.d.ts +0 -168
  414. package/dist/tools/handlers/task-status.js +1 -55
  415. package/dist/tools/handlers/trust.js +1 -380
  416. package/dist/tools/handlers/wip.js +1 -90
  417. package/dist/tools/index.js +1 -1306
  418. package/dist/tools/retry.js +1 -85
  419. package/dist/tools/rules-hook.js +1 -23
  420. package/dist/tools/shared.js +1 -130
  421. package/dist/tools/types.js +1 -1
  422. package/dist/tools/upgrade-check.d.ts +19 -0
  423. package/dist/tools/upgrade-check.js +1 -0
  424. package/dist/tools/wip-deploy-assist.d.ts +1 -1
  425. package/dist/tools/wip-deploy-assist.js +1 -278
  426. package/dist/tools/wrap.js +1 -500
  427. package/package.json +5 -3
@@ -1,805 +1 @@
1
- import { MAX_SUBMISSION_SIZE_PASSPORT } from "@wowok/wowok";
2
- export function checkPuzzleCompleteness(puzzle) {
3
- const dimensions = {
4
- intent: isIntentComplete(puzzle.intent),
5
- binding: isBindingComplete(puzzle.binding),
6
- data_sources: isDataSourcesComplete(puzzle.data_sources),
7
- query: isQueryComplete(puzzle.queries),
8
- logic: isLogicComplete(puzzle.logic),
9
- constraints: isConstraintsComplete(puzzle.constraints),
10
- };
11
- const missing = Object.keys(dimensions).filter((k) => !dimensions[k]);
12
- const missing_details = [];
13
- if (!dimensions.intent) {
14
- missing_details.push("A. Intent: protected action, validation rule, or failure conditions not clarified");
15
- }
16
- if (!dimensions.binding) {
17
- missing_details.push("B. Binding: Host Object, binding field, or circular reference mode not determined");
18
- }
19
- if (!dimensions.data_sources) {
20
- missing_details.push("C. Data sources: data sources not declared by 4 classifications (on-chain constant / witness-derived / submitted object / system context)");
21
- }
22
- if (!dimensions.query) {
23
- missing_details.push("D. Query: query instruction not determined (if the Guard needs to query on-chain data)");
24
- }
25
- if (!dimensions.logic) {
26
- missing_details.push("E. Logic: computation tree root or rely composition not designed");
27
- }
28
- if (!dimensions.constraints) {
29
- missing_details.push("F. Constraints: creation-time 10 + runtime 6 constraint checks not completed");
30
- }
31
- const complete = missing.length === 0;
32
- const next_step = recommendNextStep(puzzle, missing);
33
- return { dimensions, missing, missing_details, complete, next_step };
34
- }
35
- function isIntentComplete(intent) {
36
- return !!intent && !!intent.action && !!intent.rule_sentence && intent.failure_conditions.length > 0;
37
- }
38
- function isBindingComplete(binding) {
39
- return !!binding && !!binding.host_object && !!binding.binding_field;
40
- }
41
- function isDataSourcesComplete(data_sources) {
42
- if (!data_sources)
43
- return false;
44
- const hasType1 = data_sources.on_chain_constants.length > 0;
45
- const hasType2 = data_sources.witness_derived.length > 0;
46
- const hasType3Obj = data_sources.submitted_objects.length > 0;
47
- const hasType3Val = data_sources.submitted_values.length > 0;
48
- const hasType4 = data_sources.system_contexts.length > 0;
49
- if (!hasType1 && !hasType2 && !hasType3Obj && !hasType3Val && !hasType4) {
50
- return false;
51
- }
52
- const unboundedSubmission = data_sources.submitted_objects.some((e) => !e.binding_constraint);
53
- if (unboundedSubmission)
54
- return false;
55
- return true;
56
- }
57
- function isQueryComplete(queries) {
58
- return true;
59
- }
60
- function isLogicComplete(logic) {
61
- return !!logic && !!logic.root && logic.root.return_type === "Bool";
62
- }
63
- function isConstraintsComplete(constraints) {
64
- if (!constraints)
65
- return false;
66
- return Object.values(constraints).every((v) => v === true);
67
- }
68
- function recommendNextStep(puzzle, missing) {
69
- if (missing.includes("intent")) {
70
- return {
71
- round: "R1",
72
- action: "Capture validation intent",
73
- questions: [
74
- "What action do you want to protect? (buy/forward/claim/vote/dispute/write/allocate)",
75
- "Describe the validation rule in one sentence",
76
- "List the conditions under which the Guard should FAIL",
77
- ],
78
- };
79
- }
80
- if (missing.includes("binding")) {
81
- return {
82
- round: "R5",
83
- action: "Determine binding target",
84
- questions: [
85
- "Which Host Object will the Guard bind to? (Service/Machine/Arbitration/Reward/Repository)",
86
- "Which field will it bind to? (buy_guard/order_allocators/Forward.guard/...)",
87
- "Does the Guard need to reference the Host Object? (circular reference mode)",
88
- ],
89
- };
90
- }
91
- if (missing.includes("data_sources")) {
92
- return {
93
- round: "R2",
94
- action: "Declare data sources by 4 classifications",
95
- questions: [
96
- "Type1 (on-chain constant): Which already-published on-chain objects does the Guard need to query? (Service/Machine/Reward addresses)",
97
- "Type2 (witness-derived): Do you need to derive Progress/Machine/Service from Order/Arb? (choose witness 100-108)",
98
- "Type3 (submitted object): Which object addresses does the caller need to submit? (Order/Reward/Progress) — constraint rules must be designed",
99
- "Type3 (submitted value): Which scalar values does the caller need to submit? (amount/weight/node name)",
100
- "Type4 (system context): Do you need Signer (identity) / Clock (time) / Guard (self-reference)?",
101
- "Do you need to query EntityRegistrar(0xaab) or EntityLinker(0xaaa)?",
102
- ],
103
- };
104
- }
105
- if (missing.includes("query")) {
106
- return {
107
- round: "R3",
108
- action: "Design query nodes",
109
- questions: [
110
- "Which on-chain objects does the Guard need to query?",
111
- "Which instruction ID does each query use? (look up from GUARDQUERY)",
112
- "Do you need convert_witness to convert objects? (linked to Type2 declaration)",
113
- ],
114
- };
115
- }
116
- if (missing.includes("logic")) {
117
- return {
118
- round: "R3",
119
- action: "Design computation tree",
120
- questions: [
121
- "What is the root node? (must return Bool)",
122
- "Which data source nodes are there? (by 4 classifications: identifier/context/query)",
123
- "Which intermediate conversion nodes are there? (calc_*/convert_*/vec_*)",
124
- "Do you need rely to compose with other Guards?",
125
- ],
126
- };
127
- }
128
- if (missing.includes("constraints")) {
129
- return {
130
- round: "R6",
131
- action: "Pre-creation review",
132
- questions: ["Run the creation-time 10 + runtime 6 constraint checklist"],
133
- };
134
- }
135
- return {
136
- round: "R7",
137
- action: "Prepare for on-chain creation",
138
- questions: ["All dimensions are complete; ready to generate the semantic confirmation text"],
139
- };
140
- }
141
- export function generateConfirmationText(puzzle) {
142
- if (!puzzle.intent || !puzzle.binding || !puzzle.data_sources || !puzzle.logic) {
143
- return "[Puzzle incomplete] Cannot generate confirmation text; please complete all dimensions first";
144
- }
145
- const lines = [];
146
- lines.push("═══════════════════════════════════════════════════════");
147
- lines.push(" Guard Semantic Confirmation Report (User Review Edition)");
148
- lines.push("═══════════════════════════════════════════════════════");
149
- lines.push("");
150
- lines.push("[Intent]");
151
- lines.push(`Protected action: ${puzzle.intent.action}`);
152
- lines.push(`Validation rule: ${puzzle.intent.rule_sentence}`);
153
- lines.push("Failure conditions:");
154
- puzzle.intent.failure_conditions.forEach((c, i) => {
155
- lines.push(` ${i + 1}. ${c}`);
156
- });
157
- lines.push("");
158
- lines.push("[Binding]");
159
- lines.push(`Host Object: ${puzzle.binding.host_object}`);
160
- if (puzzle.binding.host_object_name) {
161
- lines.push(`Host Object name: ${puzzle.binding.host_object_name}`);
162
- }
163
- lines.push(`Binding field: ${puzzle.binding.binding_field}`);
164
- lines.push(`Circular reference: ${puzzle.binding.circular_reference ? "Yes (Guard references Host Object)" : "No"}`);
165
- lines.push(`Host Object state: ${puzzle.binding.host_object_state}`);
166
- lines.push("");
167
- lines.push("[Data sources (4 classifications)]");
168
- printDataSources(lines, puzzle.data_sources);
169
- lines.push("");
170
- if (puzzle.queries && puzzle.queries.length > 0) {
171
- lines.push("[Query instructions]");
172
- lines.push("┌──────┬──────────────────────────┬────────────┬──────────┬──────────┐");
173
- lines.push("│ ID │ Query instruction │ Target obj │ Params │ Return │");
174
- lines.push("├──────┼──────────────────────────┼────────────┼──────────┼──────────┤");
175
- puzzle.queries.forEach((q) => {
176
- const id = String(q.query_id).padEnd(4);
177
- const name = q.query_name.length > 24 ? q.query_name.slice(0, 23) + "…" : q.query_name.padEnd(24);
178
- const obj = q.object_type.padEnd(10);
179
- const params = (q.parameters.length === 0 ? "(none)" : q.parameters.join(",")).padEnd(8);
180
- const ret = q.return_type.padEnd(8);
181
- lines.push(`│ ${id} │ ${name} │ ${obj} │ ${params} │ ${ret} │`);
182
- });
183
- lines.push("└──────┴──────────────────────────┴────────────┴──────────┴──────────┘");
184
- lines.push("");
185
- }
186
- lines.push("[Computation tree]");
187
- lines.push(`root: ${puzzle.logic.root.node_type} (returns: ${puzzle.logic.root.return_type})`);
188
- lines.push(` ${puzzle.logic.root.description}`);
189
- if (puzzle.logic.root.children) {
190
- printLogicTree(lines, puzzle.logic.root.children, 1);
191
- }
192
- lines.push("");
193
- if (puzzle.logic.rely) {
194
- lines.push("[rely composition]");
195
- lines.push(`Dependent Guards: ${puzzle.logic.rely.guards.join(", ")}`);
196
- lines.push(`Logic: ${puzzle.logic.rely.logic_or ? "OR (any passes)" : "AND (all must pass)"}`);
197
- lines.push(`rep verification: ${puzzle.logic.rely.rep_verified.every((v) => v) ? "all passed" : "some unverified"}`);
198
- lines.push("");
199
- }
200
- if (puzzle.constraints) {
201
- lines.push("[Constraint checklist (creation-time 22 + runtime 11 = 33; MCP layer static check 16)]");
202
- const creationChecks = [
203
- ["01", "All identifiers exist in the table", puzzle.constraints.pitfall_01_identifiers_in_table],
204
- ["02", "Comparison node types are compatible", puzzle.constraints.pitfall_02_type_compatibility],
205
- ["03", "Query instruction ID and parameter count are correct", puzzle.constraints.pitfall_03_query_instruction_valid],
206
- ["04", "convert_witness type is correct", puzzle.constraints.pitfall_04_witness_correct],
207
- ["05", "Time-lock tests use small values", puzzle.constraints.pitfall_05_time_lock_test_safe],
208
- ["06", "Old Guard exported before iteration", puzzle.constraints.pitfall_06_exported_before_recreate],
209
- ["07", "root returns Bool", puzzle.constraints.pitfall_07_root_returns_bool],
210
- ["08", "rely dependency rep=true", puzzle.constraints.pitfall_08_rely_rep_true],
211
- ["09", "voting_guard GuardIdentifier numeric", puzzle.constraints.pitfall_09_voting_weight_numeric],
212
- ["10", "Arbitration not paused", puzzle.constraints.pitfall_10_arbitration_not_paused],
213
- ];
214
- const runtimeChecks = [
215
- ["R1", "Guard immutable=true to verify", puzzle.constraints.runtime_01_guard_immutable],
216
- ["R2", "submission type bytes match table declaration", puzzle.constraints.runtime_02_submission_type_match],
217
- ["R3", "b_submission=true entry found in submission", puzzle.constraints.runtime_03_submission_complete],
218
- ["R4", `submission total bytes ≤ ${MAX_SUBMISSION_SIZE_PASSPORT}`, puzzle.constraints.runtime_04_submission_size],
219
- ["R5", "witness derivation source object has related field", puzzle.constraints.runtime_05_witness_source_valid],
220
- ["R6", "query target object exists and types match", puzzle.constraints.runtime_06_query_object_valid],
221
- ];
222
- lines.push(" Creation-time constraints:");
223
- creationChecks.forEach(([num, desc, pass]) => {
224
- lines.push(` ${pass ? "✓" : "✗"} [${num}] ${desc}`);
225
- });
226
- lines.push(" Runtime constraints:");
227
- runtimeChecks.forEach(([num, desc, pass]) => {
228
- lines.push(` ${pass ? "✓" : "✗"} [${num}] ${desc}`);
229
- });
230
- lines.push("");
231
- }
232
- lines.push("[Risk warnings]");
233
- lines.push(" ⚠ Guard cannot be modified or deleted after creation (CREATE-only)");
234
- lines.push(" ⚠ On-chain execution will consume gas");
235
- lines.push(" ⚠ To modify after creation: export → edit → create new → rebind");
236
- lines.push("");
237
- lines.push("[Test plan (gen_passport static test)]");
238
- lines.push(" Expected pass scenario: submit data meeting conditions → PASS → Passport generated");
239
- lines.push(" Expected fail scenario: submit data not meeting conditions → FAIL → verify logic direction");
240
- lines.push("");
241
- lines.push("[Post-creation actions (important)]");
242
- lines.push(" 1. Use guard2file to export the Guard backup (JSON file) for later rebuild or migration");
243
- lines.push(" 2. Record the Guard object ID for subsequent binding and invocation");
244
- lines.push(" 3. If the Guard binds to a Host Object, ensure the Host Object is published after Guard creation");
245
- lines.push(" 4. Verify the Guard logic direction via gen_passport static test");
246
- lines.push("");
247
- const allCreationPass = creationChecksForReadiness(puzzle);
248
- lines.push("[Creation readiness signal]");
249
- lines.push(` Puzzle completeness: ${allCreationPass ? "✓ All passed — ready for on-chain CREATE" : "✗ Some items not passed — please fix first"}`);
250
- lines.push("");
251
- lines.push("═══════════════════════════════════════════════════════");
252
- lines.push(" Please review the Guard semantic confirmation report above");
253
- lines.push(" After confirming no issues, reply \"confirm creation\" to execute on-chain CREATE");
254
- lines.push(" If modifications are needed, please point out the parts to adjust");
255
- lines.push("═══════════════════════════════════════════════════════");
256
- return lines.join("\n");
257
- }
258
- function creationChecksForReadiness(puzzle) {
259
- if (!puzzle.intent || !puzzle.binding || !puzzle.data_sources || !puzzle.logic || !puzzle.constraints) {
260
- return false;
261
- }
262
- const c = puzzle.constraints;
263
- const creationPass = c.pitfall_01_identifiers_in_table &&
264
- c.pitfall_02_type_compatibility &&
265
- c.pitfall_03_query_instruction_valid &&
266
- c.pitfall_04_witness_correct &&
267
- c.pitfall_05_time_lock_test_safe &&
268
- c.pitfall_06_exported_before_recreate &&
269
- c.pitfall_07_root_returns_bool &&
270
- c.pitfall_08_rely_rep_true &&
271
- c.pitfall_09_voting_weight_numeric &&
272
- c.pitfall_10_arbitration_not_paused;
273
- const runtimePass = c.runtime_01_guard_immutable &&
274
- c.runtime_02_submission_type_match &&
275
- c.runtime_03_submission_complete &&
276
- c.runtime_04_submission_size &&
277
- c.runtime_05_witness_source_valid &&
278
- c.runtime_06_query_object_valid;
279
- return creationPass && runtimePass;
280
- }
281
- function printDataSources(lines, ds) {
282
- if (ds.on_chain_constants.length > 0) {
283
- lines.push(" Type1 — On-chain constant objects (OnChainConstant, b_submission=false):");
284
- ds.on_chain_constants.forEach((e) => {
285
- const sysMark = e.is_system_address ? " [system address]" : "";
286
- lines.push(` [id=${e.identifier}] ${e.object_type}(${e.object_address})${sysMark} — ${e.name}`);
287
- });
288
- }
289
- if (ds.witness_derived.length > 0) {
290
- lines.push(" Type2 — Witness-derived objects (WitnessDerived, convert_witness 100-108):");
291
- ds.witness_derived.forEach((e) => {
292
- const srcKind = e.source_b_submission ? "submitted" : "constant";
293
- lines.push(` [id=${e.identifier}] ${e.source_type}(${srcKind}) → ${e.target_type} via ${e.witness_name}(${e.witness_type}) — ${e.name}`);
294
- });
295
- }
296
- if (ds.submitted_objects.length > 0) {
297
- lines.push(" Type3 — Submitted objects (SubmittedObject, b_submission=true):");
298
- ds.submitted_objects.forEach((e) => {
299
- lines.push(` [id=${e.identifier}] ${e.expected_object_type}(${e.value_type}) — ${e.name}`);
300
- if (e.binding_constraint) {
301
- lines.push(` Constraint: ${e.binding_constraint}`);
302
- }
303
- });
304
- }
305
- if (ds.submitted_values.length > 0) {
306
- lines.push(" Type3 — Submitted values (SubmittedValue, b_submission=true, scalar):");
307
- ds.submitted_values.forEach((e) => {
308
- lines.push(` [id=${e.identifier}] ${e.value_type} — ${e.name}`);
309
- if (e.binding_constraint) {
310
- lines.push(` Constraint: ${e.binding_constraint}`);
311
- }
312
- });
313
- }
314
- if (ds.system_contexts.length > 0) {
315
- lines.push(" Type4 — System contexts (SystemContext, not in table):");
316
- ds.system_contexts.forEach((e) => {
317
- lines.push(` context(${e.context_type}) — ${e.usage}`);
318
- });
319
- }
320
- if (ds.on_chain_constants.length === 0 &&
321
- ds.witness_derived.length === 0 &&
322
- ds.submitted_objects.length === 0 &&
323
- ds.submitted_values.length === 0 &&
324
- ds.system_contexts.length === 0) {
325
- lines.push(" (No data sources declared)");
326
- }
327
- }
328
- function printLogicTree(lines, nodes, depth) {
329
- const indent = " ".repeat(depth + 1);
330
- nodes.forEach((node, i) => {
331
- const prefix = i === nodes.length - 1 ? "└── " : "├── ";
332
- lines.push(`${indent}${prefix}${node.node_type} (${node.return_type}) — ${node.description}`);
333
- if (node.references_identifier !== undefined) {
334
- lines.push(`${indent} → table[${node.references_identifier}]`);
335
- }
336
- if (node.query) {
337
- lines.push(`${indent} → query(${node.query.query_id}: ${node.query.query_name})`);
338
- }
339
- if (node.children) {
340
- printLogicTree(lines, node.children, depth + 1);
341
- }
342
- });
343
- }
344
- export function initPuzzleFromIntent(intent) {
345
- return {
346
- current_round: "R1",
347
- intent: {
348
- action: intent.action ?? "custom",
349
- rule_sentence: intent.rule_sentence ?? "",
350
- failure_conditions: intent.failure_conditions ?? [],
351
- },
352
- };
353
- }
354
- export function inferBindingFromAction(action) {
355
- const map = {
356
- buy: { host_object: "Service", binding_field: "buy_guard" },
357
- forward: { host_object: "Machine", binding_field: "Forward.guard" },
358
- allocate: { host_object: "Service", binding_field: "order_allocators" },
359
- claim_reward: { host_object: "Reward", binding_field: "guard" },
360
- vote: { host_object: "Arbitration", binding_field: "voting_guard" },
361
- dispute: { host_object: "Arbitration", binding_field: "usage_guard" },
362
- write_repository: { host_object: "Repository", binding_field: "write_guard" },
363
- submit_progress: { host_object: "Progress", binding_field: "submission" },
364
- gen_passport: { host_object: "Standalone", binding_field: "none" },
365
- custom: {},
366
- };
367
- return map[action] ?? {};
368
- }
369
- export function emptyDataSources() {
370
- return {
371
- on_chain_constants: [],
372
- witness_derived: [],
373
- submitted_objects: [],
374
- submitted_values: [],
375
- system_contexts: [],
376
- };
377
- }
378
- export const WITNESS_NAME_MAP = {
379
- 100: { name: "TypeOrderProgress", source: "Order", target: "Progress" },
380
- 101: { name: "TypeOrderMachine", source: "Order", target: "Machine" },
381
- 102: { name: "TypeOrderService", source: "Order", target: "Service" },
382
- 103: { name: "TypeProgressMachine", source: "Progress", target: "Machine" },
383
- 104: { name: "TypeArbOrder", source: "Arb", target: "Order" },
384
- 105: { name: "TypeArbArbitration", source: "Arb", target: "Arbitration" },
385
- 106: { name: "TypeArbProgress", source: "Arb", target: "Progress" },
386
- 107: { name: "TypeArbMachine", source: "Arb", target: "Machine" },
387
- 108: { name: "TypeArbService", source: "Arb", target: "Service" },
388
- };
389
- export function getWitnessInfo(witness_type) {
390
- return WITNESS_NAME_MAP[witness_type];
391
- }
392
- function traverseRoot(node, collectors) {
393
- if (!node)
394
- return;
395
- if (node.type === "identifier" && typeof node.identifier === "number") {
396
- collectors.referencedIdentifiers.add(node.identifier);
397
- }
398
- if (node.type === "context" && node.context) {
399
- collectors.contexts.add(node.context);
400
- }
401
- if (node.type === "query" && node.object) {
402
- const objId = node.object.identifier;
403
- collectors.referencedIdentifiers.add(objId);
404
- const witnessCode = node.object.convert_witness;
405
- if (typeof witnessCode === "number" && witnessCode >= 100 && witnessCode <= 108) {
406
- collectors.witnessCodes.push({ code: witnessCode, objectIdentifier: objId });
407
- }
408
- collectors.queries.push({
409
- query: node.query ?? "",
410
- objectIdentifier: objId,
411
- convertWitness: witnessCode,
412
- parametersCount: node.parameters?.length ?? 0,
413
- });
414
- if (node.parameters) {
415
- for (const param of node.parameters) {
416
- traverseRoot(param, collectors);
417
- }
418
- }
419
- }
420
- if (node.nodes) {
421
- for (const child of node.nodes) {
422
- traverseRoot(child, collectors);
423
- }
424
- }
425
- if (node.node) {
426
- traverseRoot(node.node, collectors);
427
- }
428
- if (node.nodeLeft) {
429
- traverseRoot(node.nodeLeft, collectors);
430
- }
431
- if (node.nodeRight) {
432
- traverseRoot(node.nodeRight, collectors);
433
- }
434
- }
435
- function buildLogicTree(node) {
436
- if (!node)
437
- return undefined;
438
- const logicNode = {
439
- node_type: node.type,
440
- return_type: inferNodeType(node.type),
441
- description: describeNode(node),
442
- };
443
- if (node.type === "identifier" && typeof node.identifier === "number") {
444
- logicNode.references_identifier = node.identifier;
445
- }
446
- if (node.type === "query" && node.object) {
447
- logicNode.query = {
448
- query_id: typeof node.query === "number" ? node.query : 0,
449
- query_name: typeof node.query === "string" ? node.query : String(node.query ?? ""),
450
- object_type: "",
451
- parameters: [],
452
- return_type: "",
453
- purpose: "",
454
- };
455
- if (node.object.convert_witness) {
456
- const wInfo = getWitnessInfo(node.object.convert_witness);
457
- if (wInfo) {
458
- logicNode.query.witness = {
459
- witness_type: node.object.convert_witness,
460
- witness_name: wInfo.name,
461
- source_type: wInfo.source,
462
- target_type: wInfo.target,
463
- scenario: "",
464
- };
465
- }
466
- }
467
- }
468
- if (node.nodes) {
469
- const children = node.nodes
470
- .map((c) => buildLogicTree(c))
471
- .filter((c) => c !== undefined);
472
- if (children.length > 0) {
473
- logicNode.children = children;
474
- }
475
- }
476
- if (node.node) {
477
- const child = buildLogicTree(node.node);
478
- if (child) {
479
- logicNode.children = [child];
480
- }
481
- }
482
- if (node.nodeLeft) {
483
- const child = buildLogicTree(node.nodeLeft);
484
- if (child) {
485
- logicNode.children = [...(logicNode.children ?? []), child];
486
- }
487
- }
488
- if (node.nodeRight) {
489
- const child = buildLogicTree(node.nodeRight);
490
- if (child) {
491
- logicNode.children = [...(logicNode.children ?? []), child];
492
- }
493
- }
494
- return logicNode;
495
- }
496
- function inferNodeType(nodeType) {
497
- const boolTypes = [
498
- "logic_equal", "logic_not", "logic_and", "logic_or",
499
- "logic_as_u256_greater", "logic_as_u256_lesser", "logic_as_u256_equal",
500
- "logic_as_u256_greater_or_equal", "logic_as_u256_lesser_or_equal",
501
- "logic_string_contains", "logic_string_nocase_contains", "logic_string_nocase_equal",
502
- "calc_string_contains", "calc_string_nocase_contains", "calc_string_nocase_equal",
503
- "vec_contains_bool", "vec_contains_address", "vec_contains_string",
504
- "vec_contains_string_nocase", "vec_contains_number",
505
- "query_reward_record_exists",
506
- ];
507
- if (boolTypes.includes(nodeType))
508
- return "Bool";
509
- const u256Types = [
510
- "calc_number_add", "calc_number_subtract", "calc_number_multiply",
511
- "calc_number_divide", "calc_number_mod",
512
- "convert_address_number", "convert_string_number",
513
- ];
514
- if (u256Types.includes(nodeType))
515
- return "U256";
516
- const u64Types = [
517
- "calc_string_length", "calc_string_indexof", "calc_string_nocase_indexof",
518
- "vec_length", "vec_indexof_bool", "vec_indexof_address", "vec_indexof_string",
519
- "vec_indexof_string_nocase", "vec_indexof_number",
520
- "query_reward_record_count",
521
- "query_progress_history_session_count",
522
- "query_progress_history_session_forward_count",
523
- "query_progress_history_session_forward_retained_submission_count",
524
- ];
525
- if (u64Types.includes(nodeType))
526
- return "U64";
527
- const addressTypes = ["convert_number_address"];
528
- if (addressTypes.includes(nodeType))
529
- return "Address";
530
- const stringTypes = ["convert_number_string"];
531
- if (stringTypes.includes(nodeType))
532
- return "String";
533
- const safeTypes = ["convert_safe_u8", "convert_safe_u16", "convert_safe_u32", "convert_safe_u64", "convert_safe_u128", "convert_safe_u256"];
534
- if (safeTypes.includes(nodeType)) {
535
- return nodeType.replace("convert_safe_", "U");
536
- }
537
- if (nodeType === "value_type")
538
- return "U8";
539
- if (nodeType === "query")
540
- return "query_defined";
541
- if (nodeType === "identifier")
542
- return "table_defined";
543
- if (nodeType === "context")
544
- return "context_defined";
545
- return "unknown";
546
- }
547
- function describeNode(node) {
548
- switch (node.type) {
549
- case "identifier":
550
- return `Reference to table[${node.identifier ?? "?"}]`;
551
- case "context":
552
- return `System context: ${node.context ?? "?"}`;
553
- case "query":
554
- return `Query instruction ${node.query ?? "?"} (target: table[${node.object?.identifier ?? "?"}])`;
555
- case "logic_equal":
556
- return "Equality comparison (==)";
557
- case "logic_not":
558
- return "Logical NOT (!)";
559
- case "logic_and":
560
- return "Logical AND";
561
- case "logic_or":
562
- return "Logical OR";
563
- case "logic_as_u256_greater":
564
- return "Numeric greater than (>)";
565
- case "logic_as_u256_lesser":
566
- return "Numeric less than (<)";
567
- case "logic_as_u256_equal":
568
- return "Numeric equality (==)";
569
- case "logic_as_u256_greater_or_equal":
570
- return "Numeric greater than or equal (>=)";
571
- case "logic_as_u256_lesser_or_equal":
572
- return "Numeric less than or equal (<=)";
573
- case "calc_number_add":
574
- return "Numeric addition (+)";
575
- case "calc_number_subtract":
576
- return "Numeric subtraction (-)";
577
- case "calc_number_multiply":
578
- return "Numeric multiplication (*)";
579
- case "calc_number_divide":
580
- return "Numeric division (/)";
581
- case "calc_number_mod":
582
- return "Numeric modulo (%)";
583
- case "vec_contains_address":
584
- return "Whitelist check (vec_contains_address)";
585
- case "vec_length":
586
- return "Vector length";
587
- case "convert_safe_u64":
588
- return "Safe conversion to U64";
589
- default:
590
- return node.type;
591
- }
592
- }
593
- function deriveConstraints(table, root, rely, collectors) {
594
- const pitfall01 = Array.from(collectors.referencedIdentifiers).every((id) => table.some((t) => t.identifier === id));
595
- const pitfall02 = root !== undefined;
596
- const pitfall03 = true;
597
- const pitfall04 = collectors.witnessCodes.every((w) => w.code >= 100 && w.code <= 108);
598
- const pitfall05 = true;
599
- const pitfall06 = true;
600
- const pitfall07 = root !== undefined;
601
- const pitfall08 = rely ? rely.guards.length <= 4 : true;
602
- const pitfall09 = true;
603
- const pitfall10 = true;
604
- const runtime01 = true;
605
- const runtime02 = true;
606
- const runtime03 = true;
607
- const submissionEntries = table.filter((t) => t.b_submission);
608
- const runtime04 = submissionEntries.length <= MAX_SUBMISSION_SIZE_PASSPORT;
609
- const runtime05 = true;
610
- const runtime06 = true;
611
- return {
612
- pitfall_01_identifiers_in_table: pitfall01,
613
- pitfall_02_type_compatibility: pitfall02,
614
- pitfall_03_query_instruction_valid: pitfall03,
615
- pitfall_04_witness_correct: pitfall04,
616
- pitfall_05_time_lock_test_safe: pitfall05,
617
- pitfall_06_exported_before_recreate: pitfall06,
618
- pitfall_07_root_returns_bool: pitfall07,
619
- pitfall_08_rely_rep_true: pitfall08,
620
- pitfall_09_voting_weight_numeric: pitfall09,
621
- pitfall_10_arbitration_not_paused: pitfall10,
622
- runtime_01_guard_immutable: runtime01,
623
- runtime_02_submission_type_match: runtime02,
624
- runtime_03_submission_complete: runtime03,
625
- runtime_04_submission_size: runtime04,
626
- runtime_05_witness_source_valid: runtime05,
627
- runtime_06_query_object_valid: runtime06,
628
- };
629
- }
630
- export function derivePuzzleFromCallData(input) {
631
- const table = input.table ?? [];
632
- const root = input.root;
633
- const rely = input.rely;
634
- const bindingHint = input.binding_hint;
635
- const collectors = {
636
- referencedIdentifiers: new Set(),
637
- queries: [],
638
- contexts: new Set(),
639
- witnessCodes: [],
640
- };
641
- if (root) {
642
- traverseRoot(root, collectors);
643
- }
644
- let intent;
645
- if (bindingHint) {
646
- intent = {
647
- action: bindingHint.action,
648
- rule_sentence: bindingHint.rule_sentence ?? "",
649
- failure_conditions: bindingHint.failure_conditions ?? [],
650
- };
651
- }
652
- let binding;
653
- if (bindingHint) {
654
- binding = {
655
- host_object: bindingHint.host_object,
656
- binding_field: bindingHint.binding_field,
657
- circular_reference: bindingHint.circular_reference ?? false,
658
- host_object_state: "unknown",
659
- };
660
- }
661
- const witnessCodesByIdentifier = new Map();
662
- for (const w of collectors.witnessCodes) {
663
- witnessCodesByIdentifier.set(w.objectIdentifier, w.code);
664
- }
665
- const onChainConstants = [];
666
- const witnessDerived = [];
667
- const submittedObjects = [];
668
- const submittedValues = [];
669
- for (const item of table) {
670
- const isReferencedByQuery = collectors.referencedIdentifiers.has(item.identifier);
671
- const witnessCode = witnessCodesByIdentifier.get(item.identifier);
672
- if (witnessCode !== undefined) {
673
- const wInfo = getWitnessInfo(witnessCode);
674
- if (wInfo) {
675
- witnessDerived.push({
676
- identifier: item.identifier,
677
- source_type: wInfo.source,
678
- witness_type: witnessCode,
679
- witness_name: wInfo.name,
680
- target_type: wInfo.target,
681
- source_b_submission: item.b_submission,
682
- name: item.name || `${wInfo.source}→${wInfo.target} via ${wInfo.name}`,
683
- });
684
- continue;
685
- }
686
- }
687
- if (!item.b_submission) {
688
- const valueStr = typeof item.value === "string" ? item.value.toLowerCase() : "";
689
- const isSystemAddr = valueStr === "0xaab" || valueStr === "0xaaa";
690
- onChainConstants.push({
691
- identifier: item.identifier,
692
- object_address: typeof item.value === "string" ? item.value : String(item.value ?? ""),
693
- object_type: item.object_type ?? "",
694
- name: item.name || `constant #${item.identifier}`,
695
- is_system_address: isSystemAddr,
696
- });
697
- }
698
- else {
699
- const valueTypeStr = typeof item.value_type === "string"
700
- ? item.value_type.toLowerCase()
701
- : String(item.value_type);
702
- if (valueTypeStr === "address") {
703
- submittedObjects.push({
704
- identifier: item.identifier,
705
- expected_object_type: item.object_type ?? "",
706
- value_type: "Address",
707
- name: item.name || `submitted object #${item.identifier}`,
708
- binding_constraint: item.object_type
709
- ? `must be an on-chain object address of type ${item.object_type}`
710
- : "must be a valid on-chain object address",
711
- });
712
- }
713
- else {
714
- submittedValues.push({
715
- identifier: item.identifier,
716
- value_type: typeof item.value_type === "string" ? item.value_type : String(item.value_type),
717
- name: item.name || `submitted value #${item.identifier}`,
718
- binding_constraint: `value type must be ${item.value_type}`,
719
- });
720
- }
721
- }
722
- }
723
- const systemContexts = [];
724
- for (const ctxType of collectors.contexts) {
725
- const usageMap = {
726
- Signer: "Current transaction signer address verification",
727
- Clock: "On-chain timestamp (used for time-lock/time-window)",
728
- Guard: "Guard self object ID self-reference",
729
- };
730
- systemContexts.push({
731
- context_type: ctxType,
732
- usage: usageMap[ctxType] ?? "",
733
- });
734
- }
735
- const dataSources = {
736
- on_chain_constants: onChainConstants,
737
- witness_derived: witnessDerived,
738
- submitted_objects: submittedObjects,
739
- submitted_values: submittedValues,
740
- system_contexts: systemContexts,
741
- };
742
- const queries = collectors.queries.map((q) => {
743
- const wInfo = q.convertWitness !== undefined ? getWitnessInfo(q.convertWitness) : undefined;
744
- return {
745
- query_id: typeof q.query === "number" ? q.query : 0,
746
- query_name: typeof q.query === "string" ? q.query : String(q.query),
747
- object_type: "",
748
- parameters: [],
749
- return_type: "",
750
- witness: wInfo ? {
751
- witness_type: q.convertWitness,
752
- witness_name: wInfo.name,
753
- source_type: wInfo.source,
754
- target_type: wInfo.target,
755
- scenario: "",
756
- } : undefined,
757
- purpose: "",
758
- };
759
- });
760
- let logic;
761
- if (root) {
762
- const logicRoot = buildLogicTree(root);
763
- if (logicRoot) {
764
- logicRoot.return_type = "Bool";
765
- let logicRely;
766
- if (rely && rely.guards.length > 0) {
767
- logicRely = {
768
- guards: rely.guards,
769
- logic_or: rely.logic_or ?? false,
770
- rep_verified: rely.guards.map(() => true),
771
- };
772
- }
773
- logic = { root: logicRoot, rely: logicRely };
774
- }
775
- }
776
- const constraints = deriveConstraints(table, root, rely, collectors);
777
- const puzzle = {
778
- current_round: "R7",
779
- intent,
780
- binding,
781
- data_sources: dataSources,
782
- queries,
783
- logic,
784
- constraints,
785
- };
786
- return puzzle;
787
- }
788
- export function getPuzzleStatusBooleans(puzzle) {
789
- const completeness = checkPuzzleCompleteness(puzzle);
790
- return {
791
- intent: completeness.dimensions.intent,
792
- binding: completeness.dimensions.binding,
793
- data: completeness.dimensions.data_sources,
794
- query: completeness.dimensions.query,
795
- logic: completeness.dimensions.logic,
796
- constraints: completeness.dimensions.constraints,
797
- };
798
- }
799
- export function getPendingQuestions(puzzle) {
800
- const completeness = checkPuzzleCompleteness(puzzle);
801
- if (completeness.complete) {
802
- return [];
803
- }
804
- return completeness.next_step.questions;
805
- }
1
+ import{MAX_SUBMISSION_SIZE_PASSPORT}from'@wowok/wowok';export function checkPuzzleCompleteness(a){const b={'intent':isIntentComplete(a['intent']),'binding':isBindingComplete(a['binding']),'data_sources':isDataSourcesComplete(a['data_sources']),'query':isQueryComplete(a['queries']),'logic':isLogicComplete(a['logic']),'constraints':isConstraintsComplete(a['constraints'])},c=Object['keys'](b)['filter'](g=>!b[g]),d=[];!b['intent']&&d['push']('A.\x20Intent:\x20protected\x20action,\x20validation\x20rule,\x20or\x20failure\x20conditions\x20not\x20clarified');!b['binding']&&d['push']('B.\x20Binding:\x20Host\x20Object,\x20binding\x20field,\x20or\x20circular\x20reference\x20mode\x20not\x20determined');!b['data_sources']&&d['push']('C.\x20Data\x20sources:\x20data\x20sources\x20not\x20declared\x20by\x204\x20classifications\x20(on-chain\x20constant\x20/\x20witness-derived\x20/\x20submitted\x20object\x20/\x20system\x20context)');!b['query']&&d['push']('D.\x20Query:\x20query\x20instruction\x20not\x20determined\x20(if\x20the\x20Guard\x20needs\x20to\x20query\x20on-chain\x20data)');!b['logic']&&d['push']('E.\x20Logic:\x20computation\x20tree\x20root\x20or\x20rely\x20composition\x20not\x20designed');!b['constraints']&&d['push']('F.\x20Constraints:\x20creation-time\x2010\x20+\x20runtime\x206\x20constraint\x20checks\x20not\x20completed');const e=c['length']===0x0,f=recommendNextStep(a,c);return{'dimensions':b,'missing':c,'missing_details':d,'complete':e,'next_step':f};}function isIntentComplete(a){return!!a&&!!a['action']&&!!a['rule_sentence']&&a['failure_conditions']['length']>0x0;}function isBindingComplete(a){return!!a&&!!a['host_object']&&!!a['binding_field'];}function isDataSourcesComplete(a){if(!a)return![];const b=a['on_chain_constants']['length']>0x0,c=a['witness_derived']['length']>0x0,d=a['submitted_objects']['length']>0x0,e=a['submitted_values']['length']>0x0,f=a['system_contexts']['length']>0x0;if(!b&&!c&&!d&&!e&&!f)return![];const g=a['submitted_objects']['some'](h=>!h['binding_constraint']);if(g)return![];return!![];}function isQueryComplete(a){return!![];}function isLogicComplete(a){return!!a&&!!a['root']&&a['root']['return_type']==='Bool';}function isConstraintsComplete(a){if(!a)return![];return Object['values'](a)['every'](b=>b===!![]);}function recommendNextStep(a,b){if(b['includes']('intent'))return{'round':'R1','action':'Capture\x20validation\x20intent','questions':['What\x20action\x20do\x20you\x20want\x20to\x20protect?\x20(buy/forward/claim/vote/dispute/write/allocate)','Describe\x20the\x20validation\x20rule\x20in\x20one\x20sentence','List\x20the\x20conditions\x20under\x20which\x20the\x20Guard\x20should\x20FAIL']};if(b['includes']('binding'))return{'round':'R5','action':'Determine\x20binding\x20target','questions':['Which\x20Host\x20Object\x20will\x20the\x20Guard\x20bind\x20to?\x20(Service/Machine/Arbitration/Reward/Repository)','Which\x20field\x20will\x20it\x20bind\x20to?\x20(buy_guard/order_allocators/Forward.guard/...)','Does\x20the\x20Guard\x20need\x20to\x20reference\x20the\x20Host\x20Object?\x20(circular\x20reference\x20mode)']};if(b['includes']('data_sources'))return{'round':'R2','action':'Declare\x20data\x20sources\x20by\x204\x20classifications','questions':['Type1\x20(on-chain\x20constant):\x20Which\x20already-published\x20on-chain\x20objects\x20does\x20the\x20Guard\x20need\x20to\x20query?\x20(Service/Machine/Reward\x20addresses)','Type2\x20(witness-derived):\x20Do\x20you\x20need\x20to\x20derive\x20Progress/Machine/Service\x20from\x20Order/Arb?\x20(choose\x20witness\x20100-108)','Type3\x20(submitted\x20object):\x20Which\x20object\x20addresses\x20does\x20the\x20caller\x20need\x20to\x20submit?\x20(Order/Reward/Progress)\x20—\x20constraint\x20rules\x20must\x20be\x20designed','Type3\x20(submitted\x20value):\x20Which\x20scalar\x20values\x20does\x20the\x20caller\x20need\x20to\x20submit?\x20(amount/weight/node\x20name)','Type4\x20(system\x20context):\x20Do\x20you\x20need\x20Signer\x20(identity)\x20/\x20Clock\x20(time)\x20/\x20Guard\x20(self-reference)?','Do\x20you\x20need\x20to\x20query\x20EntityRegistrar(0xaab)\x20or\x20EntityLinker(0xaaa)?']};if(b['includes']('query'))return{'round':'R3','action':'Design\x20query\x20nodes','questions':['Which\x20on-chain\x20objects\x20does\x20the\x20Guard\x20need\x20to\x20query?','Which\x20instruction\x20ID\x20does\x20each\x20query\x20use?\x20(look\x20up\x20from\x20GUARDQUERY)','Do\x20you\x20need\x20convert_witness\x20to\x20convert\x20objects?\x20(linked\x20to\x20Type2\x20declaration)']};if(b['includes']('logic'))return{'round':'R3','action':'Design\x20computation\x20tree','questions':['What\x20is\x20the\x20root\x20node?\x20(must\x20return\x20Bool)','Which\x20data\x20source\x20nodes\x20are\x20there?\x20(by\x204\x20classifications:\x20identifier/context/query)','Which\x20intermediate\x20conversion\x20nodes\x20are\x20there?\x20(calc_*/convert_*/vec_*)','Do\x20you\x20need\x20rely\x20to\x20compose\x20with\x20other\x20Guards?']};if(b['includes']('constraints'))return{'round':'R6','action':'Pre-creation\x20review','questions':['Run\x20the\x20creation-time\x2010\x20+\x20runtime\x206\x20constraint\x20checklist']};return{'round':'R7','action':'Prepare\x20for\x20on-chain\x20creation','questions':['All\x20dimensions\x20are\x20complete;\x20ready\x20to\x20generate\x20the\x20semantic\x20confirmation\x20text']};}export function generateConfirmationText(a){if(!a['intent']||!a['binding']||!a['data_sources']||!a['logic'])return'[Puzzle\x20incomplete]\x20Cannot\x20generate\x20confirmation\x20text;\x20please\x20complete\x20all\x20dimensions\x20first';const b=[];b['push']('═══════════════════════════════════════════════════════'),b['push']('\x20\x20Guard\x20Semantic\x20Confirmation\x20Report\x20(User\x20Review\x20Edition)'),b['push']('═══════════════════════════════════════════════════════'),b['push'](''),b['push']('[Intent]'),b['push']('Protected\x20action:\x20'+a['intent']['action']),b['push']('Validation\x20rule:\x20'+a['intent']['rule_sentence']),b['push']('Failure\x20conditions:'),a['intent']['failure_conditions']['forEach']((d,e)=>{b['push']('\x20\x20'+(e+0x1)+'.\x20'+d);}),b['push'](''),b['push']('[Binding]'),b['push']('Host\x20Object:\x20'+a['binding']['host_object']);a['binding']['host_object_name']&&b['push']('Host\x20Object\x20name:\x20'+a['binding']['host_object_name']);b['push']('Binding\x20field:\x20'+a['binding']['binding_field']),b['push']('Circular\x20reference:\x20'+(a['binding']['circular_reference']?'Yes\x20(Guard\x20references\x20Host\x20Object)':'No')),b['push']('Host\x20Object\x20state:\x20'+a['binding']['host_object_state']),b['push'](''),b['push']('[Data\x20sources\x20(4\x20classifications)]'),printDataSources(b,a['data_sources']),b['push']('');a['queries']&&a['queries']['length']>0x0&&(b['push']('[Query\x20instructions]'),b['push']('┌──────┬──────────────────────────┬────────────┬──────────┬──────────┐'),b['push']('│\x20ID\x20\x20\x20│\x20Query\x20instruction\x20\x20\x20\x20\x20\x20\x20\x20│\x20Target\x20obj\x20│\x20Params\x20\x20\x20│\x20Return\x20\x20\x20│'),b['push']('├──────┼──────────────────────────┼────────────┼──────────┼──────────┤'),a['queries']['forEach'](d=>{const e=String(d['query_id'])['padEnd'](0x4),f=d['query_name']['length']>0x18?d['query_name']['slice'](0x0,0x17)+'…':d['query_name']['padEnd'](0x18),g=d['object_type']['padEnd'](0xa),h=(d['parameters']['length']===0x0?'(none)':d['parameters']['join'](','))['padEnd'](0x8),i=d['return_type']['padEnd'](0x8);b['push']('│\x20'+e+'\x20│\x20'+f+'\x20│\x20'+g+'\x20│\x20'+h+'\x20│\x20'+i+'\x20│');}),b['push']('└──────┴──────────────────────────┴────────────┴──────────┴──────────┘'),b['push'](''));b['push']('[Computation\x20tree]'),b['push']('root:\x20'+a['logic']['root']['node_type']+'\x20(returns:\x20'+a['logic']['root']['return_type']+')'),b['push']('\x20\x20'+a['logic']['root']['description']);a['logic']['root']['children']&&printLogicTree(b,a['logic']['root']['children'],0x1);b['push']('');a['logic']['rely']&&(b['push']('[rely\x20composition]'),b['push']('Dependent\x20Guards:\x20'+a['logic']['rely']['guards']['join'](',\x20')),b['push']('Logic:\x20'+(a['logic']['rely']['logic_or']?'OR\x20(any\x20passes)':'AND\x20(all\x20must\x20pass)')),b['push']('rep\x20verification:\x20'+(a['logic']['rely']['rep_verified']['every'](d=>d)?'all\x20passed':'some\x20unverified')),b['push'](''));if(a['constraints']){b['push']('[Constraint\x20checklist\x20(creation-time\x2022\x20+\x20runtime\x2011\x20=\x2033;\x20MCP\x20layer\x20static\x20check\x2016)]');const d=[['01','All\x20identifiers\x20exist\x20in\x20the\x20table',a['constraints']['pitfall_01_identifiers_in_table']],['02','Comparison\x20node\x20types\x20are\x20compatible',a['constraints']['pitfall_02_type_compatibility']],['03','Query\x20instruction\x20ID\x20and\x20parameter\x20count\x20are\x20correct',a['constraints']['pitfall_03_query_instruction_valid']],['04','convert_witness\x20type\x20is\x20correct',a['constraints']['pitfall_04_witness_correct']],['05','Time-lock\x20tests\x20use\x20small\x20values',a['constraints']['pitfall_05_time_lock_test_safe']],['06','Old\x20Guard\x20exported\x20before\x20iteration',a['constraints']['pitfall_06_exported_before_recreate']],['07','root\x20returns\x20Bool',a['constraints']['pitfall_07_root_returns_bool']],['08','rely\x20dependency\x20rep=true',a['constraints']['pitfall_08_rely_rep_true']],['09','voting_guard\x20GuardIdentifier\x20numeric',a['constraints']['pitfall_09_voting_weight_numeric']],['10','Arbitration\x20not\x20paused',a['constraints']['pitfall_10_arbitration_not_paused']]],e=[['R1','Guard\x20immutable=true\x20to\x20verify',a['constraints']['runtime_01_guard_immutable']],['R2','submission\x20type\x20bytes\x20match\x20table\x20declaration',a['constraints']['runtime_02_submission_type_match']],['R3','b_submission=true\x20entry\x20found\x20in\x20submission',a['constraints']['runtime_03_submission_complete']],['R4','submission\x20total\x20bytes\x20≤\x20'+MAX_SUBMISSION_SIZE_PASSPORT,a['constraints']['runtime_04_submission_size']],['R5','witness\x20derivation\x20source\x20object\x20has\x20related\x20field',a['constraints']['runtime_05_witness_source_valid']],['R6','query\x20target\x20object\x20exists\x20and\x20types\x20match',a['constraints']['runtime_06_query_object_valid']]];b['push']('\x20\x20Creation-time\x20constraints:'),d['forEach'](([f,g,h])=>{b['push']('\x20\x20'+(h?'✓':'✗')+'\x20['+f+']\x20'+g);}),b['push']('\x20\x20Runtime\x20constraints:'),e['forEach'](([f,g,h])=>{b['push']('\x20\x20'+(h?'✓':'✗')+'\x20['+f+']\x20'+g);}),b['push']('');}b['push']('[Risk\x20warnings]'),b['push']('\x20\x20⚠\x20Guard\x20cannot\x20be\x20modified\x20or\x20deleted\x20after\x20creation\x20(CREATE-only)'),b['push']('\x20\x20⚠\x20On-chain\x20execution\x20will\x20consume\x20gas'),b['push']('\x20\x20⚠\x20To\x20modify\x20after\x20creation:\x20export\x20→\x20edit\x20→\x20create\x20new\x20→\x20rebind'),b['push'](''),b['push']('[Test\x20plan\x20(gen_passport\x20static\x20test)]'),b['push']('\x20\x20Expected\x20pass\x20scenario:\x20submit\x20data\x20meeting\x20conditions\x20→\x20PASS\x20→\x20Passport\x20generated'),b['push']('\x20\x20Expected\x20fail\x20scenario:\x20submit\x20data\x20not\x20meeting\x20conditions\x20→\x20FAIL\x20→\x20verify\x20logic\x20direction'),b['push'](''),b['push']('[Post-creation\x20actions\x20(important)]'),b['push']('\x20\x201.\x20Use\x20guard2file\x20to\x20export\x20the\x20Guard\x20backup\x20(JSON\x20file)\x20for\x20later\x20rebuild\x20or\x20migration'),b['push']('\x20\x202.\x20Record\x20the\x20Guard\x20object\x20ID\x20for\x20subsequent\x20binding\x20and\x20invocation'),b['push']('\x20\x203.\x20If\x20the\x20Guard\x20binds\x20to\x20a\x20Host\x20Object,\x20ensure\x20the\x20Host\x20Object\x20is\x20published\x20after\x20Guard\x20creation'),b['push']('\x20\x204.\x20Verify\x20the\x20Guard\x20logic\x20direction\x20via\x20gen_passport\x20static\x20test'),b['push']('');const c=creationChecksForReadiness(a);return b['push']('[Creation\x20readiness\x20signal]'),b['push']('\x20\x20Puzzle\x20completeness:\x20'+(c?'✓\x20All\x20passed\x20—\x20ready\x20for\x20on-chain\x20CREATE':'✗\x20Some\x20items\x20not\x20passed\x20—\x20please\x20fix\x20first')),b['push'](''),b['push']('═══════════════════════════════════════════════════════'),b['push']('\x20\x20Please\x20review\x20the\x20Guard\x20semantic\x20confirmation\x20report\x20above'),b['push']('\x20\x20After\x20confirming\x20no\x20issues,\x20reply\x20\x22confirm\x20creation\x22\x20to\x20execute\x20on-chain\x20CREATE'),b['push']('\x20\x20If\x20modifications\x20are\x20needed,\x20please\x20point\x20out\x20the\x20parts\x20to\x20adjust'),b['push']('═══════════════════════════════════════════════════════'),b['join']('\x0a');}function creationChecksForReadiness(a){if(!a['intent']||!a['binding']||!a['data_sources']||!a['logic']||!a['constraints'])return![];const b=a['constraints'],d=b['pitfall_01_identifiers_in_table']&&b['pitfall_02_type_compatibility']&&b['pitfall_03_query_instruction_valid']&&b['pitfall_04_witness_correct']&&b['pitfall_05_time_lock_test_safe']&&b['pitfall_06_exported_before_recreate']&&b['pitfall_07_root_returns_bool']&&b['pitfall_08_rely_rep_true']&&b['pitfall_09_voting_weight_numeric']&&b['pitfall_10_arbitration_not_paused'],e=b['runtime_01_guard_immutable']&&b['runtime_02_submission_type_match']&&b['runtime_03_submission_complete']&&b['runtime_04_submission_size']&&b['runtime_05_witness_source_valid']&&b['runtime_06_query_object_valid'];return d&&e;}function printDataSources(a,b){b['on_chain_constants']['length']>0x0&&(a['push']('\x20\x20Type1\x20—\x20On-chain\x20constant\x20objects\x20(OnChainConstant,\x20b_submission=false):'),b['on_chain_constants']['forEach'](c=>{const d=c['is_system_address']?'\x20[system\x20address]':'';a['push']('\x20\x20\x20\x20[id='+c['identifier']+']\x20'+c['object_type']+'('+c['object_address']+')'+d+'\x20—\x20'+c['name']);})),b['witness_derived']['length']>0x0&&(a['push']('\x20\x20Type2\x20—\x20Witness-derived\x20objects\x20(WitnessDerived,\x20convert_witness\x20100-108):'),b['witness_derived']['forEach'](c=>{const d=c['source_b_submission']?'submitted':'constant';a['push']('\x20\x20\x20\x20[id='+c['identifier']+']\x20'+c['source_type']+'('+d+')\x20→\x20'+c['target_type']+'\x20via\x20'+c['witness_name']+'('+c['witness_type']+')\x20—\x20'+c['name']);})),b['submitted_objects']['length']>0x0&&(a['push']('\x20\x20Type3\x20—\x20Submitted\x20objects\x20(SubmittedObject,\x20b_submission=true):'),b['submitted_objects']['forEach'](c=>{a['push']('\x20\x20\x20\x20[id='+c['identifier']+']\x20'+c['expected_object_type']+'('+c['value_type']+')\x20—\x20'+c['name']),c['binding_constraint']&&a['push']('\x20\x20\x20\x20\x20\x20Constraint:\x20'+c['binding_constraint']);})),b['submitted_values']['length']>0x0&&(a['push']('\x20\x20Type3\x20—\x20Submitted\x20values\x20(SubmittedValue,\x20b_submission=true,\x20scalar):'),b['submitted_values']['forEach'](c=>{a['push']('\x20\x20\x20\x20[id='+c['identifier']+']\x20'+c['value_type']+'\x20—\x20'+c['name']),c['binding_constraint']&&a['push']('\x20\x20\x20\x20\x20\x20Constraint:\x20'+c['binding_constraint']);})),b['system_contexts']['length']>0x0&&(a['push']('\x20\x20Type4\x20—\x20System\x20contexts\x20(SystemContext,\x20not\x20in\x20table):'),b['system_contexts']['forEach'](c=>{a['push']('\x20\x20\x20\x20context('+c['context_type']+')\x20—\x20'+c['usage']);})),b['on_chain_constants']['length']===0x0&&b['witness_derived']['length']===0x0&&b['submitted_objects']['length']===0x0&&b['submitted_values']['length']===0x0&&b['system_contexts']['length']===0x0&&a['push']('\x20\x20(No\x20data\x20sources\x20declared)');}function printLogicTree(a,b,c){const d='\x20\x20'['repeat'](c+0x1);b['forEach']((e,f)=>{const g=f===b['length']-0x1?'└──\x20':'├──\x20';a['push'](''+d+g+e['node_type']+'\x20('+e['return_type']+')\x20—\x20'+e['description']),e['references_identifier']!==undefined&&a['push'](d+'\x20\x20\x20\x20→\x20table['+e['references_identifier']+']'),e['query']&&a['push'](d+'\x20\x20\x20\x20→\x20query('+e['query']['query_id']+':\x20'+e['query']['query_name']+')'),e['children']&&printLogicTree(a,e['children'],c+0x1);});}export function initPuzzleFromIntent(a){return{'current_round':'R1','intent':{'action':a['action']??'custom','rule_sentence':a['rule_sentence']??'','failure_conditions':a['failure_conditions']??[]}};}export function inferBindingFromAction(a){const b={'buy':{'host_object':'Service','binding_field':'buy_guard'},'forward':{'host_object':'Machine','binding_field':'Forward.guard'},'allocate':{'host_object':'Service','binding_field':'order_allocators'},'claim_reward':{'host_object':'Reward','binding_field':'guard'},'vote':{'host_object':'Arbitration','binding_field':'voting_guard'},'dispute':{'host_object':'Arbitration','binding_field':'usage_guard'},'write_repository':{'host_object':'Repository','binding_field':'write_guard'},'submit_progress':{'host_object':'Progress','binding_field':'submission'},'gen_passport':{'host_object':'Standalone','binding_field':'none'},'custom':{}};return b[a]??{};}export function emptyDataSources(){return{'on_chain_constants':[],'witness_derived':[],'submitted_objects':[],'submitted_values':[],'system_contexts':[]};}export const WITNESS_NAME_MAP={0x64:{'name':'TypeOrderProgress','source':'Order','target':'Progress'},0x65:{'name':'TypeOrderMachine','source':'Order','target':'Machine'},0x66:{'name':'TypeOrderService','source':'Order','target':'Service'},0x67:{'name':'TypeProgressMachine','source':'Progress','target':'Machine'},0x68:{'name':'TypeArbOrder','source':'Arb','target':'Order'},0x69:{'name':'TypeArbArbitration','source':'Arb','target':'Arbitration'},0x6a:{'name':'TypeArbProgress','source':'Arb','target':'Progress'},0x6b:{'name':'TypeArbMachine','source':'Arb','target':'Machine'},0x6c:{'name':'TypeArbService','source':'Arb','target':'Service'}};export function getWitnessInfo(a){return WITNESS_NAME_MAP[a];}function traverseRoot(a,b){if(!a)return;a['type']==='identifier'&&typeof a['identifier']==='number'&&b['referencedIdentifiers']['add'](a['identifier']);a['type']==='context'&&a['context']&&b['contexts']['add'](a['context']);if(a['type']==='query'&&a['object']){const c=a['object']['identifier'];b['referencedIdentifiers']['add'](c);const d=a['object']['convert_witness'];typeof d==='number'&&d>=0x64&&d<=0x6c&&b['witnessCodes']['push']({'code':d,'objectIdentifier':c});b['queries']['push']({'query':a['query']??'','objectIdentifier':c,'convertWitness':d,'parametersCount':a['parameters']?.['length']??0x0});if(a['parameters'])for(const e of a['parameters']){traverseRoot(e,b);}}if(a['nodes'])for(const f of a['nodes']){traverseRoot(f,b);}a['node']&&traverseRoot(a['node'],b),a['nodeLeft']&&traverseRoot(a['nodeLeft'],b),a['nodeRight']&&traverseRoot(a['nodeRight'],b);}function buildLogicTree(a){if(!a)return undefined;const b={'node_type':a['type'],'return_type':inferNodeType(a['type']),'description':describeNode(a)};a['type']==='identifier'&&typeof a['identifier']==='number'&&(b['references_identifier']=a['identifier']);if(a['type']==='query'&&a['object']){b['query']={'query_id':typeof a['query']==='number'?a['query']:0x0,'query_name':typeof a['query']==='string'?a['query']:String(a['query']??''),'object_type':'','parameters':[],'return_type':'','purpose':''};if(a['object']['convert_witness']){const c=getWitnessInfo(a['object']['convert_witness']);c&&(b['query']['witness']={'witness_type':a['object']['convert_witness'],'witness_name':c['name'],'source_type':c['source'],'target_type':c['target'],'scenario':''});}}if(a['nodes']){const d=a['nodes']['map'](e=>buildLogicTree(e))['filter'](e=>e!==undefined);d['length']>0x0&&(b['children']=d);}if(a['node']){const e=buildLogicTree(a['node']);e&&(b['children']=[e]);}if(a['nodeLeft']){const f=buildLogicTree(a['nodeLeft']);f&&(b['children']=[...b['children']??[],f]);}if(a['nodeRight']){const g=buildLogicTree(a['nodeRight']);g&&(b['children']=[...b['children']??[],g]);}return b;}function inferNodeType(a){const b=['logic_equal','logic_not','logic_and','logic_or','logic_as_u256_greater','logic_as_u256_lesser','logic_as_u256_equal','logic_as_u256_greater_or_equal','logic_as_u256_lesser_or_equal','logic_string_contains','logic_string_nocase_contains','logic_string_nocase_equal','calc_string_contains','calc_string_nocase_contains','calc_string_nocase_equal','vec_contains_bool','vec_contains_address','vec_contains_string','vec_contains_string_nocase','vec_contains_number','query_reward_record_exists'];if(b['includes'](a))return'Bool';const c=['calc_number_add','calc_number_subtract','calc_number_multiply','calc_number_divide','calc_number_mod','convert_address_number','convert_string_number'];if(c['includes'](a))return'U256';const d=['calc_string_length','calc_string_indexof','calc_string_nocase_indexof','vec_length','vec_indexof_bool','vec_indexof_address','vec_indexof_string','vec_indexof_string_nocase','vec_indexof_number','query_reward_record_count','query_progress_history_session_count','query_progress_history_session_forward_count','query_progress_history_session_forward_retained_submission_count'];if(d['includes'](a))return'U64';const e=['convert_number_address'];if(e['includes'](a))return'Address';const f=['convert_number_string'];if(f['includes'](a))return'String';const g=['convert_safe_u8','convert_safe_u16','convert_safe_u32','convert_safe_u64','convert_safe_u128','convert_safe_u256'];if(g['includes'](a))return a['replace']('convert_safe_','U');if(a==='value_type')return'U8';if(a==='query')return'query_defined';if(a==='identifier')return'table_defined';if(a==='context')return'context_defined';return'unknown';}function describeNode(a){switch(a['type']){case'identifier':return'Reference\x20to\x20table['+(a['identifier']??'?')+']';case'context':return'System\x20context:\x20'+(a['context']??'?');case'query':return'Query\x20instruction\x20'+(a['query']??'?')+'\x20(target:\x20table['+(a['object']?.['identifier']??'?')+'])';case'logic_equal':return'Equality\x20comparison\x20(==)';case'logic_not':return'Logical\x20NOT\x20(!)';case'logic_and':return'Logical\x20AND';case'logic_or':return'Logical\x20OR';case'logic_as_u256_greater':return'Numeric\x20greater\x20than\x20(>)';case'logic_as_u256_lesser':return'Numeric\x20less\x20than\x20(<)';case'logic_as_u256_equal':return'Numeric\x20equality\x20(==)';case'logic_as_u256_greater_or_equal':return'Numeric\x20greater\x20than\x20or\x20equal\x20(>=)';case'logic_as_u256_lesser_or_equal':return'Numeric\x20less\x20than\x20or\x20equal\x20(<=)';case'calc_number_add':return'Numeric\x20addition\x20(+)';case'calc_number_subtract':return'Numeric\x20subtraction\x20(-)';case'calc_number_multiply':return'Numeric\x20multiplication\x20(*)';case'calc_number_divide':return'Numeric\x20division\x20(/)';case'calc_number_mod':return'Numeric\x20modulo\x20(%)';case'vec_contains_address':return'Whitelist\x20check\x20(vec_contains_address)';case'vec_length':return'Vector\x20length';case'convert_safe_u64':return'Safe\x20conversion\x20to\x20U64';default:return a['type'];}}function deriveConstraints(a,b,c,d){const e=Array['from'](d['referencedIdentifiers'])['every'](v=>a['some'](w=>w['identifier']===v)),f=b!==undefined,g=!![],h=d['witnessCodes']['every'](v=>v['code']>=0x64&&v['code']<=0x6c),i=!![],j=!![],k=b!==undefined,l=c?c['guards']['length']<=0x4:!![],m=!![],n=!![],o=!![],p=!![],q=!![],r=a['filter'](v=>v['b_submission']),s=r['length']<=MAX_SUBMISSION_SIZE_PASSPORT,t=!![],u=!![];return{'pitfall_01_identifiers_in_table':e,'pitfall_02_type_compatibility':f,'pitfall_03_query_instruction_valid':g,'pitfall_04_witness_correct':h,'pitfall_05_time_lock_test_safe':i,'pitfall_06_exported_before_recreate':j,'pitfall_07_root_returns_bool':k,'pitfall_08_rely_rep_true':l,'pitfall_09_voting_weight_numeric':m,'pitfall_10_arbitration_not_paused':n,'runtime_01_guard_immutable':o,'runtime_02_submission_type_match':p,'runtime_03_submission_complete':q,'runtime_04_submission_size':s,'runtime_05_witness_source_valid':t,'runtime_06_query_object_valid':u};}export function derivePuzzleFromCallData(a){const b=a['table']??[],c=a['root'],d=a['rely'],e=a['binding_hint'],f={'referencedIdentifiers':new Set(),'queries':[],'contexts':new Set(),'witnessCodes':[]};c&&traverseRoot(c,f);let g;e&&(g={'action':e['action'],'rule_sentence':e['rule_sentence']??'','failure_conditions':e['failure_conditions']??[]});let h;e&&(h={'host_object':e['host_object'],'binding_field':e['binding_field'],'circular_reference':e['circular_reference']??![],'host_object_state':'unknown'});const i=new Map();for(const t of f['witnessCodes']){i['set'](t['objectIdentifier'],t['code']);}const j=[],k=[],l=[],m=[];for(const u of b){const v=f['referencedIdentifiers']['has'](u['identifier']),x=i['get'](u['identifier']);if(x!==undefined){const y=getWitnessInfo(x);if(y){k['push']({'identifier':u['identifier'],'source_type':y['source'],'witness_type':x,'witness_name':y['name'],'target_type':y['target'],'source_b_submission':u['b_submission'],'name':u['name']||y['source']+'→'+y['target']+'\x20via\x20'+y['name']});continue;}}if(!u['b_submission']){const z=typeof u['value']==='string'?u['value']['toLowerCase']():'',A=z==='0xaab'||z==='0xaaa';j['push']({'identifier':u['identifier'],'object_address':typeof u['value']==='string'?u['value']:String(u['value']??''),'object_type':u['object_type']??'','name':u['name']||'constant\x20#'+u['identifier'],'is_system_address':A});}else{const B=typeof u['value_type']==='string'?u['value_type']['toLowerCase']():String(u['value_type']);B==='address'?l['push']({'identifier':u['identifier'],'expected_object_type':u['object_type']??'','value_type':'Address','name':u['name']||'submitted\x20object\x20#'+u['identifier'],'binding_constraint':u['object_type']?'must\x20be\x20an\x20on-chain\x20object\x20address\x20of\x20type\x20'+u['object_type']:'must\x20be\x20a\x20valid\x20on-chain\x20object\x20address'}):m['push']({'identifier':u['identifier'],'value_type':typeof u['value_type']==='string'?u['value_type']:String(u['value_type']),'name':u['name']||'submitted\x20value\x20#'+u['identifier'],'binding_constraint':'value\x20type\x20must\x20be\x20'+u['value_type']});}}const n=[];for(const C of f['contexts']){const D={'Signer':'Current\x20transaction\x20signer\x20address\x20verification','Clock':'On-chain\x20timestamp\x20(used\x20for\x20time-lock/time-window)','Guard':'Guard\x20self\x20object\x20ID\x20self-reference'};n['push']({'context_type':C,'usage':D[C]??''});}const o={'on_chain_constants':j,'witness_derived':k,'submitted_objects':l,'submitted_values':m,'system_contexts':n},p=f['queries']['map'](E=>{const F=E['convertWitness']!==undefined?getWitnessInfo(E['convertWitness']):undefined;return{'query_id':typeof E['query']==='number'?E['query']:0x0,'query_name':typeof E['query']==='string'?E['query']:String(E['query']),'object_type':'','parameters':[],'return_type':'','witness':F?{'witness_type':E['convertWitness'],'witness_name':F['name'],'source_type':F['source'],'target_type':F['target'],'scenario':''}:undefined,'purpose':''};});let q;if(c){const E=buildLogicTree(c);if(E){E['return_type']='Bool';let F;d&&d['guards']['length']>0x0&&(F={'guards':d['guards'],'logic_or':d['logic_or']??![],'rep_verified':d['guards']['map'](()=>!![])}),q={'root':E,'rely':F};}}const r=deriveConstraints(b,c,d,f),s={'current_round':'R7','intent':g,'binding':h,'data_sources':o,'queries':p,'logic':q,'constraints':r};return s;}export function getPuzzleStatusBooleans(a){const b=checkPuzzleCompleteness(a);return{'intent':b['dimensions']['intent'],'binding':b['dimensions']['binding'],'data':b['dimensions']['data_sources'],'query':b['dimensions']['query'],'logic':b['dimensions']['logic'],'constraints':b['dimensions']['constraints']};}export function getPendingQuestions(a){const b=checkPuzzleCompleteness(a);if(b['complete'])return[];return b['next_step']['questions'];}