@owloops/claude-powerline 1.21.2 → 1.22.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +42 -2
- package/dist/index.mjs +11 -11
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -434,7 +434,8 @@ Configure context window limits for different model types. Defaults to 200K toke
|
|
|
434
434
|
"block": {
|
|
435
435
|
"enabled": true,
|
|
436
436
|
"type": "weighted",
|
|
437
|
-
"burnType": "cost"
|
|
437
|
+
"burnType": "cost",
|
|
438
|
+
"displayStyle": "text"
|
|
438
439
|
}
|
|
439
440
|
```
|
|
440
441
|
|
|
@@ -442,13 +443,52 @@ Configure context window limits for different model types. Defaults to 200K toke
|
|
|
442
443
|
|
|
443
444
|
- `type`: Display format - `cost` | `tokens` | `both` | `time` | `weighted`
|
|
444
445
|
- `burnType`: Burn rate display - `cost` | `tokens` | `both` | `none`
|
|
446
|
+
- `displayStyle`: Visual style for utilization display (see table below). Only applies when native rate limit data is available.
|
|
445
447
|
|
|
446
|
-
**
|
|
448
|
+
**Native Rate Limits:** When Claude Code provides `rate_limits` in its hook data (Claude.ai Pro/Max subscribers), the block segment displays the official 5-hour utilization percentage and reset countdown instead of transcript-based estimates. This is more accurate, accounts for cross-machine usage, and requires no disk I/O. When native data is unavailable (API users, older Claude Code versions), the segment falls back to transcript-based cost/token tracking.
|
|
449
|
+
|
|
450
|
+
**Display Styles** (native mode only):
|
|
451
|
+
|
|
452
|
+
| Style | Example |
|
|
453
|
+
|-------|---------|
|
|
454
|
+
| `text` (default) | `◱ 23% (4h 12m)` |
|
|
455
|
+
| `bar` | `◱ ▪▪▫▫▫▫▫▫▫▫ 23% (4h 12m)` |
|
|
456
|
+
| `blocks` | `◱ ██░░░░░░░░ 23% (4h 12m)` |
|
|
457
|
+
| `blocks-line` | `◱ ██──────── 23% (4h 12m)` |
|
|
458
|
+
| `capped` | `◱ ━╸┄┄┄┄┄┄┄┄ 23% (4h 12m)` |
|
|
459
|
+
| `dots` | `◱ ●●○○○○○○○○ 23% (4h 12m)` |
|
|
460
|
+
| `filled` | `◱ ■■□□□□□□□□ 23% (4h 12m)` |
|
|
461
|
+
| `geometric` | `◱ ▰▰▱▱▱▱▱▱▱▱ 23% (4h 12m)` |
|
|
462
|
+
| `line` | `◱ ━━┄┄┄┄┄┄┄┄ 23% (4h 12m)` |
|
|
463
|
+
| `squares` | `◱ ◼◼◻◻◻◻◻◻◻◻ 23% (4h 12m)` |
|
|
464
|
+
| `ball` | `◱ ──●─────── 23% (4h 12m)` |
|
|
465
|
+
|
|
466
|
+
**Weighted Tokens:** In transcript mode, Opus tokens count 5x toward rate limits compared to Sonnet/Haiku tokens
|
|
447
467
|
|
|
448
468
|
**Symbols:** `◱` Block (unicode) • `B` Block (text)
|
|
449
469
|
|
|
450
470
|
</details>
|
|
451
471
|
|
|
472
|
+
<details>
|
|
473
|
+
<summary><strong>Weekly</strong> - Shows usage within 7-day rolling rate limit window</summary>
|
|
474
|
+
|
|
475
|
+
```json
|
|
476
|
+
"weekly": {
|
|
477
|
+
"enabled": true,
|
|
478
|
+
"displayStyle": "text"
|
|
479
|
+
}
|
|
480
|
+
```
|
|
481
|
+
|
|
482
|
+
**Options:**
|
|
483
|
+
|
|
484
|
+
- `displayStyle`: Visual style for utilization display - same options as the block segment (see table above)
|
|
485
|
+
|
|
486
|
+
Only visible when Claude Code provides native `rate_limits.seven_day` data (Claude.ai Pro/Max subscribers). Hidden when the data is not available.
|
|
487
|
+
|
|
488
|
+
**Symbols:** `◑` Weekly (unicode) • `W` Weekly (text)
|
|
489
|
+
|
|
490
|
+
</details>
|
|
491
|
+
|
|
452
492
|
<details>
|
|
453
493
|
<summary><strong>Today</strong> - Shows total daily usage with budget monitoring</summary>
|
|
454
494
|
|
package/dist/index.mjs
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import e from"node:process";import{json as t}from"node:stream/consumers";import n from"node:tty";import{exec as r,execSync as i}from"node:child_process";import{promisify as a}from"node:util";import o,{createReadStream as s,existsSync as c,readFileSync as l}from"node:fs";import u,{dirname as d,join as f,posix as p}from"node:path";import{get as m}from"node:https";import{URL as h}from"node:url";import g,{homedir as _}from"node:os";import{createHash as v}from"node:crypto";import{setTimeout as y}from"node:timers/promises";import{readFile as b,readdir as x,stat as ee}from"node:fs/promises";import{createInterface as te}from"node:readline";function ne(e,t){if(t&&(e.toLowerCase()===`transparent`||e.toLowerCase()===`none`))return`\x1B[49m`;let n=parseInt(e.slice(1,3),16),r=parseInt(e.slice(3,5),16),i=parseInt(e.slice(5,7),16);return`\x1b[${t?`48`:`38`};2;${n};${r};${i}m`}function S(e,t=!1){if(!e||e===``)return``;let n=e.match(/48;2;(\d+);(\d+);(\d+)/);if(n)return`\x1b[38;2;${n[1]};${n[2]};${n[3]}m`;if(t)return`\x1B[37m`;if(e.includes(`\x1B[`)&&e.includes(`m`)){let t=e.match(/\[(\d+)m/);if(t&&t[1]){let e=parseInt(t[1],10);if(e>=40&&e<=47||e>=100&&e<=107)return`\x1b[${e-10}m`}}return e.replace(`48`,`38`)}function C(){let{env:t}=e,r=!0;t.NO_COLOR&&t.NO_COLOR!==``&&(r=!1);let i=t.FORCE_COLOR;if(i&&i!==``)return i===`false`||i===`0`?`none`:i===`true`||i===`1`?`ansi`:i===`2`?`ansi256`:i===`3`?`truecolor`:`ansi`;if(!r||t.TERM===`dumb`)return`none`;if(t.CI)return[`GITHUB_ACTIONS`,`GITEA_ACTIONS`,`CIRCLECI`].some(e=>e in t)?`truecolor`:`ansi`;if(t.COLORTERM===`truecolor`||[`xterm-kitty`,`xterm-ghostty`,`wezterm`,`alacritty`,`foot`,`contour`].includes(t.TERM||``))return`truecolor`;if(t.TERM_PROGRAM)switch(t.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(t.TERM||``))return`ansi256`;if(/-truecolor$/i.test(t.TERM||``))return`truecolor`;if(/^screen|^xterm|^vt100|^vt220|^rxvt|color|ansi|cygwin|linux/i.test(t.TERM||``)||t.COLORTERM)return`ansi`;if(n?.WriteStream?.prototype?.hasColors)try{if(!n.WriteStream.prototype.hasColors())return`none`;let e=n.WriteStream.prototype.hasColors(256);return n.WriteStream.prototype.hasColors(16777216)?`truecolor`:e?`ansi256`:`ansi`}catch{}return`ansi`}function w(e,t){if(t&&(e.toLowerCase()===`transparent`||e.toLowerCase()===`none`))return`\x1B[49m`;let n=((e,t,n)=>e===t&&t===n?e<8?16:e>248?231:Math.round((e-8)/247*24)+232:16+36*Math.round(e/255*5)+6*Math.round(t/255*5)+Math.round(n/255*5))(parseInt(e.slice(1,3),16),parseInt(e.slice(3,5),16),parseInt(e.slice(5,7),16));return`\x1b[${t?`48`:`38`};5;${n}m`}function T(e,t){if(t&&(e.toLowerCase()===`transparent`||e.toLowerCase()===`none`))return`\x1B[49m`;if(t)return``;let n=parseInt(e.slice(1,3),16),r=parseInt(e.slice(3,5),16),i=parseInt(e.slice(5,7),16);return r>n&&r>i&&r>120?`\x1B[32m`:n>r&&n>i&&n>120?`\x1B[31m`:i>n&&i>r&&i>120?`\x1B[34m`:(n+r+i)/3>150?`\x1B[37m`:`\x1B[90m`}function re(e,t){let n=parseInt(e.slice(1,3),16),r=parseInt(e.slice(3,5),16),i=parseInt(e.slice(5,7),16),a=parseInt(t.slice(1,3),16),o=parseInt(t.slice(3,5),16),s=parseInt(t.slice(5,7),16);return Math.sqrt((n-a)**2+(r-o)**2+(i-s)**2)}const ie={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`}},ae={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`}},oe={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`}},se={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`}},ce={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`}},le={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`}},ue={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`}},de={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`}},fe={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`}},pe={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`}},me={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`}},he={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`}},ge={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`}},_e={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`}},ve={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`}},ye={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`}},be={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`}},xe={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`}},E={dark:ie,"dark-ansi256":ae,"dark-ansi":oe,light:se,"light-ansi256":ce,"light-ansi":le,nord:ue,"nord-ansi256":de,"nord-ansi":fe,"tokyo-night":pe,"tokyo-night-ansi256":me,"tokyo-night-ansi":he,"rose-pine":ge,"rose-pine-ansi256":_e,"rose-pine-ansi":ve,gruvbox:ye,"gruvbox-ansi256":be,"gruvbox-ansi":xe};function D(e,t){let n=E[e];if(!n)return null;if(t===`none`||t===`ansi`){let t=E[`${e}-ansi`];if(t)return t}if(t===`ansi256`){let t=E[`${e}-ansi256`];if(t)return t}return n}const O=(e,...t)=>{process.env.CLAUDE_POWERLINE_DEBUG&&console.error(`[DEBUG] ${e}`,...t)},Se=a(r);var Ce=class{isGitRepo(e){try{return o.existsSync(u.join(e,`.git`))}catch{return!1}}async execGitAsync(e,t){return Se(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,i=this.isWorktree(e);if(i)r=e;else if(n&&this.isGitRepo(n))r=n;else if(this.isGitRepo(e))r=e;else{let t=await this.findGitRoot(e);if(!t)return null;r=t}try{let e=await this.getStatusWithBranchAsync(r),n=await this.getAheadBehindAsync(r),a={branch:e.branch||`detached`,status:e.status,ahead:n.ahead,behind:n.behind};t.showWorkingTree&&e.workingTree&&(a.staged=e.workingTree.staged,a.unstaged=e.workingTree.unstaged,a.untracked=e.workingTree.untracked,a.conflicts=e.workingTree.conflicts);let o={},s={};t.showSha&&(o.sha=this.getShaAsync(r)),t.showTag&&(o.tag=this.getNearestTagAsync(r)),t.showTimeSinceCommit&&(o.timeSinceCommit=this.getTimeSinceLastCommitAsync(r)),t.showStashCount&&(s.stashCount=this.getStashCountAsync(r)),t.showUpstream&&(s.upstream=this.getUpstreamAsync(r)),t.showRepoName&&(s.repoName=this.getRepoNameAsync(r));let c=new Map;for(let[e,t]of Object.entries(o))try{let n=await t;c.set(e,n)}catch{}return Object.keys(s).length>0&&(await Promise.allSettled(Object.entries(s).map(async([e,t])=>({key:e,value:await t})))).forEach(e=>{e.status===`fulfilled`&&c.set(e.value.key,e.value.value)}),t.showSha&&(a.sha=c.get(`sha`)||void 0),t.showOperation&&(a.operation=this.getOngoingOperation(r)||void 0),t.showTag&&(a.tag=c.get(`tag`)||void 0),t.showTimeSinceCommit&&(a.timeSinceCommit=c.get(`timeSinceCommit`)||void 0),t.showStashCount&&(a.stashCount=c.get(`stashCount`)||0),t.showUpstream&&(a.upstream=c.get(`upstream`)||void 0),t.showRepoName&&(a.repoName=c.get(`repoName`)||void 0,a.isWorktree=i),a}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=u.join(e,`.git`);if(o.existsSync(t)&&o.statSync(t).isFile()){let n=o.readFileSync(t,`utf-8`).match(/^gitdir:\s*(.+)$/m);if(n?.[1])return u.resolve(e,n[1].trim())}return t}getOngoingOperation(e){try{let t=this.resolveGitDir(e);return o.existsSync(u.join(t,`MERGE_HEAD`))?`MERGE`:o.existsSync(u.join(t,`CHERRY_PICK_HEAD`))?`CHERRY-PICK`:o.existsSync(u.join(t,`REVERT_HEAD`))?`REVERT`:o.existsSync(u.join(t,`BISECT_LOG`))?`BISECT`:o.existsSync(u.join(t,`rebase-merge`))||o.existsSync(u.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 t=(await this.execGitAsync(`git log -1 --format=%ct`,{cwd:e,encoding:`utf8`,timeout:2e3})).stdout.trim();if(!t)return null;let n=parseInt(t)*1e3,r=Date.now();return Math.floor((r-n)/1e3)}catch{return null}}async getStashCountAsync(e){try{let t=(await this.execGitAsync(`git stash list`,{cwd:e,encoding:`utf8`,timeout:2e3})).stdout.trim();return t?t.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 t=(await this.execGitAsync(`git config --get remote.origin.url`,{cwd:e,encoding:`utf8`,timeout:2e3})).stdout.trim();return t&&t.match(/\/([^/]+?)(\.git)?$/)?.[1]||u.basename(e)}catch{return u.basename(e)}}isWorktree(e){try{let t=u.join(e,`.git`);return!!(o.existsSync(t)&&o.statSync(t).isFile())}catch{return!1}}async getStatusWithBranchAsync(e){try{
|
|
4
|
-
`),n=null,r=`clean`,i=0,a=0,o=0,s=0;for(let e of t)if(e){if(e.startsWith(`## `)){let t=e.substring(3).split(`...`)[0];t&&t!==`HEAD (no branch)`&&(n=t);continue}if(e.length>=2){let t=e.charAt(0),n=e.charAt(1);if(t===`?`&&n===`?`){o++,r===`clean`&&(r=`dirty`);continue}let c=t+n;if([`DD`,`AU`,`UD`,`UA`,`DU`,`AA`,`UU`].includes(c)){s++,r=`conflicts`;continue}t!==` `&&t!==`?`&&(i++,r===`clean`&&(r=`dirty`)),n!==` `&&n!==`?`&&(a++,r===`clean`&&(r=`dirty`))}}return{branch:n||await this.getFallbackBranch(e),status:r,workingTree:{staged:i,unstaged:a,untracked:o,conflicts:s}}}catch(t){return
|
|
5
|
-
`)[0];r&&JSON.parse(r).sessionId===e&&n.push(t)}catch{
|
|
6
|
-
`).filter(e=>e.trim()),n=[];for(let e of t)try{let t=JSON.parse(e);if(!t.timestamp)continue;let r={timestamp:new Date(t.timestamp),message:t.message,costUSD:typeof t.costUSD==`number`?t.costUSD:void 0,isSidechain:t.isSidechain===!0,raw:t};n.push(r)}catch(e){O(`Failed to parse JSONL line: ${e}`);continue}return n}async function je(e){return new Promise((t,n)=>{let r=[],i=s(e,{encoding:`utf8`}),a=te({input:i,crlfDelay:1/0});a.on(`line`,e=>{let t=e.trim();if(t)try{let e=JSON.parse(t);if(!e.timestamp)return;let n={timestamp:new Date(e.timestamp),message:e.message,costUSD:typeof e.costUSD==`number`?e.costUSD:void 0,isSidechain:e.isSidechain===!0,raw:e};r.push(n)}catch(e){O(`Failed to parse JSONL line: ${e}`)}}),a.on(`close`,()=>{t(r)}),a.on(`error`,t=>{O(`Streaming parser error for ${e}:`,t),n(t)}),i.on(`error`,t=>{O(`File stream error for ${e}:`,t),n(t)})})}async function Me(e){try{let t=await Oe(e);return t?{filePath:e,mtime:t}:null}catch{return null}}async function Ne(e,t){try{let n=await x(e,{withFileTypes:!0}),r=n.filter(e=>!e.isDirectory()&&e.name.endsWith(`.jsonl`)).map(t=>Me(p.join(e,t.name))),i=n.filter(e=>e.isDirectory()).map(async t=>{let n=p.join(e,t.name,`subagents`);try{return(await x(n)).filter(e=>e.startsWith(`agent-`)&&e.endsWith(`.jsonl`)).map(e=>Me(p.join(n,e)))}catch{return[]}}),[a,o]=await Promise.all([Promise.all(r),Promise.all(i).then(e=>Promise.all(e.flat()))]);return[...a,...o].filter(e=>e!==null&&(!t||t(e.filePath,e.mtime)))}catch(t){return O(`Failed to read project directory ${e}:`,t),[]}}async function M(e,t,n=!1){let r=await A(k()),i=new Set,a=r.map(e=>Ne(e,t)),o=(await Promise.all(a)).flat().filter(e=>e!==null);n&&o.sort((e,t)=>t.mtime.getTime()-e.mtime.getTime());let s=o.map(e=>e.filePath),c=[],l=s.map(async t=>(await j(t)).filter(t=>!e||e(t))),u=await Promise.all(l);for(let e of u)c.push(...e);c.sort((e,t)=>e.timestamp.getTime()-t.timestamp.getTime());let d=[];for(let e of c){let t=ke(e);t&&i.has(t)||(t&&i.add(t),d.push(e))}return d}var N=class{static CACHE_DIR=u.join(_(),`.claude`,`powerline`);static USAGE_CACHE_DIR=u.join(this.CACHE_DIR,`usage`);static LOCKS_DIR=u.join(this.CACHE_DIR,`locks`);static isLocked(e){let t=u.join(this.LOCKS_DIR,e);if(!o.existsSync(t))return!1;try{let n=o.readFileSync(t,`utf-8`),r=parseInt(n.trim(),10);if(isNaN(r))return O(`Invalid PID in lock file ${e}, removing stale lock`),o.unlinkSync(t),!1;try{return process.kill(r,0),!0}catch(n){return n.code===`ESRCH`?(O(`Removing stale lock file ${e} for dead process ${r}`),o.unlinkSync(t),!1):(O(`Error checking process ${r} for lock ${e}:`,n),!0)}}catch(t){return O(`Error reading lock file ${e}:`,t),!0}}static async acquireLock(e,t=5e3){await this.ensureCacheDirectories();let n=u.join(this.LOCKS_DIR,e),r=Date.now(),i=String(process.pid);for(;Date.now()-r<t;)try{return await o.promises.writeFile(n,i,{flag:`wx`}),O(`Lock acquired for ${e}`),!0}catch(e){if(e.code===`EEXIST`)await y(50);else throw e}return O(`Failed to acquire lock for ${e} within ${t}ms`),!1}static async releaseLock(e){let t=u.join(this.LOCKS_DIR,e);try{await o.promises.unlink(t),O(`Lock released for ${e}`)}catch(t){t.code!==`ENOENT`&&O(`Error releasing lock for ${e}:`,t)}}static async ensureCacheDirectories(){try{await Promise.all([o.promises.mkdir(this.CACHE_DIR,{recursive:!0}),o.promises.mkdir(this.USAGE_CACHE_DIR,{recursive:!0}),o.promises.mkdir(this.LOCKS_DIR,{recursive:!0})])}catch(e){O(`Failed to create cache directories:`,e)}}static createProjectHash(e){return v(`md5`).update(e).digest(`hex`).substring(0,8)}static async getUsageCache(e,t){await this.ensureCacheDirectories();let n=u.join(this.USAGE_CACHE_DIR,`${e}.json`),r=`${e}.usage.lock`;for(let i=0;i<3;i++){if(this.isLocked(r)){O(`Cache for ${e} is locked, waiting...`),await y(75);continue}try{let r=await o.promises.readFile(n,`utf-8`),i=JSON.parse(r);return!t||i.timestamp>=t?(O(`[CACHE-HIT] ${e} disk cache: found`),this.deserializeDates(i.data)):(O(`${e} cache outdated: cache=${i.timestamp}, latest=${t}`),null)}catch(t){if(t.code===`ENOENT`)return O(`No shared ${e} usage cache found`),null;O(`Attempt ${i+1} failed to read ${e} cache: ${t.message}. Retrying...`),await y(75)}}return O(`Failed to read ${e} cache after 3 attempts.`),null}static deserializeDates(e){return Array.isArray(e)?e.map(e=>({...e,timestamp:new Date(e.timestamp)})):e}static async setUsageCache(e,t,n){let r=`${e}.usage.lock`;if(!await this.acquireLock(r)){O(`Could not acquire lock to set usage cache for ${e}`);return}try{await this.ensureCacheDirectories();let r=u.join(this.USAGE_CACHE_DIR,`${e}.json`),i={data:t,timestamp:n||Date.now()},a=JSON.stringify(i);await o.promises.writeFile(r,a,`utf-8`),O(`[CACHE-SET] ${e} disk cache stored`)}catch(t){O(`Failed to save ${e} usage cache:`,t)}finally{await this.releaseLock(r)}}static async getLatestTranscriptMtime(){try{let e=await A(k()),t=0;for(let n of e)try{let e=(await o.promises.readdir(n)).filter(e=>e.endsWith(`.jsonl`));for(let r of e){let e=await Oe(u.join(n,r));e&&e.getTime()>t&&(t=e.getTime())}}catch(e){O(`Failed to read project directory ${n}:`,e);continue}return t}catch(e){return O(`Failed to get latest transcript mtime:`,e),Date.now()}}};const P={"claude-haiku-4-5-20251001":{name:`Claude Haiku 4.5`,input:1,output:5,cache_write_5m:1.25,cache_write_1h:2,cache_read:.1},"claude-haiku-4-5":{name:`Claude Haiku 4.5`,input:1,output:5,cache_write_5m:1.25,cache_write_1h:2,cache_read:.1},"claude-opus-4-20250514":{name:`Claude Opus 4`,input:15,output:75,cache_write_5m:18.75,cache_write_1h:30,cache_read:1.5},"claude-opus-4-1":{name:`Claude Opus 4.1`,input:15,output:75,cache_write_5m:18.75,cache_write_1h:30,cache_read:1.5},"claude-opus-4-1-20250805":{name:`Claude Opus 4.1`,input:15,output:75,cache_write_5m:18.75,cache_write_1h:30,cache_read:1.5},"claude-sonnet-4-20250514":{name:`Claude Sonnet 4`,input:3,output:15,cache_write_5m:3.75,cache_write_1h:6,cache_read:.3},"claude-4-opus-20250514":{name:`Claude 4 Opus`,input:15,output:75,cache_write_5m:18.75,cache_write_1h:30,cache_read:1.5},"claude-4-sonnet-20250514":{name:`Claude 4 Sonnet`,input:3,output:15,cache_write_5m:3.75,cache_write_1h:6,cache_read:.3},"claude-sonnet-4-5":{name:`Claude Sonnet 4.5`,input:3,output:15,cache_write_5m:3.75,cache_write_1h:6,cache_read:.3},"claude-sonnet-4-5-20250929":{name:`Claude Sonnet 4.5`,input:3,output:15,cache_write_5m:3.75,cache_write_1h:6,cache_read:.3},"claude-opus-4-5":{name:`Claude Opus 4.5`,input:5,output:25,cache_write_5m:6.25,cache_write_1h:10,cache_read:.5},"claude-opus-4-5-20251101":{name:`Claude Opus 4.5`,input:5,output:25,cache_write_5m:6.25,cache_write_1h:10,cache_read:.5},"claude-opus-4-6":{name:`Claude Opus 4.6`,input:5,output:25,cache_write_5m:6.25,cache_write_1h:10,cache_read:.5},"claude-opus-4-6-20260205":{name:`Claude Opus 4.6`,input:5,output:25,cache_write_5m:6.25,cache_write_1h:10,cache_read:.5},"claude-sonnet-4-6":{name:`Claude Sonnet 4.6`,input:3,output:15,cache_write_5m:3.75,cache_write_1h:6,cache_read:.3}};var F=class{static executionCache=null;static modelPricingCache=new Map;static GITHUB_PRICING_URL=`https://raw.githubusercontent.com/Owloops/claude-powerline/main/pricing.json`;static async loadDiskCache(){let e=Date.now()-1440*60*1e3;return await N.getUsageCache(`pricing`,e)}static async saveDiskCache(e){await N.setUsageCache(`pricing`,e)}static async fetchPricingData(){return new Promise(e=>{let t=new h(this.GITHUB_PRICING_URL),n=m({hostname:t.hostname,path:t.pathname,headers:{"User-Agent":`claude-powerline`,"Cache-Control":`no-cache`},timeout:5e3},t=>{if(t.statusCode!==200){O(`HTTP ${t.statusCode}: ${t.statusMessage}`),e(null);return}let r=``,i=0;t.on(`data`,t=>{if(i+=t.length,i>1048576){O(`Response too large`),n.destroy(),e(null);return}r+=t}),t.on(`end`,()=>{try{let t=JSON.parse(r),n=t._meta,i={};for(let[e,n]of Object.entries(t))e!==`_meta`&&(i[e]=n);this.validatePricingData(i)?(O(`Fetched fresh pricing from GitHub for ${Object.keys(i).length} models`),O(`Pricing last updated: ${n?.updated||`unknown`}`),e(i)):(O(`Invalid pricing data structure`),e(null))}catch(t){O(`Failed to parse JSON:`,t),e(null)}}),t.on(`error`,t=>{O(`Response error:`,t),e(null)})});n.on(`error`,t=>{O(`Request error:`,t),e(null)}),n.on(`timeout`,()=>{O(`Request timeout`),n.destroy(),e(null)}),n.end()})}static async getCurrentPricing(){if(this.executionCache!==null)return O(`[CACHE-HIT] Pricing execution cache: ${Object.keys(this.executionCache).length} models`),this.executionCache;let e=await this.loadDiskCache();if(e)return O(`[CACHE-HIT] Pricing disk cache: ${Object.keys(e).length} models`),this.executionCache=e,O(`[CACHE-SET] Pricing execution cache stored: ${Object.keys(e).length} models`),e;let t=await this.fetchPricingData();return t?(await this.saveDiskCache(t),O(`[CACHE-SET] Pricing disk cache stored: ${Object.keys(t).length} models`),this.executionCache=t,O(`[CACHE-SET] Pricing execution cache stored: ${Object.keys(t).length} models`),t):(O(`[CACHE-FALLBACK] Using offline pricing data: ${Object.keys(P).length} models`),this.executionCache=P,O(`[CACHE-SET] Pricing execution cache stored: ${Object.keys(P).length} models`),P)}static validatePricingData(e){if(!e||typeof e!=`object`)return!1;for(let[,t]of Object.entries(e)){if(!t||typeof t!=`object`)return!1;let e=t;if(typeof e.input!=`number`||typeof e.output!=`number`||typeof e.cache_read!=`number`)return!1}return!0}static async getModelPricing(e){if(this.modelPricingCache.has(e))return O(`[CACHE-HIT] Model pricing cache: ${e}`),this.modelPricingCache.get(e);let t=await this.getCurrentPricing(),n;return n=t[e]?t[e]:this.fuzzyMatchModel(e,t),this.modelPricingCache.set(e,n),O(`[CACHE-SET] Model pricing cache: ${e}`),n}static fuzzyMatchModel(e,t){let n=e.toLowerCase();for(let[e,r]of Object.entries(t))if(e.toLowerCase()===n)return r;for(let{pattern:e,fallback:r}of[{pattern:[`opus-4-6`,`claude-opus-4-6`],fallback:`claude-opus-4-6-20260205`},{pattern:[`opus-4-5`,`claude-opus-4-5`],fallback:`claude-opus-4-5-20251101`},{pattern:[`opus-4-1`,`claude-opus-4-1`],fallback:`claude-opus-4-1-20250805`},{pattern:[`opus-4`,`claude-opus-4`],fallback:`claude-opus-4-20250514`},{pattern:[`sonnet-4-6`,`sonnet-4.6`,`claude-sonnet-4-6`],fallback:`claude-sonnet-4-6`},{pattern:[`sonnet-4.5`,`4-5-sonnet`,`sonnet-4-5`],fallback:`claude-sonnet-4-5-20250929`},{pattern:[`sonnet-4`,`claude-sonnet-4`],fallback:`claude-sonnet-4-20250514`},{pattern:[`haiku-4.5`,`4-5-haiku`,`haiku-4-5`],fallback:`claude-haiku-4-5-20251001`},{pattern:[`haiku`],fallback:`claude-haiku-4-5-20251001`},{pattern:[`opus`],fallback:`claude-opus-4-20250514`},{pattern:[`sonnet`],fallback:`claude-sonnet-4-5-20250929`}])if(e.some(e=>n.includes(e))&&t[r])return t[r];return t[`claude-sonnet-4-5-20250929`]||{name:`${e} (Unknown Model)`,input:3,cache_write_5m:3.75,cache_write_1h:6,cache_read:.3,output:15}}static async calculateCostForEntry(e){let t=e.message?.usage;if(!t)return 0;let n=this.extractModelId(e),r=await this.getModelPricing(n),i=t.input_tokens||0,a=t.output_tokens||0,o=t.cache_creation_input_tokens||0,s=t.cache_read_input_tokens||0,c=i/1e6*r.input,l=a/1e6*r.output,u=s/1e6*r.cache_read,d=o/1e6*r.cache_write_5m;return c+l+d+u}static extractModelId(e){if(e.model&&typeof e.model==`string`)return e.model;let t=e.message;if(t?.model){let e=t.model;return typeof e==`string`?e:e?.id||`claude-sonnet-4-5-20250929`}return e.model_id&&typeof e.model_id==`string`?e.model_id:`claude-sonnet-4-5-20250929`}};function Pe(e){return{timestamp:e.timestamp.toISOString(),message:{usage:{input_tokens:e.message?.usage?.input_tokens||0,output_tokens:e.message?.usage?.output_tokens||0,cache_creation_input_tokens:e.message?.usage?.cache_creation_input_tokens,cache_read_input_tokens:e.message?.usage?.cache_read_input_tokens}},costUSD:e.costUSD}}var Fe=class{async getSessionUsage(e){try{let t=await Ee(e);if(!t)return O(`No transcript found for session: ${e}`),null;O(`Found transcript at: ${t}`);let n=await j(t),r=await De(e,d(t));O(`Found ${r.length} agent transcripts for session`);for(let e of r){let t=await j(e);n.push(...t)}if(n.length===0)return{totalCost:0,entries:[]};let i=[],a=0;for(let e of n)if(e.message?.usage){let t=Pe(e);if(t.costUSD!==void 0)a+=t.costUSD;else{let n=await F.calculateCostForEntry(e.raw);t.costUSD=n,a+=n}i.push(t)}return O(`Parsed ${i.length} usage entries, total cost: $${a.toFixed(4)}`),{totalCost:a,entries:i}}catch(t){return O(`Error reading session usage for ${e}:`,t),null}}calculateTokenBreakdown(e){return e.reduce((e,t)=>({input:e.input+(t.message.usage.input_tokens||0),output:e.output+(t.message.usage.output_tokens||0),cacheCreation:e.cacheCreation+(t.message.usage.cache_creation_input_tokens||0),cacheRead:e.cacheRead+(t.message.usage.cache_read_input_tokens||0)}),{input:0,output:0,cacheCreation:0,cacheRead:0})}async getSessionInfo(e,t){let n=await this.getSessionUsage(e);if(!n||n.entries.length===0)return{cost:null,calculatedCost:null,officialCost:null,tokens:null,tokenBreakdown:null};let r=this.calculateTokenBreakdown(n.entries),i=r.input+r.output+r.cacheCreation+r.cacheRead,a=n.totalCost,o=t?.cost?.total_cost_usd??null;return{cost:a??o,calculatedCost:a,officialCost:o,tokens:i,tokenBreakdown:r}}},Ie=class{sessionProvider=new Fe;async getUsageInfo(e,t){try{return O(`Starting usage info retrieval for session: ${e}`),{session:await this.sessionProvider.getSessionInfo(e,t)}}catch(t){return O(`Error getting usage info for session ${e}:`,t),{session:{cost:null,calculatedCost:null,officialCost:null,tokens:null,tokenBreakdown:null}}}}},Le=class{thresholds={LOW:50,MEDIUM:80};config;constructor(e){this.config=e}getContextUsageThresholds(){return this.thresholds}getContextLimit(e){let t=this.config.modelContextLimits||{default:2e5};return t[this.getModelType(e)]||t.default||2e5}getModelType(e){let t=e.toLowerCase();return t.includes(`sonnet`)?`sonnet`:t.includes(`opus`)?`opus`:`default`}calculatePercentages(e,t,n=33e3){let r=Math.min(100,Math.max(0,Math.round(e/t*100))),i=Math.max(1,t-n),a=Math.min(100,Math.max(0,Math.round(e/i*100)));return{percentage:r,usablePercentage:a,contextLeftPercentage:Math.max(0,100-a),usableTokens:i}}calculateContextFromHookData(e,t=33e3){let n=e.context_window?.current_usage;if(!n)return O(`No current_usage in hook data, falling back to transcript parsing`),null;let r=e.context_window?.context_window_size||2e5,i=(n.input_tokens||0)+(n.cache_creation_input_tokens||0)+(n.cache_read_input_tokens||0);return O(`Native current_usage: input=${n.input_tokens}, cache_create=${n.cache_creation_input_tokens}, cache_read=${n.cache_read_input_tokens}, total=${i} (limit: ${r})`),{totalTokens:i,maxTokens:r,...this.calculatePercentages(i,r,t)}}async calculateContextTokensFromTranscript(e,t,n=33e3){try{O(`Calculating context tokens from transcript: ${e}`);try{if(!l(e,`utf-8`))return O(`Transcript file is empty`),null}catch{return O(`Could not read transcript file`),null}let r=await j(e);if(r.length===0)return O(`No entries in transcript`),null;let i=null;for(let e=r.length-1;e>=0;e--){let t=r[e];if(t&&t.message?.usage?.input_tokens&&t.isSidechain!==!0){i=t,O(`Context segment: Found most recent entry at ${t.timestamp.toISOString()}, stopping search`);break}}if(i?.message?.usage){let e=i.message.usage,r=(e.input_tokens||0)+(e.cache_read_input_tokens||0)+(e.cache_creation_input_tokens||0),a=t?this.getContextLimit(t):2e5;return O(`Most recent main chain context: ${r} tokens (limit: ${a})`),{totalTokens:r,maxTokens:a,...this.calculatePercentages(r,a,n)}}return O(`No main chain entries with usage data found`),null}catch(e){return O(`Error reading transcript: ${e instanceof Error?e.message:String(e)}`),null}}async getContextInfo(e,t=33e3){return this.calculateContextFromHookData(e,t)||this.calculateContextTokensFromTranscript(e.transcript_path,e.model?.id,t)}},Re=class{async loadTranscriptEntries(e){try{let t=await Ee(e);if(!t)return O(`No transcript found for session: ${e}`),[];O(`Loading transcript from: ${t}`);let n=(await b(t,`utf-8`)).trim().split(`
|
|
7
|
-
`).filter(e=>e.trim()),r=[];for(let e of n)try{let t=JSON.parse(e);if(t.isSidechain===!0)continue;r.push(t)}catch(e){O(`Failed to parse JSONL line: ${e}`);continue}return O(`Loaded ${r.length} transcript entries`),r}catch(t){return O(`Error loading transcript for ${e}:`,t),[]}}calculateMessageCount(e){return e.filter(e=>{let t=e.type||e.message?.role||e.message?.type,n=e.type===`user`&&e.message?.content?.[0]?.type===`tool_result`;return t===`user`&&!n}).length}calculateLastResponseTime(e){if(e.length===0)return null;let t=e.slice(-20),n=null,r=null;for(let e of t)if(e.timestamp)try{let t=new Date(e.timestamp),i=e.type||e.message?.role||e.message?.type,a=e.type===`user`&&e.message?.content?.[0]?.type===`tool_result`;if(i===`user`&&!a)n=t;else if(i===`assistant`&&n){let e=(t.getTime()-n.getTime())/1e3;e>.1&&e<300&&(r=e)}}catch{continue}return r}async getMetricsInfo(e,t){try{if(O(`Getting metrics from hook data for session: ${e}`),!t.cost)return O(`No cost data available in hook data`),{responseTime:null,lastResponseTime:null,sessionDuration:null,messageCount:null,linesAdded:null,linesRemoved:null};let n=await this.loadTranscriptEntries(e),r=this.calculateMessageCount(n),i=this.calculateLastResponseTime(n);return{responseTime:t.cost.total_api_duration_ms/1e3,lastResponseTime:i,sessionDuration:t.cost.total_duration_ms/1e3,messageCount:r,linesAdded:t.cost.total_lines_added,linesRemoved:t.cost.total_lines_removed}}catch(t){return O(`Error getting metrics from hook data for session ${e}:`,t),{responseTime:null,lastResponseTime:null,sessionDuration:null,messageCount:null,linesAdded:null,linesRemoved:null}}}};function I(e){return e===null?`$0.00`:e<.01?`<$0.01`:`$${e.toFixed(2)}`}function L(e){return e===null||e===0?`0 tokens`:e>=1e6?`${(e/1e6).toFixed(1)}M tokens`:e>=1e3?`${(e/1e3).toFixed(1)}K tokens`:`${e} tokens`}function ze(e){if(!e)return`0 tokens`;let t=[];if(e.input>0&&t.push(`${L(e.input).replace(` tokens`,``)} in`),e.output>0&&t.push(`${L(e.output).replace(` tokens`,``)} out`),e.cacheCreation>0||e.cacheRead>0){let n=e.cacheCreation+e.cacheRead;t.push(`${L(n).replace(` tokens`,``)} cached`)}return t.length>0?t.join(` + `):`0 tokens`}function Be(e){return e<60?`${e}s`:e<3600?`${Math.floor(e/60)}m`:e<86400?`${Math.floor(e/3600)}h`:e<604800?`${Math.floor(e/86400)}d`:`${Math.floor(e/604800)}w`}function Ve(e){return e<60?`${e.toFixed(0)}s`:e<3600?`${(e/60).toFixed(0)}m`:e<86400?`${(e/3600).toFixed(1)}h`:`${(e/86400).toFixed(1)}d`}const He=/^(?:(?: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 Ue(e){if(!e)return`Claude`;let t=e.trim().match(He);if(!t?.groups)return e;let{family:n,newMajor:r,newMinor:i,oldMajor:a,oldMinor:o,oldFamily:s}=t.groups,c=n||s,l=r||a,u=i||o;return c&&l?`${c.charAt(0).toUpperCase()+c.slice(1).toLowerCase()} ${u?`${l}.${u}`:l}`:e}function We(e){let t=e.includes(`/`)?`/`:`\\`,n=e.split(t);return n.map((e,t)=>t===n.length-1||e===`~`||e===``?e:e.charAt(0)).join(t)}function Ge(e){return e<60?`${e.toFixed(1)}s`:`${(e/60).toFixed(1)}m`}function Ke(e){let t=Math.floor(e/60),n=e%60;return t>0?`${t}h ${n}m left`:`${n}m left`}function qe(e,t){return!t||t<=0||e<0?null:Math.min(100,e/t*100)}function R(e,t,n=80){let r=qe(e,t);if(r===null)return{percentage:null,isWarning:!1,displayText:``};let i=`${r.toFixed(0)}%`,a=r>=n,o=``;return o=a?` !${i}`:r>=50?` +${i}`:` ${i}`,{percentage:r,isWarning:a,displayText:o}}const Je={ball:{filled:`─`,empty:`─`,marker:`●`},blocks:{filled:`█`,empty:`░`},"blocks-line":{filled:`█`,empty:`─`},capped:{filled:`━`,empty:`┄`,cap:`╸`},dots:{filled:`●`,empty:`○`},filled:{filled:`■`,empty:`□`},geometric:{filled:`▰`,empty:`▱`},line:{filled:`━`,empty:`┄`},squares:{filled:`◼`,empty:`◻`}};var Ye=class{constructor(e,t){this.config=e,this.symbols=t}renderDirectory(e,t,n){let r=e.workspace?.current_dir||e.cwd||`/`,i=e.workspace?.project_dir,a=n?.style??(n?.showBasename?`basename`:`full`);if(a===`basename`)return{text:u.basename(r)||`root`,bgColor:t.modeBg,fgColor:t.modeFg};let o=process.env.HOME||process.env.USERPROFILE,s=r,c=i;o&&(r.startsWith(o)&&(s=r.replace(o,`~`)),i&&i.startsWith(o)&&(c=i.replace(o,`~`)));let l=this.getDisplayDirectoryName(s,c);return a===`fish`&&(l=We(l)),{text:l,bgColor:t.modeBg,fgColor:t.modeFg}}renderGit(e,t,n){if(!e)return null;let r=[];if(n?.showRepoName&&e.repoName&&(r.push(e.repoName),e.isWorktree&&r.push(this.symbols.git_worktree)),n?.showOperation&&e.operation&&r.push(`[${e.operation}]`),r.push(`${this.symbols.branch} ${e.branch}`),n?.showTag&&e.tag&&r.push(`${this.symbols.git_tag} ${e.tag}`),n?.showSha&&e.sha&&r.push(`${this.symbols.git_sha} ${e.sha}`),n?.showAheadBehind!==!1&&(e.ahead>0&&e.behind>0?r.push(`${this.symbols.git_ahead}${e.ahead}${this.symbols.git_behind}${e.behind}`):e.ahead>0?r.push(`${this.symbols.git_ahead}${e.ahead}`):e.behind>0&&r.push(`${this.symbols.git_behind}${e.behind}`)),n?.showWorkingTree){let t=[];e.staged&&e.staged>0&&t.push(`+${e.staged}`),e.unstaged&&e.unstaged>0&&t.push(`~${e.unstaged}`),e.untracked&&e.untracked>0&&t.push(`?${e.untracked}`),e.conflicts&&e.conflicts>0&&t.push(`!${e.conflicts}`),t.length>0&&r.push(`(${t.join(` `)})`)}if(n?.showUpstream&&e.upstream&&r.push(`${this.symbols.git_upstream}${e.upstream}`),n?.showStashCount&&e.stashCount&&e.stashCount>0&&r.push(`${this.symbols.git_stash} ${e.stashCount}`),n?.showTimeSinceCommit&&e.timeSinceCommit!==void 0){let t=Be(e.timeSinceCommit);r.push(`${this.symbols.git_time} ${t}`)}let i=this.symbols.git_clean;return e.status===`conflicts`?i=this.symbols.git_conflicts:e.status===`dirty`&&(i=this.symbols.git_dirty),r.push(i),{text:r.join(` `),bgColor:t.gitBg,fgColor:t.gitFg}}renderModel(e,t){let n=Ue(e.model?.display_name||`Claude`);return{text:`${this.symbols.model} ${n}`,bgColor:t.modelBg,fgColor:t.modelFg}}renderSession(e,t,n){let r=n?.type||`cost`,i=n?.costSource,a=this.config.budget?.session,o=this.formatUsageWithBudget(i===`calculated`?e.session.calculatedCost:i===`official`?e.session.officialCost:e.session.cost,e.session.tokens,e.session.tokenBreakdown,r,a?.amount,a?.warningThreshold||80,a?.type);return{text:`${this.symbols.session_cost} ${o}`,bgColor:t.sessionBg,fgColor:t.sessionFg}}renderSessionId(e,t,n){return{text:n?.showIdLabel===!1?e:`${this.symbols.session_id} ${e}`,bgColor:t.sessionBg,fgColor:t.sessionFg}}renderTmux(e,t){return e?{text:`tmux:${e}`,bgColor:t.tmuxBg,fgColor:t.tmuxFg}:{text:`tmux:none`,bgColor:t.tmuxBg,fgColor:t.tmuxFg}}renderContext(e,t,n){let r=n?.displayStyle??`text`,i=r===`text`?`remaining`:`used`,a=n?.percentageMode??i,o=r===`bar`?{filled:this.symbols.bar_filled,empty:this.symbols.bar_empty}:Je[r]??null,s=a===`remaining`?`100%`:`0%`;if(!e)return o?{text:`${o.empty.repeat(10)} ${s}`,bgColor:t.contextBg,fgColor:t.contextFg}:{text:`${this.symbols.context_time} 0 (${s})`,bgColor:t.contextBg,fgColor:t.contextFg};let c=t.contextBg,l=t.contextFg;e.contextLeftPercentage<=20?(c=t.contextCriticalBg,l=t.contextCriticalFg):e.contextLeftPercentage<=40&&(c=t.contextWarningBg,l=t.contextWarningFg);let u=a===`remaining`?e.contextLeftPercentage:e.usablePercentage,d=Math.round(e.usablePercentage/100*10),f=10-d;if(o){let t=this.buildBar(o,d,f,10);return{text:n?.showPercentageOnly?`${t} ${u}%`:`${t} ${e.totalTokens.toLocaleString()} (${u}%)`,bgColor:c,fgColor:l}}return{text:n?.showPercentageOnly?`${this.symbols.context_time} ${u}%`:`${this.symbols.context_time} ${e.totalTokens.toLocaleString()} (${u}%)`,bgColor:c,fgColor:l}}buildBar(e,t,n,r){if(e.marker){let n=Math.min(t,r-1);return e.filled.repeat(n)+e.marker+e.empty.repeat(r-n-1)}return e.cap?t===0?e.cap+e.empty.repeat(r-1):t>=r?e.filled.repeat(r):e.filled.repeat(t-1)+e.cap+e.empty.repeat(n):e.filled.repeat(t)+e.empty.repeat(n)}renderMetrics(e,t,n,r){if(!e)return{text:`${this.symbols.metrics_response} new`,bgColor:t.metricsBg,fgColor:t.metricsFg};let i=[];if(r?.showLastResponseTime&&e.lastResponseTime!==null){let t=e.lastResponseTime<60?`${e.lastResponseTime.toFixed(1)}s`:`${(e.lastResponseTime/60).toFixed(1)}m`;i.push(`${this.symbols.metrics_last_response} ${t}`)}if(r?.showResponseTime!==!1&&e.responseTime!==null){let t=e.responseTime<60?`${e.responseTime.toFixed(1)}s`:`${(e.responseTime/60).toFixed(1)}m`;i.push(`${this.symbols.metrics_response} ${t}`)}if(r?.showDuration!==!1&&e.sessionDuration!==null){let t=Ve(e.sessionDuration);i.push(`${this.symbols.metrics_duration} ${t}`)}return r?.showMessageCount!==!1&&e.messageCount!==null&&i.push(`${this.symbols.metrics_messages} ${e.messageCount}`),r?.showLinesAdded!==!1&&e.linesAdded!==null&&e.linesAdded>0&&i.push(`${this.symbols.metrics_lines_added} ${e.linesAdded}`),r?.showLinesRemoved!==!1&&e.linesRemoved!==null&&e.linesRemoved>0&&i.push(`${this.symbols.metrics_lines_removed} ${e.linesRemoved}`),i.length===0?{text:`${this.symbols.metrics_response} active`,bgColor:t.metricsBg,fgColor:t.metricsFg}:{text:i.join(` `),bgColor:t.metricsBg,fgColor:t.metricsFg}}renderBlock(e,t,n){let r;if(e.cost===null&&e.tokens===null)r=`No active block`;else{let t=n?.type||`cost`,i=n?.burnType,a=this.config.budget?.block,o=e.timeRemaining===null?null:(()=>{let t=Math.floor(e.timeRemaining/60),n=e.timeRemaining%60;return t>0?`${t}h ${n}m`:`${n}m`})(),s;switch(t){case`cost`:s=this.formatUsageWithBudget(e.cost,null,null,`cost`,a?.amount,a?.warningThreshold,a?.type);break;case`tokens`:s=this.formatUsageWithBudget(null,e.tokens,null,`tokens`,a?.amount,a?.warningThreshold,a?.type);break;case`weighted`:let t=a?.type===`tokens`?a.amount:void 0,n=L(e.weightedTokens);s=t&&e.weightedTokens!==null?`${n}${R(e.weightedTokens,t,a?.warningThreshold||80).displayText}`:`${n} (weighted)`;break;case`both`:s=this.formatUsageWithBudget(e.cost,e.tokens,null,`both`,a?.amount,a?.warningThreshold,a?.type);break;case`time`:s=o||`N/A`;break;default:s=this.formatUsageWithBudget(e.cost,null,null,`cost`,a?.amount,a?.warningThreshold,a?.type)}let c=``;if(i&&i!==`none`)switch(i){case`cost`:c=` | ${e.burnRate===null?`N/A`:e.burnRate<1?`${(e.burnRate*100).toFixed(0)}¢/h`:`$${e.burnRate.toFixed(2)}/h`}`;break;case`tokens`:c=` | ${e.tokenBurnRate===null?`N/A`:`${L(Math.round(e.tokenBurnRate))}/h`}`;break;case`both`:c=` | ${e.burnRate===null?`N/A`:e.burnRate<1?`${(e.burnRate*100).toFixed(0)}¢/h`:`$${e.burnRate.toFixed(2)}/h`} / ${e.tokenBurnRate===null?`N/A`:`${L(Math.round(e.tokenBurnRate))}/h`}`;break}r=t===`time`?s:o?`${s}${c} (${o} left)`:`${s}${c}`}return{text:`${this.symbols.block_cost} ${r}`,bgColor:t.blockBg,fgColor:t.blockFg}}renderToday(e,t,n=`cost`){let r=this.config.budget?.today;return{text:`${this.symbols.today_cost} ${this.formatUsageWithBudget(e.cost,e.tokens,e.tokenBreakdown,n,r?.amount,r?.warningThreshold,r?.type)}`,bgColor:t.todayBg,fgColor:t.todayFg}}getDisplayDirectoryName(e,t){return e.startsWith(`~`)?e:t&&t!==e&&e.startsWith(t)?e.slice(t.length+1)||u.basename(t)||`project`:e}formatUsageDisplay(e,t,n,r){switch(r){case`cost`:return I(e);case`tokens`:return L(t);case`both`:return`${I(e)} (${L(t)})`;case`breakdown`:return ze(n);default:return I(e)}}formatUsageWithBudget(e,t,n,r,i,a=80,o){let s=this.formatUsageDisplay(e,t,n,r);if(i&&i>0){let n=null;if(o===`tokens`&&t!==null?n=t:(o===`cost`&&e!==null||!o&&e!==null)&&(n=e),n!==null)return s+R(n,i,a).displayText}return s}renderVersion(e,t,n){return e.version?{text:`${this.symbols.version} v${e.version}`,bgColor:t.versionBg,fgColor:t.versionFg}:null}renderEnv(e,t){let n=process.env[t.variable];if(!n)return null;let r=t.prefix??t.variable;return{text:r?`${this.symbols.env} ${r}: ${n}`:`${this.symbols.env} ${n}`,bgColor:e.envBg,fgColor:e.envFg}}};function Xe(e){return e.includes(`opus`)?5:(e.includes(`sonnet`)||e.includes(`haiku`),1)}function Ze(e){return{timestamp:e.timestamp,usage:{inputTokens:e.message?.usage?.input_tokens||0,outputTokens:e.message?.usage?.output_tokens||0,cacheCreationInputTokens:e.message?.usage?.cache_creation_input_tokens||0,cacheReadInputTokens:e.message?.usage?.cache_read_input_tokens||0},costUSD:e.costUSD||0,model:e.message?.model||`unknown`}}var Qe=class{sessionDurationHours=5;floorToHour(e){let t=new Date(e);return t.setUTCMinutes(0,0,0),t}identifySessionBlocks(e){if(e.length===0)return[];let t=this.sessionDurationHours*60*60*1e3,n=[],r=[...e].sort((e,t)=>e.timestamp.getTime()-t.timestamp.getTime()),i=null,a=[];for(let e of r){let r=e.timestamp;if(i==null)i=this.floorToHour(r),a=[e];else{let o=r.getTime()-i.getTime(),s=a[a.length-1];if(s==null)continue;let c=s.timestamp,l=r.getTime()-c.getTime();o>t||l>t?(n.push(a),i=this.floorToHour(r),a=[e]):a.push(e)}}return i!=null&&a.length>0&&n.push(a),n}createBlockInfo(e,t){let n=new Date,r=this.sessionDurationHours*60*60*1e3,i=new Date(e.getTime()+r),a=t[t.length-1],o=a==null?e:a.timestamp;return{block:t,isActive:n.getTime()-o.getTime()<r&&n<i}}findActiveBlock(e){for(let t=e.length-1;t>=0;t--){let n=e[t];if(!n||n.length===0)continue;let r=n[0];if(!r)continue;let i=this.floorToHour(r.timestamp),a=this.createBlockInfo(i,n);if(a.isActive)return a.block}return null}async loadUsageEntries(){try{O(`Block segment: Loading entries for dynamic session blocks`);let e=new Date;e.setDate(e.getDate()-1);let t=await M(void 0,(t,n)=>n>=e,!0),n=[];for(let e of t)if(e.message?.usage){let t=Ze(e);!t.costUSD&&e.raw&&(t.costUSD=await F.calculateCostForEntry(e.raw)),n.push(t)}let r=this.identifySessionBlocks(n);O(`Block segment: Found ${r.length} session blocks`);let i=this.findActiveBlock(r),a=[];if(i&&i.length>0){O(`Block segment: Found active block with ${i.length} entries`);let e=i[0],t=i[i.length-1];e&&t&&O(`Block segment: Active block from ${e.timestamp.toISOString()} to ${t.timestamp.toISOString()}`),a=i}else O(`Block segment: No active block found`),a=[];return a}catch(e){return O(`Error loading block entries:`,e),[]}}async getActiveBlockInfo(){try{let e=await this.loadUsageEntries();if(e.length===0)return O(`Block segment: No entries in current block`),{cost:null,tokens:null,weightedTokens:null,timeRemaining:null,burnRate:null,tokenBurnRate:null};let t=e.reduce((e,t)=>e+t.costUSD,0),n=e.reduce((e,t)=>e+t.usage.inputTokens+t.usage.outputTokens+t.usage.cacheCreationInputTokens+t.usage.cacheReadInputTokens,0),r=e.reduce((e,t)=>e+(t.usage.inputTokens+t.usage.outputTokens+t.usage.cacheCreationInputTokens+t.usage.cacheReadInputTokens)*Xe(t.model),0),i=new Date,a=null;if(e.length>0){let t=e[0];if(t){let e=this.sessionDurationHours*60*60*1e3,n=this.floorToHour(t.timestamp),r=new Date(n.getTime()+e);a=Math.max(0,Math.round((r.getTime()-i.getTime())/(1e3*60)))}}let o=null,s=null;if(e.length>=1&&(t>0||n>0)){let r=e.map(e=>e.timestamp).sort((e,t)=>e.getTime()-t.getTime()),i=r[0],a=r[r.length-1];if(i&&a){let e=(a.getTime()-i.getTime())/(1e3*60);e>0&&(t>0&&(o=t/e*60),n>0&&(s=n/e*60))}}return O(`Block segment: $${t.toFixed(2)}, ${n} tokens, ${a}m remaining, burn rate: ${o?`$`+o.toFixed(2)+`/hr`:`N/A`}`),{cost:t,tokens:n,weightedTokens:r,timeRemaining:a,burnRate:o,tokenBurnRate:s}}catch(e){return O(`Error getting active block info:`,e),{cost:null,tokens:null,weightedTokens:null,timeRemaining:null,burnRate:null,tokenBurnRate:null}}}};function z(e){return`${e.getFullYear()}-${String(e.getMonth()+1).padStart(2,`0`)}-${String(e.getDate()).padStart(2,`0`)}`}function $e(e){return e.inputTokens+e.outputTokens+e.cacheCreationInputTokens+e.cacheReadInputTokens}function et(e){return{timestamp:e.timestamp,usage:{inputTokens:e.message?.usage?.input_tokens||0,outputTokens:e.message?.usage?.output_tokens||0,cacheCreationInputTokens:e.message?.usage?.cache_creation_input_tokens||0,cacheReadInputTokens:e.message?.usage?.cache_read_input_tokens||0},costUSD:e.costUSD||0,model:e.message?.model||`unknown`}}var tt=class{async loadTodayEntries(){let e=z(new Date);O(`Today segment: Loading entries for date ${e}`);let t=await N.getLatestTranscriptMtime(),n=await N.getUsageCache(`today`,t);if(n)return O(`Using shared today usage cache`),n;let r=new Date;r.setDate(r.getDate()-1),r.setHours(0,0,0,0);let i=(e,t)=>t>=r,a=new Date;a.setHours(0,0,0,0);let o=await M(e=>e.timestamp>=a,i,!0),s=[],c=0;for(let t of o)if(z(t.timestamp)===e&&t.message?.usage){let e=et(t);!e.costUSD&&t.raw&&(e.costUSD=await F.calculateCostForEntry(t.raw)),s.push(e),c++}return O(`Today segment: Found ${c} entries for today (${e})`),await N.setUsageCache(`today`,s,t),s}async getTodayEntries(){try{return await this.loadTodayEntries()}catch(e){return O(`Error loading today's entries:`,e),[]}}async getTodayInfo(){try{let e=await this.getTodayEntries();if(e.length===0)return{cost:null,tokens:null,tokenBreakdown:null,date:z(new Date)};let t=e.reduce((e,t)=>e+t.costUSD,0),n=e.reduce((e,t)=>e+$e(t.usage),0),r=e.reduce((e,t)=>({input:e.input+t.usage.inputTokens,output:e.output+t.usage.outputTokens,cacheCreation:e.cacheCreation+t.usage.cacheCreationInputTokens,cacheRead:e.cacheRead+t.usage.cacheReadInputTokens}),{input:0,output:0,cacheCreation:0,cacheRead:0});return O(`Today segment: $${t.toFixed(2)}, ${n} tokens total`),{cost:t,tokens:n,tokenBreakdown:r,date:z(new Date)}}catch(e){return O(`Error getting today's info:`,e),{cost:null,tokens:null,tokenBreakdown:null,date:z(new Date)}}}};const nt={right:``,left_rounded:``,right_rounded:``,branch:`⎇`,model:`✱`,git_clean:`✓`,git_dirty:`●`,git_conflicts:`⚠`,git_ahead:`↑`,git_behind:`↓`,git_worktree:`⧉`,git_tag:`⌂`,git_sha:`♯`,git_upstream:`→`,git_stash:`⧇`,git_time:`◷`,session_cost:`§`,block_cost:`◱`,today_cost:`☉`,context_time:`◔`,metrics_response:`⧖`,metrics_last_response:`Δ`,metrics_duration:`⧗`,metrics_messages:`◆`,metrics_lines_added:`+`,metrics_lines_removed:`-`,metrics_burn:`↗`,version:`◈`,bar_filled:`▪`,bar_empty:`▫`,env:`⚙`,session_id:`⌗`},rt={topLeft:`╭`,topRight:`╮`,bottomLeft:`╰`,bottomRight:`╯`,horizontal:`─`,vertical:`│`,teeLeft:`├`,teeRight:`┤`},it={topLeft:`+`,topRight:`+`,bottomLeft:`+`,bottomRight:`+`,horizontal:`-`,vertical:`|`,teeLeft:`+`,teeRight:`+`},at={right:``,left_rounded:``,right_rounded:``,branch:`~`,model:`M`,git_clean:`=`,git_dirty:`*`,git_conflicts:`!`,git_ahead:`^`,git_behind:`v`,git_worktree:`W`,git_tag:`T`,git_sha:`#`,git_upstream:`>>`,git_stash:`S`,git_time:`@`,session_cost:`S`,block_cost:`B`,today_cost:`D`,context_time:`C`,metrics_response:`R`,metrics_last_response:`L`,metrics_duration:`T`,metrics_messages:`#`,metrics_lines_added:`+`,metrics_lines_removed:`-`,metrics_burn:`~/h`,version:`V`,bar_filled:`=`,bar_empty:`-`,env:`$`,session_id:`#`},ot=RegExp(`\x1B\\[[0-9;]*m`,`g`),st=/^[a-zA-Z0-9/]+$/;function ct(){if(process.platform===`win32`)return null;let e=process.pid.toString();for(let t=0;t<10;t++)try{let t=i(`ps -o ppid=,tty= -p ${e}`,{encoding:`utf8`,stdio:[`pipe`,`pipe`,`ignore`]}).trim().split(/\s+/),n=t[0],r=t[1];if(r&&r!==`?`&&r!==`??`&&st.test(r))return r;if(!n||n===`1`||n===`0`)break;e=n}catch{break}return null}function lt(){try{let e=i(`mode con`,{encoding:`utf8`,stdio:[`pipe`,`pipe`,`ignore`],windowsHide:!0}).match(/Columns:\s*(\d+)/i);if(e?.[1]){let t=parseInt(e[1],10);if(!isNaN(t)&&t>0)return t}}catch{}return null}function ut(){let e=ct();if(e)try{let t=i(`stty size < /dev/${e}`,{encoding:`utf8`,stdio:[`pipe`,`pipe`,`ignore`],shell:`/bin/sh`}).trim().split(` `)[1];if(t){let e=parseInt(t,10);if(!isNaN(e)&&e>0)return e}}catch{}try{let e=i(`tput cols 2>/dev/null`,{encoding:`utf8`,stdio:[`pipe`,`pipe`,`ignore`]}).trim(),t=parseInt(e,10);if(!isNaN(t)&&t>0)return t}catch{}return null}function dt(){let e=e=>Math.floor(e*.7),t=process.env.COLUMNS;if(t){let n=parseInt(t,10);if(!isNaN(n)&&n>0)return e(n)}if(process.stdout.columns&&process.stdout.columns>0)return e(process.stdout.columns);if(process.platform===`win32`){let t=lt();if(t)return e(t)}let n=ut();return n?e(n):null}function B(e){return e.replace(ot,``)}function V(e){return B(e).length}function H(e,t,n){return t?`${t}${e}${n}`:e}function ft(e,t){let n=V(e);return n>=t?e:e+` `.repeat(t-n)}const pt=RegExp(`(\x1B\\[[0-9;]*m)`);function mt(e,t){if(B(e).length<=t)return e;let n=0,r=``,i=e.split(pt);for(let e of i){if(e.startsWith(`\x1B`)){r+=e;continue}for(let i of e){if(n>=t-1)return r+=`…`,r;r+=i,n++}}return r}function U(e,t,n){let r=n-2,i=ft(mt(t,r),r);return e.vertical+` `+i+` `+e.vertical}function W(e,t){return e.teeLeft+e.horizontal.repeat(t)+e.teeRight}function ht(e,t){return e.bottomLeft+e.horizontal.repeat(t)+e.bottomRight}function gt(e,t){if(e.length===0)return``;if(e.length===1)return e[0]??``;let n=e.map(e=>V(e)),r=t-n.reduce((e,t)=>e+t,0),i=Math.max(2,Math.floor(r/(e.length-1))),a=Array(e.length);a[e.length-1]=n[e.length-1]??0;for(let t=e.length-2;t>=0;t--)a[t]=(a[t+1]??0)+(n[t]??0);let o=e[0]??``,s=n[0]??0;for(let r=1;r<e.length;r++){let c=t-s-(a[r]??0)-(e.length-1-r)*2,l=Math.max(2,Math.min(i,c));o+=` `.repeat(l)+(e[r]??``),s+=l+(n[r]??0)}return o}function G(e,t,n){if(!t)return e;if(!e)return t;let r=V(e),i=V(t),a=n-r-i;return a<2?`${e} ${t}`:e+` `.repeat(a)+t}function _t(e,t,n){let r=` ${Ue(e.hookData.model?.display_name||`Claude`).toLowerCase()} `,i=n-1-r.length-18;if(i<2){let e=n-1-r.length;return t.topLeft+t.horizontal+r+t.horizontal.repeat(Math.max(0,e))+t.topRight}return t.topLeft+t.horizontal+r+t.horizontal.repeat(i)+` claude-powerline `+t.topRight}function vt(e,t,n,r,i){let a=Math.min(Math.floor(t*.45),40);if(!e.contextInfo)return null;let o=e.contextInfo.usablePercentage,s=Math.round(o/100*a),c=a-s,l=n.bar_filled.repeat(s)+n.bar_empty.repeat(c),u=e.contextInfo.totalTokens>=1e3?`${(e.contextInfo.totalTokens/1e3).toFixed(0)}k`:`${e.contextInfo.totalTokens}`,d=e.contextInfo.maxTokens>=1e3?`${(e.contextInfo.maxTokens/1e3).toFixed(0)}k`:`${e.contextInfo.maxTokens}`,f=i.contextFg;return o>=80?f=i.contextCriticalFg:o>=60&&(f=i.contextWarningFg),H(`${l} ${o}% ${u}/${d}`,f,r)}function yt(e){let t=e.workspace?.current_dir||e.cwd||`/`,n=process.env.HOME||process.env.USERPROFILE;return n&&t.startsWith(n)?t.replace(n,`~`):t}function bt(e,t,n,r,i){let a=[];e.blockInfo&&a.push(H(J(e.blockInfo,t,n),i.blockFg,r)),e.usageInfo&&a.push(H(Y(e.usageInfo,t,n),i.sessionFg,r)),e.todayInfo&&a.push(H(St(e.todayInfo,t,n),i.todayFg,r));let o=xt(e,t);return o.length>0&&a.push(H(o.join(` · `),i.metricsFg,r)),a}function xt(e,t){let n=[];return e.metricsInfo&&(e.metricsInfo.sessionDuration!==null&&e.metricsInfo.sessionDuration>0&&n.push(`${t.metrics_duration} ${Ve(e.metricsInfo.sessionDuration)}`),e.metricsInfo.messageCount!==null&&e.metricsInfo.messageCount>0&&n.push(`${t.metrics_messages} ${e.metricsInfo.messageCount}`)),n}function K(e,t,n,r){let i=[];if(e.gitInfo){let a=`${t.branch} ${e.gitInfo.branch}`;e.gitInfo.status===`conflicts`?a+=` ${t.git_conflicts}`:e.gitInfo.status===`dirty`?a+=` ${t.git_dirty}`:a+=` ${t.git_clean}`,e.gitInfo.ahead>0&&(a+=` ${t.git_ahead}${e.gitInfo.ahead}`),e.gitInfo.behind>0&&(a+=` ${t.git_behind}${e.gitInfo.behind}`);let o=[];e.gitInfo.staged&&e.gitInfo.staged>0&&o.push(`+${e.gitInfo.staged}`),e.gitInfo.unstaged&&e.gitInfo.unstaged>0&&o.push(`~${e.gitInfo.unstaged}`),e.gitInfo.untracked&&e.gitInfo.untracked>0&&o.push(`?${e.gitInfo.untracked}`),o.length>0&&(a+=` (${o.join(` `)})`),i.push(H(a,r.gitFg,n))}let a=We(yt(e.hookData));return i.push(H(a,r.modeFg,n)),i}function q(e,t,n,r,i){let a=[];if(e.hookData.version&&a.push(H(`${t.version} v${e.hookData.version}`,i.versionFg,r)),e.tmuxSessionId&&a.push(H(`tmux:${e.tmuxSessionId}`,i.tmuxFg,r)),e.metricsInfo){let n=[];if(e.metricsInfo.responseTime!==null&&!isNaN(e.metricsInfo.responseTime)&&e.metricsInfo.responseTime>0&&n.push(`${t.metrics_response} ${Ge(e.metricsInfo.responseTime)}`),e.metricsInfo.linesAdded!==null&&e.metricsInfo.linesAdded>0&&n.push(`${t.metrics_lines_added}${e.metricsInfo.linesAdded}`),e.metricsInfo.linesRemoved!==null&&e.metricsInfo.linesRemoved>0&&n.push(`${t.metrics_lines_removed}${e.metricsInfo.linesRemoved}`),e.blockInfo?.burnRate!==null&&e.blockInfo?.burnRate!==void 0&&e.blockInfo.burnRate>0){let r=e.blockInfo.burnRate<1?`${(e.blockInfo.burnRate*100).toFixed(0)}c/h`:`$${e.blockInfo.burnRate.toFixed(2)}/h`;n.push(`${t.metrics_burn} ${r}`)}n.length>0&&a.push(H(n.join(` · `),i.metricsFg,r))}let o=n.display.lines.map(e=>e.segments.env).find(e=>e?.enabled);if(o&&o.variable){let e=process.env[o.variable];if(e){let t=o.prefix??o.variable;a.push(H(t?`${t}:${e}`:e,i.envFg,r))}}return a}function J(e,t,n){let r=I(e.cost),i=`${t.block_cost} ${r}`;e.timeRemaining!==null&&(i+=` · ${Ke(e.timeRemaining)}`);let a=n.budget?.block;if(a?.amount&&e.cost!==null){let t=R(e.cost,a.amount,a.warningThreshold||80);i+=t.displayText}return i}function Y(e,t,n){let r=I(e.session.cost),i=e.session.tokens,a=i!==null&&i>0?L(i).replace(` tokens`,``):null,o=`${t.session_cost} ${r}`;a&&(o+=` · ${a}`);let s=n.budget?.session;if(s?.amount&&e.session.cost!==null){let t=R(e.session.cost,s.amount,s.warningThreshold||80);o+=t.displayText}return o}function St(e,t,n){let r=I(e.cost),i=`${t.today_cost} ${r} today`,a=n.budget?.today;if(a?.amount&&e.cost!==null){let t=R(e.cost,a.amount,a.warningThreshold||80);i+=t.displayText}return i}function Ct(e){let{lines:t,data:n,box:r,contentWidth:i,innerWidth:a,sym:o,config:s,reset:c,colors:l}=e,u=bt(n,o,s,c,l);u.length>0&&t.push(U(r,gt(u,i),a))}function wt(e){let{lines:t,data:n,box:r,contentWidth:i,innerWidth:a,sym:o,config:s,reset:c,colors:l}=e,u=K(n,o,c,l),d=q(n,o,s,c,l),f=u.join(` `),p=d.join(` · `);(f||p)&&(t.push(W(r,a)),t.push(U(r,G(f,p,i),a)))}function Tt(e){let{lines:t,data:n,box:r,contentWidth:i,innerWidth:a,sym:o,config:s,reset:c,colors:l}=e,u=[],d=[];n.blockInfo&&u.push(H(J(n.blockInfo,o,s),l.blockFg,c)),n.todayInfo&&u.push(H(St(n.todayInfo,o,s),l.todayFg,c)),n.usageInfo&&d.push(H(Y(n.usageInfo,o,s),l.sessionFg,c));let f=xt(n,o);f.length>0&&d.push(H(f.join(` · `),l.metricsFg,c)),u.length>0&&t.push(U(r,G(u[0]??``,u[1]??``,i),a)),d.length>0&&t.push(U(r,G(d[0]??``,d[1]??``,i),a))}function Et(e){let{lines:t,data:n,box:r,contentWidth:i,innerWidth:a,sym:o,config:s,reset:c,colors:l}=e,u=K(n,o,c,l);u.length>0&&(t.push(W(r,a)),t.push(U(r,G(u[0]??``,u[1]??``,i),a)));let d=q(n,o,s,c,l);d.length>0&&(t.push(W(r,a)),t.push(U(r,d.join(` · `),a)))}function Dt(e){let{lines:t,data:n,box:r,contentWidth:i,innerWidth:a,sym:o,config:s,reset:c,colors:l}=e;n.blockInfo&&t.push(U(r,H(J(n.blockInfo,o,s),l.blockFg,c),a));let u=[];n.usageInfo&&u.push(H(`${o.session_cost} ${I(n.usageInfo.session.cost)}`,l.sessionFg,c)),n.todayInfo&&u.push(H(`${o.today_cost} ${I(n.todayInfo.cost)} today`,l.todayFg,c)),u.length>0&&t.push(U(r,G(u[0]??``,u[1]??``,i),a))}function Ot(e){let{lines:t,data:n,box:r,contentWidth:i,innerWidth:a,sym:o,config:s,reset:c,colors:l}=e,u=K(n,o,c,l);u.length>0&&(t.push(W(r,a)),t.push(U(r,G(u[0]??``,u[1]??``,i),a)));let d=q(n,o,s,c,l);d.length>0&&t.push(U(r,d.join(` · `),a))}function kt(e){return e>=80?`wide`:e>=55?`medium`:`narrow`}function At(e){return e&&e>0?Math.max(32,e):80}function jt(e,t,n,r,i){let a=(i.display.charset||`unicode`)===`text`?at:nt,o=e.colors,s=At(r),c=s-2,l=c-2,u=kt(s),d=[];d.push(_t(e,t,c));let f=vt(e,l,a,n,o);f&&d.push(U(t,f,c));let p={lines:d,data:e,box:t,contentWidth:l,innerWidth:c,sym:a,config:i,reset:n,colors:o};return u===`wide`?(Ct(p),wt(p)):u===`medium`?(Tt(p),Et(p)):(Dt(p),Ot(p)),d.push(ht(t,c)),`\x1B[?2026h`+d.join(`
|
|
8
|
-
`)+`\x1B[?2026l`}var
|
|
9
|
-
`)}async generateAutoWrapStatusline(e,t,n,r,i,a){let o=this.getThemeColors(),s=e.workspace?.current_dir||e.cwd||`/`,c=
|
|
10
|
-
`)}async generateTuiStatusline(e){let t=this.getThemeColors(),n=dt(),r=e.workspace?.current_dir||e.cwd||`/`,i=(this.config.display.charset||`unicode`)===`text`?it:rt,a=this.config.display.lines.map(e=>e.segments.context).find(e=>e?.enabled)?.autocompactBuffer??33e3,o=await Promise.allSettled([this.usageProvider.getUsageInfo(e.session_id,e),this.blockProvider.getActiveBlockInfo(),this.todayProvider.getTodayInfo(),this.contextProvider.getContextInfo(e,a),this.metricsProvider.getMetricsInfo(e.session_id,e),this.gitService.getGitInfo(r,{showSha:!1,showWorkingTree:!0,showOperation:!1,showTag:!1,showTimeSinceCommit:!1,showStashCount:!1,showUpstream:!1,showRepoName:!1},e.workspace?.project_dir),this.tmuxService.getSessionId()]),s=e=>e.status===`fulfilled`?e.value:null,[c,l,u,d,f,p,m]=[s(o[0]),s(o[1]),s(o[2]),s(o[3]),s(o[4]),s(o[5]),s(o[6])];return jt({hookData:e,usageInfo:c,blockInfo:l,todayInfo:u,contextInfo:d,metricsInfo:f,gitInfo:p,tmuxSessionId:m,colors:t},i,t.reset,n,this.config)}calculateSegmentWidth(e,t){let n=this.config.display.style===`capsule`,r=V(e.text),i=(this.config.display.padding??1)*2;return n?r+(2+i+(t?0:1)):r+(1+i)}buildLineFromSegments(e,t){let n=this.config.display.style===`capsule`,r=t.reset;for(let i=0;i<e.length;i++){let a=e[i];if(!a)continue;let o=i===0,s=i===e.length-1?null:e[i+1];n&&!o&&(r+=` `),r+=this.formatSegment(a.bgColor,a.fgColor,a.text,s?.bgColor,t)}return r}async renderLine(e,t,n,r,i,a,o){let s=this.getThemeColors(),c=t.workspace?.current_dir||t.cwd||`/`,l=Object.entries(e.segments).filter(([e,t])=>t?.enabled).map(([e,t])=>({type:e,config:t})),u=[];for(let e of l){let l=await this.renderSegment(e,t,n,r,i,a,o,s,c);l&&u.push({type:e.type,text:l.text,bgColor:l.bgColor,fgColor:l.fgColor})}return this.buildLineFromSegments(u,s)}async renderSegment(e,t,n,r,i,a,o,s,c){return e.type===`directory`?this.segmentRenderer.renderDirectory(t,s,e.config):e.type===`model`?this.segmentRenderer.renderModel(t,s):e.type===`git`?await this.renderGitSegment(e.config,t,s,c):e.type===`session`?this.renderSessionSegment(e.config,n,s):e.type===`sessionId`?t.session_id?this.segmentRenderer.renderSessionId(t.session_id,s,e.config):null:e.type===`tmux`?await this.renderTmuxSegment(s):e.type===`context`?this.renderContextSegment(e.config,a,s):e.type===`metrics`?this.renderMetricsSegment(e.config,o,r,s):e.type===`block`?this.renderBlockSegment(e.config,r,s):e.type===`today`?this.renderTodaySegment(e.config,i,s):e.type===`version`?this.renderVersionSegment(e.config,t,s):e.type===`env`?this.segmentRenderer.renderEnv(s,e.config):null}async renderGitSegment(e,t,n,r){if(!this.needsSegmentInfo(`git`))return null;let i=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 i?this.segmentRenderer.renderGit(i,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`,i=t===`text`?at:nt;return{right:n?``:r?i.right_rounded:i.right,left:r?i.left_rounded:``,branch:i.branch,model:i.model,git_clean:i.git_clean,git_dirty:i.git_dirty,git_conflicts:i.git_conflicts,git_ahead:i.git_ahead,git_behind:i.git_behind,git_worktree:i.git_worktree,git_tag:i.git_tag,git_sha:i.git_sha,git_upstream:i.git_upstream,git_stash:i.git_stash,git_time:i.git_time,session_cost:i.session_cost,block_cost:i.block_cost,today_cost:i.today_cost,context_time:i.context_time,metrics_response:i.metrics_response,metrics_last_response:i.metrics_last_response,metrics_duration:i.metrics_duration,metrics_messages:i.metrics_messages,metrics_lines_added:i.metrics_lines_added,metrics_lines_removed:i.metrics_lines_removed,metrics_burn:i.metrics_burn,version:i.version,bar_filled:i.bar_filled,bar_empty:i.bar_empty,env:i.env,session_id:i.session_id}}getThemeColors(){let e=this.config.theme,t,n=this.config.display.colorCompatibility||`auto`,r=n===`auto`?C():n;if(e===`custom`){if(t=this.config.colors?.custom,!t)throw Error(`Custom theme selected but no colors provided in configuration`)}else t=D(e,r),t||=(console.warn(`Built-in theme '${e}' not found, falling back to 'dark' theme`),D(`dark`,r));let i=D(`dark`,r),a=this.config.display.style===`tui`,o=e===`light`?`#f0f0f0`:`#1e1e1e`,s=e=>{let n=t[e]||i[e],s=n.fg;return a&&re(s,o)<60&&(s=n.bg),r===`none`?{bg:``,fg:``}:r===`ansi`?{bg:T(n.bg,!0),fg:T(s,!1)}:r===`ansi256`?{bg:w(n.bg,!0),fg:w(s,!1)}:{bg:ne(n.bg,!0),fg:ne(s,!1)}},c=s(`directory`),l=s(`git`),u=s(`model`),d=s(`session`),f=s(`block`),p=s(`today`),m=s(`tmux`),h=s(`context`),g=s(`contextWarning`),_=s(`contextCritical`),v=s(`metrics`),y=s(`version`),b=s(`env`);return{reset:r===`none`?``:`\x1B[0m`,modeBg:c.bg,modeFg:c.fg,gitBg:l.bg,gitFg:l.fg,modelBg:u.bg,modelFg:u.fg,sessionBg:d.bg,sessionFg:d.fg,blockBg:f.bg,blockFg:f.fg,todayBg:p.bg,todayFg:p.fg,tmuxBg:m.bg,tmuxFg:m.fg,contextBg:h.bg,contextFg:h.fg,contextWarningBg:g.bg,contextWarningFg:g.fg,contextCriticalBg:_.bg,contextCriticalFg:_.fg,metricsBg:v.bg,metricsFg:v.fg,versionBg:y.bg,versionFg:y.fg,envBg:b.bg,envFg:b.fg}}getSegmentBgColor(e,t){switch(e){case`directory`:return t.modeBg;case`git`:return t.gitBg;case`model`:return t.modelBg;case`session`:case`sessionId`: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,i){let a=this.config.display.style===`capsule`,o=` `.repeat(this.config.display.padding??1);if(a){let r=this.config.display.colorCompatibility||`auto`,a=S(e,(r===`auto`?C():r)===`ansi`);return`${`${a}${this.symbols.left}${i.reset}`}${`${e}${t}${o}${n}${o}${i.reset}`}${`${a}${this.symbols.right}${i.reset}`}`}let s=`${e}${t}${o}${n}${o}`,c=this.config.display.colorCompatibility||`auto`,l=(c===`auto`?C():c)===`ansi`;if(r){let t=S(e,l);s+=`${i.reset}${r}${t}${this.symbols.right}`}else s+=`${i.reset}${S(e,l)}${this.symbols.right}${i.reset}`;return s}};const Nt={theme:`dark`,display:{style:`minimal`,charset:`unicode`,colorCompatibility:`auto`,autoWrap:!0,padding:1,lines:[{segments:{directory:{enabled:!0,style:`basename`},git:{enabled:!0,showSha:!1,showWorkingTree:!1,showOperation:!1,showTag:!1,showTimeSinceCommit:!1,showStashCount:!1,showUpstream:!1,showRepoName:!1},model:{enabled:!0},session:{enabled:!0,type:`tokens`,costSource:`calculated`},today:{enabled:!0,type:`cost`},block:{enabled:!1,type:`cost`,burnType:`cost`},version:{enabled:!1},tmux:{enabled:!1},sessionId:{enabled:!1,showIdLabel:!0},context:{enabled:!0,showPercentageOnly:!1,displayStyle:`text`,autocompactBuffer:33e3},metrics:{enabled:!1,showResponseTime:!0,showLastResponseTime:!0,showDuration:!0,showMessageCount:!0,showLinesAdded:!0,showLinesRemoved:!0}}}]},budget:{session:{warningThreshold:80},today:{warningThreshold:80,amount:50},block:{warningThreshold:80,amount:15}},modelContextLimits:{default:2e5,sonnet:2e5,opus:2e5}};function X(e){return[`light`,`dark`,`nord`,`tokyo-night`,`rose-pine`,`gruvbox`,`custom`].includes(e)}function Z(e){return e===`minimal`||e===`powerline`||e===`capsule`||e===`tui`}function Pt(e){return e===`unicode`||e===`text`}function Q(e,t){for(let n=0;n<e.length;n++){let r=e[n];if(r===t&&n+1<e.length)return e[n+1];if(r?.startsWith(`${t}=`))return r.split(`=`)[1]}}function $(e,t){let n={...e};for(let e in t){let r=t[e];r!==void 0&&(typeof r==`object`&&r&&!Array.isArray(r)?n[e]=$(n[e]||{},r):n[e]=r)}return n}function Ft(e,t){return e?o.existsSync(e)?e:null:[...t?[u.join(t,`.claude-powerline.json`)]:[],u.join(process.cwd(),`.claude-powerline.json`),u.join(g.homedir(),`.claude`,`claude-powerline.json`),u.join(g.homedir(),`.config`,`claude-powerline`,`config.json`)].find(o.existsSync)||null}function It(e){try{let t=o.readFileSync(e,`utf-8`);return JSON.parse(t)}catch(t){throw Error(`Failed to load config file ${e}: ${t instanceof Error?t.message:String(t)}`)}}function Lt(){let e={},t={},n=process.env.CLAUDE_POWERLINE_THEME;n&&X(n)&&(e.theme=n);let r=process.env.CLAUDE_POWERLINE_STYLE;return r&&(Z(r)?t.style=r:(console.warn(`Invalid display style '${r}' from environment variable, falling back to 'minimal'`),t.style=`minimal`)),Object.keys(t).length>0&&(e.display=t),e}function Rt(){return process.env.CLAUDE_POWERLINE_CONFIG}function zt(e){let t={},n={},r=Q(e,`--theme`);r&&X(r)&&(t.theme=r);let i=Q(e,`--style`);i&&(Z(i)?n.style=i:(console.warn(`Invalid display style '${i}' from CLI argument, falling back to 'minimal'`),n.style=`minimal`));let a=Q(e,`--charset`);return a&&(Pt(a)?n.charset=a:(console.warn(`Invalid charset '${a}' from CLI argument, falling back to 'unicode'`),n.charset=`unicode`)),Object.keys(n).length>0&&(t.display=n),t}function Bt(e=process.argv,t){let n=JSON.parse(JSON.stringify(Nt)),r=Q(e,`--config`)||Rt(),i=Ft(r?.startsWith(`~`)?r.replace(`~`,g.homedir()):r,t);if(i)try{let e=It(i);n=$(n,e)}catch(e){console.warn(`Warning: ${e instanceof Error?e.message:String(e)}`)}n.display?.style&&!Z(n.display.style)&&(console.warn(`Invalid display style '${n.display.style}' in config file, falling back to 'minimal'`),n.display.style=`minimal`),n.display?.charset&&!Pt(n.display.charset)&&(console.warn(`Invalid charset '${n.display.charset}' in config file, falling back to 'unicode'`),n.display.charset=`unicode`),n.theme&&!X(n.theme)&&(console.warn(`Invalid theme '${n.theme}' in config file, falling back to 'dark'`),n.theme=`dark`);let a=Lt();n=$(n,a);let o=zt(e);return n=$(n,o),n}const Vt=Bt;function Ht(){console.log(`
|
|
2
|
+
import e from"node:process";import{json as t}from"node:stream/consumers";import n from"node:tty";import{exec as r,execSync as i}from"node:child_process";import{promisify as a}from"node:util";import o,{createReadStream as s,existsSync as c,readFileSync as l}from"node:fs";import u,{dirname as d,join as f,posix as p}from"node:path";import{get as m}from"node:https";import{URL as h}from"node:url";import g,{homedir as _}from"node:os";import{createHash as v}from"node:crypto";import{setTimeout as y}from"node:timers/promises";import{readFile as b,readdir as x,stat as ee}from"node:fs/promises";import{createInterface as te}from"node:readline";function ne(e,t){if(t&&(e.toLowerCase()===`transparent`||e.toLowerCase()===`none`))return`\x1B[49m`;let n=parseInt(e.slice(1,3),16),r=parseInt(e.slice(3,5),16),i=parseInt(e.slice(5,7),16);return`\x1b[${t?`48`:`38`};2;${n};${r};${i}m`}function S(e,t=!1){if(!e||e===``)return``;let n=e.match(/48;2;(\d+);(\d+);(\d+)/);if(n)return`\x1b[38;2;${n[1]};${n[2]};${n[3]}m`;if(t)return`\x1B[37m`;if(e.includes(`\x1B[`)&&e.includes(`m`)){let t=e.match(/\[(\d+)m/);if(t&&t[1]){let e=parseInt(t[1],10);if(e>=40&&e<=47||e>=100&&e<=107)return`\x1b[${e-10}m`}}return e.replace(`48`,`38`)}function C(){let{env:t}=e,r=!0;t.NO_COLOR&&t.NO_COLOR!==``&&(r=!1);let i=t.FORCE_COLOR;if(i&&i!==``)return i===`false`||i===`0`?`none`:i===`true`||i===`1`?`ansi`:i===`2`?`ansi256`:i===`3`?`truecolor`:`ansi`;if(!r||t.TERM===`dumb`)return`none`;if(t.CI)return[`GITHUB_ACTIONS`,`GITEA_ACTIONS`,`CIRCLECI`].some(e=>e in t)?`truecolor`:`ansi`;if(t.COLORTERM===`truecolor`||[`xterm-kitty`,`xterm-ghostty`,`wezterm`,`alacritty`,`foot`,`contour`].includes(t.TERM||``))return`truecolor`;if(t.TERM_PROGRAM)switch(t.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(t.TERM||``))return`ansi256`;if(/-truecolor$/i.test(t.TERM||``))return`truecolor`;if(/^screen|^xterm|^vt100|^vt220|^rxvt|color|ansi|cygwin|linux/i.test(t.TERM||``)||t.COLORTERM)return`ansi`;if(n?.WriteStream?.prototype?.hasColors)try{if(!n.WriteStream.prototype.hasColors())return`none`;let e=n.WriteStream.prototype.hasColors(256);return n.WriteStream.prototype.hasColors(16777216)?`truecolor`:e?`ansi256`:`ansi`}catch{}return`ansi`}function w(e,t){if(t&&(e.toLowerCase()===`transparent`||e.toLowerCase()===`none`))return`\x1B[49m`;let n=((e,t,n)=>e===t&&t===n?e<8?16:e>248?231:Math.round((e-8)/247*24)+232:16+36*Math.round(e/255*5)+6*Math.round(t/255*5)+Math.round(n/255*5))(parseInt(e.slice(1,3),16),parseInt(e.slice(3,5),16),parseInt(e.slice(5,7),16));return`\x1b[${t?`48`:`38`};5;${n}m`}function re(e,t){if(t&&(e.toLowerCase()===`transparent`||e.toLowerCase()===`none`))return`\x1B[49m`;if(t)return``;let n=parseInt(e.slice(1,3),16),r=parseInt(e.slice(3,5),16),i=parseInt(e.slice(5,7),16);return r>n&&r>i&&r>120?`\x1B[32m`:n>r&&n>i&&n>120?`\x1B[31m`:i>n&&i>r&&i>120?`\x1B[34m`:(n+r+i)/3>150?`\x1B[37m`:`\x1B[90m`}function ie(e,t){let n=parseInt(e.slice(1,3),16),r=parseInt(e.slice(3,5),16),i=parseInt(e.slice(5,7),16),a=parseInt(t.slice(1,3),16),o=parseInt(t.slice(3,5),16),s=parseInt(t.slice(5,7),16);return Math.sqrt((n-a)**2+(r-o)**2+(i-s)**2)}const ae={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`},weekly:{bg:`#2a2a3a`,fg:`#a0c4e8`}},oe={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`},weekly:{bg:`#303030`,fg:`#87afd7`}},se={directory:{bg:`#d75f00`,fg:`#ffffff`},git:{bg:`#585858`,fg:`#ffffff`},model:{bg:`#444444`,fg:`#ffffff`},session:{bg:`#303030`,fg:`#00ffff`},block:{bg:`#3a3a3a`,fg:`#5fafff`},today:{bg:`#262626`,fg:`#00ff00`},tmux:{bg:`#585858`,fg:`#00ff00`},context:{bg:`#808080`,fg:`#ffffff`},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`},weekly:{bg:`#3a3a3a`,fg:`#5fafff`}},ce={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`},weekly:{bg:`#4f46e5`,fg:`#ffffff`}},le={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`},weekly:{bg:`#5f5fff`,fg:`#ffffff`}},ue={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`},weekly:{bg:`#5f5fff`,fg:`#ffffff`}},de={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`},weekly:{bg:`#3b4252`,fg:`#88c0d0`}},fe={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`},weekly:{bg:`#4e4e4e`,fg:`#5fafaf`}},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`},weekly:{bg:`#585858`,fg:`#00d7d7`}},me={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`},weekly:{bg:`#24283b`,fg:`#7dcfff`}},he={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`},weekly:{bg:`#303050`,fg:`#5fd7ff`}},ge={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`},weekly:{bg:`#444470`,fg:`#00d7ff`}},_e={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`},weekly:{bg:`#21202e`,fg:`#c4a7e7`}},ve={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`},weekly:{bg:`#303030`,fg:`#d787d7`}},ye={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`},weekly:{bg:`#444444`,fg:`#ff87ff`}},be={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`},weekly:{bg:`#3c3836`,fg:`#8ec07c`}},xe={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`},weekly:{bg:`#444444`,fg:`#87af87`}},Se={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`},weekly:{bg:`#585858`,fg:`#00d787`}},T={dark:ae,"dark-ansi256":oe,"dark-ansi":se,light:ce,"light-ansi256":le,"light-ansi":ue,nord:de,"nord-ansi256":fe,"nord-ansi":pe,"tokyo-night":me,"tokyo-night-ansi256":he,"tokyo-night-ansi":ge,"rose-pine":_e,"rose-pine-ansi256":ve,"rose-pine-ansi":ye,gruvbox:be,"gruvbox-ansi256":xe,"gruvbox-ansi":Se};function E(e,t){let n=T[e];if(!n)return null;if(t===`none`||t===`ansi`){let t=T[`${e}-ansi`];if(t)return t}if(t===`ansi256`){let t=T[`${e}-ansi256`];if(t)return t}return n}const D=(e,...t)=>{process.env.CLAUDE_POWERLINE_DEBUG&&console.error(`[DEBUG] ${e}`,...t)},Ce=a(r);var we=class{isGitRepo(e){try{return o.existsSync(u.join(e,`.git`))}catch{return!1}}async execGitAsync(e,t){return Ce(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,i=this.isWorktree(e);if(i)r=e;else if(n&&this.isGitRepo(n))r=n;else if(this.isGitRepo(e))r=e;else{let t=await this.findGitRoot(e);if(!t)return null;r=t}try{let e=await this.getStatusWithBranchAsync(r),n=await this.getAheadBehindAsync(r),a={branch:e.branch||`detached`,status:e.status,ahead:n.ahead,behind:n.behind};t.showWorkingTree&&e.workingTree&&(a.staged=e.workingTree.staged,a.unstaged=e.workingTree.unstaged,a.untracked=e.workingTree.untracked,a.conflicts=e.workingTree.conflicts);let o={},s={};t.showSha&&(o.sha=this.getShaAsync(r)),t.showTag&&(o.tag=this.getNearestTagAsync(r)),t.showTimeSinceCommit&&(o.timeSinceCommit=this.getTimeSinceLastCommitAsync(r)),t.showStashCount&&(s.stashCount=this.getStashCountAsync(r)),t.showUpstream&&(s.upstream=this.getUpstreamAsync(r)),t.showRepoName&&(s.repoName=this.getRepoNameAsync(r));let c=new Map;for(let[e,t]of Object.entries(o))try{let n=await t;c.set(e,n)}catch{}return Object.keys(s).length>0&&(await Promise.allSettled(Object.entries(s).map(async([e,t])=>({key:e,value:await t})))).forEach(e=>{e.status===`fulfilled`&&c.set(e.value.key,e.value.value)}),t.showSha&&(a.sha=c.get(`sha`)||void 0),t.showOperation&&(a.operation=this.getOngoingOperation(r)||void 0),t.showTag&&(a.tag=c.get(`tag`)||void 0),t.showTimeSinceCommit&&(a.timeSinceCommit=c.get(`timeSinceCommit`)||void 0),t.showStashCount&&(a.stashCount=c.get(`stashCount`)||0),t.showUpstream&&(a.upstream=c.get(`upstream`)||void 0),t.showRepoName&&(a.repoName=c.get(`repoName`)||void 0,a.isWorktree=i),a}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=u.join(e,`.git`);if(o.existsSync(t)&&o.statSync(t).isFile()){let n=o.readFileSync(t,`utf-8`).match(/^gitdir:\s*(.+)$/m);if(n?.[1])return u.resolve(e,n[1].trim())}return t}getOngoingOperation(e){try{let t=this.resolveGitDir(e);return o.existsSync(u.join(t,`MERGE_HEAD`))?`MERGE`:o.existsSync(u.join(t,`CHERRY_PICK_HEAD`))?`CHERRY-PICK`:o.existsSync(u.join(t,`REVERT_HEAD`))?`REVERT`:o.existsSync(u.join(t,`BISECT_LOG`))?`BISECT`:o.existsSync(u.join(t,`rebase-merge`))||o.existsSync(u.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 t=(await this.execGitAsync(`git log -1 --format=%ct`,{cwd:e,encoding:`utf8`,timeout:2e3})).stdout.trim();if(!t)return null;let n=parseInt(t)*1e3,r=Date.now();return Math.floor((r-n)/1e3)}catch{return null}}async getStashCountAsync(e){try{let t=(await this.execGitAsync(`git stash list`,{cwd:e,encoding:`utf8`,timeout:2e3})).stdout.trim();return t?t.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 t=(await this.execGitAsync(`git config --get remote.origin.url`,{cwd:e,encoding:`utf8`,timeout:2e3})).stdout.trim();return t&&t.match(/\/([^/]+?)(\.git)?$/)?.[1]||u.basename(e)}catch{return u.basename(e)}}isWorktree(e){try{let t=u.join(e,`.git`);return!!(o.existsSync(t)&&o.statSync(t).isFile())}catch{return!1}}async getStatusWithBranchAsync(e){try{D(`[GIT-EXEC] Running git status in ${e}`);let t=(await this.execGitAsync(`git status --porcelain -b`,{cwd:e,encoding:`utf8`,timeout:2e3})).stdout.split(`
|
|
4
|
+
`),n=null,r=`clean`,i=0,a=0,o=0,s=0;for(let e of t)if(e){if(e.startsWith(`## `)){let t=e.substring(3).split(`...`)[0];t&&t!==`HEAD (no branch)`&&(n=t);continue}if(e.length>=2){let t=e.charAt(0),n=e.charAt(1);if(t===`?`&&n===`?`){o++,r===`clean`&&(r=`dirty`);continue}let c=t+n;if([`DD`,`AU`,`UD`,`UA`,`DU`,`AA`,`UU`].includes(c)){s++,r=`conflicts`;continue}t!==` `&&t!==`?`&&(i++,r===`clean`&&(r=`dirty`)),n!==` `&&n!==`?`&&(a++,r===`clean`&&(r=`dirty`))}}return{branch:n||await this.getFallbackBranch(e),status:r,workingTree:{staged:i,unstaged:a,untracked:o,conflicts:s}}}catch(t){return D(`Git status with branch command failed in ${e}:`,t),{branch:await this.getFallbackBranch(e),status:`clean`}}}async getFallbackBranch(e){try{let t=(await this.execGitAsync(`git branch --show-current`,{cwd:e,encoding:`utf8`,timeout:2e3})).stdout.trim();if(t)return t}catch{try{let t=(await this.execGitAsync(`git symbolic-ref --short HEAD`,{cwd:e,encoding:`utf8`,timeout:2e3})).stdout.trim();if(t)return t}catch{return null}}return null}async getAheadBehindAsync(e){try{D(`[GIT-EXEC] Running git ahead/behind in ${e}`);let[t,n]=await Promise.all([this.execGitAsync(`git rev-list --count @{u}..HEAD`,{cwd:e,encoding:`utf8`,timeout:2e3}),this.execGitAsync(`git rev-list --count HEAD..@{u}`,{cwd:e,encoding:`utf8`,timeout:2e3})]);return{ahead:parseInt(t.stdout.trim())||0,behind:parseInt(n.stdout.trim())||0}}catch(t){return D(`Git ahead/behind command failed in ${e}:`,t),{ahead:0,behind:0}}}};const Te=a(r);var Ee=class{async getSessionId(){try{if(!process.env.TMUX_PANE)return D(`TMUX_PANE not set, not in tmux session`),null;D(`Getting tmux session ID, TMUX_PANE: ${process.env.TMUX_PANE}`);let e=(await Te(`tmux display-message -p '#S'`,{encoding:`utf8`,timeout:1e3})).stdout.trim();return D(`Tmux session ID: ${e||`empty`}`),e||null}catch(e){return D(`Error getting tmux session ID:`,e),null}}isInTmux(){return!!process.env.TMUX_PANE}};function O(){let e=[],t=process.env.CLAUDE_CONFIG_DIR;if(t&&t.split(`,`).forEach(t=>{let n=t.trim();c(n)&&e.push(n)}),e.length===0){let t=_(),n=f(t,`.config`,`claude`),r=f(t,`.claude`);c(n)&&e.push(n),c(r)&&e.push(r)}return e}async function k(e){let t=[];for(let n of e){let e=f(n,`projects`);if(c(e))try{let n=await x(e,{withFileTypes:!0});for(let r of n)if(r.isDirectory()){let n=p.join(e,r.name);t.push(n)}}catch(t){D(`Failed to read projects directory ${e}:`,t)}}return t}async function De(e){let t=await k(O());for(let n of t){let t=p.join(n,`${e}.jsonl`);if(c(t))return t}return null}async function Oe(e,t){let n=[],r=p.join(t,e,`subagents`);try{let t=(await x(r)).filter(e=>e.startsWith(`agent-`)&&e.endsWith(`.jsonl`));for(let i of t){let t=p.join(r,i);try{let r=(await b(t,`utf-8`)).split(`
|
|
5
|
+
`)[0];r&&JSON.parse(r).sessionId===e&&n.push(t)}catch{D(`Failed to check agent file ${t}`)}}}catch(e){D(`Failed to read subagents directory ${r}:`,e)}return n}async function ke(e){try{return(await ee(e)).mtime}catch{return null}}function Ae(e){let t=e.message?.id||(typeof e.raw.message==`object`&&e.raw.message!==null&&`id`in e.raw.message?e.raw.message.id:void 0),n=`requestId`in e.raw?e.raw.requestId:void 0;return!t||!n?null:`${t}:${n}`}async function A(e){try{let t=(await ee(e)).size,n;return t>1048576?(D(`Using streaming parser for large file ${e} (${Math.round(t/1024)}KB)`),n=await Me(e)):n=await je(e),D(`Parsed ${n.length} entries from ${e}`),n}catch(t){return D(`Failed to read file ${e}:`,t),[]}}async function je(e){let t=(await b(e,`utf-8`)).trim().split(`
|
|
6
|
+
`).filter(e=>e.trim()),n=[];for(let e of t)try{let t=JSON.parse(e);if(!t.timestamp)continue;let r={timestamp:new Date(t.timestamp),message:t.message,costUSD:typeof t.costUSD==`number`?t.costUSD:void 0,isSidechain:t.isSidechain===!0,raw:t};n.push(r)}catch(e){D(`Failed to parse JSONL line: ${e}`);continue}return n}async function Me(e){return new Promise((t,n)=>{let r=[],i=s(e,{encoding:`utf8`}),a=te({input:i,crlfDelay:1/0});a.on(`line`,e=>{let t=e.trim();if(t)try{let e=JSON.parse(t);if(!e.timestamp)return;let n={timestamp:new Date(e.timestamp),message:e.message,costUSD:typeof e.costUSD==`number`?e.costUSD:void 0,isSidechain:e.isSidechain===!0,raw:e};r.push(n)}catch(e){D(`Failed to parse JSONL line: ${e}`)}}),a.on(`close`,()=>{t(r)}),a.on(`error`,t=>{D(`Streaming parser error for ${e}:`,t),n(t)}),i.on(`error`,t=>{D(`File stream error for ${e}:`,t),n(t)})})}async function Ne(e){try{let t=await ke(e);return t?{filePath:e,mtime:t}:null}catch{return null}}async function Pe(e,t){try{let n=await x(e,{withFileTypes:!0}),r=n.filter(e=>!e.isDirectory()&&e.name.endsWith(`.jsonl`)).map(t=>Ne(p.join(e,t.name))),i=n.filter(e=>e.isDirectory()).map(async t=>{let n=p.join(e,t.name,`subagents`);try{return(await x(n)).filter(e=>e.startsWith(`agent-`)&&e.endsWith(`.jsonl`)).map(e=>Ne(p.join(n,e)))}catch{return[]}}),[a,o]=await Promise.all([Promise.all(r),Promise.all(i).then(e=>Promise.all(e.flat()))]);return[...a,...o].filter(e=>e!==null&&(!t||t(e.filePath,e.mtime)))}catch(t){return D(`Failed to read project directory ${e}:`,t),[]}}async function Fe(e,t,n=!1){let r=await k(O()),i=new Set,a=r.map(e=>Pe(e,t)),o=(await Promise.all(a)).flat().filter(e=>e!==null);n&&o.sort((e,t)=>t.mtime.getTime()-e.mtime.getTime());let s=o.map(e=>e.filePath),c=[],l=s.map(async t=>(await A(t)).filter(t=>!e||e(t))),u=await Promise.all(l);for(let e of u)c.push(...e);c.sort((e,t)=>e.timestamp.getTime()-t.timestamp.getTime());let d=[];for(let e of c){let t=Ae(e);t&&i.has(t)||(t&&i.add(t),d.push(e))}return d}var j=class{static CACHE_DIR=u.join(_(),`.claude`,`powerline`);static USAGE_CACHE_DIR=u.join(this.CACHE_DIR,`usage`);static LOCKS_DIR=u.join(this.CACHE_DIR,`locks`);static isLocked(e){let t=u.join(this.LOCKS_DIR,e);if(!o.existsSync(t))return!1;try{let n=o.readFileSync(t,`utf-8`),r=parseInt(n.trim(),10);if(isNaN(r))return D(`Invalid PID in lock file ${e}, removing stale lock`),o.unlinkSync(t),!1;try{return process.kill(r,0),!0}catch(n){return n.code===`ESRCH`?(D(`Removing stale lock file ${e} for dead process ${r}`),o.unlinkSync(t),!1):(D(`Error checking process ${r} for lock ${e}:`,n),!0)}}catch(t){return D(`Error reading lock file ${e}:`,t),!0}}static async acquireLock(e,t=5e3){await this.ensureCacheDirectories();let n=u.join(this.LOCKS_DIR,e),r=Date.now(),i=String(process.pid);for(;Date.now()-r<t;)try{return await o.promises.writeFile(n,i,{flag:`wx`}),D(`Lock acquired for ${e}`),!0}catch(e){if(e.code===`EEXIST`)await y(50);else throw e}return D(`Failed to acquire lock for ${e} within ${t}ms`),!1}static async releaseLock(e){let t=u.join(this.LOCKS_DIR,e);try{await o.promises.unlink(t),D(`Lock released for ${e}`)}catch(t){t.code!==`ENOENT`&&D(`Error releasing lock for ${e}:`,t)}}static async ensureCacheDirectories(){try{await Promise.all([o.promises.mkdir(this.CACHE_DIR,{recursive:!0}),o.promises.mkdir(this.USAGE_CACHE_DIR,{recursive:!0}),o.promises.mkdir(this.LOCKS_DIR,{recursive:!0})])}catch(e){D(`Failed to create cache directories:`,e)}}static createProjectHash(e){return v(`md5`).update(e).digest(`hex`).substring(0,8)}static async getUsageCache(e,t){await this.ensureCacheDirectories();let n=u.join(this.USAGE_CACHE_DIR,`${e}.json`),r=`${e}.usage.lock`;for(let i=0;i<3;i++){if(this.isLocked(r)){D(`Cache for ${e} is locked, waiting...`),await y(75);continue}try{let r=await o.promises.readFile(n,`utf-8`),i=JSON.parse(r);return!t||i.timestamp>=t?(D(`[CACHE-HIT] ${e} disk cache: found`),this.deserializeDates(i.data)):(D(`${e} cache outdated: cache=${i.timestamp}, latest=${t}`),null)}catch(t){if(t.code===`ENOENT`)return D(`No shared ${e} usage cache found`),null;D(`Attempt ${i+1} failed to read ${e} cache: ${t.message}. Retrying...`),await y(75)}}return D(`Failed to read ${e} cache after 3 attempts.`),null}static deserializeDates(e){return Array.isArray(e)?e.map(e=>({...e,timestamp:new Date(e.timestamp)})):e}static async setUsageCache(e,t,n){let r=`${e}.usage.lock`;if(!await this.acquireLock(r)){D(`Could not acquire lock to set usage cache for ${e}`);return}try{await this.ensureCacheDirectories();let r=u.join(this.USAGE_CACHE_DIR,`${e}.json`),i={data:t,timestamp:n||Date.now()},a=JSON.stringify(i);await o.promises.writeFile(r,a,`utf-8`),D(`[CACHE-SET] ${e} disk cache stored`)}catch(t){D(`Failed to save ${e} usage cache:`,t)}finally{await this.releaseLock(r)}}static async getLatestTranscriptMtime(){try{let e=await k(O()),t=0;for(let n of e)try{let e=(await o.promises.readdir(n)).filter(e=>e.endsWith(`.jsonl`));for(let r of e){let e=await ke(u.join(n,r));e&&e.getTime()>t&&(t=e.getTime())}}catch(e){D(`Failed to read project directory ${n}:`,e);continue}return t}catch(e){return D(`Failed to get latest transcript mtime:`,e),Date.now()}}};const M={"claude-haiku-4-5-20251001":{name:`Claude Haiku 4.5`,input:1,output:5,cache_write_5m:1.25,cache_write_1h:2,cache_read:.1},"claude-haiku-4-5":{name:`Claude Haiku 4.5`,input:1,output:5,cache_write_5m:1.25,cache_write_1h:2,cache_read:.1},"claude-opus-4-20250514":{name:`Claude Opus 4`,input:15,output:75,cache_write_5m:18.75,cache_write_1h:30,cache_read:1.5},"claude-opus-4-1":{name:`Claude Opus 4.1`,input:15,output:75,cache_write_5m:18.75,cache_write_1h:30,cache_read:1.5},"claude-opus-4-1-20250805":{name:`Claude Opus 4.1`,input:15,output:75,cache_write_5m:18.75,cache_write_1h:30,cache_read:1.5},"claude-sonnet-4-20250514":{name:`Claude Sonnet 4`,input:3,output:15,cache_write_5m:3.75,cache_write_1h:6,cache_read:.3},"claude-4-opus-20250514":{name:`Claude 4 Opus`,input:15,output:75,cache_write_5m:18.75,cache_write_1h:30,cache_read:1.5},"claude-4-sonnet-20250514":{name:`Claude 4 Sonnet`,input:3,output:15,cache_write_5m:3.75,cache_write_1h:6,cache_read:.3},"claude-sonnet-4-5":{name:`Claude Sonnet 4.5`,input:3,output:15,cache_write_5m:3.75,cache_write_1h:6,cache_read:.3},"claude-sonnet-4-5-20250929":{name:`Claude Sonnet 4.5`,input:3,output:15,cache_write_5m:3.75,cache_write_1h:6,cache_read:.3},"claude-opus-4-5":{name:`Claude Opus 4.5`,input:5,output:25,cache_write_5m:6.25,cache_write_1h:10,cache_read:.5},"claude-opus-4-5-20251101":{name:`Claude Opus 4.5`,input:5,output:25,cache_write_5m:6.25,cache_write_1h:10,cache_read:.5},"claude-opus-4-6":{name:`Claude Opus 4.6`,input:5,output:25,cache_write_5m:6.25,cache_write_1h:10,cache_read:.5},"claude-opus-4-6-20260205":{name:`Claude Opus 4.6`,input:5,output:25,cache_write_5m:6.25,cache_write_1h:10,cache_read:.5},"claude-sonnet-4-6":{name:`Claude Sonnet 4.6`,input:3,output:15,cache_write_5m:3.75,cache_write_1h:6,cache_read:.3}};var N=class{static executionCache=null;static modelPricingCache=new Map;static GITHUB_PRICING_URL=`https://raw.githubusercontent.com/Owloops/claude-powerline/main/pricing.json`;static async loadDiskCache(){let e=Date.now()-1440*60*1e3;return await j.getUsageCache(`pricing`,e)}static async saveDiskCache(e){await j.setUsageCache(`pricing`,e)}static async fetchPricingData(){return new Promise(e=>{let t=new h(this.GITHUB_PRICING_URL),n=m({hostname:t.hostname,path:t.pathname,headers:{"User-Agent":`claude-powerline`,"Cache-Control":`no-cache`},timeout:5e3},t=>{if(t.statusCode!==200){D(`HTTP ${t.statusCode}: ${t.statusMessage}`),e(null);return}let r=``,i=0;t.on(`data`,t=>{if(i+=t.length,i>1048576){D(`Response too large`),n.destroy(),e(null);return}r+=t}),t.on(`end`,()=>{try{let t=JSON.parse(r),n=t._meta,i={};for(let[e,n]of Object.entries(t))e!==`_meta`&&(i[e]=n);this.validatePricingData(i)?(D(`Fetched fresh pricing from GitHub for ${Object.keys(i).length} models`),D(`Pricing last updated: ${n?.updated||`unknown`}`),e(i)):(D(`Invalid pricing data structure`),e(null))}catch(t){D(`Failed to parse JSON:`,t),e(null)}}),t.on(`error`,t=>{D(`Response error:`,t),e(null)})});n.on(`error`,t=>{D(`Request error:`,t),e(null)}),n.on(`timeout`,()=>{D(`Request timeout`),n.destroy(),e(null)}),n.end()})}static async getCurrentPricing(){if(this.executionCache!==null)return D(`[CACHE-HIT] Pricing execution cache: ${Object.keys(this.executionCache).length} models`),this.executionCache;let e=await this.loadDiskCache();if(e)return D(`[CACHE-HIT] Pricing disk cache: ${Object.keys(e).length} models`),this.executionCache=e,D(`[CACHE-SET] Pricing execution cache stored: ${Object.keys(e).length} models`),e;let t=await this.fetchPricingData();return t?(await this.saveDiskCache(t),D(`[CACHE-SET] Pricing disk cache stored: ${Object.keys(t).length} models`),this.executionCache=t,D(`[CACHE-SET] Pricing execution cache stored: ${Object.keys(t).length} models`),t):(D(`[CACHE-FALLBACK] Using offline pricing data: ${Object.keys(M).length} models`),this.executionCache=M,D(`[CACHE-SET] Pricing execution cache stored: ${Object.keys(M).length} models`),M)}static validatePricingData(e){if(!e||typeof e!=`object`)return!1;for(let[,t]of Object.entries(e)){if(!t||typeof t!=`object`)return!1;let e=t;if(typeof e.input!=`number`||typeof e.output!=`number`||typeof e.cache_read!=`number`)return!1}return!0}static async getModelPricing(e){if(this.modelPricingCache.has(e))return D(`[CACHE-HIT] Model pricing cache: ${e}`),this.modelPricingCache.get(e);let t=await this.getCurrentPricing(),n;return n=t[e]?t[e]:this.fuzzyMatchModel(e,t),this.modelPricingCache.set(e,n),D(`[CACHE-SET] Model pricing cache: ${e}`),n}static fuzzyMatchModel(e,t){let n=e.toLowerCase();for(let[e,r]of Object.entries(t))if(e.toLowerCase()===n)return r;for(let{pattern:e,fallback:r}of[{pattern:[`opus-4-6`,`claude-opus-4-6`],fallback:`claude-opus-4-6-20260205`},{pattern:[`opus-4-5`,`claude-opus-4-5`],fallback:`claude-opus-4-5-20251101`},{pattern:[`opus-4-1`,`claude-opus-4-1`],fallback:`claude-opus-4-1-20250805`},{pattern:[`opus-4`,`claude-opus-4`],fallback:`claude-opus-4-20250514`},{pattern:[`sonnet-4-6`,`sonnet-4.6`,`claude-sonnet-4-6`],fallback:`claude-sonnet-4-6`},{pattern:[`sonnet-4.5`,`4-5-sonnet`,`sonnet-4-5`],fallback:`claude-sonnet-4-5-20250929`},{pattern:[`sonnet-4`,`claude-sonnet-4`],fallback:`claude-sonnet-4-20250514`},{pattern:[`haiku-4.5`,`4-5-haiku`,`haiku-4-5`],fallback:`claude-haiku-4-5-20251001`},{pattern:[`haiku`],fallback:`claude-haiku-4-5-20251001`},{pattern:[`opus`],fallback:`claude-opus-4-20250514`},{pattern:[`sonnet`],fallback:`claude-sonnet-4-5-20250929`}])if(e.some(e=>n.includes(e))&&t[r])return t[r];return t[`claude-sonnet-4-5-20250929`]||{name:`${e} (Unknown Model)`,input:3,cache_write_5m:3.75,cache_write_1h:6,cache_read:.3,output:15}}static async calculateCostForEntry(e){let t=e.message?.usage;if(!t)return 0;let n=this.extractModelId(e),r=await this.getModelPricing(n),i=t.input_tokens||0,a=t.output_tokens||0,o=t.cache_creation_input_tokens||0,s=t.cache_read_input_tokens||0,c=i/1e6*r.input,l=a/1e6*r.output,u=s/1e6*r.cache_read,d=o/1e6*r.cache_write_5m;return c+l+d+u}static extractModelId(e){if(e.model&&typeof e.model==`string`)return e.model;let t=e.message;if(t?.model){let e=t.model;return typeof e==`string`?e:e?.id||`claude-sonnet-4-5-20250929`}return e.model_id&&typeof e.model_id==`string`?e.model_id:`claude-sonnet-4-5-20250929`}};function Ie(e){return{timestamp:e.timestamp.toISOString(),message:{usage:{input_tokens:e.message?.usage?.input_tokens||0,output_tokens:e.message?.usage?.output_tokens||0,cache_creation_input_tokens:e.message?.usage?.cache_creation_input_tokens,cache_read_input_tokens:e.message?.usage?.cache_read_input_tokens}},costUSD:e.costUSD}}var Le=class{async getSessionUsage(e){try{let t=await De(e);if(!t)return D(`No transcript found for session: ${e}`),null;D(`Found transcript at: ${t}`);let n=await A(t),r=await Oe(e,d(t));D(`Found ${r.length} agent transcripts for session`);for(let e of r){let t=await A(e);n.push(...t)}if(n.length===0)return{totalCost:0,entries:[]};let i=[],a=0;for(let e of n)if(e.message?.usage){let t=Ie(e);if(t.costUSD!==void 0)a+=t.costUSD;else{let n=await N.calculateCostForEntry(e.raw);t.costUSD=n,a+=n}i.push(t)}return D(`Parsed ${i.length} usage entries, total cost: $${a.toFixed(4)}`),{totalCost:a,entries:i}}catch(t){return D(`Error reading session usage for ${e}:`,t),null}}calculateTokenBreakdown(e){return e.reduce((e,t)=>({input:e.input+(t.message.usage.input_tokens||0),output:e.output+(t.message.usage.output_tokens||0),cacheCreation:e.cacheCreation+(t.message.usage.cache_creation_input_tokens||0),cacheRead:e.cacheRead+(t.message.usage.cache_read_input_tokens||0)}),{input:0,output:0,cacheCreation:0,cacheRead:0})}async getSessionInfo(e,t){let n=await this.getSessionUsage(e);if(!n||n.entries.length===0)return{cost:null,calculatedCost:null,officialCost:null,tokens:null,tokenBreakdown:null};let r=this.calculateTokenBreakdown(n.entries),i=r.input+r.output+r.cacheCreation+r.cacheRead,a=n.totalCost,o=t?.cost?.total_cost_usd??null;return{cost:a??o,calculatedCost:a,officialCost:o,tokens:i,tokenBreakdown:r}}},Re=class{sessionProvider=new Le;async getUsageInfo(e,t){try{return D(`Starting usage info retrieval for session: ${e}`),{session:await this.sessionProvider.getSessionInfo(e,t)}}catch(t){return D(`Error getting usage info for session ${e}:`,t),{session:{cost:null,calculatedCost:null,officialCost:null,tokens:null,tokenBreakdown:null}}}}},ze=class{thresholds={LOW:50,MEDIUM:80};config;constructor(e){this.config=e}getContextUsageThresholds(){return this.thresholds}getContextLimit(e){let t=this.config.modelContextLimits||{default:2e5};return t[this.getModelType(e)]||t.default||2e5}getModelType(e){let t=e.toLowerCase();return t.includes(`sonnet`)?`sonnet`:t.includes(`opus`)?`opus`:`default`}calculatePercentages(e,t,n=33e3){let r=Math.min(100,Math.max(0,Math.round(e/t*100))),i=Math.max(1,t-n),a=Math.min(100,Math.max(0,Math.round(e/i*100)));return{percentage:r,usablePercentage:a,contextLeftPercentage:Math.max(0,100-a),usableTokens:i}}calculateContextFromHookData(e,t=33e3){let n=e.context_window?.current_usage;if(!n)return D(`No current_usage in hook data, falling back to transcript parsing`),null;let r=e.context_window?.context_window_size||2e5,i=(n.input_tokens||0)+(n.cache_creation_input_tokens||0)+(n.cache_read_input_tokens||0);return D(`Native current_usage: input=${n.input_tokens}, cache_create=${n.cache_creation_input_tokens}, cache_read=${n.cache_read_input_tokens}, total=${i} (limit: ${r})`),{totalTokens:i,maxTokens:r,...this.calculatePercentages(i,r,t)}}async calculateContextTokensFromTranscript(e,t,n=33e3){try{D(`Calculating context tokens from transcript: ${e}`);try{if(!l(e,`utf-8`))return D(`Transcript file is empty`),null}catch{return D(`Could not read transcript file`),null}let r=await A(e);if(r.length===0)return D(`No entries in transcript`),null;let i=null;for(let e=r.length-1;e>=0;e--){let t=r[e];if(t&&t.message?.usage?.input_tokens&&t.isSidechain!==!0){i=t,D(`Context segment: Found most recent entry at ${t.timestamp.toISOString()}, stopping search`);break}}if(i?.message?.usage){let e=i.message.usage,r=(e.input_tokens||0)+(e.cache_read_input_tokens||0)+(e.cache_creation_input_tokens||0),a=t?this.getContextLimit(t):2e5;return D(`Most recent main chain context: ${r} tokens (limit: ${a})`),{totalTokens:r,maxTokens:a,...this.calculatePercentages(r,a,n)}}return D(`No main chain entries with usage data found`),null}catch(e){return D(`Error reading transcript: ${e instanceof Error?e.message:String(e)}`),null}}async getContextInfo(e,t=33e3){return this.calculateContextFromHookData(e,t)||this.calculateContextTokensFromTranscript(e.transcript_path,e.model?.id,t)}},Be=class{async loadTranscriptEntries(e){try{let t=await De(e);if(!t)return D(`No transcript found for session: ${e}`),[];D(`Loading transcript from: ${t}`);let n=(await b(t,`utf-8`)).trim().split(`
|
|
7
|
+
`).filter(e=>e.trim()),r=[];for(let e of n)try{let t=JSON.parse(e);if(t.isSidechain===!0)continue;r.push(t)}catch(e){D(`Failed to parse JSONL line: ${e}`);continue}return D(`Loaded ${r.length} transcript entries`),r}catch(t){return D(`Error loading transcript for ${e}:`,t),[]}}calculateMessageCount(e){return e.filter(e=>{let t=e.type||e.message?.role||e.message?.type,n=e.type===`user`&&e.message?.content?.[0]?.type===`tool_result`;return t===`user`&&!n}).length}calculateLastResponseTime(e){if(e.length===0)return null;let t=e.slice(-20),n=null,r=null;for(let e of t)if(e.timestamp)try{let t=new Date(e.timestamp),i=e.type||e.message?.role||e.message?.type,a=e.type===`user`&&e.message?.content?.[0]?.type===`tool_result`;if(i===`user`&&!a)n=t;else if(i===`assistant`&&n){let e=(t.getTime()-n.getTime())/1e3;e>.1&&e<300&&(r=e)}}catch{continue}return r}async getMetricsInfo(e,t){try{if(D(`Getting metrics from hook data for session: ${e}`),!t.cost)return D(`No cost data available in hook data`),{responseTime:null,lastResponseTime:null,sessionDuration:null,messageCount:null,linesAdded:null,linesRemoved:null};let n=await this.loadTranscriptEntries(e),r=this.calculateMessageCount(n),i=this.calculateLastResponseTime(n);return{responseTime:t.cost.total_api_duration_ms/1e3,lastResponseTime:i,sessionDuration:t.cost.total_duration_ms/1e3,messageCount:r,linesAdded:t.cost.total_lines_added,linesRemoved:t.cost.total_lines_removed}}catch(t){return D(`Error getting metrics from hook data for session ${e}:`,t),{responseTime:null,lastResponseTime:null,sessionDuration:null,messageCount:null,linesAdded:null,linesRemoved:null}}}};function P(e){return e===null?`$0.00`:e<.01?`<$0.01`:`$${e.toFixed(2)}`}function F(e){return e===null||e===0?`0 tokens`:e>=1e6?`${(e/1e6).toFixed(1)}M tokens`:e>=1e3?`${(e/1e3).toFixed(1)}K tokens`:`${e} tokens`}function Ve(e){if(!e)return`0 tokens`;let t=[];if(e.input>0&&t.push(`${F(e.input).replace(` tokens`,``)} in`),e.output>0&&t.push(`${F(e.output).replace(` tokens`,``)} out`),e.cacheCreation>0||e.cacheRead>0){let n=e.cacheCreation+e.cacheRead;t.push(`${F(n).replace(` tokens`,``)} cached`)}return t.length>0?t.join(` + `):`0 tokens`}function He(e){return e<60?`${e}s`:e<3600?`${Math.floor(e/60)}m`:e<86400?`${Math.floor(e/3600)}h`:e<604800?`${Math.floor(e/86400)}d`:`${Math.floor(e/604800)}w`}function Ue(e){return e<60?`${e.toFixed(0)}s`:e<3600?`${(e/60).toFixed(0)}m`:e<86400?`${(e/3600).toFixed(1)}h`:`${(e/86400).toFixed(1)}d`}const We=/^(?:(?:global|apac|au|eu|us|us-east-\d|us-west-\d|eu-west-\d|eu-central-\d)\.)?(?:anthropic\.|azure_ai\/|bedrock\/|vertex_ai\/)?claude-(?:(?<family>opus|sonnet|haiku)-(?<newMajor>\d+)(?:-(?<newMinor>\d))?|(?<oldMajor>\d+)(?:-(?<oldMinor>\d))?-(?<oldFamily>opus|sonnet|haiku))(?:[-@]\d{8})?(?:-v\d+:\d+)?(?:-latest)?$/i;function Ge(e){if(!e)return`Claude`;let t=e.trim().match(We);if(!t?.groups)return e;let{family:n,newMajor:r,newMinor:i,oldMajor:a,oldMinor:o,oldFamily:s}=t.groups,c=n||s,l=r||a,u=i||o;return c&&l?`${c.charAt(0).toUpperCase()+c.slice(1).toLowerCase()} ${u?`${l}.${u}`:l}`:e}function Ke(e){let t=e.includes(`/`)?`/`:`\\`,n=e.split(t);return n.map((e,t)=>t===n.length-1||e===`~`||e===``?e:e.charAt(0)).join(t)}function qe(e){return e<60?`${e.toFixed(1)}s`:`${(e/60).toFixed(1)}m`}function I(e){let t=Math.floor(e/60),n=e%60;return t>0?`${t}h ${n}m left`:`${n}m left`}function Je(e){if(e>=1440){let t=Math.floor(e/1440),n=Math.floor(e%1440/60);return n>0?`${t}d ${n}h`:`${t}d`}else if(e>=60){let t=Math.floor(e/60),n=e%60;return n>0?`${t}h ${n}m`:`${t}h`}return`${e}m`}function L(e){return Math.round(Math.max(0,e*1e3-Date.now())/6e4)}function Ye(e,t){return!t||t<=0||e<0?null:Math.min(100,e/t*100)}function R(e,t,n=80){let r=Ye(e,t);if(r===null)return{percentage:null,isWarning:!1,displayText:``};let i=`${r.toFixed(0)}%`,a=r>=n,o=``;return o=a?` !${i}`:r>=50?` +${i}`:` ${i}`,{percentage:r,isWarning:a,displayText:o}}const Xe={ball:{filled:`─`,empty:`─`,marker:`●`},blocks:{filled:`█`,empty:`░`},"blocks-line":{filled:`█`,empty:`─`},capped:{filled:`━`,empty:`┄`,cap:`╸`},dots:{filled:`●`,empty:`○`},filled:{filled:`■`,empty:`□`},geometric:{filled:`▰`,empty:`▱`},line:{filled:`━`,empty:`┄`},squares:{filled:`◼`,empty:`◻`}};var Ze=class{constructor(e,t){this.config=e,this.symbols=t}renderDirectory(e,t,n){let r=e.workspace?.current_dir||e.cwd||`/`,i=e.workspace?.project_dir,a=n?.style??(n?.showBasename?`basename`:`full`);if(a===`basename`)return{text:u.basename(r)||`root`,bgColor:t.modeBg,fgColor:t.modeFg};let o=process.env.HOME||process.env.USERPROFILE,s=r,c=i;o&&(r.startsWith(o)&&(s=r.replace(o,`~`)),i&&i.startsWith(o)&&(c=i.replace(o,`~`)));let l=this.getDisplayDirectoryName(s,c);return a===`fish`&&(l=Ke(l)),{text:l,bgColor:t.modeBg,fgColor:t.modeFg}}renderGit(e,t,n){if(!e)return null;let r=[];if(n?.showRepoName&&e.repoName&&(r.push(e.repoName),e.isWorktree&&r.push(this.symbols.git_worktree)),n?.showOperation&&e.operation&&r.push(`[${e.operation}]`),r.push(`${this.symbols.branch} ${e.branch}`),n?.showTag&&e.tag&&r.push(`${this.symbols.git_tag} ${e.tag}`),n?.showSha&&e.sha&&r.push(`${this.symbols.git_sha} ${e.sha}`),n?.showAheadBehind!==!1&&(e.ahead>0&&e.behind>0?r.push(`${this.symbols.git_ahead}${e.ahead}${this.symbols.git_behind}${e.behind}`):e.ahead>0?r.push(`${this.symbols.git_ahead}${e.ahead}`):e.behind>0&&r.push(`${this.symbols.git_behind}${e.behind}`)),n?.showWorkingTree){let t=[];e.staged&&e.staged>0&&t.push(`+${e.staged}`),e.unstaged&&e.unstaged>0&&t.push(`~${e.unstaged}`),e.untracked&&e.untracked>0&&t.push(`?${e.untracked}`),e.conflicts&&e.conflicts>0&&t.push(`!${e.conflicts}`),t.length>0&&r.push(`(${t.join(` `)})`)}if(n?.showUpstream&&e.upstream&&r.push(`${this.symbols.git_upstream}${e.upstream}`),n?.showStashCount&&e.stashCount&&e.stashCount>0&&r.push(`${this.symbols.git_stash} ${e.stashCount}`),n?.showTimeSinceCommit&&e.timeSinceCommit!==void 0){let t=He(e.timeSinceCommit);r.push(`${this.symbols.git_time} ${t}`)}let i=this.symbols.git_clean;return e.status===`conflicts`?i=this.symbols.git_conflicts:e.status===`dirty`&&(i=this.symbols.git_dirty),r.push(i),{text:r.join(` `),bgColor:t.gitBg,fgColor:t.gitFg}}renderModel(e,t){let n=Ge(e.model?.display_name||`Claude`);return{text:`${this.symbols.model} ${n}`,bgColor:t.modelBg,fgColor:t.modelFg}}renderSession(e,t,n){let r=n?.type||`cost`,i=n?.costSource,a=this.config.budget?.session,o=this.formatUsageWithBudget(i===`calculated`?e.session.calculatedCost:i===`official`?e.session.officialCost:e.session.cost,e.session.tokens,e.session.tokenBreakdown,r,a?.amount,a?.warningThreshold||80,a?.type);return{text:`${this.symbols.session_cost} ${o}`,bgColor:t.sessionBg,fgColor:t.sessionFg}}renderSessionId(e,t,n){return{text:n?.showIdLabel===!1?e:`${this.symbols.session_id} ${e}`,bgColor:t.sessionBg,fgColor:t.sessionFg}}renderTmux(e,t){return e?{text:`tmux:${e}`,bgColor:t.tmuxBg,fgColor:t.tmuxFg}:{text:`tmux:none`,bgColor:t.tmuxBg,fgColor:t.tmuxFg}}renderContext(e,t,n){let r=n?.displayStyle??`text`,i=r===`text`?`remaining`:`used`,a=n?.percentageMode??i,o=this.resolveBarStyleDef(r),s=a===`remaining`?`100%`:`0%`;if(!e)return o?{text:`${o.empty.repeat(10)} ${s}`,bgColor:t.contextBg,fgColor:t.contextFg}:{text:`${this.symbols.context_time} 0 (${s})`,bgColor:t.contextBg,fgColor:t.contextFg};let c=t.contextBg,l=t.contextFg;e.contextLeftPercentage<=20?(c=t.contextCriticalBg,l=t.contextCriticalFg):e.contextLeftPercentage<=40&&(c=t.contextWarningBg,l=t.contextWarningFg);let u=a===`remaining`?e.contextLeftPercentage:e.usablePercentage,d=Math.round(e.usablePercentage/100*10),f=10-d;if(o){let t=this.buildBar(o,d,f,10);return{text:n?.showPercentageOnly?`${t} ${u}%`:`${t} ${e.totalTokens.toLocaleString()} (${u}%)`,bgColor:c,fgColor:l}}return{text:n?.showPercentageOnly?`${this.symbols.context_time} ${u}%`:`${this.symbols.context_time} ${e.totalTokens.toLocaleString()} (${u}%)`,bgColor:c,fgColor:l}}buildBar(e,t,n,r){if(e.marker){let n=Math.min(t,r-1);return e.filled.repeat(n)+e.marker+e.empty.repeat(r-n-1)}return e.cap?t===0?e.cap+e.empty.repeat(r-1):t>=r?e.filled.repeat(r):e.filled.repeat(t-1)+e.cap+e.empty.repeat(n):e.filled.repeat(t)+e.empty.repeat(n)}resolveBarStyleDef(e){return e===`bar`?{filled:this.symbols.bar_filled,empty:this.symbols.bar_empty}:Xe[e]??null}formatPercentageWithBar(e,t,n){let r=t??`text`,i=this.resolveBarStyleDef(r);if(i){let t=Math.round(e/100*10),r=10-t,a=this.buildBar(i,t,r,10);return n?`${a} ${e}% (${n})`:`${a} ${e}%`}return n?`${e}% (${n})`:`${e}%`}renderMetrics(e,t,n,r){if(!e)return{text:`${this.symbols.metrics_response} new`,bgColor:t.metricsBg,fgColor:t.metricsFg};let i=[];if(r?.showLastResponseTime&&e.lastResponseTime!==null){let t=e.lastResponseTime<60?`${e.lastResponseTime.toFixed(1)}s`:`${(e.lastResponseTime/60).toFixed(1)}m`;i.push(`${this.symbols.metrics_last_response} ${t}`)}if(r?.showResponseTime!==!1&&e.responseTime!==null){let t=e.responseTime<60?`${e.responseTime.toFixed(1)}s`:`${(e.responseTime/60).toFixed(1)}m`;i.push(`${this.symbols.metrics_response} ${t}`)}if(r?.showDuration!==!1&&e.sessionDuration!==null){let t=Ue(e.sessionDuration);i.push(`${this.symbols.metrics_duration} ${t}`)}return r?.showMessageCount!==!1&&e.messageCount!==null&&i.push(`${this.symbols.metrics_messages} ${e.messageCount}`),r?.showLinesAdded!==!1&&e.linesAdded!==null&&e.linesAdded>0&&i.push(`${this.symbols.metrics_lines_added} ${e.linesAdded}`),r?.showLinesRemoved!==!1&&e.linesRemoved!==null&&e.linesRemoved>0&&i.push(`${this.symbols.metrics_lines_removed} ${e.linesRemoved}`),i.length===0?{text:`${this.symbols.metrics_response} active`,bgColor:t.metricsBg,fgColor:t.metricsFg}:{text:i.join(` `),bgColor:t.metricsBg,fgColor:t.metricsFg}}renderBlock(e,t,n){return e.source===`native`&&e.nativeUtilization!==null?this.renderNativeBlock(e,t,n):this.renderTranscriptBlock(e,t,n)}renderNativeBlock(e,t,n){let r=Math.round(e.nativeUtilization),i=this.formatBlockTimeRemaining(e.timeRemaining),a=this.config.budget?.block?.warningThreshold??80,o=t.blockBg,s=t.blockFg;return r>=a?(o=t.contextCriticalBg,s=t.contextCriticalFg):r>=50&&(o=t.contextWarningBg,s=t.contextWarningFg),{text:`${this.symbols.block_cost} ${this.formatPercentageWithBar(r,n?.displayStyle,i)}`,bgColor:o,fgColor:s}}renderTranscriptBlock(e,t,n){let r;if(e.cost===null&&e.tokens===null)r=`No active block`;else{let t=n?.type||`cost`,i=n?.burnType,a=this.config.budget?.block,o=this.formatBlockTimeRemaining(e.timeRemaining),s;switch(t){case`cost`:s=this.formatUsageWithBudget(e.cost,null,null,`cost`,a?.amount,a?.warningThreshold,a?.type);break;case`tokens`:s=this.formatUsageWithBudget(null,e.tokens,null,`tokens`,a?.amount,a?.warningThreshold,a?.type);break;case`weighted`:{let t=a?.type===`tokens`?a.amount:void 0,n=F(e.weightedTokens);s=t&&e.weightedTokens!==null?`${n}${R(e.weightedTokens,t,a?.warningThreshold||80).displayText}`:`${n} (weighted)`;break}case`both`:s=this.formatUsageWithBudget(e.cost,e.tokens,null,`both`,a?.amount,a?.warningThreshold,a?.type);break;case`time`:s=o||`N/A`;break;default:s=this.formatUsageWithBudget(e.cost,null,null,`cost`,a?.amount,a?.warningThreshold,a?.type)}let c=``;if(i&&i!==`none`)switch(i){case`cost`:c=` | ${e.burnRate===null?`N/A`:e.burnRate<1?`${(e.burnRate*100).toFixed(0)}¢/h`:`$${e.burnRate.toFixed(2)}/h`}`;break;case`tokens`:c=` | ${e.tokenBurnRate===null?`N/A`:`${F(Math.round(e.tokenBurnRate))}/h`}`;break;case`both`:c=` | ${e.burnRate===null?`N/A`:e.burnRate<1?`${(e.burnRate*100).toFixed(0)}¢/h`:`$${e.burnRate.toFixed(2)}/h`} / ${e.tokenBurnRate===null?`N/A`:`${F(Math.round(e.tokenBurnRate))}/h`}`;break}r=t===`time`?s:o?`${s}${c} (${o} left)`:`${s}${c}`}return{text:`${this.symbols.block_cost} ${r}`,bgColor:t.blockBg,fgColor:t.blockFg}}formatBlockTimeRemaining(e){if(e===null)return null;let t=Math.floor(e/60),n=e%60;return t>0?`${t}h ${n}m`:`${n}m`}renderWeekly(e,t,n){let r=e.rate_limits?.seven_day;if(!r)return null;let i=Math.round(r.used_percentage),a=Je(L(r.resets_at)),o=t.weeklyBg,s=t.weeklyFg;return i>=80?(o=t.contextCriticalBg,s=t.contextCriticalFg):i>=50&&(o=t.contextWarningBg,s=t.contextWarningFg),{text:`${this.symbols.weekly_cost} ${this.formatPercentageWithBar(i,n?.displayStyle,a)}`,bgColor:o,fgColor:s}}renderToday(e,t,n=`cost`){let r=this.config.budget?.today;return{text:`${this.symbols.today_cost} ${this.formatUsageWithBudget(e.cost,e.tokens,e.tokenBreakdown,n,r?.amount,r?.warningThreshold,r?.type)}`,bgColor:t.todayBg,fgColor:t.todayFg}}getDisplayDirectoryName(e,t){return e.startsWith(`~`)?e:t&&t!==e&&e.startsWith(t)?e.slice(t.length+1)||u.basename(t)||`project`:e}formatUsageDisplay(e,t,n,r){switch(r){case`cost`:return P(e);case`tokens`:return F(t);case`both`:return`${P(e)} (${F(t)})`;case`breakdown`:return Ve(n);default:return P(e)}}formatUsageWithBudget(e,t,n,r,i,a=80,o){let s=this.formatUsageDisplay(e,t,n,r);if(i&&i>0){let n=null;if(o===`tokens`&&t!==null?n=t:(o===`cost`&&e!==null||!o&&e!==null)&&(n=e),n!==null)return s+R(n,i,a).displayText}return s}renderVersion(e,t,n){return e.version?{text:`${this.symbols.version} v${e.version}`,bgColor:t.versionBg,fgColor:t.versionFg}:null}renderEnv(e,t){let n=process.env[t.variable];if(!n)return null;let r=t.prefix??t.variable;return{text:r?`${this.symbols.env} ${r}: ${n}`:`${this.symbols.env} ${n}`,bgColor:e.envBg,fgColor:e.envFg}}};function Qe(e){return e.includes(`opus`)?5:(e.includes(`sonnet`)||e.includes(`haiku`),1)}function $e(e){return{timestamp:e.timestamp,usage:{inputTokens:e.message?.usage?.input_tokens||0,outputTokens:e.message?.usage?.output_tokens||0,cacheCreationInputTokens:e.message?.usage?.cache_creation_input_tokens||0,cacheReadInputTokens:e.message?.usage?.cache_read_input_tokens||0},costUSD:e.costUSD||0,model:e.message?.model||`unknown`}}var et=class{sessionDurationHours=5;floorToHour(e){let t=new Date(e);return t.setUTCMinutes(0,0,0),t}identifySessionBlocks(e){if(e.length===0)return[];let t=this.sessionDurationHours*60*60*1e3,n=[],r=[...e].sort((e,t)=>e.timestamp.getTime()-t.timestamp.getTime()),i=null,a=[];for(let e of r){let r=e.timestamp;if(i==null)i=this.floorToHour(r),a=[e];else{let o=r.getTime()-i.getTime(),s=a[a.length-1];if(s==null)continue;let c=s.timestamp,l=r.getTime()-c.getTime();o>t||l>t?(n.push(a),i=this.floorToHour(r),a=[e]):a.push(e)}}return i!=null&&a.length>0&&n.push(a),n}createBlockInfo(e,t){let n=new Date,r=this.sessionDurationHours*60*60*1e3,i=new Date(e.getTime()+r),a=t[t.length-1],o=a==null?e:a.timestamp;return{block:t,isActive:n.getTime()-o.getTime()<r&&n<i}}findActiveBlock(e){for(let t=e.length-1;t>=0;t--){let n=e[t];if(!n||n.length===0)continue;let r=n[0];if(!r)continue;let i=this.floorToHour(r.timestamp),a=this.createBlockInfo(i,n);if(a.isActive)return a.block}return null}async loadUsageEntries(){try{D(`Block segment: Loading entries for dynamic session blocks`);let e=new Date;e.setDate(e.getDate()-1);let t=await Fe(void 0,(t,n)=>n>=e,!0),n=[];for(let e of t)if(e.message?.usage){let t=$e(e);!t.costUSD&&e.raw&&(t.costUSD=await N.calculateCostForEntry(e.raw)),n.push(t)}let r=this.identifySessionBlocks(n);D(`Block segment: Found ${r.length} session blocks`);let i=this.findActiveBlock(r),a=[];if(i&&i.length>0){D(`Block segment: Found active block with ${i.length} entries`);let e=i[0],t=i[i.length-1];e&&t&&D(`Block segment: Active block from ${e.timestamp.toISOString()} to ${t.timestamp.toISOString()}`),a=i}else D(`Block segment: No active block found`),a=[];return a}catch(e){return D(`Error loading block entries:`,e),[]}}async getActiveBlockInfo(e){let t=e?.rate_limits?.five_hour;if(t){let e=L(t.resets_at);return D(`Block segment: Using native rate_limits: ${t.used_percentage}%, resets in ${e}m`),{cost:null,tokens:null,weightedTokens:null,timeRemaining:e,burnRate:null,tokenBurnRate:null,source:`native`,nativeUtilization:t.used_percentage}}try{let e=await this.loadUsageEntries();if(e.length===0)return D(`Block segment: No entries in current block`),{cost:null,tokens:null,weightedTokens:null,timeRemaining:null,burnRate:null,tokenBurnRate:null,source:`transcript`,nativeUtilization:null};let t=e.reduce((e,t)=>e+t.costUSD,0),n=e.reduce((e,t)=>e+t.usage.inputTokens+t.usage.outputTokens+t.usage.cacheCreationInputTokens+t.usage.cacheReadInputTokens,0),r=e.reduce((e,t)=>e+(t.usage.inputTokens+t.usage.outputTokens+t.usage.cacheCreationInputTokens+t.usage.cacheReadInputTokens)*Qe(t.model),0),i=new Date,a=null;if(e.length>0){let t=e[0];if(t){let e=this.sessionDurationHours*60*60*1e3,n=this.floorToHour(t.timestamp),r=new Date(n.getTime()+e);a=Math.max(0,Math.round((r.getTime()-i.getTime())/(1e3*60)))}}let o=null,s=null;if(e.length>=1&&(t>0||n>0)){let r=e.map(e=>e.timestamp).sort((e,t)=>e.getTime()-t.getTime()),i=r[0],a=r[r.length-1];if(i&&a){let e=(a.getTime()-i.getTime())/(1e3*60);e>0&&(t>0&&(o=t/e*60),n>0&&(s=n/e*60))}}return D(`Block segment: $${t.toFixed(2)}, ${n} tokens, ${a}m remaining, burn rate: ${o?`$`+o.toFixed(2)+`/hr`:`N/A`}`),{cost:t,tokens:n,weightedTokens:r,timeRemaining:a,burnRate:o,tokenBurnRate:s,source:`transcript`,nativeUtilization:null}}catch(e){return D(`Error getting active block info:`,e),{cost:null,tokens:null,weightedTokens:null,timeRemaining:null,burnRate:null,tokenBurnRate:null,source:`transcript`,nativeUtilization:null}}}};function z(e){return`${e.getFullYear()}-${String(e.getMonth()+1).padStart(2,`0`)}-${String(e.getDate()).padStart(2,`0`)}`}function tt(e){return e.inputTokens+e.outputTokens+e.cacheCreationInputTokens+e.cacheReadInputTokens}function nt(e){return{timestamp:e.timestamp,usage:{inputTokens:e.message?.usage?.input_tokens||0,outputTokens:e.message?.usage?.output_tokens||0,cacheCreationInputTokens:e.message?.usage?.cache_creation_input_tokens||0,cacheReadInputTokens:e.message?.usage?.cache_read_input_tokens||0},costUSD:e.costUSD||0,model:e.message?.model||`unknown`}}var rt=class{async loadTodayEntries(){let e=z(new Date);D(`Today segment: Loading entries for date ${e}`);let t=await j.getLatestTranscriptMtime(),n=await j.getUsageCache(`today`,t);if(n)return D(`Using shared today usage cache`),n;let r=new Date;r.setDate(r.getDate()-1),r.setHours(0,0,0,0);let i=(e,t)=>t>=r,a=new Date;a.setHours(0,0,0,0);let o=await Fe(e=>e.timestamp>=a,i,!0),s=[],c=0;for(let t of o)if(z(t.timestamp)===e&&t.message?.usage){let e=nt(t);!e.costUSD&&t.raw&&(e.costUSD=await N.calculateCostForEntry(t.raw)),s.push(e),c++}return D(`Today segment: Found ${c} entries for today (${e})`),await j.setUsageCache(`today`,s,t),s}async getTodayEntries(){try{return await this.loadTodayEntries()}catch(e){return D(`Error loading today's entries:`,e),[]}}async getTodayInfo(){try{let e=await this.getTodayEntries();if(e.length===0)return{cost:null,tokens:null,tokenBreakdown:null,date:z(new Date)};let t=e.reduce((e,t)=>e+t.costUSD,0),n=e.reduce((e,t)=>e+tt(t.usage),0),r=e.reduce((e,t)=>({input:e.input+t.usage.inputTokens,output:e.output+t.usage.outputTokens,cacheCreation:e.cacheCreation+t.usage.cacheCreationInputTokens,cacheRead:e.cacheRead+t.usage.cacheReadInputTokens}),{input:0,output:0,cacheCreation:0,cacheRead:0});return D(`Today segment: $${t.toFixed(2)}, ${n} tokens total`),{cost:t,tokens:n,tokenBreakdown:r,date:z(new Date)}}catch(e){return D(`Error getting today's info:`,e),{cost:null,tokens:null,tokenBreakdown:null,date:z(new Date)}}}};const it={right:``,left_rounded:``,right_rounded:``,branch:`⎇`,model:`✱`,git_clean:`✓`,git_dirty:`●`,git_conflicts:`⚠`,git_ahead:`↑`,git_behind:`↓`,git_worktree:`⧉`,git_tag:`⌂`,git_sha:`♯`,git_upstream:`→`,git_stash:`⧇`,git_time:`◷`,session_cost:`§`,block_cost:`◱`,today_cost:`☉`,context_time:`◔`,metrics_response:`⧖`,metrics_last_response:`Δ`,metrics_duration:`⧗`,metrics_messages:`◆`,metrics_lines_added:`+`,metrics_lines_removed:`-`,metrics_burn:`↗`,version:`◈`,bar_filled:`▪`,bar_empty:`▫`,env:`⚙`,session_id:`⌗`,weekly_cost:`◑`},at={topLeft:`╭`,topRight:`╮`,bottomLeft:`╰`,bottomRight:`╯`,horizontal:`─`,vertical:`│`,teeLeft:`├`,teeRight:`┤`},ot={topLeft:`+`,topRight:`+`,bottomLeft:`+`,bottomRight:`+`,horizontal:`-`,vertical:`|`,teeLeft:`+`,teeRight:`+`},st={right:``,left_rounded:``,right_rounded:``,branch:`~`,model:`M`,git_clean:`=`,git_dirty:`*`,git_conflicts:`!`,git_ahead:`^`,git_behind:`v`,git_worktree:`W`,git_tag:`T`,git_sha:`#`,git_upstream:`>>`,git_stash:`S`,git_time:`@`,session_cost:`S`,block_cost:`B`,today_cost:`D`,context_time:`C`,metrics_response:`R`,metrics_last_response:`L`,metrics_duration:`T`,metrics_messages:`#`,metrics_lines_added:`+`,metrics_lines_removed:`-`,metrics_burn:`~/h`,version:`V`,bar_filled:`=`,bar_empty:`-`,env:`$`,session_id:`#`,weekly_cost:`W`},ct=RegExp(`\x1B\\[[0-9;]*m`,`g`),lt=/^[a-zA-Z0-9/]+$/;function ut(){if(process.platform===`win32`)return null;let e=process.pid.toString();for(let t=0;t<10;t++)try{let t=i(`ps -o ppid=,tty= -p ${e}`,{encoding:`utf8`,stdio:[`pipe`,`pipe`,`ignore`]}).trim().split(/\s+/),n=t[0],r=t[1];if(r&&r!==`?`&&r!==`??`&<.test(r))return r;if(!n||n===`1`||n===`0`)break;e=n}catch{break}return null}function dt(){try{let e=i(`mode con`,{encoding:`utf8`,stdio:[`pipe`,`pipe`,`ignore`],windowsHide:!0}).match(/Columns:\s*(\d+)/i);if(e?.[1]){let t=parseInt(e[1],10);if(!isNaN(t)&&t>0)return t}}catch{}return null}function ft(){let e=ut();if(e)try{let t=i(`stty size < /dev/${e}`,{encoding:`utf8`,stdio:[`pipe`,`pipe`,`ignore`],shell:`/bin/sh`}).trim().split(` `)[1];if(t){let e=parseInt(t,10);if(!isNaN(e)&&e>0)return e}}catch{}try{let e=i(`tput cols 2>/dev/null`,{encoding:`utf8`,stdio:[`pipe`,`pipe`,`ignore`]}).trim(),t=parseInt(e,10);if(!isNaN(t)&&t>0)return t}catch{}return null}function pt(){let e=e=>Math.floor(e*.7),t=process.env.COLUMNS;if(t){let n=parseInt(t,10);if(!isNaN(n)&&n>0)return e(n)}if(process.stdout.columns&&process.stdout.columns>0)return e(process.stdout.columns);if(process.platform===`win32`){let t=dt();if(t)return e(t)}let n=ft();return n?e(n):null}function mt(e){return e.replace(ct,``)}function B(e){return mt(e).length}function V(e,t,n){return t?`${t}${e}${n}`:e}function ht(e,t){let n=B(e);return n>=t?e:e+` `.repeat(t-n)}const gt=RegExp(`(\x1B\\[[0-9;]*m)`);function _t(e,t){if(mt(e).length<=t)return e;let n=0,r=``,i=e.split(gt);for(let e of i){if(e.startsWith(`\x1B`)){r+=e;continue}for(let i of e){if(n>=t-1)return r+=`…`,r;r+=i,n++}}return r}function H(e,t,n){let r=n-2,i=ht(_t(t,r),r);return e.vertical+` `+i+` `+e.vertical}function U(e,t){return e.teeLeft+e.horizontal.repeat(t)+e.teeRight}function vt(e,t){return e.bottomLeft+e.horizontal.repeat(t)+e.bottomRight}function yt(e,t){if(e.length===0)return``;if(e.length===1)return e[0]??``;let n=e.map(e=>B(e)),r=t-n.reduce((e,t)=>e+t,0),i=Math.max(2,Math.floor(r/(e.length-1))),a=Array(e.length);a[e.length-1]=n[e.length-1]??0;for(let t=e.length-2;t>=0;t--)a[t]=(a[t+1]??0)+(n[t]??0);let o=e[0]??``,s=n[0]??0;for(let r=1;r<e.length;r++){let c=t-s-(a[r]??0)-(e.length-1-r)*2,l=Math.max(2,Math.min(i,c));o+=` `.repeat(l)+(e[r]??``),s+=l+(n[r]??0)}return o}function W(e,t,n){if(!t)return e;if(!e)return t;let r=B(e),i=B(t),a=n-r-i;return a<2?`${e} ${t}`:e+` `.repeat(a)+t}function bt(e,t,n){let r=` ${Ge(e.hookData.model?.display_name||`Claude`).toLowerCase()} `,i=n-1-r.length-18;if(i<2){let e=n-1-r.length;return t.topLeft+t.horizontal+r+t.horizontal.repeat(Math.max(0,e))+t.topRight}return t.topLeft+t.horizontal+r+t.horizontal.repeat(i)+` claude-powerline `+t.topRight}function xt(e,t,n,r,i){let a=Math.min(Math.floor(t*.45),40);if(!e.contextInfo)return null;let o=e.contextInfo.usablePercentage,s=Math.round(o/100*a),c=a-s,l=n.bar_filled.repeat(s)+n.bar_empty.repeat(c),u=e.contextInfo.totalTokens>=1e3?`${(e.contextInfo.totalTokens/1e3).toFixed(0)}k`:`${e.contextInfo.totalTokens}`,d=e.contextInfo.maxTokens>=1e3?`${(e.contextInfo.maxTokens/1e3).toFixed(0)}k`:`${e.contextInfo.maxTokens}`,f=i.contextFg;return o>=80?f=i.contextCriticalFg:o>=60&&(f=i.contextWarningFg),V(`${l} ${o}% ${u}/${d}`,f,r)}function St(e){let t=e.workspace?.current_dir||e.cwd||`/`,n=process.env.HOME||process.env.USERPROFILE;return n&&t.startsWith(n)?t.replace(n,`~`):t}function Ct(e,t,n,r,i){let a=[];e.blockInfo&&a.push(V(q(e.blockInfo,t,n),i.blockFg,r));let o=e.hookData.rate_limits?.seven_day;o&&a.push(V(J(o,t),i.weeklyFg,r)),e.usageInfo&&a.push(V(Tt(e.usageInfo,t,n),i.sessionFg,r)),e.todayInfo&&a.push(V(Et(e.todayInfo,t,n),i.todayFg,r));let s=wt(e,t);return s.length>0&&a.push(V(s.join(` · `),i.metricsFg,r)),a}function wt(e,t){let n=[];return e.metricsInfo&&(e.metricsInfo.sessionDuration!==null&&e.metricsInfo.sessionDuration>0&&n.push(`${t.metrics_duration} ${Ue(e.metricsInfo.sessionDuration)}`),e.metricsInfo.messageCount!==null&&e.metricsInfo.messageCount>0&&n.push(`${t.metrics_messages} ${e.metricsInfo.messageCount}`)),n}function G(e,t,n,r){let i=[];if(e.gitInfo){let a=`${t.branch} ${e.gitInfo.branch}`;e.gitInfo.status===`conflicts`?a+=` ${t.git_conflicts}`:e.gitInfo.status===`dirty`?a+=` ${t.git_dirty}`:a+=` ${t.git_clean}`,e.gitInfo.ahead>0&&(a+=` ${t.git_ahead}${e.gitInfo.ahead}`),e.gitInfo.behind>0&&(a+=` ${t.git_behind}${e.gitInfo.behind}`);let o=[];e.gitInfo.staged&&e.gitInfo.staged>0&&o.push(`+${e.gitInfo.staged}`),e.gitInfo.unstaged&&e.gitInfo.unstaged>0&&o.push(`~${e.gitInfo.unstaged}`),e.gitInfo.untracked&&e.gitInfo.untracked>0&&o.push(`?${e.gitInfo.untracked}`),o.length>0&&(a+=` (${o.join(` `)})`),i.push(V(a,r.gitFg,n))}let a=Ke(St(e.hookData));return i.push(V(a,r.modeFg,n)),i}function K(e,t,n,r,i){let a=[];if(e.hookData.version&&a.push(V(`${t.version} v${e.hookData.version}`,i.versionFg,r)),e.tmuxSessionId&&a.push(V(`tmux:${e.tmuxSessionId}`,i.tmuxFg,r)),e.metricsInfo){let n=[];if(e.metricsInfo.responseTime!==null&&!isNaN(e.metricsInfo.responseTime)&&e.metricsInfo.responseTime>0&&n.push(`${t.metrics_response} ${qe(e.metricsInfo.responseTime)}`),e.metricsInfo.linesAdded!==null&&e.metricsInfo.linesAdded>0&&n.push(`${t.metrics_lines_added}${e.metricsInfo.linesAdded}`),e.metricsInfo.linesRemoved!==null&&e.metricsInfo.linesRemoved>0&&n.push(`${t.metrics_lines_removed}${e.metricsInfo.linesRemoved}`),e.blockInfo?.source!==`native`&&e.blockInfo?.burnRate!==null&&e.blockInfo?.burnRate!==void 0&&e.blockInfo.burnRate>0){let r=e.blockInfo.burnRate<1?`${(e.blockInfo.burnRate*100).toFixed(0)}c/h`:`$${e.blockInfo.burnRate.toFixed(2)}/h`;n.push(`${t.metrics_burn} ${r}`)}n.length>0&&a.push(V(n.join(` · `),i.metricsFg,r))}let o=n.display.lines.map(e=>e.segments.env).find(e=>e?.enabled);if(o&&o.variable){let e=process.env[o.variable];if(e){let t=o.prefix??o.variable;a.push(V(t?`${t}:${e}`:e,i.envFg,r))}}return a}function q(e,t,n){if(e.source===`native`&&e.nativeUtilization!==null){let n=Math.round(e.nativeUtilization),r=`${t.block_cost} ${n}%`;return e.timeRemaining!==null&&(r+=` · ${I(e.timeRemaining)}`),r}let r=P(e.cost),i=`${t.block_cost} ${r}`;e.timeRemaining!==null&&(i+=` · ${I(e.timeRemaining)}`);let a=n.budget?.block;if(a?.amount&&e.cost!==null){let t=R(e.cost,a.amount,a.warningThreshold||80);i+=t.displayText}return i}function J(e,t){let n=Math.round(e.used_percentage),r=Je(L(e.resets_at));return`${t.weekly_cost} ${n}%${r?` · ${r}`:``}`}function Tt(e,t,n){let r=P(e.session.cost),i=e.session.tokens,a=i!==null&&i>0?F(i).replace(` tokens`,``):null,o=`${t.session_cost} ${r}`;a&&(o+=` · ${a}`);let s=n.budget?.session;if(s?.amount&&e.session.cost!==null){let t=R(e.session.cost,s.amount,s.warningThreshold||80);o+=t.displayText}return o}function Et(e,t,n){let r=P(e.cost),i=`${t.today_cost} ${r} today`,a=n.budget?.today;if(a?.amount&&e.cost!==null){let t=R(e.cost,a.amount,a.warningThreshold||80);i+=t.displayText}return i}function Dt(e){let{lines:t,data:n,box:r,contentWidth:i,innerWidth:a,sym:o,config:s,reset:c,colors:l}=e,u=Ct(n,o,s,c,l);u.length>0&&t.push(H(r,yt(u,i),a))}function Ot(e){let{lines:t,data:n,box:r,contentWidth:i,innerWidth:a,sym:o,config:s,reset:c,colors:l}=e,u=G(n,o,c,l),d=K(n,o,s,c,l),f=u.join(` `),p=d.join(` · `);(f||p)&&(t.push(U(r,a)),t.push(H(r,W(f,p,i),a)))}function kt(e){let{lines:t,data:n,box:r,contentWidth:i,innerWidth:a,sym:o,config:s,reset:c,colors:l}=e,u=[],d=[];n.blockInfo&&u.push(V(q(n.blockInfo,o,s),l.blockFg,c));let f=n.hookData.rate_limits?.seven_day;f&&u.push(V(J(f,o),l.weeklyFg,c)),n.todayInfo&&u.push(V(Et(n.todayInfo,o,s),l.todayFg,c)),n.usageInfo&&d.push(V(Tt(n.usageInfo,o,s),l.sessionFg,c));let p=wt(n,o);p.length>0&&d.push(V(p.join(` · `),l.metricsFg,c)),u.length>0&&t.push(H(r,yt(u,i),a)),d.length>0&&t.push(H(r,W(d[0]??``,d[1]??``,i),a))}function At(e){let{lines:t,data:n,box:r,contentWidth:i,innerWidth:a,sym:o,config:s,reset:c,colors:l}=e,u=G(n,o,c,l);u.length>0&&(t.push(U(r,a)),t.push(H(r,W(u[0]??``,u[1]??``,i),a)));let d=K(n,o,s,c,l);d.length>0&&(t.push(U(r,a)),t.push(H(r,d.join(` · `),a)))}function jt(e){let{lines:t,data:n,box:r,contentWidth:i,innerWidth:a,sym:o,config:s,reset:c,colors:l}=e;n.blockInfo&&t.push(H(r,V(q(n.blockInfo,o,s),l.blockFg,c),a));let u=n.hookData.rate_limits?.seven_day;u&&t.push(H(r,V(J(u,o),l.weeklyFg,c),a));let d=[];n.usageInfo&&d.push(V(`${o.session_cost} ${P(n.usageInfo.session.cost)}`,l.sessionFg,c)),n.todayInfo&&d.push(V(`${o.today_cost} ${P(n.todayInfo.cost)} today`,l.todayFg,c)),d.length>0&&t.push(H(r,W(d[0]??``,d[1]??``,i),a))}function Mt(e){let{lines:t,data:n,box:r,contentWidth:i,innerWidth:a,sym:o,config:s,reset:c,colors:l}=e,u=G(n,o,c,l);u.length>0&&(t.push(U(r,a)),t.push(H(r,W(u[0]??``,u[1]??``,i),a)));let d=K(n,o,s,c,l);d.length>0&&t.push(H(r,d.join(` · `),a))}function Nt(e){return e>=80?`wide`:e>=55?`medium`:`narrow`}function Pt(e){return e&&e>0?Math.max(32,e):80}function Ft(e,t,n,r,i){let a=(i.display.charset||`unicode`)===`text`?st:it,o=e.colors,s=Pt(r),c=s-2,l=c-2,u=Nt(s),d=[];d.push(bt(e,t,c));let f=xt(e,l,a,n,o);f&&d.push(H(t,f,c));let p={lines:d,data:e,box:t,contentWidth:l,innerWidth:c,sym:a,config:i,reset:n,colors:o};return u===`wide`?(Dt(p),Ot(p)):u===`medium`?(kt(p),At(p)):(jt(p),Mt(p)),d.push(vt(t,c)),`\x1B[?2026h`+d.join(`
|
|
8
|
+
`)+`\x1B[?2026l`}var It=class{symbols;_usageProvider;_blockProvider;_todayProvider;_contextProvider;_gitService;_tmuxService;_metricsProvider;_segmentRenderer;constructor(e){this.config=e,this.symbols=this.initializeSymbols()}get usageProvider(){return this._usageProvider||=new Re,this._usageProvider}get blockProvider(){return this._blockProvider||=new et,this._blockProvider}get todayProvider(){return this._todayProvider||=new rt,this._todayProvider}get contextProvider(){return this._contextProvider||=new ze(this.config),this._contextProvider}get gitService(){return this._gitService||=new we,this._gitService}get tmuxService(){return this._tmuxService||=new Ee,this._tmuxService}get metricsProvider(){return this._metricsProvider||=new Be,this._metricsProvider}get segmentRenderer(){return this._segmentRenderer||=new Ze(this.config,this.symbols),this._segmentRenderer}needsSegmentInfo(e){return this.config.display.lines.some(t=>t.segments[e]?.enabled)}async generateStatusline(e){if(this.config.display.style===`tui`)return this.generateTuiStatusline(e);let t=this.needsSegmentInfo(`session`)?await this.usageProvider.getUsageInfo(e.session_id,e):null,n=this.needsSegmentInfo(`block`)?await this.blockProvider.getActiveBlockInfo(e):null,r=this.needsSegmentInfo(`today`)?await this.todayProvider.getTodayInfo():null,i=this.config.display.lines.map(e=>e.segments.context).find(e=>e?.enabled)?.autocompactBuffer??33e3,a=this.needsSegmentInfo(`context`)?await this.contextProvider.getContextInfo(e,i):null,o=this.needsSegmentInfo(`metrics`)?await this.metricsProvider.getMetricsInfo(e.session_id,e):null;return this.config.display.autoWrap?this.generateAutoWrapStatusline(e,t,n,r,a,o):(await Promise.all(this.config.display.lines.map(i=>this.renderLine(i,e,t,n,r,a,o)))).filter(e=>e.length>0).join(`
|
|
9
|
+
`)}async generateAutoWrapStatusline(e,t,n,r,i,a){let o=this.getThemeColors(),s=e.workspace?.current_dir||e.cwd||`/`,c=pt(),l=[];for(let u of this.config.display.lines){let d=Object.entries(u.segments).filter(([e,t])=>t?.enabled).map(([e,t])=>({type:e,config:t})),f=[];for(let c of d){let l=await this.renderSegment(c,e,t,n,r,i,a,o,s);l&&f.push({type:c.type,text:l.text,bgColor:l.bgColor,fgColor:l.fgColor})}if(f.length===0)continue;if(!c||c<=0){l.push(this.buildLineFromSegments(f,o));continue}let p=[],m=0;for(let e of f){let t=this.calculateSegmentWidth(e,p.length===0);p.length>0&&m+t>c&&(l.push(this.buildLineFromSegments(p,o)),p=[],m=0),p.push(e),m+=t}p.length>0&&l.push(this.buildLineFromSegments(p,o))}return l.join(`
|
|
10
|
+
`)}async generateTuiStatusline(e){let t=this.getThemeColors(),n=pt(),r=e.workspace?.current_dir||e.cwd||`/`,i=(this.config.display.charset||`unicode`)===`text`?ot:at,a=this.config.display.lines.map(e=>e.segments.context).find(e=>e?.enabled)?.autocompactBuffer??33e3,o=await Promise.allSettled([this.usageProvider.getUsageInfo(e.session_id,e),this.blockProvider.getActiveBlockInfo(e),this.todayProvider.getTodayInfo(),this.contextProvider.getContextInfo(e,a),this.metricsProvider.getMetricsInfo(e.session_id,e),this.gitService.getGitInfo(r,{showSha:!1,showWorkingTree:!0,showOperation:!1,showTag:!1,showTimeSinceCommit:!1,showStashCount:!1,showUpstream:!1,showRepoName:!1},e.workspace?.project_dir),this.tmuxService.getSessionId()]),s=e=>e.status===`fulfilled`?e.value:null,[c,l,u,d,f,p,m]=[s(o[0]),s(o[1]),s(o[2]),s(o[3]),s(o[4]),s(o[5]),s(o[6])];return Ft({hookData:e,usageInfo:c,blockInfo:l,todayInfo:u,contextInfo:d,metricsInfo:f,gitInfo:p,tmuxSessionId:m,colors:t},i,t.reset,n,this.config)}calculateSegmentWidth(e,t){let n=this.config.display.style===`capsule`,r=B(e.text),i=(this.config.display.padding??1)*2;return n?r+(2+i+(t?0:1)):r+(1+i)}buildLineFromSegments(e,t){let n=this.config.display.style===`capsule`,r=t.reset;for(let i=0;i<e.length;i++){let a=e[i];if(!a)continue;let o=i===0,s=i===e.length-1?null:e[i+1];n&&!o&&(r+=` `),r+=this.formatSegment(a.bgColor,a.fgColor,a.text,s?.bgColor,t)}return r}async renderLine(e,t,n,r,i,a,o){let s=this.getThemeColors(),c=t.workspace?.current_dir||t.cwd||`/`,l=Object.entries(e.segments).filter(([e,t])=>t?.enabled).map(([e,t])=>({type:e,config:t})),u=[];for(let e of l){let l=await this.renderSegment(e,t,n,r,i,a,o,s,c);l&&u.push({type:e.type,text:l.text,bgColor:l.bgColor,fgColor:l.fgColor})}return this.buildLineFromSegments(u,s)}async renderSegment(e,t,n,r,i,a,o,s,c){return e.type===`directory`?this.segmentRenderer.renderDirectory(t,s,e.config):e.type===`model`?this.segmentRenderer.renderModel(t,s):e.type===`git`?await this.renderGitSegment(e.config,t,s,c):e.type===`session`?this.renderSessionSegment(e.config,n,s):e.type===`sessionId`?t.session_id?this.segmentRenderer.renderSessionId(t.session_id,s,e.config):null:e.type===`tmux`?await this.renderTmuxSegment(s):e.type===`context`?this.renderContextSegment(e.config,a,s):e.type===`metrics`?this.renderMetricsSegment(e.config,o,r,s):e.type===`block`?this.renderBlockSegment(e.config,r,s):e.type===`today`?this.renderTodaySegment(e.config,i,s):e.type===`version`?this.renderVersionSegment(e.config,t,s):e.type===`env`?this.segmentRenderer.renderEnv(s,e.config):e.type===`weekly`?this.segmentRenderer.renderWeekly(t,s,e.config):null}async renderGitSegment(e,t,n,r){if(!this.needsSegmentInfo(`git`))return null;let i=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 i?this.segmentRenderer.renderGit(i,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`,i=t===`text`?st:it;return{right:n?``:r?i.right_rounded:i.right,left:r?i.left_rounded:``,branch:i.branch,model:i.model,git_clean:i.git_clean,git_dirty:i.git_dirty,git_conflicts:i.git_conflicts,git_ahead:i.git_ahead,git_behind:i.git_behind,git_worktree:i.git_worktree,git_tag:i.git_tag,git_sha:i.git_sha,git_upstream:i.git_upstream,git_stash:i.git_stash,git_time:i.git_time,session_cost:i.session_cost,block_cost:i.block_cost,today_cost:i.today_cost,context_time:i.context_time,metrics_response:i.metrics_response,metrics_last_response:i.metrics_last_response,metrics_duration:i.metrics_duration,metrics_messages:i.metrics_messages,metrics_lines_added:i.metrics_lines_added,metrics_lines_removed:i.metrics_lines_removed,metrics_burn:i.metrics_burn,version:i.version,bar_filled:i.bar_filled,bar_empty:i.bar_empty,env:i.env,session_id:i.session_id,weekly_cost:i.weekly_cost}}getThemeColors(){let e=this.config.theme,t,n=this.config.display.colorCompatibility||`auto`,r=n===`auto`?C():n;if(e===`custom`){if(t=this.config.colors?.custom,!t)throw Error(`Custom theme selected but no colors provided in configuration`)}else t=E(e,r),t||=(console.warn(`Built-in theme '${e}' not found, falling back to 'dark' theme`),E(`dark`,r));let i=E(`dark`,r),a=this.config.display.style===`tui`,o=e===`light`?`#f0f0f0`:`#1e1e1e`,s=e=>{let n=t[e]||i[e],s=n.fg;return a&&ie(s,o)<60&&(s=n.bg),r===`none`?{bg:``,fg:``}:r===`ansi`?{bg:re(n.bg,!0),fg:re(s,!1)}:r===`ansi256`?{bg:w(n.bg,!0),fg:w(s,!1)}:{bg:ne(n.bg,!0),fg:ne(s,!1)}},c=s(`directory`),l=s(`git`),u=s(`model`),d=s(`session`),f=s(`block`),p=s(`today`),m=s(`tmux`),h=s(`context`),g=s(`contextWarning`),_=s(`contextCritical`),v=s(`metrics`),y=s(`version`),b=s(`env`),x=s(`weekly`);return{reset:r===`none`?``:`\x1B[0m`,modeBg:c.bg,modeFg:c.fg,gitBg:l.bg,gitFg:l.fg,modelBg:u.bg,modelFg:u.fg,sessionBg:d.bg,sessionFg:d.fg,blockBg:f.bg,blockFg:f.fg,todayBg:p.bg,todayFg:p.fg,tmuxBg:m.bg,tmuxFg:m.fg,contextBg:h.bg,contextFg:h.fg,contextWarningBg:g.bg,contextWarningFg:g.fg,contextCriticalBg:_.bg,contextCriticalFg:_.fg,metricsBg:v.bg,metricsFg:v.fg,versionBg:y.bg,versionFg:y.fg,envBg:b.bg,envFg:b.fg,weeklyBg:x.bg,weeklyFg:x.fg}}getSegmentBgColor(e,t){switch(e){case`directory`:return t.modeBg;case`git`:return t.gitBg;case`model`:return t.modelBg;case`session`:case`sessionId`: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;case`weekly`:return t.weeklyBg;default:return t.modeBg}}formatSegment(e,t,n,r,i){let a=this.config.display.style===`capsule`,o=` `.repeat(this.config.display.padding??1);if(a){let r=this.config.display.colorCompatibility||`auto`,a=S(e,(r===`auto`?C():r)===`ansi`);return`${`${a}${this.symbols.left}${i.reset}`}${`${e}${t}${o}${n}${o}${i.reset}`}${`${a}${this.symbols.right}${i.reset}`}`}let s=`${e}${t}${o}${n}${o}`,c=this.config.display.colorCompatibility||`auto`,l=(c===`auto`?C():c)===`ansi`;if(r){let t=S(e,l);s+=`${i.reset}${r}${t}${this.symbols.right}`}else s+=`${i.reset}${S(e,l)}${this.symbols.right}${i.reset}`;return s}};const Lt={theme:`dark`,display:{style:`minimal`,charset:`unicode`,colorCompatibility:`auto`,autoWrap:!0,padding:1,lines:[{segments:{directory:{enabled:!0,style:`basename`},git:{enabled:!0,showSha:!1,showWorkingTree:!1,showOperation:!1,showTag:!1,showTimeSinceCommit:!1,showStashCount:!1,showUpstream:!1,showRepoName:!1},model:{enabled:!0},session:{enabled:!0,type:`tokens`,costSource:`calculated`},today:{enabled:!0,type:`cost`},block:{enabled:!1,type:`cost`,burnType:`cost`,displayStyle:`text`},weekly:{enabled:!1,displayStyle:`text`},version:{enabled:!1},tmux:{enabled:!1},sessionId:{enabled:!1,showIdLabel:!0},context:{enabled:!0,showPercentageOnly:!1,displayStyle:`text`,autocompactBuffer:33e3},metrics:{enabled:!1,showResponseTime:!0,showLastResponseTime:!0,showDuration:!0,showMessageCount:!0,showLinesAdded:!0,showLinesRemoved:!0}}}]},budget:{session:{warningThreshold:80},today:{warningThreshold:80,amount:50},block:{warningThreshold:80,amount:15}},modelContextLimits:{default:2e5,sonnet:2e5,opus:2e5}};function Y(e){return[`light`,`dark`,`nord`,`tokyo-night`,`rose-pine`,`gruvbox`,`custom`].includes(e)}function X(e){return e===`minimal`||e===`powerline`||e===`capsule`||e===`tui`}function Rt(e){return e===`unicode`||e===`text`}function Z(e,t){for(let n=0;n<e.length;n++){let r=e[n];if(r===t&&n+1<e.length)return e[n+1];if(r?.startsWith(`${t}=`))return r.split(`=`)[1]}}function Q(e,t){let n={...e};for(let e in t){let r=t[e];r!==void 0&&(typeof r==`object`&&r&&!Array.isArray(r)?n[e]=Q(n[e]||{},r):n[e]=r)}return n}function zt(e,t){return e?o.existsSync(e)?e:null:[...t?[u.join(t,`.claude-powerline.json`)]:[],u.join(process.cwd(),`.claude-powerline.json`),u.join(g.homedir(),`.claude`,`claude-powerline.json`),u.join(g.homedir(),`.config`,`claude-powerline`,`config.json`)].find(o.existsSync)||null}function Bt(e){try{let t=o.readFileSync(e,`utf-8`);return JSON.parse(t)}catch(t){throw Error(`Failed to load config file ${e}: ${t instanceof Error?t.message:String(t)}`)}}function Vt(){let e={},t={},n=process.env.CLAUDE_POWERLINE_THEME;n&&Y(n)&&(e.theme=n);let r=process.env.CLAUDE_POWERLINE_STYLE;return r&&(X(r)?t.style=r:(console.warn(`Invalid display style '${r}' from environment variable, falling back to 'minimal'`),t.style=`minimal`)),Object.keys(t).length>0&&(e.display=t),e}function Ht(){return process.env.CLAUDE_POWERLINE_CONFIG}function Ut(e){let t={},n={},r=Z(e,`--theme`);r&&Y(r)&&(t.theme=r);let i=Z(e,`--style`);i&&(X(i)?n.style=i:(console.warn(`Invalid display style '${i}' from CLI argument, falling back to 'minimal'`),n.style=`minimal`));let a=Z(e,`--charset`);return a&&(Rt(a)?n.charset=a:(console.warn(`Invalid charset '${a}' from CLI argument, falling back to 'unicode'`),n.charset=`unicode`)),Object.keys(n).length>0&&(t.display=n),t}function Wt(e=process.argv,t){let n=JSON.parse(JSON.stringify(Lt)),r=Z(e,`--config`)||Ht(),i=zt(r?.startsWith(`~`)?r.replace(`~`,g.homedir()):r,t);if(i)try{let e=Bt(i);n=Q(n,e)}catch(e){console.warn(`Warning: ${e instanceof Error?e.message:String(e)}`)}n.display?.style&&!X(n.display.style)&&(console.warn(`Invalid display style '${n.display.style}' in config file, falling back to 'minimal'`),n.display.style=`minimal`),n.display?.charset&&!Rt(n.display.charset)&&(console.warn(`Invalid charset '${n.display.charset}' in config file, falling back to 'unicode'`),n.display.charset=`unicode`),n.theme&&!Y(n.theme)&&(console.warn(`Invalid theme '${n.theme}' in config file, falling back to 'dark'`),n.theme=`dark`);let a=Vt();n=Q(n,a);let o=Ut(e);return n=Q(n,o),n}const Gt=Wt;function $(){console.log(`
|
|
11
11
|
claude-powerline - Beautiful powerline statusline for Claude Code
|
|
12
12
|
|
|
13
13
|
Usage: claude-powerline [options]
|
|
@@ -26,7 +26,7 @@ Claude Code Options (for settings.json):
|
|
|
26
26
|
|
|
27
27
|
See example config at: https://github.com/Owloops/claude-powerline/blob/main/.claude-powerline.json
|
|
28
28
|
|
|
29
|
-
`)}async function
|
|
29
|
+
`)}async function Kt(){try{(e.argv.includes(`--help`)||e.argv.includes(`-h`))&&($(),e.exit(0)),e.stdin.isTTY===!0&&(console.error(`Error: This tool requires input from Claude Code
|
|
30
30
|
|
|
31
31
|
claude-powerline is designed to be used as a Claude Code statusLine command.
|
|
32
32
|
It reads hook data from stdin and outputs formatted statusline.
|
|
@@ -42,4 +42,4 @@ Add to ~/.claude/settings.json:
|
|
|
42
42
|
Run with --help for more options.
|
|
43
43
|
|
|
44
44
|
To test output manually:
|
|
45
|
-
echo '{"session_id":"test-session","workspace":{"project_dir":"/path/to/project"},"model":{"id":"claude-sonnet-4-5","display_name":"Claude"}}' | claude-powerline --style=powerline`),e.exit(1)),
|
|
45
|
+
echo '{"session_id":"test-session","workspace":{"project_dir":"/path/to/project"},"model":{"id":"claude-sonnet-4-5","display_name":"Claude"}}' | claude-powerline --style=powerline`),e.exit(1)),D(`Working directory: ${e.cwd()}`),D(`Process args:`,e.argv);let n=await t(e.stdin);D(`Received hook data:`,JSON.stringify(n,null,2)),n||(console.error(`Error: No input data received from stdin`),$(),e.exit(1));let r=n.workspace?.project_dir,i=await new It(Gt(e.argv,r)).generateStatusline(n);console.log(i)}catch(t){let n=t instanceof Error?t.message:String(t);console.error(`Error generating statusline:`,n),e.exit(1)}}Kt();export{};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@owloops/claude-powerline",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.22.0",
|
|
4
4
|
"description": "Beautiful vim-style powerline statusline for Claude Code with real-time usage tracking, git integration, and custom themes",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.mjs",
|