baseguard 1.0.4 → 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/dist/commands/fix.d.ts.map +1 -1
- package/dist/commands/fix.js +5 -1
- package/dist/commands/fix.js.map +1 -1
- package/dist/core/baseline-checker.d.ts.map +1 -1
- package/dist/core/baseline-checker.js +6 -4
- package/dist/core/baseline-checker.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 -264
- 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 -564
- 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
|
@@ -1,534 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* AgentKit-inspired orchestrator for managing multiple coding agents
|
|
3
|
-
* Based on OpenAI's AgentKit principles for production-ready agent workflows
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import type { Violation, Analysis, Fix } from '../types/index.js';
|
|
7
|
-
import { GeminiCodeFixer } from './gemini-code-fixer.js';
|
|
8
|
-
import { JulesImplementer } from './jules-implementer.js';
|
|
9
|
-
import { logger } from '../core/debug-logger.js';
|
|
10
|
-
import chalk from 'chalk';
|
|
11
|
-
|
|
12
|
-
export interface AgentCapabilities {
|
|
13
|
-
codeGeneration: boolean;
|
|
14
|
-
fileAnalysis: boolean;
|
|
15
|
-
webSearch: boolean;
|
|
16
|
-
repositoryAccess: boolean;
|
|
17
|
-
realTimeProcessing: boolean;
|
|
18
|
-
autonomousExecution: boolean;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export interface AgentMetrics {
|
|
22
|
-
successRate: number;
|
|
23
|
-
averageResponseTime: number;
|
|
24
|
-
totalExecutions: number;
|
|
25
|
-
lastUsed: Date;
|
|
26
|
-
reliability: number;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
export interface AgentStatus {
|
|
30
|
-
available: boolean;
|
|
31
|
-
capabilities: AgentCapabilities;
|
|
32
|
-
metrics: AgentMetrics;
|
|
33
|
-
lastError?: string;
|
|
34
|
-
configurationValid: boolean;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* AgentKit-inspired orchestrator for intelligent agent selection and workflow optimization
|
|
39
|
-
*/
|
|
40
|
-
export class AgentKitOrchestrator {
|
|
41
|
-
private geminiAgent: GeminiCodeFixer | null = null;
|
|
42
|
-
private julesAgent: JulesImplementer | null = null;
|
|
43
|
-
private agentMetrics: Map<string, AgentMetrics>;
|
|
44
|
-
private categoryLogger: ReturnType<typeof logger.createCategoryLogger>;
|
|
45
|
-
private geminiApiKey: string | null;
|
|
46
|
-
private julesApiKey: string | null;
|
|
47
|
-
|
|
48
|
-
constructor(geminiApiKey: string | null, julesApiKey: string | null) {
|
|
49
|
-
this.geminiApiKey = geminiApiKey;
|
|
50
|
-
this.julesApiKey = julesApiKey;
|
|
51
|
-
this.agentMetrics = new Map();
|
|
52
|
-
this.categoryLogger = logger.createCategoryLogger('agentkit-orchestrator');
|
|
53
|
-
|
|
54
|
-
// Initialize agents if API keys are available
|
|
55
|
-
if (geminiApiKey) {
|
|
56
|
-
this.geminiAgent = new GeminiCodeFixer(geminiApiKey);
|
|
57
|
-
}
|
|
58
|
-
if (julesApiKey) {
|
|
59
|
-
this.julesAgent = new JulesImplementer(julesApiKey);
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
// Initialize metrics
|
|
63
|
-
this.initializeMetrics();
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
/**
|
|
67
|
-
* Initialize agent metrics tracking
|
|
68
|
-
*/
|
|
69
|
-
private initializeMetrics(): void {
|
|
70
|
-
this.agentMetrics.set('gemini', {
|
|
71
|
-
successRate: 0.95,
|
|
72
|
-
averageResponseTime: 2500, // ms
|
|
73
|
-
totalExecutions: 0,
|
|
74
|
-
lastUsed: new Date(),
|
|
75
|
-
reliability: 0.95
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
this.agentMetrics.set('jules', {
|
|
79
|
-
successRate: 0.88,
|
|
80
|
-
averageResponseTime: 15000, // ms (async processing)
|
|
81
|
-
totalExecutions: 0,
|
|
82
|
-
lastUsed: new Date(),
|
|
83
|
-
reliability: 0.88
|
|
84
|
-
});
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
/**
|
|
88
|
-
* Get comprehensive status of all agents
|
|
89
|
-
*/
|
|
90
|
-
async getAgentStatus(): Promise<Record<string, AgentStatus>> {
|
|
91
|
-
const status: Record<string, AgentStatus> = {};
|
|
92
|
-
|
|
93
|
-
// Check Gemini status
|
|
94
|
-
if (this.geminiAgent) {
|
|
95
|
-
try {
|
|
96
|
-
const testResult = await this.geminiAgent.testConnection();
|
|
97
|
-
status.gemini = {
|
|
98
|
-
available: testResult.success,
|
|
99
|
-
capabilities: {
|
|
100
|
-
codeGeneration: true,
|
|
101
|
-
fileAnalysis: true,
|
|
102
|
-
webSearch: true,
|
|
103
|
-
repositoryAccess: false,
|
|
104
|
-
realTimeProcessing: true,
|
|
105
|
-
autonomousExecution: false
|
|
106
|
-
},
|
|
107
|
-
metrics: this.agentMetrics.get('gemini')!,
|
|
108
|
-
configurationValid: testResult.success,
|
|
109
|
-
lastError: testResult.error
|
|
110
|
-
};
|
|
111
|
-
} catch (error) {
|
|
112
|
-
status.gemini = {
|
|
113
|
-
available: false,
|
|
114
|
-
capabilities: {
|
|
115
|
-
codeGeneration: false,
|
|
116
|
-
fileAnalysis: false,
|
|
117
|
-
webSearch: false,
|
|
118
|
-
repositoryAccess: false,
|
|
119
|
-
realTimeProcessing: false,
|
|
120
|
-
autonomousExecution: false
|
|
121
|
-
},
|
|
122
|
-
metrics: this.agentMetrics.get('gemini')!,
|
|
123
|
-
lastError: error instanceof Error ? error.message : 'Unknown error',
|
|
124
|
-
configurationValid: false
|
|
125
|
-
};
|
|
126
|
-
}
|
|
127
|
-
} else {
|
|
128
|
-
status.gemini = {
|
|
129
|
-
available: false,
|
|
130
|
-
capabilities: {
|
|
131
|
-
codeGeneration: false,
|
|
132
|
-
fileAnalysis: false,
|
|
133
|
-
webSearch: false,
|
|
134
|
-
repositoryAccess: false,
|
|
135
|
-
realTimeProcessing: false,
|
|
136
|
-
autonomousExecution: false
|
|
137
|
-
},
|
|
138
|
-
metrics: this.agentMetrics.get('gemini')!,
|
|
139
|
-
lastError: 'Gemini API key not configured',
|
|
140
|
-
configurationValid: false
|
|
141
|
-
};
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
// Check Jules status
|
|
145
|
-
if (this.julesAgent) {
|
|
146
|
-
try {
|
|
147
|
-
const testResult = await this.julesAgent.testConnection();
|
|
148
|
-
const hasRepository = await this.julesAgent.isRepositoryDetected();
|
|
149
|
-
|
|
150
|
-
status.jules = {
|
|
151
|
-
available: testResult.success && hasRepository,
|
|
152
|
-
capabilities: {
|
|
153
|
-
codeGeneration: true,
|
|
154
|
-
fileAnalysis: true,
|
|
155
|
-
webSearch: false,
|
|
156
|
-
repositoryAccess: true,
|
|
157
|
-
realTimeProcessing: false,
|
|
158
|
-
autonomousExecution: true
|
|
159
|
-
},
|
|
160
|
-
metrics: this.agentMetrics.get('jules')!,
|
|
161
|
-
configurationValid: testResult.success,
|
|
162
|
-
lastError: testResult.error || (!hasRepository ? 'No GitHub repository detected' : undefined)
|
|
163
|
-
};
|
|
164
|
-
} catch (error) {
|
|
165
|
-
status.jules = {
|
|
166
|
-
available: false,
|
|
167
|
-
capabilities: {
|
|
168
|
-
codeGeneration: false,
|
|
169
|
-
fileAnalysis: false,
|
|
170
|
-
webSearch: false,
|
|
171
|
-
repositoryAccess: false,
|
|
172
|
-
realTimeProcessing: false,
|
|
173
|
-
autonomousExecution: false
|
|
174
|
-
},
|
|
175
|
-
metrics: this.agentMetrics.get('jules')!,
|
|
176
|
-
lastError: error instanceof Error ? error.message : 'Unknown error',
|
|
177
|
-
configurationValid: false
|
|
178
|
-
};
|
|
179
|
-
}
|
|
180
|
-
} else {
|
|
181
|
-
status.jules = {
|
|
182
|
-
available: false,
|
|
183
|
-
capabilities: {
|
|
184
|
-
codeGeneration: false,
|
|
185
|
-
fileAnalysis: false,
|
|
186
|
-
webSearch: false,
|
|
187
|
-
repositoryAccess: false,
|
|
188
|
-
realTimeProcessing: false,
|
|
189
|
-
autonomousExecution: false
|
|
190
|
-
},
|
|
191
|
-
metrics: this.agentMetrics.get('jules')!,
|
|
192
|
-
lastError: 'Jules API key not configured',
|
|
193
|
-
configurationValid: false
|
|
194
|
-
};
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
return status;
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
/**
|
|
201
|
-
* Intelligent agent selection based on context and requirements
|
|
202
|
-
*/
|
|
203
|
-
async selectOptimalAgent(
|
|
204
|
-
violations: Violation[],
|
|
205
|
-
context: {
|
|
206
|
-
hasRepository: boolean;
|
|
207
|
-
requiresRealTime: boolean;
|
|
208
|
-
complexityLevel: 'low' | 'medium' | 'high';
|
|
209
|
-
userPreference?: 'gemini' | 'jules';
|
|
210
|
-
}
|
|
211
|
-
): Promise<{
|
|
212
|
-
primary: 'gemini' | 'jules';
|
|
213
|
-
fallback: 'gemini' | 'jules';
|
|
214
|
-
reasoning: string;
|
|
215
|
-
confidence: number;
|
|
216
|
-
}> {
|
|
217
|
-
const agentStatus = await this.getAgentStatus();
|
|
218
|
-
const geminiMetrics = this.agentMetrics.get('gemini')!;
|
|
219
|
-
const julesMetrics = this.agentMetrics.get('jules')!;
|
|
220
|
-
|
|
221
|
-
// Calculate scores for each agent
|
|
222
|
-
let geminiScore = 0;
|
|
223
|
-
let julesScore = 0;
|
|
224
|
-
|
|
225
|
-
// Availability scoring
|
|
226
|
-
if (agentStatus.gemini?.available) geminiScore += 30;
|
|
227
|
-
if (agentStatus.jules?.available) julesScore += 30;
|
|
228
|
-
|
|
229
|
-
// Capability scoring
|
|
230
|
-
if (context.requiresRealTime) {
|
|
231
|
-
geminiScore += 25; // Gemini is real-time
|
|
232
|
-
julesScore += 5; // Jules is async
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
if (context.hasRepository) {
|
|
236
|
-
julesScore += 20; // Jules excels with repositories
|
|
237
|
-
geminiScore += 10; // Gemini can work with repos but not optimized
|
|
238
|
-
} else {
|
|
239
|
-
geminiScore += 25; // Gemini works with any files
|
|
240
|
-
julesScore += 0; // Jules requires repository
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
// Complexity scoring
|
|
244
|
-
switch (context.complexityLevel) {
|
|
245
|
-
case 'low':
|
|
246
|
-
geminiScore += 15; // Gemini is faster for simple fixes
|
|
247
|
-
julesScore += 10;
|
|
248
|
-
break;
|
|
249
|
-
case 'medium':
|
|
250
|
-
geminiScore += 12;
|
|
251
|
-
julesScore += 12;
|
|
252
|
-
break;
|
|
253
|
-
case 'high':
|
|
254
|
-
geminiScore += 8;
|
|
255
|
-
julesScore += 18; // Jules better for complex autonomous work
|
|
256
|
-
break;
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
// Reliability scoring
|
|
260
|
-
geminiScore += geminiMetrics.reliability * 10;
|
|
261
|
-
julesScore += julesMetrics.reliability * 10;
|
|
262
|
-
|
|
263
|
-
// User preference bonus
|
|
264
|
-
if (context.userPreference === 'gemini') geminiScore += 15;
|
|
265
|
-
if (context.userPreference === 'jules') julesScore += 15;
|
|
266
|
-
|
|
267
|
-
// Determine primary and fallback
|
|
268
|
-
const primary = geminiScore >= julesScore ? 'gemini' : 'jules';
|
|
269
|
-
const fallback = primary === 'gemini' ? 'jules' : 'gemini';
|
|
270
|
-
|
|
271
|
-
const confidence = Math.max(geminiScore, julesScore) / 100;
|
|
272
|
-
|
|
273
|
-
let reasoning = '';
|
|
274
|
-
if (primary === 'gemini') {
|
|
275
|
-
reasoning = `Gemini selected: ${context.requiresRealTime ? 'real-time processing needed, ' : ''}${!context.hasRepository ? 'works with local files, ' : ''}high reliability (${Math.round(geminiMetrics.reliability * 100)}%)`;
|
|
276
|
-
} else {
|
|
277
|
-
reasoning = `Jules selected: ${context.hasRepository ? 'repository context available, ' : ''}${context.complexityLevel === 'high' ? 'complex autonomous work, ' : ''}good for comprehensive fixes`;
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
this.categoryLogger.info('Agent selection completed', {
|
|
281
|
-
primary,
|
|
282
|
-
fallback,
|
|
283
|
-
geminiScore,
|
|
284
|
-
julesScore,
|
|
285
|
-
confidence,
|
|
286
|
-
reasoning
|
|
287
|
-
});
|
|
288
|
-
|
|
289
|
-
return { primary, fallback, reasoning, confidence };
|
|
290
|
-
}
|
|
291
|
-
|
|
292
|
-
/**
|
|
293
|
-
* Execute fixes using the optimal agent with fallback
|
|
294
|
-
*/
|
|
295
|
-
async executeFixes(
|
|
296
|
-
violations: Violation[],
|
|
297
|
-
analyses: Analysis[],
|
|
298
|
-
options: {
|
|
299
|
-
auto?: boolean;
|
|
300
|
-
userPreference?: 'gemini' | 'jules';
|
|
301
|
-
requiresRealTime?: boolean;
|
|
302
|
-
} = {}
|
|
303
|
-
): Promise<{
|
|
304
|
-
fixes: Fix[];
|
|
305
|
-
agentUsed: 'gemini' | 'jules';
|
|
306
|
-
executionTime: number;
|
|
307
|
-
success: boolean;
|
|
308
|
-
error?: string;
|
|
309
|
-
}> {
|
|
310
|
-
const startTime = Date.now();
|
|
311
|
-
|
|
312
|
-
// Determine context
|
|
313
|
-
const hasRepository = this.julesAgent ? await this.julesAgent.isRepositoryDetected() : false;
|
|
314
|
-
const context = {
|
|
315
|
-
hasRepository,
|
|
316
|
-
requiresRealTime: options.requiresRealTime ?? true,
|
|
317
|
-
complexityLevel: this.assessComplexity(violations),
|
|
318
|
-
userPreference: options.userPreference
|
|
319
|
-
};
|
|
320
|
-
|
|
321
|
-
// Select optimal agent
|
|
322
|
-
const selection = await this.selectOptimalAgent(violations, context);
|
|
323
|
-
|
|
324
|
-
console.log(chalk.cyan(`🤖 Using ${selection.primary} agent (${Math.round(selection.confidence * 100)}% confidence)`));
|
|
325
|
-
console.log(chalk.dim(` Reasoning: ${selection.reasoning}`));
|
|
326
|
-
|
|
327
|
-
try {
|
|
328
|
-
// Try primary agent
|
|
329
|
-
const result = await this.executeWithAgent(
|
|
330
|
-
selection.primary,
|
|
331
|
-
violations,
|
|
332
|
-
analyses,
|
|
333
|
-
options
|
|
334
|
-
);
|
|
335
|
-
|
|
336
|
-
// Update metrics
|
|
337
|
-
this.updateAgentMetrics(selection.primary, true, Date.now() - startTime);
|
|
338
|
-
|
|
339
|
-
return {
|
|
340
|
-
...result,
|
|
341
|
-
agentUsed: selection.primary,
|
|
342
|
-
executionTime: Date.now() - startTime,
|
|
343
|
-
success: true
|
|
344
|
-
};
|
|
345
|
-
|
|
346
|
-
} catch (primaryError) {
|
|
347
|
-
this.categoryLogger.warn(`Primary agent ${selection.primary} failed`, { error: primaryError });
|
|
348
|
-
|
|
349
|
-
// Update metrics for failure
|
|
350
|
-
this.updateAgentMetrics(selection.primary, false, Date.now() - startTime);
|
|
351
|
-
|
|
352
|
-
console.log(chalk.yellow(`⚠️ ${selection.primary} failed, trying ${selection.fallback}...`));
|
|
353
|
-
|
|
354
|
-
try {
|
|
355
|
-
// Try fallback agent
|
|
356
|
-
const result = await this.executeWithAgent(
|
|
357
|
-
selection.fallback,
|
|
358
|
-
violations,
|
|
359
|
-
analyses,
|
|
360
|
-
options
|
|
361
|
-
);
|
|
362
|
-
|
|
363
|
-
// Update metrics
|
|
364
|
-
this.updateAgentMetrics(selection.fallback, true, Date.now() - startTime);
|
|
365
|
-
|
|
366
|
-
return {
|
|
367
|
-
...result,
|
|
368
|
-
agentUsed: selection.fallback,
|
|
369
|
-
executionTime: Date.now() - startTime,
|
|
370
|
-
success: true
|
|
371
|
-
};
|
|
372
|
-
|
|
373
|
-
} catch (fallbackError) {
|
|
374
|
-
this.categoryLogger.error('Both agents failed', {
|
|
375
|
-
primaryError,
|
|
376
|
-
fallbackError
|
|
377
|
-
});
|
|
378
|
-
|
|
379
|
-
// Update metrics for failure
|
|
380
|
-
this.updateAgentMetrics(selection.fallback, false, Date.now() - startTime);
|
|
381
|
-
|
|
382
|
-
return {
|
|
383
|
-
fixes: [],
|
|
384
|
-
agentUsed: selection.primary,
|
|
385
|
-
executionTime: Date.now() - startTime,
|
|
386
|
-
success: false,
|
|
387
|
-
error: `Both agents failed. Primary (${selection.primary}): ${primaryError instanceof Error ? primaryError.message : 'Unknown error'}. Fallback (${selection.fallback}): ${fallbackError instanceof Error ? fallbackError.message : 'Unknown error'}`
|
|
388
|
-
};
|
|
389
|
-
}
|
|
390
|
-
}
|
|
391
|
-
}
|
|
392
|
-
|
|
393
|
-
/**
|
|
394
|
-
* Execute fixes with a specific agent
|
|
395
|
-
*/
|
|
396
|
-
private async executeWithAgent(
|
|
397
|
-
agentType: 'gemini' | 'jules',
|
|
398
|
-
violations: Violation[],
|
|
399
|
-
analyses: Analysis[],
|
|
400
|
-
_options: { auto?: boolean } = {}
|
|
401
|
-
): Promise<{ fixes: Fix[] }> {
|
|
402
|
-
const fixes: Fix[] = [];
|
|
403
|
-
|
|
404
|
-
if (agentType === 'gemini' && this.geminiAgent) {
|
|
405
|
-
// Generate fixes one by one for Gemini
|
|
406
|
-
for (let i = 0; i < violations.length; i++) {
|
|
407
|
-
const violation = violations[i];
|
|
408
|
-
const analysis = analyses[i];
|
|
409
|
-
if (violation && analysis) {
|
|
410
|
-
const fix = await this.geminiAgent.generateFix(violation, analysis);
|
|
411
|
-
fixes.push(fix);
|
|
412
|
-
}
|
|
413
|
-
}
|
|
414
|
-
} else if (agentType === 'jules' && this.julesAgent) {
|
|
415
|
-
// Generate fixes one by one for Jules
|
|
416
|
-
for (let i = 0; i < violations.length; i++) {
|
|
417
|
-
const violation = violations[i];
|
|
418
|
-
const analysis = analyses[i];
|
|
419
|
-
if (violation && analysis) {
|
|
420
|
-
const fix = await this.julesAgent.generateFix(violation, analysis);
|
|
421
|
-
fixes.push(fix);
|
|
422
|
-
}
|
|
423
|
-
}
|
|
424
|
-
} else {
|
|
425
|
-
throw new Error(`Agent ${agentType} is not available or not configured`);
|
|
426
|
-
}
|
|
427
|
-
|
|
428
|
-
return { fixes };
|
|
429
|
-
}
|
|
430
|
-
|
|
431
|
-
/**
|
|
432
|
-
* Assess complexity level of violations
|
|
433
|
-
*/
|
|
434
|
-
private assessComplexity(violations: Violation[]): 'low' | 'medium' | 'high' {
|
|
435
|
-
if (violations.length <= 3) return 'low';
|
|
436
|
-
if (violations.length <= 10) return 'medium';
|
|
437
|
-
return 'high';
|
|
438
|
-
}
|
|
439
|
-
|
|
440
|
-
/**
|
|
441
|
-
* Update agent performance metrics
|
|
442
|
-
*/
|
|
443
|
-
private updateAgentMetrics(
|
|
444
|
-
agentType: 'gemini' | 'jules',
|
|
445
|
-
success: boolean,
|
|
446
|
-
responseTime: number
|
|
447
|
-
): void {
|
|
448
|
-
const metrics = this.agentMetrics.get(agentType);
|
|
449
|
-
if (!metrics) return;
|
|
450
|
-
|
|
451
|
-
metrics.totalExecutions++;
|
|
452
|
-
metrics.lastUsed = new Date();
|
|
453
|
-
|
|
454
|
-
// Update success rate (exponential moving average)
|
|
455
|
-
const alpha = 0.1;
|
|
456
|
-
metrics.successRate = success
|
|
457
|
-
? metrics.successRate + alpha * (1 - metrics.successRate)
|
|
458
|
-
: metrics.successRate + alpha * (0 - metrics.successRate);
|
|
459
|
-
|
|
460
|
-
// Update average response time (exponential moving average)
|
|
461
|
-
metrics.averageResponseTime = metrics.averageResponseTime + alpha * (responseTime - metrics.averageResponseTime);
|
|
462
|
-
|
|
463
|
-
// Update reliability (combination of success rate and consistency)
|
|
464
|
-
metrics.reliability = metrics.successRate * 0.8 + (1 - Math.min(responseTime / 10000, 1)) * 0.2;
|
|
465
|
-
|
|
466
|
-
this.agentMetrics.set(agentType, metrics);
|
|
467
|
-
}
|
|
468
|
-
|
|
469
|
-
/**
|
|
470
|
-
* Get performance analytics for all agents
|
|
471
|
-
*/
|
|
472
|
-
getPerformanceAnalytics(): {
|
|
473
|
-
gemini: AgentMetrics & { recommendation: string };
|
|
474
|
-
jules: AgentMetrics & { recommendation: string };
|
|
475
|
-
overall: {
|
|
476
|
-
totalExecutions: number;
|
|
477
|
-
averageSuccessRate: number;
|
|
478
|
-
recommendedPrimary: 'gemini' | 'jules';
|
|
479
|
-
};
|
|
480
|
-
} {
|
|
481
|
-
const geminiMetrics = this.agentMetrics.get('gemini')!;
|
|
482
|
-
const julesMetrics = this.agentMetrics.get('jules')!;
|
|
483
|
-
|
|
484
|
-
const geminiRecommendation = this.getAgentRecommendation('gemini', geminiMetrics);
|
|
485
|
-
const julesRecommendation = this.getAgentRecommendation('jules', julesMetrics);
|
|
486
|
-
|
|
487
|
-
const totalExecutions = geminiMetrics.totalExecutions + julesMetrics.totalExecutions;
|
|
488
|
-
const averageSuccessRate = (geminiMetrics.successRate + julesMetrics.successRate) / 2;
|
|
489
|
-
const recommendedPrimary = geminiMetrics.reliability >= julesMetrics.reliability ? 'gemini' : 'jules';
|
|
490
|
-
|
|
491
|
-
return {
|
|
492
|
-
gemini: { ...geminiMetrics, recommendation: geminiRecommendation },
|
|
493
|
-
jules: { ...julesMetrics, recommendation: julesRecommendation },
|
|
494
|
-
overall: {
|
|
495
|
-
totalExecutions,
|
|
496
|
-
averageSuccessRate,
|
|
497
|
-
recommendedPrimary
|
|
498
|
-
}
|
|
499
|
-
};
|
|
500
|
-
}
|
|
501
|
-
|
|
502
|
-
/**
|
|
503
|
-
* Get recommendation for specific agent
|
|
504
|
-
*/
|
|
505
|
-
private getAgentRecommendation(agentType: 'gemini' | 'jules', metrics: AgentMetrics): string {
|
|
506
|
-
if (metrics.reliability > 0.9) {
|
|
507
|
-
return `Excellent performance - recommended for ${agentType === 'gemini' ? 'real-time fixes' : 'complex autonomous work'}`;
|
|
508
|
-
} else if (metrics.reliability > 0.8) {
|
|
509
|
-
return `Good performance - suitable for most tasks`;
|
|
510
|
-
} else if (metrics.reliability > 0.6) {
|
|
511
|
-
return `Moderate performance - consider as fallback option`;
|
|
512
|
-
} else {
|
|
513
|
-
return `Poor performance - check configuration and API keys`;
|
|
514
|
-
}
|
|
515
|
-
}
|
|
516
|
-
|
|
517
|
-
/**
|
|
518
|
-
* Reset metrics (useful for testing or fresh start)
|
|
519
|
-
*/
|
|
520
|
-
resetMetrics(): void {
|
|
521
|
-
this.initializeMetrics();
|
|
522
|
-
this.categoryLogger.info('Agent metrics reset');
|
|
523
|
-
}
|
|
524
|
-
|
|
525
|
-
/**
|
|
526
|
-
* Export metrics for external analysis
|
|
527
|
-
*/
|
|
528
|
-
exportMetrics(): Record<string, AgentMetrics> {
|
|
529
|
-
return {
|
|
530
|
-
gemini: { ...this.agentMetrics.get('gemini')! },
|
|
531
|
-
jules: { ...this.agentMetrics.get('jules')! }
|
|
532
|
-
};
|
|
533
|
-
}
|
|
534
|
-
}
|