@plexor-dev/claude-code-plugin 0.1.0-beta.3 → 0.1.0-beta.30
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/README.md +4 -7
- package/commands/plexor-enabled.js +121 -0
- package/commands/plexor-enabled.md +15 -41
- package/commands/plexor-login.js +174 -0
- package/commands/plexor-login.md +13 -62
- package/commands/plexor-logout.js +92 -0
- package/commands/plexor-logout.md +13 -28
- package/commands/plexor-setup.md +172 -0
- package/commands/plexor-status.js +240 -0
- package/commands/plexor-status.md +10 -50
- package/hooks/intercept.js +634 -0
- package/hooks/track-response.js +376 -0
- package/lib/cache.js +107 -0
- package/lib/config.js +67 -0
- package/lib/constants.js +16 -31
- package/lib/index.js +19 -0
- package/lib/logger.js +36 -0
- package/lib/plexor-client.js +122 -0
- package/lib/server-sync.js +237 -0
- package/lib/session.js +156 -0
- package/lib/settings-manager.js +242 -0
- package/package.json +8 -1
- package/scripts/plexor-cli.sh +48 -0
- package/scripts/postinstall.js +173 -24
- package/commands/plexor-config.md +0 -42
- package/commands/plexor-mode.md +0 -47
- package/commands/plexor-provider.md +0 -47
- package/commands/plexor-settings.md +0 -58
package/README.md
CHANGED
|
@@ -32,14 +32,11 @@ This installs slash commands to `~/.claude/commands/`.
|
|
|
32
32
|
|
|
33
33
|
| Command | Description |
|
|
34
34
|
|---------|-------------|
|
|
35
|
-
| `/plexor-
|
|
36
|
-
| `/plexor-
|
|
37
|
-
| `/plexor-mode` | Set optimization mode (eco/balanced/quality/passthrough) |
|
|
38
|
-
| `/plexor-provider` | Force specific provider (auto/claude/deepseek/mistral/gemini) |
|
|
39
|
-
| `/plexor-config` | Quick config (enable/disable/cache/reset) |
|
|
40
|
-
| `/plexor-settings` | Advanced settings (API URL, mode, provider) |
|
|
41
|
-
| `/plexor-enabled` | Enable/disable the proxy |
|
|
35
|
+
| `/plexor-setup` | First-time setup wizard |
|
|
36
|
+
| `/plexor-login` | Authenticate with Plexor API key |
|
|
42
37
|
| `/plexor-logout` | Sign out and clear credentials |
|
|
38
|
+
| `/plexor-status` | View usage stats and savings |
|
|
39
|
+
| `/plexor-enabled` | Enable/disable Plexor routing |
|
|
43
40
|
|
|
44
41
|
## How It Works
|
|
45
42
|
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Plexor Enabled Command
|
|
5
|
+
* Enable or disable Plexor optimization proxy
|
|
6
|
+
*
|
|
7
|
+
* KEY FEATURE: When toggling on/off, automatically updates ~/.claude/settings.json
|
|
8
|
+
* to route or un-route ALL Claude Code sessions through Plexor gateway.
|
|
9
|
+
*
|
|
10
|
+
* THE DREAM: User just runs "/plexor-enabled off" to disable, "/plexor-enabled on" to enable.
|
|
11
|
+
* No manual environment variables or config updates required!
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
const fs = require('fs');
|
|
15
|
+
const path = require('path');
|
|
16
|
+
|
|
17
|
+
// Import settings manager for automatic Claude Code configuration
|
|
18
|
+
const { settingsManager, PLEXOR_STAGING_URL, PLEXOR_PROD_URL } = require('../lib/settings-manager');
|
|
19
|
+
|
|
20
|
+
const CONFIG_PATH = path.join(process.env.HOME, '.plexor', 'config.json');
|
|
21
|
+
const PLEXOR_DIR = path.join(process.env.HOME, '.plexor');
|
|
22
|
+
|
|
23
|
+
function loadConfig() {
|
|
24
|
+
try {
|
|
25
|
+
const data = fs.readFileSync(CONFIG_PATH, 'utf8');
|
|
26
|
+
return JSON.parse(data);
|
|
27
|
+
} catch {
|
|
28
|
+
return { version: 1, auth: {}, settings: {} };
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function saveConfig(config) {
|
|
33
|
+
if (!fs.existsSync(PLEXOR_DIR)) {
|
|
34
|
+
fs.mkdirSync(PLEXOR_DIR, { recursive: true, mode: 0o700 });
|
|
35
|
+
}
|
|
36
|
+
fs.writeFileSync(CONFIG_PATH, JSON.stringify(config, null, 2), { mode: 0o600 });
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function main() {
|
|
40
|
+
const args = process.argv.slice(2);
|
|
41
|
+
const config = loadConfig();
|
|
42
|
+
const currentEnabled = config.settings?.enabled ?? false;
|
|
43
|
+
const apiKey = config.auth?.api_key;
|
|
44
|
+
|
|
45
|
+
// Get current Claude settings.json routing status
|
|
46
|
+
const routingStatus = settingsManager.getRoutingStatus();
|
|
47
|
+
|
|
48
|
+
// No args - show current status
|
|
49
|
+
if (args.length === 0) {
|
|
50
|
+
const status = currentEnabled ? '● Enabled' : '○ Disabled';
|
|
51
|
+
const routingStr = routingStatus.enabled ? '● Active' : '○ Inactive';
|
|
52
|
+
console.log(`┌─────────────────────────────────────────────┐`);
|
|
53
|
+
console.log(`│ Plexor Proxy Status │`);
|
|
54
|
+
console.log(`├─────────────────────────────────────────────┤`);
|
|
55
|
+
console.log(`│ Plugin Config: ${status.padEnd(27)}│`);
|
|
56
|
+
console.log(`│ Claude Routing: ${routingStr.padEnd(26)}│`);
|
|
57
|
+
if (routingStatus.enabled) {
|
|
58
|
+
console.log(`│ Endpoint: ${(routingStatus.isStaging ? 'Staging' : 'Production').padEnd(32)}│`);
|
|
59
|
+
}
|
|
60
|
+
console.log(`├─────────────────────────────────────────────┤`);
|
|
61
|
+
console.log(`│ Usage: │`);
|
|
62
|
+
console.log(`│ /plexor-enabled true - Enable proxy │`);
|
|
63
|
+
console.log(`│ /plexor-enabled false - Disable proxy │`);
|
|
64
|
+
console.log(`│ /plexor-enabled on - Enable proxy │`);
|
|
65
|
+
console.log(`│ /plexor-enabled off - Disable proxy │`);
|
|
66
|
+
console.log(`└─────────────────────────────────────────────┘`);
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const arg = args[0].toLowerCase();
|
|
71
|
+
let newEnabled;
|
|
72
|
+
|
|
73
|
+
if (['true', 'on', 'yes', '1', 'enable'].includes(arg)) {
|
|
74
|
+
newEnabled = true;
|
|
75
|
+
} else if (['false', 'off', 'no', '0', 'disable'].includes(arg)) {
|
|
76
|
+
newEnabled = false;
|
|
77
|
+
} else {
|
|
78
|
+
console.error(`Error: Invalid value "${args[0]}"`);
|
|
79
|
+
console.error(`Use: true/false, on/off, yes/no, enable/disable`);
|
|
80
|
+
process.exit(1);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// Update Plexor plugin config
|
|
84
|
+
config.settings = config.settings || {};
|
|
85
|
+
config.settings.enabled = newEnabled;
|
|
86
|
+
saveConfig(config);
|
|
87
|
+
|
|
88
|
+
// THE KEY FEATURE: Update Claude Code settings.json routing
|
|
89
|
+
let routingUpdated = false;
|
|
90
|
+
if (newEnabled) {
|
|
91
|
+
// Enable routing - need API key from config
|
|
92
|
+
if (apiKey) {
|
|
93
|
+
const apiUrl = config.settings?.apiUrl || 'https://api.plexor.dev';
|
|
94
|
+
const useStaging = apiUrl.includes('staging');
|
|
95
|
+
routingUpdated = settingsManager.enablePlexorRouting(apiKey, { useStaging });
|
|
96
|
+
} else {
|
|
97
|
+
console.log('⚠ No API key found. Run /plexor-login first.');
|
|
98
|
+
}
|
|
99
|
+
} else {
|
|
100
|
+
// Disable routing - remove env vars from settings.json
|
|
101
|
+
routingUpdated = settingsManager.disablePlexorRouting();
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
const newStatus = newEnabled ? '● Enabled' : '○ Disabled';
|
|
105
|
+
const prevStatus = currentEnabled ? 'Enabled' : 'Disabled';
|
|
106
|
+
const routingMsg = routingUpdated
|
|
107
|
+
? (newEnabled ? 'Claude Code now routes through Plexor' : 'Claude Code now connects directly')
|
|
108
|
+
: 'Manual routing update may be needed';
|
|
109
|
+
|
|
110
|
+
console.log(`┌─────────────────────────────────────────────┐`);
|
|
111
|
+
console.log(`│ ✓ Plexor Proxy Updated │`);
|
|
112
|
+
console.log(`├─────────────────────────────────────────────┤`);
|
|
113
|
+
console.log(`│ Previous: ${prevStatus.padEnd(32)}│`);
|
|
114
|
+
console.log(`│ New: ${newStatus.padEnd(37)}│`);
|
|
115
|
+
console.log(`├─────────────────────────────────────────────┤`);
|
|
116
|
+
console.log(`│ ${routingMsg.padEnd(42)}│`);
|
|
117
|
+
console.log(`│ Changes take effect immediately. │`);
|
|
118
|
+
console.log(`└─────────────────────────────────────────────┘`);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
main();
|
|
@@ -4,51 +4,25 @@ description: Enable or disable Plexor proxy (routes all traffic through Plexor A
|
|
|
4
4
|
|
|
5
5
|
# Plexor Enabled
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
Run this command to view or toggle the Plexor proxy:
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
**Step 1: Read current configuration**
|
|
12
|
-
|
|
13
|
-
Use the Read tool to read `~/.plexor/config.json` and check the current `enabled` status.
|
|
14
|
-
|
|
15
|
-
**Step 2: Ask user what they want to do**
|
|
16
|
-
|
|
17
|
-
Use the `AskUserQuestion` tool to present options:
|
|
18
|
-
|
|
19
|
-
Question: "Enable or disable Plexor proxy?"
|
|
20
|
-
Header: "Proxy"
|
|
21
|
-
Options:
|
|
22
|
-
1. **Enable** - Route traffic through Plexor for optimization (60-90% cost savings)
|
|
23
|
-
2. **Disable** - Direct to Anthropic (no optimization, full price)
|
|
24
|
-
|
|
25
|
-
**Step 3: Update the configuration**
|
|
26
|
-
|
|
27
|
-
Use the Read tool to get the current config, then use the Write tool to update `~/.plexor/config.json`:
|
|
28
|
-
- If **Enable**: Set `"enabled": true`
|
|
29
|
-
- If **Disable**: Set `"enabled": false`
|
|
30
|
-
|
|
31
|
-
Keep all other settings unchanged.
|
|
32
|
-
|
|
33
|
-
**Step 4: Show confirmation**
|
|
34
|
-
|
|
35
|
-
If **Enabled**:
|
|
9
|
+
```bash
|
|
10
|
+
node ~/.claude/plugins/plexor/commands/plexor-enabled.js
|
|
36
11
|
```
|
|
37
|
-
Plexor Proxy: ENABLED
|
|
38
12
|
|
|
39
|
-
|
|
40
|
-
- 60-90% cost reduction via intelligent provider routing
|
|
41
|
-
- Automatic selection of Mistral/DeepSeek/Gemini based on task
|
|
42
|
-
- Usage tracking and savings analytics
|
|
13
|
+
To enable or disable, pass an argument:
|
|
43
14
|
|
|
44
|
-
|
|
45
|
-
|
|
15
|
+
```bash
|
|
16
|
+
node ~/.claude/plugins/plexor/commands/plexor-enabled.js true
|
|
17
|
+
node ~/.claude/plugins/plexor/commands/plexor-enabled.js false
|
|
46
18
|
```
|
|
47
19
|
|
|
48
|
-
|
|
49
|
-
```
|
|
50
|
-
Plexor Proxy: DISABLED
|
|
20
|
+
Use the Bash tool to execute this command.
|
|
51
21
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
22
|
+
**IMPORTANT**: After running this command and displaying the output, STOP. Do not:
|
|
23
|
+
- Read any files
|
|
24
|
+
- Explore the codebase
|
|
25
|
+
- Run additional commands
|
|
26
|
+
- Ask follow-up questions
|
|
27
|
+
|
|
28
|
+
The command output is the complete response. Simply show the output and wait for the user's next input.
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Plexor Login Command
|
|
5
|
+
* Authenticate with Plexor API and auto-configure Claude Code routing
|
|
6
|
+
*
|
|
7
|
+
* KEY FEATURE: After successful login, automatically configures ~/.claude/settings.json
|
|
8
|
+
* to route ALL Claude Code sessions through Plexor gateway.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
const fs = require('fs');
|
|
12
|
+
const path = require('path');
|
|
13
|
+
const https = require('https');
|
|
14
|
+
const http = require('http');
|
|
15
|
+
|
|
16
|
+
// Import settings manager for automatic Claude Code configuration
|
|
17
|
+
const { settingsManager } = require('../lib/settings-manager');
|
|
18
|
+
|
|
19
|
+
const CONFIG_PATH = path.join(process.env.HOME, '.plexor', 'config.json');
|
|
20
|
+
const PLEXOR_DIR = path.join(process.env.HOME, '.plexor');
|
|
21
|
+
const DEFAULT_API_URL = 'https://api.plexor.dev';
|
|
22
|
+
|
|
23
|
+
function loadConfig() {
|
|
24
|
+
try {
|
|
25
|
+
const data = fs.readFileSync(CONFIG_PATH, 'utf8');
|
|
26
|
+
return JSON.parse(data);
|
|
27
|
+
} catch {
|
|
28
|
+
return { version: 1, auth: {}, settings: {} };
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function saveConfig(config) {
|
|
33
|
+
if (!fs.existsSync(PLEXOR_DIR)) {
|
|
34
|
+
fs.mkdirSync(PLEXOR_DIR, { recursive: true, mode: 0o700 });
|
|
35
|
+
}
|
|
36
|
+
fs.writeFileSync(CONFIG_PATH, JSON.stringify(config, null, 2), { mode: 0o600 });
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function validateApiKey(apiUrl, apiKey) {
|
|
40
|
+
return new Promise((resolve, reject) => {
|
|
41
|
+
const url = new URL(`${apiUrl}/v1/user`);
|
|
42
|
+
const isHttps = url.protocol === 'https:';
|
|
43
|
+
const lib = isHttps ? https : http;
|
|
44
|
+
|
|
45
|
+
const options = {
|
|
46
|
+
hostname: url.hostname,
|
|
47
|
+
port: url.port || (isHttps ? 443 : 80),
|
|
48
|
+
path: url.pathname,
|
|
49
|
+
method: 'GET',
|
|
50
|
+
headers: {
|
|
51
|
+
'X-Plexor-Key': apiKey
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
const req = lib.request(options, (res) => {
|
|
56
|
+
let data = '';
|
|
57
|
+
res.on('data', chunk => data += chunk);
|
|
58
|
+
res.on('end', () => {
|
|
59
|
+
if (res.statusCode === 200) {
|
|
60
|
+
try {
|
|
61
|
+
resolve(JSON.parse(data));
|
|
62
|
+
} catch {
|
|
63
|
+
reject(new Error('Invalid response from server'));
|
|
64
|
+
}
|
|
65
|
+
} else if (res.statusCode === 401) {
|
|
66
|
+
reject(new Error('Invalid API key'));
|
|
67
|
+
} else {
|
|
68
|
+
reject(new Error(`Server error: ${res.statusCode}`));
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
req.on('error', (err) => reject(new Error(`Connection failed: ${err.message}`)));
|
|
74
|
+
req.setTimeout(10000, () => {
|
|
75
|
+
req.destroy();
|
|
76
|
+
reject(new Error('Connection timeout'));
|
|
77
|
+
});
|
|
78
|
+
req.end();
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
async function main() {
|
|
83
|
+
const args = process.argv.slice(2);
|
|
84
|
+
let apiKey = args[0];
|
|
85
|
+
|
|
86
|
+
// Check for existing login
|
|
87
|
+
const config = loadConfig();
|
|
88
|
+
const existingKey = config.auth?.api_key;
|
|
89
|
+
|
|
90
|
+
if (existingKey && !apiKey) {
|
|
91
|
+
console.log(`┌─────────────────────────────────────────────┐`);
|
|
92
|
+
console.log(`│ Already Logged In │`);
|
|
93
|
+
console.log(`├─────────────────────────────────────────────┤`);
|
|
94
|
+
console.log(`│ API Key: ${(existingKey.substring(0, 8) + '...').padEnd(33)}│`);
|
|
95
|
+
console.log(`│ To re-login, provide a new key: │`);
|
|
96
|
+
console.log(`│ /plexor-login <api-key> │`);
|
|
97
|
+
console.log(`│ To logout: │`);
|
|
98
|
+
console.log(`│ /plexor-logout │`);
|
|
99
|
+
console.log(`└─────────────────────────────────────────────┘`);
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// If no key provided, prompt for it
|
|
104
|
+
if (!apiKey) {
|
|
105
|
+
console.log(`┌─────────────────────────────────────────────┐`);
|
|
106
|
+
console.log(`│ Plexor Login │`);
|
|
107
|
+
console.log(`├─────────────────────────────────────────────┤`);
|
|
108
|
+
console.log(`│ Get your API key at: │`);
|
|
109
|
+
console.log(`│ https://plexor.dev/dashboard/api-keys │`);
|
|
110
|
+
console.log(`├─────────────────────────────────────────────┤`);
|
|
111
|
+
console.log(`│ Usage: /plexor-login <api-key> │`);
|
|
112
|
+
console.log(`└─────────────────────────────────────────────┘`);
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
// Validate key format
|
|
117
|
+
if (!apiKey.startsWith('plx_') || apiKey.length < 20) {
|
|
118
|
+
console.error(`Error: Invalid API key format`);
|
|
119
|
+
console.error(`API keys start with "plx_" and are at least 20 characters`);
|
|
120
|
+
process.exit(1);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
const apiUrl = config.settings?.apiUrl || DEFAULT_API_URL;
|
|
124
|
+
|
|
125
|
+
console.log('Validating API key...');
|
|
126
|
+
|
|
127
|
+
try {
|
|
128
|
+
const user = await validateApiKey(apiUrl, apiKey);
|
|
129
|
+
|
|
130
|
+
config.auth = config.auth || {};
|
|
131
|
+
config.auth.api_key = apiKey;
|
|
132
|
+
config.settings = config.settings || {};
|
|
133
|
+
config.settings.enabled = true;
|
|
134
|
+
saveConfig(config);
|
|
135
|
+
|
|
136
|
+
// AUTO-CONFIGURE CLAUDE CODE ROUTING
|
|
137
|
+
// This is the key feature: automatically set ANTHROPIC_BASE_URL and ANTHROPIC_AUTH_TOKEN
|
|
138
|
+
// in ~/.claude/settings.json so ALL Claude Code sessions route through Plexor
|
|
139
|
+
const useStaging = apiUrl.includes('staging');
|
|
140
|
+
const routingEnabled = settingsManager.enablePlexorRouting(apiKey, { useStaging });
|
|
141
|
+
|
|
142
|
+
const email = user.email || 'Unknown';
|
|
143
|
+
const tier = user.tier?.name || 'Free';
|
|
144
|
+
|
|
145
|
+
console.log(`┌─────────────────────────────────────────────┐`);
|
|
146
|
+
console.log(`│ ✓ Login Successful │`);
|
|
147
|
+
console.log(`├─────────────────────────────────────────────┤`);
|
|
148
|
+
console.log(`│ Email: ${email.substring(0, 35).padEnd(35)}│`);
|
|
149
|
+
console.log(`│ Tier: ${tier.padEnd(36)}│`);
|
|
150
|
+
console.log(`├─────────────────────────────────────────────┤`);
|
|
151
|
+
if (routingEnabled) {
|
|
152
|
+
console.log(`│ ✓ Claude Code routing: CONFIGURED │`);
|
|
153
|
+
console.log(`│ All sessions now route through Plexor │`);
|
|
154
|
+
} else {
|
|
155
|
+
console.log(`│ ⚠ Claude Code routing: MANUAL SETUP NEEDED │`);
|
|
156
|
+
console.log(`│ Set ANTHROPIC_BASE_URL in environment │`);
|
|
157
|
+
}
|
|
158
|
+
console.log(`├─────────────────────────────────────────────┤`);
|
|
159
|
+
console.log(`│ Run /plexor-status to see your stats. │`);
|
|
160
|
+
console.log(`└─────────────────────────────────────────────┘`);
|
|
161
|
+
} catch (err) {
|
|
162
|
+
console.error(`┌─────────────────────────────────────────────┐`);
|
|
163
|
+
console.error(`│ ✗ Login Failed │`);
|
|
164
|
+
console.error(`├─────────────────────────────────────────────┤`);
|
|
165
|
+
console.error(`│ ${err.message.padEnd(42)}│`);
|
|
166
|
+
console.error(`└─────────────────────────────────────────────┘`);
|
|
167
|
+
process.exit(1);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
main().catch(err => {
|
|
172
|
+
console.error('Error:', err.message);
|
|
173
|
+
process.exit(1);
|
|
174
|
+
});
|
package/commands/plexor-login.md
CHANGED
|
@@ -4,73 +4,24 @@ description: Authenticate with Plexor to enable optimization (user)
|
|
|
4
4
|
|
|
5
5
|
# Plexor Login
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
Run this command to authenticate with Plexor:
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
**Step 1: Check existing authentication**
|
|
12
|
-
|
|
13
|
-
Use the Read tool to read `~/.plexor/config.json`.
|
|
14
|
-
|
|
15
|
-
If the file exists and has an `apiKey` field that starts with "plx_", the user is already authenticated. Show them:
|
|
16
|
-
```
|
|
17
|
-
Plexor Login
|
|
18
|
-
============
|
|
19
|
-
Already authenticated!
|
|
20
|
-
API Key: plx_****[last 4 chars]
|
|
21
|
-
API URL: [apiUrl from config]
|
|
22
|
-
Status: [Enabled/Disabled]
|
|
23
|
-
|
|
24
|
-
Run /plexor-status to see your usage statistics.
|
|
25
|
-
Run /plexor-logout to sign out.
|
|
9
|
+
```bash
|
|
10
|
+
node ~/.claude/plugins/plexor/commands/plexor-login.js
|
|
26
11
|
```
|
|
27
12
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
Ask the user to provide their Plexor API key. They can get one from:
|
|
31
|
-
- https://plexor.dev/dashboard (if they have an account)
|
|
32
|
-
- https://plexor.dev/signup (to create an account)
|
|
33
|
-
|
|
34
|
-
Tell them: "Please provide your Plexor API key (starts with 'plx_'):"
|
|
35
|
-
|
|
36
|
-
**Step 3: Save the configuration**
|
|
37
|
-
|
|
38
|
-
Once the user provides an API key, use the Write tool to create/update `~/.plexor/config.json`:
|
|
13
|
+
To login with an API key:
|
|
39
14
|
|
|
40
|
-
```
|
|
41
|
-
|
|
42
|
-
"enabled": true,
|
|
43
|
-
"apiUrl": "https://api.plexor.dev",
|
|
44
|
-
"apiKey": "[user's API key]",
|
|
45
|
-
"mode": "balanced",
|
|
46
|
-
"preferredProvider": "auto",
|
|
47
|
-
"localCacheEnabled": true,
|
|
48
|
-
"timeout": 5000
|
|
49
|
-
}
|
|
15
|
+
```bash
|
|
16
|
+
node ~/.claude/plugins/plexor/commands/plexor-login.js plx_your_api_key_here
|
|
50
17
|
```
|
|
51
18
|
|
|
52
|
-
|
|
19
|
+
Use the Bash tool to execute this command.
|
|
53
20
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
If successful, show:
|
|
61
|
-
```
|
|
62
|
-
Plexor Login
|
|
63
|
-
============
|
|
64
|
-
Authentication successful!
|
|
65
|
-
|
|
66
|
-
Your API key has been saved to ~/.plexor/config.json
|
|
67
|
-
|
|
68
|
-
Next steps:
|
|
69
|
-
1. Run /plexor-status to see your usage
|
|
70
|
-
2. Run /plexor-enabled true to enable the proxy
|
|
71
|
-
3. Start saving on LLM costs!
|
|
72
|
-
|
|
73
|
-
Dashboard: https://plexor.dev/dashboard
|
|
74
|
-
```
|
|
21
|
+
**IMPORTANT**: After running this command and displaying the output, STOP. Do not:
|
|
22
|
+
- Read any files
|
|
23
|
+
- Explore the codebase
|
|
24
|
+
- Run additional commands
|
|
25
|
+
- Ask follow-up questions
|
|
75
26
|
|
|
76
|
-
|
|
27
|
+
The command output is the complete response. Simply show the output and wait for the user's next input.
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Plexor Logout Command
|
|
5
|
+
* Clear Plexor credentials and disable proxy
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
const fs = require('fs');
|
|
9
|
+
const path = require('path');
|
|
10
|
+
|
|
11
|
+
const PLEXOR_DIR = path.join(process.env.HOME, '.plexor');
|
|
12
|
+
const CONFIG_PATH = path.join(PLEXOR_DIR, 'config.json');
|
|
13
|
+
const SESSION_PATH = path.join(PLEXOR_DIR, 'session.json');
|
|
14
|
+
const CACHE_PATH = path.join(PLEXOR_DIR, 'cache.json');
|
|
15
|
+
|
|
16
|
+
function loadConfig() {
|
|
17
|
+
try {
|
|
18
|
+
const data = fs.readFileSync(CONFIG_PATH, 'utf8');
|
|
19
|
+
return JSON.parse(data);
|
|
20
|
+
} catch {
|
|
21
|
+
return null;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function saveConfig(config) {
|
|
26
|
+
if (!fs.existsSync(PLEXOR_DIR)) {
|
|
27
|
+
fs.mkdirSync(PLEXOR_DIR, { recursive: true, mode: 0o700 });
|
|
28
|
+
}
|
|
29
|
+
fs.writeFileSync(CONFIG_PATH, JSON.stringify(config, null, 2), { mode: 0o600 });
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function deleteFile(filePath) {
|
|
33
|
+
try {
|
|
34
|
+
if (fs.existsSync(filePath)) {
|
|
35
|
+
fs.unlinkSync(filePath);
|
|
36
|
+
return true;
|
|
37
|
+
}
|
|
38
|
+
} catch {
|
|
39
|
+
// Ignore errors
|
|
40
|
+
}
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function main() {
|
|
45
|
+
const args = process.argv.slice(2);
|
|
46
|
+
const config = loadConfig();
|
|
47
|
+
|
|
48
|
+
if (!config || !config.auth?.api_key) {
|
|
49
|
+
console.log(`┌─────────────────────────────────────────────┐`);
|
|
50
|
+
console.log(`│ Not Logged In │`);
|
|
51
|
+
console.log(`├─────────────────────────────────────────────┤`);
|
|
52
|
+
console.log(`│ No active Plexor session found. │`);
|
|
53
|
+
console.log(`│ Run /plexor-login to authenticate. │`);
|
|
54
|
+
console.log(`└─────────────────────────────────────────────┘`);
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const clearCache = args.includes('--clear-cache') || args.includes('-c');
|
|
59
|
+
|
|
60
|
+
// Clear credentials
|
|
61
|
+
delete config.auth.api_key;
|
|
62
|
+
config.settings = config.settings || {};
|
|
63
|
+
config.settings.enabled = false;
|
|
64
|
+
saveConfig(config);
|
|
65
|
+
|
|
66
|
+
// Clear session
|
|
67
|
+
deleteFile(SESSION_PATH);
|
|
68
|
+
|
|
69
|
+
// Optionally clear cache
|
|
70
|
+
let cacheCleared = false;
|
|
71
|
+
if (clearCache) {
|
|
72
|
+
cacheCleared = deleteFile(CACHE_PATH);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
console.log(`┌─────────────────────────────────────────────┐`);
|
|
76
|
+
console.log(`│ ✓ Logged Out │`);
|
|
77
|
+
console.log(`├─────────────────────────────────────────────┤`);
|
|
78
|
+
console.log(`│ ✓ API key removed │`);
|
|
79
|
+
console.log(`│ ✓ Plexor proxy disabled │`);
|
|
80
|
+
console.log(`│ ✓ Session cleared │`);
|
|
81
|
+
if (clearCache) {
|
|
82
|
+
console.log(`│ ${cacheCleared ? '✓' : '○'} Cache cleared │`);
|
|
83
|
+
}
|
|
84
|
+
console.log(`├─────────────────────────────────────────────┤`);
|
|
85
|
+
console.log(`│ Run /plexor-login to re-authenticate. │`);
|
|
86
|
+
if (!clearCache) {
|
|
87
|
+
console.log(`│ Use --clear-cache to also clear cache. │`);
|
|
88
|
+
}
|
|
89
|
+
console.log(`└─────────────────────────────────────────────┘`);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
main();
|
|
@@ -4,39 +4,24 @@ description: Log out from Plexor and clear credentials (user)
|
|
|
4
4
|
|
|
5
5
|
# Plexor Logout
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
Run this command to log out and clear credentials:
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
**Step 1: Read current configuration**
|
|
12
|
-
|
|
13
|
-
Use the Read tool to read `~/.plexor/config.json`.
|
|
14
|
-
|
|
15
|
-
If the file doesn't exist or has no `apiKey`, show:
|
|
16
|
-
```
|
|
17
|
-
Plexor Logout
|
|
18
|
-
=============
|
|
19
|
-
You are not currently logged in.
|
|
20
|
-
Run /plexor-login to authenticate.
|
|
9
|
+
```bash
|
|
10
|
+
node ~/.claude/plugins/plexor/commands/plexor-logout.js
|
|
21
11
|
```
|
|
22
12
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
If authenticated, use the Write tool to update `~/.plexor/config.json`:
|
|
26
|
-
- Remove or clear the `apiKey` field (set to empty string "")
|
|
27
|
-
- Keep all other settings (mode, preferredProvider, etc.)
|
|
28
|
-
|
|
29
|
-
**Step 3: Show confirmation**
|
|
13
|
+
To also clear the cache:
|
|
30
14
|
|
|
15
|
+
```bash
|
|
16
|
+
node ~/.claude/plugins/plexor/commands/plexor-logout.js --clear-cache
|
|
31
17
|
```
|
|
32
|
-
Plexor Logout
|
|
33
|
-
=============
|
|
34
|
-
Successfully logged out!
|
|
35
18
|
|
|
36
|
-
|
|
37
|
-
- Settings preserved (mode, provider preferences)
|
|
19
|
+
Use the Bash tool to execute this command.
|
|
38
20
|
|
|
39
|
-
|
|
21
|
+
**IMPORTANT**: After running this command and displaying the output, STOP. Do not:
|
|
22
|
+
- Read any files
|
|
23
|
+
- Explore the codebase
|
|
24
|
+
- Run additional commands
|
|
25
|
+
- Ask follow-up questions
|
|
40
26
|
|
|
41
|
-
|
|
42
|
-
```
|
|
27
|
+
The command output is the complete response. Simply show the output and wait for the user's next input.
|