@wowok/agent-mcp 2.7.1 → 2.7.3

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 (597) hide show
  1. package/dist/config/index.js +1 -1
  2. package/dist/config/runtime.js +1 -238
  3. package/dist/customer/account-events.d.ts +32 -0
  4. package/dist/customer/account-events.js +1 -0
  5. package/dist/customer/customer-advice.d.ts +1 -0
  6. package/dist/customer/customer-advice.js +1 -130
  7. package/dist/customer/index.js +1 -11
  8. package/dist/customer/industry-risks.js +1 -438
  9. package/dist/customer/info-puzzle.js +1 -681
  10. package/dist/customer/order-monitor.js +1 -328
  11. package/dist/customer/order-strategy.d.ts +1 -1
  12. package/dist/customer/order-strategy.js +1 -373
  13. package/dist/customer/post-purchase.js +1 -351
  14. package/dist/customer/preorder-compare.js +1 -34
  15. package/dist/customer/reminder-system.d.ts +2 -0
  16. package/dist/customer/reminder-system.js +1 -316
  17. package/dist/customer/risk-assessment.d.ts +1 -0
  18. package/dist/customer/risk-assessment.js +1 -397
  19. package/dist/customer/types.d.ts +2 -0
  20. package/dist/customer/types.js +1 -13
  21. package/dist/customer/user-preferences.js +1 -460
  22. package/dist/evaluation/arbitration-game.d.ts +9 -2
  23. package/dist/evaluation/arbitration-game.js +1 -48
  24. package/dist/evaluation/builtins/arbitration-score.d.ts +41 -0
  25. package/dist/evaluation/builtins/arbitration-score.js +1 -0
  26. package/dist/evaluation/builtins/demand-match.js +1 -153
  27. package/dist/evaluation/builtins/index.d.ts +1 -0
  28. package/dist/evaluation/builtins/index.js +1 -10
  29. package/dist/evaluation/builtins/service-risk.js +1 -55
  30. package/dist/evaluation/capability.js +1 -13
  31. package/dist/evaluation/category-match-rules.d.ts +30 -0
  32. package/dist/evaluation/category-match-rules.js +1 -0
  33. package/dist/evaluation/composer.js +1 -40
  34. package/dist/evaluation/engine.js +1 -175
  35. package/dist/evaluation/extract.js +1 -115
  36. package/dist/evaluation/game-strategy.d.ts +27 -0
  37. package/dist/evaluation/game-strategy.js +1 -0
  38. package/dist/evaluation/gap.js +1 -100
  39. package/dist/evaluation/index.d.ts +2 -0
  40. package/dist/evaluation/index.js +1 -11
  41. package/dist/evaluation/location-match.d.ts +42 -0
  42. package/dist/evaluation/location-match.js +1 -0
  43. package/dist/evaluation/node-game.d.ts +31 -3
  44. package/dist/evaluation/node-game.js +1 -57
  45. package/dist/evaluation/path-reasoning.d.ts +35 -0
  46. package/dist/evaluation/path-reasoning.js +1 -0
  47. package/dist/evaluation/region.d.ts +6 -0
  48. package/dist/evaluation/region.js +1 -36
  49. package/dist/evaluation/types.d.ts +18 -0
  50. package/dist/evaluation/types.js +1 -1
  51. package/dist/evaluation/user-injection.js +1 -27
  52. package/dist/experience/experience-reuse.js +1 -103
  53. package/dist/experience/index.js +1 -5
  54. package/dist/experience/intent-distill.js +1 -83
  55. package/dist/experience/realtime-feedback.js +1 -94
  56. package/dist/experience/types.js +1 -1
  57. package/dist/experience/user-profile.d.ts +1 -1
  58. package/dist/experience/user-profile.js +1 -171
  59. package/dist/extensions/business-modules.js +1 -287
  60. package/dist/extensions/capability-manifest.js +1 -781
  61. package/dist/extensions/constraint-registry.js +1 -198
  62. package/dist/extensions/index.d.ts +6 -0
  63. package/dist/extensions/index.js +1 -6
  64. package/dist/extensions/industry-layers.d.ts +75 -0
  65. package/dist/extensions/industry-layers.js +1 -0
  66. package/dist/extensions/industry-pack.d.ts +105 -0
  67. package/dist/extensions/industry-pack.js +1 -0
  68. package/dist/extensions/metric-registry.js +1 -257
  69. package/dist/extensions/mode-evaluator.d.ts +1 -1
  70. package/dist/extensions/mode-evaluator.js +1 -170
  71. package/dist/extensions/modes.js +1 -499
  72. package/dist/extensions/registry.d.ts +1 -0
  73. package/dist/extensions/registry.js +1 -717
  74. package/dist/extensions/types.js +1 -1
  75. package/dist/graph/base.d.ts +8 -0
  76. package/dist/graph/base.js +1 -0
  77. package/dist/harness/auto-escalation.js +1 -68
  78. package/dist/harness/checkpoint.js +1 -129
  79. package/dist/harness/index.d.ts +1 -0
  80. package/dist/harness/index.js +1 -78
  81. package/dist/harness/plan.d.ts +2 -0
  82. package/dist/harness/plan.js +1 -315
  83. package/dist/harness/recover.d.ts +1 -1
  84. package/dist/harness/recover.js +1 -139
  85. package/dist/harness/types.d.ts +2 -3
  86. package/dist/harness/types.js +1 -1
  87. package/dist/harness/verify.js +1 -237
  88. package/dist/index.js +1 -273
  89. package/dist/intent/enrich.js +1 -67
  90. package/dist/intent/index.js +1 -60
  91. package/dist/intent/matcher.js +1 -81
  92. package/dist/intent/store.js +1 -55
  93. package/dist/intent/types.js +1 -10
  94. package/dist/knowledge/acquisition-flywheel.js +1 -192
  95. package/dist/knowledge/allocation-confirm.js +1 -534
  96. package/dist/knowledge/allocation-context.js +1 -249
  97. package/dist/knowledge/allocation-ledger.js +1 -463
  98. package/dist/knowledge/allocation-puzzle.js +1 -298
  99. package/dist/knowledge/allocation-risk.js +1 -568
  100. package/dist/knowledge/allocation-templates.js +1 -970
  101. package/dist/knowledge/allocation-translation.js +1 -585
  102. package/dist/knowledge/anti-cheat.d.ts +37 -0
  103. package/dist/knowledge/anti-cheat.js +1 -0
  104. package/dist/knowledge/arb-confirm.d.ts +28 -0
  105. package/dist/knowledge/arb-confirm.js +1 -0
  106. package/dist/knowledge/arb-risk.js +1 -210
  107. package/dist/knowledge/arb-translation.d.ts +48 -0
  108. package/dist/knowledge/arb-translation.js +1 -0
  109. package/dist/knowledge/arbitration-confirm.js +1 -559
  110. package/dist/knowledge/arbitration-context.js +1 -505
  111. package/dist/knowledge/arbitration-ledger.js +1 -521
  112. package/dist/knowledge/arbitration-puzzle.js +1 -304
  113. package/dist/knowledge/arbitration-risk.js +1 -423
  114. package/dist/knowledge/arbitration-templates.js +1 -276
  115. package/dist/knowledge/arbitration-translation.js +1 -487
  116. package/dist/knowledge/audit-rules.js +1 -141
  117. package/dist/knowledge/bridge-confirm.d.ts +26 -0
  118. package/dist/knowledge/bridge-confirm.js +1 -0
  119. package/dist/knowledge/bridge-risk.js +1 -263
  120. package/dist/knowledge/bridge-translation.d.ts +37 -0
  121. package/dist/knowledge/bridge-translation.js +1 -0
  122. package/dist/knowledge/contact-confirm.d.ts +27 -0
  123. package/dist/knowledge/contact-confirm.js +1 -0
  124. package/dist/knowledge/contact-risk.js +1 -200
  125. package/dist/knowledge/contact-templates.js +1 -60
  126. package/dist/knowledge/contact-translation.d.ts +39 -0
  127. package/dist/knowledge/contact-translation.js +1 -0
  128. package/dist/knowledge/demand-confirm.js +1 -206
  129. package/dist/knowledge/demand-context.d.ts +17 -0
  130. package/dist/knowledge/demand-context.js +1 -0
  131. package/dist/knowledge/demand-ledger.d.ts +26 -0
  132. package/dist/knowledge/demand-ledger.js +1 -0
  133. package/dist/knowledge/demand-matching.js +1 -132
  134. package/dist/knowledge/demand-puzzle.d.ts +29 -0
  135. package/dist/knowledge/demand-puzzle.js +1 -0
  136. package/dist/knowledge/demand-risk.js +1 -240
  137. package/dist/knowledge/demand-templates.d.ts +12 -0
  138. package/dist/knowledge/demand-templates.js +1 -0
  139. package/dist/knowledge/demand-translation.js +1 -354
  140. package/dist/knowledge/deployment-scanner.js +1 -823
  141. package/dist/knowledge/dynamic-pricing.js +1 -87
  142. package/dist/knowledge/evidence-review.d.ts +12 -0
  143. package/dist/knowledge/evidence-review.js +1 -0
  144. package/dist/knowledge/examples-scanner-cli.js +1 -26
  145. package/dist/knowledge/examples-scanner.js +1 -843
  146. package/dist/knowledge/flywheel-loop.d.ts +0 -1
  147. package/dist/knowledge/flywheel-loop.js +1 -404
  148. package/dist/knowledge/fund-layer.js +1 -973
  149. package/dist/knowledge/glossary.js +1 -211
  150. package/dist/knowledge/guard-confirm.js +1 -406
  151. package/dist/knowledge/guard-context.js +1 -287
  152. package/dist/knowledge/guard-design-patterns.js +1 -360
  153. package/dist/knowledge/guard-ledger.js +1 -260
  154. package/dist/knowledge/guard-lint.js +1 -670
  155. package/dist/knowledge/guard-migration.d.ts +1 -1
  156. package/dist/knowledge/guard-migration.js +1 -228
  157. package/dist/knowledge/guard-puzzle.js +1 -805
  158. package/dist/knowledge/guard-render.js +1 -700
  159. package/dist/knowledge/guard-risk.js +1 -1879
  160. package/dist/knowledge/guard-submission-prompt.js +1 -171
  161. package/dist/knowledge/guard-templates.js +1 -1105
  162. package/dist/knowledge/guard-translation.js +1 -1119
  163. package/dist/knowledge/index.d.ts +71 -3
  164. package/dist/knowledge/index.js +1 -436
  165. package/dist/knowledge/industry-evolution.js +1 -323
  166. package/dist/knowledge/industry-generalizer.js +1 -381
  167. package/dist/knowledge/industry-registry.js +1 -174
  168. package/dist/knowledge/intent-metrics.d.ts +4 -3
  169. package/dist/knowledge/intent-metrics.js +1 -566
  170. package/dist/knowledge/machine-confirm.js +1 -559
  171. package/dist/knowledge/machine-context.js +1 -833
  172. package/dist/knowledge/machine-ledger.js +1 -338
  173. package/dist/knowledge/machine-puzzle.js +1 -494
  174. package/dist/knowledge/machine-render.js +1 -565
  175. package/dist/knowledge/machine-risk.js +1 -669
  176. package/dist/knowledge/machine-templates.js +1 -1597
  177. package/dist/knowledge/machine-topology.js +1 -234
  178. package/dist/knowledge/machine-translation.js +1 -513
  179. package/dist/knowledge/market-metrics.d.ts +12 -0
  180. package/dist/knowledge/market-metrics.js +1 -0
  181. package/dist/knowledge/market-operations.d.ts +46 -0
  182. package/dist/knowledge/market-operations.js +1 -0
  183. package/dist/knowledge/mcp-schema-audit-cli.js +1 -45
  184. package/dist/knowledge/mcp-schema-audit.d.ts +22 -22
  185. package/dist/knowledge/mcp-schema-audit.js +1 -777
  186. package/dist/knowledge/onchain-constants.js +1 -35
  187. package/dist/knowledge/order-confirm.js +1 -573
  188. package/dist/knowledge/order-context.js +1 -390
  189. package/dist/knowledge/order-ledger.js +1 -341
  190. package/dist/knowledge/order-puzzle.js +1 -255
  191. package/dist/knowledge/order-risk.js +1 -653
  192. package/dist/knowledge/order-templates.js +1 -368
  193. package/dist/knowledge/order-translation.js +1 -550
  194. package/dist/knowledge/overrides-loader.js +1 -65
  195. package/dist/knowledge/passport-confirm.js +1 -531
  196. package/dist/knowledge/passport-context.js +1 -306
  197. package/dist/knowledge/passport-ledger.js +1 -282
  198. package/dist/knowledge/passport-puzzle.js +1 -333
  199. package/dist/knowledge/passport-risk.js +1 -450
  200. package/dist/knowledge/passport-templates.js +1 -568
  201. package/dist/knowledge/passport-translation.js +1 -516
  202. package/dist/knowledge/payment-confirm.d.ts +26 -0
  203. package/dist/knowledge/payment-confirm.js +1 -0
  204. package/dist/knowledge/payment-risk.js +1 -249
  205. package/dist/knowledge/payment-translation.d.ts +37 -0
  206. package/dist/knowledge/payment-translation.js +1 -0
  207. package/dist/knowledge/permission-confirm.js +1 -426
  208. package/dist/knowledge/permission-context.js +1 -224
  209. package/dist/knowledge/permission-ledger.d.ts +11 -0
  210. package/dist/knowledge/permission-ledger.js +1 -403
  211. package/dist/knowledge/permission-puzzle.js +1 -173
  212. package/dist/knowledge/permission-risk.js +1 -411
  213. package/dist/knowledge/permission-templates.js +1 -234
  214. package/dist/knowledge/permission-translation.js +1 -350
  215. package/dist/knowledge/personal-confirm.d.ts +29 -0
  216. package/dist/knowledge/personal-confirm.js +1 -0
  217. package/dist/knowledge/personal-risk.js +1 -212
  218. package/dist/knowledge/personal-translation.d.ts +37 -0
  219. package/dist/knowledge/personal-translation.js +1 -0
  220. package/dist/knowledge/process-model.d.ts +1 -11
  221. package/dist/knowledge/process-model.js +1 -160
  222. package/dist/knowledge/progress-confirm.js +1 -456
  223. package/dist/knowledge/progress-context.js +1 -452
  224. package/dist/knowledge/progress-ledger.js +1 -330
  225. package/dist/knowledge/progress-puzzle.js +1 -219
  226. package/dist/knowledge/progress-risk.js +1 -461
  227. package/dist/knowledge/progress-templates.js +1 -228
  228. package/dist/knowledge/progress-translation.js +1 -405
  229. package/dist/knowledge/proof-confirm.js +1 -187
  230. package/dist/knowledge/proof-context.d.ts +17 -0
  231. package/dist/knowledge/proof-context.js +1 -0
  232. package/dist/knowledge/proof-ledger.d.ts +34 -0
  233. package/dist/knowledge/proof-ledger.js +1 -0
  234. package/dist/knowledge/proof-puzzle.d.ts +35 -0
  235. package/dist/knowledge/proof-puzzle.js +1 -0
  236. package/dist/knowledge/proof-risk.js +1 -207
  237. package/dist/knowledge/proof-templates.d.ts +22 -0
  238. package/dist/knowledge/proof-templates.js +1 -0
  239. package/dist/knowledge/proof-translation.js +1 -283
  240. package/dist/knowledge/registrar-confirm.d.ts +26 -0
  241. package/dist/knowledge/registrar-confirm.js +1 -0
  242. package/dist/knowledge/registrar-risk.js +1 -217
  243. package/dist/knowledge/registrar-translation.d.ts +37 -0
  244. package/dist/knowledge/registrar-translation.js +1 -0
  245. package/dist/knowledge/repository-confirm.js +1 -286
  246. package/dist/knowledge/repository-context.d.ts +12 -0
  247. package/dist/knowledge/repository-context.js +1 -0
  248. package/dist/knowledge/repository-ledger.d.ts +25 -0
  249. package/dist/knowledge/repository-ledger.js +1 -0
  250. package/dist/knowledge/repository-puzzle.d.ts +30 -0
  251. package/dist/knowledge/repository-puzzle.js +1 -0
  252. package/dist/knowledge/repository-risk.js +1 -373
  253. package/dist/knowledge/repository-templates.d.ts +14 -0
  254. package/dist/knowledge/repository-templates.js +1 -0
  255. package/dist/knowledge/repository-translation.js +1 -445
  256. package/dist/knowledge/reputation-rules.js +1 -99
  257. package/dist/knowledge/resource-confirm.d.ts +25 -0
  258. package/dist/knowledge/resource-confirm.js +1 -0
  259. package/dist/knowledge/resource-risk.js +1 -157
  260. package/dist/knowledge/resource-translation.d.ts +37 -0
  261. package/dist/knowledge/resource-translation.js +1 -0
  262. package/dist/knowledge/reward-confirm.js +1 -526
  263. package/dist/knowledge/reward-context.d.ts +2 -2
  264. package/dist/knowledge/reward-context.js +1 -504
  265. package/dist/knowledge/reward-ledger.js +1 -502
  266. package/dist/knowledge/reward-puzzle.js +1 -300
  267. package/dist/knowledge/reward-risk.js +1 -627
  268. package/dist/knowledge/reward-templates.js +1 -197
  269. package/dist/knowledge/reward-translation.js +1 -501
  270. package/dist/knowledge/safety-rules.d.ts +1 -0
  271. package/dist/knowledge/safety-rules.js +1 -404
  272. package/dist/knowledge/scenario-modes.js +1 -321
  273. package/dist/knowledge/service-confirm.js +1 -807
  274. package/dist/knowledge/service-context.js +1 -403
  275. package/dist/knowledge/service-ledger.js +1 -609
  276. package/dist/knowledge/service-puzzle.js +1 -236
  277. package/dist/knowledge/service-risk.d.ts +1 -1
  278. package/dist/knowledge/service-risk.js +1 -651
  279. package/dist/knowledge/service-templates.js +1 -456
  280. package/dist/knowledge/service-translation.js +1 -622
  281. package/dist/knowledge/template-registry.js +1 -353
  282. package/dist/knowledge/tool-constraints.js +1 -195
  283. package/dist/knowledge/tools-reference.js +1 -178
  284. package/dist/knowledge/treasury-confirm.js +1 -512
  285. package/dist/knowledge/treasury-context.js +1 -363
  286. package/dist/knowledge/treasury-ledger.js +1 -300
  287. package/dist/knowledge/treasury-puzzle.js +1 -216
  288. package/dist/knowledge/treasury-risk.js +1 -440
  289. package/dist/knowledge/treasury-templates.js +1 -358
  290. package/dist/knowledge/treasury-translation.js +1 -498
  291. package/dist/knowledge/trust-metrics.js +1 -198
  292. package/dist/knowledge/universal-template.d.ts +22 -0
  293. package/dist/knowledge/universal-template.js +1 -0
  294. package/dist/knowledge/util-confirm.d.ts +24 -0
  295. package/dist/knowledge/util-confirm.js +1 -0
  296. package/dist/knowledge/util-risk.js +1 -135
  297. package/dist/knowledge/util-translation.d.ts +38 -0
  298. package/dist/knowledge/util-translation.js +1 -0
  299. package/dist/knowledge/workflow-guidance.d.ts +116 -0
  300. package/dist/knowledge/workflow-guidance.js +1 -0
  301. package/dist/loop-engineering/aggregate.js +1 -132
  302. package/dist/loop-engineering/context-collect.js +1 -83
  303. package/dist/loop-engineering/diagnose.js +1 -273
  304. package/dist/loop-engineering/improve.js +1 -405
  305. package/dist/loop-engineering/index.js +1 -4
  306. package/dist/loop-engineering/pipeline.js +1 -56
  307. package/dist/mode-market/index.js +1 -3
  308. package/dist/mode-market/registry.js +1 -124
  309. package/dist/mode-market/review.js +1 -214
  310. package/dist/mode-market/submission.js +1 -85
  311. package/dist/participation/collaborator-interest.d.ts +23 -0
  312. package/dist/participation/collaborator-interest.js +1 -0
  313. package/dist/participation/customer-interest.d.ts +25 -0
  314. package/dist/participation/customer-interest.js +1 -0
  315. package/dist/participation/employee-kpi.d.ts +25 -0
  316. package/dist/participation/employee-kpi.js +1 -0
  317. package/dist/participation/employee-store.d.ts +16 -0
  318. package/dist/participation/employee-store.js +1 -0
  319. package/dist/participation/index.d.ts +2 -0
  320. package/dist/participation/index.js +1 -0
  321. package/dist/participation/merchant-interest.js +1 -100
  322. package/dist/participation/radar-core.d.ts +13 -3
  323. package/dist/participation/radar-core.js +1 -269
  324. package/dist/participation/supplier-interest.d.ts +25 -0
  325. package/dist/participation/supplier-interest.js +1 -0
  326. package/dist/persona/analyzer.js +1 -66
  327. package/dist/persona/bridge.js +1 -86
  328. package/dist/persona/defaults.js +1 -195
  329. package/dist/persona/experience-bridge.js +1 -23
  330. package/dist/persona/index.d.ts +9 -2
  331. package/dist/persona/index.js +1 -71
  332. package/dist/persona/local-region.d.ts +20 -0
  333. package/dist/persona/local-region.js +1 -0
  334. package/dist/persona/model.js +1 -111
  335. package/dist/persona/overrides.d.ts +10 -0
  336. package/dist/persona/overrides.js +1 -0
  337. package/dist/persona/pack-personae.d.ts +11 -0
  338. package/dist/persona/pack-personae.js +1 -0
  339. package/dist/persona/store.js +1 -62
  340. package/dist/persona/strategy-intent.d.ts +20 -0
  341. package/dist/persona/strategy-intent.js +1 -0
  342. package/dist/persona/types.d.ts +6 -2
  343. package/dist/persona/types.js +1 -5
  344. package/dist/project/business-puzzle.d.ts +1 -1
  345. package/dist/project/business-puzzle.js +1 -383
  346. package/dist/project/context-assembly.js +1 -254
  347. package/dist/project/deployment-bridge.js +1 -120
  348. package/dist/project/deployment-doc.js +1 -1126
  349. package/dist/project/edit-planner.js +1 -1342
  350. package/dist/project/evaluation.d.ts +37 -1
  351. package/dist/project/evaluation.js +1 -2011
  352. package/dist/project/game-theory.js +1 -177
  353. package/dist/project/graph-builder.js +1 -656
  354. package/dist/project/graph.d.ts +3 -6
  355. package/dist/project/graph.js +1 -340
  356. package/dist/project/handlers.d.ts +33 -2
  357. package/dist/project/handlers.js +1 -1784
  358. package/dist/project/index.d.ts +2 -0
  359. package/dist/project/index.js +1 -301
  360. package/dist/project/intent-analyzer.js +1 -149
  361. package/dist/project/machine-nodes.js +1 -36
  362. package/dist/project/merchant-guide.d.ts +19 -0
  363. package/dist/project/merchant-guide.js +1 -264
  364. package/dist/project/migration.js +1 -125
  365. package/dist/project/mode-actions.js +1 -309
  366. package/dist/project/namespace.js +1 -206
  367. package/dist/project/participation-radar.js +1 -428
  368. package/dist/project/pipeline-actions.js +1 -109
  369. package/dist/project/project-store.js +1 -422
  370. package/dist/project/query.js +1 -153
  371. package/dist/project/reverse-mapping.d.ts +34 -0
  372. package/dist/project/reverse-mapping.js +1 -0
  373. package/dist/project/risk-aggregator.js +1 -295
  374. package/dist/project/rollback-policy.js +1 -290
  375. package/dist/project/semantic-assembler.js +1 -345
  376. package/dist/project/semantic-graph.d.ts +3 -5
  377. package/dist/project/semantic-graph.js +1 -292
  378. package/dist/project/stage-gate.js +1 -369
  379. package/dist/project/substep-trace.js +1 -332
  380. package/dist/project/task-tracker.js +1 -78
  381. package/dist/project/workflow-design-assessment.d.ts +24 -0
  382. package/dist/project/workflow-design-assessment.js +1 -0
  383. package/dist/role/derivation.d.ts +18 -0
  384. package/dist/role/derivation.js +1 -0
  385. package/dist/role/index.d.ts +5 -0
  386. package/dist/role/index.js +1 -0
  387. package/dist/role/model.d.ts +8 -0
  388. package/dist/role/model.js +1 -0
  389. package/dist/role/resolution.d.ts +11 -0
  390. package/dist/role/resolution.js +1 -0
  391. package/dist/role/types.d.ts +11 -0
  392. package/dist/role/types.js +1 -0
  393. package/dist/rules.js +1 -52
  394. package/dist/safety/confirm-gate.d.ts +1 -1
  395. package/dist/safety/confirm-gate.js +1 -88
  396. package/dist/safety/index.js +1 -3
  397. package/dist/safety/preview.js +1 -52
  398. package/dist/schema/call/allocation.d.ts +186 -1385
  399. package/dist/schema/call/allocation.js +1 -34
  400. package/dist/schema/call/arbitration.d.ts +272 -1871
  401. package/dist/schema/call/arbitration.js +1 -113
  402. package/dist/schema/call/base.d.ts +1831 -9076
  403. package/dist/schema/call/base.js +1 -370
  404. package/dist/schema/call/bridge.d.ts +911 -3171
  405. package/dist/schema/call/bridge.js +1 -458
  406. package/dist/schema/call/contact.d.ts +135 -931
  407. package/dist/schema/call/contact.js +1 -37
  408. package/dist/schema/call/demand.d.ts +164 -1194
  409. package/dist/schema/call/demand.js +1 -47
  410. package/dist/schema/call/guard.d.ts +298 -1140
  411. package/dist/schema/call/guard.js +1 -161
  412. package/dist/schema/call/handler.js +1 -322
  413. package/dist/schema/call/index.js +1 -20
  414. package/dist/schema/call/machine.d.ts +459 -5403
  415. package/dist/schema/call/machine.js +1 -193
  416. package/dist/schema/call/order.d.ts +137 -844
  417. package/dist/schema/call/order.js +1 -35
  418. package/dist/schema/call/payment.d.ts +74 -561
  419. package/dist/schema/call/payment.js +1 -37
  420. package/dist/schema/call/permission-handler.js +1 -54
  421. package/dist/schema/call/permission.d.ts +335 -2791
  422. package/dist/schema/call/permission.js +1 -105
  423. package/dist/schema/call/personal.d.ts +227 -1814
  424. package/dist/schema/call/personal.js +1 -78
  425. package/dist/schema/call/progress.d.ts +140 -843
  426. package/dist/schema/call/progress.js +1 -47
  427. package/dist/schema/call/proof.d.ts +42 -258
  428. package/dist/schema/call/proof.js +1 -33
  429. package/dist/schema/call/repository.d.ts +324 -2222
  430. package/dist/schema/call/repository.js +1 -77
  431. package/dist/schema/call/reward.d.ts +153 -1183
  432. package/dist/schema/call/reward.js +1 -30
  433. package/dist/schema/call/semantic.js +1 -1679
  434. package/dist/schema/call/service.d.ts +376 -3431
  435. package/dist/schema/call/service.js +1 -184
  436. package/dist/schema/call/treasury.d.ts +252 -2158
  437. package/dist/schema/call/treasury.js +1 -71
  438. package/dist/schema/common/index.d.ts +222 -697
  439. package/dist/schema/common/index.js +1 -407
  440. package/dist/schema/config/index.d.ts +18 -161
  441. package/dist/schema/config/index.js +1 -68
  442. package/dist/schema/employee/index.d.ts +99 -0
  443. package/dist/schema/employee/index.js +1 -0
  444. package/dist/schema/evaluation/index.d.ts +1062 -3748
  445. package/dist/schema/evaluation/index.js +1 -356
  446. package/dist/schema/index.d.ts +3 -0
  447. package/dist/schema/index.js +1 -17
  448. package/dist/schema/industry-pack/index.d.ts +132 -0
  449. package/dist/schema/industry-pack/index.js +1 -0
  450. package/dist/schema/intent-radar/index.d.ts +92 -245
  451. package/dist/schema/intent-radar/index.js +1 -89
  452. package/dist/schema/local/index.d.ts +2045 -18080
  453. package/dist/schema/local/index.js +1 -927
  454. package/dist/schema/local/wip.d.ts +61 -651
  455. package/dist/schema/local/wip.js +1 -187
  456. package/dist/schema/messenger/index.d.ts +949 -5557
  457. package/dist/schema/messenger/index.js +1 -475
  458. package/dist/schema/operations.d.ts +2969 -26518
  459. package/dist/schema/operations.js +1 -520
  460. package/dist/schema/persona/index.d.ts +469 -1820
  461. package/dist/schema/persona/index.js +1 -148
  462. package/dist/schema/project/index.d.ts +1027 -8408
  463. package/dist/schema/project/index.js +1 -2057
  464. package/dist/schema/query/index.d.ts +12041 -75261
  465. package/dist/schema/query/index.js +1 -1646
  466. package/dist/schema/schema-query/index.d.ts +35 -98
  467. package/dist/schema/schema-query/index.js +1 -104
  468. package/dist/schema/schema-version.js +1 -76
  469. package/dist/schema/task-status.d.ts +26 -132
  470. package/dist/schema/task-status.js +1 -36
  471. package/dist/schema/trust/index.d.ts +194 -1290
  472. package/dist/schema/trust/index.js +1 -314
  473. package/dist/schema/utils/guard-parser.js +1 -419
  474. package/dist/schema/utils/guard-query-utils.js +1 -46
  475. package/dist/schema/utils/node-parser.js +1 -369
  476. package/dist/schema/utils/object-type-utils.js +1 -35
  477. package/dist/schema/utils/permission-index-utils.js +1 -7
  478. package/dist/schema/utils/permission-machine-check.js +1 -121
  479. package/dist/schema/utils/skills-recommendation.d.ts +1 -0
  480. package/dist/schema/utils/skills-recommendation.js +1 -77
  481. package/dist/schema/workspace/index.d.ts +69 -0
  482. package/dist/schema/workspace/index.js +1 -0
  483. package/dist/schema-query-impl/index.js +1 -0
  484. package/dist/schemas/account_operation.output.json +3147 -1652
  485. package/dist/schemas/account_operation.schema.json +225 -218
  486. package/dist/schemas/bridge_operation.output.json +1168 -650
  487. package/dist/schemas/bridge_operation.schema.json +736 -504
  488. package/dist/schemas/config_operation.output.json +185 -179
  489. package/dist/schemas/config_operation.schema.json +21 -26
  490. package/dist/schemas/employee_operation.output.json +207 -0
  491. package/dist/schemas/employee_operation.schema.json +176 -0
  492. package/dist/schemas/evaluation_operation.output.json +2329 -557
  493. package/dist/schemas/evaluation_operation.schema.json +2939 -720
  494. package/dist/schemas/guard2file.output.json +58 -64
  495. package/dist/schemas/guard2file.schema.json +79 -81
  496. package/dist/schemas/index.json +29 -11
  497. package/dist/schemas/industry_pack_operation.output.json +594 -0
  498. package/dist/schemas/industry_pack_operation.schema.json +55 -0
  499. package/dist/schemas/intent_radar.output.json +275 -200
  500. package/dist/schemas/intent_radar.schema.json +124 -123
  501. package/dist/schemas/local_info_operation.output.json +1174 -657
  502. package/dist/schemas/local_info_operation.schema.json +119 -125
  503. package/dist/schemas/local_mark_operation.output.json +1239 -689
  504. package/dist/schemas/local_mark_operation.schema.json +91 -96
  505. package/dist/schemas/machineNode2file.output.json +63 -69
  506. package/dist/schemas/machineNode2file.schema.json +79 -81
  507. package/dist/schemas/messenger_operation.output.json +2722 -1528
  508. package/dist/schemas/messenger_operation.schema.json +1482 -1264
  509. package/dist/schemas/onchain_events.output.json +2590 -975
  510. package/dist/schemas/onchain_events.schema.json +117 -99
  511. package/dist/schemas/onchain_operations.output.json +3957 -2309
  512. package/dist/schemas/onchain_operations.schema.json +20799 -9285
  513. package/dist/schemas/onchain_operations_allocation.schema.json +172 -108
  514. package/dist/schemas/onchain_operations_arbitration.schema.json +233 -146
  515. package/dist/schemas/onchain_operations_contact.schema.json +129 -90
  516. package/dist/schemas/onchain_operations_demand.schema.json +170 -112
  517. package/dist/schemas/onchain_operations_gen_passport.schema.json +61 -646
  518. package/dist/schemas/onchain_operations_gen_proof.schema.json +40 -172
  519. package/dist/schemas/onchain_operations_guard.schema.json +3765 -294
  520. package/dist/schemas/onchain_operations_machine.schema.json +537 -164
  521. package/dist/schemas/onchain_operations_order.schema.json +126 -96
  522. package/dist/schemas/onchain_operations_payment.schema.json +82 -67
  523. package/dist/schemas/onchain_operations_permission.schema.json +331 -93
  524. package/dist/schemas/onchain_operations_personal.schema.json +636 -96
  525. package/dist/schemas/onchain_operations_progress.schema.json +125 -92
  526. package/dist/schemas/onchain_operations_proof.schema.json +76 -69
  527. package/dist/schemas/onchain_operations_repository.schema.json +636 -249
  528. package/dist/schemas/onchain_operations_reward.schema.json +218 -108
  529. package/dist/schemas/onchain_operations_service.schema.json +679 -221
  530. package/dist/schemas/onchain_operations_treasury.schema.json +401 -135
  531. package/dist/schemas/onchain_table_data.output.json +6018 -2430
  532. package/dist/schemas/onchain_table_data.schema.json +544 -430
  533. package/dist/schemas/persona_operation.output.json +1568 -265
  534. package/dist/schemas/persona_operation.schema.json +346 -202
  535. package/dist/schemas/project_operation.output.json +6957 -5147
  536. package/dist/schemas/project_operation.schema.json +1050 -1020
  537. package/dist/schemas/query_task_status.output.json +195 -99
  538. package/dist/schemas/query_task_status.schema.json +12 -18
  539. package/dist/schemas/query_toolkit.output.json +18870 -14566
  540. package/dist/schemas/query_toolkit.schema.json +614 -522
  541. package/dist/schemas/schema_query.output.json +127 -129
  542. package/dist/schemas/schema_query.schema.json +64 -69
  543. package/dist/schemas/trust_score.output.json +678 -587
  544. package/dist/schemas/trust_score.schema.json +289 -277
  545. package/dist/schemas/wip_file.output.json +116 -124
  546. package/dist/schemas/wip_file.schema.json +142 -143
  547. package/dist/schemas/workspace_operation.output.json +277 -0
  548. package/dist/schemas/workspace_operation.schema.json +45 -0
  549. package/dist/schemas/wowok_buildin_info.output.json +1693 -723
  550. package/dist/schemas/wowok_buildin_info.schema.json +576 -512
  551. package/dist/telemetry/index.js +1 -112
  552. package/dist/telemetry/redact.js +1 -23
  553. package/dist/telemetry/storage.js +1 -80
  554. package/dist/tools/handlers/bridge.d.ts +8 -1
  555. package/dist/tools/handlers/bridge.js +1 -1
  556. package/dist/tools/handlers/config.js +1 -74
  557. package/dist/tools/handlers/employee.d.ts +2 -0
  558. package/dist/tools/handlers/employee.js +1 -0
  559. package/dist/tools/handlers/evaluation.js +1 -123
  560. package/dist/tools/handlers/file-export.js +1 -90
  561. package/dist/tools/handlers/industry-pack.d.ts +2 -0
  562. package/dist/tools/handlers/industry-pack.js +1 -0
  563. package/dist/tools/handlers/intent-radar.js +1 -76
  564. package/dist/tools/handlers/local.js +1 -53
  565. package/dist/tools/handlers/messenger.js +1 -188
  566. package/dist/tools/handlers/onchain.js +1 -1180
  567. package/dist/tools/handlers/persona.js +1 -89
  568. package/dist/tools/handlers/project.js +1 -211
  569. package/dist/tools/handlers/query.js +1 -434
  570. package/dist/tools/handlers/schema-query.js +1 -176
  571. package/dist/tools/handlers/task-status.js +1 -26
  572. package/dist/tools/handlers/trust.js +1 -380
  573. package/dist/tools/handlers/wip.js +1 -90
  574. package/dist/tools/handlers/workspace.d.ts +2 -0
  575. package/dist/tools/handlers/workspace.js +1 -0
  576. package/dist/tools/index.d.ts +2 -1
  577. package/dist/tools/index.js +1 -1382
  578. package/dist/tools/retry.js +1 -85
  579. package/dist/tools/rules-hook.d.ts +1 -1
  580. package/dist/tools/rules-hook.js +1 -23
  581. package/dist/tools/shared.d.ts +1 -1
  582. package/dist/tools/shared.js +1 -130
  583. package/dist/tools/types.d.ts +2 -1
  584. package/dist/tools/types.js +1 -1
  585. package/dist/tools/upgrade-check.d.ts +19 -0
  586. package/dist/tools/upgrade-check.js +1 -0
  587. package/dist/tools/wip-deploy-assist.js +1 -306
  588. package/dist/tools/wrap.js +1 -500
  589. package/package.json +7 -6
  590. package/dist/knowledge/arbitration-trust.d.ts +0 -24
  591. package/dist/knowledge/arbitration-trust.js +0 -117
  592. package/dist/schema/call/bridge-handler.d.ts +0 -8
  593. package/dist/schema/call/bridge-handler.js +0 -265
  594. package/dist/schema/sync-layer4.d.ts +0 -21
  595. package/dist/schema/sync-layer4.js +0 -286
  596. package/dist/schema-query/index.js +0 -810
  597. /package/dist/{schema-query → schema-query-impl}/index.d.ts +0 -0
@@ -1,717 +1 @@
1
- import { UserModeStorage } from "@wowok/wowok";
2
- import { CapabilityRegistry } from "./capability-manifest.js";
3
- import { ModeEvaluator } from "./mode-evaluator.js";
4
- import { MetricRegistry } from "./metric-registry.js";
5
- import { ConstraintRegistry } from "./constraint-registry.js";
6
- import { BUILTIN_MODES } from "./modes.js";
7
- export class IndustryModeRegistry {
8
- static instance;
9
- registrations = new Map();
10
- userModes = new Map();
11
- aliases = new Map();
12
- evaluator;
13
- initialized = false;
14
- persistence = new UserModeStorage();
15
- userModesLoaded = false;
16
- static Instance() {
17
- if (!IndustryModeRegistry.instance) {
18
- IndustryModeRegistry.instance = new IndustryModeRegistry();
19
- }
20
- return IndustryModeRegistry.instance;
21
- }
22
- constructor() {
23
- this.evaluator = new ModeEvaluator(CapabilityRegistry.Instance(), MetricRegistry.Instance(), ConstraintRegistry.Instance());
24
- this.registerBuiltinModes();
25
- this.initialized = true;
26
- }
27
- registerMode(mode, aliases) {
28
- if (!mode.name || !mode.traits || !mode.machine_shape) {
29
- console.warn(`[IndustryModeRegistry] registerMode rejected: invalid mode ` +
30
- `(name=${mode.name || "<missing>"}, traits=${mode.traits ? "ok" : "<missing>"}, ` +
31
- `machine_shape=${mode.machine_shape ? "ok" : "<missing>"}).`);
32
- return false;
33
- }
34
- if (this.registrations.has(mode.name)) {
35
- const existing = this.registrations.get(mode.name);
36
- console.warn(`[IndustryModeRegistry] registerMode rejected: mode '${mode.name}' already registered ` +
37
- `(registered_at=${new Date(existing?.registered_at ?? 0).toISOString()}). ` +
38
- `Use evolveMode/deriveMode for user modifications, or unregister first.`);
39
- return false;
40
- }
41
- this.registrations.set(mode.name, {
42
- mode,
43
- aliases,
44
- enabled: true,
45
- registered_at: Date.now(),
46
- });
47
- if (aliases) {
48
- for (const alias of aliases) {
49
- this.aliases.set(alias, mode.name);
50
- }
51
- }
52
- return true;
53
- }
54
- getMode(name) {
55
- const canonical = this.resolveAlias(name);
56
- return this.registrations.get(canonical)?.mode;
57
- }
58
- listModes() {
59
- return Array.from(this.registrations.values())
60
- .filter(r => r.enabled)
61
- .map(r => r.mode);
62
- }
63
- resolveAlias(name) {
64
- return this.aliases.get(name) ?? name;
65
- }
66
- hasMode(name) {
67
- const canonical = this.resolveAlias(name);
68
- return this.registrations.has(canonical);
69
- }
70
- evaluateMode(name, intent, context) {
71
- const mode = this.getMode(name);
72
- if (!mode) {
73
- return {
74
- applicable: false,
75
- risk_score: 100,
76
- benefit_score: 0,
77
- risk_benefit_ratio: 0,
78
- capability_conflicts: [],
79
- violated_constraints: [],
80
- unmet_conditions: [`Mode '${name}' not found`],
81
- recommendations: [`Mode '${name}' not registered, falling back to 'general'`],
82
- };
83
- }
84
- return this.evaluator.evaluateMode(mode, intent, context);
85
- }
86
- evaluateMigration(sourceName, targetName) {
87
- const source = this.getMode(sourceName);
88
- const target = this.getMode(targetName);
89
- if (!source || !target) {
90
- return {
91
- feasibility_score: 0,
92
- source_risk_score: 0,
93
- target_risk_score: 0,
94
- source_benefit_score: 0,
95
- target_benefit_score: 0,
96
- risk_delta: 0,
97
- benefit_delta: 0,
98
- added_capabilities: [],
99
- removed_capabilities: [],
100
- conflicting_capabilities: [],
101
- recommendations: [`Mode '${sourceName}' or '${targetName}' not found`],
102
- };
103
- }
104
- return this.evaluator.evaluateMigration(source, target);
105
- }
106
- async registerUserMode(mode, userId) {
107
- await this.ensureUserModesLoaded();
108
- if (!mode.name || !mode.owner || !mode.machine_shape)
109
- return false;
110
- if (mode.source !== "custom")
111
- return false;
112
- if (mode.owner !== userId)
113
- return false;
114
- const userKey = this.userModeKey(mode.owner, mode.name);
115
- if (this.registrations.has(mode.name))
116
- return false;
117
- if (this.userModes.has(userKey))
118
- return false;
119
- if (!mode.evolution_history || mode.evolution_history.length === 0) {
120
- mode.evolution_history = [{
121
- version: mode.version || "v1",
122
- changed_at: Date.now(),
123
- changes: ["Initial registration (registerUserMode)"],
124
- }];
125
- }
126
- this.userModes.set(userKey, mode);
127
- await this.persistUserMode(mode);
128
- return true;
129
- }
130
- async deriveMode(sourceMode, modifications, userId, newName, newDisplayName) {
131
- await this.ensureUserModesLoaded();
132
- const source = this.getMode(sourceMode);
133
- if (!source)
134
- return undefined;
135
- if (!newName || this.registrations.has(newName))
136
- return undefined;
137
- const userKey = this.userModeKey(userId, newName);
138
- if (this.userModes.has(userKey))
139
- return undefined;
140
- const derived = {
141
- name: newName,
142
- display_name: newDisplayName ?? newName,
143
- version: "v1",
144
- source: "custom",
145
- traits: modifications.traits ?? source.traits,
146
- machine_shape: modifications.machine_shape ?? source.machine_shape,
147
- guards: modifications.guards ?? source.guards,
148
- allocator: modifications.allocator ?? source.allocator,
149
- risk_checks: modifications.risk_checks ?? source.risk_checks,
150
- needs: modifications.needs ?? source.needs,
151
- flywheel: modifications.flywheel ?? source.flywheel,
152
- key_risk: modifications.key_risk ?? source.key_risk,
153
- build_notes: modifications.build_notes ?? source.build_notes,
154
- capabilities_used: modifications.capabilities_used ?? source.capabilities_used,
155
- config_overrides: modifications.config_overrides ?? source.config_overrides,
156
- config_override_rules: modifications.config_override_rules ?? source.config_override_rules,
157
- expected_benefits: modifications.expected_benefits ?? source.expected_benefits,
158
- risk_appetite: modifications.risk_appetite ?? source.risk_appetite,
159
- risk_constraints: modifications.risk_constraints ?? source.risk_constraints,
160
- applicable_conditions: modifications.applicable_conditions ?? source.applicable_conditions,
161
- similar_industries: modifications.similar_industries ?? source.similar_industries,
162
- novel_capabilities: modifications.novel_capabilities ?? source.novel_capabilities,
163
- owner: userId,
164
- derived_from: sourceMode,
165
- custom_metrics: modifications.custom_metrics ?? source.custom_metrics,
166
- custom_constraints: modifications.custom_constraints ?? source.custom_constraints,
167
- evolution_history: [{
168
- version: "v1",
169
- changed_at: Date.now(),
170
- changes: [`Derived from builtin '${sourceMode}'`],
171
- }],
172
- };
173
- this.userModes.set(userKey, derived);
174
- await this.persistUserMode(derived);
175
- return derived;
176
- }
177
- async evolveMode(modeName, updates, userId, changeDescription, bumpVersion = true) {
178
- await this.ensureUserModesLoaded();
179
- const userKey = this.userModeKey(userId, modeName);
180
- const existing = this.userModes.get(userKey);
181
- if (!existing)
182
- return undefined;
183
- const newVersion = bumpVersion
184
- ? this.bumpPatchVersion(existing.version)
185
- : existing.version;
186
- const evolved = {
187
- ...existing,
188
- ...updates,
189
- name: existing.name,
190
- owner: existing.owner,
191
- source: "custom",
192
- derived_from: existing.derived_from,
193
- evolution_history: [
194
- ...(existing.evolution_history ?? []),
195
- {
196
- version: newVersion,
197
- changed_at: Date.now(),
198
- changes: [changeDescription],
199
- },
200
- ],
201
- version: newVersion,
202
- };
203
- this.userModes.set(userKey, evolved);
204
- await this.persistUserMode(evolved);
205
- return evolved;
206
- }
207
- async listUserModes(userId) {
208
- await this.ensureUserModesLoaded();
209
- const result = [];
210
- for (const mode of this.userModes.values()) {
211
- if (mode.owner === userId) {
212
- result.push(mode);
213
- }
214
- }
215
- return result;
216
- }
217
- async getUserMode(modeName, userId) {
218
- await this.ensureUserModesLoaded();
219
- const userKey = this.userModeKey(userId, modeName);
220
- return this.userModes.get(userKey);
221
- }
222
- async unregisterUserMode(modeName, userId) {
223
- await this.ensureUserModesLoaded();
224
- const userKey = this.userModeKey(userId, modeName);
225
- const removed = this.userModes.delete(userKey);
226
- if (removed) {
227
- await this.unpersistUserMode(userId, modeName);
228
- }
229
- return removed;
230
- }
231
- userModeKey(owner, name) {
232
- return `${owner}:${name}`;
233
- }
234
- async ensureUserModesLoaded() {
235
- if (this.userModesLoaded)
236
- return;
237
- this.userModesLoaded = true;
238
- try {
239
- const rows = await this.persistence.list();
240
- for (const row of rows) {
241
- try {
242
- const mode = JSON.parse(row.data);
243
- if (mode?.name && mode?.owner && mode?.machine_shape) {
244
- this.userModes.set(this.userModeKey(row.owner, row.name), mode);
245
- }
246
- }
247
- catch {
248
- console.warn(`[IndustryModeRegistry] Skipping corrupt user_modes row '${row.owner}:${row.name}'.`);
249
- }
250
- }
251
- }
252
- catch (err) {
253
- console.warn("[IndustryModeRegistry] Failed to load persisted user modes:", err.message);
254
- }
255
- }
256
- async persistUserMode(mode) {
257
- try {
258
- await this.persistence.save(mode.owner, mode.name, JSON.stringify(mode));
259
- }
260
- catch (err) {
261
- console.warn(`[IndustryModeRegistry] Failed to persist user mode '${mode.owner}:${mode.name}':`, err.message);
262
- }
263
- }
264
- async unpersistUserMode(owner, name) {
265
- try {
266
- await this.persistence.delete(owner, name);
267
- }
268
- catch (err) {
269
- console.warn(`[IndustryModeRegistry] Failed to delete persisted user mode '${owner}:${name}':`, err.message);
270
- }
271
- }
272
- bumpPatchVersion(version) {
273
- const stripped = version.replace(/^v/, "");
274
- const parts = stripped.split(".");
275
- if (parts.length < 2)
276
- return `v${stripped}.1`;
277
- const patch = parseInt(parts[1] ?? "0", 10);
278
- parts[1] = String(patch + 1);
279
- return `v${parts.join(".")}`;
280
- }
281
- async applyTemplate(name, intent, context) {
282
- const builtinMode = this.getMode(name);
283
- if (builtinMode) {
284
- const blueprint = this.doApplyTemplate(builtinMode, intent, context);
285
- this.recordCapabilitiesUsed(builtinMode);
286
- return blueprint;
287
- }
288
- if (name.includes(":")) {
289
- const [owner, modeName] = name.split(":", 2);
290
- const userMode = await this.getUserMode(modeName, owner);
291
- if (userMode) {
292
- const blueprint = this.doApplyTemplate(userMode, intent, context);
293
- this.recordCapabilitiesUsed(userMode);
294
- return blueprint;
295
- }
296
- }
297
- const general = this.getMode("general");
298
- if (!general) {
299
- throw new Error("IndustryMode 'general' not registered — cannot fallback");
300
- }
301
- const blueprint = this.doApplyTemplate(general, intent, context);
302
- this.recordCapabilitiesUsed(general);
303
- return blueprint;
304
- }
305
- async applyUserMode(modeName, userId, intent, context) {
306
- const userMode = await this.getUserMode(modeName, userId);
307
- if (!userMode) {
308
- throw new Error(`User mode '${modeName}' not found for user '${userId}'`);
309
- }
310
- const blueprint = this.doApplyTemplate(userMode, intent, context);
311
- this.recordCapabilitiesUsed(userMode);
312
- return blueprint;
313
- }
314
- doApplyTemplate(mode, intent, context) {
315
- let objects = this.buildObjects(mode, intent, context);
316
- objects = this.applyConfigOverrides(mode, objects);
317
- objects = this.applyConfigOverrideRules(mode, objects, intent, context);
318
- const edges = this.buildEdges(objects, context);
319
- const steps = this.buildSteps(objects, edges, context.network);
320
- const scenarios = this.defaultScenarios(mode, intent, objects);
321
- const validation = this.validateBlueprint(objects, edges, mode);
322
- if (validation.errors.length > 0) {
323
- throw new Error(`Blueprint validation for mode '${mode.name}' failed with ${validation.errors.length} CRITICAL error(s):\n` +
324
- validation.errors.map((e, i) => ` ${i + 1}. ${e}`).join("\n"));
325
- }
326
- if (validation.warnings.length > 0) {
327
- console.warn(`[IndustryModeRegistry] Blueprint validation for '${mode.name}' produced ${validation.warnings.length} warning(s):`, validation.warnings);
328
- }
329
- return {
330
- context,
331
- objects,
332
- edges,
333
- steps,
334
- scenarios,
335
- industry_source: mode.name,
336
- applied_template: `${mode.name}@${mode.version}`,
337
- validation,
338
- };
339
- }
340
- validateBlueprint(objects, edges, mode) {
341
- const errors = [];
342
- const warnings = [];
343
- const machine = objects.find(o => o.object_type === "machine");
344
- const service = objects.find(o => o.object_type === "service");
345
- if (machine) {
346
- const hint = machine.config.entry_node_forward_hint;
347
- if (!hint) {
348
- warnings.push("Machine blueprint missing entry_node_forward_hint. " +
349
- "The AI must ensure the entry node (prev_node='') has ≥1 forward when constructing the Machine creation call (P0-2).");
350
- }
351
- else if (hint.required === true && !hint.example_forward) {
352
- warnings.push("Machine entry_node_forward_hint marked required but example_forward is missing.");
353
- }
354
- const nodes = machine.config.nodes;
355
- if (!nodes || nodes.length === 0) {
356
- errors.push(`Machine blueprint has no nodes — mode '${mode.name}' machine_shape is empty. ` +
357
- `Add nodes to the mode's machine_shape before applying template.`);
358
- }
359
- }
360
- if (service) {
361
- const compensationFundRef = service.config.compensation_fund;
362
- if (compensationFundRef) {
363
- errors.push(`Service blueprint has compensation_fund='${compensationFundRef}' (string reference). ` +
364
- `BUG: compensation_fund is Balance<T> (numeric), NOT a Treasury object reference. ` +
365
- `Remove compensation_fund field and use compensation_fund_balance + compensation_fund_add_hint instead. ` +
366
- `Smart contract (service.move:179): compensation_fund: Balance<T>.`);
367
- }
368
- const balanceField = service.config.compensation_fund_balance;
369
- if (balanceField === undefined) {
370
- warnings.push("Service blueprint missing compensation_fund_balance. " +
371
- "Should be 0 (initial Balance<T> state) — filled via service.compensation_fund_add(coin).");
372
- }
373
- }
374
- const objectIds = new Set(objects.map(o => o.entry_id));
375
- const objectNames = new Set(objects.map(o => o.name));
376
- for (const edge of edges) {
377
- const fromOk = objectIds.has(edge.from) || objectNames.has(edge.from);
378
- const toOk = objectIds.has(edge.to) || objectNames.has(edge.to);
379
- if (!fromOk || !toOk) {
380
- errors.push(`Edge '${edge.from}' → '${edge.to}' (kind='${edge.edge_kind}') references undefined object. ` +
381
- `from_exists=${fromOk}, to_exists=${toOk}.`);
382
- }
383
- }
384
- return { errors, warnings };
385
- }
386
- buildObjects(mode, intent, context) {
387
- const prefix = context.prefix;
388
- const objects = [];
389
- objects.push(this.makeObject("permission", `${prefix}_permission`, {
390
- name: `${prefix}_permission`,
391
- description: `Permission: role permission index (${mode.display_name})`,
392
- permission_indexes: this.buildPermissionIndexes(mode),
393
- tags: [`industry:${mode.name}`],
394
- }));
395
- const serviceGuardName = this.getFirstServiceGuardName(mode, prefix);
396
- for (const guard of mode.guards) {
397
- const shortName = this.deriveGuardShortName(guard.template_id);
398
- const guardName = `${prefix}_guard_${shortName}`;
399
- objects.push(this.makeObject("guard", guardName, {
400
- name: guardName,
401
- description: `Guard: ${guard.purpose} (${mode.display_name})`,
402
- host: guard.host,
403
- template_id: guard.template_id,
404
- tags: [`industry:${mode.name}`, `host:${guard.host}`],
405
- }));
406
- }
407
- objects.push(this.makeObject("machine", `${prefix}_machine`, {
408
- name: `${prefix}_machine`,
409
- description: `Machine: workflow topology (${mode.display_name}) — ${mode.machine_shape.length} nodes`,
410
- nodes: mode.machine_shape.map(n => ({ name: n.name, role: n.role })),
411
- guard_objects: mode.guards
412
- .filter(g => g.host === "machine")
413
- .map(g => ({
414
- template_id: g.template_id,
415
- object_name: `${prefix}_guard_${this.deriveGuardShortName(g.template_id)}`,
416
- purpose: g.purpose,
417
- })),
418
- permission: `${prefix}_permission`,
419
- entry_node_forward_hint: {
420
- entry_node_name: mode.machine_shape[0]?.name ?? "paid",
421
- required: true,
422
- example_forward: {
423
- next_node: mode.machine_shape[0]?.name ?? "paid",
424
- namedOperator: "",
425
- weight: 1,
426
- },
427
- reason: "Progress starts at current='' and follows the entry node's forwards. " +
428
- "Without a forward, Progress is permanently stuck (P0-2). " +
429
- "Schema refinement in MachineNodePairSchema enforces this at publish time.",
430
- },
431
- tags: [`industry:${mode.name}`],
432
- }, true));
433
- objects.push(this.makeObject("treasury", `${prefix}_treasury`, {
434
- name: `${prefix}_treasury`,
435
- description: `Treasury: fund escrow (${mode.display_name})`,
436
- owner_receive: true,
437
- tags: [`industry:${mode.name}`],
438
- }));
439
- objects.push(this.makeObject("allocation", `${prefix}_allocation`, {
440
- name: `${prefix}_allocation`,
441
- description: `Allocation: allocation strategy (${mode.display_name}) — ${mode.allocator.description}`,
442
- strategy: mode.allocator,
443
- treasury: `${prefix}_treasury`,
444
- guard: serviceGuardName,
445
- tags: [`industry:${mode.name}`],
446
- }));
447
- objects.push(this.makeObject("service", `${prefix}_service`, {
448
- name: `${prefix}_service`,
449
- description: `Service: business service (${mode.display_name}) — ${intent.slice(0, 100)}`,
450
- machine: `${prefix}_machine`,
451
- buy_guard: serviceGuardName,
452
- permission: `${prefix}_permission`,
453
- order_allocators: [`${prefix}_allocation`],
454
- compensation_fund_balance: 0,
455
- compensation_fund_required: mode.risk_constraints?.require_compensation_fund ?? false,
456
- compensation_fund_coverage_ratio: mode.risk_constraints?.compensation_fund_coverage_ratio ?? 5,
457
- compensation_fund_add_hint: "Call service.compensation_fund_add with a Coin<T> to deposit. " +
458
- "The compensation_fund is a Balance<T> (numeric), not a Treasury object reference. " +
459
- "Without deposit, arbitration rulings that award refunds to buyers cannot be paid out. " +
460
- `Recommend ${mode.risk_constraints?.compensation_fund_coverage_ratio ?? 5}× the max single-order amount (P1-1 evaluation rule, industry: ${mode.name}).`,
461
- arbitrations: [`${prefix}_arb`],
462
- rewards: [`${prefix}_reward`],
463
- business_intent: intent,
464
- industry: mode.name,
465
- tags: [`industry:${mode.name}`],
466
- }, true));
467
- objects.push(this.makeObject("progress", `${prefix}_progress`, {
468
- name: `${prefix}_progress`,
469
- description: `Progress: order fulfillment progress (${mode.display_name})`,
470
- parent: `${prefix}_machine`,
471
- tags: [`industry:${mode.name}`],
472
- }));
473
- objects.push(this.makeObject("arb", `${prefix}_arb`, {
474
- name: `${prefix}_arb`,
475
- description: `Arbitration: arbitration rules (${mode.display_name}) — ${mode.key_risk}`,
476
- guard: `${prefix}_guard_buy`,
477
- tags: [`industry:${mode.name}`],
478
- }));
479
- objects.push(this.makeObject("reward", `${prefix}_reward`, {
480
- name: `${prefix}_reward`,
481
- description: `Reward: incentive rules (${mode.display_name})`,
482
- claim_guard: `${prefix}_guard_buy`,
483
- tags: [`industry:${mode.name}`],
484
- }));
485
- objects.push(this.makeObject("contact", `${prefix}_contact`, {
486
- name: `${prefix}_contact`,
487
- description: `Contact: customer service contact (${mode.display_name})`,
488
- tags: [`industry:${mode.name}`],
489
- }));
490
- return objects;
491
- }
492
- buildPermissionIndexes(mode) {
493
- const permOverrides = mode.config_overrides?.["permission"];
494
- if (permOverrides?.permission_indexes) {
495
- return permOverrides.permission_indexes;
496
- }
497
- return [
498
- { name: "merchant", description: "Service owner / provider" },
499
- { name: "customer", description: "Service buyer / customer" },
500
- { name: "arbiter", description: "Arbitration arbiter" },
501
- ];
502
- }
503
- applyConfigOverrides(mode, objects) {
504
- if (!mode.config_overrides)
505
- return objects;
506
- for (const obj of objects) {
507
- const overrides = mode.config_overrides[obj.object_type];
508
- if (overrides) {
509
- for (const [key, value] of Object.entries(overrides)) {
510
- obj.config[key] = value;
511
- }
512
- }
513
- }
514
- return objects;
515
- }
516
- applyConfigOverrideRules(mode, objects, intent, context) {
517
- if (!mode.config_override_rules)
518
- return objects;
519
- for (const rule of mode.config_override_rules) {
520
- const obj = objects.find(o => o.object_type === rule.object_type);
521
- if (!obj)
522
- continue;
523
- let valueToApply;
524
- if (rule.condition) {
525
- const matched = this.evaluateCondition(rule, intent, context);
526
- valueToApply = matched ? rule.condition.then_value : (rule.condition.else_value ?? rule.value);
527
- }
528
- else {
529
- valueToApply = rule.value;
530
- }
531
- if (valueToApply !== undefined) {
532
- this.setNestedField(obj.config, rule.field_path, valueToApply);
533
- }
534
- }
535
- return objects;
536
- }
537
- evaluateCondition(rule, intent, context) {
538
- if (!rule.condition)
539
- return false;
540
- if (rule.condition.intent_contains) {
541
- return intent.toLowerCase().includes(rule.condition.intent_contains.toLowerCase());
542
- }
543
- if (rule.condition.context_field && rule.condition.matches !== undefined) {
544
- const fieldValue = context[rule.condition.context_field];
545
- return fieldValue === rule.condition.matches;
546
- }
547
- return false;
548
- }
549
- setNestedField(obj, path, value) {
550
- const parts = path.split(".");
551
- let current = obj;
552
- for (let i = 0; i < parts.length - 1; i++) {
553
- const part = parts[i];
554
- if (current[part] === undefined || current[part] === null) {
555
- current[part] = {};
556
- }
557
- current = current[part];
558
- }
559
- current[parts[parts.length - 1]] = value;
560
- }
561
- buildEdges(objects, context) {
562
- const edges = [];
563
- const find = (name) => objects.find(o => o.name === name);
564
- const configPrefix = objects[0]?.config?.prefix;
565
- const prefix = context?.prefix
566
- ?? (typeof configPrefix === "string" ? configPrefix : undefined)
567
- ?? objects[0]?.name.split("_")[0]
568
- ?? "";
569
- const service = find(`${prefix}_service`);
570
- const machine = find(`${prefix}_machine`);
571
- const permission = find(`${prefix}_permission`);
572
- const allocation = find(`${prefix}_allocation`);
573
- const treasury = find(`${prefix}_treasury`);
574
- const arb = find(`${prefix}_arb`);
575
- const reward = find(`${prefix}_reward`);
576
- const progress = find(`${prefix}_progress`);
577
- const allGuards = objects.filter(o => o.object_type === "guard");
578
- const serviceGuard = allGuards.find(g => g.config?.host === "service");
579
- const machineGuards = allGuards.filter(g => g.config?.host === "machine");
580
- if (!service || !machine || !permission) {
581
- const missing = [];
582
- if (!service)
583
- missing.push("service");
584
- if (!machine)
585
- missing.push("machine");
586
- if (!permission)
587
- missing.push("permission");
588
- console.warn(`[buildEdges] Missing core objects: ${missing.join(", ")}. ` +
589
- `Edges will be empty (prefix='${prefix}'). ` +
590
- `Check buildObjects output or context.prefix.`);
591
- return edges;
592
- }
593
- edges.push(this.makeEdge(service, machine, "machine", "service.machine", true));
594
- if (serviceGuard) {
595
- edges.push(this.makeEdge(service, serviceGuard, "buy_guard", "service.buy_guard", true));
596
- }
597
- edges.push(this.makeEdge(service, permission, "permission", "service.permission", true));
598
- if (allocation)
599
- edges.push(this.makeEdge(service, allocation, "order_allocators", "service.order_allocators", true));
600
- if (arb)
601
- edges.push(this.makeEdge(service, arb, "arbitrations", "service.arbitrations", false));
602
- if (reward)
603
- edges.push(this.makeEdge(service, reward, "rewards", "service.rewards", false));
604
- edges.push(this.makeEdge(machine, permission, "permission", "machine.permission", false));
605
- for (const mg of machineGuards) {
606
- edges.push(this.makeEdge(machine, mg, "guard", "machine.forwards.guard", false));
607
- }
608
- if (progress)
609
- edges.push(this.makeEdge(progress, machine, "parent", "progress.parent", false));
610
- if (allocation && treasury)
611
- edges.push(this.makeEdge(allocation, treasury, "treasury", "allocation.treasury", false));
612
- if (allocation && serviceGuard)
613
- edges.push(this.makeEdge(allocation, serviceGuard, "buy_guard", "allocation.guard", false));
614
- return edges;
615
- }
616
- makeEdge(from, to, edge_kind, field_path, required_at_publish) {
617
- return {
618
- from: from.entry_id,
619
- to: to.entry_id,
620
- edge_kind,
621
- field_path,
622
- required_at_publish,
623
- };
624
- }
625
- buildSteps(objects, edges, network) {
626
- const order = [
627
- "permission", "guard", "machine", "treasury", "allocation",
628
- "arb", "reward", "contact", "service", "progress",
629
- ];
630
- const steps = [];
631
- const entryToStep = new Map();
632
- let stepNum = 1;
633
- for (const type of order) {
634
- const obj = objects.find(o => o.object_type === type);
635
- if (!obj)
636
- continue;
637
- const depends = [];
638
- for (const edge of edges) {
639
- if (edge.to === obj.entry_id) {
640
- const depStep = entryToStep.get(edge.from);
641
- if (depStep !== undefined) {
642
- depends.push(depStep);
643
- }
644
- }
645
- }
646
- const operation = obj.publish_required ? "publish" : "create";
647
- steps.push({
648
- step: stepNum,
649
- object_type: obj.object_type,
650
- operation,
651
- substep_count: 1,
652
- depends_on: depends,
653
- entry_id: obj.entry_id,
654
- network_phase: network,
655
- });
656
- entryToStep.set(obj.entry_id, stepNum);
657
- stepNum++;
658
- }
659
- return steps;
660
- }
661
- defaultScenarios(mode, intent, objects) {
662
- const service = objects.find(o => o.object_type === "service");
663
- return [{
664
- scenario_id: `${mode.name}_primary`,
665
- description: `${mode.display_name} main flow: ${intent.slice(0, 80)}`,
666
- primary_object: service?.entry_id ?? "",
667
- supporting_objects: objects.filter(o => o.object_type !== "service").map(o => o.entry_id),
668
- }];
669
- }
670
- recordCapabilitiesUsed(mode) {
671
- if (!mode.capabilities_used)
672
- return;
673
- try {
674
- const registry = CapabilityRegistry.Instance();
675
- for (const capId of mode.capabilities_used) {
676
- registry.recordUsage(capId, mode.name);
677
- }
678
- }
679
- catch {
680
- }
681
- }
682
- deriveGuardShortName(templateId) {
683
- if (templateId.startsWith("tpl_")) {
684
- const parts = templateId.split("_");
685
- return parts[parts.length - 1] || templateId;
686
- }
687
- const match = templateId.match(/^([a-z]+)_guard_/);
688
- if (match)
689
- return match[1];
690
- return templateId.split("_")[0] || templateId;
691
- }
692
- getFirstServiceGuardName(mode, prefix) {
693
- const serviceGuard = mode.guards.find(g => g.host === "service");
694
- if (!serviceGuard)
695
- return "";
696
- return `${prefix}_guard_${this.deriveGuardShortName(serviceGuard.template_id)}`;
697
- }
698
- makeObject(type, name, config, publish_required = false) {
699
- return {
700
- entry_id: `${type}:${name}`,
701
- object_type: type,
702
- name,
703
- config,
704
- publish_required,
705
- status: "draft",
706
- };
707
- }
708
- registerBuiltinModes() {
709
- for (const mode of BUILTIN_MODES) {
710
- this.registerMode(mode);
711
- }
712
- }
713
- }
714
- export function getIndustryModeRegistry() {
715
- return IndustryModeRegistry.Instance();
716
- }
717
- export const INDUSTRY_MODE_REGISTRY_VERSION = 2.2;
1
+ import{UserModeStorage}from'@wowok/wowok';import{CapabilityRegistry}from'./capability-manifest.js';import{ModeEvaluator}from'./mode-evaluator.js';import{MetricRegistry}from'./metric-registry.js';import{ConstraintRegistry}from'./constraint-registry.js';import{BUILTIN_MODES}from'./modes.js';export class IndustryModeRegistry{static ['instance'];['registrations']=new Map();['userModes']=new Map();['aliases']=new Map();['evaluator'];['initialized']=![];['persistence']=new UserModeStorage();['userModesLoaded']=![];static['Instance'](){return!IndustryModeRegistry['instance']&&(IndustryModeRegistry['instance']=new IndustryModeRegistry()),IndustryModeRegistry['instance'];}constructor(){this['evaluator']=new ModeEvaluator(CapabilityRegistry['Instance'](),MetricRegistry['Instance'](),ConstraintRegistry['Instance']()),this['registerBuiltinModes'](),this['initialized']=!![];}['registerMode'](a,b){if(!a['name']||!a['traits']||!a['machine_shape'])return console['warn']('[IndustryModeRegistry]\x20registerMode\x20rejected:\x20invalid\x20mode\x20'+('(name='+(a['name']||'<missing>')+',\x20traits='+(a['traits']?'ok':'<missing>')+',\x20')+('machine_shape='+(a['machine_shape']?'ok':'<missing>')+').')),![];if(this['registrations']['has'](a['name'])){const c=this['registrations']['get'](a['name']);return console['warn']('[IndustryModeRegistry]\x20registerMode\x20rejected:\x20mode\x20\x27'+a['name']+'\x27\x20already\x20registered\x20'+('(registered_at='+new Date(c?.['registered_at']??0x0)['toISOString']()+').\x20')+'Use\x20evolveMode/deriveMode\x20for\x20user\x20modifications,\x20or\x20unregister\x20first.'),![];}this['registrations']['set'](a['name'],{'mode':a,'aliases':b,'enabled':!![],'registered_at':Date['now']()});if(b)for(const d of b){this['aliases']['set'](d,a['name']);}return!![];}['getMode'](a){const b=this['resolveAlias'](a);return this['registrations']['get'](b)?.['mode'];}['listModes'](){return Array['from'](this['registrations']['values']())['filter'](a=>a['enabled'])['map'](a=>a['mode']);}['resolveAlias'](a){return this['aliases']['get'](a)??a;}['hasMode'](a){const b=this['resolveAlias'](a);return this['registrations']['has'](b);}['unregisterMode'](a){const b=this['resolveAlias'](a);if(!this['registrations']['has'](b))return![];this['registrations']['delete'](b);for(const [c,d]of this['aliases']){if(d===b)this['aliases']['delete'](c);}return!![];}['evaluateMode'](a,b,c){const d=this['getMode'](a);if(!d)return{'applicable':![],'risk_score':0x64,'benefit_score':0x0,'risk_benefit_ratio':0x0,'capability_conflicts':[],'violated_constraints':[],'unmet_conditions':['Mode\x20\x27'+a+'\x27\x20not\x20found'],'recommendations':['Mode\x20\x27'+a+'\x27\x20not\x20registered,\x20falling\x20back\x20to\x20\x27general\x27']};return this['evaluator']['evaluateMode'](d,b,c);}['evaluateMigration'](a,b){const c=this['getMode'](a),d=this['getMode'](b);if(!c||!d)return{'feasibility_score':0x0,'source_risk_score':0x0,'target_risk_score':0x0,'source_benefit_score':0x0,'target_benefit_score':0x0,'risk_delta':0x0,'benefit_delta':0x0,'added_capabilities':[],'removed_capabilities':[],'conflicting_capabilities':[],'recommendations':['Mode\x20\x27'+a+'\x27\x20or\x20\x27'+b+'\x27\x20not\x20found']};return this['evaluator']['evaluateMigration'](c,d);}async['registerUserMode'](a,b){await this['ensureUserModesLoaded']();if(!a['name']||!a['owner']||!a['machine_shape'])return![];if(a['source']!=='custom')return![];if(a['owner']!==b)return![];const c=this['userModeKey'](a['owner'],a['name']);if(this['registrations']['has'](a['name']))return![];if(this['userModes']['has'](c))return![];return(!a['evolution_history']||a['evolution_history']['length']===0x0)&&(a['evolution_history']=[{'version':a['version']||'v1','changed_at':Date['now'](),'changes':['Initial\x20registration\x20(registerUserMode)']}]),this['userModes']['set'](c,a),await this['persistUserMode'](a),!![];}async['deriveMode'](a,b,c,d,e){await this['ensureUserModesLoaded']();const f=this['getMode'](a);if(!f)return undefined;if(!d||this['registrations']['has'](d))return undefined;const g=this['userModeKey'](c,d);if(this['userModes']['has'](g))return undefined;const h={'name':d,'display_name':e??d,'version':'v1','source':'custom','traits':b['traits']??f['traits'],'machine_shape':b['machine_shape']??f['machine_shape'],'guards':b['guards']??f['guards'],'allocator':b['allocator']??f['allocator'],'risk_checks':b['risk_checks']??f['risk_checks'],'needs':b['needs']??f['needs'],'flywheel':b['flywheel']??f['flywheel'],'key_risk':b['key_risk']??f['key_risk'],'build_notes':b['build_notes']??f['build_notes'],'capabilities_used':b['capabilities_used']??f['capabilities_used'],'config_overrides':b['config_overrides']??f['config_overrides'],'config_override_rules':b['config_override_rules']??f['config_override_rules'],'expected_benefits':b['expected_benefits']??f['expected_benefits'],'risk_appetite':b['risk_appetite']??f['risk_appetite'],'risk_constraints':b['risk_constraints']??f['risk_constraints'],'applicable_conditions':b['applicable_conditions']??f['applicable_conditions'],'similar_industries':b['similar_industries']??f['similar_industries'],'novel_capabilities':b['novel_capabilities']??f['novel_capabilities'],'owner':c,'derived_from':a,'custom_metrics':b['custom_metrics']??f['custom_metrics'],'custom_constraints':b['custom_constraints']??f['custom_constraints'],'evolution_history':[{'version':'v1','changed_at':Date['now'](),'changes':['Derived\x20from\x20builtin\x20\x27'+a+'\x27']}]};return this['userModes']['set'](g,h),await this['persistUserMode'](h),h;}async['evolveMode'](a,b,c,d,e=!![]){await this['ensureUserModesLoaded']();const f=this['userModeKey'](c,a),g=this['userModes']['get'](f);if(!g)return undefined;const h=e?this['bumpPatchVersion'](g['version']):g['version'],i={...g,...b,'name':g['name'],'owner':g['owner'],'source':'custom','derived_from':g['derived_from'],'evolution_history':[...g['evolution_history']??[],{'version':h,'changed_at':Date['now'](),'changes':[d]}],'version':h};return this['userModes']['set'](f,i),await this['persistUserMode'](i),i;}async['listUserModes'](a){await this['ensureUserModesLoaded']();const b=[];for(const c of this['userModes']['values']()){c['owner']===a&&b['push'](c);}return b;}async['getUserMode'](a,b){await this['ensureUserModesLoaded']();const c=this['userModeKey'](b,a);return this['userModes']['get'](c);}async['unregisterUserMode'](a,b){await this['ensureUserModesLoaded']();const c=this['userModeKey'](b,a),d=this['userModes']['delete'](c);return d&&await this['unpersistUserMode'](b,a),d;}['userModeKey'](a,b){return a+':'+b;}async['ensureUserModesLoaded'](){if(this['userModesLoaded'])return;this['userModesLoaded']=!![];try{const a=await this['persistence']['list']();for(const b of a){try{const c=JSON['parse'](b['data']);c?.['name']&&c?.['owner']&&c?.['machine_shape']&&this['userModes']['set'](this['userModeKey'](b['owner'],b['name']),c);}catch{console['warn']('[IndustryModeRegistry]\x20Skipping\x20corrupt\x20user_modes\x20row\x20\x27'+b['owner']+':'+b['name']+'\x27.');}}}catch(d){console['warn']('[IndustryModeRegistry]\x20Failed\x20to\x20load\x20persisted\x20user\x20modes:',d['message']);}}async['persistUserMode'](a){try{await this['persistence']['save'](a['owner'],a['name'],JSON['stringify'](a));}catch(b){console['warn']('[IndustryModeRegistry]\x20Failed\x20to\x20persist\x20user\x20mode\x20\x27'+a['owner']+':'+a['name']+'\x27:',b['message']);}}async['unpersistUserMode'](a,b){try{await this['persistence']['delete'](a,b);}catch(c){console['warn']('[IndustryModeRegistry]\x20Failed\x20to\x20delete\x20persisted\x20user\x20mode\x20\x27'+a+':'+b+'\x27:',c['message']);}}['bumpPatchVersion'](a){const b=a['replace'](/^v/,''),c=b['split']('.');if(c['length']<0x2)return'v'+b+'.1';const d=parseInt(c[0x1]??'0',0xa);return c[0x1]=String(d+0x1),'v'+c['join']('.');}async['applyTemplate'](a,b,c){const d=this['getMode'](a);if(d){const g=this['doApplyTemplate'](d,b,c);return this['recordCapabilitiesUsed'](d),g;}if(a['includes'](':')){const [h,i]=a['split'](':',0x2),j=await this['getUserMode'](i,h);if(j){const k=this['doApplyTemplate'](j,b,c);return this['recordCapabilitiesUsed'](j),k;}}const e=this['getMode']('general');if(!e)throw new Error('IndustryMode\x20\x27general\x27\x20not\x20registered\x20—\x20cannot\x20fallback');const f=this['doApplyTemplate'](e,b,c);return this['recordCapabilitiesUsed'](e),f;}async['applyUserMode'](a,b,c,d){const e=await this['getUserMode'](a,b);if(!e)throw new Error('User\x20mode\x20\x27'+a+'\x27\x20not\x20found\x20for\x20user\x20\x27'+b+'\x27');const f=this['doApplyTemplate'](e,c,d);return this['recordCapabilitiesUsed'](e),f;}['doApplyTemplate'](a,b,c){let d=this['buildObjects'](a,b,c);d=this['applyConfigOverrides'](a,d),d=this['applyConfigOverrideRules'](a,d,b,c);const e=this['buildEdges'](d,c),f=this['buildSteps'](d,e,c['network']),g=this['defaultScenarios'](a,b,d),h=this['validateBlueprint'](d,e,a);if(h['errors']['length']>0x0)throw new Error('Blueprint\x20validation\x20for\x20mode\x20\x27'+a['name']+'\x27\x20failed\x20with\x20'+h['errors']['length']+'\x20CRITICAL\x20error(s):\x0a'+h['errors']['map']((j,k)=>'\x20\x20'+(k+0x1)+'.\x20'+j)['join']('\x0a'));return h['warnings']['length']>0x0&&console['warn']('[IndustryModeRegistry]\x20Blueprint\x20validation\x20for\x20\x27'+a['name']+'\x27\x20produced\x20'+h['warnings']['length']+'\x20warning(s):',h['warnings']),{'context':c,'objects':d,'edges':e,'steps':f,'scenarios':g,'industry_source':a['name'],'applied_template':a['name']+'@'+a['version'],'validation':h};}['validateBlueprint'](a,b,c){const d=[],e=[],f=a['find'](j=>j['object_type']==='machine'),g=a['find'](j=>j['object_type']==='service');if(f){const j=f['config']['entry_node_forward_hint'];if(!j)e['push']('Machine\x20blueprint\x20missing\x20entry_node_forward_hint.\x20'+'The\x20AI\x20must\x20ensure\x20the\x20entry\x20node\x20(prev_node=\x27\x27)\x20has\x20≥1\x20forward\x20when\x20constructing\x20the\x20Machine\x20creation\x20call\x20(P0-2).');else j['required']===!![]&&!j['example_forward']&&e['push']('Machine\x20entry_node_forward_hint\x20marked\x20required\x20but\x20example_forward\x20is\x20missing.');const k=f['config']['nodes'];(!k||k['length']===0x0)&&d['push']('Machine\x20blueprint\x20has\x20no\x20nodes\x20—\x20mode\x20\x27'+c['name']+'\x27\x20machine_shape\x20is\x20empty.\x20'+'Add\x20nodes\x20to\x20the\x20mode\x27s\x20machine_shape\x20before\x20applying\x20template.');}if(g){const l=g['config']['compensation_fund'];l&&d['push']('Service\x20blueprint\x20has\x20compensation_fund=\x27'+l+'\x27\x20(string\x20reference).\x20'+'BUG:\x20compensation_fund\x20is\x20Balance<T>\x20(numeric),\x20NOT\x20a\x20Treasury\x20object\x20reference.\x20'+'Remove\x20compensation_fund\x20field\x20and\x20use\x20compensation_fund_balance\x20+\x20compensation_fund_add_hint\x20instead.\x20'+'Smart\x20contract\x20(service.move:179):\x20compensation_fund:\x20Balance<T>.');const m=g['config']['compensation_fund_balance'];m===undefined&&e['push']('Service\x20blueprint\x20missing\x20compensation_fund_balance.\x20'+'Should\x20be\x200\x20(initial\x20Balance<T>\x20state)\x20—\x20filled\x20via\x20service.compensation_fund_add(coin).');}const h=new Set(a['map'](n=>n['entry_id'])),i=new Set(a['map'](n=>n['name']));for(const n of b){const o=h['has'](n['from'])||i['has'](n['from']),p=h['has'](n['to'])||i['has'](n['to']);(!o||!p)&&d['push']('Edge\x20\x27'+n['from']+'\x27\x20→\x20\x27'+n['to']+'\x27\x20(kind=\x27'+n['edge_kind']+'\x27)\x20references\x20undefined\x20object.\x20'+('from_exists='+o+',\x20to_exists='+p+'.'));}return{'errors':d,'warnings':e};}['buildObjects'](a,b,c){const d=c['prefix'],e=[];e['push'](this['makeObject']('permission',d+'_permission',{'name':d+'_permission','description':'Permission:\x20role\x20permission\x20index\x20('+a['display_name']+')','permission_indexes':this['buildPermissionIndexes'](a),'tags':['industry:'+a['name']]}));const f=this['getFirstServiceGuardName'](a,d);for(const g of a['guards']){const h=this['deriveGuardShortName'](g['template_id']),i=d+'_guard_'+h;e['push'](this['makeObject']('guard',i,{'name':i,'description':'Guard:\x20'+g['purpose']+'\x20('+a['display_name']+')','host':g['host'],'template_id':g['template_id'],'tags':['industry:'+a['name'],'host:'+g['host']]}));}return e['push'](this['makeObject']('machine',d+'_machine',{'name':d+'_machine','description':'Machine:\x20workflow\x20topology\x20('+a['display_name']+')\x20—\x20'+a['machine_shape']['length']+'\x20nodes','nodes':a['machine_shape']['map'](j=>({'name':j['name'],'role':j['role']})),'guard_objects':a['guards']['filter'](j=>j['host']==='machine')['map'](j=>({'template_id':j['template_id'],'object_name':d+'_guard_'+this['deriveGuardShortName'](j['template_id']),'purpose':j['purpose']})),'permission':d+'_permission','entry_node_forward_hint':{'entry_node_name':a['machine_shape'][0x0]?.['name']??'paid','required':!![],'example_forward':{'next_node':a['machine_shape'][0x0]?.['name']??'paid','namedOperator':'','weight':0x1},'reason':'Progress\x20starts\x20at\x20current=\x27\x27\x20and\x20follows\x20the\x20entry\x20node\x27s\x20forwards.\x20'+'Without\x20a\x20forward,\x20Progress\x20is\x20permanently\x20stuck\x20(P0-2).\x20'+'Schema\x20refinement\x20in\x20MachineNodePairSchema\x20enforces\x20this\x20at\x20publish\x20time.'},'tags':['industry:'+a['name']]},!![])),e['push'](this['makeObject']('treasury',d+'_treasury',{'name':d+'_treasury','description':'Treasury:\x20fund\x20escrow\x20('+a['display_name']+')','owner_receive':!![],'tags':['industry:'+a['name']]})),e['push'](this['makeObject']('allocation',d+'_allocation',{'name':d+'_allocation','description':'Allocation:\x20allocation\x20strategy\x20('+a['display_name']+')\x20—\x20'+a['allocator']['description'],'strategy':a['allocator'],'treasury':d+'_treasury','guard':f,'tags':['industry:'+a['name']]})),e['push'](this['makeObject']('service',d+'_service',{'name':d+'_service','description':'Service:\x20business\x20service\x20('+a['display_name']+')\x20—\x20'+b['slice'](0x0,0x64),'machine':d+'_machine','buy_guard':f,'permission':d+'_permission','order_allocators':[d+'_allocation'],'compensation_fund_balance':0x0,'compensation_fund_required':a['risk_constraints']?.['require_compensation_fund']??![],'compensation_fund_coverage_ratio':a['risk_constraints']?.['compensation_fund_coverage_ratio']??0x5,'compensation_fund_add_hint':'Call\x20service.compensation_fund_add\x20with\x20a\x20Coin<T>\x20to\x20deposit.\x20'+'The\x20compensation_fund\x20is\x20a\x20Balance<T>\x20(numeric),\x20not\x20a\x20Treasury\x20object\x20reference.\x20'+'Without\x20deposit,\x20arbitration\x20rulings\x20that\x20award\x20refunds\x20to\x20buyers\x20cannot\x20be\x20paid\x20out.\x20'+('Recommend\x20'+(a['risk_constraints']?.['compensation_fund_coverage_ratio']??0x5)+'×\x20the\x20max\x20single-order\x20amount\x20(P1-1\x20evaluation\x20rule,\x20industry:\x20'+a['name']+').'),'arbitrations':[d+'_arb'],'rewards':[d+'_reward'],'business_intent':b,'industry':a['name'],'tags':['industry:'+a['name']]},!![])),e['push'](this['makeObject']('progress',d+'_progress',{'name':d+'_progress','description':'Progress:\x20order\x20fulfillment\x20progress\x20('+a['display_name']+')','parent':d+'_machine','tags':['industry:'+a['name']]})),e['push'](this['makeObject']('arb',d+'_arb',{'name':d+'_arb','description':'Arbitration:\x20arbitration\x20rules\x20('+a['display_name']+')\x20—\x20'+a['key_risk'],'guard':d+'_guard_buy','tags':['industry:'+a['name']]})),e['push'](this['makeObject']('reward',d+'_reward',{'name':d+'_reward','description':'Reward:\x20incentive\x20rules\x20('+a['display_name']+')','claim_guard':d+'_guard_buy','tags':['industry:'+a['name']]})),e['push'](this['makeObject']('contact',d+'_contact',{'name':d+'_contact','description':'Contact:\x20customer\x20service\x20contact\x20('+a['display_name']+')','tags':['industry:'+a['name']]})),e;}['buildPermissionIndexes'](a){const b=a['config_overrides']?.['permission'];if(b?.['permission_indexes'])return b['permission_indexes'];return[{'name':'merchant','description':'Service\x20owner\x20/\x20provider'},{'name':'customer','description':'Service\x20buyer\x20/\x20customer'},{'name':'arbiter','description':'Arbitration\x20arbiter'}];}['applyConfigOverrides'](a,b){if(!a['config_overrides'])return b;for(const c of b){const d=a['config_overrides'][c['object_type']];if(d)for(const [e,f]of Object['entries'](d)){c['config'][e]=f;}}return b;}['applyConfigOverrideRules'](a,b,c,d){if(!a['config_override_rules'])return b;for(const e of a['config_override_rules']){const f=b['find'](h=>h['object_type']===e['object_type']);if(!f)continue;let g;if(e['condition']){const h=this['evaluateCondition'](e,c,d);g=h?e['condition']['then_value']:e['condition']['else_value']??e['value'];}else g=e['value'];g!==undefined&&this['setNestedField'](f['config'],e['field_path'],g);}return b;}['evaluateCondition'](a,b,c){if(!a['condition'])return![];if(a['condition']['intent_contains'])return b['toLowerCase']()['includes'](a['condition']['intent_contains']['toLowerCase']());if(a['condition']['context_field']&&a['condition']['matches']!==undefined){const d=c[a['condition']['context_field']];return d===a['condition']['matches'];}return![];}['setNestedField'](a,b,c){const d=b['split']('.');let e=a;for(let f=0x0;f<d['length']-0x1;f++){const g=d[f];(e[g]===undefined||e[g]===null)&&(e[g]={}),e=e[g];}e[d[d['length']-0x1]]=c;}['buildEdges'](a,b){const c=[],d=r=>a['find'](s=>s['name']===r),e=a[0x0]?.['config']?.['prefix'],f=b?.['prefix']??(typeof e==='string'?e:undefined)??a[0x0]?.['name']['split']('_')[0x0]??'',g=d(f+'_service'),h=d(f+'_machine'),i=d(f+'_permission'),j=d(f+'_allocation'),k=d(f+'_treasury'),l=d(f+'_arb'),m=d(f+'_reward'),n=d(f+'_progress'),o=a['filter'](r=>r['object_type']==='guard'),p=o['find'](r=>r['config']?.['host']==='service'),q=o['filter'](r=>r['config']?.['host']==='machine');if(!g||!h||!i){const r=[];if(!g)r['push']('service');if(!h)r['push']('machine');if(!i)r['push']('permission');return console['warn']('[buildEdges]\x20Missing\x20core\x20objects:\x20'+r['join'](',\x20')+'.\x20'+('Edges\x20will\x20be\x20empty\x20(prefix=\x27'+f+'\x27).\x20')+'Check\x20buildObjects\x20output\x20or\x20context.prefix.'),c;}c['push'](this['makeEdge'](g,h,'machine','service.machine',!![]));p&&c['push'](this['makeEdge'](g,p,'buy_guard','service.buy_guard',!![]));c['push'](this['makeEdge'](g,i,'permission','service.permission',!![]));if(j)c['push'](this['makeEdge'](g,j,'order_allocators','service.order_allocators',!![]));if(l)c['push'](this['makeEdge'](g,l,'arbitrations','service.arbitrations',![]));if(m)c['push'](this['makeEdge'](g,m,'rewards','service.rewards',![]));c['push'](this['makeEdge'](h,i,'permission','machine.permission',![]));for(const s of q){c['push'](this['makeEdge'](h,s,'guard','machine.forwards.guard',![]));}if(n)c['push'](this['makeEdge'](n,h,'parent','progress.parent',![]));if(j&&k)c['push'](this['makeEdge'](j,k,'treasury','allocation.treasury',![]));if(j&&p)c['push'](this['makeEdge'](j,p,'buy_guard','allocation.guard',![]));return c;}['makeEdge'](a,b,c,d,e){return{'from':a['entry_id'],'to':b['entry_id'],'edge_kind':c,'field_path':d,'required_at_publish':e};}['buildSteps'](a,b,c){const d=['permission','guard','machine','treasury','allocation','arb','reward','contact','service','progress'],e=[],f=new Map();let g=0x1;for(const h of d){const i=a['find'](l=>l['object_type']===h);if(!i)continue;const j=[];for(const l of b){if(l['to']===i['entry_id']){const m=f['get'](l['from']);m!==undefined&&j['push'](m);}}const k=i['publish_required']?'publish':'create';e['push']({'step':g,'object_type':i['object_type'],'operation':k,'substep_count':0x1,'depends_on':j,'entry_id':i['entry_id'],'network_phase':c}),f['set'](i['entry_id'],g),g++;}return e;}['defaultScenarios'](a,b,c){const d=c['find'](e=>e['object_type']==='service');return[{'scenario_id':a['name']+'_primary','description':a['display_name']+'\x20main\x20flow:\x20'+b['slice'](0x0,0x50),'primary_object':d?.['entry_id']??'','supporting_objects':c['filter'](e=>e['object_type']!=='service')['map'](e=>e['entry_id'])}];}['recordCapabilitiesUsed'](a){if(!a['capabilities_used'])return;try{const b=CapabilityRegistry['Instance']();for(const c of a['capabilities_used']){b['recordUsage'](c,a['name']);}}catch{}}['deriveGuardShortName'](a){if(a['startsWith']('tpl_')){const c=a['split']('_');return c[c['length']-0x1]||a;}const b=a['match'](/^([a-z]+)_guard_/);if(b)return b[0x1];return a['split']('_')[0x0]||a;}['getFirstServiceGuardName'](a,b){const c=a['guards']['find'](d=>d['host']==='service');if(!c)return'';return b+'_guard_'+this['deriveGuardShortName'](c['template_id']);}['makeObject'](a,b,c,d=![]){return{'entry_id':a+':'+b,'object_type':a,'name':b,'config':c,'publish_required':d,'status':'draft'};}['registerBuiltinModes'](){for(const a of BUILTIN_MODES){this['registerMode'](a);}}}export function getIndustryModeRegistry(){return IndustryModeRegistry['Instance']();}export const INDUSTRY_MODE_REGISTRY_VERSION=2.2;