@lunaroute/cli 0.14.3 → 0.14.5
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/dist/index.js +382 -135
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
import { Command, InvalidArgumentError, Option } from "commander";
|
|
5
5
|
|
|
6
6
|
// package.json
|
|
7
|
-
var version = "0.14.
|
|
7
|
+
var version = "0.14.5";
|
|
8
8
|
|
|
9
9
|
// src/login.ts
|
|
10
10
|
import { createServer } from "http";
|
|
@@ -1031,6 +1031,10 @@ var LUNAROUTE_SKILL_NAME = "lunaroute-memory";
|
|
|
1031
1031
|
function claudeUserConfigPath() {
|
|
1032
1032
|
return join3(homedir2(), ".claude.json");
|
|
1033
1033
|
}
|
|
1034
|
+
function claudeSettingsPath() {
|
|
1035
|
+
const home = process.env.CLAUDE_CONFIG_DIR || join3(homedir2(), ".claude");
|
|
1036
|
+
return join3(home, "settings.json");
|
|
1037
|
+
}
|
|
1034
1038
|
function claudeUserSkillPath(name = LUNAROUTE_SKILL_NAME) {
|
|
1035
1039
|
return join3(homedir2(), ".claude", "skills", name, "SKILL.md");
|
|
1036
1040
|
}
|
|
@@ -1093,6 +1097,11 @@ function resolveClaudeDesktopAppliedProfile(platform = process.platform) {
|
|
|
1093
1097
|
if (!isRegularFile(candidate)) return null;
|
|
1094
1098
|
return dirname2(realpathSync(candidate)) === realpathSync(claudeDesktopConfigLibraryDir()) ? candidate : null;
|
|
1095
1099
|
}
|
|
1100
|
+
var CLAUDE_DESKTOP_NO_PROFILE = "Claude Desktop has not created a third-party inference profile yet \u2014 in Desktop open Help \u2192 Troubleshooting \u2192 Enable Developer Mode, then Developer \u2192 Configure Third-Party Inference once; then re-run.";
|
|
1101
|
+
var CLAUDE_DESKTOP_UNVERIFIED_PLATFORM = "The Claude Desktop profile path is verified on Linux only \u2014 this platform's path is unverified (kata yc1y), so the CLI will not guess it. Configure Desktop by hand instead: Help \u2192 Troubleshooting \u2192 Enable Developer Mode, then Developer \u2192 Configure Third-Party Inference.";
|
|
1102
|
+
function claudeDesktopRefusal() {
|
|
1103
|
+
return process.platform === "linux" ? CLAUDE_DESKTOP_NO_PROFILE : CLAUDE_DESKTOP_UNVERIFIED_PLATFORM;
|
|
1104
|
+
}
|
|
1096
1105
|
|
|
1097
1106
|
// src/setup/adapters/opencode.ts
|
|
1098
1107
|
var EXTENSION = "@lunaroute/opencode-extension";
|
|
@@ -1110,13 +1119,13 @@ function extensionPlan(ctx) {
|
|
|
1110
1119
|
jsonc: true,
|
|
1111
1120
|
// opencode documents JSONC config
|
|
1112
1121
|
merge: (existing) => {
|
|
1113
|
-
const
|
|
1114
|
-
const raw =
|
|
1122
|
+
const obj2 = existing ?? {};
|
|
1123
|
+
const raw = obj2.plugin;
|
|
1115
1124
|
const plugins = Array.isArray(raw) ? raw : typeof raw === "string" ? [raw] : [];
|
|
1116
1125
|
if (!plugins.includes(EXTENSION)) plugins.push(EXTENSION);
|
|
1117
|
-
const next = { ...
|
|
1126
|
+
const next = { ...obj2, plugin: plugins };
|
|
1118
1127
|
if (!isProdGateway(ctx.routingUrl)) {
|
|
1119
|
-
const providers = objectOrEmpty(
|
|
1128
|
+
const providers = objectOrEmpty(obj2.provider);
|
|
1120
1129
|
const lr = objectOrEmpty(providers.lunaroute);
|
|
1121
1130
|
next.provider = {
|
|
1122
1131
|
...providers,
|
|
@@ -1167,10 +1176,10 @@ function providerPlan(ctx) {
|
|
|
1167
1176
|
jsonc: true,
|
|
1168
1177
|
// opencode documents JSONC config
|
|
1169
1178
|
merge: (existing) => {
|
|
1170
|
-
const
|
|
1171
|
-
const existingProviders = objectOrEmpty(
|
|
1179
|
+
const obj2 = existing ?? {};
|
|
1180
|
+
const existingProviders = objectOrEmpty(obj2.provider);
|
|
1172
1181
|
const provider = { ...existingProviders, lunaroute: block };
|
|
1173
|
-
return { ...
|
|
1182
|
+
return { ...obj2, provider };
|
|
1174
1183
|
}
|
|
1175
1184
|
}
|
|
1176
1185
|
],
|
|
@@ -1187,9 +1196,9 @@ function buildKeyPlan(key2) {
|
|
|
1187
1196
|
kind: "json",
|
|
1188
1197
|
path: opencodeAuthPath(),
|
|
1189
1198
|
merge: (existing) => {
|
|
1190
|
-
const
|
|
1191
|
-
delete
|
|
1192
|
-
return { ...
|
|
1199
|
+
const obj2 = existing ?? {};
|
|
1200
|
+
delete obj2["lunaroute/"];
|
|
1201
|
+
return { ...obj2, lunaroute: { type: "api", key: key2 } };
|
|
1193
1202
|
}
|
|
1194
1203
|
}
|
|
1195
1204
|
],
|
|
@@ -1262,10 +1271,10 @@ function buildPlan2(ctx) {
|
|
|
1262
1271
|
kind: "json",
|
|
1263
1272
|
path: piModelsPath(),
|
|
1264
1273
|
merge: (existing) => {
|
|
1265
|
-
const
|
|
1266
|
-
const existingProviders = typeof
|
|
1274
|
+
const obj2 = existing ?? {};
|
|
1275
|
+
const existingProviders = typeof obj2.providers === "object" && obj2.providers !== null ? obj2.providers : {};
|
|
1267
1276
|
const providers = { ...existingProviders, lunaroute: block };
|
|
1268
|
-
return { ...
|
|
1277
|
+
return { ...obj2, providers };
|
|
1269
1278
|
}
|
|
1270
1279
|
}
|
|
1271
1280
|
],
|
|
@@ -1275,8 +1284,8 @@ function buildPlan2(ctx) {
|
|
|
1275
1284
|
}
|
|
1276
1285
|
function stalePiProviderExists() {
|
|
1277
1286
|
try {
|
|
1278
|
-
const
|
|
1279
|
-
return Boolean(
|
|
1287
|
+
const obj2 = JSON.parse(readFileSync5(piModelsPath(), "utf8"));
|
|
1288
|
+
return Boolean(obj2.providers?.lunaroute);
|
|
1280
1289
|
} catch {
|
|
1281
1290
|
return false;
|
|
1282
1291
|
}
|
|
@@ -1288,10 +1297,10 @@ function buildStaleProviderCleanupPlan() {
|
|
|
1288
1297
|
kind: "json",
|
|
1289
1298
|
path: piModelsPath(),
|
|
1290
1299
|
merge: (existing) => {
|
|
1291
|
-
const
|
|
1292
|
-
const providers = { ...
|
|
1300
|
+
const obj2 = existing ?? {};
|
|
1301
|
+
const providers = { ...obj2.providers };
|
|
1293
1302
|
delete providers.lunaroute;
|
|
1294
|
-
const next = { ...
|
|
1303
|
+
const next = { ...obj2 };
|
|
1295
1304
|
if (Object.keys(providers).length > 0) next.providers = providers;
|
|
1296
1305
|
else delete next.providers;
|
|
1297
1306
|
return next;
|
|
@@ -1312,9 +1321,9 @@ function buildKeyPlan2(key2) {
|
|
|
1312
1321
|
kind: "json",
|
|
1313
1322
|
path: piAuthPath(),
|
|
1314
1323
|
merge: (existing) => {
|
|
1315
|
-
const
|
|
1324
|
+
const obj2 = existing ?? {};
|
|
1316
1325
|
return {
|
|
1317
|
-
...
|
|
1326
|
+
...obj2,
|
|
1318
1327
|
lunaroute: { type: "oauth", access: key2, refresh: "", expires: Date.now() + KEY_EXPIRES_MS }
|
|
1319
1328
|
};
|
|
1320
1329
|
}
|
|
@@ -1336,6 +1345,43 @@ function requireFirstModel(ctx, harness) {
|
|
|
1336
1345
|
return first;
|
|
1337
1346
|
}
|
|
1338
1347
|
|
|
1348
|
+
// src/model-picker.ts
|
|
1349
|
+
var LUNAROUTE_ROW_DESCRIPTION = "Managed by LunaRoute";
|
|
1350
|
+
function rows(models) {
|
|
1351
|
+
return models.map((m) => ({
|
|
1352
|
+
model: m.id,
|
|
1353
|
+
label: m.display_name || m.id,
|
|
1354
|
+
description: LUNAROUTE_ROW_DESCRIPTION
|
|
1355
|
+
}));
|
|
1356
|
+
}
|
|
1357
|
+
function obj(value) {
|
|
1358
|
+
return value !== null && typeof value === "object" && !Array.isArray(value) ? value : null;
|
|
1359
|
+
}
|
|
1360
|
+
function isRow(value) {
|
|
1361
|
+
return obj(value) !== null && typeof value.model === "string";
|
|
1362
|
+
}
|
|
1363
|
+
function claudeModelPicker(models) {
|
|
1364
|
+
return { replaceBuiltInOptions: true, options: rows(models) };
|
|
1365
|
+
}
|
|
1366
|
+
function mergeClaudeModelPickerSettings(existing, models) {
|
|
1367
|
+
const settings = obj(existing) ?? {};
|
|
1368
|
+
const prior = obj(settings.modelPicker) ?? {};
|
|
1369
|
+
const priorRows = (Array.isArray(prior.options) ? prior.options : []).filter(isRow);
|
|
1370
|
+
const current = new Set(rows(models).map((row) => row.model));
|
|
1371
|
+
const kept = priorRows.filter(
|
|
1372
|
+
(row) => row.description !== LUNAROUTE_ROW_DESCRIPTION || current.has(row.model)
|
|
1373
|
+
);
|
|
1374
|
+
const listed = new Set(kept.map((row) => row.model));
|
|
1375
|
+
return {
|
|
1376
|
+
...settings,
|
|
1377
|
+
modelPicker: {
|
|
1378
|
+
...prior,
|
|
1379
|
+
replaceBuiltInOptions: typeof prior.replaceBuiltInOptions === "boolean" ? prior.replaceBuiltInOptions : true,
|
|
1380
|
+
options: [...kept, ...rows(models).filter((row) => !listed.has(row.model))]
|
|
1381
|
+
}
|
|
1382
|
+
};
|
|
1383
|
+
}
|
|
1384
|
+
|
|
1339
1385
|
// src/setup/adapters/claudeCode.ts
|
|
1340
1386
|
function buildPlan3(ctx) {
|
|
1341
1387
|
const firstModel = requireFirstModel(ctx, "claude-code");
|
|
@@ -1344,7 +1390,19 @@ function buildPlan3(ctx) {
|
|
|
1344
1390
|
const windowTokens = row?.context_window_tokens && row.context_window_tokens > 0 ? row.context_window_tokens : void 0;
|
|
1345
1391
|
const outputTokens = row?.max_output_tokens && row.max_output_tokens > 0 ? row.max_output_tokens : void 0;
|
|
1346
1392
|
return {
|
|
1347
|
-
|
|
1393
|
+
// The `/model` picker list. Claude Code reads `modelPicker` from user
|
|
1394
|
+
// settings, takes each row's `model` verbatim and applies no id filter —
|
|
1395
|
+
// the only way a routed (BYOK) model can appear, since discovery keeps only
|
|
1396
|
+
// ids containing "claude"/"anthropic" (kata 4sak) and the alias catalog
|
|
1397
|
+
// only knows rows with a stored `claude_alias` (kata qqs5). Merged, never
|
|
1398
|
+
// replaced: this file also holds the user's permissions, hooks and theme.
|
|
1399
|
+
fileWrites: [
|
|
1400
|
+
{
|
|
1401
|
+
kind: "json",
|
|
1402
|
+
path: claudeSettingsPath(),
|
|
1403
|
+
merge: (existing) => mergeClaudeModelPickerSettings(existing, ctx.models)
|
|
1404
|
+
}
|
|
1405
|
+
],
|
|
1348
1406
|
exports: [
|
|
1349
1407
|
{ name: ctx.keyEnvVar, value: "__KEY__" },
|
|
1350
1408
|
// Point at the routing root; Claude Code appends /v1/messages itself.
|
|
@@ -1406,7 +1464,8 @@ function buildPlan3(ctx) {
|
|
|
1406
1464
|
...windowTokens || outputTokens ? [
|
|
1407
1465
|
"CLAUDE_CODE_MAX_CONTEXT_TOKENS / CLAUDE_CODE_MAX_OUTPUT_TOKENS carry the pinned model's real window and output cap: Claude Code otherwise assumes 200K and asks for 32K whatever /v1/models reports. They describe ANTHROPIC_MODEL, not the Claude-shaped alias ids the /model picker lists (Claude Code ignores the window variable for those, and for any id it recognizes as a Claude model \u2014 those run at their built-in window), and one value serves the whole session \u2014 re-run setup when you switch to a model with a different window or output cap. Claude Code clamps the output value to its own maximum, and a bigger output cap leaves less context before compaction."
|
|
1408
1466
|
] : [],
|
|
1409
|
-
"ANTHROPIC_CUSTOM_HEADERS carries X-LunaRoute-Client: claude-desktop so the /model picker's gateway discovery returns Claude-shaped alias ids instead of an empty list: Claude Code drops any discovered id without 'claude'/'anthropic' in it, and LunaRoute's normal catalog has none. The aliases route back to the real model at the gateway \u2014 pick one in /model like any other, or set ANTHROPIC_MODEL to a plain model id to skip the aliases.",
|
|
1467
|
+
"ANTHROPIC_CUSTOM_HEADERS carries X-LunaRoute-Client: claude-desktop so the /model picker's gateway discovery returns Claude-shaped alias ids instead of an empty list: Claude Code drops any discovered id without 'claude'/'anthropic' in it, and LunaRoute's normal catalog has none. The aliases route back to the real model at the gateway \u2014 pick one in /model like any other, or set ANTHROPIC_MODEL to a plain model id to skip the aliases. This is the fallback for builds older than 2.1.242, which ignore the lineup below.",
|
|
1468
|
+
"~/.claude/settings.json now carries a modelPicker lineup of every model your org can reach (Claude Code 2.1.242+), so /model lists every one of them \u2014 routed/BYOK models included, not just the aliases (the row label is the model's display name where the catalog carries one). Any rows you already had are kept as they are; ours are added or removed on every run to match your catalog (a model that left it drops out of the picker; a row we added keeps its label). It replaces the discovered list; re-run setup, or use `lunaroute run claude` (which passes the same lineup for one session), when your catalog changes.",
|
|
1410
1469
|
"ANTHROPIC_DEFAULT_HAIKU_MODEL pins Claude Code's background model (titles, summaries, compaction, the auxiliary classifier) \u2014 it defaults to your main model, and you can point it at a smaller/faster model from the list above.",
|
|
1411
1470
|
"(Auth travels in the Authorization: Bearer header via ANTHROPIC_AUTH_TOKEN.)",
|
|
1412
1471
|
"CLAUDE_CODE_GATEWAY_HINT_HEADERS=1 makes Claude Code label its auxiliary requests (the auto-mode safety classifier) so LunaRoute can route them to a fast path; without it they are still detected via their wire marker, just less directly.",
|
|
@@ -1426,9 +1485,9 @@ function buildPlan3(ctx) {
|
|
|
1426
1485
|
|
|
1427
1486
|
// src/setup/routing-url.ts
|
|
1428
1487
|
function validatedRoutingUrl(routingUrl) {
|
|
1429
|
-
function fail2(
|
|
1488
|
+
function fail2(reason2) {
|
|
1430
1489
|
throw new Error(
|
|
1431
|
-
`routingUrl rejected (reason: ${
|
|
1490
|
+
`routingUrl rejected (reason: ${reason2}; <redacted URL>) \u2014 check --routing-url or the profile's routing URL`
|
|
1432
1491
|
);
|
|
1433
1492
|
}
|
|
1434
1493
|
if (!/^https?:\/\/[^/?#]/.test(routingUrl)) fail2("invalid-url");
|
|
@@ -1510,9 +1569,9 @@ function buildKeyPlan3(routingUrl, key2, appliedPath) {
|
|
|
1510
1569
|
`refusing to modify ${appliedPath}: it is valid JSON but not a JSON object.`
|
|
1511
1570
|
);
|
|
1512
1571
|
}
|
|
1513
|
-
const
|
|
1514
|
-
const existingHeaders = typeof
|
|
1515
|
-
return { ...
|
|
1572
|
+
const obj2 = existing;
|
|
1573
|
+
const existingHeaders = typeof obj2.inferenceCustomHeaders === "object" && obj2.inferenceCustomHeaders !== null && !Array.isArray(obj2.inferenceCustomHeaders) ? obj2.inferenceCustomHeaders : {};
|
|
1574
|
+
return { ...obj2, ...ours, inferenceCustomHeaders: { ...existingHeaders, ...ourHeaders } };
|
|
1516
1575
|
}
|
|
1517
1576
|
}
|
|
1518
1577
|
],
|
|
@@ -1639,14 +1698,14 @@ function buildPlan8(ctx) {
|
|
|
1639
1698
|
// quotes still refuse; widen it if a real openclaw.json needs it (kata tnhh).
|
|
1640
1699
|
jsonc: true,
|
|
1641
1700
|
merge: (existing) => {
|
|
1642
|
-
const
|
|
1643
|
-
const modelsCfg = asRecord(
|
|
1701
|
+
const obj2 = asRecord(existing);
|
|
1702
|
+
const modelsCfg = asRecord(obj2.models);
|
|
1644
1703
|
const providers = asRecord(modelsCfg.providers);
|
|
1645
|
-
const agents = asRecord(
|
|
1704
|
+
const agents = asRecord(obj2.agents);
|
|
1646
1705
|
const defaults = asRecord(agents.defaults);
|
|
1647
1706
|
const model = asRecord(defaults.model);
|
|
1648
1707
|
return {
|
|
1649
|
-
...
|
|
1708
|
+
...obj2,
|
|
1650
1709
|
models: {
|
|
1651
1710
|
...modelsCfg,
|
|
1652
1711
|
mode: modelsCfg.mode ?? "merge",
|
|
@@ -1893,11 +1952,11 @@ function buildPlan10(ctx) {
|
|
|
1893
1952
|
// Zed ships settings.json as JSONC (its template header is comments).
|
|
1894
1953
|
jsonc: true,
|
|
1895
1954
|
merge: (existing) => {
|
|
1896
|
-
const
|
|
1897
|
-
const languageModels = objectOrEmpty2(
|
|
1955
|
+
const obj2 = objectOrEmpty2(existing);
|
|
1956
|
+
const languageModels = objectOrEmpty2(obj2.language_models);
|
|
1898
1957
|
const openaiCompatible = objectOrEmpty2(languageModels.openai_compatible);
|
|
1899
1958
|
return {
|
|
1900
|
-
...
|
|
1959
|
+
...obj2,
|
|
1901
1960
|
language_models: {
|
|
1902
1961
|
...languageModels,
|
|
1903
1962
|
openai_compatible: { ...openaiCompatible, [PROVIDER_ID]: block }
|
|
@@ -1931,6 +1990,9 @@ function buildPlan11(ctx) {
|
|
|
1931
1990
|
};
|
|
1932
1991
|
}
|
|
1933
1992
|
|
|
1993
|
+
// src/setup/remove.ts
|
|
1994
|
+
import { closeSync as closeSync2, constants as constants2, existsSync as existsSync6, fstatSync as fstatSync2, lstatSync as lstatSync3, openSync as openSync2, unlinkSync } from "fs";
|
|
1995
|
+
|
|
1934
1996
|
// src/setup/snapshot.ts
|
|
1935
1997
|
import {
|
|
1936
1998
|
chmodSync as chmodSync4,
|
|
@@ -2034,15 +2096,15 @@ function ensureSnapshotDir() {
|
|
|
2034
2096
|
}
|
|
2035
2097
|
function alreadyConfigured(existing, keys) {
|
|
2036
2098
|
if (typeof existing !== "object" || existing === null || Array.isArray(existing)) return false;
|
|
2037
|
-
const
|
|
2099
|
+
const obj2 = existing;
|
|
2038
2100
|
for (const [k, v] of Object.entries(keys)) {
|
|
2039
2101
|
if (k === "inferenceCustomHeaders") {
|
|
2040
2102
|
const ours = v["X-LunaRoute-Client"];
|
|
2041
|
-
const theirs =
|
|
2103
|
+
const theirs = obj2.inferenceCustomHeaders?.["X-LunaRoute-Client"];
|
|
2042
2104
|
if (theirs !== ours) return false;
|
|
2043
2105
|
continue;
|
|
2044
2106
|
}
|
|
2045
|
-
if (
|
|
2107
|
+
if (obj2[k] !== v) return false;
|
|
2046
2108
|
}
|
|
2047
2109
|
return true;
|
|
2048
2110
|
}
|
|
@@ -2119,6 +2181,255 @@ function restoreClaudeDesktopProfile(profilePath) {
|
|
|
2119
2181
|
return { restored: true };
|
|
2120
2182
|
}
|
|
2121
2183
|
|
|
2184
|
+
// src/setup/remove.ts
|
|
2185
|
+
var REVERSES = {
|
|
2186
|
+
"claude-desktop": removeClaudeDesktop,
|
|
2187
|
+
codex: removeCodex,
|
|
2188
|
+
"claude-code": removeClaudeCode,
|
|
2189
|
+
agy: printOnlyRemove("agy"),
|
|
2190
|
+
"copilot-cli": printOnlyRemove("copilot-cli"),
|
|
2191
|
+
generic: printOnlyRemove("generic")
|
|
2192
|
+
};
|
|
2193
|
+
async function runRemove(harness, opts, deps) {
|
|
2194
|
+
if (!Object.hasOwn(REVERSES, harness)) {
|
|
2195
|
+
console.error(`${harness} has no reverse; supports: ${Object.keys(REVERSES).join(", ")}.`);
|
|
2196
|
+
return 1;
|
|
2197
|
+
}
|
|
2198
|
+
return REVERSES[harness](opts, deps);
|
|
2199
|
+
}
|
|
2200
|
+
async function removeClaudeDesktop(opts, deps) {
|
|
2201
|
+
const profilePath = resolveClaudeDesktopAppliedProfile();
|
|
2202
|
+
if (!profilePath) {
|
|
2203
|
+
console.error(claudeDesktopRefusal());
|
|
2204
|
+
return 1;
|
|
2205
|
+
}
|
|
2206
|
+
const snapPath = claudeDesktopSnapshotPath(profilePath);
|
|
2207
|
+
const status = claudeDesktopSnapshotStatus(profilePath);
|
|
2208
|
+
const hasSnapshot = status === "regular";
|
|
2209
|
+
const takenAt = hasSnapshot ? claudeDesktopSnapshotTakenAt(profilePath) : null;
|
|
2210
|
+
if (opts.print) {
|
|
2211
|
+
console.log(
|
|
2212
|
+
hasSnapshot ? `# would restore ${profilePath} from ${snapPath}${takenAt ? ` (taken ${takenAt})` : ""}` : status === "invalid" ? `# would refuse: ${snapPath} is not a regular file` : `# would leave ${profilePath} unchanged (no snapshot)`
|
|
2213
|
+
);
|
|
2214
|
+
if (!hasSnapshot) printClaudeDesktopKeysByHand(profilePath);
|
|
2215
|
+
return 0;
|
|
2216
|
+
}
|
|
2217
|
+
if (status === "invalid") {
|
|
2218
|
+
console.error(
|
|
2219
|
+
`Refusing to touch ${profilePath}: ${snapPath} is not a regular file (a symlink, directory or FIFO), so it is not a usable snapshot. Inspect and remove it by hand.`
|
|
2220
|
+
);
|
|
2221
|
+
return 1;
|
|
2222
|
+
}
|
|
2223
|
+
if (!hasSnapshot) {
|
|
2224
|
+
console.log(
|
|
2225
|
+
"No snapshot exists for this profile \u2014 nothing was changed, and nothing was removed (a hand-configured profile can hold exactly the values we would write, and value matching is not authorship). Remove these by hand:"
|
|
2226
|
+
);
|
|
2227
|
+
printClaudeDesktopKeysByHand(profilePath);
|
|
2228
|
+
return 0;
|
|
2229
|
+
}
|
|
2230
|
+
try {
|
|
2231
|
+
const question = `Restore ${profilePath} from the snapshot at ${snapPath}${takenAt ? ` taken ${takenAt}` : ""}?`;
|
|
2232
|
+
if (!await deps.confirm(question, { yes: opts.yes })) {
|
|
2233
|
+
console.log("Skipped. Nothing written.");
|
|
2234
|
+
return 0;
|
|
2235
|
+
}
|
|
2236
|
+
} catch (err) {
|
|
2237
|
+
if (err instanceof NonInteractiveTerminalError) {
|
|
2238
|
+
console.error(
|
|
2239
|
+
"No interactive terminal available. Re-run with --yes to accept prompts, or --print to preview without writing."
|
|
2240
|
+
);
|
|
2241
|
+
return 1;
|
|
2242
|
+
}
|
|
2243
|
+
throw err;
|
|
2244
|
+
}
|
|
2245
|
+
try {
|
|
2246
|
+
const { restored } = restoreClaudeDesktopProfile(profilePath);
|
|
2247
|
+
console.log(
|
|
2248
|
+
restored ? `Restored ${profilePath} from ${snapPath}.` : `Already restored \u2014 ${profilePath} matches the snapshot; nothing written.`
|
|
2249
|
+
);
|
|
2250
|
+
return 0;
|
|
2251
|
+
} catch (err) {
|
|
2252
|
+
console.error(err instanceof Error ? err.message : String(err));
|
|
2253
|
+
return 1;
|
|
2254
|
+
}
|
|
2255
|
+
}
|
|
2256
|
+
function printClaudeDesktopKeysByHand(profilePath) {
|
|
2257
|
+
console.log(` in ${profilePath}:`);
|
|
2258
|
+
for (const [k, v] of Object.entries(claudeDesktopKeys("<your-routing-url>", "<your-lr_\u2026-key>"))) {
|
|
2259
|
+
if (k === "inferenceCustomHeaders") continue;
|
|
2260
|
+
console.log(` delete ${k} only if it is ${JSON.stringify(v)}`);
|
|
2261
|
+
}
|
|
2262
|
+
console.log(
|
|
2263
|
+
' inside inferenceCustomHeaders, delete ONLY the "X-LunaRoute-Client": "claude-desktop" entry \u2014 keep your other header entries'
|
|
2264
|
+
);
|
|
2265
|
+
}
|
|
2266
|
+
var PRINTED_VARS = {
|
|
2267
|
+
"claude-code": [
|
|
2268
|
+
"LUNAROUTE_API_KEY",
|
|
2269
|
+
"ANTHROPIC_BASE_URL",
|
|
2270
|
+
"ANTHROPIC_AUTH_TOKEN",
|
|
2271
|
+
"ANTHROPIC_MODEL",
|
|
2272
|
+
"CLAUDE_CODE_MAX_CONTEXT_TOKENS",
|
|
2273
|
+
"CLAUDE_CODE_MAX_OUTPUT_TOKENS",
|
|
2274
|
+
"ANTHROPIC_DEFAULT_HAIKU_MODEL",
|
|
2275
|
+
"CLAUDE_CODE_GATEWAY_HINT_HEADERS",
|
|
2276
|
+
"ANTHROPIC_CUSTOM_HEADERS",
|
|
2277
|
+
"CLAUDE_CODE_ENABLE_GATEWAY_MODEL_DISCOVERY"
|
|
2278
|
+
],
|
|
2279
|
+
agy: ["AGY_LLM_GATEWAY_URL", "AGY_LLM_GATEWAY_API_KEY"],
|
|
2280
|
+
"copilot-cli": [
|
|
2281
|
+
"LUNAROUTE_API_KEY",
|
|
2282
|
+
"COPILOT_PROVIDER_TYPE",
|
|
2283
|
+
"COPILOT_PROVIDER_BASE_URL",
|
|
2284
|
+
"COPILOT_PROVIDER_API_KEY",
|
|
2285
|
+
"COPILOT_MODEL"
|
|
2286
|
+
],
|
|
2287
|
+
generic: ["LUNAROUTE_API_KEY"]
|
|
2288
|
+
};
|
|
2289
|
+
function renderUnsetBlock(vars) {
|
|
2290
|
+
return [
|
|
2291
|
+
"",
|
|
2292
|
+
"The commands below clear every variable in the list \u2014 delete from the list any you did not add (LUNAROUTE_API_KEY may also serve another harness).",
|
|
2293
|
+
"",
|
|
2294
|
+
"POSIX: delete the export lines you added to your startup file (~/.zshrc, ~/.bashrc, ~/.profile), then clear them in shells that are already open:",
|
|
2295
|
+
` unset ${vars.join(" ")}`,
|
|
2296
|
+
"",
|
|
2297
|
+
"Windows: this clears the current session value and the persistent user variable; then open a NEW window:",
|
|
2298
|
+
` foreach ($v in ${vars.map((v) => `'${v}'`).join(",")}) { Remove-Item "Env:$v" -ErrorAction SilentlyContinue; [Environment]::SetEnvironmentVariable($v, $null, 'User') }`,
|
|
2299
|
+
"",
|
|
2300
|
+
"Delete only the ones you added \u2014 LUNAROUTE_API_KEY may also serve another harness.",
|
|
2301
|
+
"The CLI's own stored key stays until you run `lunaroute logout` (add -p <profile> for a non-default profile)."
|
|
2302
|
+
];
|
|
2303
|
+
}
|
|
2304
|
+
function printOnlyRemove(harness) {
|
|
2305
|
+
return async () => {
|
|
2306
|
+
const vars = PRINTED_VARS[harness] ?? [];
|
|
2307
|
+
console.log(
|
|
2308
|
+
`${harness} setup wrote no harness configuration files on this machine \u2014 this command changed nothing.`
|
|
2309
|
+
);
|
|
2310
|
+
for (const line of renderUnsetBlock(vars)) console.log(line);
|
|
2311
|
+
return 0;
|
|
2312
|
+
};
|
|
2313
|
+
}
|
|
2314
|
+
async function removeClaudeCode() {
|
|
2315
|
+
console.log(
|
|
2316
|
+
`claude-code setup writes no shell configuration; it merged a modelPicker lineup into ${claudeSettingsPath()}. Delete the rows whose description is ${LUNAROUTE_ROW_DESCRIPTION} to restore your own /model list \u2014 any other row, and every other key in the file, is yours.`
|
|
2317
|
+
);
|
|
2318
|
+
for (const line of renderUnsetBlock(PRINTED_VARS["claude-code"] ?? [])) console.log(line);
|
|
2319
|
+
return 0;
|
|
2320
|
+
}
|
|
2321
|
+
function isEnoent(err) {
|
|
2322
|
+
return err?.code === "ENOENT";
|
|
2323
|
+
}
|
|
2324
|
+
function reason(err) {
|
|
2325
|
+
return err instanceof Error ? err.message : String(err);
|
|
2326
|
+
}
|
|
2327
|
+
async function removeCodex(opts, deps) {
|
|
2328
|
+
const path = codexProfilePath();
|
|
2329
|
+
let before;
|
|
2330
|
+
try {
|
|
2331
|
+
before = lstatSync3(path);
|
|
2332
|
+
} catch (err) {
|
|
2333
|
+
if (isEnoent(err)) {
|
|
2334
|
+
console.log(`Nothing to remove: ${path} does not exist.`);
|
|
2335
|
+
return 0;
|
|
2336
|
+
}
|
|
2337
|
+
console.error(`${path} could not be checked: ${reason(err)}`);
|
|
2338
|
+
return 1;
|
|
2339
|
+
}
|
|
2340
|
+
if (!before.isFile()) {
|
|
2341
|
+
console.error(`${path} is not a regular file \u2014 refusing to remove it.`);
|
|
2342
|
+
return 1;
|
|
2343
|
+
}
|
|
2344
|
+
if (opts.print) {
|
|
2345
|
+
console.log(`# would delete ${path}`);
|
|
2346
|
+
console.log(`# it holds only LunaRoute's profile \u2014 hand edits you made to it go too`);
|
|
2347
|
+
return 0;
|
|
2348
|
+
}
|
|
2349
|
+
let fd;
|
|
2350
|
+
try {
|
|
2351
|
+
const open2 = deps.open ?? ((p) => openSync2(p, constants2.O_RDONLY | constants2.O_NOFOLLOW | constants2.O_NONBLOCK));
|
|
2352
|
+
fd = open2(path);
|
|
2353
|
+
} catch (err) {
|
|
2354
|
+
const code = err?.code;
|
|
2355
|
+
if (code === "EACCES" || code === "EPERM") {
|
|
2356
|
+
console.error(
|
|
2357
|
+
`${path} cannot be read to verify it \u2014 nothing was removed. Make it readable and re-run, or delete it by hand.`
|
|
2358
|
+
);
|
|
2359
|
+
return 1;
|
|
2360
|
+
} else if (code === "ELOOP") {
|
|
2361
|
+
console.error(`${path} is not a regular file \u2014 refusing to remove it.`);
|
|
2362
|
+
return 1;
|
|
2363
|
+
} else if (isEnoent(err)) {
|
|
2364
|
+
console.log(`Nothing to remove: ${path} does not exist.`);
|
|
2365
|
+
return 0;
|
|
2366
|
+
} else {
|
|
2367
|
+
console.error(`${path} could not be checked: ${reason(err)}`);
|
|
2368
|
+
return 1;
|
|
2369
|
+
}
|
|
2370
|
+
}
|
|
2371
|
+
try {
|
|
2372
|
+
const identity = fstatSync2(fd);
|
|
2373
|
+
if (!identity.isFile()) {
|
|
2374
|
+
console.error(`${path} is not a regular file \u2014 refusing to remove it.`);
|
|
2375
|
+
return 1;
|
|
2376
|
+
}
|
|
2377
|
+
if (identity.dev !== before.dev || identity.ino !== before.ino) {
|
|
2378
|
+
console.error(`${path} changed while it was being checked \u2014 nothing was removed.`);
|
|
2379
|
+
return 1;
|
|
2380
|
+
}
|
|
2381
|
+
try {
|
|
2382
|
+
const question = `Delete ${path}? It holds only LunaRoute's profile, but edits you made to it go too.`;
|
|
2383
|
+
if (!await deps.confirm(question, { yes: opts.yes })) {
|
|
2384
|
+
console.log("Skipped. Nothing removed.");
|
|
2385
|
+
return 0;
|
|
2386
|
+
}
|
|
2387
|
+
} catch (err) {
|
|
2388
|
+
if (err instanceof NonInteractiveTerminalError) {
|
|
2389
|
+
console.error(
|
|
2390
|
+
"No interactive terminal available. Re-run with --yes to accept prompts, or --print to preview without writing."
|
|
2391
|
+
);
|
|
2392
|
+
return 1;
|
|
2393
|
+
}
|
|
2394
|
+
throw err;
|
|
2395
|
+
}
|
|
2396
|
+
let after;
|
|
2397
|
+
try {
|
|
2398
|
+
after = lstatSync3(path);
|
|
2399
|
+
} catch (err) {
|
|
2400
|
+
if (isEnoent(err)) {
|
|
2401
|
+
console.log(`Nothing to remove: ${path} does not exist.`);
|
|
2402
|
+
return 0;
|
|
2403
|
+
}
|
|
2404
|
+
console.error(`${path} could not be re-checked: ${reason(err)}`);
|
|
2405
|
+
return 1;
|
|
2406
|
+
}
|
|
2407
|
+
if (!after.isFile() || after.dev !== identity.dev || after.ino !== identity.ino) {
|
|
2408
|
+
console.error(`${path} changed while you were deciding \u2014 nothing was removed.`);
|
|
2409
|
+
return 1;
|
|
2410
|
+
}
|
|
2411
|
+
const unlink = deps.unlink ?? unlinkSync;
|
|
2412
|
+
try {
|
|
2413
|
+
unlink(path);
|
|
2414
|
+
} catch (err) {
|
|
2415
|
+
if (isEnoent(err)) {
|
|
2416
|
+
console.log(`Nothing to remove: ${path} does not exist.`);
|
|
2417
|
+
return 0;
|
|
2418
|
+
}
|
|
2419
|
+
console.error(`${path} could not be removed: ${reason(err)}`);
|
|
2420
|
+
return 1;
|
|
2421
|
+
}
|
|
2422
|
+
console.log(`Removed ${path}.`);
|
|
2423
|
+
if (existsSync6(`${path}.bak`)) {
|
|
2424
|
+
console.log(`Kept ${path}.bak (from an earlier setup) \u2014 delete it by hand if you want it gone.`);
|
|
2425
|
+
}
|
|
2426
|
+
for (const line of renderUnsetBlock(["LUNAROUTE_API_KEY"])) console.log(line);
|
|
2427
|
+
return 0;
|
|
2428
|
+
} finally {
|
|
2429
|
+
closeSync2(fd);
|
|
2430
|
+
}
|
|
2431
|
+
}
|
|
2432
|
+
|
|
2122
2433
|
// src/commands/setup.ts
|
|
2123
2434
|
var ADAPTERS = {
|
|
2124
2435
|
opencode: buildPlan,
|
|
@@ -2155,6 +2466,10 @@ async function runSetup(harness, opts, deps = {
|
|
|
2155
2466
|
);
|
|
2156
2467
|
return 1;
|
|
2157
2468
|
}
|
|
2469
|
+
if (opts.remove && (opts.key !== void 0 || opts.routingUrl !== void 0 || opts.extension || opts.models)) {
|
|
2470
|
+
console.error("--remove takes no setup flags; drop --key, --extension, --models or --routing-url.");
|
|
2471
|
+
return 1;
|
|
2472
|
+
}
|
|
2158
2473
|
if (opts.remove) return runRemove(harness, opts, deps);
|
|
2159
2474
|
let stored = loadProfile(opts.profile);
|
|
2160
2475
|
const settings = resolveSettings(opts.profile);
|
|
@@ -2366,11 +2681,6 @@ async function runPiSetup(opts, stored, routingUrl, deps) {
|
|
|
2366
2681
|
return 1;
|
|
2367
2682
|
}
|
|
2368
2683
|
}
|
|
2369
|
-
var CLAUDE_DESKTOP_NO_PROFILE = "Claude Desktop has not created a third-party inference profile yet \u2014 in Desktop open Help \u2192 Troubleshooting \u2192 Enable Developer Mode, then Developer \u2192 Configure Third-Party Inference once; then re-run.";
|
|
2370
|
-
var CLAUDE_DESKTOP_UNVERIFIED_PLATFORM = "The Claude Desktop profile path is verified on Linux only \u2014 this platform's path is unverified (kata yc1y), so the CLI will not guess it. Configure Desktop by hand instead: Help \u2192 Troubleshooting \u2192 Enable Developer Mode, then Developer \u2192 Configure Third-Party Inference.";
|
|
2371
|
-
function claudeDesktopRefusal() {
|
|
2372
|
-
return process.platform === "linux" ? CLAUDE_DESKTOP_NO_PROFILE : CLAUDE_DESKTOP_UNVERIFIED_PLATFORM;
|
|
2373
|
-
}
|
|
2374
2684
|
async function runClaudeDesktopSetup(creds, routingUrl, opts, deps) {
|
|
2375
2685
|
const profilePath = resolveClaudeDesktopAppliedProfile();
|
|
2376
2686
|
if (!profilePath) {
|
|
@@ -2433,77 +2743,6 @@ function printClaudeDesktopPreview(profilePath, routingUrl) {
|
|
|
2433
2743
|
}
|
|
2434
2744
|
console.log(`# inferenceCustomHeaders["X-LunaRoute-Client"] = "claude-desktop" (your other entries are kept)`);
|
|
2435
2745
|
}
|
|
2436
|
-
var REVERSIBLE = ["claude-desktop"];
|
|
2437
|
-
async function runRemove(harness, opts, deps) {
|
|
2438
|
-
if (!REVERSIBLE.includes(harness)) {
|
|
2439
|
-
console.error(`${harness} has no reverse; supports: ${REVERSIBLE.join(", ")}.`);
|
|
2440
|
-
return 1;
|
|
2441
|
-
}
|
|
2442
|
-
const profilePath = resolveClaudeDesktopAppliedProfile();
|
|
2443
|
-
if (!profilePath) {
|
|
2444
|
-
console.error(claudeDesktopRefusal());
|
|
2445
|
-
return 1;
|
|
2446
|
-
}
|
|
2447
|
-
const snapPath = claudeDesktopSnapshotPath(profilePath);
|
|
2448
|
-
const status = claudeDesktopSnapshotStatus(profilePath);
|
|
2449
|
-
const hasSnapshot = status === "regular";
|
|
2450
|
-
const takenAt = hasSnapshot ? claudeDesktopSnapshotTakenAt(profilePath) : null;
|
|
2451
|
-
if (opts.print) {
|
|
2452
|
-
console.log(
|
|
2453
|
-
hasSnapshot ? `# would restore ${profilePath} from ${snapPath}${takenAt ? ` (taken ${takenAt})` : ""}` : status === "invalid" ? `# would refuse: ${snapPath} is not a regular file` : `# would leave ${profilePath} unchanged (no snapshot)`
|
|
2454
|
-
);
|
|
2455
|
-
if (!hasSnapshot) printClaudeDesktopKeysByHand(profilePath);
|
|
2456
|
-
return 0;
|
|
2457
|
-
}
|
|
2458
|
-
if (status === "invalid") {
|
|
2459
|
-
console.error(
|
|
2460
|
-
`Refusing to touch ${profilePath}: ${snapPath} is not a regular file (a symlink, directory or FIFO), so it is not a usable snapshot. Inspect and remove it by hand.`
|
|
2461
|
-
);
|
|
2462
|
-
return 1;
|
|
2463
|
-
}
|
|
2464
|
-
if (!hasSnapshot) {
|
|
2465
|
-
console.log(
|
|
2466
|
-
"No snapshot exists for this profile \u2014 nothing was changed, and nothing was removed (a hand-configured profile can hold exactly the values we would write, and value matching is not authorship). Remove these by hand:"
|
|
2467
|
-
);
|
|
2468
|
-
printClaudeDesktopKeysByHand(profilePath);
|
|
2469
|
-
return 0;
|
|
2470
|
-
}
|
|
2471
|
-
try {
|
|
2472
|
-
const question = `Restore ${profilePath} from the snapshot at ${snapPath}${takenAt ? ` taken ${takenAt}` : ""}?`;
|
|
2473
|
-
if (!await deps.confirm(question, { yes: opts.yes })) {
|
|
2474
|
-
console.log("Skipped. Nothing written.");
|
|
2475
|
-
return 0;
|
|
2476
|
-
}
|
|
2477
|
-
} catch (err) {
|
|
2478
|
-
if (err instanceof NonInteractiveTerminalError) {
|
|
2479
|
-
console.error(
|
|
2480
|
-
"No interactive terminal available. Re-run with --yes to accept prompts, or --print to preview without writing."
|
|
2481
|
-
);
|
|
2482
|
-
return 1;
|
|
2483
|
-
}
|
|
2484
|
-
throw err;
|
|
2485
|
-
}
|
|
2486
|
-
try {
|
|
2487
|
-
const { restored } = restoreClaudeDesktopProfile(profilePath);
|
|
2488
|
-
console.log(
|
|
2489
|
-
restored ? `Restored ${profilePath} from ${snapPath}.` : `Already restored \u2014 ${profilePath} matches the snapshot; nothing written.`
|
|
2490
|
-
);
|
|
2491
|
-
return 0;
|
|
2492
|
-
} catch (err) {
|
|
2493
|
-
console.error(err instanceof Error ? err.message : String(err));
|
|
2494
|
-
return 1;
|
|
2495
|
-
}
|
|
2496
|
-
}
|
|
2497
|
-
function printClaudeDesktopKeysByHand(profilePath) {
|
|
2498
|
-
console.log(` in ${profilePath}:`);
|
|
2499
|
-
for (const [k, v] of Object.entries(claudeDesktopKeys("<your-routing-url>", "<your-lr_\u2026-key>"))) {
|
|
2500
|
-
if (k === "inferenceCustomHeaders") continue;
|
|
2501
|
-
console.log(` delete ${k} only if it is ${JSON.stringify(v)}`);
|
|
2502
|
-
}
|
|
2503
|
-
console.log(
|
|
2504
|
-
' inside inferenceCustomHeaders, delete ONLY the "X-LunaRoute-Client": "claude-desktop" entry \u2014 keep your other header entries'
|
|
2505
|
-
);
|
|
2506
|
-
}
|
|
2507
2746
|
async function runHermesSetup(creds, routingUrl, opts, deps) {
|
|
2508
2747
|
const commands = hermesConfigSetArgs(routingUrl, creds.routing_key);
|
|
2509
2748
|
try {
|
|
@@ -2825,13 +3064,13 @@ async function runModels(profile, opts) {
|
|
|
2825
3064
|
}
|
|
2826
3065
|
|
|
2827
3066
|
// src/render.ts
|
|
2828
|
-
function renderTable(headers,
|
|
2829
|
-
const all = [headers, ...
|
|
3067
|
+
function renderTable(headers, rows2) {
|
|
3068
|
+
const all = [headers, ...rows2];
|
|
2830
3069
|
const widths = headers.map(
|
|
2831
3070
|
(_, col) => Math.max(...all.map((r) => (r[col] ?? "").length))
|
|
2832
3071
|
);
|
|
2833
3072
|
const fmt = (r) => r.map((cell, col) => col === r.length - 1 ? cell : (cell ?? "").padEnd(widths[col])).join(" ").replace(/\s+$/, "");
|
|
2834
|
-
return [headers, ...
|
|
3073
|
+
return [headers, ...rows2].map(fmt).join("\n");
|
|
2835
3074
|
}
|
|
2836
3075
|
|
|
2837
3076
|
// src/commands/pricing.ts
|
|
@@ -2841,25 +3080,25 @@ async function runPricing(profile, opts) {
|
|
|
2841
3080
|
console.error('Not logged in. Run "lunaroute login" first.');
|
|
2842
3081
|
return 1;
|
|
2843
3082
|
}
|
|
2844
|
-
let
|
|
3083
|
+
let rows2;
|
|
2845
3084
|
try {
|
|
2846
|
-
|
|
3085
|
+
rows2 = await getPricing({ apiUrl: s.api_url, apiKey: s.routing_key }, opts.model);
|
|
2847
3086
|
} catch (err) {
|
|
2848
3087
|
console.error(err instanceof Error ? err.message : String(err));
|
|
2849
3088
|
return 1;
|
|
2850
3089
|
}
|
|
2851
3090
|
if (opts.json) {
|
|
2852
|
-
console.log(JSON.stringify(
|
|
3091
|
+
console.log(JSON.stringify(rows2, null, 2));
|
|
2853
3092
|
return 0;
|
|
2854
3093
|
}
|
|
2855
|
-
if (
|
|
3094
|
+
if (rows2.length === 0) {
|
|
2856
3095
|
console.log("// no models enabled for your org yet \u2014 contact hello@lunaroute.com to get models enabled");
|
|
2857
3096
|
return 0;
|
|
2858
3097
|
}
|
|
2859
3098
|
const cell = (n) => n === void 0 ? "\u2014" : String(n);
|
|
2860
3099
|
const table = renderTable(
|
|
2861
3100
|
["MODEL", "INPUT (cr/M)", "OUTPUT (cr/M)", "CACHED (cr/M)"],
|
|
2862
|
-
|
|
3101
|
+
rows2.map(
|
|
2863
3102
|
(r) => r.priced ? [r.model, cell(r.input_credits_per_million), cell(r.output_credits_per_million), cell(r.cached_input_credits_per_million)] : [r.model, "\u2014", "\u2014", "\u2014"]
|
|
2864
3103
|
)
|
|
2865
3104
|
);
|
|
@@ -3264,9 +3503,9 @@ function buildSkillPlan(opts) {
|
|
|
3264
3503
|
if (opts.profile !== "default") args.push("--profile", opts.profile);
|
|
3265
3504
|
const entry = { type: "stdio", command: "npx", args };
|
|
3266
3505
|
const mergeMcp = (existing) => {
|
|
3267
|
-
const
|
|
3268
|
-
const servers = typeof
|
|
3269
|
-
return { ...
|
|
3506
|
+
const obj2 = existing ?? {};
|
|
3507
|
+
const servers = typeof obj2.mcpServers === "object" && obj2.mcpServers !== null ? obj2.mcpServers : {};
|
|
3508
|
+
return { ...obj2, mcpServers: { ...servers, [LUNAROUTE_SKILL_NAME]: entry } };
|
|
3270
3509
|
};
|
|
3271
3510
|
const skillPath = opts.project ? claudeProjectSkillPath(opts.root) : claudeUserSkillPath();
|
|
3272
3511
|
const mcpPath = opts.project ? claudeProjectMcpPath(opts.root) : claudeUserConfigPath();
|
|
@@ -3323,7 +3562,13 @@ function buildRunSpec(ctx) {
|
|
|
3323
3562
|
const outputTokens = ctx.maxOutputTokens && ctx.maxOutputTokens > 0 ? ctx.maxOutputTokens : void 0;
|
|
3324
3563
|
return {
|
|
3325
3564
|
command: "claude",
|
|
3326
|
-
|
|
3565
|
+
// The `/model` lineup, passed inline so this one-session path writes nothing
|
|
3566
|
+
// to disk. Rows are taken verbatim, so canonical ids list as-is — including
|
|
3567
|
+
// routed/BYOK models, which discovery can never show (kata qqs5). `--settings`
|
|
3568
|
+
// supplies only the keys it sets; the user's own settings still apply, and a
|
|
3569
|
+
// build older than 2.1.242 simply ignores the key and keeps the aliases
|
|
3570
|
+
// below. Needs the catalog, so it is skipped when that lookup failed.
|
|
3571
|
+
args: ctx.models?.length ? ["--settings", JSON.stringify({ modelPicker: claudeModelPicker(ctx.models) })] : [],
|
|
3327
3572
|
env: {
|
|
3328
3573
|
ANTHROPIC_BASE_URL: ctx.routingUrl,
|
|
3329
3574
|
ANTHROPIC_AUTH_TOKEN: ctx.apiKey,
|
|
@@ -3338,6 +3583,7 @@ function buildRunSpec(ctx) {
|
|
|
3338
3583
|
ANTHROPIC_DEFAULT_HAIKU_MODEL: ctx.model,
|
|
3339
3584
|
// Populates the /model picker from GET /v1/models at startup. LunaRoute
|
|
3340
3585
|
// already serves the Anthropic-native shape (spike-verified, kata nkey).
|
|
3586
|
+
// Kept for builds older than 2.1.242, which ignore the --settings lineup.
|
|
3341
3587
|
CLAUDE_CODE_ENABLE_GATEWAY_MODEL_DISCOVERY: "1",
|
|
3342
3588
|
// Claude Code keeps only discovered ids containing "claude"/"anthropic"
|
|
3343
3589
|
// (kata 4sak). The normal catalog has no such id, so discovery would
|
|
@@ -3384,12 +3630,12 @@ function buildRunSpec2(ctx) {
|
|
|
3384
3630
|
}
|
|
3385
3631
|
|
|
3386
3632
|
// src/run/adapters/zed.ts
|
|
3387
|
-
import { existsSync as
|
|
3633
|
+
import { existsSync as existsSync7, readFileSync as readFileSync8, realpathSync as realpathSync2 } from "fs";
|
|
3388
3634
|
import { homedir as homedir3 } from "os";
|
|
3389
3635
|
import { basename as basename2, dirname as dirname4, join as join6 } from "path";
|
|
3390
3636
|
|
|
3391
3637
|
// src/run/which.ts
|
|
3392
|
-
import { accessSync, constants as
|
|
3638
|
+
import { accessSync, constants as constants3 } from "fs";
|
|
3393
3639
|
import { join as join5 } from "path";
|
|
3394
3640
|
function which(cmd, env, platform) {
|
|
3395
3641
|
const pathVar = env.PATH ?? env.Path ?? "";
|
|
@@ -3400,7 +3646,7 @@ function which(cmd, env, platform) {
|
|
|
3400
3646
|
for (const ext of alreadyHasExt ? [""] : exts) {
|
|
3401
3647
|
const candidate = join5(dir, cmd + ext);
|
|
3402
3648
|
try {
|
|
3403
|
-
accessSync(candidate, platform === "win32" ?
|
|
3649
|
+
accessSync(candidate, platform === "win32" ? constants3.F_OK : constants3.X_OK);
|
|
3404
3650
|
return candidate;
|
|
3405
3651
|
} catch {
|
|
3406
3652
|
}
|
|
@@ -3411,7 +3657,7 @@ function which(cmd, env, platform) {
|
|
|
3411
3657
|
|
|
3412
3658
|
// src/run/adapters/zed.ts
|
|
3413
3659
|
function firstExisting(paths) {
|
|
3414
|
-
for (const path of paths) if (
|
|
3660
|
+
for (const path of paths) if (existsSync7(path)) return path;
|
|
3415
3661
|
return null;
|
|
3416
3662
|
}
|
|
3417
3663
|
function resolveZedCommand(deps = {}) {
|
|
@@ -3425,7 +3671,7 @@ function resolveZedCommand(deps = {}) {
|
|
|
3425
3671
|
const real = realpathSync2(shim);
|
|
3426
3672
|
if (basename2(real) === "cli") {
|
|
3427
3673
|
const app = join6(dirname4(real), "zed");
|
|
3428
|
-
if (
|
|
3674
|
+
if (existsSync7(app)) return app;
|
|
3429
3675
|
}
|
|
3430
3676
|
return real;
|
|
3431
3677
|
} catch {
|
|
@@ -3473,13 +3719,13 @@ function buildRunSpec3(ctx, deps = {}) {
|
|
|
3473
3719
|
}
|
|
3474
3720
|
|
|
3475
3721
|
// src/run/adapters/agy.ts
|
|
3476
|
-
import { accessSync as accessSync2, constants as
|
|
3722
|
+
import { accessSync as accessSync2, constants as constants4 } from "fs";
|
|
3477
3723
|
import { homedir as homedir4 } from "os";
|
|
3478
3724
|
import { join as join7 } from "path";
|
|
3479
3725
|
function firstRunnable(paths, platform) {
|
|
3480
3726
|
for (const path of paths) {
|
|
3481
3727
|
try {
|
|
3482
|
-
accessSync2(path, platform === "win32" ?
|
|
3728
|
+
accessSync2(path, platform === "win32" ? constants4.F_OK : constants4.X_OK);
|
|
3483
3729
|
return path;
|
|
3484
3730
|
} catch {
|
|
3485
3731
|
}
|
|
@@ -3582,7 +3828,8 @@ async function runRun(harness, opts, deps = realDeps) {
|
|
|
3582
3828
|
apiKey: creds.routing_key,
|
|
3583
3829
|
model,
|
|
3584
3830
|
contextWindow: row?.context_window_tokens,
|
|
3585
|
-
maxOutputTokens: row?.max_output_tokens
|
|
3831
|
+
maxOutputTokens: row?.max_output_tokens,
|
|
3832
|
+
models
|
|
3586
3833
|
});
|
|
3587
3834
|
if (spec.notice) console.error(spec.notice);
|
|
3588
3835
|
const args = spec.args.concat(opts.passthrough ?? []);
|
|
@@ -3637,7 +3884,7 @@ apiKey.command("show").description('Show the stored API key (same as "lunaroute
|
|
|
3637
3884
|
program.command("logout").description("Remove stored credentials for the active profile.").action(() => {
|
|
3638
3885
|
logout(program.opts().profile);
|
|
3639
3886
|
});
|
|
3640
|
-
program.command("setup <harness>").description("Configure a coding harness (opencode | pi | hermes | claude-code | claude-desktop | codex | copilot-cli | openclaw | dsh | zed | agy | generic).").option("--print", "print the config instead of writing files", false).option("--routing-url <url>", "override the routing base URL").option("--yes", "accept all confirmation prompts without a TTY (for scripts)", false).option("--extension", "pi only: jump straight to installing the Pi extension").option("--models", "pi only: jump straight to writing the models.json provider block").option("--remove", "claude-desktop
|
|
3887
|
+
program.command("setup <harness>").description("Configure a coding harness (opencode | pi | hermes | claude-code | claude-desktop | codex | copilot-cli | openclaw | dsh | zed | agy | generic).").option("--print", "print the config instead of writing files", false).option("--routing-url <url>", "override the routing base URL").option("--yes", "accept all confirmation prompts without a TTY (for scripts)", false).option("--extension", "pi only: jump straight to installing the Pi extension").option("--models", "pi only: jump straight to writing the models.json provider block").option("--remove", "undo a setup: claude-desktop restores its snapshot, codex deletes its profile file, export-only harnesses print what to remove").option("--key <key>", "a LunaRoute routing key (lr_\u2026), e.g. from the dashboard's onboarding page \u2014 stores it and skips the browser login").action(async (harness, opts) => {
|
|
3641
3888
|
const code = await runSetup(harness, {
|
|
3642
3889
|
profile: program.opts().profile,
|
|
3643
3890
|
print: opts.print,
|