ai-battery 0.2.1 → 0.2.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/lib/cli.js CHANGED
@@ -21,7 +21,7 @@ import { cliError, cliText, helpText, invalidChoice, requiredValue } from "./cor
21
21
  import { errorText, messageText as cliMessageText } from "./core/cli-messages.js";
22
22
  import { formatClaudeResult, formatDoctorResult, formatResetResult, formatSetupResult, formatSplitBarModeResult, formatSplitBarStatus, formatVisibilityResult } from "./core/cli-output.js";
23
23
  import { codexTerminalDisplay, claudeTerminalDisplay } from "./core/diagnostics.js";
24
- import { BAR_POSITIONS, DEFAULT_SIDEBAR_WIDTH, PROVIDERS, SPLIT_BAR_MODES, STATUS_LINE_ITEMS, defaultDisplayConfig, isDisplayConfig, normalizeBarPosition, normalizeOrder, normalizeSidebarWidth, normalizeSplitBarMode, parseOrder, orderResults, providerId, providerLabel } from "./core/display-config.js";
24
+ import { BAR_POSITIONS, DEFAULT_SIDEBAR_WIDTH, PROVIDERS, SPLIT_BAR_MODES, SPLIT_BAR_POSITIONS, STATUS_LINE_ITEMS, defaultDisplayConfig, isDisplayConfig, normalizeBarPosition, normalizeOrder, normalizeSidebarWidth, normalizeSplitBarMode, normalizeSplitBarPosition, parseOrder, orderResults, providerId, providerLabel } from "./core/display-config.js";
25
25
  import { canEditConfig, editDisplayConfig } from "./core/config-editor.js";
26
26
  import { installCliPositionWrappers, posixCliWrapperDir, uninstallCliPositionWrappers } from "./core/cli-wrappers.js";
27
27
  import { branchChanges, readGitBranchFast } from "./core/statusline-git.js";
@@ -102,7 +102,7 @@ const CODEX_PREFERRED_BACKUP_SUFFIX = ".ai-battery-original-link";
102
102
  const CODEX_TIMESTAMP_BACKUP_MARKER = ".ai-battery-backup-";
103
103
  const CODEX_STATUS_LINE = STATUS_LINE_ITEMS;
104
104
  const DEFAULT_STATUSLINE_HEADER_COLUMN_GUARD = 2;
105
- const CODEX_MENU_BAR_COLOR = "#000000";
105
+ const CODEX_MENU_BAR_COLOR = "#FFFFFF";
106
106
  const CLAUDE_MENU_BAR_COLOR = "#D97706";
107
107
  const MENU_BAR_WHITE = "#FFFFFF";
108
108
  const MENU_DETAIL_GREEN = "#30D158";
@@ -130,6 +130,11 @@ function parseArgs(argv) {
130
130
  menuBar: false,
131
131
  menuBarImage: false,
132
132
  menuDetailImage: false,
133
+ railImage: false,
134
+ railScale: 1,
135
+ railText: null,
136
+ panelText: null,
137
+ codexIcon: null,
133
138
  hudState: false,
134
139
  silent: false,
135
140
  force: false,
@@ -172,8 +177,8 @@ function parseArgs(argv) {
172
177
  resetAliasSeen = true;
173
178
  } else if (!arg.startsWith("-") && args.command === "split") {
174
179
  if (args.subcommand === "position" && !args.barPosition) {
175
- const nextPos = normalizeBarPosition(arg, null);
176
- if (!nextPos) throw invalidChoice("position", BAR_POSITIONS.join(", "), "split");
180
+ const nextPos = normalizeSplitBarPosition(arg, null);
181
+ if (!nextPos) throw invalidChoice("position", SPLIT_BAR_POSITIONS.join(", "), "split");
177
182
  args.barPosition = nextPos;
178
183
  } else if (args.subcommand) {
179
184
  throw cliError(`Unexpected argument: ${arg}.`, `불필요한 인자: ${arg}.`, "split");
@@ -217,8 +222,9 @@ function parseArgs(argv) {
217
222
  i += 1;
218
223
  } else if (arg === "--position") {
219
224
  const value = requiredValue(argv, i, args.command);
220
- const nextPos = normalizeBarPosition(value, null);
221
- if (!nextPos) throw invalidChoice("--position", BAR_POSITIONS.join(", "), args.command);
225
+ const isSplit = args.command === "split";
226
+ const nextPos = isSplit ? normalizeSplitBarPosition(value, null) : normalizeBarPosition(value, null);
227
+ if (!nextPos) throw invalidChoice("--position", (isSplit ? SPLIT_BAR_POSITIONS : BAR_POSITIONS).join(", "), args.command);
222
228
  args.barPosition = nextPos;
223
229
  i += 1;
224
230
  } else if (arg === "--interval") {
@@ -278,6 +284,35 @@ function parseArgs(argv) {
278
284
  } else if (arg === "--menu-detail-image") {
279
285
  args.menuDetailImage = true;
280
286
  args.style = "plain";
287
+ } else if (arg === "--rail-image") {
288
+ args.railImage = true;
289
+ args.style = "plain";
290
+ } else if (arg === "--rail-scale") {
291
+ const value = Number(requiredValue(argv, i, args.command));
292
+ if (!Number.isFinite(value) || value < 0.5 || value > 3) {
293
+ throw cliError("--rail-scale must be between 0.5 and 3.0.", "--rail-scale은 0.5에서 3.0 사이여야 합니다.", args.helpTopic);
294
+ }
295
+ args.railScale = value;
296
+ i += 1;
297
+ } else if (arg === "--rail-text") {
298
+ const value = String(requiredValue(argv, i, args.command)).trim().toLowerCase();
299
+ if (!["white", "black"].includes(value)) throw invalidChoice(arg, "white, black", args.helpTopic);
300
+ args.railText = value;
301
+ i += 1;
302
+ } else if (arg === "--panel-text") {
303
+ const value = String(requiredValue(argv, i, args.command)).trim().toLowerCase();
304
+ if (!["white", "black"].includes(value)) throw invalidChoice(arg, "white, black", args.helpTopic);
305
+ args.panelText = value;
306
+ i += 1;
307
+ } else if (arg === "--codex-icon") {
308
+ const value = String(requiredValue(argv, i, args.command)).trim().toLowerCase();
309
+ if (!["white", "black"].includes(value)) throw invalidChoice(arg, "white, black", args.helpTopic);
310
+ args.codexIcon = value;
311
+ i += 1;
312
+ } else if (arg.startsWith("--codex-icon=")) {
313
+ const value = arg.slice(arg.indexOf("=") + 1).trim().toLowerCase();
314
+ if (!["white", "black"].includes(value)) throw invalidChoice("--codex-icon", "white, black", args.helpTopic);
315
+ args.codexIcon = value;
281
316
  } else if (arg === "--hud-state") {
282
317
  args.hudState = true;
283
318
  args.style = "plain";
@@ -313,7 +348,7 @@ function parseArgs(argv) {
313
348
  throw invalidChoice("subcommand", SPLIT_SUBCOMMANDS.join(", "), "split");
314
349
  }
315
350
  if (args.subcommand === "position" && !args.barPosition) {
316
- throw invalidChoice("position", BAR_POSITIONS.join(", "), "split");
351
+ throw invalidChoice("position", SPLIT_BAR_POSITIONS.join(", "), "split");
317
352
  }
318
353
  }
319
354
  if (args.targets.length) {
@@ -530,7 +565,7 @@ function normalizeDisplayConfig(stored) {
530
565
  providerOrder: normalizeOrder(stored?.providerOrder, defaults.providerOrder),
531
566
  splitBar: normalizeSplitBarMode(stored?.splitBar, defaults.splitBar),
532
567
  barPosition: normalizeBarPosition(stored?.barPosition, defaults.barPosition),
533
- splitBarPosition: stored?.splitBarPosition ? normalizeBarPosition(stored.splitBarPosition, null) : null,
568
+ splitBarPosition: stored?.splitBarPosition ? normalizeSplitBarPosition(stored.splitBarPosition, null) : null,
534
569
  sidebarWidth: normalizeSidebarWidth(stored?.sidebarWidth, defaults.sidebarWidth)
535
570
  };
536
571
  }
@@ -595,7 +630,7 @@ function updateDisplayConfig({ providerOrder, providers, splitBar, barPosition,
595
630
  ? normalizeBarPosition(barPosition, latest.barPosition)
596
631
  : latest.barPosition,
597
632
  splitBarPosition: splitBarPosition !== undefined
598
- ? (splitBarPosition === null ? null : normalizeBarPosition(splitBarPosition, latest.splitBarPosition || latest.barPosition))
633
+ ? (splitBarPosition === null ? null : normalizeSplitBarPosition(splitBarPosition, latest.splitBarPosition || normalizeSplitBarPosition(latest.barPosition, "bottom")))
599
634
  : latest.splitBarPosition,
600
635
  sidebarWidth: sidebarWidth !== undefined
601
636
  ? normalizeSidebarWidth(sidebarWidth, latest.sidebarWidth)
@@ -1229,6 +1264,7 @@ function claudeUsageRowVisible(args) {
1229
1264
  const envValue = booleanEnvValue(process.env.AI_BATTERY_CLAUDE_USAGE_ROW ?? process.env.CLAUDEX_BATTERY_CLAUDE_USAGE_ROW);
1230
1265
  if (envValue !== null) return envValue;
1231
1266
  if (process.platform === "win32" && args.attachHud) return false;
1267
+ if (readConfiguredBarPosition(process.env) === "off") return false;
1232
1268
  return !tmuxStatusBarActive();
1233
1269
  }
1234
1270
 
@@ -2575,7 +2611,7 @@ function runSetup(args) {
2575
2611
  ...(args.providerOrder ? { providerOrder: args.providerOrder } : {}),
2576
2612
  ...(args.barPosition ? { barPosition: args.barPosition } : {})
2577
2613
  });
2578
- if (args.barPosition && !updatedDisplay.splitBarPosition && (process.platform === "win32" || isWsl())) {
2614
+ if (args.barPosition && updatedDisplay.barPosition !== "off" && !updatedDisplay.splitBarPosition && (process.platform === "win32" || isWsl())) {
2579
2615
  updateWtFragmentPosition({ position: updatedDisplay.barPosition, sidebarWidth: updatedDisplay.sidebarWidth });
2580
2616
  }
2581
2617
  }
@@ -5313,27 +5349,36 @@ function menuBatteryColor(percent, running = true) {
5313
5349
  return MENU_DETAIL_GREEN;
5314
5350
  }
5315
5351
 
5316
- function renderMenuBarSvgIcon(icon, x, y, height) {
5352
+ function resolveCodexMenuBarColor(codexIcon) {
5353
+ const mode = String(codexIcon || process.env.AI_BATTERY_CODEX_ICON_COLOR || "").trim().toLowerCase();
5354
+ if (mode === "black") return "#000000";
5355
+ if (mode === "white") return "#FFFFFF";
5356
+ return CODEX_MENU_BAR_COLOR;
5357
+ }
5358
+
5359
+ function renderMenuBarSvgIcon(icon, x, y, height, colorOverride = null) {
5317
5360
  const scale = height / icon.viewBox;
5318
5361
  const paths = icon.paths || [{ d: icon.path }];
5362
+ const fillColor = colorOverride || icon.color;
5319
5363
  const renderedPaths = paths.map((iconPath) => {
5320
5364
  const ruleAttrs = [
5321
5365
  iconPath.fillRule ? ` fill-rule="${iconPath.fillRule}"` : "",
5322
5366
  iconPath.clipRule ? ` clip-rule="${iconPath.clipRule}"` : ""
5323
5367
  ].join("");
5324
- return `<path d="${iconPath.d}" fill="${icon.color}"${ruleAttrs}/>`;
5368
+ return `<path d="${iconPath.d}" fill="${fillColor}"${ruleAttrs}/>`;
5325
5369
  }).join("");
5326
5370
  return `<g transform="translate(${x} ${y}) scale(${scale})">${renderedPaths}</g>`;
5327
5371
  }
5328
5372
 
5329
- function menuBarImageIcon(provider, x, y) {
5373
+ function menuBarImageIcon(provider, x, y, { codexIcon = null } = {}) {
5330
5374
  if (provider === "antigravity") {
5331
5375
  const svg = fs.readFileSync(path.join(scriptDir(), "..", "docs", "antigravity-icon.svg"), "utf8");
5332
5376
  return svg.replace(/<svg\b[^>]*>/, `<svg x="${x}" y="${y}" width="19" height="19" viewBox="0 0 180 180" fill="none" xmlns="http://www.w3.org/2000/svg">`);
5333
5377
  }
5334
5378
  const height = provider === "codex" ? 19 : 17;
5335
5379
  const iconY = provider === "codex" ? y - 0.5 : y;
5336
- if (provider === "codex") {
5380
+ const codexColor = resolveCodexMenuBarColor(codexIcon);
5381
+ if (provider === "codex" && codexColor !== "#000000") {
5337
5382
  const pngIconPath = codexMenuBarPngIconPath();
5338
5383
  if (pngIconPath) {
5339
5384
  return `<image x="${x}" y="${iconY}" width="${height}" height="${height}" href="${imageDataUri(pngIconPath)}"/>`;
@@ -5343,15 +5388,18 @@ function menuBarImageIcon(provider, x, y) {
5343
5388
  const icon = provider === "codex"
5344
5389
  ? (codexMenuBarSvgIcon() || MENU_BAR_BRAND_ICONS.codex)
5345
5390
  : (MENU_BAR_BRAND_ICONS[provider] || MENU_BAR_BRAND_ICONS.codex);
5346
- return renderMenuBarSvgIcon(icon, x, iconY, height);
5391
+ return renderMenuBarSvgIcon(icon, x, iconY, height, provider === "codex" ? codexColor : null);
5347
5392
  }
5348
5393
 
5349
- function renderMenuBarImage(snapshot) {
5394
+ function renderMenuBarImage(snapshot, { codexIcon = null, text = null } = {}) {
5350
5395
  const startX = 0;
5351
5396
  const endPadding = 0;
5352
5397
  const providerWidth = 56;
5353
5398
  const providerContentWidth = 48;
5354
5399
  const height = 24;
5400
+ const textMode = String(text || process.env.AI_BATTERY_PANEL_TEXT || "white").trim().toLowerCase();
5401
+ const darkText = textMode === "black" || textMode === "dark";
5402
+ const effectiveCodexIcon = codexIcon || (darkText ? "black" : null);
5355
5403
  const visibleResults = orderResults(snapshot.results.filter(Boolean), configuredProviderOrder());
5356
5404
  const width = visibleResults.length
5357
5405
  ? startX + ((visibleResults.length - 1) * providerWidth) + providerContentWidth + endPadding
@@ -5366,32 +5414,35 @@ function renderMenuBarImage(snapshot) {
5366
5414
  const meterY = 3;
5367
5415
  const meterWidth = 24;
5368
5416
  const meterHeight = 5;
5369
- const meterStroke = 1.1;
5417
+ const meterStroke = 1;
5370
5418
  const meterInnerX = meterX + 2;
5371
- const meterInnerY = meterY + 1.7;
5419
+ const meterInnerY = meterY + 2;
5372
5420
  const meterInnerWidth = meterWidth - 4;
5373
- const meterInnerHeight = meterHeight - 3.4;
5421
+ const meterInnerHeight = meterHeight - 3;
5374
5422
  const fillWidth = percent === null ? 0 : Math.max(percent > 0 ? 2 : 0, Math.round((percent / 100) * meterInnerWidth));
5375
- const fill = menuBatteryColor(percent, running);
5423
+ const fill = darkText && (!running || typeof percent !== "number") ? "#5C5C66" : menuBatteryColor(percent, running);
5376
5424
  const label = percent === null ? "--" : `${Math.round(percent)}%`;
5377
5425
  const labelX = meterX + (meterWidth / 2);
5378
- const textFill = running ? MENU_BAR_WHITE : MENU_DIM_TEXT;
5426
+ const textFill = darkText
5427
+ ? (running ? "#141418" : "#5C5C66")
5428
+ : (running ? MENU_BAR_WHITE : MENU_DIM_TEXT);
5429
+ const outlineStroke = darkText ? "#141418" : MENU_BAR_WHITE;
5379
5430
  const outlineOpacity = running ? MENU_BAR_OUTLINE_OPACITY : MENU_DIM_OUTLINE_OPACITY;
5380
5431
 
5381
- items.push(menuBarImageIcon(result.provider, x, 3));
5382
- items.push(`<rect x="${meterX}" y="${meterY}" width="${meterWidth}" height="${meterHeight}" rx="2.5" fill="none" stroke="${MENU_BAR_WHITE}" stroke-opacity="${outlineOpacity}" stroke-width="${meterStroke}"/>`);
5432
+ items.push(menuBarImageIcon(result.provider, x, 3, { codexIcon: effectiveCodexIcon }));
5433
+ items.push(`<rect x="${meterX + 0.5}" y="${meterY + 0.5}" width="${meterWidth - 1}" height="${meterHeight}" rx="2.5" fill="none" stroke="${outlineStroke}" stroke-opacity="${outlineOpacity}" stroke-width="${meterStroke}"/>`);
5383
5434
  if (fillWidth > 0) {
5384
- items.push(`<rect x="${meterInnerX}" y="${meterInnerY}" width="${fillWidth}" height="${meterInnerHeight}" rx="0.8" fill="${fill}"/>`);
5435
+ items.push(`<rect x="${meterInnerX}" y="${meterInnerY}" width="${fillWidth}" height="${meterInnerHeight}" rx="0.5" fill="${fill}"/>`);
5385
5436
  }
5386
- items.push(`<text x="${labelX}" y="21" text-anchor="middle" font-family="-apple-system, BlinkMacSystemFont, 'SF Pro Text', sans-serif" font-size="9.5" font-weight="650" fill="${textFill}">${svgEscape(label)}</text>`);
5437
+ items.push(`<text x="${labelX}" y="21.5" text-anchor="middle" font-family="-apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Ubuntu', 'Noto Sans', sans-serif" font-size="10.5" font-weight="700" fill="${textFill}">${svgEscape(label)}</text>`);
5387
5438
  });
5388
5439
 
5389
5440
  if (!items.length) {
5390
- items.push(`<text x="9" y="16" font-family="-apple-system, BlinkMacSystemFont, sans-serif" font-size="11" font-weight="650" fill="${MENU_BAR_WHITE}">AI --</text>`);
5441
+ items.push(`<text x="9" y="16" font-family="-apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Ubuntu', 'Noto Sans', sans-serif" font-size="11" font-weight="650" fill="${darkText ? "#141418" : MENU_BAR_WHITE}">AI --</text>`);
5391
5442
  }
5392
5443
 
5393
5444
  const svg = [
5394
- `<svg xmlns="http://www.w3.org/2000/svg" width="${width}" height="${height}" viewBox="0 0 ${width} ${height}">`,
5445
+ `<svg xmlns="http://www.w3.org/2000/svg" width="${width}" height="${height}" viewBox="0 0 ${width} ${height}" text-rendering="geometricPrecision" shape-rendering="geometricPrecision">`,
5395
5446
  ...items,
5396
5447
  "</svg>",
5397
5448
  ""
@@ -5523,14 +5574,145 @@ function renderMenuDetailImage(snapshot) {
5523
5574
  throw new Error("Could not write macOS menu detail image");
5524
5575
  }
5525
5576
 
5526
- function desktopHudSnapshot(provider = "all") {
5577
+ function railProviderTag(provider) {
5578
+ if (provider === "codex") return "CDX";
5579
+ if (provider === "claude") return "CLD";
5580
+ if (provider === "antigravity") return "AGY";
5581
+ return "AI";
5582
+ }
5583
+
5584
+ function railProviderTagColor(provider, running, darkText = false) {
5585
+ if (provider === "antigravity") {
5586
+ if (darkText) return running ? "#2563EB" : "#4B76C8";
5587
+ return running ? "#60A5FA" : "#4C84CC";
5588
+ }
5589
+ if (provider === "claude") {
5590
+ if (darkText) return running ? "#D97706" : "#B47030";
5591
+ return running ? "#F97316" : "#CC6E2A";
5592
+ }
5593
+ if (darkText) return running ? "#141418" : "#5C5C66";
5594
+ return running ? "#FFFFFF" : "#CCCCD4";
5595
+ }
5596
+
5597
+ function railWindowParts(limit, fallbackLabel, fallbackValue, preferPercent = false) {
5598
+ if (!limit) return { label: fallbackLabel, value: fallbackValue };
5599
+ const label = limit.windowMinutes ? shortWindow(limit.windowMinutes) : (limit.id || fallbackLabel);
5600
+ const value = preferPercent
5601
+ ? (typeof limit.remainingPercent === "number" ? `${Math.round(limit.remainingPercent)}%` : resetClock(limit))
5602
+ : (label === "5h" ? resetClock(limit) : (typeof limit.remainingPercent === "number" ? `${Math.round(limit.remainingPercent)}%` : resetClock(limit)));
5603
+ return { label, value: value || fallbackValue };
5604
+ }
5605
+
5606
+ function renderRailImage(snapshot, { scale = 1, backdrop = false, text = null } = {}) {
5607
+ const safeScale = Number.isFinite(Number(scale)) ? clamp(Number(scale), 0.5, 3) : 1;
5608
+ const textMode = String(text || process.env.AI_BATTERY_RAIL_TEXT || "white").trim().toLowerCase();
5609
+ const darkText = textMode === "black" || textMode === "dark";
5610
+ const visibleResults = orderResults(snapshot.results.filter(Boolean), configuredProviderOrder());
5611
+ const width = 44;
5612
+ const padY = 8;
5613
+ const tagH = 14;
5614
+ const tagGap = 3;
5615
+ const batH = 30;
5616
+ const batGap = 3;
5617
+ const pctH = 14;
5618
+ const pctGap = 2;
5619
+ const lblH = 10;
5620
+ const valH = 12;
5621
+ const pairGap = 3;
5622
+ const divGap = 11;
5623
+ const blockH = (tagH + tagGap) + (batH + batGap) + (pctH + pctGap) + (lblH + valH + pairGap) + (lblH + valH);
5624
+ const count = Math.max(1, visibleResults.length);
5625
+ const height = (padY * 2) + (count * blockH) + (Math.max(0, count - 1) * divGap);
5626
+ const scaledWidth = Math.max(24, Math.round(width * safeScale));
5627
+ const scaledHeight = Math.max(32, Math.round(height * safeScale));
5628
+ const centerX = width / 2;
5629
+ const sansFont = "-apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Ubuntu', 'Noto Sans', sans-serif";
5630
+ const monoFont = "'SF Mono', 'Cascadia Mono', 'JetBrains Mono', 'Ubuntu Mono', monospace";
5631
+ const items = backdrop
5632
+ ? [`<rect x="0.5" y="0.5" width="${width - 1}" height="${height - 1}" rx="8" fill="#1C1C20" fill-opacity="0.92" stroke="#44444A" stroke-width="1"/>`]
5633
+ : [];
5634
+
5635
+ if (!visibleResults.length) {
5636
+ items.push(`<text x="${centerX}" y="${Math.round(height / 2) + 4}" text-anchor="middle" font-family="${monoFont}" font-size="10.5" font-weight="700" fill="${darkText ? "#6C6C74" : "#9A9AA4"}">AI--</text>`);
5637
+ } else {
5638
+ let y = padY;
5639
+ visibleResults.forEach((result, index) => {
5640
+ if (index > 0) {
5641
+ const divY = y + Math.floor(divGap / 2) + 0.5;
5642
+ items.push(`<line x1="6" y1="${divY}" x2="${width - 6}" y2="${divY}" stroke="${darkText ? "#AAAAB4" : "#4A4A54"}" stroke-width="1"/>`);
5643
+ y += divGap;
5644
+ }
5645
+ const running = result.running === true;
5646
+ const percent = typeof result.percentRemaining === "number" ? clamp(result.percentRemaining, 0, 100) : null;
5647
+ const primaryColor = running
5648
+ ? (darkText ? "#141418" : "#F5F5F7")
5649
+ : (darkText ? "#6C6C74" : "#9A9AA4");
5650
+ const mutedColor = darkText ? "#787880" : "#80808A";
5651
+ const trackColor = darkText ? "#B4B4BC" : "#54545E";
5652
+ const tag = railProviderTag(result.provider);
5653
+ const tagColor = railProviderTagColor(result.provider, running, darkText);
5654
+
5655
+ items.push(`<text x="${centerX}" y="${y + 11}" text-anchor="middle" font-family="${monoFont}" font-size="11.5" font-weight="700" fill="${tagColor}">${svgEscape(tag)}</text>`);
5656
+ y += tagH + tagGap;
5657
+
5658
+ items.push(`<rect x="${centerX - 1}" y="${y}" width="2" height="${batH}" rx="1" fill="${trackColor}"/>`);
5659
+ if (percent !== null) {
5660
+ const fillH = percent > 0 ? Math.max(2, Math.round((percent / 100) * batH)) : 0;
5661
+ if (fillH > 0) {
5662
+ const fillColor = menuBatteryColor(percent, running);
5663
+ items.push(`<rect x="${centerX - 4}" y="${y + batH - fillH}" width="8" height="${fillH}" rx="1.5" fill="${fillColor}"/>`);
5664
+ }
5665
+ }
5666
+ y += batH + batGap;
5667
+
5668
+ const pctText = percent === null ? "--%" : `${Math.round(percent)}%`;
5669
+ const pctColor = running ? menuBatteryColor(percent, true) : primaryColor;
5670
+ items.push(`<text x="${centerX}" y="${y + 11}" text-anchor="middle" font-family="${sansFont}" font-size="10.5" font-weight="700" fill="${pctColor}">${svgEscape(pctText)}</text>`);
5671
+ y += pctH + pctGap;
5672
+
5673
+ const primary = railWindowParts(result.primary, "5h", "--:--", false);
5674
+ items.push(`<text x="${centerX}" y="${y + 8}" text-anchor="middle" font-family="${sansFont}" font-size="8.5" font-weight="500" fill="${mutedColor}">${svgEscape(primary.label)}</text>`);
5675
+ y += lblH;
5676
+ items.push(`<text x="${centerX}" y="${y + 10}" text-anchor="middle" font-family="${monoFont}" font-size="9.5" font-weight="500" fill="${primaryColor}">${svgEscape(primary.value)}</text>`);
5677
+ y += valH + pairGap;
5678
+
5679
+ const secondary = railWindowParts(result.secondary, "7d", "--%", true);
5680
+ items.push(`<text x="${centerX}" y="${y + 8}" text-anchor="middle" font-family="${sansFont}" font-size="8.5" font-weight="500" fill="${mutedColor}">${svgEscape(secondary.label)}</text>`);
5681
+ y += lblH;
5682
+ items.push(`<text x="${centerX}" y="${y + 10}" text-anchor="middle" font-family="${monoFont}" font-size="9.5" font-weight="500" fill="${primaryColor}">${svgEscape(secondary.value)}</text>`);
5683
+ y += valH;
5684
+ });
5685
+ }
5686
+
5687
+ const svg = [
5688
+ `<svg xmlns="http://www.w3.org/2000/svg" width="${scaledWidth}" height="${scaledHeight}" viewBox="0 0 ${width} ${height}" text-rendering="geometricPrecision" shape-rendering="geometricPrecision">`,
5689
+ ...items,
5690
+ "</svg>",
5691
+ ""
5692
+ ].join("\n");
5693
+
5694
+ for (const root of [stateDir(), path.join(os.tmpdir(), "ai-battery")]) {
5695
+ const filePath = path.join(root, "hud-rail.svg");
5696
+ try {
5697
+ fs.mkdirSync(path.dirname(filePath), { recursive: true, mode: 0o700 });
5698
+ fs.writeFileSync(filePath, svg, "utf8");
5699
+ return filePath;
5700
+ } catch {
5701
+ // Fall back to the next writable location.
5702
+ }
5703
+ }
5704
+ throw new Error("Could not write HUD rail image");
5705
+ }
5706
+
5707
+ function desktopHudSnapshot(provider = "all", { codexIcon = null } = {}) {
5527
5708
  const args = parseArgs(["--provider", provider]);
5528
5709
  const snapshot = collect(args);
5529
5710
  return {
5530
5711
  generatedAt: snapshot.generatedAt,
5531
5712
  state: renderHudState(snapshot),
5532
- panelImage: renderMenuBarImage(snapshot),
5713
+ panelImage: renderMenuBarImage(snapshot, { codexIcon }),
5533
5714
  detailImage: renderMenuDetailImage(snapshot),
5715
+ railImage: renderRailImage(snapshot),
5534
5716
  text: renderLine(snapshot, { ...args, style: "plain" }),
5535
5717
  rows: snapshot.results.filter(Boolean).map((result) => ({
5536
5718
  provider: result.provider,
@@ -5558,8 +5740,9 @@ function render(snapshot, args) {
5558
5740
  snapshot = { ...snapshot, results: orderResults(snapshot.results, configuredProviderOrder()) };
5559
5741
  if (args.json) return JSON.stringify(snapshot, null, 2);
5560
5742
  if (args.hudState) return renderHudState(snapshot);
5561
- if (args.menuBarImage) return renderMenuBarImage(snapshot);
5743
+ if (args.menuBarImage) return renderMenuBarImage(snapshot, { codexIcon: args.codexIcon, text: args.panelText });
5562
5744
  if (args.menuDetailImage) return renderMenuDetailImage(snapshot);
5745
+ if (args.railImage) return renderRailImage(snapshot, { scale: args.railScale, text: args.railText });
5563
5746
  if (args.menuBar) return renderMenuBar(snapshot);
5564
5747
 
5565
5748
  const maxWidth = args.maxWidth
@@ -5649,22 +5832,23 @@ async function main() {
5649
5832
  });
5650
5833
  if ((saveBarPosition || edited.sidebarWidthChanged) && (process.platform === "win32" || isWsl())) {
5651
5834
  const effectiveWtPos = latest.splitBarPosition || latest.barPosition;
5652
- if (!latest.splitBarPosition || edited.sidebarWidthChanged) {
5835
+ if (effectiveWtPos !== "off" && (!latest.splitBarPosition || edited.sidebarWidthChanged)) {
5653
5836
  updateWtFragmentPosition({ position: effectiveWtPos, sidebarWidth: latest.sidebarWidth });
5654
5837
  }
5655
5838
  }
5656
- if (latest.barPosition !== "bottom") {
5839
+ if (["top", "left", "right"].includes(latest.barPosition)) {
5657
5840
  ensureCliPositionWrappers(["claude", "antigravity"], { updateShellPath: true });
5658
5841
  }
5659
5842
  const visible = latest.providerOrder.filter(provider => latest.providers[provider] !== false).map(providerLabel);
5660
5843
  console.log(`${cliText("Display settings saved", "표시 설정 저장")}: ${visible.join(" → ") || cliText("All hidden", "모두 숨김")}`);
5661
5844
  const posLabel = ({
5845
+ off: cliText("off", "표시 안 함 (off)"),
5662
5846
  bottom: cliText("bottom", "하단 (bottom)"),
5663
5847
  top: cliText("top", "상단 (top)"),
5664
5848
  left: cliText("left", "좌측 (left)"),
5665
5849
  right: cliText("right", "우측 (right)")
5666
5850
  })[latest.barPosition] || latest.barPosition;
5667
- console.log(`${cliText("Bar position", "상태바 위치")}: ${posLabel}${latest.splitBarPosition && latest.splitBarPosition !== latest.barPosition ? ` (${cliText("split", "통합 바")}: ${latest.splitBarPosition})` : ""}`);
5851
+ console.log(`${cliText("Bar position", "상태바 위치")}: ${posLabel}${latest.barPosition !== "off" && latest.splitBarPosition && latest.splitBarPosition !== latest.barPosition ? ` (${cliText("split", "통합 바")}: ${latest.splitBarPosition})` : ""}`);
5668
5852
  return;
5669
5853
  }
5670
5854
  const current = (args.providerOrder || args.barPosition)
@@ -5673,10 +5857,10 @@ async function main() {
5673
5857
  ...(args.barPosition ? { barPosition: args.barPosition } : {})
5674
5858
  })
5675
5859
  : display;
5676
- if (args.barPosition && !current.splitBarPosition && (process.platform === "win32" || isWsl())) {
5860
+ if (args.barPosition && current.barPosition !== "off" && !current.splitBarPosition && (process.platform === "win32" || isWsl())) {
5677
5861
  updateWtFragmentPosition({ position: current.barPosition, sidebarWidth: current.sidebarWidth });
5678
5862
  }
5679
- if (args.barPosition && current.barPosition !== "bottom") {
5863
+ if (args.barPosition && ["top", "left", "right"].includes(current.barPosition)) {
5680
5864
  ensureCliPositionWrappers(["claude", "antigravity"], { updateShellPath: true });
5681
5865
  }
5682
5866
  const result = {
@@ -5685,13 +5869,13 @@ async function main() {
5685
5869
  providerOrder: normalizeOrder(current.providerOrder, PROVIDERS),
5686
5870
  providers: Object.fromEntries(PROVIDERS.map(provider => [provider, current.providers[provider] !== false])),
5687
5871
  barPosition: current.barPosition,
5688
- splitBarPosition: current.splitBarPosition || current.barPosition,
5872
+ splitBarPosition: current.barPosition === "off" ? "off" : (current.splitBarPosition || current.barPosition),
5689
5873
  sidebarWidth: current.sidebarWidth
5690
5874
  };
5691
5875
  if (args.json) console.log(JSON.stringify(result, null, 2));
5692
5876
  else {
5693
5877
  console.log(`${cliText("Display settings", "표시 설정")}: ${result.providerOrder.map(provider => `${providerLabel(provider)}${result.providers[provider] ? "" : cliText(" (hidden)", " (숨김)")}`).join(" → ")}`);
5694
- console.log(`${cliText("Bar position", "상태바 위치")}: ${result.barPosition}${current.splitBarPosition && current.splitBarPosition !== result.barPosition ? ` (${cliText("split", "통합 바")}: ${current.splitBarPosition})` : ""}`);
5878
+ console.log(`${cliText("Bar position", "상태바 위치")}: ${result.barPosition}${result.barPosition !== "off" && current.splitBarPosition && current.splitBarPosition !== result.barPosition ? ` (${cliText("split", "통합 바")}: ${current.splitBarPosition})` : ""}`);
5695
5879
  if (!args.providerOrder && !args.barPosition) {
5696
5880
  console.log(cliText("Run ai-battery config in a terminal: arrows reorder, Space shows/hides, Tab switches to bar position, Enter saves, Esc cancels.", "터미널에서 ai-battery config를 실행하세요: 방향키 순서 이동 · Space 표시/숨김 · Tab 상태바 위치 전환 · Enter 저장 · Esc 취소"));
5697
5881
  console.log(`${cliText("Or use", "명령으로 변경")}: ai-battery config --provider-order ${result.providerOrder.map(provider => provider === "antigravity" ? "gemini" : provider).join(",")} --position ${result.barPosition}`);
@@ -5798,8 +5982,8 @@ async function main() {
5798
5982
 
5799
5983
  if (args.command === "split") {
5800
5984
  const action = args.subcommand || (args.barPosition ? "position" : "status");
5801
- if (BAR_POSITIONS.includes(action) || action === "position") {
5802
- const targetPos = action === "position" ? args.barPosition : normalizeBarPosition(action);
5985
+ if (SPLIT_BAR_POSITIONS.includes(action) || action === "position") {
5986
+ const targetPos = action === "position" ? args.barPosition : normalizeSplitBarPosition(action);
5803
5987
  const updated = updateDisplayConfig({ splitBarPosition: targetPos });
5804
5988
  const fragmentUpdate = (process.platform === "win32" || isWsl())
5805
5989
  ? updateWtFragmentPosition({ position: targetPos, sidebarWidth: updated.sidebarWidth })
@@ -5837,7 +6021,7 @@ async function main() {
5837
6021
  action,
5838
6022
  mode: resolved.mode,
5839
6023
  configuredMode: updated.splitBar,
5840
- position: updated.splitBarPosition || updated.barPosition,
6024
+ position: updated.splitBarPosition || normalizeSplitBarPosition(updated.barPosition, "bottom"),
5841
6025
  envOverride: resolved.envOverride,
5842
6026
  displayConfigPath: displayConfigPath()
5843
6027
  };
@@ -5905,8 +6089,9 @@ async function main() {
5905
6089
  );
5906
6090
  }
5907
6091
  if (!args.silent) {
6092
+ const barHidden = readConfiguredBarPosition(process.env) === "off";
5908
6093
  const usageRowRequested = activeProvider === "antigravity"
5909
- ? (typeof args.usageRow === "boolean" ? args.usageRow : booleanEnvValue(process.env.AI_BATTERY_ANTIGRAVITY_USAGE_ROW) ?? !tmuxStatusBarActive())
6094
+ ? (typeof args.usageRow === "boolean" ? args.usageRow : booleanEnvValue(process.env.AI_BATTERY_ANTIGRAVITY_USAGE_ROW) ?? (!barHidden && !tmuxStatusBarActive()))
5910
6095
  : claudeUsageRowVisible(args);
5911
6096
  const externalBarActive = process.env.AI_BATTERY_EXTERNAL_BAR === "1";
5912
6097
  const participate = usageRowRequested && !args.attachHud && !externalBarActive;
@@ -6038,6 +6223,7 @@ export {
6038
6223
  renderHudState,
6039
6224
  renderMenuBarImage,
6040
6225
  renderMenuDetailImage,
6226
+ renderRailImage,
6041
6227
  rowptyDiagnostic,
6042
6228
  sameFilePath,
6043
6229
  teardownResultFailed,
@@ -126,7 +126,7 @@ export function helpText(command = "", { env = process.env, platform = process.p
126
126
  t("↑↓ select · ←→ reorder · Space show/hide · Enter save · Esc cancel", "↑↓ 선택 · ←→ 순서 이동 · Space 표시/숨김 · Enter 저장 · Esc 취소"),
127
127
  options([
128
128
  ["--provider-order LIST", "Set order directly, comma separated", "순서를 명령으로 지정 (쉼표로 구분)"],
129
- ["--position EDGE", "Set bar placement: bottom, top, left, right", "상태바 위치 설정: bottom, top, left, right"],
129
+ ["--position EDGE", "Set bar placement: off, bottom, top, left, right", "상태바 위치 설정: off, bottom, top, left, right"],
130
130
  json
131
131
  ]),
132
132
  examples(["ai-battery config", "ai-battery config --provider-order antigravity,codex,claude"])].join("\n\n");
@@ -163,28 +163,45 @@ export function helpText(command = "", { env = process.env, platform = process.p
163
163
  ].join("\n\n");
164
164
  }
165
165
  if (command === "hud") {
166
- return [usage("hud [start|stop|status] [options]"),
166
+ const isDesktop = ["darwin", "linux"].includes(platform);
167
+ return [usage(isDesktop ? "hud [start|stop|status|rail] [options]" : "hud [start|stop|status|icon|rail|stack] [options]"),
167
168
  t("Desktop usage display for Linux, macOS, Windows and WSL.", "Linux·macOS·Windows·WSL용 데스크톱 사용량 표시입니다."),
168
169
  `${t("Commands", "명령")}:\n${rows([
169
170
  ["start", "Start the display (default)", "사용량 표시 시작 (기본)"],
170
171
  ["stop", "Stop the display", "사용량 표시 종료"],
171
172
  ["status", "Show display status", "실행 상태 확인"],
172
- ["autostart on|off|status", "Manage login startup", "로그인 시 자동 실행 관리"]
173
+ ["autostart on|off|status", "Manage login startup", "로그인 시 자동 실행 관리"],
174
+ ...(isDesktop
175
+ ? [["rail", "Show the floating vertical rail panel", "세로 레일 패널 표시"]]
176
+ : [
177
+ ["icon", "Show the horizontal icon panel (default)", "가로 아이콘 패널 표시 (기본)"],
178
+ ["rail", "Show the floating vertical rail panel", "세로 레일 패널 표시"],
179
+ ["stack", "Show the stacked detail panel", "스택 상세 패널 표시"]
180
+ ])
173
181
  ])}`,
174
- options(["darwin", "linux"].includes(platform) ? [
182
+ options(isDesktop ? [
183
+ ["light|dark, black|white", "Panel/rail text color (default: white)", "패널·레일 글자색 선택 (기본: white)"],
184
+ ["--scale factor", "Rail size scale (0.5..3.0, small|large|xl)", "레일 크기 배율 (0.5..3.0, small|large|xl)"],
185
+ ["--codex-icon white|black", "Codex panel icon color (default: white)", "Codex 패널 아이콘 색상 (기본: white)"],
175
186
  ["--interval seconds", "Refresh interval (default: 2s)", "갱신 간격 (기본: 2초)"], providers,
176
187
  ["--once", "Print panel text once", "패널 텍스트 한 번 출력"],
177
188
  ["--foreground", "Run in the foreground", "포그라운드에서 실행"]
178
189
  ] : [
179
- ["icon|rail|stack", "Choose icon (default), vertical rail, or stack panel", "아이콘(기본)·세로 레일·스택 패널 선택"],
180
- ["light|dark", "Match light or dark taskbar colors", "밝은·어두운 작업 표시줄에 맞춤"],
181
- ["black|white", "Choose text color", "글자색 선택"],
190
+ ["light|dark, black|white", "Switch black/white text for light or dark backgrounds", "밝은·어두운 배경에 맞춰 흑백 글자 전환"],
191
+ ["--scale factor", "HUD size scale (0.5..3.0, small|large|xl)", "HUD 크기 배율 (0.5..3.0, small|large|xl)"],
192
+ ["--codex-icon white|black", "Codex icon color (auto|white|black)", "Codex 아이콘 색상 (자동|white|black)"],
182
193
  ["--backdrop [on|off]", "Toggle the background", "배경 표시 설정"],
194
+ ["--interval seconds", "Refresh interval (default: 2s)", "갱신 간격 (기본: 2초)"],
195
+ providers,
196
+ ["--once", "Print panel text once", "패널 텍스트 한 번 출력"],
197
+ ["--foreground", "Run in the foreground", "포그라운드에서 실행"],
183
198
  ["--dock-console", "Attach to the current terminal", "현재 터미널에 연결"],
184
199
  ["--dock-window HWND", "Attach to a specific window", "지정한 창에 연결"],
185
200
  ["--dock-position bottom|tabs", "Choose the docking position", "표시 위치 선택"]
186
201
  ]),
187
- examples(["ai-battery hud", "ai-battery hud rail", "ai-battery hud stack", "ai-battery hud autostart on"])
202
+ examples(isDesktop
203
+ ? ["ai-battery hud", "ai-battery hud rail", "ai-battery hud rail --scale 1.25", "ai-battery hud autostart on"]
204
+ : ["ai-battery hud", "ai-battery hud rail", "ai-battery hud stack", "ai-battery hud autostart on"])
188
205
  ].join("\n\n");
189
206
  }
190
207
  return [