doppler-gpu 0.5.1 → 0.6.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 (927) hide show
  1. package/CHANGELOG.md +33 -577
  2. package/LICENSE +21 -201
  3. package/README.md +165 -222
  4. package/models/catalog.json +241 -33
  5. package/package.json +99 -86
  6. package/src/capsule-runtime.d.ts +23 -0
  7. package/src/capsule-runtime.js +23 -0
  8. package/src/capsule.d.ts +8 -0
  9. package/src/capsule.js +4 -0
  10. package/src/cli/argument-contract.js +200 -0
  11. package/src/cli/browser-report-output.js +24 -0
  12. package/src/cli/cli-model-resolution.js +2 -2
  13. package/src/cli/cli-output.js +10 -0
  14. package/src/cli/commands/bundle.js +828 -0
  15. package/src/cli/doppler-cli.js +50 -1457
  16. package/src/cli/doppler-serve.js +18 -244
  17. package/src/cli/output/manifest.js +368 -0
  18. package/src/cli/runtime-profiles.js +1 -1
  19. package/src/cli/serve/capsule-handler.d.ts +33 -0
  20. package/src/cli/serve/capsule-handler.js +105 -0
  21. package/src/cli/serve/capsule-http.js +102 -0
  22. package/src/cli/serve/receipt.js +269 -0
  23. package/src/client/capsule-host.browser.js +1 -0
  24. package/src/client/capsule-host.d.ts +3 -0
  25. package/src/client/capsule-host.js +1 -0
  26. package/src/client/doppler-api.browser.js +42 -0
  27. package/src/client/doppler-api.d.ts +36 -1
  28. package/src/client/doppler-api.js +40 -1
  29. package/src/client/doppler-registry.js +15 -7
  30. package/src/client/electron/index.d.ts +4 -0
  31. package/src/client/electron/index.js +13 -0
  32. package/src/client/electron/ipc-contract.d.ts +9 -0
  33. package/src/client/electron/ipc-contract.js +56 -0
  34. package/src/client/electron/release-state.d.ts +53 -0
  35. package/src/client/electron/release-state.js +425 -0
  36. package/src/client/electron/renderer-runtime.d.ts +19 -0
  37. package/src/client/electron/renderer-runtime.js +104 -0
  38. package/src/client/failure-taxonomy.js +1 -28
  39. package/src/client/fault-injection.js +0 -8
  40. package/src/client/inspection.js +1 -1
  41. package/src/client/model-host/index.d.ts +140 -0
  42. package/src/client/model-host/index.js +548 -0
  43. package/src/client/model-host/model-evidence.js +255 -0
  44. package/src/client/model-host/model-session.d.ts +322 -0
  45. package/src/client/{runtime → model-host}/model-session.js +190 -148
  46. package/src/client/provider.d.ts +18 -2
  47. package/src/client/provider.js +26 -3
  48. package/src/client/receipt.js +30 -72
  49. package/src/client/runtime/capsule-acquisition.d.ts +18 -0
  50. package/src/client/runtime/capsule-acquisition.js +103 -0
  51. package/src/client/runtime/capsule-adapter-execution.d.ts +17 -0
  52. package/src/client/runtime/capsule-adapter-execution.js +63 -0
  53. package/src/client/runtime/capsule-artifact-source.js +62 -0
  54. package/src/client/runtime/capsule-embedding.d.ts +29 -0
  55. package/src/client/runtime/capsule-embedding.js +76 -0
  56. package/src/client/runtime/capsule-forecast-program.d.ts +2 -0
  57. package/src/client/runtime/capsule-forecast-program.js +85 -0
  58. package/src/client/runtime/capsule-forecast.d.ts +17 -0
  59. package/src/client/runtime/capsule-forecast.js +31 -0
  60. package/src/client/runtime/capsule-operation-adapters.d.ts +12 -0
  61. package/src/client/runtime/capsule-operation-adapters.js +68 -0
  62. package/src/client/runtime/capsule-operation-executor.d.ts +25 -0
  63. package/src/client/runtime/capsule-operation-executor.js +100 -0
  64. package/src/client/runtime/capsule-program-adapter.js +151 -0
  65. package/src/client/runtime/capsule-release-authorization.js +25 -0
  66. package/src/client/runtime/capsule-rerank.d.ts +50 -0
  67. package/src/client/runtime/capsule-rerank.js +105 -0
  68. package/src/client/runtime/capsule-session-execution.js +85 -0
  69. package/src/client/runtime/command-executor.d.ts +15 -0
  70. package/src/client/runtime/command-executor.js +128 -0
  71. package/src/client/runtime/composition-root.d.ts +74 -0
  72. package/src/client/runtime/composition-root.js +344 -0
  73. package/src/client/runtime/fetch-capsule-artifact-store.d.ts +10 -0
  74. package/src/client/runtime/fetch-capsule-artifact-store.js +25 -0
  75. package/src/client/runtime/index.d.ts +1 -117
  76. package/src/client/runtime/index.js +1 -433
  77. package/src/client/runtime/lora.d.ts +14 -0
  78. package/src/client/runtime/lora.js +19 -1
  79. package/src/client/runtime/model-manager.js +12 -0
  80. package/src/client/runtime/model-rerank.js +30 -0
  81. package/src/client/runtime/model-session.d.ts +1 -221
  82. package/src/client/runtime/model-source.d.ts +9 -0
  83. package/src/client/runtime/model-source.js +46 -17
  84. package/src/client/runtime/node-quickstart-cache.js +1 -1
  85. package/src/client/runtime/resolution-policy.d.ts +20 -0
  86. package/src/client/runtime/resolution-policy.js +84 -0
  87. package/src/client/runtime/resource-binder.d.ts +24 -0
  88. package/src/client/runtime/resource-binder.js +135 -0
  89. package/src/client/runtime/scoped-session.d.ts +10 -1
  90. package/src/client/runtime/scoped-session.js +20 -1
  91. package/src/client/runtime/session-controller.d.ts +30 -0
  92. package/src/client/runtime/session-controller.js +170 -0
  93. package/src/client/runtime/source-runtime.js +1 -1
  94. package/src/client/runtime/target-selector.d.ts +9 -0
  95. package/src/client/runtime/target-selector.js +2 -0
  96. package/src/client/runtime/types.d.ts +1 -0
  97. package/src/client/runtime/verified-capsule-artifact-store.js +72 -0
  98. package/src/client/wrap-pipeline-handle.js +3 -9
  99. package/src/config/backward-registry-loader.js +1 -1
  100. package/src/config/capsule-adapter-policy.js +30 -0
  101. package/src/config/capsule-adapters.d.ts +21 -0
  102. package/src/config/capsule-adapters.js +40 -0
  103. package/src/config/capsule-adapters.json +9 -0
  104. package/src/config/capsule-loading.d.ts +2 -0
  105. package/src/config/capsule-loading.js +14 -0
  106. package/src/config/capsule-loading.schema.json +11 -0
  107. package/src/config/capsule-operation.d.ts +19 -0
  108. package/src/config/capsule-operation.js +58 -0
  109. package/src/config/capsule-operations.json +18 -0
  110. package/src/config/capsule-release-contract.d.ts +66 -0
  111. package/src/config/capsule-release-contract.js +197 -0
  112. package/src/config/capsule-release-events.d.ts +53 -0
  113. package/src/config/capsule-release-events.js +172 -0
  114. package/src/config/capsule-sequence-receipt.js +19 -0
  115. package/src/config/capsule-serve.d.ts +9 -0
  116. package/src/config/capsule-serve.js +28 -0
  117. package/src/config/capsule-serve.schema.json +14 -0
  118. package/src/config/capsule-signature.d.ts +6 -0
  119. package/src/config/capsule-signature.js +50 -0
  120. package/src/config/capsule-v2.d.ts +70 -0
  121. package/src/config/capsule-v2.js +431 -0
  122. package/src/config/capsule-v3.d.ts +19 -0
  123. package/src/config/capsule-v3.js +72 -0
  124. package/src/config/capsule.d.ts +22 -0
  125. package/src/config/capsule.js +52 -0
  126. package/src/config/conversion/amplify/amplify-120m-f16-af32.json +1 -1
  127. package/src/config/conversion/embeddinggemma/google-embeddinggemma-300m-q4k-ehf16-af32.json +1 -1
  128. package/src/config/conversion/esm/esm2-t12-35m-ur50d-f32-af32.json +41 -1
  129. package/src/config/conversion/esmc/esmc-300m-f32-af32.json +1 -1
  130. package/src/config/conversion/gemma3/gemma-3-1b-it-q4k-ehf16-af32.json +1 -1
  131. package/src/config/conversion/gemma3/gemma-3-270m-it-f16-af32.json +1 -1
  132. package/src/config/conversion/gemma3/gemma-3-270m-it-q4k-ehf16-af16.json +1 -1
  133. package/src/config/conversion/gemma3/gemma-3-270m-it-q4k-ehf16-af32.json +1 -1
  134. package/src/config/conversion/gemma3/translategemma-4b-1b-enes-q4k-ehf16-af32.json +1 -1
  135. package/src/config/conversion/gemma3/translategemma-4b-it-q4k-ehf16-af32.json +1 -1
  136. package/src/config/conversion/gemma4/gemma-4-12b-it-text-q4k-ehf16-af16.json +2 -2
  137. package/src/config/conversion/gemma4/gemma-4-12b-it-text-q4k-ehf16-af32.json +1 -1
  138. package/src/config/conversion/gemma4/gemma-4-12b-it-text-q4k-ehf16-hq4k-af16.json +1 -1
  139. package/src/config/conversion/gemma4/gemma-4-12b-it-text-w4a16-ct-ehf16-af16.json +1 -1
  140. package/src/config/conversion/gemma4/gemma-4-31b-it-text-q4k-ehf16-af16.json +2 -2
  141. package/src/config/conversion/gemma4/gemma-4-31b-it-text-q4k-ehf16-af32.json +1 -1
  142. package/src/config/conversion/gemma4/gemma-4-e2b-it-q4k-ehf16-af16-int4ple.json +3 -3
  143. package/src/config/conversion/gemma4/gemma-4-e2b-it-q4k-ehf16-af32-int4ple.json +1 -1
  144. package/src/config/conversion/gemma4/gemma-4-e2b-it-q4k-ehf16-af32.json +1 -1
  145. package/src/config/conversion/glmocr/glm-ocr-f16-af32.json +442 -0
  146. package/src/config/conversion/minicpm/minicpm4-0-5b-f16-af32.json +1 -1
  147. package/src/config/conversion/muse-glimmer/muse-glimmer-30b-text-bf16-af32.json +529 -0
  148. package/src/config/conversion/muse-glimmer/muse-glimmer-30b-text-f16-af32.json +529 -0
  149. package/src/config/conversion/nucleotide-transformer/nucleotide-transformer-v2-50m-f32-af32.json +1 -1
  150. package/src/config/conversion/qwen3/qwen-3-5-0-8b-q4k-ehaf16.json +1 -1
  151. package/src/config/conversion/qwen3/qwen-3-5-2b-q4k-ehaf16.json +1 -1
  152. package/src/config/conversion/qwen3/qwen-3-5-9b-f16-af32.json +1 -1
  153. package/src/config/conversion/qwen3/qwen-3-5-9b-q4k-ehaf16.json +1 -1
  154. package/src/config/conversion/qwen3/qwen-3-6-27b-q4k-eaf16.json +2 -2
  155. package/src/config/conversion/qwen3/qwen-3-6-27b-q4k-ehaf16.json +1 -1
  156. package/src/config/conversion/qwen3/qwen-3-embedding-0-6b-f16-af32.json +463 -0
  157. package/src/config/conversion/qwen3/qwen-3-embedding-0-6b-q4k-ehf16-af32.json +1 -1
  158. package/src/config/conversion/qwen3/qwen-3-reranker-0-6b-f16-af32.json +1 -1
  159. package/src/config/conversion/qwen3/qwen-3-reranker-0-6b-f16-true-logit-af32.json +481 -0
  160. package/src/config/conversion/qwen3/qwen-3-reranker-0-6b-q4k-ehf16-af32.json +59 -7
  161. package/src/config/conversion/qwen3/qwen3.8-27b-text-f16-af32.json +561 -0
  162. package/src/config/conversion/qwen3/qwen3.8-27b-text-q4k-ehaf16.json +558 -0
  163. package/src/config/dtype-transition-contract.js +40 -0
  164. package/src/config/embedding-contract.js +26 -0
  165. package/src/config/embedding-reference.js +85 -0
  166. package/src/config/evidence/source-intake-policy.json +1 -1
  167. package/src/config/execution-contract-check.d.ts +16 -73
  168. package/src/config/execution-contract-check.js +7 -429
  169. package/src/config/forecast-manifest.js +56 -0
  170. package/src/config/heterogeneous-attention-contract.js +46 -0
  171. package/src/config/initial-execution-identity.d.ts +58 -0
  172. package/src/config/initial-execution-identity.js +331 -0
  173. package/src/config/kernel-path-loader.d.ts +10 -0
  174. package/src/config/kernel-path-loader.js +23 -8
  175. package/src/config/kernel-registry-contract.d.ts +25 -0
  176. package/src/config/kernel-registry-contract.js +46 -0
  177. package/src/config/kernels/kernel-ref-digests.js +50 -2
  178. package/src/config/kernels/registry.js +1 -1
  179. package/src/config/kernels/registry.json +13592 -11377
  180. package/src/config/lora-layouts.d.ts +10 -0
  181. package/src/config/lora-layouts.js +17 -0
  182. package/src/config/lora-layouts.json +9 -0
  183. package/src/config/manifest-inference-validation.js +575 -0
  184. package/src/config/merge/execution-patches.js +12 -0
  185. package/src/config/{merge-helpers.js → merge/kernel-path-policy.js} +0 -52
  186. package/src/config/merge/value-selection.js +38 -0
  187. package/src/config/merge.js +43 -11
  188. package/src/config/model-ir-v2.d.ts +57 -0
  189. package/src/config/model-ir-v2.js +258 -0
  190. package/src/config/model-ir.d.ts +49 -0
  191. package/src/config/model-ir.js +180 -0
  192. package/src/config/param-validator.js +1 -1
  193. package/src/config/platforms/amd-strix-halo-gfx1151.json +17 -0
  194. package/src/config/platforms/loader.js +2 -1
  195. package/src/config/production-release-evidence.d.ts +23 -0
  196. package/src/config/production-release-evidence.js +423 -0
  197. package/src/config/production-release.js +321 -0
  198. package/src/{client/doppler-registry.json → config/quickstart-registry.json} +7 -7
  199. package/src/config/required-inference-fields-contract-check.js +2 -2
  200. package/src/config/rerank-reference.d.ts +28 -0
  201. package/src/config/rerank-reference.js +89 -0
  202. package/src/config/revocation-policy.d.ts +65 -0
  203. package/src/config/revocation-policy.js +290 -0
  204. package/src/config/revocation-registry.json +11 -0
  205. package/src/config/revocation-updates.d.ts +68 -0
  206. package/src/config/revocation-updates.js +440 -0
  207. package/src/config/runtime/profiles/gemma4-31b-f16-activations-probe.json +1 -1
  208. package/src/config/runtime/profiles/muse-glimmer-30b-source-parity-f32kv.json +30 -0
  209. package/src/config/runtime/profiles/muse-glimmer-30b-source-parity.json +110 -0
  210. package/src/config/runtime/profiles/qwen3-6-27b-f16-activations-probe.json +1 -1
  211. package/src/config/runtime/profiles/qwen3-8-27b-source-parity.json +87 -0
  212. package/src/config/runtime-merge.js +1 -1
  213. package/src/config/runtime.js +1 -1
  214. package/src/config/schema/browser-suite-metrics.schema.d.ts +1 -0
  215. package/src/config/schema/browser-suite-metrics.schema.js +2 -0
  216. package/src/config/schema/conversion-report.schema.d.ts +3 -0
  217. package/src/config/schema/conversion-report.schema.js +29 -0
  218. package/src/config/schema/converter.schema.d.ts +1 -0
  219. package/src/config/schema/debug.schema.d.ts +1 -0
  220. package/src/config/schema/doppler.schema.js +5 -5
  221. package/src/config/schema/emulation.schema.js +1 -1
  222. package/src/config/schema/execution-v1.schema.d.ts +3 -0
  223. package/src/config/schema/execution-v1.schema.js +19 -0
  224. package/src/config/schema/harness.schema.d.ts +13 -0
  225. package/src/config/schema/harness.schema.js +6 -0
  226. package/src/config/schema/inference.schema.d.ts +21 -2
  227. package/src/config/schema/kernel-thresholds.schema.js +1 -1
  228. package/src/config/schema/manifest.schema.d.ts +26 -7
  229. package/src/config/schema/manifest.schema.js +10 -1
  230. package/src/config/schema/program-bundle.schema.d.ts +52 -6
  231. package/src/config/schema/program-bundle.schema.js +145 -10
  232. package/src/config/sequence-reference.d.ts +26 -0
  233. package/src/config/sequence-reference.js +100 -0
  234. package/src/config/target-plan.d.ts +108 -0
  235. package/src/config/target-plan.js +411 -0
  236. package/src/config/training-defaults.js +1 -1
  237. package/src/config/transforms/capability-transform-resolver.js +4 -105
  238. package/src/config/transforms/execution-graph/dtype.js +591 -0
  239. package/src/config/transforms/execution-graph/fusion.js +436 -0
  240. package/src/config/transforms/execution-graph/validation.js +414 -0
  241. package/src/config/transforms/execution-graph-transforms.js +13 -1419
  242. package/src/converter/artifact-identity.js +475 -0
  243. package/src/converter/conversion-plan.js +1 -1
  244. package/src/converter/core.js +94 -2096
  245. package/src/converter/forge-candidate-evaluation.js +271 -0
  246. package/src/converter/forge-qualification.js +162 -0
  247. package/src/converter/forge-stages.js +798 -0
  248. package/src/converter/manifest-builder.js +683 -0
  249. package/src/converter/quantization-info.js +4 -1
  250. package/src/converter/quantizer.js +58 -9
  251. package/src/converter/shard-packer.d.ts +1 -1
  252. package/src/converter/shard-packer.js +2 -2
  253. package/src/converter/tensor-transform.js +640 -0
  254. package/src/converter/tokenizer-contract.js +243 -0
  255. package/src/converter/tokenizer-manifest.js +243 -0
  256. package/src/debug/history.js +0 -8
  257. package/src/debug/index.js +0 -10
  258. package/src/debug/tensor.js +1 -1
  259. package/src/debug/trace.js +0 -7
  260. package/src/experimental/adapters/adapter-manager.js +2 -0
  261. package/src/experimental/adapters/adapter-manifest.d.ts +6 -0
  262. package/src/experimental/adapters/adapter-manifest.js +11 -0
  263. package/src/experimental/adapters/artifact-contract.d.ts +2 -2
  264. package/src/experimental/adapters/artifact-contract.js +5 -2
  265. package/src/experimental/adapters/lora-loader.d.ts +10 -1
  266. package/src/experimental/adapters/lora-loader.js +110 -48
  267. package/src/{inference/pipelines → experimental}/audio/gemma4.js +9 -31
  268. package/src/experimental/bdpa/basis-decomposed-paged.d.ts +50 -0
  269. package/src/experimental/bdpa/basis-decomposed-paged.js +276 -0
  270. package/src/experimental/bridge/trainer-artifact-bridge.js +3 -3
  271. package/src/experimental/browser/browser-converter.js +11 -11
  272. package/src/experimental/diffusion/index.d.ts +1 -1
  273. package/src/experimental/diffusion/index.js +1 -1
  274. package/src/{inference/pipelines → experimental}/diffusion/pipeline.d.ts +2 -2
  275. package/src/{inference/pipelines → experimental}/diffusion/pipeline.js +17 -17
  276. package/src/{inference/pipelines → experimental}/diffusion/text-encoder-gpu.js +21 -19
  277. package/src/experimental/diffusion/vae.js +596 -0
  278. package/src/experimental/distribution/shard-delivery/receipt.js +588 -0
  279. package/src/experimental/distribution/shard-delivery/retry.js +392 -0
  280. package/src/experimental/distribution/shard-delivery/transport.js +831 -0
  281. package/src/experimental/distribution/shard-delivery.js +4 -1709
  282. package/src/experimental/energy/index.d.ts +2 -2
  283. package/src/experimental/energy/index.js +2 -2
  284. package/src/{inference/pipelines → experimental}/energy/pipeline.js +13 -13
  285. package/src/{inference/pipelines → experimental}/energy/types.d.ts +2 -2
  286. package/src/experimental/logits/cpu-output.d.ts +27 -0
  287. package/src/{inference/pipelines/text/logits/utils.js → experimental/logits/cpu-output.js} +19 -27
  288. package/src/experimental/logits/cpu.d.ts +87 -0
  289. package/src/experimental/logits/cpu.js +95 -0
  290. package/src/experimental/orchestration/energy-row-head-pipeline.d.ts +103 -0
  291. package/src/{inference/pipelines/energy-head/row-head-pipeline.js → experimental/orchestration/energy-row-head-pipeline.js} +13 -13
  292. package/src/experimental/orchestration/index.d.ts +1 -1
  293. package/src/experimental/orchestration/index.js +1 -1
  294. package/src/experimental/training/artifacts.js +2 -2
  295. package/src/experimental/training/checkpoint.js +2 -2
  296. package/src/experimental/training/distillation/artifacts.js +1 -1
  297. package/src/experimental/training/distillation/dataset.js +2 -2
  298. package/src/experimental/training/distillation/eval.js +1 -1
  299. package/src/experimental/training/distillation/runtime.js +2 -2
  300. package/src/experimental/training/distillation/student-fixture/execution.js +166 -0
  301. package/src/experimental/training/distillation/student-fixture/model.js +353 -0
  302. package/src/experimental/training/distillation/student-fixture.js +2 -469
  303. package/src/experimental/training/lora/checkpoint.js +746 -0
  304. package/src/experimental/training/lora/execution.js +550 -0
  305. package/src/experimental/training/lora/plan.js +387 -0
  306. package/src/experimental/training/lora/recovery.js +418 -0
  307. package/src/experimental/training/lora-pipeline.js +7 -1949
  308. package/src/experimental/training/operator-artifacts.js +2 -2
  309. package/src/experimental/training/operator-command.js +4 -4
  310. package/src/experimental/training/runner/evaluation.js +62 -0
  311. package/src/experimental/training/runner/lifecycle.js +257 -0
  312. package/src/experimental/training/runner.js +5 -268
  313. package/src/experimental/training/suite/execution.js +879 -0
  314. package/src/experimental/training/suite/plan.js +855 -0
  315. package/src/experimental/training/suite.js +5 -1659
  316. package/src/experimental/training/workloads.d.ts +5 -5
  317. package/src/experimental/training/workloads.js +6 -6
  318. package/src/experimental/turboquant/codebook.js +470 -0
  319. package/src/formats/quantization-constants.d.ts +11 -0
  320. package/src/formats/quantization-constants.js +11 -0
  321. package/src/formats/rdrr/integrity.js +1 -1
  322. package/src/formats/rdrr/lowerings.js +0 -29
  323. package/src/formats/rdrr/merkle.js +1 -1
  324. package/src/formats/rdrr/tensor-config-validator.js +25 -5
  325. package/src/formats/rdrr/validation.js +3 -3
  326. package/src/gpu/command-recorder.d.ts +10 -1
  327. package/src/gpu/command-recorder.js +58 -14
  328. package/src/gpu/constant-buffer.js +29 -0
  329. package/src/gpu/device-state.js +36 -0
  330. package/src/gpu/device.js +6 -41
  331. package/src/gpu/kernel-runtime.js +2 -1
  332. package/src/gpu/kernels/activation-static-qdq.js +1 -1
  333. package/src/gpu/kernels/append_embedding.wgsl +14 -0
  334. package/src/gpu/kernels/attention/executors.js +960 -0
  335. package/src/gpu/kernels/attention/plan.js +472 -0
  336. package/src/gpu/kernels/attention.d.ts +4 -0
  337. package/src/gpu/kernels/attention.js +145 -1545
  338. package/src/gpu/kernels/attention_relative.wgsl +59 -0
  339. package/src/gpu/kernels/backward/adam.js +2 -1
  340. package/src/gpu/kernels/backward/attention_backward.js +1 -1
  341. package/src/gpu/kernels/backward/bias_add_backward.d.ts +1 -1
  342. package/src/gpu/kernels/backward/bias_add_backward.js +1 -1
  343. package/src/gpu/kernels/backward/causal_conv1d_silu_backward.js +2 -1
  344. package/src/gpu/kernels/backward/conv2d_backward.d.ts +1 -1
  345. package/src/gpu/kernels/backward/conv2d_backward.js +2 -1
  346. package/src/gpu/kernels/backward/cross_entropy_backward.d.ts +1 -1
  347. package/src/gpu/kernels/backward/cross_entropy_backward.js +1 -1
  348. package/src/gpu/kernels/backward/embed_backward.js +2 -1
  349. package/src/gpu/kernels/backward/executor.d.ts +34 -0
  350. package/src/gpu/kernels/backward/executor.js +158 -0
  351. package/src/gpu/kernels/backward/gated_delta_recurrent_backward.js +2 -1
  352. package/src/gpu/kernels/backward/gated_rmsnorm_backward.js +2 -1
  353. package/src/gpu/kernels/backward/gelu_backward.d.ts +1 -1
  354. package/src/gpu/kernels/backward/gelu_backward.js +1 -1
  355. package/src/gpu/kernels/backward/groupnorm_backward.d.ts +1 -1
  356. package/src/gpu/kernels/backward/groupnorm_backward.js +1 -1
  357. package/src/gpu/kernels/backward/layernorm_backward.d.ts +1 -1
  358. package/src/gpu/kernels/backward/layernorm_backward.js +2 -1
  359. package/src/gpu/kernels/backward/matmul.js +133 -0
  360. package/src/gpu/kernels/backward/matmul_backward.d.ts +0 -1
  361. package/src/gpu/kernels/backward/matmul_backward.js +1 -1
  362. package/src/gpu/kernels/backward/pixel_shuffle_backward.d.ts +1 -1
  363. package/src/gpu/kernels/backward/pixel_shuffle_backward.js +1 -1
  364. package/src/gpu/kernels/backward/rmsnorm_backward.d.ts +1 -1
  365. package/src/gpu/kernels/backward/rmsnorm_backward.js +2 -1
  366. package/src/gpu/kernels/backward/rope_backward.d.ts +1 -1
  367. package/src/gpu/kernels/backward/rope_backward.js +2 -1
  368. package/src/gpu/kernels/backward/scale_backward.d.ts +1 -1
  369. package/src/gpu/kernels/backward/scale_backward.js +2 -1
  370. package/src/gpu/kernels/backward/silu_backward.d.ts +1 -1
  371. package/src/gpu/kernels/backward/silu_backward.js +1 -1
  372. package/src/gpu/kernels/backward/softmax_backward.d.ts +1 -1
  373. package/src/gpu/kernels/backward/softmax_backward.js +1 -1
  374. package/src/gpu/kernels/backward/upsample2d_backward.d.ts +1 -1
  375. package/src/gpu/kernels/backward/upsample2d_backward.js +1 -1
  376. package/src/gpu/kernels/backward/utils.js +2 -392
  377. package/src/gpu/kernels/bind-group-validation.js +16 -0
  378. package/src/gpu/kernels/cast.js +2 -1
  379. package/src/gpu/kernels/check-finiteness.js +13 -49
  380. package/src/gpu/kernels/check-hot-vocab-stop.js +13 -39
  381. package/src/gpu/kernels/check-stop.js +14 -33
  382. package/src/gpu/kernels/check_finiteness.wgsl +33 -0
  383. package/src/gpu/kernels/check_hot_vocab_stop.wgsl +29 -0
  384. package/src/gpu/kernels/check_stop.wgsl +20 -0
  385. package/src/gpu/kernels/clamp.js +1 -1
  386. package/src/gpu/kernels/conv2d.js +1 -1
  387. package/src/gpu/kernels/cross_entropy_loss.js +1 -1
  388. package/src/gpu/kernels/depthwise_conv1d.js +1 -1
  389. package/src/gpu/kernels/depthwise_conv2d.js +1 -1
  390. package/src/gpu/kernels/dequant.js +7 -2
  391. package/src/gpu/kernels/diffusion-gemma-sampling.js +3 -5
  392. package/src/gpu/kernels/dispatch.js +12 -1
  393. package/src/gpu/kernels/embedding-pool.js +72 -0
  394. package/src/gpu/kernels/embedding_pool_f16.wgsl +38 -0
  395. package/src/gpu/kernels/embedding_pool_f32.wgsl +36 -0
  396. package/src/gpu/kernels/energy.js +2 -1
  397. package/src/gpu/kernels/forecast_output.wgsl +17 -0
  398. package/src/gpu/kernels/fused-gate-up-gelu.js +1 -1
  399. package/src/gpu/kernels/fused_ffn.js +10 -220
  400. package/src/gpu/kernels/fused_matmul_residual.js +2 -1
  401. package/src/gpu/kernels/fused_matmul_rmsnorm.js +2 -1
  402. package/src/gpu/kernels/fused_normed_ffn_q4k.wgsl +208 -0
  403. package/src/gpu/kernels/gated-short-conv.js +11 -69
  404. package/src/gpu/kernels/gated_delta_conv.wgsl +66 -0
  405. package/src/gpu/kernels/gated_delta_conv_f16.wgsl +68 -0
  406. package/src/gpu/kernels/gated_delta_fused_decode.wgsl +173 -0
  407. package/src/gpu/kernels/gated_delta_fused_decode_f16.wgsl +175 -0
  408. package/src/gpu/kernels/gated_delta_recurrent.wgsl +165 -0
  409. package/src/gpu/kernels/gated_delta_recurrent_f16.wgsl +167 -0
  410. package/src/gpu/kernels/gated_short_conv.wgsl +47 -0
  411. package/src/gpu/kernels/gather.d.ts +1 -1
  412. package/src/gpu/kernels/gather.js +30 -6
  413. package/src/gpu/kernels/gather_bf16.wgsl +69 -0
  414. package/src/gpu/kernels/gelu.js +1 -1
  415. package/src/gpu/kernels/gemma4-route-expert.js +1 -1
  416. package/src/gpu/kernels/grouped_pointwise_conv2d.js +1 -1
  417. package/src/gpu/kernels/groupnorm.js +1 -1
  418. package/src/gpu/kernels/index.d.ts +38 -5
  419. package/src/gpu/kernels/index.js +18 -4
  420. package/src/gpu/kernels/instance_stats.wgsl +26 -0
  421. package/src/gpu/kernels/kernel-base.js +1 -1
  422. package/src/gpu/kernels/kernel-cache-lifecycle.d.ts +9 -0
  423. package/src/gpu/kernels/kernel-cache-lifecycle.js +26 -0
  424. package/src/gpu/kernels/kernel-configs.d.ts +10 -61
  425. package/src/gpu/kernels/kernel-configs.js +26 -54
  426. package/src/gpu/kernels/kernel-execution.js +141 -0
  427. package/src/gpu/kernels/kv-cache-write.js +4 -4
  428. package/src/gpu/kernels/kv-quantize.js +4 -1
  429. package/src/gpu/kernels/l2-normalize.js +36 -0
  430. package/src/gpu/kernels/l2_normalize.wgsl +53 -0
  431. package/src/gpu/kernels/layernorm.d.ts +4 -4
  432. package/src/gpu/kernels/layernorm.js +44 -7
  433. package/src/gpu/kernels/linear-attention-core.js +29 -449
  434. package/src/gpu/kernels/linear_attention.js +1 -1
  435. package/src/gpu/kernels/lm-head-argmax.js +2 -2
  436. package/src/gpu/kernels/lm-head-select-logits.js +2 -2
  437. package/src/gpu/kernels/logit-finalize.js +103 -0
  438. package/src/gpu/kernels/logit-merge.js +13 -125
  439. package/src/gpu/kernels/logit-scatter.js +40 -0
  440. package/src/gpu/kernels/logit_finalize_f16.wgsl +43 -0
  441. package/src/gpu/kernels/logit_finalize_f32.wgsl +41 -0
  442. package/src/gpu/kernels/logit_merge_geometric.wgsl +23 -0
  443. package/src/gpu/kernels/logit_merge_max.wgsl +23 -0
  444. package/src/gpu/kernels/logit_merge_weighted.wgsl +23 -0
  445. package/src/gpu/kernels/logit_scatter_f16.wgsl +26 -0
  446. package/src/gpu/kernels/logit_scatter_f32.wgsl +24 -0
  447. package/src/gpu/kernels/matmul-dispatch.js +6 -1
  448. package/src/gpu/kernels/matmul-selection.js +3 -2
  449. package/src/gpu/kernels/matmul.js +4 -15
  450. package/src/gpu/kernels/matmul_bf16w_f32a.wgsl +93 -0
  451. package/src/gpu/kernels/matmul_gemv_subgroup_bf16w.wgsl +433 -0
  452. package/src/gpu/kernels/modulate.js +1 -1
  453. package/src/gpu/kernels/moe.js +3 -1
  454. package/src/gpu/kernels/moe_router_bias_add_f16_f16.wgsl +23 -0
  455. package/src/gpu/kernels/moe_router_bias_add_f16_f32.wgsl +23 -0
  456. package/src/gpu/kernels/moe_router_bias_add_f32_f16.wgsl +23 -0
  457. package/src/gpu/kernels/moe_router_bias_add_f32_f32.wgsl +21 -0
  458. package/src/gpu/kernels/patch_context.wgsl +29 -0
  459. package/src/gpu/kernels/pipeline-cache.js +3 -1
  460. package/src/gpu/kernels/pixel_shuffle.js +1 -1
  461. package/src/gpu/kernels/probe_shader_f16.wgsl +7 -0
  462. package/src/gpu/kernels/relu.js +1 -1
  463. package/src/gpu/kernels/repeat_channels.js +1 -1
  464. package/src/gpu/kernels/residual.js +2 -2
  465. package/src/gpu/kernels/rmsnorm-pair.js +1 -1
  466. package/src/gpu/kernels/rmsnorm-qk.js +1 -1
  467. package/src/gpu/kernels/rmsnorm-stats.js +14 -113
  468. package/src/gpu/kernels/rmsnorm.js +1 -1
  469. package/src/gpu/kernels/rmsnorm_serial.wgsl +19 -0
  470. package/src/gpu/kernels/rmsnorm_stats.wgsl +59 -0
  471. package/src/gpu/kernels/rmsnorm_stats_subgroups.wgsl +76 -0
  472. package/src/gpu/kernels/rope-precompute.js +160 -0
  473. package/src/gpu/kernels/rope-qk.js +1 -1
  474. package/src/gpu/kernels/rope.js +2 -2
  475. package/src/gpu/kernels/rope_precompute.wgsl +74 -0
  476. package/src/gpu/kernels/sample.js +5 -1
  477. package/src/gpu/kernels/scale.js +1 -1
  478. package/src/gpu/kernels/shader-cache.js +8 -4
  479. package/src/gpu/kernels/shader-source-scope.js +68 -0
  480. package/src/gpu/kernels/silu.js +2 -1
  481. package/src/gpu/kernels/soft-embedding.js +3 -1
  482. package/src/gpu/kernels/softmax.js +4 -2
  483. package/src/gpu/kernels/split-qkv-rmsnorm-qk.js +1 -1
  484. package/src/gpu/kernels/split-qkv-rmsnorm-rope-qk.js +1 -1
  485. package/src/gpu/kernels/split_qg.js +1 -1
  486. package/src/gpu/kernels/split_qkv.d.ts +2 -0
  487. package/src/gpu/kernels/split_qkv.js +18 -3
  488. package/src/gpu/kernels/split_qkv.wgsl +5 -2
  489. package/src/gpu/kernels/split_qkv_f16.wgsl +5 -2
  490. package/src/gpu/kernels/submit_probe.wgsl +6 -0
  491. package/src/gpu/kernels/transpose.js +1 -1
  492. package/src/gpu/kernels/turboquant-codebook.js +4 -535
  493. package/src/gpu/kernels/uniform-utils.js +7 -2
  494. package/src/gpu/kernels/upsample2d.js +1 -1
  495. package/src/gpu/kernels/utils.js +9 -330
  496. package/src/gpu/kernels/vision-average-pool.d.ts +13 -0
  497. package/src/gpu/kernels/vision-average-pool.js +68 -0
  498. package/src/gpu/kernels/vision-patch-embed.d.ts +17 -0
  499. package/src/gpu/kernels/vision-patch-embed.js +117 -0
  500. package/src/gpu/kernels/vision-position-embedding.d.ts +13 -0
  501. package/src/gpu/kernels/vision-position-embedding.js +79 -0
  502. package/src/gpu/kernels/vision-rope-2d.d.ts +16 -0
  503. package/src/gpu/kernels/vision-rope-2d.js +73 -0
  504. package/src/gpu/kernels/vision-spatial-merge.d.ts +19 -0
  505. package/src/gpu/kernels/vision-spatial-merge.js +100 -0
  506. package/src/gpu/kernels/vision_average_pool.wgsl +42 -0
  507. package/src/gpu/kernels/vision_patch_embed.wgsl +59 -0
  508. package/src/gpu/kernels/vision_patch_embed_f16w.wgsl +61 -0
  509. package/src/gpu/kernels/vision_position_embedding.wgsl +33 -0
  510. package/src/gpu/kernels/vision_position_embedding_f16.wgsl +35 -0
  511. package/src/gpu/kernels/vision_rope_2d.wgsl +60 -0
  512. package/src/gpu/kernels/vision_spatial_merge.wgsl +48 -0
  513. package/src/gpu/readback-buffer.js +20 -0
  514. package/src/gpu/submit-probe.js +2 -26
  515. package/src/gpu/weight-buffer.d.ts +1 -0
  516. package/src/gpu/weight-buffer.js +7 -0
  517. package/src/index.d.ts +10 -0
  518. package/src/index.js +1 -0
  519. package/src/inference/browser-harness/benchmark-execution.js +872 -0
  520. package/src/inference/browser-harness/benchmark-rerank.js +284 -0
  521. package/src/inference/browser-harness/decode-diagnostics.js +241 -0
  522. package/src/inference/browser-harness/diffusion-performance.js +102 -0
  523. package/src/inference/browser-harness/inference-execution.js +543 -0
  524. package/src/inference/{browser-harness-model-helpers.js → browser-harness/model-initialization.js} +14 -145
  525. package/src/inference/browser-harness/model-resolution.js +137 -0
  526. package/src/inference/browser-harness/report.js +338 -0
  527. package/src/inference/browser-harness/request.js +263 -0
  528. package/src/inference/browser-harness/runtime-config.d.ts +25 -0
  529. package/src/inference/browser-harness/runtime-config.js +255 -0
  530. package/src/inference/browser-harness/runtime-isolation.d.ts +13 -0
  531. package/src/inference/browser-harness/runtime-isolation.js +45 -0
  532. package/src/inference/browser-harness/runtime-report.d.ts +26 -0
  533. package/src/inference/browser-harness/runtime-report.js +117 -0
  534. package/src/inference/browser-harness/suite-summary.js +39 -0
  535. package/src/inference/browser-harness/text-evidence.js +694 -0
  536. package/src/inference/browser-harness/text-execution.js +757 -0
  537. package/src/inference/browser-harness/text-input.js +725 -0
  538. package/src/inference/{browser-harness-suite-helpers.js → browser-harness/timing-diagnostics.js} +1 -379
  539. package/src/inference/browser-harness-contract-helpers.js +1 -1
  540. package/src/inference/browser-harness-diffusion-energy-suites.js +8 -3
  541. package/src/inference/browser-harness-runtime-helpers.d.ts +3 -56
  542. package/src/inference/browser-harness-runtime-helpers.js +3 -423
  543. package/src/inference/browser-harness-text-helpers.js +31 -2199
  544. package/src/inference/browser-harness.d.ts +15 -2
  545. package/src/inference/browser-harness.js +38 -1952
  546. package/src/inference/kv-cache/base.js +67 -381
  547. package/src/inference/kv-cache/basis-decomposed-paged.d.ts +2 -50
  548. package/src/inference/kv-cache/basis-decomposed-paged.js +1 -276
  549. package/src/inference/kv-cache/quantized.d.ts +2 -2
  550. package/src/inference/kv-cache/quantized.js +4 -8
  551. package/src/inference/kv-cache/update.js +309 -0
  552. package/src/inference/model-checkpoint-evidence.d.ts +75 -0
  553. package/src/inference/model-checkpoint-evidence.js +264 -0
  554. package/src/inference/moe-router.js +36 -216
  555. package/src/inference/multi-model-network.js +5 -341
  556. package/src/inference/pipelines/audio/index.js +1 -20
  557. package/src/inference/pipelines/audio/mel.js +0 -38
  558. package/src/inference/pipelines/diffusion/profile-timing.js +10 -0
  559. package/src/inference/pipelines/diffusion/runtime-resources.js +54 -0
  560. package/src/inference/pipelines/diffusion/sd3/execution.js +805 -0
  561. package/src/inference/pipelines/diffusion/sd3/plan.js +125 -0
  562. package/src/inference/pipelines/diffusion/sd3-transformer.js +44 -895
  563. package/src/inference/pipelines/diffusion/{vae.js → vae/execution.js} +46 -618
  564. package/src/inference/pipelines/diffusion/{helpers.js → weight-contract.js} +1 -68
  565. package/src/inference/pipelines/energy-head/row-head-pipeline.d.ts +1 -103
  566. package/src/inference/pipelines/factory.js +14 -3
  567. package/src/inference/pipelines/shader-scoped-pipeline.js +29 -0
  568. package/src/inference/pipelines/structured/json-grammar-mask.js +0 -6
  569. package/src/inference/pipelines/text/abort-contract.js +22 -0
  570. package/src/inference/pipelines/text/attention/attn-config.js +1 -16
  571. package/src/inference/pipelines/text/attention/gate-projection.js +30 -0
  572. package/src/inference/pipelines/text/attention/heterogeneous-contract.js +8 -0
  573. package/src/inference/pipelines/text/attention/interpreter/immediate.js +211 -0
  574. package/src/inference/pipelines/text/attention/interpreter/recorded.js +451 -0
  575. package/src/inference/pipelines/text/attention/interpreter.js +89 -439
  576. package/src/inference/pipelines/text/attention/plan.d.ts +1 -0
  577. package/src/inference/pipelines/text/attention/plan.js +17 -0
  578. package/src/inference/pipelines/text/attention/projection-executor.js +331 -0
  579. package/src/inference/pipelines/text/attention/projection-plan.js +259 -0
  580. package/src/inference/pipelines/text/attention/projections.js +20 -537
  581. package/src/inference/pipelines/text/attention/query-transform.js +11 -0
  582. package/src/inference/pipelines/text/attention/record.js +0 -6
  583. package/src/inference/pipelines/text/attention/recorded-health.js +21 -0
  584. package/src/inference/pipelines/text/attention/rope-observation.js +40 -0
  585. package/src/inference/pipelines/text/attention/run.js +0 -6
  586. package/src/inference/pipelines/text/attention/types.js +3 -31
  587. package/src/inference/pipelines/text/chat-format.d.ts +3 -0
  588. package/src/inference/pipelines/text/chat-format.js +42 -0
  589. package/src/inference/pipelines/text/config/normalization.js +729 -0
  590. package/src/inference/pipelines/text/config/validation.js +9 -0
  591. package/src/inference/pipelines/text/config.d.ts +12 -1
  592. package/src/inference/pipelines/text/config.js +14 -1228
  593. package/src/inference/pipelines/text/debug-utils/health-metrics.js +57 -0
  594. package/src/inference/pipelines/text/debug-utils/index.js +3 -8
  595. package/src/inference/pipelines/text/debug-utils/profiles.js +8 -0
  596. package/src/inference/pipelines/text/debug-utils/readback-decoding.js +24 -0
  597. package/src/inference/pipelines/text/debug-utils/tensor.js +1 -1
  598. package/src/inference/pipelines/text/dtype-contract.js +1 -68
  599. package/src/inference/pipelines/text/embed.js +178 -241
  600. package/src/inference/pipelines/text/embedding-contract.d.ts +7 -0
  601. package/src/inference/pipelines/text/embedding-contract.js +21 -0
  602. package/src/inference/pipelines/text/embedding-extraction.js +225 -0
  603. package/src/inference/pipelines/text/embedding-normalization.js +39 -0
  604. package/src/inference/pipelines/text/execution-runtime-builders.js +0 -32
  605. package/src/inference/pipelines/text/execution-v1/plan.js +69 -0
  606. package/src/inference/pipelines/text/execution-v1/validation.js +233 -0
  607. package/src/inference/pipelines/text/execution-v1.js +7 -283
  608. package/src/inference/pipelines/text/execution.js +517 -0
  609. package/src/inference/pipelines/text/ffn/dense-executor.js +718 -0
  610. package/src/inference/pipelines/text/ffn/dense-plan.js +327 -0
  611. package/src/inference/pipelines/text/ffn/dense.js +4 -968
  612. package/src/inference/pipelines/text/ffn/sandwich.js +10 -9
  613. package/src/inference/pipelines/text/ffn/standard.js +2 -1
  614. package/src/inference/pipelines/text/generator/attention-lifecycle.js +24 -0
  615. package/src/inference/pipelines/text/generator/decode-runtime.js +991 -0
  616. package/src/inference/pipelines/text/generator/decode.js +952 -0
  617. package/src/inference/pipelines/text/generator/diffusion.js +607 -0
  618. package/src/inference/pipelines/text/generator/logits-config.js +63 -0
  619. package/src/inference/pipelines/text/generator/prefill-observation.js +29 -0
  620. package/src/inference/pipelines/text/generator/prefill-policy.js +56 -0
  621. package/src/inference/pipelines/text/generator/prefill-runtime.js +896 -0
  622. package/src/inference/pipelines/text/{generator-prefill-helpers.js → generator/prefix-embedding.js} +16 -121
  623. package/src/inference/pipelines/text/generator/prompt-input.js +47 -0
  624. package/src/inference/pipelines/text/generator/recovery.js +310 -0
  625. package/src/inference/pipelines/text/{generator-helpers.js → generator/session-context.js} +42 -110
  626. package/src/inference/pipelines/text/generator/text.js +448 -0
  627. package/src/inference/pipelines/text/generator/training.js +752 -0
  628. package/src/inference/pipelines/text/generator-decode-policy.js +1 -1
  629. package/src/inference/pipelines/text/generator-logits-observation.js +45 -0
  630. package/src/inference/pipelines/text/generator-runtime.js +5 -135
  631. package/src/inference/pipelines/text/generator-steps.js +30 -972
  632. package/src/inference/pipelines/text/generator.js +165 -3544
  633. package/src/inference/pipelines/text/image-transcription.js +304 -0
  634. package/src/inference/pipelines/text/init-qkv-fusion.js +18 -9
  635. package/src/inference/pipelines/text/init-rope.js +37 -189
  636. package/src/inference/pipelines/text/init.d.ts +8 -3
  637. package/src/inference/pipelines/text/init.js +6 -216
  638. package/src/inference/pipelines/text/layer-execution-contract.js +97 -0
  639. package/src/inference/pipelines/text/layer-input-execution.js +435 -0
  640. package/src/inference/pipelines/text/layer-plan-gpu.js +13 -6
  641. package/src/inference/pipelines/text/layer-plan.d.ts +21 -5
  642. package/src/inference/pipelines/text/layer-plan.js +45 -3
  643. package/src/inference/pipelines/text/layer.js +52 -522
  644. package/src/inference/pipelines/text/lifecycle.js +839 -0
  645. package/src/inference/pipelines/text/linear-attention/plan.js +554 -0
  646. package/src/inference/pipelines/text/linear-attention-ab-fusion.js +2 -2
  647. package/src/inference/pipelines/text/linear-attention.d.ts +2 -2
  648. package/src/inference/pipelines/text/linear-attention.js +7 -537
  649. package/src/inference/pipelines/text/logits/cpu-output.d.ts +1 -0
  650. package/src/inference/pipelines/text/logits/cpu-output.js +5 -0
  651. package/src/inference/pipelines/text/logits/cpu.d.ts +1 -87
  652. package/src/inference/pipelines/text/logits/cpu.js +8 -95
  653. package/src/inference/pipelines/text/logits/gpu-executor.js +368 -0
  654. package/src/inference/pipelines/text/logits/gpu.d.ts +27 -0
  655. package/src/inference/pipelines/text/logits/gpu.js +116 -579
  656. package/src/inference/pipelines/text/logits/index.d.ts +2 -1
  657. package/src/inference/pipelines/text/logits/index.js +62 -102
  658. package/src/inference/pipelines/text/logits/output-transform.js +47 -0
  659. package/src/inference/pipelines/text/logits/plan.js +184 -0
  660. package/src/inference/pipelines/text/logits/readback.d.ts +6 -0
  661. package/src/inference/pipelines/text/logits/readback.js +9 -0
  662. package/src/inference/pipelines/text/logits/scale-policy.js +20 -0
  663. package/src/inference/pipelines/text/logits/types.d.ts +1 -0
  664. package/src/inference/pipelines/text/lora-apply.js +12 -4
  665. package/src/inference/pipelines/text/lora-types.d.ts +12 -0
  666. package/src/inference/pipelines/text/modality-token-contract.js +115 -0
  667. package/src/inference/pipelines/text/model-load.js +0 -20
  668. package/src/inference/pipelines/text/moe/expert-loading.js +9 -0
  669. package/src/inference/pipelines/text/moe/gpu-executor.js +513 -0
  670. package/src/inference/pipelines/text/moe/plan.js +47 -0
  671. package/src/inference/pipelines/text/moe-cpu.js +9 -135
  672. package/src/inference/pipelines/text/moe-gpu.js +21 -545
  673. package/src/inference/pipelines/text/normalization-contract.js +17 -0
  674. package/src/inference/pipelines/text/per-layer/materialize.js +736 -0
  675. package/src/inference/pipelines/text/per-layer/plan.js +362 -0
  676. package/src/inference/pipelines/text/per-layer-inputs.js +4 -1037
  677. package/src/inference/pipelines/text/pipeline-load-timing.js +77 -0
  678. package/src/inference/pipelines/text/probes.js +20 -0
  679. package/src/inference/pipelines/text/state.d.ts +8 -0
  680. package/src/inference/pipelines/text/state.js +1 -0
  681. package/src/inference/pipelines/text/tsir-fixture-writer.js +88 -16
  682. package/src/inference/pipelines/text/types.d.ts +4 -0
  683. package/src/inference/pipelines/text/weight-loading-config.js +194 -0
  684. package/src/inference/pipelines/text.d.ts +2 -2
  685. package/src/inference/pipelines/text.js +46 -1633
  686. package/src/inference/pipelines/video/frame-sampler.js +0 -13
  687. package/src/inference/pipelines/video/index.js +0 -21
  688. package/src/inference/pipelines/vision/attention.js +59 -0
  689. package/src/inference/pipelines/vision/encoder.js +254 -369
  690. package/src/inference/pipelines/vision/gemma4.js +204 -318
  691. package/src/inference/pipelines/vision/glmocr-preprocess.js +273 -0
  692. package/src/inference/pipelines/vision/glmocr-rope.js +106 -0
  693. package/src/inference/pipelines/vision/glmocr.js +557 -0
  694. package/src/inference/pipelines/vision/image-preprocess.js +0 -27
  695. package/src/inference/pipelines/vision/index.js +8 -27
  696. package/src/inference/pipelines/vision/ops.js +11 -33
  697. package/src/inference/pipelines/vision/patch-embed.js +51 -145
  698. package/src/inference/pipelines/vision/spatial-merge.js +78 -0
  699. package/src/inference/pipelines/vision/weight-loading.js +79 -0
  700. package/src/inference/refactor-receipt.js +2 -2
  701. package/src/inference/rerank.js +182 -0
  702. package/src/inference/tokenizer.js +1 -1
  703. package/src/inference/tokenizers/behavior-flags.js +6 -3
  704. package/src/inference/tokenizers/bundled/decoders.js +133 -0
  705. package/src/inference/tokenizers/bundled/registry.js +216 -0
  706. package/src/inference/tokenizers/bundled.js +23 -353
  707. package/src/loader/doppler-loader.d.ts +4 -0
  708. package/src/loader/doppler-loader.js +119 -930
  709. package/src/loader/embedding-limit-preflight.js +11 -4
  710. package/src/loader/embedding-loader.js +1 -3
  711. package/src/loader/gpu-tensor-materialization.js +20 -0
  712. package/src/loader/layer-loader.js +15 -119
  713. package/src/loader/layer-tensor-aliases.js +99 -0
  714. package/src/loader/layer-weight-shape.js +29 -0
  715. package/src/loader/load-timing.js +64 -0
  716. package/src/loader/loader-types.d.ts +3 -0
  717. package/src/loader/model-executor.js +819 -0
  718. package/src/loader/model-load-validation.js +15 -0
  719. package/src/loader/quantization-constants.d.ts +11 -29
  720. package/src/loader/quantization-constants.js +1 -2
  721. package/src/loader/shard-resolver.js +0 -14
  722. package/src/loader/tensor-load-error.js +14 -0
  723. package/src/loader/tensor-shard-indices.js +8 -0
  724. package/src/loader/tensors/bf16-loader.js +125 -0
  725. package/src/loader/tensors/functional-descriptor-loader.js +3 -375
  726. package/src/loader/tensors/load-executor.js +577 -0
  727. package/src/loader/tensors/source-transform/executor.js +123 -0
  728. package/src/loader/tensors/source-transform/plan.js +107 -0
  729. package/src/loader/tensors/source-transform.js +15 -264
  730. package/src/loader/tensors/tensor-loader.d.ts +4 -4
  731. package/src/loader/tensors/tensor-loader.js +7 -653
  732. package/src/memory/buffer-pool.js +7 -29
  733. package/src/rules/capability-transform-resolver.js +80 -0
  734. package/src/rules/execution-contract.d.ts +73 -0
  735. package/src/rules/execution-contract.js +429 -0
  736. package/src/rules/execution-rules-contract-check.js +1 -1
  737. package/src/rules/generated/rule-bundle.json +4305 -0
  738. package/src/rules/inference/capability-transforms.rules.json +3 -3
  739. package/src/rules/layer-pattern-contract-check.js +1 -1
  740. package/src/rules/rule-registry.js +70 -57
  741. package/src/storage/artifact-storage-context.js +2 -2
  742. package/src/storage/backend-selection.js +43 -0
  743. package/src/storage/distribution-transport.js +5 -0
  744. package/src/storage/download/integrity.d.ts +33 -0
  745. package/src/storage/download/integrity.js +130 -0
  746. package/src/storage/download/resume-inspection.d.ts +22 -0
  747. package/src/storage/download/resume-inspection.js +134 -0
  748. package/src/storage/download/retry.js +57 -0
  749. package/src/storage/download/state.js +131 -0
  750. package/src/storage/download/transport.js +99 -0
  751. package/src/storage/downloader.js +74 -453
  752. package/src/storage/model-cache.d.ts +1 -0
  753. package/src/storage/model-cache.js +51 -11
  754. package/src/storage/shard-manager.d.ts +5 -0
  755. package/src/storage/shard-manager.js +50 -369
  756. package/src/storage/shards/index.js +60 -0
  757. package/src/storage/shards/integrity.js +225 -0
  758. package/src/storage/shards/lifecycle.js +22 -0
  759. package/src/storage/source-artifact-store.js +14 -4
  760. package/src/tooling/boundary-evidence.d.ts +4 -4
  761. package/src/tooling/boundary-evidence.js +20 -20
  762. package/src/tooling/browser-command-runner.js +13 -6
  763. package/src/tooling/capsule-v2.d.ts +11 -0
  764. package/src/tooling/capsule-v2.js +58 -0
  765. package/src/tooling/capsule.js +20 -0
  766. package/src/tooling/command-api-constants.js +1 -1
  767. package/src/tooling/command-api-family-normalizers.js +163 -5
  768. package/src/tooling/command-api.d.ts +42 -3
  769. package/src/tooling/command-api.js +7 -2
  770. package/src/tooling/command-envelope.js +1 -1
  771. package/src/tooling/{command-api-helpers.js → command-request-normalization.js} +1 -1
  772. package/src/tooling/command-runner.html +49 -1
  773. package/src/tooling/command-validation.js +1 -24
  774. package/src/tooling/conversion-run-timing.js +24 -0
  775. package/src/tooling/diagnose-runner.js +11 -9
  776. package/src/tooling/distribution-shard-transport.js +11 -0
  777. package/src/tooling/execution-cost-ledger.d.ts +76 -2
  778. package/src/tooling/execution-cost-ledger.js +197 -15
  779. package/src/tooling/hf-registry/catalog-io.js +63 -0
  780. package/src/tooling/litert/package.js +863 -0
  781. package/src/tooling/litert-package-runtime.js +3 -849
  782. package/src/tooling/model-capsule-forge.js +478 -0
  783. package/src/tooling/node-browser/execution.d.ts +40 -0
  784. package/src/tooling/node-browser/execution.js +308 -0
  785. package/src/tooling/node-browser/static-server.js +188 -0
  786. package/src/tooling/node-browser/transport.d.ts +80 -0
  787. package/src/tooling/node-browser/transport.js +622 -0
  788. package/src/tooling/node-browser-command-runner.d.ts +18 -78
  789. package/src/tooling/node-browser-command-runner.js +10 -1112
  790. package/src/tooling/node-capsule-artifact-store.js +44 -0
  791. package/src/tooling/node-command-execution.js +237 -0
  792. package/src/tooling/node-command-runner.js +26 -205
  793. package/src/tooling/node-converter/input.js +521 -0
  794. package/src/tooling/node-converter/output.js +244 -0
  795. package/src/tooling/node-converter-chunk-batches.js +21 -0
  796. package/src/tooling/node-converter.js +7 -720
  797. package/src/tooling/node-source-runtime.js +16 -276
  798. package/src/tooling/node-webgpu-provider.v1.json +33 -0
  799. package/src/tooling/node-webgpu.js +178 -453
  800. package/src/tooling/opfs-cache.d.ts +5 -0
  801. package/src/tooling/opfs-cache.js +4 -0
  802. package/src/tooling/production-release.d.ts +19 -0
  803. package/src/tooling/production-release.js +647 -0
  804. package/src/tooling/program-bundle/embedding-reference.js +19 -0
  805. package/src/tooling/program-bundle/materialize.js +324 -0
  806. package/src/tooling/program-bundle/rerank-reference.js +22 -0
  807. package/src/tooling/program-bundle/sequence-reference.js +42 -0
  808. package/src/tooling/program-bundle/validation.js +31 -0
  809. package/src/tooling/program-bundle/wgsl-closure.js +254 -0
  810. package/src/tooling/program-bundle-parity.d.ts +11 -4
  811. package/src/tooling/program-bundle-parity.js +262 -109
  812. package/src/tooling/program-bundle.d.ts +7 -0
  813. package/src/tooling/program-bundle.js +186 -591
  814. package/src/tooling/provider-v1-contract.d.ts +61 -0
  815. package/src/tooling/provider-v1-contract.js +192 -0
  816. package/src/tooling/registered-variant-calibration-job.d.ts +98 -0
  817. package/src/tooling/registered-variant-calibration-job.js +210 -0
  818. package/src/tooling/registered-variant-calibration.d.ts +167 -7
  819. package/src/tooling/registered-variant-calibration.js +57 -7
  820. package/src/tooling/runtime-optimization/candidates.js +664 -0
  821. package/src/tooling/runtime-optimization-campaign.js +166 -0
  822. package/src/tooling/runtime-optimization-index.js +16 -1
  823. package/src/tooling/runtime-optimization.d.ts +44 -0
  824. package/src/tooling/runtime-optimization.js +13 -656
  825. package/src/tooling/source-intake.d.ts +1 -1
  826. package/src/tooling/source-intake.js +34 -17
  827. package/src/tooling/source-package-profiles.js +1 -1
  828. package/src/tooling/source-runtime/bundle-materialize.js +298 -0
  829. package/src/tooling/source-runtime/bundle-plan.js +121 -0
  830. package/src/tooling/source-runtime/node-loader.js +258 -0
  831. package/src/tooling/source-runtime-bundle.js +26 -411
  832. package/src/tooling/source-runtime-converter-config.js +1 -1
  833. package/src/tooling-experimental-exports.js +0 -5
  834. package/src/tooling-exports/evidence.d.ts +14 -3
  835. package/src/tooling-exports/evidence.js +14 -3
  836. package/src/tooling-exports/storage.d.ts +5 -0
  837. package/src/tooling-exports/storage.js +4 -0
  838. package/src/tooling-exports.d.ts +3 -0
  839. package/src/tooling-exports.js +2 -0
  840. package/src/tooling-exports.shared.d.ts +17 -3
  841. package/src/tooling-exports.shared.js +9 -3
  842. package/src/training.d.ts +6 -6
  843. package/src/training.js +4 -4
  844. package/src/version.js +1 -1
  845. package/tests/kernels/browser/kernel-suite.js +512 -0
  846. package/tests/kernels/browser/test-page.js +169 -14
  847. package/tests/kernels/harness/tolerance.js +1 -0
  848. package/tests/kernels/reference/index.js +13 -1
  849. package/tests/kernels/reference/vision.js +160 -0
  850. package/src/converter/quantizer.d.ts +0 -121
  851. package/src/gpu/kernels/backward/utils.d.ts +0 -90
  852. package/src/gpu/kernels/uniform-utils.d.ts +0 -66
  853. package/src/gpu/kernels/utils.d.ts +0 -147
  854. package/src/inference/pipelines/text/debug-utils/utils.js +0 -118
  855. package/src/inference/pipelines/text/logits/utils.d.ts +0 -58
  856. package/src/inference/pipelines/text/moe-cpu-gptoss.js +0 -115
  857. package/src/inference/pipelines/text/moe-helpers.js +0 -21
  858. package/src/rules/converter/execution.rules.json +0 -20
  859. package/src/rules/converter/tensor-roles.rules.json +0 -13
  860. package/src/rules/converter/tokenizer.rules.json +0 -12
  861. package/src/rules/inference/attention.rules.json +0 -69
  862. package/src/rules/inference/config.rules.json +0 -82
  863. package/src/rules/inference/dtype.rules.json +0 -113
  864. package/src/rules/inference/execution.rules.json +0 -195
  865. package/src/rules/inference/ffn.rules.json +0 -123
  866. package/src/rules/inference/layer-pattern.rules.json +0 -16
  867. package/src/rules/inference/layer.rules.json +0 -7
  868. package/src/rules/inference/moe.rules.json +0 -145
  869. package/src/rules/kernels/attention.rules.json +0 -68
  870. package/src/rules/kernels/conv2d.rules.json +0 -6
  871. package/src/rules/kernels/depthwise-conv2d.rules.json +0 -6
  872. package/src/rules/kernels/dequant.rules.json +0 -58
  873. package/src/rules/kernels/energy.rules.json +0 -22
  874. package/src/rules/kernels/fused-ffn.rules.json +0 -15
  875. package/src/rules/kernels/fused-matmul-residual.rules.json +0 -6
  876. package/src/rules/kernels/fused-matmul-rmsnorm.rules.json +0 -8
  877. package/src/rules/kernels/gather.rules.json +0 -93
  878. package/src/rules/kernels/gelu.rules.json +0 -11
  879. package/src/rules/kernels/grouped-pointwise-conv2d.rules.json +0 -6
  880. package/src/rules/kernels/groupnorm.rules.json +0 -10
  881. package/src/rules/kernels/kv_quantize.rules.json +0 -9
  882. package/src/rules/kernels/layernorm.rules.json +0 -6
  883. package/src/rules/kernels/linear-attention.rules.json +0 -6
  884. package/src/rules/kernels/lm-head-argmax.rules.json +0 -10
  885. package/src/rules/kernels/matmul.rules.json +0 -95
  886. package/src/rules/kernels/modulate.rules.json +0 -6
  887. package/src/rules/kernels/moe.rules.gptoss.json +0 -105
  888. package/src/rules/kernels/moe.rules.json +0 -14
  889. package/src/rules/kernels/moe.rules.mixtral.json +0 -75
  890. package/src/rules/kernels/pixel_shuffle.rules.json +0 -6
  891. package/src/rules/kernels/relu.rules.json +0 -6
  892. package/src/rules/kernels/rep-penalty.rules.json +0 -6
  893. package/src/rules/kernels/repeat-channels.rules.json +0 -6
  894. package/src/rules/kernels/residual.rules.json +0 -12
  895. package/src/rules/kernels/rmsnorm-qk.rules.json +0 -6
  896. package/src/rules/kernels/rmsnorm.rules.json +0 -46
  897. package/src/rules/kernels/rope-qk.rules.json +0 -6
  898. package/src/rules/kernels/rope.rules.json +0 -6
  899. package/src/rules/kernels/sample.rules.json +0 -6
  900. package/src/rules/kernels/scale.rules.json +0 -8
  901. package/src/rules/kernels/silu.rules.json +0 -22
  902. package/src/rules/kernels/softmax.rules.json +0 -25
  903. package/src/rules/kernels/split-qg.rules.json +0 -6
  904. package/src/rules/kernels/split-qkv.rules.json +0 -6
  905. package/src/rules/kernels/upsample2d.rules.json +0 -6
  906. package/src/rules/loader/tensor-loader.rules.json +0 -42
  907. package/src/rules/loader/weights.rules.json +0 -42
  908. package/src/rules/tooling/command-runtime.rules.json +0 -65
  909. package/src/tooling/hf-registry-utils.js +0 -395
  910. /package/src/converter/{tokenizer-utils.js → tokenizer-special-tokens.js} +0 -0
  911. /package/src/{inference/pipelines/text/bdpa-steamroller.js → experimental/bdpa/steamroller.js} +0 -0
  912. /package/src/{inference/pipelines → experimental}/diffusion/scheduler.js +0 -0
  913. /package/src/{inference/pipelines → experimental}/energy/pipeline.d.ts +0 -0
  914. /package/src/{inference/pipelines → experimental}/energy/quintel.d.ts +0 -0
  915. /package/src/{inference/pipelines → experimental}/energy/quintel.js +0 -0
  916. /package/src/{utils → formats}/array-buffer.js +0 -0
  917. /package/src/{utils → formats}/canonical-hash.js +0 -0
  918. /package/src/{utils → formats}/clone-json.js +0 -0
  919. /package/src/{utils → formats}/encode-utf8.js +0 -0
  920. /package/src/{utils → formats}/load-json.js +0 -0
  921. /package/src/{utils → formats}/plain-object.js +0 -0
  922. /package/src/{utils → formats}/sha256.js +0 -0
  923. /package/src/{utils → formats}/stable-sort-object.js +0 -0
  924. /package/src/{gpu/kernels → rules}/rule-matcher.js +0 -0
  925. /package/src/{utils → storage}/hf-resolve-url.js +0 -0
  926. /package/src/{utils → storage}/runtime-env.js +0 -0
  927. /package/src/tooling/{command-runner-shared.js → command-runtime-execution.js} +0 -0
@@ -18,9 +18,10 @@ import {
18
18
  resolveStaticRootDir,
19
19
  resolveRdrrRoot,
20
20
  } from './cli-model-resolution.js';
21
- import { isPlainObject } from '../utils/plain-object.js';
21
+ import { isPlainObject } from '../formats/plain-object.js';
22
22
  import {
23
23
  toSummary,
24
+ isFailedVerificationResult,
24
25
  formatNumber,
25
26
  formatMs,
26
27
  saveBenchResult,
@@ -33,50 +34,33 @@ import {
33
34
  printMetricsSummary,
34
35
  } from './cli-output.js';
35
36
  import { formatRuntimeProfiles, listRuntimeProfiles } from './runtime-profiles.js';
37
+ import { persistBrowserRelayReport } from './browser-report-output.js';
38
+ import { isAbsoluteUrl, normalizeModelUrl, parseJsonObjectFlag, performIntake, readJsonObjectFile, readJsonObjectInput, runBoundaryCommand, runBundleCommand, runCommandOnSurface } from './commands/bundle.js';
39
+ import { DEFAULT_CLI_POLICY, createCliToolingErrorEnvelope, parseRuntimeConfigUrl, resolveConfigEnvelope, resolveSurfaceForCommand, runManifestSweep, runWithAutoSurface } from './output/manifest.js';
40
+ import {
41
+ parseCliArguments,
42
+ validateBoundaryFlags,
43
+ validateBundleFlags,
44
+ validateCommandFlags,
45
+ validateIntakeFlags,
46
+ validateOnboardFlags,
47
+ validateProfilesFlags,
48
+ validateProgramBundleFlags,
49
+ } from './argument-contract.js';
50
+ export { createCliToolingErrorEnvelope } from './output/manifest.js';
51
+ export { checkCapturePrecondition, finalizeCliCommandResponse, performIntake } from './commands/bundle.js';
36
52
 
37
53
  export { resolveBrowserModelUrl, resolveNodeModelUrl } from './cli-model-resolution.js';
38
54
 
39
- const NODE_WEBGPU_INCOMPLETE_MESSAGE = 'node command: WebGPU runtime is incomplete in Node';
40
55
  const CLI_POLICY_PATH = fileURLToPath(new URL('./config/doppler-cli-policy.json', import.meta.url));
41
- const DEFAULT_CLI_POLICY = {
42
- defaults: {
43
- surface: {
44
- default: 'auto',
45
- allowed: ['auto', 'node', 'browser'],
46
- },
47
- bench: {
48
- cacheMode: 'warm',
49
- },
50
- cacheMode: null,
51
- loadMode: null,
52
- benchmark: {
53
- saveDir: './benchmarks/vendors/results',
54
- },
55
- },
56
- surfaceFallback: {
57
- enabled: true,
58
- from: 'auto',
59
- to: 'browser',
60
- errorFragments: [NODE_WEBGPU_INCOMPLETE_MESSAGE],
61
- },
62
- };
63
-
64
- const COMMON_CLI_FLAGS = Object.freeze([
65
- 'config',
66
- 'surface',
67
- 'pretty',
68
- 'json',
69
- 'help',
70
- 'h',
71
- 'runtime-config',
72
- 'runtime-profile',
73
- ]);
74
56
 
75
57
  function usage() {
76
58
  return [
77
59
  'Usage:',
78
60
  ' doppler convert --config <path|url|json> [--surface auto|node]',
79
61
  ' doppler refresh-integrity --config <path|url|json> [--surface auto|node]',
62
+ ' doppler release --manifest <path> --out <dir> --capsule-trusted-signers <path> --fleet-trusted-signers <path> --signing-private-key <path> --signing-public-key <path> --signing-authority <id> [--fleet-receipts <path,path>] [--forge-config <path>]',
63
+ ' doppler release --action qualify --manifest <path> --target <id> --device-identity <path> --out <dir> --capsule-trusted-signers <path> --signing-private-key <path> --signing-public-key <path> --signing-authority <id>',
80
64
  ' doppler debug --config <path|url|json> [--runtime-profile <id>|--runtime-config <path|url|json>] [--surface auto|node|browser]',
81
65
  ' doppler bench --config <path|url|json> [--runtime-profile <id>|--runtime-config <path|url|json>] [--surface auto|node|browser]',
82
66
  ' doppler verify --config <path|url|json> [--runtime-profile <id>|--runtime-config <path|url|json>] [--surface auto|node|browser]',
@@ -88,9 +72,9 @@ function usage() {
88
72
  ' doppler program-bundle --manifest <path> --reference-report <path> --out <path> [--conversion-config <path>]',
89
73
  ' doppler onboard inspect --source <checkpoint-dir> --out <dir> [--family-intake <source-intake.json>]',
90
74
  ' doppler boundary capture --report <diagnose-report.json> --out <runtime-boundaries.json>',
91
- ' doppler boundary source-pack --provider-capture <provider-capture.json> --out <source-boundaries.json>',
75
+ ' doppler boundary source-capsule --provider-capture <provider-capture.json> --out <source-boundaries.json>',
92
76
  ' doppler boundary token-evidence --reference-transcript <reference-transcript.json> --out <token-evidence.json>',
93
- ' doppler boundary compare --source-pack <source-boundaries.json> --runtime-capture <runtime-boundaries.json> --token-evidence <json> --out <receipt.json>',
77
+ ' doppler boundary compare --source-capsule <source-boundaries.json> --runtime-capture <runtime-boundaries.json> --token-evidence <json> --out <receipt.json>',
94
78
  ' doppler intake --convert-config <path|json> [--manifest <path>] [--out <intake-report.json>]',
95
79
  ' doppler bundle --manifest <path> --out <dir> [--prompt <text>] [--max-tokens <n>] [--surface node|browser]',
96
80
  ' doppler bundle --convert-config <path|json> --out <dir>',
@@ -123,359 +107,6 @@ function usage() {
123
107
  ].join('\n');
124
108
  }
125
109
 
126
- function parseArgs(argv) {
127
- const out = {
128
- command: null,
129
- action: null,
130
- flags: {},
131
- };
132
-
133
- if (!argv.length) return out;
134
- out.command = asStringOrNull(argv[0]);
135
-
136
- for (let i = 1; i < argv.length; i += 1) {
137
- const token = argv[i];
138
- if (token === '-h') {
139
- out.flags.h = true;
140
- continue;
141
- }
142
- if (token.startsWith('-') && !token.startsWith('--')) {
143
- throw new Error(`Unsupported short flag "${token}". Use long-form flags (for example --help).`);
144
- }
145
- if (!token.startsWith('--')) {
146
- if ((out.command === 'onboard' || out.command === 'boundary') && out.action === null) {
147
- out.action = token;
148
- continue;
149
- }
150
- throw new Error('Positional arguments are not supported. Use --config for command payloads.');
151
- }
152
-
153
- const key = token.slice(2);
154
- if (
155
- key === 'json'
156
- || key === 'pretty'
157
- || key === 'help'
158
- || key === 'h'
159
- || key === 'skip-convert'
160
- || key === 'skip-capture'
161
- ) {
162
- out.flags[key] = true;
163
- continue;
164
- }
165
-
166
- const value = argv[i + 1];
167
- if (value === undefined) {
168
- throw new Error(`Missing value for --${key}`);
169
- }
170
-
171
- if (value.startsWith('--')) {
172
- throw new Error(`Missing value for --${key}`);
173
- }
174
-
175
- out.flags[key] = value;
176
- i += 1;
177
- }
178
-
179
- return out;
180
- }
181
-
182
- function levenshteinDistance(a, b) {
183
- const source = String(a ?? '');
184
- const target = String(b ?? '');
185
- if (source === target) return 0;
186
- if (source.length === 0) return target.length;
187
- if (target.length === 0) return source.length;
188
-
189
- const previous = new Array(target.length + 1);
190
- const current = new Array(target.length + 1);
191
-
192
- for (let i = 0; i <= target.length; i += 1) {
193
- previous[i] = i;
194
- }
195
-
196
- for (let i = 1; i <= source.length; i += 1) {
197
- current[0] = i;
198
- for (let j = 1; j <= target.length; j += 1) {
199
- const cost = source[i - 1] === target[j - 1] ? 0 : 1;
200
- current[j] = Math.min(
201
- previous[j] + 1,
202
- current[j - 1] + 1,
203
- previous[j - 1] + cost
204
- );
205
- }
206
- for (let j = 0; j <= target.length; j += 1) {
207
- previous[j] = current[j];
208
- }
209
- }
210
-
211
- return previous[target.length];
212
- }
213
-
214
- function findClosestFlag(flag, allowedFlags) {
215
- const normalizedFlag = String(flag ?? '').trim();
216
- if (!normalizedFlag) return null;
217
-
218
- let candidate = null;
219
- let distance = Infinity;
220
- for (const allowedFlag of allowedFlags) {
221
- const nextDistance = levenshteinDistance(normalizedFlag, allowedFlag);
222
- if (nextDistance < distance) {
223
- candidate = allowedFlag;
224
- distance = nextDistance;
225
- }
226
- }
227
- return distance <= 3 ? candidate : null;
228
- }
229
-
230
- function validateCommandFlags(parsed) {
231
- const command = parsed?.command;
232
- if (!command || !TOOLING_COMMANDS.includes(command)) {
233
- return;
234
- }
235
-
236
- const allowedFlags = new Set(COMMON_CLI_FLAGS);
237
- const keys = Object.keys(parsed.flags || {});
238
- for (const key of keys) {
239
- if (allowedFlags.has(key)) {
240
- continue;
241
- }
242
-
243
- const suggestion = findClosestFlag(key, allowedFlags);
244
- if (suggestion) {
245
- throw new Error(`Unknown flag --${key} for "${command}". Did you mean --${suggestion}?`);
246
- }
247
- throw new Error(`Unknown flag --${key} for "${command}".`);
248
- }
249
- }
250
-
251
- function validateProgramBundleFlags(parsed) {
252
- const allowedFlags = new Set([
253
- 'config',
254
- 'manifest',
255
- 'model-dir',
256
- 'reference-report',
257
- 'conversion-config',
258
- 'runtime-config',
259
- 'out',
260
- 'bundle-id',
261
- 'created-at',
262
- 'pretty',
263
- 'json',
264
- 'help',
265
- 'h',
266
- ]);
267
- for (const key of Object.keys(parsed.flags || {})) {
268
- if (allowedFlags.has(key)) continue;
269
- throw new Error(`Unknown flag --${key} for "program-bundle".`);
270
- }
271
- }
272
-
273
- function validateIntakeFlags(parsed) {
274
- const allowedFlags = new Set([
275
- 'convert-config',
276
- 'manifest',
277
- 'model-dir',
278
- 'out',
279
- 'skip-convert',
280
- 'pretty',
281
- 'json',
282
- 'help',
283
- 'h',
284
- ]);
285
- for (const key of Object.keys(parsed.flags || {})) {
286
- if (allowedFlags.has(key)) continue;
287
- throw new Error(`Unknown flag --${key} for "intake".`);
288
- }
289
- }
290
-
291
- function validateOnboardFlags(parsed) {
292
- if (parsed.action !== 'inspect') {
293
- throw new Error('onboard: expected the action "inspect".');
294
- }
295
- const allowedFlags = new Set([
296
- 'source',
297
- 'out',
298
- 'family-intake',
299
- 'pretty',
300
- 'json',
301
- 'help',
302
- 'h',
303
- ]);
304
- for (const key of Object.keys(parsed.flags || {})) {
305
- if (allowedFlags.has(key)) continue;
306
- throw new Error(`Unknown flag --${key} for "onboard inspect".`);
307
- }
308
- if (!asStringOrNull(parsed.flags.source)) {
309
- throw new Error('onboard inspect: --source <checkpoint-dir> is required.');
310
- }
311
- if (!asStringOrNull(parsed.flags.out)) {
312
- throw new Error('onboard inspect: --out <dir> is required.');
313
- }
314
- }
315
-
316
- function validateBoundaryFlags(parsed) {
317
- const captureFlags = new Set([
318
- 'report',
319
- 'out',
320
- 'tolerance-policy',
321
- 'pretty',
322
- 'json',
323
- 'help',
324
- 'h',
325
- ]);
326
- const compareFlags = new Set([
327
- 'source-pack',
328
- 'runtime-capture',
329
- 'source-control',
330
- 'token-evidence',
331
- 'artifact-precision',
332
- 'out',
333
- 'pretty',
334
- 'json',
335
- 'help',
336
- 'h',
337
- ]);
338
- const tokenEvidenceFlags = new Set([
339
- 'reference-transcript',
340
- 'out',
341
- 'pretty',
342
- 'json',
343
- 'help',
344
- 'h',
345
- ]);
346
- const sourcePackFlags = new Set([
347
- 'provider-capture',
348
- 'out',
349
- 'pretty',
350
- 'json',
351
- 'help',
352
- 'h',
353
- ]);
354
- const allowedFlags = parsed.action === 'capture'
355
- ? captureFlags
356
- : (
357
- parsed.action === 'compare'
358
- ? compareFlags
359
- : (
360
- parsed.action === 'token-evidence'
361
- ? tokenEvidenceFlags
362
- : (parsed.action === 'source-pack' ? sourcePackFlags : null)
363
- )
364
- );
365
- if (!allowedFlags) {
366
- throw new Error(
367
- 'boundary: expected "capture", "source-pack", "token-evidence", or "compare".'
368
- );
369
- }
370
- for (const key of Object.keys(parsed.flags || {})) {
371
- if (allowedFlags.has(key)) continue;
372
- throw new Error(`Unknown flag --${key} for "boundary ${parsed.action}".`);
373
- }
374
- if (!asStringOrNull(parsed.flags.out)) {
375
- throw new Error(`boundary ${parsed.action}: --out <path> is required.`);
376
- }
377
- if (parsed.action === 'capture' && !asStringOrNull(parsed.flags.report)) {
378
- throw new Error('boundary capture: --report <diagnose-report.json> is required.');
379
- }
380
- if (
381
- parsed.action === 'source-pack'
382
- && !asStringOrNull(parsed.flags['provider-capture'])
383
- ) {
384
- throw new Error(
385
- 'boundary source-pack: --provider-capture <provider-capture.json> is required.'
386
- );
387
- }
388
- if (
389
- parsed.action === 'token-evidence'
390
- && !asStringOrNull(parsed.flags['reference-transcript'])
391
- ) {
392
- throw new Error(
393
- 'boundary token-evidence: --reference-transcript <reference-transcript.json> is required.'
394
- );
395
- }
396
- if (parsed.action === 'compare') {
397
- for (const key of ['source-pack', 'runtime-capture', 'token-evidence']) {
398
- if (!asStringOrNull(parsed.flags[key])) {
399
- throw new Error(`boundary compare: --${key} <path> is required.`);
400
- }
401
- }
402
- }
403
- }
404
-
405
- function validateBundleFlags(parsed) {
406
- const allowedFlags = new Set([
407
- 'convert-config',
408
- 'manifest',
409
- 'model-dir',
410
- 'model-url',
411
- 'conversion-config',
412
- 'prompt',
413
- 'max-tokens',
414
- 'surface',
415
- 'runtime-config',
416
- 'out',
417
- 'bundle-id',
418
- 'created-at',
419
- 'skip-convert',
420
- 'skip-capture',
421
- 'reference-report',
422
- 'reference-transcript',
423
- 'pretty',
424
- 'json',
425
- 'help',
426
- 'h',
427
- ]);
428
- for (const key of Object.keys(parsed.flags || {})) {
429
- if (allowedFlags.has(key)) continue;
430
- throw new Error(`Unknown flag --${key} for "bundle".`);
431
- }
432
- }
433
-
434
- function validateProfilesFlags(parsed) {
435
- const allowedFlags = new Set([
436
- 'pretty',
437
- 'json',
438
- 'help',
439
- 'h',
440
- ]);
441
- for (const key of Object.keys(parsed.flags || {})) {
442
- if (allowedFlags.has(key)) continue;
443
- throw new Error(`Unknown flag --${key} for "profiles".`);
444
- }
445
- }
446
-
447
- function parseJsonObjectFlag(value, label) {
448
- if (asStringOrNull(value) === null) return null;
449
- try {
450
- const parsed = JSON.parse(value);
451
- if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed)) {
452
- throw new Error('value must be a JSON object');
453
- }
454
- return parsed;
455
- } catch (error) {
456
- throw new Error(`Invalid ${label}: ${error.message}`);
457
- }
458
- }
459
-
460
- function parseRuntimeConfigUrl(value) {
461
- const normalized = asStringOrNull(value);
462
- if (normalized === null) return null;
463
- return isAbsoluteUrl(normalized)
464
- ? normalized
465
- : pathToFileURL(path.resolve(normalized)).href;
466
- }
467
-
468
- function isAbsoluteUrl(value) {
469
- const normalized = asStringOrNull(value);
470
- if (normalized === null) return false;
471
- try {
472
- const parsed = new URL(normalized);
473
- return typeof parsed.protocol === 'string' && parsed.protocol.length > 0;
474
- } catch {
475
- return false;
476
- }
477
- }
478
-
479
110
  function parseUnifiedRuntimeConfig(value) {
480
111
  const normalized = asStringOrNull(value);
481
112
  if (normalized === null) return null;
@@ -536,65 +167,6 @@ function resolveRuntimeConfigFlags(parsed) {
536
167
  return parseUnifiedRuntimeConfig(unifiedRaw);
537
168
  }
538
169
 
539
- async function readJsonObjectFile(filePath, label) {
540
- const resolved = path.resolve(String(filePath));
541
- let raw;
542
- try {
543
- raw = await fs.readFile(resolved, 'utf8');
544
- } catch (error) {
545
- throw new Error(`${label} not found or unreadable: ${resolved}`);
546
- }
547
- let parsed;
548
- try {
549
- parsed = JSON.parse(raw);
550
- } catch (error) {
551
- throw new Error(`${label} must contain valid JSON: ${error.message}`);
552
- }
553
- if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed)) {
554
- throw new Error(`${label} must be a JSON object.`);
555
- }
556
- return parsed;
557
- }
558
-
559
- async function readJsonObjectUrl(rawUrl, label) {
560
- let response;
561
- try {
562
- response = await fetch(rawUrl, {
563
- headers: {
564
- Connection: 'close',
565
- },
566
- redirect: 'follow',
567
- signal: AbortSignal.timeout(30000),
568
- });
569
- } catch (error) {
570
- throw new Error(`${label} URL request failed: ${error?.message || String(error)}`);
571
- }
572
- if (!response.ok) {
573
- throw new Error(`${label} URL request failed: HTTP ${response.status}`);
574
- }
575
- let raw;
576
- try {
577
- raw = await response.text();
578
- } catch (error) {
579
- throw new Error(`${label} URL request failed: ${error?.message || String(error)}`);
580
- }
581
- return parseJsonObjectFlag(raw, label);
582
- }
583
-
584
- async function readJsonObjectInput(inputValue, label) {
585
- const normalized = asStringOrNull(inputValue);
586
- if (normalized === null) {
587
- throw new Error(`${label} is required.`);
588
- }
589
- if (normalized.startsWith('{')) {
590
- return parseJsonObjectFlag(normalized, label);
591
- }
592
- if (isAbsoluteUrl(normalized)) {
593
- return readJsonObjectUrl(normalized, label);
594
- }
595
- return readJsonObjectFile(normalized, label);
596
- }
597
-
598
170
  async function buildProgramBundleOptions(parsed) {
599
171
  const repoRoot = path.resolve(fileURLToPath(new URL('../..', import.meta.url)));
600
172
  const configValue = asStringOrNull(parsed.flags.config);
@@ -636,140 +208,6 @@ async function runProgramBundleCommand(parsed, jsonOutput) {
636
208
  );
637
209
  }
638
210
 
639
- const INTAKE_SCHEMA_ID = 'doppler.intake-report/v1';
640
-
641
- export async function performIntake({
642
- convertConfigValue = null,
643
- manifestFlag = null,
644
- modelDir = null,
645
- skipConvert = false,
646
- } = {}) {
647
- const { extractExecutionContractFacts, validateExecutionContractFacts } = await import(
648
- '../config/execution-contract-check.js'
649
- );
650
- const fsMod = await import('node:fs/promises');
651
-
652
- const stages = [];
653
- const blockers = [];
654
- let manifest = null;
655
-
656
- let manifestPath = null;
657
- if (manifestFlag) {
658
- manifestPath = path.resolve(manifestFlag);
659
- } else if (modelDir) {
660
- manifestPath = path.resolve(modelDir, 'manifest.json');
661
- }
662
-
663
- if (convertConfigValue && !skipConvert) {
664
- stages.push({ stage: 'convert', status: 'starting' });
665
- try {
666
- const convertConfig = await readJsonObjectInput(convertConfigValue, '--convert-config');
667
- const request = normalizeToolingCommandRequest({
668
- command: 'convert',
669
- convertPayload: convertConfig,
670
- });
671
- const response = await runCommandOnSurface(request, 'node', {}, true);
672
- stages[stages.length - 1] = {
673
- stage: 'convert',
674
- status: 'succeeded',
675
- convertReport: response?.result?.report ?? null,
676
- };
677
- if (!manifestPath) {
678
- const inferredModelBaseId =
679
- convertConfig?.output?.modelBaseId
680
- || convertConfig?.converterConfig?.output?.modelBaseId
681
- || null;
682
- const inferredBaseDir =
683
- convertConfig?.output?.baseDir
684
- || convertConfig?.converterConfig?.output?.baseDir
685
- || 'models/local';
686
- if (inferredModelBaseId) {
687
- manifestPath = path.resolve(inferredBaseDir, inferredModelBaseId, 'manifest.json');
688
- }
689
- }
690
- } catch (error) {
691
- stages[stages.length - 1] = {
692
- stage: 'convert',
693
- status: 'failed',
694
- error: error?.message || String(error),
695
- };
696
- blockers.push({
697
- stage: 'convert',
698
- code: error?.code || 'convert_failed',
699
- message: error?.message || String(error),
700
- });
701
- }
702
- } else {
703
- stages.push({ stage: 'convert', status: skipConvert ? 'skipped' : 'not_requested' });
704
- }
705
-
706
- if (blockers.length === 0 && manifestPath) {
707
- stages.push({ stage: 'manifest_load', status: 'starting' });
708
- try {
709
- const raw = await fsMod.readFile(manifestPath, 'utf8');
710
- manifest = JSON.parse(raw);
711
- stages[stages.length - 1] = {
712
- stage: 'manifest_load',
713
- status: 'succeeded',
714
- manifestPath,
715
- modelId: manifest?.modelId ?? null,
716
- };
717
-
718
- stages.push({ stage: 'execution_contract_check', status: 'starting' });
719
- try {
720
- const facts = extractExecutionContractFacts(manifest);
721
- const validation = validateExecutionContractFacts(facts);
722
- stages[stages.length - 1] = {
723
- stage: 'execution_contract_check',
724
- status: 'succeeded',
725
- stepCount: facts.steps.length,
726
- checks: Array.isArray(validation?.checks) ? validation.checks.length : null,
727
- };
728
- } catch (error) {
729
- stages[stages.length - 1] = {
730
- stage: 'execution_contract_check',
731
- status: 'failed',
732
- error: error?.message || String(error),
733
- };
734
- blockers.push({
735
- stage: 'execution_contract_check',
736
- code: 'unsupported_op_or_contract_violation',
737
- message: error?.message || String(error),
738
- });
739
- }
740
- } catch (error) {
741
- stages[stages.length - 1] = {
742
- stage: 'manifest_load',
743
- status: 'failed',
744
- error: error?.message || String(error),
745
- };
746
- blockers.push({
747
- stage: 'manifest_load',
748
- code: 'manifest_unreadable',
749
- message: error?.message || String(error),
750
- });
751
- }
752
- } else if (blockers.length === 0) {
753
- stages.push({ stage: 'manifest_load', status: 'skipped' });
754
- blockers.push({
755
- stage: 'manifest_load',
756
- code: 'no_manifest_path',
757
- message:
758
- 'intake: no manifest path resolved. Provide --manifest, --model-dir, or a convert-config with output.modelBaseId.',
759
- });
760
- }
761
-
762
- const report = {
763
- schema: INTAKE_SCHEMA_ID,
764
- ok: blockers.length === 0,
765
- blockers,
766
- stages,
767
- createdAtUtc: new Date().toISOString(),
768
- };
769
-
770
- return { report, manifestPath, manifest };
771
- }
772
-
773
211
  async function runIntakeCommand(parsed, jsonOutput) {
774
212
  const fsMod = await import('node:fs/promises');
775
213
  const { report } = await performIntake({
@@ -849,87 +287,6 @@ async function runOnboardInspectCommand(parsed, jsonOutput) {
849
287
  if (!result.report.ok) process.exitCode = 1;
850
288
  }
851
289
 
852
- async function runBoundaryCommand(parsed, jsonOutput) {
853
- const {
854
- buildDeterministicTokenEvidenceFromReferenceTranscript,
855
- buildRuntimeBoundaryCapture,
856
- buildSourceBoundaryPackFromProviderCapture,
857
- compareBoundaryEvidence,
858
- } = await import('../tooling/boundary-evidence.js');
859
- const policyPath = fileURLToPath(
860
- new URL('../config/evidence/boundary-evidence-policy.json', import.meta.url)
861
- );
862
- const policy = await readJsonObjectFile(policyPath, 'boundary evidence policy');
863
- let result;
864
- if (parsed.action === 'capture') {
865
- const report = await readJsonObjectFile(
866
- path.resolve(parsed.flags.report),
867
- '--report'
868
- );
869
- result = buildRuntimeBoundaryCapture({
870
- report,
871
- policy,
872
- tolerancePolicyId: asStringOrNull(parsed.flags['tolerance-policy'])
873
- ?? 'doppler.boundary-tolerance/source-f16-v1',
874
- });
875
- } else if (parsed.action === 'source-pack') {
876
- const providerCapture = await readJsonObjectFile(
877
- path.resolve(parsed.flags['provider-capture']),
878
- '--provider-capture'
879
- );
880
- result = buildSourceBoundaryPackFromProviderCapture(providerCapture);
881
- } else if (parsed.action === 'token-evidence') {
882
- const transcript = await readJsonObjectFile(
883
- path.resolve(parsed.flags['reference-transcript']),
884
- '--reference-transcript'
885
- );
886
- result = buildDeterministicTokenEvidenceFromReferenceTranscript(transcript);
887
- } else {
888
- const [sourcePack, runtimeCapture, tokenEvidence] = await Promise.all([
889
- readJsonObjectFile(path.resolve(parsed.flags['source-pack']), '--source-pack'),
890
- readJsonObjectFile(path.resolve(parsed.flags['runtime-capture']), '--runtime-capture'),
891
- readJsonObjectFile(path.resolve(parsed.flags['token-evidence']), '--token-evidence'),
892
- ]);
893
- const sourceControlPath = asStringOrNull(parsed.flags['source-control']);
894
- const sourcePrecisionControlReceipt = sourceControlPath
895
- ? await readJsonObjectFile(path.resolve(sourceControlPath), '--source-control')
896
- : null;
897
- result = compareBoundaryEvidence({
898
- sourcePack,
899
- runtimeCapture,
900
- policy,
901
- artifactPrecision: asStringOrNull(parsed.flags['artifact-precision']) ?? 'source',
902
- sourcePrecisionControlReceipt,
903
- deterministicTokenEvidence: tokenEvidence,
904
- });
905
- }
906
- const outputPath = path.resolve(parsed.flags.out);
907
- await fs.mkdir(path.dirname(outputPath), { recursive: true });
908
- await fs.writeFile(outputPath, `${JSON.stringify(result, null, 2)}\n`, 'utf8');
909
- if (jsonOutput) {
910
- console.log(JSON.stringify({ ...result, outputPath: path.relative(process.cwd(), outputPath) }, null, 2));
911
- } else if (parsed.action === 'capture') {
912
- console.log(`[ok] captured ${result.boundaries.length} semantic boundaries`);
913
- } else if (parsed.action === 'source-pack') {
914
- console.log(`[ok] source pack contains ${result.boundaries.length} semantic boundaries`);
915
- } else if (parsed.action === 'token-evidence') {
916
- const status = result.exact ? 'ok' : 'fail';
917
- console.log(`[${status}] token evidence covers ${result.tokenCount} tokens`);
918
- } else {
919
- const status = result.promotionGate.passed ? 'ok' : 'fail';
920
- console.log(
921
- `[${status}] boundary comparison ` +
922
- `(first divergence: ${result.firstDivergence?.boundaryId ?? 'none'})`
923
- );
924
- }
925
- if (
926
- (parsed.action === 'compare' && !result.promotionGate.passed)
927
- || (parsed.action === 'token-evidence' && !result.exact)
928
- ) {
929
- process.exitCode = 1;
930
- }
931
- }
932
-
933
290
  async function runProfilesCommand(jsonOutput) {
934
291
  const result = await listRuntimeProfiles();
935
292
  if (jsonOutput) {
@@ -939,340 +296,6 @@ async function runProfilesCommand(jsonOutput) {
939
296
  console.log(formatRuntimeProfiles(result));
940
297
  }
941
298
 
942
- const BUNDLE_SUMMARY_SCHEMA_ID = 'doppler.bundle-summary/v1';
943
- const DEFAULT_BUNDLE_PROMPT = 'The color of the sky is';
944
- const DEFAULT_BUNDLE_MAX_TOKENS = 8;
945
-
946
- export async function checkCapturePrecondition(surface) {
947
- const skipCaptureHint = 'Alternatively, use --skip-capture with pre-existing --reference-report and --reference-transcript paths.';
948
- if (surface === 'node') {
949
- const { bootstrapNodeWebGPU } = await import('../tooling/node-webgpu.js');
950
- const { hasNodeWebGPUSupport } = await import('../tooling/node-command-runner.js');
951
- const bootstrap = await bootstrapNodeWebGPU();
952
- if (bootstrap.ok && hasNodeWebGPUSupport()) {
953
- return { ok: true, surface, provider: bootstrap.provider ?? null };
954
- }
955
- return {
956
- ok: false,
957
- surface,
958
- code: 'capture_precondition_node_webgpu_unavailable',
959
- provider: bootstrap.provider ?? null,
960
- detail: bootstrap.detail ?? null,
961
- message:
962
- 'bundle: --surface node requires a working Node WebGPU binding. '
963
- + `Bootstrap attempt failed: ${bootstrap.detail ?? 'no provider produced a usable adapter'}`
964
- + '. Install a Node WebGPU binding (for example `npm install webgpu`) '
965
- + 'or set DOPPLER_NODE_WEBGPU_MODULE to a custom specifier; '
966
- + 'alternatively use --surface browser after `npx playwright install chromium`. '
967
- + skipCaptureHint,
968
- };
969
- }
970
- if (surface === 'browser') {
971
- let playwright = null;
972
- try {
973
- playwright = await import('playwright');
974
- } catch (error) {
975
- return {
976
- ok: false,
977
- surface,
978
- code: 'capture_precondition_playwright_missing',
979
- detail: error?.message ?? null,
980
- message:
981
- 'bundle: --surface browser requires the `playwright` package. '
982
- + 'Run `npm install --save-dev playwright` then `npx playwright install chromium`. '
983
- + 'Alternatively use --surface node after installing a Node WebGPU binding (e.g. `npm install webgpu`). '
984
- + skipCaptureHint,
985
- };
986
- }
987
- let executablePath = null;
988
- try {
989
- executablePath = playwright.chromium?.executablePath?.() ?? null;
990
- } catch (error) {
991
- return {
992
- ok: false,
993
- surface,
994
- code: 'capture_precondition_playwright_chromium_missing',
995
- detail: error?.message ?? null,
996
- message:
997
- 'bundle: Playwright is installed but Chromium binaries are missing. '
998
- + 'Run `npx playwright install chromium` to download them. '
999
- + skipCaptureHint,
1000
- };
1001
- }
1002
- const fsSync = await import('node:fs');
1003
- if (!executablePath || !fsSync.existsSync(executablePath)) {
1004
- return {
1005
- ok: false,
1006
- surface,
1007
- code: 'capture_precondition_playwright_chromium_missing',
1008
- detail: executablePath ? `executable not found at ${executablePath}` : 'executablePath returned null',
1009
- message:
1010
- 'bundle: Playwright Chromium binaries are not installed. '
1011
- + 'Run `npx playwright install chromium` to download them. '
1012
- + skipCaptureHint,
1013
- };
1014
- }
1015
- return { ok: true, surface, executablePath };
1016
- }
1017
- return {
1018
- ok: false,
1019
- surface,
1020
- code: 'capture_precondition_unsupported_surface',
1021
- detail: null,
1022
- message: `bundle: --surface must be 'browser' or 'node', got '${surface}'.`,
1023
- };
1024
- }
1025
-
1026
- async function runBundleCommand(parsed, jsonOutput) {
1027
- const {
1028
- runReferenceCapture,
1029
- extractReferenceReport,
1030
- extractReferenceTranscriptSeed,
1031
- writeReferenceReport,
1032
- writeReferenceTranscript,
1033
- normalizeModelUrl,
1034
- } = await import('../tooling/reference-verify.js');
1035
- const { writeProgramBundle } = await import('../tooling/program-bundle.js');
1036
- const fsMod = await import('node:fs/promises');
1037
-
1038
- const outDir = asStringOrNull(parsed.flags.out);
1039
- if (!outDir) {
1040
- throw new Error('bundle: --out <dir> is required.');
1041
- }
1042
- const skipCapture = parsed.flags['skip-capture'] === true
1043
- || String(parsed.flags['skip-capture'] ?? '').toLowerCase() === 'true';
1044
- const resolvedOut = path.resolve(outDir);
1045
- await fsMod.mkdir(resolvedOut, { recursive: true });
1046
-
1047
- const repoRoot = path.resolve(fileURLToPath(new URL('../..', import.meta.url)));
1048
- const stages = [];
1049
- const blockers = [];
1050
- const artifactPaths = {};
1051
-
1052
- stages.push({ stage: 'intake', status: 'starting' });
1053
- const intakeResult = await performIntake({
1054
- convertConfigValue: asStringOrNull(parsed.flags['convert-config']),
1055
- manifestFlag: asStringOrNull(parsed.flags.manifest),
1056
- modelDir: asStringOrNull(parsed.flags['model-dir']),
1057
- skipConvert: parsed.flags['skip-convert'] === true
1058
- || String(parsed.flags['skip-convert'] ?? '').toLowerCase() === 'true',
1059
- });
1060
- const intakeReportPath = path.join(resolvedOut, 'intake-report.json');
1061
- await fsMod.writeFile(intakeReportPath, `${JSON.stringify(intakeResult.report, null, 2)}\n`, 'utf8');
1062
- artifactPaths.intakeReport = path.relative(process.cwd(), intakeReportPath);
1063
- if (!intakeResult.report.ok) {
1064
- stages[stages.length - 1] = { stage: 'intake', status: 'failed', blockers: intakeResult.report.blockers };
1065
- blockers.push(...intakeResult.report.blockers.map((b) => ({ ...b, stage: `intake:${b.stage}` })));
1066
- return emitBundleSummary({ ok: false, stages, blockers, artifactPaths, jsonOutput, resolvedOut });
1067
- }
1068
- stages[stages.length - 1] = {
1069
- stage: 'intake',
1070
- status: 'succeeded',
1071
- manifestPath: intakeResult.manifestPath,
1072
- modelId: intakeResult.manifest?.modelId ?? null,
1073
- };
1074
-
1075
- const manifestPath = intakeResult.manifestPath;
1076
- const manifest = intakeResult.manifest;
1077
- const modelDirResolved = asStringOrNull(parsed.flags['model-dir'])
1078
- ? path.resolve(asStringOrNull(parsed.flags['model-dir']))
1079
- : path.dirname(manifestPath);
1080
- const modelId = manifest?.modelId ?? null;
1081
- if (!modelId) {
1082
- blockers.push({ stage: 'bundle', code: 'missing_model_id', message: 'manifest.modelId is required for bundle composition.' });
1083
- return emitBundleSummary({ ok: false, stages, blockers, artifactPaths, jsonOutput, resolvedOut });
1084
- }
1085
-
1086
- const referenceReportPath = path.join(resolvedOut, 'reference-report.json');
1087
- const referenceTranscriptPath = path.join(resolvedOut, 'reference-transcript.json');
1088
-
1089
- if (!skipCapture) {
1090
- const surface = asStringOrNull(parsed.flags.surface) ?? 'browser';
1091
- stages.push({ stage: 'capture', status: 'starting', surface });
1092
- const precondition = await checkCapturePrecondition(surface);
1093
- if (!precondition.ok) {
1094
- stages[stages.length - 1] = {
1095
- stage: 'capture',
1096
- status: 'blocked',
1097
- surface,
1098
- precondition: {
1099
- code: precondition.code,
1100
- detail: precondition.detail ?? null,
1101
- provider: precondition.provider ?? null,
1102
- },
1103
- };
1104
- blockers.push({
1105
- stage: 'capture',
1106
- code: precondition.code,
1107
- message: precondition.message,
1108
- surface,
1109
- detail: precondition.detail ?? null,
1110
- provider: precondition.provider ?? null,
1111
- });
1112
- return emitBundleSummary({ ok: false, stages, blockers, artifactPaths, jsonOutput, resolvedOut });
1113
- }
1114
- try {
1115
- const modelUrl = normalizeModelUrl(asStringOrNull(parsed.flags['model-url']), modelDirResolved);
1116
- const maxTokensRaw = asStringOrNull(parsed.flags['max-tokens']);
1117
- const maxTokens = maxTokensRaw == null ? DEFAULT_BUNDLE_MAX_TOKENS : Number(maxTokensRaw);
1118
- if (!Number.isFinite(maxTokens) || maxTokens <= 0) {
1119
- throw new Error('--max-tokens must be a positive number.');
1120
- }
1121
- const response = await runReferenceCapture({
1122
- manifest,
1123
- modelId,
1124
- modelUrl,
1125
- surface,
1126
- prompt: asStringOrNull(parsed.flags.prompt) ?? DEFAULT_BUNDLE_PROMPT,
1127
- maxTokens,
1128
- runtimeConfig: asStringOrNull(parsed.flags['runtime-config']),
1129
- repoRoot,
1130
- });
1131
- const report = extractReferenceReport(response);
1132
- await writeReferenceReport(report, referenceReportPath);
1133
- artifactPaths.referenceReport = path.relative(process.cwd(), referenceReportPath);
1134
- const transcript = extractReferenceTranscriptSeed(report);
1135
- await writeReferenceTranscript(transcript, referenceTranscriptPath);
1136
- artifactPaths.referenceTranscript = path.relative(process.cwd(), referenceTranscriptPath);
1137
- stages[stages.length - 1] = {
1138
- stage: 'capture',
1139
- status: 'succeeded',
1140
- surface,
1141
- tokensGenerated: transcript.output?.tokensGenerated ?? null,
1142
- stopReason: transcript.output?.stopReason ?? null,
1143
- };
1144
- } catch (error) {
1145
- stages[stages.length - 1] = {
1146
- stage: 'capture',
1147
- status: 'failed',
1148
- error: error?.message || String(error),
1149
- };
1150
- blockers.push({ stage: 'capture', code: 'capture_failed', message: error?.message || String(error) });
1151
- return emitBundleSummary({ ok: false, stages, blockers, artifactPaths, jsonOutput, resolvedOut });
1152
- }
1153
- } else {
1154
- stages.push({ stage: 'capture', status: 'skipped' });
1155
- const preExistingReport = asStringOrNull(parsed.flags['reference-report']);
1156
- const preExistingTranscript = asStringOrNull(parsed.flags['reference-transcript']);
1157
- if (preExistingReport) artifactPaths.referenceReport = preExistingReport;
1158
- if (preExistingTranscript) artifactPaths.referenceTranscript = preExistingTranscript;
1159
- if (!preExistingReport || !preExistingTranscript) {
1160
- blockers.push({
1161
- stage: 'capture',
1162
- code: 'skip_capture_requires_artifacts',
1163
- message: 'bundle: --skip-capture requires existing --reference-report and --reference-transcript paths.',
1164
- });
1165
- return emitBundleSummary({ ok: false, stages, blockers, artifactPaths, jsonOutput, resolvedOut });
1166
- }
1167
- }
1168
-
1169
- stages.push({ stage: 'bundle', status: 'starting' });
1170
- try {
1171
- const bundleOutputPath = path.join(resolvedOut, 'program-bundle.json');
1172
- const bundleResult = await writeProgramBundle({
1173
- repoRoot,
1174
- manifestPath,
1175
- modelDir: modelDirResolved,
1176
- referenceReportPath: artifactPaths.referenceReport
1177
- ? path.resolve(artifactPaths.referenceReport)
1178
- : referenceReportPath,
1179
- conversionConfigPath: asStringOrNull(parsed.flags['conversion-config']),
1180
- outputPath: bundleOutputPath,
1181
- bundleId: asStringOrNull(parsed.flags['bundle-id']),
1182
- createdAtUtc: asStringOrNull(parsed.flags['created-at']),
1183
- });
1184
- artifactPaths.programBundle = path.relative(process.cwd(), bundleResult.outputPath);
1185
- stages[stages.length - 1] = {
1186
- stage: 'bundle',
1187
- status: 'succeeded',
1188
- bundleId: bundleResult.bundle.bundleId,
1189
- executionGraphHash: bundleResult.bundle.sources.executionGraph.hash,
1190
- artifactCount: bundleResult.bundle.artifacts.length,
1191
- wgslModuleCount: bundleResult.bundle.wgslModules.length,
1192
- };
1193
- } catch (error) {
1194
- stages[stages.length - 1] = {
1195
- stage: 'bundle',
1196
- status: 'failed',
1197
- error: error?.message || String(error),
1198
- };
1199
- blockers.push({ stage: 'bundle', code: 'bundle_export_failed', message: error?.message || String(error) });
1200
- return emitBundleSummary({ ok: false, stages, blockers, artifactPaths, jsonOutput, resolvedOut });
1201
- }
1202
-
1203
- stages.push({ stage: 'parity', status: 'starting' });
1204
- try {
1205
- const { checkProgramBundleParity } = await import('../tooling/program-bundle-parity.js');
1206
- const parityOutputPath = path.join(resolvedOut, 'program-bundle-parity.json');
1207
- const bundlePath = artifactPaths.programBundle
1208
- ? path.resolve(artifactPaths.programBundle)
1209
- : path.join(resolvedOut, 'program-bundle.json');
1210
- const parityReport = await checkProgramBundleParity({
1211
- bundlePath,
1212
- mode: 'contract',
1213
- repoRoot,
1214
- });
1215
- await fs.writeFile(parityOutputPath, `${JSON.stringify(parityReport, null, 2)}\n`, 'utf8');
1216
- artifactPaths.programBundleParity = path.relative(process.cwd(), parityOutputPath);
1217
- stages[stages.length - 1] = {
1218
- stage: 'parity',
1219
- status: 'succeeded',
1220
- mode: parityReport.mode,
1221
- ok: parityReport.ok,
1222
- parityHash: parityReport.parityHash,
1223
- providers: parityReport.providers.map((result) => ({
1224
- provider: result.provider,
1225
- status: result.status,
1226
- ok: result.ok,
1227
- })),
1228
- };
1229
- } catch (error) {
1230
- stages[stages.length - 1] = {
1231
- stage: 'parity',
1232
- status: 'failed',
1233
- error: error?.message || String(error),
1234
- };
1235
- blockers.push({ stage: 'parity', code: 'parity_check_failed', message: error?.message || String(error) });
1236
- return emitBundleSummary({ ok: false, stages, blockers, artifactPaths, jsonOutput, resolvedOut });
1237
- }
1238
-
1239
- return emitBundleSummary({ ok: true, stages, blockers, artifactPaths, jsonOutput, resolvedOut });
1240
- }
1241
-
1242
- async function emitBundleSummary({ ok, stages, blockers, artifactPaths, jsonOutput, resolvedOut }) {
1243
- const fsMod = await import('node:fs/promises');
1244
- const summary = {
1245
- schema: BUNDLE_SUMMARY_SCHEMA_ID,
1246
- ok,
1247
- stages,
1248
- blockers,
1249
- artifactPaths,
1250
- outputDir: path.relative(process.cwd(), resolvedOut),
1251
- createdAtUtc: new Date().toISOString(),
1252
- };
1253
- const summaryPath = path.join(resolvedOut, 'bundle-summary.json');
1254
- await fsMod.writeFile(summaryPath, `${JSON.stringify(summary, null, 2)}\n`, 'utf8');
1255
- summary.summaryPath = path.relative(process.cwd(), summaryPath);
1256
-
1257
- if (jsonOutput) {
1258
- console.log(JSON.stringify(summary, null, 2));
1259
- } else if (ok) {
1260
- console.log(`[ok] bundle composed under ${summary.outputDir} (${stages.length} stages)`);
1261
- for (const [key, value] of Object.entries(artifactPaths)) {
1262
- console.log(` - ${key}: ${value}`);
1263
- }
1264
- } else {
1265
- console.log(`[fail] bundle composition stopped with ${blockers.length} blocker(s):`);
1266
- for (const b of blockers) {
1267
- console.log(` - [${b.stage}] ${b.code}: ${b.message}`);
1268
- }
1269
- }
1270
- if (!ok) {
1271
- process.exitCode = 1;
1272
- }
1273
- return summary;
1274
- }
1275
-
1276
299
  function resolveCommandConfigFlag(parsed) {
1277
300
  const config = asStringOrNull(parsed.flags.config);
1278
301
  if (!config) {
@@ -1281,168 +304,6 @@ function resolveCommandConfigFlag(parsed) {
1281
304
  return config;
1282
305
  }
1283
306
 
1284
- function parseBooleanFlag(value, label) {
1285
- const normalizedInput = asStringOrNull(value);
1286
- if (normalizedInput === null) return null;
1287
- if (typeof value === 'boolean') return value;
1288
- if (typeof value === 'string') {
1289
- const normalized = normalizedInput.toLowerCase();
1290
- if (normalized === 'true') return true;
1291
- if (normalized === 'false') return false;
1292
- }
1293
- throw new Error(`${label} must be true or false`);
1294
- }
1295
-
1296
- function parseNumberFlag(value, label) {
1297
- const normalized = asStringOrNull(value);
1298
- if (normalized === null) return null;
1299
- const parsed = Number(normalized);
1300
- if (!Number.isFinite(parsed)) {
1301
- throw new Error(`${label} must be a number`);
1302
- }
1303
- return parsed;
1304
- }
1305
-
1306
- function parseBrowserArgs(value) {
1307
- if (value === undefined || value === null) return [];
1308
- return Array.isArray(value) ? value.map((item) => String(item)) : [String(value)];
1309
- }
1310
-
1311
- function parseSurface(value, command, policy = DEFAULT_CLI_POLICY) {
1312
- const normalizedInput = asStringOrNull(value);
1313
- const normalizedSurface = policy.defaults && policy.defaults.surface && policy.defaults.surface.default
1314
- ? policy.defaults.surface.default
1315
- : 'auto';
1316
- const allowedSurfaces = policy.defaults && Array.isArray(policy.defaults.surface?.allowed)
1317
- ? policy.defaults.surface.allowed
1318
- : ['auto', 'node', 'browser'];
1319
- const normalized = String(normalizedInput === null ? normalizedSurface : normalizedInput).trim().toLowerCase();
1320
- if (!allowedSurfaces.includes(normalized)) {
1321
- throw new Error('--surface must be one of auto, node, browser');
1322
- }
1323
- if ((command === 'convert' || command === 'refresh-integrity') && normalized === 'browser') {
1324
- throw new Error(`${command} is not supported on browser relay. Use --surface node or --surface auto.`);
1325
- }
1326
- if ((command === 'diagnose' || command === 'lora' || command === 'distill') && normalized === 'browser') {
1327
- throw new Error(`${command} is not supported on browser relay. Use --surface node or --surface auto.`);
1328
- }
1329
- return normalized;
1330
- }
1331
-
1332
- const CONFIG_ENVELOPE_KNOWN_KEYS = new Set([
1333
- 'request',
1334
- 'run',
1335
- 'runtimeProfile',
1336
- 'runtimeConfigUrl',
1337
- 'runtimeConfig',
1338
- ]);
1339
-
1340
- function buildRuntimeOverridesFromObject(source = {}, sourceLabel = '--config') {
1341
- const normalizedRuntimeProfile = asStringOrNull(source.runtimeProfile);
1342
- const normalizedRuntimeConfigUrl = asStringOrNull(source.runtimeConfigUrl) == null
1343
- ? null
1344
- : parseRuntimeConfigUrl(source.runtimeConfigUrl);
1345
-
1346
- const hasInlineRuntimeConfig = Object.prototype.hasOwnProperty.call(source, 'runtimeConfig');
1347
- let runtimeConfig = null;
1348
- if (hasInlineRuntimeConfig) {
1349
- if (!isPlainObject(source.runtimeConfig)) {
1350
- throw new Error(`${sourceLabel} runtimeConfig must be a JSON object when provided.`);
1351
- }
1352
- runtimeConfig = source.runtimeConfig;
1353
- }
1354
-
1355
- return {
1356
- runtimeProfile: normalizedRuntimeProfile,
1357
- runtimeConfigUrl: normalizedRuntimeConfigUrl,
1358
- runtimeConfig,
1359
- };
1360
- }
1361
-
1362
- function resolveConfigEnvelope(configPayload) {
1363
- if (!isPlainObject(configPayload)) {
1364
- throw new Error('--config must resolve to a JSON object.');
1365
- }
1366
- if (configPayload.request !== undefined && !isPlainObject(configPayload.request)) {
1367
- throw new Error('--config field "request" must be a JSON object when provided.');
1368
- }
1369
- if (configPayload.run !== undefined && !isPlainObject(configPayload.run)) {
1370
- throw new Error('--config field "run" must be a JSON object when provided.');
1371
- }
1372
- if (configPayload.request !== undefined) {
1373
- const topLevelUnknown = Object.keys(configPayload).filter(
1374
- (key) => !CONFIG_ENVELOPE_KNOWN_KEYS.has(key)
1375
- );
1376
- if (topLevelUnknown.length > 0) {
1377
- throw new Error(
1378
- `--config has unknown top-level keys for request envelope: ${topLevelUnknown.join(', ')}.`
1379
- );
1380
- }
1381
- }
1382
-
1383
- const hasRequestEnvelope = isPlainObject(configPayload.request);
1384
- const requestPayload = hasRequestEnvelope
1385
- ? { ...configPayload.request }
1386
- : { ...configPayload };
1387
- const topLevelRuntimeConfig = hasRequestEnvelope
1388
- ? buildRuntimeOverridesFromObject(configPayload, '--config')
1389
- : {
1390
- runtimeProfile: null,
1391
- runtimeConfigUrl: null,
1392
- runtimeConfig: null,
1393
- };
1394
- const requestRuntimeConfig = buildRuntimeOverridesFromObject(requestPayload, '--config.request');
1395
- if (hasRequestEnvelope) {
1396
- if (
1397
- topLevelRuntimeConfig.runtimeProfile != null
1398
- && requestRuntimeConfig.runtimeProfile != null
1399
- ) {
1400
- throw new Error(
1401
- 'Cannot set runtimeProfile in both --config payload top-level and --config.request.'
1402
- );
1403
- }
1404
- if (
1405
- topLevelRuntimeConfig.runtimeConfigUrl != null
1406
- && requestRuntimeConfig.runtimeConfigUrl != null
1407
- ) {
1408
- throw new Error(
1409
- 'Cannot set runtimeConfigUrl in both --config payload top-level and --config.request.'
1410
- );
1411
- }
1412
- if (
1413
- topLevelRuntimeConfig.runtimeConfig != null
1414
- && requestRuntimeConfig.runtimeConfig != null
1415
- ) {
1416
- throw new Error(
1417
- 'Cannot set runtimeConfig in both --config payload top-level and --config.request.'
1418
- );
1419
- }
1420
- }
1421
-
1422
- const requestInput = {
1423
- ...requestPayload,
1424
- runtimeProfile: (
1425
- topLevelRuntimeConfig.runtimeProfile !== null
1426
- ? topLevelRuntimeConfig.runtimeProfile
1427
- : requestRuntimeConfig.runtimeProfile
1428
- ),
1429
- runtimeConfigUrl: (
1430
- topLevelRuntimeConfig.runtimeConfigUrl !== null
1431
- ? topLevelRuntimeConfig.runtimeConfigUrl
1432
- : requestRuntimeConfig.runtimeConfigUrl
1433
- ),
1434
- runtimeConfig: (
1435
- topLevelRuntimeConfig.runtimeConfig !== null
1436
- ? topLevelRuntimeConfig.runtimeConfig
1437
- : requestRuntimeConfig.runtimeConfig
1438
- ),
1439
- };
1440
- return {
1441
- request: requestInput,
1442
- run: isPlainObject(configPayload.run) ? configPayload.run : {},
1443
- };
1444
- }
1445
-
1446
307
  function applyRuntimeFlagOverride(requestInput, runtimeOverride) {
1447
308
  if (!runtimeOverride) {
1448
309
  return;
@@ -1477,34 +338,37 @@ function resolveBenchRunOptions(runConfig, policy = DEFAULT_CLI_POLICY) {
1477
338
  };
1478
339
  }
1479
340
 
1480
- function normalizeModelUrl(value) {
1481
- if (typeof value !== 'string' || !value.trim()) {
1482
- return value;
1483
- }
1484
- const trimmed = value.trim();
1485
- if (/^[a-z][a-z0-9+.-]*:\/\//u.test(trimmed)) {
1486
- return trimmed;
1487
- }
1488
- if (trimmed.startsWith('/') || trimmed.startsWith('.')) {
1489
- return pathToFileURL(path.resolve(trimmed)).href.replace(/\/$/, '');
1490
- }
1491
- return trimmed;
1492
- }
1493
-
1494
- function resolveSurfaceForCommand(command, parsed, runConfig, policy = DEFAULT_CLI_POLICY) {
1495
- const fromCli = asStringOrNull(parsed.flags.surface);
1496
- const fromRun = asStringOrNull(runConfig?.surface);
1497
- return parseSurface(fromCli ?? fromRun ?? null, command, policy);
1498
- }
1499
-
1500
341
  export async function buildRequest(parsed, policy = DEFAULT_CLI_POLICY) {
1501
342
  const command = parsed.command;
1502
343
  if (!command || !TOOLING_COMMANDS.includes(command)) {
1503
344
  throw new Error(`Unsupported command "${command || ''}"`);
1504
345
  }
1505
346
 
1506
- const configValue = resolveCommandConfigFlag(parsed);
1507
- const configPayload = await readJsonObjectInput(configValue, '--config');
347
+ const configValue = asStringOrNull(parsed.flags.config);
348
+ const releaseFlags = command === 'release' && configValue === null
349
+ ? {
350
+ action: asStringOrNull(parsed.flags.action) ?? 'decide',
351
+ manifestPath: asStringOrNull(parsed.flags.manifest),
352
+ outputDirectory: asStringOrNull(parsed.flags.out),
353
+ repoRoot: asStringOrNull(parsed.flags['repo-root']),
354
+ forgeConfigPath: asStringOrNull(parsed.flags['forge-config']),
355
+ targetId: asStringOrNull(parsed.flags.target),
356
+ deviceIdentityPath: asStringOrNull(parsed.flags['device-identity']),
357
+ fleetReceiptPaths: (asStringOrNull(parsed.flags['fleet-receipts']) ?? '')
358
+ .split(',')
359
+ .map((entry) => entry.trim())
360
+ .filter(Boolean),
361
+ capsuleTrustedSignersPath: asStringOrNull(parsed.flags['capsule-trusted-signers']),
362
+ fleetTrustedSignersPath: asStringOrNull(parsed.flags['fleet-trusted-signers']),
363
+ signingPrivateKeyPath: asStringOrNull(parsed.flags['signing-private-key']),
364
+ signingPublicKeyPath: asStringOrNull(parsed.flags['signing-public-key']),
365
+ signingAuthority: asStringOrNull(parsed.flags['signing-authority']),
366
+ }
367
+ : null;
368
+ const configPayload = releaseFlags ?? await readJsonObjectInput(
369
+ resolveCommandConfigFlag(parsed),
370
+ '--config'
371
+ );
1508
372
  const envelope = resolveConfigEnvelope(configPayload);
1509
373
  const runtimeOverride = resolveRuntimeConfigFlags(parsed);
1510
374
 
@@ -1533,123 +397,6 @@ export async function buildRequest(parsed, policy = DEFAULT_CLI_POLICY) {
1533
397
  };
1534
398
  }
1535
399
 
1536
- function buildNodeRunOptions(jsonOutput) {
1537
- return {
1538
- onProgress(progress) {
1539
- if (jsonOutput) return;
1540
- if (!progress?.message) return;
1541
- if (Number.isFinite(progress.current) && Number.isFinite(progress.total)) {
1542
- console.error(`[progress] ${progress.current}/${progress.total} ${progress.message}`);
1543
- } else {
1544
- console.error(`[progress] ${progress.stage ?? 'run'} ${progress.message}`);
1545
- }
1546
- },
1547
- };
1548
- }
1549
-
1550
- function buildBrowserRunOptions(runConfig, jsonOutput, request = {}) {
1551
- const browser = isPlainObject(runConfig?.browser) ? runConfig.browser : {};
1552
-
1553
- const headed = parseBooleanFlag(browser.headed, 'run.browser.headed') === true;
1554
- const explicitHeadless = parseBooleanFlag(browser.headless, 'run.browser.headless');
1555
- if (headed && explicitHeadless !== null) {
1556
- throw new Error('run.browser.headed is mutually exclusive with run.browser.headless.');
1557
- }
1558
-
1559
- const options = {
1560
- channel: asStringOrNull(browser.channel),
1561
- executablePath: asStringOrNull(browser.executablePath),
1562
- runnerPath: asStringOrNull(browser.runnerPath),
1563
- staticRootDir: asStringOrNull(browser.staticRootDir),
1564
- rdrrRoot: asStringOrNull(browser.rdrrRoot),
1565
- baseUrl: asStringOrNull(browser.baseUrl),
1566
- browserArgs: parseBrowserArgs(browser.browserArgs),
1567
- headless: headed ? false : (explicitHeadless ?? true),
1568
- };
1569
- const rdrrRoot = resolveRdrrRoot(options);
1570
- options.staticMounts = [
1571
- {
1572
- urlPrefix: '/models/external',
1573
- rootDir: rdrrRoot,
1574
- },
1575
- ];
1576
-
1577
- const port = parseNumberFlag(browser.port, 'run.browser.port');
1578
- if (port !== null) {
1579
- options.port = port;
1580
- }
1581
-
1582
- const timeoutMs = parseNumberFlag(browser.timeoutMs, 'run.browser.timeoutMs');
1583
- if (timeoutMs !== null) {
1584
- options.timeoutMs = timeoutMs;
1585
- }
1586
-
1587
- const opfsCache = parseBooleanFlag(browser.opfsCache, 'run.browser.opfsCache');
1588
- if (opfsCache === false) {
1589
- options.opfsCache = false;
1590
- }
1591
-
1592
- const userDataDir = asStringOrNull(browser.userDataDir);
1593
- if (userDataDir) {
1594
- options.userDataDir = userDataDir;
1595
- }
1596
-
1597
- if (request.cacheMode === 'cold') {
1598
- options.wipeCacheBeforeLaunch = true;
1599
- }
1600
-
1601
- const streamConsole = parseBooleanFlag(browser.console, 'run.browser.console');
1602
- const shouldStreamConsole = streamConsole === true;
1603
- if (shouldStreamConsole && !jsonOutput) {
1604
- options.onConsole = ({ type, text }) => {
1605
- console.error(`[browser:${type}] ${text}`);
1606
- };
1607
- }
1608
-
1609
- return options;
1610
- }
1611
-
1612
- function isNodeWebGPUFallbackCandidate(error, fallbackPolicy = DEFAULT_CLI_POLICY.surfaceFallback) {
1613
- const message = error?.message || String(error || '');
1614
- const fallbackSignatures = Array.isArray(fallbackPolicy?.errorFragments) && fallbackPolicy.errorFragments.length > 0
1615
- ? fallbackPolicy.errorFragments
1616
- : [NODE_WEBGPU_INCOMPLETE_MESSAGE];
1617
- return fallbackSignatures.some((signature) => message.includes(signature));
1618
- }
1619
-
1620
- function isTrainingCommandFlow(request) {
1621
- if (!request || typeof request !== 'object') return false;
1622
- if (request.workload === 'training') return true;
1623
- if (request.command === 'lora' || request.command === 'distill') return true;
1624
- return request.command === 'bench' && (request.workload === 'training' || request.workloadType === 'training');
1625
- }
1626
-
1627
- function resolveErrorSurface(error, fallbackSurface = null) {
1628
- return (
1629
- asStringOrNull(fallbackSurface)
1630
- || asStringOrNull(error?.surface)
1631
- || asStringOrNull(error?.details?.surface)
1632
- || null
1633
- );
1634
- }
1635
-
1636
- export function createCliToolingErrorEnvelope(error, context = {}) {
1637
- return createToolingErrorEnvelope(error, {
1638
- surface: resolveErrorSurface(error, context.surface),
1639
- request: context.request ?? null,
1640
- });
1641
- }
1642
-
1643
- export function finalizeCliCommandResponse(response, request) {
1644
- if (!isPlainObject(response)) {
1645
- return response;
1646
- }
1647
- return {
1648
- ...response,
1649
- request,
1650
- };
1651
- }
1652
-
1653
400
  export async function withJsonStdoutIsolation(enabled, callback) {
1654
401
  if (!enabled) {
1655
402
  return callback();
@@ -1679,76 +426,6 @@ export async function withJsonStdoutIsolation(enabled, callback) {
1679
426
  }
1680
427
  }
1681
428
 
1682
- async function runCommandOnSurface(request, surface, runConfig, jsonOutput) {
1683
- if (surface === 'node') {
1684
- const nodeRequest = await resolveNodeModelUrl(request);
1685
- if (!jsonOutput) {
1686
- console.error('[surface] running on: node');
1687
- if (nodeRequest.modelUrl && nodeRequest.modelUrl !== request.modelUrl) {
1688
- console.error(`[surface] node resolved modelUrl=${nodeRequest.modelUrl}`);
1689
- }
1690
- }
1691
- const response = await runNodeCommand(nodeRequest, buildNodeRunOptions(jsonOutput));
1692
- return finalizeCliCommandResponse(response, request);
1693
- }
1694
-
1695
- const browserOptions = buildBrowserRunOptions(runConfig, jsonOutput, request);
1696
- const browserRequest = await resolveBrowserModelUrl(request, browserOptions);
1697
-
1698
- if (!jsonOutput) {
1699
- const mode = browserOptions.headless === false ? 'headed' : 'headless';
1700
- console.error(`[surface] running on: browser (${mode})`);
1701
- if (browserRequest.modelUrl && browserRequest.modelUrl !== request.modelUrl) {
1702
- console.error(`[surface] browser resolved modelUrl=${browserRequest.modelUrl}`);
1703
- }
1704
- }
1705
-
1706
- const response = await runBrowserCommandInNode(browserRequest, browserOptions);
1707
- return finalizeCliCommandResponse(response, request);
1708
- }
1709
-
1710
- async function runWithAutoSurface(request, runConfig, jsonOutput, policy = DEFAULT_CLI_POLICY) {
1711
- if (
1712
- request.command === 'convert'
1713
- || request.command === 'refresh-integrity'
1714
- || request.command === 'diagnose'
1715
- ) {
1716
- return runCommandOnSurface(request, 'node', runConfig, jsonOutput);
1717
- }
1718
- const fallbackPolicy = policy?.surfaceFallback || { enabled: false };
1719
-
1720
- try {
1721
- return await runCommandOnSurface(request, 'node', runConfig, jsonOutput);
1722
- } catch (error) {
1723
- if (!fallbackPolicy.enabled || !isNodeWebGPUFallbackCandidate(error, fallbackPolicy)) {
1724
- throw error;
1725
- }
1726
- if (isTrainingCommandFlow(request)) {
1727
- const downgradeError = new Error(
1728
- (request.command === 'lora' || request.command === 'distill')
1729
- ? 'Training command auto-surface downgrade is blocked. Re-run with --surface node after fixing Node WebGPU support.'
1730
- : 'Training command auto-surface downgrade is blocked. Re-run with --surface node after fixing Node WebGPU support, or explicitly choose --surface browser.'
1731
- );
1732
- downgradeError.code = 'training_surface_downgrade_blocked';
1733
- downgradeError.surface = 'node';
1734
- downgradeError.command = request.command;
1735
- downgradeError.workload = request.workload;
1736
- downgradeError.workloadType = request.workloadType || null;
1737
- downgradeError.fromSurface = 'node';
1738
- downgradeError.toSurface = fallbackPolicy.to || 'browser';
1739
- throw downgradeError;
1740
- }
1741
- if (fallbackPolicy.to !== 'browser') {
1742
- throw error;
1743
- }
1744
- if (!jsonOutput) {
1745
- console.error('[surface] node WebGPU unavailable, falling back to browser');
1746
- }
1747
- return runCommandOnSurface(request, 'browser', runConfig, jsonOutput);
1748
- }
1749
- }
1750
-
1751
-
1752
429
  async function loadManifest(manifestPath) {
1753
430
  const raw = await fs.readFile(path.resolve(manifestPath), 'utf-8');
1754
431
  const manifest = JSON.parse(raw);
@@ -1758,92 +435,6 @@ async function loadManifest(manifestPath) {
1758
435
  return manifest;
1759
436
  }
1760
437
 
1761
- function mergeRunConfig(base, ...overrides) {
1762
- const merged = isPlainObject(base) ? { ...base } : {};
1763
- for (const source of overrides) {
1764
- if (!isPlainObject(source)) {
1765
- continue;
1766
- }
1767
- for (const [key, value] of Object.entries(source)) {
1768
- if ((key === 'browser' || key === 'bench') && isPlainObject(value)) {
1769
- merged[key] = {
1770
- ...(isPlainObject(merged[key]) ? merged[key] : {}),
1771
- ...value,
1772
- };
1773
- continue;
1774
- }
1775
- merged[key] = value;
1776
- }
1777
- }
1778
- return merged;
1779
- }
1780
-
1781
- async function runManifestSweep(manifest, commandContext, jsonOutput, policy = DEFAULT_CLI_POLICY) {
1782
- const defaults = manifest.defaults || {};
1783
- const results = [];
1784
-
1785
- for (let i = 0; i < manifest.runs.length; i++) {
1786
- const run = manifest.runs[i];
1787
- const label = run.label || run.modelId || run.request?.modelId || `run-${i}`;
1788
- if (!jsonOutput) {
1789
- console.error(`[sweep] (${i + 1}/${manifest.runs.length}) ${label}`);
1790
- }
1791
-
1792
- const requestInput = {
1793
- ...commandContext.request,
1794
- ...(isPlainObject(defaults.request) ? defaults.request : {}),
1795
- ...(isPlainObject(run.request) ? run.request : {}),
1796
- command: commandContext.request.command,
1797
- };
1798
- const modelId = asStringOrNull(run.modelId) || asStringOrNull(defaults.modelId);
1799
- if (modelId) {
1800
- requestInput.modelId = modelId;
1801
- }
1802
- const modelUrl = asStringOrNull(run.modelUrl) || asStringOrNull(defaults.modelUrl);
1803
- if (modelUrl) {
1804
- requestInput.modelUrl = modelUrl;
1805
- }
1806
- const runtimeProfile = asStringOrNull(run.runtimeProfile)
1807
- || asStringOrNull(defaults.runtimeProfile);
1808
- if (runtimeProfile) {
1809
- requestInput.runtimeProfile = runtimeProfile;
1810
- }
1811
-
1812
- const mergedRunConfig = mergeRunConfig(commandContext.runConfig, defaults.run, run.run);
1813
- let request = null;
1814
- let surface = commandContext.surface;
1815
- try {
1816
- request = normalizeToolingCommandRequest(requestInput);
1817
- surface = commandContext.surfaceFromCli
1818
- ? commandContext.surface
1819
- : resolveSurfaceForCommand(
1820
- request.command,
1821
- { flags: { surface: null } },
1822
- mergedRunConfig,
1823
- policy
1824
- );
1825
- const response = surface === 'auto'
1826
- ? await runWithAutoSurface(request, mergedRunConfig, jsonOutput, policy)
1827
- : await runCommandOnSurface(request, surface, mergedRunConfig, jsonOutput);
1828
- results.push({ label, response, error: null });
1829
- } catch (error) {
1830
- results.push({
1831
- label,
1832
- response: null,
1833
- error: createCliToolingErrorEnvelope(error, {
1834
- surface: surface === 'auto' ? null : surface,
1835
- request,
1836
- }),
1837
- });
1838
- if (!jsonOutput) {
1839
- console.error(`[sweep] ${label} FAILED: ${error.message}`);
1840
- }
1841
- }
1842
- }
1843
-
1844
- return results;
1845
- }
1846
-
1847
438
  async function main() {
1848
439
  const argv = process.argv.slice(2);
1849
440
  const jsonOutputRequested = !argv.includes('--pretty');
@@ -1859,7 +450,7 @@ async function main() {
1859
450
  }
1860
451
 
1861
452
  const cliPolicy = await readJsonObjectFile(CLI_POLICY_PATH, '--cli-policy');
1862
- const parsed = parseArgs(argv);
453
+ const parsed = parseCliArguments(argv);
1863
454
  if (parsed.flags.help === true || parsed.flags.h === true) {
1864
455
  console.log(usage());
1865
456
  return;
@@ -1967,6 +558,8 @@ async function main() {
1967
558
 
1968
559
  return commandResponse;
1969
560
  });
561
+ const verificationFailed = isFailedVerificationResult(request, response?.result);
562
+ if (verificationFailed) process.exitCode = 1;
1970
563
 
1971
564
  if (jsonOutput) {
1972
565
  const output = response?.result?.report !== undefined
@@ -1976,7 +569,7 @@ async function main() {
1976
569
  return;
1977
570
  }
1978
571
 
1979
- console.log(`[ok] ${toSummary(response.result)}`);
572
+ console.log(`[${verificationFailed ? 'fail' : 'ok'}] ${toSummary(response.result)}`);
1980
573
  printConvertContractSummary(response.result);
1981
574
  printConvertReportSummary(response.result);
1982
575
  printMetricsSummary(response.result);