@wowok/agent-mcp 3.4.0 → 3.4.2

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 (412) hide show
  1. package/README.md +8 -0
  2. package/dist/chain-semantics/composition-truth.d.ts +102 -0
  3. package/dist/chain-semantics/composition-truth.js +1 -0
  4. package/dist/chain-semantics/eval-order.js +1 -1
  5. package/dist/chain-semantics/fund-flow.js +1 -1
  6. package/dist/chain-semantics/index.d.ts +1 -0
  7. package/dist/chain-semantics/index.js +1 -1
  8. package/dist/composition/audit.js +1 -1
  9. package/dist/composition/blueprint-view.d.ts +3 -3
  10. package/dist/composition/blueprint-view.js +1 -1
  11. package/dist/composition/compile.d.ts +24 -3
  12. package/dist/composition/compile.js +1 -1
  13. package/dist/composition/emit-phases.d.ts +206 -0
  14. package/dist/composition/emit-phases.js +1 -0
  15. package/dist/composition/generate.d.ts +40 -0
  16. package/dist/composition/generate.js +1 -0
  17. package/dist/composition/guard-fill.d.ts +44 -0
  18. package/dist/composition/guard-fill.js +1 -0
  19. package/dist/composition/inflight.d.ts +20 -2
  20. package/dist/composition/inflight.js +1 -1
  21. package/dist/composition/input-normalize.d.ts +15 -0
  22. package/dist/composition/input-normalize.js +1 -0
  23. package/dist/composition/materialize.d.ts +18 -13
  24. package/dist/composition/materialize.js +1 -1
  25. package/dist/composition/mode-gates.d.ts +35 -0
  26. package/dist/composition/mode-gates.js +1 -0
  27. package/dist/composition/param-disclosure.js +1 -1
  28. package/dist/composition/plan-retry-ledger.d.ts +21 -0
  29. package/dist/composition/plan-retry-ledger.js +1 -0
  30. package/dist/composition/plan.d.ts +7 -2
  31. package/dist/composition/plan.js +1 -1
  32. package/dist/composition/product-card.d.ts +94 -0
  33. package/dist/composition/product-card.js +1 -0
  34. package/dist/composition/supply-chain-emit.d.ts +46 -0
  35. package/dist/composition/supply-chain-emit.js +1 -0
  36. package/dist/config/config-audit.spec.js +1 -1
  37. package/dist/config/config-warnings.d.ts +2 -0
  38. package/dist/config/config-warnings.js +1 -0
  39. package/dist/config/exposure.d.ts +2 -2
  40. package/dist/config/judgment.d.ts +31 -5
  41. package/dist/config/judgment.js +1 -1
  42. package/dist/config/judgment.spec.js +1 -1
  43. package/dist/config/match-policy-file.d.ts +34 -0
  44. package/dist/config/match-policy-file.js +1 -0
  45. package/dist/config/match-policy-file.spec.d.ts +1 -0
  46. package/dist/config/match-policy-file.spec.js +1 -0
  47. package/dist/config/rule-engine.d.ts +5 -5
  48. package/dist/config/rule-engine.js +1 -1
  49. package/dist/config/runtime.d.ts +0 -1
  50. package/dist/config/runtime.js +1 -1
  51. package/dist/config/severity.d.ts +0 -2
  52. package/dist/config/severity.js +1 -1
  53. package/dist/config/store-policy.spec.js +1 -1
  54. package/dist/config/template-params.d.ts +42 -0
  55. package/dist/config/template-params.js +1 -0
  56. package/dist/config/template-params.spec.d.ts +1 -0
  57. package/dist/config/template-params.spec.js +1 -0
  58. package/dist/data/api/api.spec.js +1 -1
  59. package/dist/data/api/server.js +1 -1
  60. package/dist/data/projection/store.d.ts +2 -1
  61. package/dist/data/projection/store.js +1 -1
  62. package/dist/data/projection/types.d.ts +22 -0
  63. package/dist/data/sync/cdc.d.ts +1 -2
  64. package/dist/data/sync/cdc.js +1 -1
  65. package/dist/evaluation/acceptance.d.ts +8 -0
  66. package/dist/evaluation/acceptance.js +1 -1
  67. package/dist/evaluation/builtins/demand-match.js +1 -1
  68. package/dist/evaluation/builtins/graph-service.spec.js +1 -1
  69. package/dist/evaluation/capability.d.ts +2 -0
  70. package/dist/evaluation/category-match-rules.d.ts +0 -1
  71. package/dist/evaluation/category-match-rules.js +1 -1
  72. package/dist/evaluation/composer.d.ts +25 -0
  73. package/dist/evaluation/composer.js +1 -1
  74. package/dist/evaluation/engine.js +1 -1
  75. package/dist/evaluation/extract.d.ts +7 -0
  76. package/dist/evaluation/extract.js +1 -1
  77. package/dist/evaluation/game-strategy.d.ts +0 -3
  78. package/dist/evaluation/game-strategy.js +1 -1
  79. package/dist/evaluation/match-operation.d.ts +9 -0
  80. package/dist/evaluation/match-operation.js +1 -1
  81. package/dist/evaluation/match-policy-resolver.d.ts +9 -0
  82. package/dist/evaluation/match-policy-resolver.js +1 -0
  83. package/dist/evaluation/match-policy.d.ts +3 -1
  84. package/dist/evaluation/match-policy.js +1 -1
  85. package/dist/evaluation/region.d.ts +0 -6
  86. package/dist/evaluation/region.js +1 -1
  87. package/dist/evaluation/standards.d.ts +2 -1
  88. package/dist/evaluation/standards.js +1 -1
  89. package/dist/evaluation/structured-lines.d.ts +8 -0
  90. package/dist/evaluation/structured-lines.js +1 -0
  91. package/dist/evaluation/types.d.ts +6 -0
  92. package/dist/experience/realtime-feedback.js +1 -1
  93. package/dist/extensions/capability-manifest.d.ts +1 -0
  94. package/dist/extensions/capability-manifest.js +1 -1
  95. package/dist/extensions/capability.d.ts +91 -0
  96. package/dist/extensions/capability.js +1 -0
  97. package/dist/extensions/industry-audit.spec.js +1 -1
  98. package/dist/extensions/industry-pack.d.ts +13 -0
  99. package/dist/extensions/industry-pack.js +1 -1
  100. package/dist/extensions/modes.js +1 -1
  101. package/dist/extensions/registry.d.ts +0 -2
  102. package/dist/extensions/registry.js +1 -1
  103. package/dist/goal/GoalEngine.js +1 -1
  104. package/dist/graph/onchain/analyze.js +1 -1
  105. package/dist/graph/onchain/expand.js +1 -1
  106. package/dist/graph/onchain/exposure.js +1 -1
  107. package/dist/graph/onchain/facts.js +1 -1
  108. package/dist/graph/onchain/order-status.d.ts +0 -1
  109. package/dist/graph/onchain/order-status.js +1 -1
  110. package/dist/harness/recover.js +1 -1
  111. package/dist/harness/verify.d.ts +0 -3
  112. package/dist/harness/verify.js +1 -1
  113. package/dist/intent/types.d.ts +0 -1
  114. package/dist/intent/types.js +1 -1
  115. package/dist/keeper/detectors.js +1 -1
  116. package/dist/keeper/types.d.ts +0 -1
  117. package/dist/keeper/types.js +1 -1
  118. package/dist/knowledge/allocation-risk.d.ts +1 -0
  119. package/dist/knowledge/allocation-risk.js +1 -1
  120. package/dist/knowledge/allocator-rail-verifier.d.ts +6 -1
  121. package/dist/knowledge/allocator-rail-verifier.js +1 -1
  122. package/dist/knowledge/arbitration-ledger.js +1 -1
  123. package/dist/knowledge/arbitration-puzzle.js +1 -1
  124. package/dist/knowledge/arbitration-templates.js +1 -1
  125. package/dist/knowledge/audit-rules.d.ts +4 -3
  126. package/dist/knowledge/audit-rules.js +1 -1
  127. package/dist/knowledge/baselines/judgment-baselines.json +21 -2
  128. package/dist/knowledge/baselines/rules/oracle.json +120 -0
  129. package/dist/knowledge/baselines/rules/plan.json +384 -17
  130. package/dist/knowledge/baselines/rules/progress.json +20 -2
  131. package/dist/knowledge/builtin-templates.d.ts +28 -1
  132. package/dist/knowledge/builtin-templates.js +1 -1
  133. package/dist/knowledge/component-schema.js +1 -1
  134. package/dist/knowledge/contact-templates.d.ts +0 -1
  135. package/dist/knowledge/contact-templates.js +1 -1
  136. package/dist/knowledge/dynamic-pricing.js +1 -1
  137. package/dist/knowledge/fee-param-bindings.js +1 -1
  138. package/dist/knowledge/fund-layer.d.ts +1 -0
  139. package/dist/knowledge/fund-layer.js +1 -1
  140. package/dist/knowledge/game-scenarios.js +1 -1
  141. package/dist/knowledge/getting-started.js +1 -1
  142. package/dist/knowledge/guard-binding-table.d.ts +52 -0
  143. package/dist/knowledge/guard-binding-table.js +1 -0
  144. package/dist/knowledge/guard-binding-verifier.d.ts +30 -0
  145. package/dist/knowledge/guard-binding-verifier.js +1 -0
  146. package/dist/knowledge/guard-bindings.js +1 -1
  147. package/dist/knowledge/guard-blueprint.d.ts +68 -0
  148. package/dist/knowledge/guard-blueprint.js +1 -0
  149. package/dist/knowledge/guard-design-patterns.d.ts +1 -1
  150. package/dist/knowledge/guard-design-patterns.js +1 -1
  151. package/dist/knowledge/guard-field-cognition.js +1 -1
  152. package/dist/knowledge/guard-host-context.d.ts +24 -0
  153. package/dist/knowledge/guard-host-context.js +1 -0
  154. package/dist/knowledge/guard-lint.js +1 -1
  155. package/dist/knowledge/guard-node-gates.d.ts +3 -0
  156. package/dist/knowledge/guard-node-gates.js +1 -1
  157. package/dist/knowledge/guard-puzzle.js +1 -1
  158. package/dist/knowledge/guard-render.js +1 -1
  159. package/dist/knowledge/guard-risk.js +1 -1
  160. package/dist/knowledge/guard-submission-prompt.d.ts +11 -0
  161. package/dist/knowledge/guard-submission-prompt.js +1 -1
  162. package/dist/knowledge/guard-templates.d.ts +1 -1
  163. package/dist/knowledge/guard-templates.js +1 -1
  164. package/dist/knowledge/guard-translation.js +1 -1
  165. package/dist/knowledge/index.d.ts +1 -1
  166. package/dist/knowledge/index.js +1 -1
  167. package/dist/knowledge/industry-generalizer.d.ts +6 -1
  168. package/dist/knowledge/industry-generalizer.js +1 -1
  169. package/dist/knowledge/industry-registry.js +1 -1
  170. package/dist/knowledge/jsonrpc-enum.d.ts +38 -0
  171. package/dist/knowledge/jsonrpc-enum.js +1 -1
  172. package/dist/knowledge/machine-topology.js +1 -1
  173. package/dist/knowledge/machine-translation.js +1 -1
  174. package/dist/knowledge/object-dependency.d.ts +31 -0
  175. package/dist/knowledge/object-dependency.js +1 -0
  176. package/dist/knowledge/onchain-constants.d.ts +2 -0
  177. package/dist/knowledge/onchain-constants.js +1 -1
  178. package/dist/knowledge/param-schema.d.ts +23 -0
  179. package/dist/knowledge/param-schema.js +1 -1
  180. package/dist/knowledge/param-tiers.js +1 -1
  181. package/dist/knowledge/passport-ledger.js +1 -1
  182. package/dist/knowledge/path-oracle/coverage.d.ts +16 -0
  183. package/dist/knowledge/path-oracle/coverage.js +1 -0
  184. package/dist/knowledge/path-oracle/index.d.ts +5 -0
  185. package/dist/knowledge/path-oracle/index.js +1 -0
  186. package/dist/knowledge/path-oracle/products/food-delivery.d.ts +2 -0
  187. package/dist/knowledge/path-oracle/products/food-delivery.js +1 -0
  188. package/dist/knowledge/path-oracle/schema.d.ts +188 -0
  189. package/dist/knowledge/path-oracle/schema.js +1 -0
  190. package/dist/knowledge/pattern-resolutions.d.ts +2 -0
  191. package/dist/knowledge/pattern-resolutions.js +1 -1
  192. package/dist/knowledge/progress-ledger.js +1 -1
  193. package/dist/knowledge/progress-risk.js +1 -1
  194. package/dist/knowledge/projection.spec.js +1 -1
  195. package/dist/knowledge/protocol-facts.js +1 -1
  196. package/dist/knowledge/requirement-families.d.ts +13 -0
  197. package/dist/knowledge/requirement-families.js +1 -0
  198. package/dist/knowledge/reward-ledger.js +1 -1
  199. package/dist/knowledge/scenario-modes.d.ts +1 -0
  200. package/dist/knowledge/scenario-modes.js +1 -1
  201. package/dist/knowledge/semantic-ir.d.ts +4 -0
  202. package/dist/knowledge/semantic-ir.js +1 -1
  203. package/dist/knowledge/service-ledger.d.ts +1 -1
  204. package/dist/knowledge/service-ledger.js +1 -1
  205. package/dist/knowledge/sku-name-gate.d.ts +17 -0
  206. package/dist/knowledge/sku-name-gate.js +1 -0
  207. package/dist/knowledge/supply-chain.d.ts +9 -0
  208. package/dist/knowledge/supply-chain.js +1 -1
  209. package/dist/knowledge/template-loader.d.ts +14 -6
  210. package/dist/knowledge/template-loader.js +1 -1
  211. package/dist/knowledge/template-nav.d.ts +3 -1
  212. package/dist/knowledge/template-nav.js +1 -1
  213. package/dist/knowledge/template-prose.d.ts +1 -1
  214. package/dist/knowledge/template-registry.js +1 -1
  215. package/dist/knowledge/template-scanner.d.ts +62 -0
  216. package/dist/knowledge/template-scanner.js +1 -1
  217. package/dist/knowledge/template-test-profiles.js +1 -1
  218. package/dist/knowledge/tools-reference.js +1 -1
  219. package/dist/knowledge/workflow-guidance.d.ts +5 -0
  220. package/dist/knowledge/workflow-guidance.js +1 -1
  221. package/dist/monitor/MonitorLoop.js +1 -1
  222. package/dist/participation/customer-interest.d.ts +4 -0
  223. package/dist/participation/customer-interest.js +1 -1
  224. package/dist/participation/node-action-advisor.d.ts +4 -0
  225. package/dist/participation/node-action-advisor.js +1 -1
  226. package/dist/participation/radar-core.js +1 -1
  227. package/dist/participation/time-window.d.ts +11 -0
  228. package/dist/participation/time-window.js +1 -1
  229. package/dist/persona/address-format.d.ts +0 -1
  230. package/dist/persona/address-format.js +1 -1
  231. package/dist/persona/bridge.js +1 -1
  232. package/dist/persona/index.d.ts +0 -2
  233. package/dist/persona/index.js +1 -1
  234. package/dist/persona/model.js +1 -1
  235. package/dist/persona/persona-audit.spec.js +1 -1
  236. package/dist/persona/types.d.ts +6 -0
  237. package/dist/playbooks/service-build/business-puzzle.js +1 -1
  238. package/dist/playbooks/service-build/game-theory.d.ts +2 -2
  239. package/dist/playbooks/service-build/intent-analyzer.js +1 -1
  240. package/dist/playbooks/service-build/machine-panorama.js +1 -1
  241. package/dist/playbooks/service-build/merchant-guide.d.ts +50 -23
  242. package/dist/playbooks/service-build/merchant-guide.js +1 -1
  243. package/dist/playbooks/service-build/migration-planner.d.ts +2 -0
  244. package/dist/playbooks/service-build/migration-planner.js +1 -1
  245. package/dist/playbooks/service-build/mode-actions.js +1 -1
  246. package/dist/playbooks/service-build/object-panorama.d.ts +8 -0
  247. package/dist/playbooks/service-build/object-panorama.js +1 -1
  248. package/dist/playbooks/service-build/participation-radar.js +1 -1
  249. package/dist/playbooks/service-build/relationship-profile.js +1 -1
  250. package/dist/playbooks/service-build/reverse-mapping.d.ts +6 -0
  251. package/dist/playbooks/service-build/reverse-mapping.js +1 -1
  252. package/dist/playbooks/service-build/service-panorama.d.ts +1 -0
  253. package/dist/playbooks/service-build/service-panorama.js +1 -1
  254. package/dist/playbooks/service-build/service-quote.js +1 -1
  255. package/dist/playbooks/service-build/service-quote.spec.js +1 -1
  256. package/dist/playbooks/service-build/workflow-design-assessment.d.ts +10 -1
  257. package/dist/playbooks/service-build/workflow-design-assessment.js +1 -1
  258. package/dist/review/index.js +1 -1
  259. package/dist/review/repository.js +1 -1
  260. package/dist/safety/confirm-gate.js +1 -1
  261. package/dist/schema/benchmark-migration/index.d.ts +104 -0
  262. package/dist/schema/benchmark-migration/index.js +1 -1
  263. package/dist/schema/call/allocation.d.ts +15 -6
  264. package/dist/schema/call/allocation.js +1 -1
  265. package/dist/schema/call/base.d.ts +256 -0
  266. package/dist/schema/call/base.js +1 -1
  267. package/dist/schema/call/bridge.d.ts +32 -6
  268. package/dist/schema/call/demand.d.ts +15 -6
  269. package/dist/schema/call/demand.js +1 -1
  270. package/dist/schema/call/guard.d.ts +8 -8
  271. package/dist/schema/call/guard.js +1 -1
  272. package/dist/schema/call/handler.d.ts +3 -0
  273. package/dist/schema/call/handler.js +1 -1
  274. package/dist/schema/call/machine.d.ts +32 -8
  275. package/dist/schema/call/machine.js +1 -1
  276. package/dist/schema/call/order.d.ts +26 -8
  277. package/dist/schema/call/order.js +1 -1
  278. package/dist/schema/call/payment.d.ts +20 -8
  279. package/dist/schema/call/payment.js +1 -1
  280. package/dist/schema/call/permission-handler.js +1 -1
  281. package/dist/schema/call/permission.d.ts +330 -114
  282. package/dist/schema/call/permission.js +1 -1
  283. package/dist/schema/call/personal.d.ts +10 -4
  284. package/dist/schema/call/personal.js +1 -1
  285. package/dist/schema/call/progress.d.ts +16 -4
  286. package/dist/schema/call/proof.js +1 -1
  287. package/dist/schema/call/reward.d.ts +10 -4
  288. package/dist/schema/call/reward.js +1 -1
  289. package/dist/schema/call/semantic.d.ts +1 -0
  290. package/dist/schema/call/semantic.js +1 -1
  291. package/dist/schema/call/service.d.ts +143 -45
  292. package/dist/schema/call/service.js +1 -1
  293. package/dist/schema/call/treasury.d.ts +15 -6
  294. package/dist/schema/call/treasury.js +1 -1
  295. package/dist/schema/common/index.js +1 -1
  296. package/dist/schema/config/index.d.ts +61 -0
  297. package/dist/schema/config/index.js +1 -1
  298. package/dist/schema/envelope-unify.d.ts +4 -0
  299. package/dist/schema/envelope-unify.js +1 -0
  300. package/dist/schema/evaluation/index.d.ts +216 -19
  301. package/dist/schema/evaluation/index.js +1 -1
  302. package/dist/schema/goal/index.d.ts +47 -0
  303. package/dist/schema/goal/planning.d.ts +115 -1
  304. package/dist/schema/goal/planning.js +1 -1
  305. package/dist/schema/industry-pack/index.d.ts +137 -6
  306. package/dist/schema/industry-pack/index.js +1 -1
  307. package/dist/schema/industry-pack/modes.d.ts +6 -6
  308. package/dist/schema/keeper/index.d.ts +26 -0
  309. package/dist/schema/local/index.d.ts +137 -0
  310. package/dist/schema/local/index.js +1 -1
  311. package/dist/schema/local/wip.d.ts +6 -0
  312. package/dist/schema/local/wip.js +1 -1
  313. package/dist/schema/messenger/index.d.ts +26 -0
  314. package/dist/schema/operations.d.ts +345 -84
  315. package/dist/schema/operations.js +1 -1
  316. package/dist/schema/persona/index.d.ts +2907 -640
  317. package/dist/schema/persona/index.js +1 -1
  318. package/dist/schema/query/bi.d.ts +145 -4
  319. package/dist/schema/query/bi.js +1 -1
  320. package/dist/schema/query/index.d.ts +266 -73
  321. package/dist/schema/query/index.js +1 -1
  322. package/dist/schema/schema-query/index.d.ts +1 -1
  323. package/dist/schema/schema-query/index.js +1 -1
  324. package/dist/schema/schema-version.js +1 -1
  325. package/dist/schema/utils/permission-machine-check.d.ts +2 -0
  326. package/dist/schema/utils/permission-machine-check.js +1 -1
  327. package/dist/schema/watch/index.d.ts +16 -0
  328. package/dist/schema/watch/index.js +1 -1
  329. package/dist/schema/workflow/index.d.ts +2 -2
  330. package/dist/schema/workflow/index.js +1 -1
  331. package/dist/schema-query-impl/index.d.ts +1 -1
  332. package/dist/schema-query-impl/index.js +1 -1
  333. package/dist/schemas/account_operation.output.json +94 -0
  334. package/dist/schemas/benchmark_migration_operation.output.json +338 -9
  335. package/dist/schemas/benchmark_migration_operation.schema.json +27 -2
  336. package/dist/schemas/bridge_operation.output.json +94 -0
  337. package/dist/schemas/config_operation.output.json +352 -0
  338. package/dist/schemas/config_operation.schema.json +20 -2
  339. package/dist/schemas/evaluation_operation.output.json +570 -4
  340. package/dist/schemas/evaluation_operation.schema.json +194 -3
  341. package/dist/schemas/goal_operation.schema.json +183 -0
  342. package/dist/schemas/index.json +1 -1
  343. package/dist/schemas/industry_pack_operation.output.json +621 -0
  344. package/dist/schemas/industry_pack_operation.schema.json +20 -2
  345. package/dist/schemas/keeper_operation.output.json +94 -0
  346. package/dist/schemas/local_cache_operation.output.json +94 -0
  347. package/dist/schemas/local_history_operation.output.json +94 -0
  348. package/dist/schemas/local_info_operation.output.json +94 -0
  349. package/dist/schemas/local_mark_operation.output.json +94 -0
  350. package/dist/schemas/messenger_operation.output.json +94 -0
  351. package/dist/schemas/monitor_events.output.json +94 -0
  352. package/dist/schemas/monitor_subscription.output.json +94 -0
  353. package/dist/schemas/onchain_events.output.json +94 -0
  354. package/dist/schemas/onchain_operations.output.json +313 -1
  355. package/dist/schemas/onchain_operations.schema.json +1265 -671
  356. package/dist/schemas/onchain_operations_allocation.schema.json +30 -15
  357. package/dist/schemas/onchain_operations_arbitration.schema.json +9 -2
  358. package/dist/schemas/onchain_operations_contact.schema.json +8 -1
  359. package/dist/schemas/onchain_operations_demand.schema.json +29 -14
  360. package/dist/schemas/onchain_operations_gen_passport.schema.json +8 -1
  361. package/dist/schemas/onchain_operations_guard.schema.json +290 -105
  362. package/dist/schemas/onchain_operations_machine.schema.json +49 -34
  363. package/dist/schemas/onchain_operations_order.schema.json +63 -40
  364. package/dist/schemas/onchain_operations_payment.schema.json +26 -11
  365. package/dist/schemas/onchain_operations_permission.schema.json +362 -235
  366. package/dist/schemas/onchain_operations_personal.schema.json +27 -15
  367. package/dist/schemas/onchain_operations_progress.schema.json +45 -30
  368. package/dist/schemas/onchain_operations_proof.schema.json +9 -2
  369. package/dist/schemas/onchain_operations_repository.schema.json +8 -1
  370. package/dist/schemas/onchain_operations_reward.schema.json +32 -17
  371. package/dist/schemas/onchain_operations_service.schema.json +232 -125
  372. package/dist/schemas/onchain_operations_treasury.schema.json +32 -17
  373. package/dist/schemas/onchain_table_data.output.json +258 -6
  374. package/dist/schemas/onchain_table_data.schema.json +92 -52
  375. package/dist/schemas/persona_operation.output.json +7752 -0
  376. package/dist/schemas/persona_operation.schema.json +1232 -4
  377. package/dist/schemas/query_toolkit.output.json +756 -116
  378. package/dist/schemas/query_toolkit.schema.json +138 -7
  379. package/dist/schemas/schema_query.schema.json +1 -1
  380. package/dist/schemas/watch_operation.output.json +83 -0
  381. package/dist/schemas/wip_file.output.json +8 -0
  382. package/dist/schemas/workflow_operation.schema.json +2 -2
  383. package/dist/tools/handlers/benchmark-migration.d.ts +20 -3
  384. package/dist/tools/handlers/benchmark-migration.js +1 -1
  385. package/dist/tools/handlers/config.js +1 -1
  386. package/dist/tools/handlers/evaluation.js +1 -1
  387. package/dist/tools/handlers/evaluation.spec.js +1 -1
  388. package/dist/tools/handlers/industry-pack.js +1 -1
  389. package/dist/tools/handlers/onchain.d.ts +30 -0
  390. package/dist/tools/handlers/onchain.js +1 -1
  391. package/dist/tools/handlers/persona.js +1 -1
  392. package/dist/tools/handlers/query.d.ts +8 -0
  393. package/dist/tools/handlers/query.js +1 -1
  394. package/dist/tools/handlers/winner-derivation.d.ts +20 -0
  395. package/dist/tools/handlers/winner-derivation.js +1 -0
  396. package/dist/tools/handlers/wip-upload.js +1 -1
  397. package/dist/tools/index.d.ts +1 -0
  398. package/dist/tools/index.js +1 -1
  399. package/dist/tools/registry/business.js +1 -1
  400. package/dist/tools/registry/config.js +1 -1
  401. package/dist/tools/registry/evaluation.js +1 -1
  402. package/dist/tools/registry/identity.js +1 -1
  403. package/dist/tools/registry/query.js +1 -1
  404. package/dist/tools/transport-integrity.d.ts +7 -0
  405. package/dist/tools/transport-integrity.js +1 -0
  406. package/dist/tools/upgrade-check.js +1 -1
  407. package/dist/tools/wrap.d.ts +5 -0
  408. package/dist/tools/wrap.js +1 -1
  409. package/package.json +2 -2
  410. package/dist/extensions/business-modules.d.ts +0 -54
  411. package/dist/extensions/business-modules.js +0 -1
  412. package/dist/schemas/guard-templates.json +0 -379
@@ -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'));}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\x20with\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+\x20fund-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\x20or\x20merchant\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,'buildTimeMs':Date['now']()}),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),a0=W==='machine'||W==='machine_forward'?'machine_forward_guard':W==='reward'?'reward_claim':W==='repository'?'repository_write_guard':W==='arbitration'?'arbitration_usage_guard':undefined;if(Z!==null){const a5=GUARD_TEMPLATES['find'](a6=>a6['id']===Z[0x0])?.['scene_id'];a5!==undefined&&(a0===undefined||a5===a0||a5==='service_order_allocators_guard'&&W!=='reward')&&(Y=a5);}Y===undefined&&W!=='reward'&&/\ballocators?\b|claimed_by|guard_identifier|order_allocators/i['test'](U)&&(Y='service_order_allocators_guard');if(Y===undefined){if(a0!==undefined)Y=a0;else{const a6=D['find'](a7=>a7['re']['test'](T+'\x20'+U));Y=a6?.['scene'];}}if(Y===undefined)return undefined;const a1=getTemplatesByScene(Y);let a2=V!==undefined&&a1['some'](a7=>a7['applicable_industries']['includes'](V))?a1['filter'](a7=>a7['applicable_industries']['includes'](V)):a1;if(/\btime[_-]?lock|\bwindow|\btimeout|\bduration|\bdeadline|\bdays?\b|\bclock|\bdelay/i['test'](T+'\x20'+U)){const a7=a2['filter'](a8=>JSON['stringify'](a8['example_root']??{})['toLowerCase']()['includes']('clock'));if(a7['length']===0x0)return undefined;a2=a7;}if(X['length']>0x0){const a8=Z!==null?a2['find'](aa=>aa['id']===Z[0x0]):undefined,a9=a2['filter'](aa=>{const ab=[];if(aa['example_root']!==undefined){const ac=JSON['stringify'](aa['example_root']);for(const ad of ac['matchAll'](/"query":"([^"]+)"/g))ab['push'](ad[0x1]);if(ac['includes']('\x22type\x22:\x22query_progress_history_time\x22'))ab['push']('progress.history.time');if(ac['includes']('\x22type\x22:\x22query_progress_history_find\x22'))ab['push']('progress.history.find');}return ab['some'](ae=>X['some'](af=>ae===af||ae['startsWith'](af)||af['startsWith'](ae)));});if(a8!==undefined&&!a9['includes'](a8))a9['push'](a8);if(a9['length']===0x0)return undefined;a2=a9;}const a3=W==='machine_forward'?'machine':W,a4=F['find'](aa=>aa['host']===a3&&aa['re']['test'](T+'\x20'+U)&&a2['some'](ab=>ab['id']===aa['tpl']));a4!==undefined&&(a2=[...a2]['sort']((aa,ab)=>(aa['id']===a4['tpl']?0x0:0x1)-(ab['id']===a4['tpl']?0x0:0x1)));if(Y==='service_order_allocators_guard'){const aa=E['find'](ab=>ab['re']['test'](T+'\x20'+U));aa!==undefined&&(a2=[...a2]['sort']((ab,ac)=>(ab['id']===aa['tpl']?0x0:0x1)-(ac['id']===aa['tpl']?0x0:0x1)));}return a2['slice'](0x0,0x3)['map'](ab=>({'template_id':ab['id'],'name':ab['name'],'parameters':ab['parameters']['map'](ac=>({'name':ac['name'],'required':ac['required'],...ac['default']!==undefined?{'default':ac['default']}:{},'description':ac['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'](a4=>(a4['from']??[])['map'](a5=>typeof a5==='string'?undefined:a5['guard_key'])['filter'](a5=>typeof a5==='string'))),X=new Map((j?.['allocator']['rows']??[])['filter'](a4=>typeof a4['guard_key']==='string')['map'](a4=>[a4['guard_key'],a4])),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'),a1=T['key']['toLowerCase'](),a2=(T['purpose']??'')['toLowerCase'](),a3=/recover|award/['test'](a1)||!/refund/['test'](a1)&&/recover|award/['test'](a2)?'POLARITY\x20LEG\x20REQUIRED\x20(the\x20sketch\x20above\x20omits\x20it):\x20this\x20rail\x20pays\x20AFTER\x20a\x20compensation/payout\x20has\x20already\x20consumed\x20the\x20order\x27s\x20claim\x20slot\x20—\x20resolve\x20with\x20order.claimed_by\x20some\x20==\x20true\x20(tpl_allocator_node_gate_recover\x20family).\x20A\x20guard\x20resolved\x20from\x20the\x20sketch\x20alone\x20would\x20pay\x20the\x20principal\x20without\x20a\x20ruling\x20and\x20double-pay\x20against\x20the\x20refund\x20rail\x20(RAIL\x20polarity,\x204R-02).':/refund/['test'](a1)||!/recover|award/['test'](a1)&&/refund/['test'](a2)?'POLARITY\x20LEG\x20REQUIRED\x20(the\x20sketch\x20above\x20omits\x20it):\x20this\x20rail\x20may\x20only\x20fire\x20while\x20NO\x20compensation\x20has\x20been\x20claimed\x20on\x20the\x20order\x20—\x20resolve\x20with\x20order.claimed_by\x20none.\x20If\x20the\x20machine\x20also\x20carries\x20a\x20recover/awarded\x20rail,\x20the\x20two\x20are\x20polarity\x20twins\x20and\x20MUST\x20NOT\x20share\x20one\x20resolved\x20guard\x20(the\x20compile-level\x20RAIL_POLARITY_COLLISION\x20gate\x20hard-blocks\x20the\x20collision;\x20S14-E\x20RAIL-03\x20keeps\x20the\x20twin\x20case\x20pending\x20for\x20judgment).':undefined;return{'key':T['key'],'template_id':T['template_id'],'host':T['host'],'purpose':T['purpose'],...U?.['logic_summary']?{'logic_summary':U['logic_summary']}:{},...a3?{'logic_summary_note':a3}:{},...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,'mandatory_disclosures':['PII\x20discipline\x20(rex5\x20B-57):\x20never\x20write\x20personal\x20data\x20(phone,\x20email,\x20exact\x20unit\x20address)\x20into\x20public\x20on-chain\x20fields\x20—\x20Contact\x20description/location/IM\x20entries,\x20repository\x20rows,\x20progress\x20messages\x20and\x20WIP\x20text\x20are\x20all\x20public.\x20Exchange\x20PII\x20over\x20the\x20encrypted\x20Messenger\x20and\x20keep\x20only\x20WTS\x20proofs\x20on\x20chain;\x20the\x20local\x20harness\x20store\x20is\x20non-private\x20too\x20(cache.db\x20holds\x20messenger\x20plaintext\x20and\x20LocalInfo\x20entries\x20unencrypted\x20on\x20disk,\x20readable\x20by\x20any\x20session\x20sharing\x20the\x20keystore).','Trust-claim\x20prose\x20is\x20not\x20a\x20chain\x20anchor\x20(rex5\x20T-31):\x20any\x20compensation-fund\x20or\x20protection\x20figure\x20quoted\x20in\x20the\x20service\x20description\x20is\x20free\x20text\x20—\x20awards\x20shrink\x20the\x20live\x20fund\x20in\x20place\x20(the\x20quoted\x20number\x20silently\x20goes\x20stale)\x20and\x20the\x20per-order\x20covered\x20ceiling\x20is\x20fund/3\x20(MAX_INDEMNITY_MULTIPLE),\x20not\x20the\x20headline.\x20Keep\x20quoted\x20numbers\x20synced\x20to\x20the\x20live\x20fund\x20balance\x20before\x20publishing\x20and\x20after\x20every\x20award.'],...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{GUARD_AFTER_SERVICE_DRAFT,relationDirection}from'../../knowledge/object-dependency.js';import{collectLateMarks}from'../../composition/plan.js';import{BUILTIN_TEMPLATES_VERSION}from'../../knowledge/builtin-templates.js';import{templateCatalogDigest}from'../../knowledge/template-loader.js';import{checkGameTheoryConstraints}from'./game-theory.js';import{assessWorkflowDesign}from'./workflow-design-assessment.js';import{getCapability,recommendCapabilities,checkCapabilityConstraints,capabilityIntentEvidence}from'../../extensions/capability.js';import{requirementCoverage}from'../../knowledge/requirement-families.js';import{recipientDesignGuidance}from'../../knowledge/recipient-constraint.js';import{getTemplate,getTemplatesByIndustry}from'../../knowledge/template-loader.js';import{resolveUserInputQuestions}from'../../knowledge/param-schema.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_rail_node_gated'),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'),c['push']('ALLOCATOR\x20GUARD\x20DESIGN\x20—\x20hand-built\x20rails\x20(sahr\x20lesson):\x20BEFORE\x20writing\x20the\x20settlement\x20Guard,\x20map\x20the\x20host\x20object\x27s\x20RICH\x20STATES:\x20enumerate\x20the\x20Machine\x27s\x20terminal\x20nodes\x20(settlement\x20vs\x20refund\x20polarity),\x20the\x20mid-flight\x20states\x20a\x20claim\x20or\x20dispute\x20opens,\x20and\x20which\x20business\x20event\x20each\x20state\x20transition\x20represents;\x20the\x20allocator\x20gate\x20must\x20sit\x20at\x20exactly\x20ONE\x20mapped\x20transition\x20(e.g.\x20\x27order\x20reached\x20settle\x20terminal\x20AND\x20business\x20obligations\x20verified\x27),\x20never\x20at\x20\x27any\x20time\x20after\x20start\x27.\x20Then\x20bind\x20WHO\x20may\x20trigger\x20alloc_by_guard:\x20the\x20gate\x20carries\x20a\x20caller-identity\x20leg\x20—\x20context(Signer)\x20compared\x20against\x20a\x20table\x20entry,\x20a\x20permission.admin\x20/\x20order.owner\x20read,\x20or\x20the\x20named-operator\x20roster\x20query.\x20order.claimed_by\x20is\x20ORDER\x20STATE,\x20not\x20a\x20caller\x20binding\x20—\x20a\x20gate\x20whose\x20legs\x20read\x20only\x20order/progress/clock\x20state\x20is\x20callable\x20by\x20ANY\x20address,\x20and\x20a\x20bystander\x20can\x20accelerate\x20someone\x20else\x27s\x20payout\x20(sahr,\x20live-proven)'),c['push']('ALLOCATOR\x20GUARD\x20REVIEW\x20—\x20pre-publish,\x20semantic\x20alignment:\x20SAFETY\x20—\x20a\x20settlement\x20track\x20with\x20refund\x20exposure\x20carries\x20the\x20dispute\x20freeze\x20leg\x20logic_not[order.dispute.open]\x20(query\x201576)\x20so\x20a\x20filed\x20dispute\x20freezes\x20new\x20settlements;\x20resolved-awaiting-stamp\x20flows\x20drive\x20the\x20stamp\x20with\x20order.dispute.unstamped\x20(query\x201578).\x20EFFECTIVENESS\x20—\x20read\x20every\x20gate\x20leg\x20back\x20against\x20the\x20business\x20description\x20(who\x20SHOULD\x20trigger,\x20at\x20which\x20business\x20milestone,\x20with\x20what\x20evidence):\x20structural\x20lint\x20passing\x20is\x20NOT\x20semantic\x20alignment.\x20Run\x20the\x20template\x20scan\x20dry-run\x20before\x20publish\x20—\x20the\x20knowledge\x20face\x20discloses\x20identity-less\x20allocator\x20gates\x20as\x20RAIL_NO_CALLER_IDENTITY\x20(info,\x20never\x20blocking);\x20treat\x20the\x20disclosure\x20as\x20a\x20design-review\x20flag\x20and\x20resolve\x20it\x20either\x20with\x20a\x20caller-identity\x20leg\x20or\x20a\x20DOCUMENTED\x20open-trigger\x20rationale\x20(scene\x20verifies\x20identity\x20upstream\x20/\x20intentionally\x20open\x20venue),\x20never\x20by\x20silence'),c['push']('ALLOCATOR\x20RULING\x20DIRECTION\x20—\x20the\x20rich-state\x20matrix\x20closes\x20BOTH\x20ruling\x20outcomes:\x20an\x20award\x20exit\x20on\x20the\x20ARBITRATION\x20indemnity\x20track\x20(a\x20tpl_forward_arb_ruling_won\x20claimed_by==true\x20leg\x20is\x20legal\x20arb-side\x20state,\x20decision\x2011)\x20bound\x20ONLY\x20to\x20a\x20buyer-side\x20identity\x20(order.owner/agent)\x20is\x20unreachable\x20after\x20a\x20MERCHANT-favored\x20ruling\x20or\x20dismissal\x20—\x20nobody\x20but\x20the\x20buyer\x20can\x20open\x20the\x20exit\x20and\x20the\x20escrow\x20principal\x20strands\x20(w3k7\x20m2:\x201.25\x20WOW\x20held\x20on\x20a\x20fully-guarded\x20order;\x20the\x20protocol\x20is\x20direction-blind,\x20the\x20order\x20object\x20exposes\x20NO\x20winner\x20accessor,\x20so\x20the\x20guard\x20itself\x20cannot\x20branch\x20on\x20who\x20won).\x20Pair\x20the\x20buyer-side\x20award\x20exit\x20with\x20a\x20merchant-side\x20exit\x20(a\x20terminal-node-gated\x20recovery\x20sweep\x20—\x20the\x20canonical\x20recover\x20rail),\x20or\x20document\x20that\x20the\x20keeper\x20dual-payout\x20protocol\x20is\x20the\x20intended\x20sole\x20post-ruling\x20exit.\x20Overlap\x20between\x20an\x20award\x20and\x20a\x20fund-rail\x20payout\x20is\x20LEGAL\x20under\x20decision\x2011\x20and\x20is\x20disclosed\x20at\x20the\x20MCP\x20dual-payout\x20confirmation\x20gate\x20—\x20resolve\x20reachability\x20before\x20publish,\x20never\x20by\x20silence.\x20INVERTED\x20FUNDING\x20award-recipient\x20face\x20(W5-01\x20d;\x20the\x20order-side\x20award\x20payout\x20hard-binds\x20to\x20the\x20order\x20owner\x20on\x20both\x20compensate\x20and\x20conclude\x20paths):\x20a\x20ruling\x20pays\x20ONLY\x20the\x20compensation\x20indemnity,\x20never\x20the\x20escrow\x20principal\x20—\x20and\x20on\x20an\x20INVERTED-FUNDING\x20build\x20(bounty/contest:\x20the\x20SPONSOR\x20is\x20the\x20order_payer,\x20so\x20order.owner\x20IS\x20the\x20funder)\x20a\x20hunter/designer-side\x20win\x20pays\x20THE\x20SPONSOR,\x20not\x20the\x20winning\x20party;\x20state\x20both\x20directions\x20(award\x20recipient\x20+\x20principal\x20exit\x20via\x20the\x20recover\x20rail\x27s\x20note)\x20in\x20the\x20storefront/quote\x20before\x20publish')),(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\x20with\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\x20activation\x20is\x20ATOMIC\x20in\x20the\x20creation\x20plan\x20—\x20the\x20chain\x20hardcodes\x20every\x20new\x20Arbitration\x20to\x20PAUSED\x20at\x20construction,\x20and\x20the\x20plan\x27s\x20arbitration\x20create\x20payload\x20carries\x20pause:false,\x20which\x20the\x20executor\x20composes\x20as\x20the\x20unpause\x20write\x20in\x20the\x20SAME\x20transaction\x20(the\x20creator\x20is\x20the\x20new\x20Permission\x27s\x20admin,\x20so\x20the\x20356\x20assert\x20passes).\x20Verify\x20the\x20paused\x20flag\x20reads\x20false\x20after\x20materialization\x20(a\x20paused\x20venue\x20aborts\x20every\x20dispute\x20filing).\x20Keep\x20Arbitration.permission\x20distinct\x20from\x20Service.permission\x20on-chain\x20(E_ARBITRATION_PERMISSION_CONFLICT=33)'),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=![],c=![]){const d=[];return!b&&(a['adoptedModules']['includes']('refund_guarantee')||a['nodes']['some'](e=>e['id']==='arbitration'))&&(!c&&d['push']({'order':d['length']+0x1,'id':'compensation_fund_topup','title':'Top\x20up\x20the\x20compensation\x20fund','when':'After\x20the\x20Service\x20PUBLISHES\x20successfully\x20(post-publish,\x20before\x20the\x20store\x20goes\x20live\x20to\x20buyers)','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)'}),d['push']({'order':d['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+\x20fund-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'](e=>e['id']==='arbitration')&&(d['push']({'order':d['length']+0x1,'id':'arbitration_unpause','title':'Verify\x20the\x20Arbitration\x20is\x20ACTIVE\x20(activation\x20rode\x20the\x20create)','when':'Immediately\x20after\x20materialization\x20—\x20before\x20the\x20store\x20goes\x20live\x20to\x20buyers','action':'The\x20creation\x20plan\x27s\x20arbitration\x20create\x20payload\x20carries\x20pause:false\x20(the\x20chain\x20hardcodes\x20new\x20Arbitrations\x20to\x20paused;\x20the\x20executor\x20composes\x20the\x20unpause\x20in\x20the\x20same\x20transaction)\x20—\x20VERIFY\x20the\x20paused\x20flag\x20reads\x20false\x20via\x20query_toolkit;\x20only\x20an\x20already-paused\x20leftover\x20venue\x20(built\x20before\x20this\x20payload\x20field\x20existed)\x20needs\x20a\x20manual\x20unpause.\x20Keep\x20its\x20Permission\x20distinct\x20from\x20the\x20Service\x20Permission\x20(E_ARBITRATION_PERMISSION_CONFLICT=33)','tool_hint':'query_toolkit\x20(arbitration\x20paused\x20flag);\x20manual\x20unpause\x20via\x20onchain_operations\x20(arbitration\x20pause:false)\x20ONLY\x20for\x20a\x20legacy\x20paused\x20venue','failure_if_skipped':'a\x20paused\x20Arbitration\x20aborts\x20every\x20dispute\x20filing\x20(testnet\x20lesson\x20R-5)'}),d['push']({'order':d['length']+0x1,'id':'arbitration_permission_write','title':'Grant\x20the\x20operator\x20account\x20its\x20venue-management\x20permissions','when':'After\x20the\x20Arbitration\x20object\x20is\x20created,\x20BEFORE\x20any\x20venue-management\x20call\x20(description/guard/fee/pause\x20edits)\x20from\x20the\x20operator\x20account','action':'Write\x20the\x20operator\x20permission\x20row:\x20onchain_operations\x20operation_type=\x27permission\x27,\x20data={object:\x27<arbitration_permission_object>\x27,\x20table:{op:\x27add\x20perm\x20by\x20entity\x27,\x20entity:\x27<operator_account>\x27,\x20index:[350,351,354,356,357,359]}}\x20—\x20350\x20file\x20new\x20cases,\x20351\x20description,\x20354\x20voting_guard\x20management,\x20356\x20pause/resume,\x20357\x20fee,\x20359\x20ruling.\x20The\x20arbitration\x20Permission\x20table\x20starts\x20EMPTY\x20with\x20only\x20the\x20creator\x20seeded\x20as\x20admin,\x20so\x20without\x20this\x20row\x20every\x20operator\x20call\x20aborts\x20on\x20the\x20permission\x20assert.\x20entity\x20must\x20be\x20a\x20FULL\x2066-char\x200x\x20address\x20or\x20a\x20local\x20mark\x20name\x20—\x20a\x20truncated\x20address\x20normalizes\x20to\x20a\x20DIFFERENT\x20on-chain\x20address\x20and\x20grants\x20the\x20wrong\x20row\x20silently','tool_hint':'onchain_operations\x20(permission\x20add\x20perm\x20by\x20entity,\x20indexes\x20350/351/354/356/357/359)','failure_if_skipped':'the\x20operator\x20account\x20holds\x20NO\x20rows\x20in\x20the\x20arbitration\x20Permission\x20table\x20—\x20every\x20venue-management\x20call\x20from\x20it\x20aborts\x20on\x20the\x20permission\x20assert\x20(permission\x20350-359\x20failures)'}),d['push']({'order':d['length']+0x1,'id':'arbitration_arbitrator_grant','title':'Grant\x20the\x20arbitrator\x20account\x20its\x20case-lifecycle\x20permissions','when':'After\x20arbitration_permission_write,\x20BEFORE\x20the\x20first\x20dispute\x20reaches\x20voting','action':'Write\x20the\x20arbitrator\x20permission\x20row:\x20same\x20permission-object\x20call\x20shape\x20with\x20entity:\x27<arbitrator_account>\x27\x20and\x20index:[358,359,360,361,362,363,364]\x20—\x20358\x20vote,\x20359\x20ruling,\x20360\x20feedback,\x20361\x20confirm,\x20362\x20voting-deadline\x20change,\x20363\x20reset,\x20364\x20receive.\x20Note:\x20the\x20disputing\x20CUSTOMER\x20must\x20hold\x20358\x20for\x20their\x20vote\x20to\x20count\x20(a\x20plain\x20vote\x20with\x20an\x20empty\x20voting_guard\x20still\x20asserts\x20358\x20—\x20ungranted,\x20voting\x20collapses\x20to\x20admin-only,\x20E-13);\x20that\x20per-dispute\x20customer\x20grant\x20is\x20issued\x20at\x20filing\x20time,\x20NOT\x20in\x20this\x20step.\x20Full\x2066-char\x20address\x20or\x20mark\x20name\x20only','tool_hint':'onchain_operations\x20(permission\x20add\x20perm\x20by\x20entity,\x20indexes\x20358-364)','failure_if_skipped':'358-364\x20stay\x20creator-admin-only\x20—\x20the\x20named\x20arbitrator\x20cannot\x20vote/rule/confirm,\x20and\x20the\x20customer\x27s\x20vote\x20collapses\x20to\x20admin-only\x20(E-13),\x20dead-locking\x20the\x20first\x20dispute'}),d['push']({'order':d['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'](f=>f['relation']==='has_order_allocators')&&d['push']({'order':d['length']+0x1,'id':'settlement_alloc_by_guard','title':'Fire\x20settlement\x20via\x20alloc_by_guard\x20(keeper\x20or\x20merchant\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)'}),d['push']({'order':d['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'}),d;}function buildCreationPlan(a){const b=[],c=new Map(a['nodes']['map'](j=>[j['id'],j])),f=new Map();for(const j of a['nodes'])f['set'](j['id'],new Set());for(const k of a['edges']){if(!f['has'](k['from'])||!c['has'](k['to']))continue;const l=relationDirection(k['relation'])==='to_depends_on_from',m=l?k['to']:k['from'],o=l?k['from']:k['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 r=GUARD_AFTER_SERVICE_DRAFT,s=a['nodes']['filter'](t=>t['type']===r['provider'])['map'](t=>t['id']);if(s['length']>0x0)for(const t of a['nodes']){if(t['type']!==r['dependent'])continue;const u=f['get'](t['id']);if(u===undefined)continue;for(const v of s)u['add'](v);}}const g=new Map([...f]['map'](([w,x])=>[w,[...x]])),h=[],i=new Map(f);while(i['size']>0x0){const w=[...i['entries']()]['filter'](([,x])=>x['size']===0x0)['map'](([x])=>x);if(w['length']===0x0){h['push'](...i['keys']());break;}w['sort']();for(const x of w){h['push'](x),i['delete'](x);for(const y of i['values']())y['delete'](x);}}return h['forEach']((z,A)=>{const B=c['get'](z),C=B['config']['name'],D=C?.['type']==='string'?C['value']:z,E=D['includes']('/')?D['replaceAll']('/','__'):D,F=z==='arbitration'?'Create\x20'+B['type']+'\x20via\x20onchain_operations\x20WITH\x20pause:false\x20(creation-time\x20activation),\x20then\x20configure.\x20Purpose:\x20'+B['purpose']:'Create\x20'+B['type']+'\x20via\x20onchain_operations,\x20then\x20configure.\x20Purpose:\x20'+B['purpose'];b['push']({'order':A+0x1,'node_id':z,'object_type':B['type'],'suggested_name':E,'depends_on':g['get'](z)??[],'operation_hint':F});}),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 const GAS_PER_ORDER_SMALLEST=0x5b8d80;export const MIN_ECONOMIC_ORDER_SMALLEST=0x2faf080;const GAS_RATIO_WARN_THRESHOLD=0.1,wow=a=>Number((a/0x3b9aca00)['toFixed'](0x6))+'\x20WOW';export function gasEconomicsWarnings(a,b){const c=[],d=(a??[])['map'](j=>Number(j?.['price']))['filter'](j=>Number['isFinite'](j)&&j>0x0);if(d['length']===0x0)return c;const e=Math['min'](...d),f=Number(b),g=Number['isFinite'](f)&&f>0x0?f:0x0,h=g+GAS_PER_ORDER_SMALLEST,i=h/e;if(e<MIN_ECONOMIC_ORDER_SMALLEST)c['push']('GAS\x20ECONOMY\x20(ddmc4\x20B-39\x20/\x20ks7\x20A-10):\x20the\x20cheapest\x20SKU\x20is\x20'+wow(e)+'\x20—\x20below\x20the\x20≈'+wow(MIN_ECONOMIC_ORDER_SMALLEST)+'\x20minimum\x20ECONOMIC\x20per-order\x20price.\x20'+('Measured\x20settlement\x20gas\x20is\x20≈'+wow(GAS_PER_ORDER_SMALLEST)+'\x20per\x20transaction')+(g>0x0?',\x20plus\x20'+wow(g)+'\x20cashback\x20per\x20claim':'')+('\x20—\x20per-order\x20overhead\x20≈'+wow(h)+'\x20('+Math['round'](i*0x64)+'%\x20of\x20this\x20SKU).\x20')+'Micro-priced\x20SKUs\x20lose\x20their\x20entire\x20margin\x20to\x20gas:\x20raise\x20the\x20price,\x20drop\x20the\x20per-claim\x20cashback,\x20or\x20batch\x20settlements.');else i>GAS_RATIO_WARN_THRESHOLD&&c['push']('GAS\x20ECONOMY\x20(ks7\x20A-10):\x20cashback\x20+\x20settlement\x20gas\x20≈'+wow(h)+'\x20per\x20order\x20is\x20'+Math['round'](i*0x64)+'%\x20of\x20the\x20cheapest\x20SKU\x20('+wow(e)+')\x20—\x20above\x20the\x2010%\x20warning\x20line.\x20'+'Trim\x20the\x20per-claim\x20cashback\x20or\x20raise\x20the\x20price.');return c;}export async function handleMerchantGuide(a){const b=a['guide_state']??{'intent_text':''},d=a['guide_confirm']??{},e={'intent_text':(a['intent']??b['intent_text']??'')['trim'](),'confirmed_industry':d['industry']??b['confirmed_industry'],'currency':d['currency']??b['currency'],'deliverables':d['deliverables']??b['deliverables'],'payment_override':d['payment']??b['payment_override'],'trust_override':d['trust']??b['trust_override'],'adopted_module_ids':d['adopted_module_ids']??b['adopted_module_ids'],'guard_resolutions':{...b['guard_resolutions']??{},...d['guard_resolutions']??{}},'review_mode':d['review_mode']??b['review_mode'],'reward_funding':d['reward_funding']??b['reward_funding'],'reward_claim_amount':d['reward_claim_amount']??b['reward_claim_amount'],'after_sales_mode':d['after_sales_mode']??b['after_sales_mode'],'acceptance_mode':d['acceptance_mode']??b['acceptance_mode'],'installment_mode':d['installment_mode']??b['installment_mode'],'affiliate_mode':d['affiliate_mode']??b['affiliate_mode'],'crowdfunding_mode':d['crowdfunding_mode']??b['crowdfunding_mode'],'logistics_mode':d['logistics_mode']??b['logistics_mode'],'supply_chain':d['supply_chain']??b['supply_chain'],'sales':d['sales']??b['sales']};for(const T of Object['keys'](e)){if(e[T]===undefined)delete e[T];}if(e['guard_resolutions']&&Object['keys'](e['guard_resolutions'])['length']===0x0)delete e['guard_resolutions'];if(!e['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 f=await analyzeIntent(e['intent_text'],{'preferredIndustry':e['confirmed_industry'],'currency':e['currency']});if(!e['confirmed_industry'])return{'action':'merchant_guide','current_step':0x2,'step_name':'Industry\x20Matching','guide_state':e,'intent_draft':f['intent'],'industry_options':{'inferred':f['inferredIndustry'],'confidence':f['industryConfidence'],'similar':f['similarIndustries']},'warnings':f['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'+f['similarIndustries']['join'](',\x20')+'\x20—\x20or\x20any\x20other\x20industry\x20id>\x27\x20}')};const g={...f['intent'],'industry':e['confirmed_industry'],'deliverables':e['deliverables']??f['intent']['deliverables'],'payment':{...f['intent']['payment'],...e['payment_override']??{}},'trust':{...f['intent']['trust'],...e['trust_override']??{}}},h=!!e['adopted_module_ids'],i=e['adopted_module_ids']?e['adopted_module_ids']['map'](U=>getCapability(U))['filter'](U=>!!U):recommendCapabilities(e['confirmed_industry'],e['intent_text'],{'maxCapabilities':0x5}),j=a['template_override']??resolveTemplate(e['confirmed_industry'],e['intent_text']);if(!j)throw new Error('No\x20compilable\x20template\x20found\x20for\x20industry\x20\x27'+e['confirmed_industry']+'\x27.\x20'+'Register\x20a\x20template\x20via\x20industry_pack_operation\x20or\x20pass\x20template_override\x20explicitly.');const l=resolveUserInputQuestions(j),m={'currency':e['currency']??g['payment']['currency'],...e['payment_override']?{'payment':e['payment_override']}:{},...e['trust_override']?{'trust':e['trust_override']}:{},...e['deliverables']?{'deliverables':e['deliverables']}:{},...e['adopted_module_ids']?{'adopted_module_ids':e['adopted_module_ids']}:{},...e['review_mode']?{'review_mode':e['review_mode']}:{},...e['reward_funding']!==undefined?{'reward_funding':e['reward_funding']}:{},...e['reward_claim_amount']!==undefined?{'reward_claim_amount':e['reward_claim_amount']}:{},...e['after_sales_mode']?{'after_sales_mode':e['after_sales_mode']}:{},...e['acceptance_mode']?{'acceptance_mode':e['acceptance_mode']}:{},...e['installment_mode']?{'installment_mode':e['installment_mode']}:{},...e['affiliate_mode']?{'affiliate_mode':e['affiliate_mode']}:{},...e['crowdfunding_mode']?{'crowdfunding_mode':e['crowdfunding_mode']}:{},...e['logistics_mode']?{'logistics_mode':e['logistics_mode']}:{},...e['sales']?.['length']?{'sales':e['sales']}:{},...e['fee_overrides']??{}},n={};Object['assign'](n,e['guard_resolutions']??{});const o=compileTemplate(j,m,{'nameBase':a['name_base']??j['id'],'intent':e['intent_text'],'guardResolutions':n,'buildTimeMs':Date['now'](),...e['supply_chain']!==undefined&&e['supply_chain']['length']>0x0?{'supplyChain':e['supply_chain']}:{}}),p=reflux(o['plan']),q=p['plan'],r=p['audit'],s=auditScore(r),t=planBlueprint(q,g,i['map'](U=>U['id'])),u=o['blockers']['map'](U=>({'module':'template','missing_constraints':[U['code']],'fix':U['detail']})),w=derivePlanSatisfiedConstraints(t,g),x={'paymentModel':e['payment_override']?.['model'],'trustArbitration':e['trust_override']?.['arbitration'],'trustRefundPolicy':e['trust_override']?.['refundPolicy'],'proofsOfDelivery':e['deliverables']?.['map'](U=>U['proofOfDelivery']),'allocationCount':e['payment_override']?.['allocation']?.['length']},y=i['map'](U=>{const V=capabilityIntentEvidence(U,e['intent_text'],x);return checkCapabilityConstraints(U,w,{'evidenceMatched':h||V['matched'],'evidence':V});}),z=j['compensation_fund_policy']==='forbidden',A=deriveDeployTimeChecks(t,z),B=derivePostDeploySteps(t,z,q['steps']['some'](U=>U['op']==='configure'&&U['id']==='service_compensation'&&U['method']==='compensation_fund_add')),C=t['edges']['some'](U=>U['relation']==='has_order_allocators')?recipientDesignGuidance()['map'](U=>({'id':U['id'],'move_recipient':U['move_recipient'],'semantics':U['semantics'],'required_constraints':U['required_constraints'],'finding_if_unmet':U['finding_if_unmet']})):undefined,D=r['findings']['filter'](U=>U['level']==='critical'||U['level']==='high')['map'](U=>({'module':'audit','missing_constraints':[U['rule_id']],'fix':U['title']+'\x20—\x20'+(U['mitigation']??U['description'])})),E=[{'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'}],F=[{'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'}],G=[{'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'}],H=(U,V,W,X,Y)=>{let Z;const a0=/tpl_[a-z0-9_]+/['exec'](U+'\x20'+V),a1=X==='machine'||X==='machine_forward'?'machine_forward_guard':X==='reward'?'reward_claim':X==='repository'?'repository_write_guard':X==='arbitration'?'arbitration_usage_guard':undefined;if(a0!==null){const a6=GUARD_TEMPLATES['find'](a7=>a7['id']===a0[0x0])?.['scene_id'];a6!==undefined&&(a1===undefined||a6===a1||a6==='service_order_allocators_guard'&&X!=='reward')&&(Z=a6);}Z===undefined&&X!=='reward'&&!G['some'](a7=>a7['host']===(X==='machine_forward'?'machine':X)&&a7['re']['test'](U))&&/\ballocators?\b|claimed_by|guard_identifier|order_allocators/i['test'](V)&&(Z='service_order_allocators_guard');if(Z===undefined){if(a1!==undefined)Z=a1;else{const a7=E['find'](a8=>a8['re']['test'](U+'\x20'+V));Z=a7?.['scene'];}}if(Z===undefined)return undefined;const a2=getTemplatesByScene(Z);let a3=W!==undefined&&a2['some'](a8=>a8['applicable_industries']['includes'](W))?a2['filter'](a8=>a8['applicable_industries']['includes'](W)):a2;if(/\btime[_-]?lock|\bwindow|\btimeout|\bduration|\bdeadline|\bdays?\b|\bclock|\bdelay/i['test'](U+'\x20'+V)){const a8=a3['filter'](a9=>JSON['stringify'](a9['example_root']??{})['toLowerCase']()['includes']('clock'));if(a8['length']===0x0)return undefined;a3=a8;}if(Y['length']>0x0){const a9=a0!==null?a3['find'](ab=>ab['id']===a0[0x0]):undefined,aa=a3['filter'](ab=>{const ac=[];if(ab['example_root']!==undefined){const ad=JSON['stringify'](ab['example_root']);for(const ae of ad['matchAll'](/"query":"([^"]+)"/g))ac['push'](ae[0x1]);if(ad['includes']('\x22type\x22:\x22query_progress_history_time\x22'))ac['push']('progress.history.time');if(ad['includes']('\x22type\x22:\x22query_progress_history_find\x22'))ac['push']('progress.history.find');}return ac['some'](af=>Y['some'](ag=>af===ag||af['startsWith'](ag)||ag['startsWith'](af)));});if(a9!==undefined&&!aa['includes'](a9))aa['push'](a9);if(aa['length']===0x0)return undefined;a3=aa;}const a4=X==='machine_forward'?'machine':X,a5=G['find'](ab=>ab['host']===a4&&ab['re']['test'](U+'\x20'+V)&&a3['some'](ac=>ac['id']===ab['tpl']));a5!==undefined&&(a3=[...a3]['sort']((ab,ac)=>(ab['id']===a5['tpl']?0x0:0x1)-(ac['id']===a5['tpl']?0x0:0x1)));if(Z==='service_order_allocators_guard'){const ab=F['find'](ac=>ac['re']['test'](U+'\x20'+V));ab!==undefined&&(a3=[...a3]['sort']((ac,ad)=>(ac['id']===ab['tpl']?0x0:0x1)-(ad['id']===ab['tpl']?0x0:0x1)));}return a3['slice'](0x0,0x3)['map'](ac=>({'template_id':ac['id'],'name':ac['name'],'parameters':ac['parameters']['map'](ad=>({'name':ad['name'],'required':ad['required'],...ad['default']!==undefined?{'default':ad['default']}:{},'description':ad['description']}))}));},I=[],J=o['unresolved']['map'](U=>{const V=getGuardDesignPattern(U['template_id']),W=H(U['template_id'],U['purpose'],j?.['industry'],U['host'],V?.['key_queries']??[]),X=new Set((j?.['machine_shape']??[])['flatMap'](a6=>(a6['from']??[])['map'](a7=>typeof a7==='string'?undefined:a7['guard_key'])['filter'](a7=>typeof a7==='string'))),Y=new Map((j?.['allocator']['rows']??[])['filter'](a6=>typeof a6['guard_key']==='string')['map'](a6=>[a6['guard_key'],a6])),Z=Y['get'](U['key']),a0=Z!==undefined&&!X['has'](U['key']),a1=!X['has'](U['key'])&&!Y['has'](U['key'])&&U['policy']===undefined&&U['host']!=='reward'&&!(U['host']==='service'&&U['key']==='buy'),a2=U['host']==='service'&&U['key']==='buy';if(!a1&&!a2)I['push'](U['key']);const a3=U['key']['toLowerCase'](),a4=(U['purpose']??'')['toLowerCase'](),a5=/recover|award/['test'](a3)||!/refund/['test'](a3)&&/recover|award/['test'](a4)?'NODE\x20GATE\x20REQUIRED\x20(the\x20sketch\x20above\x20omits\x20it):\x20this\x20recovery\x20rail\x20is\x20a\x20terminal-node-gated\x20sweep\x20—\x20resolve\x20the\x20gate\x20to\x20fire\x20only\x20when\x20the\x20order\x20has\x20reached\x20the\x20recovery\x20terminal\x20nodes\x20(tpl_allocator_node_gate_recover\x20family\x20carries\x20the\x20node-gate\x20slot\x20set;\x20NEVER\x20slot\x20254).\x20NEVER\x20add\x20an\x20order.claimed_by\x20leg:\x20fund\x20rails\x20never\x20read\x20the\x20claimed_by\x20axis\x20(decision\x2011,\x20R-FUND-RAIL-CLAIMED-BY\x20/\x20RAIL_CLAIMED_BY_LEG\x20critical).':/refund/['test'](a3)||!/recover|award/['test'](a3)&&/refund/['test'](a4)?'NODE\x20GATE\x20REQUIRED\x20(the\x20sketch\x20above\x20omits\x20it):\x20this\x20refund\x20rail\x20may\x20only\x20fire\x20at\x20its\x20refund\x20terminal\x20node\x20—\x20resolve\x20the\x20gate\x20against\x20order\x20node\x20state,\x20never\x20against\x20order.claimed_by\x20(fund\x20rails\x20NEVER\x20read\x20the\x20claimed_by\x20axis;\x20decision\x2011,\x20R-FUND-RAIL-CLAIMED-BY\x20/\x20RAIL_CLAIMED_BY_LEG\x20critical).\x20The\x20arbitration\x20award\x20is\x20the\x20indemnity\x20track\x27s\x20separate\x20commercial\x20payout\x20—\x20any\x20refund/award\x20overlap\x20is\x20legal\x20and\x20disclosed\x20at\x20the\x20MCP\x20dual-payout\x20confirmation\x20gate.':undefined;return{'key':U['key'],'template_id':U['template_id'],'host':U['host'],'purpose':U['purpose'],'bound':!a1&&!a2,...V?.['logic_summary']?{'logic_summary':V['logic_summary']}:{},...a5?{'logic_summary_note':a5}:{},...V?.['key_queries']?.['length']?{'key_queries':V['key_queries']}:{},...W!==undefined&&W['length']>0x0?{'suggested_templates':W}:{},'how_to_resolve':'guide_confirm.guard_resolutions[\x27'+U['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'+(W!==undefined&&W['length']>0x0?'\x20(suggested_templates\x20below\x20list\x20the\x20matching\x20executable\x20forms\x20and\x20their\x20parameters)':'.')+(U['host']==='machine'&&!a0?'\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.':'')+(a0?'\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.'+(Z['recipient']==='guard_identifier'&&Z['recipient_key']!=='254'?'\x20This\x20rail\x27s\x20recipient\x20is\x20GuardIdentifier('+(Z['recipient_key']??'0')+')\x20—\x20the\x20inline\x20table\x20MUST\x20'+('declare\x20slot\x20'+(Z['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).':''):'')+(a1?'\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).':'')};}),K=u['length']>0x0||r['blocking'],L={'expiredTerminal':(j['machine_shape']??[])['some'](U=>/expire|deadline|timeout/i['test'](String(U?.['name']??'')))},M=checkGameTheoryConstraints(t,g,L),N=[];for(const U of requirementCoverage(e['intent_text'],j)){if(U['status']==='mapped')continue;N['push']({'id':U['family'],'label':U['label'],'severity':U['status']==='blocker'&&U['family']==='fulfillment'?'critical':'medium','message':'Intent\x20promises\x20\x27'+U['label']+'\x27\x20(stated:\x20\x22'+U['evidence']+'\x22)\x20but\x20the\x20matched\x20template\x20does\x20not\x20carry\x20it:\x20'+U['note'],'fix':U['note']});}for(const V of y){if(V['adopted']||V['evidence_matched']!==![])continue;N['push']({'id':'module_'+V['capability'],'label':V['capability'],'severity':'info','message':'Module\x20\x27'+V['capability']+'\x27\x20rides\x20score\x20alone\x20(no\x20intent\x20evidence):\x20its\x20objects\x20ARE\x20included\x20in\x20this\x20build\x20—\x20an\x20UNCONFIRMED\x20adoption.','fix':'Confirm\x20via\x20guide_state.adopted_module_ids,\x20answer\x20the\x20structured\x20payment/trust\x20questions,\x20or\x20rebuild\x20with\x20an\x20adoption\x20list\x20that\x20omits\x20it.'});}const O=assessWorkflowDesign(t,{'gaps':N}),P=buildCreationPlan(t),Q=[...new Set(q['steps']['filter'](W=>typeof W['account']==='string')['map'](W=>W['account']))]['sort'](),R=[...collectLateMarks(q)]['sort'](),S=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'](W=>({'name':W['name'],'role':W['role'],...W['operator']?{'operator':W['operator']}:{},...W['semantic_role']?{'semantic_role':W['semantic_role']}:{}})),'guards':j['guards']['map'](W=>({'template_id':W['template_id'],'host':W['host'],'purpose':W['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':K?0x9:0xa,'step_name':K?'Harness\x20Check\x20(issues\x20found)':'Submission\x20Plan\x20Ready','guide_state':{...e,'adopted_module_ids':i['map'](W=>W['id'])},'intent':{'intent_type':g['intent'],'industry':g['industry'],'roles':g['roles'],'deliverables':g['deliverables'],'payment':g['payment'],'trust':g['trust']},'adopted_modules':i['map'](W=>({'id':W['id'],'name':W['name'],'description':W['description'],'requires_keeper':W['requiresKeeper'],'keeper_hint':W['keeperHint'],'user_protections':W['userProtections'],'merchant_obligations':W['merchantObligations']})),'mode_prior':S,...l['length']>0x0?{'user_input_questions':l,'user_input_note':'Collect\x20each\x20answer\x20and\x20pass\x20it\x20back\x20as\x20guide_state.fee_overrides[\x27<param_key>\x27]\x20on\x20the\x20next\x20merchant_guide\x20call;\x20unanswered\x20questions\x20keep\x20the\x20template\x20default.'}:{},...S?.['time_anchors']?{'time_anchor_instructions':Object['entries'](S['time_anchors'])['map'](([W,X])=>{const Y=X['startsWith']('order.time')?'\x20(order-creation\x20time\x20—\x20PRE-checkout\x20branches\x20only;\x20a\x20post-checkout\x20window\x20anchored\x20here\x20is\x20unreachable)':X['startsWith']('progress.current_time')?'\x20(entry\x20time\x20of\x20the\x20window\x27s\x20source\x20node\x20—\x20witness-derived\x20via\x20OrderProgress,\x20one\x20Guard\x20serves\x20every\x20order)':X['startsWith']('absolute_date')?'\x20(per-order\x20instance\x20Guard\x20—\x20the\x20absolute\x20date\x20differs\x20per\x20booking)':'';return'Time\x20windows\x20for\x20\x27'+W+'\x27\x20anchor\x20to\x20'+X+Y;})}:{},'blueprint':{'nodes':t['nodes']['map'](W=>({'id':W['id'],'type':W['type'],'purpose':W['purpose']})),'edges':t['edges']['map'](W=>({'from':W['from'],'to':W['to'],'relation':W['relation'],'required':W['required']}))},'evaluation_preview':{'estimatedRiskScore':s,'estimatedCompletenessScore':Math['min'](0x64,0x1e+i['length']*0x8),'keyRisks':r['findings']['filter'](W=>W['level']==='critical'||W['level']==='high')['map'](W=>W['title']),'strengths':r['findings']['filter'](W=>W['level']==='info')['map'](W=>W['title']),'moduleBoosts':{}},'graph_validation':{'valid':r['issues']['length']===0x0,'hard_violations':r['issues']['map'](W=>({'id':W['code'],'description':W['detail'],'fix':'Fix\x20the\x20Plan\x20structure'})),'soft_notes':r['findings']['filter'](W=>W['level']==='medium'||W['level']==='low')['map'](W=>({'id':W['rule_id'],'description':W['title']}))},'harness_check':{'module_constraints':y['map'](W=>{const X=W['capability']==='discount_lifecycle'&&W['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).':W['reason'],Y=W['evidence_matched']===![]?W['reason']:X;return{'module':W['capability'],'plan_satisfied':W['adopted'],'missing':W['missingConstraints'],'reason':Y,'findings':W['findings'],'evidence_matched':W['evidence_matched']};}),'blocking_issues':[...u['map'](W=>({'module':W['module'],'missing_constraints':W['missing_constraints'],'fix':W['fix']})),...D],'module_gaps':y['filter'](W=>!W['adopted'])['map'](W=>({'module':W['capability'],'missing_constraints':W['missingConstraints'],'fix':W['reason']})),'deploy_time_checks':A,'recipient_design_guidance':C},'game_theory':{'summary':M['summary'],'coverage':M['coveredCount']+'/'+M['totalCount'],'exposed_scenarios':M['exposedScenarios'],'wow_alignments':M['wowAlignments'],'scenarios':M['results']['map'](W=>({'scenario':W['scenario'],'covered':W['covered'],'conflict':W['conflict'],'user_protection':W['userProtection'],'evaluation_metric':W['evaluationMetric'],'recommendation':W['recommendation']}))},'workflow_design_assessment':{'score':O['score'],'summary':O['summary'],'findings':O['findings']['map'](W=>({'kind':W['kind'],'severity':W['severity'],'message':W['message'],'fix':W['fix']})),'checks':O['checks']['map'](W=>({'id':W['id'],'dimension':W['dimension'],'passed':W['passed'],'severity':W['severity'],'message':W['message'],'fix':W['fix']}))},'creation_plan':P,'post_deploy_steps':B,...o['supplyChain']!==undefined?{'supply_chain':o['supplyChain']['map'](W=>({'steps':W['steps']['map'](X=>X['id']),'inputs':W['inputs'],'primitives':W['primitives'],'notes':W['notes'],...W['handoff']!==undefined?{'handoff':W['handoff']}:{}}))}:{},'mandatory_disclosures':['PII\x20discipline\x20(rex5\x20B-57):\x20never\x20write\x20personal\x20data\x20(phone,\x20email,\x20exact\x20unit\x20address)\x20into\x20public\x20on-chain\x20fields\x20—\x20Contact\x20description/location/IM\x20entries,\x20repository\x20rows,\x20progress\x20messages\x20and\x20WIP\x20text\x20are\x20all\x20public.\x20Exchange\x20PII\x20over\x20the\x20encrypted\x20Messenger\x20and\x20keep\x20only\x20WTS\x20proofs\x20on\x20chain;\x20the\x20local\x20harness\x20store\x20is\x20non-private\x20too\x20(cache.db\x20holds\x20messenger\x20plaintext\x20and\x20LocalInfo\x20entries\x20unencrypted\x20on\x20disk,\x20readable\x20by\x20any\x20session\x20sharing\x20the\x20keystore).','Trust-claim\x20prose\x20is\x20not\x20a\x20chain\x20anchor\x20(rex5\x20T-31):\x20any\x20compensation-fund\x20or\x20protection\x20figure\x20quoted\x20in\x20the\x20service\x20description\x20is\x20free\x20text\x20—\x20awards\x20shrink\x20the\x20live\x20fund\x20in\x20place\x20(the\x20quoted\x20number\x20silently\x20goes\x20stale)\x20and\x20the\x20per-order\x20covered\x20ceiling\x20is\x20fund/3\x20(MAX_INDEMNITY_MULTIPLE),\x20not\x20the\x20headline.\x20Keep\x20quoted\x20numbers\x20synced\x20to\x20the\x20live\x20fund\x20balance\x20before\x20publishing\x20and\x20after\x20every\x20award.','Single-account\x20build\x20contract\x20(MN5-5R\x20decision):\x20this\x20pipeline\x20wires\x20ONLY\x20the\x20deploying\x20account\x20—\x20the\x20permission\x20layer\x27s\x20admin\x20pass-through\x20means\x20a\x20single-account\x20build\x20needs\x20zero\x20grants,\x20so\x20no\x20other\x20account\x20is\x20ever\x20granted.\x20A\x20multi-account\x20shop\x20(separate\x20keeper/staff/operator\x20accounts)\x20will\x20be\x20REFUSED\x20at\x20execution\x20time\x20(error\x20codes\x201000/1002\x20and\x20the\x20350~364\x20abort\x20family)\x20—\x20the\x20plan\x20will\x20look\x20complete\x20and\x20still\x20fail\x20on\x20first\x20non-admin\x20operation.\x20Until\x20an\x20explicit\x20account-grant\x20phase\x20ships,\x20run\x20multi-account\x20shops\x20by\x20declaring\x20the\x20limitation\x20up\x20front\x20and\x20granting\x20roles\x20manually\x20post-publish;\x20do\x20not\x20let\x20the\x20plan\x27s\x20completeness\x20imply\x20multi-account\x20readiness.'],...J['length']>0x0?{'pending_guard_designs':J}:{},...J['length']>0x0&&(q['pending_guards']?.['length']??0x0)!==J['length']?{'pending_count_note':'Two\x20counts,\x20two\x20views:\x20pending_guard_designs\x20lists\x20'+J['length']+'\x20unresolved\x20design(s)\x20(compile\x20view\x20—\x20includes\x20advisory\x20designs\x20with\x20no\x20edge/rail/policy/buy\x20mount);\x20'+('the\x20plan\x20audit\x20counts\x20'+(q['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':[...f['warnings'],...gasEconomicsWarnings(e['sales'],e['reward_claim_amount']),...o['omitted']['length']>0x0?['Advisory\x20guard\x20design(s)\x20omitted\x20by\x20decision\x20({kind:\x27omit\x27}):\x20'+o['omitted']['join'](',\x20')+'\x20—\x20'+'no\x20Guard\x20created,\x20nothing\x20binds\x20them\x20(run75747\x20F-38).']:[],...(o['supplyChain']??[])['flatMap']((W,X)=>W['notes']['map'](Y=>'Supply-chain\x20promise\x20#'+String(X+0x1)+':\x20'+Y))],'next_action':u['length']>0x0?'Resolve\x20the\x20blocking_issues\x20above\x20(compile\x20blockers\x20—\x20harness_check.blocking_issues\x20rows\x20with\x20module\x20\x27template\x27;\x20adjust\x20the\x20template\x20or\x20its\x20build\x20inputs),\x20then\x20call\x20merchant_guide\x20again.':r['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.'+(J['length']>0x0?'\x20Pending\x20guard\x20designs:\x20'+J['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.':''):I['length']>0x0?'Plan\x20is\x20structurally\x20ready,\x20but\x20'+I['length']+'\x20bound\x20guard\x20design(s)\x20('+I['map'](W=>'\x27'+W+'\x27')['join'](',\x20')+')\x20are\x20UNRESOLVED\x20(plan.pending_guard_designs)\x20—\x20do\x20NOT\x20materialize\x20yet:\x20an\x20unresolved\x20bound\x20design\x20ships\x20a\x20guard\x20the\x20executor\x20invents.\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\x20in\x20ONE\x20deterministic\x20call:\x20benchmark_migration\x20{action:\x27plan_execute\x27,\x20plan:\x20this\x20response\x27s\x20plan\x20object\x20verbatim'+(Q['length']>0x0?',\x20accounts:{'+Q['map'](W=>W+':\x20<its\x20controller\x20env>')['join'](',\x20')+'}':'')+('}\x20—\x20it\x20pre-flights\x20the\x20freeze\x20gate,\x20bind-audits\x20every\x20reference,\x20pre-resolves\x20local\x20marks,\x20slices\x20on\x20timeout_ms,\x20and\x20RESUMES\x20from\x20failures\x20(completed_steps\x20+\x20previous_outputs;\x20never\x20re-run\x20from\x20scratch\x20—\x20ghost\x20duplicates).\x20Then\x20run\x20post_deploy_steps\x20in\x20order\x20('+B['map'](W=>W['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.\x20Manual\x20fallback\x20(only\x20if\x20plan_execute\x20refuses):\x20create\x20the\x20objects\x20in\x20creation_plan\x20order\x20via\x20onchain_operations,\x20then\x20run\x20post_deploy_steps\x20in\x20order.'),'plan':((()=>{const W=templateCatalogDigest(String(q['templateId']??''));return{...q,...W!==undefined?{'template_digest':W}:{},'catalog_version':BUILTIN_TEMPLATES_VERSION};})()),...R['length']>0x0?{'required_local_marks':R,'required_local_marks_note':'plan_execute\x20(the\x20default\x20materializer\x20above)\x20resolves\x20each\x20of\x20these\x20local\x20names\x20against\x20the\x20LocalMark\x20store\x20of\x20the\x20target\x20network\x20and\x20refuses\x20to\x20execute\x20while\x20any\x20is\x20unregistered.\x20'+'Register\x20them\x20BEFORE\x20executing\x20(local_mark_operation\x20add).\x20A\x20name\x20that\x20matches\x20an\x20object\x20this\x20plan\x20itself\x20creates\x20is\x20bound\x20to\x20that\x20object\x20automatically.\x20'+'A\x20recipient\x20mark\x20must\x20point\x20at\x20a\x20real\x20account\x20address:\x20an\x20empty\x20name\x20makes\x20the\x20SDK\x20substitute\x20the\x20deploying\x20account,\x20and\x20an\x20object-id\x20/\x20zero-address\x20recipient\x20is\x20transferred\x20and\x20cannot\x20be\x20retrieved.'}:{},'audit':{'issues':r['issues'],'findings':r['findings'],'blocking':r['blocking'],'score':s},'reflux':{'applied':p['applied'],'blocks':p['blocks'],'iterations':p['iterations']}};}
@@ -1,4 +1,5 @@
1
1
  import { type IndustryTemplate } from "../../knowledge/template-loader.js";
2
+ import { type RequirementCoverageEntry } from "../../knowledge/requirement-families.js";
2
3
  import type { SemanticIRDiscovery } from "../../knowledge/semantic-ir.js";
3
4
  import type { Industry } from "../../customer/index.js";
4
5
  export interface MigrationEntry {
@@ -35,6 +36,7 @@ export interface MigrationLog {
35
36
  passed: boolean;
36
37
  findings: string[];
37
38
  };
39
+ requirement_coverage: RequirementCoverageEntry[];
38
40
  questions?: MigrationQuestion[];
39
41
  network: "testnet" | "mainnet" | "localnet";
40
42
  }
@@ -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{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.'};}const SPLIT_ORDER_PATTERNS=[/\b(?:multiple|several|many|\d+)\s+(?:pickup|collection|self[- ]pick(?:up)?)\s*(?:points?|locations?|stations?|sites?)/i,/\b(?:per|each|every)[-\s](?:pickup|collection)?[-\s]?point\b/i,/\b(?:group[- ]?buy(?:ing)?|community)\s+leaders?\b/i,/\brefund\s+(?:only\s+)?(?:some|part)\s+(?:of\s+)?(?:the\s+)?items?\b/i,/\breturn\s+(?:some|part)\s+of\s+(?:the\s+)?items?\b/i,/\b(?:refund|return)\s+\d+\s+of\s+\d+\s+items?\b/i,/\bper[- ]item\s+(?:refund|return|after[- ]?sales)\b/i];function splitOrderRecipeEntry(a){if(!SPLIT_ORDER_PATTERNS['some'](b=>b['test'](a)))return undefined;return{'source_element':'Multi-pickup-point\x20/\x20per-item\x20after-sales\x20(object-model\x20boundary)','mapping_note':'RECIPE\x20—\x20same-Service\x20split\x20orders\x20(expressible\x20TODAY):\x20keep\x20ONE\x20Service\x20as\x20the\x20storefront\x20and\x20'+'create\x20ONE\x20Order\x20per\x20pickup\x20point\x20(or\x20per\x20item\x20batch).\x20Each\x20Order\x20carries\x20its\x20own\x20escrow,\x20its\x20own\x20'+'time\x20windows\x20(a\x20per-point\x20cutoff\x20is\x20that\x20Order\x27s\x20time-lock\x20guard)\x20and\x20its\x20own\x20settlement/refund\x20'+'rails\x20—\x20no\x20topology\x20change,\x20no\x20new\x20primitive.\x20Per-item\x20partial\x20after-sales\x20rides\x20the\x20same\x20split:\x20'+'the\x20buyer\x20refunds/returns\x20per\x20Order\x20and\x20each\x20Order\x27s\x20escrow\x20settles\x20independently.\x20Generate\x20the\x20'+'Service\x20ONCE,\x20then\x20open\x20one\x20order\x20per\x20point\x20via\x20the\x20normal\x20buy\x20flow.','reason':'Chain\x20object-model\x20boundary:\x20an\x20Order\x20has\x20no\x20product\x20lines\x20or\x20point\x20sub-objects,\x20so\x20per-line\x20'+'amounts/cutoffs\x20inside\x20ONE\x20order\x20cannot\x20be\x20expressed\x20in\x20guard\x20data\x20(template\x20ruling,\x20ISSUES\x20paper\x204).\x20'+'Honest\x20costs\x20of\x20the\x20recipe:\x20object\x20count\x20scales\x20with\x20points;\x20cross-order\x20consistency\x20is\x20the\x20CLIENT\x27s\x20'+'duty\x20(no\x20atomic\x20multi-order\x20purchase);\x20campaign\x20aggregation\x20(crowdfunding\x20threshold\x20/\x20leader\x20roster)\x20'+'loses\x20its\x20single-object\x20view\x20—\x20compute\x20per-point\x20sums\x20client-side.\x20The\x20OrderLine\x20sub-object\x20primitive\x20'+'is\x20registered\x20on\x20the\x20protocol\x20train\x20(scheduled\x20after\x20the\x20machine.patch\x20paper)\x20—\x20re-check\x20the\x20train\x20'+'before\x20hand-building\x20aggregates.'};}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 j=matchTemplate(a['industry']+'\x20'+a['description'],undefined,b);j&&j['template']['industry']===a['industry']&&(c=j['template'],d={'source':j['source'],'confidence':j['confidence'],...j['matched_tags']?{'matched_tags':j['matched_tags']}:{}});}}else{const k=a['industry']?a['industry']+'\x20'+a['description']:a['description'],l=matchTemplate(k,a['industry']?undefined:a['ir_industry'],b);c=l?.['template'];l&&(d={'source':l['source'],'confidence':l['confidence'],...l['matched_tags']?{'matched_tags':l['matched_tags']}:{}});if(!c&&a['industry']){c=listTemplates()['templates']['find'](m=>m['industry']===a['industry']&&m['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);e['push'](...h['manual']),f['push'](...h['unmapped']);const i=splitOrderRecipeEntry(a['description']);if(i)e['push'](i);return{'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'](m=>m!==c['recommended_role'])},'risk_check':dryRunRiskCheck(c),...c['conditional_guards']?.['length']?{'questions':[...new Set(c['conditional_guards']['map'](m=>m['param']))]['map'](m=>{const n=c['conditional_guards']['find'](o=>o['param']===m);return{'param':m,'question':n['question'],'options':[...n['values']],'default':String(c['fee_params'][m]??'')};})}:{},'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';import{requirementCoverage}from'../../knowledge/requirement-families.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.'};}const SPLIT_ORDER_PATTERNS=[/\b(?:multiple|several|many|\d+)\s+(?:pickup|collection|self[- ]pick(?:up)?)\s*(?:points?|locations?|stations?|sites?)/i,/\b(?:per|each|every)[-\s](?:pickup|collection)?[-\s]?point\b/i,/\b(?:group[- ]?buy(?:ing)?|community)\s+leaders?\b/i,/\brefund\s+(?:only\s+)?(?:some|part)\s+(?:of\s+)?(?:the\s+)?items?\b/i,/\breturn\s+(?:some|part)\s+of\s+(?:the\s+)?items?\b/i,/\b(?:refund|return)\s+\d+\s+of\s+\d+\s+items?\b/i,/\bper[- ]item\s+(?:refund|return|after[- ]?sales)\b/i];function splitOrderRecipeEntry(a){if(!SPLIT_ORDER_PATTERNS['some'](b=>b['test'](a)))return undefined;return{'source_element':'Multi-pickup-point\x20/\x20per-item\x20after-sales\x20(object-model\x20boundary)','mapping_note':'RECIPE\x20—\x20same-Service\x20split\x20orders\x20(expressible\x20TODAY):\x20keep\x20ONE\x20Service\x20as\x20the\x20storefront\x20and\x20'+'create\x20ONE\x20Order\x20per\x20pickup\x20point\x20(or\x20per\x20item\x20batch).\x20Each\x20Order\x20carries\x20its\x20own\x20escrow,\x20its\x20own\x20'+'time\x20windows\x20(a\x20per-point\x20cutoff\x20is\x20that\x20Order\x27s\x20time-lock\x20guard)\x20and\x20its\x20own\x20settlement/refund\x20'+'rails\x20—\x20no\x20topology\x20change,\x20no\x20new\x20primitive.\x20Per-item\x20partial\x20after-sales\x20rides\x20the\x20same\x20split:\x20'+'the\x20buyer\x20refunds/returns\x20per\x20Order\x20and\x20each\x20Order\x27s\x20escrow\x20settles\x20independently.\x20Generate\x20the\x20'+'Service\x20ONCE,\x20then\x20open\x20one\x20order\x20per\x20point\x20via\x20the\x20normal\x20buy\x20flow.','reason':'Chain\x20object-model\x20boundary:\x20an\x20Order\x20has\x20no\x20product\x20lines\x20or\x20point\x20sub-objects,\x20so\x20per-line\x20'+'amounts/cutoffs\x20inside\x20ONE\x20order\x20cannot\x20be\x20expressed\x20in\x20guard\x20data\x20(template\x20ruling,\x20ISSUES\x20paper\x204).\x20'+'Honest\x20costs\x20of\x20the\x20recipe:\x20object\x20count\x20scales\x20with\x20points;\x20cross-order\x20consistency\x20is\x20the\x20CLIENT\x27s\x20'+'duty\x20(no\x20atomic\x20multi-order\x20purchase);\x20campaign\x20aggregation\x20(crowdfunding\x20threshold\x20/\x20leader\x20roster)\x20'+'loses\x20its\x20single-object\x20view\x20—\x20compute\x20per-point\x20sums\x20client-side.\x20The\x20OrderLine\x20sub-object\x20primitive\x20'+'is\x20registered\x20on\x20the\x20protocol\x20train\x20(scheduled\x20after\x20the\x20machine.patch\x20paper)\x20—\x20re-check\x20the\x20train\x20'+'before\x20hand-building\x20aggregates.'};}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 j=matchTemplate(a['industry']+'\x20'+a['description'],undefined,b);j&&j['template']['industry']===a['industry']&&(c=j['template'],d={'source':j['source'],'confidence':j['confidence'],...j['matched_tags']?{'matched_tags':j['matched_tags']}:{}});}}else{const k=a['industry']?a['industry']+'\x20'+a['description']:a['description'],l=matchTemplate(k,a['industry']?undefined:a['ir_industry'],b);c=l?.['template'];l&&(d={'source':l['source'],'confidence':l['confidence'],...l['matched_tags']?{'matched_tags':l['matched_tags']}:{}});if(!c&&a['industry']){c=listTemplates()['templates']['find'](m=>m['industry']===a['industry']&&m['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);e['push'](...h['manual']),f['push'](...h['unmapped']);const i=splitOrderRecipeEntry(a['description']);if(i)e['push'](i);return{'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'](m=>m!==c['recommended_role'])},'risk_check':dryRunRiskCheck(c),'requirement_coverage':requirementCoverage(a['description'],c),...c['conditional_guards']?.['length']?{'questions':[...new Set(c['conditional_guards']['map'](m=>m['param']))]['map'](m=>{const n=c['conditional_guards']['find'](o=>o['param']===m);return{'param':m,'question':n['question'],'options':[...n['values']],'default':String(c['fee_params'][m]??'')};})}:{},'network':a['network']??'testnet'};}
@@ -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,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']}))};}
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.\x20'+'Plan\x20the\x20whole\x20fix\x20in\x20one\x20pass:\x20renaming\x20creates\x20the\x20R-ESCROW-LEAF\x20obligation\x20'+'(every\x20terminal\x20node\x20needs\x20an\x20allocator\x20rail\x20anchored\x20to\x20it),\x20and\x20the\x20bound\x20'+'arbitration\x20must\x20not\x20share\x20the\x20service\x20Permission\x20(R-ARB-SAME-CONTROLLER)\x20and\x20'+'must\x20carry\x20a\x20non-empty\x20voting_guard\x20(R-ARB-VOTE-LOCK).');}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,c?{'localeNeutralLexicon':!![]}:undefined),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']}))};}