tako-cli 0.2.25 → 0.2.26
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +2 -2
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -321,7 +321,7 @@ ${H}`:x||H}function T1($,{maxDepth:S=1000,numbersAsFloat:Y=!1}={}){if(I$($)!=="o
|
|
|
321
321
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
322
322
|
*/var L1=X1(oS(),".codex"),k0=X1(L1,"config.toml"),aS=X1(L1,"auth.json"),iS={model_provider:"tako",model:"gpt-5.4",check_for_update_on_startup:!1,model_providers:{tako:{name:"tako",base_url:`${p}/v1`}}},rS={"full-auto":{approval_policy:"on-request",sandbox:"workspace-write"}};function I1($,S){let Y={...$};for(let[E,O]of Object.entries(S))if(O&&typeof O==="object"&&!Array.isArray(O)&&Y[E]&&typeof Y[E]==="object"&&!Array.isArray(Y[E]))Y[E]=I1(Y[E],O);else Y[E]=O;return Y}function nS($){if($.model_providers?.crs)delete $.model_providers.crs;if($.model_provider==="crs")delete $.model_provider;if($.openai_base_url)delete $.openai_base_url;let S=$.model_providers?.tako;if(S)delete S.wire_api,delete S.requires_openai_auth,delete S.supports_websockets,delete S.request_max_retries,delete S.stream_max_retries,delete S.api_key,delete S.env_key,delete S.experimental_bearer_token;return $}async function sS($,S){let Y=await import("fs/promises");try{await Y.mkdir(L1,{recursive:!0})}catch{}let E={};try{E=b1(await Y.readFile(k0,"utf-8"))}catch{}E=nS(E);let O=I1(E,iS);if(S)for(let H of S){let q=rS[H];if(q)O=I1(O,q)}await Bun.write(k0,T1(O));let x=JSON.stringify({OPENAI_API_KEY:$},null,2)+`
|
|
323
323
|
`;await Bun.write(aS,x)}var eS={id:"codex",name:"Codex",package:"@openai/codex",command:"codex",runtime:"bun",continueArg:"--continue",brandColor:"blue",getEnvVars($){return{}},setupConfigFiles:sS,launchOptions:[{id:"full-auto",label:{en:"Full-Auto",zh:"\u5168\u81EA\u52A8\u6A21\u5F0F"},shortLabel:"Full-Auto",description:{en:"Low-friction automation, auto-write in sandbox",zh:"\u4F4E\u6469\u64E6\u81EA\u52A8\u5316\uFF0C\u6C99\u7BB1\u5185\u81EA\u52A8\u5199\u5165"},flag:"--full-auto",args:[]},{id:"search",label:{en:"Web Search",zh:"\u7F51\u7EDC\u641C\u7D22"},shortLabel:"Search",description:{en:"Enable real-time web search",zh:"\u542F\u7528\u5B9E\u65F6\u7F51\u9875\u641C\u7D22"},flag:"--search",args:["--search"]}]};w$(eS);import{homedir as tS}from"os";import{join as g0}from"path";var d0=g0(tS(),".gemini"),u0=g0(d0,"settings.json");async function $H(){let $=await import("fs/promises");try{await $.mkdir(d0,{recursive:!0})}catch{}let S={};try{S=JSON.parse(await $.readFile(u0,"utf-8"))}catch{}let Y=S.security?.auth||{};if(Y.selectedType==="gemini-api-key")return;S.selectedAuthType="gemini-api-key",S.security={...S.security,auth:{...Y,selectedType:"gemini-api-key"}},await Bun.write(u0,JSON.stringify(S,null,2)+`
|
|
324
|
-
`)}var SH={id:"gemini",name:"Gemini CLI",package:"@google/gemini-cli",command:"gemini",runtime:"bun",brandColor:"cyan",getEnvVars($){return{GEMINI_API_KEY:$,GOOGLE_GEMINI_BASE_URL:"https://tako.shiroha.tech"}},setupConfigFiles:$H};w$(SH);import{join as d}from"path";h();var g$=null,d$={cn:{npm:"https://registry.npmmirror.com",bunBinary:"https://registry.npmmirror.com/-/binary/bun"},global:{npm:"https://registry.npmjs.org",bunBinary:null}};async function Z$(){if(g$)return g$;let $=[HH,YH,EH];for(let S of $)try{let Y=await Promise.race([S(),new Promise((E,O)=>setTimeout(()=>O(Error("timeout")),3000))]);if(Y)return g$=Y,Y}catch{}return g$="cn","cn"}async function HH(){try{let $=await fetch("http://ip-api.com/json/?fields=countryCode",{signal:AbortSignal.timeout(2000)});if(!$.ok)return null;return(await $.json()).countryCode==="CN"?"cn":"global"}catch{return null}}async function YH(){try{let $=await fetch("https://ipinfo.io/json",{signal:AbortSignal.timeout(2000)});if(!$.ok)return null;return(await $.json()).country==="CN"?"cn":"global"}catch{return null}}async function EH(){try{let $=await fetch("https://api.ip.sb/geoip",{signal:AbortSignal.timeout(2000)});if(!$.ok)return null;return(await $.json()).country_code==="CN"?"cn":"global"}catch{return null}}async function OH(){let $=await Z$();return d$[$]}async function t(){return(await OH()).npm}function c0(){return"curl -fsSL https://bun.sh/install | bash"}async function xH(){let $=d$.cn.bunBinary,S=await fetch(`${$}/`,{signal:AbortSignal.timeout(1e4)});if(!S.ok)throw Error(`Failed to fetch bun versions: ${S.status}`);let E=(await S.json()).map((O)=>O.name.replace(/\/$/,"")).filter((O)=>/^bun-v\d+\.\d+\.\d+$/.test(O)).sort((O,x)=>{let H=O.replace("bun-v","").split(".").map(Number),q=x.replace("bun-v","").split(".").map(Number);for(let R=0;R<3;R++)if(H[R]!==q[R])return q[R]-H[R];return 0});if(E.length===0)throw Error("No bun versions found on mirror");return E[0]}async function D0(){let $=d$.cn.bunBinary,S=await xH(),E={darwin:"darwin",win32:"windows",linux:"linux"}[process.platform]||"linux",O=process.arch==="arm64"?"aarch64":"x64",x=`bun-${E}-${O}`;return`${$}/${S}/${x}.zip`}async function p0(){let $=await Z$(),S=d$[$];if($==="cn")Z.info(M("region.usingChinaMirror")),Z.message(` npm: ${S.npm}`);else Z.info(M("region.usingGlobalMirror"))}var qH=class{constructor($){this.baseUrl=$.baseUrl,this.headers={"Content-Type":"application/json",...$.defaultHeaders},this.maxRetries=$.maxRetries??3,this.initialRetryDelay=$.initialRetryDelay??500}async resolveHeaders(){let $={};for(let[S,Y]of Object.entries(this.headers)){let E=await Y;E!==null&&($[S]=E)}return $}addHeader($,S){this.headers[$]=S}async post($,S,Y,E){try{let O=await fetch($,{method:"POST",headers:await this.resolveHeaders(),body:S?JSON.stringify(S??{}):void 0,keepalive:!0,...Y});if(O.status===401)return null;if(O.status!==200&&O.status!==202)throw Error(`HTTP error! status: ${O.status}`);let x=await O.text();return x?JSON.parse(x):null}catch(O){if(E<this.maxRetries){let x=this.initialRetryDelay*2**E;return await new Promise((H)=>setTimeout(H,x)),this.post($,S,Y,E+1)}return console.error("Max retries reached:",O),null}}async fetch($,S,Y={}){let E=`${this.baseUrl}${$}`;return this.post(E,S,Y,0)}},l0=class{constructor($){this.options=$,this.queue=[];let S={"openpanel-client-id":$.clientId};$.clientSecret&&(S["openpanel-client-secret"]=$.clientSecret),S["openpanel-sdk-name"]=$.sdk||"node",S["openpanel-sdk-version"]=$.sdkVersion||"1.0.4",this.api=new qH({baseUrl:$.apiUrl||"https://api.openpanel.dev",defaultHeaders:S})}init(){}ready(){this.options.waitForProfile=!1,this.flush()}async send($){return this.options.disabled||this.options.filter&&!this.options.filter($)?Promise.resolve():this.options.waitForProfile&&!this.profileId?(this.queue.push($),Promise.resolve()):this.api.fetch("/track",$)}setGlobalProperties($){this.global={...this.global,...$}}async track($,S){return this.log("track event",$,S),this.send({type:"track",payload:{name:$,profileId:S?.profileId??this.profileId,properties:{...this.global??{},...S??{}}}})}async identify($){if(this.log("identify user",$),$.profileId&&(this.profileId=$.profileId,this.flush()),Object.keys($).length>1)return this.send({type:"identify",payload:{...$,properties:{...this.global,...$.properties}}})}async alias($){}async increment($){return this.send({type:"increment",payload:$})}async decrement($){return this.send({type:"decrement",payload:$})}async revenue($,S){let Y=S?.deviceId;return delete S?.deviceId,this.track("revenue",{...S??{},...Y?{__deviceId:Y}:{},__revenue:$})}async fetchDeviceId(){return(await this.api.fetch("/track/device-id",void 0,{method:"GET",keepalive:!1}))?.deviceId??""}clear(){this.profileId=void 0}flush(){this.queue.forEach(($)=>{this.send({...$,payload:{...$.payload,profileId:$.payload.profileId??this.profileId}})}),this.queue=[]}log(...$){this.options.debug&&console.log("[OpenPanel.dev]",...$)}};var GH="f8ec91ab-20e5-4c17-bece-f5f2fe647a71",RH="sec_3038f0cb74f91312f374",wH="https://op.shiroha.tech/api",b$=null;function N1(){if(!b$)b$=new l0({clientId:GH,clientSecret:RH,apiUrl:wH});return b$}async function o0(){if(b$){try{b$.flush()}catch{}b$=null}}h();h();var MH="0.2.25";function a0(){return{cli_version:MH,platform:process.platform,arch:process.arch,locale:H$(),node_version:process.version}}function i0($){return Bun.hash($).toString(16).slice(0,8)}var QH="0.2.25",r0=!1,X$=null,U1=[];async function n0(){if(X$!==null)return X$;try{return X$=(await X()).telemetryEnabled!==!1,X$}catch{return X$=!1,!1}}async function vH(){try{return(await X()).apiId||"anonymous"}catch{return"anonymous"}}async function c$(){if(r0)return;try{if(!await n0())return;let $=await X();if(!$.apiId)return;let S=N1(),Y=await Z$();await S.identify({profileId:$.apiId,properties:{region:Y,locale:H$(),first_seen_version:QH,platform:process.platform,arch:process.arch}}),r0=!0}catch{}}function L($,S){let Y=ZH($,S).catch(()=>{});U1.push(Y)}async function ZH($,S){try{if(!await n0())return;let Y=N1(),E=await vH();await Y.track($,{profileId:E,...a0(),...S})}catch{}}async function L$(){await Promise.allSettled(U1),U1.length=0,await o0()}var Y$=null;function bH($){return $.startsWith(i)}async function zH(){try{if(!await Bun.file(C).exists())return null;let S=Bun.spawn([C,"--version"],{stdout:"pipe",stderr:"pipe"});if(await S.exited,S.exitCode!==0)return null;return(await new Response(S.stdout).text()).trim()}catch{return null}}async function t0(){return await zH()!==null}async function WH(){if(process.platform==="win32")return!0;try{let S=Bun.spawn(["which","unzip"],{stdout:"pipe",stderr:"pipe"});if(await S.exited,S.exitCode===0)return!0}catch{}Z.warn("\u6B63\u5728\u5B89\u88C5\u7CFB\u7EDF\u4F9D\u8D56 (unzip)...");let $=["apt-get update -qq && apt-get install -y -qq unzip","yum install -y -q unzip","dnf install -y -q unzip","pacman -S --noconfirm unzip","apk add --quiet unzip"];for(let S of $)try{let Y=Bun.spawn(["bash","-c",`sudo ${S} 2>/dev/null || ${S}`],{stdout:"pipe",stderr:"pipe"});if(await Y.exited,Y.exitCode===0)return!0}catch{}return!1}async function JH($){let S=await import("fs/promises"),{join:Y}=await import("path"),E=process.platform==="win32",O=E?"bun.exe":"bun",x=await D0();Z.info(`\u4ECE npmmirror \u4E0B\u8F7D: ${x}`);let H=await fetch(x);if(!H.ok)throw Error(`\u4E0B\u8F7D\u5931\u8D25: ${H.status}`);let q=Y($,"bun-download.zip");await Bun.write(q,H);let R=Y($,"bin");if(await S.mkdir(R,{recursive:!0}),E){let Q=`Expand-Archive -Path "${q}" -DestinationPath "${$}" -Force`,v=Bun.spawn(["powershell","-Command",Q],{stdout:"pipe",stderr:"pipe"});if(await v.exited,v.exitCode!==0)throw Error("\u89E3\u538B\u5931\u8D25")}else{let Q=Bun.spawn(["unzip","-oq",q,"-d",$],{stdout:"pipe",stderr:"pipe"});if(await Q.exited,Q.exitCode!==0)throw Error("\u89E3\u538B\u5931\u8D25")}let G=await S.readdir($);for(let Q of G){let v=Y($,Q);if((await S.stat(v)).isDirectory()&&Q.startsWith("bun-")){let V=Y(v,O);try{if(await S.access(V),await S.rename(V,Y(R,O)),!E)await S.chmod(Y(R,O),493);await S.rm(v,{recursive:!0,force:!0});break}catch{}}}return await S.rm(q,{force:!0}),!0}async function TH(){let $=g();if(!await WH())return Z.error("\u8BF7\u5148\u624B\u52A8\u5B89\u88C5 unzip: apt install unzip / yum install unzip"),!1;await p0(),$.start("\u6B63\u5728\u5B89\u88C5 Tako \u4E13\u5C5E Bun \u8FD0\u884C\u65F6...");try{if(await(await import("fs/promises")).mkdir(i,{recursive:!0}),await Z$()==="cn")await JH(i);else if(process.platform==="win32"){let E=`$env:BUN_INSTALL="${i}"; irm bun.sh/install.ps1 | iex`;if(await Bun.spawn(["powershell","-Command",E],{stdout:"inherit",stderr:"inherit"}).exited!==0)return $.stop("Bun \u5B89\u88C5\u5931\u8D25"),!1}else{let E=`BUN_INSTALL="${i}" ${c0()}`;if(await Bun.spawn(["bash","-c",E],{stdout:"inherit",stderr:"inherit"}).exited!==0)return $.stop("Bun \u5B89\u88C5\u5931\u8D25"),!1}return Y$=C,$.stop("Tako \u4E13\u5C5E Bun \u5B89\u88C5\u5B8C\u6210"),Z.info(`\u5B89\u88C5\u4F4D\u7F6E: ${i}`),!0}catch(S){return $.stop("Bun \u5B89\u88C5\u5931\u8D25"),!1}}async function IH(){if(await t0())return Y$=C,!0;return Z.warn("\u672A\u68C0\u6D4B\u5230 Tako \u4E13\u5C5E Bun\uFF0C\u6B63\u5728\u81EA\u52A8\u5B89\u88C5..."),Z.info("\uFF08\u4E0D\u4F1A\u5F71\u54CD\u60A8\u7CFB\u7EDF\u4E2D\u5DF2\u5B89\u88C5\u7684 Node.js \u6216 Bun\uFF09"),await TH()}async function D$(){if(Y$){if(!bH(Y$))Y$=C;return Y$}if(await t0())return Y$=C,C;return C}async function A1($){try{let S=await t(),Y=await fetch(`${S}/${$}/latest`);if(!Y.ok)return null;return(await Y.json()).version}catch{return null}}async function XH($){return(await X()).installedClients[$.id]?.version||null}async function $2($){let S=R$($.id),Y=d(S,"package.json");try{return await Bun.file(Y).exists()}catch{return!1}}async function S2($){let S=await XH($);if(!S)return!0;let Y=await A1($.package);if(!Y)return!1;return S!==Y}function LH($){let{platform:S,arch:Y}=process,E=`${S}-${Y}`;for(let[O,x]of Object.entries($))if(O.endsWith(E))return{pkg:O,version:x};return null}async function H2($,S,Y,E){let O=d(S,"node_modules",$.package,"package.json");try{let x=Bun.file(O);if(!await x.exists())return;let q=(await x.json()).optionalDependencies;if(!q||typeof q!=="object")return;let R=LH(q);if(!R)return;let G=d(S,"node_modules",R.pkg);if(await Bun.file(d(G,"package.json")).exists())return;await Bun.spawn([Y,"add",`${R.pkg}@${R.version}`],{cwd:S,stdout:"pipe",stderr:"pipe",env:{...process.env,BUN_CONFIG_REGISTRY:E}}).exited}catch{}}async function Y2($,S){let Y=d(S,"node_modules",$.package,"install.cjs");if(!await Bun.file(Y).exists())return;let O=Bun.spawn(["node",Y],{cwd:d(S,"node_modules",$.package),stdout:"pipe",stderr:"pipe"});if(await O.exited,O.exitCode!==0){let x=await new Response(O.stderr).text();Z.warn(`postinstall \u6267\u884C\u5F02\u5E38: ${x.slice(0,200)}`)}}async function s0($,S=!1){let Y=g(),E=R$($.id);try{if(!await IH())return{success:!1,error:"Tako \u4E13\u5C5E Bun \u5B89\u88C5\u5931\u8D25\uFF0C\u8BF7\u68C0\u67E5\u7F51\u7EDC\u6216\u624B\u52A8\u5220\u9664 ~/.tako/bun \u76EE\u5F55\u540E\u91CD\u8BD5"};let O=await $2($),x=S||await S2($);if(O&&!x)return{success:!0};let H=O?"\u66F4\u65B0":"\u5B89\u88C5";Y.start(`\u6B63\u5728${H} ${$.name}...`);let q=await import("fs/promises");await q.mkdir(E,{recursive:!0});let R=d(E,"package.json");if(!await Bun.file(R).exists())await Bun.write(R,JSON.stringify({name:`tako-${$.id}`,private:!0,dependencies:{}},null,2));let Q=await D$(),v=await t();if(O){let q$=d(E,"bun.lock");try{await q.unlink(q$)}catch{}}let z=Bun.spawn([Q,"add",`${$.package}@latest`],{cwd:E,stdout:"pipe",stderr:"pipe",env:{...process.env,BUN_CONFIG_REGISTRY:v}});if(await z.exited!==0){let q$=await new Response(z.stderr).text();return Y.stop(`${H} ${$.name} \u5931\u8D25`),{success:!1,error:q$}}await H2($,E,Q,v),await Y2($,E);let _=await A1($.package),g1=(await X()).installedClients[$.id]?.version;if(_){let q$=await X();if(q$.installedClients[$.id]={version:_,installedAt:new Date().toISOString()},await l(q$),O&&g1)L("client_updated",{client_id:$.id,from_version:g1,to_version:_});else L("client_installed",{client_id:$.id,client_version:_})}return Y.stop(`${$.name} ${H}\u5B8C\u6210`),{success:!0}}catch(O){return Y.stop("\u64CD\u4F5C\u5931\u8D25"),{success:!1,error:O instanceof Error?O.message:"\u672A\u77E5\u9519\u8BEF"}}}async function e0($){try{let S=Bun.file($);if(!await S.exists())return!0;if(S.size<100)return!0;let E=new Uint8Array(await S.slice(0,4).arrayBuffer());if(E[0]===127&&E[1]===69&&E[2]===76&&E[3]===70)return!1;if(E[0]===254||E[0]===207||E[0]===206||E[0]===202)return!1;if(E[0]===77&&E[1]===90)return!1;return!0}catch{return!0}}async function V1($){if($.runtime!=="native")return;let S=R$($.id),Y=d(S,"node_modules",$.package,"package.json");try{let E=Bun.file(Y);if(!await E.exists())return;let x=(await E.json()).bin;if(!x)return;let H=typeof x==="string"?x:x[$.command];if(!H)return;let q=d(S,"node_modules",$.package,H);if(!await e0(q))return;Z.info("\u6B63\u5728\u5B89\u88C5\u539F\u751F\u4E8C\u8FDB\u5236...");let R=await D$(),G=await t();if(await H2($,S,R,G),await Y2($,S),await e0(q))Z.warn("\u539F\u751F\u4E8C\u8FDB\u5236\u5B89\u88C5\u5931\u8D25\uFF0C\u53EF\u80FD\u5F71\u54CD\u542F\u52A8");else Z.success("\u539F\u751F\u4E8C\u8FDB\u5236\u5B89\u88C5\u5B8C\u6210")}catch{}}async function E2($){if(!await $2($)){let E=await s0($);if(E.success)await V1($);return E}if(await V1($),await S2($)){let E=await A1($.package),O=(await X()).installedClients[$.id]?.version||"\u672A\u77E5",x=E?`${O} \u2192 ${E}`:"\u6709\u65B0\u7248\u672C\u53EF\u7528";Z.info(`${$.name} \u53D1\u73B0\u66F4\u65B0: ${x}`);let H=await n({message:`\u662F\u5426\u66F4\u65B0 ${$.name}\uFF1F`,initialValue:!1});if(A(H)||!H)return Z.info("\u8DF3\u8FC7\u66F4\u65B0\uFF0C\u4F7F\u7528\u5F53\u524D\u7248\u672C"),{success:!0};let q=await s0($,!0);if(q.success)await V1($);return q}return{success:!0}}import{homedir as NH}from"os";var UH=50,B1=3;async function h1($){try{return(await(await import("fs/promises")).stat($)).isDirectory()}catch{return!1}}async function O2($,S){let Y=await X(),E=Y.recentProjects||[],O=new Date().toISOString(),x=E.findIndex((q)=>q.path===$);if(x>=0){let q=E[x],R=q.clientUsage||{},G=R[S]||{count:0,lastAt:O};E[x]={...q,launchCount:q.launchCount+1,lastLaunchedAt:O,lastClientId:S,clientUsage:{...R,[S]:{count:G.count+1,lastAt:O}}}}else E.push({path:$,launchCount:1,lastLaunchedAt:O,lastClientId:S,clientUsage:{[S]:{count:1,lastAt:O}}});let H=E.sort((q,R)=>new Date(R.lastLaunchedAt).getTime()-new Date(q.lastLaunchedAt).getTime()).slice(0,UH);Y.recentProjects=H,await n$(Y)}function VH($,S){let Y=$.clientUsage?.[S];if(Y)return new Date(Y.lastAt).getTime();if($.lastClientId===S)return new Date($.lastLaunchedAt).getTime();return 0}async function x2($,S=B1,Y=!0){let O=(await X()).recentProjects||[],x=process.cwd(),q=O.filter((G)=>{if(Y&&G.path===x)return!1;return G.clientUsage?.[$]||G.lastClientId===$}).map((G)=>({...G,lastUsedTime:VH(G,$)})).sort((G,Q)=>Q.lastUsedTime-G.lastUsedTime),R=[];for(let{lastUsedTime:G,...Q}of q){if(R.length>=S)break;if(await h1(Q.path))R.push(Q)}return R}async function q2(){let S=(await X()).recentProjects||[],Y=process.cwd();return S.find((O)=>O.path===Y)?.lastClientId||null}function G2($,S=25){let Y=NH(),E=$.startsWith(Y)?"~"+$.slice(Y.length):$;if(E.length>S){let x=E.split("/").pop()||"";if(x.length>S-4)E="..."+x.slice(-S+3);else E=`.../${x}`}return E}function R2($){let{t:S}=(h(),C2(K0)),Y=Date.now(),E=new Date($).getTime(),O=Y-E,x=Math.floor(O/60000),H=Math.floor(O/3600000),q=Math.floor(O/86400000),R=Math.floor(q/7),G=Math.floor(q/30);if(x<1)return S("time.justNow");if(x<60)return S("time.minutesAgo",{n:x});if(H<24)return S("time.hoursAgo",{n:H});if(q===1)return S("time.yesterday");if(q<7)return S("time.daysAgo",{n:q});if(q<30)return S("time.weeksAgo",{n:R});return S("time.monthsAgo",{n:G})}h();async function w2($,S){try{let Y=S?.projectPath||process.cwd(),E=await A$();if(!E)return{success:!1,error:"\u672A\u914D\u7F6E API Key"};let O=await s1($);if(!O)O=e1($);if(!await Bun.file(O).exists())return{success:!1,error:`\u627E\u4E0D\u5230\u53EF\u6267\u884C\u6587\u4EF6: ${O}`};let H=$.getEnvVars(E),q={...process.env,...H};Z.info(`\u542F\u52A8 ${$.name}...`);let R;if($.runtime==="native")R=[O];else R=[await D$(),O];if(S?.args&&S.args.length>0)R=[...R,...S.args];return await Bun.spawn(R,{env:q,stdio:["inherit","inherit","inherit"],cwd:Y}).exited,{success:!0}}catch(Y){return{success:!1,error:Y instanceof Error?Y.message:"\u542F\u52A8\u5931\u8D25"}}}async function E$($,S){try{let Y=S?.projectPath||process.cwd();if(S?.projectPath){if(!await h1(S.projectPath))return{success:!1,error:M("launcher.directoryNotFound",{path:S.projectPath})}}let E=await E2($);if(!E.success)return E;let O=await A$();if(!O)return{success:!1,error:M("launcher.apiKeyNotConfigured")};if($.setupConfigFiles)await $.setupConfigFiles(O,S?.selectedOptionIds);await O2(Y,$.id);let H=(await X()).installedClients[$.id]?.version;return L("client_launched",{client_id:$.id,client_version:H,project_hash:i0(Y),is_recent_project:!!S?.projectPath}),Z.info(M("launcher.starting",{client:$.name})),await w2($,S)}catch(Y){return{success:!1,error:Y instanceof Error?Y.message:"Launch failed"}}}h();import{join as c}from"path";var K1="tako-cli",f="0.2.25";function AH($,S){let Y=$.split(".").map(Number),E=S.split(".").map(Number);for(let O=0;O<3;O++){let x=Y[O]||0,H=E[O]||0;if(x>H)return 1;if(x<H)return-1}return 0}async function BH(){try{let $=await t(),S=await fetch(`${$}/${K1}/latest`,{signal:AbortSignal.timeout(5000)});if(!S.ok)return null;return(await S.json()).version||null}catch{return null}}async function hH(){let $=await BH();if(!$)return{hasUpdate:!1,currentVersion:f};return{hasUpdate:AH($,f)>0,latestVersion:$,currentVersion:f}}async function M2(){let $=await import("fs/promises"),S=c(k,"bin"),Y=c(S,"tako"),E=c(u,"node_modules/tako-cli/dist/index.js");if(await $.mkdir(S,{recursive:!0}),process.platform==="win32"){let x=`@echo off\r
|
|
324
|
+
`)}var SH={id:"gemini",name:"Gemini CLI",package:"@google/gemini-cli",command:"gemini",runtime:"bun",brandColor:"cyan",getEnvVars($){return{GEMINI_API_KEY:$,GOOGLE_GEMINI_BASE_URL:"https://tako.shiroha.tech"}},setupConfigFiles:$H};w$(SH);import{join as d}from"path";h();var g$=null,d$={cn:{npm:"https://registry.npmmirror.com",bunBinary:"https://registry.npmmirror.com/-/binary/bun"},global:{npm:"https://registry.npmjs.org",bunBinary:null}};async function Z$(){if(g$)return g$;let $=[HH,YH,EH];for(let S of $)try{let Y=await Promise.race([S(),new Promise((E,O)=>setTimeout(()=>O(Error("timeout")),3000))]);if(Y)return g$=Y,Y}catch{}return g$="cn","cn"}async function HH(){try{let $=await fetch("http://ip-api.com/json/?fields=countryCode",{signal:AbortSignal.timeout(2000)});if(!$.ok)return null;return(await $.json()).countryCode==="CN"?"cn":"global"}catch{return null}}async function YH(){try{let $=await fetch("https://ipinfo.io/json",{signal:AbortSignal.timeout(2000)});if(!$.ok)return null;return(await $.json()).country==="CN"?"cn":"global"}catch{return null}}async function EH(){try{let $=await fetch("https://api.ip.sb/geoip",{signal:AbortSignal.timeout(2000)});if(!$.ok)return null;return(await $.json()).country_code==="CN"?"cn":"global"}catch{return null}}async function OH(){let $=await Z$();return d$[$]}async function t(){return(await OH()).npm}function c0(){return"curl -fsSL https://bun.sh/install | bash"}async function xH(){let $=d$.cn.bunBinary,S=await fetch(`${$}/`,{signal:AbortSignal.timeout(1e4)});if(!S.ok)throw Error(`Failed to fetch bun versions: ${S.status}`);let E=(await S.json()).map((O)=>O.name.replace(/\/$/,"")).filter((O)=>/^bun-v\d+\.\d+\.\d+$/.test(O)).sort((O,x)=>{let H=O.replace("bun-v","").split(".").map(Number),q=x.replace("bun-v","").split(".").map(Number);for(let R=0;R<3;R++)if(H[R]!==q[R])return q[R]-H[R];return 0});if(E.length===0)throw Error("No bun versions found on mirror");return E[0]}async function D0(){let $=d$.cn.bunBinary,S=await xH(),E={darwin:"darwin",win32:"windows",linux:"linux"}[process.platform]||"linux",O=process.arch==="arm64"?"aarch64":"x64",x=`bun-${E}-${O}`;return`${$}/${S}/${x}.zip`}async function p0(){let $=await Z$(),S=d$[$];if($==="cn")Z.info(M("region.usingChinaMirror")),Z.message(` npm: ${S.npm}`);else Z.info(M("region.usingGlobalMirror"))}var qH=class{constructor($){this.baseUrl=$.baseUrl,this.headers={"Content-Type":"application/json",...$.defaultHeaders},this.maxRetries=$.maxRetries??3,this.initialRetryDelay=$.initialRetryDelay??500}async resolveHeaders(){let $={};for(let[S,Y]of Object.entries(this.headers)){let E=await Y;E!==null&&($[S]=E)}return $}addHeader($,S){this.headers[$]=S}async post($,S,Y,E){try{let O=await fetch($,{method:"POST",headers:await this.resolveHeaders(),body:S?JSON.stringify(S??{}):void 0,keepalive:!0,...Y});if(O.status===401)return null;if(O.status!==200&&O.status!==202)throw Error(`HTTP error! status: ${O.status}`);let x=await O.text();return x?JSON.parse(x):null}catch(O){if(E<this.maxRetries){let x=this.initialRetryDelay*2**E;return await new Promise((H)=>setTimeout(H,x)),this.post($,S,Y,E+1)}return console.error("Max retries reached:",O),null}}async fetch($,S,Y={}){let E=`${this.baseUrl}${$}`;return this.post(E,S,Y,0)}},l0=class{constructor($){this.options=$,this.queue=[];let S={"openpanel-client-id":$.clientId};$.clientSecret&&(S["openpanel-client-secret"]=$.clientSecret),S["openpanel-sdk-name"]=$.sdk||"node",S["openpanel-sdk-version"]=$.sdkVersion||"1.0.4",this.api=new qH({baseUrl:$.apiUrl||"https://api.openpanel.dev",defaultHeaders:S})}init(){}ready(){this.options.waitForProfile=!1,this.flush()}async send($){return this.options.disabled||this.options.filter&&!this.options.filter($)?Promise.resolve():this.options.waitForProfile&&!this.profileId?(this.queue.push($),Promise.resolve()):this.api.fetch("/track",$)}setGlobalProperties($){this.global={...this.global,...$}}async track($,S){return this.log("track event",$,S),this.send({type:"track",payload:{name:$,profileId:S?.profileId??this.profileId,properties:{...this.global??{},...S??{}}}})}async identify($){if(this.log("identify user",$),$.profileId&&(this.profileId=$.profileId,this.flush()),Object.keys($).length>1)return this.send({type:"identify",payload:{...$,properties:{...this.global,...$.properties}}})}async alias($){}async increment($){return this.send({type:"increment",payload:$})}async decrement($){return this.send({type:"decrement",payload:$})}async revenue($,S){let Y=S?.deviceId;return delete S?.deviceId,this.track("revenue",{...S??{},...Y?{__deviceId:Y}:{},__revenue:$})}async fetchDeviceId(){return(await this.api.fetch("/track/device-id",void 0,{method:"GET",keepalive:!1}))?.deviceId??""}clear(){this.profileId=void 0}flush(){this.queue.forEach(($)=>{this.send({...$,payload:{...$.payload,profileId:$.payload.profileId??this.profileId}})}),this.queue=[]}log(...$){this.options.debug&&console.log("[OpenPanel.dev]",...$)}};var GH="f8ec91ab-20e5-4c17-bece-f5f2fe647a71",RH="sec_3038f0cb74f91312f374",wH="https://op.shiroha.tech/api",b$=null;function N1(){if(!b$)b$=new l0({clientId:GH,clientSecret:RH,apiUrl:wH});return b$}async function o0(){if(b$){try{b$.flush()}catch{}b$=null}}h();h();var MH="0.2.26";function a0(){return{cli_version:MH,platform:process.platform,arch:process.arch,locale:H$(),node_version:process.version}}function i0($){return Bun.hash($).toString(16).slice(0,8)}var QH="0.2.26",r0=!1,X$=null,U1=[];async function n0(){if(X$!==null)return X$;try{return X$=(await X()).telemetryEnabled!==!1,X$}catch{return X$=!1,!1}}async function vH(){try{return(await X()).apiId||"anonymous"}catch{return"anonymous"}}async function c$(){if(r0)return;try{if(!await n0())return;let $=await X();if(!$.apiId)return;let S=N1(),Y=await Z$();await S.identify({profileId:$.apiId,properties:{region:Y,locale:H$(),first_seen_version:QH,platform:process.platform,arch:process.arch}}),r0=!0}catch{}}function L($,S){let Y=ZH($,S).catch(()=>{});U1.push(Y)}async function ZH($,S){try{if(!await n0())return;let Y=N1(),E=await vH();await Y.track($,{profileId:E,...a0(),...S})}catch{}}async function L$(){await Promise.allSettled(U1),U1.length=0,await o0()}var Y$=null;function bH($){return $.startsWith(i)}async function zH(){try{if(!await Bun.file(C).exists())return null;let S=Bun.spawn([C,"--version"],{stdout:"pipe",stderr:"pipe"});if(await S.exited,S.exitCode!==0)return null;return(await new Response(S.stdout).text()).trim()}catch{return null}}async function t0(){return await zH()!==null}async function WH(){if(process.platform==="win32")return!0;try{let S=Bun.spawn(["which","unzip"],{stdout:"pipe",stderr:"pipe"});if(await S.exited,S.exitCode===0)return!0}catch{}Z.warn("\u6B63\u5728\u5B89\u88C5\u7CFB\u7EDF\u4F9D\u8D56 (unzip)...");let $=["apt-get update -qq && apt-get install -y -qq unzip","yum install -y -q unzip","dnf install -y -q unzip","pacman -S --noconfirm unzip","apk add --quiet unzip"];for(let S of $)try{let Y=Bun.spawn(["bash","-c",`sudo ${S} 2>/dev/null || ${S}`],{stdout:"pipe",stderr:"pipe"});if(await Y.exited,Y.exitCode===0)return!0}catch{}return!1}async function JH($){let S=await import("fs/promises"),{join:Y}=await import("path"),E=process.platform==="win32",O=E?"bun.exe":"bun",x=await D0();Z.info(`\u4ECE npmmirror \u4E0B\u8F7D: ${x}`);let H=await fetch(x);if(!H.ok)throw Error(`\u4E0B\u8F7D\u5931\u8D25: ${H.status}`);let q=Y($,"bun-download.zip");await Bun.write(q,H);let R=Y($,"bin");if(await S.mkdir(R,{recursive:!0}),E){let Q=`Expand-Archive -Path "${q}" -DestinationPath "${$}" -Force`,v=Bun.spawn(["powershell","-Command",Q],{stdout:"pipe",stderr:"pipe"});if(await v.exited,v.exitCode!==0)throw Error("\u89E3\u538B\u5931\u8D25")}else{let Q=Bun.spawn(["unzip","-oq",q,"-d",$],{stdout:"pipe",stderr:"pipe"});if(await Q.exited,Q.exitCode!==0)throw Error("\u89E3\u538B\u5931\u8D25")}let G=await S.readdir($);for(let Q of G){let v=Y($,Q);if((await S.stat(v)).isDirectory()&&Q.startsWith("bun-")){let V=Y(v,O);try{if(await S.access(V),await S.rename(V,Y(R,O)),!E)await S.chmod(Y(R,O),493);await S.rm(v,{recursive:!0,force:!0});break}catch{}}}return await S.rm(q,{force:!0}),!0}async function TH(){let $=g();if(!await WH())return Z.error("\u8BF7\u5148\u624B\u52A8\u5B89\u88C5 unzip: apt install unzip / yum install unzip"),!1;await p0(),$.start("\u6B63\u5728\u5B89\u88C5 Tako \u4E13\u5C5E Bun \u8FD0\u884C\u65F6...");try{if(await(await import("fs/promises")).mkdir(i,{recursive:!0}),await Z$()==="cn")await JH(i);else if(process.platform==="win32"){let E=`$env:BUN_INSTALL="${i}"; irm bun.sh/install.ps1 | iex`;if(await Bun.spawn(["powershell","-Command",E],{stdout:"inherit",stderr:"inherit"}).exited!==0)return $.stop("Bun \u5B89\u88C5\u5931\u8D25"),!1}else{let E=`BUN_INSTALL="${i}" ${c0()}`;if(await Bun.spawn(["bash","-c",E],{stdout:"inherit",stderr:"inherit"}).exited!==0)return $.stop("Bun \u5B89\u88C5\u5931\u8D25"),!1}return Y$=C,$.stop("Tako \u4E13\u5C5E Bun \u5B89\u88C5\u5B8C\u6210"),Z.info(`\u5B89\u88C5\u4F4D\u7F6E: ${i}`),!0}catch(S){return $.stop("Bun \u5B89\u88C5\u5931\u8D25"),!1}}async function IH(){if(await t0())return Y$=C,!0;return Z.warn("\u672A\u68C0\u6D4B\u5230 Tako \u4E13\u5C5E Bun\uFF0C\u6B63\u5728\u81EA\u52A8\u5B89\u88C5..."),Z.info("\uFF08\u4E0D\u4F1A\u5F71\u54CD\u60A8\u7CFB\u7EDF\u4E2D\u5DF2\u5B89\u88C5\u7684 Node.js \u6216 Bun\uFF09"),await TH()}async function D$(){if(Y$){if(!bH(Y$))Y$=C;return Y$}if(await t0())return Y$=C,C;return C}async function A1($){try{let S=await t(),Y=await fetch(`${S}/${$}/latest`);if(!Y.ok)return null;return(await Y.json()).version}catch{return null}}async function XH($){return(await X()).installedClients[$.id]?.version||null}async function $2($){let S=R$($.id),Y=d(S,"package.json");try{return await Bun.file(Y).exists()}catch{return!1}}async function S2($){let S=await XH($);if(!S)return!0;let Y=await A1($.package);if(!Y)return!1;return S!==Y}function LH($){let{platform:S,arch:Y}=process,E=`${S}-${Y}`;for(let[O,x]of Object.entries($))if(O.endsWith(E))return{pkg:O,version:x};return null}async function H2($,S,Y,E){let O=d(S,"node_modules",$.package,"package.json");try{let x=Bun.file(O);if(!await x.exists())return;let q=(await x.json()).optionalDependencies;if(!q||typeof q!=="object")return;let R=LH(q);if(!R)return;let G=d(S,"node_modules",R.pkg);if(await Bun.file(d(G,"package.json")).exists())return;await Bun.spawn([Y,"add",`${R.pkg}@${R.version}`],{cwd:S,stdout:"pipe",stderr:"pipe",env:{...process.env,BUN_CONFIG_REGISTRY:E}}).exited}catch{}}async function Y2($,S){let Y=d(S,"node_modules",$.package,"install.cjs");if(!await Bun.file(Y).exists())return;let O=Bun.spawn(["node",Y],{cwd:d(S,"node_modules",$.package),stdout:"pipe",stderr:"pipe"});if(await O.exited,O.exitCode!==0){let x=await new Response(O.stderr).text();Z.warn(`postinstall \u6267\u884C\u5F02\u5E38: ${x.slice(0,200)}`)}}async function s0($,S=!1){let Y=g(),E=R$($.id);try{if(!await IH())return{success:!1,error:"Tako \u4E13\u5C5E Bun \u5B89\u88C5\u5931\u8D25\uFF0C\u8BF7\u68C0\u67E5\u7F51\u7EDC\u6216\u624B\u52A8\u5220\u9664 ~/.tako/bun \u76EE\u5F55\u540E\u91CD\u8BD5"};let O=await $2($),x=S||await S2($);if(O&&!x)return{success:!0};let H=O?"\u66F4\u65B0":"\u5B89\u88C5";Y.start(`\u6B63\u5728${H} ${$.name}...`);let q=await import("fs/promises");await q.mkdir(E,{recursive:!0});let R=d(E,"package.json");if(!await Bun.file(R).exists())await Bun.write(R,JSON.stringify({name:`tako-${$.id}`,private:!0,dependencies:{}},null,2));let Q=await D$(),v=await t();if(O){let q$=d(E,"bun.lock");try{await q.unlink(q$)}catch{}}let z=Bun.spawn([Q,"add",`${$.package}@latest`],{cwd:E,stdout:"pipe",stderr:"pipe",env:{...process.env,BUN_CONFIG_REGISTRY:v}});if(await z.exited!==0){let q$=await new Response(z.stderr).text();return Y.stop(`${H} ${$.name} \u5931\u8D25`),{success:!1,error:q$}}await H2($,E,Q,v),await Y2($,E);let _=await A1($.package),g1=(await X()).installedClients[$.id]?.version;if(_){let q$=await X();if(q$.installedClients[$.id]={version:_,installedAt:new Date().toISOString()},await l(q$),O&&g1)L("client_updated",{client_id:$.id,from_version:g1,to_version:_});else L("client_installed",{client_id:$.id,client_version:_})}return Y.stop(`${$.name} ${H}\u5B8C\u6210`),{success:!0}}catch(O){return Y.stop("\u64CD\u4F5C\u5931\u8D25"),{success:!1,error:O instanceof Error?O.message:"\u672A\u77E5\u9519\u8BEF"}}}async function e0($){try{let S=Bun.file($);if(!await S.exists())return!0;if(S.size<100)return!0;let E=new Uint8Array(await S.slice(0,4).arrayBuffer());if(E[0]===127&&E[1]===69&&E[2]===76&&E[3]===70)return!1;if(E[0]===254||E[0]===207||E[0]===206||E[0]===202)return!1;if(E[0]===77&&E[1]===90)return!1;return!0}catch{return!0}}async function V1($){if($.runtime!=="native")return;let S=R$($.id),Y=d(S,"node_modules",$.package,"package.json");try{let E=Bun.file(Y);if(!await E.exists())return;let x=(await E.json()).bin;if(!x)return;let H=typeof x==="string"?x:x[$.command];if(!H)return;let q=d(S,"node_modules",$.package,H);if(!await e0(q))return;Z.info("\u6B63\u5728\u5B89\u88C5\u539F\u751F\u4E8C\u8FDB\u5236...");let R=await D$(),G=await t();if(await H2($,S,R,G),await Y2($,S),await e0(q))Z.warn("\u539F\u751F\u4E8C\u8FDB\u5236\u5B89\u88C5\u5931\u8D25\uFF0C\u53EF\u80FD\u5F71\u54CD\u542F\u52A8");else Z.success("\u539F\u751F\u4E8C\u8FDB\u5236\u5B89\u88C5\u5B8C\u6210")}catch{}}async function E2($){if(!await $2($)){let E=await s0($);if(E.success)await V1($);return E}if(await V1($),await S2($)){let E=await A1($.package),O=(await X()).installedClients[$.id]?.version||"\u672A\u77E5",x=E?`${O} \u2192 ${E}`:"\u6709\u65B0\u7248\u672C\u53EF\u7528";Z.info(`${$.name} \u53D1\u73B0\u66F4\u65B0: ${x}`);let H=await n({message:`\u662F\u5426\u66F4\u65B0 ${$.name}\uFF1F`,initialValue:!1});if(A(H)||!H)return Z.info("\u8DF3\u8FC7\u66F4\u65B0\uFF0C\u4F7F\u7528\u5F53\u524D\u7248\u672C"),{success:!0};let q=await s0($,!0);if(q.success)await V1($);return q}return{success:!0}}import{homedir as NH}from"os";var UH=50,B1=3;async function h1($){try{return(await(await import("fs/promises")).stat($)).isDirectory()}catch{return!1}}async function O2($,S){let Y=await X(),E=Y.recentProjects||[],O=new Date().toISOString(),x=E.findIndex((q)=>q.path===$);if(x>=0){let q=E[x],R=q.clientUsage||{},G=R[S]||{count:0,lastAt:O};E[x]={...q,launchCount:q.launchCount+1,lastLaunchedAt:O,lastClientId:S,clientUsage:{...R,[S]:{count:G.count+1,lastAt:O}}}}else E.push({path:$,launchCount:1,lastLaunchedAt:O,lastClientId:S,clientUsage:{[S]:{count:1,lastAt:O}}});let H=E.sort((q,R)=>new Date(R.lastLaunchedAt).getTime()-new Date(q.lastLaunchedAt).getTime()).slice(0,UH);Y.recentProjects=H,await n$(Y)}function VH($,S){let Y=$.clientUsage?.[S];if(Y)return new Date(Y.lastAt).getTime();if($.lastClientId===S)return new Date($.lastLaunchedAt).getTime();return 0}async function x2($,S=B1,Y=!0){let O=(await X()).recentProjects||[],x=process.cwd(),q=O.filter((G)=>{if(Y&&G.path===x)return!1;return G.clientUsage?.[$]||G.lastClientId===$}).map((G)=>({...G,lastUsedTime:VH(G,$)})).sort((G,Q)=>Q.lastUsedTime-G.lastUsedTime),R=[];for(let{lastUsedTime:G,...Q}of q){if(R.length>=S)break;if(await h1(Q.path))R.push(Q)}return R}async function q2(){let S=(await X()).recentProjects||[],Y=process.cwd();return S.find((O)=>O.path===Y)?.lastClientId||null}function G2($,S=25){let Y=NH(),E=$.startsWith(Y)?"~"+$.slice(Y.length):$;if(E.length>S){let x=E.split("/").pop()||"";if(x.length>S-4)E="..."+x.slice(-S+3);else E=`.../${x}`}return E}function R2($){let{t:S}=(h(),C2(K0)),Y=Date.now(),E=new Date($).getTime(),O=Y-E,x=Math.floor(O/60000),H=Math.floor(O/3600000),q=Math.floor(O/86400000),R=Math.floor(q/7),G=Math.floor(q/30);if(x<1)return S("time.justNow");if(x<60)return S("time.minutesAgo",{n:x});if(H<24)return S("time.hoursAgo",{n:H});if(q===1)return S("time.yesterday");if(q<7)return S("time.daysAgo",{n:q});if(q<30)return S("time.weeksAgo",{n:R});return S("time.monthsAgo",{n:G})}h();async function w2($,S){try{let Y=S?.projectPath||process.cwd(),E=await A$();if(!E)return{success:!1,error:"\u672A\u914D\u7F6E API Key"};let O=await s1($);if(!O)O=e1($);if(!await Bun.file(O).exists())return{success:!1,error:`\u627E\u4E0D\u5230\u53EF\u6267\u884C\u6587\u4EF6: ${O}`};let H=$.getEnvVars(E),q={...process.env,...H};Z.info(`\u542F\u52A8 ${$.name}...`);let R;if($.runtime==="native")R=[O];else R=[await D$(),O];if(S?.args&&S.args.length>0)R=[...R,...S.args];return await Bun.spawn(R,{env:q,stdio:["inherit","inherit","inherit"],cwd:Y}).exited,{success:!0}}catch(Y){return{success:!1,error:Y instanceof Error?Y.message:"\u542F\u52A8\u5931\u8D25"}}}async function E$($,S){try{let Y=S?.projectPath||process.cwd();if(S?.projectPath){if(!await h1(S.projectPath))return{success:!1,error:M("launcher.directoryNotFound",{path:S.projectPath})}}let E=await E2($);if(!E.success)return E;let O=await A$();if(!O)return{success:!1,error:M("launcher.apiKeyNotConfigured")};if($.setupConfigFiles)await $.setupConfigFiles(O,S?.selectedOptionIds);await O2(Y,$.id);let H=(await X()).installedClients[$.id]?.version;return L("client_launched",{client_id:$.id,client_version:H,project_hash:i0(Y),is_recent_project:!!S?.projectPath}),Z.info(M("launcher.starting",{client:$.name})),await w2($,S)}catch(Y){return{success:!1,error:Y instanceof Error?Y.message:"Launch failed"}}}h();import{join as c}from"path";var K1="tako-cli",f="0.2.26";function AH($,S){let Y=$.split(".").map(Number),E=S.split(".").map(Number);for(let O=0;O<3;O++){let x=Y[O]||0,H=E[O]||0;if(x>H)return 1;if(x<H)return-1}return 0}async function BH(){try{let $=await t(),S=await fetch(`${$}/${K1}/latest`,{signal:AbortSignal.timeout(5000)});if(!S.ok)return null;return(await S.json()).version||null}catch{return null}}async function hH(){let $=await BH();if(!$)return{hasUpdate:!1,currentVersion:f};return{hasUpdate:AH($,f)>0,latestVersion:$,currentVersion:f}}async function M2(){let $=await import("fs/promises"),S=c(k,"bin"),Y=c(S,"tako"),E=c(u,"node_modules/tako-cli/dist/index.js");if(await $.mkdir(S,{recursive:!0}),process.platform==="win32"){let x=`@echo off\r
|
|
325
325
|
"${C}" "${E}" %*\r
|
|
326
326
|
`;await $.writeFile(c(S,"tako.cmd"),x)}else{let x=`#!/bin/bash
|
|
327
327
|
exec "${C}" "${E}" "$@"
|
|
@@ -329,7 +329,7 @@ exec "${C}" "${E}" "$@"
|
|
|
329
329
|
`)}async function _1(){let S=g();S.start(M("stats.fetching"));let Y=await U$();if(!Y.success){S.stop(M("stats.fetchFailed",{error:Y.error||""}));return}S.stop("");let E=10,O="",x=()=>{if(O){let q=O.split(`
|
|
330
330
|
`).length;process.stdout.write(`\x1B[${q}A\x1B[0J`)}O=uH(Y.data,E),console.log(O)};x();let H=process.stdin.isRaw;if(process.stdin.isTTY)process.stdin.setRawMode(!0);return process.stdin.resume(),new Promise((q)=>{let R=!0,G=()=>{if(!R)return;R=!1,v(),q()},Q=setInterval(async()=>{if(!R)return;if(E--,E<=0){E=10;let z=await U$();if(z.success)Y=z}x()},1000),v=()=>{if(clearInterval(Q),process.stdin.removeListener("data",G),process.stdin.isTTY)process.stdin.setRawMode(H??!1);process.stdin.pause()};process.stdin.on("data",G)})}function gH(){let S="\u2500".repeat(50);console.log(),console.log(` \u250C${S}\u2510`);let Y=`\uD83D\uDC19 ${M("cli.version",{version:f})}`,E=C1(Y),O=Math.floor((50-E)/2),x=50-O-E;console.log(` \u2502${" ".repeat(O)}${Y}${" ".repeat(x)}\u2502`);let H=M("banner.welcome"),q=`\x1B[90m${H}\x1B[0m`,R=C1(H),G=Math.floor((50-R)/2),Q=50-G-R;console.log(` \u2502${" ".repeat(G)}${q}${" ".repeat(Q)}\u2502`),console.log(` \u2514${S}\u2518`),console.log()}async function I2($){switch($.type){case"launch":{L("menu_action",{action:"launch",client_id:$.client.id});let S=await O$($.client);if(S===null)return!0;let Y=await E$($.client,{args:S.args,selectedOptionIds:S.selectedOptionIds});if(!Y.success)Z.error(Y.error||M("cli.launchFailed"));return!0}case"launch-in-project":{L("menu_action",{action:"launch",client_id:$.client.id});let S=await O$($.client);if(S===null)return!0;let Y=[...$.client.continueArg?[$.client.continueArg]:[],...S.args],E=await E$($.client,{projectPath:$.projectPath,args:Y,selectedOptionIds:S.selectedOptionIds});if(!E.success)Z.error(E.error||M("cli.launchFailed"));return!0}case"advanced":{L("menu_action",{action:"advanced"});let S=await y1();if(S)return await I2(S);return!0}case"stats":return L("menu_action",{action:"stats"}),await _1(),!0;case"config":return L("menu_action",{action:"config"}),await p$(!0),!0;case"resetOptions":return L("menu_action",{action:"resetOptions"}),await v2(),Z.success(M("menu.optionsReset")),!0;case"changelog":return L("menu_action",{action:"changelog"}),await W2(),!0;case"language":return L("menu_action",{action:"language"}),await dH(),!0;case"exit":return L("menu_action",{action:"exit"}),!1}}async function dH(){let $=Q$(),S=M(`language.${$}`),Y=await S$({message:M("menu.changeLanguage")+` (${M("menu.currentLanguage",{lang:S})})`,options:[{value:"en",label:M("language.en")},{value:"zh",label:M("language.zh")}]});if(A(Y))return;Z1(Y);let E=M(`language.${Y}`);Z.success(M("menu.languageChanged",{lang:E}))}async function X2(){if(gH(),await z2(),!await r1()){if(!await p$()){v1("\u518D\u89C1\uFF01");return}}while(!0){let S=await j1();if(S===null)break;if(!await I2(S))break}v1("\u518D\u89C1\uFF01")}h();import{homedir as DH}from"os";var N={black:"\x1B[30m",red:"\x1B[31m",green:"\x1B[32m",yellow:"\x1B[33m",blue:"\x1B[34m",magenta:"\x1B[35m",cyan:"\x1B[36m",white:"\x1B[37m",brightBlack:"\x1B[90m",brightRed:"\x1B[91m",brightGreen:"\x1B[92m",brightYellow:"\x1B[93m",brightBlue:"\x1B[94m",brightMagenta:"\x1B[95m",brightCyan:"\x1B[96m",brightWhite:"\x1B[97m"};var T={bold:"\x1B[1m",dim:"\x1B[2m",italic:"\x1B[3m",underline:"\x1B[4m",reset:"\x1B[0m"};var J={directory:{icon:N.brightYellow,text:N.brightGreen},git:{icon:N.brightBlue,text:N.brightBlue,clean:N.brightGreen,dirty:N.brightYellow,conflict:N.brightRed},model:{icon:N.brightCyan,text:N.brightCyan},version:{icon:N.brightWhite,text:N.brightBlack},outputStyle:{icon:N.brightMagenta,text:N.brightMagenta},context:{icon:N.brightMagenta,low:N.brightGreen,medium:N.brightYellow,high:N.brightRed},todayUsage:{icon:N.brightGreen,text:N.brightGreen},separator:N.brightBlack},o={directory:{nerd:"\uF07B",plain:"\uD83D\uDCC1"},git:{nerd:"\uE725",plain:"\uD83C\uDF3F"},model:{nerd:"\uF11B",plain:"\uD83E\uDD16"},version:{nerd:"\uF412",plain:"\uD83D\uDCBE"},outputStyle:{nerd:"\uF12F5",plain:"\uD83C\uDFAF"},context:{nerd:"\uF0E7",plain:"\u26A1"},todayUsage:{nerd:"\uF155",plain:"\uD83D\uDCB0"},gitClean:"\u2713",gitDirty:"\u25CF",gitConflict:"\u26A0",gitAhead:"\u2191",gitBehind:"\u2193"};function cH(){return!1}function j($){let S=o[$];if(typeof S==="string")return S;return cH()?S.nerd:S.plain}class l${id="directory";render($){let S=this.formatPath($.workspace.current_dir),Y=j("directory");return`${J.directory.icon}${Y}${T.reset} ${J.directory.text}${S}${T.reset}`}formatPath($){let S=DH();if($===S)return"~";if($.startsWith(S+"/"))return"~"+$.slice(S.length);return $}}class o${id="git";async render($){let S=$.workspace.current_dir;if(!await this.isGitRepository(S))return null;let E=await this.getBranch(S);if(!E)return null;let{status:O,statusColor:x}=await this.getStatus(S),{ahead:H,behind:q}=await this.getAheadBehind(S),R=j("git"),G=`${J.git.icon}${R}${T.reset} ${J.git.text}${E}${T.reset}`;if(G+=` ${x}${O}${T.reset}`,H>0)G+=` ${J.git.clean}${o.gitAhead}${H}${T.reset}`;if(q>0)G+=` ${J.git.dirty}${o.gitBehind}${q}${T.reset}`;return G}async isGitRepository($){try{return await Bun.spawn(["git","rev-parse","--git-dir"],{cwd:$,stdout:"pipe",stderr:"pipe"}).exited===0}catch{return!1}}async getBranch($){try{let S=Bun.spawn(["git","branch","--show-current"],{cwd:$,stdout:"pipe",stderr:"pipe"}),Y=await new Response(S.stdout).text();if(await S.exited===0&&Y.trim())return Y.trim();let O=Bun.spawn(["git","rev-parse","--short","HEAD"],{cwd:$,stdout:"pipe",stderr:"pipe"}),x=await new Response(O.stdout).text();if(await O.exited===0&&x.trim())return`detached:${x.trim()}`;return null}catch{return null}}async getStatus($){try{let S=Bun.spawn(["git","status","--porcelain"],{cwd:$,stdout:"pipe",stderr:"pipe"}),Y=await new Response(S.stdout).text();if(await S.exited!==0)return{status:o.gitClean,statusColor:J.git.clean};let O=Y.trim();if(!O)return{status:o.gitClean,statusColor:J.git.clean};if(O.includes("UU")||O.includes("AA")||O.includes("DD"))return{status:o.gitConflict,statusColor:J.git.conflict};return{status:o.gitDirty,statusColor:J.git.dirty}}catch{return{status:o.gitClean,statusColor:J.git.clean}}}async getAheadBehind($){try{let S=Bun.spawn(["git","rev-list","--count","@{u}..HEAD"],{cwd:$,stdout:"pipe",stderr:"pipe"}),Y=await new Response(S.stdout).text(),O=await S.exited===0?parseInt(Y.trim(),10)||0:0,x=Bun.spawn(["git","rev-list","--count","HEAD..@{u}"],{cwd:$,stdout:"pipe",stderr:"pipe"}),H=await new Response(x.stdout).text(),R=await x.exited===0?parseInt(H.trim(),10)||0:0;return{ahead:O,behind:R}}catch{return{ahead:0,behind:0}}}}var pH={"claude-opus-4-5-20251101":"Opus 4.5","claude-opus-4-5":"Opus 4.5","claude-sonnet-4-5-20250514":"Sonnet 4.5","claude-sonnet-4-5":"Sonnet 4.5","claude-sonnet-4-20250514":"Sonnet 4","claude-sonnet-4":"Sonnet 4","claude-sonnet-3-5-20241022":"Sonnet 3.5","claude-3-5-sonnet-20241022":"Sonnet 3.5","claude-3-5-sonnet":"Sonnet 3.5","claude-haiku-3-5-20241022":"Haiku 3.5","claude-3-5-haiku-20241022":"Haiku 3.5","claude-3-5-haiku":"Haiku 3.5"};class a${id="model";render($){let S=$.model.id,Y=pH[S]||this.simplifyModelName($.model.display_name),E=j("model");return`${J.model.icon}${E}${T.reset} ${J.model.text}${Y}${T.reset}`}simplifyModelName($){let S=$.replace(/^Claude\s+/i,"");return S=S.replace(/-\d{8}$/,""),S}}import{homedir as lH}from"os";import{join as F}from"path";var{Glob:oH}=globalThis.Bun;var L2=process.platform==="win32";class i${id="version";async render($){let S=await this.getClaudeCodeVersion();if(!S)return null;let Y=j("version");return`${J.version.icon}${Y}${T.reset} ${J.version.text}v${S}${T.reset}`}async getClaudeCodeVersion(){let $=lH(),S=[];if(L2)S.push(F($,"AppData","Roaming","npm","node_modules","@anthropic-ai","claude-code","package.json"),F($,"AppData","Local","npm-cache","_npx","**","node_modules","@anthropic-ai","claude-code","package.json"),F($,".bun","install","global","node_modules","@anthropic-ai","claude-code","package.json"));else S.push(F($,".bun","install","global","node_modules","@anthropic-ai","claude-code","package.json"),F($,".npm-global","lib","node_modules","@anthropic-ai","claude-code","package.json"),"/usr/local/lib/node_modules/@anthropic-ai/claude-code/package.json","/usr/lib/node_modules/@anthropic-ai/claude-code/package.json");for(let E of S){let O=await this.readVersionFromPackage(E);if(O)return O}let Y=[];if(L2)Y.push({base:F($,"AppData","Roaming","nvm"),pattern:"*/node_modules/@anthropic-ai/claude-code/package.json"},{base:F($,".volta","tools","image","packages","@anthropic-ai","claude-code"),pattern:"*/package.json"});else Y.push({base:F($,".local","share","fnm","node-versions"),pattern:"*/installation/lib/node_modules/@anthropic-ai/claude-code/package.json"},{base:F($,".nvm","versions","node"),pattern:"*/lib/node_modules/@anthropic-ai/claude-code/package.json"},{base:F($,".volta","tools","image","packages","@anthropic-ai","claude-code"),pattern:"*/package.json"},{base:F($,".local","share","pnpm","global"),pattern:"*/node_modules/@anthropic-ai/claude-code/package.json"});for(let{base:E,pattern:O}of Y)try{let x=new oH(O);for await(let H of x.scan({cwd:E,absolute:!0})){let q=await this.readVersionFromPackage(H);if(q)return q}}catch{continue}return null}async readVersionFromPackage($){try{let S=Bun.file($);if(!await S.exists())return null;return(await S.json()).version||null}catch{return null}}}var aH={"claude-opus-4-5-20251101":200000,"claude-opus-4-5":200000,"claude-sonnet-4-5-20250514":200000,"claude-sonnet-4-5":200000,"claude-sonnet-4-20250514":200000,"claude-sonnet-4":200000,"claude-sonnet-3-5-20241022":200000,"claude-3-5-sonnet-20241022":200000,"claude-3-5-sonnet":200000,"claude-haiku-3-5-20241022":200000,"claude-3-5-haiku-20241022":200000,"claude-3-5-haiku":200000},iH=200000;class D{id="context";static cache=null;static CACHE_TTL=5000;async render($){let S=await this.getTokensWithCache($.transcript_path),Y=this.getContextLimit($.model.id),O=Math.round((S??0)/Y*100),x=Math.max(0,100-O),H=j("context"),q=this.getRemainingColor(x),R=this.renderProgressBar(x);return`${J.context.icon}${H}${T.reset} ${q}Context Remaining: ${x}%${T.reset} ${R}`}renderProgressBar($){let Y=Math.round($/100*10),E=10-Y,O="=".repeat(Y),x="-".repeat(E),H=this.getRemainingColor($);return`${N.brightBlack}[${T.reset}${H}${O}${T.reset}${N.brightBlack}${x}]${T.reset}`}getRemainingColor($){if($<=20)return J.context.high;if($<=50)return J.context.medium;return J.context.low}async getTokensWithCache($){let S=Date.now();if(D.cache&&D.cache.path===$&&S-D.cache.timestamp<D.CACHE_TTL)return D.cache.tokens;let Y=await this.parseTranscriptTokens($);return D.cache={path:$,tokens:Y,timestamp:S},Y}async parseTranscriptTokens($){try{let S=Bun.file($);if(!await S.exists())return null;let Y=await S.text();if(!Y.trim())return null;let E=Y.split(`
|
|
331
331
|
`).filter((O)=>O.trim());for(let O=E.length-1;O>=0;O--)try{let x=JSON.parse(E[O]);if(x.type==="assistant"&&x.message?.usage){let H=x.message.usage;return(H.input_tokens||0)+(H.output_tokens||0)+(H.cache_creation_input_tokens||0)+(H.cache_read_input_tokens||0)}}catch{continue}return null}catch{return null}}getContextLimit($){return aH[$]||iH}}class a{id="today-usage";static cache=null;static CACHE_TTL=30000;async render($){if(a.cache&&Date.now()-a.cache.timestamp<a.CACHE_TTL)return a.cache.data;try{let S=await U$();if(!S.success||!S.data)return null;let Y=S.data.todayCost,E=j("todayUsage"),O=`${J.todayUsage.icon}${E}${T.reset} ${J.todayUsage.text}Today: ${Y}${T.reset}`;return a.cache={data:O,timestamp:Date.now()},O}catch{return null}}}class P1{separator=`${J.separator} \u2502 ${T.reset}`;render($){let S=["directory","git","model","version","today-usage"],Y=["context"],E=this.renderLine($,S),O=this.renderLine($,Y);return[E,O].filter((x)=>x.length>0).join(`
|
|
332
|
-
`)}renderLine($,S){let Y=[];for(let E of S){let O=$.get(E);if(O)Y.push(O)}return Y.join(this.separator)}}import{join as x$,dirname as rH}from"path";import{homedir as F1}from"os";import{mkdir as nH}from"fs/promises";var N2=x$(F1(),".tako"),sH=x$(N2,"cli"),eH=x$(N2,"bin",process.platform==="win32"?"tako.cmd":"tako");function tH(){if(process.platform==="win32")return x$(process.env.APPDATA||x$(F1(),"AppData","Roaming"),"claude","settings.json");return x$(F1(),".claude","settings.json")}var $3=process.platform==="win32",S3="0.1.48";function H3($,S){let Y=$.split(".").map(Number),E=S.split(".").map(Number),O=Math.max(Y.length,E.length);for(let x=0;x<O;x++){let H=Y[x]||0,q=E[x]||0;if(H!==q)return H-q}return 0}async function Y3(){let $=x$(sH,"node_modules","tako-cli","package.json");try{let S=Bun.file($);if(!await S.exists())return null;return(await S.json()).version||null}catch{return null}}async function E3(){let $=await Y3();if(!$)return!1;return H3($,S3)>=0}function O3(){return eH}function x3($){if($3)return $.replace(/\\/g,"/");return $}async function k1(){if(!await E3())return;let S=tH(),Y={};try{let H=Bun.file(S);if(await H.exists())Y=await H.json()}catch{}let O={type:"command",command:`"${x3(O3())}" statusline`,padding:0},x=typeof Y.statusLine==="object"&&Y.statusLine!==null?Y.statusLine.command:null;if(typeof x==="string"&&x.includes("tako statusline"))return;Y.statusLine=O,await nH(rH(S),{recursive:!0}),await Bun.write(S,JSON.stringify(Y,null,2))}var q3=[new l$,new o$,new a$,new i$,new D,new a];async function G3($){let S=await Promise.all(q3.map(async(O)=>{try{let x=await O.render($);return{id:O.id,content:x}}catch{return{id:O.id,content:null}}})),Y=new Map;for(let{id:O,content:x}of S)Y.set(O,x);return new P1().render(Y)}async function U2(){try{let $=await Bun.stdin.json(),S=await G3($);console.log(S)}catch($){process.exit(0)}}var u1="0.2.
|
|
332
|
+
`)}renderLine($,S){let Y=[];for(let E of S){let O=$.get(E);if(O)Y.push(O)}return Y.join(this.separator)}}import{join as x$,dirname as rH}from"path";import{homedir as F1}from"os";import{mkdir as nH}from"fs/promises";var N2=x$(F1(),".tako"),sH=x$(N2,"cli"),eH=x$(N2,"bin",process.platform==="win32"?"tako.cmd":"tako");function tH(){if(process.platform==="win32")return x$(process.env.APPDATA||x$(F1(),"AppData","Roaming"),"claude","settings.json");return x$(F1(),".claude","settings.json")}var $3=process.platform==="win32",S3="0.1.48";function H3($,S){let Y=$.split(".").map(Number),E=S.split(".").map(Number),O=Math.max(Y.length,E.length);for(let x=0;x<O;x++){let H=Y[x]||0,q=E[x]||0;if(H!==q)return H-q}return 0}async function Y3(){let $=x$(sH,"node_modules","tako-cli","package.json");try{let S=Bun.file($);if(!await S.exists())return null;return(await S.json()).version||null}catch{return null}}async function E3(){let $=await Y3();if(!$)return!1;return H3($,S3)>=0}function O3(){return eH}function x3($){if($3)return $.replace(/\\/g,"/");return $}async function k1(){if(!await E3())return;let S=tH(),Y={};try{let H=Bun.file(S);if(await H.exists())Y=await H.json()}catch{}let O={type:"command",command:`"${x3(O3())}" statusline`,padding:0},x=typeof Y.statusLine==="object"&&Y.statusLine!==null?Y.statusLine.command:null;if(typeof x==="string"&&x.includes("tako statusline"))return;Y.statusLine=O,await nH(rH(S),{recursive:!0}),await Bun.write(S,JSON.stringify(Y,null,2))}var q3=[new l$,new o$,new a$,new i$,new D,new a];async function G3($){let S=await Promise.all(q3.map(async(O)=>{try{let x=await O.render($);return{id:O.id,content:x}}catch{return{id:O.id,content:null}}})),Y=new Map;for(let{id:O,content:x}of S)Y.set(O,x);return new P1().render(Y)}async function U2(){try{let $=await Bun.stdin.json(),S=await G3($);console.log(S)}catch($){process.exit(0)}}var u1="0.2.26";function R3(){console.log(`
|
|
333
333
|
${M("cli.version",{version:u1})}
|
|
334
334
|
|
|
335
335
|
${M("cli.usage")}
|