-
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathhud_rate_limits.py
More file actions
31 lines (26 loc) · 928 Bytes
/
Copy pathhud_rate_limits.py
File metadata and controls
31 lines (26 loc) · 928 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
"""Rate-limit formatting for CodingBuddy statusLine (#1326).
Extracted verbatim from codingbuddy-hud.py as part of the Wave 0 refactor.
Behavior-preserving — see tests/test_hud.py for the contract.
"""
from __future__ import annotations
from typing import Any, Dict
def format_rate_limits(stdin_data: Dict[str, Any]) -> str:
"""Format Claude Code rate-limit badge.
Returns an empty string when no rate-limit data is supplied so the
badge can be dropped from the status line silently.
"""
rl = stdin_data.get("rate_limits")
if not rl:
return ""
parts = []
five = rl.get("five_hour")
if five:
pct = five.get("used_percentage", 0)
parts.append(f"5h:{pct:.0f}%")
seven = rl.get("seven_day")
if seven:
pct = seven.get("used_percentage", 0)
parts.append(f"7d:{pct:.0f}%")
if not parts:
return ""
return "RL:" + ",".join(parts)