feat(terra): Claude subscription limits panel on the rail
CLD panel next to luna showing the 5-hour and weekly usage windows (plus any per-model weekly caps), polled every 5 min via a new `claude-usage` script that reuses Claude Code's OAuth login and refreshes it when expired. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,149 @@
|
||||
pragma ComponentBehavior: Bound
|
||||
|
||||
import QtQuick
|
||||
import qs.HyprChrome.Theme
|
||||
import qs.HyprChrome.Widgets.Bar.Panels
|
||||
import qs.HyprChrome.Widgets.Bar.Vitals
|
||||
|
||||
// Claude subscription limits on the rail: the 5-hour session window and the
|
||||
// weekly one, plus any per-model weekly caps the plan reports.
|
||||
BarPanel {
|
||||
id: claude
|
||||
|
||||
// Overridable so the headless render can stage it without the network.
|
||||
property var fiveHour: usage.fiveHour
|
||||
property var sevenDay: usage.sevenDay
|
||||
property var extra: usage.extra
|
||||
property string error: usage.error
|
||||
property bool ready: usage.ready
|
||||
|
||||
readonly property var usage: ClaudeState {}
|
||||
|
||||
panelId: "CLD"
|
||||
title: "CLAUDE"
|
||||
meta: claude.error !== "" ? (claude.ready ? "STALE" : "OFFLINE") : claude.ready ? "LIMITS" : "PRIMING"
|
||||
|
||||
// Ticks the reset countdowns without re-polling.
|
||||
property date now: new Date()
|
||||
Timer {
|
||||
interval: 30000
|
||||
running: true
|
||||
repeat: true
|
||||
onTriggered: claude.now = new Date()
|
||||
}
|
||||
|
||||
implicitWidth: claude.expanded
|
||||
? Math.max(claude.headerMinWidth, claude.padding * 2 + body.width)
|
||||
: Math.max(claude.headerMinWidth, claude.briefLeft + brief.implicitWidth + claude.padding)
|
||||
|
||||
function fraction(w) {
|
||||
return w ? Math.max(0, Math.min(1, w.utilization / 100)) : 0;
|
||||
}
|
||||
|
||||
function pct(w) {
|
||||
return w ? Math.round(w.utilization) + "%" : "--";
|
||||
}
|
||||
|
||||
function until(w) {
|
||||
if (!w || !w.resets_at)
|
||||
return "";
|
||||
const mins = Math.max(0, Math.round((new Date(w.resets_at) - claude.now) / 60000));
|
||||
if (mins >= 1440)
|
||||
return `${Math.floor(mins / 1440)}D ${Math.floor(mins % 1440 / 60)}H`;
|
||||
if (mins >= 60)
|
||||
return `${Math.floor(mins / 60)}H ${mins % 60}M`;
|
||||
return `${mins}M`;
|
||||
}
|
||||
|
||||
function tone(w) {
|
||||
const f = claude.fraction(w);
|
||||
return !claude.ready ? Theme.disabled : f >= 0.85 ? Theme.hot : Theme.text;
|
||||
}
|
||||
|
||||
summary: Row {
|
||||
id: brief
|
||||
spacing: 10
|
||||
|
||||
Repeater {
|
||||
model: [
|
||||
{ label: "5H", window: claude.fiveHour },
|
||||
{ label: "7D", window: claude.sevenDay }
|
||||
]
|
||||
|
||||
Row {
|
||||
required property var modelData
|
||||
spacing: 4
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
|
||||
Text {
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
text: parent.modelData.label
|
||||
color: Theme.muted
|
||||
font.family: Theme.microFont
|
||||
font.pixelSize: 10
|
||||
}
|
||||
|
||||
Text {
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
text: claude.pct(parent.modelData.window)
|
||||
color: claude.tone(parent.modelData.window)
|
||||
font.family: Theme.displayFont
|
||||
font.pixelSize: 13
|
||||
font.bold: true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Column {
|
||||
id: body
|
||||
width: 260
|
||||
spacing: 5
|
||||
|
||||
Repeater {
|
||||
model: [
|
||||
{ label: "SESSION", window: claude.fiveHour },
|
||||
{ label: "WEEKLY", window: claude.sevenDay }
|
||||
].concat(claude.extra)
|
||||
|
||||
Column {
|
||||
required property var modelData
|
||||
width: body.width
|
||||
spacing: 2
|
||||
|
||||
VitalRow {
|
||||
width: parent.width
|
||||
labelWidth: 64
|
||||
label: parent.modelData.label
|
||||
value: claude.fraction(parent.modelData.window)
|
||||
readout: claude.pct(parent.modelData.window)
|
||||
ready: claude.ready && !!parent.modelData.window
|
||||
}
|
||||
|
||||
Text {
|
||||
x: 64
|
||||
visible: text !== ""
|
||||
text: {
|
||||
const t = claude.until(parent.modelData.window);
|
||||
return t ? `RESETS IN ${t}` : "";
|
||||
}
|
||||
color: Theme.muted
|
||||
font.family: Theme.microFont
|
||||
font.pixelSize: 9
|
||||
font.letterSpacing: 1.2
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Text {
|
||||
width: body.width
|
||||
visible: claude.error !== ""
|
||||
text: claude.error.toUpperCase()
|
||||
color: Theme.hot
|
||||
font.family: Theme.microFont
|
||||
font.pixelSize: 9
|
||||
font.letterSpacing: 1.2
|
||||
wrapMode: Text.WordWrap
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
pragma ComponentBehavior: Bound
|
||||
|
||||
import QtQuick
|
||||
import Quickshell.Io
|
||||
|
||||
// Claude subscription limits, polled through `claude-usage` (pkgs/claude-usage.nix),
|
||||
// which reuses Claude Code's OAuth login and prints the usage endpoint's JSON.
|
||||
QtObject {
|
||||
id: root
|
||||
|
||||
// Each window is { utilization: 0..100, resets_at: ISO string } or null.
|
||||
property var fiveHour: null
|
||||
property var sevenDay: null
|
||||
// Per-model weekly windows the plan reports, as [{ label, window }].
|
||||
property var extra: []
|
||||
property string error: ""
|
||||
property bool ready: false
|
||||
|
||||
// The endpoint is rate-limited and the numbers move slowly.
|
||||
property int interval: 300000
|
||||
|
||||
readonly property var proc: Process {
|
||||
id: proc
|
||||
command: ["claude-usage"]
|
||||
|
||||
stdout: StdioCollector {
|
||||
onStreamFinished: root.ingest(this.text)
|
||||
}
|
||||
}
|
||||
|
||||
readonly property var poll: Timer {
|
||||
interval: root.interval
|
||||
running: true
|
||||
repeat: true
|
||||
triggeredOnStart: true
|
||||
onTriggered: {
|
||||
if (!proc.running)
|
||||
proc.running = true;
|
||||
}
|
||||
}
|
||||
|
||||
function ingest(text: string): void {
|
||||
let msg;
|
||||
try {
|
||||
msg = JSON.parse(text);
|
||||
} catch (e) {
|
||||
root.error = "no output";
|
||||
return;
|
||||
}
|
||||
if (msg.error) {
|
||||
// Keep the last good numbers; a failed poll is not zero usage.
|
||||
root.error = msg.error;
|
||||
return;
|
||||
}
|
||||
root.error = "";
|
||||
root.fiveHour = msg.five_hour ?? null;
|
||||
root.sevenDay = msg.seven_day ?? null;
|
||||
|
||||
const found = [];
|
||||
for (const key of Object.keys(msg)) {
|
||||
const m = key.match(/^seven_day_(\w+)$/);
|
||||
const w = msg[key];
|
||||
if (m && w && typeof w.utilization === "number")
|
||||
found.push({ label: m[1].toUpperCase().replace(/_/g, " "), window: w });
|
||||
}
|
||||
root.extra = found;
|
||||
root.ready = true;
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,7 @@ import Quickshell
|
||||
import Quickshell.Wayland
|
||||
import qs.HyprChrome.Theme
|
||||
import qs.HyprChrome.Widgets.Bar.Luna
|
||||
import qs.HyprChrome.Widgets.Bar.Claude
|
||||
import qs.HyprChrome.Widgets.Bar.Host
|
||||
import qs.HyprChrome.Widgets.Bar.Vitals
|
||||
import qs.HyprChrome.Widgets.Bar.Workspaces
|
||||
@@ -87,8 +88,8 @@ PanelWindow {
|
||||
//
|
||||
// The zone still follows the target height, so tiled windows reflow once
|
||||
// per toggle, at the start, and slide while the panels animate.
|
||||
readonly property real expandedContent: Math.max(hostPanel.expandedHeight, workspacesPanel.expandedHeight, vitalsPanel.expandedHeight, lunaPanel.expandedHeight, trayPanel.expandedHeight) + window.margin * 2
|
||||
readonly property real contentHeight: Math.max(hostPanel.targetHeight, workspacesPanel.targetHeight, vitalsPanel.targetHeight, lunaPanel.targetHeight, trayPanel.targetHeight) + window.margin * 2
|
||||
readonly property real expandedContent: Math.max(hostPanel.expandedHeight, workspacesPanel.expandedHeight, vitalsPanel.expandedHeight, lunaPanel.expandedHeight, claudePanel.expandedHeight, trayPanel.expandedHeight) + window.margin * 2
|
||||
readonly property real contentHeight: Math.max(hostPanel.targetHeight, workspacesPanel.targetHeight, vitalsPanel.targetHeight, lunaPanel.targetHeight, claudePanel.targetHeight, trayPanel.targetHeight) + window.margin * 2
|
||||
|
||||
implicitHeight: Math.round(window.expandedContent)
|
||||
|
||||
@@ -161,6 +162,19 @@ PanelWindow {
|
||||
id: lunaPanel
|
||||
|
||||
expanded: window.expanded
|
||||
// Claude butts against its right edge.
|
||||
rightChamfer: false
|
||||
|
||||
toggleOnClick: false
|
||||
Layout.fillHeight: true
|
||||
}
|
||||
|
||||
ClaudePanel {
|
||||
id: claudePanel
|
||||
|
||||
expanded: window.expanded
|
||||
leftChamfer: false
|
||||
|
||||
toggleOnClick: false
|
||||
Layout.fillHeight: true
|
||||
}
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
import QtQuick
|
||||
import qs.HyprChrome.Widgets.Bar.Claude
|
||||
|
||||
// The rail's claude panel collapsed and expanded, healthy and failing.
|
||||
//
|
||||
// ./tools/quickshell-preview/render.sh \
|
||||
// tests/ClaudePanelHeadless.qml \
|
||||
// .artifacts/quickshell-preview/claude-panel.png 640 420
|
||||
Rectangle {
|
||||
width: 640
|
||||
height: 420
|
||||
color: "#0f1012"
|
||||
|
||||
readonly property var soon: new Date(Date.now() + 2 * 3600000 + 17 * 60000).toISOString()
|
||||
readonly property var later: new Date(Date.now() + 4 * 86400000 + 5 * 3600000).toISOString()
|
||||
|
||||
Row {
|
||||
x: 16
|
||||
y: 16
|
||||
spacing: 24
|
||||
|
||||
Column {
|
||||
spacing: 12
|
||||
|
||||
ClaudePanel {
|
||||
expanded: false
|
||||
ready: true
|
||||
fiveHour: ({ utilization: 42, resets_at: soon })
|
||||
sevenDay: ({ utilization: 91, resets_at: later })
|
||||
}
|
||||
|
||||
ClaudePanel {
|
||||
expanded: false
|
||||
ready: false
|
||||
error: "token refresh HTTP 400"
|
||||
}
|
||||
}
|
||||
|
||||
Column {
|
||||
spacing: 12
|
||||
|
||||
ClaudePanel {
|
||||
expanded: true
|
||||
ready: true
|
||||
fiveHour: ({ utilization: 42, resets_at: soon })
|
||||
sevenDay: ({ utilization: 91, resets_at: later })
|
||||
extra: [{ label: "SONNET", window: { utilization: 12, resets_at: later } }]
|
||||
}
|
||||
|
||||
ClaudePanel {
|
||||
expanded: true
|
||||
ready: true
|
||||
error: "usage HTTP 429"
|
||||
fiveHour: ({ utilization: 8, resets_at: soon })
|
||||
sevenDay: ({ utilization: 30, resets_at: later })
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user