@owloops/claude-powerline 1.19.6 → 1.20.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/README.md +26 -4
  2. package/dist/index.js +12 -11
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -14,7 +14,7 @@
14
14
 
15
15
  ### Demo
16
16
 
17
- <img src="images/demo.gif" alt="Claude Powerline Demo" width="600"/>
17
+ <img src="images/demo-tui.gif" alt="Claude Powerline TUI Mode Demo" width="600"/>
18
18
 
19
19
  _Live demonstration: real-time usage tracking, git integration, and theme showcase_
20
20
 
@@ -83,7 +83,7 @@ Dark, light, nord, tokyo-night, rose-pine, and gruvbox themes with full custom c
83
83
 
84
84
  **Multiple styles**
85
85
 
86
- Minimal, powerline, and capsule separators with unicode or ASCII character sets.
86
+ Minimal, powerline, capsule, and TUI panel display with unicode or ASCII character sets.
87
87
 
88
88
  </td>
89
89
  </tr>
@@ -135,7 +135,7 @@ Once added to Claude Code settings, the statusline runs automatically. For custo
135
135
  **CLI Options** (both `--arg value` and `--arg=value` syntax supported):
136
136
 
137
137
  - `--theme` - `dark` (default), `light`, `nord`, `tokyo-night`, `rose-pine`, `gruvbox`, `custom`
138
- - `--style` - `minimal` (default), `powerline`, `capsule`
138
+ - `--style` - `minimal` (default), `powerline`, `capsule`, `tui`
139
139
  - `--charset` - `unicode` (default), `text`
140
140
  - `--config` - Custom config file path
141
141
  - `--help` - Show help
@@ -161,6 +161,27 @@ export CLAUDE_POWERLINE_DEBUG=1 # Enable debug logging
161
161
 
162
162
  <img src="images/claude-powerline-styles.png" alt="Claude Powerline Styles" width="600">
163
163
 
164
+ ### TUI Panel Mode
165
+
166
+ The `tui` style renders a bordered panel with all available data in a responsive layout. Unlike other styles, TUI mode is **opinionated**: it always displays all data regardless of segment enable/disable configuration. Only theme, charset, and budget thresholds are respected.
167
+
168
+ ```json
169
+ {
170
+ "statusLine": {
171
+ "type": "command",
172
+ "command": "npx -y @owloops/claude-powerline@latest --style=tui"
173
+ }
174
+ }
175
+ ```
176
+
177
+ The panel adapts to terminal width across three breakpoints:
178
+ - **Wide** (80+ cols): metrics on one line, workspace and footer spread across columns
179
+ - **Medium** (55-79 cols): metrics split across two lines, stacked footer
180
+ - **Narrow** (<55 cols): fully stacked layout
181
+
182
+ > [!NOTE]
183
+ > Claude Code's internal progress indicators (spinner, context bar) may briefly overlap the TUI panel during tool calls. This is a limitation of the hook architecture and resolves once the tool call completes.
184
+
164
185
  ## Configuration
165
186
 
166
187
  **Get example config:**
@@ -488,10 +509,11 @@ Choose between Unicode symbols (requires Nerd Font) or ASCII text mode for maxim
488
509
 
489
510
  **Combinations with styles:**
490
511
 
491
- The charset setting works independently from separator styles, giving you 6 possible combinations:
512
+ The charset setting works independently from separator styles, giving you 8 possible combinations:
492
513
  - `minimal` + `unicode` / `text` - No separators
493
514
  - `powerline` + `unicode` / `text` - Arrow separators (requires Nerd Font for unicode)
494
515
  - `capsule` + `unicode` / `text` - Rounded caps (requires Nerd Font for unicode)
516
+ - `tui` + `unicode` / `text` - Bordered panel with rounded or ASCII box characters
495
517
 
496
518
  **CLI Usage:**
497
519
 
package/dist/index.js CHANGED
@@ -1,12 +1,13 @@
1
1
  #!/usr/bin/env node
2
- import w from'process';import {json}from'stream/consumers';import O from'tty';import {exec,execSync}from'child_process';import {promisify}from'util';import _,{existsSync,readFileSync,createReadStream}from'fs';import C,{join,posix,dirname}from'path';import {get}from'https';import {URL}from'url';import de,{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 N(o,e=false){if(!o||o==="")return "";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 j(){let{env:o}=w,e=true;o.NO_COLOR&&o.NO_COLOR!==""&&(e=false);let t=o.FORCE_COLOR;if(t&&t!=="")return t==="false"||t==="0"?"none":t==="true"||t==="1"?"ansi":t==="2"?"ansi256":t==="3"?"truecolor":"ansi";if(!e||o.TERM==="dumb")return "none";if(o.CI)return ["GITHUB_ACTIONS","GITEA_ACTIONS","CIRCLECI"].some(r=>r 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(O?.WriteStream?.prototype?.hasColors)try{if(!O.WriteStream.prototype.hasColors())return "none";let s=O.WriteStream.prototype.hasColors(256);return O.WriteStream.prototype.hasColors(16777216)?"truecolor":s?"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,l)=>a===c&&c===l?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(l/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 Ce={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"},contextWarning:{bg:"#92400e",fg:"#fbbf24"},contextCritical:{bg:"#991b1b",fg:"#fca5a5"},metrics:{bg:"#374151",fg:"#d1d5db"},version:{bg:"#3a3a4a",fg:"#b8b8d0"},env:{bg:"#2d2d3d",fg:"#d0a0d0"}},_e={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"},contextWarning:{bg:"#af5f00",fg:"#ffaf00"},contextCritical:{bg:"#870000",fg:"#ff8787"},metrics:{bg:"#4e4e4e",fg:"#d0d0d0"},version:{bg:"#444444",fg:"#d7afff"},env:{bg:"#3a3a3a",fg:"#d787d7"}},xe={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"},contextWarning:{bg:"#d75f00",fg:"#ffff00"},contextCritical:{bg:"#af0000",fg:"#ff0000"},metrics:{bg:"#666666",fg:"#ffffff"},version:{bg:"#585858",fg:"#af87ff"},env:{bg:"#444444",fg:"#ff87ff"}};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"},contextWarning:{bg:"#d97706",fg:"#ffffff"},contextCritical:{bg:"#dc2626",fg:"#ffffff"},metrics:{bg:"#6b7280",fg:"#ffffff"},version:{bg:"#8b7dd8",fg:"#ffffff"},env:{bg:"#d45dbf",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"},contextWarning:{bg:"#d78700",fg:"#ffffff"},contextCritical:{bg:"#d70000",fg:"#ffffff"},metrics:{bg:"#767676",fg:"#ffffff"},version:{bg:"#af87ff",fg:"#ffffff"},env:{bg:"#d787af",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"},contextWarning:{bg:"#d78700",fg:"#ffffff"},contextCritical:{bg:"#d70000",fg:"#ffffff"},metrics:{bg:"#767676",fg:"#ffffff"},version:{bg:"#af87ff",fg:"#ffffff"},env:{bg:"#d787af",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"},contextWarning:{bg:"#d08770",fg:"#2e3440"},contextCritical:{bg:"#bf616a",fg:"#eceff4"},metrics:{bg:"#b48ead",fg:"#2e3440"},version:{bg:"#434c5e",fg:"#88c0d0"},env:{bg:"#3b4252",fg:"#b48ead"}},ve={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"},contextWarning:{bg:"#d7875f",fg:"#3a3a3a"},contextCritical:{bg:"#d75f5f",fg:"#ffffff"},metrics:{bg:"#d787af",fg:"#3a3a3a"},version:{bg:"#5f87af",fg:"#5fafaf"},env:{bg:"#4e4e4e",fg:"#d787af"}},Pe={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"},contextWarning:{bg:"#d78700",fg:"#000000"},contextCritical:{bg:"#d75f5f",fg:"#ffffff"},metrics:{bg:"#ff87d7",fg:"#444444"},version:{bg:"#0087af",fg:"#00d7d7"},env:{bg:"#585858",fg:"#ff87af"}};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"},contextWarning:{bg:"#ff9e64",fg:"#1a1b26"},contextCritical:{bg:"#f7768e",fg:"#1a1b26"},metrics:{bg:"#3d59a1",fg:"#c0caf5"},version:{bg:"#292e42",fg:"#bb9af7"},env:{bg:"#24283b",fg:"#fca7ea"}},$e={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"},contextWarning:{bg:"#ffaf5f",fg:"#262626"},contextCritical:{bg:"#ff5f87",fg:"#262626"},metrics:{bg:"#5f5faf",fg:"#d7d7ff"},version:{bg:"#444460",fg:"#d787ff"},env:{bg:"#303050",fg:"#ff87ff"}},Re={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"},contextWarning:{bg:"#ffaf00",fg:"#000000"},contextCritical:{bg:"#ff5f5f",fg:"#000000"},metrics:{bg:"#8787d7",fg:"#ffffff"},version:{bg:"#585870",fg:"#d787ff"},env:{bg:"#444470",fg:"#ff87ff"}};var Be={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"},contextWarning:{bg:"#f6c177",fg:"#191724"},contextCritical:{bg:"#eb6f92",fg:"#191724"},metrics:{bg:"#524f67",fg:"#e0def4"},version:{bg:"#2a273f",fg:"#c4a7e7"},env:{bg:"#21202e",fg:"#eb6f92"}},De={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"},contextWarning:{bg:"#d7af5f",fg:"#1c1c1c"},contextCritical:{bg:"#ff5f87",fg:"#1c1c1c"},metrics:{bg:"#767676",fg:"#e4e4e4"},version:{bg:"#4e4e4e",fg:"#d787d7"},env:{bg:"#303030",fg:"#ff5f87"}},Ae={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"},contextWarning:{bg:"#d7af00",fg:"#000000"},contextCritical:{bg:"#ff5f5f",fg:"#000000"},metrics:{bg:"#a8a8a8",fg:"#000000"},version:{bg:"#666666",fg:"#ff87ff"},env:{bg:"#444444",fg:"#ff5f87"}};var Fe={directory:{bg:"#504945",fg:"#ebdbb2"},git:{bg:"#3c3836",fg:"#b8bb26"},model:{bg:"#665c54",fg:"#83a598"},session:{bg:"#282828",fg:"#8ec07c"},block:{bg:"#3c3836",fg:"#83a598"},today:{bg:"#282828",fg:"#fabd2f"},tmux:{bg:"#282828",fg:"#fe8019"},context:{bg:"#458588",fg:"#ebdbb2"},contextWarning:{bg:"#d79921",fg:"#282828"},contextCritical:{bg:"#cc241d",fg:"#ebdbb2"},metrics:{bg:"#d3869b",fg:"#282828"},version:{bg:"#504945",fg:"#8ec07c"},env:{bg:"#3c3836",fg:"#d3869b"}},Me={directory:{bg:"#585858",fg:"#ffffaf"},git:{bg:"#444444",fg:"#afaf00"},model:{bg:"#6c6c6c",fg:"#87afaf"},session:{bg:"#303030",fg:"#87af87"},block:{bg:"#444444",fg:"#87afaf"},today:{bg:"#303030",fg:"#ffaf00"},tmux:{bg:"#303030",fg:"#ff8700"},context:{bg:"#5f8787",fg:"#ffffaf"},contextWarning:{bg:"#d7af00",fg:"#303030"},contextCritical:{bg:"#d70000",fg:"#ffffaf"},metrics:{bg:"#d787af",fg:"#303030"},version:{bg:"#585858",fg:"#87af87"},env:{bg:"#444444",fg:"#d787af"}},Ue={directory:{bg:"#808080",fg:"#ffff00"},git:{bg:"#585858",fg:"#00ff00"},model:{bg:"#808080",fg:"#00afff"},session:{bg:"#444444",fg:"#00d787"},block:{bg:"#585858",fg:"#00afff"},today:{bg:"#444444",fg:"#ffaf00"},tmux:{bg:"#444444",fg:"#ff8700"},context:{bg:"#008787",fg:"#ffffff"},contextWarning:{bg:"#d7af00",fg:"#000000"},contextCritical:{bg:"#d70000",fg:"#ffffff"},metrics:{bg:"#ff87af",fg:"#444444"},version:{bg:"#808080",fg:"#00d787"},env:{bg:"#585858",fg:"#ff87af"}};var ce={dark:Ce,"dark-ansi256":_e,"dark-ansi":xe,light:we,"light-ansi256":Se,"light-ansi":ke,nord:Te,"nord-ansi256":ve,"nord-ansi":Pe,"tokyo-night":Ee,"tokyo-night-ansi256":$e,"tokyo-night-ansi":Re,"rose-pine":Be,"rose-pine-ansi256":De,"rose-pine-ansi":Ae,gruvbox:Fe,"gruvbox-ansi256":Me,"gruvbox-ansi":Ue};function W(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 g=(o,...e)=>{process.env.CLAUDE_POWERLINE_DEBUG&&console.error(`[DEBUG] ${o}`,...e);};var rt=promisify(exec),R=class{isGitRepo(e){try{return _.existsSync(C.join(e,".git"))}catch{return false}}async execGitAsync(e,t){return rt(e,{...t,env:{...process.env,GIT_OPTIONAL_LOCKS:"0"}})}async findGitRoot(e){try{return (await this.execGitAsync("git rev-parse --show-toplevel",{cwd:e,encoding:"utf8",timeout:2e3})).stdout.trim()||null}catch{return null}}async getGitInfo(e,t={},n){let r,s=this.isWorktree(e);if(s)r=e;else if(n&&this.isGitRepo(n))r=n;else if(this.isGitRepo(e))r=e;else {let i=await this.findGitRoot(e);if(!i)return null;r=i;}try{let i=await this.getStatusWithBranchAsync(r),a=await this.getAheadBehindAsync(r),c={branch:i.branch||"detached",status:i.status,ahead:a.ahead,behind:a.behind};t.showWorkingTree&&i.workingTree&&(c.staged=i.workingTree.staged,c.unstaged=i.workingTree.unstaged,c.untracked=i.workingTree.untracked,c.conflicts=i.workingTree.conflicts);let l={},f={};t.showSha&&(l.sha=this.getShaAsync(r)),t.showTag&&(l.tag=this.getNearestTagAsync(r)),t.showTimeSinceCommit&&(l.timeSinceCommit=this.getTimeSinceLastCommitAsync(r)),t.showStashCount&&(f.stashCount=this.getStashCountAsync(r)),t.showUpstream&&(f.upstream=this.getUpstreamAsync(r)),t.showRepoName&&(f.repoName=this.getRepoNameAsync(r));let m=new Map;for(let[u,d]of Object.entries(l))try{let p=await d;m.set(u,p);}catch{}return Object.keys(f).length>0&&(await Promise.allSettled(Object.entries(f).map(async([d,p])=>({key:d,value:await p})))).forEach(d=>{d.status==="fulfilled"&&m.set(d.value.key,d.value.value);}),t.showSha&&(c.sha=m.get("sha")||void 0),t.showOperation&&(c.operation=this.getOngoingOperation(r)||void 0),t.showTag&&(c.tag=m.get("tag")||void 0),t.showTimeSinceCommit&&(c.timeSinceCommit=m.get("timeSinceCommit")||void 0),t.showStashCount&&(c.stashCount=m.get("stashCount")||0),t.showUpstream&&(c.upstream=m.get("upstream")||void 0),t.showRepoName&&(c.repoName=m.get("repoName")||void 0,c.isWorktree=s),c}catch{return null}}async getShaAsync(e){try{return (await this.execGitAsync("git rev-parse --short=7 HEAD",{cwd:e,encoding:"utf8",timeout:2e3})).stdout.trim()||null}catch{return null}}resolveGitDir(e){let t=C.join(e,".git");if(_.existsSync(t)&&_.statSync(t).isFile()){let r=_.readFileSync(t,"utf-8").match(/^gitdir:\s*(.+)$/m);if(r?.[1])return C.resolve(e,r[1].trim())}return t}getOngoingOperation(e){try{let t=this.resolveGitDir(e);return _.existsSync(C.join(t,"MERGE_HEAD"))?"MERGE":_.existsSync(C.join(t,"CHERRY_PICK_HEAD"))?"CHERRY-PICK":_.existsSync(C.join(t,"REVERT_HEAD"))?"REVERT":_.existsSync(C.join(t,"BISECT_LOG"))?"BISECT":_.existsSync(C.join(t,"rebase-merge"))||_.existsSync(C.join(t,"rebase-apply"))?"REBASE":null}catch{return null}}async getNearestTagAsync(e){try{return (await this.execGitAsync("git describe --tags --abbrev=0",{cwd:e,encoding:"utf8",timeout:2e3})).stdout.trim()||null}catch{return null}}async getTimeSinceLastCommitAsync(e){try{let n=(await this.execGitAsync("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 this.execGitAsync("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 this.execGitAsync("git rev-parse --abbrev-ref @{u}",{cwd:e,encoding:"utf8",timeout:2e3})).stdout.trim()||null}catch{return null}}async getRepoNameAsync(e){try{let n=(await this.execGitAsync("git config --get remote.origin.url",{cwd:e,encoding:"utf8",timeout:2e3})).stdout.trim();return n?n.match(/\/([^/]+?)(\.git)?$/)?.[1]||C.basename(e):C.basename(e)}catch{return C.basename(e)}}isWorktree(e){try{let t=C.join(e,".git");return !!(_.existsSync(t)&&_.statSync(t).isFile())}catch{return false}}async getStatusWithBranchAsync(e){try{g(`[GIT-EXEC] Running git status in ${e}`);let r=(await this.execGitAsync("git status --porcelain -b",{cwd:e,encoding:"utf8",timeout:2e3})).stdout.split(`
4
- `),s=null,i="clean",a=0,c=0,l=0,f=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 u=m.charAt(0),d=m.charAt(1);if(u==="?"&&d==="?"){l++,i==="clean"&&(i="dirty");continue}let p=u+d;if(["DD","AU","UD","UA","DU","AA","UU"].includes(p)){f++,i="conflicts";continue}u!==" "&&u!=="?"&&(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:l,conflicts:f}}}catch(t){return g(`Git status with branch command failed in ${e}:`,t),{branch:await this.getFallbackBranch(e),status:"clean"}}}async getFallbackBranch(e){try{let n=(await this.execGitAsync("git branch --show-current",{cwd:e,encoding:"utf8",timeout:2e3})).stdout.trim();if(n)return n}catch{try{let n=(await this.execGitAsync("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{g(`[GIT-EXEC] Running git ahead/behind in ${e}`);let[t,n]=await Promise.all([this.execGitAsync("git rev-list --count @{u}..HEAD",{cwd:e,encoding:"utf8",timeout:2e3}),this.execGitAsync("git rev-list --count HEAD..@{u}",{cwd:e,encoding:"utf8",timeout:2e3})]);return {ahead:parseInt(t.stdout.trim())||0,behind:parseInt(n.stdout.trim())||0}}catch(t){return g(`Git ahead/behind command failed in ${e}:`,t),{ahead:0,behind:0}}}};var it=promisify(exec),B=class{async getSessionId(){try{if(!process.env.TMUX_PANE)return g("TMUX_PANE not set, not in tmux session"),null;g(`Getting tmux session ID, TMUX_PANE: ${process.env.TMUX_PANE}`);let t=(await it("tmux display-message -p '#S'",{encoding:"utf8",timeout:1e3})).stdout.trim();return g(`Tmux session ID: ${t||"empty"}`),t||null}catch(e){return g("Error getting tmux session ID:",e),null}}isInTmux(){return !!process.env.TMUX_PANE}};function G(){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 V(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){g(`Failed to read projects directory ${n}:`,r);}}return e}async function Y(o){let e=G(),t=await V(e);for(let n of t){let r=posix.join(n,`${o}.jsonl`);if(existsSync(r))return r}return null}async function Ne(o,e){let t=[],n=posix.join(e,o,"subagents");try{let s=(await readdir(n)).filter(i=>i.startsWith("agent-")&&i.endsWith(".jsonl"));for(let i of s){let a=posix.join(n,i);try{let l=(await readFile(a,"utf-8")).split(`
5
- `)[0];l&&JSON.parse(l).sessionId===o&&t.push(a);}catch{g(`Failed to check agent file ${a}`);}}}catch(r){g(`Failed to read subagents directory ${n}:`,r);}return t}async function ge(o){try{return (await stat(o)).mtime}catch{return null}}function gt(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 ft=1024*1024;async function $(o){try{let t=(await stat(o)).size,n;return t>ft?(g(`Using streaming parser for large file ${o} (${Math.round(t/1024)}KB)`),n=await mt(o)):n=await ut(o),g(`Parsed ${n.length} entries from ${o}`),n}catch(e){return g(`Failed to read file ${o}:`,e),[]}}async function ut(o){let t=(await readFile(o,"utf-8")).trim().split(`
6
- `).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){g(`Failed to parse JSONL line: ${s}`);continue}return n}async function mt(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 l={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(l);}catch(c){g(`Failed to parse JSONL line: ${c}`);}}),s.on("close",()=>{e(n);}),s.on("error",i=>{g(`Streaming parser error for ${o}:`,i),t(i);}),r.on("error",i=>{g(`File stream error for ${o}:`,i),t(i);});})}async function Le(o){try{let e=await ge(o);return e?{filePath:o,mtime:e}:null}catch{return null}}async function dt(o,e){try{let t=await readdir(o,{withFileTypes:!0}),n=t.filter(a=>!a.isDirectory()&&a.name.endsWith(".jsonl")).map(a=>Le(posix.join(o,a.name))),r=t.filter(a=>a.isDirectory()).map(async a=>{let c=posix.join(o,a.name,"subagents");try{return (await readdir(c)).filter(f=>f.startsWith("agent-")&&f.endsWith(".jsonl")).map(f=>Le(posix.join(c,f)))}catch{return []}}),[s,i]=await Promise.all([Promise.all(n),Promise.all(r).then(a=>Promise.all(a.flat()))]);return [...s,...i].filter(a=>a!==null&&(!e||e(a.filePath,a.mtime)))}catch(t){return g(`Failed to read project directory ${o}:`,t),[]}}async function J(o,e,t=false){let n=G(),r=await V(n),s=new Set,i=r.map(p=>dt(p,e)),c=(await Promise.all(i)).flat().filter(p=>p!==null);t&&c.sort((p,h)=>h.mtime.getTime()-p.mtime.getTime());let l=c.map(p=>p.filePath),f=[],m=l.map(async p=>(await $(p)).filter(b=>!o||o(b))),u=await Promise.all(m);for(let p of u)f.push(...p);f.sort((p,h)=>p.timestamp.getTime()-h.timestamp.getTime());let d=[];for(let p of f){let h=gt(p);h&&s.has(h)||(h&&s.add(h),d.push(p));}return d}var k=class{static CACHE_DIR=C.join(homedir(),".claude","powerline");static USAGE_CACHE_DIR=C.join(this.CACHE_DIR,"usage");static LOCKS_DIR=C.join(this.CACHE_DIR,"locks");static isLocked(e){let t=C.join(this.LOCKS_DIR,e);if(!_.existsSync(t))return false;try{let n=_.readFileSync(t,"utf-8"),r=parseInt(n.trim(),10);if(isNaN(r))return g(`Invalid PID in lock file ${e}, removing stale lock`),_.unlinkSync(t),!1;try{return process.kill(r,0),!0}catch(s){return s.code==="ESRCH"?(g(`Removing stale lock file ${e} for dead process ${r}`),_.unlinkSync(t),!1):(g(`Error checking process ${r} for lock ${e}:`,s),!0)}}catch(n){return g(`Error reading lock file ${e}:`,n),true}}static async acquireLock(e,t=5e3){await this.ensureCacheDirectories();let s=C.join(this.LOCKS_DIR,e),i=Date.now(),a=String(process.pid);for(;Date.now()-i<t;)try{return await _.promises.writeFile(s,a,{flag:"wx"}),g(`Lock acquired for ${e}`),!0}catch(c){if(c.code==="EEXIST")await setTimeout(50);else throw c}return g(`Failed to acquire lock for ${e} within ${t}ms`),false}static async releaseLock(e){let t=C.join(this.LOCKS_DIR,e);try{await _.promises.unlink(t),g(`Lock released for ${e}`);}catch(n){n.code!=="ENOENT"&&g(`Error releasing lock for ${e}:`,n);}}static async ensureCacheDirectories(){try{await Promise.all([_.promises.mkdir(this.CACHE_DIR,{recursive:!0}),_.promises.mkdir(this.USAGE_CACHE_DIR,{recursive:!0}),_.promises.mkdir(this.LOCKS_DIR,{recursive:!0})]);}catch(e){g("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=C.join(this.USAGE_CACHE_DIR,`${e}.json`),a=`${e}.usage.lock`;for(let c=0;c<3;c++){if(this.isLocked(a)){g(`Cache for ${e} is locked, waiting...`),await setTimeout(75);continue}try{let f=await _.promises.readFile(i,s),m=JSON.parse(f);return !t||m.timestamp>=t?(g(`[CACHE-HIT] ${e} disk cache: found`),this.deserializeDates(m.data)):(g(`${e} cache outdated: cache=${m.timestamp}, latest=${t}`),null)}catch(f){if(f.code==="ENOENT")return g(`No shared ${e} usage cache found`),null;let m=c+1;g(`Attempt ${m} failed to read ${e} cache: ${f.message}. Retrying...`),await setTimeout(75);}}return g(`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)){g(`Could not acquire lock to set usage cache for ${e}`);return}try{await this.ensureCacheDirectories();let i=C.join(this.USAGE_CACHE_DIR,`${e}.json`),a=n||Date.now(),l=JSON.stringify({data:t,timestamp:a});await _.promises.writeFile(i,l,"utf-8"),g(`[CACHE-SET] ${e} disk cache stored`);}catch(i){g(`Failed to save ${e} usage cache:`,i);}finally{await this.releaseLock(r);}}static async getLatestTranscriptMtime(){try{let e=G(),t=await V(e),n=0;for(let r of t)try{let i=(await _.promises.readdir(r)).filter(a=>a.endsWith(".jsonl"));for(let a of i){let c=C.join(r,a),l=await ge(c);l&&l.getTime()>n&&(n=l.getTime());}}catch(s){g(`Failed to read project directory ${r}:`,s);continue}return n}catch(e){return g("Failed to get latest transcript mtime:",e),Date.now()}}};var z={"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-haiku-4-5-20251001":{name:"Claude Haiku 4.5",input:1,output:5,cache_write_5m:1.25,cache_write_1h:2,cache_read:.1},"claude-haiku-4-5":{name:"Claude Haiku 4.5",input:1,output:5,cache_write_5m:1.25,cache_write_1h:2,cache_read:.1},"claude-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-sonnet-4-5":{name:"Claude Sonnet 4.5",input:3,output:15,cache_write_5m:3.75,cache_write_1h:6,cache_read:.3},"claude-sonnet-4-5-20250929":{name:"Claude Sonnet 4.5",input:3,output:15,cache_write_5m:3.75,cache_write_1h:6,cache_read:.3},"claude-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}},v=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 k.getUsageCache("pricing",t)}static async saveDiskCache(e){await k.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){g(`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){g("Response too large"),n.destroy(),e(null);return}s+=c;}),r.on("end",()=>{try{let l=JSON.parse(s),f=l._meta,m={};for(let[u,d]of Object.entries(l))u!=="_meta"&&(m[u]=d);this.validatePricingData(m)?(g(`Fetched fresh pricing from GitHub for ${Object.keys(m).length} models`),g(`Pricing last updated: ${f?.updated||"unknown"}`),e(m)):(g("Invalid pricing data structure"),e(null));}catch(c){g("Failed to parse JSON:",c),e(null);}}),r.on("error",c=>{g("Response error:",c),e(null);});});n.on("error",r=>{g("Request error:",r),e(null);}),n.on("timeout",()=>{g("Request timeout"),n.destroy(),e(null);}),n.end();})}static async getCurrentPricing(){if(this.executionCache!==null)return g(`[CACHE-HIT] Pricing execution cache: ${Object.keys(this.executionCache).length} models`),this.executionCache;let e=await this.loadDiskCache();if(e)return g(`[CACHE-HIT] Pricing disk cache: ${Object.keys(e).length} models`),this.executionCache=e,g(`[CACHE-SET] Pricing execution cache stored: ${Object.keys(e).length} models`),e;let t=await this.fetchPricingData();return t?(await this.saveDiskCache(t),g(`[CACHE-SET] Pricing disk cache stored: ${Object.keys(t).length} models`),this.executionCache=t,g(`[CACHE-SET] Pricing execution cache stored: ${Object.keys(t).length} models`),t):(g(`[CACHE-FALLBACK] Using offline pricing data: ${Object.keys(z).length} models`),this.executionCache=z,g(`[CACHE-SET] Pricing execution cache stored: ${Object.keys(z).length} models`),z)}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 g(`[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),g(`[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.5","4-5-sonnet","sonnet-4-5"],fallback:"claude-sonnet-4-5-20250929"},{pattern:["sonnet-4","claude-sonnet-4"],fallback:"claude-sonnet-4-20250514"},{pattern:["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:["haiku-4.5","4-5-haiku","haiku-4-5"],fallback:"claude-haiku-4-5-20251001"},{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,l=n.cache_read_input_tokens||0,f=i/1e6*s.input,m=a/1e6*s.output,u=l/1e6*s.cache_read,d=c/1e6*s.cache_write_5m;return f+m+d+u}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 _t(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 q=class{async getSessionUsage(e){try{let t=await Y(e);if(!t)return g(`No transcript found for session: ${e}`),null;g(`Found transcript at: ${t}`);let n=await $(t),r=dirname(t),s=await Ne(e,r);g(`Found ${s.length} agent transcripts for session`);for(let c of s){let l=await $(c);n.push(...l);}if(n.length===0)return {totalCost:0,entries:[]};let i=[],a=0;for(let c of n)if(c.message?.usage){let l=_t(c);if(l.costUSD!==void 0)a+=l.costUSD;else {let f=await v.calculateCostForEntry(c.raw);l.costUSD=f,a+=f;}i.push(l);}return g(`Parsed ${i.length} usage entries, total cost: $${a.toFixed(4)}`),{totalCost:a,entries:i}}catch(t){return g(`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}}},A=class{sessionProvider=new q;async getUsageInfo(e,t){try{return g(`Starting usage info retrieval for session: ${e}`),{session:await this.sessionProvider.getSessionInfo(e,t)}}catch(n){return g(`Error getting usage info for session ${e}:`,n),{session:{cost:null,calculatedCost:null,officialCost:null,tokens:null,tokenBreakdown:null}}}}};var F=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"}calculatePercentages(e,t,n=33e3){let r=Math.min(100,Math.max(0,Math.round(e/t*100))),s=Math.max(1,t-n),i=Math.min(100,Math.max(0,Math.round(e/s*100))),a=Math.max(0,100-i);return {percentage:r,usablePercentage:i,contextLeftPercentage:a,usableTokens:s}}calculateContextFromHookData(e,t=33e3){let n=e.context_window?.current_usage;if(!n)return g("No current_usage in hook data, falling back to transcript parsing"),null;let r=e.context_window?.context_window_size||2e5,s=(n.input_tokens||0)+(n.cache_creation_input_tokens||0)+(n.cache_read_input_tokens||0);g(`Native current_usage: input=${n.input_tokens}, cache_create=${n.cache_creation_input_tokens}, cache_read=${n.cache_read_input_tokens}, total=${s} (limit: ${r})`);let i=this.calculatePercentages(s,r,t);return {totalTokens:s,maxTokens:r,...i}}async calculateContextTokensFromTranscript(e,t,n=33e3){try{g(`Calculating context tokens from transcript: ${e}`);try{if(!readFileSync(e,"utf-8"))return g("Transcript file is empty"),null}catch{return g("Could not read transcript file"),null}let r=await $(e);if(r.length===0)return g("No entries in transcript"),null;let s=null;for(let i=r.length-1;i>=0;i--){let a=r[i];if(a&&a.message?.usage?.input_tokens&&a.isSidechain!==!0){s=a,g(`Context segment: Found most recent entry at ${a.timestamp.toISOString()}, stopping search`);break}}if(s?.message?.usage){let i=s.message.usage,a=(i.input_tokens||0)+(i.cache_read_input_tokens||0)+(i.cache_creation_input_tokens||0),c=t?this.getContextLimit(t):2e5;g(`Most recent main chain context: ${a} tokens (limit: ${c})`);let l=this.calculatePercentages(a,c,n);return {totalTokens:a,maxTokens:c,...l}}return g("No main chain entries with usage data found"),null}catch(r){return g(`Error reading transcript: ${r instanceof Error?r.message:String(r)}`),null}}async getContextInfo(e,t=33e3){let n=this.calculateContextFromHookData(e,t);return n||this.calculateContextTokensFromTranscript(e.transcript_path,e.model?.id,t)}};var M=class{async loadTranscriptEntries(e){try{let t=await Y(e);if(!t)return g(`No transcript found for session: ${e}`),[];g(`Loading transcript from: ${t}`);let r=(await readFile(t,"utf-8")).trim().split(`
7
- `).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){g(`Failed to parse JSONL line: ${a}`);continue}return g(`Loaded ${s.length} transcript entries`),s}catch(t){return g(`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 f=(i.getTime()-n.getTime())/1e3;f>.1&&f<300&&(r=f);}}catch{continue}return r}async getMetricsInfo(e,t){try{if(g(`Getting metrics from hook data for session: ${e}`),!t.cost)return g("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 g(`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 T(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 je(o){if(!o)return "0 tokens";let e=[];if(o.input>0&&e.push(`${T(o.input).replace(" tokens","")} in`),o.output>0&&e.push(`${T(o.output).replace(" tokens","")} out`),o.cacheCreation>0||o.cacheRead>0){let t=o.cacheCreation+o.cacheRead;e.push(`${T(t).replace(" tokens","")} cached`);}return e.length>0?e.join(" + "):"0 tokens"}function We(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 He(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`}var St=/^(?:(?:global|apac|au|eu|us|us-east-\d|us-west-\d|eu-west-\d|eu-central-\d)\.)?(?:anthropic\.|azure_ai\/|bedrock\/|vertex_ai\/)?claude-(?:(?<family>opus|sonnet|haiku)-(?<newMajor>\d+)(?:-(?<newMinor>\d))?|(?<oldMajor>\d+)(?:-(?<oldMinor>\d))?-(?<oldFamily>opus|sonnet|haiku))(?:[-@]\d{8})?(?:-v\d+:\d+)?(?:-latest)?$/i;function Ge(o){let e=o.trim().match(St);if(!e?.groups)return o;let{family:t,newMajor:n,newMinor:r,oldMajor:s,oldMinor:i,oldFamily:a}=e.groups,c=t||a,l=n||s,f=r||i;if(c&&l){let m=c.charAt(0).toUpperCase()+c.slice(1).toLowerCase(),u=f?`${l}.${f}`:l;return `${m} ${u}`}return o}function kt(o,e){return !e||e<=0||o<0?null:Math.min(100,o/e*100)}function ue(o,e,t=80){let n=kt(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 Tt={ball:{filled:"\u2500",empty:"\u2500",marker:"\u25CF"},blocks:{filled:"\u2588",empty:"\u2591"},"blocks-line":{filled:"\u2588",empty:"\u2500"},capped:{filled:"\u2501",empty:"\u2504",cap:"\u2578"},dots:{filled:"\u25CF",empty:"\u25CB"},filled:{filled:"\u25A0",empty:"\u25A1"},geometric:{filled:"\u25B0",empty:"\u25B1"},line:{filled:"\u2501",empty:"\u2504"},squares:{filled:"\u25FC",empty:"\u25FB"}},U=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,i=n?.style??(n?.showBasename?"basename":"full");if(i==="basename")return {text:C.basename(r)||"root",bgColor:t.modeBg,fgColor:t.modeFg};let a=process.env.HOME||process.env.USERPROFILE,c=r,l=s;a&&(r.startsWith(a)&&(c=r.replace(a,"~")),s&&s.startsWith(a)&&(l=s.replace(a,"~")));let f=this.getDisplayDirectoryName(c,l);return i==="fish"&&(f=this.abbreviateFishStyle(f)),{text:f,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=We(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",r=Ge(n);return {text:`${this.symbols.model} ${r}`,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==="calculated"?e.session.calculatedCost:s==="official"?e.session.officialCost:e.session.cost,c=this.formatUsageWithBudget(a(),e.session.tokens,e.session.tokenBreakdown,r,i?.amount,i?.warningThreshold||80,i?.type);return {text:`${this.symbols.session_cost} ${c}`,bgColor:t.sessionBg,fgColor:t.sessionFg}}renderTmux(e,t){return e?{text:`tmux:${e}`,bgColor:t.tmuxBg,fgColor:t.tmuxFg}:{text:"tmux:none",bgColor:t.tmuxBg,fgColor:t.tmuxFg}}renderContext(e,t,n){let s=n?.displayStyle??"text",i=s==="text"?"remaining":"used",a=n?.percentageMode??i,c=s==="bar"?{filled:this.symbols.bar_filled,empty:this.symbols.bar_empty}:Tt[s]??null,l=a==="remaining"?"100%":"0%";if(!e)return c?{text:`${c.empty.repeat(10)} ${l}`,bgColor:t.contextBg,fgColor:t.contextFg}:{text:`${this.symbols.context_time} 0 (${l})`,bgColor:t.contextBg,fgColor:t.contextFg};let f=t.contextBg,m=t.contextFg;e.contextLeftPercentage<=20?(f=t.contextCriticalBg,m=t.contextCriticalFg):e.contextLeftPercentage<=40&&(f=t.contextWarningBg,m=t.contextWarningFg);let u=a==="remaining"?e.contextLeftPercentage:e.usablePercentage,d=Math.round(e.usablePercentage/100*10),p=10-d;if(c){let b=this.buildBar(c,d,p,10);return {text:n?.showPercentageOnly?`${b} ${u}%`:`${b} ${e.totalTokens.toLocaleString()} (${u}%)`,bgColor:f,fgColor:m}}return {text:n?.showPercentageOnly?`${this.symbols.context_time} ${u}%`:`${this.symbols.context_time} ${e.totalTokens.toLocaleString()} (${u}%)`,bgColor:f,fgColor:m}}buildBar(e,t,n,r){if(e.marker){let s=Math.min(t,r-1);return e.filled.repeat(s)+e.marker+e.empty.repeat(r-s-1)}return e.cap?t===0?e.cap+e.empty.repeat(r-1):t>=r?e.filled.repeat(r):e.filled.repeat(t-1)+e.cap+e.empty.repeat(n):e.filled.repeat(t)+e.empty.repeat(n)}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=He(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),u=e.timeRemaining%60;return m>0?`${m}h ${u}m`:`${u}m`})():null,l;switch(s){case "cost":l=this.formatUsageWithBudget(e.cost,null,null,"cost",a?.amount,a?.warningThreshold,a?.type);break;case "tokens":l=this.formatUsageWithBudget(null,e.tokens,null,"tokens",a?.amount,a?.warningThreshold,a?.type);break;case "weighted":let m=a?.type==="tokens"?a.amount:void 0,u=T(e.weightedTokens);if(m&&e.weightedTokens!==null){let d=ue(e.weightedTokens,m,a?.warningThreshold||80);l=`${u}${d.displayText}`;}else l=`${u} (weighted)`;break;case "both":l=this.formatUsageWithBudget(e.cost,e.tokens,null,"both",a?.amount,a?.warningThreshold,a?.type);break;case "time":l=c||"N/A";break;default:l=this.formatUsageWithBudget(e.cost,null,null,"cost",a?.amount,a?.warningThreshold,a?.type);}let f="";if(i&&i!=="none")switch(i){case "cost":f=` | ${e.burnRate!==null?e.burnRate<1?`${(e.burnRate*100).toFixed(0)}\xA2/h`:`$${e.burnRate.toFixed(2)}/h`:"N/A"}`;break;case "tokens":f=` | ${e.tokenBurnRate!==null?`${T(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",p=e.tokenBurnRate!==null?`${T(Math.round(e.tokenBurnRate))}/h`:"N/A";f=` | ${d} / ${p}`;break}s==="time"?r=l:r=c?`${l}${f} (${c} left)`:`${l}${f}`;}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)||C.basename(t)||"project":e}abbreviateFishStyle(e){let t=e.split(C.sep);return t.map((n,r)=>r===t.length-1||n==="~"||n===""?n:n.charAt(0)).join(C.sep)}formatUsageDisplay(e,t,n,r){switch(r){case "cost":return X(e);case "tokens":return T(t);case "both":return `${X(e)} (${T(t)})`;case "breakdown":return je(n);default:return X(e)}}formatUsageWithBudget(e,t,n,r,s,i=80,a){let c=this.formatUsageDisplay(e,t,n,r);if(s&&s>0){let l=null;if(a==="tokens"&&t!==null?l=t:(a==="cost"&&e!==null||!a&&e!==null)&&(l=e),l!==null){let f=ue(l,s,i);return c+f.displayText}}return c}renderVersion(e,t,n){return e.version?{text:`${this.symbols.version} v${e.version}`,bgColor:t.versionBg,fgColor:t.versionFg}:null}renderEnv(e,t){let n=process.env[t.variable];if(!n)return null;let r=t.prefix??t.variable;return {text:r?`${this.symbols.env} ${r}: ${n}`:`${this.symbols.env} ${n}`,bgColor:e.envBg,fgColor:e.envFg}}};function vt(o){return o.includes("opus")?5:(o.includes("sonnet")||o.includes("haiku"),1)}function Pt(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 Z=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 l=c.getTime()-s.getTime(),f=i[i.length-1];if(f==null)continue;let m=f.timestamp,u=c.getTime()-m.getTime();l>t||u>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{g("Block segment: Loading entries for dynamic session blocks");let e=new Date;e.setDate(e.getDate()-1);let n=await J(void 0,(c,l)=>l>=e,!0),r=[];for(let c of n)if(c.message?.usage){let l=Pt(c);!l.costUSD&&c.raw&&(l.costUSD=await v.calculateCostForEntry(c.raw)),r.push(l);}let s=this.identifySessionBlocks(r);g(`Block segment: Found ${s.length} session blocks`);let i=this.findActiveBlock(s),a=[];if(i&&i.length>0){g(`Block segment: Found active block with ${i.length} entries`);let c=i[0],l=i[i.length-1];c&&l&&g(`Block segment: Active block from ${c.timestamp.toISOString()} to ${l.timestamp.toISOString()}`),a=i;}else g("Block segment: No active block found"),a=[];return a}catch(e){return g("Error loading block entries:",e),[]}}async getActiveBlockInfo(){try{let e=await this.loadUsageEntries();if(e.length===0)return g("Block segment: No entries in current block"),{cost:null,tokens:null,weightedTokens:null,timeRemaining:null,burnRate:null,tokenBurnRate:null};let t=e.reduce((l,f)=>l+f.costUSD,0),n=e.reduce((l,f)=>l+f.usage.inputTokens+f.usage.outputTokens+f.usage.cacheCreationInputTokens+f.usage.cacheReadInputTokens,0),r=e.reduce((l,f)=>{let m=f.usage.inputTokens+f.usage.outputTokens+f.usage.cacheCreationInputTokens+f.usage.cacheReadInputTokens,u=vt(f.model);return l+m*u},0),s=new Date,i=null;if(e.length>0){let l=e[0];if(l){let f=this.sessionDurationHours*60*60*1e3,m=this.floorToHour(l.timestamp),u=new Date(m.getTime()+f);i=Math.max(0,Math.round((u.getTime()-s.getTime())/(1e3*60)));}}let a=null,c=null;if(e.length>=1&&(t>0||n>0)){let l=e.map(u=>u.timestamp).sort((u,d)=>u.getTime()-d.getTime()),f=l[0],m=l[l.length-1];if(f&&m){let u=(m.getTime()-f.getTime())/6e4;u>0&&(t>0&&(a=t/u*60),n>0&&(c=n/u*60));}}return g(`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 g("Error getting active block info:",e),{cost:null,tokens:null,weightedTokens:null,timeRemaining:null,burnRate:null,tokenBurnRate:null}}}};function L(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 Et(o){return o.inputTokens+o.outputTokens+o.cacheCreationInputTokens+o.cacheReadInputTokens}function $t(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{async loadTodayEntries(){let t=L(new Date);g(`Today segment: Loading entries for date ${t}`);let n=await k.getLatestTranscriptMtime(),r=await k.getUsageCache("today",n);if(r)return g("Using shared today usage cache"),r;let s=new Date;s.setDate(s.getDate()-1),s.setHours(0,0,0,0);let i=(u,d)=>d>=s,a=new Date;a.setHours(0,0,0,0);let l=await J(u=>u.timestamp>=a,i,true),f=[],m=0;for(let u of l)if(L(u.timestamp)===t&&u.message?.usage){let p=$t(u);!p.costUSD&&u.raw&&(p.costUSD=await v.calculateCostForEntry(u.raw)),f.push(p),m++;}return g(`Today segment: Found ${m} entries for today (${t})`),await k.setUsageCache("today",f,n),f}async getTodayEntries(){try{return await this.loadTodayEntries()}catch(e){return g("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:L(new Date)};let t=e.reduce((s,i)=>s+i.costUSD,0),n=e.reduce((s,i)=>s+Et(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 g(`Today segment: $${t.toFixed(2)}, ${n} tokens total`),{cost:t,tokens:n,tokenBreakdown:r,date:L(new Date)}}catch(e){return g("Error getting today's info:",e),{cost:null,tokens:null,tokenBreakdown:null,date:L(new Date)}}}};var Ve="\x1B[0m",Ye={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",bar_filled:"\u25AA",bar_empty:"\u25AB",env:"\u2699"},Je={right:"\uE0B0",left_rounded:"\uE0B6",right_rounded:"\uE0B4",branch:"~",model:"M",git_clean:"=",git_dirty:"*",git_conflicts:"!",git_ahead:"^",git_behind:"v",git_worktree:"W",git_tag:"T",git_sha:"#",git_upstream:">>",git_stash:"S",git_time:"@",session_cost:"S",block_cost:"B",today_cost:"D",context_time:"C",metrics_response:"R",metrics_last_response:"L",metrics_duration:"T",metrics_messages:"#",metrics_lines_added:"+",metrics_lines_removed:"-",metrics_burn:"~/h",version:"V",bar_filled:"=",bar_empty:"-",env:"$"};var Rt="\x1B",Bt=new RegExp(`${Rt}\\[[0-9;]*m`,"g"),Dt=/^[a-zA-Z0-9/]+$/;function At(){if(process.platform==="win32")return null;let o=process.pid.toString();for(let e=0;e<10;e++)try{let n=execSync(`ps -o ppid=,tty= -p ${o}`,{encoding:"utf8",stdio:["pipe","pipe","ignore"]}).trim().split(/\s+/),r=n[0],s=n[1];if(s&&s!=="?"&&s!=="??"&&Dt.test(s))return s;if(!r||r==="1"||r==="0")break;o=r;}catch{break}return null}function Ft(){try{let e=execSync("mode con",{encoding:"utf8",stdio:["pipe","pipe","ignore"],windowsHide:!0}).match(/Columns:\s*(\d+)/i);if(e?.[1]){let t=parseInt(e[1],10);if(!isNaN(t)&&t>0)return t}}catch{}return null}function Mt(){let o=At();if(o)try{let t=execSync(`stty size < /dev/${o}`,{encoding:"utf8",stdio:["pipe","pipe","ignore"],shell:"/bin/sh"}).trim().split(" ")[1];if(t){let n=parseInt(t,10);if(!isNaN(n)&&n>0)return n}}catch{}try{let e=execSync("tput cols 2>/dev/null",{encoding:"utf8",stdio:["pipe","pipe","ignore"]}).trim(),t=parseInt(e,10);if(!isNaN(t)&&t>0)return t}catch{}return null}function ze(){let o=n=>Math.floor(n*.8),e=process.env.COLUMNS;if(e){let n=parseInt(e,10);if(!isNaN(n)&&n>0)return o(n)}if(process.stdout.columns&&process.stdout.columns>0)return o(process.stdout.columns);if(process.platform==="win32"){let n=Ft();if(n)return o(n)}let t=Mt();return t?o(t):null}function Ut(o){return o.replace(Bt,"")}function qe(o){return Ut(o).length}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 A),this._usageProvider}get blockProvider(){return this._blockProvider||(this._blockProvider=new Z),this._blockProvider}get todayProvider(){return this._todayProvider||(this._todayProvider=new Q),this._todayProvider}get contextProvider(){return this._contextProvider||(this._contextProvider=new F(this.config)),this._contextProvider}get gitService(){return this._gitService||(this._gitService=new R),this._gitService}get tmuxService(){return this._tmuxService||(this._tmuxService=new B),this._tmuxService}get metricsProvider(){return this._metricsProvider||(this._metricsProvider=new M),this._metricsProvider}get segmentRenderer(){return this._segmentRenderer||(this._segmentRenderer=new U(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,i=this.config.display.lines.map(f=>f.segments.context).find(f=>f?.enabled)?.autocompactBuffer??33e3,a=this.needsSegmentInfo("context")?await this.contextProvider.getContextInfo(e,i):null,c=this.needsSegmentInfo("metrics")?await this.metricsProvider.getMetricsInfo(e.session_id,e):null;return this.config.display.autoWrap?this.generateAutoWrapStatusline(e,t,n,r,a,c):(await Promise.all(this.config.display.lines.map(f=>this.renderLine(f,e,t,n,r,a,c)))).filter(f=>f.length>0).join(`
8
- `)}async generateAutoWrapStatusline(e,t,n,r,s,i){let a=this.getThemeColors(),c=e.workspace?.current_dir||e.cwd||"/",l=ze(),f=[];for(let m of this.config.display.lines){let u=Object.entries(m.segments).filter(([b,y])=>y?.enabled).map(([b,y])=>({type:b,config:y})),d=[];for(let b of u){let y=await this.renderSegment(b,e,t,n,r,s,i,a,c);y&&d.push({type:b.type,text:y.text,bgColor:y.bgColor,fgColor:y.fgColor});}if(d.length===0)continue;if(!l||l<=0){f.push(this.buildLineFromSegments(d,a));continue}let p=[],h=0;for(let b of d){let y=this.calculateSegmentWidth(b,p.length===0);p.length>0&&h+y>l&&(f.push(this.buildLineFromSegments(p,a)),p=[],h=0),p.push(b),h+=y;}p.length>0&&f.push(this.buildLineFromSegments(p,a));}return f.join(`
9
- `)}calculateSegmentWidth(e,t){let n=this.config.display.style==="capsule",r=qe(e.text),i=(this.config.display.padding??1)*2;if(n){let c=2+i+(t?0:1);return r+c}let a=1+i;return r+a}buildLineFromSegments(e,t){let n=this.config.display.style==="capsule",r=t.reset;for(let s=0;s<e.length;s++){let i=e[s];if(!i)continue;let a=s===0,l=s===e.length-1?null:e[s+1];n&&!a&&(r+=" "),r+=this.formatSegment(i.bgColor,i.fgColor,i.text,l?.bgColor,t);}return r}async renderLine(e,t,n,r,s,i,a){let c=this.getThemeColors(),l=t.workspace?.current_dir||t.cwd||"/",f=Object.entries(e.segments).filter(([u,d])=>d?.enabled).map(([u,d])=>({type:u,config:d})),m=[];for(let u of f){let d=await this.renderSegment(u,t,n,r,s,i,a,c,l);d&&m.push({type:u.type,text:d.text,bgColor:d.bgColor,fgColor:d.fgColor});}return this.buildLineFromSegments(m,c)}async renderSegment(e,t,n,r,s,i,a,c,l){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,l):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):e.type==="env"?this.segmentRenderer.renderEnv(c,e.config):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=this.config.display.charset||"unicode",n=e==="minimal",r=e==="capsule",s=t==="text"?Je:Ye;return {right:n?"":r?s.right_rounded:s.right,left:r?s.left_rounded:"",branch:s.branch,model:s.model,git_clean:s.git_clean,git_dirty:s.git_dirty,git_conflicts:s.git_conflicts,git_ahead:s.git_ahead,git_behind:s.git_behind,git_worktree:s.git_worktree,git_tag:s.git_tag,git_sha:s.git_sha,git_upstream:s.git_upstream,git_stash:s.git_stash,git_time:s.git_time,session_cost:s.session_cost,block_cost:s.block_cost,today_cost:s.today_cost,context_time:s.context_time,metrics_response:s.metrics_response,metrics_last_response:s.metrics_last_response,metrics_duration:s.metrics_duration,metrics_messages:s.metrics_messages,metrics_lines_added:s.metrics_lines_added,metrics_lines_removed:s.metrics_lines_removed,metrics_burn:s.metrics_burn,version:s.version,bar_filled:s.bar_filled,bar_empty:s.bar_empty,env:s.env}}getThemeColors(){let e=this.config.theme,t,n=this.config.display.colorCompatibility||"auto",r=n==="auto"?j():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=W(e,r),t||(console.warn(`Built-in theme '${e}' not found, falling back to 'dark' theme`),t=W("dark",r));let s=W("dark",r),i=ye=>{let E=t[ye]||s[ye];return r==="none"?{bg:"",fg:""}:r==="ansi"?{bg:ae(E.bg,true),fg:ae(E.fg,false)}:r==="ansi256"?{bg:ie(E.bg,true),fg:ie(E.fg,false)}:{bg:se(E.bg,true),fg:se(E.fg,false)}},a=i("directory"),c=i("git"),l=i("model"),f=i("session"),m=i("block"),u=i("today"),d=i("tmux"),p=i("context"),h=i("contextWarning"),b=i("contextCritical"),y=i("metrics"),I=i("version"),be=i("env");return {reset:r==="none"?"":Ve,modeBg:a.bg,modeFg:a.fg,gitBg:c.bg,gitFg:c.fg,modelBg:l.bg,modelFg:l.fg,sessionBg:f.bg,sessionFg:f.fg,blockBg:m.bg,blockFg:m.fg,todayBg:u.bg,todayFg:u.fg,tmuxBg:d.bg,tmuxFg:d.fg,contextBg:p.bg,contextFg:p.fg,contextWarningBg:h.bg,contextWarningFg:h.fg,contextCriticalBg:b.bg,contextCriticalFg:b.fg,metricsBg:y.bg,metricsFg:y.fg,versionBg:I.bg,versionFg:I.fg,envBg:be.bg,envFg:be.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;case "env":return t.envBg;default:return t.modeBg}}formatSegment(e,t,n,r,s){let i=this.config.display.style==="capsule",a=" ".repeat(this.config.display.padding??1);if(i){let u=this.config.display.colorCompatibility||"auto",p=(u==="auto"?j():u)==="ansi",h=N(e,p),b=`${h}${this.symbols.left}${s.reset}`,y=`${e}${t}${a}${n}${a}${s.reset}`,I=`${h}${this.symbols.right}${s.reset}`;return `${b}${y}${I}`}let c=`${e}${t}${a}${n}${a}`,l=this.config.display.colorCompatibility||"auto",m=(l==="auto"?j():l)==="ansi";if(r){let u=N(e,m);c+=`${s.reset}${r}${u}${this.symbols.right}`;}else c+=`${s.reset}${N(e,m)}${this.symbols.right}${s.reset}`;return c}};var Xe={theme:"dark",display:{style:"minimal",charset:"unicode",colorCompatibility:"auto",autoWrap:true,padding:1,lines:[{segments:{directory:{enabled:true,style:"basename"},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,displayStyle:"text",autocompactBuffer:33e3},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","gruvbox","custom"].includes(o)}function he(o){return o==="minimal"||o==="powerline"||o==="capsule"}function Ke(o){return o==="unicode"||o==="text"}function re(o,e){for(let t=0;t<o.length;t++){let n=o[t];if(n===e&&t+1<o.length)return o[t+1];if(n?.startsWith(`${e}=`))return n.split("=")[1]}}function oe(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]=oe(s,r);}else t[n]=r;}return t}function Lt(o,e){return o?_.existsSync(o)?o:null:[...e?[C.join(e,".claude-powerline.json")]:[],C.join(process.cwd(),".claude-powerline.json"),C.join(de.homedir(),".claude","claude-powerline.json"),C.join(de.homedir(),".config","claude-powerline","config.json")].find(_.existsSync)||null}function It(o){try{let e=_.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 Ot(){let o={},e={},t=process.env.CLAUDE_POWERLINE_THEME;t&&pe(t)&&(o.theme=t);let n=process.env.CLAUDE_POWERLINE_STYLE;return n&&(he(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 Nt(){return process.env.CLAUDE_POWERLINE_CONFIG}function jt(o){let e={},t={},n=re(o,"--theme");n&&pe(n)&&(e.theme=n);let r=re(o,"--style");r&&(he(r)?t.style=r:(console.warn(`Invalid display style '${r}' from CLI argument, falling back to 'minimal'`),t.style="minimal"));let s=re(o,"--charset");return s&&(Ke(s)?t.charset=s:(console.warn(`Invalid charset '${s}' from CLI argument, falling back to 'unicode'`),t.charset="unicode")),Object.keys(t).length>0&&(e.display=t),e}function Wt(o=process.argv,e){let t=JSON.parse(JSON.stringify(Xe)),n=re(o,"--config")||Nt(),r=n?.startsWith("~")?n.replace("~",de.homedir()):n,s=Lt(r,e);if(s)try{let c=It(s);t=oe(t,c);}catch(c){console.warn(`Warning: ${c instanceof Error?c.message:String(c)}`);}t.display?.style&&!he(t.display.style)&&(console.warn(`Invalid display style '${t.display.style}' in config file, falling back to 'minimal'`),t.display.style="minimal"),t.display?.charset&&!Ke(t.display.charset)&&(console.warn(`Invalid charset '${t.display.charset}' in config file, falling back to 'unicode'`),t.display.charset="unicode"),t.theme&&!pe(t.theme)&&(console.warn(`Invalid theme '${t.theme}' in config file, falling back to 'dark'`),t.theme="dark");let i=Ot();t=oe(t,i);let a=jt(o);return t=oe(t,a),t}var Ze=Wt;function Qe(){console.log(`
2
+ import v from'process';import {json}from'stream/consumers';import X from'tty';import {exec,execSync}from'child_process';import {promisify}from'util';import S,{existsSync,readFileSync,createReadStream}from'fs';import _,{join,posix,dirname}from'path';import {get}from'https';import {URL}from'url';import Ae,{homedir}from'os';import {createHash}from'crypto';import {setTimeout}from'timers/promises';import {readdir,stat,readFile}from'fs/promises';import {createInterface}from'readline';function _e(n,e){if(e&&(n.toLowerCase()==="transparent"||n.toLowerCase()==="none"))return "\x1B[49m";let t=parseInt(n.slice(1,3),16),o=parseInt(n.slice(3,5),16),r=parseInt(n.slice(5,7),16);return `\x1B[${e?"48":"38"};2;${t};${o};${r}m`}function J(n,e=false){if(!n||n==="")return "";let t=n.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(n.includes("\x1B[")&&n.includes("m")){let o=n.match(/\[(\d+)m/);if(o&&o[1]){let r=parseInt(o[1],10);if(r>=40&&r<=47)return `\x1B[${r-10}m`;if(r>=100&&r<=107)return `\x1B[${r-10}m`}}return n.replace("48","38")}function q(){let{env:n}=v,e=true;n.NO_COLOR&&n.NO_COLOR!==""&&(e=false);let t=n.FORCE_COLOR;if(t&&t!=="")return t==="false"||t==="0"?"none":t==="true"||t==="1"?"ansi":t==="2"?"ansi256":t==="3"?"truecolor":"ansi";if(!e||n.TERM==="dumb")return "none";if(n.CI)return ["GITHUB_ACTIONS","GITEA_ACTIONS","CIRCLECI"].some(r=>r in n)?"truecolor":"ansi";if(n.COLORTERM==="truecolor"||["xterm-kitty","xterm-ghostty","wezterm","alacritty","foot","contour"].includes(n.TERM||""))return "truecolor";if(n.TERM_PROGRAM)switch(n.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(n.TERM||""))return "ansi256";if(/-truecolor$/i.test(n.TERM||""))return "truecolor";if(/^screen|^xterm|^vt100|^vt220|^rxvt|color|ansi|cygwin|linux/i.test(n.TERM||"")||n.COLORTERM)return "ansi";if(X?.WriteStream?.prototype?.hasColors)try{if(!X.WriteStream.prototype.hasColors())return "none";let s=X.WriteStream.prototype.hasColors(256);return X.WriteStream.prototype.hasColors(16777216)?"truecolor":s?"ansi256":"ansi"}catch{}return "ansi"}function xe(n,e){if(e&&(n.toLowerCase()==="transparent"||n.toLowerCase()==="none"))return "\x1B[49m";let t=parseInt(n.slice(1,3),16),o=parseInt(n.slice(3,5),16),r=parseInt(n.slice(5,7),16),i=((a,c,l)=>a===c&&c===l?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(l/255*5))(t,o,r);return `\x1B[${e?"48":"38"};5;${i}m`}function Se(n,e){if(e&&(n.toLowerCase()==="transparent"||n.toLowerCase()==="none"))return "\x1B[49m";if(e)return "";let t=parseInt(n.slice(1,3),16),o=parseInt(n.slice(3,5),16),r=parseInt(n.slice(5,7),16);return o>t&&o>r&&o>120?"\x1B[32m":t>o&&t>r&&t>120?"\x1B[31m":r>t&&r>o&&r>120?"\x1B[34m":(t+o+r)/3>150?"\x1B[37m":"\x1B[90m"}function We(n,e){let t=parseInt(n.slice(1,3),16),o=parseInt(n.slice(3,5),16),r=parseInt(n.slice(5,7),16),s=parseInt(e.slice(1,3),16),i=parseInt(e.slice(3,5),16),a=parseInt(e.slice(5,7),16);return Math.sqrt((t-s)**2+(o-i)**2+(r-a)**2)}var je={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"},contextWarning:{bg:"#92400e",fg:"#fbbf24"},contextCritical:{bg:"#991b1b",fg:"#fca5a5"},metrics:{bg:"#374151",fg:"#d1d5db"},version:{bg:"#3a3a4a",fg:"#b8b8d0"},env:{bg:"#2d2d3d",fg:"#d0a0d0"}},He={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"},contextWarning:{bg:"#af5f00",fg:"#ffaf00"},contextCritical:{bg:"#870000",fg:"#ff8787"},metrics:{bg:"#4e4e4e",fg:"#d0d0d0"},version:{bg:"#444444",fg:"#d7afff"},env:{bg:"#3a3a3a",fg:"#d787d7"}},Ge={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"},contextWarning:{bg:"#d75f00",fg:"#ffff00"},contextCritical:{bg:"#af0000",fg:"#ff0000"},metrics:{bg:"#666666",fg:"#ffffff"},version:{bg:"#585858",fg:"#af87ff"},env:{bg:"#444444",fg:"#ff87ff"}};var ze={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"},contextWarning:{bg:"#d97706",fg:"#ffffff"},contextCritical:{bg:"#dc2626",fg:"#ffffff"},metrics:{bg:"#6b7280",fg:"#ffffff"},version:{bg:"#8b7dd8",fg:"#ffffff"},env:{bg:"#d45dbf",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"},contextWarning:{bg:"#d78700",fg:"#ffffff"},contextCritical:{bg:"#d70000",fg:"#ffffff"},metrics:{bg:"#767676",fg:"#ffffff"},version:{bg:"#af87ff",fg:"#ffffff"},env:{bg:"#d787af",fg:"#ffffff"}},Ye={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"},contextWarning:{bg:"#d78700",fg:"#ffffff"},contextCritical:{bg:"#d70000",fg:"#ffffff"},metrics:{bg:"#767676",fg:"#ffffff"},version:{bg:"#af87ff",fg:"#ffffff"},env:{bg:"#d787af",fg:"#ffffff"}};var Xe={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"},contextWarning:{bg:"#d08770",fg:"#2e3440"},contextCritical:{bg:"#bf616a",fg:"#eceff4"},metrics:{bg:"#b48ead",fg:"#2e3440"},version:{bg:"#434c5e",fg:"#88c0d0"},env:{bg:"#3b4252",fg:"#b48ead"}},Je={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"},contextWarning:{bg:"#d7875f",fg:"#3a3a3a"},contextCritical:{bg:"#d75f5f",fg:"#ffffff"},metrics:{bg:"#d787af",fg:"#3a3a3a"},version:{bg:"#5f87af",fg:"#5fafaf"},env:{bg:"#4e4e4e",fg:"#d787af"}},qe={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"},contextWarning:{bg:"#d78700",fg:"#000000"},contextCritical:{bg:"#d75f5f",fg:"#ffffff"},metrics:{bg:"#ff87d7",fg:"#444444"},version:{bg:"#0087af",fg:"#00d7d7"},env:{bg:"#585858",fg:"#ff87af"}};var Ke={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"},contextWarning:{bg:"#ff9e64",fg:"#1a1b26"},contextCritical:{bg:"#f7768e",fg:"#1a1b26"},metrics:{bg:"#3d59a1",fg:"#c0caf5"},version:{bg:"#292e42",fg:"#bb9af7"},env:{bg:"#24283b",fg:"#fca7ea"}},Ze={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"},contextWarning:{bg:"#ffaf5f",fg:"#262626"},contextCritical:{bg:"#ff5f87",fg:"#262626"},metrics:{bg:"#5f5faf",fg:"#d7d7ff"},version:{bg:"#444460",fg:"#d787ff"},env:{bg:"#303050",fg:"#ff87ff"}},Qe={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"},contextWarning:{bg:"#ffaf00",fg:"#000000"},contextCritical:{bg:"#ff5f5f",fg:"#000000"},metrics:{bg:"#8787d7",fg:"#ffffff"},version:{bg:"#585870",fg:"#d787ff"},env:{bg:"#444470",fg:"#ff87ff"}};var et={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"},contextWarning:{bg:"#f6c177",fg:"#191724"},contextCritical:{bg:"#eb6f92",fg:"#191724"},metrics:{bg:"#524f67",fg:"#e0def4"},version:{bg:"#2a273f",fg:"#c4a7e7"},env:{bg:"#21202e",fg:"#eb6f92"}},tt={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"},contextWarning:{bg:"#d7af5f",fg:"#1c1c1c"},contextCritical:{bg:"#ff5f87",fg:"#1c1c1c"},metrics:{bg:"#767676",fg:"#e4e4e4"},version:{bg:"#4e4e4e",fg:"#d787d7"},env:{bg:"#303030",fg:"#ff5f87"}},nt={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"},contextWarning:{bg:"#d7af00",fg:"#000000"},contextCritical:{bg:"#ff5f5f",fg:"#000000"},metrics:{bg:"#a8a8a8",fg:"#000000"},version:{bg:"#666666",fg:"#ff87ff"},env:{bg:"#444444",fg:"#ff5f87"}};var ot={directory:{bg:"#504945",fg:"#ebdbb2"},git:{bg:"#3c3836",fg:"#b8bb26"},model:{bg:"#665c54",fg:"#83a598"},session:{bg:"#282828",fg:"#8ec07c"},block:{bg:"#3c3836",fg:"#83a598"},today:{bg:"#282828",fg:"#fabd2f"},tmux:{bg:"#282828",fg:"#fe8019"},context:{bg:"#458588",fg:"#ebdbb2"},contextWarning:{bg:"#d79921",fg:"#282828"},contextCritical:{bg:"#cc241d",fg:"#ebdbb2"},metrics:{bg:"#d3869b",fg:"#282828"},version:{bg:"#504945",fg:"#8ec07c"},env:{bg:"#3c3836",fg:"#d3869b"}},rt={directory:{bg:"#585858",fg:"#ffffaf"},git:{bg:"#444444",fg:"#afaf00"},model:{bg:"#6c6c6c",fg:"#87afaf"},session:{bg:"#303030",fg:"#87af87"},block:{bg:"#444444",fg:"#87afaf"},today:{bg:"#303030",fg:"#ffaf00"},tmux:{bg:"#303030",fg:"#ff8700"},context:{bg:"#5f8787",fg:"#ffffaf"},contextWarning:{bg:"#d7af00",fg:"#303030"},contextCritical:{bg:"#d70000",fg:"#ffffaf"},metrics:{bg:"#d787af",fg:"#303030"},version:{bg:"#585858",fg:"#87af87"},env:{bg:"#444444",fg:"#d787af"}},st={directory:{bg:"#808080",fg:"#ffff00"},git:{bg:"#585858",fg:"#00ff00"},model:{bg:"#808080",fg:"#00afff"},session:{bg:"#444444",fg:"#00d787"},block:{bg:"#585858",fg:"#00afff"},today:{bg:"#444444",fg:"#ffaf00"},tmux:{bg:"#444444",fg:"#ff8700"},context:{bg:"#008787",fg:"#ffffff"},contextWarning:{bg:"#d7af00",fg:"#000000"},contextCritical:{bg:"#d70000",fg:"#ffffff"},metrics:{bg:"#ff87af",fg:"#444444"},version:{bg:"#808080",fg:"#00d787"},env:{bg:"#585858",fg:"#ff87af"}};var we={dark:je,"dark-ansi256":He,"dark-ansi":Ge,light:ze,"light-ansi256":Ve,"light-ansi":Ye,nord:Xe,"nord-ansi256":Je,"nord-ansi":qe,"tokyo-night":Ke,"tokyo-night-ansi256":Ze,"tokyo-night-ansi":Qe,"rose-pine":et,"rose-pine-ansi256":tt,"rose-pine-ansi":nt,gruvbox:ot,"gruvbox-ansi256":rt,"gruvbox-ansi":st};function K(n,e){let t=we[n];if(!t)return null;if(e==="none"||e==="ansi"){let o=we[`${n}-ansi`];if(o)return o}if(e==="ansi256"){let o=we[`${n}-ansi256`];if(o)return o}return t}var f=(n,...e)=>{process.env.CLAUDE_POWERLINE_DEBUG&&console.error(`[DEBUG] ${n}`,...e);};var Lt=promisify(exec),O=class{isGitRepo(e){try{return S.existsSync(_.join(e,".git"))}catch{return false}}async execGitAsync(e,t){return Lt(e,{...t,env:{...process.env,GIT_OPTIONAL_LOCKS:"0"}})}async findGitRoot(e){try{return (await this.execGitAsync("git rev-parse --show-toplevel",{cwd:e,encoding:"utf8",timeout:2e3})).stdout.trim()||null}catch{return null}}async getGitInfo(e,t={},o){let r,s=this.isWorktree(e);if(s)r=e;else if(o&&this.isGitRepo(o))r=o;else if(this.isGitRepo(e))r=e;else {let i=await this.findGitRoot(e);if(!i)return null;r=i;}try{let i=await this.getStatusWithBranchAsync(r),a=await this.getAheadBehindAsync(r),c={branch:i.branch||"detached",status:i.status,ahead:a.ahead,behind:a.behind};t.showWorkingTree&&i.workingTree&&(c.staged=i.workingTree.staged,c.unstaged=i.workingTree.unstaged,c.untracked=i.workingTree.untracked,c.conflicts=i.workingTree.conflicts);let l={},g={};t.showSha&&(l.sha=this.getShaAsync(r)),t.showTag&&(l.tag=this.getNearestTagAsync(r)),t.showTimeSinceCommit&&(l.timeSinceCommit=this.getTimeSinceLastCommitAsync(r)),t.showStashCount&&(g.stashCount=this.getStashCountAsync(r)),t.showUpstream&&(g.upstream=this.getUpstreamAsync(r)),t.showRepoName&&(g.repoName=this.getRepoNameAsync(r));let u=new Map;for(let[m,d]of Object.entries(l))try{let p=await d;u.set(m,p);}catch{}return Object.keys(g).length>0&&(await Promise.allSettled(Object.entries(g).map(async([d,p])=>({key:d,value:await p})))).forEach(d=>{d.status==="fulfilled"&&u.set(d.value.key,d.value.value);}),t.showSha&&(c.sha=u.get("sha")||void 0),t.showOperation&&(c.operation=this.getOngoingOperation(r)||void 0),t.showTag&&(c.tag=u.get("tag")||void 0),t.showTimeSinceCommit&&(c.timeSinceCommit=u.get("timeSinceCommit")||void 0),t.showStashCount&&(c.stashCount=u.get("stashCount")||0),t.showUpstream&&(c.upstream=u.get("upstream")||void 0),t.showRepoName&&(c.repoName=u.get("repoName")||void 0,c.isWorktree=s),c}catch{return null}}async getShaAsync(e){try{return (await this.execGitAsync("git rev-parse --short=7 HEAD",{cwd:e,encoding:"utf8",timeout:2e3})).stdout.trim()||null}catch{return null}}resolveGitDir(e){let t=_.join(e,".git");if(S.existsSync(t)&&S.statSync(t).isFile()){let r=S.readFileSync(t,"utf-8").match(/^gitdir:\s*(.+)$/m);if(r?.[1])return _.resolve(e,r[1].trim())}return t}getOngoingOperation(e){try{let t=this.resolveGitDir(e);return S.existsSync(_.join(t,"MERGE_HEAD"))?"MERGE":S.existsSync(_.join(t,"CHERRY_PICK_HEAD"))?"CHERRY-PICK":S.existsSync(_.join(t,"REVERT_HEAD"))?"REVERT":S.existsSync(_.join(t,"BISECT_LOG"))?"BISECT":S.existsSync(_.join(t,"rebase-merge"))||S.existsSync(_.join(t,"rebase-apply"))?"REBASE":null}catch{return null}}async getNearestTagAsync(e){try{return (await this.execGitAsync("git describe --tags --abbrev=0",{cwd:e,encoding:"utf8",timeout:2e3})).stdout.trim()||null}catch{return null}}async getTimeSinceLastCommitAsync(e){try{let o=(await this.execGitAsync("git log -1 --format=%ct",{cwd:e,encoding:"utf8",timeout:2e3})).stdout.trim();if(!o)return null;let r=parseInt(o)*1e3,s=Date.now();return Math.floor((s-r)/1e3)}catch{return null}}async getStashCountAsync(e){try{let o=(await this.execGitAsync("git stash list",{cwd:e,encoding:"utf8",timeout:2e3})).stdout.trim();return o?o.split(`
3
+ `).length:0}catch{return 0}}async getUpstreamAsync(e){try{return (await this.execGitAsync("git rev-parse --abbrev-ref @{u}",{cwd:e,encoding:"utf8",timeout:2e3})).stdout.trim()||null}catch{return null}}async getRepoNameAsync(e){try{let o=(await this.execGitAsync("git config --get remote.origin.url",{cwd:e,encoding:"utf8",timeout:2e3})).stdout.trim();return o?o.match(/\/([^/]+?)(\.git)?$/)?.[1]||_.basename(e):_.basename(e)}catch{return _.basename(e)}}isWorktree(e){try{let t=_.join(e,".git");return !!(S.existsSync(t)&&S.statSync(t).isFile())}catch{return false}}async getStatusWithBranchAsync(e){try{f(`[GIT-EXEC] Running git status in ${e}`);let r=(await this.execGitAsync("git status --porcelain -b",{cwd:e,encoding:"utf8",timeout:2e3})).stdout.split(`
4
+ `),s=null,i="clean",a=0,c=0,l=0,g=0;for(let u of r)if(u){if(u.startsWith("## ")){let d=u.substring(3).split("...")[0];d&&d!=="HEAD (no branch)"&&(s=d);continue}if(u.length>=2){let m=u.charAt(0),d=u.charAt(1);if(m==="?"&&d==="?"){l++,i==="clean"&&(i="dirty");continue}let p=m+d;if(["DD","AU","UD","UA","DU","AA","UU"].includes(p)){g++,i="conflicts";continue}m!==" "&&m!=="?"&&(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:l,conflicts:g}}}catch(t){return f(`Git status with branch command failed in ${e}:`,t),{branch:await this.getFallbackBranch(e),status:"clean"}}}async getFallbackBranch(e){try{let o=(await this.execGitAsync("git branch --show-current",{cwd:e,encoding:"utf8",timeout:2e3})).stdout.trim();if(o)return o}catch{try{let o=(await this.execGitAsync("git symbolic-ref --short HEAD",{cwd:e,encoding:"utf8",timeout:2e3})).stdout.trim();if(o)return o}catch{return null}}return null}async getAheadBehindAsync(e){try{f(`[GIT-EXEC] Running git ahead/behind in ${e}`);let[t,o]=await Promise.all([this.execGitAsync("git rev-list --count @{u}..HEAD",{cwd:e,encoding:"utf8",timeout:2e3}),this.execGitAsync("git rev-list --count HEAD..@{u}",{cwd:e,encoding:"utf8",timeout:2e3})]);return {ahead:parseInt(t.stdout.trim())||0,behind:parseInt(o.stdout.trim())||0}}catch(t){return f(`Git ahead/behind command failed in ${e}:`,t),{ahead:0,behind:0}}}};var Nt=promisify(exec),N=class{async getSessionId(){try{if(!process.env.TMUX_PANE)return f("TMUX_PANE not set, not in tmux session"),null;f(`Getting tmux session ID, TMUX_PANE: ${process.env.TMUX_PANE}`);let t=(await Nt("tmux display-message -p '#S'",{encoding:"utf8",timeout:1e3})).stdout.trim();return f(`Tmux session ID: ${t||"empty"}`),t||null}catch(e){return f("Error getting tmux session ID:",e),null}}isInTmux(){return !!process.env.TMUX_PANE}};function Q(){let n=[],e=process.env.CLAUDE_CONFIG_DIR;if(e&&e.split(",").forEach(t=>{let o=t.trim();existsSync(o)&&n.push(o);}),n.length===0){let t=homedir(),o=join(t,".config","claude"),r=join(t,".claude");existsSync(o)&&n.push(o),existsSync(r)&&n.push(r);}return n}async function ee(n){let e=[];for(let t of n){let o=join(t,"projects");if(existsSync(o))try{let r=await readdir(o,{withFileTypes:!0});for(let s of r)if(s.isDirectory()){let i=posix.join(o,s.name);e.push(i);}}catch(r){f(`Failed to read projects directory ${o}:`,r);}}return e}async function te(n){let e=Q(),t=await ee(e);for(let o of t){let r=posix.join(o,`${n}.jsonl`);if(existsSync(r))return r}return null}async function lt(n,e){let t=[],o=posix.join(e,n,"subagents");try{let s=(await readdir(o)).filter(i=>i.startsWith("agent-")&&i.endsWith(".jsonl"));for(let i of s){let a=posix.join(o,i);try{let l=(await readFile(a,"utf-8")).split(`
5
+ `)[0];l&&JSON.parse(l).sessionId===n&&t.push(a);}catch{f(`Failed to check agent file ${a}`);}}}catch(r){f(`Failed to read subagents directory ${o}:`,r);}return t}async function ke(n){try{return (await stat(n)).mtime}catch{return null}}function Gt(n){let e=n.message?.id||(typeof n.raw.message=="object"&&n.raw.message!==null&&"id"in n.raw.message?n.raw.message.id:void 0),t="requestId"in n.raw?n.raw.requestId:void 0;return !e||!t?null:`${e}:${t}`}var zt=1024*1024;async function I(n){try{let t=(await stat(n)).size,o;return t>zt?(f(`Using streaming parser for large file ${n} (${Math.round(t/1024)}KB)`),o=await Yt(n)):o=await Vt(n),f(`Parsed ${o.length} entries from ${n}`),o}catch(e){return f(`Failed to read file ${n}:`,e),[]}}async function Vt(n){let t=(await readFile(n,"utf-8")).trim().split(`
6
+ `).filter(r=>r.trim()),o=[];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};o.push(i);}catch(s){f(`Failed to parse JSONL line: ${s}`);continue}return o}async function Yt(n){return new Promise((e,t)=>{let o=[],r=createReadStream(n,{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 l={timestamp:new Date(c.timestamp),message:c.message,costUSD:typeof c.costUSD=="number"?c.costUSD:void 0,isSidechain:c.isSidechain===!0,raw:c};o.push(l);}catch(c){f(`Failed to parse JSONL line: ${c}`);}}),s.on("close",()=>{e(o);}),s.on("error",i=>{f(`Streaming parser error for ${n}:`,i),t(i);}),r.on("error",i=>{f(`File stream error for ${n}:`,i),t(i);});})}async function it(n){try{let e=await ke(n);return e?{filePath:n,mtime:e}:null}catch{return null}}async function Xt(n,e){try{let t=await readdir(n,{withFileTypes:!0}),o=t.filter(a=>!a.isDirectory()&&a.name.endsWith(".jsonl")).map(a=>it(posix.join(n,a.name))),r=t.filter(a=>a.isDirectory()).map(async a=>{let c=posix.join(n,a.name,"subagents");try{return (await readdir(c)).filter(g=>g.startsWith("agent-")&&g.endsWith(".jsonl")).map(g=>it(posix.join(c,g)))}catch{return []}}),[s,i]=await Promise.all([Promise.all(o),Promise.all(r).then(a=>Promise.all(a.flat()))]);return [...s,...i].filter(a=>a!==null&&(!e||e(a.filePath,a.mtime)))}catch(t){return f(`Failed to read project directory ${n}:`,t),[]}}async function ne(n,e,t=false){let o=Q(),r=await ee(o),s=new Set,i=r.map(p=>Xt(p,e)),c=(await Promise.all(i)).flat().filter(p=>p!==null);t&&c.sort((p,h)=>h.mtime.getTime()-p.mtime.getTime());let l=c.map(p=>p.filePath),g=[],u=l.map(async p=>(await I(p)).filter(b=>!n||n(b))),m=await Promise.all(u);for(let p of m)g.push(...p);g.sort((p,h)=>p.timestamp.getTime()-h.timestamp.getTime());let d=[];for(let p of g){let h=Gt(p);h&&s.has(h)||(h&&s.add(h),d.push(p));}return d}var E=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(!S.existsSync(t))return false;try{let o=S.readFileSync(t,"utf-8"),r=parseInt(o.trim(),10);if(isNaN(r))return f(`Invalid PID in lock file ${e}, removing stale lock`),S.unlinkSync(t),!1;try{return process.kill(r,0),!0}catch(s){return s.code==="ESRCH"?(f(`Removing stale lock file ${e} for dead process ${r}`),S.unlinkSync(t),!1):(f(`Error checking process ${r} for lock ${e}:`,s),!0)}}catch(o){return f(`Error reading lock file ${e}:`,o),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 S.promises.writeFile(s,a,{flag:"wx"}),f(`Lock acquired for ${e}`),!0}catch(c){if(c.code==="EEXIST")await setTimeout(50);else throw c}return f(`Failed to acquire lock for ${e} within ${t}ms`),false}static async releaseLock(e){let t=_.join(this.LOCKS_DIR,e);try{await S.promises.unlink(t),f(`Lock released for ${e}`);}catch(o){o.code!=="ENOENT"&&f(`Error releasing lock for ${e}:`,o);}}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){f("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)){f(`Cache for ${e} is locked, waiting...`),await setTimeout(75);continue}try{let g=await S.promises.readFile(i,s),u=JSON.parse(g);return !t||u.timestamp>=t?(f(`[CACHE-HIT] ${e} disk cache: found`),this.deserializeDates(u.data)):(f(`${e} cache outdated: cache=${u.timestamp}, latest=${t}`),null)}catch(g){if(g.code==="ENOENT")return f(`No shared ${e} usage cache found`),null;let u=c+1;f(`Attempt ${u} failed to read ${e} cache: ${g.message}. Retrying...`),await setTimeout(75);}}return f(`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,o){let r=`${e}.usage.lock`;if(!await this.acquireLock(r)){f(`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=o||Date.now(),l=JSON.stringify({data:t,timestamp:a});await S.promises.writeFile(i,l,"utf-8"),f(`[CACHE-SET] ${e} disk cache stored`);}catch(i){f(`Failed to save ${e} usage cache:`,i);}finally{await this.releaseLock(r);}}static async getLatestTranscriptMtime(){try{let e=Q(),t=await ee(e),o=0;for(let r of t)try{let i=(await S.promises.readdir(r)).filter(a=>a.endsWith(".jsonl"));for(let a of i){let c=_.join(r,a),l=await ke(c);l&&l.getTime()>o&&(o=l.getTime());}}catch(s){f(`Failed to read project directory ${r}:`,s);continue}return o}catch(e){return f("Failed to get latest transcript mtime:",e),Date.now()}}};var oe={"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-haiku-4-5-20251001":{name:"Claude Haiku 4.5",input:1,output:5,cache_write_5m:1.25,cache_write_1h:2,cache_read:.1},"claude-haiku-4-5":{name:"Claude Haiku 4.5",input:1,output:5,cache_write_5m:1.25,cache_write_1h:2,cache_read:.1},"claude-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-sonnet-4-5":{name:"Claude Sonnet 4.5",input:3,output:15,cache_write_5m:3.75,cache_write_1h:6,cache_read:.3},"claude-sonnet-4-5-20250929":{name:"Claude Sonnet 4.5",input:3,output:15,cache_write_5m:3.75,cache_write_1h:6,cache_read:.3},"claude-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 E.getUsageCache("pricing",t)}static async saveDiskCache(e){await E.setUsageCache("pricing",e);}static async fetchPricingData(){return new Promise(e=>{let t=new URL(this.GITHUB_PRICING_URL),o=get({hostname:t.hostname,path:t.pathname,headers:{"User-Agent":"claude-powerline","Cache-Control":"no-cache"},timeout:5e3},r=>{if(r.statusCode!==200){f(`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){f("Response too large"),o.destroy(),e(null);return}s+=c;}),r.on("end",()=>{try{let l=JSON.parse(s),g=l._meta,u={};for(let[m,d]of Object.entries(l))m!=="_meta"&&(u[m]=d);this.validatePricingData(u)?(f(`Fetched fresh pricing from GitHub for ${Object.keys(u).length} models`),f(`Pricing last updated: ${g?.updated||"unknown"}`),e(u)):(f("Invalid pricing data structure"),e(null));}catch(c){f("Failed to parse JSON:",c),e(null);}}),r.on("error",c=>{f("Response error:",c),e(null);});});o.on("error",r=>{f("Request error:",r),e(null);}),o.on("timeout",()=>{f("Request timeout"),o.destroy(),e(null);}),o.end();})}static async getCurrentPricing(){if(this.executionCache!==null)return f(`[CACHE-HIT] Pricing execution cache: ${Object.keys(this.executionCache).length} models`),this.executionCache;let e=await this.loadDiskCache();if(e)return f(`[CACHE-HIT] Pricing disk cache: ${Object.keys(e).length} models`),this.executionCache=e,f(`[CACHE-SET] Pricing execution cache stored: ${Object.keys(e).length} models`),e;let t=await this.fetchPricingData();return t?(await this.saveDiskCache(t),f(`[CACHE-SET] Pricing disk cache stored: ${Object.keys(t).length} models`),this.executionCache=t,f(`[CACHE-SET] Pricing execution cache stored: ${Object.keys(t).length} models`),t):(f(`[CACHE-FALLBACK] Using offline pricing data: ${Object.keys(oe).length} models`),this.executionCache=oe,f(`[CACHE-SET] Pricing execution cache stored: ${Object.keys(oe).length} models`),oe)}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 o=t;if(typeof o.input!="number"||typeof o.output!="number"||typeof o.cache_read!="number")return false}return true}static async getModelPricing(e){if(this.modelPricingCache.has(e))return f(`[CACHE-HIT] Model pricing cache: ${e}`),this.modelPricingCache.get(e);let t=await this.getCurrentPricing(),o;return t[e]?o=t[e]:o=this.fuzzyMatchModel(e,t),this.modelPricingCache.set(e,o),f(`[CACHE-SET] Model pricing cache: ${e}`),o}static fuzzyMatchModel(e,t){let o=e.toLowerCase();for(let[s,i]of Object.entries(t))if(s.toLowerCase()===o)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.5","4-5-sonnet","sonnet-4-5"],fallback:"claude-sonnet-4-5-20250929"},{pattern:["sonnet-4","claude-sonnet-4"],fallback:"claude-sonnet-4-20250514"},{pattern:["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:["haiku-4.5","4-5-haiku","haiku-4-5"],fallback:"claude-haiku-4-5-20251001"},{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=>o.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 o=e.message?.usage;if(!o)return 0;let r=this.extractModelId(e),s=await this.getModelPricing(r),i=o.input_tokens||0,a=o.output_tokens||0,c=o.cache_creation_input_tokens||0,l=o.cache_read_input_tokens||0,g=i/1e6*s.input,u=a/1e6*s.output,m=l/1e6*s.cache_read,d=c/1e6*s.cache_write_5m;return g+u+d+m}static extractModelId(e){if(e.model&&typeof e.model=="string")return e.model;let t=e.message;if(t?.model){let o=t.model;return typeof o=="string"?o:o?.id||"claude-3-5-sonnet-20241022"}return e.model_id&&typeof e.model_id=="string"?e.model_id:"claude-3-5-sonnet-20241022"}};function en(n){return {timestamp:n.timestamp.toISOString(),message:{usage:{input_tokens:n.message?.usage?.input_tokens||0,output_tokens:n.message?.usage?.output_tokens||0,cache_creation_input_tokens:n.message?.usage?.cache_creation_input_tokens,cache_read_input_tokens:n.message?.usage?.cache_read_input_tokens}},costUSD:n.costUSD}}var re=class{async getSessionUsage(e){try{let t=await te(e);if(!t)return f(`No transcript found for session: ${e}`),null;f(`Found transcript at: ${t}`);let o=await I(t),r=dirname(t),s=await lt(e,r);f(`Found ${s.length} agent transcripts for session`);for(let c of s){let l=await I(c);o.push(...l);}if(o.length===0)return {totalCost:0,entries:[]};let i=[],a=0;for(let c of o)if(c.message?.usage){let l=en(c);if(l.costUSD!==void 0)a+=l.costUSD;else {let g=await R.calculateCostForEntry(c.raw);l.costUSD=g,a+=g;}i.push(l);}return f(`Parsed ${i.length} usage entries, total cost: $${a.toFixed(4)}`),{totalCost:a,entries:i}}catch(t){return f(`Error reading session usage for ${e}:`,t),null}}calculateTokenBreakdown(e){return e.reduce((t,o)=>({input:t.input+(o.message.usage.input_tokens||0),output:t.output+(o.message.usage.output_tokens||0),cacheCreation:t.cacheCreation+(o.message.usage.cache_creation_input_tokens||0),cacheRead:t.cacheRead+(o.message.usage.cache_read_input_tokens||0)}),{input:0,output:0,cacheCreation:0,cacheRead:0})}async getSessionInfo(e,t){let o=await this.getSessionUsage(e);if(!o||o.entries.length===0)return {cost:null,calculatedCost:null,officialCost:null,tokens:null,tokenBreakdown:null};let r=this.calculateTokenBreakdown(o.entries),s=r.input+r.output+r.cacheCreation+r.cacheRead,i=o.totalCost,a=t?.cost?.total_cost_usd??null;return {cost:i??a,calculatedCost:i,officialCost:a,tokens:s,tokenBreakdown:r}}},j=class{sessionProvider=new re;async getUsageInfo(e,t){try{return f(`Starting usage info retrieval for session: ${e}`),{session:await this.sessionProvider.getSessionInfo(e,t)}}catch(o){return f(`Error getting usage info for session ${e}:`,o),{session:{cost:null,calculatedCost:null,officialCost:null,tokens:null,tokenBreakdown:null}}}}};var H=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},o=this.getModelType(e);return t[o]||t.default||2e5}getModelType(e){let t=e.toLowerCase();return t.includes("sonnet")?"sonnet":t.includes("opus")?"opus":"default"}calculatePercentages(e,t,o=33e3){let r=Math.min(100,Math.max(0,Math.round(e/t*100))),s=Math.max(1,t-o),i=Math.min(100,Math.max(0,Math.round(e/s*100))),a=Math.max(0,100-i);return {percentage:r,usablePercentage:i,contextLeftPercentage:a,usableTokens:s}}calculateContextFromHookData(e,t=33e3){let o=e.context_window?.current_usage;if(!o)return f("No current_usage in hook data, falling back to transcript parsing"),null;let r=e.context_window?.context_window_size||2e5,s=(o.input_tokens||0)+(o.cache_creation_input_tokens||0)+(o.cache_read_input_tokens||0);f(`Native current_usage: input=${o.input_tokens}, cache_create=${o.cache_creation_input_tokens}, cache_read=${o.cache_read_input_tokens}, total=${s} (limit: ${r})`);let i=this.calculatePercentages(s,r,t);return {totalTokens:s,maxTokens:r,...i}}async calculateContextTokensFromTranscript(e,t,o=33e3){try{f(`Calculating context tokens from transcript: ${e}`);try{if(!readFileSync(e,"utf-8"))return f("Transcript file is empty"),null}catch{return f("Could not read transcript file"),null}let r=await I(e);if(r.length===0)return f("No entries in transcript"),null;let s=null;for(let i=r.length-1;i>=0;i--){let a=r[i];if(a&&a.message?.usage?.input_tokens&&a.isSidechain!==!0){s=a,f(`Context segment: Found most recent entry at ${a.timestamp.toISOString()}, stopping search`);break}}if(s?.message?.usage){let i=s.message.usage,a=(i.input_tokens||0)+(i.cache_read_input_tokens||0)+(i.cache_creation_input_tokens||0),c=t?this.getContextLimit(t):2e5;f(`Most recent main chain context: ${a} tokens (limit: ${c})`);let l=this.calculatePercentages(a,c,o);return {totalTokens:a,maxTokens:c,...l}}return f("No main chain entries with usage data found"),null}catch(r){return f(`Error reading transcript: ${r instanceof Error?r.message:String(r)}`),null}}async getContextInfo(e,t=33e3){let o=this.calculateContextFromHookData(e,t);return o||this.calculateContextTokensFromTranscript(e.transcript_path,e.model?.id,t)}};var G=class{async loadTranscriptEntries(e){try{let t=await te(e);if(!t)return f(`No transcript found for session: ${e}`),[];f(`Loading transcript from: ${t}`);let r=(await readFile(t,"utf-8")).trim().split(`
7
+ `).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){f(`Failed to parse JSONL line: ${a}`);continue}return f(`Loaded ${s.length} transcript entries`),s}catch(t){return f(`Error loading transcript for ${e}:`,t),[]}}calculateMessageCount(e){return e.filter(t=>{let o=t.type||t.message?.role||t.message?.type,r=t.type==="user"&&t.message?.content?.[0]?.type==="tool_result";return o==="user"&&!r}).length}calculateLastResponseTime(e){if(e.length===0)return null;let t=e.slice(-20),o=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)o=i;else if(a==="assistant"&&o){let g=(i.getTime()-o.getTime())/1e3;g>.1&&g<300&&(r=g);}}catch{continue}return r}async getMetricsInfo(e,t){try{if(f(`Getting metrics from hook data for session: ${e}`),!t.cost)return f("No cost data available in hook data"),{responseTime:null,lastResponseTime:null,sessionDuration:null,messageCount:null,linesAdded:null,linesRemoved:null};let o=await this.loadTranscriptEntries(e),r=this.calculateMessageCount(o),s=this.calculateLastResponseTime(o);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(o){return f(`Error getting metrics from hook data for session ${e}:`,o),{responseTime:null,lastResponseTime:null,sessionDuration:null,messageCount:null,linesAdded:null,linesRemoved:null}}}};function k(n){return n===null?"$0.00":n<.01?"<$0.01":`$${n.toFixed(2)}`}function T(n){return n===null||n===0?"0 tokens":n>=1e6?`${(n/1e6).toFixed(1)}M tokens`:n>=1e3?`${(n/1e3).toFixed(1)}K tokens`:`${n} tokens`}function gt(n){if(!n)return "0 tokens";let e=[];if(n.input>0&&e.push(`${T(n.input).replace(" tokens","")} in`),n.output>0&&e.push(`${T(n.output).replace(" tokens","")} out`),n.cacheCreation>0||n.cacheRead>0){let t=n.cacheCreation+n.cacheRead;e.push(`${T(t).replace(" tokens","")} cached`);}return e.length>0?e.join(" + "):"0 tokens"}function ft(n){return n<60?`${n}s`:n<3600?`${Math.floor(n/60)}m`:n<86400?`${Math.floor(n/3600)}h`:n<604800?`${Math.floor(n/86400)}d`:`${Math.floor(n/604800)}w`}function se(n){return n<60?`${n.toFixed(0)}s`:n<3600?`${(n/60).toFixed(0)}m`:n<86400?`${(n/3600).toFixed(1)}h`:`${(n/86400).toFixed(1)}d`}var on=/^(?:(?:global|apac|au|eu|us|us-east-\d|us-west-\d|eu-west-\d|eu-central-\d)\.)?(?:anthropic\.|azure_ai\/|bedrock\/|vertex_ai\/)?claude-(?:(?<family>opus|sonnet|haiku)-(?<newMajor>\d+)(?:-(?<newMinor>\d))?|(?<oldMajor>\d+)(?:-(?<oldMinor>\d))?-(?<oldFamily>opus|sonnet|haiku))(?:[-@]\d{8})?(?:-v\d+:\d+)?(?:-latest)?$/i;function ie(n){if(!n)return "Claude";let e=n.trim().match(on);if(!e?.groups)return n;let{family:t,newMajor:o,newMinor:r,oldMajor:s,oldMinor:i,oldFamily:a}=e.groups,c=t||a,l=o||s,g=r||i;if(c&&l){let u=c.charAt(0).toUpperCase()+c.slice(1).toLowerCase(),m=g?`${l}.${g}`:l;return `${u} ${m}`}return n}function ae(n){let e=n.includes("/")?"/":"\\",t=n.split(e);return t.map((o,r)=>r===t.length-1||o==="~"||o===""?o:o.charAt(0)).join(e)}function ut(n){return n<60?`${n.toFixed(1)}s`:`${(n/60).toFixed(1)}m`}function mt(n){let e=Math.floor(n/60),t=n%60;return e>0?`${e}h ${t}m left`:`${t}m left`}function rn(n,e){return !e||e<=0||n<0?null:Math.min(100,n/e*100)}function D(n,e,t=80){let o=rn(n,e);if(o===null)return {percentage:null,isWarning:false,displayText:""};let r=`${o.toFixed(0)}%`,s=o>=t,i="";return s?i=` !${r}`:o>=50?i=` +${r}`:i=` ${r}`,{percentage:o,isWarning:s,displayText:i}}var sn={ball:{filled:"\u2500",empty:"\u2500",marker:"\u25CF"},blocks:{filled:"\u2588",empty:"\u2591"},"blocks-line":{filled:"\u2588",empty:"\u2500"},capped:{filled:"\u2501",empty:"\u2504",cap:"\u2578"},dots:{filled:"\u25CF",empty:"\u25CB"},filled:{filled:"\u25A0",empty:"\u25A1"},geometric:{filled:"\u25B0",empty:"\u25B1"},line:{filled:"\u2501",empty:"\u2504"},squares:{filled:"\u25FC",empty:"\u25FB"}},z=class{constructor(e,t){this.config=e;this.symbols=t;}renderDirectory(e,t,o){let r=e.workspace?.current_dir||e.cwd||"/",s=e.workspace?.project_dir,i=o?.style??(o?.showBasename?"basename":"full");if(i==="basename")return {text:_.basename(r)||"root",bgColor:t.modeBg,fgColor:t.modeFg};let a=process.env.HOME||process.env.USERPROFILE,c=r,l=s;a&&(r.startsWith(a)&&(c=r.replace(a,"~")),s&&s.startsWith(a)&&(l=s.replace(a,"~")));let g=this.getDisplayDirectoryName(c,l);return i==="fish"&&(g=ae(g)),{text:g,bgColor:t.modeBg,fgColor:t.modeFg}}renderGit(e,t,o){if(!e)return null;let r=[];if(o?.showRepoName&&e.repoName&&(r.push(e.repoName),e.isWorktree&&r.push(this.symbols.git_worktree)),o?.showOperation&&e.operation&&r.push(`[${e.operation}]`),r.push(`${this.symbols.branch} ${e.branch}`),o?.showTag&&e.tag&&r.push(`${this.symbols.git_tag} ${e.tag}`),o?.showSha&&e.sha&&r.push(`${this.symbols.git_sha} ${e.sha}`),o?.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}`)),o?.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(o?.showUpstream&&e.upstream&&r.push(`${this.symbols.git_upstream}${e.upstream}`),o?.showStashCount&&e.stashCount&&e.stashCount>0&&r.push(`${this.symbols.git_stash} ${e.stashCount}`),o?.showTimeSinceCommit&&e.timeSinceCommit!==void 0){let i=ft(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 o=e.model?.display_name||"Claude",r=ie(o);return {text:`${this.symbols.model} ${r}`,bgColor:t.modelBg,fgColor:t.modelFg}}renderSession(e,t,o){let r=o?.type||"cost",s=o?.costSource,i=this.config.budget?.session,a=()=>s==="calculated"?e.session.calculatedCost:s==="official"?e.session.officialCost:e.session.cost,c=this.formatUsageWithBudget(a(),e.session.tokens,e.session.tokenBreakdown,r,i?.amount,i?.warningThreshold||80,i?.type);return {text:`${this.symbols.session_cost} ${c}`,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,o){let s=o?.displayStyle??"text",i=s==="text"?"remaining":"used",a=o?.percentageMode??i,c=s==="bar"?{filled:this.symbols.bar_filled,empty:this.symbols.bar_empty}:sn[s]??null,l=a==="remaining"?"100%":"0%";if(!e)return c?{text:`${c.empty.repeat(10)} ${l}`,bgColor:t.contextBg,fgColor:t.contextFg}:{text:`${this.symbols.context_time} 0 (${l})`,bgColor:t.contextBg,fgColor:t.contextFg};let g=t.contextBg,u=t.contextFg;e.contextLeftPercentage<=20?(g=t.contextCriticalBg,u=t.contextCriticalFg):e.contextLeftPercentage<=40&&(g=t.contextWarningBg,u=t.contextWarningFg);let m=a==="remaining"?e.contextLeftPercentage:e.usablePercentage,d=Math.round(e.usablePercentage/100*10),p=10-d;if(c){let b=this.buildBar(c,d,p,10);return {text:o?.showPercentageOnly?`${b} ${m}%`:`${b} ${e.totalTokens.toLocaleString()} (${m}%)`,bgColor:g,fgColor:u}}return {text:o?.showPercentageOnly?`${this.symbols.context_time} ${m}%`:`${this.symbols.context_time} ${e.totalTokens.toLocaleString()} (${m}%)`,bgColor:g,fgColor:u}}buildBar(e,t,o,r){if(e.marker){let s=Math.min(t,r-1);return e.filled.repeat(s)+e.marker+e.empty.repeat(r-s-1)}return e.cap?t===0?e.cap+e.empty.repeat(r-1):t>=r?e.filled.repeat(r):e.filled.repeat(t-1)+e.cap+e.empty.repeat(o):e.filled.repeat(t)+e.empty.repeat(o)}renderMetrics(e,t,o,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=se(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,o){let r;if(e.cost===null&&e.tokens===null)r="No active block";else {let s=o?.type||"cost",i=o?.burnType,a=this.config.budget?.block,c=e.timeRemaining!==null?(()=>{let u=Math.floor(e.timeRemaining/60),m=e.timeRemaining%60;return u>0?`${u}h ${m}m`:`${m}m`})():null,l;switch(s){case "cost":l=this.formatUsageWithBudget(e.cost,null,null,"cost",a?.amount,a?.warningThreshold,a?.type);break;case "tokens":l=this.formatUsageWithBudget(null,e.tokens,null,"tokens",a?.amount,a?.warningThreshold,a?.type);break;case "weighted":let u=a?.type==="tokens"?a.amount:void 0,m=T(e.weightedTokens);if(u&&e.weightedTokens!==null){let d=D(e.weightedTokens,u,a?.warningThreshold||80);l=`${m}${d.displayText}`;}else l=`${m} (weighted)`;break;case "both":l=this.formatUsageWithBudget(e.cost,e.tokens,null,"both",a?.amount,a?.warningThreshold,a?.type);break;case "time":l=c||"N/A";break;default:l=this.formatUsageWithBudget(e.cost,null,null,"cost",a?.amount,a?.warningThreshold,a?.type);}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?`${T(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",p=e.tokenBurnRate!==null?`${T(Math.round(e.tokenBurnRate))}/h`:"N/A";g=` | ${d} / ${p}`;break}s==="time"?r=l:r=c?`${l}${g} (${c} left)`:`${l}${g}`;}return {text:`${this.symbols.block_cost} ${r}`,bgColor:t.blockBg,fgColor:t.blockFg}}renderToday(e,t,o="cost"){let r=this.config.budget?.today;return {text:`${this.symbols.today_cost} ${this.formatUsageWithBudget(e.cost,e.tokens,e.tokenBreakdown,o,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":e}formatUsageDisplay(e,t,o,r){switch(r){case "cost":return k(e);case "tokens":return T(t);case "both":return `${k(e)} (${T(t)})`;case "breakdown":return gt(o);default:return k(e)}}formatUsageWithBudget(e,t,o,r,s,i=80,a){let c=this.formatUsageDisplay(e,t,o,r);if(s&&s>0){let l=null;if(a==="tokens"&&t!==null?l=t:(a==="cost"&&e!==null||!a&&e!==null)&&(l=e),l!==null){let g=D(l,s,i);return c+g.displayText}}return c}renderVersion(e,t,o){return e.version?{text:`${this.symbols.version} v${e.version}`,bgColor:t.versionBg,fgColor:t.versionFg}:null}renderEnv(e,t){let o=process.env[t.variable];if(!o)return null;let r=t.prefix??t.variable;return {text:r?`${this.symbols.env} ${r}: ${o}`:`${this.symbols.env} ${o}`,bgColor:e.envBg,fgColor:e.envFg}}};function an(n){return n.includes("opus")?5:(n.includes("sonnet")||n.includes("haiku"),1)}function cn(n){return {timestamp:n.timestamp,usage:{inputTokens:n.message?.usage?.input_tokens||0,outputTokens:n.message?.usage?.output_tokens||0,cacheCreationInputTokens:n.message?.usage?.cache_creation_input_tokens||0,cacheReadInputTokens:n.message?.usage?.cache_read_input_tokens||0},costUSD:n.costUSD||0,model:n.message?.model||"unknown"}}var ce=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,o=[],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 l=c.getTime()-s.getTime(),g=i[i.length-1];if(g==null)continue;let u=g.timestamp,m=c.getTime()-u.getTime();l>t||m>t?(o.push(i),s=this.floorToHour(c),i=[a]):i.push(a);}}return s!=null&&i.length>0&&o.push(i),o}createBlockInfo(e,t){let o=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=o.getTime()-a.getTime()<r&&o<s;return {block:t,isActive:c}}findActiveBlock(e){for(let t=e.length-1;t>=0;t--){let o=e[t];if(!o||o.length===0)continue;let r=o[0];if(!r)continue;let s=this.floorToHour(r.timestamp),i=this.createBlockInfo(s,o);if(i.isActive)return i.block}return null}async loadUsageEntries(){try{f("Block segment: Loading entries for dynamic session blocks");let e=new Date;e.setDate(e.getDate()-1);let o=await ne(void 0,(c,l)=>l>=e,!0),r=[];for(let c of o)if(c.message?.usage){let l=cn(c);!l.costUSD&&c.raw&&(l.costUSD=await R.calculateCostForEntry(c.raw)),r.push(l);}let s=this.identifySessionBlocks(r);f(`Block segment: Found ${s.length} session blocks`);let i=this.findActiveBlock(s),a=[];if(i&&i.length>0){f(`Block segment: Found active block with ${i.length} entries`);let c=i[0],l=i[i.length-1];c&&l&&f(`Block segment: Active block from ${c.timestamp.toISOString()} to ${l.timestamp.toISOString()}`),a=i;}else f("Block segment: No active block found"),a=[];return a}catch(e){return f("Error loading block entries:",e),[]}}async getActiveBlockInfo(){try{let e=await this.loadUsageEntries();if(e.length===0)return f("Block segment: No entries in current block"),{cost:null,tokens:null,weightedTokens:null,timeRemaining:null,burnRate:null,tokenBurnRate:null};let t=e.reduce((l,g)=>l+g.costUSD,0),o=e.reduce((l,g)=>l+g.usage.inputTokens+g.usage.outputTokens+g.usage.cacheCreationInputTokens+g.usage.cacheReadInputTokens,0),r=e.reduce((l,g)=>{let u=g.usage.inputTokens+g.usage.outputTokens+g.usage.cacheCreationInputTokens+g.usage.cacheReadInputTokens,m=an(g.model);return l+u*m},0),s=new Date,i=null;if(e.length>0){let l=e[0];if(l){let g=this.sessionDurationHours*60*60*1e3,u=this.floorToHour(l.timestamp),m=new Date(u.getTime()+g);i=Math.max(0,Math.round((m.getTime()-s.getTime())/(1e3*60)));}}let a=null,c=null;if(e.length>=1&&(t>0||o>0)){let l=e.map(m=>m.timestamp).sort((m,d)=>m.getTime()-d.getTime()),g=l[0],u=l[l.length-1];if(g&&u){let m=(u.getTime()-g.getTime())/6e4;m>0&&(t>0&&(a=t/m*60),o>0&&(c=o/m*60));}}return f(`Block segment: $${t.toFixed(2)}, ${o} tokens, ${i}m remaining, burn rate: ${a?"$"+a.toFixed(2)+"/hr":"N/A"}`),{cost:t,tokens:o,weightedTokens:r,timeRemaining:i,burnRate:a,tokenBurnRate:c}}catch(e){return f("Error getting active block info:",e),{cost:null,tokens:null,weightedTokens:null,timeRemaining:null,burnRate:null,tokenBurnRate:null}}}};function V(n){let e=n.getFullYear(),t=String(n.getMonth()+1).padStart(2,"0"),o=String(n.getDate()).padStart(2,"0");return `${e}-${t}-${o}`}function ln(n){return n.inputTokens+n.outputTokens+n.cacheCreationInputTokens+n.cacheReadInputTokens}function gn(n){return {timestamp:n.timestamp,usage:{inputTokens:n.message?.usage?.input_tokens||0,outputTokens:n.message?.usage?.output_tokens||0,cacheCreationInputTokens:n.message?.usage?.cache_creation_input_tokens||0,cacheReadInputTokens:n.message?.usage?.cache_read_input_tokens||0},costUSD:n.costUSD||0,model:n.message?.model||"unknown"}}var le=class{async loadTodayEntries(){let t=V(new Date);f(`Today segment: Loading entries for date ${t}`);let o=await E.getLatestTranscriptMtime(),r=await E.getUsageCache("today",o);if(r)return f("Using shared today usage cache"),r;let s=new Date;s.setDate(s.getDate()-1),s.setHours(0,0,0,0);let i=(m,d)=>d>=s,a=new Date;a.setHours(0,0,0,0);let l=await ne(m=>m.timestamp>=a,i,true),g=[],u=0;for(let m of l)if(V(m.timestamp)===t&&m.message?.usage){let p=gn(m);!p.costUSD&&m.raw&&(p.costUSD=await R.calculateCostForEntry(m.raw)),g.push(p),u++;}return f(`Today segment: Found ${u} entries for today (${t})`),await E.setUsageCache("today",g,o),g}async getTodayEntries(){try{return await this.loadTodayEntries()}catch(e){return f("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:V(new Date)};let t=e.reduce((s,i)=>s+i.costUSD,0),o=e.reduce((s,i)=>s+ln(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 f(`Today segment: $${t.toFixed(2)}, ${o} tokens total`),{cost:t,tokens:o,tokenBreakdown:r,date:V(new Date)}}catch(e){return f("Error getting today's info:",e),{cost:null,tokens:null,tokenBreakdown:null,date:V(new Date)}}}};var pt="\x1B[0m",ge={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:"\u25C6",metrics_lines_added:"+",metrics_lines_removed:"-",metrics_burn:"\u2197",version:"\u25C8",bar_filled:"\u25AA",bar_empty:"\u25AB",env:"\u2699"},ht={topLeft:"\u256D",topRight:"\u256E",bottomLeft:"\u2570",bottomRight:"\u256F",horizontal:"\u2500",vertical:"\u2502",teeLeft:"\u251C",teeRight:"\u2524"},bt={topLeft:"+",topRight:"+",bottomLeft:"+",bottomRight:"+",horizontal:"-",vertical:"|",teeLeft:"+",teeRight:"+"},fe={right:"\uE0B0",left_rounded:"\uE0B6",right_rounded:"\uE0B4",branch:"~",model:"M",git_clean:"=",git_dirty:"*",git_conflicts:"!",git_ahead:"^",git_behind:"v",git_worktree:"W",git_tag:"T",git_sha:"#",git_upstream:">>",git_stash:"S",git_time:"@",session_cost:"S",block_cost:"B",today_cost:"D",context_time:"C",metrics_response:"R",metrics_last_response:"L",metrics_duration:"T",metrics_messages:"#",metrics_lines_added:"+",metrics_lines_removed:"-",metrics_burn:"~/h",version:"V",bar_filled:"=",bar_empty:"-",env:"$"};var fn="\x1B",un=new RegExp(`${fn}\\[[0-9;]*m`,"g"),mn=/^[a-zA-Z0-9/]+$/;function dn(){if(process.platform==="win32")return null;let n=process.pid.toString();for(let e=0;e<10;e++)try{let o=execSync(`ps -o ppid=,tty= -p ${n}`,{encoding:"utf8",stdio:["pipe","pipe","ignore"]}).trim().split(/\s+/),r=o[0],s=o[1];if(s&&s!=="?"&&s!=="??"&&mn.test(s))return s;if(!r||r==="1"||r==="0")break;n=r;}catch{break}return null}function pn(){try{let e=execSync("mode con",{encoding:"utf8",stdio:["pipe","pipe","ignore"],windowsHide:!0}).match(/Columns:\s*(\d+)/i);if(e?.[1]){let t=parseInt(e[1],10);if(!isNaN(t)&&t>0)return t}}catch{}return null}function hn(){let n=dn();if(n)try{let t=execSync(`stty size < /dev/${n}`,{encoding:"utf8",stdio:["pipe","pipe","ignore"],shell:"/bin/sh"}).trim().split(" ")[1];if(t){let o=parseInt(t,10);if(!isNaN(o)&&o>0)return o}}catch{}try{let e=execSync("tput cols 2>/dev/null",{encoding:"utf8",stdio:["pipe","pipe","ignore"]}).trim(),t=parseInt(e,10);if(!isNaN(t)&&t>0)return t}catch{}return null}function $e(){let n=o=>Math.floor(o*.7),e=process.env.COLUMNS;if(e){let o=parseInt(e,10);if(!isNaN(o)&&o>0)return n(o)}if(process.stdout.columns&&process.stdout.columns>0)return n(process.stdout.columns);if(process.platform==="win32"){let o=pn();if(o)return n(o)}let t=hn();return t?n(t):null}function Pe(n){return n.replace(un,"")}function F(n){return Pe(n).length}function y(n,e,t){return e?`${e}${n}${t}`:n}function bn(n,e){let t=F(n);return t>=e?n:n+" ".repeat(e-t)}var yt="\x1B",yn=new RegExp(`(${yt}\\[[0-9;]*m)`);function Cn(n,e){if(Pe(n).length<=e)return n;let t=0,o="",r=n.split(yn);for(let s of r){if(s.startsWith(yt)){o+=s;continue}for(let i of s){if(t>=e-1)return o+="\u2026",o;o+=i,t++;}}return o}function x(n,e,t){let o=t-2,r=Cn(e,o),s=bn(r,o);return n.vertical+" "+s+" "+n.vertical}function Y(n,e){return n.teeLeft+n.horizontal.repeat(e)+n.teeRight}function Ct(n,e){return n.bottomLeft+n.horizontal.repeat(e)+n.bottomRight}function _t(n,e){if(n.length===0)return "";if(n.length===1)return n[0]??"";let t=n.map(l=>F(l)),o=t.reduce((l,g)=>l+g,0),r=e-o,s=Math.max(2,Math.floor(r/(n.length-1))),i=new Array(n.length);i[n.length-1]=t[n.length-1]??0;for(let l=n.length-2;l>=0;l--)i[l]=(i[l+1]??0)+(t[l]??0);let a=n[0]??"",c=t[0]??0;for(let l=1;l<n.length;l++){let g=e-c-(i[l]??0)-(n.length-1-l)*2,u=Math.max(2,Math.min(s,g));a+=" ".repeat(u)+(n[l]??""),c+=u+(t[l]??0);}return a}function A(n,e,t){if(!e)return n;if(!n)return e;let o=F(n),r=F(e),s=t-o-r;return s<2?`${n} ${e}`:n+" ".repeat(s)+e}function xt(n,e,t){let o=n.hookData.model?.display_name||"Claude",r=ie(o).toLowerCase(),s="claude-powerline",i=` ${r} `,a=` ${s} `,c=t-1-i.length-a.length;if(c<2){let l=t-1-i.length;return e.topLeft+e.horizontal+i+e.horizontal.repeat(Math.max(0,l))+e.topRight}return e.topLeft+e.horizontal+i+e.horizontal.repeat(c)+a+e.topRight}function St(n,e,t,o,r){let s=Math.min(Math.floor(e*.45),40);if(!n.contextInfo)return null;let i=n.contextInfo.usablePercentage,a=Math.round(i/100*s),c=s-a,l=t.bar_filled.repeat(a)+t.bar_empty.repeat(c),g=n.contextInfo.totalTokens>=1e3?`${(n.contextInfo.totalTokens/1e3).toFixed(0)}k`:`${n.contextInfo.totalTokens}`,u=n.contextInfo.maxTokens>=1e3?`${(n.contextInfo.maxTokens/1e3).toFixed(0)}k`:`${n.contextInfo.maxTokens}`,m=r.contextFg;return i>=80?m=r.contextCriticalFg:i>=60&&(m=r.contextWarningFg),y(`${l} ${i}% ${g}/${u}`,m,o)}function _n(n){let e=n.workspace?.current_dir||n.cwd||"/",t=process.env.HOME||process.env.USERPROFILE;return t&&e.startsWith(t)?e.replace(t,"~"):e}function wt(n,e,t,o,r){let s=[];n.blockInfo&&s.push(y(pe(n.blockInfo,e,t),r.blockFg,o)),n.usageInfo&&s.push(y(Re(n.usageInfo,e,t),r.sessionFg,o)),n.todayInfo&&s.push(y(Be(n.todayInfo,e,t),r.todayFg,o));let i=Ee(n,e);return i.length>0&&s.push(y(i.join(" \xB7 "),r.metricsFg,o)),s}function Ee(n,e){let t=[];return n.metricsInfo&&(n.metricsInfo.sessionDuration!==null&&n.metricsInfo.sessionDuration>0&&t.push(`${e.metrics_duration} ${se(n.metricsInfo.sessionDuration)}`),n.metricsInfo.messageCount!==null&&n.metricsInfo.messageCount>0&&t.push(`${e.metrics_messages} ${n.metricsInfo.messageCount}`)),t}function me(n,e,t,o){let r=[];if(n.gitInfo){let i=`${e.branch} ${n.gitInfo.branch}`;n.gitInfo.status==="conflicts"?i+=` ${e.git_conflicts}`:n.gitInfo.status==="dirty"?i+=` ${e.git_dirty}`:i+=` ${e.git_clean}`,n.gitInfo.ahead>0&&(i+=` ${e.git_ahead}${n.gitInfo.ahead}`),n.gitInfo.behind>0&&(i+=` ${e.git_behind}${n.gitInfo.behind}`);let a=[];n.gitInfo.staged&&n.gitInfo.staged>0&&a.push(`+${n.gitInfo.staged}`),n.gitInfo.unstaged&&n.gitInfo.unstaged>0&&a.push(`~${n.gitInfo.unstaged}`),n.gitInfo.untracked&&n.gitInfo.untracked>0&&a.push(`?${n.gitInfo.untracked}`),a.length>0&&(i+=` (${a.join(" ")})`),r.push(y(i,o.gitFg,t));}let s=ae(_n(n.hookData));return r.push(y(s,o.modeFg,t)),r}function de(n,e,t,o,r){let s=[];if(n.hookData.version&&s.push(y(`${e.version} v${n.hookData.version}`,r.versionFg,o)),n.tmuxSessionId&&s.push(y(`tmux:${n.tmuxSessionId}`,r.tmuxFg,o)),n.metricsInfo){let a=[];if(n.metricsInfo.responseTime!==null&&!isNaN(n.metricsInfo.responseTime)&&n.metricsInfo.responseTime>0&&a.push(`${e.metrics_response} ${ut(n.metricsInfo.responseTime)}`),n.metricsInfo.linesAdded!==null&&n.metricsInfo.linesAdded>0&&a.push(`${e.metrics_lines_added}${n.metricsInfo.linesAdded}`),n.metricsInfo.linesRemoved!==null&&n.metricsInfo.linesRemoved>0&&a.push(`${e.metrics_lines_removed}${n.metricsInfo.linesRemoved}`),n.blockInfo?.burnRate!==null&&n.blockInfo?.burnRate!==void 0&&n.blockInfo.burnRate>0){let c=n.blockInfo.burnRate<1?`${(n.blockInfo.burnRate*100).toFixed(0)}c/h`:`$${n.blockInfo.burnRate.toFixed(2)}/h`;a.push(`${e.metrics_burn} ${c}`);}a.length>0&&s.push(y(a.join(" \xB7 "),r.metricsFg,o));}let i=t.display.lines.map(a=>a.segments.env).find(a=>a?.enabled);if(i&&i.variable){let a=process.env[i.variable];if(a){let c=i.prefix??i.variable;s.push(y(c?`${c}:${a}`:a,r.envFg,o));}}return s}function pe(n,e,t){let o=k(n.cost),r=`${e.block_cost} ${o}`;n.timeRemaining!==null&&(r+=` \xB7 ${mt(n.timeRemaining)}`);let s=t.budget?.block;if(s?.amount&&n.cost!==null){let i=D(n.cost,s.amount,s.warningThreshold||80);r+=i.displayText;}return r}function Re(n,e,t){let o=k(n.session.cost),r=n.session.tokens,s=r!==null&&r>0?T(r).replace(" tokens",""):null,i=`${e.session_cost} ${o}`;s&&(i+=` \xB7 ${s}`);let a=t.budget?.session;if(a?.amount&&n.session.cost!==null){let c=D(n.session.cost,a.amount,a.warningThreshold||80);i+=c.displayText;}return i}function Be(n,e,t){let o=k(n.cost),r=`${e.today_cost} ${o} today`,s=t.budget?.today;if(s?.amount&&n.cost!==null){let i=D(n.cost,s.amount,s.warningThreshold||80);r+=i.displayText;}return r}function Tt(n){let{lines:e,data:t,box:o,contentWidth:r,innerWidth:s,sym:i,config:a,reset:c,colors:l}=n,g=wt(t,i,a,c,l);g.length>0&&e.push(x(o,_t(g,r),s));}function kt(n){let{lines:e,data:t,box:o,contentWidth:r,innerWidth:s,sym:i,config:a,reset:c,colors:l}=n,g=me(t,i,c,l),u=de(t,i,a,c,l),m=g.join(" "),d=u.join(" \xB7 ");(m||d)&&(e.push(Y(o,s)),e.push(x(o,A(m,d,r),s)));}function vt(n){let{lines:e,data:t,box:o,contentWidth:r,innerWidth:s,sym:i,config:a,reset:c,colors:l}=n,g=[],u=[];t.blockInfo&&g.push(y(pe(t.blockInfo,i,a),l.blockFg,c)),t.todayInfo&&g.push(y(Be(t.todayInfo,i,a),l.todayFg,c)),t.usageInfo&&u.push(y(Re(t.usageInfo,i,a),l.sessionFg,c));let m=Ee(t,i);m.length>0&&u.push(y(m.join(" \xB7 "),l.metricsFg,c)),g.length>0&&e.push(x(o,A(g[0]??"",g[1]??"",r),s)),u.length>0&&e.push(x(o,A(u[0]??"",u[1]??"",r),s));}function $t(n){let{lines:e,data:t,box:o,contentWidth:r,innerWidth:s,sym:i,config:a,reset:c,colors:l}=n,g=me(t,i,c,l);g.length>0&&(e.push(Y(o,s)),e.push(x(o,A(g[0]??"",g[1]??"",r),s)));let u=de(t,i,a,c,l);u.length>0&&(e.push(Y(o,s)),e.push(x(o,u.join(" \xB7 "),s)));}function Pt(n){let{lines:e,data:t,box:o,contentWidth:r,innerWidth:s,sym:i,config:a,reset:c,colors:l}=n;t.blockInfo&&e.push(x(o,y(pe(t.blockInfo,i,a),l.blockFg,c),s));let g=[];t.usageInfo&&g.push(y(`${i.session_cost} ${k(t.usageInfo.session.cost)}`,l.sessionFg,c)),t.todayInfo&&g.push(y(`${i.today_cost} ${k(t.todayInfo.cost)} today`,l.todayFg,c)),g.length>0&&e.push(x(o,A(g[0]??"",g[1]??"",r),s));}function Et(n){let{lines:e,data:t,box:o,contentWidth:r,innerWidth:s,sym:i,config:a,reset:c,colors:l}=n,g=me(t,i,c,l);g.length>0&&(e.push(Y(o,s)),e.push(x(o,A(g[0]??"",g[1]??"",r),s)));let u=de(t,i,a,c,l);u.length>0&&e.push(x(o,u.join(" \xB7 "),s));}var xn="\x1B[?2026h",Sn="\x1B[?2026l",wn=32,Tn=80,kn=55;function vn(n){return n>=Tn?"wide":n>=kn?"medium":"narrow"}function $n(n){return n&&n>0?Math.max(wn,n):80}function De(n,e,t,o,r){let s=(r.display.charset||"unicode")==="text"?fe:ge,i=n.colors,a=$n(o),c=a-2,l=c-2,g=vn(a),u=[];u.push(xt(n,e,c));let m=St(n,l,s,t,i);m&&u.push(x(e,m,c));let d={lines:u,data:n,box:e,contentWidth:l,innerWidth:c,sym:s,config:r,reset:t,colors:i};return g==="wide"?(Tt(d),kt(d)):g==="medium"?(vt(d),$t(d)):(Pt(d),Et(d)),u.push(Ct(e,c)),xn+u.join(`
8
+ `)+Sn}var he=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 j),this._usageProvider}get blockProvider(){return this._blockProvider||(this._blockProvider=new ce),this._blockProvider}get todayProvider(){return this._todayProvider||(this._todayProvider=new le),this._todayProvider}get contextProvider(){return this._contextProvider||(this._contextProvider=new H(this.config)),this._contextProvider}get gitService(){return this._gitService||(this._gitService=new O),this._gitService}get tmuxService(){return this._tmuxService||(this._tmuxService=new N),this._tmuxService}get metricsProvider(){return this._metricsProvider||(this._metricsProvider=new G),this._metricsProvider}get segmentRenderer(){return this._segmentRenderer||(this._segmentRenderer=new z(this.config,this.symbols)),this._segmentRenderer}needsSegmentInfo(e){return this.config.display.lines.some(t=>t.segments[e]?.enabled)}async generateStatusline(e){if(this.config.display.style==="tui")return this.generateTuiStatusline(e);let t=this.needsSegmentInfo("session")?await this.usageProvider.getUsageInfo(e.session_id,e):null,o=this.needsSegmentInfo("block")?await this.blockProvider.getActiveBlockInfo():null,r=this.needsSegmentInfo("today")?await this.todayProvider.getTodayInfo():null,i=this.config.display.lines.map(g=>g.segments.context).find(g=>g?.enabled)?.autocompactBuffer??33e3,a=this.needsSegmentInfo("context")?await this.contextProvider.getContextInfo(e,i):null,c=this.needsSegmentInfo("metrics")?await this.metricsProvider.getMetricsInfo(e.session_id,e):null;return this.config.display.autoWrap?this.generateAutoWrapStatusline(e,t,o,r,a,c):(await Promise.all(this.config.display.lines.map(g=>this.renderLine(g,e,t,o,r,a,c)))).filter(g=>g.length>0).join(`
9
+ `)}async generateAutoWrapStatusline(e,t,o,r,s,i){let a=this.getThemeColors(),c=e.workspace?.current_dir||e.cwd||"/",l=$e(),g=[];for(let u of this.config.display.lines){let m=Object.entries(u.segments).filter(([b,C])=>C?.enabled).map(([b,C])=>({type:b,config:C})),d=[];for(let b of m){let C=await this.renderSegment(b,e,t,o,r,s,i,a,c);C&&d.push({type:b.type,text:C.text,bgColor:C.bgColor,fgColor:C.fgColor});}if(d.length===0)continue;if(!l||l<=0){g.push(this.buildLineFromSegments(d,a));continue}let p=[],h=0;for(let b of d){let C=this.calculateSegmentWidth(b,p.length===0);p.length>0&&h+C>l&&(g.push(this.buildLineFromSegments(p,a)),p=[],h=0),p.push(b),h+=C;}p.length>0&&g.push(this.buildLineFromSegments(p,a));}return g.join(`
10
+ `)}async generateTuiStatusline(e){let t=this.getThemeColors(),o=$e(),r=e.workspace?.current_dir||e.cwd||"/",i=(this.config.display.charset||"unicode")==="text"?bt:ht,c=this.config.display.lines.map($=>$.segments.context).find($=>$?.enabled)?.autocompactBuffer??33e3,l=await Promise.allSettled([this.usageProvider.getUsageInfo(e.session_id,e),this.blockProvider.getActiveBlockInfo(),this.todayProvider.getTodayInfo(),this.contextProvider.getContextInfo(e,c),this.metricsProvider.getMetricsInfo(e.session_id,e),this.gitService.getGitInfo(r,{showSha:false,showWorkingTree:true,showOperation:false,showTag:false,showTimeSinceCommit:false,showStashCount:false,showUpstream:false,showRepoName:false},e.workspace?.project_dir),this.tmuxService.getSessionId()]),g=$=>$.status==="fulfilled"?$.value:null,[u,m,d,p,h,b,C]=[g(l[0]),g(l[1]),g(l[2]),g(l[3]),g(l[4]),g(l[5]),g(l[6])];return De({hookData:e,usageInfo:u,blockInfo:m,todayInfo:d,contextInfo:p,metricsInfo:h,gitInfo:b,tmuxSessionId:C,colors:t},i,t.reset,o,this.config)}calculateSegmentWidth(e,t){let o=this.config.display.style==="capsule",r=F(e.text),i=(this.config.display.padding??1)*2;if(o){let c=2+i+(t?0:1);return r+c}let a=1+i;return r+a}buildLineFromSegments(e,t){let o=this.config.display.style==="capsule",r=t.reset;for(let s=0;s<e.length;s++){let i=e[s];if(!i)continue;let a=s===0,l=s===e.length-1?null:e[s+1];o&&!a&&(r+=" "),r+=this.formatSegment(i.bgColor,i.fgColor,i.text,l?.bgColor,t);}return r}async renderLine(e,t,o,r,s,i,a){let c=this.getThemeColors(),l=t.workspace?.current_dir||t.cwd||"/",g=Object.entries(e.segments).filter(([m,d])=>d?.enabled).map(([m,d])=>({type:m,config:d})),u=[];for(let m of g){let d=await this.renderSegment(m,t,o,r,s,i,a,c,l);d&&u.push({type:m.type,text:d.text,bgColor:d.bgColor,fgColor:d.fgColor});}return this.buildLineFromSegments(u,c)}async renderSegment(e,t,o,r,s,i,a,c,l){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,l):e.type==="session"?this.renderSessionSegment(e.config,o,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):e.type==="env"?this.segmentRenderer.renderEnv(c,e.config):null}async renderGitSegment(e,t,o,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,o,e):null}renderSessionSegment(e,t,o){return t?this.segmentRenderer.renderSession(t,o,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,o){return this.needsSegmentInfo("context")?this.segmentRenderer.renderContext(t,o,e):null}renderMetricsSegment(e,t,o,r){return this.segmentRenderer.renderMetrics(t,r,o,e)}renderBlockSegment(e,t,o){return t?this.segmentRenderer.renderBlock(t,o,e):null}renderTodaySegment(e,t,o){if(!t)return null;let r=e?.type||"cost";return this.segmentRenderer.renderToday(t,o,r)}renderVersionSegment(e,t,o){return this.segmentRenderer.renderVersion(t,o,e)}initializeSymbols(){let e=this.config.display.style,t=this.config.display.charset||"unicode",o=e==="minimal",r=e==="capsule",s=t==="text"?fe:ge;return {right:o?"":r?s.right_rounded:s.right,left:r?s.left_rounded:"",branch:s.branch,model:s.model,git_clean:s.git_clean,git_dirty:s.git_dirty,git_conflicts:s.git_conflicts,git_ahead:s.git_ahead,git_behind:s.git_behind,git_worktree:s.git_worktree,git_tag:s.git_tag,git_sha:s.git_sha,git_upstream:s.git_upstream,git_stash:s.git_stash,git_time:s.git_time,session_cost:s.session_cost,block_cost:s.block_cost,today_cost:s.today_cost,context_time:s.context_time,metrics_response:s.metrics_response,metrics_last_response:s.metrics_last_response,metrics_duration:s.metrics_duration,metrics_messages:s.metrics_messages,metrics_lines_added:s.metrics_lines_added,metrics_lines_removed:s.metrics_lines_removed,metrics_burn:s.metrics_burn,version:s.version,bar_filled:s.bar_filled,bar_empty:s.bar_empty,env:s.env}}getThemeColors(){let e=this.config.theme,t,o=this.config.display.colorCompatibility||"auto",r=o==="auto"?q():o;if(e==="custom"){if(t=this.config.colors?.custom,!t)throw new Error("Custom theme selected but no colors provided in configuration")}else t=K(e,r),t||(console.warn(`Built-in theme '${e}' not found, falling back to 'dark' theme`),t=K("dark",r));let s=K("dark",r),i=this.config.display.style==="tui",c=e==="light"?"#f0f0f0":"#1e1e1e",l=Ne=>{let L=t[Ne]||s[Ne],U=L.fg;return i&&We(U,c)<60&&(U=L.bg),r==="none"?{bg:"",fg:""}:r==="ansi"?{bg:Se(L.bg,true),fg:Se(U,false)}:r==="ansi256"?{bg:xe(L.bg,true),fg:xe(U,false)}:{bg:_e(L.bg,true),fg:_e(U,false)}},g=l("directory"),u=l("git"),m=l("model"),d=l("session"),p=l("block"),h=l("today"),b=l("tmux"),C=l("context"),M=l("contextWarning"),$=l("contextCritical"),Le=l("metrics"),Ue=l("version"),Oe=l("env");return {reset:r==="none"?"":pt,modeBg:g.bg,modeFg:g.fg,gitBg:u.bg,gitFg:u.fg,modelBg:m.bg,modelFg:m.fg,sessionBg:d.bg,sessionFg:d.fg,blockBg:p.bg,blockFg:p.fg,todayBg:h.bg,todayFg:h.fg,tmuxBg:b.bg,tmuxFg:b.fg,contextBg:C.bg,contextFg:C.fg,contextWarningBg:M.bg,contextWarningFg:M.fg,contextCriticalBg:$.bg,contextCriticalFg:$.fg,metricsBg:Le.bg,metricsFg:Le.fg,versionBg:Ue.bg,versionFg:Ue.fg,envBg:Oe.bg,envFg:Oe.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;case "env":return t.envBg;default:return t.modeBg}}formatSegment(e,t,o,r,s){let i=this.config.display.style==="capsule",a=" ".repeat(this.config.display.padding??1);if(i){let m=this.config.display.colorCompatibility||"auto",p=(m==="auto"?q():m)==="ansi",h=J(e,p),b=`${h}${this.symbols.left}${s.reset}`,C=`${e}${t}${a}${o}${a}${s.reset}`,M=`${h}${this.symbols.right}${s.reset}`;return `${b}${C}${M}`}let c=`${e}${t}${a}${o}${a}`,l=this.config.display.colorCompatibility||"auto",u=(l==="auto"?q():l)==="ansi";if(r){let m=J(e,u);c+=`${s.reset}${r}${m}${this.symbols.right}`;}else c+=`${s.reset}${J(e,u)}${this.symbols.right}${s.reset}`;return c}};var Rt={theme:"dark",display:{style:"minimal",charset:"unicode",colorCompatibility:"auto",autoWrap:true,padding:1,lines:[{segments:{directory:{enabled:true,style:"basename"},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,displayStyle:"text",autocompactBuffer:33e3},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 Ie(n){return ["light","dark","nord","tokyo-night","rose-pine","gruvbox","custom"].includes(n)}function Me(n){return n==="minimal"||n==="powerline"||n==="capsule"||n==="tui"}function Bt(n){return n==="unicode"||n==="text"}function ye(n,e){for(let t=0;t<n.length;t++){let o=n[t];if(o===e&&t+1<n.length)return n[t+1];if(o?.startsWith(`${e}=`))return o.split("=")[1]}}function Ce(n,e){let t={...n};for(let o in e){let r=e[o];if(r!==void 0)if(typeof r=="object"&&r!==null&&!Array.isArray(r)){let s=t[o]||{};t[o]=Ce(s,r);}else t[o]=r;}return t}function Pn(n,e){return n?S.existsSync(n)?n:null:[...e?[_.join(e,".claude-powerline.json")]:[],_.join(process.cwd(),".claude-powerline.json"),_.join(Ae.homedir(),".claude","claude-powerline.json"),_.join(Ae.homedir(),".config","claude-powerline","config.json")].find(S.existsSync)||null}function En(n){try{let e=S.readFileSync(n,"utf-8");return JSON.parse(e)}catch(e){throw new Error(`Failed to load config file ${n}: ${e instanceof Error?e.message:String(e)}`)}}function Rn(){let n={},e={},t=process.env.CLAUDE_POWERLINE_THEME;t&&Ie(t)&&(n.theme=t);let o=process.env.CLAUDE_POWERLINE_STYLE;return o&&(Me(o)?e.style=o:(console.warn(`Invalid display style '${o}' from environment variable, falling back to 'minimal'`),e.style="minimal")),Object.keys(e).length>0&&(n.display=e),n}function Bn(){return process.env.CLAUDE_POWERLINE_CONFIG}function Dn(n){let e={},t={},o=ye(n,"--theme");o&&Ie(o)&&(e.theme=o);let r=ye(n,"--style");r&&(Me(r)?t.style=r:(console.warn(`Invalid display style '${r}' from CLI argument, falling back to 'minimal'`),t.style="minimal"));let s=ye(n,"--charset");return s&&(Bt(s)?t.charset=s:(console.warn(`Invalid charset '${s}' from CLI argument, falling back to 'unicode'`),t.charset="unicode")),Object.keys(t).length>0&&(e.display=t),e}function Fn(n=process.argv,e){let t=JSON.parse(JSON.stringify(Rt)),o=ye(n,"--config")||Bn(),r=o?.startsWith("~")?o.replace("~",Ae.homedir()):o,s=Pn(r,e);if(s)try{let c=En(s);t=Ce(t,c);}catch(c){console.warn(`Warning: ${c instanceof Error?c.message:String(c)}`);}t.display?.style&&!Me(t.display.style)&&(console.warn(`Invalid display style '${t.display.style}' in config file, falling back to 'minimal'`),t.display.style="minimal"),t.display?.charset&&!Bt(t.display.charset)&&(console.warn(`Invalid charset '${t.display.charset}' in config file, falling back to 'unicode'`),t.display.charset="unicode"),t.theme&&!Ie(t.theme)&&(console.warn(`Invalid theme '${t.theme}' in config file, falling back to 'dark'`),t.theme="dark");let i=Rn();t=Ce(t,i);let a=Dn(n);return t=Ce(t,a),t}var Dt=Fn;function Ft(){console.log(`
10
11
  claude-powerline - Beautiful powerline statusline for Claude Code
11
12
 
12
13
  Usage: claude-powerline [options]
@@ -19,13 +20,13 @@ Debugging:
19
20
 
20
21
  Claude Code Options (for settings.json):
21
22
  --theme=THEME Set theme: dark, light, nord, tokyo-night, rose-pine, custom
22
- --style=STYLE Set separator style: minimal, powerline, capsule
23
+ --style=STYLE Set separator style: minimal, powerline, capsule, tui
23
24
  --charset=CHARSET Set character set: unicode (default), text
24
25
  --config=PATH Use custom config file path
25
26
 
26
27
  See example config at: https://github.com/Owloops/claude-powerline/blob/main/.claude-powerline.json
27
28
 
28
- `);}async function Gt(){try{(w.argv.includes("--help")||w.argv.includes("-h"))&&(Qe(),w.exit(0)),w.stdin.isTTY===!0&&(console.error(`Error: This tool requires input from Claude Code
29
+ `);}async function In(){try{(v.argv.includes("--help")||v.argv.includes("-h"))&&(Ft(),v.exit(0)),v.stdin.isTTY===!0&&(console.error(`Error: This tool requires input from Claude Code
29
30
 
30
31
  claude-powerline is designed to be used as a Claude Code statusLine command.
31
32
  It reads hook data from stdin and outputs formatted statusline.
@@ -41,4 +42,4 @@ Add to ~/.claude/settings.json:
41
42
  Run with --help for more options.
42
43
 
43
44
  To test output manually:
44
- echo '{"session_id":"test-session","workspace":{"project_dir":"/path/to/project"},"model":{"id":"claude-3-5-sonnet","display_name":"Claude"}}' | claude-powerline --style=powerline`),w.exit(1)),g(`Working directory: ${w.cwd()}`),g("Process args:",w.argv);let e=await json(w.stdin);g("Received hook data:",JSON.stringify(e,null,2)),e||(console.error("Error: No input data received from stdin"),Qe(),w.exit(1));let t=e.workspace?.project_dir,n=Ze(w.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),w.exit(1);}}Gt();
45
+ echo '{"session_id":"test-session","workspace":{"project_dir":"/path/to/project"},"model":{"id":"claude-3-5-sonnet","display_name":"Claude"}}' | claude-powerline --style=powerline`),v.exit(1)),f(`Working directory: ${v.cwd()}`),f("Process args:",v.argv);let e=await json(v.stdin);f("Received hook data:",JSON.stringify(e,null,2)),e||(console.error("Error: No input data received from stdin"),Ft(),v.exit(1));let t=e.workspace?.project_dir,o=Dt(v.argv,t),s=await new he(o).generateStatusline(e);console.log(s);}catch(n){let e=n instanceof Error?n.message:String(n);console.error("Error generating statusline:",e),v.exit(1);}}In();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@owloops/claude-powerline",
3
- "version": "1.19.6",
3
+ "version": "1.20.0",
4
4
  "description": "Beautiful vim-style powerline statusline for Claude Code with real-time usage tracking, git integration, and custom themes",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",