@wispbit/local 1.0.66 → 1.0.67
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cli-bundle.js +1 -1
- package/package.json +1 -1
package/cli-bundle.js
CHANGED
|
@@ -176,7 +176,7 @@ ${fd(Y,{namedOnly:!0,colored:r})}`;break;case"cst":re=`Debug CST:${J}
|
|
|
176
176
|
${fd(Y,{namedOnly:!1,colored:r})}`;break}c.push(`
|
|
177
177
|
=== ${u.language} (injection ${d+1}/${E.length}) ===
|
|
178
178
|
${re}`)}}}if(c.length===0)throw new Error(`No valid language injections found for file "${t}". Unable to generate tree dump.`);return c.join(`
|
|
179
|
-
`)}var UO=class{environment;language;astCache;constructor(e,n){this.environment=e,this.language=n,this.astCache=new bO({max:50,maxSize:1e8,sizeCalculation:r=>r.estimatedSize,dispose:(r,i)=>{r.sgRoot=void 0}})}getCacheKey(e,n){return`${e}:${this.language}:${n}`}async getOrParseAndFindMatches(e,n,r,i){let o=Sh(n),s=this.getCacheKey(e,o),a,c=this.astCache.get(s);if(c)a=c.sgRoot;else{a=await(0,pd.parseAsync)(this.language,n);let d=n.length*2,T={sgRoot:a,path:e,contentHash:o,estimatedSize:d,parsedAt:Date.now()};this.astCache.set(s,T)}let u=a.root().findAll({rule:r,language:this.language,constraints:i});if(u.length===0)return[];let l=Sh(n);return u.map(d=>{let T=d.range(),S=d.text(),p=this.generateFingerprintString(d,n),f={file:{path:e,sha:l},text:S,range:{start:{line:T.start.line,column:T.start.column,index:T.start.index},end:{line:T.end.line,column:T.end.column,index:T.end.index}},language:this.language,fingerprint:p};return fV(f)})}clearCache(){this.astCache.clear()}getCacheStats(){return{size:this.astCache.size,calculatedSize:this.astCache.calculatedSize||0}}async findMatches(e,n){if(e.length===0)return[];let{rule:r,constraints:i}=n,o=this.getBatchSize(),s=[];for(let a=0;a<e.length;a+=o){let c=e.slice(a,a+o),u=await this.processBatch(c,r,i);s.push(...u)}return s}getBatchSize(){let e=parseInt(process.env.UV_THREADPOOL_SIZE||"4",10);return Math.max(2,Math.floor(e/2))}async processBatch(e,n,r){let i=e.map(async s=>{let{path:a,content:c}=s,u=Eot.extname(a).slice(1),l=tO(this.language,u);return l&&Gx(u)?await this.processInjectedLanguageFile(a,c,l,n,r):this.parseAndExtractMatches(a,c,n,r)});return(await Promise.all(i)).flat()}parseAndExtractMatches(e,n,r,i){return this.getOrParseAndFindMatches(e,n,r,i)}async getOrParseInjectionRegions(e,n,r){let i=Sh(n),o=`${e}:${r.hostLanguage}:${i}`,s,a=this.astCache.get(o);if(a)s=a.sgRoot;else{s=await(0,pd.parseAsync)(r.hostLanguage,n);let l=n.length*2,E={sgRoot:s,path:e,contentHash:i,estimatedSize:l,parsedAt:Date.now()};this.astCache.set(o,E)}let c=s.root().findAll({rule:r.rule,language:r.hostLanguage});if(c.length===0)return[];let u=[];for(let l of c){let E=l.children(),d=null;for(let R of E)if(r.contentNodeKinds.includes(R.kind())){d=R;break}if(!d)continue;let T=d.text(),S=d.range(),p=S.start.line,f=S.start.column;d.kind()==="raw_text"&&T.startsWith(`
|
|
179
|
+
`)}var UO=class{environment;language;astCache;constructor(e,n){this.environment=e,this.language=n,this.astCache=new bO({max:50,maxSize:1e8,sizeCalculation:r=>Math.max(1,r.estimatedSize),dispose:(r,i)=>{r.sgRoot=void 0}})}getCacheKey(e,n){return`${e}:${this.language}:${n}`}async getOrParseAndFindMatches(e,n,r,i){let o=Sh(n),s=this.getCacheKey(e,o),a,c=this.astCache.get(s);if(c)a=c.sgRoot;else{a=await(0,pd.parseAsync)(this.language,n);let d=n.length*2,T={sgRoot:a,path:e,contentHash:o,estimatedSize:d,parsedAt:Date.now()};this.astCache.set(s,T)}let u=a.root().findAll({rule:r,language:this.language,constraints:i});if(u.length===0)return[];let l=Sh(n);return u.map(d=>{let T=d.range(),S=d.text(),p=this.generateFingerprintString(d,n),f={file:{path:e,sha:l},text:S,range:{start:{line:T.start.line,column:T.start.column,index:T.start.index},end:{line:T.end.line,column:T.end.column,index:T.end.index}},language:this.language,fingerprint:p};return fV(f)})}clearCache(){this.astCache.clear()}getCacheStats(){return{size:this.astCache.size,calculatedSize:this.astCache.calculatedSize||0}}async findMatches(e,n){if(e.length===0)return[];let{rule:r,constraints:i}=n,o=this.getBatchSize(),s=[];for(let a=0;a<e.length;a+=o){let c=e.slice(a,a+o),u=await this.processBatch(c,r,i);s.push(...u)}return s}getBatchSize(){let e=parseInt(process.env.UV_THREADPOOL_SIZE||"4",10);return Math.max(2,Math.floor(e/2))}async processBatch(e,n,r){let i=e.map(async s=>{let{path:a,content:c}=s,u=Eot.extname(a).slice(1),l=tO(this.language,u);return l&&Gx(u)?await this.processInjectedLanguageFile(a,c,l,n,r):this.parseAndExtractMatches(a,c,n,r)});return(await Promise.all(i)).flat()}parseAndExtractMatches(e,n,r,i){return this.getOrParseAndFindMatches(e,n,r,i)}async getOrParseInjectionRegions(e,n,r){let i=Sh(n),o=`${e}:${r.hostLanguage}:${i}`,s,a=this.astCache.get(o);if(a)s=a.sgRoot;else{s=await(0,pd.parseAsync)(r.hostLanguage,n);let l=n.length*2,E={sgRoot:s,path:e,contentHash:i,estimatedSize:l,parsedAt:Date.now()};this.astCache.set(o,E)}let c=s.root().findAll({rule:r.rule,language:r.hostLanguage});if(c.length===0)return[];let u=[];for(let l of c){let E=l.children(),d=null;for(let R of E)if(r.contentNodeKinds.includes(R.kind())){d=R;break}if(!d)continue;let T=d.text(),S=d.range(),p=S.start.line,f=S.start.column;d.kind()==="raw_text"&&T.startsWith(`
|
|
180
180
|
`)&&(T=T.slice(1),p+=1,f=0),u.push({extractedContent:T,lineOffset:p,columnOffset:f})}return u}async processInjectedLanguageFile(e,n,r,i,o){let s=await this.getOrParseInjectionRegions(e,n,r);if(s.length===0)return[];let a=[],c=Sh(n);for(let u of s){let{extractedContent:l,lineOffset:E,columnOffset:d}=u,S=(await(0,pd.parseAsync)(r.language,l)).root().findAll({rule:i,language:r.language,constraints:o});for(let p of S){let f=p.range(),R=p.text(),O=this.generateFingerprintString(p,n),N={start:{line:f.start.line+E,column:f.start.line===0?f.start.column+d:f.start.column,index:f.start.index},end:{line:f.end.line+E,column:f.end.line===0?f.end.column+d:f.end.column,index:f.end.index}},C={file:{path:e,sha:c},text:R,range:N,language:r.language,fingerprint:O};a.push(fV(C))}}return a}static async validateSchema(e,n,r){let{rule:i,constraints:o}=n;if(!i)return{isValid:!1,error:"Schema must include a 'rule' field"};if(r)try{(await(0,pd.parseAsync)(e,r)).root().findAll({rule:i,constraints:o})}catch(s){return{isValid:!1,error:`Failed to parse ast-grep schema: ${s instanceof Error?s.message:"Unknown error"}`}}return{isValid:!0}}static async validateFile(e,n){let r=bc(e);if(r.length===0||r[0]==="Unknown")return{isValid:!0};try{await q8(e,n,"ast",!1,!0)}catch(i){return{isValid:!1,error:`Invalid test file: ${i instanceof Error?i.message:"Unknown error"}`}}return{isValid:!0}}generateFingerprintString(e,n){let r=z8(e);return K8(r)}static async findNodes(e,n,r){let{rule:i,constraints:o}=r;return(await(0,pd.parseAsync)(e,n)).root().findAll({rule:i,language:e,constraints:o})}};import{spawn as J8}from"child_process";import dot from"path";var xO=class{environment;ripgrepPath;constructor(e){this.environment=e,this.ripgrepPath=dh()}async findMatches(e,n){if(e.length===0)return[];let r=e.filter(E=>{let d=bc(E.path);return d.length===1&&(d[0]==="Unknown"||d[0]==="GraphQL")});if(r.length===0)return[];let{rule:i,context:o}=n,s=i.multiline!==void 0?i.multiline:!0,a=[];if(i.any)for(let E of i.any)for(let d of r){let T=await this.executePattern(E.pattern,d.content,d.path,o,s);a.push(...T)}else{let{pattern:E}=i;for(let d of r){let T=await this.executePattern(E,d.content,d.path,o,s);a.push(...T)}}let c=[],u=new Map,l=new Map;for(let E of a){let d=dot.resolve(this.environment.getWorkspaceRoot(),E.file),T=u.get(E.file);T||(T=await DO(d),u.set(E.file,T));let S=l.get(E.file);S||(S=r.find(G=>G.path===E.file)?.content||"",l.set(E.file,S));let p=this.calculateByteOffset(S,E.line,E.column),f=E.text.split(`
|
|
181
181
|
`),R=E.line+f.length-1,O=f[f.length-1].length,N=f.length===1?E.column+E.text.length:O+1,C=this.calculateByteOffset(S,R,N);c.push({file:{path:E.file,sha:T},text:E.text,range:{start:{line:E.line,column:E.column,index:p},end:{line:R,column:N,index:C}},language:"Unknown"})}return c.sort((E,d)=>E.file.path!==d.file.path?E.file.path.localeCompare(d.file.path):E.range.start.line!==d.range.start.line?E.range.start.line-d.range.start.line:E.range.start.column-d.range.start.column),c}static async validateSchema(e){let{rule:n}=e;if(!n||!n.pattern&&!n.any)return{isValid:!1,error:"Schema must include a 'rule' object with either a 'pattern' or 'any' field"};if(n.pattern&&n.any)return{isValid:!1,error:"Schema must have either 'pattern' or 'any', but not both"};let r=dh(),i=async o=>await new Promise(s=>{let a=J8(r,["--json","--no-config","--pcre2","-U","--multiline-dotall",o,"/dev/null"],{stdio:["ignore","pipe","pipe"]}),c="";a.stderr?.on("data",u=>{c+=u.toString()}),a.on("close",u=>{s(u===0||u===1?{isValid:!0}:{isValid:!1,error:c.trim()})}),a.on("error",u=>{s({isValid:!1,error:u.message})})});if(n.any){for(let o=0;o<n.any.length;o++){let s=n.any[o],a=await i(s.pattern);if(!a.isValid)return{isValid:!1,error:`Pattern ${o+1} in 'any' array is invalid: ${a.error}`}}return{isValid:!0}}else return await i(n.pattern)}async executePattern(e,n,r,i,o=!0){let s=["--no-config","--json","--pcre2"];return o&&(s.push("-U"),s.push("--multiline-dotall")),i!==void 0&&i>0&&s.push("-C",i.toString()),s.push(e),await new Promise((a,c)=>{let u=J8(this.ripgrepPath,s,{shell:!1,stdio:["pipe","pipe","pipe"],env:{LANG:"C",RIPGREP_CONFIG_PATH:""}}),l="",E="";u.stdout?.on("data",T=>{l+=T.toString()}),u.stderr?.on("data",T=>{E+=T.toString()});let d=setTimeout(()=>{u.kill("SIGTERM"),c(new Error("Ripgrep search operation timed out"))},3e4);u.on("close",T=>{if(clearTimeout(d),T===0||T===1){let S=this.parseRipgrepOutput(l,r);a(S)}else c(new Error(`Ripgrep exited with code ${T}: ${E}`))}),u.on("error",T=>{clearTimeout(d),c(T)}),u.stdin?.write(n),u.stdin?.end()})}calculateByteOffset(e,n,r){let i=e.split(`
|
|
182
182
|
`),o=0;for(let s=0;s<n-1&&s<i.length;s++)o+=Buffer.byteLength(i[s],"utf8")+1;if(n-1<i.length){let a=i[n-1].substring(0,r-1);o+=Buffer.byteLength(a,"utf8")}return o}parseRipgrepOutput(e,n){if(!e.trim())return[];let r=[],i=e.trim().split(`
|