@lunaroute/cli 0.10.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.
Files changed (2) hide show
  1. package/dist/index.js +216 -17
  2. 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.10.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");
@@ -1184,7 +1195,14 @@ function buildPlan3(ctx) {
1184
1195
  // translate back to canonical models at ingress, and the header is
1185
1196
  // informational only (never auth/entitlements/billing). Claude Code sends
1186
1197
  // ANTHROPIC_CUSTOM_HEADERS on the discovery GET too (vendor gateway guide).
1187
- { name: "ANTHROPIC_CUSTOM_HEADERS", value: "X-LunaRoute-Client: claude-desktop" }
1198
+ { name: "ANTHROPIC_CUSTOM_HEADERS", value: "X-LunaRoute-Client: claude-desktop" },
1199
+ // Populates the /model picker from GET /v1/models. Gateway discovery is
1200
+ // opt-in since Claude Code v2.1.129: without this export the picker lists
1201
+ // only ANTHROPIC_MODEL and the aliases silently never appear (kata d7fm).
1202
+ // Mirrors the run adapter and the Connect tab. The hint header above is a
1203
+ // separate setting: that one fast-paths auxiliary requests, this one
1204
+ // fills the picker.
1205
+ { name: "CLAUDE_CODE_ENABLE_GATEWAY_MODEL_DISCOVERY", value: "1" }
1188
1206
  ],
1189
1207
  notes: [
1190
1208
  ...isWin ? [
@@ -1330,11 +1348,20 @@ function buildPlan5(ctx) {
1330
1348
  "[model_providers.lunaroute]",
1331
1349
  'name = "LunaRoute"',
1332
1350
  `base_url = "${base}/v1"`,
1351
+ // Codex's model discovery decodes {models:[ModelInfo]} and cannot read
1352
+ // the OpenAI-shaped /v1/models, so it fetches its own Codex-shaped path
1353
+ // (kata 3jrx). This is what populates the /model picker.
1354
+ `model_catalog_url = "${base}/v1/codex/models"`,
1333
1355
  'env_key = "LUNAROUTE_API_KEY"',
1334
1356
  'wire_api = "responses"',
1335
1357
  // Codex only calls /v1/alpha/search when the provider opts in; the
1336
1358
  // endpoint is derived from base_url by the /responses suffix swap.
1337
- "supports_standalone_web_search = true"
1359
+ "supports_standalone_web_search = true",
1360
+ "",
1361
+ // No-op on current Codex (Stable, default-on); enables discovery on
1362
+ // builds where the flag was still under development.
1363
+ "[features]",
1364
+ "api_key_model_discovery = true"
1338
1365
  ]).join("\n") + "\n";
1339
1366
  return {
1340
1367
  fileWrites: [{ kind: "text", path: codexProfilePath(), content }],
@@ -1344,7 +1371,7 @@ function buildPlan5(ctx) {
1344
1371
  `Change model to any of: ${ctx.models.map((m) => m.id).join(", ")}, or pass \`--model <id>\` for one session. If you change model, update or remove model_context_window to match.`,
1345
1372
  "The key rides the Authorization: Bearer header via env_key; LunaRoute authenticates the lr_ key at the edge and never forwards it upstream.",
1346
1373
  "One file: the model and the named provider live in the profile file \u2014 your ~/.codex/config.toml is untouched.",
1347
- "Codex logs a `Model metadata ... fallback metadata` warning for LunaRoute models (its /v1/models catalog shape differs); it is expected and harmless \u2014 model_context_window pins the real window above."
1374
+ "Codex discovers the LunaRoute catalog via the profile's `model_catalog_url`, so its `/model` picker lists all LunaRoute chat models and the `fallback metadata` warning is gone."
1348
1375
  ]
1349
1376
  };
1350
1377
  }
@@ -1467,7 +1494,7 @@ openclaw: restart the gateway, then \`openclaw models list\` and \`openclaw mode
1467
1494
  }
1468
1495
 
1469
1496
  // src/setup/adapters/dsh.ts
1470
- import { existsSync as existsSync4, readFileSync as readFileSync6 } from "fs";
1497
+ import { existsSync as existsSync5, readFileSync as readFileSync6 } from "fs";
1471
1498
  import { isMap, isSeq, parseDocument as parseDocument2 } from "yaml";
1472
1499
  var PI_AI_ROW_ID = "llm-pi-ai";
1473
1500
  var ROUTE_KEY = "lunaroute";
@@ -1559,7 +1586,7 @@ function mergeProvider(doc, provider) {
1559
1586
  }
1560
1587
  function homePatchOverridesPiAi() {
1561
1588
  const path = dshHomePatchPath();
1562
- if (!existsSync4(path)) return false;
1589
+ if (!existsSync5(path)) return false;
1563
1590
  try {
1564
1591
  const doc = parseDocument2(readFileSync6(path, "utf8"), { logLevel: "silent" });
1565
1592
  if (!isSeq(doc.contents)) return false;
@@ -1616,6 +1643,79 @@ function buildPlan9(ctx) {
1616
1643
  };
1617
1644
  }
1618
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
+
1619
1719
  // src/setup/snapshot.ts
1620
1720
  import {
1621
1721
  chmodSync as chmodSync4,
@@ -1810,6 +1910,7 @@ var ADAPTERS = {
1810
1910
  pi: buildPlan2,
1811
1911
  openclaw: buildPlan8,
1812
1912
  dsh: buildPlan9,
1913
+ zed: buildPlan10,
1813
1914
  "claude-code": buildPlan3,
1814
1915
  "claude-desktop": buildPlan4,
1815
1916
  codex: buildPlan5,
@@ -3026,21 +3127,29 @@ function buildRunSpec(ctx) {
3026
3127
  // at ingress. Informational header only — it never affects
3027
3128
  // auth/entitlements/billing. Claude Code sends ANTHROPIC_CUSTOM_HEADERS
3028
3129
  // on the discovery GET too (vendor gateway guide).
3029
- ANTHROPIC_CUSTOM_HEADERS: "X-LunaRoute-Client: claude-desktop"
3130
+ ANTHROPIC_CUSTOM_HEADERS: "X-LunaRoute-Client: claude-desktop",
3131
+ // LunaRoute fast-paths auxiliary requests (auto-mode classifier and
3132
+ // friends) that carry this hint instead of queueing them behind the
3133
+ // session's own requests. Mirrors setup's export and the Connect tab;
3134
+ // its absence here was the mirror image of the missing discovery flag
3135
+ // (kata d7fm).
3136
+ CLAUDE_CODE_GATEWAY_HINT_HEADERS: "1"
3030
3137
  }
3031
3138
  };
3032
3139
  }
3033
3140
 
3034
3141
  // src/run/adapters/codex.ts
3035
3142
  function buildRunSpec2(ctx) {
3036
- const provider = `{name="LunaRoute",base_url="${ctx.routingUrl}/v1",env_key="LUNAROUTE_API_KEY",wire_api="responses",supports_standalone_web_search=true}`;
3143
+ const provider = `{name="LunaRoute",base_url="${ctx.routingUrl}/v1",model_catalog_url="${ctx.routingUrl}/v1/codex/models",env_key="LUNAROUTE_API_KEY",wire_api="responses",supports_standalone_web_search=true}`;
3037
3144
  const args = [
3038
3145
  "-c",
3039
3146
  'model_provider="lunaroute"',
3040
3147
  "-c",
3041
3148
  `model_providers.lunaroute=${provider}`,
3042
3149
  "-c",
3043
- `model="${ctx.model}"`
3150
+ `model="${ctx.model}"`,
3151
+ "-c",
3152
+ "features.api_key_model_discovery=true"
3044
3153
  ];
3045
3154
  if (Number.isInteger(ctx.contextWindow) && (ctx.contextWindow ?? 0) > 0) {
3046
3155
  args.push("-c", `model_context_window=${ctx.contextWindow}`);
@@ -3054,17 +3163,102 @@ function buildRunSpec2(ctx) {
3054
3163
  };
3055
3164
  }
3056
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
+
3057
3249
  // src/commands/run.ts
3058
3250
  var ADAPTERS2 = {
3059
3251
  claude: buildRunSpec,
3060
3252
  "claude-code": buildRunSpec,
3061
- codex: buildRunSpec2
3253
+ codex: buildRunSpec2,
3254
+ zed: buildRunSpec3
3062
3255
  };
3063
3256
  var MODEL_LOOKUP_TIMEOUT_MS = 3e3;
3064
3257
  var INSTALL_HINT = {
3065
3258
  claude: "Install Claude Code: https://docs.anthropic.com/claude-code/install",
3066
3259
  "claude-code": "Install Claude Code: https://docs.anthropic.com/claude-code/install",
3067
- 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)"
3068
3262
  };
3069
3263
  var realDeps = {
3070
3264
  spawn: makeRealSpawn(),
@@ -3081,9 +3275,13 @@ async function runRun(harness, opts, deps = realDeps) {
3081
3275
  console.error('Not logged in. Run "lunaroute login" first.');
3082
3276
  return 1;
3083
3277
  }
3084
- let model = opts.model;
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 ?? "";
3085
3283
  let models = [];
3086
- if (!model) {
3284
+ if (usesModel && !model) {
3087
3285
  try {
3088
3286
  models = await deps.fetchModels(creds.routing_url, creds.routing_key);
3089
3287
  } catch (err) {
@@ -3096,7 +3294,7 @@ async function runRun(harness, opts, deps = realDeps) {
3096
3294
  return 1;
3097
3295
  }
3098
3296
  console.error(`# using model ${model} (pass --model to change)`);
3099
- } else if (harness === "codex") {
3297
+ } else if (usesModel && harness === "codex") {
3100
3298
  try {
3101
3299
  models = await deps.fetchModels(creds.routing_url, creds.routing_key, {
3102
3300
  signal: AbortSignal.timeout(MODEL_LOOKUP_TIMEOUT_MS)
@@ -3112,6 +3310,7 @@ async function runRun(harness, opts, deps = realDeps) {
3112
3310
  model,
3113
3311
  contextWindow
3114
3312
  });
3313
+ if (spec.notice) console.error(spec.notice);
3115
3314
  const args = spec.args.concat(opts.passthrough ?? []);
3116
3315
  const env = { ...process.env, ...spec.env };
3117
3316
  const child = deps.spawn(spec.command, args, env);
@@ -3159,7 +3358,7 @@ program.command("key").description('Print the stored routing key, for shell use
3159
3358
  program.command("logout").description("Remove stored credentials for the active profile.").action(() => {
3160
3359
  logout(program.opts().profile);
3161
3360
  });
3162
- 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) => {
3163
3362
  const code = await runSetup(harness, {
3164
3363
  profile: program.opts().profile,
3165
3364
  print: opts.print,
@@ -3172,7 +3371,7 @@ program.command("setup <harness>").description("Configure a coding harness (open
3172
3371
  });
3173
3372
  if (code !== 0) process.exit(code);
3174
3373
  });
3175
- 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) => {
3176
3375
  const sep = process.argv.indexOf("--");
3177
3376
  const post = sep !== -1 ? process.argv.slice(sep + 1) : [];
3178
3377
  const before = post.length <= extra.length ? extra.slice(0, extra.length - post.length) : extra;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lunaroute/cli",
3
- "version": "0.10.0",
3
+ "version": "0.12.0",
4
4
  "description": "LunaRoute CLI — configure coding harnesses and manage your LunaRoute account.",
5
5
  "repository": {
6
6
  "type": "git",