feat(worker): add OAuth usage client + poller

Adds Usage/ with ClaudeOAuthUsageClient (reads the access token Claude
Code keeps fresh at ~/.claude/.credentials.json, calls the Anthropic
OAuth usage endpoint, defensively parses buckets/limits), UsageState
(threadsafe last-good-snapshot holder that never regresses on
failure), and UsageMonitorService (BackgroundService polling on the
new usage_poll_interval_seconds config, min 15s, one poll at startup,
warns at most once per distinct error).
This commit is contained in:
mika kuns
2026-08-05 10:00:25 +02:00
parent 8d7ba1e314
commit 20d17c6887
11 changed files with 619 additions and 0 deletions
+18
View File
@@ -0,0 +1,18 @@
namespace ClaudeDo.Worker.Usage;
public sealed record UsageBucket(double Utilization, DateTimeOffset? ResetsAt);
public sealed record UsageLimitRow(
string Kind,
string Group,
double Percent,
string Severity,
DateTimeOffset? ResetsAt,
string? ScopeModelDisplayName,
bool IsActive);
public sealed record UsageSnapshot(
UsageBucket? FiveHour,
UsageBucket? SevenDay,
IReadOnlyList<UsageLimitRow> Limits,
DateTime FetchedAtUtc);