@owloops/claude-powerline 1.22.0 → 1.23.0
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/README.md +215 -189
- package/dist/index.mjs +1 -1
- package/package.json +2 -1
- package/plugin/.claude-plugin/plugin.json +11 -0
- package/plugin/bin/preview.sh +199 -0
- package/plugin/commands/powerline.md +322 -0
- package/plugin/templates/config-essential.json +36 -0
- package/plugin/templates/config-full.json +55 -0
- package/plugin/templates/config-standard.json +39 -0
- package/plugin/templates/config-tui.json +18 -0
- package/plugin/templates/nerd-fonts-sample.txt +5 -0
package/dist/index.mjs
CHANGED
|
@@ -3,7 +3,7 @@ import e from"node:process";import{json as t}from"node:stream/consumers";import
|
|
|
3
3
|
`).length:0}catch{return 0}}async getUpstreamAsync(e){try{return(await this.execGitAsync(`git rev-parse --abbrev-ref @{u}`,{cwd:e,encoding:`utf8`,timeout:2e3})).stdout.trim()||null}catch{return null}}async getRepoNameAsync(e){try{let t=(await this.execGitAsync(`git config --get remote.origin.url`,{cwd:e,encoding:`utf8`,timeout:2e3})).stdout.trim();return t&&t.match(/\/([^/]+?)(\.git)?$/)?.[1]||u.basename(e)}catch{return u.basename(e)}}isWorktree(e){try{let t=u.join(e,`.git`);return!!(o.existsSync(t)&&o.statSync(t).isFile())}catch{return!1}}async getStatusWithBranchAsync(e){try{D(`[GIT-EXEC] Running git status in ${e}`);let t=(await this.execGitAsync(`git status --porcelain -b`,{cwd:e,encoding:`utf8`,timeout:2e3})).stdout.split(`
|
|
4
4
|
`),n=null,r=`clean`,i=0,a=0,o=0,s=0;for(let e of t)if(e){if(e.startsWith(`## `)){let t=e.substring(3).split(`...`)[0];t&&t!==`HEAD (no branch)`&&(n=t);continue}if(e.length>=2){let t=e.charAt(0),n=e.charAt(1);if(t===`?`&&n===`?`){o++,r===`clean`&&(r=`dirty`);continue}let c=t+n;if([`DD`,`AU`,`UD`,`UA`,`DU`,`AA`,`UU`].includes(c)){s++,r=`conflicts`;continue}t!==` `&&t!==`?`&&(i++,r===`clean`&&(r=`dirty`)),n!==` `&&n!==`?`&&(a++,r===`clean`&&(r=`dirty`))}}return{branch:n||await this.getFallbackBranch(e),status:r,workingTree:{staged:i,unstaged:a,untracked:o,conflicts:s}}}catch(t){return D(`Git status with branch command failed in ${e}:`,t),{branch:await this.getFallbackBranch(e),status:`clean`}}}async getFallbackBranch(e){try{let t=(await this.execGitAsync(`git branch --show-current`,{cwd:e,encoding:`utf8`,timeout:2e3})).stdout.trim();if(t)return t}catch{try{let t=(await this.execGitAsync(`git symbolic-ref --short HEAD`,{cwd:e,encoding:`utf8`,timeout:2e3})).stdout.trim();if(t)return t}catch{return null}}return null}async getAheadBehindAsync(e){try{D(`[GIT-EXEC] Running git ahead/behind in ${e}`);let[t,n]=await Promise.all([this.execGitAsync(`git rev-list --count @{u}..HEAD`,{cwd:e,encoding:`utf8`,timeout:2e3}),this.execGitAsync(`git rev-list --count HEAD..@{u}`,{cwd:e,encoding:`utf8`,timeout:2e3})]);return{ahead:parseInt(t.stdout.trim())||0,behind:parseInt(n.stdout.trim())||0}}catch(t){return D(`Git ahead/behind command failed in ${e}:`,t),{ahead:0,behind:0}}}};const Te=a(r);var Ee=class{async getSessionId(){try{if(!process.env.TMUX_PANE)return D(`TMUX_PANE not set, not in tmux session`),null;D(`Getting tmux session ID, TMUX_PANE: ${process.env.TMUX_PANE}`);let e=(await Te(`tmux display-message -p '#S'`,{encoding:`utf8`,timeout:1e3})).stdout.trim();return D(`Tmux session ID: ${e||`empty`}`),e||null}catch(e){return D(`Error getting tmux session ID:`,e),null}}isInTmux(){return!!process.env.TMUX_PANE}};function O(){let e=[],t=process.env.CLAUDE_CONFIG_DIR;if(t&&t.split(`,`).forEach(t=>{let n=t.trim();c(n)&&e.push(n)}),e.length===0){let t=_(),n=f(t,`.config`,`claude`),r=f(t,`.claude`);c(n)&&e.push(n),c(r)&&e.push(r)}return e}async function k(e){let t=[];for(let n of e){let e=f(n,`projects`);if(c(e))try{let n=await x(e,{withFileTypes:!0});for(let r of n)if(r.isDirectory()){let n=p.join(e,r.name);t.push(n)}}catch(t){D(`Failed to read projects directory ${e}:`,t)}}return t}async function De(e){let t=await k(O());for(let n of t){let t=p.join(n,`${e}.jsonl`);if(c(t))return t}return null}async function Oe(e,t){let n=[],r=p.join(t,e,`subagents`);try{let t=(await x(r)).filter(e=>e.startsWith(`agent-`)&&e.endsWith(`.jsonl`));for(let i of t){let t=p.join(r,i);try{let r=(await b(t,`utf-8`)).split(`
|
|
5
5
|
`)[0];r&&JSON.parse(r).sessionId===e&&n.push(t)}catch{D(`Failed to check agent file ${t}`)}}}catch(e){D(`Failed to read subagents directory ${r}:`,e)}return n}async function ke(e){try{return(await ee(e)).mtime}catch{return null}}function Ae(e){let t=e.message?.id||(typeof e.raw.message==`object`&&e.raw.message!==null&&`id`in e.raw.message?e.raw.message.id:void 0),n=`requestId`in e.raw?e.raw.requestId:void 0;return!t||!n?null:`${t}:${n}`}async function A(e){try{let t=(await ee(e)).size,n;return t>1048576?(D(`Using streaming parser for large file ${e} (${Math.round(t/1024)}KB)`),n=await Me(e)):n=await je(e),D(`Parsed ${n.length} entries from ${e}`),n}catch(t){return D(`Failed to read file ${e}:`,t),[]}}async function je(e){let t=(await b(e,`utf-8`)).trim().split(`
|
|
6
|
-
`).filter(e=>e.trim()),n=[];for(let e of t)try{let t=JSON.parse(e);if(!t.timestamp)continue;let r={timestamp:new Date(t.timestamp),message:t.message,costUSD:typeof t.costUSD==`number`?t.costUSD:void 0,isSidechain:t.isSidechain===!0,raw:t};n.push(r)}catch(e){D(`Failed to parse JSONL line: ${e}`);continue}return n}async function Me(e){return new Promise((t,n)=>{let r=[],i=s(e,{encoding:`utf8`}),a=te({input:i,crlfDelay:1/0});a.on(`line`,e=>{let t=e.trim();if(t)try{let e=JSON.parse(t);if(!e.timestamp)return;let n={timestamp:new Date(e.timestamp),message:e.message,costUSD:typeof e.costUSD==`number`?e.costUSD:void 0,isSidechain:e.isSidechain===!0,raw:e};r.push(n)}catch(e){D(`Failed to parse JSONL line: ${e}`)}}),a.on(`close`,()=>{t(r)}),a.on(`error`,t=>{D(`Streaming parser error for ${e}:`,t),n(t)}),i.on(`error`,t=>{D(`File stream error for ${e}:`,t),n(t)})})}async function Ne(e){try{let t=await ke(e);return t?{filePath:e,mtime:t}:null}catch{return null}}async function Pe(e,t){try{let n=await x(e,{withFileTypes:!0}),r=n.filter(e=>!e.isDirectory()&&e.name.endsWith(`.jsonl`)).map(t=>Ne(p.join(e,t.name))),i=n.filter(e=>e.isDirectory()).map(async t=>{let n=p.join(e,t.name,`subagents`);try{return(await x(n)).filter(e=>e.startsWith(`agent-`)&&e.endsWith(`.jsonl`)).map(e=>Ne(p.join(n,e)))}catch{return[]}}),[a,o]=await Promise.all([Promise.all(r),Promise.all(i).then(e=>Promise.all(e.flat()))]);return[...a,...o].filter(e=>e!==null&&(!t||t(e.filePath,e.mtime)))}catch(t){return D(`Failed to read project directory ${e}:`,t),[]}}async function Fe(e,t,n=!1){let r=await k(O()),i=new Set,a=r.map(e=>Pe(e,t)),o=(await Promise.all(a)).flat().filter(e=>e!==null);n&&o.sort((e,t)=>t.mtime.getTime()-e.mtime.getTime());let s=o.map(e=>e.filePath),c=[],l=s.map(async t=>(await A(t)).filter(t=>!e||e(t))),u=await Promise.all(l);for(let e of u)c.push(...e);c.sort((e,t)=>e.timestamp.getTime()-t.timestamp.getTime());let d=[];for(let e of c){let t=Ae(e);t&&i.has(t)||(t&&i.add(t),d.push(e))}return d}var j=class{static CACHE_DIR=u.join(_(),`.claude`,`powerline`);static USAGE_CACHE_DIR=u.join(this.CACHE_DIR,`usage`);static LOCKS_DIR=u.join(this.CACHE_DIR,`locks`);static isLocked(e){let t=u.join(this.LOCKS_DIR,e);if(!o.existsSync(t))return!1;try{let n=o.readFileSync(t,`utf-8`),r=parseInt(n.trim(),10);if(isNaN(r))return D(`Invalid PID in lock file ${e}, removing stale lock`),o.unlinkSync(t),!1;try{return process.kill(r,0),!0}catch(n){return n.code===`ESRCH`?(D(`Removing stale lock file ${e} for dead process ${r}`),o.unlinkSync(t),!1):(D(`Error checking process ${r} for lock ${e}:`,n),!0)}}catch(t){return D(`Error reading lock file ${e}:`,t),!0}}static async acquireLock(e,t=5e3){await this.ensureCacheDirectories();let n=u.join(this.LOCKS_DIR,e),r=Date.now(),i=String(process.pid);for(;Date.now()-r<t;)try{return await o.promises.writeFile(n,i,{flag:`wx`}),D(`Lock acquired for ${e}`),!0}catch(e){if(e.code===`EEXIST`)await y(50);else throw e}return D(`Failed to acquire lock for ${e} within ${t}ms`),!1}static async releaseLock(e){let t=u.join(this.LOCKS_DIR,e);try{await o.promises.unlink(t),D(`Lock released for ${e}`)}catch(t){t.code!==`ENOENT`&&D(`Error releasing lock for ${e}:`,t)}}static async ensureCacheDirectories(){try{await Promise.all([o.promises.mkdir(this.CACHE_DIR,{recursive:!0}),o.promises.mkdir(this.USAGE_CACHE_DIR,{recursive:!0}),o.promises.mkdir(this.LOCKS_DIR,{recursive:!0})])}catch(e){D(`Failed to create cache directories:`,e)}}static createProjectHash(e){return v(`md5`).update(e).digest(`hex`).substring(0,8)}static async getUsageCache(e,t){await this.ensureCacheDirectories();let n=u.join(this.USAGE_CACHE_DIR,`${e}.json`),r=`${e}.usage.lock`;for(let i=0;i<3;i++){if(this.isLocked(r)){D(`Cache for ${e} is locked, waiting...`),await y(75);continue}try{let r=await o.promises.readFile(n,`utf-8`),i=JSON.parse(r);return!t||i.timestamp>=t?(D(`[CACHE-HIT] ${e} disk cache: found`),this.deserializeDates(i.data)):(D(`${e} cache outdated: cache=${i.timestamp}, latest=${t}`),null)}catch(t){if(t.code===`ENOENT`)return D(`No shared ${e} usage cache found`),null;D(`Attempt ${i+1} failed to read ${e} cache: ${t.message}. Retrying...`),await y(75)}}return D(`Failed to read ${e} cache after 3 attempts.`),null}static deserializeDates(e){return Array.isArray(e)?e.map(e=>({...e,timestamp:new Date(e.timestamp)})):e}static async setUsageCache(e,t,n){let r=`${e}.usage.lock`;if(!await this.acquireLock(r)){D(`Could not acquire lock to set usage cache for ${e}`);return}try{await this.ensureCacheDirectories();let r=u.join(this.USAGE_CACHE_DIR,`${e}.json`),i={data:t,timestamp:n||Date.now()},a=JSON.stringify(i);await o.promises.writeFile(r,a,`utf-8`),D(`[CACHE-SET] ${e} disk cache stored`)}catch(t){D(`Failed to save ${e} usage cache:`,t)}finally{await this.releaseLock(r)}}static async getLatestTranscriptMtime(){try{let e=await k(O()),t=0;for(let n of e)try{let e=(await o.promises.readdir(n)).filter(e=>e.endsWith(`.jsonl`));for(let r of e){let e=await ke(u.join(n,r));e&&e.getTime()>t&&(t=e.getTime())}}catch(e){D(`Failed to read project directory ${n}:`,e);continue}return t}catch(e){return D(`Failed to get latest transcript mtime:`,e),Date.now()}}};const M={"claude-haiku-4-5-20251001":{name:`Claude Haiku 4.5`,input:1,output:5,cache_write_5m:1.25,cache_write_1h:2,cache_read:.1},"claude-haiku-4-5":{name:`Claude Haiku 4.5`,input:1,output:5,cache_write_5m:1.25,cache_write_1h:2,cache_read:.1},"claude-opus-4-20250514":{name:`Claude Opus 4`,input:15,output:75,cache_write_5m:18.75,cache_write_1h:30,cache_read:1.5},"claude-opus-4-1":{name:`Claude Opus 4.1`,input:15,output:75,cache_write_5m:18.75,cache_write_1h:30,cache_read:1.5},"claude-opus-4-1-20250805":{name:`Claude Opus 4.1`,input:15,output:75,cache_write_5m:18.75,cache_write_1h:30,cache_read:1.5},"claude-sonnet-4-20250514":{name:`Claude Sonnet 4`,input:3,output:15,cache_write_5m:3.75,cache_write_1h:6,cache_read:.3},"claude-4-opus-20250514":{name:`Claude 4 Opus`,input:15,output:75,cache_write_5m:18.75,cache_write_1h:30,cache_read:1.5},"claude-4-sonnet-20250514":{name:`Claude 4 Sonnet`,input:3,output:15,cache_write_5m:3.75,cache_write_1h:6,cache_read:.3},"claude-sonnet-4-5":{name:`Claude Sonnet 4.5`,input:3,output:15,cache_write_5m:3.75,cache_write_1h:6,cache_read:.3},"claude-sonnet-4-5-20250929":{name:`Claude Sonnet 4.5`,input:3,output:15,cache_write_5m:3.75,cache_write_1h:6,cache_read:.3},"claude-opus-4-5":{name:`Claude Opus 4.5`,input:5,output:25,cache_write_5m:6.25,cache_write_1h:10,cache_read:.5},"claude-opus-4-5-20251101":{name:`Claude Opus 4.5`,input:5,output:25,cache_write_5m:6.25,cache_write_1h:10,cache_read:.5},"claude-opus-4-6":{name:`Claude Opus 4.6`,input:5,output:25,cache_write_5m:6.25,cache_write_1h:10,cache_read:.5},"claude-opus-4-6-20260205":{name:`Claude Opus 4.6`,input:5,output:25,cache_write_5m:6.25,cache_write_1h:10,cache_read:.5},"claude-sonnet-4-6":{name:`Claude Sonnet 4.6`,input:3,output:15,cache_write_5m:3.75,cache_write_1h:6,cache_read:.3}};var N=class{static executionCache=null;static modelPricingCache=new Map;static GITHUB_PRICING_URL=`https://raw.githubusercontent.com/Owloops/claude-powerline/main/pricing.json`;static async loadDiskCache(){let e=Date.now()-1440*60*1e3;return await j.getUsageCache(`pricing`,e)}static async saveDiskCache(e){await j.setUsageCache(`pricing`,e)}static async fetchPricingData(){return new Promise(e=>{let t=new h(this.GITHUB_PRICING_URL),n=m({hostname:t.hostname,path:t.pathname,headers:{"User-Agent":`claude-powerline`,"Cache-Control":`no-cache`},timeout:5e3},t=>{if(t.statusCode!==200){D(`HTTP ${t.statusCode}: ${t.statusMessage}`),e(null);return}let r=``,i=0;t.on(`data`,t=>{if(i+=t.length,i>1048576){D(`Response too large`),n.destroy(),e(null);return}r+=t}),t.on(`end`,()=>{try{let t=JSON.parse(r),n=t._meta,i={};for(let[e,n]of Object.entries(t))e!==`_meta`&&(i[e]=n);this.validatePricingData(i)?(D(`Fetched fresh pricing from GitHub for ${Object.keys(i).length} models`),D(`Pricing last updated: ${n?.updated||`unknown`}`),e(i)):(D(`Invalid pricing data structure`),e(null))}catch(t){D(`Failed to parse JSON:`,t),e(null)}}),t.on(`error`,t=>{D(`Response error:`,t),e(null)})});n.on(`error`,t=>{D(`Request error:`,t),e(null)}),n.on(`timeout`,()=>{D(`Request timeout`),n.destroy(),e(null)}),n.end()})}static async getCurrentPricing(){if(this.executionCache!==null)return D(`[CACHE-HIT] Pricing execution cache: ${Object.keys(this.executionCache).length} models`),this.executionCache;let e=await this.loadDiskCache();if(e)return D(`[CACHE-HIT] Pricing disk cache: ${Object.keys(e).length} models`),this.executionCache=e,D(`[CACHE-SET] Pricing execution cache stored: ${Object.keys(e).length} models`),e;let t=await this.fetchPricingData();return t?(await this.saveDiskCache(t),D(`[CACHE-SET] Pricing disk cache stored: ${Object.keys(t).length} models`),this.executionCache=t,D(`[CACHE-SET] Pricing execution cache stored: ${Object.keys(t).length} models`),t):(D(`[CACHE-FALLBACK] Using offline pricing data: ${Object.keys(M).length} models`),this.executionCache=M,D(`[CACHE-SET] Pricing execution cache stored: ${Object.keys(M).length} models`),M)}static validatePricingData(e){if(!e||typeof e!=`object`)return!1;for(let[,t]of Object.entries(e)){if(!t||typeof t!=`object`)return!1;let e=t;if(typeof e.input!=`number`||typeof e.output!=`number`||typeof e.cache_read!=`number`)return!1}return!0}static async getModelPricing(e){if(this.modelPricingCache.has(e))return D(`[CACHE-HIT] Model pricing cache: ${e}`),this.modelPricingCache.get(e);let t=await this.getCurrentPricing(),n;return n=t[e]?t[e]:this.fuzzyMatchModel(e,t),this.modelPricingCache.set(e,n),D(`[CACHE-SET] Model pricing cache: ${e}`),n}static fuzzyMatchModel(e,t){let n=e.toLowerCase();for(let[e,r]of Object.entries(t))if(e.toLowerCase()===n)return r;for(let{pattern:e,fallback:r}of[{pattern:[`opus-4-6`,`claude-opus-4-6`],fallback:`claude-opus-4-6-20260205`},{pattern:[`opus-4-5`,`claude-opus-4-5`],fallback:`claude-opus-4-5-20251101`},{pattern:[`opus-4-1`,`claude-opus-4-1`],fallback:`claude-opus-4-1-20250805`},{pattern:[`opus-4`,`claude-opus-4`],fallback:`claude-opus-4-20250514`},{pattern:[`sonnet-4-6`,`sonnet-4.6`,`claude-sonnet-4-6`],fallback:`claude-sonnet-4-6`},{pattern:[`sonnet-4.5`,`4-5-sonnet`,`sonnet-4-5`],fallback:`claude-sonnet-4-5-20250929`},{pattern:[`sonnet-4`,`claude-sonnet-4`],fallback:`claude-sonnet-4-20250514`},{pattern:[`haiku-4.5`,`4-5-haiku`,`haiku-4-5`],fallback:`claude-haiku-4-5-20251001`},{pattern:[`haiku`],fallback:`claude-haiku-4-5-20251001`},{pattern:[`opus`],fallback:`claude-opus-4-20250514`},{pattern:[`sonnet`],fallback:`claude-sonnet-4-5-20250929`}])if(e.some(e=>n.includes(e))&&t[r])return t[r];return t[`claude-sonnet-4-5-20250929`]||{name:`${e} (Unknown Model)`,input:3,cache_write_5m:3.75,cache_write_1h:6,cache_read:.3,output:15}}static async calculateCostForEntry(e){let t=e.message?.usage;if(!t)return 0;let n=this.extractModelId(e),r=await this.getModelPricing(n),i=t.input_tokens||0,a=t.output_tokens||0,o=t.cache_creation_input_tokens||0,s=t.cache_read_input_tokens||0,c=i/1e6*r.input,l=a/1e6*r.output,u=s/1e6*r.cache_read,d=o/1e6*r.cache_write_5m;return c+l+d+u}static extractModelId(e){if(e.model&&typeof e.model==`string`)return e.model;let t=e.message;if(t?.model){let e=t.model;return typeof e==`string`?e:e?.id||`claude-sonnet-4-5-20250929`}return e.model_id&&typeof e.model_id==`string`?e.model_id:`claude-sonnet-4-5-20250929`}};function Ie(e){return{timestamp:e.timestamp.toISOString(),message:{usage:{input_tokens:e.message?.usage?.input_tokens||0,output_tokens:e.message?.usage?.output_tokens||0,cache_creation_input_tokens:e.message?.usage?.cache_creation_input_tokens,cache_read_input_tokens:e.message?.usage?.cache_read_input_tokens}},costUSD:e.costUSD}}var Le=class{async getSessionUsage(e){try{let t=await De(e);if(!t)return D(`No transcript found for session: ${e}`),null;D(`Found transcript at: ${t}`);let n=await A(t),r=await Oe(e,d(t));D(`Found ${r.length} agent transcripts for session`);for(let e of r){let t=await A(e);n.push(...t)}if(n.length===0)return{totalCost:0,entries:[]};let i=[],a=0;for(let e of n)if(e.message?.usage){let t=Ie(e);if(t.costUSD!==void 0)a+=t.costUSD;else{let n=await N.calculateCostForEntry(e.raw);t.costUSD=n,a+=n}i.push(t)}return D(`Parsed ${i.length} usage entries, total cost: $${a.toFixed(4)}`),{totalCost:a,entries:i}}catch(t){return D(`Error reading session usage for ${e}:`,t),null}}calculateTokenBreakdown(e){return e.reduce((e,t)=>({input:e.input+(t.message.usage.input_tokens||0),output:e.output+(t.message.usage.output_tokens||0),cacheCreation:e.cacheCreation+(t.message.usage.cache_creation_input_tokens||0),cacheRead:e.cacheRead+(t.message.usage.cache_read_input_tokens||0)}),{input:0,output:0,cacheCreation:0,cacheRead:0})}async getSessionInfo(e,t){let n=await this.getSessionUsage(e);if(!n||n.entries.length===0)return{cost:null,calculatedCost:null,officialCost:null,tokens:null,tokenBreakdown:null};let r=this.calculateTokenBreakdown(n.entries),i=r.input+r.output+r.cacheCreation+r.cacheRead,a=n.totalCost,o=t?.cost?.total_cost_usd??null;return{cost:a??o,calculatedCost:a,officialCost:o,tokens:i,tokenBreakdown:r}}},Re=class{sessionProvider=new Le;async getUsageInfo(e,t){try{return D(`Starting usage info retrieval for session: ${e}`),{session:await this.sessionProvider.getSessionInfo(e,t)}}catch(t){return D(`Error getting usage info for session ${e}:`,t),{session:{cost:null,calculatedCost:null,officialCost:null,tokens:null,tokenBreakdown:null}}}}},ze=class{thresholds={LOW:50,MEDIUM:80};config;constructor(e){this.config=e}getContextUsageThresholds(){return this.thresholds}getContextLimit(e){let t=this.config.modelContextLimits||{default:2e5};return t[this.getModelType(e)]||t.default||2e5}getModelType(e){let t=e.toLowerCase();return t.includes(`sonnet`)?`sonnet`:t.includes(`opus`)?`opus`:`default`}calculatePercentages(e,t,n=33e3){let r=Math.min(100,Math.max(0,Math.round(e/t*100))),i=Math.max(1,t-n),a=Math.min(100,Math.max(0,Math.round(e/i*100)));return{percentage:r,usablePercentage:a,contextLeftPercentage:Math.max(0,100-a),usableTokens:i}}calculateContextFromHookData(e,t=33e3){let n=e.context_window?.current_usage;if(!n)return D(`No current_usage in hook data, falling back to transcript parsing`),null;let r=e.context_window?.context_window_size||2e5,i=(n.input_tokens||0)+(n.cache_creation_input_tokens||0)+(n.cache_read_input_tokens||0);return D(`Native current_usage: input=${n.input_tokens}, cache_create=${n.cache_creation_input_tokens}, cache_read=${n.cache_read_input_tokens}, total=${i} (limit: ${r})`),{totalTokens:i,maxTokens:r,...this.calculatePercentages(i,r,t)}}async calculateContextTokensFromTranscript(e,t,n=33e3){try{D(`Calculating context tokens from transcript: ${e}`);try{if(!l(e,`utf-8`))return D(`Transcript file is empty`),null}catch{return D(`Could not read transcript file`),null}let r=await A(e);if(r.length===0)return D(`No entries in transcript`),null;let i=null;for(let e=r.length-1;e>=0;e--){let t=r[e];if(t&&t.message?.usage?.input_tokens&&t.isSidechain!==!0){i=t,D(`Context segment: Found most recent entry at ${t.timestamp.toISOString()}, stopping search`);break}}if(i?.message?.usage){let e=i.message.usage,r=(e.input_tokens||0)+(e.cache_read_input_tokens||0)+(e.cache_creation_input_tokens||0),a=t?this.getContextLimit(t):2e5;return D(`Most recent main chain context: ${r} tokens (limit: ${a})`),{totalTokens:r,maxTokens:a,...this.calculatePercentages(r,a,n)}}return D(`No main chain entries with usage data found`),null}catch(e){return D(`Error reading transcript: ${e instanceof Error?e.message:String(e)}`),null}}async getContextInfo(e,t=33e3){return this.calculateContextFromHookData(e,t)||this.calculateContextTokensFromTranscript(e.transcript_path,e.model?.id,t)}},Be=class{async loadTranscriptEntries(e){try{let t=await De(e);if(!t)return D(`No transcript found for session: ${e}`),[];D(`Loading transcript from: ${t}`);let n=(await b(t,`utf-8`)).trim().split(`
|
|
6
|
+
`).filter(e=>e.trim()),n=[];for(let e of t)try{let t=JSON.parse(e);if(!t.timestamp)continue;let r={timestamp:new Date(t.timestamp),message:t.message,costUSD:typeof t.costUSD==`number`?t.costUSD:void 0,isSidechain:t.isSidechain===!0,raw:t};n.push(r)}catch(e){D(`Failed to parse JSONL line: ${e}`);continue}return n}async function Me(e){return new Promise((t,n)=>{let r=[],i=s(e,{encoding:`utf8`}),a=te({input:i,crlfDelay:1/0});a.on(`line`,e=>{let t=e.trim();if(t)try{let e=JSON.parse(t);if(!e.timestamp)return;let n={timestamp:new Date(e.timestamp),message:e.message,costUSD:typeof e.costUSD==`number`?e.costUSD:void 0,isSidechain:e.isSidechain===!0,raw:e};r.push(n)}catch(e){D(`Failed to parse JSONL line: ${e}`)}}),a.on(`close`,()=>{t(r)}),a.on(`error`,t=>{D(`Streaming parser error for ${e}:`,t),n(t)}),i.on(`error`,t=>{D(`File stream error for ${e}:`,t),n(t)})})}async function Ne(e){try{let t=await ke(e);return t?{filePath:e,mtime:t}:null}catch{return null}}async function Pe(e,t){try{let n=await x(e,{withFileTypes:!0}),r=n.filter(e=>!e.isDirectory()&&e.name.endsWith(`.jsonl`)).map(t=>Ne(p.join(e,t.name))),i=n.filter(e=>e.isDirectory()).map(async t=>{let n=p.join(e,t.name,`subagents`);try{return(await x(n)).filter(e=>e.startsWith(`agent-`)&&e.endsWith(`.jsonl`)).map(e=>Ne(p.join(n,e)))}catch{return[]}}),[a,o]=await Promise.all([Promise.all(r),Promise.all(i).then(e=>Promise.all(e.flat()))]);return[...a,...o].filter(e=>e!==null&&(!t||t(e.filePath,e.mtime)))}catch(t){return D(`Failed to read project directory ${e}:`,t),[]}}async function Fe(e,t,n=!1){let r=await k(O()),i=new Set,a=r.map(e=>Pe(e,t)),o=(await Promise.all(a)).flat().filter(e=>e!==null);n&&o.sort((e,t)=>t.mtime.getTime()-e.mtime.getTime());let s=o.map(e=>e.filePath),c=[],l=s.map(async t=>(await A(t)).filter(t=>!e||e(t))),u=await Promise.all(l);for(let e of u)c.push(...e);c.sort((e,t)=>e.timestamp.getTime()-t.timestamp.getTime());let d=[];for(let e of c){let t=Ae(e);t&&i.has(t)||(t&&i.add(t),d.push(e))}return d}var j=class{static CACHE_DIR=u.join(_(),`.claude`,`powerline`);static USAGE_CACHE_DIR=u.join(this.CACHE_DIR,`usage`);static LOCKS_DIR=u.join(this.CACHE_DIR,`locks`);static isLocked(e){let t=u.join(this.LOCKS_DIR,e);if(!o.existsSync(t))return!1;try{let n=o.readFileSync(t,`utf-8`),r=parseInt(n.trim(),10);if(isNaN(r))return D(`Invalid PID in lock file ${e}, removing stale lock`),o.unlinkSync(t),!1;try{return process.kill(r,0),!0}catch(n){return n.code===`ESRCH`?(D(`Removing stale lock file ${e} for dead process ${r}`),o.unlinkSync(t),!1):(D(`Error checking process ${r} for lock ${e}:`,n),!0)}}catch(t){return D(`Error reading lock file ${e}:`,t),!0}}static async acquireLock(e,t=5e3){await this.ensureCacheDirectories();let n=u.join(this.LOCKS_DIR,e),r=Date.now(),i=String(process.pid);for(;Date.now()-r<t;)try{return await o.promises.writeFile(n,i,{flag:`wx`}),D(`Lock acquired for ${e}`),!0}catch(e){if(e.code===`EEXIST`)await y(50);else throw e}return D(`Failed to acquire lock for ${e} within ${t}ms`),!1}static async releaseLock(e){let t=u.join(this.LOCKS_DIR,e);try{await o.promises.unlink(t),D(`Lock released for ${e}`)}catch(t){t.code!==`ENOENT`&&D(`Error releasing lock for ${e}:`,t)}}static async ensureCacheDirectories(){try{await Promise.all([o.promises.mkdir(this.CACHE_DIR,{recursive:!0}),o.promises.mkdir(this.USAGE_CACHE_DIR,{recursive:!0}),o.promises.mkdir(this.LOCKS_DIR,{recursive:!0})])}catch(e){D(`Failed to create cache directories:`,e)}}static createProjectHash(e){return v(`md5`).update(e).digest(`hex`).substring(0,8)}static async getUsageCache(e,t){await this.ensureCacheDirectories();let n=u.join(this.USAGE_CACHE_DIR,`${e}.json`),r=`${e}.usage.lock`;for(let i=0;i<3;i++){if(this.isLocked(r)){D(`Cache for ${e} is locked, waiting...`),await y(75);continue}try{let r=await o.promises.readFile(n,`utf-8`),i=JSON.parse(r);return!t||i.timestamp>=t?(D(`[CACHE-HIT] ${e} disk cache: found`),this.deserializeDates(i.data)):(D(`${e} cache outdated: cache=${i.timestamp}, latest=${t}`),null)}catch(t){if(t.code===`ENOENT`)return D(`No shared ${e} usage cache found`),null;D(`Attempt ${i+1} failed to read ${e} cache: ${t.message}. Retrying...`),await y(75)}}return D(`Failed to read ${e} cache after 3 attempts.`),null}static deserializeDates(e){return Array.isArray(e)?e.map(e=>({...e,timestamp:new Date(e.timestamp)})):e}static async setUsageCache(e,t,n){let r=`${e}.usage.lock`;if(!await this.acquireLock(r)){D(`Could not acquire lock to set usage cache for ${e}`);return}try{await this.ensureCacheDirectories();let r=u.join(this.USAGE_CACHE_DIR,`${e}.json`),i={data:t,timestamp:n||Date.now()},a=JSON.stringify(i);await o.promises.writeFile(r,a,`utf-8`),D(`[CACHE-SET] ${e} disk cache stored`)}catch(t){D(`Failed to save ${e} usage cache:`,t)}finally{await this.releaseLock(r)}}static async getLatestTranscriptMtime(){try{let e=await k(O()),t=0;for(let n of e)try{let e=(await o.promises.readdir(n)).filter(e=>e.endsWith(`.jsonl`));for(let r of e){let e=await ke(u.join(n,r));e&&e.getTime()>t&&(t=e.getTime())}}catch(e){D(`Failed to read project directory ${n}:`,e);continue}return t}catch(e){return D(`Failed to get latest transcript mtime:`,e),Date.now()}}};const M={"claude-haiku-4-5-20251001":{name:`Claude Haiku 4.5`,input:1,output:5,cache_write_5m:1.25,cache_write_1h:2,cache_read:.1},"claude-haiku-4-5":{name:`Claude Haiku 4.5`,input:1,output:5,cache_write_5m:1.25,cache_write_1h:2,cache_read:.1},"claude-opus-4-20250514":{name:`Claude Opus 4`,input:15,output:75,cache_write_5m:18.75,cache_write_1h:30,cache_read:1.5},"claude-opus-4-1":{name:`Claude Opus 4.1`,input:15,output:75,cache_write_5m:18.75,cache_write_1h:30,cache_read:1.5},"claude-opus-4-1-20250805":{name:`Claude Opus 4.1`,input:15,output:75,cache_write_5m:18.75,cache_write_1h:30,cache_read:1.5},"claude-sonnet-4-20250514":{name:`Claude Sonnet 4`,input:3,output:15,cache_write_5m:3.75,cache_write_1h:6,cache_read:.3},"claude-4-opus-20250514":{name:`Claude 4 Opus`,input:15,output:75,cache_write_5m:18.75,cache_write_1h:30,cache_read:1.5},"claude-4-sonnet-20250514":{name:`Claude 4 Sonnet`,input:3,output:15,cache_write_5m:3.75,cache_write_1h:6,cache_read:.3},"claude-sonnet-4-5":{name:`Claude Sonnet 4.5`,input:3,output:15,cache_write_5m:3.75,cache_write_1h:6,cache_read:.3},"claude-sonnet-4-5-20250929":{name:`Claude Sonnet 4.5`,input:3,output:15,cache_write_5m:3.75,cache_write_1h:6,cache_read:.3},"claude-opus-4-5":{name:`Claude Opus 4.5`,input:5,output:25,cache_write_5m:6.25,cache_write_1h:10,cache_read:.5},"claude-opus-4-5-20251101":{name:`Claude Opus 4.5`,input:5,output:25,cache_write_5m:6.25,cache_write_1h:10,cache_read:.5},"claude-opus-4-6":{name:`Claude Opus 4.6`,input:5,output:25,cache_write_5m:6.25,cache_write_1h:10,cache_read:.5},"claude-opus-4-6-20260205":{name:`Claude Opus 4.6`,input:5,output:25,cache_write_5m:6.25,cache_write_1h:10,cache_read:.5},"claude-sonnet-4-6":{name:`Claude Sonnet 4.6`,input:3,output:15,cache_write_5m:3.75,cache_write_1h:6,cache_read:.3}};var N=class{static executionCache=null;static modelPricingCache=new Map;static GITHUB_PRICING_URL=`https://raw.githubusercontent.com/Owloops/claude-powerline/main/pricing.json`;static async loadDiskCache(){let e=Date.now()-1440*60*1e3;return await j.getUsageCache(`pricing`,e)}static async saveDiskCache(e){await j.setUsageCache(`pricing`,e)}static async fetchPricingData(){return new Promise(e=>{let t=new h(this.GITHUB_PRICING_URL),n=m({hostname:t.hostname,path:t.pathname,headers:{"User-Agent":`claude-powerline`,"Cache-Control":`no-cache`},timeout:5e3},t=>{if(t.statusCode!==200){D(`HTTP ${t.statusCode}: ${t.statusMessage}`),e(null);return}let r=``,i=0;t.on(`data`,t=>{if(i+=t.length,i>1048576){D(`Response too large`),n.destroy(),e(null);return}r+=t}),t.on(`end`,()=>{try{let t=JSON.parse(r),n=t._meta,i={};for(let[e,n]of Object.entries(t))e!==`_meta`&&(i[e]=n);this.validatePricingData(i)?(D(`Fetched fresh pricing from GitHub for ${Object.keys(i).length} models`),D(`Pricing last updated: ${n?.updated||`unknown`}`),e(i)):(D(`Invalid pricing data structure`),e(null))}catch(t){D(`Failed to parse JSON:`,t),e(null)}}),t.on(`error`,t=>{D(`Response error:`,t),e(null)})});n.on(`error`,t=>{D(`Request error:`,t),e(null)}),n.on(`timeout`,()=>{D(`Request timeout`),n.destroy(),e(null)}),n.end()})}static async getCurrentPricing(){if(this.executionCache!==null)return D(`[CACHE-HIT] Pricing execution cache: ${Object.keys(this.executionCache).length} models`),this.executionCache;let e=await this.loadDiskCache();if(e)return D(`[CACHE-HIT] Pricing disk cache: ${Object.keys(e).length} models`),this.executionCache=e,D(`[CACHE-SET] Pricing execution cache stored: ${Object.keys(e).length} models`),e;let t=await this.fetchPricingData();return t?(await this.saveDiskCache(t),D(`[CACHE-SET] Pricing disk cache stored: ${Object.keys(t).length} models`),this.executionCache=t,D(`[CACHE-SET] Pricing execution cache stored: ${Object.keys(t).length} models`),t):(D(`[CACHE-FALLBACK] Using offline pricing data: ${Object.keys(M).length} models`),this.executionCache=M,D(`[CACHE-SET] Pricing execution cache stored: ${Object.keys(M).length} models`),M)}static validatePricingData(e){if(!e||typeof e!=`object`)return!1;for(let[,t]of Object.entries(e)){if(!t||typeof t!=`object`)return!1;let e=t;if(typeof e.input!=`number`||typeof e.output!=`number`||typeof e.cache_read!=`number`)return!1}return!0}static async getModelPricing(e){if(this.modelPricingCache.has(e))return D(`[CACHE-HIT] Model pricing cache: ${e}`),this.modelPricingCache.get(e);let t=await this.getCurrentPricing(),n;return n=t[e]?t[e]:this.fuzzyMatchModel(e,t),this.modelPricingCache.set(e,n),D(`[CACHE-SET] Model pricing cache: ${e}`),n}static fuzzyMatchModel(e,t){let n=e.toLowerCase();for(let[e,r]of Object.entries(t))if(e.toLowerCase()===n)return r;for(let{pattern:e,fallback:r}of[{pattern:[`opus-4-6`,`claude-opus-4-6`],fallback:`claude-opus-4-6-20260205`},{pattern:[`opus-4-5`,`claude-opus-4-5`],fallback:`claude-opus-4-5-20251101`},{pattern:[`opus-4-1`,`claude-opus-4-1`],fallback:`claude-opus-4-1-20250805`},{pattern:[`opus-4`,`claude-opus-4`],fallback:`claude-opus-4-20250514`},{pattern:[`sonnet-4-6`,`sonnet-4.6`,`claude-sonnet-4-6`],fallback:`claude-sonnet-4-6`},{pattern:[`sonnet-4.5`,`4-5-sonnet`,`sonnet-4-5`],fallback:`claude-sonnet-4-5-20250929`},{pattern:[`sonnet-4`,`claude-sonnet-4`],fallback:`claude-sonnet-4-20250514`},{pattern:[`haiku-4.5`,`4-5-haiku`,`haiku-4-5`],fallback:`claude-haiku-4-5-20251001`},{pattern:[`haiku`],fallback:`claude-haiku-4-5-20251001`},{pattern:[`opus`],fallback:`claude-opus-4-20250514`},{pattern:[`sonnet`],fallback:`claude-sonnet-4-5-20250929`}])if(e.some(e=>n.includes(e))&&t[r])return t[r];return t[`claude-sonnet-4-5-20250929`]||{name:`${e} (Unknown Model)`,input:3,cache_write_5m:3.75,cache_write_1h:6,cache_read:.3,output:15}}static async calculateCostForEntry(e){let t=e.message?.usage;if(!t)return 0;let n=this.extractModelId(e),r=await this.getModelPricing(n),i=t.input_tokens||0,a=t.output_tokens||0,o=t.cache_creation_input_tokens||0,s=t.cache_read_input_tokens||0,c=i/1e6*r.input,l=a/1e6*r.output,u=s/1e6*r.cache_read,d=o/1e6*r.cache_write_5m;return c+l+d+u}static extractModelId(e){if(e.model&&typeof e.model==`string`)return e.model;let t=e.message;if(t?.model){let e=t.model;return typeof e==`string`?e:e?.id||`claude-sonnet-4-5-20250929`}return e.model_id&&typeof e.model_id==`string`?e.model_id:`claude-sonnet-4-5-20250929`}};function Ie(e){return{timestamp:e.timestamp.toISOString(),message:{usage:{input_tokens:e.message?.usage?.input_tokens||0,output_tokens:e.message?.usage?.output_tokens||0,cache_creation_input_tokens:e.message?.usage?.cache_creation_input_tokens,cache_read_input_tokens:e.message?.usage?.cache_read_input_tokens}},costUSD:e.costUSD}}var Le=class{async getSessionUsage(e){try{let t=await De(e);if(!t)return D(`No transcript found for session: ${e}`),null;D(`Found transcript at: ${t}`);let n=await A(t),r=await Oe(e,d(t));D(`Found ${r.length} agent transcripts for session`);for(let e of r){let t=await A(e);n.push(...t)}if(n.length===0)return{totalCost:0,entries:[]};let i=[],a=0;for(let e of n)if(e.message?.usage){let t=Ie(e);if(t.costUSD!==void 0)a+=t.costUSD;else{let n=await N.calculateCostForEntry(e.raw);t.costUSD=n,a+=n}i.push(t)}return D(`Parsed ${i.length} usage entries, total cost: $${a.toFixed(4)}`),{totalCost:a,entries:i}}catch(t){return D(`Error reading session usage for ${e}:`,t),null}}calculateTokenBreakdown(e){return e.reduce((e,t)=>({input:e.input+(t.message.usage.input_tokens||0),output:e.output+(t.message.usage.output_tokens||0),cacheCreation:e.cacheCreation+(t.message.usage.cache_creation_input_tokens||0),cacheRead:e.cacheRead+(t.message.usage.cache_read_input_tokens||0)}),{input:0,output:0,cacheCreation:0,cacheRead:0})}async getSessionInfo(e,t){let n=await this.getSessionUsage(e);if(!n||n.entries.length===0)return{cost:null,calculatedCost:null,officialCost:null,tokens:null,tokenBreakdown:null};let r=this.calculateTokenBreakdown(n.entries),i=r.input+r.output+r.cacheCreation+r.cacheRead,a=n.totalCost,o=t?.cost?.total_cost_usd??null;return{cost:a??o,calculatedCost:a,officialCost:o,tokens:i,tokenBreakdown:r}}},Re=class{sessionProvider=new Le;async getUsageInfo(e,t){try{return D(`Starting usage info retrieval for session: ${e}`),{session:await this.sessionProvider.getSessionInfo(e,t)}}catch(t){return D(`Error getting usage info for session ${e}:`,t),{session:{cost:null,calculatedCost:null,officialCost:null,tokens:null,tokenBreakdown:null}}}}},ze=class{thresholds={LOW:50,MEDIUM:80};config;constructor(e){this.config=e}getContextUsageThresholds(){return this.thresholds}getContextLimit(e){let t=this.config.modelContextLimits||{default:2e5};return t[this.getModelType(e)]||t.default||2e5}getModelType(e){let t=e.toLowerCase();return t.includes(`sonnet`)?`sonnet`:t.includes(`opus`)?`opus`:`default`}calculatePercentages(e,t,n=33e3){let r=Math.min(100,Math.max(0,Math.round(e/t*100))),i=Math.max(1,t-n),a=Math.min(100,Math.max(0,Math.round(e/i*100)));return{percentage:r,usablePercentage:a,contextLeftPercentage:Math.max(0,100-a),usableTokens:i}}calculateContextFromHookData(e,t=33e3){let n=e.context_window?.current_usage;if(!n)return D(`No current_usage in hook data, falling back to transcript parsing`),null;let r=e.context_window?.context_window_size||2e5,i=(n.input_tokens||0)+(n.cache_creation_input_tokens||0)+(n.cache_read_input_tokens||0);D(`Native current_usage: input=${n.input_tokens}, cache_create=${n.cache_creation_input_tokens}, cache_read=${n.cache_read_input_tokens}, total=${i} (limit: ${r})`);let a=e.context_window?.used_percentage,o=this.calculatePercentages(i,r,t);return a!=null&&(o.percentage=Math.round(a),D(`Using native used_percentage: ${a}%`)),{totalTokens:i,maxTokens:r,...o}}async calculateContextTokensFromTranscript(e,t,n=33e3){try{D(`Calculating context tokens from transcript: ${e}`);try{if(!l(e,`utf-8`))return D(`Transcript file is empty`),null}catch{return D(`Could not read transcript file`),null}let r=await A(e);if(r.length===0)return D(`No entries in transcript`),null;let i=null;for(let e=r.length-1;e>=0;e--){let t=r[e];if(t&&t.message?.usage?.input_tokens&&t.isSidechain!==!0){i=t,D(`Context segment: Found most recent entry at ${t.timestamp.toISOString()}, stopping search`);break}}if(i?.message?.usage){let e=i.message.usage,r=(e.input_tokens||0)+(e.cache_read_input_tokens||0)+(e.cache_creation_input_tokens||0),a=t?this.getContextLimit(t):2e5;return D(`Most recent main chain context: ${r} tokens (limit: ${a})`),{totalTokens:r,maxTokens:a,...this.calculatePercentages(r,a,n)}}return D(`No main chain entries with usage data found`),null}catch(e){return D(`Error reading transcript: ${e instanceof Error?e.message:String(e)}`),null}}async getContextInfo(e,t=33e3){return this.calculateContextFromHookData(e,t)||this.calculateContextTokensFromTranscript(e.transcript_path,e.model?.id,t)}},Be=class{async loadTranscriptEntries(e){try{let t=await De(e);if(!t)return D(`No transcript found for session: ${e}`),[];D(`Loading transcript from: ${t}`);let n=(await b(t,`utf-8`)).trim().split(`
|
|
7
7
|
`).filter(e=>e.trim()),r=[];for(let e of n)try{let t=JSON.parse(e);if(t.isSidechain===!0)continue;r.push(t)}catch(e){D(`Failed to parse JSONL line: ${e}`);continue}return D(`Loaded ${r.length} transcript entries`),r}catch(t){return D(`Error loading transcript for ${e}:`,t),[]}}calculateMessageCount(e){return e.filter(e=>{let t=e.type||e.message?.role||e.message?.type,n=e.type===`user`&&e.message?.content?.[0]?.type===`tool_result`;return t===`user`&&!n}).length}calculateLastResponseTime(e){if(e.length===0)return null;let t=e.slice(-20),n=null,r=null;for(let e of t)if(e.timestamp)try{let t=new Date(e.timestamp),i=e.type||e.message?.role||e.message?.type,a=e.type===`user`&&e.message?.content?.[0]?.type===`tool_result`;if(i===`user`&&!a)n=t;else if(i===`assistant`&&n){let e=(t.getTime()-n.getTime())/1e3;e>.1&&e<300&&(r=e)}}catch{continue}return r}async getMetricsInfo(e,t){try{if(D(`Getting metrics from hook data for session: ${e}`),!t.cost)return D(`No cost data available in hook data`),{responseTime:null,lastResponseTime:null,sessionDuration:null,messageCount:null,linesAdded:null,linesRemoved:null};let n=await this.loadTranscriptEntries(e),r=this.calculateMessageCount(n),i=this.calculateLastResponseTime(n);return{responseTime:t.cost.total_api_duration_ms/1e3,lastResponseTime:i,sessionDuration:t.cost.total_duration_ms/1e3,messageCount:r,linesAdded:t.cost.total_lines_added,linesRemoved:t.cost.total_lines_removed}}catch(t){return D(`Error getting metrics from hook data for session ${e}:`,t),{responseTime:null,lastResponseTime:null,sessionDuration:null,messageCount:null,linesAdded:null,linesRemoved:null}}}};function P(e){return e===null?`$0.00`:e<.01?`<$0.01`:`$${e.toFixed(2)}`}function F(e){return e===null||e===0?`0 tokens`:e>=1e6?`${(e/1e6).toFixed(1)}M tokens`:e>=1e3?`${(e/1e3).toFixed(1)}K tokens`:`${e} tokens`}function Ve(e){if(!e)return`0 tokens`;let t=[];if(e.input>0&&t.push(`${F(e.input).replace(` tokens`,``)} in`),e.output>0&&t.push(`${F(e.output).replace(` tokens`,``)} out`),e.cacheCreation>0||e.cacheRead>0){let n=e.cacheCreation+e.cacheRead;t.push(`${F(n).replace(` tokens`,``)} cached`)}return t.length>0?t.join(` + `):`0 tokens`}function He(e){return e<60?`${e}s`:e<3600?`${Math.floor(e/60)}m`:e<86400?`${Math.floor(e/3600)}h`:e<604800?`${Math.floor(e/86400)}d`:`${Math.floor(e/604800)}w`}function Ue(e){return e<60?`${e.toFixed(0)}s`:e<3600?`${(e/60).toFixed(0)}m`:e<86400?`${(e/3600).toFixed(1)}h`:`${(e/86400).toFixed(1)}d`}const We=/^(?:(?:global|apac|au|eu|us|us-east-\d|us-west-\d|eu-west-\d|eu-central-\d)\.)?(?:anthropic\.|azure_ai\/|bedrock\/|vertex_ai\/)?claude-(?:(?<family>opus|sonnet|haiku)-(?<newMajor>\d+)(?:-(?<newMinor>\d))?|(?<oldMajor>\d+)(?:-(?<oldMinor>\d))?-(?<oldFamily>opus|sonnet|haiku))(?:[-@]\d{8})?(?:-v\d+:\d+)?(?:-latest)?$/i;function Ge(e){if(!e)return`Claude`;let t=e.trim().match(We);if(!t?.groups)return e;let{family:n,newMajor:r,newMinor:i,oldMajor:a,oldMinor:o,oldFamily:s}=t.groups,c=n||s,l=r||a,u=i||o;return c&&l?`${c.charAt(0).toUpperCase()+c.slice(1).toLowerCase()} ${u?`${l}.${u}`:l}`:e}function Ke(e){let t=e.includes(`/`)?`/`:`\\`,n=e.split(t);return n.map((e,t)=>t===n.length-1||e===`~`||e===``?e:e.charAt(0)).join(t)}function qe(e){return e<60?`${e.toFixed(1)}s`:`${(e/60).toFixed(1)}m`}function I(e){let t=Math.floor(e/60),n=e%60;return t>0?`${t}h ${n}m left`:`${n}m left`}function Je(e){if(e>=1440){let t=Math.floor(e/1440),n=Math.floor(e%1440/60);return n>0?`${t}d ${n}h`:`${t}d`}else if(e>=60){let t=Math.floor(e/60),n=e%60;return n>0?`${t}h ${n}m`:`${t}h`}return`${e}m`}function L(e){return Math.round(Math.max(0,e*1e3-Date.now())/6e4)}function Ye(e,t){return!t||t<=0||e<0?null:Math.min(100,e/t*100)}function R(e,t,n=80){let r=Ye(e,t);if(r===null)return{percentage:null,isWarning:!1,displayText:``};let i=`${r.toFixed(0)}%`,a=r>=n,o=``;return o=a?` !${i}`:r>=50?` +${i}`:` ${i}`,{percentage:r,isWarning:a,displayText:o}}const Xe={ball:{filled:`─`,empty:`─`,marker:`●`},blocks:{filled:`█`,empty:`░`},"blocks-line":{filled:`█`,empty:`─`},capped:{filled:`━`,empty:`┄`,cap:`╸`},dots:{filled:`●`,empty:`○`},filled:{filled:`■`,empty:`□`},geometric:{filled:`▰`,empty:`▱`},line:{filled:`━`,empty:`┄`},squares:{filled:`◼`,empty:`◻`}};var Ze=class{constructor(e,t){this.config=e,this.symbols=t}renderDirectory(e,t,n){let r=e.workspace?.current_dir||e.cwd||`/`,i=e.workspace?.project_dir,a=n?.style??(n?.showBasename?`basename`:`full`);if(a===`basename`)return{text:u.basename(r)||`root`,bgColor:t.modeBg,fgColor:t.modeFg};let o=process.env.HOME||process.env.USERPROFILE,s=r,c=i;o&&(r.startsWith(o)&&(s=r.replace(o,`~`)),i&&i.startsWith(o)&&(c=i.replace(o,`~`)));let l=this.getDisplayDirectoryName(s,c);return a===`fish`&&(l=Ke(l)),{text:l,bgColor:t.modeBg,fgColor:t.modeFg}}renderGit(e,t,n){if(!e)return null;let r=[];if(n?.showRepoName&&e.repoName&&(r.push(e.repoName),e.isWorktree&&r.push(this.symbols.git_worktree)),n?.showOperation&&e.operation&&r.push(`[${e.operation}]`),r.push(`${this.symbols.branch} ${e.branch}`),n?.showTag&&e.tag&&r.push(`${this.symbols.git_tag} ${e.tag}`),n?.showSha&&e.sha&&r.push(`${this.symbols.git_sha} ${e.sha}`),n?.showAheadBehind!==!1&&(e.ahead>0&&e.behind>0?r.push(`${this.symbols.git_ahead}${e.ahead}${this.symbols.git_behind}${e.behind}`):e.ahead>0?r.push(`${this.symbols.git_ahead}${e.ahead}`):e.behind>0&&r.push(`${this.symbols.git_behind}${e.behind}`)),n?.showWorkingTree){let t=[];e.staged&&e.staged>0&&t.push(`+${e.staged}`),e.unstaged&&e.unstaged>0&&t.push(`~${e.unstaged}`),e.untracked&&e.untracked>0&&t.push(`?${e.untracked}`),e.conflicts&&e.conflicts>0&&t.push(`!${e.conflicts}`),t.length>0&&r.push(`(${t.join(` `)})`)}if(n?.showUpstream&&e.upstream&&r.push(`${this.symbols.git_upstream}${e.upstream}`),n?.showStashCount&&e.stashCount&&e.stashCount>0&&r.push(`${this.symbols.git_stash} ${e.stashCount}`),n?.showTimeSinceCommit&&e.timeSinceCommit!==void 0){let t=He(e.timeSinceCommit);r.push(`${this.symbols.git_time} ${t}`)}let i=this.symbols.git_clean;return e.status===`conflicts`?i=this.symbols.git_conflicts:e.status===`dirty`&&(i=this.symbols.git_dirty),r.push(i),{text:r.join(` `),bgColor:t.gitBg,fgColor:t.gitFg}}renderModel(e,t){let n=Ge(e.model?.display_name||`Claude`);return{text:`${this.symbols.model} ${n}`,bgColor:t.modelBg,fgColor:t.modelFg}}renderSession(e,t,n){let r=n?.type||`cost`,i=n?.costSource,a=this.config.budget?.session,o=this.formatUsageWithBudget(i===`calculated`?e.session.calculatedCost:i===`official`?e.session.officialCost:e.session.cost,e.session.tokens,e.session.tokenBreakdown,r,a?.amount,a?.warningThreshold||80,a?.type);return{text:`${this.symbols.session_cost} ${o}`,bgColor:t.sessionBg,fgColor:t.sessionFg}}renderSessionId(e,t,n){return{text:n?.showIdLabel===!1?e:`${this.symbols.session_id} ${e}`,bgColor:t.sessionBg,fgColor:t.sessionFg}}renderTmux(e,t){return e?{text:`tmux:${e}`,bgColor:t.tmuxBg,fgColor:t.tmuxFg}:{text:`tmux:none`,bgColor:t.tmuxBg,fgColor:t.tmuxFg}}renderContext(e,t,n){let r=n?.displayStyle??`text`,i=r===`text`?`remaining`:`used`,a=n?.percentageMode??i,o=this.resolveBarStyleDef(r),s=a===`remaining`?`100%`:`0%`;if(!e)return o?{text:`${o.empty.repeat(10)} ${s}`,bgColor:t.contextBg,fgColor:t.contextFg}:{text:`${this.symbols.context_time} 0 (${s})`,bgColor:t.contextBg,fgColor:t.contextFg};let c=t.contextBg,l=t.contextFg;e.contextLeftPercentage<=20?(c=t.contextCriticalBg,l=t.contextCriticalFg):e.contextLeftPercentage<=40&&(c=t.contextWarningBg,l=t.contextWarningFg);let u=a===`remaining`?e.contextLeftPercentage:e.usablePercentage,d=Math.round(e.usablePercentage/100*10),f=10-d;if(o){let t=this.buildBar(o,d,f,10);return{text:n?.showPercentageOnly?`${t} ${u}%`:`${t} ${e.totalTokens.toLocaleString()} (${u}%)`,bgColor:c,fgColor:l}}return{text:n?.showPercentageOnly?`${this.symbols.context_time} ${u}%`:`${this.symbols.context_time} ${e.totalTokens.toLocaleString()} (${u}%)`,bgColor:c,fgColor:l}}buildBar(e,t,n,r){if(e.marker){let n=Math.min(t,r-1);return e.filled.repeat(n)+e.marker+e.empty.repeat(r-n-1)}return e.cap?t===0?e.cap+e.empty.repeat(r-1):t>=r?e.filled.repeat(r):e.filled.repeat(t-1)+e.cap+e.empty.repeat(n):e.filled.repeat(t)+e.empty.repeat(n)}resolveBarStyleDef(e){return e===`bar`?{filled:this.symbols.bar_filled,empty:this.symbols.bar_empty}:Xe[e]??null}formatPercentageWithBar(e,t,n){let r=t??`text`,i=this.resolveBarStyleDef(r);if(i){let t=Math.round(e/100*10),r=10-t,a=this.buildBar(i,t,r,10);return n?`${a} ${e}% (${n})`:`${a} ${e}%`}return n?`${e}% (${n})`:`${e}%`}renderMetrics(e,t,n,r){if(!e)return{text:`${this.symbols.metrics_response} new`,bgColor:t.metricsBg,fgColor:t.metricsFg};let i=[];if(r?.showLastResponseTime&&e.lastResponseTime!==null){let t=e.lastResponseTime<60?`${e.lastResponseTime.toFixed(1)}s`:`${(e.lastResponseTime/60).toFixed(1)}m`;i.push(`${this.symbols.metrics_last_response} ${t}`)}if(r?.showResponseTime!==!1&&e.responseTime!==null){let t=e.responseTime<60?`${e.responseTime.toFixed(1)}s`:`${(e.responseTime/60).toFixed(1)}m`;i.push(`${this.symbols.metrics_response} ${t}`)}if(r?.showDuration!==!1&&e.sessionDuration!==null){let t=Ue(e.sessionDuration);i.push(`${this.symbols.metrics_duration} ${t}`)}return r?.showMessageCount!==!1&&e.messageCount!==null&&i.push(`${this.symbols.metrics_messages} ${e.messageCount}`),r?.showLinesAdded!==!1&&e.linesAdded!==null&&e.linesAdded>0&&i.push(`${this.symbols.metrics_lines_added} ${e.linesAdded}`),r?.showLinesRemoved!==!1&&e.linesRemoved!==null&&e.linesRemoved>0&&i.push(`${this.symbols.metrics_lines_removed} ${e.linesRemoved}`),i.length===0?{text:`${this.symbols.metrics_response} active`,bgColor:t.metricsBg,fgColor:t.metricsFg}:{text:i.join(` `),bgColor:t.metricsBg,fgColor:t.metricsFg}}renderBlock(e,t,n){return e.source===`native`&&e.nativeUtilization!==null?this.renderNativeBlock(e,t,n):this.renderTranscriptBlock(e,t,n)}renderNativeBlock(e,t,n){let r=Math.round(e.nativeUtilization),i=this.formatBlockTimeRemaining(e.timeRemaining),a=this.config.budget?.block?.warningThreshold??80,o=t.blockBg,s=t.blockFg;return r>=a?(o=t.contextCriticalBg,s=t.contextCriticalFg):r>=50&&(o=t.contextWarningBg,s=t.contextWarningFg),{text:`${this.symbols.block_cost} ${this.formatPercentageWithBar(r,n?.displayStyle,i)}`,bgColor:o,fgColor:s}}renderTranscriptBlock(e,t,n){let r;if(e.cost===null&&e.tokens===null)r=`No active block`;else{let t=n?.type||`cost`,i=n?.burnType,a=this.config.budget?.block,o=this.formatBlockTimeRemaining(e.timeRemaining),s;switch(t){case`cost`:s=this.formatUsageWithBudget(e.cost,null,null,`cost`,a?.amount,a?.warningThreshold,a?.type);break;case`tokens`:s=this.formatUsageWithBudget(null,e.tokens,null,`tokens`,a?.amount,a?.warningThreshold,a?.type);break;case`weighted`:{let t=a?.type===`tokens`?a.amount:void 0,n=F(e.weightedTokens);s=t&&e.weightedTokens!==null?`${n}${R(e.weightedTokens,t,a?.warningThreshold||80).displayText}`:`${n} (weighted)`;break}case`both`:s=this.formatUsageWithBudget(e.cost,e.tokens,null,`both`,a?.amount,a?.warningThreshold,a?.type);break;case`time`:s=o||`N/A`;break;default:s=this.formatUsageWithBudget(e.cost,null,null,`cost`,a?.amount,a?.warningThreshold,a?.type)}let c=``;if(i&&i!==`none`)switch(i){case`cost`:c=` | ${e.burnRate===null?`N/A`:e.burnRate<1?`${(e.burnRate*100).toFixed(0)}¢/h`:`$${e.burnRate.toFixed(2)}/h`}`;break;case`tokens`:c=` | ${e.tokenBurnRate===null?`N/A`:`${F(Math.round(e.tokenBurnRate))}/h`}`;break;case`both`:c=` | ${e.burnRate===null?`N/A`:e.burnRate<1?`${(e.burnRate*100).toFixed(0)}¢/h`:`$${e.burnRate.toFixed(2)}/h`} / ${e.tokenBurnRate===null?`N/A`:`${F(Math.round(e.tokenBurnRate))}/h`}`;break}r=t===`time`?s:o?`${s}${c} (${o} left)`:`${s}${c}`}return{text:`${this.symbols.block_cost} ${r}`,bgColor:t.blockBg,fgColor:t.blockFg}}formatBlockTimeRemaining(e){if(e===null)return null;let t=Math.floor(e/60),n=e%60;return t>0?`${t}h ${n}m`:`${n}m`}renderWeekly(e,t,n){let r=e.rate_limits?.seven_day;if(!r)return null;let i=Math.round(r.used_percentage),a=Je(L(r.resets_at)),o=t.weeklyBg,s=t.weeklyFg;return i>=80?(o=t.contextCriticalBg,s=t.contextCriticalFg):i>=50&&(o=t.contextWarningBg,s=t.contextWarningFg),{text:`${this.symbols.weekly_cost} ${this.formatPercentageWithBar(i,n?.displayStyle,a)}`,bgColor:o,fgColor:s}}renderToday(e,t,n=`cost`){let r=this.config.budget?.today;return{text:`${this.symbols.today_cost} ${this.formatUsageWithBudget(e.cost,e.tokens,e.tokenBreakdown,n,r?.amount,r?.warningThreshold,r?.type)}`,bgColor:t.todayBg,fgColor:t.todayFg}}getDisplayDirectoryName(e,t){return e.startsWith(`~`)?e:t&&t!==e&&e.startsWith(t)?e.slice(t.length+1)||u.basename(t)||`project`:e}formatUsageDisplay(e,t,n,r){switch(r){case`cost`:return P(e);case`tokens`:return F(t);case`both`:return`${P(e)} (${F(t)})`;case`breakdown`:return Ve(n);default:return P(e)}}formatUsageWithBudget(e,t,n,r,i,a=80,o){let s=this.formatUsageDisplay(e,t,n,r);if(i&&i>0){let n=null;if(o===`tokens`&&t!==null?n=t:(o===`cost`&&e!==null||!o&&e!==null)&&(n=e),n!==null)return s+R(n,i,a).displayText}return s}renderVersion(e,t,n){return e.version?{text:`${this.symbols.version} v${e.version}`,bgColor:t.versionBg,fgColor:t.versionFg}:null}renderEnv(e,t){let n=process.env[t.variable];if(!n)return null;let r=t.prefix??t.variable;return{text:r?`${this.symbols.env} ${r}: ${n}`:`${this.symbols.env} ${n}`,bgColor:e.envBg,fgColor:e.envFg}}};function Qe(e){return e.includes(`opus`)?5:(e.includes(`sonnet`)||e.includes(`haiku`),1)}function $e(e){return{timestamp:e.timestamp,usage:{inputTokens:e.message?.usage?.input_tokens||0,outputTokens:e.message?.usage?.output_tokens||0,cacheCreationInputTokens:e.message?.usage?.cache_creation_input_tokens||0,cacheReadInputTokens:e.message?.usage?.cache_read_input_tokens||0},costUSD:e.costUSD||0,model:e.message?.model||`unknown`}}var et=class{sessionDurationHours=5;floorToHour(e){let t=new Date(e);return t.setUTCMinutes(0,0,0),t}identifySessionBlocks(e){if(e.length===0)return[];let t=this.sessionDurationHours*60*60*1e3,n=[],r=[...e].sort((e,t)=>e.timestamp.getTime()-t.timestamp.getTime()),i=null,a=[];for(let e of r){let r=e.timestamp;if(i==null)i=this.floorToHour(r),a=[e];else{let o=r.getTime()-i.getTime(),s=a[a.length-1];if(s==null)continue;let c=s.timestamp,l=r.getTime()-c.getTime();o>t||l>t?(n.push(a),i=this.floorToHour(r),a=[e]):a.push(e)}}return i!=null&&a.length>0&&n.push(a),n}createBlockInfo(e,t){let n=new Date,r=this.sessionDurationHours*60*60*1e3,i=new Date(e.getTime()+r),a=t[t.length-1],o=a==null?e:a.timestamp;return{block:t,isActive:n.getTime()-o.getTime()<r&&n<i}}findActiveBlock(e){for(let t=e.length-1;t>=0;t--){let n=e[t];if(!n||n.length===0)continue;let r=n[0];if(!r)continue;let i=this.floorToHour(r.timestamp),a=this.createBlockInfo(i,n);if(a.isActive)return a.block}return null}async loadUsageEntries(){try{D(`Block segment: Loading entries for dynamic session blocks`);let e=new Date;e.setDate(e.getDate()-1);let t=await Fe(void 0,(t,n)=>n>=e,!0),n=[];for(let e of t)if(e.message?.usage){let t=$e(e);!t.costUSD&&e.raw&&(t.costUSD=await N.calculateCostForEntry(e.raw)),n.push(t)}let r=this.identifySessionBlocks(n);D(`Block segment: Found ${r.length} session blocks`);let i=this.findActiveBlock(r),a=[];if(i&&i.length>0){D(`Block segment: Found active block with ${i.length} entries`);let e=i[0],t=i[i.length-1];e&&t&&D(`Block segment: Active block from ${e.timestamp.toISOString()} to ${t.timestamp.toISOString()}`),a=i}else D(`Block segment: No active block found`),a=[];return a}catch(e){return D(`Error loading block entries:`,e),[]}}async getActiveBlockInfo(e){let t=e?.rate_limits?.five_hour;if(t){let e=L(t.resets_at);return D(`Block segment: Using native rate_limits: ${t.used_percentage}%, resets in ${e}m`),{cost:null,tokens:null,weightedTokens:null,timeRemaining:e,burnRate:null,tokenBurnRate:null,source:`native`,nativeUtilization:t.used_percentage}}try{let e=await this.loadUsageEntries();if(e.length===0)return D(`Block segment: No entries in current block`),{cost:null,tokens:null,weightedTokens:null,timeRemaining:null,burnRate:null,tokenBurnRate:null,source:`transcript`,nativeUtilization:null};let t=e.reduce((e,t)=>e+t.costUSD,0),n=e.reduce((e,t)=>e+t.usage.inputTokens+t.usage.outputTokens+t.usage.cacheCreationInputTokens+t.usage.cacheReadInputTokens,0),r=e.reduce((e,t)=>e+(t.usage.inputTokens+t.usage.outputTokens+t.usage.cacheCreationInputTokens+t.usage.cacheReadInputTokens)*Qe(t.model),0),i=new Date,a=null;if(e.length>0){let t=e[0];if(t){let e=this.sessionDurationHours*60*60*1e3,n=this.floorToHour(t.timestamp),r=new Date(n.getTime()+e);a=Math.max(0,Math.round((r.getTime()-i.getTime())/(1e3*60)))}}let o=null,s=null;if(e.length>=1&&(t>0||n>0)){let r=e.map(e=>e.timestamp).sort((e,t)=>e.getTime()-t.getTime()),i=r[0],a=r[r.length-1];if(i&&a){let e=(a.getTime()-i.getTime())/(1e3*60);e>0&&(t>0&&(o=t/e*60),n>0&&(s=n/e*60))}}return D(`Block segment: $${t.toFixed(2)}, ${n} tokens, ${a}m remaining, burn rate: ${o?`$`+o.toFixed(2)+`/hr`:`N/A`}`),{cost:t,tokens:n,weightedTokens:r,timeRemaining:a,burnRate:o,tokenBurnRate:s,source:`transcript`,nativeUtilization:null}}catch(e){return D(`Error getting active block info:`,e),{cost:null,tokens:null,weightedTokens:null,timeRemaining:null,burnRate:null,tokenBurnRate:null,source:`transcript`,nativeUtilization:null}}}};function z(e){return`${e.getFullYear()}-${String(e.getMonth()+1).padStart(2,`0`)}-${String(e.getDate()).padStart(2,`0`)}`}function tt(e){return e.inputTokens+e.outputTokens+e.cacheCreationInputTokens+e.cacheReadInputTokens}function nt(e){return{timestamp:e.timestamp,usage:{inputTokens:e.message?.usage?.input_tokens||0,outputTokens:e.message?.usage?.output_tokens||0,cacheCreationInputTokens:e.message?.usage?.cache_creation_input_tokens||0,cacheReadInputTokens:e.message?.usage?.cache_read_input_tokens||0},costUSD:e.costUSD||0,model:e.message?.model||`unknown`}}var rt=class{async loadTodayEntries(){let e=z(new Date);D(`Today segment: Loading entries for date ${e}`);let t=await j.getLatestTranscriptMtime(),n=await j.getUsageCache(`today`,t);if(n)return D(`Using shared today usage cache`),n;let r=new Date;r.setDate(r.getDate()-1),r.setHours(0,0,0,0);let i=(e,t)=>t>=r,a=new Date;a.setHours(0,0,0,0);let o=await Fe(e=>e.timestamp>=a,i,!0),s=[],c=0;for(let t of o)if(z(t.timestamp)===e&&t.message?.usage){let e=nt(t);!e.costUSD&&t.raw&&(e.costUSD=await N.calculateCostForEntry(t.raw)),s.push(e),c++}return D(`Today segment: Found ${c} entries for today (${e})`),await j.setUsageCache(`today`,s,t),s}async getTodayEntries(){try{return await this.loadTodayEntries()}catch(e){return D(`Error loading today's entries:`,e),[]}}async getTodayInfo(){try{let e=await this.getTodayEntries();if(e.length===0)return{cost:null,tokens:null,tokenBreakdown:null,date:z(new Date)};let t=e.reduce((e,t)=>e+t.costUSD,0),n=e.reduce((e,t)=>e+tt(t.usage),0),r=e.reduce((e,t)=>({input:e.input+t.usage.inputTokens,output:e.output+t.usage.outputTokens,cacheCreation:e.cacheCreation+t.usage.cacheCreationInputTokens,cacheRead:e.cacheRead+t.usage.cacheReadInputTokens}),{input:0,output:0,cacheCreation:0,cacheRead:0});return D(`Today segment: $${t.toFixed(2)}, ${n} tokens total`),{cost:t,tokens:n,tokenBreakdown:r,date:z(new Date)}}catch(e){return D(`Error getting today's info:`,e),{cost:null,tokens:null,tokenBreakdown:null,date:z(new Date)}}}};const it={right:``,left_rounded:``,right_rounded:``,branch:`⎇`,model:`✱`,git_clean:`✓`,git_dirty:`●`,git_conflicts:`⚠`,git_ahead:`↑`,git_behind:`↓`,git_worktree:`⧉`,git_tag:`⌂`,git_sha:`♯`,git_upstream:`→`,git_stash:`⧇`,git_time:`◷`,session_cost:`§`,block_cost:`◱`,today_cost:`☉`,context_time:`◔`,metrics_response:`⧖`,metrics_last_response:`Δ`,metrics_duration:`⧗`,metrics_messages:`◆`,metrics_lines_added:`+`,metrics_lines_removed:`-`,metrics_burn:`↗`,version:`◈`,bar_filled:`▪`,bar_empty:`▫`,env:`⚙`,session_id:`⌗`,weekly_cost:`◑`},at={topLeft:`╭`,topRight:`╮`,bottomLeft:`╰`,bottomRight:`╯`,horizontal:`─`,vertical:`│`,teeLeft:`├`,teeRight:`┤`},ot={topLeft:`+`,topRight:`+`,bottomLeft:`+`,bottomRight:`+`,horizontal:`-`,vertical:`|`,teeLeft:`+`,teeRight:`+`},st={right:``,left_rounded:``,right_rounded:``,branch:`~`,model:`M`,git_clean:`=`,git_dirty:`*`,git_conflicts:`!`,git_ahead:`^`,git_behind:`v`,git_worktree:`W`,git_tag:`T`,git_sha:`#`,git_upstream:`>>`,git_stash:`S`,git_time:`@`,session_cost:`S`,block_cost:`B`,today_cost:`D`,context_time:`C`,metrics_response:`R`,metrics_last_response:`L`,metrics_duration:`T`,metrics_messages:`#`,metrics_lines_added:`+`,metrics_lines_removed:`-`,metrics_burn:`~/h`,version:`V`,bar_filled:`=`,bar_empty:`-`,env:`$`,session_id:`#`,weekly_cost:`W`},ct=RegExp(`\x1B\\[[0-9;]*m`,`g`),lt=/^[a-zA-Z0-9/]+$/;function ut(){if(process.platform===`win32`)return null;let e=process.pid.toString();for(let t=0;t<10;t++)try{let t=i(`ps -o ppid=,tty= -p ${e}`,{encoding:`utf8`,stdio:[`pipe`,`pipe`,`ignore`]}).trim().split(/\s+/),n=t[0],r=t[1];if(r&&r!==`?`&&r!==`??`&<.test(r))return r;if(!n||n===`1`||n===`0`)break;e=n}catch{break}return null}function dt(){try{let e=i(`mode con`,{encoding:`utf8`,stdio:[`pipe`,`pipe`,`ignore`],windowsHide:!0}).match(/Columns:\s*(\d+)/i);if(e?.[1]){let t=parseInt(e[1],10);if(!isNaN(t)&&t>0)return t}}catch{}return null}function ft(){let e=ut();if(e)try{let t=i(`stty size < /dev/${e}`,{encoding:`utf8`,stdio:[`pipe`,`pipe`,`ignore`],shell:`/bin/sh`}).trim().split(` `)[1];if(t){let e=parseInt(t,10);if(!isNaN(e)&&e>0)return e}}catch{}try{let e=i(`tput cols 2>/dev/null`,{encoding:`utf8`,stdio:[`pipe`,`pipe`,`ignore`]}).trim(),t=parseInt(e,10);if(!isNaN(t)&&t>0)return t}catch{}return null}function pt(){let e=e=>Math.floor(e*.7),t=process.env.COLUMNS;if(t){let n=parseInt(t,10);if(!isNaN(n)&&n>0)return e(n)}if(process.stdout.columns&&process.stdout.columns>0)return e(process.stdout.columns);if(process.platform===`win32`){let t=dt();if(t)return e(t)}let n=ft();return n?e(n):null}function mt(e){return e.replace(ct,``)}function B(e){return mt(e).length}function V(e,t,n){return t?`${t}${e}${n}`:e}function ht(e,t){let n=B(e);return n>=t?e:e+` `.repeat(t-n)}const gt=RegExp(`(\x1B\\[[0-9;]*m)`);function _t(e,t){if(mt(e).length<=t)return e;let n=0,r=``,i=e.split(gt);for(let e of i){if(e.startsWith(`\x1B`)){r+=e;continue}for(let i of e){if(n>=t-1)return r+=`…`,r;r+=i,n++}}return r}function H(e,t,n){let r=n-2,i=ht(_t(t,r),r);return e.vertical+` `+i+` `+e.vertical}function U(e,t){return e.teeLeft+e.horizontal.repeat(t)+e.teeRight}function vt(e,t){return e.bottomLeft+e.horizontal.repeat(t)+e.bottomRight}function yt(e,t){if(e.length===0)return``;if(e.length===1)return e[0]??``;let n=e.map(e=>B(e)),r=t-n.reduce((e,t)=>e+t,0),i=Math.max(2,Math.floor(r/(e.length-1))),a=Array(e.length);a[e.length-1]=n[e.length-1]??0;for(let t=e.length-2;t>=0;t--)a[t]=(a[t+1]??0)+(n[t]??0);let o=e[0]??``,s=n[0]??0;for(let r=1;r<e.length;r++){let c=t-s-(a[r]??0)-(e.length-1-r)*2,l=Math.max(2,Math.min(i,c));o+=` `.repeat(l)+(e[r]??``),s+=l+(n[r]??0)}return o}function W(e,t,n){if(!t)return e;if(!e)return t;let r=B(e),i=B(t),a=n-r-i;return a<2?`${e} ${t}`:e+` `.repeat(a)+t}function bt(e,t,n){let r=` ${Ge(e.hookData.model?.display_name||`Claude`).toLowerCase()} `,i=n-1-r.length-18;if(i<2){let e=n-1-r.length;return t.topLeft+t.horizontal+r+t.horizontal.repeat(Math.max(0,e))+t.topRight}return t.topLeft+t.horizontal+r+t.horizontal.repeat(i)+` claude-powerline `+t.topRight}function xt(e,t,n,r,i){let a=Math.min(Math.floor(t*.45),40);if(!e.contextInfo)return null;let o=e.contextInfo.usablePercentage,s=Math.round(o/100*a),c=a-s,l=n.bar_filled.repeat(s)+n.bar_empty.repeat(c),u=e.contextInfo.totalTokens>=1e3?`${(e.contextInfo.totalTokens/1e3).toFixed(0)}k`:`${e.contextInfo.totalTokens}`,d=e.contextInfo.maxTokens>=1e3?`${(e.contextInfo.maxTokens/1e3).toFixed(0)}k`:`${e.contextInfo.maxTokens}`,f=i.contextFg;return o>=80?f=i.contextCriticalFg:o>=60&&(f=i.contextWarningFg),V(`${l} ${o}% ${u}/${d}`,f,r)}function St(e){let t=e.workspace?.current_dir||e.cwd||`/`,n=process.env.HOME||process.env.USERPROFILE;return n&&t.startsWith(n)?t.replace(n,`~`):t}function Ct(e,t,n,r,i){let a=[];e.blockInfo&&a.push(V(q(e.blockInfo,t,n),i.blockFg,r));let o=e.hookData.rate_limits?.seven_day;o&&a.push(V(J(o,t),i.weeklyFg,r)),e.usageInfo&&a.push(V(Tt(e.usageInfo,t,n),i.sessionFg,r)),e.todayInfo&&a.push(V(Et(e.todayInfo,t,n),i.todayFg,r));let s=wt(e,t);return s.length>0&&a.push(V(s.join(` · `),i.metricsFg,r)),a}function wt(e,t){let n=[];return e.metricsInfo&&(e.metricsInfo.sessionDuration!==null&&e.metricsInfo.sessionDuration>0&&n.push(`${t.metrics_duration} ${Ue(e.metricsInfo.sessionDuration)}`),e.metricsInfo.messageCount!==null&&e.metricsInfo.messageCount>0&&n.push(`${t.metrics_messages} ${e.metricsInfo.messageCount}`)),n}function G(e,t,n,r){let i=[];if(e.gitInfo){let a=`${t.branch} ${e.gitInfo.branch}`;e.gitInfo.status===`conflicts`?a+=` ${t.git_conflicts}`:e.gitInfo.status===`dirty`?a+=` ${t.git_dirty}`:a+=` ${t.git_clean}`,e.gitInfo.ahead>0&&(a+=` ${t.git_ahead}${e.gitInfo.ahead}`),e.gitInfo.behind>0&&(a+=` ${t.git_behind}${e.gitInfo.behind}`);let o=[];e.gitInfo.staged&&e.gitInfo.staged>0&&o.push(`+${e.gitInfo.staged}`),e.gitInfo.unstaged&&e.gitInfo.unstaged>0&&o.push(`~${e.gitInfo.unstaged}`),e.gitInfo.untracked&&e.gitInfo.untracked>0&&o.push(`?${e.gitInfo.untracked}`),o.length>0&&(a+=` (${o.join(` `)})`),i.push(V(a,r.gitFg,n))}let a=Ke(St(e.hookData));return i.push(V(a,r.modeFg,n)),i}function K(e,t,n,r,i){let a=[];if(e.hookData.version&&a.push(V(`${t.version} v${e.hookData.version}`,i.versionFg,r)),e.tmuxSessionId&&a.push(V(`tmux:${e.tmuxSessionId}`,i.tmuxFg,r)),e.metricsInfo){let n=[];if(e.metricsInfo.responseTime!==null&&!isNaN(e.metricsInfo.responseTime)&&e.metricsInfo.responseTime>0&&n.push(`${t.metrics_response} ${qe(e.metricsInfo.responseTime)}`),e.metricsInfo.linesAdded!==null&&e.metricsInfo.linesAdded>0&&n.push(`${t.metrics_lines_added}${e.metricsInfo.linesAdded}`),e.metricsInfo.linesRemoved!==null&&e.metricsInfo.linesRemoved>0&&n.push(`${t.metrics_lines_removed}${e.metricsInfo.linesRemoved}`),e.blockInfo?.source!==`native`&&e.blockInfo?.burnRate!==null&&e.blockInfo?.burnRate!==void 0&&e.blockInfo.burnRate>0){let r=e.blockInfo.burnRate<1?`${(e.blockInfo.burnRate*100).toFixed(0)}c/h`:`$${e.blockInfo.burnRate.toFixed(2)}/h`;n.push(`${t.metrics_burn} ${r}`)}n.length>0&&a.push(V(n.join(` · `),i.metricsFg,r))}let o=n.display.lines.map(e=>e.segments.env).find(e=>e?.enabled);if(o&&o.variable){let e=process.env[o.variable];if(e){let t=o.prefix??o.variable;a.push(V(t?`${t}:${e}`:e,i.envFg,r))}}return a}function q(e,t,n){if(e.source===`native`&&e.nativeUtilization!==null){let n=Math.round(e.nativeUtilization),r=`${t.block_cost} ${n}%`;return e.timeRemaining!==null&&(r+=` · ${I(e.timeRemaining)}`),r}let r=P(e.cost),i=`${t.block_cost} ${r}`;e.timeRemaining!==null&&(i+=` · ${I(e.timeRemaining)}`);let a=n.budget?.block;if(a?.amount&&e.cost!==null){let t=R(e.cost,a.amount,a.warningThreshold||80);i+=t.displayText}return i}function J(e,t){let n=Math.round(e.used_percentage),r=Je(L(e.resets_at));return`${t.weekly_cost} ${n}%${r?` · ${r}`:``}`}function Tt(e,t,n){let r=P(e.session.cost),i=e.session.tokens,a=i!==null&&i>0?F(i).replace(` tokens`,``):null,o=`${t.session_cost} ${r}`;a&&(o+=` · ${a}`);let s=n.budget?.session;if(s?.amount&&e.session.cost!==null){let t=R(e.session.cost,s.amount,s.warningThreshold||80);o+=t.displayText}return o}function Et(e,t,n){let r=P(e.cost),i=`${t.today_cost} ${r} today`,a=n.budget?.today;if(a?.amount&&e.cost!==null){let t=R(e.cost,a.amount,a.warningThreshold||80);i+=t.displayText}return i}function Dt(e){let{lines:t,data:n,box:r,contentWidth:i,innerWidth:a,sym:o,config:s,reset:c,colors:l}=e,u=Ct(n,o,s,c,l);u.length>0&&t.push(H(r,yt(u,i),a))}function Ot(e){let{lines:t,data:n,box:r,contentWidth:i,innerWidth:a,sym:o,config:s,reset:c,colors:l}=e,u=G(n,o,c,l),d=K(n,o,s,c,l),f=u.join(` `),p=d.join(` · `);(f||p)&&(t.push(U(r,a)),t.push(H(r,W(f,p,i),a)))}function kt(e){let{lines:t,data:n,box:r,contentWidth:i,innerWidth:a,sym:o,config:s,reset:c,colors:l}=e,u=[],d=[];n.blockInfo&&u.push(V(q(n.blockInfo,o,s),l.blockFg,c));let f=n.hookData.rate_limits?.seven_day;f&&u.push(V(J(f,o),l.weeklyFg,c)),n.todayInfo&&u.push(V(Et(n.todayInfo,o,s),l.todayFg,c)),n.usageInfo&&d.push(V(Tt(n.usageInfo,o,s),l.sessionFg,c));let p=wt(n,o);p.length>0&&d.push(V(p.join(` · `),l.metricsFg,c)),u.length>0&&t.push(H(r,yt(u,i),a)),d.length>0&&t.push(H(r,W(d[0]??``,d[1]??``,i),a))}function At(e){let{lines:t,data:n,box:r,contentWidth:i,innerWidth:a,sym:o,config:s,reset:c,colors:l}=e,u=G(n,o,c,l);u.length>0&&(t.push(U(r,a)),t.push(H(r,W(u[0]??``,u[1]??``,i),a)));let d=K(n,o,s,c,l);d.length>0&&(t.push(U(r,a)),t.push(H(r,d.join(` · `),a)))}function jt(e){let{lines:t,data:n,box:r,contentWidth:i,innerWidth:a,sym:o,config:s,reset:c,colors:l}=e;n.blockInfo&&t.push(H(r,V(q(n.blockInfo,o,s),l.blockFg,c),a));let u=n.hookData.rate_limits?.seven_day;u&&t.push(H(r,V(J(u,o),l.weeklyFg,c),a));let d=[];n.usageInfo&&d.push(V(`${o.session_cost} ${P(n.usageInfo.session.cost)}`,l.sessionFg,c)),n.todayInfo&&d.push(V(`${o.today_cost} ${P(n.todayInfo.cost)} today`,l.todayFg,c)),d.length>0&&t.push(H(r,W(d[0]??``,d[1]??``,i),a))}function Mt(e){let{lines:t,data:n,box:r,contentWidth:i,innerWidth:a,sym:o,config:s,reset:c,colors:l}=e,u=G(n,o,c,l);u.length>0&&(t.push(U(r,a)),t.push(H(r,W(u[0]??``,u[1]??``,i),a)));let d=K(n,o,s,c,l);d.length>0&&t.push(H(r,d.join(` · `),a))}function Nt(e){return e>=80?`wide`:e>=55?`medium`:`narrow`}function Pt(e){return e&&e>0?Math.max(32,e):80}function Ft(e,t,n,r,i){let a=(i.display.charset||`unicode`)===`text`?st:it,o=e.colors,s=Pt(r),c=s-2,l=c-2,u=Nt(s),d=[];d.push(bt(e,t,c));let f=xt(e,l,a,n,o);f&&d.push(H(t,f,c));let p={lines:d,data:e,box:t,contentWidth:l,innerWidth:c,sym:a,config:i,reset:n,colors:o};return u===`wide`?(Dt(p),Ot(p)):u===`medium`?(kt(p),At(p)):(jt(p),Mt(p)),d.push(vt(t,c)),`\x1B[?2026h`+d.join(`
|
|
8
8
|
`)+`\x1B[?2026l`}var It=class{symbols;_usageProvider;_blockProvider;_todayProvider;_contextProvider;_gitService;_tmuxService;_metricsProvider;_segmentRenderer;constructor(e){this.config=e,this.symbols=this.initializeSymbols()}get usageProvider(){return this._usageProvider||=new Re,this._usageProvider}get blockProvider(){return this._blockProvider||=new et,this._blockProvider}get todayProvider(){return this._todayProvider||=new rt,this._todayProvider}get contextProvider(){return this._contextProvider||=new ze(this.config),this._contextProvider}get gitService(){return this._gitService||=new we,this._gitService}get tmuxService(){return this._tmuxService||=new Ee,this._tmuxService}get metricsProvider(){return this._metricsProvider||=new Be,this._metricsProvider}get segmentRenderer(){return this._segmentRenderer||=new Ze(this.config,this.symbols),this._segmentRenderer}needsSegmentInfo(e){return this.config.display.lines.some(t=>t.segments[e]?.enabled)}async generateStatusline(e){if(this.config.display.style===`tui`)return this.generateTuiStatusline(e);let t=this.needsSegmentInfo(`session`)?await this.usageProvider.getUsageInfo(e.session_id,e):null,n=this.needsSegmentInfo(`block`)?await this.blockProvider.getActiveBlockInfo(e):null,r=this.needsSegmentInfo(`today`)?await this.todayProvider.getTodayInfo():null,i=this.config.display.lines.map(e=>e.segments.context).find(e=>e?.enabled)?.autocompactBuffer??33e3,a=this.needsSegmentInfo(`context`)?await this.contextProvider.getContextInfo(e,i):null,o=this.needsSegmentInfo(`metrics`)?await this.metricsProvider.getMetricsInfo(e.session_id,e):null;return this.config.display.autoWrap?this.generateAutoWrapStatusline(e,t,n,r,a,o):(await Promise.all(this.config.display.lines.map(i=>this.renderLine(i,e,t,n,r,a,o)))).filter(e=>e.length>0).join(`
|
|
9
9
|
`)}async generateAutoWrapStatusline(e,t,n,r,i,a){let o=this.getThemeColors(),s=e.workspace?.current_dir||e.cwd||`/`,c=pt(),l=[];for(let u of this.config.display.lines){let d=Object.entries(u.segments).filter(([e,t])=>t?.enabled).map(([e,t])=>({type:e,config:t})),f=[];for(let c of d){let l=await this.renderSegment(c,e,t,n,r,i,a,o,s);l&&f.push({type:c.type,text:l.text,bgColor:l.bgColor,fgColor:l.fgColor})}if(f.length===0)continue;if(!c||c<=0){l.push(this.buildLineFromSegments(f,o));continue}let p=[],m=0;for(let e of f){let t=this.calculateSegmentWidth(e,p.length===0);p.length>0&&m+t>c&&(l.push(this.buildLineFromSegments(p,o)),p=[],m=0),p.push(e),m+=t}p.length>0&&l.push(this.buildLineFromSegments(p,o))}return l.join(`
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@owloops/claude-powerline",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.23.0",
|
|
4
4
|
"description": "Beautiful vim-style powerline statusline for Claude Code with real-time usage tracking, git integration, and custom themes",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.mjs",
|
|
@@ -44,6 +44,7 @@
|
|
|
44
44
|
"files": [
|
|
45
45
|
"dist",
|
|
46
46
|
"bin",
|
|
47
|
+
"plugin",
|
|
47
48
|
"README.md",
|
|
48
49
|
"LICENSE"
|
|
49
50
|
],
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "claude-powerline",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Claude Powerline statusline setup wizard",
|
|
5
|
+
"author": {
|
|
6
|
+
"name": "Owloops"
|
|
7
|
+
},
|
|
8
|
+
"repository": "https://github.com/Owloops/claude-powerline",
|
|
9
|
+
"license": "MIT",
|
|
10
|
+
"keywords": ["powerline", "statusline", "claude-code", "setup"]
|
|
11
|
+
}
|
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
|
|
3
|
+
set -euo pipefail
|
|
4
|
+
|
|
5
|
+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
6
|
+
readonly SCRIPT_DIR
|
|
7
|
+
readonly PLUGIN_ROOT="${SCRIPT_DIR}/.."
|
|
8
|
+
|
|
9
|
+
readonly SAMPLE_JSON='{"model":{"id":"claude-sonnet-4-20250514","display_name":"Sonnet 4"},"cost":{"total_cost_usd":0.42,"message_cost_usd":0.03,"duration":"15m"},"context_window":{"context_window_size":200000,"used_percentage":35,"current_usage":{"input_tokens":50000,"cache_creation_input_tokens":10000,"cache_read_input_tokens":5000}},"cwd":"/home/user/my-project","workspace":{"current_dir":"/home/user/my-project"},"session":{"session_id":"abc123"}}'
|
|
10
|
+
|
|
11
|
+
readonly PREVIEW_CONFIG='{
|
|
12
|
+
"theme": "dark",
|
|
13
|
+
"display": {
|
|
14
|
+
"style": "minimal",
|
|
15
|
+
"charset": "unicode",
|
|
16
|
+
"colorCompatibility": "auto",
|
|
17
|
+
"autoWrap": true,
|
|
18
|
+
"padding": 1,
|
|
19
|
+
"lines": [
|
|
20
|
+
{
|
|
21
|
+
"segments": {
|
|
22
|
+
"directory": { "enabled": true, "style": "fish" },
|
|
23
|
+
"git": { "enabled": true },
|
|
24
|
+
"model": { "enabled": true },
|
|
25
|
+
"session": { "enabled": true, "type": "cost", "costSource": "calculated" },
|
|
26
|
+
"today": { "enabled": true, "type": "cost" },
|
|
27
|
+
"context": { "enabled": true, "showPercentageOnly": false, "displayStyle": "text", "autocompactBuffer": 33000 }
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
]
|
|
31
|
+
},
|
|
32
|
+
"budget": {
|
|
33
|
+
"session": { "warningThreshold": 80 },
|
|
34
|
+
"today": { "amount": 50, "warningThreshold": 80 }
|
|
35
|
+
}
|
|
36
|
+
}'
|
|
37
|
+
|
|
38
|
+
THEME="dark"
|
|
39
|
+
STYLE="minimal"
|
|
40
|
+
CHARSET="unicode"
|
|
41
|
+
COMPARE_STYLES=false
|
|
42
|
+
COMPARE_THEMES=false
|
|
43
|
+
BIN=""
|
|
44
|
+
TEMP_FILES=()
|
|
45
|
+
|
|
46
|
+
# shellcheck disable=SC2329
|
|
47
|
+
cleanup() {
|
|
48
|
+
for f in "${TEMP_FILES[@]}"; do
|
|
49
|
+
rm -f "${f}"
|
|
50
|
+
done
|
|
51
|
+
}
|
|
52
|
+
trap cleanup EXIT
|
|
53
|
+
|
|
54
|
+
find_binary() {
|
|
55
|
+
local npm_bin="${PLUGIN_ROOT}/../bin/claude-powerline"
|
|
56
|
+
if [[ -f "${npm_bin}" ]]; then
|
|
57
|
+
printf '%s' "${npm_bin}"
|
|
58
|
+
return 0
|
|
59
|
+
fi
|
|
60
|
+
|
|
61
|
+
if command -v claude-powerline >/dev/null 2>&1; then
|
|
62
|
+
command -v claude-powerline
|
|
63
|
+
return 0
|
|
64
|
+
fi
|
|
65
|
+
|
|
66
|
+
printf 'npx'
|
|
67
|
+
return 0
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
make_temp_config() {
|
|
71
|
+
local preview_theme="$1"
|
|
72
|
+
local preview_style="$2"
|
|
73
|
+
local preview_charset="$3"
|
|
74
|
+
local tmp
|
|
75
|
+
|
|
76
|
+
tmp="$(mktemp)"
|
|
77
|
+
TEMP_FILES+=("${tmp}")
|
|
78
|
+
printf '%s' "${PREVIEW_CONFIG}" |
|
|
79
|
+
sed -e "s/\"theme\": \"dark\"/\"theme\": \"${preview_theme}\"/" \
|
|
80
|
+
-e "s/\"style\": \"minimal\"/\"style\": \"${preview_style}\"/" \
|
|
81
|
+
-e "s/\"charset\": \"unicode\"/\"charset\": \"${preview_charset}\"/" \
|
|
82
|
+
>"${tmp}"
|
|
83
|
+
printf '%s' "${tmp}"
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
run_preview() {
|
|
87
|
+
local preview_theme="$1"
|
|
88
|
+
local preview_style="$2"
|
|
89
|
+
local preview_charset="$3"
|
|
90
|
+
local tmp_config
|
|
91
|
+
|
|
92
|
+
tmp_config="$(make_temp_config "${preview_theme}" "${preview_style}" "${preview_charset}")"
|
|
93
|
+
|
|
94
|
+
if [[ "${BIN}" == "npx" ]]; then
|
|
95
|
+
printf '%s' "${SAMPLE_JSON}" | npx -y @owloops/claude-powerline@latest \
|
|
96
|
+
--config="${tmp_config}"
|
|
97
|
+
else
|
|
98
|
+
printf '%s' "${SAMPLE_JSON}" | "${BIN}" \
|
|
99
|
+
--config="${tmp_config}"
|
|
100
|
+
fi
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
run_compare_styles() {
|
|
104
|
+
local styles=(minimal powerline capsule tui)
|
|
105
|
+
local s
|
|
106
|
+
|
|
107
|
+
for s in "${styles[@]}"; do
|
|
108
|
+
printf '%s:\n' "${s}"
|
|
109
|
+
run_preview "${THEME}" "${s}" "${CHARSET}"
|
|
110
|
+
printf '\n\n'
|
|
111
|
+
done
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
run_compare_themes() {
|
|
115
|
+
local themes=(dark light nord tokyo-night rose-pine gruvbox)
|
|
116
|
+
local t
|
|
117
|
+
|
|
118
|
+
for t in "${themes[@]}"; do
|
|
119
|
+
printf '%s:\n' "${t}"
|
|
120
|
+
run_preview "${t}" "${STYLE}" "${CHARSET}"
|
|
121
|
+
printf '\n\n'
|
|
122
|
+
done
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
parse_args() {
|
|
126
|
+
while [[ $# -gt 0 ]]; do
|
|
127
|
+
case "$1" in
|
|
128
|
+
--theme=*)
|
|
129
|
+
THEME="${1#*=}"
|
|
130
|
+
shift
|
|
131
|
+
;;
|
|
132
|
+
--theme)
|
|
133
|
+
[[ $# -ge 2 ]] || {
|
|
134
|
+
printf 'Missing value for --theme\n' >&2
|
|
135
|
+
exit 1
|
|
136
|
+
}
|
|
137
|
+
THEME="$2"
|
|
138
|
+
shift 2
|
|
139
|
+
;;
|
|
140
|
+
--style=*)
|
|
141
|
+
STYLE="${1#*=}"
|
|
142
|
+
shift
|
|
143
|
+
;;
|
|
144
|
+
--style)
|
|
145
|
+
[[ $# -ge 2 ]] || {
|
|
146
|
+
printf 'Missing value for --style\n' >&2
|
|
147
|
+
exit 1
|
|
148
|
+
}
|
|
149
|
+
STYLE="$2"
|
|
150
|
+
shift 2
|
|
151
|
+
;;
|
|
152
|
+
--charset=*)
|
|
153
|
+
CHARSET="${1#*=}"
|
|
154
|
+
shift
|
|
155
|
+
;;
|
|
156
|
+
--charset)
|
|
157
|
+
[[ $# -ge 2 ]] || {
|
|
158
|
+
printf 'Missing value for --charset\n' >&2
|
|
159
|
+
exit 1
|
|
160
|
+
}
|
|
161
|
+
CHARSET="$2"
|
|
162
|
+
shift 2
|
|
163
|
+
;;
|
|
164
|
+
--compare-styles)
|
|
165
|
+
COMPARE_STYLES=true
|
|
166
|
+
shift
|
|
167
|
+
;;
|
|
168
|
+
--compare-themes)
|
|
169
|
+
COMPARE_THEMES=true
|
|
170
|
+
shift
|
|
171
|
+
;;
|
|
172
|
+
*)
|
|
173
|
+
printf 'Unknown option: %s\n' "$1" >&2
|
|
174
|
+
exit 1
|
|
175
|
+
;;
|
|
176
|
+
esac
|
|
177
|
+
done
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
main() {
|
|
181
|
+
parse_args "$@"
|
|
182
|
+
BIN="$(find_binary)"
|
|
183
|
+
|
|
184
|
+
if [[ "${COMPARE_STYLES}" == "true" ]]; then
|
|
185
|
+
run_compare_styles
|
|
186
|
+
exit 0
|
|
187
|
+
fi
|
|
188
|
+
|
|
189
|
+
if [[ "${COMPARE_THEMES}" == "true" ]]; then
|
|
190
|
+
run_compare_themes
|
|
191
|
+
exit 0
|
|
192
|
+
fi
|
|
193
|
+
|
|
194
|
+
run_preview "${THEME}" "${STYLE}" "${CHARSET}"
|
|
195
|
+
printf '\n'
|
|
196
|
+
exit 0
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
main "$@"
|