import{Yma as q}from"./cli-0.5.3-0df3r78b.mjs";import{mkdir as A,readFile as I,writeFile as x}from"node:fs/promises";import{join as N}from"node:path";var O=21600000,P=3000,R=new Set(["update","upgrade","install","doctor","completion","mcp"]),C=new Set(["--help","-h","--version","-v","-V"]),M=/[/\\]_npx[/\\]/,H=/^(\d+)\./;function _(Y,Q){let Z=Y.match(H),$=Q.match(H);if(!Z||!$)return!1;return Z[1]!==$[1]}function b(Y){if(process.env.CLAUDIO_SKIP_STARTUP_UPDATE==="1")return"env-skip";if(!process.stdout.isTTY)return"not-tty";if(Y[0]&&R.has(Y[0]))return"subcommand";if(Y.some((Q)=>C.has(Q)))return"flag";if(typeof process.argv[1]==="string"&&M.test(process.argv[1]))return"npx";return null}async function j(Y){try{if(b(Y))return;let[{isAutoUpdaterDisabled:Q},{getCurrentInstallationType:Z},{getLatestVersion:$},{logForDebugging:B},{getClaudioConfigHomeDir:W},{isENOENT:X},{writeLatestVersion:V},{getInitialSettings:y}]=await Promise.all([import("./config-0.5.3-36ecyxr9.mjs"),import("./doctorDiagnostic-0.5.3-wt72zr5s.mjs"),import("./autoUpdater-0.5.3-tj03fm4s.mjs"),import("./debug-0.5.3-emcz7a0x.mjs"),import("./envUtils-0.5.3-d9a55afw.mjs"),import("./errors-0.5.3-mcx25nxh.mjs"),import("./latestVersionCache-0.5.3-2cv3qwvm.mjs"),import("./settings-0.5.3-7avwv0f2.mjs")]);if(Q())return;let J=await Z();if(J==="development"){B(`startup-update: skipping for installType=${J}`);return}let K=()=>N(W(),"last-update-check"),L=async()=>{if(process.env.CLAUDIO_FORCE_UPDATE_CHECK==="1")return!1;try{let z=await I(K(),"utf8"),G=Number.parseInt(z.trim(),10);if(!Number.isFinite(G))return!1;return Date.now()-G<O}catch(z){if(X(z))return!1;return B(`[startup-update] throttle read failed: ${String(z)}`),!1}},U=async()=>{let z=K();try{await x(z,String(Date.now()),"utf8")}catch(G){if(X(G)){try{await A(W(),{recursive:!0}),await x(z,String(Date.now()),"utf8")}catch(w){B(`startup-update: failed to record timestamp: ${w}`)}return}B(`startup-update: failed to record timestamp: ${G}`)}};if(await L())return;let m=y()?.autoUpdatesChannel??"latest",k="0.5.3";if(!k)return;let f=await $(m,{timeoutMs:P});if(!f)return;await U();try{await V({latest:f,checkedAt:Date.now(),current:k})}catch(z){B(`startup-update: failed to persist cache: ${z}`)}}catch(Q){try{let{logError:Z}=await import("./log-0.5.3-yt87q62h.mjs"),{logForDebugging:$}=await import("./debug-0.5.3-emcz7a0x.mjs");Z(Q),$(`startup-update: unhandled error, continuing: ${Q}`)}catch{}}}export{j as runStartupUpdateCheck,_ as isCrossMajor,b as getEarlySkipReason};
