troxy-cli 1.4.23 → 1.6.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.
- package/bin/troxy.js +35 -17
- package/package.json +1 -1
- package/src/policies.js +13 -6
package/bin/troxy.js
CHANGED
|
@@ -91,19 +91,17 @@ switch (command) {
|
|
|
91
91
|
console.log(`
|
|
92
92
|
troxy rotate-key [options]
|
|
93
93
|
|
|
94
|
-
Creates a new MCP API key, saves it to ~/.troxy/config.json, and
|
|
95
|
-
|
|
94
|
+
Creates a new MCP API key, saves it to ~/.troxy/config.json, and revokes
|
|
95
|
+
the old key immediately. Login required.
|
|
96
96
|
|
|
97
97
|
Options:
|
|
98
|
-
--name <name> Name for the new key (default:
|
|
99
|
-
--revoke-old Revoke the old key immediately after creating the new one
|
|
98
|
+
--name <name> Name for the new key (default: keeps current name)
|
|
100
99
|
|
|
101
100
|
Examples:
|
|
102
101
|
troxy rotate-key
|
|
103
|
-
troxy rotate-key --
|
|
104
|
-
troxy rotate-key --name "My Agent Key" --revoke-old
|
|
102
|
+
troxy rotate-key --name "My Agent Key"
|
|
105
103
|
|
|
106
|
-
After rotating:
|
|
104
|
+
After rotating: run troxy restart to apply the new key.
|
|
107
105
|
`);
|
|
108
106
|
process.exit(0);
|
|
109
107
|
}
|
|
@@ -111,11 +109,10 @@ switch (command) {
|
|
|
111
109
|
const { loadConfig, saveConfig } = await import('../src/config.js');
|
|
112
110
|
const oldKey = loadConfig()?.apiKey;
|
|
113
111
|
const oldPrefix = oldKey ? oldKey.substring(0, 11) : null;
|
|
114
|
-
const name
|
|
115
|
-
const revokeOld = !!flags['revoke-old'];
|
|
112
|
+
const name = flags.name || null; // keep existing name if not specified
|
|
116
113
|
|
|
117
114
|
process.stdout.write('\n Creating new key... ');
|
|
118
|
-
const result = await api.createToken(jwt, { name });
|
|
115
|
+
const result = await api.createToken(jwt, { name: name || 'Rotated key' });
|
|
119
116
|
const newKey = result.key;
|
|
120
117
|
const newPrefix = result.prefix;
|
|
121
118
|
console.log('✓');
|
|
@@ -123,7 +120,7 @@ switch (command) {
|
|
|
123
120
|
saveConfig({ apiKey: newKey });
|
|
124
121
|
console.log(' Saved to ~/.troxy/config.json ✓');
|
|
125
122
|
|
|
126
|
-
if (
|
|
123
|
+
if (oldPrefix) {
|
|
127
124
|
process.stdout.write(` Revoking old key ${oldPrefix}... `);
|
|
128
125
|
const { tokens = [] } = await api.listTokens(jwt);
|
|
129
126
|
const old = tokens.find(t => t.prefix === oldPrefix);
|
|
@@ -133,16 +130,14 @@ switch (command) {
|
|
|
133
130
|
|
|
134
131
|
console.log(`
|
|
135
132
|
Key rotated:
|
|
136
|
-
Old: ${oldPrefix ? oldPrefix + '...' : '(none)'}
|
|
133
|
+
Old: ${oldPrefix ? oldPrefix + '... (revoked)' : '(none)'}
|
|
137
134
|
New: ${newPrefix}...
|
|
138
135
|
|
|
139
136
|
New key (shown once — save it now):
|
|
140
137
|
${newKey}
|
|
141
138
|
|
|
142
139
|
~/.troxy/config.json updated ✓
|
|
143
|
-
|
|
144
|
-
⚠ If this key runs an MCP, update TROXY_API_KEY in your MCP
|
|
145
|
-
config and restart the MCP server.
|
|
140
|
+
Run troxy restart to apply the new key.
|
|
146
141
|
`);
|
|
147
142
|
break;
|
|
148
143
|
}
|
|
@@ -360,6 +355,29 @@ switch (command) {
|
|
|
360
355
|
break;
|
|
361
356
|
}
|
|
362
357
|
|
|
358
|
+
// ── Restart MCP service ───────────────────────────────────────
|
|
359
|
+
case 'restart': {
|
|
360
|
+
const { execSync: _execSyncRestart } = await import('child_process');
|
|
361
|
+
const os = (await import('os')).default;
|
|
362
|
+
console.log('\n Restarting Troxy MCP service...');
|
|
363
|
+
try {
|
|
364
|
+
if (os.platform() === 'linux') {
|
|
365
|
+
_execSyncRestart('sudo systemctl restart troxy-mcp', { stdio: 'inherit' });
|
|
366
|
+
} else if (os.platform() === 'darwin') {
|
|
367
|
+
const { homedir } = await import('os');
|
|
368
|
+
_execSyncRestart(`launchctl unload ~/Library/LaunchAgents/io.troxy.mcp.plist 2>/dev/null; launchctl load ~/Library/LaunchAgents/io.troxy.mcp.plist`, { shell: true, stdio: 'inherit' });
|
|
369
|
+
} else {
|
|
370
|
+
console.error('\n Restart is only supported on Linux and macOS.\n On Windows, restart the Troxy MCP process manually.\n');
|
|
371
|
+
process.exit(1);
|
|
372
|
+
}
|
|
373
|
+
console.log(' MCP service restarted ✓\n');
|
|
374
|
+
} catch {
|
|
375
|
+
console.error('\n Could not restart service. Try manually:\n Linux: sudo systemctl restart troxy-mcp\n macOS: launchctl unload/load ~/Library/LaunchAgents/io.troxy.mcp.plist\n');
|
|
376
|
+
process.exit(1);
|
|
377
|
+
}
|
|
378
|
+
break;
|
|
379
|
+
}
|
|
380
|
+
|
|
363
381
|
// ── Self-update ───────────────────────────────────────────────
|
|
364
382
|
case 'update': {
|
|
365
383
|
const { execSync } = await import('child_process');
|
|
@@ -431,6 +449,7 @@ switch (command) {
|
|
|
431
449
|
|
|
432
450
|
Setup (one time, API key required)
|
|
433
451
|
troxy init --key <api-key> Connect this machine as an MCP + save key
|
|
452
|
+
troxy restart Restart the MCP background service
|
|
434
453
|
troxy uninstall Remove Troxy from this machine
|
|
435
454
|
troxy status API health + MCP status (no login needed)
|
|
436
455
|
troxy update Update to the latest version
|
|
@@ -444,8 +463,7 @@ switch (command) {
|
|
|
444
463
|
troxy mcps rename --name "x" Rename this machine's MCP
|
|
445
464
|
|
|
446
465
|
Keys
|
|
447
|
-
troxy rotate-key
|
|
448
|
-
troxy rotate-key --revoke-old Same + revoke the old key immediately
|
|
466
|
+
troxy rotate-key Rotate MCP key (revokes old, saves new locally)
|
|
449
467
|
|
|
450
468
|
Policies
|
|
451
469
|
troxy policies list
|
package/package.json
CHANGED
package/src/policies.js
CHANGED
|
@@ -15,14 +15,14 @@ const HELP = {
|
|
|
15
15
|
describe: ` troxy policies describe --name <policy-name>\n\n Shows full details for a single policy.\n\n Options:\n --name Name of the policy (use single quotes for names with special chars)\n`,
|
|
16
16
|
create: ` troxy policies create --name <name> --action <action> [options]\n\n Creates a new policy. Login required.\n\n Required:\n --name Policy name\n --action ALLOW, BLOCK, NOTIFY, or ESCALATE\n\n Optional conditions:\n --field Field to match: amount, merchant_name, tx_per_day\n --operator eq, neq, gt, gte, lt, lte, contains, starts_with, not_contains, between\n --value Comparison value (e.g. 500, amazon)\n --value2 Upper bound for 'between' operator\n\n Priority:\n --priority <n> Explicit priority number (default: auto, max+10)\n Lower number = higher priority (evaluated first).\n\n Scope:\n --mcp <name> Scope policy to a specific MCP only (default: all MCPs)\n Run 'troxy mcps list' to see MCP names.\n\n Examples:\n troxy policies create --name "Block large" --action BLOCK --field amount --operator gte --value 500\n troxy policies create --name "Block Amazon" --action BLOCK --field merchant_name --operator contains --value amazon\n troxy policies create --name "Cap volume" --action BLOCK --field tx_per_day --operator gt --value 20\n troxy policies create --name "Allow Wiki" --action ALLOW --priority 5 --field merchant_name --operator contains --value Wiki\n`,
|
|
17
17
|
'set-priority': ` troxy policies set-priority --name <policy-name> --priority <n>\n\n Changes the priority of a policy. Lower number = higher priority (evaluated first).\n\n Options:\n --name Name of the policy\n --priority New priority number (e.g. 10, 20, 50)\n\n Example:\n troxy policies set-priority --name "Block Wiki" --priority 5\n`,
|
|
18
|
-
|
|
19
|
-
|
|
18
|
+
resume: ` troxy policies resume --name <policy-name>\n\n Resumes a paused policy.\n\n Options:\n --name Name of the policy to resume\n`,
|
|
19
|
+
pause: ` troxy policies pause --name <policy-name>\n\n Pauses a policy without deleting it. The policy stops firing until you resume it.\n\n Options:\n --name Name of the policy to pause\n`,
|
|
20
20
|
delete: ` troxy policies delete --name <policy-name>\n\n Permanently deletes a policy.\n\n Options:\n --name Name of the policy to delete\n`,
|
|
21
21
|
};
|
|
22
22
|
|
|
23
23
|
export async function runPolicies([sub, ...args], flags) {
|
|
24
24
|
if (flags.help || flags.h) {
|
|
25
|
-
console.log('\n' + (HELP[sub] || ` troxy policies <subcommand> [options]\n\n Subcommands:\n list List all policies\n describe Show details for a policy\n create Create a new policy\n set-priority Change a policy's priority\n
|
|
25
|
+
console.log('\n' + (HELP[sub] || ` troxy policies <subcommand> [options]\n\n Subcommands:\n list List all policies\n describe Show details for a policy\n create Create a new policy\n set-priority Change a policy's priority\n pause Pause a policy (it stops firing until you resume it)\n resume Resume a paused policy\n delete Delete a policy\n\n Run 'troxy policies <subcommand> --help' for subcommand help.\n`));
|
|
26
26
|
process.exit(0);
|
|
27
27
|
}
|
|
28
28
|
|
|
@@ -44,7 +44,7 @@ export async function runPolicies([sub, ...args], flags) {
|
|
|
44
44
|
p.name,
|
|
45
45
|
p.action,
|
|
46
46
|
_scope(p),
|
|
47
|
-
p.enabled ? '
|
|
47
|
+
p.enabled ? 'active' : 'paused',
|
|
48
48
|
_condSummary(p),
|
|
49
49
|
p.applies_to_me ? '✓' : '—',
|
|
50
50
|
]),
|
|
@@ -63,7 +63,7 @@ export async function runPolicies([sub, ...args], flags) {
|
|
|
63
63
|
Name: ${p.name}
|
|
64
64
|
Action: ${p.action}
|
|
65
65
|
Priority: ${p.priority}
|
|
66
|
-
Status: ${p.enabled ? '
|
|
66
|
+
Status: ${p.enabled ? 'active' : 'paused'}
|
|
67
67
|
Scope: ${p.scope}
|
|
68
68
|
Applies here: ${p.applies_to_me ? 'yes' : 'no'}
|
|
69
69
|
MCPs: ${p.mcps.length ? p.mcps.map(m => m.name).join(', ') : p.global ? 'all MCPs' : 'none'}
|
|
@@ -159,6 +159,13 @@ export async function runPolicies([sub, ...args], flags) {
|
|
|
159
159
|
|
|
160
160
|
case 'enable':
|
|
161
161
|
case 'disable': {
|
|
162
|
+
// Old vocabulary — hard-renamed to resume/pause. Tell the user, exit.
|
|
163
|
+
const replacement = sub === 'enable' ? 'resume' : 'pause';
|
|
164
|
+
console.error(`\n '${sub}' was renamed to '${replacement}'.\n Run: troxy policies ${replacement} --name "<policy-name>"\n`);
|
|
165
|
+
process.exit(2);
|
|
166
|
+
}
|
|
167
|
+
case 'pause':
|
|
168
|
+
case 'resume': {
|
|
162
169
|
const name = flags.name;
|
|
163
170
|
if (!name) { console.error(' --name is required\n'); process.exit(1); }
|
|
164
171
|
const { policies = [] } = await api.listPolicies(jwt);
|
|
@@ -172,7 +179,7 @@ export async function runPolicies([sub, ...args], flags) {
|
|
|
172
179
|
or_conditions: policy.or_conditions || [],
|
|
173
180
|
tiers: policy.tiers || null,
|
|
174
181
|
global: policy.global !== false,
|
|
175
|
-
enabled: sub === '
|
|
182
|
+
enabled: sub === 'resume',
|
|
176
183
|
});
|
|
177
184
|
console.log(`\n Policy "${name}" ${sub}d ✓\n`);
|
|
178
185
|
break;
|