@wowok/agent-mcp 2.7.8 → 3.0.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 (393) hide show
  1. package/README.md +2 -2
  2. package/dist/config/runtime.d.ts +1 -1
  3. package/dist/config/runtime.js +1 -1
  4. package/dist/examples/rental-ziroom-machine-create.json +1 -2
  5. package/dist/examples/rental-ziroom-permission-create.json +1 -2
  6. package/dist/examples/rental-ziroom-service-create.json +1 -2
  7. package/dist/experience/experience-reuse.js +1 -1
  8. package/dist/experience/index.d.ts +2 -1
  9. package/dist/experience/index.js +1 -1
  10. package/dist/experience/persistence-config.d.ts +6 -0
  11. package/dist/experience/persistence-config.js +1 -0
  12. package/dist/experience/persistence.d.ts +21 -0
  13. package/dist/experience/persistence.js +1 -0
  14. package/dist/experience/realtime-feedback.js +1 -1
  15. package/dist/experience/user-profile.js +1 -1
  16. package/dist/extensions/business-modules.d.ts +1 -1
  17. package/dist/extensions/capability-manifest.d.ts +2 -83
  18. package/dist/extensions/capability-manifest.js +1 -1
  19. package/dist/extensions/constraint-registry.d.ts +6 -4
  20. package/dist/extensions/constraint-registry.js +1 -1
  21. package/dist/extensions/index.d.ts +4 -5
  22. package/dist/extensions/index.js +1 -1
  23. package/dist/extensions/industry-pack.js +1 -1
  24. package/dist/extensions/metric-registry.d.ts +6 -4
  25. package/dist/extensions/metric-registry.js +1 -1
  26. package/dist/extensions/mode-evaluator.d.ts +2 -3
  27. package/dist/extensions/mode-evaluator.js +1 -1
  28. package/dist/extensions/registry.d.ts +3 -25
  29. package/dist/extensions/registry.js +1 -1
  30. package/dist/extensions/types.d.ts +1 -69
  31. package/dist/goal/GoalClassifier.d.ts +17 -0
  32. package/dist/goal/GoalClassifier.js +1 -0
  33. package/dist/goal/GoalEngine.d.ts +155 -0
  34. package/dist/goal/GoalEngine.js +1 -0
  35. package/dist/goal/GoalStore.d.ts +27 -0
  36. package/dist/goal/GoalStore.js +1 -0
  37. package/dist/goal/plan-approval.d.ts +5 -0
  38. package/dist/goal/plan-approval.js +1 -0
  39. package/dist/goal/types.d.ts +80 -0
  40. package/dist/goal/types.js +1 -0
  41. package/dist/harness/index.d.ts +2 -7
  42. package/dist/harness/index.js +1 -1
  43. package/dist/harness/plan.d.ts +1 -1
  44. package/dist/harness/types.d.ts +0 -35
  45. package/dist/index.js +1 -1
  46. package/dist/knowledge/account-marks.d.ts +36 -0
  47. package/dist/knowledge/account-marks.js +1 -0
  48. package/dist/knowledge/audit-rules.d.ts +3 -1
  49. package/dist/knowledge/audit-rules.js +1 -1
  50. package/dist/knowledge/examples-scanner-cli.js +1 -1
  51. package/dist/knowledge/examples-scanner.js +1 -1
  52. package/dist/knowledge/fund-layer.d.ts +13 -9
  53. package/dist/knowledge/fund-layer.js +1 -1
  54. package/dist/knowledge/goal-completion.d.ts +19 -0
  55. package/dist/knowledge/goal-completion.js +1 -0
  56. package/dist/knowledge/guard-bindings.d.ts +21 -0
  57. package/dist/knowledge/guard-bindings.js +1 -0
  58. package/dist/knowledge/guard-translation.js +1 -1
  59. package/dist/knowledge/index.d.ts +6 -3
  60. package/dist/knowledge/index.js +1 -1
  61. package/dist/knowledge/industry-registry.js +1 -1
  62. package/dist/knowledge/mcp-schema-audit-cli.js +1 -1
  63. package/dist/knowledge/mcp-schema-audit.js +1 -1
  64. package/dist/knowledge/operation-dictionary.js +1 -1
  65. package/dist/knowledge/passport-confirm.js +1 -1
  66. package/dist/knowledge/passport-puzzle.js +1 -1
  67. package/dist/knowledge/passport-translation.js +1 -1
  68. package/dist/knowledge/proof-risk.js +1 -1
  69. package/dist/knowledge/reward-risk.d.ts +1 -1
  70. package/dist/knowledge/reward-risk.js +1 -1
  71. package/dist/knowledge/safety-rules.d.ts +2 -1
  72. package/dist/knowledge/safety-rules.js +1 -1
  73. package/dist/knowledge/scenario-topology.d.ts +43 -0
  74. package/dist/knowledge/scenario-topology.js +1 -0
  75. package/dist/knowledge/service-translation.js +1 -1
  76. package/dist/knowledge/supply-chain.js +1 -1
  77. package/dist/knowledge/template-registry.js +1 -1
  78. package/dist/knowledge/tools-reference.js +1 -1
  79. package/dist/knowledge/workflow-guidance.d.ts +36 -0
  80. package/dist/knowledge/workflow-guidance.js +1 -1
  81. package/dist/knowledge/workspace-lists.d.ts +57 -0
  82. package/dist/knowledge/workspace-lists.js +1 -0
  83. package/dist/loop-engineering/context-collect.d.ts +1 -1
  84. package/dist/monitor/EventRouter.d.ts +10 -0
  85. package/dist/monitor/EventRouter.js +1 -0
  86. package/dist/monitor/EventStore.d.ts +32 -12
  87. package/dist/monitor/EventStore.js +1 -1
  88. package/dist/monitor/MonitorLoop.d.ts +81 -0
  89. package/dist/monitor/MonitorLoop.js +1 -0
  90. package/dist/monitor/ProblemBridge.d.ts +32 -0
  91. package/dist/monitor/ProblemBridge.js +1 -0
  92. package/dist/monitor/ScopeResolver.d.ts +59 -0
  93. package/dist/monitor/ScopeResolver.js +1 -0
  94. package/dist/monitor/SubscriptionStore.d.ts +13 -0
  95. package/dist/monitor/SubscriptionStore.js +1 -0
  96. package/dist/monitor/SuggestionBridge.d.ts +38 -0
  97. package/dist/monitor/SuggestionBridge.js +1 -0
  98. package/dist/monitor/normalize.d.ts +8 -0
  99. package/dist/monitor/normalize.js +1 -0
  100. package/dist/monitor/types.d.ts +89 -0
  101. package/dist/monitor/types.js +1 -0
  102. package/dist/participation/arbitrator-interest.d.ts +20 -0
  103. package/dist/participation/arbitrator-interest.js +1 -0
  104. package/dist/participation/demander-interest.d.ts +23 -0
  105. package/dist/participation/demander-interest.js +1 -0
  106. package/dist/persona/address-format.d.ts +1 -1
  107. package/dist/persona/address-format.js +1 -1
  108. package/dist/persona/distill-goal.d.ts +20 -0
  109. package/dist/persona/distill-goal.js +1 -0
  110. package/dist/persona/index.d.ts +2 -0
  111. package/dist/persona/index.js +1 -1
  112. package/dist/persona/model.js +1 -1
  113. package/dist/playbooks/service-build/business-puzzle.js +1 -0
  114. package/dist/{project → playbooks/service-build}/context-assembly.d.ts +9 -4
  115. package/dist/playbooks/service-build/context-assembly.js +1 -0
  116. package/dist/{project → playbooks/service-build}/game-theory.d.ts +1 -1
  117. package/dist/playbooks/service-build/index.d.ts +14 -0
  118. package/dist/playbooks/service-build/index.js +1 -0
  119. package/dist/{project → playbooks/service-build}/intent-analyzer.d.ts +1 -1
  120. package/dist/playbooks/service-build/intent-analyzer.js +1 -0
  121. package/dist/playbooks/service-build/machine-nodes.js +1 -0
  122. package/dist/{project → playbooks/service-build}/machine-panorama.d.ts +5 -3
  123. package/dist/playbooks/service-build/machine-panorama.js +1 -0
  124. package/dist/{project → playbooks/service-build}/merchant-guide.d.ts +21 -1
  125. package/dist/playbooks/service-build/merchant-guide.js +1 -0
  126. package/dist/{project → playbooks/service-build}/mode-actions.d.ts +32 -8
  127. package/dist/playbooks/service-build/mode-actions.js +1 -0
  128. package/dist/playbooks/service-build/namespace.d.ts +2 -0
  129. package/dist/playbooks/service-build/namespace.js +1 -0
  130. package/dist/{project → playbooks/service-build}/object-panorama.d.ts +2 -3
  131. package/dist/playbooks/service-build/object-panorama.js +1 -0
  132. package/dist/{project → playbooks/service-build}/participation-radar.d.ts +4 -5
  133. package/dist/playbooks/service-build/participation-radar.js +1 -0
  134. package/dist/{project → playbooks/service-build}/pipeline-actions.d.ts +9 -9
  135. package/dist/playbooks/service-build/pipeline-actions.js +1 -0
  136. package/dist/playbooks/service-build/process.d.ts +6 -0
  137. package/dist/playbooks/service-build/process.js +1 -0
  138. package/dist/playbooks/service-build/relationship-profile.d.ts +2 -0
  139. package/dist/playbooks/service-build/relationship-profile.js +1 -0
  140. package/dist/playbooks/service-build/risk-aggregator.js +1 -0
  141. package/dist/{project → playbooks/service-build}/semantic-graph.d.ts +7 -3
  142. package/dist/playbooks/service-build/semantic-graph.js +1 -0
  143. package/dist/{project → playbooks/service-build}/service-panorama.d.ts +3 -19
  144. package/dist/playbooks/service-build/service-panorama.js +1 -0
  145. package/dist/relationship/derivation.d.ts +88 -0
  146. package/dist/relationship/derivation.js +1 -0
  147. package/dist/relationship/incentive.d.ts +38 -0
  148. package/dist/relationship/incentive.js +1 -0
  149. package/dist/relationship/index.d.ts +4 -0
  150. package/dist/relationship/index.js +1 -0
  151. package/dist/relationship/registry.d.ts +13 -0
  152. package/dist/relationship/registry.js +1 -0
  153. package/dist/relationship/types.d.ts +45 -0
  154. package/dist/relationship/types.js +1 -0
  155. package/dist/review/arb.d.ts +6 -0
  156. package/dist/review/arb.js +1 -0
  157. package/dist/review/demand.d.ts +3 -0
  158. package/dist/review/demand.js +1 -0
  159. package/dist/review/index.d.ts +3 -0
  160. package/dist/review/index.js +1 -0
  161. package/dist/review/machine.d.ts +3 -0
  162. package/dist/review/machine.js +1 -0
  163. package/dist/review/order.d.ts +9 -0
  164. package/dist/review/order.js +1 -0
  165. package/dist/review/progress.d.ts +3 -0
  166. package/dist/review/progress.js +1 -0
  167. package/dist/review/repository.d.ts +3 -0
  168. package/dist/review/repository.js +1 -0
  169. package/dist/review/service.d.ts +5 -0
  170. package/dist/review/service.js +1 -0
  171. package/dist/review/types.d.ts +156 -0
  172. package/dist/review/types.js +1 -0
  173. package/dist/rules.d.ts +2 -2
  174. package/dist/rules.js +1 -1
  175. package/dist/safety/confirm-gate.js +1 -1
  176. package/dist/safety/index.d.ts +1 -1
  177. package/dist/safety/index.js +1 -1
  178. package/dist/safety/preview.d.ts +1 -0
  179. package/dist/safety/preview.js +1 -1
  180. package/dist/schema/call/allocation.d.ts +1 -1
  181. package/dist/schema/call/arbitration.d.ts +1 -1
  182. package/dist/schema/call/base.d.ts +1 -1
  183. package/dist/schema/call/base.js +1 -1
  184. package/dist/schema/call/bridge.d.ts +29 -7
  185. package/dist/schema/call/bridge.js +1 -1
  186. package/dist/schema/call/contact.d.ts +1 -1
  187. package/dist/schema/call/contact.js +1 -1
  188. package/dist/schema/call/demand.d.ts +1 -1
  189. package/dist/schema/call/demand.js +1 -1
  190. package/dist/schema/call/guard.d.ts +3 -3
  191. package/dist/schema/call/handler.d.ts +0 -3
  192. package/dist/schema/call/handler.js +1 -1
  193. package/dist/schema/call/machine.d.ts +2 -2
  194. package/dist/schema/call/order.d.ts +1 -1
  195. package/dist/schema/call/payment.d.ts +1 -1
  196. package/dist/schema/call/permission.d.ts +1 -1
  197. package/dist/schema/call/personal.d.ts +1 -1
  198. package/dist/schema/call/progress.d.ts +1 -1
  199. package/dist/schema/call/proof.d.ts +2 -2
  200. package/dist/schema/call/repository.d.ts +1 -1
  201. package/dist/schema/call/repository.js +1 -1
  202. package/dist/schema/call/reward.d.ts +1 -1
  203. package/dist/schema/call/semantic.js +1 -1
  204. package/dist/schema/call/service.d.ts +1 -1
  205. package/dist/schema/call/service.js +1 -1
  206. package/dist/schema/call/treasury.d.ts +1 -1
  207. package/dist/schema/common/index.js +1 -1
  208. package/dist/schema/goal/index.d.ts +343 -0
  209. package/dist/schema/goal/index.js +1 -0
  210. package/dist/schema/goal/planning.d.ts +465 -0
  211. package/dist/schema/goal/planning.js +1 -0
  212. package/dist/schema/index.d.ts +1 -2
  213. package/dist/schema/index.js +1 -1
  214. package/dist/schema/industry-pack/index.d.ts +323 -1
  215. package/dist/schema/industry-pack/index.js +1 -1
  216. package/dist/schema/industry-pack/modes.d.ts +326 -0
  217. package/dist/schema/industry-pack/modes.js +1 -0
  218. package/dist/schema/intent-radar/index.d.ts +19 -19
  219. package/dist/schema/local/index.d.ts +11 -0
  220. package/dist/schema/local/index.js +1 -1
  221. package/dist/schema/operations.d.ts +258 -19
  222. package/dist/schema/operations.js +1 -1
  223. package/dist/schema/permission/index.d.ts +1 -0
  224. package/dist/schema/permission/index.js +1 -1
  225. package/dist/schema/persona/index.d.ts +40 -0
  226. package/dist/schema/persona/index.js +1 -1
  227. package/dist/schema/query/bi.d.ts +912 -0
  228. package/dist/schema/query/bi.js +1 -0
  229. package/dist/schema/query/index.d.ts +663 -2
  230. package/dist/schema/query/index.js +1 -1
  231. package/dist/schema/schema-version.js +1 -1
  232. package/dist/schema/utils/skills-recommendation.d.ts +0 -1
  233. package/dist/schema/utils/skills-recommendation.js +1 -1
  234. package/dist/schema-query-impl/index.js +1 -1
  235. package/dist/schemas/account_operation.output.json +32 -3
  236. package/dist/schemas/account_operation.schema.json +8 -4
  237. package/dist/schemas/bridge_operation.output.json +26 -3
  238. package/dist/schemas/bridge_operation.schema.json +85 -13
  239. package/dist/schemas/config_operation.output.json +1 -1
  240. package/dist/schemas/config_operation.schema.json +1 -1
  241. package/dist/schemas/goal_operation.schema.json +1092 -0
  242. package/dist/schemas/guard2file.schema.json +3 -3
  243. package/dist/schemas/index.json +12 -13
  244. package/dist/schemas/industry_pack_operation.output.json +1073 -0
  245. package/dist/schemas/industry_pack_operation.schema.json +236 -2
  246. package/dist/schemas/local_info_operation.output.json +2 -2
  247. package/dist/schemas/local_mark_operation.output.json +2 -2
  248. package/dist/schemas/machineNode2file.schema.json +3 -3
  249. package/dist/schemas/messenger_operation.output.json +2 -2
  250. package/dist/schemas/monitor_events.output.json +78 -3
  251. package/dist/schemas/monitor_events.schema.json +24 -1
  252. package/dist/schemas/monitor_subscription.output.json +1462 -0
  253. package/dist/schemas/monitor_subscription.schema.json +327 -0
  254. package/dist/schemas/onchain_events.output.json +5 -5
  255. package/dist/schemas/onchain_operations.output.json +2 -2
  256. package/dist/schemas/onchain_operations.schema.json +100 -100
  257. package/dist/schemas/onchain_operations_allocation.schema.json +7 -7
  258. package/dist/schemas/onchain_operations_arbitration.schema.json +6 -6
  259. package/dist/schemas/onchain_operations_contact.schema.json +6 -6
  260. package/dist/schemas/onchain_operations_demand.schema.json +6 -6
  261. package/dist/schemas/onchain_operations_gen_passport.schema.json +3 -3
  262. package/dist/schemas/onchain_operations_gen_proof.schema.json +3 -3
  263. package/dist/schemas/onchain_operations_guard.schema.json +3 -3
  264. package/dist/schemas/onchain_operations_machine.schema.json +5 -5
  265. package/dist/schemas/onchain_operations_order.schema.json +5 -5
  266. package/dist/schemas/onchain_operations_payment.schema.json +4 -4
  267. package/dist/schemas/onchain_operations_permission.schema.json +5 -5
  268. package/dist/schemas/onchain_operations_personal.schema.json +3 -3
  269. package/dist/schemas/onchain_operations_progress.schema.json +5 -5
  270. package/dist/schemas/onchain_operations_proof.schema.json +3 -3
  271. package/dist/schemas/onchain_operations_repository.schema.json +7 -7
  272. package/dist/schemas/onchain_operations_reward.schema.json +9 -9
  273. package/dist/schemas/onchain_operations_service.schema.json +11 -11
  274. package/dist/schemas/onchain_operations_treasury.schema.json +9 -9
  275. package/dist/schemas/onchain_table_data.output.json +399 -2
  276. package/dist/schemas/onchain_table_data.schema.json +22 -22
  277. package/dist/schemas/permission_operation.schema.json +6 -2
  278. package/dist/schemas/persona_operation.output.json +145 -0
  279. package/dist/schemas/persona_operation.schema.json +28 -2
  280. package/dist/schemas/query_toolkit.output.json +1514 -22
  281. package/dist/schemas/query_toolkit.schema.json +465 -11
  282. package/dist/schemas/workflow_operation.schema.json +4 -4
  283. package/dist/task/ProcessStore.d.ts +98 -0
  284. package/dist/task/ProcessStore.js +1 -0
  285. package/dist/task/playbook.d.ts +11 -0
  286. package/dist/task/playbook.js +1 -0
  287. package/dist/task/stage-gate.d.ts +22 -0
  288. package/dist/task/stage-gate.js +1 -0
  289. package/dist/{project → task}/substep-trace.d.ts +6 -45
  290. package/dist/task/types.d.ts +144 -0
  291. package/dist/task/types.js +1 -0
  292. package/dist/tools/handlers/config.js +1 -1
  293. package/dist/tools/handlers/evaluation.js +1 -1
  294. package/dist/tools/handlers/goal.d.ts +4 -0
  295. package/dist/tools/handlers/goal.js +1 -0
  296. package/dist/tools/handlers/industry-pack.js +1 -1
  297. package/dist/tools/handlers/local.d.ts +4 -3
  298. package/dist/tools/handlers/local.js +1 -1
  299. package/dist/tools/handlers/monitor.d.ts +24 -0
  300. package/dist/tools/handlers/monitor.js +1 -1
  301. package/dist/tools/handlers/network.d.ts +1 -0
  302. package/dist/tools/handlers/network.js +1 -0
  303. package/dist/tools/handlers/onchain.js +1 -1
  304. package/dist/tools/handlers/permission.js +1 -1
  305. package/dist/tools/handlers/persona.js +1 -1
  306. package/dist/tools/handlers/query.js +1 -1
  307. package/dist/tools/handlers/watch.js +1 -1
  308. package/dist/tools/handlers/workflow.js +1 -1
  309. package/dist/tools/index.d.ts +2 -0
  310. package/dist/tools/index.js +1 -1
  311. package/dist/tools/rules-hook.d.ts +1 -0
  312. package/dist/tools/rules-hook.js +1 -1
  313. package/dist/tools/shared.js +1 -1
  314. package/dist/tools/wrap.js +1 -1
  315. package/package.json +5 -4
  316. package/dist/harness/checkpoint.d.ts +0 -8
  317. package/dist/harness/checkpoint.js +0 -1
  318. package/dist/knowledge/deployment-scanner.d.ts +0 -66
  319. package/dist/knowledge/deployment-scanner.js +0 -1
  320. package/dist/mode-market/index.d.ts +0 -3
  321. package/dist/mode-market/index.js +0 -1
  322. package/dist/mode-market/registry.d.ts +0 -53
  323. package/dist/mode-market/registry.js +0 -1
  324. package/dist/mode-market/review.d.ts +0 -27
  325. package/dist/mode-market/review.js +0 -1
  326. package/dist/mode-market/submission.d.ts +0 -25
  327. package/dist/mode-market/submission.js +0 -1
  328. package/dist/project/business-puzzle.js +0 -1
  329. package/dist/project/context-assembly.js +0 -1
  330. package/dist/project/deployment-bridge.d.ts +0 -5
  331. package/dist/project/deployment-bridge.js +0 -1
  332. package/dist/project/deployment-doc.d.ts +0 -190
  333. package/dist/project/deployment-doc.js +0 -1
  334. package/dist/project/edit-planner.d.ts +0 -123
  335. package/dist/project/edit-planner.js +0 -1
  336. package/dist/project/evaluation-fix.spec.d.ts +0 -1
  337. package/dist/project/evaluation-fix.spec.js +0 -1
  338. package/dist/project/evaluation.d.ts +0 -127
  339. package/dist/project/evaluation.js +0 -1
  340. package/dist/project/graph-builder.d.ts +0 -51
  341. package/dist/project/graph-builder.js +0 -1
  342. package/dist/project/graph.d.ts +0 -70
  343. package/dist/project/graph.js +0 -1
  344. package/dist/project/handlers.d.ts +0 -524
  345. package/dist/project/handlers.js +0 -1
  346. package/dist/project/index.d.ts +0 -91
  347. package/dist/project/index.js +0 -1
  348. package/dist/project/intent-analyzer.js +0 -1
  349. package/dist/project/machine-nodes.js +0 -1
  350. package/dist/project/machine-panorama.js +0 -1
  351. package/dist/project/merchant-guide.js +0 -1
  352. package/dist/project/mode-actions.js +0 -1
  353. package/dist/project/namespace.d.ts +0 -72
  354. package/dist/project/namespace.js +0 -1
  355. package/dist/project/object-panorama.js +0 -1
  356. package/dist/project/participation-radar.js +0 -1
  357. package/dist/project/pipeline-actions.js +0 -1
  358. package/dist/project/project-store.d.ts +0 -110
  359. package/dist/project/project-store.js +0 -1
  360. package/dist/project/query.d.ts +0 -43
  361. package/dist/project/query.js +0 -1
  362. package/dist/project/risk-aggregator.js +0 -1
  363. package/dist/project/semantic-assembler.d.ts +0 -93
  364. package/dist/project/semantic-assembler.js +0 -1
  365. package/dist/project/semantic-graph.js +0 -1
  366. package/dist/project/service-panorama.js +0 -1
  367. package/dist/project/stage-gate.d.ts +0 -52
  368. package/dist/project/stage-gate.js +0 -1
  369. package/dist/project/task-tracker.d.ts +0 -30
  370. package/dist/project/task-tracker.js +0 -1
  371. package/dist/schema/project/index.d.ts +0 -2021
  372. package/dist/schema/project/index.js +0 -1
  373. package/dist/schema/task-status.d.ts +0 -62
  374. package/dist/schema/task-status.js +0 -1
  375. package/dist/schemas/project_operation.output.json +0 -7877
  376. package/dist/schemas/project_operation.schema.json +0 -1139
  377. package/dist/schemas/query_task_status.output.json +0 -211
  378. package/dist/schemas/query_task_status.schema.json +0 -18
  379. package/dist/tools/handlers/project.d.ts +0 -2
  380. package/dist/tools/handlers/project.js +0 -1
  381. package/dist/tools/handlers/task-status.d.ts +0 -2
  382. package/dist/tools/handlers/task-status.js +0 -1
  383. /package/dist/{project → playbooks/service-build}/business-puzzle.d.ts +0 -0
  384. /package/dist/{project → playbooks/service-build}/game-theory.js +0 -0
  385. /package/dist/{project → playbooks/service-build}/machine-nodes.d.ts +0 -0
  386. /package/dist/{project → playbooks/service-build}/object-type.d.ts +0 -0
  387. /package/dist/{project → playbooks/service-build}/object-type.js +0 -0
  388. /package/dist/{project → playbooks/service-build}/reverse-mapping.d.ts +0 -0
  389. /package/dist/{project → playbooks/service-build}/reverse-mapping.js +0 -0
  390. /package/dist/{project → playbooks/service-build}/risk-aggregator.d.ts +0 -0
  391. /package/dist/{project → playbooks/service-build}/workflow-design-assessment.d.ts +0 -0
  392. /package/dist/{project → playbooks/service-build}/workflow-design-assessment.js +0 -0
  393. /package/dist/{project → task}/substep-trace.js +0 -0
@@ -1 +1 @@
1
- export{CapabilityRegistry,getCapabilityRegistry,recordCapabilitiesUsed,CAPABILITY_MANIFEST_VERSION}from'./capability-manifest.js';export{IndustryModeRegistry,getIndustryModeRegistry,INDUSTRY_MODE_REGISTRY_VERSION}from'./registry.js';export{MetricRegistry,getMetricRegistry,BUILTIN_METRICS_COUNT}from'./metric-registry.js';export{ConstraintRegistry,getConstraintRegistry,BUILTIN_CONSTRAINTS_COUNT}from'./constraint-registry.js';export{ModeEvaluator}from'./mode-evaluator.js';export{BUILTIN_MODES}from'./modes.js';export{registerIndustryPack,validatePackManifest,listRegisteredPacks,unregisterIndustryPack,scanPacks,rescanPack,resolveIndustryPackDir,scanDefaultIndustryPacks,scaffoldIndustryPack,seedBuiltinIndustryTemplates,diffIndustryPack,resetIndustryPath,readMergedPackIfPresent,buildPristineMergedPack,locatePackAndRemainder,ensureIndustryReadme,industryReadmeContent}from'./industry-pack.js';export{registerDisputeRules,registerComplianceRules,registerSupplyRules,registerIndustryRules,registerIndustryPlaybook,resolveDisputeRules,resolveComplianceRules,resolveSupplyRules,resolveIndustryRules,resolveIndustryPlaybook,listRegisteredDisputeCategories,listRegisteredComplianceCategories,listRegisteredSupplyCategories,listRegisteredIndustryRuleCategories,listRegisteredPlaybookCategories,compileIndustryRule,compileIndustryRules,registerIndustryRulesToEngine,unregisterIndustryRulesFromEngine}from'./industry-layers.js';export{registerIndustryPersonae,getIndustryPersona,listPersonaeIndustries,unregisterIndustryPersonae}from'../persona/pack-personae.js';
1
+ export{CapabilityRegistry,getCapabilityRegistry,CAPABILITY_MANIFEST_VERSION}from'./capability-manifest.js';export{IndustryModeRegistry,getIndustryModeRegistry,INDUSTRY_MODE_REGISTRY_VERSION}from'./registry.js';export{MetricRegistry,getMetricRegistry,BUILTIN_METRICS_COUNT}from'./metric-registry.js';export{ConstraintRegistry,getConstraintRegistry,BUILTIN_CONSTRAINTS_COUNT}from'./constraint-registry.js';export{ModeEvaluator}from'./mode-evaluator.js';export{BUILTIN_MODES}from'./modes.js';export{registerIndustryPack,validatePackManifest,listRegisteredPacks,unregisterIndustryPack,scanPacks,rescanPack,resolveIndustryPackDir,scanDefaultIndustryPacks,scaffoldIndustryPack,seedBuiltinIndustryTemplates,diffIndustryPack,resetIndustryPath,readMergedPackIfPresent,buildPristineMergedPack,locatePackAndRemainder,ensureIndustryReadme,industryReadmeContent}from'./industry-pack.js';export{registerDisputeRules,registerComplianceRules,registerSupplyRules,registerIndustryRules,registerIndustryPlaybook,resolveDisputeRules,resolveComplianceRules,resolveSupplyRules,resolveIndustryRules,resolveIndustryPlaybook,listRegisteredDisputeCategories,listRegisteredComplianceCategories,listRegisteredSupplyCategories,listRegisteredIndustryRuleCategories,listRegisteredPlaybookCategories,compileIndustryRule,compileIndustryRules,registerIndustryRulesToEngine,unregisterIndustryRulesFromEngine}from'./industry-layers.js';export{registerIndustryPersonae,getIndustryPersona,listPersonaeIndustries,unregisterIndustryPersonae}from'../persona/pack-personae.js';
@@ -1 +1 @@
1
- import{readdirSync,readFileSync,existsSync,mkdirSync,writeFileSync}from'node:fs';import{join}from'node:path';import{getWowokIndustryDir}from'@wowok/wowok';import{getIndustryModeRegistry}from'./registry.js';import{BUILTIN_MODES}from'./modes.js';import{registerCategoryMatchRules}from'../evaluation/category-match-rules.js';import{registerIndustryPersonae,unregisterIndustryPersonae}from'../persona/pack-personae.js';import{PERSONA_ROLES,SUPPORTED_INDUSTRIES}from'../persona/types.js';import{UNIVERSAL_TEMPLATE}from'../knowledge/universal-template.js';import{registerDisputeRules,registerComplianceRules,registerSupplyRules,registerIndustryRules,registerIndustryPlaybook,registerIndustryRulesToEngine}from'./industry-layers.js';const FORBIDDEN_PRICING_MODES=new Set(UNIVERSAL_TEMPLATE['pricing_redlines']),packRegistry=new Map();export function validatePackManifest(a){const b=[];return(!a||a['pack']!=='industry-pack')&&b['push']('manifest.pack\x20must\x20be\x20\x27industry-pack\x27'),(!a['name']||typeof a['name']!=='string')&&b['push']('manifest.name\x20is\x20required'),(!a['version']||typeof a['version']!=='string')&&b['push']('manifest.version\x20is\x20required'),(!Array['isArray'](a['layers'])||a['layers']['length']===0x0)&&b['push']('manifest.layers\x20must\x20be\x20a\x20non-empty\x20array'),{'valid':b['length']===0x0,'errors':b};}function isMeaningfulMatch(a){if(!a)return![];return(a['hard_constraints']?.['length']??0x0)>0x0||Object['keys'](a['soft_weights']??{})['length']>0x0||(a['pricing_rules']?.['length']??0x0)>0x0||(a['highlight_fields']?.['length']??0x0)>0x0;}function isMeaningfulPersona(a){const b=a['long_term']??{},c=a['current']??{};return(c['strategy']?.['length']??0x0)>0x0||(c['requirements']?.['length']??0x0)>0x0||(c['rules']?.['length']??0x0)>0x0||(c['spec']?.['length']??0x0)>0x0||Object['keys'](c['preferences']??{})['length']>0x0||Object['keys'](b['preferences']??{})['length']>0x0||(b['identity']?.['region']?.['length']??0x0)>0x0||(b['identity']?.['languages']?.['length']??0x0)>0x0;}function isMeaningfulDispute(a){return(a?.['sla_tiers']?.['length']??0x0)>0x0||(a?.['fault_rules']?.['length']??0x0)>0x0;}function isMeaningfulCompliance(a){return!!a?.['prepay_mode']||(a?.['qualification']?.['length']??0x0)>0x0||(a?.['disclosure']?.['length']??0x0)>0x0||a?.['refund_window']?.['days']!==undefined&&!a?.['refund_window']?.['not_applicable'];}function isMeaningfulSupply(a){return(a?.['supplier_qualification']?.['length']??0x0)>0x0||!!a?.['first_order_policy']||a?.['redundancy_required']===!![];}function isMeaningfulRules(a){return(a?.['rules']?.['length']??0x0)>0x0;}function isMeaningfulPlaybook(a){if(!a)return![];const b=a['content']??'',c=b['replace'](/# .*Industry Playbook/g,'')['replace'](/> .*/g,'')['replace'](/## (Experience|Strategy|Personalization)/g,'')['replace'](/- \(Add .*\)/g,'')['trim']();return c['length']>0x0;}export function registerIndustryPack(a,b=![]){const c=[],d=[],e=a['manifest'],f=validatePackManifest(e);c['push'](...f['errors']);if(!f['valid'])return{'ok':![],'errors':c,'registered':d};const g=packRegistry['get'](e['name']),h=g!==undefined&&g['version']!==e['version'],i=h||b;if(e['layers']['includes']('mode')){if(!a['mode'])c['push']('pack\x20\x27'+e['name']+'\x27\x20declares\x20layer\x20\x27mode\x27\x20but\x20mode.json\x20is\x20missing');else{const j=getIndustryModeRegistry();i&&j['hasMode'](a['mode']['name'])&&j['unregisterMode'](a['mode']['name']),!j['registerMode'](a['mode'])?c['push']('mode\x20\x27'+a['mode']['name']+'\x27\x20failed\x20to\x20register\x20(already\x20registered?).\x20'+'Unregister\x20first\x20or\x20upgrade\x20with\x20a\x20different\x20version.'):d['push']('mode');}}if(e['layers']['includes']('match')){if(!a['match'])c['push']('pack\x20\x27'+e['name']+'\x27\x20declares\x20layer\x20\x27match\x27\x20but\x20match.json\x20is\x20missing');else{if(!isMeaningfulMatch(a['match'])){}else{const k=a['match']['pricing_rules']['filter'](l=>FORBIDDEN_PRICING_MODES['has'](l));if(k['length']>0x0)c['push']('match.pricing_rules\x20contains\x20forbidden\x20modes:\x20'+k['join'](',\x20')+'\x20'+'(violates\x20upper-layer\x20pricing\x20red\x20lines,\x20K3\x2015\x20§4.2)');else!registerCategoryMatchRules(a['match'],i)?c['push']('match\x20rules\x20for\x20\x27'+a['match']['category']+'\x27\x20already\x20registered'):d['push']('match');}}}if(e['layers']['includes']('personae')){if(!a['personae']||a['personae']['length']===0x0)c['push']('pack\x20\x27'+e['name']+'\x27\x20declares\x20layer\x20\x27personae\x27\x20but\x20personae\x20are\x20missing');else{const l=a['personae']['filter'](isMeaningfulPersona);if(l['length']===0x0){}else registerIndustryPersonae(e['name'],l),d['push']('personae');}}if(e['layers']['includes']('dispute')){if(!a['dispute'])c['push']('pack\x20\x27'+e['name']+'\x27\x20declares\x20layer\x20\x27dispute\x27\x20but\x20dispute.json\x20is\x20missing');else{if(!isMeaningfulDispute(a['dispute'])){}else!registerDisputeRules(a['dispute'],i)?c['push']('dispute\x20rules\x20for\x20\x27'+a['dispute']['category']+'\x27\x20already\x20registered'):d['push']('dispute');}}if(e['layers']['includes']('compliance')){if(!a['compliance'])c['push']('pack\x20\x27'+e['name']+'\x27\x20declares\x20layer\x20\x27compliance\x27\x20but\x20compliance.json\x20is\x20missing');else{if(!isMeaningfulCompliance(a['compliance'])){}else!registerComplianceRules(a['compliance'],i)?c['push']('compliance\x20rules\x20for\x20\x27'+a['compliance']['category']+'\x27\x20already\x20registered'):d['push']('compliance');}}if(e['layers']['includes']('supply')){if(!a['supply'])c['push']('pack\x20\x27'+e['name']+'\x27\x20declares\x20layer\x20\x27supply\x27\x20but\x20supply.json\x20is\x20missing');else{if(!isMeaningfulSupply(a['supply'])){}else!registerSupplyRules(a['supply'],i)?c['push']('supply\x20rules\x20for\x20\x27'+a['supply']['category']+'\x27\x20already\x20registered'):d['push']('supply');}}if(e['layers']['includes']('rules')){if(!a['rules'])c['push']('pack\x20\x27'+e['name']+'\x27\x20declares\x20layer\x20\x27rules\x27\x20but\x20rules.json\x20is\x20missing');else{if(!isMeaningfulRules(a['rules'])){}else!registerIndustryRules(a['rules'],i)?c['push']('industry\x20rules\x20for\x20\x27'+a['rules']['category']+'\x27\x20already\x20registered'):(d['push']('rules'),registerIndustryRulesToEngine(a['rules']));}}if(e['layers']['includes']('playbook')){if(!a['playbook'])c['push']('pack\x20\x27'+e['name']+'\x27\x20declares\x20layer\x20\x27playbook\x27\x20but\x20playbook.md\x20is\x20missing');else{if(!isMeaningfulPlaybook(a['playbook'])){}else!registerIndustryPlaybook(a['playbook'],i)?c['push']('playbook\x20for\x20\x27'+a['playbook']['category']+'\x27\x20already\x20registered'):d['push']('playbook');}}return c['length']===0x0&&packRegistry['set'](e['name'],{'version':e['version'],'layers':[...e['layers']],'registered_at':Date['now']()}),{'ok':c['length']===0x0,'errors':c,'registered':d};}let builtinModesAsPacksRegistered=![];function ensureBuiltinModesAsPacks(){if(builtinModesAsPacksRegistered)return;builtinModesAsPacksRegistered=!![];for(const a of BUILTIN_MODES){if(packRegistry['has'](a['name']))continue;packRegistry['set'](a['name'],{'version':a['version'],'layers':['mode','match'],'registered_at':Date['now']()});}}export function listRegisteredPacks(){return ensureBuiltinModesAsPacks(),Array['from'](packRegistry['entries']())['map'](([a,b])=>({'name':a,...b}));}export function unregisterIndustryPack(a){const b=new Set(BUILTIN_MODES['map'](c=>c['name']));if(b['has'](a))return![];if(!packRegistry['has'](a))return![];return packRegistry['delete'](a),unregisterIndustryPersonae(a),!![];}export function diffIndustryPack(a){const b=packRegistry['get'](a)??null,c=resolveIndustryPackDir(),d=join(c,a),e=readMergedPackIfPresent(d);let f=null;try{if(e&&e['manifest'])f={'version':e['manifest']['version'],'layers':e['manifest']['layers']??[]};else{const l=join(d,'manifest.json');if(existsSync(l)){const m=JSON['parse'](readFileSync(l,'utf-8'));f={'version':m['version'],'layers':m['layers']??[]};}}}catch{f=null;}const g=b?.['layers']??[],h=f?.['layers']??[],i=h['filter'](n=>!g['includes'](n)),j=g['filter'](n=>!h['includes'](n)),k=!!b&&!!f&&(b['version']!==f['version']||i['length']>0x0||j['length']>0x0);return{'name':a,'registered':b?{...b,'layers':[...b['layers']]}:null,'disk':f,'upgradable':k,'layer_diff':{'added':i,'removed':j}};}export function scanPacks(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']);try{const e=loadPackFromDir(d);if(!e)continue;b['push'](registerIndustryPack(e));}catch(f){b['push']({'ok':![],'errors':['failed\x20to\x20load\x20pack\x20\x27'+c['name']+'\x27:\x20'+f['message']],'registered':[]});}}return b;}function loadPackFromDir(a){const b=readMergedPackIfPresent(a),c=join(a,'manifest.json'),d=existsSync(c);if(!b&&!d)return null;if(b){const p=b['manifest'],q={'layout':'merged','manifest':p};if(b['mode'])q['mode']=b['mode'];if(b['match'])q['match']=b['match'];b['personae']&&Array['isArray'](b['personae'])&&(q['personae']=b['personae']);if(b['dispute'])q['dispute']=b['dispute'];if(b['compliance'])q['compliance']=b['compliance'];if(b['supply'])q['supply']=b['supply'];if(b['rules'])q['rules']=b['rules'];const r=join(a,'playbook.md');return existsSync(r)&&(q['playbook']={'category':p['name'],'content':readFileSync(r,'utf-8')}),q;}const e=JSON['parse'](readFileSync(c,'utf-8')),g={'layout':'legacy','manifest':e},h=join(a,'mode.json'),i=join(a,'match.json');existsSync(h)&&(g['mode']=JSON['parse'](readFileSync(h,'utf-8')));existsSync(i)&&(g['match']=JSON['parse'](readFileSync(i,'utf-8')));const j=join(a,'personae');if(existsSync(j)){const s=[];for(const t of readdirSync(j)){if(!t['endsWith']('.json'))continue;s['push'](JSON['parse'](readFileSync(join(j,t),'utf-8')));}if(s['length']>0x0)g['personae']=s;}const k=join(a,'dispute.json');existsSync(k)&&(g['dispute']=JSON['parse'](readFileSync(k,'utf-8')));const l=join(a,'compliance.json');existsSync(l)&&(g['compliance']=JSON['parse'](readFileSync(l,'utf-8')));const m=join(a,'supply.json');existsSync(m)&&(g['supply']=JSON['parse'](readFileSync(m,'utf-8')));const n=join(a,'rules.json');existsSync(n)&&(g['rules']=JSON['parse'](readFileSync(n,'utf-8')));const o=join(a,'playbook.md');return existsSync(o)&&(g['playbook']={'category':e['name'],'content':readFileSync(o,'utf-8')}),g;}export function rescanPack(a){const b=join(resolveIndustryPackDir(),a);try{const c=loadPackFromDir(b);if(!c)return{'ok':![],'errors':['no\x20pack\x20found\x20for\x20\x27'+a+'\x27'],'registered':[]};return registerIndustryPack(c,!![]);}catch(d){return{'ok':![],'errors':['failed\x20to\x20rescan\x20pack\x20\x27'+a+'\x27:\x20'+d['message']],'registered':[]};}}export function resolveIndustryPackDir(){return process['env']['WOWOK_INDUSTRY_DIR']||getWowokIndustryDir();}export function scanDefaultIndustryPacks(){return seedBuiltinIndustryTemplates(),ensureIndustryReadme(),ensureBuiltinModesAsPacks(),scanPacks(resolveIndustryPackDir());}export function seedBuiltinIndustryTemplates(a=SUPPORTED_INDUSTRIES){const b=[],c=resolveIndustryPackDir();mkdirSync(c,{'recursive':!![]}),ensureIndustryReadme();for(const d of a){const e=join(c,d);if(existsSync(join(e,'manifest.json'))||existsSync(join(e,'pack.json')))continue;const f=scaffoldIndustryPack(d,c);if(f['ok'])b['push'](d);}return b;}export const LAYER_FILE_SECTION={'match.json':'match','dispute.json':'dispute','compliance.json':'compliance','supply.json':'supply','rules.json':'rules','mode.json':'mode'};export const PERSONAE_DIR='personae';function manifestSection(a){return{'pack':'industry-pack','name':a,'display_name':a,'version':'0.1.0','layers':['match','personae','dispute','compliance','supply','rules','playbook']};}function matchSection(a){return{'category':a,'hard_constraints':[],'soft_weights':{},'highlight_fields':[],'calendar_mode':'none','geo_mode':'strict','pricing_rules':[]};}function personaPerRole(a,b){return{'role':a,'industry':b,'long_term':{'identity':{'self_description':b+'\x20'+a},'preferences':{}},'current':{'strategy':[],'requirements':[],'rules':[],'spec':'','preferences':{}}};}function disputeSection(a){return{'category':a,'sla_tiers':[],'fault_rules':[]};}function complianceSection(a){return{'category':a,'prepay_mode':'','qualification':[],'disclosure':[],'refund_window':{'days':0x7,'not_applicable':![]}};}function supplySection(a){return{'category':a,'supplier_qualification':[],'first_order_policy':'','redundancy_required':![]};}function rulesSection(a){return{'category':a,'rules':[]};}export function buildPristineMergedPack(a){const b=PERSONA_ROLES['map'](c=>personaPerRole(c,a));return{'manifest':manifestSection(a),'match':matchSection(a),'personae':b,'dispute':disputeSection(a),'compliance':complianceSection(a),'supply':supplySection(a),'rules':rulesSection(a),'mode':null};}export function industryReadmeContent(){return['#\x20WoWok\x20Industry\x20Packs','','>\x20This\x20folder\x20is\x20the\x20WoWok\x20industry\x20knowledge\x20root.\x20Each\x20sub-folder\x20is\x20one','>\x20industry\x20pack.\x20The\x20AI\x20reads\x20pack\x20data\x20as\x20context\x20on\x20every\x20chat\x20turn.','','##\x20Pack\x20structure\x20(unified\x20layout)','','Every\x20pack\x20is\x20exactly\x20two\x20files:','','-\x20**`<pack>/pack.json`**\x20—\x20machine-checkable\x20**settings\x20only**.\x20No\x20comments,','\x20\x20no\x20documentation.\x20One\x20section\x20per\x20layer\x20(see\x20below).','-\x20**`<pack>/playbook.md`**\x20—\x20human\x20strategy,\x20tone\x20and\x20field-tested\x20experience.','\x20\x20The\x20AI\x20reads\x20it\x20as\x20context\x20and\x20it\x20OVERRIDES\x20built-in\x20industry\x20data\x20for','\x20\x20this\x20account.','','All\x20field\x20explanations\x20live\x20in\x20THIS\x20file,\x20so\x20pack.json\x20stays\x20small\x20and\x20you','can\x20focus\x20on\x20configuration.\x20The\x20editor\x20also\x20validates\x20JSON\x20on\x20save\x20—\x20a\x20file','that\x20fails\x20to\x20parse\x20(or\x20a\x20pack.json\x20missing\x20its\x20manifest)\x20is\x20blocked.','','##\x20How\x20changes\x20take\x20effect','','1.\x20**Save**\x20in\x20the\x20Editor\x20writes\x20bytes\x20to\x20disk.','2.\x20**Scan**\x20(Industry\x20drawer)\x20re-registers\x20each\x20pack\x20into\x20the\x20runtime\x20AI','\x20\x20\x20registry\x20(and\x20SQLite\x20cache).\x20A\x20save\x20of\x20an\x20industry\x20file\x20already\x20runs','\x20\x20\x20Scan\x20automatically.','3.\x20**Next\x20AI\x20chat\x20turn**\x20the\x20L1\x20prompt\x20builder\x20reads\x20the\x20registered\x20layers,','\x20\x20\x20so\x20the\x20AI\x20reasons\x20against\x20your\x20edited\x20rules\x20from\x20that\x20point\x20onward.','','##\x20manifest\x20—\x20pack\x20metadata\x20+\x20layer\x20ENABLE\x20flags','','-\x20`name`:\x20snake_case\x20identifier,\x20must\x20match\x20the\x20folder\x20name.','-\x20`version`:\x20bump\x20after\x20editing\x20content\x20so\x20the\x20registry\x20treats\x20it\x20as\x20an\x20upgrade.','-\x20`display_name`:\x20user-visible\x20label.','-\x20`layers`:\x20which\x20sections\x20are\x20validated\x20and\x20registered\x20on\x20scan.\x20Remove\x20a','\x20\x20layer\x20name\x20to\x20DISABLE\x20it\x20(the\x20section\x20stays\x20in\x20pack.json\x20but\x20is\x20ignored).','','##\x20match\x20—\x20category-match\x20rules','','Decides\x20whether\x20an\x20order/service/account\x20belongs\x20to\x20this\x20industry\x20pack:','-\x20`hard_constraints`:\x20array\x20of\x20REQUIRED\x20predicates;\x20ALL\x20must\x20match\x20before\x20the','\x20\x20pack\x20is\x20considered.\x20Example:','\x20\x20`[{\x20key:\x20\x27order.metadata.service_kind\x27,\x20equals:\x20\x27food_onsite\x27\x20}]`','-\x20`soft_weights`:\x20dict\x20`<heuristic_key:\x20number\x200..1>`;\x20higher\x20=\x20stronger\x20signal.','-\x20`pricing_rules`:\x20pricing\x20modes\x20this\x20industry\x20requires.','-\x20`highlight_fields`:\x20dot-paths\x20surfaced\x20in\x20the\x20UI\x20as\x20important\x20info.','-\x20`geo_mode`:\x20`\x27strict\x27`\x20(region\x20must\x20match)\x20|\x20`\x27none\x27`\x20(ignore\x20region).','-\x20`calendar_mode`:\x20`\x27seasonal\x27`\x20|\x20`\x27weekday\x27`\x20|\x20`\x27none\x27`.','','##\x20personae\x20—\x20per-role\x20AI\x20personas','','One\x20persona\x20per\x20role\x20(`merchant`,\x20`customer`,\x20`supplier`,\x20`collaborator`,','`arbitrator`,\x20`prospect`).\x20The\x20AI\x20uses\x20them\x20to\x20role-play\x20negotiation\x20posture:','-\x20`long_term`:\x20stable\x20properties\x20—\x20`identity.self_description`\x20(free-text\x20bio),','\x20\x20`identity.region/languages`,\x20`preferences`\x20(`<key:\x20string[]>`).','-\x20`current`:\x20per-negotiation\x20posture\x20—\x20`strategy`\x20(moves\x20to\x20make),','\x20\x20`requirements`\x20(non-negotiable\x20demands),\x20`rules`\x20(constraints/axioms),','\x20\x20`spec`\x20(free-form\x20text),\x20`preferences`\x20(per-turn\x20overrides).','','##\x20dispute\x20—\x20SLA\x20tiers\x20+\x20fault\x20assignment','','-\x20`sla_tiers[]`:\x20response/remedy\x20windows\x20per\x20severity\x20level.','\x20\x20Example:\x20`{\x20level:\x20\x27L1\x27,\x20response_hours:\x2024,\x20remedy:\x20\x27reply\x27\x20}`','-\x20`fault_rules[]`:\x20automatic\x20fault\x20attribution\x20—\x20a\x20condition\x20plus\x20the\x20side','\x20\x20that\x20bears\x20fault\x20(`merchant`/`customer`/`supplier`/`operator`/`shared`).','\x20\x20Example:\x20`{\x20when:\x20{\x20evidence_has:\x20[\x27late\x20delivery\x20photo\x27]\x20},\x20assign_to:\x20\x27merchant\x27,\x20weight:\x201.0\x20}`','','##\x20compliance\x20—\x20hard\x20requirements\x20before\x20checkout','','-\x20`prepay_mode`:\x20`\x27\x27`\x20|\x20`\x27full\x27`\x20|\x20`\x27partial\x27`\x20|\x20`\x27deposit\x27`.','-\x20`qualification[]`:\x20licenses/certifications\x20a\x20merchant\x20must\x20hold.','\x20\x20Example:\x20`{\x20label:\x20\x27Food\x20Service\x20License\x27,\x20required:\x20true,\x20region:\x20\x27CN\x27\x20}`','-\x20`disclosure[]`:\x20text\x20the\x20merchant\x20MUST\x20show\x20buyers\x20up-front.','-\x20`refund_window`:\x20`{\x20days:\x20number,\x20not_applicable:\x20boolean,\x20exceptions:\x20[...]\x20}`','','##\x20supply\x20—\x20supply-chain\x20/\x20supplier\x20qualification','','-\x20`supplier_qualification[]`:\x20same\x20shape\x20as\x20compliance\x20qualifications,\x20but','\x20\x20evaluated\x20on\x20the\x20SUPPLIER\x20side\x20(multi-party\x20orders).','-\x20`first_order_policy`:\x20policy\x20string\x20on\x20the\x20first\x20order\x20from\x20a\x20new\x20supplier','\x20\x20(e.g.\x20`\x27sample-only\x27`,\x20`\x27reduced-quantity\x27`).','-\x20`redundancy_required`:\x20true\x20=\x20require\x20≥2\x20eligible\x20suppliers\x20before\x20accepting','\x20\x20an\x20order\x20(mitigates\x20single-sourcing).','','##\x20rules\x20—\x20declarative\x20machine-checked\x20rules','','Each\x20rule\x20is\x20an\x20AST\x20node\x20compiled\x20into\x20the\x20evaluation\x20engine:','`{\x20id:\x20\x27rule_...\x27,\x20when:\x20<bool-condition>,\x20then:\x20\x27reject\x27\x20|\x20\x27warn\x27\x20|\x20\x27flag\x27,\x20message:\x20\x27Text\x27\x20}`','Use\x20`rules`\x20for\x20rules\x20that\x20must\x20be\x20machine-checked;\x20put\x20human\x20strategy\x20in','`playbook.md`.','','##\x20mode\x20—\x20IndustryMode\x20(deep\x20shape)','','Not\x20scaffolded\x20by\x20default.\x20Add\x20it\x20when\x20you\x20need\x20a\x20full\x20driving\x20mode\x20for\x20the','industry,\x20or\x20ask\x20the\x20AI:\x20\x22help\x20me\x20fill\x20mode\x20for\x20<industry>\x22.','','##\x20Reset','','Right-click\x20any\x20file/pack\x20folder\x20in\x20the\x20Industry\x20drawer\x20and\x20choose\x20*Reset*','to\x20restore\x20the\x20pristine\x20template\x20at\x20any\x20time.','']['join']('\x0a');}export function ensureIndustryReadme(){const a=resolveIndustryPackDir();mkdirSync(a,{'recursive':!![]});const b=join(a,'README.md');return writeFileSync(b,industryReadmeContent(),'utf-8'),b;}export function scaffoldIndustryPack(a,b){const c=join(b??resolveIndustryPackDir(),a),d=[],e=[];if(!/^[a-z][a-z0-9_]*$/['test'](a))return{'ok':![],'dir':c,'files':d,'errors':['industry\x20name\x20\x27'+a+'\x27\x20must\x20be\x20lowercase\x20snake_case\x20(a-z,\x200-9,\x20_)']};try{mkdirSync(c,{'recursive':!![]}),ensureIndustryReadme();const f=buildPristineMergedPack(a);return writeFileSync(join(c,'pack.json'),JSON['stringify'](f,null,0x2)+'\x0a'),d['push']('pack.json'),writeFileSync(join(c,'playbook.md'),playbookTemplate(a)),d['push']('playbook.md'),{'ok':!![],'dir':c,'files':d,'errors':e};}catch(g){return{'ok':![],'dir':c,'files':d,'errors':['scaffold\x20failed:\x20'+g['message']]};}}export function readMergedPackIfPresent(a){const b=join(a,'pack.json');if(!existsSync(b))return null;try{const c=readFileSync(b,'utf-8');return JSON['parse'](c);}catch{return null;}}function playbookTemplate(a){return['#\x20'+a+'\x20—\x20Industry\x20Playbook','','>\x20📘\x20This\x20file\x20captures\x20human\x20business\x20intelligence\x20for\x20the\x20`'+a+'`','>\x20industry.\x20Content\x20here\x20is\x20READ\x20BY\x20THE\x20AI\x20AS\x20CONTEXT\x20on\x20every\x20turn,','>\x20and\x20OVERRIDES\x20WoWok\x27s\x20generic\x20built-in\x20industry\x20data/rules\x20for\x20this','>\x20account.\x20The\x20companion\x20`pack.json`\x20file\x20stores\x20machine-checkable','>\x20rules;\x20THIS\x20file\x20stores\x20human\x20strategy,\x20tone,\x20experience,\x20and\x20ethics.','','>\x20💡\x20Hint\x20for\x20the\x20AI:\x20when\x20the\x20user\x20asks\x20a\x20question\x20about\x20\x22how\x20to','>\x20handle\x20'+a+'\x22\x20or\x20\x22what\x20should\x20I\x20do?\x22,\x20check\x20this\x20file\x20first\x20for\x20the','>\x20merchant/customer\x20voice,\x20then\x20fall\x20back\x20to\x20your\x20built-in\x20data.\x20Cite','>\x20section\x20titles\x20in\x20your\x20reply\x20so\x20the\x20user\x20knows\x20where\x20advice\x20comes\x20from.','','##\x20Experience\x20(Field-Tested\x20Rules\x20of\x20Thumb)','','>\x20Write\x20what\x20actually\x20works\x20in\x20this\x20industry\x20—\x20not\x20what\x20textbooks\x20say.','>\x20Short\x20bullet\x20points\x20preferred;\x20the\x20AI\x20reads\x20them\x20as\x20axioms.\x20Include','>\x20specific\x20numbers\x20when\x20you\x20have\x20them.','','-\x20(Example)\x20\x22Catering:\x20if\x20the\x20event\x20starts\x20before\x2010:00,\x20always\x20assume','\x20\x20the\x20customer\x20wants\x20breakfast\x20service\x20too\x20—\x20upsell\x20it\x20proactively.\x22','-\x20(Example)\x20\x22Common\x20pitfall:\x20last-minute\x20menu\x20swaps\x20on\x20Fridays\x20—\x20require','\x20\x20a\x20written\x20change\x20request\x2048\x20h\x20before\x20the\x20event\x20or\x20charge\x20a\x2015%\x20fee.\x22','-\x20(Add\x20more\x20below\x20—\x20delete\x20the\x20examples\x20above\x20when\x20you\x20have\x20real\x20ones.)','','##\x20Strategy\x20(Competitive\x20/\x20Game-Theory)','','>\x20How\x20should\x20each\x20role\x20act\x20in\x20a\x20negotiation\x20/\x20dispute\x20/\x20supplier','>\x20relationship?\x20Think\x20in\x20\x22always\x20/\x20never\x20/\x20depends-on-X\x22\x20rules,\x20and\x20call','>\x20out\x20the\x20trade-offs.','','-\x20Merchant\x20strategy:\x20(Add\x20how\x20a\x20merchant\x20in\x20this\x20industry\x20should\x20act\x20—','\x20\x20price\x20anchoring,\x20which\x20concessions\x20to\x20give\x20early\x20vs\x20late,\x20what\x20to','\x20\x20never\x20concede\x20on,\x20etc.)','-\x20Customer\x20strategy:\x20(Add\x20what\x20a\x20smart\x20customer\x20should\x20push\x20for.)','-\x20Dispute\x20strategy:\x20(When\x20to\x20settle\x20fast\x20vs\x20when\x20to\x20fight\x20for\x20full','\x20\x20evidence\x20+\x20arbitration.\x20Call\x20out\x20the\x20escalation\x20thresholds.)','','##\x20Personalization\x20(Tone,\x20Brand,\x20Ethics,\x20Red\x20Lines)','','-\x20Tone\x20/\x20voice:\x20(Write\x20one\x20sentence\x20describing\x20the\x20exact\x20conversational','\x20\x20voice\x20this\x20account\x20should\x20use\x20—\x20casual,\x20formal,\x20technical,\x20etc.)','-\x20Brand\x20rules:\x20(Logo,\x20link-out\x20style,\x20forbidden\x20terminology,','\x20\x20always-include\x20phrases,\x20etc.)','-\x20Red\x20lines:\x20(Non-negotiable.\x20Example:\x20\x22Never\x20make\x20a\x20refund\x20promise','\x20\x20larger\x20than\x2030%\x20without\x20arbitration\x20evidence.\x22)','-\x20Ethics:\x20(Example:\x20\x22If\x20customer\x20appears\x20intoxicated,\x20refuse\x20service','\x20\x20and\x20refer\x20to\x20supervisor;\x20never\x20take\x20the\x20order\x20for\x20profit.\x22)','','##\x20Playbook\x20Maintenance','','>\x20You\x20don\x27t\x20need\x20to\x20be\x20perfect\x20on\x20day\x20one.\x20After\x20every\x20real\x20deal,\x20add\x20a','>\x20bullet\x20to\x20the\x20above\x20sections\x20with\x20what\x20worked\x20/\x20what\x20failed.\x20Every','>\x20entry\x20improves\x20the\x20AI\x27s\x20future\x20decisions.','','>\x20Right-click\x20the\x20file\x20or\x20this\x20pack\x20folder\x20in\x20the\x20Industry\x20drawer\x20at','>\x20any\x20time\x20and\x20choose\x20\x22Reset\x22\x20to\x20restore\x20this\x20annotated\x20template.','']['join']('\x0a');}export function locatePackAndRemainder(a){const b=a['replace'](/^[\\/]+/,'')['replace'](/[\\/]+$/,'');if(!b)return null;const [c,...d]=b['split'](/[\\/]+/);if(!c)return null;return{'packName':c,'remainder':d['join']('/')};}export function resetIndustryPath(a,b){const c=[],d=[],f=b??resolveIndustryPackDir(),g=locatePackAndRemainder(a),h=a;if(!g)return{'ok':![],'layout':'merged','target':h,'restored_files':[],'errors':['invalid\x20reset\x20path\x20\x27'+a+'\x27']};const {packName:i,remainder:j}=g,k=join(f,i);if(!existsSync(k))return{'ok':![],'layout':'merged','target':h,'restored_files':[],'errors':['pack\x20directory\x20\x27'+i+'\x27\x20does\x20not\x20exist']};if(!/^[a-z][a-z0-9_]*$/['test'](i))return{'ok':![],'layout':'merged','target':h,'restored_files':[],'errors':['pack\x20name\x20\x27'+i+'\x27\x20is\x20not\x20a\x20valid\x20snake_case\x20identifier']};const l=readMergedPackIfPresent(k),n=l?'merged':'legacy';if(j==='')try{mkdirSync(k,{'recursive':!![]});const s=buildPristineMergedPack(i);return writeFileSync(join(k,'pack.json'),JSON['stringify'](s,null,0x2)+'\x0a'),d['push']('pack.json'),writeFileSync(join(k,'playbook.md'),playbookTemplate(i)),d['push']('playbook.md'),{'ok':!![],'layout':'merged','target':h,'restored_files':d,'errors':c};}catch(t){return{'ok':![],'layout':n,'target':h,'restored_files':d,'errors':['pack\x20reset\x20failed:\x20'+t['message']]};}const o=j['split']('/')['slice'](-0x1)[0x0],p=j==='playbook.md',q=j['startsWith'](PERSONAE_DIR+'/')&&o['endsWith']('.json');if(n==='merged'){if(p)try{return writeFileSync(join(k,'playbook.md'),playbookTemplate(i)),d['push']('playbook.md'),{'ok':!![],'layout':n,'target':h,'restored_files':d,'errors':c};}catch(v){return{'ok':![],'layout':n,'target':h,'restored_files':d,'errors':['playbook\x20reset\x20failed:\x20'+v['message']]};}const u=LAYER_FILE_SECTION[j];if(u)try{const w=readMergedPackIfPresent(k)??buildPristineMergedPack(i);switch(u){case'match':w['match']=matchSection(i);break;case'dispute':w['dispute']=disputeSection(i);break;case'compliance':w['compliance']=complianceSection(i);break;case'supply':w['supply']=supplySection(i);break;case'rules':w['rules']=rulesSection(i);break;case'mode':w['mode']=null;break;}return writeFileSync(join(k,'pack.json'),JSON['stringify'](w,null,0x2)+'\x0a'),d['push']('pack.json'),{'ok':!![],'layout':n,'target':h,'restored_files':d,'errors':c};}catch(x){return{'ok':![],'layout':n,'target':h,'restored_files':d,'errors':['section\x20reset\x20failed:\x20'+x['message']]};}if(q){const y=o['replace'](/\.json$/,'');if(!PERSONA_ROLES['includes'](y))return{'ok':![],'layout':n,'target':h,'restored_files':[],'errors':['unknown\x20persona\x20role\x20\x27'+y+'\x27']};try{const z=readMergedPackIfPresent(k)??buildPristineMergedPack(i),A=z['personae']&&Array['isArray'](z['personae'])?[...z['personae']]:[],B=A['findIndex'](D=>D['role']===y),C=personaPerRole(y,i);if(B>=0x0)A[B]=C;else A['push'](C);return z['personae']=A,writeFileSync(join(k,'pack.json'),JSON['stringify'](z,null,0x2)+'\x0a'),d['push']('pack.json'),{'ok':!![],'layout':n,'target':h,'restored_files':d,'errors':c};}catch(D){return{'ok':![],'layout':n,'target':h,'restored_files':d,'errors':['persona\x20reset\x20failed:\x20'+D['message']]};}}if(j==='manifest.json'||j==='manifest')try{const E=readMergedPackIfPresent(k)??buildPristineMergedPack(i);return E['manifest']=manifestSection(i),writeFileSync(join(k,'pack.json'),JSON['stringify'](E,null,0x2)+'\x0a'),d['push']('pack.json'),{'ok':!![],'layout':n,'target':h,'restored_files':d,'errors':c};}catch(F){return{'ok':![],'layout':n,'target':h,'restored_files':d,'errors':['manifest\x20reset\x20failed:\x20'+F['message']]};}return{'ok':![],'layout':n,'target':h,'restored_files':[],'errors':['path\x20\x27'+j+'\x27\x20is\x20not\x20a\x20standard\x20section\x20file\x20of\x20pack\x20\x27'+i+'\x27.\x20Reset\x20is\x20only\x20provided\x20for\x20pack.json\x20standard\x20sections\x20and\x20playbook.md.']};}if(p)try{return writeFileSync(join(k,'playbook.md'),playbookTemplate(i)),d['push']('playbook.md'),{'ok':!![],'layout':n,'target':h,'restored_files':d,'errors':c};}catch(G){return{'ok':![],'layout':n,'target':h,'restored_files':d,'errors':['legacy\x20playbook\x20reset\x20failed:\x20'+G['message']]};}if(j==='manifest.json')try{const H=manifestSection(i);return writeFileSync(join(k,'manifest.json'),JSON['stringify'](H,null,0x2)+'\x0a'),d['push']('manifest.json'),{'ok':!![],'layout':n,'target':h,'restored_files':d,'errors':c};}catch(I){return{'ok':![],'layout':n,'target':h,'restored_files':d,'errors':['legacy\x20manifest\x20reset\x20failed:\x20'+I['message']]};}const r=LAYER_FILE_SECTION[j];if(r)try{let J='';switch(r){case'match':J=JSON['stringify'](matchSection(i),null,0x2)+'\x0a';break;case'dispute':J=JSON['stringify'](disputeSection(i),null,0x2)+'\x0a';break;case'compliance':J=JSON['stringify'](complianceSection(i),null,0x2)+'\x0a';break;case'supply':J=JSON['stringify'](supplySection(i),null,0x2)+'\x0a';break;case'rules':J=JSON['stringify'](rulesSection(i),null,0x2)+'\x0a';break;case'mode':J=JSON['stringify']({},null,0x2)+'\x0a';break;}return writeFileSync(join(k,j),J),d['push'](j),{'ok':!![],'layout':n,'target':h,'restored_files':d,'errors':c};}catch(K){return{'ok':![],'layout':n,'target':h,'restored_files':d,'errors':['legacy\x20section\x20reset\x20failed:\x20'+K['message']]};}if(q){const L=o['replace'](/\.json$/,'');if(!PERSONA_ROLES['includes'](L))return{'ok':![],'layout':n,'target':h,'restored_files':[],'errors':['unknown\x20persona\x20\x27'+L+'\x27']};try{return writeFileSync(join(k,j),JSON['stringify'](personaPerRole(L,i),null,0x2)+'\x0a'),d['push'](j),{'ok':!![],'layout':n,'target':h,'restored_files':d,'errors':c};}catch(M){return{'ok':![],'layout':n,'target':h,'restored_files':d,'errors':['legacy\x20persona\x20reset\x20failed:\x20'+M['message']]};}}return{'ok':![],'layout':n,'target':h,'restored_files':[],'errors':['cannot\x20reset\x20non-standard\x20file\x20\x27'+j+'\x27\x20in\x20legacy\x20layout.\x20Only\x20standard\x20layer\x20files,\x20personae/*.json,\x20manifest.json,\x20and\x20playbook.md\x20can\x20be\x20reset.']};}
1
+ import{readdirSync,readFileSync,existsSync,mkdirSync,writeFileSync}from'node:fs';import{join}from'node:path';import{getWowokIndustryDir}from'@wowok/wowok';import{getIndustryModeRegistry}from'./registry.js';import{BUILTIN_MODES}from'./modes.js';import{registerCategoryMatchRules}from'../evaluation/category-match-rules.js';import{registerIndustryPersonae,unregisterIndustryPersonae}from'../persona/pack-personae.js';import{PERSONA_ROLES,SUPPORTED_INDUSTRIES}from'../persona/types.js';import{UNIVERSAL_TEMPLATE}from'../knowledge/universal-template.js';import{registerDisputeRules,registerComplianceRules,registerSupplyRules,registerIndustryRules,registerIndustryPlaybook,registerIndustryRulesToEngine}from'./industry-layers.js';const FORBIDDEN_PRICING_MODES=new Set(UNIVERSAL_TEMPLATE['pricing_redlines']),packRegistry=new Map();export function validatePackManifest(a){const b=[];return(!a||a['pack']!=='industry-pack')&&b['push']('manifest.pack\x20must\x20be\x20\x27industry-pack\x27'),(!a['name']||typeof a['name']!=='string')&&b['push']('manifest.name\x20is\x20required'),(!a['version']||typeof a['version']!=='string')&&b['push']('manifest.version\x20is\x20required'),(!Array['isArray'](a['layers'])||a['layers']['length']===0x0)&&b['push']('manifest.layers\x20must\x20be\x20a\x20non-empty\x20array'),{'valid':b['length']===0x0,'errors':b};}function isMeaningfulMatch(a){if(!a)return![];return(a['hard_constraints']?.['length']??0x0)>0x0||Object['keys'](a['soft_weights']??{})['length']>0x0||(a['pricing_rules']?.['length']??0x0)>0x0||(a['highlight_fields']?.['length']??0x0)>0x0;}function isMeaningfulPersona(a){const b=a['long_term']??{},c=a['current']??{};return(c['strategy']?.['length']??0x0)>0x0||(c['requirements']?.['length']??0x0)>0x0||(c['rules']?.['length']??0x0)>0x0||(c['spec']?.['length']??0x0)>0x0||Object['keys'](c['preferences']??{})['length']>0x0||Object['keys'](b['preferences']??{})['length']>0x0||(b['identity']?.['region']?.['length']??0x0)>0x0||(b['identity']?.['languages']?.['length']??0x0)>0x0;}function isMeaningfulDispute(a){return(a?.['sla_tiers']?.['length']??0x0)>0x0||(a?.['fault_rules']?.['length']??0x0)>0x0;}function isMeaningfulCompliance(a){return!!a?.['prepay_mode']||(a?.['qualification']?.['length']??0x0)>0x0||(a?.['disclosure']?.['length']??0x0)>0x0||a?.['refund_window']?.['days']!==undefined&&!a?.['refund_window']?.['not_applicable'];}function isMeaningfulSupply(a){return(a?.['supplier_qualification']?.['length']??0x0)>0x0||!!a?.['first_order_policy']||a?.['redundancy_required']===!![];}function isMeaningfulRules(a){return(a?.['rules']?.['length']??0x0)>0x0;}function isMeaningfulPlaybook(a){if(!a)return![];const b=a['content']??'',c=b['replace'](/# .*Industry Playbook/g,'')['replace'](/> .*/g,'')['replace'](/## (Experience|Strategy|Personalization)/g,'')['replace'](/- \(Add .*\)/g,'')['trim']();return c['length']>0x0;}export function registerIndustryPack(a,b=![]){const c=[],d=[],e=a['manifest'],f=validatePackManifest(e);c['push'](...f['errors']);if(!f['valid'])return{'ok':![],'errors':c,'registered':d};const g=packRegistry['get'](e['name']),h=g!==undefined&&g['version']!==e['version'],i=h||b;if(e['layers']['includes']('mode')){if(!a['mode'])c['push']('pack\x20\x27'+e['name']+'\x27\x20declares\x20layer\x20\x27mode\x27\x20but\x20mode.json\x20is\x20missing');else{const j=getIndustryModeRegistry();i&&j['hasMode'](a['mode']['name'])&&j['unregisterMode'](a['mode']['name']),!j['registerMode'](a['mode'])?c['push']('mode\x20\x27'+a['mode']['name']+'\x27\x20failed\x20to\x20register\x20(already\x20registered?).\x20'+'Unregister\x20first\x20or\x20upgrade\x20with\x20a\x20different\x20version.'):d['push']('mode');}}if(e['layers']['includes']('match')){if(!a['match'])c['push']('pack\x20\x27'+e['name']+'\x27\x20declares\x20layer\x20\x27match\x27\x20but\x20match.json\x20is\x20missing');else{if(!isMeaningfulMatch(a['match'])){}else{const k=a['match']['pricing_rules']['filter'](l=>FORBIDDEN_PRICING_MODES['has'](l));if(k['length']>0x0)c['push']('match.pricing_rules\x20contains\x20forbidden\x20modes:\x20'+k['join'](',\x20')+'\x20'+'(violates\x20upper-layer\x20pricing\x20red\x20lines,\x20K3\x2015\x20§4.2)');else!registerCategoryMatchRules(a['match'],i)?c['push']('match\x20rules\x20for\x20\x27'+a['match']['category']+'\x27\x20already\x20registered'):d['push']('match');}}}if(e['layers']['includes']('personae')){if(!a['personae']||a['personae']['length']===0x0)c['push']('pack\x20\x27'+e['name']+'\x27\x20declares\x20layer\x20\x27personae\x27\x20but\x20personae\x20are\x20missing');else{const l=a['personae']['filter'](isMeaningfulPersona);if(l['length']===0x0){}else registerIndustryPersonae(e['name'],l),d['push']('personae');}}if(e['layers']['includes']('dispute')){if(!a['dispute'])c['push']('pack\x20\x27'+e['name']+'\x27\x20declares\x20layer\x20\x27dispute\x27\x20but\x20dispute.json\x20is\x20missing');else{if(!isMeaningfulDispute(a['dispute'])){}else!registerDisputeRules(a['dispute'],i)?c['push']('dispute\x20rules\x20for\x20\x27'+a['dispute']['category']+'\x27\x20already\x20registered'):d['push']('dispute');}}if(e['layers']['includes']('compliance')){if(!a['compliance'])c['push']('pack\x20\x27'+e['name']+'\x27\x20declares\x20layer\x20\x27compliance\x27\x20but\x20compliance.json\x20is\x20missing');else{if(!isMeaningfulCompliance(a['compliance'])){}else!registerComplianceRules(a['compliance'],i)?c['push']('compliance\x20rules\x20for\x20\x27'+a['compliance']['category']+'\x27\x20already\x20registered'):d['push']('compliance');}}if(e['layers']['includes']('supply')){if(!a['supply'])c['push']('pack\x20\x27'+e['name']+'\x27\x20declares\x20layer\x20\x27supply\x27\x20but\x20supply.json\x20is\x20missing');else{if(!isMeaningfulSupply(a['supply'])){}else!registerSupplyRules(a['supply'],i)?c['push']('supply\x20rules\x20for\x20\x27'+a['supply']['category']+'\x27\x20already\x20registered'):d['push']('supply');}}if(e['layers']['includes']('rules')){if(!a['rules'])c['push']('pack\x20\x27'+e['name']+'\x27\x20declares\x20layer\x20\x27rules\x27\x20but\x20rules.json\x20is\x20missing');else{if(!isMeaningfulRules(a['rules'])){}else!registerIndustryRules(a['rules'],i)?c['push']('industry\x20rules\x20for\x20\x27'+a['rules']['category']+'\x27\x20already\x20registered'):(d['push']('rules'),registerIndustryRulesToEngine(a['rules']));}}if(e['layers']['includes']('playbook')){if(!a['playbook'])c['push']('pack\x20\x27'+e['name']+'\x27\x20declares\x20layer\x20\x27playbook\x27\x20but\x20playbook.md\x20is\x20missing');else{if(!isMeaningfulPlaybook(a['playbook'])){}else!registerIndustryPlaybook(a['playbook'],i)?c['push']('playbook\x20for\x20\x27'+a['playbook']['category']+'\x27\x20already\x20registered'):d['push']('playbook');}}return c['length']===0x0&&packRegistry['set'](e['name'],{'version':e['version'],'layers':[...e['layers']],'registered_at':Date['now']()}),{'ok':c['length']===0x0,'errors':c,'registered':d};}let builtinModesAsPacksRegistered=![];function ensureBuiltinModesAsPacks(){if(builtinModesAsPacksRegistered)return;builtinModesAsPacksRegistered=!![];for(const a of BUILTIN_MODES){if(packRegistry['has'](a['name']))continue;packRegistry['set'](a['name'],{'version':a['version'],'layers':['mode','match'],'registered_at':Date['now']()});}}export function listRegisteredPacks(){return ensureBuiltinModesAsPacks(),Array['from'](packRegistry['entries']())['map'](([a,b])=>({'name':a,...b}));}export function unregisterIndustryPack(a){const b=new Set(BUILTIN_MODES['map'](c=>c['name']));if(b['has'](a))return![];if(!packRegistry['has'](a))return![];return packRegistry['delete'](a),unregisterIndustryPersonae(a),!![];}export function diffIndustryPack(a){const b=packRegistry['get'](a)??null,c=resolveIndustryPackDir(),d=join(c,a),e=readMergedPackIfPresent(d);let f=null;try{if(e&&e['manifest'])f={'version':e['manifest']['version'],'layers':e['manifest']['layers']??[]};else{const l=join(d,'manifest.json');if(existsSync(l)){const m=JSON['parse'](readFileSync(l,'utf-8'));f={'version':m['version'],'layers':m['layers']??[]};}}}catch{f=null;}const g=b?.['layers']??[],h=f?.['layers']??[],i=h['filter'](n=>!g['includes'](n)),j=g['filter'](n=>!h['includes'](n)),k=!!b&&!!f&&(b['version']!==f['version']||i['length']>0x0||j['length']>0x0);return{'name':a,'registered':b?{...b,'layers':[...b['layers']]}:null,'disk':f,'upgradable':k,'layer_diff':{'added':i,'removed':j}};}export function scanPacks(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']);try{const e=loadPackFromDir(d);if(!e)continue;b['push'](registerIndustryPack(e));}catch(f){b['push']({'ok':![],'errors':['failed\x20to\x20load\x20pack\x20\x27'+c['name']+'\x27:\x20'+f['message']],'registered':[]});}}return b;}function loadPackFromDir(a){const b=readMergedPackIfPresent(a),c=join(a,'manifest.json'),d=existsSync(c);if(!b&&!d)return null;if(b){const p=b['manifest'],q={'layout':'merged','manifest':p};if(b['mode'])q['mode']=b['mode'];if(b['match'])q['match']=b['match'];b['personae']&&Array['isArray'](b['personae'])&&(q['personae']=b['personae']);if(b['dispute'])q['dispute']=b['dispute'];if(b['compliance'])q['compliance']=b['compliance'];if(b['supply'])q['supply']=b['supply'];if(b['rules'])q['rules']=b['rules'];const r=join(a,'playbook.md');return existsSync(r)&&(q['playbook']={'category':p['name'],'content':readFileSync(r,'utf-8')}),q;}const e=JSON['parse'](readFileSync(c,'utf-8')),g={'layout':'legacy','manifest':e},h=join(a,'mode.json'),i=join(a,'match.json');existsSync(h)&&(g['mode']=JSON['parse'](readFileSync(h,'utf-8')));existsSync(i)&&(g['match']=JSON['parse'](readFileSync(i,'utf-8')));const j=join(a,'personae');if(existsSync(j)){const s=[];for(const t of readdirSync(j)){if(!t['endsWith']('.json'))continue;s['push'](JSON['parse'](readFileSync(join(j,t),'utf-8')));}if(s['length']>0x0)g['personae']=s;}const k=join(a,'dispute.json');existsSync(k)&&(g['dispute']=JSON['parse'](readFileSync(k,'utf-8')));const l=join(a,'compliance.json');existsSync(l)&&(g['compliance']=JSON['parse'](readFileSync(l,'utf-8')));const m=join(a,'supply.json');existsSync(m)&&(g['supply']=JSON['parse'](readFileSync(m,'utf-8')));const n=join(a,'rules.json');existsSync(n)&&(g['rules']=JSON['parse'](readFileSync(n,'utf-8')));const o=join(a,'playbook.md');return existsSync(o)&&(g['playbook']={'category':e['name'],'content':readFileSync(o,'utf-8')}),g;}export function rescanPack(a){const b=join(resolveIndustryPackDir(),a);try{const c=loadPackFromDir(b);if(!c)return{'ok':![],'errors':['no\x20pack\x20found\x20for\x20\x27'+a+'\x27'],'registered':[]};return registerIndustryPack(c,!![]);}catch(d){return{'ok':![],'errors':['failed\x20to\x20rescan\x20pack\x20\x27'+a+'\x27:\x20'+d['message']],'registered':[]};}}export function resolveIndustryPackDir(){return process['env']['WOWOK_INDUSTRY_DIR']||getWowokIndustryDir();}export function scanDefaultIndustryPacks(){return seedBuiltinIndustryTemplates(),ensureIndustryReadme(),ensureBuiltinModesAsPacks(),scanPacks(resolveIndustryPackDir());}export function seedBuiltinIndustryTemplates(a=SUPPORTED_INDUSTRIES){const b=[],c=resolveIndustryPackDir();mkdirSync(c,{'recursive':!![]}),ensureIndustryReadme();for(const d of a){const e=join(c,d);if(existsSync(join(e,'manifest.json'))||existsSync(join(e,'pack.json')))continue;const f=scaffoldIndustryPack(d,c);if(f['ok'])b['push'](d);}return b;}export const LAYER_FILE_SECTION={'match.json':'match','dispute.json':'dispute','compliance.json':'compliance','supply.json':'supply','rules.json':'rules','mode.json':'mode'};export const PERSONAE_DIR='personae';function manifestSection(a){return{'pack':'industry-pack','name':a,'display_name':a,'version':'0.1.0','layers':['match','personae','dispute','compliance','supply','rules','playbook']};}function matchSection(a){return{'category':a,'hard_constraints':[],'soft_weights':{},'highlight_fields':[],'calendar_mode':'none','geo_mode':'strict','pricing_rules':[]};}function personaPerRole(a,b){return{'role':a,'industry':b,'long_term':{'identity':{'self_description':b+'\x20'+a},'preferences':{}},'current':{'strategy':[],'requirements':[],'rules':[],'spec':'','preferences':{}}};}function disputeSection(a){return{'category':a,'sla_tiers':[],'fault_rules':[]};}function complianceSection(a){return{'category':a,'prepay_mode':'','qualification':[],'disclosure':[],'refund_window':{'days':0x7,'not_applicable':![]}};}function supplySection(a){return{'category':a,'supplier_qualification':[],'first_order_policy':'','redundancy_required':![]};}function rulesSection(a){return{'category':a,'rules':[]};}export function buildPristineMergedPack(a){const b=PERSONA_ROLES['map'](c=>personaPerRole(c,a));return{'manifest':manifestSection(a),'match':matchSection(a),'personae':b,'dispute':disputeSection(a),'compliance':complianceSection(a),'supply':supplySection(a),'rules':rulesSection(a),'mode':null};}export function industryReadmeContent(){return['#\x20WoWok\x20Industry\x20Packs','','>\x20This\x20folder\x20is\x20the\x20WoWok\x20industry\x20knowledge\x20root.\x20Each\x20sub-folder\x20is\x20one','>\x20industry\x20pack.\x20The\x20AI\x20reads\x20pack\x20data\x20as\x20context\x20on\x20every\x20chat\x20turn.','','##\x20Pack\x20structure\x20(unified\x20layout)','','Every\x20pack\x20is\x20exactly\x20two\x20files:','','-\x20**`<pack>/pack.json`**\x20—\x20machine-checkable\x20**settings\x20only**.\x20No\x20comments,','\x20\x20no\x20documentation.\x20One\x20section\x20per\x20layer\x20(see\x20below).','-\x20**`<pack>/playbook.md`**\x20—\x20human\x20strategy,\x20tone\x20and\x20field-tested\x20experience.','\x20\x20The\x20AI\x20reads\x20it\x20as\x20context\x20and\x20it\x20OVERRIDES\x20built-in\x20industry\x20data\x20for','\x20\x20this\x20account.','','All\x20field\x20explanations\x20live\x20in\x20THIS\x20file,\x20so\x20pack.json\x20stays\x20small\x20and\x20you','can\x20focus\x20on\x20configuration.\x20The\x20editor\x20also\x20validates\x20JSON\x20on\x20save\x20—\x20a\x20file','that\x20fails\x20to\x20parse\x20(or\x20a\x20pack.json\x20missing\x20its\x20manifest)\x20is\x20blocked.','','##\x20How\x20changes\x20take\x20effect','','1.\x20**Save**\x20in\x20the\x20Editor\x20writes\x20bytes\x20to\x20disk.','2.\x20**Scan**\x20(Industry\x20drawer)\x20re-registers\x20each\x20pack\x20into\x20the\x20runtime\x20AI','\x20\x20\x20registry\x20(and\x20SQLite\x20cache).\x20A\x20save\x20of\x20an\x20industry\x20file\x20already\x20runs','\x20\x20\x20Scan\x20automatically.','3.\x20**Next\x20AI\x20chat\x20turn**\x20the\x20L1\x20prompt\x20builder\x20reads\x20the\x20registered\x20layers,','\x20\x20\x20so\x20the\x20AI\x20reasons\x20against\x20your\x20edited\x20rules\x20from\x20that\x20point\x20onward.','','##\x20manifest\x20—\x20pack\x20metadata\x20+\x20layer\x20ENABLE\x20flags','','-\x20`name`:\x20snake_case\x20identifier,\x20must\x20match\x20the\x20folder\x20name.','-\x20`version`:\x20bump\x20after\x20editing\x20content\x20so\x20the\x20registry\x20treats\x20it\x20as\x20an\x20upgrade.','-\x20`display_name`:\x20user-visible\x20label.','-\x20`layers`:\x20which\x20sections\x20are\x20validated\x20and\x20registered\x20on\x20scan.\x20Remove\x20a','\x20\x20layer\x20name\x20to\x20DISABLE\x20it\x20(the\x20section\x20stays\x20in\x20pack.json\x20but\x20is\x20ignored).','','##\x20match\x20—\x20category-match\x20rules','','Decides\x20whether\x20an\x20order/service/account\x20belongs\x20to\x20this\x20industry\x20pack:','-\x20`hard_constraints`:\x20array\x20of\x20REQUIRED\x20predicates;\x20ALL\x20must\x20match\x20before\x20the','\x20\x20pack\x20is\x20considered.\x20Example:','\x20\x20`[{\x20key:\x20\x27order.metadata.service_kind\x27,\x20equals:\x20\x27food_onsite\x27\x20}]`','-\x20`soft_weights`:\x20dict\x20`<heuristic_key:\x20number\x200..1>`;\x20higher\x20=\x20stronger\x20signal.','-\x20`pricing_rules`:\x20pricing\x20modes\x20this\x20industry\x20requires.','-\x20`highlight_fields`:\x20dot-paths\x20surfaced\x20in\x20the\x20UI\x20as\x20important\x20info.','-\x20`geo_mode`:\x20`\x27strict\x27`\x20(region\x20must\x20match)\x20|\x20`\x27none\x27`\x20(ignore\x20region).','-\x20`calendar_mode`:\x20`\x27seasonal\x27`\x20|\x20`\x27weekday\x27`\x20|\x20`\x27none\x27`.','','##\x20personae\x20—\x20per-role\x20AI\x20personas','','One\x20persona\x20per\x20role\x20(`merchant`,\x20`customer`,\x20`supplier`,\x20`collaborator`,','`arbitrator`,\x20`prospect`).\x20The\x20AI\x20uses\x20them\x20to\x20role-play\x20negotiation\x20posture:','-\x20`long_term`:\x20stable\x20properties\x20—\x20`identity.self_description`\x20(free-text\x20bio),','\x20\x20`identity.region/languages`,\x20`preferences`\x20(`<key:\x20string[]>`).','-\x20`current`:\x20per-negotiation\x20posture\x20—\x20`strategy`\x20(moves\x20to\x20make),','\x20\x20`requirements`\x20(non-negotiable\x20demands),\x20`rules`\x20(constraints/axioms),','\x20\x20`spec`\x20(free-form\x20text),\x20`preferences`\x20(per-turn\x20overrides).','','##\x20dispute\x20—\x20SLA\x20tiers\x20+\x20fault\x20assignment','','-\x20`sla_tiers[]`:\x20response/remedy\x20windows\x20per\x20severity\x20level.','\x20\x20Example:\x20`{\x20level:\x20\x27L1\x27,\x20response_hours:\x2024,\x20remedy:\x20\x27reply\x27\x20}`','-\x20`fault_rules[]`:\x20automatic\x20fault\x20attribution\x20—\x20a\x20condition\x20plus\x20the\x20side','\x20\x20that\x20bears\x20fault\x20(`merchant`/`customer`/`supplier`/`operator`/`shared`).','\x20\x20Example:\x20`{\x20when:\x20{\x20evidence_has:\x20[\x27late\x20delivery\x20photo\x27]\x20},\x20assign_to:\x20\x27merchant\x27,\x20weight:\x201.0\x20}`','','##\x20compliance\x20—\x20hard\x20requirements\x20before\x20checkout','','-\x20`prepay_mode`:\x20`\x27\x27`\x20|\x20`\x27full\x27`\x20|\x20`\x27partial\x27`\x20|\x20`\x27deposit\x27`.','-\x20`qualification[]`:\x20licenses/certifications\x20a\x20merchant\x20must\x20hold.','\x20\x20Example:\x20`{\x20label:\x20\x27Food\x20Service\x20License\x27,\x20required:\x20true,\x20region:\x20\x27CN\x27\x20}`','-\x20`disclosure[]`:\x20text\x20the\x20merchant\x20MUST\x20show\x20buyers\x20up-front.','-\x20`refund_window`:\x20`{\x20days:\x20number,\x20not_applicable:\x20boolean,\x20exceptions:\x20[...]\x20}`','','##\x20supply\x20—\x20supply-chain\x20/\x20supplier\x20qualification','','-\x20`supplier_qualification[]`:\x20same\x20shape\x20as\x20compliance\x20qualifications,\x20but','\x20\x20evaluated\x20on\x20the\x20SUPPLIER\x20side\x20(multi-party\x20orders).','-\x20`first_order_policy`:\x20policy\x20string\x20on\x20the\x20first\x20order\x20from\x20a\x20new\x20supplier','\x20\x20(e.g.\x20`\x27sample-only\x27`,\x20`\x27reduced-quantity\x27`).','-\x20`redundancy_required`:\x20true\x20=\x20require\x20≥2\x20eligible\x20suppliers\x20before\x20accepting','\x20\x20an\x20order\x20(mitigates\x20single-sourcing).','','##\x20rules\x20—\x20declarative\x20machine-checked\x20rules','','Each\x20rule\x20is\x20an\x20AST\x20node\x20compiled\x20into\x20the\x20evaluation\x20engine:','`{\x20id:\x20\x27rule_...\x27,\x20when:\x20<bool-condition>,\x20then:\x20\x27reject\x27\x20|\x20\x27warn\x27\x20|\x20\x27flag\x27,\x20message:\x20\x27Text\x27\x20}`','Use\x20`rules`\x20for\x20rules\x20that\x20must\x20be\x20machine-checked;\x20put\x20human\x20strategy\x20in','`playbook.md`.','','##\x20mode\x20—\x20IndustryMode\x20(deep\x20shape)','','Not\x20scaffolded\x20by\x20default.\x20Add\x20it\x20when\x20you\x20need\x20a\x20full\x20driving\x20mode\x20for\x20the','industry,\x20or\x20ask\x20the\x20AI:\x20\x22help\x20me\x20fill\x20mode\x20for\x20<industry>\x22.','','Registered\x20into\x20`IndustryModeRegistry`\x20on\x20scan\x20(manifest\x20must\x20list\x20the','`mode`\x20layer).\x20A\x20pack\x20mode\x20with\x20the\x20same\x20name\x20as\x20a\x20builtin\x20replaces\x20it\x20when','the\x20pack\x20version\x20changes\x20or\x20on\x20a\x20forced\x20rescan.','','###\x20How\x20the\x20mode\x20is\x20consumed','','-\x20**Service\x20build\x20(priors)**:\x20`merchant_guide`\x20resolves\x20the\x20confirmed','\x20\x20industry\x20to\x20a\x20mode\x20(user\x20mode\x20first,\x20then\x20pack\x20mode,\x20then\x20builtin)\x20and','\x20\x20feeds\x20`machine_shape`\x20/\x20`guards`\x20/\x20`allocator`\x20/\x20`key_risk`\x20into\x20the','\x20\x20SemanticObjectGraph\x20build.','-\x20**Evaluation**:\x20the\x20metric\x20+\x20constraint\x20registries\x20score\x20the\x20mode','\x20\x20(risk/benefit\x200-100,\x20hard\x20violations\x20block\x20adoption).\x20Custom\x20metrics\x20and','\x20\x20constraints\x20registered\x20via\x20`industry_pack_operation`\x20participate\x20too.','-\x20**Recommendation**:\x20`recommend_industry`\x20matches\x20trait\x20similarity\x20and,','\x20\x20when\x20a\x20merchant\x20strategy\x20is\x20given,\x20re-ranks\x20by\x20lever\x20alignment\x20(70%','\x20\x20similarity\x20+\x2030%\x20alignment).','','###\x20Field\x20reference','','-\x20**Identity**:\x20`name`\x20(snake_case),\x20`display_name`,\x20`version`\x20(e.g.\x20`v1`),','\x20\x20`source`\x20(`builtin`\x20|\x20`custom`).','-\x20`traits`:\x2010-dimension\x20industry\x20trait\x20vector\x20(logistics,\x20cycle,\x20deposit,','\x20\x20regulatory\x20intensity,\x20...).\x20Drives\x20`recommend_industry`\x20similarity.','-\x20`machine_shape`:\x20Machine\x20node\x20topology\x20—\x20`[{\x20name,\x20role\x20}]`.\x20Node\x20names\x20are','\x20\x20business\x20states.\x20R-M1-11:\x20NEVER\x20model\x20refund/dispute\x20terminals','\x20\x20(`refunded`,\x20`disputed`,\x20`arb_*`)\x20as\x20nodes\x20—\x20disputes\x20flow\x20through','\x20\x20Service.arbitrations\x20independently;\x20route\x20refunds\x20via\x20the\x20Allocator','\x20\x20triggered\x20by\x20business\x20states\x20(`cancelled`,\x20`returned`).','-\x20`guards`:\x20`[{\x20template_id,\x20host,\x20purpose\x20}]`\x20—\x20guard\x20templates\x20to\x20attach.','\x20\x20`host`\x20is\x20one\x20of\x20`service`\x20|\x20`machine`\x20|\x20`reward`\x20|\x20`repository`\x20|','\x20\x20`arbitration`.','-\x20`allocator`:\x20`{\x20recipient,\x20count,\x20mode,\x20description\x20}`\x20—\x20fund\x20split.','\x20\x20`recipient`:\x20`signer`\x20|\x20`entity`;\x20`count`\x20>\x201\x20switches\x20to\x20multi-party','\x20\x20distribution;\x20`mode`:\x20`surplus`\x20|\x20`rate`\x20|\x20`milestone`.','-\x20`risk_checks`\x20/\x20`needs`:\x20buyer-side\x20due-diligence\x20entries\x20surfaced\x20in','\x20\x20prospect\x20evaluation.','-\x20`flywheel`:\x20acquisition\x20flywheel\x20—\x20`rewardStrategy`\x20/\x20`discountStrategy`','\x20\x20/\x20`trustSellingPoints`.\x20A\x20concrete\x20(non-`User-defined`)\x20strategy\x20turns','\x20\x20the\x20`reward`/`discount`\x20levers\x20on\x20for\x20strategy\x20alignment.','-\x20`key_risk`\x20(string)\x20/\x20`build_notes`\x20(string[]):\x20the\x20headline\x20risk\x20and','\x20\x20actionable\x20build\x20guidance\x20shown\x20to\x20the\x20merchant.','-\x20`capabilities_used`:\x20CapabilityCard\x20IDs\x20(e.g.\x20`guard.validate_buy`,','\x20\x20`machine.node_topology`,\x20`allocation.distribute_milestone`).\x20Powers\x20the','\x20\x20`buy_guard`\x20/\x20`machine_design`\x20levers\x20and\x20constraint\x20checks.','-\x20`config_overrides`:\x20per-object\x20field\x20defaults,\x20e.g.','\x20\x20`{\x20service:\x20{\x20engagement_type:\x20\x27milestone\x27\x20},\x20machine:\x20{\x20wip_required:\x20true\x20}\x20}`.','-\x20`config_override_rules`:\x20conditional\x20overrides\x20—','\x20\x20`{\x20object_type,\x20field_path,\x20value\x20|\x20{\x20intent_contains,\x20then_value,\x20else_value\x20}\x20}`.','-\x20`expected_benefits`:\x20`[{\x20metric,\x20expected_value,\x20evidence\x20}]`\x20—\x20what\x20the','\x20\x20mode\x20is\x20supposed\x20to\x20buy\x20you.','-\x20`risk_appetite`:\x20`conservative`\x20|\x20`balanced`\x20|\x20`aggressive`\x20(thresholds','\x20\x20for\x20the\x20risk/benefit\x20verdict).','-\x20`risk_constraints`:\x20`{\x20require_arbitration,\x20require_compensation_fund,','\x20\x20require_wip_evidence,\x20max_single_transaction?,','\x20\x20compensation_fund_coverage_ratio?,\x20other_constraints?\x20}`.\x20Coverage\x20ratio','\x20\x20multiplies\x20max\x20single\x20order\x20to\x20size\x20the\x20compensation\x20fund\x20(retail\x205,','\x20\x20rental\x2010,\x20subscription\x203;\x20default\x205).','-\x20`applicable_conditions`:\x20`{\x20business_scale,\x20min_daily_orders?,','\x20\x20other_conditions?\x20}`\x20—\x20when\x20the\x20mode\x20fits.','-\x20`similar_industries`\x20/\x20`novel_capabilities`:\x20migration\x20hints.','-\x20`disabled_builtin_constraints`:\x20builtin\x20constraint\x20IDs\x20this\x20mode','\x20\x20deliberately\x20opts\x20out\x20of\x20(e.g.\x20retail_d2c\x20skips\x20`require_arbitration`).','\x20\x20Custom\x20constraints\x20are\x20never\x20skipped.','','###\x20Persona\x20integration\x20(strategy\x20→\x20levers)','','The\x20personae\x20section\x27s\x20`current.strategy`\x20statements\x20are\x20bridged\x20into\x20mode','ranking\x20(value\x20intent\x20↔\x20game\x20path\x20unification).\x20Deterministic\x20mapping\x20—','\x22enumerable\x20→\x20MCP,\x20not\x20prompt\x22:','','-\x20`sales_priority`\x20(volume\x20first)\x20→\x20levers\x20`discount`\x20+\x20`reward`','-\x20`profit_priority`\x20(margin\x20first)\x20→\x20levers\x20`discount`\x20+\x20`machine_design`','-\x20`buyer_screening`\x20(qualify\x20buyers)\x20→\x20lever\x20`buy_guard`','-\x20`gross_margin_control`\x20(margin\x20band)\x20→\x20levers\x20`discount`\x20+\x20`machine_design`','','A\x20mode\x20supports\x20a\x20lever\x20when\x20its\x20data\x20says\x20so:\x20`guard.validate_buy`','capability\x20or\x20a\x20buy-guard\x20template\x20enables\x20`buy_guard`;\x20a\x20concrete','flywheel\x20reward/discount\x20strategy\x20enables\x20`reward`/`discount`;\x20a','non-empty\x20`machine_shape`\x20with\x20`machine.node_topology`\x20enables','`machine_design`.\x20Pass\x20strategy\x20text\x20to\x20`recommend_industry`\x20and\x20each','recommendation\x20reports\x20`strategy_alignment`\x20(matched/missing\x20levers).','','##\x20Reset','','Right-click\x20any\x20file/pack\x20folder\x20in\x20the\x20Industry\x20drawer\x20and\x20choose\x20*Reset*','to\x20restore\x20the\x20pristine\x20template\x20at\x20any\x20time.','']['join']('\x0a');}export function ensureIndustryReadme(){const a=resolveIndustryPackDir();mkdirSync(a,{'recursive':!![]});const b=join(a,'README.md');return writeFileSync(b,industryReadmeContent(),'utf-8'),b;}export function scaffoldIndustryPack(a,b){const c=join(b??resolveIndustryPackDir(),a),d=[],e=[];if(!/^[a-z][a-z0-9_]*$/['test'](a))return{'ok':![],'dir':c,'files':d,'errors':['industry\x20name\x20\x27'+a+'\x27\x20must\x20be\x20lowercase\x20snake_case\x20(a-z,\x200-9,\x20_)']};try{mkdirSync(c,{'recursive':!![]}),ensureIndustryReadme();const f=buildPristineMergedPack(a);return writeFileSync(join(c,'pack.json'),JSON['stringify'](f,null,0x2)+'\x0a'),d['push']('pack.json'),writeFileSync(join(c,'playbook.md'),playbookTemplate(a)),d['push']('playbook.md'),{'ok':!![],'dir':c,'files':d,'errors':e};}catch(g){return{'ok':![],'dir':c,'files':d,'errors':['scaffold\x20failed:\x20'+g['message']]};}}export function readMergedPackIfPresent(a){const b=join(a,'pack.json');if(!existsSync(b))return null;try{const c=readFileSync(b,'utf-8');return JSON['parse'](c);}catch{return null;}}function playbookTemplate(a){return['#\x20'+a+'\x20—\x20Industry\x20Playbook','','>\x20📘\x20This\x20file\x20captures\x20human\x20business\x20intelligence\x20for\x20the\x20`'+a+'`','>\x20industry.\x20Content\x20here\x20is\x20READ\x20BY\x20THE\x20AI\x20AS\x20CONTEXT\x20on\x20every\x20turn,','>\x20and\x20OVERRIDES\x20WoWok\x27s\x20generic\x20built-in\x20industry\x20data/rules\x20for\x20this','>\x20account.\x20The\x20companion\x20`pack.json`\x20file\x20stores\x20machine-checkable','>\x20rules;\x20THIS\x20file\x20stores\x20human\x20strategy,\x20tone,\x20experience,\x20and\x20ethics.','','>\x20💡\x20Hint\x20for\x20the\x20AI:\x20when\x20the\x20user\x20asks\x20a\x20question\x20about\x20\x22how\x20to','>\x20handle\x20'+a+'\x22\x20or\x20\x22what\x20should\x20I\x20do?\x22,\x20check\x20this\x20file\x20first\x20for\x20the','>\x20merchant/customer\x20voice,\x20then\x20fall\x20back\x20to\x20your\x20built-in\x20data.\x20Cite','>\x20section\x20titles\x20in\x20your\x20reply\x20so\x20the\x20user\x20knows\x20where\x20advice\x20comes\x20from.','','##\x20Experience\x20(Field-Tested\x20Rules\x20of\x20Thumb)','','>\x20Write\x20what\x20actually\x20works\x20in\x20this\x20industry\x20—\x20not\x20what\x20textbooks\x20say.','>\x20Short\x20bullet\x20points\x20preferred;\x20the\x20AI\x20reads\x20them\x20as\x20axioms.\x20Include','>\x20specific\x20numbers\x20when\x20you\x20have\x20them.','','-\x20(Example)\x20\x22Catering:\x20if\x20the\x20event\x20starts\x20before\x2010:00,\x20always\x20assume','\x20\x20the\x20customer\x20wants\x20breakfast\x20service\x20too\x20—\x20upsell\x20it\x20proactively.\x22','-\x20(Example)\x20\x22Common\x20pitfall:\x20last-minute\x20menu\x20swaps\x20on\x20Fridays\x20—\x20require','\x20\x20a\x20written\x20change\x20request\x2048\x20h\x20before\x20the\x20event\x20or\x20charge\x20a\x2015%\x20fee.\x22','-\x20(Add\x20more\x20below\x20—\x20delete\x20the\x20examples\x20above\x20when\x20you\x20have\x20real\x20ones.)','','##\x20Strategy\x20(Competitive\x20/\x20Game-Theory)','','>\x20How\x20should\x20each\x20role\x20act\x20in\x20a\x20negotiation\x20/\x20dispute\x20/\x20supplier','>\x20relationship?\x20Think\x20in\x20\x22always\x20/\x20never\x20/\x20depends-on-X\x22\x20rules,\x20and\x20call','>\x20out\x20the\x20trade-offs.','','-\x20Merchant\x20strategy:\x20(Add\x20how\x20a\x20merchant\x20in\x20this\x20industry\x20should\x20act\x20—','\x20\x20price\x20anchoring,\x20which\x20concessions\x20to\x20give\x20early\x20vs\x20late,\x20what\x20to','\x20\x20never\x20concede\x20on,\x20etc.)','-\x20Customer\x20strategy:\x20(Add\x20what\x20a\x20smart\x20customer\x20should\x20push\x20for.)','-\x20Dispute\x20strategy:\x20(When\x20to\x20settle\x20fast\x20vs\x20when\x20to\x20fight\x20for\x20full','\x20\x20evidence\x20+\x20arbitration.\x20Call\x20out\x20the\x20escalation\x20thresholds.)','','##\x20Personalization\x20(Tone,\x20Brand,\x20Ethics,\x20Red\x20Lines)','','-\x20Tone\x20/\x20voice:\x20(Write\x20one\x20sentence\x20describing\x20the\x20exact\x20conversational','\x20\x20voice\x20this\x20account\x20should\x20use\x20—\x20casual,\x20formal,\x20technical,\x20etc.)','-\x20Brand\x20rules:\x20(Logo,\x20link-out\x20style,\x20forbidden\x20terminology,','\x20\x20always-include\x20phrases,\x20etc.)','-\x20Red\x20lines:\x20(Non-negotiable.\x20Example:\x20\x22Never\x20make\x20a\x20refund\x20promise','\x20\x20larger\x20than\x2030%\x20without\x20arbitration\x20evidence.\x22)','-\x20Ethics:\x20(Example:\x20\x22If\x20customer\x20appears\x20intoxicated,\x20refuse\x20service','\x20\x20and\x20refer\x20to\x20supervisor;\x20never\x20take\x20the\x20order\x20for\x20profit.\x22)','','##\x20Playbook\x20Maintenance','','>\x20You\x20don\x27t\x20need\x20to\x20be\x20perfect\x20on\x20day\x20one.\x20After\x20every\x20real\x20deal,\x20add\x20a','>\x20bullet\x20to\x20the\x20above\x20sections\x20with\x20what\x20worked\x20/\x20what\x20failed.\x20Every','>\x20entry\x20improves\x20the\x20AI\x27s\x20future\x20decisions.','','>\x20Right-click\x20the\x20file\x20or\x20this\x20pack\x20folder\x20in\x20the\x20Industry\x20drawer\x20at','>\x20any\x20time\x20and\x20choose\x20\x22Reset\x22\x20to\x20restore\x20this\x20annotated\x20template.','']['join']('\x0a');}export function locatePackAndRemainder(a){const b=a['replace'](/^[\\/]+/,'')['replace'](/[\\/]+$/,'');if(!b)return null;const [c,...d]=b['split'](/[\\/]+/);if(!c)return null;return{'packName':c,'remainder':d['join']('/')};}export function resetIndustryPath(a,b){const c=[],d=[],f=b??resolveIndustryPackDir(),g=locatePackAndRemainder(a),h=a;if(!g)return{'ok':![],'layout':'merged','target':h,'restored_files':[],'errors':['invalid\x20reset\x20path\x20\x27'+a+'\x27']};const {packName:i,remainder:j}=g,k=join(f,i);if(!existsSync(k))return{'ok':![],'layout':'merged','target':h,'restored_files':[],'errors':['pack\x20directory\x20\x27'+i+'\x27\x20does\x20not\x20exist']};if(!/^[a-z][a-z0-9_]*$/['test'](i))return{'ok':![],'layout':'merged','target':h,'restored_files':[],'errors':['pack\x20name\x20\x27'+i+'\x27\x20is\x20not\x20a\x20valid\x20snake_case\x20identifier']};const l=readMergedPackIfPresent(k),n=l?'merged':'legacy';if(j==='')try{mkdirSync(k,{'recursive':!![]});const s=buildPristineMergedPack(i);return writeFileSync(join(k,'pack.json'),JSON['stringify'](s,null,0x2)+'\x0a'),d['push']('pack.json'),writeFileSync(join(k,'playbook.md'),playbookTemplate(i)),d['push']('playbook.md'),{'ok':!![],'layout':'merged','target':h,'restored_files':d,'errors':c};}catch(t){return{'ok':![],'layout':n,'target':h,'restored_files':d,'errors':['pack\x20reset\x20failed:\x20'+t['message']]};}const o=j['split']('/')['slice'](-0x1)[0x0],p=j==='playbook.md',q=j['startsWith'](PERSONAE_DIR+'/')&&o['endsWith']('.json');if(n==='merged'){if(p)try{return writeFileSync(join(k,'playbook.md'),playbookTemplate(i)),d['push']('playbook.md'),{'ok':!![],'layout':n,'target':h,'restored_files':d,'errors':c};}catch(v){return{'ok':![],'layout':n,'target':h,'restored_files':d,'errors':['playbook\x20reset\x20failed:\x20'+v['message']]};}const u=LAYER_FILE_SECTION[j];if(u)try{const w=readMergedPackIfPresent(k)??buildPristineMergedPack(i);switch(u){case'match':w['match']=matchSection(i);break;case'dispute':w['dispute']=disputeSection(i);break;case'compliance':w['compliance']=complianceSection(i);break;case'supply':w['supply']=supplySection(i);break;case'rules':w['rules']=rulesSection(i);break;case'mode':w['mode']=null;break;}return writeFileSync(join(k,'pack.json'),JSON['stringify'](w,null,0x2)+'\x0a'),d['push']('pack.json'),{'ok':!![],'layout':n,'target':h,'restored_files':d,'errors':c};}catch(x){return{'ok':![],'layout':n,'target':h,'restored_files':d,'errors':['section\x20reset\x20failed:\x20'+x['message']]};}if(q){const y=o['replace'](/\.json$/,'');if(!PERSONA_ROLES['includes'](y))return{'ok':![],'layout':n,'target':h,'restored_files':[],'errors':['unknown\x20persona\x20role\x20\x27'+y+'\x27']};try{const z=readMergedPackIfPresent(k)??buildPristineMergedPack(i),A=z['personae']&&Array['isArray'](z['personae'])?[...z['personae']]:[],B=A['findIndex'](D=>D['role']===y),C=personaPerRole(y,i);if(B>=0x0)A[B]=C;else A['push'](C);return z['personae']=A,writeFileSync(join(k,'pack.json'),JSON['stringify'](z,null,0x2)+'\x0a'),d['push']('pack.json'),{'ok':!![],'layout':n,'target':h,'restored_files':d,'errors':c};}catch(D){return{'ok':![],'layout':n,'target':h,'restored_files':d,'errors':['persona\x20reset\x20failed:\x20'+D['message']]};}}if(j==='manifest.json'||j==='manifest')try{const E=readMergedPackIfPresent(k)??buildPristineMergedPack(i);return E['manifest']=manifestSection(i),writeFileSync(join(k,'pack.json'),JSON['stringify'](E,null,0x2)+'\x0a'),d['push']('pack.json'),{'ok':!![],'layout':n,'target':h,'restored_files':d,'errors':c};}catch(F){return{'ok':![],'layout':n,'target':h,'restored_files':d,'errors':['manifest\x20reset\x20failed:\x20'+F['message']]};}return{'ok':![],'layout':n,'target':h,'restored_files':[],'errors':['path\x20\x27'+j+'\x27\x20is\x20not\x20a\x20standard\x20section\x20file\x20of\x20pack\x20\x27'+i+'\x27.\x20Reset\x20is\x20only\x20provided\x20for\x20pack.json\x20standard\x20sections\x20and\x20playbook.md.']};}if(p)try{return writeFileSync(join(k,'playbook.md'),playbookTemplate(i)),d['push']('playbook.md'),{'ok':!![],'layout':n,'target':h,'restored_files':d,'errors':c};}catch(G){return{'ok':![],'layout':n,'target':h,'restored_files':d,'errors':['legacy\x20playbook\x20reset\x20failed:\x20'+G['message']]};}if(j==='manifest.json')try{const H=manifestSection(i);return writeFileSync(join(k,'manifest.json'),JSON['stringify'](H,null,0x2)+'\x0a'),d['push']('manifest.json'),{'ok':!![],'layout':n,'target':h,'restored_files':d,'errors':c};}catch(I){return{'ok':![],'layout':n,'target':h,'restored_files':d,'errors':['legacy\x20manifest\x20reset\x20failed:\x20'+I['message']]};}const r=LAYER_FILE_SECTION[j];if(r)try{let J='';switch(r){case'match':J=JSON['stringify'](matchSection(i),null,0x2)+'\x0a';break;case'dispute':J=JSON['stringify'](disputeSection(i),null,0x2)+'\x0a';break;case'compliance':J=JSON['stringify'](complianceSection(i),null,0x2)+'\x0a';break;case'supply':J=JSON['stringify'](supplySection(i),null,0x2)+'\x0a';break;case'rules':J=JSON['stringify'](rulesSection(i),null,0x2)+'\x0a';break;case'mode':J=JSON['stringify']({},null,0x2)+'\x0a';break;}return writeFileSync(join(k,j),J),d['push'](j),{'ok':!![],'layout':n,'target':h,'restored_files':d,'errors':c};}catch(K){return{'ok':![],'layout':n,'target':h,'restored_files':d,'errors':['legacy\x20section\x20reset\x20failed:\x20'+K['message']]};}if(q){const L=o['replace'](/\.json$/,'');if(!PERSONA_ROLES['includes'](L))return{'ok':![],'layout':n,'target':h,'restored_files':[],'errors':['unknown\x20persona\x20\x27'+L+'\x27']};try{return writeFileSync(join(k,j),JSON['stringify'](personaPerRole(L,i),null,0x2)+'\x0a'),d['push'](j),{'ok':!![],'layout':n,'target':h,'restored_files':d,'errors':c};}catch(M){return{'ok':![],'layout':n,'target':h,'restored_files':d,'errors':['legacy\x20persona\x20reset\x20failed:\x20'+M['message']]};}}return{'ok':![],'layout':n,'target':h,'restored_files':[],'errors':['cannot\x20reset\x20non-standard\x20file\x20\x27'+j+'\x27\x20in\x20legacy\x20layout.\x20Only\x20standard\x20layer\x20files,\x20personae/*.json,\x20manifest.json,\x20and\x20playbook.md\x20can\x20be\x20reset.']};}
@@ -3,18 +3,20 @@ import type { CapabilityRegistry } from "./capability-manifest.js";
3
3
  export declare class MetricRegistry {
4
4
  private static instance;
5
5
  private metrics;
6
- private initialized;
6
+ private persistence;
7
+ private customMetricsLoaded;
7
8
  static Instance(): MetricRegistry;
8
9
  private constructor();
10
+ ensureLoaded(): Promise<void>;
9
11
  registerMetric(metric: BaseMetric): boolean;
10
- registerCustomMetric(metric_id: string, display_name: string, description: string, type: MetricType, scale: MetricScale, owner: string, weight?: number): boolean;
12
+ registerCustomMetric(metric_id: string, display_name: string, description: string, type: MetricType, scale: MetricScale, owner: string, weight?: number): Promise<boolean>;
11
13
  getMetric(metric_id: string): BaseMetric | undefined;
12
14
  listMetrics(filter?: {
13
15
  type?: MetricType;
14
16
  scope?: "builtin" | "custom";
15
17
  owner?: string;
16
- }): BaseMetric[];
17
- unregisterMetric(metric_id: string, owner: string): boolean;
18
+ }): Promise<BaseMetric[]>;
19
+ unregisterMetric(metric_id: string, owner: string): Promise<boolean>;
18
20
  evaluateMode(mode: IndustryMode, capabilityRegistry: CapabilityRegistry, extraMetrics?: BaseMetric[]): MetricEvaluation;
19
21
  private evaluateMetricGroup;
20
22
  private computeAverageScore;
@@ -1 +1 @@
1
- const BUILTIN_RISK_METRICS=[{'metric_id':'funds_risk','display_name':'Funds\x20Risk','description':'Directly\x20operates\x20funds\x20/\x20affects\x20fund\x20flow\x20/\x20no\x20fund\x20risk','type':'risk','scale':'level','weight':0x1,'scope':'builtin'},{'metric_id':'trust_risk','display_name':'Trust\x20Risk','description':'Degree\x20of\x20impact\x20on\x20trust\x20mechanism','type':'risk','scale':'level','weight':0x1,'scope':'builtin'},{'metric_id':'delivery_risk','display_name':'Delivery\x20Risk','description':'Degree\x20of\x20impact\x20on\x20order\x20fulfillment','type':'risk','scale':'level','weight':0x1,'scope':'builtin'},{'metric_id':'compliance_risk','display_name':'Compliance\x20Risk','description':'Degree\x20of\x20regulatory\x20involvement','type':'risk','scale':'level','weight':0x1,'scope':'builtin'}],BUILTIN_BENEFIT_METRICS=[{'metric_id':'automation_level','display_name':'Automation\x20Level','description':'Fully\x20automated\x20/\x20semi-automated\x20/\x20manual','type':'benefit','scale':'level','weight':0x1,'scope':'builtin'},{'metric_id':'trust_boost','display_name':'Trust\x20Boost','description':'Degree\x20of\x20enhancement\x20to\x20trust\x20mechanism','type':'benefit','scale':'level','weight':0x1,'scope':'builtin'},{'metric_id':'efficiency_gain','display_name':'Efficiency\x20Gain','description':'Degree\x20of\x20efficiency\x20improvement','type':'benefit','scale':'level','weight':0x1,'scope':'builtin'}];export class MetricRegistry{static ['instance'];['metrics']=new Map();['initialized']=![];static['Instance'](){return!MetricRegistry['instance']&&(MetricRegistry['instance']=new MetricRegistry()),MetricRegistry['instance'];}constructor(){this['registerBuiltinMetrics'](),this['initialized']=!![];}['registerMetric'](a){if(!a['metric_id']||!a['type']||!a['scale'])return![];if(this['metrics']['has'](a['metric_id']))return![];return this['metrics']['set'](a['metric_id'],a),!![];}['registerCustomMetric'](a,b,c,d,e,f,g){return this['registerMetric']({'metric_id':a,'display_name':b,'description':c,'type':d,'scale':e,'weight':g??0x1,'scope':'custom','owner':f});}['getMetric'](a){return this['metrics']['get'](a);}['listMetrics'](a){let b=Array['from'](this['metrics']['values']());if(!a)return b;if(a['type'])b=b['filter'](c=>c['type']===a['type']);if(a['scope'])b=b['filter'](c=>c['scope']===a['scope']);if(a['owner'])b=b['filter'](c=>c['owner']===a['owner']);return b;}['unregisterMetric'](a,b){const c=this['metrics']['get'](a);if(!c||c['scope']!=='custom'||c['owner']!==b)return![];return this['metrics']['delete'](a);}['evaluateMode'](a,b,c){const d=[...this['metrics']['values']()];if(c)for(const l of c){!d['some'](n=>n['metric_id']===l['metric_id'])&&d['push'](l);}const e=d['filter'](n=>n['type']==='risk'),f=d['filter'](n=>n['type']==='benefit'),g=[];for(const n of a['capabilities_used']){const o=b['getCard'](n);if(o)g['push'](o);}const h=this['evaluateMetricGroup'](g,e,'risk'),i=this['evaluateMetricGroup'](g,f,'benefit'),j=this['aggregateScore'](h),k=this['aggregateScore'](i);return{'risk_score':j,'benefit_score':k,'metric_details':[...h,...i]};}['evaluateMetricGroup'](a,b,c){const d=[];for(const e of b){const f=[];for(const h of a){const i=c==='risk'?h['risk_profile']:h['benefit_profile'];if(!i)continue;const j=i[e['metric_id']];j!==undefined&&f['push']({'value':j,'weight':0x1});}if(f['length']===0x0)continue;const g=this['computeAverageScore'](f,e['scale']);d['push']({'metric_id':e['metric_id'],'display_name':e['display_name'],'value':this['aggregateValue'](f,e['scale']),'normalized_score':g,'weight':e['weight']??0x1});}return d;}['computeAverageScore'](a,b){if(a['length']===0x0)return 0x0;if(b==='level'){const c={'high':0x64,'medium':0x3c,'low':0x1e};let d=0x0,e=0x0;for(const f of a){const g=c[String(f['value'])]??0x32;d+=g*f['weight'],e+=f['weight'];}return Math['round'](d/Math['max'](e,0x1));}if(b==='numeric'){let h=0x0,i=0x0;for(const j of a){const k=typeof j['value']==='number'?j['value']:0x32;h+=k*j['weight'],i+=j['weight'];}return Math['round'](h/Math['max'](i,0x1));}if(b==='percentage'){let l=0x0,m=0x0;for(const n of a){const o=typeof n['value']==='number'?n['value']:0x32;l+=o*n['weight'],m+=n['weight'];}return Math['round'](l/Math['max'](m,0x1));}return 0x0;}['aggregateValue'](a,b){if(b==='level'){const d={'high':0x0,'medium':0x0,'low':0x0};for(const f of a){const g=String(f['value']);if(d[g]!==undefined)d[g]++;}const e=Object['entries'](d)['sort']((h,i)=>i[0x1]-h[0x1])[0x0]?.[0x0];return e??'medium';}const c=a['reduce']((h,i)=>h+(typeof i['value']==='number'?i['value']:0x0),0x0);return Math['round'](c/a['length']);}['aggregateScore'](a){if(a['length']===0x0)return 0x0;let b=0x0,c=0x0;for(const e of a){b+=e['normalized_score']*e['weight'],c+=e['weight'];}return Math['round'](b/Math['max'](c,0x1));}['registerBuiltinMetrics'](){for(const a of BUILTIN_RISK_METRICS){this['registerMetric'](a);}for(const b of BUILTIN_BENEFIT_METRICS){this['registerMetric'](b);}}}export function getMetricRegistry(){return MetricRegistry['Instance']();}export const BUILTIN_METRICS_COUNT=BUILTIN_RISK_METRICS['length']+BUILTIN_BENEFIT_METRICS['length'];
1
+ import{OwnedRecordStorage}from'@wowok/wowok';const BUILTIN_RISK_METRICS=[{'metric_id':'funds_risk','display_name':'Funds\x20Risk','description':'Directly\x20operates\x20funds\x20/\x20affects\x20fund\x20flow\x20/\x20no\x20fund\x20risk','type':'risk','scale':'level','weight':0x1,'scope':'builtin'},{'metric_id':'trust_risk','display_name':'Trust\x20Risk','description':'Degree\x20of\x20impact\x20on\x20trust\x20mechanism','type':'risk','scale':'level','weight':0x1,'scope':'builtin'},{'metric_id':'delivery_risk','display_name':'Delivery\x20Risk','description':'Degree\x20of\x20impact\x20on\x20order\x20fulfillment','type':'risk','scale':'level','weight':0x1,'scope':'builtin'},{'metric_id':'compliance_risk','display_name':'Compliance\x20Risk','description':'Degree\x20of\x20regulatory\x20involvement','type':'risk','scale':'level','weight':0x1,'scope':'builtin'}],BUILTIN_BENEFIT_METRICS=[{'metric_id':'automation_level','display_name':'Automation\x20Level','description':'Fully\x20automated\x20/\x20semi-automated\x20/\x20manual','type':'benefit','scale':'level','weight':0x1,'scope':'builtin'},{'metric_id':'trust_boost','display_name':'Trust\x20Boost','description':'Degree\x20of\x20enhancement\x20to\x20trust\x20mechanism','type':'benefit','scale':'level','weight':0x1,'scope':'builtin'},{'metric_id':'efficiency_gain','display_name':'Efficiency\x20Gain','description':'Degree\x20of\x20efficiency\x20improvement','type':'benefit','scale':'level','weight':0x1,'scope':'builtin'}];export class MetricRegistry{static ['instance'];['metrics']=new Map();['persistence']=new OwnedRecordStorage('custom_metrics');['customMetricsLoaded']=![];static['Instance'](){return!MetricRegistry['instance']&&(MetricRegistry['instance']=new MetricRegistry()),MetricRegistry['instance'];}constructor(){this['registerBuiltinMetrics']();}async['ensureLoaded'](){if(this['customMetricsLoaded'])return;this['customMetricsLoaded']=!![];try{const a=await this['persistence']['list']();for(const b of a){try{const c=JSON['parse'](b['data']);c?.['metric_id']&&c['scope']==='custom'&&this['metrics']['set'](c['metric_id'],c);}catch{console['warn']('[MetricRegistry]\x20Skipping\x20corrupt\x20custom_metrics\x20row\x20\x27'+b['owner']+':'+b['name']+'\x27.');}}}catch(d){console['warn']('[MetricRegistry]\x20Failed\x20to\x20load\x20persisted\x20custom\x20metrics:',d['message']);}}['registerMetric'](a){if(!a['metric_id']||!a['type']||!a['scale'])return![];if(this['metrics']['has'](a['metric_id']))return![];return this['metrics']['set'](a['metric_id'],a),!![];}async['registerCustomMetric'](a,b,c,d,e,f,g){await this['ensureLoaded']();const h={'metric_id':a,'display_name':b,'description':c,'type':d,'scale':e,'weight':g??0x1,'scope':'custom','owner':f},i=this['registerMetric'](h);if(i)try{await this['persistence']['save'](f,a,JSON['stringify'](h));}catch(j){console['warn']('[MetricRegistry]\x20Failed\x20to\x20persist\x20custom\x20metric\x20\x27'+a+'\x27:',j['message']);}return i;}['getMetric'](a){return this['metrics']['get'](a);}async['listMetrics'](a){await this['ensureLoaded']();let b=Array['from'](this['metrics']['values']());if(!a)return b;if(a['type'])b=b['filter'](c=>c['type']===a['type']);if(a['scope'])b=b['filter'](c=>c['scope']===a['scope']);if(a['owner'])b=b['filter'](c=>c['owner']===a['owner']);return b;}async['unregisterMetric'](a,b){await this['ensureLoaded']();const c=this['metrics']['get'](a);if(!c||c['scope']!=='custom'||c['owner']!==b)return![];const d=this['metrics']['delete'](a);if(d)try{await this['persistence']['delete'](b,a);}catch(e){console['warn']('[MetricRegistry]\x20Failed\x20to\x20delete\x20persisted\x20custom\x20metric\x20\x27'+a+'\x27:',e['message']);}return d;}['evaluateMode'](a,b,c){const d=[...this['metrics']['values']()];if(c)for(const l of c){!d['some'](n=>n['metric_id']===l['metric_id'])&&d['push'](l);}const e=d['filter'](n=>n['type']==='risk'),f=d['filter'](n=>n['type']==='benefit'),g=[];for(const n of a['capabilities_used']){const o=b['getCard'](n);if(o)g['push'](o);}const h=this['evaluateMetricGroup'](g,e,'risk'),i=this['evaluateMetricGroup'](g,f,'benefit'),j=this['aggregateScore'](h),k=this['aggregateScore'](i);return{'risk_score':j,'benefit_score':k,'metric_details':[...h,...i]};}['evaluateMetricGroup'](a,b,c){const d=[];for(const e of b){const f=[];for(const h of a){const i=c==='risk'?h['risk_profile']:h['benefit_profile'];if(!i)continue;const j=i[e['metric_id']];j!==undefined&&f['push']({'value':j,'weight':0x1});}if(f['length']===0x0)continue;const g=this['computeAverageScore'](f,e['scale']);d['push']({'metric_id':e['metric_id'],'display_name':e['display_name'],'value':this['aggregateValue'](f,e['scale']),'normalized_score':g,'weight':e['weight']??0x1});}return d;}['computeAverageScore'](a,b){if(a['length']===0x0)return 0x0;if(b==='level'){const c={'high':0x64,'medium':0x3c,'low':0x1e};let d=0x0,e=0x0;for(const f of a){const g=c[String(f['value'])]??0x32;d+=g*f['weight'],e+=f['weight'];}return Math['round'](d/Math['max'](e,0x1));}if(b==='numeric'){let h=0x0,i=0x0;for(const j of a){const k=typeof j['value']==='number'?j['value']:0x32;h+=k*j['weight'],i+=j['weight'];}return Math['round'](h/Math['max'](i,0x1));}if(b==='percentage'){let l=0x0,m=0x0;for(const n of a){const o=typeof n['value']==='number'?n['value']:0x32;l+=o*n['weight'],m+=n['weight'];}return Math['round'](l/Math['max'](m,0x1));}return 0x0;}['aggregateValue'](a,b){if(b==='level'){const d={'high':0x0,'medium':0x0,'low':0x0};for(const f of a){const g=String(f['value']);if(d[g]!==undefined)d[g]++;}const e=Object['entries'](d)['sort']((h,i)=>i[0x1]-h[0x1])[0x0]?.[0x0];return e??'medium';}const c=a['reduce']((h,i)=>h+(typeof i['value']==='number'?i['value']:0x0),0x0);return Math['round'](c/a['length']);}['aggregateScore'](a){if(a['length']===0x0)return 0x0;let b=0x0,c=0x0;for(const e of a){b+=e['normalized_score']*e['weight'],c+=e['weight'];}return Math['round'](b/Math['max'](c,0x1));}['registerBuiltinMetrics'](){for(const a of BUILTIN_RISK_METRICS){this['registerMetric'](a);}for(const b of BUILTIN_BENEFIT_METRICS){this['registerMetric'](b);}}}export function getMetricRegistry(){return MetricRegistry['Instance']();}export const BUILTIN_METRICS_COUNT=BUILTIN_RISK_METRICS['length']+BUILTIN_BENEFIT_METRICS['length'];
@@ -1,4 +1,4 @@
1
- import type { IndustryMode, ModeEvaluation, ModeMigrationEvaluation, ProjectContext } from "./types.js";
1
+ import type { IndustryMode, ModeEvaluation } from "./types.js";
2
2
  import type { CapabilityRegistry } from "./capability-manifest.js";
3
3
  import { MetricRegistry } from "./metric-registry.js";
4
4
  import { ConstraintRegistry } from "./constraint-registry.js";
@@ -7,8 +7,7 @@ export declare class ModeEvaluator {
7
7
  private metricRegistry;
8
8
  private constraintRegistry;
9
9
  constructor(capabilityRegistry: CapabilityRegistry, metricRegistry?: MetricRegistry, constraintRegistry?: ConstraintRegistry);
10
- evaluateMode(mode: IndustryMode, _intent: string, _context: ProjectContext): ModeEvaluation;
11
- evaluateMigration(source: IndustryMode, target: IndustryMode): ModeMigrationEvaluation;
10
+ evaluateMode(mode: IndustryMode): ModeEvaluation;
12
11
  private isCustomMode;
13
12
  private checkCapabilityConflicts;
14
13
  private generateRecommendations;
@@ -1 +1 @@
1
- import{MetricRegistry}from'./metric-registry.js';import{ConstraintRegistry}from'./constraint-registry.js';export class ModeEvaluator{['capabilityRegistry'];['metricRegistry'];['constraintRegistry'];constructor(a,b,c){this['capabilityRegistry']=a,this['metricRegistry']=b??MetricRegistry['Instance'](),this['constraintRegistry']=c??ConstraintRegistry['Instance']();}['evaluateMode'](a,b,c){const d=this['checkCapabilityConflicts'](a),e=this['isCustomMode'](a)?a['custom_constraints']:undefined,f=this['constraintRegistry']['checkConstraints'](a,this['capabilityRegistry'],e),g=f['filter'](p=>p['severity']==='hard')['map'](p=>p['display_name']+':\x20'+p['violation']),h=f['filter'](p=>p['severity']==='soft')['map'](p=>p['display_name']+':\x20'+p['violation']),i=this['isCustomMode'](a)?a['custom_metrics']:undefined,j=this['metricRegistry']['evaluateMode'](a,this['capabilityRegistry'],i),k=j['risk_score'],l=j['benefit_score'],m=l/Math['max'](k,0x1),n=d['length']===0x0&&g['length']===0x0,o=this['generateRecommendations'](a,k,l,d,g,h);return{'applicable':n,'risk_score':k,'benefit_score':l,'risk_benefit_ratio':m,'capability_conflicts':d,'violated_constraints':g,'unmet_conditions':h,'recommendations':o};}['evaluateMigration'](a,b){const c=new Set(a['capabilities_used']),d=new Set(b['capabilities_used']),e=[],f=[],g=[];for(const s of d){if(!c['has'](s))e['push'](s);}for(const t of c){if(!d['has'](t))f['push'](t);}const h=this['checkCapabilityConflicts'](b);g['push'](...h);const i=this['metricRegistry']['evaluateMode'](a,this['capabilityRegistry']),j=this['metricRegistry']['evaluateMode'](b,this['capabilityRegistry']),k=i['risk_score'],l=j['risk_score'],m=i['benefit_score'],n=j['benefit_score'],o=l-k,p=n-m;let q=0x32;q+=p*0.5,q-=o*0.3,q-=g['length']*0xa,q-=e['length']*0x2,q=Math['max'](0x0,Math['min'](0x64,Math['round'](q)));const r=[];if(p>0x0)r['push']('Benefit\x20increased\x20by\x20'+p['toFixed'](0x1)+'\x20points,\x20migration\x20has\x20positive\x20value');else p<0x0&&r['push']('Benefit\x20decreased\x20by\x20'+Math['abs'](p)['toFixed'](0x1)+'\x20points,\x20need\x20to\x20evaluate\x20migration\x20necessity');if(o>0xa)r['push']('Risk\x20increased\x20by\x20'+o['toFixed'](0x1)+'\x20points,\x20recommend\x20strengthening\x20risk\x20control\x20measures');else o<-0xa&&r['push']('Risk\x20decreased\x20by\x20'+Math['abs'](o)['toFixed'](0x1)+'\x20points,\x20migration\x20helps\x20risk\x20management');e['length']>0x0&&r['push']('Added\x20'+e['length']+'\x20capabilities,\x20need\x20extra\x20configuration:\x20'+e['slice'](0x0,0x3)['join'](',\x20'));f['length']>0x0&&r['push']('Removed\x20'+f['length']+'\x20capabilities,\x20related\x20features\x20will\x20be\x20unavailable');g['length']>0x0&&r['push']('Detected\x20'+g['length']+'\x20capability\x20conflicts,\x20must\x20be\x20resolved\x20before\x20migration');if(q>=0x46)r['push']('Migration\x20feasibility\x20is\x20high,\x20recommend\x20executing');else q>=0x28?r['push']('Migration\x20feasibility\x20is\x20medium,\x20need\x20careful\x20evaluation'):r['push']('Migration\x20feasibility\x20is\x20low,\x20recommend\x20keeping\x20the\x20current\x20mode\x20or\x20finding\x20an\x20alternative');return{'feasibility_score':q,'source_risk_score':k,'target_risk_score':l,'source_benefit_score':m,'target_benefit_score':n,'risk_delta':o,'benefit_delta':p,'added_capabilities':e,'removed_capabilities':f,'conflicting_capabilities':g,'recommendations':r};}['isCustomMode'](a){return a['owner']!==undefined&&a['source']==='custom';}['checkCapabilityConflicts'](a){const b=[],c=a['capabilities_used'];for(const d of c){const e=this['capabilityRegistry']['getCard'](d);if(!e?.['constraints']?.['conflicts_with'])continue;for(const f of e['constraints']['conflicts_with']){c['includes'](f)&&b['push'](d+'\x20conflicts\x20with\x20'+f);}if(e['constraints']['must_pair_with'])for(const g of e['constraints']['must_pair_with']){!c['includes'](g)&&b['push'](d+'\x20requires\x20'+g+'\x20(must_pair_with\x20not\x20satisfied)');}}return b;}['generateRecommendations'](a,b,c,d,e,f){const g=[];d['length']>0x0&&g['push']('Detected\x20'+d['length']+'\x20capability\x20conflicts,\x20must\x20be\x20resolved\x20before\x20applying\x20the\x20mode');e['length']>0x0&&g['push']('Detected\x20'+e['length']+'\x20hard\x20constraint\x20violations,\x20need\x20to\x20supplement\x20missing\x20capabilities\x20or\x20adjust\x20mode\x20configuration');f['length']>0x0&&g['push']('Detected\x20'+f['length']+'\x20soft\x20constraints\x20not\x20met,\x20recommend\x20adjusting\x20to\x20improve\x20mode\x20quality');const h={'conservative':{'max_risk':0x1e,'min_benefit':0x32},'balanced':{'max_risk':0x3c,'min_benefit':0x3c},'aggressive':{'max_risk':0x64,'min_benefit':0x50}},i=h[a['risk_appetite']];return b>i['max_risk']&&g['push']('Risk\x20score\x20'+b+'\x20exceeds\x20'+a['risk_appetite']+'\x20mode\x20threshold\x20'+i['max_risk']+',\x20recommend\x20reducing\x20risk\x20or\x20adjusting\x20risk\x20appetite'),c<i['min_benefit']&&g['push']('Benefit\x20score\x20'+c+'\x20below\x20'+a['risk_appetite']+'\x20mode\x20threshold\x20'+i['min_benefit']+',\x20recommend\x20adding\x20benefit\x20capabilities\x20or\x20adjusting\x20risk\x20appetite'),g['length']===0x0&&g['push']('Mode\x20evaluation\x20passed:\x20risk\x20'+b+'\x20/\x20benefit\x20'+c+'\x20/\x20risk-benefit\x20ratio\x20'+(c/Math['max'](b,0x1))['toFixed'](0x2)),g;}}
1
+ import{MetricRegistry}from'./metric-registry.js';import{ConstraintRegistry}from'./constraint-registry.js';export class ModeEvaluator{['capabilityRegistry'];['metricRegistry'];['constraintRegistry'];constructor(a,b,c){this['capabilityRegistry']=a,this['metricRegistry']=b??MetricRegistry['Instance'](),this['constraintRegistry']=c??ConstraintRegistry['Instance']();}['evaluateMode'](a){const b=this['checkCapabilityConflicts'](a),c=this['isCustomMode'](a)?a['custom_constraints']:undefined,d=this['constraintRegistry']['checkConstraints'](a,this['capabilityRegistry'],c),e=d['filter'](n=>n['severity']==='hard')['map'](n=>n['display_name']+':\x20'+n['violation']),f=d['filter'](n=>n['severity']==='soft')['map'](n=>n['display_name']+':\x20'+n['violation']),g=this['isCustomMode'](a)?a['custom_metrics']:undefined,h=this['metricRegistry']['evaluateMode'](a,this['capabilityRegistry'],g),i=h['risk_score'],j=h['benefit_score'],k=j/Math['max'](i,0x1),l=b['length']===0x0&&e['length']===0x0,m=this['generateRecommendations'](a,i,j,b,e,f);return{'applicable':l,'risk_score':i,'benefit_score':j,'risk_benefit_ratio':k,'capability_conflicts':b,'violated_constraints':e,'unmet_conditions':f,'recommendations':m};}['isCustomMode'](a){return a['owner']!==undefined&&a['source']==='custom';}['checkCapabilityConflicts'](a){const b=[],c=a['capabilities_used'];for(const d of c){const e=this['capabilityRegistry']['getCard'](d);if(!e?.['constraints']?.['conflicts_with'])continue;for(const f of e['constraints']['conflicts_with']){c['includes'](f)&&b['push'](d+'\x20conflicts\x20with\x20'+f);}if(e['constraints']['must_pair_with'])for(const g of e['constraints']['must_pair_with']){!c['includes'](g)&&b['push'](d+'\x20requires\x20'+g+'\x20(must_pair_with\x20not\x20satisfied)');}}return b;}['generateRecommendations'](a,b,c,d,e,f){const g=[];d['length']>0x0&&g['push']('Detected\x20'+d['length']+'\x20capability\x20conflicts,\x20must\x20be\x20resolved\x20before\x20applying\x20the\x20mode');e['length']>0x0&&g['push']('Detected\x20'+e['length']+'\x20hard\x20constraint\x20violations,\x20need\x20to\x20supplement\x20missing\x20capabilities\x20or\x20adjust\x20mode\x20configuration');f['length']>0x0&&g['push']('Detected\x20'+f['length']+'\x20soft\x20constraints\x20not\x20met,\x20recommend\x20adjusting\x20to\x20improve\x20mode\x20quality');const h={'conservative':{'max_risk':0x1e,'min_benefit':0x32},'balanced':{'max_risk':0x3c,'min_benefit':0x3c},'aggressive':{'max_risk':0x64,'min_benefit':0x50}},i=h[a['risk_appetite']];return b>i['max_risk']&&g['push']('Risk\x20score\x20'+b+'\x20exceeds\x20'+a['risk_appetite']+'\x20mode\x20threshold\x20'+i['max_risk']+',\x20recommend\x20reducing\x20risk\x20or\x20adjusting\x20risk\x20appetite'),c<i['min_benefit']&&g['push']('Benefit\x20score\x20'+c+'\x20below\x20'+a['risk_appetite']+'\x20mode\x20threshold\x20'+i['min_benefit']+',\x20recommend\x20adding\x20benefit\x20capabilities\x20or\x20adjusting\x20risk\x20appetite'),g['length']===0x0&&g['push']('Mode\x20evaluation\x20passed:\x20risk\x20'+b+'\x20/\x20benefit\x20'+c+'\x20/\x20risk-benefit\x20ratio\x20'+(c/Math['max'](b,0x1))['toFixed'](0x2)),g;}}
@@ -1,4 +1,4 @@
1
- import type { IndustryMode, UserDefinedMode, Blueprint, BlueprintObject, BlueprintEdge, ProjectContext, ModeEvaluation, ModeMigrationEvaluation } from "./types.js";
1
+ import type { IndustryMode, UserDefinedMode, ModeEvaluation } from "./types.js";
2
2
  export declare class IndustryModeRegistry {
3
3
  private static instance;
4
4
  private registrations;
@@ -16,8 +16,7 @@ export declare class IndustryModeRegistry {
16
16
  resolveAlias(name: string): string;
17
17
  hasMode(name: string): boolean;
18
18
  unregisterMode(name: string): boolean;
19
- evaluateMode(name: string, intent: string, context: ProjectContext): ModeEvaluation;
20
- evaluateMigration(sourceName: string, targetName: string): ModeMigrationEvaluation;
19
+ evaluateModeObject(mode: IndustryMode): Promise<ModeEvaluation>;
21
20
  registerUserMode(mode: UserDefinedMode, userId: string): Promise<boolean>;
22
21
  deriveMode(sourceMode: string, modifications: Partial<UserDefinedMode>, userId: string, newName: string, newDisplayName?: string): Promise<UserDefinedMode | undefined>;
23
22
  evolveMode(modeName: string, updates: Partial<UserDefinedMode>, userId: string, changeDescription: string, bumpVersion?: boolean): Promise<UserDefinedMode | undefined>;
@@ -29,28 +28,7 @@ export declare class IndustryModeRegistry {
29
28
  private persistUserMode;
30
29
  private unpersistUserMode;
31
30
  private bumpPatchVersion;
32
- applyTemplate(name: string, intent: string, context: ProjectContext): Promise<Blueprint>;
33
- applyUserMode(modeName: string, userId: string, intent: string, context: ProjectContext): Promise<Blueprint>;
34
- private doApplyTemplate;
35
- validateBlueprint(objects: BlueprintObject[], edges: BlueprintEdge[], mode: IndustryMode): {
36
- errors: string[];
37
- warnings: string[];
38
- };
39
- private buildObjects;
40
- private buildPermissionIndexes;
41
- private applyConfigOverrides;
42
- private applyConfigOverrideRules;
43
- private evaluateCondition;
44
- private setNestedField;
45
- private buildEdges;
46
- private makeEdge;
47
- private buildSteps;
48
- private defaultScenarios;
49
- private recordCapabilitiesUsed;
50
- private deriveGuardShortName;
51
- private getFirstServiceGuardName;
52
- private makeObject;
53
31
  private registerBuiltinModes;
54
32
  }
55
33
  export declare function getIndustryModeRegistry(): IndustryModeRegistry;
56
- export declare const INDUSTRY_MODE_REGISTRY_VERSION = 2.2;
34
+ export declare const INDUSTRY_MODE_REGISTRY_VERSION = 2.3;
@@ -1 +1 @@
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;
1
+ import{OwnedRecordStorage}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 OwnedRecordStorage('user_modes');['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!![];}async['evaluateModeObject'](a){return await Promise['all']([MetricRegistry['Instance']()['ensureLoaded'](),ConstraintRegistry['Instance']()['ensureLoaded']()]),this['evaluator']['evaluateMode'](a);}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']('.');}['registerBuiltinModes'](){for(const a of BUILTIN_MODES){this['registerMode'](a);}}}export function getIndustryModeRegistry(){return IndustryModeRegistry['Instance']();}export const INDUSTRY_MODE_REGISTRY_VERSION=2.3;
@@ -1,62 +1,9 @@
1
- import type { ProjectObjectType } from "../project/namespace.js";
1
+ import type { ProjectObjectType } from "../playbooks/service-build/namespace.js";
2
2
  import type { IndustryTraits, IndustrySource } from "../knowledge/industry-registry.js";
3
3
  import type { AcquisitionFlywheel } from "../knowledge/acquisition-flywheel.js";
4
4
  import type { IndustryRiskCheck, IndustryNeed } from "../customer/industry-risks.js";
5
5
  import type { ModeMachineNode, ModeGuardRef, ModeAllocatorStrategy } from "../knowledge/scenario-modes.js";
6
6
  export type { ProjectObjectType, IndustryTraits, IndustrySource, AcquisitionFlywheel, IndustryRiskCheck, IndustryNeed, ModeMachineNode, ModeGuardRef, ModeAllocatorStrategy, };
7
- export interface ProjectContext {
8
- project_id?: string;
9
- prefix: string;
10
- network: "testnet" | "mainnet" | "both";
11
- business_intent?: string;
12
- version?: string;
13
- testnet_test_passed?: boolean;
14
- industry?: string;
15
- }
16
- export interface Blueprint {
17
- context: ProjectContext;
18
- objects: BlueprintObject[];
19
- edges: BlueprintEdge[];
20
- steps: BlueprintStep[];
21
- scenarios?: BlueprintScenario[];
22
- industry_source: string;
23
- applied_template: string;
24
- validation?: {
25
- errors: string[];
26
- warnings: string[];
27
- };
28
- }
29
- export interface BlueprintObject {
30
- entry_id: string;
31
- object_type: ProjectObjectType;
32
- name: string;
33
- config: Record<string, unknown>;
34
- publish_required: boolean;
35
- status: "draft" | "deployed";
36
- description?: string;
37
- }
38
- export interface BlueprintEdge {
39
- from: string;
40
- to: string;
41
- edge_kind: string;
42
- field_path: string;
43
- required_at_publish: boolean;
44
- }
45
- export interface BlueprintStep {
46
- step: number;
47
- object_type: ProjectObjectType;
48
- operation: "create" | "publish";
49
- substep_count: number;
50
- depends_on: number[];
51
- entry_id: string;
52
- network_phase: "testnet" | "mainnet" | "both";
53
- }
54
- export interface BlueprintScenario {
55
- scenario_id: string;
56
- description: string;
57
- primary_object: string;
58
- supporting_objects: string[];
59
- }
60
7
  export type RiskAppetite = "conservative" | "balanced" | "aggressive";
61
8
  export interface ExpectedBenefit {
62
9
  metric: string;
@@ -131,8 +78,6 @@ export interface IndustryModeRegistration {
131
78
  enabled: boolean;
132
79
  registered_at: number;
133
80
  }
134
- export type DeriveModeOptions = Partial<UserDefinedMode>;
135
- export type EvolveModeOptions = Partial<UserDefinedMode>;
136
81
  export type MetricType = "risk" | "benefit";
137
82
  export type MetricScale = "level" | "numeric" | "percentage";
138
83
  export type MetricValue = string | number;
@@ -205,16 +150,3 @@ export interface ModeEvaluation {
205
150
  unmet_conditions: string[];
206
151
  recommendations: string[];
207
152
  }
208
- export interface ModeMigrationEvaluation {
209
- feasibility_score: number;
210
- source_risk_score: number;
211
- target_risk_score: number;
212
- source_benefit_score: number;
213
- target_benefit_score: number;
214
- risk_delta: number;
215
- benefit_delta: number;
216
- added_capabilities: string[];
217
- removed_capabilities: string[];
218
- conflicting_capabilities: string[];
219
- recommendations: string[];
220
- }
@@ -0,0 +1,17 @@
1
+ import { GOAL_TYPES, type GoalType } from "./types.js";
2
+ export interface GoalClassification {
3
+ goal_type: GoalType | null;
4
+ confidence: number;
5
+ matched: string[];
6
+ alternatives: {
7
+ goal_type: GoalType;
8
+ score: number;
9
+ }[];
10
+ }
11
+ interface GoalKeywordRule {
12
+ goal_type: GoalType;
13
+ keywords: string[];
14
+ }
15
+ export declare const GOAL_KEYWORD_RULES: readonly GoalKeywordRule[];
16
+ export declare function classifyGoal(intentText: string): GoalClassification;
17
+ export { GOAL_TYPES };
@@ -0,0 +1 @@
1
+ import{GOAL_TYPES}from'./types.js';export const GOAL_KEYWORD_RULES=[{'goal_type':'publish_service','keywords':['发布服务','开店','上线服务','开个店','开个点','出售服务','上架','publish\x20service','launch\x20service','open\x20store','open\x20a\x20store','open\x20shop','sell\x20service']},{'goal_type':'fulfill_order','keywords':['履约','交付订单','新订单','推进订单','处理订单','订单交付','fulfill','fulfil','deliver\x20order','new\x20order','process\x20order']},{'goal_type':'capture_demand','keywords':['需求机会','接单','有什么需求','找需求','需求匹配','capture\x20demand','opportunities','opportunity','demands\x20available','what\x20demands']},{'goal_type':'purchase_service','keywords':['购买服务','帮我买','帮我找','定制','下单','买个','buy','purchase','order\x20a\x20service','customize','custom-made']},{'goal_type':'collaborate_flow','keywords':['待办','我的节点','协作','员工','工作任务','my\x20tasks','pending\x20nodes','collaborate','my\x20node','todo']},{'goal_type':'supply_suborder','keywords':['子订单','应征','供应商','供货','sub-order','suborder','supplier','present']},{'goal_type':'publish_demand','keywords':['发布需求','找人做','悬赏','求人','publish\x20demand','post\x20demand','bounty','looking\x20for\x20someone']},{'goal_type':'run_arbitration','keywords':['仲裁业务','仲裁服务','经营仲裁','仲裁经营','arbitration\x20business','arbitrator','arbitration\x20service']},{'goal_type':'dispute_resolution','keywords':['争议','纠纷','投诉','申诉','维权','dispute','complaint','appeal']},{'goal_type':'manage_assets','keywords':['资产','资金','数据管理','盘点','权限盘点','treasury','assets','manage\x20funds','asset','inventory']}];const ASCII_RE=/^[\x20-\x7e]+$/;function keywordWeight(a){return a['length']>=0x4?0x2:0x1;}function escapeRe(a){return a['replace'](/[.*+?^${}()|[\]\\]/g,'\x5c$&');}const boundaryCache=new Map();function keywordMatches(a,b){if(ASCII_RE['test'](a)){let c=boundaryCache['get'](a);return!c&&(c=new RegExp('\x5cb'+escapeRe(a)+'\x5cb','i'),boundaryCache['set'](a,c)),c['test'](b);}return b['includes'](a);}export function classifyGoal(a){const b=(a??'')['trim']()['toLowerCase'](),c={'goal_type':null,'confidence':0x0,'matched':[],'alternatives':[]};if(!b)return c;const d=[];for(const k of GOAL_KEYWORD_RULES){const l=[];let m=0x0;for(const n of k['keywords']){keywordMatches(n,b)&&(l['push'](n),m+=keywordWeight(n));}if(m>0x0)d['push']({'goal_type':k['goal_type'],'score':m,'matched':l});}if(d['length']===0x0)return c;let e=d[0x0];for(const o of d){if(o['score']>e['score'])e=o;}const f=d['reduce']((p,q)=>p+q['score'],0x0),g=e['score']/f,h=Math['min'](0x1,e['score']/0x3),i=Math['round'](g*h*0x3e8)/0x3e8,j=d['filter'](p=>p['goal_type']!==e['goal_type'])['sort']((p,q)=>q['score']-p['score'])['map'](({goal_type:p,score:q})=>({'goal_type':p,'score':q}));return{'goal_type':e['goal_type'],'confidence':i,'matched':e['matched'],'alternatives':j};}export{GOAL_TYPES};