@wowok/agent-mcp 3.3.7 → 3.3.8

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 (173) hide show
  1. package/dist/chain-semantics/fund-flow.js +1 -1
  2. package/dist/chain-semantics/guard-verbs.js +1 -1
  3. package/dist/chain-semantics/object-graph.js +1 -1
  4. package/dist/communication/message-cursors.d.ts +35 -0
  5. package/dist/communication/message-cursors.js +1 -0
  6. package/dist/communication/wts-attestation.d.ts +5 -0
  7. package/dist/communication/wts-attestation.js +1 -1
  8. package/dist/composition/audit.js +1 -1
  9. package/dist/composition/compile.d.ts +2 -2
  10. package/dist/composition/compile.js +1 -1
  11. package/dist/composition/inflight.d.ts +7 -0
  12. package/dist/composition/inflight.js +1 -1
  13. package/dist/composition/materialize.d.ts +4 -1
  14. package/dist/composition/materialize.js +1 -1
  15. package/dist/config/index.d.ts +1 -0
  16. package/dist/config/index.js +1 -1
  17. package/dist/config/store-policy.d.ts +14 -0
  18. package/dist/config/store-policy.js +1 -0
  19. package/dist/config/store-policy.spec.d.ts +1 -0
  20. package/dist/config/store-policy.spec.js +1 -0
  21. package/dist/customer/industry-risks.js +1 -1
  22. package/dist/customer/user-preferences.js +1 -1
  23. package/dist/evaluation/builtins/graph-service.spec.js +1 -1
  24. package/dist/evaluation/engine.js +1 -1
  25. package/dist/experience/realtime-feedback.js +1 -1
  26. package/dist/extensions/business-modules.d.ts +1 -1
  27. package/dist/extensions/business-modules.js +1 -1
  28. package/dist/extensions/industry-pack.js +1 -1
  29. package/dist/extensions/modes.js +1 -1
  30. package/dist/graph/onchain/analyze.js +1 -1
  31. package/dist/graph/onchain/expand.js +1 -1
  32. package/dist/graph/onchain/exposure.js +1 -1
  33. package/dist/graph/onchain/facts.d.ts +1 -0
  34. package/dist/graph/onchain/facts.js +1 -1
  35. package/dist/graph/onchain/facts.spec.js +1 -1
  36. package/dist/harness/recover.js +1 -1
  37. package/dist/knowledge/acquisition-flywheel.js +1 -1
  38. package/dist/knowledge/allocation-ledger.d.ts +1 -0
  39. package/dist/knowledge/allocation-ledger.js +1 -1
  40. package/dist/knowledge/allocator-rail-verifier.d.ts +6 -2
  41. package/dist/knowledge/allocator-rail-verifier.js +1 -1
  42. package/dist/knowledge/arbitration-ledger.js +1 -1
  43. package/dist/knowledge/audit-rules.d.ts +37 -0
  44. package/dist/knowledge/audit-rules.js +1 -1
  45. package/dist/knowledge/baselines/rules/plan.json +32 -2
  46. package/dist/knowledge/builtin-templates.d.ts +13 -1
  47. package/dist/knowledge/builtin-templates.js +1 -1
  48. package/dist/knowledge/commission-landing.d.ts +26 -0
  49. package/dist/knowledge/commission-landing.js +1 -0
  50. package/dist/knowledge/discount-threshold.js +1 -1
  51. package/dist/knowledge/fund-layer.d.ts +7 -0
  52. package/dist/knowledge/fund-layer.js +1 -1
  53. package/dist/knowledge/getting-started.js +1 -1
  54. package/dist/knowledge/guard-design-patterns.d.ts +1 -1
  55. package/dist/knowledge/guard-design-patterns.js +1 -1
  56. package/dist/knowledge/guard-puzzle.js +1 -1
  57. package/dist/knowledge/guard-render.d.ts +7 -0
  58. package/dist/knowledge/guard-render.js +1 -1
  59. package/dist/knowledge/guard-risk.js +1 -1
  60. package/dist/knowledge/guard-templates.d.ts +1 -1
  61. package/dist/knowledge/guard-templates.js +1 -1
  62. package/dist/knowledge/guard-translation.js +1 -1
  63. package/dist/knowledge/index.js +1 -1
  64. package/dist/knowledge/industry-generalizer.js +1 -1
  65. package/dist/knowledge/industry-registry.d.ts +1 -1
  66. package/dist/knowledge/industry-registry.js +1 -1
  67. package/dist/knowledge/industry-strategy.js +1 -1
  68. package/dist/knowledge/jsonrpc-enum.js +1 -1
  69. package/dist/knowledge/machine-fork-watch.d.ts +9 -0
  70. package/dist/knowledge/machine-fork-watch.js +1 -0
  71. package/dist/knowledge/migration-preflight.js +1 -1
  72. package/dist/knowledge/projection.spec.js +1 -1
  73. package/dist/knowledge/scenario-modes.d.ts +8 -2
  74. package/dist/knowledge/scenario-modes.js +1 -1
  75. package/dist/knowledge/semantic-ir.d.ts +24 -5
  76. package/dist/knowledge/semantic-ir.js +1 -1
  77. package/dist/knowledge/service-ledger.js +1 -1
  78. package/dist/knowledge/strategy-manuals.js +1 -1
  79. package/dist/knowledge/template-index.js +1 -1
  80. package/dist/knowledge/template-loader.d.ts +11 -0
  81. package/dist/knowledge/template-loader.js +1 -1
  82. package/dist/knowledge/template-registry.js +1 -1
  83. package/dist/knowledge/template-scanner.d.ts +4 -2
  84. package/dist/knowledge/template-scanner.js +1 -1
  85. package/dist/knowledge/template-validation.js +1 -1
  86. package/dist/knowledge/tools-reference.js +1 -1
  87. package/dist/monitor/MonitorLoop.js +1 -1
  88. package/dist/playbooks/service-build/business-puzzle.js +1 -1
  89. package/dist/playbooks/service-build/machine-panorama.js +1 -1
  90. package/dist/playbooks/service-build/merchant-guide.d.ts +12 -6
  91. package/dist/playbooks/service-build/merchant-guide.js +1 -1
  92. package/dist/playbooks/service-build/migration-planner.d.ts +10 -2
  93. package/dist/playbooks/service-build/migration-planner.js +1 -1
  94. package/dist/playbooks/service-build/mode-actions.d.ts +1 -0
  95. package/dist/playbooks/service-build/mode-actions.js +1 -1
  96. package/dist/playbooks/service-build/object-panorama.js +1 -1
  97. package/dist/playbooks/service-build/participation-radar.js +1 -1
  98. package/dist/playbooks/service-build/relationship-profile.js +1 -1
  99. package/dist/playbooks/service-build/service-panorama.js +1 -1
  100. package/dist/playbooks/service-build/service-quote.js +1 -1
  101. package/dist/playbooks/service-build/service-quote.spec.js +1 -1
  102. package/dist/review/index.js +1 -1
  103. package/dist/safety/confirm-gate.js +1 -1
  104. package/dist/schema/benchmark-migration/index.d.ts +72 -1
  105. package/dist/schema/benchmark-migration/index.js +1 -1
  106. package/dist/schema/call/allocation.d.ts +3 -0
  107. package/dist/schema/call/allocation.js +1 -1
  108. package/dist/schema/call/base.d.ts +24 -0
  109. package/dist/schema/call/bridge.d.ts +6 -0
  110. package/dist/schema/call/error-codes.d.ts +1 -1
  111. package/dist/schema/call/error-codes.js +1 -1
  112. package/dist/schema/call/order.js +1 -1
  113. package/dist/schema/call/semantic.js +1 -1
  114. package/dist/schema/call/service.js +1 -1
  115. package/dist/schema/common/index.js +1 -1
  116. package/dist/schema/config/index.d.ts +24 -0
  117. package/dist/schema/config/index.js +1 -1
  118. package/dist/schema/goal/index.d.ts +14 -0
  119. package/dist/schema/goal/planning.d.ts +26 -0
  120. package/dist/schema/goal/planning.js +1 -1
  121. package/dist/schema/industry-pack/index.d.ts +9 -1
  122. package/dist/schema/industry-pack/modes.d.ts +9 -1
  123. package/dist/schema/industry-pack/modes.js +1 -1
  124. package/dist/schema/local/index.d.ts +60 -0
  125. package/dist/schema/local/index.js +1 -1
  126. package/dist/schema/messenger/index.d.ts +278 -1
  127. package/dist/schema/messenger/index.js +1 -1
  128. package/dist/schema/operations.d.ts +1 -0
  129. package/dist/schema/query/bi.d.ts +38 -0
  130. package/dist/schema/query/bi.js +1 -1
  131. package/dist/schema/query/index.d.ts +3 -0
  132. package/dist/schema/query/index.js +1 -1
  133. package/dist/schema/schema-version.js +1 -1
  134. package/dist/schema/service-clone/index.d.ts +17 -0
  135. package/dist/schema/service-clone/index.js +1 -1
  136. package/dist/schema-query-impl/index.js +1 -1
  137. package/dist/schemas/account_operation.output.json +6 -0
  138. package/dist/schemas/benchmark_migration_operation.output.json +254 -2
  139. package/dist/schemas/benchmark_migration_operation.schema.json +87 -5
  140. package/dist/schemas/bridge_operation.output.json +6 -0
  141. package/dist/schemas/config_operation.output.json +95 -0
  142. package/dist/schemas/config_operation.schema.json +16 -1
  143. package/dist/schemas/goal_operation.schema.json +22 -0
  144. package/dist/schemas/index.json +1 -1
  145. package/dist/schemas/industry_pack_operation.output.json +4 -0
  146. package/dist/schemas/industry_pack_operation.schema.json +40 -3
  147. package/dist/schemas/local_cache_operation.output.json +6 -0
  148. package/dist/schemas/local_history_operation.output.json +6 -0
  149. package/dist/schemas/local_info_operation.output.json +6 -0
  150. package/dist/schemas/local_mark_operation.output.json +6 -0
  151. package/dist/schemas/messenger_operation.output.json +609 -1
  152. package/dist/schemas/messenger_operation.schema.json +96 -1
  153. package/dist/schemas/onchain_operations.output.json +6 -0
  154. package/dist/schemas/onchain_operations.schema.json +334 -7
  155. package/dist/schemas/onchain_operations_allocation.schema.json +10 -1
  156. package/dist/schemas/onchain_operations_guard.schema.json +318 -0
  157. package/dist/schemas/onchain_operations_order.schema.json +1 -1
  158. package/dist/schemas/onchain_operations_service.schema.json +5 -5
  159. package/dist/schemas/query_toolkit.output.json +271 -8
  160. package/dist/schemas/service_clone_operation.output.json +79 -0
  161. package/dist/tools/handlers/benchmark-migration.d.ts +14 -0
  162. package/dist/tools/handlers/benchmark-migration.js +1 -1
  163. package/dist/tools/handlers/config.js +1 -1
  164. package/dist/tools/handlers/messenger.js +1 -1
  165. package/dist/tools/handlers/onchain.d.ts +19 -1
  166. package/dist/tools/handlers/onchain.js +1 -1
  167. package/dist/tools/handlers/query.d.ts +1 -0
  168. package/dist/tools/handlers/query.js +1 -1
  169. package/dist/tools/handlers/service-clone.d.ts +18 -0
  170. package/dist/tools/handlers/service-clone.js +1 -1
  171. package/dist/tools/registry/business.js +1 -1
  172. package/dist/tools/wrap.js +1 -1
  173. package/package.json +2 -2
@@ -1 +1 @@
1
- import{analyzeIntent}from'./intent-analyzer.js';import{compileTemplate}from'../../composition/compile.js';import{reflux,auditScore}from'../../composition/reflux.js';import{planBlueprint}from'../../composition/blueprint-view.js';import{getGuardDesignPattern}from'../../knowledge/guard-design-patterns.js';import{GUARD_TEMPLATES,getTemplatesByScene}from'../../knowledge/guard-templates.js';import{checkGameTheoryConstraints}from'./game-theory.js';import{assessWorkflowDesign}from'./workflow-design-assessment.js';import{CORE_BUSINESS_MODULES,getBusinessModule,recommendModules,checkModuleConstraints,moduleHasIntentEvidence}from'../../extensions/business-modules.js';import{recipientDesignGuidance}from'../../knowledge/recipient-constraint.js';import{getTemplate,getTemplatesByIndustry}from'../../knowledge/template-loader.js';import{getScenarioMode}from'../../knowledge/scenario-modes.js';function derivePlanSatisfiedConstraints(a,b){const c=new Set(),d=i=>a['edges']['some'](j=>j['relation']===i),e=i=>a['nodes']['some'](j=>j['id']===i),f=i=>a['nodes']['some'](j=>j['type']===i),g=i=>a['adoptedModules']['includes'](i);if(d('has_order_allocators'))c['add']('order_allocators_bound');if(d('uses_machine'))c['add']('machine_bound_before_publish');if(d('has_arbitration'))c['add']('arbitration_bound_to_service');if(e('machine'))c['add']('machine_published');if(e('repository'))c['add']('repository_published');if(e('service'))c['add']('service_published');e('permission_arb')&&e('permission')&&c['add']('arbitration_permission_independent');g('independent_arbitration')&&a['nodes']['some'](i=>i['id']['includes']('guard')&&i['id']['includes']('arbitration'))&&c['add']('voting_guard_configured');g('accept_timeout_protection')&&(c['add']('time_guard_configured'),c['add']('adminUnhold_permission'));g('milestone_escrow')&&f('guard')&&c['add']('milestone_forward_guarded');const h=d('has_order_allocators');if(h&&b['payment']['allocation']&&b['payment']['allocation']['length']>0x0){c['add']('allocators_configured');const i=b['payment']['allocation']['reduce']((k,l)=>k+l['percentage'],0x0);if(Math['abs'](i-0x64)<0.001)c['add']('sharing_sum_100');const j=b['payment']['allocation']['find'](k=>k['recipient']==='platform');if(!j||j['percentage']===0x0)c['add']('platform_fee_zero');g('supplier_collaboration')&&(c['add']('allocation_sharing_configured'),c['add']('demand_configured'));}g('wip_provenance')&&e('repository')&&c['add']('wip_hash_before_delivery');g('subscription_with_proof')&&e('repository')&&(c['add']('delivery_guard_per_cycle'),c['add']('repository_updated'));g('damage_attestation')&&(c['add']('pre_rental_hash'),c['add']('post_rental_hash'));g('refund_guarantee')&&(c['add']('compensation_fund_positive'),c['add']('refund_guard_configured'));if(g('praise_incentive')){const k=a['plan']['steps']['some'](m=>m['op']==='create'&&m['object']==='reward'),l=a['plan']['steps']['some'](m=>m['op']==='configure'&&m['method']==='coin_add');k&&l&&(c['add']('reward_pool_funded'),c['add']('reward_claim_replay_armed'));}g('discount_lifecycle')&&(c['add']('discount_budget_planned'),c['add']('discount_burn_disclosed'));if(g('after_sales_guarantee')){const m=a['plan']['steps']['find'](p=>p['op']==='create'&&p['object']==='machine'),n=m?.['params']?.['nodes']??[],o=n['some'](p=>/return|refund|exchange|replace|reship|swap|warranty|repair/i['test'](p['name']??''));o&&(c['add']('after_sales_rail_present'),c['add']('after_sales_polarity_pair'),c['add']('after_sales_window_anchored'),c['add']('after_sales_no_double_remedy'));}if(g('acceptance_judging')){const p=a['plan']['steps']['find'](t=>t['op']==='create'&&t['object']==='machine'),q=p?.['params']?.['nodes']??[],r=q['map'](t=>t['name']??''),s=r['some'](t=>/accept|approv|award|ruling|place|placement|triage|vot|evaluat|winner|judge/i['test'](t));if(s){const t=r['some'](u=>/revis|redeliver|resubmit|rework/i['test'](u));c['add']('acceptance_race_free');if(e('arbitration'))c['add']('acceptance_judge_independent');if(!t||e('repository'))c['add']('acceptance_revision_bounded');}}if(g('installment_deposit')){const u=a['plan']['steps']['find'](z=>z['op']==='create'&&z['object']==='machine'),v=u?.['params']?.['nodes']??[],w=v['map'](z=>z['name']??''),x=w['some'](z=>/(deposit|down_?pay|balance_due|balance_owed|installment|milestone|awaiting|owed)/i['test'](z)),y=w['some'](z=>/(paid|funded|captured|settled)/i['test'](z));x&&y&&(c['add']('installment_funding_gated'),c['add']('installment_deposit_exit'),c['add']('installment_release_once'));}if(g('affiliate_commission')){const z=a['plan']['steps']['find'](D=>D['op']==='create'&&D['object']==='machine'),A=z?.['params']?.['nodes']??[],B=A['map'](D=>D['name']??''),C=B['some'](D=>/(commission|affiliate|referr|attribut|partner_?payout)/i['test'](D));C&&(c['add']('affiliate_rail_present'),c['add']('affiliate_clawback_disclosed'),c['add']('affiliate_window_anchored'));}if(g('crowdfunding')){const D=a['plan']['steps']['find'](H=>H['op']==='create'&&H['object']==='machine'),E=D?.['params']?.['nodes']??[],F=E['map'](H=>H['name']??''),G=F['some'](H=>/(releas|settle|funded|disburs|project)/i['test'](H));G&&(c['add']('crowdfunding_exit_rail_present'),c['add']('crowdfunding_aggregate_writer_bound'),c['add']('crowdfunding_disclosure_present'));}return c;}function deriveDeployTimeChecks(a,b=![]){const c=[];return a['nodes']['some'](d=>d['id']==='machine')&&c['push']('Machine\x20published\x20AND\x20bound\x20to\x20Service\x20BEFORE\x20Service.publish\x20(machine\x20is\x20immutable\x20after\x20publish)'),a['edges']['some'](d=>d['relation']==='has_order_allocators')&&(c['push']('Service.order_allocators\x20bound\x20(verify\x20via\x20query_objects\x20after\x20publish\x20—\x20order_allocators\x20is\x20FROZEN\x20at\x20publish)'),c['push']('Settlement\x20is\x20NOT\x20triggered\x20by\x20reaching\x20a\x20Machine\x20node\x20alone\x20—\x20an\x20explicit\x20alloc_by_guard\x20call\x20(keeper\x20or\x20merchant)\x20fires\x20the\x20settlement\x20Allocator\x20once\x20its\x20Guard\x20passes.\x20Declare\x20the\x20node->allocator\x20trigger\x20(which\x20terminal\x20node\x20unlocks\x20settlement)\x20and\x20schedule\x20the\x20keeper\x20step;\x20otherwise\x20orders\x20stall\x20at\x20the\x20settle\x20node\x20with\x20allocation_state=pending')),(a['adoptedModules']['includes']('refund_guarantee')||a['nodes']['some'](d=>d['id']==='arbitration'))&&(b?c['push']('COMPENSATION\x20FUND:\x20DO\x20NOT\x20FUND\x20—\x20this\x20template\x20declares\x20compensation_fund_policy=forbidden\x20(the\x20unreserved\x20pool\x20is\x20double-takeable\x20via\x20refund-then-claim\x20until\x20the\x20arbitration-escrow\x20shared\x20gate\x20lands;\x20user\x20ruling\x202026-10-15).\x20Disputes\x20ride\x20the\x20escrow\x20rails\x20only;\x20the\x20compensation_fund_topup\x20post-deploy\x20step\x20is\x20intentionally\x20absent'):c['push']('compensation_fund\x20MUST\x20be\x20able\x20to\x20cover\x20payouts:\x20a\x20claim\x20against\x20a\x20drained\x20fund\x20aborts\x20(service.move\x20E_COMPENSATION_NOT_MATCH).\x20Size\x20the\x20fund\x20>=\x203x\x20a\x20TYPICAL\x20single\x20order\x20(3x\x20IS\x20the\x20chain\x27s\x20hard\x20award\x20ceiling,\x20MAX_INDEMNITY_MULTIPLE)\x20—\x20per-order\x20coverage\x20is\x20enforced\x20at\x20BUY\x20time\x20(each\x20order\x20is\x20checked\x20against\x203x\x20ITS\x20OWN\x20amount,\x20not\x203x\x20the\x20highest\x20SKU),\x20so\x20publish\x20no\x20longer\x20blocks\x20on\x20coverage;\x20verify\x20the\x20on-chain\x20balance\x20before\x20going\x20live')),a['nodes']['some'](d=>d['id']==='arbitration')&&(c['push']('Arbitration.permission\x20!=\x20Service.permission\x20on-chain\x20(E_ARBITRATION_PERMISSION_CONFLICT=33)'),c['push']('A\x20freshly\x20created\x20Arbitration\x20defaults\x20to\x20PAUSED\x20—\x20unpause\x20it\x20(arbitration\x20activation)\x20before\x20the\x20first\x20case\x20can\x20be\x20filed,\x20otherwise\x20dispute\x20filing\x20aborts')),a['nodes']['some'](d=>d['id']==='repository')&&c['push']('Repository\x20published\x20and\x20Guard\x20write\x20validation\x20configured'),c['push']('After\x20materialization,\x20confirm\x20the\x20on-chain\x20state\x20matches\x20this\x20plan\x20(query_toolkit\x20query_type=\x27service_panorama\x27)'),c;}function derivePostDeploySteps(a,b=![]){const c=[];return!b&&(a['adoptedModules']['includes']('refund_guarantee')||a['nodes']['some'](d=>d['id']==='arbitration'))&&c['push']({'order':c['length']+0x1,'id':'compensation_fund_topup','title':'Top\x20up\x20the\x20compensation\x20fund','when':'After\x20the\x20Service\x20object\x20is\x20created,\x20BEFORE\x20the\x20service\x20goes\x20live\x20(before\x20the\x20first\x20order)','action':'Call\x20compensation_fund_add\x20sized\x20>=\x203x\x20a\x20TYPICAL\x20single\x20order\x20(3x\x20=\x20the\x20chain\x27s\x20hard\x20award\x20ceiling,\x20MAX_INDEMNITY_MULTIPLE;\x20above\x203x\x20only\x20buys\x20headroom\x20for\x20concurrent\x20claims).\x20Per-order\x20coverage\x20is\x20enforced\x20at\x20BUY\x20time\x20—\x20each\x20incoming\x20order\x20is\x20checked\x20against\x203x\x20ITS\x20OWN\x20amount\x20and\x20under-covered\x20orders\x20cannot\x20be\x20created\x20—\x20then\x20verify\x20the\x20on-chain\x20fund\x20balance\x20via\x20query_objects','tool_hint':'onchain_operations\x20(service.compensation_fund_add)','failure_if_skipped':'a\x20compensation\x20claim\x20against\x20an\x20empty\x20fund\x20aborts\x20(E_COMPENSATION_NOT_MATCH,\x20testnet\x20lesson\x20R-4)'}),a['nodes']['some'](d=>d['id']==='arbitration')&&(c['push']({'order':c['length']+0x1,'id':'arbitration_unpause','title':'Activate\x20the\x20Arbitration\x20(unpause)','when':'Immediately\x20after\x20the\x20Arbitration\x20object\x20is\x20created,\x20before\x20the\x20first\x20dispute\x20is\x20filed','action':'Unpause/activate\x20the\x20Arbitration\x20so\x20dispute\x20filing\x20is\x20accepted;\x20keep\x20its\x20Permission\x20distinct\x20from\x20the\x20Service\x20Permission\x20(E_ARBITRATION_PERMISSION_CONFLICT=33)','tool_hint':'onchain_operations\x20(arbitration\x20activation)','failure_if_skipped':'a\x20freshly\x20created\x20Arbitration\x20defaults\x20to\x20PAUSED\x20—\x20dispute\x20filing\x20aborts\x20(testnet\x20lesson\x20R-5)'}),c['push']({'order':c['length']+0x1,'id':'voting_guard_open_vote','title':'Bind\x20the\x20open-vote\x20voting_guard\x20(tpl_voting_guard_open_vote)','when':'After\x20the\x20Arbitration\x20is\x20activated,\x20BEFORE\x20the\x20first\x20dispute\x20can\x20be\x20voted\x20on','action':'Create\x20the\x20open-vote\x20guard\x20(tpl_voting_guard_open_vote:\x20always-true\x20root\x20+\x20FixedValue\x20weight\x201\x20=\x20one\x20person\x20one\x20vote)\x20and\x20set\x20it\x20as\x20the\x20Arbitration\x27s\x20voting_guard;\x20skip\x20this\x20step\x20ONLY\x20for\x20a\x20deliberately\x20closed\x20panel\x20(then\x20bind\x20tpl_voting_guard_numeric_weight\x20with\x20the\x20arbitrator\x20address\x20list\x20instead)','tool_hint':'onchain_operations\x20(guard\x20creation\x20+\x20arbitration\x20voting_guard\x20set,\x20op=\x27set\x27)','failure_if_skipped':'an\x20EMPTY\x20voting_guard\x20dead-locks\x20every\x20plain\x20vote\x20on\x20permission\x20358\x20(creator-admin\x20only)\x20—\x20the\x20first\x20dispute\x20cannot\x20reach\x20a\x20verdict\x20if\x20the\x20admin\x20is\x20unresponsive\x20(crs9-F-36,\x20R-ARB-VOTE-LOCK)'})),a['edges']['some'](d=>d['relation']==='has_order_allocators')&&c['push']({'order':c['length']+0x1,'id':'settlement_alloc_by_guard','title':'Fire\x20settlement\x20via\x20alloc_by_guard\x20(keeper/merchant\x20step)','when':'Recurring\x20—\x20after\x20EACH\x20order\x20reaches\x20its\x20settlement\x20terminal\x20node\x20(declare\x20which\x20node\x20unlocks\x20settlement)','action':'Call\x20alloc_by_guard\x20on\x20the\x20order\x27s\x20allocation\x20with\x20the\x20settlement\x20Guard;\x20reaching\x20the\x20Machine\x20node\x20alone\x20does\x20NOT\x20settle\x20(allocation_state\x20stays\x20pending)','tool_hint':'onchain_operations\x20(allocation.alloc_by_guard);\x20schedule\x20as\x20a\x20keeper\x20step','failure_if_skipped':'orders\x20stall\x20at\x20the\x20settle\x20node\x20with\x20funds\x20locked\x20in\x20escrow\x20(testnet\x20lesson\x20R-2)'}),c['push']({'order':c['length']+0x1,'id':'verify_service_panorama','title':'Verify\x20the\x20on-chain\x20state\x20matches\x20the\x20plan','when':'After\x20all\x20creation\x20steps\x20and\x20the\x20steps\x20above\x20are\x20done','action':'Run\x20the\x20service\x20panorama\x20query\x20and\x20diff\x20it\x20against\x20this\x20plan\x27s\x20blueprint/creation_plan','tool_hint':'query_toolkit\x20query_type=\x27service_panorama\x27','failure_if_skipped':'plan/chain\x20drift\x20(missing\x20binding,\x20wrong\x20allocator\x20order)\x20stays\x20undetected\x20until\x20an\x20order\x20hits\x20it'}),c;}function buildCreationPlan(a){const b=[],c=new Map(a['nodes']['map'](k=>[k['id'],k])),f=new Map();for(const k of a['nodes'])f['set'](k['id'],new Set());for(const l of a['edges']){if(!f['has'](l['from'])||!c['has'](l['to']))continue;const m=l['relation']==='has_guard'?l['to']:l['from'],o=l['relation']==='has_guard'?l['from']:l['to'];if(m===o||!f['has'](m))continue;f['get'](m)['add'](o);}for(const p of a['nodes']){for(const q of Object['values'](p['config'])){q['type']==='address_ref'&&q['targetId']!==p['id']&&f['has'](q['targetId'])&&f['get'](p['id'])['add'](q['targetId']);}}const g=a['nodes']['filter'](r=>r['type']==='service')['map'](r=>r['id']);if(g['length']>0x0)for(const r of a['nodes']){if(r['type']!=='guard')continue;const s=f['get'](r['id']);if(s===undefined)continue;for(const t of g)s['add'](t);}const h=new Map([...f]['map'](([u,v])=>[u,[...v]])),i=[],j=new Map(f);while(j['size']>0x0){const u=[...j['entries']()]['filter'](([,v])=>v['size']===0x0)['map'](([v])=>v);if(u['length']===0x0){i['push'](...j['keys']());break;}u['sort']();for(const v of u){i['push'](v),j['delete'](v);for(const w of j['values']())w['delete'](v);}}return i['forEach']((x,y)=>{const z=c['get'](x),A=z['config']['name'],B=A?.['type']==='string'?A['value']:x,C=B['includes']('/')?B['replaceAll']('/','__'):B;b['push']({'order':y+0x1,'node_id':x,'object_type':z['type'],'suggested_name':C,'depends_on':h['get'](x)??[],'operation_hint':'Create\x20'+z['type']+'\x20via\x20onchain_operations,\x20then\x20configure.\x20Purpose:\x20'+z['purpose']});}),b;}function resolveTemplate(a,b){if(!a)return undefined;const c=getTemplate(a);if(c)return c;const d=getTemplatesByIndustry(a);if(b){const f=b['toLowerCase'](),g=d['filter'](h=>{const i=String(h['product_ref']??'')['trim']()['toLowerCase']();return i['length']>0x0&&f['includes'](i);});if(g['length']===0x1)return g[0x0];}const e=getScenarioMode(a)?.['default_template'];if(e){const h=getTemplate(e);if(h)return h;}if(d['length']>0x0)return d[0x0];return undefined;}export async function handleMerchantGuide(a){const b=a['guide_state']??{'intent_text':''},c=a['guide_confirm']??{},d={'intent_text':(a['intent']??b['intent_text']??'')['trim'](),'confirmed_industry':c['industry']??b['confirmed_industry'],'currency':c['currency']??b['currency'],'deliverables':c['deliverables']??b['deliverables'],'payment_override':c['payment']??b['payment_override'],'trust_override':c['trust']??b['trust_override'],'adopted_module_ids':c['adopted_module_ids']??b['adopted_module_ids'],'guard_resolutions':{...b['guard_resolutions']??{},...c['guard_resolutions']??{}},'review_mode':c['review_mode']??b['review_mode'],'reward_funding':c['reward_funding']??b['reward_funding'],'reward_claim_amount':c['reward_claim_amount']??b['reward_claim_amount'],'after_sales_mode':c['after_sales_mode']??b['after_sales_mode'],'acceptance_mode':c['acceptance_mode']??b['acceptance_mode'],'installment_mode':c['installment_mode']??b['installment_mode'],'affiliate_mode':c['affiliate_mode']??b['affiliate_mode'],'crowdfunding_mode':c['crowdfunding_mode']??b['crowdfunding_mode'],'sales':c['sales']??b['sales']};for(const O of Object['keys'](d)){if(d[O]===undefined)delete d[O];}if(d['guard_resolutions']&&Object['keys'](d['guard_resolutions'])['length']===0x0)delete d['guard_resolutions'];if(!d['intent_text'])throw new Error('merchant_guide\x20requires\x20\x27intent\x27\x20(business\x20description)\x20for\x20Step\x201.\x20'+'Example:\x20intent=\x27I\x20want\x20to\x20offer\x20online\x20design\x20service\x20with\x20milestone\x20payments\x27.\x20'+'Pass\x20the\x20returned\x20guide_state\x20back\x20UNCHANGED\x20on\x20subsequent\x20calls,\x20plus\x20guide_confirm\x20for\x20merchant\x20decisions.');const e=await analyzeIntent(d['intent_text'],{'preferredIndustry':d['confirmed_industry'],'currency':d['currency']});if(!d['confirmed_industry'])return{'action':'merchant_guide','current_step':0x2,'step_name':'Industry\x20Matching','guide_state':d,'intent_draft':e['intent'],'industry_options':{'inferred':e['inferredIndustry'],'confidence':e['industryConfidence'],'similar':e['similarIndustries']},'warnings':e['warnings'],'next_action':'Confirm\x20the\x20industry\x20by\x20calling\x20merchant_guide\x20again\x20with\x20guide_state\x20(UNCHANGED)\x20'+('plus\x20guide_confirm={\x20industry:\x20\x27<one\x20of:\x20'+e['similarIndustries']['join'](',\x20')+'\x20—\x20or\x20any\x20other\x20industry\x20id>\x27\x20}')};const f={...e['intent'],'industry':d['confirmed_industry'],'deliverables':d['deliverables']??e['intent']['deliverables'],'payment':{...e['intent']['payment'],...d['payment_override']??{}},'trust':{...e['intent']['trust'],...d['trust_override']??{}}},h=!!d['adopted_module_ids'],i=d['adopted_module_ids']?d['adopted_module_ids']['map'](P=>getBusinessModule(P))['filter'](P=>!!P):recommendModules(d['confirmed_industry'],d['intent_text'],{'maxModules':0x5}),j=a['template_override']??resolveTemplate(d['confirmed_industry'],d['intent_text']);if(!j)throw new Error('No\x20compilable\x20template\x20found\x20for\x20industry\x20\x27'+d['confirmed_industry']+'\x27.\x20'+'Register\x20a\x20template\x20via\x20industry_pack_operation\x20or\x20pass\x20template_override\x20explicitly.');const l={'currency':d['currency']??f['payment']['currency'],...d['payment_override']?{'payment':d['payment_override']}:{},...d['trust_override']?{'trust':d['trust_override']}:{},...d['deliverables']?{'deliverables':d['deliverables']}:{},...d['adopted_module_ids']?{'adopted_module_ids':d['adopted_module_ids']}:{},...d['review_mode']?{'review_mode':d['review_mode']}:{},...d['reward_funding']!==undefined?{'reward_funding':d['reward_funding']}:{},...d['reward_claim_amount']!==undefined?{'reward_claim_amount':d['reward_claim_amount']}:{},...d['after_sales_mode']?{'after_sales_mode':d['after_sales_mode']}:{},...d['acceptance_mode']?{'acceptance_mode':d['acceptance_mode']}:{},...d['installment_mode']?{'installment_mode':d['installment_mode']}:{},...d['affiliate_mode']?{'affiliate_mode':d['affiliate_mode']}:{},...d['crowdfunding_mode']?{'crowdfunding_mode':d['crowdfunding_mode']}:{},...d['sales']?.['length']?{'sales':d['sales']}:{}},m={};for(const P of i){for(const Q of P['templateRefs']){if(Q['object_type']!=='guard')continue;const R=j['guards']['filter'](S=>S['template_id']===Q['template_id']);if(R['length']===0x0)continue;for(const S of R){m[S['key']??Q['template_id']+'#'+j['guards']['indexOf'](S)]={'kind':'template','template_id':Q['template_id']};}}}Object['assign'](m,d['guard_resolutions']??{});const n=compileTemplate(j,l,{'nameBase':a['name_base']??j['id'],'intent':d['intent_text'],'guardResolutions':m}),o=reflux(n['plan']),p=o['plan'],q=o['audit'],r=auditScore(q),s=planBlueprint(p,f,i['map'](T=>T['id'])),t=n['blockers']['map'](T=>({'module':'template','missing_constraints':[T['code']],'fix':T['detail']})),u=derivePlanSatisfiedConstraints(s,f),w=i['map'](T=>checkModuleConstraints(T,u,{'evidenceMatched':h||moduleHasIntentEvidence(T,d['intent_text'])})),x=j['compensation_fund_policy']==='forbidden',y=deriveDeployTimeChecks(s,x),z=derivePostDeploySteps(s,x),A=s['edges']['some'](T=>T['relation']==='has_order_allocators')?recipientDesignGuidance()['map'](T=>({'id':T['id'],'move_recipient':T['move_recipient'],'semantics':T['semantics'],'required_constraints':T['required_constraints'],'finding_if_unmet':T['finding_if_unmet']})):undefined,B=[...w['filter'](T=>!T['adopted']),...t],C=q['findings']['filter'](T=>T['level']==='critical'||T['level']==='high')['map'](T=>({'module':'audit','missing_constraints':[T['rule_id']],'fix':T['title']+'\x20—\x20'+(T['mitigation']??T['description'])})),D=[{'re':/allocat|refund|recover|claimed_by|settle|escrow/i,'scene':'service_order_allocators_guard'},{'re':/\bbuy\b|purchase|allowlist|blocklist/i,'scene':'service_buy_guard'},{'re':/reward/i,'scene':'reward_claim'},{'re':/write_guard|repository_write/i,'scene':'repository_write_guard'},{'re':/arbitrat|ruling|voting/i,'scene':'arbitration_usage_guard'},{'re':/forward|node|witness|deliver|review|cancel|expire|submission|progress/i,'scene':'machine_forward_guard'}],E=[{'re':/claimed_by\s*some\s*==\s*true/i,'tpl':'tpl_allocator_node_gate_recover'},{'re':/claimed_by\s*some\s*==\s*false|claimed_by\s*(?:is\s+)?none|\brefund|\bcancel/i,'tpl':'tpl_allocator_node_gate_refund'},{'re':/claimed_by\s*some|\brecover|\baward/i,'tpl':'tpl_allocator_node_gate_recover'}],F=[{'host':'machine','re':/pattern\.time_lock_progress/i,'tpl':'tpl_time_lock_progress'},{'host':'machine','re':/pattern\.time_window_upper_bound/i,'tpl':'tpl_time_window_upper'},{'host':'reward','re':/pattern\./i,'tpl':'tpl_reward_one_time_claim'}],G=(T,U,V,W,X)=>{let Y;const Z=/tpl_[a-z0-9_]+/['exec'](T+'\x20'+U);Z!==null&&(Y=GUARD_TEMPLATES['find'](a4=>a4['id']===Z[0x0])?.['scene_id']);Y===undefined&&W!=='reward'&&/\ballocators?\b|claimed_by|guard_identifier|order_allocators/i['test'](U)&&(Y='service_order_allocators_guard');if(Y===undefined){if(W==='machine'||W==='machine_forward')Y='machine_forward_guard';else{if(W==='reward')Y='reward_claim';else{if(W==='repository')Y='repository_write_guard';else{if(W==='arbitration')Y='arbitration_usage_guard';else{const a4=D['find'](a5=>a5['re']['test'](T+'\x20'+U));Y=a4?.['scene'];}}}}}if(Y===undefined)return undefined;const a0=getTemplatesByScene(Y);let a1=V!==undefined&&a0['some'](a5=>a5['applicable_industries']['includes'](V))?a0['filter'](a5=>a5['applicable_industries']['includes'](V)):a0;if(/\btime[_-]?lock|\bwindow|\btimeout|\bduration|\bdeadline|\bdays?\b|\bclock|\bdelay/i['test'](T+'\x20'+U)){const a5=a1['filter'](a6=>JSON['stringify'](a6['example_root']??{})['toLowerCase']()['includes']('clock'));if(a5['length']===0x0)return undefined;a1=a5;}if(X['length']>0x0){const a6=Z!==null?a1['find'](a8=>a8['id']===Z[0x0]):undefined,a7=a1['filter'](a8=>{const a9=[];if(a8['example_root']!==undefined){const aa=JSON['stringify'](a8['example_root']);for(const ab of aa['matchAll'](/"query":"([^"]+)"/g))a9['push'](ab[0x1]);if(aa['includes']('\x22type\x22:\x22query_progress_history_time\x22'))a9['push']('progress.history.time');if(aa['includes']('\x22type\x22:\x22query_progress_history_find\x22'))a9['push']('progress.history.find');}return a9['some'](ac=>X['some'](ad=>ac===ad||ac['startsWith'](ad)||ad['startsWith'](ac)));});if(a6!==undefined&&!a7['includes'](a6))a7['push'](a6);if(a7['length']===0x0)return undefined;a1=a7;}const a2=W==='machine_forward'?'machine':W,a3=F['find'](a8=>a8['host']===a2&&a8['re']['test'](T+'\x20'+U)&&a1['some'](a9=>a9['id']===a8['tpl']));a3!==undefined&&(a1=[...a1]['sort']((a8,a9)=>(a8['id']===a3['tpl']?0x0:0x1)-(a9['id']===a3['tpl']?0x0:0x1)));if(Y==='service_order_allocators_guard'){const a8=E['find'](a9=>a9['re']['test'](T+'\x20'+U));a8!==undefined&&(a1=[...a1]['sort']((a9,aa)=>(a9['id']===a8['tpl']?0x0:0x1)-(aa['id']===a8['tpl']?0x0:0x1)));}return a1['slice'](0x0,0x3)['map'](a9=>({'template_id':a9['id'],'name':a9['name'],'parameters':a9['parameters']['map'](aa=>({'name':aa['name'],'required':aa['required'],...aa['default']!==undefined?{'default':aa['default']}:{},'description':aa['description']}))}));},H=n['unresolved']['map'](T=>{const U=getGuardDesignPattern(T['template_id']),V=G(T['template_id'],T['purpose'],j?.['industry'],T['host'],U?.['key_queries']??[]),W=new Set((j?.['machine_shape']??[])['flatMap'](a1=>(a1['from']??[])['map'](a2=>typeof a2==='string'?undefined:a2['guard_key'])['filter'](a2=>typeof a2==='string'))),X=new Map((j?.['allocator']['rows']??[])['filter'](a1=>typeof a1['guard_key']==='string')['map'](a1=>[a1['guard_key'],a1])),Y=X['get'](T['key']),Z=Y!==undefined&&!W['has'](T['key']),a0=!W['has'](T['key'])&&!X['has'](T['key'])&&T['policy']===undefined&&T['host']!=='reward'&&!(T['host']==='service'&&T['key']==='buy');return{'key':T['key'],'template_id':T['template_id'],'host':T['host'],'purpose':T['purpose'],...U?.['logic_summary']?{'logic_summary':U['logic_summary']}:{},...U?.['key_queries']?.['length']?{'key_queries':U['key_queries']}:{},...V!==undefined&&V['length']>0x0?{'suggested_templates':V}:{},'how_to_resolve':'guide_confirm.guard_resolutions[\x27'+T['key']+'\x27]\x20=\x20{\x20kind:\x20\x27inline\x27,\x20table,\x20root\x20}\x20(a\x20resolved\x20Guard),\x20'+'or\x20{\x20kind:\x20\x27template\x27,\x20template_id:\x20\x27tpl_*\x27,\x20params\x20}\x20when\x20a\x20guard\x20template\x20matches\x20this\x20design'+(V!==undefined&&V['length']>0x0?'\x20(suggested_templates\x20below\x20list\x20the\x20matching\x20executable\x20forms\x20and\x20their\x20parameters)':'.')+(T['host']==='machine'&&!Z?'\x20MACHINE-HOST\x20REQUIREMENT:\x20the\x20inline\x20table\x20MUST\x20declare\x20the\x20protocol\x20task-binding\x20slot\x20'+'{\x20identifier:\x20254,\x20b_submission:\x20true,\x20value_type:\x20\x22Address\x22\x20}\x20—\x20the\x20forward\x27s\x20passport\x20only\x20emits\x20'+'DECLARED\x20slots,\x20so\x20a\x20machine-forward\x20guard\x20without\x20this\x20row\x20aborts\x20EVERY\x20order-bound\x20forward\x20'+'it\x20gates\x20(code\x2011)\x20and\x20the\x20pre-publish\x20gate\x20blocks\x20the\x20Machine\x20publish.':'')+(Z?'\x20ALLOCATOR-RAIL\x20NOTE:\x20this\x20design\x20gates\x20an\x20allocator\x20rail\x20(not\x20a\x20machine\x20forward)\x20—\x20do\x20NOT\x20add\x20the\x20'+'254\x20task-binding\x20slot:\x20a\x20254\x20declaration\x20arms\x20once-per-order\x20replay\x20protection\x20at\x20alloc\x20time\x20'+'(allocation\x20ONCE_FOR_OBJECT)\x20and\x20permanently\x20blocks\x20multi-fire\x20rails\x20(a\x20second\x20release\x20aborts\x20'+'E_ONCE_TRIGGERED).\x20The\x20kernel\x20injects\x20254\x20ONLY\x20for\x20GuardIdentifier(254)-recipient\x20rails.'+(Y['recipient']==='guard_identifier'&&Y['recipient_key']!=='254'?'\x20This\x20rail\x27s\x20recipient\x20is\x20GuardIdentifier('+(Y['recipient_key']??'0')+')\x20—\x20the\x20inline\x20table\x20MUST\x20'+('declare\x20slot\x20'+(Y['recipient_key']??'0')+'\x20as\x20an\x20Address\x20submission\x20instead\x20(N-K21:\x20the\x20passport\x20')+'submits\x20the\x20ORDER\x20address\x20into\x20it;\x20an\x20undeclared\x20slot\x20makes\x20the\x20rail\x20unexecutable).':''):'')+(a0?'\x20ADVISORY\x20DESIGN\x20(run75747\x20F-38):\x20nothing\x20in\x20this\x20archetype\x20binds\x20this\x20key\x20—\x20no\x20machine\x20edge,\x20allocator\x20'+'rail,\x20repository\x20policy,\x20or\x20service\x20mount.\x20If\x20this\x20design\x20does\x20not\x20apply\x20to\x20your\x20shop\x20you\x20may\x20resolve\x20'+'it\x20with\x20{\x20kind:\x20\x27omit\x27\x20}\x20instead\x20of\x20building\x20a\x20Guard\x20no\x20one\x20consumes:\x20the\x20design\x20leaves\x20'+'pending_guard_designs,\x20no\x20Guard\x20object\x20is\x20created,\x20and\x20the\x20decision\x20is\x20recorded\x20in\x20the\x20build\x27s\x20'+'warnings.\x20An\x20omit\x20of\x20a\x20BOUND\x20design\x20is\x20refused\x20(GUARD_OMIT_UNSUPPORTED).':'')};}),I=B['length']>0x0||q['blocking'],J={'expiredTerminal':(j['machine_shape']??[])['some'](T=>/expire|deadline|timeout/i['test'](String(T?.['name']??'')))},K=checkGameTheoryConstraints(s,f,J),L=assessWorkflowDesign(s),M=buildCreationPlan(s),N=j?{'name':j['id'],'display_name':j['variant']+'\x20archetype\x20('+j['industry']+')','source':a['template_override']?'custom':'builtin','risk_appetite':'medium','key_risk':j['key_risk'],'machine_shape':j['machine_shape']['map'](T=>({'name':T['name'],'role':T['role'],...T['operator']?{'operator':T['operator']}:{},...T['semantic_role']?{'semantic_role':T['semantic_role']}:{}})),'guards':j['guards']['map'](T=>({'template_id':T['template_id'],'host':T['host'],'purpose':T['purpose']})),'allocator':j['allocator'],'risk_constraints':{},'build_notes':j['build_notes']??[],...j['time_anchors']?{'time_anchors':j['time_anchors']}:{}}:undefined;return{'action':'merchant_guide','current_step':I?0x9:0xa,'step_name':I?'Harness\x20Check\x20(issues\x20found)':'Submission\x20Plan\x20Ready','guide_state':{...d,'adopted_module_ids':i['map'](T=>T['id'])},'intent':{'intent_type':f['intent'],'industry':f['industry'],'roles':f['roles'],'deliverables':f['deliverables'],'payment':f['payment'],'trust':f['trust']},'adopted_modules':i['map'](T=>({'id':T['id'],'name':T['name'],'description':T['description'],'requires_keeper':T['requiresKeeper'],'keeper_hint':T['keeperHint'],'user_protections':T['userProtections'],'merchant_obligations':T['merchantObligations']})),'mode_prior':N,...N?.['time_anchors']?{'time_anchor_instructions':Object['entries'](N['time_anchors'])['map'](([T,U])=>{const V=U['startsWith']('order.time')?'\x20(order-creation\x20time\x20—\x20PRE-checkout\x20branches\x20only;\x20a\x20post-checkout\x20window\x20anchored\x20here\x20is\x20unreachable)':U['startsWith']('progress.current_time')?'\x20(entry\x20time\x20of\x20the\x20window\x27s\x20source\x20node\x20—\x20witness-derived\x20via\x20OrderProgress,\x20one\x20Guard\x20serves\x20every\x20order)':U['startsWith']('absolute_date')?'\x20(per-order\x20instance\x20Guard\x20—\x20the\x20absolute\x20date\x20differs\x20per\x20booking)':'';return'Time\x20windows\x20for\x20\x27'+T+'\x27\x20anchor\x20to\x20'+U+V;})}:{},'blueprint':{'nodes':s['nodes']['map'](T=>({'id':T['id'],'type':T['type'],'purpose':T['purpose']})),'edges':s['edges']['map'](T=>({'from':T['from'],'to':T['to'],'relation':T['relation'],'required':T['required']}))},'evaluation_preview':{'estimatedRiskScore':r,'estimatedCompletenessScore':Math['min'](0x64,0x1e+i['length']*0x8),'keyRisks':q['findings']['filter'](T=>T['level']==='critical'||T['level']==='high')['map'](T=>T['title']),'strengths':q['findings']['filter'](T=>T['level']==='info')['map'](T=>T['title']),'moduleBoosts':{}},'graph_validation':{'valid':q['issues']['length']===0x0,'hard_violations':q['issues']['map'](T=>({'id':T['code'],'description':T['detail'],'fix':'Fix\x20the\x20Plan\x20structure'})),'soft_notes':q['findings']['filter'](T=>T['level']==='medium'||T['level']==='low')['map'](T=>({'id':T['rule_id'],'description':T['title']}))},'harness_check':{'module_constraints':w['map'](T=>{const U=T['module']==='discount_lifecycle'&&T['adopted']?'ADOPTION-BASED\x20satisfaction\x20(disclosure\x20obligations\x20accepted\x20with\x20module\x20adoption),\x20NOT\x20plan\x20structure:\x20creation_plan\x20intentionally\x20carries\x20no\x20Discount/SKU\x20nodes\x20—\x20they\x20are\x20minted\x20in\x20merchant\x20post-deploy\x20steps\x20and\x20verified\x20on-chain\x20after\x20deploy\x20(query\x20the\x20minted\x20Service.discount).\x20Reward\x20FUNDING\x20rides\x20review_mode\x20compile\x20emission,\x20BUT\x20the\x20reward\x20claim\x20GUARD\x20SPEC\x20must\x20still\x20be\x20declared\x20in\x20the\x20plan\x27s\x20guards[]\x20(host:\x27reward\x27)\x20—\x20compile\x20emits\x20the\x20rail\x20only\x20from\x20that\x20spec,\x20and\x20REVIEW_REWARD_GUARD_MISSING\x20hard-blocks\x20publish\x20when\x20it\x20is\x20omitted\x20(G-02,\x20onlyfans-mn\x20261019:\x20the\x20old\x20prose\x20denied\x20the\x20guard\x20spec\x20and\x20deadlocked\x20every\x20reward\x20publish).':T['reason'],V=T['evidence_matched']===![]?''+(U?U+'\x20':'')+'Adopted\x20WITHOUT\x20explicit\x20intent\x20evidence\x20(score-based\x20auto-recommendation\x20only):\x20estimated_score_boost\x20recorded\x20as\x200.\x20Keep\x20it\x20deliberately\x20or\x20drop\x20it\x20via\x20guide_state.adopted_module_ids.':U;return{'module':T['module'],'plan_satisfied':T['adopted'],'missing':T['missingConstraints'],'reason':V,'estimated_score_boost':T['estimatedScoreBoost'],'evidence_matched':T['evidence_matched']};}),'blocking_issues':[...w['filter'](T=>!T['adopted'])['map'](T=>({'module':T['module'],'missing_constraints':T['missingConstraints'],'fix':T['reason']})),...t['map'](T=>({'module':T['module'],'missing_constraints':T['missing_constraints'],'fix':T['fix']})),...C],'deploy_time_checks':y,'recipient_design_guidance':A},'game_theory':{'summary':K['summary'],'coverage':K['coveredCount']+'/'+K['totalCount'],'exposed_scenarios':K['exposedScenarios'],'wow_alignments':K['wowAlignments'],'scenarios':K['results']['map'](T=>({'scenario':T['scenario'],'covered':T['covered'],'conflict':T['conflict'],'user_protection':T['userProtection'],'evaluation_metric':T['evaluationMetric'],'recommendation':T['recommendation']}))},'workflow_design_assessment':{'score':L['score'],'summary':L['summary'],'findings':L['findings']['map'](T=>({'kind':T['kind'],'severity':T['severity'],'message':T['message'],'fix':T['fix']})),'checks':L['checks']['map'](T=>({'id':T['id'],'dimension':T['dimension'],'passed':T['passed'],'severity':T['severity'],'message':T['message'],'fix':T['fix']}))},'creation_plan':M,'post_deploy_steps':z,...H['length']>0x0?{'pending_guard_designs':H}:{},...H['length']>0x0&&(p['pending_guards']?.['length']??0x0)!==H['length']?{'pending_count_note':'Two\x20counts,\x20two\x20views:\x20pending_guard_designs\x20lists\x20'+H['length']+'\x20unresolved\x20design(s)\x20(compile\x20view\x20—\x20includes\x20advisory\x20designs\x20with\x20no\x20edge/rail/policy/buy\x20mount);\x20'+('the\x20plan\x20audit\x20counts\x20'+(p['pending_guards']?.['length']??0x0)+'\x20(plan\x20view\x20—\x20site-bound\x20designs\x20only;\x20the\x20rule-pack\x20titles\x20\x22of\x20N\x20pending\x20in\x20total\x22\x20quote\x20this).\x20')+'The\x20LIST\x20is\x20the\x20resolution\x20fill\x20space;\x20the\x20audit\x20number\x20is\x20its\x20site-bound\x20subset.'}:{},'warnings':[...e['warnings'],...n['omitted']['length']>0x0?['Advisory\x20guard\x20design(s)\x20omitted\x20by\x20decision\x20({kind:\x27omit\x27}):\x20'+n['omitted']['join'](',\x20')+'\x20—\x20'+'no\x20Guard\x20created,\x20nothing\x20binds\x20them\x20(run75747\x20F-38).']:[]],'next_action':B['length']>0x0?'Resolve\x20the\x20blocking_issues\x20above\x20(adjust\x20guide_confirm\x20payment/trust/modules,\x20or\x20accept\x20and\x20drop\x20the\x20affected\x20module\x20via\x20guide_confirm.adopted_module_ids),\x20then\x20call\x20merchant_guide\x20again.':q['blocking']?'The\x20plan\x20audit\x20is\x20BLOCKING\x20(see\x20harness_check.blocking_issues\x20and\x20audit.findings\x20—\x20e.g.\x20a\x20terminal\x20node\x20with\x20no\x20fund\x20exit,\x20or\x20an\x20unresolved\x20guard\x20bound\x20to\x20a\x20fund\x20path).\x20Fix\x20the\x20plan/template\x20or\x20guard\x20resolutions\x20and\x20call\x20merchant_guide\x20again;\x20do\x20NOT\x20materialize\x20this\x20plan.'+(H['length']>0x0?'\x20Pending\x20guard\x20designs:\x20'+H['length']+'\x20listed\x20in\x20pending_guard_designs\x20—\x20resolve\x20each\x20via\x20guide_confirm.guard_resolutions\x20(kind\x20\x27inline\x27\x20with\x20the\x20Guard\x20table+root,\x20kind\x20\x27template\x27\x20with\x20a\x20tpl_*\x20id,\x20or\x20{kind:\x27omit\x27}\x20for\x20advisory\x20designs\x20that\x20do\x20not\x20apply\x20to\x20this\x20shop),\x20then\x20call\x20merchant_guide\x20again.':''):'Plan\x20ready.\x20Materialize:\x20create\x20the\x20objects\x20in\x20creation_plan\x20order\x20via\x20onchain_operations,\x20then\x20run\x20post_deploy_steps\x20in\x20order\x20('+z['map'](T=>T['id'])['join'](',\x20')+').\x20WIZARD\x20CONTRACT:\x20on\x20the\x20Service\x20publish\x20call\x20(data.publish=true),\x20pass\x20this\x20exact\x20plan\x20back\x20as\x20data.creation_plan\x20—\x20the\x20publish\x20gate\x20replays\x20its\x20freeze\x20matrix\x20and\x20rejects\x20the\x20publish\x20if\x20any\x20gate\x20fails;\x20omitting\x20it\x20leaves\x20the\x20manual\x20path\x20ungated.','plan':p,'audit':{'issues':q['issues'],'findings':q['findings'],'blocking':q['blocking'],'score':r},'reflux':{'applied':o['applied'],'blocks':o['blocks'],'iterations':o['iterations']}};}export function listBusinessModules(){return CORE_BUSINESS_MODULES['map'](a=>({'id':a['id'],'name':a['name'],'description':a['description'],'industry_fit':a['industryFit'],'addresses_pain_points':a['addressesPainPoints'],'requires_keeper':a['requiresKeeper']}));}
1
+ import{analyzeIntent}from'./intent-analyzer.js';import{compileTemplate}from'../../composition/compile.js';import{reflux,auditScore}from'../../composition/reflux.js';import{planBlueprint}from'../../composition/blueprint-view.js';import{getGuardDesignPattern}from'../../knowledge/guard-design-patterns.js';import{GUARD_TEMPLATES,getTemplatesByScene}from'../../knowledge/guard-templates.js';import{checkGameTheoryConstraints}from'./game-theory.js';import{assessWorkflowDesign}from'./workflow-design-assessment.js';import{CORE_BUSINESS_MODULES,getBusinessModule,recommendModules,checkModuleConstraints,moduleHasIntentEvidence}from'../../extensions/business-modules.js';import{recipientDesignGuidance}from'../../knowledge/recipient-constraint.js';import{getTemplate,getTemplatesByIndustry}from'../../knowledge/template-loader.js';import{getScenarioMode}from'../../knowledge/scenario-modes.js';function derivePlanSatisfiedConstraints(a,b){const c=new Set(),d=i=>a['edges']['some'](j=>j['relation']===i),e=i=>a['nodes']['some'](j=>j['id']===i),f=i=>a['nodes']['some'](j=>j['type']===i),g=i=>a['adoptedModules']['includes'](i);if(d('has_order_allocators'))c['add']('order_allocators_bound');if(d('uses_machine'))c['add']('machine_bound_before_publish');if(d('has_arbitration'))c['add']('arbitration_bound_to_service');if(e('machine'))c['add']('machine_published');if(e('repository'))c['add']('repository_published');if(e('service'))c['add']('service_published');e('permission_arb')&&e('permission')&&c['add']('arbitration_permission_independent');g('independent_arbitration')&&a['nodes']['some'](i=>i['id']['includes']('guard')&&i['id']['includes']('arbitration'))&&c['add']('voting_guard_configured');g('accept_timeout_protection')&&(c['add']('time_guard_configured'),c['add']('adminUnhold_permission'));g('milestone_escrow')&&f('guard')&&c['add']('milestone_forward_guarded');const h=d('has_order_allocators');if(h&&b['payment']['allocation']&&b['payment']['allocation']['length']>0x0){c['add']('allocators_configured');const i=b['payment']['allocation']['reduce']((k,l)=>k+l['percentage'],0x0);if(Math['abs'](i-0x64)<0.001)c['add']('sharing_sum_100');const j=b['payment']['allocation']['find'](k=>k['recipient']==='platform');if(!j||j['percentage']===0x0)c['add']('platform_fee_zero');g('supplier_collaboration')&&(c['add']('allocation_sharing_configured'),c['add']('demand_configured'));}g('wip_provenance')&&e('repository')&&c['add']('wip_hash_before_delivery');g('subscription_with_proof')&&e('repository')&&(c['add']('delivery_guard_per_cycle'),c['add']('repository_updated'));g('damage_attestation')&&(c['add']('pre_rental_hash'),c['add']('post_rental_hash'));g('refund_guarantee')&&(c['add']('compensation_fund_positive'),c['add']('refund_guard_configured'));if(g('praise_incentive')){const k=a['plan']['steps']['some'](m=>m['op']==='create'&&m['object']==='reward'),l=a['plan']['steps']['some'](m=>m['op']==='configure'&&m['method']==='coin_add');k&&l&&(c['add']('reward_pool_funded'),c['add']('reward_claim_replay_armed'));}g('discount_lifecycle')&&(c['add']('discount_budget_planned'),c['add']('discount_burn_disclosed'));if(g('after_sales_guarantee')){const m=a['plan']['steps']['find'](p=>p['op']==='create'&&p['object']==='machine'),n=m?.['params']?.['nodes']??[],o=n['some'](p=>/return|refund|exchange|replace|reship|swap|warranty|repair/i['test'](p['name']??''));o&&(c['add']('after_sales_rail_present'),c['add']('after_sales_polarity_pair'),c['add']('after_sales_window_anchored'),c['add']('after_sales_no_double_remedy'));}if(g('acceptance_judging')){const p=a['plan']['steps']['find'](t=>t['op']==='create'&&t['object']==='machine'),q=p?.['params']?.['nodes']??[],r=q['map'](t=>t['name']??''),s=r['some'](t=>/accept|approv|award|ruling|place|placement|triage|vot|evaluat|winner|judge/i['test'](t));if(s){const t=r['some'](u=>/revis|redeliver|resubmit|rework/i['test'](u));c['add']('acceptance_race_free');if(e('arbitration'))c['add']('acceptance_judge_independent');if(!t||e('repository'))c['add']('acceptance_revision_bounded');}}if(g('installment_deposit')){const u=a['plan']['steps']['find'](z=>z['op']==='create'&&z['object']==='machine'),v=u?.['params']?.['nodes']??[],w=v['map'](z=>z['name']??''),x=w['some'](z=>/(deposit|down_?pay|balance_due|balance_owed|installment|milestone|awaiting|owed)/i['test'](z)),y=w['some'](z=>/(paid|funded|captured|settled)/i['test'](z));x&&y&&(c['add']('installment_funding_gated'),c['add']('installment_deposit_exit'),c['add']('installment_release_once'));}if(g('affiliate_commission')){const z=a['plan']['steps']['find'](D=>D['op']==='create'&&D['object']==='machine'),A=z?.['params']?.['nodes']??[],B=A['map'](D=>D['name']??''),C=B['some'](D=>/(commission|affiliate|referr|attribut|partner_?payout)/i['test'](D));C&&(c['add']('affiliate_rail_present'),c['add']('affiliate_clawback_disclosed'),c['add']('affiliate_window_anchored'));}if(g('crowdfunding')){const D=a['plan']['steps']['find'](H=>H['op']==='create'&&H['object']==='machine'),E=D?.['params']?.['nodes']??[],F=E['map'](H=>H['name']??''),G=F['some'](H=>/(releas|settle|funded|disburs|project)/i['test'](H));G&&(c['add']('crowdfunding_exit_rail_present'),c['add']('crowdfunding_aggregate_writer_bound'),c['add']('crowdfunding_disclosure_present'));}if(g('logistics_fulfillment')){const H=a['plan']['steps']['find'](L=>L['op']==='create'&&L['object']==='machine'),I=H?.['params']?.['nodes']??[],J=I['map'](L=>L['name']??''),K=J['some'](L=>/(dispatch|handover|hand_over|pickup|deliver|courier|rider|shipped)/i['test'](L));K&&(c['add']('logistics_rail_present'),c['add']('logistics_loss_covered'),c['add']('logistics_fee_independent'),c['add']('logistics_dispatch_disclosed'));}return c;}function deriveDeployTimeChecks(a,b=![]){const c=[];return a['nodes']['some'](d=>d['id']==='machine')&&c['push']('Machine\x20published\x20AND\x20bound\x20to\x20Service\x20BEFORE\x20Service.publish\x20(machine\x20is\x20immutable\x20after\x20publish)'),a['edges']['some'](d=>d['relation']==='has_order_allocators')&&(c['push']('Service.order_allocators\x20bound\x20(verify\x20via\x20query_objects\x20after\x20publish\x20—\x20order_allocators\x20is\x20FROZEN\x20at\x20publish)'),c['push']('Settlement\x20is\x20NOT\x20triggered\x20by\x20reaching\x20a\x20Machine\x20node\x20alone\x20—\x20an\x20explicit\x20alloc_by_guard\x20call\x20(keeper\x20or\x20merchant)\x20fires\x20the\x20settlement\x20Allocator\x20once\x20its\x20Guard\x20passes.\x20Declare\x20the\x20node->allocator\x20trigger\x20(which\x20terminal\x20node\x20unlocks\x20settlement)\x20and\x20schedule\x20the\x20keeper\x20step;\x20otherwise\x20orders\x20stall\x20at\x20the\x20settle\x20node\x20with\x20allocation_state=pending')),(a['adoptedModules']['includes']('refund_guarantee')||a['nodes']['some'](d=>d['id']==='arbitration'))&&(b?c['push']('COMPENSATION\x20FUND:\x20DO\x20NOT\x20FUND\x20—\x20this\x20template\x20declares\x20compensation_fund_policy=forbidden\x20(the\x20unreserved\x20pool\x20is\x20double-takeable\x20via\x20refund-then-claim\x20until\x20the\x20arbitration-escrow\x20shared\x20gate\x20lands;\x20user\x20ruling\x202026-10-15).\x20Disputes\x20ride\x20the\x20escrow\x20rails\x20only;\x20the\x20compensation_fund_topup\x20post-deploy\x20step\x20is\x20intentionally\x20absent'):c['push']('compensation_fund\x20MUST\x20be\x20able\x20to\x20cover\x20payouts:\x20a\x20claim\x20against\x20a\x20drained\x20fund\x20aborts\x20(service.move\x20E_COMPENSATION_NOT_MATCH).\x20Size\x20the\x20fund\x20>=\x203x\x20a\x20TYPICAL\x20single\x20order\x20(3x\x20IS\x20the\x20chain\x27s\x20hard\x20award\x20ceiling,\x20MAX_INDEMNITY_MULTIPLE)\x20—\x20per-order\x20coverage\x20is\x20enforced\x20at\x20BUY\x20time\x20(each\x20order\x20is\x20checked\x20against\x203x\x20ITS\x20OWN\x20amount,\x20not\x203x\x20the\x20highest\x20SKU),\x20so\x20publish\x20no\x20longer\x20blocks\x20on\x20coverage;\x20verify\x20the\x20on-chain\x20balance\x20before\x20going\x20live.\x205R-07③:\x20after\x20go-live\x20the\x20keeper\x20WATCHES\x20the\x20water\x20level\x20(see\x20the\x20compensation_fund_watch\x20step)\x20—\x20no\x20hard\x20gate,\x20the\x20merchant\x20decides')),a['nodes']['some'](d=>d['id']==='arbitration')&&(c['push']('Arbitration.permission\x20!=\x20Service.permission\x20on-chain\x20(E_ARBITRATION_PERMISSION_CONFLICT=33)'),c['push']('A\x20freshly\x20created\x20Arbitration\x20defaults\x20to\x20PAUSED\x20—\x20unpause\x20it\x20(arbitration\x20activation)\x20before\x20the\x20first\x20case\x20can\x20be\x20filed,\x20otherwise\x20dispute\x20filing\x20aborts'),c['push']('ARBITRATION\x20VENUE\x20OWNERSHIP\x20(D-5):\x20the\x20recommended\x20onboarding\x20default\x20is\x20a\x20SELF-BUILT\x20venue\x20—\x20your\x20own\x20Arbitration\x20object\x20with\x20your\x20own\x20permission/admin\x20(voting_guard\x20tpl_voting_guard_open_vote\x20for\x20community\x20cases,\x20tpl_voting_guard_numeric_weight\x20for\x20a\x20named\x20panel).\x20A\x20THIRD-PARTY\x20venue\x20you\x20do\x20not\x20control\x20hands\x20the\x20private\x20key\x20that\x20answers\x20and\x20appeals\x20cases\x20to\x20its\x20operator:\x20an\x20outside\x20store\x27s\x20admin\x20going\x20silent\x20strands\x20your\x20defense\x20(F-16,\x20live-proven).\x20Use\x20an\x20outside\x20venue\x20ONLY\x20when\x20its\x20operator\x20is\x20a\x20named,\x20reachable\x20counterparty\x20the\x20merchant\x20accepts')),a['nodes']['some'](d=>d['id']==='repository')&&c['push']('Repository\x20published\x20and\x20Guard\x20write\x20validation\x20configured'),c['push']('After\x20materialization,\x20confirm\x20the\x20on-chain\x20state\x20matches\x20this\x20plan\x20(query_toolkit\x20query_type=\x27service_panorama\x27)'),c;}function derivePostDeploySteps(a,b=![]){const c=[];return!b&&(a['adoptedModules']['includes']('refund_guarantee')||a['nodes']['some'](d=>d['id']==='arbitration'))&&(c['push']({'order':c['length']+0x1,'id':'compensation_fund_topup','title':'Top\x20up\x20the\x20compensation\x20fund','when':'After\x20the\x20Service\x20object\x20is\x20created,\x20BEFORE\x20the\x20service\x20goes\x20live\x20(before\x20the\x20first\x20order)','action':'Call\x20compensation_fund_add\x20sized\x20>=\x203x\x20a\x20TYPICAL\x20single\x20order\x20(3x\x20=\x20the\x20chain\x27s\x20hard\x20award\x20ceiling,\x20MAX_INDEMNITY_MULTIPLE;\x20above\x203x\x20only\x20buys\x20headroom\x20for\x20concurrent\x20claims).\x20Per-order\x20coverage\x20is\x20enforced\x20at\x20BUY\x20time\x20—\x20each\x20incoming\x20order\x20is\x20checked\x20against\x203x\x20ITS\x20OWN\x20amount\x20and\x20under-covered\x20orders\x20cannot\x20be\x20created\x20—\x20then\x20verify\x20the\x20on-chain\x20fund\x20balance\x20via\x20query_objects','tool_hint':'onchain_operations\x20(service.compensation_fund_add)','failure_if_skipped':'a\x20compensation\x20claim\x20against\x20an\x20empty\x20fund\x20aborts\x20(E_COMPENSATION_NOT_MATCH,\x20testnet\x20lesson\x20R-4)'}),c['push']({'order':c['length']+0x1,'id':'compensation_fund_watch','title':'Watch\x20the\x20compensation-fund\x20water\x20level\x20(recurring\x20keeper\x20step)','when':'Recurring\x20—\x20on\x20every\x20keeper\x20cycle\x20after\x20go-live,\x20and\x20ALWAYS\x20immediately\x20after\x20each\x20arbitration\x20payout\x20posts','action':'Query\x20the\x20on-chain\x20fund\x20balance\x20and\x20classify\x20it\x20with\x20classifyFundWaterLevel(balance,\x20low_water_threshold)\x20into\x20THREE\x20tiers:\x20HEALTHY\x20(balance\x20>=\x20threshold\x20—\x20silence\x20is\x20the\x20healthy\x20signal,\x20no\x20event)\x20/\x20LOW\x20WATER\x20(0\x20<\x20balance\x20<\x20threshold\x20—\x20surface\x20fundWaterReminder:\x20recommend\x20topping\x20up\x20via\x20compensation_fund_add;\x20one\x20large\x20award\x20could\x20make\x20a\x20flagship\x20SKU\x20unbuyable,\x20F-46)\x20/\x20DEPLETED\x20(balance\x200\x20—\x20surface\x20fundWaterReminder\x20LOUD:\x20every\x20claim\x20aborts\x2027\x20and\x20under-covered\x20SKUs\x20are\x20unbuyable).\x20Thresholds\x20are\x20the\x20MERCHANT\x27s\x20call\x20(decision\x207)\x20—\x20recommended\x20anchor:\x20low-water\x20line\x20at\x203x\x20the\x20flagship\x20SKU\x20price\x20(below\x20it\x20the\x20flagship\x20can\x20no\x20longer\x20be\x20bought),\x20healthy\x20line\x20at\x203x\x20the\x20typical\x20order.\x20NEVER\x20block\x20a\x20SKU\x20or\x20gate\x20a\x20claim\x20on\x20the\x20tier\x20—\x20the\x20reminder\x20is\x20the\x20whole\x20feature;\x20the\x20merchant\x20decides\x20(top\x20up\x20/\x20accept\x20the\x20exposure)','tool_hint':'query_toolkit\x20(service_panorama:\x20fund\x20balance)\x20+\x20knowledge/fund-layer\x20classifyFundWaterLevel\x20+\x20onchain_operations\x20(service.compensation_fund_add)\x20on\x20the\x20merchant\x27s\x20decision','failure_if_skipped':'a\x20drained\x20or\x20low\x20fund\x20is\x20SILENT\x20—\x20the\x20first\x20signal\x20is\x20a\x20buyer\x27s\x20claim\x20aborting\x20(27)\x20or\x20a\x20flagship\x20SKU\x20failing\x20to\x20sell\x20(buy-time\x203x\x20coverage\x20refusal,\x20F-46)'})),a['nodes']['some'](d=>d['id']==='arbitration')&&(c['push']({'order':c['length']+0x1,'id':'arbitration_unpause','title':'Activate\x20the\x20Arbitration\x20(unpause)','when':'Immediately\x20after\x20the\x20Arbitration\x20object\x20is\x20created,\x20before\x20the\x20first\x20dispute\x20is\x20filed','action':'Unpause/activate\x20the\x20Arbitration\x20so\x20dispute\x20filing\x20is\x20accepted;\x20keep\x20its\x20Permission\x20distinct\x20from\x20the\x20Service\x20Permission\x20(E_ARBITRATION_PERMISSION_CONFLICT=33)','tool_hint':'onchain_operations\x20(arbitration\x20activation)','failure_if_skipped':'a\x20freshly\x20created\x20Arbitration\x20defaults\x20to\x20PAUSED\x20—\x20dispute\x20filing\x20aborts\x20(testnet\x20lesson\x20R-5)'}),c['push']({'order':c['length']+0x1,'id':'voting_guard_open_vote','title':'Bind\x20the\x20open-vote\x20voting_guard\x20(tpl_voting_guard_open_vote)','when':'After\x20the\x20Arbitration\x20is\x20activated,\x20BEFORE\x20the\x20first\x20dispute\x20can\x20be\x20voted\x20on','action':'Create\x20the\x20open-vote\x20guard\x20(tpl_voting_guard_open_vote:\x20always-true\x20root\x20+\x20FixedValue\x20weight\x201\x20=\x20one\x20person\x20one\x20vote)\x20and\x20set\x20it\x20as\x20the\x20Arbitration\x27s\x20voting_guard;\x20skip\x20this\x20step\x20ONLY\x20for\x20a\x20deliberately\x20closed\x20panel\x20(then\x20bind\x20tpl_voting_guard_numeric_weight\x20with\x20the\x20arbitrator\x20address\x20list\x20instead)','tool_hint':'onchain_operations\x20(guard\x20creation\x20+\x20arbitration\x20voting_guard\x20set,\x20op=\x27set\x27)','failure_if_skipped':'an\x20EMPTY\x20voting_guard\x20dead-locks\x20every\x20plain\x20vote\x20on\x20permission\x20358\x20(creator-admin\x20only)\x20—\x20the\x20first\x20dispute\x20cannot\x20reach\x20a\x20verdict\x20if\x20the\x20admin\x20is\x20unresponsive\x20(crs9-F-36,\x20R-ARB-VOTE-LOCK)'})),a['edges']['some'](d=>d['relation']==='has_order_allocators')&&c['push']({'order':c['length']+0x1,'id':'settlement_alloc_by_guard','title':'Fire\x20settlement\x20via\x20alloc_by_guard\x20(keeper/merchant\x20step)','when':'Recurring\x20—\x20after\x20EACH\x20order\x20reaches\x20its\x20settlement\x20terminal\x20node\x20(declare\x20which\x20node\x20unlocks\x20settlement)','action':'Call\x20alloc_by_guard\x20on\x20the\x20order\x27s\x20allocation\x20with\x20the\x20settlement\x20Guard;\x20reaching\x20the\x20Machine\x20node\x20alone\x20does\x20NOT\x20settle\x20(allocation_state\x20stays\x20pending)','tool_hint':'onchain_operations\x20(allocation.alloc_by_guard);\x20schedule\x20as\x20a\x20keeper\x20step','failure_if_skipped':'orders\x20stall\x20at\x20the\x20settle\x20node\x20with\x20funds\x20locked\x20in\x20escrow\x20(testnet\x20lesson\x20R-2)'}),c['push']({'order':c['length']+0x1,'id':'verify_service_panorama','title':'Verify\x20the\x20on-chain\x20state\x20matches\x20the\x20plan','when':'After\x20all\x20creation\x20steps\x20and\x20the\x20steps\x20above\x20are\x20done','action':'Run\x20the\x20service\x20panorama\x20query\x20and\x20diff\x20it\x20against\x20this\x20plan\x27s\x20blueprint/creation_plan','tool_hint':'query_toolkit\x20query_type=\x27service_panorama\x27','failure_if_skipped':'plan/chain\x20drift\x20(missing\x20binding,\x20wrong\x20allocator\x20order)\x20stays\x20undetected\x20until\x20an\x20order\x20hits\x20it'}),c;}function buildCreationPlan(a){const b=[],c=new Map(a['nodes']['map'](k=>[k['id'],k])),f=new Map();for(const k of a['nodes'])f['set'](k['id'],new Set());for(const l of a['edges']){if(!f['has'](l['from'])||!c['has'](l['to']))continue;const m=l['relation']==='has_guard'?l['to']:l['from'],o=l['relation']==='has_guard'?l['from']:l['to'];if(m===o||!f['has'](m))continue;f['get'](m)['add'](o);}for(const p of a['nodes']){for(const q of Object['values'](p['config'])){q['type']==='address_ref'&&q['targetId']!==p['id']&&f['has'](q['targetId'])&&f['get'](p['id'])['add'](q['targetId']);}}const g=a['nodes']['filter'](r=>r['type']==='service')['map'](r=>r['id']);if(g['length']>0x0)for(const r of a['nodes']){if(r['type']!=='guard')continue;const s=f['get'](r['id']);if(s===undefined)continue;for(const t of g)s['add'](t);}const h=new Map([...f]['map'](([u,v])=>[u,[...v]])),i=[],j=new Map(f);while(j['size']>0x0){const u=[...j['entries']()]['filter'](([,v])=>v['size']===0x0)['map'](([v])=>v);if(u['length']===0x0){i['push'](...j['keys']());break;}u['sort']();for(const v of u){i['push'](v),j['delete'](v);for(const w of j['values']())w['delete'](v);}}return i['forEach']((x,y)=>{const z=c['get'](x),A=z['config']['name'],B=A?.['type']==='string'?A['value']:x,C=B['includes']('/')?B['replaceAll']('/','__'):B;b['push']({'order':y+0x1,'node_id':x,'object_type':z['type'],'suggested_name':C,'depends_on':h['get'](x)??[],'operation_hint':'Create\x20'+z['type']+'\x20via\x20onchain_operations,\x20then\x20configure.\x20Purpose:\x20'+z['purpose']});}),b;}function resolveTemplate(a,b){if(!a)return undefined;const c=getTemplate(a);if(c)return c;const d=getTemplatesByIndustry(a);if(b){const f=b['toLowerCase'](),g=d['filter'](h=>{const i=String(h['product_ref']??'')['trim']()['toLowerCase']();return i['length']>0x0&&f['includes'](i);});if(g['length']===0x1)return g[0x0];}const e=getScenarioMode(a)?.['default_template'];if(e){const h=getTemplate(e);if(h)return h;}if(d['length']>0x0)return d[0x0];return undefined;}export async function handleMerchantGuide(a){const b=a['guide_state']??{'intent_text':''},c=a['guide_confirm']??{},d={'intent_text':(a['intent']??b['intent_text']??'')['trim'](),'confirmed_industry':c['industry']??b['confirmed_industry'],'currency':c['currency']??b['currency'],'deliverables':c['deliverables']??b['deliverables'],'payment_override':c['payment']??b['payment_override'],'trust_override':c['trust']??b['trust_override'],'adopted_module_ids':c['adopted_module_ids']??b['adopted_module_ids'],'guard_resolutions':{...b['guard_resolutions']??{},...c['guard_resolutions']??{}},'review_mode':c['review_mode']??b['review_mode'],'reward_funding':c['reward_funding']??b['reward_funding'],'reward_claim_amount':c['reward_claim_amount']??b['reward_claim_amount'],'after_sales_mode':c['after_sales_mode']??b['after_sales_mode'],'acceptance_mode':c['acceptance_mode']??b['acceptance_mode'],'installment_mode':c['installment_mode']??b['installment_mode'],'affiliate_mode':c['affiliate_mode']??b['affiliate_mode'],'crowdfunding_mode':c['crowdfunding_mode']??b['crowdfunding_mode'],'logistics_mode':c['logistics_mode']??b['logistics_mode'],'sales':c['sales']??b['sales']};for(const O of Object['keys'](d)){if(d[O]===undefined)delete d[O];}if(d['guard_resolutions']&&Object['keys'](d['guard_resolutions'])['length']===0x0)delete d['guard_resolutions'];if(!d['intent_text'])throw new Error('merchant_guide\x20requires\x20\x27intent\x27\x20(business\x20description)\x20for\x20Step\x201.\x20'+'Example:\x20intent=\x27I\x20want\x20to\x20offer\x20online\x20design\x20service\x20with\x20milestone\x20payments\x27.\x20'+'Pass\x20the\x20returned\x20guide_state\x20back\x20UNCHANGED\x20on\x20subsequent\x20calls,\x20plus\x20guide_confirm\x20for\x20merchant\x20decisions.');const e=await analyzeIntent(d['intent_text'],{'preferredIndustry':d['confirmed_industry'],'currency':d['currency']});if(!d['confirmed_industry'])return{'action':'merchant_guide','current_step':0x2,'step_name':'Industry\x20Matching','guide_state':d,'intent_draft':e['intent'],'industry_options':{'inferred':e['inferredIndustry'],'confidence':e['industryConfidence'],'similar':e['similarIndustries']},'warnings':e['warnings'],'next_action':'Confirm\x20the\x20industry\x20by\x20calling\x20merchant_guide\x20again\x20with\x20guide_state\x20(UNCHANGED)\x20'+('plus\x20guide_confirm={\x20industry:\x20\x27<one\x20of:\x20'+e['similarIndustries']['join'](',\x20')+'\x20—\x20or\x20any\x20other\x20industry\x20id>\x27\x20}')};const f={...e['intent'],'industry':d['confirmed_industry'],'deliverables':d['deliverables']??e['intent']['deliverables'],'payment':{...e['intent']['payment'],...d['payment_override']??{}},'trust':{...e['intent']['trust'],...d['trust_override']??{}}},h=!!d['adopted_module_ids'],i=d['adopted_module_ids']?d['adopted_module_ids']['map'](P=>getBusinessModule(P))['filter'](P=>!!P):recommendModules(d['confirmed_industry'],d['intent_text'],{'maxModules':0x5}),j=a['template_override']??resolveTemplate(d['confirmed_industry'],d['intent_text']);if(!j)throw new Error('No\x20compilable\x20template\x20found\x20for\x20industry\x20\x27'+d['confirmed_industry']+'\x27.\x20'+'Register\x20a\x20template\x20via\x20industry_pack_operation\x20or\x20pass\x20template_override\x20explicitly.');const l={'currency':d['currency']??f['payment']['currency'],...d['payment_override']?{'payment':d['payment_override']}:{},...d['trust_override']?{'trust':d['trust_override']}:{},...d['deliverables']?{'deliverables':d['deliverables']}:{},...d['adopted_module_ids']?{'adopted_module_ids':d['adopted_module_ids']}:{},...d['review_mode']?{'review_mode':d['review_mode']}:{},...d['reward_funding']!==undefined?{'reward_funding':d['reward_funding']}:{},...d['reward_claim_amount']!==undefined?{'reward_claim_amount':d['reward_claim_amount']}:{},...d['after_sales_mode']?{'after_sales_mode':d['after_sales_mode']}:{},...d['acceptance_mode']?{'acceptance_mode':d['acceptance_mode']}:{},...d['installment_mode']?{'installment_mode':d['installment_mode']}:{},...d['affiliate_mode']?{'affiliate_mode':d['affiliate_mode']}:{},...d['crowdfunding_mode']?{'crowdfunding_mode':d['crowdfunding_mode']}:{},...d['logistics_mode']?{'logistics_mode':d['logistics_mode']}:{},...d['sales']?.['length']?{'sales':d['sales']}:{}},m={};for(const P of i){for(const Q of P['templateRefs']){if(Q['object_type']!=='guard')continue;const R=j['guards']['filter'](S=>S['template_id']===Q['template_id']);if(R['length']===0x0)continue;for(const S of R){m[S['key']??Q['template_id']+'#'+j['guards']['indexOf'](S)]={'kind':'template','template_id':Q['template_id']};}}}Object['assign'](m,d['guard_resolutions']??{});const n=compileTemplate(j,l,{'nameBase':a['name_base']??j['id'],'intent':d['intent_text'],'guardResolutions':m}),o=reflux(n['plan']),p=o['plan'],q=o['audit'],r=auditScore(q),s=planBlueprint(p,f,i['map'](T=>T['id'])),t=n['blockers']['map'](T=>({'module':'template','missing_constraints':[T['code']],'fix':T['detail']})),u=derivePlanSatisfiedConstraints(s,f),w=i['map'](T=>checkModuleConstraints(T,u,{'evidenceMatched':h||moduleHasIntentEvidence(T,d['intent_text'])})),x=j['compensation_fund_policy']==='forbidden',y=deriveDeployTimeChecks(s,x),z=derivePostDeploySteps(s,x),A=s['edges']['some'](T=>T['relation']==='has_order_allocators')?recipientDesignGuidance()['map'](T=>({'id':T['id'],'move_recipient':T['move_recipient'],'semantics':T['semantics'],'required_constraints':T['required_constraints'],'finding_if_unmet':T['finding_if_unmet']})):undefined,B=[...w['filter'](T=>!T['adopted']),...t],C=q['findings']['filter'](T=>T['level']==='critical'||T['level']==='high')['map'](T=>({'module':'audit','missing_constraints':[T['rule_id']],'fix':T['title']+'\x20—\x20'+(T['mitigation']??T['description'])})),D=[{'re':/allocat|refund|recover|claimed_by|settle|escrow/i,'scene':'service_order_allocators_guard'},{'re':/\bbuy\b|purchase|allowlist|blocklist/i,'scene':'service_buy_guard'},{'re':/reward/i,'scene':'reward_claim'},{'re':/write_guard|repository_write/i,'scene':'repository_write_guard'},{'re':/arbitrat|ruling|voting/i,'scene':'arbitration_usage_guard'},{'re':/forward|node|witness|deliver|review|cancel|expire|submission|progress/i,'scene':'machine_forward_guard'}],E=[{'re':/claimed_by\s*some\s*==\s*true/i,'tpl':'tpl_allocator_node_gate_recover'},{'re':/claimed_by\s*some\s*==\s*false|claimed_by\s*(?:is\s+)?none|\brefund|\bcancel/i,'tpl':'tpl_allocator_node_gate_refund'},{'re':/claimed_by\s*some|\brecover|\baward/i,'tpl':'tpl_allocator_node_gate_recover'}],F=[{'host':'machine','re':/pattern\.time_lock_progress/i,'tpl':'tpl_time_lock_progress'},{'host':'machine','re':/pattern\.time_window_upper_bound/i,'tpl':'tpl_time_window_upper'},{'host':'reward','re':/pattern\./i,'tpl':'tpl_reward_one_time_claim'}],G=(T,U,V,W,X)=>{let Y;const Z=/tpl_[a-z0-9_]+/['exec'](T+'\x20'+U);Z!==null&&(Y=GUARD_TEMPLATES['find'](a4=>a4['id']===Z[0x0])?.['scene_id']);Y===undefined&&W!=='reward'&&/\ballocators?\b|claimed_by|guard_identifier|order_allocators/i['test'](U)&&(Y='service_order_allocators_guard');if(Y===undefined){if(W==='machine'||W==='machine_forward')Y='machine_forward_guard';else{if(W==='reward')Y='reward_claim';else{if(W==='repository')Y='repository_write_guard';else{if(W==='arbitration')Y='arbitration_usage_guard';else{const a4=D['find'](a5=>a5['re']['test'](T+'\x20'+U));Y=a4?.['scene'];}}}}}if(Y===undefined)return undefined;const a0=getTemplatesByScene(Y);let a1=V!==undefined&&a0['some'](a5=>a5['applicable_industries']['includes'](V))?a0['filter'](a5=>a5['applicable_industries']['includes'](V)):a0;if(/\btime[_-]?lock|\bwindow|\btimeout|\bduration|\bdeadline|\bdays?\b|\bclock|\bdelay/i['test'](T+'\x20'+U)){const a5=a1['filter'](a6=>JSON['stringify'](a6['example_root']??{})['toLowerCase']()['includes']('clock'));if(a5['length']===0x0)return undefined;a1=a5;}if(X['length']>0x0){const a6=Z!==null?a1['find'](a8=>a8['id']===Z[0x0]):undefined,a7=a1['filter'](a8=>{const a9=[];if(a8['example_root']!==undefined){const aa=JSON['stringify'](a8['example_root']);for(const ab of aa['matchAll'](/"query":"([^"]+)"/g))a9['push'](ab[0x1]);if(aa['includes']('\x22type\x22:\x22query_progress_history_time\x22'))a9['push']('progress.history.time');if(aa['includes']('\x22type\x22:\x22query_progress_history_find\x22'))a9['push']('progress.history.find');}return a9['some'](ac=>X['some'](ad=>ac===ad||ac['startsWith'](ad)||ad['startsWith'](ac)));});if(a6!==undefined&&!a7['includes'](a6))a7['push'](a6);if(a7['length']===0x0)return undefined;a1=a7;}const a2=W==='machine_forward'?'machine':W,a3=F['find'](a8=>a8['host']===a2&&a8['re']['test'](T+'\x20'+U)&&a1['some'](a9=>a9['id']===a8['tpl']));a3!==undefined&&(a1=[...a1]['sort']((a8,a9)=>(a8['id']===a3['tpl']?0x0:0x1)-(a9['id']===a3['tpl']?0x0:0x1)));if(Y==='service_order_allocators_guard'){const a8=E['find'](a9=>a9['re']['test'](T+'\x20'+U));a8!==undefined&&(a1=[...a1]['sort']((a9,aa)=>(a9['id']===a8['tpl']?0x0:0x1)-(aa['id']===a8['tpl']?0x0:0x1)));}return a1['slice'](0x0,0x3)['map'](a9=>({'template_id':a9['id'],'name':a9['name'],'parameters':a9['parameters']['map'](aa=>({'name':aa['name'],'required':aa['required'],...aa['default']!==undefined?{'default':aa['default']}:{},'description':aa['description']}))}));},H=n['unresolved']['map'](T=>{const U=getGuardDesignPattern(T['template_id']),V=G(T['template_id'],T['purpose'],j?.['industry'],T['host'],U?.['key_queries']??[]),W=new Set((j?.['machine_shape']??[])['flatMap'](a1=>(a1['from']??[])['map'](a2=>typeof a2==='string'?undefined:a2['guard_key'])['filter'](a2=>typeof a2==='string'))),X=new Map((j?.['allocator']['rows']??[])['filter'](a1=>typeof a1['guard_key']==='string')['map'](a1=>[a1['guard_key'],a1])),Y=X['get'](T['key']),Z=Y!==undefined&&!W['has'](T['key']),a0=!W['has'](T['key'])&&!X['has'](T['key'])&&T['policy']===undefined&&T['host']!=='reward'&&!(T['host']==='service'&&T['key']==='buy');return{'key':T['key'],'template_id':T['template_id'],'host':T['host'],'purpose':T['purpose'],...U?.['logic_summary']?{'logic_summary':U['logic_summary']}:{},...U?.['key_queries']?.['length']?{'key_queries':U['key_queries']}:{},...V!==undefined&&V['length']>0x0?{'suggested_templates':V}:{},'how_to_resolve':'guide_confirm.guard_resolutions[\x27'+T['key']+'\x27]\x20=\x20{\x20kind:\x20\x27inline\x27,\x20table,\x20root\x20}\x20(a\x20resolved\x20Guard),\x20'+'or\x20{\x20kind:\x20\x27template\x27,\x20template_id:\x20\x27tpl_*\x27,\x20params\x20}\x20when\x20a\x20guard\x20template\x20matches\x20this\x20design'+(V!==undefined&&V['length']>0x0?'\x20(suggested_templates\x20below\x20list\x20the\x20matching\x20executable\x20forms\x20and\x20their\x20parameters)':'.')+(T['host']==='machine'&&!Z?'\x20MACHINE-HOST\x20REQUIREMENT:\x20the\x20inline\x20table\x20MUST\x20declare\x20the\x20protocol\x20task-binding\x20slot\x20'+'{\x20identifier:\x20254,\x20b_submission:\x20true,\x20value_type:\x20\x22Address\x22\x20}\x20—\x20the\x20forward\x27s\x20passport\x20only\x20emits\x20'+'DECLARED\x20slots,\x20so\x20a\x20machine-forward\x20guard\x20without\x20this\x20row\x20aborts\x20EVERY\x20order-bound\x20forward\x20'+'it\x20gates\x20(code\x2011)\x20and\x20the\x20pre-publish\x20gate\x20blocks\x20the\x20Machine\x20publish.':'')+(Z?'\x20ALLOCATOR-RAIL\x20NOTE:\x20this\x20design\x20gates\x20an\x20allocator\x20rail\x20(not\x20a\x20machine\x20forward)\x20—\x20do\x20NOT\x20add\x20the\x20'+'254\x20task-binding\x20slot:\x20a\x20254\x20declaration\x20arms\x20once-per-order\x20replay\x20protection\x20at\x20alloc\x20time\x20'+'(allocation\x20ONCE_FOR_OBJECT)\x20and\x20permanently\x20blocks\x20multi-fire\x20rails\x20(a\x20second\x20release\x20aborts\x20'+'E_ONCE_TRIGGERED).\x20The\x20kernel\x20injects\x20254\x20ONLY\x20for\x20GuardIdentifier(254)-recipient\x20rails.'+(Y['recipient']==='guard_identifier'&&Y['recipient_key']!=='254'?'\x20This\x20rail\x27s\x20recipient\x20is\x20GuardIdentifier('+(Y['recipient_key']??'0')+')\x20—\x20the\x20inline\x20table\x20MUST\x20'+('declare\x20slot\x20'+(Y['recipient_key']??'0')+'\x20as\x20an\x20Address\x20submission\x20instead\x20(N-K21:\x20the\x20passport\x20')+'submits\x20the\x20ORDER\x20address\x20into\x20it;\x20an\x20undeclared\x20slot\x20makes\x20the\x20rail\x20unexecutable).':''):'')+(a0?'\x20ADVISORY\x20DESIGN\x20(run75747\x20F-38):\x20nothing\x20in\x20this\x20archetype\x20binds\x20this\x20key\x20—\x20no\x20machine\x20edge,\x20allocator\x20'+'rail,\x20repository\x20policy,\x20or\x20service\x20mount.\x20If\x20this\x20design\x20does\x20not\x20apply\x20to\x20your\x20shop\x20you\x20may\x20resolve\x20'+'it\x20with\x20{\x20kind:\x20\x27omit\x27\x20}\x20instead\x20of\x20building\x20a\x20Guard\x20no\x20one\x20consumes:\x20the\x20design\x20leaves\x20'+'pending_guard_designs,\x20no\x20Guard\x20object\x20is\x20created,\x20and\x20the\x20decision\x20is\x20recorded\x20in\x20the\x20build\x27s\x20'+'warnings.\x20An\x20omit\x20of\x20a\x20BOUND\x20design\x20is\x20refused\x20(GUARD_OMIT_UNSUPPORTED).':'')};}),I=B['length']>0x0||q['blocking'],J={'expiredTerminal':(j['machine_shape']??[])['some'](T=>/expire|deadline|timeout/i['test'](String(T?.['name']??'')))},K=checkGameTheoryConstraints(s,f,J),L=assessWorkflowDesign(s),M=buildCreationPlan(s),N=j?{'name':j['id'],'display_name':j['variant']+'\x20archetype\x20('+j['industry']+')','source':a['template_override']?'custom':'builtin','risk_appetite':'medium','key_risk':j['key_risk'],'machine_shape':j['machine_shape']['map'](T=>({'name':T['name'],'role':T['role'],...T['operator']?{'operator':T['operator']}:{},...T['semantic_role']?{'semantic_role':T['semantic_role']}:{}})),'guards':j['guards']['map'](T=>({'template_id':T['template_id'],'host':T['host'],'purpose':T['purpose']})),'allocator':j['allocator'],'risk_constraints':{},'build_notes':j['build_notes']??[],...j['time_anchors']?{'time_anchors':j['time_anchors']}:{}}:undefined;return{'action':'merchant_guide','current_step':I?0x9:0xa,'step_name':I?'Harness\x20Check\x20(issues\x20found)':'Submission\x20Plan\x20Ready','guide_state':{...d,'adopted_module_ids':i['map'](T=>T['id'])},'intent':{'intent_type':f['intent'],'industry':f['industry'],'roles':f['roles'],'deliverables':f['deliverables'],'payment':f['payment'],'trust':f['trust']},'adopted_modules':i['map'](T=>({'id':T['id'],'name':T['name'],'description':T['description'],'requires_keeper':T['requiresKeeper'],'keeper_hint':T['keeperHint'],'user_protections':T['userProtections'],'merchant_obligations':T['merchantObligations']})),'mode_prior':N,...N?.['time_anchors']?{'time_anchor_instructions':Object['entries'](N['time_anchors'])['map'](([T,U])=>{const V=U['startsWith']('order.time')?'\x20(order-creation\x20time\x20—\x20PRE-checkout\x20branches\x20only;\x20a\x20post-checkout\x20window\x20anchored\x20here\x20is\x20unreachable)':U['startsWith']('progress.current_time')?'\x20(entry\x20time\x20of\x20the\x20window\x27s\x20source\x20node\x20—\x20witness-derived\x20via\x20OrderProgress,\x20one\x20Guard\x20serves\x20every\x20order)':U['startsWith']('absolute_date')?'\x20(per-order\x20instance\x20Guard\x20—\x20the\x20absolute\x20date\x20differs\x20per\x20booking)':'';return'Time\x20windows\x20for\x20\x27'+T+'\x27\x20anchor\x20to\x20'+U+V;})}:{},'blueprint':{'nodes':s['nodes']['map'](T=>({'id':T['id'],'type':T['type'],'purpose':T['purpose']})),'edges':s['edges']['map'](T=>({'from':T['from'],'to':T['to'],'relation':T['relation'],'required':T['required']}))},'evaluation_preview':{'estimatedRiskScore':r,'estimatedCompletenessScore':Math['min'](0x64,0x1e+i['length']*0x8),'keyRisks':q['findings']['filter'](T=>T['level']==='critical'||T['level']==='high')['map'](T=>T['title']),'strengths':q['findings']['filter'](T=>T['level']==='info')['map'](T=>T['title']),'moduleBoosts':{}},'graph_validation':{'valid':q['issues']['length']===0x0,'hard_violations':q['issues']['map'](T=>({'id':T['code'],'description':T['detail'],'fix':'Fix\x20the\x20Plan\x20structure'})),'soft_notes':q['findings']['filter'](T=>T['level']==='medium'||T['level']==='low')['map'](T=>({'id':T['rule_id'],'description':T['title']}))},'harness_check':{'module_constraints':w['map'](T=>{const U=T['module']==='discount_lifecycle'&&T['adopted']?'ADOPTION-BASED\x20satisfaction\x20(disclosure\x20obligations\x20accepted\x20with\x20module\x20adoption),\x20NOT\x20plan\x20structure:\x20creation_plan\x20intentionally\x20carries\x20no\x20Discount/SKU\x20nodes\x20—\x20they\x20are\x20minted\x20in\x20merchant\x20post-deploy\x20steps\x20and\x20verified\x20on-chain\x20after\x20deploy\x20(query\x20the\x20minted\x20Service.discount).\x20Reward\x20FUNDING\x20rides\x20review_mode\x20compile\x20emission,\x20BUT\x20the\x20reward\x20claim\x20GUARD\x20SPEC\x20must\x20still\x20be\x20declared\x20in\x20the\x20plan\x27s\x20guards[]\x20(host:\x27reward\x27)\x20—\x20compile\x20emits\x20the\x20rail\x20only\x20from\x20that\x20spec,\x20and\x20REVIEW_REWARD_GUARD_MISSING\x20hard-blocks\x20publish\x20when\x20it\x20is\x20omitted\x20(G-02,\x20onlyfans-mn\x20261019:\x20the\x20old\x20prose\x20denied\x20the\x20guard\x20spec\x20and\x20deadlocked\x20every\x20reward\x20publish).':T['reason'],V=T['evidence_matched']===![]?''+(U?U+'\x20':'')+'Adopted\x20WITHOUT\x20explicit\x20intent\x20evidence\x20(score-based\x20auto-recommendation\x20only):\x20estimated_score_boost\x20recorded\x20as\x200.\x20Keep\x20it\x20deliberately\x20or\x20drop\x20it\x20via\x20guide_state.adopted_module_ids.':U;return{'module':T['module'],'plan_satisfied':T['adopted'],'missing':T['missingConstraints'],'reason':V,'estimated_score_boost':T['estimatedScoreBoost'],'evidence_matched':T['evidence_matched']};}),'blocking_issues':[...t['map'](T=>({'module':T['module'],'missing_constraints':T['missing_constraints'],'fix':T['fix']})),...C],'module_gaps':w['filter'](T=>!T['adopted'])['map'](T=>({'module':T['module'],'missing_constraints':T['missingConstraints'],'fix':T['reason']})),'deploy_time_checks':y,'recipient_design_guidance':A},'game_theory':{'summary':K['summary'],'coverage':K['coveredCount']+'/'+K['totalCount'],'exposed_scenarios':K['exposedScenarios'],'wow_alignments':K['wowAlignments'],'scenarios':K['results']['map'](T=>({'scenario':T['scenario'],'covered':T['covered'],'conflict':T['conflict'],'user_protection':T['userProtection'],'evaluation_metric':T['evaluationMetric'],'recommendation':T['recommendation']}))},'workflow_design_assessment':{'score':L['score'],'summary':L['summary'],'findings':L['findings']['map'](T=>({'kind':T['kind'],'severity':T['severity'],'message':T['message'],'fix':T['fix']})),'checks':L['checks']['map'](T=>({'id':T['id'],'dimension':T['dimension'],'passed':T['passed'],'severity':T['severity'],'message':T['message'],'fix':T['fix']}))},'creation_plan':M,'post_deploy_steps':z,...H['length']>0x0?{'pending_guard_designs':H}:{},...H['length']>0x0&&(p['pending_guards']?.['length']??0x0)!==H['length']?{'pending_count_note':'Two\x20counts,\x20two\x20views:\x20pending_guard_designs\x20lists\x20'+H['length']+'\x20unresolved\x20design(s)\x20(compile\x20view\x20—\x20includes\x20advisory\x20designs\x20with\x20no\x20edge/rail/policy/buy\x20mount);\x20'+('the\x20plan\x20audit\x20counts\x20'+(p['pending_guards']?.['length']??0x0)+'\x20(plan\x20view\x20—\x20site-bound\x20designs\x20only;\x20the\x20rule-pack\x20titles\x20\x22of\x20N\x20pending\x20in\x20total\x22\x20quote\x20this).\x20')+'The\x20LIST\x20is\x20the\x20resolution\x20fill\x20space;\x20the\x20audit\x20number\x20is\x20its\x20site-bound\x20subset.'}:{},'warnings':[...e['warnings'],...n['omitted']['length']>0x0?['Advisory\x20guard\x20design(s)\x20omitted\x20by\x20decision\x20({kind:\x27omit\x27}):\x20'+n['omitted']['join'](',\x20')+'\x20—\x20'+'no\x20Guard\x20created,\x20nothing\x20binds\x20them\x20(run75747\x20F-38).']:[]],'next_action':B['length']>0x0?'Resolve\x20the\x20blocking_issues\x20above\x20(adjust\x20guide_confirm\x20payment/trust/modules,\x20or\x20accept\x20and\x20drop\x20the\x20affected\x20module\x20via\x20guide_confirm.adopted_module_ids),\x20then\x20call\x20merchant_guide\x20again.':q['blocking']?'The\x20plan\x20audit\x20is\x20BLOCKING\x20(see\x20harness_check.blocking_issues\x20and\x20audit.findings\x20—\x20e.g.\x20a\x20terminal\x20node\x20with\x20no\x20fund\x20exit,\x20or\x20an\x20unresolved\x20guard\x20bound\x20to\x20a\x20fund\x20path).\x20Fix\x20the\x20plan/template\x20or\x20guard\x20resolutions\x20and\x20call\x20merchant_guide\x20again;\x20do\x20NOT\x20materialize\x20this\x20plan.'+(H['length']>0x0?'\x20Pending\x20guard\x20designs:\x20'+H['length']+'\x20listed\x20in\x20pending_guard_designs\x20—\x20resolve\x20each\x20via\x20guide_confirm.guard_resolutions\x20(kind\x20\x27inline\x27\x20with\x20the\x20Guard\x20table+root,\x20kind\x20\x27template\x27\x20with\x20a\x20tpl_*\x20id,\x20or\x20{kind:\x27omit\x27}\x20for\x20advisory\x20designs\x20that\x20do\x20not\x20apply\x20to\x20this\x20shop),\x20then\x20call\x20merchant_guide\x20again.':''):'Plan\x20ready.\x20Materialize:\x20create\x20the\x20objects\x20in\x20creation_plan\x20order\x20via\x20onchain_operations,\x20then\x20run\x20post_deploy_steps\x20in\x20order\x20('+z['map'](T=>T['id'])['join'](',\x20')+').\x20WIZARD\x20CONTRACT:\x20on\x20the\x20Service\x20publish\x20call\x20(data.publish=true),\x20pass\x20this\x20exact\x20plan\x20back\x20as\x20data.creation_plan\x20—\x20the\x20publish\x20gate\x20replays\x20its\x20freeze\x20matrix\x20and\x20rejects\x20the\x20publish\x20if\x20any\x20gate\x20fails;\x20omitting\x20it\x20leaves\x20the\x20manual\x20path\x20ungated.','plan':p,'audit':{'issues':q['issues'],'findings':q['findings'],'blocking':q['blocking'],'score':r},'reflux':{'applied':o['applied'],'blocks':o['blocks'],'iterations':o['iterations']}};}export function listBusinessModules(){return CORE_BUSINESS_MODULES['map'](a=>({'id':a['id'],'name':a['name'],'description':a['description'],'industry_fit':a['industryFit'],'addresses_pain_points':a['addressesPainPoints'],'requires_keeper':a['requiresKeeper']}));}
@@ -1,4 +1,5 @@
1
1
  import { type IndustryTemplate } from "../../knowledge/template-loader.js";
2
+ import type { SemanticIRDiscovery } from "../../knowledge/semantic-ir.js";
2
3
  import type { Industry } from "../../customer/index.js";
3
4
  export interface MigrationEntry {
4
5
  source_element: string;
@@ -19,6 +20,7 @@ export interface MigrationLog {
19
20
  detected_industry: string;
20
21
  matched_template: string;
21
22
  };
23
+ template_match: TemplateMatchInfo;
22
24
  mapped: MigrationEntry[];
23
25
  unmapped: MigrationEntry[];
24
26
  manual_review: MigrationEntry[];
@@ -42,10 +44,16 @@ export interface MigrationPlanInput {
42
44
  template_id?: string;
43
45
  industry?: Industry;
44
46
  ir_industry?: string;
47
+ ir_discovery?: SemanticIRDiscovery;
45
48
  network?: "testnet" | "mainnet" | "localnet";
46
49
  }
47
- export declare function matchTemplate(description: string, irIndustry?: string): {
48
- template: IndustryTemplate;
50
+ export type TemplateMatchSource = "explicit" | "product_ref" | "discovery_product_ref" | "discovery_tags" | "keywords" | "ir_industry_fallback" | "industry_leader";
51
+ export interface TemplateMatchInfo {
52
+ source: TemplateMatchSource;
49
53
  confidence: number;
54
+ matched_tags?: string[];
55
+ }
56
+ export declare function matchTemplate(description: string, irIndustry?: string, discovery?: SemanticIRDiscovery): TemplateMatchInfo & {
57
+ template: IndustryTemplate;
50
58
  } | undefined;
51
59
  export declare function planMigration(input: MigrationPlanInput): MigrationLog | undefined;
@@ -1 +1 @@
1
- import{matchScenarioMode}from'../../knowledge/scenario-modes.js';import{getTemplate,listTemplates,platformShareBps}from'../../knowledge/template-loader.js';import{scanTemplate}from'../../knowledge/template-scanner.js';import{TEMPLATE_KEYWORDS,TEMPLATE_TAGS}from'../../knowledge/builtin-templates.js';import{buildTemplateIndex,resolveByProductRef}from'../../knowledge/template-index.js';export function matchTemplate(a,b){const c=a['toLowerCase'](),{templates:e}=listTemplates(),f=buildTemplateIndex(e),g=resolveByProductRef(f,a);if(g){const n=e['find'](o=>o['id']===g);if(n)return{'template':n,'confidence':0x1};}const h=b?e['filter'](o=>o['industry']===b):e,i=h['length']>0x0?h:e,j=b!==undefined&&h['length']>0x0,{mode:k,confidence:l}=matchScenarioMode(a);let m;for(const o of i){const p=TEMPLATE_KEYWORDS[o['id']]??[],q=TEMPLATE_TAGS[o['id']]??[];let r=0x0;for(const t of p){if(c['includes'](t))r+=0x1;}for(const u of q){if(c['includes'](u))r+=0x1;}if(k['name']===o['industry'])r+=l;const s=p['length']+q['length']+0x1;if(!m||r>m['score'])m={'template':o,'score':r,'max':s};}if(m&&m['score']>0x0)return{'template':m['template'],'confidence':Math['min'](0x1,m['score']/m['max'])};if(j){const v=i['find'](w=>w['archetype']==='leader')??i[0x0];return{'template':v,'confidence':0.35};}return undefined;}function dryRunRiskCheck(a){const b=scanTemplate(a),c=b['red_flags'];return{'passed':c['length']===0x0,'findings':b['findings']['map'](d=>'['+d['severity']+']\x20'+(d['rule_id']??'scan')+':\x20'+d['title']+'\x20—\x20'+d['suggestion'])};}function genericMappedEntries(a){return[{'source_element':'Order\x20lifecycle\x20/\x20status\x20flow','target_object':'Machine','mapping_note':a['machine_shape']['length']+'-node\x20workflow\x20adopted\x20from\x20the\x20'+a['id']+'\x20template'},{'source_element':'Business\x20rules\x20and\x20time\x20windows','target_object':'Guard','mapping_note':a['guards']['length']+'\x20guard\x20templates\x20carry\x20the\x20rule\x20parameters\x20as\x20immutable\x20on-chain\x20conditions'},{'source_element':'Payment\x20split\x20/\x20settlement','target_object':'Allocator','mapping_note':a['allocator']['description']},{'source_element':'Refund\x20policy','target_object':'Allocator\x20(refund\x20route)','mapping_note':'Refunds\x20route\x20via\x20Allocators\x20triggered\x20by\x20business\x20states\x20—\x20never\x20Machine\x20terminal\x20nodes\x20(R-M1-11)'},{'source_element':'Dispute\x20resolution','target_object':'Arbitration','mapping_note':'Independent\x20Arbitration\x20object\x20with\x20its\x20own\x20Permission\x20—\x20disputes\x20flow\x20off-Machine'},{'source_element':'Operator\x20roles\x20(staff/fulfiller/finance)','target_object':'Permission','mapping_note':'Role\x20slots\x20as\x20Permission\x20entities;\x20the\x20order\x20payer\x20acts\x20as\x20the\x20named\x20operator\x20without\x20occupying\x20a\x20slot'},{'source_element':'Evidence\x20and\x20records','target_object':'Repository','mapping_note':'Write-guarded\x20Repository\x20policies\x20anchor\x20evidence\x20hashes\x20(delivery,\x20inspection,\x20settlement\x20ledger)'},{'source_element':'Service\x20listing\x20and\x20pricing','target_object':'Service','mapping_note':'Service\x20carries\x20the\x20sale\x20structure,\x20buy\x20gate,\x20and\x20bound\x20Machine/Guards/Arbitration\x20before\x20publish'}];}function genericUnmappedEntries(a){const b=[{'source_element':'Incumbent\x20platform\x20internal\x20ranking\x20/\x20search\x20algorithm','mapping_note':'Marketplace\x20discovery\x20logic\x20has\x20no\x20on-chain\x20equivalent','reason':'Off-chain\x20platform\x20intelligence\x20—\x20use\x20the\x20WoWok\x20market\x20layer\x20(demand\x20matching)\x20instead'},{'source_element':'Incumbent\x20platform\x20user\x20account\x20/\x20login\x20system','mapping_note':'Identity\x20lives\x20in\x20wallets\x20and\x20Passports,\x20not\x20platform\x20accounts','reason':'WoWok\x20is\x20account-less\x20by\x20design\x20—\x20addresses\x20+\x20Passports\x20replace\x20platform\x20logins'},{'source_element':'Automatic\x20recurring\x20charges\x20(card\x20auto-debit)','mapping_note':'Recurring\x20charges\x20are\x20replaced\x20by\x20explicit\x20per-period\x20subscriber\x20signatures','reason':'Silent\x20auto-charge\x20is\x20an\x20anti-pattern\x20on\x20WoWok\x20—\x20renewal\x20requires\x20the\x20payer\x27s\x20signature\x20every\x20period'}];return a['industry']==='subscription'&&b['push']({'source_element':'Content\x20moderation\x20/\x20takedown\x20pipeline','mapping_note':'Only\x20content\x20hashes\x20live\x20on-chain;\x20content\x20bodies\x20stay\x20off-chain','reason':'Content\x20governance\x20is\x20structurally\x20out\x20of\x20scope\x20for\x20on-chain\x20objects\x20—\x20handle\x20it\x20at\x20the\x20hosting\x20layer'}),(a['industry']==='retail'||a['industry']==='rental')&&b['push']({'source_element':'Physical\x20logistics\x20/\x20courier\x20integration','mapping_note':'Logistics\x20stays\x20off-chain;\x20tracking\x20evidence\x20is\x20anchored\x20via\x20WIP\x20hashes','reason':'Carriers\x20are\x20external\x20systems\x20—\x20the\x20Machine\x20consumes\x20their\x20evidence,\x20not\x20their\x20API'}),b;}function manualReviewEntries(a){const b=[{'source_element':'Fee\x20and\x20split\x20parameters','mapping_note':'Template\x20defaults:\x20'+Object['entries'](a['fee_params'])['map'](([c,d])=>c+'='+d)['join'](',\x20'),'reason':'Confirm\x20or\x20override\x20each\x20parameter\x20before\x20generation'},{'source_element':'Operating\x20role','mapping_note':'Recommended:\x20'+a['recommended_role']+'\x20—\x20'+a['role_rationale'],'reason':'The\x20user\x20may\x20switch\x20role\x20(merchant\x20<->\x20supplier)\x20before\x20apply'},{'source_element':'Target\x20network','mapping_note':'Default\x20testnet\x20for\x20the\x20first\x20deployment','reason':'Mainnet\x20deployment\x20requires\x20explicit\x20user\x20confirmation'}];return a['keeper_dependencies']['length']>0x0&&b['push']({'source_element':'Off-chain\x20keeper\x20operations','mapping_note':'Declared\x20keepers:\x20'+a['keeper_dependencies']['join'](';\x20'),'reason':'Time-driven\x20transitions\x20only\x20ALLOW\x20advancement\x20—\x20someone\x20must\x20run\x20the\x20keepers'}),a['keeper_duty']&&a['keeper_duty']['length']>0x0&&b['push']({'source_element':'Keeper\x20duty\x20runbook','mapping_note':a['keeper_duty']['map'](c=>'WHEN\x20'+c['when']+'\x20->\x20'+c['action']+'\x20(if\x20missed:\x20'+c['miss_consequence']+')')['join'](';\x20'),'reason':'A\x20missed\x20duty\x20strands\x20an\x20order\x20or\x20funds\x20—\x20each\x20row\x20is\x20an\x20operating\x20obligation\x20of\x20this\x20build'}),b;}const FACT_PATTERNS=[{'pattern':/\b(?:coupon|promo(?:\s*code)?|discount\s*code|voucher)\b/i,'fact':{'label':'Coupons\x20/\x20promo\x20codes','note':'Maps\x20to\x20a\x20Discount\x20object\x20minted\x20on\x20the\x20Service\x20(budget\x20=\x20max_uses\x20x\x20value;\x20coupons\x20are\x20BURNED\x20on\x20use\x20—\x20never\x20restocked\x20or\x20refunded).\x20Decide\x20the\x20coupon\x20budget\x20and\x20eligibility\x20guard\x20before\x20apply.','disposition':'manual_review'}},{'pattern':/\breview\s+(?:reward|bounty|incentive)|\bincentiv\w+\s+reviews?\b|\bbonus\s+for\s+(?:a\s+)?reviews?\b/i,'fact':{'label':'Review\x20rewards\x20/\x20bounties','note':'Maps\x20to\x20a\x20funded\x20Reward\x20object\x20+\x20claim\x20guard\x20(generation\x20input\x20review_mode=\x27review_reward\x27).\x20The\x20reward\x20pool\x20MUST\x20be\x20funded\x20at\x20generation\x20time\x20(reward_funding\x20input)\x20—\x20an\x20unfunded\x20promise\x20is\x20refused.','disposition':'manual_review'}},{'pattern':/\breturn\s+(?:window|policy)|\b\d{1,3}[\s-]?day\s+returns?\b/i,'fact':{'label':'Return\x20window\x20/\x20policy','note':'Maps\x20to\x20the\x20template\x27s\x20return-window\x20guard\x20knob\x20(return_window_days\x20fee_param).\x20Compare\x20the\x20stated\x20number\x20against\x20the\x20template\x20default\x20before\x20apply\x20—\x20the\x20guard\x20binds\x20only\x20the\x20embedded\x20constant.','disposition':'manual_review'}},{'pattern':/\ba[\s-]?to[\s-]?z\b|\bbuyer\s+protection\b|\bguarantee\s+program\b/i,'fact':{'label':'Platform\x20guarantee\x20program\x20(A-to-z\x20style)','note':'Maps\x20to\x20the\x20independent\x20Arbitration\x20venue\x20plus\x20the\x20order-side\x20claim\x20rails.\x20The\x20refund-vs-award\x20exits\x20must\x20be\x20confirmed\x20at\x20guard\x20resolution\x20—\x20the\x20venue\x20itself\x20moves\x20no\x20funds.','disposition':'manual_review'}},{'pattern':/\b(?:multiple|third[- ]party)\s+sellers?\b|\bper[- ]product\s+split\b|\bmulti[- ]seller\b/i,'fact':{'label':'Multi-seller\x20per-product\x20settlement','note':'NOT\x20supported:\x20one\x20Service/Allocation\x20settles\x20ONE\x20merchant\x27s\x20split.\x20Multi-seller\x20needs\x20one\x20Service\x20per\x20seller\x20(archived\x20framework\x20boundary)\x20—\x20disclose\x20this\x20to\x20the\x20migrating\x20merchant\x20instead\x20of\x20generating\x20a\x20shop\x20that\x20cannot\x20pay\x20out.','disposition':'unmapped'}},{'pattern':/\bsales\s+tax\b|\bVAT\b|\bGST\b/i,'fact':{'label':'Sales\x20tax\x20/\x20VAT\x20handling','note':'NOT\x20supported\x20on-chain:\x20tax\x20remittance\x20is\x20an\x20off-chain\x20compliance\x20flow\x20(archived\x20framework\x20boundary).\x20Disclose;\x20do\x20not\x20model\x20it\x20as\x20a\x20split\x20row.','disposition':'unmapped'}}];function extractSplitMention(a){const b=a;let c=b['match'](/\b(?:platform|service|commission|take)\s*(?:fee|commission|rate|cut)?\s*(?:of|is|at|:)?\s*(\d{1,3}(?:\.\d+)?)\s*%/i)??b['match'](/(\d{1,3}(?:\.\d+)?)\s*%\s*(?:platform\s+)?(?:commission|service\s*fee|take|cut)\b/i);if(c)return{'statedPct':Number(c[0x1]),'raw':c[0x0],'certain':!![]};c=b['match'](/(\d{1,3}(?:\.\d+)?)\s*%\s*(?:goes\s+to|to|for)\s+the\s+(?:merchant|seller|creator|freelancer|artist)/i)??b['match'](/\b(?:merchant|seller|creator|freelancer|artist)s?\s+(?:keep|get|receive|earn)\s+(\d{1,3}(?:\.\d+)?)\s*%/i);if(c)return{'statedPct':0x64-Number(c[0x1]),'raw':c[0x0],'certain':!![]};c=b['match'](/\b(\d{1,3})\s*[/\u2013\u2014-]\s*(\d{1,3})\b(?:\s*%?\s*(?:split|revenue\s*share|share|revenue\s*split))?/i);if(c&&/split|revenue|share|commission/i['test'](b))return{'raw':c[0x0],'certain':![]};return undefined;}function splitConflictEntry(a,b){const c=extractSplitMention(b);if(!c)return undefined;const d=platformShareBps(a['fee_params']),e=d===undefined?undefined:d/0x64;if(e===undefined)return undefined;const f=Object['keys'](a['fee_params'])['find'](h=>/(?:platform|commission|service_fee)[a-z_]*_bps$/['test'](h)&&!/^attributed_/['test'](h));if(c['certain']&&c['statedPct']!==undefined&&Math['abs'](c['statedPct']-e)<0.01)return undefined;const g=c['certain']&&c['statedPct']!==undefined?c['statedPct']+'%\x20platform\x20share':'an\x20orientation-ambiguous\x20ratio\x20('+c['raw']+'\x20—\x20which\x20side\x20is\x20the\x20platform\x20is\x20not\x20stated)';return{'source_element':'Platform\x20commission\x20stated\x20in\x20the\x20description','mapping_note':'Your\x20description\x20states\x20'+g+';\x20template\x20\x27'+a['id']+'\x27\x20defaults\x20to\x20a\x20'+(e+'%\x20platform\x20share\x20(fee_params\x20'+(f??'platform_commission_bps')+'\x20=\x20'+(d??0x0)+'\x20bps).\x20')+'These\x20differ\x20—\x20the\x20template\x20default\x20wins\x20silently\x20unless\x20you\x20override\x20it.','reason':'Confirm\x20the\x20intended\x20split.\x20To\x20apply\x20the\x20stated\x20number,\x20pass\x20'+('fee_overrides[\x22'+(f??'platform_commission_bps')+'\x22]\x20=\x20'+(c['statedPct']!==undefined&&c['certain']?Math['round'](c['statedPct']*0x64):'<bps>')+'\x20')+'(basis\x20points)\x20on\x20template_generate\x20/\x20migration_apply;\x20to\x20keep\x20the\x20template\x20default,\x20ignore\x20this\x20entry.\x20'+'A\x20wrong\x20split\x20lands\x20as\x20a\x20live\x20allocator\x20row\x20and\x20order_allocators\x20is\x20frozen\x20at\x20publish.'};}function disclosedFactEntries(a,b,c){const d=[],e=[],f=new Set([...b,...c]['map'](g=>g['source_element']['toLowerCase']()));for(const {pattern:g,fact:h}of FACT_PATTERNS){if(!g['test'](a))continue;if(f['has'](h['label']['toLowerCase']()))continue;f['add'](h['label']['toLowerCase']());const i={'source_element':h['label'],'mapping_note':'Stated\x20in\x20your\x20description\x20—\x20the\x20deterministic\x20planner\x20does\x20not\x20map\x20it\x20automatically.\x20'+h['note'],'reason':'Explicit\x20disclosure\x20(amz9\x20A-3):\x20stated\x20commerce\x20facts\x20must\x20never\x20be\x20silently\x20dropped.\x20Confirm\x20or\x20decline\x20this\x20item\x20before\x20migration_apply.'};if(h['disposition']==='unmapped')e['push'](i);else d['push'](i);}return{'manual':d,'unmapped':e};}function wowokAdvantages(a){const b=['Every\x20rule\x20is\x20an\x20immutable\x20on-chain\x20Guard\x20—\x20customers\x20can\x20verify\x20the\x20exact\x20policy\x20before\x20paying','Disputes\x20resolve\x20through\x20independent\x20Arbitration\x20with\x20a\x20funded\x20compensation\x20pool','Fund\x20splits\x20execute\x20by\x20contract\x20at\x20the\x20configured\x20release\x20points\x20—\x20no\x20platform\x20discretion'];return a['industry']==='subscription'&&b['push']('Per-period\x20explicit-signature\x20renewal\x20—\x20the\x20anti-auto-renew\x20trap\x20is\x20a\x20selling\x20point'),a['industry']==='freelance'&&b['push']('Chain-verifiable\x200%\x20(or\x20low)\x20commission\x20via\x20the\x20allocator\x20split\x20itself'),a['industry']==='travel'&&b['push']('Two-tier\x20allocation\x20pays\x20each\x20supplier\x20at\x20its\x20own\x20segment\x20release\x20—\x20multi-party\x20transparency'),a['industry']==='education'&&b['push']('Regulatory\x20prepay\x20caps\x20and\x20per-session\x20release\x20protect\x20students\x20from\x20run-away\x20institutions'),a['industry']==='rental'&&b['push']('Deposit\x20escrow\x20+\x20evidence-gated\x20deduction\x20—\x20neither\x20side\x20can\x20unilaterally\x20seize\x20the\x20deposit'),a['industry']==='retail'&&b['push']('Escrow\x20+\x20confirm-on-receipt\x20release\x20—\x20the\x20buyer\x27s\x20confirmation\x20is\x20the\x20only\x20release\x20trigger'),b;}function customizableModules(a){const b=['independent_arbitration','refund_guarantee','reputation_on_chain','wip_provenance'];switch(a['industry']){case'freelance':return[...b,'milestone_escrow','accept_timeout_protection'];case'rental':return[...b,'damage_attestation'];case'education':return[...b,'accept_timeout_protection'];case'travel':return[...b,'multi_tier_allocation','supplier_collaboration'];case'subscription':return[...b,'subscription_with_proof'];case'retail':return[...b,'accept_timeout_protection'];default:return b;}}export function planMigration(a){let b;if(a['template_id']){b=getTemplate(a['template_id']);if(b&&a['industry']&&b['industry']!==a['industry']){const g=matchTemplate(a['industry']+'\x20'+a['description'],a['ir_industry']);if(g&&g['template']['industry']===a['industry'])b=g['template'];}}else{const h=a['industry']?a['industry']+'\x20'+a['description']:a['description'],i=matchTemplate(h,a['industry']?undefined:a['ir_industry']);b=i?.['template'],!b&&a['industry']&&(b=listTemplates()['templates']['find'](j=>j['industry']===a['industry']&&j['archetype']==='leader'));}if(!b)return undefined;const c=manualReviewEntries(b),d=genericUnmappedEntries(b),e=splitConflictEntry(b,a['description']);if(e)c['unshift'](e);const f=disclosedFactEntries(a['description'],c,d);return c['push'](...f['manual']),d['push'](...f['unmapped']),{'source':{'url':a['url'],'description':a['description'],'detected_industry':b['industry'],'matched_template':b['id']},'mapped':genericMappedEntries(b),'unmapped':d,'manual_review':c,'wowok_advantages':wowokAdvantages(b),'customizable_modules':customizableModules(b),'role_assessment':{'recommended':b['recommended_role'],'rationale':b['role_rationale'],'alternatives':['merchant','supplier','both']['filter'](j=>j!==b['recommended_role'])},'risk_check':dryRunRiskCheck(b),...b['conditional_guards']?.['length']?{'questions':[...new Set(b['conditional_guards']['map'](j=>j['param']))]['map'](j=>{const k=b['conditional_guards']['find'](l=>l['param']===j);return{'param':j,'question':k['question'],'options':[...k['values']],'default':String(b['fee_params'][j]??'')};})}:{},'network':a['network']??'testnet'};}
1
+ import{matchScenarioMode}from'../../knowledge/scenario-modes.js';import{getTemplate,listTemplates,platformShareBps}from'../../knowledge/template-loader.js';import{scanTemplate}from'../../knowledge/template-scanner.js';import{discoveryTagsForTemplate,TEMPLATE_KEYWORDS}from'../../knowledge/builtin-templates.js';import{buildTemplateIndex,resolveByProductRef}from'../../knowledge/template-index.js';export function matchTemplate(a,b,c){const e=c?.['english_summary']?a+'\x0a'+c['english_summary']:a,f=e['toLowerCase'](),{templates:g}=listTemplates(),h=buildTemplateIndex(g);if(c?.['product_ref']){const q=c['industry']?g['filter'](u=>u['industry']===c['industry']):g,r=q['length']>0x0?q:g,s=r['find'](u=>u['product_ref']?.['toLowerCase']()===c['product_ref']);if(s)return{'template':s,'confidence':0x1,'source':'discovery_product_ref'};}const i=resolveByProductRef(h,e);if(i){const t=g['find'](u=>u['id']===i);if(t)return{'template':t,'confidence':0x1,'source':'product_ref'};}const j=c?.['industry']??b,k=j?g['filter'](u=>u['industry']===j):g,l=k['length']>0x0?k:g,m=j!==undefined&&k['length']>0x0;if(c&&c['tags']['length']>0x0){const u=c['industry']?0x1:0x2,v=l['map'](x=>{const y=new Set(discoveryTagsForTemplate(x['id']));return{'template':x,'matched':c['tags']['filter'](z=>y['has'](z))};})['filter'](x=>x['matched']['length']>=u)['sort']((x,y)=>{if(y['matched']['length']!==x['matched']['length'])return y['matched']['length']-x['matched']['length'];const z=j!==undefined&&x['template']['industry']===j?0x1:0x0,A=j!==undefined&&y['template']['industry']===j?0x1:0x0;if(A!==z)return A-z;return x['template']['id']['localeCompare'](y['template']['id']);}),w=v[0x0];if(w){const x=w['matched']['length']/c['tags']['length'],y=j!==undefined&&w['template']['industry']===j?0.1:0x0,z=Math['min'](0.9,Number((0.45+0.55*x+y)['toFixed'](0x4)));return{'template':w['template'],'confidence':z,'source':'discovery_tags','matched_tags':w['matched']};}}const {mode:n,confidence:o}=matchScenarioMode(e);let p;for(const A of l){const B=TEMPLATE_KEYWORDS[A['id']]??[],C=discoveryTagsForTemplate(A['id']);let D=0x0;for(const F of B){if(f['includes'](F))D+=0x1;}for(const G of C){if(f['includes'](G))D+=0x1;}if(n['name']===A['industry'])D+=o;const E=B['length']+C['length']+0x1;if(!p||D>p['score'])p={'template':A,'score':D,'max':E};}if(p&&p['score']>0x0)return{'template':p['template'],'confidence':Math['min'](0x1,p['score']/p['max']),'source':'keywords'};if(m){const H=l['find'](I=>I['archetype']==='leader')??l[0x0];return{'template':H,'confidence':0.35,'source':'ir_industry_fallback'};}return undefined;}function dryRunRiskCheck(a){const b=scanTemplate(a),c=b['red_flags'];return{'passed':c['length']===0x0,'findings':b['findings']['map'](d=>'['+d['severity']+']\x20'+(d['rule_id']??'scan')+':\x20'+d['title']+'\x20—\x20'+d['suggestion'])};}function genericMappedEntries(a){return[{'source_element':'Order\x20lifecycle\x20/\x20status\x20flow','target_object':'Machine','mapping_note':a['machine_shape']['length']+'-node\x20workflow\x20adopted\x20from\x20the\x20'+a['id']+'\x20template'},{'source_element':'Business\x20rules\x20and\x20time\x20windows','target_object':'Guard','mapping_note':a['guards']['length']+'\x20guard\x20templates\x20carry\x20the\x20rule\x20parameters\x20as\x20immutable\x20on-chain\x20conditions'},{'source_element':'Payment\x20split\x20/\x20settlement','target_object':'Allocator','mapping_note':a['allocator']['description']},{'source_element':'Refund\x20policy','target_object':'Allocator\x20(refund\x20route)','mapping_note':'Refunds\x20route\x20via\x20Allocators\x20triggered\x20by\x20business\x20states\x20—\x20never\x20Machine\x20terminal\x20nodes\x20(R-M1-11)'},{'source_element':'Dispute\x20resolution','target_object':'Arbitration','mapping_note':'Independent\x20Arbitration\x20object\x20with\x20its\x20own\x20Permission\x20—\x20disputes\x20flow\x20off-Machine'},{'source_element':'Operator\x20roles\x20(staff/fulfiller/finance)','target_object':'Permission','mapping_note':'Role\x20slots\x20as\x20Permission\x20entities;\x20the\x20order\x20payer\x20acts\x20as\x20the\x20named\x20operator\x20without\x20occupying\x20a\x20slot'},{'source_element':'Evidence\x20and\x20records','target_object':'Repository','mapping_note':'Write-guarded\x20Repository\x20policies\x20anchor\x20evidence\x20hashes\x20(delivery,\x20inspection,\x20settlement\x20ledger)'},{'source_element':'Service\x20listing\x20and\x20pricing','target_object':'Service','mapping_note':'Service\x20carries\x20the\x20sale\x20structure,\x20buy\x20gate,\x20and\x20bound\x20Machine/Guards/Arbitration\x20before\x20publish'}];}function genericUnmappedEntries(a){const b=[{'source_element':'Incumbent\x20platform\x20internal\x20ranking\x20/\x20search\x20algorithm','mapping_note':'Marketplace\x20discovery\x20logic\x20has\x20no\x20on-chain\x20equivalent','reason':'Off-chain\x20platform\x20intelligence\x20—\x20use\x20the\x20WoWok\x20market\x20layer\x20(demand\x20matching)\x20instead'},{'source_element':'Incumbent\x20platform\x20user\x20account\x20/\x20login\x20system','mapping_note':'Identity\x20lives\x20in\x20wallets\x20and\x20Passports,\x20not\x20platform\x20accounts','reason':'WoWok\x20is\x20account-less\x20by\x20design\x20—\x20addresses\x20+\x20Passports\x20replace\x20platform\x20logins'},{'source_element':'Automatic\x20recurring\x20charges\x20(card\x20auto-debit)','mapping_note':'Recurring\x20charges\x20are\x20replaced\x20by\x20explicit\x20per-period\x20subscriber\x20signatures','reason':'Silent\x20auto-charge\x20is\x20an\x20anti-pattern\x20on\x20WoWok\x20—\x20renewal\x20requires\x20the\x20payer\x27s\x20signature\x20every\x20period'}];return a['industry']==='subscription'&&b['push']({'source_element':'Content\x20moderation\x20/\x20takedown\x20pipeline','mapping_note':'Only\x20content\x20hashes\x20live\x20on-chain;\x20content\x20bodies\x20stay\x20off-chain','reason':'Content\x20governance\x20is\x20structurally\x20out\x20of\x20scope\x20for\x20on-chain\x20objects\x20—\x20handle\x20it\x20at\x20the\x20hosting\x20layer'}),(a['industry']==='retail'||a['industry']==='rental')&&b['push']({'source_element':'Physical\x20logistics\x20/\x20courier\x20integration','mapping_note':'Logistics\x20stays\x20off-chain;\x20tracking\x20evidence\x20is\x20anchored\x20via\x20WIP\x20hashes','reason':'Carriers\x20are\x20external\x20systems\x20—\x20the\x20Machine\x20consumes\x20their\x20evidence,\x20not\x20their\x20API'}),b;}function manualReviewEntries(a){const b=[{'source_element':'Fee\x20and\x20split\x20parameters','mapping_note':'Template\x20defaults:\x20'+Object['entries'](a['fee_params'])['map'](([c,d])=>c+'='+d)['join'](',\x20'),'reason':'Confirm\x20or\x20override\x20each\x20parameter\x20before\x20generation'},{'source_element':'Operating\x20role','mapping_note':'Recommended:\x20'+a['recommended_role']+'\x20—\x20'+a['role_rationale'],'reason':'The\x20user\x20may\x20switch\x20role\x20(merchant\x20<->\x20supplier)\x20before\x20apply'},{'source_element':'Target\x20network','mapping_note':'Default\x20testnet\x20for\x20the\x20first\x20deployment','reason':'Mainnet\x20deployment\x20requires\x20explicit\x20user\x20confirmation'}];return a['keeper_dependencies']['length']>0x0&&b['push']({'source_element':'Off-chain\x20keeper\x20operations','mapping_note':'Declared\x20keepers:\x20'+a['keeper_dependencies']['join'](';\x20'),'reason':'Time-driven\x20transitions\x20only\x20ALLOW\x20advancement\x20—\x20someone\x20must\x20run\x20the\x20keepers'}),a['keeper_duty']&&a['keeper_duty']['length']>0x0&&b['push']({'source_element':'Keeper\x20duty\x20runbook','mapping_note':a['keeper_duty']['map'](c=>'WHEN\x20'+c['when']+'\x20->\x20'+c['action']+'\x20(if\x20missed:\x20'+c['miss_consequence']+')')['join'](';\x20'),'reason':'A\x20missed\x20duty\x20strands\x20an\x20order\x20or\x20funds\x20—\x20each\x20row\x20is\x20an\x20operating\x20obligation\x20of\x20this\x20build'}),b;}const FACT_PATTERNS=[{'pattern':/\b(?:coupon|promo(?:\s*code)?|discount\s*code|voucher)\b/i,'fact':{'label':'Coupons\x20/\x20promo\x20codes','note':'Maps\x20to\x20a\x20Discount\x20object\x20minted\x20on\x20the\x20Service\x20(budget\x20=\x20max_uses\x20x\x20value;\x20coupons\x20are\x20BURNED\x20on\x20use\x20—\x20never\x20restocked\x20or\x20refunded).\x20Decide\x20the\x20coupon\x20budget\x20and\x20eligibility\x20guard\x20before\x20apply.','disposition':'manual_review'}},{'pattern':/\breview\s+(?:reward|bounty|incentive)|\bincentiv\w+\s+reviews?\b|\bbonus\s+for\s+(?:a\s+)?reviews?\b/i,'fact':{'label':'Review\x20rewards\x20/\x20bounties','note':'Maps\x20to\x20a\x20funded\x20Reward\x20object\x20+\x20claim\x20guard\x20(generation\x20input\x20review_mode=\x27review_reward\x27).\x20The\x20reward\x20pool\x20MUST\x20be\x20funded\x20at\x20generation\x20time\x20(reward_funding\x20input)\x20—\x20an\x20unfunded\x20promise\x20is\x20refused.','disposition':'manual_review'}},{'pattern':/\breturn\s+(?:window|policy)|\b\d{1,3}[\s-]?day\s+returns?\b/i,'fact':{'label':'Return\x20window\x20/\x20policy','note':'Maps\x20to\x20the\x20template\x27s\x20return-window\x20guard\x20knob\x20(return_window_days\x20fee_param).\x20Compare\x20the\x20stated\x20number\x20against\x20the\x20template\x20default\x20before\x20apply\x20—\x20the\x20guard\x20binds\x20only\x20the\x20embedded\x20constant.','disposition':'manual_review'}},{'pattern':/\ba[\s-]?to[\s-]?z\b|\bbuyer\s+protection\b|\bguarantee\s+program\b/i,'fact':{'label':'Platform\x20guarantee\x20program\x20(A-to-z\x20style)','note':'Maps\x20to\x20the\x20independent\x20Arbitration\x20venue\x20plus\x20the\x20order-side\x20claim\x20rails.\x20The\x20refund-vs-award\x20exits\x20must\x20be\x20confirmed\x20at\x20guard\x20resolution\x20—\x20the\x20venue\x20itself\x20moves\x20no\x20funds.','disposition':'manual_review'}},{'pattern':/\b(?:multiple|third[- ]party)\s+sellers?\b|\bper[- ]product\s+split\b|\bmulti[- ]seller\b/i,'fact':{'label':'Multi-seller\x20per-product\x20settlement','note':'NOT\x20supported:\x20one\x20Service/Allocation\x20settles\x20ONE\x20merchant\x27s\x20split.\x20Multi-seller\x20needs\x20one\x20Service\x20per\x20seller\x20(archived\x20framework\x20boundary)\x20—\x20disclose\x20this\x20to\x20the\x20migrating\x20merchant\x20instead\x20of\x20generating\x20a\x20shop\x20that\x20cannot\x20pay\x20out.','disposition':'unmapped'}},{'pattern':/\bsales\s+tax\b|\bVAT\b|\bGST\b/i,'fact':{'label':'Sales\x20tax\x20/\x20VAT\x20handling','note':'NOT\x20supported\x20on-chain:\x20tax\x20remittance\x20is\x20an\x20off-chain\x20compliance\x20flow\x20(archived\x20framework\x20boundary).\x20Disclose;\x20do\x20not\x20model\x20it\x20as\x20a\x20split\x20row.','disposition':'unmapped'}}];function extractSplitMention(a){const b=a;let c=b['match'](/\b(?:platform|service|commission|take)\s*(?:fee|commission|rate|cut)?\s*(?:of|is|at|:)?\s*(\d{1,3}(?:\.\d+)?)\s*%/i)??b['match'](/(\d{1,3}(?:\.\d+)?)\s*%\s*(?:platform\s+)?(?:commission|service\s*fee|take|cut)\b/i);if(c)return{'statedPct':Number(c[0x1]),'raw':c[0x0],'certain':!![]};c=b['match'](/(\d{1,3}(?:\.\d+)?)\s*%\s*(?:goes\s+to|to|for)\s+the\s+(?:merchant|seller|creator|freelancer|artist)/i)??b['match'](/\b(?:merchant|seller|creator|freelancer|artist)s?\s+(?:keep|get|receive|earn)\s+(\d{1,3}(?:\.\d+)?)\s*%/i);if(c)return{'statedPct':0x64-Number(c[0x1]),'raw':c[0x0],'certain':!![]};c=b['match'](/\b(\d{1,3})\s*[/\u2013\u2014-]\s*(\d{1,3})\b(?:\s*%?\s*(?:split|revenue\s*share|share|revenue\s*split))?/i);if(c&&/split|revenue|share|commission/i['test'](b))return{'raw':c[0x0],'certain':![]};return undefined;}function splitConflictEntry(a,b){const c=extractSplitMention(b);if(!c)return undefined;const d=platformShareBps(a['fee_params']),e=d===undefined?undefined:d/0x64;if(e===undefined)return undefined;const f=Object['keys'](a['fee_params'])['find'](h=>/(?:platform|commission|service_fee)[a-z_]*_bps$/['test'](h)&&!/^attributed_/['test'](h));if(c['certain']&&c['statedPct']!==undefined&&Math['abs'](c['statedPct']-e)<0.01)return undefined;const g=c['certain']&&c['statedPct']!==undefined?c['statedPct']+'%\x20platform\x20share':'an\x20orientation-ambiguous\x20ratio\x20('+c['raw']+'\x20—\x20which\x20side\x20is\x20the\x20platform\x20is\x20not\x20stated)';return{'source_element':'Platform\x20commission\x20stated\x20in\x20the\x20description','mapping_note':'Your\x20description\x20states\x20'+g+';\x20template\x20\x27'+a['id']+'\x27\x20defaults\x20to\x20a\x20'+(e+'%\x20platform\x20share\x20(fee_params\x20'+(f??'platform_commission_bps')+'\x20=\x20'+(d??0x0)+'\x20bps).\x20')+'These\x20differ\x20—\x20the\x20template\x20default\x20wins\x20silently\x20unless\x20you\x20override\x20it.','reason':'Confirm\x20the\x20intended\x20split.\x20To\x20apply\x20the\x20stated\x20number,\x20pass\x20'+('fee_overrides[\x22'+(f??'platform_commission_bps')+'\x22]\x20=\x20'+(c['statedPct']!==undefined&&c['certain']?Math['round'](c['statedPct']*0x64):'<bps>')+'\x20')+'(basis\x20points)\x20on\x20template_generate\x20/\x20migration_apply;\x20to\x20keep\x20the\x20template\x20default,\x20ignore\x20this\x20entry.\x20'+'A\x20wrong\x20split\x20lands\x20as\x20a\x20live\x20allocator\x20row\x20and\x20order_allocators\x20is\x20frozen\x20at\x20publish.'};}function disclosedFactEntries(a,b,c){const d=[],e=[],f=new Set([...b,...c]['map'](g=>g['source_element']['toLowerCase']()));for(const {pattern:g,fact:h}of FACT_PATTERNS){if(!g['test'](a))continue;if(f['has'](h['label']['toLowerCase']()))continue;f['add'](h['label']['toLowerCase']());const i={'source_element':h['label'],'mapping_note':'Stated\x20in\x20your\x20description\x20—\x20the\x20deterministic\x20planner\x20does\x20not\x20map\x20it\x20automatically.\x20'+h['note'],'reason':'Explicit\x20disclosure\x20(amz9\x20A-3):\x20stated\x20commerce\x20facts\x20must\x20never\x20be\x20silently\x20dropped.\x20Confirm\x20or\x20decline\x20this\x20item\x20before\x20migration_apply.'};if(h['disposition']==='unmapped')e['push'](i);else d['push'](i);}return{'manual':d,'unmapped':e};}function wowokAdvantages(a){const b=['Every\x20rule\x20is\x20an\x20immutable\x20on-chain\x20Guard\x20—\x20customers\x20can\x20verify\x20the\x20exact\x20policy\x20before\x20paying','Disputes\x20resolve\x20through\x20independent\x20Arbitration\x20with\x20a\x20funded\x20compensation\x20pool','Fund\x20splits\x20execute\x20by\x20contract\x20at\x20the\x20configured\x20release\x20points\x20—\x20no\x20platform\x20discretion'];return a['industry']==='subscription'&&b['push']('Per-period\x20explicit-signature\x20renewal\x20—\x20the\x20anti-auto-renew\x20trap\x20is\x20a\x20selling\x20point'),a['industry']==='freelance'&&b['push']('Chain-verifiable\x200%\x20(or\x20low)\x20commission\x20via\x20the\x20allocator\x20split\x20itself'),a['industry']==='travel'&&b['push']('Two-tier\x20allocation\x20pays\x20each\x20supplier\x20at\x20its\x20own\x20segment\x20release\x20—\x20multi-party\x20transparency'),a['industry']==='education'&&b['push']('Regulatory\x20prepay\x20caps\x20and\x20per-session\x20release\x20protect\x20students\x20from\x20run-away\x20institutions'),a['industry']==='rental'&&b['push']('Deposit\x20escrow\x20+\x20evidence-gated\x20deduction\x20—\x20neither\x20side\x20can\x20unilaterally\x20seize\x20the\x20deposit'),a['industry']==='retail'&&b['push']('Escrow\x20+\x20confirm-on-receipt\x20release\x20—\x20the\x20buyer\x27s\x20confirmation\x20is\x20the\x20only\x20release\x20trigger'),b;}function customizableModules(a){const b=['independent_arbitration','refund_guarantee','reputation_on_chain','wip_provenance'];switch(a['industry']){case'freelance':return[...b,'milestone_escrow','accept_timeout_protection'];case'rental':return[...b,'damage_attestation'];case'education':return[...b,'accept_timeout_protection'];case'travel':return[...b,'multi_tier_allocation','supplier_collaboration'];case'subscription':return[...b,'subscription_with_proof'];case'retail':return[...b,'accept_timeout_protection'];default:return b;}}export function planMigration(a){const b=a['ir_discovery']?a['industry']?{...a['ir_discovery'],'industry':a['industry']}:a['ir_discovery']:undefined;let c,d={'source':'explicit','confidence':0x1};if(a['template_id']){c=getTemplate(a['template_id']);if(c&&a['industry']&&c['industry']!==a['industry']){const i=matchTemplate(a['industry']+'\x20'+a['description'],undefined,b);i&&i['template']['industry']===a['industry']&&(c=i['template'],d={'source':i['source'],'confidence':i['confidence'],...i['matched_tags']?{'matched_tags':i['matched_tags']}:{}});}}else{const j=a['industry']?a['industry']+'\x20'+a['description']:a['description'],k=matchTemplate(j,a['industry']?undefined:a['ir_industry'],b);c=k?.['template'];k&&(d={'source':k['source'],'confidence':k['confidence'],...k['matched_tags']?{'matched_tags':k['matched_tags']}:{}});if(!c&&a['industry']){c=listTemplates()['templates']['find'](l=>l['industry']===a['industry']&&l['archetype']==='leader');if(c)d={'source':'industry_leader','confidence':0.35};}}if(!c)return undefined;const e=manualReviewEntries(c),f=genericUnmappedEntries(c),g=splitConflictEntry(c,a['description']);if(g)e['unshift'](g);const h=disclosedFactEntries(a['description'],e,f);return e['push'](...h['manual']),f['push'](...h['unmapped']),{'source':{'url':a['url'],'description':a['description'],'detected_industry':c['industry'],'matched_template':c['id']},'template_match':d,'mapped':genericMappedEntries(c),'unmapped':f,'manual_review':e,'wowok_advantages':wowokAdvantages(c),'customizable_modules':customizableModules(c),'role_assessment':{'recommended':c['recommended_role'],'rationale':c['role_rationale'],'alternatives':['merchant','supplier','both']['filter'](l=>l!==c['recommended_role'])},'risk_check':dryRunRiskCheck(c),...c['conditional_guards']?.['length']?{'questions':[...new Set(c['conditional_guards']['map'](l=>l['param']))]['map'](l=>{const m=c['conditional_guards']['find'](n=>n['param']===l);return{'param':l,'question':m['question'],'options':[...m['values']],'default':String(c['fee_params'][l]??'')};})}:{},'network':a['network']??'testnet'};}
@@ -33,6 +33,7 @@ export declare function handleRecommendIndustry(v: RecommendIndustryInput): {
33
33
  contradicted_traits: string[];
34
34
  evidenced_traits: string[];
35
35
  domain_prior: boolean | undefined;
36
+ ir_industry_match: boolean | undefined;
36
37
  requirement_support: number | undefined;
37
38
  location_sensitivity: LocationSensitivity;
38
39
  trust_selling_points: string[];
@@ -1 +1 @@
1
- import{getIndustryModeRegistry,getMetricRegistry,getConstraintRegistry}from'../../extensions/index.js';import{inferTraitsFromDescription,findSimilarIndustries,detectDomainPriors,filterConsistentIndustries}from'../../knowledge/industry-generalizer.js';import{normalizeSemanticIR,mergeSemanticIR,domainPriorsFromIR,mergeDomainPriors}from'../../knowledge/semantic-ir.js';import{resolveObjective,buildStrategyIntent,suggestLevers}from'../../persona/strategy-intent.js';import{ANTI_PATTERN_NODE_REGEX}from'../../knowledge/audit-rules.js';export const LOCAL_MODE_OWNER='local';function locationSensitivity(a){if(a['has_logistics'])return'logistics';if(a['pure_digital'])return'near';return'strict';}function validateMachineShape(a,b){const c=[];if(!Array['isArray'](a))return c;const d=new Set();for(const e of a){const f=e?.['name'];if(typeof f!=='string'||!f){c['push'](b+':\x20every\x20node\x20must\x20have\x20a\x20non-empty\x20string\x20\x27name\x27');continue;}d['has'](f)&&c['push'](b+':\x20duplicate\x20node\x20name\x20\x27'+f+'\x27\x20(R-M1-10)'),d['add'](f),ANTI_PATTERN_NODE_REGEX['test'](f)&&c['push'](b+':\x20node\x20\x27'+f+'\x27\x20violates\x20R-M1-11\x20—\x20dispute/refund\x20flows\x20must\x20NOT\x20be\x20'+'modeled\x20as\x20Machine\x20nodes.\x20Disputes\x20flow\x20through\x20Service.arbitrations\x20→\x20Arbitration.dispute()\x20'+'independently\x20of\x20the\x20Machine.\x20Use\x20business-state\x20nodes\x20(e.g.\x20\x27cancel_requested\x27,\x20\x27closed_cancel\x27)\x20'+'and\x20route\x20fund\x20refunds\x20via\x20Allocator\x20triggered\x20by\x20those\x20states.\x20Bare\x20fund-terminal\x20names\x20'+'(\x27refund\x27,\x20\x27cancelled\x27,\x20…)\x20are\x20rejected\x20here\x20—\x20only\x20the\x20template\x20scanner\x20can\x20exempt\x20them,\x20'+'when\x20the\x20refund\x20allocator\x27s\x20guard\x20provably\x20anchors\x20to\x20that\x20state.');}return c;}function modeLevers(a){const b=[];return(a['capabilities_used']['some'](d=>d['startsWith']('reward.'))||a['flywheel']?.['rewardStrategy']&&a['flywheel']['rewardStrategy']!=='User-defined')&&b['push']('reward'),(a['flywheel']?.['discountStrategy']&&a['flywheel']['discountStrategy']!=='User-defined'||a['config_overrides']?.['service']?.['first_order_discount']===!![])&&b['push']('discount'),(a['capabilities_used']['includes']('guard.validate_buy')||a['guards']['some'](c=>c['template_id']['includes']('buy')))&&b['push']('buy_guard'),a['capabilities_used']['includes']('machine.node_topology')&&a['machine_shape']['length']>0x0&&b['push']('machine_design'),b;}function resolveStrategyObjectives(a){const b=typeof a==='string'?[a]:a??[],c=new Set();for(const d of b){const e=resolveObjective(d);if(e)c['add'](e);}return[...c];}const TRAIT_OBJECTIVE_PRIORS=[{'when':a=>a['trust_sensitivity']==='high'||a['regulatory_intensity']==='high','objective':'buyer_screening','metrics':['dispute_rate','claim_rate'],'target':'buyer\x20eligibility\x20gate\x20covers\x20every\x20party\x20whose\x20identity\x20the\x20trade\x20depends\x20on'},{'when':a=>a['long_cycle'],'objective':'gross_margin_control','metrics':['acceptance_rate','cycle_days'],'target':'margin\x20held\x20across\x20the\x20full\x20delivery\x20cycle,\x20not\x20per\x20milestone'},{'when':a=>a['consumption_frequency']==='frequent','objective':'sales_priority','metrics':['order_volume','repeat_rate'],'target':'repeat-purchase\x20order\x20volume\x20over\x20the\x20next\x2030\x20days'},{'when':a=>a['avg_ticket_size']==='large'||a['deposit_required'],'objective':'profit_priority','metrics':['gross_margin','escrow_balance'],'target':'per-order\x20margin\x20first;\x20the\x20ticket\x20is\x20large\x20enough\x20that\x20margin\x20dominates\x20volume'},{'when':a=>a['has_logistics'],'objective':'gross_margin_control','metrics':['fulfilment_cost_ratio','on_time_rate'],'target':'fulfilment\x20cost\x20held\x20inside\x20the\x20declared\x20merchant\x20share'}];function traitDerivedObjectives(a,b=0x2){const c=[],d=new Set();for(const e of TRAIT_OBJECTIVE_PRIORS){if(c['length']>=b)break;if(d['has'](e['objective']))continue;if(!e['when'](a))continue;d['add'](e['objective']),c['push']({'objective':e['objective'],'metrics':[...e['metrics']],'target':e['target']});}return c;}export function handleRecommendIndustry(a){const b=(a['intent']??a['project_description']??a['project_name']??'')['trim']();if(!b)throw new Error('recommend_industry\x20requires\x20\x27intent\x27\x20(business\x20description\x20text).\x20'+'Example:\x20intent=\x27I\x20rent\x20cameras\x20to\x20photographers\x20with\x20deposit\x20and\x20damage\x20inspection\x27.');const c=a['semantic_ir']?normalizeSemanticIR(a['semantic_ir']):undefined,d=inferTraitsFromDescription(b),e=c?mergeSemanticIR(d,c['ir']):undefined,f=e??d,g=!c?'keywords':d['matched_keywords']['length']>0x0?'semantic_ir+keywords':'semantic_ir',h=detectDomainPriors(b),i=c?mergeDomainPriors(h,domainPriorsFromIR(c['ir'])):h,j=new Set(i['flatMap'](D=>D['industries'])),k=new Map();for(const D of i){for(const E of D['industries']){k['set'](E,Math['min'](0.25,(k['get'](E)??0x0)+D['boost']));}}const l=findSimilarIndustries(f['traits'],undefined,{'trait_confidence':f['trait_confidence']}),m=l['map'](F=>{const G=k['get'](F['industry'])??0x0;if(G===0x0)return F;const H=Math['min'](0x1,Number((F['similarity']+G)['toFixed'](0x4)));return{...F,'similarity':H,'trait_distance':Number((0x1-H)['toFixed'](0x4)),'domain_prior':!![]};}),{consistent:n,inconsistent:o}=filterConsistentIndustries(m,f['traits'],f['trait_confidence']),q=o['map'](F=>({'industry':F['industry'],'contradicted_requirements':F['contradictions']['map'](G=>G['trait']+'='+String(G['value'])+'\x20('+G['reason']+')')}));n['sort']((F,G)=>G['similarity']-F['similarity']||F['industry']['localeCompare'](G['industry']));const r=n['slice'](0x0,0x3),s=resolveStrategyObjectives(a['strategy']),t=s['map'](F=>buildStrategyIntent(F)),u=t['length']>0x0||f['confidence']===0x0?[]:traitDerivedObjectives(f['traits'])['map'](F=>buildStrategyIntent(F['objective'],F['target'],F['metrics'])),w=[...t,...u],x=[...new Set(w['flatMap'](F=>F['levers']))],y=getIndustryModeRegistry(),z=r['map'](F=>{const G=y['getMode'](F['industry']),H=G?modeLevers(G):[],I=x['filter'](K=>H['includes'](K)),J=x['length']>0x0?{'score':I['length']/x['length'],'matched_levers':I,'missing_levers':x['filter'](K=>!H['includes'](K))}:undefined;return{'industry':F['industry'],'similarity':F['similarity'],'trait_distance':F['trait_distance'],'matched_traits':F['matched_traits'],'contradicted_traits':F['contradicted_traits']??[],'evidenced_traits':F['evidenced_traits']??[],'domain_prior':j['has'](F['industry'])?!![]:undefined,'requirement_support':F['requirement_support'],'location_sensitivity':G?locationSensitivity(G['traits']):'strict','trust_selling_points':G?G['flywheel']?.['trustSellingPoints']??[]:[],'build_notes':G?.['build_notes']??[],'strategy_alignment':J};});x['length']>0x0&&z['sort']((F,G)=>{const H=F['similarity']*0.7+(F['strategy_alignment']?.['score']??0x0)*0.3,I=G['similarity']*0.7+(G['strategy_alignment']?.['score']??0x0)*0.3;return I-H;});const A=z[0x0],B=i['length']>0x0?'\x20Domain\x20prior\x20applied:\x20'+i['map'](F=>F['matched_keywords']['length']>0x0?F['domain']+'\x20('+F['matched_keywords']['slice'](0x0,0x6)['join']('/')+')':F['domain']+'\x20(semantic\x20IR)')['join'](';\x20')+'.':'',C=q['length']>0x0?'\x20Excluded\x20'+q['length']+'\x20industry\x20mode(s)\x20whose\x20required\x20traits\x20the\x20inference\x20contradicts:\x20'+q['map'](F=>F['industry']+'\x20['+F['contradicted_requirements']['join'](';\x20')+']')['join']('\x20|\x20')+'.':'';return{'action':'recommend_industry','intent':b,'inferred_traits':f['traits'],'inference_confidence':f['confidence'],'inference_source':g,'matched_keywords':f['matched_keywords'],'semantic_ir':c?.['ir'],'semantic_ir_digest':c?.['digest'],'semantic_ir_issues':c&&c['issues']['length']>0x0?c['issues']:undefined,'semantic_ir_conflicts':e&&e['conflicts']['length']>0x0?e['conflicts']:undefined,'domain_priors':i,'strategy_intents':w,'lever_suggestions':w['flatMap'](F=>suggestLevers(F)),'recommendations':z,'excluded_by_consistency':q,'hint':A?'Top\x20match:\x20\x27'+A['industry']+'\x27\x20(similarity\x20'+(A['similarity']*0x64)['toFixed'](0x0)+'%'+(x['length']>0x0?',\x20strategy\x20alignment\x20'+((A['strategy_alignment']?.['score']??0x0)*0x64)['toFixed'](0x0)+'%':'')+').\x20Use\x20it\x20to\x20shape\x20the\x20build\x20—\x20run\x20goal_operation\x20action=\x27merchant_guide\x27\x20(or\x20\x27analyze_intent\x27)\x20with\x20this\x20industry\x20context,\x20'+'or\x20choose\x20another\x20industry\x20from\x20\x27recommendations\x27.'+B+C:'No\x20similar\x20industry\x20found.\x20Shape\x20the\x20build\x20from\x20scratch\x20via\x20goal_operation\x20action=\x27merchant_guide\x27.'+B};}export async function handleListModes(){const a=getIndustryModeRegistry(),b=a['listModes']()['filter'](d=>d['source']==='builtin')['map'](d=>({'name':d['name'],'display_name':d['display_name'],'version':d['version'],'key_risk':d['key_risk'],'machine_nodes':d['machine_shape']['map'](e=>e['name']),'buyer_action_nodes':d['machine_shape']['filter'](e=>e['operator']==='order_payer')['map'](e=>e['name']),'similar_industries':d['similar_industries']??[],'location_sensitivity':locationSensitivity(d['traits']),'trust_selling_points':d['flywheel']?.['trustSellingPoints']??[],'build_notes':d['build_notes']??[]})),c=(await a['listUserModes'](LOCAL_MODE_OWNER))['map'](d=>({'name':d['name'],'display_name':d['display_name'],'version':d['version'],'derived_from':d['derived_from']??null,'key_risk':d['key_risk'],'machine_nodes':d['machine_shape']['map'](e=>e['name']),'buyer_action_nodes':d['machine_shape']['filter'](e=>e['operator']==='order_payer')['map'](e=>e['name']),'location_sensitivity':locationSensitivity(d['traits']),'trust_selling_points':d['flywheel']?.['trustSellingPoints']??[],'build_notes':d['build_notes']??[],'evolution_history':(d['evolution_history']??[])['map'](e=>({'version':e['version'],'changed_at':e['changed_at'],'changes':e['changes']}))}));return{'action':'list_modes','builtin_modes':b,'user_modes':c,'owner':LOCAL_MODE_OWNER,'hint':'Use\x20a\x20builtin\x20mode\x20name\x20as\x20the\x20industry/mode\x20context\x20for\x20your\x20build\x20(see\x20recommend_industry\x20/\x20merchant_guide).\x20'+'Use\x20derive_user_mode\x20to\x20customize\x20a\x20builtin\x20mode,\x20or\x20register_user_mode\x20for\x20a\x20fully\x20custom\x20mode.\x20'+'User\x20modes\x20are\x20referenced\x20as\x20\x27<name>\x27\x20in\x20derive/evolve/unregister\x20actions.'};}export async function handleDeriveUserMode(a){const b=requireField(a['mode_source'],'mode_source'),c=requireField(a['mode_name'],'mode_name'),d=a['mode_changes']??{},e=validateMachineShape(d['machine_shape'],'mode_changes.machine_shape');if(e['length']>0x0)throw new Error('derive_user_mode\x20blocked:\x0a'+e['join']('\x0a'));const f=getIndustryModeRegistry(),g=await f['deriveMode'](b,d,LOCAL_MODE_OWNER,c,a['mode_display_name']);if(!g)throw new Error('derive_user_mode\x20failed:\x20source\x20mode\x20\x27'+b+'\x27\x20not\x20found,\x20or\x20name\x20\x27'+c+'\x27\x20conflicts\x20'+'with\x20a\x20builtin/existing\x20user\x20mode.\x20Call\x20list_modes\x20to\x20see\x20available\x20names.');return{'action':'derive_user_mode','mode':summarizeUserMode(g),'hint':'Mode\x20\x27'+c+'\x27\x20derived\x20from\x20\x27'+b+'\x27.\x20Use\x20it\x20as\x20the\x20industry/mode\x20context\x20for\x20your\x20build.\x20'+'Iterate\x20with\x20evolve_user_mode.'};}export async function handleEvolveUserMode(a){const b=requireField(a['mode_name'],'mode_name'),c=requireField(a['mode_change_description'],'mode_change_description'),d=a['mode_changes']??{},e=validateMachineShape(d['machine_shape'],'mode_changes.machine_shape');if(e['length']>0x0)throw new Error('evolve_user_mode\x20blocked:\x0a'+e['join']('\x0a'));const f=getIndustryModeRegistry(),g=await f['evolveMode'](b,d,LOCAL_MODE_OWNER,c,a['mode_bump_version']??!![]);if(!g)throw new Error('evolve_user_mode\x20failed:\x20user\x20mode\x20\x27'+b+'\x27\x20not\x20found\x20for\x20owner\x20\x27'+LOCAL_MODE_OWNER+'\x27.\x20'+'Call\x20list_modes\x20to\x20see\x20your\x20modes.');return{'action':'evolve_user_mode','mode':summarizeUserMode(g),'hint':'Mode\x20\x27'+b+'\x27\x20evolved\x20to\x20'+g['version']+'.\x20Evolution\x20history\x20recorded.'};}export async function handleRegisterUserMode(a){const b=requireField(a['mode_name'],'mode_name'),c=a['mode_changes']??{},d=[];(!Array['isArray'](c['machine_shape'])||c['machine_shape']['length']===0x0)&&d['push']('machine_shape\x20(non-empty\x20array\x20of\x20{name,\x20role})');(typeof c['key_risk']!=='string'||!c['key_risk'])&&d['push']('key_risk\x20(string\x20describing\x20the\x20industry\x27s\x20key\x20risk)');if(d['length']>0x0)throw new Error('register_user_mode\x20requires\x20these\x20fields\x20in\x20mode_changes:\x20'+d['join'](',\x20')+'.\x20'+'Tip:\x20derive_user_mode\x20from\x20a\x20builtin\x20mode\x20is\x20usually\x20easier\x20than\x20registering\x20from\x20scratch.');const e=validateMachineShape(c['machine_shape'],'mode_changes.machine_shape');if(e['length']>0x0)throw new Error('register_user_mode\x20blocked:\x0a'+e['join']('\x0a'));const f=getIndustryModeRegistry(),g=f['getMode']('general');if(!g)throw new Error('Builtin\x20mode\x20\x27general\x27\x20not\x20registered\x20—\x20cannot\x20build\x20custom\x20mode\x20defaults');const h={...g,...c,'name':b,'display_name':a['mode_display_name']??b,'version':'v1','source':'custom','owner':LOCAL_MODE_OWNER,'derived_from':undefined,'evolution_history':[]},i=await f['registerUserMode'](h,LOCAL_MODE_OWNER);if(!i)throw new Error('register_user_mode\x20failed:\x20name\x20\x27'+b+'\x27\x20conflicts\x20with\x20a\x20builtin/existing\x20user\x20mode,\x20'+'or\x20payload\x20is\x20invalid.\x20Call\x20list_modes\x20to\x20see\x20available\x20names.');return{'action':'register_user_mode','mode':summarizeUserMode(h),'hint':'Custom\x20mode\x20\x27'+b+'\x27\x20registered.\x20Use\x20it\x20as\x20the\x20industry/mode\x20context\x20for\x20your\x20build.'};}export async function handleUnregisterUserMode(a){const b=requireField(a['mode_name'],'mode_name'),c=getIndustryModeRegistry(),d=await c['unregisterUserMode'](b,LOCAL_MODE_OWNER);if(!d)throw new Error('unregister_user_mode\x20failed:\x20user\x20mode\x20\x27'+b+'\x27\x20not\x20found\x20for\x20owner\x20\x27'+LOCAL_MODE_OWNER+'\x27.');return{'action':'unregister_user_mode','removed':!![],'mode_name':b};}export async function handleRegisterCustomMetric(a){const b=requireField(a['metric_id'],'metric_id'),c=requireField(a['metric_display_name'],'metric_display_name'),d=requireField(a['metric_description'],'metric_description'),e=requireField(a['metric_type'],'metric_type'),f=requireField(a['metric_scale'],'metric_scale'),g=await getMetricRegistry()['registerCustomMetric'](b,c,d,e,f,LOCAL_MODE_OWNER,a['metric_weight']);if(!g)throw new Error('register_custom_metric\x20failed:\x20metric_id\x20\x27'+b+'\x27\x20already\x20exists\x20or\x20fields\x20are\x20invalid.');return{'action':'register_custom_metric','metric':{'metric_id':b,'display_name':c,'description':d,'type':e,'scale':f,'weight':a['metric_weight']??0x1,'scope':'custom','owner':LOCAL_MODE_OWNER},'hint':'Custom\x20metric\x20\x27'+b+'\x27\x20registered\x20globally\x20and\x20persisted\x20(survives\x20restart)\x20—\x20all\x20modes\x20reference\x20it\x20in\x20evaluation.'};}export async function handleUnregisterCustomMetric(a){const b=requireField(a['metric_id'],'metric_id'),c=await getMetricRegistry()['unregisterMetric'](b,LOCAL_MODE_OWNER);if(!c)throw new Error('unregister_custom_metric\x20failed:\x20custom\x20metric\x20\x27'+b+'\x27\x20not\x20found\x20(builtin\x20metrics\x20cannot\x20be\x20deleted).\x20'+'Call\x20list_metrics_constraints\x20with\x20scope_filter=\x27custom\x27\x20to\x20see\x20deletable\x20metrics.');return{'action':'unregister_custom_metric','removed':!![],'metric_id':b};}export async function handleRegisterCustomConstraint(a){const b=requireField(a['constraint_id'],'constraint_id'),c=requireField(a['constraint_display_name'],'constraint_display_name'),d=requireField(a['constraint_description'],'constraint_description'),e=a['constraint_rule'];if(!e||typeof e!=='object'||!('type'in e))throw new Error('constraint_rule\x20is\x20required\x20and\x20must\x20be\x20one\x20of:\x20'+'{type:\x27capability_required\x27,\x20capability_id}\x20|\x20{type:\x27capability_forbidden\x27,\x20capability_id}\x20|\x20'+'{type:\x27numeric_limit\x27,\x20field,\x20max?,\x20min?}\x20|\x20{type:\x27condition_required\x27,\x20condition,\x20ai_evaluated:true}');const f=await getConstraintRegistry()['registerCustomConstraint'](b,c,d,e,LOCAL_MODE_OWNER,a['constraint_severity']??'soft',a['constraint_on_violation']??'warn');if(!f)throw new Error('register_custom_constraint\x20failed:\x20constraint_id\x20\x27'+b+'\x27\x20already\x20exists\x20or\x20rule\x20is\x20invalid.');return{'action':'register_custom_constraint','constraint':{'constraint_id':b,'display_name':c,'description':d,'rule':e,'severity':a['constraint_severity']??'soft','on_violation':a['constraint_on_violation']??'warn','scope':'custom','owner':LOCAL_MODE_OWNER},'hint':'Custom\x20constraint\x20\x27'+b+'\x27\x20registered\x20and\x20persisted\x20(survives\x20restart).\x20\x27hard\x27\x20constraints\x20mark\x20a\x20mode\x20not\x20applicable\x20on\x20violation;\x20\x27soft\x27\x20only\x20warn.'};}export async function handleUnregisterCustomConstraint(a){const b=requireField(a['constraint_id'],'constraint_id'),c=await getConstraintRegistry()['unregisterConstraint'](b,LOCAL_MODE_OWNER);if(!c)throw new Error('unregister_custom_constraint\x20failed:\x20custom\x20constraint\x20\x27'+b+'\x27\x20not\x20found\x20(builtin\x20constraints\x20cannot\x20be\x20deleted).\x20'+'Call\x20list_metrics_constraints\x20with\x20scope_filter=\x27custom\x27\x20to\x20see\x20deletable\x20constraints.');return{'action':'unregister_custom_constraint','removed':!![],'constraint_id':b};}export async function handleListMetricsConstraints(a){const b=(await getMetricRegistry()['listMetrics']({'type':a['metric_type_filter'],'scope':a['scope_filter']}))['map'](d=>({'metric_id':d['metric_id'],'display_name':d['display_name'],'description':d['description'],'type':d['type'],'scale':d['scale'],'weight':d['weight'],'scope':d['scope']})),c=(await getConstraintRegistry()['listConstraints']({'scope':a['scope_filter']}))['map'](d=>({'constraint_id':d['constraint_id'],'display_name':d['display_name'],'description':d['description'],'rule':d['rule'],'severity':d['severity'],'on_violation':d['on_violation'],'scope':d['scope']}));return{'action':'list_metrics_constraints','metrics':b,'constraints':c,'hint':'Register\x20custom\x20entries\x20via\x20register_custom_metric\x20/\x20register_custom_constraint;\x20'+'delete\x20via\x20unregister_custom_metric\x20/\x20unregister_custom_constraint\x20(custom\x20only).\x20'+'Custom\x20entries\x20are\x20persisted\x20and\x20survive\x20restart.\x20'+'Filter\x20with\x20metric_type_filter\x20(\x27risk\x27|\x27benefit\x27)\x20or\x20scope_filter\x20(\x27builtin\x27|\x27custom\x27).'};}function requireField(a,b){if(a===undefined||a===null||typeof a==='string'&&!a['trim']())throw new Error('\x27'+b+'\x27\x20is\x20required\x20for\x20this\x20action');return a;}function summarizeUserMode(a){return{'name':a['name'],'display_name':a['display_name'],'version':a['version'],'derived_from':a['derived_from']??null,'owner':a['owner'],'key_risk':a['key_risk'],'machine_nodes':a['machine_shape']['map'](b=>b['name']),'buyer_action_nodes':a['machine_shape']['filter'](b=>b['operator']==='order_payer')['map'](b=>b['name']),'location_sensitivity':locationSensitivity(a['traits']),'trust_selling_points':a['flywheel']?.['trustSellingPoints']??[],'build_notes':a['build_notes']??[],'evolution_history':(a['evolution_history']??[])['map'](b=>({'version':b['version'],'changed_at':b['changed_at'],'changes':b['changes']}))};}
1
+ import{getIndustryModeRegistry,getMetricRegistry,getConstraintRegistry}from'../../extensions/index.js';import{inferTraitsFromDescription,findSimilarIndustries,detectDomainPriors,filterConsistentIndustries}from'../../knowledge/industry-generalizer.js';import{normalizeSemanticIR,mergeSemanticIR,domainPriorsFromIR,mergeDomainPriors,discoverySignal}from'../../knowledge/semantic-ir.js';import{resolveObjective,buildStrategyIntent,suggestLevers}from'../../persona/strategy-intent.js';import{ANTI_PATTERN_NODE_REGEX}from'../../knowledge/audit-rules.js';export const LOCAL_MODE_OWNER='local';function locationSensitivity(a){if(a['has_logistics'])return'logistics';if(a['pure_digital'])return'near';return'strict';}function validateMachineShape(a,b){const c=[];if(!Array['isArray'](a))return c;const d=new Set();for(const e of a){const f=e?.['name'];if(typeof f!=='string'||!f){c['push'](b+':\x20every\x20node\x20must\x20have\x20a\x20non-empty\x20string\x20\x27name\x27');continue;}d['has'](f)&&c['push'](b+':\x20duplicate\x20node\x20name\x20\x27'+f+'\x27\x20(R-M1-10)'),d['add'](f),ANTI_PATTERN_NODE_REGEX['test'](f)&&c['push'](b+':\x20node\x20\x27'+f+'\x27\x20violates\x20R-M1-11\x20—\x20dispute/refund\x20flows\x20must\x20NOT\x20be\x20'+'modeled\x20as\x20Machine\x20nodes.\x20Disputes\x20flow\x20through\x20Service.arbitrations\x20→\x20Arbitration.dispute()\x20'+'independently\x20of\x20the\x20Machine.\x20Use\x20business-state\x20nodes\x20(e.g.\x20\x27cancel_requested\x27,\x20\x27closed_cancel\x27)\x20'+'and\x20route\x20fund\x20refunds\x20via\x20Allocator\x20triggered\x20by\x20those\x20states.\x20Bare\x20fund-terminal\x20names\x20'+'(\x27refund\x27,\x20\x27cancelled\x27,\x20…)\x20are\x20rejected\x20here\x20—\x20only\x20the\x20template\x20scanner\x20can\x20exempt\x20them,\x20'+'when\x20the\x20refund\x20allocator\x27s\x20guard\x20provably\x20anchors\x20to\x20that\x20state.');}return c;}function modeLevers(a){const b=[];return(a['capabilities_used']['some'](d=>d['startsWith']('reward.'))||a['flywheel']?.['rewardStrategy']&&a['flywheel']['rewardStrategy']!=='User-defined')&&b['push']('reward'),(a['flywheel']?.['discountStrategy']&&a['flywheel']['discountStrategy']!=='User-defined'||a['config_overrides']?.['service']?.['first_order_discount']===!![])&&b['push']('discount'),(a['capabilities_used']['includes']('guard.validate_buy')||a['guards']['some'](c=>c['template_id']['includes']('buy')))&&b['push']('buy_guard'),a['capabilities_used']['includes']('machine.node_topology')&&a['machine_shape']['length']>0x0&&b['push']('machine_design'),b;}function resolveStrategyObjectives(a){const b=typeof a==='string'?[a]:a??[],c=new Set();for(const d of b){const e=resolveObjective(d);if(e)c['add'](e);}return[...c];}const TRAIT_OBJECTIVE_PRIORS=[{'when':a=>a['trust_sensitivity']==='high'||a['regulatory_intensity']==='high','objective':'buyer_screening','metrics':['dispute_rate','claim_rate'],'target':'buyer\x20eligibility\x20gate\x20covers\x20every\x20party\x20whose\x20identity\x20the\x20trade\x20depends\x20on'},{'when':a=>a['long_cycle'],'objective':'gross_margin_control','metrics':['acceptance_rate','cycle_days'],'target':'margin\x20held\x20across\x20the\x20full\x20delivery\x20cycle,\x20not\x20per\x20milestone'},{'when':a=>a['consumption_frequency']==='frequent','objective':'sales_priority','metrics':['order_volume','repeat_rate'],'target':'repeat-purchase\x20order\x20volume\x20over\x20the\x20next\x2030\x20days'},{'when':a=>a['avg_ticket_size']==='large'||a['deposit_required'],'objective':'profit_priority','metrics':['gross_margin','escrow_balance'],'target':'per-order\x20margin\x20first;\x20the\x20ticket\x20is\x20large\x20enough\x20that\x20margin\x20dominates\x20volume'},{'when':a=>a['has_logistics'],'objective':'gross_margin_control','metrics':['fulfilment_cost_ratio','on_time_rate'],'target':'fulfilment\x20cost\x20held\x20inside\x20the\x20declared\x20merchant\x20share'}];function traitDerivedObjectives(a,b=0x2){const c=[],d=new Set();for(const e of TRAIT_OBJECTIVE_PRIORS){if(c['length']>=b)break;if(d['has'](e['objective']))continue;if(!e['when'](a))continue;d['add'](e['objective']),c['push']({'objective':e['objective'],'metrics':[...e['metrics']],'target':e['target']});}return c;}export function handleRecommendIndustry(a){const b=(a['intent']??a['project_description']??a['project_name']??'')['trim']();if(!b)throw new Error('recommend_industry\x20requires\x20\x27intent\x27\x20(business\x20description\x20text).\x20'+'Example:\x20intent=\x27I\x20rent\x20cameras\x20to\x20photographers\x20with\x20deposit\x20and\x20damage\x20inspection\x27.');const c=a['semantic_ir']?normalizeSemanticIR(a['semantic_ir'],{'source_text':b}):undefined,d=c?discoverySignal(c['ir']):undefined,e=inferTraitsFromDescription(b),f=c?mergeSemanticIR(e,c['ir']):undefined,g=f??e,h=!c?'keywords':e['matched_keywords']['length']>0x0?'semantic_ir+keywords':'semantic_ir',i=detectDomainPriors(b),j=c?mergeDomainPriors(i,domainPriorsFromIR(c['ir'])):i,k=new Set(j['flatMap'](F=>F['industries'])),l=new Map();for(const F of j){for(const G of F['industries']){l['set'](G,Math['min'](0.25,(l['get'](G)??0x0)+F['boost']));}}d?.['industry']&&l['set'](d['industry'],Math['min'](0.25,(l['get'](d['industry'])??0x0)+0.2));const m=findSimilarIndustries(g['traits'],undefined,{'trait_confidence':g['trait_confidence']}),n=m['map'](H=>{const I=l['get'](H['industry'])??0x0;if(I===0x0)return H;const J=Math['min'](0x1,Number((H['similarity']+I)['toFixed'](0x4)));return{...H,'similarity':J,'trait_distance':Number((0x1-J)['toFixed'](0x4)),'domain_prior':!![]};}),{consistent:o,inconsistent:q}=filterConsistentIndustries(n,g['traits'],g['trait_confidence']),r=q['map'](H=>({'industry':H['industry'],'contradicted_requirements':H['contradictions']['map'](I=>I['trait']+'='+String(I['value'])+'\x20('+I['reason']+')')}));o['sort']((H,I)=>I['similarity']-H['similarity']||H['industry']['localeCompare'](I['industry']));const s=o['slice'](0x0,0x3),t=resolveStrategyObjectives(a['strategy']),u=t['map'](H=>buildStrategyIntent(H)),w=u['length']>0x0||g['confidence']===0x0?[]:traitDerivedObjectives(g['traits'])['map'](H=>buildStrategyIntent(H['objective'],H['target'],H['metrics'])),x=[...u,...w],y=[...new Set(x['flatMap'](H=>H['levers']))],z=getIndustryModeRegistry(),A=s['map'](H=>{const I=z['getMode'](H['industry']),J=I?modeLevers(I):[],K=y['filter'](M=>J['includes'](M)),L=y['length']>0x0?{'score':K['length']/y['length'],'matched_levers':K,'missing_levers':y['filter'](M=>!J['includes'](M))}:undefined;return{'industry':H['industry'],'similarity':H['similarity'],'trait_distance':H['trait_distance'],'matched_traits':H['matched_traits'],'contradicted_traits':H['contradicted_traits']??[],'evidenced_traits':H['evidenced_traits']??[],'domain_prior':k['has'](H['industry'])?!![]:undefined,'ir_industry_match':d?.['industry']===H['industry']?!![]:undefined,'requirement_support':H['requirement_support'],'location_sensitivity':I?locationSensitivity(I['traits']):'strict','trust_selling_points':I?I['flywheel']?.['trustSellingPoints']??[]:[],'build_notes':I?.['build_notes']??[],'strategy_alignment':L};});y['length']>0x0&&A['sort']((H,I)=>{const J=H['similarity']*0.7+(H['strategy_alignment']?.['score']??0x0)*0.3,K=I['similarity']*0.7+(I['strategy_alignment']?.['score']??0x0)*0.3;return K-J;});const B=A[0x0],C=j['length']>0x0?'\x20Domain\x20prior\x20applied:\x20'+j['map'](H=>H['matched_keywords']['length']>0x0?H['domain']+'\x20('+H['matched_keywords']['slice'](0x0,0x6)['join']('/')+')':H['domain']+'\x20(semantic\x20IR)')['join'](';\x20')+'.':'',D=r['length']>0x0?'\x20Excluded\x20'+r['length']+'\x20industry\x20mode(s)\x20whose\x20required\x20traits\x20the\x20inference\x20contradicts:\x20'+r['map'](H=>H['industry']+'\x20['+H['contradicted_requirements']['join'](';\x20')+']')['join']('\x20|\x20')+'.':'',E=d?.['industry']?'\x20Semantic\x20IR\x20discovery\x20industry\x20\x27'+d['industry']+'\x27\x20was\x20applied\x20as\x20a\x20ranking\x20prior'+(d['tags']['length']>0x0?'\x20(tags:\x20'+d['tags']['join'](',\x20')+').':'.'):'';return{'action':'recommend_industry','intent':b,'inferred_traits':g['traits'],'inference_confidence':g['confidence'],'inference_source':h,'matched_keywords':g['matched_keywords'],'semantic_ir':c?.['ir'],'semantic_ir_digest':c?.['digest'],'semantic_ir_issues':c&&c['issues']['length']>0x0?c['issues']:undefined,'semantic_ir_conflicts':f&&f['conflicts']['length']>0x0?f['conflicts']:undefined,'domain_priors':j,'strategy_intents':x,'lever_suggestions':x['flatMap'](H=>suggestLevers(H)),'recommendations':A,'excluded_by_consistency':r,'hint':B?'Top\x20match:\x20\x27'+B['industry']+'\x27\x20(similarity\x20'+(B['similarity']*0x64)['toFixed'](0x0)+'%'+(y['length']>0x0?',\x20strategy\x20alignment\x20'+((B['strategy_alignment']?.['score']??0x0)*0x64)['toFixed'](0x0)+'%':'')+').\x20Use\x20it\x20to\x20shape\x20the\x20build\x20—\x20run\x20goal_operation\x20action=\x27merchant_guide\x27\x20(or\x20\x27analyze_intent\x27)\x20with\x20this\x20industry\x20context,\x20'+'or\x20choose\x20another\x20industry\x20from\x20\x27recommendations\x27.'+C+E+D:'No\x20similar\x20industry\x20found.\x20Shape\x20the\x20build\x20from\x20scratch\x20via\x20goal_operation\x20action=\x27merchant_guide\x27.'+C+E};}export async function handleListModes(){const a=getIndustryModeRegistry(),b=a['listModes']()['filter'](d=>d['source']==='builtin')['map'](d=>({'name':d['name'],'display_name':d['display_name'],'version':d['version'],'key_risk':d['key_risk'],'machine_nodes':d['machine_shape']['map'](e=>e['name']),'buyer_action_nodes':d['machine_shape']['filter'](e=>e['operator']==='order_payer')['map'](e=>e['name']),'similar_industries':d['similar_industries']??[],'location_sensitivity':locationSensitivity(d['traits']),'trust_selling_points':d['flywheel']?.['trustSellingPoints']??[],'build_notes':d['build_notes']??[]})),c=(await a['listUserModes'](LOCAL_MODE_OWNER))['map'](d=>({'name':d['name'],'display_name':d['display_name'],'version':d['version'],'derived_from':d['derived_from']??null,'key_risk':d['key_risk'],'machine_nodes':d['machine_shape']['map'](e=>e['name']),'buyer_action_nodes':d['machine_shape']['filter'](e=>e['operator']==='order_payer')['map'](e=>e['name']),'location_sensitivity':locationSensitivity(d['traits']),'trust_selling_points':d['flywheel']?.['trustSellingPoints']??[],'build_notes':d['build_notes']??[],'evolution_history':(d['evolution_history']??[])['map'](e=>({'version':e['version'],'changed_at':e['changed_at'],'changes':e['changes']}))}));return{'action':'list_modes','builtin_modes':b,'user_modes':c,'owner':LOCAL_MODE_OWNER,'hint':'Use\x20a\x20builtin\x20mode\x20name\x20as\x20the\x20industry/mode\x20context\x20for\x20your\x20build\x20(see\x20recommend_industry\x20/\x20merchant_guide).\x20'+'Use\x20derive_user_mode\x20to\x20customize\x20a\x20builtin\x20mode,\x20or\x20register_user_mode\x20for\x20a\x20fully\x20custom\x20mode.\x20'+'User\x20modes\x20are\x20referenced\x20as\x20\x27<name>\x27\x20in\x20derive/evolve/unregister\x20actions.'};}export async function handleDeriveUserMode(a){const b=requireField(a['mode_source'],'mode_source'),c=requireField(a['mode_name'],'mode_name'),d=a['mode_changes']??{},e=validateMachineShape(d['machine_shape'],'mode_changes.machine_shape');if(e['length']>0x0)throw new Error('derive_user_mode\x20blocked:\x0a'+e['join']('\x0a'));const f=getIndustryModeRegistry(),g=await f['deriveMode'](b,d,LOCAL_MODE_OWNER,c,a['mode_display_name']);if(!g)throw new Error('derive_user_mode\x20failed:\x20source\x20mode\x20\x27'+b+'\x27\x20not\x20found,\x20or\x20name\x20\x27'+c+'\x27\x20conflicts\x20'+'with\x20a\x20builtin/existing\x20user\x20mode.\x20Call\x20list_modes\x20to\x20see\x20available\x20names.');return{'action':'derive_user_mode','mode':summarizeUserMode(g),'hint':'Mode\x20\x27'+c+'\x27\x20derived\x20from\x20\x27'+b+'\x27.\x20Use\x20it\x20as\x20the\x20industry/mode\x20context\x20for\x20your\x20build.\x20'+'Iterate\x20with\x20evolve_user_mode.'};}export async function handleEvolveUserMode(a){const b=requireField(a['mode_name'],'mode_name'),c=requireField(a['mode_change_description'],'mode_change_description'),d=a['mode_changes']??{},e=validateMachineShape(d['machine_shape'],'mode_changes.machine_shape');if(e['length']>0x0)throw new Error('evolve_user_mode\x20blocked:\x0a'+e['join']('\x0a'));const f=getIndustryModeRegistry(),g=await f['evolveMode'](b,d,LOCAL_MODE_OWNER,c,a['mode_bump_version']??!![]);if(!g)throw new Error('evolve_user_mode\x20failed:\x20user\x20mode\x20\x27'+b+'\x27\x20not\x20found\x20for\x20owner\x20\x27'+LOCAL_MODE_OWNER+'\x27.\x20'+'Call\x20list_modes\x20to\x20see\x20your\x20modes.');return{'action':'evolve_user_mode','mode':summarizeUserMode(g),'hint':'Mode\x20\x27'+b+'\x27\x20evolved\x20to\x20'+g['version']+'.\x20Evolution\x20history\x20recorded.'};}export async function handleRegisterUserMode(a){const b=requireField(a['mode_name'],'mode_name'),c=a['mode_changes']??{},d=[];(!Array['isArray'](c['machine_shape'])||c['machine_shape']['length']===0x0)&&d['push']('machine_shape\x20(non-empty\x20array\x20of\x20{name,\x20role})');(typeof c['key_risk']!=='string'||!c['key_risk'])&&d['push']('key_risk\x20(string\x20describing\x20the\x20industry\x27s\x20key\x20risk)');if(d['length']>0x0)throw new Error('register_user_mode\x20requires\x20these\x20fields\x20in\x20mode_changes:\x20'+d['join'](',\x20')+'.\x20'+'Tip:\x20derive_user_mode\x20from\x20a\x20builtin\x20mode\x20is\x20usually\x20easier\x20than\x20registering\x20from\x20scratch.');const e=validateMachineShape(c['machine_shape'],'mode_changes.machine_shape');if(e['length']>0x0)throw new Error('register_user_mode\x20blocked:\x0a'+e['join']('\x0a'));const f=getIndustryModeRegistry(),g=f['getMode']('general');if(!g)throw new Error('Builtin\x20mode\x20\x27general\x27\x20not\x20registered\x20—\x20cannot\x20build\x20custom\x20mode\x20defaults');const h={...g,...c,'name':b,'display_name':a['mode_display_name']??b,'version':'v1','source':'custom','owner':LOCAL_MODE_OWNER,'derived_from':undefined,'evolution_history':[]},i=await f['registerUserMode'](h,LOCAL_MODE_OWNER);if(!i)throw new Error('register_user_mode\x20failed:\x20name\x20\x27'+b+'\x27\x20conflicts\x20with\x20a\x20builtin/existing\x20user\x20mode,\x20'+'or\x20payload\x20is\x20invalid.\x20Call\x20list_modes\x20to\x20see\x20available\x20names.');return{'action':'register_user_mode','mode':summarizeUserMode(h),'hint':'Custom\x20mode\x20\x27'+b+'\x27\x20registered.\x20Use\x20it\x20as\x20the\x20industry/mode\x20context\x20for\x20your\x20build.'};}export async function handleUnregisterUserMode(a){const b=requireField(a['mode_name'],'mode_name'),c=getIndustryModeRegistry(),d=await c['unregisterUserMode'](b,LOCAL_MODE_OWNER);if(!d)throw new Error('unregister_user_mode\x20failed:\x20user\x20mode\x20\x27'+b+'\x27\x20not\x20found\x20for\x20owner\x20\x27'+LOCAL_MODE_OWNER+'\x27.');return{'action':'unregister_user_mode','removed':!![],'mode_name':b};}export async function handleRegisterCustomMetric(a){const b=requireField(a['metric_id'],'metric_id'),c=requireField(a['metric_display_name'],'metric_display_name'),d=requireField(a['metric_description'],'metric_description'),e=requireField(a['metric_type'],'metric_type'),f=requireField(a['metric_scale'],'metric_scale'),g=await getMetricRegistry()['registerCustomMetric'](b,c,d,e,f,LOCAL_MODE_OWNER,a['metric_weight']);if(!g)throw new Error('register_custom_metric\x20failed:\x20metric_id\x20\x27'+b+'\x27\x20already\x20exists\x20or\x20fields\x20are\x20invalid.');return{'action':'register_custom_metric','metric':{'metric_id':b,'display_name':c,'description':d,'type':e,'scale':f,'weight':a['metric_weight']??0x1,'scope':'custom','owner':LOCAL_MODE_OWNER},'hint':'Custom\x20metric\x20\x27'+b+'\x27\x20registered\x20globally\x20and\x20persisted\x20(survives\x20restart)\x20—\x20all\x20modes\x20reference\x20it\x20in\x20evaluation.'};}export async function handleUnregisterCustomMetric(a){const b=requireField(a['metric_id'],'metric_id'),c=await getMetricRegistry()['unregisterMetric'](b,LOCAL_MODE_OWNER);if(!c)throw new Error('unregister_custom_metric\x20failed:\x20custom\x20metric\x20\x27'+b+'\x27\x20not\x20found\x20(builtin\x20metrics\x20cannot\x20be\x20deleted).\x20'+'Call\x20list_metrics_constraints\x20with\x20scope_filter=\x27custom\x27\x20to\x20see\x20deletable\x20metrics.');return{'action':'unregister_custom_metric','removed':!![],'metric_id':b};}export async function handleRegisterCustomConstraint(a){const b=requireField(a['constraint_id'],'constraint_id'),c=requireField(a['constraint_display_name'],'constraint_display_name'),d=requireField(a['constraint_description'],'constraint_description'),e=a['constraint_rule'];if(!e||typeof e!=='object'||!('type'in e))throw new Error('constraint_rule\x20is\x20required\x20and\x20must\x20be\x20one\x20of:\x20'+'{type:\x27capability_required\x27,\x20capability_id}\x20|\x20{type:\x27capability_forbidden\x27,\x20capability_id}\x20|\x20'+'{type:\x27numeric_limit\x27,\x20field,\x20max?,\x20min?}\x20|\x20{type:\x27condition_required\x27,\x20condition,\x20ai_evaluated:true}');const f=await getConstraintRegistry()['registerCustomConstraint'](b,c,d,e,LOCAL_MODE_OWNER,a['constraint_severity']??'soft',a['constraint_on_violation']??'warn');if(!f)throw new Error('register_custom_constraint\x20failed:\x20constraint_id\x20\x27'+b+'\x27\x20already\x20exists\x20or\x20rule\x20is\x20invalid.');return{'action':'register_custom_constraint','constraint':{'constraint_id':b,'display_name':c,'description':d,'rule':e,'severity':a['constraint_severity']??'soft','on_violation':a['constraint_on_violation']??'warn','scope':'custom','owner':LOCAL_MODE_OWNER},'hint':'Custom\x20constraint\x20\x27'+b+'\x27\x20registered\x20and\x20persisted\x20(survives\x20restart).\x20\x27hard\x27\x20constraints\x20mark\x20a\x20mode\x20not\x20applicable\x20on\x20violation;\x20\x27soft\x27\x20only\x20warn.'};}export async function handleUnregisterCustomConstraint(a){const b=requireField(a['constraint_id'],'constraint_id'),c=await getConstraintRegistry()['unregisterConstraint'](b,LOCAL_MODE_OWNER);if(!c)throw new Error('unregister_custom_constraint\x20failed:\x20custom\x20constraint\x20\x27'+b+'\x27\x20not\x20found\x20(builtin\x20constraints\x20cannot\x20be\x20deleted).\x20'+'Call\x20list_metrics_constraints\x20with\x20scope_filter=\x27custom\x27\x20to\x20see\x20deletable\x20constraints.');return{'action':'unregister_custom_constraint','removed':!![],'constraint_id':b};}export async function handleListMetricsConstraints(a){const b=(await getMetricRegistry()['listMetrics']({'type':a['metric_type_filter'],'scope':a['scope_filter']}))['map'](d=>({'metric_id':d['metric_id'],'display_name':d['display_name'],'description':d['description'],'type':d['type'],'scale':d['scale'],'weight':d['weight'],'scope':d['scope']})),c=(await getConstraintRegistry()['listConstraints']({'scope':a['scope_filter']}))['map'](d=>({'constraint_id':d['constraint_id'],'display_name':d['display_name'],'description':d['description'],'rule':d['rule'],'severity':d['severity'],'on_violation':d['on_violation'],'scope':d['scope']}));return{'action':'list_metrics_constraints','metrics':b,'constraints':c,'hint':'Register\x20custom\x20entries\x20via\x20register_custom_metric\x20/\x20register_custom_constraint;\x20'+'delete\x20via\x20unregister_custom_metric\x20/\x20unregister_custom_constraint\x20(custom\x20only).\x20'+'Custom\x20entries\x20are\x20persisted\x20and\x20survive\x20restart.\x20'+'Filter\x20with\x20metric_type_filter\x20(\x27risk\x27|\x27benefit\x27)\x20or\x20scope_filter\x20(\x27builtin\x27|\x27custom\x27).'};}function requireField(a,b){if(a===undefined||a===null||typeof a==='string'&&!a['trim']())throw new Error('\x27'+b+'\x27\x20is\x20required\x20for\x20this\x20action');return a;}function summarizeUserMode(a){return{'name':a['name'],'display_name':a['display_name'],'version':a['version'],'derived_from':a['derived_from']??null,'owner':a['owner'],'key_risk':a['key_risk'],'machine_nodes':a['machine_shape']['map'](b=>b['name']),'buyer_action_nodes':a['machine_shape']['filter'](b=>b['operator']==='order_payer')['map'](b=>b['name']),'location_sensitivity':locationSensitivity(a['traits']),'trust_selling_points':a['flywheel']?.['trustSellingPoints']??[],'build_notes':a['build_notes']??[],'evolution_history':(a['evolution_history']??[])['map'](b=>({'version':b['version'],'changed_at':b['changed_at'],'changes':b['changes']}))};}