@wowok/agent-mcp 3.2.1 → 3.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (97) hide show
  1. package/dist/communication/wts-attestation.d.ts +34 -0
  2. package/dist/communication/wts-attestation.js +1 -0
  3. package/dist/config/judgment.d.ts +25 -0
  4. package/dist/config/rule-engine.d.ts +10 -0
  5. package/dist/config/rule-engine.js +1 -1
  6. package/dist/evaluation/builtins/graph-service.spec.js +1 -1
  7. package/dist/evaluation/engine.js +1 -1
  8. package/dist/experience/realtime-feedback.js +1 -1
  9. package/dist/extensions/industry-pack.js +1 -1
  10. package/dist/graph/onchain/expand.js +1 -1
  11. package/dist/graph/onchain/exposure.js +1 -1
  12. package/dist/knowledge/allocation-risk.d.ts +2 -1
  13. package/dist/knowledge/allocation-risk.js +1 -1
  14. package/dist/knowledge/allocation-templates.js +1 -1
  15. package/dist/knowledge/audit-rules.js +1 -1
  16. package/dist/knowledge/baselines/rules/allocation.json +31 -1
  17. package/dist/knowledge/builtin-templates.d.ts +3 -1
  18. package/dist/knowledge/builtin-templates.js +1 -1
  19. package/dist/knowledge/entity-recipient-guard.d.ts +21 -0
  20. package/dist/knowledge/entity-recipient-guard.js +1 -0
  21. package/dist/knowledge/getting-started.js +1 -1
  22. package/dist/knowledge/guard-templates.js +1 -1
  23. package/dist/knowledge/index.js +1 -1
  24. package/dist/knowledge/industry-registry.js +1 -1
  25. package/dist/knowledge/jsonrpc-enum.js +1 -1
  26. package/dist/knowledge/machine-topology.d.ts +34 -0
  27. package/dist/knowledge/machine-topology.js +1 -1
  28. package/dist/knowledge/scenario-modes.d.ts +1 -0
  29. package/dist/knowledge/scenario-modes.js +1 -1
  30. package/dist/knowledge/strategy-manuals.js +1 -1
  31. package/dist/knowledge/template-loader.d.ts +21 -0
  32. package/dist/knowledge/template-loader.js +1 -1
  33. package/dist/knowledge/template-registry.js +1 -1
  34. package/dist/knowledge/template-scanner.js +1 -1
  35. package/dist/knowledge/tool-constraints.js +1 -1
  36. package/dist/knowledge/tools-reference.js +1 -1
  37. package/dist/knowledge/workflow-guidance.d.ts +4 -0
  38. package/dist/knowledge/workflow-guidance.js +1 -1
  39. package/dist/monitor/MonitorLoop.js +1 -1
  40. package/dist/playbooks/service-build/business-puzzle.js +1 -1
  41. package/dist/playbooks/service-build/index.d.ts +1 -0
  42. package/dist/playbooks/service-build/intent-analyzer.d.ts +1 -0
  43. package/dist/playbooks/service-build/intent-analyzer.js +1 -1
  44. package/dist/playbooks/service-build/machine-nodes.d.ts +1 -1
  45. package/dist/playbooks/service-build/machine-nodes.js +1 -1
  46. package/dist/playbooks/service-build/machine-panorama.js +1 -1
  47. package/dist/playbooks/service-build/object-panorama.d.ts +27 -1
  48. package/dist/playbooks/service-build/object-panorama.js +1 -1
  49. package/dist/playbooks/service-build/participation-radar.js +1 -1
  50. package/dist/playbooks/service-build/pipeline-actions.d.ts +4 -0
  51. package/dist/playbooks/service-build/pipeline-actions.js +1 -1
  52. package/dist/playbooks/service-build/relationship-profile.js +1 -1
  53. package/dist/playbooks/service-build/semantic-graph.d.ts +1 -0
  54. package/dist/playbooks/service-build/semantic-graph.js +1 -1
  55. package/dist/playbooks/service-build/service-panorama.js +1 -1
  56. package/dist/playbooks/service-build/service-quote.js +1 -1
  57. package/dist/review/index.js +1 -1
  58. package/dist/safety/confirm-gate.js +1 -1
  59. package/dist/schema/call/machine.d.ts +1 -0
  60. package/dist/schema/call/machine.js +1 -1
  61. package/dist/schema/call/semantic.js +1 -1
  62. package/dist/schema/call/service.js +1 -1
  63. package/dist/schema/common/index.js +1 -1
  64. package/dist/schema/goal/planning.d.ts +7 -0
  65. package/dist/schema/goal/planning.js +1 -1
  66. package/dist/schema/industry-pack/index.d.ts +24 -0
  67. package/dist/schema/industry-pack/index.js +1 -1
  68. package/dist/schema/local/index.js +1 -1
  69. package/dist/schema/messenger/index.d.ts +20 -0
  70. package/dist/schema/messenger/index.js +1 -1
  71. package/dist/schema/operations.d.ts +2 -0
  72. package/dist/schema/persona/index.d.ts +110 -0
  73. package/dist/schema/query/bi.d.ts +2 -0
  74. package/dist/schema/query/bi.js +1 -1
  75. package/dist/schema/schema-version.js +1 -1
  76. package/dist/schema/utils/node-parser.js +1 -1
  77. package/dist/schema-query-impl/index.js +1 -1
  78. package/dist/schemas/index.json +1 -1
  79. package/dist/schemas/industry_pack_operation.output.json +109 -0
  80. package/dist/schemas/industry_pack_operation.schema.json +3 -1
  81. package/dist/schemas/messenger_operation.output.json +42 -4
  82. package/dist/schemas/onchain_operations.schema.json +5 -5
  83. package/dist/schemas/onchain_operations_machine.schema.json +2 -2
  84. package/dist/schemas/onchain_operations_service.schema.json +3 -3
  85. package/dist/schemas/onchain_table_data.output.json +5 -1
  86. package/dist/schemas/persona_operation.output.json +266 -0
  87. package/dist/schemas/persona_operation.schema.json +42 -0
  88. package/dist/schemas/query_toolkit.output.json +1 -1
  89. package/dist/schemas/query_toolkit.schema.json +5 -1
  90. package/dist/tools/handlers/benchmark-migration.d.ts +17 -0
  91. package/dist/tools/handlers/benchmark-migration.js +1 -1
  92. package/dist/tools/handlers/config.js +1 -1
  93. package/dist/tools/handlers/industry-pack.js +1 -1
  94. package/dist/tools/handlers/messenger.js +1 -1
  95. package/dist/tools/handlers/onchain.js +1 -1
  96. package/dist/tools/registry/business.js +1 -1
  97. package/package.json +4 -3
@@ -9168,6 +9168,10 @@
9168
9168
  "description": "DEPRECATED alias of object_address (accepted for call compatibility; must be a plain address or LocalMark NAME string, not an object). Prefer object_address. Example: {\"query_type\": \"object_panorama\", \"object_address\": \"0xabc...\"}.",
9169
9169
  "type": "string"
9170
9170
  },
9171
+ "wts_file_path": {
9172
+ "description": "Proof objects only: local path to the .wts evidence packet to cross-check against this anchor. Returns wts_anchor_check — whether the packet's message roots match the frozen root, whether the server key matches, and whether the Proof predates the packet (a frozen Proof is what makes WTS content non-re-fabricable after the fact).",
9173
+ "type": "string"
9174
+ },
9171
9175
  "context_network": {
9172
9176
  "type": "string",
9173
9177
  "enum": [
@@ -9182,7 +9186,7 @@
9182
9186
  "query_type"
9183
9187
  ],
9184
9188
  "additionalProperties": false,
9185
- "description": "ONE-CALL detail-page panorama for Progress / Demand / Order / Arb / Repository objects (client panorama family): discriminated `object_type` + head (name/tags/description) + the object's own typed fields + type-specific extras (Demand presenters from the GLOBAL tx table, Progress session/forwards, Arb votes & propositions, Repository policies). Read-only."
9189
+ "description": "ONE-CALL detail-page panorama for Progress / Demand / Order / Arb / Repository / Proof objects (client panorama family): discriminated `object_type` + head (name/tags/description) + the object's own typed fields + type-specific extras (Demand presenters from the GLOBAL tx table, Progress session/forwards, Arb votes & propositions, Repository policies, Proof anchored root + WTS cross-check). Read-only."
9186
9190
  },
9187
9191
  {
9188
9192
  "type": "object",
@@ -2861,6 +2861,20 @@
2861
2861
  ],
2862
2862
  "additionalProperties": false
2863
2863
  }
2864
+ },
2865
+ "severity_overrides": {
2866
+ "type": "object",
2867
+ "propertyNames": {
2868
+ "type": "string"
2869
+ },
2870
+ "additionalProperties": {
2871
+ "type": "string",
2872
+ "enum": [
2873
+ "error",
2874
+ "warning",
2875
+ "info"
2876
+ ]
2877
+ }
2864
2878
  }
2865
2879
  },
2866
2880
  "additionalProperties": false
@@ -5893,6 +5907,20 @@
5893
5907
  ],
5894
5908
  "additionalProperties": false
5895
5909
  }
5910
+ },
5911
+ "severity_overrides": {
5912
+ "type": "object",
5913
+ "propertyNames": {
5914
+ "type": "string"
5915
+ },
5916
+ "additionalProperties": {
5917
+ "type": "string",
5918
+ "enum": [
5919
+ "error",
5920
+ "warning",
5921
+ "info"
5922
+ ]
5923
+ }
5896
5924
  }
5897
5925
  },
5898
5926
  "additionalProperties": false
@@ -8726,6 +8754,20 @@
8726
8754
  ],
8727
8755
  "additionalProperties": false
8728
8756
  }
8757
+ },
8758
+ "severity_overrides": {
8759
+ "type": "object",
8760
+ "propertyNames": {
8761
+ "type": "string"
8762
+ },
8763
+ "additionalProperties": {
8764
+ "type": "string",
8765
+ "enum": [
8766
+ "error",
8767
+ "warning",
8768
+ "info"
8769
+ ]
8770
+ }
8729
8771
  }
8730
8772
  },
8731
8773
  "additionalProperties": false
@@ -11612,6 +11654,20 @@
11612
11654
  ],
11613
11655
  "additionalProperties": false
11614
11656
  }
11657
+ },
11658
+ "severity_overrides": {
11659
+ "type": "object",
11660
+ "propertyNames": {
11661
+ "type": "string"
11662
+ },
11663
+ "additionalProperties": {
11664
+ "type": "string",
11665
+ "enum": [
11666
+ "error",
11667
+ "warning",
11668
+ "info"
11669
+ ]
11670
+ }
11615
11671
  }
11616
11672
  },
11617
11673
  "additionalProperties": false
@@ -14445,6 +14501,20 @@
14445
14501
  ],
14446
14502
  "additionalProperties": false
14447
14503
  }
14504
+ },
14505
+ "severity_overrides": {
14506
+ "type": "object",
14507
+ "propertyNames": {
14508
+ "type": "string"
14509
+ },
14510
+ "additionalProperties": {
14511
+ "type": "string",
14512
+ "enum": [
14513
+ "error",
14514
+ "warning",
14515
+ "info"
14516
+ ]
14517
+ }
14448
14518
  }
14449
14519
  },
14450
14520
  "additionalProperties": false
@@ -17344,6 +17414,20 @@
17344
17414
  ],
17345
17415
  "additionalProperties": false
17346
17416
  }
17417
+ },
17418
+ "severity_overrides": {
17419
+ "type": "object",
17420
+ "propertyNames": {
17421
+ "type": "string"
17422
+ },
17423
+ "additionalProperties": {
17424
+ "type": "string",
17425
+ "enum": [
17426
+ "error",
17427
+ "warning",
17428
+ "info"
17429
+ ]
17430
+ }
17347
17431
  }
17348
17432
  },
17349
17433
  "additionalProperties": false
@@ -20177,6 +20261,20 @@
20177
20261
  ],
20178
20262
  "additionalProperties": false
20179
20263
  }
20264
+ },
20265
+ "severity_overrides": {
20266
+ "type": "object",
20267
+ "propertyNames": {
20268
+ "type": "string"
20269
+ },
20270
+ "additionalProperties": {
20271
+ "type": "string",
20272
+ "enum": [
20273
+ "error",
20274
+ "warning",
20275
+ "info"
20276
+ ]
20277
+ }
20180
20278
  }
20181
20279
  },
20182
20280
  "additionalProperties": false
@@ -23168,6 +23266,20 @@
23168
23266
  ],
23169
23267
  "additionalProperties": false
23170
23268
  }
23269
+ },
23270
+ "severity_overrides": {
23271
+ "type": "object",
23272
+ "propertyNames": {
23273
+ "type": "string"
23274
+ },
23275
+ "additionalProperties": {
23276
+ "type": "string",
23277
+ "enum": [
23278
+ "error",
23279
+ "warning",
23280
+ "info"
23281
+ ]
23282
+ }
23171
23283
  }
23172
23284
  },
23173
23285
  "additionalProperties": false
@@ -26001,6 +26113,20 @@
26001
26113
  ],
26002
26114
  "additionalProperties": false
26003
26115
  }
26116
+ },
26117
+ "severity_overrides": {
26118
+ "type": "object",
26119
+ "propertyNames": {
26120
+ "type": "string"
26121
+ },
26122
+ "additionalProperties": {
26123
+ "type": "string",
26124
+ "enum": [
26125
+ "error",
26126
+ "warning",
26127
+ "info"
26128
+ ]
26129
+ }
26004
26130
  }
26005
26131
  },
26006
26132
  "additionalProperties": false
@@ -28881,6 +29007,20 @@
28881
29007
  ],
28882
29008
  "additionalProperties": false
28883
29009
  }
29010
+ },
29011
+ "severity_overrides": {
29012
+ "type": "object",
29013
+ "propertyNames": {
29014
+ "type": "string"
29015
+ },
29016
+ "additionalProperties": {
29017
+ "type": "string",
29018
+ "enum": [
29019
+ "error",
29020
+ "warning",
29021
+ "info"
29022
+ ]
29023
+ }
28884
29024
  }
28885
29025
  },
28886
29026
  "additionalProperties": false
@@ -31826,6 +31966,20 @@
31826
31966
  ],
31827
31967
  "additionalProperties": false
31828
31968
  }
31969
+ },
31970
+ "severity_overrides": {
31971
+ "type": "object",
31972
+ "propertyNames": {
31973
+ "type": "string"
31974
+ },
31975
+ "additionalProperties": {
31976
+ "type": "string",
31977
+ "enum": [
31978
+ "error",
31979
+ "warning",
31980
+ "info"
31981
+ ]
31982
+ }
31829
31983
  }
31830
31984
  },
31831
31985
  "additionalProperties": false
@@ -34659,6 +34813,20 @@
34659
34813
  ],
34660
34814
  "additionalProperties": false
34661
34815
  }
34816
+ },
34817
+ "severity_overrides": {
34818
+ "type": "object",
34819
+ "propertyNames": {
34820
+ "type": "string"
34821
+ },
34822
+ "additionalProperties": {
34823
+ "type": "string",
34824
+ "enum": [
34825
+ "error",
34826
+ "warning",
34827
+ "info"
34828
+ ]
34829
+ }
34662
34830
  }
34663
34831
  },
34664
34832
  "additionalProperties": false
@@ -37507,6 +37675,20 @@
37507
37675
  ],
37508
37676
  "additionalProperties": false
37509
37677
  }
37678
+ },
37679
+ "severity_overrides": {
37680
+ "type": "object",
37681
+ "propertyNames": {
37682
+ "type": "string"
37683
+ },
37684
+ "additionalProperties": {
37685
+ "type": "string",
37686
+ "enum": [
37687
+ "error",
37688
+ "warning",
37689
+ "info"
37690
+ ]
37691
+ }
37510
37692
  }
37511
37693
  },
37512
37694
  "additionalProperties": false
@@ -40372,6 +40554,20 @@
40372
40554
  ],
40373
40555
  "additionalProperties": false
40374
40556
  }
40557
+ },
40558
+ "severity_overrides": {
40559
+ "type": "object",
40560
+ "propertyNames": {
40561
+ "type": "string"
40562
+ },
40563
+ "additionalProperties": {
40564
+ "type": "string",
40565
+ "enum": [
40566
+ "error",
40567
+ "warning",
40568
+ "info"
40569
+ ]
40570
+ }
40375
40571
  }
40376
40572
  },
40377
40573
  "additionalProperties": false
@@ -43296,6 +43492,20 @@
43296
43492
  ],
43297
43493
  "additionalProperties": false
43298
43494
  }
43495
+ },
43496
+ "severity_overrides": {
43497
+ "type": "object",
43498
+ "propertyNames": {
43499
+ "type": "string"
43500
+ },
43501
+ "additionalProperties": {
43502
+ "type": "string",
43503
+ "enum": [
43504
+ "error",
43505
+ "warning",
43506
+ "info"
43507
+ ]
43508
+ }
43299
43509
  }
43300
43510
  },
43301
43511
  "additionalProperties": false
@@ -46129,6 +46339,20 @@
46129
46339
  ],
46130
46340
  "additionalProperties": false
46131
46341
  }
46342
+ },
46343
+ "severity_overrides": {
46344
+ "type": "object",
46345
+ "propertyNames": {
46346
+ "type": "string"
46347
+ },
46348
+ "additionalProperties": {
46349
+ "type": "string",
46350
+ "enum": [
46351
+ "error",
46352
+ "warning",
46353
+ "info"
46354
+ ]
46355
+ }
46132
46356
  }
46133
46357
  },
46134
46358
  "additionalProperties": false
@@ -49009,6 +49233,20 @@
49009
49233
  ],
49010
49234
  "additionalProperties": false
49011
49235
  }
49236
+ },
49237
+ "severity_overrides": {
49238
+ "type": "object",
49239
+ "propertyNames": {
49240
+ "type": "string"
49241
+ },
49242
+ "additionalProperties": {
49243
+ "type": "string",
49244
+ "enum": [
49245
+ "error",
49246
+ "warning",
49247
+ "info"
49248
+ ]
49249
+ }
49012
49250
  }
49013
49251
  },
49014
49252
  "additionalProperties": false
@@ -51882,6 +52120,20 @@
51882
52120
  ],
51883
52121
  "additionalProperties": false
51884
52122
  }
52123
+ },
52124
+ "severity_overrides": {
52125
+ "type": "object",
52126
+ "propertyNames": {
52127
+ "type": "string"
52128
+ },
52129
+ "additionalProperties": {
52130
+ "type": "string",
52131
+ "enum": [
52132
+ "error",
52133
+ "warning",
52134
+ "info"
52135
+ ]
52136
+ }
51885
52137
  }
51886
52138
  },
51887
52139
  "additionalProperties": false
@@ -54964,6 +55216,20 @@
54964
55216
  ],
54965
55217
  "additionalProperties": false
54966
55218
  }
55219
+ },
55220
+ "severity_overrides": {
55221
+ "type": "object",
55222
+ "propertyNames": {
55223
+ "type": "string"
55224
+ },
55225
+ "additionalProperties": {
55226
+ "type": "string",
55227
+ "enum": [
55228
+ "error",
55229
+ "warning",
55230
+ "info"
55231
+ ]
55232
+ }
54967
55233
  }
54968
55234
  },
54969
55235
  "additionalProperties": false
@@ -2902,6 +2902,20 @@
2902
2902
  ],
2903
2903
  "additionalProperties": false
2904
2904
  }
2905
+ },
2906
+ "severity_overrides": {
2907
+ "type": "object",
2908
+ "propertyNames": {
2909
+ "type": "string"
2910
+ },
2911
+ "additionalProperties": {
2912
+ "type": "string",
2913
+ "enum": [
2914
+ "error",
2915
+ "warning",
2916
+ "info"
2917
+ ]
2918
+ }
2905
2919
  }
2906
2920
  },
2907
2921
  "additionalProperties": false
@@ -5735,6 +5749,20 @@
5735
5749
  ],
5736
5750
  "additionalProperties": false
5737
5751
  }
5752
+ },
5753
+ "severity_overrides": {
5754
+ "type": "object",
5755
+ "propertyNames": {
5756
+ "type": "string"
5757
+ },
5758
+ "additionalProperties": {
5759
+ "type": "string",
5760
+ "enum": [
5761
+ "error",
5762
+ "warning",
5763
+ "info"
5764
+ ]
5765
+ }
5738
5766
  }
5739
5767
  },
5740
5768
  "additionalProperties": false
@@ -8705,6 +8733,20 @@
8705
8733
  ],
8706
8734
  "additionalProperties": false
8707
8735
  }
8736
+ },
8737
+ "severity_overrides": {
8738
+ "type": "object",
8739
+ "propertyNames": {
8740
+ "type": "string"
8741
+ },
8742
+ "additionalProperties": {
8743
+ "type": "string",
8744
+ "enum": [
8745
+ "error",
8746
+ "warning",
8747
+ "info"
8748
+ ]
8749
+ }
8708
8750
  }
8709
8751
  },
8710
8752
  "additionalProperties": false
@@ -16429,7 +16429,7 @@
16429
16429
  "const": "object_panorama"
16430
16430
  },
16431
16431
  "result": {
16432
- "description": "ObjectPanorama (discriminated object_type + head + typed fields + per-type extras)."
16432
+ "description": "ObjectPanorama (discriminated object_type + head + typed fields + per-type extras, incl. Proof anchored_root + wts_anchor_check)."
16433
16433
  }
16434
16434
  },
16435
16435
  "required": [
@@ -1080,6 +1080,10 @@
1080
1080
  "description": "DEPRECATED alias of object_address (accepted for call compatibility; must be a plain address or LocalMark NAME string, not an object). Prefer object_address. Example: {\"query_type\": \"object_panorama\", \"object_address\": \"0xabc...\"}.",
1081
1081
  "type": "string"
1082
1082
  },
1083
+ "wts_file_path": {
1084
+ "description": "Proof objects only: local path to the .wts evidence packet to cross-check against this anchor. Returns wts_anchor_check — whether the packet's message roots match the frozen root, whether the server key matches, and whether the Proof predates the packet (a frozen Proof is what makes WTS content non-re-fabricable after the fact).",
1085
+ "type": "string"
1086
+ },
1083
1087
  "context_network": {
1084
1088
  "type": "string",
1085
1089
  "enum": [
@@ -1094,7 +1098,7 @@
1094
1098
  "query_type"
1095
1099
  ],
1096
1100
  "additionalProperties": false,
1097
- "description": "ONE-CALL detail-page panorama for Progress / Demand / Order / Arb / Repository objects (client panorama family): discriminated `object_type` + head (name/tags/description) + the object's own typed fields + type-specific extras (Demand presenters from the GLOBAL tx table, Progress session/forwards, Arb votes & propositions, Repository policies). Read-only."
1101
+ "description": "ONE-CALL detail-page panorama for Progress / Demand / Order / Arb / Repository / Proof objects (client panorama family): discriminated `object_type` + head (name/tags/description) + the object's own typed fields + type-specific extras (Demand presenters from the GLOBAL tx table, Progress session/forwards, Arb votes & propositions, Repository policies, Proof anchored root + WTS cross-check). Read-only."
1098
1102
  },
1099
1103
  {
1100
1104
  "type": "object",
@@ -1,2 +1,19 @@
1
+ import { type IndustryTemplate } from "../../knowledge/template-loader.js";
2
+ import type { DeliverableDefinition } from "../../playbooks/service-build/intent-analyzer.js";
3
+ import type { IndustryMode } from "../../extensions/index.js";
1
4
  import type { ToolDispatchResult } from "../types.js";
5
+ export declare function validateAllocatorRows(t: IndustryTemplate): string[];
6
+ interface PlanDivergence {
7
+ severity: "critical" | "warning";
8
+ item: string;
9
+ detail: string;
10
+ action: string;
11
+ }
12
+ export declare function planDivergences(t: IndustryTemplate, allocation: Array<{
13
+ recipient: string;
14
+ percentage: number;
15
+ }> | undefined): PlanDivergence[];
16
+ export declare function variantPaymentModel(t: IndustryTemplate): "milestone" | "subscription" | "escrow";
17
+ export declare function variantDeliverables(t: IndustryTemplate, traits: IndustryMode["traits"] | undefined): DeliverableDefinition[];
2
18
  export declare function handleBenchmarkMigrationOperation(args: unknown): Promise<ToolDispatchResult>;
19
+ export {};
@@ -1 +1 @@
1
- import{strictParse}from'../../schema/index.js';import{BenchmarkMigrationSchema}from'../../schema/benchmark-migration/index.js';import{getTemplate,listTemplates}from'../../knowledge/template-loader.js';import{scanTemplate}from'../../knowledge/template-scanner.js';import{planMigration}from'../../playbooks/service-build/migration-planner.js';import{handleMerchantGuide}from'../../playbooks/service-build/merchant-guide.js';import{getIndustryModeRegistry}from'../../extensions/index.js';import{resolveIndustryName}from'../../knowledge/industry-registry.js';function templateSummary(a){return{'id':a['id'],'industry':a['industry'],'variant':a['variant'],'product_ref':a['product_ref'],'archetype':a['archetype'],'key_risk':a['key_risk'],'node_count':a['machine_shape']['length'],'guard_count':a['guards']['length'],'recommended_role':a['recommended_role']};}function requireTemplate(a,b){if(!a)throw new Error('\x27template_id\x27\x20is\x20required\x20for\x20action=\x27'+b+'\x27');const c=getTemplate(a);if(!c)throw new Error('Unknown\x20template\x20id:\x20'+a+'\x20(use\x20action=\x27template_list\x27\x20to\x20see\x20valid\x20ids)');return c;}function scanSummary(a){const b={};for(const c of a['findings'])b[c['severity']]=(b[c['severity']]??0x0)+0x1;return{'risk_level':a['risk_level'],'passed':a['passed'],'finding_count':a['findings']['length'],'findings_by_severity':b,'red_flags':a['red_flags'],'findings':a['findings']};}function assertScanPassed(a,b){if(a['passed'])return;throw new Error('action=\x27'+b+'\x27\x20blocked:\x20pre-deploy\x20scan\x20of\x20template\x20\x27'+a['template_id']+'\x27\x20found\x20CRITICAL\x20risk\x20—\x20'+a['red_flags']['join'](';\x20')+'.\x20Fix\x20the\x20template\x20(frontmatter\x20or\x20body)\x20and\x20re-run\x20action=\x27template_scan\x27.');}function templateIntent(a,b){if(b&&b['trim']())return b['trim']();return'Adopt\x20the\x20'+a['id']+'\x20industry\x20archetype\x20template\x20('+a['archetype']+')\x20for\x20the\x20'+a['industry']+'\x20industry.\x20'+('Primary\x20risk\x20to\x20mitigate:\x20'+a['key_risk']+'.');}function effectiveFeeParams(a,b){return{...a['fee_params'],...b??{}};}function validateFeeParams(a,b){const c=[];let d=0x0;for(const [e,f]of Object['entries'](a)){if(typeof f!=='number'||!Number['isFinite'](f))continue;if(e['endsWith']('_bps')){(!Number['isInteger'](f)||f<0x0||f>0x2710)&&c['push'](e+'='+f+'\x20is\x20not\x20an\x20integer\x20rate\x20in\x20[0,\x2010000]\x20bps');if(e['endsWith']('_share_bps'))d+=Math['max'](0x0,f);}else{if(e['endsWith']('_days')){if(f<=0x0||f>0xe42)c['push'](e+'='+f+'\x20is\x20outside\x20the\x20sane\x20window\x20range\x20(0,\x203650]\x20days');}else{if(e['endsWith']('_hours')){if(f<=0x0||f>0x2238)c['push'](e+'='+f+'\x20is\x20outside\x20the\x20sane\x20window\x20range\x20(0,\x208760]\x20hours');}}}}if(d>0x2710)c['push']('*_share_bps\x20sum\x20'+d+'\x20exceeds\x2010000\x20(a\x20pool\x20splits\x20into\x20at\x20most\x20100%)');if(c['length']>0x0)throw new Error('invalid\x20fee\x20parameters\x20for\x20template\x20\x27'+b+'\x27:\x20'+c['join'](';\x20')+'.\x20'+'Correct\x20the\x20template\x27s\x20fee_params\x20or\x20pass\x20valid\x20\x27fee_overrides\x27.');}function validateAllocatorRows(a){const b=a['allocator']['rows'];if(b===undefined||b['length']===0x0)return[];const c=[],d=b['filter'](f=>f['track']==='settlement'),e=b['filter'](f=>f['track']==='refund');d['length']!==a['allocator']['count']&&c['push']('settlement\x20rows\x20'+d['length']+'\x20!=\x20allocator.count\x20'+a['allocator']['count']);e['length']>0x0&&!a['allocator']['refund_track']&&c['push']('refund\x20rows\x20declared\x20but\x20allocator.refund_track\x20is\x20missing');a['allocator']['refund_track']&&e['length']===0x0&&c['push']('refund_track\x20\x27'+a['allocator']['refund_track']+'\x27\x20declared\x20but\x20no\x20refund\x20row\x20carries\x20it');for(const [f,g]of[['settlement',d],['refund',e]]){const h=g['filter'](j=>j['mode']==='surplus')['length'];if(h>0x1)c['push'](f+'\x20track\x20has\x20'+h+'\x20Surplus\x20rows\x20(allocation.move\x20allows\x20at\x20most\x20one)');const i=g['filter'](j=>j['mode']==='rate');if(i['length']===g['length']&&i['length']>0x0&&h===0x0){const j=i['reduce']((k,l)=>k+(typeof l['value']==='number'?l['value']:Number(l['value']??NaN)),0x0);(!Number['isFinite'](j)||j!==0x2710)&&c['push'](f+'\x20track\x20is\x20all-Rate\x20but\x20sums\x20to\x20'+j+',\x20not\x2010000\x20bps');}for(const k of g){if(k['mode']==='surplus'&&k['value']!==undefined)c['push'](f+'/'+(k['recipient_key']??'?')+':\x20surplus\x20row\x20must\x20not\x20carry\x20a\x20value');k['mode']==='amount'&&k['value']===undefined&&k['value_from']===undefined&&c['push'](f+'/'+(k['recipient_key']??'?')+':\x20amount\x20row\x20needs\x20value\x20or\x20value_from'),k['value_from']!==undefined&&!(k['value_from']in a['fee_params'])&&c['push'](f+'/'+(k['recipient_key']??'?')+':\x20value_from\x20\x27'+k['value_from']+'\x27\x20is\x20not\x20a\x20fee_params\x20key'),k['recipient']==='guard_identifier'&&k['track']==='settlement'&&c['push']('settlement\x20row\x20uses\x20GuardIdentifier\x20—\x20order-anchored\x20recipients\x20belong\x20to\x20the\x20refund\x20track\x20(see\x20refund_track)');}}return c;}function planDivergences(a,b){const c=[],d=b?.['length']??0x0,e=(a['allocator']['rows']?.['length']??0x0)>0x0;if(e){const h=validateAllocatorRows(a);h['length']>0x0&&c['push']({'severity':'critical','item':'allocator_rows_invalid','detail':'Template\x20allocator\x20rows\x20are\x20internally\x20inconsistent:\x20'+h['join'](';\x20')+'.','action':'Fix\x20the\x20template\x27s\x20allocator.rows\x20(they\x20are\x20the\x20authoritative\x20money\x20plan;\x20order_allocators\x20is\x20L1-frozen\x20at\x20publish).'});}else d!==a['allocator']['count']&&c['push']({'severity':'critical','item':'allocator_row_count','detail':'Template\x20declares\x20'+a['allocator']['count']+'\x20sharing\x20row(s);\x20the\x20generated\x20plan\x20carries\x20'+d+'\x20percentage\x20row(s).','action':'Build\x20the\x20Allocation\x20with\x20the\x20template\x27s\x20own\x20row\x20set\x20(order_allocators\x20is\x20L1\x20—\x20frozen\x20at\x20Service\x20publish),\x20or\x20declare\x20allocator.rows\x20in\x20the\x20template.'}),a['allocator']['mode']!=='rate'&&c['push']({'severity':'critical','item':'allocation_mode','detail':'Template\x20allocator\x20mode\x20is\x20\x27'+a['allocator']['mode']+'\x27,\x20which\x20a\x20percentage\x20pair\x20cannot\x20represent\x20—\x20no\x20percentage\x20hint\x20was\x20emitted.','action':'Declare\x20allocator.rows\x20in\x20the\x20template\x20(per-row\x20amount\x20/\x20rate\x20/\x20surplus);\x20the\x20pipeline\x20will\x20then\x20carry\x20the\x20real\x20split\x20instead\x20of\x20a\x20hint.'});const f=a['allocator']['refund_track']!==undefined||/refund/i['test'](a['allocator']['description']);a['allocator']['refund_track']&&c['push']({'severity':'critical','item':'refund_track_not_in_plan','detail':'Template\x20declares\x20a\x20\x27'+a['allocator']['refund_track']+'\x27\x20refund\x20track;\x20the\x20generated\x20plan\x20carries\x20only\x20the\x20settlement\x20split.','action':'Build\x20the\x20second\x20Allocator\x20(Rate\x2010000\x20to\x20the\x20buyer,\x20order-anchored\x20GuardIdentifier\x20recipients)\x20bound\x20to\x20the\x20refund\x20Guard\x20before\x20publish.'});if(!f)c['push']({'severity':'critical','item':'refund_track','detail':'The\x20template\x27s\x20allocator\x20declares\x20no\x20refund\x20track\x20—\x20returns/refunds\x20have\x20no\x20funded\x20path\x20in\x20the\x20money\x20plan.','action':'Add\x20the\x20second\x20Allocator\x20(Rate\x2010000\x20to\x20the\x20buyer)\x20bound\x20to\x20the\x20refund\x20Guard,\x20or\x20confirm\x20with\x20the\x20merchant\x20that\x20refunds\x20are\x20out\x20of\x20scope.'});else!a['allocator']['refund_track']&&c['push']({'severity':'warning','item':'refund_track','detail':'A\x20refund\x20track\x20is\x20declared\x20but\x20not\x20order-anchored,\x20so\x20the\x20refund\x20recipient\x20is\x20resolved\x20from\x20the\x20signer/Entity\x20rather\x20than\x20the\x20paying\x20Order.','action':'Gate\x20the\x20refund\x20track\x20with\x20AND[signer\x20==\x20order.owner,\x20progress.node\x20==\x20X]\x20or\x20move\x20it\x20to\x20an\x20order-anchored\x20GuardIdentifier(0)\x20recipient.'});const g=Object['keys'](a['fee_params'])['filter'](i=>/_(?:days|hours)$/['test'](i));return g['length']>0x0&&!a['time_anchors']&&c['push']({'severity':'warning','item':'window_anchors','detail':'fee_params\x20declares\x20business\x20windows\x20('+g['join'](',\x20')+')\x20but\x20the\x20template\x20declares\x20no\x20time_anchors.','action':'Add\x20time_anchors\x20(or\x20name\x20the\x20window\x20in\x20the\x20Guard\x20set)\x20so\x20the\x20plan\x20emits\x20the\x20release/timeout\x20build\x20steps.'}),c;}function platformShareBps(a){const b=Object['keys'](a)['find'](c=>/(?:platform|commission|service_fee)[a-z_]*_bps$/['test'](c)&&!/^attributed_/['test'](c)&&typeof a[c]==='number');return b!==undefined?a[b]:undefined;}function variantPaymentModel(a){const b=a['machine_shape']['map'](c=>c['name']+'\x20'+c['role'])['join']('\x20')['toLowerCase']();if(/\b(milestone|revision|revis|draft|deliverable)\b/['test'](b))return'milestone';if(/\b(charge|renew|subscription|cycle|billing|monthly)\b/['test'](b))return'subscription';return'escrow';}function variantRefundPolicy(a){const b=a['allocator']['description']['toLowerCase']();if(/full[ -]?refund|100% refund|refund .*100/['test'](b))return'full';if(/pro-?rata|prorated/['test'](b))return'milestone_prorated';if(/partial/['test'](b))return'partial';return undefined;}function variantDeliverables(a,b){const c=[...a['machine_shape']]['reverse']()['find'](e=>!/refund|cancel|dispute|terminat/i['test'](e['name']+'\x20'+e['role']))??a['machine_shape'][a['machine_shape']['length']-0x1],d=b?.['has_logistics']?'physical':b?.['pure_digital']?'digital':'service_session';return[{'name':a['variant']+'\x20fulfillment','type':d,'acceptanceCriteria':'Order\x20reaches\x20the\x20terminal\x20workflow\x20node\x20\x27'+c['name']+'\x27\x20('+c['role']+')','proofOfDelivery':'manual_confirm'}];}function variantModePrior(a,b){if(!b)return undefined;return{...b,'name':a['industry']+'_'+a['variant'],'display_name':a['variant']+'\x20archetype\x20('+a['industry']+')','source':'custom','machine_shape':a['machine_shape']['map'](c=>({...c})),'guards':a['guards']['map'](c=>({...c})),'allocator':{...a['allocator']},'key_risk':a['key_risk'],'build_notes':[...a['build_notes']],...a['time_anchors']?{'time_anchors':{...a['time_anchors']}}:{}};}async function runGuide(a,b,c){const d=effectiveFeeParams(a,c);validateFeeParams(d,a['id']);const e=getIndustryModeRegistry()['getMode'](a['industry']),f=platformShareBps(d),g={'model':variantPaymentModel(a)},h=[],i=(a['allocator']['rows']?.['length']??0x0)>0x0;if(f!==undefined&&f>0x0&&!i&&a['allocator']['mode']==='rate'){const n=Math['round'](f)/0x64;h['push']({'recipient':'merchant','percentage':Math['round']((0x64-n)*0x64)/0x64}),h['push']({'recipient':'platform','percentage':n}),g['allocation']=h;}const j=variantRefundPolicy(a),k={'escrow':!![]};if(j)k['refundPolicy']=j;const l=await handleMerchantGuide({'intent':templateIntent(a,b),'guide_confirm':{'industry':a['industry'],'payment':g,'trust':k,'deliverables':variantDeliverables(a,e?.['traits'])},'mode_prior_override':variantModePrior(a,e),'name_base':a['id']}),m=planDivergences(a,h);if(a['allocator']['rows']?.['length'])l['template_allocator_rows']=a['allocator']['rows']['map'](o=>({...o}));m['length']>0x0&&(l['plan_divergence']={'template_allocator':{...a['allocator']},'template_guard_refs':a['guards']['length'],'plan_allocation':h,'divergences':m,'publish_ready':![]});l['template']={'id':a['id'],'archetype':a['archetype'],'recommended_role':a['recommended_role'],'fee_params':d};if(c&&Object['keys'](c)['length']>0x0)l['template_fee_overrides']=c;return l;}export async function handleBenchmarkMigrationOperation(a){const b=strictParse(BenchmarkMigrationSchema,a,'benchmark_migration_operation\x20input'),c=b['industry']?resolveIndustryName(b['industry'])??b['industry']['toLowerCase']():undefined;let d;switch(b['action']){case'template_list':{const {templates:e,errors:f}=listTemplates(),g=c?e['filter'](h=>h['industry']===c):e;d={'action':'template_list','count':g['length'],'templates':g['map'](templateSummary),'load_errors':f};break;}case'template_get':{const h=requireTemplate(b['template_id'],'template_get');d={'action':'template_get','template':{...h}};break;}case'template_generate':{const i=requireTemplate(b['template_id'],'template_generate'),j=scanTemplate(i);assertScanPassed(j,'template_generate');const k=await runGuide(i,b['description'],b['fee_overrides']);d={'action':'template_generate','template_id':i['id'],'scan':scanSummary(j),'plan':k};break;}case'template_scan':{const l=requireTemplate(b['template_id'],'template_scan');d={'action':'template_scan','scan':scanTemplate(l)};break;}case'migration_import':{if(!b['description']||!b['description']['trim']())throw new Error('\x27description\x27\x20is\x20required\x20for\x20action=\x27migration_import\x27');const m=planMigration({'url':b['url'],'description':b['description'],'industry':c,'network':b['network']});if(!m)throw new Error('No\x20industry\x20template\x20matched\x20the\x20description.\x20Refine\x20the\x20description\x20or\x20pass\x20an\x20explicit\x20\x27industry\x27\x20hint.');d={'action':'migration_import','log':m};break;}case'migration_review':{if(!b['log'])throw new Error('\x27log\x27\x20is\x20required\x20for\x20action=\x27migration_review\x27');const n=b['log'],o=Array['isArray'](n['mapped'])?n['mapped']:[],p=Array['isArray'](n['unmapped'])?n['unmapped']:[],q=Array['isArray'](n['manual_review'])?n['manual_review']:[],r=n['risk_check']??{};d={'action':'migration_review','log':n,'review_summary':{'mapped_count':o['length'],'unmapped_count':p['length'],'manual_review_count':q['length'],'risk_passed':r['passed']===!![]}};break;}case'migration_apply':{const s=requireTemplate(b['template_id'],'migration_apply'),t=scanTemplate(s);assertScanPassed(t,'migration_apply');const u=b['network']??'testnet',v=await runGuide(s,b['description'],b['fee_overrides']);d={'action':'migration_apply','template_id':s['id'],'network':u,'scan':scanSummary(t),'plan':v};break;}default:throw new Error('Unknown\x20benchmark_migration_operation\x20action:\x20'+String(b['action']));}return{'content':[{'type':'text','text':JSON['stringify']({'result':d})}],'structuredContent':{'result':d}};}
1
+ import{strictParse}from'../../schema/index.js';import{BenchmarkMigrationSchema}from'../../schema/benchmark-migration/index.js';import{getTemplate,listTemplates}from'../../knowledge/template-loader.js';import{scanTemplate}from'../../knowledge/template-scanner.js';import{planMigration}from'../../playbooks/service-build/migration-planner.js';import{handleMerchantGuide}from'../../playbooks/service-build/merchant-guide.js';import{inferArbitration}from'../../playbooks/service-build/intent-analyzer.js';import{getIndustryModeRegistry}from'../../extensions/index.js';import{resolveIndustryName}from'../../knowledge/industry-registry.js';function templateSummary(a){return{'id':a['id'],'industry':a['industry'],'variant':a['variant'],'product_ref':a['product_ref'],'archetype':a['archetype'],'key_risk':a['key_risk'],'node_count':a['machine_shape']['length'],'guard_count':a['guards']['length'],'recommended_role':a['recommended_role']};}function requireTemplate(a,b){if(!a)throw new Error('\x27template_id\x27\x20is\x20required\x20for\x20action=\x27'+b+'\x27');const c=getTemplate(a);if(!c)throw new Error('Unknown\x20template\x20id:\x20'+a+'\x20(use\x20action=\x27template_list\x27\x20to\x20see\x20valid\x20ids)');return c;}function scanSummary(a){const b={};for(const c of a['findings'])b[c['severity']]=(b[c['severity']]??0x0)+0x1;return{'risk_level':a['risk_level'],'passed':a['passed'],'finding_count':a['findings']['length'],'findings_by_severity':b,'red_flags':a['red_flags'],'findings':a['findings']};}function assertScanPassed(a,b){if(a['passed'])return;throw new Error('action=\x27'+b+'\x27\x20blocked:\x20pre-deploy\x20scan\x20of\x20template\x20\x27'+a['template_id']+'\x27\x20found\x20CRITICAL\x20risk\x20—\x20'+a['red_flags']['join'](';\x20')+'.\x20Fix\x20the\x20template\x20(frontmatter\x20or\x20body)\x20and\x20re-run\x20action=\x27template_scan\x27.');}function templateIntent(a,b){if(b&&b['trim']())return b['trim']();return'Adopt\x20the\x20'+a['id']+'\x20industry\x20archetype\x20template\x20('+a['archetype']+')\x20for\x20the\x20'+a['industry']+'\x20industry.\x20'+('Primary\x20risk\x20to\x20mitigate:\x20'+a['key_risk']+'.');}function effectiveFeeParams(a,b){return{...a['fee_params'],...b??{}};}function validateFeeParams(a,b){const c=[];let d=0x0;for(const [e,f]of Object['entries'](a)){if(typeof f!=='number'||!Number['isFinite'](f))continue;if(e['endsWith']('_bps')){(!Number['isInteger'](f)||f<0x0||f>0x2710)&&c['push'](e+'='+f+'\x20is\x20not\x20an\x20integer\x20rate\x20in\x20[0,\x2010000]\x20bps');if(e['endsWith']('_share_bps'))d+=Math['max'](0x0,f);}else{if(e['endsWith']('_days')){if(f<=0x0||f>0xe42)c['push'](e+'='+f+'\x20is\x20outside\x20the\x20sane\x20window\x20range\x20(0,\x203650]\x20days');}else{if(e['endsWith']('_hours')){if(f<=0x0||f>0x2238)c['push'](e+'='+f+'\x20is\x20outside\x20the\x20sane\x20window\x20range\x20(0,\x208760]\x20hours');}}}}if(d>0x2710)c['push']('*_share_bps\x20sum\x20'+d+'\x20exceeds\x2010000\x20(a\x20pool\x20splits\x20into\x20at\x20most\x20100%)');if(c['length']>0x0)throw new Error('invalid\x20fee\x20parameters\x20for\x20template\x20\x27'+b+'\x27:\x20'+c['join'](';\x20')+'.\x20'+'Correct\x20the\x20template\x27s\x20fee_params\x20or\x20pass\x20valid\x20\x27fee_overrides\x27.');}export function validateAllocatorRows(a){const b=a['allocator']['rows'];if(b===undefined||b['length']===0x0)return[];const c=[],d=b['filter'](f=>f['track']==='settlement'),e=b['filter'](f=>f['track']==='refund');d['length']!==a['allocator']['count']&&c['push']('settlement\x20rows\x20'+d['length']+'\x20!=\x20allocator.count\x20'+a['allocator']['count']);e['length']>0x0&&!a['allocator']['refund_track']&&c['push']('refund\x20rows\x20declared\x20but\x20allocator.refund_track\x20is\x20missing');a['allocator']['refund_track']&&e['length']===0x0&&c['push']('refund_track\x20\x27'+a['allocator']['refund_track']+'\x27\x20declared\x20but\x20no\x20refund\x20row\x20carries\x20it');for(const [f,g]of[['settlement',d],['refund',e]]){const h=g['filter'](j=>j['mode']==='surplus')['length'];if(h>0x1)c['push'](f+'\x20track\x20has\x20'+h+'\x20Surplus\x20rows\x20(allocation.move\x20allows\x20at\x20most\x20one)');const i=g['filter'](j=>j['mode']==='rate');if(i['length']===g['length']&&i['length']>0x0&&h===0x0){const j=i['reduce']((k,l)=>k+(typeof l['value']==='number'?l['value']:Number(l['value']??NaN)),0x0);(!Number['isFinite'](j)||j!==0x2710)&&c['push'](f+'\x20track\x20is\x20all-Rate\x20but\x20sums\x20to\x20'+j+',\x20not\x2010000\x20bps');}for(const k of g){if(k['mode']==='surplus'&&k['value']!==undefined)c['push'](f+'/'+(k['recipient_key']??'?')+':\x20surplus\x20row\x20must\x20not\x20carry\x20a\x20value');k['mode']==='amount'&&k['value']===undefined&&k['value_from']===undefined&&c['push'](f+'/'+(k['recipient_key']??'?')+':\x20amount\x20row\x20needs\x20value\x20or\x20value_from'),k['value_from']!==undefined&&!(k['value_from']in a['fee_params'])&&c['push'](f+'/'+(k['recipient_key']??'?')+':\x20value_from\x20\x27'+k['value_from']+'\x27\x20is\x20not\x20a\x20fee_params\x20key'),k['recipient']==='guard_identifier'&&k['track']==='settlement'&&c['push']('settlement\x20row\x20uses\x20GuardIdentifier\x20—\x20order-anchored\x20recipients\x20belong\x20to\x20the\x20refund\x20track\x20(see\x20refund_track)');}}return c;}export function planDivergences(a,b){const c=[],d=b?.['length']??0x0,e=(a['allocator']['rows']?.['length']??0x0)>0x0;if(e){const i=validateAllocatorRows(a);i['length']>0x0&&c['push']({'severity':'critical','item':'allocator_rows_invalid','detail':'Template\x20allocator\x20rows\x20are\x20internally\x20inconsistent:\x20'+i['join'](';\x20')+'.','action':'Fix\x20the\x20template\x27s\x20allocator.rows\x20(they\x20are\x20the\x20authoritative\x20money\x20plan;\x20order_allocators\x20is\x20L1-frozen\x20at\x20publish).'});}else d!==a['allocator']['count']&&c['push']({'severity':'critical','item':'allocator_row_count','detail':'Template\x20declares\x20'+a['allocator']['count']+'\x20sharing\x20row(s);\x20the\x20generated\x20plan\x20carries\x20'+d+'\x20percentage\x20row(s).','action':'Build\x20the\x20Allocation\x20with\x20the\x20template\x27s\x20own\x20row\x20set\x20(order_allocators\x20is\x20L1\x20—\x20frozen\x20at\x20Service\x20publish),\x20or\x20declare\x20allocator.rows\x20in\x20the\x20template.'}),a['allocator']['mode']!=='rate'&&c['push']({'severity':'critical','item':'allocation_mode','detail':'Template\x20allocator\x20mode\x20is\x20\x27'+a['allocator']['mode']+'\x27,\x20which\x20a\x20percentage\x20pair\x20cannot\x20represent\x20—\x20no\x20percentage\x20hint\x20was\x20emitted.','action':'Declare\x20allocator.rows\x20in\x20the\x20template\x20(per-row\x20amount\x20/\x20rate\x20/\x20surplus);\x20the\x20pipeline\x20will\x20then\x20carry\x20the\x20real\x20split\x20instead\x20of\x20a\x20hint.'});const f=a['allocator']['refund_track']!==undefined||/refund/i['test'](a['allocator']['description']),g=(a['allocator']['rows']??[])['some'](j=>j['track']==='refund');a['allocator']['refund_track']&&!g&&c['push']({'severity':'critical','item':'refund_track_not_in_plan','detail':'Template\x20declares\x20a\x20\x27'+a['allocator']['refund_track']+'\x27\x20refund\x20track\x20but\x20declares\x20no\x20allocator\x20row\x20with\x20track=\x27refund\x27;\x20the\x20generated\x20plan\x20cannot\x20carry\x20the\x20promised\x20refund\x20rail.','action':'Declare\x20a\x20refund\x20row\x20in\x20allocator.rows\x20(recipient\x20guard_identifier,\x20recipient_key\x20\x270\x27,\x20mode\x20rate,\x20value\x2010000)\x20so\x20the\x20order-anchored\x20full-refund\x20rail\x20rides\x20with\x20the\x20plan.'});if(!f)c['push']({'severity':'critical','item':'refund_track','detail':'The\x20template\x27s\x20allocator\x20declares\x20no\x20refund\x20track\x20—\x20returns/refunds\x20have\x20no\x20funded\x20path\x20in\x20the\x20money\x20plan.','action':'Add\x20the\x20second\x20Allocator\x20(Rate\x2010000\x20to\x20the\x20buyer)\x20bound\x20to\x20the\x20refund\x20Guard,\x20or\x20confirm\x20with\x20the\x20merchant\x20that\x20refunds\x20are\x20out\x20of\x20scope.'});else!a['allocator']['refund_track']&&c['push']({'severity':'warning','item':'refund_track','detail':'A\x20refund\x20track\x20is\x20declared\x20but\x20not\x20order-anchored,\x20so\x20the\x20refund\x20recipient\x20is\x20resolved\x20from\x20the\x20signer/Entity\x20rather\x20than\x20the\x20paying\x20Order.','action':'Gate\x20the\x20refund\x20track\x20with\x20AND[signer\x20==\x20order.owner,\x20progress.node\x20==\x20X]\x20or\x20move\x20it\x20to\x20an\x20order-anchored\x20GuardIdentifier(0)\x20recipient.'});const h=Object['keys'](a['fee_params'])['filter'](j=>/_(?:days|hours)$/['test'](j));return h['length']>0x0&&!a['time_anchors']&&c['push']({'severity':'warning','item':'window_anchors','detail':'fee_params\x20declares\x20business\x20windows\x20('+h['join'](',\x20')+')\x20but\x20the\x20template\x20declares\x20no\x20time_anchors.','action':'Add\x20time_anchors\x20(or\x20name\x20the\x20window\x20in\x20the\x20Guard\x20set)\x20so\x20the\x20plan\x20emits\x20the\x20release/timeout\x20build\x20steps.'}),c;}function platformShareBps(a){const b=Object['keys'](a)['find'](c=>/(?:platform|commission|service_fee)[a-z_]*_bps$/['test'](c)&&!/^attributed_/['test'](c)&&typeof a[c]==='number');return b!==undefined?a[b]:undefined;}export function variantPaymentModel(a){if(a['payment_model'])return a['payment_model'];const b=a['machine_shape']['map'](c=>c['name']+'\x20'+c['role'])['join']('\x20')['toLowerCase']();if(/\b(milestone|revision|revis|draft|deliverable)\b/['test'](b))return'milestone';if(/\b(charge|renew|subscription|cycle|billing|monthly)\b/['test'](b))return'subscription';return'escrow';}function variantRefundPolicy(a){const b=a['allocator']['description']['toLowerCase']();if(/full[ -]?refund|100% refund|refund .*100/['test'](b))return'full';if(/pro-?rata|prorated/['test'](b))return'milestone_prorated';if(/partial/['test'](b))return'partial';return undefined;}export function variantDeliverables(a,b){const c=a['machine_shape']['filter'](g=>g['semantic_role']==='final'),d=c[c['length']-0x1]??[...a['machine_shape']]['reverse']()['find'](g=>!/refund|cancel|dispute|terminat/i['test'](g['name']+'\x20'+g['role']))??a['machine_shape'][a['machine_shape']['length']-0x1],e=b?.['has_logistics']?'physical':b?.['pure_digital']?'digital':'service_session',f=(a['guards']??[])['filter'](h=>/repository_data_check|required_info_evidence_gate|allocator_order_anchor/['test'](h['template_id']));return[{'name':a['variant']+'\x20fulfillment','type':e,'acceptanceCriteria':'Order\x20reaches\x20the\x20terminal\x20workflow\x20node\x20\x27'+d['name']+'\x27\x20('+d['role']+')','proofOfDelivery':f['length']>0x0?'wip_hash':'manual_confirm'}];}function variantModePrior(a,b){if(!b)return undefined;return{...b,'name':a['industry']+'_'+a['variant'],'display_name':a['variant']+'\x20archetype\x20('+a['industry']+')','source':'custom','machine_shape':a['machine_shape']['map'](c=>({...c})),'guards':a['guards']['map'](c=>({...c})),'allocator':{...a['allocator']},'key_risk':a['key_risk'],'build_notes':[...a['build_notes']],...a['time_anchors']?{'time_anchors':{...a['time_anchors']}}:{}};}async function runGuide(a,b,c){const d=effectiveFeeParams(a,c);validateFeeParams(d,a['id']);const e=getIndustryModeRegistry()['getMode'](a['industry']),f=platformShareBps(d),g={'model':variantPaymentModel(a)},h=[],i=(a['allocator']['rows']?.['length']??0x0)>0x0;if(f!==undefined&&f>0x0&&!i&&a['allocator']['mode']==='rate'){const n=Math['round'](f)/0x64;h['push']({'recipient':'merchant','percentage':Math['round']((0x64-n)*0x64)/0x64}),h['push']({'recipient':'platform','percentage':n}),g['allocation']=h;}const j=variantRefundPolicy(a),k={'escrow':!![]};if(j)k['refundPolicy']=j;k['arbitration']=a['arbitration_mode']??k['arbitration']??inferArbitration(templateIntent(a,b));const l=await handleMerchantGuide({'intent':templateIntent(a,b),'guide_confirm':{'industry':a['industry'],'payment':g,'trust':k,'deliverables':variantDeliverables(a,e?.['traits'])},'mode_prior_override':variantModePrior(a,e),'name_base':a['id']}),m=planDivergences(a,h);if(a['allocator']['rows']?.['length'])l['template_allocator_rows']=a['allocator']['rows']['map'](o=>({...o}));if(m['length']>0x0){l['plan_divergence']={'template_allocator':{...a['allocator']},'template_guard_refs':a['guards']['length'],'plan_allocation':h,'divergences':m,'publish_ready':![]};const o=m['filter'](q=>q['severity']==='critical'),p=a['allocator']['refund_track']!==undefined;if(o['length']>0x0&&p&&!(a['allocator']['rows']?.['length']??0x0))throw new Error('action\x20blocked:\x20template\x20\x27'+a['id']+'\x27\x20declares\x20refund_track=\x27'+a['allocator']['refund_track']+'\x27\x20but\x20'+'carries\x20no\x20allocator.rows,\x20so\x20the\x20generated\x20plan\x20would\x20ship\x20WITHOUT\x20the\x20refund\x20rail\x20it\x20'+'promises.\x20Because\x20order_allocators\x20is\x20L1\x20and\x20one-way-frozen\x20at\x20Service\x20publish,\x20escrow\x20'+'locked\x20under\x20such\x20a\x20plan\x20can\x20never\x20be\x20returned.\x20Refusing\x20to\x20emit\x20an\x20unsafe\x20build\x20plan.\x20'+'Critical\x20divergences:\x20'+o['map'](q=>'['+q['item']+']\x20'+q['detail']+'\x20→\x20'+q['action'])['join']('\x20|\x20')+'.\x20Fix\x20the\x20template\x20by\x20declaring\x20allocator.rows\x20(one\x20row\x20per\x20sharing\x20entry,\x20including\x20the\x20'+'refund\x20track).\x20If\x20the\x20template\x20is\x20already\x20correct\x20on\x20disk\x20but\x20the\x20running\x20build\x20predates\x20'+'it,\x20run\x20industry_pack_operation\x20action=\x27repair_builtin_templates\x27\x20(and\x20'+'action=\x27template_drift\x27\x20to\x20diagnose)\x20first.');}l['template']={'id':a['id'],'archetype':a['archetype'],'recommended_role':a['recommended_role'],'fee_params':d};if(c&&Object['keys'](c)['length']>0x0)l['template_fee_overrides']=c;return l;}export async function handleBenchmarkMigrationOperation(a){const b=strictParse(BenchmarkMigrationSchema,a,'benchmark_migration_operation\x20input'),c=b['industry']?resolveIndustryName(b['industry'])??b['industry']['toLowerCase']():undefined;let d;switch(b['action']){case'template_list':{const {templates:e,errors:f}=listTemplates(),g=c?e['filter'](h=>h['industry']===c):e;d={'action':'template_list','count':g['length'],'templates':g['map'](templateSummary),'load_errors':f};break;}case'template_get':{const h=requireTemplate(b['template_id'],'template_get');d={'action':'template_get','template':{...h}};break;}case'template_generate':{const i=requireTemplate(b['template_id'],'template_generate'),j=scanTemplate(i);assertScanPassed(j,'template_generate');const k=await runGuide(i,b['description'],b['fee_overrides']);d={'action':'template_generate','template_id':i['id'],'scan':scanSummary(j),'plan':k};break;}case'template_scan':{const l=requireTemplate(b['template_id'],'template_scan');d={'action':'template_scan','scan':scanTemplate(l)};break;}case'migration_import':{if(!b['description']||!b['description']['trim']())throw new Error('\x27description\x27\x20is\x20required\x20for\x20action=\x27migration_import\x27');const m=planMigration({'url':b['url'],'description':b['description'],'industry':c,'network':b['network']});if(!m)throw new Error('No\x20industry\x20template\x20matched\x20the\x20description.\x20Refine\x20the\x20description\x20or\x20pass\x20an\x20explicit\x20\x27industry\x27\x20hint.');d={'action':'migration_import','log':m};break;}case'migration_review':{if(!b['log'])throw new Error('\x27log\x27\x20is\x20required\x20for\x20action=\x27migration_review\x27');const n=b['log'],o=Array['isArray'](n['mapped'])?n['mapped']:[],p=Array['isArray'](n['unmapped'])?n['unmapped']:[],q=Array['isArray'](n['manual_review'])?n['manual_review']:[],r=n['risk_check']??{};d={'action':'migration_review','log':n,'review_summary':{'mapped_count':o['length'],'unmapped_count':p['length'],'manual_review_count':q['length'],'risk_passed':r['passed']===!![]}};break;}case'migration_apply':{const s=requireTemplate(b['template_id'],'migration_apply'),t=scanTemplate(s);assertScanPassed(t,'migration_apply');const u=b['network']??'testnet',v=await runGuide(s,b['description'],b['fee_overrides']);d={'action':'migration_apply','template_id':s['id'],'network':u,'scan':scanSummary(t),'plan':v};break;}default:throw new Error('Unknown\x20benchmark_migration_operation\x20action:\x20'+String(b['action']));}return{'content':[{'type':'text','text':JSON['stringify']({'result':d})}],'structuredContent':{'result':d}};}