@lunaroute/cli 0.13.0 → 0.14.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/README.md +2 -2
- package/dist/index.js +299 -112
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -27,7 +27,7 @@ Prefer a script? `setup pi --extension` / `--models` pick a flow, `--yes` accept
|
|
|
27
27
|
## What it enables
|
|
28
28
|
|
|
29
29
|
- **One-command setup** — `lunaroute setup` writes the right config for `pi`, `claude-code`, `codex`, `opencode`, `copilot-cli`, or `generic` (any OpenAI-compatible base URL swap).
|
|
30
|
-
- **Session launches** — `lunaroute run claude` or `lunaroute run codex` starts a session wired to LunaRoute; `--model` picks from the catalog, everything after `--` passes through to the harness.
|
|
30
|
+
- **Session launches** — `lunaroute run claude` or `lunaroute run codex` starts a session wired to LunaRoute; `--model` picks from the catalog, everything after `--` passes through to the harness. `lunaroute run agy` does the same for Antigravity CLI (Gemini CLI's successor) through its gateway env vars — agy reads the model list from LunaRoute's own catalog, so any catalog model is selectable.
|
|
31
31
|
- **The catalog, in your terminal** — `models`, `pricing`, and `usage` show what's available, what it costs (credits per million tokens), and your wallet balance plus recent ledger entries.
|
|
32
32
|
- **Project memory** — `memory search` and `memory read` query your past agent conversations for the current project. `lunaroute mcp` exposes the same tools as a stdio MCP server, and `skill install` wires the memory skill + MCP into Claude Code.
|
|
33
33
|
|
|
@@ -39,7 +39,7 @@ Prefer a script? `setup pi --extension` / `--models` pick a flow, `--yes` accept
|
|
|
39
39
|
| `lunaroute whoami` | Show the signed-in user and organization |
|
|
40
40
|
| `lunaroute logout` | Remove stored credentials |
|
|
41
41
|
| `lunaroute setup <harness>` | Configure `opencode` \| `pi` \| `openclaw` \| `claude-code` \| `codex` \| `copilot-cli` \| `generic`. pi setup is interactive (asks before writing); `--extension` / `--models` pick a flow, `--yes` accepts prompts, `--print` previews |
|
|
42
|
-
| `lunaroute run <harness>` | Launch `claude` \| `claude-code` \| `codex` on LunaRoute for this session |
|
|
42
|
+
| `lunaroute run <harness>` | Launch `claude` \| `claude-code` \| `codex` \| `zed` \| `agy` on LunaRoute for this session |
|
|
43
43
|
| `lunaroute models` | List available LunaRoute models |
|
|
44
44
|
| `lunaroute pricing` | Per-model pricing (credits per million tokens) |
|
|
45
45
|
| `lunaroute usage` | Wallet balance and recent usage |
|
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.14.0";
|
|
8
8
|
|
|
9
9
|
// src/login.ts
|
|
10
10
|
import { createServer } from "http";
|
|
@@ -137,8 +137,8 @@ async function listSearchKeys(ctx) {
|
|
|
137
137
|
async function listSearchKeysRaw(ctx) {
|
|
138
138
|
return cliRequestRaw(ctx, "GET", "/v1/cli/search-provider-keys");
|
|
139
139
|
}
|
|
140
|
-
async function putSearchKey(ctx, provider,
|
|
141
|
-
return cliRequest(ctx, "PUT", "/v1/cli/search-provider-keys", { provider, api_key:
|
|
140
|
+
async function putSearchKey(ctx, provider, apiKey2) {
|
|
141
|
+
return cliRequest(ctx, "PUT", "/v1/cli/search-provider-keys", { provider, api_key: apiKey2 });
|
|
142
142
|
}
|
|
143
143
|
async function deleteSearchKey(ctx, provider) {
|
|
144
144
|
await cliRequest(ctx, "DELETE", `/v1/cli/search-provider-keys?provider=${encodeURIComponent(provider)}`);
|
|
@@ -314,7 +314,7 @@ async function startLoopbackServer() {
|
|
|
314
314
|
close: () => server.close()
|
|
315
315
|
};
|
|
316
316
|
}
|
|
317
|
-
async function runLogin(profile) {
|
|
317
|
+
async function runLogin(profile, label) {
|
|
318
318
|
const settings = resolveSettings(profile);
|
|
319
319
|
const state = genState();
|
|
320
320
|
const verifier = genVerifier();
|
|
@@ -338,7 +338,7 @@ async function runLogin(profile) {
|
|
|
338
338
|
const result = await exchangeCode(settings.api_url, {
|
|
339
339
|
code: cb.code,
|
|
340
340
|
verifier,
|
|
341
|
-
label: hostname()
|
|
341
|
+
label: label ?? hostname()
|
|
342
342
|
});
|
|
343
343
|
saveProfile(profile, {
|
|
344
344
|
api_url: settings.api_url,
|
|
@@ -453,6 +453,203 @@ function key(profile) {
|
|
|
453
453
|
console.log(creds.routing_key);
|
|
454
454
|
}
|
|
455
455
|
|
|
456
|
+
// src/commands/apiKey.ts
|
|
457
|
+
import { hostname as hostname2 } from "os";
|
|
458
|
+
|
|
459
|
+
// src/setup/prompt.ts
|
|
460
|
+
import { createInterface } from "readline/promises";
|
|
461
|
+
var NonInteractiveTerminalError = class extends Error {
|
|
462
|
+
};
|
|
463
|
+
async function confirm(question, opts = {}) {
|
|
464
|
+
if (opts.yes) return true;
|
|
465
|
+
const input = opts.input ?? process.stdin;
|
|
466
|
+
if (!input.isTTY) {
|
|
467
|
+
throw new NonInteractiveTerminalError();
|
|
468
|
+
}
|
|
469
|
+
const rl = createInterface({ input, output: opts.output ?? process.stdout });
|
|
470
|
+
try {
|
|
471
|
+
const answer = (await rl.question(`${question} [y/N] `)).trim().toLowerCase();
|
|
472
|
+
return answer === "y" || answer === "yes";
|
|
473
|
+
} finally {
|
|
474
|
+
rl.close();
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
async function promptInput(question, opts = {}) {
|
|
478
|
+
if (!process.stdin.isTTY && opts.default === void 0) {
|
|
479
|
+
throw new NonInteractiveTerminalError(`${question} requires a TTY \u2014 pass a flag instead`);
|
|
480
|
+
}
|
|
481
|
+
if (!process.stdin.isTTY) {
|
|
482
|
+
return opts.default;
|
|
483
|
+
}
|
|
484
|
+
process.stdout.write(question + (opts.default !== void 0 ? ` [${opts.default}] ` : ": "));
|
|
485
|
+
const raw = !!opts.hidden && !!process.stdin.isTTY;
|
|
486
|
+
if (raw) {
|
|
487
|
+
process.stdin.setRawMode(true);
|
|
488
|
+
}
|
|
489
|
+
const chunks = [];
|
|
490
|
+
process.stdin.resume();
|
|
491
|
+
await new Promise((resolve) => {
|
|
492
|
+
const off = () => {
|
|
493
|
+
process.stdin.removeListener("data", onData);
|
|
494
|
+
process.stdin.pause();
|
|
495
|
+
};
|
|
496
|
+
const trimOneCodepoint = () => {
|
|
497
|
+
const all = Buffer.concat(chunks);
|
|
498
|
+
let end = all.length;
|
|
499
|
+
while (end > 0 && (all[end - 1] & 192) === 128) end--;
|
|
500
|
+
if (end > 0) end--;
|
|
501
|
+
chunks.length = 0;
|
|
502
|
+
if (end > 0) chunks.push(all.subarray(0, end));
|
|
503
|
+
};
|
|
504
|
+
const onData = (c) => {
|
|
505
|
+
let i = 0;
|
|
506
|
+
let runStart = -1;
|
|
507
|
+
const flushRun = (upto) => {
|
|
508
|
+
if (runStart >= 0) {
|
|
509
|
+
chunks.push(c.subarray(runStart, upto));
|
|
510
|
+
runStart = -1;
|
|
511
|
+
}
|
|
512
|
+
};
|
|
513
|
+
while (i < c.length) {
|
|
514
|
+
const b = c[i];
|
|
515
|
+
if (raw && b === 3) {
|
|
516
|
+
off();
|
|
517
|
+
process.stdin.setRawMode(false);
|
|
518
|
+
process.exit(130);
|
|
519
|
+
}
|
|
520
|
+
if (b === 13 || b === 10) {
|
|
521
|
+
flushRun(i);
|
|
522
|
+
off();
|
|
523
|
+
resolve();
|
|
524
|
+
return;
|
|
525
|
+
}
|
|
526
|
+
if (raw && (b === 127 || b === 8)) {
|
|
527
|
+
flushRun(i);
|
|
528
|
+
trimOneCodepoint();
|
|
529
|
+
i++;
|
|
530
|
+
continue;
|
|
531
|
+
}
|
|
532
|
+
if (runStart < 0) runStart = i;
|
|
533
|
+
i++;
|
|
534
|
+
}
|
|
535
|
+
flushRun(c.length);
|
|
536
|
+
};
|
|
537
|
+
process.stdin.on("data", onData);
|
|
538
|
+
});
|
|
539
|
+
if (raw) {
|
|
540
|
+
process.stdin.setRawMode(false);
|
|
541
|
+
process.stdout.write("\n");
|
|
542
|
+
}
|
|
543
|
+
const value = Buffer.concat(chunks).toString("utf8").trim();
|
|
544
|
+
return value === "" && opts.default !== void 0 ? opts.default : value;
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
// src/commands/apiKey.ts
|
|
548
|
+
async function apiKeyShow(profile, opts = {}) {
|
|
549
|
+
const creds = loadProfile(profile);
|
|
550
|
+
if (!creds?.routing_key) {
|
|
551
|
+
const canPrompt = process.stdin.isTTY && process.stdout.isTTY || !!opts.yes;
|
|
552
|
+
if (canPrompt) {
|
|
553
|
+
let want = false;
|
|
554
|
+
try {
|
|
555
|
+
want = await confirm(`No API key for profile "${profile}". Generate a new one?`, { yes: opts.yes });
|
|
556
|
+
} catch (e) {
|
|
557
|
+
if (e instanceof NonInteractiveTerminalError) {
|
|
558
|
+
console.error('Not logged in. Run "lunaroute login" to get started.');
|
|
559
|
+
process.exitCode = 1;
|
|
560
|
+
return;
|
|
561
|
+
}
|
|
562
|
+
throw e;
|
|
563
|
+
}
|
|
564
|
+
if (!want) {
|
|
565
|
+
console.error('Not logged in. Run "lunaroute login" to get started.');
|
|
566
|
+
process.exitCode = 1;
|
|
567
|
+
return;
|
|
568
|
+
}
|
|
569
|
+
let name = opts.name;
|
|
570
|
+
if (!name && !opts.yes) {
|
|
571
|
+
try {
|
|
572
|
+
const n = await promptInput("Name for new API key", { default: "" });
|
|
573
|
+
if (n.trim()) name = n.trim();
|
|
574
|
+
} catch {
|
|
575
|
+
}
|
|
576
|
+
}
|
|
577
|
+
await runLogin(profile, name ?? hostname2());
|
|
578
|
+
const fresh = loadProfile(profile);
|
|
579
|
+
if (fresh?.routing_key) {
|
|
580
|
+
console.log(fresh.routing_key);
|
|
581
|
+
return;
|
|
582
|
+
}
|
|
583
|
+
console.error("Failed to create API key.");
|
|
584
|
+
process.exitCode = 1;
|
|
585
|
+
return;
|
|
586
|
+
}
|
|
587
|
+
console.error('Not logged in. Run "lunaroute login" to get started.');
|
|
588
|
+
process.exitCode = 1;
|
|
589
|
+
return;
|
|
590
|
+
}
|
|
591
|
+
const shouldValidate = process.stdin.isTTY && process.stdout.isTTY || !!opts.yes;
|
|
592
|
+
if (shouldValidate) {
|
|
593
|
+
const effectiveApiUrl = resolveSettings(profile).api_url;
|
|
594
|
+
const valid = await isKeyValid({ api_url: effectiveApiUrl, routing_key: creds.routing_key });
|
|
595
|
+
if (valid === false) {
|
|
596
|
+
console.error(`Stored key for profile "${profile}" is revoked or invalid (401).`);
|
|
597
|
+
let create = false;
|
|
598
|
+
try {
|
|
599
|
+
create = await confirm(`Generate a new API key for profile "${profile}"?`, { yes: opts.yes });
|
|
600
|
+
} catch (e) {
|
|
601
|
+
if (e instanceof NonInteractiveTerminalError) {
|
|
602
|
+
console.error(`Run "lunaroute login" to generate a new key${opts.name ? ` (e.g. --name "${opts.name}")` : ""}.`);
|
|
603
|
+
process.exitCode = 1;
|
|
604
|
+
return;
|
|
605
|
+
}
|
|
606
|
+
throw e;
|
|
607
|
+
}
|
|
608
|
+
if (!create) {
|
|
609
|
+
console.error("Aborted. Showing revoked key for reference (it will not authenticate).");
|
|
610
|
+
console.log(creds.routing_key);
|
|
611
|
+
return;
|
|
612
|
+
}
|
|
613
|
+
let name = opts.name;
|
|
614
|
+
if (!name && !opts.yes) {
|
|
615
|
+
try {
|
|
616
|
+
const n = await promptInput("Name for new API key (leave empty for default)", { default: "" });
|
|
617
|
+
if (n.trim()) name = n.trim();
|
|
618
|
+
} catch {
|
|
619
|
+
}
|
|
620
|
+
}
|
|
621
|
+
await runLogin(profile, name ?? hostname2());
|
|
622
|
+
const fresh = loadProfile(profile);
|
|
623
|
+
if (fresh?.routing_key) {
|
|
624
|
+
console.log(fresh.routing_key);
|
|
625
|
+
return;
|
|
626
|
+
}
|
|
627
|
+
console.error("Failed to create API key.");
|
|
628
|
+
process.exitCode = 1;
|
|
629
|
+
return;
|
|
630
|
+
}
|
|
631
|
+
}
|
|
632
|
+
console.log(creds.routing_key);
|
|
633
|
+
}
|
|
634
|
+
async function isKeyValid(creds) {
|
|
635
|
+
const controller = new AbortController();
|
|
636
|
+
const t = setTimeout(() => controller.abort(), 2500);
|
|
637
|
+
try {
|
|
638
|
+
const res = await fetch(`${creds.api_url}/v1/cli/models`, {
|
|
639
|
+
method: "GET",
|
|
640
|
+
headers: { Authorization: `Bearer ${creds.routing_key}` },
|
|
641
|
+
signal: controller.signal
|
|
642
|
+
});
|
|
643
|
+
if (res.status === 401) return false;
|
|
644
|
+
if (res.ok) return true;
|
|
645
|
+
return null;
|
|
646
|
+
} catch {
|
|
647
|
+
return null;
|
|
648
|
+
} finally {
|
|
649
|
+
clearTimeout(t);
|
|
650
|
+
}
|
|
651
|
+
}
|
|
652
|
+
|
|
456
653
|
// src/commands/logout.ts
|
|
457
654
|
function logout(profile) {
|
|
458
655
|
if (!loadProfile(profile)) {
|
|
@@ -755,94 +952,6 @@ ${block.header}`);
|
|
|
755
952
|
return summary;
|
|
756
953
|
}
|
|
757
954
|
|
|
758
|
-
// src/setup/prompt.ts
|
|
759
|
-
import { createInterface } from "readline/promises";
|
|
760
|
-
var NonInteractiveTerminalError = class extends Error {
|
|
761
|
-
};
|
|
762
|
-
async function confirm(question, opts = {}) {
|
|
763
|
-
if (opts.yes) return true;
|
|
764
|
-
const input = opts.input ?? process.stdin;
|
|
765
|
-
if (!input.isTTY) {
|
|
766
|
-
throw new NonInteractiveTerminalError();
|
|
767
|
-
}
|
|
768
|
-
const rl = createInterface({ input, output: opts.output ?? process.stdout });
|
|
769
|
-
try {
|
|
770
|
-
const answer = (await rl.question(`${question} [y/N] `)).trim().toLowerCase();
|
|
771
|
-
return answer === "y" || answer === "yes";
|
|
772
|
-
} finally {
|
|
773
|
-
rl.close();
|
|
774
|
-
}
|
|
775
|
-
}
|
|
776
|
-
async function promptInput(question, opts = {}) {
|
|
777
|
-
if (!process.stdin.isTTY && opts.default === void 0) {
|
|
778
|
-
throw new NonInteractiveTerminalError(`${question} requires a TTY \u2014 pass a flag instead`);
|
|
779
|
-
}
|
|
780
|
-
if (!process.stdin.isTTY) {
|
|
781
|
-
return opts.default;
|
|
782
|
-
}
|
|
783
|
-
process.stdout.write(question + (opts.default !== void 0 ? ` [${opts.default}] ` : ": "));
|
|
784
|
-
const raw = !!opts.hidden && !!process.stdin.isTTY;
|
|
785
|
-
if (raw) {
|
|
786
|
-
process.stdin.setRawMode(true);
|
|
787
|
-
}
|
|
788
|
-
const chunks = [];
|
|
789
|
-
process.stdin.resume();
|
|
790
|
-
await new Promise((resolve) => {
|
|
791
|
-
const off = () => {
|
|
792
|
-
process.stdin.removeListener("data", onData);
|
|
793
|
-
process.stdin.pause();
|
|
794
|
-
};
|
|
795
|
-
const trimOneCodepoint = () => {
|
|
796
|
-
const all = Buffer.concat(chunks);
|
|
797
|
-
let end = all.length;
|
|
798
|
-
while (end > 0 && (all[end - 1] & 192) === 128) end--;
|
|
799
|
-
if (end > 0) end--;
|
|
800
|
-
chunks.length = 0;
|
|
801
|
-
if (end > 0) chunks.push(all.subarray(0, end));
|
|
802
|
-
};
|
|
803
|
-
const onData = (c) => {
|
|
804
|
-
let i = 0;
|
|
805
|
-
let runStart = -1;
|
|
806
|
-
const flushRun = (upto) => {
|
|
807
|
-
if (runStart >= 0) {
|
|
808
|
-
chunks.push(c.subarray(runStart, upto));
|
|
809
|
-
runStart = -1;
|
|
810
|
-
}
|
|
811
|
-
};
|
|
812
|
-
while (i < c.length) {
|
|
813
|
-
const b = c[i];
|
|
814
|
-
if (raw && b === 3) {
|
|
815
|
-
off();
|
|
816
|
-
process.stdin.setRawMode(false);
|
|
817
|
-
process.exit(130);
|
|
818
|
-
}
|
|
819
|
-
if (b === 13 || b === 10) {
|
|
820
|
-
flushRun(i);
|
|
821
|
-
off();
|
|
822
|
-
resolve();
|
|
823
|
-
return;
|
|
824
|
-
}
|
|
825
|
-
if (raw && (b === 127 || b === 8)) {
|
|
826
|
-
flushRun(i);
|
|
827
|
-
trimOneCodepoint();
|
|
828
|
-
i++;
|
|
829
|
-
continue;
|
|
830
|
-
}
|
|
831
|
-
if (runStart < 0) runStart = i;
|
|
832
|
-
i++;
|
|
833
|
-
}
|
|
834
|
-
flushRun(c.length);
|
|
835
|
-
};
|
|
836
|
-
process.stdin.on("data", onData);
|
|
837
|
-
});
|
|
838
|
-
if (raw) {
|
|
839
|
-
process.stdin.setRawMode(false);
|
|
840
|
-
process.stdout.write("\n");
|
|
841
|
-
}
|
|
842
|
-
const value = Buffer.concat(chunks).toString("utf8").trim();
|
|
843
|
-
return value === "" && opts.default !== void 0 ? opts.default : value;
|
|
844
|
-
}
|
|
845
|
-
|
|
846
955
|
// src/spawn.ts
|
|
847
956
|
import { spawn as nodeSpawn } from "child_process";
|
|
848
957
|
import { spawn as crossSpawn } from "cross-spawn";
|
|
@@ -1759,8 +1868,8 @@ function buildPlan10(ctx) {
|
|
|
1759
1868
|
};
|
|
1760
1869
|
const notes = [
|
|
1761
1870
|
"\nzed: restart Zed, then pick a LunaRoute model in the agent panel.",
|
|
1762
|
-
'zed:
|
|
1763
|
-
`zed: or set ${ctx.keyEnvVar} (the block above), which Zed reads at launch and
|
|
1871
|
+
'zed: paste the API key in Zed via Settings \u2192 AI \u2192 General \u2192 LLM Providers \u2192 Configure \u2192 find lunaroute \u2192 Configure \u2192 paste the API key. Print the key with "lunaroute key" (or create one in the dashboard if you have none); this stores it in the OS keychain.',
|
|
1872
|
+
`zed: or set ${ctx.keyEnvVar} (the block above), which Zed reads at launch and takes precedence over the keychain; or launch with "lunaroute run zed" to inject it for one session \u2014 quit a running Zed first.`
|
|
1764
1873
|
];
|
|
1765
1874
|
if (skipped.length > 0) {
|
|
1766
1875
|
notes.push(`Skipped (no context window or output limit in the catalog): ${skipped.join(", ")}`);
|
|
@@ -1791,6 +1900,26 @@ function buildPlan10(ctx) {
|
|
|
1791
1900
|
};
|
|
1792
1901
|
}
|
|
1793
1902
|
|
|
1903
|
+
// src/setup/adapters/agy.ts
|
|
1904
|
+
function buildPlan11(ctx) {
|
|
1905
|
+
const model = ctx.models[0]?.id ?? "(no chat models in the catalog yet)";
|
|
1906
|
+
return {
|
|
1907
|
+
fileWrites: [],
|
|
1908
|
+
exports: [
|
|
1909
|
+
{ name: "AGY_LLM_GATEWAY_URL", value: `${ctx.routingUrl}/v1` },
|
|
1910
|
+
{ name: "AGY_LLM_GATEWAY_API_KEY", value: "__KEY__" }
|
|
1911
|
+
],
|
|
1912
|
+
notes: [
|
|
1913
|
+
"\nAntigravity CLI (agy) setup:",
|
|
1914
|
+
" Nothing is written to ~/.gemini/antigravity-cli \u2014 agy reads these two variables at launch.",
|
|
1915
|
+
" Or skip the exports entirely and let the CLI own the session:",
|
|
1916
|
+
" lunaroute run agy # first model in the catalog",
|
|
1917
|
+
` lunaroute run agy --model ${model}`,
|
|
1918
|
+
" agy takes its model list from LunaRoute's catalog, so any model id is selectable."
|
|
1919
|
+
]
|
|
1920
|
+
};
|
|
1921
|
+
}
|
|
1922
|
+
|
|
1794
1923
|
// src/setup/snapshot.ts
|
|
1795
1924
|
import {
|
|
1796
1925
|
chmodSync as chmodSync4,
|
|
@@ -1990,6 +2119,7 @@ var ADAPTERS = {
|
|
|
1990
2119
|
"claude-desktop": buildPlan4,
|
|
1991
2120
|
codex: buildPlan5,
|
|
1992
2121
|
"copilot-cli": buildPlan6,
|
|
2122
|
+
agy: buildPlan11,
|
|
1993
2123
|
generic: buildPlan7
|
|
1994
2124
|
};
|
|
1995
2125
|
var PI_INSTALL_PACKAGES = ["npm:@lunaroute/pi-extension"];
|
|
@@ -2956,7 +3086,7 @@ async function runSearchKeysSet(profile, opts) {
|
|
|
2956
3086
|
const ctx = { apiUrl: s.api_url, apiKey: s.routing_key };
|
|
2957
3087
|
try {
|
|
2958
3088
|
let provider = opts.provider;
|
|
2959
|
-
let
|
|
3089
|
+
let apiKey2 = opts.apiKey ?? process.env.LUNAROUTE_SEARCH_API_KEY;
|
|
2960
3090
|
const providers = await listSearchProviders(ctx);
|
|
2961
3091
|
const known = providers.map((p) => p.key);
|
|
2962
3092
|
if (!provider) {
|
|
@@ -2966,10 +3096,10 @@ async function runSearchKeysSet(profile, opts) {
|
|
|
2966
3096
|
console.error(`unknown provider "${provider}" \u2014 this server offers: ${known.join(", ")}`);
|
|
2967
3097
|
return 1;
|
|
2968
3098
|
}
|
|
2969
|
-
if (!
|
|
2970
|
-
|
|
3099
|
+
if (!apiKey2) {
|
|
3100
|
+
apiKey2 = await promptInput("API key", { hidden: true });
|
|
2971
3101
|
}
|
|
2972
|
-
const meta = await putSearchKey(ctx, provider,
|
|
3102
|
+
const meta = await putSearchKey(ctx, provider, apiKey2);
|
|
2973
3103
|
console.log(`Stored key for ${meta.provider} (updated ${meta.updated_at}).`);
|
|
2974
3104
|
return 0;
|
|
2975
3105
|
} catch (err) {
|
|
@@ -3239,9 +3369,13 @@ function buildRunSpec2(ctx) {
|
|
|
3239
3369
|
}
|
|
3240
3370
|
|
|
3241
3371
|
// src/run/adapters/zed.ts
|
|
3242
|
-
import {
|
|
3372
|
+
import { existsSync as existsSync6, readFileSync as readFileSync8, realpathSync as realpathSync2 } from "fs";
|
|
3243
3373
|
import { homedir as homedir3 } from "os";
|
|
3244
|
-
import { basename as basename2, dirname as dirname4, join as
|
|
3374
|
+
import { basename as basename2, dirname as dirname4, join as join6 } from "path";
|
|
3375
|
+
|
|
3376
|
+
// src/run/which.ts
|
|
3377
|
+
import { accessSync, constants as constants2 } from "fs";
|
|
3378
|
+
import { join as join5 } from "path";
|
|
3245
3379
|
function which(cmd, env, platform) {
|
|
3246
3380
|
const pathVar = env.PATH ?? env.Path ?? "";
|
|
3247
3381
|
const exts = platform === "win32" ? (env.PATHEXT ?? ".COM;.EXE;.BAT;.CMD").split(";").filter(Boolean) : [""];
|
|
@@ -3259,6 +3393,8 @@ function which(cmd, env, platform) {
|
|
|
3259
3393
|
}
|
|
3260
3394
|
return null;
|
|
3261
3395
|
}
|
|
3396
|
+
|
|
3397
|
+
// src/run/adapters/zed.ts
|
|
3262
3398
|
function firstExisting(paths) {
|
|
3263
3399
|
for (const path of paths) if (existsSync6(path)) return path;
|
|
3264
3400
|
return null;
|
|
@@ -3273,7 +3409,7 @@ function resolveZedCommand(deps = {}) {
|
|
|
3273
3409
|
try {
|
|
3274
3410
|
const real = realpathSync2(shim);
|
|
3275
3411
|
if (basename2(real) === "cli") {
|
|
3276
|
-
const app =
|
|
3412
|
+
const app = join6(dirname4(real), "zed");
|
|
3277
3413
|
if (existsSync6(app)) return app;
|
|
3278
3414
|
}
|
|
3279
3415
|
return real;
|
|
@@ -3283,20 +3419,20 @@ function resolveZedCommand(deps = {}) {
|
|
|
3283
3419
|
}
|
|
3284
3420
|
return firstExisting([
|
|
3285
3421
|
"/Applications/Zed.app/Contents/MacOS/zed",
|
|
3286
|
-
|
|
3422
|
+
join6(home, "Applications", "Zed.app", "Contents", "MacOS", "zed"),
|
|
3287
3423
|
"/Applications/Zed Preview.app/Contents/MacOS/zed",
|
|
3288
|
-
|
|
3424
|
+
join6(home, "Applications", "Zed Preview.app", "Contents", "MacOS", "zed"),
|
|
3289
3425
|
"/Applications/Zed Nightly.app/Contents/MacOS/zed"
|
|
3290
3426
|
]);
|
|
3291
3427
|
}
|
|
3292
3428
|
if (platform === "win32") {
|
|
3293
3429
|
const onPath = which("zed", env, platform);
|
|
3294
3430
|
if (onPath) return onPath;
|
|
3295
|
-
return env.LOCALAPPDATA ? firstExisting([
|
|
3431
|
+
return env.LOCALAPPDATA ? firstExisting([join6(env.LOCALAPPDATA, "Programs", "Zed", "zed.exe")]) : null;
|
|
3296
3432
|
}
|
|
3297
3433
|
return which("zed", env, platform) ?? which("zed-x11", env, platform) ?? firstExisting([
|
|
3298
|
-
|
|
3299
|
-
|
|
3434
|
+
join6(home, ".local", "bin", "zed"),
|
|
3435
|
+
join6(home, ".local", "zed.app", "bin", "zed")
|
|
3300
3436
|
]);
|
|
3301
3437
|
}
|
|
3302
3438
|
function hasLunarouteProvider(settingsPath) {
|
|
@@ -3321,19 +3457,65 @@ function buildRunSpec3(ctx, deps = {}) {
|
|
|
3321
3457
|
};
|
|
3322
3458
|
}
|
|
3323
3459
|
|
|
3460
|
+
// src/run/adapters/agy.ts
|
|
3461
|
+
import { accessSync as accessSync2, constants as constants3 } from "fs";
|
|
3462
|
+
import { homedir as homedir4 } from "os";
|
|
3463
|
+
import { join as join7 } from "path";
|
|
3464
|
+
function firstRunnable(paths, platform) {
|
|
3465
|
+
for (const path of paths) {
|
|
3466
|
+
try {
|
|
3467
|
+
accessSync2(path, platform === "win32" ? constants3.F_OK : constants3.X_OK);
|
|
3468
|
+
return path;
|
|
3469
|
+
} catch {
|
|
3470
|
+
}
|
|
3471
|
+
}
|
|
3472
|
+
return null;
|
|
3473
|
+
}
|
|
3474
|
+
function resolveAgyCommand(deps = {}) {
|
|
3475
|
+
const platform = deps.platform ?? process.platform;
|
|
3476
|
+
const env = deps.env ?? process.env;
|
|
3477
|
+
const home = env.HOME || env.USERPROFILE || homedir4();
|
|
3478
|
+
const onPath = which("agy", env, platform);
|
|
3479
|
+
if (onPath) return onPath;
|
|
3480
|
+
if (platform === "win32") {
|
|
3481
|
+
const localAppData = env.LOCALAPPDATA;
|
|
3482
|
+
const programFiles = env.ProgramFiles || env.PROGRAMFILES || "C:\\Program Files";
|
|
3483
|
+
return firstRunnable(
|
|
3484
|
+
[
|
|
3485
|
+
...localAppData ? [join7(localAppData, "agy", "bin", "agy.exe")] : [],
|
|
3486
|
+
join7(programFiles, "Google", "antigravity-cli", "agy.exe")
|
|
3487
|
+
],
|
|
3488
|
+
platform
|
|
3489
|
+
);
|
|
3490
|
+
}
|
|
3491
|
+
return firstRunnable([join7(home, ".local", "bin", "agy")], platform);
|
|
3492
|
+
}
|
|
3493
|
+
function buildRunSpec4(ctx, deps = {}) {
|
|
3494
|
+
return {
|
|
3495
|
+
command: resolveAgyCommand(deps) ?? "agy",
|
|
3496
|
+
args: ["--model", ctx.model],
|
|
3497
|
+
env: {
|
|
3498
|
+
AGY_LLM_GATEWAY_URL: `${ctx.routingUrl}/v1`,
|
|
3499
|
+
AGY_LLM_GATEWAY_API_KEY: ctx.apiKey
|
|
3500
|
+
}
|
|
3501
|
+
};
|
|
3502
|
+
}
|
|
3503
|
+
|
|
3324
3504
|
// src/commands/run.ts
|
|
3325
3505
|
var ADAPTERS2 = {
|
|
3326
3506
|
claude: buildRunSpec,
|
|
3327
3507
|
"claude-code": buildRunSpec,
|
|
3328
3508
|
codex: buildRunSpec2,
|
|
3329
|
-
zed: buildRunSpec3
|
|
3509
|
+
zed: buildRunSpec3,
|
|
3510
|
+
agy: buildRunSpec4
|
|
3330
3511
|
};
|
|
3331
3512
|
var MODEL_LOOKUP_TIMEOUT_MS = 3e3;
|
|
3332
3513
|
var INSTALL_HINT = {
|
|
3333
3514
|
claude: "Install Claude Code: https://docs.anthropic.com/claude-code/install",
|
|
3334
3515
|
"claude-code": "Install Claude Code: https://docs.anthropic.com/claude-code/install",
|
|
3335
3516
|
codex: "Install Codex: https://github.com/openai/codex#install",
|
|
3336
|
-
zed: "Install Zed: https://zed.dev/download (Windows: winget install -e --id ZedIndustries.Zed)"
|
|
3517
|
+
zed: "Install Zed: https://zed.dev/download (Windows: winget install -e --id ZedIndustries.Zed)",
|
|
3518
|
+
agy: "Install Antigravity CLI: curl -fsSL https://antigravity.google/cli/install.sh | bash (Windows: https://antigravity.google/cli/install.ps1)"
|
|
3337
3519
|
};
|
|
3338
3520
|
var realDeps = {
|
|
3339
3521
|
spawn: makeRealSpawn(),
|
|
@@ -3430,10 +3612,15 @@ program.command("whoami").description("Show the signed-in user and organization.
|
|
|
3430
3612
|
program.command("key").description('Print the stored routing key, for shell use (e.g. "$(lunaroute key)").').action(() => {
|
|
3431
3613
|
key(program.opts().profile);
|
|
3432
3614
|
});
|
|
3615
|
+
var apiKey = program.command("api-key").alias("api-keys").description("Manage API keys.");
|
|
3616
|
+
apiKey.command("show").description('Show the stored API key (same as "lunaroute key"; reuses existing key, prompts with --name on revocation).').option("--name <name>", "name for the new key when generating after revocation (or when no key exists)").option("--yes", "accept prompts without a TTY", false).action(async (opts) => {
|
|
3617
|
+
await apiKeyShow(program.opts().profile, { name: opts.name, yes: opts.yes });
|
|
3618
|
+
if (process.exitCode && process.exitCode !== 0) process.exit(process.exitCode);
|
|
3619
|
+
});
|
|
3433
3620
|
program.command("logout").description("Remove stored credentials for the active profile.").action(() => {
|
|
3434
3621
|
logout(program.opts().profile);
|
|
3435
3622
|
});
|
|
3436
|
-
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) => {
|
|
3623
|
+
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: 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) => {
|
|
3437
3624
|
const code = await runSetup(harness, {
|
|
3438
3625
|
profile: program.opts().profile,
|
|
3439
3626
|
print: opts.print,
|
|
@@ -3446,7 +3633,7 @@ program.command("setup <harness>").description("Configure a coding harness (open
|
|
|
3446
3633
|
});
|
|
3447
3634
|
if (code !== 0) process.exit(code);
|
|
3448
3635
|
});
|
|
3449
|
-
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) => {
|
|
3636
|
+
program.command("run <harness>").description("Launch a coding harness (claude | claude-code | codex | zed | agy) 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) => {
|
|
3450
3637
|
const sep = process.argv.indexOf("--");
|
|
3451
3638
|
const post = sep !== -1 ? process.argv.slice(sep + 1) : [];
|
|
3452
3639
|
const before = post.length <= extra.length ? extra.slice(0, extra.length - post.length) : extra;
|
|
@@ -3514,7 +3701,7 @@ searchKeys.command("list").description("List configured search provider keys.").
|
|
|
3514
3701
|
const code = await runSearchKeysList(program.opts().profile, { json: opts.json });
|
|
3515
3702
|
if (code !== 0) process.exit(code);
|
|
3516
3703
|
});
|
|
3517
|
-
searchKeys.command("set").description("Store or replace a search provider key (prompts for missing values).").option("--provider <key>", "provider key (e.g. kagi, brave, exa)").option("--api-key <key>", "API key (visible in shell history \u2014 prefer the prompt or LUNAROUTE_SEARCH_API_KEY)").action(async (opts) => {
|
|
3704
|
+
searchKeys.command("set").description("Store or replace a search provider key (prompts for missing values).").option("--provider <key>", "provider key (e.g. kagi, brave, exa, youcom)").option("--api-key <key>", "API key (visible in shell history \u2014 prefer the prompt or LUNAROUTE_SEARCH_API_KEY)").action(async (opts) => {
|
|
3518
3705
|
const code = await runSearchKeysSet(program.opts().profile, { provider: opts.provider, apiKey: opts.apiKey });
|
|
3519
3706
|
if (code !== 0) process.exit(code);
|
|
3520
3707
|
});
|