ai-battery 0.1.28 → 0.1.29

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
@@ -1,5 +1,7 @@
1
1
  # AI Battery
2
2
 
3
+ 0.1.29: GNOME 확장 UUID를 `ai-battery@hnode`로 변경했습니다. 기존 `ai-battery@hnode.dev` 설치는 HUD 시작 시 자동 이전하며 reset은 두 UUID의 관리 파일을 정리합니다.
4
+
3
5
  0.1.28: `setup`만으로 Codex TUI가 연결되던 0.1.24의 기본 동작을 복원했습니다. 신규 설치·업데이트·reset 후 setup을 동일하게 처리합니다. `doctor`는 표시 설정(Visibility), TUI 연동 상태, 현재 세션을 구분하고 누락된 연동·PATH·의존성에 맞는 조치를 안내합니다. [회귀 원인과 검증](docs/SETUP-REGRESSION.md).
4
6
 
5
7
  0.1.27: 한글 오류 메시지가 포함된 하단 사용량 줄이 갱신될 때 Codex 화면에 여러 줄로 누적되던 문제를 수정했습니다. 화면 칸 수를 기준으로 너비를 제한하고 불필요한 공백 채우기를 제거했습니다. 하단 바의 데이터 없음 표시는 `Claude --%`처럼 간결하게 표시합니다.
@@ -304,7 +306,7 @@ HUD는 백그라운드에서 실행되고 터미널을 바로 돌려줍니다. W
304
306
 
305
307
  Ubuntu GNOME에서는 상단 패널과 클릭 메뉴 모두 macOS와 같은 SVG를 사용합니다. 클릭하면 도구명, 그래픽 배터리 바, 퍼센트, 5h 리셋 시각과 7d 잔량을 같은 크기와 정렬로 표시하며, 아래에 새로고침·종료 메뉴가 있습니다. `ai-battery on/off` 설정도 반영합니다. 화면 잠금이나 패널 재시작 후에는 자동으로 다시 연결됩니다.
306
308
 
307
- GNOME 45–50에서는 처음 실행할 때 전용 표시 확장을 `~/.local/share/gnome-shell/extensions/ai-battery@hnode.dev`에 설치하고 활성화합니다. `XDG_DATA_HOME`을 지정한 경우 해당 경로를 사용합니다. 새 확장을 읽으려면 최초 한 번 로그아웃·로그인이 필요합니다. 그 전이나 다른 데스크톱에서는 기본 StatusNotifier 메뉴를 사용합니다. 확장만 비활성화해도 기본 패널 아이콘으로 복귀합니다.
309
+ GNOME 45–50에서는 처음 실행할 때 전용 표시 확장을 `~/.local/share/gnome-shell/extensions/ai-battery@hnode`에 설치하고 활성화합니다. `XDG_DATA_HOME`을 지정한 경우 해당 경로를 사용합니다. 새 확장을 읽으려면 최초 한 번 로그아웃·로그인이 필요합니다. 그 전이나 다른 데스크톱에서는 기본 StatusNotifier 메뉴를 사용합니다. 확장만 비활성화해도 기본 패널 아이콘으로 복귀합니다.
308
310
 
309
311
  GJS, libdbusmenu와 StatusNotifier 호스트가 필요합니다. 현재 Ubuntu 환경에서는 추가 설치 없이 실행됩니다. 구성 요소가 없다면 다음 명령으로 설치하고 Ubuntu AppIndicators 확장을 활성화하세요.
310
312
 
package/docs/RELEASING.md CHANGED
@@ -1,6 +1,10 @@
1
1
  # npm release
2
2
 
3
- The prepared version is **0.1.28**, following the published 0.1.27. Preparing or pushing this release does not publish it to npm.
3
+ The prepared version is **0.1.29**, following the published 0.1.28. Preparing or pushing this release does not publish it to npm.
4
+
5
+ ## Fixes in 0.1.29
6
+
7
+ - Change the GNOME extension UUID to `ai-battery@hnode`. Migrate the owned legacy `ai-battery@hnode.dev` directory and activation settings during HUD startup. Reset handles both identities and preserves unrelated files. GNOME may require a new login to discover the new UUID.
4
8
 
5
9
  ## Fixes in 0.1.28
6
10
 
@@ -28,16 +32,16 @@ The active runner keeps its Python code until the next launch. Updating the CLI
28
32
  ```text
29
33
  npm run check
30
34
  npm run smoke:linux
31
- mkdir -p .cache/releases/0.1.28
35
+ mkdir -p .cache/releases/0.1.29
32
36
  npm pack --dry-run --json
33
- npm pack --pack-destination .cache/releases/0.1.28 --json
37
+ npm pack --pack-destination .cache/releases/0.1.29 --json
34
38
  ```
35
39
 
36
40
  The regression suite includes real PTYs: an already-running wrapped Codex remains interactive during setup, the same Bash command cache launches it again, a fresh shell displays the usage row, and an attached tmux client displays the bar after live setup. An open wrapper reader retains its old bytes, compatibility command paths and recovery backups survive, and user Codex/shell/tmux settings are compared exactly.
37
41
 
38
42
  POSIX screen regressions replay actual output into a terminal emulator and inspect the rendered rows, cursor and scrollback. They cover repeated Korean error rows, narrow widths, wide/combining characters, control sequences, shorter replacement text, resize and keyboard input through a live PTY.
39
43
 
40
- Also install each of 0.1.24 and 0.1.27 into an isolated npm prefix, open the PTY fixture, upgrade that prefix to the exact 0.1.28 tarball, and run default setup while the original terminal remains open. Save the lifecycle report, package manifest, SHA256 checksum, installed-package smoke report and publish dry-run under `.cache/releases/0.1.28/`.
44
+ Also install each of 0.1.24 and 0.1.27 into an isolated npm prefix, open the PTY fixture, upgrade that prefix to the exact 0.1.29 tarball, and run default setup while the original terminal remains open. Save the lifecycle report, package manifest, SHA256 checksum, installed-package smoke report and publish dry-run under `.cache/releases/0.1.29/`.
41
45
 
42
46
  The Linux GUI smoke test opens the actual popup in an isolated GNOME 50.1 Wayland session, verifies zero border width for the content and box pointer, and saves a screenshot. It also checks shared macOS SVG size, provider visibility, extension fallback/reconnect and shutdown. Native Windows/macOS runtime tests require their respective environments; platform-neutral regressions still run here.
43
47
 
@@ -47,16 +51,16 @@ Inspect the tarball for runtime modules, stable bin entrypoints and required pla
47
51
 
48
52
  ```text
49
53
  npm whoami
50
- npm publish .cache/releases/0.1.28/ai-battery-0.1.28.tgz --access public --tag latest
54
+ npm publish .cache/releases/0.1.29/ai-battery-0.1.29.tgz --access public --tag latest
51
55
  npm view ai-battery version dist-tags --json
52
56
  ```
53
57
 
54
- Authenticate with `npm login` if required, and complete npm 2FA when requested. If 0.1.28 is already published, increment the version and repeat verification. Tag the tested commit `v0.1.28` after publication.
58
+ Authenticate with `npm login` if required, and complete npm 2FA when requested. If 0.1.29 is already published, increment the version and repeat verification. Tag the tested commit `v0.1.29` after publication.
55
59
 
56
60
  ## Update and enable terminal display
57
61
 
58
62
  ```text
59
- npm install -g ai-battery@0.1.28
63
+ npm install -g ai-battery@0.1.29
60
64
  ai-battery setup
61
65
  ai-battery setup tmux
62
66
  tmux
@@ -1,7 +1,9 @@
1
1
  import Gio from "gi://Gio";
2
2
  import GLib from "gi://GLib";
3
+ import { gnomeHudUuid, legacyGnomeHudUuids } from "./gnome-uuid.js";
3
4
 
4
- const uuid = "ai-battery@hnode.dev";
5
+ const uuid = ARGV[1] || gnomeHudUuid;
6
+ if (![gnomeHudUuid, ...legacyGnomeHudUuids].includes(uuid)) throw new Error("Unsupported AI Battery extension UUID");
5
7
  const service = "org.gnome.Shell.Extensions";
6
8
  const object = "/org/gnome/Shell";
7
9
  function call(method, args = null, iface = service) {
@@ -22,9 +24,12 @@ if (info.available && ["enable", "disable"].includes(ARGV[0])) {
22
24
  const enable = ARGV[0] === "enable";
23
25
  if (!enable) info.accepted = call("DisableExtension", new GLib.Variant("(s)", [uuid]))[0];
24
26
  const settings = new Gio.Settings({ schema_id: "org.gnome.shell" });
27
+ // DisableExtension can leave the old UUID in disabled-extensions. Clean
28
+ // both identities when applying the new one, including after a partial move.
29
+ const identities = uuid === gnomeHudUuid ? [uuid, ...legacyGnomeHudUuids] : [uuid];
25
30
  for (const key of ["enabled-extensions", "disabled-extensions"]) {
26
31
  const previous = settings.get_strv(key);
27
- let next = previous.filter(value => value !== uuid);
32
+ let next = previous.filter(value => !identities.includes(value));
28
33
  if (enable && key === "enabled-extensions") next.push(uuid);
29
34
  if (next.join("\0") !== previous.join("\0") && !settings.set_strv(key, next)) throw new Error(`Could not update ${key}`);
30
35
  }
@@ -0,0 +1,3 @@
1
+ // Shared by Node and GJS; keep extension identity independent of either runtime.
2
+ export const gnomeHudUuid = "ai-battery@hnode";
3
+ export const legacyGnomeHudUuids = ["ai-battery@hnode.dev"];
@@ -3,9 +3,11 @@ import os from "node:os";
3
3
  import path from "node:path";
4
4
  import { spawnSync } from "node:child_process";
5
5
  import { fileURLToPath } from "node:url";
6
+ import { gnomeHudUuid, legacyGnomeHudUuids } from "./gnome-uuid.js";
7
+
8
+ export { gnomeHudUuid } from "./gnome-uuid.js";
6
9
 
7
10
  const directory = path.dirname(fileURLToPath(import.meta.url));
8
- export const gnomeHudUuid = "ai-battery@hnode.dev";
9
11
  export const gnomeHudMetadata = {
10
12
  uuid: gnomeHudUuid, name: "AI Battery", description: "Codex and Claude usage with the macOS detail menu",
11
13
  "shell-version": ["45", "46", "47", "48", "49", "50"], version: 1,
@@ -13,52 +15,73 @@ export const gnomeHudMetadata = {
13
15
  };
14
16
 
15
17
  export function createGnomeHudIntegration({ home = os.homedir(), env = process.env, run = spawnSync } = {}) {
16
- const target = path.join(env.XDG_DATA_HOME || path.join(home, ".local/share"), "gnome-shell/extensions", gnomeHudUuid);
18
+ const extensions = path.join(env.XDG_DATA_HOME || path.join(home, ".local/share"), "gnome-shell/extensions");
19
+ const target = path.join(extensions, gnomeHudUuid);
17
20
  const source = path.join(directory, "gnome-extension/extension.js");
18
21
  const gjs = env.AI_BATTERY_GJS || (fs.existsSync("/usr/bin/gjs") ? "/usr/bin/gjs" : "gjs");
19
- function control(action) {
20
- const result = run(gjs, ["-m", path.join(directory, "gnome-control.js"), action], { env, encoding: "utf8", timeout: 8000 });
22
+ function control(action, uuid = gnomeHudUuid) {
23
+ const result = run(gjs, ["-m", path.join(directory, "gnome-control.js"), action, uuid], { env, encoding: "utf8", timeout: 8000 });
21
24
  if (result.status !== 0 || result.error) throw new Error(result.error?.message || result.stderr?.trim() || "GNOME HUD integration failed");
22
25
  return JSON.parse(result.stdout);
23
26
  }
24
- function owned() {
25
- const stat = fs.lstatSync(target, { throwIfNoEntry: false });
27
+ function owned(directory = target, uuid = gnomeHudUuid) {
28
+ const stat = fs.lstatSync(directory, { throwIfNoEntry: false });
26
29
  if (!stat) return false;
30
+ // Removal may leave unrelated notes in the directory. Their presence is
31
+ // not an installed extension and must not block a later prepare/reset.
32
+ if (stat.isDirectory() && !stat.isSymbolicLink()
33
+ && !fs.lstatSync(path.join(directory, "metadata.json"), { throwIfNoEntry: false })
34
+ && !fs.lstatSync(path.join(directory, "extension.js"), { throwIfNoEntry: false })) return false;
27
35
  let metadata;
28
36
  try {
29
- const file = path.join(target, "metadata.json");
37
+ const file = path.join(directory, "metadata.json");
30
38
  const metaStat = fs.lstatSync(file);
31
- const codeStat = fs.lstatSync(path.join(target, "extension.js"));
39
+ const codeStat = fs.lstatSync(path.join(directory, "extension.js"));
32
40
  if (!stat.isDirectory() || stat.isSymbolicLink() || !metaStat.isFile() || metaStat.isSymbolicLink()
33
41
  || !codeStat.isFile() || codeStat.isSymbolicLink()) throw new Error("Unowned extension");
34
42
  metadata = JSON.parse(fs.readFileSync(file, "utf8"));
35
43
  } catch { /* Report one ownership error without modifying the directory. */ }
36
- if (metadata?.uuid !== gnomeHudUuid || metadata["ai-battery-managed"] !== true) {
37
- throw new Error(`GNOME HUD extension ownership could not be verified; left untouched: ${target}`);
44
+ if (metadata?.uuid !== uuid || metadata["ai-battery-managed"] !== true) {
45
+ throw new Error(`GNOME HUD extension ownership could not be verified; left untouched: ${directory}`);
38
46
  }
39
47
  return true;
40
48
  }
49
+ function legacyInstallations() {
50
+ return legacyGnomeHudUuids.map(uuid => ({ uuid, directory: path.join(extensions, uuid) }))
51
+ .filter(item => owned(item.directory, item.uuid));
52
+ }
53
+ function removeOwned(directory, uuid) {
54
+ control("disable", uuid);
55
+ for (const name of ["extension.js", "metadata.json"]) fs.unlinkSync(path.join(directory, name));
56
+ if (!fs.readdirSync(directory).length) fs.rmdirSync(directory);
57
+ }
41
58
  function prepare() {
42
59
  const info = control("info");
43
60
  if (!info.available || !gnomeHudMetadata["shell-version"].includes(String(info.version).split(".")[0])) return { supported: false };
44
61
  const exists = owned();
62
+ // Validate both identities before modifying files or desktop settings.
63
+ const legacy = legacyInstallations();
45
64
  const code = fs.readFileSync(source, "utf8");
46
- const changed = !exists || fs.readFileSync(path.join(target, "extension.js"), "utf8") !== code;
65
+ const metadata = `${JSON.stringify(gnomeHudMetadata, null, 2)}\n`;
66
+ const changed = !exists || fs.readFileSync(path.join(target, "extension.js"), "utf8") !== code
67
+ || fs.readFileSync(path.join(target, "metadata.json"), "utf8") !== metadata;
47
68
  if (changed) {
48
69
  fs.mkdirSync(target, { recursive: true, mode: 0o700 });
49
70
  fs.writeFileSync(path.join(target, "extension.js"), code, { mode: 0o600 });
50
- fs.writeFileSync(path.join(target, "metadata.json"), `${JSON.stringify(gnomeHudMetadata, null, 2)}\n`, { mode: 0o600 });
71
+ fs.writeFileSync(path.join(target, "metadata.json"), metadata, { mode: 0o600 });
51
72
  }
73
+ for (const item of legacy) removeOwned(item.directory, item.uuid);
52
74
  const enabled = control("enable");
53
- return { supported: true, pending: !enabled.accepted || changed, blocked: !info.allowed, path: target };
75
+ return { supported: true, pending: !enabled.accepted || changed, blocked: !info.allowed, path: target,
76
+ migrated: legacy.map(item => item.uuid) };
54
77
  }
55
78
  function remove() {
56
- if (!owned()) return { changed: false };
57
- // Validate all managed files before touching desktop settings or removing a file.
58
- control("disable");
59
- for (const name of ["extension.js", "metadata.json"]) fs.unlinkSync(path.join(target, name));
60
- if (!fs.readdirSync(target).length) fs.rmdirSync(target);
61
- return { changed: true, path: target };
79
+ const exists = owned();
80
+ const legacy = legacyInstallations();
81
+ if (!exists && !legacy.length) return { changed: false };
82
+ if (exists) removeOwned(target, gnomeHudUuid);
83
+ for (const item of legacy) removeOwned(item.directory, item.uuid);
84
+ return { changed: true, path: exists ? target : legacy[0].directory };
62
85
  }
63
86
  return { prepare, remove, target };
64
87
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ai-battery",
3
- "version": "0.1.28",
3
+ "version": "0.1.29",
4
4
  "description": "Tiny terminal battery meter for local Codex and Claude Code usage.",
5
5
  "type": "module",
6
6
  "keywords": [
@@ -29,6 +29,7 @@ const env = { ...process.env, HOME: home, CODEX_HOME: codex, LANGUAGE: "ko", GIO
29
29
  AI_BATTERY_STATE_DIR: path.join(root, "state"), AI_BATTERY_DATA_DIR: path.join(root, "data"),
30
30
  AI_BATTERY_SHARED_USAGE_STATE_DIR: path.join(root, "shared"), AI_BATTERY_NO_UPDATE_CHECK: "1",
31
31
  AI_BATTERY_MENU_ROOT: root, AI_BATTERY_MENU_SOURCE: runtime, AI_BATTERY_MENU_NODE: process.execPath,
32
+ AI_BATTERY_MENU_UUID: gnomeHudMetadata.uuid,
32
33
  AI_BATTERY_MENU_BUS: linuxHudBusName(path.join(root, "state")) };
33
34
  for (const key of ["DISPLAY", "WAYLAND_DISPLAY", "GNOME_KEYRING_CONTROL", "GNOME_SETUP_DISPLAY", "SESSION_MANAGER", "DBUS_STARTER_ADDRESS", "DBUS_STARTER_BUS_TYPE"]) delete env[key];
34
35
  const on = spawnSync(process.execPath, [path.join(runtime, "bin/ai-battery.js"), "on", "all"], { env, encoding: "utf8" });
@@ -32,7 +32,7 @@ export async function run() {
32
32
  const source = GLib.getenv("AI_BATTERY_MENU_SOURCE");
33
33
  const node = GLib.getenv("AI_BATTERY_MENU_NODE");
34
34
  const name = GLib.getenv("AI_BATTERY_MENU_BUS");
35
- const uuid = "ai-battery@hnode.dev";
35
+ const uuid = GLib.getenv("AI_BATTERY_MENU_UUID");
36
36
  Main.overview.hide();
37
37
  const backend = Gio.Subprocess.new(["gjs", "-m", `${source}/lib/platforms/linux/panel.js`, "--bus-name", name,
38
38
  "--node", node, "--snapshot", `${source}/lib/platforms/linux/panel-snapshot.js`, "--state-dir", `${root}/state`, "--provider", "all"],
@@ -42,6 +42,15 @@ export async function run() {
42
42
  extension = Main.extensionManager.lookup(uuid)?.stateObj;
43
43
  return extension?._panels?.size === 1;
44
44
  });
45
+ // GNOME can retain the disabled old UUID after its directory was migrated.
46
+ // Exercise the real controller against Shell and dconf, not a command stub.
47
+ const settings = new Gio.Settings({ schema_id: "org.gnome.shell" });
48
+ const disabled = settings.get_strv("disabled-extensions").filter(value => value !== "ai-battery@hnode.dev");
49
+ settings.set_strv("disabled-extensions", [...disabled, "ai-battery@hnode.dev"]);
50
+ Gio.Settings.sync();
51
+ await command(["gjs", "-m", `${source}/lib/platforms/linux/gnome-control.js`, "enable", uuid]);
52
+ await until(() => !settings.get_strv("disabled-extensions").includes("ai-battery@hnode.dev"));
53
+ expect(settings.get_strv("disabled-extensions").join("\0") === disabled.join("\0"), "Migration must preserve unrelated disabled extensions");
45
54
  let panel = extension._panels.get(name);
46
55
  await until(() => panel.data.presentation === "gnome");
47
56
  expect(panel.detail.width === 392, "Detail artwork must retain the macOS width");
@@ -90,7 +99,7 @@ export async function run() {
90
99
  await call(name, "Quit");
91
100
  await until(() => extension._panels.size === 0);
92
101
  const result = { result: "passed", checks: ["Shared macOS detail SVG at full size", "Open GNOME menu renders artwork",
93
- "Korean menu actions", "Provider visibility and image resizing", "Standard tray fallback on disable", "Enable/reconnect and service shutdown"],
102
+ "Korean menu actions", "Provider visibility and image resizing", "Legacy UUID settings cleanup", "Standard tray fallback on disable", "Enable/reconnect and service shutdown"],
94
103
  screenshot: `${root}/detail-menu.png`, fullScreenshot: `${root}/menu.png`, detailImage: detailPath };
95
104
  GLib.file_set_contents(`${root}/result.json`, new TextEncoder().encode(JSON.stringify(result, null, 2)));
96
105
  print(JSON.stringify(result));