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,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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user