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.
File without changes
File without changes
@@ -1,2 +1,2 @@
1
- $implementation = Join-Path $PSScriptRoot "..\lib\platforms\windows\hud\main.ps1"
2
- . $implementation @args
1
+ $implementation = Join-Path $PSScriptRoot "..\lib\platforms\windows\hud\main.ps1"
2
+ . $implementation @args
@@ -40,6 +40,8 @@ def battery_command_base():
40
40
  return [BATTERY_BIN]
41
41
  DEFAULT_COLUMN_GUARD = 4
42
42
  DEFAULT_LEFT_PADDING = 2
43
+ STATUS_FETCH_TIMEOUT = 10.0
44
+ STATUS_OUTPUT_LIMIT = 64 * 1024
43
45
 
44
46
 
45
47
  def usage():
@@ -54,7 +56,7 @@ def usage():
54
56
 
55
57
 
56
58
  def parse_args(argv):
57
- interval = float(os.environ.get("AI_BATTERY_INTERVAL") or os.environ.get("CLAUDEX_BATTERY_INTERVAL", "10"))
59
+ interval = float(os.environ.get("AI_BATTERY_INTERVAL") or os.environ.get("CLAUDEX_BATTERY_INTERVAL", "2"))
58
60
  bar_width = os.environ.get("AI_BATTERY_BAR_WIDTH") or os.environ.get("CLAUDEX_BATTERY_BAR_WIDTH", "10")
59
61
  provider = os.environ.get("AI_BATTERY_PROVIDER") or os.environ.get("CLAUDEX_BATTERY_PROVIDER", "auto")
60
62
  layout = os.environ.get("AI_BATTERY_LAYOUT") or os.environ.get("CLAUDEX_BATTERY_LAYOUT", "auto")
@@ -181,6 +183,12 @@ class StatusLine:
181
183
  self.last_draw = 0.0
182
184
  self.text = "AI Battery starting..."
183
185
  self.last_line = None
186
+ self.fetch_process = None
187
+ self.fetch_deadline = 0.0
188
+ self.fetch_output = bytearray()
189
+ self.has_reading = False
190
+ self.last_reading = ""
191
+ self.fetch_failures = 0
184
192
  self.cols, self.rows = term_size()
185
193
 
186
194
  def resize(self):
@@ -188,10 +196,42 @@ class StatusLine:
188
196
 
189
197
  def refresh(self, force=False):
190
198
  now = time.monotonic()
199
+ previous = self.text
200
+ if self.fetch_process is not None:
201
+ process = self.fetch_process
202
+ try:
203
+ code = process.poll()
204
+ while True:
205
+ try:
206
+ chunk = os.read(process.stdout.fileno(), 8192)
207
+ except BlockingIOError:
208
+ break
209
+ if not chunk:
210
+ break
211
+ self.fetch_output.extend(chunk)
212
+ if len(self.fetch_output) > STATUS_OUTPUT_LIMIT:
213
+ raise ValueError("status output exceeds limit")
214
+ if code is not None:
215
+ text = self.fetch_output.decode("utf-8", errors="replace").rstrip("\r\n")
216
+ self.close()
217
+ if code == 0 and text:
218
+ self.text = text
219
+ self.last_reading = text
220
+ self.has_reading = True
221
+ self.fetch_failures = 0
222
+ else:
223
+ self.fetch_failed()
224
+ elif now >= self.fetch_deadline:
225
+ self.close()
226
+ self.fetch_failed()
227
+ except (OSError, ValueError):
228
+ self.close()
229
+ self.fetch_failed()
230
+ return self.text != previous
231
+
191
232
  if not force and now < self.next_fetch:
192
233
  return False
193
234
  self.next_fetch = now + self.interval
194
- previous = self.text
195
235
  max_width = max(20, self.cols - column_guard())
196
236
  try:
197
237
  battery_command = battery_command_base() + [
@@ -207,22 +247,49 @@ class StatusLine:
207
247
  battery_command.extend(["--active-provider", self.active_provider])
208
248
  if self.provider != "all":
209
249
  battery_command.extend(["--provider", self.provider])
210
- output = subprocess.check_output(
250
+ # Usage scans can include slow WSL/PowerShell process queries. Keep
251
+ # them off the terminal relay path so typing and output stay live.
252
+ self.fetch_process = subprocess.Popen(
211
253
  battery_command,
254
+ stdin=subprocess.DEVNULL,
255
+ stdout=subprocess.PIPE,
212
256
  stderr=subprocess.DEVNULL,
213
- timeout=1.5,
214
257
  )
215
- text = output.decode("utf-8", errors="replace").rstrip("\r\n")
216
- if text:
217
- self.text = text
218
- except Exception:
219
- self.text = "AI Battery unavailable"
258
+ os.set_blocking(self.fetch_process.stdout.fileno(), False)
259
+ self.fetch_deadline = now + STATUS_FETCH_TIMEOUT
260
+ self.fetch_output = bytearray()
261
+ except (OSError, ValueError):
262
+ self.close()
263
+ self.fetch_failed()
220
264
  return self.text != previous
221
265
 
266
+ def fetch_failed(self):
267
+ self.fetch_failures += 1
268
+ retry_delay = min(self.interval, 2 ** min(self.fetch_failures - 1, 4))
269
+ self.next_fetch = time.monotonic() + retry_delay
270
+ # Retain the reading, but make failed updates visible rather than
271
+ # presenting the old percentage as a successful current reading.
272
+ self.text = ("[stale] " + self.last_reading.lstrip()) if self.has_reading else "AI Battery unavailable"
273
+
274
+ def close(self):
275
+ process = self.fetch_process
276
+ if process is None:
277
+ return
278
+ self.fetch_process = None
279
+ if process.poll() is None:
280
+ try:
281
+ process.kill()
282
+ except ProcessLookupError:
283
+ pass
284
+ process.wait()
285
+ process.stdout.close()
286
+
222
287
  def refresh_due(self):
223
- return time.monotonic() >= self.next_fetch
288
+ return self.fetch_process is not None or time.monotonic() >= self.next_fetch
224
289
 
225
290
  def seconds_until_refresh(self):
291
+ if self.fetch_process is not None:
292
+ return 0.05
226
293
  return max(0.0, self.next_fetch - time.monotonic())
227
294
 
228
295
  def _write_row(self, line):
@@ -239,9 +306,7 @@ class StatusLine:
239
306
  os.write(sys.stdout.fileno(), payload.encode("utf-8", errors="replace"))
240
307
 
241
308
  def draw_cached(self):
242
- """Repaint the cached text at the current terminal size without fetching new data.
243
- Used on resize so the bar is repositioned instantly, avoiding the ~100ms
244
- subprocess call that would otherwise delay the repaint."""
309
+ """Repaint cached text at the new terminal size without starting a poll."""
245
310
  paint_width = max(1, self.cols - 1)
246
311
  line = fit_ansi(self.text, paint_width, pad=True)
247
312
  self.last_draw = time.monotonic()
@@ -321,9 +386,7 @@ def main():
321
386
  os.kill(pid, signal.SIGWINCH)
322
387
  except ProcessLookupError:
323
388
  pass
324
- # Repaint immediately at the new size using cached text (no subprocess call).
325
- # A subprocess call here blocks signal delivery for ~100ms, causing color
326
- # flicker and stutter during resize. Schedule a fresh fetch instead.
389
+ # Repaint immediately, then schedule a fresh poll at the new width.
327
390
  status.draw_cached()
328
391
  status.next_fetch = 0.0
329
392
 
@@ -384,6 +447,7 @@ def main():
384
447
  elif status.refresh_due():
385
448
  status.draw(False)
386
449
  finally:
450
+ status.close()
387
451
  termios.tcsetattr(sys.stdin.fileno(), termios.TCSADRAIN, old_term)
388
452
  status.clear()
389
453
 
File without changes
package/bin/ai-battery.js CHANGED
File without changes
@@ -1,167 +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
- };
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
+ };
package/docs/RELEASING.md CHANGED
@@ -1,60 +1,64 @@
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/).
1
+ # npm release
2
+
3
+ The current release candidate is **0.1.21**, prepared from the 0.1.20 main branch. npm `latest` was checked as **0.1.20** on 2026-10-15. This preparation does not publish to npm or create a release tag.
4
+
5
+ ## Changes in 0.1.21
6
+
7
+ - Windows default PTY composition and POSIX terminal rows poll every 2 seconds by default. POSIX polling runs asynchronously so usage scans do not block terminal input or output.
8
+ - Polls allow up to 10 seconds by default. Failed updates retry after 1 second, with backoff for repeated failures. A retained reading is marked `[stale]`; an initial failure displays `AI Battery unavailable`.
9
+ - New and changed Codex session logs invalidate the parsing cache before its normal expiry. Account usage sharing between Windows and WSL, separate session stores, and existing runtime selection are preserved.
10
+ - WSL reuses a brief Windows process scan cache. A known active Codex does not require another process scan just to fetch its usage.
11
+ - The package no longer depends on an older copy of `ai-battery` itself.
12
+
13
+ Values remain the latest usage reported by local Codex logs and Claude statusLine. They are not direct live server measurements; delayed source updates can delay the display.
14
+
15
+ ## Validation
16
+
17
+ The integrated candidate passed the following checks on 2026-10-15:
18
+
19
+ | Check | Result |
20
+ | --- | --- |
21
+ | WSL `npm run check` | 133 passed, 15 platform skips, 0 failures |
22
+ | Windows native Node 22.23.2 `node --test` | 117 passed, 31 platform skips, 0 failures |
23
+ | Focused polling and freshness tests | Slow polls, failed/empty/partial/oversized output, automatic recovery, zero remaining, new sessions, and cache invalidation |
24
+
25
+ Tarball installation results, package contents, and checksums are saved with the local release artifacts under `.cache/releases/0.1.21/`. Windows ARM64 still requires a device check; native verification here uses x64.
26
+
27
+ ## Prepare
28
+
29
+ ```text
30
+ npm run check
31
+ npm pack --dry-run
32
+ npm pack --pack-destination .cache/releases/0.1.21
33
+ ```
34
+
35
+ Inspect the package file list. It must include `lib`, the bin entrypoints and required PowerShell modules. Screenshots, logs, credentials, local runtime binaries, tests and `.cache` must not be included. Test the exact tarball with a clean installation on Windows and POSIX. On Windows, also run `npm run smoke:composite` and `npm run smoke:codex-fullscreen-win` against the installed runner; the Codex fixture uses a local mock server and does not consume account quota.
36
+
37
+ ## Publish manually
38
+
39
+ ```text
40
+ npm login
41
+ npm whoami
42
+ npm publish .cache/releases/0.1.21/ai-battery-0.1.21.tgz --access public --tag latest
43
+ npm view ai-battery version dist-tags --json
44
+ ```
45
+
46
+ Use the exact tested tarball. Complete npm's authentication/2FA prompt when requested. Publishing the same name/version twice is not allowed. If 0.1.21 is already published when you release, increment the version and repeat preparation. Use `--tag next` instead of `--tag latest` for a preview release.
47
+
48
+ After successful publication, tag the tested commit (`v0.1.21`) and push the release tag. Keep the remote release branch until the release commit is integrated into main.
49
+
50
+ ## Update installed integrations
51
+
52
+ Run separately in Windows and WSL:
53
+
54
+ ```text
55
+ npm install -g ai-battery@0.1.21
56
+ ai-battery setup codex
57
+ ai-battery doctor
58
+ ```
59
+
60
+ Restart the terminal session after updating. A running PTY wrapper retains its loaded code. Existing managed wrappers must be regenerated by setup to adopt the current integration.
61
+
62
+ 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. System Node, PATH and the original Codex installation are preserved.
63
+
64
+ Official npm references: [publish](https://docs.npmjs.com/cli/v11/commands/npm-publish/), [login](https://docs.npmjs.com/cli/v11/commands/npm-login/).