import{gY as o,jY as yJ}from"./cli-0.5.3-g0svn6bx.mjs";import{Caa as v,H$ as i,H6 as I,Q6 as K,R$ as OJ,R6 as D,Yaa as E,u9 as H,w9 as BJ,z6 as q}from"./cli-0.5.3-t65dek0m.mjs";import{Lea as A,Nea as zJ}from"./cli-0.5.3-9vh3vpap.mjs";import{Dfa as F,Nfa as W,Qfa as XJ,qfa as k,rfa as j,vfa as C,zfa as G}from"./cli-0.5.3-n3cxyxpg.mjs";import{Zfa as O,kga as b}from"./cli-0.5.3-7wdgps7z.mjs";import{Fga as y,Gga as w,Jga as u,Lga as R,uga as l}from"./cli-0.5.3-c8bcrqa4.mjs";import{Xma as M}from"./cli-0.5.3-0df3r78b.mjs";import{access as P,chmod as JJ,writeFile as QJ}from"fs/promises";import{homedir as f}from"os";import{join as B}from"path";function S(){return B(O(),"local")}function YJ(J=f()){return B(J,".claude","local")}function m(J){let Q=J?.homeDir??f(),Y=J?.configHomeDir??O();return Array.from(new Set([B(Y,"local"),YJ(Q)]))}function d(J){return[B(J,"node_modules",".bin","claudio"),B(J,"node_modules",".bin","claude")]}function ZJ(J){let Q=J.replace(/\\+/g,"/");return Q.includes("/.claudio/local/node_modules/")||Q.includes("/.claude/local/node_modules/")}function T(){return B(S(),"claudio")}function DJ(){return ZJ(process.argv[1]||"")}async function L(J,Q,Y){try{return await QJ(J,Q,{encoding:"utf8",flag:"wx",mode:Y}),!0}catch(Z){if(y(Z)==="EEXIST")return!1;throw Z}}async function $J(){try{let J=S();await G().mkdir(J),await L(B(J,"package.json"),k({name:"claudio-local",version:"0.0.1",private:!0},null,2));let Q=T();if(await L(Q,`#!/bin/sh
exec "${J}/node_modules/.bin/claudio" "$@"`,493))await JJ(Q,493);return!0}catch(J){return q(J),!1}}async function EJ(J,Q){try{if(!await $J())return"install_failed";let Z=await K("npm",["install",`@claudiolabs/claudio@${Q?Q:J==="stable"?"stable":"latest"}`],{cwd:S(),maxBuffer:1e6});if(Z.code!==0){let $=Error(`Failed to install Claude CLI package: ${Z.stderr}`);return q($),Z.code===190?"in_progress":"install_failed"}return v(($)=>({...$,installMethod:"local"})),"success"}catch(Y){return q(Y),"install_failed"}}async function PJ(){for(let J of m())for(let Q of d(J))try{return await P(Q),!0}catch{}return!1}async function fJ(){for(let J of m())for(let Q of d(J))try{return await P(Q),J}catch{}return null}function mJ(){let J=process.env.SHELL||"";if(J.includes("zsh"))return"zsh";if(J.includes("bash"))return"bash";if(J.includes("fish"))return"fish";return"unknown"}var p=M(()=>{E();b();R();D();F();I();C()});import{open as qJ,readFile as WJ,stat as KJ}from"fs/promises";import{homedir as h}from"os";import{join as U}from"path";function V(J){let Q=J?.homedir??h(),Z=(J?.env??process.env).ZDOTDIR||Q;return{zsh:U(Z,".zshrc"),bash:U(Q,".bashrc"),fish:U(Q,".config/fish/config.fish")}}function g(J){let Q=!1;return{filtered:J.filter((Z)=>{if(c.test(Z)){let $=Z.match(/alias\s+claude\s*=\s*["']([^"']+)["']/);if(!$)$=Z.match(/alias\s+claude\s*=\s*([^#\n]+)/);if($&&$[1]){if($[1].trim()===T())return Q=!0,!1}}return!0}),hadAlias:Q}}async function x(J){try{return(await WJ(J,{encoding:"utf8"})).split(`
`)}catch(Q){if(u(Q))return null;throw Q}}async function n(J,Q){let Y=await qJ(J,"w");try{await Y.writeFile(Q.join(`
`),{encoding:"utf8"}),await Y.datasync()}finally{await Y.close()}}async function NJ(J){let Q=V(J);for(let Y of Object.values(Q)){let Z=await x(Y);if(!Z)continue;for(let $ of Z)if(c.test($)){let N=$.match(/alias\s+claude=["']?([^"'\s]+)/);if(N&&N[1])return N[1]}}return null}async function nJ(J){let Q=await NJ(J);if(!Q)return null;let Y=J?.homedir??h(),Z=Q.startsWith("~")?Q.replace("~",Y):Q;try{let $=await KJ(Z);if($.isFile()||$.isSymbolicLink())return Q}catch{}return null}var c;var s=M(()=>{R();p();c=/^\s*alias\s+claude\s*=/});import{constants as GJ}from"fs";import{access as HJ,writeFile as a}from"fs/promises";import{homedir as X}from"os";import{join as _J}from"path";function r(){let J=process.argv[1]||"";if(J.includes("/.bun/install/global/"))return!0;let Q=process.env.BUN_INSTALL;if(Q&&J.startsWith(Q))return!0;return!1}async function vJ(){let J=await K("bun",["pm","ls","-g"],{cwd:X()});if(J.code!==0)return!1;return J.stdout.includes("@claudiolabs/claudio")}async function zQ(){}async function BQ(){return}async function OQ(){return}function yQ(J){let Y=i()?.minimumVersion;if(!Y)return!1;let Z=!o(J,Y);if(Z)W(`Skipping update to ${J} - below minimumVersion ${Y}`);return Z}function e(){return _J(O(),".update.lock")}async function wJ(){let J=G(),Q=e();try{let Y=await J.stat(Q);if(Date.now()-Y.mtimeMs<t)return!1;try{let $=await J.stat(Q);if(Date.now()-$.mtimeMs<t)return!1;await J.unlink(Q)}catch($){if(!w($))return q($),!1}}catch(Y){if(!w(Y))return q(Y),!1}try{return await a(Q,`${process.pid}`,{encoding:"utf8",flag:"wx"}),!0}catch(Y){let Z=y(Y);if(Z==="EEXIST")return!1;if(Z==="ENOENT")try{return await J.mkdir(O()),await a(Q,`${process.pid}`,{encoding:"utf8",flag:"wx"}),!0}catch($){if(y($)==="EEXIST")return!1;return q($),!1}return q(Y),!1}}async function MJ(){let J=G(),Q=e();try{if(await J.readFile(Q,{encoding:"utf8"})===`${process.pid}`)await J.unlink(Q)}catch(Y){if(w(Y))return;q(Y)}}async function RJ(){let J=H.isRunningWithBun()||r(),Q=null;if(J)Q=await K("bun",["pm","bin","-g"],{cwd:X()});else Q=await K("npm",["-g","config","get","prefix"],{cwd:X()});if(Q.code!==0)return q(Error(`Failed to check ${J?"bun":"npm"} permissions`)),null;return Q.stdout.trim()}async function SJ(){try{let J=await RJ();if(!J)return{hasPermissions:!1,npmPrefix:null};try{return await HJ(J,GJ.W_OK),{hasPermissions:!0,npmPrefix:J}}catch{return q(new _("Insufficient permissions for global npm install.")),{hasPermissions:!1,npmPrefix:J}}}catch(J){return q(J),{hasPermissions:!1,npmPrefix:null}}}async function GQ(J,Q={}){let Y=J==="stable"?"stable":"latest",Z=Q.timeoutMs??5000,$=await K("npm",["view",`@claudiolabs/claudio@${Y}`,"version","--prefer-online"],{abortSignal:AbortSignal.timeout(Z),cwd:X()});if($.code!==0){if(W(`npm view failed with code ${$.code}`),$.stderr)W(`npm stderr: ${$.stderr.trim()}`);else W("npm stderr: (empty)");if($.stdout)W(`npm stdout: ${$.stdout.trim()}`);return null}return $.stdout.trim()}async function HQ(){let J=await K("npm",["view","@claudiolabs/claudio","dist-tags","--json","--prefer-online"],{abortSignal:AbortSignal.timeout(5000),cwd:X()});if(J.code!==0)return W(`npm view dist-tags failed with code ${J.code}`),{latest:null,stable:null};try{let Q=j(J.stdout.trim());return{latest:typeof Q.latest==="string"?Q.latest:null,stable:typeof Q.stable==="string"?Q.stable:null}}catch(Q){return W(`Failed to parse dist-tags: ${Q}`),{latest:null,stable:null}}}async function _Q(J){return null}async function vQ(){return{latest:null,stable:null}}async function wQ(J){let Y=await K("npm",["view","@claudiolabs/claudio","versions","--json","--prefer-online"],{abortSignal:AbortSignal.timeout(30000),cwd:X()});if(Y.code!==0){if(W(`npm view versions failed with code ${Y.code}`),Y.stderr)W(`npm stderr: ${Y.stderr.trim()}`);return[]}try{return j(Y.stdout.trim()).slice(-J).reverse()}catch(Z){return W(`Failed to parse version history: ${Z}`),[]}}async function MQ(J){if(!await wJ())return q(new _("Another process is currently installing an update")),A("tengu_auto_updater_lock_contention",{pid:process.pid,currentVersion:"99.0.0"}),"in_progress";try{if(await TJ(),!H.isRunningWithBun()&&H.isNpmFromWindowsPath())return q(Error("Windows NPM detected in WSL environment")),A("tengu_auto_updater_windows_npm_in_wsl",{currentVersion:"99.0.0"}),console.error(`
Error: Windows NPM detected in WSL

You're running Claude Code in WSL but using the Windows NPM installation from /mnt/c/.
This configuration is not supported for updates.

To fix this issue:
  1. Install Node.js within your Linux distribution: e.g. sudo apt install nodejs npm
  2. Make sure Linux NPM is in your PATH before the Windows version
  3. Try updating again with 'claude update'
`),"install_failed";let{hasPermissions:Q}=await SJ();if(!Q)return"no_permissions";let Y=J?`@claudiolabs/claudio@${J}`:"@claudiolabs/claudio",Z=H.isRunningWithBun()||r()?"bun":"npm",N=await K(Z,Z==="npm"?["install","-g","--force",Y]:["install","-g",Y],{cwd:X()});if(N.code!==0){let z=new _(`Failed to install new version of claude: ${N.stdout} ${N.stderr}`);return q(z),"install_failed"}if(Z==="npm"&&await vJ()){let z=await K("bun",["install","-g",Y],{cwd:X()});if(z.code!==0)q(new _(`Failed to update bun global install: ${z.stdout} ${z.stderr}`))}return v((z)=>({...z,installMethod:"global"})),"success"}finally{await MJ()}}async function TJ(){let J=V();for(let[,Q]of Object.entries(J))try{let Y=await x(Q);if(!Y)continue;let{filtered:Z,hadAlias:$}=g(Y);if($)await n(Q,Z),W(`Removed claude alias from ${Q}`)}catch(Y){W(`Failed to remove alias from ${Q}: ${Y}`,{level:"error"})}}var _,t=300000;var UJ=M(()=>{zJ();E();XJ();BJ();b();R();D();F();I();yJ();OJ();s();C();_=class _ extends l{}});
export{DJ as uS,EJ as vS,PJ as wS,fJ as xS,mJ as yS,p as zS,V as AS,g as BS,x as CS,n as DS,NJ as ES,nJ as FS,s as GS,zQ as HS,BQ as IS,OQ as JS,yQ as KS,e as LS,SJ as MS,GQ as NS,HQ as OS,_Q as PS,vQ as QS,wQ as RS,MQ as SS,UJ as TS};
