@wowok/agent-mcp 2.7.1 → 2.7.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (597) hide show
  1. package/dist/config/index.js +1 -1
  2. package/dist/config/runtime.js +1 -238
  3. package/dist/customer/account-events.d.ts +32 -0
  4. package/dist/customer/account-events.js +1 -0
  5. package/dist/customer/customer-advice.d.ts +1 -0
  6. package/dist/customer/customer-advice.js +1 -130
  7. package/dist/customer/index.js +1 -11
  8. package/dist/customer/industry-risks.js +1 -438
  9. package/dist/customer/info-puzzle.js +1 -681
  10. package/dist/customer/order-monitor.js +1 -328
  11. package/dist/customer/order-strategy.d.ts +1 -1
  12. package/dist/customer/order-strategy.js +1 -373
  13. package/dist/customer/post-purchase.js +1 -351
  14. package/dist/customer/preorder-compare.js +1 -34
  15. package/dist/customer/reminder-system.d.ts +2 -0
  16. package/dist/customer/reminder-system.js +1 -316
  17. package/dist/customer/risk-assessment.d.ts +1 -0
  18. package/dist/customer/risk-assessment.js +1 -397
  19. package/dist/customer/types.d.ts +2 -0
  20. package/dist/customer/types.js +1 -13
  21. package/dist/customer/user-preferences.js +1 -460
  22. package/dist/evaluation/arbitration-game.d.ts +9 -2
  23. package/dist/evaluation/arbitration-game.js +1 -48
  24. package/dist/evaluation/builtins/arbitration-score.d.ts +41 -0
  25. package/dist/evaluation/builtins/arbitration-score.js +1 -0
  26. package/dist/evaluation/builtins/demand-match.js +1 -153
  27. package/dist/evaluation/builtins/index.d.ts +1 -0
  28. package/dist/evaluation/builtins/index.js +1 -10
  29. package/dist/evaluation/builtins/service-risk.js +1 -55
  30. package/dist/evaluation/capability.js +1 -13
  31. package/dist/evaluation/category-match-rules.d.ts +30 -0
  32. package/dist/evaluation/category-match-rules.js +1 -0
  33. package/dist/evaluation/composer.js +1 -40
  34. package/dist/evaluation/engine.js +1 -175
  35. package/dist/evaluation/extract.js +1 -115
  36. package/dist/evaluation/game-strategy.d.ts +27 -0
  37. package/dist/evaluation/game-strategy.js +1 -0
  38. package/dist/evaluation/gap.js +1 -100
  39. package/dist/evaluation/index.d.ts +2 -0
  40. package/dist/evaluation/index.js +1 -11
  41. package/dist/evaluation/location-match.d.ts +42 -0
  42. package/dist/evaluation/location-match.js +1 -0
  43. package/dist/evaluation/node-game.d.ts +31 -3
  44. package/dist/evaluation/node-game.js +1 -57
  45. package/dist/evaluation/path-reasoning.d.ts +35 -0
  46. package/dist/evaluation/path-reasoning.js +1 -0
  47. package/dist/evaluation/region.d.ts +6 -0
  48. package/dist/evaluation/region.js +1 -36
  49. package/dist/evaluation/types.d.ts +18 -0
  50. package/dist/evaluation/types.js +1 -1
  51. package/dist/evaluation/user-injection.js +1 -27
  52. package/dist/experience/experience-reuse.js +1 -103
  53. package/dist/experience/index.js +1 -5
  54. package/dist/experience/intent-distill.js +1 -83
  55. package/dist/experience/realtime-feedback.js +1 -94
  56. package/dist/experience/types.js +1 -1
  57. package/dist/experience/user-profile.d.ts +1 -1
  58. package/dist/experience/user-profile.js +1 -171
  59. package/dist/extensions/business-modules.js +1 -287
  60. package/dist/extensions/capability-manifest.js +1 -781
  61. package/dist/extensions/constraint-registry.js +1 -198
  62. package/dist/extensions/index.d.ts +6 -0
  63. package/dist/extensions/index.js +1 -6
  64. package/dist/extensions/industry-layers.d.ts +75 -0
  65. package/dist/extensions/industry-layers.js +1 -0
  66. package/dist/extensions/industry-pack.d.ts +105 -0
  67. package/dist/extensions/industry-pack.js +1 -0
  68. package/dist/extensions/metric-registry.js +1 -257
  69. package/dist/extensions/mode-evaluator.d.ts +1 -1
  70. package/dist/extensions/mode-evaluator.js +1 -170
  71. package/dist/extensions/modes.js +1 -499
  72. package/dist/extensions/registry.d.ts +1 -0
  73. package/dist/extensions/registry.js +1 -717
  74. package/dist/extensions/types.js +1 -1
  75. package/dist/graph/base.d.ts +8 -0
  76. package/dist/graph/base.js +1 -0
  77. package/dist/harness/auto-escalation.js +1 -68
  78. package/dist/harness/checkpoint.js +1 -129
  79. package/dist/harness/index.d.ts +1 -0
  80. package/dist/harness/index.js +1 -78
  81. package/dist/harness/plan.d.ts +2 -0
  82. package/dist/harness/plan.js +1 -315
  83. package/dist/harness/recover.d.ts +1 -1
  84. package/dist/harness/recover.js +1 -139
  85. package/dist/harness/types.d.ts +2 -3
  86. package/dist/harness/types.js +1 -1
  87. package/dist/harness/verify.js +1 -237
  88. package/dist/index.js +1 -273
  89. package/dist/intent/enrich.js +1 -67
  90. package/dist/intent/index.js +1 -60
  91. package/dist/intent/matcher.js +1 -81
  92. package/dist/intent/store.js +1 -55
  93. package/dist/intent/types.js +1 -10
  94. package/dist/knowledge/acquisition-flywheel.js +1 -192
  95. package/dist/knowledge/allocation-confirm.js +1 -534
  96. package/dist/knowledge/allocation-context.js +1 -249
  97. package/dist/knowledge/allocation-ledger.js +1 -463
  98. package/dist/knowledge/allocation-puzzle.js +1 -298
  99. package/dist/knowledge/allocation-risk.js +1 -568
  100. package/dist/knowledge/allocation-templates.js +1 -970
  101. package/dist/knowledge/allocation-translation.js +1 -585
  102. package/dist/knowledge/anti-cheat.d.ts +37 -0
  103. package/dist/knowledge/anti-cheat.js +1 -0
  104. package/dist/knowledge/arb-confirm.d.ts +28 -0
  105. package/dist/knowledge/arb-confirm.js +1 -0
  106. package/dist/knowledge/arb-risk.js +1 -210
  107. package/dist/knowledge/arb-translation.d.ts +48 -0
  108. package/dist/knowledge/arb-translation.js +1 -0
  109. package/dist/knowledge/arbitration-confirm.js +1 -559
  110. package/dist/knowledge/arbitration-context.js +1 -505
  111. package/dist/knowledge/arbitration-ledger.js +1 -521
  112. package/dist/knowledge/arbitration-puzzle.js +1 -304
  113. package/dist/knowledge/arbitration-risk.js +1 -423
  114. package/dist/knowledge/arbitration-templates.js +1 -276
  115. package/dist/knowledge/arbitration-translation.js +1 -487
  116. package/dist/knowledge/audit-rules.js +1 -141
  117. package/dist/knowledge/bridge-confirm.d.ts +26 -0
  118. package/dist/knowledge/bridge-confirm.js +1 -0
  119. package/dist/knowledge/bridge-risk.js +1 -263
  120. package/dist/knowledge/bridge-translation.d.ts +37 -0
  121. package/dist/knowledge/bridge-translation.js +1 -0
  122. package/dist/knowledge/contact-confirm.d.ts +27 -0
  123. package/dist/knowledge/contact-confirm.js +1 -0
  124. package/dist/knowledge/contact-risk.js +1 -200
  125. package/dist/knowledge/contact-templates.js +1 -60
  126. package/dist/knowledge/contact-translation.d.ts +39 -0
  127. package/dist/knowledge/contact-translation.js +1 -0
  128. package/dist/knowledge/demand-confirm.js +1 -206
  129. package/dist/knowledge/demand-context.d.ts +17 -0
  130. package/dist/knowledge/demand-context.js +1 -0
  131. package/dist/knowledge/demand-ledger.d.ts +26 -0
  132. package/dist/knowledge/demand-ledger.js +1 -0
  133. package/dist/knowledge/demand-matching.js +1 -132
  134. package/dist/knowledge/demand-puzzle.d.ts +29 -0
  135. package/dist/knowledge/demand-puzzle.js +1 -0
  136. package/dist/knowledge/demand-risk.js +1 -240
  137. package/dist/knowledge/demand-templates.d.ts +12 -0
  138. package/dist/knowledge/demand-templates.js +1 -0
  139. package/dist/knowledge/demand-translation.js +1 -354
  140. package/dist/knowledge/deployment-scanner.js +1 -823
  141. package/dist/knowledge/dynamic-pricing.js +1 -87
  142. package/dist/knowledge/evidence-review.d.ts +12 -0
  143. package/dist/knowledge/evidence-review.js +1 -0
  144. package/dist/knowledge/examples-scanner-cli.js +1 -26
  145. package/dist/knowledge/examples-scanner.js +1 -843
  146. package/dist/knowledge/flywheel-loop.d.ts +0 -1
  147. package/dist/knowledge/flywheel-loop.js +1 -404
  148. package/dist/knowledge/fund-layer.js +1 -973
  149. package/dist/knowledge/glossary.js +1 -211
  150. package/dist/knowledge/guard-confirm.js +1 -406
  151. package/dist/knowledge/guard-context.js +1 -287
  152. package/dist/knowledge/guard-design-patterns.js +1 -360
  153. package/dist/knowledge/guard-ledger.js +1 -260
  154. package/dist/knowledge/guard-lint.js +1 -670
  155. package/dist/knowledge/guard-migration.d.ts +1 -1
  156. package/dist/knowledge/guard-migration.js +1 -228
  157. package/dist/knowledge/guard-puzzle.js +1 -805
  158. package/dist/knowledge/guard-render.js +1 -700
  159. package/dist/knowledge/guard-risk.js +1 -1879
  160. package/dist/knowledge/guard-submission-prompt.js +1 -171
  161. package/dist/knowledge/guard-templates.js +1 -1105
  162. package/dist/knowledge/guard-translation.js +1 -1119
  163. package/dist/knowledge/index.d.ts +71 -3
  164. package/dist/knowledge/index.js +1 -436
  165. package/dist/knowledge/industry-evolution.js +1 -323
  166. package/dist/knowledge/industry-generalizer.js +1 -381
  167. package/dist/knowledge/industry-registry.js +1 -174
  168. package/dist/knowledge/intent-metrics.d.ts +4 -3
  169. package/dist/knowledge/intent-metrics.js +1 -566
  170. package/dist/knowledge/machine-confirm.js +1 -559
  171. package/dist/knowledge/machine-context.js +1 -833
  172. package/dist/knowledge/machine-ledger.js +1 -338
  173. package/dist/knowledge/machine-puzzle.js +1 -494
  174. package/dist/knowledge/machine-render.js +1 -565
  175. package/dist/knowledge/machine-risk.js +1 -669
  176. package/dist/knowledge/machine-templates.js +1 -1597
  177. package/dist/knowledge/machine-topology.js +1 -234
  178. package/dist/knowledge/machine-translation.js +1 -513
  179. package/dist/knowledge/market-metrics.d.ts +12 -0
  180. package/dist/knowledge/market-metrics.js +1 -0
  181. package/dist/knowledge/market-operations.d.ts +46 -0
  182. package/dist/knowledge/market-operations.js +1 -0
  183. package/dist/knowledge/mcp-schema-audit-cli.js +1 -45
  184. package/dist/knowledge/mcp-schema-audit.d.ts +22 -22
  185. package/dist/knowledge/mcp-schema-audit.js +1 -777
  186. package/dist/knowledge/onchain-constants.js +1 -35
  187. package/dist/knowledge/order-confirm.js +1 -573
  188. package/dist/knowledge/order-context.js +1 -390
  189. package/dist/knowledge/order-ledger.js +1 -341
  190. package/dist/knowledge/order-puzzle.js +1 -255
  191. package/dist/knowledge/order-risk.js +1 -653
  192. package/dist/knowledge/order-templates.js +1 -368
  193. package/dist/knowledge/order-translation.js +1 -550
  194. package/dist/knowledge/overrides-loader.js +1 -65
  195. package/dist/knowledge/passport-confirm.js +1 -531
  196. package/dist/knowledge/passport-context.js +1 -306
  197. package/dist/knowledge/passport-ledger.js +1 -282
  198. package/dist/knowledge/passport-puzzle.js +1 -333
  199. package/dist/knowledge/passport-risk.js +1 -450
  200. package/dist/knowledge/passport-templates.js +1 -568
  201. package/dist/knowledge/passport-translation.js +1 -516
  202. package/dist/knowledge/payment-confirm.d.ts +26 -0
  203. package/dist/knowledge/payment-confirm.js +1 -0
  204. package/dist/knowledge/payment-risk.js +1 -249
  205. package/dist/knowledge/payment-translation.d.ts +37 -0
  206. package/dist/knowledge/payment-translation.js +1 -0
  207. package/dist/knowledge/permission-confirm.js +1 -426
  208. package/dist/knowledge/permission-context.js +1 -224
  209. package/dist/knowledge/permission-ledger.d.ts +11 -0
  210. package/dist/knowledge/permission-ledger.js +1 -403
  211. package/dist/knowledge/permission-puzzle.js +1 -173
  212. package/dist/knowledge/permission-risk.js +1 -411
  213. package/dist/knowledge/permission-templates.js +1 -234
  214. package/dist/knowledge/permission-translation.js +1 -350
  215. package/dist/knowledge/personal-confirm.d.ts +29 -0
  216. package/dist/knowledge/personal-confirm.js +1 -0
  217. package/dist/knowledge/personal-risk.js +1 -212
  218. package/dist/knowledge/personal-translation.d.ts +37 -0
  219. package/dist/knowledge/personal-translation.js +1 -0
  220. package/dist/knowledge/process-model.d.ts +1 -11
  221. package/dist/knowledge/process-model.js +1 -160
  222. package/dist/knowledge/progress-confirm.js +1 -456
  223. package/dist/knowledge/progress-context.js +1 -452
  224. package/dist/knowledge/progress-ledger.js +1 -330
  225. package/dist/knowledge/progress-puzzle.js +1 -219
  226. package/dist/knowledge/progress-risk.js +1 -461
  227. package/dist/knowledge/progress-templates.js +1 -228
  228. package/dist/knowledge/progress-translation.js +1 -405
  229. package/dist/knowledge/proof-confirm.js +1 -187
  230. package/dist/knowledge/proof-context.d.ts +17 -0
  231. package/dist/knowledge/proof-context.js +1 -0
  232. package/dist/knowledge/proof-ledger.d.ts +34 -0
  233. package/dist/knowledge/proof-ledger.js +1 -0
  234. package/dist/knowledge/proof-puzzle.d.ts +35 -0
  235. package/dist/knowledge/proof-puzzle.js +1 -0
  236. package/dist/knowledge/proof-risk.js +1 -207
  237. package/dist/knowledge/proof-templates.d.ts +22 -0
  238. package/dist/knowledge/proof-templates.js +1 -0
  239. package/dist/knowledge/proof-translation.js +1 -283
  240. package/dist/knowledge/registrar-confirm.d.ts +26 -0
  241. package/dist/knowledge/registrar-confirm.js +1 -0
  242. package/dist/knowledge/registrar-risk.js +1 -217
  243. package/dist/knowledge/registrar-translation.d.ts +37 -0
  244. package/dist/knowledge/registrar-translation.js +1 -0
  245. package/dist/knowledge/repository-confirm.js +1 -286
  246. package/dist/knowledge/repository-context.d.ts +12 -0
  247. package/dist/knowledge/repository-context.js +1 -0
  248. package/dist/knowledge/repository-ledger.d.ts +25 -0
  249. package/dist/knowledge/repository-ledger.js +1 -0
  250. package/dist/knowledge/repository-puzzle.d.ts +30 -0
  251. package/dist/knowledge/repository-puzzle.js +1 -0
  252. package/dist/knowledge/repository-risk.js +1 -373
  253. package/dist/knowledge/repository-templates.d.ts +14 -0
  254. package/dist/knowledge/repository-templates.js +1 -0
  255. package/dist/knowledge/repository-translation.js +1 -445
  256. package/dist/knowledge/reputation-rules.js +1 -99
  257. package/dist/knowledge/resource-confirm.d.ts +25 -0
  258. package/dist/knowledge/resource-confirm.js +1 -0
  259. package/dist/knowledge/resource-risk.js +1 -157
  260. package/dist/knowledge/resource-translation.d.ts +37 -0
  261. package/dist/knowledge/resource-translation.js +1 -0
  262. package/dist/knowledge/reward-confirm.js +1 -526
  263. package/dist/knowledge/reward-context.d.ts +2 -2
  264. package/dist/knowledge/reward-context.js +1 -504
  265. package/dist/knowledge/reward-ledger.js +1 -502
  266. package/dist/knowledge/reward-puzzle.js +1 -300
  267. package/dist/knowledge/reward-risk.js +1 -627
  268. package/dist/knowledge/reward-templates.js +1 -197
  269. package/dist/knowledge/reward-translation.js +1 -501
  270. package/dist/knowledge/safety-rules.d.ts +1 -0
  271. package/dist/knowledge/safety-rules.js +1 -404
  272. package/dist/knowledge/scenario-modes.js +1 -321
  273. package/dist/knowledge/service-confirm.js +1 -807
  274. package/dist/knowledge/service-context.js +1 -403
  275. package/dist/knowledge/service-ledger.js +1 -609
  276. package/dist/knowledge/service-puzzle.js +1 -236
  277. package/dist/knowledge/service-risk.d.ts +1 -1
  278. package/dist/knowledge/service-risk.js +1 -651
  279. package/dist/knowledge/service-templates.js +1 -456
  280. package/dist/knowledge/service-translation.js +1 -622
  281. package/dist/knowledge/template-registry.js +1 -353
  282. package/dist/knowledge/tool-constraints.js +1 -195
  283. package/dist/knowledge/tools-reference.js +1 -178
  284. package/dist/knowledge/treasury-confirm.js +1 -512
  285. package/dist/knowledge/treasury-context.js +1 -363
  286. package/dist/knowledge/treasury-ledger.js +1 -300
  287. package/dist/knowledge/treasury-puzzle.js +1 -216
  288. package/dist/knowledge/treasury-risk.js +1 -440
  289. package/dist/knowledge/treasury-templates.js +1 -358
  290. package/dist/knowledge/treasury-translation.js +1 -498
  291. package/dist/knowledge/trust-metrics.js +1 -198
  292. package/dist/knowledge/universal-template.d.ts +22 -0
  293. package/dist/knowledge/universal-template.js +1 -0
  294. package/dist/knowledge/util-confirm.d.ts +24 -0
  295. package/dist/knowledge/util-confirm.js +1 -0
  296. package/dist/knowledge/util-risk.js +1 -135
  297. package/dist/knowledge/util-translation.d.ts +38 -0
  298. package/dist/knowledge/util-translation.js +1 -0
  299. package/dist/knowledge/workflow-guidance.d.ts +116 -0
  300. package/dist/knowledge/workflow-guidance.js +1 -0
  301. package/dist/loop-engineering/aggregate.js +1 -132
  302. package/dist/loop-engineering/context-collect.js +1 -83
  303. package/dist/loop-engineering/diagnose.js +1 -273
  304. package/dist/loop-engineering/improve.js +1 -405
  305. package/dist/loop-engineering/index.js +1 -4
  306. package/dist/loop-engineering/pipeline.js +1 -56
  307. package/dist/mode-market/index.js +1 -3
  308. package/dist/mode-market/registry.js +1 -124
  309. package/dist/mode-market/review.js +1 -214
  310. package/dist/mode-market/submission.js +1 -85
  311. package/dist/participation/collaborator-interest.d.ts +23 -0
  312. package/dist/participation/collaborator-interest.js +1 -0
  313. package/dist/participation/customer-interest.d.ts +25 -0
  314. package/dist/participation/customer-interest.js +1 -0
  315. package/dist/participation/employee-kpi.d.ts +25 -0
  316. package/dist/participation/employee-kpi.js +1 -0
  317. package/dist/participation/employee-store.d.ts +16 -0
  318. package/dist/participation/employee-store.js +1 -0
  319. package/dist/participation/index.d.ts +2 -0
  320. package/dist/participation/index.js +1 -0
  321. package/dist/participation/merchant-interest.js +1 -100
  322. package/dist/participation/radar-core.d.ts +13 -3
  323. package/dist/participation/radar-core.js +1 -269
  324. package/dist/participation/supplier-interest.d.ts +25 -0
  325. package/dist/participation/supplier-interest.js +1 -0
  326. package/dist/persona/analyzer.js +1 -66
  327. package/dist/persona/bridge.js +1 -86
  328. package/dist/persona/defaults.js +1 -195
  329. package/dist/persona/experience-bridge.js +1 -23
  330. package/dist/persona/index.d.ts +9 -2
  331. package/dist/persona/index.js +1 -71
  332. package/dist/persona/local-region.d.ts +20 -0
  333. package/dist/persona/local-region.js +1 -0
  334. package/dist/persona/model.js +1 -111
  335. package/dist/persona/overrides.d.ts +10 -0
  336. package/dist/persona/overrides.js +1 -0
  337. package/dist/persona/pack-personae.d.ts +11 -0
  338. package/dist/persona/pack-personae.js +1 -0
  339. package/dist/persona/store.js +1 -62
  340. package/dist/persona/strategy-intent.d.ts +20 -0
  341. package/dist/persona/strategy-intent.js +1 -0
  342. package/dist/persona/types.d.ts +6 -2
  343. package/dist/persona/types.js +1 -5
  344. package/dist/project/business-puzzle.d.ts +1 -1
  345. package/dist/project/business-puzzle.js +1 -383
  346. package/dist/project/context-assembly.js +1 -254
  347. package/dist/project/deployment-bridge.js +1 -120
  348. package/dist/project/deployment-doc.js +1 -1126
  349. package/dist/project/edit-planner.js +1 -1342
  350. package/dist/project/evaluation.d.ts +37 -1
  351. package/dist/project/evaluation.js +1 -2011
  352. package/dist/project/game-theory.js +1 -177
  353. package/dist/project/graph-builder.js +1 -656
  354. package/dist/project/graph.d.ts +3 -6
  355. package/dist/project/graph.js +1 -340
  356. package/dist/project/handlers.d.ts +33 -2
  357. package/dist/project/handlers.js +1 -1784
  358. package/dist/project/index.d.ts +2 -0
  359. package/dist/project/index.js +1 -301
  360. package/dist/project/intent-analyzer.js +1 -149
  361. package/dist/project/machine-nodes.js +1 -36
  362. package/dist/project/merchant-guide.d.ts +19 -0
  363. package/dist/project/merchant-guide.js +1 -264
  364. package/dist/project/migration.js +1 -125
  365. package/dist/project/mode-actions.js +1 -309
  366. package/dist/project/namespace.js +1 -206
  367. package/dist/project/participation-radar.js +1 -428
  368. package/dist/project/pipeline-actions.js +1 -109
  369. package/dist/project/project-store.js +1 -422
  370. package/dist/project/query.js +1 -153
  371. package/dist/project/reverse-mapping.d.ts +34 -0
  372. package/dist/project/reverse-mapping.js +1 -0
  373. package/dist/project/risk-aggregator.js +1 -295
  374. package/dist/project/rollback-policy.js +1 -290
  375. package/dist/project/semantic-assembler.js +1 -345
  376. package/dist/project/semantic-graph.d.ts +3 -5
  377. package/dist/project/semantic-graph.js +1 -292
  378. package/dist/project/stage-gate.js +1 -369
  379. package/dist/project/substep-trace.js +1 -332
  380. package/dist/project/task-tracker.js +1 -78
  381. package/dist/project/workflow-design-assessment.d.ts +24 -0
  382. package/dist/project/workflow-design-assessment.js +1 -0
  383. package/dist/role/derivation.d.ts +18 -0
  384. package/dist/role/derivation.js +1 -0
  385. package/dist/role/index.d.ts +5 -0
  386. package/dist/role/index.js +1 -0
  387. package/dist/role/model.d.ts +8 -0
  388. package/dist/role/model.js +1 -0
  389. package/dist/role/resolution.d.ts +11 -0
  390. package/dist/role/resolution.js +1 -0
  391. package/dist/role/types.d.ts +11 -0
  392. package/dist/role/types.js +1 -0
  393. package/dist/rules.js +1 -52
  394. package/dist/safety/confirm-gate.d.ts +1 -1
  395. package/dist/safety/confirm-gate.js +1 -88
  396. package/dist/safety/index.js +1 -3
  397. package/dist/safety/preview.js +1 -52
  398. package/dist/schema/call/allocation.d.ts +186 -1385
  399. package/dist/schema/call/allocation.js +1 -34
  400. package/dist/schema/call/arbitration.d.ts +272 -1871
  401. package/dist/schema/call/arbitration.js +1 -113
  402. package/dist/schema/call/base.d.ts +1831 -9076
  403. package/dist/schema/call/base.js +1 -370
  404. package/dist/schema/call/bridge.d.ts +911 -3171
  405. package/dist/schema/call/bridge.js +1 -458
  406. package/dist/schema/call/contact.d.ts +135 -931
  407. package/dist/schema/call/contact.js +1 -37
  408. package/dist/schema/call/demand.d.ts +164 -1194
  409. package/dist/schema/call/demand.js +1 -47
  410. package/dist/schema/call/guard.d.ts +298 -1140
  411. package/dist/schema/call/guard.js +1 -161
  412. package/dist/schema/call/handler.js +1 -322
  413. package/dist/schema/call/index.js +1 -20
  414. package/dist/schema/call/machine.d.ts +459 -5403
  415. package/dist/schema/call/machine.js +1 -193
  416. package/dist/schema/call/order.d.ts +137 -844
  417. package/dist/schema/call/order.js +1 -35
  418. package/dist/schema/call/payment.d.ts +74 -561
  419. package/dist/schema/call/payment.js +1 -37
  420. package/dist/schema/call/permission-handler.js +1 -54
  421. package/dist/schema/call/permission.d.ts +335 -2791
  422. package/dist/schema/call/permission.js +1 -105
  423. package/dist/schema/call/personal.d.ts +227 -1814
  424. package/dist/schema/call/personal.js +1 -78
  425. package/dist/schema/call/progress.d.ts +140 -843
  426. package/dist/schema/call/progress.js +1 -47
  427. package/dist/schema/call/proof.d.ts +42 -258
  428. package/dist/schema/call/proof.js +1 -33
  429. package/dist/schema/call/repository.d.ts +324 -2222
  430. package/dist/schema/call/repository.js +1 -77
  431. package/dist/schema/call/reward.d.ts +153 -1183
  432. package/dist/schema/call/reward.js +1 -30
  433. package/dist/schema/call/semantic.js +1 -1679
  434. package/dist/schema/call/service.d.ts +376 -3431
  435. package/dist/schema/call/service.js +1 -184
  436. package/dist/schema/call/treasury.d.ts +252 -2158
  437. package/dist/schema/call/treasury.js +1 -71
  438. package/dist/schema/common/index.d.ts +222 -697
  439. package/dist/schema/common/index.js +1 -407
  440. package/dist/schema/config/index.d.ts +18 -161
  441. package/dist/schema/config/index.js +1 -68
  442. package/dist/schema/employee/index.d.ts +99 -0
  443. package/dist/schema/employee/index.js +1 -0
  444. package/dist/schema/evaluation/index.d.ts +1062 -3748
  445. package/dist/schema/evaluation/index.js +1 -356
  446. package/dist/schema/index.d.ts +3 -0
  447. package/dist/schema/index.js +1 -17
  448. package/dist/schema/industry-pack/index.d.ts +132 -0
  449. package/dist/schema/industry-pack/index.js +1 -0
  450. package/dist/schema/intent-radar/index.d.ts +92 -245
  451. package/dist/schema/intent-radar/index.js +1 -89
  452. package/dist/schema/local/index.d.ts +2045 -18080
  453. package/dist/schema/local/index.js +1 -927
  454. package/dist/schema/local/wip.d.ts +61 -651
  455. package/dist/schema/local/wip.js +1 -187
  456. package/dist/schema/messenger/index.d.ts +949 -5557
  457. package/dist/schema/messenger/index.js +1 -475
  458. package/dist/schema/operations.d.ts +2969 -26518
  459. package/dist/schema/operations.js +1 -520
  460. package/dist/schema/persona/index.d.ts +469 -1820
  461. package/dist/schema/persona/index.js +1 -148
  462. package/dist/schema/project/index.d.ts +1027 -8408
  463. package/dist/schema/project/index.js +1 -2057
  464. package/dist/schema/query/index.d.ts +12041 -75261
  465. package/dist/schema/query/index.js +1 -1646
  466. package/dist/schema/schema-query/index.d.ts +35 -98
  467. package/dist/schema/schema-query/index.js +1 -104
  468. package/dist/schema/schema-version.js +1 -76
  469. package/dist/schema/task-status.d.ts +26 -132
  470. package/dist/schema/task-status.js +1 -36
  471. package/dist/schema/trust/index.d.ts +194 -1290
  472. package/dist/schema/trust/index.js +1 -314
  473. package/dist/schema/utils/guard-parser.js +1 -419
  474. package/dist/schema/utils/guard-query-utils.js +1 -46
  475. package/dist/schema/utils/node-parser.js +1 -369
  476. package/dist/schema/utils/object-type-utils.js +1 -35
  477. package/dist/schema/utils/permission-index-utils.js +1 -7
  478. package/dist/schema/utils/permission-machine-check.js +1 -121
  479. package/dist/schema/utils/skills-recommendation.d.ts +1 -0
  480. package/dist/schema/utils/skills-recommendation.js +1 -77
  481. package/dist/schema/workspace/index.d.ts +69 -0
  482. package/dist/schema/workspace/index.js +1 -0
  483. package/dist/schema-query-impl/index.js +1 -0
  484. package/dist/schemas/account_operation.output.json +3147 -1652
  485. package/dist/schemas/account_operation.schema.json +225 -218
  486. package/dist/schemas/bridge_operation.output.json +1168 -650
  487. package/dist/schemas/bridge_operation.schema.json +736 -504
  488. package/dist/schemas/config_operation.output.json +185 -179
  489. package/dist/schemas/config_operation.schema.json +21 -26
  490. package/dist/schemas/employee_operation.output.json +207 -0
  491. package/dist/schemas/employee_operation.schema.json +176 -0
  492. package/dist/schemas/evaluation_operation.output.json +2329 -557
  493. package/dist/schemas/evaluation_operation.schema.json +2939 -720
  494. package/dist/schemas/guard2file.output.json +58 -64
  495. package/dist/schemas/guard2file.schema.json +79 -81
  496. package/dist/schemas/index.json +29 -11
  497. package/dist/schemas/industry_pack_operation.output.json +594 -0
  498. package/dist/schemas/industry_pack_operation.schema.json +55 -0
  499. package/dist/schemas/intent_radar.output.json +275 -200
  500. package/dist/schemas/intent_radar.schema.json +124 -123
  501. package/dist/schemas/local_info_operation.output.json +1174 -657
  502. package/dist/schemas/local_info_operation.schema.json +119 -125
  503. package/dist/schemas/local_mark_operation.output.json +1239 -689
  504. package/dist/schemas/local_mark_operation.schema.json +91 -96
  505. package/dist/schemas/machineNode2file.output.json +63 -69
  506. package/dist/schemas/machineNode2file.schema.json +79 -81
  507. package/dist/schemas/messenger_operation.output.json +2722 -1528
  508. package/dist/schemas/messenger_operation.schema.json +1482 -1264
  509. package/dist/schemas/onchain_events.output.json +2590 -975
  510. package/dist/schemas/onchain_events.schema.json +117 -99
  511. package/dist/schemas/onchain_operations.output.json +3957 -2309
  512. package/dist/schemas/onchain_operations.schema.json +20799 -9285
  513. package/dist/schemas/onchain_operations_allocation.schema.json +172 -108
  514. package/dist/schemas/onchain_operations_arbitration.schema.json +233 -146
  515. package/dist/schemas/onchain_operations_contact.schema.json +129 -90
  516. package/dist/schemas/onchain_operations_demand.schema.json +170 -112
  517. package/dist/schemas/onchain_operations_gen_passport.schema.json +61 -646
  518. package/dist/schemas/onchain_operations_gen_proof.schema.json +40 -172
  519. package/dist/schemas/onchain_operations_guard.schema.json +3765 -294
  520. package/dist/schemas/onchain_operations_machine.schema.json +537 -164
  521. package/dist/schemas/onchain_operations_order.schema.json +126 -96
  522. package/dist/schemas/onchain_operations_payment.schema.json +82 -67
  523. package/dist/schemas/onchain_operations_permission.schema.json +331 -93
  524. package/dist/schemas/onchain_operations_personal.schema.json +636 -96
  525. package/dist/schemas/onchain_operations_progress.schema.json +125 -92
  526. package/dist/schemas/onchain_operations_proof.schema.json +76 -69
  527. package/dist/schemas/onchain_operations_repository.schema.json +636 -249
  528. package/dist/schemas/onchain_operations_reward.schema.json +218 -108
  529. package/dist/schemas/onchain_operations_service.schema.json +679 -221
  530. package/dist/schemas/onchain_operations_treasury.schema.json +401 -135
  531. package/dist/schemas/onchain_table_data.output.json +6018 -2430
  532. package/dist/schemas/onchain_table_data.schema.json +544 -430
  533. package/dist/schemas/persona_operation.output.json +1568 -265
  534. package/dist/schemas/persona_operation.schema.json +346 -202
  535. package/dist/schemas/project_operation.output.json +6957 -5147
  536. package/dist/schemas/project_operation.schema.json +1050 -1020
  537. package/dist/schemas/query_task_status.output.json +195 -99
  538. package/dist/schemas/query_task_status.schema.json +12 -18
  539. package/dist/schemas/query_toolkit.output.json +18870 -14566
  540. package/dist/schemas/query_toolkit.schema.json +614 -522
  541. package/dist/schemas/schema_query.output.json +127 -129
  542. package/dist/schemas/schema_query.schema.json +64 -69
  543. package/dist/schemas/trust_score.output.json +678 -587
  544. package/dist/schemas/trust_score.schema.json +289 -277
  545. package/dist/schemas/wip_file.output.json +116 -124
  546. package/dist/schemas/wip_file.schema.json +142 -143
  547. package/dist/schemas/workspace_operation.output.json +277 -0
  548. package/dist/schemas/workspace_operation.schema.json +45 -0
  549. package/dist/schemas/wowok_buildin_info.output.json +1693 -723
  550. package/dist/schemas/wowok_buildin_info.schema.json +576 -512
  551. package/dist/telemetry/index.js +1 -112
  552. package/dist/telemetry/redact.js +1 -23
  553. package/dist/telemetry/storage.js +1 -80
  554. package/dist/tools/handlers/bridge.d.ts +8 -1
  555. package/dist/tools/handlers/bridge.js +1 -1
  556. package/dist/tools/handlers/config.js +1 -74
  557. package/dist/tools/handlers/employee.d.ts +2 -0
  558. package/dist/tools/handlers/employee.js +1 -0
  559. package/dist/tools/handlers/evaluation.js +1 -123
  560. package/dist/tools/handlers/file-export.js +1 -90
  561. package/dist/tools/handlers/industry-pack.d.ts +2 -0
  562. package/dist/tools/handlers/industry-pack.js +1 -0
  563. package/dist/tools/handlers/intent-radar.js +1 -76
  564. package/dist/tools/handlers/local.js +1 -53
  565. package/dist/tools/handlers/messenger.js +1 -188
  566. package/dist/tools/handlers/onchain.js +1 -1180
  567. package/dist/tools/handlers/persona.js +1 -89
  568. package/dist/tools/handlers/project.js +1 -211
  569. package/dist/tools/handlers/query.js +1 -434
  570. package/dist/tools/handlers/schema-query.js +1 -176
  571. package/dist/tools/handlers/task-status.js +1 -26
  572. package/dist/tools/handlers/trust.js +1 -380
  573. package/dist/tools/handlers/wip.js +1 -90
  574. package/dist/tools/handlers/workspace.d.ts +2 -0
  575. package/dist/tools/handlers/workspace.js +1 -0
  576. package/dist/tools/index.d.ts +2 -1
  577. package/dist/tools/index.js +1 -1382
  578. package/dist/tools/retry.js +1 -85
  579. package/dist/tools/rules-hook.d.ts +1 -1
  580. package/dist/tools/rules-hook.js +1 -23
  581. package/dist/tools/shared.d.ts +1 -1
  582. package/dist/tools/shared.js +1 -130
  583. package/dist/tools/types.d.ts +2 -1
  584. package/dist/tools/types.js +1 -1
  585. package/dist/tools/upgrade-check.d.ts +19 -0
  586. package/dist/tools/upgrade-check.js +1 -0
  587. package/dist/tools/wip-deploy-assist.js +1 -306
  588. package/dist/tools/wrap.js +1 -500
  589. package/package.json +7 -6
  590. package/dist/knowledge/arbitration-trust.d.ts +0 -24
  591. package/dist/knowledge/arbitration-trust.js +0 -117
  592. package/dist/schema/call/bridge-handler.d.ts +0 -8
  593. package/dist/schema/call/bridge-handler.js +0 -265
  594. package/dist/schema/sync-layer4.d.ts +0 -21
  595. package/dist/schema/sync-layer4.js +0 -286
  596. package/dist/schema-query/index.js +0 -810
  597. /package/dist/{schema-query → schema-query-impl}/index.d.ts +0 -0
@@ -1,777 +1 @@
1
- import * as fs from 'fs';
2
- import * as path from 'path';
3
- export const DEPLOYED_TOOLS_DIR = 'c:\\Users\\zhou\\.trae-cn\\mcps\\s_wowok-7838e181\\solo_agent\\mcp_wagent\\tools';
4
- export const GENERATED_SCHEMAS_DIR = 'd:\\wowok\\agent\\mcp\\dist\\schemas';
5
- export const MCP_SRC_SCHEMA_DIR = 'd:\\wowok\\agent\\mcp\\src\\schema';
6
- export const MCP_SRC_TOOLS_DIR = 'd:\\wowok\\agent\\mcp\\src\\tools';
7
- export const GENERATION_SCRIPT = 'd:\\wowok\\agent\\mcp\\scripts\\generate-json-schemas.ts';
8
- export const TOOLS_INDEX_FILE = 'd:\\wowok\\agent\\mcp\\src\\tools\\index.ts';
9
- export const MCP_SCHEMA_AUDIT_VERSION = '1.0.0';
10
- export const ALL_TOOLS = [
11
- { name: 'onchain_operations', input_schema_export: 'OnchainOperationsSchema', output_schema_export: 'CallOutputSchema' },
12
- { name: 'account_operation', input_schema_export: 'AccountOperationSchema', output_schema_export: 'AccountOperationOutputWrappedSchema' },
13
- { name: 'local_mark_operation', input_schema_export: 'LocalMarkOperationSchema', output_schema_export: 'LocalMarkOperationOutputWrappedSchema' },
14
- { name: 'local_info_operation', input_schema_export: 'LocalInfoOperationSchema', output_schema_export: 'LocalInfoOperationOutputWrappedSchema' },
15
- { name: 'wip_file', input_schema_export: 'WipOperationsSchema', output_schema_export: 'WipOperationOutputSchema' },
16
- { name: 'messenger_operation', input_schema_export: 'MessengerOperationInputSchema', output_schema_export: 'MessengerOperationOutputSchema' },
17
- { name: 'guard2file', input_schema_export: 'Guard2File_InputSchema', output_schema_export: 'Guard2File_OutputWrappedSchema' },
18
- { name: 'machineNode2file', input_schema_export: 'MachineNode2File_InputSchema', output_schema_export: 'MachineNode2File_OutputWrappedSchema' },
19
- { name: 'query_toolkit', input_schema_export: 'WatchQueryOperationsSchema', output_schema_export: 'WatchQueryOperationsResultSchema' },
20
- { name: 'onchain_table_data', input_schema_export: 'OnchainTableDataSchema', output_schema_export: 'OnchainTableDataResultSchema' },
21
- { name: 'onchain_events', input_schema_export: 'OnchainEventsInputSchema', output_schema_export: 'OnchainEventsResultSchema' },
22
- { name: 'wowok_buildin_info', input_schema_export: 'ProtocolInfoQuerySchema', output_schema_export: 'ProtocolInfoResultSchema' },
23
- { name: 'schema_query', input_schema_export: 'SchemaQueryInputSchema', output_schema_export: 'SchemaQueryOutputSchema' },
24
- { name: 'bridge_operation', input_schema_export: 'BridgeOperationsSchema', output_schema_export: 'BridgeCallOutputSchema' },
25
- { name: 'project_operation', input_schema_export: 'ProjectOperationInputSchema', output_schema_export: 'ProjectOperationOutputSchema' },
26
- { name: 'config_operation', input_schema_export: 'ConfigOperationInputSchema', output_schema_export: 'ConfigOperationOutputSchema' },
27
- { name: 'trust_score', input_schema_export: 'TrustScoreInputSchema', output_schema_export: 'TrustScoreOutputSchema' },
28
- { name: 'query_task_status', input_schema_export: 'QueryTaskStatusInputSchema', output_schema_export: 'QueryTaskStatusOutputSchema' },
29
- { name: 'evaluation_operation', input_schema_export: 'EvaluationOperationInputSchema', output_schema_export: 'EvaluationOperationOutputSchema' },
30
- { name: 'persona_operation', input_schema_export: 'PersonaOperationInputSchema', output_schema_export: 'PersonaOperationOutputSchema' },
31
- { name: 'intent_radar', input_schema_export: 'IntentRadarInputSchema', output_schema_export: 'IntentRadarOutputSchema' },
32
- ];
33
- export function loadLayer4Deployed(toolName) {
34
- const filePath = path.join(DEPLOYED_TOOLS_DIR, `${toolName}.json`);
35
- const fallback = {
36
- tool_descriptor_file: filePath,
37
- file_exists: false,
38
- is_stub: true,
39
- properties_count: 0,
40
- required_count: 0,
41
- has_schema_hint: false,
42
- has_additional_properties_false: false,
43
- has_dollar_schema: false,
44
- has_oneof: false,
45
- has_anyof: false,
46
- has_allof: false,
47
- union_count: 0,
48
- };
49
- if (!fs.existsSync(filePath))
50
- return fallback;
51
- try {
52
- const raw = fs.readFileSync(filePath, 'utf-8');
53
- const data = JSON.parse(raw);
54
- const args = data.arguments ?? {};
55
- const props = args.properties ?? {};
56
- const required = args.required ?? [];
57
- const propKeys = Object.keys(props);
58
- const oneOfArr = args.oneOf ?? [];
59
- const anyOfArr = args.anyOf ?? [];
60
- const allOfArr = args.allOf ?? [];
61
- const hasOneOf = oneOfArr.length > 0;
62
- const hasAnyOf = anyOfArr.length > 0;
63
- const hasAllOf = allOfArr.length > 0;
64
- const unionCount = oneOfArr.length + anyOfArr.length + allOfArr.length;
65
- const isStub = propKeys.length === 0 && unionCount === 0;
66
- const description = data.description ?? '';
67
- const hasSchemaHint = description.includes('schema_query');
68
- return {
69
- tool_descriptor_file: filePath,
70
- file_exists: true,
71
- is_stub: isStub,
72
- properties_count: propKeys.length,
73
- required_count: required.length,
74
- has_schema_hint: hasSchemaHint,
75
- has_additional_properties_false: args.additionalProperties === false,
76
- has_dollar_schema: !!args.$schema,
77
- has_oneof: hasOneOf,
78
- has_anyof: hasAnyOf,
79
- has_allof: hasAllOf,
80
- union_count: unionCount,
81
- };
82
- }
83
- catch {
84
- return fallback;
85
- }
86
- }
87
- export function loadLayer3Generated(toolName) {
88
- const inputPath = path.join(GENERATED_SCHEMAS_DIR, `${toolName}.schema.json`);
89
- const outputPath = path.join(GENERATED_SCHEMAS_DIR, `${toolName}.output.json`);
90
- const inputExists = fs.existsSync(inputPath);
91
- const outputExists = fs.existsSync(outputPath);
92
- const inputSize = inputExists ? fs.statSync(inputPath).size : 0;
93
- const outputSize = outputExists ? fs.statSync(outputPath).size : 0;
94
- return {
95
- input_schema_file: inputPath,
96
- output_schema_file: outputPath,
97
- input_exists: inputExists,
98
- output_exists: outputExists,
99
- input_size_bytes: inputSize,
100
- output_size_bytes: outputSize,
101
- };
102
- }
103
- export function analyzeLayerCensus() {
104
- const census = [];
105
- for (const tool of ALL_TOOLS) {
106
- census.push({
107
- name: tool.name,
108
- layer2_zod: {
109
- input_schema_export: tool.input_schema_export,
110
- output_schema_export: tool.output_schema_export,
111
- schema_dir: MCP_SRC_SCHEMA_DIR,
112
- },
113
- layer3_generated: loadLayer3Generated(tool.name),
114
- layer4_deployed: loadLayer4Deployed(tool.name) ?? {},
115
- });
116
- }
117
- return census;
118
- }
119
- export function analyzeDeployedStubInconsistency(census) {
120
- const findings = [];
121
- const stubs = [];
122
- const fullSchemas = [];
123
- for (const c of census) {
124
- if (!c.layer4_deployed.file_exists) {
125
- findings.push({
126
- rule_id: 'MCP-DEPLOY-001',
127
- severity: 'critical',
128
- category: 'stub_inconsistency',
129
- tool_name: c.name,
130
- description: `Layer 4 deployed file does not exist: ${c.layer4_deployed.tool_descriptor_file}`,
131
- location: c.layer4_deployed.tool_descriptor_file,
132
- fix: `Create ${c.name}.json in DEPLOYED_TOOLS_DIR matching the Layer 3 generated schema.`,
133
- });
134
- continue;
135
- }
136
- if (c.layer4_deployed.is_stub) {
137
- stubs.push(c);
138
- }
139
- else {
140
- fullSchemas.push(c);
141
- }
142
- }
143
- for (const c of stubs) {
144
- findings.push({
145
- rule_id: 'MCP-STUB-001',
146
- severity: 'high',
147
- category: 'stub_inconsistency',
148
- tool_name: c.name,
149
- description: `Layer 4 deployed file is a STUB (empty properties:{}) — LLM must call schema_query(action='get', name='${c.name}') to learn the parameter structure. This is inconsistent with the ${fullSchemas.length} tools that embed full schemas.`,
150
- location: c.layer4_deployed.tool_descriptor_file,
151
- fix: `Regenerate ${c.name}.json from dist/schemas/${c.name}.schema.json (resolve $ref, inline definitions, wrap as {name, description, arguments}).`,
152
- });
153
- if (!c.layer4_deployed.has_schema_hint) {
154
- findings.push({
155
- rule_id: 'MCP-STUB-003',
156
- severity: 'high',
157
- category: 'stub_inconsistency',
158
- tool_name: c.name,
159
- description: `Stub file is missing schema_query hint in description — the LLM has no way to discover the parameter structure. Description should mention schema_query(action='get', name='${c.name}').`,
160
- location: c.layer4_deployed.tool_descriptor_file,
161
- fix: `Add "💡 Schema hint: Use schema_query with action='get' and name='${c.name}' to retrieve the exact parameter schema before calling." to the description.`,
162
- });
163
- }
164
- }
165
- if (stubs.length > 0 && fullSchemas.length > 0) {
166
- findings.push({
167
- rule_id: 'MCP-STUB-002',
168
- severity: 'info',
169
- category: 'stub_inconsistency',
170
- tool_name: '(all)',
171
- description: `Layer 4 deployed files are INCONSISTENT: ${stubs.length} stubs + ${fullSchemas.length} full schemas. Stubs: ${stubs.map(s => s.name).join(', ')}. Full: ${fullSchemas.map(s => s.name).join(', ')}.`,
172
- fix: `Make all 17 files consistent — either (a) embed full schemas in all 17 (RECOMMENDED — gives LLM immediate access), or (b) keep all stubs and rely on schema_query (increases token cost + latency).`,
173
- });
174
- }
175
- return findings;
176
- }
177
- export function analyzeLayerParity(census) {
178
- const findings = [];
179
- for (const c of census) {
180
- if (!c.layer4_deployed.file_exists || c.layer4_deployed.is_stub)
181
- continue;
182
- if (!c.layer3_generated.input_exists) {
183
- findings.push({
184
- rule_id: 'MCP-PARITY-001',
185
- severity: 'critical',
186
- category: 'layer_parity',
187
- tool_name: c.name,
188
- description: `Layer 4 has full schema but Layer 3 generated file is missing: ${c.layer3_generated.input_schema_file}`,
189
- fix: `Run pnpm generate:schemas to regenerate Layer 3 from Zod source.`,
190
- });
191
- continue;
192
- }
193
- const l4 = readLayer4Arguments(c.name);
194
- const l3 = readLayer3ResolvedSchema(c.name);
195
- if (!l4 || !l3)
196
- continue;
197
- const l4Props = new Set(Object.keys(l4.properties ?? {}));
198
- const l3Props = new Set(Object.keys(l3.properties ?? {}));
199
- const missingInL4 = [...l3Props].filter(p => !l4Props.has(p));
200
- const extraInL4 = [...l4Props].filter(p => !l3Props.has(p));
201
- if (missingInL4.length > 0) {
202
- findings.push({
203
- rule_id: 'MCP-PARITY-002',
204
- severity: 'high',
205
- category: 'layer_parity',
206
- tool_name: c.name,
207
- description: `Layer 4 deployed schema is missing ${missingInL4.length} properties present in Layer 3 generated schema: ${missingInL4.join(', ')}`,
208
- location: c.layer4_deployed.tool_descriptor_file,
209
- fix: `Regenerate ${c.name}.json from dist/schemas/${c.name}.schema.json.`,
210
- });
211
- }
212
- if (extraInL4.length > 0) {
213
- findings.push({
214
- rule_id: 'MCP-PARITY-003',
215
- severity: 'medium',
216
- category: 'layer_parity',
217
- tool_name: c.name,
218
- description: `Layer 4 deployed schema has ${extraInL4.length} extra properties not in Layer 3: ${extraInL4.join(', ')}`,
219
- location: c.layer4_deployed.tool_descriptor_file,
220
- fix: `Regenerate ${c.name}.json from dist/schemas/${c.name}.schema.json.`,
221
- });
222
- }
223
- const l4Req = new Set(l4.required ?? []);
224
- const l3Req = new Set(l3.required ?? []);
225
- const reqMissing = [...l3Req].filter(r => !l4Req.has(r));
226
- const reqExtra = [...l4Req].filter(r => !l3Req.has(r));
227
- if (reqMissing.length > 0 || reqExtra.length > 0) {
228
- findings.push({
229
- rule_id: 'MCP-PARITY-004',
230
- severity: 'high',
231
- category: 'layer_parity',
232
- tool_name: c.name,
233
- description: `Layer 4 'required' array differs from Layer 3. Missing in L4: [${reqMissing.join(', ')}]. Extra in L4: [${reqExtra.join(', ')}].`,
234
- location: c.layer4_deployed.tool_descriptor_file,
235
- fix: `Sync 'required' array from Layer 3 to Layer 4.`,
236
- });
237
- }
238
- const l4AP = l4.additionalProperties;
239
- const l3AP = l3.additionalProperties;
240
- if (l4AP !== l3AP) {
241
- findings.push({
242
- rule_id: 'MCP-PARITY-005',
243
- severity: 'medium',
244
- category: 'layer_parity',
245
- tool_name: c.name,
246
- description: `Layer 4 'additionalProperties' (${JSON.stringify(l4AP)}) differs from Layer 3 (${JSON.stringify(l3AP)}).`,
247
- location: c.layer4_deployed.tool_descriptor_file,
248
- fix: `Sync 'additionalProperties' value.`,
249
- });
250
- }
251
- }
252
- return findings;
253
- }
254
- function readLayer4Arguments(toolName) {
255
- const filePath = path.join(DEPLOYED_TOOLS_DIR, `${toolName}.json`);
256
- try {
257
- const raw = fs.readFileSync(filePath, 'utf-8');
258
- const data = JSON.parse(raw);
259
- return data.arguments ?? null;
260
- }
261
- catch {
262
- return null;
263
- }
264
- }
265
- function readLayer3ResolvedSchema(toolName) {
266
- const filePath = path.join(GENERATED_SCHEMAS_DIR, `${toolName}.schema.json`);
267
- try {
268
- const raw = fs.readFileSync(filePath, 'utf-8');
269
- const data = JSON.parse(raw);
270
- if (data.$ref && data.$ref.startsWith('#/definitions/')) {
271
- const defName = data.$ref.slice('#/definitions/'.length);
272
- const def = data.definitions?.[defName];
273
- if (def && typeof def === 'object') {
274
- return def;
275
- }
276
- }
277
- return data;
278
- }
279
- catch {
280
- return null;
281
- }
282
- }
283
- export function analyzeAnyUnknownCensus() {
284
- const instances = [];
285
- const scanDirs = [MCP_SRC_SCHEMA_DIR, MCP_SRC_TOOLS_DIR];
286
- for (const dir of scanDirs) {
287
- const files = listTypeScriptFiles(dir);
288
- for (const file of files) {
289
- const lines = fs.readFileSync(file, 'utf-8').split('\n');
290
- for (let i = 0; i < lines.length; i++) {
291
- const line = lines[i];
292
- const trimmed = line.trim();
293
- if (trimmed.startsWith('//') || trimmed.startsWith('*'))
294
- continue;
295
- const patterns = [
296
- { regex: /z\.any\(\)/g, pattern: 'z.any()' },
297
- { regex: /z\.unknown\(\)/g, pattern: 'z.unknown()' },
298
- { regex: /args\s*:\s*any\b/g, pattern: 'args: any' },
299
- { regex: /Promise\s*<\s*any\s*>/g, pattern: 'Promise<any>' },
300
- { regex: /Record\s*<\s*string\s*,\s*any\s*>/g, pattern: 'Record<string, any>' },
301
- { regex: /\bas\s+any\b/g, pattern: 'as any' },
302
- ];
303
- for (const { regex, pattern } of patterns) {
304
- regex.lastIndex = 0;
305
- let m;
306
- while ((m = regex.exec(line)) !== null) {
307
- const category = categorizeAnyInstance(file, i + 1, line, pattern);
308
- instances.push({
309
- file,
310
- line: i + 1,
311
- code: trimmed.length > 120 ? trimmed.slice(0, 117) + '...' : trimmed,
312
- pattern,
313
- category: category.category,
314
- reason: category.reason,
315
- fix_suggestion: category.fix,
316
- });
317
- }
318
- }
319
- }
320
- }
321
- }
322
- return instances;
323
- }
324
- function listTypeScriptFiles(dir) {
325
- const result = [];
326
- if (!fs.existsSync(dir))
327
- return result;
328
- const entries = fs.readdirSync(dir, { withFileTypes: true });
329
- for (const entry of entries) {
330
- const fullPath = path.join(dir, entry.name);
331
- if (entry.isDirectory()) {
332
- if (entry.name === '__tests__' || entry.name === 'node_modules')
333
- continue;
334
- result.push(...listTypeScriptFiles(fullPath));
335
- }
336
- else if (entry.isFile() && entry.name.endsWith('.ts')) {
337
- result.push(fullPath);
338
- }
339
- }
340
- return result;
341
- }
342
- function categorizeAnyInstance(file, lineNum, line, pattern) {
343
- const fileName = path.basename(file);
344
- const trimmed = line.trim();
345
- if (pattern === 'z.any()' && /SemanticSummarySchema\s*=\s*z\.any\(\)/.test(trimmed)) {
346
- return {
347
- category: 'fixable',
348
- reason: 'Circular-dependency workaround for SemanticSummarySchema — can use z.lazy() or refactor to break the cycle.',
349
- fix: 'Define SemanticSummarySchema with z.lazy(() => SemanticSummarySchemaReal) or restructure imports to break the cycle.',
350
- };
351
- }
352
- if (pattern === 'z.any()' && /result\s*:\s*z\.any\(\)/.test(trimmed) && /[\\/]config[\\/]|[\\/]project[\\/]/.test(file)) {
353
- return {
354
- category: 'fixable',
355
- reason: `Result shape depends on action — can use z.discriminatedUnion('action', [...]) to type each action's result.`,
356
- fix: `Define discriminated union: z.discriminatedUnion('action', [z.object({action: z.literal('list'), result: ...}), ...]).`,
357
- };
358
- }
359
- if (pattern === 'z.unknown()' && /result\s*:\s*z\.unknown\(\)/.test(trimmed) && /index\.ts/.test(fileName)) {
360
- return {
361
- category: 'fixable',
362
- reason: 'query_toolkit output result depends on query_type — can use z.discriminatedUnion(\'query_type\', [...]).',
363
- fix: 'Define discriminated union: z.discriminatedUnion(\'query_type\', [z.object({query_type: z.literal(\'local_mark_list\'), result: z.array(MarkDataSchema)}), ...]).',
364
- };
365
- }
366
- if (pattern === 'z.any()' && /data\s*:\s*z\.any\(\)/.test(trimmed) && /[\\/]schema-query[\\/]/.test(file)) {
367
- return {
368
- category: 'fixable',
369
- reason: 'SchemaQuery output data depends on action — can use discriminated union by action.',
370
- fix: 'Define discriminated union: action=\'get\' returns JSON Schema, action=\'list\' returns array of items.',
371
- };
372
- }
373
- if (pattern === 'args: any' && /handlers[\\/]/.test(file)) {
374
- return {
375
- category: 'fixable',
376
- reason: 'Handler args can use `unknown` (forces runtime validation) or a typed input schema.',
377
- fix: 'Replace `args: any` with `args: unknown` and use strictParse(schema, args) at the top of the handler.',
378
- };
379
- }
380
- if (pattern === 'args: any' && /tools[\\/]index\.ts/.test(file)) {
381
- return {
382
- category: 'fixable',
383
- reason: 'dispatchToolCall args is `any` — can be `unknown` since each tool parses with its own schema.',
384
- fix: 'Change `args: any` to `args: unknown` in dispatchToolCall signature.',
385
- };
386
- }
387
- if (pattern === 'args: any' && /types\.ts/.test(fileName) && /handler/.test(trimmed)) {
388
- return {
389
- category: 'fixable',
390
- reason: 'ToolEntry.handler args is `any` — can be `unknown` (each handler parses with its own schema).',
391
- fix: 'Change `handler: (args: any) => ...` to `handler: (args: unknown) => ...`.',
392
- };
393
- }
394
- if (pattern === 'z.any()' && /claimReceipt|ethReceipt|wowReceipt/.test(trimmed)) {
395
- return {
396
- category: 'legitimate',
397
- reason: 'EVM transaction receipts have an externally-defined shape from viem/ethers — z.any() is acceptable (receipt is informational, not validated).',
398
- };
399
- }
400
- if (pattern === 'z.any()' && /content_raw/.test(trimmed)) {
401
- return {
402
- category: 'legitimate',
403
- reason: 'content_raw holds raw content for unknown object types — by definition untyped. z.any() is acceptable here.',
404
- };
405
- }
406
- if ((pattern === 'z.unknown()' || pattern === 'z.any()') && /parsedJson/.test(trimmed)) {
407
- return {
408
- category: 'legitimate',
409
- reason: 'Event parsedJson is arbitrary on-chain event data — z.record(z.string(), z.unknown()) is appropriate.',
410
- };
411
- }
412
- if (pattern === 'z.any()' && /key_value/.test(trimmed)) {
413
- return {
414
- category: 'fixable',
415
- reason: 'Repository key_value depends on key_type — could use discriminated union by key_type (string→z.string(), u64→z.bigint()/number, etc.).',
416
- fix: 'Define z.discriminatedUnion(\'key_type\', [...]) with each variant typed.',
417
- };
418
- }
419
- if (pattern === 'z.unknown()' && /data\s*:\s*z\.unknown\(\)/.test(trimmed) && /[\\/]bridge/.test(file)) {
420
- return {
421
- category: 'legitimate',
422
- reason: 'Bridge operation result data varies by operation_type — currently 9 different shapes. Discriminated union would be ideal but high refactor cost.',
423
- };
424
- }
425
- if (pattern === 'z.unknown()' && /adjusted_params/.test(trimmed)) {
426
- return {
427
- category: 'legitimate',
428
- reason: 'adjusted_params are free-form key-value pairs suggested by AI — z.record(z.string(), z.unknown()) is appropriate.',
429
- };
430
- }
431
- if (pattern === 'z.any()' && /object\s*:\s*z\.union.*z\.record\(z\.any\(\)/.test(trimmed)) {
432
- return {
433
- category: 'fixable',
434
- reason: 'Creation vs reference object union — z.record(z.any()) should be replaced with NamedObjectSchema (structured creation input).',
435
- fix: 'Replace z.record(z.any()) with NamedObjectSchema (already defined in base.ts).',
436
- };
437
- }
438
- if (pattern === 'z.any()' && /result\s*:\s*z\.any\(\)\.optional\(\)/.test(trimmed) && /[\\/]bridge/.test(file)) {
439
- return {
440
- category: 'legitimate',
441
- reason: 'Bridge result is operation-specific (manage_evm_rpc has different result per operation) — z.any().optional() is acceptable here.',
442
- };
443
- }
444
- if (pattern === 'Promise<any>' && /[\\/](wrap|shared)\.ts/.test(file)) {
445
- return {
446
- category: 'fixable',
447
- reason: 'Generic wrappers in wrap.ts/shared.ts use Promise<any> — could be made generic <T>.',
448
- fix: 'Replace `Promise<any>` with `Promise<ToolDispatchResult>` (the actual return shape).',
449
- };
450
- }
451
- if (pattern === 'Record<string, any>' && /types\.ts/.test(fileName) && /_meta|structuredContent/.test(trimmed)) {
452
- return {
453
- category: 'fixable',
454
- reason: 'ToolConfig._meta and ToolDispatchResult.structuredContent could use structured types.',
455
- fix: 'Define ToolMeta interface (category, tags) and replace structuredContent: any with structured type.',
456
- };
457
- }
458
- if (pattern === 'as any') {
459
- return {
460
- category: 'legitimate',
461
- reason: '`as any` cast — usually for third-party type mismatches (MCP SDK). Acceptable if isolated.',
462
- };
463
- }
464
- return {
465
- category: 'legitimate',
466
- reason: 'Unclassified any/unknown usage — review manually. Defaulting to legitimate (no auto-fix).',
467
- };
468
- }
469
- export function analyzeHandlerTypeSafety(instances) {
470
- const findings = [];
471
- for (const inst of instances) {
472
- if (inst.pattern !== 'args: any')
473
- continue;
474
- if (!/tools[\\/]/.test(inst.file))
475
- continue;
476
- findings.push({
477
- rule_id: 'MCP-HANDLER-001',
478
- severity: 'medium',
479
- category: 'handler_types',
480
- tool_name: path.basename(inst.file, '.ts'),
481
- description: `Handler uses \`args: any\` — bypasses TypeScript type checking. ${inst.reason}`,
482
- location: `${inst.file}:${inst.line}`,
483
- fix: inst.fix_suggestion,
484
- });
485
- }
486
- return findings;
487
- }
488
- export function analyzeOutputSchemaCoverage(census) {
489
- const findings = [];
490
- for (const c of census) {
491
- if (!c.layer3_generated.output_exists && c.name !== "onchain_operations") {
492
- findings.push({
493
- rule_id: 'MCP-OUTPUT-001',
494
- severity: 'high',
495
- category: 'output_coverage',
496
- tool_name: c.name,
497
- description: `Layer 3 output schema file does not exist: ${c.layer3_generated.output_schema_file}`,
498
- fix: `Add outputSchema to ${c.name}'s tool definition and regenerate schemas.`,
499
- });
500
- }
501
- if (c.layer2_zod.output_schema_export === null) {
502
- findings.push({
503
- rule_id: 'MCP-OUTPUT-002',
504
- severity: 'medium',
505
- category: 'output_coverage',
506
- tool_name: c.name,
507
- description: `Layer 2 outputSchema is defined inline (not exported with a stable name). This makes it harder to reference from tests.`,
508
- fix: `Export the outputSchema with a stable name (e.g., ${c.name}OutputSchema).`,
509
- });
510
- }
511
- }
512
- return findings;
513
- }
514
- export function analyzeGenerationScriptSync() {
515
- const findings = [];
516
- if (!fs.existsSync(GENERATION_SCRIPT)) {
517
- findings.push({
518
- rule_id: 'MCP-GENSYNC-001',
519
- severity: 'critical',
520
- category: 'generation_sync',
521
- tool_name: '(all)',
522
- description: `Generation script not found: ${GENERATION_SCRIPT}`,
523
- });
524
- return findings;
525
- }
526
- const src = fs.readFileSync(GENERATION_SCRIPT, 'utf-8');
527
- const nameRegex = /name:\s*["']([^"']+)["']/g;
528
- const scriptNames = new Set();
529
- let m;
530
- while ((m = nameRegex.exec(src)) !== null) {
531
- if (ALL_TOOLS.some(t => t.name === m[1])) {
532
- scriptNames.add(m[1]);
533
- }
534
- }
535
- for (const tool of ALL_TOOLS) {
536
- if (!scriptNames.has(tool.name)) {
537
- findings.push({
538
- rule_id: 'MCP-GENSYNC-002',
539
- severity: 'high',
540
- category: 'generation_sync',
541
- tool_name: tool.name,
542
- description: `Tool "${tool.name}" is in TOOL_REGISTRY but missing from generate-json-schemas.ts. Layer 3 schemas will not be generated.`,
543
- location: GENERATION_SCRIPT,
544
- fix: `Add a get${toPascalCase(tool.name)}Tool() function and add it to the tools array.`,
545
- });
546
- }
547
- }
548
- return findings;
549
- }
550
- function toPascalCase(s) {
551
- return s.split('_').map(p => p.charAt(0).toUpperCase() + p.slice(1).toLowerCase()).join('');
552
- }
553
- export function analyzeSchemaQueryReflection(census) {
554
- const findings = [];
555
- for (const c of census) {
556
- if (!c.layer3_generated.input_exists) {
557
- findings.push({
558
- rule_id: 'MCP-REFLECT-001',
559
- severity: 'high',
560
- category: 'reflection',
561
- tool_name: c.name,
562
- description: `schema_query(action='get', name='${c.name}') would fail — Layer 3 input schema missing.`,
563
- fix: `Run pnpm generate:schemas.`,
564
- });
565
- }
566
- if (!c.layer3_generated.output_exists && c.name !== "onchain_operations") {
567
- findings.push({
568
- rule_id: 'MCP-REFLECT-002',
569
- severity: 'medium',
570
- category: 'reflection',
571
- tool_name: c.name,
572
- description: `schema_query(action='get_output', name='${c.name}') would fail — Layer 3 output schema missing.`,
573
- fix: `Run pnpm generate:schemas.`,
574
- });
575
- }
576
- }
577
- const onchainOps = [
578
- 'permission', 'service', 'machine', 'progress', 'guard',
579
- 'arbitration', 'repository', 'contact', 'treasury', 'reward',
580
- 'allocation', 'personal', 'payment', 'demand', 'order', 'gen_passport',
581
- 'proof', 'gen_proof',
582
- ];
583
- for (const op of onchainOps) {
584
- const opFile = path.join(GENERATED_SCHEMAS_DIR, `onchain_operations_${op}.schema.json`);
585
- if (!fs.existsSync(opFile)) {
586
- findings.push({
587
- rule_id: 'MCP-REFLECT-003',
588
- severity: 'medium',
589
- category: 'reflection',
590
- tool_name: `onchain_operations_${op}`,
591
- description: `Individual operation schema missing: ${opFile}. schema_query(action='get', name='onchain_operations_${op}') would fail.`,
592
- fix: `Run pnpm generate:schemas.`,
593
- });
594
- }
595
- }
596
- return findings;
597
- }
598
- export function scanAllMcpSchemas() {
599
- const census = analyzeLayerCensus();
600
- const anyInstances = analyzeAnyUnknownCensus();
601
- const findings = [
602
- ...analyzeDeployedStubInconsistency(census),
603
- ...analyzeLayerParity(census),
604
- ...analyzeHandlerTypeSafety(anyInstances),
605
- ...analyzeOutputSchemaCoverage(census),
606
- ...analyzeGenerationScriptSync(),
607
- ...analyzeSchemaQueryReflection(census),
608
- ];
609
- const bySev = new Map();
610
- const byCat = new Map();
611
- for (const f of findings) {
612
- if (!bySev.has(f.severity))
613
- bySev.set(f.severity, []);
614
- bySev.get(f.severity).push(f);
615
- if (!byCat.has(f.category))
616
- byCat.set(f.category, []);
617
- byCat.get(f.category).push(f);
618
- }
619
- const fixable = anyInstances.filter(i => i.category === 'fixable').length;
620
- const legit = anyInstances.filter(i => i.category === 'legitimate').length;
621
- const external = anyInstances.filter(i => i.category === 'external').length;
622
- const stubCount = census.filter(c => c.layer4_deployed.is_stub).length;
623
- const fullCount = census.filter(c => !c.layer4_deployed.is_stub && c.layer4_deployed.file_exists).length;
624
- return {
625
- census,
626
- findings,
627
- any_unknown_instances: anyInstances,
628
- findings_by_severity: bySev,
629
- findings_by_category: byCat,
630
- total_findings: findings.length,
631
- fixable_any_count: fixable,
632
- legitimate_any_count: legit,
633
- external_any_count: external,
634
- stub_count: stubCount,
635
- full_schema_count: fullCount,
636
- };
637
- }
638
- export function formatAuditReport(result) {
639
- const lines = [];
640
- lines.push(`# MCP Schema Audit Report — 17 WoWok Tools`);
641
- lines.push('');
642
- lines.push(`> Auto-generated by \`mcp-schema-audit.ts\` v${MCP_SCHEMA_AUDIT_VERSION} — comprehensive`);
643
- lines.push(`> 4-layer audit of schema consistency, any/unknown usage, and I/O coverage.`);
644
- lines.push('');
645
- lines.push(`## Summary`);
646
- lines.push('');
647
- lines.push(`- **Tools audited**: ${result.census.length}`);
648
- lines.push(`- **Total findings**: ${result.total_findings}`);
649
- lines.push(`- **Stub files**: ${result.stub_count} / ${result.census.length}`);
650
- lines.push(`- **Full schema files**: ${result.full_schema_count} / ${result.census.length}`);
651
- lines.push(`- **any/unknown instances**: ${result.any_unknown_instances.length} total`);
652
- lines.push(` - Fixable: ${result.fixable_any_count}`);
653
- lines.push(` - Legitimate: ${result.legitimate_any_count}`);
654
- lines.push(` - External: ${result.external_any_count}`);
655
- lines.push('');
656
- lines.push(`### Findings by Severity`);
657
- lines.push('');
658
- lines.push(`| Severity | Count |`);
659
- lines.push(`|----------|-------|`);
660
- for (const sev of ['critical', 'high', 'medium', 'low', 'info']) {
661
- const arr = result.findings_by_severity.get(sev) ?? [];
662
- lines.push(`| ${sev} | ${arr.length} |`);
663
- }
664
- lines.push('');
665
- lines.push(`### Findings by Category`);
666
- lines.push('');
667
- lines.push(`| Category | Count |`);
668
- lines.push(`|----------|-------|`);
669
- for (const cat of ['stub_inconsistency', 'layer_parity', 'handler_types', 'output_coverage', 'generation_sync', 'reflection']) {
670
- const arr = result.findings_by_category.get(cat) ?? [];
671
- lines.push(`| ${cat} | ${arr.length} |`);
672
- }
673
- lines.push('');
674
- lines.push(`## Layer Census — All 17 Tools`);
675
- lines.push('');
676
- lines.push(`| Tool | L3 Input | L3 Output | L4 Status | L4 Properties | L4 Required |`);
677
- lines.push(`|------|----------|-----------|-----------|---------------|-------------|`);
678
- for (const c of result.census) {
679
- const l3i = c.layer3_generated.input_exists ? `✓ ${(c.layer3_generated.input_size_bytes / 1024).toFixed(1)}KB` : '✗ MISSING';
680
- const l3o = c.layer3_generated.output_exists ? `✓ ${(c.layer3_generated.output_size_bytes / 1024).toFixed(1)}KB` : '✗ MISSING';
681
- const l4s = !c.layer4_deployed.file_exists ? '✗ MISSING' : c.layer4_deployed.is_stub ? '⚠ STUB' : '✓ FULL';
682
- const l4p = c.layer4_deployed.properties_count;
683
- const l4r = c.layer4_deployed.required_count;
684
- lines.push(`| ${c.name} | ${l3i} | ${l3o} | ${l4s} | ${l4p} | ${l4r} |`);
685
- }
686
- lines.push('');
687
- lines.push(`## Findings Detail`);
688
- lines.push('');
689
- const orderedSeverities = ['critical', 'high', 'medium', 'low', 'info'];
690
- for (const sev of orderedSeverities) {
691
- const sevFindings = result.findings_by_severity.get(sev) ?? [];
692
- if (sevFindings.length === 0)
693
- continue;
694
- const title = sev.toUpperCase();
695
- lines.push(`### ${title} (${sevFindings.length})`);
696
- lines.push('');
697
- for (const f of sevFindings) {
698
- lines.push(`- **[${f.rule_id}] ${f.description}`);
699
- if (f.location)
700
- lines.push(` - Location: \`${f.location}\``);
701
- if (f.fix)
702
- lines.push(` - Fix: ${f.fix}`);
703
- lines.push('');
704
- }
705
- }
706
- lines.push(`## any/unknown Census Detail`);
707
- lines.push('');
708
- lines.push(`Total instances: ${result.any_unknown_instances.length}`);
709
- lines.push('');
710
- lines.push(`### By Pattern`);
711
- lines.push('');
712
- lines.push(`| Pattern | Total | Fixable | Legitimate | External |`);
713
- lines.push(`|---------|-------|---------|------------|----------|`);
714
- const patternGroups = new Map();
715
- for (const inst of result.any_unknown_instances) {
716
- if (!patternGroups.has(inst.pattern))
717
- patternGroups.set(inst.pattern, []);
718
- patternGroups.get(inst.pattern).push(inst);
719
- }
720
- for (const [pattern, arr] of [...patternGroups.entries()].sort((a, b) => b[1].length - a[1].length)) {
721
- const fixable = arr.filter(i => i.category === 'fixable').length;
722
- const legit = arr.filter(i => i.category === 'legitimate').length;
723
- const ext = arr.filter(i => i.category === 'external').length;
724
- lines.push(`| \`${pattern}\` | ${arr.length} | ${fixable} | ${legit} | ${ext} |`);
725
- }
726
- lines.push('');
727
- const fixable = result.any_unknown_instances.filter(i => i.category === 'fixable');
728
- if (fixable.length > 0) {
729
- lines.push(`### Fixable Instances (Priority List)`);
730
- lines.push('');
731
- for (const inst of fixable) {
732
- lines.push(`- **${path.basename(inst.file)}:${inst.line}** [\`${inst.pattern}\`]`);
733
- lines.push(` - Code: \`${inst.code}\``);
734
- lines.push(` - Reason: ${inst.reason}`);
735
- if (inst.fix_suggestion)
736
- lines.push(` - Fix: ${inst.fix_suggestion}`);
737
- lines.push('');
738
- }
739
- }
740
- lines.push(`## Recommended Action Plan`);
741
- lines.push('');
742
- lines.push(`### Phase 1: Fix Layer 4 Stub Inconsistency (CRITICAL UX)`);
743
- lines.push('');
744
- lines.push(`The ${result.stub_count} stub files force the LLM to call \`schema_query\` first, creating an extra round-trip. Fix by regenerating all 17 Layer 4 files from Layer 3 schemas:`);
745
- lines.push('');
746
- lines.push(`\`\`\`bash`);
747
- lines.push(`# 1. Generate Layer 3 schemas from Zod source`);
748
- lines.push(`cd d:/wowok/agent/mcp && pnpm generate:schemas`);
749
- lines.push('');
750
- lines.push(`# 2. Generate Layer 4 deployed files from Layer 3`);
751
- lines.push(`# (Run the new sync-deployed-tools.ts script — see E2.4)`);
752
- lines.push(`npx tsx scripts/sync-deployed-tools.ts`);
753
- lines.push(`\`\`\``);
754
- lines.push('');
755
- lines.push(`### Phase 2: Type the ${result.fixable_any_count} fixable any/unknown instances`);
756
- lines.push('');
757
- lines.push(`Priority order:`);
758
- lines.push('');
759
- lines.push(`1. **SemanticSummarySchema** (src/schema/local/index.ts:6) — use \`z.lazy()\``);
760
- lines.push(`2. **ConfigOperationOutputSchema.result** (src/schema/config/index.ts:17) — discriminated union by action`);
761
- lines.push(`3. **ProjectOperationOutputSchema.result** (src/schema/project/index.ts:34) — discriminated union by action`);
762
- lines.push(`4. **query_toolkit output result** (src/tools/index.ts:250) — discriminated union by query_type`);
763
- lines.push(`5. **SchemaQueryOutputSchema.data** (src/schema/schema-query/index.ts:34) — discriminated union by action`);
764
- lines.push(`6. **RepositoryKeyValueSchema.key_value** (src/schema/operations.ts:331) — discriminated union by key_type`);
765
- lines.push(`7. **Handler args: any** — replace with \`unknown\` (forces strictParse at top of handler)`);
766
- lines.push(`8. **dispatchToolCall(name, args: any)** — replace with \`unknown\``);
767
- lines.push('');
768
- lines.push(`### Phase 3: Verify I/O Schema Match`);
769
- lines.push('');
770
- lines.push(`For each tool, write a parity test that:`);
771
- lines.push(`1. Calls the handler with a minimal valid input`);
772
- lines.push(`2. Captures the structuredContent`);
773
- lines.push(`3. Validates structuredContent against outputSchema`);
774
- lines.push(`4. Reports any mismatch`);
775
- lines.push('');
776
- return lines.join('\n');
777
- }
1
+ import*as a137a from'fs';import*as a137b from'path';import{CONCEPT_GLOSSARY}from'./glossary.js';export const TRAE_MCPS_ROOT='c:\x5cUsers\x5czhou\x5c.trae-cn\x5cmcps';export const GENERATED_SCHEMAS_DIR='d:\x5cwowok\x5cagent\x5cmcp\x5cdist\x5cschemas';export const MCP_SRC_SCHEMA_DIR='d:\x5cwowok\x5cagent\x5cmcp\x5csrc\x5cschema';export const MCP_SRC_TOOLS_DIR='d:\x5cwowok\x5cagent\x5cmcp\x5csrc\x5ctools';export const GENERATION_SCRIPT='d:\x5cwowok\x5cagent\x5cmcp\x5cscripts\x5cgenerate-json-schemas.ts';export const TOOLS_INDEX_FILE='d:\x5cwowok\x5cagent\x5cmcp\x5csrc\x5ctools\x5cindex.ts';export const MCP_SCHEMA_AUDIT_VERSION='2.1.0';export const ALL_TOOLS=[{'name':'onchain_operations','input_schema_export':'OnchainOperationsSchema','output_schema_export':'CallOutputSchema'},{'name':'account_operation','input_schema_export':'AccountOperationSchema','output_schema_export':'AccountOperationOutputWrappedSchema'},{'name':'local_mark_operation','input_schema_export':'LocalMarkOperationSchema','output_schema_export':'LocalMarkOperationOutputWrappedSchema'},{'name':'local_info_operation','input_schema_export':'LocalInfoOperationSchema','output_schema_export':'LocalInfoOperationOutputWrappedSchema'},{'name':'wip_file','input_schema_export':'WipOperationsSchema','output_schema_export':'WipOperationOutputSchema'},{'name':'messenger_operation','input_schema_export':'MessengerOperationInputSchema','output_schema_export':'MessengerOperationOutputSchema'},{'name':'guard2file','input_schema_export':'Guard2File_InputSchema','output_schema_export':'Guard2File_OutputWrappedSchema'},{'name':'machineNode2file','input_schema_export':'MachineNode2File_InputSchema','output_schema_export':'MachineNode2File_OutputWrappedSchema'},{'name':'query_toolkit','input_schema_export':'WatchQueryOperationsSchema','output_schema_export':'WatchQueryOperationsResultSchema'},{'name':'onchain_table_data','input_schema_export':'OnchainTableDataSchema','output_schema_export':'OnchainTableDataResultSchema'},{'name':'onchain_events','input_schema_export':'OnchainEventsInputSchema','output_schema_export':'OnchainEventsResultSchema'},{'name':'wowok_buildin_info','input_schema_export':'ProtocolInfoQuerySchema','output_schema_export':'ProtocolInfoResultSchema'},{'name':'schema_query','input_schema_export':'SchemaQueryInputSchema','output_schema_export':'SchemaQueryOutputSchema'},{'name':'bridge_operation','input_schema_export':'BridgeOperationsSchema','output_schema_export':'BridgeCallOutputSchema'},{'name':'project_operation','input_schema_export':'ProjectOperationInputSchema','output_schema_export':'ProjectOperationOutputSchema'},{'name':'config_operation','input_schema_export':'ConfigOperationInputSchema','output_schema_export':'ConfigOperationOutputSchema'},{'name':'trust_score','input_schema_export':'TrustScoreInputSchema','output_schema_export':'TrustScoreOutputSchema'},{'name':'query_task_status','input_schema_export':'QueryTaskStatusInputSchema','output_schema_export':'QueryTaskStatusOutputSchema'},{'name':'evaluation_operation','input_schema_export':'EvaluationOperationInputSchema','output_schema_export':'EvaluationOperationOutputSchema'},{'name':'persona_operation','input_schema_export':'PersonaOperationInputSchema','output_schema_export':'PersonaOperationOutputSchema'},{'name':'intent_radar','input_schema_export':'IntentRadarInputSchema','output_schema_export':'IntentRadarOutputSchema'},{'name':'employee_operation','input_schema_export':'EmployeeOperationInputSchema','output_schema_export':'EmployeeOperationOutputSchema'},{'name':'industry_pack_operation','input_schema_export':'IndustryPackOperationInputSchema','output_schema_export':'IndustryPackOperationOutputSchema'},{'name':'workspace_operation','input_schema_export':'WorkspaceOperationInputSchema','output_schema_export':'WorkspaceOperationOutputSchema'}];export function discoverDeployedGatewayMounts(){const a=[];if(!a137a['existsSync'](TRAE_MCPS_ROOT))return[];for(const b of a137a['readdirSync'](TRAE_MCPS_ROOT,{'withFileTypes':!![]})){if(!b['isDirectory']())continue;const c=a137b['join'](TRAE_MCPS_ROOT,b['name'],'solo_agent','mcp_wagent','tools','wowok.json');try{const d=a137a['statSync'](c);if(d['isFile']())a['push']({'file':c,'mtime':d['mtimeMs']});}catch{}}return a['sort']((e,f)=>f['mtime']-e['mtime']),a['map'](e=>e['file']);}const GATEWAY_MISSING={'gateway_file':a137b['join'](TRAE_MCPS_ROOT,'<none>','solo_agent','mcp_wagent','tools','wowok.json'),'file_exists':![],'gateway_name':null,'has_definitions':![],'definitions_count':0x0,'has_tool_field':![],'has_data_field':![],'is_strict':![],'has_schema_hint':![],'size_bytes':0x0,'all_mounts':[]};export function loadLayer4Gateway(){const a=discoverDeployedGatewayMounts();if(a['length']===0x0)return GATEWAY_MISSING;const b=a[0x0];try{const c=a137a['readFileSync'](b,'utf-8'),d=JSON['parse'](c),e=d['arguments']??{},f=e['definitions']??{},g=Object['keys'](f)['length'];let h=e;const i=e['$ref'];if(i&&i['startsWith']('#/definitions/')){const l=i['slice']('#/definitions/'['length']),m=f[l];if(m&&typeof m==='object')h=m;}const j=h['properties']??{},k=d['description']??'';return{'gateway_file':b,'file_exists':!![],'gateway_name':d['name']??null,'has_definitions':g>0x0,'definitions_count':g,'has_tool_field':'tool'in j,'has_data_field':'data'in j,'is_strict':h['additionalProperties']===![],'has_schema_hint':k['includes']('schema_query'),'size_bytes':Buffer['byteLength'](c,'utf-8'),'all_mounts':a};}catch{return{...GATEWAY_MISSING,'gateway_file':b,'all_mounts':a};}}export function loadLayer3Generated(a){const b=a137b['join'](GENERATED_SCHEMAS_DIR,a+'.schema.json'),c=a137b['join'](GENERATED_SCHEMAS_DIR,a+'.output.json'),d=a137a['existsSync'](b),e=a137a['existsSync'](c),f=d?a137a['statSync'](b)['size']:0x0,g=e?a137a['statSync'](c)['size']:0x0;return{'input_schema_file':b,'output_schema_file':c,'input_exists':d,'output_exists':e,'input_size_bytes':f,'output_size_bytes':g};}export function analyzeLayerCensus(){const a=[];for(const b of ALL_TOOLS){a['push']({'name':b['name'],'layer2_zod':{'input_schema_export':b['input_schema_export'],'output_schema_export':b['output_schema_export'],'schema_dir':MCP_SRC_SCHEMA_DIR},'layer3_generated':loadLayer3Generated(b['name'])});}return a;}export function analyzeGatewayDeployment(a){const b=[],c='(gateway)';if(!a['file_exists'])return b['push']({'rule_id':'MCP-GATEWAY-001','severity':'critical','category':'gateway_deployment','tool_name':c,'description':'No\x20deployed\x20wowok.json\x20gateway\x20descriptor\x20found\x20under\x20any\x20Trae\x20mount\x20in\x20'+TRAE_MCPS_ROOT+'.\x20The\x20MCP\x20server\x20is\x20not\x20loaded\x20by\x20any\x20Trae\x20session,\x20or\x20tools/list\x20failed.','fix':'Load\x20the\x20WoWok\x20MCP\x20server\x20in\x20a\x20Trae\x20session\x20and\x20verify\x20tools/list\x20returns\x20the\x20single\x20\x27wowok\x27\x20tool.'}),b;return a['gateway_name']!=='wowok'&&b['push']({'rule_id':'MCP-GATEWAY-002','severity':'high','category':'gateway_deployment','tool_name':c,'description':'Deployed\x20gateway\x20descriptor\x20name\x20is\x20\x27'+a['gateway_name']+'\x27\x20—\x20expected\x20\x27wowok\x27\x20(the\x20single\x20unified\x20tool\x20registered\x20by\x20the\x20server).','location':a['gateway_file'],'fix':'Restart\x20the\x20Trae\x20session\x20so\x20Trae\x20regenerates\x20wowok.json\x20from\x20the\x20server\x27s\x20tools/list.'}),!a['has_definitions']&&a['definitions_count']===0x0&&b['push']({'rule_id':'MCP-GATEWAY-003','severity':'high','category':'gateway_deployment','tool_name':c,'description':'Deployed\x20gateway\x20descriptor\x20carries\x20no\x20argument\x20schema\x20(no\x20definitions,\x20no\x20properties)\x20—\x20the\x20LLM\x20has\x20no\x20parameter\x20structure\x20at\x20all.','location':a['gateway_file'],'fix':'Ensure\x20listTools()\x20advertises\x20WowokToolDisplaySchema\x20and\x20restart\x20the\x20Trae\x20session.'}),!a['has_schema_hint']&&b['push']({'rule_id':'MCP-GATEWAY-004','severity':'medium','category':'gateway_deployment','tool_name':c,'description':'Gateway\x20descriptor\x20description\x20does\x20not\x20mention\x20schema_query\x20—\x20the\x20LLM\x20is\x20not\x20told\x20about\x20the\x20schema\x20self-correction\x20path\x20(sub-tool\x20schemas\x20are\x20returned\x20on\x20validation\x20mismatch).','location':a['gateway_file'],'fix':'Keep\x20the\x20schema_query\x20mention\x20in\x20WOWOK_TOOL_DESCRIPTION\x20(src/tools/index.ts).'}),b;}export function analyzeGatewayDispatchContract(a){const b=[],c='(gateway)';if(!a['file_exists'])return b;const d=[];if(!a['has_tool_field'])d['push']('tool');if(!a['has_data_field'])d['push']('data');return d['length']>0x0&&b['push']({'rule_id':'MCP-PARITY-001','severity':'high','category':'layer_parity','tool_name':c,'description':'Deployed\x20gateway\x20argument\x20schema\x20is\x20missing\x20dispatch\x20field(s):\x20'+d['join'](',\x20')+'.\x20Calls\x20of\x20the\x20form\x20wowok({\x20tool,\x20data\x20})\x20cannot\x20be\x20validated.','location':a['gateway_file'],'fix':'Ensure\x20WowokToolDisplaySchema\x20exposes\x20tool/data\x20properties\x20and\x20restart\x20the\x20Trae\x20session.'}),!a['is_strict']&&b['push']({'rule_id':'MCP-PARITY-002','severity':'medium','category':'layer_parity','tool_name':c,'description':'Deployed\x20gateway\x20root\x20schema\x20is\x20not\x20strict\x20(additionalProperties\x20!==\x20false)\x20—\x20unknown\x20keys\x20silently\x20pass\x20the\x20client-side\x20check.','location':a['gateway_file'],'fix':'Keep\x20additionalProperties:false\x20on\x20WowokToolDisplaySchema\x20(aliases\x20are\x20explicit\x20properties).'}),b;}export function analyzeAnyUnknownCensus(){const a=[],b=[MCP_SRC_SCHEMA_DIR,MCP_SRC_TOOLS_DIR];for(const c of b){const d=listTypeScriptFiles(c);for(const e of d){const f=a137a['readFileSync'](e,'utf-8')['split']('\x0a');for(let g=0x0;g<f['length'];g++){const h=f[g],j=h['trim']();if(j['startsWith']('//')||j['startsWith']('*'))continue;const k=[{'regex':/z\.any\(\)/g,'pattern':'z.any()'},{'regex':/z\.unknown\(\)/g,'pattern':'z.unknown()'},{'regex':/args\s*:\s*any\b/g,'pattern':'args:\x20any'},{'regex':/Promise\s*<\s*any\s*>/g,'pattern':'Promise<any>'},{'regex':/Record\s*<\s*string\s*,\s*any\s*>/g,'pattern':'Record<string,\x20any>'},{'regex':/\bas\s+any\b/g,'pattern':'as\x20any'}];for(const {regex:l,pattern:n}of k){l['lastIndex']=0x0;let o;while((o=l['exec'](h))!==null){const p=categorizeAnyInstance(e,g+0x1,h,n);a['push']({'file':e,'line':g+0x1,'code':j['length']>0x78?j['slice'](0x0,0x75)+'...':j,'pattern':n,'category':p['category'],'reason':p['reason'],'fix_suggestion':p['fix']});}}}}}return a;}function listTypeScriptFiles(a){const b=[];if(!a137a['existsSync'](a))return b;const c=a137a['readdirSync'](a,{'withFileTypes':!![]});for(const d of c){const e=a137b['join'](a,d['name']);if(d['isDirectory']()){if(d['name']==='__tests__'||d['name']==='node_modules')continue;b['push'](...listTypeScriptFiles(e));}else d['isFile']()&&d['name']['endsWith']('.ts')&&b['push'](e);}return b;}function categorizeAnyInstance(a,b,c,d){const e=a137b['basename'](a),f=c['trim']();if(d==='z.any()'&&/SemanticSummarySchema\s*=\s*z\.any\(\)/['test'](f))return{'category':'fixable','reason':'Circular-dependency\x20workaround\x20for\x20SemanticSummarySchema\x20—\x20can\x20use\x20z.lazy()\x20or\x20refactor\x20to\x20break\x20the\x20cycle.','fix':'Define\x20SemanticSummarySchema\x20with\x20z.lazy(()\x20=>\x20SemanticSummarySchemaReal)\x20or\x20restructure\x20imports\x20to\x20break\x20the\x20cycle.'};if(d==='z.any()'&&/result\s*:\s*z\.any\(\)/['test'](f)&&/[\\/]config[\\/]|[\\/]project[\\/]/['test'](a))return{'category':'fixable','reason':'Result\x20shape\x20depends\x20on\x20action\x20—\x20can\x20use\x20z.discriminatedUnion(\x27action\x27,\x20[...])\x20to\x20type\x20each\x20action\x27s\x20result.','fix':'Define\x20discriminated\x20union:\x20z.discriminatedUnion(\x27action\x27,\x20[z.object({action:\x20z.literal(\x27list\x27),\x20result:\x20...}),\x20...]).'};if(d==='z.unknown()'&&/result\s*:\s*z\.unknown\(\)/['test'](f)&&/index\.ts/['test'](e))return{'category':'fixable','reason':'query_toolkit\x20output\x20result\x20depends\x20on\x20query_type\x20—\x20can\x20use\x20z.discriminatedUnion(\x27query_type\x27,\x20[...]).','fix':'Define\x20discriminated\x20union:\x20z.discriminatedUnion(\x27query_type\x27,\x20[z.object({query_type:\x20z.literal(\x27local_mark_list\x27),\x20result:\x20z.array(MarkDataSchema)}),\x20...]).'};if(d==='z.any()'&&/data\s*:\s*z\.any\(\)/['test'](f)&&/[\\/]schema-query[\\/]/['test'](a))return{'category':'fixable','reason':'SchemaQuery\x20output\x20data\x20depends\x20on\x20action\x20—\x20can\x20use\x20discriminated\x20union\x20by\x20action.','fix':'Define\x20discriminated\x20union:\x20action=\x27get\x27\x20returns\x20JSON\x20Schema,\x20action=\x27list\x27\x20returns\x20array\x20of\x20items.'};if(d==='args:\x20any'&&/handlers[\\/]/['test'](a))return{'category':'fixable','reason':'Handler\x20args\x20can\x20use\x20`unknown`\x20(forces\x20runtime\x20validation)\x20or\x20a\x20typed\x20input\x20schema.','fix':'Replace\x20`args:\x20any`\x20with\x20`args:\x20unknown`\x20and\x20use\x20strictParse(schema,\x20args)\x20at\x20the\x20top\x20of\x20the\x20handler.'};if(d==='args:\x20any'&&/tools[\\/]index\.ts/['test'](a))return{'category':'fixable','reason':'dispatchToolCall\x20args\x20is\x20`any`\x20—\x20can\x20be\x20`unknown`\x20since\x20each\x20tool\x20parses\x20with\x20its\x20own\x20schema.','fix':'Change\x20`args:\x20any`\x20to\x20`args:\x20unknown`\x20in\x20dispatchToolCall\x20signature.'};if(d==='args:\x20any'&&/types\.ts/['test'](e)&&/handler/['test'](f))return{'category':'fixable','reason':'ToolEntry.handler\x20args\x20is\x20`any`\x20—\x20can\x20be\x20`unknown`\x20(each\x20handler\x20parses\x20with\x20its\x20own\x20schema).','fix':'Change\x20`handler:\x20(args:\x20any)\x20=>\x20...`\x20to\x20`handler:\x20(args:\x20unknown)\x20=>\x20...`.'};if(d==='z.any()'&&/claimReceipt|ethReceipt|wowReceipt/['test'](f))return{'category':'legitimate','reason':'EVM\x20transaction\x20receipts\x20have\x20an\x20externally-defined\x20shape\x20from\x20viem/ethers\x20—\x20z.any()\x20is\x20acceptable\x20(receipt\x20is\x20informational,\x20not\x20validated).'};if(d==='z.any()'&&/content_raw/['test'](f))return{'category':'legitimate','reason':'content_raw\x20holds\x20raw\x20content\x20for\x20unknown\x20object\x20types\x20—\x20by\x20definition\x20untyped.\x20z.any()\x20is\x20acceptable\x20here.'};if((d==='z.unknown()'||d==='z.any()')&&/parsedJson/['test'](f))return{'category':'legitimate','reason':'Event\x20parsedJson\x20is\x20arbitrary\x20on-chain\x20event\x20data\x20—\x20z.record(z.string(),\x20z.unknown())\x20is\x20appropriate.'};if(d==='z.any()'&&/key_value/['test'](f))return{'category':'fixable','reason':'Repository\x20key_value\x20depends\x20on\x20key_type\x20—\x20could\x20use\x20discriminated\x20union\x20by\x20key_type\x20(string→z.string(),\x20u64→z.bigint()/number,\x20etc.).','fix':'Define\x20z.discriminatedUnion(\x27key_type\x27,\x20[...])\x20with\x20each\x20variant\x20typed.'};if(d==='z.unknown()'&&/data\s*:\s*z\.unknown\(\)/['test'](f)&&/[\\/]bridge/['test'](a))return{'category':'legitimate','reason':'Bridge\x20operation\x20result\x20data\x20varies\x20by\x20operation_type\x20—\x20currently\x209\x20different\x20shapes.\x20Discriminated\x20union\x20would\x20be\x20ideal\x20but\x20high\x20refactor\x20cost.'};if(d==='z.unknown()'&&/adjusted_params/['test'](f))return{'category':'legitimate','reason':'adjusted_params\x20are\x20free-form\x20key-value\x20pairs\x20suggested\x20by\x20AI\x20—\x20z.record(z.string(),\x20z.unknown())\x20is\x20appropriate.'};if(d==='z.any()'&&/object\s*:\s*z\.union.*z\.record\(z\.any\(\)/['test'](f))return{'category':'fixable','reason':'Creation\x20vs\x20reference\x20object\x20union\x20—\x20z.record(z.any())\x20should\x20be\x20replaced\x20with\x20NamedObjectSchema\x20(structured\x20creation\x20input).','fix':'Replace\x20z.record(z.any())\x20with\x20NamedObjectSchema\x20(already\x20defined\x20in\x20base.ts).'};if(d==='z.any()'&&/result\s*:\s*z\.any\(\)\.optional\(\)/['test'](f)&&/[\\/]bridge/['test'](a))return{'category':'legitimate','reason':'Bridge\x20result\x20is\x20operation-specific\x20(manage_evm_rpc\x20has\x20different\x20result\x20per\x20operation)\x20—\x20z.any().optional()\x20is\x20acceptable\x20here.'};if(d==='Promise<any>'&&/[\\/](wrap|shared)\.ts/['test'](a))return{'category':'fixable','reason':'Generic\x20wrappers\x20in\x20wrap.ts/shared.ts\x20use\x20Promise<any>\x20—\x20could\x20be\x20made\x20generic\x20<T>.','fix':'Replace\x20`Promise<any>`\x20with\x20`Promise<ToolDispatchResult>`\x20(the\x20actual\x20return\x20shape).'};if(d==='Record<string,\x20any>'&&/types\.ts/['test'](e)&&/_meta|structuredContent/['test'](f))return{'category':'fixable','reason':'ToolConfig._meta\x20and\x20ToolDispatchResult.structuredContent\x20could\x20use\x20structured\x20types.','fix':'Define\x20ToolMeta\x20interface\x20(category,\x20tags)\x20and\x20replace\x20structuredContent:\x20any\x20with\x20structured\x20type.'};if(d==='as\x20any')return{'category':'legitimate','reason':'`as\x20any`\x20cast\x20—\x20usually\x20for\x20third-party\x20type\x20mismatches\x20(MCP\x20SDK).\x20Acceptable\x20if\x20isolated.'};return{'category':'legitimate','reason':'Unclassified\x20any/unknown\x20usage\x20—\x20review\x20manually.\x20Defaulting\x20to\x20legitimate\x20(no\x20auto-fix).'};}export function analyzeHandlerTypeSafety(a){const b=[];for(const c of a){if(c['pattern']!=='args:\x20any')continue;if(!/tools[\\/]/['test'](c['file']))continue;b['push']({'rule_id':'MCP-HANDLER-001','severity':'medium','category':'handler_types','tool_name':a137b['basename'](c['file'],'.ts'),'description':'Handler\x20uses\x20`args:\x20any`\x20—\x20bypasses\x20TypeScript\x20type\x20checking.\x20'+c['reason'],'location':c['file']+':'+c['line'],'fix':c['fix_suggestion']});}return b;}export function analyzeOutputSchemaCoverage(a){const b=[];for(const d of a){!d['layer3_generated']['output_exists']&&d['name']!=='onchain_operations'&&b['push']({'rule_id':'MCP-OUTPUT-001','severity':'high','category':'output_coverage','tool_name':d['name'],'description':'Layer\x203\x20output\x20schema\x20file\x20does\x20not\x20exist:\x20'+d['layer3_generated']['output_schema_file'],'fix':'Add\x20outputSchema\x20to\x20'+d['name']+'\x27s\x20tool\x20definition\x20and\x20regenerate\x20schemas.'}),d['layer2_zod']['output_schema_export']===null&&b['push']({'rule_id':'MCP-OUTPUT-002','severity':'medium','category':'output_coverage','tool_name':d['name'],'description':'Layer\x202\x20outputSchema\x20is\x20defined\x20inline\x20(not\x20exported\x20with\x20a\x20stable\x20name).\x20This\x20makes\x20it\x20harder\x20to\x20reference\x20from\x20tests.','fix':'Export\x20the\x20outputSchema\x20with\x20a\x20stable\x20name\x20(e.g.,\x20'+d['name']+'OutputSchema).'});}return b;}export function analyzeGenerationScriptSync(){const a=[];if(!a137a['existsSync'](GENERATION_SCRIPT))return a['push']({'rule_id':'MCP-GENSYNC-001','severity':'critical','category':'generation_sync','tool_name':'(all)','description':'Generation\x20script\x20not\x20found:\x20'+GENERATION_SCRIPT}),a;const b=a137a['readFileSync'](GENERATION_SCRIPT,'utf-8'),c=/name:\s*["']([^"']+)["']/g,d=new Set();let e;while((e=c['exec'](b))!==null){ALL_TOOLS['some'](f=>f['name']===e[0x1])&&d['add'](e[0x1]);}for(const f of ALL_TOOLS){!d['has'](f['name'])&&a['push']({'rule_id':'MCP-GENSYNC-002','severity':'high','category':'generation_sync','tool_name':f['name'],'description':'Tool\x20\x22'+f['name']+'\x22\x20is\x20in\x20TOOL_REGISTRY\x20but\x20missing\x20from\x20generate-json-schemas.ts.\x20Layer\x203\x20schemas\x20will\x20not\x20be\x20generated.','location':GENERATION_SCRIPT,'fix':'Add\x20a\x20get'+toPascalCase(f['name'])+'Tool()\x20function\x20and\x20add\x20it\x20to\x20the\x20tools\x20array.'});}return a;}function toPascalCase(a){return a['split']('_')['map'](b=>b['charAt'](0x0)['toUpperCase']()+b['slice'](0x1)['toLowerCase']())['join']('');}export function analyzeSchemaQueryReflection(a){const b=[];for(const e of a){!e['layer3_generated']['input_exists']&&b['push']({'rule_id':'MCP-REFLECT-001','severity':'high','category':'reflection','tool_name':e['name'],'description':'schema_query(action=\x27get\x27,\x20name=\x27'+e['name']+'\x27)\x20would\x20fail\x20—\x20Layer\x203\x20input\x20schema\x20missing.','fix':'Run\x20pnpm\x20generate:schemas.'}),!e['layer3_generated']['output_exists']&&e['name']!=='onchain_operations'&&b['push']({'rule_id':'MCP-REFLECT-002','severity':'medium','category':'reflection','tool_name':e['name'],'description':'schema_query(action=\x27get_output\x27,\x20name=\x27'+e['name']+'\x27)\x20would\x20fail\x20—\x20Layer\x203\x20output\x20schema\x20missing.','fix':'Run\x20pnpm\x20generate:schemas.'});}const d=['permission','service','machine','progress','guard','arbitration','repository','contact','treasury','reward','allocation','personal','payment','demand','order','gen_passport','proof','gen_proof'];for(const f of d){const g=a137b['join'](GENERATED_SCHEMAS_DIR,'onchain_operations_'+f+'.schema.json');!a137a['existsSync'](g)&&b['push']({'rule_id':'MCP-REFLECT-003','severity':'medium','category':'reflection','tool_name':'onchain_operations_'+f,'description':'Individual\x20operation\x20schema\x20missing:\x20'+g+'.\x20schema_query(action=\x27get\x27,\x20name=\x27onchain_operations_'+f+'\x27)\x20would\x20fail.','fix':'Run\x20pnpm\x20generate:schemas.'});}return b;}function normalizeGlossaryTerm(a){return a['toLowerCase']()['replace'](/[-_\s]/g,'');}const GLOSSARY_ALIAS_INDEX=((()=>{const a=new Set(CONCEPT_GLOSSARY['map'](c=>normalizeGlossaryTerm(c['term']))),b=new Map();for(const c of CONCEPT_GLOSSARY){for(const d of c['aliases']){const e=normalizeGlossaryTerm(d);if(a['has'](e))continue;if(!b['has'](e))b['set'](e,c['term']);}}return b;})());function collectSchemaProperties(a,b,c){if(!a||typeof a!=='object')return;const d=a;if(d['properties']&&typeof d['properties']==='object')for(const e of Object['keys'](d['properties'])){c['push']({'file':b,'property':e}),collectSchemaProperties(d['properties'][e],b,c);}if(d['definitions']&&typeof d['definitions']==='object')for(const f of Object['keys'](d['definitions'])){collectSchemaProperties(d['definitions'][f],b,c);}if(d['items'])collectSchemaProperties(d['items'],b,c);if(Array['isArray'](d['anyOf']))d['anyOf']['forEach'](g=>collectSchemaProperties(g,b,c));if(Array['isArray'](d['oneOf']))d['oneOf']['forEach'](g=>collectSchemaProperties(g,b,c));d['additionalProperties']&&typeof d['additionalProperties']==='object'&&collectSchemaProperties(d['additionalProperties'],b,c);}export function analyzeGlossaryAlignment(){const a=[];if(!a137a['existsSync'](GENERATED_SCHEMAS_DIR))return a;const b=a137a['readdirSync'](GENERATED_SCHEMAS_DIR)['filter'](d=>d['endsWith']('.schema.json')||d['endsWith']('.output.json')),c=new Set();for(const d of b){const e=a137b['join'](GENERATED_SCHEMAS_DIR,d);let f;try{f=JSON['parse'](a137a['readFileSync'](e,'utf-8'));}catch{continue;}const g=[];collectSchemaProperties(f,d,g);for(const h of g){const i=normalizeGlossaryTerm(h['property']),j=GLOSSARY_ALIAS_INDEX['get'](i);if(!j)continue;const k=h['file']+'::'+h['property'];if(c['has'](k))continue;c['add'](k),a['push']({'rule_id':'MCP-GLOSSARY-001','severity':'medium','category':'glossary_alignment','tool_name':d['replace'](/\.(schema|output)\.json$/,''),'description':'Schema\x20field\x20\x27'+h['property']+'\x27\x20uses\x20a\x20deprecated\x20glossary\x20alias\x20—\x20the\x20canonical\x20term\x20is\x20\x27'+j+'\x27.','location':e,'fix':'Rename\x20the\x20field\x20to\x20the\x20canonical\x20term\x20(camelCase/snake_case\x20of\x20\x27'+j+'\x27).'});}}return a;}export function scanAllMcpSchemas(){const a=analyzeLayerCensus(),b=loadLayer4Gateway(),c=analyzeAnyUnknownCensus(),d=[...analyzeGatewayDeployment(b),...analyzeGatewayDispatchContract(b),...analyzeHandlerTypeSafety(c),...analyzeOutputSchemaCoverage(a),...analyzeGenerationScriptSync(),...analyzeSchemaQueryReflection(a),...analyzeGlossaryAlignment()],e=new Map(),g=new Map();for(const k of d){if(!e['has'](k['severity']))e['set'](k['severity'],[]);e['get'](k['severity'])['push'](k);if(!g['has'](k['category']))g['set'](k['category'],[]);g['get'](k['category'])['push'](k);}const h=c['filter'](l=>l['category']==='fixable')['length'],i=c['filter'](l=>l['category']==='legitimate')['length'],j=c['filter'](l=>l['category']==='external')['length'];return{'census':a,'gateway':b,'findings':d,'any_unknown_instances':c,'findings_by_severity':e,'findings_by_category':g,'total_findings':d['length'],'fixable_any_count':h,'legitimate_any_count':i,'external_any_count':j};}export function formatAuditReport(a){const b=[];b['push']('#\x20MCP\x20Schema\x20Audit\x20Report\x20—\x20'+a['census']['length']+'\x20WoWok\x20Sub-Tools\x20+\x20Unified\x20Gateway'),b['push'](''),b['push']('>\x20Auto-generated\x20by\x20`mcp-schema-audit.ts`\x20v'+MCP_SCHEMA_AUDIT_VERSION+'\x20—\x20comprehensive'),b['push']('>\x204-layer\x20audit\x20of\x20schema\x20consistency,\x20any/unknown\x20usage,\x20and\x20I/O\x20coverage.'),b['push'](''),b['push']('##\x20Summary'),b['push'](''),b['push']('-\x20**Tools\x20audited**:\x20'+a['census']['length']),b['push']('-\x20**Total\x20findings**:\x20'+a['total_findings']),b['push']('-\x20**Gateway\x20deployed**:\x20'+(a['gateway']['file_exists']?'yes\x20('+a['gateway']['all_mounts']['length']+'\x20Trae\x20mount(s))':'NO')),b['push']('-\x20**any/unknown\x20instances**:\x20'+a['any_unknown_instances']['length']+'\x20total'),b['push']('\x20\x20-\x20Fixable:\x20'+a['fixable_any_count']),b['push']('\x20\x20-\x20Legitimate:\x20'+a['legitimate_any_count']),b['push']('\x20\x20-\x20External:\x20'+a['external_any_count']),b['push']('-\x20**Glossary\x20alignment**:\x20'+(a['findings_by_category']['get']('glossary_alignment')??[])['length']+'\x20deprecated-alias\x20schema\x20field(s)'),b['push'](''),b['push']('###\x20Findings\x20by\x20Severity'),b['push'](''),b['push']('|\x20Severity\x20|\x20Count\x20|'),b['push']('|----------|-------|');for(const h of['critical','high','medium','low','info']){const i=a['findings_by_severity']['get'](h)??[];b['push']('|\x20'+h+'\x20|\x20'+i['length']+'\x20|');}b['push'](''),b['push']('###\x20Findings\x20by\x20Category'),b['push'](''),b['push']('|\x20Category\x20|\x20Count\x20|'),b['push']('|----------|-------|');for(const j of['gateway_deployment','layer_parity','handler_types','output_coverage','generation_sync','reflection','glossary_alignment']){const k=a['findings_by_category']['get'](j)??[];b['push']('|\x20'+j+'\x20|\x20'+k['length']+'\x20|');}b['push'](''),b['push']('##\x20Layer\x204\x20—\x20Deployed\x20Gateway'),b['push']('');a['gateway']['file_exists']?(b['push']('-\x20**Descriptor**:\x20`'+a['gateway']['gateway_file']+'`\x20('+(a['gateway']['size_bytes']/0x400)['toFixed'](0x1)+'KB)'),b['push']('-\x20**Name**:\x20'+a['gateway']['gateway_name']),b['push']('-\x20**Dispatch\x20contract**:\x20tool='+(a['gateway']['has_tool_field']?'✓':'✗')+'\x20data='+(a['gateway']['has_data_field']?'✓':'✗')+'\x20strict='+(a['gateway']['is_strict']?'✓':'✗')),b['push']('-\x20**Definitions**:\x20'+a['gateway']['definitions_count']),b['push']('-\x20**schema_query\x20hint**:\x20'+(a['gateway']['has_schema_hint']?'✓':'✗')),b['push']('-\x20**Trae\x20mounts**:\x20'+a['gateway']['all_mounts']['length'])):b['push']('-\x20✗\x20No\x20wowok.json\x20found\x20under\x20any\x20Trae\x20mount\x20in\x20'+TRAE_MCPS_ROOT);b['push'](''),b['push']('##\x20Layer\x20Census\x20—\x20All\x20'+a['census']['length']+'\x20Sub-Tools\x20(dispatched\x20via\x20the\x20wowok\x20gateway)'),b['push'](''),b['push']('|\x20Tool\x20|\x20L3\x20Input\x20|\x20L3\x20Output\x20|'),b['push']('|------|----------|-----------|');for(const l of a['census']){const m=l['layer3_generated']['input_exists']?'✓\x20'+(l['layer3_generated']['input_size_bytes']/0x400)['toFixed'](0x1)+'KB':'✗\x20MISSING',n=l['layer3_generated']['output_exists']?'✓\x20'+(l['layer3_generated']['output_size_bytes']/0x400)['toFixed'](0x1)+'KB':'✗\x20MISSING';b['push']('|\x20'+l['name']+'\x20|\x20'+m+'\x20|\x20'+n+'\x20|');}b['push'](''),b['push']('##\x20Findings\x20Detail'),b['push']('');const d=['critical','high','medium','low','info'];for(const o of d){const p=a['findings_by_severity']['get'](o)??[];if(p['length']===0x0)continue;const q=o['toUpperCase']();b['push']('###\x20'+q+'\x20('+p['length']+')'),b['push']('');for(const r of p){b['push']('-\x20**['+r['rule_id']+']\x20'+r['description']);if(r['location'])b['push']('\x20\x20-\x20Location:\x20`'+r['location']+'`');if(r['fix'])b['push']('\x20\x20-\x20Fix:\x20'+r['fix']);b['push']('');}}b['push']('##\x20any/unknown\x20Census\x20Detail'),b['push'](''),b['push']('Total\x20instances:\x20'+a['any_unknown_instances']['length']),b['push'](''),b['push']('###\x20By\x20Pattern'),b['push'](''),b['push']('|\x20Pattern\x20|\x20Total\x20|\x20Fixable\x20|\x20Legitimate\x20|\x20External\x20|'),b['push']('|---------|-------|---------|------------|----------|');const e=new Map();for(const s of a['any_unknown_instances']){if(!e['has'](s['pattern']))e['set'](s['pattern'],[]);e['get'](s['pattern'])['push'](s);}for(const [t,u]of[...e['entries']()]['sort']((v,w)=>w[0x1]['length']-v[0x1]['length'])){const v=u['filter'](y=>y['category']==='fixable')['length'],w=u['filter'](y=>y['category']==='legitimate')['length'],x=u['filter'](y=>y['category']==='external')['length'];b['push']('|\x20`'+t+'`\x20|\x20'+u['length']+'\x20|\x20'+v+'\x20|\x20'+w+'\x20|\x20'+x+'\x20|');}b['push']('');const g=a['any_unknown_instances']['filter'](y=>y['category']==='fixable');if(g['length']>0x0){b['push']('###\x20Fixable\x20Instances\x20(Priority\x20List)'),b['push']('');for(const y of g){b['push']('-\x20**'+a137b['basename'](y['file'])+':'+y['line']+'**\x20[`'+y['pattern']+'`]'),b['push']('\x20\x20-\x20Code:\x20`'+y['code']+'`'),b['push']('\x20\x20-\x20Reason:\x20'+y['reason']);if(y['fix_suggestion'])b['push']('\x20\x20-\x20Fix:\x20'+y['fix_suggestion']);b['push']('');}}return b['push']('##\x20Recommended\x20Action\x20Plan'),b['push'](''),b['push']('###\x20Phase\x201:\x20Keep\x20the\x20Layer\x203\x20schema\x20set\x20regenerable'),b['push'](''),b['push']('Layer\x204\x20(the\x20deployed\x20wowok.json\x20gateway)\x20is\x20CLIENT-generated\x20from\x20our\x20tools/list\x20—\x20keep\x20Layer\x203\x20in\x20sync\x20so\x20schema_query\x20reflection\x20always\x20serves\x20fresh\x20schemas:'),b['push'](''),b['push']('```bash'),b['push']('cd\x20d:/wowok/agent/mcp\x20&&\x20pnpm\x20generate:schemas'),b['push']('```'),b['push'](''),b['push']('###\x20Phase\x202:\x20Type\x20the\x20'+a['fixable_any_count']+'\x20fixable\x20any/unknown\x20instances'),b['push'](''),b['push']('Priority\x20order:'),b['push'](''),b['push']('1.\x20**SemanticSummarySchema**\x20(src/schema/local/index.ts:6)\x20—\x20use\x20`z.lazy()`'),b['push']('2.\x20**ConfigOperationOutputSchema.result**\x20(src/schema/config/index.ts:17)\x20—\x20discriminated\x20union\x20by\x20action'),b['push']('3.\x20**ProjectOperationOutputSchema.result**\x20(src/schema/project/index.ts:34)\x20—\x20discriminated\x20union\x20by\x20action'),b['push']('4.\x20**query_toolkit\x20output\x20result**\x20(src/tools/index.ts:250)\x20—\x20discriminated\x20union\x20by\x20query_type'),b['push']('5.\x20**SchemaQueryOutputSchema.data**\x20(src/schema/schema-query/index.ts:34)\x20—\x20discriminated\x20union\x20by\x20action'),b['push']('6.\x20**RepositoryKeyValueSchema.key_value**\x20(src/schema/operations.ts:331)\x20—\x20discriminated\x20union\x20by\x20key_type'),b['push']('7.\x20**Handler\x20args:\x20any**\x20—\x20replace\x20with\x20`unknown`\x20(forces\x20strictParse\x20at\x20top\x20of\x20handler)'),b['push']('8.\x20**dispatchToolCall(name,\x20args:\x20any)**\x20—\x20replace\x20with\x20`unknown`'),b['push'](''),b['push']('###\x20Phase\x203:\x20Verify\x20I/O\x20Schema\x20Match'),b['push'](''),b['push']('For\x20each\x20tool,\x20write\x20a\x20parity\x20test\x20that:'),b['push']('1.\x20Calls\x20the\x20handler\x20with\x20a\x20minimal\x20valid\x20input'),b['push']('2.\x20Captures\x20the\x20structuredContent'),b['push']('3.\x20Validates\x20structuredContent\x20against\x20outputSchema'),b['push']('4.\x20Reports\x20any\x20mismatch'),b['push'](''),b['join']('\x0a');}