@lunaroute/cli 0.12.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 +384 -122
- 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)) {
|
|
@@ -604,18 +801,77 @@ function renderEnvBlock(exports, opts) {
|
|
|
604
801
|
}
|
|
605
802
|
|
|
606
803
|
// src/setup/apply.ts
|
|
607
|
-
function readExistingJson(path) {
|
|
608
|
-
if (!existsSync3(path)) return null;
|
|
804
|
+
function readExistingJson(path, jsonc = false) {
|
|
805
|
+
if (!existsSync3(path)) return { value: null, droppedComments: false };
|
|
609
806
|
const raw = readFileSync3(path, "utf8").trim();
|
|
610
|
-
if (raw === "") return null;
|
|
807
|
+
if (raw === "") return { value: null, droppedComments: false };
|
|
808
|
+
const scanned = jsonc ? stripJsonc(raw) : { text: raw, hadComments: false };
|
|
611
809
|
try {
|
|
612
|
-
return JSON.parse(
|
|
810
|
+
return { value: JSON.parse(scanned.text), droppedComments: scanned.hadComments };
|
|
613
811
|
} catch {
|
|
614
812
|
throw new Error(
|
|
615
|
-
`refusing to modify ${path}: it exists but is not valid JSON (malformed). Fix or remove it
|
|
813
|
+
`refusing to modify ${path}: it exists but is not valid JSON (malformed). Fix or remove it and re-run.`
|
|
616
814
|
);
|
|
617
815
|
}
|
|
618
816
|
}
|
|
817
|
+
function stripJsonc(raw) {
|
|
818
|
+
let text = "";
|
|
819
|
+
let hadComments = false;
|
|
820
|
+
let i = 0;
|
|
821
|
+
while (i < raw.length) {
|
|
822
|
+
const c = raw[i];
|
|
823
|
+
if (c === '"') {
|
|
824
|
+
text += c;
|
|
825
|
+
i++;
|
|
826
|
+
while (i < raw.length) {
|
|
827
|
+
const s = raw[i];
|
|
828
|
+
text += s;
|
|
829
|
+
i++;
|
|
830
|
+
if (s === "\\") {
|
|
831
|
+
text += raw[i] ?? "";
|
|
832
|
+
i++;
|
|
833
|
+
} else if (s === '"') break;
|
|
834
|
+
}
|
|
835
|
+
continue;
|
|
836
|
+
}
|
|
837
|
+
if (c === "/" && raw[i + 1] === "/") {
|
|
838
|
+
hadComments = true;
|
|
839
|
+
while (i < raw.length && raw[i] !== "\n") i++;
|
|
840
|
+
continue;
|
|
841
|
+
}
|
|
842
|
+
if (c === "/" && raw[i + 1] === "*") {
|
|
843
|
+
hadComments = true;
|
|
844
|
+
i += 2;
|
|
845
|
+
while (i < raw.length && !(raw[i] === "*" && raw[i + 1] === "/")) i++;
|
|
846
|
+
i += 2;
|
|
847
|
+
continue;
|
|
848
|
+
}
|
|
849
|
+
if (c === ",") {
|
|
850
|
+
let j = i + 1;
|
|
851
|
+
for (; ; ) {
|
|
852
|
+
while (j < raw.length && /\s/.test(raw[j])) j++;
|
|
853
|
+
if (raw[j] === "/" && raw[j + 1] === "/") {
|
|
854
|
+
while (j < raw.length && raw[j] !== "\n") j++;
|
|
855
|
+
continue;
|
|
856
|
+
}
|
|
857
|
+
if (raw[j] === "/" && raw[j + 1] === "*") {
|
|
858
|
+
j += 2;
|
|
859
|
+
while (j < raw.length && !(raw[j] === "*" && raw[j + 1] === "/")) j++;
|
|
860
|
+
j += 2;
|
|
861
|
+
continue;
|
|
862
|
+
}
|
|
863
|
+
break;
|
|
864
|
+
}
|
|
865
|
+
if (raw[j] === "}" || raw[j] === "]") {
|
|
866
|
+
i++;
|
|
867
|
+
continue;
|
|
868
|
+
}
|
|
869
|
+
}
|
|
870
|
+
text += c;
|
|
871
|
+
i++;
|
|
872
|
+
}
|
|
873
|
+
return { text, hadComments };
|
|
874
|
+
}
|
|
619
875
|
function resolveYamlContent(fw) {
|
|
620
876
|
const curStr = existsSync3(fw.path) ? readFileSync3(fw.path, "utf8") : null;
|
|
621
877
|
const doc = parseDocument(curStr ?? "", { logLevel: "silent" });
|
|
@@ -634,20 +890,25 @@ function resolveYamlContent(fw) {
|
|
|
634
890
|
function resolveContent(fw) {
|
|
635
891
|
if (fw.kind === "text") {
|
|
636
892
|
const curStr2 = existsSync3(fw.path) ? readFileSync3(fw.path, "utf8") : null;
|
|
637
|
-
return { nextStr: fw.content, curStr: curStr2 };
|
|
893
|
+
return { nextStr: fw.content, curStr: curStr2, droppedComments: false };
|
|
638
894
|
}
|
|
639
|
-
if (fw.kind === "yaml") return resolveYamlContent(fw);
|
|
640
|
-
const existing = readExistingJson(fw.path);
|
|
895
|
+
if (fw.kind === "yaml") return { ...resolveYamlContent(fw), droppedComments: false };
|
|
896
|
+
const { value: existing, droppedComments } = readExistingJson(fw.path, fw.jsonc);
|
|
641
897
|
const curStr = existing === null ? null : `${JSON.stringify(existing, null, 2)}
|
|
642
898
|
`;
|
|
643
899
|
const nextStr = `${JSON.stringify(fw.merge(existing), null, 2)}
|
|
644
900
|
`;
|
|
645
|
-
return { nextStr, curStr };
|
|
901
|
+
return { nextStr, curStr, droppedComments };
|
|
646
902
|
}
|
|
647
903
|
async function applyPlan(plan, opts) {
|
|
648
904
|
const summary = { written: [], backedUp: [] };
|
|
649
905
|
for (const fw of plan.fileWrites) {
|
|
650
|
-
const { nextStr, curStr } = resolveContent(fw);
|
|
906
|
+
const { nextStr, curStr, droppedComments } = resolveContent(fw);
|
|
907
|
+
if (droppedComments) {
|
|
908
|
+
console.log(
|
|
909
|
+
opts.print ? `# ${fw.path}: the merged settings are plain JSON \u2014 comments are dropped` : `# ${fw.path}: comments are dropped by the rewrite${fw.backup !== false ? `; the original is kept at ${fw.path}.bak` : ""}`
|
|
910
|
+
);
|
|
911
|
+
}
|
|
651
912
|
if (opts.print) {
|
|
652
913
|
console.log(`
|
|
653
914
|
# would write ${fw.path}:
|
|
@@ -691,94 +952,6 @@ ${block.header}`);
|
|
|
691
952
|
return summary;
|
|
692
953
|
}
|
|
693
954
|
|
|
694
|
-
// src/setup/prompt.ts
|
|
695
|
-
import { createInterface } from "readline/promises";
|
|
696
|
-
var NonInteractiveTerminalError = class extends Error {
|
|
697
|
-
};
|
|
698
|
-
async function confirm(question, opts = {}) {
|
|
699
|
-
if (opts.yes) return true;
|
|
700
|
-
const input = opts.input ?? process.stdin;
|
|
701
|
-
if (!input.isTTY) {
|
|
702
|
-
throw new NonInteractiveTerminalError();
|
|
703
|
-
}
|
|
704
|
-
const rl = createInterface({ input, output: opts.output ?? process.stdout });
|
|
705
|
-
try {
|
|
706
|
-
const answer = (await rl.question(`${question} [y/N] `)).trim().toLowerCase();
|
|
707
|
-
return answer === "y" || answer === "yes";
|
|
708
|
-
} finally {
|
|
709
|
-
rl.close();
|
|
710
|
-
}
|
|
711
|
-
}
|
|
712
|
-
async function promptInput(question, opts = {}) {
|
|
713
|
-
if (!process.stdin.isTTY && opts.default === void 0) {
|
|
714
|
-
throw new NonInteractiveTerminalError(`${question} requires a TTY \u2014 pass a flag instead`);
|
|
715
|
-
}
|
|
716
|
-
if (!process.stdin.isTTY) {
|
|
717
|
-
return opts.default;
|
|
718
|
-
}
|
|
719
|
-
process.stdout.write(question + (opts.default !== void 0 ? ` [${opts.default}] ` : ": "));
|
|
720
|
-
const raw = !!opts.hidden && !!process.stdin.isTTY;
|
|
721
|
-
if (raw) {
|
|
722
|
-
process.stdin.setRawMode(true);
|
|
723
|
-
}
|
|
724
|
-
const chunks = [];
|
|
725
|
-
process.stdin.resume();
|
|
726
|
-
await new Promise((resolve) => {
|
|
727
|
-
const off = () => {
|
|
728
|
-
process.stdin.removeListener("data", onData);
|
|
729
|
-
process.stdin.pause();
|
|
730
|
-
};
|
|
731
|
-
const trimOneCodepoint = () => {
|
|
732
|
-
const all = Buffer.concat(chunks);
|
|
733
|
-
let end = all.length;
|
|
734
|
-
while (end > 0 && (all[end - 1] & 192) === 128) end--;
|
|
735
|
-
if (end > 0) end--;
|
|
736
|
-
chunks.length = 0;
|
|
737
|
-
if (end > 0) chunks.push(all.subarray(0, end));
|
|
738
|
-
};
|
|
739
|
-
const onData = (c) => {
|
|
740
|
-
let i = 0;
|
|
741
|
-
let runStart = -1;
|
|
742
|
-
const flushRun = (upto) => {
|
|
743
|
-
if (runStart >= 0) {
|
|
744
|
-
chunks.push(c.subarray(runStart, upto));
|
|
745
|
-
runStart = -1;
|
|
746
|
-
}
|
|
747
|
-
};
|
|
748
|
-
while (i < c.length) {
|
|
749
|
-
const b = c[i];
|
|
750
|
-
if (raw && b === 3) {
|
|
751
|
-
off();
|
|
752
|
-
process.stdin.setRawMode(false);
|
|
753
|
-
process.exit(130);
|
|
754
|
-
}
|
|
755
|
-
if (b === 13 || b === 10) {
|
|
756
|
-
flushRun(i);
|
|
757
|
-
off();
|
|
758
|
-
resolve();
|
|
759
|
-
return;
|
|
760
|
-
}
|
|
761
|
-
if (raw && (b === 127 || b === 8)) {
|
|
762
|
-
flushRun(i);
|
|
763
|
-
trimOneCodepoint();
|
|
764
|
-
i++;
|
|
765
|
-
continue;
|
|
766
|
-
}
|
|
767
|
-
if (runStart < 0) runStart = i;
|
|
768
|
-
i++;
|
|
769
|
-
}
|
|
770
|
-
flushRun(c.length);
|
|
771
|
-
};
|
|
772
|
-
process.stdin.on("data", onData);
|
|
773
|
-
});
|
|
774
|
-
if (raw) {
|
|
775
|
-
process.stdin.setRawMode(false);
|
|
776
|
-
process.stdout.write("\n");
|
|
777
|
-
}
|
|
778
|
-
const value = Buffer.concat(chunks).toString("utf8").trim();
|
|
779
|
-
return value === "" && opts.default !== void 0 ? opts.default : value;
|
|
780
|
-
}
|
|
781
|
-
|
|
782
955
|
// src/spawn.ts
|
|
783
956
|
import { spawn as nodeSpawn } from "child_process";
|
|
784
957
|
import { spawn as crossSpawn } from "cross-spawn";
|
|
@@ -933,6 +1106,8 @@ function extensionPlan(ctx) {
|
|
|
933
1106
|
{
|
|
934
1107
|
kind: "json",
|
|
935
1108
|
path: opencodeConfigPath(),
|
|
1109
|
+
jsonc: true,
|
|
1110
|
+
// opencode documents JSONC config
|
|
936
1111
|
merge: (existing) => {
|
|
937
1112
|
const obj = existing ?? {};
|
|
938
1113
|
const raw = obj.plugin;
|
|
@@ -988,6 +1163,8 @@ function providerPlan(ctx) {
|
|
|
988
1163
|
{
|
|
989
1164
|
kind: "json",
|
|
990
1165
|
path: opencodeConfigPath(),
|
|
1166
|
+
jsonc: true,
|
|
1167
|
+
// opencode documents JSONC config
|
|
991
1168
|
merge: (existing) => {
|
|
992
1169
|
const obj = existing ?? {};
|
|
993
1170
|
const existingProviders = objectOrEmpty(obj.provider);
|
|
@@ -1445,6 +1622,11 @@ function buildPlan8(ctx) {
|
|
|
1445
1622
|
{
|
|
1446
1623
|
kind: "json",
|
|
1447
1624
|
path: openclawConfigPath(),
|
|
1625
|
+
// OpenClaw's config is JSON5 ("comments + trailing commas allowed"), so
|
|
1626
|
+
// a hand-edited file is read tolerantly.
|
|
1627
|
+
// shortcut: the JSON subset of JSON5 only — unquoted keys and single
|
|
1628
|
+
// quotes still refuse; widen it if a real openclaw.json needs it (kata tnhh).
|
|
1629
|
+
jsonc: true,
|
|
1448
1630
|
merge: (existing) => {
|
|
1449
1631
|
const obj = asRecord(existing);
|
|
1450
1632
|
const modelsCfg = asRecord(obj.models);
|
|
@@ -1686,8 +1868,8 @@ function buildPlan10(ctx) {
|
|
|
1686
1868
|
};
|
|
1687
1869
|
const notes = [
|
|
1688
1870
|
"\nzed: restart Zed, then pick a LunaRoute model in the agent panel.",
|
|
1689
|
-
'zed:
|
|
1690
|
-
`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.`
|
|
1691
1873
|
];
|
|
1692
1874
|
if (skipped.length > 0) {
|
|
1693
1875
|
notes.push(`Skipped (no context window or output limit in the catalog): ${skipped.join(", ")}`);
|
|
@@ -1697,6 +1879,8 @@ function buildPlan10(ctx) {
|
|
|
1697
1879
|
{
|
|
1698
1880
|
kind: "json",
|
|
1699
1881
|
path: zedSettingsPath(),
|
|
1882
|
+
// Zed ships settings.json as JSONC (its template header is comments).
|
|
1883
|
+
jsonc: true,
|
|
1700
1884
|
merge: (existing) => {
|
|
1701
1885
|
const obj = objectOrEmpty2(existing);
|
|
1702
1886
|
const languageModels = objectOrEmpty2(obj.language_models);
|
|
@@ -1716,6 +1900,26 @@ function buildPlan10(ctx) {
|
|
|
1716
1900
|
};
|
|
1717
1901
|
}
|
|
1718
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
|
+
|
|
1719
1923
|
// src/setup/snapshot.ts
|
|
1720
1924
|
import {
|
|
1721
1925
|
chmodSync as chmodSync4,
|
|
@@ -1915,6 +2119,7 @@ var ADAPTERS = {
|
|
|
1915
2119
|
"claude-desktop": buildPlan4,
|
|
1916
2120
|
codex: buildPlan5,
|
|
1917
2121
|
"copilot-cli": buildPlan6,
|
|
2122
|
+
agy: buildPlan11,
|
|
1918
2123
|
generic: buildPlan7
|
|
1919
2124
|
};
|
|
1920
2125
|
var PI_INSTALL_PACKAGES = ["npm:@lunaroute/pi-extension"];
|
|
@@ -2881,7 +3086,7 @@ async function runSearchKeysSet(profile, opts) {
|
|
|
2881
3086
|
const ctx = { apiUrl: s.api_url, apiKey: s.routing_key };
|
|
2882
3087
|
try {
|
|
2883
3088
|
let provider = opts.provider;
|
|
2884
|
-
let
|
|
3089
|
+
let apiKey2 = opts.apiKey ?? process.env.LUNAROUTE_SEARCH_API_KEY;
|
|
2885
3090
|
const providers = await listSearchProviders(ctx);
|
|
2886
3091
|
const known = providers.map((p) => p.key);
|
|
2887
3092
|
if (!provider) {
|
|
@@ -2891,10 +3096,10 @@ async function runSearchKeysSet(profile, opts) {
|
|
|
2891
3096
|
console.error(`unknown provider "${provider}" \u2014 this server offers: ${known.join(", ")}`);
|
|
2892
3097
|
return 1;
|
|
2893
3098
|
}
|
|
2894
|
-
if (!
|
|
2895
|
-
|
|
3099
|
+
if (!apiKey2) {
|
|
3100
|
+
apiKey2 = await promptInput("API key", { hidden: true });
|
|
2896
3101
|
}
|
|
2897
|
-
const meta = await putSearchKey(ctx, provider,
|
|
3102
|
+
const meta = await putSearchKey(ctx, provider, apiKey2);
|
|
2898
3103
|
console.log(`Stored key for ${meta.provider} (updated ${meta.updated_at}).`);
|
|
2899
3104
|
return 0;
|
|
2900
3105
|
} catch (err) {
|
|
@@ -3164,9 +3369,13 @@ function buildRunSpec2(ctx) {
|
|
|
3164
3369
|
}
|
|
3165
3370
|
|
|
3166
3371
|
// src/run/adapters/zed.ts
|
|
3167
|
-
import {
|
|
3372
|
+
import { existsSync as existsSync6, readFileSync as readFileSync8, realpathSync as realpathSync2 } from "fs";
|
|
3168
3373
|
import { homedir as homedir3 } from "os";
|
|
3169
|
-
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";
|
|
3170
3379
|
function which(cmd, env, platform) {
|
|
3171
3380
|
const pathVar = env.PATH ?? env.Path ?? "";
|
|
3172
3381
|
const exts = platform === "win32" ? (env.PATHEXT ?? ".COM;.EXE;.BAT;.CMD").split(";").filter(Boolean) : [""];
|
|
@@ -3184,6 +3393,8 @@ function which(cmd, env, platform) {
|
|
|
3184
3393
|
}
|
|
3185
3394
|
return null;
|
|
3186
3395
|
}
|
|
3396
|
+
|
|
3397
|
+
// src/run/adapters/zed.ts
|
|
3187
3398
|
function firstExisting(paths) {
|
|
3188
3399
|
for (const path of paths) if (existsSync6(path)) return path;
|
|
3189
3400
|
return null;
|
|
@@ -3198,7 +3409,7 @@ function resolveZedCommand(deps = {}) {
|
|
|
3198
3409
|
try {
|
|
3199
3410
|
const real = realpathSync2(shim);
|
|
3200
3411
|
if (basename2(real) === "cli") {
|
|
3201
|
-
const app =
|
|
3412
|
+
const app = join6(dirname4(real), "zed");
|
|
3202
3413
|
if (existsSync6(app)) return app;
|
|
3203
3414
|
}
|
|
3204
3415
|
return real;
|
|
@@ -3208,20 +3419,20 @@ function resolveZedCommand(deps = {}) {
|
|
|
3208
3419
|
}
|
|
3209
3420
|
return firstExisting([
|
|
3210
3421
|
"/Applications/Zed.app/Contents/MacOS/zed",
|
|
3211
|
-
|
|
3422
|
+
join6(home, "Applications", "Zed.app", "Contents", "MacOS", "zed"),
|
|
3212
3423
|
"/Applications/Zed Preview.app/Contents/MacOS/zed",
|
|
3213
|
-
|
|
3424
|
+
join6(home, "Applications", "Zed Preview.app", "Contents", "MacOS", "zed"),
|
|
3214
3425
|
"/Applications/Zed Nightly.app/Contents/MacOS/zed"
|
|
3215
3426
|
]);
|
|
3216
3427
|
}
|
|
3217
3428
|
if (platform === "win32") {
|
|
3218
3429
|
const onPath = which("zed", env, platform);
|
|
3219
3430
|
if (onPath) return onPath;
|
|
3220
|
-
return env.LOCALAPPDATA ? firstExisting([
|
|
3431
|
+
return env.LOCALAPPDATA ? firstExisting([join6(env.LOCALAPPDATA, "Programs", "Zed", "zed.exe")]) : null;
|
|
3221
3432
|
}
|
|
3222
3433
|
return which("zed", env, platform) ?? which("zed-x11", env, platform) ?? firstExisting([
|
|
3223
|
-
|
|
3224
|
-
|
|
3434
|
+
join6(home, ".local", "bin", "zed"),
|
|
3435
|
+
join6(home, ".local", "zed.app", "bin", "zed")
|
|
3225
3436
|
]);
|
|
3226
3437
|
}
|
|
3227
3438
|
function hasLunarouteProvider(settingsPath) {
|
|
@@ -3246,19 +3457,65 @@ function buildRunSpec3(ctx, deps = {}) {
|
|
|
3246
3457
|
};
|
|
3247
3458
|
}
|
|
3248
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
|
+
|
|
3249
3504
|
// src/commands/run.ts
|
|
3250
3505
|
var ADAPTERS2 = {
|
|
3251
3506
|
claude: buildRunSpec,
|
|
3252
3507
|
"claude-code": buildRunSpec,
|
|
3253
3508
|
codex: buildRunSpec2,
|
|
3254
|
-
zed: buildRunSpec3
|
|
3509
|
+
zed: buildRunSpec3,
|
|
3510
|
+
agy: buildRunSpec4
|
|
3255
3511
|
};
|
|
3256
3512
|
var MODEL_LOOKUP_TIMEOUT_MS = 3e3;
|
|
3257
3513
|
var INSTALL_HINT = {
|
|
3258
3514
|
claude: "Install Claude Code: https://docs.anthropic.com/claude-code/install",
|
|
3259
3515
|
"claude-code": "Install Claude Code: https://docs.anthropic.com/claude-code/install",
|
|
3260
3516
|
codex: "Install Codex: https://github.com/openai/codex#install",
|
|
3261
|
-
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)"
|
|
3262
3519
|
};
|
|
3263
3520
|
var realDeps = {
|
|
3264
3521
|
spawn: makeRealSpawn(),
|
|
@@ -3355,10 +3612,15 @@ program.command("whoami").description("Show the signed-in user and organization.
|
|
|
3355
3612
|
program.command("key").description('Print the stored routing key, for shell use (e.g. "$(lunaroute key)").').action(() => {
|
|
3356
3613
|
key(program.opts().profile);
|
|
3357
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
|
+
});
|
|
3358
3620
|
program.command("logout").description("Remove stored credentials for the active profile.").action(() => {
|
|
3359
3621
|
logout(program.opts().profile);
|
|
3360
3622
|
});
|
|
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) => {
|
|
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) => {
|
|
3362
3624
|
const code = await runSetup(harness, {
|
|
3363
3625
|
profile: program.opts().profile,
|
|
3364
3626
|
print: opts.print,
|
|
@@ -3371,7 +3633,7 @@ program.command("setup <harness>").description("Configure a coding harness (open
|
|
|
3371
3633
|
});
|
|
3372
3634
|
if (code !== 0) process.exit(code);
|
|
3373
3635
|
});
|
|
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) => {
|
|
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) => {
|
|
3375
3637
|
const sep = process.argv.indexOf("--");
|
|
3376
3638
|
const post = sep !== -1 ? process.argv.slice(sep + 1) : [];
|
|
3377
3639
|
const before = post.length <= extra.length ? extra.slice(0, extra.length - post.length) : extra;
|
|
@@ -3439,7 +3701,7 @@ searchKeys.command("list").description("List configured search provider keys.").
|
|
|
3439
3701
|
const code = await runSearchKeysList(program.opts().profile, { json: opts.json });
|
|
3440
3702
|
if (code !== 0) process.exit(code);
|
|
3441
3703
|
});
|
|
3442
|
-
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) => {
|
|
3443
3705
|
const code = await runSearchKeysSet(program.opts().profile, { provider: opts.provider, apiKey: opts.apiKey });
|
|
3444
3706
|
if (code !== 0) process.exit(code);
|
|
3445
3707
|
});
|