cost-bubble 0.1.2 → 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 CHANGED
@@ -13,9 +13,9 @@
13
13
  <key>CFBundlePackageType</key>
14
14
  <string>APPL</string>
15
15
  <key>CFBundleShortVersionString</key>
16
- <string>0.1.2</string>
16
+ <string>0.1.3</string>
17
17
  <key>CFBundleVersion</key>
18
- <string>3</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
@@ -16,7 +16,7 @@ This installs the Cost Bubble app, its CodeBurn pricing reader and its login ite
16
16
 
17
17
  Prefer a globally installed command? Run `npm install --global cost-bubble`, then `cost-bubble install`.
18
18
 
19
- You can also install the pinned GitHub release with `npx --allow-git=root github:anopows/cost-bubble#v0.1.2 install`.
19
+ You can also install the pinned GitHub release with `npx --allow-git=root github:anopows/cost-bubble#v0.1.3 install`.
20
20
 
21
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.
22
22
 
@@ -38,7 +38,7 @@ launchctl kickstart -k "gui/$(id -u)/io.github.anopows.cost-bubble"
38
38
  | --- | --- |
39
39
  | Hover over the pill | The arrow marks your open chat. The list initially includes other chats active today among the 12 most recent. |
40
40
  | Click a chat title | Opens the chat in the same desktop app. Antigravity leaves the picker open if several titles match. |
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. |
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. |
42
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. |
43
43
  | Click the total | Switches between today and lifetime. The total covers listed chats with estimates. |
44
44
  | Drag the pill or use − / + | Moves or resizes it. Each app remembers its own position. |
@@ -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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cost-bubble",
3
- "version": "0.1.2",
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
@@ -187,6 +188,15 @@ def agy_detail(session, cascades=None):
187
188
  result.update(context=token_sum(call, "inputTokens", "cacheReadInputTokens", "cacheCreationInputTokens"),
188
189
  model=call.get("model"))
189
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):])
190
200
  if type(window) is int and window > 0:
191
201
  result["contextWindow"] = window
192
202
  return result