import{H6 as E,T7 as F,X7 as m,a7 as U,b7 as f,z6 as K}from"./cli-0.5.3-t65dek0m.mjs";import{Xda as v,Yda as g}from"./cli-0.5.3-6j2jk6dt.mjs";import{Dfa as x,zfa as D}from"./cli-0.5.3-n3cxyxpg.mjs";import{Xma as S}from"./cli-0.5.3-0df3r78b.mjs";import{basename as H,dirname as b,join as I,sep as O}from"path";function _(q,B){if(!q)return{directory:B||v(),prefix:""};let G=F(q,B);if(q.endsWith("/")||q.endsWith(O))return{directory:G,prefix:""};let N=b(G),J=H(q);return{directory:N,prefix:J}}async function k(q){let B=Z.get(q);if(B)return B;try{let J=(await D().readdir(q)).filter((M)=>M.isDirectory()&&!M.name.startsWith(".")).map((M)=>({name:M.name,path:I(q,M.name),type:"directory"})).slice(0,100);return Z.set(q,J),J}catch(G){return K(G),[]}}async function P(q,B={}){let{basePath:G=v(),maxResults:N=10}=B,{directory:J,prefix:M}=_(q,G),V=await k(J),z=M.toLowerCase();return V.filter((X)=>X.name.toLowerCase().startsWith(z)).slice(0,N).map((X)=>({id:X.path,displayText:X.name+"/",description:"directory",metadata:{type:"directory"}}))}function o(q){return q.startsWith("~/")||q.startsWith("/")||q.startsWith("./")||q.startsWith("../")||q==="~"||q==="."||q===".."}async function u(q,B=!1){let G=`${q}:${B}`,N=A.get(G);if(N)return N;try{let V=(await D().readdir(q)).filter((z)=>B||!z.name.startsWith(".")).map((z)=>({name:z.name,path:I(q,z.name),type:z.isDirectory()?"directory":"file"})).sort((z,W)=>{if(z.type==="directory"&&W.type!=="directory")return-1;if(z.type!=="directory"&&W.type==="directory")return 1;return z.name.localeCompare(W.name)}).slice(0,100);return A.set(G,V),V}catch(J){return K(J),[]}}async function h(q,B={}){let{basePath:G=v(),maxResults:N=10,includeFiles:J=!0,includeHidden:M=!1}=B,{directory:V,prefix:z}=_(q,G),W=await u(V,M),X=z.toLowerCase(),j=W.filter((Q)=>{if(!J&&Q.type==="file")return!1;return Q.name.toLowerCase().startsWith(X)}).slice(0,N),w=q.includes("/")||q.includes(O),Y="";if(w){let Q=q.lastIndexOf("/"),$=q.lastIndexOf(O),L=Math.max(Q,$);Y=q.substring(0,L+1)}if(Y.startsWith("./")||Y.startsWith("."+O))Y=Y.slice(2);return j.map((Q)=>{let $=Y+Q.name;return{id:$,displayText:Q.type==="directory"?$+"/":$,metadata:{type:Q.type}}})}var R=500,T=300000,Z,A;var C=S(()=>{f();g();x();E();m();Z=new U({max:R,ttl:T}),A=new U({max:R,ttl:T})});
export{P as Rg,o as Sg,h as Tg,C as Ug};
