@wowok/agent-mcp 2.3.16 → 2.4.1

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 (136) hide show
  1. package/dist/customer/index.d.ts +9 -0
  2. package/dist/customer/index.js +9 -0
  3. package/dist/customer/industry-risks.d.ts +4 -0
  4. package/dist/customer/industry-risks.js +45 -31
  5. package/dist/customer/order-monitor.js +57 -57
  6. package/dist/customer/order-strategy.js +89 -89
  7. package/dist/customer/post-purchase.js +97 -97
  8. package/dist/customer/reminder-system.js +26 -26
  9. package/dist/customer/risk-assessment.js +46 -46
  10. package/dist/customer/types.d.ts +4 -4
  11. package/dist/customer/types.js +4 -4
  12. package/dist/customer/user-preferences.d.ts +3 -0
  13. package/dist/customer/user-preferences.js +59 -50
  14. package/dist/experience/intent-distill.js +6 -6
  15. package/dist/experience/realtime-feedback.js +17 -0
  16. package/dist/index.js +360 -273
  17. package/dist/knowledge/acquisition-flywheel.d.ts +3 -0
  18. package/dist/knowledge/acquisition-flywheel.js +73 -64
  19. package/dist/knowledge/arbitration-trust.js +10 -10
  20. package/dist/knowledge/demand-matching.js +8 -8
  21. package/dist/knowledge/dynamic-pricing.js +18 -18
  22. package/dist/knowledge/flywheel-loop.js +11 -11
  23. package/dist/knowledge/glossary.js +22 -22
  24. package/dist/knowledge/guard-ledger.d.ts +19 -0
  25. package/dist/knowledge/guard-ledger.js +246 -0
  26. package/dist/knowledge/guard-lint.d.ts +76 -0
  27. package/dist/knowledge/guard-lint.js +590 -0
  28. package/dist/knowledge/guard-puzzle.d.ts +188 -0
  29. package/dist/knowledge/guard-puzzle.js +804 -0
  30. package/dist/knowledge/guard-risk.d.ts +67 -0
  31. package/dist/knowledge/guard-risk.js +1046 -0
  32. package/dist/knowledge/guard-templates.d.ts +37 -0
  33. package/dist/knowledge/guard-templates.js +329 -0
  34. package/dist/knowledge/guard-translation.d.ts +58 -0
  35. package/dist/knowledge/guard-translation.js +1118 -0
  36. package/dist/knowledge/index.d.ts +17 -0
  37. package/dist/knowledge/index.js +17 -0
  38. package/dist/knowledge/industry-evolution.js +29 -29
  39. package/dist/knowledge/industry-generalizer.js +52 -52
  40. package/dist/knowledge/industry-registry.d.ts +1 -2
  41. package/dist/knowledge/industry-registry.js +43 -36
  42. package/dist/knowledge/intent-metrics.js +67 -67
  43. package/dist/knowledge/process-model.js +80 -80
  44. package/dist/knowledge/reputation-rules.js +9 -9
  45. package/dist/knowledge/reward-templates.js +51 -51
  46. package/dist/knowledge/safety-rules.js +63 -2
  47. package/dist/knowledge/tool-constraints.js +17 -11
  48. package/dist/knowledge/trust-metrics.js +26 -26
  49. package/dist/safety/confirm-gate.d.ts +4 -2
  50. package/dist/safety/confirm-gate.js +48 -4
  51. package/dist/schema/call/allocation.d.ts +24 -14
  52. package/dist/schema/call/arbitration.d.ts +142 -132
  53. package/dist/schema/call/base.d.ts +901 -43
  54. package/dist/schema/call/base.js +77 -13
  55. package/dist/schema/call/bridge-handler.js +15 -2
  56. package/dist/schema/call/bridge.d.ts +795 -27
  57. package/dist/schema/call/bridge.js +37 -0
  58. package/dist/schema/call/contact.d.ts +10 -0
  59. package/dist/schema/call/demand.d.ts +94 -84
  60. package/dist/schema/call/guard.d.ts +229 -46
  61. package/dist/schema/call/guard.js +50 -0
  62. package/dist/schema/call/handler.js +46 -14
  63. package/dist/schema/call/machine.d.ts +158 -138
  64. package/dist/schema/call/order.d.ts +10 -0
  65. package/dist/schema/call/payment.d.ts +10 -0
  66. package/dist/schema/call/permission.d.ts +314 -304
  67. package/dist/schema/call/personal.d.ts +10 -0
  68. package/dist/schema/call/progress.d.ts +10 -0
  69. package/dist/schema/call/proof.d.ts +20 -0
  70. package/dist/schema/call/repository.d.ts +32 -22
  71. package/dist/schema/call/reward.d.ts +10 -0
  72. package/dist/schema/call/semantic.d.ts +9 -2
  73. package/dist/schema/call/semantic.js +617 -25
  74. package/dist/schema/call/service.d.ts +20 -10
  75. package/dist/schema/call/treasury.d.ts +10 -0
  76. package/dist/schema/config/index.d.ts +18 -0
  77. package/dist/schema/config/index.js +17 -0
  78. package/dist/schema/index.d.ts +6 -0
  79. package/dist/schema/index.js +5 -0
  80. package/dist/schema/local/index.d.ts +9 -9
  81. package/dist/schema/local/index.js +9 -0
  82. package/dist/schema/local/wip.d.ts +39 -19
  83. package/dist/schema/local/wip.js +5 -5
  84. package/dist/schema/messenger/index.d.ts +376 -55
  85. package/dist/schema/messenger/index.js +19 -19
  86. package/dist/schema/operations.d.ts +1881 -681
  87. package/dist/schema/operations.js +91 -96
  88. package/dist/schema/project/index.d.ts +21 -0
  89. package/dist/schema/project/index.js +32 -0
  90. package/dist/schema/query/index.d.ts +1074 -168
  91. package/dist/schema/query/index.js +8 -8
  92. package/dist/schema/schema-query/index.d.ts +33 -0
  93. package/dist/schema/schema-query/index.js +36 -0
  94. package/dist/schema/schema-version.d.ts +25 -0
  95. package/dist/schema/schema-version.js +76 -0
  96. package/dist/schema/trust/index.d.ts +407 -0
  97. package/dist/schema/trust/index.js +113 -0
  98. package/dist/schema/utils/guard-parser.js +4 -4
  99. package/dist/schema/utils/node-parser.js +14 -14
  100. package/dist/schemas/bridge_operation.output.json +233 -9
  101. package/dist/schemas/bridge_operation.schema.json +67 -8
  102. package/dist/schemas/config_operation.output.json +18 -0
  103. package/dist/schemas/config_operation.schema.json +34 -0
  104. package/dist/schemas/guard-node-schema.json +82 -0
  105. package/dist/schemas/guard2file.schema.json +8 -0
  106. package/dist/schemas/index.json +19 -1
  107. package/dist/schemas/machineNode2file.schema.json +8 -0
  108. package/dist/schemas/messenger_operation.output.json +236 -10
  109. package/dist/schemas/onchain_events.output.json +718 -0
  110. package/dist/schemas/onchain_operations.output.json +286 -11
  111. package/dist/schemas/onchain_operations.schema.json +19 -16
  112. package/dist/schemas/onchain_operations_allocation.schema.json +8 -0
  113. package/dist/schemas/onchain_operations_arbitration.schema.json +8 -0
  114. package/dist/schemas/onchain_operations_contact.schema.json +8 -0
  115. package/dist/schemas/onchain_operations_demand.schema.json +8 -0
  116. package/dist/schemas/onchain_operations_gen_passport.schema.json +16 -0
  117. package/dist/schemas/onchain_operations_guard.schema.json +11 -16
  118. package/dist/schemas/onchain_operations_machine.schema.json +8 -0
  119. package/dist/schemas/onchain_operations_order.schema.json +8 -0
  120. package/dist/schemas/onchain_operations_payment.schema.json +8 -0
  121. package/dist/schemas/onchain_operations_permission.schema.json +8 -0
  122. package/dist/schemas/onchain_operations_personal.schema.json +8 -0
  123. package/dist/schemas/onchain_operations_progress.schema.json +8 -0
  124. package/dist/schemas/onchain_operations_repository.schema.json +8 -0
  125. package/dist/schemas/onchain_operations_reward.schema.json +8 -0
  126. package/dist/schemas/onchain_operations_service.schema.json +8 -0
  127. package/dist/schemas/onchain_operations_treasury.schema.json +8 -0
  128. package/dist/schemas/onchain_table_data.output.json +718 -0
  129. package/dist/schemas/project_operation.output.json +18 -0
  130. package/dist/schemas/project_operation.schema.json +42 -0
  131. package/dist/schemas/query_toolkit.schema.json +360 -368
  132. package/dist/schemas/schema_query.schema.json +6 -3
  133. package/dist/schemas/trust_score.output.json +327 -0
  134. package/dist/schemas/trust_score.schema.json +46 -0
  135. package/dist/schemas/wip_file.output.json +24 -1
  136. package/package.json +2 -2
@@ -0,0 +1,1118 @@
1
+ export const SEMANTIC_TO_SCHEMA_RULES = [
2
+ {
3
+ id: "P02",
4
+ pattern_name: "Query published object + system context",
5
+ data_source_combination: "Type1 + Type4",
6
+ semantic_intent: "Query published on-chain object fields and compare with system context",
7
+ match_keywords: ["paused", "published", "service status", "machine status", "paused", "published"],
8
+ schema_elements: {
9
+ root_type: "logic_equal / logic_and",
10
+ table_entries: [
11
+ { value_type: "Address", b_submission: false, purpose: "Published object address constant (Type1)" },
12
+ ],
13
+ context_nodes: [
14
+ { context_type: "Signer", purpose: "Optional: identity validation" },
15
+ ],
16
+ tree_structure: "logic_equal(query(<instruction>, object: { identifier: 0 }), identifier[1] or context(Signer))",
17
+ },
18
+ constraints: [
19
+ "The object_type of table[0] must match the target object type of the query instruction",
20
+ "The query return type must be compatible with the comparison object",
21
+ "The object must be published (published=true) to ensure fields are immutable",
22
+ ],
23
+ example: {
24
+ root: {
25
+ type: "logic_equal",
26
+ nodes: [
27
+ { type: "query", query: "service.paused", object: { identifier: 0 }, parameters: [] },
28
+ { type: "identifier", identifier: 1 },
29
+ ],
30
+ },
31
+ table: [
32
+ { identifier: 0, b_submission: false, value_type: "Address", value: "0xSERVICE", name: "Service object address" },
33
+ { identifier: 1, b_submission: false, value_type: "Bool", value: false, name: "Expected paused state (false=not paused)" },
34
+ ],
35
+ },
36
+ },
37
+ {
38
+ id: "P03",
39
+ pattern_name: "Identity check (single address)",
40
+ data_source_combination: "Type4 + Type1 constant",
41
+ semantic_intent: "Only a specific address can perform the operation",
42
+ match_keywords: ["only", "allow", "authorize", "identity", "specified address", "signer"],
43
+ schema_elements: {
44
+ root_type: "logic_equal",
45
+ table_entries: [
46
+ { value_type: "Address", b_submission: false, purpose: "Authorized address constant (Type1 constant)" },
47
+ ],
48
+ context_nodes: [
49
+ { context_type: "Signer", purpose: "Current transaction signer (Type4)" },
50
+ ],
51
+ tree_structure: "logic_equal(context(Signer), identifier[0])",
52
+ },
53
+ constraints: [
54
+ "root must be logic_equal (returns Bool)",
55
+ "table[0] must be Address type, b_submission=false",
56
+ "context(Signer) returns the current transaction signer address",
57
+ ],
58
+ example: {
59
+ root: {
60
+ type: "logic_equal",
61
+ nodes: [
62
+ { type: "context", context: "Signer" },
63
+ { type: "identifier", identifier: 0 },
64
+ ],
65
+ },
66
+ table: [
67
+ { identifier: 0, b_submission: false, value_type: "Address", value: "0xabc...", name: "Authorized operator address" },
68
+ ],
69
+ },
70
+ },
71
+ {
72
+ id: "P04",
73
+ pattern_name: "Identity check (whitelist)",
74
+ data_source_combination: "Type4 + Type1 constant (VecAddress)",
75
+ semantic_intent: "Addresses in the whitelist can perform this operation",
76
+ match_keywords: ["whitelist", "multiple addresses", "list", "allowlist", "roster"],
77
+ schema_elements: {
78
+ root_type: "vec_contains_address",
79
+ table_entries: [
80
+ { value_type: "VecAddress", b_submission: false, purpose: "Authorized address list (Type1 constant)" },
81
+ ],
82
+ context_nodes: [
83
+ { context_type: "Signer", purpose: "Signer being looked up (Type4)" },
84
+ ],
85
+ tree_structure: "vec_contains_address(identifier[0], context(Signer))",
86
+ },
87
+ constraints: [
88
+ "root vec_contains_address returns Bool",
89
+ "table[0] must be VecAddress type",
90
+ "context(Signer) is the element being looked up",
91
+ ],
92
+ example: {
93
+ root: {
94
+ type: "vec_contains_address",
95
+ nodes: [
96
+ { type: "identifier", identifier: 0 },
97
+ { type: "context", context: "Signer" },
98
+ ],
99
+ },
100
+ table: [
101
+ { identifier: 0, b_submission: false, value_type: "VecAddress", value: ["0xabc...", "0xdef..."], name: "Authorized address whitelist" },
102
+ ],
103
+ },
104
+ },
105
+ {
106
+ id: "P05",
107
+ pattern_name: "Time lock",
108
+ data_source_combination: "Type2 + Type4 + Type1 constant",
109
+ semantic_intent: "This operation can only be executed after waiting N milliseconds",
110
+ match_keywords: ["wait", "time", "lock", "delay", "hours", "days", "milliseconds"],
111
+ schema_elements: {
112
+ root_type: "logic_as_u256_greater_or_equal",
113
+ table_entries: [
114
+ { value_type: "Address", b_submission: true, purpose: "Source object address (e.g. Order, Type3) or constant (Type1)" },
115
+ { value_type: "U64", b_submission: false, purpose: "Lock duration (in milliseconds, 1000 for tests, Type1 constant)" },
116
+ ],
117
+ query_nodes: [
118
+ { query_name: "progress.current_time", object_type: "Progress", convert_witness: 100 },
119
+ ],
120
+ context_nodes: [
121
+ { context_type: "Clock", purpose: "Current on-chain timestamp (Type4)" },
122
+ ],
123
+ tree_structure: "logic_as_u256_greater_or_equal(context(Clock), calc_number_add(query(1272: progress.current_time, witness=100, identifier[0]), identifier[1]))",
124
+ },
125
+ constraints: [
126
+ "Time unit is milliseconds; use 1000ms for tests and adjust in production",
127
+ "convert_witness=100 (TypeOrderProgress) converts from Order to Progress",
128
+ "The object_type of table[0] must match the witness source type (Order)",
129
+ "calc_number_add returns U256, context(Clock) returns U64, auto-widened",
130
+ "Key: use progress.current_time(1272) rather than progress.session.forward.time(1271); the latter querying an unforwarded session returns 0 and disables the time lock",
131
+ ],
132
+ example: {
133
+ root: {
134
+ type: "logic_as_u256_greater_or_equal",
135
+ nodes: [
136
+ { type: "context", context: "Clock" },
137
+ {
138
+ type: "calc_number_add",
139
+ nodes: [
140
+ {
141
+ type: "query",
142
+ query: "progress.current_time",
143
+ object: { identifier: 0, convert_witness: 100 },
144
+ parameters: [],
145
+ },
146
+ { type: "identifier", identifier: 1 },
147
+ ],
148
+ },
149
+ ],
150
+ },
151
+ table: [
152
+ { identifier: 0, b_submission: true, value_type: "Address", name: "Target Order address", object_type: "Order" },
153
+ { identifier: 1, b_submission: false, value_type: "U64", value: 1000, name: "Lock duration (milliseconds)" },
154
+ ],
155
+ },
156
+ },
157
+ {
158
+ id: "P06",
159
+ pattern_name: "Progress state check",
160
+ data_source_combination: "Type2 + Type1 constant",
161
+ semantic_intent: "The order progress must reach the specified node before this operation can be executed",
162
+ match_keywords: ["progress", "node", "state", "completed", "reach", "current node"],
163
+ schema_elements: {
164
+ root_type: "logic_equal",
165
+ table_entries: [
166
+ { value_type: "Address", b_submission: true, purpose: "Source Order address (Type3, witness source)" },
167
+ { value_type: "String", b_submission: false, purpose: "Expected node name (Type1 constant)" },
168
+ ],
169
+ query_nodes: [
170
+ { query_name: "progress.current", object_type: "Progress", convert_witness: 100 },
171
+ ],
172
+ tree_structure: "logic_equal(query(1253: progress.current, witness=100, identifier[0]), identifier[1])",
173
+ },
174
+ constraints: [
175
+ "query returns String; identifier[1] must be String type",
176
+ "logic_equal comparison on String is case-sensitive",
177
+ "For case-insensitive comparison, use logic_string_nocase_equal",
178
+ "convert_witness=100 (TypeOrderProgress) converts from Order",
179
+ "Type2 stacks on Type3: the source object Order is submitted (b_submission=true)",
180
+ ],
181
+ example: {
182
+ root: {
183
+ type: "logic_equal",
184
+ nodes: [
185
+ {
186
+ type: "query",
187
+ query: "progress.current",
188
+ object: { identifier: 0, convert_witness: 100 },
189
+ parameters: [],
190
+ },
191
+ { type: "identifier", identifier: 1 },
192
+ ],
193
+ },
194
+ table: [
195
+ { identifier: 0, b_submission: true, value_type: "Address", name: "Target Order address", object_type: "Order" },
196
+ { identifier: 1, b_submission: false, value_type: "String", value: "Completed", name: "Expected progress node name" },
197
+ ],
198
+ },
199
+ },
200
+ {
201
+ id: "P07",
202
+ pattern_name: "One-time claim check",
203
+ data_source_combination: "Type3 + Type1 constant",
204
+ semantic_intent: "Users can only claim the reward once",
205
+ match_keywords: ["once", "claim", "duplicate", "already claimed", "claimed before"],
206
+ schema_elements: {
207
+ root_type: "logic_equal",
208
+ table_entries: [
209
+ { value_type: "Address", b_submission: true, purpose: "Reward object address (Type3, submitted)" },
210
+ { value_type: "U64", b_submission: false, purpose: "Expected historical claim count 0 (Type1 constant)" },
211
+ ],
212
+ query_nodes: [
213
+ { query_name: "reward.record.count", object_type: "Reward" },
214
+ ],
215
+ tree_structure: "logic_equal(query_reward_record_count(object: { identifier: 0 }, recipient: context(Signer)), identifier[1])",
216
+ },
217
+ constraints: [
218
+ "query_reward_record_count returns U64",
219
+ "Comparing count == 0 means no history record (can claim)",
220
+ "recipient defaults to context(Signer) to ensure the claimer's identity is bound",
221
+ "Type3 submitted objects must have constraint rules (here the constraint is count==0 and recipient=Signer)",
222
+ ],
223
+ example: {
224
+ root: {
225
+ type: "logic_equal",
226
+ nodes: [
227
+ {
228
+ type: "query_reward_record_count",
229
+ object: { identifier: 0 },
230
+ },
231
+ { type: "identifier", identifier: 1 },
232
+ ],
233
+ },
234
+ table: [
235
+ { identifier: 0, b_submission: true, value_type: "Address", name: "Reward object address", object_type: "Reward" },
236
+ { identifier: 1, b_submission: false, value_type: "U64", value: 0, name: "Expected historical claim count (0)" },
237
+ ],
238
+ },
239
+ },
240
+ {
241
+ id: "P08",
242
+ pattern_name: "Submitted object identity validation",
243
+ data_source_combination: "Type3 + Type4",
244
+ semantic_intent: "Verify that the owner of the submitted object matches the signer",
245
+ match_keywords: ["ownership", "belonging", "customer", "submitted object", "order.customer"],
246
+ schema_elements: {
247
+ root_type: "logic_equal",
248
+ table_entries: [
249
+ { value_type: "Address", b_submission: true, purpose: "Submitted Order address (Type3)" },
250
+ ],
251
+ context_nodes: [
252
+ { context_type: "Signer", purpose: "Current signer (Type4), compared with order.customer" },
253
+ ],
254
+ query_nodes: [
255
+ { query_name: "order.customer", object_type: "Order" },
256
+ ],
257
+ tree_structure: "logic_equal(query(1550: order.customer, object: { identifier: 0 }), context(Signer))",
258
+ },
259
+ constraints: [
260
+ "query returns Address, context(Signer) returns Address, types compatible",
261
+ "Type3 submitted object constraint: indirectly binds submitter identity via order.customer == Signer",
262
+ "Ensures callers cannot submit other users' Order addresses",
263
+ ],
264
+ example: {
265
+ root: {
266
+ type: "logic_equal",
267
+ nodes: [
268
+ {
269
+ type: "query",
270
+ query: "order.customer",
271
+ object: { identifier: 0 },
272
+ parameters: [],
273
+ },
274
+ { type: "context", context: "Signer" },
275
+ ],
276
+ },
277
+ table: [
278
+ { identifier: 0, b_submission: true, value_type: "Address", name: "User-submitted Order address", object_type: "Order" },
279
+ ],
280
+ },
281
+ },
282
+ {
283
+ id: "P09",
284
+ pattern_name: "Submitted object + witness derivation query",
285
+ data_source_combination: "Type3 + Type2 (source is Type3)",
286
+ semantic_intent: "User submits an Order and queries the Progress state via witness",
287
+ match_keywords: ["submit", "derive", "witness", "order to progress", "convert"],
288
+ schema_elements: {
289
+ root_type: "logic_equal / logic_and",
290
+ table_entries: [
291
+ { value_type: "Address", b_submission: true, purpose: "Submitted Order address (Type3, witness source)" },
292
+ { value_type: "String", b_submission: false, purpose: "Expected node name (Type1 constant)" },
293
+ ],
294
+ query_nodes: [
295
+ { query_name: "progress.current", object_type: "Progress", convert_witness: 100 },
296
+ ],
297
+ tree_structure: "logic_equal(query(1253: progress.current, object: { identifier: 0, convert_witness: 100 }), identifier[1])",
298
+ },
299
+ constraints: [
300
+ "Type2 stacks on Type3: the source object Order has b_submission=true",
301
+ "witness=100 (TypeOrderProgress) derives Progress from the submitted Order",
302
+ "query returns String; identifier[1] must be String type",
303
+ "Key: Type2 can stack on Type1 or Type3, depending on the source object's b_submission",
304
+ ],
305
+ example: {
306
+ root: {
307
+ type: "logic_equal",
308
+ nodes: [
309
+ {
310
+ type: "query",
311
+ query: "progress.current",
312
+ object: { identifier: 0, convert_witness: 100 },
313
+ parameters: [],
314
+ },
315
+ { type: "identifier", identifier: 1 },
316
+ ],
317
+ },
318
+ table: [
319
+ { identifier: 0, b_submission: true, value_type: "Address", name: "User-submitted Order address", object_type: "Order" },
320
+ { identifier: 1, b_submission: false, value_type: "String", value: "Inspecting", name: "Expected progress node name" },
321
+ ],
322
+ },
323
+ },
324
+ {
325
+ id: "P10",
326
+ pattern_name: "Multi-condition combination (AND/OR)",
327
+ data_source_combination: "Type1 + Type2 + Type3 + Type4 (combination)",
328
+ semantic_intent: "Multiple conditions must all be satisfied (AND) or any one is satisfied (OR)",
329
+ match_keywords: ["and", "simultaneously", "all satisfied", "AND", "and also", "also need", "or", "any", "OR", "or", "one of"],
330
+ schema_elements: {
331
+ root_type: "logic_and / logic_or",
332
+ table_entries: [],
333
+ tree_structure: "logic_and/logic_or([condition1, condition2, ...]) — each condition can be any combination of P03-P09",
334
+ },
335
+ constraints: [
336
+ "All subnodes of logic_and/logic_or must return Bool",
337
+ "Subnode count 2-8 (MAX_MULTI_OPERANDS)",
338
+ "Each subcondition can be any node that returns Bool",
339
+ "Multi-condition combination is a container for other Patterns and does not stand alone",
340
+ ],
341
+ example: {
342
+ root: {
343
+ type: "logic_and",
344
+ nodes: [
345
+ {},
346
+ {},
347
+ ],
348
+ },
349
+ },
350
+ },
351
+ {
352
+ id: "P11",
353
+ pattern_name: "Entity registration check",
354
+ data_source_combination: "Type1 system address + Type3",
355
+ semantic_intent: "Verify that the user is registered in the entity registrar",
356
+ match_keywords: ["register", "entity", "EntityRegistrar", "member", "certify"],
357
+ schema_elements: {
358
+ root_type: "logic_and",
359
+ table_entries: [
360
+ { value_type: "Address", b_submission: false, purpose: "EntityRegistrar system address 0xaab (Type1 system address)" },
361
+ { value_type: "Address", b_submission: true, purpose: "User address (Type3, submitted)" },
362
+ ],
363
+ query_nodes: [
364
+ { query_name: "entity.registrar.records", object_type: "EntityRegistrar" },
365
+ ],
366
+ tree_structure: "logic_and(query(1760: entity.registrar.records, object: { identifier: 0 }, parameters: [identifier[1]]), ...)",
367
+ },
368
+ constraints: [
369
+ "EntityRegistrar address is fixed at 0xaab (system address)",
370
+ "EntityLinker address is fixed at 0xaaa",
371
+ "table[0] has is_system_address=true",
372
+ "query parameters must match the instruction definition",
373
+ ],
374
+ example: {
375
+ root: {
376
+ type: "logic_and",
377
+ nodes: [
378
+ {
379
+ type: "query",
380
+ query: "entity.registrar.records",
381
+ object: { identifier: 0 },
382
+ parameters: [{ type: "identifier", identifier: 1 }],
383
+ },
384
+ ],
385
+ },
386
+ table: [
387
+ { identifier: 0, b_submission: false, value_type: "Address", value: "0xaab", name: "EntityRegistrar system address" },
388
+ { identifier: 1, b_submission: true, value_type: "Address", name: "User address (submitted)" },
389
+ ],
390
+ },
391
+ },
392
+ {
393
+ id: "P12",
394
+ pattern_name: "Dynamic voting weight",
395
+ data_source_combination: "Type3 + Type4 + Type1 constant",
396
+ semantic_intent: "Voting weight equals the reputation score (extracted from submitted data)",
397
+ match_keywords: ["weight", "vote", "reputation", "score", "voting", "weight"],
398
+ schema_elements: {
399
+ root_type: "logic_and",
400
+ table_entries: [
401
+ { value_type: "Address", b_submission: true, purpose: "Voter address (Type3)" },
402
+ { value_type: "U64", b_submission: true, purpose: "Voter weight (Type3, extracted by GuardIdentifier)" },
403
+ ],
404
+ context_nodes: [
405
+ { context_type: "Signer", purpose: "Validate voter identity (Type4)" },
406
+ ],
407
+ query_nodes: [
408
+ { query_name: "entity.registrar.records", object_type: "EntityRegistrar" },
409
+ ],
410
+ tree_structure: "logic_and(identity check: logic_equal(context(Signer), identifier[0]), weight comparison: GuardIdentifier extracts identifier[1])",
411
+ },
412
+ constraints: [
413
+ "The table entry referenced by GuardIdentifier must be numeric (U8-U256)",
414
+ "b_submission must be true (weight is submitted at runtime by the voter)",
415
+ "Non-numeric types cause E_GUARD_IDENTIFIER_NOT_NUMBER error",
416
+ "Weight value is cast to u32",
417
+ "voting_guard scene special constraint: GuardIdentifier numeric",
418
+ ],
419
+ example: {
420
+ root: {
421
+ type: "logic_and",
422
+ nodes: [
423
+ {},
424
+ {},
425
+ ],
426
+ },
427
+ table: [
428
+ { identifier: 0, b_submission: true, value_type: "Address", name: "Voter address" },
429
+ { identifier: 1, b_submission: true, value_type: "U64", name: "Voter weight (extracted from reputation score)" },
430
+ ],
431
+ },
432
+ },
433
+ {
434
+ id: "P13",
435
+ pattern_name: "Repository data query",
436
+ data_source_combination: "Type1 + Type2",
437
+ semantic_intent: "Query Repository data and validate",
438
+ match_keywords: ["Repository", "storage", "data source", "weather", "external data", "oracle"],
439
+ schema_elements: {
440
+ root_type: "logic_and",
441
+ table_entries: [
442
+ { value_type: "Address", b_submission: false, purpose: "Repository address (Type1 constant)" },
443
+ ],
444
+ query_nodes: [
445
+ { query_name: "repository.data", object_type: "Repository" },
446
+ ],
447
+ tree_structure: "logic_and(query(1167: repository.data, object: { identifier: 0 }, parameters: [...]), [data validation condition])",
448
+ },
449
+ constraints: [
450
+ "The quote_guard authentication of query 1167 always has empty impack_list during the verify phase",
451
+ "Repository queries with quote_guard fail with IMPACK_GUARD_NOT_FOUND in the gen_passport flow",
452
+ "Only passes when quote_guard==None",
453
+ "rep semantics: repository.data query does not depend on runtime submission, so rep=true",
454
+ ],
455
+ example: {
456
+ root: {
457
+ type: "logic_and",
458
+ nodes: [
459
+ {
460
+ type: "query",
461
+ query: "repository.data",
462
+ object: { identifier: 0 },
463
+ parameters: [{ type: "identifier", identifier: 1 }],
464
+ },
465
+ {},
466
+ ],
467
+ },
468
+ table: [
469
+ { identifier: 0, b_submission: false, value_type: "Address", value: "0xREPO", name: "Repository address" },
470
+ ],
471
+ },
472
+ },
473
+ {
474
+ id: "P14",
475
+ pattern_name: "Pure dependency combination",
476
+ data_source_combination: "None (rely only)",
477
+ semantic_intent: "Does not compute itself; fully depends on the results of other Guards",
478
+ match_keywords: ["depend", "combine", "reuse", "rely", "delegate"],
479
+ schema_elements: {
480
+ root_type: "logic_and / logic_or (minimized tautology)",
481
+ table_entries: [],
482
+ tree_structure: "root: minimized (e.g. context(Clock) >= 0, tautology) + rely: { guards: [...], logic_or: false }",
483
+ },
484
+ constraints: [
485
+ "Depended-on Guards must have rep=true (repository.data query does not depend on runtime submission)",
486
+ "rely.guards supports at most 4 (MAX_DEPENDED_COUNT)",
487
+ "Self-reference is forbidden",
488
+ "AND logic: all dependencies must pass; OR logic: any one passing is sufficient",
489
+ ],
490
+ example: {
491
+ root: {
492
+ type: "logic_as_u256_greater_or_equal",
493
+ nodes: [
494
+ { type: "context", context: "Clock" },
495
+ { type: "identifier", identifier: 0 },
496
+ ],
497
+ },
498
+ table: [
499
+ { identifier: 0, b_submission: false, value_type: "U64", value: 0, name: "Tautology baseline value (0)" },
500
+ ],
501
+ rely: { guards: ["guard_a", "guard_b"], logic_or: false },
502
+ },
503
+ },
504
+ {
505
+ id: "P15",
506
+ pattern_name: "Submission data retention pattern (retained_submission)",
507
+ data_source_combination: "Type3 + Type4 (submission + system context binding)",
508
+ semantic_intent: "Guard accepts runtime-submitted data but ensures it is trustworthy via Signer binding and type checking",
509
+ match_keywords: ["submit", "retain", "retained", "submission", "bind signer", "submission check"],
510
+ schema_elements: {
511
+ root_type: "logic_and",
512
+ table_entries: [
513
+ { value_type: "Address", b_submission: true, purpose: "Submitted object address (Type3, requires Signer binding)" },
514
+ { value_type: "U256", b_submission: true, purpose: "Submitted numeric value (e.g. amount, weight, requires range check)" },
515
+ ],
516
+ context_nodes: [
517
+ { context_type: "Signer", purpose: "Validate submitter identity to ensure submission data ownership" },
518
+ ],
519
+ tree_structure: "logic_and(logic_equal(context(Signer), query(..., signer_field)), logic_as_u256_greater_or_equal(identifier[1], identifier[2]))",
520
+ },
521
+ constraints: [
522
+ "The name of each b_submission=true entry must be a complete natural-language description (not a technical identifier)",
523
+ "The submitted object address should be bound to Signer (query the signer/owner field of the submitted object to validate ownership)",
524
+ "Submitted numeric values should have range checks (>= min, <= max)",
525
+ "Total table size must not exceed 40000 bytes",
526
+ "Total submission bytes must not exceed 256",
527
+ ],
528
+ example: {
529
+ root: {
530
+ type: "logic_and",
531
+ nodes: [
532
+ {
533
+ type: "logic_equal",
534
+ nodes: [
535
+ { type: "context", context: "Signer" },
536
+ {
537
+ type: "query",
538
+ query: 1237,
539
+ object: { identifier: 0 },
540
+ parameters: [],
541
+ },
542
+ ],
543
+ },
544
+ {
545
+ type: "logic_as_u256_greater_or_equal",
546
+ nodes: [
547
+ { type: "identifier", identifier: 1 },
548
+ { type: "identifier", identifier: 2 },
549
+ ],
550
+ },
551
+ ],
552
+ },
553
+ table: [
554
+ { identifier: 0, b_submission: true, value_type: "Address", name: "Submitted Order object address; must belong to the current signer" },
555
+ { identifier: 1, b_submission: true, value_type: "U256", name: "Submitted amount (unit: MIST); must be >= minimum amount" },
556
+ { identifier: 2, b_submission: false, value_type: "U256", value: 1000000, name: "Minimum amount constant (1 MIST)" },
557
+ ],
558
+ },
559
+ },
560
+ {
561
+ id: "P16",
562
+ pattern_name: "Circular reference pattern (Guard references the host object itself)",
563
+ data_source_combination: "Type1 (host object as constant, using name instead of address)",
564
+ semantic_intent: "Guard binds to a Host Object while querying the Host Object's own fields; uses name reference to achieve circular binding",
565
+ match_keywords: ["circular reference", "self", "host", "host", "circular", "self-reference"],
566
+ schema_elements: {
567
+ root_type: "logic_equal / logic_and",
568
+ table_entries: [
569
+ { value_type: "Address", b_submission: false, purpose: "Host object name (SDK resolves to address at binding time)" },
570
+ ],
571
+ query_nodes: [
572
+ { query_name: "query_service_* / query_machine_*", object_type: "Service / Machine" },
573
+ ],
574
+ tree_structure: "logic_equal(query(<host_field_query>, object: { identifier: 0 }), identifier[1] or context(Signer))",
575
+ },
576
+ constraints: [
577
+ "The Host Object must not be published (bPublished=false) when creating and binding the Guard",
578
+ "Use the Host Object name (not address) in the table; the SDK resolves it at binding time",
579
+ "The Host Object can only be published after the Guard is bound",
580
+ "Guard verification only runs normally after the Host Object is published",
581
+ "Use guard2file to export Guard backups for easy rebuilding",
582
+ ],
583
+ example: {
584
+ root: {
585
+ type: "logic_equal",
586
+ nodes: [
587
+ {
588
+ type: "query",
589
+ query: 1231,
590
+ object: { identifier: 0 },
591
+ parameters: [],
592
+ },
593
+ { type: "identifier", identifier: 1 },
594
+ ],
595
+ },
596
+ table: [
597
+ { identifier: 0, b_submission: false, value_type: "Address", value: "my_service", name: "Host Service name (circular reference, resolved by SDK at binding time)" },
598
+ { identifier: 1, b_submission: false, value_type: "Bool", value: false, name: "Expected Service paused state (false=not paused)" },
599
+ ],
600
+ },
601
+ },
602
+ {
603
+ id: "P17",
604
+ pattern_name: "Query parameter translation pattern (type conversion node combination)",
605
+ data_source_combination: "Type1/2 + type conversion (query parameter type translation)",
606
+ semantic_intent: "Guard queries parameters that require type conversion (e.g. Address → U64 timestamp key); uses convert_* nodes to translate",
607
+ match_keywords: ["type conversion", "translate", "convert", "timestamp key", "parameter translation", "address to u64"],
608
+ schema_elements: {
609
+ root_type: "logic_equal / logic_as_u256_greater_or_equal",
610
+ table_entries: [
611
+ { value_type: "Address", b_submission: false, purpose: "Query target object address (Type1/2)" },
612
+ { value_type: "U64", b_submission: false, purpose: "Comparison baseline value (e.g. timestamp threshold)" },
613
+ ],
614
+ query_nodes: [
615
+ { query_name: "query_repository_data / query_progress_history_*", object_type: "Repository / Progress" },
616
+ ],
617
+ tree_structure: "logic_as_u256_greater_or_equal(query(<query_with_converted_param>, object: { identifier: 0 }, parameters: [convert_number_address(identifier[1])]), identifier[2])",
618
+ },
619
+ constraints: [
620
+ "The query parameter type must match the parameters type defined in GUARDQUERY",
621
+ "If the table declares Address but the query requires U64, convert_number_address must be used to translate",
622
+ "The input type of convert_* nodes must be compatible with the child node's return type",
623
+ "The translated type must match the parameters definition of the query instruction",
624
+ "Use wowok_buildin_info info='guard instructions' to verify parameter types",
625
+ ],
626
+ example: {
627
+ root: {
628
+ type: "logic_as_u256_greater_or_equal",
629
+ nodes: [
630
+ {
631
+ type: "query",
632
+ query: 1167,
633
+ object: { identifier: 0 },
634
+ parameters: [
635
+ {
636
+ type: "convert_number_address",
637
+ nodes: [
638
+ { type: "identifier", identifier: 1 },
639
+ ],
640
+ },
641
+ ],
642
+ },
643
+ { type: "identifier", identifier: 2 },
644
+ ],
645
+ },
646
+ table: [
647
+ { identifier: 0, b_submission: false, value_type: "Address", value: "0xrepo", name: "Repository address constant" },
648
+ { identifier: 1, b_submission: false, value_type: "U64", value: 1700000000000, name: "Timestamp key (U64, needs to be converted to Address for Repository query)" },
649
+ { identifier: 2, b_submission: false, value_type: "U256", value: 100, name: "Expected Repository data value" },
650
+ ],
651
+ },
652
+ },
653
+ ];
654
+ export const SCHEMA_TO_SEMANTIC_RULES = [
655
+ { element_type: "node", type_name: "logic_equal", semantic: "Equality comparison (==), returns Bool. Accepts any type but both operands must be type-compatible", return_type: "Bool", child_constraints: "2 child nodes, types must be compatible" },
656
+ { element_type: "node", type_name: "logic_not", semantic: "Logical NOT (!), returns Bool", return_type: "Bool", child_constraints: "1 child node, must be Bool" },
657
+ { element_type: "node", type_name: "logic_and", semantic: "Logical AND; true if all child nodes are true", return_type: "Bool", child_constraints: "2-8 Bool child nodes (MAX_MULTI_OPERANDS)" },
658
+ { element_type: "node", type_name: "logic_or", semantic: "Logical OR; true if any child node is true", return_type: "Bool", child_constraints: "2-8 Bool child nodes" },
659
+ { element_type: "node", type_name: "logic_as_u256_greater", semantic: "Numeric greater than (>), auto-widened to U256", return_type: "Bool", child_constraints: "2 numeric child nodes (U8-U256 compatible)" },
660
+ { element_type: "node", type_name: "logic_as_u256_lesser", semantic: "Numeric less than (<)", return_type: "Bool", child_constraints: "2 numeric child nodes" },
661
+ { element_type: "node", type_name: "logic_as_u256_equal", semantic: "Numeric equality (==)", return_type: "Bool", child_constraints: "2 numeric child nodes" },
662
+ { element_type: "node", type_name: "logic_as_u256_greater_or_equal", semantic: "Numeric greater than or equal (>=)", return_type: "Bool", child_constraints: "2 numeric child nodes" },
663
+ { element_type: "node", type_name: "logic_as_u256_lesser_or_equal", semantic: "Numeric less than or equal (<=)", return_type: "Bool", child_constraints: "2 numeric child nodes" },
664
+ { element_type: "node", type_name: "logic_string_contains", semantic: "String contains (case-sensitive)", return_type: "Bool", child_constraints: "2 String child nodes" },
665
+ { element_type: "node", type_name: "logic_string_nocase_contains", semantic: "String contains (case-insensitive)", return_type: "Bool", child_constraints: "2 String child nodes" },
666
+ { element_type: "node", type_name: "logic_string_nocase_equal", semantic: "String equality (case-insensitive)", return_type: "Bool", child_constraints: "2 String child nodes" },
667
+ { element_type: "node", type_name: "identifier", semantic: "References the value of a table entry. The data source type depends on b_submission: false=Type1 constant, true=Type3 submitted", return_type: "Determined by table entry value_type", child_constraints: "No child nodes; requires identifier field to reference table", data_source_class: "Type1_OnChainConstant" },
668
+ { element_type: "node", type_name: "context", semantic: "Transaction context data (Type4 SystemContext). Signer=signer address, Clock=on-chain timestamp (U64), Guard=ObjectID of the Guard currently being verified", return_type: "Address (Signer/Guard) / U64 (Clock)", child_constraints: "No child nodes", data_source_class: "Type4_SystemContext" },
669
+ { element_type: "node", type_name: "query", semantic: "Queries on-chain object data. The data source type depends on object.convert_witness: present=Type2 (witness-derived), absent+constant=Type1, absent+submitted=Type3", return_type: "Determined by the query instruction", child_constraints: "Requires query + object + parameters fields", data_source_class: "Type1_OnChainConstant", discovery_tool: "wowok_buildin_info(info='guard instructions')" },
670
+ { element_type: "node", type_name: "calc_number_add", semantic: "Numeric addition", return_type: "U256", child_constraints: "2 numeric child nodes" },
671
+ { element_type: "node", type_name: "calc_number_subtract", semantic: "Numeric subtraction", return_type: "U256", child_constraints: "2 numeric child nodes" },
672
+ { element_type: "node", type_name: "calc_number_multiply", semantic: "Numeric multiplication", return_type: "U256", child_constraints: "2 numeric child nodes" },
673
+ { element_type: "node", type_name: "calc_number_divide", semantic: "Numeric division", return_type: "U256", child_constraints: "2 numeric child nodes" },
674
+ { element_type: "node", type_name: "calc_number_mod", semantic: "Numeric modulo", return_type: "U256", child_constraints: "2 numeric child nodes" },
675
+ { element_type: "node", type_name: "calc_string_length", semantic: "String length", return_type: "U64", child_constraints: "1 String child node" },
676
+ { element_type: "node", type_name: "calc_string_contains", semantic: "String contains (returns Bool)", return_type: "Bool", child_constraints: "2 String child nodes" },
677
+ { element_type: "node", type_name: "calc_string_nocase_contains", semantic: "String contains (case-insensitive, returns Bool)", return_type: "Bool", child_constraints: "2 String child nodes" },
678
+ { element_type: "node", type_name: "calc_string_nocase_equal", semantic: "String equality (case-insensitive, returns Bool)", return_type: "Bool", child_constraints: "2 String child nodes" },
679
+ { element_type: "node", type_name: "calc_string_indexof", semantic: "String find index", return_type: "U64", child_constraints: "2 String child nodes + order" },
680
+ { element_type: "node", type_name: "calc_string_nocase_indexof", semantic: "String find index (case-insensitive)", return_type: "U64", child_constraints: "2 String child nodes + order" },
681
+ { element_type: "node", type_name: "convert_number_address", semantic: "Number → Address conversion (e.g. timestamp to address)", return_type: "Address", child_constraints: "1 numeric child node" },
682
+ { element_type: "node", type_name: "convert_address_number", semantic: "Address → Number conversion", return_type: "U256", child_constraints: "1 Address child node" },
683
+ { element_type: "node", type_name: "convert_number_string", semantic: "Number → String conversion", return_type: "String", child_constraints: "1 numeric child node" },
684
+ { element_type: "node", type_name: "convert_string_number", semantic: "String → Number conversion", return_type: "U256", child_constraints: "1 String child node" },
685
+ { element_type: "node", type_name: "convert_safe_u8", semantic: "Safe conversion to U8 (errors on overflow)", return_type: "U8", child_constraints: "1 numeric child node" },
686
+ { element_type: "node", type_name: "convert_safe_u16", semantic: "Safe conversion to U16", return_type: "U16", child_constraints: "1 numeric child node" },
687
+ { element_type: "node", type_name: "convert_safe_u32", semantic: "Safe conversion to U32", return_type: "U32", child_constraints: "1 numeric child node" },
688
+ { element_type: "node", type_name: "convert_safe_u64", semantic: "Safe conversion to U64", return_type: "U64", child_constraints: "1 numeric child node" },
689
+ { element_type: "node", type_name: "convert_safe_u128", semantic: "Safe conversion to U128", return_type: "U128", child_constraints: "1 numeric child node" },
690
+ { element_type: "node", type_name: "convert_safe_u256", semantic: "Safe conversion to U256", return_type: "U256", child_constraints: "1 numeric child node" },
691
+ { element_type: "node", type_name: "value_type", semantic: "Returns the value's type identifier (U8) — used for dynamic type checking", return_type: "U8", child_constraints: "1 variable child node" },
692
+ { element_type: "node", type_name: "vec_length", semantic: "Vector length", return_type: "U64", child_constraints: "1 vec child node" },
693
+ { element_type: "node", type_name: "vec_contains_bool", semantic: "Whether the vector contains a Bool value", return_type: "Bool", child_constraints: "1 VecBool + 1 Bool" },
694
+ { element_type: "node", type_name: "vec_contains_address", semantic: "Whether the vector contains an Address (whitelist check)", return_type: "Bool", child_constraints: "1 VecAddress + 1 Address" },
695
+ { element_type: "node", type_name: "vec_contains_string", semantic: "Whether the vector contains a String", return_type: "Bool", child_constraints: "1 VecString + 1 String" },
696
+ { element_type: "node", type_name: "vec_contains_string_nocase", semantic: "Whether the vector contains a String (case-insensitive)", return_type: "Bool", child_constraints: "1 VecString + 1 String" },
697
+ { element_type: "node", type_name: "vec_contains_number", semantic: "Whether the vector contains a number", return_type: "Bool", child_constraints: "1 Vec* + 1 Number" },
698
+ { element_type: "node", type_name: "vec_indexof_bool", semantic: "Bool vector find index", return_type: "U64", child_constraints: "VecBool + Bool + order" },
699
+ { element_type: "node", type_name: "vec_indexof_address", semantic: "Address vector find index", return_type: "U64", child_constraints: "VecAddress + Address + order" },
700
+ { element_type: "node", type_name: "vec_indexof_string", semantic: "String vector find index", return_type: "U64", child_constraints: "VecString + String + order" },
701
+ { element_type: "node", type_name: "vec_indexof_string_nocase", semantic: "String vector find index (case-insensitive)", return_type: "U64", child_constraints: "VecString + String + order" },
702
+ { element_type: "node", type_name: "vec_indexof_number", semantic: "Numeric vector find index", return_type: "U64", child_constraints: "Vec* + Number + order" },
703
+ { element_type: "node", type_name: "query_reward_record_find", semantic: "Query reward claim records (returns the found record)", return_type: "Bool", child_constraints: "Requires object + recipient + where + find" },
704
+ { element_type: "node", type_name: "query_reward_record_count", semantic: "Query reward claim record count (U64)", return_type: "U64", child_constraints: "Requires object + recipient (optional)" },
705
+ { element_type: "node", type_name: "query_reward_record_exists", semantic: "Query whether a reward claim record exists (Bool)", return_type: "Bool", child_constraints: "Requires object + recipient (optional)" },
706
+ { element_type: "node", type_name: "query_progress_history_find", semantic: "Query whether a specified session exists in Progress history", return_type: "Bool", child_constraints: "Requires object + where + find" },
707
+ { element_type: "node", type_name: "query_progress_history_session_find", semantic: "Query a Progress session", return_type: "Bool", child_constraints: "Requires object + historyIdx + where + find" },
708
+ { element_type: "node", type_name: "query_progress_history_session_forward_find", semantic: "Query whether a specified forward exists in a Progress session", return_type: "Bool", child_constraints: "Requires object + historyIdx + sessionIdx + where + find" },
709
+ { element_type: "node", type_name: "query_progress_history_session_count", semantic: "Query the number of Progress sessions", return_type: "U64", child_constraints: "Requires object + historyIdx" },
710
+ { element_type: "node", type_name: "query_progress_history_session_forward_count", semantic: "Query the number of forwards in a Progress session", return_type: "U64", child_constraints: "Requires object + historyIdx + sessionIdx" },
711
+ { element_type: "node", type_name: "query_progress_history_session_forward_retained_submission_count", semantic: "Query the retained submission count of a forward in a Progress session", return_type: "U64", child_constraints: "Requires object + historyIdx + sessionIdx + forwardIdx" },
712
+ { element_type: "witness", type_name: "TypeOrderProgress", semantic: "Reads the order.progress field from an Order address to derive Progress (100, single hop)", data_source_class: "Type2_WitnessDerived", discovery_tool: "wowok_buildin_info(info='guard instructions')" },
713
+ { element_type: "witness", type_name: "TypeOrderMachine", semantic: "Reads the order.machine field from an Order address to derive Machine (101, single hop)", data_source_class: "Type2_WitnessDerived" },
714
+ { element_type: "witness", type_name: "TypeOrderService", semantic: "Reads the order.service field from an Order address to derive Service (102, single hop)", data_source_class: "Type2_WitnessDerived" },
715
+ { element_type: "witness", type_name: "TypeProgressMachine", semantic: "Reads the progress.machine field from a Progress address to derive Machine (103, single hop)", data_source_class: "Type2_WitnessDerived" },
716
+ { element_type: "witness", type_name: "TypeArbOrder", semantic: "Reads the arb.order field from an Arb address to derive Order (104, single hop)", data_source_class: "Type2_WitnessDerived" },
717
+ { element_type: "witness", type_name: "TypeArbArbitration", semantic: "Reads the arb.arbitration field from an Arb address to derive the parent Arbitration service (105, single hop)", data_source_class: "Type2_WitnessDerived" },
718
+ { element_type: "witness", type_name: "TypeArbProgress", semantic: "Derives from Arb in two hops: arb.order → order.progress (106, multi-hop)", data_source_class: "Type2_WitnessDerived" },
719
+ { element_type: "witness", type_name: "TypeArbMachine", semantic: "Derives from Arb in two hops: arb.order → order.machine (107, multi-hop)", data_source_class: "Type2_WitnessDerived" },
720
+ { element_type: "witness", type_name: "TypeArbService", semantic: "Derives from Arb in two hops: arb.order → order.service (108, multi-hop)", data_source_class: "Type2_WitnessDerived" },
721
+ { element_type: "context", type_name: "Signer", semantic: "Current transaction signer address (TransactionContext.sender())", return_type: "Address", data_source_class: "Type4_SystemContext" },
722
+ { element_type: "context", type_name: "Clock", semantic: "Current on-chain timestamp (reads timestamp_ms of WOW_CLOCK_OBJECT_ID 0x6)", return_type: "U64", data_source_class: "Type4_SystemContext" },
723
+ { element_type: "context", type_name: "Guard", semantic: "ObjectID of the Guard object currently being verified (self-reference, rare)", return_type: "Address", data_source_class: "Type4_SystemContext" },
724
+ { element_type: "table_entry", type_name: "Bool", semantic: "Boolean constant or submission" },
725
+ { element_type: "table_entry", type_name: "Address", semantic: "Address constant (Type1) or submission (Type3). Object address type" },
726
+ { element_type: "table_entry", type_name: "String", semantic: "String constant or submission" },
727
+ { element_type: "table_entry", type_name: "U8", semantic: "8-bit unsigned integer" },
728
+ { element_type: "table_entry", type_name: "U16", semantic: "16-bit unsigned integer" },
729
+ { element_type: "table_entry", type_name: "U32", semantic: "32-bit unsigned integer" },
730
+ { element_type: "table_entry", type_name: "U64", semantic: "64-bit unsigned integer (commonly used for timestamps)" },
731
+ { element_type: "table_entry", type_name: "U128", semantic: "128-bit unsigned integer" },
732
+ { element_type: "table_entry", type_name: "U256", semantic: "256-bit unsigned integer (auto-widening target for numeric operations)" },
733
+ { element_type: "table_entry", type_name: "VecAddress", semantic: "Address vector (used for whitelists, Type1 constant)" },
734
+ { element_type: "table_entry", type_name: "VecString", semantic: "String vector" },
735
+ { element_type: "table_entry", type_name: "VecU64", semantic: "U64 vector" },
736
+ { element_type: "table_entry", type_name: "VecU8", semantic: "U8 vector (raw bytes)" },
737
+ { element_type: "table_entry", type_name: "Value", semantic: "Dynamic type (19, first byte is the type identifier) — used for Repository data, EntityRegistrar records, Passport submission value" },
738
+ { element_type: "rely", type_name: "rely_and", semantic: "Depends on other Guards, AND logic (all must pass). Depended-on Guards must have rep=true", child_constraints: "At most 4 dependencies, each with rep=true (repository.data query does not depend on submission)" },
739
+ { element_type: "rely", type_name: "rely_or", semantic: "Depends on other Guards, OR logic (any one passing is sufficient). Depended-on Guards must have rep=true", child_constraints: "At most 4 dependencies, each with rep=true" },
740
+ ];
741
+ export const GUARD_CONSTRAINT_RULES = [
742
+ {
743
+ id: "ROOT_01",
744
+ name: "root returns Bool",
745
+ description: "The Guard root node must return a Bool type",
746
+ category: "root",
747
+ phase: "creation",
748
+ validation_logic: "root.node_type must be in the allowedTypes list (logic_*, calc_string_contains, vec_contains_*, query_reward_record_exists, query[Bool return], identifier[Bool type])",
749
+ failure_message: "Guard root node must be an operation that returns Bool",
750
+ verification_location: "SDK buildNode(root, ValueType.Bool, ...)",
751
+ pitfall_number: 7,
752
+ },
753
+ {
754
+ id: "TABLE_01",
755
+ name: "identifier uniqueness",
756
+ description: "Each identifier in the table must be unique (0-255)",
757
+ category: "table",
758
+ phase: "creation",
759
+ validation_logic: "No duplicate identifiers in the table",
760
+ failure_message: "Duplicate table identifier",
761
+ verification_location: "SDK lodash groupBy",
762
+ },
763
+ {
764
+ id: "TABLE_02",
765
+ name: "identifier referential integrity",
766
+ description: "Every identifier node in the computation tree must exist in the table",
767
+ category: "table",
768
+ phase: "creation",
769
+ validation_logic: "Traverse the computation tree; each identifier node's index exists in the table",
770
+ failure_message: "Identifier not found in table",
771
+ verification_location: "SDK buildNode",
772
+ pitfall_number: 1,
773
+ },
774
+ {
775
+ id: "TABLE_03",
776
+ name: "Constant entries must have a value",
777
+ description: "Entries with b_submission=false must have a value field",
778
+ category: "table",
779
+ phase: "creation",
780
+ validation_logic: "All entries with b_submission=false have a non-empty value field",
781
+ failure_message: "Constant table entry must have a value",
782
+ verification_location: "SDK operate",
783
+ },
784
+ {
785
+ id: "TABLE_04",
786
+ name: "table size limit",
787
+ description: "At most 256 entries; serialized size must not exceed 40000 bytes",
788
+ category: "table",
789
+ phase: "creation",
790
+ validation_logic: "table.length <= 256 && serialize(table).length <= 40000",
791
+ failure_message: "Table exceeds size limit (256 entries or 40000 bytes)",
792
+ verification_location: "Move guard::new",
793
+ },
794
+ {
795
+ id: "TABLE_05",
796
+ name: "submission entry value is 1 byte (type code only)",
797
+ description: "Entries with b_submission=true have a serialized value of just 1 byte (the type code)",
798
+ category: "table",
799
+ phase: "creation",
800
+ validation_logic: "When b_submission=true, bcsValue.length === 1 and bcsValue[0] === valueType",
801
+ failure_message: "Submission table entry value must be 1 byte (type code only)",
802
+ verification_location: "native deserialize_constants",
803
+ },
804
+ {
805
+ id: "QUERY_01",
806
+ name: "query instruction valid",
807
+ description: "The query field of a query node must be a valid GUARDQUERY ID or name",
808
+ category: "query",
809
+ phase: "creation",
810
+ validation_logic: "The query field exists in GUARDQUERY (via isValidGuardQueryIdOrName)",
811
+ failure_message: "Invalid Guard query instruction",
812
+ verification_location: "SDK getGuardQueryInfo",
813
+ pitfall_number: 3,
814
+ },
815
+ {
816
+ id: "QUERY_02",
817
+ name: "query parameter count match",
818
+ description: "The number and types of parameters in a query node must match the instruction definition",
819
+ category: "query",
820
+ phase: "creation",
821
+ validation_logic: "parameters.length === instruction.parameters.length && type-compatible",
822
+ failure_message: "Query parameter count or type mismatch",
823
+ verification_location: "SDK buildNode",
824
+ pitfall_number: 3,
825
+ },
826
+ {
827
+ id: "QUERY_03",
828
+ name: "query return type compatible",
829
+ description: "The return type of a query node must be compatible with the parent node's expected type",
830
+ category: "query",
831
+ phase: "creation",
832
+ validation_logic: "checkType(query.return_type, parent.expected_type)",
833
+ failure_message: "Query return type incompatible with parent node",
834
+ verification_location: "SDK checkType",
835
+ },
836
+ {
837
+ id: "QUERY_04",
838
+ name: "query object identifier's value_type is Address",
839
+ description: "The table entry referenced by query node's object.identifier must have value_type of Address",
840
+ category: "query",
841
+ phase: "creation",
842
+ validation_logic: "table[object.identifier].value_type === Address",
843
+ failure_message: "Query object identifier must reference an Address-type table entry",
844
+ verification_location: "SDK buildNode L603-609",
845
+ },
846
+ {
847
+ id: "WITNESS_01",
848
+ name: "witness type valid",
849
+ description: "convert_witness must be a valid WitnessType (100-108)",
850
+ category: "witness",
851
+ phase: "creation",
852
+ validation_logic: "The witness value is within the range allowed by WitnessTypeSchema (100-108)",
853
+ failure_message: "Invalid witness type",
854
+ verification_location: "SDK isWitnessType",
855
+ pitfall_number: 4,
856
+ },
857
+ {
858
+ id: "WITNESS_02",
859
+ name: "witness target matches query objectType",
860
+ description: "The witness's target type must match the query instruction's objectType",
861
+ category: "witness",
862
+ phase: "creation",
863
+ validation_logic: "witness.target_type === instruction.objectType",
864
+ failure_message: "Witness target type does not match query object type",
865
+ verification_location: "SDK buildNode L613-619",
866
+ pitfall_number: 4,
867
+ },
868
+ {
869
+ id: "WITNESS_03",
870
+ name: "witness source matches tableItem object_type",
871
+ description: "The witness's source type must match the object_type declared in the table entry (if declared)",
872
+ category: "witness",
873
+ phase: "creation",
874
+ validation_logic: "table[identifier].object_type === witness.source_type (if tableItem.object_type is declared)",
875
+ failure_message: "Witness source type does not match table entry object_type",
876
+ verification_location: "SDK buildNode L622-631",
877
+ pitfall_number: 4,
878
+ },
879
+ {
880
+ id: "RELY_01",
881
+ name: "rely dependency count ≤ 4",
882
+ description: "rely.guards supports at most 4 dependencies (MAX_DEPENDED_COUNT)",
883
+ category: "rely",
884
+ phase: "creation",
885
+ validation_logic: "rely.guards.length <= 4",
886
+ failure_message: "Rely dependencies exceed limit (4)",
887
+ verification_location: "SDK reliesAdd",
888
+ },
889
+ {
890
+ id: "RELY_02",
891
+ name: "rely dependency rep=true",
892
+ description: "All rely-depended Guards must have rep=true (repository.data query does not depend on runtime submission)",
893
+ category: "rely",
894
+ phase: "creation",
895
+ validation_logic: "Query each depended Guard's rep field; must be true",
896
+ failure_message: "Rely dependency has rep=false (not standalone)",
897
+ verification_location: "Move guard::relies_add",
898
+ pitfall_number: 8,
899
+ },
900
+ {
901
+ id: "RELY_03",
902
+ name: "rely forbids self-reference",
903
+ description: "A Guard cannot depend on itself",
904
+ category: "rely",
905
+ phase: "creation",
906
+ validation_logic: "rely.guards does not contain the current Guard's address",
907
+ failure_message: "Guard cannot rely on itself",
908
+ verification_location: "SDK reliesAdd",
909
+ },
910
+ {
911
+ id: "BINDING_01",
912
+ name: "voting_guard GuardIdentifier numeric",
913
+ description: "The table entry referenced by Arbitration voting_guard's GuardIdentifier must be of a numeric type",
914
+ category: "binding",
915
+ phase: "creation",
916
+ validation_logic: "If binding=voting_guard, the table entry pointed to by GuardIdentifier has value_type in [U8,U16,U32,U64,U128,U256]",
917
+ failure_message: "E_GUARD_IDENTIFIER_NOT_NUMBER: voting_guard weight must be numeric",
918
+ verification_location: "Move Arbitration",
919
+ pitfall_number: 9,
920
+ },
921
+ {
922
+ id: "BINDING_02",
923
+ name: "Repository id_from_submission Address",
924
+ description: "The table entry referenced by Repository write_guard's id_from_submission must be of Address type",
925
+ category: "binding",
926
+ phase: "creation",
927
+ validation_logic: "If binding=write_guard and id_from_submission is set, table[id_from_submission].value_type === Address",
928
+ failure_message: "Repository id_from_submission must be Address type",
929
+ verification_location: "Move Repository",
930
+ },
931
+ {
932
+ id: "BINDING_03",
933
+ name: "Repository data_from_submission type match",
934
+ description: "The table entry referenced by Repository write_guard's data_from_submission must match the Repository value_type",
935
+ category: "binding",
936
+ phase: "creation",
937
+ validation_logic: "If binding=write_guard and data_from_submission is set, table[data_from_submission].value_type === Repository.value_type",
938
+ failure_message: "Repository data_from_submission type mismatch",
939
+ verification_location: "Move Repository",
940
+ },
941
+ {
942
+ id: "INPUT_01",
943
+ name: "root byte stream non-empty",
944
+ description: "The serialized byte stream of root cannot be empty",
945
+ category: "input",
946
+ phase: "creation",
947
+ validation_logic: "input.length > 0",
948
+ failure_message: "Input cannot be empty",
949
+ verification_location: "SDK newGuard",
950
+ },
951
+ {
952
+ id: "INPUT_02",
953
+ name: "root byte stream ≤ MAX_INPUT_SIZE",
954
+ description: "The serialized byte stream of root must not exceed MAX_INPUT_SIZE",
955
+ category: "input",
956
+ phase: "creation",
957
+ validation_logic: "input.length <= MAX_INPUT_SIZE",
958
+ failure_message: "Input size exceeds maximum limit",
959
+ verification_location: "SDK newGuard",
960
+ },
961
+ {
962
+ id: "IMMUTABLE_01",
963
+ name: "Guard immutable=true after creation",
964
+ description: "After creation, a Guard cannot be modified or deleted (CREATE-only)",
965
+ category: "immutable",
966
+ phase: "creation",
967
+ validation_logic: "After guard::create, the immutable field is set to true",
968
+ failure_message: "Guard is immutable after creation",
969
+ verification_location: "Move guard::create",
970
+ },
971
+ {
972
+ id: "RUN_IMMUTABLE_01",
973
+ name: "Guard must be immutable=true to verify",
974
+ description: "At runtime verification, the Guard must be frozen (immutable=true)",
975
+ category: "immutable",
976
+ phase: "runtime",
977
+ validation_logic: "guard.immutable === true",
978
+ failure_message: "Guard must be immutable to verify",
979
+ verification_location: "native verify_guard L497-506",
980
+ },
981
+ {
982
+ id: "RUN_SUB_01",
983
+ name: "submission type byte matches table declaration",
984
+ description: "The value[0] (type byte) of submission must match the value_type declared in the table",
985
+ category: "table",
986
+ phase: "runtime",
987
+ validation_logic: "submission_value[0] === table[identifier].value_type",
988
+ failure_message: "Submission type byte does not match table declaration",
989
+ verification_location: "native parse_table_items L306",
990
+ },
991
+ {
992
+ id: "RUN_SUB_02",
993
+ name: "table entries with b_submission=true must be found in submission",
994
+ description: "All table entries declared as submitted must have corresponding submission data",
995
+ category: "table",
996
+ phase: "runtime",
997
+ validation_logic: "forall identifier in table where b_submission=true: identifier in submission_map",
998
+ failure_message: "Missing submission for declared b_submission=true table entry",
999
+ verification_location: "native parse_table_items L301-321",
1000
+ },
1001
+ {
1002
+ id: "RUN_SUB_03",
1003
+ name: "submission total bytes ≤ MAX_SUBMISSION_SIZE (256)",
1004
+ description: "The total bytes of all data submitted at runtime must not exceed 256",
1005
+ category: "table",
1006
+ phase: "runtime",
1007
+ validation_logic: "total_submission_bytes <= 256",
1008
+ failure_message: "Submission exceeds MAX_SUBMISSION_SIZE (256 bytes)",
1009
+ verification_location: "Move verify L252",
1010
+ },
1011
+ {
1012
+ id: "RUN_WITNESS_01",
1013
+ name: "witness derivation source object must have the required relation field",
1014
+ description: "When witness conversion occurs, the source object must contain the relation field needed for derivation",
1015
+ category: "witness",
1016
+ phase: "runtime",
1017
+ validation_logic: "The source object exists and contains the field required for witness derivation (e.g. order.progress field is non-empty)",
1018
+ failure_message: "Witness source object missing required field for derivation",
1019
+ verification_location: "native convert_witness",
1020
+ },
1021
+ {
1022
+ id: "RUN_WITNESS_02",
1023
+ name: "witness-derived target object must exist",
1024
+ description: "The target object derived by witness must exist on-chain",
1025
+ category: "witness",
1026
+ phase: "runtime",
1027
+ validation_logic: "The derived target object ID exists on-chain",
1028
+ failure_message: "Witness derived target object does not exist",
1029
+ verification_location: "native convert_witness",
1030
+ },
1031
+ {
1032
+ id: "RUN_QUERY_01",
1033
+ name: "query target object must exist and type match",
1034
+ description: "The target object of a query must exist on-chain and its type must match",
1035
+ category: "query",
1036
+ phase: "runtime",
1037
+ validation_logic: "Target object exists && object type matches query.objectType",
1038
+ failure_message: "Query target object does not exist or type mismatch",
1039
+ verification_location: "native process_object_query",
1040
+ },
1041
+ {
1042
+ id: "RUN_IMPACK_01",
1043
+ name: "at least one impack guard",
1044
+ description: "Passport verification requires at least one impack guard",
1045
+ category: "runtime",
1046
+ phase: "runtime",
1047
+ validation_logic: "impack_list.length >= 1 (note: impack_list is always empty during verify phase; this constraint is checked in result_for_permission phase)",
1048
+ failure_message: "No impack guard found",
1049
+ verification_location: "Move verify L281",
1050
+ },
1051
+ {
1052
+ id: "RUN_IMPACK_02",
1053
+ name: "impack guard failure fails the entire passport",
1054
+ description: "If any impack guard verification fails, the entire passport verification fails",
1055
+ category: "runtime",
1056
+ phase: "runtime",
1057
+ validation_logic: "forall guard in impack_list: guard.result === true",
1058
+ failure_message: "Impack guard verification failed",
1059
+ verification_location: "Move verify L270-275",
1060
+ },
1061
+ {
1062
+ id: "RUN_TX_01",
1063
+ name: "Passport tx_hash must match the current transaction",
1064
+ description: "The tx_hash recorded in the Passport must match the hash of the currently executing transaction",
1065
+ category: "runtime",
1066
+ phase: "runtime",
1067
+ validation_logic: "passport.tx_hash === current_tx_hash",
1068
+ failure_message: "Passport tx_hash does not match current transaction",
1069
+ verification_location: "Move verify L231",
1070
+ },
1071
+ {
1072
+ id: "RUN_RELY_01",
1073
+ name: "rely guard must have been added to passport",
1074
+ description: "Guards relied on must have been registered in the passport",
1075
+ category: "rely",
1076
+ phase: "runtime",
1077
+ validation_logic: "forall guard in rely.guards: guard in passport.relies",
1078
+ failure_message: "Rely guard not added to passport",
1079
+ verification_location: "Move calculate_relies_result",
1080
+ },
1081
+ ];
1082
+ export function matchSemanticPattern(userIntent) {
1083
+ const lower = userIntent.toLowerCase();
1084
+ return SEMANTIC_TO_SCHEMA_RULES.filter((rule) => rule.match_keywords.some((kw) => lower.includes(kw.toLowerCase())));
1085
+ }
1086
+ export function explainNode(nodeType) {
1087
+ return SCHEMA_TO_SEMANTIC_RULES.find((r) => r.element_type === "node" && r.type_name === nodeType);
1088
+ }
1089
+ export function explainWitness(witnessType) {
1090
+ const witnessMap = {
1091
+ 100: "TypeOrderProgress",
1092
+ 101: "TypeOrderMachine",
1093
+ 102: "TypeOrderService",
1094
+ 103: "TypeProgressMachine",
1095
+ 104: "TypeArbOrder",
1096
+ 105: "TypeArbArbitration",
1097
+ 106: "TypeArbProgress",
1098
+ 107: "TypeArbMachine",
1099
+ 108: "TypeArbService",
1100
+ };
1101
+ const name = witnessMap[witnessType];
1102
+ return SCHEMA_TO_SEMANTIC_RULES.find((r) => r.element_type === "witness" && r.type_name === name);
1103
+ }
1104
+ export function explainContext(contextType) {
1105
+ return SCHEMA_TO_SEMANTIC_RULES.find((r) => r.element_type === "context" && r.type_name === contextType);
1106
+ }
1107
+ export function getConstraintsByCategory(category) {
1108
+ return GUARD_CONSTRAINT_RULES.filter((r) => r.category === category);
1109
+ }
1110
+ export function getConstraintsByPhase(phase) {
1111
+ return GUARD_CONSTRAINT_RULES.filter((r) => r.phase === phase);
1112
+ }
1113
+ export function getPatternById(id) {
1114
+ return SEMANTIC_TO_SCHEMA_RULES.find((r) => r.id === id);
1115
+ }
1116
+ export function getDataSourceCombinations() {
1117
+ return [...new Set(SEMANTIC_TO_SCHEMA_RULES.map((r) => r.data_source_combination))];
1118
+ }