cloxy 5.1__tar.gz → 5.2__tar.gz
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.
- {cloxy-5.1 → cloxy-5.2}/PKG-INFO +53 -7
- {cloxy-5.1 → cloxy-5.2}/README.md +52 -6
- {cloxy-5.1 → cloxy-5.2}/cloxy/__init__.py +1 -1
- cloxy-5.2/cloxy/backends/__init__.py +11 -0
- cloxy-5.2/cloxy/backends/openai_backend.py +133 -0
- {cloxy-5.1 → cloxy-5.2}/cloxy/cli.py +173 -1
- cloxy-5.2/cloxy/cluster.py +131 -0
- {cloxy-5.1 → cloxy-5.2}/cloxy/config.py +38 -2
- {cloxy-5.1 → cloxy-5.2}/cloxy/convos.py +98 -17
- cloxy-5.2/cloxy/push.py +220 -0
- {cloxy-5.1 → cloxy-5.2}/cloxy/server.py +89 -21
- {cloxy-5.1 → cloxy-5.2}/cloxy.egg-info/PKG-INFO +53 -7
- {cloxy-5.1 → cloxy-5.2}/cloxy.egg-info/SOURCES.txt +6 -1
- {cloxy-5.1 → cloxy-5.2}/tests/test_cli.py +13 -0
- cloxy-5.2/tests/test_cluster.py +177 -0
- {cloxy-5.1 → cloxy-5.2}/tests/test_convos.py +80 -0
- cloxy-5.2/tests/test_push.py +126 -0
- cloxy-5.1/cloxy/backends/__init__.py +0 -0
- {cloxy-5.1 → cloxy-5.2}/LICENSE +0 -0
- {cloxy-5.1 → cloxy-5.2}/cloxy/__main__.py +0 -0
- {cloxy-5.1 → cloxy-5.2}/cloxy/backends/mlx_backend.py +0 -0
- {cloxy-5.1 → cloxy-5.2}/cloxy/catalog.py +0 -0
- {cloxy-5.1 → cloxy-5.2}/cloxy/hardware.py +0 -0
- {cloxy-5.1 → cloxy-5.2}/cloxy/mcp_server.py +0 -0
- {cloxy-5.1 → cloxy-5.2}/cloxy/memory.py +0 -0
- {cloxy-5.1 → cloxy-5.2}/cloxy/proxy.py +0 -0
- {cloxy-5.1 → cloxy-5.2}/cloxy.egg-info/dependency_links.txt +0 -0
- {cloxy-5.1 → cloxy-5.2}/cloxy.egg-info/entry_points.txt +0 -0
- {cloxy-5.1 → cloxy-5.2}/cloxy.egg-info/requires.txt +0 -0
- {cloxy-5.1 → cloxy-5.2}/cloxy.egg-info/top_level.txt +0 -0
- {cloxy-5.1 → cloxy-5.2}/pyproject.toml +0 -0
- {cloxy-5.1 → cloxy-5.2}/setup.cfg +0 -0
- {cloxy-5.1 → cloxy-5.2}/tests/test_config.py +0 -0
- {cloxy-5.1 → cloxy-5.2}/tests/test_endpoints.py +0 -0
- {cloxy-5.1 → cloxy-5.2}/tests/test_mcp.py +0 -0
- {cloxy-5.1 → cloxy-5.2}/tests/test_memory.py +0 -0
- {cloxy-5.1 → cloxy-5.2}/tests/test_proxy.py +0 -0
{cloxy-5.1 → cloxy-5.2}/PKG-INFO
RENAMED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: cloxy
|
|
3
|
-
Version: 5.
|
|
3
|
+
Version: 5.2
|
|
4
4
|
Summary: Give your local AI eyes and memory — web proxy, self-maintaining conversation memory, MCP server, and an Apple Silicon LLM in one process.
|
|
5
5
|
License: MIT
|
|
6
6
|
Project-URL: Homepage, https://github.com/roygurner-gif/cloxy
|
|
@@ -43,7 +43,7 @@ Dynamic: license-file
|
|
|
43
43
|
|
|
44
44
|
Cloxy is one process that gives any AI tool three things it doesn't have on its own:
|
|
45
45
|
|
|
46
|
-
- **Memory that keeps itself.** Cloxy watches your Claude Code sessions and ingests them as they happen. Ask "what did we decide about the auth flow last week" and get the actual conversation back — dated, tagged with the project, ranked by a hybrid semantic + keyword search.
|
|
46
|
+
- **Memory that keeps itself.** Cloxy watches your Claude Code and Codex sessions and ingests them as they happen — one memory shared by every agent you run, on every machine you run them on. Ask "what did we decide about the auth flow last week" and get the actual conversation back — dated, tagged with the project, ranked by a hybrid semantic + keyword search.
|
|
47
47
|
- **Eyes.** A web proxy that turns any URL into clean text, markdown, or a CSS-selected extract, and a `/verify` endpoint that ranks a page's passages against a claim.
|
|
48
48
|
- **A local LLM** (optional, Apple Silicon). `cloxy init` picks an MLX model that fits your unified memory; `/v1/chat/completions` serves it OpenAI-style — with your memory injected if you want.
|
|
49
49
|
|
|
@@ -67,7 +67,7 @@ pipx install "git+https://github.com/roygurner-gif/cloxy"
|
|
|
67
67
|
## Quick start
|
|
68
68
|
|
|
69
69
|
```bash
|
|
70
|
-
cloxy start # server on http://127.0.0.1:9055 — the watcher
|
|
70
|
+
cloxy start # server on http://127.0.0.1:9055 — the watcher ingests ~/.claude/projects + ~/.codex/sessions
|
|
71
71
|
cloxy status # memories, watcher, index sizes
|
|
72
72
|
cloxy recall "what port does the staging cluster use"
|
|
73
73
|
```
|
|
@@ -99,12 +99,21 @@ CLOXY_URL=http://192.168.1.20:9055
|
|
|
99
99
|
CLOXY_API_KEY=…
|
|
100
100
|
```
|
|
101
101
|
|
|
102
|
-
To feed that server this machine's
|
|
102
|
+
To feed that server this machine's agent sessions too, run `cloxy push` on the client:
|
|
103
|
+
|
|
104
|
+
```bash
|
|
105
|
+
cloxy push # every 10s: send new session lines to CLOXY_URL
|
|
106
|
+
cloxy push --once # one pass (cron / a timer)
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
It sends only complete lines that are new since the last pass, tagged with the byte offset they start at, to `POST /push`. The server appends them to a mirror under `~/.cloxy/inbox/<host>/<agent>/` — refusing any slice that doesn't line up, and telling the client where to resume — and its watcher ingests the mirror like local sessions. Same API key as everything else; no ssh, no rsync. `--host` sets the name this machine appears under (default: its hostname).
|
|
103
110
|
|
|
104
111
|
## How memory works
|
|
105
112
|
|
|
106
113
|
```
|
|
107
|
-
~/.claude/projects/**/*.jsonl
|
|
114
|
+
~/.claude/projects/**/*.jsonl ─┐
|
|
115
|
+
~/.codex/sessions/**/*.jsonl ─┼─watcher (5s)──▶ parse new lines from last byte offset
|
|
116
|
+
~/.cloxy/inbox/ (cloxy push) ─┘
|
|
108
117
|
│
|
|
109
118
|
pack whole messages into ~1500-char chunks
|
|
110
119
|
header: [2026-09-12 14:40 · rmbr · Board colors]
|
|
@@ -117,6 +126,7 @@ To feed that server this machine's Claude Code sessions, mirror them into one of
|
|
|
117
126
|
```
|
|
118
127
|
|
|
119
128
|
- **Incremental.** Each session file is tracked by byte offset. Only new lines are read. The last, still-growing chunk is stored so it's searchable immediately and replaced on the next pass.
|
|
129
|
+
- **Every agent.** Claude Code and Codex CLI sessions are recognised per file (by name, else by the first line); harness plumbing — system reminders, Codex's environment/AGENTS.md preamble, tool calls, reasoning — is dropped, and each memory records which `agent` wrote it.
|
|
120
130
|
- **Dated and scoped.** Every memory carries the session's working directory (project), timestamps, git branch, and title. Filter with `project`, `since`, `until`.
|
|
121
131
|
- **Hybrid.** Dense vectors catch meaning; FTS5 catches the exact port number, hostname, or flag that embeddings blur. Results are fused and gently tilted toward recent memories (30-day half-life; `recency_weight` 0–1). The `score` on each hit is the fused rank value (typically 0.01–0.04), so compare hits within one query by order, not by magnitude — it is not a cosine similarity like `/verify` reports.
|
|
122
132
|
- **Asymmetric embeddings.** A short question is embedded differently from the long text it searches. Models trained that way (the E5 family) get their `query: ` / `passage: ` prefixes automatically; fastembed does not add them, and without them E5 recall drops sharply. Override with `CLOXY_EMBED_QUERY_PREFIX` / `CLOXY_EMBED_PASSAGE_PREFIX`.
|
|
@@ -133,6 +143,7 @@ Existing v3/v4 databases migrate in place on first start.
|
|
|
133
143
|
| `POST` | `/ingest_text` | Store any text. `{text, source, project?, metadata?}` |
|
|
134
144
|
| `POST` | `/ingest_convos` | Run an ingest pass now. `{convo_dir?, force?}` |
|
|
135
145
|
| `GET` | `/projects` | Projects present in memory with counts and date ranges |
|
|
146
|
+
| `POST` | `/push` | Receive session lines from `cloxy push`. `{host, agent, path, offset, data (base64, whole lines), replace?}` → `{size}`; 409 + `{size}` if the offset doesn't match |
|
|
136
147
|
| `GET` | `/ingest_status` | Watcher state |
|
|
137
148
|
| `GET` | `/memory_stats` | Counts, sources, index sizes |
|
|
138
149
|
| `DELETE` | `/memory/{id}` | Delete one memory |
|
|
@@ -194,6 +205,28 @@ Continue.dev / Cursor: add an OpenAI-compatible model with base URL `http://loca
|
|
|
194
205
|
|
|
195
206
|
Why MLX: it's Apple's framework for the unified-memory architecture, it runs in-process (no daemon, no HTTP hop between proxy and model), and it's fast on M-series parts. Cross-platform inference via `llama-cpp-python` is planned as a separate extra.
|
|
196
207
|
|
|
208
|
+
### A model bigger than one Mac (MLX distributed / JACCL)
|
|
209
|
+
|
|
210
|
+
Shard one model across several Macs with MLX's own distributed stack. Cloxy drives Apple's tools (`mlx.distributed_config`, `mlx.launch`, `mlx_lm server`); it does not shard anything itself:
|
|
211
|
+
|
|
212
|
+
```bash
|
|
213
|
+
# every Mac: same python path with cloxy[mlx] installed, passwordless ssh from this one
|
|
214
|
+
cloxy cluster setup --hosts m4-a.local,m4-b.local,m4-c.local --backend jaccl-ring --auto-setup
|
|
215
|
+
cloxy cluster serve --model mlx-community/Qwen3-235B-A22B-4bit # rank 0 = first host, port 9056
|
|
216
|
+
CLOXY_LLM_URL=http://m4-a.local:9056 cloxy start # memory + chat, cluster as the brain
|
|
217
|
+
cloxy cluster status
|
|
218
|
+
```
|
|
219
|
+
|
|
220
|
+
| Backend | Link | When |
|
|
221
|
+
|---|---|---|
|
|
222
|
+
| `jaccl` | RDMA over Thunderbolt 5, every pair of Macs cabled | lowest latency; macOS 26.2+ with RDMA enabled |
|
|
223
|
+
| `jaccl-ring` | RDMA over Thunderbolt 5, each Mac cabled to two neighbours | more Macs than TB ports |
|
|
224
|
+
| `ring` | TCP over any network | always works, slowest |
|
|
225
|
+
|
|
226
|
+
`setup` writes `~/.cloxy/hostfile.json` (RDMA devices per pair); `--auto-setup` lets mlx configure the Thunderbolt interfaces and needs sudo on each Mac. `serve` picks pipeline parallel (layers split, ~1 sync per token) on `ring` and tensor parallel on `jaccl` — tensor syncs every layer of every token, which only pays on RDMA (two M4 minis over Wi-Fi: tensor 0.85 tok/s, pipeline 27–36 tok/s). Override with `--pipeline` / `--tensor`; flags after `--` go to `mlx_lm server` (e.g. `-- --max-tokens 4096`). With `CLOXY_LLM_URL` set, `/v1/chat/completions` injects memory here and forwards to the cluster — no model loads in the cloxy process. The same variable works for any OpenAI-compatible server (Ollama, LM Studio, vLLM).
|
|
227
|
+
|
|
228
|
+
> `mlx_lm server` has no auth; rank 0 binds `0.0.0.0`. Keep the cluster on a private network and expose only cloxy (with `CLOXY_API_KEY`).
|
|
229
|
+
|
|
197
230
|
## CLI
|
|
198
231
|
|
|
199
232
|
```
|
|
@@ -201,10 +234,14 @@ cloxy start [--host H] [--port P] run the server
|
|
|
201
234
|
cloxy mcp MCP stdio server (for editors)
|
|
202
235
|
cloxy recall QUERY [-k N] [--project P] [--since D] [--until D] [--mode M] [--full] [--json]
|
|
203
236
|
cloxy ingest [DIR] [--force] run an ingest pass now
|
|
237
|
+
cloxy push [--once] [--interval S] [--host NAME] mirror this machine's sessions to CLOXY_URL
|
|
204
238
|
cloxy status health, memory, watcher
|
|
205
239
|
cloxy reembed re-embed every memory (after changing model/prefix; server stopped)
|
|
206
240
|
cloxy install-service | uninstall-service launchd (macOS)
|
|
207
241
|
cloxy init | show | list local LLM setup
|
|
242
|
+
cloxy cluster setup --hosts A,B,... [--over thunderbolt|ethernet] [--backend jaccl|jaccl-ring|ring] [--auto-setup]
|
|
243
|
+
cloxy cluster serve [--model ID] [--port P] [--pipeline] [-- MLX_LM_SERVER_FLAGS]
|
|
244
|
+
cloxy cluster status hostfile + whether CLOXY_LLM_URL answers
|
|
208
245
|
```
|
|
209
246
|
|
|
210
247
|
## Configuration
|
|
@@ -220,8 +257,10 @@ Everything is an environment variable.
|
|
|
220
257
|
| `CLOXY_DATA_DIR` | `~/.cloxy` | Database, LLM config, logs, downloaded embedding models (`models/`) |
|
|
221
258
|
| `FASTEMBED_CACHE_PATH` | `$CLOXY_DATA_DIR/models` | Where embedding/reranker models are cached (set explicitly to share an existing cache) |
|
|
222
259
|
| `CLOXY_WATCH` | `1` | Run the conversation watcher |
|
|
223
|
-
| `CLOXY_WATCH_DIRS` | `~/.claude/projects` | Directories to watch (`:`-separated) |
|
|
260
|
+
| `CLOXY_WATCH_DIRS` | `~/.claude/projects:~/.codex/sessions` | Directories to watch (`:`-separated). `~/.cloxy/inbox` is always watched too |
|
|
224
261
|
| `CLOXY_WATCH_INTERVAL` | `5` | Seconds between scans |
|
|
262
|
+
| `CLOXY_PUSH_SOURCES` | `claude=~/.claude/projects,codex=~/.codex/sessions` | What `cloxy push` mirrors, as `agent=dir` pairs |
|
|
263
|
+
| `CLOXY_PUSH_INTERVAL` | `10` | Seconds between `cloxy push` passes |
|
|
225
264
|
| `CLOXY_EMBED_MODEL` | `BAAI/bge-small-en-v1.5` | Embedding model (recorded in the DB; change it, then `cloxy reembed`) |
|
|
226
265
|
| `CLOXY_EMBED_DIM` | `384` | Must match the model |
|
|
227
266
|
| `CLOXY_EMBED_QUERY_PREFIX` | by model | Prepended to every query before embedding (`query: ` for E5, empty otherwise) |
|
|
@@ -235,13 +274,20 @@ Everything is an environment variable.
|
|
|
235
274
|
| `CLOXY_FETCH_TIMEOUT` | `30` | Web fetch timeout, seconds |
|
|
236
275
|
| `CLOXY_CONFIG` | `~/.cloxy/config.json` | LLM config written by `cloxy init` |
|
|
237
276
|
| `CLOXY_EAGER_LLM` | *(unset)* | `1` loads the LLM at startup |
|
|
277
|
+
| `CLOXY_LLM_URL` | *(unset)* | Forward chat to this OpenAI-compatible server (e.g. a `cloxy cluster serve` rank 0) instead of in-process MLX |
|
|
278
|
+
| `CLOXY_LLM_API_KEY` | *(unset)* | Sent upstream as `Authorization: Bearer` |
|
|
279
|
+
| `CLOXY_LLM_TIMEOUT` | `600` | Upstream request timeout, seconds |
|
|
280
|
+
| `CLOXY_HOSTFILE` | `~/.cloxy/hostfile.json` | MLX distributed hostfile for `cloxy cluster` |
|
|
281
|
+
| `CLOXY_CLUSTER_BACKEND` | `jaccl` | Backend when neither `--backend` nor the hostfile names one |
|
|
282
|
+
| `CLOXY_CLUSTER_PORT` | `9056` | Port `cloxy cluster serve` gives `mlx_lm server` |
|
|
238
283
|
|
|
239
284
|
## Security
|
|
240
285
|
|
|
241
286
|
- **Loopback by default.** Nothing is reachable off your machine unless you set `CLOXY_HOST=0.0.0.0`.
|
|
242
287
|
- **If you expose it, set an API key.** Otherwise anyone on the network can read and write your memory. The key is compared in constant time.
|
|
243
288
|
- **SSRF guard.** `/fetch`, `/search`, `/verify` resolve the target and refuse private, loopback, link-local, and cloud-metadata addresses — and re-check every redirect hop (max 5). Bodies are streamed and cut at 500 KB; binary content types are refused.
|
|
244
|
-
- **Your transcripts stay local.** The watcher reads
|
|
289
|
+
- **Your transcripts stay local.** The watcher reads the session directories on this machine and writes to `~/.cloxy/memory.db`. They leave it only if you run `cloxy push`, and then only to the `CLOXY_URL` you set. No telemetry.
|
|
290
|
+
- **`/push` writes only inside the inbox.** Host, agent, and every path component are validated; anything that resolves outside `~/.cloxy/inbox` is refused. The only outbound traffic is `/fetch` requests you make and one-time model downloads.
|
|
245
291
|
|
|
246
292
|
## Docker (proxy + memory + MCP; no LLM, no watcher)
|
|
247
293
|
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
Cloxy is one process that gives any AI tool three things it doesn't have on its own:
|
|
6
6
|
|
|
7
|
-
- **Memory that keeps itself.** Cloxy watches your Claude Code sessions and ingests them as they happen. Ask "what did we decide about the auth flow last week" and get the actual conversation back — dated, tagged with the project, ranked by a hybrid semantic + keyword search.
|
|
7
|
+
- **Memory that keeps itself.** Cloxy watches your Claude Code and Codex sessions and ingests them as they happen — one memory shared by every agent you run, on every machine you run them on. Ask "what did we decide about the auth flow last week" and get the actual conversation back — dated, tagged with the project, ranked by a hybrid semantic + keyword search.
|
|
8
8
|
- **Eyes.** A web proxy that turns any URL into clean text, markdown, or a CSS-selected extract, and a `/verify` endpoint that ranks a page's passages against a claim.
|
|
9
9
|
- **A local LLM** (optional, Apple Silicon). `cloxy init` picks an MLX model that fits your unified memory; `/v1/chat/completions` serves it OpenAI-style — with your memory injected if you want.
|
|
10
10
|
|
|
@@ -28,7 +28,7 @@ pipx install "git+https://github.com/roygurner-gif/cloxy"
|
|
|
28
28
|
## Quick start
|
|
29
29
|
|
|
30
30
|
```bash
|
|
31
|
-
cloxy start # server on http://127.0.0.1:9055 — the watcher
|
|
31
|
+
cloxy start # server on http://127.0.0.1:9055 — the watcher ingests ~/.claude/projects + ~/.codex/sessions
|
|
32
32
|
cloxy status # memories, watcher, index sizes
|
|
33
33
|
cloxy recall "what port does the staging cluster use"
|
|
34
34
|
```
|
|
@@ -60,12 +60,21 @@ CLOXY_URL=http://192.168.1.20:9055
|
|
|
60
60
|
CLOXY_API_KEY=…
|
|
61
61
|
```
|
|
62
62
|
|
|
63
|
-
To feed that server this machine's
|
|
63
|
+
To feed that server this machine's agent sessions too, run `cloxy push` on the client:
|
|
64
|
+
|
|
65
|
+
```bash
|
|
66
|
+
cloxy push # every 10s: send new session lines to CLOXY_URL
|
|
67
|
+
cloxy push --once # one pass (cron / a timer)
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
It sends only complete lines that are new since the last pass, tagged with the byte offset they start at, to `POST /push`. The server appends them to a mirror under `~/.cloxy/inbox/<host>/<agent>/` — refusing any slice that doesn't line up, and telling the client where to resume — and its watcher ingests the mirror like local sessions. Same API key as everything else; no ssh, no rsync. `--host` sets the name this machine appears under (default: its hostname).
|
|
64
71
|
|
|
65
72
|
## How memory works
|
|
66
73
|
|
|
67
74
|
```
|
|
68
|
-
~/.claude/projects/**/*.jsonl
|
|
75
|
+
~/.claude/projects/**/*.jsonl ─┐
|
|
76
|
+
~/.codex/sessions/**/*.jsonl ─┼─watcher (5s)──▶ parse new lines from last byte offset
|
|
77
|
+
~/.cloxy/inbox/ (cloxy push) ─┘
|
|
69
78
|
│
|
|
70
79
|
pack whole messages into ~1500-char chunks
|
|
71
80
|
header: [2026-09-12 14:40 · rmbr · Board colors]
|
|
@@ -78,6 +87,7 @@ To feed that server this machine's Claude Code sessions, mirror them into one of
|
|
|
78
87
|
```
|
|
79
88
|
|
|
80
89
|
- **Incremental.** Each session file is tracked by byte offset. Only new lines are read. The last, still-growing chunk is stored so it's searchable immediately and replaced on the next pass.
|
|
90
|
+
- **Every agent.** Claude Code and Codex CLI sessions are recognised per file (by name, else by the first line); harness plumbing — system reminders, Codex's environment/AGENTS.md preamble, tool calls, reasoning — is dropped, and each memory records which `agent` wrote it.
|
|
81
91
|
- **Dated and scoped.** Every memory carries the session's working directory (project), timestamps, git branch, and title. Filter with `project`, `since`, `until`.
|
|
82
92
|
- **Hybrid.** Dense vectors catch meaning; FTS5 catches the exact port number, hostname, or flag that embeddings blur. Results are fused and gently tilted toward recent memories (30-day half-life; `recency_weight` 0–1). The `score` on each hit is the fused rank value (typically 0.01–0.04), so compare hits within one query by order, not by magnitude — it is not a cosine similarity like `/verify` reports.
|
|
83
93
|
- **Asymmetric embeddings.** A short question is embedded differently from the long text it searches. Models trained that way (the E5 family) get their `query: ` / `passage: ` prefixes automatically; fastembed does not add them, and without them E5 recall drops sharply. Override with `CLOXY_EMBED_QUERY_PREFIX` / `CLOXY_EMBED_PASSAGE_PREFIX`.
|
|
@@ -94,6 +104,7 @@ Existing v3/v4 databases migrate in place on first start.
|
|
|
94
104
|
| `POST` | `/ingest_text` | Store any text. `{text, source, project?, metadata?}` |
|
|
95
105
|
| `POST` | `/ingest_convos` | Run an ingest pass now. `{convo_dir?, force?}` |
|
|
96
106
|
| `GET` | `/projects` | Projects present in memory with counts and date ranges |
|
|
107
|
+
| `POST` | `/push` | Receive session lines from `cloxy push`. `{host, agent, path, offset, data (base64, whole lines), replace?}` → `{size}`; 409 + `{size}` if the offset doesn't match |
|
|
97
108
|
| `GET` | `/ingest_status` | Watcher state |
|
|
98
109
|
| `GET` | `/memory_stats` | Counts, sources, index sizes |
|
|
99
110
|
| `DELETE` | `/memory/{id}` | Delete one memory |
|
|
@@ -155,6 +166,28 @@ Continue.dev / Cursor: add an OpenAI-compatible model with base URL `http://loca
|
|
|
155
166
|
|
|
156
167
|
Why MLX: it's Apple's framework for the unified-memory architecture, it runs in-process (no daemon, no HTTP hop between proxy and model), and it's fast on M-series parts. Cross-platform inference via `llama-cpp-python` is planned as a separate extra.
|
|
157
168
|
|
|
169
|
+
### A model bigger than one Mac (MLX distributed / JACCL)
|
|
170
|
+
|
|
171
|
+
Shard one model across several Macs with MLX's own distributed stack. Cloxy drives Apple's tools (`mlx.distributed_config`, `mlx.launch`, `mlx_lm server`); it does not shard anything itself:
|
|
172
|
+
|
|
173
|
+
```bash
|
|
174
|
+
# every Mac: same python path with cloxy[mlx] installed, passwordless ssh from this one
|
|
175
|
+
cloxy cluster setup --hosts m4-a.local,m4-b.local,m4-c.local --backend jaccl-ring --auto-setup
|
|
176
|
+
cloxy cluster serve --model mlx-community/Qwen3-235B-A22B-4bit # rank 0 = first host, port 9056
|
|
177
|
+
CLOXY_LLM_URL=http://m4-a.local:9056 cloxy start # memory + chat, cluster as the brain
|
|
178
|
+
cloxy cluster status
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
| Backend | Link | When |
|
|
182
|
+
|---|---|---|
|
|
183
|
+
| `jaccl` | RDMA over Thunderbolt 5, every pair of Macs cabled | lowest latency; macOS 26.2+ with RDMA enabled |
|
|
184
|
+
| `jaccl-ring` | RDMA over Thunderbolt 5, each Mac cabled to two neighbours | more Macs than TB ports |
|
|
185
|
+
| `ring` | TCP over any network | always works, slowest |
|
|
186
|
+
|
|
187
|
+
`setup` writes `~/.cloxy/hostfile.json` (RDMA devices per pair); `--auto-setup` lets mlx configure the Thunderbolt interfaces and needs sudo on each Mac. `serve` picks pipeline parallel (layers split, ~1 sync per token) on `ring` and tensor parallel on `jaccl` — tensor syncs every layer of every token, which only pays on RDMA (two M4 minis over Wi-Fi: tensor 0.85 tok/s, pipeline 27–36 tok/s). Override with `--pipeline` / `--tensor`; flags after `--` go to `mlx_lm server` (e.g. `-- --max-tokens 4096`). With `CLOXY_LLM_URL` set, `/v1/chat/completions` injects memory here and forwards to the cluster — no model loads in the cloxy process. The same variable works for any OpenAI-compatible server (Ollama, LM Studio, vLLM).
|
|
188
|
+
|
|
189
|
+
> `mlx_lm server` has no auth; rank 0 binds `0.0.0.0`. Keep the cluster on a private network and expose only cloxy (with `CLOXY_API_KEY`).
|
|
190
|
+
|
|
158
191
|
## CLI
|
|
159
192
|
|
|
160
193
|
```
|
|
@@ -162,10 +195,14 @@ cloxy start [--host H] [--port P] run the server
|
|
|
162
195
|
cloxy mcp MCP stdio server (for editors)
|
|
163
196
|
cloxy recall QUERY [-k N] [--project P] [--since D] [--until D] [--mode M] [--full] [--json]
|
|
164
197
|
cloxy ingest [DIR] [--force] run an ingest pass now
|
|
198
|
+
cloxy push [--once] [--interval S] [--host NAME] mirror this machine's sessions to CLOXY_URL
|
|
165
199
|
cloxy status health, memory, watcher
|
|
166
200
|
cloxy reembed re-embed every memory (after changing model/prefix; server stopped)
|
|
167
201
|
cloxy install-service | uninstall-service launchd (macOS)
|
|
168
202
|
cloxy init | show | list local LLM setup
|
|
203
|
+
cloxy cluster setup --hosts A,B,... [--over thunderbolt|ethernet] [--backend jaccl|jaccl-ring|ring] [--auto-setup]
|
|
204
|
+
cloxy cluster serve [--model ID] [--port P] [--pipeline] [-- MLX_LM_SERVER_FLAGS]
|
|
205
|
+
cloxy cluster status hostfile + whether CLOXY_LLM_URL answers
|
|
169
206
|
```
|
|
170
207
|
|
|
171
208
|
## Configuration
|
|
@@ -181,8 +218,10 @@ Everything is an environment variable.
|
|
|
181
218
|
| `CLOXY_DATA_DIR` | `~/.cloxy` | Database, LLM config, logs, downloaded embedding models (`models/`) |
|
|
182
219
|
| `FASTEMBED_CACHE_PATH` | `$CLOXY_DATA_DIR/models` | Where embedding/reranker models are cached (set explicitly to share an existing cache) |
|
|
183
220
|
| `CLOXY_WATCH` | `1` | Run the conversation watcher |
|
|
184
|
-
| `CLOXY_WATCH_DIRS` | `~/.claude/projects` | Directories to watch (`:`-separated) |
|
|
221
|
+
| `CLOXY_WATCH_DIRS` | `~/.claude/projects:~/.codex/sessions` | Directories to watch (`:`-separated). `~/.cloxy/inbox` is always watched too |
|
|
185
222
|
| `CLOXY_WATCH_INTERVAL` | `5` | Seconds between scans |
|
|
223
|
+
| `CLOXY_PUSH_SOURCES` | `claude=~/.claude/projects,codex=~/.codex/sessions` | What `cloxy push` mirrors, as `agent=dir` pairs |
|
|
224
|
+
| `CLOXY_PUSH_INTERVAL` | `10` | Seconds between `cloxy push` passes |
|
|
186
225
|
| `CLOXY_EMBED_MODEL` | `BAAI/bge-small-en-v1.5` | Embedding model (recorded in the DB; change it, then `cloxy reembed`) |
|
|
187
226
|
| `CLOXY_EMBED_DIM` | `384` | Must match the model |
|
|
188
227
|
| `CLOXY_EMBED_QUERY_PREFIX` | by model | Prepended to every query before embedding (`query: ` for E5, empty otherwise) |
|
|
@@ -196,13 +235,20 @@ Everything is an environment variable.
|
|
|
196
235
|
| `CLOXY_FETCH_TIMEOUT` | `30` | Web fetch timeout, seconds |
|
|
197
236
|
| `CLOXY_CONFIG` | `~/.cloxy/config.json` | LLM config written by `cloxy init` |
|
|
198
237
|
| `CLOXY_EAGER_LLM` | *(unset)* | `1` loads the LLM at startup |
|
|
238
|
+
| `CLOXY_LLM_URL` | *(unset)* | Forward chat to this OpenAI-compatible server (e.g. a `cloxy cluster serve` rank 0) instead of in-process MLX |
|
|
239
|
+
| `CLOXY_LLM_API_KEY` | *(unset)* | Sent upstream as `Authorization: Bearer` |
|
|
240
|
+
| `CLOXY_LLM_TIMEOUT` | `600` | Upstream request timeout, seconds |
|
|
241
|
+
| `CLOXY_HOSTFILE` | `~/.cloxy/hostfile.json` | MLX distributed hostfile for `cloxy cluster` |
|
|
242
|
+
| `CLOXY_CLUSTER_BACKEND` | `jaccl` | Backend when neither `--backend` nor the hostfile names one |
|
|
243
|
+
| `CLOXY_CLUSTER_PORT` | `9056` | Port `cloxy cluster serve` gives `mlx_lm server` |
|
|
199
244
|
|
|
200
245
|
## Security
|
|
201
246
|
|
|
202
247
|
- **Loopback by default.** Nothing is reachable off your machine unless you set `CLOXY_HOST=0.0.0.0`.
|
|
203
248
|
- **If you expose it, set an API key.** Otherwise anyone on the network can read and write your memory. The key is compared in constant time.
|
|
204
249
|
- **SSRF guard.** `/fetch`, `/search`, `/verify` resolve the target and refuse private, loopback, link-local, and cloud-metadata addresses — and re-check every redirect hop (max 5). Bodies are streamed and cut at 500 KB; binary content types are refused.
|
|
205
|
-
- **Your transcripts stay local.** The watcher reads
|
|
250
|
+
- **Your transcripts stay local.** The watcher reads the session directories on this machine and writes to `~/.cloxy/memory.db`. They leave it only if you run `cloxy push`, and then only to the `CLOXY_URL` you set. No telemetry.
|
|
251
|
+
- **`/push` writes only inside the inbox.** Host, agent, and every path component are validated; anything that resolves outside `~/.cloxy/inbox` is refused. The only outbound traffic is `/fetch` requests you make and one-time model downloads.
|
|
206
252
|
|
|
207
253
|
## Docker (proxy + memory + MCP; no LLM, no watcher)
|
|
208
254
|
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"""LLM backends: in-process MLX, or an upstream OpenAI-compatible server."""
|
|
2
|
+
from .. import config
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
def get():
|
|
6
|
+
"""The active backend module. CLOXY_LLM_URL set = upstream (e.g. an MLX cluster)."""
|
|
7
|
+
if config.LLM_URL:
|
|
8
|
+
from . import openai_backend
|
|
9
|
+
return openai_backend
|
|
10
|
+
from . import mlx_backend
|
|
11
|
+
return mlx_backend
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Upstream backend: forward chat to an OpenAI-compatible server (CLOXY_LLM_URL).
|
|
3
|
+
|
|
4
|
+
The main use is an MLX distributed cluster — `cloxy cluster serve` runs
|
|
5
|
+
mlx_lm.server under mlx.launch, so the model is sharded across several Macs
|
|
6
|
+
(JACCL over Thunderbolt 5, or ring over TCP) and rank 0 answers HTTP. Anything
|
|
7
|
+
else that speaks /v1/chat/completions works too (Ollama, LM Studio, vLLM).
|
|
8
|
+
|
|
9
|
+
Same interface as mlx_backend: load_model / is_loaded / current_model /
|
|
10
|
+
generate_chat / stream_chat (yields StreamPiece).
|
|
11
|
+
"""
|
|
12
|
+
from __future__ import annotations
|
|
13
|
+
|
|
14
|
+
import json
|
|
15
|
+
import time
|
|
16
|
+
from typing import AsyncGenerator, List, Optional
|
|
17
|
+
|
|
18
|
+
import httpx
|
|
19
|
+
|
|
20
|
+
from .. import config
|
|
21
|
+
from .mlx_backend import StreamPiece
|
|
22
|
+
|
|
23
|
+
# Tests swap this for an httpx.MockTransport.
|
|
24
|
+
_transport: Optional[httpx.AsyncBaseTransport] = None
|
|
25
|
+
_model_id: Optional[str] = None
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
class UpstreamError(RuntimeError):
|
|
29
|
+
def __init__(self, status: int, detail: str):
|
|
30
|
+
super().__init__(detail)
|
|
31
|
+
self.status = status
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def _client() -> httpx.AsyncClient:
|
|
35
|
+
headers = {"Authorization": f"Bearer {config.LLM_API_KEY}"} if config.LLM_API_KEY else {}
|
|
36
|
+
return httpx.AsyncClient(base_url=config.LLM_URL, headers=headers,
|
|
37
|
+
timeout=httpx.Timeout(config.LLM_TIMEOUT, connect=10),
|
|
38
|
+
transport=_transport)
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def is_loaded() -> bool:
|
|
42
|
+
return _model_id is not None
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def current_model() -> Optional[str]:
|
|
46
|
+
return _model_id
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
async def load_model(hf_id: Optional[str] = None) -> None:
|
|
50
|
+
"""
|
|
51
|
+
Nothing to load locally: check the upstream answers and remember which model
|
|
52
|
+
to name. The configured id wins; otherwise ask /v1/models. mlx_lm.server
|
|
53
|
+
lists every cached model there, so the configured id is the reliable one.
|
|
54
|
+
"""
|
|
55
|
+
global _model_id
|
|
56
|
+
try:
|
|
57
|
+
async with _client() as c:
|
|
58
|
+
r = await c.get("/v1/models")
|
|
59
|
+
except httpx.HTTPError as e:
|
|
60
|
+
raise UpstreamError(503, f"LLM upstream {config.LLM_URL} unreachable: {e}") from e
|
|
61
|
+
if r.status_code != 200:
|
|
62
|
+
raise UpstreamError(503, f"LLM upstream {config.LLM_URL} returned HTTP {r.status_code}")
|
|
63
|
+
if hf_id:
|
|
64
|
+
_model_id = hf_id
|
|
65
|
+
return
|
|
66
|
+
data = (r.json() or {}).get("data") or []
|
|
67
|
+
_model_id = data[0]["id"] if data else "upstream"
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
def _body(messages, max_tokens, temperature, top_p, stream: bool) -> dict:
|
|
71
|
+
# No "model" field: mlx_lm.server would try to load whatever we name, which
|
|
72
|
+
# a sharded cluster can't do mid-flight. Omitted = the model it was started with.
|
|
73
|
+
body = {"messages": messages, "max_tokens": max_tokens,
|
|
74
|
+
"temperature": temperature, "top_p": top_p, "stream": stream}
|
|
75
|
+
if stream:
|
|
76
|
+
body["stream_options"] = {"include_usage": True}
|
|
77
|
+
return body
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
async def generate_chat(messages: List[dict], max_tokens: int = 512,
|
|
81
|
+
temperature: float = 0.7, top_p: float = 0.95) -> dict:
|
|
82
|
+
started = time.perf_counter()
|
|
83
|
+
try:
|
|
84
|
+
async with _client() as c:
|
|
85
|
+
r = await c.post("/v1/chat/completions",
|
|
86
|
+
json=_body(messages, max_tokens, temperature, top_p, False))
|
|
87
|
+
except httpx.HTTPError as e:
|
|
88
|
+
raise UpstreamError(502, f"LLM upstream error: {e}") from e
|
|
89
|
+
if r.status_code != 200:
|
|
90
|
+
raise UpstreamError(502, f"LLM upstream returned HTTP {r.status_code}: {r.text[:300]}")
|
|
91
|
+
out = r.json()
|
|
92
|
+
elapsed = time.perf_counter() - started
|
|
93
|
+
out["model"] = _model_id or out.get("model")
|
|
94
|
+
toks = (out.get("usage") or {}).get("completion_tokens")
|
|
95
|
+
out["cloxy_meta"] = {
|
|
96
|
+
"elapsed_seconds": round(elapsed, 3),
|
|
97
|
+
"tokens_per_second": round(toks / elapsed, 2) if toks and elapsed > 0 else None,
|
|
98
|
+
"upstream": config.LLM_URL,
|
|
99
|
+
}
|
|
100
|
+
return out
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
async def stream_chat(messages: List[dict], max_tokens: int = 512,
|
|
104
|
+
temperature: float = 0.7, top_p: float = 0.95,
|
|
105
|
+
) -> AsyncGenerator[StreamPiece, None]:
|
|
106
|
+
"""Relay the upstream SSE stream as StreamPiece fragments."""
|
|
107
|
+
finish, usage = None, None
|
|
108
|
+
try:
|
|
109
|
+
async with _client() as c:
|
|
110
|
+
async with c.stream("POST", "/v1/chat/completions",
|
|
111
|
+
json=_body(messages, max_tokens, temperature, top_p, True)) as r:
|
|
112
|
+
if r.status_code != 200:
|
|
113
|
+
detail = (await r.aread()).decode(errors="replace")[:300]
|
|
114
|
+
raise UpstreamError(502, f"LLM upstream returned HTTP {r.status_code}: {detail}")
|
|
115
|
+
async for line in r.aiter_lines():
|
|
116
|
+
if not line.startswith("data:"):
|
|
117
|
+
continue
|
|
118
|
+
payload = line[5:].strip()
|
|
119
|
+
if payload == "[DONE]":
|
|
120
|
+
break
|
|
121
|
+
try:
|
|
122
|
+
chunk = json.loads(payload)
|
|
123
|
+
except json.JSONDecodeError:
|
|
124
|
+
continue
|
|
125
|
+
usage = chunk.get("usage") or usage
|
|
126
|
+
for choice in chunk.get("choices") or []:
|
|
127
|
+
text = (choice.get("delta") or {}).get("content")
|
|
128
|
+
if text:
|
|
129
|
+
yield StreamPiece(text=text)
|
|
130
|
+
finish = choice.get("finish_reason") or finish
|
|
131
|
+
except httpx.HTTPError as e:
|
|
132
|
+
raise UpstreamError(502, f"LLM upstream error: {e}") from e
|
|
133
|
+
yield StreamPiece(text="", finish_reason=finish or "stop", usage=usage)
|
|
@@ -6,10 +6,14 @@ Cloxy CLI.
|
|
|
6
6
|
cloxy mcp run the MCP stdio server (for Claude Code, Cursor, ...)
|
|
7
7
|
cloxy recall "query" search memory from the shell
|
|
8
8
|
cloxy ingest [DIR] run an ingest pass now (the watcher does this live)
|
|
9
|
+
cloxy push mirror this machine's agent sessions to CLOXY_URL
|
|
9
10
|
cloxy status health + memory + watcher summary
|
|
10
11
|
cloxy install-service keep the server running via launchd (macOS)
|
|
11
12
|
cloxy uninstall-service
|
|
12
13
|
cloxy show / list current LLM config / model catalog
|
|
14
|
+
cloxy cluster setup|serve|status
|
|
15
|
+
shard one model across several Macs (MLX distributed:
|
|
16
|
+
JACCL over Thunderbolt 5, or ring over TCP)
|
|
13
17
|
"""
|
|
14
18
|
from __future__ import annotations
|
|
15
19
|
|
|
@@ -195,7 +199,12 @@ def cmd_status(args: argparse.Namespace) -> int:
|
|
|
195
199
|
try:
|
|
196
200
|
with _http() as c:
|
|
197
201
|
h = c.get("/health").json()
|
|
198
|
-
|
|
202
|
+
r = c.get("/memory_stats")
|
|
203
|
+
if r.status_code == 401:
|
|
204
|
+
print(f"cloxy v{h['version']} at {config.URL} is up, but rejected the API key. "
|
|
205
|
+
"Set CLOXY_API_KEY (or ~/.cloxy/client.env).")
|
|
206
|
+
return 1
|
|
207
|
+
s = r.json()
|
|
199
208
|
w = c.get("/ingest_status").json()
|
|
200
209
|
except httpx.ConnectError:
|
|
201
210
|
return _not_running()
|
|
@@ -266,6 +275,49 @@ def cmd_ingest(args: argparse.Namespace) -> int:
|
|
|
266
275
|
return 0
|
|
267
276
|
|
|
268
277
|
|
|
278
|
+
def cmd_push(args: argparse.Namespace) -> int:
|
|
279
|
+
import httpx
|
|
280
|
+
from . import push
|
|
281
|
+
|
|
282
|
+
if push.is_loopback_url(config.URL) and not args.force:
|
|
283
|
+
print(f"CLOXY_URL is {config.URL}: that server already watches this machine's "
|
|
284
|
+
"sessions.\nSet CLOXY_URL (and CLOXY_API_KEY) to the remote server in "
|
|
285
|
+
f"{config.DATA_DIR}/client.env, or pass --force.")
|
|
286
|
+
return 1
|
|
287
|
+
host = args.host or push.default_host()
|
|
288
|
+
|
|
289
|
+
def report(s: "push.PushSummary") -> None:
|
|
290
|
+
if s.files_pushed or s.errors or args.once:
|
|
291
|
+
print(f"push {host} → {config.URL}: {s.files_pushed}/{s.files_seen} files, "
|
|
292
|
+
f"{s.bytes_sent:,} bytes" + (f", {s.resyncs} resyncs" if s.resyncs else ""),
|
|
293
|
+
flush=True)
|
|
294
|
+
for e in s.errors[:10]:
|
|
295
|
+
print(f" error {e}", flush=True)
|
|
296
|
+
|
|
297
|
+
with _http() as c:
|
|
298
|
+
def post(payload: dict):
|
|
299
|
+
r = c.post("/push", json=payload)
|
|
300
|
+
try:
|
|
301
|
+
return r.status_code, r.json()
|
|
302
|
+
except ValueError:
|
|
303
|
+
return r.status_code, {"error": r.text[:200]}
|
|
304
|
+
try:
|
|
305
|
+
c.get("/health")
|
|
306
|
+
except httpx.ConnectError:
|
|
307
|
+
return _not_running()
|
|
308
|
+
if args.once:
|
|
309
|
+
s = push.push_once(post, host)
|
|
310
|
+
report(s)
|
|
311
|
+
return 1 if s.errors else 0
|
|
312
|
+
print(f"Pushing {', '.join(f'{a}={d}' for a, d in config.PUSH_SOURCES)} "
|
|
313
|
+
f"to {config.URL} as '{host}' every {args.interval:g}s (Ctrl-C to stop)")
|
|
314
|
+
try:
|
|
315
|
+
push.run_loop(post, host, args.interval, report)
|
|
316
|
+
except KeyboardInterrupt:
|
|
317
|
+
return 0
|
|
318
|
+
return 0
|
|
319
|
+
|
|
320
|
+
|
|
269
321
|
def cmd_reembed(args: argparse.Namespace) -> int:
|
|
270
322
|
"""
|
|
271
323
|
Offline: re-embed every memory with the configured model and prefix.
|
|
@@ -373,6 +425,81 @@ def cmd_uninstall_service(args: argparse.Namespace) -> int:
|
|
|
373
425
|
return 0
|
|
374
426
|
|
|
375
427
|
|
|
428
|
+
# =============================================================================
|
|
429
|
+
# MLX distributed cluster
|
|
430
|
+
# =============================================================================
|
|
431
|
+
|
|
432
|
+
def _run(argv: list) -> int:
|
|
433
|
+
print(" $ " + " ".join(argv) + "\n", flush=True)
|
|
434
|
+
try:
|
|
435
|
+
return subprocess.call(argv)
|
|
436
|
+
except FileNotFoundError:
|
|
437
|
+
print("mlx is not installed here. Run: pip install 'cloxy[mlx]'")
|
|
438
|
+
return 1
|
|
439
|
+
except KeyboardInterrupt:
|
|
440
|
+
return 130
|
|
441
|
+
|
|
442
|
+
|
|
443
|
+
def cmd_cluster_setup(args: argparse.Namespace) -> int:
|
|
444
|
+
from . import cluster
|
|
445
|
+
Path(args.hostfile).parent.mkdir(parents=True, exist_ok=True)
|
|
446
|
+
rc = _run(cluster.setup_argv(args.hosts, args.hostfile, over=args.over,
|
|
447
|
+
backend=args.backend, auto_setup=args.auto_setup,
|
|
448
|
+
verbose=args.verbose))
|
|
449
|
+
if rc == 0 and Path(args.hostfile).exists():
|
|
450
|
+
print(f"\nHostfile: {args.hostfile}")
|
|
451
|
+
for line in cluster.describe(cluster.read_hostfile(args.hostfile)):
|
|
452
|
+
print(line)
|
|
453
|
+
print("\nNext: cloxy cluster serve --model <hf-id>")
|
|
454
|
+
return rc
|
|
455
|
+
|
|
456
|
+
|
|
457
|
+
def cmd_cluster_serve(args: argparse.Namespace) -> int:
|
|
458
|
+
from . import cluster
|
|
459
|
+
if not Path(args.hostfile).exists():
|
|
460
|
+
print(f"No hostfile at {args.hostfile}. Run `cloxy cluster setup --hosts a,b,...` "
|
|
461
|
+
"first (or pass --hostfile).")
|
|
462
|
+
return 1
|
|
463
|
+
model = args.model or (_read_config() or {}).get("model_hf_id")
|
|
464
|
+
if not model:
|
|
465
|
+
print("No model. Pass --model <hf-id> or run `cloxy init`.")
|
|
466
|
+
return 1
|
|
467
|
+
hf = cluster.read_hostfile(args.hostfile)
|
|
468
|
+
backend = args.backend or hf.get("backend") or config.CLUSTER_BACKEND
|
|
469
|
+
url = cluster.rank0_url(hf, args.port)
|
|
470
|
+
pipeline = cluster.use_pipeline(backend, args.pipeline, args.tensor)
|
|
471
|
+
print(f"Serving {model} on {len(hf.get('hosts') or [])} Macs over {backend} "
|
|
472
|
+
f"({'pipeline' if pipeline else 'tensor'} parallel).")
|
|
473
|
+
if url:
|
|
474
|
+
print(f"Point cloxy at it: CLOXY_LLM_URL={url} (or http://127.0.0.1:{args.port} "
|
|
475
|
+
"if cloxy runs on rank 0)")
|
|
476
|
+
return _run(cluster.serve_argv(model, args.hostfile, args.port, backend=backend,
|
|
477
|
+
pipeline=pipeline, python=args.python,
|
|
478
|
+
extra=args.extra, verbose=args.verbose))
|
|
479
|
+
|
|
480
|
+
|
|
481
|
+
def cmd_cluster_status(args: argparse.Namespace) -> int:
|
|
482
|
+
import httpx
|
|
483
|
+
from . import cluster
|
|
484
|
+
if Path(args.hostfile).exists():
|
|
485
|
+
print(f"Hostfile: {args.hostfile}")
|
|
486
|
+
for line in cluster.describe(cluster.read_hostfile(args.hostfile)):
|
|
487
|
+
print(line)
|
|
488
|
+
else:
|
|
489
|
+
print(f"No hostfile at {args.hostfile}.")
|
|
490
|
+
if not config.LLM_URL:
|
|
491
|
+
print("CLOXY_LLM_URL not set — cloxy chat uses the in-process MLX model.")
|
|
492
|
+
return 0
|
|
493
|
+
headers = {"Authorization": f"Bearer {config.LLM_API_KEY}"} if config.LLM_API_KEY else {}
|
|
494
|
+
try:
|
|
495
|
+
r = httpx.get(f"{config.LLM_URL}/health", headers=headers, timeout=5)
|
|
496
|
+
state = "up" if r.status_code == 200 else f"HTTP {r.status_code}"
|
|
497
|
+
except httpx.HTTPError as e:
|
|
498
|
+
state = f"unreachable ({type(e).__name__})"
|
|
499
|
+
print(f"LLM upstream {config.LLM_URL}: {state}")
|
|
500
|
+
return 0 if state == "up" else 2
|
|
501
|
+
|
|
502
|
+
|
|
376
503
|
# =============================================================================
|
|
377
504
|
# Parser
|
|
378
505
|
# =============================================================================
|
|
@@ -410,9 +537,54 @@ def build_parser() -> argparse.ArgumentParser:
|
|
|
410
537
|
p.add_argument("--force", action="store_true", help="re-ingest from scratch")
|
|
411
538
|
p.set_defaults(func=cmd_ingest)
|
|
412
539
|
|
|
540
|
+
p = sub.add_parser("push", help="Mirror this machine's agent sessions to a remote "
|
|
541
|
+
"Cloxy server (CLOXY_URL)")
|
|
542
|
+
p.add_argument("--once", action="store_true", help="one pass, then exit (for cron)")
|
|
543
|
+
p.add_argument("--interval", type=float, default=config.PUSH_INTERVAL,
|
|
544
|
+
help=f"seconds between passes (default {config.PUSH_INTERVAL:g})")
|
|
545
|
+
p.add_argument("--host", help="name for this machine on the server (default: hostname)")
|
|
546
|
+
p.add_argument("--force", action="store_true", help="push even to a loopback CLOXY_URL")
|
|
547
|
+
p.set_defaults(func=cmd_push)
|
|
548
|
+
|
|
413
549
|
sub.add_parser("reembed", help="Re-embed all memories after changing the embedding "
|
|
414
550
|
"model or prefix (server stopped)").set_defaults(func=cmd_reembed)
|
|
415
551
|
|
|
552
|
+
p = sub.add_parser("cluster", help="Shard one model across several Macs (MLX distributed)")
|
|
553
|
+
csub = p.add_subparsers(dest="cluster_cmd", required=True)
|
|
554
|
+
from .cluster import BACKENDS
|
|
555
|
+
|
|
556
|
+
c = csub.add_parser("setup", help="Discover links between the Macs and write a hostfile")
|
|
557
|
+
c.add_argument("--hosts", required=True, help="comma-separated ssh names; first = rank 0")
|
|
558
|
+
c.add_argument("--over", choices=["thunderbolt", "ethernet"], default="thunderbolt")
|
|
559
|
+
c.add_argument("--backend", choices=BACKENDS, default=None,
|
|
560
|
+
help="jaccl = full TB5 mesh, jaccl-ring = TB5 ring (default: mlx picks)")
|
|
561
|
+
c.add_argument("--auto-setup", action="store_true",
|
|
562
|
+
help="let mlx configure the Thunderbolt interfaces (needs sudo on each Mac)")
|
|
563
|
+
c.add_argument("--hostfile", default=config.HOSTFILE)
|
|
564
|
+
c.add_argument("--verbose", action="store_true")
|
|
565
|
+
c.set_defaults(func=cmd_cluster_setup)
|
|
566
|
+
|
|
567
|
+
c = csub.add_parser("serve", help="Run mlx_lm.server across the hostfile (rank 0 serves HTTP)")
|
|
568
|
+
c.add_argument("--model", help="Hugging Face MLX id (default: `cloxy init` model)")
|
|
569
|
+
c.add_argument("--port", type=int, default=config.CLUSTER_PORT)
|
|
570
|
+
c.add_argument("--backend", choices=BACKENDS,
|
|
571
|
+
help=f"default: the hostfile's, else {config.CLUSTER_BACKEND}")
|
|
572
|
+
mode = c.add_mutually_exclusive_group()
|
|
573
|
+
mode.add_argument("--pipeline", action="store_true",
|
|
574
|
+
help="pipeline parallel: layers split, ~1 sync per token (default on ring)")
|
|
575
|
+
mode.add_argument("--tensor", action="store_true",
|
|
576
|
+
help="tensor parallel: dozens of syncs per token (default on jaccl)")
|
|
577
|
+
c.add_argument("--python", help="python on the remote Macs, if not this one's path")
|
|
578
|
+
c.add_argument("--hostfile", default=config.HOSTFILE)
|
|
579
|
+
c.add_argument("--verbose", action="store_true")
|
|
580
|
+
c.add_argument("extra", nargs=argparse.REMAINDER,
|
|
581
|
+
help="after --, extra mlx_lm server flags (e.g. -- --max-tokens 2048)")
|
|
582
|
+
c.set_defaults(func=cmd_cluster_serve)
|
|
583
|
+
|
|
584
|
+
c = csub.add_parser("status", help="Show the hostfile and whether CLOXY_LLM_URL answers")
|
|
585
|
+
c.add_argument("--hostfile", default=config.HOSTFILE)
|
|
586
|
+
c.set_defaults(func=cmd_cluster_status)
|
|
587
|
+
|
|
416
588
|
sub.add_parser("install-service", help="Run cloxy at login via launchd (macOS)") \
|
|
417
589
|
.set_defaults(func=cmd_install_service)
|
|
418
590
|
sub.add_parser("uninstall-service", help="Remove the launchd service") \
|