@lisa.ai/agent 2.1.0 → 2.1.1
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/services/llm.service.js +48 -52
- package/dist/utils/parser.js +6 -5
- package/package.json +1 -1
|
@@ -43,8 +43,6 @@ const anthropic_1 = require("@ai-sdk/anthropic");
|
|
|
43
43
|
const google_1 = require("@ai-sdk/google");
|
|
44
44
|
const path = __importStar(require("path"));
|
|
45
45
|
const dotenv = __importStar(require("dotenv"));
|
|
46
|
-
// Force dotenv to load the `.env` file from the agent's root directory
|
|
47
|
-
// regardless of which folder the user is currently running the CLI inside.
|
|
48
46
|
dotenv.config({ path: path.resolve(__dirname, '../../.env') });
|
|
49
47
|
function getProvider(provider, apiKey) {
|
|
50
48
|
if (provider === 'claude') {
|
|
@@ -67,35 +65,41 @@ function getProvider(provider, apiKey) {
|
|
|
67
65
|
async function askLisaForFix(filePath, fileContent, errorLog, modelProvider, apiKey, previousFixAttempt, siblingContext) {
|
|
68
66
|
console.log(`[Lisa.ai Auto-Heal] Requesting fix from ${modelProvider} for ${filePath}...`);
|
|
69
67
|
const model = getProvider(modelProvider, apiKey);
|
|
70
|
-
let prompt =
|
|
71
|
-
A build/compilation error occurred. Your task is to fix the provided file so that the error resolves
|
|
72
|
-
|
|
73
|
-
---
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
4. CRITICAL AGILE RULE: If the error is 'Cannot find module' or 'Property DOES NOT EXIST' and you do NOT know the correct import path or cannot resolve it from the context, you MUST silently comment out the failing import and completely comment out/stub the code that relies on it. Your ultimate goal is to make the file compile successfully so the Agent can proceed to the next file.
|
|
84
|
-
5. FRAMEWORK TEST RULE: If fixing a testing file (\`.spec\` or \`.test\`) and an Angular error happens like 'NullInjectorError: No provider for X', you MUST add X to the 'providers' array in 'TestBed.configureTestingModule' or import the required testing module. If a React testing library error arises, fix the render context.
|
|
85
|
-
6. Return the code wrapped in a markdown code block (\`\`\`typescript ... \`\`\`). Do not include any explanation or intro text.`;
|
|
68
|
+
let prompt = "You are Lisa.ai, an autonomous CI/CD expert platform.\n" +
|
|
69
|
+
"A build/compilation error occurred. Your task is to fix the provided file so that the error resolves.\n\n" +
|
|
70
|
+
"--- Error Log ---\n" + errorLog + "\n\n" +
|
|
71
|
+
"--- Target File Content (" + filePath + ") ---\n" + fileContent + "\n\n" +
|
|
72
|
+
"--- Constraints ---\n" +
|
|
73
|
+
"1. Do not delete business logic unless absolutely necessary to resolve a missing dependency.\n" +
|
|
74
|
+
"2. Do not suppress TypeScript errors with @ts-ignore or any type assertions unless absolutely unavoidable.\n" +
|
|
75
|
+
"3. Fix the underlying type or logic issue.\n" +
|
|
76
|
+
"4. CRITICAL AGILE RULE: If the error is 'Cannot find module' or 'Property DOES NOT EXIST' and you do NOT know the correct import path or cannot resolve it from the context, you MUST silently comment out the failing import and completely comment out/stub the code that relies on it. Your ultimate goal is to make the file compile successfully so the Agent can proceed to the next file.\n" +
|
|
77
|
+
"5. FRAMEWORK TEST RULE: If fixing a testing file ('.spec' or '.test') and an Angular error happens like 'NullInjectorError: No provider for X', you MUST add X to the 'providers' array in 'TestBed.configureTestingModule' or import the required testing module. If a React testing library error arises, fix the render context.\n" +
|
|
78
|
+
"6. CRITICAL ANGULAR RULE: If an Angular component imports 'RouterLink' or uses '[routerLink]' in its template, you MUST provide 'ActivatedRoute' in the providers array or import 'RouterTestingModule'. If it uses HTTP, import 'HttpClientTestingModule'.\n" +
|
|
79
|
+
"7. CRITICAL STANDALONE RULE: If a component has 'standalone: true' in its decorator (check the Sibling Context!), you MUST NOT add it to the 'declarations' array. Instead, you MUST add it to the 'imports' array within 'TestBed.configureTestingModule'.\n" +
|
|
80
|
+
"8. Return the code wrapped in a markdown code block (```typescript ... ```). Do not include any explanation or intro text.";
|
|
86
81
|
if (siblingContext) {
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
82
|
+
const isStandalone = /standalone\s*:\s*true/.test(siblingContext);
|
|
83
|
+
if (isStandalone) {
|
|
84
|
+
const classMatch = siblingContext.match(/export class (\w+)/);
|
|
85
|
+
const className = classMatch ? classMatch[1] : 'the component';
|
|
86
|
+
prompt += "\n\n--- CRITICAL ARCHITECTURAL REQUIREMENT ---\n" +
|
|
87
|
+
"The component " + className + " is marked as STANDALONE (standalone: true).\n" +
|
|
88
|
+
"You MUST add " + className + " to the 'imports' array within 'TestBed.configureTestingModule'.\n" +
|
|
89
|
+
"DO NOT add it to the 'declarations' array. If you omit " + className + " from 'imports', the test will fail.";
|
|
90
|
+
}
|
|
91
|
+
prompt += "\n\n--- Sibling Component / Service Context ---\n" +
|
|
92
|
+
"You are fixing a '.spec' test file. Here is the actual implementation code for the component you are testing.\n" +
|
|
93
|
+
"Use this to identify EXACTLY which imports, Services, and Variables need to be mocked inside your 'TestBed'.\n" +
|
|
94
|
+
siblingContext;
|
|
91
95
|
}
|
|
92
96
|
if (previousFixAttempt) {
|
|
93
97
|
console.log(`[Lisa.ai Auto-Heal] Warning! Agent is looping on ${filePath}. Injecting previous failed context...`);
|
|
94
|
-
prompt +=
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
DO NOT repeat the identical code changes. Try a completely different programming approach, fix syntax typos, or check for missing imports
|
|
98
|
+
prompt += "\n\n--- CRITICAL WARNING ---\n" +
|
|
99
|
+
"You previously attempted to fix this file but the compiler REJECTED your fix!\n" +
|
|
100
|
+
"Here is the previous analysis and failed fix you attempted:\n" +
|
|
101
|
+
previousFixAttempt + "\n\n" +
|
|
102
|
+
"DO NOT repeat the identical code changes. Try a completely different programming approach, fix syntax typos, or check for missing imports.";
|
|
99
103
|
}
|
|
100
104
|
const { text } = await (0, ai_1.generateText)({
|
|
101
105
|
model,
|
|
@@ -107,17 +111,14 @@ DO NOT repeat the identical code changes. Try a completely different programming
|
|
|
107
111
|
async function generateTestForFile(sourceFilePath, sourceFileContent, modelProvider, apiKey) {
|
|
108
112
|
console.log(`[Lisa.ai Coverage] Requesting test generation from ${modelProvider} for ${sourceFilePath}...`);
|
|
109
113
|
const model = getProvider(modelProvider, apiKey);
|
|
110
|
-
const prompt =
|
|
111
|
-
A source file lacks 100% test coverage. Your task is to generate a comprehensive testing suite covering all branches, lines, and functions
|
|
112
|
-
|
|
113
|
-
---
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
2. Do not include any explanation or intro text.
|
|
119
|
-
3. Include all necessary imports assuming a standard testing framework (Jest/Karma/Vitest) is available.
|
|
120
|
-
4. Aim for 100% logic coverage.`;
|
|
114
|
+
const prompt = "You are Lisa.ai, an autonomous CI/CD expert platform.\n" +
|
|
115
|
+
"A source file lacks 100% test coverage. Your task is to generate a comprehensive testing suite covering all branches, lines, and functions.\n\n" +
|
|
116
|
+
"--- Target File Content (" + sourceFilePath + ") ---\n" + sourceFileContent + "\n\n" +
|
|
117
|
+
"--- Constraints ---\n" +
|
|
118
|
+
"1. Return the generated test code wrapped in a markdown code block (```typescript ... ```).\n" +
|
|
119
|
+
"2. Do not include any explanation or intro text.\n" +
|
|
120
|
+
"3. Include all necessary imports assuming a standard testing framework (Jest/Karma/Vitest) is available.\n" +
|
|
121
|
+
"4. Aim for 100% logic coverage.";
|
|
121
122
|
const { text } = await (0, ai_1.generateText)({
|
|
122
123
|
model,
|
|
123
124
|
prompt,
|
|
@@ -128,20 +129,15 @@ ${sourceFileContent}
|
|
|
128
129
|
async function updateTestForFile(sourceFilePath, sourceFileContent, testFilePath, existingTestContent, modelProvider, apiKey) {
|
|
129
130
|
console.log(`[Lisa.ai Coverage] Requesting test update from ${modelProvider} for ${sourceFilePath}...`);
|
|
130
131
|
const model = getProvider(modelProvider, apiKey);
|
|
131
|
-
const prompt =
|
|
132
|
-
A source file lacks 100% test coverage. You must update its existing test suite to achieve full coverage
|
|
133
|
-
|
|
134
|
-
---
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
--- Constraints ---
|
|
141
|
-
1. Return the updated complete test code wrapped in a markdown code block (\`\`\`typescript ... \`\`\`).
|
|
142
|
-
2. Do not include any explanation or intro text.
|
|
143
|
-
3. Append missing tests to the existing suite. Do not delete existing passing tests unless they are fundamentally broken.
|
|
144
|
-
4. Aim for 100% logic coverage across branches, lines, and functions.`;
|
|
132
|
+
const prompt = "You are Lisa.ai, an autonomous CI/CD expert platform.\n" +
|
|
133
|
+
"A source file lacks 100% test coverage. You must update its existing test suite to achieve full coverage.\n\n" +
|
|
134
|
+
"--- Target File Content (" + sourceFilePath + ") ---\n" + sourceFileContent + "\n\n" +
|
|
135
|
+
"--- Existing Test Suite (" + testFilePath + ") ---\n" + existingTestContent + "\n\n" +
|
|
136
|
+
"--- Constraints ---\n" +
|
|
137
|
+
"1. Return the updated complete test code wrapped in a markdown code block (```typescript ... ```).\n" +
|
|
138
|
+
"2. Do not include any explanation or intro text.\n" +
|
|
139
|
+
"3. Append missing tests to the existing suite. Do not delete existing passing tests unless they are fundamentally broken.\n" +
|
|
140
|
+
"4. Aim for 100% logic coverage across branches, lines, and functions.";
|
|
145
141
|
const { text } = await (0, ai_1.generateText)({
|
|
146
142
|
model,
|
|
147
143
|
prompt,
|
package/dist/utils/parser.js
CHANGED
|
@@ -43,24 +43,25 @@ function extractFilePath(errorLog, skipFiles = [], searchDir = process.cwd()) {
|
|
|
43
43
|
const normalizedSkips = skipFiles.map(p => path.resolve(p));
|
|
44
44
|
// 1. First Pass: Try to match typical JS/TS/Vue error patterns with line numbers
|
|
45
45
|
// e.g., "src/components/Button.tsx:12:3 - error"
|
|
46
|
-
|
|
46
|
+
// Supporting Windows absolute paths (e.g. C:\...)
|
|
47
|
+
const exactErrorRegex = /([a-zA-Z]:[a-zA-Z0-9_.\-\/\\]+\.(?:ts|tsx|js|jsx|vue)|[a-zA-Z0-9_.\-\/\\]+\.(?:ts|tsx|js|jsx|vue))(?:\s*[:(])/g;
|
|
47
48
|
let match;
|
|
48
49
|
while ((match = exactErrorRegex.exec(cleanLog)) !== null) {
|
|
49
50
|
const foundPath = match[1];
|
|
50
51
|
if (foundPath) {
|
|
51
|
-
const absoluteFoundPath = path.resolve(searchDir, foundPath);
|
|
52
|
+
const absoluteFoundPath = path.isAbsolute(foundPath) ? foundPath : path.resolve(searchDir, foundPath);
|
|
52
53
|
if (!normalizedSkips.includes(absoluteFoundPath) && fs.existsSync(absoluteFoundPath)) {
|
|
53
54
|
return foundPath;
|
|
54
55
|
}
|
|
55
56
|
}
|
|
56
57
|
}
|
|
57
58
|
// 2. Second Pass (Fallback): Find anything that looks like a source file
|
|
58
|
-
const fallbackRegex = /([a-zA-Z0-9_.\-\/\\]+\.(?:ts|tsx|js|jsx|vue))/g;
|
|
59
|
+
const fallbackRegex = /([a-zA-Z]:[a-zA-Z0-9_.\-\/\\]+\.(?:ts|tsx|js|jsx|vue)|[a-zA-Z0-9_.\-\/\\]+\.(?:ts|tsx|js|jsx|vue))/g;
|
|
59
60
|
let fallbackMatch;
|
|
60
61
|
while ((fallbackMatch = fallbackRegex.exec(cleanLog)) !== null) {
|
|
61
62
|
const foundPath = fallbackMatch[1];
|
|
62
63
|
if (foundPath) {
|
|
63
|
-
const absoluteFoundPath = path.resolve(searchDir, foundPath);
|
|
64
|
+
const absoluteFoundPath = path.isAbsolute(foundPath) ? foundPath : path.resolve(searchDir, foundPath);
|
|
64
65
|
if (!normalizedSkips.includes(absoluteFoundPath) && fs.existsSync(absoluteFoundPath)) {
|
|
65
66
|
return foundPath;
|
|
66
67
|
}
|
|
@@ -72,7 +73,7 @@ function extractFilePath(errorLog, skipFiles = [], searchDir = process.cwd()) {
|
|
|
72
73
|
let symbolMatch;
|
|
73
74
|
const searchedSymbols = new Set();
|
|
74
75
|
// Filter out common JS/Browser built-ins and framework generics that are not user files
|
|
75
|
-
const ignoreList = ['Error', 'TypeError', 'SyntaxError', 'NullInjectorError', 'Object', 'Boolean', 'String', 'Number', 'Array', 'Chrome', 'Windows', 'Linux', 'Macintosh', 'UserContext', 'TestBed', 'Module'];
|
|
76
|
+
const ignoreList = ['Error', 'TypeError', 'SyntaxError', 'NullInjectorError', 'Object', 'Boolean', 'String', 'Number', 'Array', 'Chrome', 'Windows', 'Linux', 'Macintosh', 'UserContext', 'TestBed', 'Module', 'Unexpected', 'Expected', 'ChromeHeadless', 'Users', 'AppData', 'Local', 'Temp', 'Process', 'Component'];
|
|
76
77
|
while ((symbolMatch = symbolRegex.exec(cleanLog)) !== null) {
|
|
77
78
|
const symbolName = symbolMatch[1];
|
|
78
79
|
if (symbolName && !ignoreList.includes(symbolName) && !searchedSymbols.has(symbolName)) {
|