ai-battery 0.1.17 → 0.1.19

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.19: Codex wrapper는 현재 PATH를 따릅니다. nvm 등의 전환 후 새 Codex를 고정된 이전 경로 대신 실행합니다. Windows·WSL 사용량 공유 수정도 포함하므로 양쪽 설치를 업데이트하세요. Windows Terminal padding 변경은 로컬 표시 조정이며, 패키지는 사용자 터미널 설정을 자동 변경하지 않습니다.
4
+
3
5
  [한국어](README.md) · [English](docs/i18n/en/) · [日本語](docs/i18n/ja/) · [中文](docs/i18n/zh/) · [Español](docs/i18n/es/)
4
6
 
5
7
  Codex and Claude Usage Battery Meter
@@ -40,7 +42,7 @@ Codex 86% │ 5h 18:09 │ 7d 82% ┃ Claude 4% │ 5h 18:10 │ 7d 71%
40
42
  | 공통 사용량 표시 | Codex와 Claude Code 사용량을 같은 형식으로 표시합니다. |
41
43
  | 리셋 시각 표시 | `5h`, `7d` 창 라벨과 값을 표시합니다. |
42
44
  | 색상 기준 | 40% 초과 초록, 21-40% 주황, 20% 이하 빨강으로 배터리만 강조합니다. |
43
- | Codex terminal row | Windows에서는 Codex를 직접 실행한 채 외부 docked 행을 붙이고, WSL/Linux/macOS에서는 PTY wrapper로 별도 사용량 행을 고정합니다. |
45
+ | Codex terminal row | Windows에서는 가상 터미널 화면과 배터리 행을 합성하고, WSL/Linux/macOS에서는 PTY wrapper로 별도 사용량 행을 고정합니다. |
44
46
  | Claude statusLine | Claude Code 내장 statusLine hook과 실제 429 hit 로그로 Claude rate limit 상태를 읽습니다. |
45
47
  | HUD / menu bar | Windows native에서는 terminal-docked/floating HUD, WSL에서는 floating HUD, macOS에서는 menu bar status item을 제공합니다. |
46
48
  | npm 실행 | `npm install -g` 또는 `npx`로 실행할 수 있습니다. |
@@ -52,7 +54,7 @@ Codex 86% │ 5h 18:09 │ 7d 82% ┃ Claude 4% │ 5h 18:10 │ 7d 71%
52
54
  | `ai-battery` | 지원 | 지원 | 지원 | 지원 | Node.js 18 이상이 필요합니다. |
53
55
  | `ai-battery --watch` | 지원 | 지원 | 지원 | 지원 | 터미널 안에서 주기적으로 갱신합니다. |
54
56
  | Claude statusLine | 지원 | 지원 | 지원 | 지원 | Claude Code `statusLine`에 `node <script>` 명령을 저장합니다. |
55
- | Codex fullscreen | 지원 | 지원 | 지원 | 지원 | Windows 기본값은 Codex가 native alternate screen 전체를 직접 소유하고 AI Battery는 docked HUD에 표시됩니다. WSL/Linux/macOS는 POSIX PTY와 `python3`를 사용합니다. |
57
+ | Codex fullscreen | 지원 | 지원 | 지원 | 지원 | Windows 기본값은 Fullscreen PTY 화면과 터미널 배터리 행을 합성합니다. WSL/Linux/macOS는 POSIX PTY와 `python3`를 사용합니다. |
56
58
  | `ai-battery setup codex` | 지원 | 지원 | 지원 | 지원 | Codex `[tui].status_line`을 맞추고, Windows는 `codex.cmd` wrapper, WSL/Linux/macOS는 POSIX shell wrapper를 설치합니다. |
57
59
  | `ai-battery hud` | 지원 | 지원 | 미지원 | 지원 | Windows/WSL은 PowerShell/WinForms HUD, macOS는 menu bar status item입니다. |
58
60
 
@@ -173,13 +175,13 @@ ai-battery setup codex
173
175
 
174
176
  Codex setup은 `~/.codex/config.toml`의 `[tui]`에 `model-with-reasoning`, `current-dir`, `git-branch` status line을 설정합니다. 기존 값이 있으면 uninstall 복구용으로 백업합니다. Codex wrapper는 기존 `codex` 명령을 직접 덮어쓰지 않습니다. `~/.local/bin`이 이미 PATH에서 원본 `codex`보다 앞에 있고 `~/.local/bin/codex`가 비어 있거나 AI Battery 관리 파일이면 그 위치에 wrapper를 둬서 바로 잡히게 합니다. 그렇지 않으면 `~/.local/share/ai-battery/bin/codex`에 관리형 wrapper를 만들고, 필요한 경우 셸 설정에 이 디렉터리를 PATH 앞쪽으로 추가합니다. `~/.local/bin/codex` 같은 공용 위치에 이미 다른 파일이 있으면 덮어쓰지 않습니다. 새 터미널부터 `codex`가 자동으로 AI Battery 하단 행과 함께 실행됩니다. 같은 터미널에서 이미 `codex`를 실행한 적이 있으면 셸 캐시 때문에 `hash -r`이 한 번 필요할 수 있고, PATH 추가가 필요한 경우에는 `setup` 출력에 표시되는 `source ...` 명령을 실행하세요.
175
177
 
176
- Windows native `cmd`/PowerShell에서는 `codex.cmd` wrapper가 기본 `fullscreen` runner를 실행합니다. 이 경로에는 중간 ConPTY나 headless terminal이 없습니다. Codex가 실제 콘솔에 직접 연결되어 native alternate screen, 스크롤, 입력과 `[tui].status_line`을 그대로 소유합니다. AI Battery는 터미널 바로 아래에 Codex와 Claude 사용량을 Linux/macOS와 같은 텍스트 TUI 상태행으로 표시합니다. 최대화, 전체화면, Windows 스냅이 터미널 높이를 다시 채우면 상태행 공간을 자동으로 재확보합니다. dock 중에는 터미널 하단 코너를 직각으로 바꾸고 상태행을 경계에 겹쳐 붙인 뒤 상태행의 하단 코너만 둥글게 처리하므로 하나의 창처럼 이어집니다. 이 docked TUI와 작업표시줄 HUD는 별도 프로세스와 singleton을 사용하므로 동시에 실행할 수 있습니다. `AI_BATTERY_WIN_LAYOUT=fullscreen`이 명시 이름이고 `auto`는 같은 경로의 호환 alias입니다.
178
+ Windows native `cmd`/PowerShell에서는 `codex.cmd` wrapper가 현재 PATH에서 원본 Codex를 매번 찾고, 기본 `composite` runner로 실행합니다. Codex Fullscreen 화면은 `node-pty`의 bundled ConPTY와 `@xterm/headless` 안에서 해석한 뒤, 터미널 최하단의 AI Battery 1행과 합성합니다. Codex의 기본 상태·단축키 행은 본문 스크롤 이동에서 제외하며, 바뀐 화면만 다시 그립니다. 시스템 Node와 Codex 설치는 변경하지 않습니다.
177
179
 
178
180
  Windows dock 위치는 `AI_BATTERY_WIN_DOCK_POSITION`으로 선택합니다. 기본값 `bottom`은 터미널 하단에 결합하고, `tabs`는 같은 compact 사용량 행을 상단 탭 바 오른쪽에 고정합니다. PowerShell에서는 `$env:AI_BATTERY_WIN_DOCK_POSITION="tabs"`, cmd에서는 `set AI_BATTERY_WIN_DOCK_POSITION=tabs`를 설정한 뒤 `codex`를 실행합니다. launcher를 직접 확인하려면 `ai-battery hud --dock-console --dock-position tabs`를 사용합니다.
179
181
 
180
- `composite`는 `@xterm/headless`로 화면을 재해석하는 실험 모드입니다. `tui`, `reserve`, `overlay`, `inline`도 이전 구현을 확인하기 위한 호환 모드이며, `tui`에서만 로컬 빌드된 `rowpty.exe`와 bundled ConPTY를 사용합니다. 기본 docked HUD에는 rowpty가 필요하지 않으므로 일반 `setup`에서는 컴파일하지 않습니다. 레거시 경로가 필요하면 `AI_BATTERY_WIN_LAYOUT=tui` 또는 `AI_BATTERY_INSTALL_ROWPTY=1`을 설정한 뒤 `ai-battery setup codex`를 다시 실행하세요. `plain`은 HUD 없이 Codex를 직접 실행합니다. Windows의 Claude statusLine은 Claude Code 내부 header만 표시하고, 첫 statusLine payload에서 같은 terminal-docked 사용량 HUD를 연결합니다.
182
+ Windows의 현재 Node가 VT raw 입력을 지원하지 않으면 사용자 데이터 디렉터리의 전용 Node 24.21.0을 사용합니다. 첫 실행에서 공식 Node 배포본을 내려받아 SHA256 검증 후 `node.exe`만 설치하며, PATH는 변경하지 않습니다. 런타임 준비나 PTY 의존성 로드가 실패하면 기존 native HUD로 전환합니다. `AI_BATTERY_RUNTIME_DOWNLOAD=0`은 자동 다운로드를 끕니다. `AI_BATTERY_WIN_LAYOUT=fullscreen` 또는 `hud`는 HUD 방식, `plain`은 추가 표시 없는 직접 실행, `tui`, `reserve`, `overlay`, `inline`은 이전 구현을 확인하기 위한 명시적 모드입니다. `auto`는 기본 `composite`를 선택합니다.
181
183
 
182
- Native fullscreen의 자동 smoke는 `npm run smoke:fullscreen`, 실험 compositor smoke는 `npm run smoke:composite`로 실행합니다. 두 테스트 모두 `cmd`와 PowerShell 자식을 각각 검증합니다.
184
+ 기본 compositor 검사는 `npm run smoke:composite`, 실제 Codex Fullscreen 검사는 `npm run smoke:codex-fullscreen-win`, native HUD 경로 검사는 `npm run smoke:fullscreen`으로 실행합니다.
183
185
 
184
186
  Windows rowpty 문제를 재현할 때는 말로 설명하지 말고 smoke report를 남기는 쪽이 가장 빠릅니다. WSL에서는 `npm run smoke:wsl-win`을 실행하면 새 Windows PowerShell 콘솔을 열어 실제 Windows 콘솔 핸들에서 테스트하고, `rowpty-smoke-report.json`을 repo 루트에 저장합니다. Windows native 터미널에서는 `npm run smoke:win`을 바로 실행하면 됩니다. smoke test는 `cmd.exe` child와 `powershell.exe` child를 모두 rowpty 안에서 실행합니다. report에는 rowpty 사용 여부, overlay/node-pty fallback 여부, 키 입력 없이 delayed output이 화면 버퍼에 나타났는지, status row가 보였는지, `CSI 3J` 이후 scrollback sentinel이 남았는지가 case별로 기록됩니다.
185
187
 
@@ -342,7 +344,7 @@ Codex는 최근 세션 로그에서 `rate_limits` 이벤트를 찾습니다. Cla
342
344
 
343
345
  ## Source Environment
344
346
 
345
- 기본 CLI는 Node.js 18 이상이 있으면 Windows native, WSL, Linux, macOS에서 실행됩니다. Windows native의 기본 Codex 경로는 중간 PTY 없이 Codex를 직접 실행하고 PowerShell/WinForms docked HUD를 붙입니다. `rowpty.exe`와 same-console overlay는 명시적으로 선택한 레거시 `tui`/`reserve`/`overlay` 모드에서만 사용합니다. WSL/Linux/macOS의 `ai-battery-run`은 Python 3와 POSIX PTY를 사용하고, macOS HUD는 내장 `osascript`와 AppleScriptObjC를 사용합니다.
347
+ 기본 CLI는 Node.js 18 이상에서 실행됩니다. Windows 기본 compositor는 VT raw 입력을 지원하는 전용 런타임을 필요할 때 준비합니다. WSL/Linux/macOS는 Python 3와 POSIX PTY를 사용합니다. 전용 런타임이나 의존성을 준비할 수 없으면 native HUD로 전환합니다.
346
348
 
347
349
  Codex 데이터는 Codex가 실제로 사용하는 `CODEX_HOME`(기본값 `~/.codex`)의 `sessions`를 읽습니다. AI Battery는 `HOME`, `USERPROFILE`, `CODEX_HOME`을 설정하거나 변경하지 않습니다. `CODEX_HOME`을 바꾸면 Codex 자체의 `/resume` 저장소도 바뀌므로 Windows와 WSL의 경로를 합치는 용도로 사용하지 마세요. 쉼표로 여러 경로를 지정하는 방식도 지원하지 않습니다.
348
350
 
@@ -32,7 +32,9 @@ def battery_command_base():
32
32
  # Running the .js file directly depends on its exec bit and shebang;
33
33
  # prefer an explicit node invocation when node is available.
34
34
  if BATTERY_BIN.endswith(".js"):
35
- node = shutil.which("node")
35
+ node = os.environ.get("AI_BATTERY_NODE")
36
+ if not node or not os.path.isfile(node) or not os.access(node, os.X_OK):
37
+ node = shutil.which("node")
36
38
  if node:
37
39
  return [node, BATTERY_BIN]
38
40
  return [BATTERY_BIN]
@@ -0,0 +1,167 @@
1
+ // Shared PATH lookup and command launch for Windows. Generated bridges embed
2
+ // this file so a removed AI Battery package cannot pin Codex to an old install.
3
+ const fs = require("node:fs");
4
+ const path = require("node:path");
5
+ const { spawn } = require("node:child_process");
6
+ const UNSAFE_CMD_ARGUMENT_RE = /[\r\n&|<>^%!()]/;
7
+ const UNSAFE_CMD_PATH_RE = /[\r\n&|<>^%!]/;
8
+
9
+ function windowsCommandNames(command, env = process.env) {
10
+ const extensions = (env.PATHEXT || ".COM;.EXE;.BAT;.CMD").split(";").filter(Boolean);
11
+ return [...extensions.map((ext) => command + ext.toLowerCase()), command];
12
+ }
13
+
14
+ function isManagedWrapper(file) {
15
+ let fd;
16
+ try {
17
+ fd = fs.openSync(file, "r");
18
+ const header = Buffer.alloc(512);
19
+ const count = fs.readSync(fd, header, 0, header.length, 0);
20
+ return header.toString("utf8", 0, count).includes("AI_BATTERY_MANAGED_CODEX_WRAPPER");
21
+ } catch {
22
+ return false;
23
+ } finally {
24
+ if (fd !== undefined) fs.closeSync(fd);
25
+ }
26
+ }
27
+
28
+ function findWindowsPathCommand(command, env = process.env, skipPaths = []) {
29
+ for (const entry of (env.PATH || "").split(path.delimiter)) {
30
+ const dir = entry.replace(/^"(.*)"$/, "$1");
31
+ for (const name of windowsCommandNames(command, env)) {
32
+ const candidate = path.resolve(dir, name);
33
+ try {
34
+ if (!fs.statSync(candidate).isFile()) continue;
35
+ if (skipPaths.some((entry) => {
36
+ try {
37
+ return fs.realpathSync(candidate).toLowerCase() === fs.realpathSync(entry).toLowerCase();
38
+ } catch {
39
+ return path.resolve(candidate).toLowerCase() === path.resolve(entry).toLowerCase();
40
+ }
41
+ })) continue;
42
+ if (command === "codex" && isManagedWrapper(candidate)) continue;
43
+ return candidate;
44
+ } catch {}
45
+ }
46
+ }
47
+ return null;
48
+ }
49
+
50
+ function normalizeWindowsCommandPath(value) {
51
+ let text = String(value || "").trim();
52
+ for (let i = 0; i < 6; i += 1) {
53
+ const before = text;
54
+ text = text.replace(/\\"/g, "\"").trim();
55
+ if (
56
+ (text.startsWith("\"") && text.endsWith("\""))
57
+ || (text.startsWith("'") && text.endsWith("'"))
58
+ ) {
59
+ text = text.slice(1, -1).trim();
60
+ }
61
+ if (text === before) break;
62
+ }
63
+ return text;
64
+ }
65
+
66
+ function resolveWindowsCommandFile(commandPath) {
67
+ commandPath = normalizeWindowsCommandPath(commandPath);
68
+ if (path.extname(commandPath)) return commandPath;
69
+ for (const suffix of [".cmd", ".exe", ".bat", ".ps1"]) {
70
+ const candidate = `${commandPath}${suffix}`;
71
+ if (fs.existsSync(candidate)) return candidate;
72
+ }
73
+ return commandPath;
74
+ }
75
+
76
+ function resolveNpmCmdShim(commandPath) {
77
+ if (!/\.cmd$/i.test(commandPath)) return null;
78
+ let source;
79
+ try {
80
+ source = fs.readFileSync(commandPath, "utf8");
81
+ } catch {
82
+ return null;
83
+ }
84
+ if (!source.includes("%dp0%") || !source.includes("%*")) return null;
85
+ const match = source.match(/%dp0%[\\/]([^"\r\n]+?\.(?:cjs|mjs|js))"?\s+%\*/i);
86
+ if (!match) return null;
87
+ const scriptPath = path.resolve(path.dirname(commandPath), match[1].replace(/[\\/]+/g, path.sep));
88
+ if (!fs.existsSync(scriptPath)) return null;
89
+ const localNode = path.join(path.dirname(commandPath), "node.exe");
90
+ return {
91
+ // npm uses its adjacent node.exe, otherwise the caller's PATH Node.
92
+ file: fs.existsSync(localNode) ? localNode : findWindowsPathCommand("node") || "node",
93
+ scriptPath
94
+ };
95
+ }
96
+
97
+ function assertSafeCmdArguments(commandPath, args) {
98
+ const unsafePath = UNSAFE_CMD_PATH_RE.test(String(commandPath));
99
+ const unsafeArgument = args.find((value) => UNSAFE_CMD_ARGUMENT_RE.test(String(value)));
100
+ if (!unsafePath && unsafeArgument === undefined) return;
101
+ throw new Error(
102
+ `Cannot safely pass shell metacharacters through legacy batch command ${commandPath}. `
103
+ + "Use an .exe/.js entrypoint or an npm-generated .cmd shim instead."
104
+ );
105
+ }
106
+
107
+ function windowsCommand(command) {
108
+ const exe = resolveWindowsCommandFile(command[0]);
109
+ const rest = command.slice(1);
110
+ if (/\.(cmd|bat)$/i.test(exe)) {
111
+ const npmShim = resolveNpmCmdShim(exe);
112
+ if (npmShim) {
113
+ return {
114
+ file: npmShim.file,
115
+ args: [npmShim.scriptPath, ...rest]
116
+ };
117
+ }
118
+ assertSafeCmdArguments(exe, rest);
119
+ return {
120
+ file: "cmd.exe",
121
+ args: ["/d", "/s", "/c", "call", exe, ...rest]
122
+ };
123
+ }
124
+ if (/\.ps1$/i.test(exe)) {
125
+ return {
126
+ file: "powershell.exe",
127
+ args: ["-NoProfile", "-ExecutionPolicy", "Bypass", "-File", exe, ...rest]
128
+ };
129
+ }
130
+ if (/\.(js|mjs|cjs)$/i.test(exe)) {
131
+ return {
132
+ file: process.execPath,
133
+ args: [exe, ...rest]
134
+ };
135
+ }
136
+ return { file: exe, args: rest };
137
+ }
138
+
139
+ async function runCodexWrapper(runner) {
140
+ const command = findWindowsPathCommand("codex");
141
+ if (!command) {
142
+ console.error("codex: command not found on PATH");
143
+ process.exitCode = 127;
144
+ return;
145
+ }
146
+ const env = { ...process.env, AI_BATTERY_ORIGINAL_CODEX: command };
147
+ delete env.AI_BATTERY_WRAPPED_CODEX;
148
+ let launch;
149
+ if (process.stdin.isTTY && process.stdout.isTTY
150
+ && env.AI_BATTERY_DISABLE_WINDOWS_CODEX_RUNNER !== "1" && fs.existsSync(runner)) {
151
+ env.AI_BATTERY_WRAPPED_CODEX = "1";
152
+ launch = { file: process.execPath, args: [runner, "--provider", "all", "--left-padding", "2", "--", command, ...process.argv.slice(2)] };
153
+ } else {
154
+ launch = windowsCommand([command, ...process.argv.slice(2)]);
155
+ }
156
+ const child = spawn(launch.file, launch.args, { stdio: "inherit", env });
157
+ child.on("error", (error) => {
158
+ console.error("codex: " + error.message);
159
+ process.exitCode = error.code === "ENOENT" ? 127 : 1;
160
+ });
161
+ child.on("exit", (code) => { process.exitCode = code ?? 1; });
162
+ }
163
+
164
+ module.exports = {
165
+ findWindowsPathCommand, windowsCommandNames, runCodexWrapper,
166
+ normalizeWindowsCommandPath, resolveWindowsCommandFile, resolveNpmCmdShim, windowsCommand
167
+ };
@@ -0,0 +1,119 @@
1
+ # Shared by setup, doctor and the self-contained installed wrapper.
2
+ # Resolve paths and bounded headers without running Codex or package managers.
3
+ ai_battery_readlink=$(command -v readlink) || ai_battery_readlink=/usr/bin/readlink
4
+ ai_battery_head=$(command -v head) || ai_battery_head=/usr/bin/head
5
+
6
+ ai_battery_realpath() {
7
+ case "$1" in /*) ai_battery_link=$1 ;; *) ai_battery_link=$PWD/$1 ;; esac
8
+ ai_battery_link_count=0
9
+ while :; do
10
+ ai_battery_link_dir=$(CDPATH= cd -P "${ai_battery_link%/*}" 2>/dev/null && pwd -P) || return 1
11
+ ai_battery_link=$ai_battery_link_dir/${ai_battery_link##*/}
12
+ if [ ! -L "$ai_battery_link" ]; then printf '%s\n' "$ai_battery_link"; return 0; fi
13
+ ai_battery_link_count=$((ai_battery_link_count + 1))
14
+ [ "$ai_battery_link_count" -le 40 ] || return 1
15
+ ai_battery_link_text=$("$ai_battery_readlink" "$ai_battery_link" 2>/dev/null) || return 1
16
+ case "$ai_battery_link_text" in
17
+ /*) ai_battery_link=$ai_battery_link_text ;;
18
+ *) ai_battery_link=$ai_battery_link_dir/$ai_battery_link_text ;;
19
+ esac
20
+ done
21
+ }
22
+
23
+ ai_battery_is_wrapper() {
24
+ ai_battery_header=$("$ai_battery_head" -c 256 "$1" 2>/dev/null) || return 1
25
+ case "$ai_battery_header" in
26
+ *AI_BATTERY_MANAGED_CODEX_WRAPPER*) return 0 ;;
27
+ esac
28
+ return 1
29
+ }
30
+
31
+ ai_battery_nvm_node() {
32
+ case "$1" in
33
+ */versions/node/*)
34
+ ai_battery_version_base=${1%%/versions/node/*}/versions/node/
35
+ ai_battery_version_tail=${1#"$ai_battery_version_base"}
36
+ ai_battery_version=${ai_battery_version_tail%%/*}
37
+ ai_battery_owner_node=$ai_battery_version_base$ai_battery_version/bin/node
38
+ if [ -f "$ai_battery_owner_node" ] && [ -x "$ai_battery_owner_node" ]; then
39
+ printf '%s\n' "$ai_battery_owner_node"
40
+ return 0
41
+ fi
42
+ ;;
43
+ esac
44
+ return 1
45
+ }
46
+
47
+ # Codex follows the caller's PATH and its own launcher. Only AI Battery
48
+ # wrappers are skipped, so npm, Homebrew and standalone installs behave alike.
49
+ ai_battery_find_command() {
50
+ ai_battery_remaining_path=$PATH
51
+ while :; do
52
+ case "$ai_battery_remaining_path" in
53
+ *:*)
54
+ ai_battery_dir=${ai_battery_remaining_path%%:*}
55
+ ai_battery_remaining_path=${ai_battery_remaining_path#*:}
56
+ ai_battery_more=1 ;;
57
+ *) ai_battery_dir=$ai_battery_remaining_path; ai_battery_more=0 ;;
58
+ esac
59
+ ai_battery_candidate=${ai_battery_dir:-.}/$1
60
+ if [ -f "$ai_battery_candidate" ] && [ -x "$ai_battery_candidate" ]; then
61
+ if [ "$1" = codex ]; then
62
+ ai_battery_target=$(ai_battery_realpath "$ai_battery_candidate") || ai_battery_target=$ai_battery_candidate
63
+ if ! ai_battery_is_excluded "$ai_battery_candidate" && ! ai_battery_is_wrapper "$ai_battery_target"; then
64
+ printf '%s\n' "$ai_battery_candidate"
65
+ return 0
66
+ fi
67
+ elif [ "$1" != ai-battery-run ] || ai_battery_usable_runner "$ai_battery_candidate"; then
68
+ printf '%s\n' "$ai_battery_candidate"
69
+ return 0
70
+ fi
71
+ fi
72
+ [ "$ai_battery_more" = 1 ] || break
73
+ done
74
+ return 1
75
+ }
76
+
77
+ ai_battery_usable_runner() {
78
+ [ -f "$1" ] && [ -x "$1" ] || return 1
79
+ ai_battery_runner_target=$(ai_battery_realpath "$1") || return 1
80
+ case "$ai_battery_runner_target" in
81
+ */versions/node/*) ai_battery_nvm_node "$ai_battery_runner_target" >/dev/null ;;
82
+ *) return 0 ;;
83
+ esac
84
+ }
85
+
86
+ ai_battery_codex=$(ai_battery_find_command codex) || ai_battery_codex=
87
+ ai_battery_codex_target=
88
+ if [ -n "$ai_battery_codex" ]; then
89
+ ai_battery_codex_target=$(ai_battery_realpath "$ai_battery_codex") || ai_battery_codex_target=$ai_battery_codex
90
+ fi
91
+ ai_battery_active_node=$(ai_battery_find_command node) || ai_battery_active_node=
92
+ ai_battery_runner=$(ai_battery_find_command ai-battery-run) || ai_battery_runner=
93
+ if [ -z "$ai_battery_runner" ] && ai_battery_usable_runner "$ai_battery_configured_runner"; then
94
+ ai_battery_runner=$ai_battery_configured_runner
95
+ fi
96
+ ai_battery_runner_node=
97
+ if [ -n "$ai_battery_runner" ]; then
98
+ ai_battery_runner_target=$(ai_battery_realpath "$ai_battery_runner") || ai_battery_runner_target=
99
+ ai_battery_runner_node=$(ai_battery_nvm_node "$ai_battery_runner_target") || ai_battery_runner_node=
100
+ fi
101
+
102
+ if [ "${AI_BATTERY_CODEX_RESOLVE_ONLY:-}" = 1 ]; then
103
+ printf '%s\000' "$ai_battery_codex" "$ai_battery_codex_target" "$ai_battery_runner" "$ai_battery_runner_node" "$ai_battery_active_node"
104
+ exit 0
105
+ fi
106
+ if [ -z "$ai_battery_codex" ]; then
107
+ printf '%s\n' 'codex: command not found on PATH' >&2
108
+ exit 127
109
+ fi
110
+ export AI_BATTERY_ORIGINAL_CODEX="$ai_battery_codex"
111
+ unset AI_BATTERY_WRAPPED_CODEX
112
+ if [ -t 0 ] && [ -t 1 ] && [ -x "$ai_battery_runner" ]; then
113
+ # This runtime is for usage polling only. Codex keeps its own shebang and PATH.
114
+ unset AI_BATTERY_NODE
115
+ if [ -n "$ai_battery_runner_node" ]; then export AI_BATTERY_NODE="$ai_battery_runner_node"; fi
116
+ export AI_BATTERY_WRAPPED_CODEX=1
117
+ exec "$ai_battery_runner" --provider all -- "$ai_battery_codex" "$@"
118
+ fi
119
+ exec "$ai_battery_codex" "$@"
@@ -0,0 +1,60 @@
1
+ # npm release
2
+
3
+ The current release candidate is **0.1.19**. `latest` on npm was checked as **0.1.18** on 2026-10-09. Publishing the same name/version twice is not allowed.
4
+
5
+ Preflight on 2026-10-09 passed 105 Windows tests (24 platform skips) and 117 WSL tests (12 platform skips). The installed tarball passed all 13 actual Codex 0.161.0 fullscreen checks under system Node 22.15.1 with automatic private-runtime selection. A fresh official runtime download, SHA256 verification, extraction and launch also passed. Windows and WSL installed CLI readings were checked against the same shared account usage. npm publication and remote Git changes remain pending.
6
+
7
+ The final focused Windows regression uses separate Node 22 and 24.21 installations and compares the original npm launcher with the compositor launcher: Codex Node, unchanged PATH, npm selection, simulated update destination, and the next launch agree in both PATH orders. Removing both original Nodes fails on both paths rather than using the private display Node to rescue Codex. Updates in this test use temporary fixtures, not the production Codex installation or npm registry. A PATH that already mixes one installation's Codex with another installation's npm can still mismatch without AI Battery; the wrapper preserves that original selection.
8
+
9
+ ## Changes
10
+
11
+ - Codex wrappers on Windows and POSIX resolve the original command from the caller's current PATH, skipping AI Battery wrappers. Node version changes do not pin Codex to an older installation.
12
+ - Windows defaults to Fullscreen PTY composition with a terminal battery row. Rendering preserves Codex's footer, battery styles and ordered output without serial parser delays.
13
+ - On Windows, a private verified Node 24.21.0 runtime is prepared on first interactive launch if the caller's Node lacks VT raw input. It does not replace system Node or change PATH. Runtime/dependency failures fall back to the existing native HUD.
14
+ - Account rate-limit selection ignores model-specific empty buckets. Windows and WSL share the latest account usage while preserving separate Codex session stores. Both installations must be updated.
15
+ - Windows Terminal padding is not modified by setup. The local padding adjustment is not a package dependency.
16
+
17
+ ## Prepare
18
+
19
+ ```powershell
20
+ npm run check
21
+ npm pack --dry-run
22
+ npm pack
23
+ ```
24
+
25
+ Inspect the package file list. Screenshots, logs, credentials, local runtime binaries and `.cache` must not be included. Test the tarball with a clean installation and test Windows runtime switching, POSIX PATH switching, and shared usage. Windows ARM64 runtime paths are supported but require a device check; the release's manual Windows verification used x64.
26
+
27
+ ## Publish manually
28
+
29
+ ```powershell
30
+ npm login
31
+ npm whoami
32
+ npm publish ./ai-battery-0.1.19.tgz --access public --tag latest
33
+ npm view ai-battery version dist-tags --json
34
+ ```
35
+
36
+ Use the exact tested tarball. Complete npm's authentication/2FA prompt when requested. This repository's preflight does not perform `npm login` or `npm publish` automatically. If 0.1.19 has already been published by the time you release, increment the package version and repeat the preparation.
37
+
38
+ For a preview instead of replacing `latest`:
39
+
40
+ ```powershell
41
+ npm publish ./ai-battery-0.1.19.tgz --access public --tag next
42
+ ```
43
+
44
+ After a successful publication, tag the tested commit (`v0.1.19`), push the release commit/tag, and remove merged remote feature branches. Do not delete the remote test branch before the integrated release commit reaches the remote main branch.
45
+
46
+ ## Update installed integrations
47
+
48
+ Run this separately in Windows and WSL:
49
+
50
+ ```text
51
+ npm install -g ai-battery@0.1.19
52
+ ai-battery setup codex
53
+ ai-battery doctor
54
+ ```
55
+
56
+ Restart the terminal session after updating. A running PTY wrapper retains its loaded code. Existing local custom wrappers must be regenerated by setup to adopt PATH lookup and private runtime selection.
57
+
58
+ The private Windows runtime lives under `%LOCALAPPDATA%\ai-battery\runtimes` by default, or the selected AI Battery data directory. `AI_BATTERY_RUNTIME_DOWNLOAD=0` disables downloading. An interrupted preparation lock expires after five minutes; downloads and extracted staging files are cleaned after completion/failure.
59
+
60
+ Official npm references: [publish](https://docs.npmjs.com/cli/v11/commands/npm-publish/), [login](https://docs.npmjs.com/cli/v11/commands/npm-login/).