athanor 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 (230) hide show
  1. package/AGENTS.md +201 -0
  2. package/LICENSE +201 -0
  3. package/README.md +627 -0
  4. package/bin/athanor +2 -0
  5. package/dist/adapters/__fixtures.d.ts +4 -0
  6. package/dist/adapters/__fixtures.d.ts.map +1 -0
  7. package/dist/adapters/__fixtures.js +29 -0
  8. package/dist/adapters/__fixtures.js.map +1 -0
  9. package/dist/adapters/health.d.ts +9 -0
  10. package/dist/adapters/health.d.ts.map +1 -0
  11. package/dist/adapters/health.js +44 -0
  12. package/dist/adapters/health.js.map +1 -0
  13. package/dist/adapters/index.d.ts +13 -0
  14. package/dist/adapters/index.d.ts.map +1 -0
  15. package/dist/adapters/index.js +59 -0
  16. package/dist/adapters/index.js.map +1 -0
  17. package/dist/adapters/llama.d.ts +10 -0
  18. package/dist/adapters/llama.d.ts.map +1 -0
  19. package/dist/adapters/llama.js +28 -0
  20. package/dist/adapters/llama.js.map +1 -0
  21. package/dist/adapters/mlx.d.ts +11 -0
  22. package/dist/adapters/mlx.d.ts.map +1 -0
  23. package/dist/adapters/mlx.js +54 -0
  24. package/dist/adapters/mlx.js.map +1 -0
  25. package/dist/app/models.d.ts +22 -0
  26. package/dist/app/models.d.ts.map +1 -0
  27. package/dist/app/models.js +81 -0
  28. package/dist/app/models.js.map +1 -0
  29. package/dist/cli/commands.d.ts +6 -0
  30. package/dist/cli/commands.d.ts.map +1 -0
  31. package/dist/cli/commands.js +50 -0
  32. package/dist/cli/commands.js.map +1 -0
  33. package/dist/cli/doctor.d.ts +2 -0
  34. package/dist/cli/doctor.d.ts.map +1 -0
  35. package/dist/cli/doctor.js +16 -0
  36. package/dist/cli/doctor.js.map +1 -0
  37. package/dist/cli/format.d.ts +6 -0
  38. package/dist/cli/format.d.ts.map +1 -0
  39. package/dist/cli/format.js +59 -0
  40. package/dist/cli/format.js.map +1 -0
  41. package/dist/cli/index.d.ts +2 -0
  42. package/dist/cli/index.d.ts.map +1 -0
  43. package/dist/cli/index.js +214 -0
  44. package/dist/cli/index.js.map +1 -0
  45. package/dist/cli/model-commands.d.ts +13 -0
  46. package/dist/cli/model-commands.d.ts.map +1 -0
  47. package/dist/cli/model-commands.js +201 -0
  48. package/dist/cli/model-commands.js.map +1 -0
  49. package/dist/cli/preset-commands.d.ts +7 -0
  50. package/dist/cli/preset-commands.d.ts.map +1 -0
  51. package/dist/cli/preset-commands.js +78 -0
  52. package/dist/cli/preset-commands.js.map +1 -0
  53. package/dist/cli/pull-renderer.d.ts +7 -0
  54. package/dist/cli/pull-renderer.d.ts.map +1 -0
  55. package/dist/cli/pull-renderer.js +109 -0
  56. package/dist/cli/pull-renderer.js.map +1 -0
  57. package/dist/cli/shared.d.ts +6 -0
  58. package/dist/cli/shared.d.ts.map +1 -0
  59. package/dist/cli/shared.js +7 -0
  60. package/dist/cli/shared.js.map +1 -0
  61. package/dist/cli/style.d.ts +29 -0
  62. package/dist/cli/style.d.ts.map +1 -0
  63. package/dist/cli/style.js +63 -0
  64. package/dist/cli/style.js.map +1 -0
  65. package/dist/cli/system-commands.d.ts +16 -0
  66. package/dist/cli/system-commands.d.ts.map +1 -0
  67. package/dist/cli/system-commands.js +109 -0
  68. package/dist/cli/system-commands.js.map +1 -0
  69. package/dist/config/index.d.ts +52 -0
  70. package/dist/config/index.d.ts.map +1 -0
  71. package/dist/config/index.js +223 -0
  72. package/dist/config/index.js.map +1 -0
  73. package/dist/control/server.d.ts +4 -0
  74. package/dist/control/server.d.ts.map +1 -0
  75. package/dist/control/server.js +84 -0
  76. package/dist/control/server.js.map +1 -0
  77. package/dist/discovery/ingest.d.ts +8 -0
  78. package/dist/discovery/ingest.d.ts.map +1 -0
  79. package/dist/discovery/ingest.js +18 -0
  80. package/dist/discovery/ingest.js.map +1 -0
  81. package/dist/discovery/scanner.d.ts +8 -0
  82. package/dist/discovery/scanner.d.ts.map +1 -0
  83. package/dist/discovery/scanner.js +261 -0
  84. package/dist/discovery/scanner.js.map +1 -0
  85. package/dist/discovery/watcher.d.ts +15 -0
  86. package/dist/discovery/watcher.d.ts.map +1 -0
  87. package/dist/discovery/watcher.js +71 -0
  88. package/dist/discovery/watcher.js.map +1 -0
  89. package/dist/index.d.ts +3 -0
  90. package/dist/index.d.ts.map +1 -0
  91. package/dist/index.js +67 -0
  92. package/dist/index.js.map +1 -0
  93. package/dist/presets/edit.d.ts +14 -0
  94. package/dist/presets/edit.d.ts.map +1 -0
  95. package/dist/presets/edit.js +105 -0
  96. package/dist/presets/edit.js.map +1 -0
  97. package/dist/presets/recipes.d.ts +12 -0
  98. package/dist/presets/recipes.d.ts.map +1 -0
  99. package/dist/presets/recipes.js +91 -0
  100. package/dist/presets/recipes.js.map +1 -0
  101. package/dist/pull/api.d.ts +14 -0
  102. package/dist/pull/api.d.ts.map +1 -0
  103. package/dist/pull/api.js +29 -0
  104. package/dist/pull/api.js.map +1 -0
  105. package/dist/pull/download.d.ts +46 -0
  106. package/dist/pull/download.d.ts.map +1 -0
  107. package/dist/pull/download.js +133 -0
  108. package/dist/pull/download.js.map +1 -0
  109. package/dist/pull/hf.d.ts +16 -0
  110. package/dist/pull/hf.d.ts.map +1 -0
  111. package/dist/pull/hf.js +50 -0
  112. package/dist/pull/hf.js.map +1 -0
  113. package/dist/pull/hf_pull.py +137 -0
  114. package/dist/pull/resolve-python.d.ts +11 -0
  115. package/dist/pull/resolve-python.d.ts.map +1 -0
  116. package/dist/pull/resolve-python.js +81 -0
  117. package/dist/pull/resolve-python.js.map +1 -0
  118. package/dist/pull/suggestions.d.ts +11 -0
  119. package/dist/pull/suggestions.d.ts.map +1 -0
  120. package/dist/pull/suggestions.js +24 -0
  121. package/dist/pull/suggestions.js.map +1 -0
  122. package/dist/registry/index.d.ts +28 -0
  123. package/dist/registry/index.d.ts.map +1 -0
  124. package/dist/registry/index.js +125 -0
  125. package/dist/registry/index.js.map +1 -0
  126. package/dist/registry/materialize.d.ts +19 -0
  127. package/dist/registry/materialize.d.ts.map +1 -0
  128. package/dist/registry/materialize.js +96 -0
  129. package/dist/registry/materialize.js.map +1 -0
  130. package/dist/registry/sort.d.ts +4 -0
  131. package/dist/registry/sort.d.ts.map +1 -0
  132. package/dist/registry/sort.js +20 -0
  133. package/dist/registry/sort.js.map +1 -0
  134. package/dist/router/server.d.ts +10 -0
  135. package/dist/router/server.d.ts.map +1 -0
  136. package/dist/router/server.js +158 -0
  137. package/dist/router/server.js.map +1 -0
  138. package/dist/search/format.d.ts +6 -0
  139. package/dist/search/format.d.ts.map +1 -0
  140. package/dist/search/format.js +62 -0
  141. package/dist/search/format.js.map +1 -0
  142. package/dist/search/hf.d.ts +39 -0
  143. package/dist/search/hf.d.ts.map +1 -0
  144. package/dist/search/hf.js +242 -0
  145. package/dist/search/hf.js.map +1 -0
  146. package/dist/supervisor/index.d.ts +18 -0
  147. package/dist/supervisor/index.d.ts.map +1 -0
  148. package/dist/supervisor/index.js +149 -0
  149. package/dist/supervisor/index.js.map +1 -0
  150. package/dist/supervisor/inflight.d.ts +6 -0
  151. package/dist/supervisor/inflight.d.ts.map +1 -0
  152. package/dist/supervisor/inflight.js +66 -0
  153. package/dist/supervisor/inflight.js.map +1 -0
  154. package/dist/supervisor/logs.d.ts +7 -0
  155. package/dist/supervisor/logs.d.ts.map +1 -0
  156. package/dist/supervisor/logs.js +31 -0
  157. package/dist/supervisor/logs.js.map +1 -0
  158. package/dist/supervisor/metrics.d.ts +26 -0
  159. package/dist/supervisor/metrics.d.ts.map +1 -0
  160. package/dist/supervisor/metrics.js +156 -0
  161. package/dist/supervisor/metrics.js.map +1 -0
  162. package/dist/supervisor/policies.d.ts +6 -0
  163. package/dist/supervisor/policies.d.ts.map +1 -0
  164. package/dist/supervisor/policies.js +17 -0
  165. package/dist/supervisor/policies.js.map +1 -0
  166. package/dist/supervisor/state.d.ts +5 -0
  167. package/dist/supervisor/state.d.ts.map +1 -0
  168. package/dist/supervisor/state.js +34 -0
  169. package/dist/supervisor/state.js.map +1 -0
  170. package/dist/sync/pi.d.ts +15 -0
  171. package/dist/sync/pi.d.ts.map +1 -0
  172. package/dist/sync/pi.js +228 -0
  173. package/dist/sync/pi.js.map +1 -0
  174. package/dist/types/index.d.ts +87 -0
  175. package/dist/types/index.d.ts.map +1 -0
  176. package/dist/types/index.js +2 -0
  177. package/dist/types/index.js.map +1 -0
  178. package/dist/ui/App.d.ts +7 -0
  179. package/dist/ui/App.d.ts.map +1 -0
  180. package/dist/ui/App.js +218 -0
  181. package/dist/ui/App.js.map +1 -0
  182. package/dist/ui/Banner.d.ts +9 -0
  183. package/dist/ui/Banner.d.ts.map +1 -0
  184. package/dist/ui/Banner.js +58 -0
  185. package/dist/ui/Banner.js.map +1 -0
  186. package/dist/ui/LogFocus.d.ts +13 -0
  187. package/dist/ui/LogFocus.d.ts.map +1 -0
  188. package/dist/ui/LogFocus.js +92 -0
  189. package/dist/ui/LogFocus.js.map +1 -0
  190. package/dist/ui/LogTail.d.ts +7 -0
  191. package/dist/ui/LogTail.d.ts.map +1 -0
  192. package/dist/ui/LogTail.js +22 -0
  193. package/dist/ui/LogTail.js.map +1 -0
  194. package/dist/ui/ModelList.d.ts +16 -0
  195. package/dist/ui/ModelList.d.ts.map +1 -0
  196. package/dist/ui/ModelList.js +91 -0
  197. package/dist/ui/ModelList.js.map +1 -0
  198. package/dist/ui/PresetEditor.d.ts +7 -0
  199. package/dist/ui/PresetEditor.d.ts.map +1 -0
  200. package/dist/ui/PresetEditor.js +149 -0
  201. package/dist/ui/PresetEditor.js.map +1 -0
  202. package/dist/ui/PullModal.d.ts +9 -0
  203. package/dist/ui/PullModal.d.ts.map +1 -0
  204. package/dist/ui/PullModal.js +139 -0
  205. package/dist/ui/PullModal.js.map +1 -0
  206. package/dist/ui/SearchBrowser.d.ts +11 -0
  207. package/dist/ui/SearchBrowser.d.ts.map +1 -0
  208. package/dist/ui/SearchBrowser.js +433 -0
  209. package/dist/ui/SearchBrowser.js.map +1 -0
  210. package/dist/ui/Suggestions.d.ts +6 -0
  211. package/dist/ui/Suggestions.d.ts.map +1 -0
  212. package/dist/ui/Suggestions.js +10 -0
  213. package/dist/ui/Suggestions.js.map +1 -0
  214. package/dist/ui/useAppData.d.ts +17 -0
  215. package/dist/ui/useAppData.d.ts.map +1 -0
  216. package/dist/ui/useAppData.js +47 -0
  217. package/dist/ui/useAppData.js.map +1 -0
  218. package/dist/ui/useAppInput.d.ts +33 -0
  219. package/dist/ui/useAppInput.d.ts.map +1 -0
  220. package/dist/ui/useAppInput.js +128 -0
  221. package/dist/ui/useAppInput.js.map +1 -0
  222. package/dist/ui/useModelActions.d.ts +18 -0
  223. package/dist/ui/useModelActions.d.ts.map +1 -0
  224. package/dist/ui/useModelActions.js +78 -0
  225. package/dist/ui/useModelActions.js.map +1 -0
  226. package/dist/ui/useMouseWheel.d.ts +19 -0
  227. package/dist/ui/useMouseWheel.d.ts.map +1 -0
  228. package/dist/ui/useMouseWheel.js +92 -0
  229. package/dist/ui/useMouseWheel.js.map +1 -0
  230. package/package.json +53 -0
package/AGENTS.md ADDED
@@ -0,0 +1,201 @@
1
+ # AGENTS.md
2
+
3
+ Orientation for contributors and AI agents working on athanor. Read this before making changes; the invariants below are not negotiable without an explicit user decision.
4
+
5
+ ## What athanor is
6
+
7
+ Athanor — personal LLM alchemy on Apple Silicon. It scans the Hugging Face cache, registers MLX and `llama.cpp` (GGUF) models in `~/.athanor/models.json`, assigns each one a **stable port**, supervises detached child processes, and exposes models to [pi-agent](https://github.com/badlogic/pi-mono) as one custom provider per model. Surfaces are an Ink TUI (`athanor`) and a hand-rolled CLI (`athanor <cmd>`).
8
+
9
+ Not a library. Not a daemon. No network listeners except the runtime children themselves (and an optional local control API, off by default).
10
+
11
+ ## Invariants
12
+
13
+ These are load-bearing. If a change seems to need to break one, stop and ask.
14
+
15
+ 1. **Stable port per model.** Ports are allocated on first discovery from `config.portRange` and persisted on the registry entry forever. A model's port never changes behind the user's back; pi-agent provider URLs must be stable across restarts.
16
+ 2. **Atomic registry writes.** `~/.athanor/models.json` is always written via temp-file + rename in `src/registry/index.ts`. Never partial-write it, never keep it open across awaits.
17
+ 3. **Preserve non-athanor pi entries.** `src/sync/pi.ts` rewrites only providers whose name starts with `athanor-`. Everything else in `~/.pi/agent/models.json` (OpenAI, Anthropic, Ollama, OpenRouter, user customs) must round-trip untouched. Same for `~/.pi/agent/settings.json` — only `defaultProvider` / `defaultModel` are touched, and only when a model is started as the active default.
18
+ 4. **Pi sync shape follows `config.router.enabled`.** Default (router off): each exposed athanor model becomes its own pi provider `athanor-<runtime>-<slug>` with one `baseUrl` per model. Router on: up to two aggregator providers — `athanor-mlx` and `athanor-llama` — both pointing at the router `baseUrl`, each listing only models of its runtime and carrying runtime-specific compat flags (MLX sets `supportsDeveloperRole: false`; llama-server doesn't). A provider with zero exposed members is suppressed. Never emit both shapes. The CLI verbs are `expose` / `hide`; the underlying registry field is `publish: boolean` (storage name, kept stable for backward-compat of on-disk `models.json`).
19
+ 5. **Runtime model id matches launch argument literally.** `mlx_lm.server` compares the request's `model` field to whatever was passed as `--model` and falls back to a HuggingFace network lookup on mismatch. The pi model `id` we emit must equal the adapter's `--model` (or `--alias` for `llama-server`). See `src/sync/pi.ts` and `src/adapters/*.ts`.
20
+ 6. **Pi context metadata reflects effective served context.** `src/sync/pi.ts` must advertise the model's effective runtime context window from merged runtime config (`mergedConfigFor(entry)`), not only explicit per-model preset fields and not the model's theoretical maximum. pi should see what athanor will actually serve.
21
+ 7. **MLX capability detection and flavor routing are separate axes.** Two fields live on an MLX entry:
22
+ - `mlxCapabilities: ("vlm")[]` — a detected *fact* about the model (does config.json advertise a vision tower?). Refreshed by `ingestDiscovered` and `pull` via `detectMlxCapabilities()` in `src/discovery/scanner.ts`. Safe to overwrite on re-scan.
23
+ - `mlxFlavor: "lm" | "vlm"` — user *intent* about which server binary to launch. `"vlm"` routes to `mlx_vlm.server`; `"lm"` (or absent) routes to `mlx_lm.server`. Only set by `athanor flavor <slug> lm|vlm` (`cmdFlavor` in `src/cli/commands.ts`). Discovery and ingest must never touch it.
24
+
25
+ Detection is advisory because many VLM-tagged repos run fine as text-only under `mlx_lm.server` with no torch/torchvision installed, and that's usually the preferred path. `cmdShow` surfaces the capability with a hint that points at `athanor flavor`. Do not add VLM detection anywhere other than `detectMlxCapabilities`; keep it a single source of truth.
26
+ 8. **Supervisor default policy is `single-active`.** Starting model B stops model A unless the user opts into `multi-active-lru` (or `manual`) in `config.json`. Policies live in `src/supervisor/policies.ts`.
27
+ 9. **Presets are additive, scans are non-destructive.** `athanor scan` refreshes `path`, `sizeBytes`, and `mlxCapabilities`. `preset`, `publish`, `piAlias`, `tags`, `port`, `slug`, and `mlxFlavor` must survive re-scans. Built-in recipes are explicit presets; `balanced` is not shorthand for clearing a preset, and `preset clear` is the separate remove action.
28
+ 10. **All mutations go through helpers.** Use `setPresetFields` / `unsetPresetFields` / `recipeToPreset` from `src/presets/edit.ts` and `updateModel` from `src/registry/index.ts`. Do not hand-edit registry objects in commands or UI components.
29
+
30
+ ## Layout
31
+
32
+ ```
33
+ src/
34
+ adapters/ # mlx_lm + mlx_vlm + llama-server command builders, health probes
35
+ cli/ # dispatcher (index.ts), commands.ts, doctor, formatting
36
+ config/ # config load + defaults
37
+ control/ # optional HTTP control API (opt-in)
38
+ discovery/ # HF cache scanner + ingest + fs.watch watcher; detectMlxCapabilities lives here
39
+ presets/ # preset merge, tunable-key metadata, recipes
40
+ pull/ # HF repo inspection + `hf` download wrapper
41
+ registry/ # atomic models.json CRUD, slug + port allocation
42
+ router/ # optional OpenAI-compatible proxy (opt-in, single port)
43
+ search/ # HF Hub search + trending
44
+ supervisor/ # detached process lifecycle, policy, reattach, logs
45
+ sync/ # namespaced pi-agent catalog merge
46
+ ui/ # Ink TUI: App, ModelList, LogTail, PullModal, PresetEditor
47
+ types/ # shared types (ModelEntry, DiscoveredModel, etc.)
48
+ test/setup.ts # redirects ATHANOR_HOME and PI_HOME to a tmp dir per run
49
+ ```
50
+
51
+ Entry points: `bin/athanor` → `dist/index.js` (built) or `npm start` (tsx) → `src/index.tsx`, which dispatches to TUI or `src/cli/index.ts` based on argv.
52
+
53
+ ## Context files
54
+
55
+ Keep reusable architecture context under `context/`.
56
+
57
+ - `context/ARCH_MAP.md` — compressed architecture map for routine work
58
+ - `context/ARCH_REVIEW.md` — deeper review notes, findings, and phased plan
59
+
60
+ Context discipline:
61
+ - consult `context/ARCH_MAP.md` first for normal coding tasks
62
+ - avoid re-reading the entire repository unless the task is cross-cutting, the map is stale, or the user asks for a fresh architectural review
63
+ - prefer incremental context: changed files, directly related modules, and affected invariants
64
+ - after meaningful architectural refactors, update the relevant file(s) under `context/`
65
+
66
+ ## Development
67
+
68
+ ```bash
69
+ npm install
70
+ npx tsc --noEmit # typecheck — must be clean
71
+ npm run test:run # vitest run, one shot
72
+ npm test # vitest in watch mode
73
+ npm run build # tsc -> dist/
74
+ ```
75
+
76
+ Tests set `ATHANOR_HOME` and `PI_HOME` to a per-run temp directory via `test/setup.ts`. Running the suite never touches the user's real config. Any new test that reads config must rely on these env vars, not on hardcoded paths.
77
+
78
+ Before sending a change:
79
+
80
+ 1. `npx tsc --noEmit` clean.
81
+ 2. `npm run test:run` green.
82
+ 3. If you added a new command or TUI key, update `README.md` (CLI reference / TUI bindings tables) in the same change.
83
+ 4. If you touched an invariant above, flag it explicitly in the PR description.
84
+
85
+ ## Onboarding a user
86
+
87
+ When a user opens this repo with an agent and asks to "set up athanor", work in this order. Nothing below requires edits to tracked files — it's all install, profile, pick, pull, start.
88
+
89
+ ### CLI install modes
90
+
91
+ `bin/athanor` resolves `../src/index.js` (the compiled entry), so the binary only works after a build. Pick one:
92
+
93
+ | Mode | Setup | Invocation |
94
+ |---|---|---|
95
+ | from source, no build | `npm install` | `npm start -- <cmd>` (the `--` forwards args to tsx) |
96
+ | linked global | `npm install && npm run build && npm link` | `athanor <cmd>` from anywhere |
97
+ | project-local | `npm install && npm run build` | `./bin/athanor <cmd>` or `npx athanor <cmd>` |
98
+
99
+ Linked mode does not auto-rebuild. Re-run `npm run build` after pulling changes or switch to `npm start` for the dev loop.
100
+
101
+ ### External binaries
102
+
103
+ Run `athanor doctor` first — it prints presence and paths for each dependency and is the source of truth:
104
+
105
+ - `mlx_lm.server` — required for MLX text models. `uv tool install mlx-lm` (or `pipx install mlx-lm`).
106
+ - `mlx_vlm.server` — optional, for vision MLX models. `uv tool install mlx-vlm --with torch --with torchvision`. The torch/torchvision extras are load-bearing: `mlx-vlm` itself doesn't depend on them, but the `transformers` VLM processors it imports do, so installing `mlx-vlm` alone passes `athanor doctor` and then fails at request time with `Qwen3VLVideoProcessor requires the PyTorch library but it was not found in your environment`. Equivalent forms: `pipx install mlx-vlm && pipx inject mlx-vlm torch torchvision`, or `pip install -U mlx-vlm torch torchvision` in an active venv.
107
+ - `llama-server` — optional, for GGUF models. `brew install llama.cpp` or build from source.
108
+ - `hf` — required for `athanor pull`. `uv tool install huggingface_hub --with hf_transfer` (or `pip install -U huggingface_hub[cli]`).
109
+
110
+ `athanor pull` refuses when `hf` is missing; `athanor start` refuses when the target runtime binary is missing. Neither condition is a reason to edit code — surface the missing tool to the user.
111
+
112
+ ### Profiling the host
113
+
114
+ Before suggesting a model, confirm Apple Silicon and read the memory ceiling. The signals an agent should gather:
115
+
116
+ | Signal | Where |
117
+ |---|---|
118
+ | CPU architecture | `uname -m` — must be `arm64` |
119
+ | Chip model | `sysctl -n machdep.cpu.brand_string` |
120
+ | Unified memory total | `sysctl -n hw.memsize` (bytes); `os.totalmem()` agrees |
121
+ | Memory actually used | `vm_stat` parsed by `parseVmStat` in `src/supervisor/metrics.ts` — `(active + wired + compressor) × pagesize`. Inactive and speculative pages are reclaimable cache, not used. |
122
+ | HF cache footprint | `du -sh ~/.cache/huggingface/hub` |
123
+ | Registry state | `athanor ls` — when empty it prints curated suggestions sized by segment |
124
+
125
+ Rule of thumb for 4-bit MLX quants: weights occupy roughly **0.6 GB per billion parameters**, KV cache and context add 1–3 GB, and macOS plus the user's other apps want 6–8 GB. Practical budget: 8 GB Macs → stop at 4B-4bit; 16 GB → 9B-4bit; 32 GB+ → 27B-4bit is comfortable. Never recommend a quant whose on-disk size exceeds `totalMemBytes − currentUsed − 8 GB`.
126
+
127
+ ### Finding models on Hugging Face
128
+
129
+ Three ordered sources, cheapest first:
130
+
131
+ 1. **Curated suggestions** — `src/pull/suggestions.ts`. Surfaced automatically by `athanor ls` and the TUI empty state. Safe defaults for 8/16/32 GB Macs. Start here unless the user has a specific model in mind.
132
+ 2. **`athanor search <query>`** — groups results into MLX / GGUF / other. `--mlx` and `--gguf` narrow the filter; `--author mlx-community`, `--sort downloads|likes|trending|modified`, and `--limit N` refine further. `athanor trending` is shorthand for `--sort trending`. Rows carry download count, likes, license, and last-modified — weight those over raw likes when judging a repo.
133
+ 3. **Direct pull** — `athanor pull <repo>` for an MLX repo, `athanor pull <repo> --file F.gguf` for a specific GGUF file.
134
+
135
+ Quantization reading:
136
+
137
+ - **MLX:** prefer `mlx-community/*` — they carry the right conversion manifest. Suffix `-4bit` is the default; `-6bit` / `-8bit` cost ~1.5×/2× disk and memory for modest quality gains; `-bf16` is rarely worth it for serving on a Mac.
138
+ - **GGUF:** `Q4_K_M` is the balanced default, `Q5_K_M` / `Q6_K` trade size for quality, `Q8_0` is near-lossless but large. Avoid `Q2_*` and `Q3_*` except on tight memory.
139
+
140
+ After pull, `athanor show <slug>` shows detected capabilities, resolved launch command, and merged preset. For MLX entries where `caps` includes `vlm`, only flip `athanor flavor <slug> vlm` if the user actually needs image input — most VLM repos serve text fine under `mlx_lm.server` without the torch install (see invariant #6).
141
+
142
+ ### Running a model
143
+
144
+ End-to-end operator flow once a model is in the registry (pulled or scanned):
145
+
146
+ | Step | Command | Notes |
147
+ |---|---|---|
148
+ | refresh cache | `athanor scan` | idempotent; picks up anything downloaded outside `athanor pull`, e.g. via `hf download` directly |
149
+ | list | `athanor ls` | empty ⇒ curated suggestions; otherwise shows slug, runtime, port, publish state, running state |
150
+ | inspect | `athanor show <slug>` | detected capabilities, resolved launch command, merged preset, current status |
151
+ | start | `athanor start <slug>` | spawns a detached child on the entry's stable port; default policy (`single-active`) stops any currently-running model first |
152
+ | tail logs | `athanor logs <slug> -n 500` | prints the last N lines from `~/.athanor/logs/<slug>-<pid>.log`; for live follow use the TUI |
153
+ | verify endpoint | `curl localhost:<port>/v1/models` | OpenAI-compatible; port is printed by `ls` / `show` / `status` |
154
+ | runtime status | `athanor status` | pid, cpu, rss, tok/s across all running instances |
155
+ | stop | `athanor stop <slug>` | graceful SIGTERM; if the router is on, any in-flight stream drains up to `config.router.drainTimeoutMs` (30s default) first |
156
+ | restart | `athanor restart <slug>` | stop + start; useful after `athanor preset set` changes |
157
+
158
+ Bare `athanor` (no args) opens the Ink TUI with the same surface. When the registry is empty, the TUI's start screen lists the curated suggestions from `src/pull/suggestions.ts`; pressing `Enter` pulls the selected one inline. Once models exist: `p` pulls, `s` scans, `Enter` toggles start/stop, `tab` hides the selector to scroll logs with `↑ ↓ / page up/down / mouse wheel`, `q` exits.
159
+
160
+ To make a running model available to `pi-agent` downstream, `athanor expose <slug>` flips its `publish` field and runs a namespaced merge into `~/.pi/agent/models.json` (see invariant #3 and #4). `athanor hide <slug>` reverses it. `athanor sync` re-emits the namespace without changing publish state — useful after upgrading athanor or toggling `config.router.enabled`.
161
+
162
+ ## How to add things
163
+
164
+ - **New adapter (runtime).** Add a file in `src/adapters/`, export `buildCommand(entry, config): { cmd, args }` and a health probe. Register it in `src/adapters/index.ts`. Add a fixture to `__fixtures.ts` and a test alongside.
165
+ - **New CLI command.** Implement it in the relevant CLI module (`src/cli/model-commands.ts`, `preset-commands.ts`, `system-commands.ts`, or a new focused module), re-export as needed from `src/cli/commands.ts` for compatibility, and wire it in `src/cli/index.ts`'s dispatcher. Keep output going through `src/cli/format.ts` / `style.ts` so colors respect `NO_COLOR`.
166
+ - **New TUI key.** Bind it in `src/ui/App.tsx`'s `useInput` handler and document it in the footer string and the README key table.
167
+ - **New registry field.** Add it to `ModelEntry` in `src/types/index.ts`, teach `ingestDiscovered` how to populate/refresh it, add a migration-safe default (optional field, never required of older entries), and surface it in `athanor show` if user-relevant.
168
+ - **New tunable runtime flag.** Add to `TUNABLE_KEYS` in `src/presets/edit.ts` with both kebab-case CLI name and camelCase JSON name, then reference it in the relevant adapter's `buildCommand`.
169
+
170
+ ## Where state lives
171
+
172
+ | Path | Purpose |
173
+ |---|---|
174
+ | `~/.athanor/config.json` | user config: scan roots, port range, supervisor policy, control API |
175
+ | `~/.athanor/models.json` | registry — source of truth for slugs, ports, presets, publish state |
176
+ | `~/.athanor/recipes.json` | optional user recipes; overrides built-ins of the same name |
177
+ | `~/.athanor/logs/<slug>-<pid>.log` | per-run supervisor log |
178
+ | `~/.athanor/state.json` | running PIDs / ports for reattach (see `src/supervisor/state.ts`) |
179
+ | `~/.pi/agent/models.json` | pi-agent providers; athanor namespace only |
180
+ | `~/.pi/agent/settings.json` | pi-agent settings; only `defaultProvider` / `defaultModel` touched |
181
+ | `~/.cache/huggingface/hub` | HF snapshots scanned by `src/discovery/scanner.ts` |
182
+
183
+ ## Conventions
184
+
185
+ - TypeScript strict; no `any` unless unavoidable. Prefer `unknown` at boundaries and narrow.
186
+ - Functions named after what they do, not how. Side-effecting helpers end in verbs (`ingestDiscovered`, `updateModel`, `syncPi`).
187
+ - Comments match the local density. Do not annotate obvious code or explain the rationale for a change inside a comment — that belongs in the PR.
188
+ - No new files unless necessary. Prefer editing an existing module. Especially: do not create new top-level docs (`*.md`) without being asked.
189
+ - Keep command output scannable. Tables go through `format.ts`. Errors exit non-zero with a one-line message plus, when useful, a hint on the next line.
190
+
191
+ ## Roadmap
192
+
193
+ ### Router — remaining work
194
+
195
+ The router in `src/router/server.ts` is live (see invariant #4 and the Router section in `README.md`). Headless mode (`athanor router` subcommand) and in-flight stream safety (`src/supervisor/inflight.ts` + `supervisor.stop()` drain before SIGTERM, bounded by `config.router.drainTimeoutMs`) are both done. One follow-up remains:
196
+
197
+ - **Token accounting via passthrough.** The router sees the completion stream live. `src/supervisor/metrics.ts` could tee token counts off the passthrough instead of tailing logs, which would make `tok/s` a live counter while generation is running (not just post-request) when router mode is on. The hook point is the `pipeline(Readable.fromWeb(...), res)` call in `proxy()`; insert a passthrough Transform that counts SSE `data:` frames and updates a shared metric keyed on `entry.id`, then teach `src/supervisor/metrics.ts` to prefer that source when non-null.
198
+
199
+ ## License
200
+
201
+ Apache License 2.0. Copyright 2026 Myles Borins. See `LICENSE`. Contributions are accepted under the same license (Apache 2.0 Section 5 — inbound = outbound). Do not add code under a license incompatible with Apache 2.0 (e.g. GPL, AGPL, SSPL, or code lifted from a proprietary source) without flagging it explicitly.
package/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of tracking or improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, notices, patent notices,
102
+ trademark, and attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for describing the origin of the Work and
141
+ reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Support. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or support.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2026 Myles Borins
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
200
+ implied. See the License for the specific language governing permissions and
201
+ limitations under the License.