labs-claude 0.4.1 → 0.4.2

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/package.json +1 -1
  2. package/src/ui.js +32 -5
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "labs-claude",
3
- "version": "0.4.1",
3
+ "version": "0.4.2",
4
4
  "description": "Run the real Claude Code CLI on Qwen4 1M (Vision + Web), Gemini 4, Bedrock, or ElevenLabs — with colorful setup and admin token tracking.",
5
5
  "bin": {
6
6
  "labs": "bin/labs.js"
package/src/ui.js CHANGED
@@ -3,7 +3,7 @@
3
3
  const fs = require('fs');
4
4
  const path = require('path');
5
5
  const readline = require('readline');
6
- const { spawnSync } = require('child_process');
6
+ const { spawn, spawnSync } = require('child_process');
7
7
 
8
8
  const USE_COLOR = Boolean(process.stdout.isTTY && !process.env.NO_COLOR);
9
9
  const ansi = (code, s) => (USE_COLOR ? `\x1b[${code}m${s}\x1b[0m` : String(s));
@@ -292,7 +292,25 @@ function isNewerVersion(latest, current) {
292
292
  return false;
293
293
  }
294
294
 
295
- // Non-blocking 24h cached npm version check so friends always know when a newer labs-claude is out.
295
+ // Non-blocking auto-updater: checks npm in the background and silently installs newer versions
296
+ // in a detached process (once per version) so the next `labs` window is automatically up to date.
297
+ function spawnBackgroundUpdate(latest, cacheFile, cached) {
298
+ if (process.env.LABS_NO_AUTO_UPDATE === '1') return;
299
+ if (cached && cached.autoUpdatedTo === latest) return;
300
+ try {
301
+ fs.mkdirSync(path.dirname(cacheFile), { recursive: true });
302
+ fs.writeFileSync(cacheFile, JSON.stringify({ ...cached, latest, checkedAt: Date.now(), autoUpdatedTo: latest }));
303
+ const cmd = process.platform === 'win32' ? 'npm.cmd' : 'npm';
304
+ const child = spawn(cmd, ['install', '-g', `labs-claude@${latest}`, '--prefer-online', '--no-audit', '--no-fund'], {
305
+ stdio: 'ignore',
306
+ detached: true,
307
+ shell: process.platform === 'win32',
308
+ windowsHide: true,
309
+ });
310
+ child.unref();
311
+ } catch { /* silent fallback to manual labs update */ }
312
+ }
313
+
296
314
  function checkUpdateNotice(currentVersion, labsDir) {
297
315
  const cacheFile = path.join(labsDir, 'update-check.json');
298
316
  let cached = null;
@@ -301,17 +319,26 @@ function checkUpdateNotice(currentVersion, labsDir) {
301
319
  } catch { /* ignore corrupt cache */ }
302
320
 
303
321
  if (cached && cached.latest && isNewerVersion(cached.latest, currentVersion)) {
304
- console.log(` ${c.amber('⬆')} ${c.bold('Update available:')} ${c.dim(currentVersion)} → ${c.mint(cached.latest)} ${c.dim('Run:')} ${c.cyan('labs update')}`);
322
+ if (cached.autoUpdatedTo !== cached.latest) {
323
+ spawnBackgroundUpdate(cached.latest, cacheFile, cached);
324
+ console.log(` ${c.mint('⬆')} ${c.dim(`auto-updating labs`)} ${c.dim(currentVersion)} → ${c.cyan(cached.latest)} ${c.dim('in background (ready next window) ✨')}`);
325
+ } else {
326
+ console.log(` ${c.amber('⬆')} ${c.bold('update available:')} ${c.dim(currentVersion)} → ${c.mint(cached.latest)} ${c.dim('run:')} ${c.cyan('labs update')}`);
327
+ }
305
328
  }
306
329
 
307
- const stale = !cached || (Date.now() - (cached.checkedAt || 0)) > 6 * 3600e3;
330
+ const stale = !cached || (Date.now() - (cached.checkedAt || 0)) > 2 * 3600e3;
308
331
  if (stale && typeof fetch === 'function') {
309
332
  fetch('https://registry.npmjs.org/labs-claude/latest', { signal: AbortSignal.timeout(2500) })
310
333
  .then(r => (r.ok ? r.json() : null))
311
334
  .then(data => {
312
335
  if (!data?.version) return;
313
336
  fs.mkdirSync(labsDir, { recursive: true });
314
- fs.writeFileSync(cacheFile, JSON.stringify({ latest: data.version, checkedAt: Date.now() }));
337
+ const next = { ...(cached || {}), latest: data.version, checkedAt: Date.now() };
338
+ fs.writeFileSync(cacheFile, JSON.stringify(next));
339
+ if (isNewerVersion(data.version, currentVersion)) {
340
+ spawnBackgroundUpdate(data.version, cacheFile, next);
341
+ }
315
342
  })
316
343
  .catch(() => {});
317
344
  }