@andrewkent/claude-statusline 1.1.5 → 1.1.7
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/assets/statusline.sh +44 -5
- package/package.json +1 -1
package/assets/statusline.sh
CHANGED
|
@@ -660,6 +660,13 @@ if $needs_refresh || $needs_profile_refresh; then
|
|
|
660
660
|
-H "User-Agent: claude-code/2.1.34" \
|
|
661
661
|
"https://api.anthropic.com/api/oauth/usage" 2>/dev/null)
|
|
662
662
|
if [ -n "$response" ] && echo "$response" | jq -e '.five_hour' >/dev/null 2>&1; then
|
|
663
|
+
# Save previous poll for interpolation
|
|
664
|
+
if [ -f "$cache_file" ]; then
|
|
665
|
+
prev_ts=$(stat -f %m "$cache_file" 2>/dev/null || stat -c %Y "$cache_file" 2>/dev/null)
|
|
666
|
+
prev_5h=$(jq -r '.five_hour.utilization // 0' "$cache_file" 2>/dev/null)
|
|
667
|
+
prev_7d=$(jq -r '.seven_day.utilization // 0' "$cache_file" 2>/dev/null)
|
|
668
|
+
printf '{"ts":%s,"five_hour":%s,"seven_day":%s}' "$prev_ts" "$prev_5h" "$prev_7d" > "/tmp/claude/statusline-usage-prev.json"
|
|
669
|
+
fi
|
|
663
670
|
echo "$response" > "$cache_file"
|
|
664
671
|
fi
|
|
665
672
|
fi
|
|
@@ -715,13 +722,46 @@ if [ -n "$usage_data" ] && echo "$usage_data" | jq -e . >/dev/null 2>&1; then
|
|
|
715
722
|
"extra_limit_raw=" + (.extra_usage.monthly_limit // 0 | tostring | @sh)
|
|
716
723
|
' 2>/dev/null)"
|
|
717
724
|
|
|
718
|
-
|
|
725
|
+
# Interpolate between polls for fractional precision
|
|
726
|
+
prev_poll_file="/tmp/claude/statusline-usage-prev.json"
|
|
727
|
+
if [ -f "$prev_poll_file" ] && [ -f "$cache_file" ]; then
|
|
728
|
+
poll_ts=$(stat -f %m "$cache_file" 2>/dev/null || stat -c %Y "$cache_file" 2>/dev/null)
|
|
729
|
+
prev_ts=$(jq -r '.ts // 0' "$prev_poll_file" 2>/dev/null)
|
|
730
|
+
prev_5h=$(jq -r '.five_hour // 0' "$prev_poll_file" 2>/dev/null)
|
|
731
|
+
prev_7d=$(jq -r '.seven_day // 0' "$prev_poll_file" 2>/dev/null)
|
|
732
|
+
interp_now=$(date +%s)
|
|
733
|
+
poll_interval=$(( poll_ts - prev_ts ))
|
|
734
|
+
secs_since_poll=$(( interp_now - poll_ts ))
|
|
735
|
+
|
|
736
|
+
if [ "$poll_interval" -gt 10 ] 2>/dev/null && [ "$secs_since_poll" -ge 0 ] 2>/dev/null; then
|
|
737
|
+
five_hour_pct_display=$(awk "BEGIN {
|
|
738
|
+
rate = ($five_hour_pct - $prev_5h) / $poll_interval;
|
|
739
|
+
if (rate < 0) rate = 0;
|
|
740
|
+
est = $five_hour_pct + rate * $secs_since_poll;
|
|
741
|
+
if (est > 100) est = 100;
|
|
742
|
+
printf \"%.1f\", est
|
|
743
|
+
}")
|
|
744
|
+
seven_day_pct_display=$(awk "BEGIN {
|
|
745
|
+
rate = ($seven_day_pct_raw - $prev_7d) / $poll_interval;
|
|
746
|
+
if (rate < 0) rate = 0;
|
|
747
|
+
est = $seven_day_pct_raw + rate * $secs_since_poll;
|
|
748
|
+
if (est > 100) est = 100;
|
|
749
|
+
printf \"%.1f\", est
|
|
750
|
+
}")
|
|
751
|
+
else
|
|
752
|
+
five_hour_pct_display=$(printf "%.1f" "$five_hour_pct" 2>/dev/null || echo "0.0")
|
|
753
|
+
seven_day_pct_display=$(printf "%.1f" "$seven_day_pct_raw" 2>/dev/null || echo "0.0")
|
|
754
|
+
fi
|
|
755
|
+
else
|
|
756
|
+
five_hour_pct_display=$(printf "%.1f" "$five_hour_pct" 2>/dev/null || echo "0.0")
|
|
757
|
+
seven_day_pct_display=$(printf "%.1f" "$seven_day_pct_raw" 2>/dev/null || echo "0.0")
|
|
758
|
+
fi
|
|
719
759
|
five_hour_pct=$(printf "%.0f" "$five_hour_pct" 2>/dev/null || echo 0)
|
|
720
760
|
five_hour_reset=$(format_reset_time "$five_hour_reset_iso" "time")
|
|
721
761
|
five_hour_bar=$(build_bar "$five_hour_pct" "$bar_width")
|
|
722
762
|
five_hour_pct_color=$(color_for_pct "$five_hour_pct")
|
|
723
763
|
|
|
724
|
-
rate_lines+="${white}$(printf "%-7s" "current")${reset} ${five_hour_bar} ${five_hour_pct_color}$(printf "%5.1f" "$five_hour_pct_display")
|
|
764
|
+
rate_lines+="${white}$(printf "%-7s" "current")${reset} ${five_hour_bar} ${five_hour_pct_color}$(printf "%5.1f" "$five_hour_pct_display")%${reset}"
|
|
725
765
|
[ -n "$five_hour_reset" ] && rate_lines+=" ${white}${five_hour_reset}${reset}"
|
|
726
766
|
|
|
727
767
|
# ── Burn-down projection ──────────────────────────
|
|
@@ -776,13 +816,12 @@ if [ -n "$usage_data" ] && echo "$usage_data" | jq -e . >/dev/null 2>&1; then
|
|
|
776
816
|
fi
|
|
777
817
|
fi
|
|
778
818
|
|
|
779
|
-
seven_day_pct_display=$(printf "%.1f" "$seven_day_pct_raw" 2>/dev/null || echo "0.0")
|
|
780
819
|
seven_day_pct=$(printf "%.0f" "$seven_day_pct_raw" 2>/dev/null || echo 0)
|
|
781
820
|
seven_day_reset=$(format_reset_time "$seven_day_reset_iso" "datetime")
|
|
782
821
|
seven_day_bar=$(build_bar "$seven_day_pct" "$bar_width")
|
|
783
822
|
seven_day_pct_color=$(color_for_pct "$seven_day_pct")
|
|
784
823
|
|
|
785
|
-
rate_lines+="\n${white}$(printf "%-7s" "weekly")${reset} ${seven_day_bar} ${seven_day_pct_color}$(printf "%5.1f" "$seven_day_pct_display")
|
|
824
|
+
rate_lines+="\n${white}$(printf "%-7s" "weekly")${reset} ${seven_day_bar} ${seven_day_pct_color}$(printf "%5.1f" "$seven_day_pct_display")%${reset}"
|
|
786
825
|
[ -n "$seven_day_reset" ] && rate_lines+=" ${white}${seven_day_reset}${reset}"
|
|
787
826
|
|
|
788
827
|
# ── Weekly burn-down projection ──────────────────
|
|
@@ -860,7 +899,7 @@ if [ -n "$usage_data" ] && echo "$usage_data" | jq -e . >/dev/null 2>&1; then
|
|
|
860
899
|
extra_bar=$(build_bar "$extra_pct" "$bar_width")
|
|
861
900
|
extra_pct_color=$(color_for_pct "$extra_pct")
|
|
862
901
|
|
|
863
|
-
rate_lines+="\n${white}$(printf "%-7s" "extra")${reset} ${extra_bar} ${extra_pct_color}$(printf "%5.1f" "$extra_pct_display")
|
|
902
|
+
rate_lines+="\n${white}$(printf "%-7s" "extra")${reset} ${extra_bar} ${extra_pct_color}$(printf "%5.1f" "$extra_pct_display")%${reset} ${white}\$${extra_used}${dim}/${reset}${white}\$${extra_limit}${reset}"
|
|
864
903
|
fi
|
|
865
904
|
fi
|
|
866
905
|
|