ai-battery 0.1.19 → 0.1.21

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.
@@ -6,7 +6,8 @@ import path from "node:path";
6
6
  export function createWindowsPathIntegration({
7
7
  pathDirPrecedesOriginal,
8
8
  samePath,
9
- uniquePaths
9
+ uniquePaths,
10
+ runPowerShell
10
11
  }) {
11
12
 
12
13
  function psQuote(value) {
@@ -14,6 +15,7 @@ function psQuote(value) {
14
15
  }
15
16
 
16
17
  function runWindowsPowerShell(script) {
18
+ if (runPowerShell) return runPowerShell(script);
17
19
  return spawnSync("powershell.exe", ["-NoProfile", "-ExecutionPolicy", "Bypass", "-Command", script], {
18
20
  encoding: "utf8",
19
21
  windowsHide: true,
@@ -23,7 +25,8 @@ function runWindowsPowerShell(script) {
23
25
 
24
26
  function windowsUserPathParts() {
25
27
  const result = runWindowsPowerShell("[Environment]::GetEnvironmentVariable('Path', 'User')");
26
- const text = result.status === 0 ? result.stdout : "";
28
+ if (result.status !== 0) throw new Error("Could not read Windows user PATH; leaving it unchanged");
29
+ const text = result.stdout;
27
30
  return String(text || "")
28
31
  .trim()
29
32
  .split(";")
@@ -48,32 +51,33 @@ function windowsUserPathWithShim(parts, shimDir) {
48
51
  !sameWindowsPath(entry, shimDir)
49
52
  && !staleWindowsAiBatteryTempPath(entry)
50
53
  ));
54
+ const next = [shimDir, ...filtered];
51
55
  return {
52
- parts: [shimDir, ...filtered],
53
- changed: filtered.length !== parts.length || !sameWindowsPath(parts[0] || "", shimDir)
56
+ parts: next,
57
+ changed: next.length !== parts.length || next.some((entry, index) => !sameWindowsPath(entry, parts[index] || ""))
54
58
  };
55
59
  }
56
60
 
57
61
  function ensureWindowsShimPath(shimDir, originalCommand) {
58
62
  const activeNow = pathDirPrecedesOriginal(shimDir, originalCommand);
59
- if (activeNow) {
63
+ if (process.env.AI_BATTERY_SKIP_WINDOWS_PATH_WRITE === "1") {
60
64
  return {
61
65
  changed: false,
62
66
  rcPath: null,
63
- note: `${shimDir} is already before the original codex on PATH. Plain "codex" can use AI Battery in new command lookups. Open a new cmd/PowerShell if this terminal cached the old command.`
67
+ note: `Skipped Windows user PATH update for ${shimDir}`
64
68
  };
65
69
  }
66
70
 
67
- if (process.env.AI_BATTERY_SKIP_WINDOWS_PATH_WRITE === "1") {
71
+ const parts = windowsUserPathParts();
72
+ const nextPath = windowsUserPathWithShim(parts, shimDir);
73
+ if (activeNow && !nextPath.changed) {
68
74
  return {
69
75
  changed: false,
70
76
  rcPath: null,
71
- note: `Skipped Windows user PATH update for ${shimDir}`
77
+ note: `${shimDir} is already configured in the Windows user PATH. Open a new cmd/PowerShell if this terminal cached the old command.`
72
78
  };
73
79
  }
74
80
 
75
- const parts = windowsUserPathParts();
76
- const nextPath = windowsUserPathWithShim(parts, shimDir);
77
81
  const next = nextPath.parts.join(";");
78
82
  const result = runWindowsPowerShell(`[Environment]::SetEnvironmentVariable('Path', ${psQuote(next)}, 'User')`);
79
83
  if (result.status !== 0) {
package/package.json CHANGED
@@ -1,75 +1,75 @@
1
- {
2
- "name": "ai-battery",
3
- "version": "0.1.19",
4
- "description": "Tiny terminal battery meter for local Codex and Claude Code usage.",
5
- "type": "module",
6
- "keywords": [
7
- "ai",
8
- "battery",
9
- "codex",
10
- "claude",
11
- "statusline",
12
- "tui",
13
- "usage"
14
- ],
15
- "bin": {
16
- "ai-battery": "bin/ai-battery.js",
17
- "ai-battery-hud": "bin/ai-battery-hud.js",
18
- "ai-battery-run": "bin/ai-battery-run",
19
- "ai-battery-run-win": "bin/ai-battery-run-win.js",
20
- "claudex-battery": "bin/ai-battery.js",
21
- "claudex-battery-hud": "bin/ai-battery-hud.js",
22
- "claudex-battery-run": "bin/ai-battery-run"
23
- },
24
- "files": [
25
- "bin/ai-battery.js",
26
- "bin/codex-wrapper.sh",
27
- "bin/codex-wrapper-win.cjs",
28
- "bin/ai-battery-run",
29
- "bin/ai-battery-run-win.js",
30
- "bin/terminal-compositor.js",
31
- "bin/ai-battery-hud",
32
- "bin/ai-battery-hud.js",
33
- "bin/ai-battery-macos-status.applescript",
34
- "bin/ai-battery-hud.ps1",
35
- "lib/**/*.js",
36
- "lib/**/*.ps1",
37
- "scripts/windows-rowpty-smoke.ps1",
38
- "scripts/windows-fullscreen-smoke.mjs",
39
- "scripts/windows-codex-fullscreen-check.mjs",
40
- "scripts/wsl-windows-rowpty-smoke.sh",
41
- "vendor/rowpty/RowPty.cs",
42
- "docs/*.svg",
43
- "docs/RELEASING.md",
44
- "README.md"
45
- ],
46
- "scripts": {
47
- "start": "node ./bin/ai-battery.js",
48
- "sync:rowpty": "node ./scripts/sync-rowpty.mjs",
49
- "smoke:win": "powershell -NoProfile -ExecutionPolicy Bypass -File ./scripts/windows-rowpty-smoke.ps1",
50
- "smoke:composite": "node ./scripts/windows-fullscreen-smoke.mjs",
51
- "smoke:fullscreen": "node ./scripts/windows-fullscreen-smoke.mjs --native",
52
- "smoke:codex-fullscreen-win": "node ./scripts/windows-codex-fullscreen-check.mjs",
53
- "smoke:wsl-win": "bash ./scripts/wsl-windows-rowpty-smoke.sh",
54
- "check": "node --check ./bin/ai-battery.js && node --check ./bin/ai-battery-hud.js && node --check ./bin/ai-battery-run-win.js && node --check ./lib/hud/launcher.js && node --check ./lib/platforms/windows/codex-runner.js && node --test",
55
- "test": "node --test"
56
- },
57
- "engines": {
58
- "node": ">=18"
59
- },
60
- "dependencies": {
61
- "@xterm/headless": "6.0.0"
62
- },
63
- "optionalDependencies": {
64
- "node-pty": "1.1.0"
65
- },
66
- "license": "MIT",
67
- "repository": {
68
- "type": "git",
69
- "url": "git+https://github.com/hojin-v/ai-battery.git"
70
- },
71
- "bugs": {
72
- "url": "https://github.com/hojin-v/ai-battery/issues"
73
- },
74
- "homepage": "https://github.com/hojin-v/ai-battery#readme"
75
- }
1
+ {
2
+ "name": "ai-battery",
3
+ "version": "0.1.21",
4
+ "description": "Tiny terminal battery meter for local Codex and Claude Code usage.",
5
+ "type": "module",
6
+ "keywords": [
7
+ "ai",
8
+ "battery",
9
+ "codex",
10
+ "claude",
11
+ "statusline",
12
+ "tui",
13
+ "usage"
14
+ ],
15
+ "bin": {
16
+ "ai-battery": "bin/ai-battery.js",
17
+ "ai-battery-hud": "bin/ai-battery-hud.js",
18
+ "ai-battery-run": "bin/ai-battery-run",
19
+ "ai-battery-run-win": "bin/ai-battery-run-win.js",
20
+ "claudex-battery": "bin/ai-battery.js",
21
+ "claudex-battery-hud": "bin/ai-battery-hud.js",
22
+ "claudex-battery-run": "bin/ai-battery-run"
23
+ },
24
+ "files": [
25
+ "bin/ai-battery.js",
26
+ "bin/codex-wrapper.sh",
27
+ "bin/codex-wrapper-win.cjs",
28
+ "bin/ai-battery-run",
29
+ "bin/ai-battery-run-win.js",
30
+ "bin/terminal-compositor.js",
31
+ "bin/ai-battery-hud",
32
+ "bin/ai-battery-hud.js",
33
+ "bin/ai-battery-macos-status.applescript",
34
+ "bin/ai-battery-hud.ps1",
35
+ "lib/**/*.js",
36
+ "lib/**/*.ps1",
37
+ "scripts/windows-rowpty-smoke.ps1",
38
+ "scripts/windows-fullscreen-smoke.mjs",
39
+ "scripts/windows-codex-fullscreen-check.mjs",
40
+ "scripts/wsl-windows-rowpty-smoke.sh",
41
+ "vendor/rowpty/RowPty.cs",
42
+ "docs/*.svg",
43
+ "docs/RELEASING.md",
44
+ "README.md"
45
+ ],
46
+ "scripts": {
47
+ "start": "node ./bin/ai-battery.js",
48
+ "sync:rowpty": "node ./scripts/sync-rowpty.mjs",
49
+ "smoke:win": "powershell -NoProfile -ExecutionPolicy Bypass -File ./scripts/windows-rowpty-smoke.ps1",
50
+ "smoke:composite": "node ./scripts/windows-fullscreen-smoke.mjs",
51
+ "smoke:fullscreen": "node ./scripts/windows-fullscreen-smoke.mjs --native",
52
+ "smoke:codex-fullscreen-win": "node ./scripts/windows-codex-fullscreen-check.mjs",
53
+ "smoke:wsl-win": "bash ./scripts/wsl-windows-rowpty-smoke.sh",
54
+ "check": "node --check ./bin/ai-battery.js && node --check ./bin/ai-battery-hud.js && node --check ./bin/ai-battery-run-win.js && node --check ./lib/hud/launcher.js && node --check ./lib/platforms/windows/codex-runner.js && node --test",
55
+ "test": "node --test"
56
+ },
57
+ "engines": {
58
+ "node": ">=18"
59
+ },
60
+ "dependencies": {
61
+ "@xterm/headless": "6.0.0"
62
+ },
63
+ "optionalDependencies": {
64
+ "node-pty": "1.1.0"
65
+ },
66
+ "license": "MIT",
67
+ "repository": {
68
+ "type": "git",
69
+ "url": "git+https://github.com/hojin-v/ai-battery.git"
70
+ },
71
+ "bugs": {
72
+ "url": "https://github.com/hojin-v/ai-battery/issues"
73
+ },
74
+ "homepage": "https://github.com/hojin-v/ai-battery#readme"
75
+ }