Skip to content
Closed
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: 2 additions & 0 deletions Sources/CodexBarCLI/CLIHelp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ extension CodexBarCLI {

Description:
Print local token cost usage from Claude/Codex native logs plus supported pi and OMP sessions.
Pi provider usage is attributed to its CodexBar counterpart (Codex, Claude, DeepSeek, Gemini, xAI, ...)
and uses pi's reported per-message cost when available.
This does not require web or CLI access and uses cached scan results unless --refresh is provided.

Examples:
Expand Down
2 changes: 1 addition & 1 deletion Sources/CodexBarCore/CostUsageFetcher.swift
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ public struct CostUsageFetcher: Sendable {
modelsDevCacheRoot: scanOptions.cacheRoot,
sessionRoots: roots)
}
if includePiSessions, provider == .claude || (provider == .codex && shouldMergePiUsage) {
if includePiSessions, PiSessionCostScanner.mappedTargetProviders.contains(provider), shouldMergePiUsage {
let piReport = try PiSessionCostScanner.loadDailyReportCancellable(
Comment on lines +337 to 338

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Merge Bedrock pi usage before returning remote costs

For every Bedrock request, loadRemoteTokenSnapshot constructs a non-nil snapshot and the caller returns it at lines 238-245, so execution never reaches this new merge branch. Consequently, includePiSessions: true still omits all amazon-bedrock pi/OMP sessions from Bedrock cost output; the remote Bedrock report needs to be combined with the pi report rather than returned early.

Useful? React with 👍 / 👎.

provider: provider,
since: since,
Expand Down
4 changes: 2 additions & 2 deletions Sources/CodexBarCore/PiSessionCostCache.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import Foundation

enum PiSessionCostCacheIO {
/// Artifact schema version. Pricing changes are tracked separately by `pricingKey`.
private static let artifactVersion = 8
private static let artifactVersion = 9

private static func defaultCacheRoot() -> URL {
let root = FileManager.default.urls(for: .cachesDirectory, in: .userDomainMask).first!
Expand Down Expand Up @@ -63,7 +63,7 @@ struct PiSessionCostCache: Codable {
var daysByProvider: [String: [String: [String: PiPackedUsage]]] = [:]
var files: [String: PiSessionFileUsage] = [:]

init(version: Int = 8) {
init(version: Int = 9) {
self.version = version
}
}
Expand Down
285 changes: 237 additions & 48 deletions Sources/CodexBarCore/PiSessionCostScanner.swift

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Tests/CodexBarTests/CostUsageCacheTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ struct CostUsageCacheTests {

let loaded = PiSessionCostCacheIO.load(cacheRoot: root)

#expect(loaded.version == 8)
#expect(loaded.version == 9)
#expect(loaded.lastScanUnixMs == 0)
#expect(loaded.files.isEmpty)
}
Expand Down
Loading