@nclamvn/vibecode-cli 1.1.0 → 1.3.0
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/bin/vibecode.js +17 -0
- package/package.json +1 -1
- package/src/commands/build.js +496 -3
- package/src/commands/config.js +149 -0
- package/src/commands/plan.js +8 -2
- package/src/config/constants.js +1 -1
- package/src/config/templates.js +146 -15
- package/src/core/error-analyzer.js +237 -0
- package/src/core/fix-generator.js +195 -0
- package/src/core/iteration.js +226 -0
- package/src/core/session.js +18 -2
- package/src/core/test-runner.js +248 -0
- package/src/index.js +7 -0
- package/src/providers/claude-code.js +164 -0
- package/src/providers/index.js +45 -0
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
// ═══════════════════════════════════════════════════════════════════════════════
|
|
2
|
+
// VIBECODE CLI - Config Command
|
|
3
|
+
// ═══════════════════════════════════════════════════════════════════════════════
|
|
4
|
+
|
|
5
|
+
import chalk from 'chalk';
|
|
6
|
+
import path from 'path';
|
|
7
|
+
import { workspaceExists, getWorkspacePath } from '../core/workspace.js';
|
|
8
|
+
import { pathExists, readJson, writeJson } from '../utils/files.js';
|
|
9
|
+
import { PROVIDERS, getDefaultProvider } from '../providers/index.js';
|
|
10
|
+
import { printBox, printError, printSuccess, printInfo } from '../ui/output.js';
|
|
11
|
+
|
|
12
|
+
const CONFIG_FILE = 'config.json';
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Get config file path
|
|
16
|
+
*/
|
|
17
|
+
function getConfigPath() {
|
|
18
|
+
return path.join(getWorkspacePath(), CONFIG_FILE);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Load config
|
|
23
|
+
*/
|
|
24
|
+
async function loadConfig() {
|
|
25
|
+
const configPath = getConfigPath();
|
|
26
|
+
if (await pathExists(configPath)) {
|
|
27
|
+
return await readJson(configPath);
|
|
28
|
+
}
|
|
29
|
+
return getDefaultConfig();
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Save config
|
|
34
|
+
*/
|
|
35
|
+
async function saveConfig(config) {
|
|
36
|
+
const configPath = getConfigPath();
|
|
37
|
+
await writeJson(configPath, config);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Get default config
|
|
42
|
+
*/
|
|
43
|
+
function getDefaultConfig() {
|
|
44
|
+
return {
|
|
45
|
+
provider: 'claude-code',
|
|
46
|
+
claudeCode: {
|
|
47
|
+
flags: ['--dangerously-skip-permissions'],
|
|
48
|
+
timeout: 30 // minutes
|
|
49
|
+
},
|
|
50
|
+
autoEvidence: true,
|
|
51
|
+
verbose: false
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export async function configCommand(options = {}) {
|
|
56
|
+
try {
|
|
57
|
+
// Check workspace for set operations
|
|
58
|
+
if (options.provider || options.set) {
|
|
59
|
+
if (!await workspaceExists()) {
|
|
60
|
+
printError('No Vibecode workspace found. Run `vibecode init` first.');
|
|
61
|
+
process.exit(1);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// Show current config
|
|
66
|
+
if (options.show || (!options.provider && !options.set)) {
|
|
67
|
+
await showConfig();
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// Set provider
|
|
72
|
+
if (options.provider) {
|
|
73
|
+
await setProvider(options.provider);
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
} catch (error) {
|
|
78
|
+
printError(error.message);
|
|
79
|
+
process.exit(1);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
async function showConfig() {
|
|
84
|
+
console.log();
|
|
85
|
+
|
|
86
|
+
// Check if workspace exists
|
|
87
|
+
if (!await workspaceExists()) {
|
|
88
|
+
// Show default config
|
|
89
|
+
console.log(chalk.cyan('Default Configuration (no workspace):'));
|
|
90
|
+
console.log();
|
|
91
|
+
const defaultConfig = getDefaultConfig();
|
|
92
|
+
console.log(chalk.gray('Provider: ') + chalk.white(defaultConfig.provider));
|
|
93
|
+
console.log(chalk.gray('Flags: ') + chalk.white(defaultConfig.claudeCode.flags.join(', ')));
|
|
94
|
+
console.log(chalk.gray('Timeout: ') + chalk.white(`${defaultConfig.claudeCode.timeout} minutes`));
|
|
95
|
+
console.log();
|
|
96
|
+
console.log(chalk.gray('Run `vibecode init` to create a workspace.'));
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
const config = await loadConfig();
|
|
101
|
+
|
|
102
|
+
const content = `Current Configuration
|
|
103
|
+
|
|
104
|
+
Provider: ${config.provider}
|
|
105
|
+
Flags: ${config.claudeCode?.flags?.join(', ') || 'none'}
|
|
106
|
+
Timeout: ${config.claudeCode?.timeout || 30} minutes
|
|
107
|
+
Auto Evidence: ${config.autoEvidence ? 'enabled' : 'disabled'}
|
|
108
|
+
Verbose: ${config.verbose ? 'enabled' : 'disabled'}`;
|
|
109
|
+
|
|
110
|
+
printBox(content, { borderColor: 'cyan' });
|
|
111
|
+
|
|
112
|
+
// Show available providers
|
|
113
|
+
console.log();
|
|
114
|
+
console.log(chalk.cyan('Available Providers:'));
|
|
115
|
+
Object.entries(PROVIDERS).forEach(([key, provider]) => {
|
|
116
|
+
const status = provider.available ? chalk.green('available') : chalk.gray('coming soon');
|
|
117
|
+
const current = key === config.provider ? chalk.yellow(' (current)') : '';
|
|
118
|
+
console.log(chalk.gray(` • ${key}: ${provider.description} [${status}]${current}`));
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
console.log();
|
|
122
|
+
console.log(chalk.gray('To change: vibecode config --provider <name>'));
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
async function setProvider(providerName) {
|
|
126
|
+
// Validate provider
|
|
127
|
+
if (!PROVIDERS[providerName]) {
|
|
128
|
+
printError(`Unknown provider: ${providerName}`);
|
|
129
|
+
console.log();
|
|
130
|
+
console.log(chalk.cyan('Available providers:'));
|
|
131
|
+
Object.keys(PROVIDERS).forEach(key => {
|
|
132
|
+
console.log(chalk.gray(` • ${key}`));
|
|
133
|
+
});
|
|
134
|
+
process.exit(1);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
if (!PROVIDERS[providerName].available) {
|
|
138
|
+
printError(`Provider "${providerName}" is not yet available.`);
|
|
139
|
+
process.exit(1);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
// Load and update config
|
|
143
|
+
const config = await loadConfig();
|
|
144
|
+
config.provider = providerName;
|
|
145
|
+
await saveConfig(config);
|
|
146
|
+
|
|
147
|
+
printSuccess(`Provider set to: ${providerName}`);
|
|
148
|
+
console.log(chalk.gray(`Config saved to: ${getConfigPath()}`));
|
|
149
|
+
}
|
package/src/commands/plan.js
CHANGED
|
@@ -45,7 +45,7 @@ export async function planCommand(options = {}) {
|
|
|
45
45
|
const sessionPath = await getCurrentSessionPath();
|
|
46
46
|
const specHash = await getSpecHash();
|
|
47
47
|
|
|
48
|
-
// Read contract and
|
|
48
|
+
// Read contract, blueprint, and intake
|
|
49
49
|
spinner.text = 'Reading contract...';
|
|
50
50
|
const contractContent = await readSessionFile('contract.md');
|
|
51
51
|
|
|
@@ -54,6 +54,11 @@ export async function planCommand(options = {}) {
|
|
|
54
54
|
blueprintContent = await readSessionFile('blueprint.md');
|
|
55
55
|
}
|
|
56
56
|
|
|
57
|
+
let intakeContent = '';
|
|
58
|
+
if (await sessionFileExists('intake.md')) {
|
|
59
|
+
intakeContent = await readSessionFile('intake.md');
|
|
60
|
+
}
|
|
61
|
+
|
|
57
62
|
// Generate plan
|
|
58
63
|
spinner.text = 'Generating plan...';
|
|
59
64
|
const planContent = getPlanTemplate(projectName, sessionId, specHash, contractContent);
|
|
@@ -66,7 +71,8 @@ export async function planCommand(options = {}) {
|
|
|
66
71
|
sessionId,
|
|
67
72
|
specHash,
|
|
68
73
|
contractContent,
|
|
69
|
-
blueprintContent
|
|
74
|
+
blueprintContent,
|
|
75
|
+
intakeContent
|
|
70
76
|
);
|
|
71
77
|
await writeSessionFile('coder_pack.md', coderPackContent);
|
|
72
78
|
|
package/src/config/constants.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
// Spec Hash: 0fe43335f5a325e3279a079ce616c052
|
|
4
4
|
// ═══════════════════════════════════════════════════════════════════════════════
|
|
5
5
|
|
|
6
|
-
export const VERSION = '1.1
|
|
6
|
+
export const VERSION = '1.0.1';
|
|
7
7
|
export const SPEC_HASH = '0fe43335f5a325e3279a079ce616c052';
|
|
8
8
|
|
|
9
9
|
// ─────────────────────────────────────────────────────────────────────────────
|
package/src/config/templates.js
CHANGED
|
@@ -124,11 +124,39 @@ src/
|
|
|
124
124
|
}
|
|
125
125
|
|
|
126
126
|
/**
|
|
127
|
-
* Get contract template
|
|
127
|
+
* Get contract template with content extracted from intake and blueprint
|
|
128
128
|
*/
|
|
129
|
-
export function getContractTemplate(projectName, sessionId) {
|
|
129
|
+
export function getContractTemplate(projectName, sessionId, intakeContent = '', blueprintContent = '') {
|
|
130
130
|
const timestamp = new Date().toISOString();
|
|
131
131
|
|
|
132
|
+
// Extract goal from intake (look for "Mô tả dự án" section)
|
|
133
|
+
let goal = extractSection(intakeContent, '## 🎯 Mô tả dự án', '---') ||
|
|
134
|
+
extractSection(intakeContent, '## Mô tả dự án', '---') ||
|
|
135
|
+
'[Define your clear, specific goal here]';
|
|
136
|
+
|
|
137
|
+
// Extract tech stack from blueprint
|
|
138
|
+
let techStack = extractSection(blueprintContent, '## 💻 Tech Stack', '---') || '';
|
|
139
|
+
|
|
140
|
+
// Extract architecture from blueprint
|
|
141
|
+
let architecture = extractSection(blueprintContent, '## 📐 Architecture', '---') || '';
|
|
142
|
+
|
|
143
|
+
// Extract file structure from blueprint
|
|
144
|
+
let fileStructure = extractSection(blueprintContent, '## 📁 File Structure', '---') || '';
|
|
145
|
+
|
|
146
|
+
// Generate deliverables from goal and architecture
|
|
147
|
+
const deliverables = generateDeliverablesFromContent(goal, techStack, architecture);
|
|
148
|
+
|
|
149
|
+
// Generate acceptance criteria from deliverables
|
|
150
|
+
const acceptanceCriteria = generateAcceptanceCriteria(deliverables);
|
|
151
|
+
|
|
152
|
+
// Generate in-scope items
|
|
153
|
+
const inScopeItems = deliverables.map(d => `- [ ] ${d.item}`).join('\n');
|
|
154
|
+
|
|
155
|
+
// Generate deliverables table
|
|
156
|
+
const deliverablesTable = deliverables.map((d, i) =>
|
|
157
|
+
`| ${i + 1} | ${d.item} | ${d.description} | ⬜ |`
|
|
158
|
+
).join('\n');
|
|
159
|
+
|
|
132
160
|
return `# 📜 CONTRACT: ${projectName}
|
|
133
161
|
|
|
134
162
|
## Session: ${sessionId}
|
|
@@ -140,22 +168,21 @@ export function getContractTemplate(projectName, sessionId) {
|
|
|
140
168
|
|
|
141
169
|
## 🎯 Goal
|
|
142
170
|
|
|
143
|
-
|
|
171
|
+
${goal.trim()}
|
|
144
172
|
|
|
145
173
|
---
|
|
146
174
|
|
|
147
175
|
## ✅ In-Scope
|
|
148
176
|
|
|
149
|
-
- [ ] [Deliverable 1]
|
|
150
|
-
- [ ] [Deliverable 2]
|
|
151
|
-
- [ ] [Deliverable 3]
|
|
177
|
+
${inScopeItems || '- [ ] [Deliverable 1]\n- [ ] [Deliverable 2]\n- [ ] [Deliverable 3]'}
|
|
152
178
|
|
|
153
179
|
---
|
|
154
180
|
|
|
155
181
|
## ❌ Out-of-Scope
|
|
156
182
|
|
|
157
|
-
-
|
|
158
|
-
-
|
|
183
|
+
- Features not mentioned in goal
|
|
184
|
+
- Additional integrations not specified
|
|
185
|
+
- Performance optimization beyond MVP
|
|
159
186
|
|
|
160
187
|
---
|
|
161
188
|
|
|
@@ -163,14 +190,13 @@ export function getContractTemplate(projectName, sessionId) {
|
|
|
163
190
|
|
|
164
191
|
| # | Item | Description | Status |
|
|
165
192
|
|---|------|-------------|--------|
|
|
166
|
-
| 1 | [Item] | [Description] | ⬜ |
|
|
193
|
+
${deliverablesTable || '| 1 | [Item] | [Description] | ⬜ |'}
|
|
167
194
|
|
|
168
195
|
---
|
|
169
196
|
|
|
170
197
|
## ✔️ Acceptance Criteria
|
|
171
198
|
|
|
172
|
-
- [ ] [Criterion 1]
|
|
173
|
-
- [ ] [Criterion 2]
|
|
199
|
+
${acceptanceCriteria || '- [ ] [Criterion 1]\n- [ ] [Criterion 2]'}
|
|
174
200
|
|
|
175
201
|
---
|
|
176
202
|
|
|
@@ -178,13 +204,17 @@ export function getContractTemplate(projectName, sessionId) {
|
|
|
178
204
|
|
|
179
205
|
| Risk | Mitigation |
|
|
180
206
|
|------|------------|
|
|
181
|
-
|
|
|
207
|
+
| Dependencies unavailable | Use alternative packages |
|
|
208
|
+
| Scope creep | Strict contract adherence |
|
|
182
209
|
|
|
183
210
|
---
|
|
184
211
|
|
|
185
212
|
## 🔙 Rollback Plan
|
|
186
213
|
|
|
187
|
-
|
|
214
|
+
If build fails:
|
|
215
|
+
1. Revert to last stable commit
|
|
216
|
+
2. Review contract requirements
|
|
217
|
+
3. Rebuild with corrections
|
|
188
218
|
|
|
189
219
|
---
|
|
190
220
|
|
|
@@ -193,6 +223,91 @@ export function getContractTemplate(projectName, sessionId) {
|
|
|
193
223
|
`;
|
|
194
224
|
}
|
|
195
225
|
|
|
226
|
+
/**
|
|
227
|
+
* Extract a section from markdown content
|
|
228
|
+
*/
|
|
229
|
+
function extractSection(content, startMarker, endMarker) {
|
|
230
|
+
if (!content) return null;
|
|
231
|
+
|
|
232
|
+
const startIndex = content.indexOf(startMarker);
|
|
233
|
+
if (startIndex === -1) return null;
|
|
234
|
+
|
|
235
|
+
const contentStart = startIndex + startMarker.length;
|
|
236
|
+
const endIndex = content.indexOf(endMarker, contentStart);
|
|
237
|
+
|
|
238
|
+
if (endIndex === -1) {
|
|
239
|
+
return content.substring(contentStart).trim();
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
return content.substring(contentStart, endIndex).trim();
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
/**
|
|
246
|
+
* Generate deliverables from content analysis
|
|
247
|
+
*/
|
|
248
|
+
function generateDeliverablesFromContent(goal, techStack, architecture) {
|
|
249
|
+
const deliverables = [];
|
|
250
|
+
|
|
251
|
+
// Parse goal for keywords to generate deliverables
|
|
252
|
+
const goalLower = goal.toLowerCase();
|
|
253
|
+
|
|
254
|
+
// Common patterns
|
|
255
|
+
if (goalLower.includes('landing page') || goalLower.includes('website')) {
|
|
256
|
+
deliverables.push({ item: 'Landing Page', description: 'Main landing page with hero section' });
|
|
257
|
+
deliverables.push({ item: 'Responsive Design', description: 'Mobile-friendly layout' });
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
if (goalLower.includes('cli') || goalLower.includes('command')) {
|
|
261
|
+
deliverables.push({ item: 'CLI Commands', description: 'Core command implementations' });
|
|
262
|
+
deliverables.push({ item: 'Help System', description: 'Command help and documentation' });
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
if (goalLower.includes('api') || goalLower.includes('backend')) {
|
|
266
|
+
deliverables.push({ item: 'API Endpoints', description: 'REST/GraphQL endpoints' });
|
|
267
|
+
deliverables.push({ item: 'Data Models', description: 'Database models and schemas' });
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
if (goalLower.includes('auth') || goalLower.includes('login')) {
|
|
271
|
+
deliverables.push({ item: 'Authentication', description: 'User login/logout flow' });
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
if (goalLower.includes('dashboard') || goalLower.includes('admin')) {
|
|
275
|
+
deliverables.push({ item: 'Dashboard UI', description: 'Admin dashboard interface' });
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
// Always include core deliverables if none detected
|
|
279
|
+
if (deliverables.length === 0) {
|
|
280
|
+
deliverables.push({ item: 'Core Implementation', description: 'Main functionality as described' });
|
|
281
|
+
deliverables.push({ item: 'UI/UX', description: 'User interface implementation' });
|
|
282
|
+
deliverables.push({ item: 'Documentation', description: 'Usage documentation' });
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
// Add testing if not already included
|
|
286
|
+
if (!deliverables.some(d => d.item.toLowerCase().includes('test'))) {
|
|
287
|
+
deliverables.push({ item: 'Testing', description: 'Basic functionality tests' });
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
return deliverables;
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
/**
|
|
294
|
+
* Generate acceptance criteria from deliverables
|
|
295
|
+
*/
|
|
296
|
+
function generateAcceptanceCriteria(deliverables) {
|
|
297
|
+
if (!deliverables || deliverables.length === 0) {
|
|
298
|
+
return '- [ ] All features work as expected\n- [ ] No console errors\n- [ ] Documentation complete';
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
const criteria = deliverables.map(d =>
|
|
302
|
+
`- [ ] ${d.item} is complete and functional`
|
|
303
|
+
);
|
|
304
|
+
|
|
305
|
+
criteria.push('- [ ] No console errors or warnings');
|
|
306
|
+
criteria.push('- [ ] Code is clean and documented');
|
|
307
|
+
|
|
308
|
+
return criteria.join('\n');
|
|
309
|
+
}
|
|
310
|
+
|
|
196
311
|
/**
|
|
197
312
|
* Get plan template
|
|
198
313
|
*/
|
|
@@ -260,9 +375,13 @@ ${deliverables}
|
|
|
260
375
|
/**
|
|
261
376
|
* Get coder pack template - instructions for AI coder
|
|
262
377
|
*/
|
|
263
|
-
export function getCoderPackTemplate(projectName, sessionId, specHash, contractContent, blueprintContent) {
|
|
378
|
+
export function getCoderPackTemplate(projectName, sessionId, specHash, contractContent, blueprintContent, intakeContent = '') {
|
|
264
379
|
const timestamp = new Date().toISOString();
|
|
265
380
|
|
|
381
|
+
// Extract the goal from intake for quick reference
|
|
382
|
+
const goalMatch = intakeContent.match(/## 🎯 Mô tả dự án\s*([\s\S]*?)(?=---|##|$)/);
|
|
383
|
+
const projectGoal = goalMatch ? goalMatch[1].trim() : 'See contract for details';
|
|
384
|
+
|
|
266
385
|
return `# 🏗️ CODER PACK: ${projectName}
|
|
267
386
|
|
|
268
387
|
## Session: ${sessionId}
|
|
@@ -283,6 +402,12 @@ You are the **Thợ (Builder)**. Your job is to execute the locked contract exac
|
|
|
283
402
|
|
|
284
403
|
---
|
|
285
404
|
|
|
405
|
+
## 🎯 PROJECT GOAL (Quick Reference)
|
|
406
|
+
|
|
407
|
+
${projectGoal}
|
|
408
|
+
|
|
409
|
+
---
|
|
410
|
+
|
|
286
411
|
## 📜 CONTRACT (LOCKED)
|
|
287
412
|
|
|
288
413
|
${contractContent}
|
|
@@ -291,7 +416,13 @@ ${contractContent}
|
|
|
291
416
|
|
|
292
417
|
## 📘 BLUEPRINT REFERENCE
|
|
293
418
|
|
|
294
|
-
${blueprintContent}
|
|
419
|
+
${blueprintContent || '[No blueprint provided - follow contract specifications]'}
|
|
420
|
+
|
|
421
|
+
---
|
|
422
|
+
|
|
423
|
+
## 📥 ORIGINAL INTAKE
|
|
424
|
+
|
|
425
|
+
${intakeContent || '[No intake provided]'}
|
|
295
426
|
|
|
296
427
|
---
|
|
297
428
|
|
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
// ═══════════════════════════════════════════════════════════════════════════════
|
|
2
|
+
// VIBECODE CLI - Error Analyzer
|
|
3
|
+
// Intelligent error analysis for iterative builds
|
|
4
|
+
// ═══════════════════════════════════════════════════════════════════════════════
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Analyze test results and extract actionable errors
|
|
8
|
+
* @param {TestResults} testResult - Results from test runner
|
|
9
|
+
* @returns {AnalyzedError[]}
|
|
10
|
+
*/
|
|
11
|
+
export function analyzeErrors(testResult) {
|
|
12
|
+
const errors = [];
|
|
13
|
+
|
|
14
|
+
for (const test of testResult.tests) {
|
|
15
|
+
if (!test.passed) {
|
|
16
|
+
const testErrors = test.errors || [];
|
|
17
|
+
|
|
18
|
+
for (const error of testErrors) {
|
|
19
|
+
errors.push({
|
|
20
|
+
source: test.name,
|
|
21
|
+
type: categorizeError(error),
|
|
22
|
+
file: error.file || null,
|
|
23
|
+
line: error.line || null,
|
|
24
|
+
column: error.column || null,
|
|
25
|
+
message: error.message,
|
|
26
|
+
suggestion: generateSuggestion(error),
|
|
27
|
+
priority: calculatePriority(error),
|
|
28
|
+
raw: error.raw
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// If no specific errors but test failed, add generic error
|
|
33
|
+
if (testErrors.length === 0) {
|
|
34
|
+
errors.push({
|
|
35
|
+
source: test.name,
|
|
36
|
+
type: 'unknown',
|
|
37
|
+
message: test.error || `${test.name} failed`,
|
|
38
|
+
suggestion: `Check ${test.name} output for details`,
|
|
39
|
+
priority: 'medium',
|
|
40
|
+
raw: test.output
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// Sort by priority
|
|
47
|
+
return errors.sort((a, b) => {
|
|
48
|
+
const priorityOrder = { critical: 0, high: 1, medium: 2, low: 3 };
|
|
49
|
+
return (priorityOrder[a.priority] || 2) - (priorityOrder[b.priority] || 2);
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Categorize error type
|
|
55
|
+
*/
|
|
56
|
+
function categorizeError(error) {
|
|
57
|
+
const message = (error.message || '').toLowerCase();
|
|
58
|
+
const raw = (error.raw || '').toLowerCase();
|
|
59
|
+
const combined = message + ' ' + raw;
|
|
60
|
+
|
|
61
|
+
if (combined.includes('syntaxerror') || combined.includes('unexpected token')) {
|
|
62
|
+
return 'syntax';
|
|
63
|
+
}
|
|
64
|
+
if (combined.includes('typeerror') || combined.includes('type error') || combined.includes('is not a function')) {
|
|
65
|
+
return 'type';
|
|
66
|
+
}
|
|
67
|
+
if (combined.includes('referenceerror') || combined.includes('is not defined')) {
|
|
68
|
+
return 'reference';
|
|
69
|
+
}
|
|
70
|
+
if (combined.includes('import') || combined.includes('require') || combined.includes('module not found')) {
|
|
71
|
+
return 'import';
|
|
72
|
+
}
|
|
73
|
+
if (combined.includes('eslint') || combined.includes('lint')) {
|
|
74
|
+
return 'lint';
|
|
75
|
+
}
|
|
76
|
+
if (combined.includes('test') || combined.includes('expect') || combined.includes('assert')) {
|
|
77
|
+
return 'test';
|
|
78
|
+
}
|
|
79
|
+
if (combined.includes('typescript') || combined.includes('ts(')) {
|
|
80
|
+
return 'typescript';
|
|
81
|
+
}
|
|
82
|
+
if (combined.includes('build') || combined.includes('compile')) {
|
|
83
|
+
return 'build';
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
return 'unknown';
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Generate fix suggestion based on error type
|
|
91
|
+
*/
|
|
92
|
+
function generateSuggestion(error) {
|
|
93
|
+
const type = categorizeError(error);
|
|
94
|
+
const message = error.message || '';
|
|
95
|
+
|
|
96
|
+
switch (type) {
|
|
97
|
+
case 'syntax':
|
|
98
|
+
return 'Check for missing brackets, semicolons, or typos near the error location';
|
|
99
|
+
|
|
100
|
+
case 'type':
|
|
101
|
+
if (message.includes('undefined')) {
|
|
102
|
+
return 'Check if the variable/property is properly initialized';
|
|
103
|
+
}
|
|
104
|
+
if (message.includes('is not a function')) {
|
|
105
|
+
return 'Verify the function exists and is properly imported';
|
|
106
|
+
}
|
|
107
|
+
return 'Check type compatibility and ensure proper type handling';
|
|
108
|
+
|
|
109
|
+
case 'reference':
|
|
110
|
+
return 'Ensure the variable/function is defined or imported before use';
|
|
111
|
+
|
|
112
|
+
case 'import':
|
|
113
|
+
if (message.includes('module not found')) {
|
|
114
|
+
return 'Install missing package with npm install or fix import path';
|
|
115
|
+
}
|
|
116
|
+
return 'Check import path and ensure the module exports correctly';
|
|
117
|
+
|
|
118
|
+
case 'lint':
|
|
119
|
+
return 'Fix the linting issue as specified in the error message';
|
|
120
|
+
|
|
121
|
+
case 'test':
|
|
122
|
+
return 'Update the implementation to match expected behavior, or fix the test assertion';
|
|
123
|
+
|
|
124
|
+
case 'typescript':
|
|
125
|
+
return 'Fix type errors by adding proper types or type guards';
|
|
126
|
+
|
|
127
|
+
case 'build':
|
|
128
|
+
return 'Check build configuration and dependencies';
|
|
129
|
+
|
|
130
|
+
default:
|
|
131
|
+
return 'Review the error message and fix accordingly';
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Calculate error priority
|
|
137
|
+
*/
|
|
138
|
+
function calculatePriority(error) {
|
|
139
|
+
const type = categorizeError(error);
|
|
140
|
+
|
|
141
|
+
// Critical - blocks everything
|
|
142
|
+
if (type === 'syntax' || type === 'import') {
|
|
143
|
+
return 'critical';
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
// High - likely causes cascading failures
|
|
147
|
+
if (type === 'reference' || type === 'type') {
|
|
148
|
+
return 'high';
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
// Medium - should be fixed
|
|
152
|
+
if (type === 'typescript' || type === 'build' || type === 'test') {
|
|
153
|
+
return 'medium';
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
// Low - nice to fix
|
|
157
|
+
if (type === 'lint') {
|
|
158
|
+
return 'low';
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
return 'medium';
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* Group errors by file for better organization
|
|
166
|
+
*/
|
|
167
|
+
export function groupErrorsByFile(errors) {
|
|
168
|
+
const grouped = {};
|
|
169
|
+
|
|
170
|
+
for (const error of errors) {
|
|
171
|
+
const file = error.file || 'unknown';
|
|
172
|
+
if (!grouped[file]) {
|
|
173
|
+
grouped[file] = [];
|
|
174
|
+
}
|
|
175
|
+
grouped[file].push(error);
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
return grouped;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* Get unique files with errors
|
|
183
|
+
*/
|
|
184
|
+
export function getAffectedFiles(errors) {
|
|
185
|
+
const files = new Set();
|
|
186
|
+
for (const error of errors) {
|
|
187
|
+
if (error.file) {
|
|
188
|
+
files.add(error.file);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
return Array.from(files);
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
/**
|
|
195
|
+
* Format errors for display
|
|
196
|
+
*/
|
|
197
|
+
export function formatErrors(errors) {
|
|
198
|
+
const lines = [];
|
|
199
|
+
|
|
200
|
+
lines.push(`Found ${errors.length} error(s):`);
|
|
201
|
+
lines.push('');
|
|
202
|
+
|
|
203
|
+
const grouped = groupErrorsByFile(errors);
|
|
204
|
+
|
|
205
|
+
for (const [file, fileErrors] of Object.entries(grouped)) {
|
|
206
|
+
lines.push(`📄 ${file}`);
|
|
207
|
+
for (const error of fileErrors) {
|
|
208
|
+
const loc = error.line ? `:${error.line}` : '';
|
|
209
|
+
const priority = error.priority === 'critical' ? '🔴' :
|
|
210
|
+
error.priority === 'high' ? '🟠' :
|
|
211
|
+
error.priority === 'medium' ? '🟡' : '🟢';
|
|
212
|
+
lines.push(` ${priority} ${error.type}: ${error.message?.substring(0, 60) || 'Unknown error'}`);
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
return lines.join('\n');
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
/**
|
|
220
|
+
* Create a summary of errors for logging
|
|
221
|
+
*/
|
|
222
|
+
export function createErrorSummary(errors) {
|
|
223
|
+
const byType = {};
|
|
224
|
+
const byPriority = { critical: 0, high: 0, medium: 0, low: 0 };
|
|
225
|
+
|
|
226
|
+
for (const error of errors) {
|
|
227
|
+
byType[error.type] = (byType[error.type] || 0) + 1;
|
|
228
|
+
byPriority[error.priority] = (byPriority[error.priority] || 0) + 1;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
return {
|
|
232
|
+
total: errors.length,
|
|
233
|
+
byType,
|
|
234
|
+
byPriority,
|
|
235
|
+
files: getAffectedFiles(errors)
|
|
236
|
+
};
|
|
237
|
+
}
|