@nexus-cortex/cli 4.27.0 → 4.28.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/bin/cortex.js +35 -1
  2. package/package.json +2 -2
package/bin/cortex.js CHANGED
@@ -25,7 +25,8 @@
25
25
  import { spawn, spawnSync } from 'child_process';
26
26
  import { fileURLToPath } from 'url';
27
27
  import { dirname, join, resolve } from 'path';
28
- import { existsSync, readFileSync, realpathSync } from 'fs';
28
+ import { existsSync, readFileSync, realpathSync, statSync, mkdirSync, writeFileSync } from 'fs';
29
+ import { homedir } from 'os';
29
30
  import { createRequire } from 'module';
30
31
 
31
32
  const __cortex_require = createRequire(import.meta.url);
@@ -61,6 +62,37 @@ if (!process.env.CORTEX_ROOT) {
61
62
  const BASE_PORT = process.env.PORT || '4000';
62
63
  const BASE_URL = process.env.CORTEX_URL || `http://localhost:${BASE_PORT}`;
63
64
 
65
+ // ── Background auto-update (opt-out) ──────────────────────────────
66
+ // On by default; set CORTEX_AUTO_UPDATE=false (or pass --no-auto-update) to disable.
67
+ // Fire-and-forget: spawns a DETACHED `npm i -g nexus-cortex@latest` that the current
68
+ // run does NOT wait on and that does NOT hot-swap the running process — the update
69
+ // lands on the NEXT launch. Throttled to once per 24h via a marker file. Skipped for
70
+ // dev/source checkouts (only updates an actual global npm install). Never blocks or
71
+ // throws into startup — any failure is swallowed.
72
+ function maybeAutoUpdate() {
73
+ try {
74
+ const optOut = String(process.env.CORTEX_AUTO_UPDATE).toLowerCase() === 'false'
75
+ || process.argv.includes('--no-auto-update');
76
+ if (optOut) return;
77
+ // Only auto-update a real installed package, never a git/source checkout.
78
+ if (!__cortex_dirname.includes('node_modules')) return;
79
+
80
+ const marker = join(homedir(), '.cortex', '.update-check');
81
+ const DAY_MS = 24 * 60 * 60 * 1000;
82
+ try {
83
+ if (Date.now() - statSync(marker).mtimeMs < DAY_MS) return; // throttled
84
+ } catch { /* no marker yet — proceed */ }
85
+ try { mkdirSync(dirname(marker), { recursive: true }); writeFileSync(marker, String(Date.now())); } catch {}
86
+
87
+ const child = spawn('npm', ['install', '-g', 'nexus-cortex@latest'], {
88
+ detached: true,
89
+ stdio: 'ignore',
90
+ });
91
+ child.unref();
92
+ } catch { /* never let auto-update affect the CLI */ }
93
+ }
94
+ maybeAutoUpdate();
95
+
64
96
  let serverProcess = null;
65
97
 
66
98
  // ── Argument parsing ──────────────────────────────────────────────
@@ -210,6 +242,8 @@ FLAGS:
210
242
  --timeout MS Request timeout in ms (default: 600000 = 10 min)
211
243
  --idle-timeout SECS Auto-shutdown server after N seconds of inactivity
212
244
  --cwd DIR (agent) Run in DIR — the agent's file tools operate there
245
+ --no-auto-update Skip the background update check for this run
246
+ (also: export CORTEX_AUTO_UPDATE=false to disable it entirely)
213
247
  --shutdown Stop the running server and exit
214
248
  --tmux List active tmux sessions with dashboard URLs
215
249
  --stats Show current session statistics
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nexus-cortex/cli",
3
- "version": "4.27.0",
3
+ "version": "4.28.0",
4
4
  "description": "Nexus Cortex CLI - Terminal interface for multi-provider LLM orchestration",
5
5
  "main": "dist/index.js",
6
6
  "type": "module",
@@ -19,7 +19,7 @@
19
19
  "prepack": "node ../../scripts/copy-pkg-cortex-scaffold.mjs"
20
20
  },
21
21
  "dependencies": {
22
- "@nexus-cortex/core": "^4.27.0",
22
+ "@nexus-cortex/core": "^4.28.0",
23
23
  "chalk": "^4.1.2",
24
24
  "cli-spinners": "^2.9.0",
25
25
  "commander": "^11.0.0",