@nexus-cortex/cli 4.37.0 → 4.37.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/bin/cortex.js +12 -2
  2. package/package.json +1 -1
package/bin/cortex.js CHANGED
@@ -409,8 +409,18 @@ XAI_API_KEY=
409
409
  // keyless server running that would force a --shutdown + re-invoke. When a key IS present
410
410
  // (a filled .env, or secrets in the environment), this is a no-op and the run proceeds —
411
411
  // one-shot. The container case (secrets in env) hits the no-op path and writes nothing.
412
- function ensureKeysOrExit() {
412
+ async function ensureKeysOrExit() {
413
413
  if (hasAnyApiKey()) return;
414
+ // No key resolvable. If a server is already running, it was started with no key and has
415
+ // cached that empty config — so even after you add a key it would keep failing until a
416
+ // restart. Drain it now (graceful) so the NEXT run (with your key) starts a fresh server
417
+ // that picks the key up — no manual --shutdown dance.
418
+ try {
419
+ if (await isServerUp()) {
420
+ try { await fetch(`${BASE_URL}/shutdown`, { method: 'POST', signal: AbortSignal.timeout(5000) }); } catch { /* best-effort */ }
421
+ process.stderr.write('[cortex] Stopped the running server so it will pick up your key on the next run.\n');
422
+ }
423
+ } catch { /* never block on the drain */ }
414
424
  const dir = getGlobalCortexDir();
415
425
  const envPath = join(dir, '.env');
416
426
  let seeded = false;
@@ -488,7 +498,7 @@ async function run() {
488
498
  // Read-only ops (--stats/--sessions/--tmux/--pr, no prompt) don't need a key and are
489
499
  // fine against a keyless server, so only gate the actual prompt path.
490
500
  if (prompt) {
491
- ensureKeysOrExit();
501
+ await ensureKeysOrExit();
492
502
  }
493
503
 
494
504
  await ensureServer();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nexus-cortex/cli",
3
- "version": "4.37.0",
3
+ "version": "4.37.1",
4
4
  "description": "Nexus Cortex CLI - Terminal interface for multi-provider LLM orchestration",
5
5
  "main": "dist/index.js",
6
6
  "type": "module",