@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
@@ -84,6 +84,16 @@ function shortTypeName(objectType) {
84
84
  }
85
85
  return shortName;
86
86
  }
87
+ function groupByType(objects) {
88
+ const byType = new Map();
89
+ for (const obj of objects) {
90
+ const t = shortTypeName(obj.objectType);
91
+ if (!byType.has(t))
92
+ byType.set(t, []);
93
+ byType.get(t).push(obj);
94
+ }
95
+ return byType;
96
+ }
87
97
  function parseCacheData(cached) {
88
98
  if (!cached)
89
99
  return null;
@@ -338,6 +348,43 @@ function normalizeWeights(criterionScores) {
338
348
  return criterionScores;
339
349
  return criterionScores.map(c => ({ ...c, weight: c.weight / total }));
340
350
  }
351
+ export const RISK_WEIGHTS = {
352
+ structural_risk: 0.25,
353
+ fund_safety: 0.2,
354
+ operational_risk: 0.15,
355
+ governance_risk: 0.1,
356
+ graph_coherence: 0.2,
357
+ mode_registry: 0.1,
358
+ };
359
+ export const TRUST_WEIGHTS = {
360
+ reputation: 0.25,
361
+ arbitration_coverage: 0.2,
362
+ guard_quality: 0.2,
363
+ transparency: 0.15,
364
+ consumer_diligence: 0.2,
365
+ };
366
+ export const COMPLETENESS_WEIGHTS = {
367
+ object_coverage: 0.3,
368
+ binding_completeness: 0.25,
369
+ workflow_rationality: 0.2,
370
+ deployment_readiness: 0.25,
371
+ };
372
+ export const EXTENDED_DIMENSION_WEIGHTS = {
373
+ escrow_quality: 0.15,
374
+ proof_integrity: 0.1,
375
+ arbitration_fairness: 0.15,
376
+ fee_transparency: 0.1,
377
+ timeout_protection: 0.1,
378
+ supplier_visibility: 0.1,
379
+ content_commitment: 0.1,
380
+ reputation_verifiability: 0.1,
381
+ permission_safety: 0.1,
382
+ };
383
+ export function finalizeCriterionScores(baseScores, perspective) {
384
+ const criterionScores = normalizeWeights(adjustWeightsForPerspective(baseScores, perspective));
385
+ const overall = clampScore(criterionScores.reduce((sum, c) => sum + c.score * c.weight, 0));
386
+ return { criterionScores, overall };
387
+ }
341
388
  function buildBindingIndex(edges) {
342
389
  const idx = new Map();
343
390
  for (const e of edges) {
@@ -379,13 +426,7 @@ function evaluateIndustryPattern(project, objects, objectCache, edges) {
379
426
  }
380
427
  if (!mode)
381
428
  return result;
382
- const byType = new Map();
383
- for (const obj of objects) {
384
- const t = shortTypeName(obj.objectType);
385
- if (!byType.has(t))
386
- byType.set(t, []);
387
- byType.get(t).push(obj);
388
- }
429
+ const byType = groupByType(objects);
389
430
  const bindingIndex = buildBindingIndex(edges);
390
431
  let matchCount = 0;
391
432
  let totalChecks = 0;
@@ -534,13 +575,7 @@ function evaluateRisk(input) {
534
575
  const findings = [];
535
576
  const strengths = [];
536
577
  const { objects, edges, objectCache, project } = input;
537
- const byType = new Map();
538
- for (const obj of objects) {
539
- const t = shortTypeName(obj.objectType);
540
- if (!byType.has(t))
541
- byType.set(t, []);
542
- byType.get(t).push(obj);
543
- }
578
+ const byType = groupByType(objects);
544
579
  const services = byType.get("Service") ?? [];
545
580
  const bindingIndex = buildBindingIndex(edges);
546
581
  let structuralScore = 100;
@@ -944,15 +979,91 @@ function evaluateRisk(input) {
944
979
  strengths.push("Graph is coherent — no dangling refs or cycles");
945
980
  }
946
981
  coherenceScore = clampScore(coherenceScore);
947
- let criterionScores = [
948
- { name: "structural_risk", score: structuralScore, weight: 0.25, rationale: `${CRITICAL_BINDINGS.filter(b => b.sourceType === "Service").length} expected Service bindings checked` },
949
- { name: "fund_safety", score: fundScore, weight: 0.2, rationale: `Treasury + compensation_fund coverage` },
950
- { name: "operational_risk", score: operationalScore, weight: 0.2, rationale: `Service state + arbitration coverage` },
951
- { name: "governance_risk", score: governanceScore, weight: 0.15, rationale: `Permission + UM presence` },
952
- { name: "graph_coherence", score: coherenceScore, weight: 0.2, rationale: `${danglingCount} dangling + ${cycles.length} circular refs` },
953
- ];
954
- criterionScores = normalizeWeights(adjustWeightsForPerspective(criterionScores, project.perspective));
955
- const overall = clampScore(criterionScores.reduce((sum, c) => sum + c.score * c.weight, 0));
982
+ let modeRegistryScore = 100;
983
+ let modeRegistryRationale = "no industry declared — check skipped";
984
+ if (!project.industry) {
985
+ findings.push({
986
+ criterion: "mode_registry",
987
+ severity: "info",
988
+ message: "Project has no industry tag — mode registry gates (metrics/constraints) not evaluated. Set project industry to enable.",
989
+ deduction: 0,
990
+ });
991
+ }
992
+ else {
993
+ try {
994
+ const modeEval = IndustryModeRegistry.Instance().evaluateMode(project.industry, project.description ?? project.name, {
995
+ prefix: project.prefix,
996
+ network: project.network === "mainnet" ? "mainnet" : "testnet",
997
+ business_intent: project.description ?? undefined,
998
+ industry: project.industry,
999
+ version: project.currentVersion ?? undefined,
1000
+ });
1001
+ const modeNotFound = modeEval.unmet_conditions.some(c => c.includes("not found"));
1002
+ if (modeNotFound) {
1003
+ modeRegistryScore = 50;
1004
+ modeRegistryRationale = `mode '${project.industry}' not registered`;
1005
+ findings.push({
1006
+ criterion: "mode_registry",
1007
+ severity: "warning",
1008
+ message: `Industry mode '${project.industry}' is not registered in the mode registry — cannot verify capability/conflict/constraint gates. Falling back to unverified mode.`,
1009
+ deduction: -50,
1010
+ });
1011
+ }
1012
+ else {
1013
+ for (const v of modeEval.violated_constraints) {
1014
+ modeRegistryScore -= 25;
1015
+ findings.push({
1016
+ criterion: "mode_registry",
1017
+ severity: "critical",
1018
+ message: `Mode '${project.industry}' hard constraint violated: ${v}`,
1019
+ deduction: -25,
1020
+ });
1021
+ }
1022
+ for (const c of modeEval.capability_conflicts) {
1023
+ modeRegistryScore -= 20;
1024
+ findings.push({
1025
+ criterion: "mode_registry",
1026
+ severity: "critical",
1027
+ message: `Mode '${project.industry}' capability conflict: ${c}`,
1028
+ deduction: -20,
1029
+ });
1030
+ }
1031
+ for (const u of modeEval.unmet_conditions) {
1032
+ modeRegistryScore -= 10;
1033
+ findings.push({
1034
+ criterion: "mode_registry",
1035
+ severity: "warning",
1036
+ message: `Mode '${project.industry}' soft constraint unmet: ${u}`,
1037
+ deduction: -10,
1038
+ });
1039
+ }
1040
+ modeRegistryScore = clampScore(modeRegistryScore);
1041
+ modeRegistryRationale =
1042
+ `metric risk ${modeEval.risk_score} / benefit ${modeEval.benefit_score} ` +
1043
+ `(ratio ${modeEval.risk_benefit_ratio.toFixed(2)}); ` +
1044
+ `${modeEval.violated_constraints.length} hard + ${modeEval.unmet_conditions.length} soft constraint issue(s), ` +
1045
+ `${modeEval.capability_conflicts.length} capability conflict(s)`;
1046
+ if (modeEval.applicable && modeEval.violated_constraints.length === 0 &&
1047
+ modeEval.capability_conflicts.length === 0 && modeEval.unmet_conditions.length === 0) {
1048
+ strengths.push(`Mode '${project.industry}' passes all mode-registry gates — ` +
1049
+ `metric risk ${modeEval.risk_score} / benefit ${modeEval.benefit_score} ` +
1050
+ `(risk-benefit ratio ${modeEval.risk_benefit_ratio.toFixed(2)})`);
1051
+ }
1052
+ }
1053
+ }
1054
+ catch {
1055
+ modeRegistryRationale = "mode registry unavailable — check skipped";
1056
+ }
1057
+ }
1058
+ modeRegistryScore = clampScore(modeRegistryScore);
1059
+ const { criterionScores, overall } = finalizeCriterionScores([
1060
+ { name: "structural_risk", score: structuralScore, weight: RISK_WEIGHTS.structural_risk, rationale: `${CRITICAL_BINDINGS.filter(b => b.sourceType === "Service").length} expected Service bindings checked` },
1061
+ { name: "fund_safety", score: fundScore, weight: RISK_WEIGHTS.fund_safety, rationale: `Treasury + compensation_fund coverage` },
1062
+ { name: "operational_risk", score: operationalScore, weight: RISK_WEIGHTS.operational_risk, rationale: `Service state + arbitration coverage` },
1063
+ { name: "governance_risk", score: governanceScore, weight: RISK_WEIGHTS.governance_risk, rationale: `Permission + UM presence` },
1064
+ { name: "graph_coherence", score: coherenceScore, weight: RISK_WEIGHTS.graph_coherence, rationale: `${danglingCount} dangling + ${cycles.length} circular refs` },
1065
+ { name: "mode_registry", score: modeRegistryScore, weight: RISK_WEIGHTS.mode_registry, rationale: modeRegistryRationale },
1066
+ ], project.perspective);
956
1067
  const criticalCount = findings.filter(f => f.severity === "critical").length;
957
1068
  const summary = criticalCount > 0
958
1069
  ? `HIGH RISK: ${criticalCount} critical issue(s). ${findings.length} total findings.`
@@ -972,13 +1083,7 @@ function evaluateTrust(input) {
972
1083
  const findings = [];
973
1084
  const strengths = [];
974
1085
  const { objects, edges, objectCache, reputation, project } = input;
975
- const byType = new Map();
976
- for (const obj of objects) {
977
- const t = shortTypeName(obj.objectType);
978
- if (!byType.has(t))
979
- byType.set(t, []);
980
- byType.get(t).push(obj);
981
- }
1086
+ const byType = groupByType(objects);
982
1087
  const services = byType.get("Service") ?? [];
983
1088
  let reputationScore = 50;
984
1089
  if (reputation && reputation.size > 0 && services[0]) {
@@ -1192,15 +1297,13 @@ function evaluateTrust(input) {
1192
1297
  });
1193
1298
  }
1194
1299
  diligenceScore = clampScore(diligenceScore);
1195
- let criterionScores = [
1196
- { name: "reputation", score: reputationScore, weight: 0.25, rationale: `Registrar likes/dislikes + affiliations` },
1197
- { name: "arbitration_coverage", score: arbitrationScore, weight: 0.2, rationale: `Dispute resolution availability` },
1198
- { name: "guard_quality", score: guardScore, weight: 0.2, rationale: `Validation rules + buy_guard binding` },
1199
- { name: "transparency", score: transparencyScore, weight: 0.15, rationale: `Description + Repository + Contact presence` },
1200
- { name: "consumer_diligence", score: diligenceScore, weight: 0.2, rationale: `${diligencePassed.length}/${CONSUMER_DUE_DILIGENCE.length} E-checks passed` },
1201
- ];
1202
- criterionScores = normalizeWeights(adjustWeightsForPerspective(criterionScores, project.perspective));
1203
- const overall = clampScore(criterionScores.reduce((sum, c) => sum + c.score * c.weight, 0));
1300
+ const { criterionScores, overall } = finalizeCriterionScores([
1301
+ { name: "reputation", score: reputationScore, weight: TRUST_WEIGHTS.reputation, rationale: `Registrar likes/dislikes + affiliations` },
1302
+ { name: "arbitration_coverage", score: arbitrationScore, weight: TRUST_WEIGHTS.arbitration_coverage, rationale: `Dispute resolution availability` },
1303
+ { name: "guard_quality", score: guardScore, weight: TRUST_WEIGHTS.guard_quality, rationale: `Validation rules + buy_guard binding` },
1304
+ { name: "transparency", score: transparencyScore, weight: TRUST_WEIGHTS.transparency, rationale: `Description + Repository + Contact presence` },
1305
+ { name: "consumer_diligence", score: diligenceScore, weight: TRUST_WEIGHTS.consumer_diligence, rationale: `${diligencePassed.length}/${CONSUMER_DUE_DILIGENCE.length} E-checks passed` },
1306
+ ], project.perspective);
1204
1307
  const summary = overall >= 70
1205
1308
  ? `Trusted project (score ${overall}/100). ${strengths.length} strength(s).`
1206
1309
  : `Limited trust signals (score ${overall}/100). ${findings.length} finding(s).`;
@@ -1219,13 +1322,7 @@ function evaluateCompleteness(input) {
1219
1322
  const findings = [];
1220
1323
  const strengths = [];
1221
1324
  const { objects, edges, objectCache, project } = input;
1222
- const byType = new Map();
1223
- for (const obj of objects) {
1224
- const t = shortTypeName(obj.objectType);
1225
- if (!byType.has(t))
1226
- byType.set(t, []);
1227
- byType.get(t).push(obj);
1228
- }
1325
+ const byType = groupByType(objects);
1229
1326
  const services = byType.get("Service") ?? [];
1230
1327
  const bindingIndex = buildBindingIndex(edges);
1231
1328
  const svcObjForRequiredItems = services[0];
@@ -1473,14 +1570,12 @@ function evaluateCompleteness(input) {
1473
1570
  readinessScore = 0;
1474
1571
  }
1475
1572
  readinessScore = clampScore(readinessScore);
1476
- let criterionScores = [
1477
- { name: "object_coverage", score: coverageScore, weight: 0.3, rationale: `R1-R8: ${requiredMet}/${requiredCount} required, R9-R12: ${optionalMet}/${optionalItems.length} optional` },
1478
- { name: "binding_completeness", score: bindingScore, weight: 0.25, rationale: `Service critical bindings checked` },
1479
- { name: "workflow_rationality", score: workflowScore, weight: 0.2, rationale: `Machine nodes + dangling edges` },
1480
- { name: "deployment_readiness", score: readinessScore, weight: 0.25, rationale: `Service publishable state` },
1481
- ];
1482
- criterionScores = normalizeWeights(adjustWeightsForPerspective(criterionScores, project.perspective));
1483
- const overall = clampScore(criterionScores.reduce((sum, c) => sum + c.score * c.weight, 0));
1573
+ const { criterionScores, overall } = finalizeCriterionScores([
1574
+ { name: "object_coverage", score: coverageScore, weight: COMPLETENESS_WEIGHTS.object_coverage, rationale: `R1-R8: ${requiredMet}/${requiredCount} required, R9-R12: ${optionalMet}/${optionalItems.length} optional` },
1575
+ { name: "binding_completeness", score: bindingScore, weight: COMPLETENESS_WEIGHTS.binding_completeness, rationale: `Service critical bindings checked` },
1576
+ { name: "workflow_rationality", score: workflowScore, weight: COMPLETENESS_WEIGHTS.workflow_rationality, rationale: `Machine nodes + dangling edges` },
1577
+ { name: "deployment_readiness", score: readinessScore, weight: COMPLETENESS_WEIGHTS.deployment_readiness, rationale: `Service publishable state` },
1578
+ ], project.perspective);
1484
1579
  const criticalCount = findings.filter(f => f.severity === "critical").length;
1485
1580
  const summary = criticalCount > 0
1486
1581
  ? `Incomplete: ${criticalCount} critical gap(s). Not ready for deployment.`
@@ -1501,10 +1596,278 @@ function evaluateCompleteness(input) {
1501
1596
  evaluatedAt: Date.now(),
1502
1597
  };
1503
1598
  }
1599
+ function evaluateEscrowQuality(input) {
1600
+ const { objects, edges, objectCache } = input;
1601
+ const byType = groupByType(objects);
1602
+ const services = byType.get("Service") ?? [];
1603
+ const allocations = byType.get("Allocation") ?? [];
1604
+ const bindingIndex = buildBindingIndex(edges);
1605
+ let score = 50;
1606
+ const findings = [];
1607
+ if (services.length === 0) {
1608
+ return { name: "escrow_quality", score: 0, weight: EXTENDED_DIMENSION_WEIGHTS.escrow_quality, rationale: "No Service object" };
1609
+ }
1610
+ const service = services[0];
1611
+ const svcData = parseCacheData(objectCache.get(service.objectAddress));
1612
+ const hasOrderAllocators = bindingIndex.get(`${service.objectAddress}#order_allocators`)?.size ?? 0;
1613
+ if (hasOrderAllocators > 0 && allocations.length > 0) {
1614
+ score = 90;
1615
+ findings.push("On-chain escrow active: order_allocators bound + Allocation objects present");
1616
+ }
1617
+ else if (hasOrderAllocators > 0) {
1618
+ score = 70;
1619
+ findings.push("order_allocators template bound — escrow will activate per-order");
1620
+ }
1621
+ else if (svcData && getBalanceValue(svcData, "compensation_fund") > 0) {
1622
+ score = 60;
1623
+ findings.push("compensation_fund present but no Allocation escrow — funds held by merchant, not locked in contract");
1624
+ }
1625
+ else {
1626
+ score = 20;
1627
+ findings.push("No escrow mechanism — funds flow directly to merchant (high counterparty risk)");
1628
+ }
1629
+ return { name: "escrow_quality", score: clampScore(score), weight: EXTENDED_DIMENSION_WEIGHTS.escrow_quality, rationale: findings.join("; ") };
1630
+ }
1631
+ function evaluateProofIntegrity(input) {
1632
+ const { objects, edges } = input;
1633
+ const byType = groupByType(objects);
1634
+ const repositories = byType.get("Repository") ?? [];
1635
+ const guards = byType.get("Guard") ?? [];
1636
+ const proofs = byType.get("Proof") ?? [];
1637
+ let score = 50;
1638
+ const parts = [];
1639
+ if (repositories.length > 0) {
1640
+ score += 20;
1641
+ parts.push(`${repositories.length} Repository object(s)`);
1642
+ }
1643
+ if (guards.length > 0) {
1644
+ score += 15;
1645
+ parts.push(`${guards.length} Guard object(s)`);
1646
+ }
1647
+ if (proofs.length > 0) {
1648
+ score += 15;
1649
+ parts.push(`${proofs.length} Proof object(s)`);
1650
+ }
1651
+ if (repositories.length === 0 && guards.length === 0) {
1652
+ score = 20;
1653
+ parts.push("No on-chain proof mechanism — evidence can be tampered");
1654
+ }
1655
+ return { name: "proof_integrity", score: clampScore(score), weight: EXTENDED_DIMENSION_WEIGHTS.proof_integrity, rationale: parts.join(", ") || "No proof objects" };
1656
+ }
1657
+ function evaluateArbitrationFairness(input) {
1658
+ const { objects, edges, objectCache } = input;
1659
+ const byType = groupByType(objects);
1660
+ const services = byType.get("Service") ?? [];
1661
+ const arbitrations = byType.get("Arbitration") ?? [];
1662
+ const bindingIndex = buildBindingIndex(edges);
1663
+ if (arbitrations.length === 0) {
1664
+ return { name: "arbitration_fairness", score: 0, weight: EXTENDED_DIMENSION_WEIGHTS.arbitration_fairness, rationale: "No Arbitration configured" };
1665
+ }
1666
+ let score = 50;
1667
+ const issues = [];
1668
+ const service = services[0];
1669
+ if (!service) {
1670
+ return { name: "arbitration_fairness", score: 30, weight: EXTENDED_DIMENSION_WEIGHTS.arbitration_fairness, rationale: "No Service to compare against" };
1671
+ }
1672
+ const svcPermKey = `${service.objectAddress}#permission`;
1673
+ const svcPermAddr = bindingIndex.get(svcPermKey)?.values().next().value;
1674
+ for (const arb of arbitrations) {
1675
+ const arbPermKey = `${arb.objectAddress}#permission`;
1676
+ const arbPermAddr = bindingIndex.get(arbPermKey)?.values().next().value;
1677
+ if (!svcPermAddr || !arbPermAddr) {
1678
+ score -= 10;
1679
+ issues.push(`Arbitration ${arb.objectAddress.slice(0, 8)} missing permission binding`);
1680
+ continue;
1681
+ }
1682
+ if (svcPermAddr === arbPermAddr) {
1683
+ score = 10;
1684
+ issues.push(`Arbitration ${arb.objectAddress.slice(0, 8)} shares SAME Permission as Service — NOT independent`);
1685
+ }
1686
+ else {
1687
+ score += 30;
1688
+ issues.push(`Arbitration ${arb.objectAddress.slice(0, 8)} has independent Permission`);
1689
+ }
1690
+ }
1691
+ return { name: "arbitration_fairness", score: clampScore(score), weight: EXTENDED_DIMENSION_WEIGHTS.arbitration_fairness, rationale: issues.join("; ") };
1692
+ }
1693
+ function evaluateFeeTransparency(input) {
1694
+ const { objects, edges, objectCache } = input;
1695
+ const byType = groupByType(objects);
1696
+ const allocations = byType.get("Allocation") ?? [];
1697
+ const services = byType.get("Service") ?? [];
1698
+ let score = 60;
1699
+ const parts = [];
1700
+ if (allocations.length > 0) {
1701
+ score += 20;
1702
+ parts.push(`${allocations.length} Allocation object(s) — fee distribution on-chain`);
1703
+ }
1704
+ const service = services[0];
1705
+ if (service) {
1706
+ const svcData = parseCacheData(objectCache.get(service.objectAddress));
1707
+ if (svcData?.sales && Array.isArray(svcData.sales)) {
1708
+ score += 10;
1709
+ parts.push(`${svcData.sales.length} sale item(s) — pricing visible`);
1710
+ }
1711
+ if (svcData?.compensation_fund && getBalanceValue(svcData, "compensation_fund") > 0) {
1712
+ score += 10;
1713
+ parts.push("compensation_fund visible");
1714
+ }
1715
+ }
1716
+ return { name: "fee_transparency", score: clampScore(score), weight: EXTENDED_DIMENSION_WEIGHTS.fee_transparency, rationale: parts.join(", ") || "Limited fee visibility" };
1717
+ }
1718
+ function evaluateTimeoutProtection(input) {
1719
+ const { objects, objectCache } = input;
1720
+ const byType = groupByType(objects);
1721
+ const machines = byType.get("Machine") ?? [];
1722
+ let score = 50;
1723
+ const parts = [];
1724
+ for (const machine of machines) {
1725
+ const data = parseCacheData(objectCache.get(machine.objectAddress));
1726
+ const nodeCount = getMachineNodeCount(data);
1727
+ if (nodeCount > 0) {
1728
+ const meta = machine.metadata;
1729
+ const config = meta?.config;
1730
+ if (config?.timeout_guard || config?.time_guard) {
1731
+ score += 30;
1732
+ parts.push("Machine has timeout guard configured");
1733
+ }
1734
+ else if (nodeCount >= 2) {
1735
+ score += 10;
1736
+ parts.push(`Machine has ${nodeCount} nodes — workflow structure present`);
1737
+ }
1738
+ }
1739
+ }
1740
+ if (machines.length === 0) {
1741
+ score = 20;
1742
+ parts.push("No Machine — no workflow timeout protection");
1743
+ }
1744
+ return { name: "timeout_protection", score: clampScore(score), weight: EXTENDED_DIMENSION_WEIGHTS.timeout_protection, rationale: parts.join("; ") || "No timeout mechanisms detected" };
1745
+ }
1746
+ function evaluateSupplierVisibility(input) {
1747
+ const { objects } = input;
1748
+ const byType = groupByType(objects);
1749
+ const demands = byType.get("Demand") ?? [];
1750
+ const allocations = byType.get("Allocation") ?? [];
1751
+ let score = 60;
1752
+ const parts = [];
1753
+ if (demands.length > 0) {
1754
+ score += 20;
1755
+ parts.push(`${demands.length} Demand object(s) — supplier discovery on-chain`);
1756
+ }
1757
+ if (allocations.length > 0) {
1758
+ score += 20;
1759
+ parts.push(`${allocations.length} Allocation object(s) — supplier payments visible`);
1760
+ }
1761
+ if (demands.length === 0 && allocations.length === 0) {
1762
+ score = 30;
1763
+ parts.push("No Demand or Allocation — supplier relationships opaque");
1764
+ }
1765
+ return { name: "supplier_visibility", score: clampScore(score), weight: EXTENDED_DIMENSION_WEIGHTS.supplier_visibility, rationale: parts.join(", ") || "No supplier transparency" };
1766
+ }
1767
+ function evaluateContentCommitment(input) {
1768
+ const { objects } = input;
1769
+ const byType = groupByType(objects);
1770
+ const repositories = byType.get("Repository") ?? [];
1771
+ const guards = byType.get("Guard") ?? [];
1772
+ let score = 50;
1773
+ const parts = [];
1774
+ if (repositories.length > 0) {
1775
+ score += 25;
1776
+ parts.push("Repository present — content hash commitments possible");
1777
+ }
1778
+ if (guards.length > 0) {
1779
+ score += 25;
1780
+ parts.push("Guard present — delivery verification possible");
1781
+ }
1782
+ return { name: "content_commitment", score: clampScore(score), weight: EXTENDED_DIMENSION_WEIGHTS.content_commitment, rationale: parts.join(", ") || "No content commitment mechanism" };
1783
+ }
1784
+ function evaluateReputationVerifiability(input) {
1785
+ const { reputation, objects } = input;
1786
+ const services = groupByType(objects).get("Service") ?? [];
1787
+ let score = 40;
1788
+ const parts = [];
1789
+ if (reputation && reputation.size > 0 && services[0]) {
1790
+ const rep = reputation.get(services[0].objectAddress);
1791
+ if (rep) {
1792
+ score += 30;
1793
+ parts.push(`Registrar data: ${rep.likes} likes, ${rep.dislikes} dislikes, ${rep.affiliations} affiliations`);
1794
+ }
1795
+ }
1796
+ if (services.length > 0) {
1797
+ score += 10;
1798
+ parts.push("Service object present — reputation can accumulate");
1799
+ }
1800
+ return { name: "reputation_verifiability", score: clampScore(score), weight: EXTENDED_DIMENSION_WEIGHTS.reputation_verifiability, rationale: parts.join(", ") || "No reputation data available" };
1801
+ }
1802
+ function evaluatePermissionSafety(input) {
1803
+ const { objects, edges, objectCache } = input;
1804
+ const byType = groupByType(objects);
1805
+ const machines = byType.get("Machine") ?? [];
1806
+ const permissions = byType.get("Permission") ?? [];
1807
+ const bindingIndex = buildBindingIndex(edges);
1808
+ let score = 60;
1809
+ const issues = [];
1810
+ if (machines.length === 0) {
1811
+ return { name: "permission_safety", score: 50, weight: EXTENDED_DIMENSION_WEIGHTS.permission_safety, rationale: "No Machine to check" };
1812
+ }
1813
+ const permDataMap = new Map();
1814
+ for (const permObj of permissions) {
1815
+ const cached = parseCacheData(objectCache.get(permObj.objectAddress));
1816
+ if (cached) {
1817
+ permDataMap.set(permObj.objectAddress, {
1818
+ address: permObj.objectAddress,
1819
+ entity_count: typeof cached.entity_count === "number" ? cached.entity_count : undefined,
1820
+ perm_remark: Array.isArray(cached.perm_remark) ? cached.perm_remark : undefined,
1821
+ owner: typeof cached.owner === "string" ? cached.owner : undefined,
1822
+ admin: Array.isArray(cached.admin) ? cached.admin : undefined,
1823
+ });
1824
+ }
1825
+ }
1826
+ for (const machine of machines) {
1827
+ const permBindings = bindingIndex.get(`${machine.objectAddress}#permission`);
1828
+ if (!permBindings || permBindings.size === 0)
1829
+ continue;
1830
+ const permAddr = permBindings.values().next().value;
1831
+ const permData = permAddr ? permDataMap.get(permAddr) : null;
1832
+ if (!permData)
1833
+ continue;
1834
+ const machineData = parseCacheData(objectCache.get(machine.objectAddress));
1835
+ const nodes = extractMachineNodesFromCache(machineData);
1836
+ if (nodes.length === 0)
1837
+ continue;
1838
+ const collection = collectPermissionIndexes(nodes);
1839
+ if (collection.requiredIndexes.length === 0)
1840
+ continue;
1841
+ const report = checkPermissionAuthorization(collection.requiredIndexes, permData);
1842
+ if (!report.allAuthorized) {
1843
+ score -= 30;
1844
+ issues.push(`Machine ${machine.objectAddress.slice(0, 8)} has unauthorized permission indexes: [${report.missingIndexes.join(", ")}]`);
1845
+ }
1846
+ else {
1847
+ score += 20;
1848
+ issues.push(`Machine ${machine.objectAddress.slice(0, 8)}: all ${collection.requiredIndexes.length} permission index(es) authorized`);
1849
+ }
1850
+ }
1851
+ return { name: "permission_safety", score: clampScore(score), weight: EXTENDED_DIMENSION_WEIGHTS.permission_safety, rationale: issues.join("; ") || "Permission checks passed" };
1852
+ }
1504
1853
  function evaluateWorthBuyingStub(input, llmPrompt) {
1505
1854
  const riskResult = evaluateRisk(input);
1506
1855
  const trustResult = evaluateTrust(input);
1507
1856
  const completenessResult = evaluateCompleteness(input);
1857
+ const extendedDimensions = [
1858
+ evaluateEscrowQuality(input),
1859
+ evaluateProofIntegrity(input),
1860
+ evaluateArbitrationFairness(input),
1861
+ evaluateFeeTransparency(input),
1862
+ evaluateTimeoutProtection(input),
1863
+ evaluateSupplierVisibility(input),
1864
+ evaluateContentCommitment(input),
1865
+ evaluateReputationVerifiability(input),
1866
+ evaluatePermissionSafety(input),
1867
+ ];
1868
+ const extendedSummary = extendedDimensions
1869
+ .map(d => `${d.name}: ${d.score}/100 — ${d.rationale}`)
1870
+ .join("\n");
1508
1871
  const summaryLines = [
1509
1872
  "=== RULE-BASED EVALUATION SUMMARY (F-08 enriched context) ===",
1510
1873
  "",
@@ -1517,6 +1880,9 @@ function evaluateWorthBuyingStub(input, llmPrompt) {
1517
1880
  `Completeness: ${completenessResult.score}/100 — ${completenessResult.summary}`,
1518
1881
  ...completenessResult.findings.slice(0, 3).map(f => ` - [${f.severity}] ${f.message}`),
1519
1882
  "",
1883
+ "=== EXTENDED DIMENSIONS D16-D24 (GLM6/93) ===",
1884
+ extendedSummary,
1885
+ "",
1520
1886
  "=== END RULE-BASED SUMMARY ===",
1521
1887
  "",
1522
1888
  ];
@@ -1530,8 +1896,8 @@ function evaluateWorthBuyingStub(input, llmPrompt) {
1530
1896
  evaluationType: "worth_buying",
1531
1897
  score: 0,
1532
1898
  summary: "Requires LLM evaluation — semantic prompt assembled with rule-based " +
1533
- "context (risk/trust/completeness summary). Call save_evaluation with " +
1534
- "the LLM result.",
1899
+ "context (risk/trust/completeness + D16-D24 extended dimensions). " +
1900
+ "Call save_evaluation with the LLM result.",
1535
1901
  criterionScores: [],
1536
1902
  findings: [],
1537
1903
  strengths: [],
@@ -0,0 +1,43 @@
1
+ import type { SemanticObjectGraph } from "./semantic-graph.js";
2
+ import type { BusinessIntent } from "./intent-analyzer.js";
3
+ import type { BusinessModuleId } from "../extensions/business-modules.js";
4
+ export type GameScenario = "merchant_may_deliver_late" | "merchant_may_abandon" | "customer_may_deny_acceptance" | "customer_may_false_claim" | "supplier_may_not_deliver";
5
+ export interface GameTheoryConstraint {
6
+ scenario: GameScenario;
7
+ conflict: string;
8
+ userProtection: {
9
+ mechanism: string;
10
+ object: string;
11
+ guard?: string;
12
+ };
13
+ merchantConstraint: {
14
+ requiredDeposit?: boolean;
15
+ requiredArbitration?: boolean;
16
+ requiredProof?: string;
17
+ timeoutPenalty?: string;
18
+ };
19
+ evaluationMetric: string;
20
+ mitigationSignals: string[][];
21
+ mitigatingModules: BusinessModuleId[];
22
+ recommendation: string;
23
+ }
24
+ export interface GameTheoryCheckResult {
25
+ scenario: GameScenario;
26
+ conflict: string;
27
+ covered: boolean;
28
+ matchedSignals: string[];
29
+ partialSignals: string[];
30
+ userProtection: string;
31
+ evaluationMetric: string;
32
+ recommendation?: string;
33
+ }
34
+ export interface GameTheoryReport {
35
+ results: GameTheoryCheckResult[];
36
+ coveredCount: number;
37
+ totalCount: number;
38
+ exposedScenarios: GameScenario[];
39
+ wowAlignments: string[];
40
+ summary: string;
41
+ }
42
+ export declare const GAME_THEORY_CONSTRAINTS: GameTheoryConstraint[];
43
+ export declare function checkGameTheoryConstraints(graph: SemanticObjectGraph, intent: BusinessIntent): GameTheoryReport;