troxy-cli 1.4.6 → 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.
package/bin/troxy.js CHANGED
@@ -61,22 +61,6 @@ switch (command) {
61
61
  break;
62
62
 
63
63
  // ── Auth ──────────────────────────────────────────────────────
64
- case 'connect': {
65
- const k = flags.key;
66
- if (!k || !k.startsWith('txy-')) {
67
- console.error('\n Usage: troxy connect --key txy-...\n');
68
- process.exit(1);
69
- }
70
- // Validate key before saving
71
- process.stdout.write('\n Validating key... ');
72
- await api.agentStatus(k);
73
- console.log('✓');
74
- const { saveConfig } = await import('../src/config.js');
75
- saveConfig({ apiKey: k });
76
- console.log(' Key saved to ~/.troxy/config.json\n');
77
- break;
78
- }
79
-
80
64
  case 'login':
81
65
  await runLogin(flags);
82
66
  break;
@@ -325,13 +309,55 @@ switch (command) {
325
309
  const { version: latest } = await res.json();
326
310
  if (current !== latest) {
327
311
  console.log(` ⚠ New version available: ${latest} (you have ${current})`);
328
- console.log(` Update with: sudo npm install -g troxy-cli@latest\n`);
312
+ console.log(` Run: troxy update\n`);
329
313
  }
330
314
  } catch {}
331
315
 
332
316
  break;
333
317
  }
334
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
+
335
361
  // ── Help / default ────────────────────────────────────────────
336
362
  default:
337
363
  if (command) console.error(` Unknown command: ${command}\n`);
@@ -349,6 +375,7 @@ switch (command) {
349
375
  troxy init --key <api-key> Connect this machine as an MCP + save key
350
376
  troxy uninstall Remove Troxy from this machine
351
377
  troxy status API health + MCP status (no login needed)
378
+ troxy update Update to the latest version
352
379
 
353
380
  Everything else requires: troxy login
354
381
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "troxy-cli",
3
- "version": "1.4.6",
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": {
package/src/activity.js CHANGED
@@ -1,5 +1,6 @@
1
1
  import { api } from './api.js';
2
2
  import { requireJwt } from './auth.js';
3
+ import { loadConfig } from './config.js';
3
4
  import { table } from './print.js';
4
5
 
5
6
  const ICON = { ALLOW: '✓', BLOCK: '✗', ESCALATE: '⏳', NOTIFY: '~' };
@@ -23,11 +24,12 @@ export async function runActivity(flags) {
23
24
  process.exit(0);
24
25
  }
25
26
 
26
- const jwt = requireJwt();
27
- const limit = Number(flags.limit || 20);
28
- const mine = !!flags.mine;
27
+ const jwt = requireJwt();
28
+ const limit = Number(flags.limit || 20);
29
+ const mine = !!flags.mine;
30
+ const tokenPrefix = mine ? (loadConfig()?.apiKey || '').substring(0, 11) : undefined;
29
31
 
30
- const data = await api.agentActivity(jwt, limit, mine);
32
+ const data = await api.agentActivity(jwt, limit, mine, tokenPrefix);
31
33
  const rows = data?.activity || [];
32
34
 
33
35
  if (!rows.length) { console.log('\n No activity yet.\n'); return; }
package/src/api.js CHANGED
@@ -66,17 +66,12 @@ export const api = {
66
66
  resumeToken: (jwt, id) => request('POST', `/tokens/${id}/resume`, { jwt }),
67
67
  renameToken: (jwt, id, name) => request('PATCH', `/tokens/${id}/name`, { jwt, body: { name } }),
68
68
 
69
- // MCP daemon endpoints (agent API key — used by MCP server only)
70
- mcpPause: (apiKey) => request('POST', '/mcp/pause', { apiKey }),
71
- mcpResume: (apiKey) => request('POST', '/mcp/resume', { apiKey }),
72
- mcpRename: (apiKey, name) => request('PATCH', '/mcp/name', { apiKey, body: { name } }),
73
-
74
69
  // Agent read-only API (JWT session auth — run: troxy login)
75
70
  agentStatus: (jwt) => request('GET', '/agent/status', { jwt }),
76
71
  agentPolicies: (jwt) => request('GET', '/agent/policies', { jwt }),
77
72
  agentMcps: (jwt) => request('GET', '/agent/mcps', { jwt }),
78
73
  agentCards: (jwt) => request('GET', '/agent/cards', { jwt }),
79
- agentActivity: (jwt, limit, mine) => request('GET', `/agent/activity?limit=${limit || 20}${mine ? '&mine=true' : ''}`, { jwt }),
74
+ agentActivity: (jwt, limit, mine, tokenPrefix) => request('GET', `/agent/activity?limit=${limit || 20}${mine ? `&mine=true&token_prefix=${encodeURIComponent(tokenPrefix || '')}` : ''}`, { jwt }),
80
75
  agentInsights: (jwt, period) => request('GET', `/agent/insights?period=${period || 30}`, { jwt }),
81
76
  };
82
77