@wowok/agent-mcp 2.6.1 → 2.6.3

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 (125) hide show
  1. package/dist/customer/info-puzzle.d.ts +1 -1
  2. package/dist/customer/info-puzzle.js +4 -2
  3. package/dist/customer/risk-assessment.js +26 -4
  4. package/dist/customer/types.d.ts +2 -0
  5. package/dist/examples/guard-template-balance-check.json +38 -0
  6. package/dist/examples/guard-template-time-lock.json +39 -0
  7. package/dist/examples/machine-template-7node-rental.json +114 -0
  8. package/dist/examples/rental-ziroom-machine-create.json +137 -0
  9. package/dist/examples/rental-ziroom-permission-create.json +35 -0
  10. package/dist/examples/rental-ziroom-service-create.json +80 -0
  11. package/dist/examples/retail-myshop-service-create.json +88 -0
  12. package/dist/extensions/capability-manifest.js +24 -24
  13. package/dist/extensions/constraint-registry.js +18 -18
  14. package/dist/extensions/metric-registry.js +14 -14
  15. package/dist/extensions/mode-evaluator.js +16 -16
  16. package/dist/extensions/modes.js +131 -45
  17. package/dist/extensions/registry.d.ts +2 -0
  18. package/dist/extensions/registry.js +63 -30
  19. package/dist/extensions/types.d.ts +1 -0
  20. package/dist/index.js +50 -0
  21. package/dist/knowledge/deployment-scanner.js +1 -1
  22. package/dist/knowledge/fund-layer.d.ts +72 -0
  23. package/dist/knowledge/fund-layer.js +420 -0
  24. package/dist/knowledge/guard-render.d.ts +57 -0
  25. package/dist/knowledge/guard-render.js +700 -0
  26. package/dist/knowledge/guard-submission-prompt.d.ts +31 -0
  27. package/dist/knowledge/guard-submission-prompt.js +171 -0
  28. package/dist/knowledge/machine-ledger.js +1 -1
  29. package/dist/knowledge/machine-render.d.ts +41 -0
  30. package/dist/knowledge/machine-render.js +565 -0
  31. package/dist/knowledge/machine-templates.js +4 -4
  32. package/dist/knowledge/reward-confirm.js +2 -2
  33. package/dist/knowledge/reward-puzzle.js +1 -1
  34. package/dist/knowledge/reward-risk.js +9 -9
  35. package/dist/knowledge/reward-templates.js +2 -2
  36. package/dist/knowledge/service-confirm.d.ts +1 -1
  37. package/dist/knowledge/service-confirm.js +3 -3
  38. package/dist/knowledge/service-context.js +1 -1
  39. package/dist/knowledge/service-ledger.js +1 -1
  40. package/dist/knowledge/service-risk.d.ts +1 -1
  41. package/dist/knowledge/service-risk.js +3 -3
  42. package/dist/knowledge/service-templates.js +2 -2
  43. package/dist/knowledge/service-translation.d.ts +1 -1
  44. package/dist/knowledge/service-translation.js +7 -7
  45. package/dist/project/deployment-bridge.js +6 -5
  46. package/dist/project/deployment-doc.js +5 -5
  47. package/dist/project/edit-planner.d.ts +123 -0
  48. package/dist/project/edit-planner.js +1371 -0
  49. package/dist/project/evaluation.js +314 -14
  50. package/dist/project/graph-builder.js +6 -1
  51. package/dist/project/handlers.d.ts +99 -2
  52. package/dist/project/handlers.js +358 -16
  53. package/dist/project/stage-gate.js +4 -4
  54. package/dist/schema/call/allocation.js +2 -2
  55. package/dist/schema/call/arbitration.js +19 -6
  56. package/dist/schema/call/contact.js +2 -2
  57. package/dist/schema/call/demand.js +2 -2
  58. package/dist/schema/call/guard.js +1 -1
  59. package/dist/schema/call/machine.d.ts +1975 -777
  60. package/dist/schema/call/machine.js +50 -4
  61. package/dist/schema/call/order.js +3 -6
  62. package/dist/schema/call/permission.js +2 -2
  63. package/dist/schema/call/repository.js +2 -2
  64. package/dist/schema/call/reward.js +3 -3
  65. package/dist/schema/call/semantic.js +7 -1
  66. package/dist/schema/call/service.d.ts +180 -8
  67. package/dist/schema/call/service.js +82 -27
  68. package/dist/schema/call/treasury.js +3 -3
  69. package/dist/schema/common/index.d.ts +2 -0
  70. package/dist/schema/common/index.js +46 -10
  71. package/dist/schema/local/index.js +5 -1
  72. package/dist/schema/operations.d.ts +755 -176
  73. package/dist/schema/operations.js +43 -7
  74. package/dist/schema/project/index.d.ts +969 -6
  75. package/dist/schema/project/index.js +268 -4
  76. package/dist/schema/query/index.d.ts +217 -0
  77. package/dist/schema/query/index.js +63 -33
  78. package/dist/schema/schema-query/index.d.ts +53 -3
  79. package/dist/schema/schema-query/index.js +17 -2
  80. package/dist/schema/utils/node-parser.js +13 -0
  81. package/dist/schema/utils/object-type-utils.d.ts +12 -0
  82. package/dist/schema/utils/object-type-utils.js +35 -0
  83. package/dist/schema/utils/permission-machine-check.d.ts +49 -0
  84. package/dist/schema/utils/permission-machine-check.js +121 -0
  85. package/dist/schema/utils/skills-recommendation.d.ts +2 -0
  86. package/dist/schema/utils/skills-recommendation.js +76 -0
  87. package/dist/schema-query/index.d.ts +14 -1
  88. package/dist/schema-query/index.js +104 -2
  89. package/dist/schemas/account_operation.schema.json +1 -1
  90. package/dist/schemas/index.json +1 -1
  91. package/dist/schemas/onchain_events.output.json +1 -1
  92. package/dist/schemas/onchain_operations.output.json +2820 -0
  93. package/dist/schemas/onchain_operations.schema.json +115 -53
  94. package/dist/schemas/onchain_operations_allocation.schema.json +5 -5
  95. package/dist/schemas/onchain_operations_arbitration.schema.json +9 -7
  96. package/dist/schemas/onchain_operations_contact.schema.json +3 -3
  97. package/dist/schemas/onchain_operations_demand.schema.json +3 -3
  98. package/dist/schemas/onchain_operations_gen_passport.schema.json +2 -2
  99. package/dist/schemas/onchain_operations_guard.schema.json +1 -1
  100. package/dist/schemas/onchain_operations_machine.schema.json +4 -4
  101. package/dist/schemas/onchain_operations_order.schema.json +3 -3
  102. package/dist/schemas/onchain_operations_payment.schema.json +1 -1
  103. package/dist/schemas/onchain_operations_permission.schema.json +2 -2
  104. package/dist/schemas/onchain_operations_progress.schema.json +1 -1
  105. package/dist/schemas/onchain_operations_proof.schema.json +1 -1
  106. package/dist/schemas/onchain_operations_repository.schema.json +3 -3
  107. package/dist/schemas/onchain_operations_reward.schema.json +6 -6
  108. package/dist/schemas/onchain_operations_service.schema.json +77 -17
  109. package/dist/schemas/onchain_operations_treasury.schema.json +4 -4
  110. package/dist/schemas/onchain_table_data.output.json +1 -1
  111. package/dist/schemas/onchain_table_data.schema.json +10 -9
  112. package/dist/schemas/project_operation.output.json +1026 -7
  113. package/dist/schemas/project_operation.schema.json +46 -4
  114. package/dist/schemas/query_toolkit.output.json +15 -15
  115. package/dist/schemas/query_toolkit.schema.json +3 -3
  116. package/dist/schemas/schema_query.output.json +64 -1
  117. package/dist/schemas/schema_query.schema.json +3 -2
  118. package/dist/schemas/wowok_buildin_info.output.json +81 -8
  119. package/dist/schemas/wowok_buildin_info.schema.json +46 -2
  120. package/dist/tools/handlers/onchain.js +571 -6
  121. package/dist/tools/handlers/project.js +25 -2
  122. package/dist/tools/handlers/schema-query.js +24 -1
  123. package/dist/tools/index.d.ts +8 -0
  124. package/dist/tools/index.js +177 -6
  125. package/package.json +2 -2
@@ -64,19 +64,47 @@ const RETAIL_BUILD_NOTES = [
64
64
  "Refund path must support return-and-exchange flow",
65
65
  "Compensation fund covers return/exchange disputes",
66
66
  ];
67
+ const RETAIL_D2C_MACHINE_SHAPE = [
68
+ { name: "ordered", role: "Entry: order created (funds escrowed in Allocation)" },
69
+ { name: "shipped", role: "Merchant ships goods" },
70
+ { name: "delivered", role: "Goods delivered to buyer" },
71
+ { name: "completed", role: "Buyer confirms receipt — withdraw_guard releases funds" },
72
+ { name: "cancelled", role: "Pre-ship cancellation — refund_guard refunds buyer" },
73
+ ];
74
+ const RETAIL_D2C_GUARDS = [
75
+ { template_id: "withdraw_guard_delivery", host: "service", purpose: "Release funds to merchant + processor on order completion (delivery confirmation)" },
76
+ { template_id: "refund_guard_cancellation", host: "service", purpose: "Refund 100% to buyer on order cancellation" },
77
+ ];
78
+ const RETAIL_D2C_ALLOCATOR = {
79
+ recipient: "entity",
80
+ count: 2,
81
+ mode: "rate",
82
+ description: "Merchant 97% + Processor 3% (rate-based split, no platform commission)",
83
+ };
84
+ const RETAIL_D2C_KEY_RISK = "No platform arbitration — disputes rely on optional Arbitration or off-chain chargeback";
85
+ const RETAIL_D2C_BUILD_NOTES = [
86
+ "Allocation escrow replaces platform custody — funds locked in contract until Guard releases",
87
+ "withdraw_guard enforces delivery gate — merchant must reach 'completed' state to receive payment",
88
+ "refund_guard ensures 100% refund on cancellation — no merchant approval needed",
89
+ "No buy_guard needed — D2C doesn't gate purchases (open storefront)",
90
+ "Arbitration is optional — add when dispute volume justifies the cost",
91
+ "Service ↔ Guard circular dependency: create Service (unpublished) → create Guards → update Service (publish)",
92
+ ];
67
93
  const SUPPORTED_INDUSTRY_SET = new Set([
68
- "freelance", "rental", "education", "travel", "subscription", "retail",
94
+ "freelance", "rental", "education", "travel", "subscription", "retail", "retail_d2c",
69
95
  ]);
70
96
  function fetchTemplate(name) {
71
- const traits = getIndustryTraits(name) ?? GENERAL_TRAITS;
97
+ const traitsLookupName = name === "retail_d2c" ? "retail" : name;
98
+ const traits = getIndustryTraits(traitsLookupName) ?? GENERAL_TRAITS;
72
99
  const isSupported = SUPPORTED_INDUSTRY_SET.has(name);
100
+ const industryLookupName = name === "retail_d2c" ? "retail" : name;
73
101
  const risk_checks = isSupported
74
- ? getIndustryRiskChecks(name)
102
+ ? getIndustryRiskChecks(industryLookupName)
75
103
  : [];
76
104
  const needs = isSupported
77
- ? getIndustryNeeds(name)
105
+ ? getIndustryNeeds(industryLookupName)
78
106
  : [];
79
- const flywheel = getFlywheelForIndustry(name) ?? GENERAL_FLYWHEEL;
107
+ const flywheel = getFlywheelForIndustry(traitsLookupName) ?? GENERAL_FLYWHEEL;
80
108
  let machine_shape;
81
109
  let guards;
82
110
  let allocator;
@@ -89,6 +117,13 @@ function fetchTemplate(name) {
89
117
  key_risk = RETAIL_KEY_RISK;
90
118
  build_notes = RETAIL_BUILD_NOTES;
91
119
  }
120
+ else if (name === "retail_d2c") {
121
+ machine_shape = RETAIL_D2C_MACHINE_SHAPE;
122
+ guards = RETAIL_D2C_GUARDS;
123
+ allocator = RETAIL_D2C_ALLOCATOR;
124
+ key_risk = RETAIL_D2C_KEY_RISK;
125
+ build_notes = RETAIL_D2C_BUILD_NOTES;
126
+ }
92
127
  else if (name === "general") {
93
128
  const sm = getScenarioMode("general");
94
129
  machine_shape = GENERAL_MACHINE_SHAPE;
@@ -113,7 +148,7 @@ function fetchTemplate(name) {
113
148
  export const BUILTIN_MODES = [
114
149
  {
115
150
  name: "freelance",
116
- display_name: "Freelance 自由职业",
151
+ display_name: "Freelance",
117
152
  version: "v1",
118
153
  source: "builtin",
119
154
  ...fetchTemplate("freelance"),
@@ -131,28 +166,31 @@ export const BUILTIN_MODES = [
131
166
  machine: { wip_required: true, wip_hash_algorithm: "sha256", acceptance_gate: true },
132
167
  },
133
168
  expected_benefits: [
134
- { metric: "纠纷率降低", expected_value: "40%", evidence: "WIP 哈希 + 里程碑分账强制交付证据" },
135
- { metric: "交付确认效率", expected_value: "提升 50%", evidence: "acceptance gate 自动化验收" },
136
- { metric: "提供方回款保障", expected_value: "100%", evidence: "accepted 节点后资金自动释放给提供方" },
169
+ { metric: "Dispute rate reduction", expected_value: "40%", evidence: "WIP hash + milestone allocation enforces delivery evidence" },
170
+ { metric: "Delivery confirmation efficiency", expected_value: "+50%", evidence: "acceptance gate automates acceptance workflow" },
171
+ { metric: "Provider payment assurance", expected_value: "100%", evidence: "Funds auto-release to provider after accepted node" },
137
172
  ],
138
173
  risk_appetite: "balanced",
139
174
  risk_constraints: {
140
175
  require_arbitration: true,
141
176
  require_compensation_fund: false,
142
177
  require_wip_evidence: true,
143
- other_constraints: ["setting_locked_time ≥ 7d 以锁定合作期规则"],
178
+ other_constraints: [
179
+ "setting_locked_time >= 7d to lock engagement-period rules",
180
+ "ISSUE-P1-4: 48h auto-accept requires off-chain keeper (WoWok Guard does not support time-based triggers). Deploy a keeper service that polls Progress objects in 'delivered' state and calls adminUnhold (permission 224) after 48h timeout. See keeper template in docs.",
181
+ ],
144
182
  },
145
183
  applicable_conditions: {
146
184
  business_scale: "small",
147
185
  min_daily_orders: 1,
148
- other_conditions: ["适合中长期项目交付", "需里程碑分阶段验收"],
186
+ other_conditions: ["Suitable for mid-to-long-term project delivery", "Requires milestone-based phased acceptance"],
149
187
  },
150
188
  similar_industries: ["rental", "education"],
151
189
  novel_capabilities: ["allocation.distribute_milestone"],
152
190
  },
153
191
  {
154
192
  name: "rental",
155
- display_name: "Rental 租赁",
193
+ display_name: "Rental",
156
194
  version: "v1",
157
195
  source: "builtin",
158
196
  ...fetchTemplate("rental"),
@@ -170,9 +208,9 @@ export const BUILTIN_MODES = [
170
208
  machine: { wip_required: true, wip_stages: ["handover_out", "returned"], inspection_gate: true },
171
209
  },
172
210
  expected_benefits: [
173
- { metric: "押金纠纷率", expected_value: "降低 60%", evidence: "pre-rental WIP 强制记录物品原始状态" },
174
- { metric: "损坏定责准确率", expected_value: "提升 70%", evidence: "前后 WIP 哈希对比,杜绝无据扣款" },
175
- { metric: "信任评分", expected_value: "提升 25%", evidence: "compensation_fund 覆盖损坏风险" },
211
+ { metric: "Deposit dispute rate", expected_value: "-60%", evidence: "pre-rental WIP mandatorily records item's original state" },
212
+ { metric: "Damage liability accuracy", expected_value: "+70%", evidence: "pre/post WIP hash comparison eliminates unfounded deductions" },
213
+ { metric: "Trust score", expected_value: "+25%", evidence: "compensation_fund covers damage risk" },
176
214
  ],
177
215
  risk_appetite: "conservative",
178
216
  risk_constraints: {
@@ -180,19 +218,20 @@ export const BUILTIN_MODES = [
180
218
  require_compensation_fund: true,
181
219
  require_wip_evidence: true,
182
220
  max_single_transaction: 10000,
183
- other_constraints: ["押金必须 escrow 托管(不可直转)", "lock_duration ≥ 7d 防止商家随意提取"],
221
+ compensation_fund_coverage_ratio: 10,
222
+ other_constraints: ["Deposit must be escrowed (no direct transfer)", "lock_duration >= 7d to prevent arbitrary merchant withdrawal"],
184
223
  },
185
224
  applicable_conditions: {
186
225
  business_scale: "small",
187
226
  min_daily_orders: 1,
188
- other_conditions: ["需物理物品交接", "有物流或线下交付环节"],
227
+ other_conditions: ["Requires physical item handover", "Has logistics or offline delivery leg"],
189
228
  },
190
229
  similar_industries: ["retail", "travel"],
191
230
  novel_capabilities: [],
192
231
  },
193
232
  {
194
233
  name: "education",
195
- display_name: "Education 教育",
234
+ display_name: "Education",
196
235
  version: "v1",
197
236
  source: "builtin",
198
237
  ...fetchTemplate("education"),
@@ -218,28 +257,28 @@ export const BUILTIN_MODES = [
218
257
  service: { setting_locked_time: "120d", anti_runaway: true },
219
258
  },
220
259
  expected_benefits: [
221
- { metric: "退费纠纷率", expected_value: "降低 50%", evidence: "per-session release 按课时释放学费" },
222
- { metric: "机构跑路风险", expected_value: "消除", evidence: "资金按课时释放,未交付部分可退" },
223
- { metric: "出勤可追溯", expected_value: "100%", evidence: "attendance_guard 每课时签名" },
260
+ { metric: "Refund dispute rate", expected_value: "-50%", evidence: "per-session release distributes tuition by class" },
261
+ { metric: "Institution runaway risk", expected_value: "eliminated", evidence: "Funds release per session; undelivered portion is refundable" },
262
+ { metric: "Attendance traceability", expected_value: "100%", evidence: "attendance_guard signs each session" },
224
263
  ],
225
264
  risk_appetite: "conservative",
226
265
  risk_constraints: {
227
266
  require_arbitration: true,
228
267
  require_compensation_fund: true,
229
268
  require_wip_evidence: false,
230
- other_constraints: ["setting_locked_time 覆盖整个学期(≥90d)", "长周期需关注 >90d 进度"],
269
+ other_constraints: ["setting_locked_time covers the entire term (>=90d)", "Long-cycle projects must monitor >90d progress"],
231
270
  },
232
271
  applicable_conditions: {
233
272
  business_scale: "medium",
234
273
  min_daily_orders: 1,
235
- other_conditions: ["长周期交付", "需分课时验收", "监管强度 medium"],
274
+ other_conditions: ["Long-cycle delivery", "Requires per-session acceptance", "Regulatory intensity: medium"],
236
275
  },
237
276
  similar_industries: ["freelance", "subscription"],
238
277
  novel_capabilities: ["allocation.distribute_milestone"],
239
278
  },
240
279
  {
241
280
  name: "travel",
242
- display_name: "Travel 旅游",
281
+ display_name: "Travel",
243
282
  version: "v1",
244
283
  source: "builtin",
245
284
  ...fetchTemplate("travel"),
@@ -266,28 +305,28 @@ export const BUILTIN_MODES = [
266
305
  service: { supply_chain_suborders: true, segment_guard_required: true },
267
306
  },
268
307
  expected_benefits: [
269
- { metric: "资金透明度", expected_value: "100%", evidence: "multi-tier allocation 按段分账至酒店/导游/司机" },
270
- { metric: "行程变更纠纷", expected_value: "降低 45%", evidence: "segment WIP 每段验收" },
271
- { metric: "违约赔付保障", expected_value: "提升 60%", evidence: "compensation_fund 覆盖行程违约" },
308
+ { metric: "Fund transparency", expected_value: "100%", evidence: "multi-tier allocation splits per segment to hotel/guide/driver" },
309
+ { metric: "Itinerary change disputes", expected_value: "-45%", evidence: "segment WIP accepts each leg" },
310
+ { metric: "Breach compensation assurance", expected_value: "+60%", evidence: "compensation_fund covers itinerary breach" },
272
311
  ],
273
312
  risk_appetite: "balanced",
274
313
  risk_constraints: {
275
314
  require_arbitration: true,
276
315
  require_compensation_fund: true,
277
316
  require_wip_evidence: true,
278
- other_constraints: ["多级分账需 guard chaining 校验", "deposit 20% + final 80% 两段付款"],
317
+ other_constraints: ["Multi-tier allocation requires guard chaining validation", "deposit 20% + final 80% two-stage payment"],
279
318
  },
280
319
  applicable_conditions: {
281
320
  business_scale: "medium",
282
321
  min_daily_orders: 1,
283
- other_conditions: ["多段行程组合", "需酒店/导游/司机多方分账"],
322
+ other_conditions: ["Multi-segment itinerary combination", "Requires hotel/guide/driver multi-party allocation"],
284
323
  },
285
324
  similar_industries: ["rental", "education"],
286
325
  novel_capabilities: [],
287
326
  },
288
327
  {
289
328
  name: "subscription",
290
- display_name: "Subscription 订阅",
329
+ display_name: "Subscription",
291
330
  version: "v1",
292
331
  source: "builtin",
293
332
  ...fetchTemplate("subscription"),
@@ -310,28 +349,29 @@ export const BUILTIN_MODES = [
310
349
  service: { creator_data_subscription: true, periodic_billing: true },
311
350
  },
312
351
  expected_benefits: [
313
- { metric: "续费率", expected_value: "提升 25%", evidence: "loyalty reward + 透明订阅机制" },
314
- { metric: "退订纠纷", expected_value: "消除", evidence: "cancel anytime + no auto-renew trap" },
315
- { metric: "创作者留存", expected_value: "提升 30%", evidence: "deliver_guard_wip 防止内容断更" },
352
+ { metric: "Renewal rate", expected_value: "+25%", evidence: "loyalty reward + transparent subscription mechanism" },
353
+ { metric: "Cancellation disputes", expected_value: "eliminated", evidence: "cancel anytime + no auto-renew trap" },
354
+ { metric: "Creator retention", expected_value: "+30%", evidence: "deliver_guard_wip prevents content dropout" },
316
355
  ],
317
356
  risk_appetite: "aggressive",
318
357
  risk_constraints: {
319
358
  require_arbitration: false,
320
359
  require_compensation_fund: false,
321
360
  require_wip_evidence: false,
322
- other_constraints: ["禁止 dead-end 节点(防止锁定)", "charge_guard 每期需用户确认"],
361
+ compensation_fund_coverage_ratio: 3,
362
+ other_constraints: ["Forbid dead-end nodes (prevent lock-in)", "charge_guard requires user confirmation each period"],
323
363
  },
324
364
  applicable_conditions: {
325
365
  business_scale: "small",
326
366
  min_daily_orders: 5,
327
- other_conditions: ["纯数字交付", "周期性内容或 SaaS 服务"],
367
+ other_conditions: ["Pure-digital delivery", "Periodic content or SaaS service"],
328
368
  },
329
369
  similar_industries: ["freelance", "education"],
330
370
  novel_capabilities: [],
331
371
  },
332
372
  {
333
373
  name: "retail",
334
- display_name: "Retail 零售",
374
+ display_name: "Retail",
335
375
  version: "v1",
336
376
  source: "builtin",
337
377
  ...fetchTemplate("retail"),
@@ -354,28 +394,74 @@ export const BUILTIN_MODES = [
354
394
  service: { logistics_mode: "standard", first_order_discount: true },
355
395
  },
356
396
  expected_benefits: [
357
- { metric: "退货纠纷率", expected_value: "降低 35%", evidence: "logistics WIP + refund path 保障" },
358
- { metric: "复购率", expected_value: "提升 20%", evidence: "spend cashback reward" },
359
- { metric: "商品真实性可追溯", expected_value: "100%", evidence: "WIP 验证商品/物流信息" },
397
+ { metric: "Return dispute rate", expected_value: "-35%", evidence: "logistics WIP + refund path assurance" },
398
+ { metric: "Repurchase rate", expected_value: "+20%", evidence: "spend cashback reward" },
399
+ { metric: "Product authenticity traceability", expected_value: "100%", evidence: "WIP verifies product/logistics info" },
360
400
  ],
361
401
  risk_appetite: "conservative",
362
402
  risk_constraints: {
363
403
  require_arbitration: true,
364
404
  require_compensation_fund: true,
365
405
  require_wip_evidence: false,
366
- other_constraints: ["refund_window ≥ 7d", "confirm_gate 仅买家可确认收货"],
406
+ compensation_fund_coverage_ratio: 5,
407
+ other_constraints: ["refund_window >= 7d", "confirm_gate: only buyer can confirm receipt"],
367
408
  },
368
409
  applicable_conditions: {
369
410
  business_scale: "medium",
370
411
  min_daily_orders: 10,
371
- other_conditions: ["有物流发货环节", "高频小额交易"],
412
+ other_conditions: ["Has logistics shipping leg", "High-frequency small-ticket transactions"],
372
413
  },
373
414
  similar_industries: ["rental", "subscription"],
374
415
  novel_capabilities: [],
375
416
  },
417
+ {
418
+ name: "retail_d2c",
419
+ display_name: "Retail D2C (Direct-to-Consumer)",
420
+ version: "v1",
421
+ source: "builtin",
422
+ ...fetchTemplate("retail_d2c"),
423
+ capabilities_used: [
424
+ "permission.index_create", "permission.role_assign",
425
+ "guard.validate_withdraw", "guard.validate_refund",
426
+ "machine.node_topology",
427
+ "allocation.distribute",
428
+ "service.publish", "progress.advance",
429
+ "contact.im_create",
430
+ ],
431
+ config_overrides: {
432
+ machine: {
433
+ wip_required: false,
434
+ confirm_gate: true,
435
+ refund_requires_approval: false,
436
+ },
437
+ service: { logistics_mode: "merchant_managed", multi_recipient_allocation: true },
438
+ },
439
+ expected_benefits: [
440
+ { metric: "Merchant revenue share", expected_value: "97%", evidence: "No platform commission — only 3% processing fee" },
441
+ { metric: "Fund safety", expected_value: "contract-grade", evidence: "Allocation escrow + Guard verification replaces platform custody" },
442
+ { metric: "Delivery reliability", expected_value: "high", evidence: "withdraw_guard enforces delivery confirmation before payment" },
443
+ ],
444
+ risk_appetite: "balanced",
445
+ risk_constraints: {
446
+ require_arbitration: false,
447
+ require_compensation_fund: false,
448
+ require_wip_evidence: false,
449
+ other_constraints: [
450
+ "Allocation escrow required (withdraw_guard + refund_guard)",
451
+ "Service ↔ Guard circular dependency requires 3-step creation pattern",
452
+ ],
453
+ },
454
+ applicable_conditions: {
455
+ business_scale: "small",
456
+ min_daily_orders: 1,
457
+ other_conditions: ["Independent storefront (no marketplace)", "Merchant-managed logistics", "Allocation escrow model"],
458
+ },
459
+ similar_industries: ["retail", "subscription"],
460
+ novel_capabilities: ["Allocation escrow as platform-custody alternative", "Multi-recipient allocation (merchant + processor)"],
461
+ },
376
462
  {
377
463
  name: "general",
378
- display_name: "General 通用",
464
+ display_name: "General",
379
465
  version: "v1",
380
466
  source: "builtin",
381
467
  ...fetchTemplate("general"),
@@ -388,8 +474,8 @@ export const BUILTIN_MODES = [
388
474
  "progress.advance",
389
475
  ],
390
476
  expected_benefits: [
391
- { metric: "灵活性", expected_value: "100%", evidence: "用户自定义所有信任机制参数" },
392
- { metric: "降级安全", expected_value: "可用", evidence: "任意时刻可切换至 general 兜底" },
477
+ { metric: "Flexibility", expected_value: "100%", evidence: "User customizes all trust mechanism parameters" },
478
+ { metric: "Degraded safety", expected_value: "usable", evidence: "Can fall back to general at any time" },
393
479
  ],
394
480
  risk_appetite: "balanced",
395
481
  risk_constraints: {
@@ -399,7 +485,7 @@ export const BUILTIN_MODES = [
399
485
  },
400
486
  applicable_conditions: {
401
487
  business_scale: "small",
402
- other_conditions: ["降级兜底模式", "未被其他行业覆盖的混合场景"],
488
+ other_conditions: ["Fallback degraded mode", "Hybrid scenarios not covered by other industries"],
403
489
  },
404
490
  similar_industries: [],
405
491
  novel_capabilities: [],
@@ -41,6 +41,8 @@ export declare class IndustryModeRegistry {
41
41
  private buildSteps;
42
42
  private defaultScenarios;
43
43
  private recordCapabilitiesUsed;
44
+ private deriveGuardShortName;
45
+ private getFirstServiceGuardName;
44
46
  private makeObject;
45
47
  private registerBuiltinModes;
46
48
  }
@@ -116,7 +116,7 @@ export class IndustryModeRegistry {
116
116
  mode.evolution_history = [{
117
117
  version: mode.version || "v1",
118
118
  changed_at: Date.now(),
119
- changes: ["初始注册(registerUserMode)"],
119
+ changes: ["Initial registration (registerUserMode)"],
120
120
  }];
121
121
  }
122
122
  this.userModes.set(userKey, mode);
@@ -161,7 +161,7 @@ export class IndustryModeRegistry {
161
161
  evolution_history: [{
162
162
  version: "v1",
163
163
  changed_at: Date.now(),
164
- changes: [`从 builtin '${sourceMode}' 派生`],
164
+ changes: [`Derived from builtin '${sourceMode}'`],
165
165
  }],
166
166
  };
167
167
  this.userModes.set(userKey, derived);
@@ -333,22 +333,33 @@ export class IndustryModeRegistry {
333
333
  const objects = [];
334
334
  objects.push(this.makeObject("permission", `${prefix}_permission`, {
335
335
  name: `${prefix}_permission`,
336
- description: `Permission: 角色权限索引(${mode.display_name})`,
336
+ description: `Permission: role permission index (${mode.display_name})`,
337
337
  permission_indexes: this.buildPermissionIndexes(mode),
338
338
  tags: [`industry:${mode.name}`],
339
339
  }));
340
- objects.push(this.makeObject("guard", `${prefix}_guard_buy`, {
341
- name: `${prefix}_guard_buy`,
342
- description: `Guard: 下单验证(${mode.display_name})`,
343
- host: "service",
344
- templates: mode.guards.filter(g => g.host === "service").map(g => g.template_id),
345
- tags: [`industry:${mode.name}`],
346
- }));
340
+ const serviceGuardName = this.getFirstServiceGuardName(mode, prefix);
341
+ for (const guard of mode.guards) {
342
+ const shortName = this.deriveGuardShortName(guard.template_id);
343
+ const guardName = `${prefix}_guard_${shortName}`;
344
+ objects.push(this.makeObject("guard", guardName, {
345
+ name: guardName,
346
+ description: `Guard: ${guard.purpose} (${mode.display_name})`,
347
+ host: guard.host,
348
+ template_id: guard.template_id,
349
+ tags: [`industry:${mode.name}`, `host:${guard.host}`],
350
+ }));
351
+ }
347
352
  objects.push(this.makeObject("machine", `${prefix}_machine`, {
348
353
  name: `${prefix}_machine`,
349
- description: `Machine: 工作流拓扑(${mode.display_name})— ${mode.machine_shape.length} 节点`,
354
+ description: `Machine: workflow topology (${mode.display_name}) — ${mode.machine_shape.length} nodes`,
350
355
  nodes: mode.machine_shape.map(n => ({ name: n.name, role: n.role })),
351
- guard_templates: mode.guards.filter(g => g.host === "machine").map(g => g.template_id),
356
+ guard_objects: mode.guards
357
+ .filter(g => g.host === "machine")
358
+ .map(g => ({
359
+ template_id: g.template_id,
360
+ object_name: `${prefix}_guard_${this.deriveGuardShortName(g.template_id)}`,
361
+ purpose: g.purpose,
362
+ })),
352
363
  permission: `${prefix}_permission`,
353
364
  entry_node_forward_hint: {
354
365
  entry_node_name: mode.machine_shape[0]?.name ?? "paid",
@@ -366,31 +377,32 @@ export class IndustryModeRegistry {
366
377
  }, true));
367
378
  objects.push(this.makeObject("treasury", `${prefix}_treasury`, {
368
379
  name: `${prefix}_treasury`,
369
- description: `Treasury: 资金托管(${mode.display_name})`,
380
+ description: `Treasury: fund escrow (${mode.display_name})`,
370
381
  owner_receive: true,
371
382
  tags: [`industry:${mode.name}`],
372
383
  }));
373
384
  objects.push(this.makeObject("allocation", `${prefix}_allocation`, {
374
385
  name: `${prefix}_allocation`,
375
- description: `Allocation: 分账策略(${mode.display_name})— ${mode.allocator.description}`,
386
+ description: `Allocation: allocation strategy (${mode.display_name}) — ${mode.allocator.description}`,
376
387
  strategy: mode.allocator,
377
388
  treasury: `${prefix}_treasury`,
378
- guard: `${prefix}_guard_buy`,
389
+ guard: serviceGuardName,
379
390
  tags: [`industry:${mode.name}`],
380
391
  }));
381
392
  objects.push(this.makeObject("service", `${prefix}_service`, {
382
393
  name: `${prefix}_service`,
383
- description: `Service: 业务服务(${mode.display_name})— ${intent.slice(0, 100)}`,
394
+ description: `Service: business service (${mode.display_name}) — ${intent.slice(0, 100)}`,
384
395
  machine: `${prefix}_machine`,
385
- buy_guard: `${prefix}_guard_buy`,
396
+ buy_guard: serviceGuardName,
386
397
  permission: `${prefix}_permission`,
387
398
  order_allocators: [`${prefix}_allocation`],
388
399
  compensation_fund_balance: 0,
389
400
  compensation_fund_required: mode.risk_constraints?.require_compensation_fund ?? false,
401
+ compensation_fund_coverage_ratio: mode.risk_constraints?.compensation_fund_coverage_ratio ?? 5,
390
402
  compensation_fund_add_hint: "Call service.compensation_fund_add with a Coin<T> to deposit. " +
391
403
  "The compensation_fund is a Balance<T> (numeric), not a Treasury object reference. " +
392
404
  "Without deposit, arbitration rulings that award refunds to buyers cannot be paid out. " +
393
- "Recommend 5× the max single-order amount (P1-1 evaluation rule).",
405
+ `Recommend ${mode.risk_constraints?.compensation_fund_coverage_ratio ?? 5}× the max single-order amount (P1-1 evaluation rule, industry: ${mode.name}).`,
394
406
  arbitrations: [`${prefix}_arb`],
395
407
  rewards: [`${prefix}_reward`],
396
408
  business_intent: intent,
@@ -399,25 +411,25 @@ export class IndustryModeRegistry {
399
411
  }, true));
400
412
  objects.push(this.makeObject("progress", `${prefix}_progress`, {
401
413
  name: `${prefix}_progress`,
402
- description: `Progress: 订单履约进度(${mode.display_name})`,
414
+ description: `Progress: order fulfillment progress (${mode.display_name})`,
403
415
  parent: `${prefix}_machine`,
404
416
  tags: [`industry:${mode.name}`],
405
417
  }));
406
418
  objects.push(this.makeObject("arb", `${prefix}_arb`, {
407
419
  name: `${prefix}_arb`,
408
- description: `Arbitration: 仲裁规则(${mode.display_name})— ${mode.key_risk}`,
420
+ description: `Arbitration: arbitration rules (${mode.display_name}) — ${mode.key_risk}`,
409
421
  guard: `${prefix}_guard_buy`,
410
422
  tags: [`industry:${mode.name}`],
411
423
  }));
412
424
  objects.push(this.makeObject("reward", `${prefix}_reward`, {
413
425
  name: `${prefix}_reward`,
414
- description: `Reward: 激励规则(${mode.display_name})`,
426
+ description: `Reward: incentive rules (${mode.display_name})`,
415
427
  claim_guard: `${prefix}_guard_buy`,
416
428
  tags: [`industry:${mode.name}`],
417
429
  }));
418
430
  objects.push(this.makeObject("contact", `${prefix}_contact`, {
419
431
  name: `${prefix}_contact`,
420
- description: `Contact: 客服联系(${mode.display_name})`,
432
+ description: `Contact: customer service contact (${mode.display_name})`,
421
433
  tags: [`industry:${mode.name}`],
422
434
  }));
423
435
  return objects;
@@ -501,21 +513,21 @@ export class IndustryModeRegistry {
501
513
  ?? "";
502
514
  const service = find(`${prefix}_service`);
503
515
  const machine = find(`${prefix}_machine`);
504
- const guard = find(`${prefix}_guard_buy`);
505
516
  const permission = find(`${prefix}_permission`);
506
517
  const allocation = find(`${prefix}_allocation`);
507
518
  const treasury = find(`${prefix}_treasury`);
508
519
  const arb = find(`${prefix}_arb`);
509
520
  const reward = find(`${prefix}_reward`);
510
521
  const progress = find(`${prefix}_progress`);
511
- if (!service || !machine || !guard || !permission) {
522
+ const allGuards = objects.filter(o => o.object_type === "guard");
523
+ const serviceGuard = allGuards.find(g => g.config?.host === "service");
524
+ const machineGuards = allGuards.filter(g => g.config?.host === "machine");
525
+ if (!service || !machine || !permission) {
512
526
  const missing = [];
513
527
  if (!service)
514
528
  missing.push("service");
515
529
  if (!machine)
516
530
  missing.push("machine");
517
- if (!guard)
518
- missing.push("guard");
519
531
  if (!permission)
520
532
  missing.push("permission");
521
533
  console.warn(`[buildEdges] Missing core objects: ${missing.join(", ")}. ` +
@@ -524,7 +536,9 @@ export class IndustryModeRegistry {
524
536
  return edges;
525
537
  }
526
538
  edges.push(this.makeEdge(service, machine, "machine", "service.machine", true));
527
- edges.push(this.makeEdge(service, guard, "buy_guard", "service.buy_guard", true));
539
+ if (serviceGuard) {
540
+ edges.push(this.makeEdge(service, serviceGuard, "buy_guard", "service.buy_guard", true));
541
+ }
528
542
  edges.push(this.makeEdge(service, permission, "permission", "service.permission", true));
529
543
  if (allocation)
530
544
  edges.push(this.makeEdge(service, allocation, "order_allocators", "service.order_allocators", true));
@@ -533,12 +547,15 @@ export class IndustryModeRegistry {
533
547
  if (reward)
534
548
  edges.push(this.makeEdge(service, reward, "rewards", "service.rewards", false));
535
549
  edges.push(this.makeEdge(machine, permission, "permission", "machine.permission", false));
550
+ for (const mg of machineGuards) {
551
+ edges.push(this.makeEdge(machine, mg, "guard", "machine.forwards.guard", false));
552
+ }
536
553
  if (progress)
537
554
  edges.push(this.makeEdge(progress, machine, "parent", "progress.parent", false));
538
555
  if (allocation && treasury)
539
556
  edges.push(this.makeEdge(allocation, treasury, "treasury", "allocation.treasury", false));
540
- if (allocation && guard)
541
- edges.push(this.makeEdge(allocation, guard, "buy_guard", "allocation.guard", false));
557
+ if (allocation && serviceGuard)
558
+ edges.push(this.makeEdge(allocation, serviceGuard, "buy_guard", "allocation.guard", false));
542
559
  return edges;
543
560
  }
544
561
  makeEdge(from, to, edge_kind, field_path, required_at_publish) {
@@ -590,7 +607,7 @@ export class IndustryModeRegistry {
590
607
  const service = objects.find(o => o.object_type === "service");
591
608
  return [{
592
609
  scenario_id: `${mode.name}_primary`,
593
- description: `${mode.display_name} 主流程:${intent.slice(0, 80)}`,
610
+ description: `${mode.display_name} main flow: ${intent.slice(0, 80)}`,
594
611
  primary_object: service?.entry_id ?? "",
595
612
  supporting_objects: objects.filter(o => o.object_type !== "service").map(o => o.entry_id),
596
613
  }];
@@ -607,6 +624,22 @@ export class IndustryModeRegistry {
607
624
  catch {
608
625
  }
609
626
  }
627
+ deriveGuardShortName(templateId) {
628
+ if (templateId.startsWith("tpl_")) {
629
+ const parts = templateId.split("_");
630
+ return parts[parts.length - 1] || templateId;
631
+ }
632
+ const match = templateId.match(/^([a-z]+)_guard_/);
633
+ if (match)
634
+ return match[1];
635
+ return templateId.split("_")[0] || templateId;
636
+ }
637
+ getFirstServiceGuardName(mode, prefix) {
638
+ const serviceGuard = mode.guards.find(g => g.host === "service");
639
+ if (!serviceGuard)
640
+ return "";
641
+ return `${prefix}_guard_${this.deriveGuardShortName(serviceGuard.template_id)}`;
642
+ }
610
643
  makeObject(type, name, config, publish_required = false) {
611
644
  return {
612
645
  entry_id: `${type}:${name}`,
@@ -68,6 +68,7 @@ export interface ModeRiskConstraints {
68
68
  require_compensation_fund: boolean;
69
69
  require_wip_evidence: boolean;
70
70
  max_single_transaction?: number;
71
+ compensation_fund_coverage_ratio?: number;
71
72
  other_constraints?: string[];
72
73
  }
73
74
  export interface ModeApplicableConditions {