mlx-bun 0.0.8 → 0.0.10

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 (144) hide show
  1. package/README.md +112 -20
  2. package/docs/design/batching-perf-path.md +232 -0
  3. package/docs/design/batching-v2-plan.md +515 -0
  4. package/docs/design/bucketing-stage.md +196 -0
  5. package/docs/design/compat-cli-surface-design.md +11 -11
  6. package/docs/design/docs-reorg-plan.md +1 -1
  7. package/docs/design/dreaming-nightly-pipeline.md +291 -0
  8. package/docs/design/dspark-speculative-decoding.md +106 -0
  9. package/docs/design/generic-model-support.md +381 -0
  10. package/docs/design/memory-inference-path.md +422 -0
  11. package/docs/design/memory-synthesis.md +287 -0
  12. package/docs/design/minicpm5-decode-megakernel.md +484 -0
  13. package/docs/design/mlx-lm-tool-parity-plan.md +535 -0
  14. package/docs/design/omlx-adoption-map.md +90 -0
  15. package/docs/design/orpo-dynamic-lambda.md +41 -0
  16. package/docs/design/orpo-training.md +35 -5
  17. package/docs/design/parallel-slots.md +12 -1
  18. package/docs/design/parity-tier-dag.md +13 -5
  19. package/docs/design/segmented-backward-training.md +15 -0
  20. package/docs/design/spec-decode-larger-targets.md +229 -0
  21. package/docs/design/ssd-kv-cold-tier.md +158 -0
  22. package/docs/design/tauri-desktop-app.md +2 -2
  23. package/docs/design/the-dreaming-handoff.md +141 -0
  24. package/docs/design/the-dreaming-master-plan.md +446 -0
  25. package/docs/design/write-pipeline-entity.md +468 -0
  26. package/docs/investigations/curve-bisector-routing.md +1 -1
  27. package/docs/investigations/decode-roofline-lookagain.md +348 -0
  28. package/docs/investigations/dspark-handoff.md +58 -0
  29. package/docs/investigations/kernel-perf-review-2026-07.md +171 -0
  30. package/docs/planning/PRODUCT_ROADMAP.md +2 -2
  31. package/docs/planning/curve-sampler-research-plan.md +331 -0
  32. package/docs/planning/memory-docs-and-dag-plan.md +185 -0
  33. package/docs/planning/pi-integration-review.md +178 -0
  34. package/docs/planning/release-notes-v0.0.10.md +57 -0
  35. package/docs/planning/release-notes-v0.0.9.md +122 -0
  36. package/docs/planning/web-ui-pass-plan.md +213 -0
  37. package/docs/planning/website-readme-pass-plan.md +224 -0
  38. package/docs/reference/cli.md +255 -0
  39. package/docs/reference/embedding.md +7 -2
  40. package/docs/reference/library-api.md +22 -3
  41. package/docs/reference/memory.md +5 -5
  42. package/docs/reference/models.md +137 -0
  43. package/docs/reference/orpo-quickstart.md +6 -0
  44. package/docs/reference/server-api.md +187 -9
  45. package/docs/reference/server-config.md +43 -9
  46. package/docs/reference/training.md +31 -12
  47. package/package.json +1 -1
  48. package/src/anthropic.ts +22 -0
  49. package/src/assets/curve-designer.html +1 -1
  50. package/src/chat-template.ts +25 -7
  51. package/src/cli.ts +1077 -90
  52. package/src/config.ts +4 -1
  53. package/src/download.ts +99 -8
  54. package/src/embed.ts +77 -0
  55. package/src/eval/perplexity.ts +164 -0
  56. package/src/eval/runner.ts +15 -6
  57. package/src/eval/tasks/bfcl.ts +1 -1
  58. package/src/generate.ts +149 -18
  59. package/src/harness-pi.ts +43 -17
  60. package/src/index.ts +2 -0
  61. package/src/kv-store.ts +240 -98
  62. package/src/lora.ts +2 -2
  63. package/src/memory/article.ts +558 -0
  64. package/src/memory/chunk-validation.ts +150 -0
  65. package/src/memory/chunk.ts +305 -12
  66. package/src/memory/cluster.ts +344 -17
  67. package/src/memory/coverage.ts +134 -0
  68. package/src/memory/crosslink.ts +0 -0
  69. package/src/memory/db.ts +184 -45
  70. package/src/memory/entity.ts +203 -0
  71. package/src/memory/gate.ts +187 -0
  72. package/src/memory/history.ts +152 -0
  73. package/src/memory/ingest.ts +324 -11
  74. package/src/memory/model.ts +321 -0
  75. package/src/memory/normalize.ts +671 -0
  76. package/src/memory/parse.ts +22 -0
  77. package/src/memory/pipeline.ts +242 -30
  78. package/src/memory/prompts.ts +42 -0
  79. package/src/memory/query.ts +334 -0
  80. package/src/memory/reconcile.ts +734 -0
  81. package/src/memory/redirect.ts +108 -0
  82. package/src/memory/reindex.ts +325 -0
  83. package/src/memory/resolve.ts +307 -0
  84. package/src/memory/route.ts +272 -0
  85. package/src/memory/schedule.ts +6 -4
  86. package/src/memory/stages.ts +774 -0
  87. package/src/memory/synthesize.ts +1629 -20
  88. package/src/memory/tools.ts +446 -96
  89. package/src/memory/vault.ts +462 -35
  90. package/src/memory/wikify.ts +1057 -16
  91. package/src/mlx/array.ts +21 -0
  92. package/src/mlx/ffi.ts +3 -0
  93. package/src/mlx/ops.ts +72 -0
  94. package/src/model/compiled-decode.ts +43 -8
  95. package/src/model/factory.ts +29 -8
  96. package/src/model/flash-attention.ts +4 -2
  97. package/src/model/fused-decode-kernel.ts +14 -7
  98. package/src/model/fused-mlp-kernel.ts +169 -0
  99. package/src/model/fused-swiglu-kernel.ts +240 -0
  100. package/src/model/gemma4-base.ts +96 -7
  101. package/src/model/gemma4.ts +33 -2
  102. package/src/model/minicpm5.ts +106 -8
  103. package/src/model/qwen3-delta.ts +48 -1
  104. package/src/model/qwen3.ts +276 -0
  105. package/src/model/qwen3_5.ts +11 -2
  106. package/src/model/steel-linear-kernel.ts +96 -0
  107. package/src/model/support.ts +38 -8
  108. package/src/model/universal/archs.ts +332 -0
  109. package/src/model/universal/dense.ts +576 -0
  110. package/src/model/universal/modules.ts +163 -0
  111. package/src/model/universal/rope.ts +366 -0
  112. package/src/pi-provider.ts +1 -1
  113. package/src/pi-terminal.ts +29 -8
  114. package/src/pi-web.ts +19 -2
  115. package/src/prompt-cache.ts +55 -9
  116. package/src/quantize/config-writer.ts +1 -1
  117. package/src/registry.ts +219 -8
  118. package/src/responses.ts +23 -0
  119. package/src/sampler.ts +220 -9
  120. package/src/serve/batch-scheduler.ts +307 -83
  121. package/src/serve/generation-gateway.ts +156 -29
  122. package/src/server.ts +746 -73
  123. package/src/spec/drafter.ts +81 -49
  124. package/src/spec/dspark/data-dflash.ts +156 -0
  125. package/src/spec/dspark/data.ts +201 -0
  126. package/src/spec/dspark/generate-dflash.ts +193 -0
  127. package/src/spec/dspark/generate.ts +290 -0
  128. package/src/spec/dspark/loss.ts +213 -0
  129. package/src/spec/dspark/module-dflash.ts +361 -0
  130. package/src/spec/dspark/module.ts +540 -0
  131. package/src/spec/dspark/sample.ts +112 -0
  132. package/src/spec/generate.ts +40 -19
  133. package/src/ssd-cache.ts +213 -0
  134. package/src/status-page.html +1 -1
  135. package/src/tokenizer.ts +7 -0
  136. package/src/train/flash-cce.ts +81 -23
  137. package/src/train/fuse.ts +243 -0
  138. package/src/train/index.ts +3 -0
  139. package/src/train/job.ts +8 -0
  140. package/src/train/loss.ts +341 -40
  141. package/src/train/prefix-shared.ts +62 -11
  142. package/src/train/segmented.ts +215 -55
  143. package/src/train/trainer.ts +112 -38
  144. package/src/web/skills/memory/SKILL.md +40 -17
@@ -0,0 +1,224 @@
1
+ # Website + README pass — audit findings and fix plan (2026-07-01)
2
+
3
+ Scope: the `website/` Astro subproject (mlx-bun.dev), `README.md`, and the
4
+ `docs/reference/` sources that feed both. Audited read-only against current
5
+ main **and against the published `v0.0.8` tag** (what installers actually
6
+ get). Every claim below was verified in source (`git show v0.0.8:…` for
7
+ release attribution), not doc-vs-doc.
8
+
9
+ ## 0. The one decision that gates everything
10
+
11
+ **The site and README already document v0.0.9 behavior.** The published
12
+ v0.0.8 binary serves on **port 8090, bound to all interfaces**; main (and
13
+ every doc: README, quickstart, http-api, the synced server-config page)
14
+ says **8080 + loopback**. A fresh `brew install` user today follows the
15
+ quickstart and every curl example fails. The five auto-synced reference
16
+ pages likewise already describe `--max-tokens`, logprobs, `--sft-scope`,
17
+ and `/v1/completions` — all post-tag.
18
+
19
+ Two coherent options:
20
+
21
+ - **(A) Recommended: cut v0.0.9, then deploy the site.** All docs become
22
+ true simultaneously; nothing below needs version annotations. The
23
+ release-notes draft already exists (`docs/planning/release-notes-v0.0.9.md`).
24
+ - **(B)** If v0.0.9 is not imminent: hold site deploys, and treat every
25
+ item marked *v0.0.9* below as blocked. (Reverting docs to 8090 is churn
26
+ for nothing — don't.)
27
+
28
+ The rest of this plan assumes (A); each item is still marked
29
+ **[safe-now]** (true for v0.0.8 users too) or **[v0.0.9]** (true only
30
+ after release).
31
+
32
+ ## 1. Mechanism: how site content is produced
33
+
34
+ - **Generated (cannot drift):** 5 pages built from `docs/reference/*.md`
35
+ by `website/scripts/sync-reference-docs.mjs`, run on every
36
+ dev/build via the `astro:config:setup` hook in `astro.config.mjs`:
37
+ `server-api.md`, `server-config.md`, `training.md` → `reference/`;
38
+ `library-api.md`, `embedding.md` → `guides/`. Generated copies are
39
+ gitignored. This works well — verified accurate against main.
40
+ - **Hand-written (tracked, CAN silently drift, and did):** `index.mdx`,
41
+ `getting-started/{introduction,installation,quickstart,models}`,
42
+ `guides/{http-api,troubleshooting}`, `reference/cli.md`, `about/*` (4).
43
+ The three that drifted are exactly the ones duplicating CLI/model facts:
44
+ `reference/cli.md`, `getting-started/models.md`, `guides/http-api.md`.
45
+ - **Not synced at all:** `docs/reference/{memory,models,orpo-quickstart,distribution}.md`.
46
+ The first three are user-facing and site-worthy; distribution.md is
47
+ maintainer-ops, keep repo-only.
48
+
49
+ ### Mechanism bugs
50
+
51
+ 1. **Deploy trigger misses the source docs.** `.github/workflows/deploy-site.yml`
52
+ triggers only on `paths: website/**`. Edits to `docs/reference/*.md`
53
+ alone never redeploy — the "cannot drift" pages drift *in production*
54
+ until the next unrelated website commit. **Fix [safe-now]:** add
55
+ `docs/reference/**` to the paths filter.
56
+ 2. **"Edit page" links on the 5 generated pages 404.** Starlight's global
57
+ `editLink.baseUrl` points at `website/src/content/docs/…`, but those
58
+ files are gitignored, so GitHub 404s. **Fix [safe-now]:** have the sync
59
+ script inject per-page `editUrl:` frontmatter pointing at the real
60
+ source (`docs/reference/<file>.md`).
61
+ 3. **Local dev/build needs Node ≥ 22.12** (Astro 6). The machine default
62
+ is nvm Node 18 → `bun run build` fails locally; CI uses Node 22 and is
63
+ fine. **Fix [safe-now]:** add `"engines": { "node": ">=22.12.0" }` to
64
+ `website/package.json` and a one-liner in `website/README.md`
65
+ (`nvm use 22` or `bunx --bun astro build`).
66
+
67
+ ### Build health (measured)
68
+
69
+ - Build: **green** — 18 pages, pagefind index, sitemap (built with Node 22 semantics via `bunx --bun astro build`).
70
+ - Internal links: **all 17 unique internal hrefs resolve** to built routes.
71
+ - GitHub `blob/main` links (22 unique): **all targets exist** in the repo.
72
+ - Assets: `public/{CNAME,install.sh,favicon.svg}` present.
73
+ - The only broken-link class is the editLink bug above.
74
+
75
+ ## 2. WRONG (fix first — actively misleads)
76
+
77
+ | # | Where | Claim | Truth | Gate |
78
+ |---|---|---|---|---|
79
+ | W1 | Site quickstart/installation/index-hero, README (lines 96/108/208/235/286), synced server-config | server on `localhost:8080`, loopback | **v0.0.8 = port 8090, all interfaces**; 8080+loopback is post-tag (8ee691d) | **[v0.0.9]** — resolves itself under option (A) |
80
+ | W2 | `website/…/reference/cli.md:29` | `--no-kv-quant` / `--kv-bits <n>` | Never existed. Real flag: `--kv-quant config\|off\|4\|8` | [safe-now] |
81
+ | W3 | `website/…/reference/cli.md:30` | `--adapter id=dir` | Syntax is `--adapter <dir>` | [safe-now] |
82
+ | W4 | `README.md:304` | "Published to npm as `mlx-bun` (current: 0.0.4)" | 0.0.8 | [safe-now] |
83
+ | W5 | `getting-started/models.md:19` + `introduction.md:33` | "Currently MiniCPM5 plus the Gemma-4 quants… Qwen 3.x is next on the roadmap" | **Qwen3.5-4B is supported in v0.0.8** (support.ts at tag) — and `about/comparison.md:39` already says so; the site contradicts itself | [safe-now] |
84
+ | W6 | `README.md:39`, `installation.mdx:22` | pin example `MLX_BUN_VERSION=v0.0.4` | Use `v0.0.8` (or drop the pinned example) | [safe-now] |
85
+
86
+ ## 3. STALE (true once, now behind)
87
+
88
+ - S1 `getting-started/models.md` table: add the Qwen3.5-4B row (copy the
89
+ README's row: 3.1 GB, 8 GB, thinking + tool calling). [safe-now]
90
+ - S2 `guides/http-api.md:85-89` endpoint list: `/stats`, `/fit`,
91
+ `/library`, `/downloads` existed at v0.0.8 and are undocumented
92
+ [safe-now]; `/v1/completions`, `/v1/embeddings`, `/health`,
93
+ logprobs/top_logprobs are **[v0.0.9]**.
94
+ - S3 `about/benchmarks.md:6`: "mlx-optiq 0.2.1" — oracle venv now runs
95
+ 0.2.4; also "clean-machine re-measure is pending" (line 35) — refresh or
96
+ date-stamp when the re-measure lands. [safe-now, low priority]
97
+ - S4 README "Status" section: reflect the v0.0.9 wave (CI gate now exists,
98
+ Tier-0 generics, mlx-lm tool parity) — **[v0.0.9]**.
99
+
100
+ ## 4. MISSING (goals with no page)
101
+
102
+ - M1 **Memory system — goal 5 — has ZERO website presence.** The
103
+ README sells it; the site never mentions it. `docs/reference/memory.md`
104
+ is accurate and site-worthy. **Fix:** add to the sync MAP →
105
+ `guides/memory.md` ("Personal memory") + a home-page feature card + a
106
+ sidebar entry. Read path (init/status/open/search/agent tools) shipped
107
+ in v0.0.8 [safe-now]; `memory synthesize` as a real pipeline is
108
+ **[v0.0.9]** (f7dad8f is post-tag) — under option (A) publish the whole
109
+ page at once.
110
+ - M2 **CLI reference covers 7 of ~21 verbs.** Missing and in v0.0.8:
111
+ `gen/generate`, `bench`, `train`, `train-watch`, `memory`, `pi`, `help`
112
+ [safe-now]. Missing and post-tag: `embed`, `gc`, `fuse`, `convert`,
113
+ `upload`, `perplexity`, `setup` alias **[v0.0.9]**. **Structural fix:**
114
+ stop hand-writing it — create `docs/reference/cli.md` as the tracked
115
+ source (or generate from `printHelp`) and add it to the sync MAP, so the
116
+ CLI page can never drift again.
117
+ - M3 **Model management** (`get`/`scan`/`ls`/`gc`, cache layout, gc safety
118
+ rails): `docs/reference/models.md` is accurate + site-worthy → sync to
119
+ `guides/model-management.md`. gc verb is **[v0.0.9]**; the rest safe-now.
120
+ - M4 **Drop-in mlx-lm replacement — goal 1 — has no page.** It's v0.0.9's
121
+ headline (mlx_lm.server endpoint/flag/sampler/logprobs parity, same
122
+ port/host defaults, `fuse`/`convert`/`perplexity`/`upload` tool parity).
123
+ **Fix [v0.0.9]:** new `guides/drop-in-mlx-lm.md` — "stop
124
+ `mlx_lm.server`, start `mlx-bun serve`, same curl works" with the
125
+ parity table and the deliberately-not-ported list.
126
+ - M5 **Tier-0 generic models** (UniversalDense, 11 archs, L1-gated,
127
+ bit-exact goldens for llama/qwen2/gemma2): reframes the scope story from
128
+ "a few models" to "runs what mlx-lm runs; *optimizes* the targets".
129
+ Rewrite `models.md` around the targeted-vs-generic tier split (`ls`
130
+ already labels it). **[v0.0.9]**.
131
+ - M6 **The lab — goal 6 — is invisible.** ORPO training (orpo-quickstart
132
+ is accurate + site-worthy), DSpark speculative decoding, the curve
133
+ designer (`/curves` UI ships in v0.0.8!), diffusion-gemma, the
134
+ train-watch dashboard. **Fix:** new `about/lab.md` (or top-level "The
135
+ lab") presenting these as the experimental playground with GitHub links
136
+ into docs/design + docs/investigations; sync orpo-quickstart →
137
+ `guides/fine-tuning-quickstart.md`. Mostly [safe-now] (frame as
138
+ experimental); `--sft-scope` mention is [v0.0.9].
139
+ - M7 **README link coverage:** memory paragraphs (137–145) should link
140
+ `docs/reference/memory.md` + `docs/design/memory-synthesis.md`; the
141
+ model table (155) should link `docs/reference/models.md`; nothing links
142
+ to **mlx-bun.dev** anywhere except install.sh — add a "Docs:
143
+ https://mlx-bun.dev" line at the top. [safe-now]
144
+
145
+ ## 5. Structure / information architecture
146
+
147
+ ### Website — proposed sidebar (new items marked)
148
+
149
+ ```
150
+ Getting started
151
+ Introduction · Installation · Quickstart · Choosing a model (rewrite: tiers, M5)
152
+ Guides
153
+ The HTTP API
154
+ Drop-in for mlx-lm ← NEW (M4, v0.0.9)
155
+ Personal memory ← NEW (M1, synced from docs/reference/memory.md)
156
+ Model management ← NEW (M3, synced from docs/reference/models.md)
157
+ Using the library · Embedding in a Mac app
158
+ Fine-tuning quickstart ← NEW (M6, synced from orpo-quickstart.md)
159
+ Troubleshooting
160
+ Reference
161
+ CLI (→ synced, M2) · Server API · Server configuration · Training & fine-tuning
162
+ About
163
+ Why mlx-bun · How it compares · Benchmarks · Correctness
164
+ The lab ← NEW (M6)
165
+ ```
166
+
167
+ ### Six-goals legibility scorecard (today → after)
168
+
169
+ | Goal | Today | After |
170
+ |---|---|---|
171
+ | 1 Drop-in mlx-lm replacement | implicit ("OpenAI-compatible") | M4 page + home card names mlx_lm.server explicitly |
172
+ | 2 JS library / Mac apps | ✅ library + embedding guides | unchanged (already good) |
173
+ | 3 Memory/quality/speed | ✅ benchmarks + correctness + fit | S3 refresh |
174
+ | 4 One command <60s, 4 paths | ✅ home hero + installation | W1 port fix is the blocker |
175
+ | 5 Memory showcase | ❌ absent | M1 guide + home feature card |
176
+ | 6 Playground | ❌ absent | M6 lab page + home card |
177
+
178
+ - **Home page:** the 6 feature cards cover goals 1–4 twice and 5–6 never.
179
+ Swap/add two cards: "Personal memory" (goal 5) and "The lab" (goal 6);
180
+ make the Protocols card say "drop-in for mlx_lm.server" (goal 1).
181
+ - **Reading order** is otherwise sound: hero → install → quickstart →
182
+ guides works; introduction.md and why.md duplicate two paragraphs
183
+ verbatim — acceptable, but keep them in sync or have intro link out.
184
+
185
+ ### README
186
+
187
+ - The 60-second promise is buried at line 92 inside the *fourth* install
188
+ path. Move it into the opening: "one command, chatting in under a
189
+ minute" as the first bold claim, install one-liner immediately after —
190
+ matching the website hero (they should tell the same story; today the
191
+ README leads with the product-bet essay).
192
+ - Add the six goals as an explicit bulleted frame (the "What mlx-bun is"
193
+ section at line 120 is close — reorder it to map 1:1 and give the memory
194
+ system and the lab their own H2s with doc links).
195
+ - Add the mlx-bun.dev docs link at the top (M7).
196
+ - Keep README ⊆ website: README states, website explains — every README
197
+ section should end with a link to the corresponding site page once M1–M6
198
+ land.
199
+
200
+ ## 6. Execution order
201
+
202
+ 1. **[safe-now, no release needed]** W2–W6, S1–S3, M7, mechanism fixes
203
+ (deploy paths filter, editUrl injection, engines field). Note: do NOT
204
+ deploy the site after these until step 2, because the synced pages
205
+ already carry v0.0.9 content (W1).
206
+ 2. **Josh: cut v0.0.9** (release-notes draft exists).
207
+ 3. **[with v0.0.9]** W1 becomes true; land M1–M6 + S4 + README
208
+ restructure; deploy once. New synced pages = add 4 entries to the
209
+ sync-script MAP (cli, memory, models→model-management,
210
+ orpo-quickstart→fine-tuning-quickstart) + sidebar entries + link
211
+ rewrites for the new routes.
212
+
213
+ ## Appendix: release-attribution ground truth (verified via `git show v0.0.8:`)
214
+
215
+ - **In v0.0.8:** verbs get/scan/ls/fit/serve/gen/bench/evals/pi/harness/
216
+ train/train-watch/memory(read-path); Qwen3.5 + DiffusionGemma support;
217
+ `/curves`, `/dag`, `/stats`, `/fit`, `/library`, `/downloads`, chat UI;
218
+ port **8090**, host **all interfaces**.
219
+ - **Post-tag (v0.0.9):** port 8080 + loopback, `--temp`/`--max-tokens`,
220
+ `/v1/completions`, `/health`, `/v1/embeddings`, logprobs/top_logprobs,
221
+ sampler parity (min_p/XTC/logit_bias/penalties), verbs
222
+ embed/gc/fuse/convert/perplexity/upload, `--sft-scope`, Tier-0
223
+ UniversalDense (11 archs, L1 goldens), memory synthesize (real
224
+ pipeline), registry dedupe, CI gate, `--l2` tier-contract fix.
@@ -0,0 +1,255 @@
1
+ # CLI reference
2
+
3
+ Every mlx-bun verb. Commands are shown as `mlx-bun <verb>`; from a clone the
4
+ identical command is `bun src/cli.ts <verb>`. `mlx-bun help <verb>` (or
5
+ `mlx-bun <verb> --help`) prints the full flag list for any command.
6
+
7
+ Model arguments are **substring queries** against the registry (`e4b`, `26B`,
8
+ `12B-it`); a query matching more than one model errors out and lists the
9
+ candidates — just make it more specific.
10
+
11
+ Bare `mlx-bun` with no verb runs `serve` — the appliance path: first run
12
+ downloads a starter model, serves it, and opens the chat UI.
13
+
14
+ > Verbs marked **(v0.0.9)** ship in v0.0.9; everything else is in v0.0.8.
15
+
16
+ ## Serving & chat
17
+
18
+ ### `serve` — run the server
19
+
20
+ Start the OpenAI/Anthropic-compatible server plus the status page and browser
21
+ chat UI.
22
+
23
+ ```sh
24
+ mlx-bun serve # default model, http://localhost:8080
25
+ mlx-bun serve e4b # pick a model by substring
26
+ mlx-bun serve gemma --memory-budget 18 # ...with admission control (GB)
27
+ mlx-bun serve e4b --no-open # don't open the browser chat UI
28
+ ```
29
+
30
+ Common flags (full list in [server-config.md](server-config.md)):
31
+
32
+ | Flag | Effect |
33
+ |---|---|
34
+ | `--host <addr>` | Interface to bind (default `127.0.0.1`, loopback only; `0.0.0.0` to expose) |
35
+ | `--port <n>` | Listen port (default 8080) |
36
+ | `--memory-budget <GB>` | Reject loads/requests that can't fit the budget |
37
+ | `--kv-quant config\|off\|4\|8` | KV cache quantization: per-layer `kv_config.json`, bf16, or uniform bits (default `config`) |
38
+ | `--adapter <dir>` | Mount a LoRA adapter at startup (`--adapter-path` accepted as the mlx_lm.server alias) |
39
+ | `--batch <n>` | Continuous-batched bf16 serving (default 1 = serial) |
40
+ | `--temperature` / `--top-p` / `--top-k` / `--max-tokens` | Server-wide sampling defaults (per-request fields still win) |
41
+ | `--l1` / `--l2` / `--l3` | Parity tier: bit-exact to mlx-lm / bit-exact to mlx-optiq / best performance |
42
+ | `--no-open` | Don't auto-open the chat UI |
43
+
44
+ Endpoints: `/v1/chat/completions`, `/v1/completions`, `/v1/messages`,
45
+ `/v1/responses`, `/v1/models`, `/v1/adapters`, `/health`, `/stats`, `/fit`,
46
+ `/library`, `/downloads` — status page at `/`, browser chat at `/chat`. Full
47
+ schemas in [server-api.md](server-api.md).
48
+
49
+ ### `pi` — built-in coding agent
50
+
51
+ Run the pi coding agent's terminal UI in-process against a local model —
52
+ nothing to install. Reuses a healthy running server, otherwise starts one for
53
+ the session.
54
+
55
+ ```sh
56
+ mlx-bun pi # interactive agent session
57
+ mlx-bun pi -p "explain this repo" # one-shot: print the reply and exit
58
+ ```
59
+
60
+ ### `harness pi` — connect your own pi
61
+
62
+ For people who already use
63
+ [pi](https://www.npmjs.com/package/@earendil-works/pi-coding-agent): installs a small,
64
+ reversible discovery extension that registers the local server as a pi
65
+ provider.
66
+
67
+ ```sh
68
+ mlx-bun harness pi # then: pi --provider mlx-bun
69
+ mlx-bun harness pi --remove # disconnect
70
+ ```
71
+
72
+ ### `generate` (alias `gen`) — one-shot generation
73
+
74
+ Load the model, generate, print, exit — no server. Renders through the chat
75
+ template by default; `--raw` feeds the prompt verbatim. Sampling and
76
+ decode-path levers mirror `serve` (`--temperature`, `--seed`, `--l1/--l2/--l3`,
77
+ `--kv-quant`, …).
78
+
79
+ ```sh
80
+ mlx-bun generate gemma "a haiku about metal shaders"
81
+ mlx-bun gen e4b --prompt "…" --max-tokens 512 --seed 42
82
+ ```
83
+
84
+ ### `embed` — text embeddings **(v0.0.9)**
85
+
86
+ One-shot embeddings from a local Qwen3-Embedding model (last-token pooled,
87
+ L2-normalized — bit-exact vs mlx-lm). One JSON vector per input line.
88
+
89
+ ```sh
90
+ mlx-bun embed --text "hello world"
91
+ echo -e "line one\nline two" | mlx-bun embed --json
92
+ ```
93
+
94
+ For a server endpoint, `mlx-bun serve <embedding-model>` then
95
+ `POST /v1/embeddings`.
96
+
97
+ ## Models & disk
98
+
99
+ Full guide: [models.md](models.md).
100
+
101
+ ### `get` — download a model
102
+
103
+ Resumable, checksum-verified download into the standard Hugging Face cache
104
+ (plain HTTPS, no Xet — no 0% stalls).
105
+
106
+ ```sh
107
+ mlx-bun get mlx-community/gemma-4-12B-it-OptiQ-4bit
108
+ mlx-bun get 12B # no "/" = registry query; re-gets/refreshes the match
109
+ ```
110
+
111
+ ### `scan` — index your cache
112
+
113
+ Re-index the HF cache into the registry (config + safetensors headers only,
114
+ never tensor bytes) so `ls`, `serve`, and `fit` can find models by substring.
115
+
116
+ ```sh
117
+ mlx-bun scan
118
+ ```
119
+
120
+ ### `ls` — list models
121
+
122
+ ```sh
123
+ mlx-bun ls # size, params, quant, capabilities
124
+ mlx-bun ls --vision --max-size 10GB # filter
125
+ mlx-bun ls --all-revisions # one row per cached snapshot
126
+ ```
127
+
128
+ ### `gc` — reclaim disk **(v0.0.9)**
129
+
130
+ Delete superseded snapshots and the blobs only they reference. Prints the plan
131
+ by default; `--yes` actually deletes.
132
+
133
+ ```sh
134
+ mlx-bun gc # dry-run: what would be reclaimed
135
+ mlx-bun gc --yes # delete
136
+ ```
137
+
138
+ ### `fit` — memory contract
139
+
140
+ Deterministic memory assessment: does it fit, what's the max context, predicted
141
+ tok/s. Weights bytes from safetensors headers, KV bytes/token from the config,
142
+ calibrated prefill transient, wired-memory ceiling.
143
+
144
+ ```sh
145
+ mlx-bun fit gemma --ctx 32768 # for this machine
146
+ mlx-bun fit gemma --ctx 8192 --skus # across the Apple Silicon lineup
147
+ ```
148
+
149
+ ## Training & model creation
150
+
151
+ Full reference: [training.md](training.md); guided walkthrough:
152
+ [orpo-quickstart.md](orpo-quickstart.md).
153
+
154
+ ### `train` — LoRA fine-tune
155
+
156
+ SFT / DPO / ORPO on your data, with the full memory stack (flash-CCE head,
157
+ prefix-sharing, segmented backward) on by default. Saves a mountable adapter.
158
+
159
+ ```sh
160
+ mlx-bun train e4b --data ./prefs # ORPO (default) on {prompt,chosen,rejected}
161
+ mlx-bun train e4b --data ./prefs --method sft # SFT on {messages|text}
162
+ mlx-bun train e4b --data ./prefs --dry-run # inspect the plan, don't train
163
+ ```
164
+
165
+ ### `train-watch` — live training dashboard
166
+
167
+ Tails an adapter dir's `metrics.jsonl` and renders live loss / speed / memory.
168
+
169
+ ```sh
170
+ mlx-bun train-watch ~/.cache/mlx-bun/mlx-bun-finetunes/orpo-e4b
171
+ ```
172
+
173
+ ### `fuse` — merge an adapter into the base **(v0.0.9)**
174
+
175
+ Folds LoRA deltas into the base weights and writes a standalone snapshot; a
176
+ quantized base keeps its exact quantization layout. Flag names match
177
+ `mlx_lm.fuse`.
178
+
179
+ ```sh
180
+ mlx-bun fuse e4b --adapter ./adapters --save-path ./fused_model
181
+ mlx-bun serve ./fused_model
182
+ ```
183
+
184
+ ### `convert` — quantize a model **(v0.0.9)**
185
+
186
+ Quantize an HF model (local path, downloaded model, or repo id) into a local
187
+ MLX snapshot — uniform 4/8-bit, or mixed-precision via `--target-bpw`
188
+ (sensitivity sweep + per-layer bit knapsack). `--upload-repo` pushes the result.
189
+
190
+ ```sh
191
+ mlx-bun convert Qwen/Qwen3-4B -q # uniform 4-bit
192
+ mlx-bun convert Qwen/Qwen3-4B --target-bpw 4.5 # mixed precision
193
+ ```
194
+
195
+ ### `upload` — push to the Hugging Face Hub **(v0.0.9)**
196
+
197
+ Native push-to-hub, no Python: creates the repo if needed, uploads via the
198
+ git-LFS batch protocol, commits. Flag names match `mlx_lm.upload`.
199
+
200
+ ```sh
201
+ mlx-bun upload --path ./fused_model --upload-repo you/my-model
202
+ ```
203
+
204
+ ### `perplexity` — evaluate on your data **(v0.0.9)**
205
+
206
+ `mlx_lm.perplexity` methodology exactly, over a **local** `.jsonl`/`.txt` file.
207
+
208
+ ```sh
209
+ mlx-bun perplexity e4b --data-path ./corpus.jsonl
210
+ ```
211
+
212
+ ## Memory
213
+
214
+ ### `memory` — the personal wiki
215
+
216
+ A local, durable memory for the assistant: a git-tracked Markdown wiki at
217
+ `~/.mlx-bun/wiki` that loads into every `mlx-bun pi` / `mlx-bun serve` session.
218
+ Full guide: [memory.md](memory.md).
219
+
220
+ ```sh
221
+ mlx-bun memory init # create the wiki (idempotent); import + schedule
222
+ mlx-bun memory status # path, article count, git + schedule state
223
+ mlx-bun memory open [article] # open in Obsidian (falls back to Finder)
224
+ mlx-bun memory search <query> # search articles from the terminal
225
+ mlx-bun memory synthesize # conversations → cross-linked articles, all local
226
+ mlx-bun memory schedule --at 03:00
227
+ ```
228
+
229
+ `setup` is an alias for `memory` **(v0.0.9)**.
230
+
231
+ ## Measurement
232
+
233
+ ### `benchmark` (alias `bench`) — measure our stack
234
+
235
+ Runs mlx-bun by itself on this machine and records to the eval DB.
236
+
237
+ ```sh
238
+ mlx-bun bench e4b --tokens 256 --runs 3
239
+ ```
240
+
241
+ For quotable **cross-stack** numbers use `./benchmark.sh` from the repo — it
242
+ preflight-gates on an idle machine and runs the mlx-lm/optiq comparison legs,
243
+ writing `benchmarks-h2h-<date>.md`.
244
+
245
+ ### `evals` — recorded runs
246
+
247
+ ```sh
248
+ mlx-bun evals # table: when, model, KV mode, tok/s, TTFT, peak, commit
249
+ mlx-bun evals --raw # JSON lines for scripts/jq
250
+ ```
251
+
252
+ ## Everything else
253
+
254
+ - `help [verb]` — overview, or per-verb help (same as `<verb> --help`).
255
+ - `--version` / `-v` — print the version.
@@ -1,5 +1,10 @@
1
1
  # Embedding mlx-bun (single-binary sidecar)
2
2
 
3
+ > **Not text embeddings.** This page is about *embedding the mlx-bun binary*
4
+ > inside an app. For text-vector embeddings (Qwen3-Embedding, `mlx-bun embed`,
5
+ > `POST /v1/embeddings`), see [server-api.md](./server-api.md#post-v1embeddings-openai-embeddings-api)
6
+ > and [library-api.md](./library-api.md#text-embeddings).
7
+
3
8
  Ship local inference inside a Mac app (Tauri, Electron, or anything
4
9
  that can spawn a process) with zero user-visible dependencies: one
5
10
  executable + three native libraries, dropped into your app's resources.
@@ -89,7 +94,7 @@ Spawn the server on app start, point your in-app client at it:
89
94
  ```ts
90
95
  // Electron main / Tauri sidecar config
91
96
  const child = spawn(resourcePath("mlx-bun"), [
92
- "serve", "gemma-4-12B", "--port", "8090", "--memory-budget", "12",
97
+ "serve", "gemma-4-12B", "--port", "8080", "--memory-budget", "12",
93
98
  ]);
94
99
  // readiness: poll GET /v1/models (start→ready is ~0.4 s warm)
95
100
  ```
@@ -113,7 +118,7 @@ The binary includes the resumable verified downloader:
113
118
  ```sh
114
119
  mlx-bun get mlx-community/gemma-4-12B-it-OptiQ-4bit # → standard HF cache
115
120
  mlx-bun scan # index it
116
- mlx-bun serve gemma-4-12B --port 8090
121
+ mlx-bun serve gemma-4-12B --port 8080
117
122
  ```
118
123
 
119
124
  Downloads resume across interruption, every blob is checksum-verified
@@ -78,7 +78,7 @@ prompt time), the decode clock from there.
78
78
  import { loadContext, createServer } from "mlx-bun";
79
79
 
80
80
  const ctx = await loadContext(dir, "my-model", { memoryBudgetBytes: 12e9 });
81
- const server = createServer(ctx, 8090, {
81
+ const server = createServer(ctx, 8080, {
82
82
  promptCacheBytes: 2e9, // byte-capped LRU (never count-capped)
83
83
  kvQuant: undefined, // default: kv_config.json; "off" | bits
84
84
  memoryBudgetBytes: 12e9, // admission control — the only OOM defense
@@ -87,8 +87,27 @@ const server = createServer(ctx, 8090, {
87
87
 
88
88
  `loadContext` refuses models that cannot serve any context within the
89
89
  budget (pre-GPU, mmap-only check). The server exposes OpenAI chat
90
- completions, Anthropic `/v1/messages`, OpenAI Responses, adapters, and
91
- `/stats` — [server-api.md](./server-api.md).
90
+ completions, Anthropic `/v1/messages`, OpenAI Responses, embeddings,
91
+ adapters, and `/stats` — [server-api.md](./server-api.md).
92
+
93
+ ## Text embeddings
94
+
95
+ ```ts
96
+ import { createModel, loadTokenizer, isEmbeddingModel, embedMany } from "mlx-bun";
97
+
98
+ const model = createModel(await Weights.open(dir), config); // Qwen3-Embedding
99
+ if (!isEmbeddingModel(model)) throw new Error("not an embedding model");
100
+ const tok = await loadTokenizer(dir);
101
+
102
+ const [a, b] = embedMany(model, tok, ["the cat sat", "a kitten rested"]);
103
+ // a.vector / b.vector are Float32Array, L2-normalized → dot product = cosine.
104
+ ```
105
+
106
+ `isEmbeddingModel` narrows a `RuntimeModel` to the plain-Qwen3 backbone (the
107
+ only one exposing `embedPooled`: last-token hidden → L2-norm). `embedOne`/
108
+ `embedMany` append the `<|endoftext|>` pooling token and, given an optional
109
+ `instruction`, apply Qwen3-Embedding's query format. Same vectors the CLI
110
+ (`mlx-bun embed`) and `/v1/embeddings` produce — bit-exact vs mlx-lm.
92
111
 
93
112
  ## Prompt cache (in-process prefix reuse)
94
113
 
@@ -6,7 +6,7 @@ Core rule:
6
6
 
7
7
  > Chat agents read memory articles. `mlx-bun memory synthesize` is the only writer.
8
8
 
9
- The current release includes the vault, read path, Obsidian open flow, and scheduler. Synthesis is scaffolded but still a no-op M1 stub. The planned synthesis engine uses the same local models you chat with, switched into an editorial pipeline with stage-specific LoRA adapters.
9
+ The current release includes the vault, read path, Obsidian open flow, scheduler, and a live synthesis engine: `mlx-bun memory synthesize` runs the full local DAG (and the nightly job runs it on a schedule). Synthesis uses the same local models you chat with, switched into an editorial pipeline; stage-specific LoRA adapters are the hardening roadmap below.
10
10
 
11
11
  ## Storage
12
12
 
@@ -38,7 +38,7 @@ mlx-bun memory schedule --at 03:00
38
38
  mlx-bun memory unschedule
39
39
  ```
40
40
 
41
- `memory synthesize` is currently safe and side-effect-free: it reports that M1 stage bodies are not implemented and writes nothing. In the full flow, `memory init` will be able to offer the HF-hosted memory adapter pack download so synthesis can run locally.
41
+ **`memory synthesize` writes to your vault.** It runs the full local synthesis DAG (segment → extract → route → create/patch → reconcile → link → wikify) and creates/patches articles under `articles/` (git-committed, so every change is reviewable and revertible). `--dry-run` is the safe, no-write mode: it reports what would happen without touching the vault. `--since` and `--model` scope/steer a run. The decomposed stage workers (`segment`/`extract`/`route`/`synthesize-stage`/`link`) run one stage each and are resumable.
42
42
 
43
43
  ## Agent tools
44
44
 
@@ -50,7 +50,7 @@ Both `mlx-bun pi` and the web chat expose these read-only tools:
50
50
  - `memory_section`
51
51
  - `memory_links`
52
52
  - `memory_list` — user articles plus read-only `Reference/*` docs
53
- - `memory_status` — vault path, setup state, article count, git state, last-synthesis placeholder, schedule state, recent changed articles
53
+ - `memory_status` — vault path, setup state, article count, git state, last synthesis run (from the vault's git log), schedule state, recent changed articles
54
54
 
55
55
  The tools are always registered. If no vault exists, they return a setup message instead of disappearing. Search/read results prefixed with `Reference/` are mlx-bun docs, not user memory articles.
56
56
 
@@ -65,7 +65,7 @@ The first command opens the vault. The second opens one article. Obsidian is pre
65
65
 
66
66
  ## Synthesis roadmap
67
67
 
68
- M1/M2 will turn saved pi sessions into articles using the local model plus four specialized LoRA adapters trained by Josh from existing Lucien-scale pipeline data and distributed from Hugging Face:
68
+ The pipeline (saved pi sessions → articles) runs today on the local model; the roadmap hardens each stage with four specialized LoRA adapters trained from existing Lucien-scale pipeline data and distributed from Hugging Face:
69
69
 
70
70
  1. deterministic ingest of saved web/terminal pi session JSONL;
71
71
  2. **memory-chunk LoRA** — conversation → topic chunks (already trained as a WIP artifact);
@@ -74,4 +74,4 @@ M1/M2 will turn saved pi sessions into articles using the local model plus four
74
74
  5. **memory-editor LoRA** — candidate article → polished wiki Markdown;
75
75
  6. deterministic footnote/wikilink normalization, quality gates, and git commit.
76
76
 
77
- The adapters propose; the pipeline validates and writes. The pipeline writes only `articles/`; `Reference/` is immutable context. Until synthesis lands, memory works with imported/hand-written user articles plus the built-in read-only mlx-bun reference docs.
77
+ The adapters propose; the pipeline validates and writes. The pipeline writes only `articles/`; `Reference/` is immutable context. Synthesis is live today (`mlx-bun memory synthesize` runs the full DAG; the nightly `memory schedule` job runs it automatically); imported/hand-written user articles and the built-in read-only mlx-bun reference docs coexist with synthesized ones.