@wowok/agent-mcp 2.6.3 → 2.6.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (193) hide show
  1. package/README.md +13 -9
  2. package/dist/customer/customer-advice.d.ts +31 -0
  3. package/dist/customer/customer-advice.js +129 -0
  4. package/dist/customer/index.d.ts +2 -0
  5. package/dist/customer/index.js +2 -0
  6. package/dist/customer/info-puzzle.d.ts +8 -1
  7. package/dist/customer/info-puzzle.js +30 -5
  8. package/dist/customer/order-monitor.d.ts +2 -0
  9. package/dist/customer/order-monitor.js +3 -2
  10. package/dist/customer/post-purchase.d.ts +2 -0
  11. package/dist/customer/post-purchase.js +6 -5
  12. package/dist/customer/preorder-compare.d.ts +24 -0
  13. package/dist/customer/preorder-compare.js +34 -0
  14. package/dist/customer/reminder-system.d.ts +2 -0
  15. package/dist/customer/reminder-system.js +2 -1
  16. package/dist/customer/risk-assessment.js +4 -3
  17. package/dist/customer/types.d.ts +5 -0
  18. package/dist/examples/arbitration-dispute-create.json +41 -0
  19. package/dist/examples/arbitration-vote-weighted.json +35 -0
  20. package/dist/examples/arbitration-voting-guard-add.json +38 -0
  21. package/dist/examples/demand-present-service.json +33 -0
  22. package/dist/examples/gen-passport-verify-guard.json +48 -0
  23. package/dist/examples/guard-template-balance-check.json +36 -15
  24. package/dist/examples/guard-template-time-lock.json +33 -12
  25. package/dist/examples/insurance-guard-claim-timelock.json +75 -0
  26. package/dist/examples/insurance-guard-withdraw-allocation.json +96 -0
  27. package/dist/examples/insurance-machine-create-publish.json +75 -0
  28. package/dist/examples/insurance-service-allocators-publish.json +56 -0
  29. package/dist/examples/machine-multisig-threshold.json +86 -0
  30. package/dist/examples/machine-template-7node-rental.json +99 -94
  31. package/dist/examples/payment-scenario-bound.json +45 -0
  32. package/dist/examples/rental-ziroom-machine-create.json +126 -114
  33. package/dist/examples/rental-ziroom-permission-create.json +10 -3
  34. package/dist/examples/rental-ziroom-service-create.json +27 -18
  35. package/dist/examples/retail-adv-guard-customer-win-create.json +80 -0
  36. package/dist/examples/retail-adv-guard-messenger-proof-create.json +65 -0
  37. package/dist/examples/retail-adv-guard-reward-timeout-create.json +92 -0
  38. package/dist/examples/retail-adv-reward-guard-add.json +51 -0
  39. package/dist/examples/retail-myshop-allocation-activate.json +55 -0
  40. package/dist/examples/retail-myshop-arbitration-create.json +40 -0
  41. package/dist/examples/retail-myshop-contact-create.json +43 -0
  42. package/dist/examples/retail-myshop-order-create.json +56 -0
  43. package/dist/examples/retail-myshop-progress-operate.json +38 -0
  44. package/dist/examples/retail-myshop-reward-create.json +35 -0
  45. package/dist/examples/service-discount-issue.json +46 -0
  46. package/dist/examples/threebody-guard-create.json +56 -0
  47. package/dist/examples/threebody-machine-create.json +72 -0
  48. package/dist/examples/threebody-permission-create.json +38 -0
  49. package/dist/examples/threebody-service-allocators.json +49 -0
  50. package/dist/examples/travel-guard-time-lock.json +69 -0
  51. package/dist/examples/travel-guard-weather-oracle.json +70 -0
  52. package/dist/examples/travel-machine-create.json +136 -0
  53. package/dist/examples/travel-repository-create.json +47 -0
  54. package/dist/examples/travel-service-create.json +102 -0
  55. package/dist/examples/travel-treasury-create.json +34 -0
  56. package/dist/examples/treasury-deposit.json +37 -0
  57. package/dist/examples/treasury-withdraw.json +38 -0
  58. package/dist/extensions/business-modules.d.ts +49 -0
  59. package/dist/extensions/business-modules.js +287 -0
  60. package/dist/extensions/capability-manifest.js +192 -5
  61. package/dist/extensions/constraint-registry.js +3 -1
  62. package/dist/extensions/modes.js +10 -4
  63. package/dist/extensions/registry.d.ts +14 -9
  64. package/dist/extensions/registry.js +69 -14
  65. package/dist/extensions/types.d.ts +1 -0
  66. package/dist/knowledge/fund-layer.d.ts +67 -1
  67. package/dist/knowledge/fund-layer.js +561 -12
  68. package/dist/knowledge/guard-templates.d.ts +10 -0
  69. package/dist/knowledge/guard-templates.js +50 -0
  70. package/dist/knowledge/index.d.ts +2 -2
  71. package/dist/knowledge/index.js +2 -2
  72. package/dist/knowledge/machine-risk.js +4 -1
  73. package/dist/knowledge/progress-context.js +1 -1
  74. package/dist/knowledge/progress-ledger.js +3 -3
  75. package/dist/knowledge/progress-templates.js +1 -1
  76. package/dist/knowledge/progress-translation.js +1 -1
  77. package/dist/knowledge/safety-rules.d.ts +83 -1
  78. package/dist/knowledge/safety-rules.js +166 -2
  79. package/dist/knowledge/scenario-modes.d.ts +1 -1
  80. package/dist/knowledge/scenario-modes.js +13 -11
  81. package/dist/knowledge/template-registry.d.ts +48 -0
  82. package/dist/knowledge/template-registry.js +341 -0
  83. package/dist/knowledge/tool-constraints.js +6 -6
  84. package/dist/knowledge/tools-reference.js +11 -8
  85. package/dist/participation/merchant-interest.d.ts +32 -0
  86. package/dist/participation/merchant-interest.js +100 -0
  87. package/dist/participation/radar-core.d.ts +104 -0
  88. package/dist/participation/radar-core.js +269 -0
  89. package/dist/project/context-assembly.js +8 -0
  90. package/dist/project/edit-planner.js +27 -56
  91. package/dist/project/evaluation.d.ts +36 -0
  92. package/dist/project/evaluation.js +422 -56
  93. package/dist/project/game-theory.d.ts +43 -0
  94. package/dist/project/game-theory.js +177 -0
  95. package/dist/project/graph-builder.js +1 -0
  96. package/dist/project/handlers.d.ts +38 -0
  97. package/dist/project/handlers.js +65 -35
  98. package/dist/project/intent-analyzer.d.ts +71 -0
  99. package/dist/project/intent-analyzer.js +149 -0
  100. package/dist/project/machine-nodes.d.ts +2 -0
  101. package/dist/project/machine-nodes.js +36 -0
  102. package/dist/project/merchant-guide.d.ts +165 -0
  103. package/dist/project/merchant-guide.js +264 -0
  104. package/dist/project/mode-actions.d.ts +199 -0
  105. package/dist/project/mode-actions.js +309 -0
  106. package/dist/project/participation-radar.d.ts +18 -0
  107. package/dist/project/participation-radar.js +428 -0
  108. package/dist/project/pipeline-actions.d.ts +101 -0
  109. package/dist/project/pipeline-actions.js +109 -0
  110. package/dist/project/semantic-graph.d.ts +95 -0
  111. package/dist/project/semantic-graph.js +245 -0
  112. package/dist/schema/call/allocation.d.ts +11 -11
  113. package/dist/schema/call/allocation.js +11 -1
  114. package/dist/schema/call/arbitration.d.ts +21 -21
  115. package/dist/schema/call/arbitration.js +17 -9
  116. package/dist/schema/call/base.d.ts +2 -2
  117. package/dist/schema/call/base.js +1 -1
  118. package/dist/schema/call/bridge.d.ts +127 -127
  119. package/dist/schema/call/bridge.js +12 -12
  120. package/dist/schema/call/contact.d.ts +3 -3
  121. package/dist/schema/call/demand.d.ts +3 -3
  122. package/dist/schema/call/guard.d.ts +11 -11
  123. package/dist/schema/call/guard.js +1 -1
  124. package/dist/schema/call/machine.d.ts +216 -21
  125. package/dist/schema/call/machine.js +1 -1
  126. package/dist/schema/call/order.d.ts +7 -7
  127. package/dist/schema/call/payment.d.ts +3 -3
  128. package/dist/schema/call/permission.d.ts +3 -3
  129. package/dist/schema/call/personal.d.ts +337 -3
  130. package/dist/schema/call/personal.js +10 -0
  131. package/dist/schema/call/progress.d.ts +177 -9
  132. package/dist/schema/call/progress.js +7 -3
  133. package/dist/schema/call/proof.d.ts +6 -6
  134. package/dist/schema/call/repository.d.ts +3 -3
  135. package/dist/schema/call/reward.d.ts +57 -57
  136. package/dist/schema/call/semantic.js +41 -1
  137. package/dist/schema/call/service.d.ts +114 -114
  138. package/dist/schema/call/service.js +11 -2
  139. package/dist/schema/call/treasury.d.ts +57 -57
  140. package/dist/schema/messenger/index.js +4 -1
  141. package/dist/schema/operations.d.ts +713 -291
  142. package/dist/schema/operations.js +33 -0
  143. package/dist/schema/project/index.d.ts +4635 -100
  144. package/dist/schema/project/index.js +868 -1
  145. package/dist/schema/query/index.d.ts +363 -19
  146. package/dist/schema/query/index.js +25 -3
  147. package/dist/schema/schema-query/index.d.ts +13 -7
  148. package/dist/schema/schema-query/index.js +29 -5
  149. package/dist/schema/trust/index.d.ts +1012 -6
  150. package/dist/schema/trust/index.js +212 -11
  151. package/dist/schema/utils/skills-recommendation.js +1 -0
  152. package/dist/schema-query/index.d.ts +4 -1
  153. package/dist/schema-query/index.js +255 -1
  154. package/dist/schemas/bridge_operation.schema.json +14 -7
  155. package/dist/schemas/guard2file.schema.json +2 -0
  156. package/dist/schemas/index.json +1 -1
  157. package/dist/schemas/machineNode2file.schema.json +2 -0
  158. package/dist/schemas/messenger_operation.schema.json +1 -1
  159. package/dist/schemas/onchain_operations.schema.json +143 -15
  160. package/dist/schemas/onchain_operations_allocation.schema.json +2 -1
  161. package/dist/schemas/onchain_operations_arbitration.schema.json +7 -5
  162. package/dist/schemas/onchain_operations_contact.schema.json +1 -0
  163. package/dist/schemas/onchain_operations_demand.schema.json +1 -0
  164. package/dist/schemas/onchain_operations_gen_passport.schema.json +2 -0
  165. package/dist/schemas/onchain_operations_gen_proof.schema.json +2 -0
  166. package/dist/schemas/onchain_operations_guard.schema.json +578 -0
  167. package/dist/schemas/onchain_operations_machine.schema.json +1 -0
  168. package/dist/schemas/onchain_operations_order.schema.json +4 -3
  169. package/dist/schemas/onchain_operations_payment.schema.json +1 -0
  170. package/dist/schemas/onchain_operations_permission.schema.json +1 -0
  171. package/dist/schemas/onchain_operations_personal.schema.json +37 -0
  172. package/dist/schemas/onchain_operations_progress.schema.json +90 -3
  173. package/dist/schemas/onchain_operations_proof.schema.json +1 -0
  174. package/dist/schemas/onchain_operations_repository.schema.json +1 -0
  175. package/dist/schemas/onchain_operations_reward.schema.json +1 -0
  176. package/dist/schemas/onchain_operations_service.schema.json +4 -3
  177. package/dist/schemas/onchain_operations_treasury.schema.json +1 -0
  178. package/dist/schemas/project_operation.output.json +2243 -1
  179. package/dist/schemas/project_operation.schema.json +683 -1
  180. package/dist/schemas/query_toolkit.output.json +1 -1
  181. package/dist/schemas/query_toolkit.schema.json +37 -0
  182. package/dist/schemas/schema_query.output.json +1 -1
  183. package/dist/schemas/schema_query.schema.json +30 -5
  184. package/dist/schemas/trust_score.output.json +392 -1
  185. package/dist/schemas/trust_score.schema.json +275 -1
  186. package/dist/tools/handlers/onchain.js +73 -8
  187. package/dist/tools/handlers/project.js +46 -0
  188. package/dist/tools/handlers/query.js +117 -2
  189. package/dist/tools/handlers/schema-query.js +41 -0
  190. package/dist/tools/handlers/trust.js +192 -6
  191. package/dist/tools/index.js +52 -9
  192. package/dist/tools/wrap.js +194 -15
  193. package/package.json +2 -2
@@ -0,0 +1,177 @@
1
+ export const GAME_THEORY_CONSTRAINTS = [
2
+ {
3
+ scenario: "merchant_may_deliver_late",
4
+ conflict: "Merchant incentive: collect payment fast, deliver at own pace (or never). User bears schedule risk with no leverage once funds leave their wallet.",
5
+ userProtection: {
6
+ mechanism: "Milestone escrow — funds locked in Order, released per verified milestone",
7
+ object: "Order + Allocation",
8
+ guard: "milestone forward guard verifies deliverable before release",
9
+ },
10
+ merchantConstraint: {
11
+ requiredDeposit: true,
12
+ timeoutPenalty: "compensation_fund covers refund for unstarted milestones",
13
+ },
14
+ evaluationMetric: "timeout_protection",
15
+ mitigationSignals: [
16
+ ["edge:has_order_allocators", "node:main_machine"],
17
+ ["module:milestone_escrow"],
18
+ ],
19
+ mitigatingModules: ["milestone_escrow", "refund_guarantee"],
20
+ recommendation: "Adopt milestone_escrow module: bind order_allocators + Machine so funds release only per verified milestone. Add compensation_fund for late-delivery refunds.",
21
+ },
22
+ {
23
+ scenario: "merchant_may_abandon",
24
+ conflict: "Merchant incentive: maximize intake then abandon the service (exit scam). User has no recourse without locked funds or deposit.",
25
+ userProtection: {
26
+ mechanism: "Escrow + compensation fund — user refunds from on-chain fund even if merchant vanishes",
27
+ object: "Service.compensation_fund + Order",
28
+ guard: "refund_guard validates claim conditions",
29
+ },
30
+ merchantConstraint: {
31
+ requiredDeposit: true,
32
+ requiredArbitration: true,
33
+ },
34
+ evaluationMetric: "escrow_quality",
35
+ mitigationSignals: [
36
+ ["edge:has_order_allocators", "module:refund_guarantee"],
37
+ ["module:refund_guarantee", "node:main_arbitration"],
38
+ ],
39
+ mitigatingModules: ["refund_guarantee", "milestone_escrow", "reputation_on_chain"],
40
+ recommendation: "Adopt refund_guarantee module: compensation_fund_add > 0 with refund_guard. Escrow via order_allocators prevents merchant from touching funds before delivery.",
41
+ },
42
+ {
43
+ scenario: "customer_may_deny_acceptance",
44
+ conflict: "Customer incentive: withhold acceptance confirmation to delay payment indefinitely while using the deliverable. Merchant's funds stay locked.",
45
+ userProtection: {
46
+ mechanism: "Accept timeout — after N days without response, order auto-advances (adminUnhold) and merchant gets paid",
47
+ object: "Machine forward + Progress",
48
+ guard: "time_guard on accept forward",
49
+ },
50
+ merchantConstraint: {
51
+ timeoutPenalty: "user silence past timeout = implicit acceptance",
52
+ },
53
+ evaluationMetric: "timeout_protection",
54
+ mitigationSignals: [
55
+ ["module:accept_timeout_protection"],
56
+ ["node:guard_accept_timeout_protection"],
57
+ ],
58
+ mitigatingModules: ["accept_timeout_protection"],
59
+ recommendation: "Adopt accept_timeout_protection module: time_guard on the accept forward (e.g. 7 days) + PROGRESS_UNHOLD permission so the workflow auto-advances on customer silence.",
60
+ },
61
+ {
62
+ scenario: "customer_may_false_claim",
63
+ conflict: "Customer incentive: claim non-delivery or defect to obtain refund while keeping the goods/service. Merchant loses both deliverable and payment.",
64
+ userProtection: {
65
+ mechanism: "WIP provenance — delivery hash committed on-chain before/at delivery; independent arbitration verifies evidence",
66
+ object: "Repository + Arbitration",
67
+ guard: "Guard compares proof.signer/proof.time against committed WIP hash",
68
+ },
69
+ merchantConstraint: {
70
+ requiredProof: "wip_hash committed to Repository before fund release",
71
+ requiredArbitration: true,
72
+ },
73
+ evaluationMetric: "proof_integrity",
74
+ mitigationSignals: [
75
+ ["node:main_repository", "node:main_arbitration"],
76
+ ["module:wip_provenance", "node:main_arbitration"],
77
+ ],
78
+ mitigatingModules: ["wip_provenance", "independent_arbitration", "damage_attestation"],
79
+ recommendation: "Adopt wip_provenance + independent_arbitration modules: Repository stores WIP hashes as tamper-proof delivery evidence; Arbitration (independent Permission) resolves false claims against on-chain proof.",
80
+ },
81
+ {
82
+ scenario: "supplier_may_not_deliver",
83
+ conflict: "Supplier incentive: accept sub-order payment terms then under-deliver, leaving the merchant liable to the end customer. Multi-party opacity hides the failure point.",
84
+ userProtection: {
85
+ mechanism: "Supplier visibility — Demand + sub-order flow with multi-tier Allocation; each tier paid only on its own verified delivery",
86
+ object: "Demand + Allocation (multi-tier)",
87
+ guard: "per-tier release guard",
88
+ },
89
+ merchantConstraint: {
90
+ requiredProof: "sub-delivery proof per Allocation tier",
91
+ },
92
+ evaluationMetric: "supplier_visibility",
93
+ mitigationSignals: [
94
+ ["module:supplier_collaboration"],
95
+ ["module:multi_tier_allocation"],
96
+ ],
97
+ mitigatingModules: ["supplier_collaboration", "multi_tier_allocation"],
98
+ recommendation: "Adopt supplier_collaboration module: publish Demand referencing the main Service, split Allocation across tiers so each supplier is paid only for verified sub-delivery.",
99
+ },
100
+ ];
101
+ function evalSignal(token, graph, intent) {
102
+ const [kind, value] = token.split(":", 2);
103
+ switch (kind) {
104
+ case "node":
105
+ return graph.nodes.some((n) => n.id === value);
106
+ case "edge":
107
+ return graph.edges.some((e) => e.relation === value);
108
+ case "module":
109
+ return graph.adoptedModules.includes(value);
110
+ case "type":
111
+ return graph.nodes.some((n) => n.type === value);
112
+ case "trust": {
113
+ const v = intent.trust;
114
+ return v[value] === true || (typeof v[value] === "string" && v[value] !== "none");
115
+ }
116
+ default:
117
+ return false;
118
+ }
119
+ }
120
+ export function checkGameTheoryConstraints(graph, intent) {
121
+ const results = [];
122
+ for (const c of GAME_THEORY_CONSTRAINTS) {
123
+ let matched = null;
124
+ let bestPartial = [];
125
+ let bestPartialScore = -1;
126
+ for (const group of c.mitigationSignals) {
127
+ const hits = group.filter((s) => evalSignal(s, graph, intent));
128
+ if (hits.length === group.length) {
129
+ matched = group;
130
+ break;
131
+ }
132
+ const score = hits.length / group.length;
133
+ if (hits.length > 0 && score > bestPartialScore) {
134
+ bestPartialScore = score;
135
+ bestPartial = hits;
136
+ }
137
+ }
138
+ results.push({
139
+ scenario: c.scenario,
140
+ conflict: c.conflict,
141
+ covered: matched !== null,
142
+ matchedSignals: matched ?? [],
143
+ partialSignals: matched ? [] : bestPartial,
144
+ userProtection: `${c.userProtection.mechanism} (${c.userProtection.object}${c.userProtection.guard ? `, guard: ${c.userProtection.guard}` : ""})`,
145
+ evaluationMetric: c.evaluationMetric,
146
+ recommendation: matched ? undefined : c.recommendation,
147
+ });
148
+ }
149
+ const covered = results.filter((r) => r.covered);
150
+ const exposed = results.filter((r) => !r.covered);
151
+ const wowAlignments = [];
152
+ if (graph.edges.some((e) => e.relation === "has_order_allocators")) {
153
+ wowAlignments.push("Milestone escrow: funds locked in Order, released per verified milestone — merchant paid for delivery, user pays for value");
154
+ }
155
+ if (graph.adoptedModules.includes("accept_timeout_protection")) {
156
+ wowAlignments.push("Accept timeout: customer silence past N days = implicit acceptance — merchant protected from payment stalling");
157
+ }
158
+ if (graph.nodes.some((n) => n.id === "main_repository")) {
159
+ wowAlignments.push("WIP provenance: delivery hash on-chain — false claims verifiable against tamper-proof evidence");
160
+ }
161
+ if (graph.nodes.some((n) => n.id === "main_arbitration")) {
162
+ wowAlignments.push("Micro-arbitration: Guard-weighted voting with independent Permission — low-cost dispute resolution without platform fees");
163
+ }
164
+ if (graph.adoptedModules.includes("reputation_on_chain")) {
165
+ wowAlignments.push("On-chain reputation: both sides' behavior permanently recorded — future transactions price the risk");
166
+ }
167
+ return {
168
+ results,
169
+ coveredCount: covered.length,
170
+ totalCount: results.length,
171
+ exposedScenarios: exposed.map((r) => r.scenario),
172
+ wowAlignments,
173
+ summary: exposed.length === 0
174
+ ? `All ${results.length} adversarial scenarios have on-chain mitigations.`
175
+ : `${exposed.length}/${results.length} adversarial scenarios EXPOSED: ${exposed.map((r) => r.scenario).join(", ")}. Apply the recommendations to align incentives.`,
176
+ };
177
+ }
@@ -259,6 +259,7 @@ const EXPECTED_RELATIONSHIPS = new Map([
259
259
  ["Demand", [
260
260
  { targetType: "Guard", fieldName: "guard", relationshipType: "validate" },
261
261
  { targetType: "Reward", fieldName: "rewards", relationshipType: "trigger" },
262
+ { targetType: "Permission", fieldName: "permission", relationshipType: "validate", single: true },
262
263
  { targetType: "Contact", fieldName: "um", relationshipType: "bind", single: true },
263
264
  ]],
264
265
  ["Treasury", [
@@ -30,6 +30,7 @@ export declare function handleCreateProject(v: ProjectInput): Promise<{
30
30
  action: "create_project";
31
31
  project: import("@wowok/wowok").Project;
32
32
  blueprint: {
33
+ industry_mismatch_hint?: string | undefined;
33
34
  objects_count: number;
34
35
  edges_count: number;
35
36
  industry_source: string;
@@ -37,6 +38,15 @@ export declare function handleCreateProject(v: ProjectInput): Promise<{
37
38
  steps_count: number;
38
39
  scenarios_count: number;
39
40
  key_risk: string | undefined;
41
+ intent_inference: {
42
+ traits: import("../knowledge/industry-registry.js").IndustryTraits;
43
+ confidence: number;
44
+ matched_keywords: string[];
45
+ top_matches: {
46
+ industry: string;
47
+ similarity: number;
48
+ }[];
49
+ };
40
50
  };
41
51
  recommended_creation_order: {
42
52
  step: number;
@@ -47,6 +57,7 @@ export declare function handleCreateProject(v: ProjectInput): Promise<{
47
57
  blueprint_warning?: undefined;
48
58
  blueprint_skipped?: undefined;
49
59
  hint?: undefined;
60
+ recommended_industries?: undefined;
50
61
  } | {
51
62
  action: "create_project";
52
63
  project: import("@wowok/wowok").Project;
@@ -60,6 +71,7 @@ export declare function handleCreateProject(v: ProjectInput): Promise<{
60
71
  blueprint?: undefined;
61
72
  blueprint_skipped?: undefined;
62
73
  hint?: undefined;
74
+ recommended_industries?: undefined;
63
75
  } | {
64
76
  action: "create_project";
65
77
  project: import("@wowok/wowok").Project;
@@ -73,6 +85,31 @@ export declare function handleCreateProject(v: ProjectInput): Promise<{
73
85
  }[];
74
86
  blueprint?: undefined;
75
87
  blueprint_warning?: undefined;
88
+ recommended_industries?: undefined;
89
+ } | {
90
+ action: "create_project";
91
+ project: import("@wowok/wowok").Project;
92
+ recommended_creation_order: {
93
+ step: number;
94
+ object: string;
95
+ reason: string;
96
+ required: boolean;
97
+ }[];
98
+ recommended_industries: {
99
+ industry: string;
100
+ similarity: number;
101
+ matched_traits: string[];
102
+ reference_examples: {
103
+ file: string;
104
+ title: string;
105
+ operation_type: string;
106
+ verified: boolean;
107
+ }[];
108
+ }[];
109
+ hint: string;
110
+ blueprint?: undefined;
111
+ blueprint_warning?: undefined;
112
+ blueprint_skipped?: undefined;
76
113
  } | {
77
114
  action: "create_project";
78
115
  project: import("@wowok/wowok").Project;
@@ -86,6 +123,7 @@ export declare function handleCreateProject(v: ProjectInput): Promise<{
86
123
  blueprint_warning?: undefined;
87
124
  blueprint_skipped?: undefined;
88
125
  hint?: undefined;
126
+ recommended_industries?: undefined;
89
127
  }>;
90
128
  export declare function handleCreateProjectFromOnchain(v: ProjectInput): Promise<{
91
129
  action: "create_project_from_onchain";
@@ -1,10 +1,12 @@
1
- import { LocalProject, LocalMark, query_objects, query_table, } from "@wowok/wowok";
1
+ import { LocalProject, LocalMark, query_objects, } from "@wowok/wowok";
2
+ import { fetchMachineNodes } from "./machine-nodes.js";
2
3
  import { GraphBuilder } from "./graph-builder.js";
3
4
  import { SemanticAssembler } from "./semantic-assembler.js";
4
5
  import { runEvaluation, compareProjects, } from "./evaluation.js";
5
6
  import { TaskTracker } from "./task-tracker.js";
6
7
  import { renderGuardMermaid, renderGuardTreeIndented, renderGuardAscii, renderGuardMarkmap, } from "../knowledge/guard-render.js";
7
8
  import { renderMachineMermaid, renderMachineTreeIndented, renderMachineAscii, renderMachineMarkmap, } from "../knowledge/machine-render.js";
9
+ import { inferTraitsFromDescription, findSimilarIndustries, } from "../knowledge/industry-generalizer.js";
8
10
  import { isObjectOfType } from "../schema/utils/object-type-utils.js";
9
11
  const localProject = LocalProject.Instance();
10
12
  function requireField(value, name) {
@@ -169,7 +171,28 @@ export async function handleCreateProject(v) {
169
171
  business_intent: v.project_description ?? name,
170
172
  industry,
171
173
  };
172
- const blueprint = registry.applyTemplate(industry, context.business_intent, context);
174
+ const blueprint = await registry.applyTemplate(industry, context.business_intent, context);
175
+ const intentInference = inferTraitsFromDescription(context.business_intent);
176
+ const industryMatches = findSimilarIndustries(intentInference.traits, 3);
177
+ const intentInferenceSummary = {
178
+ traits: intentInference.traits,
179
+ confidence: intentInference.confidence,
180
+ matched_keywords: intentInference.matched_keywords,
181
+ top_matches: industryMatches.map((m) => ({
182
+ industry: m.industry,
183
+ similarity: m.similarity,
184
+ })),
185
+ };
186
+ const topMatch = industryMatches[0];
187
+ const industryMismatchHint = topMatch &&
188
+ !industryMatches.some((m) => m.industry === industry) &&
189
+ intentInference.confidence >= 0.3 &&
190
+ topMatch.similarity >= 0.6
191
+ ? `Intent inference suggests industry '${topMatch.industry}' ` +
192
+ `(similarity ${(topMatch.similarity * 100).toFixed(0)}%) may fit the description ` +
193
+ `better than the chosen '${industry}'. Call action='recommend_industry' for the full ` +
194
+ `recommendation chain, or ignore this hint if '${industry}' was chosen intentionally.`
195
+ : undefined;
173
196
  const draftObjects = [];
174
197
  for (const obj of blueprint.objects) {
175
198
  const projectObj = await localProject.addObject(project.id, {
@@ -203,6 +226,20 @@ export async function handleCreateProject(v) {
203
226
  },
204
227
  }));
205
228
  await localProject.saveGraphEdges(project.id, graphEdges);
229
+ try {
230
+ await localProject.saveDocument(project.id, context.network, JSON.stringify({
231
+ applied_template: blueprint.applied_template,
232
+ industry_source: blueprint.industry_source,
233
+ steps: blueprint.steps,
234
+ scenarios: blueprint.scenarios ?? [],
235
+ validation: blueprint.validation,
236
+ intent_inference: intentInferenceSummary,
237
+ generated_at: new Date().toISOString(),
238
+ }, null, 2), "blueprint");
239
+ }
240
+ catch (docErr) {
241
+ console.warn(`[create_project] Failed to persist blueprint document: ${docErr.message}`);
242
+ }
206
243
  return {
207
244
  action: "create_project",
208
245
  project,
@@ -214,6 +251,8 @@ export async function handleCreateProject(v) {
214
251
  steps_count: blueprint.steps.length,
215
252
  scenarios_count: blueprint.scenarios?.length ?? 0,
216
253
  key_risk: registry.getMode(industry)?.key_risk,
254
+ intent_inference: intentInferenceSummary,
255
+ ...(industryMismatchHint ? { industry_mismatch_hint: industryMismatchHint } : {}),
217
256
  },
218
257
  recommended_creation_order: getRecommendedCreationOrder(industry),
219
258
  };
@@ -236,6 +275,29 @@ export async function handleCreateProject(v) {
236
275
  recommended_creation_order: getRecommendedCreationOrder(industry),
237
276
  };
238
277
  }
278
+ if (!industry) {
279
+ const intentText = (v.project_description ?? name).trim();
280
+ if (intentText) {
281
+ try {
282
+ const { handleRecommendIndustry } = await import("./mode-actions.js");
283
+ const rec = handleRecommendIndustry({ intent: intentText });
284
+ if (rec.recommendations.length > 0) {
285
+ return {
286
+ action: "create_project",
287
+ project,
288
+ recommended_creation_order: getRecommendedCreationOrder(industry),
289
+ recommended_industries: rec.recommendations,
290
+ hint: "No industry specified. Based on your description, top match is '" +
291
+ rec.recommendations[0].industry + "'. To get a ready-made blueprint " +
292
+ "(~10 draft objects + graph edges), recreate with project_industry set — " +
293
+ "or continue from scratch with add_object.",
294
+ };
295
+ }
296
+ }
297
+ catch {
298
+ }
299
+ }
300
+ }
239
301
  return {
240
302
  action: "create_project",
241
303
  project,
@@ -1247,39 +1309,7 @@ export async function handleGetMachineGraph(v) {
1247
1309
  const edgeList = [];
1248
1310
  let rawNodes = [];
1249
1311
  try {
1250
- const allFieldObjectIds = [];
1251
- let cursor = undefined;
1252
- for (;;) {
1253
- const tableResult = await query_table({
1254
- parent: machineAddress,
1255
- cursor: cursor ?? undefined,
1256
- network,
1257
- });
1258
- if (!tableResult?.items || tableResult.items.length === 0)
1259
- break;
1260
- for (const item of tableResult.items) {
1261
- if (item.object)
1262
- allFieldObjectIds.push(item.object);
1263
- }
1264
- if (!tableResult.hasNextPage || !tableResult.nextCursor)
1265
- break;
1266
- cursor = tableResult.nextCursor;
1267
- }
1268
- if (allFieldObjectIds.length > 0) {
1269
- const BATCH = 50;
1270
- for (let i = 0; i < allFieldObjectIds.length; i += BATCH) {
1271
- const batch = allFieldObjectIds.slice(i, i + BATCH);
1272
- const nodeQueryResult = await query_objects({
1273
- objects: batch,
1274
- network,
1275
- });
1276
- for (const obj of nodeQueryResult?.objects ?? []) {
1277
- if (obj.type === "TableItem_MachineNode") {
1278
- rawNodes.push(obj);
1279
- }
1280
- }
1281
- }
1282
- }
1312
+ rawNodes = await fetchMachineNodes(machineAddress, network);
1283
1313
  }
1284
1314
  catch (e) {
1285
1315
  throw new Error(`Failed to query Machine nodes on ${network}: ${e instanceof Error ? e.message : String(e)}`);
@@ -0,0 +1,71 @@
1
+ import type { IndustryTraits } from "../knowledge/industry-registry.js";
2
+ export type BusinessIntentType = "sell_service" | "sell_product" | "sell_subscription" | "rent_asset" | "crowdfund" | "escrow";
3
+ export interface RoleDefinition {
4
+ name: string;
5
+ description: string;
6
+ obligations: string[];
7
+ rights: string[];
8
+ }
9
+ export interface DeliverableDefinition {
10
+ name: string;
11
+ type: "digital" | "physical" | "service_session" | "access_right";
12
+ acceptanceCriteria: string;
13
+ proofOfDelivery: "manual_confirm" | "wip_hash" | "third_party_attestation" | "auto_verify";
14
+ }
15
+ export interface PaymentTrigger {
16
+ event: string;
17
+ guardDescription: string;
18
+ }
19
+ export interface PaymentAllocation {
20
+ recipient: string;
21
+ percentage: number;
22
+ }
23
+ export interface PaymentIntent {
24
+ model: "milestone" | "upfront" | "subscription" | "per_use" | "escrow";
25
+ currency: string;
26
+ triggers: PaymentTrigger[];
27
+ allocation?: PaymentAllocation[];
28
+ }
29
+ export interface TrustIntent {
30
+ refundPolicy: "no_refund" | "partial" | "full" | "milestone_prorated";
31
+ arbitration: "none" | "merchant_pick" | "mutual_pick" | "third_party";
32
+ escrow: boolean;
33
+ transparency: "minimal" | "standard" | "full";
34
+ }
35
+ export interface TimelineMilestone {
36
+ name: string;
37
+ description: string;
38
+ duration: string;
39
+ }
40
+ export interface TimelineIntent {
41
+ totalDuration?: string;
42
+ milestones?: TimelineMilestone[];
43
+ }
44
+ export interface BusinessIntent {
45
+ intent: BusinessIntentType;
46
+ industry?: string;
47
+ description: string;
48
+ roles: {
49
+ merchant: RoleDefinition;
50
+ customer: RoleDefinition;
51
+ suppliers?: RoleDefinition[];
52
+ arbitrators?: RoleDefinition;
53
+ };
54
+ deliverables: DeliverableDefinition[];
55
+ payment: PaymentIntent;
56
+ trust: TrustIntent;
57
+ timeline?: TimelineIntent;
58
+ }
59
+ export interface IntentAnalysisResult {
60
+ intent: BusinessIntent;
61
+ inferredIndustry: string;
62
+ industryConfidence: number;
63
+ similarIndustries: string[];
64
+ inferredTraits: IndustryTraits;
65
+ recommendedModules: string[];
66
+ warnings: string[];
67
+ }
68
+ export declare function analyzeIntent(description: string, options?: {
69
+ preferredIndustry?: string;
70
+ currency?: string;
71
+ }): Promise<IntentAnalysisResult>;
@@ -0,0 +1,149 @@
1
+ import { findSimilarIndustries, inferTraitsFromDescription } from "../knowledge/industry-generalizer.js";
2
+ const INTENT_KEYWORDS = {
3
+ sell_service: ["design", "develop", "consult", "freelance", "service", "build", "create", "write", "translate"],
4
+ sell_product: ["sell", "product", "item", "goods", "merchandise", "store", "shop"],
5
+ sell_subscription: ["subscribe", "subscription", "membership", "monthly", "recurring", "creator", "patron"],
6
+ rent_asset: ["rent", "rental", "lease", "borrow", "car", "house", "apartment", "equipment"],
7
+ crowdfund: ["crowdfund", "fund", "raise", "campaign", "donation", "backer"],
8
+ escrow: ["escrow", "hold", "mediate", "intermediary", "safe", "secure transaction"],
9
+ };
10
+ function classifyIntentType(description) {
11
+ const lower = description.toLowerCase();
12
+ let bestType = "sell_service";
13
+ let bestScore = 0;
14
+ for (const [type, keywords] of Object.entries(INTENT_KEYWORDS)) {
15
+ const score = keywords.filter((k) => lower.includes(k)).length;
16
+ if (score > bestScore) {
17
+ bestScore = score;
18
+ bestType = type;
19
+ }
20
+ }
21
+ return bestType;
22
+ }
23
+ function inferPaymentModel(description) {
24
+ const lower = description.toLowerCase();
25
+ if (lower.includes("milestone") || lower.includes("phase") || lower.includes("stage"))
26
+ return "milestone";
27
+ if (lower.includes("subscription") || lower.includes("monthly") || lower.includes("recurring"))
28
+ return "subscription";
29
+ if (lower.includes("per use") || lower.includes("hourly") || lower.includes("per session"))
30
+ return "per_use";
31
+ if (lower.includes("escrow") || lower.includes("hold"))
32
+ return "escrow";
33
+ return "upfront";
34
+ }
35
+ function inferRefundPolicy(description) {
36
+ const lower = description.toLowerCase();
37
+ if (lower.includes("no refund") || lower.includes("non-refundable"))
38
+ return "no_refund";
39
+ if (lower.includes("milestone") && lower.includes("refund"))
40
+ return "milestone_prorated";
41
+ if (lower.includes("full refund"))
42
+ return "full";
43
+ return "partial";
44
+ }
45
+ function inferArbitration(description) {
46
+ const lower = description.toLowerCase();
47
+ if (lower.includes("no arbitration") || lower.includes("no dispute"))
48
+ return "none";
49
+ if (lower.includes("third party") || lower.includes("independent"))
50
+ return "third_party";
51
+ if (lower.includes("mutual"))
52
+ return "mutual_pick";
53
+ return "merchant_pick";
54
+ }
55
+ export async function analyzeIntent(description, options) {
56
+ const warnings = [];
57
+ const intentType = classifyIntentType(description);
58
+ const traitInference = inferTraitsFromDescription(description);
59
+ const similarMatches = findSimilarIndustries(traitInference.traits, 3);
60
+ const similarIndustries = similarMatches.map((m) => m.industry);
61
+ const inferredIndustry = options?.preferredIndustry ?? similarIndustries[0] ?? "general";
62
+ const industryConfidence = similarIndustries.includes(inferredIndustry) ? 0.85 : 0.5;
63
+ const inferredTraits = traitInference.traits;
64
+ const intent = {
65
+ intent: intentType,
66
+ industry: inferredIndustry,
67
+ description,
68
+ roles: {
69
+ merchant: {
70
+ name: "merchant",
71
+ description: "Service provider or seller",
72
+ obligations: ["Deliver as described", "Maintain compensation_fund if required", "Accept arbitration verdicts"],
73
+ rights: ["Receive payment upon verified delivery", "Set service terms before publish"],
74
+ },
75
+ customer: {
76
+ name: "customer",
77
+ description: "Buyer or service recipient",
78
+ obligations: ["Pay according to agreed schedule", "Provide acceptance/rejection within timeout"],
79
+ rights: ["Receive deliverables as described", "Request refund if delivery fails", "Initiate arbitration for disputes"],
80
+ },
81
+ },
82
+ deliverables: [
83
+ {
84
+ name: "main_deliverable",
85
+ type: inferDeliverableType(description),
86
+ acceptanceCriteria: "To be defined by merchant during configuration",
87
+ proofOfDelivery: "wip_hash",
88
+ },
89
+ ],
90
+ payment: {
91
+ model: inferPaymentModel(description),
92
+ currency: options?.currency ?? "WOW",
93
+ triggers: [
94
+ {
95
+ event: inferPaymentModel(description) === "milestone" ? "milestone completion" : "service confirmation",
96
+ guardDescription: "Guard verifies deliverable meets acceptance criteria",
97
+ },
98
+ ],
99
+ allocation: [
100
+ { recipient: "merchant", percentage: 90 },
101
+ { recipient: "platform", percentage: 0 },
102
+ { recipient: "arbitration_reserve", percentage: 10 },
103
+ ],
104
+ },
105
+ trust: {
106
+ refundPolicy: inferRefundPolicy(description),
107
+ arbitration: inferArbitration(description),
108
+ escrow: true,
109
+ transparency: "full",
110
+ },
111
+ };
112
+ if (intent.payment.model === "milestone" && !description.toLowerCase().includes("milestone")) {
113
+ warnings.push("Payment model inferred as 'milestone' but not explicitly mentioned. Please verify.");
114
+ }
115
+ if (intent.trust.arbitration === "none") {
116
+ warnings.push("No arbitration configured. This increases risk for both parties. Consider adding independent_arbitration module.");
117
+ }
118
+ if (intent.payment.allocation && intent.payment.allocation.some((a) => a.recipient === "platform" && a.percentage > 0)) {
119
+ warnings.push("Platform fee > 0 detected. WOW philosophy recommends 0% platform fee for peer-to-peer transactions.");
120
+ }
121
+ let recommendedModules = [];
122
+ try {
123
+ const { recommendModules } = await import("../extensions/business-modules.js");
124
+ const modules = recommendModules(inferredIndustry, description, { maxModules: 5 });
125
+ recommendedModules = modules.map((m) => m.id);
126
+ }
127
+ catch {
128
+ recommendedModules = ["milestone_escrow", "independent_arbitration", "wip_provenance"];
129
+ }
130
+ return {
131
+ intent,
132
+ inferredIndustry,
133
+ industryConfidence,
134
+ similarIndustries,
135
+ inferredTraits,
136
+ recommendedModules,
137
+ warnings,
138
+ };
139
+ }
140
+ function inferDeliverableType(description) {
141
+ const lower = description.toLowerCase();
142
+ if (lower.includes("design") || lower.includes("code") || lower.includes("write") || lower.includes("digital"))
143
+ return "digital";
144
+ if (lower.includes("class") || lower.includes("lesson") || lower.includes("session"))
145
+ return "service_session";
146
+ if (lower.includes("rent") || lower.includes("access"))
147
+ return "access_right";
148
+ return "physical";
149
+ }
@@ -0,0 +1,2 @@
1
+ import type { ENTRYPOINT, TableItem_MachineNode } from "@wowok/wowok";
2
+ export declare function fetchMachineNodes(machineAddress: string, network: ENTRYPOINT): Promise<TableItem_MachineNode[]>;
@@ -0,0 +1,36 @@
1
+ import { query_objects, query_table } from "@wowok/wowok";
2
+ const BATCH = 50;
3
+ export async function fetchMachineNodes(machineAddress, network) {
4
+ const allFieldObjectIds = [];
5
+ let cursor = undefined;
6
+ for (;;) {
7
+ const tableResult = await query_table({
8
+ parent: machineAddress,
9
+ cursor: cursor ?? undefined,
10
+ network,
11
+ });
12
+ if (!tableResult?.items || tableResult.items.length === 0)
13
+ break;
14
+ for (const item of tableResult.items) {
15
+ if (item.object)
16
+ allFieldObjectIds.push(item.object);
17
+ }
18
+ if (!tableResult.hasNextPage || !tableResult.nextCursor)
19
+ break;
20
+ cursor = tableResult.nextCursor;
21
+ }
22
+ const rawNodes = [];
23
+ for (let i = 0; i < allFieldObjectIds.length; i += BATCH) {
24
+ const batch = allFieldObjectIds.slice(i, i + BATCH);
25
+ const nodeQueryResult = await query_objects({
26
+ objects: batch,
27
+ network,
28
+ });
29
+ for (const obj of nodeQueryResult?.objects ?? []) {
30
+ if (obj.type === "TableItem_MachineNode") {
31
+ rawNodes.push(obj);
32
+ }
33
+ }
34
+ }
35
+ return rawNodes;
36
+ }