aico-ai 1.0.13 → 1.0.15
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/index.js +43 -5
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -10,6 +10,28 @@ const { prompt } = enquirer;
|
|
|
10
10
|
import { saveGlobalConfig } from './lib/config-utils.js';
|
|
11
11
|
import { execSync } from 'child_process';
|
|
12
12
|
|
|
13
|
+
// Spinner utility
|
|
14
|
+
let spinnerInterval;
|
|
15
|
+
const spinnerFrames = ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏'];
|
|
16
|
+
let frameIndex = 0;
|
|
17
|
+
|
|
18
|
+
function startSpinner(text) {
|
|
19
|
+
frameIndex = 0;
|
|
20
|
+
process.stdout.write('\x1B[?25l'); // Hide cursor
|
|
21
|
+
spinnerInterval = setInterval(() => {
|
|
22
|
+
process.stdout.write(`\r${pc.cyan(spinnerFrames[frameIndex++ % spinnerFrames.length])} ${text}`);
|
|
23
|
+
}, 80);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function stopSpinner() {
|
|
27
|
+
if (spinnerInterval) {
|
|
28
|
+
clearInterval(spinnerInterval);
|
|
29
|
+
spinnerInterval = null;
|
|
30
|
+
process.stdout.write('\r\x1b[K'); // Clear line
|
|
31
|
+
process.stdout.write('\x1B[?25h'); // Show cursor
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
13
35
|
async function init() {
|
|
14
36
|
console.log(pc.bold(pc.blue('Aico: Initializing...')));
|
|
15
37
|
|
|
@@ -76,6 +98,13 @@ async function init() {
|
|
|
76
98
|
try {
|
|
77
99
|
console.log(pc.blue('Setting up Husky...'));
|
|
78
100
|
execSync('npx husky init', { stdio: 'inherit' });
|
|
101
|
+
|
|
102
|
+
// Remove the default pre-commit hook that runs "npm test"
|
|
103
|
+
const preCommitPath = '.husky/pre-commit';
|
|
104
|
+
if (fs.existsSync(preCommitPath)) {
|
|
105
|
+
fs.unlinkSync(preCommitPath);
|
|
106
|
+
}
|
|
107
|
+
|
|
79
108
|
// Add aico to pre-push
|
|
80
109
|
const huskyPath = '.husky/pre-push';
|
|
81
110
|
const hookContent = '#!/bin/sh\naico review\n';
|
|
@@ -139,7 +168,6 @@ async function main() {
|
|
|
139
168
|
}
|
|
140
169
|
|
|
141
170
|
if (command === 'commit') {
|
|
142
|
-
console.log(pc.bold(pc.blue('Aico: Generating commit message...')));
|
|
143
171
|
try {
|
|
144
172
|
const diff = await getStagedDiff();
|
|
145
173
|
if (!diff || diff.trim() === '') {
|
|
@@ -149,10 +177,13 @@ async function main() {
|
|
|
149
177
|
|
|
150
178
|
// For commit messages, we use a truncated diff if it's too large to save tokens
|
|
151
179
|
const commitDiff = diff.length > 20000 ? diff.substring(0, 20000) + '\n... [Diff truncated for summary] ...' : diff;
|
|
180
|
+
|
|
181
|
+
startSpinner('Generating commit message...');
|
|
152
182
|
let message = await generateCommitMessage(commitDiff);
|
|
183
|
+
stopSpinner();
|
|
153
184
|
|
|
154
185
|
while (true) {
|
|
155
|
-
console.log(
|
|
186
|
+
console.log(`${pc.bold('Suggested message:')} ${pc.green(message)}`);
|
|
156
187
|
|
|
157
188
|
const { action } = await prompt({
|
|
158
189
|
type: 'select',
|
|
@@ -187,6 +218,7 @@ async function main() {
|
|
|
187
218
|
}
|
|
188
219
|
}
|
|
189
220
|
} catch (error) {
|
|
221
|
+
stopSpinner();
|
|
190
222
|
console.error(pc.red('Error during commit:'), error.message);
|
|
191
223
|
process.exit(1);
|
|
192
224
|
}
|
|
@@ -206,12 +238,16 @@ async function main() {
|
|
|
206
238
|
const allIssues = [];
|
|
207
239
|
|
|
208
240
|
for (let i = 0; i < chunks.length; i++) {
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
241
|
+
const statusText = chunks.length > 1
|
|
242
|
+
? `Analyzing changes (Chunk ${i + 1}/${chunks.length})...`
|
|
243
|
+
: 'Analyzing your changes...';
|
|
244
|
+
|
|
245
|
+
startSpinner(statusText);
|
|
212
246
|
|
|
213
247
|
try {
|
|
214
248
|
const aiResponse = await reviewCode(chunks[i]);
|
|
249
|
+
stopSpinner();
|
|
250
|
+
|
|
215
251
|
const chunkIssues = parseAIResponse(aiResponse);
|
|
216
252
|
allIssues.push(...chunkIssues);
|
|
217
253
|
|
|
@@ -220,6 +256,7 @@ async function main() {
|
|
|
220
256
|
await new Promise(resolve => setTimeout(resolve, 1000));
|
|
221
257
|
}
|
|
222
258
|
} catch (error) {
|
|
259
|
+
stopSpinner();
|
|
223
260
|
console.error(pc.red(`\nError during chunk ${i + 1} review:`), error.message);
|
|
224
261
|
if (chunks.length === 1) throw error; // Re-throw if it's the only chunk
|
|
225
262
|
}
|
|
@@ -283,6 +320,7 @@ async function main() {
|
|
|
283
320
|
|
|
284
321
|
console.log(pc.green('Proceeding with push...'));
|
|
285
322
|
} catch (error) {
|
|
323
|
+
stopSpinner();
|
|
286
324
|
console.error(pc.red('Error during review:'), error.message);
|
|
287
325
|
process.exit(1);
|
|
288
326
|
}
|