@lunaroute/cli 0.11.0 → 0.12.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/dist/index.js +186 -11
- 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.
|
|
7
|
+
var version = "0.12.0";
|
|
8
8
|
|
|
9
9
|
// src/login.ts
|
|
10
10
|
import { createServer } from "http";
|
|
@@ -807,7 +807,7 @@ function describeSpawnError(command, installHint, err) {
|
|
|
807
807
|
|
|
808
808
|
// src/setup/paths.ts
|
|
809
809
|
import { execSync } from "child_process";
|
|
810
|
-
import { lstatSync, readFileSync as readFileSync4, realpathSync } from "fs";
|
|
810
|
+
import { existsSync as existsSync4, lstatSync, readFileSync as readFileSync4, realpathSync } from "fs";
|
|
811
811
|
import { homedir as homedir2 } from "os";
|
|
812
812
|
import { dirname as dirname2, join as join3 } from "path";
|
|
813
813
|
function configHome() {
|
|
@@ -842,6 +842,17 @@ function dshProfilePatchPath(profile = "web") {
|
|
|
842
842
|
function dshHomePatchPath() {
|
|
843
843
|
return join3(dshHome(), "cordis.patch.yml");
|
|
844
844
|
}
|
|
845
|
+
function zedSettingsPath(platform = process.platform) {
|
|
846
|
+
if (platform === "win32") {
|
|
847
|
+
const appData = process.env.APPDATA || join3(homedir2(), "AppData", "Roaming");
|
|
848
|
+
return join3(appData, "Zed", "settings.json");
|
|
849
|
+
}
|
|
850
|
+
if (platform === "darwin") {
|
|
851
|
+
return join3(homedir2(), ".config", "zed", "settings.json");
|
|
852
|
+
}
|
|
853
|
+
const flatpak = join3(homedir2(), ".var", "app", "dev.zed.Zed", "config", "zed");
|
|
854
|
+
return existsSync4(flatpak) ? join3(flatpak, "settings.json") : join3(configHome(), "zed", "settings.json");
|
|
855
|
+
}
|
|
845
856
|
var LUNAROUTE_SKILL_NAME = "lunaroute-memory";
|
|
846
857
|
function claudeUserConfigPath() {
|
|
847
858
|
return join3(homedir2(), ".claude.json");
|
|
@@ -1483,7 +1494,7 @@ openclaw: restart the gateway, then \`openclaw models list\` and \`openclaw mode
|
|
|
1483
1494
|
}
|
|
1484
1495
|
|
|
1485
1496
|
// src/setup/adapters/dsh.ts
|
|
1486
|
-
import { existsSync as
|
|
1497
|
+
import { existsSync as existsSync5, readFileSync as readFileSync6 } from "fs";
|
|
1487
1498
|
import { isMap, isSeq, parseDocument as parseDocument2 } from "yaml";
|
|
1488
1499
|
var PI_AI_ROW_ID = "llm-pi-ai";
|
|
1489
1500
|
var ROUTE_KEY = "lunaroute";
|
|
@@ -1575,7 +1586,7 @@ function mergeProvider(doc, provider) {
|
|
|
1575
1586
|
}
|
|
1576
1587
|
function homePatchOverridesPiAi() {
|
|
1577
1588
|
const path = dshHomePatchPath();
|
|
1578
|
-
if (!
|
|
1589
|
+
if (!existsSync5(path)) return false;
|
|
1579
1590
|
try {
|
|
1580
1591
|
const doc = parseDocument2(readFileSync6(path, "utf8"), { logLevel: "silent" });
|
|
1581
1592
|
if (!isSeq(doc.contents)) return false;
|
|
@@ -1632,6 +1643,79 @@ function buildPlan9(ctx) {
|
|
|
1632
1643
|
};
|
|
1633
1644
|
}
|
|
1634
1645
|
|
|
1646
|
+
// src/setup/adapters/zed.ts
|
|
1647
|
+
var PROVIDER_ID = "lunaroute";
|
|
1648
|
+
function buildZedModelEntry(m) {
|
|
1649
|
+
if (!m.context_window_tokens || !m.max_output_tokens) return null;
|
|
1650
|
+
return {
|
|
1651
|
+
name: m.id,
|
|
1652
|
+
display_name: m.display_name ?? m.id,
|
|
1653
|
+
// /v1/models emits none today
|
|
1654
|
+
max_tokens: m.context_window_tokens,
|
|
1655
|
+
max_output_tokens: m.max_output_tokens,
|
|
1656
|
+
capabilities: {
|
|
1657
|
+
tools: m.capabilities?.tools ?? true,
|
|
1658
|
+
images: m.capabilities?.vision === true,
|
|
1659
|
+
parallel_tool_calls: false,
|
|
1660
|
+
prompt_cache_key: false,
|
|
1661
|
+
chat_completions: true,
|
|
1662
|
+
interleaved_reasoning: false,
|
|
1663
|
+
max_tokens_parameter: false
|
|
1664
|
+
}
|
|
1665
|
+
};
|
|
1666
|
+
}
|
|
1667
|
+
function objectOrEmpty2(v) {
|
|
1668
|
+
return typeof v === "object" && v !== null ? v : {};
|
|
1669
|
+
}
|
|
1670
|
+
function buildPlan10(ctx) {
|
|
1671
|
+
const skipped = [];
|
|
1672
|
+
const models = [];
|
|
1673
|
+
for (const m of ctx.models) {
|
|
1674
|
+
const entry = buildZedModelEntry(m);
|
|
1675
|
+
if (entry) models.push(entry);
|
|
1676
|
+
else skipped.push(m.id);
|
|
1677
|
+
}
|
|
1678
|
+
if (models.length === 0) {
|
|
1679
|
+
throw new Error(
|
|
1680
|
+
`no LunaRoute model has a context window in the catalog${skipped.length ? ` (skipped: ${skipped.join(", ")})` : ""}`
|
|
1681
|
+
);
|
|
1682
|
+
}
|
|
1683
|
+
const block = {
|
|
1684
|
+
api_url: `${ctx.routingUrl}/v1`,
|
|
1685
|
+
available_models: models
|
|
1686
|
+
};
|
|
1687
|
+
const notes = [
|
|
1688
|
+
"\nzed: restart Zed, then pick a LunaRoute model in the agent panel.",
|
|
1689
|
+
'zed: to paste the key in Zed, run "agent: open settings" and open LLM Providers \u2192 LunaRoute \u2192 paste. Print the key with "lunaroute key" (or create one in the dashboard if you have none); Zed stores it in the OS keychain.',
|
|
1690
|
+
`zed: or set ${ctx.keyEnvVar} (the block above), which Zed reads at launch and which takes precedence over the keychain; or launch with "lunaroute run zed" to inject it for one session \u2014 quit a running Zed first.`
|
|
1691
|
+
];
|
|
1692
|
+
if (skipped.length > 0) {
|
|
1693
|
+
notes.push(`Skipped (no context window or output limit in the catalog): ${skipped.join(", ")}`);
|
|
1694
|
+
}
|
|
1695
|
+
return {
|
|
1696
|
+
fileWrites: [
|
|
1697
|
+
{
|
|
1698
|
+
kind: "json",
|
|
1699
|
+
path: zedSettingsPath(),
|
|
1700
|
+
merge: (existing) => {
|
|
1701
|
+
const obj = objectOrEmpty2(existing);
|
|
1702
|
+
const languageModels = objectOrEmpty2(obj.language_models);
|
|
1703
|
+
const openaiCompatible = objectOrEmpty2(languageModels.openai_compatible);
|
|
1704
|
+
return {
|
|
1705
|
+
...obj,
|
|
1706
|
+
language_models: {
|
|
1707
|
+
...languageModels,
|
|
1708
|
+
openai_compatible: { ...openaiCompatible, [PROVIDER_ID]: block }
|
|
1709
|
+
}
|
|
1710
|
+
};
|
|
1711
|
+
}
|
|
1712
|
+
}
|
|
1713
|
+
],
|
|
1714
|
+
exports: [{ name: ctx.keyEnvVar, value: "__KEY__" }],
|
|
1715
|
+
notes
|
|
1716
|
+
};
|
|
1717
|
+
}
|
|
1718
|
+
|
|
1635
1719
|
// src/setup/snapshot.ts
|
|
1636
1720
|
import {
|
|
1637
1721
|
chmodSync as chmodSync4,
|
|
@@ -1826,6 +1910,7 @@ var ADAPTERS = {
|
|
|
1826
1910
|
pi: buildPlan2,
|
|
1827
1911
|
openclaw: buildPlan8,
|
|
1828
1912
|
dsh: buildPlan9,
|
|
1913
|
+
zed: buildPlan10,
|
|
1829
1914
|
"claude-code": buildPlan3,
|
|
1830
1915
|
"claude-desktop": buildPlan4,
|
|
1831
1916
|
codex: buildPlan5,
|
|
@@ -3078,17 +3163,102 @@ function buildRunSpec2(ctx) {
|
|
|
3078
3163
|
};
|
|
3079
3164
|
}
|
|
3080
3165
|
|
|
3166
|
+
// src/run/adapters/zed.ts
|
|
3167
|
+
import { accessSync, constants as constants2, existsSync as existsSync6, readFileSync as readFileSync8, realpathSync as realpathSync2 } from "fs";
|
|
3168
|
+
import { homedir as homedir3 } from "os";
|
|
3169
|
+
import { basename as basename2, dirname as dirname4, join as join5 } from "path";
|
|
3170
|
+
function which(cmd, env, platform) {
|
|
3171
|
+
const pathVar = env.PATH ?? env.Path ?? "";
|
|
3172
|
+
const exts = platform === "win32" ? (env.PATHEXT ?? ".COM;.EXE;.BAT;.CMD").split(";").filter(Boolean) : [""];
|
|
3173
|
+
const alreadyHasExt = cmd.includes(".");
|
|
3174
|
+
for (const dir of pathVar.split(platform === "win32" ? ";" : ":")) {
|
|
3175
|
+
if (!dir) continue;
|
|
3176
|
+
for (const ext of alreadyHasExt ? [""] : exts) {
|
|
3177
|
+
const candidate = join5(dir, cmd + ext);
|
|
3178
|
+
try {
|
|
3179
|
+
accessSync(candidate, platform === "win32" ? constants2.F_OK : constants2.X_OK);
|
|
3180
|
+
return candidate;
|
|
3181
|
+
} catch {
|
|
3182
|
+
}
|
|
3183
|
+
}
|
|
3184
|
+
}
|
|
3185
|
+
return null;
|
|
3186
|
+
}
|
|
3187
|
+
function firstExisting(paths) {
|
|
3188
|
+
for (const path of paths) if (existsSync6(path)) return path;
|
|
3189
|
+
return null;
|
|
3190
|
+
}
|
|
3191
|
+
function resolveZedCommand(deps = {}) {
|
|
3192
|
+
const platform = deps.platform ?? process.platform;
|
|
3193
|
+
const env = deps.env ?? process.env;
|
|
3194
|
+
const home = env.HOME || env.USERPROFILE || homedir3();
|
|
3195
|
+
if (platform === "darwin") {
|
|
3196
|
+
const shim = which("zed", env, platform);
|
|
3197
|
+
if (shim) {
|
|
3198
|
+
try {
|
|
3199
|
+
const real = realpathSync2(shim);
|
|
3200
|
+
if (basename2(real) === "cli") {
|
|
3201
|
+
const app = join5(dirname4(real), "zed");
|
|
3202
|
+
if (existsSync6(app)) return app;
|
|
3203
|
+
}
|
|
3204
|
+
return real;
|
|
3205
|
+
} catch {
|
|
3206
|
+
return shim;
|
|
3207
|
+
}
|
|
3208
|
+
}
|
|
3209
|
+
return firstExisting([
|
|
3210
|
+
"/Applications/Zed.app/Contents/MacOS/zed",
|
|
3211
|
+
join5(home, "Applications", "Zed.app", "Contents", "MacOS", "zed"),
|
|
3212
|
+
"/Applications/Zed Preview.app/Contents/MacOS/zed",
|
|
3213
|
+
join5(home, "Applications", "Zed Preview.app", "Contents", "MacOS", "zed"),
|
|
3214
|
+
"/Applications/Zed Nightly.app/Contents/MacOS/zed"
|
|
3215
|
+
]);
|
|
3216
|
+
}
|
|
3217
|
+
if (platform === "win32") {
|
|
3218
|
+
const onPath = which("zed", env, platform);
|
|
3219
|
+
if (onPath) return onPath;
|
|
3220
|
+
return env.LOCALAPPDATA ? firstExisting([join5(env.LOCALAPPDATA, "Programs", "Zed", "zed.exe")]) : null;
|
|
3221
|
+
}
|
|
3222
|
+
return which("zed", env, platform) ?? which("zed-x11", env, platform) ?? firstExisting([
|
|
3223
|
+
join5(home, ".local", "bin", "zed"),
|
|
3224
|
+
join5(home, ".local", "zed.app", "bin", "zed")
|
|
3225
|
+
]);
|
|
3226
|
+
}
|
|
3227
|
+
function hasLunarouteProvider(settingsPath) {
|
|
3228
|
+
try {
|
|
3229
|
+
const parsed = JSON.parse(readFileSync8(settingsPath, "utf8"));
|
|
3230
|
+
return Boolean(parsed.language_models?.openai_compatible?.lunaroute);
|
|
3231
|
+
} catch {
|
|
3232
|
+
return false;
|
|
3233
|
+
}
|
|
3234
|
+
}
|
|
3235
|
+
function buildRunSpec3(ctx, deps = {}) {
|
|
3236
|
+
const settingsPath = deps.settingsPath ?? zedSettingsPath(deps.platform ?? process.platform);
|
|
3237
|
+
return {
|
|
3238
|
+
command: resolveZedCommand(deps) ?? "zed",
|
|
3239
|
+
args: [],
|
|
3240
|
+
// Read by Zed at launch; a non-empty env var takes precedence over the
|
|
3241
|
+
// keychain, so this overrides a previously pasted key for this process.
|
|
3242
|
+
env: { LUNAROUTE_API_KEY: ctx.apiKey },
|
|
3243
|
+
...hasLunarouteProvider(settingsPath) ? {} : {
|
|
3244
|
+
notice: `zed: no "lunaroute" provider in ${settingsPath} \u2014 run "lunaroute setup zed" first. This launch injects only LUNAROUTE_API_KEY.`
|
|
3245
|
+
}
|
|
3246
|
+
};
|
|
3247
|
+
}
|
|
3248
|
+
|
|
3081
3249
|
// src/commands/run.ts
|
|
3082
3250
|
var ADAPTERS2 = {
|
|
3083
3251
|
claude: buildRunSpec,
|
|
3084
3252
|
"claude-code": buildRunSpec,
|
|
3085
|
-
codex: buildRunSpec2
|
|
3253
|
+
codex: buildRunSpec2,
|
|
3254
|
+
zed: buildRunSpec3
|
|
3086
3255
|
};
|
|
3087
3256
|
var MODEL_LOOKUP_TIMEOUT_MS = 3e3;
|
|
3088
3257
|
var INSTALL_HINT = {
|
|
3089
3258
|
claude: "Install Claude Code: https://docs.anthropic.com/claude-code/install",
|
|
3090
3259
|
"claude-code": "Install Claude Code: https://docs.anthropic.com/claude-code/install",
|
|
3091
|
-
codex: "Install Codex: https://github.com/openai/codex#install"
|
|
3260
|
+
codex: "Install Codex: https://github.com/openai/codex#install",
|
|
3261
|
+
zed: "Install Zed: https://zed.dev/download (Windows: winget install -e --id ZedIndustries.Zed)"
|
|
3092
3262
|
};
|
|
3093
3263
|
var realDeps = {
|
|
3094
3264
|
spawn: makeRealSpawn(),
|
|
@@ -3105,9 +3275,13 @@ async function runRun(harness, opts, deps = realDeps) {
|
|
|
3105
3275
|
console.error('Not logged in. Run "lunaroute login" first.');
|
|
3106
3276
|
return 1;
|
|
3107
3277
|
}
|
|
3108
|
-
|
|
3278
|
+
const usesModel = harness !== "zed";
|
|
3279
|
+
if (!usesModel && opts.model) {
|
|
3280
|
+
console.error("# note: Zed picks its model in the agent panel \u2014 --model is ignored.");
|
|
3281
|
+
}
|
|
3282
|
+
let model = opts.model ?? "";
|
|
3109
3283
|
let models = [];
|
|
3110
|
-
if (!model) {
|
|
3284
|
+
if (usesModel && !model) {
|
|
3111
3285
|
try {
|
|
3112
3286
|
models = await deps.fetchModels(creds.routing_url, creds.routing_key);
|
|
3113
3287
|
} catch (err) {
|
|
@@ -3120,7 +3294,7 @@ async function runRun(harness, opts, deps = realDeps) {
|
|
|
3120
3294
|
return 1;
|
|
3121
3295
|
}
|
|
3122
3296
|
console.error(`# using model ${model} (pass --model to change)`);
|
|
3123
|
-
} else if (harness === "codex") {
|
|
3297
|
+
} else if (usesModel && harness === "codex") {
|
|
3124
3298
|
try {
|
|
3125
3299
|
models = await deps.fetchModels(creds.routing_url, creds.routing_key, {
|
|
3126
3300
|
signal: AbortSignal.timeout(MODEL_LOOKUP_TIMEOUT_MS)
|
|
@@ -3136,6 +3310,7 @@ async function runRun(harness, opts, deps = realDeps) {
|
|
|
3136
3310
|
model,
|
|
3137
3311
|
contextWindow
|
|
3138
3312
|
});
|
|
3313
|
+
if (spec.notice) console.error(spec.notice);
|
|
3139
3314
|
const args = spec.args.concat(opts.passthrough ?? []);
|
|
3140
3315
|
const env = { ...process.env, ...spec.env };
|
|
3141
3316
|
const child = deps.spawn(spec.command, args, env);
|
|
@@ -3183,7 +3358,7 @@ program.command("key").description('Print the stored routing key, for shell use
|
|
|
3183
3358
|
program.command("logout").description("Remove stored credentials for the active profile.").action(() => {
|
|
3184
3359
|
logout(program.opts().profile);
|
|
3185
3360
|
});
|
|
3186
|
-
program.command("setup <harness>").description("Configure a coding harness (opencode | pi | hermes | claude-code | claude-desktop | codex | copilot-cli | openclaw | dsh | 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: restore the profile from the snapshot taken at setup (writes nothing when no snapshot exists)").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) => {
|
|
3361
|
+
program.command("setup <harness>").description("Configure a coding harness (opencode | pi | hermes | claude-code | claude-desktop | codex | copilot-cli | openclaw | dsh | zed | 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: restore the profile from the snapshot taken at setup (writes nothing when no snapshot exists)").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) => {
|
|
3187
3362
|
const code = await runSetup(harness, {
|
|
3188
3363
|
profile: program.opts().profile,
|
|
3189
3364
|
print: opts.print,
|
|
@@ -3196,7 +3371,7 @@ program.command("setup <harness>").description("Configure a coding harness (open
|
|
|
3196
3371
|
});
|
|
3197
3372
|
if (code !== 0) process.exit(code);
|
|
3198
3373
|
});
|
|
3199
|
-
program.command("run <harness>").description("Launch a coding harness (claude | claude-code | codex) configured to use LunaRoute for this session.").option("--model <id>", "model id to launch on (default: first model in the catalog)").argument("[extra...]").action(async (harness, extra, opts) => {
|
|
3374
|
+
program.command("run <harness>").description("Launch a coding harness (claude | claude-code | codex | zed) configured to use LunaRoute for this session.").option("--model <id>", "model id to launch on (default: first model in the catalog)").argument("[extra...]").action(async (harness, extra, opts) => {
|
|
3200
3375
|
const sep = process.argv.indexOf("--");
|
|
3201
3376
|
const post = sep !== -1 ? process.argv.slice(sep + 1) : [];
|
|
3202
3377
|
const before = post.length <= extra.length ? extra.slice(0, extra.length - post.length) : extra;
|