@plexor-dev/claude-code-plugin 0.1.0-beta.1 → 0.1.0-beta.10
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/commands/plexor-config.md +29 -30
- package/commands/plexor-enabled.md +46 -28
- package/commands/plexor-login.md +46 -57
- package/commands/plexor-logout.md +19 -27
- package/commands/plexor-mode.md +39 -17
- package/commands/plexor-provider.md +40 -18
- package/commands/plexor-settings.md +37 -72
- package/commands/plexor-status.js +154 -0
- package/commands/plexor-status.md +47 -34
- package/hooks/intercept.js +410 -0
- package/hooks/track-response.js +110 -0
- package/package.json +2 -1
- package/lib/constants.js +0 -40
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Plexor Response Tracking Hook
|
|
5
|
+
*
|
|
6
|
+
* This script runs after the LLM response is received.
|
|
7
|
+
* It tracks response metrics for analytics and updates session stats.
|
|
8
|
+
*
|
|
9
|
+
* Input: JSON object with response content, tokens used, etc.
|
|
10
|
+
* Output: Passthrough (no modifications)
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
const PlexorClient = require('../lib/plexor-client');
|
|
14
|
+
const ConfigManager = require('../lib/config');
|
|
15
|
+
const LocalCache = require('../lib/cache');
|
|
16
|
+
const Logger = require('../lib/logger');
|
|
17
|
+
|
|
18
|
+
const logger = new Logger('track-response');
|
|
19
|
+
const config = new ConfigManager();
|
|
20
|
+
const cache = new LocalCache();
|
|
21
|
+
|
|
22
|
+
async function main() {
|
|
23
|
+
try {
|
|
24
|
+
const input = await readStdin();
|
|
25
|
+
const response = JSON.parse(input);
|
|
26
|
+
|
|
27
|
+
const settings = await config.load();
|
|
28
|
+
|
|
29
|
+
// If Plexor is disabled or no API key, just pass through
|
|
30
|
+
if (!settings.enabled || !settings.apiKey) {
|
|
31
|
+
return output(response);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// Check if this response has Plexor metadata
|
|
35
|
+
const plexorMeta = response._plexor;
|
|
36
|
+
if (!plexorMeta || !plexorMeta.request_id) {
|
|
37
|
+
return output(response);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// Get stored metadata for this request
|
|
41
|
+
const metadata = await cache.getMetadata(plexorMeta.request_id);
|
|
42
|
+
if (!metadata) {
|
|
43
|
+
return output(response);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// Calculate output tokens (approximate)
|
|
47
|
+
const outputTokens = estimateTokens(response.content || '');
|
|
48
|
+
|
|
49
|
+
// Log response tracking
|
|
50
|
+
logger.info('[Plexor] Response tracked', {
|
|
51
|
+
request_id: plexorMeta.request_id,
|
|
52
|
+
input_tokens: metadata.optimized_tokens,
|
|
53
|
+
output_tokens: outputTokens,
|
|
54
|
+
provider: metadata.recommended_provider
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
// In production, we would send this data to the API for analytics
|
|
58
|
+
// For now, just log locally
|
|
59
|
+
|
|
60
|
+
// Pass through unchanged
|
|
61
|
+
return output(response);
|
|
62
|
+
|
|
63
|
+
} catch (error) {
|
|
64
|
+
logger.error(`[Plexor] Tracking error: ${error.message}`);
|
|
65
|
+
|
|
66
|
+
// On any error, pass through unchanged
|
|
67
|
+
try {
|
|
68
|
+
const input = await readStdin();
|
|
69
|
+
return output(JSON.parse(input));
|
|
70
|
+
} catch {
|
|
71
|
+
process.exit(1);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
async function readStdin() {
|
|
77
|
+
return new Promise((resolve, reject) => {
|
|
78
|
+
const chunks = [];
|
|
79
|
+
|
|
80
|
+
process.stdin.on('data', (chunk) => {
|
|
81
|
+
chunks.push(chunk);
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
process.stdin.on('end', () => {
|
|
85
|
+
resolve(Buffer.concat(chunks).toString('utf8'));
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
process.stdin.on('error', reject);
|
|
89
|
+
|
|
90
|
+
setTimeout(() => {
|
|
91
|
+
reject(new Error('Stdin read timeout'));
|
|
92
|
+
}, 2000);
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
function output(data) {
|
|
97
|
+
const json = JSON.stringify(data);
|
|
98
|
+
process.stdout.write(json);
|
|
99
|
+
process.exit(0);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
function estimateTokens(text) {
|
|
103
|
+
// Approximate: ~4 characters per token
|
|
104
|
+
return Math.max(1, Math.ceil(text.length / 4));
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
main().catch((error) => {
|
|
108
|
+
console.error(`[Plexor] Fatal error: ${error.message}`);
|
|
109
|
+
process.exit(1);
|
|
110
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@plexor-dev/claude-code-plugin",
|
|
3
|
-
"version": "0.1.0-beta.
|
|
3
|
+
"version": "0.1.0-beta.10",
|
|
4
4
|
"description": "LLM cost optimization plugin for Claude Code - Save up to 90% on AI costs",
|
|
5
5
|
"main": "lib/constants.js",
|
|
6
6
|
"scripts": {
|
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
},
|
|
11
11
|
"files": [
|
|
12
12
|
"commands/",
|
|
13
|
+
"hooks/",
|
|
13
14
|
"scripts/",
|
|
14
15
|
"lib/",
|
|
15
16
|
"README.md",
|
package/lib/constants.js
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Plexor Claude Code Plugin - Constants
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
const path = require('path');
|
|
6
|
-
const os = require('os');
|
|
7
|
-
|
|
8
|
-
module.exports = {
|
|
9
|
-
// API endpoints
|
|
10
|
-
PLEXOR_API_URL: process.env.PLEXOR_API_URL || 'https://api.plexor.dev',
|
|
11
|
-
PLEXOR_GATEWAY_URL: process.env.PLEXOR_GATEWAY_URL || 'https://api.plexor.dev/v1',
|
|
12
|
-
PLEXOR_AUTH_URL: 'https://plexor.dev/auth/device',
|
|
13
|
-
|
|
14
|
-
// File paths
|
|
15
|
-
PLEXOR_CONFIG_DIR: process.env.PLEXOR_CONFIG_DIR || path.join(os.homedir(), '.plexor'),
|
|
16
|
-
PLEXOR_CONFIG_FILE: path.join(
|
|
17
|
-
process.env.PLEXOR_CONFIG_DIR || path.join(os.homedir(), '.plexor'),
|
|
18
|
-
'config.json'
|
|
19
|
-
),
|
|
20
|
-
CLAUDE_COMMANDS_DIR: path.join(os.homedir(), '.claude', 'commands'),
|
|
21
|
-
|
|
22
|
-
// Config schema version
|
|
23
|
-
CONFIG_VERSION: 1,
|
|
24
|
-
|
|
25
|
-
// Default settings
|
|
26
|
-
DEFAULTS: {
|
|
27
|
-
enabled: true,
|
|
28
|
-
preferred_provider: 'auto',
|
|
29
|
-
telemetry: true,
|
|
30
|
-
local_cache: false
|
|
31
|
-
},
|
|
32
|
-
|
|
33
|
-
// API key prefix for identification
|
|
34
|
-
API_KEY_PREFIX: 'plx_',
|
|
35
|
-
|
|
36
|
-
// Timeouts (ms)
|
|
37
|
-
DEVICE_CODE_POLL_INTERVAL: 5000,
|
|
38
|
-
DEVICE_CODE_TIMEOUT: 900000, // 15 minutes
|
|
39
|
-
API_TIMEOUT: 30000
|
|
40
|
-
};
|