@wowok/agent-mcp 2.6.3 → 2.6.6

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 (193) hide show
  1. package/README.md +13 -9
  2. package/dist/customer/customer-advice.d.ts +31 -0
  3. package/dist/customer/customer-advice.js +129 -0
  4. package/dist/customer/index.d.ts +2 -0
  5. package/dist/customer/index.js +2 -0
  6. package/dist/customer/info-puzzle.d.ts +8 -1
  7. package/dist/customer/info-puzzle.js +30 -5
  8. package/dist/customer/order-monitor.d.ts +2 -0
  9. package/dist/customer/order-monitor.js +3 -2
  10. package/dist/customer/post-purchase.d.ts +2 -0
  11. package/dist/customer/post-purchase.js +6 -5
  12. package/dist/customer/preorder-compare.d.ts +24 -0
  13. package/dist/customer/preorder-compare.js +34 -0
  14. package/dist/customer/reminder-system.d.ts +2 -0
  15. package/dist/customer/reminder-system.js +2 -1
  16. package/dist/customer/risk-assessment.js +4 -3
  17. package/dist/customer/types.d.ts +5 -0
  18. package/dist/examples/arbitration-dispute-create.json +41 -0
  19. package/dist/examples/arbitration-vote-weighted.json +35 -0
  20. package/dist/examples/arbitration-voting-guard-add.json +38 -0
  21. package/dist/examples/demand-present-service.json +33 -0
  22. package/dist/examples/gen-passport-verify-guard.json +48 -0
  23. package/dist/examples/guard-template-balance-check.json +36 -15
  24. package/dist/examples/guard-template-time-lock.json +33 -12
  25. package/dist/examples/insurance-guard-claim-timelock.json +75 -0
  26. package/dist/examples/insurance-guard-withdraw-allocation.json +96 -0
  27. package/dist/examples/insurance-machine-create-publish.json +75 -0
  28. package/dist/examples/insurance-service-allocators-publish.json +56 -0
  29. package/dist/examples/machine-multisig-threshold.json +86 -0
  30. package/dist/examples/machine-template-7node-rental.json +99 -94
  31. package/dist/examples/payment-scenario-bound.json +45 -0
  32. package/dist/examples/rental-ziroom-machine-create.json +126 -114
  33. package/dist/examples/rental-ziroom-permission-create.json +10 -3
  34. package/dist/examples/rental-ziroom-service-create.json +27 -18
  35. package/dist/examples/retail-adv-guard-customer-win-create.json +80 -0
  36. package/dist/examples/retail-adv-guard-messenger-proof-create.json +65 -0
  37. package/dist/examples/retail-adv-guard-reward-timeout-create.json +92 -0
  38. package/dist/examples/retail-adv-reward-guard-add.json +51 -0
  39. package/dist/examples/retail-myshop-allocation-activate.json +55 -0
  40. package/dist/examples/retail-myshop-arbitration-create.json +40 -0
  41. package/dist/examples/retail-myshop-contact-create.json +43 -0
  42. package/dist/examples/retail-myshop-order-create.json +56 -0
  43. package/dist/examples/retail-myshop-progress-operate.json +38 -0
  44. package/dist/examples/retail-myshop-reward-create.json +35 -0
  45. package/dist/examples/service-discount-issue.json +46 -0
  46. package/dist/examples/threebody-guard-create.json +56 -0
  47. package/dist/examples/threebody-machine-create.json +72 -0
  48. package/dist/examples/threebody-permission-create.json +38 -0
  49. package/dist/examples/threebody-service-allocators.json +49 -0
  50. package/dist/examples/travel-guard-time-lock.json +69 -0
  51. package/dist/examples/travel-guard-weather-oracle.json +70 -0
  52. package/dist/examples/travel-machine-create.json +136 -0
  53. package/dist/examples/travel-repository-create.json +47 -0
  54. package/dist/examples/travel-service-create.json +102 -0
  55. package/dist/examples/travel-treasury-create.json +34 -0
  56. package/dist/examples/treasury-deposit.json +37 -0
  57. package/dist/examples/treasury-withdraw.json +38 -0
  58. package/dist/extensions/business-modules.d.ts +49 -0
  59. package/dist/extensions/business-modules.js +287 -0
  60. package/dist/extensions/capability-manifest.js +192 -5
  61. package/dist/extensions/constraint-registry.js +3 -1
  62. package/dist/extensions/modes.js +10 -4
  63. package/dist/extensions/registry.d.ts +14 -9
  64. package/dist/extensions/registry.js +69 -14
  65. package/dist/extensions/types.d.ts +1 -0
  66. package/dist/knowledge/fund-layer.d.ts +67 -1
  67. package/dist/knowledge/fund-layer.js +561 -12
  68. package/dist/knowledge/guard-templates.d.ts +10 -0
  69. package/dist/knowledge/guard-templates.js +50 -0
  70. package/dist/knowledge/index.d.ts +2 -2
  71. package/dist/knowledge/index.js +2 -2
  72. package/dist/knowledge/machine-risk.js +4 -1
  73. package/dist/knowledge/progress-context.js +1 -1
  74. package/dist/knowledge/progress-ledger.js +3 -3
  75. package/dist/knowledge/progress-templates.js +1 -1
  76. package/dist/knowledge/progress-translation.js +1 -1
  77. package/dist/knowledge/safety-rules.d.ts +83 -1
  78. package/dist/knowledge/safety-rules.js +166 -2
  79. package/dist/knowledge/scenario-modes.d.ts +1 -1
  80. package/dist/knowledge/scenario-modes.js +13 -11
  81. package/dist/knowledge/template-registry.d.ts +48 -0
  82. package/dist/knowledge/template-registry.js +341 -0
  83. package/dist/knowledge/tool-constraints.js +6 -6
  84. package/dist/knowledge/tools-reference.js +11 -8
  85. package/dist/participation/merchant-interest.d.ts +32 -0
  86. package/dist/participation/merchant-interest.js +100 -0
  87. package/dist/participation/radar-core.d.ts +104 -0
  88. package/dist/participation/radar-core.js +269 -0
  89. package/dist/project/context-assembly.js +8 -0
  90. package/dist/project/edit-planner.js +27 -56
  91. package/dist/project/evaluation.d.ts +36 -0
  92. package/dist/project/evaluation.js +422 -56
  93. package/dist/project/game-theory.d.ts +43 -0
  94. package/dist/project/game-theory.js +177 -0
  95. package/dist/project/graph-builder.js +1 -0
  96. package/dist/project/handlers.d.ts +38 -0
  97. package/dist/project/handlers.js +65 -35
  98. package/dist/project/intent-analyzer.d.ts +71 -0
  99. package/dist/project/intent-analyzer.js +149 -0
  100. package/dist/project/machine-nodes.d.ts +2 -0
  101. package/dist/project/machine-nodes.js +36 -0
  102. package/dist/project/merchant-guide.d.ts +165 -0
  103. package/dist/project/merchant-guide.js +264 -0
  104. package/dist/project/mode-actions.d.ts +199 -0
  105. package/dist/project/mode-actions.js +309 -0
  106. package/dist/project/participation-radar.d.ts +18 -0
  107. package/dist/project/participation-radar.js +428 -0
  108. package/dist/project/pipeline-actions.d.ts +101 -0
  109. package/dist/project/pipeline-actions.js +109 -0
  110. package/dist/project/semantic-graph.d.ts +95 -0
  111. package/dist/project/semantic-graph.js +245 -0
  112. package/dist/schema/call/allocation.d.ts +11 -11
  113. package/dist/schema/call/allocation.js +11 -1
  114. package/dist/schema/call/arbitration.d.ts +21 -21
  115. package/dist/schema/call/arbitration.js +17 -9
  116. package/dist/schema/call/base.d.ts +2 -2
  117. package/dist/schema/call/base.js +1 -1
  118. package/dist/schema/call/bridge.d.ts +127 -127
  119. package/dist/schema/call/bridge.js +12 -12
  120. package/dist/schema/call/contact.d.ts +3 -3
  121. package/dist/schema/call/demand.d.ts +3 -3
  122. package/dist/schema/call/guard.d.ts +11 -11
  123. package/dist/schema/call/guard.js +1 -1
  124. package/dist/schema/call/machine.d.ts +216 -21
  125. package/dist/schema/call/machine.js +1 -1
  126. package/dist/schema/call/order.d.ts +7 -7
  127. package/dist/schema/call/payment.d.ts +3 -3
  128. package/dist/schema/call/permission.d.ts +3 -3
  129. package/dist/schema/call/personal.d.ts +337 -3
  130. package/dist/schema/call/personal.js +10 -0
  131. package/dist/schema/call/progress.d.ts +177 -9
  132. package/dist/schema/call/progress.js +7 -3
  133. package/dist/schema/call/proof.d.ts +6 -6
  134. package/dist/schema/call/repository.d.ts +3 -3
  135. package/dist/schema/call/reward.d.ts +57 -57
  136. package/dist/schema/call/semantic.js +41 -1
  137. package/dist/schema/call/service.d.ts +114 -114
  138. package/dist/schema/call/service.js +11 -2
  139. package/dist/schema/call/treasury.d.ts +57 -57
  140. package/dist/schema/messenger/index.js +4 -1
  141. package/dist/schema/operations.d.ts +713 -291
  142. package/dist/schema/operations.js +33 -0
  143. package/dist/schema/project/index.d.ts +4635 -100
  144. package/dist/schema/project/index.js +868 -1
  145. package/dist/schema/query/index.d.ts +363 -19
  146. package/dist/schema/query/index.js +25 -3
  147. package/dist/schema/schema-query/index.d.ts +13 -7
  148. package/dist/schema/schema-query/index.js +29 -5
  149. package/dist/schema/trust/index.d.ts +1012 -6
  150. package/dist/schema/trust/index.js +212 -11
  151. package/dist/schema/utils/skills-recommendation.js +1 -0
  152. package/dist/schema-query/index.d.ts +4 -1
  153. package/dist/schema-query/index.js +255 -1
  154. package/dist/schemas/bridge_operation.schema.json +14 -7
  155. package/dist/schemas/guard2file.schema.json +2 -0
  156. package/dist/schemas/index.json +1 -1
  157. package/dist/schemas/machineNode2file.schema.json +2 -0
  158. package/dist/schemas/messenger_operation.schema.json +1 -1
  159. package/dist/schemas/onchain_operations.schema.json +143 -15
  160. package/dist/schemas/onchain_operations_allocation.schema.json +2 -1
  161. package/dist/schemas/onchain_operations_arbitration.schema.json +7 -5
  162. package/dist/schemas/onchain_operations_contact.schema.json +1 -0
  163. package/dist/schemas/onchain_operations_demand.schema.json +1 -0
  164. package/dist/schemas/onchain_operations_gen_passport.schema.json +2 -0
  165. package/dist/schemas/onchain_operations_gen_proof.schema.json +2 -0
  166. package/dist/schemas/onchain_operations_guard.schema.json +578 -0
  167. package/dist/schemas/onchain_operations_machine.schema.json +1 -0
  168. package/dist/schemas/onchain_operations_order.schema.json +4 -3
  169. package/dist/schemas/onchain_operations_payment.schema.json +1 -0
  170. package/dist/schemas/onchain_operations_permission.schema.json +1 -0
  171. package/dist/schemas/onchain_operations_personal.schema.json +37 -0
  172. package/dist/schemas/onchain_operations_progress.schema.json +90 -3
  173. package/dist/schemas/onchain_operations_proof.schema.json +1 -0
  174. package/dist/schemas/onchain_operations_repository.schema.json +1 -0
  175. package/dist/schemas/onchain_operations_reward.schema.json +1 -0
  176. package/dist/schemas/onchain_operations_service.schema.json +4 -3
  177. package/dist/schemas/onchain_operations_treasury.schema.json +1 -0
  178. package/dist/schemas/project_operation.output.json +2243 -1
  179. package/dist/schemas/project_operation.schema.json +683 -1
  180. package/dist/schemas/query_toolkit.output.json +1 -1
  181. package/dist/schemas/query_toolkit.schema.json +37 -0
  182. package/dist/schemas/schema_query.output.json +1 -1
  183. package/dist/schemas/schema_query.schema.json +30 -5
  184. package/dist/schemas/trust_score.output.json +392 -1
  185. package/dist/schemas/trust_score.schema.json +275 -1
  186. package/dist/tools/handlers/onchain.js +73 -8
  187. package/dist/tools/handlers/project.js +46 -0
  188. package/dist/tools/handlers/query.js +117 -2
  189. package/dist/tools/handlers/schema-query.js +41 -0
  190. package/dist/tools/handlers/trust.js +192 -6
  191. package/dist/tools/index.js +52 -9
  192. package/dist/tools/wrap.js +194 -15
  193. package/package.json +2 -2
@@ -26,7 +26,272 @@
26
26
  "evaluate",
27
27
  "preorder"
28
28
  ],
29
- "description": "InfoPuzzle collection depth. browse: only Service basics + trust score; evaluate (default): + workflow/fund/trust dimensions risk assessment; preorder: + merchant behavior + market context (most thorough)."
29
+ "description": "InfoPuzzle collection depth. browse: only Service basics + trust score; evaluate (default): + workflow/fund/trust dimensions risk assessment; preorder: + full preorder advice (confidence, game strategies, preference match, industry risks, blocking reminders)."
30
+ },
31
+ "industry": {
32
+ "type": "string",
33
+ "enum": [
34
+ "freelance",
35
+ "rental",
36
+ "education",
37
+ "travel",
38
+ "subscription",
39
+ "retail"
40
+ ],
41
+ "description": "Explicit industry override for industry-specific risk checks and needs matrix. If omitted at depth=preorder, the industry is inferred from the puzzle."
42
+ },
43
+ "preferences": {
44
+ "type": "object",
45
+ "properties": {
46
+ "price_sensitivity": {
47
+ "type": "string",
48
+ "enum": [
49
+ "low",
50
+ "medium",
51
+ "high"
52
+ ]
53
+ },
54
+ "budget_range": {
55
+ "type": "object",
56
+ "properties": {
57
+ "min": {
58
+ "type": [
59
+ "string",
60
+ "number"
61
+ ],
62
+ "description": "Budget lower bound (smallest token unit)."
63
+ },
64
+ "max": {
65
+ "type": [
66
+ "string",
67
+ "number"
68
+ ],
69
+ "description": "Budget upper bound (smallest token unit)."
70
+ }
71
+ },
72
+ "required": [
73
+ "min",
74
+ "max"
75
+ ],
76
+ "additionalProperties": false
77
+ },
78
+ "value_orientation": {
79
+ "type": "string",
80
+ "enum": [
81
+ "quality",
82
+ "balanced",
83
+ "budget"
84
+ ]
85
+ },
86
+ "discount_sensitivity": {
87
+ "type": "number",
88
+ "minimum": 0,
89
+ "maximum": 1
90
+ },
91
+ "delivery_speed_priority": {
92
+ "type": "string",
93
+ "enum": [
94
+ "urgent",
95
+ "normal",
96
+ "flexible"
97
+ ]
98
+ },
99
+ "max_acceptable_cycle": {
100
+ "type": "number",
101
+ "minimum": 0,
102
+ "description": "Max acceptable delivery cycle (days)."
103
+ },
104
+ "response_time_expectation": {
105
+ "type": "number",
106
+ "minimum": 0,
107
+ "description": "Expected merchant response time (hours)."
108
+ },
109
+ "merchant_preference": {
110
+ "type": "string",
111
+ "enum": [
112
+ "established",
113
+ "emerging",
114
+ "neutral"
115
+ ]
116
+ },
117
+ "min_order_history": {
118
+ "type": "integer",
119
+ "minimum": 0
120
+ },
121
+ "bargain_hunting": {
122
+ "type": "number",
123
+ "minimum": 0,
124
+ "maximum": 1
125
+ },
126
+ "reward_seeking": {
127
+ "type": "boolean"
128
+ },
129
+ "referral_participation": {
130
+ "type": "boolean"
131
+ },
132
+ "communication_style": {
133
+ "type": "string",
134
+ "enum": [
135
+ "formal",
136
+ "casual",
137
+ "friendly"
138
+ ]
139
+ },
140
+ "transparency_demand": {
141
+ "type": "number",
142
+ "minimum": 0,
143
+ "maximum": 1
144
+ },
145
+ "after_sales_expectation": {
146
+ "type": "string",
147
+ "enum": [
148
+ "full",
149
+ "basic",
150
+ "minimal"
151
+ ]
152
+ },
153
+ "risk_appetite": {
154
+ "type": "string",
155
+ "enum": [
156
+ "conservative",
157
+ "balanced",
158
+ "aggressive"
159
+ ]
160
+ },
161
+ "min_trust_score": {
162
+ "type": "number",
163
+ "minimum": 0,
164
+ "maximum": 100
165
+ },
166
+ "require_arbitration": {
167
+ "type": "boolean"
168
+ },
169
+ "require_compensation_fund": {
170
+ "type": "boolean"
171
+ },
172
+ "preferred_industries": {
173
+ "type": "array",
174
+ "items": {
175
+ "type": "string"
176
+ }
177
+ },
178
+ "preferred_tokens": {
179
+ "type": "array",
180
+ "items": {
181
+ "type": "string"
182
+ }
183
+ },
184
+ "preferred_merchants": {
185
+ "type": "array",
186
+ "items": {
187
+ "type": "string"
188
+ }
189
+ }
190
+ },
191
+ "additionalProperties": false,
192
+ "description": "Optional user preference overrides (partial; merged over profile-derived defaults). Only used at depth=preorder for preference matching and pref-aware strategies."
193
+ },
194
+ "user_metrics": {
195
+ "type": "object",
196
+ "properties": {
197
+ "metrics": {
198
+ "type": "array",
199
+ "items": {
200
+ "type": "object",
201
+ "properties": {
202
+ "name": {
203
+ "type": "string",
204
+ "description": "Stable metric identifier (e.g. 'merchant_tenure_days')."
205
+ },
206
+ "label": {
207
+ "type": "string",
208
+ "description": "Human-readable label shown to the user."
209
+ },
210
+ "evaluator": {
211
+ "type": "string",
212
+ "enum": [
213
+ "threshold",
214
+ "ratio",
215
+ "boolean",
216
+ "presence",
217
+ "regex_match",
218
+ "custom_query"
219
+ ],
220
+ "description": "How the metric is evaluated against the puzzle context."
221
+ },
222
+ "params": {
223
+ "type": "object",
224
+ "properties": {
225
+ "path": {
226
+ "type": "string",
227
+ "description": "JSON path in the raw data context (e.g. 'service.name')."
228
+ },
229
+ "threshold": {
230
+ "type": [
231
+ "string",
232
+ "number"
233
+ ],
234
+ "description": "Threshold value (threshold/presence evaluators)."
235
+ },
236
+ "invert": {
237
+ "type": "boolean",
238
+ "description": "true: pass when value <= threshold."
239
+ },
240
+ "min": {
241
+ "type": "number",
242
+ "description": "Min ratio (ratio evaluator)."
243
+ },
244
+ "max": {
245
+ "type": "number",
246
+ "description": "Max ratio (ratio evaluator)."
247
+ },
248
+ "pattern": {
249
+ "type": "string",
250
+ "description": "Regex pattern (regex_match evaluator)."
251
+ },
252
+ "query_key": {
253
+ "type": "string",
254
+ "description": "Custom query identifier (custom_query evaluator)."
255
+ }
256
+ },
257
+ "additionalProperties": false
258
+ },
259
+ "weight": {
260
+ "type": "number",
261
+ "minimum": 0,
262
+ "maximum": 1,
263
+ "description": "Relative weight vs other user metrics (0-1)."
264
+ },
265
+ "advice_on_fail": {
266
+ "type": "string"
267
+ },
268
+ "advice_on_pass": {
269
+ "type": "string"
270
+ }
271
+ },
272
+ "required": [
273
+ "name",
274
+ "label",
275
+ "evaluator",
276
+ "params",
277
+ "weight"
278
+ ],
279
+ "additionalProperties": false
280
+ },
281
+ "minItems": 1,
282
+ "description": "User-defined scoring factors."
283
+ },
284
+ "adjustment_cap": {
285
+ "type": "number",
286
+ "exclusiveMinimum": 0,
287
+ "description": "Global cap for the composite confidence adjustment (default ±10 points)."
288
+ }
289
+ },
290
+ "required": [
291
+ "metrics"
292
+ ],
293
+ "additionalProperties": false,
294
+ "description": "Optional user-controllable scoring factors (评分体系用户可控). Evaluated at depth=preorder; the composite adjustment (±cap) nudges the order confidence score."
30
295
  },
31
296
  "network": {
32
297
  "type": "string",
@@ -35,6 +300,15 @@
35
300
  "no_cache": {
36
301
  "type": "boolean",
37
302
  "description": "Skip object cache and force a fresh on-chain query."
303
+ },
304
+ "compare_with": {
305
+ "type": "array",
306
+ "items": {
307
+ "type": "string"
308
+ },
309
+ "minItems": 1,
310
+ "maxItems": 9,
311
+ "description": "Optional candidate Service addresses/LocalMark names (1-9) for deterministic multi-service comparison. Only used at depth=preorder. The SAME preferences/user_metrics/industry are applied uniformly to all candidates; output gains a `comparison` block with per-metric bests (NO overall ranking — the buyer decides)."
38
312
  }
39
313
  },
40
314
  "required": [
@@ -6,7 +6,7 @@ import { handlePermissionOperations } from "../../schema/call/permission-handler
6
6
  import { collectPermissionIndexes, checkPermissionAuthorization, formatPermissionWarning, } from "../../schema/utils/permission-machine-check.js";
7
7
  import { isProjectServiceEnabled, normalize as projectNormalize, } from "../../project/index.js";
8
8
  import { getSkillsHintForOnchain } from "../../schema/utils/skills-recommendation.js";
9
- import { processFundOperation, generateSkillsHint as generateFundSkillsHint } from "../../knowledge/fund-layer.js";
9
+ import { prepareFundOperation, generateSkillsHint as generateFundSkillsHint } from "../../knowledge/fund-layer.js";
10
10
  import { generateGuardSubmissionPrompt, formatSubmissionPrompt } from "../../knowledge/guard-submission-prompt.js";
11
11
  import { withHarness } from "../shared.js";
12
12
  function formatRecipientLabel(recipient) {
@@ -242,6 +242,45 @@ async function detectServiceGuardCircularDependency(data) {
242
242
  },
243
243
  };
244
244
  }
245
+ function buildFundBlockResult(fund, operationType) {
246
+ const hasMismatch = fund.matchErrors.length > 0;
247
+ const hasInputErrors = fund.errors.length > 0;
248
+ const title = hasMismatch && hasInputErrors
249
+ ? "FUND OPERATION BLOCKED"
250
+ : hasMismatch
251
+ ? "TOKEN TYPE MISMATCH — operation blocked"
252
+ : "FUND INPUT BLOCKED — operation blocked";
253
+ const errorCode = hasMismatch && hasInputErrors
254
+ ? "fund_blocked"
255
+ : hasMismatch
256
+ ? "token_type_mismatch"
257
+ : "fund_input_error";
258
+ const errorText = `⛔ ${title}\n\n` +
259
+ fund.blockingErrors.map(e => ` • ${e}`).join("\n") +
260
+ `\n\nThe token type of a generic on-chain object (e.g. Treasury<T>, Service<T>) is ` +
261
+ `determined at creation and can NEVER be changed, and monetary input is never ` +
262
+ `processed with unknown token precision. This ${operationType} operation was ` +
263
+ `NOT executed. Fix the errors above and re-issue the operation` +
264
+ (fund.objectTokenType ? ` (object token type: ${fund.objectTokenType})` : "") + ".";
265
+ return {
266
+ content: [{ type: "text", text: errorText }],
267
+ structuredContent: {
268
+ result: {
269
+ type: "error",
270
+ error: fund.blockingErrors.join(" | "),
271
+ error_code: errorCode,
272
+ retryable: true,
273
+ recovery_hint: `Use token type ${fund.objectTokenType ?? "<the object's generic token type>"} for all ` +
274
+ `amounts, coins, and receive records in this ${operationType} operation. ` +
275
+ `Query the object via query_toolkit onchain_objects to confirm its generic ` +
276
+ `token type (type_raw, e.g. "0x2::treasury::Treasury<0x2::wow::WOW>"). ` +
277
+ `For precision-unavailable tokens, retry the operation — the on-chain ` +
278
+ `metadata lookup may have been transient.`,
279
+ },
280
+ message: "Fund operation blocked before execution.",
281
+ },
282
+ };
283
+ }
245
284
  export async function handleOnchainOperations(args) {
246
285
  let validated;
247
286
  let constraintWarnings = [];
@@ -350,7 +389,10 @@ export async function handleOnchainOperations(args) {
350
389
  if (circularDepGuide) {
351
390
  return circularDepGuide;
352
391
  }
353
- const fundResult = await processFundOperation(data, "service", env?.network);
392
+ const fundResult = await prepareFundOperation(data, "service", env?.network);
393
+ if (fundResult.blockingErrors.length > 0) {
394
+ return buildFundBlockResult(fundResult, "service");
395
+ }
354
396
  constraintWarnings.push(...fundResult.warnings);
355
397
  if (fundResult.confirmation) {
356
398
  constraintWarnings.push(fundResult.confirmation.message);
@@ -511,10 +553,10 @@ export async function handleOnchainOperations(args) {
511
553
  ` - The Order object is the bridge: it has 'progress' (Machine) and 'dispute' (Arb list) fields\n` +
512
554
  ` - When Arb rules, it calls order::compensate() — the ONLY connection to the business flow\n\n` +
513
555
  `CORRECT PATTERN:\n` +
514
- ` - Machine: business states only (ordered -> shipped -> delivered -> refunded -> completed)\n` +
556
+ ` - Machine: business states only (ordered -> shipped -> delivered -> completed)\n` +
515
557
  ` - Arbitration: separate object with its own Permission (NOT shared with Service)\n` +
516
558
  ` - Arb: 7-state lifecycle (Principal_confirming -> Arbitrator_confirming -> Voting -> Arbitrated -> Objectionable -> Finished -> Withdrawn)\n` +
517
- ` - Use 'refunded'/'cancelled' nodes for the BUSINESS OUTCOME of a dispute, not 'disputed'\n\n` +
559
+ ` - R-M1-11: NEVER name nodes 'refunded'/'disputed'/'arb'/'refund' — use business states ('cancelled'/'returned') for dispute OUTCOMES; refunds route via Allocator triggered by those states, disputes via the separate Arbitration object\n\n` +
518
560
  `If this node name is a legitimate business state (not arbitration), ignore this warning.`);
519
561
  }
520
562
  }
@@ -612,7 +654,10 @@ export async function handleOnchainOperations(args) {
612
654
  return output;
613
655
  }
614
656
  case "arbitration": {
615
- const arbFundResult = await processFundOperation(validated.data, "arbitration", env?.network);
657
+ const arbFundResult = await prepareFundOperation(validated.data, "arbitration", env?.network);
658
+ if (arbFundResult.blockingErrors.length > 0) {
659
+ return buildFundBlockResult(arbFundResult, "arbitration");
660
+ }
616
661
  constraintWarnings.push(...arbFundResult.warnings);
617
662
  if (arbFundResult.confirmation) {
618
663
  constraintWarnings.push(arbFundResult.confirmation.message);
@@ -638,7 +683,10 @@ export async function handleOnchainOperations(args) {
638
683
  return output;
639
684
  }
640
685
  case "treasury": {
641
- const trFundResult = await processFundOperation(validated.data, "treasury", env?.network);
686
+ const trFundResult = await prepareFundOperation(validated.data, "treasury", env?.network);
687
+ if (trFundResult.blockingErrors.length > 0) {
688
+ return buildFundBlockResult(trFundResult, "treasury");
689
+ }
642
690
  constraintWarnings.push(...trFundResult.warnings);
643
691
  if (trFundResult.confirmation) {
644
692
  constraintWarnings.push(trFundResult.confirmation.message);
@@ -655,7 +703,10 @@ export async function handleOnchainOperations(args) {
655
703
  return output;
656
704
  }
657
705
  case "reward": {
658
- const rwFundResult = await processFundOperation(validated.data, "reward", env?.network);
706
+ const rwFundResult = await prepareFundOperation(validated.data, "reward", env?.network);
707
+ if (rwFundResult.blockingErrors.length > 0) {
708
+ return buildFundBlockResult(rwFundResult, "reward");
709
+ }
659
710
  constraintWarnings.push(...rwFundResult.warnings);
660
711
  if (rwFundResult.confirmation) {
661
712
  constraintWarnings.push(rwFundResult.confirmation.message);
@@ -673,6 +724,17 @@ export async function handleOnchainOperations(args) {
673
724
  return output;
674
725
  }
675
726
  case "allocation": {
727
+ const alFundResult = await prepareFundOperation(validated.data, "allocation", env?.network);
728
+ if (alFundResult.blockingErrors.length > 0) {
729
+ return buildFundBlockResult(alFundResult, "allocation");
730
+ }
731
+ constraintWarnings.push(...alFundResult.warnings);
732
+ if (alFundResult.confirmation) {
733
+ constraintWarnings.push(alFundResult.confirmation.message);
734
+ const fundHint = generateFundSkillsHint(alFundResult.confirmation);
735
+ if (fundHint)
736
+ constraintWarnings.push(fundHint);
737
+ }
676
738
  const callAllocation = new CallAllocation(validated.data);
677
739
  const result = validated.submission
678
740
  ? await callAllocation.call_with_submission(env, await transformSubmission(validated.submission))
@@ -824,7 +886,10 @@ export async function handleOnchainOperations(args) {
824
886
  return output;
825
887
  }
826
888
  case "payment": {
827
- const payFundResult = await processFundOperation(validated.data, "payment", env?.network);
889
+ const payFundResult = await prepareFundOperation(validated.data, "payment", env?.network);
890
+ if (payFundResult.blockingErrors.length > 0) {
891
+ return buildFundBlockResult(payFundResult, "payment");
892
+ }
828
893
  constraintWarnings.push(...payFundResult.warnings);
829
894
  if (payFundResult.confirmation) {
830
895
  constraintWarnings.push(payFundResult.confirmation.message);
@@ -5,6 +5,10 @@ import { validateStageGate } from "../../project/stage-gate.js";
5
5
  import { scanDeployment } from "../../knowledge/deployment-scanner.js";
6
6
  import { handleListProjects, handleCreateProject, handleCreateProjectFromOnchain, handleUpdateProject, handleGetProjectDetail, handleAddObject, handleRemoveObject, handleUpdateObject, handleCreateVersion, handleBuildGraph, handleGetGraph, handleEvaluateProject, handleSaveEvaluation, handleCompareProjects, handleRefreshObjects, handleGetObjectDiff, handleDeleteProject, handleGetMachineGraph, handleGetGuardGraph, handlePreEvaluateCheck, handleVerifyDeployment, handleCloneProjectToNetwork, handleMigrateToMainnet, } from "../../project/handlers.js";
7
7
  import { handlePlanObjectEdit, handleApplyObjectEdit, handlePatchMachineNodes, handlePatchGuardTree, } from "../../project/edit-planner.js";
8
+ import { handleRecommendIndustry, handleListModes, handleDeriveUserMode, handleEvolveUserMode, handleRegisterUserMode, handleUnregisterUserMode, handleRegisterCustomMetric, handleRegisterCustomConstraint, handleListMetricsConstraints, } from "../../project/mode-actions.js";
9
+ import { handleAnalyzeIntent, handleAggregateRisks, handleTraceSubsteps, } from "../../project/pipeline-actions.js";
10
+ import { handleMerchantGuide } from "../../project/merchant-guide.js";
11
+ import { handleParticipationRadar } from "../../project/participation-radar.js";
8
12
  import { strictParse } from "../../schema/index.js";
9
13
  import { ProjectOperationInputSchema } from "../../schema/project/index.js";
10
14
  import { getStageCache } from "../../project/index.js";
@@ -152,6 +156,48 @@ export async function handleProjectOperation(args) {
152
156
  case "patch_guard_tree":
153
157
  result = await handlePatchGuardTree(validated);
154
158
  break;
159
+ case "recommend_industry":
160
+ result = handleRecommendIndustry(validated);
161
+ break;
162
+ case "list_modes":
163
+ result = await handleListModes();
164
+ break;
165
+ case "derive_user_mode":
166
+ result = await handleDeriveUserMode(validated);
167
+ break;
168
+ case "evolve_user_mode":
169
+ result = await handleEvolveUserMode(validated);
170
+ break;
171
+ case "register_user_mode":
172
+ result = await handleRegisterUserMode(validated);
173
+ break;
174
+ case "unregister_user_mode":
175
+ result = await handleUnregisterUserMode(validated);
176
+ break;
177
+ case "register_custom_metric":
178
+ result = handleRegisterCustomMetric(validated);
179
+ break;
180
+ case "register_custom_constraint":
181
+ result = handleRegisterCustomConstraint(validated);
182
+ break;
183
+ case "list_metrics_constraints":
184
+ result = handleListMetricsConstraints(validated);
185
+ break;
186
+ case "analyze_intent":
187
+ result = handleAnalyzeIntent(validated);
188
+ break;
189
+ case "aggregate_risks":
190
+ result = handleAggregateRisks(validated);
191
+ break;
192
+ case "trace_substeps":
193
+ result = handleTraceSubsteps(validated);
194
+ break;
195
+ case "merchant_guide":
196
+ result = await handleMerchantGuide(validated);
197
+ break;
198
+ case "participation_radar":
199
+ result = await handleParticipationRadar(validated);
200
+ break;
155
201
  default:
156
202
  throw new Error(`Unknown project_operation action: ${String(action)}`);
157
203
  }
@@ -1,7 +1,46 @@
1
1
  import { strictParse, WatchQueryOperationsSchema, OnchainTableDataSchema, OnchainEventsInputSchema, ProtocolInfoQuerySchema, } from "../../schema/index.js";
2
2
  import { query_local_mark_list, query_account_list, query_local_info_list, query_local_token_list, query_account, GetLocalNamesByAddresses, query_personal, query_objects, query_table, query_tableItem, queryTableItem_RepositoryData, queryTableItem_PermissionPerm, queryTableItem_RewardRecord, queryTableItem_DemandPresenter, queryTableItem_TreasuryHistory, queryTableItem_MachineNode, queryTableItem_ProgressHistory, queryTableItem_AddressMark, queryTableItem_EntityRegistrar, queryTableItem_EntityLinker, query_received, queryProtocolInfo, query_events, query_transaction, query_object_history, query_address_activity, generateNodeComments, } from "@wowok/wowok";
3
3
  import { buildDataSemantic, } from "../../schema/call/semantic.js";
4
+ import { formatChainValue, annotateObjectMonetaryFields, annotateTableItemMonetaryFields, annotateEventsMonetaryFields, annotateBalanceChanges, resolveParentObjectTokenType, convertTokenValue, } from "../../knowledge/fund-layer.js";
4
5
  import { normalizeAccountOrMark } from "./messenger.js";
6
+ async function annotateAccountBalance(result, network) {
7
+ if (!result || typeof result !== "object")
8
+ return;
9
+ const displays = {};
10
+ const convert = (raw, coinType) => {
11
+ if (raw === null || raw === undefined)
12
+ return undefined;
13
+ if (typeof raw !== "string" && typeof raw !== "number" && typeof raw !== "bigint")
14
+ return undefined;
15
+ if (typeof coinType !== "string" || !coinType)
16
+ return undefined;
17
+ return formatChainValue(raw, coinType, network);
18
+ };
19
+ const balance = result.balance;
20
+ if (balance && typeof balance === "object") {
21
+ const coinType = balance.coinType;
22
+ const total = await convert(balance.totalBalance, coinType);
23
+ if (total)
24
+ displays["balance.totalBalance"] = total;
25
+ if (balance.lockedBalance !== undefined) {
26
+ const locked = await convert(balance.lockedBalance, coinType);
27
+ if (locked)
28
+ displays["balance.lockedBalance"] = locked;
29
+ }
30
+ }
31
+ const coinData = result.coin?.data;
32
+ if (Array.isArray(coinData)) {
33
+ for (let i = 0; i < coinData.length; i++) {
34
+ const c = coinData[i];
35
+ const d = await convert(c?.balance, c?.coinType);
36
+ if (d)
37
+ displays[`coin.data[${i}].balance`] = d;
38
+ }
39
+ }
40
+ if (Object.keys(displays).length > 0) {
41
+ result._money_display = displays;
42
+ }
43
+ }
5
44
  export async function handleWatchQueryOperations(args) {
6
45
  const validated = strictParse(WatchQueryOperationsSchema, args, "watch_and_query input");
7
46
  let result;
@@ -34,6 +73,7 @@ export async function handleWatchQueryOperations(args) {
34
73
  coin: validated.coin,
35
74
  network: validated.network,
36
75
  });
76
+ await annotateAccountBalance(queryResult, validated.network);
37
77
  result = { query_type: "account_balance", result: queryResult };
38
78
  break;
39
79
  }
@@ -100,6 +140,13 @@ export async function handleWatchQueryOperations(args) {
100
140
  }
101
141
  return obj;
102
142
  });
143
+ for (const obj of queryResult.objects) {
144
+ try {
145
+ await annotateObjectMonetaryFields(obj, validated.network);
146
+ }
147
+ catch {
148
+ }
149
+ }
103
150
  }
104
151
  result = { query_type: "onchain_objects", result: queryResult };
105
152
  break;
@@ -113,7 +160,37 @@ export async function handleWatchQueryOperations(args) {
113
160
  no_cache: validated.no_cache,
114
161
  network: validated.network,
115
162
  });
116
- result = { query_type: "onchain_received", result: queryResult };
163
+ const qr = queryResult;
164
+ if (qr && typeof qr === "object" && typeof qr.balance === "bigint") {
165
+ const tokenType = qr.token_type;
166
+ qr.balance = qr.balance.toString();
167
+ if (Array.isArray(qr.received)) {
168
+ for (const item of qr.received) {
169
+ if (item && typeof item.balance === "bigint") {
170
+ item.balance = item.balance.toString();
171
+ }
172
+ }
173
+ }
174
+ if (tokenType) {
175
+ try {
176
+ const displays = {
177
+ balance: await formatChainValue(qr.balance, tokenType, validated.network),
178
+ };
179
+ if (Array.isArray(qr.received)) {
180
+ for (let i = 0; i < qr.received.length; i++) {
181
+ const b = qr.received[i]?.balance;
182
+ if (b !== undefined && b !== null) {
183
+ displays[`received[${i}].balance`] = await formatChainValue(b, tokenType, validated.network);
184
+ }
185
+ }
186
+ }
187
+ qr._money_display = displays;
188
+ }
189
+ catch {
190
+ }
191
+ }
192
+ }
193
+ result = { query_type: "onchain_received", result: qr };
117
194
  break;
118
195
  }
119
196
  case "onchain_transaction": {
@@ -122,6 +199,11 @@ export async function handleWatchQueryOperations(args) {
122
199
  no_cache: validated.no_cache,
123
200
  network: validated.network,
124
201
  });
202
+ try {
203
+ await annotateBalanceChanges(queryResult?.balance_changes, validated.network);
204
+ }
205
+ catch {
206
+ }
125
207
  result = { query_type: "onchain_transaction", result: queryResult };
126
208
  break;
127
209
  }
@@ -152,8 +234,20 @@ export async function handleWatchQueryOperations(args) {
152
234
  result = { query_type: "onchain_address_activity", result: queryResult };
153
235
  break;
154
236
  }
237
+ case "token_value_convert": {
238
+ const hasRaw = validated.raw !== undefined;
239
+ const hasUnit = validated.unit !== undefined;
240
+ if (hasRaw === hasUnit) {
241
+ throw new Error(`token_value_convert: provide EXACTLY ONE of 'raw' (u64 smallest units → unit value) ` +
242
+ `or 'unit' (unit value → u64 raw). Received raw=${JSON.stringify(validated.raw)}, ` +
243
+ `unit=${JSON.stringify(validated.unit)}.`);
244
+ }
245
+ const conversion = await convertTokenValue(validated.token_type, hasRaw ? { raw: validated.raw } : { unit: validated.unit }, validated.network);
246
+ result = { query_type: "token_value_convert", result: conversion };
247
+ break;
248
+ }
155
249
  default:
156
- throw new Error(`Unknown query type. Valid query_types are: "local_mark_list", "account_list", "local_info_list", "token_list", "account_balance", "local_names", "onchain_personal_profile", "onchain_objects", "onchain_received", "onchain_transaction", "onchain_object_history", "onchain_address_activity". For table queries, use the "onchain_table_data" tool.`);
250
+ throw new Error(`Unknown query type. Valid query_types are: "local_mark_list", "account_list", "local_info_list", "token_list", "account_balance", "local_names", "onchain_personal_profile", "onchain_objects", "onchain_received", "onchain_transaction", "onchain_object_history", "onchain_address_activity", "token_value_convert". For table queries, use the "onchain_table_data" tool.`);
157
251
  }
158
252
  return {
159
253
  content: [{ type: "text", text: JSON.stringify({ result }) }],
@@ -202,6 +296,14 @@ export async function handleOnchainTableData(args) {
202
296
  parent: validated.parent, address: validated.address,
203
297
  no_cache: validated.no_cache, network: validated.network,
204
298
  });
299
+ if (queryResult) {
300
+ try {
301
+ const parentToken = await resolveParentObjectTokenType(validated.parent, validated.network);
302
+ await annotateTableItemMonetaryFields(queryResult, parentToken, validated.network);
303
+ }
304
+ catch {
305
+ }
306
+ }
205
307
  result = { query_type: "onchain_table_item_reward_record", result: queryResult };
206
308
  break;
207
309
  }
@@ -218,6 +320,14 @@ export async function handleOnchainTableData(args) {
218
320
  parent: validated.parent, address: validated.address,
219
321
  no_cache: validated.no_cache, network: validated.network,
220
322
  });
323
+ if (queryResult) {
324
+ try {
325
+ const parentToken = await resolveParentObjectTokenType(validated.parent, validated.network);
326
+ await annotateTableItemMonetaryFields(queryResult, parentToken, validated.network);
327
+ }
328
+ catch {
329
+ }
330
+ }
221
331
  result = { query_type: "onchain_table_item_treasury_history", result: queryResult };
222
332
  break;
223
333
  }
@@ -298,6 +408,11 @@ export async function handleOnchainEvents(args) {
298
408
  no_cache: validated.no_cache,
299
409
  network: validated.network,
300
410
  });
411
+ try {
412
+ await annotateEventsMonetaryFields(queryResult?.data, validated.network);
413
+ }
414
+ catch {
415
+ }
301
416
  return {
302
417
  content: [{ type: "text", text: JSON.stringify({ result: queryResult }) }],
303
418
  structuredContent: {