@wispbit/local 1.0.82 → 1.0.83

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.
Files changed (2) hide show
  1. package/cli-bundle.js +3 -3
  2. package/package.json +1 -1
package/cli-bundle.js CHANGED
@@ -214,7 +214,7 @@ You can use this when we know the exact symbol/function name/etc. to search in s
214
214
  ${o.join(`
215
215
  `)}`)}import{readFile as Qst}from"fs/promises";import eat from"path";async function t1(t,e,n,r=!1){let i=eat.resolve(t,e),s=(await Qst(i,"utf-8")).split(`
216
216
  `),{start:a,end:c}=n,u=a.line-1,l=c.line-1;if(a.line===c.line){let d=s[u]||"";return r?d.substring(a.column-1,c.column-1):d}let E=[];for(let d=u;d<=l&&d<s.length;d++){let f=s[d];d===u?E.push(r?f.substring(a.column-1):f):d===l?E.push(r?f.substring(0,c.column-1):f):E.push(f)}return E.join(`
217
- `)}var tat={read:WJ,grep:KJ,glob:zJ},aC=class{environment;eventEmitter;config;maxIterations;batchSize;constructor(e,n,r,i,o){this.environment=n,this.eventEmitter=r||new zr,this.config=e,this.maxIterations=i||20,this.batchSize=o||50}async executeTool(e,n,r,i){if(n==="report_fix")return{error:"Tool 'report_fix' is not supported in LLMStep. Available tools are: read, grep, glob"};let o=tat[n];if(!o)return{error:`Unknown tool: ${n}. Available tools are: read, grep, glob`};let s=HJ(n,r,[o]);if(!s.success)return{error:`Tool parameter validation failed: ${s.error}. Please fix the parameters and try again.`};let a=s.data;switch(n){case"read":{this.eventEmitter.llmToolExecution(e,"read",{file:a.target_file,offset:a.offset,limit:a.limit});let c=await qO(a,this.environment.getWorkspaceRoot());if(!("error"in c)){let u=a.target_file;i.some(l=>l.path===u)||i.push({path:u,sha:c.sha})}return"error"in c?c:c.content}case"grep":{this.eventEmitter.llmToolExecution(e,"grep",{path:a.path,pattern:a.pattern});let c=await JO(a,this.environment.getWorkspaceRoot(),[],ZJ());if(!("error"in c))for(let u of c.matches)i.some(l=>l.path===u.file)||i.push({path:u.file,sha:u.sha});return"error"in c?c:JSON.stringify(c.matches)}case"glob":{this.eventEmitter.llmToolExecution(e,"glob",{path:a.path,pattern:a.pattern});let c=await QO(a,this.environment.getWorkspaceRoot());return"error"in c?c:JSON.stringify(c.files)}default:return{error:`Unknown tool: ${n}`}}}async hydrateMatchesWithFileContent(e){let n=[];for(let r of e){let i=await t1(this.environment.getWorkspaceRoot(),r.file.path,r.range).catch(s=>{if(s.code==="ENOENT")return null;throw s});if(i===null)continue;let o=r.evidence;if(r.evidence&&r.evidence.length>0){o=[];let s=!1;for(let a of r.evidence){let c=await t1(this.environment.getWorkspaceRoot(),a.file.path,a.range).catch(u=>{if(u.code==="ENOENT")return null;throw u});if(c===null){s=!0;break}o.push({...a,text:c})}if(s)continue}n.push({...r,text:i,evidence:o})}return n}async executeLLMValidation(e,n,r){let i=Date.now(),o=this.config.getLLMProvider();this.eventEmitter.startLLMValidation(e.id,n.length);let s=[],a=[],c=new sr(0),u=new sr(0),l=new sr(0);this.eventEmitter.startLLMSearchPhase(e.id,n.length);let E,d=[],f=[];for(let h=0;h<this.maxIterations;h++){let C=await o.search({rule:e,matches:n,tools:r,messages:s,files:a});if(f.push(C),C.usage&&C.usage.inputTokens&&C.usage.outputTokens&&C.usage.cost&&(c=c.plus(new sr(C.usage.inputTokens)),u=u.plus(new sr(C.usage.outputTokens)),l=l.plus(new sr(C.usage.cost))),C.type==="partial_matches"){let P=await this.hydrateMatchesWithFileContent(C.matches);d=[...d,...P],n=C.unresolved;continue}if(C.type==="matches"){let P=await this.hydrateMatchesWithFileContent(C.matches);E={...C,matches:[...d,...P]};break}if(C.type==="request_files"){for(let P of C.files)a.some(G=>G.path===P.path)||a.push({path:P.path,sha:P.sha});continue}if(C.type==="assistant"){s.push({type:"assistant",content:C.content}),s.push({type:"user",content:"Please use tool calls to interact with the codebase and report violations."});continue}if(C.type==="tool_request"){s.push({type:"tool_request",tool_calls:C.tool_calls});let P=await Promise.all(C.tool_calls.map(async G=>{let Y=await this.executeTool(e.id,G.function.name,G.function.arguments,a),re=typeof Y=="string"?Y:JSON.stringify(Y);return{tool_call_id:G.id,content:re}}));s.push({type:"tool_response",tool_results:P});continue}}if(!E)throw this.eventEmitter.emit("llm:max-iterations-reached",{ruleId:e.id,maxIterations:this.maxIterations,messages:s,results:f}),new Error(`Max iterations (${this.maxIterations}) reached without getting matches`);let T=E.matches;if(T.length===0){let h=c.plus(u).toNumber();return this.eventEmitter.completeLLMValidation(e.id,h,c.toNumber(),u.toNumber(),l.toString(),Date.now()-i,0,!1),{matches:[],executionTime:Date.now()-i,cost:l.toString()}}this.eventEmitter.startLLMValidationPhase(e.id,T.length);let p=[],S=T;for(;S.length>0;){let h=await o.validate({rule:e,matches:S,files:a});if(h.usage&&h.usage.inputTokens&&h.usage.outputTokens&&h.usage.cost&&(c=c.plus(new sr(h.usage.inputTokens)),u=u.plus(new sr(h.usage.outputTokens)),l=l.plus(new sr(h.usage.cost))),h.type==="partial_matches"){let C=await this.hydrateMatchesWithFileContent(h.matches);p=[...p,...C],S=h.unresolved;continue}if(h.type==="matches"){let C=await this.hydrateMatchesWithFileContent(h.matches);p=[...p,...C];break}}let m=p,O=c.plus(u).toNumber();return this.eventEmitter.completeLLMValidation(e.id,O,c.toNumber(),u.toNumber(),l.toString(),Date.now()-i,m.length,!1),{matches:m,executionTime:Date.now()-i,cost:l.toString()}}async execute(e,n,r){if(n.length===0)return{matches:[],executionTime:0,cost:"0"};let i=Date.now(),o=[...n].sort((l,E)=>l.file.path!==E.file.path?l.file.path.localeCompare(E.file.path):l.range.start.line-E.range.start.line),s=[];for(let l=0;l<o.length;l+=this.batchSize)s.push(o.slice(l,l+this.batchSize));let a=s.length,c=[],u=new sr(0);for(let l=0;l<s.length;l++){let E=s[l],d=l+1,f=n.length-(l+1)*this.batchSize,T=Math.max(0,f);a>1&&this.eventEmitter.llmValidationPhaseBatch(e.id,d,a,E.length,T,n.length);let p=await this.executeLLMValidation(e,E,r);c=[...c,...p.matches],u=u.plus(new sr(p.cost))}return{matches:c,executionTime:Date.now()-i,cost:u.toString()}}};var La=class{fileFilterStep;findMatchesStep;llmStep;environment;eventEmitter;config;previousResults=new Map;inFlightLLMRequests=new Map;sharedAstCache;constructor(e,n,r){this.environment=n,this.eventEmitter=r||new zr,this.config=e,this.sharedAstCache=new Od,this.fileFilterStep=new jO(this.environment),this.findMatchesStep=new iC(this.environment,this.eventEmitter,this.sharedAstCache),this.llmStep=new aC(this.config,this.environment,this.eventEmitter)}clearCache(){this.previousResults.clear(),this.inFlightLLMRequests.clear(),this.sharedAstCache.clear()}async executeStep(e,n,r,i,o,s){let a=n.type;if(a==="ast-grep"){let{type:c,language:u,...l}=n,E=r.map(T=>o.getFileInput(T,!1)),d=await this.findMatchesStep.execute(l,u,{fileInputs:E}),f=[];if(this.shouldDeduplicateMatches(o)){let T=r.filter(p=>o.hasBaseContent(p));if(T.length>0){let p=T.map(m=>o.getFileInput(m,!0));f=(await this.findMatchesStep.execute(l,u,{fileInputs:p})).matches}}return{matches:d.matches,oldMatches:f}}if(a==="ripgrep"){let{type:c,...u}=n,l=r.map(f=>o.getFileInput(f,!1)),E=await this.findMatchesStep.execute(u,"Unknown",{fileInputs:l}),d=[];if(this.shouldDeduplicateMatches(o)){let f=r.filter(T=>o.hasBaseContent(T));if(f.length>0){let T=f.map(S=>o.getFileInput(S,!0));d=(await this.findMatchesStep.execute(u,"Unknown",{fileInputs:T})).matches}}return{matches:E.matches,oldMatches:d}}if(a==="file-filter")return{filePaths:this.fileFilterStep.execute(r,{include:n.include,ignore:n.ignore,additionalGlobs:this.config.getAdditionalGlobs()}).filteredPaths};if(a==="llm"){if(i.length===0)return{matches:[],cost:"0"};let c=[],u=i;if(this.previousResults.has(e.internalId)){let p=this.previousResults.get(e.internalId).matches,S=FV(i,p);if(c=S.remappedMatches,u=S.unmappedMatches,c.length>0){let m=c.length+u.length;this.eventEmitter.emit("rules:rule-partial",{ruleId:e.internalId,matches:c,totalMatches:m});let O=new Map;for(let h of c){let C=h.file.path;O.has(C)||O.set(C,[]),O.get(C).push(h)}for(let[h,C]of O.entries())this.eventEmitter.emit("rules:rule-file-partial",{ruleId:e.internalId,filePath:h,matches:C,totalMatches:m})}}if(u.length===0)return{matches:c,cost:"0"};let E=this.inFlightLLMRequests.get(e.internalId);if(E){let T=await E,{remappedMatches:p,unmappedMatches:S}=FV(u,T.matches);if(S.length>0){let m=this.llmStep.execute(e,S,n.tools??[]);this.inFlightLLMRequests.set(e.internalId,m);let O=await m;return this.inFlightLLMRequests.delete(e.internalId),{matches:[...c,...p,...O.matches],cost:O.cost}}else return{matches:[...c,...p],cost:"0"}}let d=this.llmStep.execute(e,u,n.tools??[]);this.inFlightLLMRequests.set(e.internalId,d);let f=await d;return this.inFlightLLMRequests.delete(e.internalId),{matches:[...c,...f.matches],cost:f.cost}}throw new Error(`Unknown step type: ${a}`)}async executeRule(e,n,r){let i=e.id,o=r?.relativePath?n.filePaths.filter(E=>E===r.relativePath):[...n.filePaths],s=[],a;for(let E of e.steps){let d=E.id,f=E.step;if(f.type==="step-group"){let T=f.steps,p=[],m=T.some(O=>O.type==="ast-grep")?T.filter(O=>O.type!=="ripgrep"):T;for(let O=0;O<m.length;O++){let h=m[O],C=`${d}[${O}]`;this.eventEmitter.startStep(i,C,h.type,{filePaths:o,matches:s},d);let P=Date.now(),G=await this.executeStep(e,h,o,s,n,r),Y=Date.now()-P;G.filePaths!==void 0&&(o=n.filterFiles(G.filePaths));let re=[];if(G.matches!==void 0){let W=G.oldMatches||[];re=n.filterMatches(G.matches,W),p=p.concat(re)}this.eventEmitter.completeStep(i,C,h.type,{filePaths:o,matches:re},Y,d)}s=p}else{this.eventEmitter.startStep(i,d,f.type,{filePaths:o,matches:s});let T=Date.now(),p=await this.executeStep(e,f,o,s,n,r),S=Date.now()-T;if(p.filePaths!==void 0&&(o=n.filterFiles(p.filePaths),s=n.filterMatchesByFilePaths(s,o)),p.matches!==void 0){let m=p.oldMatches||[];s=n.filterMatches(p.matches,m)}p.cost!==void 0&&(a=p.cost),this.eventEmitter.completeStep(i,d,f.type,{filePaths:o,matches:s},S)}if(o.length===0)break}let c=s;if(r?.dismissedMatchesByRule){let E=r.dismissedMatchesByRule.get(e.internalId);if(E&&E.length>0){let d=new Map;for(let p of c){let S=p.file.path;d.has(S)||d.set(S,[]),d.get(S).push(p)}let f=new Map;for(let p of E){let S=p.file.path;f.has(S)||f.set(S,[]),f.get(S).push(p)}let T=[];for(let[p,S]of d){let m=f.get(p)||[];if(m.length===0){T.push(...S);continue}let O=S.map(G=>({file:p,startLine:G.range.start.line,endLine:G.range.end.line,fingerprint:G.fingerprint})),h=m.map(G=>({file:p,startLine:G.range.start.line,endLine:G.range.end.line,fingerprint:G.fingerprint})),P=gh(O,h).map(G=>S.find(Y=>Y.range.start.line===G.startLine&&Y.range.end.line===G.endLine&&Y.fingerprint===G.fingerprint));T.push(...P)}c=T}}let u=c.sort((E,d)=>E.file.path.localeCompare(d.file.path)),l={ruleId:i,matches:u,cost:a};return this.previousResults.set(e.internalId,l),l}shouldDeduplicateMatches(e){return e.hasBaseContent!==void 0}getPoolSize(){let e=nat().length;return Math.max(2,Math.min(8,e))}async execute(e,n,r){this.eventEmitter.startRules(e.length);let i=this.getPoolSize(),o=[],s=[...e],a=async d=>{let f=d.id,T=!1;for(let O of d.steps)if(O.step.type==="llm"){T=!0;break}this.eventEmitter.emit("rules:rule-start",{ruleId:f,isLlm:T,message:d.message,severity:d.severity});let p=await this.executeRule(d,n,r||{});this.eventEmitter.emit("rules:rule-complete",{ruleId:f,matches:p.matches});let S=new Map;for(let O of p.matches){let h=O.file.path;S.has(h)||S.set(h,[]),S.get(h).push(O)}let m=r?.relativePath?[r.relativePath]:n.filePaths;for(let[O,h]of S.entries())this.eventEmitter.emit("rules:rule-file-complete",{ruleId:f,filePath:O,matches:h});for(let O of m)S.has(O)||this.eventEmitter.emit("rules:rule-file-complete",{ruleId:f,filePath:O,matches:[]});return p},c=async d=>{let f=await a(d).catch(T=>T);if(f instanceof Error){if(r?.emitErrors)return this.eventEmitter.errorRule(d.id,f,d.message,d.severity),{ruleId:d.id,matches:[]};let T=new Error(`Error executing rule "${d.id}" (${d.message}): ${f.message}`);throw T.stack=f.stack,T}return f};await(async()=>{let d=async()=>{if(s.length===0)return;let T=s.shift(),p=await c(T);o.push(p),await d()},f=[];for(let T=0;T<Math.min(i,e.length);T++)f.push(d());await Promise.all(f)})();let l=new Map(e.map((d,f)=>[d.id,f]));o.sort((d,f)=>{let T=l.get(d.ruleId)??0,p=l.get(f.ruleId)??0;return T-p});let E=o.reduce((d,f)=>d+f.matches.length,0);return this.eventEmitter.completeRules(e.length,E),Ae.logMemory(`After rules: ${e.length}`),this.sharedAstCache.logStats(),o}};import{stripVTControlCharacters as yQ}from"node:util";import fC from"node:process";import tQ from"node:process";import _C from"node:process";var rat=(t,e,n,r)=>{if(n==="length"||n==="prototype"||n==="arguments"||n==="caller")return;let i=Object.getOwnPropertyDescriptor(t,n),o=Object.getOwnPropertyDescriptor(e,n);!iat(i,o)&&r||Object.defineProperty(t,n,o)},iat=function(t,e){return t===void 0||t.configurable||t.writable===e.writable&&t.enumerable===e.enumerable&&t.configurable===e.configurable&&(t.writable||t.value===e.value)},oat=(t,e)=>{let n=Object.getPrototypeOf(e);n!==Object.getPrototypeOf(t)&&Object.setPrototypeOf(t,n)},sat=(t,e)=>`/* Wrapped ${t}*/
217
+ `)}var tat={read:WJ,grep:KJ,glob:zJ},aC=class{environment;eventEmitter;config;maxIterations;batchSize;constructor(e,n,r,i,o){this.environment=n,this.eventEmitter=r||new zr,this.config=e,this.maxIterations=i||20,this.batchSize=o||50}async executeTool(e,n,r,i){if(n==="report_fix")return{error:"Tool 'report_fix' is not supported in LLMStep. Available tools are: read, grep, glob"};let o=tat[n];if(!o)return{error:`Unknown tool: ${n}. Available tools are: read, grep, glob`};let s=HJ(n,r,[o]);if(!s.success)return{error:`Tool parameter validation failed: ${s.error}. Please fix the parameters and try again.`};let a=s.data;switch(n){case"read":{this.eventEmitter.llmToolExecution(e,"read",{file:a.target_file,offset:a.offset,limit:a.limit});let c=await qO(a,this.environment.getWorkspaceRoot());if(!("error"in c)){let u=a.target_file;i.some(l=>l.path===u)||i.push({path:u,sha:c.sha})}return"error"in c?c:c.content}case"grep":{this.eventEmitter.llmToolExecution(e,"grep",{path:a.path,pattern:a.pattern});let c=await JO(a,this.environment.getWorkspaceRoot(),[],ZJ());if(!("error"in c))for(let u of c.matches)i.some(l=>l.path===u.file)||i.push({path:u.file,sha:u.sha});return"error"in c?c:JSON.stringify(c.matches)}case"glob":{this.eventEmitter.llmToolExecution(e,"glob",{path:a.path,pattern:a.pattern});let c=await QO(a,this.environment.getWorkspaceRoot());return"error"in c?c:JSON.stringify(c.files)}default:return{error:`Unknown tool: ${n}`}}}async hydrateMatchesWithFileContent(e){let n=[];for(let r of e){let i=await t1(this.environment.getWorkspaceRoot(),r.file.path,r.range).catch(s=>{if(s.code==="ENOENT")return null;throw s});if(i===null)continue;let o=r.evidence;if(r.evidence&&r.evidence.length>0){o=[];let s=!1;for(let a of r.evidence){let c=await t1(this.environment.getWorkspaceRoot(),a.file.path,a.range).catch(u=>{if(u.code==="ENOENT")return null;throw u});if(c===null){s=!0;break}o.push({...a,text:c})}if(s)continue}n.push({...r,text:i,evidence:o})}return n}async executeLLMValidation(e,n,r){let i=Date.now(),o=this.config.getLLMProvider();this.eventEmitter.startLLMValidation(e.id,n.length);let s=[],a=[],c=new sr(0),u=new sr(0),l=new sr(0);this.eventEmitter.startLLMSearchPhase(e.id,n.length);let E,d=[],f=[];for(let h=0;h<this.maxIterations;h++){let C=await o.search({rule:e,matches:n,tools:r,messages:s,files:a});if(f.push(C),C.usage&&C.usage.inputTokens&&C.usage.outputTokens&&C.usage.cost&&(c=c.plus(new sr(C.usage.inputTokens)),u=u.plus(new sr(C.usage.outputTokens)),l=l.plus(new sr(C.usage.cost))),C.type==="partial_matches"){let P=await this.hydrateMatchesWithFileContent(C.matches);d=[...d,...P],n=C.unresolved;continue}if(C.type==="matches"){let P=await this.hydrateMatchesWithFileContent(C.matches);E={...C,matches:[...d,...P]};break}if(C.type==="request_files"){for(let P of C.files)a.some(G=>G.path===P.path)||a.push({path:P.path,sha:P.sha});continue}if(C.type==="assistant"){s.push({type:"assistant",content:C.content}),s.push({type:"user",content:"Please use tool calls to interact with the codebase and report violations."});continue}if(C.type==="tool_request"){s.push({type:"tool_request",tool_calls:C.tool_calls});let P=await Promise.all(C.tool_calls.map(async G=>{let Y=await this.executeTool(e.id,G.function.name,G.function.arguments,a),re=typeof Y=="string"?Y:JSON.stringify(Y);return{tool_call_id:G.id,content:re}}));s.push({type:"tool_response",tool_results:P});continue}}if(!E)throw this.eventEmitter.emit("llm:max-iterations-reached",{ruleId:e.id,maxIterations:this.maxIterations,messages:s,results:f}),new Error(`Max iterations (${this.maxIterations}) reached without getting matches`);let T=E.matches;if(T.length===0){let h=c.plus(u).toNumber();return this.eventEmitter.completeLLMValidation(e.id,h,c.toNumber(),u.toNumber(),l.toString(),Date.now()-i,0,!1),{matches:[],executionTime:Date.now()-i,cost:l.toString()}}this.eventEmitter.startLLMValidationPhase(e.id,T.length);let p=[],S=T;for(;S.length>0;){let h=await o.validate({rule:e,matches:S,files:a});if(h.usage&&h.usage.inputTokens&&h.usage.outputTokens&&h.usage.cost&&(c=c.plus(new sr(h.usage.inputTokens)),u=u.plus(new sr(h.usage.outputTokens)),l=l.plus(new sr(h.usage.cost))),h.type==="partial_matches"){let C=await this.hydrateMatchesWithFileContent(h.matches);p=[...p,...C],S=h.unresolved;continue}if(h.type==="matches"){let C=await this.hydrateMatchesWithFileContent(h.matches);p=[...p,...C];break}}let m=p,O=c.plus(u).toNumber();return this.eventEmitter.completeLLMValidation(e.id,O,c.toNumber(),u.toNumber(),l.toString(),Date.now()-i,m.length,!1),{matches:m,executionTime:Date.now()-i,cost:l.toString()}}async execute(e,n,r){if(n.length===0)return{matches:[],executionTime:0,cost:"0"};let i=Date.now(),o=[...n].sort((l,E)=>l.file.path!==E.file.path?l.file.path.localeCompare(E.file.path):l.range.start.line-E.range.start.line),s=[];for(let l=0;l<o.length;l+=this.batchSize)s.push(o.slice(l,l+this.batchSize));let a=s.length,c=[],u=new sr(0);for(let l=0;l<s.length;l++){let E=s[l],d=l+1,f=n.length-(l+1)*this.batchSize,T=Math.max(0,f);a>1&&this.eventEmitter.llmValidationPhaseBatch(e.id,d,a,E.length,T,n.length);let p=await this.executeLLMValidation(e,E,r);c=[...c,...p.matches],u=u.plus(new sr(p.cost))}return{matches:c,executionTime:Date.now()-i,cost:u.toString()}}};var La=class{fileFilterStep;findMatchesStep;llmStep;environment;eventEmitter;config;previousResults=new Map;inFlightLLMRequests=new Map;sharedAstCache;constructor(e,n,r){this.environment=n,this.eventEmitter=r||new zr,this.config=e,this.sharedAstCache=new Od,this.fileFilterStep=new jO(this.environment),this.findMatchesStep=new iC(this.environment,this.eventEmitter,this.sharedAstCache),this.llmStep=new aC(this.config,this.environment,this.eventEmitter)}clearCache(){this.previousResults.clear(),this.inFlightLLMRequests.clear(),this.sharedAstCache.clear()}async executeStep(e,n,r,i,o,s){let a=n.type;if(a==="ast-grep"){let{type:c,language:u,...l}=n,E=r.map(T=>o.getFileInput(T,!1)),d=await this.findMatchesStep.execute(l,u,{fileInputs:E}),f=[];if(this.shouldDeduplicateMatches(o)){let T=r.filter(p=>o.hasBaseContent(p));if(T.length>0){let p=T.map(m=>o.getFileInput(m,!0));f=(await this.findMatchesStep.execute(l,u,{fileInputs:p})).matches}}return{matches:d.matches,oldMatches:f}}if(a==="ripgrep"){let{type:c,...u}=n,l=r.map(f=>o.getFileInput(f,!1)),E=await this.findMatchesStep.execute(u,"Unknown",{fileInputs:l}),d=[];if(this.shouldDeduplicateMatches(o)){let f=r.filter(T=>o.hasBaseContent(T));if(f.length>0){let T=f.map(S=>o.getFileInput(S,!0));d=(await this.findMatchesStep.execute(u,"Unknown",{fileInputs:T})).matches}}return{matches:E.matches,oldMatches:d}}if(a==="file-filter")return{filePaths:this.fileFilterStep.execute(r,{include:n.include,ignore:n.ignore,additionalGlobs:this.config.getAdditionalGlobs()}).filteredPaths};if(a==="llm"){if(i.length===0)return{matches:[],cost:"0"};let c=[],u=i;if(this.previousResults.has(e.internalId)){let p=this.previousResults.get(e.internalId).matches,S=FV(i,p);if(c=S.remappedMatches,u=S.unmappedMatches,c.length>0){let m=c.length+u.length;this.eventEmitter.emit("rules:rule-partial",{ruleId:e.internalId,matches:c,totalMatches:m});let O=new Map;for(let h of c){let C=h.file.path;O.has(C)||O.set(C,[]),O.get(C).push(h)}for(let[h,C]of O.entries())this.eventEmitter.emit("rules:rule-file-partial",{ruleId:e.internalId,filePath:h,matches:C,totalMatches:m})}}if(u.length===0)return{matches:c,cost:"0"};let E=this.inFlightLLMRequests.get(e.internalId);if(E){let T=await E,{remappedMatches:p,unmappedMatches:S}=FV(u,T.matches);if(S.length>0){let m=this.llmStep.execute(e,S,n.tools??[]);this.inFlightLLMRequests.set(e.internalId,m);let O=await m;return this.inFlightLLMRequests.delete(e.internalId),{matches:[...c,...p,...O.matches],cost:O.cost}}else return{matches:[...c,...p],cost:"0"}}let d=this.llmStep.execute(e,u,n.tools??[]);this.inFlightLLMRequests.set(e.internalId,d);let f=await d;return this.inFlightLLMRequests.delete(e.internalId),{matches:[...c,...f.matches],cost:f.cost}}throw new Error(`Unknown step type: ${a}`)}async executeRule(e,n,r){let i=e.id,o=n.filePaths||[],s=r?.relativePath?o.filter(d=>d===r.relativePath):[...o],a=[],c;for(let d of e.steps){let f=d.id,T=d.step;if(T.type==="step-group"){let p=T.steps,S=[],O=p.some(h=>h.type==="ast-grep")?p.filter(h=>h.type!=="ripgrep"):p;for(let h=0;h<O.length;h++){let C=O[h],P=`${f}[${h}]`;this.eventEmitter.startStep(i,P,C.type,{filePaths:s,matches:a},f);let G=Date.now(),Y=await this.executeStep(e,C,s,a,n,r),re=Date.now()-G;Y.filePaths!==void 0&&(s=n.filterFiles(Y.filePaths));let W=[];if(Y.matches!==void 0){let q=Y.oldMatches||[];W=n.filterMatches(Y.matches,q),S=S.concat(W)}this.eventEmitter.completeStep(i,P,C.type,{filePaths:s,matches:W},re,f)}a=S}else{this.eventEmitter.startStep(i,f,T.type,{filePaths:s,matches:a});let p=Date.now(),S=await this.executeStep(e,T,s,a,n,r),m=Date.now()-p;if(S.filePaths!==void 0&&(s=n.filterFiles(S.filePaths),a=n.filterMatchesByFilePaths(a,s)),S.matches!==void 0){let O=S.oldMatches||[];a=n.filterMatches(S.matches,O)}S.cost!==void 0&&(c=S.cost),this.eventEmitter.completeStep(i,f,T.type,{filePaths:s,matches:a},m)}if(s.length===0)break}let u=a;if(r?.dismissedMatchesByRule){let d=r.dismissedMatchesByRule.get(e.internalId);if(d&&d.length>0){let f=new Map;for(let S of u){let m=S.file.path;f.has(m)||f.set(m,[]),f.get(m).push(S)}let T=new Map;for(let S of d){let m=S.file.path;T.has(m)||T.set(m,[]),T.get(m).push(S)}let p=[];for(let[S,m]of f){let O=T.get(S)||[];if(O.length===0){p.push(...m);continue}let h=m.map(Y=>({file:S,startLine:Y.range.start.line,endLine:Y.range.end.line,fingerprint:Y.fingerprint})),C=O.map(Y=>({file:S,startLine:Y.range.start.line,endLine:Y.range.end.line,fingerprint:Y.fingerprint})),G=gh(h,C).map(Y=>m.find(re=>re.range.start.line===Y.startLine&&re.range.end.line===Y.endLine&&re.fingerprint===Y.fingerprint));p.push(...G)}u=p}}let l=u.sort((d,f)=>d.file.path.localeCompare(f.file.path)),E={ruleId:i,matches:l,cost:c};return this.previousResults.set(e.internalId,E),E}shouldDeduplicateMatches(e){return e.hasBaseContent!==void 0}getPoolSize(){let e=nat().length;return Math.max(2,Math.min(8,e))}async execute(e,n,r){this.eventEmitter.startRules(e.length);let i=this.getPoolSize(),o=[],s=[...e],a=async d=>{let f=d.id,T=!1;for(let O of d.steps)if(O.step.type==="llm"){T=!0;break}this.eventEmitter.emit("rules:rule-start",{ruleId:f,isLlm:T,message:d.message,severity:d.severity});let p=await this.executeRule(d,n,r||{});this.eventEmitter.emit("rules:rule-complete",{ruleId:f,matches:p.matches});let S=new Map;for(let O of p.matches){let h=O.file.path;S.has(h)||S.set(h,[]),S.get(h).push(O)}let m=r?.relativePath?[r.relativePath]:n.filePaths||[];for(let[O,h]of S.entries())this.eventEmitter.emit("rules:rule-file-complete",{ruleId:f,filePath:O,matches:h});for(let O of m)S.has(O)||this.eventEmitter.emit("rules:rule-file-complete",{ruleId:f,filePath:O,matches:[]});return p},c=async d=>{let f=await a(d).catch(T=>T);if(f instanceof Error){if(r?.emitErrors)return this.eventEmitter.errorRule(d.id,f,d.message,d.severity),{ruleId:d.id,matches:[]};let T=new Error(`Error executing rule "${d.id}" (${d.message}): ${f.message}`);throw T.stack=f.stack,T}return f};await(async()=>{let d=async()=>{if(s.length===0)return;let T=s.shift(),p=await c(T);o.push(p),await d()},f=[];for(let T=0;T<Math.min(i,e.length);T++)f.push(d());await Promise.all(f)})();let l=new Map(e.map((d,f)=>[d.id,f]));o.sort((d,f)=>{let T=l.get(d.ruleId)??0,p=l.get(f.ruleId)??0;return T-p});let E=o.reduce((d,f)=>d+f.matches.length,0);return this.eventEmitter.completeRules(e.length,E),Ae.logMemory(`After rules: ${e.length}`),this.sharedAstCache.logStats(),o}};import{stripVTControlCharacters as yQ}from"node:util";import fC from"node:process";import tQ from"node:process";import _C from"node:process";var rat=(t,e,n,r)=>{if(n==="length"||n==="prototype"||n==="arguments"||n==="caller")return;let i=Object.getOwnPropertyDescriptor(t,n),o=Object.getOwnPropertyDescriptor(e,n);!iat(i,o)&&r||Object.defineProperty(t,n,o)},iat=function(t,e){return t===void 0||t.configurable||t.writable===e.writable&&t.enumerable===e.enumerable&&t.configurable===e.configurable&&(t.writable||t.value===e.value)},oat=(t,e)=>{let n=Object.getPrototypeOf(e);n!==Object.getPrototypeOf(t)&&Object.setPrototypeOf(t,n)},sat=(t,e)=>`/* Wrapped ${t}*/
218
218
  ${e}`,aat=Object.getOwnPropertyDescriptor(Function.prototype,"toString"),cat=Object.getOwnPropertyDescriptor(Function.prototype.toString,"name"),uat=(t,e,n)=>{let r=n===""?"":`with ${n.trim()}() `,i=sat.bind(null,r,e.toString());Object.defineProperty(i,"name",cat);let{writable:o,enumerable:s,configurable:a}=aat;Object.defineProperty(t,"toString",{value:i,writable:o,enumerable:s,configurable:a})};function n1(t,e,{ignoreNonConfigurable:n=!1}={}){let{name:r}=t;for(let i of Reflect.ownKeys(e))rat(t,e,i,n);return oat(t,e),uat(t,e,r),t}var cC=new WeakMap,XJ=(t,e={})=>{if(typeof t!="function")throw new TypeError("Expected a function");let n,r=0,i=t.displayName||t.name||"<anonymous>",o=function(...s){if(cC.set(o,++r),r===1)n=t.apply(this,s),t=void 0;else if(e.throw===!0)throw new Error(`Function \`${i}\` can only be called once`);return n};return n1(o,t),cC.set(o,r),o};XJ.callCount=t=>{if(!cC.has(t))throw new Error(`The given function \`${t.name}\` is not wrapped by the \`onetime\` package`);return cC.get(t)};var qJ=XJ;var ql=[];ql.push("SIGHUP","SIGINT","SIGTERM");process.platform!=="win32"&&ql.push("SIGALRM","SIGABRT","SIGVTALRM","SIGXCPU","SIGXFSZ","SIGUSR2","SIGTRAP","SIGSYS","SIGQUIT","SIGIOT");process.platform==="linux"&&ql.push("SIGIO","SIGPOLL","SIGPWR","SIGSTKFLT");var uC=t=>!!t&&typeof t=="object"&&typeof t.removeListener=="function"&&typeof t.emit=="function"&&typeof t.reallyExit=="function"&&typeof t.listeners=="function"&&typeof t.kill=="function"&&typeof t.pid=="number"&&typeof t.on=="function",r1=Symbol.for("signal-exit emitter"),i1=globalThis,lat=Object.defineProperty.bind(Object),o1=class{emitted={afterExit:!1,exit:!1};listeners={afterExit:[],exit:[]};count=0;id=Math.random();constructor(){if(i1[r1])return i1[r1];lat(i1,r1,{value:this,writable:!1,enumerable:!1,configurable:!1})}on(e,n){this.listeners[e].push(n)}removeListener(e,n){let r=this.listeners[e],i=r.indexOf(n);i!==-1&&(i===0&&r.length===1?r.length=0:r.splice(i,1))}emit(e,n,r){if(this.emitted[e])return!1;this.emitted[e]=!0;let i=!1;for(let o of this.listeners[e])i=o(n,r)===!0||i;return e==="exit"&&(i=this.emit("afterExit",n,r)||i),i}},lC=class{},_at=t=>({onExit(e,n){return t.onExit(e,n)},load(){return t.load()},unload(){return t.unload()}}),s1=class extends lC{onExit(){return()=>{}}load(){}unload(){}},a1=class extends lC{#e=c1.platform==="win32"?"SIGINT":"SIGHUP";#n=new o1;#t;#a;#d;#p={};#c=!1;constructor(e){super(),this.#t=e,this.#p={};for(let n of ql)this.#p[n]=()=>{let r=this.#t.listeners(n),{count:i}=this.#n,o=e;if(typeof o.__signal_exit_emitter__=="object"&&typeof o.__signal_exit_emitter__.count=="number"&&(i+=o.__signal_exit_emitter__.count),r.length===i){this.unload();let s=this.#n.emit("exit",null,n),a=n==="SIGHUP"?this.#e:n;s||e.kill(e.pid,a)}};this.#d=e.reallyExit,this.#a=e.emit}onExit(e,n){if(!uC(this.#t))return()=>{};this.#c===!1&&this.load();let r=n?.alwaysLast?"afterExit":"exit";return this.#n.on(r,e),()=>{this.#n.removeListener(r,e),this.#n.listeners.exit.length===0&&this.#n.listeners.afterExit.length===0&&this.unload()}}load(){if(!this.#c){this.#c=!0,this.#n.count+=1;for(let e of ql)try{let n=this.#p[e];n&&this.#t.on(e,n)}catch{}this.#t.emit=(e,...n)=>this.#r(e,...n),this.#t.reallyExit=e=>this.#l(e)}}unload(){this.#c&&(this.#c=!1,ql.forEach(e=>{let n=this.#p[e];if(!n)throw new Error("Listener not defined for signal: "+e);try{this.#t.removeListener(e,n)}catch{}}),this.#t.emit=this.#a,this.#t.reallyExit=this.#d,this.#n.count-=1)}#l(e){return uC(this.#t)?(this.#t.exitCode=e||0,this.#n.emit("exit",this.#t.exitCode,null),this.#d.call(this.#t,this.#t.exitCode)):0}#r(e,...n){let r=this.#a;if(e==="exit"&&uC(this.#t)){typeof n[0]=="number"&&(this.#t.exitCode=n[0]);let i=r.call(this.#t,e,...n);return this.#n.emit("exit",this.#t.exitCode,null),i}else return r.call(this.#t,e,...n)}},c1=globalThis.process,{onExit:JJ,load:b1t,unload:v1t}=_at(uC(c1)?new a1(c1):new s1);var QJ=_C.stderr.isTTY?_C.stderr:_C.stdout.isTTY?_C.stdout:void 0,Eat=QJ?qJ(()=>{JJ(()=>{QJ.write("\x1B[?25h")},{alwaysLast:!0})}):()=>{},eQ=Eat;var EC=!1,Pd={};Pd.show=(t=tQ.stderr)=>{t.isTTY&&(EC=!1,t.write("\x1B[?25h"))};Pd.hide=(t=tQ.stderr)=>{t.isTTY&&(eQ(),EC=!0,t.write("\x1B[?25l"))};Pd.toggle=(t,e)=>{t!==void 0&&(EC=t),EC?Pd.show(e):Pd.hide(e)};var u1=Pd;var l1={dots:{interval:80,frames:["\u280B","\u2819","\u2839","\u2838","\u283C","\u2834","\u2826","\u2827","\u2807","\u280F"]},dots2:{interval:80,frames:["\u28FE","\u28FD","\u28FB","\u28BF","\u287F","\u28DF","\u28EF","\u28F7"]},dots3:{interval:80,frames:["\u280B","\u2819","\u281A","\u281E","\u2816","\u2826","\u2834","\u2832","\u2833","\u2813"]},dots4:{interval:80,frames:["\u2804","\u2806","\u2807","\u280B","\u2819","\u2838","\u2830","\u2820","\u2830","\u2838","\u2819","\u280B","\u2807","\u2806"]},dots5:{interval:80,frames:["\u280B","\u2819","\u281A","\u2812","\u2802","\u2802","\u2812","\u2832","\u2834","\u2826","\u2816","\u2812","\u2810","\u2810","\u2812","\u2813","\u280B"]},dots6:{interval:80,frames:["\u2801","\u2809","\u2819","\u281A","\u2812","\u2802","\u2802","\u2812","\u2832","\u2834","\u2824","\u2804","\u2804","\u2824","\u2834","\u2832","\u2812","\u2802","\u2802","\u2812","\u281A","\u2819","\u2809","\u2801"]},dots7:{interval:80,frames:["\u2808","\u2809","\u280B","\u2813","\u2812","\u2810","\u2810","\u2812","\u2816","\u2826","\u2824","\u2820","\u2820","\u2824","\u2826","\u2816","\u2812","\u2810","\u2810","\u2812","\u2813","\u280B","\u2809","\u2808"]},dots8:{interval:80,frames:["\u2801","\u2801","\u2809","\u2819","\u281A","\u2812","\u2802","\u2802","\u2812","\u2832","\u2834","\u2824","\u2804","\u2804","\u2824","\u2820","\u2820","\u2824","\u2826","\u2816","\u2812","\u2810","\u2810","\u2812","\u2813","\u280B","\u2809","\u2808","\u2808"]},dots9:{interval:80,frames:["\u28B9","\u28BA","\u28BC","\u28F8","\u28C7","\u2867","\u2857","\u284F"]},dots10:{interval:80,frames:["\u2884","\u2882","\u2881","\u2841","\u2848","\u2850","\u2860"]},dots11:{interval:100,frames:["\u2801","\u2802","\u2804","\u2840","\u2880","\u2820","\u2810","\u2808"]},dots12:{interval:80,frames:["\u2880\u2800","\u2840\u2800","\u2804\u2800","\u2882\u2800","\u2842\u2800","\u2805\u2800","\u2883\u2800","\u2843\u2800","\u280D\u2800","\u288B\u2800","\u284B\u2800","\u280D\u2801","\u288B\u2801","\u284B\u2801","\u280D\u2809","\u280B\u2809","\u280B\u2809","\u2809\u2819","\u2809\u2819","\u2809\u2829","\u2808\u2899","\u2808\u2859","\u2888\u2829","\u2840\u2899","\u2804\u2859","\u2882\u2829","\u2842\u2898","\u2805\u2858","\u2883\u2828","\u2843\u2890","\u280D\u2850","\u288B\u2820","\u284B\u2880","\u280D\u2841","\u288B\u2801","\u284B\u2801","\u280D\u2809","\u280B\u2809","\u280B\u2809","\u2809\u2819","\u2809\u2819","\u2809\u2829","\u2808\u2899","\u2808\u2859","\u2808\u2829","\u2800\u2899","\u2800\u2859","\u2800\u2829","\u2800\u2898","\u2800\u2858","\u2800\u2828","\u2800\u2890","\u2800\u2850","\u2800\u2820","\u2800\u2880","\u2800\u2840"]},dots13:{interval:80,frames:["\u28FC","\u28F9","\u28BB","\u283F","\u285F","\u28CF","\u28E7","\u28F6"]},dots14:{interval:80,frames:["\u2809\u2809","\u2808\u2819","\u2800\u2839","\u2800\u28B8","\u2800\u28F0","\u2880\u28E0","\u28C0\u28C0","\u28C4\u2840","\u28C6\u2800","\u2847\u2800","\u280F\u2800","\u280B\u2801"]},dots8Bit:{interval:80,frames:["\u2800","\u2801","\u2802","\u2803","\u2804","\u2805","\u2806","\u2807","\u2840","\u2841","\u2842","\u2843","\u2844","\u2845","\u2846","\u2847","\u2808","\u2809","\u280A","\u280B","\u280C","\u280D","\u280E","\u280F","\u2848","\u2849","\u284A","\u284B","\u284C","\u284D","\u284E","\u284F","\u2810","\u2811","\u2812","\u2813","\u2814","\u2815","\u2816","\u2817","\u2850","\u2851","\u2852","\u2853","\u2854","\u2855","\u2856","\u2857","\u2818","\u2819","\u281A","\u281B","\u281C","\u281D","\u281E","\u281F","\u2858","\u2859","\u285A","\u285B","\u285C","\u285D","\u285E","\u285F","\u2820","\u2821","\u2822","\u2823","\u2824","\u2825","\u2826","\u2827","\u2860","\u2861","\u2862","\u2863","\u2864","\u2865","\u2866","\u2867","\u2828","\u2829","\u282A","\u282B","\u282C","\u282D","\u282E","\u282F","\u2868","\u2869","\u286A","\u286B","\u286C","\u286D","\u286E","\u286F","\u2830","\u2831","\u2832","\u2833","\u2834","\u2835","\u2836","\u2837","\u2870","\u2871","\u2872","\u2873","\u2874","\u2875","\u2876","\u2877","\u2838","\u2839","\u283A","\u283B","\u283C","\u283D","\u283E","\u283F","\u2878","\u2879","\u287A","\u287B","\u287C","\u287D","\u287E","\u287F","\u2880","\u2881","\u2882","\u2883","\u2884","\u2885","\u2886","\u2887","\u28C0","\u28C1","\u28C2","\u28C3","\u28C4","\u28C5","\u28C6","\u28C7","\u2888","\u2889","\u288A","\u288B","\u288C","\u288D","\u288E","\u288F","\u28C8","\u28C9","\u28CA","\u28CB","\u28CC","\u28CD","\u28CE","\u28CF","\u2890","\u2891","\u2892","\u2893","\u2894","\u2895","\u2896","\u2897","\u28D0","\u28D1","\u28D2","\u28D3","\u28D4","\u28D5","\u28D6","\u28D7","\u2898","\u2899","\u289A","\u289B","\u289C","\u289D","\u289E","\u289F","\u28D8","\u28D9","\u28DA","\u28DB","\u28DC","\u28DD","\u28DE","\u28DF","\u28A0","\u28A1","\u28A2","\u28A3","\u28A4","\u28A5","\u28A6","\u28A7","\u28E0","\u28E1","\u28E2","\u28E3","\u28E4","\u28E5","\u28E6","\u28E7","\u28A8","\u28A9","\u28AA","\u28AB","\u28AC","\u28AD","\u28AE","\u28AF","\u28E8","\u28E9","\u28EA","\u28EB","\u28EC","\u28ED","\u28EE","\u28EF","\u28B0","\u28B1","\u28B2","\u28B3","\u28B4","\u28B5","\u28B6","\u28B7","\u28F0","\u28F1","\u28F2","\u28F3","\u28F4","\u28F5","\u28F6","\u28F7","\u28B8","\u28B9","\u28BA","\u28BB","\u28BC","\u28BD","\u28BE","\u28BF","\u28F8","\u28F9","\u28FA","\u28FB","\u28FC","\u28FD","\u28FE","\u28FF"]},dotsCircle:{interval:80,frames:["\u288E ","\u280E\u2801","\u280A\u2811","\u2808\u2831"," \u2871","\u2880\u2870","\u2884\u2860","\u2886\u2840"]},sand:{interval:80,frames:["\u2801","\u2802","\u2804","\u2840","\u2848","\u2850","\u2860","\u28C0","\u28C1","\u28C2","\u28C4","\u28CC","\u28D4","\u28E4","\u28E5","\u28E6","\u28EE","\u28F6","\u28F7","\u28FF","\u287F","\u283F","\u289F","\u281F","\u285B","\u281B","\u282B","\u288B","\u280B","\u280D","\u2849","\u2809","\u2811","\u2821","\u2881"]},line:{interval:130,frames:["-","\\","|","/"]},line2:{interval:100,frames:["\u2802","-","\u2013","\u2014","\u2013","-"]},rollingLine:{interval:80,frames:["/ "," - "," \\ "," |"," |"," \\ "," - ","/ "]},pipe:{interval:100,frames:["\u2524","\u2518","\u2534","\u2514","\u251C","\u250C","\u252C","\u2510"]},simpleDots:{interval:400,frames:[". ",".. ","..."," "]},simpleDotsScrolling:{interval:200,frames:[". ",".. ","..."," .."," ."," "]},star:{interval:70,frames:["\u2736","\u2738","\u2739","\u273A","\u2739","\u2737"]},star2:{interval:80,frames:["+","x","*"]},flip:{interval:70,frames:["_","_","_","-","`","`","'","\xB4","-","_","_","_"]},hamburger:{interval:100,frames:["\u2631","\u2632","\u2634"]},growVertical:{interval:120,frames:["\u2581","\u2583","\u2584","\u2585","\u2586","\u2587","\u2586","\u2585","\u2584","\u2583"]},growHorizontal:{interval:120,frames:["\u258F","\u258E","\u258D","\u258C","\u258B","\u258A","\u2589","\u258A","\u258B","\u258C","\u258D","\u258E"]},balloon:{interval:140,frames:[" ",".","o","O","@","*"," "]},balloon2:{interval:120,frames:[".","o","O","\xB0","O","o","."]},noise:{interval:100,frames:["\u2593","\u2592","\u2591"]},bounce:{interval:120,frames:["\u2801","\u2802","\u2804","\u2802"]},boxBounce:{interval:120,frames:["\u2596","\u2598","\u259D","\u2597"]},boxBounce2:{interval:100,frames:["\u258C","\u2580","\u2590","\u2584"]},triangle:{interval:50,frames:["\u25E2","\u25E3","\u25E4","\u25E5"]},binary:{interval:80,frames:["010010","001100","100101","111010","111101","010111","101011","111000","110011","110101"]},arc:{interval:100,frames:["\u25DC","\u25E0","\u25DD","\u25DE","\u25E1","\u25DF"]},circle:{interval:120,frames:["\u25E1","\u2299","\u25E0"]},squareCorners:{interval:180,frames:["\u25F0","\u25F3","\u25F2","\u25F1"]},circleQuarters:{interval:120,frames:["\u25F4","\u25F7","\u25F6","\u25F5"]},circleHalves:{interval:50,frames:["\u25D0","\u25D3","\u25D1","\u25D2"]},squish:{interval:100,frames:["\u256B","\u256A"]},toggle:{interval:250,frames:["\u22B6","\u22B7"]},toggle2:{interval:80,frames:["\u25AB","\u25AA"]},toggle3:{interval:120,frames:["\u25A1","\u25A0"]},toggle4:{interval:100,frames:["\u25A0","\u25A1","\u25AA","\u25AB"]},toggle5:{interval:100,frames:["\u25AE","\u25AF"]},toggle6:{interval:300,frames:["\u101D","\u1040"]},toggle7:{interval:80,frames:["\u29BE","\u29BF"]},toggle8:{interval:100,frames:["\u25CD","\u25CC"]},toggle9:{interval:100,frames:["\u25C9","\u25CE"]},toggle10:{interval:100,frames:["\u3282","\u3280","\u3281"]},toggle11:{interval:50,frames:["\u29C7","\u29C6"]},toggle12:{interval:120,frames:["\u2617","\u2616"]},toggle13:{interval:80,frames:["=","*","-"]},arrow:{interval:100,frames:["\u2190","\u2196","\u2191","\u2197","\u2192","\u2198","\u2193","\u2199"]},arrow2:{interval:80,frames:["\u2B06\uFE0F ","\u2197\uFE0F ","\u27A1\uFE0F ","\u2198\uFE0F ","\u2B07\uFE0F ","\u2199\uFE0F ","\u2B05\uFE0F ","\u2196\uFE0F "]},arrow3:{interval:120,frames:["\u25B9\u25B9\u25B9\u25B9\u25B9","\u25B8\u25B9\u25B9\u25B9\u25B9","\u25B9\u25B8\u25B9\u25B9\u25B9","\u25B9\u25B9\u25B8\u25B9\u25B9","\u25B9\u25B9\u25B9\u25B8\u25B9","\u25B9\u25B9\u25B9\u25B9\u25B8"]},bouncingBar:{interval:80,frames:["[ ]","[= ]","[== ]","[=== ]","[====]","[ ===]","[ ==]","[ =]","[ ]","[ =]","[ ==]","[ ===]","[====]","[=== ]","[== ]","[= ]"]},bouncingBall:{interval:80,frames:["( \u25CF )","( \u25CF )","( \u25CF )","( \u25CF )","( \u25CF)","( \u25CF )","( \u25CF )","( \u25CF )","( \u25CF )","(\u25CF )"]},smiley:{interval:200,frames:["\u{1F604} ","\u{1F61D} "]},monkey:{interval:300,frames:["\u{1F648} ","\u{1F648} ","\u{1F649} ","\u{1F64A} "]},hearts:{interval:100,frames:["\u{1F49B} ","\u{1F499} ","\u{1F49C} ","\u{1F49A} ","\u{1F497} "]},clock:{interval:100,frames:["\u{1F55B} ","\u{1F550} ","\u{1F551} ","\u{1F552} ","\u{1F553} ","\u{1F554} ","\u{1F555} ","\u{1F556} ","\u{1F557} ","\u{1F558} ","\u{1F559} ","\u{1F55A} "]},earth:{interval:180,frames:["\u{1F30D} ","\u{1F30E} ","\u{1F30F} "]},material:{interval:17,frames:["\u2588\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581","\u2588\u2588\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581","\u2588\u2588\u2588\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581","\u2588\u2588\u2588\u2588\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581","\u2588\u2588\u2588\u2588\u2588\u2588\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581","\u2588\u2588\u2588\u2588\u2588\u2588\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581","\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581","\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581","\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581","\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581","\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581","\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581","\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2581\u2581\u2581\u2581\u2581\u2581\u2581","\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2581\u2581\u2581\u2581\u2581\u2581","\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2581\u2581\u2581\u2581\u2581\u2581","\u2581\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2581\u2581\u2581\u2581\u2581","\u2581\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2581\u2581\u2581\u2581\u2581","\u2581\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2581\u2581\u2581\u2581\u2581","\u2581\u2581\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2581\u2581\u2581\u2581","\u2581\u2581\u2581\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2581\u2581\u2581","\u2581\u2581\u2581\u2581\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2581\u2581\u2581","\u2581\u2581\u2581\u2581\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2581\u2581","\u2581\u2581\u2581\u2581\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2581\u2581","\u2581\u2581\u2581\u2581\u2581\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2581","\u2581\u2581\u2581\u2581\u2581\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2581","\u2581\u2581\u2581\u2581\u2581\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2581","\u2581\u2581\u2581\u2581\u2581\u2581\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588","\u2581\u2581\u2581\u2581\u2581\u2581\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588","\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588","\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588","\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588","\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588","\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588","\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588","\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588","\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588","\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588","\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2588\u2588\u2588\u2588\u2588\u2588\u2588","\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2588\u2588\u2588\u2588\u2588\u2588","\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2588\u2588\u2588\u2588\u2588","\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2588\u2588\u2588\u2588\u2588","\u2588\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2588\u2588\u2588\u2588","\u2588\u2588\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2588\u2588\u2588","\u2588\u2588\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2588\u2588\u2588","\u2588\u2588\u2588\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2588\u2588\u2588","\u2588\u2588\u2588\u2588\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2588\u2588","\u2588\u2588\u2588\u2588\u2588\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2588","\u2588\u2588\u2588\u2588\u2588\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2588","\u2588\u2588\u2588\u2588\u2588\u2588\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2588","\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581","\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581","\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581","\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581","\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581","\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581","\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581","\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581","\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2581\u2581\u2581\u2581\u2581\u2581","\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2581\u2581\u2581\u2581\u2581\u2581","\u2581\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2581\u2581\u2581\u2581\u2581","\u2581\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2581\u2581\u2581\u2581\u2581","\u2581\u2581\u2581\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2581\u2581\u2581\u2581","\u2581\u2581\u2581\u2581\u2581\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2581\u2581\u2581","\u2581\u2581\u2581\u2581\u2581\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2581\u2581\u2581","\u2581\u2581\u2581\u2581\u2581\u2581\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2581\u2581\u2581","\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2581\u2581\u2581","\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2581\u2581\u2581","\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2581\u2581","\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2581\u2581","\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2581","\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2581","\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2581","\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2581","\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2581","\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2588\u2588\u2588\u2588\u2588\u2588\u2588","\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2588\u2588\u2588\u2588\u2588\u2588\u2588","\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2588\u2588\u2588\u2588\u2588","\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2588\u2588\u2588\u2588","\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2588\u2588\u2588\u2588","\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2588\u2588\u2588\u2588","\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2588\u2588\u2588","\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2588\u2588\u2588","\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2588\u2588","\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2588\u2588","\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2588\u2588","\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2588","\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2588","\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2588","\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581","\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581","\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581","\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581"]},moon:{interval:80,frames:["\u{1F311} ","\u{1F312} ","\u{1F313} ","\u{1F314} ","\u{1F315} ","\u{1F316} ","\u{1F317} ","\u{1F318} "]},runner:{interval:140,frames:["\u{1F6B6} ","\u{1F3C3} "]},pong:{interval:80,frames:["\u2590\u2802 \u258C","\u2590\u2808 \u258C","\u2590 \u2802 \u258C","\u2590 \u2820 \u258C","\u2590 \u2840 \u258C","\u2590 \u2820 \u258C","\u2590 \u2802 \u258C","\u2590 \u2808 \u258C","\u2590 \u2802 \u258C","\u2590 \u2820 \u258C","\u2590 \u2840 \u258C","\u2590 \u2820 \u258C","\u2590 \u2802 \u258C","\u2590 \u2808 \u258C","\u2590 \u2802\u258C","\u2590 \u2820\u258C","\u2590 \u2840\u258C","\u2590 \u2820 \u258C","\u2590 \u2802 \u258C","\u2590 \u2808 \u258C","\u2590 \u2802 \u258C","\u2590 \u2820 \u258C","\u2590 \u2840 \u258C","\u2590 \u2820 \u258C","\u2590 \u2802 \u258C","\u2590 \u2808 \u258C","\u2590 \u2802 \u258C","\u2590 \u2820 \u258C","\u2590 \u2840 \u258C","\u2590\u2820 \u258C"]},shark:{interval:120,frames:["\u2590|\\____________\u258C","\u2590_|\\___________\u258C","\u2590__|\\__________\u258C","\u2590___|\\_________\u258C","\u2590____|\\________\u258C","\u2590_____|\\_______\u258C","\u2590______|\\______\u258C","\u2590_______|\\_____\u258C","\u2590________|\\____\u258C","\u2590_________|\\___\u258C","\u2590__________|\\__\u258C","\u2590___________|\\_\u258C","\u2590____________|\\\u258C","\u2590____________/|\u258C","\u2590___________/|_\u258C","\u2590__________/|__\u258C","\u2590_________/|___\u258C","\u2590________/|____\u258C","\u2590_______/|_____\u258C","\u2590______/|______\u258C","\u2590_____/|_______\u258C","\u2590____/|________\u258C","\u2590___/|_________\u258C","\u2590__/|__________\u258C","\u2590_/|___________\u258C","\u2590/|____________\u258C"]},dqpb:{interval:100,frames:["d","q","p","b"]},weather:{interval:100,frames:["\u2600\uFE0F ","\u2600\uFE0F ","\u2600\uFE0F ","\u{1F324} ","\u26C5\uFE0F ","\u{1F325} ","\u2601\uFE0F ","\u{1F327} ","\u{1F328} ","\u{1F327} ","\u{1F328} ","\u{1F327} ","\u{1F328} ","\u26C8 ","\u{1F328} ","\u{1F327} ","\u{1F328} ","\u2601\uFE0F ","\u{1F325} ","\u26C5\uFE0F ","\u{1F324} ","\u2600\uFE0F ","\u2600\uFE0F "]},christmas:{interval:400,frames:["\u{1F332}","\u{1F384}"]},grenade:{interval:80,frames:["\u060C ","\u2032 "," \xB4 "," \u203E "," \u2E0C"," \u2E0A"," |"," \u204E"," \u2055"," \u0DF4 "," \u2053"," "," "," "]},point:{interval:125,frames:["\u2219\u2219\u2219","\u25CF\u2219\u2219","\u2219\u25CF\u2219","\u2219\u2219\u25CF","\u2219\u2219\u2219"]},layer:{interval:150,frames:["-","=","\u2261"]},betaWave:{interval:80,frames:["\u03C1\u03B2\u03B2\u03B2\u03B2\u03B2\u03B2","\u03B2\u03C1\u03B2\u03B2\u03B2\u03B2\u03B2","\u03B2\u03B2\u03C1\u03B2\u03B2\u03B2\u03B2","\u03B2\u03B2\u03B2\u03C1\u03B2\u03B2\u03B2","\u03B2\u03B2\u03B2\u03B2\u03C1\u03B2\u03B2","\u03B2\u03B2\u03B2\u03B2\u03B2\u03C1\u03B2","\u03B2\u03B2\u03B2\u03B2\u03B2\u03B2\u03C1"]},fingerDance:{interval:160,frames:["\u{1F918} ","\u{1F91F} ","\u{1F596} ","\u270B ","\u{1F91A} ","\u{1F446} "]},fistBump:{interval:80,frames:["\u{1F91C}\u3000\u3000\u3000\u3000\u{1F91B} ","\u{1F91C}\u3000\u3000\u3000\u3000\u{1F91B} ","\u{1F91C}\u3000\u3000\u3000\u3000\u{1F91B} ","\u3000\u{1F91C}\u3000\u3000\u{1F91B}\u3000 ","\u3000\u3000\u{1F91C}\u{1F91B}\u3000\u3000 ","\u3000\u{1F91C}\u2728\u{1F91B}\u3000\u3000 ","\u{1F91C}\u3000\u2728\u3000\u{1F91B}\u3000 "]},soccerHeader:{interval:80,frames:[" \u{1F9D1}\u26BD\uFE0F \u{1F9D1} ","\u{1F9D1} \u26BD\uFE0F \u{1F9D1} ","\u{1F9D1} \u26BD\uFE0F \u{1F9D1} ","\u{1F9D1} \u26BD\uFE0F \u{1F9D1} ","\u{1F9D1} \u26BD\uFE0F \u{1F9D1} ","\u{1F9D1} \u26BD\uFE0F \u{1F9D1} ","\u{1F9D1} \u26BD\uFE0F\u{1F9D1} ","\u{1F9D1} \u26BD\uFE0F \u{1F9D1} ","\u{1F9D1} \u26BD\uFE0F \u{1F9D1} ","\u{1F9D1} \u26BD\uFE0F \u{1F9D1} ","\u{1F9D1} \u26BD\uFE0F \u{1F9D1} ","\u{1F9D1} \u26BD\uFE0F \u{1F9D1} "]},mindblown:{interval:160,frames:["\u{1F610} ","\u{1F610} ","\u{1F62E} ","\u{1F62E} ","\u{1F626} ","\u{1F626} ","\u{1F627} ","\u{1F627} ","\u{1F92F} ","\u{1F4A5} ","\u2728 ","\u3000 ","\u3000 ","\u3000 "]},speaker:{interval:160,frames:["\u{1F508} ","\u{1F509} ","\u{1F50A} ","\u{1F509} "]},orangePulse:{interval:100,frames:["\u{1F538} ","\u{1F536} ","\u{1F7E0} ","\u{1F7E0} ","\u{1F536} "]},bluePulse:{interval:100,frames:["\u{1F539} ","\u{1F537} ","\u{1F535} ","\u{1F535} ","\u{1F537} "]},orangeBluePulse:{interval:100,frames:["\u{1F538} ","\u{1F536} ","\u{1F7E0} ","\u{1F7E0} ","\u{1F536} ","\u{1F539} ","\u{1F537} ","\u{1F535} ","\u{1F535} ","\u{1F537} "]},timeTravel:{interval:100,frames:["\u{1F55B} ","\u{1F55A} ","\u{1F559} ","\u{1F558} ","\u{1F557} ","\u{1F556} ","\u{1F555} ","\u{1F554} ","\u{1F553} ","\u{1F552} ","\u{1F551} ","\u{1F550} "]},aesthetic:{interval:80,frames:["\u25B0\u25B1\u25B1\u25B1\u25B1\u25B1\u25B1","\u25B0\u25B0\u25B1\u25B1\u25B1\u25B1\u25B1","\u25B0\u25B0\u25B0\u25B1\u25B1\u25B1\u25B1","\u25B0\u25B0\u25B0\u25B0\u25B1\u25B1\u25B1","\u25B0\u25B0\u25B0\u25B0\u25B0\u25B1\u25B1","\u25B0\u25B0\u25B0\u25B0\u25B0\u25B0\u25B1","\u25B0\u25B0\u25B0\u25B0\u25B0\u25B0\u25B0","\u25B0\u25B1\u25B1\u25B1\u25B1\u25B1\u25B1"]},dwarfFortress:{interval:80,frames:[" \u2588\u2588\u2588\u2588\u2588\u2588\xA3\xA3\xA3 ","\u263A\u2588\u2588\u2588\u2588\u2588\u2588\xA3\xA3\xA3 ","\u263A\u2588\u2588\u2588\u2588\u2588\u2588\xA3\xA3\xA3 ","\u263A\u2593\u2588\u2588\u2588\u2588\u2588\xA3\xA3\xA3 ","\u263A\u2593\u2588\u2588\u2588\u2588\u2588\xA3\xA3\xA3 ","\u263A\u2592\u2588\u2588\u2588\u2588\u2588\xA3\xA3\xA3 ","\u263A\u2592\u2588\u2588\u2588\u2588\u2588\xA3\xA3\xA3 ","\u263A\u2591\u2588\u2588\u2588\u2588\u2588\xA3\xA3\xA3 ","\u263A\u2591\u2588\u2588\u2588\u2588\u2588\xA3\xA3\xA3 ","\u263A \u2588\u2588\u2588\u2588\u2588\xA3\xA3\xA3 "," \u263A\u2588\u2588\u2588\u2588\u2588\xA3\xA3\xA3 "," \u263A\u2588\u2588\u2588\u2588\u2588\xA3\xA3\xA3 "," \u263A\u2593\u2588\u2588\u2588\u2588\xA3\xA3\xA3 "," \u263A\u2593\u2588\u2588\u2588\u2588\xA3\xA3\xA3 "," \u263A\u2592\u2588\u2588\u2588\u2588\xA3\xA3\xA3 "," \u263A\u2592\u2588\u2588\u2588\u2588\xA3\xA3\xA3 "," \u263A\u2591\u2588\u2588\u2588\u2588\xA3\xA3\xA3 "," \u263A\u2591\u2588\u2588\u2588\u2588\xA3\xA3\xA3 "," \u263A \u2588\u2588\u2588\u2588\xA3\xA3\xA3 "," \u263A\u2588\u2588\u2588\u2588\xA3\xA3\xA3 "," \u263A\u2588\u2588\u2588\u2588\xA3\xA3\xA3 "," \u263A\u2593\u2588\u2588\u2588\xA3\xA3\xA3 "," \u263A\u2593\u2588\u2588\u2588\xA3\xA3\xA3 "," \u263A\u2592\u2588\u2588\u2588\xA3\xA3\xA3 "," \u263A\u2592\u2588\u2588\u2588\xA3\xA3\xA3 "," \u263A\u2591\u2588\u2588\u2588\xA3\xA3\xA3 "," \u263A\u2591\u2588\u2588\u2588\xA3\xA3\xA3 "," \u263A \u2588\u2588\u2588\xA3\xA3\xA3 "," \u263A\u2588\u2588\u2588\xA3\xA3\xA3 "," \u263A\u2588\u2588\u2588\xA3\xA3\xA3 "," \u263A\u2593\u2588\u2588\xA3\xA3\xA3 "," \u263A\u2593\u2588\u2588\xA3\xA3\xA3 "," \u263A\u2592\u2588\u2588\xA3\xA3\xA3 "," \u263A\u2592\u2588\u2588\xA3\xA3\xA3 "," \u263A\u2591\u2588\u2588\xA3\xA3\xA3 "," \u263A\u2591\u2588\u2588\xA3\xA3\xA3 "," \u263A \u2588\u2588\xA3\xA3\xA3 "," \u263A\u2588\u2588\xA3\xA3\xA3 "," \u263A\u2588\u2588\xA3\xA3\xA3 "," \u263A\u2593\u2588\xA3\xA3\xA3 "," \u263A\u2593\u2588\xA3\xA3\xA3 "," \u263A\u2592\u2588\xA3\xA3\xA3 "," \u263A\u2592\u2588\xA3\xA3\xA3 "," \u263A\u2591\u2588\xA3\xA3\xA3 "," \u263A\u2591\u2588\xA3\xA3\xA3 "," \u263A \u2588\xA3\xA3\xA3 "," \u263A\u2588\xA3\xA3\xA3 "," \u263A\u2588\xA3\xA3\xA3 "," \u263A\u2593\xA3\xA3\xA3 "," \u263A\u2593\xA3\xA3\xA3 "," \u263A\u2592\xA3\xA3\xA3 "," \u263A\u2592\xA3\xA3\xA3 "," \u263A\u2591\xA3\xA3\xA3 "," \u263A\u2591\xA3\xA3\xA3 "," \u263A \xA3\xA3\xA3 "," \u263A\xA3\xA3\xA3 "," \u263A\xA3\xA3\xA3 "," \u263A\u2593\xA3\xA3 "," \u263A\u2593\xA3\xA3 "," \u263A\u2592\xA3\xA3 "," \u263A\u2592\xA3\xA3 "," \u263A\u2591\xA3\xA3 "," \u263A\u2591\xA3\xA3 "," \u263A \xA3\xA3 "," \u263A\xA3\xA3 "," \u263A\xA3\xA3 "," \u263A\u2593\xA3 "," \u263A\u2593\xA3 "," \u263A\u2592\xA3 "," \u263A\u2592\xA3 "," \u263A\u2591\xA3 "," \u263A\u2591\xA3 "," \u263A \xA3 "," \u263A\xA3 "," \u263A\xA3 "," \u263A\u2593 "," \u263A\u2593 "," \u263A\u2592 "," \u263A\u2592 "," \u263A\u2591 "," \u263A\u2591 "," \u263A "," \u263A &"," \u263A \u263C&"," \u263A \u263C &"," \u263A\u263C &"," \u263A\u263C & "," \u203C & "," \u263A & "," \u203C & "," \u263A & "," \u203C & "," \u263A & ","\u203C & "," & "," & "," & \u2591 "," & \u2592 "," & \u2593 "," & \xA3 "," & \u2591\xA3 "," & \u2592\xA3 "," & \u2593\xA3 "," & \xA3\xA3 "," & \u2591\xA3\xA3 "," & \u2592\xA3\xA3 ","& \u2593\xA3\xA3 ","& \xA3\xA3\xA3 "," \u2591\xA3\xA3\xA3 "," \u2592\xA3\xA3\xA3 "," \u2593\xA3\xA3\xA3 "," \u2588\xA3\xA3\xA3 "," \u2591\u2588\xA3\xA3\xA3 "," \u2592\u2588\xA3\xA3\xA3 "," \u2593\u2588\xA3\xA3\xA3 "," \u2588\u2588\xA3\xA3\xA3 "," \u2591\u2588\u2588\xA3\xA3\xA3 "," \u2592\u2588\u2588\xA3\xA3\xA3 "," \u2593\u2588\u2588\xA3\xA3\xA3 "," \u2588\u2588\u2588\xA3\xA3\xA3 "," \u2591\u2588\u2588\u2588\xA3\xA3\xA3 "," \u2592\u2588\u2588\u2588\xA3\xA3\xA3 "," \u2593\u2588\u2588\u2588\xA3\xA3\xA3 "," \u2588\u2588\u2588\u2588\xA3\xA3\xA3 "," \u2591\u2588\u2588\u2588\u2588\xA3\xA3\xA3 "," \u2592\u2588\u2588\u2588\u2588\xA3\xA3\xA3 "," \u2593\u2588\u2588\u2588\u2588\xA3\xA3\xA3 "," \u2588\u2588\u2588\u2588\u2588\xA3\xA3\xA3 "," \u2591\u2588\u2588\u2588\u2588\u2588\xA3\xA3\xA3 "," \u2592\u2588\u2588\u2588\u2588\u2588\xA3\xA3\xA3 "," \u2593\u2588\u2588\u2588\u2588\u2588\xA3\xA3\xA3 "," \u2588\u2588\u2588\u2588\u2588\u2588\xA3\xA3\xA3 "," \u2588\u2588\u2588\u2588\u2588\u2588\xA3\xA3\xA3 "]}};var Mh=l1,$1t=Object.keys(l1);var Jl={};or(Jl,{error:()=>mat,info:()=>Sat,success:()=>pat,warning:()=>hat});import fat from"node:tty";var Tat=fat?.WriteStream?.prototype?.hasColors?.()??!1,_t=(t,e)=>{if(!Tat)return i=>i;let n=`\x1B[${t}m`,r=`\x1B[${e}m`;return i=>{let o=i+"",s=o.indexOf(r);if(s===-1)return n+o+r;let a=n,c=0;for(;s!==-1;)a+=o.slice(c,s)+n,c=s+r.length,s=o.indexOf(r,c);return a+=o.slice(c)+r,a}},K1t=_t(0,0),z1t=_t(1,22),Z1t=_t(2,22),X1t=_t(3,23),q1t=_t(4,24),J1t=_t(53,55),Q1t=_t(7,27),eGt=_t(8,28),tGt=_t(9,29),nGt=_t(30,39),nQ=_t(31,39),rQ=_t(32,39),iQ=_t(33,39),oQ=_t(34,39),rGt=_t(35,39),iGt=_t(36,39),oGt=_t(37,39),sGt=_t(90,39),aGt=_t(40,49),cGt=_t(41,49),uGt=_t(42,49),lGt=_t(43,49),_Gt=_t(44,49),EGt=_t(45,49),dGt=_t(46,49),fGt=_t(47,49),TGt=_t(100,49),SGt=_t(91,39),pGt=_t(92,39),hGt=_t(93,39),mGt=_t(94,39),AGt=_t(95,39),gGt=_t(96,39),RGt=_t(97,39),NGt=_t(101,49),OGt=_t(102,49),CGt=_t(103,49),IGt=_t(104,49),MGt=_t(105,49),PGt=_t(106,49),DGt=_t(107,49);import sQ from"node:process";function Ph(){let{env:t}=sQ,{TERM:e,TERM_PROGRAM:n}=t;return sQ.platform!=="win32"?e!=="linux":!!t.WT_SESSION||!!t.TERMINUS_SUBLIME||t.ConEmuTask==="{cmd::Cmder}"||n==="Terminus-Sublime"||n==="vscode"||e==="xterm-256color"||e==="alacritty"||e==="rxvt-unicode"||e==="rxvt-unicode-256color"||t.TERMINAL_EMULATOR==="JetBrains-JediTerm"}var dC=Ph(),Sat=oQ(dC?"\u2139":"i"),pat=rQ(dC?"\u2714":"\u221A"),hat=iQ(dC?"\u26A0":"\u203C"),mat=nQ(dC?"\u2716":"\xD7");function _1({onlyFirst:t=!1}={}){let n=["[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]+)*|[a-zA-Z\\d]+(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?(?:\\u0007|\\u001B\\u005C|\\u009C))","(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-nq-uy=><~]))"].join("|");return new RegExp(n,t?void 0:"g")}var Aat=_1();function E1(t){if(typeof t!="string")throw new TypeError(`Expected a \`string\`, got \`${typeof t}\``);return t.replace(Aat,"")}var pQ=ue(SQ(),1);function T1({stream:t=process.stdout}={}){return!!(t&&t.isTTY&&process.env.TERM!=="dumb"&&!("CI"in process.env))}import Ms from"node:process";var Cat=3,S1=class{#e=0;start(){this.#e++,this.#e===1&&this.#n()}stop(){if(this.#e<=0)throw new Error("`stop` called more times than `start`");this.#e--,this.#e===0&&this.#t()}#n(){Ms.platform==="win32"||!Ms.stdin.isTTY||(Ms.stdin.setRawMode(!0),Ms.stdin.on("data",this.#a),Ms.stdin.resume())}#t(){Ms.stdin.isTTY&&(Ms.stdin.off("data",this.#a),Ms.stdin.pause(),Ms.stdin.setRawMode(!1))}#a(e){e[0]===Cat&&Ms.emit("SIGINT")}},Iat=new S1,p1=Iat;var h1=class{#e=0;#n=!1;#t=0;#a=-1;#d=0;#p=0;#c;#l;#r;#i;#o;#_;#s;#E;#S;#f;#T;color;constructor(e){typeof e=="string"&&(e={text:e}),this.#c={color:"cyan",stream:fC.stderr,discardStdin:!0,hideCursor:!0,...e},this.color=this.#c.color,this.spinner=this.#c.spinner,this.#o=this.#c.interval,this.#r=this.#c.stream,this.#_=typeof this.#c.isEnabled=="boolean"?this.#c.isEnabled:T1({stream:this.#r}),this.#s=typeof this.#c.isSilent=="boolean"?this.#c.isSilent:!1,this.text=this.#c.text,this.prefixText=this.#c.prefixText,this.suffixText=this.#c.suffixText,this.indent=this.#c.indent,fC.env.NODE_ENV==="test"&&(this._stream=this.#r,this._isEnabled=this.#_,Object.defineProperty(this,"_linesToClear",{get(){return this.#e},set(n){this.#e=n}}),Object.defineProperty(this,"_frameIndex",{get(){return this.#a}}),Object.defineProperty(this,"_lineCount",{get(){return this.#t}}))}get indent(){return this.#E}set indent(e=0){if(!(e>=0&&Number.isInteger(e)))throw new Error("The `indent` option must be an integer from 0 and up");this.#E=e,this.#h()}get interval(){return this.#o??this.#l.interval??100}get spinner(){return this.#l}set spinner(e){if(this.#a=-1,this.#o=void 0,typeof e=="object"){if(!Array.isArray(e.frames)||e.frames.length===0||e.frames.some(n=>typeof n!="string"))throw new Error("The given spinner must have a non-empty `frames` array of strings");if(e.interval!==void 0&&!(Number.isInteger(e.interval)&&e.interval>0))throw new Error("`spinner.interval` must be a positive integer if provided");this.#l=e}else if(!Ph())this.#l=Mh.line;else if(e===void 0)this.#l=Mh.dots;else if(e!=="default"&&Mh[e])this.#l=Mh[e];else throw new Error(`There is no built-in spinner named '${e}'. See https://github.com/sindresorhus/cli-spinners/blob/main/spinners.json for a full list.`)}get text(){return this.#S}set text(e=""){this.#S=e,this.#h()}get prefixText(){return this.#f}set prefixText(e=""){this.#f=e,this.#h()}get suffixText(){return this.#T}set suffixText(e=""){this.#T=e,this.#h()}get isSpinning(){return this.#i!==void 0}#C(e,n,r=!1){let i=typeof e=="function"?e():e;return typeof i=="string"&&i!==""?r?n+i:i+n:""}#m(e=this.#f,n=" "){return this.#C(e,n,!1)}#A(e=this.#T,n=" "){return this.#C(e,n,!0)}#O(e,n){let r=0;for(let i of E1(e).split(`
219
219
  `))r+=Math.max(1,Math.ceil((0,pQ.default)(i)/n));return r}#h(){let e=this.#r.columns??80,n=typeof this.#f=="function"?"":this.#f,r=typeof this.#T=="function"?"":this.#T,i=typeof n=="string"&&n!==""?n+" ":"",o=typeof r=="string"&&r!==""?" "+r:"",a=" ".repeat(this.#E)+i+"-"+(typeof this.#S=="string"?" "+this.#S:"")+o;this.#t=this.#O(a,e)}get isEnabled(){return this.#_&&!this.#s}set isEnabled(e){if(typeof e!="boolean")throw new TypeError("The `isEnabled` option must be a boolean");this.#_=e}get isSilent(){return this.#s}set isSilent(e){if(typeof e!="boolean")throw new TypeError("The `isSilent` option must be a boolean");this.#s=e}frame(){let e=Date.now();(this.#a===-1||e-this.#d>=this.interval)&&(this.#a=++this.#a%this.#l.frames.length,this.#d=e);let{frames:n}=this.#l,r=n[this.#a];this.color&&(r=j[this.color](r));let i=this.#m(this.#f," "),o=typeof this.text=="string"?" "+this.text:"",s=this.#A(this.#T," ");return i+r+o+s}clear(){if(!this.#_||!this.#r.isTTY)return this;this.#r.cursorTo(0);for(let e=0;e<this.#e;e++)e>0&&this.#r.moveCursor(0,-1),this.#r.clearLine(1);return(this.#E||this.#p!==this.#E)&&this.#r.cursorTo(this.#E),this.#p=this.#E,this.#e=0,this}render(){if(!this.#_||this.#s)return this;this.clear();let e=this.frame(),n=this.#r.columns??80,r=this.#O(e,n),i=this.#r.rows;if(i&&i>1&&r>i){let o=e.split(`
220
220
  `),s=i-1;e=[...o.slice(0,s),"... (content truncated to fit terminal)"].join(`
@@ -278,7 +278,7 @@ ${Re}`)}else u.push(Z)}let E="";if(o&&(o.mode==="check"?E=o.filePath?` ${j.dim(`
278
278
  `+f),i&&s.size>0&&i.start()}).catch(f=>{console.error("Error formatting rule result:",f),i&&s.size>0&&i.start()}),a.add(u.ruleId)}}c()}),t.on("rules:rule-error",u=>{s.delete(u.ruleId),c()}),t.on("llm:tool-execution",u=>{let l=s.get(u.ruleId);l&&(l.toolInfo={toolName:u.toolName,file:u.file,path:u.path,pattern:u.pattern,offset:u.offset,limit:u.limit},c())}),t.on("llm:search-phase:start",u=>{let l=s.get(u.ruleId);l&&(l.searchPhase={matchCount:u.matchCount},c())}),t.on("llm:validation-phase:start",u=>{let l=s.get(u.ruleId);l&&(l.toolInfo=void 0,l.searchPhase=void 0,l.validationPhase={matchCount:u.matchCount},c())}),t.on("llm:validation-phase:batch",u=>{let l=s.get(u.ruleId);l&&(l.batchInfo={currentBatch:u.currentBatch,totalBatches:u.totalBatches,batchSize:u.batchSize,remainingMatches:u.remainingMatches,totalMatches:u.totalMatches},c())}),t.on("rules:progress",u=>{c()}),t.on("rules:complete",()=>{i&&(i._updateInterval&&clearInterval(i._updateInterval),i.stopAndPersist(),i=null),s.clear()}),()=>{i&&(i._updateInterval&&clearInterval(i._updateInterval),i.stopAndPersist(),i=null),s.clear()}}var hC=class extends _O{provider="claude";dataSchema=P6;eventSchemas=M6;getConversationId(e){return e.session_id}async handleEvent(e,n){switch(e){case"SessionStart":return await this.handleSessionStart(n);case"PostToolUse":return await this.handlePostToolUse(n);case"Stop":return await this.handleStop(n);case"SessionEnd":return await this.handleSessionEnd(n);default:throw new Error(`Unknown Claude event: ${e}`)}}async isSessionValid(e){let n=new Kr({repositoryUrl:void 0,workspaceRoot:e}),r=await mC(),i=await Yo.initialize(n,{apiKey:r||void 0});return"failed"in i?{valid:!1,error:i.error}:{valid:!0}}async handleSessionStart(e){Ae.log(`[ClaudeHookHandler] SessionStart for session ${e.session_id}`);let n=await this.isSessionValid(e.cwd);if(!n.valid){Ae.log(`[ClaudeHookHandler] API key not configured or invalid. Error: ${n.error}. Skipping session initialization.`);return}Ae.log("[ClaudeHookHandler] Config validated successfully");let i=await new Na().initializeSession(e.cwd,"claude",e.session_id);Ae.log(`[ClaudeHookHandler] Initialized wispbit session: ${i}`);let o=process.env.CLAUDE_ENV_FILE;if(o){Ae.log(`[ClaudeHookHandler] Writing session ID to CLAUDE_ENV_FILE: ${o}`);let a=`export WISPBIT_SESSION_ID="${i}"
279
279
  `;await wQ.promises.appendFile(o,a)}return{systemMessage:new Cl({level:3}).dim.italic("wispbit will automatically review all changes in this session")}}async handlePostToolUse(e){Ae.log(`[ClaudeHookHandler] PostToolUse (${e.tool_name}) for file ${e.tool_input.file_path}`);let n=new Na;if(!await n.getSession("claude",e.session_id)){Ae.log("[ClaudeHookHandler] Session not initialized, skipping PostToolUse");return}let i=e.tool_input.file_path,o=AC.isAbsolute(i)?AC.relative(e.cwd,i):i,s,a;e.tool_name==="Write"?(a="",s=e.tool_input.content||""):(a=e.tool_input.old_string||"",s=e.tool_input.new_string||""),await n.addFileChange(o,a,s),Ae.log(`[ClaudeHookHandler] Added change for ${o}`)}async handleStop(e){Ae.log(`[ClaudeHookHandler] Stop for session ${e.session_id}`);let n=new Na,r=await n.getSession("claude",e.session_id);if(!r){Ae.log("[ClaudeHookHandler] Session not initialized, skipping Stop");return}Ae.log(`[ClaudeHookHandler] Wispbit session ID: ${r.wispbitSessionId}`);let i=n.getLastCheckpointTimestamp();if((i?n.getFileChanges(i):n.getFileChanges()).length===0){Ae.log("[ClaudeHookHandler] No file changes since last checkpoint, skipping");return}let s=n.getFileChanges();Ae.log(`[ClaudeHookHandler] Found ${s.length} files changed in session`);for(let P of s)Ae.log(`
280
280
  [ClaudeHookHandler] File: ${P.filename} (${P.status})`),Ae.log(`[ClaudeHookHandler] +${P.additions} -${P.deletions}`),Ae.log(`[ClaudeHookHandler] Diff:
281
- ${P.patch}`);let{results:a,rules:c}=await this.runPowerlint(e.cwd,s),u=a.flatMap(P=>P.matches.map(G=>({...G,ruleId:P.ruleId}))),l=n.getLastCheckpointMatches(),E=new Map;for(let P of u){let G=P.ruleId;E.has(G)||E.set(G,[]),E.get(G).push(P)}let d=new Map;for(let P of l)d.has(P.ruleId)||d.set(P.ruleId,[]),d.get(P.ruleId).push(P);let f=[];for(let[P,G]of E.entries()){let Y=d.get(P)||[],re=G.map(H=>({file:H.file.path,startLine:H.range.start.line,endLine:H.range.end.line,fingerprint:H.fingerprint})),W=Y.map(H=>({file:H.file.path,startLine:H.range.start.line,endLine:H.range.end.line,fingerprint:H.fingerprint})),q=Ah(re,W),Z=G.filter((H,oe)=>!q.has(oe));f.push(...Z)}let T=new Map;for(let P of f){let G=P.ruleId;T.has(G)||T.set(G,[]),T.get(G).push(P)}let p=Array.from(T.entries()).map(([P,G])=>({ruleId:P,matches:G})),S=new Map;for(let P of u){let G=P.ruleId;S.has(G)||S.set(G,[]),S.get(G).push(P)}let m=Array.from(S.entries()).map(([P,G])=>({ruleId:P,matches:G})),O=f.length,h=u.length;Ae.log(`[ClaudeHookHandler] New: ${O}, Total: ${h}`),await n.createCheckpoint(f);let C=await this.buildStopMessage(p,m,c,e.cwd,O,h,s.length);if(Ae.log(`[ClaudeHookHandler] Built system message: ${C?"yes":"no"}`),!!C)return{systemMessage:C}}async handleSessionEnd(e){Ae.log(`[ClaudeHookHandler] SessionEnd (${e.reason}) for session ${e.session_id}`);let n=new Na;if(!await n.getSession("claude",e.session_id)){Ae.log("[ClaudeHookHandler] Session not initialized, skipping SessionEnd");return}await n.endSession()}async runPowerlint(e,n){let r=new Kr({repositoryUrl:void 0,workspaceRoot:e}),i=await mC(),o=await Yo.initialize(r,{apiKey:i||void 0});if("failed"in o)throw new Error(`Failed to initialize config: ${o.error}`);let s=o,a=new zr,c=new $o(s,r),u=await c.loadAllRules(),l=new La(s,r,a),E=await c.getDismissals([]),d=new Map;for(let p of E)d.has(p.ruleId)||d.set(p.ruleId,[]),d.get(p.ruleId).push(p.match);let f=await Pa.initialize(s,r,"session",a,void 0,void 0,{fileChanges:n});return{results:await l.execute(u,f,{dismissedMatchesByRule:d}),rules:u}}async buildStopMessage(e,n,r,i,o,s,a){let c=e.filter(f=>f.matches.length>0),u=n.filter(f=>f.matches.length>0),l=new Cl({level:3}),E;if(s===o)if(o>0)E=l.red("wispbit found ")+l.red.bold(`${o} new`)+l.red(` ${o===1?"issue":"issues"}`);else return null;else o>0?E=l.red("wispbit found ")+l.red.bold(`${o} new`)+l.red(` ${o===1?"issue":"issues"}`)+l.dim(` (${s} total)`):E=l.dim.italic(`wispbit found ${s} total ${s===1?"issue":"issues"} from ${a} ${a===1?"file edit":"file edits"} this session`);let d=[];if(c.length>0){let f=new Set;for(let p of u)for(let S of p.matches)f.add(S.file.path);let T=await vh(c,r,i,l,{maxMatchesPerRule:1,maxDiffLines:10});d.push(T),d.push("",E),d.push(l.dim("Run ")+l.cyan("!wispbit")+l.dim(" to view, ")+l.cyan("!wispbit --fix")+l.dim(" to fix, ")+l.cyan("!wispbit --dismiss")+l.dim(" to dismiss (add ")+l.cyan("RULE-123")+l.dim(" for specific rules)"))}else u.length>0?d.push(E+l.dim.italic(". Run ")+l.cyan("!wispbit")+l.dim.italic(" to view and fix issues.")):d.push(E);return d.join(`
281
+ ${P.patch}`);let{results:a,rules:c}=await this.runPowerlint(e.cwd,s),u=a.flatMap(P=>P.matches.map(G=>({...G,ruleId:P.ruleId}))),l=n.getLastCheckpointMatches(),E=new Map;for(let P of u){let G=P.ruleId;E.has(G)||E.set(G,[]),E.get(G).push(P)}let d=new Map;for(let P of l)d.has(P.ruleId)||d.set(P.ruleId,[]),d.get(P.ruleId).push(P);let f=[];for(let[P,G]of E.entries()){let Y=d.get(P)||[],re=G.map(H=>({file:H.file.path,startLine:H.range.start.line,endLine:H.range.end.line,fingerprint:H.fingerprint})),W=Y.map(H=>({file:H.file.path,startLine:H.range.start.line,endLine:H.range.end.line,fingerprint:H.fingerprint})),q=Ah(re,W),Z=G.filter((H,oe)=>!q.has(oe));f.push(...Z)}let T=new Map;for(let P of f){let G=P.ruleId;T.has(G)||T.set(G,[]),T.get(G).push(P)}let p=Array.from(T.entries()).map(([P,G])=>({ruleId:P,matches:G})),S=new Map;for(let P of u){let G=P.ruleId;S.has(G)||S.set(G,[]),S.get(G).push(P)}let m=Array.from(S.entries()).map(([P,G])=>({ruleId:P,matches:G})),O=f.length,h=u.length;Ae.log(`[ClaudeHookHandler] New: ${O}, Total: ${h}`),await n.createCheckpoint(f);let C=await this.buildStopMessage(p,m,c,e.cwd,O,h,s.length);if(Ae.log(`[ClaudeHookHandler] Built system message: ${C?"yes":"no"}`),!!C)return{systemMessage:C}}async handleSessionEnd(e){Ae.log(`[ClaudeHookHandler] SessionEnd (${e.reason}) for session ${e.session_id}`);let n=new Na;if(!await n.getSession("claude",e.session_id)){Ae.log("[ClaudeHookHandler] Session not initialized, skipping SessionEnd");return}await n.endSession()}async runPowerlint(e,n){let r=new Kr({repositoryUrl:void 0,workspaceRoot:e}),i=await mC(),o=await Yo.initialize(r,{apiKey:i||void 0});if("failed"in o)throw new Error(`Failed to initialize config: ${o.error}`);let s=o,a=new zr,c=new $o(s,r),u=await c.loadAllRules(),l=new La(s,r,a),E=await c.getDismissals([]),d=new Map;for(let p of E)d.has(p.ruleId)||d.set(p.ruleId,[]),d.get(p.ruleId).push(p.match);let f=await Pa.initialize(s,r,"session",a,void 0,void 0,{fileChanges:n});return{results:await l.execute(u,f,{dismissedMatchesByRule:d,emitErrors:!0}),rules:u}}async buildStopMessage(e,n,r,i,o,s,a){let c=e.filter(f=>f.matches.length>0),u=n.filter(f=>f.matches.length>0),l=new Cl({level:3}),E;if(s===o)if(o>0)E=l.red("wispbit found ")+l.red.bold(`${o} new`)+l.red(` ${o===1?"issue":"issues"}`);else return null;else o>0?E=l.red("wispbit found ")+l.red.bold(`${o} new`)+l.red(` ${o===1?"issue":"issues"}`)+l.dim(` (${s} total)`):E=l.dim.italic(`wispbit found ${s} total ${s===1?"issue":"issues"} from ${a} ${a===1?"file edit":"file edits"} this session`);let d=[];if(c.length>0){let f=new Set;for(let p of u)for(let S of p.matches)f.add(S.file.path);let T=await vh(c,r,i,l,{maxMatchesPerRule:1,maxDiffLines:10});d.push(T),d.push("",E),d.push(l.dim("Run ")+l.cyan("!wispbit")+l.dim(" to view, ")+l.cyan("!wispbit --fix")+l.dim(" to fix, ")+l.cyan("!wispbit --dismiss")+l.dim(" to dismiss (add ")+l.cyan("RULE-123")+l.dim(" for specific rules)"))}else u.length>0?d.push(E+l.dim.italic(". Run ")+l.cyan("!wispbit")+l.dim.italic(" to view and fix issues.")):d.push(E);return d.join(`
282
282
  `)}};function xQ(t){switch(t){case"claude":return new hC;default:throw new Error(`Unknown hook provider: ${t}`)}}import*as Wc from"fs/promises";import*as VQ from"os";import*as Uh from"path";var gC=class{getStorageDir(){return Uh.join(VQ.homedir(),".wispbit","hooks")}getStoragePath(e){return Uh.join(this.getStorageDir(),`${e}.json`)}async load(e){let n=this.getStoragePath(e);try{let r=await Wc.readFile(n,"utf-8");return JSON.parse(r)}catch{return null}}async save(e,n){let r=this.getStoragePath(e);await Wc.mkdir(Uh.dirname(r),{recursive:!0}),await Wc.writeFile(r,JSON.stringify(n,null,2))}async clear(e){let n=this.getStoragePath(e);try{await Wc.unlink(n)}catch{}}};async function GQ(t,e){let[n,r]=t.split(".");if(!n||!r)throw new Error(`Invalid providerEvent format: ${t}. Expected "provider.event"`);let i=xQ(n),o=new gC,s=i.eventSchemas[r];if(!s)throw new Error(`Unknown event: ${r} for provider: ${n}`);let a=s.parse(e),c=i.getConversationId(a);i._setContext(o,c);let u=await i.handleEvent(r,a);return i._clearContext(),u??{}}var _r=ue(are(),1);import{promises as _re}from"fs";import{join as u_,relative as Ere}from"path";import{fileURLToPath as Jo,pathToFileURL as tlt}from"url";var WI=class t{constructor(e,n,r,i){this._uri=e,this._languageId=n,this._version=r,this._content=i,this._lineOffsets=void 0}get uri(){return this._uri}get languageId(){return this._languageId}get version(){return this._version}getText(e){if(e){let n=this.offsetAt(e.start),r=this.offsetAt(e.end);return this._content.substring(n,r)}return this._content}update(e,n){for(let r of e)if(t.isIncremental(r)){let i=lre(r.range),o=this.offsetAt(i.start),s=this.offsetAt(i.end);this._content=this._content.substring(0,o)+r.text+this._content.substring(s,this._content.length);let a=Math.max(i.start.line,0),c=Math.max(i.end.line,0),u=this._lineOffsets,l=cre(r.text,!1,o);if(c-a===l.length)for(let d=0,f=l.length;d<f;d++)u[d+a+1]=l[d];else l.length<1e4?u.splice(a+1,c-a,...l):this._lineOffsets=u=u.slice(0,a+1).concat(l,u.slice(c+1));let E=r.text.length-(s-o);if(E!==0)for(let d=a+1+l.length,f=u.length;d<f;d++)u[d]=u[d]+E}else if(t.isFull(r))this._content=r.text,this._lineOffsets=void 0;else throw new Error("Unknown change event received");this._version=n}getLineOffsets(){return this._lineOffsets===void 0&&(this._lineOffsets=cre(this._content,!0)),this._lineOffsets}positionAt(e){e=Math.max(Math.min(e,this._content.length),0);let n=this.getLineOffsets(),r=0,i=n.length;if(i===0)return{line:0,character:e};for(;r<i;){let s=Math.floor((r+i)/2);n[s]>e?i=s:r=s+1}let o=r-1;return e=this.ensureBeforeEOL(e,n[o]),{line:o,character:e-n[o]}}offsetAt(e){let n=this.getLineOffsets();if(e.line>=n.length)return this._content.length;if(e.line<0)return 0;let r=n[e.line];if(e.character<=0)return r;let i=e.line+1<n.length?n[e.line+1]:this._content.length,o=Math.min(r+e.character,i);return this.ensureBeforeEOL(o,r)}ensureBeforeEOL(e,n){for(;e>n&&ure(this._content.charCodeAt(e-1));)e--;return e}get lineCount(){return this.getLineOffsets().length}static isIncremental(e){let n=e;return n!=null&&typeof n.text=="string"&&n.range!==void 0&&(n.rangeLength===void 0||typeof n.rangeLength=="number")}static isFull(e){let n=e;return n!=null&&typeof n.text=="string"&&n.range===void 0&&n.rangeLength===void 0}},rm;(function(t){function e(i,o,s,a){return new WI(i,o,s,a)}t.create=e;function n(i,o,s){if(i instanceof WI)return i.update(o,s),i;throw new Error("TextDocument.update: document must be created by TextDocument.create")}t.update=n;function r(i,o){let s=i.getText(),a=CF(o.map(Xut),(l,E)=>{let d=l.range.start.line-E.range.start.line;return d===0?l.range.start.character-E.range.start.character:d}),c=0,u=[];for(let l of a){let E=i.offsetAt(l.range.start);if(E<c)throw new Error("Overlapping edit");E>c&&u.push(s.substring(c,E)),l.newText.length&&u.push(l.newText),c=i.offsetAt(l.range.end)}return u.push(s.substr(c)),u.join("")}t.applyEdits=r})(rm||(rm={}));function CF(t,e){if(t.length<=1)return t;let n=t.length/2|0,r=t.slice(0,n),i=t.slice(n);CF(r,e),CF(i,e);let o=0,s=0,a=0;for(;o<r.length&&s<i.length;)e(r[o],i[s])<=0?t[a++]=r[o++]:t[a++]=i[s++];for(;o<r.length;)t[a++]=r[o++];for(;s<i.length;)t[a++]=i[s++];return t}function cre(t,e,n=0){let r=e?[n]:[];for(let i=0;i<t.length;i++){let o=t.charCodeAt(i);ure(o)&&(o===13&&i+1<t.length&&t.charCodeAt(i+1)===10&&i++,r.push(n+i+1))}return r}function ure(t){return t===13||t===10}function lre(t){let e=t.start,n=t.end;return e.line>n.line||e.line===n.line&&e.character>n.character?{start:n,end:e}:t}function Xut(t){let e=lre(t.range);return e!==t.range?{newText:t.newText,range:e}:t}function qr(t){let e=decodeURIComponent(t);return e.startsWith("file:///")&&(e=e.replace(/\\/g,"/")),e=e.replace(/^file:\/\/\/([a-z]):/,(n,r)=>`file:///${r.toUpperCase()}:`),e}var KI=class{syncedDocuments=new Map;diagnosticsByFileAndRule=new Map;dismissalsByFile=new Map;fixesByFile=new Map;listen(e,n){e.onDidOpenTextDocument(r=>{let i=r.textDocument,o=qr(i.uri),s=rm.create(o,i.languageId,i.version,i.text);this.syncedDocuments.set(o,s),n.onDidOpen?.(o,s)}),e.onDidChangeTextDocument(r=>{let i=r.textDocument,o=qr(i.uri),s=r.contentChanges;if(s.length===0)return;let a=i.version;if(a==null)return;let c=this.syncedDocuments.get(o);c&&(c=rm.update(c,s,a),this.syncedDocuments.set(o,c),n.onDidChangeContent?.(o,c,s))}),e.onDidCloseTextDocument(r=>{let i=qr(r.textDocument.uri);this.syncedDocuments.delete(i),n.onDidClose?.(i)}),e.onDidSaveTextDocument(r=>{let i=qr(r.textDocument.uri),o=this.syncedDocuments.get(i);o&&n.onDidSave?.(i,o)})}getDocument(e){let n=qr(e);return this.syncedDocuments.get(n)}getAllDocumentUris(){return Array.from(this.syncedDocuments.values()).map(e=>e.uri)}getAllDiagnosticUris(){return Array.from(this.diagnosticsByFileAndRule.keys())}setDiagnosticsForRule(e,n,r){let i=qr(e);this.diagnosticsByFileAndRule.has(i)||this.diagnosticsByFileAndRule.set(i,new Map),this.diagnosticsByFileAndRule.get(i).set(n,r)}getDiagnosticsForRule(e,n){let r=qr(e),i=this.diagnosticsByFileAndRule.get(r);return i?i.get(n)||[]:[]}getDiagnostics(e){let n=qr(e),r=this.diagnosticsByFileAndRule.get(n);if(!r)return[];let i=[];for(let[o,s]of r.entries())i.push(...s);return i}clearDiagnostics(e){let n=qr(e);this.diagnosticsByFileAndRule.delete(n)}setDismissals(e,n){this.dismissalsByFile.set(e,n)}getDismissals(e){return this.dismissalsByFile.get(e)||[]}hasDismissals(e){return this.dismissalsByFile.has(e)}clearDismissals(e){this.dismissalsByFile.delete(e)}setFixes(e,n){this.fixesByFile.set(e,n)}getFixes(e){return this.fixesByFile.get(e)||[]}hasFixes(e){return this.fixesByFile.has(e)}clearFixes(e){this.fixesByFile.delete(e)}};import{sep as elt}from"path";var zI=class{runtimeManager;config;environment;apiClient;previousResults=new Map;constructor(e,n,r){this.runtimeManager=e,this.config=n,this.environment=r,this.apiClient=new Gl({baseUrl:n.getBaseUrl(),apiKey:n.getApiKey()})}clearCache(){this.previousResults.clear()}async execute(e,n,r){let i=this.environment.getWorkspaceRoot(),o=[],s=n?e.filePaths.filter(E=>E===n):e.filePaths,a=await this.runtimeManager.getDuplicates(i,n),c=await a.loadFileContents(i),u=a.clusterBySharedFiles(),l=new Set;for(let E of u){let d=Array.from(E.files),f=new Map,T=!0,p=new Map;for(let h of E.groups)for(let C of h.fragments)p.set(C.file,C.file_sha);for(let h of d){let C=this.previousResults.get(h);if(C&&C.length>0){let P=p.get(h);C.some(Y=>Y.file.sha!==P)?(this.previousResults.delete(h),T=!1):f.set(h,C)}else T=!1}if(T&&f.size===d.length){for(let[h,C]of f.entries())r(h,C,C.length,!1),o.push(...C),l.add(h);continue}let S=[];for(let h of E.groups){let C=await this.createMatchForGroup(h,c,i,a);if(!C)continue;let P=e.filterMatches([C],[]);P.length!==0&&S.push({match:P[0],group:h})}if(S.length===0)continue;let m=await this.processClusterMatches(S,d,i,r,c,a),O=new Map;for(let h of m){let C=h.file.path;O.has(C)||O.set(C,[]),O.get(C).push(h)}for(let[h,C]of O.entries())this.previousResults.set(h,C),r(h,C,C.length,!1),o.push(...C),l.add(h)}for(let E of s)!l.has(E)&&this.previousResults.has(E)&&(r(E,[],0,!1),this.previousResults.delete(E));return o}async createMatchForGroup(e,n,r,i){if(e.fragments.length===0)return null;let s=[...e.fragments].sort((l,E)=>l.start_line-E.start_line)[0],a=await i.extractFragmentSnippet(s,r,n),c=await Promise.all(e.fragments.filter(l=>!(l.file===s.file&&l.start_line===s.start_line)).map(async l=>{let E=await i.extractFragmentSnippet(l,r,n);return{file:{path:l.file,sha:l.file_sha},text:E,range:{start:{line:l.start_line+1,column:l.start_column+1,index:l.start_index},end:{line:l.end_line+1,column:l.end_column+1,index:l.end_index}},language:this.detectLanguage(l.file),description:"Duplicate location"}}));return{file:{path:s.file,sha:s.file_sha},text:a,range:{start:{line:s.start_line+1,column:s.start_column+1,index:s.start_index},end:{line:s.start_line+1,column:9999,index:s.start_index+a.split(`
283
283
  `)[0].length}},language:this.detectLanguage(s.file),fingerprint:e.hash,description:`Duplicate code found in ${e.fragments.length} locations`,evidence:c}}async processClusterMatches(e,n,r,i,o,s){let a=e.map(T=>T.match),c=[];for(let T of n){let p=this.previousResults.get(T);p&&c.push(...p)}let{remappedMatches:u,unmappedMatches:l}=EJ(a,c),E=u.length+l.length;if(u.length>0){let T=new Map;for(let p of u){let S=p.file.path;T.has(S)||T.set(S,[]),T.get(S).push(p)}for(let[p,S]of T.entries())i(p,S,E,!0);Ae.log(`[DuplicateManager] Emitted ${u.length} remapped duplicates, processing ${l.length} through LLM`)}else l.length>0&&Ae.log(`[DuplicateManager] No remapped duplicates, processing ${l.length} through LLM`);if(l.length===0)return u;let d=e.filter(T=>l.some(p=>p.fingerprint===T.match.fingerprint&&p.file.path===T.match.file.path));Ae.log(`[DuplicateManager] Processing ${d.length} duplicates through LLM validation and fix generation`);let f=await this.processMatchesWithLLM(d,r,o,s);return[...u,...f]}async processMatchesWithLLM(e,n,r,i){let o=e.map(T=>T.match),s=this.config.getContext();if(!s)throw new Error("Context is required for duplicate processing. Please ensure the configuration is initialized with repository information.");Ae.log(`[DuplicateManager] Querying validation cache for ${o.length} duplicates`);let a=await this.apiClient.queryLlmCache({matches:o,type:"duplicate_validate",repository_id:s.repository_id});if("error"in a)return Ae.log(`[DuplicateManager] ERROR: Cache query failed: ${a.error}`),await this.processMatchesWithoutCache(e,n,s,r,i);let c=new Map,u=[];for(let T of a.results){let p=`${T.match.fingerprint}:${T.match.file.path}`;if(T.hit&&T.data)c.set(p,T.data[0]);else{let S=o.find(m=>m.fingerprint===T.match.fingerprint&&m.file.path===T.match.file.path);S&&u.push(S)}}Ae.log(`[DuplicateManager] Validation cache: ${c.size} hits, ${u.length} misses`);let l=[];for(let T of o){let p=`${T.fingerprint}:${T.file.path}`,S=c.get(p);S&&(S.isValid?(l.push(T),Ae.log(`[DuplicateManager] Cached validation for ${T.file.path}:${T.range.start.line}: VALID - ${S.reason}`)):Ae.log(`[DuplicateManager] Cached validation for ${T.file.path}:${T.range.start.line}: INVALID - ${S.reason}`))}for(let T=0;T<u.length;T++){let p=u[T];Ae.log(`[DuplicateManager] [${T+1}/${u.length}] Validating duplicate in ${p.file.path}:${p.range.start.line}`);let S=e.find(h=>h.match.fingerprint===p.fingerprint&&h.match.file.path===p.file.path);if(!S){Ae.log(`[DuplicateManager] ERROR: Could not find group for match ${p.file.path}`);continue}let m=this.extractContextForMatch(S.group,i,r),O=await this.apiClient.validateDuplicates({matches:[p],language:p.language,repository_id:s.repository_id,context:m});if("error"in O){let h=p.text?.substring(0,80).replace(/\n/g," ")||"";Ae.log(`[DuplicateManager] ERROR: Validation failed for ${p.file.path}:${p.range.start.line} "${h}...": ${O.error}`);continue}Ae.log(`[DuplicateManager] [${T+1}/${u.length}] Validation result: ${O.isValid?"VALID":"INVALID"} - ${O.reason}`),O.isValid&&l.push(p)}if(l.length===0)return[];Ae.log(`[DuplicateManager] Querying fix generation cache for ${l.length} duplicates`);let E=await this.apiClient.queryLlmCache({matches:l,type:"duplicate_generate",repository_id:s.repository_id});if("error"in E)return Ae.log(`[DuplicateManager] ERROR: Fix cache query failed: ${E.error}`),await this.generateFixesForMatches(l,n,new Map);let d=new Map,f=[];for(let T of E.results){let p=`${T.match.fingerprint}:${T.match.file.path}`;if(T.hit&&T.data)d.set(p,T.data);else{let S=l.find(m=>m.fingerprint===T.match.fingerprint&&m.file.path===T.match.file.path);S&&f.push(S)}}return Ae.log(`[DuplicateManager] Fix generation cache: ${d.size} hits, ${f.length} misses`),await this.generateFixesForMatches(l,n,d)}async generateFixesForMatches(e,n,r){let i=[];for(let o=0;o<e.length;o++){let s=e[o],a=`${s.fingerprint}:${s.file.path}`,c=r.get(a);if(c){Ae.log(`[DuplicateManager] [${o+1}/${e.length}] Using cached fix for ${s.file.path}:${s.range.start.line}`);let u=await this.replayCachedConversation(c,[s],n);if(u){let l={...s,edits:u.edits,description:u.description};i.push(l),Ae.log(`[DuplicateManager] [${o+1}/${e.length}] Cached fix applied: ${u.description}`)}}else{Ae.log(`[DuplicateManager] [${o+1}/${e.length}] Generating fix for ${s.file.path}:${s.range.start.line}`);let u=await this.generateFixesWithToolLoop([s],n);if(u){let l={...s,edits:u.edits,description:u.description};i.push(l),Ae.log(`[DuplicateManager] [${o+1}/${e.length}] Fix generated successfully: ${u.description}`)}else{let l=s.text?.substring(0,80).replace(/\n/g," ")||"";Ae.log(`[DuplicateManager] ERROR: Fix generation failed for ${s.file.path}:${s.range.start.line} "${l}..."`)}}}return i}async processMatchesWithoutCache(e,n,r,i,o){let s=e.map(c=>c.match),a=[];Ae.log(`[DuplicateManager] Processing ${s.length} duplicates without cache`);for(let c=0;c<e.length;c++){let{match:u,group:l}=e[c],E=this.extractContextForMatch(l,o,i),d=await this.apiClient.validateDuplicates({matches:[u],language:u.language,repository_id:r.repository_id,context:E});"error"in d||d.isValid&&a.push(u)}return await this.generateFixesForMatches(a,n,new Map)}async replayCachedConversation(e,n,r){let i=[];return Ae.log(`[DuplicateManager] Resuming from cached conversation with ${e.length} messages`),await this.continueFixGenerationWithLLM(n,r,e,i)}async continueFixGenerationWithLLM(e,n,r,i){let s=this.config.getContext();if(!s)throw new Error("Context is required for fix generation");for(let a=0;a<20;a++){let c=await this.executeToolCalls(r,n,e[0].file.path,i);if(c.length>0){let f=this.extractReportFixResult(c);if(f)return f;r.push(...c)}Ae.log(`[DuplicateManager] LLM call (resume) - Input: ${r.length} previous messages, Match: ${e[0].file.path}:${e[0].range.start.line}`);let u=await this.apiClient.generateDuplicateFixes({matches:e,language:e[0].language,messages:r,repository_id:s.repository_id,visited_files:i});if("error"in u){let f=e[0]?.text?.substring(0,80).replace(/\n/g," ")||"unknown";Ae.log(`[DuplicateManager] ERROR: generateDuplicateFixes API call failed (resume) for ${e[0]?.file?.path}:${e[0]?.range?.start?.line} "${f}...": ${u.error}`);let T=r.slice(-3);return Ae.log(`[DuplicateManager] Last ${T.length} messages before failure:
284
284
  ${JSON.stringify(T,null,2)}`),null}let l=u.messages,E=await this.executeToolCalls(l,n,e[0].file.path,i);r.push(...l);let d=this.checkForSuccessfulReportFix(l);if(d)return d;if(E.length>0){let f=this.extractReportFixResult(E);if(f)return f;r.push(...E)}}return Ae.log("[DuplicateManager] Max iterations (20) reached without valid fix"),null}extractReportFixFromMessages(e){for(let n of e)if(n.role==="tool"&&n.content){for(let r of n.content)if(r.toolName==="report_fix"){let i=JSON.parse(r.output.value);if(i.success&&i.result)return i.result}}return null}extractReportFixResult(e){return this.extractReportFixFromMessages(e)}async generateFixesWithToolLoop(e,n){let r=[],o=this.config.getContext(),s=[];if(!o)throw new Error("Context is required for fix generation. Please ensure the configuration is initialized with repository information.");for(let a=0;a<20;a++){Ae.log(`[DuplicateManager] LLM call - Input: ${r.length} previous messages, Match: ${e[0].file.path}:${e[0].range.start.line}`);let c=await this.apiClient.generateDuplicateFixes({matches:e,language:e[0].language,messages:r,repository_id:o.repository_id,visited_files:s});if("error"in c){let f=e[0]?.text?.substring(0,80).replace(/\n/g," ")||"unknown";Ae.log(`[DuplicateManager] ERROR: generateDuplicateFixes API call failed for ${e[0]?.file?.path}:${e[0]?.range?.start?.line} "${f}...": ${c.error}`);let T=r.slice(-3);return Ae.log(`[DuplicateManager] Last ${T.length} messages before failure:
@@ -291,7 +291,7 @@ ${e}`);let r={id:String(++this.requestId),command:"shutdown"};this.serverProcess
291
291
  ${u}`:r.message;c(new Error(l))}else a(r);else if(i)if(i==="success")a(o);else{let u=this.getRecentStderr(),l=u?`${s||"Request failed"}. Runtime logs:
292
292
  ${u}`:s||"Request failed";c(new Error(l))}else Ae.log("[Runtime] Unknown response format"),c(new Error("Unknown response format"))}getRuntimePath(){let e=globalThis.__POWERLINT_ASSETS__;if(!e?.runtime)throw new Error("Runtime binary not found. This should be set by the Bun executable build. Make sure you're running the compiled Bun executable, not the source code directly.");return Ae.log(`[RuntimeProvider] Using runtime from Bun executable: ${e.runtime}`),e.runtime}};import{homedir as Jut}from"os";import{join as Qut}from"path";import{promises as IF}from"fs";import*as XI from"path";var im=class{groups;constructor(e){this.groups=e}patternCount(){return this.groups.length}patternCost(){return this.groups.reduce((e,n)=>e+n.cost*n.fragments.length,0)}patternDensity(){let e=this.patternCount();return e>0?this.patternCost()/e:0}fragmentOccurrences(e){let n=this.groups.find(r=>r.hash===e);return n?n.fragments.length:0}patternHash(e){return this.groups[e]?.hash}fileCount(){let e=new Set;for(let n of this.groups)for(let r of n.fragments)e.add(r.file);return e.size}title(e){let n=this.groups.find(o=>o.hash===e);if(!n||n.fragments.length===0)return"Unknown pattern";let r=n.fragments[0];return`${r.file.split("/").pop()||r.file}:${r.start_line+1}-${r.end_line+1} (${n.fragments.length} occurrences)`}fragmentsByFile(e){let n=new Map,r=this.groups.find(i=>i.hash===e);if(!r)return n;for(let i of r.fragments){let o=n.get(i.file)||[];o.push(i),n.set(i.file,o)}return n}getGroups(){return this.groups}async getFragmentText(e,n){let r=XI.join(n,e.file),i=await IF.readFile(r,"utf-8");return Buffer.from(i,"utf-8").slice(e.start_index,e.end_index).toString("utf-8")}getFragmentsInFile(e){let n=[];for(let r of this.groups)for(let i of r.fragments)i.file===e&&n.push(i);return n}getStatistics(){let e=this.groups.reduce((n,r)=>n+r.fragments.length,0);return{patternCount:this.patternCount(),totalCost:this.patternCost(),averageCost:this.patternDensity(),fileCount:this.fileCount(),totalFragments:e}}async extractFragmentSnippet(e,n,r){let i;if(r.has(e.file))i=r.get(e.file);else{let s=XI.join(n,e.file);i=await IF.readFile(s,"utf-8"),r.set(e.file,i)}return Buffer.from(i,"utf-8").slice(e.start_index,e.end_index).toString("utf-8")}async loadFileContents(e){let n=new Map,r=new Set;for(let i of this.groups)for(let o of i.fragments)r.add(o.file);return await Promise.all(Array.from(r).map(async i=>{let o=XI.join(e,i),s=await IF.readFile(o,"utf-8");n.set(i,s)})),n}extractFragmentContext(e,n,r=20){let i=n.get(e.file);if(!i)throw new Error(`File content not available for ${e.file}`);let o=i.split(`
293
293
  `),s=e.start_line,a=Math.max(0,s-r),c=Math.min(o.length-1,s+r),u=o.slice(a,c+1).join(`
294
- `);return{file:e.file,range:{start:{line:a+1,column:1},end:{line:c+1,column:o[c]?.length||1}},text:u}}extractGroupContext(e,n,r=20){return e.fragments.map(i=>this.extractFragmentContext(i,n,r))}clusterBySharedFiles(){if(this.groups.length===0)return[];let e=new Map;this.groups.forEach((o,s)=>{let a=new Set;for(let c of o.fragments)a.add(c.file);for(let c of a)e.has(c)||e.set(c,[]),e.get(c).push(s)});let n=new MF(this.groups.length);for(let o of e.values())for(let s=1;s<o.length;s++)n.union(o[0],o[s]);let r=new Map;for(let o=0;o<this.groups.length;o++){let s=n.find(o);r.has(s)||r.set(s,[]),r.get(s).push(o)}let i=[];for(let o of r.values()){let s=o.map(c=>this.groups[c]),a=new Set;for(let c of s)for(let u of c.fragments)a.add(u.file);i.push({groups:s,files:a})}return i}},MF=class{parent=new Map;rank=new Map;constructor(e){for(let n=0;n<e;n++)this.parent.set(n,n),this.rank.set(n,0)}find(e){return this.parent.get(e)!==e&&this.parent.set(e,this.find(this.parent.get(e))),this.parent.get(e)}union(e,n){let r=this.find(e),i=this.find(n);if(r===i)return;let o=this.rank.get(r),s=this.rank.get(i);o<s?this.parent.set(r,i):o>s?this.parent.set(i,r):(this.parent.set(i,r),this.rank.set(r,o+1))}};var qI=class t{static INDEX_FOLDER=Qut(Jut(),".wispbit","indexes");provider;initialized=!1;constructor(e){this.provider=e}async initializeProvider(){this.initialized||(await this.provider.initialize(),this.initialized=!0)}async initialize(e){await this.initializeProvider();let n=await this.provider.sendRequest({command:"initialize_workspaces",workspace_configs:e.workspaceConfigs.map(r=>({workspace_root:r.workspaceRoot,base_commit_sha:r.baseCommitSha})),index_folder:t.INDEX_FOLDER,ignores:e.ignores});if("error"in n&&n.error)throw new Error(`Failed to initialize workspaces: ${n.error}`);return{fullScan:n.full_scan||!1}}async getDuplicates(e,n){await this.initializeProvider();let r=await this.provider.sendRequest({command:"get_duplicates",workspace_root:e,file_path:n});if("error"in r&&r.error)throw new Error(`Failed to get duplicates: ${r.error}`);let i=r;return new im(i)}async getDuplicatesForFile(e,n){await this.initializeProvider();let r=await this.provider.sendRequest({command:"get_duplicates",workspace_root:e,file_path:n});if("error"in r&&r.error)throw new Error(`Failed to get duplicates for file: ${r.error}`);let i=r;return new im(i)}invalidationQueue=Promise.resolve();async invalidateFiles(e,n){let r=this.invalidationQueue.then(async()=>{await this.initializeProvider();let i=Date.now(),o=await this.provider.sendRequest({command:"invalidate_files",workspace_root:e,files:n.map(a=>({file_path:a.filePath,content_sha:a.contentSha}))}),s=Date.now()-i;if(Ae.log(`[RuntimeManager] Invalidated ${n.length} file(s) in ${s}ms for ${e}`),"error"in o&&o.error)throw new Error(`Failed to invalidate files: ${o.error}`)}).catch(i=>{throw Ae.log(`[RuntimeManager] Invalidation failed: ${i.message}`),i});this.invalidationQueue=r.catch(()=>{}),await r}isInitialized(){return this.initialized}async shutdown(){this.initialized&&(Ae.log("[RuntimeManager] Shutdown requested, waiting for in-flight operations..."),await this.invalidationQueue.catch(()=>{}),Ae.log("[RuntimeManager] All operations complete, shutting down runtime..."),await this.provider.shutdown(),this.initialized=!1)}};var JI=class{contexts=new Map;workspacePath;apiKey;lspClient;sharedRuntimeManager=null;RULES_CACHE_TTL_MS=300*1e3;constructor(e){this.workspacePath=e.workspacePath,this.apiKey=e.apiKey,this.lspClient=e.lspClient}async discoverAndInitialize(e,n){let r=await tO(this.workspacePath),i=[];for(let s of r){let a=await this.initializeContext(s).catch(c=>(n?.(s,c),null));if(a){let{baseCommitSha:c}=await ga(s);i.push({repoRoot:s,context:a,baseCommitSha:c}),this.contexts.set(s,a),e?.(s,a)}}let o=[];for(let{repoRoot:s,context:a,baseCommitSha:c}of i)a.config.getEnableDeduplicator()&&o.push({workspaceRoot:s,baseCommitSha:c});if(o.length>0){let s=new ZI(o[0].workspaceRoot);this.sharedRuntimeManager=new qI(s);for(let{context:a}of i)a.config.getEnableDeduplicator()&&(a.runtimeManager=this.sharedRuntimeManager,a.duplicateManager=new zI(this.sharedRuntimeManager,a.config,a.environment))}}async initializeContext(e){let n=new Kr({workspaceRoot:e}),r=await Yo.initialize(n,{apiKey:this.apiKey,lspClient:this.lspClient});if("failed"in r)throw new Error(`Config initialization failed for ${e}: ${r.error}`);let i=r,o=new $o(i,n),s=new zr,a=new La(i,n,s);return{repoRoot:e,environment:n,config:i,ruleProvider:o,eventEmitter:s,ruleExecutor:a,cachedRules:null,rulesById:new Map,rulesCacheTimestamp:0,rulesLoadingPromise:null,lastCommitSelector:null,currentExecutionRules:[],completedRulesCount:0,isExecuting:!1,currentExecutionPromise:null,runtimeManager:null,duplicateManager:null,executionContext:null}}findContextForFile(e){let n=e.toLowerCase();return Array.from(this.contexts.entries()).filter(([i])=>{let o=i.toLowerCase();return n.startsWith(o+elt)||n===o}).sort((i,o)=>o[0].length-i[0].length)[0]?.[1]||null}getAllContexts(){return Array.from(this.contexts.values())}getRepoCount(){return this.contexts.size}hasRepositories(){return this.contexts.size>0}getContext(e){return this.contexts.get(e)}async initializeRuntimeManager(){if(!this.sharedRuntimeManager)return!1;let e=[],n=[];for(let r of this.contexts.values())if(r.config.getEnableDeduplicator()){let{baseCommitSha:i}=await ga(r.repoRoot);e.push({workspaceRoot:r.repoRoot,baseCommitSha:i}),n.length===0&&(n=r.config.getIgnoredGlobs())}return e.length===0?!1:(await this.sharedRuntimeManager.initialize({workspaceConfigs:e,ignores:n}),!0)}async shutdown(){for(let e of this.contexts.values())e.ruleExecutor.clearCache(),e.duplicateManager&&e.duplicateManager.clearCache();this.sharedRuntimeManager&&(await this.sharedRuntimeManager.shutdown(),this.sharedRuntimeManager=null),this.contexts.clear()}};function dre(t,e,n){if(t.fingerprint)return`${e}:${t.fingerprint}`;let r=t.text?.slice(0,100)||"",i=`${t.range.start.line}:${t.range.start.column}-${t.range.end.line}:${t.range.end.column}`;return`${e}:${n}:${i}:${nlt(r)}`}function nlt(t){let e=0;for(let n=0;n<t.length;n++){let r=t.charCodeAt(n);e=(e<<5)-e+r,e=e&e}return e.toString(36)}function fre(t){return t.end.line-t.start.line+1>20?{start:{line:t.start.line-1,character:t.start.column-1},end:{line:t.start.line-1,character:Number.MAX_SAFE_INTEGER}}:{start:{line:t.start.line-1,character:t.start.column-1},end:{line:t.end.line-1,character:t.end.column-1}}}var PF=class{connection;documentManager;repositoryContextManager;workspacePath;apiKey;lspClient;batchProgressReporter=null;batchProgressToken="wispbit-batch-lint";progressTokenCreated=!1;fixQueue=[];isProcessingFix=!1;branchCheckTimer=null;BRANCH_CHECK_DEBOUNCE_MS=1e3;branchCheckInterval=null;BRANCH_CHECK_INTERVAL_MS=3e4;executionDebounceTimer=null;EXECUTION_DEBOUNCE_MS=1e3;changedFiles=new Set;hasRunInitialCheck=!1;isExecutingInitial=!1;dismissalsLoadingPromises=new Map;fixesLoadingPromises=new Map;localDismissals=[];constructor(e){this.workspacePath=e.workspacePath,this.apiKey=e.apiKey,this.lspClient=e.lspClient,this.connection=(0,_r.createConnection)(_r.ProposedFeatures.all,process.stdin,process.stdout),this.documentManager=new KI,this.repositoryContextManager=new JI({workspacePath:this.workspacePath,apiKey:this.apiKey,lspClient:this.lspClient}),this.registerHandlers()}addLocalDismissal(e){this.localDismissals.push(e)}isLocallyDismissed(e,n,r,i,o){return this.localDismissals.some(s=>s.matchId===o&&s.uri===e?!0:s.uri===e&&s.ruleId===n?s.startLine<=i&&s.endLine>=r:!1)}clearLocalDismissalsForUri(e){this.localDismissals=this.localDismissals.filter(n=>n.uri!==e)}clearAllLocalDismissals(){this.localDismissals=[]}findContextForFile(e){let n=Jo(e);return this.repositoryContextManager.findContextForFile(n)}pathToNormalizedUri(e){let n=tlt(e).toString();return decodeURIComponent(n)}getDiagnosticsForUri(e){let n=this.documentManager.getDiagnostics(e);if(n.length===0){let r=qr(e),i=this.documentManager.getAllDiagnosticUris();for(let o of i)if(qr(o)===r){n=this.documentManager.getDiagnostics(o);break}}return n}handleRuleComplete(e,n,r){if(!e.isExecuting||e.currentExecutionRules.length===0)return;e.completedRulesCount++;let i=Math.round(e.completedRulesCount/e.currentExecutionRules.length*100);this.updateBatchProgress(i,n)}async handleRuleFileComplete(e,n,r,i){if(!e.isExecuting||e.currentExecutionRules.length===0)return;let o=e.currentExecutionRules.find(u=>u.id===n);if(!o){this.connection.console.log(`[${e.repoRoot}] Warning: Rule ${n} not found in current execution`);return}let s=u_(e.repoRoot,r),a=this.pathToNormalizedUri(s);if(i.length===0){this.updateDiagnosticsForRule(a,o.internalId,[]);return}let c=await this.createDiagnosticsForFile(e,r,o.internalId,i,e.currentExecutionRules);this.updateDiagnosticsForRule(a,o.internalId,c)}async handleRuleFilePartial(e,n,r,i,o){if(!e.isExecuting||e.currentExecutionRules.length===0)return;let s=e.currentExecutionRules.find(l=>l.internalId===n);if(!s){this.connection.console.log(`[${e.repoRoot}] Warning: Rule ${n} not found in current execution`);return}let a=u_(e.repoRoot,r),c=this.pathToNormalizedUri(a);if(i.length===0){this.updateDiagnosticsForRule(c,s.internalId,[]);return}let u=await this.createDiagnosticsForFile(e,r,s.internalId,i,e.currentExecutionRules);this.updateDiagnosticsForRule(c,s.internalId,u)}async convertDuplicateResultsToDiagnostics(e,n,r,i){let o=[];for(let s of n)for(let a of s.matches){let c=dre(a,"DUPLICATE",i);if(this.isLocallyDismissed(i,"DUPLICATE",a.range.start.line,a.range.end.line,c))continue;let u=fre(a.range),l=a.evidence?.map(f=>{let T=u_(e.repoRoot,f.file.path);return{location:{uri:this.pathToNormalizedUri(T),range:{start:{line:f.range.start.line-1,character:f.range.start.column-1},end:{line:f.range.end.line-1,character:f.range.end.column-1}}},message:"Duplicate location"}}),E=null;a.edits&&a.edits.length>0&&(E=await this.computeFixForMatch(a,e).catch(f=>(this.connection.console.log(`Warning: Failed to compute fix for duplicate: ${f}`),null)));let d={range:u,severity:_r.DiagnosticSeverity.Warning,message:a.description||"Duplicate code detected",code:"DUPLICATE",source:"wispbit",relatedInformation:l,data:{uri:i,match:a,matchId:c,fix:E?{diff:E.diff,diffs:E.diffs,autofix:!1}:null,ruleId:"DUPLICATE",filePath:a.file.path,rule:{id:"DUPLICATE",displayId:"DUPLICATE",summary:null}}};o.push(d)}return o}async handleDuplicateFileComplete(e,n,r,i,o){let s=u_(e.repoRoot,n),a=this.pathToNormalizedUri(s),c=await this.createDiagnosticsForFile(e,n,"DUPLICATE",r,[],this.convertDuplicateResultsToDiagnostics.bind(this));this.updateDiagnosticsForRule(a,"DUPLICATE",c)}setupProgressListenersForContext(e){e.eventEmitter.on("rules:progress",n=>{this.updateBatchProgress(n.percentage,n.ruleId)}),e.eventEmitter.on("rules:rule-complete",n=>{this.handleRuleComplete(e,n.ruleId,n.matches)}),e.eventEmitter.on("rules:rule-file-complete",async n=>{await this.handleRuleFileComplete(e,n.ruleId,n.filePath,n.matches)}),e.eventEmitter.on("rules:rule-file-partial",async n=>{await this.handleRuleFilePartial(e,n.ruleId,n.filePath,n.matches,n.totalMatches)})}toRelativePath(e,n){if(!n){let r=this.pathToNormalizedUri(e);n=this.findContextForFile(r)||void 0}return n?Ere(n.repoRoot,e):Ere(this.workspacePath,e)}updateDiagnosticsForRule(e,n,r){this.documentManager.setDiagnosticsForRule(e,n,r);let i=this.documentManager.getDiagnostics(e);this.connection.sendDiagnostics({uri:e,diagnostics:i})}removeDiagnosticByMatchId(e,n){let r=this.documentManager.getDiagnostics(e),i=r.find(a=>a.data?.matchId===n);if(!i)return;let o=i.data?.rule?.id;if(!o)return;let s=r.filter(a=>a.data?.rule?.id===o&&a.data?.matchId!==n);this.updateDiagnosticsForRule(e,o,s)}clearAllDiagnostics(){let e=this.documentManager.getAllDiagnosticUris();for(let n of e)this.clearDiagnosticsForFile(n);this.clearAllLocalDismissals()}clearDiagnosticsForFile(e){this.documentManager.clearDiagnostics(e),this.clearLocalDismissalsForUri(e),this.connection.sendDiagnostics({uri:e,diagnostics:[]})}handleDocumentChangesWithRanges(e,n){let r=this.documentManager.getDiagnostics(e);if(r.length===0)return;this.connection.console.log(`Document changed: ${e}, ${n.length} change(s), ${r.length} diagnostic(s)`);let i=new Set;for(let o of n){if(!o.range){this.connection.console.log("Full document change detected - removing all diagnostics");for(let s of r)s.data?.matchId&&i.add(s.data.matchId);continue}for(let s of r)this.rangesOverlap(o.range,s.range)&&s.data?.matchId&&i.add(s.data.matchId)}for(let o of i)this.removeDiagnosticByMatchId(e,o);i.size>0&&this.connection.console.log(`Removed ${i.size} diagnostic(s) due to document edits`)}rangesOverlap(e,n){return e.end.line<n.start.line||e.start.line>n.end.line?!1:e.start.line<=n.end.line&&e.end.line>=n.start.line}async createDiagnosticsForFile(e,n,r,i,o,s){let a=i.length;this.documentManager.hasDismissals(n)||await this.loadDismissalsForFile(e,n),this.documentManager.hasFixes(n)||await this.loadFixesForFile(e,n);let c={ruleId:r,matches:i},u=this.filterDismissedResults([c],n),l=u[0]?.matches.length||0,E=a-l,d=await this.filterFixedResults(e,u,n),f=d[0]?.matches.length||0,T=l-f,p=u_(e.repoRoot,n),S=this.pathToNormalizedUri(p),m=await(s||this.convertResultsToDiagnostics.bind(this))(e,d,o,S);if(a>0){let h=o.find(P=>P.internalId===r)?.id||r,C=[];E>0&&C.push(`${E} dismissed`),T>0&&C.push(`${T} fixed`),C.length>0?this.connection.console.log(`[${e.repoRoot}] ${n}: ${m.length} diagnostic(s) created, ${C.join(", ")} (rule: ${h})`):this.connection.console.log(`[${e.repoRoot}] ${n}: ${m.length} diagnostic(s) created (rule: ${h})`)}return m}async getFileContent(e){let n=this.pathToNormalizedUri(e),r=this.documentManager.getDocument(n);return r?r.getText():await _re.readFile(e,"utf-8").catch(()=>null)}async computeFixForMatch(e,n){if(!e.edits||e.edits.length===0)return null;let r=await jc(e.edits,e.file.path,n.repoRoot,o=>this.getFileContent(o));return r?{fileChanges:r.fileChanges.map(o=>({...o,fileUri:this.pathToNormalizedUri(o.filePath)})),diff:r.diff,diffs:r.diffs}:null}async loadRulesWithCache(e){let r=Date.now()-e.rulesCacheTimestamp;return e.cachedRules&&r<this.repositoryContextManager.RULES_CACHE_TTL_MS?(this.connection.console.log(`[${e.repoRoot}] Using cached rules (age: ${Math.round(r/1e3)}s / ${this.repositoryContextManager.RULES_CACHE_TTL_MS/1e3}s)`),e.cachedRules):e.rulesLoadingPromise?(this.connection.console.log(`[${e.repoRoot}] Rules are already being loaded, waiting for existing request...`),e.rulesLoadingPromise):(this.connection.console.log(`[${e.repoRoot}] Loading fresh rules from API...`),e.rulesLoadingPromise=e.ruleProvider.loadAllRules().then(i=>{let o=i.filter(s=>s.execution==="llm");e.cachedRules=o,e.rulesCacheTimestamp=Date.now(),e.rulesById.clear();for(let s of o)e.rulesById.set(s.id,s);if(this.connection.console.log(`[${e.repoRoot}] Loaded ${o.length} rules (cache valid for ${this.repositoryContextManager.RULES_CACHE_TTL_MS/1e3}s)`),o.length>0){this.connection.console.log(`[${e.repoRoot}] Fetched rules:`);for(let s of o){let a=s.autofix||!1,c="";a&&(c=" (autofix)"),this.connection.console.log(`[${e.repoRoot}] - ${s.id}: ${s.message}${c}`)}}return o}).finally(()=>{e.rulesLoadingPromise=null}),await e.rulesLoadingPromise)}async loadDismissalsForFile(e,n){if(this.documentManager.hasDismissals(n))return;let r=this.dismissalsLoadingPromises.get(n);if(r)return await r;let i=(async()=>{let s=(await e.ruleProvider.getDismissals([n])).map(a=>({ruleId:a.ruleId,file:a.match.file.path,startLine:a.match.range.start.line,endLine:a.match.range.end.line,fingerprint:a.match.fingerprint,dismissedAt:a.createdAt,dismissalId:a.dismissalId}));this.documentManager.setDismissals(n,s)})().finally(()=>{this.dismissalsLoadingPromises.delete(n)});return this.dismissalsLoadingPromises.set(n,i),await i}async loadFixesForFile(e,n){if(this.documentManager.hasFixes(n))return;let r=this.fixesLoadingPromises.get(n);if(r)return await r;let i=(async()=>{let o=await e.ruleProvider.getFixes([n]);this.documentManager.setFixes(n,o)})().finally(()=>{this.fixesLoadingPromises.delete(n)});return this.fixesLoadingPromises.set(n,i),await i}filterDismissedResults(e,n){let r=this.documentManager.getDismissals(n);return r.length===0?e:e.map(i=>{let o=r.filter(u=>u.ruleId===i.ruleId);if(o.length===0)return i;let s=i.matches.map(u=>({file:n,startLine:u.range.start.line,endLine:u.range.end.line,fingerprint:u.fingerprint})),c=gh(s,o).map(u=>i.matches.find(l=>l.range.start.line===u.startLine&&l.range.end.line===u.endLine&&l.fingerprint===u.fingerprint));return{...i,matches:c}})}async filterFixedResults(e,n,r){let i=this.documentManager.getFixes(r);if(i.length===0)return n;this.connection.console.log(`[${e.repoRoot}] Filtering fixes for ${r}: ${i.length} fix(es) loaded`);let o=u_(e.repoRoot,r),s=await this.getFileContent(o);return s===null?n:n.map(a=>{let c=i.filter(S=>S.ruleId===a.ruleId);if(c.length===0)return a;let u=new Set;for(let S of c)S.match?.edits?.some(O=>O.oldString&&m1(s,O.oldString))&&S.match.fingerprint&&u.add(S.match.fingerprint);let l=c.length-u.size;u.size>0&&this.connection.console.log(`[${e.repoRoot}] ${r}: ${u.size} fix(es) reverted, ${l} still active`);let E=a.matches.map(S=>({file:r,startLine:S.range.start.line,endLine:S.range.end.line,fingerprint:S.fingerprint})),d=c.filter(S=>!S.match.fingerprint||!u.has(S.match.fingerprint)).map(S=>({file:r,startLine:S.match.range.start.line,endLine:S.match.range.end.line,fingerprint:S.match.fingerprint})),T=gh(E,d).map(S=>a.matches.find(m=>m.range.start.line===S.startLine&&m.range.end.line===S.endLine&&m.fingerprint===S.fingerprint)),p=a.matches.length-T.length;return p>0&&this.connection.console.log(`[${e.repoRoot}] ${r}: Filtered out ${p} match(es) with active fixes`),{...a,matches:T}})}async convertResultsToDiagnostics(e,n,r,i){let o=[],s=new Set;for(let a of n){let c=r.find(u=>u.internalId===a.ruleId);if(!c){this.connection.console.log(`Warning: Could not find rule with internal ID ${a.ruleId}`);continue}for(let u of a.matches){let l=`${u.range.start.line}-${u.range.end.line}`;if(s.has(l))continue;s.add(l);let E=dre(u,c.internalId,i);if(this.isLocallyDismissed(i,c.internalId,u.range.start.line,u.range.end.line,E))continue;let d=null;u.edits&&u.edits.length>0&&(d=await this.computeFixForMatch(u,e).catch(p=>(this.connection.console.log(`Warning: Failed to compute fix for match: ${p}`),null)));let T={range:fre(u.range),severity:_r.DiagnosticSeverity.Warning,message:u.description||c.message,code:c.id,codeDescription:{href:`https://app.wispbit.com/rules/${c.internalId}`},source:"wispbit",data:{uri:i,match:u,matchId:E,fix:d?{diff:d.diff,diffs:d.diffs,autofix:c.autofix||!1}:null,rule:{id:c.internalId,displayId:c.id,summary:c.summary||null}}};o.push(T)}}return o}triggerExecution(){this.executionDebounceTimer&&(clearTimeout(this.executionDebounceTimer),this.executionDebounceTimer=null),this.executionDebounceTimer=setTimeout(()=>{this.executionDebounceTimer=null,this.executeQueuedFiles()},this.EXECUTION_DEBOUNCE_MS)}lintDocument(e){if(!this.documentManager.getDocument(e)){this.connection.console.log(`Document not found: ${e}`);return}let r=Jo(e),i=this.toRelativePath(r);this.connection.console.log(`File changed: ${i}`),this.changedFiles.add(e),this.triggerExecution()}async executeQueuedFiles(){let e=this.repositoryContextManager.getAllContexts();if(e.length===0){this.connection.console.log("No repositories found, skipping execution");return}if(!this.hasRunInitialCheck){if(this.isExecutingInitial){this.connection.console.log("Initial check already in progress, files will be queued for next run");return}this.changedFiles.clear(),this.isExecutingInitial=!0;try{await this.repositoryContextManager.initializeRuntimeManager()&&this.connection.console.log("RuntimeManager initialized successfully"),this.hasRunInitialCheck=!0,this.cleanupProgress(),await this.startBatchProgress(0);try{for(let i of e)await this.executeForContext(i,null);this.cleanupProgress()}catch(i){this.connection.console.error(`Error executing rules: ${i.message}`),this.connection.console.error(i.stack),this.cleanupProgress()}}finally{this.isExecutingInitial=!1}}else{let r=Array.from(this.changedFiles);if(this.changedFiles.clear(),r.length===0){this.connection.console.log("No files to check, skipping incremental execution");return}this.connection.console.log(`Incremental check for ${r.length} file(s)`),await this.startBatchProgress(0);try{for(let i of e)await this.executeForContext(i,r);this.cleanupProgress()}catch(i){this.connection.console.error(`Error executing rules: ${i.message}`),this.connection.console.error(i.stack),this.cleanupProgress()}}}async executeForContext(e,n){e.isExecuting=!0;try{let r=await this.loadRulesWithCache(e);e.completedRulesCount=0,e.currentExecutionRules=r;let{commitSelector:i,include:o}=await ga(e.repoRoot);e.lastCommitSelector=i;let s=await Pa.initialize(e.config,e.environment,"diff",e.eventEmitter,void 0,{include:o,commitSelector:i,skipPreExistingViolations:!0});if(e.executionContext=s,e.runtimeManager){let a=[];if(n!==null&&n.length>0?a=n.filter(c=>this.findContextForFile(c)?.repoRoot===e.repoRoot).map(c=>({filePath:this.toRelativePath(Jo(c),e)})):a=s.filePaths.map(c=>({filePath:c})),a.length>0){this.connection.console.log(`[${e.repoRoot}] Starting invalidation of ${a.length} file(s) in RuntimeManager...`);let c=Date.now();await e.runtimeManager.invalidateFiles(e.repoRoot,a);let u=Date.now()-c;this.connection.console.log(`[${e.repoRoot}] Completed invalidation in ${u}ms`)}}if(n!==null&&n.length>0){let a=n.filter(c=>this.findContextForFile(c)?.repoRoot===e.repoRoot);if(a.length===0){this.connection.console.log(`[${e.repoRoot}] No changed files in this repository, skipping`);return}for(let c of a){let u=this.toRelativePath(Jo(c),e);this.connection.console.log(`[${e.repoRoot}] Executing rules for ${u}`),e.completedRulesCount=0;let l=e.ruleExecutor.execute(r,s,{relativePath:u}),E=e.duplicateManager?e.duplicateManager.execute(s,u,(d,f,T,p)=>{this.handleDuplicateFileComplete(e,d,f,T,p)}):Promise.resolve();await Promise.all([l,E])}}else{let a=e.ruleExecutor.execute(r,s),c=e.duplicateManager?(async()=>{let u=e.duplicateManager;this.connection.console.log(`[${e.repoRoot}] Starting duplicate detection...`);let l=Date.now();await u.execute(s,void 0,(d,f,T,p)=>{this.handleDuplicateFileComplete(e,d,f,T,p)});let E=Date.now()-l;this.connection.console.log(`[${e.repoRoot}] Completed duplicate detection in ${E}ms`)})():Promise.resolve();await Promise.all([a,c])}}catch(r){this.connection.console.error(`[${e.repoRoot}] Error executing rules: ${r.message}`),this.connection.console.error(r.stack)}finally{e.isExecuting=!1}}async startBatchProgress(e){if(this.batchProgressReporter)this.batchProgressReporter.report(e,"Checking workspace");else try{this.progressTokenCreated||(await this.connection.sendRequest("window/workDoneProgress/create",{token:this.batchProgressToken}),this.progressTokenCreated=!0),this.batchProgressReporter=await this.connection.window.createWorkDoneProgress(),this.batchProgressReporter.begin("wispbit",e,"Checking workspace",!1)}catch(n){this.connection.console.log(`Failed to create batch progress: ${n}`)}}cleanupProgress(){this.batchProgressReporter&&(this.batchProgressReporter.done(),this.batchProgressReporter=null)}updateBatchProgress(e,n){if(!this.batchProgressReporter)return;let r=`Checking workspace (${n})`;this.batchProgressReporter.report(e,r)}async processFixQueue(){if(!this.isProcessingFix){for(this.isProcessingFix=!0;this.fixQueue.length>0;){let e=this.fixQueue.shift();e&&await e()}this.isProcessingFix=!1}}handleQuickfix(e){let{uri:n,matchId:r}=e[0];this.fixQueue.push(async()=>{await this.applyQuickfix(n,r)}),this.processFixQueue()}async applyQuickfix(e,n){let i=this.getDiagnosticsForUri(e).find(T=>T.data?.matchId===n);if(!i){this.connection.window.showErrorMessage("Could not apply fix"),this.connection.console.error(`Diagnostic not found for matchId: ${n}`);return}let o=i.data?.match,s=i.data?.rule;if(!o?.edits||o.edits.length===0){this.connection.window.showErrorMessage("No fix available"),this.connection.console.error(`No fix available for matchId ${n}, rule ${s?.id}`);return}let a=this.findContextForFile(e);if(!a){this.connection.window.showErrorMessage("File is not in any repository"),this.connection.console.error(`No repository context found for ${e}`);return}let c=Jo(e),u=this.toRelativePath(c,a);this.connection.console.log(`[${a.repoRoot}] Applying fix for matchId ${n}, rule ${s?.id}`);let l=await this.computeFixForMatch(o,a);if(!l){this.connection.window.showErrorMessage("Failed to compute fix"),this.connection.console.error(`[${a.repoRoot}] Failed to compute fix for matchId ${n}, rule ${s?.id}`);return}let E=Jo(e),d=[];for(let T of l.fileChanges){let S=T.filePath===E?e:T.fileUri,m=this.documentManager.getDocument(S),O=m?m.lineCount:T.oldContent.split(`
294
+ `);return{file:e.file,range:{start:{line:a+1,column:1},end:{line:c+1,column:o[c]?.length||1}},text:u}}extractGroupContext(e,n,r=20){return e.fragments.map(i=>this.extractFragmentContext(i,n,r))}clusterBySharedFiles(){if(this.groups.length===0)return[];let e=new Map;this.groups.forEach((o,s)=>{let a=new Set;for(let c of o.fragments)a.add(c.file);for(let c of a)e.has(c)||e.set(c,[]),e.get(c).push(s)});let n=new MF(this.groups.length);for(let o of e.values())for(let s=1;s<o.length;s++)n.union(o[0],o[s]);let r=new Map;for(let o=0;o<this.groups.length;o++){let s=n.find(o);r.has(s)||r.set(s,[]),r.get(s).push(o)}let i=[];for(let o of r.values()){let s=o.map(c=>this.groups[c]),a=new Set;for(let c of s)for(let u of c.fragments)a.add(u.file);i.push({groups:s,files:a})}return i}},MF=class{parent=new Map;rank=new Map;constructor(e){for(let n=0;n<e;n++)this.parent.set(n,n),this.rank.set(n,0)}find(e){return this.parent.get(e)!==e&&this.parent.set(e,this.find(this.parent.get(e))),this.parent.get(e)}union(e,n){let r=this.find(e),i=this.find(n);if(r===i)return;let o=this.rank.get(r),s=this.rank.get(i);o<s?this.parent.set(r,i):o>s?this.parent.set(i,r):(this.parent.set(i,r),this.rank.set(r,o+1))}};var qI=class t{static INDEX_FOLDER=Qut(Jut(),".wispbit","indexes");provider;initialized=!1;constructor(e){this.provider=e}async initializeProvider(){this.initialized||(await this.provider.initialize(),this.initialized=!0)}async initialize(e){await this.initializeProvider();let n=await this.provider.sendRequest({command:"initialize_workspaces",workspace_configs:e.workspaceConfigs.map(r=>({workspace_root:r.workspaceRoot,base_commit_sha:r.baseCommitSha})),index_folder:t.INDEX_FOLDER,ignores:e.ignores});if("error"in n&&n.error)throw new Error(`Failed to initialize workspaces: ${n.error}`);return{fullScan:n.full_scan||!1}}async getDuplicates(e,n){await this.initializeProvider();let r=await this.provider.sendRequest({command:"get_duplicates",workspace_root:e,file_path:n});if("error"in r&&r.error)throw new Error(`Failed to get duplicates: ${r.error}`);let i=r;return new im(i)}async getDuplicatesForFile(e,n){await this.initializeProvider();let r=await this.provider.sendRequest({command:"get_duplicates",workspace_root:e,file_path:n});if("error"in r&&r.error)throw new Error(`Failed to get duplicates for file: ${r.error}`);let i=r;return new im(i)}invalidationQueue=Promise.resolve();async invalidateFiles(e,n){let r=this.invalidationQueue.then(async()=>{await this.initializeProvider();let i=Date.now(),o=await this.provider.sendRequest({command:"invalidate_files",workspace_root:e,files:n.map(a=>({file_path:a.filePath,content_sha:a.contentSha}))}),s=Date.now()-i;if(Ae.log(`[RuntimeManager] Invalidated ${n.length} file(s) in ${s}ms for ${e}`),"error"in o&&o.error)throw new Error(`Failed to invalidate files: ${o.error}`)}).catch(i=>{throw Ae.log(`[RuntimeManager] Invalidation failed: ${i.message}`),i});this.invalidationQueue=r.catch(()=>{}),await r}isInitialized(){return this.initialized}async shutdown(){this.initialized&&(Ae.log("[RuntimeManager] Shutdown requested, waiting for in-flight operations..."),await this.invalidationQueue.catch(()=>{}),Ae.log("[RuntimeManager] All operations complete, shutting down runtime..."),await this.provider.shutdown(),this.initialized=!1)}};var JI=class{contexts=new Map;workspacePath;apiKey;lspClient;sharedRuntimeManager=null;RULES_CACHE_TTL_MS=300*1e3;constructor(e){this.workspacePath=e.workspacePath,this.apiKey=e.apiKey,this.lspClient=e.lspClient}async discoverAndInitialize(e,n){let r=await tO(this.workspacePath),i=[];for(let s of r){let a=await this.initializeContext(s).catch(c=>(n?.(s,c),null));if(a){let{baseCommitSha:c}=await ga(s);i.push({repoRoot:s,context:a,baseCommitSha:c}),this.contexts.set(s,a),e?.(s,a)}}let o=[];for(let{repoRoot:s,context:a,baseCommitSha:c}of i)a.config.getEnableDeduplicator()&&o.push({workspaceRoot:s,baseCommitSha:c});if(o.length>0){let s=new ZI(o[0].workspaceRoot);this.sharedRuntimeManager=new qI(s);for(let{context:a}of i)a.config.getEnableDeduplicator()&&(a.runtimeManager=this.sharedRuntimeManager,a.duplicateManager=new zI(this.sharedRuntimeManager,a.config,a.environment))}}async initializeContext(e){let n=new Kr({workspaceRoot:e}),r=await Yo.initialize(n,{apiKey:this.apiKey,lspClient:this.lspClient});if("failed"in r)throw new Error(`Config initialization failed for ${e}: ${r.error}`);let i=r,o=new $o(i,n),s=new zr,a=new La(i,n,s);return{repoRoot:e,environment:n,config:i,ruleProvider:o,eventEmitter:s,ruleExecutor:a,cachedRules:null,rulesById:new Map,rulesCacheTimestamp:0,rulesLoadingPromise:null,lastCommitSelector:null,currentExecutionRules:[],completedRulesCount:0,isExecuting:!1,currentExecutionPromise:null,runtimeManager:null,duplicateManager:null,executionContext:null}}findContextForFile(e){let n=e.toLowerCase();return Array.from(this.contexts.entries()).filter(([i])=>{let o=i.toLowerCase();return n.startsWith(o+elt)||n===o}).sort((i,o)=>o[0].length-i[0].length)[0]?.[1]||null}getAllContexts(){return Array.from(this.contexts.values())}getRepoCount(){return this.contexts.size}hasRepositories(){return this.contexts.size>0}getContext(e){return this.contexts.get(e)}async initializeRuntimeManager(){if(!this.sharedRuntimeManager)return!1;let e=[],n=[];for(let r of this.contexts.values())if(r.config.getEnableDeduplicator()){let{baseCommitSha:i}=await ga(r.repoRoot);e.push({workspaceRoot:r.repoRoot,baseCommitSha:i}),n.length===0&&(n=r.config.getIgnoredGlobs())}return e.length===0?!1:(await this.sharedRuntimeManager.initialize({workspaceConfigs:e,ignores:n}),!0)}async shutdown(){for(let e of this.contexts.values())e.ruleExecutor.clearCache(),e.duplicateManager&&e.duplicateManager.clearCache();this.sharedRuntimeManager&&(await this.sharedRuntimeManager.shutdown(),this.sharedRuntimeManager=null),this.contexts.clear()}};function dre(t,e,n){if(t.fingerprint)return`${e}:${t.fingerprint}`;let r=t.text?.slice(0,100)||"",i=`${t.range.start.line}:${t.range.start.column}-${t.range.end.line}:${t.range.end.column}`;return`${e}:${n}:${i}:${nlt(r)}`}function nlt(t){let e=0;for(let n=0;n<t.length;n++){let r=t.charCodeAt(n);e=(e<<5)-e+r,e=e&e}return e.toString(36)}function fre(t){return t.end.line-t.start.line+1>20?{start:{line:t.start.line-1,character:t.start.column-1},end:{line:t.start.line-1,character:Number.MAX_SAFE_INTEGER}}:{start:{line:t.start.line-1,character:t.start.column-1},end:{line:t.end.line-1,character:t.end.column-1}}}var PF=class{connection;documentManager;repositoryContextManager;workspacePath;apiKey;lspClient;batchProgressReporter=null;batchProgressToken="wispbit-batch-lint";progressTokenCreated=!1;fixQueue=[];isProcessingFix=!1;branchCheckTimer=null;BRANCH_CHECK_DEBOUNCE_MS=1e3;branchCheckInterval=null;BRANCH_CHECK_INTERVAL_MS=3e4;executionDebounceTimer=null;EXECUTION_DEBOUNCE_MS=1e3;changedFiles=new Set;hasRunInitialCheck=!1;isExecutingInitial=!1;dismissalsLoadingPromises=new Map;fixesLoadingPromises=new Map;localDismissals=[];constructor(e){this.workspacePath=e.workspacePath,this.apiKey=e.apiKey,this.lspClient=e.lspClient,this.connection=(0,_r.createConnection)(_r.ProposedFeatures.all,process.stdin,process.stdout),this.documentManager=new KI,this.repositoryContextManager=new JI({workspacePath:this.workspacePath,apiKey:this.apiKey,lspClient:this.lspClient}),this.registerHandlers()}addLocalDismissal(e){this.localDismissals.push(e)}isLocallyDismissed(e,n,r,i,o){return this.localDismissals.some(s=>s.matchId===o&&s.uri===e?!0:s.uri===e&&s.ruleId===n?s.startLine<=i&&s.endLine>=r:!1)}clearLocalDismissalsForUri(e){this.localDismissals=this.localDismissals.filter(n=>n.uri!==e)}clearAllLocalDismissals(){this.localDismissals=[]}findContextForFile(e){let n=Jo(e);return this.repositoryContextManager.findContextForFile(n)}pathToNormalizedUri(e){let n=tlt(e).toString();return decodeURIComponent(n)}getDiagnosticsForUri(e){let n=this.documentManager.getDiagnostics(e);if(n.length===0){let r=qr(e),i=this.documentManager.getAllDiagnosticUris();for(let o of i)if(qr(o)===r){n=this.documentManager.getDiagnostics(o);break}}return n}handleRuleComplete(e,n,r){if(!e.isExecuting||e.currentExecutionRules.length===0)return;e.completedRulesCount++;let i=Math.round(e.completedRulesCount/e.currentExecutionRules.length*100);this.updateBatchProgress(i,n)}async handleRuleFileComplete(e,n,r,i){if(!e.isExecuting||e.currentExecutionRules.length===0)return;let o=e.currentExecutionRules.find(u=>u.id===n);if(!o){this.connection.console.log(`[${e.repoRoot}] Warning: Rule ${n} not found in current execution`);return}let s=u_(e.repoRoot,r),a=this.pathToNormalizedUri(s);if(i.length===0){this.updateDiagnosticsForRule(a,o.internalId,[]);return}let c=await this.createDiagnosticsForFile(e,r,o.internalId,i,e.currentExecutionRules);this.updateDiagnosticsForRule(a,o.internalId,c)}async handleRuleFilePartial(e,n,r,i,o){if(!e.isExecuting||e.currentExecutionRules.length===0)return;let s=e.currentExecutionRules.find(l=>l.internalId===n);if(!s){this.connection.console.log(`[${e.repoRoot}] Warning: Rule ${n} not found in current execution`);return}let a=u_(e.repoRoot,r),c=this.pathToNormalizedUri(a);if(i.length===0){this.updateDiagnosticsForRule(c,s.internalId,[]);return}let u=await this.createDiagnosticsForFile(e,r,s.internalId,i,e.currentExecutionRules);this.updateDiagnosticsForRule(c,s.internalId,u)}async convertDuplicateResultsToDiagnostics(e,n,r,i){let o=[];for(let s of n)for(let a of s.matches){let c=dre(a,"DUPLICATE",i);if(this.isLocallyDismissed(i,"DUPLICATE",a.range.start.line,a.range.end.line,c))continue;let u=fre(a.range),l=a.evidence?.map(f=>{let T=u_(e.repoRoot,f.file.path);return{location:{uri:this.pathToNormalizedUri(T),range:{start:{line:f.range.start.line-1,character:f.range.start.column-1},end:{line:f.range.end.line-1,character:f.range.end.column-1}}},message:"Duplicate location"}}),E=null;a.edits&&a.edits.length>0&&(E=await this.computeFixForMatch(a,e).catch(f=>(this.connection.console.log(`Warning: Failed to compute fix for duplicate: ${f}`),null)));let d={range:u,severity:_r.DiagnosticSeverity.Warning,message:a.description||"Duplicate code detected",code:"DUPLICATE",source:"wispbit",relatedInformation:l,data:{uri:i,match:a,matchId:c,fix:E?{diff:E.diff,diffs:E.diffs,autofix:!1}:null,ruleId:"DUPLICATE",filePath:a.file.path,rule:{id:"DUPLICATE",displayId:"DUPLICATE",summary:null}}};o.push(d)}return o}async handleDuplicateFileComplete(e,n,r,i,o){let s=u_(e.repoRoot,n),a=this.pathToNormalizedUri(s),c=await this.createDiagnosticsForFile(e,n,"DUPLICATE",r,[],this.convertDuplicateResultsToDiagnostics.bind(this));this.updateDiagnosticsForRule(a,"DUPLICATE",c)}setupProgressListenersForContext(e){e.eventEmitter.on("rules:progress",n=>{this.updateBatchProgress(n.percentage,n.ruleId)}),e.eventEmitter.on("rules:rule-complete",n=>{this.handleRuleComplete(e,n.ruleId,n.matches)}),e.eventEmitter.on("rules:rule-file-complete",async n=>{await this.handleRuleFileComplete(e,n.ruleId,n.filePath,n.matches)}),e.eventEmitter.on("rules:rule-file-partial",async n=>{await this.handleRuleFilePartial(e,n.ruleId,n.filePath,n.matches,n.totalMatches)})}toRelativePath(e,n){if(!n){let r=this.pathToNormalizedUri(e);n=this.findContextForFile(r)||void 0}return n?Ere(n.repoRoot,e):Ere(this.workspacePath,e)}updateDiagnosticsForRule(e,n,r){this.documentManager.setDiagnosticsForRule(e,n,r);let i=this.documentManager.getDiagnostics(e);this.connection.sendDiagnostics({uri:e,diagnostics:i})}removeDiagnosticByMatchId(e,n){let r=this.documentManager.getDiagnostics(e),i=r.find(a=>a.data?.matchId===n);if(!i)return;let o=i.data?.rule?.id;if(!o)return;let s=r.filter(a=>a.data?.rule?.id===o&&a.data?.matchId!==n);this.updateDiagnosticsForRule(e,o,s)}clearAllDiagnostics(){let e=this.documentManager.getAllDiagnosticUris();for(let n of e)this.clearDiagnosticsForFile(n);this.clearAllLocalDismissals()}clearDiagnosticsForFile(e){this.documentManager.clearDiagnostics(e),this.clearLocalDismissalsForUri(e),this.connection.sendDiagnostics({uri:e,diagnostics:[]})}handleDocumentChangesWithRanges(e,n){let r=this.documentManager.getDiagnostics(e);if(r.length===0)return;this.connection.console.log(`Document changed: ${e}, ${n.length} change(s), ${r.length} diagnostic(s)`);let i=new Set;for(let o of n){if(!o.range){this.connection.console.log("Full document change detected - removing all diagnostics");for(let s of r)s.data?.matchId&&i.add(s.data.matchId);continue}for(let s of r)this.rangesOverlap(o.range,s.range)&&s.data?.matchId&&i.add(s.data.matchId)}for(let o of i)this.removeDiagnosticByMatchId(e,o);i.size>0&&this.connection.console.log(`Removed ${i.size} diagnostic(s) due to document edits`)}rangesOverlap(e,n){return e.end.line<n.start.line||e.start.line>n.end.line?!1:e.start.line<=n.end.line&&e.end.line>=n.start.line}async createDiagnosticsForFile(e,n,r,i,o,s){let a=i.length;this.documentManager.hasDismissals(n)||await this.loadDismissalsForFile(e,n),this.documentManager.hasFixes(n)||await this.loadFixesForFile(e,n);let c={ruleId:r,matches:i},u=this.filterDismissedResults([c],n),l=u[0]?.matches.length||0,E=a-l,d=await this.filterFixedResults(e,u,n),f=d[0]?.matches.length||0,T=l-f,p=u_(e.repoRoot,n),S=this.pathToNormalizedUri(p),m=await(s||this.convertResultsToDiagnostics.bind(this))(e,d,o,S);if(a>0){let h=o.find(P=>P.internalId===r)?.id||r,C=[];E>0&&C.push(`${E} dismissed`),T>0&&C.push(`${T} fixed`),C.length>0?this.connection.console.log(`[${e.repoRoot}] ${n}: ${m.length} diagnostic(s) created, ${C.join(", ")} (rule: ${h})`):this.connection.console.log(`[${e.repoRoot}] ${n}: ${m.length} diagnostic(s) created (rule: ${h})`)}return m}async getFileContent(e){let n=this.pathToNormalizedUri(e),r=this.documentManager.getDocument(n);return r?r.getText():await _re.readFile(e,"utf-8").catch(()=>null)}async computeFixForMatch(e,n){if(!e.edits||e.edits.length===0)return null;let r=await jc(e.edits,e.file.path,n.repoRoot,o=>this.getFileContent(o));return r?{fileChanges:r.fileChanges.map(o=>({...o,fileUri:this.pathToNormalizedUri(o.filePath)})),diff:r.diff,diffs:r.diffs}:null}async loadRulesWithCache(e){let r=Date.now()-e.rulesCacheTimestamp;return e.cachedRules&&r<this.repositoryContextManager.RULES_CACHE_TTL_MS?(this.connection.console.log(`[${e.repoRoot}] Using cached rules (age: ${Math.round(r/1e3)}s / ${this.repositoryContextManager.RULES_CACHE_TTL_MS/1e3}s)`),e.cachedRules):e.rulesLoadingPromise?(this.connection.console.log(`[${e.repoRoot}] Rules are already being loaded, waiting for existing request...`),e.rulesLoadingPromise):(this.connection.console.log(`[${e.repoRoot}] Loading fresh rules from API...`),e.rulesLoadingPromise=e.ruleProvider.loadAllRules().then(i=>{let o=i.filter(s=>s.execution==="llm");e.cachedRules=o,e.rulesCacheTimestamp=Date.now(),e.rulesById.clear();for(let s of o)e.rulesById.set(s.id,s);if(this.connection.console.log(`[${e.repoRoot}] Loaded ${o.length} rules (cache valid for ${this.repositoryContextManager.RULES_CACHE_TTL_MS/1e3}s)`),o.length>0){this.connection.console.log(`[${e.repoRoot}] Fetched rules:`);for(let s of o){let a=s.autofix||!1,c="";a&&(c=" (autofix)"),this.connection.console.log(`[${e.repoRoot}] - ${s.id}: ${s.message}${c}`)}}return o}).finally(()=>{e.rulesLoadingPromise=null}),await e.rulesLoadingPromise)}async loadDismissalsForFile(e,n){if(this.documentManager.hasDismissals(n))return;let r=this.dismissalsLoadingPromises.get(n);if(r)return await r;let i=(async()=>{let s=(await e.ruleProvider.getDismissals([n])).map(a=>({ruleId:a.ruleId,file:a.match.file.path,startLine:a.match.range.start.line,endLine:a.match.range.end.line,fingerprint:a.match.fingerprint,dismissedAt:a.createdAt,dismissalId:a.dismissalId}));this.documentManager.setDismissals(n,s)})().finally(()=>{this.dismissalsLoadingPromises.delete(n)});return this.dismissalsLoadingPromises.set(n,i),await i}async loadFixesForFile(e,n){if(this.documentManager.hasFixes(n))return;let r=this.fixesLoadingPromises.get(n);if(r)return await r;let i=(async()=>{let o=await e.ruleProvider.getFixes([n]);this.documentManager.setFixes(n,o)})().finally(()=>{this.fixesLoadingPromises.delete(n)});return this.fixesLoadingPromises.set(n,i),await i}filterDismissedResults(e,n){let r=this.documentManager.getDismissals(n);return r.length===0?e:e.map(i=>{let o=r.filter(u=>u.ruleId===i.ruleId);if(o.length===0)return i;let s=i.matches.map(u=>({file:n,startLine:u.range.start.line,endLine:u.range.end.line,fingerprint:u.fingerprint})),c=gh(s,o).map(u=>i.matches.find(l=>l.range.start.line===u.startLine&&l.range.end.line===u.endLine&&l.fingerprint===u.fingerprint));return{...i,matches:c}})}async filterFixedResults(e,n,r){let i=this.documentManager.getFixes(r);if(i.length===0)return n;this.connection.console.log(`[${e.repoRoot}] Filtering fixes for ${r}: ${i.length} fix(es) loaded`);let o=u_(e.repoRoot,r),s=await this.getFileContent(o);return s===null?n:n.map(a=>{let c=i.filter(S=>S.ruleId===a.ruleId);if(c.length===0)return a;let u=new Set;for(let S of c)S.match?.edits?.some(O=>O.oldString&&m1(s,O.oldString))&&S.match.fingerprint&&u.add(S.match.fingerprint);let l=c.length-u.size;u.size>0&&this.connection.console.log(`[${e.repoRoot}] ${r}: ${u.size} fix(es) reverted, ${l} still active`);let E=a.matches.map(S=>({file:r,startLine:S.range.start.line,endLine:S.range.end.line,fingerprint:S.fingerprint})),d=c.filter(S=>!S.match.fingerprint||!u.has(S.match.fingerprint)).map(S=>({file:r,startLine:S.match.range.start.line,endLine:S.match.range.end.line,fingerprint:S.match.fingerprint})),T=gh(E,d).map(S=>a.matches.find(m=>m.range.start.line===S.startLine&&m.range.end.line===S.endLine&&m.fingerprint===S.fingerprint)),p=a.matches.length-T.length;return p>0&&this.connection.console.log(`[${e.repoRoot}] ${r}: Filtered out ${p} match(es) with active fixes`),{...a,matches:T}})}async convertResultsToDiagnostics(e,n,r,i){let o=[],s=new Set;for(let a of n){let c=r.find(u=>u.internalId===a.ruleId);if(!c){this.connection.console.log(`Warning: Could not find rule with internal ID ${a.ruleId}`);continue}for(let u of a.matches){let l=`${u.range.start.line}-${u.range.end.line}`;if(s.has(l))continue;s.add(l);let E=dre(u,c.internalId,i);if(this.isLocallyDismissed(i,c.internalId,u.range.start.line,u.range.end.line,E))continue;let d=null;u.edits&&u.edits.length>0&&(d=await this.computeFixForMatch(u,e).catch(p=>(this.connection.console.log(`Warning: Failed to compute fix for match: ${p}`),null)));let T={range:fre(u.range),severity:_r.DiagnosticSeverity.Warning,message:u.description||c.message,code:c.id,codeDescription:{href:`https://app.wispbit.com/rules/${c.internalId}`},source:"wispbit",data:{uri:i,match:u,matchId:E,fix:d?{diff:d.diff,diffs:d.diffs,autofix:c.autofix||!1}:null,rule:{id:c.internalId,displayId:c.id,summary:c.summary||null}}};o.push(T)}}return o}triggerExecution(){this.executionDebounceTimer&&(clearTimeout(this.executionDebounceTimer),this.executionDebounceTimer=null),this.executionDebounceTimer=setTimeout(()=>{this.executionDebounceTimer=null,this.executeQueuedFiles()},this.EXECUTION_DEBOUNCE_MS)}lintDocument(e){if(!this.documentManager.getDocument(e)){this.connection.console.log(`Document not found: ${e}`);return}let r=Jo(e),i=this.toRelativePath(r);this.connection.console.log(`File changed: ${i}`),this.changedFiles.add(e),this.triggerExecution()}async executeQueuedFiles(){let e=this.repositoryContextManager.getAllContexts();if(e.length===0){this.connection.console.log("No repositories found, skipping execution");return}if(!this.hasRunInitialCheck){if(this.isExecutingInitial){this.connection.console.log("Initial check already in progress, files will be queued for next run");return}this.changedFiles.clear(),this.isExecutingInitial=!0;try{await this.repositoryContextManager.initializeRuntimeManager()&&this.connection.console.log("RuntimeManager initialized successfully"),this.hasRunInitialCheck=!0,this.cleanupProgress(),await this.startBatchProgress(0);try{for(let i of e)await this.executeForContext(i,null);this.cleanupProgress()}catch(i){this.connection.console.error(`Error executing rules: ${i.message}`),this.connection.console.error(i.stack),this.cleanupProgress()}}finally{this.isExecutingInitial=!1}}else{let r=Array.from(this.changedFiles);if(this.changedFiles.clear(),r.length===0){this.connection.console.log("No files to check, skipping incremental execution");return}this.connection.console.log(`Incremental check for ${r.length} file(s)`),await this.startBatchProgress(0);try{for(let i of e)await this.executeForContext(i,r);this.cleanupProgress()}catch(i){this.connection.console.error(`Error executing rules: ${i.message}`),this.connection.console.error(i.stack),this.cleanupProgress()}}}async executeForContext(e,n){e.isExecuting=!0;try{let r=await this.loadRulesWithCache(e);e.completedRulesCount=0,e.currentExecutionRules=r;let{commitSelector:i,include:o}=await ga(e.repoRoot);e.lastCommitSelector=i;let s=await Pa.initialize(e.config,e.environment,"diff",e.eventEmitter,void 0,{include:o,commitSelector:i,skipPreExistingViolations:!0});if(e.executionContext=s,e.runtimeManager){let a=[];if(n!==null&&n.length>0?a=n.filter(c=>this.findContextForFile(c)?.repoRoot===e.repoRoot).map(c=>({filePath:this.toRelativePath(Jo(c),e)})):a=s.filePaths.map(c=>({filePath:c})),a.length>0){this.connection.console.log(`[${e.repoRoot}] Starting invalidation of ${a.length} file(s) in RuntimeManager...`);let c=Date.now();await e.runtimeManager.invalidateFiles(e.repoRoot,a);let u=Date.now()-c;this.connection.console.log(`[${e.repoRoot}] Completed invalidation in ${u}ms`)}}if(n!==null&&n.length>0){let a=n.filter(c=>this.findContextForFile(c)?.repoRoot===e.repoRoot);if(a.length===0){this.connection.console.log(`[${e.repoRoot}] No changed files in this repository, skipping`);return}for(let c of a){let u=this.toRelativePath(Jo(c),e);this.connection.console.log(`[${e.repoRoot}] Executing rules for ${u}`),e.completedRulesCount=0;let l=e.ruleExecutor.execute(r,s,{relativePath:u,emitErrors:!0}),E=e.duplicateManager?e.duplicateManager.execute(s,u,(d,f,T,p)=>{this.handleDuplicateFileComplete(e,d,f,T,p)}):Promise.resolve();await Promise.all([l,E])}}else{let a=e.ruleExecutor.execute(r,s,{emitErrors:!0}),c=e.duplicateManager?(async()=>{let u=e.duplicateManager;this.connection.console.log(`[${e.repoRoot}] Starting duplicate detection...`);let l=Date.now();await u.execute(s,void 0,(d,f,T,p)=>{this.handleDuplicateFileComplete(e,d,f,T,p)});let E=Date.now()-l;this.connection.console.log(`[${e.repoRoot}] Completed duplicate detection in ${E}ms`)})():Promise.resolve();await Promise.all([a,c])}}catch(r){this.connection.console.error(`[${e.repoRoot}] Error executing rules: ${r.message}`),this.connection.console.error(r.stack)}finally{e.isExecuting=!1}}async startBatchProgress(e){if(this.batchProgressReporter)this.batchProgressReporter.report(e,"Checking workspace");else try{this.progressTokenCreated||(await this.connection.sendRequest("window/workDoneProgress/create",{token:this.batchProgressToken}),this.progressTokenCreated=!0),this.batchProgressReporter=await this.connection.window.createWorkDoneProgress(),this.batchProgressReporter.begin("wispbit",e,"Checking workspace",!1)}catch(n){this.connection.console.log(`Failed to create batch progress: ${n}`)}}cleanupProgress(){this.batchProgressReporter&&(this.batchProgressReporter.done(),this.batchProgressReporter=null)}updateBatchProgress(e,n){if(!this.batchProgressReporter)return;let r=`Checking workspace (${n})`;this.batchProgressReporter.report(e,r)}async processFixQueue(){if(!this.isProcessingFix){for(this.isProcessingFix=!0;this.fixQueue.length>0;){let e=this.fixQueue.shift();e&&await e()}this.isProcessingFix=!1}}handleQuickfix(e){let{uri:n,matchId:r}=e[0];this.fixQueue.push(async()=>{await this.applyQuickfix(n,r)}),this.processFixQueue()}async applyQuickfix(e,n){let i=this.getDiagnosticsForUri(e).find(T=>T.data?.matchId===n);if(!i){this.connection.window.showErrorMessage("Could not apply fix"),this.connection.console.error(`Diagnostic not found for matchId: ${n}`);return}let o=i.data?.match,s=i.data?.rule;if(!o?.edits||o.edits.length===0){this.connection.window.showErrorMessage("No fix available"),this.connection.console.error(`No fix available for matchId ${n}, rule ${s?.id}`);return}let a=this.findContextForFile(e);if(!a){this.connection.window.showErrorMessage("File is not in any repository"),this.connection.console.error(`No repository context found for ${e}`);return}let c=Jo(e),u=this.toRelativePath(c,a);this.connection.console.log(`[${a.repoRoot}] Applying fix for matchId ${n}, rule ${s?.id}`);let l=await this.computeFixForMatch(o,a);if(!l){this.connection.window.showErrorMessage("Failed to compute fix"),this.connection.console.error(`[${a.repoRoot}] Failed to compute fix for matchId ${n}, rule ${s?.id}`);return}let E=Jo(e),d=[];for(let T of l.fileChanges){let S=T.filePath===E?e:T.fileUri,m=this.documentManager.getDocument(S),O=m?m.lineCount:T.oldContent.split(`
295
295
  `).length;m||T.oldContent.length>0||d.push(_r.CreateFile.create(S,{overwrite:!1,ignoreIfExists:!0}));let C={textDocument:{uri:S,version:m?.version??null},edits:[_r.TextEdit.replace({start:{line:0,character:0},end:{line:O,character:0}},T.newContent)]};d.push(C)}let f=await this.connection.workspace.applyEdit({documentChanges:d});f.applied?this.connection.console.log(`[${a.repoRoot}] Applied fix successfully`):this.connection.console.log(`[${a.repoRoot}] Could not apply fix. Reason: ${f.failureReason}, Change: ${f.failedChange}`),await a.ruleProvider.createFix(s?.id,o).catch(T=>{this.connection.console.log(`[${a.repoRoot}] Failed to track fix: ${T.message}`)}),this.removeDiagnosticByMatchId(e,n),this.documentManager.clearFixes(u)}async handleDismiss(e){let{uri:n,matchId:r,ruleId:i,startLine:o,endLine:s}=e[0],a=this.findContextForFile(n);if(!a){this.connection.window.showErrorMessage("File is not in any repository"),this.connection.console.error(`No repository context found for ${n}`);return}let c=Jo(n),u=this.toRelativePath(c,a),l=this.getDiagnosticsForUri(n),E=l.find(S=>S.data?.matchId===r);if(!E&&i&&o!==void 0&&s!==void 0&&(E=l.find(S=>{let m=S.data?.rule?.id,O=S.range.start.line+1,h=S.range.end.line+1;return m===i&&O<=s&&h>=o})),!E){this.connection.window.showErrorMessage("Could not dismiss violation"),this.connection.console.error(`[${a.repoRoot}] Diagnostic not found for matchId: ${r}`);return}let d=E.data?.match,f=E.data?.rule?.id,T=E.data?.matchId;if(!d||!f||!T){this.connection.window.showErrorMessage("Could not dismiss violation"),this.connection.console.error(`[${a.repoRoot}] Match not found for matchId: ${r}`);return}this.addLocalDismissal({uri:n,ruleId:f,startLine:E.range.start.line+1,endLine:E.range.end.line+1,matchId:T,timestamp:Date.now()}),this.removeDiagnosticByMatchId(n,T),await a.ruleProvider.createDismissal(f,d).catch(S=>{this.connection.console.log(`[${a.repoRoot}] Failed to create dismissal: ${S.message}`)});let p=E.data?.rule?.displayId||f;this.connection.console.log(`[${a.repoRoot}] Dismissed violation: ${p} with matchId ${T}`),this.documentManager.clearDismissals(u)}async handleGetDismissals(e){let{uri:n}=e[0];if(!n||typeof n!="string")return this.connection.console.log(`Invalid URI provided to getDismissals: ${n}`),[];if(!n.startsWith("file://"))return this.connection.console.log(`URI must be a file:// URL, got: ${n}`),[];let r=this.findContextForFile(n);if(!r)return this.connection.console.log(`No repository context found for ${n}`),[];let i=Jo(n),o=this.toRelativePath(i,r);await this.loadDismissalsForFile(r,o);let s=this.documentManager.getDismissals(o),a=await this.loadRulesWithCache(r),c=this.documentManager.getDocument(n);if(!c){let u=qr(n),l=this.documentManager.getAllDocumentUris();for(let E of l)if(qr(E)===u){c=this.documentManager.getDocument(E);break}}return s.map(u=>{let l=a.find(f=>f.internalId===u.ruleId),E="";if(c){let f=c.getText({start:{line:u.startLine-1,character:0},end:{line:u.startLine-1,character:100}});E=f.trim().substring(0,60),f.trim().length>60&&(E+="...")}let d="";if(u.dismissedAt){let f=new Date,T=new Date(u.dismissedAt),p=f.getTime()-T.getTime(),S=Math.floor(p/6e4),m=Math.floor(S/60),O=Math.floor(m/24);S<1?d="just now":S<60?d=`${S} minute${S===1?"":"s"} ago`:m<24?d=`${m} hour${m===1?"":"s"} ago`:d=`${O} day${O===1?"":"s"} ago`}return{dismissalId:u.dismissalId,ruleId:u.ruleId,displayId:l?.id||u.ruleId,ruleName:l?.message||"Unknown rule",line:u.startLine,fingerprint:u.fingerprint,fileName:o,codeSnippet:E,timeAgo:d}})}async handleUndismiss(e){let{uri:n,dismissalId:r}=e[0],i=this.findContextForFile(n);if(!i){this.connection.window.showErrorMessage("File is not in any repository"),this.connection.console.error(`No repository context found for ${n}`);return}let o=Jo(n),s=this.toRelativePath(o,i),c=this.documentManager.getDismissals(s).find(f=>f.dismissalId===r);if(!c){this.connection.window.showErrorMessage("Dismissal not found"),this.connection.console.error(`[${i.repoRoot}] Dismissal not found with ID ${r}`);return}await i.ruleProvider.deleteDismissal(c.ruleId,c.file,c.fingerprint);let l=(await this.loadRulesWithCache(i)).find(f=>f.internalId===c.ruleId),E=l?.id||c.ruleId,d=l?.message||"Unknown rule";this.connection.console.log(`Undismissed violation: ${E} at line ${c.startLine}`),this.connection.window.showInformationMessage(`Undismissed violation: ${E} at line ${c.startLine} - ${d}`),this.documentManager.clearDismissals(s),this.triggerExecution()}async handleRemember(e){let{uri:n,range:r,selectedText:i,note:o}=e[0],s=this.findContextForFile(n);if(!s){this.connection.window.showErrorMessage("File is not in any repository"),this.connection.console.error(`No repository context found for ${n}`);return}let a=Jo(n),c=this.toRelativePath(a,s);if(!o||o.trim().length===0){this.connection.window.showErrorMessage("Note is required to remember a pattern");return}let l=this.getDiagnosticsForUri(n).filter(E=>E.source==="wispbit"&&E.data?.match).map(E=>({...E.data.match,ruleId:E.data.rule?.id}));this.connection.console.log(`[${s.repoRoot}] Remembering pattern with ${l.length} matches: ${i.substring(0,100)}...`),this.connection.console.log(`[${s.repoRoot}] Note: ${o}`);try{await s.ruleProvider.rememberPattern(c,i,{start:{line:r.start.line+1,column:r.start.character+1},end:{line:r.end.line+1,column:r.end.character+1}},o.trim(),l),this.connection.window.showInformationMessage(`Pattern remembered: ${o.trim()}`)}catch(E){this.connection.console.log(`Failed to remember: ${E.message}`),this.connection.window.showErrorMessage(`Failed to remember: ${E.message}`)}}truncateMessage(e,n=60){return e.length<=n?e:e.substring(0,n)+"..."}generateCodeActions(e,n){let r=[],i=n.filter(c=>c.source==="wispbit"),o=i.filter(c=>c.data?.fix),s=o.length>1&&o.some((c,u)=>o.slice(u+1).some(l=>c.range.start.line<=l.range.end.line&&c.range.end.line>=l.range.start.line)),a=!1;for(let c of i){let u=c.data?.fix,l=u?.autofix||!1,E=u&&(!s||!a);if(u){let f=this.truncateMessage(c.message);r.push({title:`Apply fix: ${f}`,kind:"quickfix",command:{title:"Apply Fix",command:"wispbit.quickfix",arguments:[{uri:e,matchId:c.data?.matchId}]},diagnostics:[c],isPreferred:E}),E&&(a=!0),l&&r.push({title:`Fix: ${f}`,kind:"source.fixAll",command:{title:"Apply Fix",command:"wispbit.quickfix",arguments:[{uri:e,matchId:c.data?.matchId}]},diagnostics:[c],isPreferred:!1})}let d=this.truncateMessage(c.message);r.push({title:`Dismiss: ${d}`,kind:"quickfix",command:{title:"Dismiss",command:"wispbit.dismiss",arguments:[{uri:e,matchId:c.data?.matchId}]},diagnostics:[c]})}return r}generateHover(e,n){let r=e.find(d=>n.line<d.range.start.line||n.line>d.range.end.line?!1:d.range.start.line===d.range.end.line?n.character>=d.range.start.character&&n.character<=d.range.end.character:n.line===d.range.start.line?n.character>=d.range.start.character:n.line===d.range.end.line?n.character<=d.range.end.character:!0);if(!r)return null;let i=String(r.code||""),o;for(let d of this.repositoryContextManager.getAllContexts())if(o=d.rulesById.get(i),o)break;let s=r.data?.fix,a=r.data?.match?.file?.path,c=r.data?.uri,l=(c?this.findContextForFile(c):null)?.repoRoot||this.workspacePath,E="";if(s?.diffs&&s.diffs.length>0)for(let{file:d,diff:f}of s.diffs){if(!(d.path===a)){let p=u_(l,d.path),S=this.pathToNormalizedUri(p);E+=`*[${d.path}](${S})*
296
296
  `}E+="```diff\n",E+=f,E+="\n```\n\n"}return o?.summary&&(o.summary.content&&(E+=`**Summary:** ${o.summary.content}
297
297
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wispbit/local",
3
- "version": "1.0.82",
3
+ "version": "1.0.83",
4
4
  "type": "module",
5
5
  "main": "cli.js",
6
6
  "bin": {