ai-battery 0.1.26 → 0.1.27

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.27: 한글 오류 메시지가 포함된 하단 사용량 줄이 갱신될 때 Codex 화면에 여러 줄로 누적되던 문제를 수정했습니다. 화면 칸 수를 기준으로 너비를 제한하고 불필요한 공백 채우기를 제거했습니다. 하단 바의 데이터 없음 표시는 `Claude --%`처럼 간결하게 표시합니다.
4
+
3
5
  0.1.26: `setup`이 기존 Codex 연동을 해제하던 문제를 수정했습니다. 기존 wrapper·PATH·Codex 상태줄과 tmux 연동을 유지·갱신하며, 실행 중인 셸이 기억하는 경로를 제거하지 않습니다. tmux 미실행 상태를 구분하고 HUD 메뉴의 밝은 테두리를 제거했습니다. 기본 예시는 `ai-battery setup tmux`입니다.
4
6
 
5
7
  0.1.25: Ubuntu/Linux 패널 HUD를 추가했습니다. macOS와 같은 로고·배터리 바·퍼센트를 표시합니다. 도움말·진단·설정 결과·오류 안내는 간결한 한국어/영어로 표시합니다. 명령 없이 실행하면 도움말을 표시하며 `show` 명령은 제거했습니다. 설정 복원은 `ai-battery reset`으로 실행하고, 이전 `reset settings`·`reset config`도 계속 지원합니다.
@@ -6,6 +6,7 @@ import signal
6
6
  import subprocess
7
7
  import sys
8
8
  import time
9
+ import unicodedata
9
10
 
10
11
  if os.name == "nt":
11
12
  print(
@@ -25,7 +26,12 @@ import tty
25
26
 
26
27
  SCRIPT_DIR = os.path.dirname(os.path.realpath(__file__))
27
28
  BATTERY_BIN = os.environ.get("AI_BATTERY_BIN") or os.environ.get("CLAUDEX_BATTERY_BIN", os.path.join(SCRIPT_DIR, "ai-battery.js"))
28
- ANSI_RE = re.compile(r"\x1b\[[0-?]*[ -/]*[@-~]")
29
+ ANSI_RE = re.compile(
30
+ r"(\x1b(?:\[[0-?]*[ -/]*[@-~]"
31
+ r"|\][^\x07\x1b]*(?:\x07|\x1b\\|$)"
32
+ r"|[PX^_][\s\S]*?(?:\x1b\\|$)|[ -/]*[@-~]))"
33
+ )
34
+ SGR_RE = re.compile(r"\x1b\[[0-9:;]*m")
29
35
 
30
36
 
31
37
  def battery_command_base():
@@ -164,12 +170,31 @@ def column_guard():
164
170
  return DEFAULT_COLUMN_GUARD
165
171
 
166
172
 
167
- def fit_ansi(text, width, pad=True):
168
- plain = strip_ansi(text)
169
- if len(plain) <= width:
170
- return text + (" " * (width - len(plain)) if pad else "")
171
- suffix = " " if pad else ""
172
- return plain[: max(0, width - len(suffix))] + suffix
173
+ def fit_ansi(text, width):
174
+ # Python len() counts code points, not terminal cells. Padding a Korean
175
+ # line using len() can wrap at the bottom and scroll a copy into the TUI
176
+ # on every refresh. EL clears the tail, so no padding is necessary.
177
+ output = []
178
+ cells = 0
179
+ for token in ANSI_RE.split(text):
180
+ if token.startswith("\x1b"):
181
+ # Status output may style text, but must never move the cursor,
182
+ # erase the child's screen or introduce another physical row.
183
+ if SGR_RE.fullmatch(token):
184
+ output.append(token)
185
+ continue
186
+ for char in token:
187
+ category = unicodedata.category(char)
188
+ if category in ("Cc", "Cs"):
189
+ continue
190
+ char_width = 0 if category in ("Mn", "Me", "Cf") else (
191
+ 2 if unicodedata.east_asian_width(char) in ("W", "F") else 1
192
+ )
193
+ if cells + char_width > width:
194
+ return "".join(output)
195
+ output.append(char)
196
+ cells += char_width
197
+ return "".join(output)
173
198
 
174
199
 
175
200
  class StatusLine:
@@ -308,7 +333,7 @@ class StatusLine:
308
333
  def draw_cached(self):
309
334
  """Repaint cached text at the new terminal size without starting a poll."""
310
335
  paint_width = max(1, self.cols - 1)
311
- line = fit_ansi(self.text, paint_width, pad=True)
336
+ line = fit_ansi(self.text, paint_width)
312
337
  self.last_draw = time.monotonic()
313
338
  self.last_line = line
314
339
  self._write_row(line)
@@ -319,7 +344,7 @@ class StatusLine:
319
344
  return
320
345
  self.refresh(force)
321
346
  paint_width = max(1, self.cols - 1)
322
- line = fit_ansi(self.text, paint_width, pad=True)
347
+ line = fit_ansi(self.text, paint_width)
323
348
  if not force and not dirty and line == self.last_line:
324
349
  return
325
350
  self.last_draw = now
package/docs/RELEASING.md CHANGED
@@ -1,6 +1,12 @@
1
1
  # npm release
2
2
 
3
- The prepared version is **0.1.26**, following the published 0.1.25. Preparing or pushing this release does not publish it to npm.
3
+ The prepared version is **0.1.27**, following the published 0.1.26. Preparing or pushing this release does not publish it to npm.
4
+
5
+ ## Fixes in 0.1.27
6
+
7
+ - POSIX terminal rows measure Korean/full-width text in screen cells, retain colors while clipping, and clear the old tail without space padding. Repeated refreshes no longer wrap the bottom row and accumulate meter copies in the Codex screen or scrollback. Bounded rows show unavailable providers as `Codex --%` / `Claude --%`; detailed diagnostics retain localized errors.
8
+
9
+ The active runner keeps its Python code until the next launch. Updating the CLI formatter also mitigates the reported Korean-error overflow in already-running sessions, since each status poll loads the formatter again. Existing Codex processes need not be terminated.
4
10
 
5
11
  ## Fixes in 0.1.26
6
12
 
@@ -16,14 +22,16 @@ The prepared version is **0.1.26**, following the published 0.1.25. Preparing or
16
22
  ```text
17
23
  npm run check
18
24
  npm run smoke:linux
19
- mkdir -p .cache/releases/0.1.26
25
+ mkdir -p .cache/releases/0.1.27
20
26
  npm pack --dry-run --json
21
- npm pack --pack-destination .cache/releases/0.1.26 --json
27
+ npm pack --pack-destination .cache/releases/0.1.27 --json
22
28
  ```
23
29
 
24
30
  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.
25
31
 
26
- Also install 0.1.25 into an isolated npm prefix, open the PTY fixture, upgrade that prefix to the exact 0.1.26 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.26/`.
32
+ 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.
33
+
34
+ Also install 0.1.26 into an isolated npm prefix, open the PTY fixture, upgrade that prefix to the exact 0.1.27 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.27/`.
27
35
 
28
36
  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.
29
37
 
@@ -33,16 +41,16 @@ Inspect the tarball for runtime modules, stable bin entrypoints and required pla
33
41
 
34
42
  ```text
35
43
  npm whoami
36
- npm publish .cache/releases/0.1.26/ai-battery-0.1.26.tgz --access public --tag latest
44
+ npm publish .cache/releases/0.1.27/ai-battery-0.1.27.tgz --access public --tag latest
37
45
  npm view ai-battery version dist-tags --json
38
46
  ```
39
47
 
40
- Authenticate with `npm login` if required, and complete npm 2FA when requested. If 0.1.26 is already published, increment the version and repeat verification. Tag the tested commit `v0.1.26` after publication.
48
+ Authenticate with `npm login` if required, and complete npm 2FA when requested. If 0.1.27 is already published, increment the version and repeat verification. Tag the tested commit `v0.1.27` after publication.
41
49
 
42
50
  ## Update and enable terminal display
43
51
 
44
52
  ```text
45
- npm install -g ai-battery@0.1.26
53
+ npm install -g ai-battery@0.1.27
46
54
  ai-battery setup
47
55
  ai-battery setup tmux
48
56
  tmux
package/lib/cli.js CHANGED
@@ -4378,7 +4378,8 @@ function weekText(secondary) {
4378
4378
  }
4379
4379
 
4380
4380
  function formatCodex(data, args) {
4381
- if (!data.ok) return statusColorize(data, `Codex ? (${cliMessageText(data.error)})`, args);
4381
+ if (!data.ok) return statusColorize(data, args.maxWidth && !args.showPaths
4382
+ ? "Codex --%" : `Codex ? (${cliMessageText(data.error)})`, args);
4382
4383
 
4383
4384
  const batteryColor = remainingColor(data.percentRemaining);
4384
4385
  const primary = data.primary;
@@ -4413,7 +4414,8 @@ function formatCodex(data, args) {
4413
4414
  }
4414
4415
 
4415
4416
  function formatClaude(data, args) {
4416
- if (!data.ok) return statusColorize(data, `Claude ? (${cliMessageText(data.error)})`, args);
4417
+ if (!data.ok) return statusColorize(data, args.maxWidth && !args.showPaths
4418
+ ? "Claude --%" : `Claude ? (${cliMessageText(data.error)})`, args);
4417
4419
 
4418
4420
  if (data.sourceType === "statusline") {
4419
4421
  const batteryColor = remainingColor(data.percentRemaining);
@@ -4977,7 +4979,7 @@ function render(snapshot, args) {
4977
4979
  }
4978
4980
  // A split pane can be too narrow even for the minimum bars. Retain both
4979
4981
  // names and readings rather than letting the one-row terminal wrap away
4980
- // a provider. Error detail and bars remain available in wider panes.
4982
+ // a provider. Detailed errors remain available in diagnostics.
4981
4983
  const readings = snapshot.results.map((result) => {
4982
4984
  const percent = typeof result.percentRemaining === "number" ? `${result.percentRemaining}%` : "--%";
4983
4985
  const name = result.provider === "codex" ? "Codex" : result.provider === "claude" ? "Claude" : result.provider;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ai-battery",
3
- "version": "0.1.26",
3
+ "version": "0.1.27",
4
4
  "description": "Tiny terminal battery meter for local Codex and Claude Code usage.",
5
5
  "type": "module",
6
6
  "keywords": [