import{TP as L,UP as qq,bi as Y,di as t,jE as f,mE as F,pE as e,sh as E,th as o}from"./cli-0.5.4-k5fz4zd3.mjs";import"./cli-0.5.4-wbqf44ym.mjs";import"./cli-0.5.4-9ewg9gfs.mjs";import"./cli-0.5.4-we3mspgg.mjs";import"./cli-0.5.4-jzhazry0.mjs";import"./cli-0.5.4-82sw3hrw.mjs";import"./cli-0.5.4-31v143kt.mjs";import"./cli-0.5.4-1cy7wd6s.mjs";import"./cli-0.5.4-5e0pk96f.mjs";import"./cli-0.5.4-z154a7bp.mjs";import"./cli-0.5.4-ng5p0zjs.mjs";import"./cli-0.5.4-5hp7ks3t.mjs";import"./cli-0.5.4-8hdwp78f.mjs";import"./cli-0.5.4-mr9aznxx.mjs";import{BS as i,PS as G,US as D,VS as l,xS as O,yS as b}from"./cli-0.5.4-jevfk5q7.mjs";import"./cli-0.5.4-27dzbzdy.mjs";import"./cli-0.5.4-a5bkdqqb.mjs";import"./cli-0.5.4-j2hnw539.mjs";import"./cli-0.5.4-9w59nnw4.mjs";import"./cli-0.5.4-z5d3q8kh.mjs";import"./cli-0.5.4-c0r12dqp.mjs";import"./cli-0.5.4-kqh172jk.mjs";import"./cli-0.5.4-vv4jbgkc.mjs";import{JW as w,PW as h}from"./cli-0.5.4-s7k1f0wc.mjs";import"./cli-0.5.4-0h0yz2k5.mjs";import"./cli-0.5.4-942dm5q1.mjs";import{iY as v,lY as a}from"./cli-0.5.4-rcmp5h4y.mjs";import"./cli-0.5.4-xdcww3x8.mjs";import"./cli-0.5.4-fq32ny1h.mjs";import"./cli-0.5.4-h1m67ngp.mjs";import"./cli-0.5.4-49erze3e.mjs";import"./cli-0.5.4-jytjks37.mjs";import"./cli-0.5.4-mn22gk7g.mjs";import"./cli-0.5.4-5t3jj85n.mjs";import"./cli-0.5.4-5shjmmkz.mjs";import"./cli-0.5.4-zb412kkm.mjs";import"./cli-0.5.4-prfn3sxd.mjs";import"./cli-0.5.4-6xmgebmk.mjs";import"./cli-0.5.4-vjgejcrz.mjs";import"./cli-0.5.4-jqt00ywx.mjs";import"./cli-0.5.4-9e7rkd8e.mjs";import{X3 as X,Y3 as r}from"./cli-0.5.4-jp4wtw87.mjs";import"./cli-0.5.4-hambpq58.mjs";import"./cli-0.5.4-syvgmg9g.mjs";import"./cli-0.5.4-w8ttefr5.mjs";import"./cli-0.5.4-j7kkqxv6.mjs";import"./cli-0.5.4-qrwczx7j.mjs";import"./cli-0.5.4-v2z6p9td.mjs";import{Eaa as U,Haa as j,J$ as M,J6 as T,R6 as P,T$ as g,T6 as S,_aa as n}from"./cli-0.5.4-cbq01zg3.mjs";import"./cli-0.5.4-37v5fhf1.mjs";import"./cli-0.5.4-7grzwf6q.mjs";import"./cli-0.5.4-9qmek5dq.mjs";import"./cli-0.5.4-9c6r1fjg.mjs";import"./cli-0.5.4-2dw33ms6.mjs";import"./cli-0.5.4-x1fzfxmm.mjs";import"./cli-0.5.4-e822fzaq.mjs";import{Nea as x,Pea as s}from"./cli-0.5.4-09dvrzcr.mjs";import{Pfa as Q,Sfa as N}from"./cli-0.5.4-end8wj9r.mjs";import{Ufa as q,Yfa as c}from"./cli-0.5.4-4x206j04.mjs";import{$fa as y,mga as p}from"./cli-0.5.4-yd3rd9qt.mjs";import{Nga as k}from"./cli-0.5.4-sgcaw17t.mjs";import"./cli-0.5.4-jmc3bzbn.mjs";import"./cli-0.5.4-959vxhhb.mjs";import"./cli-0.5.4-aacw1src.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.4
`);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.4",W))q(`Update available: ${"0.5.4"} → ${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.4",W))q(`Update available: ${"0.5.4"} → ${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.4",W))q(`Update available: ${"0.5.4"} → ${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.4")q(X.green("Claudio is up to date (0.5.4)")+`
`);else q(X.green(`Successfully updated from 0.5.4 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.4")q(X.green("Claudio is up to date (0.5.4)")+`
`),await Y(0);q(`New version available: ${z} (current: 0.5.4)
`),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.4 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};
