Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ for the full-size view, including the native menu bar or taskbar.
- **Popup view** — Segmented bars showing exact fill level with reset times and live countdowns that show "resetting..." when a window flips
- **Usage chart** — Smooth, glowing area chart of historical usage with availability-aware 5H / 24H / 7D choices and hover-scrub
- **Burn-rate ETA** — Estimates time to 100% from your recent trend (e.g. "↗ ~3h to 100%") for each available window
- **Period comparison** — Shows how today/this week compares to the same point last period (e.g. "+12% vs last week")
- **Period comparison** — Shows how much more or less you have used than by the same point last period (e.g. "+12% vs last week"): weekly and monthly windows against the same day of the one before, 5-hour sessions as today against yesterday by the same time
- **Cost aggregation** — Combined API spend across Claude, OpenAI, and OpenRouter in the footer
- **Model breakdown** — Usage per model for providers that expose it
- **Theme-aware accent** — Follows your Plasma accent color by default, or use per-service brand colors
Expand Down
11 changes: 11 additions & 0 deletions backend/tidesi/accounts.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,4 +175,15 @@ def relabel(provider, account):
result["id"] = account["id"]
result["label"] = f"{base_label} · {account['label']}"
result["profile"] = {"base": account["base"], "label": account["label"], "home": account["home"]}
# Its own history series ("s@work"): two logins of one provider are two
# quotas, and one series fed by both is a chart and an ETA of neither.
series = lambda key: f"{key}{ACCOUNT_SEPARATOR}{account['key']}" # noqa: E731
if isinstance(result.get("historyValues"), dict):
result["historyValues"] = {series(key): value for key, value in result["historyValues"].items()}
if isinstance(result.get("chartWindows"), list):
result["chartWindows"] = [{**w, "key": series(w["key"])} if isinstance(w, dict) and w.get("key") else w for w in result["chartWindows"]]
if isinstance(result.get("quotaWindows"), list):
result["quotaWindows"] = [
{**w, "historyKey": series(w["historyKey"])} if isinstance(w, dict) and w.get("historyKey") else w for w in result["quotaWindows"]
]
return result
51 changes: 41 additions & 10 deletions backend/tidesi/contract.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,44 @@ def window_value(pct, reset, active):
return {"available": True, "pct": pct_clamp(pct), "resetAt": epoch_of(reset)}


def quota_window(key, label, w, detail, history=""):
# A window that resets on a calendar date: its length is the month that ends at
# the row's reset, which period_ms() works out.
MONTH = "month"


def period_ms(period, reset_at):
"""The length in ms of the window a row meters, 0 when it is not known.

`period` is a length in ms, or MONTH for a window that runs from one
calendar date to the same date a month on: 28 to 31 days, read off the
reset so the frontends compare against the right day of the month before."""
if period != MONTH:
return int(period) if isinstance(period, (int, float)) and not isinstance(period, bool) and period > 0 else 0
if not reset_at or reset_at <= 0:
return 0
try:
end = datetime.datetime.fromtimestamp(reset_at, datetime.timezone.utc)
except (OverflowError, OSError, ValueError):
return 0
year, month = (end.year, end.month - 1) if end.month > 1 else (end.year - 1, 12)
start = end.replace(year=year, month=month, day=min(end.day, calendar.monthrange(year, month)[1]))
return int((end - start).total_seconds() * 1000)


def _series(w, history, period):
if history:
# The historyValues series this row's pct is recorded under, which the
# frontends read the row's "~3h to 100%" and "+12% vs last week" from.
w["historyKey"] = history
length = period_ms(period, w["resetAt"])
if length:
# How long the metered window runs, for the comparison with the same
# point of the window before.
w["periodMs"] = length
return w


def quota_window(key, label, w, detail, history="", period=0):
reset_at = w.get("resetAt", 0) or 0
qw = {
"key": key,
Expand All @@ -189,14 +226,10 @@ def quota_window(key, label, w, detail, history=""):
"detail": detail,
"showMeter": True,
}
if history:
# The historyValues series this row's pct is recorded under, which the
# frontends fit a burn rate to for the row's "~3h to 100%".
qw["historyKey"] = history
return qw
return _series(qw, history, period)


def flat_window(key, label, pct, reset_at, detail, meter, note="", history=""):
def flat_window(key, label, pct, reset_at, detail, meter, note="", history="", period=0):
w = {
"key": key,
"label": label,
Expand All @@ -212,9 +245,7 @@ def flat_window(key, label, pct, reset_at, detail, meter, note="", history=""):
# beside it. `note` is the aside such a row would otherwise have to
# cram into the value.
w["note"] = note
if history:
w["historyKey"] = history
return w
return _series(w, history, period)


def chart_window(id_, key, label, size, gran):
Expand Down
12 changes: 9 additions & 3 deletions backend/tidesi/normalize/claude.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,9 +212,14 @@ def normalize_claude(raw):
"hasChart": True,
}
r["quotaWindows"] = [
quota_window("session", tr("5-hour session"), w["session"], s_detail, history="s"),
quota_window("weekly", tr("7-day window"), w["weekly"], w_detail, history="w"),
] + [quota_window(scoped_key(name), scoped_label(name), win, "") for name, win in w["scoped"] if win["available"]]
quota_window("session", tr("5-hour session"), w["session"], s_detail, history="s", period=18000000),
quota_window("weekly", tr("7-day window"), w["weekly"], w_detail, history="w", period=604800000),
] + [
# A scoped week is a budget of its own, so it is recorded under its row key.
quota_window(scoped_key(name), scoped_label(name), win, "", history=scoped_key(name), period=604800000)
for name, win in w["scoped"]
if win["available"]
]
r["slots"] = [
{
"pct": w["session"]["pct"],
Expand All @@ -233,6 +238,7 @@ def normalize_claude(raw):
r["historyValues"] = {
**({"s": w["session"]["pct"]} if w["session"]["available"] else {}),
**({"w": w["weekly"]["pct"]} if w["weekly"]["available"] else {}),
**{scoped_key(name): win["pct"] for name, win in w["scoped"] if win["available"]},
}
if extra.get("tokens_remaining") is not None:
extra_tokens = num(extra.get("tokens_remaining"))
Expand Down
2 changes: 1 addition & 1 deletion backend/tidesi/normalize/copilot.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def normalize_copilot(raw):
"detail": f"@{username}" if username != "" else tr("Personal billing"),
"hasChart": True,
}
r["quotaWindows"] = [flat_window("copilot", tr("Premium requests"), pct, reset_at, detail, not unlimited, history="gh")]
r["quotaWindows"] = [flat_window("copilot", tr("Premium requests"), pct, reset_at, detail, not unlimited, history="gh", period="month")]
r["slots"] = [{"pct": pct, "color": "#8b5cf6", "text": None, "tooltip": tr("Copilot premium requests: %1", detail)}]
r["chartWindows"] = monthly_window("copilot", "gh", False)
r["historyValues"] = {"gh": pct}
Expand Down
10 changes: 6 additions & 4 deletions backend/tidesi/normalize/cursor.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,12 @@ def normalize_cursor(raw):
od_limit = num(slu.get("individualLimit")) / 100

total_detail = f"{money(included, 'USD')} / {money(limit, 'USD')}" if limit > 0 else tr("%1% of included usage", jround(total))
windows = [flat_window("cursor_total", tr("Included usage"), total, reset_at, total_detail, True, history="cu")]
windows = [flat_window("cursor_total", tr("Included usage"), total, reset_at, total_detail, True, history="cu", period="month")]
if has_split:
windows.append(flat_window("cursor_auto", tr("Auto + Composer"), auto, reset_at, tr("%1% used", jround(auto)), True))
windows.append(flat_window("cursor_api", tr("API models"), api, reset_at, tr("%1% used", jround(api)), True))
windows.append(
flat_window("cursor_auto", tr("Auto + Composer"), auto, reset_at, tr("%1% used", jround(auto)), True, history="cua", period="month")
)
windows.append(flat_window("cursor_api", tr("API models"), api, reset_at, tr("%1% used", jround(api)), True, history="cup", period="month"))
if od_limit > 0 or od_used > 0:
od_pct = od_used / od_limit * 100 if od_limit > 0 else 0
od_detail = f"{money(od_used, 'USD')} / {money(od_limit, 'USD')}" if od_limit > 0 else money(od_used, "USD")
Expand All @@ -77,7 +79,7 @@ def normalize_cursor(raw):
}
]
r["chartWindows"] = monthly_window("cursor", "cu", False)
r["historyValues"] = {"cu": total}
r["historyValues"] = {"cu": total, **({"cua": auto, "cup": api} if has_split else {})}
upgrade = plan_body.get("nextUpgrade") if isinstance(plan_body.get("nextUpgrade"), dict) else {}
r["details"] = {
**base_details,
Expand Down
2 changes: 1 addition & 1 deletion backend/tidesi/normalize/jetbrains.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def normalize_jetbrains(raw):
r = provider_base("jetbrains", "JetBrains AI", ACCENT, now)
r["account"] = account(res.get("ide") or "", [chip(res.get("state"), "muted")] if res.get("state") not in ("", "Available", None) else [])
r["summary"] = {"pct": pct, "text": f"{jround(pct)}%", "detail": detail, "hasChart": True}
r["quotaWindows"] = [flat_window("jetbrains", tr("Monthly credits"), pct, reset_at, detail, True, history="jb")]
r["quotaWindows"] = [flat_window("jetbrains", tr("Monthly credits"), pct, reset_at, detail, True, history="jb", period="month")]
r["slots"] = [
{
"pct": pct,
Expand Down
2 changes: 1 addition & 1 deletion backend/tidesi/normalize/kiro.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def normalize_kiro(raw):
),
)
r["summary"] = {"pct": pct, "text": f"{jround(pct)}%", "detail": plan, "hasChart": True}
r["quotaWindows"] = [flat_window("kiro", tr("Monthly credits"), pct, reset_at, detail, True, history="kr" if available else "")]
r["quotaWindows"] = [flat_window("kiro", tr("Monthly credits"), pct, reset_at, detail, True, history="kr" if available else "", period="month")]
r["slots"] = [
{
"pct": pct,
Expand Down
13 changes: 12 additions & 1 deletion backend/tidesi/normalize/moonshot.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,18 @@ def normalize_moonshot(raw):
first_of.setdefault(w.get("seconds"), w)
for i, w in enumerate(windows):
series = {18000: "kc", 604800: "kcw"}.get(w.get("seconds"), "") if first_of.get(w.get("seconds")) is w else ""
rows.append(flat_window(f"kimi_code_{i}", w["label"], w["pct"], w["resetAt"], f"{w['used']} / {w['limit']}", True, history=series))
rows.append(
flat_window(
f"kimi_code_{i}",
w["label"],
w["pct"],
w["resetAt"],
f"{w['used']} / {w['limit']}",
True,
history=series,
period=(w.get("seconds") or 0) * 1000,
)
)
if exhausted and not windows:
rows.append(flat_window("kimi_code_plan", tr("Plan usage"), 100, 0, code_plan["message"] or tr("Plan quota used up"), True))
if code_plan["booster"]:
Expand Down
4 changes: 2 additions & 2 deletions backend/tidesi/normalize/muse.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,9 @@ def normalize_muse(raw):
# Plan windows only exist here when the user opted into the billed call
# (providers/muse_quota.py); everything else on this tab is free and local.
windows = []
for key, label, w, series in (("muse_current", "Current", current, "mc"), ("muse_weekly", "Weekly", weekly, "mw")):
for key, label, w, series, period in (("muse_current", "Current", current, "mc", 0), ("muse_weekly", "Weekly", weekly, "mw", 604800000)):
if w["available"]:
windows.append(quota_window(key, label, w, tr("%1% used", jround(w["pct"])), history=series))
windows.append(quota_window(key, label, w, tr("%1% used", jround(w["pct"])), history=series, period=period))

if stats.get("available"):
windows.append(
Expand Down
5 changes: 4 additions & 1 deletion backend/tidesi/normalize/ollama.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

ACCENT = "#f0f0f0"
BUCKETS = (("session", "Session (5h)"), ("weekly", "Weekly (7d)"), ("monthly", "Monthly"))
_PERIODS = {"session": 18000000, "weekly": 604800000, "monthly": "month"}


def normalize_ollama(raw):
Expand Down Expand Up @@ -59,7 +60,9 @@ def normalize_ollama(raw):
if "allowance_usd" in bucket:
label = tr("Included credits")
detail = tr("%1 of %2 USD remaining", f"{bucket['balance_usd']:.2f}", f"{bucket['allowance_usd']:.2f}")
windows.append(flat_window(f"ollama_{key}", label, pct, epoch_of(bucket.get("resets_at")), detail, True, history=f"ollama_{key}"))
windows.append(
flat_window(f"ollama_{key}", label, pct, epoch_of(bucket.get("resets_at")), detail, True, history=f"ollama_{key}", period=_PERIODS[key])
)
rows = bucket.get("models")
if isinstance(rows, list):
models[key] = [
Expand Down
29 changes: 26 additions & 3 deletions backend/tidesi/normalize/openai.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@
from ..stats import codex_stats


def _additional_series(name, suffix):
"""The history series of an additional (per-model) Codex limit: "cx_<model>_s"
for its 5-hour window, "_w" for its weekly one."""
slug = "".join(c if c.isalnum() else "_" for c in str(name).lower()).strip("_") or "model"
return f"cx_{slug}_{suffix}"


def _codex_window(w):
if not isinstance(w, dict):
return {"kind": "", "value": unavailable_window()}
Expand Down Expand Up @@ -165,9 +172,13 @@ def normalize_openai(raw):
}
quota_windows = []
if session_on:
quota_windows.append(quota_window("codex_session", tr("Codex 5-hour"), codex["session"], tr("ChatGPT/Codex plan window"), history="cp"))
quota_windows.append(
quota_window("codex_session", tr("Codex 5-hour"), codex["session"], tr("ChatGPT/Codex plan window"), history="cp", period=18000000)
)
if weekly_on:
quota_windows.append(quota_window("codex_weekly", tr("Codex weekly"), codex["weekly"], tr("Secondary plan window"), history="cw"))
quota_windows.append(
quota_window("codex_weekly", tr("Codex weekly"), codex["weekly"], tr("Secondary plan window"), history="cw", period=604800000)
)
for a in codex["additional"]:
if a["session"]["available"]:
quota_windows.append(
Expand All @@ -176,10 +187,16 @@ def normalize_openai(raw):
tr("%1 · 5-hour", a["name"]),
a["session"],
tr("Limit reached") if a["limitReached"] else "",
history=_additional_series(a["name"], "s"),
period=18000000,
)
)
if a["weekly"]["available"]:
quota_windows.append(quota_window("additional", tr("%1 · weekly", a["name"]), a["weekly"], ""))
quota_windows.append(
quota_window(
"additional", tr("%1 · weekly", a["name"]), a["weekly"], "", history=_additional_series(a["name"], "w"), period=604800000
)
)
r["quotaWindows"] = quota_windows
if org_error:
r["quotaWindows"].append(flat_window("openai_org_usage", tr("Organization usage unavailable"), 0, 0, org_error, False))
Expand Down Expand Up @@ -215,6 +232,12 @@ def normalize_openai(raw):
r["historyValues"] = {
**({"cp": codex["session"]["pct"]} if codex["session"]["available"] else {}),
**({"cw": codex["weekly"]["pct"]} if codex["weekly"]["available"] else {}),
**{
_additional_series(a["name"], suffix): a[window]["pct"]
for a in codex["additional"]
for window, suffix in (("session", "s"), ("weekly", "w"))
if a[window]["available"]
},
}
r["details"] = details
return r
Expand Down
4 changes: 2 additions & 2 deletions backend/tidesi/normalize/opencode.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,8 @@ def _normalize_go(now, stats, account):
r = provider_base("opencode", "OpenCode", ACCENT, now)
r["summary"] = {"pct": primary_pct, "text": f"{jround(primary_pct)}%", "detail": primary_label, "hasChart": True}
r["quotaWindows"] = [
flat_window(key, label, pct, reset_at, tr("%1% used", jround(pct)), True, history=key)
for _name, (key, label, _period, (pct, reset_at)) in parsed.items()
flat_window(key, label, pct, reset_at, tr("%1% used", jround(pct)), True, history=key, period="month" if name == "monthly" else period)
for name, (key, label, period, (pct, reset_at)) in parsed.items()
]
r["slots"] = [
{
Expand Down
8 changes: 4 additions & 4 deletions backend/tidesi/normalize/zai.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,9 @@ def normalize_zai(raw):
today_detail = _today_detail(today) if today else ""

r["quotaWindows"] = [
flat_window("zai_tokens", tr("5-hour tokens"), token_pct, token_reset, token_detail, True, history="za"),
flat_window("zai_tokens_long", tr("7-day tokens"), token2_pct, token2_reset, "", True),
flat_window("zai_tools", tr("Monthly tools"), tools_pct, tools_reset, tools_detail, True),
flat_window("zai_tokens", tr("5-hour tokens"), token_pct, token_reset, token_detail, True, history="za", period=18000000),
flat_window("zai_tokens_long", tr("7-day tokens"), token2_pct, token2_reset, "", True, history="za7", period=604800000),
flat_window("zai_tools", tr("Monthly tools"), tools_pct, tools_reset, tools_detail, True, history="zat", period="month"),
]
if today_detail:
# Consumption so far, not a share of anything, so it carries a value
Expand All @@ -108,7 +108,7 @@ def normalize_zai(raw):
{"pct": tools_pct, "color": "#60a5fa", "text": None, "tooltip": tr("Z.AI tools: %1%", jround(tools_pct))},
]
r["chartWindows"] = monthly_window("zai", "za", False)
r["historyValues"] = {"za": token_pct}
r["historyValues"] = {"za": token_pct, "za7": token2_pct, "zat": tools_pct}
r["details"] = {
"hasKey": res.get("hasKey") is True,
"keyValid": res.get("keyValid") is True,
Expand Down
11 changes: 10 additions & 1 deletion backend/tidesi/normalize/zed.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,16 @@ def normalize_zed(raw):
if not unlimited and isinstance(used, (int, float)) and isinstance(limit, (int, float)) and limit > 0:
pct = pct_clamp(used / limit * 100)
rows.append(
flat_window("zed_predictions", tr("Edit predictions"), pct, reset_at, tr("%1 / %2", jround(used), jround(limit)), True, history="zd")
flat_window(
"zed_predictions",
tr("Edit predictions"),
pct,
reset_at,
tr("%1 / %2", jround(used), jround(limit)),
True,
history="zd",
period="month",
)
)
elif unlimited:
rows.append(flat_window("zed_predictions", tr("Edit predictions"), 0, reset_at, tr("Unlimited"), False))
Expand Down
Loading
Loading