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.
package/lib/cli.js CHANGED
@@ -21,6 +21,10 @@ 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, formatVisibilityResult } from "./core/cli-output.js";
23
23
  import { codexTerminalDisplay, claudeTerminalDisplay } from "./core/diagnostics.js";
24
+ import { PROVIDERS, STATUS_LINE_ITEMS, normalizeOrder, parseOrder, orderResults, providerId, providerLabel } from "./core/display-config.js";
25
+ import { canEditConfig, editDisplayConfig } from "./core/config-editor.js";
26
+ import { branchChanges } from "./core/statusline-git.js";
27
+ import { createAntigravityIntegration } from "./providers/antigravity.js";
24
28
  import {
25
29
  cacheAgeSeconds,
26
30
  clamp,
@@ -67,24 +71,25 @@ const COMMANDS = new Set([
67
71
  "teardown",
68
72
  "uninstall",
69
73
  "doctor",
74
+ "config",
70
75
  "hud",
71
76
  "on",
72
77
  "off",
73
78
  "capture-claude",
79
+ "capture-antigravity",
74
80
  "install-claude-statusline",
75
81
  "uninstall-claude-statusline"
76
82
  ]);
77
- const PROVIDERS = ["codex", "claude"];
78
- const TEARDOWN_TARGETS = ["codex", "claude", "hud", "tmux"];
83
+ const TEARDOWN_TARGETS = [...PROVIDERS, "hud", "tmux"];
79
84
  const CODEX_WRAPPER_MARKER = "AI_BATTERY_MANAGED_CODEX_WRAPPER";
80
85
  const CODEX_WRAPPER_BRIDGE_MARKER = "AI_BATTERY_MANAGED_CODEX_BRIDGE";
81
86
  const CODEX_PATH_LOOKUP_MARKER = "AI_BATTERY_CODEX_PATH_LOOKUP=1";
82
87
  const CODEX_PATH_ONLY_MARKER = "AI_BATTERY_CODEX_PATH_ONLY=1";
83
88
  const CODEX_PREFERRED_BACKUP_SUFFIX = ".ai-battery-original-link";
84
89
  const CODEX_TIMESTAMP_BACKUP_MARKER = ".ai-battery-backup-";
85
- const CODEX_STATUS_LINE = ["model-with-reasoning", "current-dir", "git-branch"];
90
+ const CODEX_STATUS_LINE = STATUS_LINE_ITEMS;
86
91
  const DEFAULT_STATUSLINE_HEADER_COLUMN_GUARD = 2;
87
- const CODEX_MENU_BAR_COLOR = "#315CFF";
92
+ const CODEX_MENU_BAR_COLOR = "#000000";
88
93
  const CLAUDE_MENU_BAR_COLOR = "#D97706";
89
94
  const MENU_BAR_WHITE = "#FFFFFF";
90
95
  const MENU_DETAIL_GREEN = "#30D158";
@@ -116,7 +121,8 @@ function parseArgs(argv) {
116
121
  silent: false,
117
122
  force: false,
118
123
  wrapCodex: true,
119
- configureCodexStatusLine: false,
124
+ configureCodexStatusLine: true,
125
+ providerOrder: null,
120
126
  attachHud: false,
121
127
  header: true,
122
128
  usageRow: "auto",
@@ -172,6 +178,11 @@ function parseArgs(argv) {
172
178
  args.wrapCodex = false;
173
179
  } else if (arg === "--configure-codex-statusline") {
174
180
  args.configureCodexStatusLine = true;
181
+ } else if (arg === "--provider-order") {
182
+ const value = requiredValue(argv, i, args.command);
183
+ try { args.providerOrder = parseOrder(value, PROVIDERS, "--provider-order"); }
184
+ catch { throw cliError("--provider-order requires unique comma-separated tools: codex, claude, gemini.", "--provider-order에 codex, claude, gemini를 쉼표로 구분하고 중복 없이 입력하세요.", args.command); }
185
+ i += 1;
175
186
  } else if (arg === "--attach-hud") {
176
187
  args.attachHud = true;
177
188
  } else if (arg === "--watch" || arg === "-w") {
@@ -225,17 +236,21 @@ function parseArgs(argv) {
225
236
  }
226
237
 
227
238
  args.helpTopic = commandSeen ? args.command : "";
228
- if (!["all", "codex", "claude"].includes(args.provider)) {
229
- throw invalidChoice("--provider", "all, codex, claude", args.helpTopic);
239
+ args.provider = providerId(args.provider);
240
+ args.activeProvider = providerId(args.activeProvider);
241
+ args.targets = args.targets.map(providerId);
242
+ if (!["all", ...PROVIDERS].includes(args.provider)) {
243
+ throw invalidChoice("--provider", "all, codex, claude, gemini", args.helpTopic);
230
244
  }
231
- if (args.activeProvider && !["codex", "claude"].includes(args.activeProvider)) {
232
- throw invalidChoice("--active-provider", "codex, claude", args.helpTopic);
245
+ if (args.activeProvider && !PROVIDERS.includes(args.activeProvider)) {
246
+ throw invalidChoice("--active-provider", "codex, claude, gemini", args.helpTopic);
233
247
  }
248
+ if (args.providerOrder && !["config", "setup"].includes(args.command)) throw cliError("--provider-order requires config or setup.", "--provider-order는 config 또는 setup에서 사용하세요.", args.helpTopic);
234
249
  if (args.targets.length) {
235
250
  const choices = args.command === "setup" ? [...PROVIDERS, "tmux", "all"]
236
251
  : ["on", "off"].includes(args.command) ? [...PROVIDERS, "all"] : [...TEARDOWN_TARGETS, "all"];
237
252
  if (args.targets.some((target) => !choices.includes(target))) {
238
- throw invalidChoice("target", choices.join(", "), args.command);
253
+ throw invalidChoice("target", choices.map(target => target === "antigravity" ? "gemini" : target).join(", "), args.command);
239
254
  }
240
255
  }
241
256
 
@@ -376,11 +391,14 @@ function defaultConfig() {
376
391
  version: 1,
377
392
  providers: {
378
393
  codex: true,
379
- claude: true
394
+ claude: true,
395
+ antigravity: true
380
396
  },
397
+ providerOrder: [...PROVIDERS],
381
398
  codexWrapper: null,
382
399
  codexStatusLineBackup: null,
383
- claudeStatusLineBackup: null
400
+ claudeStatusLineBackup: null,
401
+ antigravityStatusLineBackup: null
384
402
  };
385
403
  }
386
404
 
@@ -422,6 +440,14 @@ function providerVisible(provider) {
422
440
  return config.providers?.[provider] !== false;
423
441
  }
424
442
 
443
+ function configuredProviderOrder() {
444
+ return normalizeOrder(readConfig().providerOrder, PROVIDERS);
445
+ }
446
+
447
+ function antigravityAvailable() {
448
+ return fs.existsSync(antigravity.cachePath()) || fs.existsSync(antigravity.settingsPath());
449
+ }
450
+
425
451
  function providerTargets(targets) {
426
452
  const requested = targets.length ? targets : ["all"];
427
453
  const providers = new Set();
@@ -1369,6 +1395,13 @@ function codexStatusLineMatches(text) {
1369
1395
  && useColors === "false";
1370
1396
  }
1371
1397
 
1398
+ function managedCodexStatusLineMatches(text) {
1399
+ if (codexStatusLineMatches(text)) return true;
1400
+ // Keep reset compatible with the three-item configuration installed before 0.1.29.
1401
+ return isDeepStrictEqual(parseTomlStringArray(tomlSectionValue(text, "tui", "status_line")), ["model-with-reasoning", "current-dir", "git-branch"])
1402
+ && String(tomlSectionValue(text, "tui", "status_line_use_colors") || "").toLowerCase() === "false";
1403
+ }
1404
+
1372
1405
  function managedCodexStatusLineText(text) {
1373
1406
  return upsertTomlSectionKeys(text || "", "tui", codexStatusLineSettings());
1374
1407
  }
@@ -1469,7 +1502,7 @@ function restoreCodexStatusLine(config) {
1469
1502
  }
1470
1503
 
1471
1504
  const currentText = fs.readFileSync(configPath, "utf8");
1472
- if (!codexStatusLineMatches(currentText) && codexStatusLineValuesMatch(currentText, backup.text)) {
1505
+ if (!managedCodexStatusLineMatches(currentText) && codexStatusLineValuesMatch(currentText, backup.text)) {
1473
1506
  config.codexStatusLineBackup = null;
1474
1507
  return {
1475
1508
  changed: false,
@@ -1480,7 +1513,7 @@ function restoreCodexStatusLine(config) {
1480
1513
  };
1481
1514
  }
1482
1515
  if (backup.text === null) {
1483
- if (!codexStatusLineMatches(currentText)) {
1516
+ if (!managedCodexStatusLineMatches(currentText)) {
1484
1517
  return {
1485
1518
  changed: false,
1486
1519
  skipped: true,
@@ -1503,7 +1536,7 @@ function restoreCodexStatusLine(config) {
1503
1536
  };
1504
1537
  }
1505
1538
 
1506
- if (!codexStatusLineMatches(currentText)) {
1539
+ if (!managedCodexStatusLineMatches(currentText)) {
1507
1540
  return {
1508
1541
  changed: false,
1509
1542
  skipped: true,
@@ -2050,12 +2083,14 @@ async function runDoctor() {
2050
2083
  codexWrapper: Boolean(recoveryConfig.codexWrapper),
2051
2084
  codexStatusLine: Boolean(recoveryConfig.codexStatusLineBackup),
2052
2085
  claudeStatusLine: Boolean(recoveryConfig.claudeStatusLineBackup),
2086
+ antigravityStatusLine: Boolean(recoveryConfig.antigravityStatusLineBackup),
2053
2087
  claudeOriginalKnown: recoveryConfig.claudeStatusLineBackup
2054
2088
  ? !recoveryConfig.claudeStatusLineBackup.legacyOriginalUnknown
2055
2089
  : null
2056
2090
  }
2057
2091
  },
2058
2092
  codex: diagnoseCodex(),
2093
+ antigravity: antigravity.diagnose(),
2059
2094
  ...(process.platform !== "win32" ? { tmux: diagnoseTmux() } : {}),
2060
2095
  claude: {
2061
2096
  providerEnabled: providerVisible("claude"),
@@ -2246,13 +2281,18 @@ function setupTargets(targets) {
2246
2281
  } else if (PROVIDERS.includes(target) || target === "tmux") {
2247
2282
  selected.add(target);
2248
2283
  } else {
2249
- throw new Error("target must be one of: codex, claude, tmux, all");
2284
+ throw new Error("target must be one of: codex, claude, gemini, tmux, all");
2250
2285
  }
2251
2286
  }
2252
2287
  return [...selected];
2253
2288
  }
2254
2289
 
2255
2290
  function runSetup(args) {
2291
+ if (args.providerOrder) {
2292
+ const config = readConfig({ strict: true });
2293
+ config.providerOrder = args.providerOrder;
2294
+ writeConfig(config);
2295
+ }
2256
2296
  const targets = setupTargets(args.targets);
2257
2297
  const previous = readConfig({ strict: true });
2258
2298
  let tmuxRefreshPath = null;
@@ -2278,6 +2318,7 @@ function runSetup(args) {
2278
2318
  results.claude = statusLine;
2279
2319
  }
2280
2320
  }
2321
+ if (targets.includes("antigravity")) results.antigravity = antigravity.install(args);
2281
2322
  if (targets.includes("tmux")) {
2282
2323
  results.tmux = installTmuxStatus(tmuxRefreshPath ? { confPath: tmuxRefreshPath } : {});
2283
2324
  }
@@ -2316,6 +2357,7 @@ function runSetup(args) {
2316
2357
  function setupResultFailed(result) {
2317
2358
  return Boolean(
2318
2359
  result.claude?.error
2360
+ || result.antigravity?.error
2319
2361
  || result.claude?.launcher?.error
2320
2362
  || (result.claude?.launcher && result.claude.launcher.ok === false)
2321
2363
  || (result.codex && result.codex.ok === false)
@@ -2398,6 +2440,7 @@ function runTeardown(args) {
2398
2440
  if (targets.includes("claude")) {
2399
2441
  runStep("claude", () => uninstallClaudeStatusline({ strict: false }));
2400
2442
  }
2443
+ if (targets.includes("antigravity")) runStep("antigravity", antigravity.uninstall);
2401
2444
  if (targets.includes("codex")) {
2402
2445
  runStep("codex", uninstallCodexWrapper);
2403
2446
  }
@@ -2420,7 +2463,7 @@ function runTeardown(args) {
2420
2463
  results.artifacts = cleanupBatteryArtifacts({
2421
2464
  roots,
2422
2465
  home: userHome(),
2423
- protectedRoots: [codexRuntimeHome(), homePath(".claude"), path.resolve(scriptDir(), "..")]
2466
+ protectedRoots: [codexRuntimeHome(), homePath(".claude"), homePath(".gemini"), path.resolve(scriptDir(), "..")]
2424
2467
  });
2425
2468
  }
2426
2469
  return {
@@ -2747,6 +2790,11 @@ const {
2747
2790
  scanCacheSeconds,
2748
2791
  writeScanCache
2749
2792
  });
2793
+ const antigravity = createAntigravityIntegration({
2794
+ homePath, stateDir, readJson, readUserJsonObject, readConfig, writeConfig,
2795
+ writeJsonAtomic, samePath, shellArg, scriptDir, isProviderRunning
2796
+ });
2797
+
2750
2798
  function readStdin() {
2751
2799
  return new Promise((resolve, reject) => {
2752
2800
  let input = "";
@@ -3230,6 +3278,7 @@ function installClaudeStatusline(args) {
3230
3278
  "--left-padding",
3231
3279
  "1"
3232
3280
  ];
3281
+ if (args.header === false) commandParts.push("--no-header");
3233
3282
  if (args.usageRow === false || (process.platform === "win32" && args.usageRow !== true)) commandParts.push("--no-usage-row");
3234
3283
  if (args.usageRow === true) commandParts.push("--usage-row");
3235
3284
  if (process.platform === "win32") commandParts.push("--attach-hud");
@@ -4270,19 +4319,6 @@ function contextLeftText(input, fallbackContext = null) {
4270
4319
  return `${remaining}% context left`;
4271
4320
  }
4272
4321
 
4273
- function alignHeader(left, right, columns) {
4274
- if (!right) return left;
4275
-
4276
- const gap = 2;
4277
- const rightWidth = visibleWidth(right);
4278
- if (!columns || columns <= rightWidth + gap) return `${left} ${right}`;
4279
-
4280
- const leftBudget = columns - rightWidth - gap;
4281
- const fittedLeft = truncateMiddleVisible(left, leftBudget);
4282
- const spaces = Math.max(gap, columns - visibleWidth(fittedLeft) - rightWidth);
4283
- return `${fittedLeft}${" ".repeat(spaces)}${right}`;
4284
- }
4285
-
4286
4322
  function displayPath(dir) {
4287
4323
  if (!dir) return "~";
4288
4324
  const home = userHome();
@@ -4336,15 +4372,15 @@ function statuslineGitBranch(input) {
4336
4372
  function claudeHeader(input, args, capturedClaude = null) {
4337
4373
  const model = typeof input.model === "string"
4338
4374
  ? input.model
4339
- : input.model?.display_name || input.model?.displayName || input.model?.id || "Claude";
4340
- const effort = input.effort?.level || input.effortLevel || null;
4341
- const workspaceRoot = input.workspace?.project_dir
4342
- || input.workspace?.projectDir
4375
+ : input.model?.display_name || input.model?.displayName || input.model?.id || (input.product === "antigravity" ? providerLabel("antigravity") : "Claude");
4376
+ const effort = input.model?.effort || (typeof input.effort === "string" ? input.effort : input.effort?.level) || input.effortLevel || null;
4377
+ const workspaceRoot = input.workspace?.current_dir
4378
+ || input.workspace?.currentDir
4343
4379
  || input.cwd
4344
4380
  || input.current_dir
4345
4381
  || input.currentDir
4346
- || input.workspace?.current_dir
4347
- || input.workspace?.currentDir
4382
+ || input.workspace?.project_dir
4383
+ || input.workspace?.projectDir
4348
4384
  || "";
4349
4385
  const gitBranch = statuslineGitBranch(input);
4350
4386
  const parts = [model];
@@ -4355,10 +4391,12 @@ function claudeHeader(input, args, capturedClaude = null) {
4355
4391
  parts.push("·");
4356
4392
  parts.push(gitBranch);
4357
4393
  }
4358
- const left = parts.join(" ");
4359
- const right = contextLeftText(input, capturedClaude?.contextWindow ?? null);
4394
+ const changes = branchChanges(workspaceRoot);
4395
+ if (changes) parts.push("·", changes);
4396
+ const context = contextLeftText(input, capturedClaude?.contextWindow ?? null);
4397
+ if (context) parts.push("·", context);
4360
4398
  const columns = statusLineHeaderColumns(input, args);
4361
- const header = alignHeader(left, right, columns);
4399
+ const header = truncateMiddleVisible(parts.join(" "), columns);
4362
4400
  return statusColorize({ running: false }, header, args);
4363
4401
  }
4364
4402
 
@@ -4397,18 +4435,16 @@ function formatCodex(data, args) {
4397
4435
  `${statusColorize(data, "Codex ", args)}${bar(data.percentRemaining, args.barWidth, batteryColor, args.style)}${statusColorize(data, ` ${Number.isFinite(data.percentRemaining) ? data.percentRemaining : "--"}%`, args)}`
4398
4436
  ];
4399
4437
 
4400
- // Compact drops the reset/week detail so the core "Codex ▓ 51%" survives a
4401
- // terminal too narrow to hold both providers in full (see render()).
4402
- if (!args.compact) {
4438
+ if (args.showPrimary !== false) {
4403
4439
  const primaryReset = limitResetText(primary);
4404
4440
  if (primaryReset) {
4405
4441
  bits.push(divider(args));
4406
4442
  bits.push(statusColorize(data, primaryReset, args));
4407
4443
  }
4408
- if (secondary) {
4409
- bits.push(divider(args));
4410
- bits.push(statusColorize(data, weekText(secondary), args));
4411
- }
4444
+ }
4445
+ if (args.showSecondary !== false && secondary) {
4446
+ bits.push(divider(args));
4447
+ bits.push(statusColorize(data, weekText(secondary), args));
4412
4448
  }
4413
4449
  if (data.reachedType) {
4414
4450
  bits.push(statusColorize(data, `limit ${data.reachedType}`, args));
@@ -4431,16 +4467,16 @@ function formatClaude(data, args) {
4431
4467
  const bits = [
4432
4468
  `${statusColorize(data, "Claude ", args)}${bar(data.percentRemaining, args.barWidth, batteryColor, args.style)}${statusColorize(data, ` ${data.percentRemaining}%`, args)}`
4433
4469
  ];
4434
- if (!args.compact) {
4470
+ if (args.showPrimary !== false) {
4435
4471
  const primaryReset = limitResetText(data.primary);
4436
4472
  if (primaryReset) {
4437
4473
  bits.push(divider(args));
4438
4474
  bits.push(statusColorize(data, primaryReset, args));
4439
4475
  }
4440
- if (data.secondary) {
4441
- bits.push(divider(args));
4442
- bits.push(statusColorize(data, weekText(data.secondary), args));
4443
- }
4476
+ }
4477
+ if (args.showSecondary !== false && data.secondary) {
4478
+ bits.push(divider(args));
4479
+ bits.push(statusColorize(data, weekText(data.secondary), args));
4444
4480
  }
4445
4481
  if (args.showPaths) {
4446
4482
  const seen = ageText(data.ageSeconds);
@@ -4453,8 +4489,10 @@ function formatClaude(data, args) {
4453
4489
  const bits = [
4454
4490
  `${statusColorize(data, "Claude ", args)}${bar(null, args.barWidth, "gray", args.style)}${statusColorize(data, " --%", args)}`
4455
4491
  ];
4456
- if (!args.compact) {
4492
+ if (args.showPrimary !== false) {
4457
4493
  bits.push(divider(args), statusColorize(data, "5h --:--", args));
4494
+ }
4495
+ if (args.showSecondary !== false) {
4458
4496
  bits.push(divider(args), statusColorize(data, "7d ---%", args));
4459
4497
  }
4460
4498
 
@@ -4462,6 +4500,23 @@ function formatClaude(data, args) {
4462
4500
  return bits.join(" ");
4463
4501
  }
4464
4502
 
4503
+ function formatAntigravity(data, args) {
4504
+ const name = providerLabel("antigravity");
4505
+ if (!data.ok || typeof data.percentRemaining !== "number") {
4506
+ const amounts = data.quotas?.filter(quota => quota.remainingAmount !== null)
4507
+ .map(quota => `${quota.id} ${quota.remainingAmount}`).join(" · ");
4508
+ return statusColorize(data, amounts && args.showSecondary !== false ? `${name} ${amounts}` : `${name} --%`, args);
4509
+ }
4510
+ const bits = [`${statusColorize(data, `${name} `, args)}${bar(data.percentRemaining, args.barWidth, remainingColor(data.percentRemaining), args.style)}${statusColorize(data, ` ${data.percentRemaining}%`, args)}`];
4511
+ if (args.showPrimary !== false && data.primary) {
4512
+ const label = data.primary.windowMinutes ? shortWindow(data.primary.windowMinutes) : data.primary.id;
4513
+ bits.push(divider(args), statusColorize(data, `${label} ${resetClock(data.primary)}`, args));
4514
+ }
4515
+ if (args.showSecondary !== false && data.secondary) bits.push(divider(args), statusColorize(data, weekText(data.secondary), args));
4516
+ if (args.showPaths) bits.push(statusColorize(data, data.source || antigravity.cachePath(), args));
4517
+ return bits.join(" ");
4518
+ }
4519
+
4465
4520
  function compactNumber(value) {
4466
4521
  const number = Number(value) || 0;
4467
4522
  if (number >= 1_000_000) return `${(number / 1_000_000).toFixed(1)}M`;
@@ -4486,9 +4541,12 @@ function collect(args) {
4486
4541
  if ((args.provider === "all" || args.provider === "claude") && (includeHidden || providerVisible("claude"))) {
4487
4542
  results.push(readClaude({ runningOverride: runningOverrideForProvider(args, "claude") }));
4488
4543
  }
4544
+ if ((args.provider === "antigravity" || (args.provider === "all" && providerVisible("antigravity") && antigravityAvailable()))) {
4545
+ results.push(antigravity.read({ runningOverride: runningOverrideForProvider(args, "antigravity") }));
4546
+ }
4489
4547
  return {
4490
4548
  generatedAt: new Date().toISOString(),
4491
- results
4549
+ results: orderResults(results, configuredProviderOrder())
4492
4550
  };
4493
4551
  }
4494
4552
 
@@ -4498,6 +4556,7 @@ function renderLine(snapshot, args) {
4498
4556
  .map((result) => {
4499
4557
  if (result.provider === "codex") return formatCodex(result, args);
4500
4558
  if (result.provider === "claude") return formatClaude(result, args);
4559
+ if (result.provider === "antigravity") return formatAntigravity(result, args);
4501
4560
  return `${result.provider} ?`;
4502
4561
  })
4503
4562
  .join(providerDivider);
@@ -4506,7 +4565,8 @@ function renderLine(snapshot, args) {
4506
4565
  function renderMenuBar(snapshot) {
4507
4566
  const marks = {
4508
4567
  codex: "◎",
4509
- claude: "✳"
4568
+ claude: "✳",
4569
+ antigravity: "△"
4510
4570
  };
4511
4571
  const meter = (percent) => {
4512
4572
  if (typeof percent !== "number") return "";
@@ -4517,7 +4577,7 @@ function renderMenuBar(snapshot) {
4517
4577
  return `${"▰".repeat(full)}${"▱".repeat(width - full)}`;
4518
4578
  };
4519
4579
 
4520
- const parts = snapshot.results
4580
+ const parts = orderResults(snapshot.results, configuredProviderOrder())
4521
4581
  .map((result) => {
4522
4582
  const mark = marks[result.provider] || "?";
4523
4583
  if (!result.ok || typeof result.percentRemaining !== "number") return `${mark} --`;
@@ -4739,6 +4799,10 @@ function renderMenuBarSvgIcon(icon, x, y, height) {
4739
4799
  }
4740
4800
 
4741
4801
  function menuBarImageIcon(provider, x, y) {
4802
+ if (provider === "antigravity") {
4803
+ const svg = fs.readFileSync(path.join(scriptDir(), "..", "docs", "antigravity-icon.svg"), "utf8");
4804
+ 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">`);
4805
+ }
4742
4806
  const height = provider === "codex" ? 19 : 17;
4743
4807
  const iconY = provider === "codex" ? y - 0.5 : y;
4744
4808
  if (provider === "codex") {
@@ -4760,7 +4824,7 @@ function renderMenuBarImage(snapshot) {
4760
4824
  const providerWidth = 56;
4761
4825
  const providerContentWidth = 48;
4762
4826
  const height = 24;
4763
- const visibleResults = snapshot.results.filter(Boolean);
4827
+ const visibleResults = orderResults(snapshot.results.filter(Boolean), configuredProviderOrder());
4764
4828
  const width = visibleResults.length
4765
4829
  ? startX + ((visibleResults.length - 1) * providerWidth) + providerContentWidth + endPadding
4766
4830
  : 54;
@@ -4820,7 +4884,7 @@ function renderMenuBarImage(snapshot) {
4820
4884
 
4821
4885
  function menuDetailLimitText(limit) {
4822
4886
  if (!limit) return null;
4823
- const label = shortWindow(limit.windowMinutes);
4887
+ const label = limit.windowMinutes ? shortWindow(limit.windowMinutes) : limit.id || "?";
4824
4888
  if (label === "5h") return `${label} ${resetClock(limit)}`;
4825
4889
  if (typeof limit.remainingPercent === "number") return `${label} ${limit.remainingPercent}%`;
4826
4890
  return `${label} ${resetClock(limit)}`;
@@ -4866,9 +4930,9 @@ function menuDetailUsageUpdateText(result) {
4866
4930
  }
4867
4931
 
4868
4932
  function renderMenuDetailImage(snapshot) {
4869
- const visibleResults = snapshot.results.filter(Boolean);
4933
+ const visibleResults = orderResults(snapshot.results.filter(Boolean), configuredProviderOrder());
4870
4934
  const rows = visibleResults.length ? visibleResults : [{ provider: "ai", ok: false }];
4871
- const width = 392;
4935
+ const width = rows.some(row => row.provider === "antigravity") ? 420 : 392;
4872
4936
  const usageTexts = rows.map(menuDetailUsageUpdateText);
4873
4937
  const hasUsageText = usageTexts.some(Boolean);
4874
4938
  const rowHeight = hasUsageText ? 46 : 36;
@@ -4884,13 +4948,13 @@ function renderMenuDetailImage(snapshot) {
4884
4948
  const baseline = y + (hasUsageText ? 19 : 22);
4885
4949
  const usageBaseline = y + 38;
4886
4950
  const usageText = usageTexts[index];
4887
- const provider = result.provider === "codex" ? "Codex" : result.provider === "claude" ? "Claude" : "AI";
4951
+ const provider = providerLabel(result.provider);
4888
4952
  const running = result.running === true;
4889
4953
  const percent = typeof result.percentRemaining === "number" ? clamp(result.percentRemaining, 0, 100) : null;
4890
4954
  const fillWidth = percent === null ? 0 : Math.max(percent > 0 ? 3 : 0, Math.round((percent / 100) * barWidth));
4891
4955
  const fill = menuBatteryColor(percent, running);
4892
4956
  const percentText = percent === null ? "--%" : `${Math.round(percent)}%`;
4893
- const metaText = result.ok ? menuDetailMetaText(result) : "unavailable";
4957
+ const metaText = truncateMiddleVisible(result.ok ? menuDetailMetaText(result) : "unavailable", 20);
4894
4958
  const barY = baseline - barHeight;
4895
4959
  const primaryFill = running ? "#F5F5F7" : MENU_DIM_TEXT;
4896
4960
  const metaFill = running ? MENU_DIM_TEXT : "#8E8E93";
@@ -4942,7 +5006,7 @@ function desktopHudSnapshot(provider = "all") {
4942
5006
  text: renderLine(snapshot, { ...args, style: "plain" }),
4943
5007
  rows: snapshot.results.filter(Boolean).map((result) => ({
4944
5008
  provider: result.provider,
4945
- label: result.provider === "codex" ? "Codex" : "Claude",
5009
+ label: providerLabel(result.provider),
4946
5010
  percent: typeof result.percentRemaining === "number" ? clamp(result.percentRemaining, 0, 100) : null,
4947
5011
  running: result.running === true,
4948
5012
  meta: result.ok ? menuDetailMetaText(result) : "unavailable",
@@ -4963,6 +5027,7 @@ function applyLeftPadding(output, args) {
4963
5027
  }
4964
5028
 
4965
5029
  function render(snapshot, args) {
5030
+ snapshot = { ...snapshot, results: orderResults(snapshot.results, configuredProviderOrder()) };
4966
5031
  if (args.json) return JSON.stringify(snapshot, null, 2);
4967
5032
  if (args.hudState) return renderHudState(snapshot);
4968
5033
  if (args.menuBarImage) return renderMenuBarImage(snapshot);
@@ -4970,28 +5035,31 @@ function render(snapshot, args) {
4970
5035
  if (args.menuBar) return renderMenuBar(snapshot);
4971
5036
 
4972
5037
  const maxWidth = args.maxWidth
4973
- ? Math.max(20, args.maxWidth - (Number(args.leftPadding) || 0))
5038
+ ? Math.max(1, args.maxWidth - (Number(args.leftPadding) || 0))
4974
5039
  : null;
4975
5040
 
4976
5041
  if (args.maxWidth) {
4977
- // First shrink the bars. If the line still overflows at the minimum bar
4978
- // width, switch to compact (drop the reset/week detail) and shrink again,
4979
- // so a narrow terminal keeps every provider's core reading instead of
4980
- // hard-truncating the tail — which would silently drop the last provider.
4981
- let lastLine = null;
4982
- for (const compact of [false, true]) {
4983
- for (let width = args.barWidth; width >= 4; width -= 1) {
4984
- const trialArgs = { ...args, barWidth: width, compact };
4985
- lastLine = renderLine(snapshot, trialArgs);
4986
- if (visibleWidth(lastLine) <= maxWidth) return applyLeftPadding(lastLine, args);
4987
- }
5042
+ // Use exact 10%, 20% or 25% steps. Keep 5h reset times after dropping
5043
+ // weekly detail, before spending the available space on longer bars.
5044
+ const widths = [10, 5, 4].filter(width => width <= args.barWidth);
5045
+ const fullWidth = widths[0];
5046
+ const shortWidth = widths.find(width => width <= 5);
5047
+ const candidates = [
5048
+ { barWidth: fullWidth, showPrimary: true, showSecondary: true },
5049
+ ...(fullWidth !== shortWidth ? [{ barWidth: shortWidth, showPrimary: true, showSecondary: true }] : []),
5050
+ { barWidth: shortWidth, showPrimary: true, showSecondary: false },
5051
+ ...widths.map(barWidth => ({ barWidth, showPrimary: false, showSecondary: false }))
5052
+ ];
5053
+ for (const candidate of candidates) {
5054
+ const line = renderLine(snapshot, { ...args, ...candidate });
5055
+ if (visibleWidth(line) <= maxWidth) return applyLeftPadding(line, args);
4988
5056
  }
4989
5057
  // A split pane can be too narrow even for the minimum bars. Retain both
4990
5058
  // names and readings rather than letting the one-row terminal wrap away
4991
5059
  // a provider. Detailed errors remain available in diagnostics.
4992
5060
  const readings = snapshot.results.map((result) => {
4993
5061
  const percent = typeof result.percentRemaining === "number" ? `${result.percentRemaining}%` : "--%";
4994
- const name = result.provider === "codex" ? "Codex" : result.provider === "claude" ? "Claude" : result.provider;
5062
+ const name = providerLabel(result.provider);
4995
5063
  return statusColorize(result, `${name} ${percent}`, args);
4996
5064
  }).join(` ${colorize(PROVIDER_DIVIDER, "gray", args.style)} `);
4997
5065
  return applyLeftPadding(readings, args);
@@ -5034,6 +5102,37 @@ async function main() {
5034
5102
  return;
5035
5103
  }
5036
5104
 
5105
+ if (args.command === "config") {
5106
+ const config = readConfig({ strict: true });
5107
+ if (!args.providerOrder && !args.json && canEditConfig()) {
5108
+ const edited = await editDisplayConfig(config, { color: args.style !== "plain" && !Object.hasOwn(process.env, "NO_COLOR") });
5109
+ if (!edited) {
5110
+ console.log(cliText("Configuration cancelled.", "설정을 취소했습니다."));
5111
+ return;
5112
+ }
5113
+ // Merge with the latest settings so another process's changes survive the editor.
5114
+ const latest = readConfig({ strict: true });
5115
+ latest.providerOrder = edited.providerOrder;
5116
+ Object.assign(latest.providers, edited.providerChanges);
5117
+ writeConfig(latest);
5118
+ const visible = latest.providerOrder.filter(provider => latest.providers[provider] !== false).map(providerLabel);
5119
+ console.log(`${cliText("Display settings saved", "표시 설정 저장")}: ${visible.join(" → ") || cliText("All hidden", "모두 숨김")}`);
5120
+ return;
5121
+ }
5122
+ if (args.providerOrder) { config.providerOrder = args.providerOrder; writeConfig(config); }
5123
+ const result = { configPath: configPath(), providerOrder: normalizeOrder(config.providerOrder, PROVIDERS),
5124
+ providers: Object.fromEntries(PROVIDERS.map(provider => [provider, config.providers[provider] !== false])) };
5125
+ if (args.json) console.log(JSON.stringify(result, null, 2));
5126
+ else {
5127
+ console.log(`${cliText("Display settings", "표시 설정")}: ${result.providerOrder.map(provider => `${providerLabel(provider)}${result.providers[provider] ? "" : cliText(" (hidden)", " (숨김)")}`).join(" → ")}`);
5128
+ if (!args.providerOrder) {
5129
+ console.log(cliText("Run ai-battery config in a terminal: arrows reorder, Space shows/hides, Enter saves, Esc cancels.", "터미널에서 ai-battery config를 실행하세요: 방향키 순서 이동 · Space 표시/숨김 · Enter 저장 · Esc 취소"));
5130
+ console.log(`${cliText("Or use", "명령으로 변경")}: ai-battery config --provider-order ${result.providerOrder.map(provider => provider === "antigravity" ? "gemini" : provider).join(",")}`);
5131
+ }
5132
+ }
5133
+ return;
5134
+ }
5135
+
5037
5136
  if (["reset", "teardown", "uninstall"].includes(args.command)) {
5038
5137
  if (!args.silent && !args.json && args.command !== "reset") {
5039
5138
  console.log(cliText(`"${args.command}" is an alias for "reset".`, `"${args.command}"는 "reset"의 호환 명령입니다.`));
@@ -5082,14 +5181,16 @@ async function main() {
5082
5181
  return;
5083
5182
  }
5084
5183
 
5085
- if (args.command === "capture-claude") {
5184
+ if (args.command === "capture-claude" || args.command === "capture-antigravity") {
5185
+ const activeProvider = args.command === "capture-antigravity" ? "antigravity" : "claude";
5086
5186
  const inputText = await readStdin();
5087
- if (!inputText.trim()) throw new Error("capture-claude expected Claude statusline JSON on stdin");
5187
+ if (!inputText.trim()) throw new Error(activeProvider === "claude" ? "capture-claude expected Claude statusline JSON on stdin" : "capture-antigravity expected statusline JSON on stdin");
5088
5188
  let input;
5089
5189
  try { input = JSON.parse(inputText); }
5090
- catch { throw new Error("capture-claude received invalid JSON"); }
5091
- const capturedClaude = captureClaudeStatusline(input);
5092
- if (args.attachHud) {
5190
+ catch { throw new Error(`${args.command} received invalid JSON`); }
5191
+ if (!input || typeof input !== "object" || Array.isArray(input)) throw new Error(`${args.command} expected a JSON object`);
5192
+ const capturedClaude = activeProvider === "antigravity" ? antigravity.capture(input) : captureClaudeStatusline(input);
5193
+ if (args.attachHud && activeProvider === "claude") {
5093
5194
  attachWindowsClaudeHud(
5094
5195
  capturedClaude.sessionId,
5095
5196
  capturedClaude.workspace?.currentDir || capturedClaude.workspace?.projectDir || process.cwd(),
@@ -5098,8 +5199,10 @@ async function main() {
5098
5199
  }
5099
5200
  if (!args.silent) {
5100
5201
  const contentWidth = Math.max(20, statusLineUsableColumns(input) - (Number(args.leftPadding) || 0));
5101
- const header = args.header ? claudeHeader(input, args, capturedClaude) : "";
5102
- const usageRowVisible = claudeUsageRowVisible(args);
5202
+ const header = args.header ? claudeHeader(activeProvider === "antigravity" ? { ...input, product: "antigravity" } : input, args, capturedClaude) : "";
5203
+ const usageRowVisible = activeProvider === "antigravity"
5204
+ ? (typeof args.usageRow === "boolean" ? args.usageRow : booleanEnvValue(process.env.AI_BATTERY_ANTIGRAVITY_USAGE_ROW) ?? !tmuxStatusBarActive())
5205
+ : claudeUsageRowVisible(args);
5103
5206
  if (!usageRowVisible && header) {
5104
5207
  console.log(applyLeftPadding(header, args));
5105
5208
  return;
@@ -5110,16 +5213,21 @@ async function main() {
5110
5213
  if (codexData) results.push(codexData);
5111
5214
  }
5112
5215
  if ((args.provider === "all" || args.provider === "claude") && providerVisible("claude")) {
5113
- const capturedSource = capturedClaude.sessionKind === "bg" && capturedClaude.sessionId
5114
- ? claudeSessionCachePath(capturedClaude.sessionId)
5115
- : claudeCachePath();
5116
- const claudeData = claudeStatuslineResultFromCache(capturedClaude, capturedSource, { includeBackground: true }) ?? readClaude();
5117
- results.push({ ...claudeData, running: true });
5216
+ if (activeProvider === "claude") {
5217
+ const capturedSource = capturedClaude.sessionKind === "bg" && capturedClaude.sessionId
5218
+ ? claudeSessionCachePath(capturedClaude.sessionId)
5219
+ : claudeCachePath();
5220
+ const claudeData = claudeStatuslineResultFromCache(capturedClaude, capturedSource, { includeBackground: true }) ?? readClaude();
5221
+ results.push({ ...claudeData, running: true });
5222
+ } else results.push(readClaude());
5223
+ }
5224
+ if ((args.provider === "all" || args.provider === "antigravity") && providerVisible("antigravity") && (activeProvider === "antigravity" || antigravityAvailable())) {
5225
+ results.push(antigravity.read({ runningOverride: activeProvider === "antigravity" ? true : null }));
5118
5226
  }
5119
5227
  const usage = render({
5120
5228
  generatedAt: new Date().toISOString(),
5121
5229
  results
5122
- }, { ...args, activeProvider: "claude", leftPadding: 0, maxWidth: contentWidth });
5230
+ }, { ...args, activeProvider, leftPadding: 0, maxWidth: contentWidth });
5123
5231
  // Inside tmux with the status-bar integration, the battery already shows
5124
5232
  // in tmux's own bar; keep the statusline to the one line tmux can't show.
5125
5233
  const text = !usageRowVisible
@@ -5167,6 +5275,7 @@ async function main() {
5167
5275
  export {
5168
5276
  bar,
5169
5277
  claudeHeader,
5278
+ configuredProviderOrder,
5170
5279
  claudeNativeSessionOwnerPid,
5171
5280
  claudeStateDir,
5172
5281
  commandMatchesProvider,
@@ -5200,6 +5309,7 @@ export {
5200
5309
  removeAiBatteryShellPathBlock,
5201
5310
  percentValue,
5202
5311
  providerRunningInProcesses,
5312
+ render,
5203
5313
  renderHudState,
5204
5314
  renderMenuBarImage,
5205
5315
  renderMenuDetailImage,