// @bun
var{defineProperty:T,getOwnPropertyNames:Z,getOwnPropertyDescriptor:_}=Object,$=Object.prototype.hasOwnProperty;function b(j){return this[j]}var R=(j)=>{var q=(W??=new WeakMap).get(j),z;if(q)return q;if(q=T({},"__esModule",{value:!0}),j&&typeof j==="object"||typeof j==="function"){for(var A of Z(j))if(!$.call(q,A))T(q,A,{get:b.bind(j,A),enumerable:!(z=_(j,A))||z.enumerable})}return W.set(j,q),q},W;var D=(j)=>j;function P(j,q){this[j]=D.bind(null,q)}var E=(j,q)=>{for(var z in q)T(j,z,{get:q[z],enumerable:!0,configurable:!0,set:P.bind(q,z)})};var S=(j,q)=>()=>(j&&(q=j(j=0)),q);var w=import.meta.require;import J from"fs";import F from"path";function X(j){try{return J.statSync(j).mtimeMs}catch{return null}}function Q(j,q){let z=Math.max(0,Math.round((q-j)/1000));if(z<60)return`${z}s ago`;if(z<3600)return`${Math.round(z/60)}m ago`;return`${Math.round(z/3600)}h ago`}function u(j,q){try{return globalThis.Bun?.resolveSync(j,q)??null}catch{return null}}function v(j,q="stx"){let z=F.resolve(j);for(let A=0;A<10;A++){let B=F.join(z,"pantry","@stacksjs",q);if(J.existsSync(B))return B;let K=F.dirname(z);if(K===z)break;z=K}return null}async function y(j={}){let q=j.cwd?F.resolve(j.cwd):process.cwd(),z=j.resolve??u,A=Date.now(),B=[],K=z("@stacksjs/stx",q);B.push(K?{name:"@stacksjs/stx resolves to",status:"ok",detail:K}:{name:"@stacksjs/stx resolves to",status:"info",detail:"not resolvable from here (running inside the stx repo, or not installed)"});let U=z("bun-plugin-stx",q);if(U)B.push({name:"bun-plugin-stx resolves to",status:"ok",detail:U});let C=v(q,"stx");if(!C)B.push({name:"pantry",status:"info",detail:"no pantry/@stacksjs/stx found \u2014 standard install (nothing to rebuild)"});else{let H=F.join(C,"src/signals.ts"),I=[F.join(C,"dist/index.js"),F.join(C,"dist/signals.js")].find((G)=>J.existsSync(G))||null,L=X(H),N=I?X(I):null;if(L==null)B.push({name:"pantry dist freshness",status:"info",detail:`found pantry at ${C} but no src/signals.ts to compare`});else if(N==null)B.push({name:"pantry dist freshness",status:"error",detail:"pantry has src but no built dist \u2014 the dev server will resolve nothing (or a stale copy elsewhere)",fix:`cd ${C} && bun build.ts`});else if(N<L){let G=Math.round((L-N)/1000);B.push({name:"pantry dist freshness",status:"error",detail:`dist (${Q(N,A)}) is OLDER than src/signals.ts (${Q(L,A)}) by ${G}s \u2014 your edit isn't built`,fix:`cd ${C} && bun build.ts`})}else B.push({name:"pantry dist freshness",status:"ok",detail:`dist rebuilt after src (src ${Q(L,A)}, dist ${Q(N,A)})`});let V=F.join(q,"node_modules/@stacksjs/stx"),O=null;try{O=J.lstatSync(V)}catch{O=null}if(!O)B.push({name:"node_modules \u2192 pantry",status:"info",detail:"node_modules/@stacksjs/stx not present (not installed here)"});else if(O.isSymbolicLink()){let G=null;try{G=J.realpathSync(V)}catch{}let Y=(()=>{try{return J.realpathSync(C)}catch{return C}})();B.push(G===Y?{name:"node_modules \u2192 pantry",status:"ok",detail:"symlinked to pantry"}:{name:"node_modules \u2192 pantry",status:"warn",detail:`symlinked to ${G||"(dangling)"}, not pantry`})}else B.push({name:"node_modules \u2192 pantry",status:"warn",detail:"is a real directory, NOT symlinked to pantry \u2014 edits to pantry src/dist won't be resolved",fix:"rm -rf node_modules/@stacksjs/stx && ln -s ../../pantry/@stacksjs/stx node_modules/@stacksjs/stx"})}if(B.push({name:"dev runtime cache",status:"info",detail:"cleared automatically on source edits by the dev watcher (clearDevCaches, #1745 item C)"}),j.generateRuntime)try{let I=j.generateRuntime().length;B.push(I>1000?{name:"signals runtime",status:"ok",detail:`generated ${I.toLocaleString()} chars`}:{name:"signals runtime",status:"warn",detail:`generated only ${I} chars \u2014 suspiciously short`})}catch(H){B.push({name:"signals runtime",status:"error",detail:`failed to generate: ${H.message}`})}return{checks:B,ok:!B.some((H)=>H.status==="error")}}function k(j){let q={ok:"\u2713",warn:"\u26A0",error:"\u2717",info:"\xB7"},z=["stx runtime resolution:"];for(let A of j.checks)if(z.push(`  ${q[A.status]} ${A.name}: ${A.detail}`),A.fix)z.push(`     \u2192 ${A.fix}`);return z.push(""),z.push(j.ok?"\u2713 All framework-runtime layers are aligned.":"\u2717 A runtime layer is stale \u2014 see the fixes above."),z.join(`
`)}var x=()=>{};x();export{y as runDoctor,k as formatDoctorReport,v as findPantryPackage};
