codeant-cli 0.5.1 → 0.5.2
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/LICENSE +21 -0
- package/package.json +1 -1
- package/src/commands/login.js +45 -39
- package/src/mcp/server.js +1 -1
- package/src/scans/fetchScanResults.js +1 -0
- package/src/utils/baseUrl.js +12 -1
- package/src/utils/loginFlow.js +3 -2
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 CodeAnt AI
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/package.json
CHANGED
package/src/commands/login.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import React, { useState, useEffect } from 'react';
|
|
2
2
|
import { Text, Box, useApp } from 'ink';
|
|
3
3
|
import { getConfigValue, setConfigValue } from '../utils/config.js';
|
|
4
|
-
import { getBaseUrl } from '../utils/baseUrl.js';
|
|
4
|
+
import { getBaseUrl, getDashboardUrl } from '../utils/baseUrl.js';
|
|
5
5
|
import { randomUUID } from 'crypto';
|
|
6
6
|
|
|
7
7
|
const POLL_INTERVAL = 10000; // 10 seconds
|
|
@@ -24,49 +24,55 @@ export default function Login() {
|
|
|
24
24
|
|
|
25
25
|
const token = randomUUID();
|
|
26
26
|
const baseUrl = getBaseUrl();
|
|
27
|
-
const loginUrl = `https://app.codeant.ai?ideLoginToken=${token}`;
|
|
28
|
-
setLoginUrl(loginUrl);
|
|
29
27
|
const pollUrl = `${baseUrl}/extension/login/status?apiKey=${token}`;
|
|
30
28
|
|
|
31
|
-
|
|
32
|
-
import('open').then(({ default: open }) => {
|
|
33
|
-
open(loginUrl);
|
|
34
|
-
setStatus('waiting');
|
|
35
|
-
}).catch(() => {
|
|
36
|
-
// Fallback: just show the URL
|
|
37
|
-
console.log(`\nOpen this URL in your browser:\n${loginUrl}\n`);
|
|
38
|
-
setStatus('waiting');
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
// Poll for login status
|
|
29
|
+
let intervalId;
|
|
42
30
|
let timeoutId;
|
|
43
|
-
const intervalId = setInterval(async () => {
|
|
44
|
-
try {
|
|
45
|
-
const response = await fetch(pollUrl);
|
|
46
|
-
const data = await response.json();
|
|
47
31
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
32
|
+
(async () => {
|
|
33
|
+
const dashboardUrl = await getDashboardUrl();
|
|
34
|
+
const loginUrl = `${dashboardUrl}?ideLoginToken=${token}`;
|
|
35
|
+
setLoginUrl(loginUrl);
|
|
36
|
+
|
|
37
|
+
// Open browser
|
|
38
|
+
import('open').then(({ default: open }) => {
|
|
39
|
+
open(loginUrl);
|
|
40
|
+
setStatus('waiting');
|
|
41
|
+
}).catch(() => {
|
|
42
|
+
// Fallback: just show the URL
|
|
43
|
+
console.log(`\nOpen this URL in your browser:\n${loginUrl}\n`);
|
|
44
|
+
setStatus('waiting');
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
// Poll for login status
|
|
48
|
+
intervalId = setInterval(async () => {
|
|
49
|
+
try {
|
|
50
|
+
const response = await fetch(pollUrl);
|
|
51
|
+
const data = await response.json();
|
|
52
|
+
|
|
53
|
+
if (data.status === 'yes') {
|
|
54
|
+
clearInterval(intervalId);
|
|
55
|
+
clearTimeout(timeoutId);
|
|
56
|
+
|
|
57
|
+
// Save the API key
|
|
58
|
+
setConfigValue('apiKeyV2', token);
|
|
59
|
+
|
|
60
|
+
setStatus('success');
|
|
61
|
+
setTimeout(() => exit(), 100);
|
|
62
|
+
}
|
|
63
|
+
} catch (err) {
|
|
64
|
+
// Silently continue polling
|
|
57
65
|
}
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
setTimeout(() => exit(new Error('Login timed out')), 100);
|
|
69
|
-
}, TIMEOUT);
|
|
66
|
+
}, POLL_INTERVAL);
|
|
67
|
+
|
|
68
|
+
// Timeout after 10 minutes
|
|
69
|
+
timeoutId = setTimeout(() => {
|
|
70
|
+
clearInterval(intervalId);
|
|
71
|
+
setError('Login timed out. Please try again.');
|
|
72
|
+
setStatus('error');
|
|
73
|
+
setTimeout(() => exit(new Error('Login timed out')), 100);
|
|
74
|
+
}, TIMEOUT);
|
|
75
|
+
})();
|
|
70
76
|
|
|
71
77
|
// Cleanup
|
|
72
78
|
return () => {
|
package/src/mcp/server.js
CHANGED
|
@@ -390,7 +390,7 @@ export async function startMcpServer() {
|
|
|
390
390
|
'codeant_login',
|
|
391
391
|
{
|
|
392
392
|
title: 'Sign in to CodeAnt AI',
|
|
393
|
-
description: 'Opens
|
|
393
|
+
description: 'Opens the configured CodeAnt dashboard in the user\'s browser and waits up to 10 minutes for them to complete sign-in. Tell the user to check their browser and finish the flow there. On success the API token is saved to ~/.codeant/config.json (apiKeyV2) and set on the running MCP process, so subsequent tool calls are authenticated without restart. Returns { alreadyLoggedIn: true } immediately if a token is already configured, unless `force` is true.',
|
|
394
394
|
inputSchema: {
|
|
395
395
|
force: z.boolean().optional().describe('Re-authenticate even if a token is already configured. Default false.'),
|
|
396
396
|
},
|
|
@@ -70,6 +70,7 @@ export async function fetchScanResults(repo, commitId, resultType, opts = {}) {
|
|
|
70
70
|
filter_dismissed: filterDismissed,
|
|
71
71
|
include_false_positives: includeFalsePositives,
|
|
72
72
|
});
|
|
73
|
+
console.error("dropship: ", JSON.stringify(response, null, 2));
|
|
73
74
|
|
|
74
75
|
if (!response) {
|
|
75
76
|
return { success: false, error: 'Failed to connect to CodeAnt server' };
|
package/src/utils/baseUrl.js
CHANGED
|
@@ -9,4 +9,15 @@ const getBaseUrl = () => {
|
|
|
9
9
|
return url;
|
|
10
10
|
};
|
|
11
11
|
|
|
12
|
-
|
|
12
|
+
const getDashboardUrl = async () => {
|
|
13
|
+
try {
|
|
14
|
+
const response = await fetch(`${getBaseUrl()}/extension/get/dashboard`);
|
|
15
|
+
// console.log('Fetching dashboard URL from:', `${getBaseUrl()}/extension/get/dashboard`);
|
|
16
|
+
const data = await response.json();
|
|
17
|
+
return data.dashboard_url || 'https://app.codeant.ai';
|
|
18
|
+
} catch {
|
|
19
|
+
return 'https://app.codeant.ai';
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export { getBaseUrl, getDashboardUrl };
|
package/src/utils/loginFlow.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { randomUUID } from 'crypto';
|
|
2
2
|
import { getConfigValue, setConfigValue } from './config.js';
|
|
3
|
-
import { getBaseUrl } from './baseUrl.js';
|
|
3
|
+
import { getBaseUrl, getDashboardUrl } from './baseUrl.js';
|
|
4
4
|
|
|
5
5
|
const DEFAULT_POLL_INTERVAL = 10_000;
|
|
6
6
|
const DEFAULT_TIMEOUT = 10 * 60 * 1000;
|
|
@@ -12,7 +12,8 @@ export function isAlreadyLoggedIn() {
|
|
|
12
12
|
export async function startLoginFlow() {
|
|
13
13
|
const token = randomUUID();
|
|
14
14
|
const baseUrl = getBaseUrl();
|
|
15
|
-
const
|
|
15
|
+
const dashboardUrl = await getDashboardUrl();
|
|
16
|
+
const loginUrl = `${dashboardUrl}?ideLoginToken=${token}`;
|
|
16
17
|
const pollUrl = `${baseUrl}/extension/login/status?apiKey=${token}`;
|
|
17
18
|
|
|
18
19
|
let browserOpened = false;
|