import{$u as T,Dz as b,EP as i,Jz as j,OL as f,PL as L,ZL as r,oA as K,qA as I,rA as _,tA as p,xz as P}from"./cli-0.5.3-jbzr8k4s.mjs";import{AR as n,zR as A}from"./cli-0.5.3-mn45xfck.mjs";import{Lea as M,Nea as u}from"./cli-0.5.3-9vh3vpap.mjs";import{Dfa as S,Nfa as Z,Qfa as m,afa as E,cfa as C,zfa as F}from"./cli-0.5.3-n3cxyxpg.mjs";import{Pla as v,gma as c,lia as Y,mia as k}from"./cli-0.5.3-qrvd6cmy.mjs";n();c();r();u();p();P();C();m();S();i();k();import*as H from"path";var d=1000,o=500,l=300,e=2000,h=typeof Bun<"u",x=null,y=null,Q=new Set,B=!1,D=!1,V=!1,X=null,W=Y(),U=null;async function t(){if(B||D)return;if(B=!0,!V)V=!0,_(()=>{f(),W.emit()});let q=await a();if(q.length===0)return;Z(`Watching for changes in skill/command directories: ${q.join(", ")}...`),x=A.watch(q,{persistent:!1,ignoreInitial:!0,depth:2,awaitWriteFinish:{stabilityThreshold:U?.stabilityThreshold??d,pollInterval:U?.pollInterval??o},ignored:(w,z)=>{if(z&&!z.isFile()&&!z.isDirectory())return!0;return w.split(H.sep).some((J)=>J===".git")},ignorePermissionErrors:!0,usePolling:h,interval:U?.chokidarInterval??e,atomic:!0}),x.on("add",$),x.on("change",$),x.on("unlink",$),X=E(async()=>{await g()})}function g(){if(D=!0,X)X(),X=null;let q=Promise.resolve();if(x)q=x.close(),x=null;if(y)clearTimeout(y),y=null;return Q.clear(),W.clear(),q}var s=W.subscribe;async function a(){let q=F(),w=[],z=K("userSettings","skills");if(z)try{await q.stat(z),w.push(z)}catch{}let J=K("userSettings","commands");if(J)try{await q.stat(J),w.push(J)}catch{}let N=K("projectSettings","skills");if(N)try{let G=H.resolve(N);await q.stat(G),w.push(G)}catch{}let O=K("projectSettings","commands");if(O)try{let G=H.resolve(O);await q.stat(G),w.push(G)}catch{}for(let G of v()){let R=H.join(G,".claudio","skills");try{await q.stat(R),w.push(R)}catch{}}return w}function $(q){Z(`Detected skill change: ${q}`),M("tengu_skill_file_changed",{source:"chokidar"}),qq(q)}function qq(q){if(Q.add(q),y)clearTimeout(y);y=setTimeout(async()=>{y=null;let w=[...Q];Q.clear();let z=await j("skills",w[0]);if(b(z)){Z(`ConfigChange hook blocked skill reload (${w.length} paths)`);return}I(),L(),T(),W.emit()},U?.reloadDebounce??l)}async function wq(q){if(x)await x.close(),x=null;if(y)clearTimeout(y),y=null;Q.clear(),W.clear(),B=!1,D=!1,U=q??null}var Zq={initialize:t,dispose:g,subscribe:s,resetForTesting:wq};
export{Zq as cb};
