@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
@@ -3,7 +3,7 @@ export const CONCEPT_GLOSSARY = [
3
3
  term: "Permission",
4
4
  definition: "Organization-wide permission object. indices 0-999 builtin, 1000-65535 custom. " +
5
5
  "Shared across all Progress instances of a Service. Use for internal staff roles.",
6
- aliases: ["permission object", "权限对象"],
6
+ aliases: ["permission object"],
7
7
  category: "permission",
8
8
  },
9
9
  {
@@ -17,7 +17,7 @@ export const CONCEPT_GLOSSARY = [
17
17
  term: "OrderHolder",
18
18
  definition: "The order holder and their agents. Represented by namedOperator=\"\" (empty string) " +
19
19
  "on a Forward. Lets the customer operate their own order.",
20
- aliases: ["order owner", "orderholder", "订单持有人"],
20
+ aliases: ["order owner", "orderholder", "order holder"],
21
21
  category: "permission",
22
22
  },
23
23
  {
@@ -25,139 +25,139 @@ export const CONCEPT_GLOSSARY = [
25
25
  definition: "A state-transition edge in a Machine. Carries weight, a permission " +
26
26
  "(Permission index / NamedOperator / OrderHolder), and an optional Guard. " +
27
27
  "Every Forward MUST define at least one permission.",
28
- aliases: ["迁移", "transition"],
28
+ aliases: ["transition"],
29
29
  category: "operation",
30
30
  },
31
31
  {
32
32
  term: "Pair",
33
33
  definition: "A prev_node → next_node transition group in a Machine with a threshold. " +
34
34
  "When the cumulative weight of executed Forwards meets the threshold, the Pair fires.",
35
- aliases: ["迁移对", "transition pair"],
35
+ aliases: ["transition pair"],
36
36
  category: "operation",
37
37
  },
38
38
  {
39
39
  term: "Machine",
40
40
  definition: "Workflow blueprint (directed graph). Becomes immutable after publish. " +
41
41
  "A Progress instance is created per order from the Machine.",
42
- aliases: ["工作流模板", "machine template"],
42
+ aliases: ["machine template"],
43
43
  category: "object",
44
44
  },
45
45
  {
46
46
  term: "Progress",
47
47
  definition: "A workflow instance bound to one order. Advances via Forwards; " +
48
48
  "carries retained_submission values for Guard verification.",
49
- aliases: ["流程实例", "progress instance"],
49
+ aliases: ["progress instance"],
50
50
  category: "object",
51
51
  },
52
52
  {
53
53
  term: "Guard",
54
54
  definition: "Immutable static validation rule. Verifies submissions and on-chain object data. " +
55
55
  "Returns boolean. Cannot be mutated after creation.",
56
- aliases: ["守卫", "guard object"],
56
+ aliases: ["guard object"],
57
57
  category: "acceptance",
58
58
  },
59
59
  {
60
60
  term: "Repository",
61
61
  definition: "Mutable dynamic acceptance store. Keyed by (name, entity). " +
62
62
  "Used for data that can change over time (e.g. SLA config, review records).",
63
- aliases: ["仓库", "repository object"],
63
+ aliases: ["repository object"],
64
64
  category: "acceptance",
65
65
  },
66
66
  {
67
67
  term: "Acceptance",
68
68
  definition: "The verification standard for a process step. Composed of static Guard + " +
69
69
  "dynamic Repository. Drives whether a Forward can execute.",
70
- aliases: ["验收标准", "acceptance standard"],
70
+ aliases: ["acceptance standard"],
71
71
  category: "acceptance",
72
72
  },
73
73
  {
74
74
  term: "Service",
75
75
  definition: "A merchant's service listing. References Machine, order_allocators, arbitrations, " +
76
76
  "compensation_fund, rewards, buy_guard. machine & order_allocators lock after publish.",
77
- aliases: ["服务", "service object"],
77
+ aliases: ["service object"],
78
78
  category: "object",
79
79
  },
80
80
  {
81
81
  term: "Order",
82
82
  definition: "An order against a Service. Funds are escrowed; released via Progress + Allocation. " +
83
83
  "Arb cases attach to orders for dispute resolution.",
84
- aliases: ["订单"],
84
+ aliases: ["order instance"],
85
85
  category: "object",
86
86
  },
87
87
  {
88
88
  term: "Allocator",
89
89
  definition: "Fund distribution rules. Priority: Amount → Rate → Surplus. first-Guard-wins. " +
90
90
  "Locked on Service publish (order_allocators).",
91
- aliases: ["分账器", "allocation"],
91
+ aliases: ["allocation"],
92
92
  category: "fund",
93
93
  },
94
94
  {
95
95
  term: "Allocation",
96
96
  definition: "The act of distributing escrowed funds to recipients per an Allocator. " +
97
97
  "Executed by the order holder or Permission holder.",
98
- aliases: ["分账"],
98
+ aliases: ["allocation act"],
99
99
  category: "fund",
100
100
  },
101
101
  {
102
102
  term: "Arbitration",
103
103
  definition: "Independent arbitration service object. Configured with voting_guard, usage_guard, " +
104
104
  "fee. Generates Arb cases per dispute. Third-party preferred over self-built.",
105
- aliases: ["仲裁服务", "arb service"],
105
+ aliases: ["arb service"],
106
106
  category: "object",
107
107
  },
108
108
  {
109
109
  term: "Arb",
110
110
  definition: "A single dispute case instance of an Arbitration. Has a state machine " +
111
111
  "(dispute → confirm → vote → verdict → settle).",
112
- aliases: ["仲裁案", "arb case"],
112
+ aliases: ["arb case"],
113
113
  category: "object",
114
114
  },
115
115
  {
116
116
  term: "compensation_fund",
117
117
  definition: "A fund attached to a Service. Arbitration indemnity is drawn from it. " +
118
118
  "Adequacy is a key trust signal for customers.",
119
- aliases: ["赔偿基金", "赔偿金"],
119
+ aliases: ["compensation fund"],
120
120
  category: "fund",
121
121
  },
122
122
  {
123
123
  term: "buy_guard",
124
124
  definition: "A Guard attached to a Service that gates purchasing. Validates customer eligibility.",
125
- aliases: ["购买守卫"],
125
+ aliases: ["buy guard"],
126
126
  category: "acceptance",
127
127
  },
128
128
  {
129
129
  term: "Sub-Order",
130
130
  definition: "A child order in a cross-Machine supply chain. Introduced at a node with transparent " +
131
131
  "suppliers; verified by Guard to originate from one of the declared suppliers.",
132
- aliases: ["采购子订单", "suborder", "sub order"],
132
+ aliases: ["suborder", "sub order"],
133
133
  category: "object",
134
134
  },
135
135
  {
136
136
  term: "Reward",
137
137
  definition: "Incentive pool. claim is Guard-gated. guard_add supports Fixed or GuardU64Identifier " +
138
138
  "(dynamic). Used for marketing (first-order, cumulative, referral).",
139
- aliases: ["奖励", "reward pool"],
139
+ aliases: ["reward pool"],
140
140
  category: "fund",
141
141
  },
142
142
  {
143
143
  term: "Demand",
144
144
  definition: "A user's posted service request with optional reward. presenters submit proposals; " +
145
145
  "Guard filters them. Matches Services for personalized acquisition.",
146
- aliases: ["需求"],
146
+ aliases: ["demand request"],
147
147
  category: "object",
148
148
  },
149
149
  {
150
150
  term: "Personal",
151
151
  definition: "Permanently public on-chain identity profile. Social links, reputation (likes/dislikes), " +
152
152
  "personal info records. CRITICAL: everything here is PUBLIC forever.",
153
- aliases: ["公开身份", "personal profile"],
153
+ aliases: ["personal profile"],
154
154
  category: "object",
155
155
  },
156
156
  {
157
157
  term: "Contact",
158
158
  definition: "Bridges a Service's um (contact) and the Messenger ims (messaging). Enables " +
159
159
  "off-chain encrypted communication for pre-order negotiation & evidence.",
160
- aliases: ["联系"],
160
+ aliases: ["contact bridge"],
161
161
  category: "object",
162
162
  },
163
163
  ];
@@ -0,0 +1,19 @@
1
+ export interface GuardScene {
2
+ id: string;
3
+ name: string;
4
+ host_object: "Service" | "Machine" | "Arbitration" | "Reward" | "Repository" | "Progress" | "Demand" | "Standalone";
5
+ binding_field: string;
6
+ validation_scene: string;
7
+ pass_result: string;
8
+ fail_result: string;
9
+ submission_source: string;
10
+ special_constraints: string[];
11
+ common_patterns: string[];
12
+ mutable_after_publish: boolean;
13
+ r_rounds_focus: string[];
14
+ }
15
+ export declare const GUARD_SCENES: GuardScene[];
16
+ export declare function findScene(host_object: string, binding_field: string): GuardScene | undefined;
17
+ export declare function inferSceneFromAction(action: "buy" | "forward" | "allocate" | "claim_reward" | "vote" | "dispute" | "write_repository" | "submit_progress" | "gen_passport"): GuardScene | undefined;
18
+ export declare function getImmutableScenes(): GuardScene[];
19
+ export declare function getNumericIdentifierScenes(): GuardScene[];
@@ -0,0 +1,246 @@
1
+ export const GUARD_SCENES = [
2
+ {
3
+ id: "service_buy_guard",
4
+ name: "Service purchase validation (buy_guard)",
5
+ host_object: "Service",
6
+ binding_field: "buy_guard",
7
+ validation_scene: "When a customer places an order to purchase a service, the Guard validates whether the customer is eligible to purchase (identity/permission/condition)",
8
+ pass_result: "Create the Order object; the customer enters the payment flow",
9
+ fail_result: "Transaction rejected; Order is not created; the customer cannot purchase",
10
+ submission_source: "Customer (signer address, credentials, Passport, etc.)",
11
+ special_constraints: [
12
+ "The Guard table must declare all data the customer needs to submit",
13
+ "The name of b_submission=true entries must be a natural-language description (the contract the customer sees)",
14
+ "If the Guard references the Service itself, use the circular reference pattern (CREATE Service → CREATE Guard → MODIFY Service)",
15
+ "buy_guard can still be modified after Service is published (via MODIFY Service)",
16
+ ],
17
+ common_patterns: [
18
+ "Identity check: context(Signer) + logic_equal (single address) / vec_contains_address (whitelist)",
19
+ "Membership validation: query EntityRegistrar(0xaab) + logic_and combination",
20
+ "Time limit: context(Clock) + logic_as_u256_greater_or_equal",
21
+ "Multi-condition: logic_and combining multiple checks",
22
+ ],
23
+ mutable_after_publish: true,
24
+ r_rounds_focus: ["R1", "R2", "R3", "R5", "R7", "R9"],
25
+ },
26
+ {
27
+ id: "service_order_allocators_guard",
28
+ name: "Allocation strategy selection validation (order_allocators[].guard)",
29
+ host_object: "Service",
30
+ binding_field: "order_allocators",
31
+ validation_scene: "When an order is completed or allocation conditions are met, the system evaluates each Allocator's Guard in order_allocators order. " +
32
+ "The first Allocator whose Guard passes executes the allocation",
33
+ pass_result: "Execute that Allocator's allocation strategy (distribute funds by ratio/condition)",
34
+ fail_result: "Skip this Allocator and try the next (first-match-wins). If all Allocators fail, funds are not distributed",
35
+ submission_source: "System auto-derives from Progress state (no explicit customer submission needed)",
36
+ special_constraints: [
37
+ "order_allocators is order-sensitive: the first Allocator whose Guard passes executes allocation",
38
+ "order_allocators cannot be modified after Service is published (immutable)",
39
+ "Guard usually queries Order/Progress state to determine allocation conditions",
40
+ "Common queries: order.amount, progress.current_node, order.completed, etc.",
41
+ "GuardIdentifier can be used for dynamic amounts (extract u64 value from table as allocation ratio)",
42
+ ],
43
+ common_patterns: [
44
+ "Node state check: query(Progress.current_node) + logic_equal('Completed')",
45
+ "Amount threshold: query(Order.amount) + logic_as_u256_greater_or_equal(threshold)",
46
+ "Multi-condition combination: logic_and (node state + amount + time)",
47
+ "GuardIdentifier dynamic ratio: table[u64] extracts allocation ratio",
48
+ ],
49
+ mutable_after_publish: false,
50
+ r_rounds_focus: ["R1", "R2", "R3", "R5", "R6", "R7"],
51
+ },
52
+ {
53
+ id: "machine_forward_guard",
54
+ name: "Workflow node advancement validation (Forward.guard)",
55
+ host_object: "Machine",
56
+ binding_field: "Forward.guard",
57
+ validation_scene: "When a customer or provider executes a Forward operation to advance the workflow, the Guard validates whether advancement to the next node is allowed",
58
+ pass_result: "Progress advances to next_node; session accumulates weight",
59
+ fail_result: "Forward is blocked; Progress stays at the current node. Optional retained_submission retains audit data",
60
+ submission_source: "The party executing Forward (Customer or Provider, depending on Forward configuration)",
61
+ special_constraints: [
62
+ "Forward.guard cannot be modified after Machine is published (a new Machine must be created)",
63
+ "Optional retained_submission: stores submission data in Progress for later audit",
64
+ "retained_submission indices must correspond to the Guard table",
65
+ "Common queries: progress.current_node, progress.session_forward, order.service, etc.",
66
+ "Time lock: context(Clock) + calc_number_add(progress.entry_time, duration) tested with 1000ms",
67
+ ],
68
+ common_patterns: [
69
+ "Identity check: context(Signer) + logic_equal (only specific parties can advance)",
70
+ "Time lock: context(Clock) + calc_number_add + logic_as_u256_greater_or_equal",
71
+ "Prior Forward completion: query_progress_history_find + logic_equal(accomplished=true)",
72
+ "Submission data validation: identifier(submission) + logic_equal(expected_value)",
73
+ "Cross-object query: convert_witness=TypeOrderProgress(100) queries Progress from Order",
74
+ ],
75
+ mutable_after_publish: false,
76
+ r_rounds_focus: ["R1", "R2", "R3", "R5", "R6", "R7", "R8", "R9"],
77
+ },
78
+ {
79
+ id: "progress_submission_guard",
80
+ name: "Progress submission data validation (submission guard)",
81
+ host_object: "Progress",
82
+ binding_field: "submission",
83
+ validation_scene: "Whether the data (e.g. signature, credential, confirmation) submitted during Forward execution satisfies the Guard condition",
84
+ pass_result: "Forward completes; node advances after session accumulates weight to threshold",
85
+ fail_result: "Forward does not complete; waits for resubmission or condition satisfaction",
86
+ submission_source: "The party submitting data (Customer or Provider)",
87
+ special_constraints: [
88
+ "Works in concert with Forward.guard: Forward.guard validates eligibility, submission guard validates data",
89
+ "retained_submission stores submission data in Progress session for audit",
90
+ "Common queries: progress.session_forward, progress.session_weight, etc.",
91
+ ],
92
+ common_patterns: [
93
+ "Signature validation: identifier(signature_submission) + logic_equal(expected)",
94
+ "Credential validation: query(Repository.data) + logic_equal(submission_proof)",
95
+ "Confirmation validation: identifier(confirm_submission) + logic_equal(true)",
96
+ ],
97
+ mutable_after_publish: false,
98
+ r_rounds_focus: ["R1", "R2", "R3", "R5", "R6", "R8"],
99
+ },
100
+ {
101
+ id: "reward_guard",
102
+ name: "Reward claim validation (Reward.guard)",
103
+ host_object: "Reward",
104
+ binding_field: "guard",
105
+ validation_scene: "When a user claims from a reward pool, the Guard validates eligibility to claim",
106
+ pass_result: "Reward is distributed to the Claimant and recorded in reward_record",
107
+ fail_result: "Claim rejected; reward is not distributed",
108
+ submission_source: "Claimant (address, credentials, Passport)",
109
+ special_constraints: [
110
+ "Common query_reward_record_count prevents duplicate claims (one-time claim)",
111
+ "Guard usually queries history records + time conditions + identity validation",
112
+ "If the Reward references a Service, use the circular reference pattern",
113
+ ],
114
+ common_patterns: [
115
+ "One-time claim: query_reward_record_count(recipient) + logic_equal(0)",
116
+ "Time window: context(Clock) + logic_as_u256_greater_or_equal(start_time)",
117
+ "Identity validation: context(Signer) + vec_contains_address(allowlist)",
118
+ "Multi-condition: logic_and (identity + time + not claimed before)",
119
+ ],
120
+ mutable_after_publish: true,
121
+ r_rounds_focus: ["R1", "R2", "R3", "R5", "R7", "R8", "R9"],
122
+ },
123
+ {
124
+ id: "repository_write_guard",
125
+ name: "Repository write validation (write_guard)",
126
+ host_object: "Repository",
127
+ binding_field: "write_guard",
128
+ validation_scene: "When writing to on-chain storage, the Guard validates write eligibility and optionally extracts data",
129
+ pass_result: "Write succeeds; optional id_from_submission extracts the entity ID, data_from_submission extracts the data value",
130
+ fail_result: "Write rejected",
131
+ submission_source: "Writer/Reader",
132
+ special_constraints: [
133
+ "The table entry referenced by id_from_submission must be of Address type",
134
+ "The table entry referenced by data_from_submission must match the Repository's value_type",
135
+ "Type mismatch leads to write failure or data corruption",
136
+ "Commonly used for oracle data writes, third-party credential attestation, etc.",
137
+ ],
138
+ common_patterns: [
139
+ "Authorized writer: context(Signer) + vec_contains_address(authorized_writers)",
140
+ "Data format validation: identifier(data_submission) + logic_string_contains(expected_prefix)",
141
+ "ID extraction: id_from_submission + data_from_submission combination",
142
+ ],
143
+ mutable_after_publish: true,
144
+ r_rounds_focus: ["R1", "R2", "R3", "R5", "R6", "R7"],
145
+ },
146
+ {
147
+ id: "arbitration_usage_guard",
148
+ name: "Dispute initiation validation (usage_guard)",
149
+ host_object: "Arbitration",
150
+ binding_field: "usage_guard",
151
+ validation_scene: "When a customer initiates a dispute against an order, the Guard validates whether the customer is eligible to initiate the dispute",
152
+ pass_result: "Create an Arb case and enter the arbitration flow",
153
+ fail_result: "Dispute rejected; Arb is not created",
154
+ submission_source: "Customer (Passport credential)",
155
+ special_constraints: [
156
+ "When Arbitration bPaused=true, it blocks first (before the Guard check)",
157
+ "The customer must first generate a Passport (gen_passport passes usage_guard)",
158
+ "Common queries: order.completed, order.service, entity.has, etc.",
159
+ "Guard validates customer identity + order status + dispute eligibility",
160
+ ],
161
+ common_patterns: [
162
+ "Order status validation: query(Order.status) + logic_equal('completed')",
163
+ "Membership validation: query(EntityRegistrar) + logic_and",
164
+ "Time window: query(Order.time) + calc_number_add + context(Clock)",
165
+ "Passport credential: identifier(passport_submission) + context(Signer)",
166
+ ],
167
+ mutable_after_publish: true,
168
+ r_rounds_focus: ["R1", "R2", "R3", "R5", "R7", "R8", "R9"],
169
+ },
170
+ {
171
+ id: "arbitration_voting_guard",
172
+ name: "Arbitration voting weight validation (voting_guard[])",
173
+ host_object: "Arbitration",
174
+ binding_field: "voting_guard",
175
+ validation_scene: "When an arbitrator votes, the Guard validates voting eligibility and extracts the voting weight (u32) from GuardIdentifier",
176
+ pass_result: "Vote is counted; weight is the value extracted by GuardIdentifier",
177
+ fail_result: "Vote rejected",
178
+ submission_source: "Voter (Passport credential with weight data)",
179
+ special_constraints: [
180
+ "The table entry referenced by GuardIdentifier must be of a numeric type (U8-U256), cast to u32",
181
+ "Non-numeric types cause E_GUARD_IDENTIFIER_NOT_NUMBER error",
182
+ "b_submission must be true (weight is submitted at runtime by the voter)",
183
+ "Multiple voting_guards can be configured, each corresponding to a different voter group",
184
+ "When Arbitration bPaused=true, voting is blocked",
185
+ ],
186
+ common_patterns: [
187
+ "Reputation score weight: query(EntityRegistrar.records[reputation]) + GuardIdentifier(u64)",
188
+ "Fixed weight: identifier(constant_weight) + GuardIdentifier",
189
+ "Multi-tier voting: different voting_guards correspond to different weight tiers",
190
+ "Eligibility + weight: logic_and (eligibility check + GuardIdentifier extracts weight)",
191
+ ],
192
+ mutable_after_publish: true,
193
+ r_rounds_focus: ["R1", "R2", "R3", "R5", "R6", "R7", "R8", "R9"],
194
+ },
195
+ {
196
+ id: "gen_passport_guard",
197
+ name: "Passport credential generation validation (gen_passport)",
198
+ host_object: "Standalone",
199
+ binding_field: "none",
200
+ validation_scene: "When a user calls gen_passport, the Guard validates user eligibility and generates a Passport with credentials",
201
+ pass_result: "Passport is generated, containing credentials validated by the Guard",
202
+ fail_result: "Passport generation fails; the user did not pass validation",
203
+ submission_source: "Passport applicant (signer + credentials)",
204
+ special_constraints: [
205
+ "impack_list is always empty during the verify phase (only filled after result_for_permission)",
206
+ "Therefore quote_guard (query 1167) always fails in the gen_passport flow (IMPACK_GUARD_NOT_FOUND)",
207
+ "Only Repository queries with quote_guard==None can pass in gen_passport",
208
+ "Guard can be created standalone (not bound to a specific Host Object)",
209
+ "Guard can be depended on by other Guards via rely (requires rep=true)",
210
+ "The Passport generated by gen_passport can be used as submission data for subsequent operations",
211
+ ],
212
+ common_patterns: [
213
+ "Identity validation: context(Signer) + logic_equal (single address/whitelist)",
214
+ "Membership eligibility: query(EntityRegistrar) + logic_equal",
215
+ "Reputation threshold: query(EntityRegistrar.records[reputation]) + logic_as_u256_greater_or_equal",
216
+ "Multi-condition combination: logic_and (identity + eligibility + reputation)",
217
+ ],
218
+ mutable_after_publish: false,
219
+ r_rounds_focus: ["R1", "R2", "R3", "R5", "R6", "R7"],
220
+ },
221
+ ];
222
+ export function findScene(host_object, binding_field) {
223
+ return GUARD_SCENES.find((s) => s.host_object === host_object &&
224
+ s.binding_field === binding_field);
225
+ }
226
+ export function inferSceneFromAction(action) {
227
+ const map = {
228
+ buy: "service_buy_guard",
229
+ forward: "machine_forward_guard",
230
+ allocate: "service_order_allocators_guard",
231
+ claim_reward: "reward_guard",
232
+ vote: "arbitration_voting_guard",
233
+ dispute: "arbitration_usage_guard",
234
+ write_repository: "repository_write_guard",
235
+ submit_progress: "progress_submission_guard",
236
+ gen_passport: "gen_passport_guard",
237
+ };
238
+ const id = map[action];
239
+ return GUARD_SCENES.find((s) => s.id === id);
240
+ }
241
+ export function getImmutableScenes() {
242
+ return GUARD_SCENES.filter((s) => !s.mutable_after_publish);
243
+ }
244
+ export function getNumericIdentifierScenes() {
245
+ return GUARD_SCENES.filter((s) => s.special_constraints.some((c) => c.includes("numeric") || c.includes("GuardIdentifier")));
246
+ }
@@ -0,0 +1,76 @@
1
+ import { type GuardRiskAssessment } from "./guard-risk.js";
2
+ export type DiagnosticSource = "sdk" | "lint" | "risk";
3
+ export type DiagnosticSeverity = "error" | "warning" | "info" | "hint";
4
+ export interface GuardDiagnostic {
5
+ code: string;
6
+ message: string;
7
+ severity: DiagnosticSeverity;
8
+ source: DiagnosticSource;
9
+ location: {
10
+ path: string;
11
+ };
12
+ fix?: {
13
+ description: string;
14
+ auto_fixable: boolean;
15
+ };
16
+ }
17
+ export interface GuardJsonInput {
18
+ description?: string;
19
+ table: Array<{
20
+ identifier: number;
21
+ b_submission?: boolean;
22
+ value_type?: string;
23
+ value?: unknown;
24
+ name?: string;
25
+ object_type?: string;
26
+ is_system_address?: boolean;
27
+ }>;
28
+ root: any;
29
+ rely?: {
30
+ guards: string[];
31
+ logic_or?: boolean;
32
+ };
33
+ binding_hint?: {
34
+ host_object?: string;
35
+ binding_field?: string;
36
+ action?: string;
37
+ };
38
+ }
39
+ export interface AutoFixAction {
40
+ diagnostic_code: string;
41
+ description: string;
42
+ before?: string;
43
+ after?: string;
44
+ path: string;
45
+ }
46
+ export interface GuardLintResult {
47
+ json_summary: {
48
+ table_count: number;
49
+ root_type: string;
50
+ has_rely: boolean;
51
+ rely_count: number;
52
+ has_description: boolean;
53
+ };
54
+ diagnostics: GuardDiagnostic[];
55
+ fixed_json?: GuardJsonInput;
56
+ fix_actions: AutoFixAction[];
57
+ risk_assessment?: GuardRiskAssessment;
58
+ summary: {
59
+ errors: number;
60
+ warnings: number;
61
+ infos: number;
62
+ auto_fixes_applied: number;
63
+ ready: boolean;
64
+ next_step: string;
65
+ };
66
+ }
67
+ export declare function autoFixGuard(json: GuardJsonInput): {
68
+ fixed: GuardJsonInput;
69
+ actions: AutoFixAction[];
70
+ };
71
+ export declare function lintGuard(json: GuardJsonInput, options?: {
72
+ auto_fix?: boolean;
73
+ }): Promise<GuardLintResult>;
74
+ export declare function isGuardReady(json: GuardJsonInput): Promise<boolean>;
75
+ export declare function getGuardErrors(json: GuardJsonInput): Promise<GuardDiagnostic[]>;
76
+ export declare function formatLintResult(result: GuardLintResult): string;