@owloops/claude-powerline 1.9.12 → 1.9.13

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.
Files changed (3) hide show
  1. package/README.md +19 -28
  2. package/dist/index.js +8 -9
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -16,7 +16,7 @@
16
16
 
17
17
  <img src="images/demo.gif" alt="Claude Powerline Demo" width="600"/>
18
18
 
19
- *Live demonstration: real-time usage tracking, git integration, and theme showcase*
19
+ _Live demonstration: real-time usage tracking, git integration, and theme showcase_
20
20
 
21
21
  <table>
22
22
  <tr>
@@ -97,28 +97,20 @@
97
97
 
98
98
  ### Setup
99
99
 
100
- Requires Node.js 18+, Claude Code, and Git 2.0+.
100
+ Requires Node.js 18+, Claude Code, Git 2.0+, and terminal with [Nerd Font](https://www.nerdfonts.com/) for proper icon display.
101
101
 
102
- **1. Install powerline fonts:**
103
-
104
- ```bash
105
- npx -y @owloops/claude-powerline --install-fonts
106
- ```
107
-
108
- > **Note:** The capsule style works best with [Nerd Fonts](https://www.nerdfonts.com) for properly rounded segment ends.
109
-
110
- **2. Add to your Claude Code `settings.json`:**
102
+ **1. Add to your Claude Code `settings.json`:**
111
103
 
112
104
  ```json
113
105
  {
114
106
  "statusLine": {
115
- "type": "command",
107
+ "type": "command",
116
108
  "command": "npx -y @owloops/claude-powerline@latest --style=powerline"
117
109
  }
118
110
  }
119
111
  ```
120
112
 
121
- **3. Start a Claude session** - the statusline appears at the bottom during conversations.
113
+ **2. Start a Claude session** - the statusline appears at the bottom during conversations.
122
114
 
123
115
  ![Claude Code with powerline](images/claude-interface-with-powerline.png)
124
116
 
@@ -133,7 +125,6 @@ Once added to Claude Code settings, the statusline runs automatically. For custo
133
125
  - `--theme` - `dark` (default), `light`, `nord`, `tokyo-night`, `rose-pine`, `custom`
134
126
  - `--style` - `minimal` (default), `powerline`, `capsule`
135
127
  - `--config` - Custom config file path
136
- - `--install-fonts` - Install powerline fonts
137
128
  - `--help` - Show help
138
129
 
139
130
  **Examples:**
@@ -169,7 +160,7 @@ curl -o ~/.claude/claude-powerline.json https://raw.githubusercontent.com/Owloop
169
160
  **Config locations** (in priority order):
170
161
 
171
162
  - `./.claude-powerline.json` - Project-specific
172
- - `~/.claude/claude-powerline.json` - User config
163
+ - `~/.claude/claude-powerline.json` - User config
173
164
  - `~/.config/claude-powerline/config.json` - XDG standard
174
165
 
175
166
  **Override priority:** CLI flags → Environment variables → Config files → Defaults
@@ -299,7 +290,7 @@ Configure context window limits for different model types. Defaults to 200K toke
299
290
  **Available Model Types:**
300
291
 
301
292
  - `sonnet`: Claude Sonnet models (3.5, 4, etc.)
302
- - `opus`: Claude Opus models
293
+ - `opus`: Claude Opus models
303
294
  - `default`: Fallback for unrecognized models (200K)
304
295
 
305
296
  **Note:** Sonnet 4's 1M context window is currently in beta for tier 4+ users. Set `"sonnet": 1000000` when you have access.
@@ -477,18 +468,18 @@ Execution times for different configurations:
477
468
  <details>
478
469
  <summary><strong>Detailed Segment Timings</strong></summary>
479
470
 
480
- | Segment | Timing | Notes |
481
- |---------|--------|-------|
482
- | `directory` | ~40ms | No external commands |
483
- | `model` | ~40ms | Uses hook data |
484
- | `session` | ~40ms | Minimal transcript parsing |
485
- | `context` | ~40ms | Hook data calculation |
486
- | `metrics` | ~40ms | Transcript analysis |
487
- | `git` | ~60ms | No caching for fresh data |
488
- | `tmux` | ~50ms | Environment check + command |
489
- | `block` | ~180ms | 5-hour window transcript load |
490
- | `today` | ~250ms | Full daily transcript load (cached: ~50ms) |
491
- | `version` | ~40ms | Uses hook data |
471
+ | Segment | Timing | Notes |
472
+ | ----------- | ------ | ------------------------------------------ |
473
+ | `directory` | ~40ms | No external commands |
474
+ | `model` | ~40ms | Uses hook data |
475
+ | `session` | ~40ms | Minimal transcript parsing |
476
+ | `context` | ~40ms | Hook data calculation |
477
+ | `metrics` | ~40ms | Transcript analysis |
478
+ | `git` | ~60ms | No caching for fresh data |
479
+ | `tmux` | ~50ms | Environment check + command |
480
+ | `block` | ~180ms | 5-hour window transcript load |
481
+ | `today` | ~250ms | Full daily transcript load (cached: ~50ms) |
482
+ | `version` | ~40ms | Uses hook data |
492
483
 
493
484
  **Benchmark:** `npm run benchmark:timing`
494
485
 
package/dist/index.js CHANGED
@@ -1,16 +1,15 @@
1
1
  #!/usr/bin/env node
2
- import b from'process';import w,{join,posix}from'path';import S,{existsSync,readFileSync,createReadStream}from'fs';import {exec,execSync}from'child_process';import M,{homedir}from'os';import {json}from'stream/consumers';import V from'tty';import {promisify}from'util';import {get}from'https';import {URL}from'url';import {createHash}from'crypto';import {setTimeout}from'timers/promises';import {readdir,stat,readFile}from'fs/promises';import {createInterface}from'readline';function ce(r,e){if(e&&(r.toLowerCase()==="transparent"||r.toLowerCase()==="none"))return "\x1B[49m";let t=parseInt(r.slice(1,3),16),n=parseInt(r.slice(3,5),16),o=parseInt(r.slice(5,7),16);return `\x1B[${e?"48":"38"};2;${t};${n};${o}m`}function J(r,e=false){let t=r.match(/48;2;(\d+);(\d+);(\d+)/);if(t)return `\x1B[38;2;${t[1]};${t[2]};${t[3]}m`;if(e)return "\x1B[37m";if(r.includes("\x1B[")&&r.includes("m")){let n=r.match(/\[(\d+)m/);if(n&&n[1]){let o=parseInt(n[1],10);if(o>=40&&o<=47)return `\x1B[${o-10}m`;if(o>=100&&o<=107)return `\x1B[${o-10}m`}}return r.replace("48","38")}function Y(){let{env:r}=b;if(r.NO_COLOR)return "none";let e=r.FORCE_COLOR;if(e==="false"||e==="0")return "none";if(e==="true"||e==="1")return "ansi";if(e==="2")return "ansi256";if(e==="3")return "truecolor";if(r.TERM==="dumb")return "none";if(r.CI)return ["GITHUB_ACTIONS","GITEA_ACTIONS","CIRCLECI"].some(n=>n in r)?"truecolor":"ansi";if(r.COLORTERM==="truecolor"||["xterm-kitty","xterm-ghostty","wezterm","alacritty","foot","contour"].includes(r.TERM||""))return "truecolor";if(r.TERM_PROGRAM)switch(r.TERM_PROGRAM){case "iTerm.app":return "truecolor";case "Apple_Terminal":return "ansi256";case "vscode":return "truecolor";case "Tabby":return "truecolor"}if(/-256(color)?$/i.test(r.TERM||""))return "ansi256";if(/-truecolor$/i.test(r.TERM||""))return "truecolor";if(/^screen|^xterm|^vt100|^vt220|^rxvt|color|ansi|cygwin|linux/i.test(r.TERM||"")||r.COLORTERM)return "ansi";if(V?.WriteStream?.prototype?.hasColors)try{if(!V.WriteStream.prototype.hasColors())return "none";let o=V.WriteStream.prototype.hasColors(256);return V.WriteStream.prototype.hasColors(16777216)?"truecolor":o?"ansi256":"ansi"}catch{}return "ansi"}function le(r,e){if(e&&(r.toLowerCase()==="transparent"||r.toLowerCase()==="none"))return "\x1B[49m";let t=parseInt(r.slice(1,3),16),n=parseInt(r.slice(3,5),16),o=parseInt(r.slice(5,7),16),i=((a,c,u)=>a===c&&c===u?a<8?16:a>248?231:Math.round((a-8)/247*24)+232:16+36*Math.round(a/255*5)+6*Math.round(c/255*5)+Math.round(u/255*5))(t,n,o);return `\x1B[${e?"48":"38"};5;${i}m`}function ue(r,e){if(e&&(r.toLowerCase()==="transparent"||r.toLowerCase()==="none"))return "\x1B[49m";if(e)return "";let t=parseInt(r.slice(1,3),16),n=parseInt(r.slice(3,5),16),o=parseInt(r.slice(5,7),16);return n>t&&n>o&&n>120?"\x1B[32m":t>n&&t>o&&t>120?"\x1B[31m":o>t&&o>n&&o>120?"\x1B[34m":(t+n+o)/3>150?"\x1B[37m":"\x1B[90m"}var we={directory:{bg:"#8b4513",fg:"#ffffff"},git:{bg:"#404040",fg:"#ffffff"},model:{bg:"#2d2d2d",fg:"#ffffff"},session:{bg:"#202020",fg:"#00ffff"},block:{bg:"#2a2a2a",fg:"#87ceeb"},today:{bg:"#1a1a1a",fg:"#98fb98"},tmux:{bg:"#2f4f2f",fg:"#90ee90"},context:{bg:"#4a5568",fg:"#cbd5e0"},metrics:{bg:"#374151",fg:"#d1d5db"},version:{bg:"#3a3a4a",fg:"#b8b8d0"}},ke={directory:{bg:"#af5f00",fg:"#ffffff"},git:{bg:"#444444",fg:"#ffffff"},model:{bg:"#3a3a3a",fg:"#ffffff"},session:{bg:"#262626",fg:"#00ffff"},block:{bg:"#303030",fg:"#87ceeb"},today:{bg:"#1c1c1c",fg:"#87ff87"},tmux:{bg:"#444444",fg:"#87ff87"},context:{bg:"#585858",fg:"#d0d0d0"},metrics:{bg:"#4e4e4e",fg:"#d0d0d0"},version:{bg:"#444444",fg:"#d7afff"}},Se={directory:{bg:"#d75f00",fg:"#ffffff"},git:{bg:"#585858",fg:"#ffffff"},model:{bg:"#444444",fg:"#ffffff"},session:{bg:"#303030",fg:"#00ffff"},block:{bg:"#3a3a3a",fg:"#5fafff"},today:{bg:"#262626",fg:"#00ff00"},tmux:{bg:"#585858",fg:"#00ff00"},context:{bg:"#808080",fg:"#ffffff"},metrics:{bg:"#666666",fg:"#ffffff"},version:{bg:"#585858",fg:"#af87ff"}};var Te={directory:{bg:"#ff6b47",fg:"#ffffff"},git:{bg:"#4fb3d9",fg:"#ffffff"},model:{bg:"#87ceeb",fg:"#000000"},session:{bg:"#da70d6",fg:"#ffffff"},block:{bg:"#6366f1",fg:"#ffffff"},today:{bg:"#10b981",fg:"#ffffff"},tmux:{bg:"#32cd32",fg:"#ffffff"},context:{bg:"#718096",fg:"#ffffff"},metrics:{bg:"#6b7280",fg:"#ffffff"},version:{bg:"#8b7dd8",fg:"#ffffff"}},xe={directory:{bg:"#ff5f5f",fg:"#ffffff"},git:{bg:"#5fafff",fg:"#ffffff"},model:{bg:"#87d7ff",fg:"#000000"},session:{bg:"#ff5fff",fg:"#ffffff"},block:{bg:"#5f5fff",fg:"#ffffff"},today:{bg:"#00d787",fg:"#ffffff"},tmux:{bg:"#00ff5f",fg:"#ffffff"},context:{bg:"#808080",fg:"#ffffff"},metrics:{bg:"#767676",fg:"#ffffff"},version:{bg:"#af87ff",fg:"#ffffff"}},ve={directory:{bg:"#ff5f5f",fg:"#ffffff"},git:{bg:"#5fafff",fg:"#ffffff"},model:{bg:"#87d7ff",fg:"#000000"},session:{bg:"#ff5fff",fg:"#ffffff"},block:{bg:"#5f5fff",fg:"#ffffff"},today:{bg:"#00d787",fg:"#ffffff"},tmux:{bg:"#00ff5f",fg:"#ffffff"},context:{bg:"#808080",fg:"#ffffff"},metrics:{bg:"#767676",fg:"#ffffff"},version:{bg:"#af87ff",fg:"#ffffff"}};var Pe={directory:{bg:"#434c5e",fg:"#d8dee9"},git:{bg:"#3b4252",fg:"#a3be8c"},model:{bg:"#4c566a",fg:"#81a1c1"},session:{bg:"#2e3440",fg:"#88c0d0"},block:{bg:"#3b4252",fg:"#81a1c1"},today:{bg:"#2e3440",fg:"#8fbcbb"},tmux:{bg:"#2e3440",fg:"#8fbcbb"},context:{bg:"#5e81ac",fg:"#eceff4"},metrics:{bg:"#b48ead",fg:"#2e3440"},version:{bg:"#434c5e",fg:"#88c0d0"}},Ee={directory:{bg:"#5f87af",fg:"#e4e4e4"},git:{bg:"#4e4e4e",fg:"#87d787"},model:{bg:"#6c6c6c",fg:"#87afd7"},session:{bg:"#3a3a3a",fg:"#5fafaf"},block:{bg:"#4e4e4e",fg:"#87afd7"},today:{bg:"#3a3a3a",fg:"#5fd7d7"},tmux:{bg:"#3a3a3a",fg:"#5fd7d7"},context:{bg:"#5f87d7",fg:"#ffffff"},metrics:{bg:"#d787af",fg:"#3a3a3a"},version:{bg:"#5f87af",fg:"#5fafaf"}},$e={directory:{bg:"#0087af",fg:"#ffffff"},git:{bg:"#585858",fg:"#87d700"},model:{bg:"#808080",fg:"#87afff"},session:{bg:"#444444",fg:"#00d7d7"},block:{bg:"#585858",fg:"#87afff"},today:{bg:"#444444",fg:"#00ffff"},tmux:{bg:"#444444",fg:"#00ffff"},context:{bg:"#0087ff",fg:"#ffffff"},metrics:{bg:"#ff87d7",fg:"#444444"},version:{bg:"#0087af",fg:"#00d7d7"}};var Re={directory:{bg:"#2f334d",fg:"#82aaff"},git:{bg:"#1e2030",fg:"#c3e88d"},model:{bg:"#191b29",fg:"#fca7ea"},session:{bg:"#222436",fg:"#86e1fc"},block:{bg:"#2d3748",fg:"#7aa2f7"},today:{bg:"#1a202c",fg:"#4fd6be"},tmux:{bg:"#191b29",fg:"#4fd6be"},context:{bg:"#414868",fg:"#c0caf5"},metrics:{bg:"#3d59a1",fg:"#c0caf5"},version:{bg:"#292e42",fg:"#bb9af7"}},De={directory:{bg:"#444478",fg:"#87afff"},git:{bg:"#262640",fg:"#afff87"},model:{bg:"#1c1c30",fg:"#ff87ff"},session:{bg:"#3a3a50",fg:"#5fd7ff"},block:{bg:"#4e4e68",fg:"#5f87ff"},today:{bg:"#262640",fg:"#00d7af"},tmux:{bg:"#1c1c30",fg:"#00d7af"},context:{bg:"#5f5f87",fg:"#d7d7ff"},metrics:{bg:"#5f5faf",fg:"#d7d7ff"},version:{bg:"#444460",fg:"#d787ff"}},Be={directory:{bg:"#5f5faf",fg:"#87afff"},git:{bg:"#303050",fg:"#87ff87"},model:{bg:"#262640",fg:"#ff87ff"},session:{bg:"#444470",fg:"#00d7ff"},block:{bg:"#666680",fg:"#5f87ff"},today:{bg:"#303050",fg:"#00d787"},tmux:{bg:"#262640",fg:"#00d787"},context:{bg:"#808080",fg:"#ffffff"},metrics:{bg:"#8787d7",fg:"#ffffff"},version:{bg:"#585870",fg:"#d787ff"}};var Ae={directory:{bg:"#26233a",fg:"#c4a7e7"},git:{bg:"#1f1d2e",fg:"#9ccfd8"},model:{bg:"#191724",fg:"#ebbcba"},session:{bg:"#26233a",fg:"#f6c177"},block:{bg:"#2a273f",fg:"#eb6f92"},today:{bg:"#232136",fg:"#9ccfd8"},tmux:{bg:"#26233a",fg:"#908caa"},context:{bg:"#393552",fg:"#e0def4"},metrics:{bg:"#524f67",fg:"#e0def4"},version:{bg:"#2a273f",fg:"#c4a7e7"}},Ue={directory:{bg:"#444444",fg:"#d787d7"},git:{bg:"#262626",fg:"#87d7d7"},model:{bg:"#1c1c1c",fg:"#ffaf87"},session:{bg:"#444444",fg:"#d7af5f"},block:{bg:"#4e4e4e",fg:"#ff5f87"},today:{bg:"#3a3a3a",fg:"#87d7d7"},tmux:{bg:"#444444",fg:"#9e9e9e"},context:{bg:"#585858",fg:"#e4e4e4"},metrics:{bg:"#767676",fg:"#e4e4e4"},version:{bg:"#4e4e4e",fg:"#d787d7"}},Me={directory:{bg:"#585858",fg:"#ff87ff"},git:{bg:"#303030",fg:"#00d7d7"},model:{bg:"#262626",fg:"#ffaf87"},session:{bg:"#585858",fg:"#d7af00"},block:{bg:"#666666",fg:"#ff5f87"},today:{bg:"#444444",fg:"#00d7d7"},tmux:{bg:"#585858",fg:"#bcbcbc"},context:{bg:"#808080",fg:"#ffffff"},metrics:{bg:"#a8a8a8",fg:"#000000"},version:{bg:"#666666",fg:"#ff87ff"}};var ge={dark:we,"dark-ansi256":ke,"dark-ansi":Se,light:Te,"light-ansi256":xe,"light-ansi":ve,nord:Pe,"nord-ansi256":Ee,"nord-ansi":$e,"tokyo-night":Re,"tokyo-night-ansi256":De,"tokyo-night-ansi":Be,"rose-pine":Ae,"rose-pine-ansi256":Ue,"rose-pine-ansi":Me};function q(r,e){let t=ge[r];if(!t)return null;if(e==="none"||e==="ansi"){let n=ge[`${r}-ansi`];if(n)return n}if(e==="ansi256"){let n=ge[`${r}-ansi256`];if(n)return n}return t}var l=(r,...e)=>{process.env.CLAUDE_POWERLINE_DEBUG&&console.error(`[DEBUG] ${r}`,...e);};var k=promisify(exec),F=class{isGitRepo(e){try{return S.existsSync(w.join(e,".git"))}catch{return false}}async findGitRoot(e){try{return (await k("git rev-parse --show-toplevel",{cwd:e,encoding:"utf8",timeout:2e3})).stdout.trim()||null}catch{return null}}async getGitInfo(e,t={},n){let o;if(n&&this.isGitRepo(n))o=n;else if(this.isGitRepo(e))o=e;else {let s=await this.findGitRoot(e);if(!s)return null;o=s;}try{let s=await this.getStatusWithBranchAsync(o),i=await this.getAheadBehindAsync(o),a={branch:s.branch||"detached",status:s.status,ahead:i.ahead,behind:i.behind};t.showWorkingTree&&s.workingTree&&(a.staged=s.workingTree.staged,a.unstaged=s.workingTree.unstaged,a.untracked=s.workingTree.untracked,a.conflicts=s.workingTree.conflicts);let c={},u={};t.showSha&&(c.sha=this.getShaAsync(o)),t.showTag&&(c.tag=this.getNearestTagAsync(o)),t.showTimeSinceCommit&&(c.timeSinceCommit=this.getTimeSinceLastCommitAsync(o)),t.showStashCount&&(u.stashCount=this.getStashCountAsync(o)),t.showUpstream&&(u.upstream=this.getUpstreamAsync(o)),t.showRepoName&&(u.repoName=this.getRepoNameAsync(o));let g=new Map;for(let[m,f]of Object.entries(c))try{let d=await f;g.set(m,d);}catch{}return Object.keys(u).length>0&&(await Promise.allSettled(Object.entries(u).map(async([f,d])=>({key:f,value:await d})))).forEach(f=>{f.status==="fulfilled"&&g.set(f.value.key,f.value.value);}),t.showSha&&(a.sha=g.get("sha")||void 0),t.showOperation&&(a.operation=this.getOngoingOperation(o)||void 0),t.showTag&&(a.tag=g.get("tag")||void 0),t.showTimeSinceCommit&&(a.timeSinceCommit=g.get("timeSinceCommit")||void 0),t.showStashCount&&(a.stashCount=g.get("stashCount")||0),t.showUpstream&&(a.upstream=g.get("upstream")||void 0),t.showRepoName&&(a.repoName=g.get("repoName")||void 0,a.isWorktree=this.isWorktree(o)),a}catch{return null}}async getShaAsync(e){try{return (await k("git rev-parse --short=7 HEAD",{cwd:e,encoding:"utf8",timeout:2e3})).stdout.trim()||null}catch{return null}}getOngoingOperation(e){try{let t=w.join(e,".git");return S.existsSync(w.join(t,"MERGE_HEAD"))?"MERGE":S.existsSync(w.join(t,"CHERRY_PICK_HEAD"))?"CHERRY-PICK":S.existsSync(w.join(t,"REVERT_HEAD"))?"REVERT":S.existsSync(w.join(t,"BISECT_LOG"))?"BISECT":S.existsSync(w.join(t,"rebase-merge"))||S.existsSync(w.join(t,"rebase-apply"))?"REBASE":null}catch{return null}}async getNearestTagAsync(e){try{return (await k("git describe --tags --abbrev=0",{cwd:e,encoding:"utf8",timeout:2e3})).stdout.trim()||null}catch{return null}}async getTimeSinceLastCommitAsync(e){try{let n=(await k("git log -1 --format=%ct",{cwd:e,encoding:"utf8",timeout:2e3})).stdout.trim();if(!n)return null;let o=parseInt(n)*1e3,s=Date.now();return Math.floor((s-o)/1e3)}catch{return null}}async getStashCountAsync(e){try{let n=(await k("git stash list",{cwd:e,encoding:"utf8",timeout:2e3})).stdout.trim();return n?n.split(`
3
- `).length:0}catch{return 0}}async getUpstreamAsync(e){try{return (await k("git rev-parse --abbrev-ref @{u}",{cwd:e,encoding:"utf8",timeout:2e3})).stdout.trim()||null}catch{return null}}async getRepoNameAsync(e){try{let n=(await k("git config --get remote.origin.url",{cwd:e,encoding:"utf8",timeout:2e3})).stdout.trim();return n?n.match(/\/([^/]+?)(\.git)?$/)?.[1]||w.basename(e):w.basename(e)}catch{return w.basename(e)}}isWorktree(e){try{let t=w.join(e,".git");return !!(S.existsSync(t)&&S.statSync(t).isFile())}catch{return false}}async getStatusWithBranchAsync(e){try{l(`[GIT-EXEC] Running git status in ${e}`);let o=(await k("git status --porcelain -b",{cwd:e,encoding:"utf8",timeout:2e3})).stdout.split(`
4
- `),s=null,i="clean",a=0,c=0,u=0,g=0;for(let m of o)if(m){if(m.startsWith("## ")){let d=m.substring(3).split("...")[0];d&&d!=="HEAD (no branch)"&&(s=d);continue}if(m.length>=2){let f=m.charAt(0),d=m.charAt(1);if(f==="?"&&d==="?"){u++,i==="clean"&&(i="dirty");continue}let h=f+d;if(["DD","AU","UD","UA","DU","AA","UU"].includes(h)){g++,i="conflicts";continue}f!==" "&&f!=="?"&&(a++,i==="clean"&&(i="dirty")),d!==" "&&d!=="?"&&(c++,i==="clean"&&(i="dirty"));}}return {branch:s||await this.getFallbackBranch(e),status:i,workingTree:{staged:a,unstaged:c,untracked:u,conflicts:g}}}catch(t){return l(`Git status with branch command failed in ${e}:`,t),{branch:await this.getFallbackBranch(e),status:"clean"}}}async getFallbackBranch(e){try{let n=(await k("git branch --show-current",{cwd:e,encoding:"utf8",timeout:2e3})).stdout.trim();if(n)return n}catch{try{let n=(await k("git symbolic-ref --short HEAD",{cwd:e,encoding:"utf8",timeout:2e3})).stdout.trim();if(n)return n}catch{return null}}return null}async getAheadBehindAsync(e){try{l(`[GIT-EXEC] Running git ahead/behind in ${e}`);let[t,n]=await Promise.all([k("git rev-list --count @{u}..HEAD",{cwd:e,encoding:"utf8",timeout:2e3}),k("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 l(`Git ahead/behind command failed in ${e}:`,t),{ahead:0,behind:0}}}};var Ke=promisify(exec),L=class{async getSessionId(){try{if(!process.env.TMUX_PANE)return l("TMUX_PANE not set, not in tmux session"),null;l(`Getting tmux session ID, TMUX_PANE: ${process.env.TMUX_PANE}`);let t=(await Ke("tmux display-message -p '#S'",{encoding:"utf8",timeout:1e3})).stdout.trim();return l(`Tmux session ID: ${t||"empty"}`),t||null}catch(e){return l("Error getting tmux session ID:",e),null}}isInTmux(){return !!process.env.TMUX_PANE}};function z(){let r=[],e=process.env.CLAUDE_CONFIG_DIR;if(e&&e.split(",").forEach(t=>{let n=t.trim();existsSync(n)&&r.push(n);}),r.length===0){let t=homedir(),n=join(t,".config","claude"),o=join(t,".claude");existsSync(n)?r.push(n):existsSync(o)&&r.push(o);}return r}async function X(r){let e=[];for(let t of r){let n=join(t,"projects");if(existsSync(n))try{let o=await readdir(n,{withFileTypes:!0});for(let s of o)if(s.isDirectory()){let i=posix.join(n,s.name);e.push(i);}}catch(o){l(`Failed to read projects directory ${n}:`,o);}}return e}async function K(r){let e=z(),t=await X(e);for(let n of t){let o=posix.join(n,`${r}.jsonl`);if(existsSync(o))return o}return null}async function de(r){try{return (await stat(r)).mtime}catch{return null}}function nt(r){let e=r.message?.id||(typeof r.raw.message=="object"&&r.raw.message!==null&&"id"in r.raw.message?r.raw.message.id:void 0),t="requestId"in r.raw?r.raw.requestId:void 0;return !e||!t?null:`${e}:${t}`}var ot=1024*1024;async function I(r){try{let t=(await stat(r)).size,n;return t>ot?(l(`Using streaming parser for large file ${r} (${Math.round(t/1024)}KB)`),n=await st(r)):n=await rt(r),l(`Parsed ${n.length} entries from ${r}`),n}catch(e){return l(`Failed to read file ${r}:`,e),[]}}async function rt(r){let t=(await readFile(r,"utf-8")).trim().split(`
5
- `).filter(o=>o.trim()),n=[];for(let o of t)try{let s=JSON.parse(o);if(!s.timestamp)continue;let i={timestamp:new Date(s.timestamp),message:s.message,costUSD:typeof s.costUSD=="number"?s.costUSD:void 0,isSidechain:s.isSidechain===!0,raw:s};n.push(i);}catch(s){l(`Failed to parse JSONL line: ${s}`);continue}return n}async function st(r){return new Promise((e,t)=>{let n=[],o=createReadStream(r,{encoding:"utf8"}),s=createInterface({input:o,crlfDelay:1/0});s.on("line",i=>{let a=i.trim();if(a)try{let c=JSON.parse(a);if(!c.timestamp)return;let u={timestamp:new Date(c.timestamp),message:c.message,costUSD:typeof c.costUSD=="number"?c.costUSD:void 0,isSidechain:c.isSidechain===!0,raw:c};n.push(u);}catch(c){l(`Failed to parse JSONL line: ${c}`);}}),s.on("close",()=>{e(n);}),s.on("error",i=>{l(`Streaming parser error for ${r}:`,i),t(i);}),o.on("error",i=>{l(`File stream error for ${r}:`,i),t(i);});})}async function Z(r,e,t=false){let n=z(),o=await X(n),s=new Set,i=o.map(async h=>{try{let A=(await readdir(h)).filter(_=>_.endsWith(".jsonl")).map(async _=>{let ae=posix.join(h,_);if(existsSync(ae)){let Ve=await de(ae);return {filePath:ae,mtime:Ve}}return null});return (await Promise.all(A)).filter(_=>_?.mtime&&(!e||e(_.filePath,_.mtime)))}catch(y){return l(`Failed to read project directory ${h}:`,y),[]}}),c=(await Promise.all(i)).flat().filter(h=>h!==null);t&&c.sort((h,y)=>y.mtime.getTime()-h.mtime.getTime());let u=c.map(h=>h.filePath),g=[],m=u.map(async h=>(await I(h)).filter(T=>!r||r(T))),f=await Promise.all(m);for(let h of f)g.push(...h);g.sort((h,y)=>h.timestamp.getTime()-y.timestamp.getTime());let d=[];for(let h of g){let y=nt(h);y&&s.has(y)||(y&&s.add(y),d.push(h));}return d}var $=class{static CACHE_DIR=w.join(homedir(),".claude","powerline");static USAGE_CACHE_DIR=w.join(this.CACHE_DIR,"usage");static LOCKS_DIR=w.join(this.CACHE_DIR,"locks");static isLocked(e){let t=w.join(this.LOCKS_DIR,e);if(!S.existsSync(t))return false;try{let n=S.readFileSync(t,"utf-8"),o=parseInt(n.trim(),10);if(isNaN(o))return l(`Invalid PID in lock file ${e}, removing stale lock`),S.unlinkSync(t),!1;try{return process.kill(o,0),!0}catch(s){return s.code==="ESRCH"?(l(`Removing stale lock file ${e} for dead process ${o}`),S.unlinkSync(t),!1):(l(`Error checking process ${o} for lock ${e}:`,s),!0)}}catch(n){return l(`Error reading lock file ${e}:`,n),true}}static async acquireLock(e,t=5e3){await this.ensureCacheDirectories();let s=w.join(this.LOCKS_DIR,e),i=Date.now(),a=String(process.pid);for(;Date.now()-i<t;)try{return await S.promises.writeFile(s,a,{flag:"wx"}),l(`Lock acquired for ${e}`),!0}catch(c){if(c.code==="EEXIST")await setTimeout(50);else throw c}return l(`Failed to acquire lock for ${e} within ${t}ms`),false}static async releaseLock(e){let t=w.join(this.LOCKS_DIR,e);try{await S.promises.unlink(t),l(`Lock released for ${e}`);}catch(n){n.code!=="ENOENT"&&l(`Error releasing lock for ${e}:`,n);}}static async ensureCacheDirectories(){try{await Promise.all([S.promises.mkdir(this.CACHE_DIR,{recursive:!0}),S.promises.mkdir(this.USAGE_CACHE_DIR,{recursive:!0}),S.promises.mkdir(this.LOCKS_DIR,{recursive:!0})]);}catch(e){l("Failed to create cache directories:",e);}}static createProjectHash(e){return createHash("md5").update(e).digest("hex").substring(0,8)}static async getUsageCache(e,t){let s="utf-8";await this.ensureCacheDirectories();let i=w.join(this.USAGE_CACHE_DIR,`${e}.json`),a=`${e}.usage.lock`;for(let c=0;c<3;c++){if(this.isLocked(a)){l(`Cache for ${e} is locked, waiting...`),await setTimeout(75);continue}try{let g=await S.promises.readFile(i,s),m=JSON.parse(g);return !t||m.timestamp>=t?(l(`[CACHE-HIT] ${e} disk cache: found`),this.deserializeDates(m.data)):(l(`${e} cache outdated: cache=${m.timestamp}, latest=${t}`),null)}catch(g){if(g.code==="ENOENT")return l(`No shared ${e} usage cache found`),null;let m=c+1;l(`Attempt ${m} failed to read ${e} cache: ${g.message}. Retrying...`),await setTimeout(75);}}return l(`Failed to read ${e} cache after 3 attempts.`),null}static deserializeDates(e){return Array.isArray(e)?e.map(t=>({...t,timestamp:new Date(t.timestamp)})):e}static async setUsageCache(e,t,n){let o=`${e}.usage.lock`;if(!await this.acquireLock(o)){l(`Could not acquire lock to set usage cache for ${e}`);return}try{await this.ensureCacheDirectories();let i=w.join(this.USAGE_CACHE_DIR,`${e}.json`),a=n||Date.now(),u=JSON.stringify({data:t,timestamp:a});await S.promises.writeFile(i,u,"utf-8"),l(`[CACHE-SET] ${e} disk cache stored`);}catch(i){l(`Failed to save ${e} usage cache:`,i);}finally{await this.releaseLock(o);}}static async getLatestTranscriptMtime(){try{let e=z(),t=await X(e),n=0;for(let o of t)try{let i=(await S.promises.readdir(o)).filter(a=>a.endsWith(".jsonl"));for(let a of i){let c=w.join(o,a),u=await de(c);u&&u.getTime()>n&&(n=u.getTime());}}catch(s){l(`Failed to read project directory ${o}:`,s);continue}return n}catch(e){return l("Failed to get latest transcript mtime:",e),Date.now()}}};var Q={"claude-3-haiku-20240307":{name:"Claude 3 Haiku",input:.25,output:1.25,cache_write_5m:.3,cache_write_1h:.5,cache_read:.03},"claude-3-5-haiku-20241022":{name:"Claude 3.5 Haiku",input:.8,output:4,cache_write_5m:1,cache_write_1h:1.6,cache_read:.08},"claude-3-5-haiku-latest":{name:"Claude 3.5 Haiku Latest",input:1,output:5,cache_write_5m:1.25,cache_write_1h:2,cache_read:.1},"claude-3-opus-latest":{name:"Claude 3 Opus Latest",input:15,output:75,cache_write_5m:18.75,cache_write_1h:30,cache_read:1.5},"claude-3-opus-20240229":{name:"Claude 3 Opus",input:15,output:75,cache_write_5m:18.75,cache_write_1h:30,cache_read:1.5},"claude-3-5-sonnet-latest":{name:"Claude 3.5 Sonnet Latest",input:3,output:15,cache_write_5m:3.75,cache_write_1h:6,cache_read:.3},"claude-3-5-sonnet-20240620":{name:"Claude 3.5 Sonnet",input:3,output:15,cache_write_5m:3.75,cache_write_1h:6,cache_read:.3},"claude-3-5-sonnet-20241022":{name:"Claude 3.5 Sonnet",input:3,output:15,cache_write_5m:3.75,cache_write_1h:6,cache_read:.3},"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-3-7-sonnet-latest":{name:"Claude 3.7 Sonnet Latest",input:3,output:15,cache_write_5m:3.75,cache_write_1h:6,cache_read:.3},"claude-3-7-sonnet-20250219":{name:"Claude 3.7 Sonnet",input:3,output:15,cache_write_5m:3.75,cache_write_1h:6,cache_read:.3}},R=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 t=Date.now()-864e5;return await $.getUsageCache("pricing",t)}static async saveDiskCache(e){await $.setUsageCache("pricing",e);}static async fetchPricingData(){return new Promise(e=>{let t=new URL(this.GITHUB_PRICING_URL),n=get({hostname:t.hostname,path:t.pathname,headers:{"User-Agent":"claude-powerline","Cache-Control":"no-cache"},timeout:5e3},o=>{if(o.statusCode!==200){l(`HTTP ${o.statusCode}: ${o.statusMessage}`),e(null);return}let s="",i=0,a=1024*1024;o.on("data",c=>{if(i+=c.length,i>a){l("Response too large"),n.destroy(),e(null);return}s+=c;}),o.on("end",()=>{try{let u=JSON.parse(s),g=u._meta,m={};for(let[f,d]of Object.entries(u))f!=="_meta"&&(m[f]=d);this.validatePricingData(m)?(l(`Fetched fresh pricing from GitHub for ${Object.keys(m).length} models`),l(`Pricing last updated: ${g?.updated||"unknown"}`),e(m)):(l("Invalid pricing data structure"),e(null));}catch(c){l("Failed to parse JSON:",c),e(null);}}),o.on("error",c=>{l("Response error:",c),e(null);});});n.on("error",o=>{l("Request error:",o),e(null);}),n.on("timeout",()=>{l("Request timeout"),n.destroy(),e(null);}),n.end();})}static async getCurrentPricing(){if(this.executionCache!==null)return l(`[CACHE-HIT] Pricing execution cache: ${Object.keys(this.executionCache).length} models`),this.executionCache;let e=await this.loadDiskCache();if(e)return l(`[CACHE-HIT] Pricing disk cache: ${Object.keys(e).length} models`),this.executionCache=e,l(`[CACHE-SET] Pricing execution cache stored: ${Object.keys(e).length} models`),e;let t=await this.fetchPricingData();return t?(await this.saveDiskCache(t),l(`[CACHE-SET] Pricing disk cache stored: ${Object.keys(t).length} models`),this.executionCache=t,l(`[CACHE-SET] Pricing execution cache stored: ${Object.keys(t).length} models`),t):(l(`[CACHE-FALLBACK] Using offline pricing data: ${Object.keys(Q).length} models`),this.executionCache=Q,l(`[CACHE-SET] Pricing execution cache stored: ${Object.keys(Q).length} models`),Q)}static validatePricingData(e){if(!e||typeof e!="object")return false;for(let[,t]of Object.entries(e)){if(!t||typeof t!="object")return false;let n=t;if(typeof n.input!="number"||typeof n.output!="number"||typeof n.cache_read!="number")return false}return true}static async getModelPricing(e){if(this.modelPricingCache.has(e))return l(`[CACHE-HIT] Model pricing cache: ${e}`),this.modelPricingCache.get(e);let t=await this.getCurrentPricing(),n;return t[e]?n=t[e]:n=this.fuzzyMatchModel(e,t),this.modelPricingCache.set(e,n),l(`[CACHE-SET] Model pricing cache: ${e}`),n}static fuzzyMatchModel(e,t){let n=e.toLowerCase();for(let[s,i]of Object.entries(t))if(s.toLowerCase()===n)return i;let o=[{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","claude-sonnet-4"],fallback:"claude-sonnet-4-20250514"},{pattern:["sonnet-3.7","3-7-sonnet"],fallback:"claude-3-7-sonnet-20250219"},{pattern:["3-5-sonnet","sonnet-3.5"],fallback:"claude-3-5-sonnet-20241022"},{pattern:["3-5-haiku","haiku-3.5"],fallback:"claude-3-5-haiku-20241022"},{pattern:["haiku","3-haiku"],fallback:"claude-3-haiku-20240307"},{pattern:["opus"],fallback:"claude-opus-4-20250514"},{pattern:["sonnet"],fallback:"claude-3-5-sonnet-20241022"}];for(let{pattern:s,fallback:i}of o)if(s.some(a=>n.includes(a))&&t[i])return t[i];return t["claude-3-5-sonnet-20241022"]||{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 n=e.message?.usage;if(!n)return 0;let o=this.extractModelId(e),s=await this.getModelPricing(o),i=n.input_tokens||0,a=n.output_tokens||0,c=n.cache_creation_input_tokens||0,u=n.cache_read_input_tokens||0,g=i/1e6*s.input,m=a/1e6*s.output,f=u/1e6*s.cache_read,d=c/1e6*s.cache_write_5m;return g+m+d+f}static extractModelId(e){if(e.model&&typeof e.model=="string")return e.model;let t=e.message;if(t?.model){let n=t.model;return typeof n=="string"?n:n?.id||"claude-3-5-sonnet-20241022"}return e.model_id&&typeof e.model_id=="string"?e.model_id:"claude-3-5-sonnet-20241022"}};function ut(r){return {timestamp:r.timestamp.toISOString(),message:{usage:{input_tokens:r.message?.usage?.input_tokens||0,output_tokens:r.message?.usage?.output_tokens||0,cache_creation_input_tokens:r.message?.usage?.cache_creation_input_tokens,cache_read_input_tokens:r.message?.usage?.cache_read_input_tokens}},costUSD:r.costUSD}}var ee=class{async getSessionUsage(e){try{let t=await K(e);if(!t)return l(`No transcript found for session: ${e}`),null;l(`Found transcript at: ${t}`);let n=await I(t);if(n.length===0)return {totalCost:0,entries:[]};let o=[],s=0;for(let i of n)if(i.message?.usage){let a=ut(i);if(a.costUSD!==void 0)s+=a.costUSD;else {let c=await R.calculateCostForEntry(i.raw);a.costUSD=c,s+=c;}o.push(a);}return l(`Parsed ${o.length} usage entries, total cost: $${s.toFixed(4)}`),{totalCost:s,entries:o}}catch(t){return l(`Error reading session usage for ${e}:`,t),null}}calculateTokenBreakdown(e){return e.reduce((t,n)=>({input:t.input+(n.message.usage.input_tokens||0),output:t.output+(n.message.usage.output_tokens||0),cacheCreation:t.cacheCreation+(n.message.usage.cache_creation_input_tokens||0),cacheRead:t.cacheRead+(n.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 o=this.calculateTokenBreakdown(n.entries),s=o.input+o.output+o.cacheCreation+o.cacheRead,i=n.totalCost,a=t?.cost?.total_cost_usd??null;return {cost:i??a,calculatedCost:i,officialCost:a,tokens:s,tokenBreakdown:o}}},O=class{sessionProvider=new ee;async getUsageInfo(e,t){try{return l(`Starting usage info retrieval for session: ${e}`),{session:await this.sessionProvider.getSessionInfo(e,t)}}catch(n){return l(`Error getting usage info for session ${e}:`,n),{session:{cost:null,calculatedCost:null,officialCost:null,tokens:null,tokenBreakdown:null}}}}};var j=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},n=this.getModelType(e);return t[n]||t.default||2e5}getModelType(e){let t=e.toLowerCase();return t.includes("sonnet")?"sonnet":t.includes("opus")?"opus":"default"}async calculateContextTokens(e,t){try{l(`Calculating context tokens from transcript: ${e}`);try{if(!readFileSync(e,"utf-8"))return l("Transcript file is empty"),null}catch{return l("Could not read transcript file"),null}let n=await I(e);if(n.length===0)return l("No entries in transcript"),null;let o=null;for(let s=n.length-1;s>=0;s--){let i=n[s];if(i&&i.message?.usage?.input_tokens&&i.isSidechain!==!0){o=i,l(`Context segment: Found most recent entry at ${i.timestamp.toISOString()}, stopping search`);break}}if(o?.message?.usage){let s=o.message.usage,i=(s.input_tokens||0)+(s.cache_read_input_tokens||0)+(s.cache_creation_input_tokens||0),a=t?this.getContextLimit(t):2e5;l(`Most recent main chain context: ${i} tokens (limit: ${a})`);let c=Math.min(100,Math.max(0,Math.round(i/a*100))),u=Math.round(a*.75),g=Math.min(100,Math.max(0,Math.round(i/u*100))),m=Math.max(0,100-g);return {inputTokens:i,percentage:c,usablePercentage:g,contextLeftPercentage:m,maxTokens:a,usableTokens:u}}return l("No main chain entries with usage data found"),null}catch(n){return l(`Error reading transcript: ${n instanceof Error?n.message:String(n)}`),null}}};var N=class{async loadTranscriptEntries(e){try{let t=await K(e);if(!t)return l(`No transcript found for session: ${e}`),[];l(`Loading transcript from: ${t}`);let o=(await readFile(t,"utf-8")).trim().split(`
6
- `).filter(i=>i.trim()),s=[];for(let i of o)try{let a=JSON.parse(i);if(a.isSidechain===!0)continue;s.push(a);}catch(a){l(`Failed to parse JSONL line: ${a}`);continue}return l(`Loaded ${s.length} transcript entries`),s}catch(t){return l(`Error loading transcript for ${e}:`,t),[]}}calculateMessageCount(e){return e.filter(t=>{let n=t.type||t.message?.role||t.message?.type,o=t.type==="user"&&t.message?.content?.[0]?.type==="tool_result";return n==="user"&&!o}).length}calculateLastResponseTime(e){if(e.length===0)return null;let t=e.slice(-20),n=null,o=null;for(let s of t)if(s.timestamp)try{let i=new Date(s.timestamp),a=s.type||s.message?.role||s.message?.type,c=s.type==="user"&&s.message?.content?.[0]?.type==="tool_result";if(a==="user"&&!c)n=i;else if(a==="assistant"&&n){let g=(i.getTime()-n.getTime())/1e3;g>.1&&g<300&&(o=g);}}catch{continue}return o}async getMetricsInfo(e,t){try{if(l(`Getting metrics from hook data for session: ${e}`),!t.cost)return l("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),o=this.calculateMessageCount(n),s=this.calculateLastResponseTime(n);return {responseTime:t.cost.total_api_duration_ms/1e3,lastResponseTime:s,sessionDuration:t.cost.total_duration_ms/1e3,messageCount:o,linesAdded:t.cost.total_lines_added,linesRemoved:t.cost.total_lines_removed}}catch(n){return l(`Error getting metrics from hook data for session ${e}:`,n),{responseTime:null,lastResponseTime:null,sessionDuration:null,messageCount:null,linesAdded:null,linesRemoved:null}}}};function x(r){return r===null?"$0.00":r<.01?"<$0.01":`$${r.toFixed(2)}`}function C(r){return r===null||r===0?"0 tokens":r>=1e6?`${(r/1e6).toFixed(1)}M tokens`:r>=1e3?`${(r/1e3).toFixed(1)}K tokens`:`${r} tokens`}function pe(r){if(!r)return "0 tokens";let e=[];if(r.input>0&&e.push(`${C(r.input).replace(" tokens","")}in`),r.output>0&&e.push(`${C(r.output).replace(" tokens","")}out`),r.cacheCreation>0||r.cacheRead>0){let t=r.cacheCreation+r.cacheRead;e.push(`${C(t).replace(" tokens","")}cached`);}return e.length>0?e.join(" + "):"0 tokens"}function Ie(r){return r<60?`${r}s`:r<3600?`${Math.floor(r/60)}m`:r<86400?`${Math.floor(r/3600)}h`:r<604800?`${Math.floor(r/86400)}d`:`${Math.floor(r/604800)}w`}function Oe(r){return r<60?`${r.toFixed(0)}s`:r<3600?`${(r/60).toFixed(0)}m`:r<86400?`${(r/3600).toFixed(1)}h`:`${(r/86400).toFixed(1)}d`}function mt(r,e){return !e||e<=0||r<0?null:Math.min(100,r/e*100)}function ye(r,e,t=80){let n=mt(r,e);if(n===null)return {percentage:null,isWarning:false,displayText:""};let o=`${n.toFixed(0)}%`,s=n>=t,i="";return s?i=` !${o}`:n>=50?i=` +${o}`:i=` ${o}`,{percentage:n,isWarning:s,displayText:i}}var H=class{constructor(e,t){this.config=e;this.symbols=t;}renderDirectory(e,t,n){let o=e.workspace?.current_dir||e.cwd||"/",s=e.workspace?.project_dir;if(n?.showBasename)return {text:w.basename(o)||"root",bgColor:t.modeBg,fgColor:t.modeFg};let i=process.env.HOME||process.env.USERPROFILE,a=o,c=s;return i&&(o.startsWith(i)&&(a=o.replace(i,"~")),s&&s.startsWith(i)&&(c=s.replace(i,"~"))),{text:this.getDisplayDirectoryName(a,c),bgColor:t.modeBg,fgColor:t.modeFg}}renderGit(e,t,n){if(!e)return null;let o=[];if(n?.showRepoName&&e.repoName&&(o.push(e.repoName),e.isWorktree&&o.push(this.symbols.git_worktree)),n?.showOperation&&e.operation&&o.push(`[${e.operation}]`),o.push(`${this.symbols.branch} ${e.branch}`),n?.showTag&&e.tag&&o.push(`${this.symbols.git_tag} ${e.tag}`),n?.showSha&&e.sha&&o.push(`${this.symbols.git_sha} ${e.sha}`),n?.showAheadBehind!==false&&(e.ahead>0&&e.behind>0?o.push(`${this.symbols.git_ahead}${e.ahead}${this.symbols.git_behind}${e.behind}`):e.ahead>0?o.push(`${this.symbols.git_ahead}${e.ahead}`):e.behind>0&&o.push(`${this.symbols.git_behind}${e.behind}`)),n?.showWorkingTree){let i=[];e.staged&&e.staged>0&&i.push(`+${e.staged}`),e.unstaged&&e.unstaged>0&&i.push(`~${e.unstaged}`),e.untracked&&e.untracked>0&&i.push(`?${e.untracked}`),e.conflicts&&e.conflicts>0&&i.push(`!${e.conflicts}`),i.length>0&&o.push(`(${i.join(" ")})`);}if(n?.showUpstream&&e.upstream&&o.push(`${this.symbols.git_upstream}${e.upstream}`),n?.showStashCount&&e.stashCount&&e.stashCount>0&&o.push(`${this.symbols.git_stash} ${e.stashCount}`),n?.showTimeSinceCommit&&e.timeSinceCommit!==void 0){let i=Ie(e.timeSinceCommit);o.push(`${this.symbols.git_time} ${i}`);}let s=this.symbols.git_clean;return e.status==="conflicts"?s=this.symbols.git_conflicts:e.status==="dirty"&&(s=this.symbols.git_dirty),o.push(s),{text:o.join(" "),bgColor:t.gitBg,fgColor:t.gitFg}}renderModel(e,t){let n=e.model?.display_name||"Claude";return {text:`${this.symbols.model} ${n}`,bgColor:t.modelBg,fgColor:t.modelFg}}renderSession(e,t,n){let o=n?.type||"cost",s=n?.costSource,i=this.config.budget?.session,a=s?this.formatSessionUsageDisplay(e.session,o,s):this.formatUsageWithBudget(e.session.cost,e.session.tokens,e.session.tokenBreakdown,o,i?.amount,i?.warningThreshold||80,i?.type);return {text:`${this.symbols.session_cost} ${a}`,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){if(!e)return {text:`${this.symbols.context_time} 0 (100%)`,bgColor:t.contextBg,fgColor:t.contextFg};let o=`${e.contextLeftPercentage}%`;return {text:n?.showPercentageOnly?`${this.symbols.context_time} ${o}`:`${this.symbols.context_time} ${e.inputTokens.toLocaleString()} (${o})`,bgColor:t.contextBg,fgColor:t.contextFg}}renderMetrics(e,t,n,o){if(!e)return {text:`${this.symbols.metrics_response} new`,bgColor:t.metricsBg,fgColor:t.metricsFg};let s=[];if(o?.showLastResponseTime&&e.lastResponseTime!==null){let i=e.lastResponseTime<60?`${e.lastResponseTime.toFixed(1)}s`:`${(e.lastResponseTime/60).toFixed(1)}m`;s.push(`${this.symbols.metrics_last_response} ${i}`);}if(o?.showResponseTime!==false&&e.responseTime!==null){let i=e.responseTime<60?`${e.responseTime.toFixed(1)}s`:`${(e.responseTime/60).toFixed(1)}m`;s.push(`${this.symbols.metrics_response} ${i}`);}if(o?.showDuration!==false&&e.sessionDuration!==null){let i=Oe(e.sessionDuration);s.push(`${this.symbols.metrics_duration} ${i}`);}return o?.showMessageCount!==false&&e.messageCount!==null&&s.push(`${this.symbols.metrics_messages} ${e.messageCount}`),o?.showLinesAdded!==false&&e.linesAdded!==null&&e.linesAdded>0&&s.push(`${this.symbols.metrics_lines_added} ${e.linesAdded}`),o?.showLinesRemoved!==false&&e.linesRemoved!==null&&e.linesRemoved>0&&s.push(`${this.symbols.metrics_lines_removed} ${e.linesRemoved}`),s.length===0?{text:`${this.symbols.metrics_response} active`,bgColor:t.metricsBg,fgColor:t.metricsFg}:{text:s.join(" "),bgColor:t.metricsBg,fgColor:t.metricsFg}}renderBlock(e,t,n){let o;if(e.cost===null&&e.tokens===null)o="No active block";else {let s=n?.type||"cost",i=n?.burnType,a=this.config.budget?.block,c=e.timeRemaining!==null?(()=>{let m=Math.floor(e.timeRemaining/60),f=e.timeRemaining%60;return m>0?`${m}h ${f}m`:`${f}m`})():null,u;switch(s){case "cost":a?.amount&&a?.type==="cost"?u=this.formatUsageWithBudget(e.cost,null,null,"cost",a.amount,a.warningThreshold,a.type):u=x(e.cost);break;case "tokens":a?.amount&&a?.type==="tokens"?u=this.formatUsageWithBudget(null,e.tokens,null,"tokens",a.amount,a.warningThreshold,a.type):u=C(e.tokens);break;case "weighted":let m=a?.type==="tokens"?a.amount:void 0,f=C(e.weightedTokens);if(m&&e.weightedTokens!==null){let d=ye(e.weightedTokens,m,a?.warningThreshold||80);u=`${f}${d.displayText}`;}else u=`${f} (weighted)`;break;case "both":a?.amount?u=this.formatUsageWithBudget(e.cost,e.tokens,null,"both",a.amount,a.warningThreshold,a.type):u=`${x(e.cost)} / ${C(e.tokens)}`;break;case "time":u=c||"N/A";break;default:a?.amount&&a?.type==="cost"?u=this.formatUsageWithBudget(e.cost,null,null,"cost",a.amount,a.warningThreshold,a.type):u=x(e.cost);}let g="";if(i&&i!=="none")switch(i){case "cost":g=` | ${e.burnRate!==null?e.burnRate<1?`${(e.burnRate*100).toFixed(0)}\xA2/h`:`$${e.burnRate.toFixed(2)}/h`:"N/A"}`;break;case "tokens":g=` | ${e.tokenBurnRate!==null?`${C(Math.round(e.tokenBurnRate))}/h`:"N/A"}`;break;case "both":let d=e.burnRate!==null?e.burnRate<1?`${(e.burnRate*100).toFixed(0)}\xA2/h`:`$${e.burnRate.toFixed(2)}/h`:"N/A",h=e.tokenBurnRate!==null?`${C(Math.round(e.tokenBurnRate))}/h`:"N/A";g=` | ${d} / ${h}`;break}s==="time"?o=u:o=c?`${u}${g} (${c} left)`:`${u}${g}`;}return {text:`${this.symbols.block_cost} ${o}`,bgColor:t.blockBg,fgColor:t.blockFg}}renderToday(e,t,n="cost"){let o=this.config.budget?.today;return {text:`${this.symbols.today_cost} ${this.formatUsageWithBudget(e.cost,e.tokens,e.tokenBreakdown,n,o?.amount,o?.warningThreshold,o?.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)||w.basename(t)||"project":w.basename(e)||"root":w.basename(e)||"root"}formatUsageDisplay(e,t,n,o){switch(o){case "cost":return x(e);case "tokens":return C(t);case "both":return `${x(e)} (${C(t)})`;case "breakdown":return pe(n);default:return x(e)}}formatSessionUsageDisplay(e,t,n){let o=()=>n==="calculated"?e.calculatedCost:n==="official"?e.officialCost:e.cost;switch(t){case "cost":return x(o());case "tokens":return C(e.tokens);case "both":return `${x(o())} (${C(e.tokens)})`;case "breakdown":return pe(e.tokenBreakdown);default:return x(o())}}formatUsageWithBudget(e,t,n,o,s,i=80,a){let c=this.formatUsageDisplay(e,t,n,o);if(s&&s>0){let u=null;if(a==="tokens"&&t!==null?u=t:(a==="cost"&&e!==null||!a&&e!==null)&&(u=e),u!==null){let g=ye(u,s,i);return c+g.displayText}}return c}renderVersion(e,t,n){return e.version?{text:`${this.symbols.version} v${e.version}`,bgColor:t.versionBg,fgColor:t.versionFg}:null}};function dt(r){return r.includes("opus")?5:(r.includes("sonnet")||r.includes("haiku"),1)}function ht(r){return {timestamp:r.timestamp,usage:{inputTokens:r.message?.usage?.input_tokens||0,outputTokens:r.message?.usage?.output_tokens||0,cacheCreationInputTokens:r.message?.usage?.cache_creation_input_tokens||0,cacheReadInputTokens:r.message?.usage?.cache_read_input_tokens||0},costUSD:r.costUSD||0,model:r.message?.model||"unknown"}}var ne=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=[],o=[...e].sort((a,c)=>a.timestamp.getTime()-c.timestamp.getTime()),s=null,i=[];for(let a of o){let c=a.timestamp;if(s==null)s=this.floorToHour(c),i=[a];else {let u=c.getTime()-s.getTime(),g=i[i.length-1];if(g==null)continue;let m=g.timestamp,f=c.getTime()-m.getTime();u>t||f>t?(n.push(i),s=this.floorToHour(c),i=[a]):i.push(a);}}return s!=null&&i.length>0&&n.push(i),n}createBlockInfo(e,t){let n=new Date,o=this.sessionDurationHours*60*60*1e3,s=new Date(e.getTime()+o),i=t[t.length-1],a=i!=null?i.timestamp:e,c=n.getTime()-a.getTime()<o&&n<s;return {block:t,isActive:c}}findActiveBlock(e){for(let t=e.length-1;t>=0;t--){let n=e[t];if(!n||n.length===0)continue;let o=n[0];if(!o)continue;let s=this.floorToHour(o.timestamp),i=this.createBlockInfo(s,n);if(i.isActive)return i.block}return null}async loadUsageEntries(){try{l("Block segment: Loading entries for dynamic session blocks");let e=new Date;e.setDate(e.getDate()-1);let n=await Z(void 0,(c,u)=>u>=e,!0),o=[];for(let c of n)if(c.message?.usage){let u=ht(c);!u.costUSD&&c.raw&&(u.costUSD=await R.calculateCostForEntry(c.raw)),o.push(u);}let s=this.identifySessionBlocks(o);l(`Block segment: Found ${s.length} session blocks`);let i=this.findActiveBlock(s),a=[];if(i&&i.length>0){l(`Block segment: Found active block with ${i.length} entries`);let c=i[0],u=i[i.length-1];c&&u&&l(`Block segment: Active block from ${c.timestamp.toISOString()} to ${u.timestamp.toISOString()}`),a=i;}else l("Block segment: No active block found"),a=[];return a}catch(e){return l("Error loading block entries:",e),[]}}async getActiveBlockInfo(){try{let e=await this.loadUsageEntries();if(e.length===0)return l("Block segment: No entries in current block"),{cost:null,tokens:null,weightedTokens:null,timeRemaining:null,burnRate:null,tokenBurnRate:null};let t=e.reduce((u,g)=>u+g.costUSD,0),n=e.reduce((u,g)=>u+g.usage.inputTokens+g.usage.outputTokens+g.usage.cacheCreationInputTokens+g.usage.cacheReadInputTokens,0),o=e.reduce((u,g)=>{let m=g.usage.inputTokens+g.usage.outputTokens+g.usage.cacheCreationInputTokens+g.usage.cacheReadInputTokens,f=dt(g.model);return u+m*f},0),s=new Date,i=null;if(e.length>0){let u=e[0];if(u){let g=this.sessionDurationHours*60*60*1e3,m=this.floorToHour(u.timestamp),f=new Date(m.getTime()+g);i=Math.max(0,Math.round((f.getTime()-s.getTime())/(1e3*60)));}}let a=null,c=null;if(e.length>=1&&(t>0||n>0)){let u=e.map(f=>f.timestamp).sort((f,d)=>f.getTime()-d.getTime()),g=u[0],m=u[u.length-1];if(g&&m){let f=(m.getTime()-g.getTime())/6e4;f>0&&(t>0&&(a=t/f*60),n>0&&(c=n/f*60));}}return l(`Block segment: $${t.toFixed(2)}, ${n} tokens, ${i}m remaining, burn rate: ${a?"$"+a.toFixed(2)+"/hr":"N/A"}`),{cost:t,tokens:n,weightedTokens:o,timeRemaining:i,burnRate:a,tokenBurnRate:c}}catch(e){return l("Error getting active block info:",e),{cost:null,tokens:null,weightedTokens:null,timeRemaining:null,burnRate:null,tokenBurnRate:null}}}};function G(r){let e=r.getFullYear(),t=String(r.getMonth()+1).padStart(2,"0"),n=String(r.getDate()).padStart(2,"0");return `${e}-${t}-${n}`}function pt(r){return r.inputTokens+r.outputTokens+r.cacheCreationInputTokens+r.cacheReadInputTokens}function yt(r){return {timestamp:r.timestamp,usage:{inputTokens:r.message?.usage?.input_tokens||0,outputTokens:r.message?.usage?.output_tokens||0,cacheCreationInputTokens:r.message?.usage?.cache_creation_input_tokens||0,cacheReadInputTokens:r.message?.usage?.cache_read_input_tokens||0},costUSD:r.costUSD||0,model:r.message?.model||"unknown"}}var oe=class{async loadTodayEntries(){let t=G(new Date);l(`Today segment: Loading entries for date ${t}`);let n=await $.getLatestTranscriptMtime(),o=await $.getUsageCache("today",n);if(o)return l("Using shared today usage cache"),o;let s=new Date;s.setDate(s.getDate()-1),s.setHours(0,0,0,0);let i=(f,d)=>d>=s,a=new Date;a.setHours(0,0,0,0);let u=await Z(f=>f.timestamp>=a,i,true),g=[],m=0;for(let f of u)if(G(f.timestamp)===t&&f.message?.usage){let h=yt(f);!h.costUSD&&f.raw&&(h.costUSD=await R.calculateCostForEntry(f.raw)),g.push(h),m++;}return l(`Today segment: Found ${m} entries for today (${t})`),await $.setUsageCache("today",g,n),g}async getTodayEntries(){try{return await this.loadTodayEntries()}catch(e){return l("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:G(new Date)};let t=e.reduce((s,i)=>s+i.costUSD,0),n=e.reduce((s,i)=>s+pt(i.usage),0),o=e.reduce((s,i)=>({input:s.input+i.usage.inputTokens,output:s.output+i.usage.outputTokens,cacheCreation:s.cacheCreation+i.usage.cacheCreationInputTokens,cacheRead:s.cacheRead+i.usage.cacheReadInputTokens}),{input:0,output:0,cacheCreation:0,cacheRead:0});return l(`Today segment: $${t.toFixed(2)}, ${n} tokens total`),{cost:t,tokens:n,tokenBreakdown:o,date:G(new Date)}}catch(e){return l("Error getting today's info:",e),{cost:null,tokens:null,tokenBreakdown:null,date:G(new Date)}}}};var D="\x1B[0m",p={right:"\uE0B0",left_rounded:"\uE0B6",right_rounded:"\uE0B4",branch:"\u2387",model:"\u2731",git_clean:"\u2713",git_dirty:"\u25CF",git_conflicts:"\u26A0",git_ahead:"\u2191",git_behind:"\u2193",git_worktree:"\u29C9",git_tag:"\u2302",git_sha:"\u266F",git_upstream:"\u2192",git_stash:"\u29C7",git_time:"\u25F7",session_cost:"\xA7",block_cost:"\u25F1",today_cost:"\u2609",context_time:"\u25D4",metrics_response:"\u29D6",metrics_last_response:"\u0394",metrics_duration:"\u29D7",metrics_messages:"\u27D0",metrics_lines_added:"+",metrics_lines_removed:"-",metrics_burn:"\u27E2",version:"\u25C8"};var re=class{constructor(e){this.config=e;this.symbols=this.initializeSymbols();}symbols;_usageProvider;_blockProvider;_todayProvider;_contextProvider;_gitService;_tmuxService;_metricsProvider;_segmentRenderer;get usageProvider(){return this._usageProvider||(this._usageProvider=new O),this._usageProvider}get blockProvider(){return this._blockProvider||(this._blockProvider=new ne),this._blockProvider}get todayProvider(){return this._todayProvider||(this._todayProvider=new oe),this._todayProvider}get contextProvider(){return this._contextProvider||(this._contextProvider=new j(this.config)),this._contextProvider}get gitService(){return this._gitService||(this._gitService=new F),this._gitService}get tmuxService(){return this._tmuxService||(this._tmuxService=new L),this._tmuxService}get metricsProvider(){return this._metricsProvider||(this._metricsProvider=new N),this._metricsProvider}get segmentRenderer(){return this._segmentRenderer||(this._segmentRenderer=new H(this.config,this.symbols)),this._segmentRenderer}needsSegmentInfo(e){return this.config.display.lines.some(t=>t.segments[e]?.enabled)}async generateStatusline(e){let t=this.needsSegmentInfo("session")?await this.usageProvider.getUsageInfo(e.session_id,e):null,n=this.needsSegmentInfo("block")?await this.blockProvider.getActiveBlockInfo():null,o=this.needsSegmentInfo("today")?await this.todayProvider.getTodayInfo():null,s=this.needsSegmentInfo("context")?await this.contextProvider.calculateContextTokens(e.transcript_path,e.model?.id):null,i=this.needsSegmentInfo("metrics")?await this.metricsProvider.getMetricsInfo(e.session_id,e):null;return (await Promise.all(this.config.display.lines.map(c=>this.renderLine(c,e,t,n,o,s,i)))).filter(c=>c.length>0).join(`
7
- `)}async renderLine(e,t,n,o,s,i,a){let c=this.getThemeColors(),u=t.workspace?.current_dir||t.cwd||"/",g=Object.entries(e.segments).filter(([d,h])=>h?.enabled).map(([d,h])=>({type:d,config:h})),m=this.config.display.style==="capsule",f=c.reset;for(let d=0;d<g.length;d++){let h=g[d];if(!h)continue;let y=d===0,T=d===g.length-1,A=T?null:g[d+1],v=A?this.getSegmentBgColor(A.type,c):"",_=await this.renderSegment(h,t,n,o,s,i,a,c,u);_&&(m&&!y&&(f+=" "),f+=this.formatSegment(_.bgColor,_.fgColor,_.text,T?void 0:v));}return f}async renderSegment(e,t,n,o,s,i,a,c,u){return e.type==="directory"?this.segmentRenderer.renderDirectory(t,c,e.config):e.type==="model"?this.segmentRenderer.renderModel(t,c):e.type==="git"?await this.renderGitSegment(e.config,t,c,u):e.type==="session"?this.renderSessionSegment(e.config,n,c):e.type==="tmux"?await this.renderTmuxSegment(c):e.type==="context"?this.renderContextSegment(e.config,i,c):e.type==="metrics"?this.renderMetricsSegment(e.config,a,o,c):e.type==="block"?this.renderBlockSegment(e.config,o,c):e.type==="today"?this.renderTodaySegment(e.config,s,c):e.type==="version"?this.renderVersionSegment(e.config,t,c):null}async renderGitSegment(e,t,n,o){if(!this.needsSegmentInfo("git"))return null;let s=await this.gitService.getGitInfo(o,{showSha:e?.showSha,showWorkingTree:e?.showWorkingTree,showOperation:e?.showOperation,showTag:e?.showTag,showTimeSinceCommit:e?.showTimeSinceCommit,showStashCount:e?.showStashCount,showUpstream:e?.showUpstream,showRepoName:e?.showRepoName},t.workspace?.project_dir);return s?this.segmentRenderer.renderGit(s,n,e):null}renderSessionSegment(e,t,n){return t?this.segmentRenderer.renderSession(t,n,e):null}async renderTmuxSegment(e){if(!this.needsSegmentInfo("tmux"))return null;let t=await this.tmuxService.getSessionId();return this.segmentRenderer.renderTmux(t,e)}renderContextSegment(e,t,n){return this.needsSegmentInfo("context")?this.segmentRenderer.renderContext(t,n,e):null}renderMetricsSegment(e,t,n,o){return this.segmentRenderer.renderMetrics(t,o,n,e)}renderBlockSegment(e,t,n){return t?this.segmentRenderer.renderBlock(t,n,e):null}renderTodaySegment(e,t,n){if(!t)return null;let o=e?.type||"cost";return this.segmentRenderer.renderToday(t,n,o)}renderVersionSegment(e,t,n){return this.segmentRenderer.renderVersion(t,n,e)}initializeSymbols(){let e=this.config.display.style,t=e==="minimal",n=e==="capsule";return {right:t?"":n?p.right_rounded:p.right,left:n?p.left_rounded:"",branch:p.branch,model:p.model,git_clean:p.git_clean,git_dirty:p.git_dirty,git_conflicts:p.git_conflicts,git_ahead:p.git_ahead,git_behind:p.git_behind,git_worktree:p.git_worktree,git_tag:p.git_tag,git_sha:p.git_sha,git_upstream:p.git_upstream,git_stash:p.git_stash,git_time:p.git_time,session_cost:p.session_cost,block_cost:p.block_cost,today_cost:p.today_cost,context_time:p.context_time,metrics_response:p.metrics_response,metrics_last_response:p.metrics_last_response,metrics_duration:p.metrics_duration,metrics_messages:p.metrics_messages,metrics_lines_added:p.metrics_lines_added,metrics_lines_removed:p.metrics_lines_removed,metrics_burn:p.metrics_burn,version:p.version}}getThemeColors(){let e=this.config.theme,t,n=this.config.display.colorCompatibility||"auto",o=n==="auto"?Y():n;if(e==="custom"){if(t=this.config.colors?.custom,!t)throw new Error("Custom theme selected but no colors provided in configuration")}else t=q(e,o),t||(console.warn(`Built-in theme '${e}' not found, falling back to 'dark' theme`),t=q("dark",o));let s=q("dark",o),i=A=>{let v=t[A]||s[A];return o==="ansi"?{bg:ue(v.bg,true),fg:ue(v.fg,false)}:o==="ansi256"?{bg:le(v.bg,true),fg:le(v.fg,false)}:{bg:ce(v.bg,true),fg:ce(v.fg,false)}},a=i("directory"),c=i("git"),u=i("model"),g=i("session"),m=i("block"),f=i("today"),d=i("tmux"),h=i("context"),y=i("metrics"),T=i("version");return {reset:D,modeBg:a.bg,modeFg:a.fg,gitBg:c.bg,gitFg:c.fg,modelBg:u.bg,modelFg:u.fg,sessionBg:g.bg,sessionFg:g.fg,blockBg:m.bg,blockFg:m.fg,todayBg:f.bg,todayFg:f.fg,tmuxBg:d.bg,tmuxFg:d.fg,contextBg:h.bg,contextFg:h.fg,metricsBg:y.bg,metricsFg:y.fg,versionBg:T.bg,versionFg:T.fg}}getSegmentBgColor(e,t){switch(e){case "directory":return t.modeBg;case "git":return t.gitBg;case "model":return t.modelBg;case "session":return t.sessionBg;case "block":return t.blockBg;case "today":return t.todayBg;case "tmux":return t.tmuxBg;case "context":return t.contextBg;case "metrics":return t.metricsBg;case "version":return t.versionBg;default:return t.modeBg}}formatSegment(e,t,n,o){if(this.config.display.style==="capsule"){let g=this.config.display.colorCompatibility||"auto",f=(g==="auto"?Y():g)==="ansi",d=J(e,f),h=`${d}${this.symbols.left}${D}`,y=`${e}${t} ${n} ${D}`,T=`${d}${this.symbols.right}${D}`;return `${h}${y}${T}`}let i=`${e}${t} ${n} `,a=this.config.display.colorCompatibility||"auto",u=(a==="auto"?Y():a)==="ansi";if(o){let g=J(e,u);i+=`${D}${o}${g}${this.symbols.right}`;}else i+=`${D}${J(e,u)}${this.symbols.right}${D}`;return i}};var je={theme:"dark",display:{style:"minimal",colorCompatibility:"auto",lines:[{segments:{directory:{enabled:true,showBasename:true},git:{enabled:true,showSha:false,showWorkingTree:false,showOperation:false,showTag:false,showTimeSinceCommit:false,showStashCount:false,showUpstream:false,showRepoName:false},model:{enabled:true},session:{enabled:true,type:"tokens",costSource:"calculated"},today:{enabled:true,type:"cost"},block:{enabled:false,type:"cost",burnType:"cost"},version:{enabled:false},tmux:{enabled:false},context:{enabled:true,showPercentageOnly:false},metrics:{enabled:false,showResponseTime:true,showLastResponseTime:true,showDuration:true,showMessageCount:true,showLinesAdded:true,showLinesRemoved:true}}}]},budget:{session:{warningThreshold:80},today:{warningThreshold:80,amount:50},block:{warningThreshold:80,amount:15}},modelContextLimits:{default:2e5,sonnet:2e5,opus:2e5}};function Ce(r){return ["light","dark","nord","tokyo-night","rose-pine","custom"].includes(r)}function _e(r){return r==="minimal"||r==="powerline"||r==="capsule"}function ie(r,e){let t={...r};for(let n in e){let o=e[n];if(o!==void 0)if(typeof o=="object"&&o!==null&&!Array.isArray(o)){let s=t[n]||{};t[n]=ie(s,o);}else t[n]=o;}return t}function bt(r,e){return r?S.existsSync(r)?r:null:[...e?[w.join(e,".claude-powerline.json")]:[],w.join(process.cwd(),".claude-powerline.json"),w.join(M.homedir(),".claude","claude-powerline.json"),w.join(M.homedir(),".config","claude-powerline","config.json")].find(S.existsSync)||null}function Ct(r){try{let e=S.readFileSync(r,"utf-8");return JSON.parse(e)}catch(e){throw new Error(`Failed to load config file ${r}: ${e instanceof Error?e.message:String(e)}`)}}function _t(){let r={},e={},t=process.env.CLAUDE_POWERLINE_THEME;t&&Ce(t)&&(r.theme=t);let n=process.env.CLAUDE_POWERLINE_STYLE;return n&&(_e(n)?e.style=n:(console.warn(`Invalid display style '${n}' from environment variable, falling back to 'minimal'`),e.style="minimal")),Object.keys(e).length>0&&(r.display=e),r}function wt(){return process.env.CLAUDE_POWERLINE_CONFIG}function kt(r){let e={},t={},n=r.find(s=>s.startsWith("--theme="))?.split("=")[1];n&&Ce(n)&&(e.theme=n);let o=r.find(s=>s.startsWith("--style="))?.split("=")[1];return o&&(_e(o)?t.style=o:(console.warn(`Invalid display style '${o}' from CLI argument, falling back to 'minimal'`),t.style="minimal")),Object.keys(t).length>0&&(e.display=t),e}function St(r=process.argv,e){let t=JSON.parse(JSON.stringify(je)),n=r.find(a=>a.startsWith("--config="))?.split("=")[1]||wt(),o=bt(n,e);if(o)try{let a=Ct(o);t=ie(t,a);}catch(a){console.warn(`Warning: ${a instanceof Error?a.message:String(a)}`);}t.display?.style&&!_e(t.display.style)&&(console.warn(`Invalid display style '${t.display.style}' in config file, falling back to 'minimal'`),t.display.style="minimal"),t.theme&&!Ce(t.theme)&&(console.warn(`Invalid theme '${t.theme}' in config file, falling back to 'dark'`),t.theme="dark");let s=_t();t=ie(t,s);let i=kt(r);return t=ie(t,i),t}var He=St;async function xt(){try{let r=M.platform(),e;if(r==="darwin")e=w.join(M.homedir(),"Library","Fonts");else if(r==="linux")e=w.join(M.homedir(),".local","share","fonts");else if(r==="win32")e=w.join(M.homedir(),"AppData","Local","Microsoft","Windows","Fonts");else {console.log("Unsupported platform for font installation");return}S.existsSync(e)||S.mkdirSync(e,{recursive:!0}),console.log("Installing Powerline Fonts..."),console.log("Downloading from https://github.com/powerline/fonts");let t=w.join(M.tmpdir(),"powerline-fonts"),n=()=>{S.existsSync(t)&&S.rmSync(t,{recursive:!0,force:!0});};b.on("SIGINT",n),b.on("SIGTERM",n);try{S.existsSync(t)&&S.rmSync(t,{recursive:!0,force:!0}),console.log("Cloning powerline fonts repository..."),execSync("git clone --depth=1 https://github.com/powerline/fonts.git powerline-fonts",{stdio:"inherit",cwd:M.tmpdir()}),console.log("Installing fonts...");let o=w.join(t,"install.sh");if(S.existsSync(o))S.chmodSync(o,493),execSync("./install.sh",{stdio:"inherit",cwd:t});else throw new Error("Install script not found in powerline fonts repository");console.log("Powerline fonts installation complete!"),console.log("Please restart your terminal and set your terminal font to a powerline font."),console.log("Popular choices: Source Code Pro Powerline, DejaVu Sans Mono Powerline, Ubuntu Mono Powerline");}finally{n(),b.removeListener("SIGINT",n),b.removeListener("SIGTERM",n);}}catch(r){console.error("Error installing fonts:",r instanceof Error?r.message:String(r)),console.log("You can manually install fonts from: https://github.com/powerline/fonts");}}function We(){console.log(`
2
+ import S from'process';import {json}from'stream/consumers';import H from'tty';import {exec}from'child_process';import {promisify}from'util';import k,{existsSync,readFileSync,createReadStream}from'fs';import _,{join,posix}from'path';import {get}from'https';import {URL}from'url';import Oe,{homedir}from'os';import {createHash}from'crypto';import {setTimeout}from'timers/promises';import {readdir,stat,readFile}from'fs/promises';import {createInterface}from'readline';function se(o,e){if(e&&(o.toLowerCase()==="transparent"||o.toLowerCase()==="none"))return "\x1B[49m";let t=parseInt(o.slice(1,3),16),n=parseInt(o.slice(3,5),16),r=parseInt(o.slice(5,7),16);return `\x1B[${e?"48":"38"};2;${t};${n};${r}m`}function G(o,e=false){let t=o.match(/48;2;(\d+);(\d+);(\d+)/);if(t)return `\x1B[38;2;${t[1]};${t[2]};${t[3]}m`;if(e)return "\x1B[37m";if(o.includes("\x1B[")&&o.includes("m")){let n=o.match(/\[(\d+)m/);if(n&&n[1]){let r=parseInt(n[1],10);if(r>=40&&r<=47)return `\x1B[${r-10}m`;if(r>=100&&r<=107)return `\x1B[${r-10}m`}}return o.replace("48","38")}function W(){let{env:o}=S;if(o.NO_COLOR)return "none";let e=o.FORCE_COLOR;if(e==="false"||e==="0")return "none";if(e==="true"||e==="1")return "ansi";if(e==="2")return "ansi256";if(e==="3")return "truecolor";if(o.TERM==="dumb")return "none";if(o.CI)return ["GITHUB_ACTIONS","GITEA_ACTIONS","CIRCLECI"].some(n=>n in o)?"truecolor":"ansi";if(o.COLORTERM==="truecolor"||["xterm-kitty","xterm-ghostty","wezterm","alacritty","foot","contour"].includes(o.TERM||""))return "truecolor";if(o.TERM_PROGRAM)switch(o.TERM_PROGRAM){case "iTerm.app":return "truecolor";case "Apple_Terminal":return "ansi256";case "vscode":return "truecolor";case "Tabby":return "truecolor"}if(/-256(color)?$/i.test(o.TERM||""))return "ansi256";if(/-truecolor$/i.test(o.TERM||""))return "truecolor";if(/^screen|^xterm|^vt100|^vt220|^rxvt|color|ansi|cygwin|linux/i.test(o.TERM||"")||o.COLORTERM)return "ansi";if(H?.WriteStream?.prototype?.hasColors)try{if(!H.WriteStream.prototype.hasColors())return "none";let r=H.WriteStream.prototype.hasColors(256);return H.WriteStream.prototype.hasColors(16777216)?"truecolor":r?"ansi256":"ansi"}catch{}return "ansi"}function ie(o,e){if(e&&(o.toLowerCase()==="transparent"||o.toLowerCase()==="none"))return "\x1B[49m";let t=parseInt(o.slice(1,3),16),n=parseInt(o.slice(3,5),16),r=parseInt(o.slice(5,7),16),i=((a,c,u)=>a===c&&c===u?a<8?16:a>248?231:Math.round((a-8)/247*24)+232:16+36*Math.round(a/255*5)+6*Math.round(c/255*5)+Math.round(u/255*5))(t,n,r);return `\x1B[${e?"48":"38"};5;${i}m`}function ae(o,e){if(e&&(o.toLowerCase()==="transparent"||o.toLowerCase()==="none"))return "\x1B[49m";if(e)return "";let t=parseInt(o.slice(1,3),16),n=parseInt(o.slice(3,5),16),r=parseInt(o.slice(5,7),16);return n>t&&n>r&&n>120?"\x1B[32m":t>n&&t>r&&t>120?"\x1B[31m":r>t&&r>n&&r>120?"\x1B[34m":(t+n+r)/3>150?"\x1B[37m":"\x1B[90m"}var ye={directory:{bg:"#8b4513",fg:"#ffffff"},git:{bg:"#404040",fg:"#ffffff"},model:{bg:"#2d2d2d",fg:"#ffffff"},session:{bg:"#202020",fg:"#00ffff"},block:{bg:"#2a2a2a",fg:"#87ceeb"},today:{bg:"#1a1a1a",fg:"#98fb98"},tmux:{bg:"#2f4f2f",fg:"#90ee90"},context:{bg:"#4a5568",fg:"#cbd5e0"},metrics:{bg:"#374151",fg:"#d1d5db"},version:{bg:"#3a3a4a",fg:"#b8b8d0"}},Ce={directory:{bg:"#af5f00",fg:"#ffffff"},git:{bg:"#444444",fg:"#ffffff"},model:{bg:"#3a3a3a",fg:"#ffffff"},session:{bg:"#262626",fg:"#00ffff"},block:{bg:"#303030",fg:"#87ceeb"},today:{bg:"#1c1c1c",fg:"#87ff87"},tmux:{bg:"#444444",fg:"#87ff87"},context:{bg:"#585858",fg:"#d0d0d0"},metrics:{bg:"#4e4e4e",fg:"#d0d0d0"},version:{bg:"#444444",fg:"#d7afff"}},_e={directory:{bg:"#d75f00",fg:"#ffffff"},git:{bg:"#585858",fg:"#ffffff"},model:{bg:"#444444",fg:"#ffffff"},session:{bg:"#303030",fg:"#00ffff"},block:{bg:"#3a3a3a",fg:"#5fafff"},today:{bg:"#262626",fg:"#00ff00"},tmux:{bg:"#585858",fg:"#00ff00"},context:{bg:"#808080",fg:"#ffffff"},metrics:{bg:"#666666",fg:"#ffffff"},version:{bg:"#585858",fg:"#af87ff"}};var we={directory:{bg:"#ff6b47",fg:"#ffffff"},git:{bg:"#4fb3d9",fg:"#ffffff"},model:{bg:"#87ceeb",fg:"#000000"},session:{bg:"#da70d6",fg:"#ffffff"},block:{bg:"#6366f1",fg:"#ffffff"},today:{bg:"#10b981",fg:"#ffffff"},tmux:{bg:"#32cd32",fg:"#ffffff"},context:{bg:"#718096",fg:"#ffffff"},metrics:{bg:"#6b7280",fg:"#ffffff"},version:{bg:"#8b7dd8",fg:"#ffffff"}},ke={directory:{bg:"#ff5f5f",fg:"#ffffff"},git:{bg:"#5fafff",fg:"#ffffff"},model:{bg:"#87d7ff",fg:"#000000"},session:{bg:"#ff5fff",fg:"#ffffff"},block:{bg:"#5f5fff",fg:"#ffffff"},today:{bg:"#00d787",fg:"#ffffff"},tmux:{bg:"#00ff5f",fg:"#ffffff"},context:{bg:"#808080",fg:"#ffffff"},metrics:{bg:"#767676",fg:"#ffffff"},version:{bg:"#af87ff",fg:"#ffffff"}},Se={directory:{bg:"#ff5f5f",fg:"#ffffff"},git:{bg:"#5fafff",fg:"#ffffff"},model:{bg:"#87d7ff",fg:"#000000"},session:{bg:"#ff5fff",fg:"#ffffff"},block:{bg:"#5f5fff",fg:"#ffffff"},today:{bg:"#00d787",fg:"#ffffff"},tmux:{bg:"#00ff5f",fg:"#ffffff"},context:{bg:"#808080",fg:"#ffffff"},metrics:{bg:"#767676",fg:"#ffffff"},version:{bg:"#af87ff",fg:"#ffffff"}};var Te={directory:{bg:"#434c5e",fg:"#d8dee9"},git:{bg:"#3b4252",fg:"#a3be8c"},model:{bg:"#4c566a",fg:"#81a1c1"},session:{bg:"#2e3440",fg:"#88c0d0"},block:{bg:"#3b4252",fg:"#81a1c1"},today:{bg:"#2e3440",fg:"#8fbcbb"},tmux:{bg:"#2e3440",fg:"#8fbcbb"},context:{bg:"#5e81ac",fg:"#eceff4"},metrics:{bg:"#b48ead",fg:"#2e3440"},version:{bg:"#434c5e",fg:"#88c0d0"}},xe={directory:{bg:"#5f87af",fg:"#e4e4e4"},git:{bg:"#4e4e4e",fg:"#87d787"},model:{bg:"#6c6c6c",fg:"#87afd7"},session:{bg:"#3a3a3a",fg:"#5fafaf"},block:{bg:"#4e4e4e",fg:"#87afd7"},today:{bg:"#3a3a3a",fg:"#5fd7d7"},tmux:{bg:"#3a3a3a",fg:"#5fd7d7"},context:{bg:"#5f87d7",fg:"#ffffff"},metrics:{bg:"#d787af",fg:"#3a3a3a"},version:{bg:"#5f87af",fg:"#5fafaf"}},ve={directory:{bg:"#0087af",fg:"#ffffff"},git:{bg:"#585858",fg:"#87d700"},model:{bg:"#808080",fg:"#87afff"},session:{bg:"#444444",fg:"#00d7d7"},block:{bg:"#585858",fg:"#87afff"},today:{bg:"#444444",fg:"#00ffff"},tmux:{bg:"#444444",fg:"#00ffff"},context:{bg:"#0087ff",fg:"#ffffff"},metrics:{bg:"#ff87d7",fg:"#444444"},version:{bg:"#0087af",fg:"#00d7d7"}};var Ee={directory:{bg:"#2f334d",fg:"#82aaff"},git:{bg:"#1e2030",fg:"#c3e88d"},model:{bg:"#191b29",fg:"#fca7ea"},session:{bg:"#222436",fg:"#86e1fc"},block:{bg:"#2d3748",fg:"#7aa2f7"},today:{bg:"#1a202c",fg:"#4fd6be"},tmux:{bg:"#191b29",fg:"#4fd6be"},context:{bg:"#414868",fg:"#c0caf5"},metrics:{bg:"#3d59a1",fg:"#c0caf5"},version:{bg:"#292e42",fg:"#bb9af7"}},Pe={directory:{bg:"#444478",fg:"#87afff"},git:{bg:"#262640",fg:"#afff87"},model:{bg:"#1c1c30",fg:"#ff87ff"},session:{bg:"#3a3a50",fg:"#5fd7ff"},block:{bg:"#4e4e68",fg:"#5f87ff"},today:{bg:"#262640",fg:"#00d7af"},tmux:{bg:"#1c1c30",fg:"#00d7af"},context:{bg:"#5f5f87",fg:"#d7d7ff"},metrics:{bg:"#5f5faf",fg:"#d7d7ff"},version:{bg:"#444460",fg:"#d787ff"}},$e={directory:{bg:"#5f5faf",fg:"#87afff"},git:{bg:"#303050",fg:"#87ff87"},model:{bg:"#262640",fg:"#ff87ff"},session:{bg:"#444470",fg:"#00d7ff"},block:{bg:"#666680",fg:"#5f87ff"},today:{bg:"#303050",fg:"#00d787"},tmux:{bg:"#262640",fg:"#00d787"},context:{bg:"#808080",fg:"#ffffff"},metrics:{bg:"#8787d7",fg:"#ffffff"},version:{bg:"#585870",fg:"#d787ff"}};var Re={directory:{bg:"#26233a",fg:"#c4a7e7"},git:{bg:"#1f1d2e",fg:"#9ccfd8"},model:{bg:"#191724",fg:"#ebbcba"},session:{bg:"#26233a",fg:"#f6c177"},block:{bg:"#2a273f",fg:"#eb6f92"},today:{bg:"#232136",fg:"#9ccfd8"},tmux:{bg:"#26233a",fg:"#908caa"},context:{bg:"#393552",fg:"#e0def4"},metrics:{bg:"#524f67",fg:"#e0def4"},version:{bg:"#2a273f",fg:"#c4a7e7"}},Be={directory:{bg:"#444444",fg:"#d787d7"},git:{bg:"#262626",fg:"#87d7d7"},model:{bg:"#1c1c1c",fg:"#ffaf87"},session:{bg:"#444444",fg:"#d7af5f"},block:{bg:"#4e4e4e",fg:"#ff5f87"},today:{bg:"#3a3a3a",fg:"#87d7d7"},tmux:{bg:"#444444",fg:"#9e9e9e"},context:{bg:"#585858",fg:"#e4e4e4"},metrics:{bg:"#767676",fg:"#e4e4e4"},version:{bg:"#4e4e4e",fg:"#d787d7"}},De={directory:{bg:"#585858",fg:"#ff87ff"},git:{bg:"#303030",fg:"#00d7d7"},model:{bg:"#262626",fg:"#ffaf87"},session:{bg:"#585858",fg:"#d7af00"},block:{bg:"#666666",fg:"#ff5f87"},today:{bg:"#444444",fg:"#00d7d7"},tmux:{bg:"#585858",fg:"#bcbcbc"},context:{bg:"#808080",fg:"#ffffff"},metrics:{bg:"#a8a8a8",fg:"#000000"},version:{bg:"#666666",fg:"#ff87ff"}};var ce={dark:ye,"dark-ansi256":Ce,"dark-ansi":_e,light:we,"light-ansi256":ke,"light-ansi":Se,nord:Te,"nord-ansi256":xe,"nord-ansi":ve,"tokyo-night":Ee,"tokyo-night-ansi256":Pe,"tokyo-night-ansi":$e,"rose-pine":Re,"rose-pine-ansi256":Be,"rose-pine-ansi":De};function V(o,e){let t=ce[o];if(!t)return null;if(e==="none"||e==="ansi"){let n=ce[`${o}-ansi`];if(n)return n}if(e==="ansi256"){let n=ce[`${o}-ansi256`];if(n)return n}return t}var l=(o,...e)=>{process.env.CLAUDE_POWERLINE_DEBUG&&console.error(`[DEBUG] ${o}`,...e);};var w=promisify(exec),U=class{isGitRepo(e){try{return k.existsSync(_.join(e,".git"))}catch{return false}}async findGitRoot(e){try{return (await w("git rev-parse --show-toplevel",{cwd:e,encoding:"utf8",timeout:2e3})).stdout.trim()||null}catch{return null}}async getGitInfo(e,t={},n){let r;if(n&&this.isGitRepo(n))r=n;else if(this.isGitRepo(e))r=e;else {let s=await this.findGitRoot(e);if(!s)return null;r=s;}try{let s=await this.getStatusWithBranchAsync(r),i=await this.getAheadBehindAsync(r),a={branch:s.branch||"detached",status:s.status,ahead:i.ahead,behind:i.behind};t.showWorkingTree&&s.workingTree&&(a.staged=s.workingTree.staged,a.unstaged=s.workingTree.unstaged,a.untracked=s.workingTree.untracked,a.conflicts=s.workingTree.conflicts);let c={},u={};t.showSha&&(c.sha=this.getShaAsync(r)),t.showTag&&(c.tag=this.getNearestTagAsync(r)),t.showTimeSinceCommit&&(c.timeSinceCommit=this.getTimeSinceLastCommitAsync(r)),t.showStashCount&&(u.stashCount=this.getStashCountAsync(r)),t.showUpstream&&(u.upstream=this.getUpstreamAsync(r)),t.showRepoName&&(u.repoName=this.getRepoNameAsync(r));let g=new Map;for(let[m,f]of Object.entries(c))try{let d=await f;g.set(m,d);}catch{}return Object.keys(u).length>0&&(await Promise.allSettled(Object.entries(u).map(async([f,d])=>({key:f,value:await d})))).forEach(f=>{f.status==="fulfilled"&&g.set(f.value.key,f.value.value);}),t.showSha&&(a.sha=g.get("sha")||void 0),t.showOperation&&(a.operation=this.getOngoingOperation(r)||void 0),t.showTag&&(a.tag=g.get("tag")||void 0),t.showTimeSinceCommit&&(a.timeSinceCommit=g.get("timeSinceCommit")||void 0),t.showStashCount&&(a.stashCount=g.get("stashCount")||0),t.showUpstream&&(a.upstream=g.get("upstream")||void 0),t.showRepoName&&(a.repoName=g.get("repoName")||void 0,a.isWorktree=this.isWorktree(r)),a}catch{return null}}async getShaAsync(e){try{return (await w("git rev-parse --short=7 HEAD",{cwd:e,encoding:"utf8",timeout:2e3})).stdout.trim()||null}catch{return null}}getOngoingOperation(e){try{let t=_.join(e,".git");return k.existsSync(_.join(t,"MERGE_HEAD"))?"MERGE":k.existsSync(_.join(t,"CHERRY_PICK_HEAD"))?"CHERRY-PICK":k.existsSync(_.join(t,"REVERT_HEAD"))?"REVERT":k.existsSync(_.join(t,"BISECT_LOG"))?"BISECT":k.existsSync(_.join(t,"rebase-merge"))||k.existsSync(_.join(t,"rebase-apply"))?"REBASE":null}catch{return null}}async getNearestTagAsync(e){try{return (await w("git describe --tags --abbrev=0",{cwd:e,encoding:"utf8",timeout:2e3})).stdout.trim()||null}catch{return null}}async getTimeSinceLastCommitAsync(e){try{let n=(await w("git log -1 --format=%ct",{cwd:e,encoding:"utf8",timeout:2e3})).stdout.trim();if(!n)return null;let r=parseInt(n)*1e3,s=Date.now();return Math.floor((s-r)/1e3)}catch{return null}}async getStashCountAsync(e){try{let n=(await w("git stash list",{cwd:e,encoding:"utf8",timeout:2e3})).stdout.trim();return n?n.split(`
3
+ `).length:0}catch{return 0}}async getUpstreamAsync(e){try{return (await w("git rev-parse --abbrev-ref @{u}",{cwd:e,encoding:"utf8",timeout:2e3})).stdout.trim()||null}catch{return null}}async getRepoNameAsync(e){try{let n=(await w("git config --get remote.origin.url",{cwd:e,encoding:"utf8",timeout:2e3})).stdout.trim();return n?n.match(/\/([^/]+?)(\.git)?$/)?.[1]||_.basename(e):_.basename(e)}catch{return _.basename(e)}}isWorktree(e){try{let t=_.join(e,".git");return !!(k.existsSync(t)&&k.statSync(t).isFile())}catch{return false}}async getStatusWithBranchAsync(e){try{l(`[GIT-EXEC] Running git status in ${e}`);let r=(await w("git status --porcelain -b",{cwd:e,encoding:"utf8",timeout:2e3})).stdout.split(`
4
+ `),s=null,i="clean",a=0,c=0,u=0,g=0;for(let m of r)if(m){if(m.startsWith("## ")){let d=m.substring(3).split("...")[0];d&&d!=="HEAD (no branch)"&&(s=d);continue}if(m.length>=2){let f=m.charAt(0),d=m.charAt(1);if(f==="?"&&d==="?"){u++,i==="clean"&&(i="dirty");continue}let h=f+d;if(["DD","AU","UD","UA","DU","AA","UU"].includes(h)){g++,i="conflicts";continue}f!==" "&&f!=="?"&&(a++,i==="clean"&&(i="dirty")),d!==" "&&d!=="?"&&(c++,i==="clean"&&(i="dirty"));}}return {branch:s||await this.getFallbackBranch(e),status:i,workingTree:{staged:a,unstaged:c,untracked:u,conflicts:g}}}catch(t){return l(`Git status with branch command failed in ${e}:`,t),{branch:await this.getFallbackBranch(e),status:"clean"}}}async getFallbackBranch(e){try{let n=(await w("git branch --show-current",{cwd:e,encoding:"utf8",timeout:2e3})).stdout.trim();if(n)return n}catch{try{let n=(await w("git symbolic-ref --short HEAD",{cwd:e,encoding:"utf8",timeout:2e3})).stdout.trim();if(n)return n}catch{return null}}return null}async getAheadBehindAsync(e){try{l(`[GIT-EXEC] Running git ahead/behind in ${e}`);let[t,n]=await Promise.all([w("git rev-list --count @{u}..HEAD",{cwd:e,encoding:"utf8",timeout:2e3}),w("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 l(`Git ahead/behind command failed in ${e}:`,t),{ahead:0,behind:0}}}};var Ye=promisify(exec),M=class{async getSessionId(){try{if(!process.env.TMUX_PANE)return l("TMUX_PANE not set, not in tmux session"),null;l(`Getting tmux session ID, TMUX_PANE: ${process.env.TMUX_PANE}`);let t=(await Ye("tmux display-message -p '#S'",{encoding:"utf8",timeout:1e3})).stdout.trim();return l(`Tmux session ID: ${t||"empty"}`),t||null}catch(e){return l("Error getting tmux session ID:",e),null}}isInTmux(){return !!process.env.TMUX_PANE}};function J(){let o=[],e=process.env.CLAUDE_CONFIG_DIR;if(e&&e.split(",").forEach(t=>{let n=t.trim();existsSync(n)&&o.push(n);}),o.length===0){let t=homedir(),n=join(t,".config","claude"),r=join(t,".claude");existsSync(n)?o.push(n):existsSync(r)&&o.push(r);}return o}async function Y(o){let e=[];for(let t of o){let n=join(t,"projects");if(existsSync(n))try{let r=await readdir(n,{withFileTypes:!0});for(let s of r)if(s.isDirectory()){let i=posix.join(n,s.name);e.push(i);}}catch(r){l(`Failed to read projects directory ${n}:`,r);}}return e}async function q(o){let e=J(),t=await Y(e);for(let n of t){let r=posix.join(n,`${o}.jsonl`);if(existsSync(r))return r}return null}async function ge(o){try{return (await stat(o)).mtime}catch{return null}}function Ze(o){let e=o.message?.id||(typeof o.raw.message=="object"&&o.raw.message!==null&&"id"in o.raw.message?o.raw.message.id:void 0),t="requestId"in o.raw?o.raw.requestId:void 0;return !e||!t?null:`${e}:${t}`}var Qe=1024*1024;async function F(o){try{let t=(await stat(o)).size,n;return t>Qe?(l(`Using streaming parser for large file ${o} (${Math.round(t/1024)}KB)`),n=await tt(o)):n=await et(o),l(`Parsed ${n.length} entries from ${o}`),n}catch(e){return l(`Failed to read file ${o}:`,e),[]}}async function et(o){let t=(await readFile(o,"utf-8")).trim().split(`
5
+ `).filter(r=>r.trim()),n=[];for(let r of t)try{let s=JSON.parse(r);if(!s.timestamp)continue;let i={timestamp:new Date(s.timestamp),message:s.message,costUSD:typeof s.costUSD=="number"?s.costUSD:void 0,isSidechain:s.isSidechain===!0,raw:s};n.push(i);}catch(s){l(`Failed to parse JSONL line: ${s}`);continue}return n}async function tt(o){return new Promise((e,t)=>{let n=[],r=createReadStream(o,{encoding:"utf8"}),s=createInterface({input:r,crlfDelay:1/0});s.on("line",i=>{let a=i.trim();if(a)try{let c=JSON.parse(a);if(!c.timestamp)return;let u={timestamp:new Date(c.timestamp),message:c.message,costUSD:typeof c.costUSD=="number"?c.costUSD:void 0,isSidechain:c.isSidechain===!0,raw:c};n.push(u);}catch(c){l(`Failed to parse JSONL line: ${c}`);}}),s.on("close",()=>{e(n);}),s.on("error",i=>{l(`Streaming parser error for ${o}:`,i),t(i);}),r.on("error",i=>{l(`File stream error for ${o}:`,i),t(i);});})}async function z(o,e,t=false){let n=J(),r=await Y(n),s=new Set,i=r.map(async h=>{try{let D=(await readdir(h)).filter(C=>C.endsWith(".jsonl")).map(async C=>{let oe=posix.join(h,C);if(existsSync(oe)){let je=await ge(oe);return {filePath:oe,mtime:je}}return null});return (await Promise.all(D)).filter(C=>C?.mtime&&(!e||e(C.filePath,C.mtime)))}catch(b){return l(`Failed to read project directory ${h}:`,b),[]}}),c=(await Promise.all(i)).flat().filter(h=>h!==null);t&&c.sort((h,b)=>b.mtime.getTime()-h.mtime.getTime());let u=c.map(h=>h.filePath),g=[],m=u.map(async h=>(await F(h)).filter(T=>!o||o(T))),f=await Promise.all(m);for(let h of f)g.push(...h);g.sort((h,b)=>h.timestamp.getTime()-b.timestamp.getTime());let d=[];for(let h of g){let b=Ze(h);b&&s.has(b)||(b&&s.add(b),d.push(h));}return d}var $=class{static CACHE_DIR=_.join(homedir(),".claude","powerline");static USAGE_CACHE_DIR=_.join(this.CACHE_DIR,"usage");static LOCKS_DIR=_.join(this.CACHE_DIR,"locks");static isLocked(e){let t=_.join(this.LOCKS_DIR,e);if(!k.existsSync(t))return false;try{let n=k.readFileSync(t,"utf-8"),r=parseInt(n.trim(),10);if(isNaN(r))return l(`Invalid PID in lock file ${e}, removing stale lock`),k.unlinkSync(t),!1;try{return process.kill(r,0),!0}catch(s){return s.code==="ESRCH"?(l(`Removing stale lock file ${e} for dead process ${r}`),k.unlinkSync(t),!1):(l(`Error checking process ${r} for lock ${e}:`,s),!0)}}catch(n){return l(`Error reading lock file ${e}:`,n),true}}static async acquireLock(e,t=5e3){await this.ensureCacheDirectories();let s=_.join(this.LOCKS_DIR,e),i=Date.now(),a=String(process.pid);for(;Date.now()-i<t;)try{return await k.promises.writeFile(s,a,{flag:"wx"}),l(`Lock acquired for ${e}`),!0}catch(c){if(c.code==="EEXIST")await setTimeout(50);else throw c}return l(`Failed to acquire lock for ${e} within ${t}ms`),false}static async releaseLock(e){let t=_.join(this.LOCKS_DIR,e);try{await k.promises.unlink(t),l(`Lock released for ${e}`);}catch(n){n.code!=="ENOENT"&&l(`Error releasing lock for ${e}:`,n);}}static async ensureCacheDirectories(){try{await Promise.all([k.promises.mkdir(this.CACHE_DIR,{recursive:!0}),k.promises.mkdir(this.USAGE_CACHE_DIR,{recursive:!0}),k.promises.mkdir(this.LOCKS_DIR,{recursive:!0})]);}catch(e){l("Failed to create cache directories:",e);}}static createProjectHash(e){return createHash("md5").update(e).digest("hex").substring(0,8)}static async getUsageCache(e,t){let s="utf-8";await this.ensureCacheDirectories();let i=_.join(this.USAGE_CACHE_DIR,`${e}.json`),a=`${e}.usage.lock`;for(let c=0;c<3;c++){if(this.isLocked(a)){l(`Cache for ${e} is locked, waiting...`),await setTimeout(75);continue}try{let g=await k.promises.readFile(i,s),m=JSON.parse(g);return !t||m.timestamp>=t?(l(`[CACHE-HIT] ${e} disk cache: found`),this.deserializeDates(m.data)):(l(`${e} cache outdated: cache=${m.timestamp}, latest=${t}`),null)}catch(g){if(g.code==="ENOENT")return l(`No shared ${e} usage cache found`),null;let m=c+1;l(`Attempt ${m} failed to read ${e} cache: ${g.message}. Retrying...`),await setTimeout(75);}}return l(`Failed to read ${e} cache after 3 attempts.`),null}static deserializeDates(e){return Array.isArray(e)?e.map(t=>({...t,timestamp:new Date(t.timestamp)})):e}static async setUsageCache(e,t,n){let r=`${e}.usage.lock`;if(!await this.acquireLock(r)){l(`Could not acquire lock to set usage cache for ${e}`);return}try{await this.ensureCacheDirectories();let i=_.join(this.USAGE_CACHE_DIR,`${e}.json`),a=n||Date.now(),u=JSON.stringify({data:t,timestamp:a});await k.promises.writeFile(i,u,"utf-8"),l(`[CACHE-SET] ${e} disk cache stored`);}catch(i){l(`Failed to save ${e} usage cache:`,i);}finally{await this.releaseLock(r);}}static async getLatestTranscriptMtime(){try{let e=J(),t=await Y(e),n=0;for(let r of t)try{let i=(await k.promises.readdir(r)).filter(a=>a.endsWith(".jsonl"));for(let a of i){let c=_.join(r,a),u=await ge(c);u&&u.getTime()>n&&(n=u.getTime());}}catch(s){l(`Failed to read project directory ${r}:`,s);continue}return n}catch(e){return l("Failed to get latest transcript mtime:",e),Date.now()}}};var X={"claude-3-haiku-20240307":{name:"Claude 3 Haiku",input:.25,output:1.25,cache_write_5m:.3,cache_write_1h:.5,cache_read:.03},"claude-3-5-haiku-20241022":{name:"Claude 3.5 Haiku",input:.8,output:4,cache_write_5m:1,cache_write_1h:1.6,cache_read:.08},"claude-3-5-haiku-latest":{name:"Claude 3.5 Haiku Latest",input:1,output:5,cache_write_5m:1.25,cache_write_1h:2,cache_read:.1},"claude-3-opus-latest":{name:"Claude 3 Opus Latest",input:15,output:75,cache_write_5m:18.75,cache_write_1h:30,cache_read:1.5},"claude-3-opus-20240229":{name:"Claude 3 Opus",input:15,output:75,cache_write_5m:18.75,cache_write_1h:30,cache_read:1.5},"claude-3-5-sonnet-latest":{name:"Claude 3.5 Sonnet Latest",input:3,output:15,cache_write_5m:3.75,cache_write_1h:6,cache_read:.3},"claude-3-5-sonnet-20240620":{name:"Claude 3.5 Sonnet",input:3,output:15,cache_write_5m:3.75,cache_write_1h:6,cache_read:.3},"claude-3-5-sonnet-20241022":{name:"Claude 3.5 Sonnet",input:3,output:15,cache_write_5m:3.75,cache_write_1h:6,cache_read:.3},"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-3-7-sonnet-latest":{name:"Claude 3.7 Sonnet Latest",input:3,output:15,cache_write_5m:3.75,cache_write_1h:6,cache_read:.3},"claude-3-7-sonnet-20250219":{name:"Claude 3.7 Sonnet",input:3,output:15,cache_write_5m:3.75,cache_write_1h:6,cache_read:.3}},R=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 t=Date.now()-864e5;return await $.getUsageCache("pricing",t)}static async saveDiskCache(e){await $.setUsageCache("pricing",e);}static async fetchPricingData(){return new Promise(e=>{let t=new URL(this.GITHUB_PRICING_URL),n=get({hostname:t.hostname,path:t.pathname,headers:{"User-Agent":"claude-powerline","Cache-Control":"no-cache"},timeout:5e3},r=>{if(r.statusCode!==200){l(`HTTP ${r.statusCode}: ${r.statusMessage}`),e(null);return}let s="",i=0,a=1024*1024;r.on("data",c=>{if(i+=c.length,i>a){l("Response too large"),n.destroy(),e(null);return}s+=c;}),r.on("end",()=>{try{let u=JSON.parse(s),g=u._meta,m={};for(let[f,d]of Object.entries(u))f!=="_meta"&&(m[f]=d);this.validatePricingData(m)?(l(`Fetched fresh pricing from GitHub for ${Object.keys(m).length} models`),l(`Pricing last updated: ${g?.updated||"unknown"}`),e(m)):(l("Invalid pricing data structure"),e(null));}catch(c){l("Failed to parse JSON:",c),e(null);}}),r.on("error",c=>{l("Response error:",c),e(null);});});n.on("error",r=>{l("Request error:",r),e(null);}),n.on("timeout",()=>{l("Request timeout"),n.destroy(),e(null);}),n.end();})}static async getCurrentPricing(){if(this.executionCache!==null)return l(`[CACHE-HIT] Pricing execution cache: ${Object.keys(this.executionCache).length} models`),this.executionCache;let e=await this.loadDiskCache();if(e)return l(`[CACHE-HIT] Pricing disk cache: ${Object.keys(e).length} models`),this.executionCache=e,l(`[CACHE-SET] Pricing execution cache stored: ${Object.keys(e).length} models`),e;let t=await this.fetchPricingData();return t?(await this.saveDiskCache(t),l(`[CACHE-SET] Pricing disk cache stored: ${Object.keys(t).length} models`),this.executionCache=t,l(`[CACHE-SET] Pricing execution cache stored: ${Object.keys(t).length} models`),t):(l(`[CACHE-FALLBACK] Using offline pricing data: ${Object.keys(X).length} models`),this.executionCache=X,l(`[CACHE-SET] Pricing execution cache stored: ${Object.keys(X).length} models`),X)}static validatePricingData(e){if(!e||typeof e!="object")return false;for(let[,t]of Object.entries(e)){if(!t||typeof t!="object")return false;let n=t;if(typeof n.input!="number"||typeof n.output!="number"||typeof n.cache_read!="number")return false}return true}static async getModelPricing(e){if(this.modelPricingCache.has(e))return l(`[CACHE-HIT] Model pricing cache: ${e}`),this.modelPricingCache.get(e);let t=await this.getCurrentPricing(),n;return t[e]?n=t[e]:n=this.fuzzyMatchModel(e,t),this.modelPricingCache.set(e,n),l(`[CACHE-SET] Model pricing cache: ${e}`),n}static fuzzyMatchModel(e,t){let n=e.toLowerCase();for(let[s,i]of Object.entries(t))if(s.toLowerCase()===n)return i;let r=[{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","claude-sonnet-4"],fallback:"claude-sonnet-4-20250514"},{pattern:["sonnet-3.7","3-7-sonnet"],fallback:"claude-3-7-sonnet-20250219"},{pattern:["3-5-sonnet","sonnet-3.5"],fallback:"claude-3-5-sonnet-20241022"},{pattern:["3-5-haiku","haiku-3.5"],fallback:"claude-3-5-haiku-20241022"},{pattern:["haiku","3-haiku"],fallback:"claude-3-haiku-20240307"},{pattern:["opus"],fallback:"claude-opus-4-20250514"},{pattern:["sonnet"],fallback:"claude-3-5-sonnet-20241022"}];for(let{pattern:s,fallback:i}of r)if(s.some(a=>n.includes(a))&&t[i])return t[i];return t["claude-3-5-sonnet-20241022"]||{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 n=e.message?.usage;if(!n)return 0;let r=this.extractModelId(e),s=await this.getModelPricing(r),i=n.input_tokens||0,a=n.output_tokens||0,c=n.cache_creation_input_tokens||0,u=n.cache_read_input_tokens||0,g=i/1e6*s.input,m=a/1e6*s.output,f=u/1e6*s.cache_read,d=c/1e6*s.cache_write_5m;return g+m+d+f}static extractModelId(e){if(e.model&&typeof e.model=="string")return e.model;let t=e.message;if(t?.model){let n=t.model;return typeof n=="string"?n:n?.id||"claude-3-5-sonnet-20241022"}return e.model_id&&typeof e.model_id=="string"?e.model_id:"claude-3-5-sonnet-20241022"}};function it(o){return {timestamp:o.timestamp.toISOString(),message:{usage:{input_tokens:o.message?.usage?.input_tokens||0,output_tokens:o.message?.usage?.output_tokens||0,cache_creation_input_tokens:o.message?.usage?.cache_creation_input_tokens,cache_read_input_tokens:o.message?.usage?.cache_read_input_tokens}},costUSD:o.costUSD}}var K=class{async getSessionUsage(e){try{let t=await q(e);if(!t)return l(`No transcript found for session: ${e}`),null;l(`Found transcript at: ${t}`);let n=await F(t);if(n.length===0)return {totalCost:0,entries:[]};let r=[],s=0;for(let i of n)if(i.message?.usage){let a=it(i);if(a.costUSD!==void 0)s+=a.costUSD;else {let c=await R.calculateCostForEntry(i.raw);a.costUSD=c,s+=c;}r.push(a);}return l(`Parsed ${r.length} usage entries, total cost: $${s.toFixed(4)}`),{totalCost:s,entries:r}}catch(t){return l(`Error reading session usage for ${e}:`,t),null}}calculateTokenBreakdown(e){return e.reduce((t,n)=>({input:t.input+(n.message.usage.input_tokens||0),output:t.output+(n.message.usage.output_tokens||0),cacheCreation:t.cacheCreation+(n.message.usage.cache_creation_input_tokens||0),cacheRead:t.cacheRead+(n.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),s=r.input+r.output+r.cacheCreation+r.cacheRead,i=n.totalCost,a=t?.cost?.total_cost_usd??null;return {cost:i??a,calculatedCost:i,officialCost:a,tokens:s,tokenBreakdown:r}}},L=class{sessionProvider=new K;async getUsageInfo(e,t){try{return l(`Starting usage info retrieval for session: ${e}`),{session:await this.sessionProvider.getSessionInfo(e,t)}}catch(n){return l(`Error getting usage info for session ${e}:`,n),{session:{cost:null,calculatedCost:null,officialCost:null,tokens:null,tokenBreakdown:null}}}}};var O=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},n=this.getModelType(e);return t[n]||t.default||2e5}getModelType(e){let t=e.toLowerCase();return t.includes("sonnet")?"sonnet":t.includes("opus")?"opus":"default"}async calculateContextTokens(e,t){try{l(`Calculating context tokens from transcript: ${e}`);try{if(!readFileSync(e,"utf-8"))return l("Transcript file is empty"),null}catch{return l("Could not read transcript file"),null}let n=await F(e);if(n.length===0)return l("No entries in transcript"),null;let r=null;for(let s=n.length-1;s>=0;s--){let i=n[s];if(i&&i.message?.usage?.input_tokens&&i.isSidechain!==!0){r=i,l(`Context segment: Found most recent entry at ${i.timestamp.toISOString()}, stopping search`);break}}if(r?.message?.usage){let s=r.message.usage,i=(s.input_tokens||0)+(s.cache_read_input_tokens||0)+(s.cache_creation_input_tokens||0),a=t?this.getContextLimit(t):2e5;l(`Most recent main chain context: ${i} tokens (limit: ${a})`);let c=Math.min(100,Math.max(0,Math.round(i/a*100))),u=Math.round(a*.75),g=Math.min(100,Math.max(0,Math.round(i/u*100))),m=Math.max(0,100-g);return {inputTokens:i,percentage:c,usablePercentage:g,contextLeftPercentage:m,maxTokens:a,usableTokens:u}}return l("No main chain entries with usage data found"),null}catch(n){return l(`Error reading transcript: ${n instanceof Error?n.message:String(n)}`),null}}};var I=class{async loadTranscriptEntries(e){try{let t=await q(e);if(!t)return l(`No transcript found for session: ${e}`),[];l(`Loading transcript from: ${t}`);let r=(await readFile(t,"utf-8")).trim().split(`
6
+ `).filter(i=>i.trim()),s=[];for(let i of r)try{let a=JSON.parse(i);if(a.isSidechain===!0)continue;s.push(a);}catch(a){l(`Failed to parse JSONL line: ${a}`);continue}return l(`Loaded ${s.length} transcript entries`),s}catch(t){return l(`Error loading transcript for ${e}:`,t),[]}}calculateMessageCount(e){return e.filter(t=>{let n=t.type||t.message?.role||t.message?.type,r=t.type==="user"&&t.message?.content?.[0]?.type==="tool_result";return n==="user"&&!r}).length}calculateLastResponseTime(e){if(e.length===0)return null;let t=e.slice(-20),n=null,r=null;for(let s of t)if(s.timestamp)try{let i=new Date(s.timestamp),a=s.type||s.message?.role||s.message?.type,c=s.type==="user"&&s.message?.content?.[0]?.type==="tool_result";if(a==="user"&&!c)n=i;else if(a==="assistant"&&n){let g=(i.getTime()-n.getTime())/1e3;g>.1&&g<300&&(r=g);}}catch{continue}return r}async getMetricsInfo(e,t){try{if(l(`Getting metrics from hook data for session: ${e}`),!t.cost)return l("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),s=this.calculateLastResponseTime(n);return {responseTime:t.cost.total_api_duration_ms/1e3,lastResponseTime:s,sessionDuration:t.cost.total_duration_ms/1e3,messageCount:r,linesAdded:t.cost.total_lines_added,linesRemoved:t.cost.total_lines_removed}}catch(n){return l(`Error getting metrics from hook data for session ${e}:`,n),{responseTime:null,lastResponseTime:null,sessionDuration:null,messageCount:null,linesAdded:null,linesRemoved:null}}}};function x(o){return o===null?"$0.00":o<.01?"<$0.01":`$${o.toFixed(2)}`}function y(o){return o===null||o===0?"0 tokens":o>=1e6?`${(o/1e6).toFixed(1)}M tokens`:o>=1e3?`${(o/1e3).toFixed(1)}K tokens`:`${o} tokens`}function me(o){if(!o)return "0 tokens";let e=[];if(o.input>0&&e.push(`${y(o.input).replace(" tokens","")}in`),o.output>0&&e.push(`${y(o.output).replace(" tokens","")}out`),o.cacheCreation>0||o.cacheRead>0){let t=o.cacheCreation+o.cacheRead;e.push(`${y(t).replace(" tokens","")}cached`);}return e.length>0?e.join(" + "):"0 tokens"}function Me(o){return o<60?`${o}s`:o<3600?`${Math.floor(o/60)}m`:o<86400?`${Math.floor(o/3600)}h`:o<604800?`${Math.floor(o/86400)}d`:`${Math.floor(o/604800)}w`}function Fe(o){return o<60?`${o.toFixed(0)}s`:o<3600?`${(o/60).toFixed(0)}m`:o<86400?`${(o/3600).toFixed(1)}h`:`${(o/86400).toFixed(1)}d`}function lt(o,e){return !e||e<=0||o<0?null:Math.min(100,o/e*100)}function de(o,e,t=80){let n=lt(o,e);if(n===null)return {percentage:null,isWarning:false,displayText:""};let r=`${n.toFixed(0)}%`,s=n>=t,i="";return s?i=` !${r}`:n>=50?i=` +${r}`:i=` ${r}`,{percentage:n,isWarning:s,displayText:i}}var N=class{constructor(e,t){this.config=e;this.symbols=t;}renderDirectory(e,t,n){let r=e.workspace?.current_dir||e.cwd||"/",s=e.workspace?.project_dir;if(n?.showBasename)return {text:_.basename(r)||"root",bgColor:t.modeBg,fgColor:t.modeFg};let i=process.env.HOME||process.env.USERPROFILE,a=r,c=s;return i&&(r.startsWith(i)&&(a=r.replace(i,"~")),s&&s.startsWith(i)&&(c=s.replace(i,"~"))),{text:this.getDisplayDirectoryName(a,c),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!==false&&(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 i=[];e.staged&&e.staged>0&&i.push(`+${e.staged}`),e.unstaged&&e.unstaged>0&&i.push(`~${e.unstaged}`),e.untracked&&e.untracked>0&&i.push(`?${e.untracked}`),e.conflicts&&e.conflicts>0&&i.push(`!${e.conflicts}`),i.length>0&&r.push(`(${i.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 i=Me(e.timeSinceCommit);r.push(`${this.symbols.git_time} ${i}`);}let s=this.symbols.git_clean;return e.status==="conflicts"?s=this.symbols.git_conflicts:e.status==="dirty"&&(s=this.symbols.git_dirty),r.push(s),{text:r.join(" "),bgColor:t.gitBg,fgColor:t.gitFg}}renderModel(e,t){let n=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",s=n?.costSource,i=this.config.budget?.session,a=s?this.formatSessionUsageDisplay(e.session,r,s):this.formatUsageWithBudget(e.session.cost,e.session.tokens,e.session.tokenBreakdown,r,i?.amount,i?.warningThreshold||80,i?.type);return {text:`${this.symbols.session_cost} ${a}`,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){if(!e)return {text:`${this.symbols.context_time} 0 (100%)`,bgColor:t.contextBg,fgColor:t.contextFg};let r=`${e.contextLeftPercentage}%`;return {text:n?.showPercentageOnly?`${this.symbols.context_time} ${r}`:`${this.symbols.context_time} ${e.inputTokens.toLocaleString()} (${r})`,bgColor:t.contextBg,fgColor:t.contextFg}}renderMetrics(e,t,n,r){if(!e)return {text:`${this.symbols.metrics_response} new`,bgColor:t.metricsBg,fgColor:t.metricsFg};let s=[];if(r?.showLastResponseTime&&e.lastResponseTime!==null){let i=e.lastResponseTime<60?`${e.lastResponseTime.toFixed(1)}s`:`${(e.lastResponseTime/60).toFixed(1)}m`;s.push(`${this.symbols.metrics_last_response} ${i}`);}if(r?.showResponseTime!==false&&e.responseTime!==null){let i=e.responseTime<60?`${e.responseTime.toFixed(1)}s`:`${(e.responseTime/60).toFixed(1)}m`;s.push(`${this.symbols.metrics_response} ${i}`);}if(r?.showDuration!==false&&e.sessionDuration!==null){let i=Fe(e.sessionDuration);s.push(`${this.symbols.metrics_duration} ${i}`);}return r?.showMessageCount!==false&&e.messageCount!==null&&s.push(`${this.symbols.metrics_messages} ${e.messageCount}`),r?.showLinesAdded!==false&&e.linesAdded!==null&&e.linesAdded>0&&s.push(`${this.symbols.metrics_lines_added} ${e.linesAdded}`),r?.showLinesRemoved!==false&&e.linesRemoved!==null&&e.linesRemoved>0&&s.push(`${this.symbols.metrics_lines_removed} ${e.linesRemoved}`),s.length===0?{text:`${this.symbols.metrics_response} active`,bgColor:t.metricsBg,fgColor:t.metricsFg}:{text:s.join(" "),bgColor:t.metricsBg,fgColor:t.metricsFg}}renderBlock(e,t,n){let r;if(e.cost===null&&e.tokens===null)r="No active block";else {let s=n?.type||"cost",i=n?.burnType,a=this.config.budget?.block,c=e.timeRemaining!==null?(()=>{let m=Math.floor(e.timeRemaining/60),f=e.timeRemaining%60;return m>0?`${m}h ${f}m`:`${f}m`})():null,u;switch(s){case "cost":a?.amount&&a?.type==="cost"?u=this.formatUsageWithBudget(e.cost,null,null,"cost",a.amount,a.warningThreshold,a.type):u=x(e.cost);break;case "tokens":a?.amount&&a?.type==="tokens"?u=this.formatUsageWithBudget(null,e.tokens,null,"tokens",a.amount,a.warningThreshold,a.type):u=y(e.tokens);break;case "weighted":let m=a?.type==="tokens"?a.amount:void 0,f=y(e.weightedTokens);if(m&&e.weightedTokens!==null){let d=de(e.weightedTokens,m,a?.warningThreshold||80);u=`${f}${d.displayText}`;}else u=`${f} (weighted)`;break;case "both":a?.amount?u=this.formatUsageWithBudget(e.cost,e.tokens,null,"both",a.amount,a.warningThreshold,a.type):u=`${x(e.cost)} / ${y(e.tokens)}`;break;case "time":u=c||"N/A";break;default:a?.amount&&a?.type==="cost"?u=this.formatUsageWithBudget(e.cost,null,null,"cost",a.amount,a.warningThreshold,a.type):u=x(e.cost);}let g="";if(i&&i!=="none")switch(i){case "cost":g=` | ${e.burnRate!==null?e.burnRate<1?`${(e.burnRate*100).toFixed(0)}\xA2/h`:`$${e.burnRate.toFixed(2)}/h`:"N/A"}`;break;case "tokens":g=` | ${e.tokenBurnRate!==null?`${y(Math.round(e.tokenBurnRate))}/h`:"N/A"}`;break;case "both":let d=e.burnRate!==null?e.burnRate<1?`${(e.burnRate*100).toFixed(0)}\xA2/h`:`$${e.burnRate.toFixed(2)}/h`:"N/A",h=e.tokenBurnRate!==null?`${y(Math.round(e.tokenBurnRate))}/h`:"N/A";g=` | ${d} / ${h}`;break}s==="time"?r=u:r=c?`${u}${g} (${c} left)`:`${u}${g}`;}return {text:`${this.symbols.block_cost} ${r}`,bgColor:t.blockBg,fgColor:t.blockFg}}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)||_.basename(t)||"project":_.basename(e)||"root":_.basename(e)||"root"}formatUsageDisplay(e,t,n,r){switch(r){case "cost":return x(e);case "tokens":return y(t);case "both":return `${x(e)} (${y(t)})`;case "breakdown":return me(n);default:return x(e)}}formatSessionUsageDisplay(e,t,n){let r=()=>n==="calculated"?e.calculatedCost:n==="official"?e.officialCost:e.cost;switch(t){case "cost":return x(r());case "tokens":return y(e.tokens);case "both":return `${x(r())} (${y(e.tokens)})`;case "breakdown":return me(e.tokenBreakdown);default:return x(r())}}formatUsageWithBudget(e,t,n,r,s,i=80,a){let c=this.formatUsageDisplay(e,t,n,r);if(s&&s>0){let u=null;if(a==="tokens"&&t!==null?u=t:(a==="cost"&&e!==null||!a&&e!==null)&&(u=e),u!==null){let g=de(u,s,i);return c+g.displayText}}return c}renderVersion(e,t,n){return e.version?{text:`${this.symbols.version} v${e.version}`,bgColor:t.versionBg,fgColor:t.versionFg}:null}};function ut(o){return o.includes("opus")?5:(o.includes("sonnet")||o.includes("haiku"),1)}function gt(o){return {timestamp:o.timestamp,usage:{inputTokens:o.message?.usage?.input_tokens||0,outputTokens:o.message?.usage?.output_tokens||0,cacheCreationInputTokens:o.message?.usage?.cache_creation_input_tokens||0,cacheReadInputTokens:o.message?.usage?.cache_read_input_tokens||0},costUSD:o.costUSD||0,model:o.message?.model||"unknown"}}var Q=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((a,c)=>a.timestamp.getTime()-c.timestamp.getTime()),s=null,i=[];for(let a of r){let c=a.timestamp;if(s==null)s=this.floorToHour(c),i=[a];else {let u=c.getTime()-s.getTime(),g=i[i.length-1];if(g==null)continue;let m=g.timestamp,f=c.getTime()-m.getTime();u>t||f>t?(n.push(i),s=this.floorToHour(c),i=[a]):i.push(a);}}return s!=null&&i.length>0&&n.push(i),n}createBlockInfo(e,t){let n=new Date,r=this.sessionDurationHours*60*60*1e3,s=new Date(e.getTime()+r),i=t[t.length-1],a=i!=null?i.timestamp:e,c=n.getTime()-a.getTime()<r&&n<s;return {block:t,isActive:c}}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 s=this.floorToHour(r.timestamp),i=this.createBlockInfo(s,n);if(i.isActive)return i.block}return null}async loadUsageEntries(){try{l("Block segment: Loading entries for dynamic session blocks");let e=new Date;e.setDate(e.getDate()-1);let n=await z(void 0,(c,u)=>u>=e,!0),r=[];for(let c of n)if(c.message?.usage){let u=gt(c);!u.costUSD&&c.raw&&(u.costUSD=await R.calculateCostForEntry(c.raw)),r.push(u);}let s=this.identifySessionBlocks(r);l(`Block segment: Found ${s.length} session blocks`);let i=this.findActiveBlock(s),a=[];if(i&&i.length>0){l(`Block segment: Found active block with ${i.length} entries`);let c=i[0],u=i[i.length-1];c&&u&&l(`Block segment: Active block from ${c.timestamp.toISOString()} to ${u.timestamp.toISOString()}`),a=i;}else l("Block segment: No active block found"),a=[];return a}catch(e){return l("Error loading block entries:",e),[]}}async getActiveBlockInfo(){try{let e=await this.loadUsageEntries();if(e.length===0)return l("Block segment: No entries in current block"),{cost:null,tokens:null,weightedTokens:null,timeRemaining:null,burnRate:null,tokenBurnRate:null};let t=e.reduce((u,g)=>u+g.costUSD,0),n=e.reduce((u,g)=>u+g.usage.inputTokens+g.usage.outputTokens+g.usage.cacheCreationInputTokens+g.usage.cacheReadInputTokens,0),r=e.reduce((u,g)=>{let m=g.usage.inputTokens+g.usage.outputTokens+g.usage.cacheCreationInputTokens+g.usage.cacheReadInputTokens,f=ut(g.model);return u+m*f},0),s=new Date,i=null;if(e.length>0){let u=e[0];if(u){let g=this.sessionDurationHours*60*60*1e3,m=this.floorToHour(u.timestamp),f=new Date(m.getTime()+g);i=Math.max(0,Math.round((f.getTime()-s.getTime())/(1e3*60)));}}let a=null,c=null;if(e.length>=1&&(t>0||n>0)){let u=e.map(f=>f.timestamp).sort((f,d)=>f.getTime()-d.getTime()),g=u[0],m=u[u.length-1];if(g&&m){let f=(m.getTime()-g.getTime())/6e4;f>0&&(t>0&&(a=t/f*60),n>0&&(c=n/f*60));}}return l(`Block segment: $${t.toFixed(2)}, ${n} tokens, ${i}m remaining, burn rate: ${a?"$"+a.toFixed(2)+"/hr":"N/A"}`),{cost:t,tokens:n,weightedTokens:r,timeRemaining:i,burnRate:a,tokenBurnRate:c}}catch(e){return l("Error getting active block info:",e),{cost:null,tokens:null,weightedTokens:null,timeRemaining:null,burnRate:null,tokenBurnRate:null}}}};function j(o){let e=o.getFullYear(),t=String(o.getMonth()+1).padStart(2,"0"),n=String(o.getDate()).padStart(2,"0");return `${e}-${t}-${n}`}function ft(o){return o.inputTokens+o.outputTokens+o.cacheCreationInputTokens+o.cacheReadInputTokens}function mt(o){return {timestamp:o.timestamp,usage:{inputTokens:o.message?.usage?.input_tokens||0,outputTokens:o.message?.usage?.output_tokens||0,cacheCreationInputTokens:o.message?.usage?.cache_creation_input_tokens||0,cacheReadInputTokens:o.message?.usage?.cache_read_input_tokens||0},costUSD:o.costUSD||0,model:o.message?.model||"unknown"}}var ee=class{async loadTodayEntries(){let t=j(new Date);l(`Today segment: Loading entries for date ${t}`);let n=await $.getLatestTranscriptMtime(),r=await $.getUsageCache("today",n);if(r)return l("Using shared today usage cache"),r;let s=new Date;s.setDate(s.getDate()-1),s.setHours(0,0,0,0);let i=(f,d)=>d>=s,a=new Date;a.setHours(0,0,0,0);let u=await z(f=>f.timestamp>=a,i,true),g=[],m=0;for(let f of u)if(j(f.timestamp)===t&&f.message?.usage){let h=mt(f);!h.costUSD&&f.raw&&(h.costUSD=await R.calculateCostForEntry(f.raw)),g.push(h),m++;}return l(`Today segment: Found ${m} entries for today (${t})`),await $.setUsageCache("today",g,n),g}async getTodayEntries(){try{return await this.loadTodayEntries()}catch(e){return l("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:j(new Date)};let t=e.reduce((s,i)=>s+i.costUSD,0),n=e.reduce((s,i)=>s+ft(i.usage),0),r=e.reduce((s,i)=>({input:s.input+i.usage.inputTokens,output:s.output+i.usage.outputTokens,cacheCreation:s.cacheCreation+i.usage.cacheCreationInputTokens,cacheRead:s.cacheRead+i.usage.cacheReadInputTokens}),{input:0,output:0,cacheCreation:0,cacheRead:0});return l(`Today segment: $${t.toFixed(2)}, ${n} tokens total`),{cost:t,tokens:n,tokenBreakdown:r,date:j(new Date)}}catch(e){return l("Error getting today's info:",e),{cost:null,tokens:null,tokenBreakdown:null,date:j(new Date)}}}};var B="\x1B[0m",p={right:"\uE0B0",left_rounded:"\uE0B6",right_rounded:"\uE0B4",branch:"\u2387",model:"\u2731",git_clean:"\u2713",git_dirty:"\u25CF",git_conflicts:"\u26A0",git_ahead:"\u2191",git_behind:"\u2193",git_worktree:"\u29C9",git_tag:"\u2302",git_sha:"\u266F",git_upstream:"\u2192",git_stash:"\u29C7",git_time:"\u25F7",session_cost:"\xA7",block_cost:"\u25F1",today_cost:"\u2609",context_time:"\u25D4",metrics_response:"\u29D6",metrics_last_response:"\u0394",metrics_duration:"\u29D7",metrics_messages:"\u27D0",metrics_lines_added:"+",metrics_lines_removed:"-",metrics_burn:"\u27E2",version:"\u25C8"};var te=class{constructor(e){this.config=e;this.symbols=this.initializeSymbols();}symbols;_usageProvider;_blockProvider;_todayProvider;_contextProvider;_gitService;_tmuxService;_metricsProvider;_segmentRenderer;get usageProvider(){return this._usageProvider||(this._usageProvider=new L),this._usageProvider}get blockProvider(){return this._blockProvider||(this._blockProvider=new Q),this._blockProvider}get todayProvider(){return this._todayProvider||(this._todayProvider=new ee),this._todayProvider}get contextProvider(){return this._contextProvider||(this._contextProvider=new O(this.config)),this._contextProvider}get gitService(){return this._gitService||(this._gitService=new U),this._gitService}get tmuxService(){return this._tmuxService||(this._tmuxService=new M),this._tmuxService}get metricsProvider(){return this._metricsProvider||(this._metricsProvider=new I),this._metricsProvider}get segmentRenderer(){return this._segmentRenderer||(this._segmentRenderer=new N(this.config,this.symbols)),this._segmentRenderer}needsSegmentInfo(e){return this.config.display.lines.some(t=>t.segments[e]?.enabled)}async generateStatusline(e){let t=this.needsSegmentInfo("session")?await this.usageProvider.getUsageInfo(e.session_id,e):null,n=this.needsSegmentInfo("block")?await this.blockProvider.getActiveBlockInfo():null,r=this.needsSegmentInfo("today")?await this.todayProvider.getTodayInfo():null,s=this.needsSegmentInfo("context")?await this.contextProvider.calculateContextTokens(e.transcript_path,e.model?.id):null,i=this.needsSegmentInfo("metrics")?await this.metricsProvider.getMetricsInfo(e.session_id,e):null;return (await Promise.all(this.config.display.lines.map(c=>this.renderLine(c,e,t,n,r,s,i)))).filter(c=>c.length>0).join(`
7
+ `)}async renderLine(e,t,n,r,s,i,a){let c=this.getThemeColors(),u=t.workspace?.current_dir||t.cwd||"/",g=Object.entries(e.segments).filter(([d,h])=>h?.enabled).map(([d,h])=>({type:d,config:h})),m=this.config.display.style==="capsule",f=c.reset;for(let d=0;d<g.length;d++){let h=g[d];if(!h)continue;let b=d===0,T=d===g.length-1,D=T?null:g[d+1],v=D?this.getSegmentBgColor(D.type,c):"",C=await this.renderSegment(h,t,n,r,s,i,a,c,u);C&&(m&&!b&&(f+=" "),f+=this.formatSegment(C.bgColor,C.fgColor,C.text,T?void 0:v));}return f}async renderSegment(e,t,n,r,s,i,a,c,u){return e.type==="directory"?this.segmentRenderer.renderDirectory(t,c,e.config):e.type==="model"?this.segmentRenderer.renderModel(t,c):e.type==="git"?await this.renderGitSegment(e.config,t,c,u):e.type==="session"?this.renderSessionSegment(e.config,n,c):e.type==="tmux"?await this.renderTmuxSegment(c):e.type==="context"?this.renderContextSegment(e.config,i,c):e.type==="metrics"?this.renderMetricsSegment(e.config,a,r,c):e.type==="block"?this.renderBlockSegment(e.config,r,c):e.type==="today"?this.renderTodaySegment(e.config,s,c):e.type==="version"?this.renderVersionSegment(e.config,t,c):null}async renderGitSegment(e,t,n,r){if(!this.needsSegmentInfo("git"))return null;let s=await this.gitService.getGitInfo(r,{showSha:e?.showSha,showWorkingTree:e?.showWorkingTree,showOperation:e?.showOperation,showTag:e?.showTag,showTimeSinceCommit:e?.showTimeSinceCommit,showStashCount:e?.showStashCount,showUpstream:e?.showUpstream,showRepoName:e?.showRepoName},t.workspace?.project_dir);return s?this.segmentRenderer.renderGit(s,n,e):null}renderSessionSegment(e,t,n){return t?this.segmentRenderer.renderSession(t,n,e):null}async renderTmuxSegment(e){if(!this.needsSegmentInfo("tmux"))return null;let t=await this.tmuxService.getSessionId();return this.segmentRenderer.renderTmux(t,e)}renderContextSegment(e,t,n){return this.needsSegmentInfo("context")?this.segmentRenderer.renderContext(t,n,e):null}renderMetricsSegment(e,t,n,r){return this.segmentRenderer.renderMetrics(t,r,n,e)}renderBlockSegment(e,t,n){return t?this.segmentRenderer.renderBlock(t,n,e):null}renderTodaySegment(e,t,n){if(!t)return null;let r=e?.type||"cost";return this.segmentRenderer.renderToday(t,n,r)}renderVersionSegment(e,t,n){return this.segmentRenderer.renderVersion(t,n,e)}initializeSymbols(){let e=this.config.display.style,t=e==="minimal",n=e==="capsule";return {right:t?"":n?p.right_rounded:p.right,left:n?p.left_rounded:"",branch:p.branch,model:p.model,git_clean:p.git_clean,git_dirty:p.git_dirty,git_conflicts:p.git_conflicts,git_ahead:p.git_ahead,git_behind:p.git_behind,git_worktree:p.git_worktree,git_tag:p.git_tag,git_sha:p.git_sha,git_upstream:p.git_upstream,git_stash:p.git_stash,git_time:p.git_time,session_cost:p.session_cost,block_cost:p.block_cost,today_cost:p.today_cost,context_time:p.context_time,metrics_response:p.metrics_response,metrics_last_response:p.metrics_last_response,metrics_duration:p.metrics_duration,metrics_messages:p.metrics_messages,metrics_lines_added:p.metrics_lines_added,metrics_lines_removed:p.metrics_lines_removed,metrics_burn:p.metrics_burn,version:p.version}}getThemeColors(){let e=this.config.theme,t,n=this.config.display.colorCompatibility||"auto",r=n==="auto"?W():n;if(e==="custom"){if(t=this.config.colors?.custom,!t)throw new Error("Custom theme selected but no colors provided in configuration")}else t=V(e,r),t||(console.warn(`Built-in theme '${e}' not found, falling back to 'dark' theme`),t=V("dark",r));let s=V("dark",r),i=D=>{let v=t[D]||s[D];return r==="ansi"?{bg:ae(v.bg,true),fg:ae(v.fg,false)}:r==="ansi256"?{bg:ie(v.bg,true),fg:ie(v.fg,false)}:{bg:se(v.bg,true),fg:se(v.fg,false)}},a=i("directory"),c=i("git"),u=i("model"),g=i("session"),m=i("block"),f=i("today"),d=i("tmux"),h=i("context"),b=i("metrics"),T=i("version");return {reset:B,modeBg:a.bg,modeFg:a.fg,gitBg:c.bg,gitFg:c.fg,modelBg:u.bg,modelFg:u.fg,sessionBg:g.bg,sessionFg:g.fg,blockBg:m.bg,blockFg:m.fg,todayBg:f.bg,todayFg:f.fg,tmuxBg:d.bg,tmuxFg:d.fg,contextBg:h.bg,contextFg:h.fg,metricsBg:b.bg,metricsFg:b.fg,versionBg:T.bg,versionFg:T.fg}}getSegmentBgColor(e,t){switch(e){case "directory":return t.modeBg;case "git":return t.gitBg;case "model":return t.modelBg;case "session":return t.sessionBg;case "block":return t.blockBg;case "today":return t.todayBg;case "tmux":return t.tmuxBg;case "context":return t.contextBg;case "metrics":return t.metricsBg;case "version":return t.versionBg;default:return t.modeBg}}formatSegment(e,t,n,r){if(this.config.display.style==="capsule"){let g=this.config.display.colorCompatibility||"auto",f=(g==="auto"?W():g)==="ansi",d=G(e,f),h=`${d}${this.symbols.left}${B}`,b=`${e}${t} ${n} ${B}`,T=`${d}${this.symbols.right}${B}`;return `${h}${b}${T}`}let i=`${e}${t} ${n} `,a=this.config.display.colorCompatibility||"auto",u=(a==="auto"?W():a)==="ansi";if(r){let g=G(e,u);i+=`${B}${r}${g}${this.symbols.right}`;}else i+=`${B}${G(e,u)}${this.symbols.right}${B}`;return i}};var Le={theme:"dark",display:{style:"minimal",colorCompatibility:"auto",lines:[{segments:{directory:{enabled:true,showBasename:true},git:{enabled:true,showSha:false,showWorkingTree:false,showOperation:false,showTag:false,showTimeSinceCommit:false,showStashCount:false,showUpstream:false,showRepoName:false},model:{enabled:true},session:{enabled:true,type:"tokens",costSource:"calculated"},today:{enabled:true,type:"cost"},block:{enabled:false,type:"cost",burnType:"cost"},version:{enabled:false},tmux:{enabled:false},context:{enabled:true,showPercentageOnly:false},metrics:{enabled:false,showResponseTime:true,showLastResponseTime:true,showDuration:true,showMessageCount:true,showLinesAdded:true,showLinesRemoved:true}}}]},budget:{session:{warningThreshold:80},today:{warningThreshold:80,amount:50},block:{warningThreshold:80,amount:15}},modelContextLimits:{default:2e5,sonnet:2e5,opus:2e5}};function pe(o){return ["light","dark","nord","tokyo-night","rose-pine","custom"].includes(o)}function be(o){return o==="minimal"||o==="powerline"||o==="capsule"}function re(o,e){let t={...o};for(let n in e){let r=e[n];if(r!==void 0)if(typeof r=="object"&&r!==null&&!Array.isArray(r)){let s=t[n]||{};t[n]=re(s,r);}else t[n]=r;}return t}function dt(o,e){return o?k.existsSync(o)?o:null:[...e?[_.join(e,".claude-powerline.json")]:[],_.join(process.cwd(),".claude-powerline.json"),_.join(Oe.homedir(),".claude","claude-powerline.json"),_.join(Oe.homedir(),".config","claude-powerline","config.json")].find(k.existsSync)||null}function ht(o){try{let e=k.readFileSync(o,"utf-8");return JSON.parse(e)}catch(e){throw new Error(`Failed to load config file ${o}: ${e instanceof Error?e.message:String(e)}`)}}function pt(){let o={},e={},t=process.env.CLAUDE_POWERLINE_THEME;t&&pe(t)&&(o.theme=t);let n=process.env.CLAUDE_POWERLINE_STYLE;return n&&(be(n)?e.style=n:(console.warn(`Invalid display style '${n}' from environment variable, falling back to 'minimal'`),e.style="minimal")),Object.keys(e).length>0&&(o.display=e),o}function bt(){return process.env.CLAUDE_POWERLINE_CONFIG}function yt(o){let e={},t={},n=o.find(s=>s.startsWith("--theme="))?.split("=")[1];n&&pe(n)&&(e.theme=n);let r=o.find(s=>s.startsWith("--style="))?.split("=")[1];return r&&(be(r)?t.style=r:(console.warn(`Invalid display style '${r}' from CLI argument, falling back to 'minimal'`),t.style="minimal")),Object.keys(t).length>0&&(e.display=t),e}function Ct(o=process.argv,e){let t=JSON.parse(JSON.stringify(Le)),n=o.find(a=>a.startsWith("--config="))?.split("=")[1]||bt(),r=dt(n,e);if(r)try{let a=ht(r);t=re(t,a);}catch(a){console.warn(`Warning: ${a instanceof Error?a.message:String(a)}`);}t.display?.style&&!be(t.display.style)&&(console.warn(`Invalid display style '${t.display.style}' in config file, falling back to 'minimal'`),t.display.style="minimal"),t.theme&&!pe(t.theme)&&(console.warn(`Invalid theme '${t.theme}' in config file, falling back to 'dark'`),t.theme="dark");let s=pt();t=re(t,s);let i=yt(o);return t=re(t,i),t}var Ie=Ct;function Ne(){console.log(`
8
8
  claude-powerline - Beautiful powerline statusline for Claude Code
9
9
 
10
10
  Usage: claude-powerline [options]
11
11
 
12
12
  Standalone Commands:
13
- --install-fonts Install powerline fonts to system
14
13
  -h, --help Show this help
15
14
 
16
15
  Debugging:
@@ -23,7 +22,7 @@ Claude Code Options (for settings.json):
23
22
 
24
23
  See example config at: https://github.com/Owloops/claude-powerline/blob/main/.claude-powerline.json
25
24
 
26
- `);}async function vt(){try{let r=b.argv.includes("--help")||b.argv.includes("-h");b.argv.includes("--install-fonts")&&(await xt(),b.exit(0)),r&&(We(),b.exit(0)),b.stdin.isTTY===!0&&(console.error(`Error: This tool requires input from Claude Code
25
+ `);}async function wt(){try{(S.argv.includes("--help")||S.argv.includes("-h"))&&(Ne(),S.exit(0)),S.stdin.isTTY===!0&&(console.error(`Error: This tool requires input from Claude Code
27
26
 
28
27
  claude-powerline is designed to be used as a Claude Code statusLine command.
29
28
  It reads hook data from stdin and outputs formatted statusline.
@@ -39,4 +38,4 @@ Add to ~/.claude/settings.json:
39
38
  Run with --help for more options.
40
39
 
41
40
  To test output manually:
42
- echo '{"session_id":"test-session","workspace":{"project_dir":"/path/to/project"},"model":{"id":"claude-3-5-sonnet","display_name":"Claude"}}' | claude-powerline --style=powerline`),b.exit(1)),l(`Working directory: ${b.cwd()}`),l("Process args:",b.argv);let t=await json(b.stdin);l("Received hook data:",JSON.stringify(t,null,2)),t||(console.error("Error: No input data received from stdin"),We(),b.exit(1));let n=t.workspace?.project_dir,o=He(b.argv,n),i=await new re(o).generateStatusline(t);console.log(i);}catch(r){let e=r instanceof Error?r.message:String(r);console.error("Error generating statusline:",e),b.exit(1);}}vt();
41
+ echo '{"session_id":"test-session","workspace":{"project_dir":"/path/to/project"},"model":{"id":"claude-3-5-sonnet","display_name":"Claude"}}' | claude-powerline --style=powerline`),S.exit(1)),l(`Working directory: ${S.cwd()}`),l("Process args:",S.argv);let e=await json(S.stdin);l("Received hook data:",JSON.stringify(e,null,2)),e||(console.error("Error: No input data received from stdin"),Ne(),S.exit(1));let t=e.workspace?.project_dir,n=Ie(S.argv,t),s=await new te(n).generateStatusline(e);console.log(s);}catch(o){let e=o instanceof Error?o.message:String(o);console.error("Error generating statusline:",e),S.exit(1);}}wt();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@owloops/claude-powerline",
3
- "version": "1.9.12",
3
+ "version": "1.9.13",
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.js",