import{_ma as q}from"./cli-0.5.4-aacw1src.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.4-xpmr28j4.mjs"),import("./doctorDiagnostic-0.5.4-m74xefn5.mjs"),import("./autoUpdater-0.5.4-74s1mx3n.mjs"),import("./debug-0.5.4-3xeyrs5f.mjs"),import("./envUtils-0.5.4-p0fpzpvm.mjs"),import("./errors-0.5.4-18sh0as6.mjs"),import("./latestVersionCache-0.5.4-qvyfjmn9.mjs"),import("./settings-0.5.4-3hjb0838.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.4";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.4-whfz2j69.mjs"),{logForDebugging:$}=await import("./debug-0.5.4-3xeyrs5f.mjs");Z(Q),$(`startup-update: unhandled error, continuing: ${Q}`)}catch{}}}export{j as runStartupUpdateCheck,_ as isCrossMajor,b as getEarlySkipReason};
