import{n as e}from"./chunk-DR8-3Aex.js";import{_ as t,h as n}from"./debug-otxXY3j-.js";import{n as r,t as i}from"./cwd--iizewsn.js";import{o as a,s as o}from"./log-DSV4Ht5l.js";import{n as s,t as c}from"./index.min-BNgJ2wVD.js";import{i as l,n as u}from"./path-BE28AJwZ.js";import{basename as d,dirname as f,join as p,sep as m}from"path";function h(e,t){if(!e)return{directory:t||i(),prefix:``};let n=u(e,t);return e.endsWith(`/`)||e.endsWith(m)?{directory:n,prefix:``}:{directory:f(n),prefix:d(e)}}async function g(e){let t=C.get(e);if(t)return t;try{let t=(await n().readdir(e)).filter(e=>e.isDirectory()&&!e.name.startsWith(`.`)).map(t=>({name:t.name,path:p(e,t.name),type:`directory`})).slice(0,100);return C.set(e,t),t}catch(e){return o(e),[]}}async function _(e,t={}){let{basePath:n=i(),maxResults:r=10}=t,{directory:a,prefix:o}=h(e,n),s=await g(a),c=o.toLowerCase();return s.filter(e=>e.name.toLowerCase().startsWith(c)).slice(0,r).map(e=>({id:e.path,displayText:e.name+`/`,description:`directory`,metadata:{type:`directory`}}))}function v(e){return e.startsWith(`~/`)||e.startsWith(`/`)||e.startsWith(`./`)||e.startsWith(`../`)||e===`~`||e===`.`||e===`..`}async function y(e,t=!1){let r=`${e}:${t}`,i=w.get(r);if(i)return i;try{let i=(await n().readdir(e)).filter(e=>t||!e.name.startsWith(`.`)).map(t=>({name:t.name,path:p(e,t.name),type:t.isDirectory()?`directory`:`file`})).sort((e,t)=>e.type===`directory`&&t.type!==`directory`?-1:e.type!==`directory`&&t.type===`directory`?1:e.name.localeCompare(t.name)).slice(0,100);return w.set(r,i),i}catch(e){return o(e),[]}}async function b(e,t={}){let{basePath:n=i(),maxResults:r=10,includeFiles:a=!0,includeHidden:o=!1}=t,{directory:s,prefix:c}=h(e,n),l=await y(s,o),u=c.toLowerCase(),d=l.filter(e=>!a&&e.type===`file`?!1:e.name.toLowerCase().startsWith(u)).slice(0,r),f=e.includes(`/`)||e.includes(m),p=``;if(f){let t=e.lastIndexOf(`/`),n=e.lastIndexOf(m),r=Math.max(t,n);p=e.substring(0,r+1)}return(p.startsWith(`./`)||p.startsWith(`.`+m))&&(p=p.slice(2)),d.map(e=>{let t=p+e.name;return{id:t,displayText:e.type===`directory`?t+`/`:t,metadata:{type:e.type}}})}var x,S,C,w,T=e((()=>{s(),r(),t(),a(),l(),x=500,S=300*1e3,C=new c({max:x,ttl:S}),w=new c({max:x,ttl:S})}));export{v as i,b as n,T as r,_ as t};