mlx-bun 0.2.0 → 0.4.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 (433) hide show
  1. package/README.md +71 -588
  2. package/docs/README.md +94 -0
  3. package/docs/{design → archive/investigations}/audio-input-plan.md +4 -4
  4. package/docs/{design → archive/investigations}/diffusion-gemma-port.md +3 -3
  5. package/docs/{design → archive/investigations}/faithful-l1-consolidation.md +4 -4
  6. package/docs/{design → archive/investigations}/minicpm5-decode-megakernel.md +11 -11
  7. package/docs/archive/investigations/openjarvis-fit.md +198 -0
  8. package/docs/{design → archive/investigations}/optimization_plan.md +1 -1
  9. package/docs/{design → archive/investigations}/pre-colibri-stabilization.md +5 -5
  10. package/docs/archive/investigations/qwen38-27b-campaign-log.md +1092 -0
  11. package/docs/{design → archive/investigations}/the-dreaming-handoff.md +2 -2
  12. package/docs/archive/planning/release-notes-v0.3.0.md +35 -0
  13. package/docs/design/batching.md +1841 -0
  14. package/docs/design/decode-speed-program.md +2346 -169
  15. package/docs/design/dreaming-nightly-pipeline.md +675 -282
  16. package/docs/design/generic-model-support.md +655 -334
  17. package/docs/design/kv-cache.md +824 -0
  18. package/docs/design/orpo-training.md +673 -1239
  19. package/docs/design/speculative-decoding.md +1990 -0
  20. package/docs/design/turboquant.md +2212 -0
  21. package/docs/design/unified-engine-frontier-plan.md +1833 -727
  22. package/docs/design/web-chat-redesign.md +666 -1083
  23. package/docs/planning/PRODUCT_ROADMAP.md +50 -1
  24. package/docs/planning/release-notes-v0.4.0.md +45 -0
  25. package/docs/planning/video-series.md +2 -2
  26. package/docs/reference/benchmarks.md +3613 -0
  27. package/docs/reference/cli.md +434 -160
  28. package/docs/reference/distribution.md +328 -182
  29. package/docs/reference/environment.md +398 -0
  30. package/docs/reference/glossary.md +39 -0
  31. package/docs/reference/library-api.md +566 -168
  32. package/docs/reference/memory.md +227 -64
  33. package/docs/reference/models.md +113 -6
  34. package/docs/reference/server-api.md +944 -429
  35. package/docs/reference/server-config.md +740 -338
  36. package/docs/reference/training.md +393 -254
  37. package/docs/reference/troubleshooting.md +158 -0
  38. package/package.json +9 -4
  39. package/src/audio/decode.ts +2 -2
  40. package/src/audio/features.ts +2 -2
  41. package/src/backends/mlx/assistant-target.ts +46 -0
  42. package/src/backends/mlx/autoregressive-draft-rows.ts +120 -0
  43. package/src/backends/mlx/autoregressive.ts +108 -0
  44. package/src/backends/mlx/batch-group.ts +1790 -0
  45. package/src/backends/mlx/cache-attachment.ts +67 -0
  46. package/src/backends/mlx/cache-layout.ts +31 -0
  47. package/src/backends/mlx/checkpoint-state.ts +53 -0
  48. package/src/backends/mlx/continuation-persistence.ts +106 -0
  49. package/src/backends/mlx/continuation-request.ts +43 -0
  50. package/src/backends/mlx/continuation.ts +77 -0
  51. package/src/backends/mlx/diffusion.ts +39 -0
  52. package/src/backends/mlx/draft-target.ts +32 -0
  53. package/src/backends/mlx/evaluation.ts +105 -0
  54. package/src/backends/mlx/fill-append.ts +45 -0
  55. package/src/backends/mlx/full-kv-row-append.ts +32 -0
  56. package/src/backends/mlx/full-kv-row-donor.ts +54 -0
  57. package/src/backends/mlx/full-transitioning-kv-rows.ts +65 -0
  58. package/src/backends/mlx/gateway-binding.ts +130 -0
  59. package/src/backends/mlx/graph.ts +38 -0
  60. package/src/backends/mlx/kv-codec.ts +9 -0
  61. package/src/backends/mlx/kv-maintenance.ts +133 -0
  62. package/src/backends/mlx/kv-tensor-rows.ts +212 -0
  63. package/src/backends/mlx/memory-client.ts +189 -0
  64. package/src/backends/mlx/methods.ts +90 -0
  65. package/src/backends/mlx/model-prompt.ts +164 -0
  66. package/src/backends/mlx/model-serving.ts +79 -0
  67. package/src/backends/mlx/prefill-cohort.ts +89 -0
  68. package/src/backends/mlx/prefill-rows.ts +200 -0
  69. package/src/backends/mlx/prefill.ts +33 -0
  70. package/src/backends/mlx/projected-context-rows.ts +72 -0
  71. package/src/backends/mlx/request-policy.ts +20 -0
  72. package/src/backends/mlx/request-state-policy.ts +41 -0
  73. package/src/backends/mlx/rollback.ts +89 -0
  74. package/src/backends/mlx/row-sampling.ts +49 -0
  75. package/src/backends/mlx/serial-executor.ts +242 -0
  76. package/src/backends/mlx/speculative-group.ts +359 -0
  77. package/src/backends/mlx/speculative-round.ts +161 -0
  78. package/src/backends/mlx/speculative.ts +114 -0
  79. package/src/backends/mlx/state-rows.ts +104 -0
  80. package/src/backends/mlx/state-views.ts +46 -0
  81. package/src/backends/mlx/target-layout-capability.ts +35 -0
  82. package/src/backends/mlx/text-engine.ts +73 -0
  83. package/src/backends/mlx/transitioning-kv-rows.ts +165 -0
  84. package/src/cli.ts +66 -58
  85. package/src/client.ts +66 -0
  86. package/src/config.ts +21 -4
  87. package/src/contracts/completion.ts +16 -0
  88. package/src/contracts/execution.ts +60 -0
  89. package/src/contracts/generation.ts +103 -0
  90. package/src/contracts/host.ts +7 -0
  91. package/src/contracts/jobs.ts +66 -0
  92. package/src/contracts/pi-provider.ts +30 -0
  93. package/src/contracts/pi.ts +259 -0
  94. package/src/contracts/prefix-cache.ts +23 -0
  95. package/src/contracts/resources.ts +25 -0
  96. package/src/contracts/sampling.ts +23 -0
  97. package/src/contracts/scheduling.ts +45 -0
  98. package/src/contracts/tsconfig.json +14 -0
  99. package/src/diffusion/diffusion-generate.ts +218 -153
  100. package/src/embed.ts +1 -1
  101. package/src/engine/admission.ts +59 -0
  102. package/src/engine/cancellation.ts +38 -0
  103. package/src/engine/engine.ts +56 -0
  104. package/src/engine/execution-coordinator.ts +70 -0
  105. package/src/engine/execution-plan.ts +53 -0
  106. package/src/engine/resources.ts +53 -0
  107. package/src/engine/scheduler.ts +72 -0
  108. package/src/engine/session.ts +247 -0
  109. package/src/eval/README.md +44 -1
  110. package/src/eval/kl.ts +236 -3
  111. package/src/eval/reference-logits.ts +207 -0
  112. package/src/eval/runner.ts +8 -96
  113. package/src/fill/echo-index.ts +188 -0
  114. package/src/fill/fill-session.ts +452 -0
  115. package/src/fill/proposal.ts +68 -0
  116. package/src/fill/schema-rows.ts +506 -0
  117. package/src/fill/tool-boundary.ts +103 -0
  118. package/src/fit.ts +30 -16
  119. package/src/generate.ts +709 -417
  120. package/src/grammar.ts +12 -7
  121. package/src/harness-pi.ts +14 -33
  122. package/src/hub-rest.ts +4 -4
  123. package/src/index.ts +7 -0
  124. package/src/inference/denoising.ts +17 -0
  125. package/src/inference/draft-acceptance.ts +41 -0
  126. package/src/inference/draft-output.ts +49 -0
  127. package/src/inference/graph.ts +33 -0
  128. package/src/inference/prefill.ts +39 -0
  129. package/src/inference/rollback.ts +7 -0
  130. package/src/jobs/db.ts +4 -0
  131. package/src/jobs/index.ts +2 -0
  132. package/src/jobs/job-entry.ts +12 -12
  133. package/src/jobs/runner.ts +98 -13
  134. package/src/jobs/task-client.ts +19 -0
  135. package/src/jobs/types.ts +2 -58
  136. package/src/kv-scheme.ts +70 -12
  137. package/src/kv-store.ts +177 -63
  138. package/src/lab/README.md +18 -0
  139. package/src/{assets → lab/curve}/curve-designer.html +2 -2
  140. package/src/{curve-sampler.ts → lab/curve/curve-sampler.ts} +2 -2
  141. package/src/{expert-trace.ts → lab/expert-trace/expert-trace.ts} +5 -5
  142. package/src/lab/paged-kv/paged-kv-rows.ts +83 -0
  143. package/src/{model → lab/paged-kv}/paged-kv.ts +32 -15
  144. package/src/library.ts +40 -0
  145. package/src/lora.ts +18 -0
  146. package/src/media-fetch.ts +1 -1
  147. package/src/memory/article.ts +1 -1
  148. package/src/memory/chunk.ts +1 -1
  149. package/src/memory/model.ts +30 -169
  150. package/src/memory/prompts.ts +1 -1
  151. package/src/memory/rest.ts +1 -1
  152. package/src/memory/schedule.ts +1 -1
  153. package/src/memory/stages.ts +4 -1
  154. package/src/memory/vault.ts +1 -3
  155. package/src/mlx/array.ts +11 -11
  156. package/src/mlx/compile.ts +12 -2
  157. package/src/mlx/ffi.ts +58 -11
  158. package/src/mlx/materialize.ts +23 -0
  159. package/src/mlx/metal-kernel.ts +10 -11
  160. package/src/mlx/ops.ts +33 -13
  161. package/src/mlx/quantized-rows.ts +36 -0
  162. package/src/mlx/token-bitmask.ts +52 -0
  163. package/src/mlx/turboquant-kv-decode.ts +82 -0
  164. package/src/mlx/turboquant-kv-inverse.ts +122 -0
  165. package/src/mlx/turboquant-ops.ts +33 -3
  166. package/src/mlx/turboquant-tables.ts +2 -2
  167. package/src/model/artifact-identity.ts +73 -0
  168. package/src/model/batched-kv.ts +235 -0
  169. package/src/model/batched-mask.ts +20 -6
  170. package/src/model/batched-quant.ts +9 -3
  171. package/src/model/batched-quantized-kv.ts +144 -0
  172. package/src/model/batched-rotating-quant.ts +78 -17
  173. package/src/model/batched-rotating-state.ts +76 -0
  174. package/src/model/batched-rotating.ts +65 -23
  175. package/src/model/batched-row-storage.ts +52 -0
  176. package/src/model/batched-ssm.ts +52 -0
  177. package/src/model/batched-turboquant-kv.ts +93 -0
  178. package/src/model/compiled-decode.ts +8 -2
  179. package/src/model/decoded-kv-donor.ts +12 -0
  180. package/src/model/delayed-quantized-kv.ts +72 -0
  181. package/src/model/delayed-rotating-quantized-kv.ts +93 -0
  182. package/src/model/delayed-turboquant-kv.ts +55 -0
  183. package/src/model/diffusion-gemma.ts +8 -8
  184. package/src/model/factory.ts +76 -33
  185. package/src/model/fingerprint.ts +1 -1
  186. package/src/model/flash-attention.ts +3 -3
  187. package/src/model/full-prefill-padding.ts +56 -0
  188. package/src/model/full-prefill-row.ts +105 -0
  189. package/src/model/gemma4-base.ts +179 -80
  190. package/src/model/gemma4.ts +40 -32
  191. package/src/model/generated/gemma4-12b.ts +6 -3
  192. package/src/model/generated/gemma4-26b.ts +6 -3
  193. package/src/model/generated/gemma4-e4b.ts +6 -3
  194. package/src/model/glm52-cache.ts +80 -4
  195. package/src/model/glm52-dsa.ts +13 -9
  196. package/src/model/glm52-memory.ts +1 -1
  197. package/src/model/glm52-mla.ts +12 -6
  198. package/src/model/glm52.ts +19 -40
  199. package/src/model/implementation.ts +69 -0
  200. package/src/model/kv-attention-view.ts +67 -0
  201. package/src/model/minicpm5.ts +17 -15
  202. package/src/model/profile.ts +12 -2
  203. package/src/model/qwen-append.ts +12 -0
  204. package/src/model/qwen-conv.ts +52 -0
  205. package/src/model/qwen3-delta-state.ts +74 -0
  206. package/src/model/qwen3-delta.ts +59 -36
  207. package/src/model/qwen3_5-checkpoint.ts +164 -0
  208. package/src/model/qwen3_5.ts +202 -78
  209. package/src/model/rotating-kv-donor.ts +35 -0
  210. package/src/model/rotating-kv-layout.ts +262 -0
  211. package/src/model/rotating-row-transaction.ts +35 -0
  212. package/src/model/speculative-rotating-kv.ts +101 -0
  213. package/src/model/ssm-prefill-padding.ts +39 -0
  214. package/src/model/support.ts +1 -1
  215. package/src/model/trellis-balanced-scatter.ts +51 -0
  216. package/src/model/trellis-linear.ts +672 -0
  217. package/src/model/trellis-shared-m.ts +151 -0
  218. package/src/model/trellis-shared-scatter.ts +144 -0
  219. package/src/model/trellis-splitk-prefill.ts +158 -0
  220. package/src/model/trellis-tiled-prefill.ts +136 -0
  221. package/src/model/trellis-vector-expand.ts +62 -0
  222. package/src/model/trellis-wide-prefill.ts +94 -0
  223. package/src/model/turboquant-codec.ts +83 -0
  224. package/src/model/universal/dense.ts +15 -14
  225. package/src/model/universal/modules.ts +8 -1
  226. package/src/native-pack.ts +6 -5
  227. package/src/pi-provider.ts +6 -64
  228. package/src/pi-web.ts +8 -315
  229. package/src/preflight.ts +31 -15
  230. package/src/prompt-cache.ts +110 -69
  231. package/src/quantize/allocator.ts +1 -1
  232. package/src/quantize/config-writer.ts +10 -3
  233. package/src/quantize/rotate.ts +4 -4
  234. package/src/quantize/trellis.ts +586 -0
  235. package/src/responses.ts +28 -1
  236. package/src/runtime-config.ts +18 -4
  237. package/src/sampler.ts +40 -29
  238. package/src/serve/batch-scheduler.ts +8 -1671
  239. package/src/serve/chat-request.ts +391 -0
  240. package/src/serve/chat-stage.ts +195 -0
  241. package/src/serve/checkpoint-identity.ts +64 -0
  242. package/src/serve/completion-executor.ts +15 -7
  243. package/src/serve/discovery-routes.ts +12 -13
  244. package/src/serve/generation-gateway.ts +183 -213
  245. package/src/serve/http.ts +159 -0
  246. package/src/serve/inference-request.ts +79 -0
  247. package/src/serve/isolate.ts +297 -105
  248. package/src/serve/lab-routes.ts +3 -0
  249. package/src/serve/lane-registry.ts +2 -1
  250. package/src/serve/model-admin-routes.ts +7 -5
  251. package/src/serve/model-binding.ts +43 -0
  252. package/src/serve/model-host.ts +511 -0
  253. package/src/serve/openai-wire.ts +103 -0
  254. package/src/serve/parent-application.ts +56 -0
  255. package/src/serve/pipeline.ts +33 -0
  256. package/src/serve/preparation.ts +33 -0
  257. package/src/serve/request-plan.ts +23 -18
  258. package/src/serve/request-prep.ts +344 -0
  259. package/src/serve/response-lease.ts +24 -0
  260. package/src/serve/responses-client.ts +69 -0
  261. package/src/serve/session-completion-engine.ts +110 -0
  262. package/src/serve/session-search.ts +1 -1
  263. package/src/serve/static-routes.ts +5 -5
  264. package/src/serve/text-completion-stage.ts +104 -0
  265. package/src/serve/token-streams.ts +519 -0
  266. package/src/server.ts +335 -2711
  267. package/src/spec/assistant-rows.ts +92 -0
  268. package/src/spec/assistant-source.ts +31 -55
  269. package/src/spec/cache-identity.ts +22 -0
  270. package/src/spec/deepspec-rows.ts +29 -0
  271. package/src/spec/deepspec-source.ts +16 -14
  272. package/src/spec/dflash-source.ts +36 -12
  273. package/src/spec/drafter.ts +153 -142
  274. package/src/spec/dspark/ab-stats.ts +3 -3
  275. package/src/spec/dspark/calibration.ts +2 -2
  276. package/src/spec/dspark/deepspec-module.ts +97 -122
  277. package/src/spec/dspark/generate-dflash.ts +2 -2
  278. package/src/spec/dspark/generate.ts +2 -2
  279. package/src/spec/dspark/loader.ts +1 -1
  280. package/src/spec/dspark/module-dflash.ts +129 -172
  281. package/src/spec/dspark/module.ts +3 -3
  282. package/src/spec/dspark/quantize-drafter.ts +1 -1
  283. package/src/spec/generate.ts +1 -1
  284. package/src/spec/glm52-mtp-graph.ts +29 -0
  285. package/src/spec/glm52-mtp-rows.ts +132 -0
  286. package/src/spec/glm52-mtp-source.ts +54 -137
  287. package/src/spec/glm52-mtp-state.ts +33 -0
  288. package/src/spec/ngram-source.ts +93 -21
  289. package/src/spec/projected-draft-rows.ts +73 -0
  290. package/src/spec/qwen-mtp-module.ts +171 -0
  291. package/src/spec/qwen-mtp-rows.ts +219 -0
  292. package/src/spec/qwen-mtp-source.ts +147 -195
  293. package/src/spec/qwen-mtp-state.ts +30 -0
  294. package/src/spec/serve-loop.ts +201 -201
  295. package/src/spec/source.ts +110 -13
  296. package/src/spec/two-model-rows.ts +61 -0
  297. package/src/spec/two-model.ts +44 -102
  298. package/src/ssd-cache.ts +99 -19
  299. package/src/ssd-durability.ts +36 -20
  300. package/src/tool-call.ts +51 -14
  301. package/src/train/flash-cce.ts +2 -2
  302. package/src/train/forward.ts +6 -0
  303. package/src/train/loss.ts +1 -1
  304. package/src/train/prefix-shared.ts +5 -1
  305. package/src/train/segmented.ts +5 -3
  306. package/src/train/trainer.ts +6 -6
  307. package/src/vision/prompt.ts +1 -1
  308. package/src/vision/qwen3vl-tower.ts +52 -10
  309. package/src/web/app.html +1 -1
  310. package/src/web/app.js +62 -60
  311. package/src/web/src/adapters-panel.ts +3 -3
  312. package/src/web/src/assistant.ts +2 -36
  313. package/src/web/src/chat.ts +4 -4
  314. package/src/web/src/composer.ts +4 -4
  315. package/src/web/src/hub.ts +1 -1
  316. package/src/web/src/markdown.ts +0 -0
  317. package/src/web/src/memory-panel.ts +1 -1
  318. package/src/web/src/model-picker.ts +1 -1
  319. package/src/web/src/palette.ts +1 -1
  320. package/src/web/src/protocol.ts +3 -39
  321. package/src/web/src/sessions.ts +1 -1
  322. package/src/web/src/ui-catalog.ts +4 -18
  323. package/src/web-assets.ts +47 -0
  324. package/src/weights.ts +55 -9
  325. package/docs/archive/investigations/curve-runs/bisector-route.json +0 -98
  326. package/docs/archive/investigations/curve-runs/bisector-trace.json +0 -1393
  327. package/docs/archive/investigations/curve-runs/curve-terrain.json +0 -1179
  328. package/docs/archive/investigations/curve-runs/curve-terrain.svg +0 -42
  329. package/docs/archive/investigations/hlg-ab.html +0 -34
  330. package/docs/archive/investigations/hlg-explorer.html +0 -238
  331. package/docs/archive/investigations/hlg-figs/cliff.svg +0 -1
  332. package/docs/archive/investigations/hlg-figs/cross.svg +0 -1
  333. package/docs/archive/investigations/hlg-figs/edges.svg +0 -1
  334. package/docs/archive/investigations/hlg-figs/k20-grids.svg +0 -1
  335. package/docs/archive/investigations/hlg-figs/k20-peaks.svg +0 -1
  336. package/docs/archive/investigations/hlg-figs/lw-curve.svg +0 -1
  337. package/docs/archive/investigations/hlg-figs/terrain.svg +0 -1
  338. package/docs/archive/investigations/hlg-report.html +0 -262
  339. package/docs/archive/investigations/hlg-runs/hlg-ab.json +0 -149
  340. package/docs/archive/investigations/hlg-runs/hlg-blind-prompts.md +0 -87
  341. package/docs/archive/investigations/hlg-runs/hlg-blind.json +0 -107
  342. package/docs/archive/investigations/hlg-runs/hlg-cliff.json +0 -197
  343. package/docs/archive/investigations/hlg-runs/hlg-cross.json +0 -505
  344. package/docs/archive/investigations/hlg-runs/hlg-edge.json +0 -388
  345. package/docs/archive/investigations/hlg-runs/hlg-eval1.json +0 -25
  346. package/docs/archive/investigations/hlg-runs/hlg-frontier.json +0 -86
  347. package/docs/archive/investigations/hlg-runs/hlg-grid.json +0 -242
  348. package/docs/archive/investigations/hlg-runs/hlg-grid2.json +0 -343
  349. package/docs/archive/investigations/hlg-runs/hlg-lw-coarse.json +0 -110
  350. package/docs/archive/investigations/hlg-runs/hlg-map.json +0 -383
  351. package/docs/archive/investigations/hlg-runs/run0-original.log +0 -159
  352. package/docs/archive/investigations/hlg-runs/runA-recommended.log +0 -131
  353. package/docs/archive/investigations/hlg-runs/runAA-cliff-cpm5.log +0 -26
  354. package/docs/archive/investigations/hlg-runs/runAB-grid2-e4b.log +0 -18
  355. package/docs/archive/investigations/hlg-runs/runAC-peak-e4b-partial.log +0 -25
  356. package/docs/archive/investigations/hlg-runs/runAD-ab-samples.log +0 -8
  357. package/docs/archive/investigations/hlg-runs/runAE-edge-e4b.log +0 -51
  358. package/docs/archive/investigations/hlg-runs/runAF-logit-calibration.log +0 -10
  359. package/docs/archive/investigations/hlg-runs/runAG-eval-config2.log +0 -16
  360. package/docs/archive/investigations/hlg-runs/runB-gain-variants.log +0 -192
  361. package/docs/archive/investigations/hlg-runs/runC-pivots.log +0 -162
  362. package/docs/archive/investigations/hlg-runs/runD-oetf.log +0 -132
  363. package/docs/archive/investigations/hlg-runs/runE-eotf.log +0 -162
  364. package/docs/archive/investigations/hlg-runs/runF-shaper-working.log +0 -86
  365. package/docs/archive/investigations/hlg-runs/runG-shaper-sweep.log +0 -101
  366. package/docs/archive/investigations/hlg-runs/runH-wsweep.log +0 -176
  367. package/docs/archive/investigations/hlg-runs/runI-asweep.log +0 -176
  368. package/docs/archive/investigations/hlg-runs/runJ-knobmap.log +0 -49
  369. package/docs/archive/investigations/hlg-runs/runK-frontier.log +0 -19
  370. package/docs/archive/investigations/hlg-runs/runL-widemap.log +0 -65
  371. package/docs/archive/investigations/hlg-runs/runM-frontier-emb.log +0 -15
  372. package/docs/archive/investigations/hlg-runs/runN-verify.log +0 -116
  373. package/docs/archive/investigations/hlg-runs/runO-frontier-seed5000.log +0 -15
  374. package/docs/archive/investigations/hlg-runs/runP-grid-AxSm.log +0 -15
  375. package/docs/archive/investigations/hlg-runs/runQ-grid-tgW.log +0 -15
  376. package/docs/archive/investigations/hlg-runs/runR-blind-transcript.log +0 -79
  377. package/docs/archive/investigations/hlg-runs/runS-cross-coherence.log +0 -33
  378. package/docs/archive/investigations/hlg-runs/runT-cross-cpm5.log +0 -33
  379. package/docs/archive/investigations/hlg-runs/runU-cross-12b.log +0 -33
  380. package/docs/archive/investigations/hlg-runs/runV-lw-e4b.log +0 -22
  381. package/docs/archive/investigations/hlg-runs/runW-lw-12b.log +0 -22
  382. package/docs/archive/investigations/hlg-runs/runX-lw-cpm5.log +0 -22
  383. package/docs/archive/investigations/hlg-runs/runY-cliff-e4b.log +0 -26
  384. package/docs/archive/investigations/hlg-runs/runZ-cliff-12b.log +0 -26
  385. package/docs/archive/mlx-bun-lab-report.html +0 -275
  386. package/docs/archive/wwdc-mlx-bun.html +0 -848
  387. package/docs/design/adapters-end-to-end.md +0 -205
  388. package/docs/design/batching-perf-path.md +0 -255
  389. package/docs/design/batching-v2-plan.md +0 -529
  390. package/docs/design/bucketing-stage.md +0 -197
  391. package/docs/design/compat-cli-surface-design.md +0 -230
  392. package/docs/design/docs-reorg-plan.md +0 -165
  393. package/docs/design/dspark-serving-program.md +0 -371
  394. package/docs/design/dspark-speculative-decoding.md +0 -318
  395. package/docs/design/grammar-spec-batching-integration.md +0 -301
  396. package/docs/design/memory-inference-path.md +0 -422
  397. package/docs/design/memory-synthesis.md +0 -287
  398. package/docs/design/memory-system.md +0 -237
  399. package/docs/design/mlx-lm-serving-execution-seam.md +0 -81
  400. package/docs/design/mlx-lm-tool-parity-plan.md +0 -545
  401. package/docs/design/omlx-adoption-map.md +0 -98
  402. package/docs/design/orpo-dynamic-lambda.md +0 -220
  403. package/docs/design/orpo-future-enhancements.md +0 -340
  404. package/docs/design/paged-kv-cache.md +0 -214
  405. package/docs/design/parallel-slots.md +0 -567
  406. package/docs/design/parity-tier-dag.md +0 -161
  407. package/docs/design/repo-cleanup-plan.md +0 -231
  408. package/docs/design/runtime-isolation.md +0 -263
  409. package/docs/design/segmented-backward-training.md +0 -543
  410. package/docs/design/spec-decode-larger-targets.md +0 -229
  411. package/docs/design/ssd-kv-cold-tier.md +0 -415
  412. package/docs/design/structured-output.md +0 -484
  413. package/docs/design/tauri-desktop-app.md +0 -127
  414. package/docs/design/the-dreaming-master-plan.md +0 -445
  415. package/docs/design/turboquant-kv.md +0 -235
  416. package/docs/design/turboquant-weights.md +0 -467
  417. package/docs/design/w4a16-compute-precision-spike.md +0 -232
  418. package/docs/design/web-chat-beat-matrix.md +0 -315
  419. package/docs/design/write-pipeline-entity.md +0 -468
  420. package/docs/planning/IDEAS.md +0 -69
  421. package/docs/reference/embedding.md +0 -197
  422. package/docs/reference/features-matrix.md +0 -101
  423. package/docs/reference/orpo-quickstart.md +0 -135
  424. package/src/flags.ts +0 -11
  425. /package/docs/{design → archive/investigations}/colibri-glm52-port.md +0 -0
  426. /package/docs/{planning → archive/planning}/chunk-task-roadmap.md +0 -0
  427. /package/docs/{planning → archive/planning}/curve-sampler-research-plan.md +0 -0
  428. /package/docs/{planning → archive/planning}/memory-docs-and-dag-plan.md +0 -0
  429. /package/docs/{planning → archive/planning}/pi-integration-review.md +0 -0
  430. /package/docs/{planning → archive/planning}/release-notes-v0.2.0.md +0 -0
  431. /package/src/{memory-plan.ts → admission-plan.ts} +0 -0
  432. /package/{docs/archive/investigations → src/serve/assets}/curve-terrain.html +0 -0
  433. /package/{docs/dag → src/serve/assets}/training-inference-map.html +0 -0
package/src/web/app.js CHANGED
@@ -1,7 +1,7 @@
1
1
  // GENERATED — do not edit by hand.
2
2
  // Source: src/web/src/*.ts (entrypoint main.ts). To regenerate:
3
3
  // bun scripts/build-web.ts
4
- // tests/web-build.test.ts enforces that this file matches the source.
4
+ // tests/using/web-build.test.ts enforces that this file matches the source.
5
5
  // src/web/src/api.ts
6
6
  async function api(path, opts) {
7
7
  const { body, ...rest } = opts || {};
@@ -994,14 +994,14 @@ function highlightIn(container) {
994
994
  return;
995
995
  const blocks = container.querySelectorAll("pre code");
996
996
  for (const block of blocks) {
997
- const el2 = block;
998
- if (el2.dataset.highlighted)
997
+ const el = block;
998
+ if (el.dataset.highlighted)
999
999
  continue;
1000
- const hasLang = /\blanguage-/.test(el2.className);
1001
- if (!hasLang && (el2.textContent || "").length > 20000)
1000
+ const hasLang = /\blanguage-/.test(el.className);
1001
+ if (!hasLang && (el.textContent || "").length > 20000)
1002
1002
  continue;
1003
1003
  try {
1004
- hljs.highlightElement(el2);
1004
+ hljs.highlightElement(el);
1005
1005
  } catch {}
1006
1006
  }
1007
1007
  }
@@ -2611,12 +2611,12 @@ async function renderListBody() {
2611
2611
  async function renderArticleLists(query) {
2612
2612
  const listEl = $("mem-list");
2613
2613
  if (!query) {
2614
- const d2 = await getJson("/api/memory/list").catch(() => ({ ok: false }));
2615
- if (!d2.ok) {
2614
+ const d = await getJson("/api/memory/list").catch(() => ({ ok: false }));
2615
+ if (!d.ok) {
2616
2616
  listEl.innerHTML = `<div class="mem-list-empty">Couldn't load the vault contents.</div>`;
2617
2617
  return;
2618
2618
  }
2619
- const articles = d2.articles || [], reference = d2.reference || [];
2619
+ const articles = d.articles || [], reference = d.reference || [];
2620
2620
  listEl.innerHTML = '<div class="mem-sec"><div class="mem-sec-title">Articles</div>' + (articles.length ? articles.map((a) => articleRowHtml(a)).join("") : '<div class="mem-list-empty">No articles yet — nightly synthesis writes here after a few conversations.</div>') + "</div>" + (reference.length ? '<div class="mem-sec"><div class="mem-sec-title">Reference</div>' + reference.map((r) => articleRowHtml(r, undefined, "\uD83D\uDCD8")).join("") + "</div>" : "");
2621
2621
  wireArticleRows(listEl);
2622
2622
  return;
@@ -2892,11 +2892,13 @@ function initMemoryPanel() {
2892
2892
  maybeShowConsentCard();
2893
2893
  }
2894
2894
 
2895
+ // src/contracts/pi.ts
2896
+ var APP_ROUTE_IDS = ["chat", "quantize", "finetune", "dataset", "status"];
2897
+
2895
2898
  // src/web/src/ui-catalog.ts
2896
- var ROUTE_IDS = ["chat", "quantize", "finetune", "dataset", "status"];
2897
2899
  var VIEW_IDS = ["memory-panel", "hub-panel", "settings", "adapters-panel"];
2898
2900
  function isRouteId(v) {
2899
- return ROUTE_IDS.includes(v);
2901
+ return APP_ROUTE_IDS.includes(v);
2900
2902
  }
2901
2903
  function isViewId(v) {
2902
2904
  return VIEW_IDS.includes(v);
@@ -2951,11 +2953,11 @@ var INTERACTIVE_SELECTOR = [
2951
2953
  "[data-spotlight]"
2952
2954
  ].join(", ");
2953
2955
  var MAX_ELEMENTS = 120;
2954
- function isAgentChrome(el2) {
2955
- return !!el2.closest("[data-ui-chrome]") || !!el2.closest("#toasts");
2956
+ function isAgentChrome(el) {
2957
+ return !!el.closest("[data-ui-chrome]") || !!el.closest("#toasts");
2956
2958
  }
2957
- function isHiddenSelf(el2) {
2958
- const html = el2;
2959
+ function isHiddenSelf(el) {
2960
+ const html = el;
2959
2961
  if (html.hidden)
2960
2962
  return true;
2961
2963
  const inline = html.style?.display;
@@ -2966,21 +2968,21 @@ function isHiddenSelf(el2) {
2966
2968
  return true;
2967
2969
  return false;
2968
2970
  }
2969
- function isVisible(el2) {
2970
- const html = el2;
2971
+ function isVisible(el) {
2972
+ const html = el;
2971
2973
  if (html.offsetParent === null) {
2972
2974
  const style = globalThis.getComputedStyle?.(html);
2973
2975
  if (style && style.position === "fixed")
2974
2976
  return true;
2975
2977
  }
2976
- for (let node = el2;node; node = node.parentElement) {
2978
+ for (let node = el;node; node = node.parentElement) {
2977
2979
  if (isHiddenSelf(node))
2978
2980
  return false;
2979
2981
  }
2980
2982
  return true;
2981
2983
  }
2982
- function elementLabel(el2) {
2983
- const html = el2;
2984
+ function elementLabel(el) {
2985
+ const html = el;
2984
2986
  const uiLabel = html.getAttribute("data-ui-label")?.trim();
2985
2987
  if (uiLabel)
2986
2988
  return uiLabel;
@@ -3015,13 +3017,13 @@ function captureUiSnapshot(route) {
3015
3017
  const elements = [];
3016
3018
  const seenRefs = new Set;
3017
3019
  let index = 0;
3018
- for (const el2 of nodes) {
3019
- if (isAgentChrome(el2) || !isVisible(el2))
3020
+ for (const el of nodes) {
3021
+ if (isAgentChrome(el) || !isVisible(el))
3020
3022
  continue;
3021
- const label = elementLabel(el2);
3023
+ const label = elementLabel(el);
3022
3024
  if (!label)
3023
3025
  continue;
3024
- const html = el2;
3026
+ const html = el;
3025
3027
  const spotlightId = html.getAttribute("data-spotlight")?.trim() || undefined;
3026
3028
  const existingRef = html.getAttribute("data-ui-ref");
3027
3029
  const ref = existingRef ?? `ui-${route.replace(/[^a-zA-Z0-9]/g, "_") || "root"}-${index}`;
@@ -3065,12 +3067,12 @@ function findByLabel(snapshot, label) {
3065
3067
  return;
3066
3068
  let best;
3067
3069
  let bestScore = 0;
3068
- for (const el2 of snapshot.elements) {
3069
- const hay = [el2.label, el2.spotlightId].filter(Boolean).join(" ");
3070
+ for (const el of snapshot.elements) {
3071
+ const hay = [el.label, el.spotlightId].filter(Boolean).join(" ");
3070
3072
  const score = matchScore(hay, label);
3071
3073
  if (score > bestScore) {
3072
3074
  bestScore = score;
3073
- best = el2;
3075
+ best = el;
3074
3076
  }
3075
3077
  }
3076
3078
  return bestScore >= 50 ? best : undefined;
@@ -3087,9 +3089,9 @@ function safeQuery(selector) {
3087
3089
  }
3088
3090
  function resolveSpotlightTarget(request, snapshot) {
3089
3091
  if (request.ref) {
3090
- const el2 = snapshot?.elements.find((e) => e.ref === request.ref);
3091
- if (el2)
3092
- return { selector: el2.selector, title: el2.label, message: request.message };
3092
+ const el = snapshot?.elements.find((e) => e.ref === request.ref);
3093
+ if (el)
3094
+ return { selector: el.selector, title: el.label, message: request.message };
3093
3095
  const selector = `[data-ui-ref="${attrEscape(request.ref)}"]`;
3094
3096
  if (safeQuery(selector)) {
3095
3097
  return { selector, title: request.label ?? request.ref, message: request.message };
@@ -3099,9 +3101,9 @@ function resolveSpotlightTarget(request, snapshot) {
3099
3101
  return { selector: request.selector, title: request.label ?? "Here", message: request.message };
3100
3102
  }
3101
3103
  if (request.label) {
3102
- const el2 = findByLabel(snapshot, request.label);
3103
- if (el2)
3104
- return { selector: el2.selector, title: el2.label, message: request.message };
3104
+ const el = findByLabel(snapshot, request.label);
3105
+ if (el)
3106
+ return { selector: el.selector, title: el.label, message: request.message };
3105
3107
  let bestEl = null;
3106
3108
  let bestScore = 0;
3107
3109
  for (const node of document.querySelectorAll("[data-ui-label]")) {
@@ -3142,15 +3144,15 @@ var AUTO_DISMISS_MS = 3000;
3142
3144
  var dismissTimer = null;
3143
3145
  var dismissListeners = null;
3144
3146
  function ensureOverlayEl() {
3145
- let el2 = document.getElementById("assistant-spotlight");
3146
- if (!el2) {
3147
- el2 = document.createElement("div");
3148
- el2.id = "assistant-spotlight";
3149
- el2.setAttribute("data-ui-chrome", "assistant");
3150
- el2.innerHTML = '<div class="asr-ring"></div><div class="asr-pop"><div class="asr-pop-text"></div></div>';
3151
- document.body.appendChild(el2);
3147
+ let el = document.getElementById("assistant-spotlight");
3148
+ if (!el) {
3149
+ el = document.createElement("div");
3150
+ el.id = "assistant-spotlight";
3151
+ el.setAttribute("data-ui-chrome", "assistant");
3152
+ el.innerHTML = '<div class="asr-ring"></div><div class="asr-pop"><div class="asr-pop-text"></div></div>';
3153
+ document.body.appendChild(el);
3152
3154
  }
3153
- return el2;
3155
+ return el;
3154
3156
  }
3155
3157
  function dismissSpotlight() {
3156
3158
  if (dismissTimer) {
@@ -3161,9 +3163,9 @@ function dismissSpotlight() {
3161
3163
  dismissListeners();
3162
3164
  dismissListeners = null;
3163
3165
  }
3164
- const el2 = document.getElementById("assistant-spotlight");
3165
- if (el2)
3166
- el2.classList.remove("show");
3166
+ const el = document.getElementById("assistant-spotlight");
3167
+ if (el)
3168
+ el.classList.remove("show");
3167
3169
  }
3168
3170
  function showSpotlight(resolved) {
3169
3171
  const target = safeQuery(resolved.selector);
@@ -3330,7 +3332,7 @@ function createChatController() {
3330
3332
  }
3331
3333
  return false;
3332
3334
  }
3333
- function currentView2() {
3335
+ function currentView() {
3334
3336
  if ($("mem-overlay")?.classList.contains("open"))
3335
3337
  return "memory-panel";
3336
3338
  if ($("hub-overlay")?.classList.contains("open"))
@@ -3343,16 +3345,16 @@ function createChatController() {
3343
3345
  const route = currentRoute();
3344
3346
  if (!isRouteId(route))
3345
3347
  return;
3346
- const ctx = buildAppContext(route, currentView2());
3348
+ const ctx = buildAppContext(route, currentView());
3347
3349
  lastSnapshot = ctx.snapshot;
3348
3350
  send({ type: "context", context: ctx });
3349
3351
  }
3350
3352
  function watchWizardSteps() {
3351
3353
  const mo = new MutationObserver(() => pushAppContext());
3352
3354
  for (const id of ["q-steps", "f-steps", "d-steps"]) {
3353
- const el2 = $(id);
3354
- if (el2)
3355
- mo.observe(el2, { childList: true, subtree: true });
3355
+ const el = $(id);
3356
+ if (el)
3357
+ mo.observe(el, { childList: true, subtree: true });
3356
3358
  }
3357
3359
  }
3358
3360
  function setChatStatus(s) {
@@ -3546,8 +3548,8 @@ function createChatController() {
3546
3548
  if (t)
3547
3549
  return t;
3548
3550
  if (isMemoryToolName(tool || "")) {
3549
- const handle2 = memoryToolChip(a.bubble, tool, args);
3550
- t = { kind: "memchip", wrap: handle2.wrap, handle: handle2, chunks: "" };
3551
+ const handle = memoryToolChip(a.bubble, tool, args);
3552
+ t = { kind: "memchip", wrap: handle.wrap, handle, chunks: "" };
3551
3553
  a.tools.set(callId, t);
3552
3554
  stick();
3553
3555
  return t;
@@ -3761,9 +3763,9 @@ function createChatController() {
3761
3763
  }
3762
3764
  for (const t of item.tools || []) {
3763
3765
  if (isMemoryToolName(t.name || "")) {
3764
- const handle2 = memoryToolChip(bubble, t.name, t.args);
3766
+ const handle = memoryToolChip(bubble, t.name, t.args);
3765
3767
  if (t.result)
3766
- handle2.setResult(t.result);
3768
+ handle.setResult(t.result);
3767
3769
  continue;
3768
3770
  }
3769
3771
  const wrap = el("div", "tool ok", bubble);
@@ -4079,9 +4081,9 @@ function createChatController() {
4079
4081
  watchWizardSteps();
4080
4082
  const overlayMo = new MutationObserver(() => pushAppContext());
4081
4083
  for (const id of ["mem-overlay", "hub-overlay", "adapters-overlay"]) {
4082
- const el2 = $(id);
4083
- if (el2)
4084
- overlayMo.observe(el2, { attributes: true, attributeFilter: ["class"] });
4084
+ const el = $(id);
4085
+ if (el)
4086
+ overlayMo.observe(el, { attributes: true, attributeFilter: ["class"] });
4085
4087
  }
4086
4088
  },
4087
4089
  enter() {
@@ -4891,7 +4893,7 @@ function createStatusController() {
4891
4893
  async function loadFit() {
4892
4894
  let f;
4893
4895
  try {
4894
- f = await fetch("/fit").then((r2) => r2.json());
4896
+ f = await fetch("/fit").then((r) => r.json());
4895
4897
  } catch {
4896
4898
  return;
4897
4899
  }
@@ -5317,9 +5319,9 @@ async function openHubPanel() {
5317
5319
  if (inFlightDownloads.size)
5318
5320
  ensureDownloadPolling();
5319
5321
  setTimeout(() => {
5320
- const el22 = $("hub-search-input");
5321
- if (el22)
5322
- el22.focus();
5322
+ const el2 = $("hub-search-input");
5323
+ if (el2)
5324
+ el2.focus();
5323
5325
  }, 30);
5324
5326
  }
5325
5327
  function setOfflineFooter(offline) {
@@ -9,9 +9,9 @@
9
9
  // docs/reference/server-api.md), with compatible-graying and a why-not
10
10
  // tooltip. Actions: mount, select, unselect, and stack two compatible
11
11
  // adapters as "a+b" — resolveSpec/injectAdapter already support composite
12
- // ids end to end (proved in tests/pi-web.test.ts's stacking test; the
12
+ // ids end to end (proved in tests/research/pi-web.test.ts's stacking test; the
13
13
  // shape-validated mount is proved against real weights in the
14
- // MLX_BUN_TEST_LORA=1-gated tests/lora.test.ts).
14
+ // MLX_BUN_TEST_LORA=1-gated tests/parity/lora.test.ts).
15
15
  //
16
16
  // Single source of SELECTION state, not a single fetch: composer.ts's quick
17
17
  // <select> and this table each hit /v1/adapters(+/available) independently
@@ -158,7 +158,7 @@ export function renderAdapterRow(
158
158
  }
159
159
 
160
160
  /** Full table body: a stack-mode toggle + composed-spec bar (when picks
161
- * exist), then one section of rows. Exported so tests/web-app.test.ts can
161
+ * exist), then one section of rows. Exported so tests/using/web-app.test.ts can
162
162
  * exercise esc() discipline without a live DOM/network. */
163
163
  export function renderAdaptersBodyHtml(state: AdaptersPanelState): string {
164
164
  if (!state.available.length) {
@@ -1,3 +1,5 @@
1
+ import type { UiSnapshotElement, UiSnapshot, WizardStep } from "../../contracts/pi";
2
+ export type { UiSnapshotElement, UiSnapshot, WizardStep } from "../../contracts/pi";
1
3
  // GENERATED-ADJACENT source module — part of the src/web/src/* split (plan
2
4
  // §6.6 "the app-aware assistant", §9 Phase 3, beat matrix Axis 12). Built
3
5
  // into src/web/app.js by scripts/build-web.ts.
@@ -26,42 +28,6 @@
26
28
 
27
29
  import { getSpotlightTarget, isViewId, ROUTE_LABELS, type RouteId, type ViewId } from "./ui-catalog";
28
30
 
29
- /* ────────────────────────────────────────────────────────────────────
30
- 1. SEE — the structured DOM snapshot
31
- ──────────────────────────────────────────────────────────────────── */
32
-
33
- export interface UiSnapshotElement {
34
- ref: string;
35
- tag: string;
36
- label: string;
37
- kind: "interactive" | "region";
38
- role?: string;
39
- selector: string;
40
- spotlightId?: string;
41
- }
42
-
43
- export interface UiSnapshot {
44
- route: string;
45
- capturedAt: string;
46
- elements: UiSnapshotElement[];
47
- }
48
-
49
- /** Process-state fields layered onto the snapshot (§6.6 "the snapshot
50
- * carries process state, not just elements") — wizard step for the
51
- * quantize/finetune/dataset wizards, when the current route has one.
52
- * Derived by reading the DOM the step indicator already renders
53
- * (markdown.ts's renderSteps into #q-steps/#f-steps/#d-steps + the
54
- * [data-qstep]/[data-fstep]/[data-dstep] visibility toggle quantize.ts/
55
- * finetune.ts/dataset.ts already do) rather than adding a callback hook to
56
- * those three controllers — zero behavior change to files outside this
57
- * wave's scope, and the DOM IS the source of truth those controllers
58
- * already write to. */
59
- export interface WizardStep {
60
- index: number;
61
- count: number;
62
- label: string;
63
- }
64
-
65
31
  const STEP_CONTAINER_BY_ROUTE: Partial<Record<RouteId, string>> = {
66
32
  quantize: "q-steps",
67
33
  finetune: "f-steps",
@@ -10,15 +10,15 @@
10
10
  // typed, checkable seams between these concerns).
11
11
  //
12
12
  // Typed WS contract (plan §9 Phase 2 item 2): ClientMessage/ServerMessage
13
- // and the history/session shapes are imported TYPE-ONLY from ../../pi-web
13
+ // and the history/session shapes are imported TYPE-ONLY from ../../contracts/pi
14
14
  // so this module (and the whole bundle) contains zero server code — the
15
15
  // bundler errors on bun:ffi if a value import ever sneaks in here, which is
16
16
  // the intended guard (see scripts/build-web.ts).
17
17
 
18
18
  import type {
19
19
  ClientMessage, HistoryItem, ReadyGenDefaults, ServerMessage, SessionListItem,
20
- } from "../../pi-web";
21
- import type { Lane } from "../../serve/lane-registry";
20
+ } from "../../contracts/pi";
21
+ import type { Lane } from "../../contracts/pi";
22
22
  import {
23
23
  $, el, toast, currentRoute, closeDrawer,
24
24
  storedCodingToolsPreference, renderCodingToolsState, renderToolApprovals,
@@ -44,7 +44,7 @@ import { isRouteId } from "./ui-catalog";
44
44
 
45
45
  /* ────────────────────────────────────────────────────────────────────
46
46
  Chat-with-files RAG v1 — Sources panel (plan §9 Phase 3, beat matrix
47
- Axis 5). Pure HTML builder so tests/web-app.test.ts can exercise the
47
+ Axis 5). Pure HTML builder so tests/using/web-app.test.ts can exercise the
48
48
  esc() discipline directly, same reasoning as renderAdapterOptionsHtml
49
49
  etc. in composer.ts.
50
50
  ──────────────────────────────────────────────────────────────────── */
@@ -10,8 +10,8 @@
10
10
  // the original single IIFE), but every WS send goes through a callback
11
11
  // passed in from chat.ts, which owns the actual WebSocket.
12
12
 
13
- import type { ReadyGenDefaults, SamplingOverrides } from "../../pi-web";
14
- import type { Lane } from "../../serve/lane-registry";
13
+ import type { ReadyGenDefaults, SamplingOverrides } from "../../contracts/pi";
14
+ import type { Lane } from "../../contracts/pi";
15
15
  import { api } from "./api";
16
16
  import type { ApiEnvelope } from "./protocol";
17
17
  import {
@@ -200,7 +200,7 @@ function escHtml(s: unknown): string {
200
200
 
201
201
  /** Pure: builds the <option> markup for the adapter <select> from the
202
202
  * /v1/adapters/available list. Split out from refreshAdapters() (which
203
- * does the fetch + DOM write) so tests/web-app.test.ts can exercise the
203
+ * does the fetch + DOM write) so tests/using/web-app.test.ts can exercise the
204
204
  * esc() discipline on this template directly without a DOM or network —
205
205
  * every interpolated field (id, rank, path, base_model) must be escaped,
206
206
  * since adapter ids/paths are user-controlled (on-disk directory names). */
@@ -719,7 +719,7 @@ export function renderLane(lane: Lane | undefined): void {
719
719
  already resolves, so the agent's memory tools pick it up naturally, same
720
720
  as in the vault's own prose). No vault -> files-only picker. Pure
721
721
  query-detection/insertion helpers below are unit-tested directly
722
- (tests/web-app.test.ts); DOM wiring (initMentionPicker) owns the
722
+ (tests/using/web-app.test.ts); DOM wiring (initMentionPicker) owns the
723
723
  picker's open/close/keyboard-nav state.
724
724
  ──────────────────────────────────────────────────────────────────── */
725
725
 
@@ -119,7 +119,7 @@ function localRowHtml(m: HubLocalRow): string {
119
119
  }
120
120
 
121
121
  /** Pure render, exported for esc()-discipline + empty-state tests
122
- * (tests/web-app.test.ts, mirroring renderModelPopBodyHtml's pattern). */
122
+ * (tests/using/web-app.test.ts, mirroring renderModelPopBodyHtml's pattern). */
123
123
  export function renderHubLocalHtml(models: HubLocalRow[]): string {
124
124
  if (!models.length) {
125
125
  return '<div class="hub-empty">No models downloaded yet — search Hugging Face below to get one.</div>';
Binary file
@@ -394,7 +394,7 @@ export async function refreshSidebarEntry(): Promise<void> {
394
394
  // by a literal list rather than an import: this module must stay
395
395
  // server-code-free (bundler-enforced, see chat.ts's header comment), so it
396
396
  // can't import a value from src/memory/tools.ts even though the identifiers
397
- // are the same. tests/web-app.test.ts cross-checks this list against the
397
+ // are the same. tests/using/web-app.test.ts cross-checks this list against the
398
398
  // real export so drift is caught at test time instead of silently.
399
399
  export const MEMORY_CHIP_TOOL_NAMES = [
400
400
  "memory_resolve", "memory_category", "memory_read", "memory_section",
@@ -85,7 +85,7 @@ function renderRow(m: LibraryRow): string {
85
85
  }
86
86
 
87
87
  /** Pure render of the popover body from a /library response. Exported for
88
- * tests/web-app.test.ts's esc() discipline check (repo ids are
88
+ * tests/using/web-app.test.ts's esc() discipline check (repo ids are
89
89
  * user-controlled HF strings — the same class of interpolation hazard
90
90
  * finding #15 flagged for the adapter dropdown). */
91
91
  export function renderModelPopBodyHtml(models: LibraryRow[]): string {
@@ -39,7 +39,7 @@ interface PaletteAction {
39
39
  }
40
40
 
41
41
  /** Pure: the static action list, independent of any live session data —
42
- * independently testable (tests/web-app.test.ts asserts labels/ids without
42
+ * independently testable (tests/using/web-app.test.ts asserts labels/ids without
43
43
  * needing a DOM). Session rows and message-search hits are appended
44
44
  * dynamically in refreshResults() below, not part of this list. */
45
45
  export function staticActions(): PaletteAction[] {
@@ -1,47 +1,11 @@
1
- // Shared frontend-only protocol shapes that don't already live on the
2
- // server side as exported types. The WS contract itself (ClientMessage /
3
- // ServerMessage / HistoryItem / SessionListItem / ReadyGenDefaults) is
4
- // imported type-only from ../../pi-web — see chat.ts. This file only holds
5
- // shapes with no server-side export to anchor to (e.g. the SSE job-stream
6
- // events, which live as a doc-comment in app.html today, not a type).
7
- //
8
- // Pointer comment for the server side: src/web/src/protocol.ts mirrors the
9
- // SSE line protocol documented at the jobStream() call site (api.ts) —
10
- // keep the two adjacent if the job event shape changes server-side
11
- // (scripts/ that emit `data:` lines for /api/jobs/:id/stream).
12
-
13
- /** One line of the /api/jobs/:id/stream SSE protocol (JSON per `data:` line). */
14
- export type JobEvent =
15
- | { type: "log"; line: string }
16
- | {
17
- type: "stage";
18
- stage: string;
19
- progress?: number;
20
- message?: string;
21
- output_dir?: string;
22
- adapter_path?: string;
23
- // Dataset-generation-specific row counts (present on the dataset
24
- // builder's job stream only; absent/ignored for quantize/finetune).
25
- n_train?: number;
26
- n_valid?: number;
27
- }
28
- | {
29
- type: "metric";
30
- kind: "train" | "val";
31
- step: number;
32
- loss: number;
33
- learning_rate?: number;
34
- tokens_per_sec?: number;
35
- progress?: number;
36
- message?: string;
37
- }
38
- | { type: "done"; n_train?: number; n_valid?: number }
39
- | { type: "failed"; error?: string };
1
+ import type { JobEvent } from "../../contracts/jobs";
2
+ export type { JobEvent } from "../../contracts/jobs";
40
3
 
41
4
  /** Handlers passed to jobStream(); each key is an optional callback for the
42
5
  * matching JobEvent variant, plus an `error` callback for the EventSource's
43
6
  * own onerror (transport failure, not a `failed` protocol event). */
44
7
  export interface JobStreamHandlers {
8
+ started?: (e: Extract<JobEvent, { type: "started" }>) => void;
45
9
  log?: (e: Extract<JobEvent, { type: "log" }>) => void;
46
10
  stage?: (e: Extract<JobEvent, { type: "stage" }>) => void;
47
11
  metric?: (e: Extract<JobEvent, { type: "metric" }>) => void;
@@ -20,7 +20,7 @@
20
20
  // wires each rendered `.sess` row's click to `onOpen` below — this just
21
21
  // finds and clicks the right row instead of duplicating that send()).
22
22
 
23
- import type { SessionListItem } from "../../pi-web";
23
+ import type { SessionListItem } from "../../contracts/pi";
24
24
  import { $, el, injectStyles } from "./shell";
25
25
  import { api } from "./api";
26
26
 
@@ -2,28 +2,14 @@
2
2
  // §7/§9 Phase 3, §6.6 "app-aware assistant"). Built into src/web/app.js by
3
3
  // scripts/build-web.ts.
4
4
  //
5
- // The frontend half of the app-aware assistant's route/spotlight catalog.
6
- // Mirrors PortfolioManager's ui-catalog.json pattern (client/src/lib/
7
- // ui-catalog.ts + server/src/agent/ui-catalog.ts, read together with
8
- // server/src/agent/portfolio-tools.ts as the reference implementation) but
9
- // inlined as a TS module (not a shared JSON file) since mlx-bun's server and
10
- // browser bundles are separate build outputs (scripts/build-web.ts vs bun's
11
- // own TS execution) with no shared-JSON-import convention today — pi-web.ts
12
- // mirrors ROUTE_IDS/SPOTLIGHT_TARGETS as plain string arrays for its own
13
- // server-side validation (navigate_app/spotlight_ui reject anything not in
14
- // that list BEFORE touching the browser) so route validity is checked at
15
- // both ends without a build-time shared asset.
16
- //
17
- // Keep this list's ROUTE_IDS in sync with shell.ts's ROUTES tuple (chat,
18
- // quantize, finetune, dataset, status) plus the Developer-only overlays that
19
- // aren't hash-routes (memory panel, hub panel, settings) — those are
20
- // `view`s, not `route`s (see UiContext.view below), reached by opening an
21
- // overlay rather than changing the URL hash.
5
+ // Shared route IDs keep browser navigation and server validation in agreement.
6
+ // Spotlight selectors and overlay IDs belong to the browser.
22
7
 
23
8
  /** A hash-routed page (shell.ts's Route union, minus "routes" — the DAG
24
9
  * diagram tab isn't a useful assistant destination and is itself
25
10
  * feature-detected/hidden when unavailable). */
26
- export const ROUTE_IDS = ["chat", "quantize", "finetune", "dataset", "status"] as const;
11
+ import { APP_ROUTE_IDS as ROUTE_IDS } from "../../contracts/pi";
12
+ export { ROUTE_IDS };
27
13
  export type RouteId = (typeof ROUTE_IDS)[number];
28
14
 
29
15
  /** A non-route overlay/panel the assistant can navigate to or spotlight
@@ -0,0 +1,47 @@
1
+ // Embedded web app — the unified SPA (chat / quantize / finetune /
2
+ // dataset / status). `with { type: "text" }` inlines the file in both
3
+ // `bun run` and the compiled single binary. bun-types types *.html
4
+ // imports as HTMLBundle (the html loader), but the text attribute makes
5
+ // the runtime value a string — hence the double cast.
6
+ import appHtml from "./web/app.html" with { type: "text" };
7
+ import curveDesignerHtml from "./lab/curve/curve-designer.html" with { type: "text" };
8
+ // Vendored, no-CDN static assets referenced by app.html (convention: any
9
+ // self-contained JS/CSS too big to inline gets `with { type: "text" }`
10
+ // imported here and served under /assets/<name>; see src/web/vendor/README
11
+ // for how hljs.js was built). Add new vendored assets the same way.
12
+ import hljsJs from "./web/vendor/hljs.js" with { type: "text" };
13
+ import hljsCss from "./web/vendor/hljs-theme.css" with { type: "text" };
14
+ // The frontend bundle (plan §7/§9 Phase 2 module split): GENERATED from
15
+ // src/web/src/*.ts by `bun scripts/build-web.ts` — see that file's header
16
+ // and tests/using/web-build.test.ts (the freshness gate). Same
17
+ // with { type: "text" } + /assets/<name> pattern as the vendored assets
18
+ // above; app.html's <script defer src="/assets/app.js"> loads it.
19
+ import appJs from "./web/app.js" with { type: "text" };
20
+ // PWA installability (plan §9 Phase 3, beat-matrix Axis 10): a manifest +
21
+ // a single inline SVG icon (no binary PNGs — the hygiene gate forbids
22
+ // tracked binary files; some browsers won't show an SVG app icon, which is
23
+ // an accepted tradeoff, see docs/reference/server-config.md) + a shell-
24
+ // only service worker. Same with { type: "text" } + /assets/<name>-shaped
25
+ // pattern as the vendored assets above; see src/web/sw.js's header for why
26
+ // it deliberately does NOT cache API/WS traffic.
27
+ import manifestWebmanifest from "./web/manifest.webmanifest" with { type: "text" };
28
+ import iconSvg from "./web/icon.svg" with { type: "text" };
29
+ import swJs from "./web/sw.js" with { type: "text" };
30
+ const APP_PAGE = appHtml as unknown as string;
31
+ const HLJS_JS = hljsJs as unknown as string;
32
+ const HLJS_CSS = hljsCss as unknown as string;
33
+ const APP_JS = appJs as unknown as string;
34
+ const MANIFEST_WEBMANIFEST = manifestWebmanifest as unknown as string;
35
+ const ICON_SVG = iconSvg as unknown as string;
36
+ const SW_JS = swJs as unknown as string;
37
+ const CURVE_PAGE = curveDesignerHtml as unknown as string;
38
+ export const STATIC_ROUTE_ASSETS = {
39
+ appPage: APP_PAGE,
40
+ appJs: APP_JS,
41
+ hljsJs: HLJS_JS,
42
+ hljsCss: HLJS_CSS,
43
+ manifest: MANIFEST_WEBMANIFEST,
44
+ iconSvg: ICON_SVG,
45
+ serviceWorker: SW_JS,
46
+ curvePage: CURVE_PAGE,
47
+ };