erosolar-cli 1.7.372 → 1.7.373
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/core/alphaZeroEngine.d.ts +269 -0
- package/dist/core/alphaZeroEngine.d.ts.map +1 -0
- package/dist/core/alphaZeroEngine.js +523 -0
- package/dist/core/alphaZeroEngine.js.map +1 -0
- package/dist/core/metricsTracker.d.ts +35 -0
- package/dist/core/metricsTracker.d.ts.map +1 -1
- package/dist/core/metricsTracker.js +67 -0
- package/dist/core/metricsTracker.js.map +1 -1
- package/dist/shell/interactiveShell.js +1 -1
- package/dist/shell/interactiveShell.js.map +1 -1
- package/dist/ui/ShellUIAdapter.d.ts +11 -1
- package/dist/ui/ShellUIAdapter.d.ts.map +1 -1
- package/dist/ui/ShellUIAdapter.js +73 -9
- package/dist/ui/ShellUIAdapter.js.map +1 -1
- package/dist/ui/shortcutsHelp.d.ts +11 -0
- package/dist/ui/shortcutsHelp.d.ts.map +1 -1
- package/dist/ui/shortcutsHelp.js +25 -0
- package/dist/ui/shortcutsHelp.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,523 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AlphaZero-Style Dual Agent Engine
|
|
3
|
+
*
|
|
4
|
+
* Implements self-play concepts for code generation:
|
|
5
|
+
* 1. Dual Response Generation - Generate 2 responses, pick the best
|
|
6
|
+
* 2. Self-Critique Loop - Critique and improve responses
|
|
7
|
+
* 3. Solution Quality Scoring - Multi-dimensional evaluation
|
|
8
|
+
* 4. Tool Pattern Learning - Learn optimal tool sequences
|
|
9
|
+
*
|
|
10
|
+
* Principal Investigator: Bo Shang
|
|
11
|
+
*/
|
|
12
|
+
export const DEFAULT_DUAL_CONFIG = {
|
|
13
|
+
enabled: true,
|
|
14
|
+
temperatureA: 0.3, // Conservative
|
|
15
|
+
temperatureB: 0.7, // Creative
|
|
16
|
+
minQualityDifference: 0.1,
|
|
17
|
+
timeoutMs: 60000,
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* Generates evaluation prompt for comparing two responses
|
|
21
|
+
*/
|
|
22
|
+
export function buildEvaluationPrompt(userQuery, responseA, responseB) {
|
|
23
|
+
return `You are an expert code reviewer evaluating two AI assistant responses.
|
|
24
|
+
|
|
25
|
+
USER QUERY:
|
|
26
|
+
${userQuery}
|
|
27
|
+
|
|
28
|
+
RESPONSE A:
|
|
29
|
+
---
|
|
30
|
+
${responseA.slice(0, 4000)}
|
|
31
|
+
---
|
|
32
|
+
|
|
33
|
+
RESPONSE B:
|
|
34
|
+
---
|
|
35
|
+
${responseB.slice(0, 4000)}
|
|
36
|
+
---
|
|
37
|
+
|
|
38
|
+
Evaluate both responses on these dimensions (0-100 each):
|
|
39
|
+
1. Correctness - Is the solution correct and bug-free?
|
|
40
|
+
2. Completeness - Does it fully address the user's request?
|
|
41
|
+
3. Efficiency - Is the code/approach efficient?
|
|
42
|
+
4. Code Quality - Is the code clean, readable, well-structured?
|
|
43
|
+
5. Tool Usage - Are tools used appropriately and effectively?
|
|
44
|
+
|
|
45
|
+
Return JSON only:
|
|
46
|
+
{
|
|
47
|
+
"winner": "A" | "B" | "tie",
|
|
48
|
+
"scores": {
|
|
49
|
+
"correctness": { "a": 0-100, "b": 0-100 },
|
|
50
|
+
"completeness": { "a": 0-100, "b": 0-100 },
|
|
51
|
+
"efficiency": { "a": 0-100, "b": 0-100 },
|
|
52
|
+
"codeQuality": { "a": 0-100, "b": 0-100 },
|
|
53
|
+
"toolUsage": { "a": 0-100, "b": 0-100 }
|
|
54
|
+
},
|
|
55
|
+
"reasoning": "brief explanation",
|
|
56
|
+
"confidence": 0-100
|
|
57
|
+
}`;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Parse evaluation response from LLM
|
|
61
|
+
*/
|
|
62
|
+
export function parseEvaluationResponse(response) {
|
|
63
|
+
try {
|
|
64
|
+
const match = response.match(/\{[\s\S]*\}/);
|
|
65
|
+
if (!match)
|
|
66
|
+
return null;
|
|
67
|
+
const parsed = JSON.parse(match[0]);
|
|
68
|
+
const qualityA = (parsed.scores.correctness.a +
|
|
69
|
+
parsed.scores.completeness.a +
|
|
70
|
+
parsed.scores.efficiency.a +
|
|
71
|
+
parsed.scores.codeQuality.a +
|
|
72
|
+
parsed.scores.toolUsage.a) / 5;
|
|
73
|
+
const qualityB = (parsed.scores.correctness.b +
|
|
74
|
+
parsed.scores.completeness.b +
|
|
75
|
+
parsed.scores.efficiency.b +
|
|
76
|
+
parsed.scores.codeQuality.b +
|
|
77
|
+
parsed.scores.toolUsage.b) / 5;
|
|
78
|
+
return {
|
|
79
|
+
qualityScoreA: qualityA,
|
|
80
|
+
qualityScoreB: qualityB,
|
|
81
|
+
dimensions: {
|
|
82
|
+
correctness: parsed.scores.correctness,
|
|
83
|
+
completeness: parsed.scores.completeness,
|
|
84
|
+
efficiency: parsed.scores.efficiency,
|
|
85
|
+
codeQuality: parsed.scores.codeQuality,
|
|
86
|
+
toolUsage: parsed.scores.toolUsage,
|
|
87
|
+
},
|
|
88
|
+
reasoning: parsed.reasoning,
|
|
89
|
+
confidence: parsed.confidence,
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
catch {
|
|
93
|
+
return null;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
// ============================================================================
|
|
97
|
+
// SELF-CRITIQUE ENGINE
|
|
98
|
+
// ============================================================================
|
|
99
|
+
/**
|
|
100
|
+
* Generates self-critique prompt
|
|
101
|
+
*/
|
|
102
|
+
export function buildCritiquePrompt(userQuery, response, toolCalls) {
|
|
103
|
+
const toolSummary = toolCalls.length > 0
|
|
104
|
+
? toolCalls.map(t => `- ${t.name}: ${t.success ? 'success' : 'failed'}`).join('\n')
|
|
105
|
+
: 'No tools used';
|
|
106
|
+
return `You are a critical code reviewer. Analyze this AI assistant response for issues.
|
|
107
|
+
|
|
108
|
+
USER QUERY:
|
|
109
|
+
${userQuery}
|
|
110
|
+
|
|
111
|
+
RESPONSE:
|
|
112
|
+
---
|
|
113
|
+
${response.slice(0, 6000)}
|
|
114
|
+
---
|
|
115
|
+
|
|
116
|
+
TOOLS USED:
|
|
117
|
+
${toolSummary}
|
|
118
|
+
|
|
119
|
+
Find issues in these categories:
|
|
120
|
+
- correctness: bugs, logic errors, wrong approaches
|
|
121
|
+
- completeness: missing features, partial solutions
|
|
122
|
+
- efficiency: performance issues, unnecessary operations
|
|
123
|
+
- style: code style, readability problems
|
|
124
|
+
- security: potential vulnerabilities
|
|
125
|
+
|
|
126
|
+
Return JSON only:
|
|
127
|
+
{
|
|
128
|
+
"issues": [
|
|
129
|
+
{
|
|
130
|
+
"category": "correctness|completeness|efficiency|style|security",
|
|
131
|
+
"severity": "critical|major|minor",
|
|
132
|
+
"description": "what's wrong",
|
|
133
|
+
"suggestion": "how to fix",
|
|
134
|
+
"location": "where in code (if applicable)"
|
|
135
|
+
}
|
|
136
|
+
],
|
|
137
|
+
"overallQuality": 0-100,
|
|
138
|
+
"needsImprovement": true|false,
|
|
139
|
+
"improvementPriority": ["issue indices in order of importance"]
|
|
140
|
+
}`;
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Parse critique response
|
|
144
|
+
*/
|
|
145
|
+
export function parseCritiqueResponse(response) {
|
|
146
|
+
try {
|
|
147
|
+
const match = response.match(/\{[\s\S]*\}/);
|
|
148
|
+
if (!match)
|
|
149
|
+
return [];
|
|
150
|
+
const parsed = JSON.parse(match[0]);
|
|
151
|
+
return parsed.issues || [];
|
|
152
|
+
}
|
|
153
|
+
catch {
|
|
154
|
+
return [];
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Build improvement prompt based on critique
|
|
159
|
+
*/
|
|
160
|
+
export function buildImprovementPrompt(userQuery, originalResponse, issues) {
|
|
161
|
+
const issueList = issues
|
|
162
|
+
.map((i, idx) => `${idx + 1}. [${i.severity.toUpperCase()}] ${i.category}: ${i.description}${i.suggestion ? ` → ${i.suggestion}` : ''}`)
|
|
163
|
+
.join('\n');
|
|
164
|
+
return `Improve your previous response by fixing these issues:
|
|
165
|
+
|
|
166
|
+
ORIGINAL QUERY:
|
|
167
|
+
${userQuery}
|
|
168
|
+
|
|
169
|
+
ISSUES FOUND:
|
|
170
|
+
${issueList}
|
|
171
|
+
|
|
172
|
+
ORIGINAL RESPONSE:
|
|
173
|
+
---
|
|
174
|
+
${originalResponse.slice(0, 4000)}
|
|
175
|
+
---
|
|
176
|
+
|
|
177
|
+
Generate an improved response that addresses ALL issues listed above.
|
|
178
|
+
Focus especially on critical and major issues.
|
|
179
|
+
Maintain what was good about the original response.`;
|
|
180
|
+
}
|
|
181
|
+
// ============================================================================
|
|
182
|
+
// TOOL PATTERN LEARNING
|
|
183
|
+
// ============================================================================
|
|
184
|
+
/**
|
|
185
|
+
* Tool pattern tracker for learning optimal sequences
|
|
186
|
+
*/
|
|
187
|
+
export class ToolPatternTracker {
|
|
188
|
+
patterns = new Map();
|
|
189
|
+
currentSequence = [];
|
|
190
|
+
currentTaskType = 'general';
|
|
191
|
+
sequenceStartTime = 0;
|
|
192
|
+
/**
|
|
193
|
+
* Start tracking a new task
|
|
194
|
+
*/
|
|
195
|
+
startTask(taskType) {
|
|
196
|
+
this.currentTaskType = taskType;
|
|
197
|
+
this.currentSequence = [];
|
|
198
|
+
this.sequenceStartTime = Date.now();
|
|
199
|
+
}
|
|
200
|
+
/**
|
|
201
|
+
* Record a tool use
|
|
202
|
+
*/
|
|
203
|
+
recordToolUse(toolName, success) {
|
|
204
|
+
this.currentSequence.push(toolName);
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* Complete the current task and record the pattern
|
|
208
|
+
*/
|
|
209
|
+
completeTask(success) {
|
|
210
|
+
if (this.currentSequence.length === 0)
|
|
211
|
+
return;
|
|
212
|
+
const duration = Date.now() - this.sequenceStartTime;
|
|
213
|
+
const patternKey = this.currentSequence.join('→');
|
|
214
|
+
let patterns = this.patterns.get(this.currentTaskType);
|
|
215
|
+
if (!patterns) {
|
|
216
|
+
patterns = [];
|
|
217
|
+
this.patterns.set(this.currentTaskType, patterns);
|
|
218
|
+
}
|
|
219
|
+
// Find existing pattern or create new
|
|
220
|
+
let existing = patterns.find(p => p.toolSequence.join('→') === patternKey);
|
|
221
|
+
if (existing) {
|
|
222
|
+
// Update statistics
|
|
223
|
+
existing.occurrences++;
|
|
224
|
+
existing.successRate = (existing.successRate * (existing.occurrences - 1) + (success ? 1 : 0)) / existing.occurrences;
|
|
225
|
+
existing.avgDuration = (existing.avgDuration * (existing.occurrences - 1) + duration) / existing.occurrences;
|
|
226
|
+
}
|
|
227
|
+
else {
|
|
228
|
+
// Create new pattern
|
|
229
|
+
patterns.push({
|
|
230
|
+
taskType: this.currentTaskType,
|
|
231
|
+
toolSequence: [...this.currentSequence],
|
|
232
|
+
successRate: success ? 1 : 0,
|
|
233
|
+
avgDuration: duration,
|
|
234
|
+
occurrences: 1,
|
|
235
|
+
});
|
|
236
|
+
}
|
|
237
|
+
// Sort by success rate
|
|
238
|
+
patterns.sort((a, b) => b.successRate - a.successRate);
|
|
239
|
+
// Keep top 10 patterns per task type
|
|
240
|
+
if (patterns.length > 10) {
|
|
241
|
+
patterns.length = 10;
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
/**
|
|
245
|
+
* Get recommended tool sequence for a task type
|
|
246
|
+
*/
|
|
247
|
+
getRecommendedSequence(taskType) {
|
|
248
|
+
const patterns = this.patterns.get(taskType);
|
|
249
|
+
if (!patterns || patterns.length === 0)
|
|
250
|
+
return null;
|
|
251
|
+
// Return the most successful pattern with enough occurrences
|
|
252
|
+
const reliable = patterns.find(p => p.occurrences >= 3 && p.successRate >= 0.7);
|
|
253
|
+
return reliable?.toolSequence ?? patterns[0]?.toolSequence ?? null;
|
|
254
|
+
}
|
|
255
|
+
/**
|
|
256
|
+
* Get all learned patterns
|
|
257
|
+
*/
|
|
258
|
+
getAllPatterns() {
|
|
259
|
+
return new Map(this.patterns);
|
|
260
|
+
}
|
|
261
|
+
/**
|
|
262
|
+
* Export patterns for persistence
|
|
263
|
+
*/
|
|
264
|
+
exportPatterns() {
|
|
265
|
+
const result = {};
|
|
266
|
+
for (const [key, value] of this.patterns) {
|
|
267
|
+
result[key] = value;
|
|
268
|
+
}
|
|
269
|
+
return result;
|
|
270
|
+
}
|
|
271
|
+
/**
|
|
272
|
+
* Import patterns from persistence
|
|
273
|
+
*/
|
|
274
|
+
importPatterns(data) {
|
|
275
|
+
this.patterns.clear();
|
|
276
|
+
for (const [key, value] of Object.entries(data)) {
|
|
277
|
+
this.patterns.set(key, value);
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
/**
|
|
282
|
+
* Quick heuristic-based quality scoring (no LLM needed)
|
|
283
|
+
*/
|
|
284
|
+
export function quickQualityScore(response, toolCalls) {
|
|
285
|
+
let correctness = 50;
|
|
286
|
+
let completeness = 50;
|
|
287
|
+
let efficiency = 50;
|
|
288
|
+
let maintainability = 50;
|
|
289
|
+
let security = 50;
|
|
290
|
+
// Tool call success rate affects correctness
|
|
291
|
+
if (toolCalls.length > 0) {
|
|
292
|
+
const successRate = toolCalls.filter(t => t.success).length / toolCalls.length;
|
|
293
|
+
correctness = Math.round(50 + successRate * 40);
|
|
294
|
+
}
|
|
295
|
+
// Response length indicates completeness
|
|
296
|
+
if (response.length > 1000)
|
|
297
|
+
completeness += 15;
|
|
298
|
+
if (response.length > 3000)
|
|
299
|
+
completeness += 10;
|
|
300
|
+
if (response.length < 200)
|
|
301
|
+
completeness -= 20;
|
|
302
|
+
// Code blocks indicate actual implementation
|
|
303
|
+
const codeBlocks = (response.match(/```/g) || []).length / 2;
|
|
304
|
+
if (codeBlocks >= 1)
|
|
305
|
+
completeness += 10;
|
|
306
|
+
if (codeBlocks >= 3)
|
|
307
|
+
completeness += 5;
|
|
308
|
+
// Check for common patterns
|
|
309
|
+
if (/error|exception|try.*catch/i.test(response)) {
|
|
310
|
+
maintainability += 10; // Error handling
|
|
311
|
+
}
|
|
312
|
+
if (/\bconst\b|\blet\b/.test(response)) {
|
|
313
|
+
maintainability += 5; // Modern JS
|
|
314
|
+
}
|
|
315
|
+
if (/async|await|Promise/.test(response)) {
|
|
316
|
+
efficiency += 5; // Async patterns
|
|
317
|
+
}
|
|
318
|
+
// Security indicators
|
|
319
|
+
if (/validate|sanitize|escape/i.test(response))
|
|
320
|
+
security += 10;
|
|
321
|
+
if (/sql\s*injection|xss|csrf/i.test(response.toLowerCase()))
|
|
322
|
+
security -= 10; // Mentions vulnerabilities without fixing
|
|
323
|
+
// Bound scores
|
|
324
|
+
const bound = (n) => Math.max(0, Math.min(100, n));
|
|
325
|
+
correctness = bound(correctness);
|
|
326
|
+
completeness = bound(completeness);
|
|
327
|
+
efficiency = bound(efficiency);
|
|
328
|
+
maintainability = bound(maintainability);
|
|
329
|
+
security = bound(security);
|
|
330
|
+
const overall = Math.round(correctness * 0.3 +
|
|
331
|
+
completeness * 0.25 +
|
|
332
|
+
efficiency * 0.2 +
|
|
333
|
+
maintainability * 0.15 +
|
|
334
|
+
security * 0.1);
|
|
335
|
+
const breakdown = [
|
|
336
|
+
`Correctness: ${correctness}`,
|
|
337
|
+
`Completeness: ${completeness}`,
|
|
338
|
+
`Efficiency: ${efficiency}`,
|
|
339
|
+
`Maintainability: ${maintainability}`,
|
|
340
|
+
`Security: ${security}`,
|
|
341
|
+
].join(' | ');
|
|
342
|
+
return {
|
|
343
|
+
overall,
|
|
344
|
+
correctness,
|
|
345
|
+
completeness,
|
|
346
|
+
efficiency,
|
|
347
|
+
maintainability,
|
|
348
|
+
security,
|
|
349
|
+
breakdown,
|
|
350
|
+
};
|
|
351
|
+
}
|
|
352
|
+
// ============================================================================
|
|
353
|
+
// TASK TYPE CLASSIFICATION
|
|
354
|
+
// ============================================================================
|
|
355
|
+
/**
|
|
356
|
+
* Classify task type from user query for pattern matching
|
|
357
|
+
*/
|
|
358
|
+
export function classifyTaskType(query) {
|
|
359
|
+
const q = query.toLowerCase();
|
|
360
|
+
if (/\b(bug|fix|error|issue|broken|doesn't work|not working)\b/.test(q)) {
|
|
361
|
+
return 'bug-fix';
|
|
362
|
+
}
|
|
363
|
+
if (/\b(add|create|implement|build|make|new)\b/.test(q)) {
|
|
364
|
+
return 'feature-add';
|
|
365
|
+
}
|
|
366
|
+
if (/\b(refactor|clean|improve|optimize|simplify)\b/.test(q)) {
|
|
367
|
+
return 'refactor';
|
|
368
|
+
}
|
|
369
|
+
if (/\b(test|spec|coverage)\b/.test(q)) {
|
|
370
|
+
return 'testing';
|
|
371
|
+
}
|
|
372
|
+
if (/\b(explain|what|how|why|understand)\b/.test(q)) {
|
|
373
|
+
return 'explanation';
|
|
374
|
+
}
|
|
375
|
+
if (/\b(review|check|analyze|audit)\b/.test(q)) {
|
|
376
|
+
return 'review';
|
|
377
|
+
}
|
|
378
|
+
if (/\b(deploy|release|publish|ship)\b/.test(q)) {
|
|
379
|
+
return 'deployment';
|
|
380
|
+
}
|
|
381
|
+
if (/\b(config|setup|install|configure)\b/.test(q)) {
|
|
382
|
+
return 'configuration';
|
|
383
|
+
}
|
|
384
|
+
return 'general';
|
|
385
|
+
}
|
|
386
|
+
export const DEFAULT_ALPHA_CONFIG = {
|
|
387
|
+
dualResponseEnabled: true,
|
|
388
|
+
selfCritiqueEnabled: true,
|
|
389
|
+
patternLearningEnabled: true,
|
|
390
|
+
minQualityThreshold: 60,
|
|
391
|
+
maxCritiqueIterations: 2,
|
|
392
|
+
};
|
|
393
|
+
/**
|
|
394
|
+
* Main AlphaZero Engine coordinating all components
|
|
395
|
+
*/
|
|
396
|
+
export class AlphaZeroEngine {
|
|
397
|
+
config;
|
|
398
|
+
patternTracker;
|
|
399
|
+
sessionStats;
|
|
400
|
+
constructor(config = {}) {
|
|
401
|
+
this.config = { ...DEFAULT_ALPHA_CONFIG, ...config };
|
|
402
|
+
this.patternTracker = new ToolPatternTracker();
|
|
403
|
+
this.sessionStats = {
|
|
404
|
+
dualResponsesGenerated: 0,
|
|
405
|
+
critiqueIterations: 0,
|
|
406
|
+
improvementsApplied: 0,
|
|
407
|
+
patternsLearned: 0,
|
|
408
|
+
};
|
|
409
|
+
}
|
|
410
|
+
/**
|
|
411
|
+
* Start tracking a task
|
|
412
|
+
*/
|
|
413
|
+
startTask(userQuery) {
|
|
414
|
+
const taskType = classifyTaskType(userQuery);
|
|
415
|
+
this.patternTracker.startTask(taskType);
|
|
416
|
+
}
|
|
417
|
+
/**
|
|
418
|
+
* Record a tool call
|
|
419
|
+
*/
|
|
420
|
+
recordToolCall(toolName, success) {
|
|
421
|
+
this.patternTracker.recordToolUse(toolName, success);
|
|
422
|
+
}
|
|
423
|
+
/**
|
|
424
|
+
* Complete current task
|
|
425
|
+
*/
|
|
426
|
+
completeTask(success) {
|
|
427
|
+
this.patternTracker.completeTask(success);
|
|
428
|
+
if (success) {
|
|
429
|
+
this.sessionStats.patternsLearned++;
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
/**
|
|
433
|
+
* Get recommended tools for current task type
|
|
434
|
+
*/
|
|
435
|
+
getRecommendedTools(taskType) {
|
|
436
|
+
return this.patternTracker.getRecommendedSequence(taskType);
|
|
437
|
+
}
|
|
438
|
+
/**
|
|
439
|
+
* Score a response
|
|
440
|
+
*/
|
|
441
|
+
scoreResponse(response, toolCalls) {
|
|
442
|
+
return quickQualityScore(response, toolCalls);
|
|
443
|
+
}
|
|
444
|
+
/**
|
|
445
|
+
* Check if response needs improvement
|
|
446
|
+
*/
|
|
447
|
+
needsImprovement(score) {
|
|
448
|
+
return score.overall < this.config.minQualityThreshold;
|
|
449
|
+
}
|
|
450
|
+
/**
|
|
451
|
+
* Get session statistics
|
|
452
|
+
*/
|
|
453
|
+
getStats() {
|
|
454
|
+
return { ...this.sessionStats };
|
|
455
|
+
}
|
|
456
|
+
/**
|
|
457
|
+
* Export learned patterns
|
|
458
|
+
*/
|
|
459
|
+
exportLearning() {
|
|
460
|
+
return {
|
|
461
|
+
patterns: this.patternTracker.exportPatterns(),
|
|
462
|
+
stats: { ...this.sessionStats },
|
|
463
|
+
};
|
|
464
|
+
}
|
|
465
|
+
/**
|
|
466
|
+
* Import learned patterns
|
|
467
|
+
*/
|
|
468
|
+
importLearning(data) {
|
|
469
|
+
if (data.patterns) {
|
|
470
|
+
this.patternTracker.importPatterns(data.patterns);
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
/**
|
|
474
|
+
* Increment dual response counter
|
|
475
|
+
*/
|
|
476
|
+
recordDualResponse() {
|
|
477
|
+
this.sessionStats.dualResponsesGenerated++;
|
|
478
|
+
}
|
|
479
|
+
/**
|
|
480
|
+
* Increment critique counter
|
|
481
|
+
*/
|
|
482
|
+
recordCritique() {
|
|
483
|
+
this.sessionStats.critiqueIterations++;
|
|
484
|
+
}
|
|
485
|
+
/**
|
|
486
|
+
* Increment improvement counter
|
|
487
|
+
*/
|
|
488
|
+
recordImprovement() {
|
|
489
|
+
this.sessionStats.improvementsApplied++;
|
|
490
|
+
}
|
|
491
|
+
/**
|
|
492
|
+
* Get configuration
|
|
493
|
+
*/
|
|
494
|
+
getConfig() {
|
|
495
|
+
return { ...this.config };
|
|
496
|
+
}
|
|
497
|
+
/**
|
|
498
|
+
* Update configuration
|
|
499
|
+
*/
|
|
500
|
+
updateConfig(updates) {
|
|
501
|
+
this.config = { ...this.config, ...updates };
|
|
502
|
+
}
|
|
503
|
+
}
|
|
504
|
+
// ============================================================================
|
|
505
|
+
// SINGLETON INSTANCE
|
|
506
|
+
// ============================================================================
|
|
507
|
+
let engineInstance = null;
|
|
508
|
+
/**
|
|
509
|
+
* Get the global AlphaZero engine instance
|
|
510
|
+
*/
|
|
511
|
+
export function getAlphaZeroEngine() {
|
|
512
|
+
if (!engineInstance) {
|
|
513
|
+
engineInstance = new AlphaZeroEngine();
|
|
514
|
+
}
|
|
515
|
+
return engineInstance;
|
|
516
|
+
}
|
|
517
|
+
/**
|
|
518
|
+
* Reset the engine (for testing)
|
|
519
|
+
*/
|
|
520
|
+
export function resetAlphaZeroEngine() {
|
|
521
|
+
engineInstance = null;
|
|
522
|
+
}
|
|
523
|
+
//# sourceMappingURL=alphaZeroEngine.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"alphaZeroEngine.js","sourceRoot":"","sources":["../../src/core/alphaZeroEngine.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAgGH,MAAM,CAAC,MAAM,mBAAmB,GAAuB;IACrD,OAAO,EAAE,IAAI;IACb,YAAY,EAAE,GAAG,EAAG,eAAe;IACnC,YAAY,EAAE,GAAG,EAAG,WAAW;IAC/B,oBAAoB,EAAE,GAAG;IACzB,SAAS,EAAE,KAAK;CACjB,CAAC;AAEF;;GAEG;AACH,MAAM,UAAU,qBAAqB,CACnC,SAAiB,EACjB,SAAiB,EACjB,SAAiB;IAEjB,OAAO;;;EAGP,SAAS;;;;EAIT,SAAS,CAAC,KAAK,CAAC,CAAC,EAAE,IAAI,CAAC;;;;;EAKxB,SAAS,CAAC,KAAK,CAAC,CAAC,EAAE,IAAI,CAAC;;;;;;;;;;;;;;;;;;;;;;EAsBxB,CAAC;AACH,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,uBAAuB,CAAC,QAAgB;IACtD,IAAI,CAAC;QACH,MAAM,KAAK,GAAG,QAAQ,CAAC,KAAK,CAAC,aAAa,CAAC,CAAC;QAC5C,IAAI,CAAC,KAAK;YAAE,OAAO,IAAI,CAAC;QAExB,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAWjC,CAAC;QAEF,MAAM,QAAQ,GAAG,CACf,MAAM,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC;YAC3B,MAAM,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC;YAC5B,MAAM,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;YAC1B,MAAM,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC;YAC3B,MAAM,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C,cAAc,CAAC,cAAc,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QACpD,CAAC;IACH,CAAC;IAED;;OAEG;IACH,kBAAkB;QAChB,IAAI,CAAC,YAAY,CAAC,sBAAsB,EAAE,CAAC;IAC7C,CAAC;IAED;;OAEG;IACH,cAAc;QACZ,IAAI,CAAC,YAAY,CAAC,kBAAkB,EAAE,CAAC;IACzC,CAAC;IAED;;OAEG;IACH,iBAAiB;QACf,IAAI,CAAC,YAAY,CAAC,mBAAmB,EAAE,CAAC;IAC1C,CAAC;IAED;;OAEG;IACH,SAAS;QACP,OAAO,EAAE,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC;IAC5B,CAAC;IAED;;OAEG;IACH,YAAY,CAAC,OAAiC;QAC5C,IAAI,CAAC,MAAM,GAAG,EAAE,GAAG,IAAI,CAAC,MAAM,EAAE,GAAG,OAAO,EAAE,CAAC;IAC/C,CAAC;CACF;AAED,+EAA+E;AAC/E,qBAAqB;AACrB,+EAA+E;AAE/E,IAAI,cAAc,GAA2B,IAAI,CAAC;AAElD;;GAEG;AACH,MAAM,UAAU,kBAAkB;IAChC,IAAI,CAAC,cAAc,EAAE,CAAC;QACpB,cAAc,GAAG,IAAI,eAAe,EAAE,CAAC;IACzC,CAAC;IACD,OAAO,cAAc,CAAC;AACxB,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,oBAAoB;IAClC,cAAc,GAAG,IAAI,CAAC;AACxB,CAAC"}
|
|
@@ -2,8 +2,10 @@
|
|
|
2
2
|
* Performance Metrics Tracker
|
|
3
3
|
*
|
|
4
4
|
* Tracks session performance metrics for analytics and improvement suggestions.
|
|
5
|
+
* Integrated with AlphaZero engine for learning-based improvements.
|
|
5
6
|
*/
|
|
6
7
|
import type { ProviderUsage } from './types.js';
|
|
8
|
+
import { type QualityScore, type ToolCallRecord } from './alphaZeroEngine.js';
|
|
7
9
|
/**
|
|
8
10
|
* Performance metrics for an agent session.
|
|
9
11
|
*/
|
|
@@ -118,5 +120,38 @@ export declare class MetricsTracker {
|
|
|
118
120
|
* Reset all metrics.
|
|
119
121
|
*/
|
|
120
122
|
reset(): void;
|
|
123
|
+
/**
|
|
124
|
+
* Start tracking a new task with AlphaZero
|
|
125
|
+
*/
|
|
126
|
+
startAlphaZeroTask(userQuery: string): void;
|
|
127
|
+
/**
|
|
128
|
+
* Record tool call with AlphaZero pattern learning
|
|
129
|
+
*/
|
|
130
|
+
recordToolCallWithLearning(toolName: string, success: boolean, durationMs?: number): void;
|
|
131
|
+
/**
|
|
132
|
+
* Complete task and record pattern
|
|
133
|
+
*/
|
|
134
|
+
completeAlphaZeroTask(success: boolean): void;
|
|
135
|
+
/**
|
|
136
|
+
* Get quick quality score for a response
|
|
137
|
+
*/
|
|
138
|
+
getResponseQualityScore(response: string, toolCalls: ToolCallRecord[]): QualityScore;
|
|
139
|
+
/**
|
|
140
|
+
* Get recommended tools for a task type
|
|
141
|
+
*/
|
|
142
|
+
getRecommendedTools(userQuery: string): string[] | null;
|
|
143
|
+
/**
|
|
144
|
+
* Get AlphaZero statistics
|
|
145
|
+
*/
|
|
146
|
+
getAlphaZeroStats(): {
|
|
147
|
+
dualResponsesGenerated: number;
|
|
148
|
+
critiqueIterations: number;
|
|
149
|
+
improvementsApplied: number;
|
|
150
|
+
patternsLearned: number;
|
|
151
|
+
};
|
|
152
|
+
/**
|
|
153
|
+
* Get combined performance summary with AlphaZero stats
|
|
154
|
+
*/
|
|
155
|
+
getEnhancedPerformanceSummary(): string;
|
|
121
156
|
}
|
|
122
157
|
//# sourceMappingURL=metricsTracker.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"metricsTracker.d.ts","sourceRoot":"","sources":["../../src/core/metricsTracker.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"metricsTracker.d.ts","sourceRoot":"","sources":["../../src/core/metricsTracker.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,aAAa,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IAK3C;;OAEG;IACH,0BAA0B,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,UAAU,CAAC,EAAE,MAAM,GAAG,IAAI;IAMzF;;OAEG;IACH,qBAAqB,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI;IAK7C;;OAEG;IACH,uBAAuB,CAAC,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,cAAc,EAAE,GAAG,YAAY;IAIpF;;OAEG;IACH,mBAAmB,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,IAAI;IAMvD;;OAEG;IACH,iBAAiB,IAAI;QACnB,sBAAsB,EAAE,MAAM,CAAC;QAC/B,kBAAkB,EAAE,MAAM,CAAC;QAC3B,mBAAmB,EAAE,MAAM,CAAC;QAC5B,eAAe,EAAE,MAAM,CAAC;KACzB;IAKD;;OAEG;IACH,6BAA6B,IAAI,MAAM;CAmBxC"}
|
|
@@ -2,7 +2,9 @@
|
|
|
2
2
|
* Performance Metrics Tracker
|
|
3
3
|
*
|
|
4
4
|
* Tracks session performance metrics for analytics and improvement suggestions.
|
|
5
|
+
* Integrated with AlphaZero engine for learning-based improvements.
|
|
5
6
|
*/
|
|
7
|
+
import { getAlphaZeroEngine, quickQualityScore, classifyTaskType, } from './alphaZeroEngine.js';
|
|
6
8
|
/**
|
|
7
9
|
* Creates default performance metrics.
|
|
8
10
|
*/
|
|
@@ -202,5 +204,70 @@ export class MetricsTracker {
|
|
|
202
204
|
this.errorHandlingScores = [];
|
|
203
205
|
this.traces = [];
|
|
204
206
|
}
|
|
207
|
+
// =========================================================================
|
|
208
|
+
// ALPHA ZERO INTEGRATION
|
|
209
|
+
// =========================================================================
|
|
210
|
+
/**
|
|
211
|
+
* Start tracking a new task with AlphaZero
|
|
212
|
+
*/
|
|
213
|
+
startAlphaZeroTask(userQuery) {
|
|
214
|
+
const engine = getAlphaZeroEngine();
|
|
215
|
+
engine.startTask(userQuery);
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* Record tool call with AlphaZero pattern learning
|
|
219
|
+
*/
|
|
220
|
+
recordToolCallWithLearning(toolName, success, durationMs) {
|
|
221
|
+
this.recordToolCall(success);
|
|
222
|
+
const engine = getAlphaZeroEngine();
|
|
223
|
+
engine.recordToolCall(toolName, success);
|
|
224
|
+
}
|
|
225
|
+
/**
|
|
226
|
+
* Complete task and record pattern
|
|
227
|
+
*/
|
|
228
|
+
completeAlphaZeroTask(success) {
|
|
229
|
+
const engine = getAlphaZeroEngine();
|
|
230
|
+
engine.completeTask(success);
|
|
231
|
+
}
|
|
232
|
+
/**
|
|
233
|
+
* Get quick quality score for a response
|
|
234
|
+
*/
|
|
235
|
+
getResponseQualityScore(response, toolCalls) {
|
|
236
|
+
return quickQualityScore(response, toolCalls);
|
|
237
|
+
}
|
|
238
|
+
/**
|
|
239
|
+
* Get recommended tools for a task type
|
|
240
|
+
*/
|
|
241
|
+
getRecommendedTools(userQuery) {
|
|
242
|
+
const taskType = classifyTaskType(userQuery);
|
|
243
|
+
const engine = getAlphaZeroEngine();
|
|
244
|
+
return engine.getRecommendedTools(taskType);
|
|
245
|
+
}
|
|
246
|
+
/**
|
|
247
|
+
* Get AlphaZero statistics
|
|
248
|
+
*/
|
|
249
|
+
getAlphaZeroStats() {
|
|
250
|
+
const engine = getAlphaZeroEngine();
|
|
251
|
+
return engine.getStats();
|
|
252
|
+
}
|
|
253
|
+
/**
|
|
254
|
+
* Get combined performance summary with AlphaZero stats
|
|
255
|
+
*/
|
|
256
|
+
getEnhancedPerformanceSummary() {
|
|
257
|
+
const baseSummary = this.getPerformanceSummary();
|
|
258
|
+
const alphaStats = this.getAlphaZeroStats();
|
|
259
|
+
const engine = getAlphaZeroEngine();
|
|
260
|
+
const patterns = engine.exportLearning().patterns;
|
|
261
|
+
const patternCount = Object.values(patterns).reduce((sum, p) => sum + p.length, 0);
|
|
262
|
+
const alphaSection = [
|
|
263
|
+
'',
|
|
264
|
+
'AlphaZero Learning:',
|
|
265
|
+
` Dual Responses: ${alphaStats.dualResponsesGenerated}`,
|
|
266
|
+
` Self-Critiques: ${alphaStats.critiqueIterations}`,
|
|
267
|
+
` Improvements Applied: ${alphaStats.improvementsApplied}`,
|
|
268
|
+
` Patterns Learned: ${patternCount}`,
|
|
269
|
+
].join('\n');
|
|
270
|
+
return baseSummary + alphaSection;
|
|
271
|
+
}
|
|
205
272
|
}
|
|
206
273
|
//# sourceMappingURL=metricsTracker.js.map
|