@wowok/agent-mcp 3.3.9 → 3.4.0

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 (252) hide show
  1. package/dist/chain-semantics/field-capability.js +1 -1
  2. package/dist/chain-semantics/freeze-map.js +1 -1
  3. package/dist/chain-semantics/fund-flow.js +1 -1
  4. package/dist/chain-semantics/guard-verbs.js +1 -1
  5. package/dist/chain-semantics/object-graph.js +1 -1
  6. package/dist/composition/audit.js +1 -1
  7. package/dist/composition/compile.d.ts +3 -2
  8. package/dist/composition/compile.js +1 -1
  9. package/dist/composition/inflight.d.ts +6 -0
  10. package/dist/composition/inflight.js +1 -1
  11. package/dist/composition/materialize.d.ts +4 -0
  12. package/dist/composition/materialize.js +1 -1
  13. package/dist/composition/param-disclosure.d.ts +61 -0
  14. package/dist/composition/param-disclosure.js +1 -0
  15. package/dist/composition/plan.d.ts +11 -1
  16. package/dist/composition/plan.js +1 -1
  17. package/dist/customer/account-events.js +1 -1
  18. package/dist/data/api/api.spec.js +1 -1
  19. package/dist/data/api/cli.js +1 -1
  20. package/dist/data/api/server.d.ts +1 -0
  21. package/dist/data/api/server.js +1 -1
  22. package/dist/data/projection/store.d.ts +2 -1
  23. package/dist/data/projection/store.js +1 -1
  24. package/dist/data/projection/types.d.ts +10 -0
  25. package/dist/data/sync/cdc.js +1 -1
  26. package/dist/data/sync/cdc.spec.js +1 -1
  27. package/dist/data/sync/store.d.ts +5 -0
  28. package/dist/data/sync/store.js +1 -1
  29. package/dist/data/sync/types.d.ts +2 -0
  30. package/dist/evaluation/builtins/graph-service.spec.js +1 -1
  31. package/dist/evaluation/engine.js +1 -1
  32. package/dist/evaluation/guard-scan.js +1 -1
  33. package/dist/experience/realtime-feedback.js +1 -1
  34. package/dist/extensions/business-modules.js +1 -1
  35. package/dist/extensions/industry-pack.js +1 -1
  36. package/dist/extensions/modes.js +1 -1
  37. package/dist/graph/onchain/expand.js +1 -1
  38. package/dist/graph/onchain/exposure.js +1 -1
  39. package/dist/harness/recover.js +1 -1
  40. package/dist/index.js +1 -1
  41. package/dist/knowledge/allocation-risk.js +1 -1
  42. package/dist/knowledge/allocation-templates.js +1 -1
  43. package/dist/knowledge/allocator-rail-verifier.js +1 -1
  44. package/dist/knowledge/arb-fund-facts.d.ts +1 -0
  45. package/dist/knowledge/arb-fund-facts.js +1 -1
  46. package/dist/knowledge/arbitration-ledger.js +1 -1
  47. package/dist/knowledge/arbitration-risk.d.ts +1 -0
  48. package/dist/knowledge/arbitration-risk.js +1 -1
  49. package/dist/knowledge/audit-rules.js +1 -1
  50. package/dist/knowledge/baselines/rules/allocation.json +6 -6
  51. package/dist/knowledge/baselines/rules/arb.json +2 -2
  52. package/dist/knowledge/baselines/rules/guard.json +11 -11
  53. package/dist/knowledge/baselines/rules/order.json +1 -1
  54. package/dist/knowledge/baselines/rules/plan.json +1 -1
  55. package/dist/knowledge/baselines/semantic-facts.js +1 -1
  56. package/dist/knowledge/builtin-templates.d.ts +14 -1
  57. package/dist/knowledge/builtin-templates.js +1 -1
  58. package/dist/knowledge/catalog-facts.d.ts +4 -0
  59. package/dist/knowledge/catalog-facts.js +1 -0
  60. package/dist/knowledge/commission-landing.js +1 -1
  61. package/dist/knowledge/component-schema.d.ts +64 -0
  62. package/dist/knowledge/component-schema.js +1 -0
  63. package/dist/knowledge/entity-recipient-guard.js +1 -1
  64. package/dist/knowledge/event-semantics.js +1 -1
  65. package/dist/knowledge/fee-param-bindings.d.ts +26 -0
  66. package/dist/knowledge/fee-param-bindings.js +1 -0
  67. package/dist/knowledge/fund-layer.js +1 -1
  68. package/dist/knowledge/getting-started.d.ts +2 -2
  69. package/dist/knowledge/getting-started.js +1 -1
  70. package/dist/knowledge/guard-anchor-reach.js +1 -1
  71. package/dist/knowledge/guard-design-patterns.js +1 -1
  72. package/dist/knowledge/guard-ledger.js +1 -1
  73. package/dist/knowledge/guard-lint.d.ts +1 -0
  74. package/dist/knowledge/guard-lint.js +1 -1
  75. package/dist/knowledge/guard-puzzle.js +1 -1
  76. package/dist/knowledge/guard-risk.js +1 -1
  77. package/dist/knowledge/guard-templates.d.ts +1 -1
  78. package/dist/knowledge/guard-templates.js +1 -1
  79. package/dist/knowledge/guard-translation.js +1 -1
  80. package/dist/knowledge/index.js +1 -1
  81. package/dist/knowledge/industry-registry.js +1 -1
  82. package/dist/knowledge/industry-strategy.js +1 -1
  83. package/dist/knowledge/jsonrpc-enum.d.ts +14 -3
  84. package/dist/knowledge/jsonrpc-enum.js +1 -1
  85. package/dist/knowledge/knob-docs.d.ts +5 -0
  86. package/dist/knowledge/knob-docs.js +1 -0
  87. package/dist/knowledge/machine-templates.js +1 -1
  88. package/dist/knowledge/machine-topology.js +1 -1
  89. package/dist/knowledge/machine-translation.js +1 -1
  90. package/dist/knowledge/onchain-constants.d.ts +2 -0
  91. package/dist/knowledge/onchain-constants.js +1 -1
  92. package/dist/knowledge/order-ledger.js +1 -1
  93. package/dist/knowledge/param-schema.d.ts +70 -0
  94. package/dist/knowledge/param-schema.js +1 -0
  95. package/dist/knowledge/param-tiers.d.ts +25 -0
  96. package/dist/knowledge/param-tiers.js +1 -0
  97. package/dist/knowledge/passport-ledger.d.ts +1 -1
  98. package/dist/knowledge/passport-ledger.js +1 -1
  99. package/dist/knowledge/pattern-resolutions.d.ts +106 -0
  100. package/dist/knowledge/pattern-resolutions.js +1 -0
  101. package/dist/knowledge/projection.spec.js +1 -1
  102. package/dist/knowledge/safety-rules.js +1 -1
  103. package/dist/knowledge/scenario-modes.d.ts +1 -0
  104. package/dist/knowledge/scenario-modes.js +1 -1
  105. package/dist/knowledge/scenario-topology.js +1 -1
  106. package/dist/knowledge/service-allocation-semantics.js +1 -1
  107. package/dist/knowledge/service-ledger.js +1 -1
  108. package/dist/knowledge/service-templates.js +1 -1
  109. package/dist/knowledge/strategy-manuals.d.ts +1 -1
  110. package/dist/knowledge/strategy-manuals.js +1 -1
  111. package/dist/knowledge/template-loader.d.ts +101 -1
  112. package/dist/knowledge/template-loader.js +1 -1
  113. package/dist/knowledge/template-nav.d.ts +7 -0
  114. package/dist/knowledge/template-nav.js +1 -0
  115. package/dist/knowledge/template-registry.js +1 -1
  116. package/dist/knowledge/template-scanner.d.ts +33 -0
  117. package/dist/knowledge/template-scanner.js +1 -1
  118. package/dist/knowledge/template-test-profiles.d.ts +17 -0
  119. package/dist/knowledge/template-test-profiles.js +1 -0
  120. package/dist/knowledge/template-validation.d.ts +1 -0
  121. package/dist/knowledge/template-validation.js +1 -1
  122. package/dist/knowledge/tools-reference.js +1 -1
  123. package/dist/knowledge/treasury-templates.js +1 -1
  124. package/dist/knowledge/workflow-guidance.js +1 -1
  125. package/dist/monitor/MonitorLoop.js +1 -1
  126. package/dist/participation/time-window.d.ts +37 -0
  127. package/dist/participation/time-window.js +1 -0
  128. package/dist/playbooks/service-build/business-puzzle.js +1 -1
  129. package/dist/playbooks/service-build/machine-panorama.d.ts +1 -0
  130. package/dist/playbooks/service-build/machine-panorama.js +1 -1
  131. package/dist/playbooks/service-build/merchant-guide.d.ts +4 -1
  132. package/dist/playbooks/service-build/merchant-guide.js +1 -1
  133. package/dist/playbooks/service-build/migration-planner.js +1 -1
  134. package/dist/playbooks/service-build/object-panorama.js +1 -1
  135. package/dist/playbooks/service-build/participation-radar.d.ts +1 -0
  136. package/dist/playbooks/service-build/participation-radar.js +1 -1
  137. package/dist/playbooks/service-build/relationship-profile.js +1 -1
  138. package/dist/playbooks/service-build/service-panorama.d.ts +1 -0
  139. package/dist/playbooks/service-build/service-panorama.js +1 -1
  140. package/dist/playbooks/service-build/service-quote.js +1 -1
  141. package/dist/playbooks/service-build/service-quote.spec.js +1 -1
  142. package/dist/playbooks/service-build/workflow-design-assessment.js +1 -1
  143. package/dist/relationship/registry.js +1 -1
  144. package/dist/review/index.js +1 -1
  145. package/dist/runtime/instance-registry.d.ts +7 -1
  146. package/dist/runtime/instance-registry.js +1 -1
  147. package/dist/safety/confirm-gate.js +1 -1
  148. package/dist/schema/benchmark-migration/index.d.ts +2 -0
  149. package/dist/schema/benchmark-migration/index.js +1 -1
  150. package/dist/schema/call/allocation.js +1 -1
  151. package/dist/schema/call/arbitration.js +1 -1
  152. package/dist/schema/call/base.d.ts +8 -0
  153. package/dist/schema/call/base.js +1 -1
  154. package/dist/schema/call/bridge.d.ts +2 -0
  155. package/dist/schema/call/error-codes.d.ts +1 -1
  156. package/dist/schema/call/error-codes.js +1 -1
  157. package/dist/schema/call/guard.js +1 -1
  158. package/dist/schema/call/handler.js +1 -1
  159. package/dist/schema/call/machine.js +1 -1
  160. package/dist/schema/call/semantic.js +1 -1
  161. package/dist/schema/call/service.d.ts +3 -3
  162. package/dist/schema/call/service.js +1 -1
  163. package/dist/schema/common/index.js +1 -1
  164. package/dist/schema/evaluation/index.d.ts +8 -0
  165. package/dist/schema/evaluation/index.js +1 -1
  166. package/dist/schema/goal/planning.d.ts +1 -0
  167. package/dist/schema/goal/planning.js +1 -1
  168. package/dist/schema/industry-pack/index.d.ts +29 -0
  169. package/dist/schema/industry-pack/index.js +1 -1
  170. package/dist/schema/local/index.d.ts +20 -0
  171. package/dist/schema/local/index.js +1 -1
  172. package/dist/schema/messenger/index.d.ts +2 -0
  173. package/dist/schema/messenger/index.js +1 -1
  174. package/dist/schema/operations.d.ts +1 -1
  175. package/dist/schema/operations.js +1 -1
  176. package/dist/schema/query/bi.d.ts +106 -0
  177. package/dist/schema/query/bi.js +1 -1
  178. package/dist/schema/query/index.d.ts +5 -5
  179. package/dist/schema/query/index.js +1 -1
  180. package/dist/schema/schema-version.js +1 -1
  181. package/dist/schema/watch/index.js +1 -1
  182. package/dist/schema-query-impl/index.js +1 -1
  183. package/dist/schemas/account_operation.output.json +4 -2
  184. package/dist/schemas/benchmark_migration_operation.output.json +3 -3
  185. package/dist/schemas/benchmark_migration_operation.schema.json +16 -2
  186. package/dist/schemas/bridge_operation.output.json +4 -2
  187. package/dist/schemas/bridge_operation.schema.json +5 -5
  188. package/dist/schemas/evaluation_operation.output.json +16 -0
  189. package/dist/schemas/guard2file.schema.json +1 -1
  190. package/dist/schemas/index.json +1 -1
  191. package/dist/schemas/industry_pack_operation.output.json +150 -1
  192. package/dist/schemas/industry_pack_operation.schema.json +9 -3
  193. package/dist/schemas/keeper_operation.output.json +2 -2
  194. package/dist/schemas/local_cache_operation.output.json +4 -2
  195. package/dist/schemas/local_history_operation.output.json +4 -2
  196. package/dist/schemas/local_info_operation.output.json +4 -2
  197. package/dist/schemas/local_mark_operation.output.json +4 -2
  198. package/dist/schemas/machineNode2file.schema.json +1 -1
  199. package/dist/schemas/messenger_operation.output.json +13 -2
  200. package/dist/schemas/messenger_operation.schema.json +41 -34
  201. package/dist/schemas/monitor_events.output.json +2 -2
  202. package/dist/schemas/monitor_subscription.output.json +2 -2
  203. package/dist/schemas/onchain_events.output.json +14 -14
  204. package/dist/schemas/onchain_operations.output.json +13 -10
  205. package/dist/schemas/onchain_operations.schema.json +124 -99
  206. package/dist/schemas/onchain_operations_allocation.schema.json +7 -6
  207. package/dist/schemas/onchain_operations_arbitration.schema.json +7 -6
  208. package/dist/schemas/onchain_operations_contact.schema.json +4 -3
  209. package/dist/schemas/onchain_operations_demand.schema.json +4 -3
  210. package/dist/schemas/onchain_operations_gen_passport.schema.json +4 -3
  211. package/dist/schemas/onchain_operations_gen_proof.schema.json +1 -1
  212. package/dist/schemas/onchain_operations_guard.schema.json +7 -6
  213. package/dist/schemas/onchain_operations_machine.schema.json +9 -7
  214. package/dist/schemas/onchain_operations_order.schema.json +6 -4
  215. package/dist/schemas/onchain_operations_payment.schema.json +2 -2
  216. package/dist/schemas/onchain_operations_permission.schema.json +19 -15
  217. package/dist/schemas/onchain_operations_personal.schema.json +17 -14
  218. package/dist/schemas/onchain_operations_progress.schema.json +6 -4
  219. package/dist/schemas/onchain_operations_proof.schema.json +4 -3
  220. package/dist/schemas/onchain_operations_repository.schema.json +9 -7
  221. package/dist/schemas/onchain_operations_reward.schema.json +5 -4
  222. package/dist/schemas/onchain_operations_service.schema.json +15 -12
  223. package/dist/schemas/onchain_operations_treasury.schema.json +4 -3
  224. package/dist/schemas/onchain_table_data.output.json +18 -13
  225. package/dist/schemas/onchain_table_data.schema.json +13 -13
  226. package/dist/schemas/query_toolkit.output.json +301 -33
  227. package/dist/schemas/query_toolkit.schema.json +6 -6
  228. package/dist/schemas/watch_operation.output.json +3 -3
  229. package/dist/schemas/workflow_operation.schema.json +3 -2
  230. package/dist/schemas/wowok_buildin_info.schema.json +1 -1
  231. package/dist/task/playbook.js +1 -1
  232. package/dist/tools/handlers/benchmark-migration.d.ts +1 -0
  233. package/dist/tools/handlers/benchmark-migration.js +1 -1
  234. package/dist/tools/handlers/config.js +1 -1
  235. package/dist/tools/handlers/evaluation.js +1 -1
  236. package/dist/tools/handlers/evaluation.spec.js +1 -1
  237. package/dist/tools/handlers/industry-pack.js +1 -1
  238. package/dist/tools/handlers/messenger.js +1 -1
  239. package/dist/tools/handlers/onchain.d.ts +4 -0
  240. package/dist/tools/handlers/onchain.js +1 -1
  241. package/dist/tools/index.js +1 -1
  242. package/dist/tools/registry/business.js +1 -1
  243. package/dist/tools/registry/onchain.js +1 -1
  244. package/dist/tools/registry/query.js +1 -1
  245. package/dist/tools/sanitize-output.js +1 -1
  246. package/dist/tools/sanitize-output.spec.js +1 -1
  247. package/dist/tools/types.d.ts +1 -0
  248. package/dist/tools/upgrade-check.d.ts +22 -0
  249. package/dist/tools/upgrade-check.js +1 -1
  250. package/dist/tools/wrap.d.ts +1 -1
  251. package/dist/tools/wrap.js +1 -1
  252. package/package.json +7 -6
@@ -1 +1 @@
1
- import{copyFileSync,existsSync,mkdirSync,readdirSync,readFileSync,renameSync,rmdirSync,statSync,writeFileSync}from'node:fs';import{join,relative,sep}from'node:path';import{z}from'zod';import{getWowokDataDir,getWowokIndustryDir}from'@wowok/wowok';import{SUPPORTED_INDUSTRIES}from'../customer/user-preferences.js';import{isRegisteredIndustry}from'./industry-registry.js';import{BUILTIN_TEMPLATES,BUILTIN_TEMPLATES_VERSION}from'./builtin-templates.js';import{MachineProseEnvelopeSchema}from'./template-prose.js';import{releaseBodyHash,releaseSentinelLine,stripReleaseSentinel}from'./release-sentinel.js';export const TEMPLATES_SUBDIR='templates';export function resolveTemplatesDir(){return process['env']['WOWOK_TEMPLATES_DIR']||getWowokIndustryDir();}function resolveLegacyTemplatesDir(){return process['env']['WOWOK_LEGACY_TEMPLATES_DIR']||join(getWowokDataDir(),'templates');}const MachineEdgeSchema=z['object']({'prev':z['string'](),'forward':z['string']()['min'](0x1)['optional'](),'operator':z['enum'](['merchant','order_payer'])['optional'](),'named_operator':z['string']()['min'](0x1)['optional'](),'permission_index':z['number']()['int']()['min'](0x3e8)['optional'](),'guard_key':z['string']()['min'](0x1)['optional']()}),MachineNodeSchema=z['object']({'name':z['string']()['min'](0x1),'role':z['string']()['min'](0x1),'operator':z['enum'](['merchant','order_payer'])['optional'](),'named_operator':z['string']()['min'](0x1)['optional'](),'semantic_role':z['enum'](['draft','active','delivered','final','cancelled'])['optional'](),'optional':z['boolean']()['optional'](),'threshold':z['number']()['int']()['min'](0x0)['optional'](),'from':z['array'](z['union']([z['string'](),MachineEdgeSchema]))['optional']()}),GuardRefSchema=z['object']({'template_id':z['string']()['regex'](/^(pattern\.[a-z0-9_]+|tpl_[a-z0-9_]+)$/,'guard\x20template_id\x20must\x20be\x20a\x20\x27pattern.*\x27\x20design\x20pattern\x20or\x20\x27tpl_*\x27\x20guard\x20template'),'host':z['enum'](['service','machine','reward','repository','arbitration']),'purpose':z['string']()['min'](0x1),'key':z['string']()['min'](0x1)['optional'](),'policy':z['object']({'name':z['string']()['min'](0x1)['optional'](),'description':z['string']()['min'](0x1)['optional'](),'id_from':z['string']()['min'](0x1)['optional'](),'value_type':z['string']()['min'](0x1)['optional']()})['optional'](),'params':z['record'](z['string'](),z['unknown']())['optional']()}),ConditionalGuardEmissionSchema=z['object']({'guard_key':z['string']()['min'](0x1),'param':z['string']()['min'](0x1),'values':z['array'](z['string']()['min'](0x1))['min'](0x2),'emit_value':z['string']()['min'](0x1),'question':z['string']()['min'](0x1)})['strict'](),AllocatorRowSchema=z['object']({'track':z['enum'](['settlement','refund']),'recipient':z['enum'](['entity','guard_identifier','signer']),'recipient_key':z['string']()['min'](0x1)['optional'](),'mode':z['enum'](['amount','rate','surplus']),'value':z['union']([z['string'](),z['number']()])['optional'](),'value_from':z['string']()['optional'](),'value_from_complement':z['string']()['min'](0x1)['optional'](),'fix':z['union']([z['string'](),z['number']()])['optional'](),'fix_from':z['string']()['optional'](),'guard_key':z['string']()['min'](0x1)['optional'](),'note':z['string']()['optional']()})['strict'](),AllocatorSchema=z['object']({'recipient':z['enum'](['signer','entity','fixed']),'recipient_key':z['string']()['min'](0x1)['optional'](),'refund_track':z['enum'](['order_anchored'])['optional'](),'count':z['number']()['int']()['positive'](),'mode':z['enum'](['amount','rate','surplus']),'once_per_order':z['boolean']()['optional'](),'rows':z['array'](AllocatorRowSchema)['optional'](),'description':z['string']()['min'](0x1)})['strict'](),IndustryNameSchema=z['string']()['regex'](/^[a-z][a-z0-9_]*$/,'industry\x20must\x20be\x20lowercase\x20snake_case\x20(a-z,\x200-9,\x20_)')['refine'](a=>isRegisteredIndustry(a),{'message':'unknown\x20industry\x20—\x20register\x20it\x20first\x20via\x20an\x20industry\x20pack\x20'+'(industry_pack_operation\x20action=\x27scaffold\x27)\x20or\x20the\x20industry\x20generalizer;\x20'+('builtin\x20industries:\x20'+SUPPORTED_INDUSTRIES['join'](',\x20'))});export const TemplateFrontmatterSchema=z['object']({'id':z['string']()['regex'](/^[a-z][a-z0-9_-]*\/[a-z][a-z0-9_-]*$/,'id\x20must\x20be\x20\x27<industry>/<variant>\x27'),'industry':IndustryNameSchema,'variant':z['string']()['regex'](/^[a-z][a-z0-9_-]*$/),'product_ref':z['string']()['regex'](/^[a-z][a-z0-9._-]*$/,'product_ref\x20must\x20be\x20a\x20lowercase\x20product\x20slug')['optional'](),'archetype':z['enum'](['leader','challenger']),'phase':z['number']()['int']()['min'](0x1)['max'](0x3),'machine_shape':z['array'](MachineNodeSchema)['min'](0x1),'guards':z['array'](GuardRefSchema),'allocator':AllocatorSchema,'fee_params':z['record'](z['string'](),z['union']([z['number'](),z['string']()])),'trust_mechanisms':z['array'](z['string']()),'keeper_dependencies':z['array'](z['string']()),'keeper_duty':z['array'](z['object']({'when':z['string']()['min'](0x1),'action':z['string']()['min'](0x1),'miss_consequence':z['string']()['min'](0x1)})['strict']())['optional'](),'recommended_role':z['enum'](['merchant','supplier','both']),'role_rationale':z['string']()['min'](0x1),'differences':z['array'](z['string']()),'user_inputs':z['array'](z['string']()),'key_risk':z['string']()['min'](0x1)['max'](0x12c,'key_risk\x20must\x20be\x20a\x20one-line\x20risk\x20statement\x20(<=\x20300\x20chars)\x20—\x20rules\x20and\x20doctrine\x20do\x20not\x20belong\x20in\x20this\x20field')['refine'](a=>!/STANDING RULE|TECHNOLOGY PROVIDER|NOT A PARTY TO THE DEAL|Full text:/i['test'](a),{'message':'key_risk\x20carries\x20an\x20instruction-block\x20fragment\x20(STANDING\x20RULE\x20/\x20provider\x20doctrine\x20/\x20\x27Full\x20text:\x27\x20reference)\x20—\x20keep\x20doctrine\x20in\x20body\x20prose\x20or\x20playbooks,\x20not\x20in\x20this\x20field'}),'build_notes':z['array'](z['string']()),'prose_language':z['enum'](['en','other'])['optional'](),'machine_prose':z['record'](z['string'](),MachineProseEnvelopeSchema)['optional'](),'evidence_refs':z['array'](z['string']())['optional'](),'conditional_guards':z['array'](ConditionalGuardEmissionSchema)['optional'](),'time_anchors':z['record'](z['string'](),z['string']())['optional'](),'payment_model':z['enum'](['milestone','subscription','escrow'])['optional'](),'arbitration_mode':z['enum'](['none','merchant_pick','mutual_pick','third_party'])['optional'](),'reward_claim_policy':z['object']({'kind':z['enum'](['once','periodic','capped']),'min_claim_interval_ms':z['number']()['optional'](),'max_total_per_recipient':z['string']()['optional']()})['optional'](),'review_mode':z['enum'](['none','review','review_reward'])['optional'](),'after_sales_mode':z['enum'](['none','return','exchange','warranty'])['optional'](),'acceptance_mode':z['enum'](['none','milestone','contest','bounty','agent'])['optional'](),'installment_mode':z['enum'](['none','deposit_balance','milestone_n'])['optional'](),'affiliate_mode':z['enum'](['none','commission'])['optional'](),'crowdfunding_mode':z['enum'](['none','threshold','flexible'])['optional'](),'logistics_mode':z['enum'](['none','carrier','merchant_managed','courier','pickup_point'])['optional'](),'compensation_fund_policy':z['enum'](['allowed','forbidden'])['optional'](),'reentry_kind':z['enum'](['none','review-loop','paid-cycle'])['optional']()})['strict']();import{validateAllocatorRows}from'./template-validation.js';export{validateAllocatorRows};export function platformShareBps(a){const b=Object['keys'](a)['find'](c=>/(?:platform|commission|service_fee)[a-z_]*_bps$/['test'](c)&&!/^attributed_/['test'](c)&&!/_cap_bps$/['test'](c)&&typeof a[c]==='number');return b!==undefined?a[b]:undefined;}export const PLATFORM_TAKE_KEY=/^(?:platform_(?:share|commission|take|tool_fee)_bps|platform_fee_rate_bps|commission_rate_bps|(?:base_)?commission_rate_bps|offsite_ads_rate_bps|service_fee_rate_bps|payment_fee_bps)$/;export function parseTemplateFile(a){const b=a['replace'](/^\uFEFF/,'')['replace'](/^<!-- builtin:[a-z0-9-]+:v\d+:[0-9a-f]+ -->\r?\n/,''),c=b['split'](/\r?\n/);if(c[0x0]?.['trim']()!=='---')throw new Error('template\x20must\x20start\x20with\x20a\x20\x27---\x27\x20frontmatter\x20block');let d=-0x1;for(let f=0x1;f<c['length'];f++){if(c[f]['trim']()==='---'){d=f;break;}}if(d===-0x1)throw new Error('unterminated\x20frontmatter\x20block\x20(missing\x20closing\x20\x27---\x27)');const e={};for(let g=0x1;g<d;g++){const h=c[g];if(!h['trim']()||h['trim']()['startsWith']('#'))continue;const j=h['indexOf'](':');if(j===-0x1)throw new Error('invalid\x20frontmatter\x20line\x20'+(g+0x1)+':\x20\x27'+h['trim']()+'\x27\x20(expected\x20\x27key:\x20value\x27)');const k=h['slice'](0x0,j)['trim'](),l=h['slice'](j+0x1)['trim']();if(!k)throw new Error('invalid\x20frontmatter\x20line\x20'+(g+0x1)+':\x20empty\x20key');if(l['startsWith']('[')||l['startsWith']('{'))try{e[k]=JSON['parse'](l);}catch(m){throw new Error('frontmatter\x20key\x20\x27'+k+'\x27\x20is\x20not\x20valid\x20JSON:\x20'+m['message']);}else{if(/^-?\d+(\.\d+)?$/['test'](l))e[k]=Number(l);else{if(l['startsWith']('\x22')&&l['endsWith']('\x22')&&l['length']>=0x2||l['startsWith']('\x27')&&l['endsWith']('\x27')&&l['length']>=0x2){if(l[0x0]==='\x22')try{e[k]=JSON['parse'](l);}catch(n){throw new Error('frontmatter\x20key\x20\x27'+k+'\x27\x20is\x20not\x20valid\x20JSON:\x20'+n['message']);}else e[k]=l['slice'](0x1,-0x1);}else e[k]=l;}}}return{'frontmatter':e,'body':c['slice'](d+0x1)['join']('\x0a')['trim']()};}function frontmatterLine(a,b){if(typeof b==='number')return a+':\x20'+b;if(typeof b==='string')return a+':\x20'+b;return a+':\x20'+JSON['stringify'](b);}export const TEMPLATE_SENTINEL_KIND='industry-template';export function canonicalTemplateContent(a){const b=a,c=[['id',a['id']],['industry',a['industry']],['variant',a['variant']],['product_ref',a['product_ref']],['archetype',a['archetype']],['phase',a['phase']],['recommended_role',a['recommended_role']],['role_rationale',a['role_rationale']],['key_risk',a['key_risk']],['machine_shape',a['machine_shape']],['guards',a['guards']],['allocator',a['allocator']],['fee_params',a['fee_params']],['trust_mechanisms',a['trust_mechanisms']],['keeper_dependencies',a['keeper_dependencies']],...a['keeper_duty']?[['keeper_duty',a['keeper_duty']]]:[],['differences',a['differences']],['user_inputs',a['user_inputs']],['build_notes',a['build_notes']],...b['prose_language']?[['prose_language',b['prose_language']]]:[],...b['machine_prose']?[['machine_prose',b['machine_prose']]]:[],...a['evidence_refs']?[['evidence_refs',a['evidence_refs']]]:[],...a['conditional_guards']?[['conditional_guards',a['conditional_guards']]]:[],...a['time_anchors']?[['time_anchors',a['time_anchors']]]:[],...a['payment_model']?[['payment_model',a['payment_model']]]:[],...a['arbitration_mode']?[['arbitration_mode',a['arbitration_mode']]]:[],...a['review_mode']?[['review_mode',a['review_mode']]]:[],...a['after_sales_mode']?[['after_sales_mode',a['after_sales_mode']]]:[],...a['acceptance_mode']?[['acceptance_mode',a['acceptance_mode']]]:[],...a['installment_mode']?[['installment_mode',a['installment_mode']]]:[],...a['affiliate_mode']?[['affiliate_mode',a['affiliate_mode']]]:[],...a['crowdfunding_mode']?[['crowdfunding_mode',a['crowdfunding_mode']]]:[],...a['logistics_mode']?[['logistics_mode',a['logistics_mode']]]:[],...a['reward_claim_policy']?[['reward_claim_policy',a['reward_claim_policy']]]:[],...a['compensation_fund_policy']?[['compensation_fund_policy',a['compensation_fund_policy']]]:[],...a['reentry_kind']&&a['reentry_kind']!=='none'?[['reentry_kind',a['reentry_kind']]]:[]],d=['---',...c['map'](([f,g])=>frontmatterLine(f,g)),'---'],e=['','#\x20'+a['industry']+'\x20/\x20'+a['variant']+'\x20('+a['archetype']+')','','>\x20Industry\x20archetype\x20template.\x20Editable\x20and\x20migratable:\x20the\x20frontmatter\x20is','>\x20zod-validated\x20on\x20every\x20load;\x20the\x20body\x20is\x20free-form\x20guidance\x20for\x20the\x20AI.','','##\x20Key\x20risk','',a['key_risk'],'','##\x20Differences\x20vs\x20the\x20sibling\x20variant','',...a['differences']['map'](f=>'-\x20'+f),'','##\x20User\x20inputs\x20(inject\x20at\x20build\x20time)','',...a['user_inputs']['map'](f=>'-\x20'+f),'','##\x20Risk-avoidance\x20checklist\x20(R1-R10)','',...a['trust_mechanisms']['map'](f=>'-\x20'+f),'','##\x20Build\x20notes','',...a['build_notes']['map'](f=>'-\x20'+f),''];return[...d,...e]['join']('\x0a');}export function renderTemplateFile(a){const b=canonicalTemplateContent(a);return releaseSentinelLine(TEMPLATE_SENTINEL_KIND,BUILTIN_TEMPLATES_VERSION,releaseBodyHash(b))+'\x0a'+b;}export function matchBuiltinTemplateFile(a){const b=relative(resolveTemplatesDir(),a);if(!b||b['startsWith']('..'))return null;const c=b['split'](sep);if(c['length']!==0x3||c[0x1]!==TEMPLATES_SUBDIR||!c[0x2]['endsWith']('.md'))return null;const d=c[0x2]['slice'](0x0,-'.md'['length']);return BUILTIN_TEMPLATES['find'](e=>e['industry']===c[0x0]&&e['variant']===d)??null;}let seeded=![];function migrateLegacyTemplates(a){const b=resolveLegacyTemplatesDir();if(b===a)return;if(!existsSync(b))return;try{for(const c of readdirSync(b,{'withFileTypes':!![]})){if(!c['isDirectory']())continue;const d=join(b,c['name']),e=join(a,c['name'],TEMPLATES_SUBDIR);for(const g of readdirSync(d,{'withFileTypes':!![]})){if(!g['isFile']()||!g['name']['endsWith']('.md'))continue;const h=join(e,g['name']);if(existsSync(h))continue;mkdirSync(e,{'recursive':!![]}),renameSync(join(d,g['name']),h);}try{rmdirSync(d);}catch{}}try{rmdirSync(b);}catch{}}catch{}}export function seedBuiltinTemplates(){const a=[],b=resolveTemplatesDir();migrateLegacyTemplates(b);for(const c of BUILTIN_TEMPLATES){const d=join(b,c['industry'],TEMPLATES_SUBDIR),e=join(d,c['variant']+'.md'),f=canonicalTemplateContent(c),g={'template':c['id'],'status':'written','path':e};try{if(!existsSync(e))mkdirSync(d,{'recursive':!![]}),writeFileSync(e,renderTemplateFile(c),'utf-8');else{const h=readFileSync(e,'utf-8'),{sentinel:i,content:j}=stripReleaseSentinel(h,TEMPLATE_SENTINEL_KIND);!i?j===f?(writeFileSync(e,renderTemplateFile(c),'utf-8'),g['status']='restamped',g['detail']='body\x20matches\x20canonical\x20but\x20no\x20sentinel\x20present;\x20sentinel\x20header\x20added,\x20body\x20untouched'):(g['status']='skipped_user_file',g['detail']='template\x20file\x20exists\x20without\x20builtin\x20sentinel\x20and\x20body\x20differs\x20from\x20canonical;\x20leaving\x20user\x20file\x20untouched'):j===f?i['version']!==BUILTIN_TEMPLATES_VERSION||releaseBodyHash(j)!==i['hash']?(writeFileSync(e,renderTemplateFile(c),'utf-8'),g['status']='restamped',g['detail']='body\x20matches\x20canonical\x20but\x20sentinel\x20stale/wrong;\x20header\x20refreshed,\x20body\x20untouched'):g['status']='current':(g['status']='skipped_modified',g['detail']='body\x20differs\x20from\x20canonical;\x20not\x20overwritten\x20by\x20seeding\x20—\x20use\x20repair_builtin_templates\x20(preview→confirm)\x20to\x20reseed');}}catch(k){g['status']='error',g['detail']=k['message'];}a['push'](g);}return a;}export function summarizeTemplateDiff(a,b){let c,d;try{c=parseTemplateFile(a);}catch(g){return'on-disk\x20file\x20is\x20not\x20parseable\x20('+g['message']+');\x20full\x20content\x20will\x20be\x20replaced';}try{d=parseTemplateFile(b);}catch{return'canonical\x20render\x20is\x20not\x20parseable\x20(code\x20defect);\x20full\x20content\x20will\x20be\x20replaced';}const e=[],f=new Set([...Object['keys'](c['frontmatter']),...Object['keys'](d['frontmatter'])]);for(const h of[...f]['sort']()){const i=h in c['frontmatter'],j=h in d['frontmatter'];if(i&&!j)e['push']('-'+h);else{if(!i&&j)e['push']('+'+h);else{if(JSON['stringify'](c['frontmatter'][h])!==JSON['stringify'](d['frontmatter'][h]))e['push']('~'+h);}}}return c['body']!==d['body']&&e['push']('~body\x20('+c['body']['split']('\x0a')['length']+'\x20->\x20'+d['body']['split']('\x0a')['length']+'\x20lines)'),e['length']>0x0?e['join'](',\x20'):'whitespace/ordering\x20only';}export function repairBuiltinTemplates(a){const b=[],c=resolveTemplatesDir(),d=a?.['backup']!==![],e=a?.['dryRun']===!![],f=new Set(a?.['includeUserEdited']??[]);for(const g of BUILTIN_TEMPLATES){const h=join(c,g['industry'],TEMPLATES_SUBDIR),i=join(h,g['variant']+'.md');if(!existsSync(i))continue;const j=canonicalTemplateContent(g);let k=null,l='';const m={'template':g['id'],'status':'would_update','path':i};try{const p=stripReleaseSentinel(readFileSync(i,'utf-8'),TEMPLATE_SENTINEL_KIND);k=p['sentinel'],l=p['content'];}catch(q){m['status']='error',m['detail']=q['message'],b['push'](m);continue;}if(l===j)continue;let n;if(k){if(k['version']>BUILTIN_TEMPLATES_VERSION){m['status']='error',m['detail']='newer\x20release\x20on\x20disk\x20(sentinel\x20v'+k['version']+'\x20>\x20running\x20catalog\x20v'+BUILTIN_TEMPLATES_VERSION+')\x20—\x20'+'repair\x20would\x20DOWNGRADE\x20and\x20lose\x20the\x20newer\x20release\x27s\x20content;\x20refused.\x20Upgrade\x20the\x20MCP\x20server\x20instead',b['push'](m);continue;}if(releaseBodyHash(l)!==k['hash']){if(!f['has'](g['id']))continue;n='sentinel-body\x20hash\x20mismatch\x20(sentinel\x20v'+k['version']+'\x20no\x20longer\x20binds\x20the\x20body)\x20'+'reseeded\x20under\x20EXPLICIT\x20include_user_edited\x20authorization';}else n='untouched\x20older\x20release\x20(sentinel\x20v'+k['version']+',\x20current\x20v'+BUILTIN_TEMPLATES_VERSION+')';}else{let r;try{r=String(parseTemplateFile(l)['frontmatter']['id']??'');}catch{continue;}if(r!==g['id'])continue;n='legacy\x20sentinel-less\x20builtin\x20file';}const o=summarizeTemplateDiff(l,j);if(e){m['status']='would_update',m['detail']=n+'\x20would\x20be\x20reseeded\x20from\x20BUILTIN_TEMPLATES\x20('+g['id']+')\x20—\x20diff\x20vs\x20canonical:\x20'+o+(d?';\x20previous\x20body\x20would\x20be\x20saved\x20as\x20<file>.bak':'')+'\x20—\x20execute\x20with\x20authorize=true\x20after\x20the\x20user\x20explicitly\x20confirms',b['push'](m);continue;}try{if(d)copyFileSync(i,i+'.bak');writeFileSync(i,renderTemplateFile(g),'utf-8'),cache['delete'](i),m['status']='updated',m['detail']=n+'\x20reseeded\x20from\x20BUILTIN_TEMPLATES\x20('+g['id']+')\x20—\x20diff\x20was:\x20'+o+(d?';\x20previous\x20body\x20saved\x20as\x20<file>.bak':'');}catch(s){m['status']='error',m['detail']=s['message'];}b['push'](m);}return b;}export function builtinTemplateDrift(a){const b=new Set(a?.['includeUserEdited']??[]),c=[],d=resolveTemplatesDir();for(const e of BUILTIN_TEMPLATES){const f=join(d,e['industry'],TEMPLATES_SUBDIR,e['variant']+'.md');if(!existsSync(f)){c['push']({'template':e['id'],'path':f,'state':'missing','repairable':!![],'detail':'no\x20file\x20on\x20disk;\x20seeding\x20will\x20create\x20it'});continue;}const g=canonicalTemplateContent(e);let h=null,i='';try{const k=stripReleaseSentinel(readFileSync(f,'utf-8'),TEMPLATE_SENTINEL_KIND);h=k['sentinel'],i=k['content'];}catch(l){c['push']({'template':e['id'],'path':f,'state':'modified','repairable':![],'detail':'unreadable:\x20'+l['message']});continue;}if(i===g)continue;const j=summarizeTemplateDiff(i,g);if(!h){let m;try{m=String(parseTemplateFile(i)['frontmatter']['id']??'');}catch{m=undefined;}m===e['id']?c['push']({'template':e['id'],'path':f,'state':'modified','repairable':!![],'detail':'legacy\x20sentinel-less\x20builtin\x20file\x20—\x20seeding\x20never\x20rewrites\x20it\x20and\x20no\x20sentinel\x20proves\x20provenance;\x20repair\x20can\x20reseed\x20—\x20diff\x20vs\x20canonical:\x20'+j}):c['push']({'template':e['id'],'path':f,'state':'modified','repairable':![],'detail':'no\x20release\x20sentinel\x20and\x20id\x20\x27'+(m??'<unparseable>')+'\x27\x20does\x20not\x20match\x20the\x20builtin\x20id\x20—\x20a\x20user\x20file\x20occupies\x20this\x20path;\x20never\x20touched\x20(rename\x20it\x20to\x20free\x20the\x20slot)'});continue;}if(releaseBodyHash(i)===h['hash'])h['version']>BUILTIN_TEMPLATES_VERSION?c['push']({'template':e['id'],'path':f,'state':'modified','repairable':![],'detail':'newer\x20release\x20(sentinel\x20v'+h['version']+'\x20>\x20running\x20catalog\x20v'+BUILTIN_TEMPLATES_VERSION+')\x20—\x20'+'repair\x20would\x20DOWNGRADE\x20and\x20lose\x20the\x20newer\x20release\x27s\x20content;\x20repairable:\x20false.\x20'+'Upgrade\x20the\x20MCP\x20server\x20to\x20match\x20—\x20diff\x20vs\x20canonical:\x20'+j}):c['push']({'template':e['id'],'path':f,'state':'modified','repairable':!![],'detail':'untouched\x20older\x20release\x20(sentinel\x20v'+h['version']+',\x20current\x20v'+BUILTIN_TEMPLATES_VERSION+')\x20—\x20repair\x20can\x20upgrade\x20—\x20diff\x20vs\x20canonical:\x20'+j});else{const n=b['has'](e['id']);c['push']({'template':e['id'],'path':f,'state':'modified','repairable':n,'detail':n?'sentinel-body\x20hash\x20mismatch\x20(sentinel\x20v'+h['version']+'\x20no\x20longer\x20binds\x20the\x20body)\x20—\x20reseedable\x20under\x20the\x20explicit\x20include_user_edited\x20authorization\x20for\x20this\x20id\x20—\x20diff\x20vs\x20canonical:\x20'+j:'user-edited\x20body\x20—\x20kept\x20by\x20design;\x20repair\x20never\x20overwrites\x20user\x20edits\x20—\x20diff\x20vs\x20canonical:\x20'+j});}}return c;}const cache=new Map();export function reloadTemplates(){cache['clear'](),seeded=![];}export function loadAndValidate(a){const b=readFileSync(a,'utf-8');let c;try{c=parseTemplateFile(b);}catch(f){throw new Error('template\x20\x27'+a+'\x27\x20failed\x20to\x20parse:\x20'+f['message']);}const d=TemplateFrontmatterSchema['safeParse'](c['frontmatter']);if(!d['success']){const g=d['error']['issues']['map'](h=>(h['path']['join']('.')||'<root>')+':\x20'+h['message'])['join'](';\x20');throw new Error('template\x20\x27'+a+'\x27\x20failed\x20validation:\x20'+g);}const e=validateAllocatorRows(d['data']);if(e['length']>0x0)throw new Error('template\x20\x27'+a+'\x27\x20failed\x20allocator-row\x20validation:\x20'+e['join'](';\x20'));return{...d['data'],'body':c['body'],'source_path':a};}function templateFilesOnDisk(a){const b=[];if(!existsSync(a))return b;for(const c of readdirSync(a,{'withFileTypes':!![]})){if(!c['isDirectory']())continue;const d=join(a,c['name'],TEMPLATES_SUBDIR);if(!existsSync(d))continue;for(const e of readdirSync(d,{'withFileTypes':!![]})){if(e['isFile']()&&e['name']['endsWith']('.md'))b['push'](join(d,e['name']));}}return b['sort']();}export function listTemplates(){!seeded&&(seedBuiltinTemplates(),seeded=!![]);const a=resolveTemplatesDir(),b=[],c=[],d=new Set();for(const e of templateFilesOnDisk(a)){d['add'](e);try{const f=statSync(e)['mtimeMs'],g=cache['get'](e);if(g&&g['mtimeMs']===f){b['push'](g['template']);continue;}const h=loadAndValidate(e);cache['set'](e,{'mtimeMs':f,'template':h}),b['push'](h);}catch(i){cache['delete'](e),c['push'](i['message']);}}for(const j of[...cache['keys']()]){if(!d['has'](j))cache['delete'](j);}return b['sort']((k,l)=>k['id']['localeCompare'](l['id'])),{'templates':b,'errors':c};}export function getTemplate(a){return listTemplates()['templates']['find'](b=>b['id']===a);}export function getTemplatesByIndustry(a){return listTemplates()['templates']['filter'](b=>b['industry']===a);}
1
+ import{copyFileSync,existsSync,mkdirSync,readdirSync,readFileSync,rmSync,statSync,writeFileSync}from'node:fs';import{dirname,join,relative,sep}from'node:path';import{z}from'zod';import{getWowokIndustryDir}from'@wowok/wowok';import{SUPPORTED_INDUSTRIES}from'../customer/user-preferences.js';import{isRegisteredIndustry}from'./industry-registry.js';import{BUILTIN_TEMPLATES,BUILTIN_TEMPLATES_VERSION}from'./builtin-templates.js';import{knobDocLines}from'./knob-docs.js';import{MachineProseEnvelopeSchema}from'./template-prose.js';import{INDUSTRY_NAV_FILENAME,classifyIndustryNav,renderIndustryNav}from'./template-nav.js';import{classifyRelease,releaseBodyHash,releaseSentinelLine,stripReleaseSentinel}from'./release-sentinel.js';export const TEMPLATES_SUBDIR='templates';export const MACHINE_TEMPLATES_SUBDIR='.machine';export const TEMPLATE_ARCHIVE_SUBDIR='.archive';export function resolveTemplatesDir(){return process['env']['WOWOK_TEMPLATES_DIR']||getWowokIndustryDir();}const MachineEdgeSchema=z['object']({'prev':z['string'](),'forward':z['string']()['min'](0x1)['optional'](),'operator':z['enum'](['merchant','order_payer'])['optional'](),'named_operator':z['string']()['min'](0x1)['optional'](),'permission_index':z['number']()['int']()['min'](0x3e8)['optional'](),'guard_key':z['string']()['min'](0x1)['optional']()}),MachineNodeSchema=z['object']({'name':z['string']()['min'](0x1),'role':z['string']()['min'](0x1),'operator':z['enum'](['merchant','order_payer'])['optional'](),'named_operator':z['string']()['min'](0x1)['optional'](),'semantic_role':z['enum'](['draft','active','delivered','final','cancelled'])['optional'](),'optional':z['boolean']()['optional'](),'threshold':z['number']()['int']()['min'](0x0)['optional'](),'from':z['array'](z['union']([z['string'](),MachineEdgeSchema]))['optional']()}),GuardRefSchema=z['object']({'template_id':z['string']()['regex'](/^(pattern\.[a-z0-9_]+|tpl_[a-z0-9_]+)$/,'guard\x20template_id\x20must\x20be\x20a\x20\x27pattern.*\x27\x20design\x20pattern\x20or\x20\x27tpl_*\x27\x20guard\x20template'),'host':z['enum'](['service','machine','reward','repository','arbitration']),'purpose':z['string']()['min'](0x1),'key':z['string']()['min'](0x1)['optional'](),'policy':z['object']({'name':z['string']()['min'](0x1)['optional'](),'description':z['string']()['min'](0x1)['optional'](),'id_from':z['string']()['min'](0x1)['optional'](),'value_type':z['string']()['min'](0x1)['optional']()})['optional'](),'params':z['record'](z['string'](),z['unknown']())['optional']()}),ConditionalGuardEmissionSchema=z['object']({'guard_key':z['string']()['min'](0x1),'param':z['string']()['min'](0x1),'values':z['array'](z['string']()['min'](0x1))['min'](0x2),'emit_value':z['string']()['min'](0x1),'question':z['string']()['min'](0x1)})['strict'](),AllocatorRowSchema=z['object']({'track':z['enum'](['settlement','refund']),'recipient':z['enum'](['entity','guard_identifier','signer']),'recipient_key':z['string']()['min'](0x1)['optional'](),'mode':z['enum'](['amount','rate','surplus']),'value':z['union']([z['string'](),z['number']()])['optional'](),'value_from':z['string']()['optional'](),'value_from_complement':z['string']()['min'](0x1)['optional'](),'repeat_from':z['string']()['min'](0x1)['optional'](),'fix':z['union']([z['string'](),z['number']()])['optional'](),'fix_from':z['string']()['optional'](),'guard_key':z['string']()['min'](0x1)['optional'](),'note':z['string']()['optional']()})['strict'](),AllocatorSchema=z['object']({'recipient':z['enum'](['signer','entity','fixed']),'recipient_key':z['string']()['min'](0x1)['optional'](),'refund_track':z['enum'](['order_anchored'])['optional'](),'count':z['number']()['int']()['positive'](),'mode':z['enum'](['amount','rate','surplus']),'once_per_order':z['boolean']()['optional'](),'rows':z['array'](AllocatorRowSchema)['optional'](),'description':z['string']()['min'](0x1)})['strict'](),IndustryNameSchema=z['string']()['regex'](/^[a-z][a-z0-9_]*$/,'industry\x20must\x20be\x20lowercase\x20snake_case\x20(a-z,\x200-9,\x20_)')['refine'](a=>isRegisteredIndustry(a),{'message':'unknown\x20industry\x20—\x20register\x20it\x20first\x20via\x20an\x20industry\x20pack\x20'+'(industry_pack_operation\x20action=\x27scaffold\x27)\x20or\x20the\x20industry\x20generalizer;\x20'+('builtin\x20industries:\x20'+SUPPORTED_INDUSTRIES['join'](',\x20'))});export const TemplateFrontmatterSchema=z['object']({'id':z['string']()['regex'](/^[a-z][a-z0-9_-]*\/[a-z][a-z0-9_-]*$/,'id\x20must\x20be\x20\x27<industry>/<variant>\x27'),'industry':IndustryNameSchema,'variant':z['string']()['regex'](/^[a-z][a-z0-9_-]*$/),'product_ref':z['string']()['regex'](/^[a-z][a-z0-9._-]*$/,'product_ref\x20must\x20be\x20a\x20lowercase\x20product\x20slug')['optional'](),'archetype':z['enum'](['leader','challenger']),'phase':z['number']()['int']()['min'](0x1)['max'](0x3),'machine_shape':z['array'](MachineNodeSchema)['min'](0x1),'guards':z['array'](GuardRefSchema),'allocator':AllocatorSchema,'fee_params':z['record'](z['string'](),z['union']([z['number'](),z['string']()])),'trust_mechanisms':z['array'](z['string']()),'keeper_dependencies':z['array'](z['string']()),'keeper_duty':z['array'](z['object']({'when':z['string']()['min'](0x1),'action':z['string']()['min'](0x1),'miss_consequence':z['string']()['min'](0x1)})['strict']())['optional'](),'recommended_role':z['enum'](['merchant','supplier','both']),'role_rationale':z['string']()['min'](0x1),'differences':z['array'](z['string']()),'user_inputs':z['array'](z['string']()),'key_risk':z['string']()['min'](0x1)['max'](0x12c,'key_risk\x20must\x20be\x20a\x20one-line\x20risk\x20statement\x20(<=\x20300\x20chars)\x20—\x20rules\x20and\x20doctrine\x20do\x20not\x20belong\x20in\x20this\x20field')['refine'](a=>!/STANDING RULE|TECHNOLOGY PROVIDER|NOT A PARTY TO THE DEAL|Full text:/i['test'](a),{'message':'key_risk\x20carries\x20an\x20instruction-block\x20fragment\x20(STANDING\x20RULE\x20/\x20provider\x20doctrine\x20/\x20\x27Full\x20text:\x27\x20reference)\x20—\x20keep\x20doctrine\x20in\x20body\x20prose\x20or\x20playbooks,\x20not\x20in\x20this\x20field'}),'build_notes':z['array'](z['string']()),'prose_language':z['enum'](['en','other'])['optional'](),'machine_prose':z['record'](z['string'](),MachineProseEnvelopeSchema)['optional'](),'evidence_refs':z['array'](z['string']())['optional'](),'conditional_guards':z['array'](ConditionalGuardEmissionSchema)['optional'](),'time_anchors':z['record'](z['string'](),z['string']())['optional'](),'payment_model':z['enum'](['milestone','subscription','escrow'])['optional'](),'arbitration_mode':z['enum'](['none','merchant_pick','mutual_pick','third_party'])['optional'](),'reward_claim_policy':z['object']({'kind':z['enum'](['once','periodic','capped']),'min_claim_interval_ms':z['number']()['optional'](),'max_total_per_recipient':z['string']()['optional']()})['optional'](),'review_mode':z['enum'](['none','review','review_reward'])['optional'](),'after_sales_mode':z['enum'](['none','return','exchange','warranty'])['optional'](),'acceptance_mode':z['enum'](['none','milestone','contest','bounty','agent'])['optional'](),'installment_mode':z['enum'](['none','deposit_balance','milestone_n'])['optional'](),'affiliate_mode':z['enum'](['none','commission'])['optional'](),'crowdfunding_mode':z['enum'](['none','threshold','flexible'])['optional'](),'logistics_mode':z['enum'](['none','carrier','merchant_managed','courier','pickup_point'])['optional'](),'compensation_fund_policy':z['enum'](['allowed','forbidden'])['optional'](),'reentry_kind':z['enum'](['none','review-loop','paid-cycle'])['optional'](),'settlement_window_merge':z['array'](z['string']())['optional']()})['strict']();import{validateAllocatorRows}from'./template-validation.js';export{validateAllocatorRows};export function platformShareBps(a){const b=Object['keys'](a)['find'](c=>/(?:platform|commission|service_fee)[a-z_]*_bps$/['test'](c)&&!/^attributed_/['test'](c)&&!/_cap_bps$/['test'](c)&&typeof a[c]==='number');return b!==undefined?a[b]:undefined;}export const PLATFORM_TAKE_KEY=/^(?:platform_(?:share|commission|take|tool_fee)_bps|platform_fee_rate_bps|commission_rate_bps|(?:base_)?commission_rate_bps|offsite_ads_rate_bps|service_fee_rate_bps|payment_fee_bps)$/;export function parseTemplateFile(a){const b=a['replace'](/^\uFEFF/,'')['replace'](/^<!-- builtin:[a-z0-9-]+:v\d+:[0-9a-f]+ -->\r?\n/,''),c=b['split'](/\r?\n/);if(c[0x0]?.['trim']()!=='---')throw new Error('template\x20must\x20start\x20with\x20a\x20\x27---\x27\x20frontmatter\x20block');let d=-0x1;for(let f=0x1;f<c['length'];f++){if(c[f]['trim']()==='---'){d=f;break;}}if(d===-0x1)throw new Error('unterminated\x20frontmatter\x20block\x20(missing\x20closing\x20\x27---\x27)');const e={};for(let g=0x1;g<d;g++){const h=c[g];if(!h['trim']()||h['trim']()['startsWith']('#'))continue;const j=h['indexOf'](':');if(j===-0x1)throw new Error('invalid\x20frontmatter\x20line\x20'+(g+0x1)+':\x20\x27'+h['trim']()+'\x27\x20(expected\x20\x27key:\x20value\x27)');const k=h['slice'](0x0,j)['trim'](),l=h['slice'](j+0x1)['trim']();if(!k)throw new Error('invalid\x20frontmatter\x20line\x20'+(g+0x1)+':\x20empty\x20key');if(l['startsWith']('[')||l['startsWith']('{'))try{e[k]=JSON['parse'](l);}catch(m){throw new Error('frontmatter\x20key\x20\x27'+k+'\x27\x20is\x20not\x20valid\x20JSON:\x20'+m['message']);}else{if(/^-?\d+(\.\d+)?$/['test'](l))e[k]=Number(l);else{if(l['startsWith']('\x22')&&l['endsWith']('\x22')&&l['length']>=0x2||l['startsWith']('\x27')&&l['endsWith']('\x27')&&l['length']>=0x2){if(l[0x0]==='\x22')try{e[k]=JSON['parse'](l);}catch(n){throw new Error('frontmatter\x20key\x20\x27'+k+'\x27\x20is\x20not\x20valid\x20JSON:\x20'+n['message']);}else e[k]=l['slice'](0x1,-0x1);}else e[k]=l;}}}return{'frontmatter':e,'body':c['slice'](d+0x1)['join']('\x0a')['trim']()};}function frontmatterLine(a,b){if(typeof b==='number')return a+':\x20'+b;if(typeof b==='string')return a+':\x20'+b;return a+':\x20'+JSON['stringify'](b);}export const TEMPLATE_SENTINEL_KIND='industry-template';export function canonicalTemplateContent(a){const b=a,c=[['id',a['id']],['industry',a['industry']],['variant',a['variant']],['product_ref',a['product_ref']],['archetype',a['archetype']],['phase',a['phase']],['recommended_role',a['recommended_role']],['role_rationale',a['role_rationale']],['key_risk',a['key_risk']],['machine_shape',a['machine_shape']],['guards',a['guards']],['allocator',a['allocator']],['fee_params',a['fee_params']],['trust_mechanisms',a['trust_mechanisms']],['keeper_dependencies',a['keeper_dependencies']],...a['keeper_duty']?[['keeper_duty',a['keeper_duty']]]:[],['differences',a['differences']],['user_inputs',a['user_inputs']],['build_notes',a['build_notes']],...b['prose_language']?[['prose_language',b['prose_language']]]:[],...b['machine_prose']?[['machine_prose',b['machine_prose']]]:[],...a['evidence_refs']?[['evidence_refs',a['evidence_refs']]]:[],...a['conditional_guards']?[['conditional_guards',a['conditional_guards']]]:[],...a['time_anchors']?[['time_anchors',a['time_anchors']]]:[],...a['payment_model']?[['payment_model',a['payment_model']]]:[],...a['arbitration_mode']?[['arbitration_mode',a['arbitration_mode']]]:[],...a['review_mode']?[['review_mode',a['review_mode']]]:[],...a['after_sales_mode']?[['after_sales_mode',a['after_sales_mode']]]:[],...a['acceptance_mode']?[['acceptance_mode',a['acceptance_mode']]]:[],...a['installment_mode']?[['installment_mode',a['installment_mode']]]:[],...a['affiliate_mode']?[['affiliate_mode',a['affiliate_mode']]]:[],...a['crowdfunding_mode']?[['crowdfunding_mode',a['crowdfunding_mode']]]:[],...a['logistics_mode']?[['logistics_mode',a['logistics_mode']]]:[],...a['reward_claim_policy']?[['reward_claim_policy',a['reward_claim_policy']]]:[],...a['compensation_fund_policy']?[['compensation_fund_policy',a['compensation_fund_policy']]]:[],...a['reentry_kind']&&a['reentry_kind']!=='none'?[['reentry_kind',a['reentry_kind']]]:[],...a['settlement_window_merge']?[['settlement_window_merge',a['settlement_window_merge']]]:[]],d=['---',...c['map'](([f,g])=>frontmatterLine(f,g)),'---'],e=['','#\x20'+a['industry']+'\x20/\x20'+a['variant']+'\x20('+a['archetype']+')','','>\x20Industry\x20archetype\x20template.\x20Editable\x20and\x20migratable:\x20the\x20frontmatter\x20is','>\x20zod-validated\x20on\x20every\x20load;\x20the\x20body\x20is\x20free-form\x20guidance\x20for\x20the\x20AI.','','##\x20Key\x20risk','',a['key_risk'],'','##\x20Differences\x20vs\x20the\x20sibling\x20variant','',...a['differences']['map'](f=>'-\x20'+f),'','##\x20User\x20inputs\x20(inject\x20at\x20build\x20time)','',...a['user_inputs']['map'](f=>'-\x20'+f),'','##\x20Risk-avoidance\x20checklist\x20(R1-R10)','',...a['trust_mechanisms']['map'](f=>'-\x20'+f),'','##\x20Build\x20notes','',...a['build_notes']['map'](f=>'-\x20'+f),''];return[...d,...e]['join']('\x0a');}export function renderTemplateFile(a){const b=canonicalTemplateContent(a);return releaseSentinelLine(TEMPLATE_SENTINEL_KIND,BUILTIN_TEMPLATES_VERSION,releaseBodyHash(b))+'\x0a'+b;}export const TEMPLATE_KNOBS_SENTINEL_KIND='template-knobs';export const TEMPLATE_KNOBS_VERSION=0x3;export const TemplateKnobOverlaySchema=TemplateFrontmatterSchema['pick']({'fee_params':!![],'key_risk':!![],'recommended_role':!![],'role_rationale':!![],'differences':!![],'user_inputs':!![],'payment_model':!![],'arbitration_mode':!![],'review_mode':!![],'after_sales_mode':!![],'acceptance_mode':!![],'installment_mode':!![],'affiliate_mode':!![],'crowdfunding_mode':!![],'logistics_mode':!![],'reward_claim_policy':!![],'reentry_kind':!![],'compensation_fund_policy':!![]})['partial']()['extend']({'id':z['string']()['regex'](/^[a-z][a-z0-9._-]*\/[a-z][a-z0-9._-]*$/,'knob\x20file\x20id\x20must\x20be\x20\x27<industry>/<variant>\x27')})['strict']();export function foldKnobFrontmatter(a){const b={},c={};for(const [d,e]of Object['entries'](a)){d['startsWith']('fee_params.')?c[d['slice']('fee_params.'['length'])]=e:b[d]=e;}if(Object['keys'](c)['length']>0x0)b['fee_params']=c;return b;}export function parseKnobFile(a,b){const c=stripReleaseSentinel(a,TEMPLATE_KNOBS_SENTINEL_KIND);let d;try{const f=parseTemplateFile(c['sentinel']?c['content']:a);d=f['frontmatter'];}catch{return null;}const e=TemplateKnobOverlaySchema['safeParse'](foldKnobFrontmatter(d));if(!e['success']||e['data']['id']!==b)return null;return e['data'];}function knobLine(a,b){if(typeof b==='number')return a+':\x20'+b;if(typeof b==='string')return/^-?\d+(\.\d+)?$/['test'](b)?a+':\x20\x27'+b+'\x27':a+':\x20'+b;return a+':\x20'+JSON['stringify'](b);}export function canonicalKnobContent(a){const b=['id:\x20'+a['id'],knobLine('key_risk',a['key_risk']),knobLine('recommended_role',a['recommended_role']),knobLine('role_rationale',a['role_rationale']),...Object['keys'](a['fee_params'])['sort']()['flatMap'](d=>[...knobDocLines(d),knobLine('fee_params.'+d,a['fee_params'][d])]),...a['payment_model']!==undefined?[knobLine('payment_model',a['payment_model'])]:[],...a['arbitration_mode']!==undefined?[knobLine('arbitration_mode',a['arbitration_mode'])]:[],...a['review_mode']!==undefined?[knobLine('review_mode',a['review_mode'])]:[],...a['after_sales_mode']!==undefined?[knobLine('after_sales_mode',a['after_sales_mode'])]:[],...a['acceptance_mode']!==undefined?[knobLine('acceptance_mode',a['acceptance_mode'])]:[],...a['installment_mode']!==undefined?[knobLine('installment_mode',a['installment_mode'])]:[],...a['affiliate_mode']!==undefined?[knobLine('affiliate_mode',a['affiliate_mode'])]:[],...a['crowdfunding_mode']!==undefined?[knobLine('crowdfunding_mode',a['crowdfunding_mode'])]:[],...a['logistics_mode']!==undefined?[knobLine('logistics_mode',a['logistics_mode'])]:[],...a['reward_claim_policy']!==undefined?[knobLine('reward_claim_policy',a['reward_claim_policy'])]:[],...a['reentry_kind']!==undefined&&a['reentry_kind']!=='none'?[knobLine('reentry_kind',a['reentry_kind'])]:[],...a['compensation_fund_policy']!==undefined?[knobLine('compensation_fund_policy',a['compensation_fund_policy'])]:[],knobLine('differences',a['differences']),knobLine('user_inputs',a['user_inputs'])],c=['','#\x20'+a['industry']+'\x20/\x20'+a['variant']+'\x20('+a['archetype']+')\x20—\x20business\x20knobs','','>\x20THIS\x20file\x20is\x20the\x20one\x20you\x20edit.\x20Each\x20line\x20above\x20the\x20body\x20is\x20a\x20knob\x20the','>\x20build\x20honors:\x20`fee_params.<name>`\x20(numbers\x20—\x20pricing\x20windows,\x20caps,','>\x20pools),\x20the\x20mode\x20switches\x20(review/arbitration/logistics/...),\x20and\x20the','>\x20guidance\x20prose\x20below.\x20Lines\x20starting\x20with\x20`#`\x20are\x20read-only\x20docs\x20for','>\x20the\x20knob\x20line\x20below\x20them\x20—\x20edit\x20the\x20value\x20line,\x20never\x20the\x20`#`\x20lines','>\x20(docs\x20refresh\x20with\x20each\x20release).\x20The\x20workflow\x20structure\x20itself','>\x20(nodes,\x20guards,\x20fund\x20rails)\x20is\x20system-managed\x20in\x20a\x20hidden\x20`.machine/`','>\x20file\x20next\x20to\x20this\x20one\x20and\x20is\x20deliberately\x20not\x20exposed\x20—\x20change','>\x20business\x20intent\x20through\x20these\x20knobs\x20or\x20through\x20the\x20migration\x20wizard,','>\x20never\x20by\x20editing\x20node\x20graphs\x20by\x20hand.','','##\x20Key\x20risk','',a['key_risk'],'','##\x20Differences\x20vs\x20the\x20sibling\x20variant','',...a['differences']['map'](e=>'-\x20'+e),'','##\x20User\x20inputs\x20(inject\x20at\x20build\x20time)','',...a['user_inputs']['map'](d=>'-\x20'+d),'','##\x20Your\x20notes\x20(free-form\x20—\x20the\x20AI\x20reads\x20this\x20body\x20as\x20guidance)','','-\x20(Add\x20your\x20own\x20pricing,\x20tone,\x20or\x20policy\x20notes\x20below\x20—\x20they\x20override\x20the','\x20\x20generic\x20guidance\x20the\x20same\x20way\x20playbook.md\x20does.)',''];return['---',...b,'---',...c]['join']('\x0a');}export function renderKnobFile(a){const b=canonicalKnobContent(a);return releaseSentinelLine(TEMPLATE_KNOBS_SENTINEL_KIND,TEMPLATE_KNOBS_VERSION,releaseBodyHash(b))+'\x0a'+b;}export function classifyKnobFile(a,b){const c=stripReleaseSentinel(a,TEMPLATE_KNOBS_SENTINEL_KIND);if(!c['sentinel'])return null;if(parseKnobFile(c['content'],b)===null)return null;const d=classifyRelease(c['sentinel'],c['content'],TEMPLATE_KNOBS_VERSION);return d==='user_file'?null:d;}export function applyKnobOverlay(a,b,c){return{...a,...b['fee_params']!==undefined?{'fee_params':{...a['fee_params'],...b['fee_params']}}:{},...b['key_risk']!==undefined?{'key_risk':b['key_risk']}:{},...b['recommended_role']!==undefined?{'recommended_role':b['recommended_role']}:{},...b['role_rationale']!==undefined?{'role_rationale':b['role_rationale']}:{},...b['differences']!==undefined?{'differences':b['differences']}:{},...b['user_inputs']!==undefined?{'user_inputs':b['user_inputs']}:{},...b['payment_model']!==undefined?{'payment_model':b['payment_model']}:{},...b['arbitration_mode']!==undefined?{'arbitration_mode':b['arbitration_mode']}:{},...b['review_mode']!==undefined?{'review_mode':b['review_mode']}:{},...b['after_sales_mode']!==undefined?{'after_sales_mode':b['after_sales_mode']}:{},...b['acceptance_mode']!==undefined?{'acceptance_mode':b['acceptance_mode']}:{},...b['installment_mode']!==undefined?{'installment_mode':b['installment_mode']}:{},...b['affiliate_mode']!==undefined?{'affiliate_mode':b['affiliate_mode']}:{},...b['crowdfunding_mode']!==undefined?{'crowdfunding_mode':b['crowdfunding_mode']}:{},...b['logistics_mode']!==undefined?{'logistics_mode':b['logistics_mode']}:{},...b['reward_claim_policy']!==undefined?{'reward_claim_policy':b['reward_claim_policy']}:{},...b['reentry_kind']!==undefined?{'reentry_kind':b['reentry_kind']}:{},...b['compensation_fund_policy']!==undefined?{'compensation_fund_policy':b['compensation_fund_policy']}:{},'body':c};}function machineTemplateFile(a,b){return join(a,b['industry'],TEMPLATES_SUBDIR,MACHINE_TEMPLATES_SUBDIR,b['variant']+'.md');}function knobTemplateFile(a,b){return join(a,b['industry'],TEMPLATES_SUBDIR,b['variant']+'.md');}function archiveBackupFile(a,b,c){return join(a,b['industry'],TEMPLATES_SUBDIR,TEMPLATE_ARCHIVE_SUBDIR,''+b['variant']+c);}export function matchBuiltinTemplateSlot(a){const b=relative(resolveTemplatesDir(),a);if(!b||b['startsWith']('..'))return null;const c=b['split'](sep);if(c['length']===0x4&&c[0x1]===TEMPLATES_SUBDIR&&c[0x2]===MACHINE_TEMPLATES_SUBDIR&&c[0x3]['endsWith']('.md')){const d=c[0x3]['slice'](0x0,-'.md'['length']),e=BUILTIN_TEMPLATES['find'](f=>f['industry']===c[0x0]&&f['variant']===d)??null;return e?{'template':e,'part':'machine'}:null;}if(c['length']===0x3&&c[0x1]===TEMPLATES_SUBDIR&&c[0x2]['endsWith']('.md')){const f=c[0x2]['slice'](0x0,-'.md'['length']),g=BUILTIN_TEMPLATES['find'](h=>h['industry']===c[0x0]&&h['variant']===f)??null;return g?{'template':g,'part':'knobs'}:null;}return null;}export function matchBuiltinTemplateFile(a){return matchBuiltinTemplateSlot(a)?.['template']??null;}let seeded=![];export function seedBuiltinTemplates(){const a=[],b=resolveTemplatesDir();for(const c of BUILTIN_TEMPLATES){const d=machineTemplateFile(b,c),e=knobTemplateFile(b,c),f=dirname(d),g=canonicalTemplateContent(c),h={'template':c['id'],'status':'written','path':d};try{if(!existsSync(d))mkdirSync(f,{'recursive':!![]}),writeFileSync(d,renderTemplateFile(c),'utf-8');else{const i=readFileSync(d,'utf-8'),{sentinel:j,content:k}=stripReleaseSentinel(i,TEMPLATE_SENTINEL_KIND);!j?k===g?(writeFileSync(d,renderTemplateFile(c),'utf-8'),h['status']='restamped',h['detail']='body\x20matches\x20canonical\x20but\x20no\x20sentinel\x20present;\x20sentinel\x20header\x20added,\x20body\x20untouched'):(h['status']='skipped_user_file',h['detail']='machine\x20file\x20exists\x20without\x20builtin\x20sentinel\x20and\x20body\x20differs\x20from\x20canonical;\x20leaving\x20user\x20file\x20untouched'):k===g?j['version']!==BUILTIN_TEMPLATES_VERSION||releaseBodyHash(k)!==j['hash']?(writeFileSync(d,renderTemplateFile(c),'utf-8'),h['status']='restamped',h['detail']='body\x20matches\x20canonical\x20but\x20sentinel\x20stale/wrong;\x20header\x20refreshed,\x20body\x20untouched'):h['status']='current':(h['status']='skipped_modified',h['detail']='body\x20differs\x20from\x20canonical;\x20not\x20overwritten\x20by\x20seeding\x20—\x20use\x20repair_builtin_templates\x20(preview→confirm)\x20to\x20reseed');}}catch(l){h['status']='error',h['detail']=l['message'];}a['push'](h);try{a['push'](seedKnobSlot(b,c));}catch(m){a['push']({'template':c['id'],'status':'error','path':e,'detail':m['message']});}}try{a['push'](...seedIndustryNavPages(b));}catch{}return a;}function seedKnobSlot(a,b){const c=knobTemplateFile(a,b),d={'template':b['id'],'status':'knob_written','path':c};if(!existsSync(c))return mkdirSync(dirname(c),{'recursive':!![]}),writeFileSync(c,renderKnobFile(b),'utf-8'),d['detail']='knob\x20file\x20written\x20(fresh)',d;const e=readFileSync(c,'utf-8'),f=classifyKnobFile(e,b['id']);if(f==='current')return{...d,'status':'knob_current'};if(f==='outdated')return writeFileSync(c,renderKnobFile(b),'utf-8'),{...d,'status':'knob_current','detail':'unmodified\x20older\x20knob\x20release\x20auto-upgraded\x20to\x20the\x20current\x20render'};if(f==='user_modified')return{...d,'status':'knob_kept_user','detail':'user-edited\x20knobs\x20kept\x20by\x20design\x20(never\x20overwritten)'};let g;try{g=String(parseTemplateFile(e)['frontmatter']['id']??'');}catch{g=undefined;}if(g!==b['id'])return{...d,'status':'skipped_user_file','detail':'a\x20non-knob\x20file\x20(id\x20\x27'+(g??'<unparseable>')+'\x27)\x20occupies\x20the\x20knob\x20slot;\x20machine\x20template\x20wins,\x20file\x20untouched\x20—\x20rename\x20it\x20to\x20free\x20the\x20slot'};const h=join(dirname(c),TEMPLATE_ARCHIVE_SUBDIR);mkdirSync(h,{'recursive':!![]});const i=join(h,b['variant']+'.pre-split.md');return writeFileSync(i,e,'utf-8'),rmSync(c,{'force':!![]}),writeFileSync(c,renderKnobFile(b),'utf-8'),{...d,'status':'knob_written','detail':'obsolete\x20pre-S8\x20single-file\x20template\x20retired\x20to\x20'+i+';\x20knob\x20file\x20re-rendered\x20from\x20the\x20current\x20catalog'};}function seedIndustryNavPages(a){const b=[],c=new Map();for(const d of BUILTIN_TEMPLATES){const e=c['get'](d['industry'])??[];e['push'](d),c['set'](d['industry'],e);}for(const [f,g]of[...c['entries']()]['sort']()){const h=join(a,f,INDUSTRY_NAV_FILENAME),i={'template':'nav/'+f,'status':'written','path':h};try{if(!existsSync(h))mkdirSync(dirname(h),{'recursive':!![]}),writeFileSync(h,renderIndustryNav(f,g),'utf-8');else{const j=classifyIndustryNav(readFileSync(h,'utf-8'));if(j==='current')i['status']='current';else j==='outdated'?(writeFileSync(h,renderIndustryNav(f,g),'utf-8'),i['status']='restamped',i['detail']='unmodified\x20older\x20nav\x20page\x20auto-upgraded'):(i['status']='skipped_modified',i['detail']='nav\x20page\x20user-edited;\x20kept\x20by\x20design');}}catch(k){i['status']='error',i['detail']=k['message'];}b['push'](i);}return b;}export function summarizeTemplateDiff(a,b){let c,d;try{c=parseTemplateFile(a);}catch(g){return'on-disk\x20file\x20is\x20not\x20parseable\x20('+g['message']+');\x20full\x20content\x20will\x20be\x20replaced';}try{d=parseTemplateFile(b);}catch{return'canonical\x20render\x20is\x20not\x20parseable\x20(code\x20defect);\x20full\x20content\x20will\x20be\x20replaced';}const e=[],f=new Set([...Object['keys'](c['frontmatter']),...Object['keys'](d['frontmatter'])]);for(const h of[...f]['sort']()){const i=h in c['frontmatter'],j=h in d['frontmatter'];if(i&&!j)e['push']('-'+h);else{if(!i&&j)e['push']('+'+h);else{if(JSON['stringify'](c['frontmatter'][h])!==JSON['stringify'](d['frontmatter'][h]))e['push']('~'+h);}}}return c['body']!==d['body']&&e['push']('~body\x20('+c['body']['split']('\x0a')['length']+'\x20->\x20'+d['body']['split']('\x0a')['length']+'\x20lines)'),e['length']>0x0?e['join'](',\x20'):'whitespace/ordering\x20only';}export function repairBuiltinTemplates(a){const b=[],c=resolveTemplatesDir(),d=a?.['backup']!==![],e=a?.['dryRun']===!![],f=new Set(a?.['includeUserEdited']??[]);for(const g of BUILTIN_TEMPLATES){const h=machineTemplateFile(c,g);if(!existsSync(h))continue;const i=canonicalTemplateContent(g);let j=null,k='';const l={'template':g['id'],'status':'would_update','path':h};try{const p=stripReleaseSentinel(readFileSync(h,'utf-8'),TEMPLATE_SENTINEL_KIND);j=p['sentinel'],k=p['content'];}catch(q){l['status']='error',l['detail']=q['message'],b['push'](l);continue;}if(k===i)continue;let m;if(j){if(j['version']>BUILTIN_TEMPLATES_VERSION){l['status']='error',l['detail']='newer\x20release\x20on\x20disk\x20(sentinel\x20v'+j['version']+'\x20>\x20running\x20catalog\x20v'+BUILTIN_TEMPLATES_VERSION+')\x20—\x20'+'repair\x20would\x20DOWNGRADE\x20and\x20lose\x20the\x20newer\x20release\x27s\x20content;\x20refused.\x20Upgrade\x20the\x20MCP\x20server\x20instead',b['push'](l);continue;}if(releaseBodyHash(k)!==j['hash']){if(!f['has'](g['id']))continue;m='sentinel-body\x20hash\x20mismatch\x20(sentinel\x20v'+j['version']+'\x20no\x20longer\x20binds\x20the\x20body)\x20'+'reseeded\x20under\x20EXPLICIT\x20include_user_edited\x20authorization';}else m='untouched\x20older\x20release\x20(sentinel\x20v'+j['version']+',\x20current\x20v'+BUILTIN_TEMPLATES_VERSION+')';}else{let r;try{r=String(parseTemplateFile(k)['frontmatter']['id']??'');}catch{continue;}if(r!==g['id'])continue;m='legacy\x20sentinel-less\x20builtin\x20file';}const n=summarizeTemplateDiff(k,i),o=d?';\x20previous\x20body\x20would\x20be\x20saved\x20in\x20templates/.archive/':'';if(e){l['status']='would_update',l['detail']=m+'\x20would\x20be\x20reseeded\x20from\x20BUILTIN_TEMPLATES\x20('+g['id']+')\x20—\x20diff\x20vs\x20canonical:\x20'+n+o+'\x20—\x20execute\x20with\x20authorize=true\x20after\x20the\x20user\x20explicitly\x20confirms',b['push'](l);continue;}try{if(d){const s=archiveBackupFile(c,g,'.repair.md');mkdirSync(dirname(s),{'recursive':!![]}),copyFileSync(h,s);}writeFileSync(h,renderTemplateFile(g),'utf-8'),cache['delete'](h),l['status']='updated',l['detail']=m+'\x20reseeded\x20from\x20BUILTIN_TEMPLATES\x20('+g['id']+')\x20—\x20diff\x20was:\x20'+n+(d?';\x20previous\x20body\x20saved\x20in\x20templates/.archive/':'');}catch(u){l['status']='error',l['detail']=u['message'];}b['push'](l);}return b;}export function builtinTemplateDrift(a){const b=new Set(a?.['includeUserEdited']??[]),c=[],d=resolveTemplatesDir();for(const e of BUILTIN_TEMPLATES){const f=machineTemplateFile(d,e);if(!existsSync(f)){c['push']({'template':e['id'],'path':f,'state':'missing','repairable':!![],'detail':'no\x20file\x20on\x20disk;\x20seeding\x20will\x20create\x20it'});continue;}const g=canonicalTemplateContent(e);let h=null,i='';try{const k=stripReleaseSentinel(readFileSync(f,'utf-8'),TEMPLATE_SENTINEL_KIND);h=k['sentinel'],i=k['content'];}catch(l){c['push']({'template':e['id'],'path':f,'state':'modified','repairable':![],'detail':'unreadable:\x20'+l['message']});continue;}if(i===g)continue;const j=summarizeTemplateDiff(i,g);if(!h){let m;try{m=String(parseTemplateFile(i)['frontmatter']['id']??'');}catch{m=undefined;}m===e['id']?c['push']({'template':e['id'],'path':f,'state':'modified','repairable':!![],'detail':'legacy\x20sentinel-less\x20builtin\x20file\x20—\x20seeding\x20never\x20rewrites\x20it\x20and\x20no\x20sentinel\x20proves\x20provenance;\x20repair\x20can\x20reseed\x20—\x20diff\x20vs\x20canonical:\x20'+j}):c['push']({'template':e['id'],'path':f,'state':'modified','repairable':![],'detail':'no\x20release\x20sentinel\x20and\x20id\x20\x27'+(m??'<unparseable>')+'\x27\x20does\x20not\x20match\x20the\x20builtin\x20id\x20—\x20a\x20user\x20file\x20occupies\x20this\x20path;\x20never\x20touched\x20(rename\x20it\x20to\x20free\x20the\x20slot)'});continue;}if(releaseBodyHash(i)===h['hash'])h['version']>BUILTIN_TEMPLATES_VERSION?c['push']({'template':e['id'],'path':f,'state':'modified','repairable':![],'detail':'newer\x20release\x20(sentinel\x20v'+h['version']+'\x20>\x20running\x20catalog\x20v'+BUILTIN_TEMPLATES_VERSION+')\x20—\x20'+'repair\x20would\x20DOWNGRADE\x20and\x20lose\x20the\x20newer\x20release\x27s\x20content;\x20repairable:\x20false.\x20'+'Upgrade\x20the\x20MCP\x20server\x20to\x20match\x20—\x20diff\x20vs\x20canonical:\x20'+j}):c['push']({'template':e['id'],'path':f,'state':'modified','repairable':!![],'detail':'untouched\x20older\x20release\x20(sentinel\x20v'+h['version']+',\x20current\x20v'+BUILTIN_TEMPLATES_VERSION+')\x20—\x20repair\x20can\x20upgrade\x20—\x20diff\x20vs\x20canonical:\x20'+j});else{const n=b['has'](e['id']);c['push']({'template':e['id'],'path':f,'state':'modified','repairable':n,'detail':n?'sentinel-body\x20hash\x20mismatch\x20(sentinel\x20v'+h['version']+'\x20no\x20longer\x20binds\x20the\x20body)\x20—\x20reseedable\x20under\x20the\x20explicit\x20include_user_edited\x20authorization\x20for\x20this\x20id\x20—\x20diff\x20vs\x20canonical:\x20'+j:'user-edited\x20body\x20—\x20kept\x20by\x20design;\x20repair\x20never\x20overwrites\x20user\x20edits\x20—\x20diff\x20vs\x20canonical:\x20'+j});}}for(const o of c){const p=BUILTIN_TEMPLATES['find'](q=>q['id']===o['template']);if(p)o['knob_state']=knobFileState(d,p);}return c;}function knobFileState(a,b){const c=knobTemplateFile(a,b);if(!existsSync(c))return'missing';try{return classifyKnobFile(readFileSync(c,'utf-8'),b['id'])==='user_modified'?'user_modified':'current';}catch{return'current';}}const cache=new Map();export function reloadTemplates(){cache['clear'](),seeded=![];}export function loadAndValidate(a){const b=readFileSync(a,'utf-8');let c;try{c=parseTemplateFile(b);}catch(f){throw new Error('template\x20\x27'+a+'\x27\x20failed\x20to\x20parse:\x20'+f['message']);}const d=TemplateFrontmatterSchema['safeParse'](c['frontmatter']);if(!d['success']){const g=d['error']['issues']['map'](h=>(h['path']['join']('.')||'<root>')+':\x20'+h['message'])['join'](';\x20');throw new Error('template\x20\x27'+a+'\x27\x20failed\x20validation:\x20'+g);}const e=validateAllocatorRows(d['data']);if(e['length']>0x0)throw new Error('template\x20\x27'+a+'\x27\x20failed\x20allocator-row\x20validation:\x20'+e['join'](';\x20'));return{...d['data'],'body':c['body'],'source_path':a};}function templateFilesOnDisk(a){const b=[];if(!existsSync(a))return b;const c=new Set(BUILTIN_TEMPLATES['map'](d=>d['industry']+'/'+d['variant']));for(const d of readdirSync(a,{'withFileTypes':!![]})){if(!d['isDirectory']())continue;const e=join(a,d['name'],TEMPLATES_SUBDIR);if(!existsSync(e))continue;const g=join(e,MACHINE_TEMPLATES_SUBDIR);if(existsSync(g))for(const h of readdirSync(g,{'withFileTypes':!![]})){if(!h['isFile']()||!h['name']['endsWith']('.md'))continue;const i=h['name']['slice'](0x0,-'.md'['length']),j=c['has'](d['name']+'/'+i)?join(e,h['name']):null;b['push']({'file':join(g,h['name']),'knobFile':j});}for(const k of readdirSync(e,{'withFileTypes':!![]})){if(!k['isFile']()||!k['name']['endsWith']('.md'))continue;const l=k['name']['slice'](0x0,-'.md'['length']);if(c['has'](d['name']+'/'+l))continue;b['push']({'file':join(e,k['name']),'knobFile':null});}}return b['sort']((m,n)=>m['file']['localeCompare'](n['file']));}export function listTemplates(){!seeded&&(seedBuiltinTemplates(),seeded=!![]);const a=resolveTemplatesDir(),b=[],c=[],d=new Set();for(const {file:e,knobFile:f}of templateFilesOnDisk(a)){d['add'](e);try{const g=statSync(e)['mtimeMs'],h=f&&existsSync(f)?statSync(f)['mtimeMs']:0x0,i=cache['get'](e);if(i&&i['mtimeMs']===g&&i['knobMtimeMs']===h){b['push'](i['template']);continue;}let j=loadAndValidate(e);if(f&&h>0x0){const k=readFileSync(f,'utf-8'),l=parseKnobFile(k,j['id']);if(l){j=applyKnobOverlay(j,l,parseTemplateFile(k)['body']);const m=validateAllocatorRows(j);if(m['length']>0x0)throw new Error('template\x20\x27'+e+'\x27\x20—\x20knob\x20overlay\x20\x27'+f+'\x27\x20broke\x20allocator-row\x20validation:\x20'+m['join'](';\x20'));}else c['push']('knob\x20file\x20\x27'+f+'\x27\x20is\x20not\x20a\x20valid\x20knob\x20overlay\x20for\x20\x27'+j['id']+'\x27\x20—\x20ignored,\x20machine\x20template\x20used\x20as-is');}cache['set'](e,{'mtimeMs':g,'knobMtimeMs':h,'template':j}),b['push'](j);}catch(n){cache['delete'](e),c['push'](n['message']);}}for(const o of[...cache['keys']()]){if(!d['has'](o))cache['delete'](o);}return b['sort']((p,q)=>p['id']['localeCompare'](q['id'])),{'templates':b,'errors':c};}export function getTemplate(a){return listTemplates()['templates']['find'](b=>b['id']===a);}export function getTemplatesByIndustry(a){return listTemplates()['templates']['filter'](b=>b['industry']===a);}
@@ -0,0 +1,7 @@
1
+ import type { ArchetypeTemplate } from "./builtin-templates.js";
2
+ export declare const INDUSTRY_NAV_FILENAME = "README.md";
3
+ export declare const INDUSTRY_NAV_SENTINEL_KIND = "industry-nav";
4
+ export declare const INDUSTRY_NAV_VERSION = 4;
5
+ export declare function canonicalIndustryNav(industry: string, templates: ArchetypeTemplate[]): string;
6
+ export declare function renderIndustryNav(industry: string, templates: ArchetypeTemplate[]): string;
7
+ export declare function classifyIndustryNav(raw: string): "current" | "outdated" | "user_modified" | null;
@@ -0,0 +1 @@
1
+ import{classifyRelease,releaseBodyHash,releaseSentinelLine,stripReleaseSentinel}from'./release-sentinel.js';import{KNOB_UNIT_HINTS}from'./knob-docs.js';export const INDUSTRY_NAV_FILENAME='README.md';export const INDUSTRY_NAV_SENTINEL_KIND='industry-nav';export const INDUSTRY_NAV_VERSION=0x4;function glossarySection(){return['##\x20The\x20settings,\x20in\x20plain\x20words','','Every\x20setting\x20line\x20in\x20a\x20template\x20file\x20is\x20one\x20business\x20number\x20or\x20one\x20switch.','This\x20section\x20is\x20the\x20dictionary:\x20what\x20the\x20numbers\x20mean,\x20and\x20what\x20each\x20switch','chooses\x20between.\x20A\x20knob\x27s\x20own\x20meaning\x20is\x20written\x20right\x20above\x20it\x20in\x20the','template\x20file,\x20as\x20a\x20`#`\x20note.','','###\x20Units\x20—\x20read\x20the\x20number\x20right','',...KNOB_UNIT_HINTS['map'](a=>'-\x20a\x20setting\x20whose\x20name\x20ends\x20in\x20`'+a['suffix']+'`\x20is\x20'+a['doc']+'.'),'-\x20a\x20money\x20setting\x20with\x20NO\x20unit\x20suffix\x20(pools,\x20fees,\x20prices,\x20deposits)\x20is\x20in\x20RAW','\x20\x20on-chain\x20smallest\x20units:\x200.5\x20WOW\x20is\x20written\x20500000000.\x20Count\x20the\x20zeros\x20—','\x20\x20this\x20is\x20the\x20one\x20mistake\x20the\x20system\x20cannot\x20guess\x20for\x20you.','','###\x20The\x20mode\x20switches','','-\x20`payment_model`\x20—\x20how\x20money\x20moves:\x20`escrow`\x20(one\x20funded\x20order,\x20released\x20on','\x20\x20acceptance),\x20`milestone`\x20(a\x20ladder\x20of\x20funded\x20phases),\x20`subscription`\x20(recurring).','-\x20`arbitration_mode`\x20—\x20who\x20judges\x20a\x20dispute:\x20`none`,\x20`merchant_pick`\x20(the\x20merchant','\x20\x20names\x20the\x20arbitrator),\x20`mutual_pick`\x20(both\x20sides\x20must\x20agree),\x20`third_party`\x20(a','\x20\x20standing\x20independent\x20arbitrator).','-\x20`review_mode`\x20—\x20`review`\x20(reputation\x20only,\x20costs\x20nothing)\x20or\x20`review_reward`','\x20\x20(paid\x20reviews\x20—\x20needs\x20the\x20reward\x20pool\x20settings\x20AND\x20the\x20build-time\x20reward\x20funding;','\x20\x20the\x20pre-launch\x20check\x20refuses\x20an\x20unfunded\x20reward\x20instead\x20of\x20advertising\x20one).','-\x20`after_sales_mode`\x20—\x20the\x20remedy\x20rail:\x20`return`,\x20`exchange`,\x20or\x20`warranty`.','-\x20`acceptance_mode`\x20—\x20how\x20work\x20is\x20accepted:\x20`milestone`,\x20`contest`,\x20`bounty`,\x20or','\x20\x20`agent`\x20(an\x20agent\x20accepts\x20on\x20the\x20buyer\x27s\x20behalf).','-\x20`installment_mode`\x20—\x20`deposit_balance`\x20(deposit\x20now,\x20balance\x20later)\x20or','\x20\x20`milestone_n`\x20(n\x20installments).','-\x20`affiliate_mode`\x20—\x20`commission`\x20lets\x20referrers\x20earn\x20a\x20share.','-\x20`crowdfunding_mode`\x20—\x20`threshold`\x20(all-or-nothing:\x20release\x20or\x20full\x20refund)\x20or','\x20\x20`flexible`\x20(keep\x20whatever\x20is\x20raised).','-\x20`logistics_mode`\x20—\x20who\x20carries:\x20`carrier`,\x20`merchant_managed`,\x20`courier`,\x20or','\x20\x20`pickup_point`.','-\x20`reward_claim_policy`\x20—\x20how\x20reward\x20claims\x20repeat:\x20`once`,\x20`periodic`,\x20or\x20`capped`.','-\x20`reentry_kind`\x20—\x20what\x20a\x20repeat\x20visit\x20means:\x20`review-loop`\x20(free\x20remedy\x20revisits\x20of','\x20\x20the\x20same\x20order)\x20or\x20`paid-cycle`\x20(each\x20revisit\x20charges\x20again).','-\x20`compensation_fund_policy`\x20—\x20`allowed`\x20or\x20`forbidden`:\x20whether\x20this\x20template\x27s','\x20\x20risk\x20story\x20permits\x20a\x20compensation\x20fund\x20at\x20all.','','###\x20Mechanisms\x20worth\x20knowing','','-\x20The\x20settlement\x20lock\x20can\x20be\x20a\x20SUM:\x20some\x20templates\x20fold\x20several\x20windows\x20(settlement','\x20\x20+\x20reserve\x20+\x20return)\x20into\x20ONE\x20release\x20instant.\x20Each\x20window\x20knob\x20stays\x20live,\x20and\x20the','\x20\x20build\x20refuses\x20a\x20compile\x20that\x20disagrees\x20with\x20the\x20declared\x20sum.','-\x20A\x20silent\x20buyer\x20is\x20never\x20a\x20dead\x20end:\x20after\x20`auto_confirm_days`\x20(or\x20`_hours`)\x20from','\x20\x20shipment,\x20a\x20keeper\x20advances\x20the\x20order\x20so\x20escrow\x20can\x20settle.','-\x20Windows\x20must\x20nest\x20in\x20order:\x20the\x20dispute-filing\x20window\x20always\x20closes\x20before\x20the','\x20\x20settlement\x20release\x20opens\x20—\x20the\x20pre-launch\x20lint\x20rejects\x20the\x20colliding\x20order.','-\x20`recommended_role`\x20says\x20who\x20a\x20template\x20is\x20built\x20for:\x20a\x20`merchant`,\x20a\x20`supplier`,','\x20\x20or\x20`both`.',''];}function shortRisk(a){const b=a['split'](/(?<=[.!?])\s/)[0x0]??a,c=b['length']>0x8c?b['slice'](0x0,0x89)+'...':b;return c['replace'](/\|/g,'/')['replace'](/\r?\n/g,'\x20');}export function canonicalIndustryNav(a,b){const c=[...b]['sort']((e,f)=>e['variant']['localeCompare'](f['variant'])),d=['#\x20'+a+'\x20—\x20templates\x20you\x20can\x20start\x20from','','Pick\x20one\x20template\x20below,\x20then\x20adjust\x20its\x20numbers.\x20You\x20only\x20edit\x20one\x20file\x20per','template:\x20`templates/<variant>.md`.\x20Everything\x20else\x20in\x20this\x20folder\x20is\x20either','reading\x20material\x20or\x20handled\x20by\x20the\x20system\x20for\x20you.','','##\x20Templates','','|\x20template\x20|\x20modeled\x20on\x20a\x20service\x20like\x20|\x20market\x20position\x20|\x20launch\x20phase\x20|\x20who\x20runs\x20it\x20|\x20main\x20risk\x20to\x20watch\x20|','|\x20---\x20|\x20---\x20|\x20---\x20|\x20---\x20|\x20---\x20|\x20---\x20|',...c['map'](e=>'|\x20'+e['variant']+'\x20|\x20'+e['product_ref']+'\x20|\x20'+e['archetype']+'\x20|\x20'+e['phase']+'\x20|\x20'+e['recommended_role']+'\x20|\x20'+shortRisk(e['key_risk'])+'\x20|'),'','##\x20How\x20the\x20templates\x20differ','',...c['flatMap'](e=>['###\x20'+e['variant'],'',...e['differences']['map'](f=>'-\x20'+f),'']),...glossarySection(),'##\x20What\x20is\x20in\x20this\x20folder','','-\x20`playbook.md`\x20—\x20your\x20own\x20strategy,\x20tone\x20and\x20experience\x20notes.\x20The\x20AI\x20reads\x20this','\x20\x20before\x20every\x20task;\x20write\x20it\x20freely\x20in\x20your\x20own\x20words.','-\x20`strategy-manual.md`\x20—\x20background\x20knowledge\x20for\x20this\x20industry.\x20Read\x20it;\x20you\x20do','\x20\x20not\x20need\x20to\x20maintain\x20it.','-\x20`templates/<variant>.md`\x20—\x20the\x20numbers\x20and\x20switches\x20of\x20one\x20template.\x20This\x20is\x20the','\x20\x20file\x20you\x20change.','-\x20`templates/.machine/`\x20—\x20the\x20workflow\x20behind\x20a\x20template.\x20The\x20system\x20keeps\x20it;\x20it\x20is','\x20\x20not\x20shown\x20in\x20the\x20app\x20and\x20you\x20never\x20need\x20to\x20edit\x20it.','','The\x20version\x20stamp\x20at\x20the\x20very\x20top\x20of\x20a\x20released\x20file\x20is\x20bookkeeping\x20written\x20by\x20the','system.\x20Leave\x20it\x20alone\x20—\x20it\x20is\x20how\x20the\x20system\x20knows\x20whether\x20to\x20upgrade\x20the\x20file.','','##\x20How\x20to\x20change\x20a\x20template','','1.\x20Open\x20`templates/<variant>.md`.\x20Every\x20line\x20is\x20one\x20setting:\x20`key:\x20value`.','2.\x20Change\x20a\x20number\x20(fees,\x20waiting\x20windows,\x20caps)\x20or\x20pick\x20another\x20mode\x20from\x20the','\x20\x20\x20allowed\x20list.\x20A\x20setting\x20you\x20leave\x20out\x20keeps\x20its\x20default.','3.\x20Only\x20promise\x20what\x20you\x20fund.\x20Example:\x20paying\x20buyers\x20for\x20reviews','\x20\x20\x20(`review_mode:\x20review_reward`)\x20needs\x20the\x20reward\x20budget\x20in\x20the\x20same\x20file\x20—','\x20\x20\x20`fee_params.review_reward_pool`\x20and\x20`fee_params.review_reward_per_claim`.\x20If\x20the','\x20\x20\x20money\x20is\x20missing,\x20the\x20pre-launch\x20check\x20refuses\x20to\x20build\x20the\x20service\x20instead\x20of','\x20\x20\x20letting\x20you\x20advertise\x20a\x20reward\x20you\x20cannot\x20pay.','4.\x20Keep\x20waiting\x20windows\x20in\x20a\x20sane\x20order:\x20settlement\x20time\x20must\x20be\x20at\x20least\x20as\x20long','\x20\x20\x20as\x20the\x20claim\x20window,\x20or\x20payouts\x20collide\x20with\x20claims.','5.\x20A\x20mistyped\x20mode\x20name,\x20or\x20a\x20number\x20in\x20the\x20wrong\x20shape,\x20is\x20rejected\x20the\x20moment\x20you','\x20\x20\x20save.\x20You\x20cannot\x20break\x20a\x20template\x20silently.','','##\x20Maintaining\x20it\x20by\x20talking\x20to\x20the\x20AI','','-\x20Say\x20what\x20you\x20want\x20in\x20plain\x20words\x20—\x20\x22raise\x20the\x20commission\x20to\x208%\x22,\x20\x22give\x20buyers','\x20\x2030\x20days\x20to\x20claim\x22,\x20\x22add\x20a\x20reward\x20for\x20reviews\x22.\x20The\x20AI\x20edits\x20the\x20right\x20line\x20and','\x20\x20shows\x20you\x20the\x20risk\x20before\x20anything\x20is\x20built.','-\x20A\x20change\x20to\x20the\x20process\x20itself\x20—\x20extra\x20steps,\x20a\x20different\x20approval,\x20a\x20different','\x20\x20split\x20of\x20the\x20money\x20—\x20is\x20not\x20a\x20setting.\x20Ask\x20the\x20AI\x20to\x20regenerate\x20the\x20template\x20from','\x20\x20the\x20catalog\x20instead,\x20so\x20the\x20workflow\x20is\x20compiled\x20and\x20checked.','-\x20If\x20a\x20change\x20seems\x20to\x20have\x20no\x20effect,\x20ask\x20the\x20AI\x20to\x20check\x20the\x20template\x20for\x20a\x20stale','\x20\x20copy.\x20That\x20is\x20a\x20known,\x20diagnosable\x20state\x20—\x20not\x20a\x20lost\x20edit.',''];return d['join']('\x0a');}export function renderIndustryNav(a,b){const c=canonicalIndustryNav(a,b);return releaseSentinelLine(INDUSTRY_NAV_SENTINEL_KIND,INDUSTRY_NAV_VERSION,releaseBodyHash(c))+'\x0a'+c;}export function classifyIndustryNav(a){const b=stripReleaseSentinel(a,INDUSTRY_NAV_SENTINEL_KIND);if(!b['sentinel'])return null;const c=classifyRelease(b['sentinel'],b['content'],INDUSTRY_NAV_VERSION);return c==='user_file'?null:c;}
@@ -1 +1 @@
1
- import{GUARD_TEMPLATES,fillGuardTemplate}from'./guard-templates.js';import{MACHINE_TEMPLATES,fillTemplate as a317a}from'./machine-templates.js';import{SERVICE_TEMPLATES,fillServiceTemplate}from'./service-templates.js';import{ORDER_TEMPLATES,fillTemplate as a317b}from'./order-templates.js';import{PROGRESS_TEMPLATES,fillProgressTemplate}from'./progress-templates.js';import{ARBITRATION_TEMPLATES,fillTemplate as a317c}from'./arbitration-templates.js';import{TREASURY_TEMPLATES,fillTemplate as a317d}from'./treasury-templates.js';import{PERMISSION_TEMPLATES,fillTemplate as a317e}from'./permission-templates.js';import{PASSPORT_TEMPLATES,fillTemplate as a317f}from'./passport-templates.js';import{ALLOCATION_TEMPLATES,fillTemplate as a317g}from'./allocation-templates.js';import{CONTACT_TEMPLATES,fillTemplate as a317h}from'./contact-templates.js';import{REWARD_TEMPLATES}from'./reward-templates.js';export const TEMPLATE_REGISTRY_VERSION=0x1;export const TEMPLATE_OBJECT_TYPES=['guard','machine','service','order','progress','arbitration','treasury','permission','passport','allocation','reward','contact'];function normalizeParam(a){return{'name':a['name'],'type':a['type'],'description':a['description']??'','required':a['required'],...a['default']!==undefined?{'default':a['default']}:{},...a['constraint']!==undefined?{'constraint':a['constraint']}:{}};}function guardMeta(a){return{'id':a['id'],'object_type':'guard','name':a['name'],'description':a['description'],'scenes':[a['scene_id']],'industries':a['applicable_industries'],'instantiable':!![],'parameters':a['parameters']['map'](b=>normalizeParam(b))};}function machineMeta(a){return{'id':a['id'],'object_type':'machine','name':a['name'],'description':a['description'],'scenes':[a['scene_id']],'industries':a['applicable_industries'],'instantiable':!![],'parameters':a['parameters']['map'](b=>normalizeParam(b))};}function bodyMeta(a,b,c,d){return{'id':a['id'],'object_type':b,'name':a['name'],'description':a['description'],'scenes':c,'industries':d,'instantiable':!![],'parameters':a['params']['map'](e=>normalizeParam(e))};}function rewardMeta(a){return{'id':a['type'],'object_type':'reward','name':a['name'],'description':a['description'],'scenes':[],'industries':[],'instantiable':![],'parameters':a['parameters']['map'](b=>normalizeParam(b))};}let REGISTRY=null,ID_COLLISIONS=[];function buildRegistry(){const a=new Map(),b=[],c=d=>{if(a['has'](d['meta']['id'])){b['push'](d['meta']['id']);return;}a['set'](d['meta']['id'],d);};for(const d of GUARD_TEMPLATES){c({'meta':guardMeta(d),'raw':d,'notes':d['creation_notes']});}for(const e of MACHINE_TEMPLATES){c({'meta':machineMeta(e),'raw':e,'notes':e['creation_notes']});}for(const f of SERVICE_TEMPLATES){c({'meta':bodyMeta(f,'service',f['applicable_scenes'],f['industry_tags']),'raw':f,'notes':f['notes']});}for(const g of ORDER_TEMPLATES){c({'meta':bodyMeta(g,'order',g['applicable_scenes'],g['industry_tags']),'raw':g,'notes':g['notes']});}for(const h of PROGRESS_TEMPLATES){c({'meta':bodyMeta(h,'progress',h['applicable_scenes'],h['industry_tags']),'raw':h,'notes':h['notes']});}for(const i of ARBITRATION_TEMPLATES){c({'meta':bodyMeta(i,'arbitration',i['applicable_scenes'],i['industry_tags']),'raw':i,'notes':i['notes']});}for(const j of TREASURY_TEMPLATES){c({'meta':bodyMeta(j,'treasury',j['applicable_scenes'],j['industry_tags']),'raw':j,'notes':j['notes']});}for(const k of PERMISSION_TEMPLATES){c({'meta':bodyMeta(k,'permission',k['applicable_scenes'],k['industry_tags']),'raw':k,'notes':k['notes']});}for(const l of PASSPORT_TEMPLATES){c({'meta':bodyMeta(l,'passport',l['applicable_scenarios'],l['industry_tags']),'raw':l,'notes':l['notes']});}for(const m of ALLOCATION_TEMPLATES){c({'meta':bodyMeta(m,'allocation',m['applicable_scenes'],m['industry_tags']),'raw':m,'notes':m['notes']});}for(const n of REWARD_TEMPLATES){c({'meta':rewardMeta(n),'raw':n,'guidance':{'guardCondition':n['guardCondition'],'amountRange':n['amountRange'],'allocationStrategy':n['allocationStrategy'],'example':n['example'],'relevantGuardOps':n['relevantGuardOps']}});}for(const o of CONTACT_TEMPLATES){c({'meta':bodyMeta(o,'contact',o['applicable_scenes'],o['industry_tags']),'raw':o,'notes':o['notes']});}return ID_COLLISIONS=b,a;}function registry(){return!REGISTRY&&(REGISTRY=buildRegistry()),REGISTRY;}export function getTemplateIdCollisions(){return registry(),ID_COLLISIONS;}export function getTemplateCounts(){const a=Object['fromEntries'](TEMPLATE_OBJECT_TYPES['map'](b=>[b,0x0]));for(const b of registry()['values']()){a[b['meta']['object_type']]+=0x1;}return a;}export function listTemplates(a){const b=[...registry()['values']()]['map'](c=>c['meta']);return a?b['filter'](c=>c['object_type']===a):b;}export function getTemplateDetail(a){const b=registry()['get'](a);if(!b)return null;return{...b['meta'],'raw':b['raw'],...b['notes']?{'notes':b['notes']}:{},...b['guidance']?{'guidance':b['guidance']}:{}};}export function findTemplateObjectType(a){return registry()['get'](a)?.['meta']['object_type']??null;}export function instantiateTemplate(a,b){const c=registry()['get'](a);if(!c)return{'ok':![],'object_type':null,'template_id':a,'error':'Template\x20not\x20found:\x20'+a+'.\x20Use\x20get_templates\x20without\x20\x27template\x27\x20to\x20list\x20all\x20template\x20ids.'};const d=c['meta']['object_type'];if(!c['meta']['instantiable'])return{'ok':![],'object_type':d,'template_id':a,'error':'Reward\x20templates\x20are\x20guidance-only\x20(prose\x20guard\x20conditions)\x20and\x20cannot\x20be\x20'+'instantiated\x20into\x20executable\x20JSON.\x20Use\x20the\x20guidance\x20payload\x20to\x20design\x20the\x20'+'Reward\x20+\x20Guard\x20manually.','guidance':c['guidance']};switch(d){case'guard':{const e=fillGuardTemplate(a,b);if(!e['ok'])return{'ok':![],'object_type':d,'template_id':a,'error':e['error'],...e['missing']?{'missing_params':e['missing']}:{}};return{'ok':!![],'object_type':d,'template_id':a,'body':{'table':e['table'],'root':e['root']},...c['notes']?{'notes':c['notes']}:{}};}case'machine':{const f=a317a(a,b);if(!f['success'])return{'ok':![],'object_type':d,'template_id':a,'error':f['validation_errors']?.['join'](';\x20')??'Machine\x20template\x20fill\x20failed',...f['missing_params']?{'missing_params':f['missing_params']}:{}};return{'ok':!![],'object_type':d,'template_id':a,'body':{'nodes':f['filled_nodes'],'pairs':f['filled_pairs']},...c['notes']?{'notes':c['notes']}:{}};}case'service':{const g=fillServiceTemplate(a,b);if(!g['ok'])return{'ok':![],'object_type':d,'template_id':a,'error':g['error']??'Service\x20template\x20fill\x20failed',...g['missing_required']?{'missing_params':g['missing_required']}:{}};return{'ok':!![],'object_type':d,'template_id':a,'body':g['body'],...c['notes']?{'notes':c['notes']}:{}};}case'order':case'arbitration':case'treasury':case'permission':case'passport':case'allocation':case'progress':case'contact':{const h=fillBodyTemplate(d,a,b);if(!h['ok'])return{'ok':![],'object_type':d,'template_id':a,'error':h['error']};return{'ok':!![],'object_type':d,'template_id':a,'body':h['body'],...c['notes']?{'notes':c['notes']}:{}};}default:return{'ok':![],'object_type':d,'template_id':a,'error':'Instantiation\x20not\x20supported\x20for\x20object_type\x20\x27'+d+'\x27'};}}function fillBodyTemplate(a,b,c){switch(a){case'order':return a317b(b,c);case'arbitration':return a317c(b,c);case'treasury':return a317d(b,c);case'permission':return a317e(b,c);case'passport':return a317f(b,c);case'allocation':return a317g(b,c);case'progress':return fillProgressTemplate(b,c);case'contact':return a317h(b,c);default:return{'ok':![],'error':'No\x20body-template\x20fill\x20for\x20\x27'+a+'\x27'};}}
1
+ import{GUARD_TEMPLATES,fillGuardTemplate}from'./guard-templates.js';import{MACHINE_TEMPLATES,fillTemplate as a326a}from'./machine-templates.js';import{SERVICE_TEMPLATES,fillServiceTemplate}from'./service-templates.js';import{ORDER_TEMPLATES,fillTemplate as a326b}from'./order-templates.js';import{PROGRESS_TEMPLATES,fillProgressTemplate}from'./progress-templates.js';import{ARBITRATION_TEMPLATES,fillTemplate as a326c}from'./arbitration-templates.js';import{TREASURY_TEMPLATES,fillTemplate as a326d}from'./treasury-templates.js';import{PERMISSION_TEMPLATES,fillTemplate as a326e}from'./permission-templates.js';import{PASSPORT_TEMPLATES,fillTemplate as a326f}from'./passport-templates.js';import{ALLOCATION_TEMPLATES,fillTemplate as a326g}from'./allocation-templates.js';import{CONTACT_TEMPLATES,fillTemplate as a326h}from'./contact-templates.js';import{REWARD_TEMPLATES}from'./reward-templates.js';export const TEMPLATE_REGISTRY_VERSION=0x1;export const TEMPLATE_OBJECT_TYPES=['guard','machine','service','order','progress','arbitration','treasury','permission','passport','allocation','reward','contact'];function normalizeParam(a){return{'name':a['name'],'type':a['type'],'description':a['description']??'','required':a['required'],...a['default']!==undefined?{'default':a['default']}:{},...a['constraint']!==undefined?{'constraint':a['constraint']}:{}};}function guardMeta(a){return{'id':a['id'],'object_type':'guard','name':a['name'],'description':a['description'],'scenes':[a['scene_id']],'industries':a['applicable_industries'],'instantiable':!![],'parameters':a['parameters']['map'](b=>normalizeParam(b))};}function machineMeta(a){return{'id':a['id'],'object_type':'machine','name':a['name'],'description':a['description'],'scenes':[a['scene_id']],'industries':a['applicable_industries'],'instantiable':!![],'parameters':a['parameters']['map'](b=>normalizeParam(b))};}function bodyMeta(a,b,c,d){return{'id':a['id'],'object_type':b,'name':a['name'],'description':a['description'],'scenes':c,'industries':d,'instantiable':!![],'parameters':a['params']['map'](e=>normalizeParam(e))};}function rewardMeta(a){return{'id':a['type'],'object_type':'reward','name':a['name'],'description':a['description'],'scenes':[],'industries':[],'instantiable':![],'parameters':a['parameters']['map'](b=>normalizeParam(b))};}let REGISTRY=null,ID_COLLISIONS=[];function buildRegistry(){const a=new Map(),b=[],c=d=>{if(a['has'](d['meta']['id'])){b['push'](d['meta']['id']);return;}a['set'](d['meta']['id'],d);};for(const d of GUARD_TEMPLATES){c({'meta':guardMeta(d),'raw':d,'notes':d['creation_notes']});}for(const e of MACHINE_TEMPLATES){c({'meta':machineMeta(e),'raw':e,'notes':e['creation_notes']});}for(const f of SERVICE_TEMPLATES){c({'meta':bodyMeta(f,'service',f['applicable_scenes'],f['industry_tags']),'raw':f,'notes':f['notes']});}for(const g of ORDER_TEMPLATES){c({'meta':bodyMeta(g,'order',g['applicable_scenes'],g['industry_tags']),'raw':g,'notes':g['notes']});}for(const h of PROGRESS_TEMPLATES){c({'meta':bodyMeta(h,'progress',h['applicable_scenes'],h['industry_tags']),'raw':h,'notes':h['notes']});}for(const i of ARBITRATION_TEMPLATES){c({'meta':bodyMeta(i,'arbitration',i['applicable_scenes'],i['industry_tags']),'raw':i,'notes':i['notes']});}for(const j of TREASURY_TEMPLATES){c({'meta':bodyMeta(j,'treasury',j['applicable_scenes'],j['industry_tags']),'raw':j,'notes':j['notes']});}for(const k of PERMISSION_TEMPLATES){c({'meta':bodyMeta(k,'permission',k['applicable_scenes'],k['industry_tags']),'raw':k,'notes':k['notes']});}for(const l of PASSPORT_TEMPLATES){c({'meta':bodyMeta(l,'passport',l['applicable_scenarios'],l['industry_tags']),'raw':l,'notes':l['notes']});}for(const m of ALLOCATION_TEMPLATES){c({'meta':bodyMeta(m,'allocation',m['applicable_scenes'],m['industry_tags']),'raw':m,'notes':m['notes']});}for(const n of REWARD_TEMPLATES){c({'meta':rewardMeta(n),'raw':n,'guidance':{'guardCondition':n['guardCondition'],'amountRange':n['amountRange'],'allocationStrategy':n['allocationStrategy'],'example':n['example'],'relevantGuardOps':n['relevantGuardOps']}});}for(const o of CONTACT_TEMPLATES){c({'meta':bodyMeta(o,'contact',o['applicable_scenes'],o['industry_tags']),'raw':o,'notes':o['notes']});}return ID_COLLISIONS=b,a;}function registry(){return!REGISTRY&&(REGISTRY=buildRegistry()),REGISTRY;}export function getTemplateIdCollisions(){return registry(),ID_COLLISIONS;}export function getTemplateCounts(){const a=Object['fromEntries'](TEMPLATE_OBJECT_TYPES['map'](b=>[b,0x0]));for(const b of registry()['values']()){a[b['meta']['object_type']]+=0x1;}return a;}export function listTemplates(a){const b=[...registry()['values']()]['map'](c=>c['meta']);return a?b['filter'](c=>c['object_type']===a):b;}export function getTemplateDetail(a){const b=registry()['get'](a);if(!b)return null;return{...b['meta'],'raw':b['raw'],...b['notes']?{'notes':b['notes']}:{},...b['guidance']?{'guidance':b['guidance']}:{}};}export function findTemplateObjectType(a){return registry()['get'](a)?.['meta']['object_type']??null;}export function instantiateTemplate(a,b){const c=registry()['get'](a);if(!c)return{'ok':![],'object_type':null,'template_id':a,'error':'Template\x20not\x20found:\x20'+a+'.\x20Use\x20get_templates\x20without\x20\x27template\x27\x20to\x20list\x20all\x20template\x20ids.'};const d=c['meta']['object_type'];if(!c['meta']['instantiable'])return{'ok':![],'object_type':d,'template_id':a,'error':'Reward\x20templates\x20are\x20guidance-only\x20(prose\x20guard\x20conditions)\x20and\x20cannot\x20be\x20'+'instantiated\x20into\x20executable\x20JSON.\x20Use\x20the\x20guidance\x20payload\x20to\x20design\x20the\x20'+'Reward\x20+\x20Guard\x20manually.','guidance':c['guidance']};switch(d){case'guard':{const e=fillGuardTemplate(a,b);if(!e['ok'])return{'ok':![],'object_type':d,'template_id':a,'error':e['error'],...e['missing']?{'missing_params':e['missing']}:{}};return{'ok':!![],'object_type':d,'template_id':a,'body':{'table':e['table'],'root':e['root']},...c['notes']?{'notes':c['notes']}:{}};}case'machine':{const f=a326a(a,b);if(!f['success'])return{'ok':![],'object_type':d,'template_id':a,'error':f['validation_errors']?.['join'](';\x20')??'Machine\x20template\x20fill\x20failed',...f['missing_params']?{'missing_params':f['missing_params']}:{}};return{'ok':!![],'object_type':d,'template_id':a,'body':{'nodes':f['filled_nodes'],'pairs':f['filled_pairs']},...c['notes']?{'notes':c['notes']}:{}};}case'service':{const g=fillServiceTemplate(a,b);if(!g['ok'])return{'ok':![],'object_type':d,'template_id':a,'error':g['error']??'Service\x20template\x20fill\x20failed',...g['missing_required']?{'missing_params':g['missing_required']}:{}};return{'ok':!![],'object_type':d,'template_id':a,'body':g['body'],...c['notes']?{'notes':c['notes']}:{}};}case'order':case'arbitration':case'treasury':case'permission':case'passport':case'allocation':case'progress':case'contact':{const h=fillBodyTemplate(d,a,b);if(!h['ok'])return{'ok':![],'object_type':d,'template_id':a,'error':h['error']};return{'ok':!![],'object_type':d,'template_id':a,'body':h['body'],...c['notes']?{'notes':c['notes']}:{}};}default:return{'ok':![],'object_type':d,'template_id':a,'error':'Instantiation\x20not\x20supported\x20for\x20object_type\x20\x27'+d+'\x27'};}}function fillBodyTemplate(a,b,c){switch(a){case'order':return a326b(b,c);case'arbitration':return a326c(b,c);case'treasury':return a326d(b,c);case'permission':return a326e(b,c);case'passport':return a326f(b,c);case'allocation':return a326g(b,c);case'progress':return fillProgressTemplate(b,c);case'contact':return a326h(b,c);default:return{'ok':![],'error':'No\x20body-template\x20fill\x20for\x20\x27'+a+'\x27'};}}
@@ -43,4 +43,37 @@ export declare function buildFeeParamLandingTable(t: IndustryTemplate, fee: Reco
43
43
  split_family: boolean;
44
44
  landings: FeeParamLanding[];
45
45
  }>;
46
+ export interface FeeParamCouplingMismatch {
47
+ key: string;
48
+ template_id: string;
49
+ param: string;
50
+ declared: number;
51
+ literals: number[];
52
+ }
53
+ export type FeeParamCouplingSource = Pick<IndustryTemplate, "guards" | "fee_params">;
54
+ export declare function feeParamCouplingMismatches(t: FeeParamCouplingSource): FeeParamCouplingMismatch[];
55
+ export type WindowMathSource = Pick<IndustryTemplate, "fee_params"> & {
56
+ settlement_window_merge?: readonly string[];
57
+ };
58
+ export interface WindowMathMismatch {
59
+ settle_param: string;
60
+ settle_value: number;
61
+ violates: string;
62
+ rule: "R-WINDOW-MATH-ZERO" | "R-WINDOW-MATH-UNDERCUT";
63
+ }
64
+ export declare function windowMathMismatches(t: WindowMathSource): WindowMathMismatch[];
65
+ export interface IncentiveProseSource {
66
+ trust_mechanisms?: readonly string[];
67
+ key_risk?: string;
68
+ user_inputs?: readonly string[];
69
+ differences?: readonly string[];
70
+ build_notes?: readonly string[];
71
+ }
72
+ export interface IncentiveRatingFloorClaim {
73
+ field: string;
74
+ claimed: number;
75
+ excerpt: string;
76
+ kind: "numeric" | "praise";
77
+ }
78
+ export declare function incentiveRatingFloorClaims(t: IncentiveProseSource): IncentiveRatingFloorClaim[];
46
79
  export declare function scanTemplate(raw: IndustryTemplate): TemplateScanResult;