@moonmath-ai/zro 0.2.5 → 0.4.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 (52) hide show
  1. package/README.md +116 -91
  2. package/dist/args.js +29 -4
  3. package/dist/args.js.map +1 -1
  4. package/dist/cli.js +0 -0
  5. package/dist/endpoints.d.ts +9 -0
  6. package/dist/endpoints.js +40 -0
  7. package/dist/endpoints.js.map +1 -0
  8. package/dist/engine/constants.d.ts +5 -202
  9. package/dist/engine/constants.js +5 -188
  10. package/dist/engine/constants.js.map +1 -1
  11. package/dist/engine/tools/claude.d.ts +1 -0
  12. package/dist/engine/tools/claude.js +44 -25
  13. package/dist/engine/tools/claude.js.map +1 -1
  14. package/dist/engine/tools/codex.d.ts +4 -1
  15. package/dist/engine/tools/codex.js +28 -8
  16. package/dist/engine/tools/codex.js.map +1 -1
  17. package/dist/engine/tools/grok.js +11 -9
  18. package/dist/engine/tools/grok.js.map +1 -1
  19. package/dist/engine/tools/hermes.js +34 -21
  20. package/dist/engine/tools/hermes.js.map +1 -1
  21. package/dist/engine/tools/kilo.d.ts +1 -1
  22. package/dist/engine/tools/kilo.js +15 -13
  23. package/dist/engine/tools/kilo.js.map +1 -1
  24. package/dist/engine/tools/omp.d.ts +2 -2
  25. package/dist/engine/tools/omp.js +12 -12
  26. package/dist/engine/tools/omp.js.map +1 -1
  27. package/dist/engine/tools/openclaw.js +27 -19
  28. package/dist/engine/tools/openclaw.js.map +1 -1
  29. package/dist/engine/tools/opencode.d.ts +5 -1
  30. package/dist/engine/tools/opencode.js +26 -15
  31. package/dist/engine/tools/opencode.js.map +1 -1
  32. package/dist/engine/tools/pi.js +17 -17
  33. package/dist/engine/tools/pi.js.map +1 -1
  34. package/dist/engine/tools/prime.js +17 -19
  35. package/dist/engine/tools/prime.js.map +1 -1
  36. package/dist/engine/types.d.ts +7 -1
  37. package/dist/install.d.ts +1 -1
  38. package/dist/install.js +29 -10
  39. package/dist/install.js.map +1 -1
  40. package/dist/model-catalog.d.ts +7 -2
  41. package/dist/model-catalog.js +113 -11
  42. package/dist/model-catalog.js.map +1 -1
  43. package/dist/process.d.ts +8 -0
  44. package/dist/process.js +51 -0
  45. package/dist/process.js.map +1 -0
  46. package/dist/run.js +277 -114
  47. package/dist/run.js.map +1 -1
  48. package/dist/types.d.ts +10 -0
  49. package/dist/ui.d.ts +3 -2
  50. package/dist/ui.js +24 -3
  51. package/dist/ui.js.map +1 -1
  52. package/package.json +2 -5
package/dist/run.js CHANGED
@@ -4,9 +4,9 @@ import fsSync from "node:fs";
4
4
  import fs from "node:fs/promises";
5
5
  import os from "node:os";
6
6
  import path from "node:path";
7
- import { ENDPOINT_ROOT, ZRO_ENV_KEY } from "./engine/constants.js";
7
+ import { NO_AUTH_PLACEHOLDER_KEY, ZRO_ENV_KEY } from "./engine/constants.js";
8
8
  import { credentialFilePath, deleteStoredApiKey, maskKey, promptHidden, readStoredApiKey, resolveApiKey, writeStoredApiKey } from "./engine/key.js";
9
- import { CLAUDE_MODEL_ALIAS_SLOTS, claudeTool } from "./engine/tools/claude.js";
9
+ import { CLAUDE_MODEL_ALIAS_SLOTS, claudeConfigDir, claudeTool } from "./engine/tools/claude.js";
10
10
  import { codexAppCredentialFilePath, codexAppTool, codexTool, } from "./engine/tools/codex.js";
11
11
  import { grokTool } from "./engine/tools/grok.js";
12
12
  import { hermesTool } from "./engine/tools/hermes.js";
@@ -17,11 +17,13 @@ import { opencodeTool } from "./engine/tools/opencode.js";
17
17
  import { piTool } from "./engine/tools/pi.js";
18
18
  import { primeTool } from "./engine/tools/prime.js";
19
19
  import { parseArgs } from "./args.js";
20
- import { describeTool, TOOLS } from "./catalog.js";
20
+ import { isNoAuth, resolveControlPlaneRoot, resolveInference, resolveMcpUrl } from "./endpoints.js";
21
+ import { describeTool } from "./catalog.js";
21
22
  import { commandExists, ensureHarnessInstalled, install } from "./install.js";
22
23
  import { readPreferences, writePreferences } from "./preferences.js";
23
24
  import { CatalogAuthenticationError, invalidateModelCatalog, loadModelCatalog, } from "./model-catalog.js";
24
- import { banner, chooseConnectMethod, chooseTool, helpText, isTty, modelName, promptLine, theme } from "./ui.js";
25
+ import { spawnCommand } from "./process.js";
26
+ import { banner, chooseConnectMethod, chooseInstall, chooseTool, helpText, isTty, modelName, promptLine, theme } from "./ui.js";
25
27
  const tools = {
26
28
  claude: claudeTool,
27
29
  codex: codexTool,
@@ -37,10 +39,6 @@ const tools = {
37
39
  };
38
40
  const PACKAGE_VERSION = JSON.parse(fsSync.readFileSync(new URL("../package.json", import.meta.url), "utf8")).version;
39
41
  export async function run(argv, io = defaultIo()) {
40
- if ((io.platform ?? process.platform) === "win32") {
41
- io.stderr.write("zro supports macOS and Linux. Use WSL on Windows.\n");
42
- return 1;
43
- }
44
42
  let request;
45
43
  try {
46
44
  request = parseArgs(argv);
@@ -68,9 +66,9 @@ export async function run(argv, io = defaultIo()) {
68
66
  if (request.command === "logout")
69
67
  return logout(request.output, io, env);
70
68
  if (request.command === "status")
71
- return status(request.output, io, env, colors);
69
+ return status(request, io, env, colors);
72
70
  if (request.command === "models")
73
- return models(request.output, io, env, colors);
71
+ return models(request, io, env, colors);
74
72
  if (request.command === "feedback")
75
73
  return feedback(request, io, env, colors);
76
74
  if (request.command === "home") {
@@ -108,50 +106,53 @@ export async function run(argv, io = defaultIo()) {
108
106
  dryRun: request.dryRun,
109
107
  output: request.output,
110
108
  extraArgs: [],
111
- aliases: request.aliases
109
+ aliases: request.aliases,
110
+ inferenceUrl: request.inferenceUrl,
111
+ noAuth: request.noAuth,
112
112
  };
113
113
  }
114
- if (request.install && !request.dryRun) {
115
- const ready = await ensureHarnessInstalled(request.tool, io, env);
116
- if (!ready)
117
- return 1;
118
- }
119
114
  return launch(request, io, env, colors);
120
115
  }
121
116
  async function launch(request, io, env, colors) {
122
- let key;
117
+ const noAuth = isNoAuth(request.noAuth, env);
118
+ let inference;
119
+ let mcpUrl;
123
120
  try {
124
- key = await resolveApiKey({ flagValue: request.apiKey, env, homeDir: io.homeDir });
121
+ inference = resolveInference(env, request.inferenceUrl, noAuth);
122
+ mcpUrl = resolveMcpUrl(env);
125
123
  }
126
124
  catch (error) {
127
- if (!isTty(io.stdin) || !isTty(io.stdout)) {
128
- io.stderr.write("Not logged in. Run zro login or set ZRO_API_KEY.\n");
129
- return 1;
130
- }
131
- io.stdout.write(`${colors.strong("Connect once to keep going.")}\n\n`);
132
- const loggedIn = await loginWithWebsite({
133
- command: "login",
134
- method: "browser",
135
- openBrowser: true,
136
- output: "human",
137
- }, io, env, colors);
138
- if (loggedIn !== 0)
139
- return loggedIn;
125
+ io.stderr.write(`${messageOf(error)}\n`);
126
+ return 1;
127
+ }
128
+ let key;
129
+ if (noAuth) {
130
+ key = { apiKey: NO_AUTH_PLACEHOLDER_KEY, source: "none" };
131
+ }
132
+ else {
140
133
  try {
141
- key = await resolveApiKey({ env, homeDir: io.homeDir });
134
+ key = await resolveApiKey({ flagValue: request.apiKey, env, homeDir: io.homeDir });
142
135
  }
143
- catch (resolutionError) {
144
- io.stderr.write(`${messageOf(resolutionError)}\n`);
145
- return 1;
136
+ catch {
137
+ if (!isTty(io.stdin) || !isTty(io.stdout)) {
138
+ io.stderr.write("Not logged in. Run zro login or set ZRO_API_KEY.\n");
139
+ return 1;
140
+ }
141
+ const connected = await connectInteractively(io, env, colors);
142
+ if (typeof connected === "number")
143
+ return connected;
144
+ key = connected;
146
145
  }
147
146
  }
148
- if (request.apiKey) {
147
+ if (request.apiKey && !noAuth) {
149
148
  io.stderr.write(`Note: --api-key can land in shell history. Prefer zro login or ${ZRO_ENV_KEY}.\n`);
150
149
  }
151
150
  let catalog;
152
151
  try {
153
152
  catalog = await loadModelCatalog({
154
153
  apiKey: key.apiKey,
154
+ noAuth,
155
+ inferenceRoot: inference.root,
155
156
  env,
156
157
  homeDir: io.homeDir,
157
158
  fetch: io.fetch,
@@ -163,7 +164,7 @@ async function launch(request, io, env, colors) {
163
164
  io.stderr.write(`Authentication failed: ${error.message} Run zro login --manual with a valid API key. Agent was not started.\n`);
164
165
  return 1;
165
166
  }
166
- io.stderr.write(`Could not load the Zro model catalog: ${messageOf(error)}\n`);
167
+ io.stderr.write(`${messageOf(error)} Agent was not started.\n`);
167
168
  return 1;
168
169
  }
169
170
  const model = request.model ?? catalog.default;
@@ -171,6 +172,27 @@ async function launch(request, io, env, colors) {
171
172
  io.stderr.write(unknownModelMessage(model, catalog.source));
172
173
  return 1;
173
174
  }
175
+ const tool = describeTool(request.tool);
176
+ if (!request.dryRun &&
177
+ !await commandExists(tool.executable, env) &&
178
+ (request.install || (isTty(io.stdin) && isTty(io.stdout)))) {
179
+ if (!request.install) {
180
+ let choice;
181
+ try {
182
+ choice = await chooseInstall(tool.name, io.stdin, io.stdout, colors);
183
+ }
184
+ catch (error) {
185
+ if (messageOf(error) !== "Cancelled.")
186
+ io.stderr.write(`${messageOf(error)}\n`);
187
+ return messageOf(error) === "Cancelled." ? 0 : 1;
188
+ }
189
+ if (choice === "cancel")
190
+ return 0;
191
+ }
192
+ const ready = await ensureHarnessInstalled(request.tool, io, env);
193
+ if (!ready)
194
+ return 1;
195
+ }
174
196
  let modelAliases;
175
197
  for (const [slot, modelId] of Object.entries(request.aliases ?? {})) {
176
198
  if (request.tool !== "claude") {
@@ -196,6 +218,10 @@ async function launch(request, io, env, colors) {
196
218
  plan = await tools[request.tool].launch({
197
219
  apiKey: key.apiKey,
198
220
  apiKeySource: key.source,
221
+ inferenceRoot: inference.root,
222
+ inferenceBaseUrl: inference.baseUrl,
223
+ mcpUrl,
224
+ noAuth,
199
225
  env,
200
226
  model,
201
227
  models: catalog.models,
@@ -204,6 +230,7 @@ async function launch(request, io, env, colors) {
204
230
  homeDir: io.homeDir,
205
231
  cwd: io.cwd,
206
232
  tempDir,
233
+ platform: io.platform ?? process.platform,
207
234
  stdin: io.stdin,
208
235
  stdout: io.stdout,
209
236
  stderr: io.stderr
@@ -215,11 +242,11 @@ async function launch(request, io, env, colors) {
215
242
  return 1;
216
243
  }
217
244
  if (request.dryRun) {
218
- printPreview(plan, request.output, io, key.apiKey, colors);
245
+ printPreview(plan, request.output, io, key.apiKey, colors, catalog.models);
219
246
  await fs.rm(tempDir, { recursive: true, force: true });
220
247
  return 0;
221
248
  }
222
- if (!await verifyApiKey(key.apiKey, io, env)) {
249
+ if (!noAuth && !await verifyApiKey(key.apiKey, io, env, inference.root)) {
223
250
  await fs.rm(tempDir, { recursive: true, force: true });
224
251
  return 1;
225
252
  }
@@ -245,13 +272,29 @@ async function launch(request, io, env, colors) {
245
272
  return 1;
246
273
  }
247
274
  finally {
248
- await fs.rm(tempDir, { recursive: true, force: true });
275
+ await removeSessionDir(tempDir, io);
276
+ }
277
+ }
278
+ // Windows keeps files locked briefly after a child exits (antivirus, plugin clones), so a
279
+ // single rm can fail with EBUSY/EPERM even though the session is over. Retry, then warn rather
280
+ // than crash after the session.
281
+ async function removeSessionDir(tempDir, io) {
282
+ for (const delayMs of [0, 250, 1000, 3000]) {
283
+ if (delayMs > 0)
284
+ await new Promise((resolve) => setTimeout(resolve, delayMs));
285
+ try {
286
+ await fs.rm(tempDir, { recursive: true, force: true });
287
+ return;
288
+ }
289
+ catch {
290
+ // Retry.
291
+ }
249
292
  }
293
+ io.stderr.write(`Could not remove ${tempDir}; it may hold session files, so delete it manually.\n`);
250
294
  }
251
- async function verifyApiKey(apiKey, io, env) {
295
+ async function verifyApiKey(apiKey, io, env, inferenceRoot) {
252
296
  const fetcher = io.fetch ?? globalThis.fetch;
253
- const endpointRoot = (env.ZRO_ENDPOINT_ROOT || ENDPOINT_ROOT).replace(/\/+$/, "");
254
- const validationUrl = `${endpointRoot}/v1/models`;
297
+ const validationUrl = `${inferenceRoot}/v1/models`;
255
298
  let response;
256
299
  try {
257
300
  response = await fetcher(validationUrl, {
@@ -260,7 +303,7 @@ async function verifyApiKey(apiKey, io, env) {
260
303
  });
261
304
  }
262
305
  catch (error) {
263
- io.stderr.write(`Could not verify Zro authentication at ${endpointRoot}: ${messageOf(error)}. Agent was not started.\n`);
306
+ io.stderr.write(`Could not verify Zro authentication at ${inferenceRoot}: ${messageOf(error)}. Agent was not started.\n`);
264
307
  return false;
265
308
  }
266
309
  const status = response.status;
@@ -282,12 +325,31 @@ async function verifyApiKey(apiKey, io, env) {
282
325
  "Agent was not started.\n");
283
326
  return false;
284
327
  }
285
- async function login(request, io, env, colors) {
328
+ async function connectInteractively(io, env, colors) {
329
+ io.stdout.write(`${colors.strong("Connect once to keep going.")}\n\n`);
330
+ const loggedIn = await login({
331
+ command: "login",
332
+ method: "choose",
333
+ openBrowser: true,
334
+ output: "human",
335
+ }, io, env, colors, false);
336
+ if (loggedIn !== 0)
337
+ return loggedIn;
338
+ try {
339
+ return await resolveApiKey({ env, homeDir: io.homeDir });
340
+ }
341
+ catch (error) {
342
+ io.stderr.write(`${messageOf(error)}\n`);
343
+ return 1;
344
+ }
345
+ }
346
+ async function login(request, io, env, colors, showBanner = true) {
286
347
  let method = request.method;
287
- let showWebsiteBanner = true;
348
+ let showWebsiteBanner = showBanner;
288
349
  if (method === "choose") {
289
350
  if (request.output === "human" && isTty(io.stdin) && isTty(io.stdout)) {
290
- io.stdout.write(`${banner(colors)}\n\n`);
351
+ if (showBanner)
352
+ io.stdout.write(`${banner(colors)}\n\n`);
291
353
  try {
292
354
  method = await chooseConnectMethod(io.stdin, io.stdout, colors);
293
355
  }
@@ -440,6 +502,8 @@ async function logout(output, io, env) {
440
502
  deleteStoredApiKey({ homeDir: io.homeDir, env }),
441
503
  deleteOptionalFile(codexAppCredentialFilePath(io.homeDir)),
442
504
  invalidateModelCatalog({ homeDir: io.homeDir, env }),
505
+ fs.rm(claudeConfigDir(io.homeDir, env), { recursive: true, force: true })
506
+ .catch(() => undefined),
443
507
  ]);
444
508
  const removed = storedKeyRemoved || codexAppKeyRemoved;
445
509
  io.stdout.write(output === "json"
@@ -461,22 +525,47 @@ async function deleteOptionalFile(filePath) {
461
525
  throw error;
462
526
  }
463
527
  }
464
- async function status(output, io, env, colors) {
528
+ async function status(request, io, env, colors) {
529
+ const output = request.output;
530
+ const preferences = await readPreferences({ homeDir: io.homeDir, env });
531
+ if (isNoAuth(request.noAuth, env)) {
532
+ let inferenceRoot;
533
+ try {
534
+ inferenceRoot = resolveInference(env, request.inferenceUrl).root;
535
+ }
536
+ catch {
537
+ inferenceRoot = undefined;
538
+ }
539
+ if (output === "json") {
540
+ io.stdout.write(`${JSON.stringify({
541
+ connected: false,
542
+ mode: "no-auth",
543
+ noAuth: true,
544
+ credentialSource: "none",
545
+ inferenceUrl: inferenceRoot ?? null,
546
+ lastSession: preferences.lastTool && preferences.lastModel
547
+ ? { tool: preferences.lastTool, model: preferences.lastModel }
548
+ : null,
549
+ }, null, 2)}\n`);
550
+ return 0;
551
+ }
552
+ io.stdout.write(`${banner(colors)}\n`);
553
+ io.stdout.write(`\n${colors.muted("CONNECTION")}\n`);
554
+ io.stdout.write(` ${colors.good("◆")} ${colors.strong("No-auth gateway mode")}\n`);
555
+ if (inferenceRoot) {
556
+ io.stdout.write(` ${colors.muted(inferenceRoot)}\n`);
557
+ }
558
+ io.stdout.write(`\n${colors.muted("LAST SESSION")}\n`);
559
+ printLastSession(preferences, io, colors);
560
+ return 0;
561
+ }
465
562
  const stored = await readStoredApiKey({ homeDir: io.homeDir, env });
466
563
  const envKey = env[ZRO_ENV_KEY];
467
564
  const source = envKey ? "environment" : stored ? "stored" : "none";
468
565
  const credential = envKey ?? stored;
469
- const preferences = await readPreferences({ homeDir: io.homeDir, env });
470
- const [installed, accountResult] = await Promise.all([
471
- Promise.all(TOOLS.map(async (tool) => ({
472
- id: tool.id,
473
- name: tool.name,
474
- installed: await commandExists(tool.executable, env)
475
- }))),
476
- credential
477
- ? fetchAccountStatus(credential, io, env)
478
- : Promise.resolve({ state: "not_connected" }),
479
- ]);
566
+ const accountResult = credential
567
+ ? await fetchAccountStatus(credential, io, env)
568
+ : { state: "not_connected" };
480
569
  const connected = source !== "none" && accountResult.state !== "rejected";
481
570
  if (accountResult.state === "rejected") {
482
571
  await invalidateModelCatalog({ homeDir: io.homeDir, env }).catch(() => { });
@@ -491,34 +580,42 @@ async function status(output, io, env, colors) {
491
580
  lastSession: preferences.lastTool && preferences.lastModel
492
581
  ? { tool: preferences.lastTool, model: preferences.lastModel }
493
582
  : null,
494
- tools: installed
495
583
  }, null, 2)}\n`);
496
584
  return 0;
497
585
  }
498
- io.stdout.write(`${banner(colors)}\n\n`);
499
- io.stdout.write(`${!connected ? colors.muted("◇") : colors.good("◆")} Connection `);
500
- io.stdout.write(source === "none"
501
- ? `${colors.muted("not logged in")}\n Run zro login\n`
502
- : accountResult.state === "rejected"
503
- ? `${colors.muted("API key rejected")}\n Run zro login --manual\n`
504
- : `${colors.strong(source)} ${colors.muted(`· ${maskKey(credential)}`)}\n`);
586
+ io.stdout.write(`${banner(colors)}\n`);
587
+ io.stdout.write(`\n${colors.muted("CONNECTION")}\n`);
588
+ if (source === "none") {
589
+ io.stdout.write(` ${colors.muted("◇")} Not logged in\n`);
590
+ io.stdout.write(` ${colors.muted("Run")} zro login ${colors.muted("to connect")}\n`);
591
+ }
592
+ else if (accountResult.state === "rejected") {
593
+ io.stdout.write(` ${colors.muted("◇")} API key rejected\n`);
594
+ io.stdout.write(` ${colors.muted("Run")} zro login --manual ${colors.muted("with a valid key")}\n`);
595
+ }
596
+ else {
597
+ io.stdout.write(` ${colors.good("◆")} ${colors.strong(source)} ${colors.muted(maskKey(credential))}\n`);
598
+ }
505
599
  if (accountResult.state === "available") {
506
600
  printAccountStatus(accountResult.account, io, colors);
507
601
  }
508
602
  else if (accountResult.state === "unavailable") {
509
- io.stdout.write(`${colors.muted("◇")} Account ${colors.muted("details unavailable")}\n`);
603
+ io.stdout.write(`\n${colors.muted("ACCOUNT")}\n`);
604
+ io.stdout.write(` ${colors.muted("◇")} Details unavailable\n`);
510
605
  }
606
+ io.stdout.write(`\n${colors.muted("LAST SESSION")}\n`);
607
+ printLastSession(preferences, io, colors);
608
+ return 0;
609
+ }
610
+ function printLastSession(preferences, io, colors) {
511
611
  if (preferences.lastTool && preferences.lastModel) {
512
- io.stdout.write(`${colors.accent("◆")} Last session ${describeTool(preferences.lastTool).name} ${colors.muted(`· ${preferences.lastModel}`)}\n`);
612
+ io.stdout.write(` ${colors.accent("◆")} ${colors.strong(describeTool(preferences.lastTool).name)} ` +
613
+ `${colors.muted(preferences.lastModel)}\n`);
614
+ io.stdout.write(` ${colors.muted("Reopen with")} zro again\n`);
513
615
  }
514
616
  else {
515
- io.stdout.write(`${colors.muted("◇")} Last session ${colors.muted("none yet")}\n`);
617
+ io.stdout.write(` ${colors.muted("◇")} None yet — start with ${colors.muted("zro claude")}\n`);
516
618
  }
517
- io.stdout.write("\nTools\n");
518
- for (const tool of installed) {
519
- io.stdout.write(` ${tool.installed ? colors.good("◆") : colors.muted("◇")} ${pad(tool.name, 13)} ${tool.installed ? "ready" : colors.muted("not installed")}\n`);
520
- }
521
- return 0;
522
619
  }
523
620
  async function fetchAccountStatus(apiKey, io, env) {
524
621
  const fetcher = io.fetch ?? globalThis.fetch;
@@ -544,7 +641,7 @@ async function fetchAccountStatus(apiKey, io, env) {
544
641
  }
545
642
  }
546
643
  function getAuthRoot(env) {
547
- return (env.ZRO_AUTH_URL || env.ZRO_ENDPOINT_ROOT || ENDPOINT_ROOT).replace(/\/+$/, "");
644
+ return resolveControlPlaneRoot(env);
548
645
  }
549
646
  function browserApprovalUrl(serverUrl, env) {
550
647
  const publicRoot = env.ZRO_PUBLIC_URL || env.ZRO_AUTH_URL;
@@ -579,19 +676,24 @@ function hasNumbers(value, keys) {
579
676
  }
580
677
  function printAccountStatus(account, io, colors) {
581
678
  const plan = account.billing.plan;
582
- io.stdout.write("\nAccount\n");
583
- io.stdout.write(` ${colors.good("◆")} Plan ${plan ? colors.strong(plan.name) : colors.muted("none")} ` +
584
- `${colors.muted(`· ${account.billing.status}`)}\n`);
585
- if (plan) {
586
- io.stdout.write(` ${colors.good("◆")} Plan usage ${money(plan.used, account.billing.currency)} of ` +
587
- `${money(plan.allowance, account.billing.currency)} · ${money(plan.remaining, account.billing.currency)} left\n`);
588
- }
679
+ const currency = account.billing.currency;
589
680
  const packs = account.billing.usagePacks;
590
- io.stdout.write(` ${packs.remaining > 0 ? colors.good("◆") : colors.muted("◇")} Usage packs ` +
591
- `${money(packs.remaining, account.billing.currency)} left · ${money(packs.total, account.billing.currency)} total\n`);
592
- io.stdout.write(` ${colors.good("◆")} Available ${money(account.billing.totalRemaining, account.billing.currency)} total\n`);
593
- io.stdout.write(` ${colors.muted("◇")} Last 30 days ${formatInteger(account.activity30d.requests)} requests · ` +
594
- `${formatInteger(account.activity30d.totalTokens)} tokens\n`);
681
+ const activity = account.activity30d;
682
+ io.stdout.write(`\n${colors.muted("ACCOUNT")}\n`);
683
+ io.stdout.write(` ${plan ? colors.good("◆") : colors.muted("◇")} Plan ` +
684
+ `${plan ? colors.strong(plan.name) : colors.muted("none")} ` +
685
+ `${colors.muted(account.billing.status)}\n`);
686
+ if (plan) {
687
+ const ratio = plan.allowance > 0 ? Math.min(Math.max(plan.used / plan.allowance, 0), 1) : 0;
688
+ const width = 24;
689
+ const filled = Math.round(ratio * width);
690
+ const bar = colors.good("█".repeat(filled)) + colors.muted("░".repeat(width - filled));
691
+ io.stdout.write(` ${bar} ${colors.strong(`${Math.round(ratio * 100)}%`)} ${colors.muted("used")}\n`);
692
+ }
693
+ io.stdout.write(` ${packs.remaining > 0 ? colors.good("◆") : colors.muted("◇")} Top-up credits ` +
694
+ `${colors.strong(money(packs.remaining, currency))} ${colors.muted(`left · ${money(packs.total, currency)} total`)}\n`);
695
+ io.stdout.write(` ${colors.muted("◇")} Activity ${formatInteger(activity.requests)} ${colors.muted("requests ·")} ` +
696
+ `${formatTokens(activity.totalTokens)} ${colors.muted("tokens")} ${colors.muted("(30d)")}\n`);
595
697
  }
596
698
  function money(value, currency) {
597
699
  return new Intl.NumberFormat("en-US", {
@@ -604,25 +706,69 @@ function money(value, currency) {
604
706
  function formatInteger(value) {
605
707
  return new Intl.NumberFormat("en-US", { maximumFractionDigits: 0 }).format(value);
606
708
  }
607
- async function models(output, io, env, colors) {
608
- let apiKey;
609
- try {
610
- apiKey = (await resolveApiKey({ env, homeDir: io.homeDir })).apiKey;
709
+ async function models(request, io, env, colors) {
710
+ const output = request.output;
711
+ const noAuth = isNoAuth(request.noAuth, env);
712
+ let inferenceRoot;
713
+ if (noAuth) {
714
+ try {
715
+ inferenceRoot = resolveInference(env, request.inferenceUrl, true).root;
716
+ }
717
+ catch (error) {
718
+ io.stderr.write(`${messageOf(error)}\n`);
719
+ return 1;
720
+ }
611
721
  }
612
- catch {
613
- // A cached or bundled catalog remains useful before the user signs in.
722
+ let apiKey;
723
+ if (!noAuth) {
724
+ try {
725
+ apiKey = (await resolveApiKey({ env, homeDir: io.homeDir })).apiKey;
726
+ }
727
+ catch {
728
+ // A cached catalog remains useful before the user signs in.
729
+ }
614
730
  }
615
731
  let catalog;
616
732
  try {
617
- catalog = await loadModelCatalog({ apiKey, env, homeDir: io.homeDir, fetch: io.fetch });
733
+ catalog = await loadModelCatalog({
734
+ apiKey,
735
+ noAuth,
736
+ inferenceRoot,
737
+ env,
738
+ homeDir: io.homeDir,
739
+ fetch: io.fetch,
740
+ });
618
741
  }
619
742
  catch (error) {
620
743
  if (error instanceof CatalogAuthenticationError) {
621
744
  io.stderr.write(`Authentication failed: ${error.message} Run zro login --manual with a valid API key.\n`);
622
745
  return 1;
623
746
  }
624
- io.stderr.write(`Could not load the Zro model catalog: ${messageOf(error)}\n`);
625
- return 1;
747
+ if (noAuth) {
748
+ io.stderr.write(`Could not load the public model catalog: ${messageOf(error)}\n`);
749
+ return 1;
750
+ }
751
+ if (output === "human" && isTty(io.stdin) && isTty(io.stdout)) {
752
+ const connected = await connectInteractively(io, env, colors);
753
+ if (typeof connected === "number")
754
+ return connected;
755
+ try {
756
+ catalog = await loadModelCatalog({
757
+ apiKey: connected.apiKey,
758
+ env,
759
+ homeDir: io.homeDir,
760
+ fetch: io.fetch,
761
+ });
762
+ }
763
+ catch (retryError) {
764
+ io.stderr.write(`Could not load the Zro model catalog: ${messageOf(retryError)}\n`);
765
+ return 1;
766
+ }
767
+ }
768
+ else {
769
+ io.stderr.write(`Could not load the Zro model catalog: ${messageOf(error)}\n`);
770
+ return 1;
771
+ }
626
772
  }
627
773
  if (output === "json") {
628
774
  io.stdout.write(`${JSON.stringify(catalog, null, 2)}\n`);
@@ -634,10 +780,14 @@ async function models(output, io, env, colors) {
634
780
  io.stdout.write(`\n ${isDefault ? colors.accent("◆") : colors.muted("◇")} ${colors.strong(model.displayName)} ${colors.muted(model.id)}${isDefault ? colors.accent(" default") : ""}\n`);
635
781
  io.stdout.write(` ${formatTokens(model.contextWindow)} context · ${formatTokens(model.maxOutputTokens)} max output · ${model.reasoning.levels.map((level) => level.id).join(" / ")}\n`);
636
782
  }
637
- io.stdout.write("\nChoose per session with -m, for example: zro codex -m glm-5.3\n");
783
+ io.stdout.write(`\nChoose per session with -m, for example: zro codex -m ${catalog.default}\n`);
638
784
  return 0;
639
785
  }
640
786
  async function feedback(request, io, env, colors) {
787
+ if (isNoAuth(request.noAuth, env)) {
788
+ io.stderr.write("Feedback needs a Zro account and is unavailable in no-auth mode.\n");
789
+ return 1;
790
+ }
641
791
  let message = request.message;
642
792
  if (!message) {
643
793
  if (isTty(io.stdin) && isTty(io.stdout)) {
@@ -702,7 +852,7 @@ async function feedback(request, io, env, colors) {
702
852
  : `${colors.good("Thanks!")} Your feedback is on its way.\n`);
703
853
  return 0;
704
854
  }
705
- function printPreview(plan, output, io, secret, colors) {
855
+ function printPreview(plan, output, io, secret, colors, models) {
706
856
  const safeEnv = Object.fromEntries(Object.entries(plan.env ?? {}).map(([key, value]) => [key, redact(key, value, secret)]));
707
857
  const result = {
708
858
  tool: plan.tool,
@@ -718,7 +868,7 @@ function printPreview(plan, output, io, secret, colors) {
718
868
  }
719
869
  io.stdout.write(`${banner(colors)}\n\n${colors.strong("Session preview")}\n`);
720
870
  io.stdout.write(` Tool ${describeTool(plan.tool).name}\n`);
721
- io.stdout.write(` Model ${modelName(plan.model)} ${colors.muted(`· ${plan.model}`)}\n`);
871
+ io.stdout.write(` Model ${modelName(plan.model, models)} ${colors.muted(`· ${plan.model}`)}\n`);
722
872
  io.stdout.write(` Command ${shellPreview([plan.command, ...plan.args])}\n`);
723
873
  const entries = Object.entries(safeEnv);
724
874
  if (entries.length) {
@@ -741,7 +891,7 @@ async function writeLaunchFiles(plan) {
741
891
  }
742
892
  async function spawnPlan(plan, io, env) {
743
893
  const spawn = io.spawn ?? nodeSpawn;
744
- const child = spawn(plan.command, plan.args, {
894
+ const child = spawnCommand(spawn, io.platform ?? process.platform, plan.command, plan.args, {
745
895
  cwd: io.cwd,
746
896
  env: { ...env, ...(plan.env ?? {}) },
747
897
  stdio: "inherit"
@@ -762,13 +912,10 @@ export function unknownModelMessage(model, source) {
762
912
  if (source === "remote") {
763
913
  return `Unknown model "${model}". It is not offered by your account's catalog. Run zro models.\n`;
764
914
  }
765
- if (source === "cache") {
766
- return `Unknown model "${model}". It is not in the cached catalog from your last login. Run zro login to refresh your account's catalog.\n`;
767
- }
768
- return `Unknown model "${model}". It is not in the offline catalog bundled with zro. Run zro login to fetch your account's catalog.\n`;
915
+ return `Unknown model "${model}". It is not in the cached catalog from your last login. Run zro login to refresh your account's catalog.\n`;
769
916
  }
770
917
  export function redact(key, value, secret) {
771
- if (value === "")
918
+ if (value === "" || value === NO_AUTH_PLACEHOLDER_KEY)
772
919
  return value;
773
920
  const nameTokens = key.split(/[^A-Za-z0-9]+/).map((token) => token.toUpperCase());
774
921
  if (nameTokens.some((token) => SECRET_NAME_TOKENS.has(token)) || value.includes(secret)) {
@@ -802,22 +949,38 @@ function compactPath(cwd, homeDir) {
802
949
  return cwd === homeDir ? "~" : cwd.startsWith(`${homeDir}${path.sep}`) ? `~${cwd.slice(homeDir.length)}` : cwd;
803
950
  }
804
951
  function formatTokens(value) {
805
- if (value >= 1_000_000)
806
- return `${(value / 1_000_000).toFixed(1).replace(".0", "")}M`;
807
- return `${Math.round(value / 1_000)}K`;
808
- }
809
- function pad(value, width) {
810
- return value + " ".repeat(Math.max(1, width - value.length));
952
+ const units = [
953
+ [1_000_000_000, "B"],
954
+ [1_000_000, "M"],
955
+ [1_000, "K"],
956
+ ];
957
+ for (const [threshold, suffix] of units) {
958
+ if (value >= threshold) {
959
+ const scaled = value / threshold;
960
+ return `${scaled >= 10 ? Math.round(scaled) : scaled.toFixed(1)}${suffix}`;
961
+ }
962
+ }
963
+ return String(value);
811
964
  }
812
965
  function messageOf(error) {
813
966
  return error instanceof Error ? error.message : String(error);
814
967
  }
815
968
  async function openBrowserWithSystem(url, platform) {
816
- const command = platform === "darwin" ? "open" : platform === "linux" ? "xdg-open" : null;
969
+ // explorer.exe is a single-instance shell: a spawned process just forwards its argument to the
970
+ // running shell, which often opens a File Explorer window instead of the URL. rundll32 goes
971
+ // straight through the URL protocol handler, so the default browser always opens.
972
+ const command = platform === "darwin"
973
+ ? "open"
974
+ : platform === "linux"
975
+ ? "xdg-open"
976
+ : platform === "win32"
977
+ ? "rundll32"
978
+ : null;
817
979
  if (!command)
818
980
  return false;
981
+ const args = platform === "win32" ? ["url.dll,FileProtocolHandler", url] : [url];
819
982
  return new Promise((resolve) => {
820
- const child = nodeSpawn(command, [url], { detached: true, stdio: "ignore" });
983
+ const child = nodeSpawn(command, args, { detached: true, stdio: "ignore" });
821
984
  let settled = false;
822
985
  child.once("error", () => {
823
986
  if (settled)