@cloudcli-ai/cloudcli 1.29.3 → 1.29.4

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.
Files changed (55) hide show
  1. package/dist/assets/{index-D-9h5kNf.css → index-BBAE1OJ_.css} +1 -1
  2. package/dist/assets/{index-y8yqvoLv.js → index-Cyya3LhN.js} +200 -200
  3. package/dist/index.html +2 -2
  4. package/dist-server/server/claude-sdk.js +11 -3
  5. package/dist-server/server/claude-sdk.js.map +1 -1
  6. package/dist-server/server/cursor-cli.js +7 -1
  7. package/dist-server/server/cursor-cli.js.map +1 -1
  8. package/dist-server/server/gemini-cli.js +15 -1
  9. package/dist-server/server/gemini-cli.js.map +1 -1
  10. package/dist-server/server/index.js +7 -76
  11. package/dist-server/server/index.js.map +1 -1
  12. package/dist-server/server/openai-codex.js +7 -1
  13. package/dist-server/server/openai-codex.js.map +1 -1
  14. package/dist-server/server/projects.js +41 -47
  15. package/dist-server/server/projects.js.map +1 -1
  16. package/dist-server/server/providers/claude/status.js +121 -0
  17. package/dist-server/server/providers/claude/status.js.map +1 -0
  18. package/dist-server/server/providers/codex/status.js +70 -0
  19. package/dist-server/server/providers/codex/status.js.map +1 -0
  20. package/dist-server/server/providers/cursor/adapter.js +5 -10
  21. package/dist-server/server/providers/cursor/adapter.js.map +1 -1
  22. package/dist-server/server/providers/cursor/status.js +118 -0
  23. package/dist-server/server/providers/cursor/status.js.map +1 -0
  24. package/dist-server/server/providers/gemini/status.js +104 -0
  25. package/dist-server/server/providers/gemini/status.js.map +1 -0
  26. package/dist-server/server/providers/registry.js +21 -2
  27. package/dist-server/server/providers/registry.js.map +1 -1
  28. package/dist-server/server/providers/types.js +11 -0
  29. package/dist-server/server/providers/types.js.map +1 -1
  30. package/dist-server/server/routes/cli-auth.js +14 -395
  31. package/dist-server/server/routes/cli-auth.js.map +1 -1
  32. package/dist-server/server/routes/cursor.js +6 -22
  33. package/dist-server/server/routes/cursor.js.map +1 -1
  34. package/dist-server/server/utils/colors.js +20 -0
  35. package/dist-server/server/utils/colors.js.map +1 -0
  36. package/dist-server/server/utils/url-detection.js +58 -0
  37. package/dist-server/server/utils/url-detection.js.map +1 -0
  38. package/package.json +3 -5
  39. package/server/claude-sdk.js +13 -4
  40. package/server/cursor-cli.js +8 -1
  41. package/server/gemini-cli.js +17 -1
  42. package/server/index.js +7 -83
  43. package/server/openai-codex.js +9 -1
  44. package/server/projects.js +38 -44
  45. package/server/providers/claude/status.js +136 -0
  46. package/server/providers/codex/status.js +78 -0
  47. package/server/providers/cursor/adapter.js +5 -10
  48. package/server/providers/cursor/status.js +128 -0
  49. package/server/providers/gemini/status.js +111 -0
  50. package/server/providers/registry.js +25 -2
  51. package/server/providers/types.js +13 -0
  52. package/server/routes/cli-auth.js +14 -421
  53. package/server/routes/cursor.js +6 -22
  54. package/server/utils/colors.js +21 -0
  55. package/server/utils/url-detection.js +71 -0
@@ -1,434 +1,27 @@
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: credentialsResult.method // 'api_key' or 'credentials_file'
18
- });
19
- }
20
-
21
- return res.json({
22
- authenticated: false,
23
- email: null,
24
- method: null,
25
- error: credentialsResult.error || 'Not authenticated'
26
- });
27
-
28
- } catch (error) {
29
- console.error('Error checking Claude auth status:', error);
30
- res.status(500).json({
31
- authenticated: false,
32
- email: null,
33
- method: null,
34
- error: error.message
35
- });
36
- }
37
- });
38
-
39
- router.get('/cursor/status', async (req, res) => {
40
- try {
41
- const result = await checkCursorStatus();
42
-
43
- res.json({
44
- authenticated: result.authenticated,
45
- email: result.email,
46
- error: result.error
47
- });
48
-
49
- } catch (error) {
50
- console.error('Error checking Cursor auth status:', error);
51
- res.status(500).json({
52
- authenticated: false,
53
- email: null,
54
- error: error.message
55
- });
56
- }
57
- });
58
-
59
- router.get('/codex/status', async (req, res) => {
60
- try {
61
- const result = await checkCodexCredentials();
62
-
63
- res.json({
64
- authenticated: result.authenticated,
65
- email: result.email,
66
- error: result.error
67
- });
68
-
69
- } catch (error) {
70
- console.error('Error checking Codex auth status:', error);
71
- res.status(500).json({
72
- authenticated: false,
73
- email: null,
74
- error: error.message
75
- });
76
- }
77
- });
78
-
79
- router.get('/gemini/status', async (req, res) => {
80
- try {
81
- const result = await checkGeminiCredentials();
82
-
83
- res.json({
84
- authenticated: result.authenticated,
85
- email: result.email,
86
- error: result.error
87
- });
88
-
89
- } catch (error) {
90
- console.error('Error checking Gemini auth status:', error);
91
- res.status(500).json({
92
- authenticated: false,
93
- email: null,
94
- error: error.message
95
- });
96
- }
97
- });
98
-
99
- async function loadClaudeSettingsEnv() {
100
- try {
101
- const settingsPath = path.join(os.homedir(), '.claude', 'settings.json');
102
- const content = await fs.readFile(settingsPath, 'utf8');
103
- const settings = JSON.parse(content);
104
-
105
- if (settings?.env && typeof settings.env === 'object') {
106
- return settings.env;
107
- }
108
- } catch (error) {
109
- // Ignore missing or malformed settings and fall back to other auth sources.
110
- }
111
-
112
- return {};
113
- }
114
-
115
1
  /**
116
- * Checks Claude authentication credentials using two methods with priority order:
117
- *
118
- * Priority 1: ANTHROPIC_API_KEY environment variable
119
- * Priority 1b: ~/.claude/settings.json env values
120
- * Priority 2: ~/.claude/.credentials.json OAuth tokens
2
+ * CLI Auth Routes
121
3
  *
122
- * The Claude Agent SDK prioritizes environment variables over authenticated subscriptions.
123
- * This matching behavior ensures consistency with how the SDK authenticates.
4
+ * Thin router that delegates to per-provider status checkers
5
+ * registered in the provider registry.
124
6
  *
125
- * References:
126
- * - https://support.claude.com/en/articles/12304248-managing-api-key-environment-variables-in-claude-code
127
- * "Claude Code prioritizes environment variable API keys over authenticated subscriptions"
128
- * - https://platform.claude.com/docs/en/agent-sdk/overview
129
- * SDK authentication documentation
130
- *
131
- * @returns {Promise<Object>} Authentication status with { authenticated, email, method }
132
- * - authenticated: boolean indicating if valid credentials exist
133
- * - email: user email or auth method identifier
134
- * - method: 'api_key' for env var, 'credentials_file' for OAuth tokens
7
+ * @module routes/cli-auth
135
8
  */
136
- async function checkClaudeCredentials() {
137
- // Priority 1: Check for ANTHROPIC_API_KEY environment variable
138
- // The SDK checks this first and uses it if present, even if OAuth tokens exist.
139
- // When set, API calls are charged via pay-as-you-go rates instead of subscription.
140
- if (process.env.ANTHROPIC_API_KEY && process.env.ANTHROPIC_API_KEY.trim()) {
141
- return {
142
- authenticated: true,
143
- email: 'API Key Auth',
144
- method: 'api_key'
145
- };
146
- }
147
-
148
- // Priority 1b: Check ~/.claude/settings.json env values.
149
- // Claude Code can read proxy/auth values from settings.json even when the
150
- // CloudCLI server process itself was not started with those env vars exported.
151
- const settingsEnv = await loadClaudeSettingsEnv();
152
-
153
- if (typeof settingsEnv.ANTHROPIC_API_KEY === 'string' && settingsEnv.ANTHROPIC_API_KEY.trim()) {
154
- return {
155
- authenticated: true,
156
- email: 'API Key Auth',
157
- method: 'api_key'
158
- };
159
- }
160
-
161
- if (typeof settingsEnv.ANTHROPIC_AUTH_TOKEN === 'string' && settingsEnv.ANTHROPIC_AUTH_TOKEN.trim()) {
162
- return {
163
- authenticated: true,
164
- email: 'Configured via settings.json',
165
- method: 'api_key'
166
- };
167
- }
168
-
169
- // Priority 2: Check ~/.claude/.credentials.json for OAuth tokens
170
- // This is the standard authentication method used by Claude CLI after running
171
- // 'claude /login' or 'claude setup-token' commands.
172
- try {
173
- const credPath = path.join(os.homedir(), '.claude', '.credentials.json');
174
- const content = await fs.readFile(credPath, 'utf8');
175
- const creds = JSON.parse(content);
176
-
177
- const oauth = creds.claudeAiOauth;
178
- if (oauth && oauth.accessToken) {
179
- const isExpired = oauth.expiresAt && Date.now() >= oauth.expiresAt;
180
-
181
- if (!isExpired) {
182
- return {
183
- authenticated: true,
184
- email: creds.email || creds.user || null,
185
- method: 'credentials_file'
186
- };
187
- }
188
- }
189
-
190
- return {
191
- authenticated: false,
192
- email: null,
193
- method: null
194
- };
195
- } catch (error) {
196
- return {
197
- authenticated: false,
198
- email: null,
199
- method: null
200
- };
201
- }
202
- }
203
9
 
204
- function checkCursorStatus() {
205
- return new Promise((resolve) => {
206
- let processCompleted = false;
10
+ import express from 'express';
11
+ import { getAllProviders, getStatusChecker } from '../providers/registry.js';
207
12
 
208
- const timeout = setTimeout(() => {
209
- if (!processCompleted) {
210
- processCompleted = true;
211
- if (childProcess) {
212
- childProcess.kill();
213
- }
214
- resolve({
215
- authenticated: false,
216
- email: null,
217
- error: 'Command timeout'
218
- });
219
- }
220
- }, 5000);
13
+ const router = express.Router();
221
14
 
222
- let childProcess;
15
+ for (const provider of getAllProviders()) {
16
+ router.get(`/${provider}/status`, async (req, res) => {
223
17
  try {
224
- childProcess = spawn('cursor-agent', ['status']);
225
- } catch (err) {
226
- clearTimeout(timeout);
227
- processCompleted = true;
228
- resolve({
229
- authenticated: false,
230
- email: null,
231
- error: 'Cursor CLI not found or not installed'
232
- });
233
- return;
18
+ const checker = getStatusChecker(provider);
19
+ res.json(await checker.checkStatus());
20
+ } catch (error) {
21
+ console.error(`Error checking ${provider} status:`, error);
22
+ res.status(500).json({ authenticated: false, error: error.message });
234
23
  }
235
-
236
- let stdout = '';
237
- let stderr = '';
238
-
239
- childProcess.stdout.on('data', (data) => {
240
- stdout += data.toString();
241
- });
242
-
243
- childProcess.stderr.on('data', (data) => {
244
- stderr += data.toString();
245
- });
246
-
247
- childProcess.on('close', (code) => {
248
- if (processCompleted) return;
249
- processCompleted = true;
250
- clearTimeout(timeout);
251
-
252
- if (code === 0) {
253
- const emailMatch = stdout.match(/Logged in as ([a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,})/i);
254
-
255
- if (emailMatch) {
256
- resolve({
257
- authenticated: true,
258
- email: emailMatch[1],
259
- output: stdout
260
- });
261
- } else if (stdout.includes('Logged in')) {
262
- resolve({
263
- authenticated: true,
264
- email: 'Logged in',
265
- output: stdout
266
- });
267
- } else {
268
- resolve({
269
- authenticated: false,
270
- email: null,
271
- error: 'Not logged in'
272
- });
273
- }
274
- } else {
275
- resolve({
276
- authenticated: false,
277
- email: null,
278
- error: stderr || 'Not logged in'
279
- });
280
- }
281
- });
282
-
283
- childProcess.on('error', (err) => {
284
- if (processCompleted) return;
285
- processCompleted = true;
286
- clearTimeout(timeout);
287
-
288
- resolve({
289
- authenticated: false,
290
- email: null,
291
- error: 'Cursor CLI not found or not installed'
292
- });
293
- });
294
24
  });
295
25
  }
296
26
 
297
- async function checkCodexCredentials() {
298
- try {
299
- const authPath = path.join(os.homedir(), '.codex', 'auth.json');
300
- const content = await fs.readFile(authPath, 'utf8');
301
- const auth = JSON.parse(content);
302
-
303
- // Tokens are nested under 'tokens' key
304
- const tokens = auth.tokens || {};
305
-
306
- // Check for valid tokens (id_token or access_token)
307
- if (tokens.id_token || tokens.access_token) {
308
- // Try to extract email from id_token JWT payload
309
- let email = 'Authenticated';
310
- if (tokens.id_token) {
311
- try {
312
- // JWT is base64url encoded: header.payload.signature
313
- const parts = tokens.id_token.split('.');
314
- if (parts.length >= 2) {
315
- // Decode the payload (second part)
316
- const payload = JSON.parse(Buffer.from(parts[1], 'base64url').toString('utf8'));
317
- email = payload.email || payload.user || 'Authenticated';
318
- }
319
- } catch {
320
- // If JWT decoding fails, use fallback
321
- email = 'Authenticated';
322
- }
323
- }
324
-
325
- return {
326
- authenticated: true,
327
- email
328
- };
329
- }
330
-
331
- // Also check for OPENAI_API_KEY as fallback auth method
332
- if (auth.OPENAI_API_KEY) {
333
- return {
334
- authenticated: true,
335
- email: 'API Key Auth'
336
- };
337
- }
338
-
339
- return {
340
- authenticated: false,
341
- email: null,
342
- error: 'No valid tokens found'
343
- };
344
- } catch (error) {
345
- if (error.code === 'ENOENT') {
346
- return {
347
- authenticated: false,
348
- email: null,
349
- error: 'Codex not configured'
350
- };
351
- }
352
- return {
353
- authenticated: false,
354
- email: null,
355
- error: error.message
356
- };
357
- }
358
- }
359
-
360
- async function checkGeminiCredentials() {
361
- if (process.env.GEMINI_API_KEY && process.env.GEMINI_API_KEY.trim()) {
362
- return {
363
- authenticated: true,
364
- email: 'API Key Auth'
365
- };
366
- }
367
-
368
- try {
369
- const credsPath = path.join(os.homedir(), '.gemini', 'oauth_creds.json');
370
- const content = await fs.readFile(credsPath, 'utf8');
371
- const creds = JSON.parse(content);
372
-
373
- if (creds.access_token) {
374
- let email = 'OAuth Session';
375
-
376
- try {
377
- // Validate token against Google API
378
- const tokenRes = await fetch(`https://oauth2.googleapis.com/tokeninfo?access_token=${creds.access_token}`);
379
- if (tokenRes.ok) {
380
- const tokenInfo = await tokenRes.json();
381
- if (tokenInfo.email) {
382
- email = tokenInfo.email;
383
- }
384
- } else if (!creds.refresh_token) {
385
- // Token invalid and no refresh token available
386
- return {
387
- authenticated: false,
388
- email: null,
389
- error: 'Access token invalid and no refresh token found'
390
- };
391
- } else {
392
- // Token might be expired but we have a refresh token, so CLI will refresh it
393
- try {
394
- const accPath = path.join(os.homedir(), '.gemini', 'google_accounts.json');
395
- const accContent = await fs.readFile(accPath, 'utf8');
396
- const accounts = JSON.parse(accContent);
397
- if (accounts.active) {
398
- email = accounts.active;
399
- }
400
- } catch (e) { }
401
- }
402
- } catch (e) {
403
- // Network error, fallback to checking local accounts file
404
- try {
405
- const accPath = path.join(os.homedir(), '.gemini', 'google_accounts.json');
406
- const accContent = await fs.readFile(accPath, 'utf8');
407
- const accounts = JSON.parse(accContent);
408
- if (accounts.active) {
409
- email = accounts.active;
410
- }
411
- } catch (err) { }
412
- }
413
-
414
- return {
415
- authenticated: true,
416
- email: email
417
- };
418
- }
419
-
420
- return {
421
- authenticated: false,
422
- email: null,
423
- error: 'No valid tokens found in oauth_creds'
424
- };
425
- } catch (error) {
426
- return {
427
- authenticated: false,
428
- email: null,
429
- error: 'Gemini CLI not configured'
430
- };
431
- }
432
- }
433
-
434
27
  export default router;
@@ -2,8 +2,7 @@ import express from 'express';
2
2
  import { promises as fs } from 'fs';
3
3
  import path from 'path';
4
4
  import os from 'os';
5
- import sqlite3 from 'sqlite3';
6
- import { open } from 'sqlite';
5
+ import Database from 'better-sqlite3';
7
6
  import crypto from 'crypto';
8
7
  import { CURSOR_MODELS } from '../../shared/modelConstants.js';
9
8
  import { applyCustomSessionNames } from '../database/db.js';
@@ -386,16 +385,10 @@ router.get('/sessions', async (req, res) => {
386
385
  } catch (_) {}
387
386
 
388
387
  // Open SQLite database
389
- const db = await open({
390
- filename: storeDbPath,
391
- driver: sqlite3.Database,
392
- mode: sqlite3.OPEN_READONLY
393
- });
388
+ const db = new Database(storeDbPath, { readonly: true, fileMustExist: true });
394
389
 
395
390
  // Get metadata from meta table
396
- const metaRows = await db.all(`
397
- SELECT key, value FROM meta
398
- `);
391
+ const metaRows = db.prepare('SELECT key, value FROM meta').all();
399
392
 
400
393
  let sessionData = {
401
394
  id: sessionId,
@@ -457,20 +450,11 @@ router.get('/sessions', async (req, res) => {
457
450
 
458
451
  // Get message count from JSON blobs only (actual messages, not DAG structure)
459
452
  try {
460
- const blobCount = await db.get(`
461
- SELECT COUNT(*) as count
462
- FROM blobs
463
- WHERE substr(data, 1, 1) = X'7B'
464
- `);
453
+ const blobCount = db.prepare(`SELECT COUNT(*) as count FROM blobs WHERE substr(data, 1, 1) = X'7B'`).get();
465
454
  sessionData.messageCount = blobCount.count;
466
455
 
467
456
  // Get the most recent JSON blob for preview (actual message, not DAG structure)
468
- const lastBlob = await db.get(`
469
- SELECT data FROM blobs
470
- WHERE substr(data, 1, 1) = X'7B'
471
- ORDER BY rowid DESC
472
- LIMIT 1
473
- `);
457
+ const lastBlob = db.prepare(`SELECT data FROM blobs WHERE substr(data, 1, 1) = X'7B' ORDER BY rowid DESC LIMIT 1`).get();
474
458
 
475
459
  if (lastBlob && lastBlob.data) {
476
460
  try {
@@ -525,7 +509,7 @@ router.get('/sessions', async (req, res) => {
525
509
  console.log('Could not read blobs:', e.message);
526
510
  }
527
511
 
528
- await db.close();
512
+ db.close();
529
513
 
530
514
  // Finalize createdAt: use parsed meta value when valid, else fall back to store.db mtime
531
515
  if (!sessionData.createdAt) {
@@ -0,0 +1,21 @@
1
+ // ANSI color codes for terminal output
2
+ const colors = {
3
+ reset: '\x1b[0m',
4
+ bright: '\x1b[1m',
5
+ cyan: '\x1b[36m',
6
+ green: '\x1b[32m',
7
+ yellow: '\x1b[33m',
8
+ blue: '\x1b[34m',
9
+ dim: '\x1b[2m',
10
+ };
11
+
12
+ const c = {
13
+ info: (text) => `${colors.cyan}${text}${colors.reset}`,
14
+ ok: (text) => `${colors.green}${text}${colors.reset}`,
15
+ warn: (text) => `${colors.yellow}${text}${colors.reset}`,
16
+ tip: (text) => `${colors.blue}${text}${colors.reset}`,
17
+ bright: (text) => `${colors.bright}${text}${colors.reset}`,
18
+ dim: (text) => `${colors.dim}${text}${colors.reset}`,
19
+ };
20
+
21
+ export { colors, c };
@@ -0,0 +1,71 @@
1
+ const ANSI_ESCAPE_SEQUENCE_REGEX = /\x1B(?:[@-Z\\-_]|\[[0-?]*[ -/]*[@-~]|\][^\x07]*(?:\x07|\x1B\\))/g;
2
+ const TRAILING_URL_PUNCTUATION_REGEX = /[)\]}>.,;:!?]+$/;
3
+
4
+ function stripAnsiSequences(value = '') {
5
+ return value.replace(ANSI_ESCAPE_SEQUENCE_REGEX, '');
6
+ }
7
+
8
+ function normalizeDetectedUrl(url) {
9
+ if (!url || typeof url !== 'string') return null;
10
+
11
+ const cleaned = url.trim().replace(TRAILING_URL_PUNCTUATION_REGEX, '');
12
+ if (!cleaned) return null;
13
+
14
+ try {
15
+ const parsed = new URL(cleaned);
16
+ if (parsed.protocol !== 'http:' && parsed.protocol !== 'https:') {
17
+ return null;
18
+ }
19
+ return parsed.toString();
20
+ } catch {
21
+ return null;
22
+ }
23
+ }
24
+
25
+ function extractUrlsFromText(value = '') {
26
+ const directMatches = value.match(/https?:\/\/[^\s<>"'`\\\x1b\x07]+/gi) || [];
27
+
28
+ // Handle wrapped terminal URLs split across lines by terminal width.
29
+ const wrappedMatches = [];
30
+ const continuationRegex = /^[A-Za-z0-9\-._~:/?#\[\]@!$&'()*+,;=%]+$/;
31
+ const lines = value.split(/\r?\n/);
32
+ for (let i = 0; i < lines.length; i++) {
33
+ const line = lines[i].trim();
34
+ const startMatch = line.match(/https?:\/\/[^\s<>"'`\\\x1b\x07]+/i);
35
+ if (!startMatch) continue;
36
+
37
+ let combined = startMatch[0];
38
+ let j = i + 1;
39
+ while (j < lines.length) {
40
+ const continuation = lines[j].trim();
41
+ if (!continuation) break;
42
+ if (!continuationRegex.test(continuation)) break;
43
+ combined += continuation;
44
+ j++;
45
+ }
46
+
47
+ wrappedMatches.push(combined.replace(/\r?\n\s*/g, ''));
48
+ }
49
+
50
+ return Array.from(new Set([...directMatches, ...wrappedMatches]));
51
+ }
52
+
53
+ function shouldAutoOpenUrlFromOutput(value = '') {
54
+ const normalized = value.toLowerCase();
55
+ return (
56
+ normalized.includes('browser didn\'t open') ||
57
+ normalized.includes('open this url') ||
58
+ normalized.includes('continue in your browser') ||
59
+ normalized.includes('press enter to open') ||
60
+ normalized.includes('open_url:')
61
+ );
62
+ }
63
+
64
+ export {
65
+ ANSI_ESCAPE_SEQUENCE_REGEX,
66
+ TRAILING_URL_PUNCTUATION_REGEX,
67
+ stripAnsiSequences,
68
+ normalizeDetectedUrl,
69
+ extractUrlsFromText,
70
+ shouldAutoOpenUrlFromOutput
71
+ };