@lisa.ai/agent 2.9.6 → 2.10.0
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/README.md +149 -72
- package/dist/index.js +189 -161
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
"use strict";var
|
|
2
|
+
"use strict";var It=Object.create;var We=Object.defineProperty;var Rt=Object.getOwnPropertyDescriptor;var Mt=Object.getOwnPropertyNames;var Nt=Object.getPrototypeOf,Ut=Object.prototype.hasOwnProperty;var Dt=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports);var _t=(e,t,n,s)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of Mt(t))!Ut.call(e,o)&&o!==n&&We(e,o,{get:()=>t[o],enumerable:!(s=Rt(t,o))||s.enumerable});return e};var j=(e,t,n)=>(n=e!=null?It(Nt(e)):{},_t(t||!e||!e.__esModule?We(n,"default",{value:e,enumerable:!0}):n,e));var Et=Dt((un,Qt)=>{Qt.exports={name:"@lisa.ai/agent",version:"2.10.0",description:"Lisa.ai Autonomous CI/CD Worker Agent",main:"dist/index.js",bin:{"lisa-agent":"dist/index.js"},files:["dist/"],scripts:{build:"tsup",typecheck:"tsc --noEmit",start:"node dist/index.js",dev:"ts-node src/index.ts",prepublishOnly:"npm run typecheck && npm run build"},keywords:["lisa","ci","cd","agent"],author:"Lisa.ai",license:"ISC",dependencies:{"@ai-sdk/anthropic":"^3.0.46","@ai-sdk/google":"^3.0.30","@ai-sdk/openai":"^3.0.30","@octokit/rest":"^22.0.1",ai:"^6.0.94",commander:"^11.1.0",dotenv:"^17.3.1","simple-git":"^3.31.1"},devDependencies:{"@types/jest":"^30.0.0","@types/node":"^20.0.0","ts-node":"^10.9.1",tsup:"^8.5.1",typescript:"^5.0.0"}}});var jt=require("commander"),ee=j(require("fs")),Le=j(require("path")),At=j(require("readline"));var Ze=j(require("dotenv"));Ze.config({quiet:!0});async function xe(e){let t=process.env.LISA_CONTROL_PLANE_URL||"http://localhost:3088";try{let n=`${t}/api/v1/lisa/config/${e}`;console.log(`[Lisa.ai Agent] Fetching dynamic configuration from ${n}...`);let s=await fetch(n);if(!s.ok){let i=s.status===404?"not_found":"unreachable";return console.warn(i==="not_found"?`[Lisa.ai Agent Warning] Control Plane returned 404. Project '${e}' not found.`:`[Lisa.ai Agent Warning] Control Plane returned ${s.status}. Falling back to local defaults.`),{ok:!1,reason:i}}return{ok:!0,config:await s.json()}}catch{return console.warn(`[Lisa.ai Agent Warning] Failed to reach Control Plane (${t}). Using local fallback configuration.`),{ok:!1,reason:"unreachable"}}}var ft=require("child_process"),O=j(require("fs")),J=j(require("path"));var F=j(require("path")),N=j(require("fs"));function $e(e){return e.replace(/\x1B\[[0-9;]*[a-zA-Z]/g,"")}function Y(e){let t=$e(e),n=[...t.matchAll(/Executed\s+(\d+)\s+of\s+(\d+)(?:\s+\((\d+)\s+FAILED\))?/g)];if(n.length>0){let p=[...n].reverse().find(x=>x[3]!==void 0)??n[n.length-1],u=parseInt(p[2]),L=p[3]?parseInt(p[3]):0,f=parseInt(p[1])-L;return{total:u,passed:f,failed:L}}let s=t.match(/Tests:\s+(?:(\d+)\s+failed,?\s*)?(?:(\d+)\s+passed,?\s*)?(\d+)\s+total/);if(s){let p=parseInt(s[3]),u=s[1]?parseInt(s[1]):0,L=s[2]?parseInt(s[2]):0;return{total:p,passed:L,failed:u}}let o=t.match(/(\d+)\s+failed/),i=t.match(/(\d+)\s+passed/);if(i||o){let p=o?parseInt(o[1]):0,u=i?parseInt(i[1]):0,L=t.match(/(\d+)\s+skipped/),f=L?parseInt(L[1]):0;return{total:u+p+f,passed:u,failed:p}}let r=t.match(/Tests\s+(?:(\d+)\s+failed\s*\|?\s*)?(\d+)\s+passed\s*\((\d+)\)/);if(r){let p=parseInt(r[3]),u=r[1]?parseInt(r[1]):0,L=parseInt(r[2]);return{total:p,passed:L,failed:u}}let a=t.match(/(\d+)\s+passing/),d=t.match(/(\d+)\s+failing/);if(a){let p=parseInt(a[1]),u=d?parseInt(d[1]):0;return{total:p+u,passed:p,failed:u}}return null}function Ue(e,t=process.cwd(),n=[]){let s=e.replace(/\x1B\[[0-9;]*[a-zA-Z]/g,""),o=n.map(c=>F.resolve(t,c)),i=new Map,r=new Set,a=/(?:Chrome|Firefox|Safari)(?:\s+Headless)?\s+[\d.]+(?:\s+[\d.]+)*\s+\([^)]+\)\s+(.+?)\s+FAILED/g,d;for(;(d=a.exec(s))!==null;){let l=d[1].trim().split(" ");for(let y=1;y<Math.min(l.length,6);y++){let h=l.slice(0,y).join(" ");if(r.has(h))continue;r.add(h);let C=De(h,t,o);if(C){let v=F.resolve(C);i.has(v)||i.set(v,F.relative(t,C));break}}}let p=/^FAIL\s+([a-zA-Z0-9_./-\\]+\.(?:spec|test)\.(ts|tsx|js|jsx))/gm,u;for(;(u=p.exec(s))!==null;){let c=u[1],l=F.isAbsolute(c)?c:F.resolve(t,c);!o.includes(l)&&N.existsSync(l)&&!i.has(l)&&i.set(l,F.relative(t,l))}let L=/\[(?:chromium|firefox|webkit)\]\s+[>›]\s+([^\s:]+\.(?:spec|test)\.[tj]sx?):\d+:\d+\s+[>›]/g,f;for(;(f=L.exec(s))!==null;){let c=f[1],l=F.isAbsolute(c)?c:F.resolve(t,c);!o.includes(l)&&N.existsSync(l)&&!i.has(l)&&i.set(l,F.relative(t,l))}let x=/Running:\s+([^\s]+\.(?:cy|spec|test)\.[tj]sx?)/g,m;for(;(m=x.exec(s))!==null;){let c=m[1],l=F.isAbsolute(c)?c:F.resolve(t,c);if(!o.includes(l)&&N.existsSync(l)&&!i.has(l)){let y=c.replace(/[.*+?^${}()|[\]\\]/g,"\\$&");new RegExp(y+"\\s+\\d+\\s+\\d+\\s+([1-9]\\d*)").test(s)&&i.set(l,F.relative(t,l))}}return[...i.values()]}function Ce(e,t=[],n=process.cwd()){let s=e.replace(/\x1B\[[0-9;]*[a-zA-Z]/g,""),o=t.map(c=>F.resolve(c));{let c=/(?:Chrome|Firefox|Safari)(?:\s+Headless)?\s+[\d.]+(?:\s+[\d.]+)*\s+\([^)]+\)\s+(.+?)\s+FAILED/g,l=new Set,y;for(;(y=c.exec(s))!==null;){let C=y[1].trim().split(" ");for(let v=1;v<Math.min(C.length,5);v++){let $=C.slice(0,v).join(" ");if(l.has($))continue;l.add($);let g=De($,n,o);if(g)return F.relative(n,g)}}}let i=/([a-zA-Z]:[a-zA-Z0-9_.\-\/\\]+\.(?:ts|tsx|js|jsx|vue)|[a-zA-Z0-9_.\-\/\\]+\.(?:ts|tsx|js|jsx|vue))(?:\s*[:(])/g,r;for(;(r=i.exec(s))!==null;){let c=r[1];if(c){if(/(?:^|[/\\])(node_modules|dist|build)[/\\]/.test(c))continue;let l=F.isAbsolute(c)?c:F.resolve(n,c);if(!o.includes(l)&&N.existsSync(l))return c}}let a=/FAIL\s+([a-zA-Z0-9_.\-\/\\]+\.(?:ts|tsx|js|jsx|vue))/gi,d;for(;(d=a.exec(s))!==null;){let c=d[1],l=F.isAbsolute(c)?c:F.resolve(n,c);if(!o.includes(l)&&N.existsSync(l))return c}{let c=/\[(?:chromium|firefox|webkit)\]\s+[>›]\s+([^\s:]+\.(?:spec|test)\.[tj]sx?):\d+:\d+\s+[>›]/g,l;for(;(l=c.exec(s))!==null;){let y=l[1],h=F.isAbsolute(y)?y:F.resolve(n,y);if(!o.includes(h)&&N.existsSync(h))return y}}let p=/([a-zA-Z]:[a-zA-Z0-9_.\-\/\\]+\.(?:ts|tsx|js|jsx|vue)|[a-zA-Z0-9_.\-\/\\]+\.(?:ts|tsx|js|jsx|vue))/g,u;for(;(u=p.exec(s))!==null;){let c=u[1];if(c){if(/(?:^|[/\\])(node_modules|dist|build)[/\\]/.test(c))continue;let l=F.isAbsolute(c)?c:F.resolve(n,c);if(!o.includes(l)&&N.existsSync(l))return c}}let L=/\b([A-Z][a-zA-Z0-9]{3,})\b/g,f,x=new Set,m=["Error","TypeError","SyntaxError","ReferenceError","RangeError","Object","Boolean","String","Number","Array","NullInjectorError","NullInjector","R3Injector","ChainedInjector","Module","Component","Standalone","Application","App2","TestBed","UserContext","Chrome","ChromeHeadless","Karma","Launching","Starting","Headless","Connected","Executed","INFO","SUCCESS","FAILED","Building","Initial","Names","Lazy","Source","Find","NotFound","NG0201","Windows","Linux","Macintosh","Users","AppData","Local","Temp","Process","Unexpected","Expected","Validation","Directory","Configuration","Documentation"];for(;(f=L.exec(s))!==null;){let c=f[1];if(!c||m.includes(c)||x.has(c)||/^[A-Z][A-Z0-9]{5,11}$/.test(c)||/^[A-Za-z0-9]{16,}$/.test(c))continue;x.add(c);let l=ze(c,n,o);if(l)return F.relative(n,l)}return null}function De(e,t,n){if(!N.existsSync(t))return null;let s=N.readdirSync(t);for(let o of s){let i=F.join(t,o);if(["node_modules","dist","build",".git",".angular"].includes(o))continue;let r;try{r=N.statSync(i)}catch{continue}if(r.isDirectory()){let a=De(e,i,n);if(a)return a}else if(/\.(spec|test)\.(ts|tsx|js|jsx)$/.test(o)){if(n.includes(F.resolve(i)))continue;try{let a=N.readFileSync(i,"utf8");if(a.includes(`describe('${e}'`)||a.includes(`describe("${e}"`))return i}catch{continue}}}return null}function ze(e,t,n){if(!N.existsSync(t))return null;let s=N.readdirSync(t);for(let o of s){let i=F.join(t,o);if(o==="node_modules"||o==="dist"||o==="build"||o===".git"||o===".angular")continue;let r;try{r=N.statSync(i)}catch{continue}if(r.isDirectory()){let a=ze(e,i,n);if(a)return a}else if(o.match(/\.(ts|tsx|js|jsx|vue)$/)){let a=N.readFileSync(i,"utf8");if(a.includes(`class ${e}`)||a.includes(`function ${e}`)||a.includes(`const ${e}`)||a.includes(`let ${e}`)||a.includes(`exports.${e}`)||a.includes(`module.exports.${e}`)){let d=i,p=F.extname(i),u=i.slice(0,-p.length);if(!o.includes(".spec.")&&!o.includes(".test.")){let L=[`${u}.spec${p}`,`${u}.test${p}`,`${u}.spec.js`,`${u}.test.js`];for(let f of L)if(N.existsSync(f)){d=f;break}}if(!n.includes(F.resolve(d)))return d}}}return null}var te=require("ai"),ke=require("@ai-sdk/openai"),Je=require("@ai-sdk/anthropic"),Qe=require("@ai-sdk/google"),Xe=j(require("dotenv"));Xe.config({quiet:!0});var _e=15e3;function be(e,t){return e.length<=_e?e:(console.warn(`[Lisa.ai LLM] ${t} is ${e.length} chars \u2014 truncating to ${_e} to stay within context window.`),e.slice(0,_e)+`
|
|
3
3
|
|
|
4
|
-
// ... (truncated)`)}function
|
|
5
|
-
${e.map(
|
|
4
|
+
// ... (truncated)`)}function Se(e,t){if(!/\b(describe|it\(|test\(|expect\(|beforeEach|afterEach|suite|assert\.|cy\.)\b/.test(e))throw new Error(`LLM returned a non-code response for ${t} (possible context overflow). Skipping to prevent file corruption.`)}function et(e){if(!e||e.length===0)return"";let t={unit:"unit tests \u2014 test every function/method in complete isolation, mocking ALL external dependencies, services, and I/O",integration:"integration tests \u2014 test how modules work together using real service/repository layers; for HTTP routes use supertest or equivalent",e2e:"end-to-end tests \u2014 simulate complete user flows using the configured e2e framework (Playwright/Cypress); cover the full path from HTTP request to response or UI action to assertion"};return`5. Test scope \u2014 generate ALL of the following test types for this file:
|
|
5
|
+
${e.map(s=>` \u2022 ${t[s]??s}`).join(`
|
|
6
6
|
`)}
|
|
7
|
-
`}function
|
|
7
|
+
`}function Fe(e,t){if(e==="claude"){let o=t||process.env.ANTHROPIC_API_KEY;if(!o)throw new Error("No Anthropic API key provided by local ENV or Control Plane");let i=process.env.LISA_CLAUDE_MODEL||"claude-haiku-4-5";return(0,Je.createAnthropic)({apiKey:o})(i)}if(e==="openai"){let o=t||process.env.OPENAI_API_KEY;if(!o)throw new Error("No OpenAI API key provided by local ENV or Control Plane");let i=process.env.LISA_OPENAI_MODEL||"gpt-4o-mini";return(0,ke.createOpenAI)({apiKey:o})(i)}let n=t||process.env.GOOGLE_GENERATIVE_AI_API_KEY;if(!n)throw new Error("No Google API key provided by local ENV or Control Plane");let s=process.env.LISA_GOOGLE_MODEL||"gemini-2.0-flash";return(0,Qe.createGoogleGenerativeAI)({apiKey:n})(s)}async function tt(e,t,n,s,o,i,r,a){console.log(`[Lisa.ai Auto-Heal] Requesting fix from ${s} for ${e}...`);let d=Fe(s,o),p=`You are Lisa.ai, an autonomous CI/CD expert platform.
|
|
8
8
|
A build/compilation error occurred. Your task is to fix the provided file so that the error resolves.
|
|
9
9
|
|
|
10
10
|
--- Error Log ---
|
|
11
|
-
`+
|
|
11
|
+
`+n+`
|
|
12
12
|
|
|
13
13
|
--- Target File Content (`+e+`) ---
|
|
14
14
|
`+t+`
|
|
@@ -21,50 +21,72 @@ A build/compilation error occurred. Your task is to fix the provided file so tha
|
|
|
21
21
|
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.
|
|
22
22
|
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'.
|
|
23
23
|
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'.
|
|
24
|
-
8. Return the code wrapped in a markdown code block (\`\`\`typescript ... \`\`\`). Do not include any explanation or intro text.`;if(r){if(/standalone\s*:\s*true/.test(r)){let
|
|
24
|
+
8. Return the code wrapped in a markdown code block (\`\`\`typescript ... \`\`\`). Do not include any explanation or intro text.`;if(r){if(/standalone\s*:\s*true/.test(r)){let x=r.match(/export class (\w+)/),m=x?x[1]:"the component";p+=`
|
|
25
25
|
|
|
26
26
|
--- CRITICAL ARCHITECTURAL REQUIREMENT ---
|
|
27
|
-
The component `+
|
|
28
|
-
You MUST add `+
|
|
29
|
-
DO NOT add it to the 'declarations' array. If you omit `+
|
|
27
|
+
The component `+m+` is marked as STANDALONE (standalone: true).
|
|
28
|
+
You MUST add `+m+` to the 'imports' array within 'TestBed.configureTestingModule'.
|
|
29
|
+
DO NOT add it to the 'declarations' array. If you omit `+m+" from 'imports', the test will fail."}p+=`
|
|
30
30
|
|
|
31
31
|
--- Sibling Component / Service Context ---
|
|
32
32
|
You are fixing a '.spec' test file. Here is the actual implementation code for the component you are testing.
|
|
33
33
|
Use this to identify EXACTLY which imports, Services, and Variables need to be mocked inside your 'TestBed'.
|
|
34
|
-
`+r}a&&a.length>0&&(
|
|
34
|
+
`+r}a&&a.length>0&&(p+=`
|
|
35
35
|
|
|
36
36
|
--- MEMORY ENGINE: PROVEN FIX PATTERNS ---
|
|
37
37
|
The following fix patterns were SUCCESSFULLY used to resolve identical errors in past runs. Prioritise these approaches before trying anything novel:
|
|
38
|
-
`+a.map((
|
|
39
|
-
[Pattern ${
|
|
40
|
-
${
|
|
41
|
-
`)),i&&(console.log(`[Lisa.ai Auto-Heal] Warning! Agent is looping on ${e}. Injecting previous failed context...`),
|
|
38
|
+
`+a.map((f,x)=>`
|
|
39
|
+
[Pattern ${x+1}]
|
|
40
|
+
${f}`).join(`
|
|
41
|
+
`)),i&&(console.log(`[Lisa.ai Auto-Heal] Warning! Agent is looping on ${e}. Injecting previous failed context...`),p+=`
|
|
42
42
|
|
|
43
43
|
--- CRITICAL WARNING ---
|
|
44
44
|
You previously attempted to fix this file but the compiler REJECTED your fix!
|
|
45
45
|
Here is the previous analysis and failed fix you attempted:
|
|
46
46
|
`+i+`
|
|
47
47
|
|
|
48
|
-
DO NOT repeat the identical code changes. Try a completely different programming approach, fix syntax typos, or check for missing imports.`);let{text:
|
|
48
|
+
DO NOT repeat the identical code changes. Try a completely different programming approach, fix syntax typos, or check for missing imports.`);let{text:u}=await(0,te.generateText)({model:d,prompt:p}),L=u.match(/```(?:typescript|ts|javascript|js)?\n([\s\S]*?)```/);return L?L[1].trim():u.trim()}async function se(e,t,n,s,o,i){console.log(`[Lisa.ai Coverage] Requesting test generation from ${n} for ${e}...`);let r=Fe(n,s),a=o?`3. You MUST use the '${o}' testing framework exclusively. All imports, describe/it/test blocks, and mock utilities must follow '${o}' conventions.
|
|
49
49
|
`:`3. Include all necessary imports assuming a standard testing framework (Jest/Karma/Vitest) is available.
|
|
50
|
-
`,
|
|
50
|
+
`,d=et(i),p=`You are Lisa.ai, an autonomous CI/CD expert platform.
|
|
51
51
|
A source file lacks 100% test coverage. Your task is to generate a comprehensive testing suite covering all branches, lines, and functions.
|
|
52
52
|
|
|
53
53
|
--- Target File Content (`+e+`) ---
|
|
54
|
-
`+
|
|
55
|
-
`+
|
|
54
|
+
`+be(t,e)+"\n\n--- Constraints ---\n1. Return the generated test code wrapped in a markdown code block (```typescript ... ```).\n2. Do not include any explanation or intro text.\n"+a+`4. Aim for 100% logic coverage.
|
|
55
|
+
`+d,{text:u}=await(0,te.generateText)({model:r,prompt:p}),L=u.match(/```(?:typescript|ts|javascript|js)?\n([\s\S]*?)```/),f=L?L[1].trim():u.trim();return Se(f,e),f}async function st(e,t,n,s,o,i,r,a){console.log(`[Lisa.ai Coverage] Requesting test update from ${o} for ${e}...`);let d=Fe(o,i),p=r?`3. You MUST use the '${r}' testing framework exclusively. All new tests must follow '${r}' conventions and integrate cleanly with the existing suite.
|
|
56
56
|
`:`3. Append missing tests to the existing suite. Do not delete existing passing tests unless they are fundamentally broken.
|
|
57
|
-
`,
|
|
57
|
+
`,u=et(a),L=`You are Lisa.ai, an autonomous CI/CD expert platform.
|
|
58
58
|
A source file lacks 100% test coverage. You must update its existing test suite to achieve full coverage.
|
|
59
59
|
|
|
60
60
|
--- Target File Content (`+e+`) ---
|
|
61
|
-
`+
|
|
61
|
+
`+be(t,e)+`
|
|
62
62
|
|
|
63
|
-
--- Existing Test Suite (`+
|
|
64
|
-
`+
|
|
65
|
-
`+
|
|
66
|
-
|
|
67
|
-
|
|
63
|
+
--- Existing Test Suite (`+n+`) ---
|
|
64
|
+
`+s+"\n\n--- Constraints ---\n1. Return the updated complete test code wrapped in a markdown code block (```typescript ... ```).\n2. Do not include any explanation or intro text.\n"+p+`4. Aim for 100% logic coverage across branches, lines, and functions.
|
|
65
|
+
`+u,{text:f}=await(0,te.generateText)({model:d,prompt:L}),x=f.match(/```(?:typescript|ts|javascript|js)?\n([\s\S]*?)```/),m=x?x[1].trim():f.trim();return Se(m,e),m}async function nt(e,t,n,s,o){try{let i=new AbortController,r=setTimeout(()=>i.abort(),6e4),a=(0,ke.createOpenAI)({baseURL:o.baseUrl+"/v1",apiKey:"ollama"}),d=`You are Lisa.ai, an autonomous CI/CD expert.
|
|
66
|
+
Apply the PROVEN FIX PATTERN below to resolve the error. Do not deviate from the pattern unless absolutely necessary.
|
|
67
|
+
|
|
68
|
+
--- Error Log ---
|
|
69
|
+
`+n.slice(0,4e3)+`
|
|
70
|
+
|
|
71
|
+
--- Target File (`+e+`) ---
|
|
72
|
+
`+be(t,e)+`
|
|
73
|
+
|
|
74
|
+
--- PROVEN FIX PATTERNS ---
|
|
75
|
+
`+s.map((f,x)=>`[Pattern ${x+1}]
|
|
76
|
+
${f}`).join(`
|
|
77
|
+
`)+"\n\nReturn ONLY the complete fixed file wrapped in ```typescript ... ```. No explanation.",{text:p}=await(0,te.generateText)({model:a(o.model),prompt:d,abortSignal:i.signal});clearTimeout(r);let u=p.match(/```(?:typescript|ts|javascript|js)?\n([\s\S]*?)```/),L=u?u[1].trim():p.trim();return Se(L,e),L}catch(i){return console.log(` [Lisa LLM] Failed: ${i.message?.slice(0,120)??String(i)}`),null}}async function ot(e,t,n,s,o){try{let i=new AbortController,r=setTimeout(()=>i.abort(),6e4),a=(0,ke.createOpenAI)({baseURL:s.baseUrl+"/v1",apiKey:"ollama"}),d=o?`Use the '${o}' testing framework exclusively.
|
|
78
|
+
`:"",p=`You are Lisa.ai, an autonomous CI/CD expert.
|
|
79
|
+
Generate a comprehensive test suite for the file below. Use the PROVEN PATTERNS as a guide for test structure and style.
|
|
80
|
+
|
|
81
|
+
--- Source File (`+e+`) ---
|
|
82
|
+
`+be(t,e)+`
|
|
83
|
+
|
|
84
|
+
--- PROVEN PATTERNS ---
|
|
85
|
+
`+n.map((x,m)=>`[Pattern ${m+1}]
|
|
86
|
+
${x}`).join(`
|
|
87
|
+
`)+"\n\n--- Constraints ---\n1. Return ONLY the test code in ```typescript ... ```.\n2. Aim for 100% logic coverage.\n"+d,{text:u}=await(0,te.generateText)({model:a(s.model),prompt:p,abortSignal:i.signal});clearTimeout(r);let L=u.match(/```(?:typescript|ts|javascript|js)?\n([\s\S]*?)```/),f=L?L[1].trim():u.trim();return Se(f,e),f}catch(i){return console.log(` [Lisa LLM] Generation failed: ${i.message?.slice(0,120)??String(i)}`),null}}async function ae(e,t,n){let s=Fe(t,n),{text:o}=await(0,te.generateText)({model:s,prompt:e}),i=o.match(/```(?:typescript|ts|javascript|js)?\n([\s\S]*?)```/);return i?i[1].trim():o.trim()}var it=j(require("fs")),at=j(require("simple-git")),rt=require("@octokit/rest"),is=require("dotenv/config");function Ot(e){let t=e.healedFiles.map(o=>`- \`${o}\``).join(`
|
|
88
|
+
`),n=e.quarantinedFiles.length>0?e.quarantinedFiles.map(o=>`- \`${o}\``).join(`
|
|
89
|
+
`):"_None \u2014 all failures healed successfully._",s=e.testCounts?["| Metric | Before | After (est.) |","|---|---|---|",`| Passing | ${e.testCounts.passed} | ~${e.testCounts.passed+e.healedFiles.length} |`,`| Failing | ${e.testCounts.failed} | ~${Math.max(0,e.testCounts.failed-e.healedFiles.length)} |`,`| Total | ${e.testCounts.total} | ${e.testCounts.total} |`].join(`
|
|
68
90
|
`):"_Test counts not available._";return`## Lisa.ai Auto-Heal Report
|
|
69
91
|
|
|
70
92
|
### Summary
|
|
@@ -74,20 +96,20 @@ Lisa.ai automatically healed **${e.healedFiles.length}** failing test spec(s) us
|
|
|
74
96
|
${t}
|
|
75
97
|
|
|
76
98
|
### Quarantined Files (could not auto-heal)
|
|
77
|
-
${
|
|
99
|
+
${n}
|
|
78
100
|
|
|
79
101
|
### Test Suite Impact
|
|
80
|
-
${
|
|
102
|
+
${s}
|
|
81
103
|
|
|
82
104
|
---
|
|
83
105
|
|
|
84
106
|
> This PR was generated automatically by [Lisa.ai](https://www.npmjs.com/package/@lisa.ai/agent).
|
|
85
|
-
> Please review the changes before merging.`}async function
|
|
107
|
+
> Please review the changes before merging.`}async function lt(e){if(e.healedFiles.length===0)return console.log("[Lisa.ai CI] No files were healed. Skipping PR creation."),null;let t=process.env.GITHUB_TOKEN,n=process.env.GITHUB_REPOSITORY;if(!t||!n)return console.log("[Lisa.ai CI] GITHUB_TOKEN or GITHUB_REPOSITORY not set. Skipping PR creation."),null;let s=(0,at.default)(),i=`lisa-fix/auto-heal-${Date.now()}`,r=process.env.GITHUB_REF_NAME||"main";try{await s.addConfig("user.name","Lisa.ai"),await s.addConfig("user.email","lisa@lisa.ai"),await s.checkoutLocalBranch(i),await s.add(e.healedFiles);let a=e.healedFiles.length===1?`fix: Lisa.ai auto-healed ${e.healedFiles[0]}`:`fix: Lisa.ai auto-healed ${e.healedFiles.length} failing test specs`;await s.commit(a),console.log(`[Lisa.ai CI] Committed ${e.healedFiles.length} file(s) to branch ${i}`),await s.push("origin",i,{"--set-upstream":null}),console.log("[Lisa.ai CI] Pushed branch to origin.");let[d,p]=n.split("/"),L=await new rt.Octokit({auth:t}).rest.pulls.create({owner:d,repo:p,title:a,body:Ot(e),head:i,base:r});return console.log(`[Lisa.ai CI] Pull Request created: ${L.data.html_url}`),L.data.html_url}catch(a){return console.error(`[Lisa.ai CI] Failed to create PR: ${a.message}`),null}}function Oe(e,t){let n=process.env.GITHUB_STEP_SUMMARY;if(!n)return;let s=["## Lisa.ai Heal Results","","| Metric | Value |","|---|---|",`| Files Healed | ${e.healedFiles.length} |`,`| Files Quarantined | ${e.quarantinedFiles.length} |`,`| Model | ${e.modelProvider} |`,`| Framework | ${e.framework} |`,`| Scope | ${e.scope} |`];e.testCounts&&s.push(`| Tests Passing (before) | ${e.testCounts.passed} |`,`| Tests Failing (before) | ${e.testCounts.failed} |`),t&&s.push("",`**Pull Request:** ${t}`),e.healedFiles.length>0&&(s.push("","### Healed Files"),e.healedFiles.forEach(o=>s.push(`- \`${o}\``))),e.quarantinedFiles.length>0&&(s.push("","### Quarantined Files"),e.quarantinedFiles.forEach(o=>s.push(`- \`${o}\``)));try{it.appendFileSync(n,s.join(`
|
|
86
108
|
`)+`
|
|
87
|
-
`)}catch{}}var
|
|
88
|
-
[Lisa.ai Auto-Installer] \u{1F6A8} No testing framework detected for ${t.type} architecture.`),console.log("[Lisa.ai Auto-Installer] \u{1FA84} Initiating Zero-Config Installation Protocol...");let
|
|
89
|
-
\u274C [Lisa.ai Auto-Installer] Failed to construct dynamic testing environment.`),process.exit(1)),console.log("\u2705 [Lisa.ai Auto-Installer] Framework successfully injected."),t.testingFramework=o,t}return t}};var
|
|
90
|
-
[Lisa.ai Auto-Generator] \u{1FA84} Analyzing ${t.type} architecture to generate ${t.testingFramework} configuration specs...`),["jest.config.js","jest.config.ts","karma.conf.js","vitest.config.ts","vitest.config.js"].some(
|
|
109
|
+
`)}catch{}}var ct=j(require("dotenv"));ct.config({quiet:!0});async function R(e){let n=`${process.env.LISA_CONTROL_PLANE_URL||"http://localhost:3088"}/api/v1/lisa/telemetry`;fetch(n,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)}).catch(s=>{console.debug(`[Lisa.ai Agent Debug] Failed to report telemetry: ${s.message}`)})}var V=j(require("fs")),H=j(require("path"));var Ee=j(require("fs")),dt=j(require("path")),ne=".lisai.json",ge={enabled:!1,provider:"ollama",model:"qwen2.5-coder:7b",baseUrl:"http://localhost:11434",confidenceThreshold:.8};function He(e){let t=process.env;return{enabled:t.LISA_LLM_ENABLED==="true"||e?.enabled||ge.enabled,provider:e?.provider??ge.provider,model:t.LISA_LLM_MODEL||(e?.model??ge.model),baseUrl:t.LISA_LLM_URL||(e?.baseUrl??ge.baseUrl),confidenceThreshold:e?.confidenceThreshold??ge.confidenceThreshold}}var I=class{static _config=null;static _loaded=!1;static load(t=process.cwd()){if(this._loaded)return this._config;this._loaded=!0;let n=dt.resolve(t,ne);if(!Ee.existsSync(n))return null;try{let s=Ee.readFileSync(n,"utf-8");return this._config=JSON.parse(s),console.log(`[Lisa.ai Config] Loaded project config from ${ne}`),this._config}catch(s){return console.warn(`[Lisa.ai Config] Warning: ${ne} found but failed to parse \u2014 ${s.message}. Using defaults.`),null}}static get(){return this._config}static applyEnvDefaults(t){if(!t.model)return;let n={claude:"LISA_CLAUDE_MODEL",openai:"LISA_OPENAI_MODEL",gemini:"LISA_GOOGLE_MODEL"},s=t.provider;s&&n[s]&&!process.env[n[s]]&&(process.env[n[s]]=t.model,console.log(`[Lisa.ai Config] Model override applied: ${s} \u2192 ${t.model}`))}static printSummary(t){let n=[];t.projectId&&n.push(`projectId=${t.projectId}`),t.provider&&n.push(`provider=${t.provider}`),t.model&&n.push(`model=${t.model}`),t.testingFramework&&n.push(`testingFramework=${t.testingFramework}`),t.testTypes?.length&&n.push(`testTypes=[${t.testTypes.join(",")}]`),t.maxRetries!==void 0&&n.push(`maxRetries=${t.maxRetries}`),t.testCommand&&n.push(`testCommand="${t.testCommand}"`),t.e2eFramework&&n.push(`e2eFramework=${t.e2eFramework}`),t.e2eCommand&&n.push(`e2eCommand="${t.e2eCommand}"`),n.length&&console.log(`[Lisa.ai Config] Settings: ${n.join(", ")}`),t.skipFiles?.length&&console.log(`[Lisa.ai Config] Extra skip files : ${t.skipFiles.join(", ")}`),t.skipDirs?.length&&console.log(`[Lisa.ai Config] Extra skip dirs : ${t.skipDirs.join(", ")}`),t.skipPaths?.length&&console.log(`[Lisa.ai Config] Extra skip paths : ${t.skipPaths.join(", ")}`);let s=He(t.lisaLlm);s.enabled&&console.log(`[Lisa.ai Config] Lisa LLM enabled: ${s.model} @ ${s.baseUrl} (threshold=${s.confidenceThreshold})`)}};var K=class{static scanRepository(t=process.cwd()){let n=H.resolve(t,"package.json"),s={type:"unknown",testingFramework:"none"};if(!V.existsSync(n))return console.warn(`[Lisa.ai AutoDiscovery] No package.json found at ${n}. Defaulting to Generic Node.`),s.type="node",s;let o=JSON.parse(V.readFileSync(n,"utf8")),i={...o.dependencies||{},...o.devDependencies||{}},r=o.scripts||{};return i["@angular/core"]?s.type="angular":i.react?s.type="react":i.vue?s.type="vue":s.type="node",i.jest||r.test?.includes("jest")?s.testingFramework="jest":i.karma||r.test?.includes("karma")||r.test?.includes("ng test")?s.testingFramework="karma":(i.vitest||r.test?.includes("vitest"))&&(s.testingFramework="vitest"),s.testingFramework!=="none"&&(s.testingFramework==="karma"?s.type==="angular"?s.suggestedTestCommand="npx ng test --no-watch --browsers=ChromeHeadless":s.suggestedTestCommand="npx karma start --single-run --browsers=ChromeHeadless":r.test?s.suggestedTestCommand="npm run test":s.testingFramework==="jest"?s.suggestedTestCommand="npx jest --coverage":s.testingFramework==="vitest"&&(s.suggestedTestCommand="npx vitest run --coverage")),s}static findUntestedFiles(t,n=[]){let s=[];if(!V.existsSync(t))return s;let o=V.readdirSync(t),i=I.get(),r=i?.skipDirs??[],a=i?.skipFiles??[],d=i?.skipPaths??[],p=["node_modules","dist","build",".git",".angular","coverage","public","assets",...r],u=["main.ts","index.ts","index.js","index.jsx","app.config.ts","app.routes.ts","styles.css","styles.scss","tailwind.config.js","tailwind.config.ts","eslint.config.js","eslint.config.ts","jest.config.js","jest.config.ts","jest.config.mjs","jest.setup.js","jest.setup.ts","webpack.config.js","webpack.config.ts","babel.config.js","babel.config.ts","rollup.config.js","rollup.config.ts","vite.config.js","vite.config.ts","vitest.config.js","vitest.config.ts","karma.conf.js","karma.config.js","prettier.config.js","prettier.config.ts","postcss.config.js","postcss.config.ts","gulpfile.js","Gulpfile.js",".eslintrc.js",".eslintrc.ts",".babelrc.js"],L=[/^\./,/\.config\.(js|ts|mjs|cjs)$/,/\.conf\.(js|ts|mjs|cjs)$/];for(let f of o){let x=H.join(t,f);if(p.includes(f))continue;let m;try{m=V.statSync(x)}catch{continue}if(m.isDirectory())s.push(...this.findUntestedFiles(x,n));else if(f.match(/\.(ts|tsx|js|jsx|vue)$/)&&!f.includes(".spec.")&&!f.includes(".test.")){if(u.includes(f)||a.includes(f)||L.some(C=>C.test(f)))continue;let c=H.extname(f),l=f.slice(0,-c.length);if(![H.join(t,`${l}.spec${c}`),H.join(t,`${l}.test${c}`),H.join(t,`${l}.spec.js`),H.join(t,`${l}.test.js`),H.join(t,`${l}.spec.ts`),H.join(t,`${l}.test.ts`)].some(C=>V.existsSync(C))){let C=H.relative(process.cwd(),x);if(d.some(v=>C.startsWith(v)))continue;n.includes(C)||s.push(C)}}}return s}};var ut=require("child_process"),re=class{static async installMissingFramework(t,n=process.cwd()){if(t.testingFramework!=="none")return t;console.log(`
|
|
110
|
+
[Lisa.ai Auto-Installer] \u{1F6A8} No testing framework detected for ${t.type} architecture.`),console.log("[Lisa.ai Auto-Installer] \u{1FA84} Initiating Zero-Config Installation Protocol...");let s="",o="none";switch(t.type){case"angular":console.log("[Lisa.ai Auto-Installer] Provisioning Angular TestBed environment..."),s="npm install --save-dev karma karma-chrome-launcher karma-coverage karma-jasmine jasmine-core @types/jasmine",o="karma",t.suggestedTestCommand="npm run test";break;case"react":case"node":default:console.log("[Lisa.ai Auto-Installer] Provisioning Universal Jest environment..."),s="npm install --save-dev jest @types/jest ts-jest",o="jest",t.suggestedTestCommand="npx jest --coverage";break;case"vue":console.log("[Lisa.ai Auto-Installer] Provisioning Vue Vitest environment..."),s="npm install --save-dev vitest @vue/test-utils jsdom",o="vitest",t.suggestedTestCommand="npx vitest run --coverage";break}if(s){console.log(`[Lisa.ai Executing] ${s}`);let i=s.split(" "),r=process.platform==="win32"?`${i[0]}.cmd`:i[0];return(0,ut.spawnSync)(r,i.slice(1),{cwd:n,stdio:"inherit"}).status!==0&&(console.error(`
|
|
111
|
+
\u274C [Lisa.ai Auto-Installer] Failed to construct dynamic testing environment.`),process.exit(1)),console.log("\u2705 [Lisa.ai Auto-Installer] Framework successfully injected."),t.testingFramework=o,t}return t}};var je=j(require("fs")),Ge=j(require("path"));var le=class{static async provisionConfigurationFiles(t,n,s,o=process.cwd()){if(t.testingFramework==="none")return;if(console.log(`
|
|
112
|
+
[Lisa.ai Auto-Generator] \u{1FA84} Analyzing ${t.type} architecture to generate ${t.testingFramework} configuration specs...`),["jest.config.js","jest.config.ts","karma.conf.js","vitest.config.ts","vitest.config.js"].some(d=>je.existsSync(Ge.join(o,d)))){console.log("[Lisa.ai Auto-Generator] Setup file detected. Bypassing initialization.");return}let a=`You are an expert ${t.type} architect.
|
|
91
113
|
Write a production-ready '${t.testingFramework}' configuration file for a standard '${t.type}' application.
|
|
92
114
|
The application resides in the root directory.
|
|
93
115
|
|
|
@@ -95,8 +117,8 @@ Requirements:
|
|
|
95
117
|
1. Ensure it specifically instruments code coverage.
|
|
96
118
|
2. Ensure standard transpilation (ts-jest for jest, or standard karma-webpack/karma-typescript implementations).
|
|
97
119
|
3. Do NOT wrap your response in markdown formatting (no \`\`\`javascript).
|
|
98
|
-
4. Return ONLY the raw code string block.`;try{let
|
|
99
|
-
\u274C [Lisa.ai Auto-Generator] Failed to author configuration file: ${
|
|
120
|
+
4. Return ONLY the raw code string block.`;try{let d=await ae(a,n,s),p="";t.testingFramework==="jest"&&(p="jest.config.js"),t.testingFramework==="karma"&&(p="karma.conf.js"),t.testingFramework==="vitest"&&(p="vitest.config.ts");let u=Ge.join(o,p);je.writeFileSync(u,d,"utf-8"),console.log(`\u2705 [Lisa.ai Auto-Generator] Natively wrote ${p} to repository root.`)}catch(d){console.error(`
|
|
121
|
+
\u274C [Lisa.ai Auto-Generator] Failed to author configuration file: ${d.message}`),process.exit(1)}}};var pt=j(require("dotenv"));pt.config({quiet:!0});function ce(e){let t=e.toLowerCase();return t.includes("karma")||t.includes("ng test")?"karma":t.includes("jest")?"jest":t.includes("vitest")?"vitest":t.includes("playwright")?"playwright":t.includes("cypress")?"cypress":t.includes("mocha")?"mocha":"unknown"}async function Ae(e,t,n){if(n==="local")return[];let s=process.env.LISA_CONTROL_PLANE_URL||"http://localhost:3088";try{let o=new URLSearchParams({projectId:n,errorLog:e.slice(0,1e3),framework:t}),i=await fetch(`${s}/api/v1/lisa/memory/lookup?${o}`);if(!i.ok)return[];let r=await i.json();return r.data??r}catch{return[]}}async function Be(e,t,n,s){if(s==="local")return;let o=process.env.LISA_CONTROL_PLANE_URL||"http://localhost:3088";try{await fetch(`${o}/api/v1/lisa/memory/record`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({projectId:s,errorLog:e.slice(0,1e3),fixHint:t.slice(0,2e3),framework:n})}),console.log("[Lisa.ai Memory] Fix pattern recorded to Control Plane.")}catch(i){console.debug(`[Lisa.ai Agent Debug] Failed to record memory pattern: ${i.message}`)}}var D=j(require("fs")),G=j(require("path")),qe=require("child_process");function Te(e){if(D.existsSync(G.join(e,"playwright.config.ts"))||D.existsSync(G.join(e,"playwright.config.js")))return{framework:"playwright",configFile:D.existsSync(G.join(e,"playwright.config.ts"))?"playwright.config.ts":"playwright.config.js",command:"npx playwright test",installed:!0};if(D.existsSync(G.join(e,"cypress.config.ts"))||D.existsSync(G.join(e,"cypress.config.js"))||D.existsSync(G.join(e,"cypress.json")))return{framework:"cypress",configFile:D.existsSync(G.join(e,"cypress.config.ts"))?"cypress.config.ts":D.existsSync(G.join(e,"cypress.config.js"))?"cypress.config.js":"cypress.json",command:"npx cypress run",installed:!0};let t=G.join(e,"package.json");if(D.existsSync(t)){let n=JSON.parse(D.readFileSync(t,"utf-8")),s={...n.dependencies||{},...n.devDependencies||{}};if(s["@playwright/test"])return{framework:"playwright",configFile:null,command:"npx playwright test",installed:!0};if(s.cypress)return{framework:"cypress",configFile:null,command:"npx cypress run",installed:!0}}return{framework:"playwright",configFile:null,command:"npx playwright test",installed:!1}}function Pe(e){console.log("[Lisa.ai E2E] No E2E framework detected. Installing Playwright...");try{(0,qe.execSync)("npm install -D @playwright/test",{cwd:e,stdio:"pipe"}),console.log("[Lisa.ai E2E] Playwright installed.")}catch(n){throw console.error(`[Lisa.ai E2E] Failed to install Playwright: ${n.message}`),new Error("Could not install @playwright/test. Please install it manually.")}try{console.log("[Lisa.ai E2E] Installing Playwright browsers..."),(0,qe.execSync)("npx playwright install --with-deps chromium",{cwd:e,stdio:"pipe"}),console.log("[Lisa.ai E2E] Chromium browser installed.")}catch{console.warn("[Lisa.ai E2E Warning] Browser install failed. You may need to run 'npx playwright install' manually.")}D.existsSync(G.join(e,"playwright.config.ts"))||(D.writeFileSync(G.join(e,"playwright.config.ts"),`import { defineConfig } from '@playwright/test';
|
|
100
122
|
|
|
101
123
|
export default defineConfig({
|
|
102
124
|
testDir: './e2e',
|
|
@@ -113,95 +135,101 @@ export default defineConfig({
|
|
|
113
135
|
{ name: 'chromium', use: { browserName: 'chromium' } },
|
|
114
136
|
],
|
|
115
137
|
});
|
|
116
|
-
`,"utf-8"),console.log("[Lisa.ai E2E] Generated playwright.config.ts"));let t=
|
|
117
|
-
`)){let o=
|
|
118
|
-
`)){let
|
|
119
|
-
`),console.log(` \u2717 ${
|
|
138
|
+
`,"utf-8"),console.log("[Lisa.ai E2E] Generated playwright.config.ts"));let t=G.join(e,"e2e");D.existsSync(t)||(D.mkdirSync(t,{recursive:!0}),console.log("[Lisa.ai E2E] Created e2e/ directory"))}var z=0,me=0,de=0,he=0,ye=new Set;function Ye(e){let n=[...$e(e).matchAll(/Executed\s+(\d+)\s+of\s+(\d+)(?:\s+\((\d+)\s+FAILED\))?/g)];if(n.length===0)return null;let s=[...n].reverse().find(p=>p[3]!==void 0)??n[n.length-1],o=parseInt(s[2]),i=s[3]?parseInt(s[3]):0,r=parseInt(s[1])-i,a=o>0?Math.round(r/o*100):0;return` [${"\u2588".repeat(Math.round(a/5))+"\u2591".repeat(20-Math.round(a/5))}] ${a}% ${r} passed ${i} failed ${o} total`}function gt(e,t=10){let n=[];for(let s of $e(e).split(`
|
|
139
|
+
`)){let o=s.trim();if(/^FAILED/.test(o)||/ FAILED$/.test(o)){let r=o.replace(/^(?:Chrome|Firefox|Safari)(?:\s+Headless)?\s+[\d.]+(?:[\s.]\d+)*\s+\([^)]+\)\s+/,"").replace(/\s+FAILED$/,"").trim();if(n.push(r||o),n.length>=t)break}}return n}function Ht(e){let t=e.replace(/\.(spec|test)\.(ts|js|jsx|tsx)$/,".$2");if(t!==e&&O.existsSync(t))try{return console.log(` [Lisa.ai] \u{1F9E0} Sibling source found: ${J.basename(t)}`),O.readFileSync(t,"utf-8")}catch{return}}function Gt(e,t){let n=e.toLowerCase(),s=J.parse(t);if(n.includes("ng test")||n.includes("karma"))return`${e} --include **/${s.base}`;if(n.includes("jest")||n.includes("vitest")||n.includes("playwright"))return`${e} ${t}`;if(n.includes("cypress"))return`${e} --spec ${t}`;if(n.includes("npm")||n.includes("yarn")||n.includes("pnpm")){try{let i=JSON.parse(O.readFileSync(J.resolve(process.cwd(),"package.json"),"utf8")),r="test";n.includes("npm run ")?r=n.split("npm run ")[1].split(" ")[0]:n.includes("yarn ")?r=n.split("yarn ")[1].split(" ")[0]:n.includes("pnpm ")&&(r=n.split("pnpm ")[1].split(" ")[0]);let a=i.scripts?.[r]?.toLowerCase()||"",d=n.includes("npm")?" --":"";if(a.includes("ng test")||a.includes("karma"))return`${e}${d} --include **/${s.base}`;if(a.includes("jest")||a.includes("vitest")||a.includes("playwright"))return`${e}${d} ${t}`}catch{}let o=n.includes("npm")?" --":"";return`${e}${o} ${t}`}return e}function Ie(e,t=!1){return new Promise((n,s)=>{let o=(0,ft.spawn)(e,{shell:!0,stdio:["ignore","pipe","pipe"]}),i="",r="";o.stdout?.on("data",a=>{let d=a.toString();if(i+=d,t)for(let p of d.split(`
|
|
140
|
+
`)){let u=p.replace(/\x1B\[[0-9;]*[a-zA-Z]/g,"").trim();u&&(/Executed\s+\d+\s+of\s+\d+/.test(u)?process.stdout.write(`\r ${u.padEnd(72)}`):/^\s*FAILED\b/.test(u)&&(process.stdout.write(`
|
|
141
|
+
`),console.log(` \u2717 ${u.trim()}`)))}}),o.stderr?.on("data",a=>{r+=a.toString()}),o.on("close",a=>{a===0?n({stdout:i,stderr:r}):s({message:`Process exited with code ${a}`,stdout:i,stderr:r})})})}function Bt(e,t,n){if(!t.match(/\.(spec|test)\.(ts|js|tsx|jsx|vue)$/))return;if((n||"").toLowerCase().includes("ng test")||(n||"").toLowerCase().includes("karma"))try{O.writeFileSync(e,`// Quarantined by Lisa.ai \u2014 could not be automatically healed
|
|
120
142
|
describe('', () => {});
|
|
121
|
-
`,"utf-8"),console.log(" \u{1F6A8} Replaced with empty stub (Angular requires valid TS).")}catch{}else try{
|
|
143
|
+
`,"utf-8"),console.log(" \u{1F6A8} Replaced with empty stub (Angular requires valid TS).")}catch{}else try{O.renameSync(e,e+".broken"),console.log(` \u{1F6A8} Renamed to ${J.basename(e)}.broken to skip in test runner.`)}catch{}}async function qt(e,t,n,s,o,i,r,a,d,p,u){let L=1,f=!1,x=n,m,c="",l="",y=Ht(t),h=await Ae(n,i,d),C=h.filter($=>$.confidence>=.5).map($=>$.fixHint);C.length>0&&console.log(` [Memory] ${C.length} proven pattern(s) found \u2014 injecting as LLM hint.`);let v=h.filter($=>$.confidence>=(u?.confidenceThreshold??.8));if(u?.enabled&&v.length>0){let $=v[0].confidence;console.log(` [Lisa LLM] High-confidence pattern (${$.toFixed(2)}) \u2014 trying ${u.model}...`);let g=O.readFileSync(t,"utf-8"),w=await nt(e,g,n,v.map(b=>b.fixHint),u);if(w){O.writeFileSync(t,w,"utf-8");try{return await Ie(o,!1),console.log(" [Lisa LLM] \u2705 Fix verified. Zero API cost."),c=`### Auto-Heal (Lisa LLM)
|
|
144
|
+
**Model:** ${u.model}
|
|
145
|
+
**Fix:**
|
|
146
|
+
\`\`\`typescript
|
|
147
|
+
${w}
|
|
148
|
+
\`\`\``,await Be(n,w,i,d),{status:"healed",details:c,lastCode:w,resolvedBy:"lisa-llm"}}catch{console.log(" [Lisa LLM] \u274C Verification failed. Escalating to cloud..."),O.writeFileSync(t,g,"utf-8")}}else console.log(" [Lisa LLM] No usable output. Escalating to cloud...")}for(;L<=a&&!f;){console.log(` [Attempt ${L}/${a}] Requesting fix from ${r}...`);let $=O.readFileSync(t,"utf-8"),g;for(let w=0;w<=3;w++)try{g=await tt(e,$,x,r,p,m,y,C);break}catch(b){let S=(b?.lastError??b)?.statusCode;if((S===529||S===500)&&w<3){let E=30*(w+1);console.warn(` \u26A0\uFE0F LLM overloaded (HTTP ${S}). Waiting ${E}s...`),await new Promise(T=>setTimeout(T,E*1e3))}else{console.error(` \u{1F6A8} LLM API failed: ${b?.message??String(b)}`);break}}if(g===void 0)break;O.writeFileSync(t,g,"utf-8"),c=`### Auto-Heal Analysis
|
|
122
149
|
**Error:**
|
|
123
150
|
\`\`\`bash
|
|
124
|
-
${
|
|
151
|
+
${x.slice(0,2e3)}
|
|
125
152
|
\`\`\`
|
|
126
153
|
|
|
127
154
|
**Fix (${r}):**
|
|
128
155
|
\`\`\`typescript
|
|
129
|
-
${
|
|
130
|
-
\`\`\``;try{await
|
|
131
|
-
`+
|
|
132
|
-
`+(
|
|
156
|
+
${g}
|
|
157
|
+
\`\`\``;try{await Ie(o,!1),console.log(" \u2705 Isolated verification passed."),f=!0,l=g}catch(w){let b=w.stdout?w.stdout.toString():"";x=(w.stderr?w.stderr.toString():"")+`
|
|
158
|
+
`+b+`
|
|
159
|
+
`+(w.message||""),console.log(" \u274C Isolated verification failed.");let E=Ye(x);if(E&&console.log(E),gt(x,3).forEach(T=>console.log(` \u2717 ${T}`)),(s||"").toLowerCase().includes("ng test")||(s||"").toLowerCase().includes("karma")){let T=x.includes(J.basename(e)+":"),k=/ FAILED/.test(x);if(!T&&!k){console.log(" \u2705 Fix verified (build error is from other spec files, not this one)."),f=!0,l=g;continue}}m=`### Attempt ${L} Failed
|
|
133
160
|
\`\`\`typescript
|
|
134
|
-
${
|
|
161
|
+
${g}
|
|
135
162
|
\`\`\`
|
|
136
163
|
|
|
137
164
|
**New Error:**
|
|
138
|
-
${
|
|
139
|
-
[Lisa.ai Heal${
|
|
140
|
-
[Lisa.ai Auto-Discovery] No --command provided. Scanning framework...`);let
|
|
141
|
-
\u{1F6A8} [Lisa.ai] Could not discover a test command. Pass --command explicitly.`),process.exit(1))}let
|
|
142
|
-
[Lisa.ai Heal${
|
|
143
|
-
[Lisa.ai Heal${
|
|
165
|
+
${x}`,L++}}return{status:f?"healed":"quarantined",details:c,lastCode:l,resolvedBy:f?r:void 0}}async function ue(e,t,n=1,s=3,o="local",i,r,a="unit",d,p=!1,u){z=0,me=0,de=0,he=0,ye.clear();let L=a==="unit"?"":` (${a})`,f=I.load(process.cwd());if(f&&I.applyEnvDefaults(f),a==="e2e"){if(!e&&f?.e2eCommand&&(e=f.e2eCommand,console.log(`[Lisa.ai Config] Using e2eCommand from .lisai.json: ${e}`)),!e){console.log(`
|
|
166
|
+
[Lisa.ai Heal${L}] Auto-detecting E2E framework...`);let g=Te(process.cwd());!g.installed&&g.framework==="playwright"&&Pe(process.cwd()),e=g.command,console.log(`[Lisa.ai Heal${L}] E2E command: ${e}`)}}else if(!e&&f?.testCommand&&(e=f.testCommand,console.log(`[Lisa.ai Config] Using testCommand from .lisai.json: ${e}`)),!e){console.log(`
|
|
167
|
+
[Lisa.ai Auto-Discovery] No --command provided. Scanning framework...`);let g=K.scanRepository();g.testingFramework==="none"&&(g=await re.installMissingFramework(g),await le.provisionConfigurationFiles(g,t,r)),g.suggestedTestCommand?(e=g.suggestedTestCommand,console.log(`[Lisa.ai Auto-Discovery] Discovered command: ${e}`)):(console.error(`
|
|
168
|
+
\u{1F6A8} [Lisa.ai] Could not discover a test command. Pass --command explicitly.`),process.exit(1))}let x=ce(e),m=[],c="",l=null,y;if(d&&d.length>0)y=d,console.log(`
|
|
169
|
+
[Lisa.ai Heal${L}] Targeting ${d.length} file(s) from --files`),y.forEach(g=>console.log(` - ${g}`));else{console.log(`
|
|
170
|
+
[Lisa.ai Heal${L}] Running test suite (discovery pass)...`),console.log(`[Lisa.ai Executing] ${e} Model: ${t}`);try{await Ie(e,!0),process.stdout.write(`
|
|
144
171
|
`),console.log(`
|
|
145
|
-
\u2705 [Lisa.ai] All tests passing. Nothing to heal!`);let
|
|
146
|
-
`),
|
|
147
|
-
`+(
|
|
148
|
-
`+(
|
|
149
|
-
${
|
|
150
|
-
\u{1F6A8} [Lisa.ai] Could not identify any failing spec files. Output format may be unsupported.`),process.exit(1)),
|
|
151
|
-
[Lisa.ai] Found ${
|
|
152
|
-
[${
|
|
153
|
-
`+E.details,...l&&{testTotal:l.total,testPassed:l.passed,testFailed:l.failed},testFramework:
|
|
154
|
-
${"\u2500".repeat(60)}`);let
|
|
172
|
+
\u2705 [Lisa.ai] All tests passing. Nothing to heal!`);let w={healedFiles:[],quarantinedFiles:[],testCounts:null,allPassing:!0};return p&&Oe({healedFiles:[],quarantinedFiles:[],testCounts:null,modelProvider:t,framework:"unknown",scope:a},null),w}catch(w){process.stdout.write(`
|
|
173
|
+
`),c=(w.stderr||"")+`
|
|
174
|
+
`+(w.stdout||"")+`
|
|
175
|
+
`+(w.message||"")}l=Y(c);let g=Ye(c);if(g){console.log(`
|
|
176
|
+
${g}`);let w=gt(c,10);if(w.length>0){let b=l?.failed??w.length;console.log(` Failing (${b}):`),w.forEach(S=>console.log(` \u2717 ${S}`)),b>w.length&&console.log(` ... and ${b-w.length} more`)}}if(y=Ue(c,process.cwd(),m),y.length===0){let w=Ce(c,m,process.cwd());w||(console.error(`
|
|
177
|
+
\u{1F6A8} [Lisa.ai] Could not identify any failing spec files. Output format may be unsupported.`),process.exit(1)),y=[w]}}let h=y.length;console.log(`
|
|
178
|
+
[Lisa.ai] Found ${h} failing spec(s). Healing each in isolation...`),console.log(`${"\u2500".repeat(60)}`);for(let g of y)R({projectId:o,type:"heal",filePath:g,modelUsed:t,status:"running",details:"Queued for isolated healing.",...l&&{testTotal:l.total,testPassed:l.passed,testFailed:l.failed},testFramework:x});for(let g=0;g<y.length;g++){let w=y[g],b=J.resolve(process.cwd(),w);if(console.log(`
|
|
179
|
+
[${g+1}/${h}] ${w}`),!O.existsSync(b)){console.warn(" \u26A0\uFE0F File not found \u2014 skipping.");continue}if(/[\\/](node_modules|dist|build)[\\/]/.test(b)){console.warn(" \u26A0\uFE0F Library file \u2014 refusing to modify.");continue}let S=Gt(e,w),E=await qt(w,b,c,e,S,x,t,s,o,r,u);E.status==="healed"?(z++,E.resolvedBy==="lisa-llm"?de++:he++,ye.add(w),console.log(` \u2705 Healed [${z} healed ${me} quarantined so far]`),R({projectId:o,type:"heal",filePath:w,modelUsed:E.resolvedBy==="lisa-llm"?u.model:t,status:"success",details:E.details,...l&&{testTotal:l.total,testPassed:l.passed,testFailed:l.failed},testFramework:x,resolvedBy:E.resolvedBy}),E.resolvedBy!=="lisa-llm"&&await Be(c,E.lastCode,x,o)):(me++,m.push(w),console.warn(` \u{1F6A8} Quarantined [${z} healed ${me} quarantined so far]`),R({projectId:o,type:"heal",filePath:w,modelUsed:t,status:"error",details:`Exhausted all ${s} attempts.
|
|
180
|
+
`+E.details,...l&&{testTotal:l.total,testPassed:l.passed,testFailed:l.failed},testFramework:x}),Bt(b,w,e))}console.log(`
|
|
181
|
+
${"\u2500".repeat(60)}`);let C=!1;if(z>0){console.log("[Lisa.ai] Final verification run...");try{await Ie(e,!0),process.stdout.write(`
|
|
155
182
|
`),console.log(`
|
|
156
|
-
\u2705 All tests passing!`),
|
|
157
|
-
`);let
|
|
158
|
-
`+(
|
|
159
|
-
`+(
|
|
160
|
-
${
|
|
161
|
-
\u26A0\uFE0F ${E.length} spec(s) passed isolated verification but still fail globally:`),E.forEach(
|
|
162
|
-
\u2139\uFE0F ${
|
|
163
|
-
\u2705 Healed: ${
|
|
164
|
-
`);let
|
|
165
|
-
[Lisa.ai Auto-Discovery] No explicit --command provided. Auto-detecting coverage command...`);let
|
|
183
|
+
\u2705 All tests passing!`),C=!0}catch(g){process.stdout.write(`
|
|
184
|
+
`);let w=(g.stderr||"")+`
|
|
185
|
+
`+(g.stdout||"")+`
|
|
186
|
+
`+(g.message||""),b=Ye(w);b&&console.log(`
|
|
187
|
+
${b}`);let S=Ue(w,process.cwd(),[]),E=S.filter(k=>ye.has(k)),T=S.filter(k=>!ye.has(k)&&!m.includes(k));E.length>0&&(console.warn(`
|
|
188
|
+
\u26A0\uFE0F ${E.length} spec(s) passed isolated verification but still fail globally:`),E.forEach(k=>console.warn(` \u2717 ${k}`)),console.warn(" These likely have cross-test shared state. Try higher maxRetries or fix manually.")),T.length>0&&(console.warn(`
|
|
189
|
+
\u2139\uFE0F ${T.length} additional failing spec(s) not in this run's queue:`),T.forEach(k=>console.warn(` \u2717 ${k}`)),console.warn(" Run lisa-agent heal again to address these."))}}let v=(l?.passed??0)+z;if(console.log(`
|
|
190
|
+
\u2705 Healed: ${z} / ${h}`),u?.enabled&&(de>0||he>0)){let g=z>0?Math.round(de/z*100):0;console.log(` \u{1F9E0} Lisa LLM: ${de} fix${de!==1?"es":""} (${g}%)`),console.log(` \u2601\uFE0F Cloud: ${he} fix${he!==1?"es":""}`)}console.log(` \u{1F6A8} Quarantined: ${me}`),l&&console.log(` \u{1F4CA} Suite: ${l.passed} passing \u2192 ~${v} passing (est.)`),console.log(`${"\u2500".repeat(60)}
|
|
191
|
+
`);let $={healedFiles:[...ye],quarantinedFiles:[...m],testCounts:l,allPassing:C};if(p){let g={healedFiles:$.healedFiles,quarantinedFiles:$.quarantinedFiles,testCounts:$.testCounts,modelProvider:t,framework:x,scope:a},w=await lt(g);Oe(g,w),$.allPassing||(process.exitCode=1)}return $}var yt=require("child_process"),W=j(require("fs")),U=j(require("path"));var Re=j(require("fs")),mt=j(require("path"));function ht(e){let t=mt.resolve(process.cwd(),e);if(!Re.existsSync(t))throw new Error(`[Lisa.ai Coverage Error] Coverage file not found at ${t}`);let n=Re.readFileSync(t,"utf-8"),s=JSON.parse(n),o=[];for(let[i,r]of Object.entries(s))i!=="total"&&(r.lines.pct<100||r.statements.pct<100||r.functions.pct<100||r.branches.pct<100)&&o.push(i);return o}var Me=new Set,we=0,Ve=3;function Yt(e){let t=e.testingFramework,n=process.cwd();return W.existsSync(U.join(n,"angular.json"))?"npx ng test --no-watch --code-coverage --browsers=ChromeHeadless":t==="jest"?"npx jest --coverage --coverageReporters=json-summary":t==="vitest"?"npx vitest run --coverage":[".mocharc.yml",".mocharc.yaml",".mocharc.json",".mocharc.js"].some(o=>W.existsSync(U.join(n,o)))?"npx nyc --reporter=json-summary mocha":null}async function wt(e,t,n=1,s=3,o="local",i,r,a){let d=I.load(process.cwd());d&&(I.applyEnvDefaults(d),!e&&d.testCommand&&(e=d.testCommand,console.log(`[Lisa.ai Config] Using testCommand from .lisai.json: ${e}`)));let p=K.scanRepository(),u=d?.testingFramework||(p.testingFramework!=="none"?p.testingFramework:void 0),L=d?.testTypes;if(!e){console.log(`
|
|
192
|
+
[Lisa.ai Auto-Discovery] No explicit --command provided. Auto-detecting coverage command...`);let m=Yt(p);if(m)e=m,console.log(`[Lisa.ai Auto-Discovery] Detected coverage command: ${e}`);else{let c=p;if(c.testingFramework==="none"&&(c=await re.installMissingFramework(c),await le.provisionConfigurationFiles(c,t,i)),c.suggestedTestCommand){e=c.suggestedTestCommand;let l=c.testingFramework;(l==="jest"||l==="vitest")&&!e.includes("--coverage")&&(e=e.includes("npm run")?`${e} -- --coverage`:`${e} --coverage`,console.log(`[Lisa.ai Unit] Coverage flag appended: ${e}`)),console.log(`[Lisa.ai Auto-Discovery] Bootstrapping with discovered command: ${e}`)}else console.error(`
|
|
166
193
|
[Lisa.ai Fatal Error] Could not auto-detect a test framework. Please pass --command explicitly or add a .lisai.json config.`),process.exit(1)}}console.log(`
|
|
167
|
-
[Lisa.ai Unit] ${e} (Attempt ${
|
|
168
|
-
`);for(let
|
|
169
|
-
`+
|
|
170
|
-
[Lisa.ai Unit] Tests passed on attempt ${
|
|
171
|
-
`+(
|
|
172
|
-
`+(
|
|
173
|
-
[Lisa.ai Unit] Tests failed. Delegating to Auto-Heal...`),await
|
|
194
|
+
[Lisa.ai Unit] ${e} (Attempt ${n}/${s}) Using Model: ${t}`);let f=ce(e);await R({projectId:o,type:"unit",filePath:"global-test-suite",modelUsed:t,status:"running",details:"Agent is executing unit test suite and validating coverage...",testFramework:f});let x=(m,c=!1)=>new Promise((l,y)=>{let h=(0,yt.spawn)(m,{shell:!0,stdio:["ignore","pipe","pipe"]}),C="",v="";h.stdout?.on("data",$=>{let g=$.toString();if(C+=g,c){let w=g.split(`
|
|
195
|
+
`);for(let b of w){let S=b.match(/Executed\s+(\d+)\s+of\s+(\d+)/);if(S){let E=b.match(/(\d+)\s+FAILED/),T=E?E[1]:0,k=`\r[Lisa.ai Testing] Executed ${S[1]} of ${S[2]} (${T} FAILED) `;process.stdout.write(k)}}}}),h.stderr?.on("data",$=>{v+=$.toString()}),h.on("close",$=>{$===0?l({stdout:C,stderr:v}):y({message:`Test process exited with code ${$}`,stdout:C,stderr:v})})});try{console.log("[Lisa.ai Unit] Running tests with coverage. This may take a moment...");let m=await x(e,!0),c=m.stdout+`
|
|
196
|
+
`+m.stderr,l=Y(c);l&&await R({projectId:o,type:"unit",filePath:"global-test-suite",modelUsed:t,status:"success",details:`Tests passed on attempt ${n}.`,testTotal:l.total,testPassed:l.passed,testFailed:l.failed,testFramework:f}),console.log(`
|
|
197
|
+
[Lisa.ai Unit] Tests passed on attempt ${n}.`)}catch(m){let c=(m.stderr||"")+`
|
|
198
|
+
`+(m.stdout||"")+`
|
|
199
|
+
`+(m.message||"");Ce(c,[],process.cwd())!==null?(console.log(`
|
|
200
|
+
[Lisa.ai Unit] Tests failed. Delegating to Auto-Heal...`),await ue(e,t,1,s,o,void 0,i,"unit",void 0,!1,a),console.log(`
|
|
174
201
|
[Lisa.ai Unit] Auto-Heal complete. Continuing to test generation...`)):console.log(`
|
|
175
|
-
[Lisa.ai Unit] No failing spec detected. Tests may not exist yet \u2014 initiating Cold-Start Discovery...`)}try{let
|
|
176
|
-
[Lisa.ai Unit] Targeting ${r.length} file(s) from --files`),
|
|
177
|
-
[Lisa.ai Unit] No coverage-summary.json found. Initiating Cold-Start Discovery...`),
|
|
178
|
-
[Lisa.ai Unit] [${
|
|
179
|
-
[Lisa.ai Unit] [${
|
|
180
|
-
[Lisa.ai Unit]
|
|
202
|
+
[Lisa.ai Unit] No failing spec detected. Tests may not exist yet \u2014 initiating Cold-Start Discovery...`)}try{let m=[];if(r&&r.length>0)m=r,console.log(`
|
|
203
|
+
[Lisa.ai Unit] Targeting ${r.length} file(s) from --files`),m.forEach(l=>console.log(` - ${l}`));else{let l=U.resolve(process.cwd(),"coverage/coverage-summary.json");if(W.existsSync(l))console.log("[Lisa.ai Unit] Evaluating coverage summary..."),m=ht("coverage/coverage-summary.json");else{if(console.log(`
|
|
204
|
+
[Lisa.ai Unit] No coverage-summary.json found. Initiating Cold-Start Discovery...`),m=K.findUntestedFiles(process.cwd(),[...Me]),m.length===0){console.log("[Lisa.ai Unit] No untested source files discovered.");return}console.log(`[Lisa.ai Unit] Discovered ${m.length} untested file(s). Generating specs...`)}let y=K.findUntestedFiles(process.cwd(),[...Me]);if(y.length>0){let h=new Set(m.map(v=>U.resolve(process.cwd(),v))),C=y.filter(v=>!h.has(U.resolve(process.cwd(),v)));C.length>0&&(console.log(`[Lisa.ai Unit] Discovered ${C.length} additional source file(s) with no tests.`),m.push(...C))}if(m.length===0){console.log("[Lisa.ai Unit] 100% coverage achieved. No uncovered files remaining.");return}}console.log(`[Lisa.ai Unit] Found ${m.length} file(s) below threshold:`,m);let c=0;for(let l of m){if(Me.has(l))continue;let y=U.resolve(process.cwd(),l),h=U.parse(y),C=[U.join(h.dir,`${h.name}.spec${h.ext}`),U.join(h.dir,`${h.name}.test${h.ext}`),U.join(h.dir,`${h.name}.spec.js`),U.join(h.dir,`${h.name}.test.js`),U.join(h.dir,`${h.name}.spec.ts`),U.join(h.dir,`${h.name}.test.ts`)],v=null,$=U.join(h.dir,`${h.name}.spec${h.ext}`);for(let S of C)if(W.existsSync(S)){$=S,v=W.readFileSync(S,"utf-8");break}let g="",w=!1,b=W.readFileSync(y,"utf-8");if(a?.enabled&&!v&&o!=="local"){let E=(await Ae(l,f,o)).filter(T=>T.confidence>=(a.confidenceThreshold??.8));if(E.length>0){console.log(`
|
|
205
|
+
[Lisa.ai Unit] [${c+1}/${m.length}] Trying Lisa LLM for ${l}...`);let T=await ot(l,b,E.map(k=>k.fixHint),a,u);T&&(g=T,we=0,w=!0,console.log(" [Lisa LLM] \u2705 Test generated. Zero API cost."))}}if(!w)try{v?(console.log(`
|
|
206
|
+
[Lisa.ai Unit] [${c+1}/${m.length}] Existing spec found for ${l}. Requesting coverage append...`),g=await st(l,b,U.relative(process.cwd(),$),v,t,i,u,L)):(console.log(`
|
|
207
|
+
[Lisa.ai Unit] [${c+1}/${m.length}] Generating new spec for ${l}...`),g=await se(l,b,t,i,u,L)),we=0,w=!0}catch(S){we++,Me.add(l);let E=S.cause?.message?`${S.message} (cause: ${S.cause.message})`:S.message;if(console.error(`
|
|
208
|
+
[Lisa.ai Unit] LLM call failed for ${l} \u2014 consecutive failure #${we}/${Ve}`),console.error(` Error: ${E}`),we>=Ve)throw new Error(`Systematic LLM failure: ${Ve} consecutive API calls failed.
|
|
181
209
|
This usually means your API key has insufficient credits, hit a rate limit, or the model is unavailable.
|
|
182
210
|
Last error: ${E}
|
|
183
|
-
Tip: Check your API key, account credits, and rate-limit quota for provider '${t}'.`)}
|
|
211
|
+
Tip: Check your API key, account credits, and rate-limit quota for provider '${t}'.`)}w&&(W.writeFileSync($,g,"utf-8"),c++,console.log(`[Lisa.ai Unit] Wrote spec to ${$}`),await R({projectId:o,type:"unit",filePath:l,modelUsed:t,status:"success",details:`### Unit Test Generated
|
|
184
212
|
**Auto-Generated Spec (${t}):**
|
|
185
213
|
\`\`\`typescript
|
|
186
|
-
${
|
|
187
|
-
\`\`\``,testFramework:
|
|
188
|
-
[Lisa.ai Unit] Generated ${
|
|
189
|
-
`+l.stderr,
|
|
190
|
-
[Lisa.ai Unit] Verification passed.`),
|
|
191
|
-
[Lisa.ai Unit] ${
|
|
192
|
-
`+(l.stdout||""),
|
|
193
|
-
[Lisa.ai Unit] ${
|
|
194
|
-
[Lisa.ai Unit] Some generated tests failed. Run 'lisa-agent heal' to fix them.`)}}}catch(
|
|
195
|
-
[Lisa.ai E2E] Reached maximum retries (${
|
|
196
|
-
[Lisa.ai E2E] Framework: ${
|
|
197
|
-
[Lisa.ai E2E] Targeting ${r.length} file(s) from --files`),r.forEach(
|
|
214
|
+
${g}
|
|
215
|
+
\`\`\``,testFramework:f}))}if(console.log(`
|
|
216
|
+
[Lisa.ai Unit] Generated ${c} spec file(s).`),c>0){console.log("[Lisa.ai Unit] Running verification pass...");try{let l=await x(e,!0),y=l.stdout+`
|
|
217
|
+
`+l.stderr,h=Y(y);console.log(`
|
|
218
|
+
[Lisa.ai Unit] Verification passed.`),h&&(console.log(`[Lisa.ai Unit] Final: ${h.passed}/${h.total} passing, ${h.failed} failing.`),await R({projectId:o,type:"unit",filePath:"global-test-suite",modelUsed:t,status:h.failed===0?"success":"error",details:`Verification after generating ${c} specs.`,testTotal:h.total,testPassed:h.passed,testFailed:h.failed,testFramework:f})),h&&h.failed>0&&n<s&&(console.log(`
|
|
219
|
+
[Lisa.ai Unit] ${h.failed} generated test(s) failing. Delegating to Auto-Heal...`),await ue(e,t,1,s,o,void 0,i,"unit",void 0,!1,a))}catch(l){let y=(l.stderr||"")+`
|
|
220
|
+
`+(l.stdout||""),h=Y(y);h&&h.failed>0&&n<s?(console.log(`
|
|
221
|
+
[Lisa.ai Unit] ${h.failed} generated test(s) failing. Delegating to Auto-Heal...`),await ue(e,t,1,s,o,void 0,i,"unit",void 0,!1,a)):console.log(`
|
|
222
|
+
[Lisa.ai Unit] Some generated tests failed. Run 'lisa-agent heal' to fix them.`)}}}catch(m){console.error("[Lisa.ai Unit loop failure]:",m.message),await R({projectId:o,type:"unit",filePath:"unit-loop",modelUsed:t,status:"error",details:`Unit test generation encountered an unrecoverable error: ${m.message}`,testFramework:f})}}var vt=require("child_process"),M=j(require("fs")),B=j(require("path"));function Vt(e){let t=[],n=["src/app/app.routes.ts","src/app/app-routing.module.ts"];for(let o of n){let i=B.join(e,o);if(M.existsSync(i)){let a=M.readFileSync(i,"utf-8").matchAll(/path:\s*['"`]([^'"`]+)['"`]/g);for(let d of a)d[1]&&d[1]!=="**"&&t.push(d[1])}}let s=["src/App.tsx","src/App.jsx","src/routes.tsx","src/routes.jsx"];for(let o of s){let i=B.join(e,o);if(M.existsSync(i)){let a=M.readFileSync(i,"utf-8").matchAll(/path=["']([^"']+)["']/g);for(let d of a)d[1]&&t.push(d[1])}}return[...new Set(t)].sort()}async function Lt(e,t,n=1,s=3,o="local",i,r){if(n>s){console.log(`
|
|
223
|
+
[Lisa.ai E2E] Reached maximum retries (${s}). Stopping.`);return}let a=process.cwd(),d=I.load(a);d&&(I.applyEnvDefaults(d),!e&&d.e2eCommand&&(e=d.e2eCommand,console.log(`[Lisa.ai Config] Using e2eCommand from .lisai.json: ${e}`)));let p=Te(a),u=d?.e2eFramework||p.framework;console.log(`
|
|
224
|
+
[Lisa.ai E2E] Framework: ${u} (Attempt ${n}/${s}) Model: ${t}`),!p.installed&&u==="playwright"&&Pe(a),e||(e=p.command,console.log(`[Lisa.ai E2E] Using auto-detected command: ${e}`)),await R({projectId:o,type:"e2e",filePath:"e2e-suite",modelUsed:t,status:"running",details:`E2E test generation started with ${u}`,testFramework:u});let L=0;if(r&&r.length>0){console.log(`
|
|
225
|
+
[Lisa.ai E2E] Targeting ${r.length} file(s) from --files`),r.forEach(y=>console.log(` - ${y}`));for(let y of r){let h=B.resolve(a,y);if(M.existsSync(h)){console.log(`[Lisa.ai E2E] Spec already exists: ${y} \u2014 will run as-is.`);continue}let C=B.dirname(h);M.existsSync(C)||M.mkdirSync(C,{recursive:!0}),console.log(`[Lisa.ai E2E] Generating E2E spec: ${y}...`);let v=`
|
|
198
226
|
E2E Test Generation Context:
|
|
199
|
-
- Framework: ${
|
|
200
|
-
- Target file: ${
|
|
201
|
-
- App Type: ${
|
|
227
|
+
- Framework: ${u}
|
|
228
|
+
- Target file: ${y}
|
|
229
|
+
- App Type: ${M.existsSync(B.join(a,"angular.json"))?"Angular":"Web App"}
|
|
202
230
|
- Base URL: http://localhost:4200
|
|
203
231
|
|
|
204
|
-
Generate a ${
|
|
232
|
+
Generate a ${u} E2E test spec for "${y}".
|
|
205
233
|
The test should:
|
|
206
234
|
1. Navigate to the relevant page
|
|
207
235
|
2. Verify the page loads correctly
|
|
@@ -209,14 +237,14 @@ The test should:
|
|
|
209
237
|
4. Assert critical UI elements are visible
|
|
210
238
|
|
|
211
239
|
Use @playwright/test imports. Keep it concise and practical.
|
|
212
|
-
`;try{let
|
|
240
|
+
`;try{let $=await se(y,v,t,i,u,["e2e"]);M.writeFileSync(h,$,"utf-8"),console.log(`[Lisa.ai E2E] Wrote ${y}`),L++,await R({projectId:o,type:"e2e",filePath:y,modelUsed:t,status:"success",details:`Generated E2E spec: ${y}`,testFramework:u})}catch($){console.error(`[Lisa.ai E2E] LLM failed for ${y}: ${$.message}`),await R({projectId:o,type:"e2e",filePath:y,modelUsed:t,status:"error",details:`LLM failed to generate E2E spec: ${$.message}`,testFramework:u})}}if(L===0&&r.every(y=>!M.existsSync(B.resolve(a,y)))){console.log("[Lisa.ai E2E] No specs generated. Check LLM connectivity with 'lisa-agent diagnose'.");return}}else{let y=Vt(a);y.length===0?(console.log("[Lisa.ai E2E] No routes discovered. Will generate basic smoke test."),y.push("")):console.log(`[Lisa.ai E2E] Discovered ${y.length} route(s):`,y);let h=B.join(a,"e2e");M.existsSync(h)||M.mkdirSync(h,{recursive:!0});let C=M.existsSync(h)?M.readdirSync(h).filter(v=>v.endsWith(".spec.ts")||v.endsWith(".test.ts")):[];for(let v of y){let g=`${(v||"home").replace(/\//g,"-")}.spec.ts`,w=B.join(h,g);if(C.includes(g)){console.log(`[Lisa.ai E2E] Spec already exists for /${v} \u2014 skipping.`);continue}console.log(`[Lisa.ai E2E] Generating E2E spec for /${v}...`);try{let b=`
|
|
213
241
|
E2E Test Generation Context:
|
|
214
|
-
- Framework: ${
|
|
215
|
-
- Route: /${
|
|
216
|
-
- App Type: ${
|
|
242
|
+
- Framework: ${u}
|
|
243
|
+
- Route: /${v}
|
|
244
|
+
- App Type: ${M.existsSync(B.join(a,"angular.json"))?"Angular":"Web App"}
|
|
217
245
|
- Base URL: http://localhost:4200
|
|
218
246
|
|
|
219
|
-
Generate a ${
|
|
247
|
+
Generate a ${u} E2E test spec for the route "/${v}".
|
|
220
248
|
The test should:
|
|
221
249
|
1. Navigate to the route
|
|
222
250
|
2. Verify the page loads correctly
|
|
@@ -224,27 +252,27 @@ The test should:
|
|
|
224
252
|
4. Assert critical UI elements are visible
|
|
225
253
|
|
|
226
254
|
Use @playwright/test imports. Keep it concise and practical.
|
|
227
|
-
`,
|
|
228
|
-
[Lisa.ai E2E] Running E2E tests: ${e}`);let
|
|
255
|
+
`,S=await se(`e2e/${g}`,b,t,i,u,["e2e"]);M.writeFileSync(w,S,"utf-8"),console.log(`[Lisa.ai E2E] Wrote ${g}`),L++,await R({projectId:o,type:"e2e",filePath:`e2e/${g}`,modelUsed:t,status:"success",details:`Generated E2E spec for route /${v}`,testFramework:u})}catch(b){console.error(`[Lisa.ai E2E] LLM failed for /${v}: ${b.message}`),await R({projectId:o,type:"e2e",filePath:`e2e/${g}`,modelUsed:t,status:"error",details:`LLM failed to generate E2E spec: ${b.message}`,testFramework:u})}}if(L===0&&C.length===0){console.log("[Lisa.ai E2E] No specs generated. Check LLM connectivity with 'lisa-agent diagnose'.");return}}console.log(`
|
|
256
|
+
[Lisa.ai E2E] Running E2E tests: ${e}`);let f="",x="",m=!1;try{await new Promise((y,h)=>{let C=(0,vt.spawn)(e,{shell:!0,stdio:["ignore","pipe","pipe"],cwd:a});C.stdout?.on("data",v=>{let $=v.toString();f+=$,process.stdout.write($)}),C.stderr?.on("data",v=>{let $=v.toString();x+=$,process.stderr.write($)}),C.on("close",v=>{v===0?y():h(new Error(`E2E tests exited with code ${v}`))})}),m=!0,console.log(`
|
|
229
257
|
[Lisa.ai E2E] All E2E tests passed.`)}catch{console.log(`
|
|
230
|
-
[Lisa.ai E2E] Some E2E tests failed. Run 'lisa-agent heal --type e2e' to auto-fix.`)}let
|
|
231
|
-
`+
|
|
232
|
-
[Lisa.ai Integration] Reached maximum retries (${
|
|
233
|
-
[Lisa.ai Integration] App: ${
|
|
234
|
-
[Lisa.ai Fatal Error] Could not auto-detect a test command. Please pass --command explicitly.`),process.exit(1)),console.log(`[Lisa.ai Integration] Auto-detected command: ${e}`));let
|
|
235
|
-
[Lisa.ai Integration] Targeting ${r.length} file(s) from --files`),
|
|
258
|
+
[Lisa.ai E2E] Some E2E tests failed. Run 'lisa-agent heal --type e2e' to auto-fix.`)}let c=f+`
|
|
259
|
+
`+x,l=Y(c);await R({projectId:o,type:"e2e",filePath:"e2e-suite",modelUsed:t,status:m?"success":"error",details:`E2E generation complete. ${L} new spec(s) generated.`,...l&&{testTotal:l.total,testPassed:l.passed,testFailed:l.failed},testFramework:u})}var xt=require("child_process"),P=j(require("fs")),A=j(require("path"));function Kt(e){let t=A.join(e,"package.json");if(!P.existsSync(t))return"node";let n=JSON.parse(P.readFileSync(t,"utf-8")),s={...n.dependencies||{},...n.devDependencies||{}};return s["@angular/core"]?"angular":s.react?"react":s.vue?"vue":s["@nestjs/core"]?"nestjs":s.express?"express":"node"}function Wt(e,t){let n=[];if(t==="angular"){let s=A.join(e,"src","app");if(!P.existsSync(s))return n;let o=ve(s,/\.(ts)$/).filter(i=>!i.includes(".spec.")&&!i.includes(".test.")&&!i.includes("node_modules"));for(let i of o){let r=P.readFileSync(i,"utf-8");if(r.includes("@Component")&&r.includes("inject(")){let a=A.relative(e,i),d=a.replace(/\.ts$/,".integration.spec.ts");if(P.existsSync(A.join(e,d)))continue;let u=[...r.matchAll(/inject\((\w+)\)/g)].map(f=>f[1]),L=[];for(let f of u){let x=ve(s,new RegExp(`${Zt(f)}\\.ts$`));L.push(...x.map(m=>A.relative(e,m)))}n.push({filePath:a,relatedFiles:L,description:`Angular component+service integration: ${A.basename(i)} injects ${u.join(", ")}`})}}}else if(t==="express"||t==="nestjs"){let s=["src","server","api","routes","controllers"];for(let o of s){let i=A.join(e,o);if(!P.existsSync(i))continue;let r=ve(i,/\.(controller|route|router)\.(ts|js)$/).filter(a=>!a.includes(".spec.")&&!a.includes(".test.")&&!a.includes("node_modules"));for(let a of r){let d=A.relative(e,a),p=d.replace(/\.(ts|js)$/,".integration.spec.$1");P.existsSync(A.join(e,p))||n.push({filePath:d,relatedFiles:[],description:`API endpoint integration test for ${A.basename(a)} \u2014 test with supertest against real middleware chain`})}}}else{let s=A.join(e,"src");if(P.existsSync(s)){let o=ve(s,/\.(ts|js|tsx|jsx)$/).filter(i=>!i.includes(".spec.")&&!i.includes(".test.")&&!i.includes("node_modules"));for(let i of o){let a=[...P.readFileSync(i,"utf-8").matchAll(/from\s+['"]\.\.?\//g)];if(a.length>=2){let d=A.relative(e,i),p=d.replace(/\.(ts|js|tsx|jsx)$/,".integration.spec.$1");if(P.existsSync(A.join(e,p)))continue;n.push({filePath:d,relatedFiles:[],description:`Module integration: ${A.basename(i)} imports ${a.length} local modules`})}}}}return n}function ve(e,t){let n=[],s=["node_modules","dist","build",".git",".angular","coverage"];if(!P.existsSync(e))return n;let o=P.readdirSync(e);for(let i of o){if(s.includes(i))continue;let r=A.join(e,i);try{P.statSync(r).isDirectory()?n.push(...ve(r,t)):t.test(i)&&n.push(r)}catch{continue}}return n}function Zt(e){return e.replace(/([a-z0-9])([A-Z])/g,"$1-$2").toLowerCase()}async function $t(e,t,n=1,s=3,o="local",i,r){if(n>s){console.log(`
|
|
260
|
+
[Lisa.ai Integration] Reached maximum retries (${s}). Stopping.`);return}let a=process.cwd(),d=I.load(a);d&&(I.applyEnvDefaults(d),!e&&d.testCommand&&(e=d.testCommand,console.log(`[Lisa.ai Config] Using testCommand from .lisai.json: ${e}`)));let p=Kt(a),u=K.scanRepository(),L=d?.testingFramework||(u.testingFramework!=="none"?u.testingFramework:void 0);console.log(`
|
|
261
|
+
[Lisa.ai Integration] App: ${p}, Framework: ${L||"auto"} (Attempt ${n}/${s}) Model: ${t}`),e||(u.suggestedTestCommand?e=u.suggestedTestCommand:P.existsSync(A.join(a,"angular.json"))?e="npx ng test --no-watch --browsers=ChromeHeadless":(console.error(`
|
|
262
|
+
[Lisa.ai Fatal Error] Could not auto-detect a test command. Please pass --command explicitly.`),process.exit(1)),console.log(`[Lisa.ai Integration] Auto-detected command: ${e}`));let f=ce(e);await R({projectId:o,type:"integration",filePath:"integration-suite",modelUsed:t,status:"running",details:`Integration test generation started for ${p} app`,testFramework:f});let x;if(r&&r.length>0)x=r.map(v=>({filePath:v,relatedFiles:[],description:"User-specified"})),console.log(`
|
|
263
|
+
[Lisa.ai Integration] Targeting ${r.length} file(s) from --files`),x.forEach(v=>console.log(` - ${v.filePath}`));else{if(x=Wt(a,p),x.length===0){console.log("[Lisa.ai Integration] No integration targets discovered. The project may already have full integration coverage.");return}console.log(`[Lisa.ai Integration] Found ${x.length} integration target(s):`),x.forEach(v=>console.log(` - ${v.filePath}: ${v.description}`))}let m=0;for(let v of x){let $=A.resolve(a,v.filePath);if(!P.existsSync($))continue;let g=A.parse($),w=A.join(g.dir,`${g.name}.integration.spec${g.ext}`);if(P.existsSync(w)){console.log(`[Lisa.ai Integration] Spec exists for ${v.filePath} \u2014 skipping.`);continue}console.log(`[Lisa.ai Integration] Generating integration spec for ${v.filePath}...`);let b=P.readFileSync($,"utf-8"),S="";for(let T of v.relatedFiles.slice(0,3)){let k=A.resolve(a,T);if(P.existsSync(k)){let _=P.readFileSync(k,"utf-8");S+=`
|
|
236
264
|
|
|
237
|
-
// --- Related file: ${
|
|
238
|
-
${
|
|
239
|
-
INTEGRATION TEST \u2014 ${
|
|
265
|
+
// --- Related file: ${T} ---
|
|
266
|
+
${_.slice(0,5e3)}`}}let E=`
|
|
267
|
+
INTEGRATION TEST \u2014 ${v.description}
|
|
240
268
|
|
|
241
269
|
Generate an integration test that exercises real module interactions (NOT mocked).
|
|
242
|
-
${
|
|
270
|
+
${p==="angular"?`
|
|
243
271
|
- Use TestBed with real service providers (not jasmine.createSpyObj)
|
|
244
272
|
- Import the actual component and its real dependencies
|
|
245
273
|
- Test that the component and service work together correctly
|
|
246
274
|
- Use HttpClientTestingModule for HTTP calls
|
|
247
|
-
`:
|
|
275
|
+
`:p==="express"||p==="nestjs"?`
|
|
248
276
|
- Use supertest to make real HTTP requests against the app
|
|
249
277
|
- Test the full middleware chain (auth, validation, handler)
|
|
250
278
|
- Use a test database or in-memory mock for data layer
|
|
@@ -255,32 +283,32 @@ ${g==="angular"?`
|
|
|
255
283
|
`}
|
|
256
284
|
|
|
257
285
|
Source file:
|
|
258
|
-
${
|
|
286
|
+
${b.slice(0,1e4)}
|
|
259
287
|
|
|
260
|
-
${
|
|
261
|
-
${
|
|
262
|
-
`;try{let
|
|
263
|
-
[Lisa.ai Integration] Running tests to verify generated specs: ${e}`);let
|
|
288
|
+
${S?`Related modules:
|
|
289
|
+
${S}`:""}
|
|
290
|
+
`;try{let T=await se(v.filePath,E,t,i,L,["integration"]);P.writeFileSync(w,T,"utf-8"),console.log(`[Lisa.ai Integration] Wrote ${A.relative(a,w)}`),m++,await R({projectId:o,type:"integration",filePath:v.filePath,modelUsed:t,status:"success",details:`Generated integration spec: ${v.description}`,testFramework:f})}catch(T){console.error(`[Lisa.ai Integration] LLM failed for ${v.filePath}: ${T.message}`)}}if(m===0){console.log("[Lisa.ai Integration] No new integration specs generated.");return}console.log(`
|
|
291
|
+
[Lisa.ai Integration] Running tests to verify generated specs: ${e}`);let c="",l="",y=!1;try{await new Promise((v,$)=>{let g=(0,xt.spawn)(e,{shell:!0,stdio:["ignore","pipe","pipe"],cwd:a});g.stdout?.on("data",w=>{let b=w.toString();c+=b,process.stdout.write(b)}),g.stderr?.on("data",w=>{let b=w.toString();l+=b,process.stderr.write(b)}),g.on("close",w=>{w===0?v():$(new Error(`Tests exited with code ${w}`))})}),y=!0,console.log(`
|
|
264
292
|
[Lisa.ai Integration] All tests passed including integration specs.`)}catch{console.log(`
|
|
265
|
-
[Lisa.ai Integration] Some tests failed. Run 'lisa-agent heal --type integration' to auto-fix.`)}let
|
|
266
|
-
`+
|
|
267
|
-
\u{1F6A8} [Lisa.ai Audit] No package.json found in ${process.cwd()}.`),console.error(" The audit command currently supports Node.js / npm projects only."),process.exit(1));let
|
|
268
|
-
[Lisa.ai Audit] Scanning for vulnerabilities...`);let{stdout:o,code:i}=await
|
|
269
|
-
\u2705 [Lisa.ai Audit] No vulnerabilities found! Repository is clean.`);return}let r=await
|
|
270
|
-
Vulnerabilities found:`),
|
|
271
|
-
[Lisa.ai Audit] Applying safe automatic fixes (npm audit fix)...`);let{stdout:
|
|
272
|
-
`)){let
|
|
273
|
-
\u2705 [Lisa.ai Audit] All vulnerabilities fixed by safe auto-fix!`);return}let
|
|
274
|
-
[Lisa.ai Audit] Safe auto-fix resolved ${
|
|
275
|
-
[Lisa.ai Audit] Applying ${
|
|
276
|
-
\u2705 [Lisa.ai Audit] All vulnerabilities resolved!`);return}}let{stdout:
|
|
293
|
+
[Lisa.ai Integration] Some tests failed. Run 'lisa-agent heal --type integration' to auto-fix.`)}let h=c+`
|
|
294
|
+
`+l,C=Y(h);await R({projectId:o,type:"integration",filePath:"integration-suite",modelUsed:t,status:y?"success":"error",details:`Integration test generation complete. ${m} new spec(s) generated.`,...C&&{testTotal:C.total,testPassed:C.passed,testFailed:C.failed},testFramework:f})}var bt=j(require("dotenv")),St=require("child_process"),X=j(require("fs")),Q=j(require("path"));bt.config({quiet:!0});function pe(e){return new Promise(t=>{let n=(0,St.spawn)(e,{shell:!0,stdio:["ignore","pipe","pipe"]}),s="",o="";n.stdout?.on("data",i=>{s+=i.toString()}),n.stderr?.on("data",i=>{o+=i.toString()}),n.on("close",i=>t({stdout:s,stderr:o,code:i??1}))})}function zt(){return X.existsSync(Q.resolve(process.cwd(),"pnpm-lock.yaml"))?"pnpm":X.existsSync(Q.resolve(process.cwd(),"yarn.lock"))?"yarn":"npm"}var Jt={critical:"\u{1F534}",high:"\u{1F7E0}",moderate:"\u{1F7E1}",low:"\u{1F535}",info:"\u26AA"},Ct={critical:5,high:4,moderate:3,low:2,info:1};function kt(e){let t=["critical","high","moderate","low","info"];for(let n of t){let s=e[n]??0;s>0&&console.log(` ${Jt[n]} ${n.padEnd(10)} ${s}`)}console.log(` ${"\u2500".repeat(22)}`),console.log(` ${"Total".padEnd(10)} ${e.total}`)}async function Ke(e){try{return JSON.parse(e)}catch{return null}}async function Ft(e,t="local",n){X.existsSync(Q.resolve(process.cwd(),"package.json"))||(console.error(`
|
|
295
|
+
\u{1F6A8} [Lisa.ai Audit] No package.json found in ${process.cwd()}.`),console.error(" The audit command currently supports Node.js / npm projects only."),process.exit(1));let s=zt();console.log(`[Lisa.ai Audit] Package manager: ${s}`),console.log(`
|
|
296
|
+
[Lisa.ai Audit] Scanning for vulnerabilities...`);let{stdout:o,code:i}=await pe(s==="npm"?"npm audit --json":s==="yarn"?"yarn audit --json":"pnpm audit --json");if(i===0){console.log(`
|
|
297
|
+
\u2705 [Lisa.ai Audit] No vulnerabilities found! Repository is clean.`);return}let r=await Ke(o);r||(console.error("[Lisa.ai Audit] Could not parse audit output. Run 'npm audit' manually to investigate."),process.exit(1));let a=r.metadata.vulnerabilities;console.log(`
|
|
298
|
+
Vulnerabilities found:`),kt(a),console.log(`
|
|
299
|
+
[Lisa.ai Audit] Applying safe automatic fixes (npm audit fix)...`);let{stdout:d}=await pe(s==="npm"?"npm audit fix":s==="yarn"?"yarn upgrade":"pnpm audit fix");for(let k of d.split(`
|
|
300
|
+
`)){let _=k.trim();_&&!_.startsWith("npm warn")&&!_.startsWith("npm notice")&&console.log(` ${_}`)}let p=s==="npm"?"npm audit --json":s==="yarn"?"yarn audit --json":"pnpm audit --json",{stdout:u,code:L}=await pe(p);if(L===0){console.log(`
|
|
301
|
+
\u2705 [Lisa.ai Audit] All vulnerabilities fixed by safe auto-fix!`);return}let f=await Ke(u);if(!f){console.warn("[Lisa.ai Audit] Could not parse post-fix audit output.");return}let x=Object.values(f.vulnerabilities),m=f.metadata.vulnerabilities,c=a.total-m.total;console.log(`
|
|
302
|
+
[Lisa.ai Audit] Safe auto-fix resolved ${c} vulnerability(-ies).`),m.total>0&&(console.log(" Remaining:"),kt(m));let l=x.filter(k=>typeof k.fixAvailable=="object"&&!k.fixAvailable.isSemVerMajor).map(k=>k.fixAvailable),y=[...new Map(l.map(k=>[k.name,k])).values()];if(y.length>0){console.log(`
|
|
303
|
+
[Lisa.ai Audit] Applying ${y.length} non-breaking targeted upgrade(s)...`);for(let ie of y){let q=`npm install ${ie.name}@${ie.version}`;console.log(` \u2192 ${q}`);let{stderr:fe}=await pe(q);fe&&!fe.includes("npm warn")&&console.warn(` ${fe.trim()}`)}let{stdout:k,code:_}=await pe(p);if(_===0){console.log(`
|
|
304
|
+
\u2705 [Lisa.ai Audit] All vulnerabilities resolved!`);return}}let{stdout:h}=await pe(p),C=await Ke(h)??f,$=Object.values(C.vulnerabilities).sort((k,_)=>(Ct[_.severity]??0)-(Ct[k.severity]??0)).slice(0,10).filter(k=>k.fixAvailable===!1?!0:typeof k.fixAvailable=="object"?k.fixAvailable.isSemVerMajor:!1);if($.length===0){console.log(`
|
|
277
305
|
\u2705 [Lisa.ai Audit] No breaking-change or unfixable vulnerabilities remain.`);return}console.log(`
|
|
278
|
-
[Lisa.ai Audit] ${
|
|
279
|
-
`),
|
|
306
|
+
[Lisa.ai Audit] ${$.length} vulnerability(-ies) require manual attention.`),console.log(`[Lisa.ai Audit] Consulting ${e} for remediation guidance...`);let g={};try{g=JSON.parse(X.readFileSync(Q.resolve(process.cwd(),"package.json"),"utf8"))}catch{}let w={...g.dependencies??{},...g.devDependencies??{}},b=$.map(k=>{let _=k.fixAvailable,ie=_===!1?"no fix available yet":`upgrade to ${_.name}@${_.version} (BREAKING \u2014 major version bump)`,q=w[k.name]?`current: ${w[k.name]}`:"transitive dependency";return`\u2022 ${k.name} (${k.severity}) \u2014 ${q} \u2014 ${ie}`}).join(`
|
|
307
|
+
`),S=`You are a Node.js security expert helping a developer fix npm vulnerabilities.
|
|
280
308
|
|
|
281
309
|
These vulnerabilities remain after safe auto-fixes were applied. Each requires either a breaking upgrade or has no automated fix:
|
|
282
310
|
|
|
283
|
-
${
|
|
311
|
+
${b}
|
|
284
312
|
|
|
285
313
|
For each vulnerability:
|
|
286
314
|
1. Briefly explain the security risk (1 sentence).
|
|
@@ -288,35 +316,35 @@ For each vulnerability:
|
|
|
288
316
|
3. If the upgrade is breaking (major version), note the most likely code change needed (e.g. renamed API, changed import path).
|
|
289
317
|
4. If no fix exists, suggest a workaround or safe alternative package.
|
|
290
318
|
|
|
291
|
-
Be concrete. Use numbered items. If a vulnerability is a transitive dependency, explain how to force a resolution override in package.json.`;try{let
|
|
319
|
+
Be concrete. Use numbered items. If a vulnerability is a transitive dependency, explain how to force a resolution override in package.json.`;try{let k=await ae(S,e,n);console.log(`
|
|
292
320
|
Remediation guidance:
|
|
293
|
-
`);for(let
|
|
294
|
-
`))console.log(` ${
|
|
295
|
-
`);
|
|
296
|
-
[Lisa.ai Audit] Full report saved to: lisa-audit-report.md`)}catch(
|
|
297
|
-
[Lisa.ai Audit] LLM guidance failed: ${
|
|
298
|
-
${"\u2500".repeat(50)}`),console.log(" Lisa.ai Audit Complete"),console.log(` \u2705 Fixed: ${
|
|
299
|
-
`)}var
|
|
321
|
+
`);for(let q of k.split(`
|
|
322
|
+
`))console.log(` ${q}`);let _=Q.resolve(process.cwd(),"lisa-audit-report.md"),ie=["# Lisa.ai Security Audit Report","",`Generated: ${new Date().toISOString()}`,`Project: ${g.name??Q.basename(process.cwd())}`,"","## Summary","","| Severity | Initial | Remaining |","|----------|---------|-----------|",...["critical","high","moderate","low"].map(q=>{let fe=a[q]??0,Pt=C.metadata.vulnerabilities[q]??0;return`| ${q} | ${fe} | ${Pt} |`}),"","## Vulnerabilities Requiring Manual Action","",b,"",`## Remediation Guidance (${e})`,"",k].join(`
|
|
323
|
+
`);X.writeFileSync(_,ie,"utf-8"),console.log(`
|
|
324
|
+
[Lisa.ai Audit] Full report saved to: lisa-audit-report.md`)}catch(k){console.error(`
|
|
325
|
+
[Lisa.ai Audit] LLM guidance failed: ${k.message}`),console.log(" Run 'npm audit' manually and address the remaining vulnerabilities.")}let E=C.metadata.vulnerabilities,T=a.total-E.total;console.log(`
|
|
326
|
+
${"\u2500".repeat(50)}`),console.log(" Lisa.ai Audit Complete"),console.log(` \u2705 Fixed: ${T} / ${a.total}`),console.log(` \u26A0\uFE0F Remaining: ${E.total} (see lisa-audit-report.md)`),console.log(`${"\u2500".repeat(50)}
|
|
327
|
+
`)}var Tt=Et();function oe(){let e=Tt.version;console.log(`
|
|
300
328
|
\x1B[38;2;99;102;241m\u2554\u2550\u2557\x1B[0m \x1B[1mLisa.ai Agent\x1B[0m v${e}
|
|
301
329
|
\x1B[38;2;99;102;241m\u2551\x1B[38;2;129;140;248m\u26A1\x1B[38;2;99;102;241m\u2551\x1B[0m Autonomous CI/CD Platform
|
|
302
330
|
\x1B[38;2;99;102;241m\u255A\u2550\u255D\x1B[0m \x1B[2mheal \xB7 unit \xB7 e2e \xB7 integration \xB7 audit\x1B[0m
|
|
303
|
-
`)}async function
|
|
331
|
+
`)}async function Ne(e){let t=5,n=e.model,s,o=I.load(process.cwd()),i=e.projectId||o?.projectId||"local";if(i!=="local"){let a=await xe(i);if(!a.ok)a.reason==="not_found"?(console.error(`
|
|
304
332
|
[Lisa.ai Agent Error] Project '${i}' does not exist on the Control Plane. Please create it in the Dashboard first or run locally without a project ID.`),process.exit(1)):console.warn(`
|
|
305
|
-
[Lisa.ai Warning] Control Plane is unreachable. Continuing with local CLI defaults (model=${
|
|
306
|
-
[Lisa.ai Warning] maxRetries is ${
|
|
307
|
-
[Lisa.ai Error] Invalid heal type '${e.type}'. Valid types: ${t.join(", ")}`),process.exit(1));let
|
|
308
|
-
[Lisa.ai Diagnose] Testing ${t} \u2192 model ID: ${r}`);try{let a=await
|
|
333
|
+
[Lisa.ai Warning] Control Plane is unreachable. Continuing with local CLI defaults (model=${n}, maxRetries=${t}).`);else{let d=a.config;console.log(`[Lisa.ai Agent] Dynamic Config Loaded: Provider=${d.modelProvider}, MaxRetries=${d.maxRetries}`),n=d.modelProvider,t=d.maxRetries,s=d.apiKey,d.agentEnabled===!1&&(console.log("[Lisa.ai Agent] Agent is disabled by Control Plane for this project."),process.exit(1))}}o&&(I.applyEnvDefaults(o),o.maxRetries!==void 0&&(t=o.maxRetries),o.provider&&e.model==="gemini"&&(n=o.provider),I.printSummary(o)),t<5&&console.warn(`
|
|
334
|
+
[Lisa.ai Warning] maxRetries is ${t}. Consider increasing to 5+ for complex projects.`);let r=He(o?.lisaLlm);return r.enabled&&console.log(`[Lisa.ai Config] Lisa LLM enabled: ${r.model} @ ${r.baseUrl}`),{model:n,maxRetries:t,apiKey:s,projectId:i,lisaLlmConfig:r}}var Z=new jt.Command;Z.name("lisa-agent").description("Lisa.ai - Autonomous CI/CD Platform Worker Agent").version(Tt.version);Z.command("heal").description("Run tests and autonomously heal all failures via LLM + Memory Engine").option("-c, --command <type>","Test command to execute (auto-detected if omitted)").option("-m, --model <provider>","LLM provider to use (gemini, claude, openai)","gemini").option("-p, --project-id <id>","Control Plane Project ID").option("-t, --type <scope>","Test type to heal: unit (default), e2e, integration","unit").option("-f, --files <paths>","Target specific files (comma-separated, bypasses discovery)").option("--ci","CI mode: commit healed files, open PR, write GitHub Actions step summary").action(async e=>{oe();let t=["unit","e2e","integration"],n=e.type;t.includes(n)||(console.error(`
|
|
335
|
+
[Lisa.ai Error] Invalid heal type '${e.type}'. Valid types: ${t.join(", ")}`),process.exit(1));let s=e.files?e.files.split(",").map(r=>r.trim()):void 0,o=e.ci===!0,i=await Ne(e);await ue(e.command,i.model,1,i.maxRetries,i.projectId,void 0,i.apiKey,n,s,o,i.lisaLlmConfig)});Z.command("unit").description("Generate missing unit test specs to reach 100% coverage (auto-detects framework)").option("-c, --command <type>","Test+coverage command to execute (auto-detected if omitted)").option("-m, --model <provider>","LLM provider to use (gemini, claude, openai)","gemini").option("-p, --project-id <id>","Control Plane Project ID").option("-f, --files <paths>","Target specific files (comma-separated, bypasses discovery)").action(async e=>{oe();let t=e.files?e.files.split(",").map(s=>s.trim()):void 0,n=await Ne(e);await wt(e.command,n.model,1,n.maxRetries,n.projectId,n.apiKey,t,n.lisaLlmConfig)});Z.command("e2e").description("Generate E2E tests via Playwright (auto-installs if none detected)").option("-c, --command <type>","E2E command to execute (auto-detected if omitted)").option("-m, --model <provider>","LLM provider to use (gemini, claude, openai)","gemini").option("-p, --project-id <id>","Control Plane Project ID").option("-f, --files <paths>","Target specific files (comma-separated, bypasses discovery)").action(async e=>{oe();let t=e.files?e.files.split(",").map(s=>s.trim()):void 0,n=await Ne(e);await Lt(e.command,n.model,1,n.maxRetries,n.projectId,n.apiKey,t)});Z.command("integration").description("Generate integration tests for module seams (component+service, API+DB)").option("-c, --command <type>","Test command to execute (auto-detected if omitted)").option("-m, --model <provider>","LLM provider to use (gemini, claude, openai)","gemini").option("-p, --project-id <id>","Control Plane Project ID").option("-f, --files <paths>","Target specific files (comma-separated, bypasses discovery)").action(async e=>{oe();let t=e.files?e.files.split(",").map(s=>s.trim()):void 0,n=await Ne(e);await $t(e.command,n.model,1,n.maxRetries,n.projectId,n.apiKey,t)});Z.command("diagnose").description("Test LLM connectivity and API key health without running the full agent").option("-m, --model <provider>","LLM provider to test (gemini, claude, openai)","claude").option("-p, --project-id <id>","Control Plane Project ID to fetch API key from").action(async e=>{oe();let t=e.model,n,s=I.load(process.cwd()),o=e.projectId||s?.projectId||"local";if(o!=="local"){let a=await xe(o);a.ok?(t=a.config.modelProvider,n=a.config.apiKey,console.log(`[Lisa.ai Diagnose] Config fetched from Control Plane. Provider=${t}`)):console.warn(`[Lisa.ai Diagnose] Control Plane ${a.reason}. Using local env for API key.`)}let r={claude:process.env.LISA_CLAUDE_MODEL||"claude-haiku-4-5",openai:process.env.LISA_OPENAI_MODEL||"gpt-4o-mini",gemini:process.env.LISA_GOOGLE_MODEL||"gemini-2.0-flash"}[t]||t;console.log(`
|
|
336
|
+
[Lisa.ai Diagnose] Testing ${t} \u2192 model ID: ${r}`);try{let a=await ae("Reply with exactly: LISA_OK",t,n);console.log(`
|
|
309
337
|
[Lisa.ai Diagnose] ${t} is working correctly.`),console.log(` Model response: "${a}"`)}catch(a){console.error(`
|
|
310
338
|
[Lisa.ai Diagnose] ${t} call FAILED.`),console.error(` Error: ${a.message}`),a.cause&&console.error(` Cause: ${a.cause?.message??a.cause}`),console.error(`
|
|
311
|
-
Common causes:`),console.error(" - API key is invalid, expired, or has no credits"),console.error(" - Model ID is deprecated (current: claude-sonnet-4-6, gemini-2.0-flash, gpt-4o-mini)"),console.error(" - Rate limit exceeded \u2014 wait a minute and retry"),console.error(" - Network/proxy issue blocking api.anthropic.com"),process.exit(1)}});
|
|
312
|
-
[Lisa.ai Init] ${
|
|
339
|
+
Common causes:`),console.error(" - API key is invalid, expired, or has no credits"),console.error(" - Model ID is deprecated (current: claude-sonnet-4-6, gemini-2.0-flash, gpt-4o-mini)"),console.error(" - Rate limit exceeded \u2014 wait a minute and retry"),console.error(" - Network/proxy issue blocking api.anthropic.com"),process.exit(1)}});Z.command("init").description("Interactively create a .lisai.json config file in the current project").option("--force","Overwrite existing .lisai.json if it exists").action(async e=>{let t=Le.resolve(process.cwd(),ne);ee.existsSync(t)&&!e.force&&(console.error(`
|
|
340
|
+
[Lisa.ai Init] ${ne} already exists. Use --force to overwrite.`),process.exit(1));let n=At.createInterface({input:process.stdin,output:process.stdout}),s=(x,m="")=>new Promise(c=>n.question(m?`${x} [${m}]: `:`${x}: `,l=>c(l.trim()||m)));console.log(`
|
|
313
341
|
Lisa.ai Project Setup \u2014 press Enter to accept the default shown in [ ]
|
|
314
|
-
`);let o=await
|
|
342
|
+
`);let o=await s("Control Plane project ID (leave empty for local-only mode)",""),i=await s("LLM provider (gemini / claude / openai)","gemini"),r=await s("Testing framework (jest / vitest / mocha / karma / jasmine \u2014 leave empty to auto-detect)",""),a=await s("E2E framework (playwright / cypress \u2014 leave empty for Playwright default)",""),d=await s("Test types to generate (unit / integration / e2e \u2014 comma-separated)","unit"),p=await s("Test command (leave empty for auto-discovery)",""),u=await s("E2E command (leave empty for auto-discovery)",""),L=await s("Max heal retries","5");n.close();let f={...o?{projectId:o}:{},provider:i,testTypes:d.split(",").map(x=>x.trim()).filter(Boolean),maxRetries:parseInt(L,10)||5,skipFiles:[],skipDirs:[],skipPaths:[]};r&&(f.testingFramework=r),a&&(f.e2eFramework=a),p&&(f.testCommand=p),u&&(f.e2eCommand=u),ee.writeFileSync(t,JSON.stringify(f,null,2)+`
|
|
315
343
|
`,"utf-8"),console.log(`
|
|
316
|
-
Created ${
|
|
317
|
-
`),console.log(JSON.stringify(
|
|
344
|
+
Created ${ne}:
|
|
345
|
+
`),console.log(JSON.stringify(f,null,2)),console.log(`
|
|
318
346
|
Tip: add "model" to pin a specific model ID (e.g. "claude-sonnet-4-6").`),console.log(` Edit skipFiles / skipDirs / skipPaths to exclude files from test analysis.
|
|
319
|
-
`)});function
|
|
347
|
+
`)});function Xt(e,t){return`# Lisa.ai Auto-Heal Workflow
|
|
320
348
|
# Generated by: lisa-agent init-ci
|
|
321
349
|
# Docs: https://www.npmjs.com/package/@lisa.ai/agent
|
|
322
350
|
|
|
@@ -357,9 +385,9 @@ jobs:
|
|
|
357
385
|
${t}: \${{ secrets.${t} }}
|
|
358
386
|
GITHUB_TOKEN: \${{ secrets.GITHUB_TOKEN }}
|
|
359
387
|
run: lisa-agent heal --model ${e} --ci
|
|
360
|
-
`}
|
|
361
|
-
[Lisa.ai Init-CI] .github/workflows/lisa-heal.yml already exists. Use --force to overwrite.`),process.exit(1));let
|
|
388
|
+
`}Z.command("init-ci").description("Generate a GitHub Actions workflow file for Lisa.ai CI/CD healing").option("--force","Overwrite existing workflow file").option("-m, --model <provider>","LLM provider for the workflow (gemini, claude, openai)","gemini").action(async e=>{oe();let t=Le.resolve(process.cwd(),".github","workflows"),n=Le.join(t,"lisa-heal.yml");ee.existsSync(n)&&!e.force&&(console.error(`
|
|
389
|
+
[Lisa.ai Init-CI] .github/workflows/lisa-heal.yml already exists. Use --force to overwrite.`),process.exit(1));let s={gemini:"GOOGLE_GENERATIVE_AI_API_KEY",claude:"ANTHROPIC_API_KEY",openai:"OPENAI_API_KEY"},o=e.model||"gemini",i=s[o]||"GOOGLE_GENERATIVE_AI_API_KEY",r=Xt(o,i);ee.mkdirSync(t,{recursive:!0}),ee.writeFileSync(n,r,"utf-8"),console.log(`
|
|
362
390
|
Created: .github/workflows/lisa-heal.yml`),console.log(`
|
|
363
391
|
Required repository secret: ${i}`),console.log(" Set it in: GitHub repo > Settings > Secrets and variables > Actions"),console.log(`
|
|
364
392
|
The workflow will:`),console.log(" 1. Run on every push to main/master/develop"),console.log(" 2. Install dependencies + run lisa-agent heal --ci"),console.log(" 3. If tests fail and Lisa heals them, open a PR automatically"),console.log(` 4. If all tests pass or nothing can be healed, report status
|
|
365
|
-
`)});
|
|
393
|
+
`)});Z.command("audit").description("Scan for npm vulnerabilities and auto-fix where safe; consult LLM for manual fixes").option("-m, --model <provider>","LLM provider to use (gemini, claude, openai)","gemini").option("-p, --project-id <id>","Control Plane Project ID").action(async e=>{oe();let t=e.model,n,s=I.load(process.cwd()),o=e.projectId||s?.projectId||"local";if(o!=="local"){let i=await xe(o);i.ok?(t=i.config.modelProvider,n=i.config.apiKey,console.log(`[Lisa.ai Audit] Config fetched from Control Plane. Provider=${t}`)):console.warn(`[Lisa.ai Audit] Control Plane ${i.reason}. Using local env for API key.`)}await Ft(t,o,n)});Z.parse(process.argv);
|