import{gE as E,hE as o,lE as f,mE as t,sE as F,vE as L,wO as Y,yE as e,yO as qq}from"./cli-0.5.12-zc0qwdy2.mjs";import"./cli-0.5.12-whfz3xsx.mjs";import"./cli-0.5.12-z100r543.mjs";import{OQ as O,PQ as b,SQ as i,eR as G,jR as D,kR as l}from"./cli-0.5.12-bzab36pn.mjs";import"./cli-0.5.12-pp1549k7.mjs";import"./cli-0.5.12-9mq24qzr.mjs";import"./cli-0.5.12-7repzgzv.mjs";import"./cli-0.5.12-pdqnfqg3.mjs";import"./cli-0.5.12-c2yq69h9.mjs";import"./cli-0.5.12-kez9r81a.mjs";import"./cli-0.5.12-zbcr8cbk.mjs";import"./cli-0.5.12-2wf629mh.mjs";import"./cli-0.5.12-ghtxkxqx.mjs";import"./cli-0.5.12-xg7a0dy4.mjs";import"./cli-0.5.12-s0h788we.mjs";import"./cli-0.5.12-m22yxpb9.mjs";import"./cli-0.5.12-cw1qs4bg.mjs";import"./cli-0.5.12-yq8ds97a.mjs";import"./cli-0.5.12-qew4mzgp.mjs";import"./cli-0.5.12-gwg1e43k.mjs";import"./cli-0.5.12-36swspqa.mjs";import"./cli-0.5.12-4dn79vqp.mjs";import"./cli-0.5.12-f5pfjvdk.mjs";import{qX as w,wX as h}from"./cli-0.5.12-fqp5s15p.mjs";import"./cli-0.5.12-rc1p9wk6.mjs";import"./cli-0.5.12-x479axrj.mjs";import{RY as v,UY as a}from"./cli-0.5.12-ysy6e9rz.mjs";import"./cli-0.5.12-cqv7z22w.mjs";import"./cli-0.5.12-7cn41yy7.mjs";import"./cli-0.5.12-34cd39ve.mjs";import"./cli-0.5.12-m2gh4ewc.mjs";import"./cli-0.5.12-c6whkxmz.mjs";import"./cli-0.5.12-w3hy6c60.mjs";import"./cli-0.5.12-5d3qcvf5.mjs";import"./cli-0.5.12-f141d2qa.mjs";import"./cli-0.5.12-khvy67r3.mjs";import"./cli-0.5.12-pycnjaeg.mjs";import"./cli-0.5.12-8v5w8znc.mjs";import{A4 as g,z4 as X}from"./cli-0.5.12-ctqkj6ve.mjs";import"./cli-0.5.12-cbevkwg4.mjs";import"./cli-0.5.12-w00qj83e.mjs";import"./cli-0.5.12-nbcjwzzn.mjs";import"./cli-0.5.12-3t06hwwh.mjs";import"./cli-0.5.12-057c2cp2.mjs";import"./cli-0.5.12-ecgx5n54.mjs";import{Jaa as U,Jca as S,M$ as M,Maa as j,Q6 as P,S6 as T,W$ as n,eba as r}from"./cli-0.5.12-g4wb8mj2.mjs";import"./cli-0.5.12-vp5smcs1.mjs";import"./cli-0.5.12-y2kq7fe8.mjs";import"./cli-0.5.12-7vxpqr5a.mjs";import"./cli-0.5.12-hvtcdcev.mjs";import"./cli-0.5.12-asbn3d19.mjs";import"./cli-0.5.12-k1crwtdc.mjs";import{dfa as x,ffa as c}from"./cli-0.5.12-2jxq8gnm.mjs";import{fga as Q,iga as N}from"./cli-0.5.12-p5ps8gf0.mjs";import{kga as q,oga as s}from"./cli-0.5.12-hp0508v9.mjs";import{Gga as k}from"./cli-0.5.12-tfdwzg37.mjs";import{Jga as y,Wga as p}from"./cli-0.5.12-60w1a0bs.mjs";import"./cli-0.5.12-c8f4daey.mjs";import"./cli-0.5.12-0qasc0ef.mjs";import"./cli-0.5.12-f8850v2j.mjs";import"./cli-0.5.12-495d826j.mjs";import"./cli-0.5.12-rt0k97yj.mjs";import"./cli-0.5.12-1vyz0tt9.mjs";import"./cli-0.5.12-xzeb7mtb.mjs";g();c();l();import{homedir as d}from"os";import{dirname as Zq,join as B}from"path";w();h();N();p();k();T();S();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}`)}r();N();t();qq();i();e();o();s();a();n();async function fq(){x("tengu_update_check",{}),q(`Current version: 0.5.12
`);let K=M()?.autoUpdatesChannel??"latest";q(`Checking for updates to ${K} version...
`),Q("update: Starting update check"),Q("update: Running diagnostic");let J=await f();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/claudin@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.12",W))q(`Update available: ${"0.5.12"} → ${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.12",W))q(`Update available: ${"0.5.12"} → ${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.12",W))q(`Update available: ${"0.5.12"} → ${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.12")q(X.green("Claudin is up to date (0.5.12)")+`
`);else q(X.green(`Successfully updated from 0.5.12 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 L();Q("update: Checking npm registry for latest version"),Q("update: Package URL: @claudiolabs/claudin"),Q(`update: Running: ${`npm view @claudiolabs/claudin@${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/claudin".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/claudin";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.12")q(X.green("Claudin is up to date (0.5.12)")+`
`),await Y(0);q(`New version available: ${z} (current: 0.5.12)
`),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.12 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 ~/.claudin/local && npm update @claudiolabs/claudin
`);else process.stderr.write(`Try running with sudo or fix npm permissions
`),process.stderr.write(`Or consider using native installation with: claudin 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 ~/.claudin/local && npm update @claudiolabs/claudin
`);else process.stderr.write(`Or consider using native installation with: claudin 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};
