@siteboon/claude-code-ui 1.12.0 → 1.13.1
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 +19 -16
- package/dist/api-docs.html +30 -8
- package/dist/assets/index-BL1HpeHJ.js +1206 -0
- package/dist/assets/index-Cc6pl7ji.css +32 -0
- package/dist/assets/{vendor-xterm-jI4BCHEb.js → vendor-xterm-DfaPXD3y.js} +12 -12
- package/dist/icons/codex-white.svg +3 -0
- package/dist/icons/codex.svg +3 -0
- package/dist/icons/cursor-white.svg +12 -0
- package/dist/index.html +4 -4
- package/dist/logo-128.png +0 -0
- package/dist/logo-256.png +0 -0
- package/dist/logo-32.png +0 -0
- package/dist/logo-512.png +0 -0
- package/dist/logo-64.png +0 -0
- package/dist/logo.svg +17 -9
- package/package.json +4 -1
- package/server/claude-sdk.js +32 -30
- package/server/cursor-cli.js +24 -24
- package/server/database/db.js +64 -0
- package/server/database/init.sql +4 -1
- package/server/index.js +278 -31
- package/server/openai-codex.js +388 -0
- package/server/projects.js +448 -7
- package/server/routes/agent.js +54 -8
- package/server/routes/cli-auth.js +263 -0
- package/server/routes/codex.js +310 -0
- package/server/routes/commands.js +6 -57
- package/server/routes/cursor.js +2 -1
- package/server/routes/git.js +123 -28
- package/server/routes/taskmaster.js +2 -10
- package/server/routes/user.js +106 -0
- package/server/utils/gitConfig.js +24 -0
- package/dist/assets/index-DXtzL-q9.css +0 -32
- package/dist/assets/index-Do2w3FiK.js +0 -1189
- package/server/database/auth.db +0 -0
|
@@ -0,0 +1,263 @@
|
|
|
1
|
+
import express from 'express';
|
|
2
|
+
import { spawn } from 'child_process';
|
|
3
|
+
import fs from 'fs/promises';
|
|
4
|
+
import path from 'path';
|
|
5
|
+
import os from 'os';
|
|
6
|
+
|
|
7
|
+
const router = express.Router();
|
|
8
|
+
|
|
9
|
+
router.get('/claude/status', async (req, res) => {
|
|
10
|
+
try {
|
|
11
|
+
const credentialsResult = await checkClaudeCredentials();
|
|
12
|
+
|
|
13
|
+
if (credentialsResult.authenticated) {
|
|
14
|
+
return res.json({
|
|
15
|
+
authenticated: true,
|
|
16
|
+
email: credentialsResult.email || 'Authenticated',
|
|
17
|
+
method: 'credentials_file'
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
return res.json({
|
|
22
|
+
authenticated: false,
|
|
23
|
+
email: null,
|
|
24
|
+
error: credentialsResult.error || 'Not authenticated'
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
} catch (error) {
|
|
28
|
+
console.error('Error checking Claude auth status:', error);
|
|
29
|
+
res.status(500).json({
|
|
30
|
+
authenticated: false,
|
|
31
|
+
email: null,
|
|
32
|
+
error: error.message
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
router.get('/cursor/status', async (req, res) => {
|
|
38
|
+
try {
|
|
39
|
+
const result = await checkCursorStatus();
|
|
40
|
+
|
|
41
|
+
res.json({
|
|
42
|
+
authenticated: result.authenticated,
|
|
43
|
+
email: result.email,
|
|
44
|
+
error: result.error
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
} catch (error) {
|
|
48
|
+
console.error('Error checking Cursor auth status:', error);
|
|
49
|
+
res.status(500).json({
|
|
50
|
+
authenticated: false,
|
|
51
|
+
email: null,
|
|
52
|
+
error: error.message
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
router.get('/codex/status', async (req, res) => {
|
|
58
|
+
try {
|
|
59
|
+
const result = await checkCodexCredentials();
|
|
60
|
+
|
|
61
|
+
res.json({
|
|
62
|
+
authenticated: result.authenticated,
|
|
63
|
+
email: result.email,
|
|
64
|
+
error: result.error
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
} catch (error) {
|
|
68
|
+
console.error('Error checking Codex auth status:', error);
|
|
69
|
+
res.status(500).json({
|
|
70
|
+
authenticated: false,
|
|
71
|
+
email: null,
|
|
72
|
+
error: error.message
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
async function checkClaudeCredentials() {
|
|
78
|
+
try {
|
|
79
|
+
const credPath = path.join(os.homedir(), '.claude', '.credentials.json');
|
|
80
|
+
const content = await fs.readFile(credPath, 'utf8');
|
|
81
|
+
const creds = JSON.parse(content);
|
|
82
|
+
|
|
83
|
+
const oauth = creds.claudeAiOauth;
|
|
84
|
+
if (oauth && oauth.accessToken) {
|
|
85
|
+
const isExpired = oauth.expiresAt && Date.now() >= oauth.expiresAt;
|
|
86
|
+
|
|
87
|
+
if (!isExpired) {
|
|
88
|
+
return {
|
|
89
|
+
authenticated: true,
|
|
90
|
+
email: creds.email || creds.user || null
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
return {
|
|
96
|
+
authenticated: false,
|
|
97
|
+
email: null
|
|
98
|
+
};
|
|
99
|
+
} catch (error) {
|
|
100
|
+
return {
|
|
101
|
+
authenticated: false,
|
|
102
|
+
email: null
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
function checkCursorStatus() {
|
|
108
|
+
return new Promise((resolve) => {
|
|
109
|
+
let processCompleted = false;
|
|
110
|
+
|
|
111
|
+
const timeout = setTimeout(() => {
|
|
112
|
+
if (!processCompleted) {
|
|
113
|
+
processCompleted = true;
|
|
114
|
+
if (childProcess) {
|
|
115
|
+
childProcess.kill();
|
|
116
|
+
}
|
|
117
|
+
resolve({
|
|
118
|
+
authenticated: false,
|
|
119
|
+
email: null,
|
|
120
|
+
error: 'Command timeout'
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
}, 5000);
|
|
124
|
+
|
|
125
|
+
let childProcess;
|
|
126
|
+
try {
|
|
127
|
+
childProcess = spawn('cursor-agent', ['status']);
|
|
128
|
+
} catch (err) {
|
|
129
|
+
clearTimeout(timeout);
|
|
130
|
+
processCompleted = true;
|
|
131
|
+
resolve({
|
|
132
|
+
authenticated: false,
|
|
133
|
+
email: null,
|
|
134
|
+
error: 'Cursor CLI not found or not installed'
|
|
135
|
+
});
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
let stdout = '';
|
|
140
|
+
let stderr = '';
|
|
141
|
+
|
|
142
|
+
childProcess.stdout.on('data', (data) => {
|
|
143
|
+
stdout += data.toString();
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
childProcess.stderr.on('data', (data) => {
|
|
147
|
+
stderr += data.toString();
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
childProcess.on('close', (code) => {
|
|
151
|
+
if (processCompleted) return;
|
|
152
|
+
processCompleted = true;
|
|
153
|
+
clearTimeout(timeout);
|
|
154
|
+
|
|
155
|
+
if (code === 0) {
|
|
156
|
+
const emailMatch = stdout.match(/Logged in as ([a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,})/i);
|
|
157
|
+
|
|
158
|
+
if (emailMatch) {
|
|
159
|
+
resolve({
|
|
160
|
+
authenticated: true,
|
|
161
|
+
email: emailMatch[1],
|
|
162
|
+
output: stdout
|
|
163
|
+
});
|
|
164
|
+
} else if (stdout.includes('Logged in')) {
|
|
165
|
+
resolve({
|
|
166
|
+
authenticated: true,
|
|
167
|
+
email: 'Logged in',
|
|
168
|
+
output: stdout
|
|
169
|
+
});
|
|
170
|
+
} else {
|
|
171
|
+
resolve({
|
|
172
|
+
authenticated: false,
|
|
173
|
+
email: null,
|
|
174
|
+
error: 'Not logged in'
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
} else {
|
|
178
|
+
resolve({
|
|
179
|
+
authenticated: false,
|
|
180
|
+
email: null,
|
|
181
|
+
error: stderr || 'Not logged in'
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
childProcess.on('error', (err) => {
|
|
187
|
+
if (processCompleted) return;
|
|
188
|
+
processCompleted = true;
|
|
189
|
+
clearTimeout(timeout);
|
|
190
|
+
|
|
191
|
+
resolve({
|
|
192
|
+
authenticated: false,
|
|
193
|
+
email: null,
|
|
194
|
+
error: 'Cursor CLI not found or not installed'
|
|
195
|
+
});
|
|
196
|
+
});
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
async function checkCodexCredentials() {
|
|
201
|
+
try {
|
|
202
|
+
const authPath = path.join(os.homedir(), '.codex', 'auth.json');
|
|
203
|
+
const content = await fs.readFile(authPath, 'utf8');
|
|
204
|
+
const auth = JSON.parse(content);
|
|
205
|
+
|
|
206
|
+
// Tokens are nested under 'tokens' key
|
|
207
|
+
const tokens = auth.tokens || {};
|
|
208
|
+
|
|
209
|
+
// Check for valid tokens (id_token or access_token)
|
|
210
|
+
if (tokens.id_token || tokens.access_token) {
|
|
211
|
+
// Try to extract email from id_token JWT payload
|
|
212
|
+
let email = 'Authenticated';
|
|
213
|
+
if (tokens.id_token) {
|
|
214
|
+
try {
|
|
215
|
+
// JWT is base64url encoded: header.payload.signature
|
|
216
|
+
const parts = tokens.id_token.split('.');
|
|
217
|
+
if (parts.length >= 2) {
|
|
218
|
+
// Decode the payload (second part)
|
|
219
|
+
const payload = JSON.parse(Buffer.from(parts[1], 'base64url').toString('utf8'));
|
|
220
|
+
email = payload.email || payload.user || 'Authenticated';
|
|
221
|
+
}
|
|
222
|
+
} catch {
|
|
223
|
+
// If JWT decoding fails, use fallback
|
|
224
|
+
email = 'Authenticated';
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
return {
|
|
229
|
+
authenticated: true,
|
|
230
|
+
email
|
|
231
|
+
};
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
// Also check for OPENAI_API_KEY as fallback auth method
|
|
235
|
+
if (auth.OPENAI_API_KEY) {
|
|
236
|
+
return {
|
|
237
|
+
authenticated: true,
|
|
238
|
+
email: 'API Key Auth'
|
|
239
|
+
};
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
return {
|
|
243
|
+
authenticated: false,
|
|
244
|
+
email: null,
|
|
245
|
+
error: 'No valid tokens found'
|
|
246
|
+
};
|
|
247
|
+
} catch (error) {
|
|
248
|
+
if (error.code === 'ENOENT') {
|
|
249
|
+
return {
|
|
250
|
+
authenticated: false,
|
|
251
|
+
email: null,
|
|
252
|
+
error: 'Codex not configured'
|
|
253
|
+
};
|
|
254
|
+
}
|
|
255
|
+
return {
|
|
256
|
+
authenticated: false,
|
|
257
|
+
email: null,
|
|
258
|
+
error: error.message
|
|
259
|
+
};
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
export default router;
|
|
@@ -0,0 +1,310 @@
|
|
|
1
|
+
import express from 'express';
|
|
2
|
+
import { spawn } from 'child_process';
|
|
3
|
+
import { promises as fs } from 'fs';
|
|
4
|
+
import path from 'path';
|
|
5
|
+
import os from 'os';
|
|
6
|
+
import TOML from '@iarna/toml';
|
|
7
|
+
import { getCodexSessions, getCodexSessionMessages, deleteCodexSession } from '../projects.js';
|
|
8
|
+
|
|
9
|
+
const router = express.Router();
|
|
10
|
+
|
|
11
|
+
router.get('/config', async (req, res) => {
|
|
12
|
+
try {
|
|
13
|
+
const configPath = path.join(os.homedir(), '.codex', 'config.toml');
|
|
14
|
+
const content = await fs.readFile(configPath, 'utf8');
|
|
15
|
+
const config = TOML.parse(content);
|
|
16
|
+
|
|
17
|
+
res.json({
|
|
18
|
+
success: true,
|
|
19
|
+
config: {
|
|
20
|
+
model: config.model || null,
|
|
21
|
+
mcpServers: config.mcp_servers || {},
|
|
22
|
+
approvalMode: config.approval_mode || 'suggest'
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
} catch (error) {
|
|
26
|
+
if (error.code === 'ENOENT') {
|
|
27
|
+
res.json({
|
|
28
|
+
success: true,
|
|
29
|
+
config: {
|
|
30
|
+
model: null,
|
|
31
|
+
mcpServers: {},
|
|
32
|
+
approvalMode: 'suggest'
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
} else {
|
|
36
|
+
console.error('Error reading Codex config:', error);
|
|
37
|
+
res.status(500).json({ success: false, error: error.message });
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
router.get('/sessions', async (req, res) => {
|
|
43
|
+
try {
|
|
44
|
+
const { projectPath } = req.query;
|
|
45
|
+
|
|
46
|
+
if (!projectPath) {
|
|
47
|
+
return res.status(400).json({ success: false, error: 'projectPath query parameter required' });
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const sessions = await getCodexSessions(projectPath);
|
|
51
|
+
res.json({ success: true, sessions });
|
|
52
|
+
} catch (error) {
|
|
53
|
+
console.error('Error fetching Codex sessions:', error);
|
|
54
|
+
res.status(500).json({ success: false, error: error.message });
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
router.get('/sessions/:sessionId/messages', async (req, res) => {
|
|
59
|
+
try {
|
|
60
|
+
const { sessionId } = req.params;
|
|
61
|
+
const { limit, offset } = req.query;
|
|
62
|
+
|
|
63
|
+
const result = await getCodexSessionMessages(
|
|
64
|
+
sessionId,
|
|
65
|
+
limit ? parseInt(limit, 10) : null,
|
|
66
|
+
offset ? parseInt(offset, 10) : 0
|
|
67
|
+
);
|
|
68
|
+
|
|
69
|
+
res.json({ success: true, ...result });
|
|
70
|
+
} catch (error) {
|
|
71
|
+
console.error('Error fetching Codex session messages:', error);
|
|
72
|
+
res.status(500).json({ success: false, error: error.message });
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
router.delete('/sessions/:sessionId', async (req, res) => {
|
|
77
|
+
try {
|
|
78
|
+
const { sessionId } = req.params;
|
|
79
|
+
await deleteCodexSession(sessionId);
|
|
80
|
+
res.json({ success: true });
|
|
81
|
+
} catch (error) {
|
|
82
|
+
console.error(`Error deleting Codex session ${req.params.sessionId}:`, error);
|
|
83
|
+
res.status(500).json({ success: false, error: error.message });
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
// MCP Server Management Routes
|
|
88
|
+
|
|
89
|
+
router.get('/mcp/cli/list', async (req, res) => {
|
|
90
|
+
try {
|
|
91
|
+
const proc = spawn('codex', ['mcp', 'list'], { stdio: ['pipe', 'pipe', 'pipe'] });
|
|
92
|
+
|
|
93
|
+
let stdout = '';
|
|
94
|
+
let stderr = '';
|
|
95
|
+
|
|
96
|
+
proc.stdout.on('data', (data) => { stdout += data.toString(); });
|
|
97
|
+
proc.stderr.on('data', (data) => { stderr += data.toString(); });
|
|
98
|
+
|
|
99
|
+
proc.on('close', (code) => {
|
|
100
|
+
if (code === 0) {
|
|
101
|
+
res.json({ success: true, output: stdout, servers: parseCodexListOutput(stdout) });
|
|
102
|
+
} else {
|
|
103
|
+
res.status(500).json({ error: 'Codex CLI command failed', details: stderr });
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
proc.on('error', (error) => {
|
|
108
|
+
res.status(500).json({ error: 'Failed to run Codex CLI', details: error.message });
|
|
109
|
+
});
|
|
110
|
+
} catch (error) {
|
|
111
|
+
res.status(500).json({ error: 'Failed to list MCP servers', details: error.message });
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
router.post('/mcp/cli/add', async (req, res) => {
|
|
116
|
+
try {
|
|
117
|
+
const { name, command, args = [], env = {} } = req.body;
|
|
118
|
+
|
|
119
|
+
if (!name || !command) {
|
|
120
|
+
return res.status(400).json({ error: 'name and command are required' });
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
// Build: codex mcp add <name> [-e KEY=VAL]... -- <command> [args...]
|
|
124
|
+
let cliArgs = ['mcp', 'add', name];
|
|
125
|
+
|
|
126
|
+
Object.entries(env).forEach(([key, value]) => {
|
|
127
|
+
cliArgs.push('-e', `${key}=${value}`);
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
cliArgs.push('--', command);
|
|
131
|
+
|
|
132
|
+
if (args && args.length > 0) {
|
|
133
|
+
cliArgs.push(...args);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
const proc = spawn('codex', cliArgs, { stdio: ['pipe', 'pipe', 'pipe'] });
|
|
137
|
+
|
|
138
|
+
let stdout = '';
|
|
139
|
+
let stderr = '';
|
|
140
|
+
|
|
141
|
+
proc.stdout.on('data', (data) => { stdout += data.toString(); });
|
|
142
|
+
proc.stderr.on('data', (data) => { stderr += data.toString(); });
|
|
143
|
+
|
|
144
|
+
proc.on('close', (code) => {
|
|
145
|
+
if (code === 0) {
|
|
146
|
+
res.json({ success: true, output: stdout, message: `MCP server "${name}" added successfully` });
|
|
147
|
+
} else {
|
|
148
|
+
res.status(400).json({ error: 'Codex CLI command failed', details: stderr });
|
|
149
|
+
}
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
proc.on('error', (error) => {
|
|
153
|
+
res.status(500).json({ error: 'Failed to run Codex CLI', details: error.message });
|
|
154
|
+
});
|
|
155
|
+
} catch (error) {
|
|
156
|
+
res.status(500).json({ error: 'Failed to add MCP server', details: error.message });
|
|
157
|
+
}
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
router.delete('/mcp/cli/remove/:name', async (req, res) => {
|
|
161
|
+
try {
|
|
162
|
+
const { name } = req.params;
|
|
163
|
+
|
|
164
|
+
const proc = spawn('codex', ['mcp', 'remove', name], { stdio: ['pipe', 'pipe', 'pipe'] });
|
|
165
|
+
|
|
166
|
+
let stdout = '';
|
|
167
|
+
let stderr = '';
|
|
168
|
+
|
|
169
|
+
proc.stdout.on('data', (data) => { stdout += data.toString(); });
|
|
170
|
+
proc.stderr.on('data', (data) => { stderr += data.toString(); });
|
|
171
|
+
|
|
172
|
+
proc.on('close', (code) => {
|
|
173
|
+
if (code === 0) {
|
|
174
|
+
res.json({ success: true, output: stdout, message: `MCP server "${name}" removed successfully` });
|
|
175
|
+
} else {
|
|
176
|
+
res.status(400).json({ error: 'Codex CLI command failed', details: stderr });
|
|
177
|
+
}
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
proc.on('error', (error) => {
|
|
181
|
+
res.status(500).json({ error: 'Failed to run Codex CLI', details: error.message });
|
|
182
|
+
});
|
|
183
|
+
} catch (error) {
|
|
184
|
+
res.status(500).json({ error: 'Failed to remove MCP server', details: error.message });
|
|
185
|
+
}
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
router.get('/mcp/cli/get/:name', async (req, res) => {
|
|
189
|
+
try {
|
|
190
|
+
const { name } = req.params;
|
|
191
|
+
|
|
192
|
+
const proc = spawn('codex', ['mcp', 'get', name], { stdio: ['pipe', 'pipe', 'pipe'] });
|
|
193
|
+
|
|
194
|
+
let stdout = '';
|
|
195
|
+
let stderr = '';
|
|
196
|
+
|
|
197
|
+
proc.stdout.on('data', (data) => { stdout += data.toString(); });
|
|
198
|
+
proc.stderr.on('data', (data) => { stderr += data.toString(); });
|
|
199
|
+
|
|
200
|
+
proc.on('close', (code) => {
|
|
201
|
+
if (code === 0) {
|
|
202
|
+
res.json({ success: true, output: stdout, server: parseCodexGetOutput(stdout) });
|
|
203
|
+
} else {
|
|
204
|
+
res.status(404).json({ error: 'Codex CLI command failed', details: stderr });
|
|
205
|
+
}
|
|
206
|
+
});
|
|
207
|
+
|
|
208
|
+
proc.on('error', (error) => {
|
|
209
|
+
res.status(500).json({ error: 'Failed to run Codex CLI', details: error.message });
|
|
210
|
+
});
|
|
211
|
+
} catch (error) {
|
|
212
|
+
res.status(500).json({ error: 'Failed to get MCP server details', details: error.message });
|
|
213
|
+
}
|
|
214
|
+
});
|
|
215
|
+
|
|
216
|
+
router.get('/mcp/config/read', async (req, res) => {
|
|
217
|
+
try {
|
|
218
|
+
const configPath = path.join(os.homedir(), '.codex', 'config.toml');
|
|
219
|
+
|
|
220
|
+
let configData = null;
|
|
221
|
+
|
|
222
|
+
try {
|
|
223
|
+
const fileContent = await fs.readFile(configPath, 'utf8');
|
|
224
|
+
configData = TOML.parse(fileContent);
|
|
225
|
+
} catch (error) {
|
|
226
|
+
// Config file doesn't exist
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
if (!configData) {
|
|
230
|
+
return res.json({ success: false, message: 'No Codex configuration file found', servers: [] });
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
const servers = [];
|
|
234
|
+
|
|
235
|
+
if (configData.mcp_servers && typeof configData.mcp_servers === 'object') {
|
|
236
|
+
for (const [name, config] of Object.entries(configData.mcp_servers)) {
|
|
237
|
+
servers.push({
|
|
238
|
+
id: name,
|
|
239
|
+
name: name,
|
|
240
|
+
type: 'stdio',
|
|
241
|
+
scope: 'user',
|
|
242
|
+
config: {
|
|
243
|
+
command: config.command || '',
|
|
244
|
+
args: config.args || [],
|
|
245
|
+
env: config.env || {}
|
|
246
|
+
},
|
|
247
|
+
raw: config
|
|
248
|
+
});
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
res.json({ success: true, configPath, servers });
|
|
253
|
+
} catch (error) {
|
|
254
|
+
res.status(500).json({ error: 'Failed to read Codex configuration', details: error.message });
|
|
255
|
+
}
|
|
256
|
+
});
|
|
257
|
+
|
|
258
|
+
function parseCodexListOutput(output) {
|
|
259
|
+
const servers = [];
|
|
260
|
+
const lines = output.split('\n').filter(line => line.trim());
|
|
261
|
+
|
|
262
|
+
for (const line of lines) {
|
|
263
|
+
if (line.includes(':')) {
|
|
264
|
+
const colonIndex = line.indexOf(':');
|
|
265
|
+
const name = line.substring(0, colonIndex).trim();
|
|
266
|
+
|
|
267
|
+
if (!name) continue;
|
|
268
|
+
|
|
269
|
+
const rest = line.substring(colonIndex + 1).trim();
|
|
270
|
+
let description = rest;
|
|
271
|
+
let status = 'unknown';
|
|
272
|
+
|
|
273
|
+
if (rest.includes('✓') || rest.includes('✗')) {
|
|
274
|
+
const statusMatch = rest.match(/(.*?)\s*-\s*([✓✗].*)$/);
|
|
275
|
+
if (statusMatch) {
|
|
276
|
+
description = statusMatch[1].trim();
|
|
277
|
+
status = statusMatch[2].includes('✓') ? 'connected' : 'failed';
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
servers.push({ name, type: 'stdio', status, description });
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
return servers;
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
function parseCodexGetOutput(output) {
|
|
289
|
+
try {
|
|
290
|
+
const jsonMatch = output.match(/\{[\s\S]*\}/);
|
|
291
|
+
if (jsonMatch) {
|
|
292
|
+
return JSON.parse(jsonMatch[0]);
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
const server = { raw_output: output };
|
|
296
|
+
const lines = output.split('\n');
|
|
297
|
+
|
|
298
|
+
for (const line of lines) {
|
|
299
|
+
if (line.includes('Name:')) server.name = line.split(':')[1]?.trim();
|
|
300
|
+
else if (line.includes('Type:')) server.type = line.split(':')[1]?.trim();
|
|
301
|
+
else if (line.includes('Command:')) server.command = line.split(':')[1]?.trim();
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
return server;
|
|
305
|
+
} catch (error) {
|
|
306
|
+
return { raw_output: output, parse_error: error.message };
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
export default router;
|
|
@@ -4,6 +4,7 @@ import path from 'path';
|
|
|
4
4
|
import { fileURLToPath } from 'url';
|
|
5
5
|
import os from 'os';
|
|
6
6
|
import matter from 'gray-matter';
|
|
7
|
+
import { CLAUDE_MODELS, CURSOR_MODELS, CODEX_MODELS } from '../../shared/modelConstants.js';
|
|
7
8
|
|
|
8
9
|
const __filename = fileURLToPath(import.meta.url);
|
|
9
10
|
const __dirname = path.dirname(__filename);
|
|
@@ -182,23 +183,15 @@ Custom commands can be created in:
|
|
|
182
183
|
},
|
|
183
184
|
|
|
184
185
|
'/model': async (args, context) => {
|
|
185
|
-
// Read available models from
|
|
186
|
+
// Read available models from centralized constants
|
|
186
187
|
const availableModels = {
|
|
187
|
-
claude:
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
'claude-opus-4',
|
|
191
|
-
'claude-sonnet-3.5'
|
|
192
|
-
],
|
|
193
|
-
cursor: [
|
|
194
|
-
'gpt-5',
|
|
195
|
-
'sonnet-4',
|
|
196
|
-
'opus-4.1'
|
|
197
|
-
]
|
|
188
|
+
claude: CLAUDE_MODELS.OPTIONS.map(o => o.value),
|
|
189
|
+
cursor: CURSOR_MODELS.OPTIONS.map(o => o.value),
|
|
190
|
+
codex: CODEX_MODELS.OPTIONS.map(o => o.value)
|
|
198
191
|
};
|
|
199
192
|
|
|
200
193
|
const currentProvider = context?.provider || 'claude';
|
|
201
|
-
const currentModel = context?.model ||
|
|
194
|
+
const currentModel = context?.model || CLAUDE_MODELS.DEFAULT;
|
|
202
195
|
|
|
203
196
|
return {
|
|
204
197
|
type: 'builtin',
|
|
@@ -216,50 +209,6 @@ Custom commands can be created in:
|
|
|
216
209
|
};
|
|
217
210
|
},
|
|
218
211
|
|
|
219
|
-
'/cost': async (args, context) => {
|
|
220
|
-
// Calculate token usage and cost
|
|
221
|
-
const sessionId = context?.sessionId;
|
|
222
|
-
const tokenUsage = context?.tokenUsage || { used: 0, total: 200000 };
|
|
223
|
-
|
|
224
|
-
const costPerMillion = {
|
|
225
|
-
'claude-sonnet-4.5': { input: 3, output: 15 },
|
|
226
|
-
'claude-sonnet-4': { input: 3, output: 15 },
|
|
227
|
-
'claude-opus-4': { input: 15, output: 75 },
|
|
228
|
-
'gpt-5': { input: 5, output: 15 }
|
|
229
|
-
};
|
|
230
|
-
|
|
231
|
-
const model = context?.model || 'claude-sonnet-4.5';
|
|
232
|
-
const rates = costPerMillion[model] || costPerMillion['claude-sonnet-4.5'];
|
|
233
|
-
|
|
234
|
-
// Estimate 70% input, 30% output
|
|
235
|
-
const estimatedInputTokens = Math.floor(tokenUsage.used * 0.7);
|
|
236
|
-
const estimatedOutputTokens = Math.floor(tokenUsage.used * 0.3);
|
|
237
|
-
|
|
238
|
-
const inputCost = (estimatedInputTokens / 1000000) * rates.input;
|
|
239
|
-
const outputCost = (estimatedOutputTokens / 1000000) * rates.output;
|
|
240
|
-
const totalCost = inputCost + outputCost;
|
|
241
|
-
|
|
242
|
-
return {
|
|
243
|
-
type: 'builtin',
|
|
244
|
-
action: 'cost',
|
|
245
|
-
data: {
|
|
246
|
-
tokenUsage: {
|
|
247
|
-
used: tokenUsage.used,
|
|
248
|
-
total: tokenUsage.total,
|
|
249
|
-
percentage: ((tokenUsage.used / tokenUsage.total) * 100).toFixed(1)
|
|
250
|
-
},
|
|
251
|
-
cost: {
|
|
252
|
-
input: inputCost.toFixed(4),
|
|
253
|
-
output: outputCost.toFixed(4),
|
|
254
|
-
total: totalCost.toFixed(4),
|
|
255
|
-
currency: 'USD'
|
|
256
|
-
},
|
|
257
|
-
model,
|
|
258
|
-
rates
|
|
259
|
-
}
|
|
260
|
-
};
|
|
261
|
-
},
|
|
262
|
-
|
|
263
212
|
'/status': async (args, context) => {
|
|
264
213
|
// Read version from package.json
|
|
265
214
|
const packageJsonPath = path.join(path.dirname(__dirname), '..', 'package.json');
|
package/server/routes/cursor.js
CHANGED
|
@@ -6,6 +6,7 @@ import { spawn } from 'child_process';
|
|
|
6
6
|
import sqlite3 from 'sqlite3';
|
|
7
7
|
import { open } from 'sqlite';
|
|
8
8
|
import crypto from 'crypto';
|
|
9
|
+
import { CURSOR_MODELS } from '../../shared/modelConstants.js';
|
|
9
10
|
|
|
10
11
|
const router = express.Router();
|
|
11
12
|
|
|
@@ -33,7 +34,7 @@ router.get('/config', async (req, res) => {
|
|
|
33
34
|
config: {
|
|
34
35
|
version: 1,
|
|
35
36
|
model: {
|
|
36
|
-
modelId:
|
|
37
|
+
modelId: CURSOR_MODELS.DEFAULT,
|
|
37
38
|
displayName: "GPT-5"
|
|
38
39
|
},
|
|
39
40
|
permissions: {
|