import{In as e,Ln as t}from"./src-Di342QoJ.js";import{l as n,p as r}from"./debug-otxXY3j-.js";import{n as i,o as a}from"./process-DMKLUQIO.js";import{n as o,r as s}from"./execFileNoThrow-azCkYhmF.js";import{SE as c,wE as l}from"./loadAgentsDir-C_wFhytF.js";import{n as u,t as d}from"./distRoot-BNg_iO5-.js";import{join as f}from"node:path";import{execSync as p}from"node:child_process";import{existsSync as m,readFileSync as h}from"node:fs";import{homedir as g}from"node:os";t(),n(),u(),s(),l(),i();var _=`claude-code-best`;function v(){try{let e=f(d,`..`,`package.json`);if(m(e)){let t=JSON.parse(h(e,`utf-8`));if(t.version)return t.version}}catch{}return`2.7.1`}function y(e){try{return p(`which ${e} 2>/dev/null`,{stdio:`pipe`}),!0}catch{return!1}}function b(){return!!(process.execPath.includes(`bun`)||m(f(f(g(),`.bun`,`install`,`global`),`node_modules`,_)))}async function x(){let e=await o(`npm`,[`view`,`${_}@latest`,`version`,`--prefer-online`],{abortSignal:AbortSignal.timeout(1e4),cwd:g()});return e.code===0?e.stdout.trim():(r(`npm view failed: ${e.stderr}`),null)}function S(e,t){let n=e=>e.replace(/^\D/,``).split(`.`).map(Number),r=n(e),i=n(t);for(let e=0;e<3;e++){if((r[e]??0)>(i[e]??0))return!0;if((r[e]??0)<(i[e]??0))return!1}return!0}async function C(){let t=v();a(`Current version: ${t}\n`);let n=y(`bun`),r=b()&&n?`bun`:`npm`;a(`Package manager: ${r}\n`),a(`Checking for updates...
`);let i=await x();if(!i){process.stderr.write(e.red(`Failed to check for updates`)+`
`),process.stderr.write(`Unable to fetch latest version from npm registry.
`),await c(1);return}if(i===t||S(t,i)){a(e.green(`ccb is up to date (${t})`)+`
`),await c(0);return}a(`New version available: ${i} (current: ${t})\n`),a(`Installing update via ${r}...\n`);try{p(r===`bun`?`bun install -g ${_}@latest`:`npm install -g ${_}@latest`,{stdio:`inherit`,cwd:g(),timeout:12e4}),a(e.green(`Successfully updated from ${t} to ${i}`)+`
`)}catch(t){process.stderr.write(e.red(`Update failed`)+`
`),process.stderr.write(`${t}\n`),process.stderr.write(`
`),process.stderr.write(`Try manually updating with:
`),r===`bun`?process.stderr.write(e.bold(`  bun install -g ${_}@latest`)+`
`):process.stderr.write(e.bold(`  npm install -g ${_}@latest`)+`
`),await c(1)}await c(0)}export{C as updateCCB};