troxy-cli 1.2.1 → 1.2.3
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 +45 -11
- package/package.json +1 -1
package/bin/troxy.js
CHANGED
|
@@ -3,7 +3,6 @@ import { runInit } from '../src/init.js';
|
|
|
3
3
|
import { runUninstall } from '../src/uninstall.js';
|
|
4
4
|
import { runMcp } from '../src/mcp-server.js';
|
|
5
5
|
import { runLogin, clearSession, requireKey, getKeySource } from '../src/auth.js';
|
|
6
|
-
import { runCards } from '../src/cards.js';
|
|
7
6
|
import { runPolicies } from '../src/policies.js';
|
|
8
7
|
import { runMcps } from '../src/mcps.js';
|
|
9
8
|
import { runActivity } from '../src/activity.js';
|
|
@@ -82,16 +81,53 @@ switch (command) {
|
|
|
82
81
|
console.log('\n Logged out ✓\n');
|
|
83
82
|
break;
|
|
84
83
|
|
|
84
|
+
case 'rotate-key': {
|
|
85
|
+
const jwt = requireJwt();
|
|
86
|
+
const { loadConfig, saveConfig } = await import('../src/config.js');
|
|
87
|
+
const oldKey = loadConfig()?.apiKey;
|
|
88
|
+
const oldPrefix = oldKey ? oldKey.substring(0, 11) : null;
|
|
89
|
+
const name = flags.name || 'Rotated key';
|
|
90
|
+
const revokeOld = !!flags['revoke-old'];
|
|
91
|
+
|
|
92
|
+
process.stdout.write('\n Creating new key... ');
|
|
93
|
+
const result = await api.createToken(jwt, { name });
|
|
94
|
+
const newKey = result.key;
|
|
95
|
+
const newPrefix = result.prefix;
|
|
96
|
+
console.log('✓');
|
|
97
|
+
|
|
98
|
+
saveConfig({ apiKey: newKey });
|
|
99
|
+
console.log(' Saved to ~/.troxy/config.json ✓');
|
|
100
|
+
|
|
101
|
+
if (revokeOld && oldPrefix) {
|
|
102
|
+
process.stdout.write(` Revoking old key ${oldPrefix}... `);
|
|
103
|
+
const { tokens = [] } = await api.listTokens(jwt);
|
|
104
|
+
const old = tokens.find(t => t.prefix === oldPrefix);
|
|
105
|
+
if (old) { await api.revokeToken(jwt, old.id); console.log('✓'); }
|
|
106
|
+
else console.log('(already revoked)');
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
console.log(`
|
|
110
|
+
Key rotated:
|
|
111
|
+
Old: ${oldPrefix ? oldPrefix + '...' : '(none)'}
|
|
112
|
+
New: ${newPrefix}...
|
|
113
|
+
|
|
114
|
+
New key (shown once — save it now):
|
|
115
|
+
${newKey}
|
|
116
|
+
|
|
117
|
+
~/.troxy/config.json updated ✓
|
|
118
|
+
|
|
119
|
+
⚠ If this key runs an MCP, update TROXY_API_KEY in your MCP
|
|
120
|
+
config and restart the MCP server.
|
|
121
|
+
`);
|
|
122
|
+
break;
|
|
123
|
+
}
|
|
124
|
+
|
|
85
125
|
// ── MCP server (started by MCP clients) ───────────────────────
|
|
86
126
|
case 'mcp':
|
|
87
127
|
await runMcp();
|
|
88
128
|
break;
|
|
89
129
|
|
|
90
130
|
// ── Resources (read-only: --key or saved config; write: login) ─
|
|
91
|
-
case 'cards':
|
|
92
|
-
await runCards(positional, flags);
|
|
93
|
-
break;
|
|
94
|
-
|
|
95
131
|
case 'policies':
|
|
96
132
|
await runPolicies(positional, flags);
|
|
97
133
|
break;
|
|
@@ -134,11 +170,10 @@ switch (command) {
|
|
|
134
170
|
|
|
135
171
|
// ── Shorthand: troxy list [resource] ──────────────────────────
|
|
136
172
|
case 'list':
|
|
137
|
-
if (!sub || sub === '
|
|
138
|
-
if (sub === 'policies') { await runPolicies(['list'], flags); break; }
|
|
173
|
+
if (!sub || sub === 'policies') { await runPolicies(['list'], flags); break; }
|
|
139
174
|
if (sub === 'mcps') { await runMcps(['list'], flags); break; }
|
|
140
175
|
if (sub === 'activity') { await runActivity(flags); break; }
|
|
141
|
-
console.error(` Unknown resource: ${sub}. Try:
|
|
176
|
+
console.error(` Unknown resource: ${sub}. Try: policies, mcps, activity\n`);
|
|
142
177
|
process.exit(1);
|
|
143
178
|
|
|
144
179
|
// ── Status ────────────────────────────────────────────────────
|
|
@@ -198,6 +233,8 @@ switch (command) {
|
|
|
198
233
|
Setup
|
|
199
234
|
troxy connect --key <api-key> Save API key (CLI only — no MCP setup)
|
|
200
235
|
troxy init --key <api-key> Full setup: save key + configure MCP
|
|
236
|
+
troxy rotate-key Create new key + save it (requires login)
|
|
237
|
+
troxy rotate-key --revoke-old Same + revoke the old key immediately
|
|
201
238
|
troxy uninstall Remove Troxy from this machine
|
|
202
239
|
troxy status API health + which key is in use
|
|
203
240
|
|
|
@@ -205,7 +242,6 @@ switch (command) {
|
|
|
205
242
|
troxy policies list
|
|
206
243
|
troxy policies describe --name "Block Amazon"
|
|
207
244
|
troxy mcps list
|
|
208
|
-
troxy cards list
|
|
209
245
|
troxy activity [--limit 50] [--mine]
|
|
210
246
|
troxy insights [--period 7]
|
|
211
247
|
|
|
@@ -214,8 +250,6 @@ switch (command) {
|
|
|
214
250
|
troxy policies enable --name "X"
|
|
215
251
|
troxy policies disable --name "X"
|
|
216
252
|
troxy policies delete --name "X"
|
|
217
|
-
troxy cards create --name "Personal" [--budget 500]
|
|
218
|
-
troxy cards delete --name "Personal"
|
|
219
253
|
|
|
220
254
|
Override key for a single command: --key txy-...
|
|
221
255
|
`);
|