@wowok/agent-mcp 2.3.16 → 2.3.18

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 (106) 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 +14 -0
  5. package/dist/customer/user-preferences.d.ts +3 -0
  6. package/dist/customer/user-preferences.js +9 -0
  7. package/dist/experience/realtime-feedback.js +17 -0
  8. package/dist/index.js +360 -273
  9. package/dist/knowledge/acquisition-flywheel.d.ts +3 -0
  10. package/dist/knowledge/acquisition-flywheel.js +9 -0
  11. package/dist/knowledge/guard-ledger.d.ts +19 -0
  12. package/dist/knowledge/guard-ledger.js +219 -0
  13. package/dist/knowledge/guard-puzzle.d.ts +93 -0
  14. package/dist/knowledge/guard-puzzle.js +278 -0
  15. package/dist/knowledge/guard-risk.d.ts +60 -0
  16. package/dist/knowledge/guard-risk.js +474 -0
  17. package/dist/knowledge/guard-translation.d.ts +46 -0
  18. package/dist/knowledge/guard-translation.js +487 -0
  19. package/dist/knowledge/index.d.ts +13 -0
  20. package/dist/knowledge/index.js +13 -0
  21. package/dist/knowledge/industry-registry.d.ts +1 -2
  22. package/dist/knowledge/industry-registry.js +23 -3
  23. package/dist/knowledge/safety-rules.js +61 -0
  24. package/dist/knowledge/tool-constraints.js +12 -22
  25. package/dist/safety/confirm-gate.d.ts +4 -2
  26. package/dist/safety/confirm-gate.js +48 -4
  27. package/dist/schema/call/allocation.d.ts +24 -14
  28. package/dist/schema/call/arbitration.d.ts +142 -132
  29. package/dist/schema/call/base.d.ts +901 -43
  30. package/dist/schema/call/base.js +66 -2
  31. package/dist/schema/call/bridge-handler.js +15 -2
  32. package/dist/schema/call/bridge.d.ts +769 -1
  33. package/dist/schema/call/bridge.js +37 -0
  34. package/dist/schema/call/contact.d.ts +10 -0
  35. package/dist/schema/call/demand.d.ts +10 -0
  36. package/dist/schema/call/guard.d.ts +76 -46
  37. package/dist/schema/call/handler.js +46 -14
  38. package/dist/schema/call/machine.d.ts +158 -138
  39. package/dist/schema/call/order.d.ts +10 -0
  40. package/dist/schema/call/payment.d.ts +10 -0
  41. package/dist/schema/call/permission.d.ts +232 -222
  42. package/dist/schema/call/personal.d.ts +10 -0
  43. package/dist/schema/call/progress.d.ts +10 -0
  44. package/dist/schema/call/proof.d.ts +20 -0
  45. package/dist/schema/call/repository.d.ts +32 -22
  46. package/dist/schema/call/reward.d.ts +10 -0
  47. package/dist/schema/call/semantic.d.ts +9 -2
  48. package/dist/schema/call/semantic.js +409 -21
  49. package/dist/schema/call/service.d.ts +20 -10
  50. package/dist/schema/call/treasury.d.ts +10 -0
  51. package/dist/schema/config/index.d.ts +18 -0
  52. package/dist/schema/config/index.js +17 -0
  53. package/dist/schema/index.d.ts +6 -0
  54. package/dist/schema/index.js +5 -0
  55. package/dist/schema/local/index.d.ts +9 -9
  56. package/dist/schema/local/index.js +9 -0
  57. package/dist/schema/messenger/index.d.ts +350 -29
  58. package/dist/schema/messenger/index.js +17 -17
  59. package/dist/schema/operations.d.ts +1667 -545
  60. package/dist/schema/operations.js +91 -96
  61. package/dist/schema/project/index.d.ts +21 -0
  62. package/dist/schema/project/index.js +32 -0
  63. package/dist/schema/query/index.d.ts +1074 -168
  64. package/dist/schema/query/index.js +8 -8
  65. package/dist/schema/schema-query/index.d.ts +33 -0
  66. package/dist/schema/schema-query/index.js +36 -0
  67. package/dist/schema/schema-version.d.ts +25 -0
  68. package/dist/schema/schema-version.js +76 -0
  69. package/dist/schema/trust/index.d.ts +407 -0
  70. package/dist/schema/trust/index.js +113 -0
  71. package/dist/schemas/bridge_operation.output.json +224 -0
  72. package/dist/schemas/bridge_operation.schema.json +67 -8
  73. package/dist/schemas/config_operation.output.json +18 -0
  74. package/dist/schemas/config_operation.schema.json +34 -0
  75. package/dist/schemas/guard-node-schema.json +82 -0
  76. package/dist/schemas/guard2file.schema.json +8 -0
  77. package/dist/schemas/index.json +19 -1
  78. package/dist/schemas/machineNode2file.schema.json +8 -0
  79. package/dist/schemas/messenger_operation.output.json +224 -0
  80. package/dist/schemas/onchain_events.output.json +718 -0
  81. package/dist/schemas/onchain_operations.output.json +277 -2
  82. package/dist/schemas/onchain_operations.schema.json +19 -16
  83. package/dist/schemas/onchain_operations_allocation.schema.json +8 -0
  84. package/dist/schemas/onchain_operations_arbitration.schema.json +8 -0
  85. package/dist/schemas/onchain_operations_contact.schema.json +8 -0
  86. package/dist/schemas/onchain_operations_demand.schema.json +8 -0
  87. package/dist/schemas/onchain_operations_gen_passport.schema.json +16 -0
  88. package/dist/schemas/onchain_operations_guard.schema.json +11 -16
  89. package/dist/schemas/onchain_operations_machine.schema.json +8 -0
  90. package/dist/schemas/onchain_operations_order.schema.json +8 -0
  91. package/dist/schemas/onchain_operations_payment.schema.json +8 -0
  92. package/dist/schemas/onchain_operations_permission.schema.json +8 -0
  93. package/dist/schemas/onchain_operations_personal.schema.json +8 -0
  94. package/dist/schemas/onchain_operations_progress.schema.json +8 -0
  95. package/dist/schemas/onchain_operations_repository.schema.json +8 -0
  96. package/dist/schemas/onchain_operations_reward.schema.json +8 -0
  97. package/dist/schemas/onchain_operations_service.schema.json +8 -0
  98. package/dist/schemas/onchain_operations_treasury.schema.json +8 -0
  99. package/dist/schemas/onchain_table_data.output.json +718 -0
  100. package/dist/schemas/project_operation.output.json +18 -0
  101. package/dist/schemas/project_operation.schema.json +42 -0
  102. package/dist/schemas/query_toolkit.schema.json +360 -368
  103. package/dist/schemas/schema_query.schema.json +6 -3
  104. package/dist/schemas/trust_score.output.json +327 -0
  105. package/dist/schemas/trust_score.schema.json +46 -0
  106. package/package.json +2 -2
@@ -24,6 +24,9 @@ export interface TrustDescriptionParams {
24
24
  }
25
25
  export declare const ACQUISITION_FLYWHEEL_VERSION = 1;
26
26
  export declare const INDUSTRY_FLYWHEELS: AcquisitionFlywheel[];
27
+ export declare function _setRegistryLookup(fn: ((industry: string) => {
28
+ flywheel?: AcquisitionFlywheel;
29
+ } | undefined) | null): void;
27
30
  export declare function getFlywheelForIndustry(industry: string): AcquisitionFlywheel | undefined;
28
31
  export declare function listIndustries(): string[];
29
32
  export declare function suggestAcquisitionActions(industry: string): FlywheelAction[];
@@ -91,7 +91,16 @@ export const INDUSTRY_FLYWHEELS = [
91
91
  trustDescription: "交易托管 + 物流 Guard + 退款保障",
92
92
  },
93
93
  ];
94
+ let _registryLookup = null;
95
+ export function _setRegistryLookup(fn) {
96
+ _registryLookup = fn;
97
+ }
94
98
  export function getFlywheelForIndustry(industry) {
99
+ if (_registryLookup) {
100
+ const profile = _registryLookup(industry);
101
+ if (profile?.flywheel)
102
+ return profile.flywheel;
103
+ }
95
104
  return INDUSTRY_FLYWHEELS.find((f) => f.industry === industry.toLowerCase());
96
105
  }
97
106
  export function listIndustries() {
@@ -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"): GuardScene | undefined;
18
+ export declare function getImmutableScenes(): GuardScene[];
19
+ export declare function getNumericIdentifierScenes(): GuardScene[];
@@ -0,0 +1,219 @@
1
+ export const GUARD_SCENES = [
2
+ {
3
+ id: "service_buy_guard",
4
+ name: "服务购买验证(buy_guard)",
5
+ host_object: "Service",
6
+ binding_field: "buy_guard",
7
+ validation_scene: "客户下单购买服务时,Guard 验证客户是否有资格购买(身份/许可/条件)",
8
+ pass_result: "创建 Order 对象,客户进入支付流程",
9
+ fail_result: "交易拒绝,Order 不创建,客户无法购买",
10
+ submission_source: "Customer(signer 地址、credentials、Passport 等)",
11
+ special_constraints: [
12
+ "Guard table 必须声明所有客户需要提交的数据",
13
+ "b_submission=true 条目的 name 必须是自然语言描述(客户看到的契约)",
14
+ "如果 Guard 引用 Service 本身,使用循环引用模式(CREATE Service → CREATE Guard → MODIFY Service)",
15
+ "Service 发布后 buy_guard 仍可修改(通过 MODIFY Service)",
16
+ ],
17
+ common_patterns: [
18
+ "身份检查:context(Signer) + logic_equal(单地址)/ vec_contains_address(白名单)",
19
+ "会员验证:query EntityRegistrar(0xaab) + logic_and 组合",
20
+ "时间限制:context(Clock) + logic_as_u256_greater_or_equal",
21
+ "多条件:logic_and 组合多个检查",
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: "分账策略选择验证(order_allocators[].guard)",
29
+ host_object: "Service",
30
+ binding_field: "order_allocators",
31
+ validation_scene: "订单完成或满足分账条件时,系统按 order_allocators 顺序评估每个 Allocator 的 Guard," +
32
+ "第一个通过的 Guard 对应的 Allocator 执行分账",
33
+ pass_result: "执行该 Allocator 的分账策略(按比例/按条件分配资金)",
34
+ fail_result: "跳过此 Allocator,尝试下一个(first-match-wins)。如果所有 Allocator 都失败,资金不分配",
35
+ submission_source: "System 从 Progress 状态自动派生(无需客户显式提交)",
36
+ special_constraints: [
37
+ "order_allocators 顺序敏感:第一个 Guard 通过的 Allocator 执行分账",
38
+ "Service 发布后 order_allocators 不可修改(immutable)",
39
+ "Guard 通常查询 Order/Progress 状态判断分账条件",
40
+ "常用 query: order.amount, progress.current_node, order.completed 等",
41
+ "GuardIdentifier 可用于动态金额(从 table 提取 u64 值作为分账比例)",
42
+ ],
43
+ common_patterns: [
44
+ "节点状态检查:query(Progress.current_node) + logic_equal('Completed')",
45
+ "金额阈值:query(Order.amount) + logic_as_u256_greater_or_equal(threshold)",
46
+ "多条件组合:logic_and(节点状态 + 金额 + 时间)",
47
+ "GuardIdentifier 动态比例:table[u64] 提取分账比例",
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: "工作流节点推进验证(Forward.guard)",
55
+ host_object: "Machine",
56
+ binding_field: "Forward.guard",
57
+ validation_scene: "客户或商家执行 Forward 操作推进工作流时,Guard 验证是否允许推进到下一节点",
58
+ pass_result: "Progress 推进到 next_node,session 累计权重",
59
+ fail_result: "Forward 阻塞,Progress 停留在当前节点。可选 retained_submission 留存审计数据",
60
+ submission_source: "执行 Forward 的一方(Customer 或 Provider,取决于 Forward 配置)",
61
+ special_constraints: [
62
+ "Machine 发布后 Forward.guard 不可修改(需新建 Machine)",
63
+ "可选 retained_submission:将提交数据存入 Progress 供后续审计",
64
+ "retained_submission 索引必须与 Guard table 对应",
65
+ "常用 query: progress.current_node, progress.session_forward, order.service 等",
66
+ "时间锁:context(Clock) + calc_number_add(progress.entry_time, duration) 测试用 1000ms",
67
+ ],
68
+ common_patterns: [
69
+ "身份检查:context(Signer) + logic_equal(只有特定方可推进)",
70
+ "时间锁:context(Clock) + calc_number_add + logic_as_u256_greater_or_equal",
71
+ "前置 Forward 完成:query_progress_history_find + logic_equal(accomplished=true)",
72
+ "提交数据验证:identifier(submission) + logic_equal(expected_value)",
73
+ "跨对象查询:convert_witness=TypeOrderProgress(100) 从 Order 查 Progress",
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 guard)",
81
+ host_object: "Progress",
82
+ binding_field: "submission",
83
+ validation_scene: "Forward 执行时提交的数据(如签名、凭证、确认)是否满足 Guard 条件",
84
+ pass_result: "Forward 完成,session 累计权重达到阈值后推进节点",
85
+ fail_result: "Forward 不完成,等待重新提交或满足条件",
86
+ submission_source: "提交数据的一方(Customer 或 Provider)",
87
+ special_constraints: [
88
+ "与 Forward.guard 协同:Forward.guard 验证资格,submission guard 验证数据",
89
+ "retained_submission 将提交数据存入 Progress session 供审计",
90
+ "常用 query: progress.session_forward, progress.session_weight 等",
91
+ ],
92
+ common_patterns: [
93
+ "签名验证:identifier(signature_submission) + logic_equal(expected)",
94
+ "凭证验证:query(Repository.data) + logic_equal(submission_proof)",
95
+ "确认验证: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.guard)",
103
+ host_object: "Reward",
104
+ binding_field: "guard",
105
+ validation_scene: "用户领取奖励池时,Guard 验证是否有资格领取",
106
+ pass_result: "奖励发放给 Claimant,记录到 reward_record",
107
+ fail_result: "领取拒绝,奖励不发",
108
+ submission_source: "Claimant(address、credentials、Passport)",
109
+ special_constraints: [
110
+ "常用 query_reward_record_count 防重复领取(one-time claim)",
111
+ "Guard 通常查询历史记录 + 时间条件 + 身份验证",
112
+ "如果 Reward 引用 Service,使用循环引用模式",
113
+ ],
114
+ common_patterns: [
115
+ "一次性领取:query_reward_record_count(recipient) + logic_equal(0)",
116
+ "时间窗口:context(Clock) + logic_as_u256_greater_or_equal(start_time)",
117
+ "身份验证:context(Signer) + vec_contains_address(allowlist)",
118
+ "多条件:logic_and(身份 + 时间 + 未领取过)",
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: "存储写入验证(write_guard)",
126
+ host_object: "Repository",
127
+ binding_field: "write_guard",
128
+ validation_scene: "写入链上存储时,Guard 验证写入资格并可选提取数据",
129
+ pass_result: "写入成功;可选 id_from_submission 提取 entity ID,data_from_submission 提取数据值",
130
+ fail_result: "写入拒绝",
131
+ submission_source: "Writer/Reader",
132
+ special_constraints: [
133
+ "id_from_submission 引用的 table 条目必须是 Address 类型",
134
+ "data_from_submission 引用的 table 条目必须匹配 Repository 的 value_type",
135
+ "类型不匹配导致写入失败或数据损坏",
136
+ "常用于 oracle 数据写入、第三方凭证存证等场景",
137
+ ],
138
+ common_patterns: [
139
+ "授权写入者:context(Signer) + vec_contains_address(authorized_writers)",
140
+ "数据格式验证:identifier(data_submission) + logic_string_contains(expected_prefix)",
141
+ "ID 提取:id_from_submission + data_from_submission 组合",
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: "争议发起验证(usage_guard)",
149
+ host_object: "Arbitration",
150
+ binding_field: "usage_guard",
151
+ validation_scene: "客户对订单发起争议时,Guard 验证客户是否有资格发起争议",
152
+ pass_result: "创建 Arb 案件,进入仲裁流程",
153
+ fail_result: "争议拒绝,Arb 不创建",
154
+ submission_source: "Customer(Passport credential)",
155
+ special_constraints: [
156
+ "Arbitration bPaused=true 时优先阻塞(先于 Guard 检查)",
157
+ "客户需先生成 Passport(gen_passport 通过 usage_guard)",
158
+ "常用 query: order.completed, order.service, entity.has 等",
159
+ "Guard 验证客户身份 + 订单状态 + 争议资格",
160
+ ],
161
+ common_patterns: [
162
+ "订单状态验证:query(Order.status) + logic_equal('completed')",
163
+ "会员验证:query(EntityRegistrar) + logic_and",
164
+ "时间窗口:query(Order.time) + calc_number_add + context(Clock)",
165
+ " Passport 凭证: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: "仲裁投票权重验证(voting_guard[])",
173
+ host_object: "Arbitration",
174
+ binding_field: "voting_guard",
175
+ validation_scene: "仲裁员投票时,Guard 验证投票资格并从 GuardIdentifier 提取投票权重(u32)",
176
+ pass_result: "投票计入,权重为 GuardIdentifier 提取的数值",
177
+ fail_result: "投票拒绝",
178
+ submission_source: "Voter(Passport credential with weight data)",
179
+ special_constraints: [
180
+ "GuardIdentifier 引用的 table 条目必须是 numeric 类型(U8-U256),cast 为 u32",
181
+ "非 numeric 类型导致 E_GUARD_IDENTIFIER_NOT_NUMBER 错误",
182
+ "b_submission 必须 true(权重由 voter 运行时提交)",
183
+ "可配置多个 voting_guard,每个对应不同投票者群体",
184
+ "Arbitration bPaused=true 时阻塞投票",
185
+ ],
186
+ common_patterns: [
187
+ "声誉分权重:query(EntityRegistrar.records[reputation]) + GuardIdentifier(u64)",
188
+ "固定权重:identifier(constant_weight) + GuardIdentifier",
189
+ "多级投票:不同 voting_guard 对应不同权重等级",
190
+ "资格 + 权重:logic_and(资格检查 + GuardIdentifier 提取权重)",
191
+ ],
192
+ mutable_after_publish: true,
193
+ r_rounds_focus: ["R1", "R2", "R3", "R5", "R6", "R7", "R8", "R9"],
194
+ },
195
+ ];
196
+ export function findScene(host_object, binding_field) {
197
+ return GUARD_SCENES.find((s) => s.host_object === host_object &&
198
+ s.binding_field === binding_field);
199
+ }
200
+ export function inferSceneFromAction(action) {
201
+ const map = {
202
+ buy: "service_buy_guard",
203
+ forward: "machine_forward_guard",
204
+ allocate: "service_order_allocators_guard",
205
+ claim_reward: "reward_guard",
206
+ vote: "arbitration_voting_guard",
207
+ dispute: "arbitration_usage_guard",
208
+ write_repository: "repository_write_guard",
209
+ submit_progress: "progress_submission_guard",
210
+ };
211
+ const id = map[action];
212
+ return GUARD_SCENES.find((s) => s.id === id);
213
+ }
214
+ export function getImmutableScenes() {
215
+ return GUARD_SCENES.filter((s) => !s.mutable_after_publish);
216
+ }
217
+ export function getNumericIdentifierScenes() {
218
+ return GUARD_SCENES.filter((s) => s.special_constraints.some((c) => c.includes("numeric") || c.includes("GuardIdentifier")));
219
+ }
@@ -0,0 +1,93 @@
1
+ export interface IntentPuzzle {
2
+ action: "buy" | "forward" | "allocate" | "claim_reward" | "vote" | "dispute" | "write_repository" | "submit_progress" | "gen_passport" | "custom";
3
+ rule_sentence: string;
4
+ failure_conditions: string[];
5
+ }
6
+ export interface BindingPuzzle {
7
+ host_object: "Service" | "Machine" | "Arbitration" | "Reward" | "Repository" | "Progress" | "Demand" | "Standalone";
8
+ host_object_name?: string;
9
+ binding_field: "buy_guard" | "order_allocators" | "Forward.guard" | "submission" | "guard" | "write_guard" | "usage_guard" | "voting_guard" | "ServiceGuard" | "none";
10
+ circular_reference: boolean;
11
+ host_object_state: "not_created" | "created_unpublished" | "published_immutable" | "unknown";
12
+ }
13
+ export interface DataEntryPuzzle {
14
+ identifier: number;
15
+ b_submission: boolean;
16
+ value_type: string;
17
+ value?: string | number | boolean | string[];
18
+ name: string;
19
+ object_type?: string;
20
+ is_system_address?: boolean;
21
+ }
22
+ export interface WitnessUsagePuzzle {
23
+ witness_type: number;
24
+ witness_name: string;
25
+ source_type: string;
26
+ target_type: string;
27
+ scenario: string;
28
+ }
29
+ export interface QueryPuzzle {
30
+ query_id: number;
31
+ query_name: string;
32
+ object_type: string;
33
+ parameters: string[];
34
+ return_type: string;
35
+ witness?: WitnessUsagePuzzle;
36
+ purpose: string;
37
+ }
38
+ export interface LogicNodePuzzle {
39
+ node_type: string;
40
+ return_type: string;
41
+ children?: LogicNodePuzzle[];
42
+ references_identifier?: number;
43
+ query?: QueryPuzzle;
44
+ description: string;
45
+ }
46
+ export interface RelyPuzzle {
47
+ guards: string[];
48
+ logic_or: boolean;
49
+ rep_verified: boolean[];
50
+ }
51
+ export interface ConstraintChecklist {
52
+ pitfall_01_identifiers_in_table: boolean;
53
+ pitfall_02_type_compatibility: boolean;
54
+ pitfall_03_query_instruction_valid: boolean;
55
+ pitfall_04_witness_correct: boolean;
56
+ pitfall_05_time_lock_test_safe: boolean;
57
+ pitfall_06_exported_before_recreate: boolean;
58
+ pitfall_07_root_returns_bool: boolean;
59
+ pitfall_08_rely_rep_true: boolean;
60
+ pitfall_09_voting_weight_numeric: boolean;
61
+ pitfall_10_arbitration_not_paused: boolean;
62
+ }
63
+ export interface GuardPuzzle {
64
+ current_round: "R1" | "R2" | "R3" | "R4" | "R5" | "R6" | "R7" | "R8" | "R9" | "R10";
65
+ intent?: IntentPuzzle;
66
+ binding?: BindingPuzzle;
67
+ data?: {
68
+ entries: DataEntryPuzzle[];
69
+ witnesses: WitnessUsagePuzzle[];
70
+ };
71
+ queries?: QueryPuzzle[];
72
+ logic?: {
73
+ root: LogicNodePuzzle;
74
+ rely?: RelyPuzzle;
75
+ };
76
+ constraints?: ConstraintChecklist;
77
+ }
78
+ export type PuzzleDimension = "intent" | "binding" | "data" | "query" | "logic" | "constraints";
79
+ export interface PuzzleCompleteness {
80
+ dimensions: Record<PuzzleDimension, boolean>;
81
+ missing: PuzzleDimension[];
82
+ missing_details: string[];
83
+ complete: boolean;
84
+ next_step: {
85
+ round: GuardPuzzle["current_round"];
86
+ action: string;
87
+ questions: string[];
88
+ };
89
+ }
90
+ export declare function checkPuzzleCompleteness(puzzle: GuardPuzzle): PuzzleCompleteness;
91
+ export declare function generateConfirmationText(puzzle: GuardPuzzle): string;
92
+ export declare function initPuzzleFromIntent(intent: Partial<IntentPuzzle>): GuardPuzzle;
93
+ export declare function inferBindingFromAction(action: IntentPuzzle["action"]): Partial<BindingPuzzle>;
@@ -0,0 +1,278 @@
1
+ export function checkPuzzleCompleteness(puzzle) {
2
+ const dimensions = {
3
+ intent: isIntentComplete(puzzle.intent),
4
+ binding: isBindingComplete(puzzle.binding),
5
+ data: isDataComplete(puzzle.data),
6
+ query: isQueryComplete(puzzle.queries),
7
+ logic: isLogicComplete(puzzle.logic),
8
+ constraints: isConstraintsComplete(puzzle.constraints),
9
+ };
10
+ const missing = Object.keys(dimensions).filter((k) => !dimensions[k]);
11
+ const missing_details = [];
12
+ if (!dimensions.intent) {
13
+ missing_details.push("A. 意图:未明确被保护动作、验证规则或失败条件");
14
+ }
15
+ if (!dimensions.binding) {
16
+ missing_details.push("B. 绑定:未确定 Host Object、绑定字段或循环引用模式");
17
+ }
18
+ if (!dimensions.data) {
19
+ missing_details.push("C. 数据:未声明 table 条目(常量/提交)或 convert_witness");
20
+ }
21
+ if (!dimensions.query) {
22
+ missing_details.push("D. 查询:未确定查询指令(如果 Guard 需要查询链上数据)");
23
+ }
24
+ if (!dimensions.logic) {
25
+ missing_details.push("E. 逻辑:未设计计算树 root 或 rely 组合");
26
+ }
27
+ if (!dimensions.constraints) {
28
+ missing_details.push("F. 约束:未完成 10 项 Common Pitfalls 检查");
29
+ }
30
+ const complete = missing.length === 0;
31
+ const next_step = recommendNextStep(puzzle, missing);
32
+ return { dimensions, missing, missing_details, complete, next_step };
33
+ }
34
+ function isIntentComplete(intent) {
35
+ return !!intent && !!intent.action && !!intent.rule_sentence && intent.failure_conditions.length > 0;
36
+ }
37
+ function isBindingComplete(binding) {
38
+ return !!binding && !!binding.host_object && !!binding.binding_field;
39
+ }
40
+ function isDataComplete(data) {
41
+ return !!data && data.entries.length > 0;
42
+ }
43
+ function isQueryComplete(queries) {
44
+ return true;
45
+ }
46
+ function isLogicComplete(logic) {
47
+ return !!logic && !!logic.root && logic.root.return_type === "Bool";
48
+ }
49
+ function isConstraintsComplete(constraints) {
50
+ if (!constraints)
51
+ return false;
52
+ return Object.values(constraints).every((v) => v === true);
53
+ }
54
+ function recommendNextStep(puzzle, missing) {
55
+ if (missing.includes("intent")) {
56
+ return {
57
+ round: "R1",
58
+ action: "捕获验证意图",
59
+ questions: [
60
+ "你要保护什么动作?(buy/forward/claim/vote/dispute/write/allocate)",
61
+ "用一句话描述验证规则",
62
+ "列出 Guard 应该 FAIL 的情况",
63
+ ],
64
+ };
65
+ }
66
+ if (missing.includes("binding")) {
67
+ return {
68
+ round: "R5",
69
+ action: "确定绑定目标",
70
+ questions: [
71
+ "Guard 将绑定到哪个 Host Object?(Service/Machine/Arbitration/Reward/Repository)",
72
+ "绑定到哪个字段?(buy_guard/order_allocators/Forward.guard/...)",
73
+ "Guard 是否需要引用 Host Object?(循环引用模式)",
74
+ ],
75
+ };
76
+ }
77
+ if (missing.includes("data")) {
78
+ return {
79
+ round: "R2",
80
+ action: "声明数据表",
81
+ questions: [
82
+ "Guard 需要哪些常量数据?(已知且不变的值)",
83
+ "Guard 需要哪些提交数据?(运行时由 caller 提供)",
84
+ "每个提交数据的 value_type 是什么?",
85
+ "是否需要查询 EntityRegistrar(0xaab) 或 EntityLinker(0xaaa)?",
86
+ ],
87
+ };
88
+ }
89
+ if (missing.includes("query")) {
90
+ return {
91
+ round: "R3",
92
+ action: "设计查询节点",
93
+ questions: [
94
+ "Guard 需要查询哪些链上对象?",
95
+ "每个查询使用哪个指令 ID?(从 GUARDQUERY 查询)",
96
+ "是否需要 convert_witness 转换对象?",
97
+ ],
98
+ };
99
+ }
100
+ if (missing.includes("logic")) {
101
+ return {
102
+ round: "R3",
103
+ action: "设计计算树",
104
+ questions: [
105
+ "root 节点是什么?(必须返回 Bool)",
106
+ "数据源节点有哪些?(identifier/context/query)",
107
+ "中间转换节点有哪些?(calc_*/convert_*/vec_*)",
108
+ "是否需要 rely 组合其他 Guard?",
109
+ ],
110
+ };
111
+ }
112
+ if (missing.includes("constraints")) {
113
+ return {
114
+ round: "R6",
115
+ action: "预创建审查",
116
+ questions: ["运行 10 项 Common Pitfalls 检查清单"],
117
+ };
118
+ }
119
+ return {
120
+ round: "R7",
121
+ action: "准备链上创建",
122
+ questions: ["所有维度已补全,准备生成语义确认文本"],
123
+ };
124
+ }
125
+ export function generateConfirmationText(puzzle) {
126
+ if (!puzzle.intent || !puzzle.binding || !puzzle.data || !puzzle.logic) {
127
+ return "【拼图未完整】无法生成确认文本,请先补全所有维度";
128
+ }
129
+ const lines = [];
130
+ lines.push("═══════════════════════════════════════════════════════");
131
+ lines.push(" Guard 语义确认报告(用户审核版)");
132
+ lines.push("═══════════════════════════════════════════════════════");
133
+ lines.push("");
134
+ lines.push("【意图】");
135
+ lines.push(`被保护动作: ${puzzle.intent.action}`);
136
+ lines.push(`验证规则: ${puzzle.intent.rule_sentence}`);
137
+ lines.push("失败条件:");
138
+ puzzle.intent.failure_conditions.forEach((c, i) => {
139
+ lines.push(` ${i + 1}. ${c}`);
140
+ });
141
+ lines.push("");
142
+ lines.push("【绑定】");
143
+ lines.push(`Host Object: ${puzzle.binding.host_object}`);
144
+ if (puzzle.binding.host_object_name) {
145
+ lines.push(`Host Object 名称: ${puzzle.binding.host_object_name}`);
146
+ }
147
+ lines.push(`绑定字段: ${puzzle.binding.binding_field}`);
148
+ lines.push(`循环引用: ${puzzle.binding.circular_reference ? "是(Guard 引用 Host Object)" : "否"}`);
149
+ lines.push(`Host Object 状态: ${puzzle.binding.host_object_state}`);
150
+ lines.push("");
151
+ lines.push("【数据表】");
152
+ lines.push("┌─────┬──────────┬──────────┬───────────────┬─────────────────────────┐");
153
+ lines.push("│ ID │ 类型 │ 提交/常量│ 值/占位 │ 名称描述 │");
154
+ lines.push("├─────┼──────────┼──────────┼───────────────┼─────────────────────────┤");
155
+ puzzle.data.entries.forEach((e) => {
156
+ const id = String(e.identifier).padEnd(3);
157
+ const type = e.value_type.padEnd(8);
158
+ const src = (e.b_submission ? "提交" : "常量").padEnd(8);
159
+ const val = (e.b_submission ? "(运行时)" : String(e.value ?? "")).padEnd(13);
160
+ const name = e.name.length > 23 ? e.name.slice(0, 22) + "…" : e.name.padEnd(23);
161
+ lines.push(`│ ${id} │ ${type} │ ${src} │ ${val} │ ${name} │`);
162
+ });
163
+ lines.push("└─────┴──────────┴──────────┴───────────────┴─────────────────────────┘");
164
+ if (puzzle.data.witnesses.length > 0) {
165
+ lines.push("");
166
+ lines.push("【对象转换 (convert_witness)】");
167
+ puzzle.data.witnesses.forEach((w) => {
168
+ lines.push(` ${w.witness_type} (${w.witness_name}): ${w.source_type} → ${w.target_type}`);
169
+ lines.push(` 场景: ${w.scenario}`);
170
+ });
171
+ }
172
+ lines.push("");
173
+ if (puzzle.queries && puzzle.queries.length > 0) {
174
+ lines.push("【查询指令】");
175
+ lines.push("┌──────┬──────────────────────────┬────────────┬──────────┬──────────┐");
176
+ lines.push("│ ID │ 查询指令 │ 目标对象 │ 参数 │ 返回类型 │");
177
+ lines.push("├──────┼──────────────────────────┼────────────┼──────────┼──────────┤");
178
+ puzzle.queries.forEach((q) => {
179
+ const id = String(q.query_id).padEnd(4);
180
+ const name = q.query_name.length > 24 ? q.query_name.slice(0, 23) + "…" : q.query_name.padEnd(24);
181
+ const obj = q.object_type.padEnd(10);
182
+ const params = (q.parameters.length === 0 ? "(无)" : q.parameters.join(",")).padEnd(8);
183
+ const ret = q.return_type.padEnd(8);
184
+ lines.push(`│ ${id} │ ${name} │ ${obj} │ ${params} │ ${ret} │`);
185
+ });
186
+ lines.push("└──────┴──────────────────────────┴────────────┴──────────┴──────────┘");
187
+ lines.push("");
188
+ }
189
+ lines.push("【计算树】");
190
+ lines.push(`root: ${puzzle.logic.root.node_type} (返回: ${puzzle.logic.root.return_type})`);
191
+ lines.push(` ${puzzle.logic.root.description}`);
192
+ if (puzzle.logic.root.children) {
193
+ printLogicTree(lines, puzzle.logic.root.children, 1);
194
+ }
195
+ lines.push("");
196
+ if (puzzle.logic.rely) {
197
+ lines.push("【rely 组合】");
198
+ lines.push(`依赖 Guard: ${puzzle.logic.rely.guards.join(", ")}`);
199
+ lines.push(`逻辑: ${puzzle.logic.rely.logic_or ? "OR(任一通过即可)" : "AND(全部必须通过)"}`);
200
+ lines.push(`rep 验证: ${puzzle.logic.rely.rep_verified.every((v) => v) ? "全部通过" : "有未验证"}`);
201
+ lines.push("");
202
+ }
203
+ if (puzzle.constraints) {
204
+ lines.push("【约束检查清单 (10 项 Common Pitfalls)】");
205
+ const checks = [
206
+ ["01", "所有 identifier 在 table 中存在", puzzle.constraints.pitfall_01_identifiers_in_table],
207
+ ["02", "比较节点类型兼容", puzzle.constraints.pitfall_02_type_compatibility],
208
+ ["03", "查询指令 ID 和参数数量正确", puzzle.constraints.pitfall_03_query_instruction_valid],
209
+ ["04", "convert_witness 类型正确", puzzle.constraints.pitfall_04_witness_correct],
210
+ ["05", "时间锁测试用小值", puzzle.constraints.pitfall_05_time_lock_test_safe],
211
+ ["06", "迭代前已导出旧 Guard", puzzle.constraints.pitfall_06_exported_before_recreate],
212
+ ["07", "root 返回 Bool", puzzle.constraints.pitfall_07_root_returns_bool],
213
+ ["08", "rely 依赖 rep=true", puzzle.constraints.pitfall_08_rely_rep_true],
214
+ ["09", "voting_guard GuardIdentifier numeric", puzzle.constraints.pitfall_09_voting_weight_numeric],
215
+ ["10", "Arbitration 未暂停", puzzle.constraints.pitfall_10_arbitration_not_paused],
216
+ ];
217
+ checks.forEach(([num, desc, pass]) => {
218
+ lines.push(` ${pass ? "✓" : "✗"} [${num}] ${desc}`);
219
+ });
220
+ lines.push("");
221
+ }
222
+ lines.push("【风险提示】");
223
+ lines.push(" ⚠ Guard 创建后不可修改、不可删除(CREATE-only)");
224
+ lines.push(" ⚠ 链上执行将消耗 gas");
225
+ lines.push(" ⚠ 创建后如需修改,需 export → 编辑 → 新建 → 重新绑定");
226
+ lines.push("");
227
+ lines.push("【测试计划 (gen_passport 静态测试)】");
228
+ lines.push(" 预期通过场景: 提交符合条件的数据 → PASS → 生成 Passport");
229
+ lines.push(" 预期失败场景: 提交不符合条件的数据 → FAIL → 验证逻辑方向正确");
230
+ lines.push("");
231
+ lines.push("═══════════════════════════════════════════════════════");
232
+ lines.push(" 请审核以上 Guard 语义确认报告");
233
+ lines.push(" 确认无误后回复「确认创建」以执行链上 CREATE");
234
+ lines.push(" 如需修改,请指出需要调整的部分");
235
+ lines.push("═══════════════════════════════════════════════════════");
236
+ return lines.join("\n");
237
+ }
238
+ function printLogicTree(lines, nodes, depth) {
239
+ const indent = " ".repeat(depth + 1);
240
+ nodes.forEach((node, i) => {
241
+ const prefix = i === nodes.length - 1 ? "└── " : "├── ";
242
+ lines.push(`${indent}${prefix}${node.node_type} (${node.return_type}) — ${node.description}`);
243
+ if (node.references_identifier !== undefined) {
244
+ lines.push(`${indent} → table[${node.references_identifier}]`);
245
+ }
246
+ if (node.query) {
247
+ lines.push(`${indent} → query(${node.query.query_id}: ${node.query.query_name})`);
248
+ }
249
+ if (node.children) {
250
+ printLogicTree(lines, node.children, depth + 1);
251
+ }
252
+ });
253
+ }
254
+ export function initPuzzleFromIntent(intent) {
255
+ return {
256
+ current_round: "R1",
257
+ intent: {
258
+ action: intent.action ?? "custom",
259
+ rule_sentence: intent.rule_sentence ?? "",
260
+ failure_conditions: intent.failure_conditions ?? [],
261
+ },
262
+ };
263
+ }
264
+ export function inferBindingFromAction(action) {
265
+ const map = {
266
+ buy: { host_object: "Service", binding_field: "buy_guard" },
267
+ forward: { host_object: "Machine", binding_field: "Forward.guard" },
268
+ allocate: { host_object: "Service", binding_field: "order_allocators" },
269
+ claim_reward: { host_object: "Reward", binding_field: "guard" },
270
+ vote: { host_object: "Arbitration", binding_field: "voting_guard" },
271
+ dispute: { host_object: "Arbitration", binding_field: "usage_guard" },
272
+ write_repository: { host_object: "Repository", binding_field: "write_guard" },
273
+ submit_progress: { host_object: "Progress", binding_field: "submission" },
274
+ gen_passport: { host_object: "Standalone", binding_field: "none" },
275
+ custom: {},
276
+ };
277
+ return map[action] ?? {};
278
+ }