tako-cli 0.2.9 → 0.2.10
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
|
@@ -302,7 +302,7 @@ ${x.default.gray(K$)} ${$}
|
|
|
302
302
|
`)}
|
|
303
303
|
`)},info:($)=>{N.message($,{symbol:x.default.blue(x2)})},success:($)=>{N.message($,{symbol:x.default.green(q2)})},step:($)=>{N.message($,{symbol:x.default.green(x1)})},warn:($)=>{N.message($,{symbol:x.default.yellow(v2)})},warning:($)=>{N.warn($)},error:($)=>{N.message($,{symbol:x.default.red(N2)})}},k=()=>{let $=T1?["\u25D2","\u25D0","\u25D3","\u25D1"]:["\u2022","o","O","0"],S=T1?80:120,H,E,R=!1,I="",O=(T="")=>{R=!0,H=J0(),I=T.replace(/\.+$/,""),process.stdout.write(`${x.default.gray(U)}
|
|
304
304
|
`);let q=0,Q=0;E=setInterval(()=>{let u=x.default.magenta($[q]),C=".".repeat(Math.floor(Q)).slice(0,3);process.stdout.write(H$.cursor.move(-999,0)),process.stdout.write(H$.erase.down(1)),process.stdout.write(`${u} ${I}${C}`),q=q+1<$.length?q+1:0,Q=Q<$.length?Q+0.125:0},S)},Y=(T="",q=0)=>{I=T??I,R=!1,clearInterval(E);let Q=q===0?x.default.green(x1):q===1?x.default.red(X0):x.default.red(U0);process.stdout.write(H$.cursor.move(-999,0)),process.stdout.write(H$.erase.down(1)),process.stdout.write(`${Q} ${I}
|
|
305
|
-
`),H()},b=(T="")=>{I=T??I},G=(T)=>{let q=T>1?"Something went wrong":"Canceled";R&&Y(q,T)};return process.on("uncaughtExceptionMonitor",()=>G(2)),process.on("unhandledRejection",()=>G(2)),process.on("SIGINT",()=>G(1)),process.on("SIGTERM",()=>G(1)),process.on("exit",G),{start:O,stop:Y,message:b}};import{join as Q1}from"path";V();var y$=null,w1={cn:{npm:"https://registry.npmmirror.com",bun:"https://bun.sh/install",bunMirror:"https://registry.npmmirror.com/-/binary/bun"},global:{npm:"https://registry.npmjs.org",bun:"https://bun.sh/install",bunMirror:null}};async function r(){if(y$)return y$;let $=[Q2,z2,Z2];for(let S of $)try{let H=await Promise.race([S(),new Promise((E,R)=>setTimeout(()=>R(Error("timeout")),3000))]);if(H)return y$=H,H}catch{}return y$="cn","cn"}async function Q2(){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 z2(){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 Z2(){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 W2(){let $=await r();return w1[$]}async function n(){return(await W2()).npm}async function V0(){if(await r()==="cn")return`curl -fsSL https://bun.sh/install | BUN_INSTALL_MIRROR="${w1.cn.bunMirror}" bash`;return"curl -fsSL https://bun.sh/install | bash"}async function f0(){let $=await r(),S=w1[$];if($==="cn")N.info(M("region.usingChinaMirror")),N.message(` npm: ${S.npm}`);else N.info(M("region.usingGlobalMirror"))}var J2=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,H]of Object.entries(this.headers)){let E=await H;E!==null&&($[S]=E)}return $}addHeader($,S){this.headers[$]=S}async post($,S,H,E){try{let R=await fetch($,{method:"POST",headers:await this.resolveHeaders(),body:S?JSON.stringify(S??{}):void 0,keepalive:!0,...H});if(R.status===401)return null;if(R.status!==200&&R.status!==202)throw Error(`HTTP error! status: ${R.status}`);let I=await R.text();return I?JSON.parse(I):null}catch(R){if(E<this.maxRetries){let I=this.initialRetryDelay*2**E;return await new Promise((O)=>setTimeout(O,I)),this.post($,S,H,E+1)}return console.error("Max retries reached:",R),null}}async fetch($,S,H={}){let E=`${this.baseUrl}${$}`;return this.post(E,S,H,0)}},K0=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 J2({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 H=S?.deviceId;return delete S?.deviceId,this.track("revenue",{...S??{},...H?{__deviceId:H}:{},__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 X2="f8ec91ab-20e5-4c17-bece-f5f2fe647a71",U2="sec_3038f0cb74f91312f374",h2="https://op.shiroha.tech/api",T$=null;function L1(){if(!T$)T$=new K0({clientId:X2,clientSecret:U2,apiUrl:h2});return T$}async function C0(){if(T$)try{T$=null}catch{}}V();V();var A2="0.2.9";function m0(){return{cli_version:A2,platform:process.platform,arch:process.arch,locale:a(),node_version:process.version}}function y0($){return Bun.hash($).toString(16).slice(0,8)}var B2="0.2.9",j0=!1,x$=null;async function _0(){if(x$!==null)return x$;try{return x$=(await X()).telemetryEnabled!==!1,x$}catch{return x$=!1,!1}}async function V2(){try{return(await X()).apiId||"anonymous"}catch{return"anonymous"}}async function j$(){if(j0)return;try{if(!await _0())return;let $=await X();if(!$.apiId)return;let S=L1(),H=await r();await S.identify({profileId:$.apiId,properties:{region:H,locale:a(),first_seen_version:B2,platform:process.platform,arch:process.arch}}),j0=!0}catch{}}function J($,S){f2($,S).catch(()=>{})}async function f2($,S){try{if(!await _0())return;let H=L1(),E=await V2();await H.track($,{profileId:E,properties:{...m0(),...S}})}catch{}}async function q$(){await C0()}var s=null;function K2($){return $.startsWith(D)}async function C2(){try{if(!await Bun.file(A).exists())return null;let S=Bun.spawn([A,"--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 k0(){return await C2()!==null}async function m2(){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{}N.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 H=Bun.spawn(["bash","-c",`sudo ${S} 2>/dev/null || ${S}`],{stdout:"pipe",stderr:"pipe"});if(await H.exited,H.exitCode===0)return!0}catch{}return!1}async function y2(){let $=k();if(!await m2())return N.error("\u8BF7\u5148\u624B\u52A8\u5B89\u88C5 unzip: apt install unzip / yum install unzip"),!1;await f0(),$.start("\u6B63\u5728\u5B89\u88C5 Tako \u4E13\u5C5E Bun \u8FD0\u884C\u65F6...");try{await(await import("fs/promises")).mkdir(D,{recursive:!0});let H;if(process.platform==="win32"){let R=await r()==="cn"?'$env:BUN_INSTALL_MIRROR="https://registry.npmmirror.com/-/binary/bun"; ':"",I=`$env:BUN_INSTALL="${D}"; ${R}irm bun.sh/install.ps1 | iex`;H=await Bun.spawn(["powershell","-Command",I],{stdout:"inherit",stderr:"inherit"}).exited}else{let E=await V0(),R=`BUN_INSTALL="${D}" ${E}`;H=await Bun.spawn(["bash","-c",R],{stdout:"inherit",stderr:"inherit"}).exited}if(H!==0)return $.stop("Bun \u5B89\u88C5\u5931\u8D25"),!1;return s=A,$.stop("Tako \u4E13\u5C5E Bun \u5B89\u88C5\u5B8C\u6210"),N.info(`\u5B89\u88C5\u4F4D\u7F6E: ${D}`),!0}catch(S){return $.stop("Bun \u5B89\u88C5\u5931\u8D25"),!1}}async function j2(){if(await k0())return s=A,!0;return N.warn("\u672A\u68C0\u6D4B\u5230 Tako \u4E13\u5C5E Bun\uFF0C\u6B63\u5728\u81EA\u52A8\u5B89\u88C5..."),N.info("\uFF08\u4E0D\u4F1A\u5F71\u54CD\u60A8\u7CFB\u7EDF\u4E2D\u5DF2\u5B89\u88C5\u7684 Node.js \u6216 Bun\uFF09"),await y2()}async function z1(){if(s){if(!K2(s))s=A;return s}if(await k0())return s=A,A;return A}async function F0($){try{let S=await n(),H=await fetch(`${S}/${$}/latest`);if(!H.ok)return null;return(await H.json()).version}catch{return null}}async function _2($){return(await X()).installedClients[$.id]?.version||null}async function g0($){let S=I$($.id),H=Q1(S,"package.json");try{return await Bun.file(H).exists()}catch{return!1}}async function u0($){let S=await _2($);if(!S)return!0;let H=await F0($.package);if(!H)return!1;return S!==H}async function P0($,S=!1){let H=k(),E=I$($.id);try{if(!await j2())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 R=await g0($),I=S||await u0($);if(R&&!I)return{success:!0};let O=R?"\u66F4\u65B0":"\u5B89\u88C5";H.start(`\u6B63\u5728${O} ${$.name}...`);let Y=await import("fs/promises");await Y.mkdir(E,{recursive:!0});let b=Q1(E,"package.json");if(!await Bun.file(b).exists())await Bun.write(b,JSON.stringify({name:`tako-${$.id}`,private:!0,dependencies:{}},null,2));let T=await z1(),q=await n();if(R){let $$=Q1(E,"bun.lock");try{await Y.unlink($$)}catch{}}let Q=Bun.spawn([T,"add",`${$.package}@latest`],{cwd:E,stdout:"pipe",stderr:"pipe",env:{...process.env,BUN_CONFIG_REGISTRY:q}});if(await Q.exited!==0){let $$=await new Response(Q.stderr).text();return H.stop(`${O} ${$.name} \u5931\u8D25`),{success:!1,error:$$}}let C=await F0($.package),C1=(await X()).installedClients[$.id]?.version;if(C){let $$=await X();if($$.installedClients[$.id]={version:C,installedAt:new Date().toISOString()},await L$($$),R&&C1)J("client_updated",{client_id:$.id,from_version:C1,to_version:C});else J("client_installed",{client_id:$.id,client_version:C})}return H.stop(`${$.name} ${O}\u5B8C\u6210`),{success:!0}}catch(R){return H.stop("\u64CD\u4F5C\u5931\u8D25"),{success:!1,error:R instanceof Error?R.message:"\u672A\u77E5\u9519\u8BEF"}}}async function _$($){if(!await g0($))return await P0($);if(await u0($))return await P0($,!0);return{success:!0}}import{homedir as P2}from"os";var k2=50,Z1=3;async function v$($){try{return(await(await import("fs/promises")).stat($)).isDirectory()}catch{return!1}}async function P$($,S){let H=await X(),E=H.recentProjects||[],R=new Date().toISOString(),I=E.findIndex((Y)=>Y.path===$);if(I>=0){let Y=E[I],b=Y.clientUsage||{},G=b[S]||{count:0,lastAt:R};E[I]={...Y,launchCount:Y.launchCount+1,lastLaunchedAt:R,lastClientId:S,clientUsage:{...b,[S]:{count:G.count+1,lastAt:R}}}}else E.push({path:$,launchCount:1,lastLaunchedAt:R,lastClientId:S,clientUsage:{[S]:{count:1,lastAt:R}}});let O=E.sort((Y,b)=>new Date(b.lastLaunchedAt).getTime()-new Date(Y.lastLaunchedAt).getTime()).slice(0,k2);H.recentProjects=O,await o$(H)}function F2($,S){let H=$.clientUsage?.[S];if(H)return new Date(H.lastAt).getTime();if($.lastClientId===S)return new Date($.lastLaunchedAt).getTime();return 0}async function c0($,S=Z1,H=!0){let R=(await X()).recentProjects||[],I=process.cwd(),Y=R.filter((G)=>{if(H&&G.path===I)return!1;return G.clientUsage?.[$]||G.lastClientId===$}).map((G)=>({...G,lastUsedTime:F2(G,$)})).sort((G,T)=>T.lastUsedTime-G.lastUsedTime),b=[];for(let{lastUsedTime:G,...T}of Y){if(b.length>=S)break;if(await v$(T.path))b.push(T)}return b}async function d0(){let S=(await X()).recentProjects||[],H=process.cwd();return S.find((R)=>R.path===H)?.lastClientId||null}function l0($,S=25){let H=P2(),E=$.startsWith(H)?"~"+$.slice(H.length):$;if(E.length>S){let I=E.split("/").pop()||"";if(I.length>S-4)E="..."+I.slice(-S+3);else E=`.../${I}`}return E}function o0($){let{t:S}=(V(),RS(B0)),H=Date.now(),E=new Date($).getTime(),R=H-E,I=Math.floor(R/60000),O=Math.floor(R/3600000),Y=Math.floor(R/86400000),b=Math.floor(Y/7),G=Math.floor(Y/30);if(I<1)return S("time.justNow");if(I<60)return S("time.minutesAgo",{n:I});if(O<24)return S("time.hoursAgo",{n:O});if(Y===1)return S("time.yesterday");if(Y<7)return S("time.daysAgo",{n:Y});if(Y<30)return S("time.weeksAgo",{n:b});return S("time.monthsAgo",{n:G})}V();async function i0($,S){try{let H=S?.projectPath||process.cwd();if(S?.projectPath){if(!await v$(S.projectPath))return{success:!1,error:`\u76EE\u5F55\u4E0D\u5B58\u5728: ${S.projectPath}`}}let E=await _$($);if(!E.success)return E;let R=await Q$();if(!R)return{success:!1,error:"\u672A\u914D\u7F6E API Key"};if($.setupConfigFiles)await $.setupConfigFiles(R);let I=await d1($);if(!I)I=l1($);if(!await Bun.file(I).exists())return{success:!1,error:`\u627E\u4E0D\u5230\u53EF\u6267\u884C\u6587\u4EF6: ${I}`};await P$(H,$.id);let Y=$.getEnvVars(R),b={...process.env,...Y};N.info(`\u542F\u52A8 ${$.name}...`);let G;if($.runtime==="native")G=[I];else G=[await z1(),I];if(S?.args&&S.args.length>0)G=[...G,...S.args];return await Bun.spawn(G,{env:b,stdio:["inherit","inherit","inherit"],cwd:H}).exited,{success:!0}}catch(H){return{success:!1,error:H instanceof Error?H.message:"\u542F\u52A8\u5931\u8D25"}}}async function E$($,S){try{let H=S?.projectPath||process.cwd();if(S?.projectPath){if(!await v$(S.projectPath))return{success:!1,error:M("launcher.directoryNotFound",{path:S.projectPath})}}let E=await _$($);if(!E.success)return E;let R=await Q$();if(!R)return{success:!1,error:M("launcher.apiKeyNotConfigured")};if($.setupConfigFiles)await $.setupConfigFiles(R);await P$(H,$.id);let O=(await X()).installedClients[$.id]?.version;return J("client_launched",{client_id:$.id,client_version:O,project_hash:y0(H),is_recent_project:!!S?.projectPath}),N.info(M("launcher.starting",{client:$.name})),await i0($,S)}catch(H){return{success:!1,error:H instanceof Error?H.message:"Launch failed"}}}V();import{join as F}from"path";var W1="tako-cli",e="0.2.9";function g2($,S){let H=$.split(".").map(Number),E=S.split(".").map(Number);for(let R=0;R<3;R++){let I=H[R]||0,O=E[R]||0;if(I>O)return 1;if(I<O)return-1}return 0}async function u2(){try{let $=await n(),S=await fetch(`${$}/${W1}/latest`,{signal:AbortSignal.timeout(5000)});if(!S.ok)return null;return(await S.json()).version||null}catch{return null}}async function c2(){let $=await u2();if(!$)return{hasUpdate:!1,currentVersion:e};return{hasUpdate:g2($,e)>0,latestVersion:$,currentVersion:e}}async function p0(){let $=await import("fs/promises"),S=F(_,"bin"),H=F(S,"tako"),E=F(P,"node_modules/tako-cli/dist/index.js");if(await $.mkdir(S,{recursive:!0}),process.platform==="win32"){let I=`@echo off\r
|
|
305
|
+
`),H()},b=(T="")=>{I=T??I},G=(T)=>{let q=T>1?"Something went wrong":"Canceled";R&&Y(q,T)};return process.on("uncaughtExceptionMonitor",()=>G(2)),process.on("unhandledRejection",()=>G(2)),process.on("SIGINT",()=>G(1)),process.on("SIGTERM",()=>G(1)),process.on("exit",G),{start:O,stop:Y,message:b}};import{join as Q1}from"path";V();var y$=null,w1={cn:{npm:"https://registry.npmmirror.com",bun:"https://bun.sh/install",bunMirror:"https://registry.npmmirror.com/-/binary/bun"},global:{npm:"https://registry.npmjs.org",bun:"https://bun.sh/install",bunMirror:null}};async function r(){if(y$)return y$;let $=[Q2,z2,Z2];for(let S of $)try{let H=await Promise.race([S(),new Promise((E,R)=>setTimeout(()=>R(Error("timeout")),3000))]);if(H)return y$=H,H}catch{}return y$="cn","cn"}async function Q2(){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 z2(){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 Z2(){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 W2(){let $=await r();return w1[$]}async function n(){return(await W2()).npm}async function V0(){if(await r()==="cn")return`curl -fsSL https://bun.sh/install | BUN_INSTALL_MIRROR="${w1.cn.bunMirror}" bash`;return"curl -fsSL https://bun.sh/install | bash"}async function f0(){let $=await r(),S=w1[$];if($==="cn")N.info(M("region.usingChinaMirror")),N.message(` npm: ${S.npm}`);else N.info(M("region.usingGlobalMirror"))}var J2=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,H]of Object.entries(this.headers)){let E=await H;E!==null&&($[S]=E)}return $}addHeader($,S){this.headers[$]=S}async post($,S,H,E){try{let R=await fetch($,{method:"POST",headers:await this.resolveHeaders(),body:S?JSON.stringify(S??{}):void 0,keepalive:!0,...H});if(R.status===401)return null;if(R.status!==200&&R.status!==202)throw Error(`HTTP error! status: ${R.status}`);let I=await R.text();return I?JSON.parse(I):null}catch(R){if(E<this.maxRetries){let I=this.initialRetryDelay*2**E;return await new Promise((O)=>setTimeout(O,I)),this.post($,S,H,E+1)}return console.error("Max retries reached:",R),null}}async fetch($,S,H={}){let E=`${this.baseUrl}${$}`;return this.post(E,S,H,0)}},K0=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 J2({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 H=S?.deviceId;return delete S?.deviceId,this.track("revenue",{...S??{},...H?{__deviceId:H}:{},__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 X2="f8ec91ab-20e5-4c17-bece-f5f2fe647a71",U2="sec_3038f0cb74f91312f374",h2="https://op.shiroha.tech/api",T$=null;function L1(){if(!T$)T$=new K0({clientId:X2,clientSecret:U2,apiUrl:h2});return T$}async function C0(){if(T$)try{T$=null}catch{}}V();V();var A2="0.2.10";function m0(){return{cli_version:A2,platform:process.platform,arch:process.arch,locale:a(),node_version:process.version}}function y0($){return Bun.hash($).toString(16).slice(0,8)}var B2="0.2.10",j0=!1,x$=null;async function _0(){if(x$!==null)return x$;try{return x$=(await X()).telemetryEnabled!==!1,x$}catch{return x$=!1,!1}}async function V2(){try{return(await X()).apiId||"anonymous"}catch{return"anonymous"}}async function j$(){if(j0)return;try{if(!await _0())return;let $=await X();if(!$.apiId)return;let S=L1(),H=await r();await S.identify({profileId:$.apiId,properties:{region:H,locale:a(),first_seen_version:B2,platform:process.platform,arch:process.arch}}),j0=!0}catch{}}function J($,S){f2($,S).catch(()=>{})}async function f2($,S){try{if(!await _0())return;let H=L1(),E=await V2();await H.track($,{profileId:E,properties:{...m0(),...S}})}catch{}}async function q$(){await C0()}var s=null;function K2($){return $.startsWith(D)}async function C2(){try{if(!await Bun.file(A).exists())return null;let S=Bun.spawn([A,"--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 k0(){return await C2()!==null}async function m2(){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{}N.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 H=Bun.spawn(["bash","-c",`sudo ${S} 2>/dev/null || ${S}`],{stdout:"pipe",stderr:"pipe"});if(await H.exited,H.exitCode===0)return!0}catch{}return!1}async function y2(){let $=k();if(!await m2())return N.error("\u8BF7\u5148\u624B\u52A8\u5B89\u88C5 unzip: apt install unzip / yum install unzip"),!1;await f0(),$.start("\u6B63\u5728\u5B89\u88C5 Tako \u4E13\u5C5E Bun \u8FD0\u884C\u65F6...");try{await(await import("fs/promises")).mkdir(D,{recursive:!0});let H;if(process.platform==="win32"){let R=await r()==="cn"?'$env:BUN_INSTALL_MIRROR="https://registry.npmmirror.com/-/binary/bun"; ':"",I=`$env:BUN_INSTALL="${D}"; ${R}irm bun.sh/install.ps1 | iex`;H=await Bun.spawn(["powershell","-Command",I],{stdout:"inherit",stderr:"inherit"}).exited}else{let E=await V0(),R=`BUN_INSTALL="${D}" ${E}`;H=await Bun.spawn(["bash","-c",R],{stdout:"inherit",stderr:"inherit"}).exited}if(H!==0)return $.stop("Bun \u5B89\u88C5\u5931\u8D25"),!1;return s=A,$.stop("Tako \u4E13\u5C5E Bun \u5B89\u88C5\u5B8C\u6210"),N.info(`\u5B89\u88C5\u4F4D\u7F6E: ${D}`),!0}catch(S){return $.stop("Bun \u5B89\u88C5\u5931\u8D25"),!1}}async function j2(){if(await k0())return s=A,!0;return N.warn("\u672A\u68C0\u6D4B\u5230 Tako \u4E13\u5C5E Bun\uFF0C\u6B63\u5728\u81EA\u52A8\u5B89\u88C5..."),N.info("\uFF08\u4E0D\u4F1A\u5F71\u54CD\u60A8\u7CFB\u7EDF\u4E2D\u5DF2\u5B89\u88C5\u7684 Node.js \u6216 Bun\uFF09"),await y2()}async function z1(){if(s){if(!K2(s))s=A;return s}if(await k0())return s=A,A;return A}async function F0($){try{let S=await n(),H=await fetch(`${S}/${$}/latest`);if(!H.ok)return null;return(await H.json()).version}catch{return null}}async function _2($){return(await X()).installedClients[$.id]?.version||null}async function g0($){let S=I$($.id),H=Q1(S,"package.json");try{return await Bun.file(H).exists()}catch{return!1}}async function u0($){let S=await _2($);if(!S)return!0;let H=await F0($.package);if(!H)return!1;return S!==H}async function P0($,S=!1){let H=k(),E=I$($.id);try{if(!await j2())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 R=await g0($),I=S||await u0($);if(R&&!I)return{success:!0};let O=R?"\u66F4\u65B0":"\u5B89\u88C5";H.start(`\u6B63\u5728${O} ${$.name}...`);let Y=await import("fs/promises");await Y.mkdir(E,{recursive:!0});let b=Q1(E,"package.json");if(!await Bun.file(b).exists())await Bun.write(b,JSON.stringify({name:`tako-${$.id}`,private:!0,dependencies:{}},null,2));let T=await z1(),q=await n();if(R){let $$=Q1(E,"bun.lock");try{await Y.unlink($$)}catch{}}let Q=Bun.spawn([T,"add",`${$.package}@latest`],{cwd:E,stdout:"pipe",stderr:"pipe",env:{...process.env,BUN_CONFIG_REGISTRY:q}});if(await Q.exited!==0){let $$=await new Response(Q.stderr).text();return H.stop(`${O} ${$.name} \u5931\u8D25`),{success:!1,error:$$}}let C=await F0($.package),C1=(await X()).installedClients[$.id]?.version;if(C){let $$=await X();if($$.installedClients[$.id]={version:C,installedAt:new Date().toISOString()},await L$($$),R&&C1)J("client_updated",{client_id:$.id,from_version:C1,to_version:C});else J("client_installed",{client_id:$.id,client_version:C})}return H.stop(`${$.name} ${O}\u5B8C\u6210`),{success:!0}}catch(R){return H.stop("\u64CD\u4F5C\u5931\u8D25"),{success:!1,error:R instanceof Error?R.message:"\u672A\u77E5\u9519\u8BEF"}}}async function _$($){if(!await g0($))return await P0($);if(await u0($))return await P0($,!0);return{success:!0}}import{homedir as P2}from"os";var k2=50,Z1=3;async function v$($){try{return(await(await import("fs/promises")).stat($)).isDirectory()}catch{return!1}}async function P$($,S){let H=await X(),E=H.recentProjects||[],R=new Date().toISOString(),I=E.findIndex((Y)=>Y.path===$);if(I>=0){let Y=E[I],b=Y.clientUsage||{},G=b[S]||{count:0,lastAt:R};E[I]={...Y,launchCount:Y.launchCount+1,lastLaunchedAt:R,lastClientId:S,clientUsage:{...b,[S]:{count:G.count+1,lastAt:R}}}}else E.push({path:$,launchCount:1,lastLaunchedAt:R,lastClientId:S,clientUsage:{[S]:{count:1,lastAt:R}}});let O=E.sort((Y,b)=>new Date(b.lastLaunchedAt).getTime()-new Date(Y.lastLaunchedAt).getTime()).slice(0,k2);H.recentProjects=O,await o$(H)}function F2($,S){let H=$.clientUsage?.[S];if(H)return new Date(H.lastAt).getTime();if($.lastClientId===S)return new Date($.lastLaunchedAt).getTime();return 0}async function c0($,S=Z1,H=!0){let R=(await X()).recentProjects||[],I=process.cwd(),Y=R.filter((G)=>{if(H&&G.path===I)return!1;return G.clientUsage?.[$]||G.lastClientId===$}).map((G)=>({...G,lastUsedTime:F2(G,$)})).sort((G,T)=>T.lastUsedTime-G.lastUsedTime),b=[];for(let{lastUsedTime:G,...T}of Y){if(b.length>=S)break;if(await v$(T.path))b.push(T)}return b}async function d0(){let S=(await X()).recentProjects||[],H=process.cwd();return S.find((R)=>R.path===H)?.lastClientId||null}function l0($,S=25){let H=P2(),E=$.startsWith(H)?"~"+$.slice(H.length):$;if(E.length>S){let I=E.split("/").pop()||"";if(I.length>S-4)E="..."+I.slice(-S+3);else E=`.../${I}`}return E}function o0($){let{t:S}=(V(),RS(B0)),H=Date.now(),E=new Date($).getTime(),R=H-E,I=Math.floor(R/60000),O=Math.floor(R/3600000),Y=Math.floor(R/86400000),b=Math.floor(Y/7),G=Math.floor(Y/30);if(I<1)return S("time.justNow");if(I<60)return S("time.minutesAgo",{n:I});if(O<24)return S("time.hoursAgo",{n:O});if(Y===1)return S("time.yesterday");if(Y<7)return S("time.daysAgo",{n:Y});if(Y<30)return S("time.weeksAgo",{n:b});return S("time.monthsAgo",{n:G})}V();async function i0($,S){try{let H=S?.projectPath||process.cwd();if(S?.projectPath){if(!await v$(S.projectPath))return{success:!1,error:`\u76EE\u5F55\u4E0D\u5B58\u5728: ${S.projectPath}`}}let E=await _$($);if(!E.success)return E;let R=await Q$();if(!R)return{success:!1,error:"\u672A\u914D\u7F6E API Key"};if($.setupConfigFiles)await $.setupConfigFiles(R);let I=await d1($);if(!I)I=l1($);if(!await Bun.file(I).exists())return{success:!1,error:`\u627E\u4E0D\u5230\u53EF\u6267\u884C\u6587\u4EF6: ${I}`};await P$(H,$.id);let Y=$.getEnvVars(R),b={...process.env,...Y};N.info(`\u542F\u52A8 ${$.name}...`);let G;if($.runtime==="native")G=[I];else G=[await z1(),I];if(S?.args&&S.args.length>0)G=[...G,...S.args];return await Bun.spawn(G,{env:b,stdio:["inherit","inherit","inherit"],cwd:H}).exited,{success:!0}}catch(H){return{success:!1,error:H instanceof Error?H.message:"\u542F\u52A8\u5931\u8D25"}}}async function E$($,S){try{let H=S?.projectPath||process.cwd();if(S?.projectPath){if(!await v$(S.projectPath))return{success:!1,error:M("launcher.directoryNotFound",{path:S.projectPath})}}let E=await _$($);if(!E.success)return E;let R=await Q$();if(!R)return{success:!1,error:M("launcher.apiKeyNotConfigured")};if($.setupConfigFiles)await $.setupConfigFiles(R);await P$(H,$.id);let O=(await X()).installedClients[$.id]?.version;return J("client_launched",{client_id:$.id,client_version:O,project_hash:y0(H),is_recent_project:!!S?.projectPath}),N.info(M("launcher.starting",{client:$.name})),await i0($,S)}catch(H){return{success:!1,error:H instanceof Error?H.message:"Launch failed"}}}V();import{join as F}from"path";var W1="tako-cli",e="0.2.10";function g2($,S){let H=$.split(".").map(Number),E=S.split(".").map(Number);for(let R=0;R<3;R++){let I=H[R]||0,O=E[R]||0;if(I>O)return 1;if(I<O)return-1}return 0}async function u2(){try{let $=await n(),S=await fetch(`${$}/${W1}/latest`,{signal:AbortSignal.timeout(5000)});if(!S.ok)return null;return(await S.json()).version||null}catch{return null}}async function c2(){let $=await u2();if(!$)return{hasUpdate:!1,currentVersion:e};return{hasUpdate:g2($,e)>0,latestVersion:$,currentVersion:e}}async function p0(){let $=await import("fs/promises"),S=F(_,"bin"),H=F(S,"tako"),E=F(P,"node_modules/tako-cli/dist/index.js");if(await $.mkdir(S,{recursive:!0}),process.platform==="win32"){let I=`@echo off\r
|
|
306
306
|
"${A}" "${E}" %*\r
|
|
307
307
|
`;await $.writeFile(F(S,"tako.cmd"),I)}else{let I=`#!/bin/bash
|
|
308
308
|
exec "${A}" "${E}" "$@"
|
|
@@ -310,7 +310,7 @@ exec "${A}" "${E}" "$@"
|
|
|
310
310
|
`)}async function A1(){let S=k();S.start(M("stats.fetching"));let H=await N$();if(!H.success){S.stop(M("stats.fetchFailed",{error:H.error||""}));return}S.stop("");let E=10,R="",I=()=>{if(R){let Y=R.split(`
|
|
311
311
|
`).length;process.stdout.write(`\x1B[${Y}A\x1B[0J`)}R=n2(H.data,E),console.log(R)};I();let O=process.stdin.isRaw;if(process.stdin.isTTY)process.stdin.setRawMode(!0);return process.stdin.resume(),new Promise((Y)=>{let b=!0,G=()=>{if(!b)return;b=!1,q(),Y()},T=setInterval(async()=>{if(!b)return;if(E--,E<=0){E=10;let Q=await N$();if(Q.success)H=Q}I()},1000),q=()=>{if(clearInterval(T),process.stdin.removeListener("data",G),process.stdin.isTTY)process.stdin.setRawMode(O??!1);process.stdin.pause()};process.stdin.on("data",G)})}function s2(){let S="\u2500".repeat(50);console.log(),console.log(` \u250C${S}\u2510`);let H=`\uD83D\uDC19 ${M("cli.version",{version:e})}`,E=J1(H),R=Math.floor((50-E)/2),I=50-R-E;console.log(` \u2502${" ".repeat(R)}${H}${" ".repeat(I)}\u2502`);let O=M("banner.welcome"),Y=`\x1B[90m${O}\x1B[0m`,b=J1(O),G=Math.floor((50-b)/2),T=50-G-b;console.log(` \u2502${" ".repeat(G)}${Y}${" ".repeat(T)}\u2502`),console.log(` \u2514${S}\u2518`),console.log()}async function r0($){switch($.type){case"launch":{J("menu_action",{action:"launch",client_id:$.client.id});let S=await E$($.client);if(!S.success)N.error(S.error||M("cli.launchFailed"));return!0}case"launch-in-project":{J("menu_action",{action:"launch",client_id:$.client.id});let S=$.client.continueArg?[$.client.continueArg]:[],H=await E$($.client,{projectPath:$.projectPath,args:S});if(!H.success)N.error(H.error||M("cli.launchFailed"));return!0}case"advanced":{J("menu_action",{action:"advanced"});let S=await U1();if(S)return await r0(S);return!0}case"stats":return J("menu_action",{action:"stats"}),await A1(),!0;case"config":return J("menu_action",{action:"config"}),await F$(!0),!0;case"language":return J("menu_action",{action:"language"}),await e2(),!0;case"exit":return J("menu_action",{action:"exit"}),!1}}async function e2(){let $=N1(),S=M(`language.${$}`),H=await M$({message:M("menu.changeLanguage")+` (${M("menu.currentLanguage",{lang:S})})`,options:[{value:"en",label:M("language.en")},{value:"zh",label:M("language.zh")}]});if(d(H))return;v1(H);let E=M(`language.${H}`);N.success(M("menu.languageChanged",{lang:E}))}async function n0(){if(s2(),!await u1()){if(!await F$()){q1("\u518D\u89C1\uFF01");return}}while(!0){let S=await X1();if(S===null)break;if(!await r0(S))break}q1("\u518D\u89C1\uFF01")}V();import{homedir as $O}from"os";var Z={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 L={bold:"\x1B[1m",dim:"\x1B[2m",italic:"\x1B[3m",underline:"\x1B[4m",reset:"\x1B[0m"};var w={directory:{icon:Z.brightYellow,text:Z.brightGreen},git:{icon:Z.brightBlue,text:Z.brightBlue,clean:Z.brightGreen,dirty:Z.brightYellow,conflict:Z.brightRed},model:{icon:Z.brightCyan,text:Z.brightCyan},version:{icon:Z.brightWhite,text:Z.brightBlack},outputStyle:{icon:Z.brightMagenta,text:Z.brightMagenta},context:{icon:Z.brightMagenta,low:Z.brightGreen,medium:Z.brightYellow,high:Z.brightRed},todayUsage:{icon:Z.brightGreen,text:Z.brightGreen},separator:Z.brightBlack},l={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 t2(){return!1}function f($){let S=l[$];if(typeof S==="string")return S;return t2()?S.nerd:S.plain}class g${id="directory";render($){let S=this.formatPath($.workspace.current_dir),H=f("directory");return`${w.directory.icon}${H}${L.reset} ${w.directory.text}${S}${L.reset}`}formatPath($){let S=$O();if($===S)return"~";if($.startsWith(S+"/"))return"~"+$.slice(S.length);return $}}class u${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:R,statusColor:I}=await this.getStatus(S),{ahead:O,behind:Y}=await this.getAheadBehind(S),b=f("git"),G=`${w.git.icon}${b}${L.reset} ${w.git.text}${E}${L.reset}`;if(G+=` ${I}${R}${L.reset}`,O>0)G+=` ${w.git.clean}${l.gitAhead}${O}${L.reset}`;if(Y>0)G+=` ${w.git.dirty}${l.gitBehind}${Y}${L.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"}),H=await new Response(S.stdout).text();if(await S.exited===0&&H.trim())return H.trim();let R=Bun.spawn(["git","rev-parse","--short","HEAD"],{cwd:$,stdout:"pipe",stderr:"pipe"}),I=await new Response(R.stdout).text();if(await R.exited===0&&I.trim())return`detached:${I.trim()}`;return null}catch{return null}}async getStatus($){try{let S=Bun.spawn(["git","status","--porcelain"],{cwd:$,stdout:"pipe",stderr:"pipe"}),H=await new Response(S.stdout).text();if(await S.exited!==0)return{status:l.gitClean,statusColor:w.git.clean};let R=H.trim();if(!R)return{status:l.gitClean,statusColor:w.git.clean};if(R.includes("UU")||R.includes("AA")||R.includes("DD"))return{status:l.gitConflict,statusColor:w.git.conflict};return{status:l.gitDirty,statusColor:w.git.dirty}}catch{return{status:l.gitClean,statusColor:w.git.clean}}}async getAheadBehind($){try{let S=Bun.spawn(["git","rev-list","--count","@{u}..HEAD"],{cwd:$,stdout:"pipe",stderr:"pipe"}),H=await new Response(S.stdout).text(),R=await S.exited===0?parseInt(H.trim(),10)||0:0,I=Bun.spawn(["git","rev-list","--count","HEAD..@{u}"],{cwd:$,stdout:"pipe",stderr:"pipe"}),O=await new Response(I.stdout).text(),b=await I.exited===0?parseInt(O.trim(),10)||0:0;return{ahead:R,behind:b}}catch{return{ahead:0,behind:0}}}}var SO={"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 c${id="model";render($){let S=$.model.id,H=SO[S]||this.simplifyModelName($.model.display_name),E=f("model");return`${w.model.icon}${E}${L.reset} ${w.model.text}${H}${L.reset}`}simplifyModelName($){let S=$.replace(/^Claude\s+/i,"");return S=S.replace(/-\d{8}$/,""),S}}import{homedir as OO}from"os";import{join as y}from"path";var{Glob:HO}=globalThis.Bun;var s0=process.platform==="win32";class d${id="version";async render($){let S=await this.getClaudeCodeVersion();if(!S)return null;let H=f("version");return`${w.version.icon}${H}${L.reset} ${w.version.text}v${S}${L.reset}`}async getClaudeCodeVersion(){let $=OO(),S=[];if(s0)S.push(y($,"AppData","Roaming","npm","node_modules","@anthropic-ai","claude-code","package.json"),y($,"AppData","Local","npm-cache","_npx","**","node_modules","@anthropic-ai","claude-code","package.json"),y($,".bun","install","global","node_modules","@anthropic-ai","claude-code","package.json"));else S.push(y($,".bun","install","global","node_modules","@anthropic-ai","claude-code","package.json"),y($,".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 R=await this.readVersionFromPackage(E);if(R)return R}let H=[];if(s0)H.push({base:y($,"AppData","Roaming","nvm"),pattern:"*/node_modules/@anthropic-ai/claude-code/package.json"},{base:y($,".volta","tools","image","packages","@anthropic-ai","claude-code"),pattern:"*/package.json"});else H.push({base:y($,".local","share","fnm","node-versions"),pattern:"*/installation/lib/node_modules/@anthropic-ai/claude-code/package.json"},{base:y($,".nvm","versions","node"),pattern:"*/lib/node_modules/@anthropic-ai/claude-code/package.json"},{base:y($,".volta","tools","image","packages","@anthropic-ai","claude-code"),pattern:"*/package.json"},{base:y($,".local","share","pnpm","global"),pattern:"*/node_modules/@anthropic-ai/claude-code/package.json"});for(let{base:E,pattern:R}of H)try{let I=new HO(R);for await(let O of I.scan({cwd:E,absolute:!0})){let Y=await this.readVersionFromPackage(O);if(Y)return Y}}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 EO={"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},RO=200000;class g{id="context";static cache=null;static CACHE_TTL=5000;async render($){let S=await this.getTokensWithCache($.transcript_path),H=this.getContextLimit($.model.id),R=Math.round((S??0)/H*100),I=Math.max(0,100-R),O=f("context"),Y=this.getRemainingColor(I),b=this.renderProgressBar(I);return`${w.context.icon}${O}${L.reset} ${Y}Context Remaining: ${I}%${L.reset} ${b}`}renderProgressBar($){let H=Math.round($/100*10),E=10-H,R="=".repeat(H),I="-".repeat(E),O=this.getRemainingColor($);return`${Z.brightBlack}[${L.reset}${O}${R}${L.reset}${Z.brightBlack}${I}]${L.reset}`}getRemainingColor($){if($<=20)return w.context.high;if($<=50)return w.context.medium;return w.context.low}async getTokensWithCache($){let S=Date.now();if(g.cache&&g.cache.path===$&&S-g.cache.timestamp<g.CACHE_TTL)return g.cache.tokens;let H=await this.parseTranscriptTokens($);return g.cache={path:$,tokens:H,timestamp:S},H}async parseTranscriptTokens($){try{let S=Bun.file($);if(!await S.exists())return null;let H=await S.text();if(!H.trim())return null;let E=H.split(`
|
|
312
312
|
`).filter((R)=>R.trim());for(let R=E.length-1;R>=0;R--)try{let I=JSON.parse(E[R]);if(I.type==="assistant"&&I.message?.usage){let O=I.message.usage;return(O.input_tokens||0)+(O.output_tokens||0)+(O.cache_creation_input_tokens||0)+(O.cache_read_input_tokens||0)}}catch{continue}return null}catch{return null}}getContextLimit($){return EO[$]||RO}}class o{id="today-usage";static cache=null;static CACHE_TTL=30000;async render($){if(o.cache&&Date.now()-o.cache.timestamp<o.CACHE_TTL)return o.cache.data;try{let S=await N$();if(!S.success||!S.data)return null;let H=S.data.todayCost,E=f("todayUsage"),R=`${w.todayUsage.icon}${E}${L.reset} ${w.todayUsage.text}Today: ${H}${L.reset}`;return o.cache={data:R,timestamp:Date.now()},R}catch{return null}}}class B1{separator=`${w.separator} \u2502 ${L.reset}`;render($){let S=["directory","git","model","version","today-usage"],H=["context"],E=this.renderLine($,S),R=this.renderLine($,H);return[E,R].filter((I)=>I.length>0).join(`
|
|
313
|
-
`)}renderLine($,S){let H=[];for(let E of S){let R=$.get(E);if(R)H.push(R)}return H.join(this.separator)}}import{join as t,dirname as IO}from"path";import{homedir as V1}from"os";import{mkdir as YO}from"fs/promises";var e0=t(V1(),".tako"),GO=t(e0,"cli"),bO=t(e0,"bin",process.platform==="win32"?"tako.cmd":"tako");function MO(){if(process.platform==="win32")return t(process.env.APPDATA||t(V1(),"AppData","Roaming"),"claude","settings.json");return t(V1(),".claude","settings.json")}var TO=process.platform==="win32",xO="0.1.48";function qO($,S){let H=$.split(".").map(Number),E=S.split(".").map(Number),R=Math.max(H.length,E.length);for(let I=0;I<R;I++){let O=H[I]||0,Y=E[I]||0;if(O!==Y)return O-Y}return 0}async function vO(){let $=t(GO,"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 NO(){let $=await vO();if(!$)return!1;return qO($,xO)>=0}function wO(){return bO}function LO($){if(TO)return $.replace(/\\/g,"/");return $}async function f1(){if(!await NO())return;let S=MO(),H={};try{let O=Bun.file(S);if(await O.exists())H=await O.json()}catch{}let R={type:"command",command:`"${LO(wO())}" statusline`,padding:0},I=typeof H.statusLine==="object"&&H.statusLine!==null?H.statusLine.command:null;if(typeof I==="string"&&I.includes("tako statusline"))return;H.statusLine=R,await YO(IO(S),{recursive:!0}),await Bun.write(S,JSON.stringify(H,null,2))}var QO=[new g$,new u$,new c$,new d$,new g,new o];async function zO($){let S=await Promise.all(QO.map(async(R)=>{try{let I=await R.render($);return{id:R.id,content:I}}catch{return{id:R.id,content:null}}})),H=new Map;for(let{id:R,content:I}of S)H.set(R,I);return new B1().render(H)}async function t0(){try{let $=await Bun.stdin.json(),S=await zO($);console.log(S)}catch($){process.exit(0)}}var K1="0.2.
|
|
313
|
+
`)}renderLine($,S){let H=[];for(let E of S){let R=$.get(E);if(R)H.push(R)}return H.join(this.separator)}}import{join as t,dirname as IO}from"path";import{homedir as V1}from"os";import{mkdir as YO}from"fs/promises";var e0=t(V1(),".tako"),GO=t(e0,"cli"),bO=t(e0,"bin",process.platform==="win32"?"tako.cmd":"tako");function MO(){if(process.platform==="win32")return t(process.env.APPDATA||t(V1(),"AppData","Roaming"),"claude","settings.json");return t(V1(),".claude","settings.json")}var TO=process.platform==="win32",xO="0.1.48";function qO($,S){let H=$.split(".").map(Number),E=S.split(".").map(Number),R=Math.max(H.length,E.length);for(let I=0;I<R;I++){let O=H[I]||0,Y=E[I]||0;if(O!==Y)return O-Y}return 0}async function vO(){let $=t(GO,"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 NO(){let $=await vO();if(!$)return!1;return qO($,xO)>=0}function wO(){return bO}function LO($){if(TO)return $.replace(/\\/g,"/");return $}async function f1(){if(!await NO())return;let S=MO(),H={};try{let O=Bun.file(S);if(await O.exists())H=await O.json()}catch{}let R={type:"command",command:`"${LO(wO())}" statusline`,padding:0},I=typeof H.statusLine==="object"&&H.statusLine!==null?H.statusLine.command:null;if(typeof I==="string"&&I.includes("tako statusline"))return;H.statusLine=R,await YO(IO(S),{recursive:!0}),await Bun.write(S,JSON.stringify(H,null,2))}var QO=[new g$,new u$,new c$,new d$,new g,new o];async function zO($){let S=await Promise.all(QO.map(async(R)=>{try{let I=await R.render($);return{id:R.id,content:I}}catch{return{id:R.id,content:null}}})),H=new Map;for(let{id:R,content:I}of S)H.set(R,I);return new B1().render(H)}async function t0(){try{let $=await Bun.stdin.json(),S=await zO($);console.log(S)}catch($){process.exit(0)}}var K1="0.2.10";function ZO(){console.log(`
|
|
314
314
|
${M("cli.version",{version:K1})}
|
|
315
315
|
|
|
316
316
|
${M("cli.usage")}
|