cost-bubble 0.1.1 → 0.1.3
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/antigravity_context.py +83 -0
- package/build.sh +1 -1
- package/codex_sessions.py +20 -10
- package/package.json +2 -1
- package/session_cost.py +44 -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.3</string>
|
|
17
17
|
<key>CFBundleVersion</key>
|
|
18
|
-
<string>
|
|
18
|
+
<string>4</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.3 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. For Antigravity Desktop the limit comes from the matching request in the local conversation database. 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] {
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
"""Read a request's context limit from Antigravity Desktop's generation metadata."""
|
|
2
|
+
import sqlite3
|
|
3
|
+
|
|
4
|
+
from local_database import read_database
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
def _varint(data, offset):
|
|
8
|
+
value = 0
|
|
9
|
+
for shift in range(0, 70, 7):
|
|
10
|
+
if offset >= len(data):
|
|
11
|
+
break
|
|
12
|
+
byte = data[offset]
|
|
13
|
+
offset += 1
|
|
14
|
+
value |= (byte & 127) << shift
|
|
15
|
+
if byte < 128:
|
|
16
|
+
return value, offset
|
|
17
|
+
raise ValueError("Invalid protobuf varint")
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def _field(data, number, wire_type):
|
|
21
|
+
"""Skip unneeded fields without copying the request's prompt or messages."""
|
|
22
|
+
if data is None:
|
|
23
|
+
return None
|
|
24
|
+
offset = 0
|
|
25
|
+
while offset < len(data):
|
|
26
|
+
tag, offset = _varint(data, offset)
|
|
27
|
+
wire = tag & 7
|
|
28
|
+
if tag >> 3 == 0:
|
|
29
|
+
raise ValueError("Invalid protobuf tag")
|
|
30
|
+
if wire == 0:
|
|
31
|
+
value, offset = _varint(data, offset)
|
|
32
|
+
else:
|
|
33
|
+
if wire == 2:
|
|
34
|
+
length, offset = _varint(data, offset)
|
|
35
|
+
elif wire in (1, 5):
|
|
36
|
+
length = 8 if wire == 1 else 4
|
|
37
|
+
else:
|
|
38
|
+
raise ValueError("Unsupported protobuf wire type")
|
|
39
|
+
end = offset + length
|
|
40
|
+
if end > len(data):
|
|
41
|
+
raise ValueError("Incomplete protobuf field")
|
|
42
|
+
value, offset = data[offset:end], end
|
|
43
|
+
if tag >> 3 == number and wire == wire_type:
|
|
44
|
+
return value
|
|
45
|
+
return None
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def request_window(database, request_key):
|
|
49
|
+
if not database.is_file() or not request_key:
|
|
50
|
+
return None
|
|
51
|
+
needle = request_key.encode("utf-8")
|
|
52
|
+
# CodeBurn uses the row index when ModelUsageStats.response_id is absent.
|
|
53
|
+
index = int(request_key) if request_key.isascii() and request_key.isdecimal() and len(request_key) < 19 else -1
|
|
54
|
+
try:
|
|
55
|
+
with read_database(database) as conn:
|
|
56
|
+
rows = conn.execute("SELECT idx, data FROM gen_metadata "
|
|
57
|
+
"WHERE idx = ? OR instr(data, ?) > 0 ORDER BY idx DESC", (index, needle))
|
|
58
|
+
for idx, blob in rows:
|
|
59
|
+
if not isinstance(blob, bytes):
|
|
60
|
+
continue
|
|
61
|
+
try:
|
|
62
|
+
# CortexStepGeneratorMetadata.chat_model -> ChatModelMetadata.
|
|
63
|
+
chat = _field(memoryview(blob), 1, 2)
|
|
64
|
+
usage = _field(chat, 4, 2)
|
|
65
|
+
if not usage:
|
|
66
|
+
continue
|
|
67
|
+
raw = _field(usage, 11, 2)
|
|
68
|
+
response = bytes(raw).decode("utf-8") if raw else ""
|
|
69
|
+
key = response if response and not any(c.isspace() for c in response) else str(idx)
|
|
70
|
+
if key != request_key:
|
|
71
|
+
continue
|
|
72
|
+
# chat_start_metadata.context_window_metadata.max_context_tokens.
|
|
73
|
+
start = _field(chat, 9, 2)
|
|
74
|
+
metadata = _field(start, 10, 2)
|
|
75
|
+
limit = _field(metadata, 4, 0)
|
|
76
|
+
if limit is not None and 0 < limit <= 2**31 - 1:
|
|
77
|
+
return limit
|
|
78
|
+
return None
|
|
79
|
+
except ValueError:
|
|
80
|
+
continue
|
|
81
|
+
except (OSError, sqlite3.Error):
|
|
82
|
+
pass
|
|
83
|
+
return None
|
package/build.sh
CHANGED
|
@@ -8,6 +8,6 @@ target=${1:?Usage: ./build.sh /absolute/path/Cost Bubble.app}
|
|
|
8
8
|
mkdir -p "$target/Contents/MacOS" "$target/Contents/Resources"
|
|
9
9
|
xcrun swiftc -O -target "$(uname -m)-apple-macos14.0" Sources/*.swift -o "$target/Contents/MacOS/SessionHUD"
|
|
10
10
|
install -m 644 Info.plist "$target/Contents/Info.plist"
|
|
11
|
-
install -m 644 session_cost.py codex_sessions.py usage_activity.py reviewer_records.py local_database.py "$target/Contents/Resources/"
|
|
11
|
+
install -m 644 antigravity_context.py session_cost.py codex_sessions.py usage_activity.py reviewer_records.py local_database.py "$target/Contents/Resources/"
|
|
12
12
|
codesign --force --sign - "$target"
|
|
13
13
|
codesign --verify --strict "$target"
|
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
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cost-bubble",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
4
4
|
"description": "A macOS cost HUD for Codex, Claude Code and Antigravity.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -24,6 +24,7 @@
|
|
|
24
24
|
"Info.plist",
|
|
25
25
|
"Sources/",
|
|
26
26
|
"session_cost.py",
|
|
27
|
+
"antigravity_context.py",
|
|
27
28
|
"codex_sessions.py",
|
|
28
29
|
"usage_activity.py",
|
|
29
30
|
"reviewer_records.py",
|
package/session_cost.py
CHANGED
|
@@ -11,6 +11,7 @@ import subprocess
|
|
|
11
11
|
import sys
|
|
12
12
|
import uuid
|
|
13
13
|
|
|
14
|
+
import antigravity_context
|
|
14
15
|
import codex_sessions
|
|
15
16
|
from local_database import read_database
|
|
16
17
|
import usage_activity
|
|
@@ -162,15 +163,18 @@ def claude_detail(session):
|
|
|
162
163
|
"cache_creation_input_tokens")
|
|
163
164
|
if tokens is not None and tokens > 0:
|
|
164
165
|
result.update(context=tokens, model=msg.get("model"))
|
|
166
|
+
window = (msg.get("usage") or {}).get("context_window_size")
|
|
167
|
+
if type(window) is int and window > 0:
|
|
168
|
+
result["contextWindow"] = window
|
|
165
169
|
break
|
|
166
170
|
except (ValueError, TypeError, AttributeError):
|
|
167
171
|
continue
|
|
168
172
|
return result
|
|
169
173
|
|
|
170
174
|
|
|
171
|
-
def agy_detail(session):
|
|
175
|
+
def agy_detail(session, cascades=None):
|
|
172
176
|
result = {}
|
|
173
|
-
calls = agy_calls(session)
|
|
177
|
+
calls = agy_calls(session, cascades)
|
|
174
178
|
latest = None
|
|
175
179
|
for call in calls:
|
|
176
180
|
try:
|
|
@@ -183,18 +187,34 @@ def agy_detail(session):
|
|
|
183
187
|
call = latest[1]
|
|
184
188
|
result.update(context=token_sum(call, "inputTokens", "cacheReadInputTokens", "cacheCreationInputTokens"),
|
|
185
189
|
model=call.get("model"))
|
|
190
|
+
window = call.get("contextWindow")
|
|
191
|
+
if not (type(window) is int and window > 0) and valid_id(session):
|
|
192
|
+
key = call.get("deduplicationKey")
|
|
193
|
+
prefix = "antigravity:" + session + ":"
|
|
194
|
+
if isinstance(key, str) and key.startswith(prefix):
|
|
195
|
+
paths = [HOME / ".gemini" / app / "conversations" / (session + ".db")
|
|
196
|
+
for app in ("antigravity", "antigravity-cli", "antigravity-ide")]
|
|
197
|
+
matches = [path for path in paths if path.is_file()]
|
|
198
|
+
if len(matches) == 1:
|
|
199
|
+
window = antigravity_context.request_window(matches[0], key[len(prefix):])
|
|
200
|
+
if type(window) is int and window > 0:
|
|
201
|
+
result["contextWindow"] = window
|
|
186
202
|
return result
|
|
187
203
|
|
|
188
204
|
|
|
189
|
-
def
|
|
205
|
+
def agy_cascades():
|
|
190
206
|
folder = Path(os.environ.get("CODEBURN_CACHE_DIR") or HOME / ".cache/codeburn")
|
|
191
207
|
cache = folder / "antigravity-results.v11.json"
|
|
192
208
|
if not cache.is_file():
|
|
193
|
-
return
|
|
209
|
+
return {}
|
|
194
210
|
data = json.loads(cache.read_bytes())
|
|
195
|
-
if data.get("version")
|
|
196
|
-
|
|
197
|
-
|
|
211
|
+
return data.get("cascades", {}) if data.get("version") == 11 else {}
|
|
212
|
+
|
|
213
|
+
|
|
214
|
+
def agy_calls(session, cascades=None):
|
|
215
|
+
if cascades is None:
|
|
216
|
+
cascades = agy_cascades()
|
|
217
|
+
calls = cascades.get(session, {}).get("calls", [])
|
|
198
218
|
return [call for call in calls if call.get("provider") == "antigravity"
|
|
199
219
|
and call.get("sessionId") == session and not call.get("costIsEstimated")]
|
|
200
220
|
|
|
@@ -328,16 +348,23 @@ def main():
|
|
|
328
348
|
if sys.argv[1:2] == ["--spend"] and len(sys.argv) == 4:
|
|
329
349
|
provider, session = sys.argv[2:]
|
|
330
350
|
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
|
-
|
|
351
|
+
if sys.argv[1:2] in (["--details"], ["--detail"]) and len(sys.argv) >= 4:
|
|
352
|
+
provider = sys.argv[2]
|
|
353
|
+
results = {}
|
|
354
|
+
cascades = agy_cascades() if provider == "antigravity" else None
|
|
355
|
+
for session in dict.fromkeys(sys.argv[3:]):
|
|
356
|
+
if not valid_id(session):
|
|
357
|
+
continue
|
|
358
|
+
try:
|
|
359
|
+
if provider == "codex":
|
|
360
|
+
results[session] = codex_sessions.detail(codex_sessions.codex_home(), session)
|
|
361
|
+
elif provider == "claude":
|
|
362
|
+
results[session] = claude_detail(session)
|
|
363
|
+
elif provider == "antigravity":
|
|
364
|
+
results[session] = agy_detail(session, cascades)
|
|
365
|
+
except (OSError, ValueError, sqlite3.Error):
|
|
366
|
+
continue
|
|
367
|
+
return results if sys.argv[1] == "--details" else results.get(sys.argv[3], {})
|
|
341
368
|
if sys.argv[1:2] == ["--list"] and len(sys.argv) >= 4:
|
|
342
369
|
provider, route = sys.argv[2:4]
|
|
343
370
|
extra_ids = {key for key in sys.argv[4:] if valid_id(key)}
|