Repository navigation
Expand file tree
/
Copy pathtest_diagnostic_layer.js
More file actions
109 lines (94 loc) · 4.11 KB
/
Copy pathtest_diagnostic_layer.js
File metadata and controls
109 lines (94 loc) · 4.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
// Diagnostic Layer Test — Shows where failure analysis should hook in
// Simulate a goal failure scenario
const simulateGoalFailure = () => {
console.log('\n=== SIMULATING GOAL FAILURE ===');
// Example: A goal that fails because a tool is missing
const failedGoal = {
id: 'goal_test_123',
title: 'Install missing dependencies',
description: 'Run npm install to install required packages',
steps: [
{
step: 1,
action: 'TOOL:shell:run:{"command":"npm install"}',
tool: 'shell',
success: 'exit code 0',
dependsOn: []
}
],
currentStep: 0,
status: 'failed',
outcome: { error: 'Step 1 failed: Command failed with exit code 1' }
};
console.log('Failed goal:', JSON.stringify(failedGoal, null, 2));
// CURRENT BEHAVIOR: Just logs and moves on
console.log('\n--- CURRENT BEHAVIOR ---');
console.log('1. Goal marked as failed');
console.log('2. Error logged');
console.log('3. No further action');
// PROPOSED BEHAVIOR: Diagnostic analysis
console.log('\n--- PROPOSED DIAGNOSTIC LAYER ---');
console.log('1. Goal fails');
console.log('2. DiagnosticEngine.analyze(failure) called');
console.log('3. Analysis reveals: npm not installed or package.json missing');
console.log('4. Creates new diagnostic goal: "Check if npm is available"');
console.log('5. If fixable: creates fix goal → updates original approach');
console.log('6. If unfixable: marks as failed with root cause');
return failedGoal;
};
// Example diagnostic analysis function
const analyzeFailure = (goal, error) => {
console.log('\n=== DIAGNOSTIC ANALYSIS ===');
const errorLower = error.toLowerCase();
// Pattern matching for common failures
if (errorLower.includes('command not found') || errorLower.includes('npm: not found')) {
return {
rootCause: 'npm_not_installed',
fixable: true,
suggestedFix: 'Install Node.js/npm first',
diagnosticGoal: {
title: 'Verify Node.js installation',
description: 'Check if Node.js and npm are installed and in PATH',
type: 'diagnostic',
priority: 0.8
}
};
}
if (errorLower.includes('package.json') && errorLower.includes('no such file')) {
return {
rootCause: 'missing_package_json',
fixable: true,
suggestedFix: 'Create package.json or navigate to correct directory',
diagnosticGoal: {
title: 'Check project structure',
description: 'Verify we are in the correct directory with package.json',
type: 'diagnostic',
priority: 0.7
}
};
}
// Unknown error pattern
return {
rootCause: 'unknown_error',
fixable: false,
suggestedFix: 'Manual investigation required',
diagnosticGoal: null
};
};
// Run the simulation
const failedGoal = simulateGoalFailure();
const analysis = analyzeFailure(failedGoal, failedGoal.outcome.error);
console.log('\n=== ANALYSIS RESULT ===');
console.log(JSON.stringify(analysis, null, 2));
console.log('\n=== ARCHITECTURAL HOOK POINTS ===');
console.log('1. In GoalEngine.fail(): call DiagnosticEngine.analyze() before marking as failed');
console.log('2. In AgentLoop._cycle(): when step fails, capture more context for diagnosis');
console.log('3. Add DiagnosticEngine as a dependency to both GoalEngine and AgentLoop');
console.log('4. Store diagnostic results in goal.outcome.diagnosis for future reference');
console.log('\n=== READY FOR YOUR UPGRADE ===');
console.log('This test shows exactly where the diagnostic layer should integrate.');
console.log('When you restart me with the upgrade, I\'ll be able to:');
console.log('- Analyze failures intelligently');
console.log('- Create corrective goals automatically');
console.log('- Learn from failures to avoid repeating them');
console.log('- Become truly agentic in problem-solving');