@copilotkit/aimock 1.42.1 → 1.44.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (442) hide show
  1. package/.claude-plugin/marketplace.json +1 -1
  2. package/.claude-plugin/plugin.json +1 -1
  3. package/CHANGELOG.md +65 -0
  4. package/README.md +108 -16
  5. package/dist/agui-handler.d.ts.map +1 -1
  6. package/dist/agui-mock.cjs +1 -1
  7. package/dist/agui-mock.cjs.map +1 -1
  8. package/dist/agui-mock.d.cts.map +1 -1
  9. package/dist/agui-mock.d.ts.map +1 -1
  10. package/dist/agui-mock.js +1 -1
  11. package/dist/agui-mock.js.map +1 -1
  12. package/dist/agui-recorder.cjs +33 -11
  13. package/dist/agui-recorder.cjs.map +1 -1
  14. package/dist/agui-recorder.d.cts +10 -1
  15. package/dist/agui-recorder.d.cts.map +1 -1
  16. package/dist/agui-recorder.d.ts +10 -1
  17. package/dist/agui-recorder.d.ts.map +1 -1
  18. package/dist/agui-recorder.js +33 -11
  19. package/dist/agui-recorder.js.map +1 -1
  20. package/dist/agui-types.d.cts +1 -0
  21. package/dist/agui-types.d.cts.map +1 -1
  22. package/dist/agui-types.d.ts +1 -0
  23. package/dist/agui-types.d.ts.map +1 -1
  24. package/dist/aimock-cli.cjs +38 -10
  25. package/dist/aimock-cli.cjs.map +1 -1
  26. package/dist/aimock-cli.d.cts +5 -0
  27. package/dist/aimock-cli.d.cts.map +1 -1
  28. package/dist/aimock-cli.d.ts +5 -0
  29. package/dist/aimock-cli.d.ts.map +1 -1
  30. package/dist/aimock-cli.js +38 -10
  31. package/dist/aimock-cli.js.map +1 -1
  32. package/dist/batches.cjs +458 -0
  33. package/dist/batches.cjs.map +1 -0
  34. package/dist/batches.d.cts +57 -0
  35. package/dist/batches.d.cts.map +1 -0
  36. package/dist/batches.d.ts +57 -0
  37. package/dist/batches.d.ts.map +1 -0
  38. package/dist/batches.js +453 -0
  39. package/dist/batches.js.map +1 -0
  40. package/dist/bedrock-converse.cjs +44 -12
  41. package/dist/bedrock-converse.cjs.map +1 -1
  42. package/dist/bedrock-converse.d.cts.map +1 -1
  43. package/dist/bedrock-converse.d.ts.map +1 -1
  44. package/dist/bedrock-converse.js +46 -14
  45. package/dist/bedrock-converse.js.map +1 -1
  46. package/dist/bedrock.cjs +10 -8
  47. package/dist/bedrock.cjs.map +1 -1
  48. package/dist/bedrock.d.cts.map +1 -1
  49. package/dist/bedrock.d.ts.map +1 -1
  50. package/dist/bedrock.js +12 -10
  51. package/dist/bedrock.js.map +1 -1
  52. package/dist/byteplus-video.cjs +3 -3
  53. package/dist/byteplus-video.cjs.map +1 -1
  54. package/dist/byteplus-video.js +4 -4
  55. package/dist/byteplus-video.js.map +1 -1
  56. package/dist/chaos.cjs +625 -72
  57. package/dist/chaos.cjs.map +1 -1
  58. package/dist/chaos.d.cts +164 -7
  59. package/dist/chaos.d.cts.map +1 -1
  60. package/dist/chaos.d.ts +164 -7
  61. package/dist/chaos.d.ts.map +1 -1
  62. package/dist/chaos.js +616 -74
  63. package/dist/chaos.js.map +1 -1
  64. package/dist/cli.cjs +131 -30
  65. package/dist/cli.cjs.map +1 -1
  66. package/dist/cli.js +132 -31
  67. package/dist/cli.js.map +1 -1
  68. package/dist/cohere.cjs +37 -9
  69. package/dist/cohere.cjs.map +1 -1
  70. package/dist/cohere.d.cts.map +1 -1
  71. package/dist/cohere.d.ts.map +1 -1
  72. package/dist/cohere.js +39 -11
  73. package/dist/cohere.js.map +1 -1
  74. package/dist/config-loader.cjs +1 -1
  75. package/dist/config-loader.js +1 -1
  76. package/dist/constants.cjs +8 -0
  77. package/dist/constants.cjs.map +1 -1
  78. package/dist/constants.d.cts +6 -2
  79. package/dist/constants.d.ts +6 -2
  80. package/dist/constants.js +8 -1
  81. package/dist/constants.js.map +1 -1
  82. package/dist/convert.cjs +1 -1
  83. package/dist/convert.cjs.map +1 -1
  84. package/dist/convert.js +1 -1
  85. package/dist/convert.js.map +1 -1
  86. package/dist/echo-text.cjs +65 -0
  87. package/dist/echo-text.cjs.map +1 -0
  88. package/dist/echo-text.d.cts +22 -0
  89. package/dist/echo-text.d.cts.map +1 -0
  90. package/dist/echo-text.d.ts +22 -0
  91. package/dist/echo-text.d.ts.map +1 -0
  92. package/dist/echo-text.js +65 -0
  93. package/dist/echo-text.js.map +1 -0
  94. package/dist/elevenlabs-audio.cjs +3 -3
  95. package/dist/elevenlabs-audio.cjs.map +1 -1
  96. package/dist/elevenlabs-audio.js +4 -4
  97. package/dist/elevenlabs-audio.js.map +1 -1
  98. package/dist/elevenlabs-voice.cjs +1053 -0
  99. package/dist/elevenlabs-voice.cjs.map +1 -0
  100. package/dist/elevenlabs-voice.d.cts +72 -0
  101. package/dist/elevenlabs-voice.d.cts.map +1 -0
  102. package/dist/elevenlabs-voice.d.ts +72 -0
  103. package/dist/elevenlabs-voice.d.ts.map +1 -0
  104. package/dist/elevenlabs-voice.js +1048 -0
  105. package/dist/elevenlabs-voice.js.map +1 -0
  106. package/dist/embeddings.cjs +26 -5
  107. package/dist/embeddings.cjs.map +1 -1
  108. package/dist/embeddings.d.cts +1 -1
  109. package/dist/embeddings.d.cts.map +1 -1
  110. package/dist/embeddings.d.ts +1 -1
  111. package/dist/embeddings.d.ts.map +1 -1
  112. package/dist/embeddings.js +27 -6
  113. package/dist/embeddings.js.map +1 -1
  114. package/dist/fal-audio.cjs +3 -3
  115. package/dist/fal-audio.cjs.map +1 -1
  116. package/dist/fal-audio.js +4 -4
  117. package/dist/fal-audio.js.map +1 -1
  118. package/dist/fal.cjs +28 -4
  119. package/dist/fal.cjs.map +1 -1
  120. package/dist/fal.d.cts +16 -1
  121. package/dist/fal.d.cts.map +1 -1
  122. package/dist/fal.d.ts +16 -1
  123. package/dist/fal.d.ts.map +1 -1
  124. package/dist/fal.js +28 -5
  125. package/dist/fal.js.map +1 -1
  126. package/dist/files.cjs +1069 -0
  127. package/dist/files.cjs.map +1 -0
  128. package/dist/files.d.cts +68 -0
  129. package/dist/files.d.cts.map +1 -0
  130. package/dist/files.d.ts +68 -0
  131. package/dist/files.d.ts.map +1 -0
  132. package/dist/files.js +1056 -0
  133. package/dist/files.js.map +1 -0
  134. package/dist/fine-tuning.cjs +1033 -0
  135. package/dist/fine-tuning.cjs.map +1 -0
  136. package/dist/fine-tuning.d.cts +96 -0
  137. package/dist/fine-tuning.d.cts.map +1 -0
  138. package/dist/fine-tuning.d.ts +96 -0
  139. package/dist/fine-tuning.d.ts.map +1 -0
  140. package/dist/fine-tuning.js +1026 -0
  141. package/dist/fine-tuning.js.map +1 -0
  142. package/dist/fixture-loader-services.cjs +116 -0
  143. package/dist/fixture-loader-services.cjs.map +1 -0
  144. package/dist/fixture-loader-services.d.cts +48 -0
  145. package/dist/fixture-loader-services.d.cts.map +1 -0
  146. package/dist/fixture-loader-services.d.ts +48 -0
  147. package/dist/fixture-loader-services.d.ts.map +1 -0
  148. package/dist/fixture-loader-services.js +114 -0
  149. package/dist/fixture-loader-services.js.map +1 -0
  150. package/dist/fixture-loader.cjs +0 -0
  151. package/dist/fixture-loader.cjs.map +1 -1
  152. package/dist/fixture-loader.d.cts +131 -5
  153. package/dist/fixture-loader.d.cts.map +1 -1
  154. package/dist/fixture-loader.d.ts +131 -5
  155. package/dist/fixture-loader.d.ts.map +1 -1
  156. package/dist/fixture-loader.js +0 -0
  157. package/dist/fixture-loader.js.map +1 -1
  158. package/dist/gemini-embeddings.cjs +44 -4
  159. package/dist/gemini-embeddings.cjs.map +1 -1
  160. package/dist/gemini-embeddings.js +46 -6
  161. package/dist/gemini-embeddings.js.map +1 -1
  162. package/dist/gemini-interactions.cjs +51 -7
  163. package/dist/gemini-interactions.cjs.map +1 -1
  164. package/dist/gemini-interactions.d.cts.map +1 -1
  165. package/dist/gemini-interactions.d.ts.map +1 -1
  166. package/dist/gemini-interactions.js +53 -9
  167. package/dist/gemini-interactions.js.map +1 -1
  168. package/dist/gemini.cjs +19 -8
  169. package/dist/gemini.cjs.map +1 -1
  170. package/dist/gemini.d.cts.map +1 -1
  171. package/dist/gemini.d.ts.map +1 -1
  172. package/dist/gemini.js +21 -10
  173. package/dist/gemini.js.map +1 -1
  174. package/dist/grok-video.cjs +14 -14
  175. package/dist/grok-video.cjs.map +1 -1
  176. package/dist/grok-video.js +15 -15
  177. package/dist/grok-video.js.map +1 -1
  178. package/dist/helpers.cjs +497 -10
  179. package/dist/helpers.cjs.map +1 -1
  180. package/dist/helpers.d.cts +38 -2
  181. package/dist/helpers.d.cts.map +1 -1
  182. package/dist/helpers.d.ts +38 -2
  183. package/dist/helpers.d.ts.map +1 -1
  184. package/dist/helpers.js +487 -12
  185. package/dist/helpers.js.map +1 -1
  186. package/dist/images.cjs +57 -125
  187. package/dist/images.cjs.map +1 -1
  188. package/dist/images.d.cts.map +1 -1
  189. package/dist/images.d.ts.map +1 -1
  190. package/dist/images.js +58 -126
  191. package/dist/images.js.map +1 -1
  192. package/dist/index.cjs +71 -9
  193. package/dist/index.d.cts +17 -7
  194. package/dist/index.d.ts +17 -7
  195. package/dist/index.js +21 -11
  196. package/dist/jest.cjs +24 -12
  197. package/dist/jest.cjs.map +1 -1
  198. package/dist/jest.d.cts +6 -3
  199. package/dist/jest.d.cts.map +1 -1
  200. package/dist/jest.d.ts +6 -3
  201. package/dist/jest.d.ts.map +1 -1
  202. package/dist/jest.js +25 -13
  203. package/dist/jest.js.map +1 -1
  204. package/dist/journal.cjs +61 -4
  205. package/dist/journal.cjs.map +1 -1
  206. package/dist/journal.d.cts +60 -3
  207. package/dist/journal.d.cts.map +1 -1
  208. package/dist/journal.d.ts +60 -3
  209. package/dist/journal.d.ts.map +1 -1
  210. package/dist/journal.js +61 -5
  211. package/dist/journal.js.map +1 -1
  212. package/dist/live-fixture.cjs +1192 -0
  213. package/dist/live-fixture.cjs.map +1 -0
  214. package/dist/live-fixture.js +1187 -0
  215. package/dist/live-fixture.js.map +1 -0
  216. package/dist/live-recorder.cjs +256 -0
  217. package/dist/live-recorder.cjs.map +1 -0
  218. package/dist/live-recorder.js +254 -0
  219. package/dist/live-recorder.js.map +1 -0
  220. package/dist/live-replay.cjs +286 -0
  221. package/dist/live-replay.cjs.map +1 -0
  222. package/dist/live-replay.js +285 -0
  223. package/dist/live-replay.js.map +1 -0
  224. package/dist/live-sanitize.cjs +196 -0
  225. package/dist/live-sanitize.cjs.map +1 -0
  226. package/dist/live-sanitize.js +196 -0
  227. package/dist/live-sanitize.js.map +1 -0
  228. package/dist/live-types.d.cts +71 -0
  229. package/dist/live-types.d.cts.map +1 -0
  230. package/dist/live-types.d.ts +71 -0
  231. package/dist/live-types.d.ts.map +1 -0
  232. package/dist/llmock.cjs +132 -49
  233. package/dist/llmock.cjs.map +1 -1
  234. package/dist/llmock.d.cts +51 -5
  235. package/dist/llmock.d.cts.map +1 -1
  236. package/dist/llmock.d.ts +51 -5
  237. package/dist/llmock.d.ts.map +1 -1
  238. package/dist/llmock.js +133 -50
  239. package/dist/llmock.js.map +1 -1
  240. package/dist/mcp-fakes-mount.cjs +216 -0
  241. package/dist/mcp-fakes-mount.cjs.map +1 -0
  242. package/dist/mcp-fakes-mount.js +210 -0
  243. package/dist/mcp-fakes-mount.js.map +1 -0
  244. package/dist/mcp-fakes.cjs +1619 -0
  245. package/dist/mcp-fakes.cjs.map +1 -0
  246. package/dist/mcp-fakes.d.cts +101 -0
  247. package/dist/mcp-fakes.d.cts.map +1 -0
  248. package/dist/mcp-fakes.d.ts +101 -0
  249. package/dist/mcp-fakes.d.ts.map +1 -0
  250. package/dist/mcp-fakes.js +1614 -0
  251. package/dist/mcp-fakes.js.map +1 -0
  252. package/dist/mcp-handler.cjs +331 -17
  253. package/dist/mcp-handler.cjs.map +1 -1
  254. package/dist/mcp-handler.js +330 -18
  255. package/dist/mcp-handler.js.map +1 -1
  256. package/dist/mcp-mock.cjs +217 -49
  257. package/dist/mcp-mock.cjs.map +1 -1
  258. package/dist/mcp-mock.d.cts +66 -1
  259. package/dist/mcp-mock.d.cts.map +1 -1
  260. package/dist/mcp-mock.d.ts +66 -1
  261. package/dist/mcp-mock.d.ts.map +1 -1
  262. package/dist/mcp-mock.js +218 -50
  263. package/dist/mcp-mock.js.map +1 -1
  264. package/dist/mcp-stub.cjs +5 -1
  265. package/dist/mcp-stub.d.cts +3 -1
  266. package/dist/mcp-stub.d.ts +3 -1
  267. package/dist/mcp-stub.js +3 -1
  268. package/dist/mcp-types.d.cts +6 -0
  269. package/dist/mcp-types.d.ts +6 -0
  270. package/dist/message-text.cjs +192 -0
  271. package/dist/message-text.cjs.map +1 -0
  272. package/dist/message-text.d.cts +31 -0
  273. package/dist/message-text.d.cts.map +1 -0
  274. package/dist/message-text.d.ts +31 -0
  275. package/dist/message-text.d.ts.map +1 -0
  276. package/dist/message-text.js +184 -0
  277. package/dist/message-text.js.map +1 -0
  278. package/dist/messages.cjs +49 -7
  279. package/dist/messages.cjs.map +1 -1
  280. package/dist/messages.d.cts.map +1 -1
  281. package/dist/messages.d.ts.map +1 -1
  282. package/dist/messages.js +51 -9
  283. package/dist/messages.js.map +1 -1
  284. package/dist/metrics.cjs +278 -45
  285. package/dist/metrics.cjs.map +1 -1
  286. package/dist/metrics.d.cts +17 -7
  287. package/dist/metrics.d.cts.map +1 -1
  288. package/dist/metrics.d.ts +17 -7
  289. package/dist/metrics.d.ts.map +1 -1
  290. package/dist/metrics.js +270 -29
  291. package/dist/metrics.js.map +1 -1
  292. package/dist/moderation.cjs +10 -1
  293. package/dist/moderation.cjs.map +1 -1
  294. package/dist/moderation.d.cts.map +1 -1
  295. package/dist/moderation.d.ts.map +1 -1
  296. package/dist/moderation.js +10 -1
  297. package/dist/moderation.js.map +1 -1
  298. package/dist/ollama.cjs +10 -6
  299. package/dist/ollama.cjs.map +1 -1
  300. package/dist/ollama.d.cts.map +1 -1
  301. package/dist/ollama.d.ts.map +1 -1
  302. package/dist/ollama.js +11 -7
  303. package/dist/ollama.js.map +1 -1
  304. package/dist/openapi.cjs +3405 -0
  305. package/dist/openapi.cjs.map +1 -0
  306. package/dist/openapi.d.cts +30 -0
  307. package/dist/openapi.d.cts.map +1 -0
  308. package/dist/openapi.d.ts +30 -0
  309. package/dist/openapi.d.ts.map +1 -0
  310. package/dist/openapi.js +3404 -0
  311. package/dist/openapi.js.map +1 -0
  312. package/dist/openrouter-video.cjs +9 -9
  313. package/dist/openrouter-video.cjs.map +1 -1
  314. package/dist/openrouter-video.d.cts.map +1 -1
  315. package/dist/openrouter-video.d.ts.map +1 -1
  316. package/dist/openrouter-video.js +10 -10
  317. package/dist/openrouter-video.js.map +1 -1
  318. package/dist/recorder.cjs +54 -10
  319. package/dist/recorder.cjs.map +1 -1
  320. package/dist/recorder.d.cts.map +1 -1
  321. package/dist/recorder.d.ts.map +1 -1
  322. package/dist/recorder.js +52 -12
  323. package/dist/recorder.js.map +1 -1
  324. package/dist/responses.cjs +47 -7
  325. package/dist/responses.cjs.map +1 -1
  326. package/dist/responses.d.cts.map +1 -1
  327. package/dist/responses.d.ts.map +1 -1
  328. package/dist/responses.js +48 -9
  329. package/dist/responses.js.map +1 -1
  330. package/dist/route-registry.cjs +951 -0
  331. package/dist/route-registry.cjs.map +1 -0
  332. package/dist/route-registry.d.cts +33 -0
  333. package/dist/route-registry.d.cts.map +1 -0
  334. package/dist/route-registry.d.ts +33 -0
  335. package/dist/route-registry.d.ts.map +1 -0
  336. package/dist/route-registry.js +866 -0
  337. package/dist/route-registry.js.map +1 -0
  338. package/dist/router.cjs +21 -34
  339. package/dist/router.cjs.map +1 -1
  340. package/dist/router.d.cts +4 -1
  341. package/dist/router.d.cts.map +1 -1
  342. package/dist/router.d.ts +4 -1
  343. package/dist/router.d.ts.map +1 -1
  344. package/dist/router.js +21 -35
  345. package/dist/router.js.map +1 -1
  346. package/dist/server.cjs +1252 -777
  347. package/dist/server.cjs.map +1 -1
  348. package/dist/server.d.cts +5 -1
  349. package/dist/server.d.cts.map +1 -1
  350. package/dist/server.d.ts +5 -1
  351. package/dist/server.d.ts.map +1 -1
  352. package/dist/server.js +1185 -710
  353. package/dist/server.js.map +1 -1
  354. package/dist/speech.cjs +6 -4
  355. package/dist/speech.cjs.map +1 -1
  356. package/dist/speech.js +7 -5
  357. package/dist/speech.js.map +1 -1
  358. package/dist/suite.cjs +1 -1
  359. package/dist/suite.js +1 -1
  360. package/dist/transcription.cjs +6 -6
  361. package/dist/transcription.cjs.map +1 -1
  362. package/dist/transcription.d.cts.map +1 -1
  363. package/dist/transcription.d.ts.map +1 -1
  364. package/dist/transcription.js +7 -7
  365. package/dist/transcription.js.map +1 -1
  366. package/dist/types.cjs +18 -0
  367. package/dist/types.cjs.map +1 -0
  368. package/dist/types.d.cts +320 -17
  369. package/dist/types.d.cts.map +1 -1
  370. package/dist/types.d.ts +320 -17
  371. package/dist/types.d.ts.map +1 -1
  372. package/dist/types.js +17 -0
  373. package/dist/types.js.map +1 -0
  374. package/dist/validate-cli.cjs +983 -0
  375. package/dist/validate-cli.cjs.map +1 -0
  376. package/dist/validate-cli.js +982 -0
  377. package/dist/validate-cli.js.map +1 -0
  378. package/dist/vector-stores.cjs +1180 -0
  379. package/dist/vector-stores.cjs.map +1 -0
  380. package/dist/vector-stores.d.cts +106 -0
  381. package/dist/vector-stores.d.cts.map +1 -0
  382. package/dist/vector-stores.d.ts +106 -0
  383. package/dist/vector-stores.d.ts.map +1 -0
  384. package/dist/vector-stores.js +1164 -0
  385. package/dist/vector-stores.js.map +1 -0
  386. package/dist/vector-types.d.cts.map +1 -1
  387. package/dist/vector-types.d.ts.map +1 -1
  388. package/dist/veo-video.cjs +13 -13
  389. package/dist/veo-video.cjs.map +1 -1
  390. package/dist/veo-video.js +14 -14
  391. package/dist/veo-video.js.map +1 -1
  392. package/dist/video.cjs +23 -4
  393. package/dist/video.cjs.map +1 -1
  394. package/dist/video.d.cts +1 -1
  395. package/dist/video.d.cts.map +1 -1
  396. package/dist/video.d.ts +1 -1
  397. package/dist/video.d.ts.map +1 -1
  398. package/dist/video.js +24 -5
  399. package/dist/video.js.map +1 -1
  400. package/dist/vitest.cjs +23 -11
  401. package/dist/vitest.cjs.map +1 -1
  402. package/dist/vitest.d.cts +5 -2
  403. package/dist/vitest.d.cts.map +1 -1
  404. package/dist/vitest.d.ts +5 -2
  405. package/dist/vitest.d.ts.map +1 -1
  406. package/dist/vitest.js +25 -13
  407. package/dist/vitest.js.map +1 -1
  408. package/dist/watcher.cjs +2 -1
  409. package/dist/watcher.cjs.map +1 -1
  410. package/dist/watcher.js +2 -1
  411. package/dist/watcher.js.map +1 -1
  412. package/dist/ws-framing.cjs +150 -35
  413. package/dist/ws-framing.cjs.map +1 -1
  414. package/dist/ws-framing.d.cts +18 -3
  415. package/dist/ws-framing.d.cts.map +1 -1
  416. package/dist/ws-framing.d.ts +18 -3
  417. package/dist/ws-framing.d.ts.map +1 -1
  418. package/dist/ws-framing.js +151 -36
  419. package/dist/ws-framing.js.map +1 -1
  420. package/dist/ws-gemini-live.cjs +2 -2
  421. package/dist/ws-gemini-live.js +2 -2
  422. package/dist/ws-live.cjs +401 -0
  423. package/dist/ws-live.cjs.map +1 -0
  424. package/dist/ws-live.js +400 -0
  425. package/dist/ws-live.js.map +1 -0
  426. package/dist/ws-realtime.cjs +46 -2
  427. package/dist/ws-realtime.cjs.map +1 -1
  428. package/dist/ws-realtime.d.cts.map +1 -1
  429. package/dist/ws-realtime.d.ts.map +1 -1
  430. package/dist/ws-realtime.js +46 -2
  431. package/dist/ws-realtime.js.map +1 -1
  432. package/dist/ws-responses.cjs +16 -4
  433. package/dist/ws-responses.cjs.map +1 -1
  434. package/dist/ws-responses.js +16 -4
  435. package/dist/ws-responses.js.map +1 -1
  436. package/dist/ws-upstream.cjs +118 -0
  437. package/dist/ws-upstream.cjs.map +1 -0
  438. package/dist/ws-upstream.js +115 -0
  439. package/dist/ws-upstream.js.map +1 -0
  440. package/fixtures/openai-live-client.json +390 -0
  441. package/fixtures/openai-live-managed.json +709 -0
  442. package/package.json +4 -1
@@ -0,0 +1,982 @@
1
+ import { build, msg, plainText } from "./message-text.js";
2
+ import { entryToFixture, hasMcpFakesKey, renderValidationRef, validateFixtures } from "./fixture-loader.js";
3
+ import { Logger } from "./logger.js";
4
+ import { McpFakeStore, McpFakesAddError, validateMcpFakes } from "./mcp-fakes.js";
5
+ import { readFileSync, readdirSync, realpathSync, statSync } from "node:fs";
6
+ import { join, relative, resolve, sep } from "node:path";
7
+ import { format, parseArgs } from "node:util";
8
+
9
+ //#region src/validate-cli.ts
10
+ /**
11
+ * `aimock validate` subcommand — offline fixture lint.
12
+ *
13
+ * Usage: `aimock validate [--strict] [--json] [--] <path> [more paths ...]`
14
+ *
15
+ * Each path is a fixture file or a directory; directories are walked
16
+ * recursively for `*.json` in the same order `--fixtures <dir>` loads them.
17
+ * For each file: read bytes, JSON-parse, require a top-level
18
+ * `{ "fixtures": [...] }` envelope, convert the entries (surfacing the
19
+ * per-entry conversion warnings the server logs), then run the
20
+ * `validateFixtures` rules over that file's entries alone, so its findings
21
+ * are attributed to it.
22
+ *
23
+ * `validateFixtures` is then run a SECOND time over the union of every
24
+ * successfully-parsed file's entries, in load order. Its rules are not all
25
+ * per-fixture: `duplicate userMessage` and the catch-all ordering check look
26
+ * at the other fixtures in the array they are given. Run per file those two
27
+ * cannot see across files, so the findings the union pass adds — a
28
+ * `userMessage` duplicated in two files, a catch-all that is last in its own
29
+ * file but not last overall — are the cross-file ones. They are reported
30
+ * against the file that owns the fixture, with the other file named in the
31
+ * message; findings the per-file pass already made are not repeated.
32
+ *
33
+ * How this compares to the server's `--validate-on-load`, in both directions:
34
+ * - Stricter: there an unreadable, unparseable or wrong-shape file is
35
+ * non-fatal — it warns on stderr, contributes zero fixtures, and startup
36
+ * continues as long as the run loaded at least one fixture from somewhere.
37
+ * Here every such file fails the run — with one deliberate exception, for
38
+ * parity: a `*.json` file the WALK turned up that parses but carries no
39
+ * top-level `fixtures` array is not a fixture file (this package's own
40
+ * `fixtures/` tree holds aimock config files alongside fixtures), and is
41
+ * passed over with a note, exactly as the loader passes over it. A file
42
+ * the caller NAMES is still validated, wrong shape and all. Two walk
43
+ * hazards the server does not
44
+ * survive are refused outright rather than mirrored: a `*.json` path that
45
+ * is not a regular file (a FIFO, a socket, a device) is a per-file error
46
+ * here, where the server's `readFileSync` blocks on it forever; and a
47
+ * directory symlink that points back at a directory already being walked
48
+ * is reported once as a cycle, where the server recurses through it until
49
+ * the kernel returns ELOOP (~32 levels deep) and loads those levels'
50
+ * fixtures over and over. Malformed scalar or array matches are rejected
51
+ * before conversion, as they are by the server's fixture loader. The lint
52
+ * reports an entry error and continues validating valid siblings.
53
+ * - Equal: the `validateFixtures` rules themselves, because of the union
54
+ * pass above, and the zero-fixture rule — a run whose inputs yield no
55
+ * fixtures at all is an error here, matching the server's "No fixtures
56
+ * loaded and validation/strict mode is enabled — aborting." A single
57
+ * `{"fixtures": []}` file alongside files that do load fixtures is an
58
+ * error in neither place. Equal too in what the inputs expand to: a path
59
+ * named twice, and a directory reached both directly and through an
60
+ * acyclic symlink to it, are validated once per mention, exactly as the
61
+ * server loads one `--fixtures` source per mention — so the duplicate
62
+ * fixtures that produces are reported here as the server reports them,
63
+ * one finding per (fixture, rule), the same count the server logs.
64
+ *
65
+ * A path mentioned more than once in one run is therefore several DIFFERENT
66
+ * loads that happen to share a name, and printing that bare name for each of
67
+ * them made them indistinguishable: a warning read as if a fixture shadowed
68
+ * itself. Each mention is numbered, and every rendering surface carries that
69
+ * number — human lines and their summary, cross-file references, and a
70
+ * `mention` field on each `--json` `files[]` entry. The `<path>[<n>]` suffix
71
+ * is printed only for a path that IS mentioned more than once, because for
72
+ * every other path the name alone already names one load; the `--json` field
73
+ * is always present so a consumer never has to infer it.
74
+ * - Weaker: this is a static lint. It never starts a server, so it covers
75
+ * nothing about binding, remote `--fixtures <url>` sources (it reads local
76
+ * paths only), `--watch` reloads, or any runtime behaviour.
77
+ *
78
+ * Nothing the filesystem or a fixture entry can do is allowed to escape this
79
+ * function: a malformed entry, an unreadable path, a stat failure or a symlink
80
+ * cycle each becomes a per-file `[error]` in the report, and a crash inside
81
+ * either `validateFixtures` pass becomes a file-level or run-level `[error]`,
82
+ * so the run still emits a report (valid JSON under `--json`) and still exits
83
+ * 1. Run-level errors print after the per-file output, and the "no fixtures
84
+ * loaded" one is withheld when a file already reported why it loaded none.
85
+ *
86
+ * Prints human lines by default (`file: [error|warning] #i message`) or a
87
+ * JSON document with `--json`. Everything that contributes to a non-zero exit
88
+ * goes to stderr, so a CI log's stderr always shows the reason; `--json` keeps
89
+ * stdout to the report alone and puts the reason on stderr. The two modes
90
+ * report the same facts: a fatal file is one record that both the stdout
91
+ * tally and `files[].errors` count, and `--json` emits a document for a usage
92
+ * error too — stdout is never empty on a `--json` run, whatever failed it.
93
+ * A path naming a remote source (`https://...`) is refused as unsupported
94
+ * rather than read as a filename. Exit codes:
95
+ * 0 = clean (warnings allowed unless `--strict`), 1 = everything that fails
96
+ * the run — errors / unreadable / unparseable / wrong shape / unwalkable path
97
+ * / no fixtures loaded at all, and a usage error (no paths or an unknown
98
+ * option) too, because every other CLI surface in this package exits 1 on a
99
+ * usage error and nothing here uses sysexits codes. `--help` is handled
100
+ * separately and exits 0.
101
+ */
102
+ const VALIDATE_HELP = `
103
+ Usage: aimock validate [options] [--] <path> [more paths ...]
104
+
105
+ Validate aimock fixture files offline. Each path is a fixture file or a
106
+ directory of them (walked recursively for *.json, like --fixtures <dir>).
107
+ Files are checked one at a time and then as one combined set, so the rules
108
+ that span files -- a userMessage duplicated across two files, a catch-all
109
+ that is not last overall -- are reported here as the server reports them.
110
+
111
+ Where the server's --validate-on-load differs: there an unreadable,
112
+ unparseable or wrong-shape file only warns and startup continues, while here
113
+ every such file fails the run. The one exception, which matches the loader: a
114
+ *.json file found by WALKING a directory that has no top-level "fixtures"
115
+ array is not a fixture file (an aimock config, say) and is skipped with a
116
+ note -- a file you name on the command line is still validated. As on the
117
+ server, a run that loads no fixtures at all is an error. This is a static lint: it starts no server and reads
118
+ local paths only (no remote --fixtures URL).
119
+
120
+ A path given twice is validated twice, because the server loads one set of
121
+ fixtures per --fixtures it is given; the duplicate fixtures that produces are
122
+ reported as the server reports them, one finding per fixture and rule. Such a
123
+ path is printed as <path>[<n>], numbering its mentions from 1, so each load
124
+ and every reference to its fixtures names one of them (--json reports the
125
+ number as "mention" on every file). A directory symlink pointing back at a
126
+ directory already being walked is a symlink cycle and fails the run; one
127
+ pointing anywhere else is followed, as the server follows it.
128
+
129
+ Options:
130
+ --strict Treat warnings as errors (exit 1 on warnings)
131
+ --json Emit a JSON report instead of human lines
132
+ -h, --help Show this help message
133
+ -- Stop option parsing; every later argument is a path
134
+ (use this for a path that begins with "-")
135
+
136
+ Exit codes:
137
+ 0 all files valid (warnings allowed unless --strict)
138
+ 1 anything that failed the run: validation errors; a malformed fixture
139
+ entry; an unreadable or unparseable file; a named path of the wrong
140
+ shape (a walked one is skipped instead); a path that
141
+ cannot be stat'd, read or walked (including a symlink cycle, or a
142
+ *.json path that is not a regular file); a directory holding no *.json;
143
+ no fixtures loaded from any input; --strict warnings; or a usage error
144
+ (no paths given, or an unknown option)
145
+ `.trim();
146
+ /** The indices a ref names, in a fixed order, for identity purposes. */
147
+ function refIndices(ref) {
148
+ return ref.rule === "duplicate-user-message" ? [ref.shadows] : [ref.shadowsFrom, ref.shadowsThrough];
149
+ }
150
+ /**
151
+ * A path argument that names a remote source rather than a local file: any
152
+ * `scheme://` prefix, not just http(s), so `ftp://` and friends get the same
153
+ * explanation instead of a filesystem error. A Windows drive letter ("C:\\x")
154
+ * has no `//` and is not matched.
155
+ */
156
+ const REMOTE_SOURCE = /^[a-z][a-z0-9+.-]*:\/\//i;
157
+ /** Render an unknown thrown value as a one-line message. */
158
+ function errText(err) {
159
+ return err instanceof Error ? err.message : String(err);
160
+ }
161
+ /**
162
+ * Record why a file produced no report at all. A fatal is ONE fact, so it is
163
+ * written once, here, into both shapes that report it: `fatal`, which names
164
+ * the reason, and `errors`, which is what every tally — the human summary
165
+ * line, the `--json` consumer counting `files[].errors` — actually counts.
166
+ * Set on `fatal` alone, the two modes disagreed: stdout said "1 error(s)"
167
+ * while the same run's JSON said `"errors": []`, so a CI script adding up the
168
+ * JSON saw a clean run that had exited 1.
169
+ *
170
+ * The finding carries no `index`: a fatal is about the file, not an entry
171
+ * (see `Finding.index`).
172
+ */
173
+ function setFatal(report, message) {
174
+ report.fatal = message;
175
+ report.errors.push({ message });
176
+ }
177
+ /** A file that never got as far as a report, with its fatal already recorded. */
178
+ function fatalReport(file, mention, message) {
179
+ const report = {
180
+ file,
181
+ mention,
182
+ fixtures: 0,
183
+ errors: [],
184
+ warnings: []
185
+ };
186
+ setFatal(report, message);
187
+ return report;
188
+ }
189
+ /**
190
+ * Logger that routes `warn` AND `error` into caller-supplied sinks instead of
191
+ * the console, so the per-entry conversion diagnostics `entryToFixture` emits
192
+ * land in the report rather than being dropped on the floor — and, under
193
+ * `--json`, never interleave with the JSON document on stdout/stderr.
194
+ * Exported for tests only; it is not part of the package's public API.
195
+ * `info`/`debug` are inert: they are already below this logger's "warn" level,
196
+ * and silencing them explicitly keeps future call sites off stdout too.
197
+ */
198
+ var CollectingLogger = class CollectingLogger extends Logger {
199
+ warnSink;
200
+ errorSink;
201
+ constructor(warnSink, errorSink) {
202
+ super("warn");
203
+ this.warnSink = warnSink;
204
+ this.errorSink = errorSink;
205
+ }
206
+ /**
207
+ * Serialise exactly as the sink this logger replaces does — byte for byte.
208
+ * `Logger` writes `console.warn("[aimock]", ...args)`, and console's
209
+ * formatting IS `util.format`, so the call it makes is
210
+ * `format("[aimock]", ...args)`: `"[aimock]"` is the FORMAT STRING and holds
211
+ * no specifiers, which is what makes a caller's own `%s`/`%d` inert and its
212
+ * arguments plain trailing values. Calling `format(...args)` instead
213
+ * promoted the caller's message into the format slot — so a message that
214
+ * happened to contain `%s` (a fixture path, say) swallowed the next
215
+ * argument — and dropped the `[aimock]` prefix, leaving the report and the
216
+ * server's own stderr disagreeing about the same diagnostic.
217
+ * `util.inspect` still renders object arguments readably, which is what
218
+ * `String(a)` could not do.
219
+ */
220
+ static format(args) {
221
+ return format("[aimock]", ...args);
222
+ }
223
+ warn(...args) {
224
+ this.warnSink(CollectingLogger.format(args));
225
+ }
226
+ error(...args) {
227
+ this.errorSink(CollectingLogger.format(args));
228
+ }
229
+ info(...args) {}
230
+ debug(...args) {}
231
+ };
232
+ /**
233
+ * Why a `*.json` file the WALK turned up is not a fixture file, or
234
+ * `undefined` if it is one (or if the question cannot be answered cheaply).
235
+ *
236
+ * A directory is not a fixture directory: this package ships `fixtures/`
237
+ * holding both fixture files and eight aimock CONFIG files — the six
238
+ * `fixtures/examples/**\/*-config.json`, `full-suite.json`, and
239
+ * `agui/agui-text-response.json`, whose AG-UI fixtures sit NESTED under
240
+ * `agui` where `--fixtures` cannot see them — which is why the documented
241
+ * `aimock validate ./fixtures/` exited 1 on the package's own tree. The
242
+ * server has the same mixture to deal with and passes over it:
243
+ * `loadFixtureFile` warns "Missing or invalid \"fixtures\" array", returns no
244
+ * fixtures, and startup continues. This mirrors that skip, so a walked
245
+ * directory reports on the fixture files in it and says what it passed over.
246
+ *
247
+ * Non-fixture means the file carries no top-level `fixtures` key at all (or
248
+ * is an aimock config). A `fixtures` key that is present but not an array is
249
+ * a MALFORMED fixture file and still fails the run, as the loader would refuse
250
+ * it. The skip applies ONLY to files the walk discovered — a path the caller named explicitly is still validated, and a
251
+ * wrong-shape file there still fails the run, because naming a file is
252
+ * asking about that file.
253
+ *
254
+ * A file carrying an aimock config section (`configSections`) is named as
255
+ * what it is rather than by what it lacks, because "not a fixture file" on
256
+ * its own is read as "holds no fixtures" — false of `agui`-sectioned configs,
257
+ * which hold AG-UI fixtures that `aimock --config`, not `--fixtures`, serves.
258
+ *
259
+ * Unreadable and unparseable are deliberately NOT skips. Returning
260
+ * `undefined` for them hands the file to `validateOneFile`, which reports the
261
+ * real read error or JSON syntax error — a defect in any `*.json` file, and
262
+ * one no config file has an excuse for either.
263
+ */
264
+ function nonFixtureSkipReason(file) {
265
+ let parsed;
266
+ try {
267
+ parsed = JSON.parse(readFileSync(file, "utf-8"));
268
+ } catch {
269
+ return;
270
+ }
271
+ if (hasMcpFakesKey(parsed)) return void 0;
272
+ const asConfig = aimockConfigDescription(parsed);
273
+ if (asConfig !== void 0) return `not a fixture file — ${asConfig}`;
274
+ if (typeof parsed === "object" && parsed !== null && "fixtures" in parsed) return void 0;
275
+ return "not a fixture file — no top-level \"fixtures\" key";
276
+ }
277
+ /**
278
+ * The mock sections of `AimockConfig` (config-loader.ts). An object carrying
279
+ * any of them is an aimock config file: `aimock --config <path>` starts a
280
+ * server from it, while `--fixtures <path>` loads nothing from it.
281
+ */
282
+ const CONFIG_SECTIONS = [
283
+ "llm",
284
+ "mcp",
285
+ "a2a",
286
+ "agui",
287
+ "vector",
288
+ "services"
289
+ ];
290
+ /**
291
+ * What a parsed-but-not-fixture-shaped JSON document IS, when it is an aimock
292
+ * config file, or `undefined` when it is not one. Used by both the walk's skip
293
+ * note and the fatal a NAMED file of that shape gets, so the two surfaces
294
+ * describe the same file the same way. The sections found are listed, so an
295
+ * `agui` config is never described as a file holding no fixtures — it holds
296
+ * AG-UI ones, nested where the fixture loader does not look.
297
+ */
298
+ function aimockConfigDescription(parsed) {
299
+ if (typeof parsed !== "object" || parsed === null) return void 0;
300
+ const doc = parsed;
301
+ const sections = CONFIG_SECTIONS.filter((key) => typeof doc[key] === "object" && doc[key]);
302
+ if (sections.length === 0) return void 0;
303
+ return `an aimock config file (${sections.join(", ")}), which "aimock --config" serves and "--fixtures" does not load`;
304
+ }
305
+ /**
306
+ * Collect `*.json` files under `dirPath`, recursing into subdirectories.
307
+ * Mirrors `loadFixturesFromDir`: within a directory the `*.json` files come
308
+ * first in sorted order, then its subdirectories in sorted order, so the
309
+ * reported order matches the server's load order, and the same stat-error
310
+ * handling — a vanished entry (ENOENT) is skipped silently, every other
311
+ * failure is surfaced. Unlike the loader, which only warns, each surfaced
312
+ * failure becomes a `fatal` entry that fails the run, and it is emitted in
313
+ * walk position (an unreadable subdirectory is reported where that
314
+ * subdirectory was reached, not after every file in the tree) so the report
315
+ * reads in encounter order. Entries that are neither directories nor
316
+ * `*.json` files are ignored, as they are by the loader.
317
+ *
318
+ * `ancestors` holds the real paths of the directories this call is nested
319
+ * inside. A directory whose real path is one of them closes a symlink cycle
320
+ * and is reported instead of walked; the server has no such guard and
321
+ * recurses through the cycle until the kernel returns ELOOP. A repeat visit
322
+ * that is NOT an ancestor — `root/link -> root/sub` alongside `root/sub` — is
323
+ * no cycle: it is walked again, because the server walks it again and loads
324
+ * those fixtures twice.
325
+ *
326
+ * A `*.json` entry that is not a regular file (a FIFO, a socket, a device)
327
+ * is a `fatal` entry rather than a target, because reading it is what the
328
+ * containment promise above cannot keep: `readFileSync` on a FIFO with no
329
+ * writer blocks forever, as it does on the server.
330
+ */
331
+ function collectJsonFiles(dirPath, ancestors, out = []) {
332
+ let realPath;
333
+ try {
334
+ realPath = realpathSync(dirPath);
335
+ } catch (err) {
336
+ out.push({
337
+ file: dirPath,
338
+ fatal: `Could not resolve directory: ${errText(err)}`
339
+ });
340
+ return out;
341
+ }
342
+ if (ancestors.includes(realPath)) {
343
+ out.push({
344
+ file: dirPath,
345
+ fatal: `Symlink cycle detected: already walking ${realPath}`
346
+ });
347
+ return out;
348
+ }
349
+ let names;
350
+ try {
351
+ names = readdirSync(dirPath);
352
+ } catch (err) {
353
+ out.push({
354
+ file: dirPath,
355
+ fatal: `Could not read directory: ${errText(err)}`
356
+ });
357
+ return out;
358
+ }
359
+ const subdirs = [];
360
+ for (const name of [...names].sort()) {
361
+ const fullPath = join(dirPath, name);
362
+ let stats;
363
+ try {
364
+ stats = statSync(fullPath);
365
+ } catch (err) {
366
+ if (err.code !== "ENOENT") out.push({
367
+ file: fullPath,
368
+ fatal: `Could not stat: ${errText(err)}`
369
+ });
370
+ continue;
371
+ }
372
+ if (stats.isDirectory()) subdirs.push(name);
373
+ else if (!name.endsWith(".json")) continue;
374
+ else if (stats.isFile()) {
375
+ const skipped = nonFixtureSkipReason(fullPath);
376
+ out.push(skipped === void 0 ? { file: fullPath } : {
377
+ file: fullPath,
378
+ skipped
379
+ });
380
+ } else out.push({
381
+ file: fullPath,
382
+ fatal: "Not a regular file"
383
+ });
384
+ }
385
+ const chain = [...ancestors, realPath];
386
+ for (const sub of subdirs) collectJsonFiles(join(dirPath, sub), chain, out);
387
+ return out;
388
+ }
389
+ /** The entry shape the loader and the server both assume, quoted verbatim. */
390
+ const ENTRY_SHAPE = "every entry needs { \"match\": { ... }, \"response\": { ... } }";
391
+ /** Name a value the way a fixture author would read it back in their JSON. */
392
+ function gotText(value) {
393
+ if (value === null) return "null";
394
+ if (value === void 0) return "absent";
395
+ if (Array.isArray(value)) return "an array";
396
+ return `a ${typeof value}`;
397
+ }
398
+ /**
399
+ * Classify a raw entry's shape, or return `undefined` when nothing about it is
400
+ * worth saying. Runs before `entryToFixture`, so every branch below is driven
401
+ * by the entry itself rather than by whichever exception the conversion
402
+ * happened to throw.
403
+ *
404
+ * A missing or non-object `response` is deliberately NOT classified here: the
405
+ * conversion accepts it (`{ ...undefined }` is `{}`), the server accepts it,
406
+ * and the `validateFixtures` rules already reject it by name — "response is
407
+ * not a recognized type (must have content, toolCalls, ...)" — which is the
408
+ * more actionable message of the two. Saying it here as well would report one
409
+ * defect twice. It is still named alongside `match` when `match` is fatal,
410
+ * because then the rules never run on the entry at all and an author fixing
411
+ * `{}` would otherwise need one round trip per missing key.
412
+ */
413
+ function classifyEntry(entry) {
414
+ if (entry === null || typeof entry !== "object" || Array.isArray(entry)) return {
415
+ severity: "error",
416
+ convertible: false,
417
+ why: `entry is ${gotText(entry)}, expected an object — ${ENTRY_SHAPE}`
418
+ };
419
+ const match = entry.match;
420
+ if (match === null || match === void 0) return {
421
+ severity: "error",
422
+ convertible: false,
423
+ why: `missing or non-object ${["match", "response"].filter((key) => {
424
+ const value = entry[key];
425
+ return value === null || typeof value !== "object" || Array.isArray(value);
426
+ }).map((k) => `"${k}"`).join(" and ")} — ${ENTRY_SHAPE}`
427
+ };
428
+ if (typeof match !== "object" || Array.isArray(match)) return {
429
+ severity: "error",
430
+ convertible: false,
431
+ why: `"match" is ${gotText(match)}, expected an object — ${ENTRY_SHAPE}`
432
+ };
433
+ }
434
+ /**
435
+ * The backstop for an entry `classifyEntry` passed and `entryToFixture` threw
436
+ * on anyway (a `toolCalls: [null]`, say, which `normalizeResponse` walks).
437
+ * Which entry it was is the actionable half, so that leads; the raw thrown
438
+ * text follows as `detail`, which `--json` carries as its own field and the
439
+ * human report prints on an indented continuation line. It used to say
440
+ * `see "detail"`, naming a field only the `--json` report has — in human mode
441
+ * that pointed at nothing at all.
442
+ */
443
+ function unexpectedEntryFailure(index, err) {
444
+ return {
445
+ index,
446
+ message: `Invalid fixture entry #${index}: could not be converted to a fixture`,
447
+ detail: errText(err)
448
+ };
449
+ }
450
+ /**
451
+ * Validate one fixture file into a report. Every failure mode — unreadable,
452
+ * unparseable, wrong shape, or a single malformed entry — is recorded in the
453
+ * returned report rather than thrown.
454
+ *
455
+ * The converted fixtures are handed back alongside the report, with
456
+ * `indices[i]` giving the entry index `fixtures[i]` was converted from, so the
457
+ * cross-file union pass can append them and map its findings back to a file
458
+ * and an entry index.
459
+ */
460
+ function validateOneFile(file, mention, source) {
461
+ const report = {
462
+ file,
463
+ mention,
464
+ fixtures: 0,
465
+ errors: [],
466
+ warnings: []
467
+ };
468
+ const fixtures = [];
469
+ const sourceIndex = [];
470
+ const runErrors = [];
471
+ const identities = [];
472
+ const mcpFakes = [];
473
+ let raw;
474
+ try {
475
+ raw = readFileSync(file, "utf-8");
476
+ } catch (err) {
477
+ setFatal(report, `Could not read file: ${errText(err)}`);
478
+ return {
479
+ report,
480
+ fixtures,
481
+ indices: sourceIndex,
482
+ identities,
483
+ runErrors,
484
+ mcpFakes
485
+ };
486
+ }
487
+ let parsed;
488
+ try {
489
+ parsed = JSON.parse(raw);
490
+ } catch (err) {
491
+ setFatal(report, `Invalid JSON: ${errText(err)}`);
492
+ return {
493
+ report,
494
+ fixtures,
495
+ indices: sourceIndex,
496
+ identities,
497
+ runErrors,
498
+ mcpFakes
499
+ };
500
+ }
501
+ const fakesDoc = hasMcpFakesKey(parsed) ? parsed : void 0;
502
+ const fixturesLeftOut = fakesDoc !== void 0 && !Object.prototype.hasOwnProperty.call(fakesDoc, "fixtures");
503
+ const badShape = !fixturesLeftOut && (typeof parsed !== "object" || parsed === null || !Array.isArray(parsed.fixtures));
504
+ if (badShape) {
505
+ const asConfig = aimockConfigDescription(parsed);
506
+ setFatal(report, asConfig === void 0 ? "Missing or invalid \"fixtures\" array (expected { \"fixtures\": [...] })" : `Missing or invalid "fixtures" array (expected { "fixtures": [...] }) — this is ${asConfig}`);
507
+ }
508
+ if (fakesDoc !== void 0) {
509
+ const fakes = fakesDoc.mcpFakes;
510
+ const validation = validateMcpFakes(fakes, source);
511
+ report.errors.push(...validation.errors.map(loadErrorFinding));
512
+ report.mcpFakeBlocks = 0;
513
+ if (validation.errors.length > 0) report.warnings.push(...validation.warnings.map(issueFinding));
514
+ else if (Array.isArray(fakes)) fakes.forEach((block, blockIndex) => {
515
+ mcpFakes.push({
516
+ source,
517
+ blockIndex,
518
+ raw: block
519
+ });
520
+ });
521
+ else mcpFakes.push({
522
+ source,
523
+ blockIndex: null,
524
+ raw: fakes
525
+ });
526
+ }
527
+ if (fixturesLeftOut || badShape) return {
528
+ report,
529
+ fixtures,
530
+ indices: sourceIndex,
531
+ identities,
532
+ runErrors,
533
+ mcpFakes
534
+ };
535
+ let entryIndex = 0;
536
+ const entryLogger = new CollectingLogger((message) => report.warnings.push({
537
+ index: entryIndex,
538
+ message
539
+ }), (message) => report.errors.push({
540
+ index: entryIndex,
541
+ message
542
+ }));
543
+ const entries = parsed.fixtures;
544
+ for (let index = 0; index < entries.length; index++) {
545
+ entryIndex = index;
546
+ const defect = classifyEntry(entries[index]);
547
+ if (defect !== void 0) {
548
+ const label = defect.severity === "error" ? "Invalid fixture entry" : "Fixture entry";
549
+ const finding = {
550
+ index,
551
+ message: `${label} #${index}: ${defect.why}`
552
+ };
553
+ if (!defect.convertible) {
554
+ report.errors.push(finding);
555
+ continue;
556
+ }
557
+ report.warnings.push(finding);
558
+ }
559
+ try {
560
+ fixtures.push(entryToFixture(entries[index], entryLogger));
561
+ sourceIndex.push(index);
562
+ } catch (err) {
563
+ report.errors.push(unexpectedEntryFailure(index, err));
564
+ }
565
+ }
566
+ report.fixtures = fixtures.length;
567
+ const unresolved = /* @__PURE__ */ new Set();
568
+ const toEntryIndex = (fixtureIndex) => {
569
+ const entry = sourceIndex[fixtureIndex];
570
+ if (entry !== void 0) return entry;
571
+ if (!unresolved.has(fixtureIndex)) {
572
+ unresolved.add(fixtureIndex);
573
+ runErrors.push(`finding for fixture index ${fixtureIndex}, which maps to no entry in this file`);
574
+ }
575
+ return fixtureIndex;
576
+ };
577
+ try {
578
+ for (const r of validateFixtures(fixtures)) {
579
+ const index = toEntryIndex(r.fixtureIndex);
580
+ const refs = r.ref === void 0 ? [] : refIndices(r.ref).map(toEntryIndex);
581
+ const finding = {
582
+ index,
583
+ message: r.ref === void 0 ? r.message : renderValidationRef(r.ref, (i) => String(toEntryIndex(i)))
584
+ };
585
+ identities.push({
586
+ severity: r.severity,
587
+ index,
588
+ kind: r.ref === void 0 ? `message:${r.message}` : r.ref.rule,
589
+ refs,
590
+ finding
591
+ });
592
+ if (r.severity === "error") report.errors.push(finding);
593
+ else report.warnings.push(finding);
594
+ }
595
+ } catch (err) {
596
+ report.errors.push({ message: `Validation failed for this file: ${errText(err)}` });
597
+ }
598
+ return {
599
+ report,
600
+ fixtures,
601
+ indices: sourceIndex,
602
+ identities,
603
+ runErrors,
604
+ mcpFakes
605
+ };
606
+ }
607
+ /**
608
+ * A `FixtureLoadError` from an `mcpFakes` block as a file-level finding (no
609
+ * fixture entry index): its message names the rule, file, block and entry.
610
+ */
611
+ function loadErrorFinding(err) {
612
+ return { message: err.message };
613
+ }
614
+ /** An L8 shadowed-entry warning as a file-level finding. */
615
+ function issueFinding(issue) {
616
+ return { message: issue.message };
617
+ }
618
+ /**
619
+ * `#<index> ` for a finding that belongs to one entry; empty for a file-level
620
+ * finding, which names no entry (see Finding.index). Shared by the human lines
621
+ * and the failure summary so a reader of either can locate the same entry.
622
+ */
623
+ const findingAt = (f) => f.index === void 0 ? "" : `#${f.index} `;
624
+ /**
625
+ * One-line reason a run failed, for the stderr side of `--json` output.
626
+ *
627
+ * It NAMES the failure first — the file and the finding that caused the
628
+ * non-zero exit — and only then totals what else failed, because the line is
629
+ * often the single line a CI log shows. Leading with a fixed list of counts
630
+ * put two zeros ("0 unreadable/invalid file(s), 0 file(s) with errors") in
631
+ * front of every strict-warning failure, where the reader has to get past the
632
+ * things that did NOT happen to reach the one that did. Counts that are zero
633
+ * are omitted for the same reason, and a file whose fatal is already the lead
634
+ * is counted as unreadable/invalid only, not a second time under "with
635
+ * errors" — its fatal now rides in `errors` as well (see `setFatal`).
636
+ */
637
+ function summarizeFailure(reports, strict, runErrors, name) {
638
+ const fatalFiles = reports.filter((r) => r.fatal !== void 0);
639
+ const erroredFiles = reports.filter((r) => r.fatal === void 0 && r.errors.length > 0);
640
+ const warnedFiles = reports.filter((r) => r.warnings.length > 0);
641
+ let lead;
642
+ if (fatalFiles[0] !== void 0) lead = `${name(fatalFiles[0])}: ${fatalFiles[0].fatal}`;
643
+ else if (erroredFiles[0] !== void 0) lead = `${name(erroredFiles[0])}: ${findingAt(erroredFiles[0].errors[0])}${erroredFiles[0].errors[0].message}`;
644
+ else if (runErrors[0] !== void 0) lead = runErrors[0];
645
+ else if (warnedFiles[0] !== void 0) lead = `${name(warnedFiles[0])}: ${findingAt(warnedFiles[0].warnings[0])}${warnedFiles[0].warnings[0].message} (--strict)`;
646
+ else lead = "the run failed";
647
+ const counts = [];
648
+ if (fatalFiles.length > 0) counts.push(`${fatalFiles.length} unreadable/invalid file(s)`);
649
+ if (erroredFiles.length > 0) counts.push(`${erroredFiles.length} file(s) with errors`);
650
+ if (runErrors.length > 0) counts.push(`${runErrors.length} run-level error(s)`);
651
+ if (strict && warnedFiles.length > 0) counts.push(`${warnedFiles.length} file(s) with warnings (--strict)`);
652
+ return `Error: fixture validation failed — ${lead} [${counts.join(", ")}].`;
653
+ }
654
+ function runValidateCli(deps = {}) {
655
+ const argv = deps.argv ?? process.argv.slice(2);
656
+ const log = deps.log ?? console.log.bind(console);
657
+ const logError = deps.logError ?? console.error.bind(console);
658
+ const exit = deps.exit ?? process.exit.bind(process);
659
+ /**
660
+ * Is `flag` present as an OPTION in argv — i.e. before the `--` terminator,
661
+ * after which every argument is a path? Needed because a usage error can be
662
+ * a `parseArgs` throw, which leaves no parsed `values` to consult, and the
663
+ * output mode still has to be honoured. `--flag=value` counts: these are all
664
+ * boolean options, so giving one a value IS the usage error being reported,
665
+ * and matching the bare token alone answered "no `--json` here" for the one
666
+ * argv that most obviously asked for JSON — leaving stdout empty.
667
+ */
668
+ const flagInArgv = (flag) => {
669
+ for (const arg of argv) {
670
+ if (arg === "--") return false;
671
+ if (arg === flag || arg.startsWith(`${flag}=`)) return true;
672
+ }
673
+ return false;
674
+ };
675
+ /**
676
+ * A usage error, in whichever mode the argv asked for. `--json` promises
677
+ * "one document on stdout" (README), and a run that fails on its own argv is
678
+ * still a run: emitting nothing there handed a CI job parsing stdout an
679
+ * empty buffer — a JSON parse error standing in for a perfectly ordinary
680
+ * "no paths given". The document reports the usage error the same way a
681
+ * run-level error is reported, so one consumer shape reads both. The
682
+ * human-readable reason plus the help text stay on stderr in both modes, so
683
+ * `--json` stdout is still the document alone.
684
+ */
685
+ const usageError = (message) => {
686
+ logError(`Error: ${message}\n\n${VALIDATE_HELP}`);
687
+ if (flagInArgv("--json")) log(JSON.stringify({
688
+ strict: flagInArgv("--strict"),
689
+ failed: true,
690
+ files: [],
691
+ run: {
692
+ fixtures: 0,
693
+ mcpFakeBlocks: 0,
694
+ errors: [message]
695
+ }
696
+ }, null, 2));
697
+ exit(1);
698
+ };
699
+ let values;
700
+ let paths;
701
+ try {
702
+ const parsed = parseArgs({
703
+ args: argv,
704
+ options: {
705
+ strict: {
706
+ type: "boolean",
707
+ default: false
708
+ },
709
+ json: {
710
+ type: "boolean",
711
+ default: false
712
+ },
713
+ help: {
714
+ type: "boolean",
715
+ short: "h",
716
+ default: false
717
+ }
718
+ },
719
+ strict: true,
720
+ allowPositionals: true
721
+ });
722
+ values = parsed.values;
723
+ paths = parsed.positionals;
724
+ } catch (err) {
725
+ usageError(err instanceof Error ? err.message : String(err));
726
+ return;
727
+ }
728
+ if (values.help === true) {
729
+ log(values.json === true ? JSON.stringify({ help: VALIDATE_HELP }, null, 2) : VALIDATE_HELP);
730
+ exit(0);
731
+ return;
732
+ }
733
+ const strict = values.strict === true;
734
+ const json = values.json === true;
735
+ if (paths.length === 0) {
736
+ usageError("no fixture paths given.");
737
+ return;
738
+ }
739
+ const targets = [];
740
+ for (const path of paths) {
741
+ if (REMOTE_SOURCE.test(path)) {
742
+ targets.push({
743
+ file: path,
744
+ fatal: "Remote fixture source: this lint reads local paths only (the server's --fixtures accepts a URL; validate does not) — download the file and validate the local copy"
745
+ });
746
+ continue;
747
+ }
748
+ let stats;
749
+ try {
750
+ stats = statSync(path);
751
+ } catch (err) {
752
+ if (err.code === "ENOENT") targets.push({ file: path });
753
+ else targets.push({
754
+ file: path,
755
+ fatal: `Could not stat: ${errText(err)}`
756
+ });
757
+ continue;
758
+ }
759
+ if (!stats.isDirectory()) {
760
+ if (stats.isFile()) targets.push({ file: path });
761
+ else targets.push({
762
+ file: path,
763
+ fatal: "Not a regular file"
764
+ });
765
+ continue;
766
+ }
767
+ const entries = collectJsonFiles(path, []);
768
+ if (entries.length === 0) {
769
+ targets.push({
770
+ file: path,
771
+ fatal: "No .json fixture files found in directory"
772
+ });
773
+ continue;
774
+ }
775
+ for (const entry of entries) targets.push({
776
+ ...entry,
777
+ source: relative(path, entry.file).split(sep).join("/")
778
+ });
779
+ }
780
+ const mentionKey = (file) => resolve(file);
781
+ const mentionCount = /* @__PURE__ */ new Map();
782
+ for (const target of targets) mentionCount.set(mentionKey(target.file), (mentionCount.get(mentionKey(target.file)) ?? 0) + 1);
783
+ const mentionsSoFar = /* @__PURE__ */ new Map();
784
+ const nextMention = (file) => {
785
+ const mention = (mentionsSoFar.get(mentionKey(file)) ?? 0) + 1;
786
+ mentionsSoFar.set(mentionKey(file), mention);
787
+ return mention;
788
+ };
789
+ /**
790
+ * How a file is NAMED in human output and in cross-file references. A path
791
+ * this run loads more than once gets its mention number, because the bare
792
+ * path names all of those loads at once: without it a second load's findings
793
+ * read as a file shadowing itself. A path loaded once is printed unadorned —
794
+ * there is nothing to tell it apart from, and "[1]" on every line of an
795
+ * ordinary run is noise. The `--json` report carries `mention` regardless.
796
+ */
797
+ const displayName = (report) => (mentionCount.get(mentionKey(report.file)) ?? 1) > 1 ? `${report.file}[${report.mention}]` : report.file;
798
+ const reports = [];
799
+ const union = [];
800
+ const provenance = [];
801
+ const reportedBySite = /* @__PURE__ */ new Map();
802
+ const fileIds = /* @__PURE__ */ new Map();
803
+ const runErrors = [];
804
+ const fakeStore = new McpFakeStore();
805
+ let mcpFakeBlocks = 0;
806
+ const siteKey = (fileId, index, severity, kind) => [
807
+ fileId,
808
+ index,
809
+ severity,
810
+ kind
811
+ ].join("\0");
812
+ for (const target of targets) {
813
+ if (target.skipped !== void 0) {
814
+ reports.push({
815
+ file: target.file,
816
+ mention: nextMention(target.file),
817
+ fixtures: 0,
818
+ errors: [],
819
+ warnings: [],
820
+ skipped: target.skipped
821
+ });
822
+ continue;
823
+ }
824
+ if (target.fatal !== void 0) {
825
+ reports.push(fatalReport(target.file, nextMention(target.file), target.fatal));
826
+ continue;
827
+ }
828
+ let report;
829
+ let fixtures = [];
830
+ let indices = [];
831
+ let identities = [];
832
+ let fileRunErrors = [];
833
+ let mcpFakes = [];
834
+ const mention = nextMention(target.file);
835
+ try {
836
+ ({report, fixtures, indices, identities, runErrors: fileRunErrors, mcpFakes} = validateOneFile(target.file, mention, target.source ?? target.file));
837
+ } catch (err) {
838
+ report = fatalReport(target.file, mention, `Validation failed: ${errText(err)}`);
839
+ }
840
+ if (mcpFakes.length > 0) try {
841
+ const added = fakeStore.add(mcpFakes, { kind: "file" });
842
+ report.mcpFakeBlocks = mcpFakes.length;
843
+ mcpFakeBlocks += mcpFakes.length;
844
+ report.warnings.push(...added.warnings.map(issueFinding));
845
+ } catch (err) {
846
+ if (err instanceof McpFakesAddError) {
847
+ report.errors.push(...err.errors.map(loadErrorFinding));
848
+ report.warnings.push(...err.warnings.map(issueFinding));
849
+ } else report.errors.push({ message: build(msg`mcpFakes check failed: ${plainText(errText(err), Infinity)}`) });
850
+ }
851
+ reports.push(report);
852
+ runErrors.push(...fileRunErrors.map((e) => `${displayName(report)}: ${e}`));
853
+ const fileId = fileIds.size;
854
+ fileIds.set(report, fileId);
855
+ for (const identity of identities) {
856
+ const key = siteKey(fileId, identity.index, identity.severity, identity.kind);
857
+ const atSite = reportedBySite.get(key) ?? [];
858
+ atSite.push({
859
+ finding: identity.finding,
860
+ refs: identity.refs.map((ref) => `${fileId}:${ref}`)
861
+ });
862
+ reportedBySite.set(key, atSite);
863
+ }
864
+ for (let i = 0; i < fixtures.length; i++) {
865
+ const index = indices[i];
866
+ if (index === void 0) runErrors.push(`${displayName(report)}: converted fixture ${i} has no source entry index; cross-file findings against it are reported at its array position`);
867
+ union.push(fixtures[i]);
868
+ provenance.push({
869
+ report,
870
+ index: index ?? i
871
+ });
872
+ }
873
+ }
874
+ let noFixturesLoaded = false;
875
+ const causeAlreadyReported = reports.some((r) => r.fatal !== void 0 || r.errors.length > 0);
876
+ if (union.length === 0) {
877
+ if (!causeAlreadyReported && mcpFakeBlocks === 0) {
878
+ runErrors.push("No fixtures loaded from any input — the server aborts startup on this under --validate-on-load/--strict");
879
+ noFixturesLoaded = true;
880
+ }
881
+ } else {
882
+ const describe = (unionIndex) => {
883
+ const origin = provenance[unionIndex];
884
+ return origin === void 0 ? String(unionIndex) : `${displayName(origin.report)} #${origin.index}`;
885
+ };
886
+ const targetOf = (unionIndex) => {
887
+ const origin = provenance[unionIndex];
888
+ if (origin === void 0) return `union:${unionIndex}`;
889
+ const fileId = fileIds.get(origin.report);
890
+ return fileId === void 0 ? `union:${unionIndex}` : `${fileId}:${origin.index}`;
891
+ };
892
+ const renderCrossFile = (ref) => {
893
+ if (ref.rule === "duplicate-user-message") return `duplicate userMessage '${ref.userMessage}' — shadows fixture ${describe(ref.shadows)}`;
894
+ const head = "empty match acts as catch-all but is not the last fixture";
895
+ return ref.shadowsFrom === ref.shadowsThrough ? `${head} — shadows ${describe(ref.shadowsFrom)}` : `${head} — shadows every later fixture, from ${describe(ref.shadowsFrom)} through ${describe(ref.shadowsThrough)}`;
896
+ };
897
+ try {
898
+ for (const r of validateFixtures(union)) {
899
+ const origin = provenance[r.fixtureIndex];
900
+ if (origin === void 0) {
901
+ runErrors.push(`Cross-file finding for an unknown fixture index ${r.fixtureIndex}: ${r.message}`);
902
+ continue;
903
+ }
904
+ const fileId = fileIds.get(origin.report);
905
+ if (fileId === void 0) {
906
+ runErrors.push(`Cross-file finding for an unrecognised file: ${r.message}`);
907
+ continue;
908
+ }
909
+ const kind = r.ref === void 0 ? `message:${r.message}` : r.ref.rule;
910
+ const refTargets = r.ref === void 0 ? [] : refIndices(r.ref).map(targetOf);
911
+ const message = `cross-file: ${r.ref === void 0 ? r.message : renderCrossFile(r.ref)}`;
912
+ const already = reportedBySite.get(siteKey(fileId, origin.index, r.severity, kind))?.shift();
913
+ if (already !== void 0) {
914
+ if (!(already.refs.length === refTargets.length && already.refs.every((target, i) => target === refTargets[i]))) already.finding.message = message;
915
+ continue;
916
+ }
917
+ if (r.severity === "error") origin.report.errors.push({
918
+ index: origin.index,
919
+ message
920
+ });
921
+ else origin.report.warnings.push({
922
+ index: origin.index,
923
+ message
924
+ });
925
+ }
926
+ } catch (err) {
927
+ runErrors.push(`Cross-file validation failed: ${errText(err)}`);
928
+ }
929
+ }
930
+ const hasFatal = reports.some((r) => r.fatal !== void 0);
931
+ const hasErrors = reports.some((r) => r.errors.length > 0) || runErrors.length > 0;
932
+ const hasWarnings = reports.some((r) => r.warnings.length > 0);
933
+ const failed = hasFatal || hasErrors || strict && hasWarnings;
934
+ const logWarning = strict ? logError : log;
935
+ if (json) {
936
+ log(JSON.stringify({
937
+ strict,
938
+ failed,
939
+ files: reports,
940
+ run: {
941
+ fixtures: union.length,
942
+ mcpFakeBlocks,
943
+ errors: runErrors
944
+ }
945
+ }, null, 2));
946
+ if (failed) logError(summarizeFailure(reports, strict, runErrors, displayName));
947
+ } else {
948
+ const at = findingAt;
949
+ const emitDetail = (f, sink) => {
950
+ if (f.detail !== void 0) sink(` ${f.detail}`);
951
+ };
952
+ for (const r of reports) {
953
+ const name = displayName(r);
954
+ if (r.skipped !== void 0) {
955
+ log(`${name}: skipped (${r.skipped})`);
956
+ continue;
957
+ }
958
+ for (const e of r.errors) {
959
+ logError(`${name}: [error] ${at(e)}${e.message}`);
960
+ emitDetail(e, logError);
961
+ }
962
+ for (const w of r.warnings) {
963
+ logWarning(`${name}: [warning] ${at(w)}${w.message}`);
964
+ emitDetail(w, logWarning);
965
+ }
966
+ if (r.errors.length === 0 && r.warnings.length === 0) {
967
+ const blocks = r.mcpFakeBlocks ?? 0;
968
+ if (r.fixtures === 0 && blocks === 0 && failed) {
969
+ const why = noFixturesLoaded ? "see the run-level error" : "the run failed elsewhere";
970
+ log(`${name}: ${r.fixtures} fixture(s), loaded nothing — ${why}`);
971
+ } else if (blocks > 0) log(build(msg`${plainText(name, Infinity)}: OK (${r.fixtures} fixture(s), ${blocks} mcpFakes block(s))`));
972
+ else log(`${name}: OK (${r.fixtures} fixture(s))`);
973
+ } else log(`${name}: ${r.fixtures} fixture(s), ${r.errors.length} error(s), ${r.warnings.length} warning(s)`);
974
+ }
975
+ for (const e of runErrors) logError(`[error] ${e}`);
976
+ }
977
+ exit(failed ? 1 : 0);
978
+ }
979
+
980
+ //#endregion
981
+ export { runValidateCli };
982
+ //# sourceMappingURL=validate-cli.js.map