@owloops/claude-powerline 1.23.5 → 1.24.1

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 CHANGED
@@ -568,6 +568,18 @@ Create custom themes and configure color compatibility:
568
568
 
569
569
  **Color Options:** `bg` (hex, `transparent`, `none`) • `fg` (hex)
570
570
 
571
+ **TUI Grid Colors:** In TUI grid mode, custom colors also support bare segment names and dot-notation parts as keys. A bare segment key (e.g. `"context"`) sets the default color for the segment and all its parts. A part key (e.g. `"context.bar"`) overrides a specific part:
572
+
573
+ ```json
574
+ "colors": {
575
+ "custom": {
576
+ "model": { "fg": "#e0d68a" },
577
+ "context": { "fg": "#7dcfff" },
578
+ "metrics.lastResponse": { "fg": "#bb9af7" }
579
+ }
580
+ }
581
+ ```
582
+
571
583
  **Compatibility Modes:** `auto` (default), `ansi`, `ansi256`, `truecolor`
572
584
 
573
585
  **Environment Variables:**
@@ -597,11 +609,238 @@ Create custom themes and configure color compatibility:
597
609
  }
598
610
  ```
599
611
 
600
- The panel adapts to terminal width across three breakpoints:
612
+ By default, the TUI panel uses a built-in responsive layout. For full control over what goes where, add a `display.tui` object to your config this activates the **grid layout engine**, a CSS Grid-inspired system that lets you define rows, columns, spans, and responsive breakpoints.
613
+
614
+ #### Grid Layout Configuration
615
+
616
+ Add `display.tui` to your config file to enable the grid engine:
617
+
618
+ ```json
619
+ {
620
+ "display": {
621
+ "style": "tui",
622
+ "tui": {
623
+ "fitContent": true,
624
+ "widthReserve": 45,
625
+ "minWidth": 32,
626
+ "maxWidth": 120,
627
+ "padding": { "horizontal": 4 },
628
+ "separator": {
629
+ "column": " ",
630
+ "divider": "─"
631
+ },
632
+ "box": { ... },
633
+ "title": { ... },
634
+ "footer": { ... },
635
+ "segments": { ... },
636
+ "breakpoints": [ ... ]
637
+ }
638
+ }
639
+ }
640
+ ```
641
+
642
+ | Property | Type | Default | Description |
643
+ |---|---|---|---|
644
+ | `fitContent` | `boolean` | `false` | Panel shrinks to fit content instead of filling terminal width |
645
+ | `widthReserve` | `number` | `45` | Characters reserved from terminal width (ignored when `fitContent: true`) |
646
+ | `minWidth` | `number` | `32` | Minimum panel width |
647
+ | `maxWidth` | `number` | `∞` | Maximum panel width |
648
+ | `padding.horizontal` | `number` | `0` | Extra horizontal padding in `fitContent` mode |
649
+ | `separator.column` | `string` | `" "` | String placed between columns |
650
+ | `separator.divider` | `string` | box char | Character used for `---` divider rows |
651
+ | `box` | `object` | — | Custom box-drawing characters (see below) |
652
+ | `title` | `object` | — | Title bar text configuration (see below) |
653
+ | `footer` | `object` | — | Footer text configuration (see below) |
654
+ | `segments` | `object` | — | Custom segment templates (see below) |
655
+ | `breakpoints` | `array` | required | Responsive layout definitions |
656
+
657
+ #### Breakpoints
658
+
659
+ Each breakpoint defines a complete layout that activates when the panel width is at or above its `minWidth`. The engine picks the first match, sorted widest-first.
660
+
661
+ ```json
662
+ "breakpoints": [
663
+ {
664
+ "minWidth": 80,
665
+ "areas": [
666
+ "git.head git.head git.head . git.working",
667
+ "---",
668
+ "context.icon context.bar context.bar context.pct context.tokens",
669
+ "block.icon block.bar block.bar block.value block.time"
670
+ ],
671
+ "columns": ["auto", "1fr", "auto", "auto", "auto"],
672
+ "align": ["left", "left", "right", "right", "right"]
673
+ },
674
+ {
675
+ "minWidth": 55,
676
+ "areas": [
677
+ "git.head git.working",
678
+ "---",
679
+ "context.bar context.tokens",
680
+ "block ."
681
+ ],
682
+ "columns": ["1fr", "auto"],
683
+ "align": ["left", "right"]
684
+ },
685
+ {
686
+ "minWidth": 0,
687
+ "areas": [
688
+ "git.head",
689
+ "git.working",
690
+ "---",
691
+ "context",
692
+ "block"
693
+ ],
694
+ "columns": ["1fr"],
695
+ "align": ["left"]
696
+ }
697
+ ]
698
+ ```
699
+
700
+ | Property | Type | Required | Description |
701
+ |---|---|---|---|
702
+ | `minWidth` | `number` | yes | Minimum panel width to activate this layout |
703
+ | `areas` | `string[]` | yes | Grid rows — each string is one row of space-separated cell names |
704
+ | `columns` | `string[]` | yes | Column sizing: `"auto"`, `"1fr"` / `"2fr"`, or a fixed number like `"20"` |
705
+ | `align` | `string[]` | no | Per-column alignment: `"left"`, `"center"`, or `"right"` (defaults to `"left"`) |
706
+
707
+ **Column sizing:**
708
+ - `"auto"` — shrinks to the widest content in that column
709
+ - `"1fr"`, `"2fr"` — fractional units that divide remaining space proportionally
710
+ - `"20"` — fixed width in characters
711
+
712
+ **Special area tokens:**
713
+ - `.` — empty cell (renders as blank space)
714
+ - `---` — full-width horizontal divider row
715
+
716
+ **Spanning:** repeat the same name in adjacent cells to span columns:
717
+
718
+ ```
719
+ "context.bar context.bar context.bar context.pct context.tokens"
720
+ ```
721
+
722
+ Here `context.bar` spans the first three columns.
723
+
724
+ #### Segment Names
725
+
726
+ Use bare segment names to render the full pre-formatted segment:
727
+
728
+ ```
729
+ context block session today weekly
730
+ git dir version tmux metrics
731
+ activity burn env
732
+ ```
733
+
734
+ #### Dot-Notation Subsegments
735
+
736
+ Use `segment.part` to place individual pieces of a segment into separate cells with independent alignment:
737
+
738
+ | Segment | Parts |
739
+ |---|---|
740
+ | `git` | `icon`, `branch`, `status`, `ahead`, `behind`, `working`, `head` |
741
+ | `context` | `icon`, `bar`, `pct`, `tokens` |
742
+ | `block` | `icon`, `bar`, `value`, `time`, `budget` |
743
+ | `session` | `icon`, `cost`, `tokens`, `budget` |
744
+ | `today` | `icon`, `cost`, `label`, `budget` |
745
+ | `weekly` | `icon`, `bar`, `pct`, `time` |
746
+ | `metrics` | `response`, `responseIcon`, `responseVal`, `lastResponse`, `lastResponseIcon`, `lastResponseVal`, `added`, `addedIcon`, `addedVal`, `removed`, `removedIcon`, `removedVal` |
747
+ | `activity` | `duration`, `durationIcon`, `durationVal`, `messages`, `messagesIcon`, `messagesVal` |
748
+ | `burn` | `icon`, `rate` |
749
+ | `version` | `icon`, `value` |
750
+ | `tmux` | `label`, `value` |
751
+ | `dir` | `value` |
752
+ | `env` | `prefix`, `value` |
753
+
754
+ Example — block segment with a progress bar, mirroring the context layout:
755
+
756
+ ```json
757
+ "areas": [
758
+ "context.icon context.bar context.bar context.pct context.tokens",
759
+ "block.icon block.bar block.bar block.value block.time"
760
+ ]
761
+ ```
762
+
763
+ > [!NOTE]
764
+ > `context.bar`, `block.bar`, and `weekly.bar` are width-aware — their progress bars render at exactly the resolved column width. Block bar uses `nativeUtilization` when available, or `cost / budget` for transcript mode. Weekly bar uses the 7-day `used_percentage`.
765
+
766
+ #### Custom Box Characters
767
+
768
+ Override individual box-drawing characters. Partial overrides merge with the charset default (`unicode` or `text`):
769
+
770
+ ```json
771
+ "box": {
772
+ "topLeft": "┌",
773
+ "topRight": "┐",
774
+ "bottomLeft": "└",
775
+ "bottomRight": "┘",
776
+ "horizontal": "─",
777
+ "vertical": "│",
778
+ "teeLeft": "├",
779
+ "teeRight": "┤"
780
+ }
781
+ ```
782
+
783
+ Only specify the characters you want to change — the rest inherit from the active charset.
784
+
785
+ #### Title Bar
786
+
787
+ Configure the left and right text in the top border. Supports `{model}` and any `{segment}` or `{segment.part}` token that resolves from segment data:
788
+
789
+ ```json
790
+ "title": {
791
+ "left": "{model}",
792
+ "right": "{dir}"
793
+ }
794
+ ```
795
+
796
+ | Property | Type | Default | Description |
797
+ |---|---|---|---|
798
+ | `left` | `string` | `"{model}"` | Left-side text (supports tokens) |
799
+ | `right` | `string \| false` | `"claude-powerline"` | Right-side text, or `false` to hide |
800
+
801
+ #### Footer
802
+
803
+ Same as the title bar, but on the bottom border. Defaults to no text (plain border):
804
+
805
+ ```json
806
+ "footer": {
807
+ "left": "{weekly}",
808
+ "right": "{metrics.lastResponse}"
809
+ }
810
+ ```
811
+
812
+ | Property | Type | Default | Description |
813
+ |---|---|---|---|
814
+ | `left` | `string` | — | Left-side footer text (supports tokens) |
815
+ | `right` | `string` | — | Right-side footer text (supports tokens) |
816
+
817
+ Tokens resolve any segment or subsegment reference: `{model}`, `{dir}`, `{git.head}`, `{block.value}`, `{metrics.lastResponse}`, etc.
818
+
819
+ #### Segment Templates
820
+
821
+ Define custom compositions for composite cells using the `segments` key. This assembles multiple parts into a single cell:
822
+
823
+ ```json
824
+ "segments": {
825
+ "metrics.lastResponse": {
826
+ "items": ["{lastResponseIcon}", "{lastResponseVal}"],
827
+ "gap": 1,
828
+ "justify": "start"
829
+ }
830
+ }
831
+ ```
832
+
833
+ | Property | Type | Default | Description |
834
+ |---|---|---|---|
835
+ | `items` | `string[]` | required | Part references like `"{partName}"` or literal strings |
836
+ | `gap` | `number` | `1` | Spaces between items |
837
+ | `justify` | `string` | `"start"` | `"start"` packs items left; `"between"` distributes across cell width |
838
+
839
+ The template name (e.g. `metrics.lastResponse`) can then be used as a cell name in `areas`.
840
+
841
+ #### Automatic Culling
601
842
 
602
- - **Wide** (80+ cols): metrics on one line, workspace and footer spread across columns
603
- - **Medium** (55-79 cols): metrics split across two lines, stacked footer
604
- - **Narrow** (<55 cols): fully stacked layout
843
+ Empty segments are automatically removed cells resolve to `.`, empty rows are dropped, and orphaned dividers are cleaned up. A wide layout gracefully degrades when data is unavailable.
605
844
 
606
845
  > [!NOTE]
607
846
  > Claude Code's internal progress indicators (spinner, context bar) may briefly overlap the TUI panel during tool calls. This is a limitation of the hook architecture and resolves once the tool call completes.
package/dist/index.mjs CHANGED
@@ -1,13 +1,14 @@
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 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);D(`Native current_usage: input=${n.input_tokens}, cache_create=${n.cache_creation_input_tokens}, cache_read=${n.cache_read_input_tokens}, total=${i} (limit: ${r})`);let a=e.context_window?.used_percentage,o=this.calculatePercentages(i,r,t);return a!=null&&(o.percentage=Math.round(a),D(`Using native used_percentage: ${a}%`)),{totalTokens:i,maxTokens:r,...o}}async calculateContextTokensFromTranscript(e,t,n=33e3){try{D(`Calculating context tokens from transcript: ${e}`);try{if(!l(e,`utf-8`))return D(`Transcript file is empty`),null}catch{return D(`Could not read transcript file`),null}let r=await A(e);if(r.length===0)return D(`No entries in transcript`),null;let i=null;for(let e=r.length-1;e>=0;e--){let t=r[e];if(t&&t.message?.usage?.input_tokens&&t.isSidechain!==!0){i=t,D(`Context segment: Found most recent entry at ${t.timestamp.toISOString()}, stopping search`);break}}if(i?.message?.usage){let e=i.message.usage,r=(e.input_tokens||0)+(e.cache_read_input_tokens||0)+(e.cache_creation_input_tokens||0),a=t?this.getContextLimit(t):2e5;return D(`Most recent main chain context: ${r} tokens (limit: ${a})`),{totalTokens:r,maxTokens:a,...this.calculatePercentages(r,a,n)}}return D(`No main chain entries with usage data found`),null}catch(e){return D(`Error reading transcript: ${e instanceof Error?e.message:String(e)}`),null}}async getContextInfo(e,t=33e3){return this.calculateContextFromHookData(e,t)||this.calculateContextTokensFromTranscript(e.transcript_path,e.model?.id,t)}},Be=class{async loadTranscriptEntries(e){try{let t=await De(e);if(!t)return D(`No transcript found for session: ${e}`),[];D(`Loading transcript from: ${t}`);let n=(await b(t,`utf-8`)).trim().split(`
7
- `).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!==`??`&&lt.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(`
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}from"node:fs";import l,{dirname as u,join as d}from"node:path";import{get as f}from"node:https";import{URL as p}from"node:url";import m,{homedir as h}from"node:os";import{createHash as g}from"node:crypto";import{setTimeout as _}from"node:timers/promises";import{readFile as v,readdir as y,stat as b}from"node:fs/promises";import{createInterface as x}from"node:readline";function ee(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 te(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 ne(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`},weekly:{bg:`#2a2a3a`,fg:`#a0c4e8`}},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`},weekly:{bg:`#303030`,fg:`#87afd7`}},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`},weekly:{bg:`#3a3a3a`,fg:`#5fafff`}},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`},weekly:{bg:`#4f46e5`,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`},weekly:{bg:`#5f5fff`,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:`#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`}},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`},weekly:{bg:`#4e4e4e`,fg:`#5fafaf`}},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`},weekly:{bg:`#585858`,fg:`#00d7d7`}},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`},weekly:{bg:`#24283b`,fg:`#7dcfff`}},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`},weekly:{bg:`#303050`,fg:`#5fd7ff`}},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`},weekly:{bg:`#444470`,fg:`#00d7ff`}},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`},weekly:{bg:`#21202e`,fg:`#c4a7e7`}},_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`},weekly:{bg:`#303030`,fg:`#d787d7`}},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`},weekly:{bg:`#444444`,fg:`#ff87ff`}},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`},weekly:{bg:`#3c3836`,fg:`#8ec07c`}},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`},weekly:{bg:`#444444`,fg:`#87af87`}},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`},weekly:{bg:`#585858`,fg:`#00d787`}},w={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 T(e,t){let n=w[e];if(!n)return null;if(t===`none`||t===`ansi`){let t=w[`${e}-ansi`];if(t)return t}if(t===`ansi256`){let t=w[`${e}-ansi256`];if(t)return t}return n}function E(e,...t){process.env.CLAUDE_POWERLINE_DEBUG&&console.error(`[DEBUG] ${e}`,...t)}const Se=a(r);var Ce=class{isGitRepo(e){try{return o.existsSync(l.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=l.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 l.resolve(e,n[1].trim())}return t}getOngoingOperation(e){try{let t=this.resolveGitDir(e);return o.existsSync(l.join(t,`MERGE_HEAD`))?`MERGE`:o.existsSync(l.join(t,`CHERRY_PICK_HEAD`))?`CHERRY-PICK`:o.existsSync(l.join(t,`REVERT_HEAD`))?`REVERT`:o.existsSync(l.join(t,`BISECT_LOG`))?`BISECT`:o.existsSync(l.join(t,`rebase-merge`))||o.existsSync(l.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;return Math.floor((Date.now()-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]||l.basename(e)}catch{return l.basename(e)}}isWorktree(e){try{let t=l.join(e,`.git`);return!!(o.existsSync(t)&&o.statSync(t).isFile())}catch{return!1}}async getStatusWithBranchAsync(e){try{E(`[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 E(`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{E(`[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 E(`Git ahead/behind command failed in ${e}:`,t),{ahead:0,behind:0}}}};const we=a(r);var Te=class{async getSessionId(){try{if(!process.env.TMUX_PANE)return E(`TMUX_PANE not set, not in tmux session`),null;E(`Getting tmux session ID, TMUX_PANE: ${process.env.TMUX_PANE}`);let e=(await we(`tmux display-message -p '#S'`,{encoding:`utf8`,timeout:1e3})).stdout.trim();return E(`Tmux session ID: ${e||`empty`}`),e||null}catch(e){return E(`Error getting tmux session ID:`,e),null}}isInTmux(){return!!process.env.TMUX_PANE}};function Ee(){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=h(),n=d(t,`.config`,`claude`),r=d(t,`.claude`);c(n)&&e.push(n),c(r)&&e.push(r)}return e}async function De(e){let t=[];for(let n of e){let e=d(n,`projects`);if(c(e))try{let n=await y(e,{withFileTypes:!0});for(let r of n)if(r.isDirectory()){let n=d(e,r.name);t.push(n)}}catch(t){E(`Failed to read projects directory ${e}:`,t)}}return t}async function Oe(e){let t=await De(Ee());for(let n of t){let t=d(n,`${e}.jsonl`);if(c(t))return t}return null}async function ke(e,t){let n=[],r=d(t,e,`subagents`);try{let t=(await y(r)).filter(e=>e.startsWith(`agent-`)&&e.endsWith(`.jsonl`));for(let i of t){let t=d(r,i);try{let r=(await v(t,`utf-8`)).split(`
5
+ `)[0];r&&JSON.parse(r).sessionId===e&&n.push(t)}catch{E(`Failed to check agent file ${t}`)}}}catch(e){E(`Failed to read subagents directory ${r}:`,e)}return n}async function Ae(e){try{return(await b(e)).mtime}catch{return null}}function je(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 D(e){try{let t=(await b(e)).size,n;return t>1048576?(E(`Using streaming parser for large file ${e} (${Math.round(t/1024)}KB)`),n=await Ne(e)):n=await Me(e),E(`Parsed ${n.length} entries from ${e}`),n}catch(t){return E(`Failed to read file ${e}:`,t),[]}}async function Me(e){let t=(await v(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){E(`Failed to parse JSONL line: ${e}`);continue}return n}async function Ne(e){return new Promise((t,n)=>{let r=[],i=s(e,{encoding:`utf8`}),a=x({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){E(`Failed to parse JSONL line: ${e}`)}}),a.on(`close`,()=>{t(r)}),a.on(`error`,t=>{E(`Streaming parser error for ${e}:`,t),n(t)}),i.on(`error`,t=>{E(`File stream error for ${e}:`,t),n(t)})})}async function Pe(e){try{let t=await Ae(e);return t?{filePath:e,mtime:t}:null}catch{return null}}async function Fe(e,t){try{let n=await y(e,{withFileTypes:!0}),r=n.filter(e=>!e.isDirectory()&&e.name.endsWith(`.jsonl`)).map(t=>Pe(d(e,t.name))),i=n.filter(e=>e.isDirectory()).map(async t=>{let n=d(e,t.name,`subagents`);try{return(await y(n)).filter(e=>e.startsWith(`agent-`)&&e.endsWith(`.jsonl`)).map(e=>Pe(d(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 E(`Failed to read project directory ${e}:`,t),[]}}async function Ie(e,t,n=!1){let r=await De(Ee()),i=new Set,a=r.map(e=>Fe(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 D(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=je(e);t&&i.has(t)||(t&&i.add(t),d.push(e))}return d}var O=class{static CACHE_DIR=l.join(h(),`.claude`,`powerline`);static USAGE_CACHE_DIR=l.join(this.CACHE_DIR,`usage`);static LOCKS_DIR=l.join(this.CACHE_DIR,`locks`);static isLocked(e){let t=l.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 E(`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`?(E(`Removing stale lock file ${e} for dead process ${r}`),o.unlinkSync(t),!1):(E(`Error checking process ${r} for lock ${e}:`,n),!0)}}catch(t){return E(`Error reading lock file ${e}:`,t),!0}}static async acquireLock(e,t=5e3){await this.ensureCacheDirectories();let n=l.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`}),E(`Lock acquired for ${e}`),!0}catch(e){if(e.code===`EEXIST`)await _(50);else throw e}return E(`Failed to acquire lock for ${e} within ${t}ms`),!1}static async releaseLock(e){let t=l.join(this.LOCKS_DIR,e);try{await o.promises.unlink(t),E(`Lock released for ${e}`)}catch(t){t.code!==`ENOENT`&&E(`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){E(`Failed to create cache directories:`,e)}}static createProjectHash(e){return g(`md5`).update(e).digest(`hex`).substring(0,8)}static async getUsageCache(e,t){await this.ensureCacheDirectories();let n=l.join(this.USAGE_CACHE_DIR,`${e}.json`),r=`${e}.usage.lock`;for(let i=0;i<3;i++){if(this.isLocked(r)){E(`Cache for ${e} is locked, waiting...`),await _(75);continue}try{let r=await o.promises.readFile(n,`utf-8`),i=JSON.parse(r);return!t||i.timestamp>=t?(E(`[CACHE-HIT] ${e} disk cache: found`),this.deserializeDates(i.data)):(E(`${e} cache outdated: cache=${i.timestamp}, latest=${t}`),null)}catch(t){if(t.code===`ENOENT`)return E(`No shared ${e} usage cache found`),null;E(`Attempt ${i+1} failed to read ${e} cache: ${t.message}. Retrying...`),await _(75)}}return E(`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)){E(`Could not acquire lock to set usage cache for ${e}`);return}try{await this.ensureCacheDirectories();let r=l.join(this.USAGE_CACHE_DIR,`${e}.json`),i=JSON.stringify({data:t,timestamp:n||Date.now()});await o.promises.writeFile(r,i,`utf-8`),E(`[CACHE-SET] ${e} disk cache stored`)}catch(t){E(`Failed to save ${e} usage cache:`,t)}finally{await this.releaseLock(r)}}static async getLatestTranscriptMtime(){try{let e=await De(Ee()),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 Ae(l.join(n,r));e&&e.getTime()>t&&(t=e.getTime())}}catch(e){E(`Failed to read project directory ${n}:`,e);continue}return t}catch(e){return E(`Failed to get latest transcript mtime:`,e),Date.now()}}};const k={"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 Le=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 O.getUsageCache(`pricing`,e)}static async saveDiskCache(e){await O.setUsageCache(`pricing`,e)}static async fetchPricingData(){return new Promise(e=>{let t=new p(this.GITHUB_PRICING_URL),n=f({hostname:t.hostname,path:t.pathname,headers:{"User-Agent":`claude-powerline`,"Cache-Control":`no-cache`},timeout:5e3},t=>{if(t.statusCode!==200){E(`HTTP ${t.statusCode}: ${t.statusMessage}`),e(null);return}let r=``,i=0;t.on(`data`,t=>{if(i+=t.length,i>1048576){E(`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)?(E(`Fetched fresh pricing from GitHub for ${Object.keys(i).length} models`),E(`Pricing last updated: ${n?.updated||`unknown`}`),e(i)):(E(`Invalid pricing data structure`),e(null))}catch(t){E(`Failed to parse JSON:`,t),e(null)}}),t.on(`error`,t=>{E(`Response error:`,t),e(null)})});n.on(`error`,t=>{E(`Request error:`,t),e(null)}),n.on(`timeout`,()=>{E(`Request timeout`),n.destroy(),e(null)}),n.end()})}static async getCurrentPricing(){if(this.executionCache!==null)return E(`[CACHE-HIT] Pricing execution cache: ${Object.keys(this.executionCache).length} models`),this.executionCache;let e=await this.loadDiskCache();if(e)return E(`[CACHE-HIT] Pricing disk cache: ${Object.keys(e).length} models`),this.executionCache=e,E(`[CACHE-SET] Pricing execution cache stored: ${Object.keys(e).length} models`),e;let t=await this.fetchPricingData();return t?(await this.saveDiskCache(t),E(`[CACHE-SET] Pricing disk cache stored: ${Object.keys(t).length} models`),this.executionCache=t,E(`[CACHE-SET] Pricing execution cache stored: ${Object.keys(t).length} models`),t):(E(`[CACHE-FALLBACK] Using offline pricing data: ${Object.keys(k).length} models`),this.executionCache=k,E(`[CACHE-SET] Pricing execution cache stored: ${Object.keys(k).length} models`),k)}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 E(`[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),E(`[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;if(typeof e==`string`)return e;let n=e;return(typeof n?.id==`string`?n.id:null)||`claude-sonnet-4-5-20250929`}return e.model_id&&typeof e.model_id==`string`?e.model_id:`claude-sonnet-4-5-20250929`}};function Re(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 ze=class{async getSessionUsage(e){try{let t=await Oe(e);if(!t)return E(`No transcript found for session: ${e}`),null;E(`Found transcript at: ${t}`);let n=await D(t),r=await ke(e,u(t));E(`Found ${r.length} agent transcripts for session`);for(let e of r){let t=await D(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=Re(e);if(t.costUSD!==void 0)a+=t.costUSD;else{let n=await Le.calculateCostForEntry(e.raw);t.costUSD=n,a+=n}i.push(t)}return E(`Parsed ${i.length} usage entries, total cost: $${a.toFixed(4)}`),{totalCost:a,entries:i}}catch(t){return E(`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}}},Be=class{sessionProvider=new ze;async getUsageInfo(e,t){try{return E(`Starting usage info retrieval for session: ${e}`),{session:await this.sessionProvider.getSessionInfo(e,t)}}catch(t){return E(`Error getting usage info for session ${e}:`,t),{session:{cost:null,calculatedCost:null,officialCost:null,tokens:null,tokenBreakdown:null}}}}},Ve=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 E(`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);E(`Native current_usage: input=${n.input_tokens}, cache_create=${n.cache_creation_input_tokens}, cache_read=${n.cache_read_input_tokens}, total=${i} (limit: ${r})`);let a=e.context_window?.used_percentage,o=this.calculatePercentages(i,r,t);return a!=null&&(o.percentage=Math.round(a),E(`Using native used_percentage: ${a}%`)),{totalTokens:i,maxTokens:r,...o}}async calculateContextTokensFromTranscript(e,t,n=33e3){try{E(`Calculating context tokens from transcript: ${e}`);let r=await D(e);if(r.length===0)return E(`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,E(`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 E(`Most recent main chain context: ${r} tokens (limit: ${a})`),{totalTokens:r,maxTokens:a,...this.calculatePercentages(r,a,n)}}return E(`No main chain entries with usage data found`),null}catch(e){return E(`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)}},He=class{async loadTranscriptEntries(e){try{let t=await Oe(e);if(!t)return E(`No transcript found for session: ${e}`),[];E(`Loading transcript from: ${t}`);let n=(await v(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){E(`Failed to parse JSONL line: ${e}`);continue}return E(`Loaded ${r.length} transcript entries`),r}catch(t){return E(`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(E(`Getting metrics from hook data for session: ${e}`),!t.cost)return E(`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 E(`Error getting metrics from hook data for session ${e}:`,t),{responseTime:null,lastResponseTime:null,sessionDuration:null,messageCount:null,linesAdded:null,linesRemoved:null}}}};function A(e){return e===null?`$0.00`:e<.01?`<$0.01`:`$${e.toFixed(2)}`}function j(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 Ue(e){if(!e)return`0 tokens`;let t=[];if(e.input>0&&t.push(`${M(e.input)} in`),e.output>0&&t.push(`${M(e.output)} out`),e.cacheCreation>0||e.cacheRead>0){let n=e.cacheCreation+e.cacheRead;t.push(`${M(n)} cached`)}return t.length>0?t.join(` + `):`0 tokens`}function We(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 Ge(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 Ke=/^(?:(?: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 qe(e){if(!e)return`Claude`;let t=e.trim().match(Ke);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 Je(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 Ye(e){return e<60?`${e.toFixed(1)}s`:`${(e/60).toFixed(1)}m`}function M(e){return j(e).replace(` tokens`,``)}function N(e){return e==null||e<=0?``:e<1?`${(e*100).toFixed(0)}c/h`:`$${e.toFixed(2)}/h`}function Xe(e){let t=process.env.HOME||process.env.USERPROFILE;return t&&e.startsWith(t)?e.replace(t,`~`):e}function Ze(e){let t=Math.floor(e/60),n=e%60;return t>0?`${t}h ${n}m left`:`${n}m left`}function Qe(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 $e(e){return Math.round(Math.max(0,e*1e3-Date.now())/6e4)}function et(e,t){return!t||t<=0||e<0?null:Math.min(100,e/t*100)}function P(e,t,n=80){let r=et(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 tt={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 nt=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:l.basename(r)||`root`,bgColor:t.modeBg,fgColor:t.modeFg};let o=Xe(r),s=i&&Xe(i),c=this.getDisplayDirectoryName(o,s);return a===`fish`&&(c=Je(c)),{text:c,bgColor:t.modeBg,fgColor:t.modeFg}}renderGit(e,t,n){if(!e)return null;let r=[];if(n?.showRepoName&&e.repoName&&(r.push(e.repoName),e.isWorktree&&r.push(this.symbols.git_worktree)),n?.showOperation&&e.operation&&r.push(`[${e.operation}]`),r.push(`${this.symbols.branch} ${e.branch}`),n?.showTag&&e.tag&&r.push(`${this.symbols.git_tag} ${e.tag}`),n?.showSha&&e.sha&&r.push(`${this.symbols.git_sha} ${e.sha}`),n?.showAheadBehind!==!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=We(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=qe(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}:tt[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){if(!e)return{text:`${this.symbols.metrics_response} new`,bgColor:t.metricsBg,fgColor:t.metricsFg};let r=[];if(n?.showLastResponseTime&&e.lastResponseTime!==null){let t=e.lastResponseTime<60?`${e.lastResponseTime.toFixed(1)}s`:`${(e.lastResponseTime/60).toFixed(1)}m`;r.push(`${this.symbols.metrics_last_response} ${t}`)}if(n?.showResponseTime!==!1&&e.responseTime!==null){let t=e.responseTime<60?`${e.responseTime.toFixed(1)}s`:`${(e.responseTime/60).toFixed(1)}m`;r.push(`${this.symbols.metrics_response} ${t}`)}if(n?.showDuration!==!1&&e.sessionDuration!==null){let t=Ge(e.sessionDuration);r.push(`${this.symbols.metrics_duration} ${t}`)}return n?.showMessageCount!==!1&&e.messageCount!==null&&r.push(`${this.symbols.metrics_messages} ${e.messageCount}`),n?.showLinesAdded!==!1&&e.linesAdded!==null&&e.linesAdded>0&&r.push(`${this.symbols.metrics_lines_added} ${e.linesAdded}`),n?.showLinesRemoved!==!1&&e.linesRemoved!==null&&e.linesRemoved>0&&r.push(`${this.symbols.metrics_lines_removed} ${e.linesRemoved}`),r.length===0?{text:`${this.symbols.metrics_response} active`,bgColor:t.metricsBg,fgColor:t.metricsFg}:{text:r.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=j(e.weightedTokens);s=t&&e.weightedTokens!==null?`${n}${P(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=` | ${N(e.burnRate)||`N/A`}`;break;case`tokens`:c=` | ${e.tokenBurnRate===null?`N/A`:`${j(Math.round(e.tokenBurnRate))}/h`}`;break;case`both`:c=` | ${N(e.burnRate)||`N/A`} / ${e.tokenBurnRate===null?`N/A`:`${j(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){return e===null?null:Qe(e)}renderWeekly(e,t,n){let r=e.rate_limits?.seven_day;if(!r)return null;let i=Math.round(r.used_percentage),a=Qe($e(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)||l.basename(t)||`project`:e}formatUsageDisplay(e,t,n,r){switch(r){case`cost`:return A(e);case`tokens`:return j(t);case`both`:return`${A(e)} (${j(t)})`;case`breakdown`:return Ue(n);default:return A(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+P(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 rt(e){return e.includes(`opus`)?5:(e.includes(`sonnet`)||e.includes(`haiku`),1)}function it(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 at=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{E(`Block segment: Loading entries for dynamic session blocks`);let e=new Date;e.setDate(e.getDate()-1);let t=await Ie(void 0,(t,n)=>n>=e,!0),n=[];for(let e of t)if(e.message?.usage){let t=it(e);!t.costUSD&&e.raw&&(t.costUSD=await Le.calculateCostForEntry(e.raw)),n.push(t)}let r=this.identifySessionBlocks(n);E(`Block segment: Found ${r.length} session blocks`);let i=this.findActiveBlock(r),a=[];if(i&&i.length>0){E(`Block segment: Found active block with ${i.length} entries`);let e=i[0],t=i[i.length-1];e&&t&&E(`Block segment: Active block from ${e.timestamp.toISOString()} to ${t.timestamp.toISOString()}`),a=i}else E(`Block segment: No active block found`),a=[];return a}catch(e){return E(`Error loading block entries:`,e),[]}}async getActiveBlockInfo(e){let t=e?.rate_limits?.five_hour;if(t){let e=$e(t.resets_at);return E(`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 E(`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)*rt(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 E(`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 E(`Error getting active block info:`,e),{cost:null,tokens:null,weightedTokens:null,timeRemaining:null,burnRate:null,tokenBurnRate:null,source:`transcript`,nativeUtilization:null}}}};function F(e){return`${e.getFullYear()}-${String(e.getMonth()+1).padStart(2,`0`)}-${String(e.getDate()).padStart(2,`0`)}`}function ot(e){return e.inputTokens+e.outputTokens+e.cacheCreationInputTokens+e.cacheReadInputTokens}function st(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 ct=class{async loadTodayEntries(){let e=F(new Date);E(`Today segment: Loading entries for date ${e}`);let t=await O.getLatestTranscriptMtime(),n=await O.getUsageCache(`today`,t);if(n)return E(`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 Ie(e=>e.timestamp>=a,i,!0),s=[],c=0;for(let t of o)if(F(t.timestamp)===e&&t.message?.usage){let e=st(t);!e.costUSD&&t.raw&&(e.costUSD=await Le.calculateCostForEntry(t.raw)),s.push(e),c++}return E(`Today segment: Found ${c} entries for today (${e})`),await O.setUsageCache(`today`,s,t),s}async getTodayEntries(){try{return await this.loadTodayEntries()}catch(e){return E(`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:F(new Date)};let t=e.reduce((e,t)=>e+t.costUSD,0),n=e.reduce((e,t)=>e+ot(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 E(`Today segment: $${t.toFixed(2)}, ${n} tokens total`),{cost:t,tokens:n,tokenBreakdown:r,date:F(new Date)}}catch(e){return E(`Error getting today's info:`,e),{cost:null,tokens:null,tokenBreakdown:null,date:F(new Date)}}}};const lt={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:`◑`},ut={topLeft:`╭`,topRight:`╮`,bottomLeft:`╰`,bottomRight:`╯`,horizontal:`─`,vertical:`│`,teeLeft:`├`,teeRight:`┤`},dt={topLeft:`+`,topRight:`+`,bottomLeft:`+`,bottomRight:`+`,horizontal:`-`,vertical:`|`,teeLeft:`+`,teeRight:`+`},I={rounded:ut,square:{topLeft:`┌`,topRight:`┐`,bottomLeft:`└`,bottomRight:`┘`,horizontal:`─`,vertical:`│`,teeLeft:`├`,teeRight:`┤`},heavy:{topLeft:`┏`,topRight:`┓`,bottomLeft:`┗`,bottomRight:`┛`,horizontal:`━`,vertical:`┃`,teeLeft:`┣`,teeRight:`┫`},double:{topLeft:`╔`,topRight:`╗`,bottomLeft:`╚`,bottomRight:`╝`,horizontal:`═`,vertical:`║`,teeLeft:`╠`,teeRight:`╣`},dashed:{topLeft:`╭`,topRight:`╮`,bottomLeft:`╰`,bottomRight:`╯`,horizontal:`┄`,vertical:`┊`,teeLeft:`├`,teeRight:`┤`},"heavy-dashed":{topLeft:`┏`,topRight:`┓`,bottomLeft:`┗`,bottomRight:`┛`,horizontal:`┅`,vertical:`┇`,teeLeft:`┣`,teeRight:`┫`},mixed:{topLeft:`┍`,topRight:`┑`,bottomLeft:`┕`,bottomRight:`┙`,horizontal:`━`,vertical:`│`,teeLeft:`┝`,teeRight:`┥`},ascii:dt,invisible:{topLeft:` `,topRight:` `,bottomLeft:` `,bottomRight:` `,horizontal:` `,vertical:` `,teeLeft:` `,teeRight:` `}},ft={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`},pt=RegExp(`\x1B\\[[0-9;]*m`,`g`),mt=RegExp(`(\x1B\\[[0-9;]*m)`),ht=/^[a-zA-Z0-9/]+$/;function gt(){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!==`??`&&ht.test(r))return r;if(!n||n===`1`||n===`0`)break;e=n}catch{break}return null}function _t(){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 vt(){let e=gt();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 yt(){let e=e=>Math.max(1,e-45),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=_t();if(t)return e(t)}let n=vt();return n?e(n):null}function bt(){return process.platform===`win32`?_t():vt()}function xt(e){return e.replace(pt,``)}function L(e){return xt(e).length}function R(e,t,n){return t?`${t}${e}${n}`:e}function z(e,t){let n=L(e);return n>=t?e:e+` `.repeat(t-n)}function St(e,t){let n=L(e);return n>=t?e:` `.repeat(t-n)+e}function Ct(e,t){let n=L(e);if(n>=t)return e;let r=t-n,i=Math.floor(r/2),a=r-i;return` `.repeat(i)+e+` `.repeat(a)}function B(e,t){if(xt(e).length<=t)return e;let n=0,r=``,i=e.split(mt);for(let e of i){if(e.startsWith(`\x1B`)){r+=e;continue}for(let i of e){if(n>=t-1)return r+=`…\x1B[0m`,r;r+=i,n++}}return r}function V(e,t,n){let r=n-2,i=z(B(t,r),r);return e.vertical+` `+i+` `+e.vertical}function H(e,t){return e.teeLeft+e.horizontal.repeat(t)+e.teeRight}function wt(e,t,n,r){if(!n&&!r)return e.bottomLeft+e.horizontal.repeat(t)+e.bottomRight;let i=n?` ${n} `:``,a=r?` ${r} `:``,o=L(i),s=L(a);if(o+s>t){let e=Math.max(0,t-s);if(o>e&&(i=B(i,e),o=L(i)),o+s>t){let e=Math.max(0,t-o);a=B(a,e),s=L(a)}}let c=t-o-s;return e.bottomLeft+i+e.horizontal.repeat(Math.max(0,c))+a+e.bottomRight}function Tt(e,t){if(e.length===0)return``;if(e.length===1)return e[0]??``;let n=e.map(e=>L(e)),r=t-n.reduce((e,t)=>e+t,0),i=Math.max(2,Math.floor(r/(e.length-1))),a=Array.from({length: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 U(e,t,n){if(!t)return e;if(!e)return t;let r=L(e),i=L(t),a=n-r-i;return a<2?`${e} ${t}`:e+` `.repeat(a)+t}function W(e,t,n){let r=qe(t.hookData.model?.display_name||`Claude`).toLowerCase();return e.replace(/\{([^}]+)\}/g,(e,t)=>{if(n){let e=n[t];if(e!==void 0)return e}return t===`model`?r:``})}function Et(e,t,n,r,i){let a=r?.left??`{model}`,o=r?.right===void 0?`claude-powerline`:r.right,s=o!==!1,c=W(a,e,i),l=c?` ${c} `:``,u=L(l);if(!s||!o){let e=n-u;return t.topLeft+l+t.horizontal.repeat(Math.max(0,e))+t.topRight}let d=W(o,e,i),f=d?` ${d} `:``,p=L(f),m=l,h=u,g=f,_=p;if(h+_>n){let e=Math.max(0,n-_);if(h>e&&(m=B(m,e),h=L(m)),h+_>n){let e=Math.max(0,n-h);g=B(g,e),_=L(g)}}let v=n-h-_;if(v<2){let e=n-h;return t.topLeft+m+t.horizontal.repeat(Math.max(0,e))+t.topRight}return t.topLeft+m+t.horizontal.repeat(v)+g+t.topRight}function G(e,t,n,r=60,i=80){return e>=i?n.contextCriticalFg:e>=r?n.contextWarningFg:t}function Dt(e,t,n,r,i){t=Math.max(5,t);let a=Math.max(0,Math.min(t,Math.round(e/100*t))),o=t-a;return R(n.bar_filled.repeat(a)+n.bar_empty.repeat(o),i,r)}function Ot(e,t){if(!e.contextInfo)return{icon:``,bar:``,pct:``,tokens:``};let n=e.contextInfo.usablePercentage,r=M(e.contextInfo.totalTokens),i=M(e.contextInfo.maxTokens);return{icon:t.context_time,bar:` `,pct:`${n}%`,tokens:`${r}/${i}`}}function kt(e,t,n,r,i,a){if(!e.contextInfo)return``;let o=e.contextInfo.usablePercentage;return Dt(o,t,n,r,G(o,a?.[`context.bar`]??a?.context??i.contextFg,i))}function At(e,t,n,r,i,a,o){if(!e.blockInfo)return``;let s=null;if(e.blockInfo.source===`native`&&e.blockInfo.nativeUtilization!==null)s=e.blockInfo.nativeUtilization;else{let t=a.budget?.block;t?.amount&&e.blockInfo.cost!==null&&(s=Math.min(100,e.blockInfo.cost/t.amount*100))}if(s===null)return``;let c=a.budget?.block?.warningThreshold??80,l=o?.[`block.bar`]??o?.block??i.blockFg,u=G(s,l,i,50,c);return Dt(s,t,n,r,u)}function jt(e,t,n,r,i,a){let o=e.hookData.rate_limits?.seven_day;if(!o)return``;let s=o.used_percentage;return Dt(s,t,n,r,G(s,a?.[`weekly.bar`]??a?.weekly??i.weeklyFg,i))}function Mt(e,t,n,r,i){if(!e.contextInfo)return null;let a=e.contextInfo.usablePercentage,o=` ${a}% ${M(e.contextInfo.totalTokens)}/${M(e.contextInfo.maxTokens)}`,s=Math.max(5,t-o.length),c=Math.max(0,Math.min(s,Math.round(a/100*s))),l=s-c,u=n.bar_filled.repeat(c)+n.bar_empty.repeat(l),d=G(a,i.contextFg,i);return R(`${u}${o}`,d,r)}function Nt(e){return Xe(e.workspace?.current_dir||e.cwd||`/`)}function Pt(e,t,n,r,i){let a=[];e.blockInfo&&a.push(R(K(e.blockInfo,t,n),i.blockFg,r));let o=e.hookData.rate_limits?.seven_day;o&&a.push(R(q(o,t),i.weeklyFg,r)),e.usageInfo&&a.push(R(Vt(e.usageInfo,t,n),i.sessionFg,r)),e.todayInfo&&a.push(R(Ut(e.todayInfo,t,n),i.todayFg,r));let s=Ft(e,t);return s.length>0&&a.push(R(s.join(` · `),i.metricsFg,r)),a}function Ft(e,t){let n=[];return e.metricsInfo&&(e.metricsInfo.sessionDuration!==null&&e.metricsInfo.sessionDuration>0&&n.push(`${t.metrics_duration} ${Ge(e.metricsInfo.sessionDuration)}`),e.metricsInfo.messageCount!==null&&e.metricsInfo.messageCount>0&&n.push(`${t.metrics_messages} ${e.metricsInfo.messageCount}`)),n}function It(e,t,n,r){let i=[],a=Zt(e,t);a&&i.push(R(a,r.gitFg,n));let o=Je(Nt(e.hookData));return i.push(R(o,r.modeFg,n)),i}function Lt(e,t,n,r,i){let a=[];if(e.hookData.version&&a.push(R(`${t.version} v${e.hookData.version}`,i.versionFg,r)),e.tmuxSessionId&&a.push(R(`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} ${Ye(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`){let r=N(e.blockInfo?.burnRate);r&&n.push(`${t.metrics_burn} ${r}`)}n.length>0&&a.push(R(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(R(t?`${t}:${e}`:e,i.envFg,r))}}return a}function Rt(e,t,n){let r;r=e.source===`native`&&e.nativeUtilization!==null?`${Math.round(e.nativeUtilization)}%`:A(e.cost);let i=e.timeRemaining===null?``:Ze(e.timeRemaining),a=``;if(e.source!==`native`){let t=n.budget?.block;t?.amount&&e.cost!==null&&(a=P(e.cost,t.amount,t.warningThreshold||80).displayText)}let o=!1;return(e.source===`native`&&e.nativeUtilization!==null||n.budget?.block?.amount&&e.cost!==null)&&(o=!0),{icon:t.block_cost,value:r,time:i,budget:a,bar:o?` `:``}}function K(e,t,n){let r=Rt(e,t,n),i=`${r.icon} ${r.value}`;return r.time&&(i+=` · ${r.time}`),r.budget&&(i+=r.budget),i}function zt(e,t){let n=`${Math.round(e.used_percentage)}%`,r=Qe($e(e.resets_at));return{icon:t.weekly_cost,pct:n,time:r,bar:` `}}function q(e,t){let n=zt(e,t),r=`${n.icon} ${n.pct}`;return n.time&&(r+=` · ${n.time}`),r}function Bt(e,t,n){let r=e.session.tokens,i=r!==null&&r>0?M(r):``,a=``,o=n.budget?.session;return o?.amount&&e.session.cost!==null&&(a=P(e.session.cost,o.amount,o.warningThreshold||80).displayText),{icon:t.session_cost,cost:A(e.session.cost),tokens:i,budget:a}}function Vt(e,t,n){let r=Bt(e,t,n),i=`${r.icon} ${r.cost}`;return r.tokens&&(i+=` · ${r.tokens}`),r.budget&&(i+=r.budget),i}function Ht(e,t,n){let r=``,i=n.budget?.today;return i?.amount&&e.cost!==null&&(r=P(e.cost,i.amount,i.warningThreshold||80).displayText),{icon:t.today_cost,cost:A(e.cost),label:`today`,budget:r}}function Ut(e,t,n){let r=Ht(e,t,n),i=`${r.icon} ${r.cost} ${r.label}`;return r.budget&&(i+=r.budget),i}function Wt(e,t){let n=N(e?.burnRate);return n?{icon:t.metrics_burn,rate:n}:{icon:``,rate:``}}function Gt(e,t){let n=Wt(e,t);return n.icon?`${n.icon} ${n.rate}`:``}function Kt(e,t){let n={response:``,responseIcon:``,responseVal:``,lastResponse:``,lastResponseIcon:``,lastResponseVal:``,added:``,addedIcon:``,addedVal:``,removed:``,removedIcon:``,removedVal:``};if(!e.metricsInfo)return n;let r=e.metricsInfo.responseTime!==null&&!isNaN(e.metricsInfo.responseTime)&&e.metricsInfo.responseTime>0,i=r?Ye(e.metricsInfo.responseTime):``,a=e.metricsInfo.lastResponseTime!==null&&!isNaN(e.metricsInfo.lastResponseTime)&&e.metricsInfo.lastResponseTime>0,o=a?Ye(e.metricsInfo.lastResponseTime):``,s=e.metricsInfo.linesAdded!==null&&e.metricsInfo.linesAdded>0,c=s?`${e.metricsInfo.linesAdded}`:``,l=e.metricsInfo.linesRemoved!==null&&e.metricsInfo.linesRemoved>0,u=l?`${e.metricsInfo.linesRemoved}`:``;return{response:r?`${t.metrics_response} ${i}`:``,responseIcon:r?t.metrics_response:``,responseVal:i,lastResponse:a?`${t.metrics_last_response} ${o}`:`${t.metrics_last_response} --`,lastResponseIcon:t.metrics_last_response,lastResponseVal:a?o:`--`,added:s?`${t.metrics_lines_added}${c}`:``,addedIcon:s?t.metrics_lines_added:``,addedVal:c,removed:l?`${t.metrics_lines_removed}${u}`:``,removedIcon:l?t.metrics_lines_removed:``,removedVal:u}}function qt(e,t){let n=Kt(e,t),r=[n.response,n.lastResponse,n.added,n.removed].filter(Boolean);return r.length>0?r.join(` · `):``}function Jt(e,t){let n={duration:``,durationIcon:``,durationVal:``,messages:``,messagesIcon:``,messagesVal:``};if(!e.metricsInfo)return n;let r=e.metricsInfo.sessionDuration!==null&&e.metricsInfo.sessionDuration>0,i=r?Ge(e.metricsInfo.sessionDuration):``,a=e.metricsInfo.messageCount!==null&&e.metricsInfo.messageCount>0,o=a?`${e.metricsInfo.messageCount}`:``;return{duration:r?`${t.metrics_duration} ${i}`:``,durationIcon:r?t.metrics_duration:``,durationVal:i,messages:a?`${t.metrics_messages} ${o}`:``,messagesIcon:a?t.metrics_messages:``,messagesVal:o}}function Yt(e,t){let n=Jt(e,t),r=[n.duration,n.messages].filter(Boolean);return r.length>0?r.join(` · `):``}function Xt(e,t){if(!e.gitInfo)return{icon:``,branch:``,status:``,ahead:``,behind:``,working:``};let n;n=e.gitInfo.status===`conflicts`?t.git_conflicts:e.gitInfo.status===`dirty`?t.git_dirty:t.git_clean;let r=e.gitInfo.ahead>0?`${t.git_ahead}${e.gitInfo.ahead}`:``,i=e.gitInfo.behind>0?`${t.git_behind}${e.gitInfo.behind}`:``,a=[];e.gitInfo.staged&&e.gitInfo.staged>0&&a.push(`+${e.gitInfo.staged}`),e.gitInfo.unstaged&&e.gitInfo.unstaged>0&&a.push(`~${e.gitInfo.unstaged}`),e.gitInfo.untracked&&e.gitInfo.untracked>0&&a.push(`?${e.gitInfo.untracked}`);let o=a.length>0?`(${a.join(` `)})`:``,s=[t.branch,e.gitInfo.branch,n];return r&&s.push(r),i&&s.push(i),{icon:t.branch,branch:e.gitInfo.branch,status:n,ahead:r,behind:i,working:o,head:s.join(` `)}}function Zt(e,t){let n=Xt(e,t);if(!n.icon)return``;let r=`${n.icon} ${n.branch} ${n.status}`;return n.ahead&&(r+=` ${n.ahead}`),n.behind&&(r+=`${n.behind}`),n.working&&(r+=` ${n.working}`),r}function Qt(e,t){return{value:$t(e,t)}}function $t(e,t){let n=Nt(e.hookData),r=t.display.lines.map(e=>e.segments.directory).find(e=>e?.enabled),i=r?.style??(r?.showBasename?`basename`:`fish`);if(i===`basename`){let e=n.includes(`/`)?`/`:`\\`;return n.split(e).pop()||n}return i===`full`?n:Je(n)}function en(e,t){return e.hookData.version?{icon:t.version,value:`v${e.hookData.version}`}:{icon:``,value:``}}function tn(e,t){let n=en(e,t);return n.icon?`${n.icon} ${n.value}`:``}function nn(e){return e.tmuxSessionId?{label:`tmux`,value:e.tmuxSessionId}:{label:``,value:``}}function rn(e){let t=nn(e);return t.label?`${t.label}:${t.value}`:``}function an(e){let t=e.display.lines.map(e=>e.segments.env).find(e=>e?.enabled);if(!t||!t.variable)return{prefix:``,value:``};let n=process.env[t.variable];return n?{prefix:(t.prefix??t.variable)||``,value:n}:{prefix:``,value:``}}function on(e){let t=an(e);return t.value?t.prefix?`${t.prefix}:${t.value}`:t.value:``}function J(e,t,n,r,i,a){for(let[o,s]of Object.entries(n)){let n=`${t}.${o}`,c=a?.[n]??a?.[t]??r;e[n]=s?R(s,c,i):``}}function sn(e,t,n){let r=t.indexOf(`.`),i=r===-1?t:t.slice(0,r);return e.items.map(e=>{let t=e.match(/^\{(.+)\}$/);return t?n[`${i}.${t[1]}`]??``:e?R(e,``,``):``}).filter(Boolean)}function cn(e,t,n,r){if(e.length===0)return``;if(n===`between`&&r!==void 0&&e.length>1){let n=e.reduce((e,t)=>e+L(t),0),i=Math.max(t*(e.length-1),r-n),a=Math.floor(i/(e.length-1)),o=i%(e.length-1),s=e[0];for(let t=1;t<e.length;t++)s+=` `.repeat(a+(t<=o?1:0))+e[t];return s}return e.join(` `.repeat(t))}function ln(e,t){let{sym:n,config:r,reset:i,colors:a}=t,o=a.partFg,s=(e,t)=>e?R(e,t,i):``,c={},l=qe(e.hookData.model?.display_name||`Claude`).toLowerCase(),u=o?.model??a.modelFg;if(c.model=s(`${n.model} ${l}`,u),J(c,`model`,{icon:n.model,value:l},a.modelFg,i,o),c.context=Mt(e,t.contentWidth,n,i,a)??``,J(c,`context`,Ot(e,n),e.contextInfo?G(e.contextInfo.usablePercentage,a.contextFg,a):a.contextFg,i,o),e.blockInfo){let t=o?.block??a.blockFg;c.block=s(K(e.blockInfo,n,r),t),J(c,`block`,Rt(e.blockInfo,n,r),a.blockFg,i,o)}else c.block=``;if(e.usageInfo){let t=o?.session??a.sessionFg;c.session=s(Vt(e.usageInfo,n,r),t),J(c,`session`,Bt(e.usageInfo,n,r),a.sessionFg,i,o)}else c.session=``;if(e.todayInfo){let t=o?.today??a.todayFg;c.today=s(Ut(e.todayInfo,n,r),t),J(c,`today`,Ht(e.todayInfo,n,r),a.todayFg,i,o)}else c.today=``;let d=e.hookData.rate_limits?.seven_day;if(d){let e=o?.weekly??a.weeklyFg;c.weekly=s(q(d,n),e),J(c,`weekly`,zt(d,n),a.weeklyFg,i,o)}else c.weekly=``;let f=o?.git??a.gitFg;c.git=s(Zt(e,n),f),J(c,`git`,Xt(e,n),a.gitFg,i,o);let p=o?.dir??a.modeFg;c.dir=s($t(e,r),p),J(c,`dir`,Qt(e,r),a.modeFg,i,o);let m=o?.version??a.versionFg;c.version=s(tn(e,n),m),J(c,`version`,en(e,n),a.versionFg,i,o);let h=o?.tmux??a.tmuxFg;c.tmux=s(rn(e),h),J(c,`tmux`,nn(e),a.tmuxFg,i,o);let g=o?.metrics??a.metricsFg;c.metrics=s(qt(e,n),g),J(c,`metrics`,Kt(e,n),a.metricsFg,i,o);let _=o?.activity??a.metricsFg;c.activity=s(Yt(e,n),_),J(c,`activity`,Jt(e,n),a.metricsFg,i,o);let v=o?.burn??a.metricsFg;c.burn=s(Gt(e.blockInfo,n),v),J(c,`burn`,Wt(e.blockInfo,n),a.metricsFg,i,o);let y=o?.env??a.envFg;c.env=s(on(r),y),J(c,`env`,an(r),a.envFg,i,o);let b={},x=r.display.tui?.segments;if(x)for(let[e,t]of Object.entries(x)){let n=sn(t,e,c),r=t.gap??1,i=t.justify??`start`;b[e]={items:n,gap:r,justify:i},c[e]=cn(n,r,i===`between`?`start`:i)}return{data:c,templates:b}}function un(e){let{lines:t,data:n,box:r,contentWidth:i,innerWidth:a,sym:o,config:s,reset:c,colors:l}=e,u=Pt(n,o,s,c,l);u.length>0&&t.push(V(r,Tt(u,i),a))}function dn(e){let{lines:t,data:n,box:r,contentWidth:i,innerWidth:a,sym:o,config:s,reset:c,colors:l}=e,u=It(n,o,c,l),d=Lt(n,o,s,c,l),f=u.join(` `),p=d.join(` · `);(f||p)&&(t.push(H(r,a)),t.push(V(r,U(f,p,i),a)))}function fn(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(R(K(n.blockInfo,o,s),l.blockFg,c));let f=n.hookData.rate_limits?.seven_day;f&&u.push(R(q(f,o),l.weeklyFg,c)),n.todayInfo&&u.push(R(Ut(n.todayInfo,o,s),l.todayFg,c)),n.usageInfo&&d.push(R(Vt(n.usageInfo,o,s),l.sessionFg,c));let p=Ft(n,o);p.length>0&&d.push(R(p.join(` · `),l.metricsFg,c)),u.length>0&&t.push(V(r,Tt(u,i),a)),d.length>0&&t.push(V(r,U(d[0]??``,d[1]??``,i),a))}function pn(e){let{lines:t,data:n,box:r,contentWidth:i,innerWidth:a,sym:o,config:s,reset:c,colors:l}=e,u=It(n,o,c,l);u.length>0&&(t.push(H(r,a)),t.push(V(r,U(u[0]??``,u[1]??``,i),a)));let d=Lt(n,o,s,c,l);d.length>0&&(t.push(H(r,a)),t.push(V(r,d.join(` · `),a)))}function mn(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(V(r,R(K(n.blockInfo,o,s),l.blockFg,c),a));let u=n.hookData.rate_limits?.seven_day;u&&t.push(V(r,R(q(u,o),l.weeklyFg,c),a));let d=[];n.usageInfo&&d.push(R(`${o.session_cost} ${A(n.usageInfo.session.cost)}`,l.sessionFg,c)),n.todayInfo&&d.push(R(`${o.today_cost} ${A(n.todayInfo.cost)} today`,l.todayFg,c)),d.length>0&&t.push(V(r,U(d[0]??``,d[1]??``,i),a))}function hn(e){let{lines:t,data:n,box:r,contentWidth:i,innerWidth:a,sym:o,config:s,reset:c,colors:l}=e,u=It(n,o,c,l);u.length>0&&(t.push(H(r,a)),t.push(V(r,U(u[0]??``,u[1]??``,i),a)));let d=Lt(n,o,s,c,l);d.length>0&&t.push(V(r,d.join(` · `),a))}const gn=new Set([`context`,`context.bar`,`block.bar`,`weekly.bar`]);function Y(e){return e.length===1&&e[0].segment===`---`}function X(e){if(!e.endsWith(`fr`))return 0;let t=parseInt(e.replace(`fr`,``),10);return!isNaN(t)&&t>0?t:0}function _n(e,t,n){let r=Math.floor(e/t.length),i=e-r*t.length;for(let e of t)n[e]=n[e]+r+(i>0?1:0),i>0&&i--}function Z(e,t,n,r){let i=0;for(let r=0;r<n;r++)i+=e[t+r]??0;return n>1&&(i+=(n-1)*r),i}function vn(e,t){let n;for(let r of e)t>=r.minWidth&&(!n||r.minWidth>n.minWidth)&&(n=r);if(n)return n;let r=e[0];for(let t=1;t<e.length;t++)e[t].minWidth<r.minWidth&&(r=e[t]);return r}function yn(e){let t=[];for(let n of e){let e=n.trim();if(e===`---`){t.push([{segment:`---`,spanStart:!0,spanSize:1}]);continue}let r=e.split(/\s+/),i=[],a=0;for(;a<r.length;){let e=r[a],t=1;for(;a+t<r.length&&r[a+t]===e;)t++;i.push({segment:e,spanStart:!0,spanSize:t});for(let n=1;n<t;n++)i.push({segment:e,spanStart:!1,spanSize:0});a+=t}t.push(i)}return t}function bn(e,t){let n=e.map(e=>Y(e)?e:e.map(e=>e.segment===`.`||e.segment===`---`||t[e.segment]?e:{segment:`.`,spanStart:!0,spanSize:1})).map(e=>{if(Y(e))return e;let t=e.map(e=>e.segment),n=[],r=0;for(;r<t.length;){let e=t[r],i=1;for(;r+i<t.length&&t[r+i]===e;)i++;n.push({segment:e,spanStart:!0,spanSize:i});for(let t=1;t<i;t++)n.push({segment:e,spanStart:!1,spanSize:0});r+=i}return n}).filter(e=>Y(e)?!0:e.some(e=>e.segment!==`.`)),r=[];for(let e=0;e<n.length;e++){let t=n[e];if(!Y(t)){r.push(t);continue}r.length!==0&&(Y(r[r.length-1])||r.push(t))}return r.length>0&&Y(r[r.length-1])&&r.pop(),r}function xn(e,t,n,r){let i=Array.from({length:e}).fill(0);for(let a of t)if(!Y(a))for(let t=0;t<a.length;t++){let o=a[t];if(!o.spanStart||o.spanSize!==1||o.segment===`.`||t>=e||r?.has(o.segment))continue;let s=L(n[o.segment]||``);s>i[t]&&(i[t]=s)}return i}function Sn(e,t,n,r,i,a){let o=e.length,s=xn(o,t,n,a),c=Array.from({length:o}).fill(0);for(let t=0;t<o;t++)e[t]===`auto`&&(c[t]=s[t]);for(let t=0;t<o;t++){let n=e[t];if(n===`auto`||n.endsWith(`fr`))continue;let r=parseInt(n,10);!isNaN(r)&&r>0&&(c[t]=r)}let l=Math.max(0,o-1)*i,u=c.reduce((e,t)=>e+t,0),d=Math.max(0,r-u-l),f=0;for(let t of e)f+=X(t);if(f>0){let t=d/f,n=[],r=0;for(let i=0;i<o;i++){let a=X(e[i]);if(a>0){let e=Math.floor(t*a);c[i]=e,r+=e,n.push(i)}}let i=d-r;for(let e=0;i>0&&e<n.length;e++)c[n[e]]+=1,i--}for(let e=0;e<o;e++)c[e]<1&&(c[e]=1);return c}function Cn(e,t,n,r,i,a){let o=e.length,s=xn(o,t,n,a),c=Array.from({length:o});for(let t=0;t<o;t++){let n=e[t];if(n!==`auto`&&!n.endsWith(`fr`)){let e=parseInt(n,10);c[t]=!isNaN(e)&&e>0?e:s[t]}else c[t]=s[t]}for(let i of t)if(!Y(i))for(let t=0;t<i.length;t++){let a=i[t];if(!a.spanStart||a.spanSize<=1||a.segment===`.`)continue;let o=L(n[a.segment]||``),s=Z(c,t,a.spanSize,r);if(o>s){let n=o-s,r=[];for(let n=0;n<a.spanSize;n++)X(e[t+n])>0&&r.push(t+n);if(r.length>0)_n(n,r,c);else{let e=[];for(let n=0;n<a.spanSize;n++)e.push(t+n);_n(n,e,c)}}}if(i>0){let t=0;for(let n of e)t+=X(n);if(t>0){let n=[],r=0;for(let a=0;a<o;a++){let o=X(e[a]);if(o>0){let e=Math.floor(i*o/t);c[a]=c[a]+e,r+=e,n.push(a)}}let a=i-r;for(let e=0;a>0&&e<n.length;e++)c[n[e]]+=1,a--}}for(let e=0;e<o;e++)c[e]<1&&(c[e]=1);let l=0;for(let e=0;e<o;e++)l+=c[e];let u=Math.max(0,o-1)*r;return{panelWidth:l+u+4,colWidths:c}}function wn(e,t,n){switch(n){case`right`:return St(e,t);case`center`:return Ct(e,t);default:return z(e,t)}}function Tn(e,t,n,r,i){let a=[],o=L(i);for(let i=0;i<e.length;i++){let s=e[i];if(!s.spanStart)continue;let c=Z(t,i,s.spanSize,o);if(s.segment===`.`)a.push(` `.repeat(c));else{let e=B(r[s.segment]||``,c),t=n[i]||`left`;a.push(wn(e,c,t))}}return a.join(i)}function En(e,t,n){let r=n||e.horizontal;return e.teeLeft+r.repeat(t)+e.teeRight}function Dn(e,t,n,r,i){let a=e.minWidth??32,o=e.maxWidth??1/0,s=e.separator?.column??` `,c=e.separator?.divider,l=L(s),u=e.fitContent??!1,d=e.padding?.horizontal??0,f;if(u)f=o===1/0?r:Math.min(r,o);else{let t=e.widthReserve??45;f=Math.min(o,Math.max(a,r-t))}let p=vn(e.breakpoints,f),m=bn(yn(p.areas),t);if(m.length===0)return{lines:[],panelWidth:f};let h,g=new Set(gn);if(e.segments)for(let t of Object.keys(e.segments))g.add(t);if(u){let e=Cn(p.columns,m,t,l,d,g);f=Math.min(o,Math.max(a,e.panelWidth)),h=e.colWidths;let n=f-e.panelWidth;if(n>0){let e=0;for(let t of p.columns)e+=X(t);if(e>0){let t=[],r=0;for(let i=0;i<h.length;i++){let a=X(p.columns[i]);if(a>0){let o=Math.floor(n*a/e);h[i]+=o,r+=o,t.push(i)}}let i=n-r;for(let e=0;i>0&&e<t.length;e++)h[t[e]]+=1,i--}}}else{let e=f-2-2;h=Sn(p.columns,m,t,e,l,g)}let _=f-2,v=_-2,y=p.align||p.columns.map(()=>`left`);if(i){let e=new Set;for(let n of m)if(!Y(n))for(let r=0;r<n.length;r++){let a=n[r];if(!a.spanStart||a.segment===`.`||a.segment===`---`||e.has(a.segment))continue;e.add(a.segment);let o=Z(h,r,a.spanSize,l),s=i(a.segment,o);s!==void 0&&(t[a.segment]=s)}}let b=bn(m,t);if(b.length===0)return{lines:[],panelWidth:f};let x=[];for(let e of b)if(Y(e))x.push(En(n,_,c));else{let r=z(B(Tn(e,h,y,t,s),v),v);x.push(n.vertical+` `+r+` `+n.vertical)}return{lines:x,panelWidth:f}}const On=`\x1B[?2026h`,kn=`\x1B[?2026l`,An=`\x1B[0m`;function jn(e){return e>=80?`wide`:e>=55?`medium`:`narrow`}function Mn(e){return e&&e>0?Math.max(32,e):80}async function Nn(e,t,n,r,i){let a=(i.display.charset||`unicode`)===`text`?ft:lt,o=e.colors;if(i.display.tui){let r=i.display.tui,s=r.terminalWidth??bt()??120,c;c=typeof r.box==`string`?I[r.box]??t:r.box?{...t,...r.box}:t;let l=Math.max(r.minWidth??32,s-(r.widthReserve??45))-2,u=l-2,d=ln(e,{lines:[],data:e,box:c,contentWidth:u,innerWidth:l,sym:a,config:i,reset:n,colors:o}),f=d.data,p=d.templates,m=o.partFg,h=Dn(r,f,c,s,(t,r)=>{if(t===`context`)return Mt(e,r,a,n,o)??``;if(t===`context.bar`)return kt(e,r,a,n,o,m);if(t===`block.bar`)return At(e,r,a,n,o,i,m);if(t===`weekly.bar`)return jt(e,r,a,n,o,m);let s=p[t];if(s)return cn(s.items,s.gap,s.justify,r)}),g=h.panelWidth-2,_=r.footer?.left?W(r.footer.left,e,f):void 0,v=r.footer?.right?W(r.footer.right,e,f):void 0,y=[];return y.push(Et(e,c,g,r.title,f)),y.push(...h.lines),y.push(wt(c,g,_,v)),On+y.map(e=>An+e).join(`
8
+ `)+kn}let s=Mn(r),c=s-2,l=c-2,u=jn(s),d=[];d.push(Et(e,t,c));let f=Mt(e,l,a,n,o);f&&d.push(V(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`?(un(p),dn(p)):u===`medium`?(fn(p),pn(p)):(mn(p),hn(p)),d.push(wt(t,c)),On+d.map(e=>An+e).join(`
9
+ `)+kn}var Pn=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 Be,this._usageProvider}get blockProvider(){return this._blockProvider||=new at,this._blockProvider}get todayProvider(){return this._todayProvider||=new ct,this._todayProvider}get contextProvider(){return this._contextProvider||=new Ve(this.config),this._contextProvider}get gitService(){return this._gitService||=new Ce,this._gitService}get tmuxService(){return this._tmuxService||=new Te,this._tmuxService}get metricsProvider(){return this._metricsProvider||=new He,this._metricsProvider}get segmentRenderer(){return this._segmentRenderer||=new nt(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(`
10
+ `)}async generateAutoWrapStatusline(e,t,n,r,i,a){let o=this.getThemeColors(),s=e.workspace?.current_dir||e.cwd||`/`,c=yt(),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(`
11
+ `)}async generateTuiStatusline(e){let t=this.getThemeColors(),n=yt(),r=e.workspace?.current_dir||e.cwd||`/`,i=(this.config.display.charset||`unicode`)===`text`?dt:ut,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 Nn({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=L(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,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`?ft:lt;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=T(e,r),t||=(console.warn(`Built-in theme '${e}' not found, falling back to 'dark' theme`),T(`dark`,r));let i=(e,t)=>r===`none`?``:r===`ansi`?ne(e,t):r===`ansi256`?te(e,t):ee(e,t),a=T(`dark`,r),o=this.config.display.style===`tui`,s=e===`light`?`#f0f0f0`:`#1e1e1e`,c=e=>{let n=a[e],r=t[e],c={fg:r?.fg||n.fg,bg:r?.bg||n.bg},l=c.fg;return o&&re(l,s)<60&&(l=c.bg),{bg:i(c.bg,!0),fg:i(l,!1)}},l=c(`directory`),u=c(`git`),d=c(`model`),f=c(`session`),p=c(`block`),m=c(`today`),h=c(`tmux`),g=c(`context`),_=c(`contextWarning`),v=c(`contextCritical`),y=c(`metrics`),b=c(`version`),x=c(`env`),S=c(`weekly`);return{reset:r===`none`?``:`\x1B[0m`,modeBg:l.bg,modeFg:l.fg,gitBg:u.bg,gitFg:u.fg,modelBg:d.bg,modelFg:d.fg,sessionBg:f.bg,sessionFg:f.fg,blockBg:p.bg,blockFg:p.fg,todayBg:m.bg,todayFg:m.fg,tmuxBg:h.bg,tmuxFg:h.fg,contextBg:g.bg,contextFg:g.fg,contextWarningBg:_.bg,contextWarningFg:_.fg,contextCriticalBg:v.bg,contextCriticalFg:v.fg,metricsBg:y.bg,metricsFg:y.fg,versionBg:b.bg,versionFg:b.fg,envBg:x.bg,envFg:x.fg,weeklyBg:S.bg,weeklyFg:S.fg,partFg:this.resolvePartColors(i)}}resolvePartColors(e){let t=this.config.colors?.custom;if(!t)return{};let n={};for(let r of Object.keys(t)){let i=t[r];i?.fg&&(n[r]=e(i.fg,!1))}return n}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 Fn={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}},In=new Set([`context`,`block`,`session`,`today`,`weekly`,`git`,`dir`,`model`,`version`,`tmux`,`metrics`,`activity`,`burn`,`env`]),Ln={session:[`icon`,`cost`,`tokens`,`budget`],block:[`icon`,`value`,`time`,`budget`,`bar`],today:[`icon`,`cost`,`label`,`budget`],weekly:[`icon`,`pct`,`time`,`bar`],git:[`icon`,`branch`,`status`,`ahead`,`behind`,`working`,`head`],context:[`icon`,`bar`,`pct`,`tokens`],metrics:[`response`,`responseIcon`,`responseVal`,`lastResponse`,`lastResponseIcon`,`lastResponseVal`,`added`,`addedIcon`,`addedVal`,`removed`,`removedIcon`,`removedVal`],activity:[`duration`,`durationIcon`,`durationVal`,`messages`,`messagesIcon`,`messagesVal`],model:[`icon`,`value`],burn:[`icon`,`rate`],version:[`icon`,`value`],tmux:[`label`,`value`],dir:[`value`],env:[`prefix`,`value`]};function Rn(e){if(e===`.`||e===`---`||In.has(e))return!0;let t=e.indexOf(`.`);if(t===-1)return!1;let n=e.slice(0,t),r=e.slice(t+1);if(!n||!r)return!1;let i=Ln[n];return i?i.includes(r):!1}function zn(e){return[`light`,`dark`,`nord`,`tokyo-night`,`rose-pine`,`gruvbox`,`custom`].includes(e)}function Bn(e){return e===`minimal`||e===`powerline`||e===`capsule`||e===`tui`}function Vn(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 Hn(e,t){return e?o.existsSync(e)?e:null:[...t?[l.join(t,`.claude-powerline.json`)]:[],l.join(process.cwd(),`.claude-powerline.json`),l.join(m.homedir(),`.claude`,`claude-powerline.json`),l.join(m.homedir(),`.config`,`claude-powerline`,`config.json`)].find(o.existsSync)||null}function Un(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 Wn(){let e={},t={},n=process.env.CLAUDE_POWERLINE_THEME;n&&zn(n)&&(e.theme=n);let r=process.env.CLAUDE_POWERLINE_STYLE;return r&&(Bn(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 Gn(){return process.env.CLAUDE_POWERLINE_CONFIG}function Kn(e){let t={},n={},r=Q(e,`--theme`);r&&zn(r)&&(t.theme=r);let i=Q(e,`--style`);i&&(Bn(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&&(Vn(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 qn(e){if(typeof e.box==`string`&&!I[e.box]){let t=Object.keys(I).join(`, `);return`unknown box preset "${e.box}" (valid: ${t})`}if(!e.breakpoints||!Array.isArray(e.breakpoints)||e.breakpoints.length===0)return`grid config must have at least one breakpoint`;let t=new Set;for(let n=0;n<e.breakpoints.length;n++){let r=e.breakpoints[n],i=`breakpoint[${n}]`;if(typeof r.minWidth!=`number`||r.minWidth<0)return`${i}: minWidth must be a non-negative number`;if(t.has(r.minWidth))return`${i}: duplicate minWidth ${r.minWidth} (each breakpoint must have a unique minWidth)`;if(t.add(r.minWidth),!r.areas||!Array.isArray(r.areas)||r.areas.length===0)return`${i}: areas must be a non-empty array of strings`;if(!r.columns||!Array.isArray(r.columns)||r.columns.length===0)return`${i}: columns must be a non-empty array`;let a=r.columns.length;for(let e of r.columns){if(typeof e!=`string`)return`${i}: column definition must be a string`;if(!/^(\d+fr|\d+|auto)$/.test(e))return`${i}: invalid column definition "${e}" (use "auto", "Nfr", or a fixed integer)`}if(r.align!==void 0){if(!Array.isArray(r.align))return`${i}: align must be an array`;if(r.align.length!==a)return`${i}: align length (${r.align.length}) must match columns length (${a})`;for(let e of r.align)if(e!==`left`&&e!==`center`&&e!==`right`)return`${i}: invalid align value "${e}"`}let o=new Set;for(let t=0;t<r.areas.length;t++){let n=r.areas[t];if(n.trim()===`---`)continue;let s=n.trim().split(/\s+/);if(s.length!==a)return`${i}: row "${n}" has ${s.length} cells but expected ${a} columns`;let c=e.segments?new Set(Object.keys(e.segments)):new Set,l=``,u=``;for(let e of s){if(e!==`.`){if(!Rn(e)&&!c.has(e))return`${i}: unknown segment name "${e}"`;if(e!==u&&o.has(e))return`${i}: segment "${e}" appears on multiple rows`}e!==l&&(u=e),l=e}let d=new Map;for(let e=0;e<s.length;e++){let t=s[e];if(t===`.`||t===`---`)continue;let r=d.get(t);if(r!==void 0&&r!==e-1)return`${i}: segment "${t}" has non-contiguous span in row "${n}"`;d.set(t,e)}for(let e of s)e!==`.`&&e!==`---`&&o.add(e)}}if(e.segments)for(let[t,n]of Object.entries(e.segments)){if(!n.items||!Array.isArray(n.items))return`segments["${t}"]: items must be an array`;if(n.justify!==void 0&&n.justify!==`start`&&n.justify!==`between`)return`segments["${t}"]: invalid justify value "${n.justify}" (use "start" or "between")`}return null}function Jn(e=process.argv,t){let n=JSON.parse(JSON.stringify(Fn)),r=Q(e,`--config`)||Gn(),i=Hn(r?.startsWith(`~`)?r.replace(`~`,m.homedir()):r,t);if(i)try{let e=Un(i);n=$(n,e)}catch(e){console.warn(`Warning: ${e instanceof Error?e.message:String(e)}`)}n.display?.style&&!Bn(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&&!Vn(n.display.charset)&&(console.warn(`Invalid charset '${n.display.charset}' in config file, falling back to 'unicode'`),n.display.charset=`unicode`),n.theme&&!zn(n.theme)&&(console.warn(`Invalid theme '${n.theme}' in config file, falling back to 'dark'`),n.theme=`dark`);let a=Wn();n=$(n,a);let o=Kn(e);if(n=$(n,o),n.display?.tui){let e=qn(n.display.tui);e&&(process.stderr.write(`Warning: invalid grid config: ${e}. Falling back to hardcoded layout.\n`),delete n.display.tui)}return n}const Yn=Jn;function Xn(){console.log(`
11
12
  claude-powerline - Beautiful powerline statusline for Claude Code
12
13
 
13
14
  Usage: claude-powerline [options]
@@ -26,7 +27,7 @@ Claude Code Options (for settings.json):
26
27
 
27
28
  See example config at: https://github.com/Owloops/claude-powerline/blob/main/.claude-powerline.json
28
29
 
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
+ `)}async function Zn(){try{(e.argv.includes(`--help`)||e.argv.includes(`-h`))&&(Xn(),e.exit(0)),e.stdin.isTTY===!0&&(console.error(`Error: This tool requires input from Claude Code
30
31
 
31
32
  claude-powerline is designed to be used as a Claude Code statusLine command.
32
33
  It reads hook data from stdin and outputs formatted statusline.
@@ -42,4 +43,4 @@ Add to ~/.claude/settings.json:
42
43
  Run with --help for more options.
43
44
 
44
45
  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)),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{};
46
+ 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)),E(`Working directory: ${e.cwd()}`),E(`Process args:`,e.argv);let n=await t(e.stdin);E(`Received hook data:`,JSON.stringify(n,null,2)),n||(console.error(`Error: No input data received from stdin`),Xn(),e.exit(1));let r=n.workspace?.project_dir,i=await new Pn(Yn(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)}}Zn();export{};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@owloops/claude-powerline",
3
- "version": "1.23.5",
3
+ "version": "1.24.1",
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",
@@ -6,7 +6,50 @@ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
6
6
  readonly SCRIPT_DIR
7
7
  readonly PLUGIN_ROOT="${SCRIPT_DIR}/.."
8
8
 
9
- readonly SAMPLE_JSON='{"model":{"id":"claude-sonnet-4-20250514","display_name":"Sonnet 4"},"cost":{"total_cost_usd":0.42,"message_cost_usd":0.03,"duration":"15m"},"context_window":{"context_window_size":200000,"used_percentage":35,"current_usage":{"input_tokens":50000,"cache_creation_input_tokens":10000,"cache_read_input_tokens":5000}},"cwd":"/home/user/my-project","workspace":{"current_dir":"/home/user/my-project"},"session":{"session_id":"abc123"}}'
9
+ readonly SAMPLE_JSON='{"model":{"id":"claude-sonnet-4-20250514","display_name":"Sonnet 4"},"cost":{"total_cost_usd":0.42,"message_cost_usd":0.03,"duration":"15m"},"context_window":{"context_window_size":200000,"used_percentage":35,"current_usage":{"input_tokens":50000,"cache_creation_input_tokens":10000,"cache_read_input_tokens":5000}},"cwd":"/home/user/my-project","workspace":{"current_dir":"/home/user/my-project"},"session_id":"abc123"}'
10
+
11
+ setup_tui_transcript() {
12
+ local now_iso user_iso cwd_encoded transcript_dir
13
+ now_iso=$(date -u +"%Y-%m-%dT%H:%M:%S.000Z")
14
+ user_iso=$(date -u -d "-13 seconds" +"%Y-%m-%dT%H:%M:%S.000Z" 2>/dev/null \
15
+ || date -u -v-13S +"%Y-%m-%dT%H:%M:%S.000Z" 2>/dev/null \
16
+ || echo "${now_iso}")
17
+
18
+ # Encode the preview CWD the same way Claude Code encodes project dirs
19
+ # On Windows: C:\Users\foo\proj -> C--Users-foo-proj
20
+ # On Unix: /home/user/proj -> -home-user-proj
21
+ local preview_cwd
22
+ # Create a temp git repo so previews always show git data
23
+ local fake_repo
24
+ fake_repo="$(mktemp -d)/my-project"
25
+ mkdir -p "${fake_repo}"
26
+ git -C "${fake_repo}" init -b main --quiet 2>/dev/null
27
+ git -C "${fake_repo}" -c user.name="User" -c user.email="u@e.co" commit --allow-empty -m "init" --quiet 2>/dev/null
28
+ git -C "${fake_repo}" checkout -b feat/my-feature --quiet 2>/dev/null
29
+ touch "${fake_repo}/newfile.txt"
30
+ printf 'change\n' > "${fake_repo}/README.md"
31
+ git -C "${fake_repo}" add README.md 2>/dev/null
32
+
33
+ # Use native path for Node.js compatibility (Windows needs C:\... not /c/...)
34
+ preview_cwd="$(cd "${fake_repo}" && pwd -W 2>/dev/null || pwd)"
35
+ cwd_encoded="$(printf '%s' "${preview_cwd}" | sed 's|[/\\]|-|g; s|:||g')"
36
+ TUI_PREVIEW_CWD="${preview_cwd}"
37
+
38
+ transcript_dir="${HOME}/.claude/projects/${cwd_encoded}"
39
+ TUI_TRANSCRIPT="${transcript_dir}/preview-123.jsonl"
40
+ mkdir -p "${transcript_dir}"
41
+ printf '{"timestamp":"%s","type":"user","message":{"role":"user","content":[{"type":"text","text":"hello"}]}}\n' "${user_iso}" > "${TUI_TRANSCRIPT}"
42
+ printf '{"timestamp":"%s","type":"assistant","message":{"role":"assistant","content":[{"type":"text","text":"done"}]}}\n' "${now_iso}" >> "${TUI_TRANSCRIPT}"
43
+ }
44
+
45
+ make_tui_sample_json() {
46
+ local resets_5h resets_7d
47
+ resets_5h=$(( $(date +%s) + 15480 ))
48
+ resets_7d=$(( $(date +%s) + 432000 ))
49
+
50
+ printf '{"model":{"id":"claude-sonnet-4-20250514","display_name":"Sonnet 4"},"cost":{"total_cost_usd":2.85,"message_cost_usd":0.12,"total_duration_ms":16200000,"total_api_duration_ms":480000,"total_lines_added":342,"total_lines_removed":87},"context_window":{"context_window_size":200000,"used_percentage":42,"total_input_tokens":72000,"total_output_tokens":12000,"current_usage":{"input_tokens":72000,"output_tokens":12000,"cache_creation_input_tokens":15000,"cache_read_input_tokens":8000}},"rate_limits":{"five_hour":{"used_percentage":35,"resets_at":%d},"seven_day":{"used_percentage":28,"resets_at":%d}},"cwd":"%s","workspace":{"current_dir":"%s","project_dir":"%s"},"session_id":"preview-123","version":"1.0.47"}' \
51
+ "${resets_5h}" "${resets_7d}" "${TUI_PREVIEW_CWD}" "${TUI_PREVIEW_CWD}" "${TUI_PREVIEW_CWD}"
52
+ }
10
53
 
11
54
  readonly PREVIEW_CONFIG='{
12
55
  "theme": "dark",
@@ -40,6 +83,7 @@ STYLE="minimal"
40
83
  CHARSET="unicode"
41
84
  COMPARE_STYLES=false
42
85
  COMPARE_THEMES=false
86
+ COMPARE_TUI_LAYOUTS=false
43
87
  BIN=""
44
88
  TEMP_FILES=()
45
89
 
@@ -58,7 +102,8 @@ test_binary() {
58
102
 
59
103
  find_binary() {
60
104
  local npm_bin="${PLUGIN_ROOT}/../bin/claude-powerline"
61
- if [[ -f "${npm_bin}" ]] && test_binary "${npm_bin}"; then
105
+ local dist_file="${PLUGIN_ROOT}/../dist/index.mjs"
106
+ if [[ -f "${npm_bin}" ]] && [[ -f "${dist_file}" ]] && test_binary "${npm_bin}"; then
62
107
  printf '%s' "${npm_bin}"
63
108
  return 0
64
109
  fi
@@ -98,14 +143,60 @@ run_preview() {
98
143
  tmp_config="$(make_temp_config "${preview_theme}" "${preview_style}" "${preview_charset}")"
99
144
 
100
145
  if [[ "${BIN}" == "npx" ]]; then
101
- printf '%s' "${SAMPLE_JSON}" | npx -y @owloops/claude-powerline@latest \
146
+ printf '%s' "${SAMPLE_JSON}" | FORCE_COLOR=3 npx -y @owloops/claude-powerline@latest \
102
147
  --config="${tmp_config}"
103
148
  else
104
- printf '%s' "${SAMPLE_JSON}" | "${BIN}" \
149
+ printf '%s' "${SAMPLE_JSON}" | FORCE_COLOR=3 "${BIN}" \
105
150
  --config="${tmp_config}"
106
151
  fi
107
152
  }
108
153
 
154
+ run_preview_config() {
155
+ local config_file="$1"
156
+ local sample_data="$2"
157
+
158
+ if [[ "${BIN}" == "npx" ]]; then
159
+ printf '%s' "${sample_data}" | FORCE_COLOR=3 npx -y @owloops/claude-powerline@latest \
160
+ --config="${config_file}"
161
+ else
162
+ printf '%s' "${sample_data}" | FORCE_COLOR=3 "${BIN}" \
163
+ --config="${config_file}"
164
+ fi
165
+ }
166
+
167
+ run_compare_tui_layouts() {
168
+ local layouts=(compact standard full)
169
+ local label
170
+ local template_file tmp tui_json fake_repo
171
+
172
+ setup_tui_transcript
173
+ tui_json="$(make_tui_sample_json)"
174
+ fake_repo="${TUI_PREVIEW_CWD}"
175
+
176
+ for label in "${layouts[@]}"; do
177
+ template_file="${PLUGIN_ROOT}/templates/config-tui-${label}.json"
178
+ if [[ ! -f "${template_file}" ]]; then
179
+ printf '%s: template not found\n\n' "${label}"
180
+ continue
181
+ fi
182
+
183
+ tmp="$(mktemp)"
184
+ TEMP_FILES+=("${tmp}")
185
+ sed -e "s/replace:THEME/${THEME}/g" \
186
+ -e "s/replace:CHARSET/${CHARSET}/g" \
187
+ -e "s/\"replace:TODAY_BUDGET\"/50/g" \
188
+ "${template_file}" >"${tmp}"
189
+
190
+ printf '%s:\n' "${label}"
191
+ run_preview_config "${tmp}" "${tui_json}"
192
+ printf '\n\n'
193
+ done
194
+
195
+ # Clean up fake transcript and git repo
196
+ rm -f "${TUI_TRANSCRIPT}" 2>/dev/null
197
+ rm -rf "${fake_repo%/my-project}" 2>/dev/null
198
+ }
199
+
109
200
  run_compare_styles() {
110
201
  local styles=(minimal powerline capsule tui)
111
202
  local s
@@ -175,6 +266,10 @@ parse_args() {
175
266
  COMPARE_THEMES=true
176
267
  shift
177
268
  ;;
269
+ --compare-tui-layouts)
270
+ COMPARE_TUI_LAYOUTS=true
271
+ shift
272
+ ;;
178
273
  *)
179
274
  printf 'Unknown option: %s\n' "$1" >&2
180
275
  exit 1
@@ -197,6 +292,11 @@ main() {
197
292
  exit 0
198
293
  fi
199
294
 
295
+ if [[ "${COMPARE_TUI_LAYOUTS}" == "true" ]]; then
296
+ run_compare_tui_layouts
297
+ exit 0
298
+ fi
299
+
200
300
  run_preview "${THEME}" "${STYLE}" "${CHARSET}"
201
301
  printf '\n'
202
302
  exit 0
@@ -152,7 +152,57 @@ Then ask:
152
152
 
153
153
  If the user chose `charset=text`, add a note that powerline and capsule use text fallback separators.
154
154
 
155
- **If the user chose "tui":** skip Steps 5 and 6. TUI mode is opinionated and always displays all data regardless of segment configuration. Tell the user: "TUI mode shows all available data automatically. Segment and bar style selection are not needed." Then continue to Step 7.
155
+ **If the user chose "tui":** skip Steps 5 and 6 and continue to Step 4b for TUI layout selection.
156
+
157
+ ## Step 4b: TUI Layout Selection
158
+
159
+ > [!NOTE]
160
+ > This step only applies if the user chose "tui" style in Step 4. Otherwise skip to Step 5.
161
+
162
+ Show a preview of all three TUI layouts using the bundled preview script.
163
+
164
+ > [!IMPORTANT]
165
+ > You MUST run the preview command below and let the terminal display the result.
166
+ > After running, tell the user to expand the bash output if they cannot see the previews.
167
+
168
+ ```bash
169
+ ${CLAUDE_PLUGIN_ROOT}/bin/preview.sh --compare-tui-layouts --theme=${chosen_theme} --charset=${charset}
170
+ ```
171
+
172
+ After running the command, tell the user: "The three TUI layout previews are in the bash output above. Expand it if needed."
173
+
174
+ Display the three TUI layout presets:
175
+
176
+ ````markdown
177
+ **Choose a TUI layout:**
178
+
179
+ 1. **Compact** — Git + context window only
180
+ Minimal footprint. Model name in the title bar. Clean and focused.
181
+
182
+ 2. **Standard** — Git + context + block usage with progress bars
183
+ Model and directory in the title bar. Good default for most users.
184
+
185
+ 3. **Full** — Git, context, block, session, and daily cost
186
+ Title bar with model and directory. Footer with weekly usage and response time.
187
+ Maximum information density.
188
+ ````
189
+
190
+ Then ask:
191
+
192
+ - **Question**: "Which TUI layout?"
193
+ - **Header**: "TUI Layout"
194
+ - **Options**:
195
+ - "Compact" -> Set `chosen_tui_layout=compact`
196
+ - "Standard" -> Set `chosen_tui_layout=standard`
197
+ - "Full" -> Set `chosen_tui_layout=full`
198
+
199
+ After selection, skip Steps 5 and 6 (always skipped for TUI). If "Compact" or "Standard", also skip Step 7 (no budget needed). If "Full", continue to Step 7.
200
+
201
+ ### TUI preset to template mapping
202
+
203
+ - `compact` -> `config-tui-compact.json`
204
+ - `standard` -> `config-tui-standard.json`
205
+ - `full` -> `config-tui-full.json`
156
206
 
157
207
  ## Step 5: Segment Selection
158
208
 
@@ -190,7 +240,8 @@ Each preset has a corresponding template config file in `${CLAUDE_PLUGIN_ROOT}/t
190
240
  - `essential` -> `config-essential.json`
191
241
  - `standard` -> `config-standard.json`
192
242
  - `full` -> `config-full.json`
193
- - `tui` (style) -> `config-tui.json`
243
+
244
+ For TUI templates, see Step 4b.
194
245
 
195
246
  ## Step 6: Bar Display Style
196
247
 
@@ -227,7 +278,7 @@ Apply `chosen_bar_style` to the `displayStyle` field of context, block, and week
227
278
  ## Step 7: Budget
228
279
 
229
280
  > [!NOTE]
230
- > Skip this step if the user chose "Essential" preset or "tui" style. The essential template has no budget placeholder, and TUI uses defaults.
281
+ > Skip this step if the user chose "Essential" preset, or TUI "Compact" or "Standard" layout. Only TUI "Full" layout uses a budget placeholder.
231
282
 
232
283
  Ask the user about their daily budget for cost tracking:
233
284
 
@@ -258,7 +309,9 @@ If it exists, ask:
258
309
 
259
310
  ### Build and write the config
260
311
 
261
- 1. **Pick the template file.** If the user chose "tui" style, use `config-tui.json`. Otherwise use the preset template: `config-essential.json`, `config-standard.json`, or `config-full.json`.
312
+ 1. **Pick the template file.** Based on the user's choices:
313
+ - Non-TUI styles: `config-essential.json`, `config-standard.json`, or `config-full.json` (from Step 5)
314
+ - TUI style: `config-tui-compact.json`, `config-tui-standard.json`, or `config-tui-full.json` (from Step 4b)
262
315
 
263
316
  2. **Read the template** using the Read tool:
264
317
 
@@ -271,12 +324,12 @@ ${CLAUDE_PLUGIN_ROOT}/templates/<template-file>
271
324
  | Placeholder | Replace with |
272
325
  |-------------|-------------|
273
326
  | `replace:THEME` | The chosen theme (e.g., `tokyo-night`) |
274
- | `replace:STYLE` | The chosen style (e.g., `capsule`). Not present in tui template. |
327
+ | `replace:STYLE` | The chosen style (e.g., `capsule`). Not present in TUI templates. |
275
328
  | `replace:CHARSET` | `unicode` or `text` |
276
- | `replace:BAR_STYLE` | The chosen bar style (e.g., `blocks`). Default `text` if Step 6 was skipped. Not present in tui template. |
277
- | `replace:TODAY_BUDGET` | The budget number (e.g., `50`). Not present in essential template. **Important:** replace `"replace:TODAY_BUDGET"` (including the surrounding quotes) with the bare number so the result is `"amount": 50` not `"amount": "50"`. |
329
+ | `replace:BAR_STYLE` | The chosen bar style (e.g., `blocks`). Default `text` if Step 6 was skipped. Not present in TUI templates. |
330
+ | `replace:TODAY_BUDGET` | The budget number (e.g., `50`). Only present in non-TUI standard/full and TUI full templates. **Important:** replace `"replace:TODAY_BUDGET"` (including the surrounding quotes) with the bare number so the result is `"amount": 50` not `"amount": "50"`. |
278
331
 
279
- 1. **Handle "No budget"**: If the user chose "No budget" in Step 7, remove the entire `"amount": "replace:TODAY_BUDGET",` line (including the trailing comma) from the budget section. If Step 7 was skipped (essential preset), do not modify the budget section.
332
+ 1. **Handle "No budget"**: If the user chose "No budget" in Step 7, remove the entire `"amount": "replace:TODAY_BUDGET",` line (including the trailing comma) from the budget section. If Step 7 was skipped (essential preset, or TUI compact/standard), do not modify the budget section.
280
333
 
281
334
  1. **Write the result** to `~/.claude/claude-powerline.json` using the Write tool. Do NOT read or merge with any existing config.
282
335
 
@@ -331,3 +384,20 @@ Setup complete.
331
384
 
332
385
  Documentation: https://github.com/Owloops/claude-powerline
333
386
  ````
387
+
388
+ **If the user chose TUI style**, also display:
389
+
390
+ ````markdown
391
+ **Customizing your TUI grid layout:**
392
+
393
+ Edit `display.tui` in `~/.claude/claude-powerline.json` to fine-tune:
394
+
395
+ - **Box style** — Add `"box": "rounded"` to change borders. Presets: `rounded`, `square`, `heavy`, `double`, `dashed`, `heavy-dashed`, `mixed`, `ascii`, `invisible`
396
+ - **Title/footer** — Edit `title.left`, `title.right`, `footer.left`, `footer.right` using `{segment.part}` tokens (e.g. `{model.icon}`, `{dir}`, `{weekly.pct}`)
397
+ - **Grid areas** — Rearrange cells in `breakpoints[].areas`. Use `.` for empty cells, `---` for dividers. Repeat a name across adjacent cells to span columns
398
+ - **Custom colors** — Add `colors.custom` entries with dot-notation keys (e.g. `"context.bar": { "fg": "#4a9eff" }`)
399
+ - **Responsive breakpoints** — Add breakpoints for different terminal widths. The engine picks the largest `minWidth` that fits
400
+ - **Column sizing** — `"auto"` (fit content), `"1fr"` (fill remaining), or a fixed number like `"20"`
401
+
402
+ See the TUI Grid Layout section in the README for the full reference.
403
+ ````
@@ -0,0 +1,59 @@
1
+ {
2
+ "theme": "replace:THEME",
3
+ "display": {
4
+ "style": "tui",
5
+ "charset": "replace:CHARSET",
6
+ "colorCompatibility": "auto",
7
+ "autoWrap": true,
8
+ "tui": {
9
+ "fitContent": true,
10
+ "minWidth": 50,
11
+ "padding": { "horizontal": 2 },
12
+ "separator": { "column": " " },
13
+ "title": {
14
+ "left": "{model}",
15
+ "right": "{dir}"
16
+ },
17
+ "breakpoints": [
18
+ {
19
+ "minWidth": 0,
20
+ "areas": [
21
+ "git.icon git.head . git.working",
22
+ "---",
23
+ "context.icon context.bar context.pct context.tokens"
24
+ ],
25
+ "columns": ["auto", "1fr", "auto", "auto"],
26
+ "align": ["left", "left", "right", "right"]
27
+ }
28
+ ]
29
+ },
30
+ "lines": [
31
+ {
32
+ "segments": {
33
+ "directory": { "enabled": true, "showBasename": true },
34
+ "git": { "enabled": true },
35
+ "model": { "enabled": true },
36
+ "context": { "enabled": true, "autocompactBuffer": 0 }
37
+ }
38
+ }
39
+ ]
40
+ },
41
+ "colors": {
42
+ "custom": {
43
+ "model": { "fg": "#e0d68a" },
44
+ "dir": { "fg": "#d2e08a" },
45
+ "git": { "fg": "#c3e88d" },
46
+ "git.working": { "fg": "#90c499" },
47
+ "context": { "fg": "#7ecbc8" },
48
+ "context.pct": { "fg": "#71b7b4" },
49
+ "context.tokens": { "fg": "#71b7b4" }
50
+ }
51
+ },
52
+ "budget": {
53
+ "session": { "warningThreshold": 80 }
54
+ },
55
+ "modelContextLimits": {
56
+ "sonnet": 1000000,
57
+ "opus": 200000
58
+ }
59
+ }
@@ -0,0 +1,110 @@
1
+ {
2
+ "theme": "replace:THEME",
3
+ "display": {
4
+ "style": "tui",
5
+ "charset": "replace:CHARSET",
6
+ "colorCompatibility": "auto",
7
+ "autoWrap": true,
8
+ "tui": {
9
+ "fitContent": true,
10
+ "minWidth": 60,
11
+ "padding": { "horizontal": 2 },
12
+ "separator": { "column": " " },
13
+ "title": {
14
+ "left": "{model.icon} {model.value}",
15
+ "right": "{dir}"
16
+ },
17
+ "footer": {
18
+ "left": "{activity.durationIcon} {activity.durationVal} {activity.messagesIcon} {activity.messagesVal}",
19
+ "right": "{metrics.lastResponse}"
20
+ },
21
+ "segments": {
22
+ "git.info": {
23
+ "items": ["{branch}", "{status}", "{ahead}", "{behind}"],
24
+ "gap": 1
25
+ }
26
+ },
27
+ "breakpoints": [
28
+ {
29
+ "minWidth": 55,
30
+ "areas": [
31
+ "git.icon git.info git.info . git.working",
32
+ "---",
33
+ "context.icon context.bar context.bar context.pct context.tokens",
34
+ "block.icon block.bar block.bar block.value block.time",
35
+ "weekly.icon weekly.bar weekly.bar weekly.pct weekly.time",
36
+ "---",
37
+ "session session . today today"
38
+ ],
39
+ "columns": ["auto", "1fr", "auto", "auto", "auto"],
40
+ "align": ["left", "left", "right", "right", "right"]
41
+ },
42
+ {
43
+ "minWidth": 0,
44
+ "areas": [
45
+ "git.head",
46
+ "git.working",
47
+ "---",
48
+ "context",
49
+ "block",
50
+ "---",
51
+ "session",
52
+ "today"
53
+ ],
54
+ "columns": ["1fr"],
55
+ "align": ["left"]
56
+ }
57
+ ]
58
+ },
59
+ "lines": [
60
+ {
61
+ "segments": {
62
+ "directory": { "enabled": true, "style": "fish" },
63
+ "git": { "enabled": true, "showAheadBehind": true },
64
+ "model": { "enabled": true },
65
+ "context": { "enabled": true, "autocompactBuffer": 0 },
66
+ "block": { "enabled": true, "type": "tokens" },
67
+ "session": { "enabled": true, "type": "tokens" },
68
+ "today": { "enabled": true, "type": "cost" },
69
+ "weekly": { "enabled": true },
70
+ "metrics": {
71
+ "enabled": true,
72
+ "showLastResponseTime": true,
73
+ "showResponseTime": false,
74
+ "showDuration": true,
75
+ "showMessageCount": true
76
+ }
77
+ }
78
+ }
79
+ ]
80
+ },
81
+ "colors": {
82
+ "custom": {
83
+ "model": { "fg": "#e0d68a" },
84
+ "dir": { "fg": "#d2e08a" },
85
+ "git": { "fg": "#c3e88d" },
86
+ "git.working": { "fg": "#90c499" },
87
+ "context": { "fg": "#7ecbc8" },
88
+ "context.pct": { "fg": "#71b8cd" },
89
+ "context.tokens": { "fg": "#71b8cd" },
90
+ "block": { "fg": "#7dcfff" },
91
+ "block.value": { "fg": "#6fa6e2" },
92
+ "block.time": { "fg": "#6fa6e2" },
93
+ "weekly": { "fg": "#7aa2f7" },
94
+ "weekly.pct": { "fg": "#8b8ede" },
95
+ "weekly.time": { "fg": "#8b8ede" },
96
+ "session": { "fg": "#bb9af7" },
97
+ "today": { "fg": "#aaa0dd" },
98
+ "activity": { "fg": "#c0caf5" },
99
+ "metrics.lastResponse": { "fg": "#c0caf5" }
100
+ }
101
+ },
102
+ "budget": {
103
+ "session": { "warningThreshold": 80 },
104
+ "today": { "amount": "replace:TODAY_BUDGET", "warningThreshold": 80 }
105
+ },
106
+ "modelContextLimits": {
107
+ "sonnet": 1000000,
108
+ "opus": 200000
109
+ }
110
+ }
@@ -0,0 +1,70 @@
1
+ {
2
+ "theme": "replace:THEME",
3
+ "display": {
4
+ "style": "tui",
5
+ "charset": "replace:CHARSET",
6
+ "colorCompatibility": "auto",
7
+ "autoWrap": true,
8
+ "tui": {
9
+ "fitContent": true,
10
+ "minWidth": 55,
11
+ "padding": { "horizontal": 2 },
12
+ "separator": { "column": " " },
13
+ "title": {
14
+ "left": "{model}",
15
+ "right": "{dir}"
16
+ },
17
+ "segments": {
18
+ "git.info": {
19
+ "items": ["{branch}", "{status}", "{ahead}", "{behind}"],
20
+ "gap": 1
21
+ }
22
+ },
23
+ "breakpoints": [
24
+ {
25
+ "minWidth": 0,
26
+ "areas": [
27
+ "git.icon git.info git.info . git.working",
28
+ "---",
29
+ "context.icon context.bar context.bar context.pct context.tokens",
30
+ "block.icon block.bar block.bar block.value block.time"
31
+ ],
32
+ "columns": ["auto", "1fr", "auto", "auto", "auto"],
33
+ "align": ["left", "left", "right", "right", "right"]
34
+ }
35
+ ]
36
+ },
37
+ "lines": [
38
+ {
39
+ "segments": {
40
+ "directory": { "enabled": true, "showBasename": true },
41
+ "git": { "enabled": true, "showAheadBehind": true },
42
+ "model": { "enabled": true },
43
+ "context": { "enabled": true, "autocompactBuffer": 0 },
44
+ "block": { "enabled": true, "type": "tokens" }
45
+ }
46
+ }
47
+ ]
48
+ },
49
+ "colors": {
50
+ "custom": {
51
+ "model": { "fg": "#e0d68a" },
52
+ "dir": { "fg": "#d2e08a" },
53
+ "git": { "fg": "#c3e88d" },
54
+ "git.working": { "fg": "#90c499" },
55
+ "context": { "fg": "#7ecbc8" },
56
+ "context.pct": { "fg": "#70a4c9" },
57
+ "context.tokens": { "fg": "#70a4c9" },
58
+ "block": { "fg": "#7aa2f7" },
59
+ "block.value": { "fg": "#6e92de" },
60
+ "block.time": { "fg": "#6e92de" }
61
+ }
62
+ },
63
+ "budget": {
64
+ "session": { "warningThreshold": 80 }
65
+ },
66
+ "modelContextLimits": {
67
+ "sonnet": 1000000,
68
+ "opus": 200000
69
+ }
70
+ }