cost-bubble 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Info.plist +2 -2
- package/README.md +5 -3
- package/Sources/ChatLine.swift +15 -5
- package/Sources/CostBreakdown.swift +5 -0
- package/Sources/HUDController.swift +5 -6
- package/Sources/SessionData.swift +12 -2
- package/Sources/SessionUpdates.swift +17 -10
- package/codex_sessions.py +20 -10
- package/package.json +1 -1
- package/session_cost.py +34 -17
package/Info.plist
CHANGED
|
@@ -13,9 +13,9 @@
|
|
|
13
13
|
<key>CFBundlePackageType</key>
|
|
14
14
|
<string>APPL</string>
|
|
15
15
|
<key>CFBundleShortVersionString</key>
|
|
16
|
-
<string>0.1.
|
|
16
|
+
<string>0.1.2</string>
|
|
17
17
|
<key>CFBundleVersion</key>
|
|
18
|
-
<string>
|
|
18
|
+
<string>3</string>
|
|
19
19
|
<key>LSMinimumSystemVersion</key>
|
|
20
20
|
<string>14.0</string>
|
|
21
21
|
<key>LSUIElement</key>
|
package/README.md
CHANGED
|
@@ -6,7 +6,7 @@ See the estimated cost of the chat you have open in Codex, Claude Code or Antigr
|
|
|
6
6
|
|
|
7
7
|
## Install on macOS 14 or later
|
|
8
8
|
|
|
9
|
-
With Node.js 22.15 or later and Apple’s Command Line Tools installed, run
|
|
9
|
+
With Node.js 22.15 or later and Apple’s Command Line Tools installed, run the [npm installer](https://www.npmjs.com/package/cost-bubble) in Terminal:
|
|
10
10
|
|
|
11
11
|
```sh
|
|
12
12
|
npx cost-bubble@latest install
|
|
@@ -14,7 +14,9 @@ npx cost-bubble@latest install
|
|
|
14
14
|
|
|
15
15
|
This installs the Cost Bubble app, its CodeBurn pricing reader and its login item for your Mac account. Once it launches, enable **Cost Bubble** under **System Settings → Privacy & Security → Accessibility** and open a supported chat.
|
|
16
16
|
|
|
17
|
-
Prefer a globally installed command? Run `npm install --global cost-bubble`, then `cost-bubble install`.
|
|
17
|
+
Prefer a globally installed command? Run `npm install --global cost-bubble`, then `cost-bubble install`.
|
|
18
|
+
|
|
19
|
+
You can also install the pinned GitHub release with `npx --allow-git=root github:anopows/cost-bubble#v0.1.2 install`.
|
|
18
20
|
|
|
19
21
|
If you need the prerequisites, [install Node.js](https://nodejs.org/), then run `xcode-select --install` and let it finish. The installer builds and signs the app locally. To install from source, download and extract the [release archive](https://github.com/anopows/cost-bubble/releases), then run `./install.sh --with-codeburn` in the extracted folder.
|
|
20
22
|
|
|
@@ -36,7 +38,7 @@ launchctl kickstart -k "gui/$(id -u)/io.github.anopows.cost-bubble"
|
|
|
36
38
|
| --- | --- |
|
|
37
39
|
| Hover over the pill | The arrow marks your open chat. The list initially includes other chats active today among the 12 most recent. |
|
|
38
40
|
| Click a chat title | Opens the chat in the same desktop app. Antigravity leaves the picker open if several titles match. |
|
|
39
|
-
| Hover over the token bars | Shows the latest
|
|
41
|
+
| Hover over the token bars | Shows the latest request’s input tokens, including cached input. Bar fill shows the fraction of the reported context window used by those tokens. When the provider omits the limit, the bars stay gray and hover still shows the recorded count. |
|
|
40
42
|
| Hover over a price | Compares the last five minutes and hour, shows the input/output share, and separates cache reads and writes. The lifetime row compares the latest, average and peak request or turn. Click to keep the breakdown open. |
|
|
41
43
|
| Click the total | Switches between today and lifetime. The total covers listed chats with estimates. |
|
|
42
44
|
| Drag the pill or use − / + | Moves or resizes it. Each app remembers its own position. |
|
package/Sources/ChatLine.swift
CHANGED
|
@@ -3,15 +3,24 @@ import ApplicationServices
|
|
|
3
3
|
|
|
4
4
|
final class SignalBars: NSView {
|
|
5
5
|
var agentCount = 0 { didSet { if oldValue != agentCount { needsDisplay = true } } }
|
|
6
|
-
var
|
|
6
|
+
var contextFraction: Double? { didSet { if oldValue != contextFraction { needsDisplay = true } } }
|
|
7
7
|
override func draw(_ dirtyRect: NSRect) {
|
|
8
8
|
let unit = bounds.width / 17
|
|
9
9
|
for index in 0..<4 {
|
|
10
10
|
let height = CGFloat(4 + index * 3) * unit
|
|
11
|
-
|
|
12
|
-
fill.setFill()
|
|
11
|
+
NSColor.white.withAlphaComponent(0.18).setFill()
|
|
13
12
|
let rect = NSRect(x: CGFloat(index) * 4.5 * unit, y: agentCount > 0 ? 4 * unit : unit, width: 2.8 * unit, height: agentCount > 0 ? height * 0.78 : height)
|
|
14
|
-
NSBezierPath(roundedRect: rect, xRadius: unit, yRadius: unit)
|
|
13
|
+
let shape = NSBezierPath(roundedRect: rect, xRadius: unit, yRadius: unit)
|
|
14
|
+
shape.fill()
|
|
15
|
+
let portion = min(1, max(0, (contextFraction ?? 0) * 4 - Double(index)))
|
|
16
|
+
if portion > 0 {
|
|
17
|
+
NSGraphicsContext.saveGraphicsState()
|
|
18
|
+
NSBezierPath(rect: NSRect(x: rect.minX, y: rect.minY, width: rect.width,
|
|
19
|
+
height: rect.height * CGFloat(portion))).addClip()
|
|
20
|
+
NSColor.systemCyan.setFill()
|
|
21
|
+
shape.fill()
|
|
22
|
+
NSGraphicsContext.restoreGraphicsState()
|
|
23
|
+
}
|
|
15
24
|
}
|
|
16
25
|
NSColor.systemPurple.setFill()
|
|
17
26
|
for index in 0..<min(4, agentCount) {
|
|
@@ -64,8 +73,9 @@ final class ChatLine: NSView {
|
|
|
64
73
|
label.textColor = row.current ? .white : NSColor.white.withAlphaComponent(0.73)
|
|
65
74
|
label.toolTip = row.title
|
|
66
75
|
bars.agentCount = row.agentCount
|
|
67
|
-
bars.
|
|
76
|
+
bars.contextFraction = row.contextFraction
|
|
68
77
|
bars.setAccessibilityLabel(row.agentCount == 0 ? "Session tokens" : "Session tokens, \(row.agentCount) subagents")
|
|
78
|
+
bars.setAccessibilityValue(row.contextFraction?.formatted(.percent) ?? "Context window unavailable")
|
|
69
79
|
bars.setAccessibilityElement(true)
|
|
70
80
|
tokenLabel.font = .monospacedDigitSystemFont(ofSize: 12*zoom, weight: .semibold)
|
|
71
81
|
arrow.isHidden = !row.current
|
|
@@ -10,6 +10,7 @@ struct CostBreakdown: Equatable {
|
|
|
10
10
|
let title: String
|
|
11
11
|
let total: String
|
|
12
12
|
let model: String?
|
|
13
|
+
var windowDescription: String?
|
|
13
14
|
var calls: String?
|
|
14
15
|
var windows: [BreakdownMetric] = []
|
|
15
16
|
var tokens: [BreakdownMetric] = []
|
|
@@ -126,6 +127,10 @@ final class BreakdownView: NSView {
|
|
|
126
127
|
y += 28
|
|
127
128
|
}
|
|
128
129
|
} else { y += 28 }
|
|
130
|
+
if let window = next.windowDescription {
|
|
131
|
+
text(window, inset, y, inner, 12, .medium, cyan, label: "Context window")
|
|
132
|
+
y += 17
|
|
133
|
+
}
|
|
129
134
|
if !next.windows.isEmpty { y += 3; grid(next.windows) }
|
|
130
135
|
if !next.tokens.isEmpty || !next.cache.isEmpty {
|
|
131
136
|
divider()
|
|
@@ -171,14 +171,13 @@ final class Controller: NSObject, NSApplicationDelegate {
|
|
|
171
171
|
updateHover()
|
|
172
172
|
return
|
|
173
173
|
}
|
|
174
|
+
refreshTokenDetails(provider, chats: chats)
|
|
174
175
|
let rows = chats.map { chat -> DisplayRow in
|
|
175
176
|
let stats = displayedPrices?[chat.id]
|
|
176
177
|
let amount = stats?.displayCost ?? formattedCost(nil, pending: displayedPrices == nil)
|
|
177
|
-
let
|
|
178
|
-
let strength = age.map { secs in [300.0, 900, 3600, 86400].filter { secs < $0 }.count } ?? 0
|
|
179
|
-
let activity = age.map { "Last active " + RelativeDateTimeFormatter().localizedString(fromTimeInterval: -$0) } ?? "Activity time unavailable"
|
|
178
|
+
let fraction = tokenDetails[provider + "/" + chat.id]?.detail?.fraction
|
|
180
179
|
return DisplayRow(amount: amount, title: chat.title, tooltip: usageTip(stats, amount: amount),
|
|
181
|
-
current: chat.id == scope,
|
|
180
|
+
current: chat.id == scope, contextFraction: fraction, agentCount: helpers(provider, chat.id).filter { !$0.reviewer }.count)
|
|
182
181
|
}
|
|
183
182
|
let h = expanded ? (32*z).rounded()+rowH*CGFloat(rows.count) : pillFrame.height + rowH * CGFloat(rows.count-1)
|
|
184
183
|
let idealTop = pillFrame.midY + (26*z).rounded() + rowH/2
|
|
@@ -274,7 +273,7 @@ final class Controller: NSObject, NSApplicationDelegate {
|
|
|
274
273
|
}
|
|
275
274
|
let chat = chats[index]
|
|
276
275
|
let stats = (todayPrices ? dailyReports : reports)[provider]?[chat.id]
|
|
277
|
-
let detail =
|
|
276
|
+
let detail = tokenDetails[provider + "/" + chat.id]?.detail
|
|
278
277
|
if index == hovered {
|
|
279
278
|
let line = lines[index]
|
|
280
279
|
let inline = inlineTokens(detail, helpers: helpers(provider, chat.id), loading: detailPending.contains(provider + "/" + chat.id))
|
|
@@ -283,7 +282,7 @@ final class Controller: NSObject, NSApplicationDelegate {
|
|
|
283
282
|
let content: CostBreakdown
|
|
284
283
|
if index == hovered {
|
|
285
284
|
content = CostBreakdown(title: "Latest request input tokens", total: detail?.context?.formatted() ?? "—",
|
|
286
|
-
model: detail?.model)
|
|
285
|
+
model: detail?.model, windowDescription: detail?.windowDescription ?? "Context window unavailable")
|
|
287
286
|
} else {
|
|
288
287
|
let spend = provider == "claude" ? requestSpend(provider, chat: chat) : activity[provider]?[chat.id]
|
|
289
288
|
let other = (todayPrices ? reports : dailyReports)[provider]
|
|
@@ -39,6 +39,17 @@ struct Usage: Decodable {
|
|
|
39
39
|
struct TokenDetail: Decodable {
|
|
40
40
|
let context: Int?
|
|
41
41
|
let model: String?
|
|
42
|
+
let contextWindow: Int?
|
|
43
|
+
|
|
44
|
+
var fraction: Double? {
|
|
45
|
+
guard let context, context >= 0, let contextWindow, contextWindow > 0 else { return nil }
|
|
46
|
+
return min(1, Double(context) / Double(contextWindow))
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
var windowDescription: String {
|
|
50
|
+
guard let fraction, let contextWindow else { return "Context window unavailable" }
|
|
51
|
+
return "\(fraction.formatted(.percent.precision(.fractionLength(0)))) of \(contextWindow.formatted()) tokens"
|
|
52
|
+
}
|
|
42
53
|
}
|
|
43
54
|
|
|
44
55
|
struct RecentChat: Decodable, Equatable {
|
|
@@ -53,9 +64,8 @@ struct DisplayRow: Equatable {
|
|
|
53
64
|
let title: String
|
|
54
65
|
let tooltip: String
|
|
55
66
|
let current: Bool
|
|
56
|
-
let
|
|
67
|
+
let contextFraction: Double?
|
|
57
68
|
let agentCount: Int
|
|
58
|
-
let activity: String
|
|
59
69
|
}
|
|
60
70
|
|
|
61
71
|
func usageTip(_ usage: Usage?, amount: String) -> String {
|
|
@@ -118,20 +118,27 @@ extension Controller {
|
|
|
118
118
|
return cached?.value
|
|
119
119
|
}
|
|
120
120
|
|
|
121
|
-
func
|
|
122
|
-
let
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
121
|
+
func refreshTokenDetails(_ provider: String, chats: [RecentChat]) {
|
|
122
|
+
let now = Date()
|
|
123
|
+
let missing = chats.filter { chat in
|
|
124
|
+
let key = provider + "/" + chat.id
|
|
125
|
+
let age = now.timeIntervalSince(tokenDetails[key]?.time ?? .distantPast)
|
|
126
|
+
return age >= (chat.id == scope ? 12 : 60) && !detailPending.contains(key)
|
|
127
|
+
}
|
|
128
|
+
guard !missing.isEmpty else { return }
|
|
129
|
+
let ids = missing.map(\.id)
|
|
130
|
+
for id in ids { detailPending.insert(provider + "/" + id) }
|
|
131
|
+
DispatchQueue.global(qos: .utility).async {
|
|
132
|
+
let values: [String: TokenDetail]? = readSnapshot(["--details", provider] + ids)
|
|
133
|
+
DispatchQueue.main.async {
|
|
134
|
+
for id in ids {
|
|
135
|
+
let key = provider + "/" + id
|
|
128
136
|
self.detailPending.remove(key)
|
|
129
|
-
self.tokenDetails[key] = (Date(),
|
|
130
|
-
self.updateHover()
|
|
137
|
+
self.tokenDetails[key] = (Date(), values?[id] ?? self.tokenDetails[key]?.detail)
|
|
131
138
|
}
|
|
139
|
+
if self.activeProvider == provider { self.updateHover() }
|
|
132
140
|
}
|
|
133
141
|
}
|
|
134
|
-
return tokenDetails[key]?.detail
|
|
135
142
|
}
|
|
136
143
|
|
|
137
144
|
func helpers(_ provider: String, _ id: String) -> [SessionHelper] {
|
package/codex_sessions.py
CHANGED
|
@@ -115,22 +115,32 @@ def detail(home, session):
|
|
|
115
115
|
stream.seek(offset)
|
|
116
116
|
if offset:
|
|
117
117
|
stream.readline()
|
|
118
|
-
|
|
119
|
-
|
|
118
|
+
turn = window = None
|
|
119
|
+
for line in stream:
|
|
120
|
+
if not any(marker in line for marker in (b'"token_usage_record"', b'"token_count"', b'"task_started"', b'"turn_context"')):
|
|
120
121
|
continue
|
|
121
122
|
try:
|
|
122
123
|
event = json.loads(line)
|
|
123
124
|
payload = event.get("payload") or {}
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
usage = (payload.get("info") or {}).get("last_token_usage") or {}
|
|
128
|
-
else:
|
|
125
|
+
kind = event.get("type")
|
|
126
|
+
event_kind = payload.get("type") if kind == "event_msg" else None
|
|
127
|
+
if kind not in ("turn_context", "token_usage_record") and event_kind not in ("task_started", "token_count"):
|
|
129
128
|
continue
|
|
130
|
-
|
|
131
|
-
if
|
|
129
|
+
turn_id = payload.get("turn_id")
|
|
130
|
+
if turn_id and turn_id != turn:
|
|
131
|
+
turn, window = turn_id, None
|
|
132
|
+
info = (payload.get("info") or {}) if event_kind == "token_count" else payload
|
|
133
|
+
limit = info.get("model_context_window")
|
|
134
|
+
if type(limit) is int and limit > 0:
|
|
135
|
+
window = limit
|
|
136
|
+
usage = payload.get("usage") if kind == "token_usage_record" else info.get("last_token_usage")
|
|
137
|
+
count = (usage or {}).get("input_tokens")
|
|
138
|
+
if type(count) is int and count >= 0:
|
|
132
139
|
result["context"] = count
|
|
133
|
-
|
|
140
|
+
if window:
|
|
141
|
+
result["contextWindow"] = window
|
|
142
|
+
else:
|
|
143
|
+
result.pop("contextWindow", None)
|
|
134
144
|
except (ValueError, AttributeError):
|
|
135
145
|
continue
|
|
136
146
|
return result
|
package/package.json
CHANGED
package/session_cost.py
CHANGED
|
@@ -162,15 +162,18 @@ def claude_detail(session):
|
|
|
162
162
|
"cache_creation_input_tokens")
|
|
163
163
|
if tokens is not None and tokens > 0:
|
|
164
164
|
result.update(context=tokens, model=msg.get("model"))
|
|
165
|
+
window = (msg.get("usage") or {}).get("context_window_size")
|
|
166
|
+
if type(window) is int and window > 0:
|
|
167
|
+
result["contextWindow"] = window
|
|
165
168
|
break
|
|
166
169
|
except (ValueError, TypeError, AttributeError):
|
|
167
170
|
continue
|
|
168
171
|
return result
|
|
169
172
|
|
|
170
173
|
|
|
171
|
-
def agy_detail(session):
|
|
174
|
+
def agy_detail(session, cascades=None):
|
|
172
175
|
result = {}
|
|
173
|
-
calls = agy_calls(session)
|
|
176
|
+
calls = agy_calls(session, cascades)
|
|
174
177
|
latest = None
|
|
175
178
|
for call in calls:
|
|
176
179
|
try:
|
|
@@ -183,18 +186,25 @@ def agy_detail(session):
|
|
|
183
186
|
call = latest[1]
|
|
184
187
|
result.update(context=token_sum(call, "inputTokens", "cacheReadInputTokens", "cacheCreationInputTokens"),
|
|
185
188
|
model=call.get("model"))
|
|
189
|
+
window = call.get("contextWindow")
|
|
190
|
+
if type(window) is int and window > 0:
|
|
191
|
+
result["contextWindow"] = window
|
|
186
192
|
return result
|
|
187
193
|
|
|
188
194
|
|
|
189
|
-
def
|
|
195
|
+
def agy_cascades():
|
|
190
196
|
folder = Path(os.environ.get("CODEBURN_CACHE_DIR") or HOME / ".cache/codeburn")
|
|
191
197
|
cache = folder / "antigravity-results.v11.json"
|
|
192
198
|
if not cache.is_file():
|
|
193
|
-
return
|
|
199
|
+
return {}
|
|
194
200
|
data = json.loads(cache.read_bytes())
|
|
195
|
-
if data.get("version")
|
|
196
|
-
|
|
197
|
-
|
|
201
|
+
return data.get("cascades", {}) if data.get("version") == 11 else {}
|
|
202
|
+
|
|
203
|
+
|
|
204
|
+
def agy_calls(session, cascades=None):
|
|
205
|
+
if cascades is None:
|
|
206
|
+
cascades = agy_cascades()
|
|
207
|
+
calls = cascades.get(session, {}).get("calls", [])
|
|
198
208
|
return [call for call in calls if call.get("provider") == "antigravity"
|
|
199
209
|
and call.get("sessionId") == session and not call.get("costIsEstimated")]
|
|
200
210
|
|
|
@@ -328,16 +338,23 @@ def main():
|
|
|
328
338
|
if sys.argv[1:2] == ["--spend"] and len(sys.argv) == 4:
|
|
329
339
|
provider, session = sys.argv[2:]
|
|
330
340
|
return session_spend(provider, session) if provider in ("claude", "antigravity") and valid_id(session) else {}
|
|
331
|
-
if sys.argv[1:2]
|
|
332
|
-
provider
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
if
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
+
if sys.argv[1:2] in (["--details"], ["--detail"]) and len(sys.argv) >= 4:
|
|
342
|
+
provider = sys.argv[2]
|
|
343
|
+
results = {}
|
|
344
|
+
cascades = agy_cascades() if provider == "antigravity" else None
|
|
345
|
+
for session in dict.fromkeys(sys.argv[3:]):
|
|
346
|
+
if not valid_id(session):
|
|
347
|
+
continue
|
|
348
|
+
try:
|
|
349
|
+
if provider == "codex":
|
|
350
|
+
results[session] = codex_sessions.detail(codex_sessions.codex_home(), session)
|
|
351
|
+
elif provider == "claude":
|
|
352
|
+
results[session] = claude_detail(session)
|
|
353
|
+
elif provider == "antigravity":
|
|
354
|
+
results[session] = agy_detail(session, cascades)
|
|
355
|
+
except (OSError, ValueError, sqlite3.Error):
|
|
356
|
+
continue
|
|
357
|
+
return results if sys.argv[1] == "--details" else results.get(sys.argv[3], {})
|
|
341
358
|
if sys.argv[1:2] == ["--list"] and len(sys.argv) >= 4:
|
|
342
359
|
provider, route = sys.argv[2:4]
|
|
343
360
|
extra_ids = {key for key in sys.argv[4:] if valid_id(key)}
|