Skip to content
Open
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 Sources/CodexBar/MenuBarMetricWindowResolver.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ enum MenuBarMetricWindowResolver {
if provider == .antigravity {
return snapshot.primary ?? snapshot.secondary ?? snapshot.tertiary
}
if provider == .factory || provider == .kimi {
if provider == .factory {
return snapshot.secondary ?? snapshot.primary
}
if provider == .copilot,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ public enum KimiProviderDescriptor {
metadata: ProviderMetadata(
id: .kimi,
displayName: "Kimi",
sessionLabel: "Weekly",
weeklyLabel: "Rate Limit",
sessionLabel: "Rate Limit",
weeklyLabel: "Weekly",
opusLabel: nil,
supportsOpus: false,
supportsCredits: false,
Expand Down
4 changes: 2 additions & 2 deletions Sources/CodexBarCore/Providers/Kimi/KimiUsageSnapshot.swift
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ extension KimiUsageSnapshot {
loginMethod: nil)

return UsageSnapshot(
primary: weeklyWindow,
secondary: rateLimitWindow,
primary: rateLimitWindow,
secondary: weeklyWindow,
tertiary: nil,
providerCost: nil,
updatedAt: self.updatedAt,
Expand Down
26 changes: 13 additions & 13 deletions Tests/CodexBarTests/KimiProviderTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -191,16 +191,16 @@ struct KimiUsageSnapshotConversionTests {
let usageSnapshot = snapshot.toUsageSnapshot()

#expect(usageSnapshot.primary != nil)
let weeklyExpected = 375.0 / 2048.0 * 100.0
#expect(abs((usageSnapshot.primary?.usedPercent ?? 0.0) - weeklyExpected) < 0.01)
#expect(usageSnapshot.primary?.resetDescription == "375/2048 requests")
#expect(usageSnapshot.primary?.windowMinutes == nil)
let rateExpected = 200.0 / 200.0 * 100.0
#expect(abs((usageSnapshot.primary?.usedPercent ?? 0.0) - rateExpected) < 0.01)
#expect(usageSnapshot.primary?.windowMinutes == 300) // 5 hours
#expect(usageSnapshot.primary?.resetDescription == "Rate: 200/200 per 5 hours")

#expect(usageSnapshot.secondary != nil)
let rateExpected = 200.0 / 200.0 * 100.0
#expect(abs((usageSnapshot.secondary?.usedPercent ?? 0.0) - rateExpected) < 0.01)
#expect(usageSnapshot.secondary?.windowMinutes == 300) // 5 hours
#expect(usageSnapshot.secondary?.resetDescription == "Rate: 200/200 per 5 hours")
let weeklyExpected = 375.0 / 2048.0 * 100.0
#expect(abs((usageSnapshot.secondary?.usedPercent ?? 0.0) - weeklyExpected) < 0.01)
#expect(usageSnapshot.secondary?.resetDescription == "375/2048 requests")
#expect(usageSnapshot.secondary?.windowMinutes == nil)

#expect(usageSnapshot.tertiary == nil)
#expect(usageSnapshot.updatedAt == now)
Expand All @@ -222,10 +222,10 @@ struct KimiUsageSnapshotConversionTests {

let usageSnapshot = snapshot.toUsageSnapshot()

#expect(usageSnapshot.primary != nil)
#expect(usageSnapshot.primary == nil)
#expect(usageSnapshot.secondary != nil)
let weeklyExpected = 375.0 / 2048.0 * 100.0
#expect(abs((usageSnapshot.primary?.usedPercent ?? 0.0) - weeklyExpected) < 0.01)
#expect(usageSnapshot.secondary == nil)
#expect(abs((usageSnapshot.secondary?.usedPercent ?? 0.0) - weeklyExpected) < 0.01)
#expect(usageSnapshot.tertiary == nil)
}

Expand All @@ -244,7 +244,7 @@ struct KimiUsageSnapshotConversionTests {
updatedAt: now)

let usageSnapshot = snapshot.toUsageSnapshot()
#expect(usageSnapshot.primary?.usedPercent == 0.0)
#expect(usageSnapshot.secondary?.usedPercent == 0.0)
}

@Test
Expand All @@ -262,7 +262,7 @@ struct KimiUsageSnapshotConversionTests {
updatedAt: now)

let usageSnapshot = snapshot.toUsageSnapshot()
#expect(usageSnapshot.primary?.usedPercent == 100.0)
#expect(usageSnapshot.secondary?.usedPercent == 100.0)
}
}

Expand Down
4 changes: 2 additions & 2 deletions Tests/CodexBarTests/StatusItemAnimationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -308,8 +308,8 @@ struct StatusItemAnimationTests {
statusBar: self.makeStatusBarForTesting())

let snapshot = UsageSnapshot(
primary: RateWindow(usedPercent: 12, windowMinutes: nil, resetsAt: nil, resetDescription: nil),
secondary: RateWindow(usedPercent: 42, windowMinutes: 300, resetsAt: nil, resetDescription: nil),
primary: RateWindow(usedPercent: 42, windowMinutes: 300, resetsAt: nil, resetDescription: nil),
secondary: RateWindow(usedPercent: 12, windowMinutes: nil, resetsAt: nil, resetDescription: nil),
updatedAt: Date())

store._setSnapshotForTesting(snapshot, provider: .kimi)
Expand Down
6 changes: 4 additions & 2 deletions Tests/CodexBarTests/UsageStoreCoverageTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,12 @@ struct UsageStoreCoverageTests {
secondary: nil,
updatedAt: now),
provider: .codex)
// With the fix, Kimi's primary is now rate limit and secondary is weekly.
// In automatic mode, Kimi uses primary like other providers.
store._setSnapshotForTesting(
UsageSnapshot(
primary: RateWindow(usedPercent: 10, windowMinutes: nil, resetsAt: nil, resetDescription: nil),
secondary: RateWindow(usedPercent: 80, windowMinutes: 300, resetsAt: nil, resetDescription: nil),
primary: RateWindow(usedPercent: 80, windowMinutes: 300, resetsAt: nil, resetDescription: nil),
secondary: RateWindow(usedPercent: 10, windowMinutes: nil, resetsAt: nil, resetDescription: nil),
updatedAt: now),
provider: .kimi)

Expand Down
8 changes: 5 additions & 3 deletions Tests/CodexBarTests/UsageStoreHighestUsageTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ struct UsageStoreHighestUsageTests {
}

@Test
func `automatic metric uses secondary for kimi when ranking highest usage`() {
func `automatic metric uses primary for kimi when ranking highest usage`() {
let settings = SettingsStore(
configStore: testConfigStore(suiteName: "UsageStoreHighestUsageTests-kimi-automatic"),
zaiTokenStore: NoopZaiTokenStore(),
Expand All @@ -104,9 +104,11 @@ struct UsageStoreHighestUsageTests {
primary: RateWindow(usedPercent: 70, windowMinutes: nil, resetsAt: nil, resetDescription: nil),
secondary: nil,
updatedAt: Date())
// With the fix, Kimi's primary is now rate limit (typically lower usage %)
// and secondary is weekly. In automatic mode, Kimi uses primary like other providers.
let kimiSnapshot = UsageSnapshot(
primary: RateWindow(usedPercent: 90, windowMinutes: nil, resetsAt: nil, resetDescription: nil),
secondary: RateWindow(usedPercent: 20, windowMinutes: nil, resetsAt: nil, resetDescription: nil),
primary: RateWindow(usedPercent: 20, windowMinutes: nil, resetsAt: nil, resetDescription: nil),
secondary: RateWindow(usedPercent: 90, windowMinutes: nil, resetsAt: nil, resetDescription: nil),
updatedAt: Date())

store._setSnapshotForTesting(codexSnapshot, provider: .codex)
Expand Down