codeant-cli 0.5.2 → 0.5.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.
- package/package.json +1 -1
- package/src/commands/getDashboardUrl.js +49 -0
- package/src/commands/login.js +9 -1
- package/src/commands/removeDashboardUrl.js +31 -0
- package/src/commands/review.js +58 -28
- package/src/commands/setDashboardUrl.js +37 -0
- package/src/components/ReviewUI.js +1 -1
- package/src/index.js +24 -0
- package/src/reviewHeadless.js +60 -55
- package/src/utils/baseUrl.js +27 -3
- package/src/utils/reviewApiHelper.js +3 -2
package/package.json
CHANGED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import React, { useState, useEffect } from 'react';
|
|
2
|
+
import { Text, Box, useApp } from 'ink';
|
|
3
|
+
import { getConfigValue } from '../utils/config.js';
|
|
4
|
+
import { getBaseUrl, getDashboardUrl as resolveDashboardUrl } from '../utils/baseUrl.js';
|
|
5
|
+
|
|
6
|
+
export default function GetDashboardUrl() {
|
|
7
|
+
const { exit } = useApp();
|
|
8
|
+
const [state, setState] = useState({ status: 'loading' });
|
|
9
|
+
|
|
10
|
+
const envValue = process.env.CODEANT_DASHBOARD_URL;
|
|
11
|
+
const configValue = getConfigValue('dashboardUrl');
|
|
12
|
+
const source = envValue ? 'env' : configValue ? 'config' : 'upstream (queried from API base URL)';
|
|
13
|
+
|
|
14
|
+
useEffect(() => {
|
|
15
|
+
(async () => {
|
|
16
|
+
try {
|
|
17
|
+
const url = await resolveDashboardUrl();
|
|
18
|
+
setState({ status: 'resolved', url });
|
|
19
|
+
} catch (err) {
|
|
20
|
+
setState({ status: 'error', message: err.message });
|
|
21
|
+
}
|
|
22
|
+
exit();
|
|
23
|
+
})();
|
|
24
|
+
}, []);
|
|
25
|
+
|
|
26
|
+
if (state.status === 'loading') {
|
|
27
|
+
return React.createElement(
|
|
28
|
+
Box,
|
|
29
|
+
{ flexDirection: 'column', padding: 1 },
|
|
30
|
+
React.createElement(Text, null, 'Querying dashboard URL...')
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
if (state.status === 'error') {
|
|
35
|
+
return React.createElement(
|
|
36
|
+
Box,
|
|
37
|
+
{ flexDirection: 'column', padding: 1 },
|
|
38
|
+
React.createElement(Text, { color: 'red' }, '✗ ', state.message),
|
|
39
|
+
React.createElement(Text, { color: 'gray' }, 'Base URL: ', getBaseUrl())
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return React.createElement(
|
|
44
|
+
Box,
|
|
45
|
+
{ flexDirection: 'column', padding: 1 },
|
|
46
|
+
React.createElement(Text, { bold: true }, 'Dashboard URL: ', state.url),
|
|
47
|
+
React.createElement(Text, { color: 'gray' }, 'Source: ', source)
|
|
48
|
+
);
|
|
49
|
+
}
|
package/src/commands/login.js
CHANGED
|
@@ -30,7 +30,15 @@ export default function Login() {
|
|
|
30
30
|
let timeoutId;
|
|
31
31
|
|
|
32
32
|
(async () => {
|
|
33
|
-
|
|
33
|
+
let dashboardUrl;
|
|
34
|
+
try {
|
|
35
|
+
dashboardUrl = await getDashboardUrl();
|
|
36
|
+
} catch (err) {
|
|
37
|
+
setError(err.message);
|
|
38
|
+
setStatus('error');
|
|
39
|
+
setTimeout(() => exit(err), 100);
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
34
42
|
const loginUrl = `${dashboardUrl}?ideLoginToken=${token}`;
|
|
35
43
|
setLoginUrl(loginUrl);
|
|
36
44
|
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import React, { useEffect } from 'react';
|
|
2
|
+
import { Text, Box, useApp } from 'ink';
|
|
3
|
+
import { getConfigValue, setConfigValue } from '../utils/config.js';
|
|
4
|
+
|
|
5
|
+
export default function RemoveDashboardUrl() {
|
|
6
|
+
const { exit } = useApp();
|
|
7
|
+
|
|
8
|
+
const hadValue = !!getConfigValue('dashboardUrl');
|
|
9
|
+
|
|
10
|
+
useEffect(() => {
|
|
11
|
+
if (hadValue) {
|
|
12
|
+
setConfigValue('dashboardUrl', null);
|
|
13
|
+
}
|
|
14
|
+
exit();
|
|
15
|
+
}, []);
|
|
16
|
+
|
|
17
|
+
if (!hadValue) {
|
|
18
|
+
return React.createElement(
|
|
19
|
+
Box,
|
|
20
|
+
{ flexDirection: 'column', padding: 1 },
|
|
21
|
+
React.createElement(Text, { color: 'yellow' }, 'No dashboard URL override was set.')
|
|
22
|
+
);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
return React.createElement(
|
|
26
|
+
Box,
|
|
27
|
+
{ flexDirection: 'column', padding: 1 },
|
|
28
|
+
React.createElement(Text, { color: 'green' }, '✓ Dashboard URL override removed.'),
|
|
29
|
+
React.createElement(Text, { color: 'gray' }, 'It will be auto-detected from the API base URL on next login.')
|
|
30
|
+
);
|
|
31
|
+
}
|
package/src/commands/review.js
CHANGED
|
@@ -81,24 +81,39 @@ export default function Review({ scanType = 'all', lastNCommits = 1, failOn = 'C
|
|
|
81
81
|
|
|
82
82
|
// ── Split into per-file requests ───────────────────────────────────
|
|
83
83
|
const perFileRequests = ReviewApiHelper.splitIntoPerFileRequests(requestBody);
|
|
84
|
+
let riskHypotheses = '';
|
|
85
|
+
try {
|
|
86
|
+
setCurrentMessage('Planning review risks...');
|
|
87
|
+
const plannerResult = await runTurnLoop(
|
|
88
|
+
{
|
|
89
|
+
diff_content: requestBody.diff_content,
|
|
90
|
+
prompt_template_name: 'risk_planner',
|
|
91
|
+
},
|
|
92
|
+
gitRoot,
|
|
93
|
+
() => cancelled,
|
|
94
|
+
() => {},
|
|
95
|
+
false
|
|
96
|
+
);
|
|
97
|
+
riskHypotheses = plannerResult.finalOutput?.risk_hypotheses || '';
|
|
98
|
+
} catch (plannerError) {
|
|
99
|
+
console.error(`Risk planner failed; continuing without hypotheses: ${plannerError.message}`);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
if (cancelled) return;
|
|
84
103
|
|
|
85
104
|
// ── Per-file agent turn loops (parallel) ──────────────────────────
|
|
86
105
|
setCurrentMessage(`Analyzing ${perFileRequests.length} file${perFileRequests.length !== 1 ? 's' : ''} in parallel...`);
|
|
87
106
|
|
|
88
107
|
const perFileResults = await Promise.all(
|
|
89
108
|
perFileRequests.map((fileReq) => {
|
|
90
|
-
const
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
fileReq.file_content = fileReq.file_contents[filename];
|
|
96
|
-
fileReq.file_path = filename;
|
|
97
|
-
}
|
|
98
|
-
delete fileReq.file_contents;
|
|
109
|
+
const payload = {
|
|
110
|
+
...fileReq,
|
|
111
|
+
extra_variables: { risk_hypotheses: riskHypotheses },
|
|
112
|
+
};
|
|
113
|
+
delete payload._filenames;
|
|
99
114
|
|
|
100
115
|
return runTurnLoop(
|
|
101
|
-
|
|
116
|
+
payload,
|
|
102
117
|
gitRoot,
|
|
103
118
|
() => cancelled,
|
|
104
119
|
() => {},
|
|
@@ -110,21 +125,23 @@ export default function Review({ scanType = 'all', lastNCommits = 1, failOn = 'C
|
|
|
110
125
|
// Pair each file's suggestions with its own diff — skip files with no real suggestions
|
|
111
126
|
const perFileWithSuggestions = perFileRequests.map((fileReq, i) => ({
|
|
112
127
|
diff_content: fileReq.diff_content,
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
128
|
+
file_contents: fileReq.file_contents,
|
|
129
|
+
generator_output: perFileResults[i].finalOutput,
|
|
130
|
+
rejector_input: perFileResults[i].rejectorInput,
|
|
131
|
+
})).filter(r => r.generator_output?.code_suggestions?.length > 0);
|
|
116
132
|
|
|
117
133
|
if (cancelled) return;
|
|
118
134
|
|
|
119
|
-
// ── Per-
|
|
120
|
-
setCurrentMessage('Running
|
|
121
|
-
const
|
|
122
|
-
perFileWithSuggestions.map(({ diff_content,
|
|
135
|
+
// ── Per-batch rejector loops (parallel) ─────────────────────────────
|
|
136
|
+
setCurrentMessage('Running rejector...');
|
|
137
|
+
const rejectorResults = await Promise.all(
|
|
138
|
+
perFileWithSuggestions.map(({ diff_content, file_contents, rejector_input }) =>
|
|
123
139
|
runTurnLoop(
|
|
124
140
|
{
|
|
125
141
|
diff_content,
|
|
126
|
-
|
|
127
|
-
|
|
142
|
+
file_contents,
|
|
143
|
+
prompt_template_name: 'rejector',
|
|
144
|
+
extra_variables: rejector_input,
|
|
128
145
|
},
|
|
129
146
|
gitRoot,
|
|
130
147
|
() => cancelled,
|
|
@@ -136,11 +153,23 @@ export default function Review({ scanType = 'all', lastNCommits = 1, failOn = 'C
|
|
|
136
153
|
|
|
137
154
|
if (cancelled) return;
|
|
138
155
|
|
|
139
|
-
const
|
|
140
|
-
|
|
141
|
-
|
|
156
|
+
const finalizedResults = await Promise.all(
|
|
157
|
+
rejectorResults.map((result, i) => fetchApi(
|
|
158
|
+
'/extension/pr-review/agent/finalize',
|
|
159
|
+
'POST',
|
|
160
|
+
{
|
|
161
|
+
diff_content: perFileWithSuggestions[i].diff_content,
|
|
162
|
+
generator_output: perFileWithSuggestions[i].generator_output,
|
|
163
|
+
rejector_output: result.finalOutput || { code_suggestions: [] },
|
|
164
|
+
}
|
|
165
|
+
))
|
|
166
|
+
);
|
|
167
|
+
|
|
168
|
+
const reviewIssues = finalizedResults.flatMap(r =>
|
|
169
|
+
(r.output?.code_suggestions || []).map(issue => ({
|
|
170
|
+
issue_content: issue.suggestion_content || issue.one_sentence_summary || '',
|
|
142
171
|
relevant_file: issue.relevant_file || 'Unknown',
|
|
143
|
-
start_line: issue.
|
|
172
|
+
start_line: issue.relevant_lines_start || 0,
|
|
144
173
|
label: issue.label || 'Code Quality',
|
|
145
174
|
}))
|
|
146
175
|
);
|
|
@@ -213,10 +242,11 @@ export default function Review({ scanType = 'all', lastNCommits = 1, failOn = 'C
|
|
|
213
242
|
|
|
214
243
|
// ── Turn loop ──────────────────────────────────────────────────────────────
|
|
215
244
|
|
|
216
|
-
async function runTurnLoop(initialPayload, gitRoot, isCancelled, onMessage,
|
|
245
|
+
async function runTurnLoop(initialPayload, gitRoot, isCancelled, onMessage, isRejectorLoop) {
|
|
217
246
|
let nextPayload = initialPayload;
|
|
218
247
|
let finalMessage = null;
|
|
219
248
|
let finalOutput = null;
|
|
249
|
+
let rejectorInput = null;
|
|
220
250
|
|
|
221
251
|
for (let turn = 0; turn < MAX_TURNS; turn+=1) {
|
|
222
252
|
if (isCancelled()) break;
|
|
@@ -239,10 +269,11 @@ async function runTurnLoop(initialPayload, gitRoot, isCancelled, onMessage, isRe
|
|
|
239
269
|
|
|
240
270
|
finalMessage = assistantMsg;
|
|
241
271
|
if (resp.output) finalOutput = resp.output;
|
|
272
|
+
if (resp.rejector_input) rejectorInput = resp.rejector_input;
|
|
242
273
|
|
|
243
274
|
if (done) {
|
|
244
|
-
//
|
|
245
|
-
if (
|
|
275
|
+
// Preserve malformed rejector output for debugging.
|
|
276
|
+
if (isRejectorLoop && resp.parsing_error) {
|
|
246
277
|
const dumpDir = path.join(gitRoot, '.codeant', 'codeSuggestions');
|
|
247
278
|
const dumpFile = path.join(dumpDir, `code_suggestions_${Date.now()}.txt`);
|
|
248
279
|
let dumpContent = resp.response?.content || JSON.stringify(resp, null, 2);
|
|
@@ -289,6 +320,5 @@ async function runTurnLoop(initialPayload, gitRoot, isCancelled, onMessage, isRe
|
|
|
289
320
|
nextPayload = { session_id: sessionId, tool_results: toolResults };
|
|
290
321
|
}
|
|
291
322
|
|
|
292
|
-
return { finalMessage, finalOutput };
|
|
323
|
+
return { finalMessage, finalOutput, rejectorInput };
|
|
293
324
|
}
|
|
294
|
-
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import React, { useEffect } from 'react';
|
|
2
|
+
import { Text, Box, useApp } from 'ink';
|
|
3
|
+
import { setConfigValue, CONFIG_FILE } from '../utils/config.js';
|
|
4
|
+
|
|
5
|
+
export default function SetDashboardUrl({ url }) {
|
|
6
|
+
const { exit } = useApp();
|
|
7
|
+
|
|
8
|
+
useEffect(() => {
|
|
9
|
+
if (!url) {
|
|
10
|
+
exit(new Error('URL is required'));
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
try {
|
|
15
|
+
setConfigValue('dashboardUrl', url);
|
|
16
|
+
exit();
|
|
17
|
+
} catch (err) {
|
|
18
|
+
exit(err);
|
|
19
|
+
}
|
|
20
|
+
}, []);
|
|
21
|
+
|
|
22
|
+
if (!url) {
|
|
23
|
+
return React.createElement(
|
|
24
|
+
Box,
|
|
25
|
+
{ flexDirection: 'column', padding: 1 },
|
|
26
|
+
React.createElement(Text, { color: 'red' }, '✗ Error: URL is required'),
|
|
27
|
+
React.createElement(Text, { color: 'gray' }, 'Usage: codeant set-dashboard-url <url>')
|
|
28
|
+
);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
return React.createElement(
|
|
32
|
+
Box,
|
|
33
|
+
{ flexDirection: 'column', padding: 1 },
|
|
34
|
+
React.createElement(Text, { color: 'green' }, '✓ Dashboard URL set to: ', url),
|
|
35
|
+
React.createElement(Text, { color: 'gray' }, 'Saved to: ', CONFIG_FILE)
|
|
36
|
+
);
|
|
37
|
+
}
|
|
@@ -180,7 +180,7 @@ export function renderFetchingDiff(startTime) {
|
|
|
180
180
|
}
|
|
181
181
|
|
|
182
182
|
export function renderReviewing(currentMessage, startTime, meta) {
|
|
183
|
-
const step = currentMessage?.toLowerCase().includes('
|
|
183
|
+
const step = currentMessage?.toLowerCase().includes('rejector') ? 3 : 2;
|
|
184
184
|
return React.createElement(ReviewLoading, {
|
|
185
185
|
message: currentMessage || 'Analyzing code...',
|
|
186
186
|
step,
|
package/src/index.js
CHANGED
|
@@ -7,6 +7,9 @@ import { createRequire } from 'module';
|
|
|
7
7
|
import Secrets from './commands/secrets.js';
|
|
8
8
|
import SetBaseUrl from './commands/setBaseUrl.js';
|
|
9
9
|
import GetBaseUrl from './commands/getBaseUrl.js';
|
|
10
|
+
import SetDashboardUrl from './commands/setDashboardUrl.js';
|
|
11
|
+
import GetDashboardUrl from './commands/getDashboardUrl.js';
|
|
12
|
+
import RemoveDashboardUrl from './commands/removeDashboardUrl.js';
|
|
10
13
|
import SetApiKey from './commands/setApiKey.js';
|
|
11
14
|
import GetApiKey from './commands/getApiKey.js';
|
|
12
15
|
import Login from './commands/login.js';
|
|
@@ -188,6 +191,27 @@ program
|
|
|
188
191
|
render(React.createElement(GetBaseUrl));
|
|
189
192
|
});
|
|
190
193
|
|
|
194
|
+
program
|
|
195
|
+
.command('set-dashboard-url <url>')
|
|
196
|
+
.description('Set the web app dashboard URL used for login')
|
|
197
|
+
.action((url) => {
|
|
198
|
+
render(React.createElement(SetDashboardUrl, { url }));
|
|
199
|
+
});
|
|
200
|
+
|
|
201
|
+
program
|
|
202
|
+
.command('get-dashboard-url')
|
|
203
|
+
.description('Show the current dashboard URL override')
|
|
204
|
+
.action(() => {
|
|
205
|
+
render(React.createElement(GetDashboardUrl));
|
|
206
|
+
});
|
|
207
|
+
|
|
208
|
+
program
|
|
209
|
+
.command('remove-dashboard-url')
|
|
210
|
+
.description('Remove the dashboard URL override')
|
|
211
|
+
.action(() => {
|
|
212
|
+
render(React.createElement(RemoveDashboardUrl));
|
|
213
|
+
});
|
|
214
|
+
|
|
191
215
|
program
|
|
192
216
|
.command('set-codeant-api-key <key>')
|
|
193
217
|
.description('Set the CodeAnt API key')
|
package/src/reviewHeadless.js
CHANGED
|
@@ -7,12 +7,13 @@ import { track } from './utils/analytics.js';
|
|
|
7
7
|
const MAX_TURNS = 5;
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
|
-
* Run a single agent turn loop (
|
|
10
|
+
* Run a single agent turn loop (planner, generator, or rejector).
|
|
11
11
|
*/
|
|
12
|
-
async function runTurnLoop(initialPayload, gitRoot,
|
|
12
|
+
async function runTurnLoop(initialPayload, gitRoot, isRejectorLoop) {
|
|
13
13
|
let nextPayload = initialPayload;
|
|
14
14
|
let finalMessage = null;
|
|
15
15
|
let finalOutput = null;
|
|
16
|
+
let rejectorInput = null;
|
|
16
17
|
|
|
17
18
|
for (let turn = 0; turn < MAX_TURNS; turn += 1) {
|
|
18
19
|
const resp = await fetchApi('/extension/pr-review/agent/turn', 'POST', nextPayload);
|
|
@@ -31,10 +32,11 @@ async function runTurnLoop(initialPayload, gitRoot, isReflectorLoop) {
|
|
|
31
32
|
|
|
32
33
|
finalMessage = assistantMsg;
|
|
33
34
|
if (resp.output) finalOutput = resp.output;
|
|
35
|
+
if (resp.rejector_input) rejectorInput = resp.rejector_input;
|
|
34
36
|
|
|
35
37
|
if (done) {
|
|
36
|
-
if (
|
|
37
|
-
console.error('Warning: parsing error in
|
|
38
|
+
if (isRejectorLoop && resp.parsing_error) {
|
|
39
|
+
console.error('Warning: parsing error in rejector response');
|
|
38
40
|
}
|
|
39
41
|
break;
|
|
40
42
|
}
|
|
@@ -52,7 +54,7 @@ async function runTurnLoop(initialPayload, gitRoot, isReflectorLoop) {
|
|
|
52
54
|
nextPayload = { session_id: sessionId, tool_results: toolResults };
|
|
53
55
|
}
|
|
54
56
|
|
|
55
|
-
return { finalMessage, finalOutput };
|
|
57
|
+
return { finalMessage, finalOutput, rejectorInput };
|
|
56
58
|
}
|
|
57
59
|
|
|
58
60
|
/**
|
|
@@ -126,29 +128,38 @@ export async function runReviewHeadless(options = {}) {
|
|
|
126
128
|
const perFileRequests = ReviewApiHelper.splitIntoPerFileRequests(requestBody);
|
|
127
129
|
|
|
128
130
|
const totalFiles = perFileRequests.reduce((n, r) => n + (r._filenames?.length || 0), 0);
|
|
131
|
+
let riskHypotheses = '';
|
|
132
|
+
try {
|
|
133
|
+
onProgress(`Planning risks across ${totalFiles} file${totalFiles !== 1 ? 's' : ''}...`);
|
|
134
|
+
const plannerResult = await runTurnLoop(
|
|
135
|
+
{
|
|
136
|
+
diff_content: requestBody.diff_content,
|
|
137
|
+
prompt_template_name: 'risk_planner',
|
|
138
|
+
},
|
|
139
|
+
gitRoot,
|
|
140
|
+
false
|
|
141
|
+
);
|
|
142
|
+
riskHypotheses = plannerResult.finalOutput?.risk_hypotheses || '';
|
|
143
|
+
} catch (err) {
|
|
144
|
+
console.error(`[warning] Risk planner failed; continuing without hypotheses: ${err.message}`);
|
|
145
|
+
}
|
|
129
146
|
onProgress(`Analyzing ${totalFiles} file${totalFiles !== 1 ? 's' : ''}...`);
|
|
130
147
|
|
|
131
148
|
// ── Per-batch agent turn loops (parallel, fault-tolerant) ────────────
|
|
132
|
-
// Each
|
|
133
|
-
// in a single session (matches pragent's FileBatcher).
|
|
149
|
+
// Each review session covers a batch of up to five files.
|
|
134
150
|
const perFileResults = await Promise.all(
|
|
135
151
|
perFileRequests.map(async (fileReq) => {
|
|
136
152
|
const filenames = fileReq._filenames || [];
|
|
137
|
-
|
|
153
|
+
const payload = {
|
|
154
|
+
...fileReq,
|
|
155
|
+
extra_variables: { risk_hypotheses: riskHypotheses },
|
|
156
|
+
};
|
|
157
|
+
delete payload._filenames;
|
|
138
158
|
const label = filenames.join(', ');
|
|
139
159
|
|
|
140
|
-
// Single-file batch: still pass file_content/file_path so backend can
|
|
141
|
-
// build head_file_str. Multi-file batches drop these (head_file_str
|
|
142
|
-
// becomes empty; agent gathers context via tools instead).
|
|
143
|
-
if (filenames.length === 1 && fileReq.file_contents?.[filenames[0]]) {
|
|
144
|
-
fileReq.file_content = fileReq.file_contents[filenames[0]];
|
|
145
|
-
fileReq.file_path = filenames[0];
|
|
146
|
-
}
|
|
147
|
-
delete fileReq.file_contents;
|
|
148
|
-
|
|
149
160
|
try {
|
|
150
161
|
onProgress(`Reviewing ${label}...`);
|
|
151
|
-
const result = await runTurnLoop(
|
|
162
|
+
const result = await runTurnLoop(payload, gitRoot, false);
|
|
152
163
|
onProgress(`Done reviewing ${label}`);
|
|
153
164
|
return result;
|
|
154
165
|
} catch (err) {
|
|
@@ -161,65 +172,59 @@ export async function runReviewHeadless(options = {}) {
|
|
|
161
172
|
// Pair each file's suggestions with its own diff — skip files with no real suggestions
|
|
162
173
|
const perFileWithSuggestions = perFileRequests.map((fileReq, i) => ({
|
|
163
174
|
diff_content: fileReq.diff_content,
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
175
|
+
file_contents: fileReq.file_contents,
|
|
176
|
+
generator_output: perFileResults[i].finalOutput,
|
|
177
|
+
rejector_input: perFileResults[i].rejectorInput,
|
|
178
|
+
})).filter(r => r.generator_output?.code_suggestions?.length > 0);
|
|
167
179
|
|
|
168
180
|
const filesWithSuggestions = new Set(
|
|
169
181
|
perFileWithSuggestions.flatMap(r =>
|
|
170
|
-
(r.
|
|
182
|
+
(r.generator_output?.code_suggestions || []).map(s => (s.relevant_file || '').trim()).filter(Boolean)
|
|
171
183
|
)
|
|
172
184
|
).size;
|
|
173
|
-
onProgress(`${filesWithSuggestions} file${filesWithSuggestions !== 1 ? 's' : ''} have suggestions, running
|
|
185
|
+
onProgress(`${filesWithSuggestions} file${filesWithSuggestions !== 1 ? 's' : ''} have suggestions, running rejector...`);
|
|
174
186
|
|
|
175
|
-
// ── Per-
|
|
176
|
-
const
|
|
177
|
-
perFileWithSuggestions.map(async ({ diff_content,
|
|
187
|
+
// ── Per-batch rejector loops (parallel, fault-tolerant) ──────────────
|
|
188
|
+
const rejectorResults = await Promise.all(
|
|
189
|
+
perFileWithSuggestions.map(async ({ diff_content, file_contents, rejector_input }, i) => {
|
|
178
190
|
try {
|
|
179
191
|
return await runTurnLoop(
|
|
180
192
|
{
|
|
181
193
|
diff_content,
|
|
182
|
-
|
|
183
|
-
|
|
194
|
+
file_contents,
|
|
195
|
+
prompt_template_name: 'rejector',
|
|
196
|
+
extra_variables: rejector_input,
|
|
184
197
|
},
|
|
185
198
|
gitRoot,
|
|
186
199
|
true
|
|
187
200
|
);
|
|
188
201
|
} catch (err) {
|
|
189
|
-
console.error(`[error]
|
|
202
|
+
console.error(`[error] Rejector failed for batch ${i}: ${err.message}`);
|
|
190
203
|
return { finalMessage: null, finalOutput: null };
|
|
191
204
|
}
|
|
192
205
|
})
|
|
193
206
|
);
|
|
194
207
|
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
// Match by summary (pragent's primary strategy): rejector's
|
|
204
|
-
// suggestion_summary (renamed to issue_content server-side) is
|
|
205
|
-
// "Repeated from the input" — i.e. the generator's one_sentence_summary.
|
|
206
|
-
const summary = norm(issue.issue_content);
|
|
207
|
-
if (summary) {
|
|
208
|
-
const exact = genSuggestions.find(g => norm(g.one_sentence_summary) === summary);
|
|
209
|
-
if (norm(exact?.label)) return norm(exact.label);
|
|
208
|
+
const finalizedResults = await Promise.all(
|
|
209
|
+
rejectorResults.map((result, i) => fetchApi(
|
|
210
|
+
'/extension/pr-review/agent/finalize',
|
|
211
|
+
'POST',
|
|
212
|
+
{
|
|
213
|
+
diff_content: perFileWithSuggestions[i].diff_content,
|
|
214
|
+
generator_output: perFileWithSuggestions[i].generator_output,
|
|
215
|
+
rejector_output: result.finalOutput || { code_suggestions: [] },
|
|
210
216
|
}
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
issue_content: issue.issue_content || '',
|
|
217
|
+
))
|
|
218
|
+
);
|
|
219
|
+
|
|
220
|
+
const issues = finalizedResults.flatMap(r =>
|
|
221
|
+
(r.output?.code_suggestions || []).map(issue => ({
|
|
222
|
+
issue_content: issue.suggestion_content || issue.one_sentence_summary || '',
|
|
218
223
|
relevant_file: issue.relevant_file || 'Unknown',
|
|
219
|
-
start_line: issue.
|
|
220
|
-
label:
|
|
221
|
-
}))
|
|
222
|
-
|
|
224
|
+
start_line: issue.relevant_lines_start || 0,
|
|
225
|
+
label: issue.label || 'Code Quality',
|
|
226
|
+
}))
|
|
227
|
+
);
|
|
223
228
|
|
|
224
229
|
const labelCounts = {};
|
|
225
230
|
for (const i of issues) { labelCounts[i.label] = (labelCounts[i.label] || 0) + 1; }
|
package/src/utils/baseUrl.js
CHANGED
|
@@ -2,6 +2,11 @@ import { getConfigValue } from './config.js';
|
|
|
2
2
|
|
|
3
3
|
//
|
|
4
4
|
const NEW_BASE_URL = 'https://service.codeant.ai';
|
|
5
|
+
const DEFAULT_BASE_URLS = new Set([
|
|
6
|
+
'https://service.codeant.ai',
|
|
7
|
+
'https://api.codeant.ai',
|
|
8
|
+
'https://dev-api.codeant.ai',
|
|
9
|
+
]);
|
|
5
10
|
|
|
6
11
|
const getBaseUrl = () => {
|
|
7
12
|
const url = process.env.CODEANT_API_URL || getConfigValue('baseUrl') || NEW_BASE_URL;
|
|
@@ -9,15 +14,34 @@ const getBaseUrl = () => {
|
|
|
9
14
|
return url;
|
|
10
15
|
};
|
|
11
16
|
|
|
17
|
+
const isDefaultBaseUrl = () => {
|
|
18
|
+
const configuredUrl = process.env.CODEANT_API_URL || getConfigValue('baseUrl');
|
|
19
|
+
return !configuredUrl || DEFAULT_BASE_URLS.has(configuredUrl);
|
|
20
|
+
};
|
|
21
|
+
|
|
12
22
|
const getDashboardUrl = async () => {
|
|
23
|
+
const override = process.env.CODEANT_DASHBOARD_URL || getConfigValue('dashboardUrl');
|
|
24
|
+
if (override) return override;
|
|
25
|
+
|
|
26
|
+
const usingDefaultBaseUrl = isDefaultBaseUrl();
|
|
27
|
+
|
|
13
28
|
try {
|
|
14
29
|
const response = await fetch(`${getBaseUrl()}/extension/get/dashboard`);
|
|
15
|
-
// console.log('Fetching dashboard URL from:', `${getBaseUrl()}/extension/get/dashboard`);
|
|
16
30
|
const data = await response.json();
|
|
17
|
-
|
|
31
|
+
// On a custom base URL, never silently trust an auto-detected app.codeant.ai —
|
|
32
|
+
// that's the SaaS dashboard, and a self-hosted instance's OAuth apps won't
|
|
33
|
+
// recognize it as a valid redirect target. Require an explicit override instead.
|
|
34
|
+
if (data.dashboard_url && (usingDefaultBaseUrl || data.dashboard_url !== 'https://app.codeant.ai')) {
|
|
35
|
+
return data.dashboard_url;
|
|
36
|
+
}
|
|
18
37
|
} catch {
|
|
19
|
-
|
|
38
|
+
// fall through to the error below
|
|
20
39
|
}
|
|
40
|
+
|
|
41
|
+
throw new Error(
|
|
42
|
+
`Could not determine the dashboard URL for base URL "${getBaseUrl()}". ` +
|
|
43
|
+
`Set it explicitly with: codeant set-dashboard-url <your web app URL>`
|
|
44
|
+
);
|
|
21
45
|
};
|
|
22
46
|
|
|
23
47
|
export { getBaseUrl, getDashboardUrl };
|
|
@@ -266,8 +266,8 @@ class ReviewApiHelper extends CommonApiHelper {
|
|
|
266
266
|
|
|
267
267
|
/**
|
|
268
268
|
* Split a combined review request into batched payloads.
|
|
269
|
-
* Files are grouped in chunks of up to FILES_PER_BATCH so each
|
|
270
|
-
* session
|
|
269
|
+
* Files are grouped in chunks of up to FILES_PER_BATCH so each review
|
|
270
|
+
* session can process multiple files together.
|
|
271
271
|
*/
|
|
272
272
|
static splitIntoPerFileRequests(requestBody, batchSize = 5) {
|
|
273
273
|
if (!requestBody?.diff_content?.length) return [];
|
|
@@ -280,6 +280,7 @@ class ReviewApiHelper extends CommonApiHelper {
|
|
|
280
280
|
if (!nameMatch) continue;
|
|
281
281
|
perFile.push({ section, filename: nameMatch[1] });
|
|
282
282
|
}
|
|
283
|
+
perFile.sort((a, b) => (a.filename < b.filename ? -1 : a.filename > b.filename ? 1 : 0));
|
|
283
284
|
|
|
284
285
|
const batches = [];
|
|
285
286
|
for (let i = 0; i < perFile.length; i += batchSize) {
|