ai-battery 0.1.13 → 0.1.15

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/README.md CHANGED
@@ -54,7 +54,7 @@ Codex 86% │ 5h 18:09 │ 7d 82% ┃ Claude 4% │ 5h 18:10 │ 7d 71%
54
54
  | `ai-battery setup codex` | 지원 | 지원 | 지원 | 지원 | Codex `[tui].status_line`을 맞추고, Windows는 `codex.cmd` wrapper, WSL/Linux/macOS는 POSIX shell wrapper를 설치합니다. |
55
55
  | `ai-battery hud` | 지원 | 지원 | 미지원 | 지원 | Windows/WSL은 PowerShell/WinForms HUD, macOS는 menu bar status item입니다. |
56
56
 
57
- 실행 중 감지(흰색/회색 표시)는 Linux/WSL은 `/proc`, macOS는 `ps`, Windows는 PowerShell 프로세스 목록을 사용합니다.
57
+ 실행 중 감지는 Linux/WSL은 `/proc`, macOS는 `ps`, Windows는 PowerShell 프로세스 목록을 사용합니다. 텍스트 출력은 흰색/회색으로, macOS HUD는 실행 중인 항목만 색상 배터리바로 강조하고 비실행 항목은 흐린 회색 계열로 표시합니다.
58
58
 
59
59
  ## Install
60
60
 
@@ -247,7 +247,7 @@ Claude가 한 번 이상 statusLine payload를 전달해야 Claude의 사용량
247
247
 
248
248
  ## Desktop HUD
249
249
 
250
- 일반 터미널 위에 외부 프로세스가 안전하게 status line을 덧그리는 방식은 안정적이지 않습니다. 그래서 Windows에서는 floating overlay를, macOS에서는 상단 menu bar status item을 제공합니다. Windows native에서는 WSL 없이 PowerShell/WinForms로 바로 실행되고, WSL에서는 `powershell.exe`를 통해 같은 HUD를 띄웁니다. macOS에서는 투명 배경의 작은 SVG 이미지로 Codex와 Claude 로고, 짧은 미터, 퍼센트만 표시하고, 클릭하면 자세한 상태를 볼 수 있습니다.
250
+ 일반 터미널 위에 외부 프로세스가 안전하게 status line을 덧그리는 방식은 안정적이지 않습니다. 그래서 Windows에서는 floating overlay를, macOS에서는 상단 menu bar status item을 제공합니다. Windows native에서는 WSL 없이 PowerShell/WinForms로 바로 실행되고, WSL에서는 `powershell.exe`를 통해 같은 HUD를 띄웁니다. macOS에서는 투명 배경의 작은 SVG 이미지로 Codex와 Claude 로고, 짧은 미터, 퍼센트를 표시하고, 클릭하면 자세한 상태를 볼 수 있습니다.
251
251
 
252
252
  ```bash
253
253
  ai-battery hud
@@ -272,6 +272,11 @@ Claude [battery:76] │ 5h 00:47 │ 7d 59%
272
272
  | `ai-battery hud -Once` | 콘솔에서 한 번만 출력합니다. |
273
273
  | `ai-battery hud -Interval 2` | 갱신 주기를 바꿉니다. |
274
274
  | `ai-battery hud -Mode tray` | Windows tray icon 모드로 실행합니다. macOS에서는 menu bar item이 기본입니다. |
275
+ | `ai-battery hud light` / `ai-battery hud dark` | Windows floating HUD를 밝은 작업표시줄용 검은 글자 또는 어두운 작업표시줄용 흰 글자로 바꿉니다. |
276
+ | `ai-battery hud black` / `ai-battery hud white` | 글자색을 직접 검은색 또는 흰색으로 바꿉니다. |
277
+ | `ai-battery hud --backdrop` / `ai-battery hud --no-backdrop` | Windows floating HUD 글자 뒤 어두운 backing을 켜거나 끕니다. |
278
+
279
+ Windows floating HUD는 기본적으로 투명 배경에 밝은 글자로 표시합니다. 밝은 작업표시줄에서는 `ai-battery hud light`, 어두운 작업표시줄에서는 `ai-battery hud dark`를 쓰면 됩니다. 글자색으로 직접 고르려면 `ai-battery hud black` 또는 `ai-battery hud white`를 쓰세요. 로그인 자동 실행에도 같은 모드를 저장하려면 `ai-battery hud autostart on light`처럼 붙이면 됩니다.
275
280
 
276
281
  Windows autostart는 `HKCU\Software\Microsoft\Windows\CurrentVersion\Run`에 사용자 단위로 등록됩니다. Windows native에서는 WSL 없이 바로 실행되고, WSL에서 등록한 경우에는 HUD 스크립트 사본을 `%LOCALAPPDATA%\ai-battery`에 둡니다. macOS autostart는 `~/Library/LaunchAgents/com.ai-battery.hud.plist`로 등록됩니다. ai-battery를 업데이트한 뒤에는 `ai-battery hud autostart on`을 다시 실행해 등록 경로를 갱신하세요.
277
282
 
@@ -104,6 +104,15 @@ function waitForFile(filePath, timeoutMs = 3500) {
104
104
  return false;
105
105
  }
106
106
 
107
+ function isDirectRun() {
108
+ if (!process.argv[1]) return false;
109
+ try {
110
+ return fs.realpathSync(process.argv[1]) === scriptPath;
111
+ } catch {
112
+ return false;
113
+ }
114
+ }
115
+
107
116
  function snapshotHasWeekly(jsonText) {
108
117
  try {
109
118
  const snapshot = JSON.parse(jsonText);
@@ -216,21 +225,41 @@ function macCommands(options) {
216
225
  return {
217
226
  title: `${envPrefix} ${node} ${batteryJs} --menu-bar-image${providerArgs} 2>/dev/null`,
218
227
  detailImage: `${envPrefix} ${node} ${batteryJs} --menu-detail-image${providerArgs} 2>/dev/null`,
219
- detail: `${envPrefix} ${node} ${batteryJs} --no-color${providerArgs} 2>/dev/null`
228
+ detail: `${envPrefix} ${node} ${batteryJs} --no-color${providerArgs} 2>/dev/null`,
229
+ state: `${envPrefix} ${node} ${batteryJs} --hud-state${providerArgs} 2>/dev/null`
220
230
  };
221
231
  }
222
232
 
223
233
  function macHudPids() {
224
- const result = spawnSync("pgrep", ["-f", macStatusPath], {
234
+ const result = spawnSync("ps", ["-axo", "pid=,args="], {
225
235
  encoding: "utf8",
226
236
  stdio: ["ignore", "pipe", "ignore"]
227
237
  });
228
238
  if (result.status !== 0) return [];
229
- return (result.stdout || "")
230
- .trim()
231
- .split(/\s+/)
232
- .map((pid) => Number(pid))
233
- .filter((pid) => Number.isInteger(pid) && pid > 0 && pid !== process.pid);
239
+ return macHudPidsFromPsOutput(result.stdout, process.pid);
240
+ }
241
+
242
+ function macHudCommandMatches(cmdline) {
243
+ const text = String(cmdline || "").trim();
244
+ if (!text.includes("ai-battery-macos-status.applescript")) return false;
245
+ if (!text.includes("--menu-bar-image") || !text.includes("--menu-detail-image")) return false;
246
+ return path.basename(text.split(/\s+/, 1)[0] || "") === "osascript";
247
+ }
248
+
249
+ function macHudPidsFromPsOutput(output, ownPid = process.pid) {
250
+ return String(output || "")
251
+ .split(/\r?\n/)
252
+ .map((line) => {
253
+ const match = line.match(/^\s*(\d+)\s+(.*)$/);
254
+ if (!match) return null;
255
+ return { pid: Number(match[1]), cmdline: match[2] };
256
+ })
257
+ .filter((proc) => proc
258
+ && Number.isInteger(proc.pid)
259
+ && proc.pid > 0
260
+ && proc.pid !== ownPid
261
+ && macHudCommandMatches(proc.cmdline))
262
+ .map((proc) => proc.pid);
234
263
  }
235
264
 
236
265
  function macLaunchAgentPath() {
@@ -351,7 +380,8 @@ function runMacHud(cliArgs) {
351
380
  commands.title,
352
381
  commands.detailImage,
353
382
  commands.detail,
354
- String(options.interval)
383
+ String(options.interval),
384
+ commands.state
355
385
  ];
356
386
 
357
387
  if (options.foreground) {
@@ -368,60 +398,249 @@ function runMacHud(cliArgs) {
368
398
  process.exit(0);
369
399
  }
370
400
 
371
- if (process.platform === "darwin") {
372
- runMacHud(process.argv.slice(2));
373
- }
374
-
375
401
  const useWsl = isWsl();
376
402
  const powershell = "powershell.exe";
377
403
 
378
- if (!useWsl && process.platform !== "win32") {
379
- console.error("ai-battery-hud: desktop HUD needs Windows (native or WSL) or macOS.");
380
- console.error("On Linux terminals use: ai-battery --watch");
381
- process.exit(1);
382
- }
383
-
384
- if (!commandExists(powershell)) {
385
- console.error("ai-battery-hud: powershell.exe is required for the Windows HUD.");
386
- process.exit(1);
387
- }
388
-
389
- const filteredArgs = [];
390
- let foreground = false;
391
- let once = false;
392
- let stop = false;
393
- let subcommand = null;
394
- let autostartAction = "status";
395
-
396
- const cliArgs = process.argv.slice(2);
397
- for (let i = 0; i < cliArgs.length; i += 1) {
398
- const arg = cliArgs[i];
399
- if (arg === "-Foreground" || arg === "--foreground") {
400
- foreground = true;
401
- } else if (arg === "-Movable" || arg === "--movable") {
402
- filteredArgs.push("-Movable");
403
- } else if (arg === "-Once" || arg === "--once") {
404
- once = true;
405
- filteredArgs.push("-Once");
406
- } else if (arg === "-Stop" || arg === "--stop" || arg === "stop") {
407
- stop = true;
408
- filteredArgs.push("-StopExisting");
409
- } else if (arg === "start") {
410
- // Launching is the default action.
411
- } else if (arg === "status") {
412
- subcommand = "status";
413
- } else if (arg === "autostart") {
414
- subcommand = "autostart";
415
- const next = cliArgs[i + 1];
416
- if (next === "on" || next === "off" || next === "status") {
417
- autostartAction = next;
404
+ function normalizeHudTextOption(value) {
405
+ const normalized = String(value || "").trim().toLowerCase();
406
+ if (["black", "dark", "ink"].includes(normalized)) return "dark";
407
+ if (["white", "light", "bright"].includes(normalized)) return "light";
408
+ throw new Error("--text must be one of: black or white");
409
+ }
410
+
411
+ function hudTextForTaskbar(value) {
412
+ const normalized = String(value || "").trim().toLowerCase();
413
+ if (["light", "white-taskbar", "light-taskbar", "lightbar"].includes(normalized)) return "dark";
414
+ if (["dark", "black-taskbar", "dark-taskbar", "darkbar"].includes(normalized)) return "light";
415
+ throw new Error("taskbar color must be one of: light or dark");
416
+ }
417
+
418
+ function normalizeHudBackdropOption(value) {
419
+ const normalized = String(value || "").trim().toLowerCase();
420
+ if (["1", "true", "yes", "on", "solid", "backdrop"].includes(normalized)) return "on";
421
+ if (["0", "false", "no", "off", "none", "transparent"].includes(normalized)) return "off";
422
+ throw new Error("--backdrop must be one of: on, off");
423
+ }
424
+
425
+ function optionValue(cliArgs, index, optionName) {
426
+ const next = cliArgs[index + 1];
427
+ if (!next || String(next).startsWith("-")) {
428
+ throw new Error(`${optionName} requires a value`);
429
+ }
430
+ return next;
431
+ }
432
+
433
+ function windowsHudUsage() {
434
+ return [
435
+ "Taskbar color:",
436
+ " ai-battery hud light light taskbar -> black text",
437
+ " ai-battery hud dark dark taskbar -> white text",
438
+ "",
439
+ "Text color:",
440
+ " ai-battery hud black black text",
441
+ " ai-battery hud white white text",
442
+ "",
443
+ "Other:",
444
+ " ai-battery hud stop",
445
+ " ai-battery hud status",
446
+ " ai-battery hud --backdrop",
447
+ " ai-battery hud autostart on light"
448
+ ].join("\n");
449
+ }
450
+
451
+ function describeWindowsHudOptions(filteredArgs) {
452
+ const descriptions = [];
453
+ for (let i = 0; i < filteredArgs.length; i += 1) {
454
+ const option = String(filteredArgs[i]).toLowerCase();
455
+ const value = filteredArgs[i + 1];
456
+ if (option === "-text") {
457
+ descriptions.push(value === "dark" ? "black text" : "white text");
458
+ i += 1;
459
+ } else if (option === "-backdrop") {
460
+ descriptions.push(value === "on" ? "backdrop on" : "backdrop off");
461
+ i += 1;
462
+ } else if (option === "-transparent") {
463
+ descriptions.push(value === "solid" ? "solid background" : "transparent background");
418
464
  i += 1;
419
465
  }
420
- } else {
421
- filteredArgs.push(arg);
422
466
  }
467
+
468
+ return [...new Set(descriptions)].join(", ");
469
+ }
470
+
471
+ const HUD_PASSTHROUGH_OPTIONS_WITH_VALUE = new Set([
472
+ "-batterycommand",
473
+ "-batterycommandbase64",
474
+ "-initialjsonbase64",
475
+ "-interval",
476
+ "-mode",
477
+ "-opacity",
478
+ "-position",
479
+ "-readypath",
480
+ "-width"
481
+ ]);
482
+
483
+ const HUD_PASSTHROUGH_SWITCHES = new Set([
484
+ "-clickthrough",
485
+ "-locked",
486
+ "-movable",
487
+ "-once",
488
+ "-stopexisting",
489
+ "-usewsl"
490
+ ]);
491
+
492
+ function parseWindowsHudArgs(cliArgs) {
493
+ const passthroughArgs = [];
494
+ let textMode = null;
495
+ let backdropMode = null;
496
+ let transparentMode = null;
497
+ let foreground = false;
498
+ let once = false;
499
+ let stop = false;
500
+ let subcommand = null;
501
+ let autostartAction = "status";
502
+
503
+ const setTextMode = (value) => {
504
+ textMode = normalizeHudTextOption(value);
505
+ };
506
+ const setBackdropMode = (value) => {
507
+ backdropMode = normalizeHudBackdropOption(value);
508
+ if (backdropMode === "on" && textMode === null) {
509
+ textMode = "light";
510
+ }
511
+ };
512
+ const optionalBackdropValue = (value) => {
513
+ try {
514
+ return normalizeHudBackdropOption(value);
515
+ } catch {
516
+ return null;
517
+ }
518
+ };
519
+
520
+ for (let i = 0; i < cliArgs.length; i += 1) {
521
+ const arg = cliArgs[i];
522
+ const lowerArg = String(arg).toLowerCase();
523
+ if (arg === "-Foreground" || arg === "--foreground") {
524
+ foreground = true;
525
+ } else if (arg === "-Movable" || arg === "--movable") {
526
+ passthroughArgs.push("-Movable");
527
+ } else if (arg === "-Once" || arg === "--once") {
528
+ once = true;
529
+ passthroughArgs.push("-Once");
530
+ } else if (arg === "-Stop" || arg === "--stop" || arg === "stop") {
531
+ stop = true;
532
+ passthroughArgs.push("-StopExisting");
533
+ } else if (arg === "start") {
534
+ // Launching is the default action.
535
+ } else if (arg === "status") {
536
+ subcommand = "status";
537
+ } else if (arg === "autostart") {
538
+ subcommand = "autostart";
539
+ const next = cliArgs[i + 1];
540
+ if (next === "on" || next === "off" || next === "status") {
541
+ autostartAction = next;
542
+ i += 1;
543
+ }
544
+ } else if (lowerArg === "--black" || lowerArg === "black") {
545
+ setTextMode("black");
546
+ } else if (lowerArg === "--white" || lowerArg === "white") {
547
+ setTextMode("white");
548
+ } else if (lowerArg === "--light" || lowerArg === "light") {
549
+ textMode = hudTextForTaskbar("light");
550
+ } else if (lowerArg === "--dark" || lowerArg === "dark") {
551
+ textMode = hudTextForTaskbar("dark");
552
+ } else if (lowerArg === "--text" || lowerArg === "--hud-text") {
553
+ setTextMode(optionValue(cliArgs, i, arg));
554
+ i += 1;
555
+ } else if (lowerArg.startsWith("--text=") || lowerArg.startsWith("--hud-text=")) {
556
+ setTextMode(arg.slice(arg.indexOf("=") + 1));
557
+ } else if (lowerArg === "--backdrop") {
558
+ const next = cliArgs[i + 1];
559
+ const backdropValue = next && !String(next).startsWith("-") ? optionalBackdropValue(next) : null;
560
+ if (backdropValue) {
561
+ setBackdropMode(backdropValue);
562
+ i += 1;
563
+ } else {
564
+ setBackdropMode("on");
565
+ }
566
+ } else if (lowerArg.startsWith("--backdrop=")) {
567
+ setBackdropMode(arg.slice(arg.indexOf("=") + 1));
568
+ } else if (lowerArg === "-backdrop") {
569
+ setBackdropMode(optionValue(cliArgs, i, arg));
570
+ i += 1;
571
+ } else if (lowerArg === "--no-backdrop") {
572
+ setBackdropMode("off");
573
+ } else if (lowerArg === "--solid") {
574
+ transparentMode = "solid";
575
+ } else if (lowerArg === "--transparent") {
576
+ transparentMode = "on";
577
+ } else if (lowerArg === "-transparent") {
578
+ transparentMode = optionValue(cliArgs, i, arg);
579
+ i += 1;
580
+ } else if (lowerArg === "-text") {
581
+ setTextMode(optionValue(cliArgs, i, arg));
582
+ i += 1;
583
+ } else if (arg.startsWith("-")) {
584
+ if (HUD_PASSTHROUGH_OPTIONS_WITH_VALUE.has(lowerArg)) {
585
+ passthroughArgs.push(arg, optionValue(cliArgs, i, arg));
586
+ i += 1;
587
+ } else if (HUD_PASSTHROUGH_SWITCHES.has(lowerArg)) {
588
+ passthroughArgs.push(arg);
589
+ } else {
590
+ throw new Error(`unknown HUD option: ${arg}`);
591
+ }
592
+ } else {
593
+ throw new Error(`unknown HUD option: ${arg}`);
594
+ }
595
+ }
596
+
597
+ const filteredArgs = [...passthroughArgs];
598
+ if (backdropMode !== null) filteredArgs.push("-Backdrop", backdropMode);
599
+ if (textMode !== null) filteredArgs.push("-Text", textMode);
600
+ if (transparentMode !== null) filteredArgs.push("-Transparent", transparentMode);
601
+
602
+ return {
603
+ filteredArgs,
604
+ foreground,
605
+ once,
606
+ stop,
607
+ subcommand,
608
+ autostartAction
609
+ };
610
+ }
611
+
612
+ function runDesktopHud(cliArgs) {
613
+ if (process.platform === "darwin") {
614
+ runMacHud(cliArgs);
615
+ return;
616
+ }
617
+
618
+ if (!useWsl && process.platform !== "win32") {
619
+ console.error("ai-battery-hud: desktop HUD needs Windows (native or WSL) or macOS.");
620
+ console.error("On Linux terminals use: ai-battery --watch");
621
+ process.exit(1);
622
+ }
623
+
624
+ if (!commandExists(powershell)) {
625
+ console.error("ai-battery-hud: powershell.exe is required for the Windows HUD.");
626
+ process.exit(1);
627
+ }
628
+
629
+ runWindowsHud(cliArgs);
423
630
  }
424
631
 
632
+ function runWindowsHud(cliArgs) {
633
+ const parsedArgs = (() => {
634
+ try {
635
+ return parseWindowsHudArgs(cliArgs);
636
+ } catch (error) {
637
+ console.error(`ai-battery-hud: ${error.message}`);
638
+ console.error(windowsHudUsage());
639
+ process.exit(1);
640
+ }
641
+ })();
642
+ const { filteredArgs, foreground, once, stop, subcommand, autostartAction } = parsedArgs;
643
+
425
644
  const hudScript = useWsl ? wslPath(ps1Path) : ps1Path;
426
645
  const nodePath = process.execPath;
427
646
  const batteryJs = path.join(scriptDir, "ai-battery.js");
@@ -468,6 +687,10 @@ function autostartEnable() {
468
687
  // launches the copy so sign-in start never depends on WSL being up. The HUD
469
688
  // must run as a separate PowerShell process whose command line contains
470
689
  // ai-battery-hud.ps1: stop/status and single-instance cleanup match it.
690
+ const autostartExtraArgs = filteredArgs
691
+ .filter((arg) => arg !== "-Once" && arg !== "-StopExisting")
692
+ .map(psSingleQuote)
693
+ .join(" ");
471
694
  const autostartScript = [
472
695
  "# Generated by: ai-battery hud autostart on",
473
696
  `$src = ${psSingleQuote(hudScript)}`,
@@ -475,7 +698,9 @@ function autostartEnable() {
475
698
  "try { Copy-Item $src $hud -Force -ErrorAction Stop } catch { }",
476
699
  `$battery = ${psSingleQuote(batteryCommand)}`,
477
700
  "$batteryB64 = [Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes($battery))",
478
- "$invoke = '& ' + \"'\" + ($hud -replace \"'\", \"''\") + \"'\" + ' -BatteryCommandBase64 ' + $batteryB64" + (useWsl ? " + ' -UseWsl'" : ""),
701
+ "$invoke = '& ' + \"'\" + ($hud -replace \"'\", \"''\") + \"'\" + ' -BatteryCommandBase64 ' + $batteryB64"
702
+ + (autostartExtraArgs ? ` + ${psSingleQuote(` ${autostartExtraArgs}`)}` : "")
703
+ + (useWsl ? " + ' -UseWsl'" : ""),
479
704
  "$argList = @('-NoProfile', '-ExecutionPolicy', 'Bypass', '-Command', ('\"' + ($invoke -replace '\"', '\\\"') + '\"')) -join ' '",
480
705
  "Start-Process -WindowStyle Hidden -FilePath 'powershell.exe' -ArgumentList $argList",
481
706
  ""
@@ -531,6 +756,9 @@ if (subcommand === "autostart") {
531
756
  process.exit(0);
532
757
  }
533
758
 
759
+ const wasRunning = (!foreground && !once && !stop)
760
+ ? hudProcessStatus().startsWith("running ")
761
+ : false;
534
762
  const initialJson = stop ? null : prefetchInitialJson(batteryCommand, useWsl);
535
763
  const readyPath = (!useWsl && process.platform === "win32" && !foreground && !once && !stop)
536
764
  ? path.join(os.tmpdir(), `ai-battery-hud-ready-${process.pid}-${Date.now()}.json`)
@@ -593,6 +821,24 @@ if (useWsl) {
593
821
  if (readyPath && !waitForFile(readyPath)) {
594
822
  console.log("AI Battery HUD start requested, but no visible window was confirmed. Run: ai-battery hud --foreground");
595
823
  } else {
596
- console.log("AI Battery HUD started. Drag it to place it; right-click and choose Exit to close.");
824
+ const detail = describeWindowsHudOptions(filteredArgs);
825
+ const action = wasRunning ? (detail ? "updated" : "restarted") : "started";
826
+ console.log(`AI Battery HUD ${action}${detail ? `: ${detail}` : ""}.`);
827
+ if (!wasRunning) {
828
+ console.log("Drag to move. Right-click to exit.");
829
+ }
597
830
  }
598
831
  if (readyPath) fs.rmSync(readyPath, { force: true });
832
+ }
833
+
834
+ if (isDirectRun()) {
835
+ runDesktopHud(process.argv.slice(2));
836
+ }
837
+
838
+ export {
839
+ macHudCommandMatches,
840
+ macHudPidsFromPsOutput,
841
+ describeWindowsHudOptions,
842
+ parseWindowsHudArgs,
843
+ windowsHudUsage
844
+ };