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
Original file line number Diff line number Diff line change
Expand Up @@ -1160,7 +1160,9 @@ extension ClaudeUsageFetcher {
resetsAt: resetDate,
resetDescription: resetDescription))
}
return routineWindows + Self.oauthScopedWeeklyLimitWindows(from: usage)
// Keep the same row order as the Web path: model-scoped weekly limits first,
// Daily Routines last.
return Self.oauthScopedWeeklyLimitWindows(from: usage) + routineWindows
}

private static func oauthScopedWeeklyLimitWindows(from usage: OAuthUsageResponse) -> [NamedRateWindow] {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ enum ClaudeWebExtraRateWindowParser {
var sourceKeys: [String: String] = [:]
windows.reserveCapacity(Self.definitions.count)

// Model-scoped weekly limits come first: they track the model budget users spend
// day to day, while Daily Routines stays at 0% for accounts that never use
// Routines/Cowork and would otherwise push the meaningful row down the card.
windows.append(contentsOf: Self.scopedWeeklyLimitWindows(from: json))

for definition in Self.definitions {
if let foundWindow = Self.firstUsageWindow(in: json, keys: definition.keys) {
let rawWindow = foundWindow.window
Expand All @@ -46,7 +51,6 @@ enum ClaudeWebExtraRateWindowParser {
sourceKeys[definition.id] = key
}
}
windows.append(contentsOf: Self.scopedWeeklyLimitWindows(from: json))
return (windows, sourceKeys)
}

Expand Down
21 changes: 21 additions & 0 deletions Tests/CodexBarTests/ClaudeOAuthTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,27 @@ struct ClaudeOAuthTests {
#expect(fable?.window.resetsAt != nil)
}

@Test
func `orders O auth scoped weekly windows before daily routines`() throws {
let json = """
{
"five_hour": { "utilization": 12.5, "resets_at": "2025-12-25T12:00:00.000Z" },
"seven_day": { "utilization": 30, "resets_at": "2025-12-31T00:00:00.000Z" },
"seven_day_routines": { "utilization": 18, "resets_at": "2026-01-01T00:00:00.000Z" },
"limits": [
{
"kind": "weekly_scoped", "group": "weekly", "percent": 29,
"resets_at": "2025-12-31T00:00:00.000Z",
"scope": { "model": { "id": null, "display_name": "Fable" }, "surface": null },
"is_active": false
}
]
}
"""
let snap = try ClaudeUsageFetcher._mapOAuthUsageForTesting(Data(json.utf8))
#expect(snap.extraRateWindows.map(\.title) == ["Fable only", "Daily Routines"])
}

@Test
func `ignores weekly scoped limit without a model display name`() throws {
let json = """
Expand Down
50 changes: 50 additions & 0 deletions Tests/CodexBarTests/ClaudeWebUsageExtraWindowTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,54 @@ struct ClaudeWebUsageExtraWindowTests {
#expect(fable?.window.usedPercent == 5)
#expect(fable?.window.resetsAt != nil)
}

@Test
func `orders scoped weekly windows before daily routines`() throws {
let json = """
{
"five_hour": { "utilization": 9, "resets_at": "2026-07-03T00:30:00.440902+00:00" },
"seven_day": { "utilization": 20, "resets_at": "2026-07-08T09:00:00.440924+00:00" },
"seven_day_cowork": { "utilization": 11, "resets_at": "2026-07-08T09:00:00.440924+00:00" },
"limits": [
{
"kind": "weekly_scoped", "group": "weekly", "percent": 29,
"resets_at": "2026-07-08T09:00:00.441154+00:00",
"scope": { "model": { "id": null, "display_name": "Fable" }, "surface": null },
"is_active": false
}
]
}
"""
let data = Data(json.utf8)
let parsed = try ClaudeWebAPIFetcher._parseUsageResponseForTesting(data)
#expect(parsed.extraRateWindows.map(\.title) == ["Fable only", "Daily Routines"])
}

@Test
func `keeps multiple scoped weekly windows in payload order before routines`() throws {
let json = """
{
"five_hour": { "utilization": 9, "resets_at": "2026-07-03T00:30:00.440902+00:00" },
"seven_day": { "utilization": 20, "resets_at": "2026-07-08T09:00:00.440924+00:00" },
"seven_day_cowork": { "utilization": 11, "resets_at": "2026-07-08T09:00:00.440924+00:00" },
"limits": [
{
"kind": "weekly_scoped", "group": "weekly", "percent": 12,
"resets_at": "2026-07-08T09:00:00.441154+00:00",
"scope": { "model": { "id": null, "display_name": "Opus" }, "surface": null },
"is_active": false
},
{
"kind": "weekly_scoped", "group": "weekly", "percent": 29,
"resets_at": "2026-07-08T09:00:00.441154+00:00",
"scope": { "model": { "id": null, "display_name": "Fable" }, "surface": null },
"is_active": false
}
]
}
"""
let data = Data(json.utf8)
let parsed = try ClaudeWebAPIFetcher._parseUsageResponseForTesting(data)
#expect(parsed.extraRateWindows.map(\.title) == ["Opus only", "Fable only", "Daily Routines"])
}
}