@wowok/agent-mcp 2.6.1 → 2.6.4

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 (246) hide show
  1. package/dist/customer/customer-advice.d.ts +31 -0
  2. package/dist/customer/customer-advice.js +129 -0
  3. package/dist/customer/index.d.ts +2 -0
  4. package/dist/customer/index.js +2 -0
  5. package/dist/customer/info-puzzle.d.ts +9 -2
  6. package/dist/customer/info-puzzle.js +34 -7
  7. package/dist/customer/order-monitor.d.ts +2 -0
  8. package/dist/customer/order-monitor.js +3 -2
  9. package/dist/customer/post-purchase.d.ts +2 -0
  10. package/dist/customer/post-purchase.js +6 -5
  11. package/dist/customer/preorder-compare.d.ts +24 -0
  12. package/dist/customer/preorder-compare.js +34 -0
  13. package/dist/customer/reminder-system.d.ts +2 -0
  14. package/dist/customer/reminder-system.js +2 -1
  15. package/dist/customer/risk-assessment.js +30 -7
  16. package/dist/customer/types.d.ts +7 -0
  17. package/dist/examples/arbitration-dispute-create.json +41 -0
  18. package/dist/examples/arbitration-vote-weighted.json +35 -0
  19. package/dist/examples/arbitration-voting-guard-add.json +38 -0
  20. package/dist/examples/demand-present-service.json +33 -0
  21. package/dist/examples/gen-passport-verify-guard.json +48 -0
  22. package/dist/examples/guard-template-balance-check.json +59 -0
  23. package/dist/examples/guard-template-time-lock.json +60 -0
  24. package/dist/examples/insurance-guard-claim-timelock.json +75 -0
  25. package/dist/examples/insurance-guard-withdraw-allocation.json +96 -0
  26. package/dist/examples/insurance-machine-create-publish.json +75 -0
  27. package/dist/examples/insurance-service-allocators-publish.json +56 -0
  28. package/dist/examples/machine-multisig-threshold.json +86 -0
  29. package/dist/examples/machine-template-7node-rental.json +119 -0
  30. package/dist/examples/payment-scenario-bound.json +45 -0
  31. package/dist/examples/rental-ziroom-machine-create.json +149 -0
  32. package/dist/examples/rental-ziroom-permission-create.json +42 -0
  33. package/dist/examples/rental-ziroom-service-create.json +89 -0
  34. package/dist/examples/retail-adv-guard-customer-win-create.json +80 -0
  35. package/dist/examples/retail-adv-guard-messenger-proof-create.json +65 -0
  36. package/dist/examples/retail-adv-guard-reward-timeout-create.json +92 -0
  37. package/dist/examples/retail-adv-reward-guard-add.json +51 -0
  38. package/dist/examples/retail-myshop-allocation-activate.json +55 -0
  39. package/dist/examples/retail-myshop-arbitration-create.json +40 -0
  40. package/dist/examples/retail-myshop-contact-create.json +43 -0
  41. package/dist/examples/retail-myshop-order-create.json +56 -0
  42. package/dist/examples/retail-myshop-progress-operate.json +38 -0
  43. package/dist/examples/retail-myshop-reward-create.json +35 -0
  44. package/dist/examples/retail-myshop-service-create.json +88 -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 +216 -29
  61. package/dist/extensions/constraint-registry.js +21 -19
  62. package/dist/extensions/metric-registry.js +14 -14
  63. package/dist/extensions/mode-evaluator.js +16 -16
  64. package/dist/extensions/modes.js +141 -49
  65. package/dist/extensions/registry.d.ts +16 -9
  66. package/dist/extensions/registry.js +132 -44
  67. package/dist/extensions/types.d.ts +2 -0
  68. package/dist/index.js +50 -0
  69. package/dist/knowledge/deployment-scanner.js +1 -1
  70. package/dist/knowledge/fund-layer.d.ts +138 -0
  71. package/dist/knowledge/fund-layer.js +969 -0
  72. package/dist/knowledge/guard-render.d.ts +57 -0
  73. package/dist/knowledge/guard-render.js +700 -0
  74. package/dist/knowledge/guard-submission-prompt.d.ts +31 -0
  75. package/dist/knowledge/guard-submission-prompt.js +171 -0
  76. package/dist/knowledge/guard-templates.d.ts +10 -0
  77. package/dist/knowledge/guard-templates.js +50 -0
  78. package/dist/knowledge/index.d.ts +2 -2
  79. package/dist/knowledge/index.js +2 -2
  80. package/dist/knowledge/machine-ledger.js +1 -1
  81. package/dist/knowledge/machine-render.d.ts +41 -0
  82. package/dist/knowledge/machine-render.js +565 -0
  83. package/dist/knowledge/machine-risk.js +4 -1
  84. package/dist/knowledge/machine-templates.js +4 -4
  85. package/dist/knowledge/progress-context.js +1 -1
  86. package/dist/knowledge/progress-ledger.js +3 -3
  87. package/dist/knowledge/progress-templates.js +1 -1
  88. package/dist/knowledge/progress-translation.js +1 -1
  89. package/dist/knowledge/reward-confirm.js +2 -2
  90. package/dist/knowledge/reward-puzzle.js +1 -1
  91. package/dist/knowledge/reward-risk.js +9 -9
  92. package/dist/knowledge/reward-templates.js +2 -2
  93. package/dist/knowledge/safety-rules.d.ts +83 -1
  94. package/dist/knowledge/safety-rules.js +166 -2
  95. package/dist/knowledge/scenario-modes.d.ts +1 -1
  96. package/dist/knowledge/scenario-modes.js +13 -11
  97. package/dist/knowledge/service-confirm.d.ts +1 -1
  98. package/dist/knowledge/service-confirm.js +3 -3
  99. package/dist/knowledge/service-context.js +1 -1
  100. package/dist/knowledge/service-ledger.js +1 -1
  101. package/dist/knowledge/service-risk.d.ts +1 -1
  102. package/dist/knowledge/service-risk.js +3 -3
  103. package/dist/knowledge/service-templates.js +2 -2
  104. package/dist/knowledge/service-translation.d.ts +1 -1
  105. package/dist/knowledge/service-translation.js +7 -7
  106. package/dist/knowledge/template-registry.d.ts +48 -0
  107. package/dist/knowledge/template-registry.js +341 -0
  108. package/dist/knowledge/tool-constraints.js +6 -6
  109. package/dist/knowledge/tools-reference.js +11 -8
  110. package/dist/participation/merchant-interest.d.ts +32 -0
  111. package/dist/participation/merchant-interest.js +100 -0
  112. package/dist/participation/radar-core.d.ts +104 -0
  113. package/dist/participation/radar-core.js +269 -0
  114. package/dist/project/context-assembly.js +8 -0
  115. package/dist/project/deployment-bridge.js +6 -5
  116. package/dist/project/deployment-doc.js +5 -5
  117. package/dist/project/edit-planner.d.ts +123 -0
  118. package/dist/project/edit-planner.js +1342 -0
  119. package/dist/project/evaluation.d.ts +36 -0
  120. package/dist/project/evaluation.js +734 -68
  121. package/dist/project/game-theory.d.ts +43 -0
  122. package/dist/project/game-theory.js +177 -0
  123. package/dist/project/graph-builder.js +7 -1
  124. package/dist/project/handlers.d.ts +137 -2
  125. package/dist/project/handlers.js +423 -51
  126. package/dist/project/intent-analyzer.d.ts +71 -0
  127. package/dist/project/intent-analyzer.js +149 -0
  128. package/dist/project/machine-nodes.d.ts +2 -0
  129. package/dist/project/machine-nodes.js +36 -0
  130. package/dist/project/merchant-guide.d.ts +165 -0
  131. package/dist/project/merchant-guide.js +264 -0
  132. package/dist/project/mode-actions.d.ts +199 -0
  133. package/dist/project/mode-actions.js +309 -0
  134. package/dist/project/participation-radar.d.ts +18 -0
  135. package/dist/project/participation-radar.js +428 -0
  136. package/dist/project/pipeline-actions.d.ts +101 -0
  137. package/dist/project/pipeline-actions.js +109 -0
  138. package/dist/project/semantic-graph.d.ts +95 -0
  139. package/dist/project/semantic-graph.js +245 -0
  140. package/dist/project/stage-gate.js +4 -4
  141. package/dist/schema/call/allocation.d.ts +11 -11
  142. package/dist/schema/call/allocation.js +13 -3
  143. package/dist/schema/call/arbitration.d.ts +21 -21
  144. package/dist/schema/call/arbitration.js +30 -9
  145. package/dist/schema/call/base.d.ts +2 -2
  146. package/dist/schema/call/base.js +1 -1
  147. package/dist/schema/call/bridge.d.ts +127 -127
  148. package/dist/schema/call/bridge.js +12 -12
  149. package/dist/schema/call/contact.d.ts +3 -3
  150. package/dist/schema/call/contact.js +2 -2
  151. package/dist/schema/call/demand.d.ts +3 -3
  152. package/dist/schema/call/demand.js +2 -2
  153. package/dist/schema/call/guard.d.ts +11 -11
  154. package/dist/schema/call/guard.js +2 -2
  155. package/dist/schema/call/machine.d.ts +2072 -679
  156. package/dist/schema/call/machine.js +51 -5
  157. package/dist/schema/call/order.d.ts +7 -7
  158. package/dist/schema/call/order.js +3 -6
  159. package/dist/schema/call/payment.d.ts +3 -3
  160. package/dist/schema/call/permission.d.ts +3 -3
  161. package/dist/schema/call/permission.js +2 -2
  162. package/dist/schema/call/personal.d.ts +337 -3
  163. package/dist/schema/call/personal.js +10 -0
  164. package/dist/schema/call/progress.d.ts +177 -9
  165. package/dist/schema/call/progress.js +7 -3
  166. package/dist/schema/call/proof.d.ts +6 -6
  167. package/dist/schema/call/repository.d.ts +3 -3
  168. package/dist/schema/call/repository.js +2 -2
  169. package/dist/schema/call/reward.d.ts +57 -57
  170. package/dist/schema/call/reward.js +3 -3
  171. package/dist/schema/call/semantic.js +48 -2
  172. package/dist/schema/call/service.d.ts +285 -113
  173. package/dist/schema/call/service.js +92 -28
  174. package/dist/schema/call/treasury.d.ts +57 -57
  175. package/dist/schema/call/treasury.js +3 -3
  176. package/dist/schema/common/index.d.ts +2 -0
  177. package/dist/schema/common/index.js +46 -10
  178. package/dist/schema/local/index.js +5 -1
  179. package/dist/schema/messenger/index.js +4 -1
  180. package/dist/schema/operations.d.ts +1318 -317
  181. package/dist/schema/operations.js +76 -7
  182. package/dist/schema/project/index.d.ts +5662 -164
  183. package/dist/schema/project/index.js +1136 -5
  184. package/dist/schema/query/index.d.ts +580 -19
  185. package/dist/schema/query/index.js +88 -36
  186. package/dist/schema/schema-query/index.d.ts +59 -3
  187. package/dist/schema/schema-query/index.js +45 -6
  188. package/dist/schema/trust/index.d.ts +1012 -6
  189. package/dist/schema/trust/index.js +212 -11
  190. package/dist/schema/utils/node-parser.js +13 -0
  191. package/dist/schema/utils/object-type-utils.d.ts +12 -0
  192. package/dist/schema/utils/object-type-utils.js +35 -0
  193. package/dist/schema/utils/permission-machine-check.d.ts +49 -0
  194. package/dist/schema/utils/permission-machine-check.js +121 -0
  195. package/dist/schema/utils/skills-recommendation.d.ts +2 -0
  196. package/dist/schema/utils/skills-recommendation.js +77 -0
  197. package/dist/schema-query/index.d.ts +17 -1
  198. package/dist/schema-query/index.js +359 -3
  199. package/dist/schemas/account_operation.schema.json +1 -1
  200. package/dist/schemas/bridge_operation.schema.json +14 -7
  201. package/dist/schemas/guard2file.schema.json +2 -0
  202. package/dist/schemas/index.json +1 -1
  203. package/dist/schemas/machineNode2file.schema.json +2 -0
  204. package/dist/schemas/messenger_operation.schema.json +1 -1
  205. package/dist/schemas/onchain_events.output.json +1 -1
  206. package/dist/schemas/onchain_operations.output.json +2820 -0
  207. package/dist/schemas/onchain_operations.schema.json +255 -65
  208. package/dist/schemas/onchain_operations_allocation.schema.json +7 -6
  209. package/dist/schemas/onchain_operations_arbitration.schema.json +14 -10
  210. package/dist/schemas/onchain_operations_contact.schema.json +4 -3
  211. package/dist/schemas/onchain_operations_demand.schema.json +4 -3
  212. package/dist/schemas/onchain_operations_gen_passport.schema.json +4 -2
  213. package/dist/schemas/onchain_operations_gen_proof.schema.json +2 -0
  214. package/dist/schemas/onchain_operations_guard.schema.json +579 -1
  215. package/dist/schemas/onchain_operations_machine.schema.json +5 -4
  216. package/dist/schemas/onchain_operations_order.schema.json +7 -6
  217. package/dist/schemas/onchain_operations_payment.schema.json +2 -1
  218. package/dist/schemas/onchain_operations_permission.schema.json +3 -2
  219. package/dist/schemas/onchain_operations_personal.schema.json +37 -0
  220. package/dist/schemas/onchain_operations_progress.schema.json +91 -4
  221. package/dist/schemas/onchain_operations_proof.schema.json +2 -1
  222. package/dist/schemas/onchain_operations_repository.schema.json +4 -3
  223. package/dist/schemas/onchain_operations_reward.schema.json +7 -6
  224. package/dist/schemas/onchain_operations_service.schema.json +80 -19
  225. package/dist/schemas/onchain_operations_treasury.schema.json +5 -4
  226. package/dist/schemas/onchain_table_data.output.json +1 -1
  227. package/dist/schemas/onchain_table_data.schema.json +10 -9
  228. package/dist/schemas/project_operation.output.json +3318 -57
  229. package/dist/schemas/project_operation.schema.json +728 -4
  230. package/dist/schemas/query_toolkit.output.json +16 -16
  231. package/dist/schemas/query_toolkit.schema.json +40 -3
  232. package/dist/schemas/schema_query.output.json +65 -2
  233. package/dist/schemas/schema_query.schema.json +31 -5
  234. package/dist/schemas/trust_score.output.json +392 -1
  235. package/dist/schemas/trust_score.schema.json +275 -1
  236. package/dist/schemas/wowok_buildin_info.output.json +81 -8
  237. package/dist/schemas/wowok_buildin_info.schema.json +46 -2
  238. package/dist/tools/handlers/onchain.js +636 -6
  239. package/dist/tools/handlers/project.js +71 -2
  240. package/dist/tools/handlers/query.js +117 -2
  241. package/dist/tools/handlers/schema-query.js +65 -1
  242. package/dist/tools/handlers/trust.js +192 -6
  243. package/dist/tools/index.d.ts +8 -0
  244. package/dist/tools/index.js +229 -15
  245. package/dist/tools/wrap.js +194 -15
  246. package/package.json +2 -2
@@ -2,6 +2,7 @@ import { z } from "zod";
2
2
  const IndustryEnum = z.enum([
3
3
  "general",
4
4
  "retail",
5
+ "retail_d2c",
5
6
  "service",
6
7
  "rental",
7
8
  "freelance",
@@ -70,11 +71,31 @@ export const ProjectOperationInputSchema = z
70
71
  "delete_project",
71
72
  "assemble_context",
72
73
  "get_machine_graph",
74
+ "get_guard_graph",
73
75
  "generate_deployment_doc",
74
76
  "pre_evaluate_check",
75
77
  "verify_deployment",
76
78
  "clone_project_to_network",
77
79
  "migrate_network",
80
+ "migrate_to_mainnet",
81
+ "plan_object_edit",
82
+ "apply_object_edit",
83
+ "patch_machine_nodes",
84
+ "patch_guard_tree",
85
+ "recommend_industry",
86
+ "list_modes",
87
+ "derive_user_mode",
88
+ "evolve_user_mode",
89
+ "register_user_mode",
90
+ "unregister_user_mode",
91
+ "register_custom_metric",
92
+ "register_custom_constraint",
93
+ "list_metrics_constraints",
94
+ "analyze_intent",
95
+ "aggregate_risks",
96
+ "trace_substeps",
97
+ "merchant_guide",
98
+ "participation_radar",
78
99
  ])
79
100
  .describe("Action to perform. Two categories:\n" +
80
101
  "1. Project Entity + Evaluation (15, GLM6): list_projects, create_project, create_project_from_onchain, update_project, get_project_detail, add_object, remove_object, create_version, build_graph, get_graph, evaluate_project, save_evaluation, compare_projects, refresh_objects, get_object_diff. Projects are first-class entities with SQLite persistence, rigid project-object relationships, three-pathway graph construction, and a dual rule-based + LLM-assisted evaluation engine.\n" +
@@ -83,7 +104,10 @@ export const ProjectOperationInputSchema = z
83
104
  project: z
84
105
  .string()
85
106
  .optional()
86
- .describe("Project prefix (human-readable unique identifier). Used by create_version, build_graph, evaluate_project, etc. Takes precedence resolution: project_id > project (prefix)."),
107
+ .describe("Project prefix (human-readable unique identifier). " +
108
+ "For create_project: OPTIONAL — if omitted, auto-derived from project_name (e.g. 'Twitch Service' → 'twitch_service'). " +
109
+ "For other actions (build_graph, evaluate_project, etc.): used to identify the project. " +
110
+ "Takes precedence resolution: project_id > project (prefix)."),
87
111
  version: z
88
112
  .string()
89
113
  .regex(/^v\d+$/)
@@ -128,7 +152,8 @@ export const ProjectOperationInputSchema = z
128
152
  "(and not 'general'), the system auto-applies an industry blueprint " +
129
153
  "with ~10 draft objects (Permission, Service, Machine, Guard, Treasury, " +
130
154
  "Allocation, etc.) + graph edges, ready for deployment. " +
131
- "Supported industries: 'general' (no template), 'retail', 'service', " +
155
+ "Supported industries: 'general' (no template), 'retail', 'retail_d2c' " +
156
+ "(Direct-to-Consumer, e.g., Shopify — Allocation escrow + 2 Guards), 'service', " +
132
157
  "'rental', 'freelance', 'education', 'travel', 'subscription', 'custom'. " +
133
158
  "Each industry preset embeds risk constraints (e.g., 'freelance' does " +
134
159
  "NOT require compensation_fund, while 'rental'/'travel' do). " +
@@ -269,7 +294,11 @@ export const ProjectOperationInputSchema = z
269
294
  refresh_before_eval: z
270
295
  .boolean()
271
296
  .optional()
272
- .describe("When true, evaluate_project refreshes object cache from chain before evaluating. Default false."),
297
+ .describe("When true (DEFAULT), evaluate_project refreshes object cache from chain before evaluating. " +
298
+ "Set to false ONLY for read-only checks where staleness is acceptable (e.g., quick comparisons). " +
299
+ "BUG-P0-2 fix: previously defaulted to false, causing stale Machine node_count and other " +
300
+ "dynamic-field-derived fields to produce false findings (e.g., 'Machine has no nodes'). " +
301
+ "Now defaults to true — set refresh_before_eval=false explicitly to skip refresh."),
273
302
  eval_score: z
274
303
  .number()
275
304
  .min(0)
@@ -320,6 +349,351 @@ export const ProjectOperationInputSchema = z
320
349
  "'detailed': adds sale list, arbitration list, reward list. " +
321
350
  "'full': complete fields including stock, price, wip_hash, all config. " +
322
351
  "Use 'summary' for quick review; request 'detailed' or 'full' only when deeper inspection is needed."),
352
+ object_kind: z
353
+ .enum(["machine", "guard"])
354
+ .optional()
355
+ .describe("Object kind for plan_object_edit. 'machine' = Machine workflow directed graph (cycles allowed), 'guard' = Guard computation tree. " +
356
+ "Required when action='plan_object_edit'. Inferred from action for patch_machine_nodes (always 'machine') " +
357
+ "and patch_guard_tree (always 'guard')."),
358
+ edit_format: z
359
+ .enum(["tree_outline", "json"])
360
+ .optional()
361
+ .describe("Format of the edited content for plan_object_edit. " +
362
+ "'tree_outline' (default): the indented Markdown outline produced by get_machine_graph / get_guard_graph (human-editable). " +
363
+ "'json': raw JSON (machine-readable, for programmatic edits). " +
364
+ "Both formats are bidirectional with the parse functions in knowledge/machine-render.ts / guard-render.ts."),
365
+ edited_content: z
366
+ .string()
367
+ .optional()
368
+ .describe("Edited content for plan_object_edit. Must be in the format specified by edit_format. " +
369
+ "For 'tree_outline': the full tree_outline string from get_machine_graph/get_guard_graph with user edits. " +
370
+ "For 'json': a JSON string matching the Machine/Guard schema. " +
371
+ "The content is parsed + validated + diffed against the current on-chain state."),
372
+ plan_id: z
373
+ .string()
374
+ .optional()
375
+ .describe("Plan ID returned by plan_object_edit. Required for apply_object_edit. " +
376
+ "The plan is short-lived (10-minute TTL) and stored in-memory."),
377
+ expected_hash: z
378
+ .string()
379
+ .optional()
380
+ .describe("Expected hash returned by plan_object_edit. Required for apply_object_edit. " +
381
+ "Used for optimistic concurrency control: if the on-chain state changed between plan and apply, " +
382
+ "the hash will mismatch and apply will refuse to proceed (stale edit protection)."),
383
+ patch_operations: z
384
+ .array(z.string())
385
+ .optional()
386
+ .describe("Patch operations for patch_machine_nodes / patch_guard_tree. Each string is a single patch operation.\n" +
387
+ "Machine operations (13 total):\n" +
388
+ " 'add node <name>' | 'remove node <name>' | 'set description <node_name> <text...>'\n" +
389
+ " 'add edge <from> <to>' | 'remove edge <from> <to>' | 'set threshold <edge_from> <edge_to> <value>'\n" +
390
+ " 'add forward <edge_from> <edge_to> <forward_name>' | 'remove forward <edge_from> <edge_to> <forward_name>'\n" +
391
+ " 'set guard <edge_from> <edge_to> <forward_name> <guard_addr_or_name|none>'\n" +
392
+ " 'set permission <edge_from> <edge_to> <forward_name> <perm_index>'\n" +
393
+ " 'set operator <edge_from> <edge_to> <forward_name> <named_operator|none>'\n" +
394
+ " 'set weight <edge_from> <edge_to> <forward_name> <weight>'\n" +
395
+ " 'set retained_submission <edge_from> <edge_to> <forward_name> <comma_separated_indices|none>'\n" +
396
+ "Guard operations (8 total — see patch_guard_tree):\n" +
397
+ " 'add table <identifier> <name|none> <value_type> <b_submission> [json_value]'\n" +
398
+ " 'remove table <identifier>' | 'set table_value <identifier> [json_value|none]'\n" +
399
+ " 'set table_name <identifier> <name|none>' | 'set table_submission <identifier> <true|false>'\n" +
400
+ " 'set root <json_node>' | 'set rely <comma_separated_guard_addresses|none>'\n" +
401
+ "Operations are applied in order. Both patches are validated (validateMachine/validateGuard) before execution."),
402
+ intent: z
403
+ .string()
404
+ .max(2000)
405
+ .optional()
406
+ .describe("Business intent text for recommend_industry (e.g. 'I rent cameras to photographers " +
407
+ "with deposit and damage inspection'). Falls back to project_description / project_name when omitted."),
408
+ mode_source: z
409
+ .string()
410
+ .optional()
411
+ .describe("Source builtin mode name for derive_user_mode (e.g. 'freelance'). Call list_modes to see available modes."),
412
+ mode_name: z
413
+ .string()
414
+ .max(100)
415
+ .optional()
416
+ .describe("Mode name for derive_user_mode (new mode name), evolve_user_mode / unregister_user_mode (existing custom mode), register_user_mode (new mode name). " +
417
+ "Must NOT conflict with builtin mode names."),
418
+ mode_display_name: z
419
+ .string()
420
+ .max(200)
421
+ .optional()
422
+ .describe("Display name for derive_user_mode / register_user_mode. Defaults to mode_name."),
423
+ mode_changes: z
424
+ .record(z.unknown())
425
+ .optional()
426
+ .describe("Mode field overrides for derive_user_mode / evolve_user_mode / register_user_mode. " +
427
+ "For register_user_mode, REQUIRED fields: machine_shape (non-empty array of {name, role}) and key_risk (string). " +
428
+ "Common overrides: machine_shape (array of {name:string, role:string}), config_overrides (per-object config), " +
429
+ "allocator, guards, build_notes, risk_appetite. " +
430
+ "R-M1-11 ENFORCED: machine_shape node names must NOT contain dispute/refund/arb terms — " +
431
+ "disputes flow through Service.arbitrations independently of the Machine."),
432
+ mode_change_description: z
433
+ .string()
434
+ .max(500)
435
+ .optional()
436
+ .describe("Change description for evolve_user_mode (recorded in evolution history)."),
437
+ mode_bump_version: z
438
+ .boolean()
439
+ .optional()
440
+ .describe("Whether evolve_user_mode bumps the patch version (default true: v1.0 → v1.1)."),
441
+ metric_id: z.string().max(100).optional().describe("Unique metric ID for register_custom_metric (e.g. 'seasonality_risk')."),
442
+ metric_display_name: z.string().max(200).optional().describe("Display name for register_custom_metric."),
443
+ metric_description: z.string().max(1000).optional().describe("Description for register_custom_metric."),
444
+ metric_type: z
445
+ .enum(["risk", "benefit"])
446
+ .optional()
447
+ .describe("Metric type for register_custom_metric: 'risk' (negative) or 'benefit' (positive)."),
448
+ metric_scale: z
449
+ .enum(["level", "numeric", "percentage"])
450
+ .optional()
451
+ .describe("Metric scale for register_custom_metric: 'level' (high/medium/low), 'numeric', or 'percentage'."),
452
+ metric_weight: z
453
+ .number()
454
+ .min(0)
455
+ .max(10)
456
+ .optional()
457
+ .describe("Metric weight for register_custom_metric (default 1.0)."),
458
+ constraint_id: z.string().max(100).optional().describe("Unique constraint ID for register_custom_constraint."),
459
+ constraint_display_name: z.string().max(200).optional().describe("Display name for register_custom_constraint."),
460
+ constraint_description: z.string().max(1000).optional().describe("Description for register_custom_constraint."),
461
+ constraint_rule: z
462
+ .discriminatedUnion("type", [
463
+ z.object({ type: z.literal("capability_required"), capability_id: z.string() }).strict(),
464
+ z.object({ type: z.literal("capability_forbidden"), capability_id: z.string() }).strict(),
465
+ z.object({ type: z.literal("numeric_limit"), field: z.string(), max: z.number().optional(), min: z.number().optional() }).strict(),
466
+ z.object({ type: z.literal("condition_required"), condition: z.string(), ai_evaluated: z.literal(true) }).strict(),
467
+ ])
468
+ .optional()
469
+ .describe("Constraint rule for register_custom_constraint. 4 types: " +
470
+ "capability_required/capability_forbidden (capability_id), numeric_limit (field + max/min), " +
471
+ "condition_required (natural-language condition, AI-evaluated)."),
472
+ constraint_severity: z
473
+ .enum(["hard", "soft"])
474
+ .optional()
475
+ .describe("Constraint severity for register_custom_constraint: 'hard' blocks applyTemplate on violation; 'soft' only warns (default 'soft')."),
476
+ constraint_on_violation: z
477
+ .enum(["block", "warn", "log"])
478
+ .optional()
479
+ .describe("Violation action for register_custom_constraint (default 'warn')."),
480
+ metric_type_filter: z
481
+ .enum(["risk", "benefit"])
482
+ .optional()
483
+ .describe("Filter list_metrics_constraints by metric type."),
484
+ scope_filter: z
485
+ .enum(["builtin", "custom"])
486
+ .optional()
487
+ .describe("Filter list_metrics_constraints by scope (builtin or custom)."),
488
+ target_objects: z
489
+ .array(z.string())
490
+ .optional()
491
+ .describe("Optional explicit target objects for analyze_intent (entry_ids or object_type names). " +
492
+ "When provided, puzzle snapshots are restricted to these objects."),
493
+ puzzles: z
494
+ .record(z
495
+ .object({
496
+ puzzle: z.unknown().describe("Puzzle snapshot (opaque — pass through from analyze_intent output unchanged)."),
497
+ completeness: z.unknown().describe("Completeness snapshot (opaque — pass through unchanged)."),
498
+ missing_dimensions: z.array(z.string()).describe("Dimensions still missing for this object."),
499
+ })
500
+ .strict())
501
+ .optional()
502
+ .describe("Per-object puzzle snapshots for aggregate_risks, keyed by object_type. " +
503
+ "Pass the 'puzzles' field from a prior analyze_intent result UNCHANGED. " +
504
+ "When omitted but 'intent' is present, the handler runs analyze_intent first (C1→C2 in one call)."),
505
+ severity_threshold: z
506
+ .enum(["CRITICAL", "HIGH", "MEDIUM", "LOW", "INFO"])
507
+ .optional()
508
+ .describe("Severity threshold for aggregate_risks (default 'HIGH'). Risks at or above this level block deployment (status RISK_BLOCKED)."),
509
+ user_confirmed_high_risks: z
510
+ .array(z.string())
511
+ .optional()
512
+ .describe("IDs of HIGH risks the user has already confirmed in a prior round (aggregate_risks). " +
513
+ "Confirmed HIGH risks no longer trigger RISK_PENDING_CONFIRM."),
514
+ planned_objects: z
515
+ .array(z
516
+ .object({
517
+ object_type: z.string().describe("Wowok object type (e.g. 'service', 'guard', 'machine')."),
518
+ is_new: z.boolean().describe("true when creating a NEW object; false when reusing an existing one."),
519
+ name: z.string().optional().describe("Planned object name (for readable messages)."),
520
+ })
521
+ .strict())
522
+ .optional()
523
+ .describe("Planned objects for aggregate_risks OBJECT_REUSE check (safety-rules). " +
524
+ "Flags NEW objects whose type carries an always/strongly-recommended reuse rule."),
525
+ planned_operations: z
526
+ .array(z
527
+ .object({
528
+ object_type: z.string().describe("Wowok object type (e.g. 'service', 'arbitration')."),
529
+ trigger: z.enum(["create", "publish"]).describe("Lifecycle trigger that locks fields."),
530
+ name: z.string().optional().describe("Object name (for readable messages)."),
531
+ })
532
+ .strict())
533
+ .optional()
534
+ .describe("Planned create/publish operations for aggregate_risks IMMUTABILITY check (safety-rules). " +
535
+ "Warns which fields become permanently locked after each operation."),
536
+ substeps: z
537
+ .array(z
538
+ .object({
539
+ step_id: z.string().describe("Substep id, format 'T<step>.<substep>' e.g. 'T1.1'."),
540
+ parent_step: z.string().describe("Parent step id, format 'T<step>' e.g. 'T1'."),
541
+ object_type: ProjectObjectTypeEnum.describe("Wowok object type this substep operates on."),
542
+ entry_id: z.string().describe("Puzzle entry_id this substep corresponds to."),
543
+ operation_type: z.string().describe("operation_type for onchain_operations."),
544
+ network: z.enum(["testnet", "mainnet"]).describe("Target network."),
545
+ input: z
546
+ .object({
547
+ data: z.record(z.unknown()).describe("Input data payload."),
548
+ input_refs: z.array(z.string()).describe("Upstream substep_ids this substep consumes."),
549
+ })
550
+ .strict(),
551
+ output: z
552
+ .object({
553
+ object_id: z.string().optional(),
554
+ tx_digest: z.string().optional(),
555
+ })
556
+ .catchall(z.unknown())
557
+ .optional()
558
+ .describe("Output data (filled after execution)."),
559
+ timestamp: z.number().describe("Execution timestamp (ms)."),
560
+ status: z.enum(["PENDING", "SUCCESS", "FAILED", "SKIPPED"]).describe("Execution status."),
561
+ failure_reason: z.string().optional().describe("Failure reason (when status='FAILED')."),
562
+ dependencies: z
563
+ .object({
564
+ input_refs: z.array(z.string()),
565
+ output_refs: z
566
+ .array(z
567
+ .object({
568
+ substep_id: z.string().describe("Downstream substep that consumes this output."),
569
+ field_path: z.string().describe("Field path produced by this substep (e.g. 'permission_address')."),
570
+ })
571
+ .strict()),
572
+ })
573
+ .strict()
574
+ .describe("Dependencies (input_refs + output_refs)."),
575
+ retry_info: z
576
+ .object({
577
+ original_step_id: z.string(),
578
+ retry_count: z.number(),
579
+ retry_reason: z.string(),
580
+ })
581
+ .strict()
582
+ .optional()
583
+ .describe("Retry info (when this substep is a retry of an earlier one)."),
584
+ })
585
+ .strict())
586
+ .optional()
587
+ .describe("Substep execution records for trace_substeps (63-spec §2.1). " +
588
+ "Required when action='trace_substeps'. Construct from your deployment execution trace."),
589
+ substep_edges: z
590
+ .array(z
591
+ .object({
592
+ source: z.string().describe("Source substep id."),
593
+ target: z.string().describe("Target substep id (depends on source)."),
594
+ field_path: z.string().describe("Field path flowing along this edge."),
595
+ })
596
+ .strict())
597
+ .optional()
598
+ .describe("Explicit DAG edges for trace_substeps. When omitted, edges are derived from each substep's input_refs."),
599
+ guide_state: z
600
+ .object({
601
+ intent_text: z.string().describe("Step 1: raw merchant business description."),
602
+ confirmed_industry: z.string().optional().describe("Step 2: merchant-confirmed industry id."),
603
+ currency: z.string().optional().describe("Step 5: payment currency (default WOW)."),
604
+ deliverables: z.array(z.unknown()).optional().describe("Step 4: merchant-defined deliverables (opaque passthrough)."),
605
+ payment_override: z.record(z.unknown()).optional().describe("Step 5: payment structure overrides (opaque passthrough)."),
606
+ trust_override: z.record(z.unknown()).optional().describe("Step 6: trust mechanism overrides (opaque passthrough)."),
607
+ adopted_module_ids: z.array(z.string()).optional().describe("Step 6: merchant-confirmed business module ids."),
608
+ })
609
+ .strict()
610
+ .optional()
611
+ .describe("Wizard state from a prior merchant_guide result. Pass back UNCHANGED on " +
612
+ "every subsequent call (same pattern as C1→C2 puzzles). The handler re-runs " +
613
+ "the pipeline deterministically and advances to the furthest reachable step."),
614
+ guide_confirm: z
615
+ .object({
616
+ industry: z.string().optional().describe("Step 2 confirmation: industry id (e.g. 'freelance')."),
617
+ currency: z.string().optional().describe("Step 5 confirmation: payment currency."),
618
+ deliverables: z.array(z.unknown()).optional().describe("Step 4 confirmation: deliverable definitions."),
619
+ payment: z.record(z.unknown()).optional().describe("Step 5 confirmation: { model, triggers, allocation } overrides."),
620
+ trust: z.record(z.unknown()).optional().describe("Step 6 confirmation: { refundPolicy, arbitration, escrow } overrides."),
621
+ adopted_module_ids: z.array(z.string()).optional().describe("Step 6 confirmation: business module ids to adopt (overrides recommendation)."),
622
+ })
623
+ .strict()
624
+ .optional()
625
+ .describe("Merchant decisions for the current wizard step. Merged over guide_state. " +
626
+ "Typical flow: call 1 with intent only → receive step-2 industry options → " +
627
+ "call 2 with guide_state + guide_confirm={industry} → receive full blueprint " +
628
+ "plan (steps 7-10)."),
629
+ radar_account: z
630
+ .string()
631
+ .optional()
632
+ .describe("Account to analyze — address (0x...) or LocalMark name (resolved to an address). " +
633
+ "Required when action='participation_radar'. The perspective (customer/operator/observer) " +
634
+ "is DERIVED from on-chain data (Order.builder + PermissionPerm grants) — never asserted by this field."),
635
+ radar_targets: z
636
+ .array(z
637
+ .object({
638
+ progress: z
639
+ .string()
640
+ .describe("Progress object address (0x...) or LocalMark name. The Progress carries the current node + bound Machine."),
641
+ order: z
642
+ .string()
643
+ .optional()
644
+ .describe("Order object address or LocalMark name (optional but recommended — enables order-holder detection, " +
645
+ "service-level compensation/reward claims, and dispute context)."),
646
+ })
647
+ .strict())
648
+ .min(1)
649
+ .max(20)
650
+ .optional()
651
+ .describe("In-flight orders to analyze (1-20). Required when action='participation_radar'. " +
652
+ "Each target is analyzed independently; results are aggregated into one account dashboard."),
653
+ radar_include_alerts: z
654
+ .boolean()
655
+ .optional()
656
+ .describe("Attach order-monitor alerts (progress stall / compensation fund / review & arbitration windows) " +
657
+ "to each per-order result. Default true."),
658
+ radar_monitor_thresholds: z
659
+ .object({
660
+ progress_stall_hours: z
661
+ .number()
662
+ .positive()
663
+ .optional()
664
+ .describe("Progress stall alert threshold in HOURS. Default 0 = auto (expected_node_duration × 2)."),
665
+ compensation_drop_ratio: z
666
+ .number()
667
+ .min(0)
668
+ .max(1)
669
+ .optional()
670
+ .describe("Compensation fund drop alert ratio (0-1). Default 0.3 = alert on ≥30% drop."),
671
+ compensation_coverage_min: z
672
+ .number()
673
+ .min(0)
674
+ .max(1)
675
+ .optional()
676
+ .describe("Minimum compensation coverage ratio vs order amount (0-1). Default 1.0 = must fully cover."),
677
+ messenger_timeout_hours: z
678
+ .number()
679
+ .positive()
680
+ .optional()
681
+ .describe("Messenger no-reply timeout in HOURS. Default 24."),
682
+ review_window_closing_days: z
683
+ .number()
684
+ .positive()
685
+ .optional()
686
+ .describe("Review window near-closing alert threshold in DAYS. Default 3."),
687
+ arb_window_closing_days: z
688
+ .number()
689
+ .positive()
690
+ .optional()
691
+ .describe("Arbitration window near-closing alert threshold in DAYS. Default 3."),
692
+ })
693
+ .strict()
694
+ .optional()
695
+ .describe("Optional per-call overrides for order-monitor alert thresholds (only used when radar_include_alerts is on). " +
696
+ "All fields optional; omitted fields keep defaults. Units: hours/days as marked per field."),
323
697
  })
324
698
  .strict();
325
699
  const AssembleContextResultSchema = z
@@ -415,6 +789,17 @@ const RecommendedCreationOrderItemSchema = z.object({
415
789
  reason: z.string().describe("Why this step is here, including dependencies and irreversibility notes."),
416
790
  required: z.boolean().describe("Whether this step is mandatory for a working deployment."),
417
791
  }).strict();
792
+ const RecommendedIndustryItemSchema = z.object({
793
+ industry: z.string().describe("Recommended builtin industry mode name."),
794
+ similarity: z.number().describe("Trait similarity 0-1 (10-dim industry trait match)."),
795
+ matched_traits: z.array(z.string()).describe("Trait dimensions that matched."),
796
+ reference_examples: z.array(z.object({
797
+ file: z.string().describe("Example file name (fetch via schema_query search_examples)."),
798
+ title: z.string(),
799
+ operation_type: z.string(),
800
+ verified: z.boolean(),
801
+ }).strict()).describe("Verified reference examples for this industry (top 3)."),
802
+ }).strict();
418
803
  const CreateProjectResultSchema = z
419
804
  .object({
420
805
  action: z.literal("create_project"),
@@ -429,10 +814,24 @@ const CreateProjectResultSchema = z
429
814
  steps_count: z.number().describe("Number of deployment steps in the template."),
430
815
  scenarios_count: z.number().describe("Number of scenarios in the template."),
431
816
  key_risk: z.string().nullable().optional().describe("Industry-specific key risk note (or null)."),
432
- }).strict().optional().describe("Blueprint summary — present when industry template applied successfully. Objects have status='draft' and address='draft:<name>'."),
817
+ intent_inference: z.object({
818
+ traits: z.record(z.string(), z.unknown()).describe("10-dimension inferred industry traits (unmatched traits use neutral defaults)."),
819
+ confidence: z.number().describe("Inference confidence 0-1 (matched trait count / 10)."),
820
+ matched_keywords: z.array(z.string()).describe("Keywords that triggered trait inference."),
821
+ top_matches: z.array(z.object({
822
+ industry: z.string(),
823
+ similarity: z.number().describe("Trait similarity 0-1."),
824
+ }).strict()).describe("Top-3 similar industries by trait similarity."),
825
+ }).strict().optional().describe("Intent inference summary (E.3) — present when industry template applied."),
826
+ industry_mismatch_hint: z.string().optional().describe("Advisory hint — present when intent inference suggests a different industry fits the description better (non-blocking)."),
827
+ }).strict().optional().describe("Blueprint summary — present when industry template applied successfully. Objects have status='draft' and address='draft:<name>'. Full steps/scenarios persisted as project document doc_type='blueprint'."),
433
828
  blueprint_warning: z.string().optional().describe("Warning message — present when industry template application failed. Project is created without blueprint; use add_object to manually add objects."),
434
829
  blueprint_skipped: z.boolean().optional().describe("True when skip_templates=true was passed — no industry blueprint objects were created."),
435
830
  hint: z.string().optional().describe("User-facing hint — guides to next action (e.g. add_object, generate_deployment_doc)."),
831
+ recommended_industries: z.array(RecommendedIndustryItemSchema).optional().describe("Top-3 recommended industry modes inferred from the project description (E.7). " +
832
+ "Present only when no project_industry was given. Each item includes reference examples " +
833
+ "('standing on giants' shoulders'). To apply: call update_project is NOT enough — recreate " +
834
+ "via create_project with project_industry set to get the blueprint."),
436
835
  })
437
836
  .strict();
438
837
  const CreateProjectFromOnchainResultSchema = z
@@ -695,7 +1094,7 @@ const GenerateDeploymentDocResultSchema = z
695
1094
  status: z.enum(["PASS", "WARN", "FAIL"]).describe("Check result status."),
696
1095
  message: z.string().describe("Human-readable check result message."),
697
1096
  }).strict()).describe("Per-dimension check results."),
698
- }).strict().describe("Stage gate validation (GLM6 5-stage lifecycle 衔接). Validates Stage 3 risk score threshold (>=80 PASS, >=50 WARN, <50 FAIL) and Stage 4 deployment doc generation prerequisite."),
1097
+ }).strict().describe("Stage gate validation (GLM6 5-stage lifecycle handoff). Validates Stage 3 risk score threshold (>=80 PASS, >=50 WARN, <50 FAIL) and Stage 4 deployment doc generation prerequisite."),
699
1098
  deployment_scan: z.object({
700
1099
  overall_readiness: z.enum(["ready", "blocked", "warnings"]).describe("'ready' = all 20 checks pass; 'blocked' = any critical fail; 'warnings' = only warning fails."),
701
1100
  critical_count: z.number().describe("Number of critical findings (blocks deployment)."),
@@ -817,6 +1216,158 @@ const GetMachineGraphResultSchema = z
817
1216
  edges: z.array(MachineGraphEdgeSchema).describe("Directed edges (pairs) connecting nodes. Each edge has a threshold and forwards."),
818
1217
  published: z.boolean().nullable().describe("Whether the Machine is published (locked for production). null = unknown."),
819
1218
  paused: z.boolean().nullable().describe("Whether the Machine is paused (not generating new Progress). null = unknown."),
1219
+ mermaid: z.string().describe("Mermaid stateDiagram-v2 string visualizing the directed graph. Entry nodes start from [*]. Edge labels include forward name + threshold + guard info. Cycles (revision loops) are rendered as normal edges. Includes a color legend comment block + BehaviorTree.CPP-style color annotations (entry=green, terminal=red, revision=amber, normal=blue). Renderable in markdown viewers."),
1220
+ tree_outline: z.string().describe("Indented Markdown outline of the directed graph (human-editable format). Lists edges as outline entries with forwards nested under each edge. Includes a Backrefs section consolidating incoming edges per node (editing aid — answers 'who transitions INTO node X?'). Bidirectional with parseMachineTreeIndented(). Includes JSON code block for round-trip safety. Use this for the download -> edit -> republish workflow."),
1221
+ ascii_art: z.string().describe("ASCII art directed graph visualization using arrow notation (A -forward-> B). Cycle (revision loop) and terminal annotations included. Terminal-friendly, avoids JSON escaping issues that affect multi-line Mermaid strings. Use when rendering in plain-text contexts."),
1222
+ markmap: z.string().describe("Markmap-compatible Markdown string (heading levels represent hierarchy). Edge-centric layout with forwards nested under edges. Renderable by VS Code Markmap extension or markmap.js. Provides an interactive mind-map view of the workflow."),
1223
+ })
1224
+ .strict();
1225
+ const GuardGraphNodeSchema = z.lazy(() => z.object({
1226
+ type: z.string().describe("Guard node type (logic_and, query, identifier, context, calc_*, convert_*, vec_*, etc.)."),
1227
+ nodes: z.array(GuardGraphNodeSchema).optional().describe("Child nodes (for logic_and/or, calc_*, vec_contains_*, etc.)."),
1228
+ node: GuardGraphNodeSchema.optional().describe("Single child (for logic_not, convert_*, value_type)."),
1229
+ nodeLeft: GuardGraphNodeSchema.optional().describe("Left child (for vec_indexof_*)."),
1230
+ nodeRight: GuardGraphNodeSchema.optional().describe("Right child (for vec_indexof_*)."),
1231
+ query: z.union([z.number(), z.string()]).optional().describe("Query instruction ID or name (for query nodes)."),
1232
+ object: z.object({
1233
+ identifier: z.number().optional(),
1234
+ convert_witness: z.number().optional(),
1235
+ }).optional().describe("Query target object reference."),
1236
+ parameters: z.array(GuardGraphNodeSchema).optional().describe("Query parameters."),
1237
+ identifier: z.number().optional().describe("Table entry index (for identifier nodes)."),
1238
+ context: z.string().optional().describe("Context type: Signer, Clock, or Guard."),
1239
+ }).strict());
1240
+ const GuardTableEntrySchema = z.object({
1241
+ identifier: z.number().describe("Table entry index (0-255)."),
1242
+ b_submission: z.boolean().describe("Whether this entry is submitted at runtime."),
1243
+ value_type: z.union([z.number(), z.string()]).describe("Value type (numeric code or name)."),
1244
+ value: z.unknown().optional().describe("Constant value (if b_submission=false)."),
1245
+ name: z.string().optional().describe("Human-readable name/description."),
1246
+ }).strict();
1247
+ const GetGuardGraphResultSchema = z
1248
+ .object({
1249
+ action: z.literal("get_guard_graph"),
1250
+ guardAddress: z.string().describe("The Guard object address."),
1251
+ guardName: z.string().nullable().describe("The Guard's local name (from LocalMark) if available."),
1252
+ root: GuardGraphNodeSchema.describe("Root computation node (returns Bool). The tree is recursive — each node may have children."),
1253
+ table: z.array(GuardTableEntrySchema).describe("Guard data table entries (constants + submission slots)."),
1254
+ rely: z.object({
1255
+ guards: z.array(z.string()),
1256
+ logic_or: z.boolean().optional(),
1257
+ }).nullable().describe("Rely dependencies (other Guards this Guard depends on). null = no rely."),
1258
+ immutable: z.boolean().nullable().describe("Whether the Guard is immutable (frozen for verification). null = unknown."),
1259
+ mermaid: z.string().describe("Mermaid flowchart TD string visualizing the tree. Node shapes: {}=decision (logic_*), []=computation/query, ([])=leaf (identifier), {{}}=context. Includes a color legend comment block + BehaviorTree.CPP-style color annotations (control=blue, decision=amber, computation=purple, query=cyan, leaf=gray, context=green)."),
1260
+ tree_outline: z.string().describe("Indented Markdown outline of the tree (human-editable format). Bidirectional with parseGuardTreeIndented(). Includes JSON code block for round-trip safety."),
1261
+ ascii_art: z.string().describe("ASCII art tree visualization using box-drawing characters (+-- --, |). Table summary appended. Terminal-friendly, avoids JSON escaping issues that affect multi-line Mermaid strings."),
1262
+ markmap: z.string().describe("Markmap-compatible Markdown string (heading levels represent tree depth). Root -> branches -> leaves hierarchy. Renderable by VS Code Markmap extension or markmap.js. Provides an interactive mind-map view of the Guard tree."),
1263
+ })
1264
+ .strict();
1265
+ const PlanObjectEditResultSchema = z
1266
+ .object({
1267
+ action: z.literal("plan_object_edit"),
1268
+ plan_id: z.string().describe("Unique plan ID (UUID). Pass to apply_object_edit within 10 minutes to execute."),
1269
+ object_kind: z.enum(["machine", "guard"]).describe("The object kind that was edited."),
1270
+ object_address: z.string().describe("The on-chain object address being edited."),
1271
+ object_name: z.string().nullable().describe("The object's local name (from LocalMark) if available."),
1272
+ expected_hash: z.string().describe("SHA-256 hash of (current_onchain_state + edited_content). Pass to apply_object_edit as expected_hash for stale-edit detection."),
1273
+ diff: z.object({
1274
+ added: z.array(z.string()).describe("List of added items (node names, edge 'from->to', table identifiers, etc.)."),
1275
+ removed: z.array(z.string()).describe("List of removed items."),
1276
+ modified: z.array(z.string()).describe("List of modified items with a brief description of the change."),
1277
+ summary: z.string().describe("Human-readable one-line diff summary (e.g. '2 nodes added, 1 edge removed, 3 forwards modified')."),
1278
+ }).describe("Structured diff between current on-chain state and edited content."),
1279
+ warnings: z.array(z.object({
1280
+ id: z.string().describe("Warning identifier (e.g. 'W-01')."),
1281
+ description: z.string().describe("What the warning is about."),
1282
+ impact: z.string().describe("Potential impact if ignored."),
1283
+ })).describe("Non-blocking warnings (the edit can still proceed, but review is recommended)."),
1284
+ blocking_errors: z.array(z.object({
1285
+ id: z.string().describe("Error identifier (e.g. 'E-01')."),
1286
+ description: z.string().describe("What the error is."),
1287
+ impact: z.string().describe("Why this blocks execution."),
1288
+ })).describe("Blocking errors (the edit CANNOT proceed until these are fixed)."),
1289
+ can_apply: z.boolean().describe("Whether apply_object_edit can proceed. false if blocking_errors is non-empty."),
1290
+ prepared_call: z.unknown().nullable().describe("The prepared onchain_operations call data (operation_type + data). null if can_apply=false. Pass this to onchain_operations to execute the edit."),
1291
+ expires_at: z.string().describe("ISO timestamp when the plan expires (10 minutes from creation). After expiry, apply_object_edit will refuse to proceed."),
1292
+ summary: z.string().describe("Human-readable one-line plan summary."),
1293
+ })
1294
+ .strict();
1295
+ const ApplyObjectEditResultSchema = z
1296
+ .object({
1297
+ action: z.literal("apply_object_edit"),
1298
+ plan_id: z.string().describe("The plan ID that was applied."),
1299
+ applied: z.boolean().describe("Whether the plan was successfully applied (hash matched and plan was fresh)."),
1300
+ hash_match: z.boolean().describe("Whether the expected_hash matched the stored plan hash. false = stale edit detected."),
1301
+ prepared_call: z.unknown().nullable().describe("The prepared onchain_operations call data. Pass this to onchain_operations to execute the edit on-chain. null if applied=false."),
1302
+ error: z.string().nullable().describe("Error message if applied=false (e.g. 'Plan not found', 'Hash mismatch — on-chain state changed', 'Plan expired'). null on success."),
1303
+ next_step: z.string().describe("Instructions for the next step (typically 'Pass prepared_call to onchain_operations to execute the edit on-chain')."),
1304
+ })
1305
+ .strict();
1306
+ const PatchMachineNodesResultSchema = z
1307
+ .object({
1308
+ action: z.literal("patch_machine_nodes"),
1309
+ machine_address: z.string().describe("The Machine object address being patched."),
1310
+ machine_name: z.string().nullable().describe("The Machine's local name (from LocalMark) if available."),
1311
+ operations_applied: z.number().describe("Number of patch operations successfully applied."),
1312
+ operations_failed: z.array(z.object({
1313
+ operation: z.string().describe("The original operation string."),
1314
+ error: z.string().describe("Why the operation failed."),
1315
+ })).describe("Operations that failed parse/apply (not applied). Also surfaced as E-OP entries in blocking_errors for schema symmetry with plan_object_edit."),
1316
+ patched_nodes: z.array(z.unknown()).describe("The patched Machine nodes (after applying all successful operations)."),
1317
+ patched_edges: z.array(z.unknown()).describe("The patched Machine edges (after applying all successful operations)."),
1318
+ diff: z.object({
1319
+ added: z.array(z.string()).describe("List of added items."),
1320
+ removed: z.array(z.string()).describe("List of removed items."),
1321
+ modified: z.array(z.string()).describe("List of modified items."),
1322
+ summary: z.string().describe("Human-readable one-line diff summary."),
1323
+ }).describe("Diff between original and patched Machine."),
1324
+ warnings: z.array(z.object({
1325
+ id: z.string().describe("Warning identifier (e.g. 'W-01' unreachable node, 'W-02' self-loop)."),
1326
+ description: z.string().describe("What the warning is about."),
1327
+ impact: z.string().describe("Potential impact if ignored."),
1328
+ })).describe("Non-blocking warnings from validateMachine (W-01 unreachable, W-02 self-loop)."),
1329
+ blocking_errors: z.array(z.object({
1330
+ id: z.string().describe("Error identifier (e.g. 'E-01' no entry forward, 'E-02' orphan endpoint, 'E-03' too many nodes, 'E-OP' operation failed)."),
1331
+ description: z.string().describe("What the error is."),
1332
+ impact: z.string().describe("Why this blocks execution."),
1333
+ })).describe("Blocking errors (operation failures + structural validation). The patch CANNOT proceed until these are fixed. Empty array when can_apply=true."),
1334
+ can_apply: z.boolean().describe("Whether the patch can be applied on-chain. false if any blocking_errors exist (operation failures or validateMachine blocking errors)."),
1335
+ prepared_call: z.unknown().nullable().describe("The prepared onchain_operations call data. null if can_apply=false."),
1336
+ summary: z.string().describe("Human-readable one-line patch summary."),
1337
+ })
1338
+ .strict();
1339
+ const PatchGuardTreeResultSchema = z
1340
+ .object({
1341
+ action: z.literal("patch_guard_tree"),
1342
+ guard_address: z.string().describe("The Guard object address being patched."),
1343
+ guard_name: z.string().nullable().describe("The Guard's local name (from LocalMark) if available."),
1344
+ operations_applied: z.number().describe("Number of Guard patch operations successfully applied."),
1345
+ operations_failed: z.array(z.object({
1346
+ operation: z.string().describe("The original operation string."),
1347
+ error: z.string().describe("Why the operation failed."),
1348
+ })).describe("Operations that failed parse/apply (not applied). Also surfaced as E-OP entries in blocking_errors."),
1349
+ patched_root: z.unknown().describe("The patched Guard root node (after applying all successful operations). For set_root, this is the new root; otherwise the original root unchanged."),
1350
+ patched_table: z.array(z.unknown()).describe("The patched Guard table entries (after applying all successful table operations)."),
1351
+ patched_rely: z.unknown().nullable().describe("The patched rely field (cross-guard composition). null if rely was cleared or never set. Shape: { guards: string[], logic_or?: boolean }."),
1352
+ diff: z.object({
1353
+ added: z.array(z.string()).describe("List of added items (table entries, tree nodes)."),
1354
+ removed: z.array(z.string()).describe("List of removed items."),
1355
+ modified: z.array(z.string()).describe("List of modified items with a brief description of the change."),
1356
+ summary: z.string().describe("Human-readable one-line diff summary."),
1357
+ }).describe("Diff between original and patched Guard (root tree + table)."),
1358
+ warnings: z.array(z.object({
1359
+ id: z.string().describe("Warning identifier (e.g. 'W-01' dead submission slot, 'W-02' orphan table entry, 'W-03' deep nesting)."),
1360
+ description: z.string().describe("What the warning is about."),
1361
+ impact: z.string().describe("Potential impact if ignored."),
1362
+ })).describe("Non-blocking warnings from validateGuard (W-01 dead submission slot, W-02 orphan table entry, W-03 deep nesting > 16)."),
1363
+ blocking_errors: z.array(z.object({
1364
+ id: z.string().describe("Error identifier (e.g. 'E-01' no root, 'E-02' identifier not in table, 'E-03' table too large, 'E-OP' operation failed)."),
1365
+ description: z.string().describe("What the error is."),
1366
+ impact: z.string().describe("Why this blocks execution."),
1367
+ })).describe("Blocking errors (operation failures + structural validation). The patch CANNOT proceed until these are fixed. Empty array when can_apply=true."),
1368
+ can_apply: z.boolean().describe("Whether the patch can be applied on-chain. false if any blocking_errors exist."),
1369
+ prepared_call: z.unknown().nullable().describe("The prepared onchain_operations call data (operation_type='guard'). null if can_apply=false."),
1370
+ summary: z.string().describe("Human-readable one-line patch summary."),
820
1371
  })
821
1372
  .strict();
822
1373
  const CloneProjectToNetworkResultSchema = z
@@ -841,6 +1392,562 @@ const MigrateNetworkResultSchema = z
841
1392
  next_steps: z.string().describe("Instructions for deploying the migrated objects on the target network."),
842
1393
  })
843
1394
  .strict();
1395
+ const MigrationPlanStepSchema = z.object({
1396
+ step: z.number().describe("Step number (1-5)."),
1397
+ status: z.enum(["completed", "pending_user_action"]).describe("Whether this step is done or awaits user action."),
1398
+ action: z.string().describe("The action to perform (e.g. 'clone_project_to_network', 'onchain_operations', 'local_mark_operation', 'update_project', 'build_graph')."),
1399
+ description: z.string().describe("Human-readable description of what this step does."),
1400
+ result: z.string().optional().describe("Result of this step (only present when status='completed')."),
1401
+ deployment_plan: z.array(z.object({
1402
+ order: z.number(),
1403
+ object_type: z.string(),
1404
+ object_name: z.string(),
1405
+ operation_type: z.string(),
1406
+ localmark_name: z.string(),
1407
+ note: z.string(),
1408
+ })).optional().describe("Deployment plan for step 2 (on-chain deployment). Only present for step 2."),
1409
+ names_to_register: z.array(z.string()).optional().describe("LocalMark names to re-register on mainnet. Only present for step 3."),
1410
+ critical_note: z.string().optional().describe("Critical note for this step."),
1411
+ }).strict();
1412
+ const MigrateToMainnetResultSchema = z
1413
+ .object({
1414
+ action: z.literal("migrate_to_mainnet"),
1415
+ migration_status: z.string().describe("Overall migration status (e.g. 'step_1_complete_steps_2_5_pending_user_action')."),
1416
+ source_project: z.object({
1417
+ prefix: z.string(),
1418
+ network: z.string(),
1419
+ preserved: z.boolean().describe("Whether the source project is preserved unchanged (always true)."),
1420
+ }).strict(),
1421
+ target_project: z.object({
1422
+ prefix: z.string(),
1423
+ project_id: z.string(),
1424
+ network: z.string(),
1425
+ cloned_objects_count: z.number(),
1426
+ }).strict(),
1427
+ key_principle: z.string().describe("Explains that testnet/mainnet are different projects with different addresses for same names."),
1428
+ migration_plan: z.array(MigrationPlanStepSchema).describe("5-step migration plan. Step 1 is completed; steps 2-5 require user action."),
1429
+ summary: z.string().describe("Human-readable summary of the migration."),
1430
+ })
1431
+ .strict();
1432
+ const RecommendIndustryResultSchema = z
1433
+ .object({
1434
+ action: z.literal("recommend_industry"),
1435
+ intent: z.string().describe("The intent text used for inference."),
1436
+ inferred_traits: z.record(z.unknown()).describe("10-dim industry traits inferred from intent."),
1437
+ inference_confidence: z.number().describe("Inference confidence 0-1 (matched trait count / 10)."),
1438
+ matched_keywords: z.array(z.string()).describe("Keywords that triggered trait inference."),
1439
+ recommendations: z.array(RecommendedIndustryItemSchema).describe("Top-3 similar industries + reference examples."),
1440
+ hint: z.string().describe("How to apply the recommendation (create_project with project_industry)."),
1441
+ })
1442
+ .strict();
1443
+ const ModeSummarySchema = z.object({
1444
+ name: z.string(),
1445
+ display_name: z.string(),
1446
+ version: z.string(),
1447
+ derived_from: z.string().nullable().describe("Source builtin mode (derive_user_mode) or null."),
1448
+ owner: z.string().optional().describe("Mode owner (custom modes only)."),
1449
+ key_risk: z.string(),
1450
+ machine_nodes: z.array(z.string()).describe("Machine shape node names."),
1451
+ similar_industries: z.array(z.string()).optional(),
1452
+ evolution_history: z.array(z.object({
1453
+ version: z.string(),
1454
+ changed_at: z.number(),
1455
+ changes: z.array(z.string()),
1456
+ }).strict()).optional(),
1457
+ }).strict();
1458
+ const ListModesResultSchema = z
1459
+ .object({
1460
+ action: z.literal("list_modes"),
1461
+ builtin_modes: z.array(ModeSummarySchema).describe("Builtin industry modes (use name as project_industry)."),
1462
+ user_modes: z.array(ModeSummarySchema).describe("Caller's custom modes (derive/evolve/register)."),
1463
+ owner: z.string().describe("Owner key for custom modes (local single-user)."),
1464
+ hint: z.string(),
1465
+ })
1466
+ .strict();
1467
+ const DeriveUserModeResultSchema = z
1468
+ .object({
1469
+ action: z.literal("derive_user_mode"),
1470
+ mode: ModeSummarySchema.describe("The derived (and registered) custom mode."),
1471
+ hint: z.string(),
1472
+ })
1473
+ .strict();
1474
+ const EvolveUserModeResultSchema = z
1475
+ .object({
1476
+ action: z.literal("evolve_user_mode"),
1477
+ mode: ModeSummarySchema.describe("The evolved custom mode (version bumped)."),
1478
+ hint: z.string(),
1479
+ })
1480
+ .strict();
1481
+ const RegisterUserModeResultSchema = z
1482
+ .object({
1483
+ action: z.literal("register_user_mode"),
1484
+ mode: ModeSummarySchema.describe("The registered fully-custom mode."),
1485
+ hint: z.string(),
1486
+ })
1487
+ .strict();
1488
+ const UnregisterUserModeResultSchema = z
1489
+ .object({
1490
+ action: z.literal("unregister_user_mode"),
1491
+ removed: z.literal(true),
1492
+ mode_name: z.string(),
1493
+ })
1494
+ .strict();
1495
+ const MetricInfoSchema = z.object({
1496
+ metric_id: z.string(),
1497
+ display_name: z.string(),
1498
+ description: z.string(),
1499
+ type: z.enum(["risk", "benefit"]),
1500
+ scale: z.enum(["level", "numeric", "percentage"]),
1501
+ weight: z.number(),
1502
+ scope: z.enum(["builtin", "custom"]),
1503
+ owner: z.string().optional(),
1504
+ }).strict();
1505
+ const RegisterCustomMetricResultSchema = z
1506
+ .object({
1507
+ action: z.literal("register_custom_metric"),
1508
+ metric: MetricInfoSchema.describe("The registered custom metric (globally effective)."),
1509
+ hint: z.string(),
1510
+ })
1511
+ .strict();
1512
+ const ConstraintInfoSchema = z.object({
1513
+ constraint_id: z.string(),
1514
+ display_name: z.string(),
1515
+ description: z.string(),
1516
+ rule: z.record(z.unknown()).describe("Constraint rule (4 types — see constraint_rule input)."),
1517
+ severity: z.enum(["hard", "soft"]),
1518
+ on_violation: z.enum(["block", "warn", "log"]),
1519
+ scope: z.enum(["builtin", "custom"]),
1520
+ owner: z.string().optional(),
1521
+ }).strict();
1522
+ const RegisterCustomConstraintResultSchema = z
1523
+ .object({
1524
+ action: z.literal("register_custom_constraint"),
1525
+ constraint: ConstraintInfoSchema.describe("The registered custom constraint."),
1526
+ hint: z.string(),
1527
+ })
1528
+ .strict();
1529
+ const ListMetricsConstraintsResultSchema = z
1530
+ .object({
1531
+ action: z.literal("list_metrics_constraints"),
1532
+ metrics: z.array(MetricInfoSchema),
1533
+ constraints: z.array(ConstraintInfoSchema),
1534
+ hint: z.string(),
1535
+ })
1536
+ .strict();
1537
+ const KeywordMatchSchema = z
1538
+ .object({
1539
+ keyword: z.string(),
1540
+ category: z.string(),
1541
+ matched_objects: z.array(z.string()),
1542
+ required_level: z.enum(["R", "C", "OPTIONAL"]),
1543
+ match_count: z.number(),
1544
+ })
1545
+ .strict();
1546
+ const AnalyzeIntentResultSchema = z
1547
+ .object({
1548
+ action: z.literal("analyze_intent"),
1549
+ intent_parsed: z
1550
+ .object({
1551
+ primary_object: z.string().describe("Primary object inferred from the intent keywords."),
1552
+ secondary_objects: z.array(z.string()).describe("Supporting objects typically required alongside the primary one."),
1553
+ detected_scenes: z
1554
+ .array(z
1555
+ .object({
1556
+ object: z.string(),
1557
+ scene_id: z.string().describe("Free-form scene id, e.g. 'retail', 'rental_return'."),
1558
+ })
1559
+ .strict())
1560
+ .describe("Scenes detected from the intent (used for template selection)."),
1561
+ industry: z.string().describe("Industry mode resolved from the intent (defaults to 'general')."),
1562
+ keyword_matches: z.array(KeywordMatchSchema).describe("All keyword matches that drove the identification."),
1563
+ })
1564
+ .strict(),
1565
+ puzzles: z
1566
+ .record(z
1567
+ .object({
1568
+ puzzle: z.unknown(),
1569
+ completeness: z.unknown(),
1570
+ missing_dimensions: z.array(z.string()),
1571
+ })
1572
+ .strict())
1573
+ .describe("Per-object puzzle snapshot, keyed by object_type. Pass this UNCHANGED to aggregate_risks."),
1574
+ overall_completeness: z.enum(["complete", "partial", "empty"]),
1575
+ next_step: z.string().describe("Human-readable suggestion for the next puzzle step."),
1576
+ recommended_creation_order: z.array(z.string()).describe("Recommended object creation order (dependency topology)."),
1577
+ warnings: z.array(z.string()),
1578
+ })
1579
+ .strict();
1580
+ const AggregatedRiskSchema = z
1581
+ .object({
1582
+ risk_rule_id: z.string().describe("Unified risk rule id, e.g. 'R-S-01'."),
1583
+ object_type: z.string(),
1584
+ entry_id: z.string().describe("Object entry_id ('*' when cross-object)."),
1585
+ severity: z.enum(["CRITICAL", "HIGH", "MEDIUM", "LOW", "INFO"]),
1586
+ message: z.string(),
1587
+ fix_suggestion: z.string(),
1588
+ details: z
1589
+ .object({
1590
+ field_path: z.string().optional(),
1591
+ actual_value: z.unknown().optional(),
1592
+ expected_value: z.unknown().optional(),
1593
+ rule_source: z.string().optional(),
1594
+ })
1595
+ .strict()
1596
+ .optional(),
1597
+ })
1598
+ .strict();
1599
+ const SafetyFindingSchema = z
1600
+ .object({
1601
+ rule_id: z.string().describe("Safety rule id (e.g. 'REUSE-SERVICE-01', 'IMMUT-001')."),
1602
+ severity: z.enum(["info", "warn"]),
1603
+ message: z.string(),
1604
+ })
1605
+ .strict();
1606
+ const AggregateRisksResultSchema = z
1607
+ .object({
1608
+ action: z.literal("aggregate_risks"),
1609
+ namespace: z
1610
+ .object({
1611
+ prefix: z.string(),
1612
+ version: z.string(),
1613
+ industry: z.string().optional(),
1614
+ })
1615
+ .strict(),
1616
+ findings: z.array(AggregatedRiskSchema).describe("All risks found, sorted (CRITICAL first)."),
1617
+ severity_summary: z.record(z.number()).describe("Counts keyed by severity."),
1618
+ status: z
1619
+ .enum(["RISK_PASSED", "RISK_BLOCKED", "RISK_PENDING_CONFIRM", "RISK_CANCELLED"])
1620
+ .describe("Aggregated status (62-spec §3.2). RISK_BLOCKED = CRITICAL or above-threshold risks present."),
1621
+ pending_confirmations: z
1622
+ .array(z
1623
+ .object({
1624
+ risk_rule_id: z.string(),
1625
+ description: z.string(),
1626
+ fix_suggestion: z.string(),
1627
+ object_type: z.string(),
1628
+ entry_id: z.string(),
1629
+ })
1630
+ .strict())
1631
+ .optional()
1632
+ .describe("HIGH risks awaiting user confirmation (only when status='RISK_PENDING_CONFIRM')."),
1633
+ calibrated_at: z.number().describe("Calibration timestamp (ms)."),
1634
+ fix_suggestions_grouped: z
1635
+ .record(z.array(z
1636
+ .object({
1637
+ risk_rule_id: z.string(),
1638
+ severity: z.enum(["CRITICAL", "HIGH", "MEDIUM", "LOW", "INFO"]),
1639
+ message: z.string(),
1640
+ fix_suggestion: z.string(),
1641
+ entry_id: z.string(),
1642
+ })
1643
+ .strict()))
1644
+ .optional()
1645
+ .describe("Fix suggestions grouped by object_type."),
1646
+ safety_findings: z
1647
+ .array(SafetyFindingSchema)
1648
+ .optional()
1649
+ .describe("OBJECT_REUSE / IMMUTABILITY findings from safety-rules (only when planned_objects / planned_operations were provided)."),
1650
+ intent_echo: z
1651
+ .object({
1652
+ primary_object: z.string(),
1653
+ industry: z.string(),
1654
+ overall_completeness: z.enum(["complete", "partial", "empty"]),
1655
+ })
1656
+ .strict()
1657
+ .optional()
1658
+ .describe("Echo of the auto-run analyze_intent (only when 'puzzles' was omitted and 'intent' was used)."),
1659
+ warnings: z.array(z.string()),
1660
+ })
1661
+ .strict();
1662
+ const TraceSubstepsResultSchema = z
1663
+ .object({
1664
+ action: z.literal("trace_substeps"),
1665
+ namespace: z.object({ prefix: z.string(), version: z.string() }).strict(),
1666
+ network: z.enum(["testnet", "mainnet"]),
1667
+ coherent: z.boolean().describe("True when no dangling inputs, no cycles, no missing outputs, no cross-step breaks."),
1668
+ dangling_inputs: z
1669
+ .array(z.object({ substep_id: z.string(), missing_ref: z.string(), field_path: z.string() }).strict())
1670
+ .describe("Input refs pointing to non-existent substeps."),
1671
+ circular_refs: z
1672
+ .array(z.object({ cycle: z.array(z.string()) }).strict())
1673
+ .describe("Substep id cycles (when present, topological_order is empty)."),
1674
+ missing_outputs: z
1675
+ .array(z
1676
+ .object({
1677
+ substep_id: z.string(),
1678
+ expected_field: z.string(),
1679
+ dependent_substeps: z.array(z.string()),
1680
+ })
1681
+ .strict())
1682
+ .describe("Substeps that should have produced a field but did not."),
1683
+ cross_step_breaks: z
1684
+ .array(z
1685
+ .object({
1686
+ source_step: z.string(),
1687
+ target_step: z.string(),
1688
+ missing_field: z.string(),
1689
+ })
1690
+ .strict())
1691
+ .describe("Upstream step failed → downstream cannot proceed."),
1692
+ step_details: z
1693
+ .array(z
1694
+ .object({
1695
+ parent_step: z.string(),
1696
+ total_substeps: z.number(),
1697
+ successful: z.number(),
1698
+ failed: z.number(),
1699
+ pending: z.number(),
1700
+ skipped: z.number(),
1701
+ substep_ids: z.array(z.string()),
1702
+ })
1703
+ .strict())
1704
+ .describe("Per-step summary, keyed by parent_step."),
1705
+ topological_order: z.array(z.string()).describe("Topological order of substep ids (empty when a cycle exists)."),
1706
+ d10_check: z
1707
+ .object({
1708
+ check_id: z.literal("D-10"),
1709
+ description: z.string(),
1710
+ status: z.enum(["PASS", "FAIL", "WARN"]),
1711
+ notes: z.array(z.string()),
1712
+ })
1713
+ .strict()
1714
+ .describe("D-10 substep linkage completeness verdict."),
1715
+ })
1716
+ .strict();
1717
+ const MerchantGuideResultSchema = z
1718
+ .object({
1719
+ action: z.literal("merchant_guide"),
1720
+ current_step: z.number().describe("Furthest wizard step reached (2 = awaiting industry confirmation; 9 = harness issues found; 10 = plan ready)."),
1721
+ step_name: z.string(),
1722
+ guide_state: z
1723
+ .object({
1724
+ intent_text: z.string(),
1725
+ confirmed_industry: z.string().optional(),
1726
+ currency: z.string().optional(),
1727
+ deliverables: z.array(z.unknown()).optional(),
1728
+ payment_override: z.record(z.unknown()).optional(),
1729
+ trust_override: z.record(z.unknown()).optional(),
1730
+ adopted_module_ids: z.array(z.string()).optional(),
1731
+ })
1732
+ .strict()
1733
+ .describe("Wizard state — pass back UNCHANGED on the next merchant_guide call."),
1734
+ intent_draft: z.unknown().optional().describe("Step 1-2 only: BusinessIntent draft inferred from the description."),
1735
+ industry_options: z
1736
+ .object({
1737
+ inferred: z.string(),
1738
+ confidence: z.number(),
1739
+ similar: z.array(z.string()),
1740
+ })
1741
+ .strict()
1742
+ .optional()
1743
+ .describe("Step 2 only: industry candidates awaiting merchant confirmation."),
1744
+ intent: z.unknown().optional().describe("Steps 7-10: final BusinessIntent after merchant overrides."),
1745
+ adopted_modules: z
1746
+ .array(z
1747
+ .object({
1748
+ id: z.string(),
1749
+ name: z.string(),
1750
+ description: z.string(),
1751
+ requires_keeper: z.boolean(),
1752
+ keeper_hint: z.string().optional(),
1753
+ user_protections: z.array(z.string()),
1754
+ merchant_obligations: z.array(z.string()),
1755
+ })
1756
+ .strict())
1757
+ .optional()
1758
+ .describe("Steps 6-10: adopted business modules with protections/obligations."),
1759
+ blueprint: z
1760
+ .object({
1761
+ nodes: z.array(z.object({ id: z.string(), type: z.string(), purpose: z.string() }).strict()),
1762
+ edges: z.array(z.object({ from: z.string(), to: z.string(), relation: z.string(), required: z.boolean() }).strict()),
1763
+ })
1764
+ .strict()
1765
+ .optional()
1766
+ .describe("Step 7: semantic object graph (nodes + edges)."),
1767
+ evaluation_preview: z.unknown().optional().describe("Step 8: estimated risk/trust/completeness scores + key risks + module boosts."),
1768
+ graph_validation: z
1769
+ .object({
1770
+ valid: z.boolean(),
1771
+ hard_violations: z.array(z.object({ id: z.string(), description: z.string(), fix: z.string().optional() }).strict()),
1772
+ soft_notes: z.array(z.object({ id: z.string(), description: z.string() }).strict()),
1773
+ })
1774
+ .strict()
1775
+ .optional()
1776
+ .describe("Step 8: structural validation of the semantic graph."),
1777
+ harness_check: z
1778
+ .object({
1779
+ module_constraints: z.array(z.object({
1780
+ module: z.string(),
1781
+ plan_satisfied: z.boolean(),
1782
+ missing: z.array(z.string()).optional(),
1783
+ reason: z.string().optional(),
1784
+ estimated_score_boost: z.number(),
1785
+ }).strict()),
1786
+ blocking_issues: z.array(z.object({
1787
+ module: z.string(),
1788
+ missing_constraints: z.array(z.string()).optional(),
1789
+ fix: z.string().optional(),
1790
+ }).strict()),
1791
+ deploy_time_checks: z.array(z.string()),
1792
+ })
1793
+ .strict()
1794
+ .optional()
1795
+ .describe("Step 9: module constraint check at blueprint stage + deploy-time checklist."),
1796
+ game_theory: z
1797
+ .object({
1798
+ summary: z.string(),
1799
+ coverage: z.string().describe("Covered/total scenario count, e.g. '4/5'."),
1800
+ exposed_scenarios: z.array(z.string()),
1801
+ wow_alignments: z.array(z.string()).describe("Active WOW mechanisms aligning merchant/user incentives."),
1802
+ scenarios: z.array(z.object({
1803
+ scenario: z.string(),
1804
+ covered: z.boolean(),
1805
+ conflict: z.string(),
1806
+ user_protection: z.string(),
1807
+ evaluation_metric: z.string(),
1808
+ recommendation: z.string().optional(),
1809
+ }).strict()),
1810
+ })
1811
+ .strict()
1812
+ .optional()
1813
+ .describe("Step 9 (GLM6/93 §2.3): merchant-user adversarial scenario coverage. 5 canonical scenarios checked against the blueprint; exposed scenarios include fix recommendations."),
1814
+ creation_plan: z
1815
+ .array(z.object({
1816
+ order: z.number(),
1817
+ node_id: z.string(),
1818
+ object_type: z.string(),
1819
+ suggested_name: z.string(),
1820
+ depends_on: z.array(z.string()),
1821
+ operation_hint: z.string(),
1822
+ }).strict())
1823
+ .optional()
1824
+ .describe("Step 10: topologically ordered creation plan. NOT executed — materialize via create_project + onchain_operations."),
1825
+ warnings: z.array(z.string()),
1826
+ next_action: z.string().describe("Human-readable guidance for the next call."),
1827
+ })
1828
+ .strict();
1829
+ const RadarMonitorAlertSchema = z
1830
+ .object({
1831
+ id: z.string(),
1832
+ category: z.enum([
1833
+ "progress_stall", "compensation_drop", "compensation_insufficient",
1834
+ "messenger_timeout", "user_action_required", "review_window",
1835
+ "arb_window", "refund_received", "anomaly",
1836
+ ]),
1837
+ severity: z.enum(["info", "warning", "critical"]),
1838
+ title: z.string(),
1839
+ message: z.string(),
1840
+ action: z.string().optional().describe("Suggested next step."),
1841
+ timestamp: z.number(),
1842
+ order_id: z.string().optional(),
1843
+ service_id: z.string().optional(),
1844
+ node: z.string().optional(),
1845
+ metric: z
1846
+ .object({
1847
+ label: z.string(),
1848
+ value: z.number(),
1849
+ threshold: z.number().optional(),
1850
+ unit: z.string().optional(),
1851
+ })
1852
+ .strict()
1853
+ .optional(),
1854
+ })
1855
+ .strict();
1856
+ const RadarForwardSchema = z
1857
+ .object({
1858
+ name: z.string().describe("Forward (operation) name."),
1859
+ to_node: z.string().describe("Target node after execution."),
1860
+ execution_path: z
1861
+ .enum(["order_holder", "permission", "named_operator", "not_available"])
1862
+ .describe("How this account may execute it (not_available if it can't)."),
1863
+ permission_index: z.number().optional().describe("Permission index required (if permission-gated)."),
1864
+ named_operator: z.string().optional().describe("Named operator (LocalMark name) required (if named-gated)."),
1865
+ guard: z.string().optional().describe("Guard address gating this forward."),
1866
+ semantics: z.string().describe("Human explanation of what executing this forward means."),
1867
+ consequence: z.string().optional().describe("Consequence hint (completion fund-release / refund path)."),
1868
+ })
1869
+ .strict();
1870
+ const RadarPendingClaimSchema = z
1871
+ .object({
1872
+ kind: z.enum(["reward", "discount", "compensation", "rating"]),
1873
+ label: z.string(),
1874
+ how: z.string().describe("How to claim (tool + operation hint)."),
1875
+ })
1876
+ .strict();
1877
+ const MerchantInterestAnalysisSchema = z
1878
+ .object({
1879
+ fund_flow: z
1880
+ .array(z.string())
1881
+ .describe("Where money sits and what releases it (escrow, Allocation waterfall, compensation_fund)."),
1882
+ responsibility: z
1883
+ .array(z.string())
1884
+ .describe("What this account is semantically liable for right now (permission-gated forwards, guard obligations)."),
1885
+ leverage: z
1886
+ .array(z.string())
1887
+ .describe("Actions serving the merchant's own interest (settlement speed, evidence pre-upload, Messenger nudge). Informational only."),
1888
+ stakes: z
1889
+ .array(z.string())
1890
+ .describe("Downside exposure (arbitration indemnity, arb-loss record, stall statistics, refund aftermath)."),
1891
+ summary: z.string().describe("One-paragraph merchant-interest summary."),
1892
+ })
1893
+ .strict();
1894
+ const OrderRadarResultSchema = z
1895
+ .object({
1896
+ account: z.string(),
1897
+ progress: z.string(),
1898
+ order: z.string().optional(),
1899
+ current_node: z.string().describe("Current node name ('' = entry, not yet started)."),
1900
+ perspective: z
1901
+ .enum(["customer", "operator", "observer"])
1902
+ .describe("Derived from on-chain data (Order.builder + PermissionPerm grants), never caller-asserted."),
1903
+ roles: z
1904
+ .array(z.object({ label: z.string(), can_act_now: z.boolean() }).strict())
1905
+ .describe("All roles this account holds on this order's workflow."),
1906
+ operable: z.array(RadarForwardSchema).describe("Forwards THIS account can execute NOW (branch options if >1)."),
1907
+ branch_choice: z
1908
+ .object({
1909
+ message: z.string(),
1910
+ options: z.array(z.object({ forward: z.string(), to_node: z.string(), consequence: z.string().optional() }).strict()),
1911
+ })
1912
+ .strict()
1913
+ .optional()
1914
+ .describe("Present when >1 operable forward. AI MUST present options neutrally; the role decides."),
1915
+ waiting_on: z
1916
+ .array(z.object({ role: z.string(), forwards: z.array(z.string()) }).strict())
1917
+ .describe("What the workflow is waiting on from OTHER roles."),
1918
+ pending_claims: z.array(RadarPendingClaimSchema).describe("Unclaimed benefits / post-purchase actions."),
1919
+ interest_hints: z
1920
+ .array(z.string())
1921
+ .describe("Perspective-specific own-interest hints (fund-release trigger, settlement cycle, reputation)."),
1922
+ workflow_unknown: z.boolean().describe("True when Machine data was unavailable — operable/waiting_on unknown."),
1923
+ interest_analysis: MerchantInterestAnalysisSchema.optional().describe("Merchant-side interest analysis (fund_flow/responsibility/leverage/stakes) — present ONLY when perspective='operator' " +
1924
+ "and order data is available. AI MUST surface it as neutral information; the merchant decides."),
1925
+ summary: z.string().describe("One-paragraph AI-ready summary."),
1926
+ attached_alerts: z
1927
+ .array(RadarMonitorAlertSchema)
1928
+ .optional()
1929
+ .describe("Order-monitor alerts (stall/compensation/review-window) when radar_include_alerts=true."),
1930
+ })
1931
+ .strict();
1932
+ const ParticipationRadarResultSchema = z
1933
+ .object({
1934
+ action: z.literal("participation_radar"),
1935
+ account: z.string().describe("Resolved account address."),
1936
+ orders_analyzed: z.number(),
1937
+ actionable: z
1938
+ .array(OrderRadarResultSchema)
1939
+ .describe("Orders where the account can act NOW or has pending claims (customer perspective first)."),
1940
+ waiting: z.array(OrderRadarResultSchema).describe("Orders where the account is only waiting on other roles."),
1941
+ all_pending_claims: z
1942
+ .array(RadarPendingClaimSchema.extend({ progress: z.string() }))
1943
+ .describe("All pending claims across orders, tagged with their Progress address."),
1944
+ unread_messages_total: z.number().describe("Unread Messenger messages total across all conversations of the radar account (local encrypted storage, read-only — never marks messages viewed; 0 with a data_gaps note when the account is not a local messenger account)."),
1945
+ data_gaps: z
1946
+ .array(z.string())
1947
+ .describe("Graceful degradation notes (e.g. 'Order 0x… not found', 'Machine nodes unavailable')."),
1948
+ summary: z.string().describe("Account-level dashboard summary."),
1949
+ })
1950
+ .strict();
844
1951
  export const ProjectOperationOutputSchema = z
845
1952
  .object({
846
1953
  result: z.discriminatedUnion("action", [
@@ -866,8 +1973,32 @@ export const ProjectOperationOutputSchema = z
866
1973
  PreEvaluateCheckResultSchema,
867
1974
  VerifyDeploymentResultSchema,
868
1975
  GetMachineGraphResultSchema,
1976
+ GetGuardGraphResultSchema,
1977
+ PlanObjectEditResultSchema,
1978
+ ApplyObjectEditResultSchema,
1979
+ PatchMachineNodesResultSchema,
1980
+ PatchGuardTreeResultSchema,
869
1981
  CloneProjectToNetworkResultSchema,
870
1982
  MigrateNetworkResultSchema,
1983
+ MigrateToMainnetResultSchema,
1984
+ RecommendIndustryResultSchema,
1985
+ ListModesResultSchema,
1986
+ DeriveUserModeResultSchema,
1987
+ EvolveUserModeResultSchema,
1988
+ RegisterUserModeResultSchema,
1989
+ UnregisterUserModeResultSchema,
1990
+ RegisterCustomMetricResultSchema,
1991
+ RegisterCustomConstraintResultSchema,
1992
+ ListMetricsConstraintsResultSchema,
1993
+ AnalyzeIntentResultSchema,
1994
+ AggregateRisksResultSchema,
1995
+ TraceSubstepsResultSchema,
1996
+ MerchantGuideResultSchema,
1997
+ ParticipationRadarResultSchema,
871
1998
  ]).describe("Query result — shape depends on action"),
1999
+ skills_recommended: z.string().optional().describe("Skills recommendation hint (F-10). Informational only — MCP executes " +
2000
+ "independently of skills. Present when the action benefits from skills' " +
2001
+ "business-semantic guidance (e.g. service/machine/guard/evaluation). " +
2002
+ "Users without skills installed can ignore this field."),
872
2003
  })
873
2004
  .strict();