baseguard 1.0.5 ā 1.0.6
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/dist/ai/gemini-analyzer.d.ts.map +1 -1
- package/dist/ai/gemini-analyzer.js +1 -1
- package/dist/ai/gemini-analyzer.js.map +1 -1
- package/dist/ai/gemini-code-fixer.d.ts.map +1 -1
- package/dist/ai/gemini-code-fixer.js +2 -7
- package/dist/ai/gemini-code-fixer.js.map +1 -1
- package/dist/ai/jules-implementer.d.ts +8 -0
- package/dist/ai/jules-implementer.d.ts.map +1 -1
- package/dist/ai/jules-implementer.js +115 -17
- package/dist/ai/jules-implementer.js.map +1 -1
- package/package.json +1 -1
- package/src/ai/__tests__/gemini-analyzer.test.ts +0 -181
- package/src/ai/agentkit-orchestrator.ts +0 -534
- package/src/ai/fix-manager.ts +0 -362
- package/src/ai/gemini-analyzer.ts +0 -665
- package/src/ai/gemini-code-fixer.ts +0 -539
- package/src/ai/index.ts +0 -4
- package/src/ai/jules-implementer.ts +0 -504
- package/src/ai/unified-code-fixer.ts +0 -347
- package/src/commands/automation.ts +0 -344
- package/src/commands/check.ts +0 -298
- package/src/commands/config.ts +0 -584
- package/src/commands/fix.ts +0 -269
- package/src/commands/index.ts +0 -7
- package/src/commands/init.ts +0 -156
- package/src/commands/status.ts +0 -307
- package/src/core/api-key-manager.ts +0 -298
- package/src/core/baseguard.ts +0 -757
- package/src/core/baseline-checker.ts +0 -566
- package/src/core/cache-manager.ts +0 -272
- package/src/core/configuration-recovery.ts +0 -672
- package/src/core/configuration.ts +0 -596
- package/src/core/debug-logger.ts +0 -590
- package/src/core/directory-filter.ts +0 -421
- package/src/core/error-handler.ts +0 -518
- package/src/core/file-processor.ts +0 -338
- package/src/core/gitignore-manager.ts +0 -169
- package/src/core/graceful-degradation-manager.ts +0 -596
- package/src/core/index.ts +0 -17
- package/src/core/lazy-loader.ts +0 -317
- package/src/core/logger.ts +0 -0
- package/src/core/memory-manager.ts +0 -290
- package/src/core/parser-worker.ts +0 -33
- package/src/core/startup-optimizer.ts +0 -246
- package/src/core/system-error-handler.ts +0 -755
- package/src/git/automation-engine.ts +0 -361
- package/src/git/github-manager.ts +0 -190
- package/src/git/hook-manager.ts +0 -210
- package/src/git/index.ts +0 -4
- package/src/index.ts +0 -8
- package/src/parsers/feature-validator.ts +0 -559
- package/src/parsers/index.ts +0 -8
- package/src/parsers/parser-manager.ts +0 -418
- package/src/parsers/parser.ts +0 -26
- package/src/parsers/react-parser-optimized.ts +0 -161
- package/src/parsers/react-parser.ts +0 -359
- package/src/parsers/svelte-parser.ts +0 -510
- package/src/parsers/vanilla-parser.ts +0 -685
- package/src/parsers/vue-parser.ts +0 -476
- package/src/types/index.ts +0 -96
- package/src/ui/components.ts +0 -567
- package/src/ui/help.ts +0 -193
- package/src/ui/index.ts +0 -4
- package/src/ui/prompts.ts +0 -681
- package/src/ui/terminal-header.ts +0 -59
- package/tests/e2e/baseguard.e2e.test.ts +0 -516
- package/tests/e2e/cross-platform.e2e.test.ts +0 -420
- package/tests/e2e/git-integration.e2e.test.ts +0 -487
- package/tests/fixtures/react-project/package.json +0 -14
- package/tests/fixtures/react-project/src/App.css +0 -76
- package/tests/fixtures/react-project/src/App.tsx +0 -77
- package/tests/fixtures/svelte-project/package.json +0 -11
- package/tests/fixtures/svelte-project/src/App.svelte +0 -369
- package/tests/fixtures/vanilla-project/index.html +0 -76
- package/tests/fixtures/vanilla-project/script.js +0 -331
- package/tests/fixtures/vanilla-project/styles.css +0 -359
- package/tests/fixtures/vue-project/package.json +0 -12
- package/tests/fixtures/vue-project/src/App.vue +0 -216
- package/tmp-smoke/.baseguard/backups/config-2026-02-19T12-04-11-067Z-auto.json +0 -30
- package/tmp-smoke/src/bad.css +0 -3
package/src/ai/fix-manager.ts
DELETED
|
@@ -1,362 +0,0 @@
|
|
|
1
|
-
import { readFile, writeFile, copyFile } from 'fs/promises';
|
|
2
|
-
import { existsSync } from 'fs';
|
|
3
|
-
import { join, dirname } from 'path';
|
|
4
|
-
import { mkdir } from 'fs/promises';
|
|
5
|
-
import chalk from 'chalk';
|
|
6
|
-
import type { Fix } from '../types/index.js';
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Fix manager for previewing and applying code fixes
|
|
10
|
-
*/
|
|
11
|
-
export class FixManager {
|
|
12
|
-
private appliedFixes: Map<string, { original: string; backup: string }> = new Map();
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Generate unified diff preview of proposed changes
|
|
16
|
-
*/
|
|
17
|
-
async generatePreview(fix: Fix): Promise<string> {
|
|
18
|
-
try {
|
|
19
|
-
const originalContent = await readFile(fix.filePath, 'utf8');
|
|
20
|
-
const modifiedContent = this.applyPatchToContent(originalContent, fix.patch);
|
|
21
|
-
|
|
22
|
-
return this.createUnifiedDiff(fix.filePath, originalContent, modifiedContent);
|
|
23
|
-
} catch (error) {
|
|
24
|
-
throw new Error(`Failed to generate preview: ${error instanceof Error ? error.message : 'Unknown error'}`);
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* Show interactive fix approval with clear change descriptions
|
|
30
|
-
*/
|
|
31
|
-
async showFixPreview(fix: Fix): Promise<boolean> {
|
|
32
|
-
console.log(chalk.cyan(`\nš§ Fix Preview for ${fix.violation.feature} in ${fix.filePath}\n`));
|
|
33
|
-
|
|
34
|
-
// Show fix explanation
|
|
35
|
-
console.log(chalk.white('š Fix Description:'));
|
|
36
|
-
console.log(chalk.dim(fix.explanation));
|
|
37
|
-
console.log();
|
|
38
|
-
|
|
39
|
-
// Show confidence score
|
|
40
|
-
const confidenceColor = fix.confidence >= 0.8 ? 'green' : fix.confidence >= 0.6 ? 'yellow' : 'red';
|
|
41
|
-
console.log(chalk.white('šÆ Confidence: ') + chalk[confidenceColor](`${Math.round(fix.confidence * 100)}%`));
|
|
42
|
-
console.log();
|
|
43
|
-
|
|
44
|
-
// Show unified diff
|
|
45
|
-
console.log(chalk.white('š Changes:'));
|
|
46
|
-
const preview = await this.generatePreview(fix);
|
|
47
|
-
console.log(this.colorizeUnifiedDiff(preview));
|
|
48
|
-
console.log();
|
|
49
|
-
|
|
50
|
-
// Show human-readable preview
|
|
51
|
-
if (fix.preview) {
|
|
52
|
-
console.log(chalk.white('š Summary:'));
|
|
53
|
-
console.log(chalk.dim(fix.preview));
|
|
54
|
-
console.log();
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
// Interactive approval
|
|
58
|
-
const { default: inquirer } = await import('inquirer');
|
|
59
|
-
|
|
60
|
-
const { action } = await inquirer.prompt([
|
|
61
|
-
{
|
|
62
|
-
type: 'list',
|
|
63
|
-
name: 'action',
|
|
64
|
-
message: 'What would you like to do with this fix?',
|
|
65
|
-
choices: [
|
|
66
|
-
{ name: 'ā
Apply this fix', value: 'apply' },
|
|
67
|
-
{ name: 'š Show detailed diff', value: 'detail' },
|
|
68
|
-
{ name: 'ā Skip this fix', value: 'skip' },
|
|
69
|
-
{ name: 'š« Cancel all fixes', value: 'cancel' }
|
|
70
|
-
]
|
|
71
|
-
}
|
|
72
|
-
]);
|
|
73
|
-
|
|
74
|
-
switch (action) {
|
|
75
|
-
case 'apply':
|
|
76
|
-
return true;
|
|
77
|
-
case 'detail':
|
|
78
|
-
await this.showDetailedDiff(fix);
|
|
79
|
-
return await this.showFixPreview(fix); // Show preview again
|
|
80
|
-
case 'skip':
|
|
81
|
-
return false;
|
|
82
|
-
case 'cancel':
|
|
83
|
-
throw new Error('Fix application cancelled by user');
|
|
84
|
-
default:
|
|
85
|
-
return false;
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
/**
|
|
90
|
-
* Apply fixes to original files while preserving formatting and structure
|
|
91
|
-
*/
|
|
92
|
-
async applyFix(fix: Fix): Promise<void> {
|
|
93
|
-
try {
|
|
94
|
-
// Create backup before applying fix
|
|
95
|
-
await this.createBackup(fix.filePath);
|
|
96
|
-
|
|
97
|
-
// Read original content
|
|
98
|
-
const originalContent = await readFile(fix.filePath, 'utf8');
|
|
99
|
-
|
|
100
|
-
// Apply patch to content
|
|
101
|
-
const modifiedContent = this.applyPatchToContent(originalContent, fix.patch);
|
|
102
|
-
|
|
103
|
-
// Write modified content back to file
|
|
104
|
-
await writeFile(fix.filePath, modifiedContent, 'utf8');
|
|
105
|
-
|
|
106
|
-
// Store fix information for potential rollback
|
|
107
|
-
this.appliedFixes.set(fix.filePath, {
|
|
108
|
-
original: originalContent,
|
|
109
|
-
backup: this.getBackupPath(fix.filePath)
|
|
110
|
-
});
|
|
111
|
-
|
|
112
|
-
console.log(chalk.green(`ā
Applied fix to ${fix.filePath}`));
|
|
113
|
-
} catch (error) {
|
|
114
|
-
throw new Error(`Failed to apply fix: ${error instanceof Error ? error.message : 'Unknown error'}`);
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
/**
|
|
119
|
-
* Apply multiple fixes with batch processing
|
|
120
|
-
*/
|
|
121
|
-
async applyFixes(fixes: Fix[]): Promise<{ applied: Fix[]; skipped: Fix[]; failed: { fix: Fix; error: string }[] }> {
|
|
122
|
-
const results = {
|
|
123
|
-
applied: [] as Fix[],
|
|
124
|
-
skipped: [] as Fix[],
|
|
125
|
-
failed: [] as { fix: Fix; error: string }[]
|
|
126
|
-
};
|
|
127
|
-
|
|
128
|
-
console.log(chalk.cyan(`\nš§ Applying ${fixes.length} fixes...\n`));
|
|
129
|
-
|
|
130
|
-
for (const fix of fixes) {
|
|
131
|
-
try {
|
|
132
|
-
const shouldApply = await this.showFixPreview(fix);
|
|
133
|
-
|
|
134
|
-
if (shouldApply) {
|
|
135
|
-
await this.applyFix(fix);
|
|
136
|
-
results.applied.push(fix);
|
|
137
|
-
} else {
|
|
138
|
-
results.skipped.push(fix);
|
|
139
|
-
console.log(chalk.yellow(`āļø Skipped fix for ${fix.filePath}`));
|
|
140
|
-
}
|
|
141
|
-
} catch (error) {
|
|
142
|
-
const errorMessage = error instanceof Error ? error.message : 'Unknown error';
|
|
143
|
-
results.failed.push({ fix, error: errorMessage });
|
|
144
|
-
console.log(chalk.red(`ā Failed to apply fix for ${fix.filePath}: ${errorMessage}`));
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
return results;
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
/**
|
|
152
|
-
* Rollback applied fixes
|
|
153
|
-
*/
|
|
154
|
-
async rollbackFix(filePath: string): Promise<void> {
|
|
155
|
-
const fixInfo = this.appliedFixes.get(filePath);
|
|
156
|
-
|
|
157
|
-
if (!fixInfo) {
|
|
158
|
-
throw new Error(`No applied fix found for ${filePath}`);
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
try {
|
|
162
|
-
// Restore original content
|
|
163
|
-
await writeFile(filePath, fixInfo.original, 'utf8');
|
|
164
|
-
|
|
165
|
-
// Remove from applied fixes
|
|
166
|
-
this.appliedFixes.delete(filePath);
|
|
167
|
-
|
|
168
|
-
console.log(chalk.green(`ā
Rolled back fix for ${filePath}`));
|
|
169
|
-
} catch (error) {
|
|
170
|
-
throw new Error(`Failed to rollback fix: ${error instanceof Error ? error.message : 'Unknown error'}`);
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
/**
|
|
175
|
-
* Rollback all applied fixes
|
|
176
|
-
*/
|
|
177
|
-
async rollbackAllFixes(): Promise<void> {
|
|
178
|
-
const filePaths = Array.from(this.appliedFixes.keys());
|
|
179
|
-
|
|
180
|
-
console.log(chalk.cyan(`\nš Rolling back ${filePaths.length} fixes...\n`));
|
|
181
|
-
|
|
182
|
-
for (const filePath of filePaths) {
|
|
183
|
-
try {
|
|
184
|
-
await this.rollbackFix(filePath);
|
|
185
|
-
} catch (error) {
|
|
186
|
-
console.log(chalk.red(`ā Failed to rollback ${filePath}: ${error instanceof Error ? error.message : 'Unknown error'}`));
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
/**
|
|
192
|
-
* Get list of applied fixes
|
|
193
|
-
*/
|
|
194
|
-
getAppliedFixes(): string[] {
|
|
195
|
-
return Array.from(this.appliedFixes.keys());
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
/**
|
|
199
|
-
* Create backup of original file
|
|
200
|
-
*/
|
|
201
|
-
private async createBackup(filePath: string): Promise<void> {
|
|
202
|
-
const backupPath = this.getBackupPath(filePath);
|
|
203
|
-
const backupDir = dirname(backupPath);
|
|
204
|
-
|
|
205
|
-
// Ensure backup directory exists
|
|
206
|
-
if (!existsSync(backupDir)) {
|
|
207
|
-
await mkdir(backupDir, { recursive: true });
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
// Copy original file to backup location
|
|
211
|
-
await copyFile(filePath, backupPath);
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
/**
|
|
215
|
-
* Get backup file path
|
|
216
|
-
*/
|
|
217
|
-
private getBackupPath(filePath: string): string {
|
|
218
|
-
const timestamp = new Date().toISOString().replace(/[:.]/g, '-');
|
|
219
|
-
return join('.baseguard', 'backups', `${filePath.replace(/[/\\]/g, '_')}.${timestamp}.backup`);
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
/**
|
|
223
|
-
* Apply patch to file content
|
|
224
|
-
*/
|
|
225
|
-
private applyPatchToContent(originalContent: string, patch: string): string {
|
|
226
|
-
const lines = originalContent.split('\n');
|
|
227
|
-
const patchLines = patch.split('\n');
|
|
228
|
-
|
|
229
|
-
const result = [...lines];
|
|
230
|
-
let currentLine = 0;
|
|
231
|
-
|
|
232
|
-
for (const patchLine of patchLines) {
|
|
233
|
-
if (patchLine.startsWith('@@')) {
|
|
234
|
-
// Parse hunk header to get line numbers
|
|
235
|
-
const match = patchLine.match(/@@ -(\d+),?\d* \+(\d+),?\d* @@/);
|
|
236
|
-
if (match && match[2]) {
|
|
237
|
-
currentLine = parseInt(match[2]) - 1;
|
|
238
|
-
}
|
|
239
|
-
} else if (patchLine.startsWith('-')) {
|
|
240
|
-
// Remove line
|
|
241
|
-
const lineToRemove = patchLine.substring(1);
|
|
242
|
-
const index = result.findIndex((line, i) => i >= currentLine && line.trim() === lineToRemove.trim());
|
|
243
|
-
if (index !== -1) {
|
|
244
|
-
result.splice(index, 1);
|
|
245
|
-
}
|
|
246
|
-
} else if (patchLine.startsWith('+')) {
|
|
247
|
-
// Add line
|
|
248
|
-
const lineToAdd = patchLine.substring(1);
|
|
249
|
-
result.splice(currentLine, 0, lineToAdd);
|
|
250
|
-
currentLine++;
|
|
251
|
-
} else if (patchLine.startsWith(' ')) {
|
|
252
|
-
// Context line - advance current line
|
|
253
|
-
currentLine++;
|
|
254
|
-
}
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
return result.join('\n');
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
/**
|
|
261
|
-
* Create unified diff between original and modified content
|
|
262
|
-
*/
|
|
263
|
-
private createUnifiedDiff(filePath: string, original: string, modified: string): string {
|
|
264
|
-
const originalLines = original.split('\n');
|
|
265
|
-
const modifiedLines = modified.split('\n');
|
|
266
|
-
|
|
267
|
-
let diff = `--- a/${filePath}\n+++ b/${filePath}\n`;
|
|
268
|
-
|
|
269
|
-
// Simple diff algorithm (in production, use a proper diff library)
|
|
270
|
-
let i = 0, j = 0;
|
|
271
|
-
while (i < originalLines.length || j < modifiedLines.length) {
|
|
272
|
-
const originalLine = originalLines[i] || '';
|
|
273
|
-
const modifiedLine = modifiedLines[j] || '';
|
|
274
|
-
|
|
275
|
-
if (originalLine === modifiedLine) {
|
|
276
|
-
diff += ` ${originalLine}\n`;
|
|
277
|
-
i++;
|
|
278
|
-
j++;
|
|
279
|
-
} else {
|
|
280
|
-
// Find next matching line
|
|
281
|
-
let nextMatch = -1;
|
|
282
|
-
for (let k = j + 1; k < modifiedLines.length; k++) {
|
|
283
|
-
if (modifiedLines[k] === originalLine) {
|
|
284
|
-
nextMatch = k;
|
|
285
|
-
break;
|
|
286
|
-
}
|
|
287
|
-
}
|
|
288
|
-
|
|
289
|
-
if (nextMatch !== -1) {
|
|
290
|
-
// Lines were added
|
|
291
|
-
for (let k = j; k < nextMatch; k++) {
|
|
292
|
-
diff += `+${modifiedLines[k]}\n`;
|
|
293
|
-
}
|
|
294
|
-
j = nextMatch;
|
|
295
|
-
} else {
|
|
296
|
-
// Line was removed or changed
|
|
297
|
-
if (i < originalLines.length) {
|
|
298
|
-
diff += `-${originalLine}\n`;
|
|
299
|
-
i++;
|
|
300
|
-
}
|
|
301
|
-
if (j < modifiedLines.length) {
|
|
302
|
-
diff += `+${modifiedLine}\n`;
|
|
303
|
-
j++;
|
|
304
|
-
}
|
|
305
|
-
}
|
|
306
|
-
}
|
|
307
|
-
}
|
|
308
|
-
|
|
309
|
-
return diff;
|
|
310
|
-
}
|
|
311
|
-
|
|
312
|
-
/**
|
|
313
|
-
* Colorize unified diff for better readability
|
|
314
|
-
*/
|
|
315
|
-
private colorizeUnifiedDiff(diff: string): string {
|
|
316
|
-
return diff
|
|
317
|
-
.split('\n')
|
|
318
|
-
.map(line => {
|
|
319
|
-
if (line.startsWith('+++') || line.startsWith('---')) {
|
|
320
|
-
return chalk.bold(line);
|
|
321
|
-
} else if (line.startsWith('@@')) {
|
|
322
|
-
return chalk.cyan(line);
|
|
323
|
-
} else if (line.startsWith('+')) {
|
|
324
|
-
return chalk.green(line);
|
|
325
|
-
} else if (line.startsWith('-')) {
|
|
326
|
-
return chalk.red(line);
|
|
327
|
-
} else {
|
|
328
|
-
return chalk.dim(line);
|
|
329
|
-
}
|
|
330
|
-
})
|
|
331
|
-
.join('\n');
|
|
332
|
-
}
|
|
333
|
-
|
|
334
|
-
/**
|
|
335
|
-
* Show detailed diff with more context
|
|
336
|
-
*/
|
|
337
|
-
private async showDetailedDiff(fix: Fix): Promise<void> {
|
|
338
|
-
console.log(chalk.cyan(`\nš Detailed Diff for ${fix.filePath}\n`));
|
|
339
|
-
|
|
340
|
-
try {
|
|
341
|
-
const originalContent = await readFile(fix.filePath, 'utf8');
|
|
342
|
-
const modifiedContent = this.applyPatchToContent(originalContent, fix.patch);
|
|
343
|
-
|
|
344
|
-
const originalLines = originalContent.split('\n');
|
|
345
|
-
const modifiedLines = modifiedContent.split('\n');
|
|
346
|
-
|
|
347
|
-
console.log(chalk.white('Original:'));
|
|
348
|
-
originalLines.forEach((line, i) => {
|
|
349
|
-
console.log(chalk.dim(`${(i + 1).toString().padStart(3)} | `) + line);
|
|
350
|
-
});
|
|
351
|
-
|
|
352
|
-
console.log(chalk.white('\nModified:'));
|
|
353
|
-
modifiedLines.forEach((line, i) => {
|
|
354
|
-
console.log(chalk.dim(`${(i + 1).toString().padStart(3)} | `) + line);
|
|
355
|
-
});
|
|
356
|
-
|
|
357
|
-
console.log();
|
|
358
|
-
} catch (error) {
|
|
359
|
-
console.log(chalk.red(`Failed to show detailed diff: ${error instanceof Error ? error.message : 'Unknown error'}`));
|
|
360
|
-
}
|
|
361
|
-
}
|
|
362
|
-
}
|