ai-battery 0.1.28 → 0.2.0

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.
@@ -18,7 +18,8 @@ function shellArg(value) {
18
18
 
19
19
  const PROVIDER_EXECUTABLE_RE = {
20
20
  codex: /^codex(?:\.(?:cmd|exe|bat|js|mjs|cjs))?$/i,
21
- claude: /^(?:claude|claude-code)(?:\.(?:cmd|exe|bat|js|mjs|cjs))?$/i
21
+ claude: /^(?:claude|claude-code)(?:\.(?:cmd|exe|bat|js|mjs|cjs))?$/i,
22
+ antigravity: /^agy(?:\.(?:cmd|exe|bat|js|mjs|cjs))?$/i
22
23
  };
23
24
  const PROVIDER_PACKAGE_MARKERS = {
24
25
  codex: ["@openai/codex"],
@@ -0,0 +1,41 @@
1
+ import fs from "node:fs";
2
+ import { execFileSync } from "node:child_process";
3
+ import { isWsl } from "./runtime.js";
4
+
5
+ const neutral = value => /^(?:c|posix)(?:[.@_-]|$)/i.test(value || "");
6
+
7
+ export function detectSystemUiLocale({ platform = process.platform, wsl = isWsl(), run = execFileSync, read = fs.readFileSync } = {}) {
8
+ const options = { encoding: "utf8", stdio: ["ignore", "pipe", "ignore"], timeout: 1500, windowsHide: true };
9
+ if (platform === "win32" || wsl) {
10
+ try {
11
+ const output = run("powershell.exe", ["-NoProfile", "-NonInteractive", "-Command", "[Globalization.CultureInfo]::CurrentUICulture.Name"], options);
12
+ const locale = String(output).replace(/^\uFEFF/, "").trim().split(/\r?\n/).find(line => /^[a-z]{2,3}(?:-[a-z0-9]+)*$/i.test(line));
13
+ if (locale) return locale;
14
+ } catch { /* Fall back when Windows interop or PowerShell is unavailable. */ }
15
+ }
16
+ if (platform === "darwin") {
17
+ try {
18
+ const output = run("defaults", ["read", "-g", "AppleLanguages"], options);
19
+ const locale = String(output).match(/[a-z]{2,3}(?:-[a-z0-9]+)*/i)?.[0];
20
+ if (locale) return locale;
21
+ } catch { /* Use the runtime locale if no UI preference is available. */ }
22
+ }
23
+ if (platform === "linux" && !wsl) {
24
+ for (const file of ["/etc/locale.conf", "/etc/default/locale"]) {
25
+ try {
26
+ const text = read(file, "utf8");
27
+ for (const key of ["LC_MESSAGES", "LANG"]) {
28
+ const value = String(text).match(new RegExp(`^\\s*(?:export\\s+)?${key}=["']?([^"'\\s]+)`, "m"))?.[1];
29
+ if (value && !neutral(value)) return value;
30
+ }
31
+ } catch { /* Not every distribution has both files. */ }
32
+ }
33
+ }
34
+ return null;
35
+ }
36
+
37
+ let cachedLocale;
38
+ export function systemUiLocale() {
39
+ cachedLocale ??= detectSystemUiLocale() || Intl.DateTimeFormat().resolvedOptions().locale;
40
+ return cachedLocale;
41
+ }
@@ -29,7 +29,7 @@ const UNSAFE_CMD_ARGUMENT_RE = /[\r\n&|<>^%!()]/;
29
29
  const UNSAFE_CMD_PATH_RE = /[\r\n&|<>^%!]/;
30
30
 
31
31
  function usage() {
32
- console.log(`Usage: ai-battery-run-win [--interval SECONDS] [--bar-width N] [--provider auto|all|codex|claude] [--layout fullscreen|hud|plain|tui|inline|auto|composite|reserve|overlay] [--left-padding N] -- COMMAND [ARGS...]
32
+ console.log(`Usage: ai-battery-run-win [--interval SECONDS] [--bar-width N] [--provider auto|all|codex|claude|antigravity] [--layout fullscreen|hud|plain|tui|inline|auto|composite|reserve|overlay] [--left-padding N] -- COMMAND [ARGS...]
33
33
 
34
34
  Runs COMMAND with an AI Battery display.
35
35
  Default layout "composite" renders Codex above a terminal battery row.
@@ -81,8 +81,8 @@ function parseArgs(argv) {
81
81
  args.barWidth = argv[++i] || args.barWidth;
82
82
  } else if (arg === "--provider") {
83
83
  args.provider = argv[++i] || args.provider;
84
- if (!["auto", "all", "codex", "claude"].includes(args.provider)) {
85
- throw new Error("--provider must be one of: auto, all, codex, claude");
84
+ if (!["auto", "all", "codex", "claude", "antigravity"].includes(args.provider)) {
85
+ throw new Error("--provider must be one of: auto, all, codex, claude, antigravity");
86
86
  }
87
87
  } else if (arg === "--layout") {
88
88
  const layout = String(argv[++i] || args.layout).toLowerCase();
@@ -118,6 +118,7 @@ function inferProvider(command) {
118
118
  const names = command.map((part) => path.basename(part).toLowerCase());
119
119
  if (names.some((name) => name.includes("codex")) || joined.includes("@openai/codex")) return "codex";
120
120
  if (names.some((name) => name.includes("claude")) || joined.includes("@anthropic-ai/claude-code")) return "claude";
121
+ if (names.some(name => /^(?:agy|agy\.exe|agy\.cmd)$/.test(name))) return "antigravity";
121
122
  return "all";
122
123
  }
123
124
 
@@ -191,7 +192,7 @@ function batteryCommand(args, activeProvider, maxWidth) {
191
192
  "--left-padding",
192
193
  String(args.leftPadding)
193
194
  ];
194
- if (activeProvider === "codex" || activeProvider === "claude") {
195
+ if (["codex", "claude", "antigravity"].includes(activeProvider)) {
195
196
  command.push("--active-provider", activeProvider);
196
197
  }
197
198
  command.push("--provider", args.provider);
@@ -1006,7 +1007,7 @@ function launchDockedHudAttachment(session, provider) {
1006
1007
  function runNativeFullscreen(args) {
1007
1008
  const hudEnabled = nativeFullscreenHudEnabled();
1008
1009
  const inferredProvider = inferProvider(args.command);
1009
- const provider = ["codex", "claude"].includes(inferredProvider) ? inferredProvider : "codex";
1010
+ const provider = ["codex", "claude", "antigravity"].includes(inferredProvider) ? inferredProvider : "codex";
1010
1011
  const dockSession = hudEnabled ? ensureDockedHud(provider) : 0;
1011
1012
  const command = windowsCommand(args.command);
1012
1013
  const env = {
@@ -1347,7 +1348,7 @@ async function main() {
1347
1348
  }
1348
1349
  const commandProvider = inferProvider(args.command);
1349
1350
  if (args.provider === "auto") args.provider = commandProvider;
1350
- const activeProvider = ["codex", "claude"].includes(commandProvider) ? commandProvider : null;
1351
+ const activeProvider = ["codex", "claude", "antigravity"].includes(commandProvider) ? commandProvider : null;
1351
1352
  debugLog("main:start", {
1352
1353
  argv: process.argv.slice(2),
1353
1354
  provider: args.provider,
@@ -1,12 +1,24 @@
1
+ function Set-HudControlVisible($Control, [bool]$Visible) {
2
+ # Visible reads false when a parent is hidden; Tag records the intended state.
3
+ if ($Control.Tag -ne $Visible) {
4
+ $Control.Visible = $Visible
5
+ $Control.Tag = $Visible
6
+ }
7
+ }
8
+
1
9
  function Set-HudBatteryImage($Box, [Nullable[int]]$Percent, [bool]$Running) {
2
- $oldImage = $Box.Image
3
- $Box.Image = New-BatteryImage $Percent $Running 36 16 $false
4
- $Box.AccessibleName = if ($null -eq $Percent) { "--" } else { [string][int]$Percent }
5
- $Box.ForeColor = Get-HudBatteryTextColor $Running
6
- $Box.Visible = $true
7
- $Box.Tag = $true
8
- $Box.Invalidate()
9
- if ($oldImage) { $oldImage.Dispose() }
10
+ if (-not $script:hudBatteryRenderKeys) { $script:hudBatteryRenderKeys = @{} }
11
+ $key = "$Percent|$Running|$script:hudScale|$script:hudDarkText"
12
+ if (-not $Box.Image -or $script:hudBatteryRenderKeys[$Box] -ne $key) {
13
+ $image = New-BatteryImage $Percent $Running 36 16 $false
14
+ $oldImage = $Box.Image
15
+ $Box.AccessibleName = if ($null -eq $Percent) { "--" } else { [string][int]$Percent }
16
+ $Box.ForeColor = Get-HudBatteryTextColor $Running
17
+ $Box.Image = $image
18
+ $script:hudBatteryRenderKeys[$Box] = $key
19
+ if ($oldImage) { $oldImage.Dispose() }
20
+ }
21
+ Set-HudControlVisible $Box $true
10
22
  }
11
23
 
12
24
  function New-HudGlyphImage([string]$Kind, [System.Drawing.Color]$Color, [int]$Width = 21, [int]$Height = 18) {
@@ -147,28 +159,24 @@ function Set-HudMetricLabel($Label, [string]$Value, [System.Drawing.Color]$Color
147
159
  $Label.ForeColor = $Color
148
160
  if ([string]::IsNullOrWhiteSpace($Value)) {
149
161
  $Label.Width = 0
150
- $Label.Visible = $false
151
- $Label.Tag = $false
162
+ Set-HudControlVisible $Label $false
152
163
  } else {
153
164
  $Label.Width = if ($null -ne $FixedWidth -and $FixedWidth -gt 0) {
154
165
  [int]$FixedWidth
155
166
  } else {
156
167
  (Get-LabelTextWidth $Label) + (Scale-HudValue 1)
157
168
  }
158
- $Label.Visible = $true
159
- $Label.Tag = $true
169
+ Set-HudControlVisible $Label $true
160
170
  }
161
171
  }
162
172
 
163
173
  function Set-HudDivider($Divider, [string]$Value) {
164
174
  if ([string]::IsNullOrWhiteSpace($Value)) {
165
- $Divider.Visible = $false
175
+ Set-HudControlVisible $Divider $false
166
176
  $Divider.Width = 0
167
- $Divider.Tag = $false
168
177
  } else {
169
- $Divider.Visible = $true
178
+ Set-HudControlVisible $Divider $true
170
179
  $Divider.Width = Scale-HudValue 1
171
- $Divider.Tag = $true
172
180
  }
173
181
  }
174
182
 
@@ -190,12 +198,12 @@ function Get-SharedHudColumnWidth([string[]]$Values, [int]$Minimum = 0) {
190
198
  return [int]$width
191
199
  }
192
200
 
193
- function Set-HudParts($Parts, $PrefixLabel, $BatteryBox, $Divider1, $ResetLabel, $Divider2, $WeekLabel, $ExtraLabel, [Nullable[int]]$ResetWidth = $null, [Nullable[int]]$WeekWidth = $null) {
201
+ function Set-HudParts($Parts, $PrefixLabel, $BatteryBox, $Divider1, $ResetLabel, $Divider2, $WeekLabel, $ExtraLabel, [Nullable[int]]$ResetWidth = $null, [Nullable[int]]$WeekWidth = $null, [Nullable[int]]$PrefixWidth = $null) {
194
202
  $PrefixLabel.Text = $Parts.Prefix
195
203
  $PrefixLabel.ForeColor = $Parts.TextColor
196
- $PrefixLabel.Width = Scale-HudValue 48
197
- $PrefixLabel.Visible = $true
198
- $PrefixLabel.Tag = $true
204
+ $PrefixLabel.Width = if ($null -ne $PrefixWidth) { [int]$PrefixWidth } else { [math]::Max((Scale-HudValue 48), (Get-LabelTextWidth $PrefixLabel) + (Scale-HudValue 1)) }
205
+ Set-HudControlVisible $PrefixLabel $true
206
+ $BatteryBox.Width = Scale-HudValue 42
199
207
  Set-HudBatteryImage $BatteryBox $Parts.Percent $Parts.Running
200
208
  Set-HudDivider $Divider1 $Parts.ResetValue
201
209
  Set-HudMetricLabel $ResetLabel $Parts.ResetValue $Parts.TextColor $ResetWidth
@@ -206,8 +214,7 @@ function Set-HudParts($Parts, $PrefixLabel, $BatteryBox, $Divider1, $ResetLabel,
206
214
 
207
215
  function Set-HudControlsVisible($Controls, [bool]$Visible) {
208
216
  foreach ($control in $Controls) {
209
- $control.Visible = $Visible
210
- $control.Tag = $Visible
217
+ Set-HudControlVisible $control $Visible
211
218
  }
212
219
  }
213
220
 
@@ -242,39 +249,30 @@ function Resize-HudToContent {
242
249
 
243
250
  $oldRight = $form.Left + $form.Width
244
251
  $oldBottom = $form.Top + $form.Height
245
- $codexWidth = $(if ($script:codexRowVisible) { Get-HudControlsWidth $codexHudControls } else { 0 })
246
- $claudeWidth = $(if ($script:claudeRowVisible) { Get-HudControlsWidth $claudeHudControls } else { 0 })
247
- $bothRows = $script:codexRowVisible -and $script:claudeRowVisible
248
- if ($providerDivider) {
249
- $providerDivider.Visible = $bothRows
250
- $providerDivider.Tag = $bothRows
251
- }
252
+ $visibleCount = @($script:hudVisibleProviders).Count
253
+ if ($providerDivider) { $providerDivider.Visible = $false; $providerDivider.Tag = $false }
252
254
  if ($script:dockTuiStatusline) {
253
255
  Set-DockedTuiWindowRegion
254
256
  Sync-HitFormBounds
255
257
  return
256
258
  }
257
- $contentWidth = [math]::Max($codexWidth, $claudeWidth)
258
- $desiredWidth = $panel.Padding.Left + $panel.Padding.Right +
259
- $contentWidth +
260
- (Scale-HudValue 1)
261
- $desiredWidth = [math]::Max((Scale-HudValue 150), [int][math]::Ceiling($desiredWidth))
262
-
263
- $desiredHeight = [int]$(if ($bothRows) { $script:hudTwoRowHeight } else { $script:hudOneRowHeight })
264
- if ($bothRows) {
265
- $panel.RowStyles[0] = [System.Windows.Forms.RowStyle]::new([System.Windows.Forms.SizeType]::Percent, 50)
266
- $panel.RowStyles[1] = [System.Windows.Forms.RowStyle]::new([System.Windows.Forms.SizeType]::Percent, 50)
267
- } elseif ($script:claudeRowVisible) {
268
- $panel.RowStyles[0] = [System.Windows.Forms.RowStyle]::new([System.Windows.Forms.SizeType]::Absolute, 0)
269
- $panel.RowStyles[1] = [System.Windows.Forms.RowStyle]::new([System.Windows.Forms.SizeType]::Percent, 100)
270
- } else {
271
- $panel.RowStyles[0] = [System.Windows.Forms.RowStyle]::new([System.Windows.Forms.SizeType]::Percent, 100)
272
- $panel.RowStyles[1] = [System.Windows.Forms.RowStyle]::new([System.Windows.Forms.SizeType]::Absolute, 0)
259
+ $contentWidth = 0
260
+ foreach ($name in $script:hudVisibleProviders) {
261
+ $contentWidth = [math]::Max($contentWidth, (Get-HudControlsWidth $script:hudProviderRows[$name].Controls))
262
+ }
263
+ $desiredWidth = [math]::Max((Scale-HudValue 150), $panel.Padding.Left + $panel.Padding.Right + $contentWidth + (Scale-HudValue 1))
264
+ $rowHeight = $script:hudTwoRowHeight - $script:hudOneRowHeight
265
+ $desiredHeight = $script:hudOneRowHeight + [math]::Max(0, $visibleCount - 1) * $rowHeight
266
+ for ($i = 0; $i -lt 3; $i += 1) {
267
+ $sizeType = if ($i -lt $visibleCount) { [System.Windows.Forms.SizeType]::Percent } else { [System.Windows.Forms.SizeType]::Absolute }
268
+ $height = if ($i -lt $visibleCount) { 100 / [math]::Max(1, $visibleCount) } else { 0 }
269
+ $style = $panel.RowStyles[$i]
270
+ if ($style.SizeType -ne $sizeType) { $style.SizeType = $sizeType }
271
+ if ([math]::Abs($style.Height - $height) -gt 0.01) { $style.Height = $height }
273
272
  }
274
273
 
275
274
  if (([math]::Abs($form.Width - $desiredWidth) -gt 1) -or ($form.Height -ne $desiredHeight)) {
276
- $form.Width = $desiredWidth
277
- $form.Height = $desiredHeight
275
+ $form.Size = [System.Drawing.Size]::new($desiredWidth, $desiredHeight)
278
276
  $newX = if ($script:hudAnchorX -eq "right") { $oldRight - $form.Width } else { $form.Left }
279
277
  $newY = if ($script:hudAnchorY -eq "bottom") { $oldBottom - $form.Height } else { $form.Top }
280
278
  $form.Location = [System.Drawing.Point]::new([int]$newX, [int]$newY)
@@ -284,6 +282,9 @@ function Resize-HudToContent {
284
282
  }
285
283
 
286
284
  function Show-HudMessage([string]$Message) {
285
+ $key = "message:$Message|$script:hudScale|$script:hudDarkText"
286
+ if ($script:hudVisualKey -eq $key) { return }
287
+ $script:hudVisualKey = $null
287
288
  $codexPrefixLabel.Text = $Message
288
289
  $codexPrefixLabel.ForeColor = Get-HudMutedTextColor
289
290
  $codexPrefixLabel.Width = (Get-LabelTextWidth $codexPrefixLabel) + (Scale-HudValue 1)
@@ -308,9 +309,14 @@ function Show-HudMessage([string]$Message) {
308
309
  if ($oldImage) { $oldImage.Dispose() }
309
310
  $script:codexRowVisible = $true
310
311
  $script:claudeRowVisible = $false
311
- $codexRow.Visible = $true
312
- $claudeRow.Visible = $false
312
+ Set-HudControlVisible $codexRow $true
313
+ Set-HudControlVisible $claudeRow $false
314
+ Set-HudControlVisible $antigravityRow $false
315
+ Set-HudControlsVisible $antigravityHudControls $false
316
+ $script:hudVisibleProviders = @("codex")
317
+ if (-not $script:dockTuiStatusline -and $panel.GetRow($codexRow) -ne 0) { $panel.SetRow($codexRow, 0) }
313
318
  Resize-HudToContent
319
+ $script:hudVisualKey = $key
314
320
  }
315
321
 
316
322
  function Update-HudFromSnapshot($Snapshot) {
@@ -323,35 +329,51 @@ function Update-HudFromSnapshot($Snapshot) {
323
329
 
324
330
  try {
325
331
  $texts = ConvertTo-HudTexts $Snapshot
332
+ # Timestamps and fetch metadata do not affect the frame. Keep polling and
333
+ # caching fresh snapshots, but leave an identical screen untouched.
334
+ $visualRows = @($texts.Rows | ForEach-Object {
335
+ @{ Provider = $_.Provider; Prefix = $_.Parts.Prefix; Percent = $_.Parts.Percent;
336
+ Running = $_.Parts.Running; Color = $_.Parts.TextColor.ToArgb();
337
+ Reset = $_.Parts.ResetValue; Week = $_.Parts.WeekValue; Extra = $_.Parts.ExtraText }
338
+ })
339
+ $key = (@{ Rows = $visualRows; Scale = $script:hudScale; DarkText = $script:hudDarkText } | ConvertTo-Json -Depth 5 -Compress)
340
+ if ($script:hudVisualKey -eq $key) {
341
+ Invalidate-DockedTuiIfChanged $Snapshot
342
+ Update-HudVisibilityForFullscreen
343
+ return
344
+ }
345
+ $script:hudVisualKey = $null
326
346
  $script:codexRowVisible = [bool]$texts.CodexVisible
327
347
  $script:claudeRowVisible = [bool]$texts.ClaudeVisible
328
- $resetValues = @()
329
- $weekValues = @()
330
- if ($texts.CodexVisible) {
331
- if ($texts.Codex.ResetValue) { $resetValues += $texts.Codex.ResetValue }
332
- if ($texts.Codex.WeekValue) { $weekValues += $texts.Codex.WeekValue }
333
- }
334
- if ($texts.ClaudeVisible) {
335
- if ($texts.Claude.ResetValue) { $resetValues += $texts.Claude.ResetValue }
336
- if ($texts.Claude.WeekValue) { $weekValues += $texts.Claude.WeekValue }
337
- }
348
+ $script:hudVisibleProviders = @($texts.Rows | ForEach-Object { $_.Provider })
349
+ $prefixValues = @($texts.Rows | ForEach-Object { $_.Parts.Prefix })
350
+ $resetValues = @($texts.Rows | ForEach-Object { $_.Parts.ResetValue } | Where-Object { $_ })
351
+ $weekValues = @($texts.Rows | ForEach-Object { $_.Parts.WeekValue } | Where-Object { $_ })
338
352
  $resetWidth = Get-SharedHudColumnWidth $resetValues
339
353
  $weekWidth = Get-SharedHudColumnWidth $weekValues
340
- if ($texts.CodexVisible) {
341
- $codexRow.Visible = $true
342
- Set-HudParts $texts.Codex $codexPrefixLabel $codexIconLabel $codexDivider1 $codexResetLabel $codexDivider2 $codexWeekLabel $codexExtraLabel $resetWidth $weekWidth
343
- } else {
344
- $codexRow.Visible = $false
345
- Set-HudControlsVisible $codexHudControls $false
346
- }
347
- if ($texts.ClaudeVisible) {
348
- $claudeRow.Visible = $true
349
- Set-HudParts $texts.Claude $claudePrefixLabel $claudeIconLabel $claudeDivider1 $claudeResetLabel $claudeDivider2 $claudeWeekLabel $claudeExtraLabel $resetWidth $weekWidth
350
- } else {
351
- $claudeRow.Visible = $false
352
- Set-HudControlsVisible $claudeHudControls $false
353
- }
354
+ $prefixWidth = Get-SharedHudColumnWidth $prefixValues 48
355
+ $panel.SuspendLayout()
356
+ try {
357
+ foreach ($name in $script:hudProviderRows.Keys) {
358
+ $entry = $script:hudProviderRows[$name]
359
+ if ($script:hudVisibleProviders -notcontains $name) { Set-HudControlVisible $entry.Row $false }
360
+ }
361
+ $index = 0
362
+ foreach ($row in $texts.Rows) {
363
+ $entry = $script:hudProviderRows[$row.Provider]
364
+ if (-not $entry) { continue }
365
+ $c = $entry.Controls
366
+ $entry.Row.SuspendLayout()
367
+ try {
368
+ Set-HudParts $row.Parts ($c[0]) ($c[1]) ($c[2]) ($c[3]) ($c[4]) ($c[5]) ($c[6]) $resetWidth $weekWidth $prefixWidth
369
+ } finally { $entry.Row.ResumeLayout() }
370
+ if (-not $script:dockTuiStatusline -and $panel.GetRow($entry.Row) -ne $index) { $panel.SetRow($entry.Row, $index) }
371
+ Set-HudControlVisible $entry.Row $true
372
+ $index += 1
373
+ }
374
+ } finally { $panel.ResumeLayout() }
354
375
  Resize-HudToContent
376
+ $script:hudVisualKey = $key
355
377
  } catch {
356
378
  Show-HudMessage "AI Battery unavailable"
357
379
  }