@wowok/agent-mcp 2.4.1 → 2.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (348) hide show
  1. package/dist/config/runtime.d.ts +4 -0
  2. package/dist/config/runtime.js +29 -5
  3. package/dist/harness/auto-escalation.d.ts +27 -0
  4. package/dist/harness/auto-escalation.js +68 -0
  5. package/dist/index.d.ts +2 -2
  6. package/dist/index.js +29 -1621
  7. package/dist/knowledge/allocation-confirm.d.ts +115 -0
  8. package/dist/knowledge/allocation-confirm.js +534 -0
  9. package/dist/knowledge/allocation-context.d.ts +58 -0
  10. package/dist/knowledge/allocation-context.js +249 -0
  11. package/dist/knowledge/allocation-ledger.d.ts +67 -0
  12. package/dist/knowledge/allocation-ledger.js +463 -0
  13. package/dist/knowledge/allocation-puzzle.d.ts +135 -0
  14. package/dist/knowledge/allocation-puzzle.js +298 -0
  15. package/dist/knowledge/allocation-risk.d.ts +78 -0
  16. package/dist/knowledge/allocation-risk.js +568 -0
  17. package/dist/knowledge/allocation-templates.d.ts +38 -0
  18. package/dist/knowledge/allocation-templates.js +970 -0
  19. package/dist/knowledge/allocation-translation.d.ts +72 -0
  20. package/dist/knowledge/allocation-translation.js +585 -0
  21. package/dist/knowledge/arb-risk.d.ts +37 -0
  22. package/dist/knowledge/arb-risk.js +210 -0
  23. package/dist/knowledge/arbitration-confirm.d.ts +135 -0
  24. package/dist/knowledge/arbitration-confirm.js +559 -0
  25. package/dist/knowledge/arbitration-context.d.ts +81 -0
  26. package/dist/knowledge/arbitration-context.js +505 -0
  27. package/dist/knowledge/arbitration-ledger.d.ts +62 -0
  28. package/dist/knowledge/arbitration-ledger.js +521 -0
  29. package/dist/knowledge/arbitration-puzzle.d.ts +84 -0
  30. package/dist/knowledge/arbitration-puzzle.js +304 -0
  31. package/dist/knowledge/arbitration-risk.d.ts +112 -0
  32. package/dist/knowledge/arbitration-risk.js +433 -0
  33. package/dist/knowledge/arbitration-templates.d.ts +38 -0
  34. package/dist/knowledge/arbitration-templates.js +276 -0
  35. package/dist/knowledge/arbitration-translation.d.ts +91 -0
  36. package/dist/knowledge/arbitration-translation.js +487 -0
  37. package/dist/knowledge/bridge-risk.d.ts +36 -0
  38. package/dist/knowledge/bridge-risk.js +263 -0
  39. package/dist/knowledge/contact-risk.d.ts +32 -0
  40. package/dist/knowledge/contact-risk.js +200 -0
  41. package/dist/knowledge/demand-confirm.d.ts +32 -0
  42. package/dist/knowledge/demand-confirm.js +206 -0
  43. package/dist/knowledge/demand-risk.d.ts +30 -0
  44. package/dist/knowledge/demand-risk.js +240 -0
  45. package/dist/knowledge/demand-translation.d.ts +55 -0
  46. package/dist/knowledge/demand-translation.js +354 -0
  47. package/dist/knowledge/deployment-scanner.d.ts +63 -0
  48. package/dist/knowledge/deployment-scanner.js +762 -0
  49. package/dist/knowledge/examples-scanner-cli.d.ts +1 -0
  50. package/dist/knowledge/examples-scanner-cli.js +26 -0
  51. package/dist/knowledge/examples-scanner.d.ts +121 -0
  52. package/dist/knowledge/examples-scanner.js +825 -0
  53. package/dist/knowledge/flywheel-loop.d.ts +3 -0
  54. package/dist/knowledge/flywheel-loop.js +32 -3
  55. package/dist/knowledge/glossary.js +3 -1
  56. package/dist/knowledge/guard-confirm.d.ts +86 -0
  57. package/dist/knowledge/guard-confirm.js +406 -0
  58. package/dist/knowledge/guard-context.d.ts +56 -0
  59. package/dist/knowledge/guard-context.js +287 -0
  60. package/dist/knowledge/guard-design-patterns.d.ts +37 -0
  61. package/dist/knowledge/guard-design-patterns.js +257 -0
  62. package/dist/knowledge/guard-ledger.js +14 -0
  63. package/dist/knowledge/guard-lint.d.ts +1 -0
  64. package/dist/knowledge/guard-lint.js +83 -3
  65. package/dist/knowledge/guard-migration.d.ts +48 -0
  66. package/dist/knowledge/guard-migration.js +228 -0
  67. package/dist/knowledge/guard-puzzle.js +3 -2
  68. package/dist/knowledge/guard-risk.d.ts +3 -1
  69. package/dist/knowledge/guard-risk.js +832 -64
  70. package/dist/knowledge/guard-templates.d.ts +1 -0
  71. package/dist/knowledge/guard-templates.js +278 -2
  72. package/dist/knowledge/guard-translation.js +6 -5
  73. package/dist/knowledge/index.d.ts +342 -0
  74. package/dist/knowledge/index.js +344 -0
  75. package/dist/knowledge/machine-confirm.d.ts +102 -0
  76. package/dist/knowledge/machine-confirm.js +559 -0
  77. package/dist/knowledge/machine-context.d.ts +160 -0
  78. package/dist/knowledge/machine-context.js +812 -0
  79. package/dist/knowledge/machine-ledger.d.ts +41 -0
  80. package/dist/knowledge/machine-ledger.js +315 -0
  81. package/dist/knowledge/machine-puzzle.d.ts +206 -0
  82. package/dist/knowledge/machine-puzzle.js +494 -0
  83. package/dist/knowledge/machine-risk.d.ts +75 -0
  84. package/dist/knowledge/machine-risk.js +644 -0
  85. package/dist/knowledge/machine-templates.d.ts +92 -0
  86. package/dist/knowledge/machine-templates.js +1592 -0
  87. package/dist/knowledge/machine-topology.d.ts +57 -0
  88. package/dist/knowledge/machine-topology.js +234 -0
  89. package/dist/knowledge/machine-translation.d.ts +96 -0
  90. package/dist/knowledge/machine-translation.js +513 -0
  91. package/dist/knowledge/mcp-schema-audit-cli.d.ts +1 -0
  92. package/dist/knowledge/mcp-schema-audit-cli.js +45 -0
  93. package/dist/knowledge/mcp-schema-audit.d.ts +90 -0
  94. package/dist/knowledge/mcp-schema-audit.js +772 -0
  95. package/dist/knowledge/onchain-constants.d.ts +4 -0
  96. package/dist/knowledge/onchain-constants.js +35 -0
  97. package/dist/knowledge/order-confirm.d.ts +115 -0
  98. package/dist/knowledge/order-confirm.js +573 -0
  99. package/dist/knowledge/order-context.d.ts +66 -0
  100. package/dist/knowledge/order-context.js +390 -0
  101. package/dist/knowledge/order-ledger.d.ts +69 -0
  102. package/dist/knowledge/order-ledger.js +341 -0
  103. package/dist/knowledge/order-puzzle.d.ts +159 -0
  104. package/dist/knowledge/order-puzzle.js +255 -0
  105. package/dist/knowledge/order-risk.d.ts +66 -0
  106. package/dist/knowledge/order-risk.js +653 -0
  107. package/dist/knowledge/order-templates.d.ts +50 -0
  108. package/dist/knowledge/order-templates.js +368 -0
  109. package/dist/knowledge/order-translation.d.ts +78 -0
  110. package/dist/knowledge/order-translation.js +550 -0
  111. package/dist/knowledge/passport-confirm.d.ts +130 -0
  112. package/dist/knowledge/passport-confirm.js +531 -0
  113. package/dist/knowledge/passport-context.d.ts +59 -0
  114. package/dist/knowledge/passport-context.js +306 -0
  115. package/dist/knowledge/passport-ledger.d.ts +48 -0
  116. package/dist/knowledge/passport-ledger.js +282 -0
  117. package/dist/knowledge/passport-puzzle.d.ts +108 -0
  118. package/dist/knowledge/passport-puzzle.js +333 -0
  119. package/dist/knowledge/passport-risk.d.ts +70 -0
  120. package/dist/knowledge/passport-risk.js +450 -0
  121. package/dist/knowledge/passport-templates.d.ts +40 -0
  122. package/dist/knowledge/passport-templates.js +568 -0
  123. package/dist/knowledge/passport-translation.d.ts +68 -0
  124. package/dist/knowledge/passport-translation.js +516 -0
  125. package/dist/knowledge/payment-risk.d.ts +33 -0
  126. package/dist/knowledge/payment-risk.js +182 -0
  127. package/dist/knowledge/permission-confirm.d.ts +110 -0
  128. package/dist/knowledge/permission-confirm.js +426 -0
  129. package/dist/knowledge/permission-context.d.ts +58 -0
  130. package/dist/knowledge/permission-context.js +224 -0
  131. package/dist/knowledge/permission-ledger.d.ts +38 -0
  132. package/dist/knowledge/permission-ledger.js +403 -0
  133. package/dist/knowledge/permission-puzzle.d.ts +122 -0
  134. package/dist/knowledge/permission-puzzle.js +173 -0
  135. package/dist/knowledge/permission-risk.d.ts +76 -0
  136. package/dist/knowledge/permission-risk.js +411 -0
  137. package/dist/knowledge/permission-templates.d.ts +38 -0
  138. package/dist/knowledge/permission-templates.js +234 -0
  139. package/dist/knowledge/permission-translation.d.ts +57 -0
  140. package/dist/knowledge/permission-translation.js +350 -0
  141. package/dist/knowledge/personal-risk.d.ts +36 -0
  142. package/dist/knowledge/personal-risk.js +212 -0
  143. package/dist/knowledge/progress-confirm.d.ts +108 -0
  144. package/dist/knowledge/progress-confirm.js +456 -0
  145. package/dist/knowledge/progress-context.d.ts +123 -0
  146. package/dist/knowledge/progress-context.js +452 -0
  147. package/dist/knowledge/progress-ledger.d.ts +63 -0
  148. package/dist/knowledge/progress-ledger.js +327 -0
  149. package/dist/knowledge/progress-puzzle.d.ts +82 -0
  150. package/dist/knowledge/progress-puzzle.js +219 -0
  151. package/dist/knowledge/progress-risk.d.ts +74 -0
  152. package/dist/knowledge/progress-risk.js +461 -0
  153. package/dist/knowledge/progress-templates.d.ts +38 -0
  154. package/dist/knowledge/progress-templates.js +228 -0
  155. package/dist/knowledge/progress-translation.d.ts +52 -0
  156. package/dist/knowledge/progress-translation.js +401 -0
  157. package/dist/knowledge/proof-confirm.d.ts +31 -0
  158. package/dist/knowledge/proof-confirm.js +187 -0
  159. package/dist/knowledge/proof-risk.d.ts +33 -0
  160. package/dist/knowledge/proof-risk.js +207 -0
  161. package/dist/knowledge/proof-translation.d.ts +52 -0
  162. package/dist/knowledge/proof-translation.js +283 -0
  163. package/dist/knowledge/registrar-risk.d.ts +34 -0
  164. package/dist/knowledge/registrar-risk.js +217 -0
  165. package/dist/knowledge/repository-confirm.d.ts +36 -0
  166. package/dist/knowledge/repository-confirm.js +242 -0
  167. package/dist/knowledge/repository-risk.d.ts +40 -0
  168. package/dist/knowledge/repository-risk.js +312 -0
  169. package/dist/knowledge/repository-translation.d.ts +58 -0
  170. package/dist/knowledge/repository-translation.js +422 -0
  171. package/dist/knowledge/resource-risk.d.ts +32 -0
  172. package/dist/knowledge/resource-risk.js +157 -0
  173. package/dist/knowledge/reward-confirm.d.ts +113 -0
  174. package/dist/knowledge/reward-confirm.js +496 -0
  175. package/dist/knowledge/reward-context.d.ts +127 -0
  176. package/dist/knowledge/reward-context.js +504 -0
  177. package/dist/knowledge/reward-ledger.d.ts +96 -0
  178. package/dist/knowledge/reward-ledger.js +502 -0
  179. package/dist/knowledge/reward-puzzle.d.ts +97 -0
  180. package/dist/knowledge/reward-puzzle.js +288 -0
  181. package/dist/knowledge/reward-risk.d.ts +84 -0
  182. package/dist/knowledge/reward-risk.js +545 -0
  183. package/dist/knowledge/reward-translation.d.ts +58 -0
  184. package/dist/knowledge/reward-translation.js +501 -0
  185. package/dist/knowledge/safety-rules.js +11 -3
  186. package/dist/knowledge/scenario-modes.d.ts +53 -0
  187. package/dist/knowledge/scenario-modes.js +302 -0
  188. package/dist/knowledge/service-confirm.d.ts +152 -0
  189. package/dist/knowledge/service-confirm.js +699 -0
  190. package/dist/knowledge/service-context.d.ts +66 -0
  191. package/dist/knowledge/service-context.js +403 -0
  192. package/dist/knowledge/service-ledger.d.ts +71 -0
  193. package/dist/knowledge/service-ledger.js +609 -0
  194. package/dist/knowledge/service-puzzle.d.ts +158 -0
  195. package/dist/knowledge/service-puzzle.js +236 -0
  196. package/dist/knowledge/service-risk.d.ts +108 -0
  197. package/dist/knowledge/service-risk.js +615 -0
  198. package/dist/knowledge/service-templates.d.ts +39 -0
  199. package/dist/knowledge/service-templates.js +418 -0
  200. package/dist/knowledge/service-translation.d.ts +103 -0
  201. package/dist/knowledge/service-translation.js +622 -0
  202. package/dist/knowledge/tools-reference.d.ts +17 -0
  203. package/dist/knowledge/tools-reference.js +151 -0
  204. package/dist/knowledge/treasury-confirm.d.ts +133 -0
  205. package/dist/knowledge/treasury-confirm.js +512 -0
  206. package/dist/knowledge/treasury-context.d.ts +64 -0
  207. package/dist/knowledge/treasury-context.js +363 -0
  208. package/dist/knowledge/treasury-ledger.d.ts +42 -0
  209. package/dist/knowledge/treasury-ledger.js +300 -0
  210. package/dist/knowledge/treasury-puzzle.d.ts +163 -0
  211. package/dist/knowledge/treasury-puzzle.js +216 -0
  212. package/dist/knowledge/treasury-risk.d.ts +86 -0
  213. package/dist/knowledge/treasury-risk.js +440 -0
  214. package/dist/knowledge/treasury-templates.d.ts +38 -0
  215. package/dist/knowledge/treasury-templates.js +316 -0
  216. package/dist/knowledge/treasury-translation.d.ts +78 -0
  217. package/dist/knowledge/treasury-translation.js +498 -0
  218. package/dist/knowledge/util-risk.d.ts +30 -0
  219. package/dist/knowledge/util-risk.js +135 -0
  220. package/dist/project/business-puzzle.d.ts +47 -0
  221. package/dist/project/business-puzzle.js +372 -0
  222. package/dist/project/deployment-doc.d.ts +61 -0
  223. package/dist/project/deployment-doc.js +432 -0
  224. package/dist/project/graph.d.ts +1 -0
  225. package/dist/project/graph.js +27 -1
  226. package/dist/project/index.d.ts +1 -0
  227. package/dist/project/index.js +39 -2
  228. package/dist/project/namespace.d.ts +11 -1
  229. package/dist/project/namespace.js +27 -2
  230. package/dist/project/query.d.ts +2 -0
  231. package/dist/project/query.js +56 -15
  232. package/dist/project/risk-aggregator.d.ts +50 -0
  233. package/dist/project/risk-aggregator.js +280 -0
  234. package/dist/project/substep-trace.d.ts +130 -0
  235. package/dist/project/substep-trace.js +332 -0
  236. package/dist/rules.d.ts +12 -0
  237. package/dist/rules.js +9 -0
  238. package/dist/schema/call/allocation.d.ts +44 -44
  239. package/dist/schema/call/arbitration.d.ts +141 -141
  240. package/dist/schema/call/base.d.ts +386 -386
  241. package/dist/schema/call/base.js +6 -6
  242. package/dist/schema/call/bridge-handler.d.ts +5 -2
  243. package/dist/schema/call/bridge.d.ts +159 -159
  244. package/dist/schema/call/contact.d.ts +110 -110
  245. package/dist/schema/call/demand.d.ts +76 -76
  246. package/dist/schema/call/handler.d.ts +2 -3
  247. package/dist/schema/call/handler.js +1 -1
  248. package/dist/schema/call/machine.d.ts +96 -96
  249. package/dist/schema/call/order.d.ts +98 -110
  250. package/dist/schema/call/permission-handler.d.ts +5 -0
  251. package/dist/schema/call/permission-handler.js +54 -0
  252. package/dist/schema/call/permission.d.ts +108 -108
  253. package/dist/schema/call/personal.d.ts +14 -14
  254. package/dist/schema/call/progress.d.ts +57 -72
  255. package/dist/schema/call/progress.js +7 -4
  256. package/dist/schema/call/proof.d.ts +18 -18
  257. package/dist/schema/call/proof.js +12 -7
  258. package/dist/schema/call/repository.d.ts +154 -154
  259. package/dist/schema/call/reward.d.ts +55 -55
  260. package/dist/schema/call/semantic.js +1 -1
  261. package/dist/schema/call/service.d.ts +238 -238
  262. package/dist/schema/call/treasury.d.ts +93 -93
  263. package/dist/schema/config/index.d.ts +178 -5
  264. package/dist/schema/config/index.js +52 -1
  265. package/dist/schema/local/index.d.ts +3554 -836
  266. package/dist/schema/local/index.js +2 -1
  267. package/dist/schema/messenger/index.d.ts +162 -162
  268. package/dist/schema/operations.d.ts +1102 -1118
  269. package/dist/schema/operations.js +7 -1
  270. package/dist/schema/project/index.d.ts +1392 -6
  271. package/dist/schema/project/index.js +426 -2
  272. package/dist/schema/query/index.d.ts +818 -818
  273. package/dist/schema/query/index.js +15 -9
  274. package/dist/schema/schema-query/index.d.ts +23 -3
  275. package/dist/schema/schema-query/index.js +13 -2
  276. package/dist/schema/sync-layer4.d.ts +21 -0
  277. package/dist/schema/sync-layer4.js +261 -0
  278. package/dist/schema/trust/index.d.ts +26 -26
  279. package/dist/schema/utils/guard-query-utils.d.ts +7 -0
  280. package/dist/schema/utils/guard-query-utils.js +14 -1
  281. package/dist/schemas/account_operation.output.json +718 -0
  282. package/dist/schemas/bridge_operation.output.json +1 -1
  283. package/dist/schemas/config_operation.output.json +173 -0
  284. package/dist/schemas/index.json +9 -1
  285. package/dist/schemas/local_info_operation.output.json +718 -0
  286. package/dist/schemas/local_mark_operation.output.json +718 -0
  287. package/dist/schemas/messenger_operation.output.json +1 -1
  288. package/dist/schemas/onchain_events.output.json +1 -1
  289. package/dist/schemas/onchain_operations.output.json +5 -4
  290. package/dist/schemas/onchain_operations.schema.json +1813 -333
  291. package/dist/schemas/onchain_operations_allocation.schema.json +9 -11
  292. package/dist/schemas/onchain_operations_arbitration.schema.json +2 -1
  293. package/dist/schemas/onchain_operations_contact.schema.json +2 -1
  294. package/dist/schemas/onchain_operations_demand.schema.json +2 -1
  295. package/dist/schemas/onchain_operations_gen_passport.schema.json +878 -872
  296. package/dist/schemas/onchain_operations_gen_proof.schema.json +273 -0
  297. package/dist/schemas/onchain_operations_guard.schema.json +584 -70
  298. package/dist/schemas/onchain_operations_machine.schema.json +4 -6
  299. package/dist/schemas/onchain_operations_order.schema.json +13 -9
  300. package/dist/schemas/onchain_operations_payment.schema.json +2 -1
  301. package/dist/schemas/onchain_operations_permission.schema.json +2 -1
  302. package/dist/schemas/onchain_operations_personal.schema.json +2 -1
  303. package/dist/schemas/onchain_operations_progress.schema.json +14 -10
  304. package/dist/schemas/onchain_operations_proof.schema.json +699 -0
  305. package/dist/schemas/onchain_operations_repository.schema.json +2 -1
  306. package/dist/schemas/onchain_operations_reward.schema.json +2 -1
  307. package/dist/schemas/onchain_operations_service.schema.json +4 -6
  308. package/dist/schemas/onchain_operations_treasury.schema.json +2 -1
  309. package/dist/schemas/onchain_table_data.output.json +6 -12
  310. package/dist/schemas/onchain_table_data.schema.json +32 -1
  311. package/dist/schemas/project_operation.output.json +879 -0
  312. package/dist/schemas/project_operation.schema.json +473 -2
  313. package/dist/schemas/query_toolkit.output.json +14906 -6
  314. package/dist/schemas/schema_query.output.json +38 -1
  315. package/dist/telemetry/index.d.ts +1 -1
  316. package/dist/tools/handlers/bridge.d.ts +1 -0
  317. package/dist/tools/handlers/bridge.js +1 -0
  318. package/dist/tools/handlers/config.d.ts +2 -0
  319. package/dist/tools/handlers/config.js +74 -0
  320. package/dist/tools/handlers/file-export.d.ts +3 -0
  321. package/dist/tools/handlers/file-export.js +90 -0
  322. package/dist/tools/handlers/local.d.ts +3 -0
  323. package/dist/tools/handlers/local.js +38 -0
  324. package/dist/tools/handlers/messenger.d.ts +16 -0
  325. package/dist/tools/handlers/messenger.js +188 -0
  326. package/dist/tools/handlers/onchain.d.ts +2 -0
  327. package/dist/tools/handlers/onchain.js +248 -0
  328. package/dist/tools/handlers/project.d.ts +2 -0
  329. package/dist/tools/handlers/project.js +293 -0
  330. package/dist/tools/handlers/query.d.ts +5 -0
  331. package/dist/tools/handlers/query.js +256 -0
  332. package/dist/tools/handlers/schema-query.d.ts +2 -0
  333. package/dist/tools/handlers/schema-query.js +93 -0
  334. package/dist/tools/handlers/trust.d.ts +2 -0
  335. package/dist/tools/handlers/trust.js +194 -0
  336. package/dist/tools/handlers/wip.d.ts +2 -0
  337. package/dist/tools/handlers/wip.js +44 -0
  338. package/dist/tools/index.d.ts +13 -0
  339. package/dist/tools/index.js +526 -0
  340. package/dist/tools/rules-hook.d.ts +2 -0
  341. package/dist/tools/rules-hook.js +23 -0
  342. package/dist/tools/shared.d.ts +20 -0
  343. package/dist/tools/shared.js +130 -0
  344. package/dist/tools/types.d.ts +35 -0
  345. package/dist/tools/types.js +1 -0
  346. package/dist/tools/wrap.d.ts +14 -0
  347. package/dist/tools/wrap.js +267 -0
  348. package/package.json +20 -6
@@ -0,0 +1,550 @@
1
+ import { MAX_AGENT_COUNT, MAX_DISPUTE_COUNT, } from "@wowok/wowok";
2
+ import { ORDER_SCENES, inferSceneFromIntent, } from "./order-ledger.js";
3
+ export const SEMANTIC_TO_SCHEMA_RULES = [
4
+ {
5
+ id: "P-O-01",
6
+ pattern_name: "Create Order via service::buy (compound creation)",
7
+ semantic_intent: "Buy items from a Service — atomically creates Order + Allocation + Progress, snapshots service.machine, emits NewOrderEvent",
8
+ match_keywords: ["buy", "purchase", "order"],
9
+ schema_fields: ["(via service::buy, not direct order::create)"],
10
+ example_json: {
11
+ _note: "Order is NOT created via CallOrder_Data. It is created via service::buy() which internally calls order::new + order::create.",
12
+ _call_target: "service",
13
+ object: "0xSERVICE_ADDRESS",
14
+ buy: {
15
+ items: [{ name: "Product A", price: "1000000000", quantity: 1, wip_hash: "0xABC..." }],
16
+ discount: null,
17
+ named_order: "my_order_alias",
18
+ machine_forward: null,
19
+ },
20
+ },
21
+ reverse_explanation: "Order creation is composite — service::buy atomically builds Order + Allocation + Progress + emits NewOrderEvent. order::create is package-only.",
22
+ operation_field: "object",
23
+ permission_layer: "L3_package_only",
24
+ },
25
+ {
26
+ id: "P-O-02",
27
+ pattern_name: "Advance Progress (forward/hold)",
28
+ semantic_intent: "Advance Order's Progress to next node via forward or hold",
29
+ match_keywords: ["advance", "forward", "progress", "next"],
30
+ schema_fields: ["object", "progress"],
31
+ example_json: {
32
+ object: "0xORDER_ADDRESS",
33
+ progress: {
34
+ next_node_name: "shipped",
35
+ forward: { name: "deliver", operator: null, guard: null },
36
+ op: "next",
37
+ message: "Order dispatched",
38
+ },
39
+ },
40
+ reverse_explanation: "progress.forward triggers Progress::operate → order.progress node transition. Both owner and agent can advance (L2).",
41
+ operation_field: "progress",
42
+ permission_layer: "L2_owner_or_agent",
43
+ },
44
+ {
45
+ id: "P-O-03",
46
+ pattern_name: "Set agent list (owner-only, pre-progress)",
47
+ semantic_intent: "Replace the entire agent list. Frozen after Progress binding.",
48
+ match_keywords: ["set agent", "agent", "delegate"],
49
+ schema_fields: ["object", "agent"],
50
+ example_json: {
51
+ object: "0xORDER_ADDRESS",
52
+ agent: ["0xAGENT1", "0xAGENT2"],
53
+ },
54
+ reverse_explanation: "agent field overwrites entire agent list. Owner-only (L1). Aborts E_PROGRESS_NOT_SPECIFIED if Progress already bound. ⚠️ Boundary bug: actual max 11 (not 10).",
55
+ operation_field: "agent",
56
+ permission_layer: "L1_owner_only",
57
+ },
58
+ {
59
+ id: "P-O-04",
60
+ pattern_name: "Set required_info (Contact or WTS Proof)",
61
+ semantic_intent: "Update recipient contact or delivery proof. Both owner and agent can update.",
62
+ match_keywords: ["required_info", "recipient", "contact", "wts proof"],
63
+ schema_fields: ["object", "required_info"],
64
+ example_json: {
65
+ object: "0xORDER_ADDRESS",
66
+ required_info: "0xCONTACT_ADDRESS",
67
+ },
68
+ reverse_explanation: "required_info accepts Contact object (recipient) or WTS Proof object (delivery proof). null clears. L2 (owner or agent).",
69
+ operation_field: "required_info",
70
+ permission_layer: "L2_owner_or_agent",
71
+ },
72
+ {
73
+ id: "P-O-05",
74
+ pattern_name: "Apply for arbitration (arb_confirm)",
75
+ semantic_intent: "File arbitration with confirm/deny + description + proposition. Triggers dispute() appending Arb to order.dispute.",
76
+ match_keywords: ["arb_confirm", "apply arbitration", "file dispute", "compensation"],
77
+ schema_fields: ["object", "arb_confirm"],
78
+ example_json: {
79
+ object: "0xORDER_ADDRESS",
80
+ arb_confirm: {
81
+ arb: "0xARB_ADDRESS",
82
+ confirm: true,
83
+ description: "Item never arrived",
84
+ proposition: ["Refund full amount", "Compensation for delay"],
85
+ },
86
+ },
87
+ reverse_explanation: "arb_confirm triggers arb::principal_confirm + arb::description_change + arb::proposition_change, and Arb module calls order::dispute(arb) to append. L2.",
88
+ operation_field: "arb_confirm",
89
+ permission_layer: "L2_owner_or_agent",
90
+ },
91
+ {
92
+ id: "P-O-06",
93
+ pattern_name: "Object to arbitration (arb_objection)",
94
+ semantic_intent: "Object to Arb ruling and request re-arbitration",
95
+ match_keywords: ["arb_objection", "object", "appeal"],
96
+ schema_fields: ["object", "arb_objection"],
97
+ example_json: {
98
+ object: "0xORDER_ADDRESS",
99
+ arb_objection: {
100
+ arb: "0xARB_ADDRESS",
101
+ objection: "Evidence was not properly reviewed",
102
+ },
103
+ },
104
+ reverse_explanation: "arb_objection triggers arb::objection. Requires Arb status = Arbitrated. L2 (owner or agent). Irreversible.",
105
+ operation_field: "arb_objection",
106
+ permission_layer: "L2_owner_or_agent",
107
+ },
108
+ {
109
+ id: "P-O-07",
110
+ pattern_name: "Claim compensation (arb_claim_compensation)",
111
+ semantic_intent: "Claim compensation from a ruled Arb. Sets claimed_by — ONE-TIME, IRREVERSIBLE, blocks future disputes.",
112
+ match_keywords: ["arb_claim_compensation", "claim", "compensation"],
113
+ schema_fields: ["object", "arb_claim_compensation"],
114
+ example_json: {
115
+ object: "0xORDER_ADDRESS",
116
+ arb_claim_compensation: {
117
+ arb: "0xRULED_ARB_ADDRESS",
118
+ },
119
+ },
120
+ reverse_explanation: "arb_claim_compensation triggers service::compensation_claim → order::compensate(arb) → sets claimed_by=arb. IRREVERSIBLE. L2.",
121
+ operation_field: "arb_claim_compensation",
122
+ permission_layer: "L2_owner_or_agent",
123
+ },
124
+ {
125
+ id: "P-O-08",
126
+ pattern_name: "Receive payment/objects (owner-only)",
127
+ semantic_intent: "Receive CoinWrapper or arbitrary Receiving<K> from Progress. Funds forwarded to owner.",
128
+ match_keywords: ["receive", "collect", "extract"],
129
+ schema_fields: ["object", "receive"],
130
+ example_json: {
131
+ object: "0xORDER_ADDRESS",
132
+ receive: {
133
+ received: "0xRECEIVING_OBJECT_ID",
134
+ },
135
+ },
136
+ reverse_explanation: "receive calls order::owner_receive or owner_receive_object. Owner-only (L1) — agent CANNOT receive. Aborts E_ORDER_DELIVERING if Progress not at terminal.",
137
+ operation_field: "receive",
138
+ permission_layer: "L1_owner_only",
139
+ },
140
+ {
141
+ id: "P-O-09",
142
+ pattern_name: "Transfer ownership (transfer_to)",
143
+ semantic_intent: "Transfer Order ownership to new address. IRREVERSIBLE. New owner takes over ALL permissions.",
144
+ match_keywords: ["transfer", "transfer_to", "handover"],
145
+ schema_fields: ["object", "transfer_to"],
146
+ example_json: {
147
+ object: "0xORDER_ADDRESS",
148
+ transfer_to: "0xNEW_OWNER_ADDRESS",
149
+ },
150
+ reverse_explanation: "transfer_to calls order::owner_change(new_owner). Owner-only (L1). IRREVERSIBLE. Unlike agent_set, can be called after Progress binding.",
151
+ operation_field: "transfer_to",
152
+ permission_layer: "L1_owner_only",
153
+ },
154
+ {
155
+ id: "P-O-10",
156
+ pattern_name: "Query Order state (read-only)",
157
+ semantic_intent: "Read Order fields: items, amount, owner/builder, agent, dispute, claimed_by, progress, machine, time",
158
+ match_keywords: ["query", "read", "check", "status"],
159
+ schema_fields: ["(read-only via query layer, not CallOrder_Data)"],
160
+ example_json: {
161
+ _note: "Query uses the query/object endpoint, not CallOrder_Data",
162
+ _call_target: "query",
163
+ object: "0xORDER_ADDRESS",
164
+ fields: ["items", "amount", "owner", "agent", "dispute", "claimed_by", "progress", "machine"],
165
+ },
166
+ reverse_explanation: "Query is read-only — does not modify state. Use to verify state before any L1/L2 operation. SDK ObjectOrder returns all 14 fields.",
167
+ operation_field: "object",
168
+ },
169
+ {
170
+ id: "P-O-11",
171
+ pattern_name: "Query Order history (event log)",
172
+ semantic_intent: "Query Order lifecycle events. ⚠️ Only NewOrderEvent is actually emitted — other events must be INFERRED from field changes.",
173
+ match_keywords: ["history", "events", "lifecycle", "audit"],
174
+ schema_fields: ["(read-only via query layer, event filter)"],
175
+ example_json: {
176
+ _note: "Only NewOrderEvent is emitted on-chain. Other lifecycle events must be inferred by querying Order field diffs over time.",
177
+ _call_target: "query",
178
+ object: "0xORDER_ADDRESS",
179
+ event_filter: { type: "order::NewOrderEvent" },
180
+ },
181
+ reverse_explanation: "Audit weakness: only 1 of 11 lifecycle events is actually emitted. Use status_inference formula from ORDER_AUDIT_FORMULAS to derive state.",
182
+ operation_field: "object",
183
+ },
184
+ {
185
+ id: "P-O-12",
186
+ pattern_name: "Monitor Order status changes (polling)",
187
+ semantic_intent: "Poll Order status to detect: Progress advance, dispute append, claimed_by set, ownership transfer",
188
+ match_keywords: ["monitor", "poll", "watch", "track"],
189
+ schema_fields: ["(read-only via query layer, polling)"],
190
+ example_json: {
191
+ _note: "Monitor by querying Order at intervals and diffing fields",
192
+ _call_target: "query",
193
+ object: "0xORDER_ADDRESS",
194
+ poll_interval_ms: 5000,
195
+ watch_fields: ["progress", "dispute", "claimed_by", "owner"],
196
+ },
197
+ reverse_explanation: "No push notifications — must poll. Track 4 critical fields: progress (advance), dispute (new arb), claimed_by (terminal), owner (transfer).",
198
+ operation_field: "object",
199
+ },
200
+ ];
201
+ export const SCHEMA_TO_SEMANTIC_RULES = [
202
+ {
203
+ element_type: "field",
204
+ type_name: "object",
205
+ semantic_explanation: "Order object address. STRING=operate existing Order. null/omitted is invalid (Order creation goes through service::buy).",
206
+ constraints: ["Must be valid Order object ID", "Order must exist on-chain"],
207
+ },
208
+ {
209
+ element_type: "field",
210
+ type_name: "agent",
211
+ semantic_explanation: "Agent address list (overwrites entire list). Owner-only (L1). Frozen after Progress binding. ⚠️ Boundary bug: actual max 11 (not 10).",
212
+ constraints: [`<= ${MAX_AGENT_COUNT} agents (doc) / 11 (actual bug)`, "Owner-only", "Frozen after Progress binding"],
213
+ },
214
+ {
215
+ element_type: "field",
216
+ type_name: "required_info",
217
+ semantic_explanation: "Contact object (recipient info) or WTS Proof object (delivery proof). null clears. L2 (owner or agent).",
218
+ constraints: ["Must be Contact or WTS Proof object", "null clears the field"],
219
+ },
220
+ {
221
+ element_type: "field",
222
+ type_name: "progress",
223
+ semantic_explanation: "Progress operation object — advance via forward/hold. Both owner and agent can advance. Node transition is irreversible.",
224
+ constraints: ["Requires Progress binding (order.progress.is_some())", "L2 (owner or agent)", "Node transition irreversible"],
225
+ },
226
+ {
227
+ element_type: "field",
228
+ type_name: "arb_confirm",
229
+ semantic_explanation: "Apply for arbitration compensation. Triggers dispute() appending Arb to order.dispute. L2. Irreversible.",
230
+ constraints: ["Arb must exist", "L2 (owner or agent)", "claimed_by must be None"],
231
+ },
232
+ {
233
+ element_type: "field",
234
+ type_name: "arb_objection",
235
+ semantic_explanation: "Object to Arb ruling and request re-arbitration. Requires Arb status = Arbitrated. L2. Irreversible.",
236
+ constraints: ["Arb must be in Arbitrated state", "L2 (owner or agent)"],
237
+ },
238
+ {
239
+ element_type: "field",
240
+ type_name: "arb_claim_compensation",
241
+ semantic_explanation: "Claim compensation from ruled Arb. Sets claimed_by. ONE-TIME, IRREVERSIBLE, blocks future disputes. L2.",
242
+ constraints: ["Arb must be Arbitrated", "claimed_by must be None", "L2 (owner or agent)", "IRREVERSIBLE"],
243
+ },
244
+ {
245
+ element_type: "field",
246
+ type_name: "receive",
247
+ semantic_explanation: "Receive CoinWrapper or arbitrary Receiving<K> from Progress. Funds forwarded to owner. Owner-only (L1) — agent CANNOT.",
248
+ constraints: ["Owner-only (L1)", "Progress must be at terminal node (not delivering)", "Can be called multiple times"],
249
+ },
250
+ {
251
+ element_type: "field",
252
+ type_name: "transfer_to",
253
+ semantic_explanation: "New owner address for ownership transfer. IRREVERSIBLE. New owner takes over ALL permissions. Owner-only (L1).",
254
+ constraints: ["Owner-only (L1)", "IRREVERSIBLE", "Valid Wow address"],
255
+ },
256
+ {
257
+ element_type: "op",
258
+ type_name: "forward",
259
+ semantic_explanation: "Advance Progress to next node via named forward. Triggers Progress::operate.",
260
+ constraints: ["Forward name must exist on current node", "Guard (if any) must pass"],
261
+ },
262
+ {
263
+ element_type: "op",
264
+ type_name: "hold",
265
+ semantic_explanation: "Hold at current Progress node (optional pause).",
266
+ constraints: ["Node must support hold"],
267
+ },
268
+ {
269
+ element_type: "op",
270
+ type_name: "confirm",
271
+ semantic_explanation: "In arb_confirm: true=confirm materials valid, false=deny materials.",
272
+ constraints: ["Boolean — no other values"],
273
+ },
274
+ {
275
+ element_type: "index",
276
+ type_name: "dispute_index",
277
+ semantic_explanation: "Position in order.dispute vector. 0-based. Max 10 disputes total.",
278
+ constraints: [`<= ${MAX_DISPUTE_COUNT} disputes`, "Frozen when claimed_by.is_some()"],
279
+ },
280
+ {
281
+ element_type: "error",
282
+ type_name: "E_OWNER (code 1)",
283
+ semantic_explanation: "Sender != order.owner. L1 operation attempted by non-owner (agent or third party).",
284
+ constraints: ["Aborts assert_owner"],
285
+ },
286
+ {
287
+ element_type: "error",
288
+ type_name: "E_PERMISSION (code 5)",
289
+ semantic_explanation: "Sender is neither owner nor in agent[]. L2 operation attempted by unauthorized caller.",
290
+ constraints: ["Aborts assert_op_permission (via has_op_permission returning false)"],
291
+ },
292
+ {
293
+ element_type: "error",
294
+ type_name: "E_PROGRESS_NOT_SPECIFIED (code 3)",
295
+ semantic_explanation: "⚠️ DUAL SEMANTICS: (a) order::create — machine is Some but progress is None; (b) agent_set/owner_change — progress is already bound (frozen).",
296
+ constraints: ["Check context to disambiguate", "Same code, opposite meanings"],
297
+ },
298
+ {
299
+ element_type: "error",
300
+ type_name: "E_ORDER_ALREADY_CLAIMED (code 7)",
301
+ semantic_explanation: "claimed_by is already Some. Cannot file new disputes, claim again, or call compensate.",
302
+ constraints: ["IRREVERSIBLE — no way to reset claimed_by"],
303
+ },
304
+ {
305
+ element_type: "error",
306
+ type_name: "E_MAX_AGENT_COUNT (code 2)",
307
+ semantic_explanation: "agent list exceeds MAX_AGENT_COUNT (10). ⚠️ Actual boundary uses <= so allows 11 (bug).",
308
+ constraints: [`Doc limit: ${MAX_AGENT_COUNT}`, "Actual limit: 11 (boundary bug)"],
309
+ },
310
+ {
311
+ element_type: "error",
312
+ type_name: "E_MAX_DISPUTE_COUNT (code 6)",
313
+ semantic_explanation: "dispute vector at MAX_DISPUTE_COUNT (10). Next dispute() call aborts.",
314
+ constraints: [`Max: ${MAX_DISPUTE_COUNT}`],
315
+ },
316
+ {
317
+ element_type: "error",
318
+ type_name: "E_ALLOCATION_NOT_SPECIFIED (code 8)",
319
+ semantic_explanation: "order::create with amount > 0 but allocation is None.",
320
+ constraints: ["If amount > 0, allocation must be set"],
321
+ },
322
+ {
323
+ element_type: "error",
324
+ type_name: "E_ALLOCATION_ALREADY_SPECIFIED (code 9)",
325
+ semantic_explanation: "on_allocation called twice. Allocation is one-time set.",
326
+ constraints: ["One-time only"],
327
+ },
328
+ {
329
+ element_type: "error",
330
+ type_name: "E_PROGRESS_ALREADY_SPECIFIED (code 10)",
331
+ semantic_explanation: "on_progress called twice. Progress is one-time set.",
332
+ constraints: ["One-time only"],
333
+ },
334
+ ];
335
+ export const ORDER_CONSTRAINT_RULES = [
336
+ {
337
+ id: "MC-O-01",
338
+ category: "structural",
339
+ rule: "Order has 14 fields; SDK uses 'builder' for Move's 'owner' (only naming deviation in 22 objects)",
340
+ applies_to: ["object.owner", "object.builder"],
341
+ },
342
+ {
343
+ id: "MC-O-02",
344
+ category: "structural",
345
+ rule: `agent count <= MAX_AGENT_COUNT (${MAX_AGENT_COUNT}) per docs; ⚠️ actual allows 11 due to <= bug`,
346
+ applies_to: ["agent"],
347
+ },
348
+ {
349
+ id: "MC-O-03",
350
+ category: "structural",
351
+ rule: `dispute count <= MAX_DISPUTE_COUNT (${MAX_DISPUTE_COUNT}); frozen when claimed_by.is_some()`,
352
+ applies_to: ["dispute"],
353
+ },
354
+ {
355
+ id: "MC-O-04",
356
+ category: "structural",
357
+ rule: "Order creation is COMPOSITE via service::buy — order::create is package-only",
358
+ applies_to: ["(creation flow)"],
359
+ },
360
+ {
361
+ id: "MC-O-05",
362
+ category: "semantic",
363
+ rule: "order.machine is a SNAPSHOT copied from service.machine at buy time (not a reference)",
364
+ applies_to: ["machine"],
365
+ },
366
+ {
367
+ id: "MC-O-06",
368
+ category: "semantic",
369
+ rule: "E_PROGRESS_NOT_SPECIFIED has DUAL semantics: (a) create: machine Some + progress None; (b) agent_set/owner_change: progress already bound",
370
+ applies_to: ["error code 3"],
371
+ },
372
+ {
373
+ id: "MC-O-07",
374
+ category: "semantic",
375
+ rule: "Only NewOrderEvent is actually emitted; 10 other lifecycle events must be inferred from field changes",
376
+ applies_to: ["events"],
377
+ },
378
+ {
379
+ id: "MC-O-08",
380
+ category: "semantic",
381
+ rule: "SaleItem.item ↔ PurchasedItem.name (different field names for same concept)",
382
+ applies_to: ["items.item", "purchased_items.name"],
383
+ },
384
+ {
385
+ id: "MC-O-09",
386
+ category: "authority",
387
+ rule: "L1 owner-only operations: receive, transfer_to, owner_change, agent_set (assert_owner)",
388
+ applies_to: ["receive", "transfer_to", "agent"],
389
+ },
390
+ {
391
+ id: "MC-O-10",
392
+ category: "authority",
393
+ rule: "L2 owner-or-agent operations: required_info, progress, arb_confirm, arb_objection, arb_claim_compensation (has_op_permission)",
394
+ applies_to: ["required_info", "progress", "arb_confirm", "arb_objection", "arb_claim_compensation"],
395
+ },
396
+ {
397
+ id: "MC-O-11",
398
+ category: "authority",
399
+ rule: "L3 package-only operations: on_progress, on_allocation, dispute, compensate (no external access)",
400
+ applies_to: ["(package-only functions)"],
401
+ },
402
+ {
403
+ id: "MC-O-12",
404
+ category: "authority",
405
+ rule: "Agent CANNOT receive payments — only owner can call owner_receive / owner_receive_object",
406
+ applies_to: ["receive"],
407
+ },
408
+ {
409
+ id: "MC-O-13",
410
+ category: "lifecycle",
411
+ rule: "Progress binding FREEZES owner and agent — agent_set/owner_change abort E_PROGRESS_NOT_SPECIFIED after binding",
412
+ applies_to: ["agent", "transfer_to (pre-progress)", "owner_change"],
413
+ },
414
+ {
415
+ id: "MC-O-14",
416
+ category: "lifecycle",
417
+ rule: "claimed_by is ONE-TIME, IRREVERSIBLE — blocks future dispute(), compensate(), and arb_claim_compensation",
418
+ applies_to: ["claimed_by", "arb_claim_compensation", "dispute"],
419
+ },
420
+ {
421
+ id: "MC-O-15",
422
+ category: "cross_object",
423
+ rule: "Order + Allocation + Progress are 1:1:1 bound at creation; cannot rebind or detach",
424
+ applies_to: ["progress", "allocation"],
425
+ },
426
+ ];
427
+ export const ORDER_TRANSLATION_VERSION = "1.0.0";
428
+ export function matchSemanticPattern(userIntent) {
429
+ const lower = userIntent.toLowerCase();
430
+ return SEMANTIC_TO_SCHEMA_RULES.filter(rule => rule.match_keywords.some(kw => lower.includes(kw.toLowerCase())));
431
+ }
432
+ export function explainOrderCallData(data) {
433
+ const lines = [];
434
+ if (!data.object) {
435
+ lines.push("Operation: ⚠️ INVALID — Order object address required (Order creation goes through service::buy, not CallOrder_Data)");
436
+ return lines.join("\n");
437
+ }
438
+ lines.push(`Operation: MODIFY existing Order at ${data.object}`);
439
+ if (data.agent) {
440
+ lines.push(`- ⚠️ Set agent list (${data.agent.length} agent(s)): [${data.agent.join(", ")}]`);
441
+ lines.push(` Owner-only (L1). Frozen after Progress binding. Boundary bug allows max 11 (not 10).`);
442
+ }
443
+ if (data.required_info !== undefined) {
444
+ if (data.required_info === null) {
445
+ lines.push(`- Clear required_info (L2 — owner or agent)`);
446
+ }
447
+ else {
448
+ lines.push(`- Set required_info: ${data.required_info} (Contact or WTS Proof; L2 — owner or agent)`);
449
+ }
450
+ }
451
+ if (data.progress) {
452
+ const p = data.progress;
453
+ lines.push(`- Advance Progress (L2 — owner or agent)`);
454
+ if (p.next_node_name)
455
+ lines.push(` Next node: ${p.next_node_name}`);
456
+ if (p.forward)
457
+ lines.push(` Forward: ${p.forward.name}${p.forward.operator ? ` (operator: ${p.forward.operator})` : ""}`);
458
+ if (p.op)
459
+ lines.push(` Op: ${p.op}`);
460
+ if (p.message)
461
+ lines.push(` Message: "${p.message}"`);
462
+ }
463
+ if (data.arb_confirm) {
464
+ const a = data.arb_confirm;
465
+ lines.push(`- ⚠️ Apply for arbitration (L2 — owner or agent, IRREVERSIBLE)`);
466
+ lines.push(` Arb: ${a.arb}`);
467
+ lines.push(` Confirm: ${a.confirm ? "valid materials" : "deny materials"}`);
468
+ if (a.description)
469
+ lines.push(` Description: "${a.description}"`);
470
+ if (a.proposition && a.proposition.length > 0) {
471
+ lines.push(` Propositions: ${a.proposition.length} claim(s)`);
472
+ }
473
+ }
474
+ if (data.arb_objection) {
475
+ const a = data.arb_objection;
476
+ lines.push(`- ⚠️ Object to Arb ruling (L2 — owner or agent, IRREVERSIBLE)`);
477
+ lines.push(` Arb: ${a.arb}`);
478
+ lines.push(` Objection: "${a.objection}"`);
479
+ }
480
+ if (data.arb_claim_compensation) {
481
+ const a = data.arb_claim_compensation;
482
+ lines.push(`- ⚠️⚠️ CLAIM COMPENSATION (L2 — owner or agent, ONE-TIME, IRREVERSIBLE)`);
483
+ lines.push(` Arb: ${a.arb}`);
484
+ lines.push(` After claim: NO new disputes can be filed (E_ORDER_ALREADY_CLAIMED)`);
485
+ }
486
+ if (data.receive) {
487
+ lines.push(`- Receive (L1 — OWNER-ONLY, agent CANNOT)`);
488
+ lines.push(` Received object: ${data.receive.received}`);
489
+ lines.push(` Funds/objects forwarded to owner address`);
490
+ }
491
+ if (data.transfer_to) {
492
+ lines.push(`- ⚠️⚠️ TRANSFER OWNERSHIP to ${data.transfer_to} (L1 — OWNER-ONLY, IRREVERSIBLE)`);
493
+ lines.push(` New owner takes over ALL permissions`);
494
+ lines.push(` Can be called even after Progress binding (unlike agent_set)`);
495
+ }
496
+ return lines.join("\n");
497
+ }
498
+ export function explainField(fieldName) {
499
+ return SCHEMA_TO_SEMANTIC_RULES.find(r => r.element_type === "field" && r.type_name === fieldName);
500
+ }
501
+ export function explainOp(opName) {
502
+ return SCHEMA_TO_SEMANTIC_RULES.find(r => r.element_type === "op" && r.type_name === opName);
503
+ }
504
+ export function explainOrderError(errorNameOrCode) {
505
+ const str = String(errorNameOrCode);
506
+ return SCHEMA_TO_SEMANTIC_RULES.find(r => r.element_type === "error" && (r.type_name === str ||
507
+ r.type_name.startsWith(str + " ") ||
508
+ r.type_name.includes(str)));
509
+ }
510
+ export function getConstraintsByCategory(category) {
511
+ return ORDER_CONSTRAINT_RULES.filter(r => r.category === category);
512
+ }
513
+ export function explainPermissionLayer(layer) {
514
+ const descriptions = {
515
+ L1_owner_only: "L1 — Owner-only (assert_owner). Aborts E_OWNER (code 1) if sender != owner. Agent CANNOT perform L1 ops.",
516
+ L2_owner_or_agent: "L2 — Owner or agent (has_op_permission). Aborts E_PERMISSION (code 5) if sender is neither owner nor in agent[].",
517
+ L3_package_only: "L3 — Package-only (no external access). Called by other wow-framework modules (progress, allocation, arbitration).",
518
+ };
519
+ return descriptions[layer];
520
+ }
521
+ export function resolveFieldName(sdkOrMoveName) {
522
+ if (sdkOrMoveName === "builder" || sdkOrMoveName === "owner") {
523
+ return { sdk_name: "builder", move_name: "owner", is_deviation: true };
524
+ }
525
+ return { sdk_name: sdkOrMoveName, move_name: sdkOrMoveName, is_deviation: false };
526
+ }
527
+ export function matchSceneFromOperation(operationField) {
528
+ const scenes = ORDER_SCENES.filter(s => s.operation_field === operationField);
529
+ return scenes.length > 0 ? scenes[0] : undefined;
530
+ }
531
+ export function explainOrderIntent(intent) {
532
+ const matchedScene = inferSceneFromIntent(intent);
533
+ const matchedPatterns = matchSemanticPattern(intent);
534
+ const relevantConstraints = matchedScene
535
+ ? ORDER_CONSTRAINT_RULES.filter(c => {
536
+ if (matchedScene.permission_layer === "L1_owner_only") {
537
+ return c.category === "authority" || c.category === "lifecycle";
538
+ }
539
+ if (matchedScene.permission_layer === "L2_owner_or_agent") {
540
+ return c.category === "authority" || c.category === "semantic";
541
+ }
542
+ return c.category === "structural" || c.category === "cross_object";
543
+ })
544
+ : ORDER_CONSTRAINT_RULES;
545
+ return {
546
+ matched_scene: matchedScene,
547
+ matched_patterns: matchedPatterns,
548
+ relevant_constraints: relevantConstraints,
549
+ };
550
+ }
@@ -0,0 +1,130 @@
1
+ import { type PassportScenario } from "./passport-ledger.js";
2
+ import { type PassportRiskAssessment } from "./passport-risk.js";
3
+ export type ConfirmAction = "block" | "warn" | "confirm_twice" | "info";
4
+ export type ConfirmSeverity = "CRITICAL" | "HIGH" | "MEDIUM" | "LOW" | "INFO";
5
+ export type ConfirmGateStatus = "approved" | "blocked_creation" | "blocked_operation" | "blocked_consistency" | "pending_confirmation";
6
+ export interface PassportConfirmationRule {
7
+ id: string;
8
+ check: string;
9
+ severity: ConfirmSeverity;
10
+ action: ConfirmAction;
11
+ related_error?: string;
12
+ layer: "creation" | "operation" | "consistency";
13
+ }
14
+ export interface CheckResult {
15
+ errors: string[];
16
+ warnings: string[];
17
+ requiresConfirmation: string[];
18
+ canProceed: boolean;
19
+ }
20
+ export interface ConfirmGateResult {
21
+ status: ConfirmGateStatus;
22
+ creation_result?: CheckResult;
23
+ operation_result?: CheckResult;
24
+ consistency_result?: CheckResult;
25
+ risk_assessment?: PassportRiskAssessment;
26
+ confirmation_text: string;
27
+ block_reason?: string;
28
+ decision_record: DecisionRecord;
29
+ }
30
+ export interface DecisionRecord {
31
+ timestamp: string;
32
+ gate_version: string;
33
+ final_status: ConfirmGateStatus;
34
+ layers_passed: string[];
35
+ layers_failed: string[];
36
+ }
37
+ export interface PassportGuardInfo {
38
+ guard: string;
39
+ result: boolean;
40
+ impack: boolean;
41
+ }
42
+ export interface ObjectPassport {
43
+ object: string;
44
+ info: PassportGuardInfo[];
45
+ result: boolean;
46
+ tx_hash: string;
47
+ impack_guard: string[];
48
+ time: number;
49
+ signer: string;
50
+ has_verified: boolean;
51
+ }
52
+ export interface ObjectGuard {
53
+ object: string;
54
+ relies?: string[];
55
+ relies_logic_and?: boolean;
56
+ table?: {
57
+ identifier: number;
58
+ value_type: string;
59
+ b_submission: boolean;
60
+ }[];
61
+ }
62
+ export type PassportOperation = {
63
+ type: "guard_add";
64
+ guard: string;
65
+ impack: boolean;
66
+ submission?: {
67
+ identifier: number;
68
+ value: unknown;
69
+ value_type: string;
70
+ }[];
71
+ } | {
72
+ type: "verify";
73
+ } | {
74
+ type: "guard_clear";
75
+ } | {
76
+ type: "freezen";
77
+ } | {
78
+ type: "destroy";
79
+ } | {
80
+ type: "result_query";
81
+ } | {
82
+ type: "result_for_guard";
83
+ guard: string;
84
+ } | {
85
+ type: "result_for_permission";
86
+ } | {
87
+ type: "submission_get";
88
+ guard: string;
89
+ identifier: number;
90
+ };
91
+ export declare const PASSPORT_CONFIRMATION_RULES: {
92
+ creation: PassportConfirmationRule[];
93
+ operation: PassportConfirmationRule[];
94
+ consistency: PassportConfirmationRule[];
95
+ };
96
+ export interface CreationCheckInput {
97
+ clock: string | null;
98
+ txDigest: string | null;
99
+ }
100
+ export declare function preCheckPassportCreation(input: CreationCheckInput): CheckResult;
101
+ export interface OperationCheckInput {
102
+ passport: ObjectPassport;
103
+ operation: PassportOperation;
104
+ guardObjects: Map<string, ObjectGuard>;
105
+ }
106
+ export declare function preCheckPassportOperation(input: OperationCheckInput): CheckResult;
107
+ export interface ConsistencyCheckInput {
108
+ passport: ObjectPassport;
109
+ guardObjects: Map<string, ObjectGuard>;
110
+ isFrozen: boolean;
111
+ }
112
+ export declare function checkPassportStateConsistency(input: ConsistencyCheckInput): CheckResult;
113
+ export declare const PASSPORT_CONFIRM_VERSION = "1.0.0";
114
+ export interface ConfirmGateInput {
115
+ creation_input?: CreationCheckInput;
116
+ operation_input?: OperationCheckInput;
117
+ consistency_input?: ConsistencyCheckInput;
118
+ skip_risk_assessment?: boolean;
119
+ skip_user_confirmation?: boolean;
120
+ scenario?: PassportScenario;
121
+ }
122
+ export declare function runPassportConfirmGate(input: ConfirmGateInput): ConfirmGateResult;
123
+ export declare function estimateSubmissionSize(submission: {
124
+ identifier: number;
125
+ value: unknown;
126
+ value_type: string;
127
+ }[]): number;
128
+ export declare function getAllConfirmationRules(): PassportConfirmationRule[];
129
+ export declare function getConfirmationRulesByLayer(layer: "creation" | "operation" | "consistency"): PassportConfirmationRule[];
130
+ export declare function getConfirmationRuleById(id: string): PassportConfirmationRule | undefined;