@spmos/local-proxy 0.1.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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Veridical Tech, Inc.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,97 @@
1
+ # SPM Local Proxy
2
+
3
+ SPM Local Proxy is a standalone terminal application that keeps the upstream
4
+ provider credential on the user's machine while using hosted SPM memory and
5
+ deterministic context compression.
6
+
7
+ ```text
8
+ Codex / Claude Code / SDK
9
+ |
10
+ | local harness token
11
+ v
12
+ http://127.0.0.1:8765/v1
13
+ |
14
+ +-- SPM key ------> api.spmos.ai memory
15
+ |
16
+ +-- provider key -> configured provider Base URL
17
+ ```
18
+
19
+ The proxy owns only the provider Base URL, provider API key, SPM key, and local
20
+ listener authentication. **It does not select, validate, cache, or rewrite a
21
+ model.** Downstream harnesses can call `GET /v1/models` through the proxy and
22
+ send their selected `model` unchanged in Chat Completions, Responses, or
23
+ Anthropic Messages requests.
24
+
25
+ ## Install
26
+
27
+ ```bash
28
+ npm install --global @spmos/local-proxy
29
+ spm
30
+ ```
31
+
32
+ The first run opens an English-only terminal wizard with blue SPM ASCII art.
33
+ Provider search is derived from the models.dev `models.json` dataset delivered
34
+ through jsDelivr, so it remains reachable in environments where `models.dev`
35
+ cannot be fetched directly. Catalog model counts are discovery metadata only;
36
+ model selection is never written to Local Proxy configuration.
37
+
38
+ ## Commands
39
+
40
+ ```bash
41
+ spm setup
42
+ spm start
43
+ spm catalog --refresh
44
+ spm config
45
+ spm config path
46
+ spm config token
47
+ spm doctor
48
+ spm print-config codex
49
+ spm print-config claude
50
+ ```
51
+
52
+ ## BYO provider configuration
53
+
54
+ The Custom BYO flow accepts:
55
+
56
+ - HTTPS Base URL
57
+ - OpenAI-compatible or Anthropic Messages wire API
58
+ - bearer, `x-api-key`, or `api-key` authentication
59
+ - API key
60
+ - custom headers as JSON
61
+ - query parameters as JSON
62
+
63
+ Use the literal value `$API_KEY` in a custom header or query parameter when the
64
+ provider requires its secret outside the standard authentication header.
65
+
66
+ ## Secret handling
67
+
68
+ The configuration is written atomically to
69
+ `$SPM_CONFIG_HOME/local-proxy.json`, `$XDG_CONFIG_HOME/spm/local-proxy.json`, or
70
+ `~/.config/spm/local-proxy.json`, with mode `0600` where supported. Secrets are
71
+ masked by `spm config` and request/response bodies are never logged.
72
+
73
+ The following environment variables override stored secrets:
74
+
75
+ ```text
76
+ SPM_API_KEY
77
+ SPM_LOCAL_PROVIDER_API_KEY
78
+ SPM_LOCAL_PROXY_TOKEN
79
+ ```
80
+
81
+ For the strongest process boundary, run the proxy in a dedicated shell or user
82
+ service and remove the provider/SPM keys from the downstream harness process.
83
+
84
+ ## Protocol and security behavior
85
+
86
+ - Listener binds only to `127.0.0.1`, `::1`, or `localhost`.
87
+ - Browser `Origin` requests and unexpected `Host` values are rejected.
88
+ - Provider endpoints must use HTTPS and resolve only to public addresses.
89
+ - Client, edge, cookie, and SPM headers are removed before provider egress.
90
+ - OpenAI Chat Completions, OpenAI Responses, and Anthropic Messages are supported.
91
+ - Codex zstd request bodies are decoded locally.
92
+ - Provider JSON response bytes and SSE chunks are relayed without reserialization.
93
+ - `previous_response_id` requests bypass recall mutation and compression.
94
+ - If hosted recall fails, the complete original request is forwarded unchanged.
95
+
96
+ SPM still receives recall queries and memory content. This package keeps the
97
+ provider credential local; it is not an offline or zero-disclosure memory mode.
package/bin/spm.js ADDED
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env node
2
+
3
+ import { main } from "../src/cli.js";
4
+
5
+ main(process.argv.slice(2)).catch((error) => {
6
+ const message = error instanceof Error ? error.message : "Unexpected failure";
7
+ process.stderr.write(`SPM: ${message}\n`);
8
+ process.exitCode = 1;
9
+ });
package/package.json ADDED
@@ -0,0 +1,48 @@
1
+ {
2
+ "name": "@spmos/local-proxy",
3
+ "version": "0.1.0",
4
+ "description": "Loopback-only SPM memory and compression proxy with local provider credentials",
5
+ "type": "module",
6
+ "license": "MIT",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://github.com/VeridicalTech/spm-local-proxy.git"
10
+ },
11
+ "homepage": "https://github.com/VeridicalTech/spm-local-proxy#readme",
12
+ "bugs": {
13
+ "url": "https://github.com/VeridicalTech/spm-local-proxy/issues"
14
+ },
15
+ "engines": {
16
+ "node": ">=22.15"
17
+ },
18
+ "bin": {
19
+ "spm": "bin/spm.js",
20
+ "spm-local-proxy": "bin/spm.js"
21
+ },
22
+ "exports": {
23
+ ".": "./src/index.js"
24
+ },
25
+ "files": [
26
+ "bin/",
27
+ "src/",
28
+ "README.md",
29
+ "LICENSE"
30
+ ],
31
+ "scripts": {
32
+ "test": "node --test",
33
+ "prepack": "npm test"
34
+ },
35
+ "publishConfig": {
36
+ "access": "public",
37
+ "provenance": true
38
+ },
39
+ "keywords": [
40
+ "spm",
41
+ "memory",
42
+ "llm",
43
+ "proxy",
44
+ "codex",
45
+ "claude-code",
46
+ "byo"
47
+ ]
48
+ }
package/src/catalog.js ADDED
@@ -0,0 +1,143 @@
1
+ import { randomBytes } from "node:crypto";
2
+ import { chmod, mkdir, readFile, rename, writeFile } from "node:fs/promises";
3
+ import { dirname, join } from "node:path";
4
+
5
+ import { configPath } from "./config.js";
6
+
7
+ export const MODELS_DEV_URL = "https://cdn.jsdelivr.net/gh/anomalyco/models.dev@dev/models.json";
8
+ const MAX_BYTES = 16 * 1024 * 1024;
9
+ const CACHE_TTL_MS = 24 * 60 * 60 * 1000;
10
+
11
+ const REVIEWED = {
12
+ openai: ["OpenAI", "https://api.openai.com/v1", "openai_compatible", "bearer"],
13
+ anthropic: ["Anthropic", "https://api.anthropic.com/v1", "anthropic_messages", "x-api-key"],
14
+ deepseek: ["DeepSeek", "https://api.deepseek.com/v1", "openai_compatible", "bearer"],
15
+ openrouter: ["OpenRouter", "https://openrouter.ai/api/v1", "openai_compatible", "bearer"],
16
+ groq: ["Groq", "https://api.groq.com/openai/v1", "openai_compatible", "bearer"],
17
+ mistral: ["Mistral", "https://api.mistral.ai/v1", "openai_compatible", "bearer"],
18
+ xai: ["xAI", "https://api.x.ai/v1", "openai_compatible", "bearer"],
19
+ togetherai: ["Together AI", "https://api.together.xyz/v1", "openai_compatible", "bearer"],
20
+ "fireworks-ai": ["Fireworks AI", "https://api.fireworks.ai/inference/v1", "openai_compatible", "bearer"],
21
+ moonshotai: ["Moonshot AI", "https://api.moonshot.cn/v1", "openai_compatible", "bearer"],
22
+ alibaba: ["Alibaba DashScope", "https://dashscope.aliyuncs.com/compatible-mode/v1", "openai_compatible", "bearer"],
23
+ };
24
+
25
+ export function catalogCachePath(env = process.env) {
26
+ return join(dirname(configPath(env)), "models-dev-providers.json");
27
+ }
28
+
29
+ function text(value) {
30
+ return typeof value === "string" ? value.trim() : "";
31
+ }
32
+
33
+ export function parseCatalog(payload) {
34
+ if (!payload || typeof payload !== "object" || Array.isArray(payload)) {
35
+ throw new Error("models.dev returned an invalid catalog");
36
+ }
37
+ let entries;
38
+ if (Object.hasOwn(payload, "data")) {
39
+ if (!Array.isArray(payload.data)) throw new Error("models.dev returned an invalid catalog");
40
+ const modelCounts = new Map();
41
+ for (const raw of payload.data) {
42
+ const modelId = text(raw?.id);
43
+ const separator = modelId.indexOf("/");
44
+ if (separator <= 0 || separator === modelId.length - 1) continue;
45
+ const providerId = modelId.slice(0, separator);
46
+ modelCounts.set(providerId, (modelCounts.get(providerId) || 0) + 1);
47
+ }
48
+ entries = [...modelCounts].map(([id, modelCount]) => [id, { id, modelCount }]);
49
+ } else {
50
+ entries = Object.entries(payload);
51
+ }
52
+ return entries.map(([key, raw]) => {
53
+ const value = raw && typeof raw === "object" ? raw : {};
54
+ const id = text(value.id) || key;
55
+ const reviewed = REVIEWED[id] || REVIEWED[key];
56
+ const rawBaseUrl = text(value.api) || text(value.base_url) || text(value.baseURL);
57
+ const models = Number.isInteger(value.modelCount)
58
+ ? value.modelCount
59
+ : value.models && typeof value.models === "object"
60
+ ? Object.keys(value.models).length : 0;
61
+ return {
62
+ id,
63
+ name: reviewed?.[0] || text(value.name) || id,
64
+ baseUrl: reviewed?.[1] || rawBaseUrl,
65
+ apiStyle: reviewed?.[2] || "",
66
+ authScheme: reviewed?.[3] || "",
67
+ reviewed: Boolean(reviewed),
68
+ modelCount: models,
69
+ docs: text(value.doc) || text(value.docs),
70
+ env: Array.isArray(value.env) ? value.env.map(String) : [],
71
+ };
72
+ }).sort((left, right) => left.name.localeCompare(right.name));
73
+ }
74
+
75
+ async function fetchPayload(fetchImpl, url = MODELS_DEV_URL) {
76
+ let current = new URL(url);
77
+ const trustedOrigin = current.origin;
78
+ for (let redirects = 0; redirects < 3; redirects += 1) {
79
+ const response = await fetchImpl(current, {
80
+ redirect: "manual",
81
+ signal: AbortSignal.timeout(15_000),
82
+ headers: { accept: "application/json" },
83
+ });
84
+ if ([301, 302, 303, 307, 308].includes(response.status)) {
85
+ const next = new URL(response.headers.get("location"), current);
86
+ if (next.protocol !== "https:" || next.origin !== trustedOrigin) {
87
+ throw new Error("models.dev redirect left the trusted origin");
88
+ }
89
+ current = next;
90
+ continue;
91
+ }
92
+ if (!response.ok) throw new Error(`models.dev returned HTTP ${response.status}`);
93
+ const declared = Number(response.headers.get("content-length") || 0);
94
+ if (declared > MAX_BYTES) throw new Error("models.dev catalog exceeds the size limit");
95
+ const bytes = new Uint8Array(await response.arrayBuffer());
96
+ if (bytes.byteLength > MAX_BYTES) throw new Error("models.dev catalog exceeds the size limit");
97
+ return JSON.parse(new TextDecoder().decode(bytes));
98
+ }
99
+ throw new Error("models.dev redirect chain did not resolve");
100
+ }
101
+
102
+ async function writeCache(path, catalog) {
103
+ const wrapper = {
104
+ version: 1,
105
+ fetchedAt: new Date().toISOString(),
106
+ providers: catalog,
107
+ };
108
+ await mkdir(dirname(path), { recursive: true, mode: 0o700 });
109
+ const temporary = `${path}.${process.pid}.${randomBytes(4).toString("hex")}.tmp`;
110
+ await writeFile(temporary, `${JSON.stringify(wrapper)}\n`, { mode: 0o600, flag: "wx" });
111
+ await rename(temporary, path);
112
+ await chmod(path, 0o600).catch(() => {});
113
+ }
114
+
115
+ export async function getProviderCatalog({
116
+ fetchImpl = globalThis.fetch,
117
+ cachePath = catalogCachePath(),
118
+ refresh = false,
119
+ } = {}) {
120
+ if (!refresh) {
121
+ try {
122
+ const cached = JSON.parse(await readFile(cachePath, "utf8"));
123
+ const age = Date.now() - Date.parse(cached.fetchedAt);
124
+ if (cached.version === 1 && Array.isArray(cached.providers) && age < CACHE_TTL_MS) {
125
+ return { providers: cached.providers, source: "cache", fetchedAt: cached.fetchedAt };
126
+ }
127
+ } catch {}
128
+ }
129
+ try {
130
+ const providers = parseCatalog(await fetchPayload(fetchImpl));
131
+ if (!providers.length) throw new Error("models.dev catalog is empty");
132
+ await writeCache(cachePath, providers);
133
+ return { providers, source: "models.dev", fetchedAt: new Date().toISOString() };
134
+ } catch (error) {
135
+ try {
136
+ const cached = JSON.parse(await readFile(cachePath, "utf8"));
137
+ if (cached.version === 1 && Array.isArray(cached.providers)) {
138
+ return { providers: cached.providers, source: "stale-cache", fetchedAt: cached.fetchedAt };
139
+ }
140
+ } catch {}
141
+ throw error;
142
+ }
143
+ }
package/src/cli.js ADDED
@@ -0,0 +1,237 @@
1
+ import { access } from "node:fs/promises";
2
+
3
+ import { getProviderCatalog } from "./catalog.js";
4
+ import {
5
+ configPath,
6
+ loadConfig,
7
+ maskedConfig,
8
+ newLocalToken,
9
+ saveConfig,
10
+ } from "./config.js";
11
+ import { createGateway, listenGateway } from "./gateway.js";
12
+ import { blue, logo, promptLine, promptSecret, searchMenu } from "./terminal.js";
13
+
14
+ const HELP = `Usage: spm [command]
15
+
16
+ Commands:
17
+ setup Configure provider endpoint/key and SPM key
18
+ start Start the loopback Local Proxy
19
+ catalog [--refresh] Search models.dev providers (models stay downstream)
20
+ config Show the current configuration with masked secrets
21
+ config path Print the configuration path
22
+ config token Print the local harness token
23
+ doctor Validate configuration and runtime requirements
24
+ print-config codex Print Codex custom-provider configuration
25
+ print-config claude Print Claude Code environment configuration
26
+ help Show this help
27
+
28
+ The Local Proxy never selects or rewrites a model. Downstream harnesses fetch
29
+ /v1/models and send their chosen model in each request.`;
30
+
31
+ function choice(value, allowed, fallback) {
32
+ const normalized = value.trim().toLowerCase();
33
+ return allowed.includes(normalized) ? normalized : fallback;
34
+ }
35
+
36
+ async function objectPrompt(label, defaultValue = {}) {
37
+ const answer = await promptLine(label, {
38
+ defaultValue: Object.keys(defaultValue).length ? JSON.stringify(defaultValue) : "{}",
39
+ });
40
+ let parsed;
41
+ try { parsed = JSON.parse(answer); } catch { throw new Error(`${label} must be valid JSON`); }
42
+ if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
43
+ throw new Error(`${label} must be a JSON object`);
44
+ }
45
+ return parsed;
46
+ }
47
+
48
+ async function selectProvider(refresh = false) {
49
+ let providers = [];
50
+ let source = "unavailable";
51
+ try {
52
+ const catalog = await getProviderCatalog({ refresh });
53
+ providers = catalog.providers;
54
+ source = catalog.source;
55
+ } catch (error) {
56
+ process.stdout.write(`models.dev unavailable: ${error.message}\nBYO configuration remains available.\n`);
57
+ }
58
+ const custom = {
59
+ id: "custom-byo",
60
+ name: "Custom BYO provider",
61
+ baseUrl: "",
62
+ apiStyle: "",
63
+ authScheme: "",
64
+ reviewed: true,
65
+ modelCount: 0,
66
+ custom: true,
67
+ };
68
+ const selected = await searchMenu({
69
+ title: `Provider configuration · models.dev source: ${source}`,
70
+ items: [custom, ...providers],
71
+ fields: ["id", "name", "baseUrl"],
72
+ render: (item) => item.custom
73
+ ? blue("Custom BYO provider")
74
+ : `${item.name} (${item.id}) · ${item.modelCount} catalog models${item.reviewed ? "" : " · transport confirmation required"}`,
75
+ });
76
+ return selected;
77
+ }
78
+
79
+ export async function setup({ refresh = false } = {}) {
80
+ logo();
81
+ process.stdout.write("Configure only provider transport and SPM memory. Model discovery and selection remain downstream.\n");
82
+ const selected = await selectProvider(refresh);
83
+ if (!selected.custom && !selected.reviewed) {
84
+ process.stdout.write("\nThis provider is present in models.dev, but its wire protocol is not pre-approved by SPM. Confirm an OpenAI-compatible or Anthropic Messages endpoint before use.\n");
85
+ }
86
+ const providerName = selected.custom
87
+ ? await promptLine("Provider name", { defaultValue: "Custom provider" })
88
+ : selected.name;
89
+ const providerId = selected.custom ? "custom" : selected.id;
90
+ const baseUrl = await promptLine("Provider Base URL", { defaultValue: selected.baseUrl || "https://" });
91
+ const styleDefault = selected.apiStyle || "openai_compatible";
92
+ const apiStyle = choice(
93
+ await promptLine("API style (openai_compatible/anthropic_messages)", { defaultValue: styleDefault }),
94
+ ["openai_compatible", "anthropic_messages"],
95
+ styleDefault,
96
+ );
97
+ const authDefault = selected.authScheme || (apiStyle === "anthropic_messages" ? "x-api-key" : "bearer");
98
+ const authScheme = choice(
99
+ await promptLine("Auth scheme (bearer/x-api-key/api-key)", { defaultValue: authDefault }),
100
+ ["bearer", "x-api-key", "api-key"],
101
+ authDefault,
102
+ );
103
+ const providerApiKey = await promptSecret("Provider API key");
104
+ const spmApiKey = await promptSecret("SPM API key");
105
+ const customHeaders = selected.custom ? await objectPrompt("Custom headers JSON") : {};
106
+ const queryParams = selected.custom ? await objectPrompt("Query parameters JSON") : {};
107
+ const port = Number(await promptLine("Local Proxy port", { defaultValue: "8765" }));
108
+ const inputBudgetTokens = Number(await promptLine("Compression input budget", { defaultValue: "8192" }));
109
+ const config = await saveConfig({
110
+ version: 1,
111
+ spm: { apiKey: spmApiKey, baseUrl: "https://api.spmos.ai" },
112
+ provider: {
113
+ id: providerId,
114
+ name: providerName,
115
+ source: selected.custom ? "byo" : "models.dev",
116
+ baseUrl,
117
+ apiStyle,
118
+ authScheme,
119
+ apiKey: providerApiKey,
120
+ customHeaders,
121
+ queryParams,
122
+ },
123
+ proxy: {
124
+ host: "127.0.0.1",
125
+ port,
126
+ localToken: newLocalToken(),
127
+ inputBudgetTokens,
128
+ maxRecalledTokens: 512,
129
+ memoryMode: "read-write",
130
+ compressionMode: "deterministic",
131
+ },
132
+ });
133
+ process.stdout.write(`\n${blue("Configuration saved")} · ${configPath()}\n`);
134
+ process.stdout.write("The provider key and SPM key are stored in a mode-0600 file. Environment variables can override them.\n");
135
+ return config;
136
+ }
137
+
138
+ export async function start() {
139
+ const config = await loadConfig();
140
+ logo();
141
+ const server = createGateway({ config });
142
+ await listenGateway(server, config.proxy);
143
+ process.stdout.write(`${blue("SPM Local Proxy is running")}\n`);
144
+ process.stdout.write(` URL: http://${config.proxy.host}:${config.proxy.port}/v1\n`);
145
+ process.stdout.write(` Provider: ${config.provider.name}\n`);
146
+ process.stdout.write(` Base URL: ${config.provider.baseUrl}\n`);
147
+ process.stdout.write(" Models: downstream discovery via GET /v1/models; request model is never rewritten\n");
148
+ process.stdout.write(" Logs: request and response bodies disabled\n\nPress Ctrl+C to stop.\n");
149
+ const close = () => server.close(() => process.exit(0));
150
+ process.once("SIGINT", close);
151
+ process.once("SIGTERM", close);
152
+ return server;
153
+ }
154
+
155
+ async function catalogCommand(refresh) {
156
+ logo();
157
+ const catalog = await getProviderCatalog({ refresh });
158
+ const selected = await searchMenu({
159
+ title: `models.dev providers · ${catalog.source}`,
160
+ items: catalog.providers,
161
+ fields: ["id", "name", "baseUrl"],
162
+ render: (item) => `${item.name} (${item.id}) · ${item.modelCount} catalog models · ${item.baseUrl || "endpoint not declared"}`,
163
+ });
164
+ process.stdout.write(`${JSON.stringify(selected, null, 2)}\n`);
165
+ }
166
+
167
+ function printHarnessConfig(harness, config) {
168
+ const local = `http://${config.proxy.host}:${config.proxy.port}`;
169
+ if (harness === "codex") {
170
+ process.stdout.write(`[model_providers.spm_local]\nname = "SPM Local Proxy"\nbase_url = "${local}/v1"\nenv_key = "SPM_LOCAL_PROXY_TOKEN"\nwire_api = "responses"\n`);
171
+ return;
172
+ }
173
+ process.stdout.write(`ANTHROPIC_BASE_URL="${local}"\nANTHROPIC_API_KEY="$SPM_LOCAL_PROXY_TOKEN"\n`);
174
+ }
175
+
176
+ async function exists(path) {
177
+ try { await access(path); return true; } catch { return false; }
178
+ }
179
+
180
+ export async function main(args = []) {
181
+ const command = args[0] || "default";
182
+ if (["help", "--help", "-h"].includes(command)) {
183
+ logo();
184
+ process.stdout.write(`${HELP}\n`);
185
+ return;
186
+ }
187
+ if (command === "setup") {
188
+ await setup({ refresh: args.includes("--refresh") });
189
+ return;
190
+ }
191
+ if (command === "start") {
192
+ await start();
193
+ return;
194
+ }
195
+ if (command === "catalog") {
196
+ await catalogCommand(args.includes("--refresh"));
197
+ return;
198
+ }
199
+ if (command === "config") {
200
+ const subcommand = args[1] || "show";
201
+ if (subcommand === "path") {
202
+ process.stdout.write(`${configPath()}\n`);
203
+ return;
204
+ }
205
+ const config = await loadConfig();
206
+ if (subcommand === "token") {
207
+ process.stdout.write(`${config.proxy.localToken}\n`);
208
+ return;
209
+ }
210
+ logo();
211
+ process.stdout.write(`${JSON.stringify(maskedConfig(config), null, 2)}\n`);
212
+ return;
213
+ }
214
+ if (command === "doctor") {
215
+ logo();
216
+ const config = await loadConfig();
217
+ process.stdout.write(`${blue("PASS")} configuration schema\n`);
218
+ process.stdout.write(`${blue("PASS")} loopback-only listener ${config.proxy.host}:${config.proxy.port}\n`);
219
+ process.stdout.write(`${blue("PASS")} provider protocol ${config.provider.apiStyle}\n`);
220
+ process.stdout.write(`${blue("PASS")} model ownership remains downstream\n`);
221
+ return;
222
+ }
223
+ if (command === "print-config") {
224
+ const harness = args[1];
225
+ if (!new Set(["codex", "claude", "claude-code"]).has(harness)) {
226
+ throw new Error("print-config requires codex or claude");
227
+ }
228
+ printHarnessConfig(harness === "codex" ? "codex" : "claude", await loadConfig());
229
+ return;
230
+ }
231
+ if (command === "default") {
232
+ if (!await exists(configPath())) await setup();
233
+ await start();
234
+ return;
235
+ }
236
+ throw new Error(`Unknown command: ${command}`);
237
+ }