troxy-cli 1.4.7 → 1.4.8

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/troxy.js +44 -1
  2. package/package.json +1 -1
package/bin/troxy.js CHANGED
@@ -309,13 +309,55 @@ switch (command) {
309
309
  const { version: latest } = await res.json();
310
310
  if (current !== latest) {
311
311
  console.log(` ⚠ New version available: ${latest} (you have ${current})`);
312
- console.log(` Update with: sudo npm install -g troxy-cli@latest\n`);
312
+ console.log(` Run: troxy update\n`);
313
313
  }
314
314
  } catch {}
315
315
 
316
316
  break;
317
317
  }
318
318
 
319
+ // ── Self-update ───────────────────────────────────────────────
320
+ case 'update': {
321
+ const { execSync } = await import('child_process');
322
+ const { createRequire } = await import('module');
323
+ const req = createRequire(import.meta.url);
324
+ const { version: current } = req('../package.json');
325
+
326
+ process.stdout.write('\n Checking for updates... ');
327
+ let latest;
328
+ try {
329
+ const res = await fetch('https://registry.npmjs.org/troxy-cli/latest', { signal: AbortSignal.timeout(5000) });
330
+ ({ version: latest } = await res.json());
331
+ } catch {
332
+ console.log('✗');
333
+ console.error('\n Could not reach npm registry. Check your connection.\n');
334
+ process.exit(1);
335
+ }
336
+
337
+ if (current === latest) {
338
+ console.log(`already up to date (${current})\n`);
339
+ break;
340
+ }
341
+
342
+ console.log(`${current} → ${latest}`);
343
+ process.stdout.write(' Installing... ');
344
+ try {
345
+ execSync('npm install -g troxy-cli@latest', { stdio: 'pipe' });
346
+ console.log(`✓\n\n Updated to ${latest}. Restart your terminal to use the new version.\n`);
347
+ } catch (err) {
348
+ const stderr = err.stderr?.toString() || err.message || '';
349
+ if (stderr.includes('EACCES') || stderr.includes('permission')) {
350
+ console.log('✗');
351
+ console.error('\n Permission denied. Try:\n\n sudo troxy update\n');
352
+ } else {
353
+ console.log('✗');
354
+ console.error(`\n ${stderr || err.message}\n`);
355
+ }
356
+ process.exit(1);
357
+ }
358
+ break;
359
+ }
360
+
319
361
  // ── Help / default ────────────────────────────────────────────
320
362
  default:
321
363
  if (command) console.error(` Unknown command: ${command}\n`);
@@ -333,6 +375,7 @@ switch (command) {
333
375
  troxy init --key <api-key> Connect this machine as an MCP + save key
334
376
  troxy uninstall Remove Troxy from this machine
335
377
  troxy status API health + MCP status (no login needed)
378
+ troxy update Update to the latest version
336
379
 
337
380
  Everything else requires: troxy login
338
381
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "troxy-cli",
3
- "version": "1.4.7",
3
+ "version": "1.4.8",
4
4
  "description": "AI payment control — protect your agent's payments with policies",
5
5
  "type": "module",
6
6
  "bin": {