mlx-bun 0.5.0 → 1.0.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 (640) hide show
  1. package/README.md +1449 -109
  2. package/THIRD_PARTY_NOTICES.md +882 -0
  3. package/bin/mlx-bun.convert.mjs +4 -0
  4. package/bin/mlx-bun.fuse.mjs +4 -0
  5. package/bin/mlx-bun.generate.mjs +4 -0
  6. package/bin/mlx-bun.lora.mjs +4 -0
  7. package/bin/mlx-bun.mjs +13 -21
  8. package/bin/mlx-bun.server.mjs +4 -0
  9. package/bin/mlx-bun.upload.mjs +4 -0
  10. package/dist/web/app.js +9584 -0
  11. package/package.json +50 -53
  12. package/src/cli/ane-install.ts +76 -0
  13. package/src/cli/args.ts +179 -0
  14. package/src/cli/engine-entry.ts +68 -0
  15. package/src/cli/inference.ts +214 -0
  16. package/src/cli/job-entry.ts +97 -0
  17. package/src/cli/library-host.ts +117 -0
  18. package/src/cli/main.ts +57 -0
  19. package/src/cli/memory-engine.ts +163 -0
  20. package/src/cli/memory.ts +36 -0
  21. package/src/cli/mlx-lm-aliases.ts +309 -0
  22. package/src/cli/model-choice.ts +33 -0
  23. package/src/cli/model-selection.ts +84 -0
  24. package/src/cli/module-host.ts +11 -0
  25. package/src/cli/module-verbs.ts +50 -0
  26. package/src/cli/numerical-policy.ts +12 -0
  27. package/src/cli/perplexity.ts +89 -0
  28. package/src/cli/serve-host.ts +423 -0
  29. package/src/cli/serve-isolated.ts +217 -0
  30. package/src/cli/serve-options.ts +106 -0
  31. package/src/cli/serve-state.ts +205 -0
  32. package/src/cli/serve.ts +500 -0
  33. package/src/cli/served-model-host.ts +102 -0
  34. package/src/cli/server-entry.ts +148 -0
  35. package/src/cli/serving-unit.ts +177 -0
  36. package/src/{tui.ts → cli/terminal.ts} +13 -8
  37. package/src/cli/worker-adapters.ts +34 -0
  38. package/src/cli/worker-entry.ts +272 -0
  39. package/src/cli/worker-unit.ts +179 -0
  40. package/src/engine/adapter-operation.ts +26 -0
  41. package/src/engine/cache-services.ts +114 -0
  42. package/src/engine/completion.ts +39 -0
  43. package/src/engine/generation-gateway.ts +358 -0
  44. package/src/engine/index.ts +59 -0
  45. package/src/engine/kv-budget.ts +120 -0
  46. package/src/engine/media-preparation.ts +232 -0
  47. package/src/engine/model-binding.ts +24 -0
  48. package/src/engine/model-host.ts +513 -0
  49. package/src/engine/model-serving.ts +89 -0
  50. package/src/{serve → engine}/preparation.ts +7 -5
  51. package/src/{serve → engine}/session-completion-engine.ts +6 -6
  52. package/src/engine/telemetry.ts +109 -0
  53. package/src/hub/downloads.ts +116 -0
  54. package/src/jobs/db.ts +16 -7
  55. package/src/jobs/events.ts +29 -0
  56. package/src/jobs/executable.ts +5 -0
  57. package/src/jobs/host.ts +51 -0
  58. package/src/jobs/in-process.ts +55 -0
  59. package/src/{contracts/jobs.ts → jobs/protocol.ts} +7 -9
  60. package/src/jobs/runner.ts +150 -231
  61. package/src/jobs/service.ts +75 -0
  62. package/src/jobs/sse.ts +59 -23
  63. package/src/jobs/worker-memory.ts +46 -0
  64. package/src/jobs/worker-process.ts +163 -0
  65. package/src/jobs/worker-supervisor.ts +258 -0
  66. package/src/modules.ts +58 -0
  67. package/src/publishing/catalog-hub.ts +18 -0
  68. package/src/publishing/credentials.ts +31 -0
  69. package/src/publishing/upload.ts +37 -0
  70. package/src/residency/leased-adapters.ts +21 -0
  71. package/src/residency/local-records.ts +16 -0
  72. package/src/residency/model-residency.ts +405 -0
  73. package/src/residency/record-index.ts +28 -0
  74. package/src/residency/resident-estimate.ts +50 -0
  75. package/src/{anthropic.ts → server/anthropic.ts} +3 -81
  76. package/src/server/cache-routes.ts +36 -0
  77. package/src/{serve → server}/chat-request.ts +10 -10
  78. package/src/{serve → server}/chat-stage.ts +14 -14
  79. package/src/{client.ts → server/client.ts} +28 -2
  80. package/src/{serve → server}/completion-executor.ts +33 -41
  81. package/src/server/decision-body.ts +55 -0
  82. package/src/server/decision-routes.ts +134 -0
  83. package/src/server/decision-wire.ts +228 -0
  84. package/src/{serve → server}/discovery-routes.ts +25 -82
  85. package/src/{serve → server}/http.ts +25 -13
  86. package/src/{serve → server}/inference-request.ts +5 -5
  87. package/src/server/job-routes.ts +20 -0
  88. package/src/server/media-prompt.ts +63 -0
  89. package/src/server/memory-completion-client.ts +46 -0
  90. package/src/server/model-routes.ts +192 -0
  91. package/src/{serve → server}/openai-wire.ts +3 -2
  92. package/src/{serve → server}/pipeline.ts +1 -1
  93. package/src/server/prompt-builder.ts +13 -0
  94. package/src/server/prompt-contracts.ts +17 -0
  95. package/src/server/proxy-routes.ts +187 -0
  96. package/src/server/publishing-routes.ts +41 -0
  97. package/src/{serve → server}/request-plan.ts +6 -8
  98. package/src/{serve → server}/request-prep.ts +47 -50
  99. package/src/{serve → server}/responses-client.ts +30 -13
  100. package/src/{responses.ts → server/responses.ts} +12 -93
  101. package/src/server/routes.ts +205 -0
  102. package/src/server/start.ts +72 -0
  103. package/src/server/status-routes.ts +108 -0
  104. package/src/{serve → server}/text-completion-stage.ts +25 -4
  105. package/src/server/text-prompt.ts +12 -0
  106. package/src/{serve → server}/token-streams.ts +36 -38
  107. package/src/server/worker-routes.ts +311 -0
  108. package/src/storage/paths.ts +61 -0
  109. package/src/web/assets.ts +37 -0
  110. package/src/web/{src → browser}/api.ts +5 -23
  111. package/src/web/browser/chat-host.ts +17 -0
  112. package/src/web/browser/installed-panels.ts +6 -0
  113. package/src/web/browser/main.ts +55 -0
  114. package/src/web/browser/markdown.ts +279 -0
  115. package/src/web/browser/memory-panel.ts +9 -0
  116. package/src/web/browser/palette.ts +64 -0
  117. package/src/web/browser/protocol.ts +13 -0
  118. package/src/web/browser/shell.ts +467 -0
  119. package/src/web/{src → browser}/status.ts +32 -36
  120. package/src/web/build.ts +51 -0
  121. package/src/web/public/app.html +1054 -0
  122. package/src/web/{sw.js → public/sw.js} +4 -3
  123. package/src/web/{vendor → public/vendor}/hljs-theme.css +2 -2
  124. package/src/web/{vendor → public/vendor}/hljs.js +2 -2
  125. package/THIRD_PARTY_LICENSES.md +0 -51
  126. package/docs/README.md +0 -107
  127. package/docs/archive/hlg-sampling.md +0 -350
  128. package/docs/archive/investigations/audio-input-plan.md +0 -356
  129. package/docs/archive/investigations/benchmark-ledger-through-v0.4.0.md +0 -3617
  130. package/docs/archive/investigations/chunk-finetune-experiment.md +0 -84
  131. package/docs/archive/investigations/colibri-glm52-port.md +0 -1486
  132. package/docs/archive/investigations/colibri-oracle-pin.md +0 -1284
  133. package/docs/archive/investigations/curve-bisector-routing.md +0 -123
  134. package/docs/archive/investigations/decode-roofline-lookagain.md +0 -348
  135. package/docs/archive/investigations/diffusion-gemma-port.md +0 -602
  136. package/docs/archive/investigations/dspark-handoff.md +0 -224
  137. package/docs/archive/investigations/expert-offload-single-user-moe.md +0 -292
  138. package/docs/archive/investigations/faithful-l1-consolidation.md +0 -310
  139. package/docs/archive/investigations/hlg-sampling-investigation.md +0 -970
  140. package/docs/archive/investigations/indexshare-performance-spike.md +0 -357
  141. package/docs/archive/investigations/kernel-perf-review-2026-07.md +0 -171
  142. package/docs/archive/investigations/lab-build-journal.md +0 -157
  143. package/docs/archive/investigations/minicpm5-decode-megakernel.md +0 -489
  144. package/docs/archive/investigations/openjarvis-fit.md +0 -198
  145. package/docs/archive/investigations/openwiki-evaluation.md +0 -249
  146. package/docs/archive/investigations/optimization_plan.md +0 -346
  147. package/docs/archive/investigations/orpo-base-uf-experiment-and-directions.md +0 -120
  148. package/docs/archive/investigations/orpo-flash-cce-pin-leak.md +0 -167
  149. package/docs/archive/investigations/orpo-uf-testing-handoff.md +0 -126
  150. package/docs/archive/investigations/pareto-specialized-runtime-findings.md +0 -92
  151. package/docs/archive/investigations/pi-builtin-investigation.md +0 -308
  152. package/docs/archive/investigations/pre-colibri-stabilization.md +0 -329
  153. package/docs/archive/investigations/qwen38-27b-campaign-log.md +0 -1092
  154. package/docs/archive/investigations/segmented-backward-handoff.md +0 -148
  155. package/docs/archive/investigations/starter-model-port-handoff.md +0 -342
  156. package/docs/archive/investigations/steel-flash-cce-handoff.md +0 -489
  157. package/docs/archive/investigations/the-dreaming-handoff.md +0 -141
  158. package/docs/archive/investigations/trainer-validation-experiment.md +0 -173
  159. package/docs/archive/planning/chat-ui-vision-memory-first.md +0 -199
  160. package/docs/archive/planning/chat-ui-vision.md +0 -50
  161. package/docs/archive/planning/chunk-task-roadmap.md +0 -77
  162. package/docs/archive/planning/curve-sampler-research-plan.md +0 -331
  163. package/docs/archive/planning/journal.md +0 -316
  164. package/docs/archive/planning/memory-docs-and-dag-plan.md +0 -194
  165. package/docs/archive/planning/pi-integration-review.md +0 -178
  166. package/docs/archive/planning/release-notes-v0.0.10.md +0 -57
  167. package/docs/archive/planning/release-notes-v0.0.11.md +0 -239
  168. package/docs/archive/planning/release-notes-v0.0.12.md +0 -80
  169. package/docs/archive/planning/release-notes-v0.0.13.md +0 -77
  170. package/docs/archive/planning/release-notes-v0.0.9.md +0 -122
  171. package/docs/archive/planning/release-notes-v0.2.0.md +0 -49
  172. package/docs/archive/planning/release-notes-v0.3.0.md +0 -35
  173. package/docs/archive/planning/release-notes-v0.4.0.md +0 -45
  174. package/docs/archive/planning/release-notes-v0.5.0.md +0 -37
  175. package/docs/archive/planning/web-ui-pass-plan.md +0 -213
  176. package/docs/archive/planning/website-readme-pass-plan.md +0 -224
  177. package/docs/design/batching.md +0 -2054
  178. package/docs/design/decode-speed-program.md +0 -2404
  179. package/docs/design/dreaming-nightly-pipeline.md +0 -684
  180. package/docs/design/generic-model-support.md +0 -821
  181. package/docs/design/kv-cache.md +0 -993
  182. package/docs/design/orpo-training.md +0 -680
  183. package/docs/design/speculative-decoding.md +0 -2129
  184. package/docs/design/turboquant.md +0 -2225
  185. package/docs/design/unified-engine-frontier-plan.md +0 -1987
  186. package/docs/design/web-chat-redesign.md +0 -695
  187. package/docs/planning/PRODUCT_ROADMAP.md +0 -593
  188. package/docs/planning/ResearchTopics.md +0 -119
  189. package/docs/planning/public-readiness-handoff.md +0 -244
  190. package/docs/planning/public-readiness.md +0 -149
  191. package/docs/planning/video-series.md +0 -421
  192. package/docs/reference/benchmarks.md +0 -3587
  193. package/docs/reference/cli.md +0 -646
  194. package/docs/reference/distribution.md +0 -380
  195. package/docs/reference/environment.md +0 -494
  196. package/docs/reference/glossary.md +0 -39
  197. package/docs/reference/library-api.md +0 -688
  198. package/docs/reference/memory.md +0 -260
  199. package/docs/reference/models.md +0 -346
  200. package/docs/reference/server-api.md +0 -1945
  201. package/docs/reference/server-config.md +0 -973
  202. package/docs/reference/training.md +0 -462
  203. package/docs/reference/troubleshooting.md +0 -158
  204. package/src/admission-plan.ts +0 -18
  205. package/src/audio/audiotoolbox.ts +0 -112
  206. package/src/audio/conformer.ts +0 -655
  207. package/src/audio/decode.ts +0 -133
  208. package/src/audio/features.ts +0 -202
  209. package/src/audio/mic-capture.ts +0 -98
  210. package/src/audio/silero-vad.ts +0 -379
  211. package/src/audio/transcode.ts +0 -67
  212. package/src/audio/whisper-decode.ts +0 -774
  213. package/src/audio/whisper-fast.ts +0 -732
  214. package/src/audio/whisper-format.ts +0 -73
  215. package/src/audio/whisper-mel.ts +0 -185
  216. package/src/audio/whisper-timing.ts +0 -274
  217. package/src/audio/whisper-tokenizer.ts +0 -239
  218. package/src/audio/whisper-transcribe.ts +0 -410
  219. package/src/backends/mlx/assistant-target.ts +0 -46
  220. package/src/backends/mlx/autoregressive-draft-rows.ts +0 -120
  221. package/src/backends/mlx/autoregressive.ts +0 -129
  222. package/src/backends/mlx/batch-group.ts +0 -1874
  223. package/src/backends/mlx/cache-attachment.ts +0 -67
  224. package/src/backends/mlx/cache-layout.ts +0 -31
  225. package/src/backends/mlx/checkpoint-state.ts +0 -53
  226. package/src/backends/mlx/continuation-persistence.ts +0 -107
  227. package/src/backends/mlx/continuation-request.ts +0 -43
  228. package/src/backends/mlx/continuation.ts +0 -77
  229. package/src/backends/mlx/diffusion.ts +0 -39
  230. package/src/backends/mlx/draft-target.ts +0 -32
  231. package/src/backends/mlx/encoder-cache.ts +0 -25
  232. package/src/backends/mlx/evaluation.ts +0 -105
  233. package/src/backends/mlx/fill-append.ts +0 -58
  234. package/src/backends/mlx/fill-group.ts +0 -497
  235. package/src/backends/mlx/full-kv-row-append.ts +0 -32
  236. package/src/backends/mlx/full-kv-row-donor.ts +0 -54
  237. package/src/backends/mlx/full-transitioning-kv-rows.ts +0 -65
  238. package/src/backends/mlx/gateway-binding.ts +0 -174
  239. package/src/backends/mlx/graph.ts +0 -38
  240. package/src/backends/mlx/kv-codec.ts +0 -9
  241. package/src/backends/mlx/kv-maintenance.ts +0 -161
  242. package/src/backends/mlx/kv-tensor-rows.ts +0 -212
  243. package/src/backends/mlx/memory-client.ts +0 -189
  244. package/src/backends/mlx/methods.ts +0 -90
  245. package/src/backends/mlx/mixed-iteration.ts +0 -62
  246. package/src/backends/mlx/model-prompt.ts +0 -178
  247. package/src/backends/mlx/model-serving.ts +0 -80
  248. package/src/backends/mlx/paged-cache-codec.ts +0 -27
  249. package/src/backends/mlx/prefill-cohort.ts +0 -100
  250. package/src/backends/mlx/prefill-policy.ts +0 -26
  251. package/src/backends/mlx/prefill-rows.ts +0 -244
  252. package/src/backends/mlx/prefill.ts +0 -33
  253. package/src/backends/mlx/projected-context-rows.ts +0 -72
  254. package/src/backends/mlx/prompt-input.ts +0 -29
  255. package/src/backends/mlx/qwen-prompt-input.ts +0 -40
  256. package/src/backends/mlx/request-policy.ts +0 -20
  257. package/src/backends/mlx/request-state-policy.ts +0 -54
  258. package/src/backends/mlx/rollback.ts +0 -92
  259. package/src/backends/mlx/row-sampling.ts +0 -49
  260. package/src/backends/mlx/serial-executor.ts +0 -251
  261. package/src/backends/mlx/speculative-group.ts +0 -438
  262. package/src/backends/mlx/speculative-round.ts +0 -161
  263. package/src/backends/mlx/speculative.ts +0 -131
  264. package/src/backends/mlx/state-rows.ts +0 -104
  265. package/src/backends/mlx/state-views.ts +0 -46
  266. package/src/backends/mlx/target-layout-capability.ts +0 -35
  267. package/src/backends/mlx/text-engine.ts +0 -73
  268. package/src/backends/mlx/transitioning-kv-rows.ts +0 -173
  269. package/src/chat-template.ts +0 -382
  270. package/src/cli.ts +0 -3490
  271. package/src/config.ts +0 -399
  272. package/src/contracts/completion.ts +0 -16
  273. package/src/contracts/execution.ts +0 -70
  274. package/src/contracts/generation.ts +0 -103
  275. package/src/contracts/host.ts +0 -7
  276. package/src/contracts/object-cache.ts +0 -8
  277. package/src/contracts/pi-provider.ts +0 -30
  278. package/src/contracts/pi.ts +0 -261
  279. package/src/contracts/prefix-cache.ts +0 -33
  280. package/src/contracts/resources.ts +0 -25
  281. package/src/contracts/sampling.ts +0 -23
  282. package/src/contracts/scheduling.ts +0 -54
  283. package/src/contracts/tsconfig.json +0 -14
  284. package/src/dataset/generators.ts +0 -1087
  285. package/src/dataset/index.ts +0 -12
  286. package/src/dataset/job.ts +0 -81
  287. package/src/dataset/llm.ts +0 -71
  288. package/src/dataset/registry.ts +0 -528
  289. package/src/diffusion/diffusion-generate.ts +0 -507
  290. package/src/download.ts +0 -505
  291. package/src/embed.ts +0 -77
  292. package/src/engine/admission.ts +0 -59
  293. package/src/engine/cancellation.ts +0 -38
  294. package/src/engine/engine.ts +0 -56
  295. package/src/engine/execution-coordinator.ts +0 -70
  296. package/src/engine/execution-plan.ts +0 -64
  297. package/src/engine/execution-tasks.ts +0 -44
  298. package/src/engine/namespaced-cache.ts +0 -13
  299. package/src/engine/resources.ts +0 -53
  300. package/src/engine/scheduler.ts +0 -92
  301. package/src/engine/session.ts +0 -247
  302. package/src/eval/README.md +0 -130
  303. package/src/eval/ifeval.ts +0 -81
  304. package/src/eval/kl-prompts.ts +0 -29
  305. package/src/eval/kl.ts +0 -590
  306. package/src/eval/perplexity.ts +0 -164
  307. package/src/eval/quality-db.ts +0 -92
  308. package/src/eval/reference-logits.ts +0 -207
  309. package/src/eval/runner.ts +0 -124
  310. package/src/eval/score.ts +0 -49
  311. package/src/eval/tasks/bfcl.ts +0 -535
  312. package/src/eval/tasks/gsm8k.ts +0 -98
  313. package/src/eval/tasks/hashhop.ts +0 -139
  314. package/src/eval/tasks/humaneval.ts +0 -275
  315. package/src/eval/tasks/ifeval.ts +0 -525
  316. package/src/eval/tasks/mmlu.ts +0 -157
  317. package/src/eval/ultrafeedback.ts +0 -60
  318. package/src/evaldb.ts +0 -199
  319. package/src/expert-io.ts +0 -393
  320. package/src/expert-offload-build.ts +0 -77
  321. package/src/expert-offload.ts +0 -76
  322. package/src/expert-residency.ts +0 -1134
  323. package/src/expert-usage.ts +0 -415
  324. package/src/fill/echo-index.ts +0 -188
  325. package/src/fill/fill-session.ts +0 -463
  326. package/src/fill/proposal.ts +0 -68
  327. package/src/fill/schema-rows.ts +0 -506
  328. package/src/fill/tool-boundary.ts +0 -103
  329. package/src/fit.ts +0 -249
  330. package/src/generate.ts +0 -1352
  331. package/src/grammar.ts +0 -604
  332. package/src/harness-pi.ts +0 -184
  333. package/src/hf-push.ts +0 -628
  334. package/src/hub-rest.ts +0 -242
  335. package/src/index.ts +0 -63
  336. package/src/inference/denoising.ts +0 -17
  337. package/src/inference/draft-acceptance.ts +0 -41
  338. package/src/inference/draft-output.ts +0 -49
  339. package/src/inference/graph.ts +0 -33
  340. package/src/inference/prefill.ts +0 -45
  341. package/src/inference/rollback.ts +0 -7
  342. package/src/jobs/index.ts +0 -31
  343. package/src/jobs/job-entry.ts +0 -107
  344. package/src/jobs/task-client.ts +0 -19
  345. package/src/jobs/types.ts +0 -2
  346. package/src/kv-scheme.ts +0 -279
  347. package/src/kv-store.ts +0 -1135
  348. package/src/lab/README.md +0 -22
  349. package/src/lab/curve/curve-designer.html +0 -303
  350. package/src/lab/curve/curve-sampler.ts +0 -122
  351. package/src/lab/expert-trace/expert-trace.ts +0 -69
  352. package/src/lab/paged-kv/paged-attention.ts +0 -117
  353. package/src/lab/paged-kv/paged-kv-rows.ts +0 -111
  354. package/src/lab/paged-kv/paged-kv.ts +0 -336
  355. package/src/library.ts +0 -40
  356. package/src/lora.ts +0 -408
  357. package/src/md-modules.d.ts +0 -54
  358. package/src/media-fetch.ts +0 -442
  359. package/src/memory/article.ts +0 -558
  360. package/src/memory/chunk-validation.ts +0 -150
  361. package/src/memory/chunk.ts +0 -318
  362. package/src/memory/cluster.ts +0 -351
  363. package/src/memory/coverage.ts +0 -134
  364. package/src/memory/crosslink.ts +0 -0
  365. package/src/memory/db.ts +0 -253
  366. package/src/memory/entity.ts +0 -203
  367. package/src/memory/gate.ts +0 -187
  368. package/src/memory/history.ts +0 -152
  369. package/src/memory/ingest.ts +0 -335
  370. package/src/memory/model.ts +0 -183
  371. package/src/memory/normalize.ts +0 -671
  372. package/src/memory/parse.ts +0 -22
  373. package/src/memory/pipeline.ts +0 -275
  374. package/src/memory/prompts.ts +0 -65
  375. package/src/memory/query.ts +0 -334
  376. package/src/memory/reconcile.ts +0 -734
  377. package/src/memory/redirect.ts +0 -108
  378. package/src/memory/reindex.ts +0 -325
  379. package/src/memory/resolve.ts +0 -307
  380. package/src/memory/rest.ts +0 -245
  381. package/src/memory/route.ts +0 -272
  382. package/src/memory/schedule.ts +0 -165
  383. package/src/memory/stages.ts +0 -777
  384. package/src/memory/synthesize.ts +0 -1638
  385. package/src/memory/tools.ts +0 -749
  386. package/src/memory/vault.ts +0 -1194
  387. package/src/memory/wikify.ts +0 -1064
  388. package/src/mlx/array.ts +0 -425
  389. package/src/mlx/autograd.ts +0 -304
  390. package/src/mlx/checkpoint.ts +0 -149
  391. package/src/mlx/compile.ts +0 -168
  392. package/src/mlx/custom-vjp.ts +0 -188
  393. package/src/mlx/ffi.ts +0 -531
  394. package/src/mlx/materialize.ts +0 -23
  395. package/src/mlx/metal-kernel.ts +0 -159
  396. package/src/mlx/normalized-argmax.ts +0 -116
  397. package/src/mlx/ops.ts +0 -1108
  398. package/src/mlx/quantized-rows.ts +0 -36
  399. package/src/mlx/token-bitmask.ts +0 -52
  400. package/src/mlx/turboquant-kv-decode.ts +0 -82
  401. package/src/mlx/turboquant-kv-inverse.ts +0 -122
  402. package/src/mlx/turboquant-ops.ts +0 -861
  403. package/src/mlx/turboquant-tables.ts +0 -237
  404. package/src/mmap.ts +0 -90
  405. package/src/model/artifact-identity.ts +0 -73
  406. package/src/model/batched-kv.ts +0 -235
  407. package/src/model/batched-mask.ts +0 -279
  408. package/src/model/batched-quant.ts +0 -212
  409. package/src/model/batched-quantized-kv.ts +0 -144
  410. package/src/model/batched-rotating-quant.ts +0 -353
  411. package/src/model/batched-rotating-state.ts +0 -149
  412. package/src/model/batched-rotating.ts +0 -338
  413. package/src/model/batched-row-storage.ts +0 -179
  414. package/src/model/batched-ssm.ts +0 -52
  415. package/src/model/batched-turboquant-kv.ts +0 -94
  416. package/src/model/compiled-decode.ts +0 -712
  417. package/src/model/decoded-kv-donor.ts +0 -12
  418. package/src/model/delayed-quantized-kv.ts +0 -72
  419. package/src/model/delayed-rotating-quantized-kv.ts +0 -93
  420. package/src/model/delayed-turboquant-kv.ts +0 -57
  421. package/src/model/diffusion-gemma.ts +0 -1026
  422. package/src/model/factory.ts +0 -215
  423. package/src/model/fingerprint.ts +0 -45
  424. package/src/model/flash-attention.ts +0 -694
  425. package/src/model/full-prefill-padding.ts +0 -56
  426. package/src/model/full-prefill-row.ts +0 -105
  427. package/src/model/gemma4-base.ts +0 -2370
  428. package/src/model/gemma4.ts +0 -1395
  429. package/src/model/generated/gemma4-12b.ts +0 -429
  430. package/src/model/generated/gemma4-26b.ts +0 -448
  431. package/src/model/generated/gemma4-e4b.ts +0 -717
  432. package/src/model/generated/index.ts +0 -18
  433. package/src/model/glm52-atlas.ts +0 -511
  434. package/src/model/glm52-cache.ts +0 -792
  435. package/src/model/glm52-config.ts +0 -262
  436. package/src/model/glm52-container.ts +0 -305
  437. package/src/model/glm52-coupling.ts +0 -388
  438. package/src/model/glm52-dsa.ts +0 -606
  439. package/src/model/glm52-expert-layout.ts +0 -253
  440. package/src/model/glm52-layout.ts +0 -152
  441. package/src/model/glm52-memory.ts +0 -500
  442. package/src/model/glm52-mla.ts +0 -792
  443. package/src/model/glm52-moe.ts +0 -223
  444. package/src/model/glm52-pilot.ts +0 -537
  445. package/src/model/glm52-reference.ts +0 -445
  446. package/src/model/glm52-residency.ts +0 -557
  447. package/src/model/glm52-resident-weights.ts +0 -135
  448. package/src/model/glm52-streamed-experts.ts +0 -453
  449. package/src/model/glm52-streamed-metal.ts +0 -610
  450. package/src/model/glm52-weights.ts +0 -503
  451. package/src/model/glm52.ts +0 -1132
  452. package/src/model/implementation.ts +0 -69
  453. package/src/model/kv-attention-view.ts +0 -70
  454. package/src/model/minicpm5.ts +0 -376
  455. package/src/model/profile.ts +0 -468
  456. package/src/model/quantized-append-attention.ts +0 -31
  457. package/src/model/qwen-append.ts +0 -12
  458. package/src/model/qwen-conv.ts +0 -52
  459. package/src/model/qwen3-delta-state.ts +0 -74
  460. package/src/model/qwen3-delta.ts +0 -451
  461. package/src/model/qwen3-moe.ts +0 -404
  462. package/src/model/qwen3-mrope.ts +0 -250
  463. package/src/model/qwen3.ts +0 -277
  464. package/src/model/qwen3_5-checkpoint.ts +0 -164
  465. package/src/model/qwen3_5.ts +0 -881
  466. package/src/model/rotating-kv-donor.ts +0 -35
  467. package/src/model/rotating-kv-layout.ts +0 -262
  468. package/src/model/rotating-row-transaction.ts +0 -35
  469. package/src/model/speculative-rotating-kv.ts +0 -101
  470. package/src/model/ssm-prefill-padding.ts +0 -39
  471. package/src/model/support.ts +0 -110
  472. package/src/model/token-groups.ts +0 -66
  473. package/src/model/trellis-balanced-scatter.ts +0 -51
  474. package/src/model/trellis-linear.ts +0 -672
  475. package/src/model/trellis-shared-m.ts +0 -151
  476. package/src/model/trellis-shared-scatter.ts +0 -144
  477. package/src/model/trellis-splitk-prefill.ts +0 -158
  478. package/src/model/trellis-tiled-prefill.ts +0 -136
  479. package/src/model/trellis-vector-expand.ts +0 -62
  480. package/src/model/trellis-wide-prefill.ts +0 -94
  481. package/src/model/turboquant-codec.ts +0 -89
  482. package/src/model/universal/archs.ts +0 -332
  483. package/src/model/universal/dense.ts +0 -612
  484. package/src/model/universal/modules.ts +0 -170
  485. package/src/model/universal/rope.ts +0 -381
  486. package/src/model/whisper.ts +0 -435
  487. package/src/native/expert_io.c +0 -523
  488. package/src/native/frame_extract.swift +0 -140
  489. package/src/native/mic_capture.swift +0 -92
  490. package/src/native-pack.ts +0 -163
  491. package/src/pi-provider.ts +0 -53
  492. package/src/pi-session.ts +0 -81
  493. package/src/pi-terminal.ts +0 -274
  494. package/src/pi-web.ts +0 -1940
  495. package/src/preflight.ts +0 -158
  496. package/src/prompt-cache.ts +0 -682
  497. package/src/quantize/allocator.ts +0 -627
  498. package/src/quantize/atomic-output.ts +0 -38
  499. package/src/quantize/calibration.ts +0 -181
  500. package/src/quantize/config-writer.ts +0 -145
  501. package/src/quantize/index.ts +0 -84
  502. package/src/quantize/job.ts +0 -162
  503. package/src/quantize/quantizer.ts +0 -666
  504. package/src/quantize/rotate.ts +0 -603
  505. package/src/quantize/safetensors-writer.ts +0 -249
  506. package/src/quantize/sensitivity.ts +0 -216
  507. package/src/quantize/trellis.ts +0 -586
  508. package/src/quantize/weight-transform.ts +0 -292
  509. package/src/registry.ts +0 -602
  510. package/src/runtime-config.ts +0 -77
  511. package/src/safetensors.ts +0 -165
  512. package/src/sampler.ts +0 -1012
  513. package/src/serve/admin-routes.ts +0 -184
  514. package/src/serve/assets/curve-terrain.html +0 -105
  515. package/src/serve/assets/training-inference-map.html +0 -575
  516. package/src/serve/audio-routes.ts +0 -323
  517. package/src/serve/aux-routes.ts +0 -132
  518. package/src/serve/batch-scheduler.ts +0 -8
  519. package/src/serve/checkpoint-identity.ts +0 -64
  520. package/src/serve/generation-gateway.ts +0 -537
  521. package/src/serve/isolate.ts +0 -609
  522. package/src/serve/kv-budget.ts +0 -14
  523. package/src/serve/lab-routes.ts +0 -341
  524. package/src/serve/lane-registry.ts +0 -45
  525. package/src/serve/model-admin-routes.ts +0 -155
  526. package/src/serve/model-binding.ts +0 -49
  527. package/src/serve/model-host.ts +0 -511
  528. package/src/serve/parent-application.ts +0 -56
  529. package/src/serve/prompt-response-trace.ts +0 -161
  530. package/src/serve/response-lease.ts +0 -24
  531. package/src/serve/session-search.ts +0 -326
  532. package/src/serve/static-routes.ts +0 -101
  533. package/src/serve/transcription-server.ts +0 -64
  534. package/src/serve/transcription-service.ts +0 -502
  535. package/src/server.ts +0 -1282
  536. package/src/spec/assistant-rows.ts +0 -93
  537. package/src/spec/assistant-source.ts +0 -126
  538. package/src/spec/cache-identity.ts +0 -22
  539. package/src/spec/deepspec-rows.ts +0 -29
  540. package/src/spec/deepspec-source.ts +0 -145
  541. package/src/spec/dflash-source.ts +0 -149
  542. package/src/spec/drafter.ts +0 -304
  543. package/src/spec/dspark/ab-stats.ts +0 -136
  544. package/src/spec/dspark/calibration.ts +0 -112
  545. package/src/spec/dspark/data-dflash.ts +0 -156
  546. package/src/spec/dspark/data.ts +0 -201
  547. package/src/spec/dspark/deepspec-module.ts +0 -776
  548. package/src/spec/dspark/generate-dflash.ts +0 -245
  549. package/src/spec/dspark/generate.ts +0 -290
  550. package/src/spec/dspark/loader.ts +0 -23
  551. package/src/spec/dspark/loss.ts +0 -213
  552. package/src/spec/dspark/module-dflash.ts +0 -560
  553. package/src/spec/dspark/module.ts +0 -540
  554. package/src/spec/dspark/quantize-drafter.ts +0 -91
  555. package/src/spec/dspark/sample.ts +0 -112
  556. package/src/spec/generate.ts +0 -276
  557. package/src/spec/glm52-mtp-graph.ts +0 -29
  558. package/src/spec/glm52-mtp-rows.ts +0 -132
  559. package/src/spec/glm52-mtp-source.ts +0 -318
  560. package/src/spec/glm52-mtp-state.ts +0 -33
  561. package/src/spec/ngram-source.ts +0 -226
  562. package/src/spec/projected-draft-rows.ts +0 -73
  563. package/src/spec/qwen-mtp-module.ts +0 -171
  564. package/src/spec/qwen-mtp-rows.ts +0 -230
  565. package/src/spec/qwen-mtp-source.ts +0 -386
  566. package/src/spec/qwen-mtp-state.ts +0 -30
  567. package/src/spec/serve-loop.ts +0 -587
  568. package/src/spec/source.ts +0 -228
  569. package/src/spec/two-model-rows.ts +0 -62
  570. package/src/spec/two-model.ts +0 -113
  571. package/src/ssd-cache.ts +0 -431
  572. package/src/ssd-durability.ts +0 -209
  573. package/src/storage/host-buffer.ts +0 -24
  574. package/src/storage/kv-writer.ts +0 -83
  575. package/src/storage/kv-writer.worker.js +0 -264
  576. package/src/storage/retention-policy.ts +0 -37
  577. package/src/tiered-prompt-cache.ts +0 -45
  578. package/src/tokenizer.ts +0 -335
  579. package/src/tool-approvals.ts +0 -131
  580. package/src/tool-call.ts +0 -695
  581. package/src/train/dataset.ts +0 -484
  582. package/src/train/diffusion-lora.ts +0 -216
  583. package/src/train/export.ts +0 -32
  584. package/src/train/flash-cce.ts +0 -1234
  585. package/src/train/forward.ts +0 -266
  586. package/src/train/fuse.ts +0 -243
  587. package/src/train/index.ts +0 -46
  588. package/src/train/job.ts +0 -205
  589. package/src/train/lora-params.ts +0 -254
  590. package/src/train/loss.ts +0 -1591
  591. package/src/train/merge.ts +0 -195
  592. package/src/train/optimizer.ts +0 -183
  593. package/src/train/prefix-shared.ts +0 -490
  594. package/src/train/rank.ts +0 -137
  595. package/src/train/segmented.ts +0 -1828
  596. package/src/train/steel-qmm-header.ts +0 -1461
  597. package/src/train/trainer.ts +0 -1221
  598. package/src/train/watch.ts +0 -542
  599. package/src/vision/diffusion-vision.ts +0 -620
  600. package/src/vision/embedder.ts +0 -176
  601. package/src/vision/preprocess.ts +0 -247
  602. package/src/vision/prompt.ts +0 -409
  603. package/src/vision/qwen3vl-preprocess.ts +0 -409
  604. package/src/vision/qwen3vl-prompt.ts +0 -233
  605. package/src/vision/qwen3vl-tower.ts +0 -566
  606. package/src/vision/siglip.ts +0 -607
  607. package/src/vision/video-frames.ts +0 -148
  608. package/src/web/app.html +0 -2155
  609. package/src/web/app.js +0 -5863
  610. package/src/web/skills/memory/SKILL.md +0 -120
  611. package/src/web/skills/web-research/SKILL.md +0 -46
  612. package/src/web/skills.ts +0 -97
  613. package/src/web/src/adapters-panel.ts +0 -288
  614. package/src/web/src/assistant.ts +0 -451
  615. package/src/web/src/chat.ts +0 -1060
  616. package/src/web/src/composer.ts +0 -962
  617. package/src/web/src/dataset.ts +0 -132
  618. package/src/web/src/finetune.ts +0 -267
  619. package/src/web/src/hub.ts +0 -428
  620. package/src/web/src/main.ts +0 -98
  621. package/src/web/src/markdown.ts +0 -0
  622. package/src/web/src/memory-panel.ts +0 -572
  623. package/src/web/src/model-picker.ts +0 -159
  624. package/src/web/src/palette.ts +0 -346
  625. package/src/web/src/protocol.ts +0 -26
  626. package/src/web/src/quantize.ts +0 -167
  627. package/src/web/src/rag.ts +0 -274
  628. package/src/web/src/sessions.ts +0 -469
  629. package/src/web/src/shell.ts +0 -804
  630. package/src/web/src/ui-catalog.ts +0 -78
  631. package/src/web/src/voice.ts +0 -141
  632. package/src/web/vendor/README.md +0 -61
  633. package/src/web-assets.ts +0 -47
  634. package/src/web-tools.ts +0 -478
  635. package/src/weights.ts +0 -255
  636. /package/src/{serve → server}/completion-sink.ts +0 -0
  637. /package/src/{serve → server}/generated-token-history.ts +0 -0
  638. /package/src/web/{icon.svg → public/icon.svg} +0 -0
  639. /package/src/web/{manifest.webmanifest → public/manifest.webmanifest} +0 -0
  640. /package/src/web/{vendor → public/vendor}/hljs-LICENSE +0 -0
@@ -1,684 +0,0 @@
1
- ---
2
- status: active
3
- axis: USING
4
- canonical-for: memory-synthesis (the Dreaming)
5
- plan-anchor: none
6
- last-verified: 2026-08-23
7
- ---
8
-
9
- # The Dreaming — memory write path + synthesis (canonical design)
10
-
11
- This is THE design doc for mlx-bun's memory write path: the pipeline that
12
- turns conversations into a personal wiki (`src/memory/`, `scripts/memory/`),
13
- the local-model inference seam it runs on, the read path it feeds, and the
14
- evaluation methodology that sits beside it. It consolidates, in supersession
15
- order, `docs/design/dreaming-nightly-pipeline.md` → `docs/design/dreaming-nightly-pipeline.md` →
16
- `docs/design/dreaming-nightly-pipeline.md` → this doc, plus the architecture half of
17
- `docs/design/dreaming-nightly-pipeline.md`, `docs/design/dreaming-nightly-pipeline.md`, and the still-open task list
18
- from `docs/design/dreaming-nightly-pipeline.md`. Where those docs disagree, this doc wins.
19
-
20
- - User-facing behaviour (CLI, tools, vault layout as the user sees it) lives
21
- in `docs/reference/memory.md`. Status and changelog prose belong in
22
- `PLAN.md`; this doc carries design plus a short dated History.
23
- - Every code claim below was re-read against `src/memory/` on 2026-08-23.
24
- Where the code and the settled design differ, both are stated
25
- ("as built" vs "target") — the code is the truth about what runs; the
26
- design is the truth about where it goes.
27
-
28
- The system is the second iteration of Lucien's memory pipeline
29
- (`~/Code/lucien`, cloud models), rebuilt to run entirely on local models. Same
30
- methodology at the core — do whatever Wikipedia does — with two consequences
31
- of the local constraint:
32
-
33
- 1. **Small tasks.** Every AI step is the smallest single-purpose unit a small
34
- local model does well — one chunk, one section, ideally a binary judgment.
35
- Never a whole-article blob in or out. And every AI step is pure
36
- text-in/text-out: no tool calls, no agent loop. The pipeline hands the
37
- model exactly the context it needs and applies the output
38
- deterministically.
39
- 2. **Deterministic gates between AI steps.** AI does judgment; code enforces
40
- invariants (citations, footnotes, wikilinks, infobox shape, word floors).
41
- A weak output is gated to NO-OP, never allowed to corrupt the vault.
42
- "LoRAs propose, gates dispose."
43
-
44
- ## 1. Contract and fixed principles
45
-
46
- **The memory contract (ported from Lucien):** chat-time agents READ memory;
47
- the synthesis pipeline WRITES memory. Articles are durable priors,
48
- conversations are evidence, synthesis is the deliberate, auditable process
49
- that turns evidence into updated articles. Normal chat never mutates an
50
- article; writes happen only through `mlx-bun memory synthesize` (or its
51
- per-stage subcommands) and the user's own edits in the vault.
52
-
53
- Fixed principles (do not re-derive, do not contradict):
54
-
55
- - **Conversations are the base.** The pipeline's only input is conversation
56
- transcripts — pi sessions in steady state, a one-time historical import
57
- through the same code for onboarding.
58
- - **Articles are THINGS (subjects), with sections.** One subject per
59
- article: a lead, an infobox, `##` sections, See also, References. Subject
60
- mentions are `[[wikilinks]]`. Every article is "the thing AND how the user
61
- relates to it"; general world-facts link out.
62
- - **No notability filter.** "If I talk about it, it's notable." Nothing is
63
- dropped as trivia. A thin subject is CAPTURED (kept searchable in
64
- `_captured`) until it recurs; stubs are a feature.
65
- - **Capacity by decomposition.** A small model's effective capacity scales
66
- inversely with task size; you don't make the model smarter, you make each
67
- task narrower. Decompose to binary where possible and run M×N — affordable
68
- because local inference is nearly free. Coarse gates prune fine ones
69
- (chunk → article → section).
70
- - **No embeddings in the pipeline.** Routing, grouping, and reading are
71
- deterministic name/alias/category lookup plus small-model judgments. The
72
- hot path asserts the `src/embed.ts` tripwire (`getEmbedCounter()`) stays
73
- at 0. Embeddings survive only as offline eval instruments (§8) — see the
74
- contradiction note there.
75
- - **Vault = truth, DB = derived cache.** Markdown in the vault is canonical
76
- and git-tracked; SQLite is pipeline ledger + rebuildable index
77
- (`reindex`).
78
- - **Chronology is load-bearing.** Every stage walks
79
- `conversations.updated_at ASC, chunks.start ASC`. This is what makes
80
- self-healing correct: the user's latest statement dominates.
81
- - **Self-healing through ordinary use.** Corrections arrive as ordinary
82
- chunks; a later-dated contradiction resolves the article toward the
83
- user's latest position. The user's evolving positions keep a `## History`
84
- trace; an AI factual error is silently overwritten.
85
- - **Prompts and Meta pages are SCHEMATIC** — no real names, specs, or dates.
86
- The small model parrots concrete example values into unrelated articles
87
- (observed five times during bring-up). Every prompt carries a no-copy
88
- guard; leaky drafts are rejected (`isLeakyDraft`).
89
- - **Runs nightly, locally, unattended** (launchd, `src/memory/schedule.ts`).
90
- - **Lucien is a read-only oracle.** `~/Code/lucien/.lucien/lucien.db` is
91
- opened read-only; `~/Dreaming` is never written. Never suggest modifying
92
- Lucien's code, DB, or vault.
93
- - **Model evals are beside the system, not inside it.** Judges, gold sets,
94
- and signal scripts choose and train the models the pipeline uses; they are
95
- never a pipeline stage.
96
-
97
- ## 2. Data model
98
-
99
- ### 2.1 Vault (truth)
100
-
101
- - Root `~/.mlx-bun/wiki/` (override `MLX_BUN_WIKI`, honoured by `vaultRoot()`
102
- — every script and test redirects the whole pipeline by setting it).
103
- - `articles/*.md` user articles · `Meta/*.md` editable policy pages ·
104
- `Talk/` restructure suggestions · `Reference/*.md` read-only symlinks to
105
- mlx-bun's own docs (chat tools may read them; synthesis must never write
106
- through them).
107
- - Plain Markdown, git-tracked, usable as an Obsidian vault. Every pipeline
108
- write ends in `commitVault`.
109
- - Meta pages seeded by `setupVault` (`src/memory/vault.ts` `META_PAGES`):
110
- Editorial_Guidelines, Bucketing, Article_Conventions, Infobox_Schemas,
111
- Category_Definitions, Entities, Summary_Style, Buckets, Chunking,
112
- Topics_to_Ignore. Policy lives in the vault, not in code:
113
- `loadMetaPolicy(names)` (`src/memory/prompts.ts`) inlines pages into a
114
- stage prompt (single-turn, bounded prefill — never "go read the page")
115
- and throws if a requested page is missing.
116
-
117
- ### 2.2 Article grammar (`src/memory/article.ts`)
118
-
119
- Fixed skeleton, top to bottom: `# H1` (== filename stem with `_`→space) →
120
- optional series banner `*Part of a series on [[X]].*` → optional infobox
121
- (fenced ```` ```info ```` block of `key: value` lines) → lead (present-tense
122
- relationship abstract) → `##` sections → `## See also` → optional `## Notes`
123
- → `## References` last. Templates the parser and NORMALIZE recognise:
124
- `{{stub}}`, `*Main article: [[Child]]*`, `*Redirects to [[X]]*`.
125
-
126
- - **Infobox** — `snake_case` keys; entity-valued fields are `[[wikilinks]]`
127
- (they feed the link graph); `aliases:` is a comma list feeding the entity
128
- index; `kind:` is the closed set `ENTITY_KINDS = thing | person | domain |
129
- project | standard`; `type:` and every other field label are EMERGENT
130
- (governed by `Infobox_Schemas.md`, never a code enum). Fields are either
131
- world-facts (citable specs) or relationship-facts (owned / used_for /
132
- opinion / status … — the personal layer). The infobox is CONTENT the model
133
- reads, never a query/filter engine; there is no field query anywhere.
134
- - **Categories** — emergent and explicit: an article declares
135
- `[[Category:Name]]`; the deriver accumulates names into `categories`. A
136
- fresh vault has zero.
137
- - **Citations** — footnote defs in the Lucien standard
138
- `` [^N]: `conv:HASH` (YYYY-MM-DD, source) — desc ``, HASH = first 8 hex of
139
- the conversation UUID. A hash identifies the CONVERSATION only; chunk →
140
- section provenance is recovered from the ledger, never by parsing
141
- footnotes. The model only PLACES markers; code writes every definition
142
- line (`buildFootnoteMap`, `footnoteDefLine` in `synthesize.ts`).
143
- - One shared fence scanner (`isFenceLine`/`fenceLabel`) so `article.ts`,
144
- `vault.ts`, `normalize.ts`, `crosslink.ts` agree on "inside a code block";
145
- `repairFences` closes a dangling fence deterministically.
146
-
147
- ### 2.3 Store (`src/memory/db.ts`, `~/.cache/mlx-bun/memory.sqlite`)
148
-
149
- bun:sqlite, WAL, `PRAGMA foreign_keys = ON`, `ON DELETE CASCADE`. A DB
150
- carrying the pre-rewrite schema (`chunks.text` column or a
151
- `synthesized_bucket_chunks` table) is dropped and recreated on open.
152
-
153
- - **Derived cache** (rebuilt from markdown by `reindex`, never the reverse):
154
- `entities` · `entity_aliases` · `categories` · `article_categories` ·
155
- `infobox_facts` · `links` (`via ∈ prose|infobox|seealso|series|main`).
156
- - **Synthesis ledger** (authoritative pipeline progress, not derivable from
157
- the vault): `conversations` · `messages` · `chunks` · `chunk_entities` ·
158
- `chunk_sections` · `synthesized_chunk_sections` · `reconciled_articles` ·
159
- `watermarks` · `buckets` / `chunk_buckets` · `subject_redirects`.
160
- - **Pointers, not copies.** `messages` holds text once, keyed
161
- `(conv, position)`. A chunk is a `[start,end]` range plus a label, id
162
- `${conv}:${start}-${end}` (deterministic, idempotent re-chunking);
163
- `chunkText(id)` reassembles on demand. Assignments are join tables
164
- (many-to-many at every layer). The article markdown is the only
165
- materialised synthesis; its `conv:` citations point back at sources.
166
- - `reindex` (`src/memory/reindex.ts`) drops and rebuilds exactly the six
167
- derived tables from the vault with foreign keys off (so pipeline
168
- `chunk_entities` rows survive), in sorted-stem order, deterministically.
169
- It also PROJECTS `subject_redirects` into `entity_aliases` so a subject
170
- that folded into or was captured near another article still resolves.
171
-
172
- Turso/sqlite-vec were considered as a vector-capable engine and are moot
173
- under the no-embeddings rule; the driver stays bun:sqlite.
174
-
175
- ## 3. The pipeline as built (verified 2026-08-23)
176
-
177
- ```
178
- pi sessions / Lucien import ingest.ts (watermark per source) [NOT wired into the nightly run — §9]
179
- │
180
- ▼ SEGMENT ─────────── AI (memory-chunk adapter): one conversation → single-topic chunks + labels
181
- ▼ ENTITY-EXTRACT ──── AI (base+Entities.md): one chunk → the THINGS it is about (name list)
182
- ▼ ROUTE ────────────── deterministic resolve → binary disambiguate → create | routed | capture
183
- ▼ SYNTHESIZE
184
- │ CREATE ─────────── AI: sub-cluster → OUTLINE → per-section DRAFT → INFOBOX → assemble
185
- │ SECTION-ROUTE ──── AI: M×N binary "does this chunk update THIS section?" (+ name a new one)
186
- │ PATCH ──────────── AI: one (chunk, section) → replacement section, rest byte-identical
187
- │ RECONCILE ──────── AI+code: infobox = ground truth; lead/body/infobox agree; History
188
- │ ── every write: NORMALIZE (code) → conservative gate (code) → weak ⇒ NO-OP ──
189
- ▼ LINK ─────────────── code: first-mention [[links]] + co-occurrence See also (idempotent)
190
- ▼ commit (git)
191
- ▼ WIKIFY sweep ─────── AI (editor): per-section tighten + infobox refresh, every article
192
- ```
193
-
194
- Orchestration: `runSynthesis` (`src/memory/pipeline.ts`) drives
195
- `runPipeline` = `runSegmentStage → runExtractStage → runRouteStage →
196
- runSynthesizeStage → runLinkStage`, then `wikifyVault` over every article.
197
- Each stage worker (`src/memory/stages.ts`) pulls its eligible work from the
198
- DB by state, processes a bounded batch, persists, and is individually
199
- runnable: `mlx-bun memory segment | extract | route | synthesize-stage |
200
- link`; `mlx-bun memory synthesize` is the full DAG; `--dry-run` plans without
201
- model calls. A failed article never blocks the rest of a run.
202
-
203
- ### 3.1 INGEST (`ingest.ts`)
204
-
205
- Two sources, watermark-gated per `source`: pi sessions via
206
- `SessionManager.listAll()` (`ingestSessions`) and the one-time Lucien
207
- bootstrap (`ingestLucien`, read-only; maps Lucien's UUID-anchored chunks to
208
- positions). Idempotent — a re-touched conversation is rewritten in place.
209
- **As built, neither entry point is called by `runSynthesis` or any
210
- `scripts/memory/` driver** (only `tests/memory-ingest.test.ts` exercises
211
- `ingestLucien`); `runPipeline` emits "ingest: corpus already in the store".
212
- The nightly fold-in of new pi sessions is therefore not yet end-to-end — see
213
- §9.
214
-
215
- ### 3.2 SEGMENT (`chunk.ts`, `chunk-validation.ts`)
216
-
217
- The `memory-chunk` adapter (`e4b-chunk-300`, symlinked to
218
- `~/.cache/mlx-bun/adapters/memory-chunk`) segments each conversation whose
219
- `chunked_at` is NULL or older than `updated_at`. Prompt = `CHUNK_SYSTEM`
220
- (the exact trained system turn, byte-for-byte) + `CHUNK_PROMPT` with
221
- `Chunking.md` + `Topics_to_Ignore.md` inlined. Output is JSON of message-UUID
222
- anchors + a 4–10-word label; anchors are validated and repaired
223
- (`validateChunks`) before pointer rows are written; a conversation whose
224
- output fails validation is left unmarked and retried next run. Re-run is a
225
- no-op by watermark. Chunk purity is the foundation of everything downstream:
226
- a chunk that fuses two topics pollutes every article it routes to.
227
-
228
- ### 3.3 ENTITY-EXTRACT (`entity.ts`, `resolve.ts`)
229
-
230
- One chunk per call, base model + `Entities.md`: "what things is this chunk
231
- about? canonical wiki-title names, one per line, specific things AND the
232
- broad domain, NONE if nothing nameable." Plain newline list parsed by
233
- `parseLines` — no multi-item JSON, no batch indices (the batch-index drift
234
- that sank Lucien's batched assign). Persists `chunk_entities(chunk_id,
235
- entity_name, surface_form)` and a candidate `entities` row (article_stem
236
- NULL). Canonicalisation is deterministic and conservative
237
- (`EntityResolver`): `canonicalize` (casefold, whitespace, leading
238
- articles/possessives) → `squeeze` (strip all non-alphanumerics) → alias index
239
- (store + `goldens/dreaming-entities-gold.json` seeds) → token-subset fuzzy
240
- match requiring a distinctive token (the over-merge guard). When in doubt it
241
- mints a new canonical rather than fusing two things.
242
-
243
- ### 3.4 ROUTE (`route.ts`, `redirect.ts`)
244
-
245
- Per surface: (1) RESOLVE against the known-entity index — a hit folds into
246
- that article with no model call; (2) DISAMBIGUATE a miss with a trigram
247
- shortlist of existing entities and one bounded binary per candidate ("is X
248
- the same thing as Y? yes/no", `parseBinary`, existing wins); (3) CREATE /
249
- CAPTURE for a surface matching nothing: it earns its own article when it
250
- RECURS (`RECURRENCE_THRESHOLD = 2` routed chunks) or, with the optional
251
- `useSubjectGate`, when a chunk engages it as a genuine subject; otherwise it
252
- is CAPTURED — its chunks go to the reserved `_captured` bucket, `notable = 0`,
253
- still searchable, never dropped, promoted later if it recurs. There is no
254
- ownership/usefulness test. `runRouteStage` also registers
255
- `subject_redirects` so every discussed subject resolves to a home (a folded
256
- subject → its article; a captured subject → the article it most co-occurs
257
- with). A chunk fans out to every article it names — this is where facet
258
- extraction falls out: the same chunk lands on several articles, each keeping
259
- only what is relevant to it at patch time.
260
-
261
- ### 3.5 SYNTHESIZE (`stages.ts` `runSynthesizeStage`, `synthesize.ts`, `cluster.ts`)
262
-
263
- Chronological throughout; commits once at the end.
264
-
265
- - **CREATE** (`synthesizeCreate`) for each `notable = 1` entity with no
266
- article file, oldest entity first, capped by `DEFAULT_ARTICLE_CAP = 20`
267
- per pass: `subClusterChunks` groups the entity's chunks into proto-sections
268
- by label/text token overlap (deterministic, no embeddings) → OUTLINE (2–6
269
- headings) → per-section DRAFT from only that section's chunks → LEAD →
270
- seed INFOBOX (`buildInfoboxFields`, kind + declared aliases) → assemble →
271
- NORMALIZE → gate → write + `synthesized_chunk_sections` ledger. The model
272
- never holds a whole article. Leaky drafts retry once, then NO-OP.
273
- - **SECTION-ROUTE** (`routeSections`) for each chunk routed to an existing
274
- article and not yet in the ledger: one binary per routable section
275
- (structural tails References/See also/Notes excluded; the lead is a
276
- first-class target, `LEAD_ANCHOR`), prompt = title + heading + section's
277
- first ~2 sentences + chunk label + gist. All-no + substantive → "name a new
278
- section (2–5 words) or NONE"; a named section is honoured
279
- (`synthesizeNewSection`), never a silent drop. Hierarchical pruning is
280
- structural: only articles ROUTE matched are ever gridded.
281
- - **PATCH** (`synthesizePatch`, `patchSection`) — the model is handed the
282
- current section + the chunk (with its pre-assigned `[^N]`) and outputs a
283
- complete REPLACEMENT SECTION; code swaps exactly that section
284
- (`replaceSection`), appends the definition line, and leaves the rest of
285
- the file byte-identical. Contradiction = correction: rewrite toward the
286
- latest statement, classified by `classifyContradiction` (`history.ts`) as
287
- EVOLUTION (keep a `## History` entry citing both sources; default when
288
- ambiguous) or ERROR (silent overwrite, the wrong value's citation may be
289
- pruned via `allowDroppedHashes`). Idempotent via the ledger PK.
290
- - **RECONCILE** (`reconcileArticle`) runs after the patch loop over every
291
- article touched this run: the infobox is ground truth; relationship
292
- fields (favourite/opinion/status/owned … — never `PHYSICAL_SPEC_KEYS`) and
293
- sibling body sections still asserting a superseded value are refreshed
294
- toward the latest-dated position, provenance-preserving (every `[^k]`
295
- survives, phrased as change over time). Consistent article ⇒ NO-OP;
296
- unresolved present-tense assertions are logged, not forced.
297
-
298
- ### 3.6 The conservative write gate (`gate.ts`) and NORMALIZE (`normalize.ts`)
299
-
300
- `gateEdit(before, after)` is a faithful port of Lucien's editorial gate and
301
- guards every write (create, patch, new section, reconcile, link, wikify):
302
- every pre-existing `conv:` citation survives (unless deliberately pruned),
303
- footnote bijection, edited word count ≥ `floor` (default 0.7) of the
304
- original, H1 and `## References` survive, at most one `## See also`. It can
305
- only reject, never rewrite; it catches citation/structure/bulk-prose loss,
306
- not nuance loss (that is the judge's job, §8).
307
-
308
- `normalizeArticle` runs inside every write before the gate, pure and
309
- idempotent: footnote renumber/merge (`normalizeFootnotes`), wikilink
310
- canonicalisation to on-disk stems (`normalizeWikilinks`), infobox key sort,
311
- section order (`## See also` before `## References` last), `{{stub}}` guard
312
- for thin articles (`articleThinness`), `title = H1 = stem`, fence repair.
313
- Non-fatal per step. `normalizeVault` exists for a whole-vault pass but is not
314
- a nightly stage; normalisation is constitutive of each write instead.
315
-
316
- ### 3.7 LINK (`crosslink.ts`)
317
-
318
- Cross-linking is its own deterministic stage because synthesis is bounded to
319
- one article and cannot know the others. (1) MENTION edges: wrap the first
320
- whole-word mention of another article's title/alias as
321
- `[[Stem|surface]]` — never inside an existing link, code span, marker,
322
- infobox, heading, or References. (2) CO-OCCURRENCE edges from shared folded
323
- chunks (`synthesized_chunk_sections` ⋈ `chunk_entities`). (3) Rebuild
324
- `## See also` idempotently (mentions first, then top co-occurring articles
325
- that exist). Every edit passes `normalizeWikilinks` + `gateEdit`; a fully
326
- linked article re-runs to a byte-identical no-op. Measured on a 587-article
327
- snapshot of the import (2026-06-28, M1 Max 32 GB): See-also coverage 18% →
328
- 96%, resolved edges 309 → 7026.
329
-
330
- ### 3.8 WIKIFY — the editorial pass (`wikify.ts`)
331
-
332
- The periodic sweep, distinct from NORMALIZE: the model supplies judgment, the
333
- gate disposes of weak judgment. As built, `runSynthesis` runs `wikifyVault`
334
- over EVERY article every night after the write branch; each article commits
335
- its own change or NO-OPs, and a wikify defect cannot lose the committed
336
- create/patch work.
337
-
338
- - Per-section IMPROVE (`improveSections`, `editor` stage): "tighten this
339
- section — remove redundancy, keep every citation and every specific
340
- detail." Behind the gate.
341
- - Infobox EXTRACT/REFRESH (`refreshInfobox`): creates a missing infobox,
342
- refreshes present ones without losing a grounded fact, entity-valued
343
- fields as wikilinks, declared `aliases:` feed the entity index on reindex.
344
- - Summary-style SPLIT (`detectSplitCandidate`, `applySplit`): when one body
345
- section dominates the article it becomes a child article with the full
346
- cited prose; the parent keeps a summary + `*Main article: [[Child]]*`
347
- (a `via=main` edge). Skips the word floor (a sanctioned bulk move); gated
348
- structurally instead. Series banner maintenance (`setSeriesBanner`).
349
- - MERGE signals (`detectMergeCandidates`) and structure suggestions are
350
- written to `Talk/<stem>.md` (`writeTalkPage`) — the pass never
351
- restructures across articles on its own. `sectionCohesion` (an injected
352
- `EmbedFn` silhouette) exists here as an offline triage instrument only;
353
- `wikify.ts` never imports `src/embed.ts`.
354
-
355
- ### 3.9 Nightly run contract
356
-
357
- - Trigger: launchd `com.mlx-bun.memory` (`schedule.ts`; `mlx-bun memory
358
- schedule --at HH:MM`, default 03:00), running `mlx-bun memory synthesize`;
359
- logs `~/.mlx-bun/logs/memory-synthesis.{out,err}.log`.
360
- - Scope: only work past each stage's state (watermark / missing downstream
361
- row / ledger). A normal night is minutes, not hours; throughput only
362
- matters for the one-time import.
363
- - Inference: one resident Gemma-4-e4b (§4); a stage's adapter is mounted iff
364
- `~/.cache/mlx-bun/adapters/memory-<stage>` exists, else base + policy.
365
- - Every article change is a git commit; the run ends with a summary line.
366
- - Never started by an agent: the full-corpus import and any GPU training are
367
- user actions.
368
-
369
- ## 4. The inference seam (`src/memory/model.ts`)
370
-
371
- One shared runtime: one `RuntimeModel` (Gemma-4-e4b OptiQ-4bit, snapshot
372
- resolved by globbing for `config.json`), the `memory-chunk` adapter mounted
373
- once and ACTIVATED per call (`loraState.active`), one in-process
374
- `BatchScheduler`. Two seams: `callLocal(stage, {system?, user})` (bit-exact
375
- greedy via the eval runner's raw-forward decode) and `callLocalBatch(stage,
376
- inputs[])` (order-preserving; batched only when `MLX_BUN_MEMORY_BATCH > 1`
377
- and N > 1, else the same serial loop). Never auto-downloads; throws with the
378
- `hf download` hint until the snapshot lands.
379
-
380
- **Templating.** Each stage renders a `[system?, user]` message array through
381
- the model's chat template exactly as the server and the trainer's
382
- prompt-region render do (render with generation prompt → encode → dedupe a
383
- double BOS; `memoryPromptIds`). This fixed the bring-up defect where the
384
- chunk adapter — SFT'd with a system turn that Gemma-4 renders as a distinct
385
- `<|turn>system…<turn|>` block — was decoded with the system segment dropped.
386
- `tests/memory-templating.test.ts` asserts `memoryPromptIds("chunk", …)` is
387
- id-identical to a real training row's prompt region. Base stages get concise
388
- default systems (`DEFAULT_STAGE_SYSTEM`); only `chunk` must match training
389
- byte-for-byte.
390
-
391
- **Token budget.** `MAX_OUTPUT_TOKENS = 64_000` is the single backstop; stages
392
- pass it rather than per-call caps, because a finished answer stops at EOS and
393
- a cap can only truncate an unfinished one. (The per-stage 4/16/128/2048 caps
394
- in the original inference-path design are superseded; `extractEntityNamesRaw`
395
- still defaults to 128 when called directly.)
396
-
397
- **Batching — implemented, off by default (decision: Josh, 2026-07-01).**
398
- Measured 2026-06-28 on Gemma-4-e4b OptiQ-4bit, held-out
399
- `chunk-data-le4000/valid.jsonl` + the live 2096-conversation store, M-series
400
- GPU: 8 extract-style prompts (~400-token prefills) batched 9345 ms vs serial
401
- 5001 ms (≈1.9× slower, 8/8 exact); 8 short replies batched 2085 ms vs 1067 ms
402
- (≈2× slower, 7/8 match — one documented near-tie divergence); only 16 short
403
- uniform one-liners won (≈1.2× faster). The warm uniform chunk workload on the
404
- M1 Max 32 GB measured 0.607 vs 0.357 s/chunk (~1.7× slower). Root cause: the
405
- scheduler pads heterogeneous prefills to the batch max, losing to one
406
- efficient single-sequence prefill per row. The real efficiency lever for
407
- daily use is load-once (the shared runtime above; a persistent-server route
408
- remains open, §9), not batching.
409
-
410
- **Adapter constraint.** `loraState.active` is a single global field read per
411
- forward, so a batch is necessarily single-adapter; `callLocalBatch` is
412
- per-stage and stage→adapter is fixed. The seam must never be shared with a
413
- live server process.
414
-
415
- ## 5. Target design: the BUCKET layer (settled with Josh 2026-07-01, not built)
416
-
417
- **The Wikipedia-editor analogy.** A news story is reported seven times in a
418
- day, each report carrying a little different information; an editor who
419
- heard ALL of them incorporates everything into every article the story
420
- affects. Conversations are the news shows, topics (chunks) are the stories,
421
- and the **bucket is the editor's brain** — where everything reported TODAY
422
- about THAT STORY accumulates before any article is touched.
423
-
424
- **A bucket is keyed by the STORY, not by a subject.** Worked example: the
425
- story "2026 Lincoln Memorial Reflecting Pool controversy" has no article of
426
- its own and may never get one, but it affects three: *Lincoln Memorial
427
- Reflecting Pool*, *Second presidency of Donald Trump*, *John J. Cafaro*. Each
428
- receives the facet relevant to it. Bucket ≠ article is structural: articles
429
- are THINGS, buckets are STORIES, story→things is many-to-many. Buckets are
430
- emergent (never a predefined list) and short-lived relative to articles.
431
-
432
- Target stage order:
433
-
434
- ```
435
- SEGMENT → BUCKET → RESOLVE → SYNTHESIZE (delta-at-once) → RECONCILE → LINK → NORMALIZE → EDITORIAL
436
- ```
437
-
438
- - **BUCKET** — group chunks by story: normalise/compare labels
439
- deterministically first, a binary "same story? yes/no" for near-misses, a
440
- new-bucket proposal for genuinely new stories. `_captured` remains the
441
- catch-all so nothing is dropped.
442
- - **RESOLVE** — per non-empty bucket delta (all new chunks since the last
443
- run, TOGETHER): "which articles does this story affect?" Existing article →
444
- UPDATE (section-route the delta's facet for that article); missing →
445
- CREATE the subject article (a THING, never an article named after the
446
- story). The as-built entity-keyed ROUTE becomes RESOLVE.
447
- - **SYNTHESIZE, one edit per (bucket, article)** — the cardinal rule. Never
448
- patch a section from one chunk and re-patch it from the next five minutes
449
- later: sequential single-chunk edits overwrite each other, churn
450
- citations, and produce patchwork prose. The delta arrives aggregated; the
451
- model rewrites one section once, weaving everything in, resolving
452
- contradictions within the delta toward the latest chunk. Edit mechanics
453
- stay as built (replacement section, code performs the write, same gate).
454
- Two buckets touching the SAME section of one article fold
455
- chronologically; the editorial pass smooths the seam.
456
-
457
- As-built vs target, so nobody re-derives it:
458
-
459
- | Target (2026-07-01) | As built (2026-08-23) |
460
- | --- | --- |
461
- | Story-keyed BUCKET stage between SEGMENT and article fan-out | No bucket stage; `buckets`/`chunk_buckets` hold only `_captured` |
462
- | RESOLVE: bucket delta → affected articles | ROUTE: chunk-entity surfaces → articles (`route.ts`) |
463
- | One edit per (bucket, article) per run | One PATCH per (chunk, section), chronological |
464
- | RECONCILE every night over every article | RECONCILE over articles touched by this run's patches |
465
- | EDITORIAL over touched articles (cadence open) | `wikifyVault` over every article every run |
466
-
467
- ## 6. The read path (design; user-facing details in `docs/reference/memory.md`)
468
-
469
- The read path is deliberately trivial — all the acceptance pressure is on
470
- the write side keeping each article a good, current account. FIND → READ →
471
- ANSWER in small reads, never a context dump: find the one article (name /
472
- alias / category / a `[[link]]` hop), open its TOC, read the ONE relevant
473
- section, answer from the user's recorded position there. Silent-colleague
474
- contract (ported from Lucien): look up before answering; each article is the
475
- consolidated position, don't reconstruct from raw history; speak as a
476
- continuation, never "per the wiki…".
477
-
478
- - Tools (`src/memory/tools.ts`, registered by the shared pi surface for
479
- terminal and web, read-only, auto-allowed): `memory_resolve`,
480
- `memory_category`, `memory_read` (TOC + lead by default; full text only on
481
- request), `memory_section` (the default read), `memory_links`,
482
- `memory_infobox` (readable content, not a query), `memory_list`,
483
- `memory_status`, `memory_search` (last-resort substring fallback). There is
484
- deliberately no infobox-field query tool. mlx-bun's own docs are a
485
- separate `reference_*` surface, never mixed into personal memory.
486
- - Navigation index (`src/memory/query.ts`): mtime-incremental in-memory maps
487
- (alias → stem, category/series/kind/type → stems, infobox, lead, link
488
- graph) mirroring the derived tables; zero embedding calls by contract.
489
- - Exposure: tools and the bundled memory skill appear only when the vault
490
- exists; `memoryIndexHint()` adds a one-line presence hint, never a title
491
- dump. Memory is for personal continuity, not weather, public facts, or
492
- ordinary coding tasks.
493
- - Acceptance budget (the bar Lucien's traces failed at 33–150 KB per query,
494
- one 671-line blob read up to 42× in a query): mean context < 5 KB (8 KB
495
- hard ceiling), no single read > 2 KB, `getEmbedCounter() == 0`, local
496
- only, silent. Harness: `scripts/memory/eval-northstar.ts` over the frozen
497
- `scripts/memory/northstar-queries.json` (Q1–Q6; Q6 is the negative
498
- control), graded by `scripts/memory/judge-answer.ts`; traversal proof
499
- `scripts/memory/north-star-traversal.ts`.
500
-
501
- ## 7. Adapters and training
502
-
503
- One base model for every stage. Per-stage adapters are product assets (the
504
- creator trains them, publishes to Hugging Face, `memory init` may offer to
505
- download); they never get write authority — they produce candidates, the
506
- gates decide.
507
-
508
- | stage string | task | adapter |
509
- | --- | --- | --- |
510
- | `chunk` | one conversation → single-topic chunks + labels | **`memory-chunk` = `e4b-chunk-300` (exists, the only trained adapter)** |
511
- | `entity` | one chunk → the things it is about | base + `Entities.md` (`memory-entity` only on a measured recall miss) |
512
- | `route` | binary "same thing?" / "engages as subject?" | base |
513
- | `section` | binary "does this chunk update THIS section?" / name a new one | base (`memory-section` only if the binary misfires) |
514
- | `synthesis` | draft one section / integrate one chunk into one section / reconcile | base (`memory-synthesis` is the highest-value adapter to train) |
515
- | `editor` | tighten one section / refresh an infobox / summarise a split | base (`memory-editor` if base misfires) |
516
-
517
- Staged LoRA decision, per stage: measure the base + inlined policy on the
518
- stage's own judge first; train only on a measured miss; pick checkpoints by
519
- the task judge, never validation loss. Recipe: `scripts/examples/chunk-finetune.ts`
520
- (sft, rank 16, lr 1e-5, seq 8192, `ops.sdpa`; e4b needs the segmented-backward
521
- path — `SEG=2` as `e4b-chunk-300` was trained; see
522
- `docs/design/orpo-training.md`). Training data uses the
523
- trainer's `messages` row shape with loss masked to the assistant turn.
524
- Section-granular synthesis gold can be mined from Lucien's structured tables
525
- plus `~/Dreaming` git history (chunk identity from `chunks`/`chunk_buckets`/
526
- `synthesized_bucket_chunks`, section before/after from integration commits) —
527
- never from footnote parsing. All training is a user action.
528
-
529
- Recorded chunk-adapter numbers (`reports/orpo-chunk-paper/research-journal.md`,
530
- via `scripts/examples/chunk-eval.ts`): `e4b-chunk-300` purity 92.2 /
531
- cohesion 87.8 vs base e4b 99.5 / 58.8; the e4b metric is purity × cohesion.
532
- The chunk eval score is well-formedness, not accuracy — see the memory note
533
- "chunk-eval 95.10 = format, not accuracy".
534
-
535
- ## 8. Evaluation methodology (beside the system)
536
-
537
- - **Lucien bucket-gold is NOT the write-path oracle.** Its 379-bucket /
538
- 385-article topic-bin taxonomy (245 `X_and_Y` bins, 0 infoboxes) is
539
- exactly what this pipeline replaces; bucket-F1 / Jaccard against it are
540
- routing-instrument numbers, never a pipeline-health gate.
541
- - **Cloud LLM-judge on real output + hand-curated gold.** Quality is judged
542
- by a strong cloud model reading END articles (the article the user reads
543
- next morning, after every stage has run — not intermediate drafts), against
544
- `goldens/dreaming-entities-gold.json` (hand-curated variant groups and
545
- notable entities, grounded by reading `~/Dreaming` and live chunks; NOT
546
- derived from bucket-gold). The judge is never in the hot path.
547
- - **Metrics that mean something:** topic aggregation (many conversations →
548
- one article), coverage (0 engaged-with things lost even as article count
549
- drops), structural invariants (title is a thing, infobox present and
550
- resolvable, footnote bijection, every claim cited), gate pass-rate, and
551
- the read-path byte/embedding budgets. Do not measure articles per
552
- conversation — there is no conv→article link.
553
- - **Embeddings as instruments only.** They measure cohesion/dispersion well
554
- (silhouette ρ≈0.68 vs the LLM judges, per-conversation) and purity poorly
555
- (ρ≈0.32) — so purity rides on the chunker, never on cosine geometry. The
556
- P4 label-proxy routing measured a pessimistic ~39% recall@12 on chunk
557
- labels, which is why ENTITY-EXTRACT reads full chunk text.
558
-
559
- Instruments, all under `scripts/memory/` (moved 2026-08-23; Lucien read-only
560
- throughout):
561
-
562
- | script | what it measures |
563
- | --- | --- |
564
- | `bucket-cohesion-signal.ts` | embedding shortlist recall ceiling chunk→bucket, per bucket-size bin (the bucketing-stage foundation check) |
565
- | `chunk-embedding-signal.ts` · `chunk-judge-correlate.ts` | boundary-local embedding features vs the two LLM chunk judges |
566
- | `eval-name-recall.ts` · `dreaming-lex.ts` | lexical (trigram + token-overlap) shortlist recall over names, no model |
567
- | `eval-route.ts` | no-vector routing proof; `--phase embed` and `--phase route` run as separate processes so the embedder and e4b are never co-resident |
568
- | `eval-entity-extract.ts` | precision/recall/F1 + canonicalisation rate for ENTITY-EXTRACT |
569
- | `eval-section-route.ts` | per-pair accuracy + section-set Jaccard on frozen proxy gold; new-section-not-drop |
570
- | `eval-patch.ts` | only-that-section-changed + self-healing scenarios, judged on output |
571
- | `eval-wikify-split.ts` · `p8-judge-wikify.ts` · `wikify-smoke.ts` | split/series/merge/Talk mechanics; cloud-judge fixture for improve-not-degrade |
572
- | `audit-bootstrap.ts` · `eval-coverage.ts` | structural audit of a bootstrap; migration parity against the notable-entity gold |
573
- | `north-star-traversal.ts` · `eval-northstar.ts` · `judge-answer.ts` · `northstar-queries.json` | read-path proof, acceptance harness, grader |
574
- | `segment-smoke.ts` · `dreaming-create-smoke.ts` · `dreaming-coldstart-smoke.ts` · `dreaming-stages-independent.ts` | wiring smokes (real adapter; one entity; whole DAG; stage independence, model-free) |
575
- | `dreaming-selfheal-demo.ts` | the timestamp-ordered self-healing demonstration |
576
- | `dreaming-full-run.ts` · `dreaming-slice-select.ts` · `dreaming-slice-run.ts` · `dreaming-slice-inventory.ts` · `dreaming-chunk-diag.ts` | the resumable full-corpus import driver (user-launched, writes `~/.mlx-bun/wiki-full`, cursor `~/.mlx-bun/full-run-cursor.txt`) and its slice tools |
577
- | `mine-gold-entities.ts` | the frozen entity vocabulary (`goldens/entities.json`) from `~/Dreaming` titles/lead bolds/bucket names |
578
- | `eval-pi-memory-fixation.ts` | the pi surface exposes memory only when enabled and names the negative cases |
579
-
580
- **Contradiction with the no-embeddings principle, recorded rather than
581
- hidden:** `wikify.ts sectionCohesion` (injected `EmbedFn`), the
582
- `bucket-cohesion-signal` / `chunk-embedding-signal` / `chunk-judge-correlate`
583
- scripts and `eval-route.ts --phase embed` still use an embedder. None of them
584
- is on the pipeline or read path (`src/memory/` never imports `src/embed.ts`;
585
- the tripwire asserts 0). The design rule as settled 2026-07-01 says "no
586
- embeddings anywhere in the project"; the code keeps them as offline
587
- instruments. Deleting them is an open decision (§9), not a silent rewrite.
588
-
589
- ## 9. Open work (verified against `src/memory/` 2026-08-23)
590
-
591
- Ordered. None of it touches the user's real vault (`~/.mlx-bun/wiki`) without
592
- the promotion step.
593
-
594
- 1. **Wire ingest into the nightly run.** `ingestSessions` has no caller
595
- outside tests; `runSynthesis` assumes the corpus is already in the store.
596
- Without this the launchd job cannot fold in new pi sessions. Sequence:
597
- ingest → the existing DAG; watermark per source already exists.
598
- 2. **Bucket layer** (§5): story-keyed BUCKET stage, RESOLVE, delta-at-once
599
- synthesis replacing the per-chunk patch loop (not wrapping it). The
600
- `buckets`/`chunk_buckets` tables already exist.
601
- 3. **Nightly DAG order**: RECONCILE over every article (today: touched
602
- stems only) and a single NORMALIZE/EDITORIAL closing pass in the settled
603
- order.
604
- 4. **Persistent-server inference routing**: route memory generation through
605
- the resident server when one is running (load-once for daily use), with
606
- the in-process runtime as the no-server fallback. Batching is not the
607
- lever (§4).
608
- 5. **Chunk user-turn drift**: `CHUNK_PROMPT` still differs from the trained
609
- user turn (an added no-copy line; 2 inlined Meta pages vs 8 in training;
610
- abstracted label examples; the training vault-path line). Either
611
- reconcile the prompt to training or retrain `e4b-chunk-300` on the live
612
- prompt — pick one, don't stay half-aligned. Re-segmenting conversations
613
- chunked under the old user-only template is principled but low-urgency
614
- (old output was valid in-range).
615
- 6. **Promote + schedule**: after the import (`~/.mlx-bun/wiki-full`) is
616
- judged good on a broad, diverse cloud-judged sample — `reindex`,
617
- `mlx-bun memory link`, browse in Obsidian — point `~/.mlx-bun/wiki` at
618
- it and enable the nightly job. The `Reference/` symlinks into the repo
619
- are non-portable; drop them for the real personal vault.
620
- 7. **Known quality fixes**: schematic-prompt leaks (<1% of articles), run-on
621
- leads, `owned:` framing on abstract concepts (reframe the lead spec per
622
- subject kind), and stale in-code comments that still describe the dead
623
- "≥3 chunks or owned/decided" CREATE rule (`synthesize.ts` header;
624
- `prompts.ts` M1 stub constants) — the live rule is
625
- `RECURRENCE_THRESHOLD = 2` in `route.ts`.
626
- 8. **Per-stage adapters** (§7), each a user-launched training run gated on a
627
- measured base miss: `memory-synthesis` first (RECONCILE logs
628
- "UNRESOLVED … a memory-synthesis LoRA would close it" when the base model
629
- leaves a stale present-tense assertion), then section, entity, editor.
630
- Prerequisite: give `chunk-finetune.ts` a `TASK` selector defaulting
631
- DATA/ADAPTER per stage and an e4b (not MiniCPM5) default model.
632
- 9. **Embedding residue** (§8): decide whether `sectionCohesion` and the
633
- embedding signal scripts stay as instruments or go.
634
- 10. **Jobs-runner integration**: move `memory synthesize` onto the jobs
635
- runner with SSE progress once manual synthesis is boring.
636
-
637
- ## 10. Decisions overridden (explicit, so no agent re-derives them)
638
-
639
- | Earlier statement | Superseded by |
640
- | --- | --- |
641
- | Personal-notability checklist; CREATE gate "≥3 chunks OR owned/decided, else PARK as trivia"; ≤40-article first-run cap (master plan P1-T5, P5-T4, R5, P9-T3) | **No notability filter.** Everything surfaces; `_captured` keeps the tail searchable; recurrence (2 chunks) or subject engagement earns an article; thin subjects → stubs. |
642
- | Buckets demoted to "optional staging, may ship empty" (master plan L4, write-pipeline-entity) | **Buckets are first-class** story-keyed accumulators between chunks and articles (§5). |
643
- | Embeddings as routing narrower / offline instruments (bucketing-stage, memory-synthesis section-routing, master plan P4/P8-T4) | **No embeddings in the pipeline**; the tripwire is permanent. Residual instruments are catalogued in §8 pending deletion. |
644
- | Routing / section-route acceptance gated on Lucien bucket-F1 / Jaccard (P4-T2, P7-T1) | Model-selection evals live outside the design; pipeline health is judged on real END output by a cloud judge, never Lucien's bin taxonomy. |
645
- | Cross-linking + infobox work assigned to periodic WIKIFY (P8) | LINK and RECONCILE are nightly stages; wikify is the readability pass. |
646
- | Whole-article synthesis (Lucien `synthesize-update`) and per-chunk sequential patches (as built) | One replacement section per (bucket, article) per run, code performs the write (§5). |
647
- | Per-stage `maxTokens` caps 4/16/128/2048 (inference-path design) | One `MAX_OUTPUT_TOKENS` backstop; never cap below it. |
648
- | Batching as the import throughput lever | Measured slower for the real workload; default serial; load-once is the lever. |
649
- | Turso / vector-capable store evaluation | Moot without embeddings; bun:sqlite stays. |
650
-
651
- ## 11. Open questions
652
-
653
- - **When does a `_captured` chunk graduate?** Re-scan `_captured` nightly for
654
- subjects that have since accumulated related chunks, or only when a new
655
- bucket's name matches? (Today: promotion happens when ROUTE recomputes and
656
- the subject recurs.)
657
- - **Editorial cadence.** Every night over every article (as built), or
658
- touched articles nightly plus a slower full-vault sweep?
659
- - **Provisional / temporal facts.** A convention (e.g. "as of YYYY-MM" tied
660
- to the citation date) so "work set to begin July" updates cleanly to
661
- "began / completed" rather than contradicting.
662
- - **Domain vs specific granularity.** ENTITY-EXTRACT emits both; the
663
- summary-style split decides what becomes its own page. Is that enough?
664
- - **Bootstrap on a stronger model?** Is first creation good enough locally,
665
- or is the one-time import the one place a stronger model earns its cost?
666
-
667
- ## History
668
-
669
- - 2026-06-19 — M0 landed: vault, read tools, CLI, launchd scheduling
670
- (`docs/design/dreaming-nightly-pipeline.md`); synthesis a safe no-op stub.
671
- - 2026-06-26 — M1 design (`docs/design/dreaming-nightly-pipeline.md`): pointer DB, create/update
672
- split, wikify as its own node; bucketing decomposition
673
- (`docs/design/dreaming-nightly-pipeline.md`); entity-keyed routing (`docs/design/dreaming-nightly-pipeline.md`).
674
- - 2026-06-28 — Pipeline built end-to-end on real data; stage workers,
675
- chronological order, self-healing, LINK stage, templating fix; batching
676
- measured and shelved (`docs/design/dreaming-nightly-pipeline.md`); full import resumed
677
- from 720/2096 into `~/.mlx-bun/wiki-full`.
678
- - 2026-07-01 — Settled with Josh: no notability filter, no embeddings,
679
- buckets are stories, one edit per (bucket, article), replacement-section
680
- edit mechanics; `MLX_BUN_MEMORY_BATCH` default 1. This doc became
681
- canonical.
682
- - 2026-08-23 — Consolidated the source docs into this one; scripts moved to
683
- `scripts/memory/`; every code claim re-verified; ingest-not-wired and
684
- embedding-residue contradictions recorded.