import{RP as L,SP as qq,ai as Y,ci as t,hE as f,kE as F,nE as e,sh as E,th as o}from"./cli-0.5.3-jbzr8k4s.mjs";import"./cli-0.5.3-me9jkw92.mjs";import"./cli-0.5.3-bqmztzjc.mjs";import"./cli-0.5.3-ytqxzjff.mjs";import"./cli-0.5.3-h6n812td.mjs";import"./cli-0.5.3-hg8c6qbh.mjs";import"./cli-0.5.3-39jr2yrx.mjs";import"./cli-0.5.3-42e2paz8.mjs";import"./cli-0.5.3-mn45xfck.mjs";import"./cli-0.5.3-m884a3pk.mjs";import"./cli-0.5.3-4f9xxrem.mjs";import"./cli-0.5.3-gr8nsa2k.mjs";import"./cli-0.5.3-yj9nbd9d.mjs";import"./cli-0.5.3-55kd38ff.mjs";import{NS as G,SS as D,TS as l,vS as O,wS as b,zS as i}from"./cli-0.5.3-e6bjcfwg.mjs";import"./cli-0.5.3-4dbxtwh3.mjs";import"./cli-0.5.3-m0kfmb79.mjs";import"./cli-0.5.3-8zq9vdtg.mjs";import"./cli-0.5.3-vmx7agj7.mjs";import"./cli-0.5.3-h8xs2818.mjs";import"./cli-0.5.3-wcx7cnw5.mjs";import"./cli-0.5.3-9zbakvbf.mjs";import"./cli-0.5.3-hx550gz2.mjs";import{HW as w,NW as h}from"./cli-0.5.3-842pf3t4.mjs";import"./cli-0.5.3-wxead1ct.mjs";import"./cli-0.5.3-s1hz35ye.mjs";import{gY as v,jY as a}from"./cli-0.5.3-g0svn6bx.mjs";import"./cli-0.5.3-sfdh3pkx.mjs";import"./cli-0.5.3-d8tjnxcj.mjs";import"./cli-0.5.3-6zfw1732.mjs";import"./cli-0.5.3-ptjdgcsy.mjs";import"./cli-0.5.3-tp3jye12.mjs";import"./cli-0.5.3-vqmxwet2.mjs";import"./cli-0.5.3-rch86nhn.mjs";import"./cli-0.5.3-zg2apr51.mjs";import"./cli-0.5.3-ngnshpb7.mjs";import"./cli-0.5.3-e58xste9.mjs";import"./cli-0.5.3-6163zevg.mjs";import"./cli-0.5.3-jmkkd5ph.mjs";import"./cli-0.5.3-1vt6twff.mjs";import"./cli-0.5.3-7017ez65.mjs";import{V3 as X,W3 as r}from"./cli-0.5.3-ea94acj4.mjs";import"./cli-0.5.3-3k22nqvy.mjs";import"./cli-0.5.3-63q4g3zt.mjs";import"./cli-0.5.3-dyhbm5kp.mjs";import"./cli-0.5.3-vpcrbd8n.mjs";import"./cli-0.5.3-jdw3ajfv.mjs";import"./cli-0.5.3-qg4a557t.mjs";import{Caa as U,Faa as j,H$ as M,H6 as T,P6 as P,R$ as g,R6 as S,Yaa as n}from"./cli-0.5.3-t65dek0m.mjs";import"./cli-0.5.3-kavpx97n.mjs";import"./cli-0.5.3-9bdwhdys.mjs";import"./cli-0.5.3-ttc72eq3.mjs";import"./cli-0.5.3-g75gdzrp.mjs";import"./cli-0.5.3-1rg2r7n7.mjs";import"./cli-0.5.3-6j2jk6dt.mjs";import"./cli-0.5.3-66650sba.mjs";import{Lea as x,Nea as s}from"./cli-0.5.3-9vh3vpap.mjs";import{Nfa as Q,Qfa as N}from"./cli-0.5.3-n3cxyxpg.mjs";import{Sfa as q,Wfa as c}from"./cli-0.5.3-kbvzmaax.mjs";import{Zfa as y,kga as p}from"./cli-0.5.3-7wdgps7z.mjs";import{Lga as k}from"./cli-0.5.3-c8bcrqa4.mjs";import"./cli-0.5.3-qrvd6cmy.mjs";import"./cli-0.5.3-2dk1sk8w.mjs";import"./cli-0.5.3-0df3r78b.mjs";r();s();l();import{homedir as d}from"os";import{dirname as Zq,join as B}from"path";w();h();N();p();k();S();T();function u(){let K=process.env.SHELL||"",J=d(),_=y();if(K.endsWith("/zsh")||K.endsWith("/zsh.exe")){let Z=B(_,"completion.zsh");return{name:"zsh",rcFile:B(J,".zshrc"),cacheFile:Z,completionLine:`[[ -f "${Z}" ]] && source "${Z}"`,shellFlag:"zsh"}}if(K.endsWith("/bash")||K.endsWith("/bash.exe")){let Z=B(_,"completion.bash");return{name:"bash",rcFile:B(J,".bashrc"),cacheFile:Z,completionLine:`[ -f "${Z}" ] && source "${Z}"`,shellFlag:"bash"}}if(K.endsWith("/fish")||K.endsWith("/fish.exe")){let Z=process.env.XDG_CONFIG_HOME||B(J,".config"),R=B(_,"completion.fish");return{name:"fish",rcFile:B(Z,"fish","config.fish"),cacheFile:R,completionLine:`[ -f "${R}" ] && source "${R}"`,shellFlag:"fish"}}return null}async function C(){let K=u();if(!K)return;Q(`update: Regenerating ${K.name} completion cache`);let J=process.argv[1]||"claude";if((await P(J,["completion",K.shellFlag,"--output",K.cacheFile],{timeout:5000,preserveOutputOnError:!0,useCwd:!0,stdin:"ignore"})).code!==0){Q(`update: Failed to regenerate ${K.name} completion cache`);return}Q(`update: Regenerated ${K.name} completion cache at ${K.cacheFile}`)}n();N();qq();t();i();e();o();c();a();g();async function fq(){x("tengu_update_check",{}),q(`Current version: 0.5.3
`);let K=M()?.autoUpdatesChannel??"latest";q(`Checking for updates to ${K} version...
`),Q("update: Starting update check"),Q("update: Running diagnostic");let J=await L();if(Q(`update: Installation type: ${J.installationType}`),Q(`update: Config install method: ${J.configInstallMethod}`),J.multipleInstallations.length>1){q(`
`),q(X.yellow("Warning: Multiple installations found")+`
`);for(let A of J.multipleInstallations){let W=J.installationType===A.type?" (currently running)":"";q(`- ${A.type} at ${A.path}${W}
`)}}if(J.warnings.length>0){q(`
`);for(let A of J.warnings)Q(`update: Warning detected: ${A.issue}`),Q(`update: Showing warning: ${A.issue}`),q(X.yellow(`Warning: ${A.issue}
`)),q(X.bold(`Fix: ${A.fix}
`))}let _=j();if(!_.installMethod&&J.installationType!=="package-manager"){q(`
`),q(`Updating configuration to track installation method...
`);let A="unknown";switch(J.installationType){case"npm-local":A="local";break;case"native":A="native";break;case"npm-global":A="global";break;default:A="unknown"}U((W)=>({...W,installMethod:A})),q(`Installation method set to: ${A}
`)}if(J.installationType==="development")q(`
`),q(X.yellow("You are running a development build — auto-update is unavailable.")+`
`),q(`To update, pull the latest source and rebuild:
`),q(X.bold("  git pull && bun install && bun run build")+`
`),q(`
`),q(`Or reinstall from npm:
`),q(X.bold("  npm install -g @claudiolabs/claudio@latest")+`
`),await Y(0);if(J.installationType==="package-manager"){let A=await E();if(q(`
`),A==="homebrew"){q(`Claude is managed by Homebrew.
`);let W=await G(K);if(W&&!v("0.5.3",W))q(`Update available: ${"0.5.3"} → ${W}
`),q(`
`),q(`To update, run:
`),q(X.bold("  brew upgrade claude-code")+`
`);else q(`Claude is up to date!
`)}else if(A==="winget"){q(`Claude is managed by winget.
`);let W=await G(K);if(W&&!v("0.5.3",W))q(`Update available: ${"0.5.3"} → ${W}
`),q(`
`),q(`To update, run:
`),q(X.bold("  winget upgrade Anthropic.ClaudeCode")+`
`);else q(`Claude is up to date!
`)}else if(A==="apk"){q(`Claude is managed by apk.
`);let W=await G(K);if(W&&!v("0.5.3",W))q(`Update available: ${"0.5.3"} → ${W}
`),q(`
`),q(`To update, run:
`),q(X.bold("  apk upgrade claude-code")+`
`);else q(`Claude is up to date!
`)}else q(`Claude is managed by a package manager.
`),q(`Please use your package manager to update.
`);await Y(0)}if(_.installMethod&&J.configInstallMethod!=="not set"&&J.installationType!=="package-manager"){let{installationType:A,configInstallMethod:W}=J,V={"npm-local":"local","npm-global":"global",native:"native",development:"development",unknown:"unknown"}[A]||A;if(V!==W&&W!=="unknown")q(`
`),q(X.yellow("Warning: Configuration mismatch")+`
`),q(`Config expects: ${W} installation
`),q(`Currently running: ${A}
`),q(X.yellow(`Updating the ${A} installation you are currently using`)+`
`),U((m)=>({...m,installMethod:V})),q(`Config updated to reflect current installation method: ${V}
`)}if(J.installationType==="native"){Q("update: Detected native installation, using native updater");try{let A=await f(K,!0);if(A.lockFailed){let W=A.lockHolderPid?` (PID ${A.lockHolderPid})`:"";q(X.yellow(`Another Claude process${W} is currently running. Please try again in a moment.`)+`
`),await Y(0)}if(!A.latestVersion)process.stderr.write(`Failed to check for updates
`),await Y(1);if(A.latestVersion==="0.5.3")q(X.green("Claudio is up to date (0.5.3)")+`
`);else q(X.green(`Successfully updated from 0.5.3 to version ${A.latestVersion}`)+`
`),await C();await Y(0)}catch(A){process.stderr.write(`Error: Failed to install native update
`),process.stderr.write(String(A)+`
`),process.stderr.write(`Try running "claude doctor" for diagnostics
`),await Y(1)}}if(_.installMethod!=="native")await F();Q("update: Checking npm registry for latest version"),Q("update: Package URL: @claudiolabs/claudio"),Q(`update: Running: ${`npm view @claudiolabs/claudio@${K==="stable"?"stable":"latest"} version`}`);let z=await G(K);if(Q(`update: Latest version from npm: ${z||"FAILED"}`),!z){if(Q("update: Failed to get latest version from npm registry"),process.stderr.write(X.red("Failed to check for updates")+`
`),process.stderr.write(`Unable to fetch latest version from npm registry
`),process.stderr.write(`
`),process.stderr.write(`Possible causes:
`),process.stderr.write(`  • Network connectivity issues
`),process.stderr.write(`  • npm registry is unreachable
`),process.stderr.write(`  • Corporate proxy/firewall blocking npm
`),!"@claudiolabs/claudio".startsWith("@anthropic"))process.stderr.write(`  • Internal/development build not published to npm
`);process.stderr.write(`
`),process.stderr.write(`Try:
`),process.stderr.write(`  • Check your internet connection
`),process.stderr.write(`  • Run with --debug flag for more details
`);let A="@claudiolabs/claudio";process.stderr.write(`  • Manually check: npm view ${A} version
`),process.stderr.write(`  • Check if you need to login: npm whoami
`),await Y(1)}if(z==="0.5.3")q(X.green("Claudio is up to date (0.5.3)")+`
`),await Y(0);q(`New version available: ${z} (current: 0.5.3)
`),q(`Installing update...
`);let $=!1,H="";switch(J.installationType){case"npm-local":$=!0,H="local";break;case"npm-global":$=!1,H="global";break;case"unknown":{let A=await b();$=A,H=A?"local":"global",q(X.yellow("Warning: Could not determine installation type")+`
`),q(`Attempting ${H} update based on file detection...
`);break}default:process.stderr.write(`Error: Cannot update ${J.installationType} installation
`),await Y(1)}q(`Using ${H} installation update method...
`),Q(`update: Update method determined: ${H}`),Q(`update: useLocalUpdate: ${$}`);let I;if($)Q("update: Calling installOrUpdateClaudePackage() for local update"),I=await O(K);else Q("update: Calling installGlobalPackage() for global update"),I=await D();switch(Q(`update: Installation status: ${I}`),I){case"success":q(X.green(`Successfully updated from 0.5.3 to version ${z}`)+`
`),await C();break;case"no_permissions":if(process.stderr.write(`Error: Insufficient permissions to install update
`),$)process.stderr.write(`Try manually updating with:
`),process.stderr.write(`  cd ~/.claudio/local && npm update @claudiolabs/claudio
`);else process.stderr.write(`Try running with sudo or fix npm permissions
`),process.stderr.write(`Or consider using native installation with: claudio install
`);await Y(1);break;case"install_failed":if(process.stderr.write(`Error: Failed to install update
`),$)process.stderr.write(`Try manually updating with:
`),process.stderr.write(`  cd ~/.claudio/local && npm update @claudiolabs/claudio
`);else process.stderr.write(`Or consider using native installation with: claudio install
`);await Y(1);break;case"in_progress":process.stderr.write(`Error: Another instance is currently performing an update
`),process.stderr.write(`Please wait and try again later
`),await Y(1);break}await Y(0)}export{fq as update};
