agy-statusblocks 0.1.5 → 0.1.6

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.
@@ -7,21 +7,43 @@ function formatTokens(n) {
7
7
  return `${Math.round(safe / 1000)}K`;
8
8
  return String(safe);
9
9
  }
10
+ function resolveContextUsage(total, rawPct, inTokens, outTokens) {
11
+ if (rawPct != null && rawPct > 0) {
12
+ const inPct = total > 0 ? (inTokens / total) * 100 : 0;
13
+ const sumPct = total > 0 ? ((inTokens + outTokens) / total) * 100 : 0;
14
+ const inDiff = Math.abs(inPct - rawPct);
15
+ const sumDiff = Math.abs(sumPct - rawPct);
16
+ let used;
17
+ if (inTokens > 0 && inDiff <= sumDiff && inDiff <= 1) {
18
+ // Antigravity sets total_input_tokens = estimated_tokens_used and
19
+ // used_percentage = (estimated_tokens_used / context_window_size) * 100,
20
+ // while leaving total_output_tokens as cumulative lifetime session output.
21
+ used = inTokens;
22
+ }
23
+ else if (inTokens + outTokens > 0 && sumDiff <= 1) {
24
+ // Fallback step-sum mode where used_percentage reflects inTokens + outTokens.
25
+ used = inTokens + outTokens;
26
+ }
27
+ else {
28
+ // Only used_percentage is reliable/present; derive used token count from it.
29
+ used = Math.round((rawPct / 100) * total);
30
+ }
31
+ const pct = Math.min(100, Math.max(0, Math.round(rawPct)));
32
+ return { pct, used };
33
+ }
34
+ const used = inTokens + outTokens;
35
+ const pct = total > 0 ? Math.min(100, Math.max(0, Math.round((used / total) * 100))) : 0;
36
+ return { pct, used };
37
+ }
10
38
  export const contextSegment = {
11
39
  id: 'context',
12
40
  priority: 10,
13
41
  enabled: () => true,
14
42
  render(data) {
15
43
  const total = data.context_window.context_window_size || 1048576;
16
- let pct = data.context_window.used_percentage != null
17
- ? Math.floor(data.context_window.used_percentage)
18
- : 0;
19
44
  const inTokens = data.context_window.total_input_tokens ?? 0;
20
45
  const outTokens = data.context_window.total_output_tokens ?? 0;
21
- const used = inTokens + outTokens;
22
- if (pct === 0 && used > 0 && total > 0) {
23
- pct = Math.floor((used / total) * 100);
24
- }
46
+ const { pct, used } = resolveContextUsage(total, data.context_window.used_percentage, inTokens, outTokens);
25
47
  const barColor = pctColor(pct);
26
48
  const info = `${color(`${pct}%`, barColor, c.bold)}${color(' · ', c.dim)}${color(`${formatTokens(used)}/${formatTokens(total)}`, c.dim)}`;
27
49
  const cardWidth = Math.max(16, visibleLength(info));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agy-statusblocks",
3
- "version": "0.1.5",
3
+ "version": "0.1.6",
4
4
  "description": "Opinionated, adaptive block-based status line for Antigravity CLI (agy) with bin-packing layout, rate limit tracking, and live agent telemetry",
5
5
  "type": "module",
6
6
  "bin": {