ai-battery 0.1.22 → 0.1.24
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 +81 -83
- package/bin/ai-battery-run +9 -1
- package/docs/RELEASING.md +21 -41
- package/lib/cli.js +56 -42
- package/lib/core/uninstall.js +0 -60
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# AI Battery
|
|
2
2
|
|
|
3
|
-
0.1.
|
|
3
|
+
0.1.24: `ai-battery setup`만으로 Claude와 Codex의 사용량 표시를 자동 연결합니다. 원본 Codex 실행 파일과 기존 설정은 보존합니다. `reset settings`는 AI Battery의 변경을 복원하며 npm 패키지 삭제는 별도로 진행합니다.
|
|
4
4
|
|
|
5
5
|
[한국어](README.md) · [English](docs/i18n/en/) · [日本語](docs/i18n/ja/) · [中文](docs/i18n/zh/) · [Español](docs/i18n/es/)
|
|
6
6
|
|
|
@@ -29,34 +29,34 @@ Markdown의 텍스트 fallback은 렌더러별 블록 문자 높이 차이를
|
|
|
29
29
|
Codex 86% │ 5h 18:09 │ 7d 82% ┃ Claude 4% │ 5h 18:10 │ 7d 71%
|
|
30
30
|
```
|
|
31
31
|
|
|
32
|
-
| Provider
|
|
33
|
-
|
|
|
34
|
-
| Codex
|
|
35
|
-
| Claude Code
|
|
36
|
-
| Claude fallback | `~/.claude/projects/**/*.jsonl`
|
|
32
|
+
| Provider | Source | Shows |
|
|
33
|
+
| --------------- | ------------------------------------------------ | ------------------------------ |
|
|
34
|
+
| Codex | `~/.codex/sessions/**/*.jsonl` | 5h 잔량, 5h 리셋 시각, 7d 잔량 |
|
|
35
|
+
| Claude Code | Claude `statusLine` payload cache + 429 hit logs | 5h 잔량, 5h 리셋 시각, 7d 잔량 |
|
|
36
|
+
| Claude fallback | `~/.claude/projects/**/*.jsonl` | 최근 턴 토큰 사용량 |
|
|
37
37
|
|
|
38
38
|
## Features
|
|
39
39
|
|
|
40
|
-
| Feature
|
|
41
|
-
|
|
|
42
|
-
| 공통 사용량 표시
|
|
43
|
-
| 리셋 시각 표시
|
|
44
|
-
| 색상 기준
|
|
45
|
-
| Codex terminal row | Windows에서는 가상 터미널 화면과 배터리 행을 합성하고, WSL/Linux/macOS에서는 PTY wrapper로 별도 사용량 행을 고정합니다.
|
|
46
|
-
| Claude statusLine
|
|
47
|
-
| HUD / menu bar
|
|
48
|
-
| npm 실행
|
|
40
|
+
| Feature | Description |
|
|
41
|
+
| ------------------ | ------------------------------------------------------------------------------------------------------------------------- |
|
|
42
|
+
| 공통 사용량 표시 | Codex와 Claude Code 사용량을 같은 형식으로 표시합니다. |
|
|
43
|
+
| 리셋 시각 표시 | `5h`, `7d` 창 라벨과 값을 표시합니다. |
|
|
44
|
+
| 색상 기준 | 40% 초과 초록, 21-40% 주황, 20% 이하 빨강으로 배터리만 강조합니다. |
|
|
45
|
+
| Codex terminal row | Windows에서는 가상 터미널 화면과 배터리 행을 합성하고, WSL/Linux/macOS에서는 PTY wrapper로 별도 사용량 행을 고정합니다. |
|
|
46
|
+
| Claude statusLine | Claude Code 내장 statusLine hook과 실제 429 hit 로그로 Claude rate limit 상태를 읽습니다. |
|
|
47
|
+
| HUD / menu bar | Windows native에서는 terminal-docked/floating HUD, WSL에서는 floating HUD, macOS에서는 menu bar status item을 제공합니다. |
|
|
48
|
+
| npm 실행 | `npm install -g` 또는 `npx`로 실행할 수 있습니다. |
|
|
49
49
|
|
|
50
50
|
## Platform Support
|
|
51
51
|
|
|
52
|
-
| Mode
|
|
53
|
-
|
|
|
54
|
-
| `ai-battery`
|
|
55
|
-
| `ai-battery --watch`
|
|
56
|
-
| Claude statusLine
|
|
57
|
-
| Codex fullscreen
|
|
58
|
-
| `ai-battery setup codex` | 지원 | 지원 | 지원 | 지원 |
|
|
59
|
-
| `ai-battery hud`
|
|
52
|
+
| Mode | Windows native | WSL | Linux | macOS | Note |
|
|
53
|
+
| ------------------------ | -------------- | ---- | ------ | ----- | --------------------------------------------------------------------------------------------------------------------------- |
|
|
54
|
+
| `ai-battery` | 지원 | 지원 | 지원 | 지원 | Node.js 18 이상이 필요합니다. |
|
|
55
|
+
| `ai-battery --watch` | 지원 | 지원 | 지원 | 지원 | 터미널 안에서 주기적으로 갱신합니다. |
|
|
56
|
+
| Claude statusLine | 지원 | 지원 | 지원 | 지원 | Claude Code `statusLine`에 `node <script>` 명령을 저장합니다. |
|
|
57
|
+
| Codex fullscreen | 지원 | 지원 | 지원 | 지원 | Windows 기본값은 Fullscreen PTY 화면과 터미널 배터리 행을 합성합니다. WSL/Linux/macOS는 POSIX PTY와 `python3`를 사용합니다. |
|
|
58
|
+
| `ai-battery setup codex` | 지원 | 지원 | 지원 | 지원 | 원본 실행 파일을 보존하는 관리형 wrapper로 Codex 사용량을 자동 표시합니다. |
|
|
59
|
+
| `ai-battery hud` | 지원 | 지원 | 미지원 | 지원 | Windows/WSL은 PowerShell/WinForms HUD, macOS는 menu bar status item입니다. |
|
|
60
60
|
|
|
61
61
|
실행 중 감지는 Linux/WSL은 `/proc`, macOS는 `ps`, Windows는 PowerShell 프로세스 목록을 사용합니다. 텍스트 출력은 흰색/회색으로, macOS HUD는 실행 중인 항목만 색상 배터리바로 강조하고 비실행 항목은 흐린 회색 계열로 표시합니다.
|
|
62
62
|
|
|
@@ -82,20 +82,20 @@ npx ai-battery
|
|
|
82
82
|
npm install -g ai-battery
|
|
83
83
|
```
|
|
84
84
|
|
|
85
|
-
2. Claude statusLine
|
|
85
|
+
2. Claude statusLine과 Codex 자동 표시를 설정합니다.
|
|
86
86
|
|
|
87
87
|
```bash
|
|
88
88
|
ai-battery setup
|
|
89
89
|
```
|
|
90
90
|
|
|
91
|
-
3.
|
|
91
|
+
3. 새 터미널을 열거나 setup이 안내한 셸 갱신 명령을 실행한 뒤, 원래 명령을 그대로 사용합니다.
|
|
92
92
|
|
|
93
93
|
```bash
|
|
94
94
|
claude
|
|
95
95
|
codex
|
|
96
96
|
```
|
|
97
97
|
|
|
98
|
-
4.
|
|
98
|
+
4. 별도 데스크톱 표시가 필요하면 Windows/WSL/macOS HUD를 실행합니다.
|
|
99
99
|
|
|
100
100
|
```bash
|
|
101
101
|
ai-battery hud
|
|
@@ -111,73 +111,71 @@ ai-battery --version
|
|
|
111
111
|
ai-battery --provider codex
|
|
112
112
|
ai-battery --provider claude
|
|
113
113
|
ai-battery setup
|
|
114
|
-
ai-battery
|
|
114
|
+
ai-battery reset settings
|
|
115
115
|
ai-battery doctor
|
|
116
116
|
ai-battery hud
|
|
117
117
|
ai-battery off codex
|
|
118
118
|
ai-battery on codex
|
|
119
119
|
```
|
|
120
120
|
|
|
121
|
-
| Option
|
|
122
|
-
|
|
|
123
|
-
| `--provider all\|codex\|claude` | 표시할 provider를 선택합니다.
|
|
124
|
-
| `--watch [seconds]`
|
|
125
|
-
| `--json`
|
|
126
|
-
| `--bar-width N`
|
|
127
|
-
| `--show-paths`
|
|
128
|
-
| `-v`, `--version`
|
|
121
|
+
| Option | Description |
|
|
122
|
+
| ------------------------------- | ---------------------------------------------------- |
|
|
123
|
+
| `--provider all\|codex\|claude` | 표시할 provider를 선택합니다. |
|
|
124
|
+
| `--watch [seconds]` | 같은 줄에서 주기적으로 갱신합니다. |
|
|
125
|
+
| `--json` | HUD나 다른 도구에서 쓰기 좋은 JSON을 출력합니다. |
|
|
126
|
+
| `--bar-width N` | 터미널 배터리 바 길이를 조정합니다. |
|
|
127
|
+
| `--show-paths` | 로그 파일 경로와 데이터 관측 시각을 함께 표시합니다. |
|
|
128
|
+
| `-v`, `--version` | 설치된 `ai-battery` 버전을 출력합니다. |
|
|
129
129
|
|
|
130
130
|
`doctor`는 설치 상태와 함께 npm latest 버전을 확인합니다. 네트워크가 막혀 있으면 버전 확인만 건너뛰고 나머지 진단은 계속 표시합니다.
|
|
131
131
|
|
|
132
|
-
|
|
132
|
+
<a id="uninstall"></a>
|
|
133
133
|
|
|
134
|
-
|
|
134
|
+
## Reset Settings
|
|
135
|
+
|
|
136
|
+
`ai-battery reset settings`는 AI Battery가 추가한 통합 설정을 원래 값으로 복원하고, 소유권을 확인한 AI Battery 캐시·전용 런타임·생성 파일을 정리합니다. Codex·Claude의 관련 없는 설정과 npm 패키지·실행 명령은 유지합니다. Codex나 Claude의 설정 전체를 기본값으로 초기화하는 명령은 아닙니다.
|
|
135
137
|
|
|
136
138
|
```bash
|
|
137
|
-
ai-battery
|
|
139
|
+
ai-battery reset settings
|
|
138
140
|
```
|
|
139
141
|
|
|
140
|
-
|
|
142
|
+
`ai-battery reset config`도 같은 동작입니다. 일부 통합만 복원하려면 대상을 지정합니다. 대상 지정 시 다른 통합과 공통 캐시는 유지합니다.
|
|
141
143
|
|
|
142
144
|
```bash
|
|
143
|
-
ai-battery
|
|
144
|
-
ai-battery
|
|
145
|
-
ai-battery
|
|
145
|
+
ai-battery reset settings codex
|
|
146
|
+
ai-battery reset settings claude
|
|
147
|
+
ai-battery reset settings hud
|
|
148
|
+
ai-battery reset settings tmux
|
|
146
149
|
```
|
|
147
150
|
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
복구 기록은 `ai-battery uninstall`이 해당 항목을 성공적으로 복원하거나 안전하게 제거한 뒤에만 지워집니다. Claude는 기존 `statusLine`과 파일 존재 여부·권한만 저장하며 `settings.json` 전체를 복제하지 않으므로 다른 설정이나 비밀값을 백업 파일에 중복 보관하지 않습니다. JSON 결과나 종료 코드를 확인하는 자동화에서는 0일 때만 완전한 정리로 간주하세요.
|
|
151
|
+
관리 중인 status line이나 설정 블록이 사용자에 의해 변경됐다면 덮어쓰지 않고 복구 기록을 보존하며 종료 코드 1로 알립니다. 관련 없는 Codex·Claude 설정, 사용자 추가 파일, 확인할 수 없는 파일은 보존합니다. 셸·tmux의 사용자 수정도 관리 블록 밖의 내용은 유지합니다. 복구 기록은 해당 항목이 복원되거나 안전하게 제거된 뒤에만 지워집니다.
|
|
151
152
|
|
|
152
|
-
|
|
153
|
+
패키지까지 삭제하려면 설정 복원이 성공한 다음 npm으로 제거합니다. 로컬 설치는 `npm uninstall ai-battery`, 전역 설치는 아래 명령을 사용합니다. Windows와 WSL, Node 버전별 설치는 각각 진행하세요.
|
|
153
154
|
|
|
154
155
|
```bash
|
|
155
|
-
ai-battery uninstall
|
|
156
|
+
ai-battery reset settings && npm uninstall -g ai-battery
|
|
156
157
|
hash -r # Bash: 기존 터미널의 삭제된 wrapper 경로 캐시 해제 (zsh: rehash)
|
|
157
158
|
```
|
|
158
159
|
|
|
159
|
-
|
|
160
|
+
CLI는 npm 제거를 자동 실행하지 않습니다. `teardown`과 `uninstall`은 호환용 별칭으로 남아 있으며, 동일하게 설정과 생성 파일만 정리합니다. `off`는 표시만 숨깁니다. 이미 npm 패키지를 먼저 지웠다면 다시 설치하고 `reset settings`로 통합부터 복원하세요.
|
|
161
|
+
|
|
162
|
+
자식 프로세스인 CLI는 부모 셸의 명령 캐시를 지울 수 없습니다. 새 터미널을 열어도 캐시는 초기화됩니다. 이미 wrapper로 시작한 Codex 세션의 하단 행은 해당 세션을 종료해야 사라집니다.
|
|
160
163
|
|
|
161
164
|
## Setup
|
|
162
165
|
|
|
163
|
-
`setup`은 Claude Code의 statusLine hook
|
|
166
|
+
`setup`은 Claude Code의 statusLine hook과 Codex 자동 표시를 한 번에 설정합니다. 이후에는 `claude`, `codex`를 평소처럼 실행하면 됩니다. Codex는 별도 경로의 관리형 wrapper를 사용하며 원본 실행 파일은 교체하지 않습니다. 기존 Codex 설정과 세션 기록도 유지합니다.
|
|
164
167
|
|
|
165
168
|
```bash
|
|
166
169
|
ai-battery setup
|
|
167
170
|
```
|
|
168
171
|
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
```bash
|
|
172
|
-
ai-battery setup claude
|
|
173
|
-
ai-battery setup codex
|
|
174
|
-
```
|
|
172
|
+
한 도구만 설정하려면 `ai-battery setup codex` 또는 `ai-battery setup claude`를 사용합니다. 기존 터미널에는 setup 출력의 `source ...` 안내를 적용하고 `hash -r`을 실행하거나, 새 터미널을 여세요. Windows에서는 새 cmd/PowerShell을 엽니다.
|
|
175
173
|
|
|
176
|
-
|
|
174
|
+
AI Battery 사용량 표시에는 Codex `[tui].status_line` 변경이 필요하지 않습니다. Codex 자체의 모델·디렉터리·브랜치 행도 변경하고 싶을 때만 `--configure-codex-statusline`을 추가합니다. 기존 값은 복원용으로 먼저 기록합니다.
|
|
177
175
|
|
|
178
|
-
|
|
176
|
+
Codex 자동 연동을 사용하지 않으려면 `ai-battery setup codex --no-wrap-codex`로 해제합니다. 별도 표시에는 `ai-battery --watch 2`나 `ai-battery hud`를, 세션 하나에만 표시하려면 `ai-battery-run -- codex`(POSIX) 또는 `ai-battery-run-win -- codex`(Windows)를 사용합니다.
|
|
179
177
|
|
|
180
|
-
|
|
178
|
+
Windows와 WSL은 각각 설치한 환경에서 setup을 실행합니다. 아래 Windows runner 설명은 기본 Codex 자동 연동에도 적용됩니다.
|
|
181
179
|
|
|
182
180
|
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 설치는 변경하지 않습니다.
|
|
183
181
|
|
|
@@ -195,7 +193,7 @@ tmux에서는 pane마다 하단 행을 예약하면 같은 전역 배터리가 p
|
|
|
195
193
|
ai-battery setup tmux
|
|
196
194
|
```
|
|
197
195
|
|
|
198
|
-
`~/.tmux.conf`에 관리 블록을 추가해 status-right에 배터리를 표시하고(10초 간격 갱신), 이 tmux 안에서 실행되는 `codex`는 pane별 배터리 행을 생략하고 pane 전체를 사용합니다. Claude statusLine도 같은 환경에서는 배터리 행을 접고 header(모델·디렉터리·브랜치) 1행만 표시합니다 — 배터리는 tmux bar에 이미 있기 때문입니다. 적용하려면 `tmux source-file ~/.tmux.conf` 후 새 pane을 여세요. 이 블록은 기존 `status-right` 설정을 덮어쓰므로 `setup all`에 포함되지 않는 opt-in입니다. 해제는 `ai-battery
|
|
196
|
+
`~/.tmux.conf`에 관리 블록을 추가해 status-right에 배터리를 표시하고(10초 간격 갱신), 이 tmux 안에서 실행되는 `codex`는 pane별 배터리 행을 생략하고 pane 전체를 사용합니다. Claude statusLine도 같은 환경에서는 배터리 행을 접고 header(모델·디렉터리·브랜치) 1행만 표시합니다 — 배터리는 tmux bar에 이미 있기 때문입니다. 적용하려면 `tmux source-file ~/.tmux.conf` 후 새 pane을 여세요. 이 블록은 기존 `status-right` 설정을 덮어쓰므로 `setup all`에 포함되지 않는 opt-in입니다. 해제는 `ai-battery reset settings tmux`, tmux 안에서도 pane별 행을 유지하려면 `AI_BATTERY_TMUX=row`를 설정합니다.
|
|
199
197
|
|
|
200
198
|
Codex 하단 행이 보이지 않으면 진단을 실행합니다.
|
|
201
199
|
|
|
@@ -218,7 +216,7 @@ ai-battery on all
|
|
|
218
216
|
|
|
219
217
|
## Codex Terminal Row
|
|
220
218
|
|
|
221
|
-
|
|
219
|
+
`ai-battery setup` 후에는 평소처럼 `codex`를 실행하면 하단에 AI Battery 사용량 행이 표시됩니다. 기존 셸은 setup의 안내에 따라 갱신하거나 새 터미널을 여세요.
|
|
222
220
|
|
|
223
221
|
세션 하나에 하단 행을 추가하려면 명시적으로 실행합니다.
|
|
224
222
|
|
|
@@ -271,7 +269,7 @@ ai-battery hud -Mode statusline -Position bottomcenter
|
|
|
271
269
|
제거:
|
|
272
270
|
|
|
273
271
|
```bash
|
|
274
|
-
ai-battery
|
|
272
|
+
ai-battery reset settings claude
|
|
275
273
|
```
|
|
276
274
|
|
|
277
275
|
Claude가 한 번 이상 statusLine payload를 전달해야 Claude의 사용량 캐시가 생성됩니다. 그 전에는 Claude 로컬 로그 기반 fallback이 표시됩니다.
|
|
@@ -291,21 +289,21 @@ Codex [battery:88] │ 5h 00:47 │ 7d 93%
|
|
|
291
289
|
Claude [battery:76] │ 5h 00:47 │ 7d 59%
|
|
292
290
|
```
|
|
293
291
|
|
|
294
|
-
| Command
|
|
295
|
-
|
|
|
296
|
-
| `ai-battery hud` / `ai-battery hud start`
|
|
297
|
-
| `ai-battery hud stop`
|
|
298
|
-
| `ai-battery hud status`
|
|
299
|
-
| `ai-battery hud autostart on`
|
|
300
|
-
| `ai-battery hud autostart off`
|
|
301
|
-
| `ai-battery hud autostart status`
|
|
302
|
-
| `ai-battery hud -Foreground`
|
|
303
|
-
| `ai-battery hud -Once`
|
|
304
|
-
| `ai-battery hud -Interval 2`
|
|
305
|
-
| `ai-battery hud -Mode tray`
|
|
306
|
-
| `ai-battery hud light` / `ai-battery hud dark`
|
|
307
|
-
| `ai-battery hud black` / `ai-battery hud white`
|
|
308
|
-
| `ai-battery hud --backdrop` / `ai-battery hud --no-backdrop` | Windows floating HUD 글자 뒤 어두운 backing을 켜거나 끕니다.
|
|
292
|
+
| Command | Role |
|
|
293
|
+
| ------------------------------------------------------------ | ----------------------------------------------------------------------------------------------- |
|
|
294
|
+
| `ai-battery hud` / `ai-battery hud start` | Windows floating HUD 또는 macOS menu bar item을 시작합니다. |
|
|
295
|
+
| `ai-battery hud stop` | 실행 중인 HUD/menu bar item을 종료합니다. (`--stop`도 동일) |
|
|
296
|
+
| `ai-battery hud status` | HUD/menu bar 실행 여부와 autostart 등록 상태를 보여줍니다. |
|
|
297
|
+
| `ai-battery hud autostart on` | Windows 로그인 또는 macOS 로그인 시 자동 실행을 등록합니다. |
|
|
298
|
+
| `ai-battery hud autostart off` | 자동 실행 등록을 해제합니다. |
|
|
299
|
+
| `ai-battery hud autostart status` | 자동 실행 등록 상태만 보여줍니다. |
|
|
300
|
+
| `ai-battery hud -Foreground` | 디버깅용으로 터미널에 붙여 실행합니다. |
|
|
301
|
+
| `ai-battery hud -Once` | 콘솔에서 한 번만 출력합니다. |
|
|
302
|
+
| `ai-battery hud -Interval 2` | 갱신 주기를 바꿉니다. |
|
|
303
|
+
| `ai-battery hud -Mode tray` | Windows tray icon 모드로 실행합니다. macOS에서는 menu bar item이 기본입니다. |
|
|
304
|
+
| `ai-battery hud light` / `ai-battery hud dark` | Windows floating HUD를 밝은 작업표시줄용 검은 글자 또는 어두운 작업표시줄용 흰 글자로 바꿉니다. |
|
|
305
|
+
| `ai-battery hud black` / `ai-battery hud white` | 글자색을 직접 검은색 또는 흰색으로 바꿉니다. |
|
|
306
|
+
| `ai-battery hud --backdrop` / `ai-battery hud --no-backdrop` | Windows floating HUD 글자 뒤 어두운 backing을 켜거나 끕니다. |
|
|
309
307
|
|
|
310
308
|
Windows floating HUD는 기본적으로 투명 배경에 밝은 글자로 표시합니다. 밝은 작업표시줄에서는 `ai-battery hud light`, 어두운 작업표시줄에서는 `ai-battery hud dark`를 쓰면 됩니다. 글자색으로 직접 고르려면 `ai-battery hud black` 또는 `ai-battery hud white`를 쓰세요. 로그인 자동 실행에도 같은 모드를 저장하려면 `ai-battery hud autostart on light`처럼 붙이면 됩니다.
|
|
311
309
|
|
|
@@ -339,13 +337,13 @@ Codex는 최근 세션 로그에서 `rate_limits` 이벤트를 찾습니다. Cla
|
|
|
339
337
|
|
|
340
338
|
## Tech Stack
|
|
341
339
|
|
|
342
|
-
| Layer
|
|
343
|
-
|
|
|
344
|
-
| CLI
|
|
345
|
-
| PTY row
|
|
346
|
-
| HUD launcher | Node.js / Bash compatibility wrapper
|
|
347
|
-
| HUD UI
|
|
348
|
-
| Data
|
|
340
|
+
| Layer | Technology | Role |
|
|
341
|
+
| ------------ | ------------------------------------- | -------------------------------------------------------- |
|
|
342
|
+
| CLI | Node.js | 로그 파싱, Claude cache, ANSI/statusLine 출력 |
|
|
343
|
+
| PTY row | Python 3 | Codex 실행용 reserved terminal row |
|
|
344
|
+
| HUD launcher | Node.js / Bash compatibility wrapper | Windows native/WSL PowerShell HUD와 macOS menu bar 실행 |
|
|
345
|
+
| HUD UI | PowerShell WinForms / AppleScriptObjC | Windows floating overlay, tray icon, macOS menu bar item |
|
|
346
|
+
| Data | JSONL logs, statusLine JSON | Codex/Claude 사용량 소스 |
|
|
349
347
|
|
|
350
348
|
## Source Environment
|
|
351
349
|
|
package/bin/ai-battery-run
CHANGED
|
@@ -376,7 +376,7 @@ def main():
|
|
|
376
376
|
|
|
377
377
|
set_winsize(master_fd, child_rows, cols)
|
|
378
378
|
old_term = termios.tcgetattr(sys.stdin.fileno())
|
|
379
|
-
child_exit =
|
|
379
|
+
child_exit = None
|
|
380
380
|
|
|
381
381
|
def on_resize(_signum, _frame):
|
|
382
382
|
status.resize()
|
|
@@ -451,6 +451,14 @@ def main():
|
|
|
451
451
|
termios.tcsetattr(sys.stdin.fileno(), termios.TCSADRAIN, old_term)
|
|
452
452
|
status.clear()
|
|
453
453
|
|
|
454
|
+
# PTY EOF/EIO can arrive before waitpid(WNOHANG) observes the exit.
|
|
455
|
+
# Reap the child in that case so the wrapper preserves its actual status.
|
|
456
|
+
if child_exit is None:
|
|
457
|
+
_, wait_status = os.waitpid(pid, 0)
|
|
458
|
+
if os.WIFEXITED(wait_status):
|
|
459
|
+
child_exit = os.WEXITSTATUS(wait_status)
|
|
460
|
+
elif os.WIFSIGNALED(wait_status):
|
|
461
|
+
child_exit = 128 + os.WTERMSIG(wait_status)
|
|
454
462
|
raise SystemExit(child_exit)
|
|
455
463
|
|
|
456
464
|
|
package/docs/RELEASING.md
CHANGED
|
@@ -1,66 +1,46 @@
|
|
|
1
1
|
# npm release
|
|
2
2
|
|
|
3
|
-
The current release candidate is **0.1.
|
|
3
|
+
The current release candidate is **0.1.24**, based on the 0.1.23 main branch. Preparing this tarball does not publish it to npm.
|
|
4
4
|
|
|
5
|
-
## Changes in 0.1.
|
|
5
|
+
## Changes in 0.1.24
|
|
6
6
|
|
|
7
|
-
-
|
|
8
|
-
-
|
|
9
|
-
-
|
|
10
|
-
-
|
|
11
|
-
-
|
|
7
|
+
- `ai-battery setup` once again configures both the Claude statusLine and automatic Codex usage display. `setup codex` also enables the Codex wrapper without extra flags.
|
|
8
|
+
- Codex runs through a separate managed PATH wrapper. The original executable, existing Codex configuration, session history and npm packages are preserved. Repeated setup remains restorable with `reset settings`.
|
|
9
|
+
- `--no-wrap-codex` explicitly disables the automatic integration. `--wrap-codex` remains compatible. `--configure-codex-statusline` only controls Codex's optional built-in model/directory/branch row and is not required for usage display.
|
|
10
|
+
- The POSIX runner preserves the original command's exit code when PTY EOF arrives before the child exit is observed. Usage polling failure still allows Codex to run.
|
|
11
|
+
- Settings restoration remains separate from npm removal. `reset settings` / `reset config`, with `uninstall` / `teardown` compatibility aliases, do not uninstall packages.
|
|
12
12
|
|
|
13
13
|
## Validation
|
|
14
14
|
|
|
15
|
-
|
|
15
|
+
Results are saved under `.cache/releases/0.1.24/`. Tests cover plain setup and targeted setup, original executable/config/session preservation, repeated setup and exact restoration, terminal meter rendering, query failures, exit status propagation, and explicit standalone mode. Native Windows checks use isolated profile/data directories and skip writes to the real user PATH. Desktop cleanup tests use a temporary registry key; macOS ownership tests use a filesystem fixture.
|
|
16
16
|
|
|
17
|
-
|
|
18
|
-
| --- | --- |
|
|
19
|
-
| WSL `npm run check` | 155 passed, 16 platform skips, 0 failures |
|
|
20
|
-
| Windows native Node 22.23.2 full suite | 132 passed, 39 platform skips, 0 failures |
|
|
17
|
+
Native macOS and Windows ARM64 are not verified here.
|
|
21
18
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
The current WSL installation was removed with the new cleanup helpers after successful teardown. Original shell, Codex and Claude settings and the original Codex launcher were byte-identical afterward. Codex and Claude still ran successfully. Previous manual test backups were preserved under `.cache/uninstall-audit/preserved-local-test-backups/`.
|
|
25
|
-
|
|
26
|
-
Native Windows validation uses x64 Node 22.23.2. macOS LaunchAgent ownership and file handling are tested through an isolated fixture; native macOS and Windows ARM64 are not verified here.
|
|
27
|
-
|
|
28
|
-
## Prepare
|
|
19
|
+
## Prepare and publish
|
|
29
20
|
|
|
30
21
|
```text
|
|
31
22
|
npm run check
|
|
32
|
-
npm pack --
|
|
33
|
-
npm
|
|
34
|
-
```
|
|
35
|
-
|
|
36
|
-
Inspect the package file list. Include the core cleanup/recovery modules, platform modules, bin entrypoints and required PowerShell files. Exclude screenshots, logs, credentials, local runtime binaries, tests and `.cache`. Verify the exact tarball using an isolated npm prefix and provider homes. Release 0.1.21 fullscreen/compositor reports remain under `.cache/releases/0.1.21/`; this release changes setup/removal rather than terminal composition.
|
|
37
|
-
|
|
38
|
-
## Publish manually
|
|
39
|
-
|
|
40
|
-
```text
|
|
41
|
-
npm login
|
|
42
|
-
npm whoami
|
|
43
|
-
npm publish .cache/releases/0.1.22/ai-battery-0.1.22.tgz --access public --tag latest
|
|
44
|
-
npm view ai-battery version dist-tags --json
|
|
23
|
+
npm pack --pack-destination .cache/releases/0.1.24
|
|
24
|
+
npm publish .cache/releases/0.1.24/ai-battery-0.1.24.tgz --access public --tag latest
|
|
45
25
|
```
|
|
46
26
|
|
|
47
|
-
|
|
27
|
+
Verify the exact tarball in isolated Windows and POSIX prefixes before publishing. Check that packed files match the tested commit and exclude tests, logs, screenshots, caches and credentials. Complete npm authentication/2FA when requested. If this version is already published, increment it and repeat preparation.
|
|
48
28
|
|
|
49
|
-
##
|
|
29
|
+
## Setup and removal
|
|
50
30
|
|
|
51
|
-
Run
|
|
31
|
+
Run in each installation (Windows and WSL are separate):
|
|
52
32
|
|
|
53
33
|
```text
|
|
54
|
-
npm install -g ai-battery@0.1.
|
|
55
|
-
ai-battery setup
|
|
34
|
+
npm install -g ai-battery@0.1.24
|
|
35
|
+
ai-battery setup
|
|
56
36
|
```
|
|
57
37
|
|
|
58
|
-
|
|
38
|
+
Open a new terminal, or apply the shell reload instructions from setup and clear Bash's command cache with `hash -r` (zsh: `rehash`). Windows users open a new cmd/PowerShell. A child CLI cannot change the PATH or command cache of its parent shell. The existing 0.1.23 installation can enable Codex integration with `ai-battery setup codex --wrap-codex` before this release is published.
|
|
59
39
|
|
|
60
|
-
|
|
40
|
+
Reset and remove a global package separately:
|
|
61
41
|
|
|
62
42
|
```text
|
|
63
|
-
ai-battery uninstall
|
|
43
|
+
ai-battery reset settings && npm uninstall -g ai-battery
|
|
64
44
|
```
|
|
65
45
|
|
|
66
|
-
|
|
46
|
+
For a local package use `npm uninstall ai-battery`. Edited or unrecognized files and unresolved recovery records are preserved and reported. A running wrapped session retains its loaded code until it exits.
|
package/lib/cli.js
CHANGED
|
@@ -15,7 +15,7 @@ import { quoteWindowsCommandLineArg, rowptyExePath } from "./platforms/windows/c
|
|
|
15
15
|
import { isWsl } from "./platforms/runtime.js";
|
|
16
16
|
import { createProcessScanner } from "./platforms/process-scanner.js";
|
|
17
17
|
import { createWindowsPathIntegration } from "./platforms/windows/path-integration.js";
|
|
18
|
-
import { cleanupBatteryArtifacts, isBatteryConfig
|
|
18
|
+
import { cleanupBatteryArtifacts, isBatteryConfig } from "./core/uninstall.js";
|
|
19
19
|
import { createIntegrationFiles } from "./core/integration-files.js";
|
|
20
20
|
import {
|
|
21
21
|
cacheAgeSeconds,
|
|
@@ -60,6 +60,7 @@ const DEFAULT_STATUSLINE_COLUMN_GUARD = 4;
|
|
|
60
60
|
const COMMANDS = new Set([
|
|
61
61
|
"show",
|
|
62
62
|
"setup",
|
|
63
|
+
"reset",
|
|
63
64
|
"teardown",
|
|
64
65
|
"uninstall",
|
|
65
66
|
"doctor",
|
|
@@ -110,26 +111,32 @@ function parseArgs(argv) {
|
|
|
110
111
|
hudState: false,
|
|
111
112
|
silent: false,
|
|
112
113
|
force: false,
|
|
113
|
-
wrapCodex:
|
|
114
|
+
wrapCodex: true,
|
|
114
115
|
configureCodexStatusLine: false,
|
|
115
116
|
attachHud: false,
|
|
116
117
|
header: true,
|
|
117
118
|
usageRow: "auto",
|
|
118
119
|
help: false,
|
|
119
120
|
version: false,
|
|
121
|
+
resetScope: null,
|
|
120
122
|
targets: [],
|
|
121
123
|
rest: []
|
|
122
124
|
};
|
|
123
125
|
|
|
126
|
+
let commandSeen = false;
|
|
124
127
|
for (let i = 0; i < argv.length; i += 1) {
|
|
125
128
|
const arg = argv[i];
|
|
126
|
-
if (!arg.startsWith("-") && COMMANDS.has(arg)) {
|
|
129
|
+
if (!commandSeen && !arg.startsWith("-") && COMMANDS.has(arg)) {
|
|
127
130
|
args.command = arg;
|
|
131
|
+
commandSeen = true;
|
|
128
132
|
if (arg === "hud") {
|
|
129
133
|
args.rest = argv.slice(i + 1);
|
|
130
134
|
break;
|
|
131
135
|
}
|
|
132
|
-
} else if (!arg.startsWith("-") &&
|
|
136
|
+
} else if (!arg.startsWith("-") && args.command === "reset" && !args.resetScope) {
|
|
137
|
+
if (!["settings", "config"].includes(arg)) throw new Error("Usage: ai-battery reset settings|config [codex|claude|hud|tmux|all]");
|
|
138
|
+
args.resetScope = "settings";
|
|
139
|
+
} else if (!arg.startsWith("-") && ["setup", "reset", "teardown", "uninstall", "on", "off"].includes(args.command)) {
|
|
133
140
|
args.targets.push(arg);
|
|
134
141
|
} else if (arg === "--provider" || arg === "-p") {
|
|
135
142
|
args.provider = argv[++i] || "all";
|
|
@@ -154,6 +161,8 @@ function parseArgs(argv) {
|
|
|
154
161
|
args.force = true;
|
|
155
162
|
} else if (arg === "--wrap-codex") {
|
|
156
163
|
args.wrapCodex = true;
|
|
164
|
+
} else if (arg === "--no-wrap-codex") {
|
|
165
|
+
args.wrapCodex = false;
|
|
157
166
|
} else if (arg === "--configure-codex-statusline") {
|
|
158
167
|
args.configureCodexStatusLine = true;
|
|
159
168
|
} else if (arg === "--attach-hud") {
|
|
@@ -198,6 +207,9 @@ function parseArgs(argv) {
|
|
|
198
207
|
}
|
|
199
208
|
}
|
|
200
209
|
|
|
210
|
+
if (args.command === "reset" && !args.resetScope && !args.help && !args.version) {
|
|
211
|
+
throw new Error("Usage: ai-battery reset settings|config [codex|claude|hud|tmux|all]");
|
|
212
|
+
}
|
|
201
213
|
if (!["all", "codex", "claude"].includes(args.provider)) {
|
|
202
214
|
throw new Error("--provider must be one of: all, codex, claude");
|
|
203
215
|
}
|
|
@@ -213,9 +225,8 @@ function printHelp() {
|
|
|
213
225
|
|
|
214
226
|
Usage:
|
|
215
227
|
ai-battery [options]
|
|
216
|
-
ai-battery setup [codex|claude] [--force] [--wrap-codex]
|
|
217
|
-
ai-battery
|
|
218
|
-
ai-battery teardown [codex|claude|hud|tmux|all]
|
|
228
|
+
ai-battery setup [codex|claude] [--force] [--no-wrap-codex]
|
|
229
|
+
ai-battery reset settings [codex|claude|hud|tmux|all]
|
|
219
230
|
ai-battery doctor
|
|
220
231
|
ai-battery hud [start|stop|status] [hud options]
|
|
221
232
|
ai-battery hud autostart on|off|status
|
|
@@ -224,10 +235,12 @@ Usage:
|
|
|
224
235
|
|
|
225
236
|
Aliases:
|
|
226
237
|
claudex-battery
|
|
238
|
+
ai-battery reset config [codex|claude|hud|tmux|all]
|
|
227
239
|
|
|
228
|
-
Setup
|
|
229
|
-
|
|
230
|
-
|
|
240
|
+
Setup enables automatic Codex usage display through a managed PATH wrapper.
|
|
241
|
+
The original Codex executable and existing Codex configuration are preserved.
|
|
242
|
+
Reset settings restores AI Battery's integrations and cleans its generated files.
|
|
243
|
+
The npm package stays installed. Remove it separately: npm uninstall -g ai-battery
|
|
231
244
|
|
|
232
245
|
Options:
|
|
233
246
|
-p, --provider all|codex|claude Provider to show (default: all)
|
|
@@ -245,7 +258,8 @@ Options:
|
|
|
245
258
|
--menu-bar Print compact macOS menu bar text
|
|
246
259
|
--tmux Emit tmux status-line color markup
|
|
247
260
|
--force Replace an existing Claude statusLine
|
|
248
|
-
--wrap-codex
|
|
261
|
+
--wrap-codex Enable automatic Codex usage display (default)
|
|
262
|
+
--no-wrap-codex Use Codex without the AI Battery wrapper
|
|
249
263
|
--configure-codex-statusline Explicitly configure Codex's own status line
|
|
250
264
|
--no-color Disable ANSI colors
|
|
251
265
|
-v, --version Show ai-battery version
|
|
@@ -254,7 +268,8 @@ Options:
|
|
|
254
268
|
Compatibility:
|
|
255
269
|
ai-battery install-claude-statusline [--force]
|
|
256
270
|
ai-battery uninstall-claude-statusline
|
|
257
|
-
ai-battery teardown [codex|claude|hud|all]
|
|
271
|
+
ai-battery teardown [codex|claude|hud|tmux|all]
|
|
272
|
+
ai-battery uninstall [codex|claude|hud|tmux|all]
|
|
258
273
|
`);
|
|
259
274
|
}
|
|
260
275
|
|
|
@@ -1906,10 +1921,10 @@ function diagnoseCodex() {
|
|
|
1906
1921
|
notes.push("Codex wrapper is not installed. Run: ai-battery setup codex");
|
|
1907
1922
|
}
|
|
1908
1923
|
if (!statusLine.configured) {
|
|
1909
|
-
notes.push("Codex status_line is not configured.
|
|
1924
|
+
notes.push("Codex's optional built-in status_line is not configured. Use --configure-codex-statusline with setup codex only if desired; AI Battery usage display does not require it.");
|
|
1910
1925
|
}
|
|
1911
1926
|
if (activeIsWrapper && !wrapperInstalled) {
|
|
1912
|
-
notes.push("Plain \"codex\" still resolves to an AI Battery wrapper outside the configured shim. Run: ai-battery
|
|
1927
|
+
notes.push("Plain \"codex\" still resolves to an AI Battery wrapper outside the configured shim. Run: ai-battery reset settings codex");
|
|
1913
1928
|
}
|
|
1914
1929
|
if (activeWrapperBackup) {
|
|
1915
1930
|
notes.push(`A Codex backup is available for restore: ${activeWrapperBackup}`);
|
|
@@ -2267,7 +2282,7 @@ function runSetup(args) {
|
|
|
2267
2282
|
standalone: !failed,
|
|
2268
2283
|
skipped: failed,
|
|
2269
2284
|
legacyCleanup,
|
|
2270
|
-
reason: failed ? "Could not safely detach the legacy Codex integration; kept recovery metadata. Run ai-battery
|
|
2285
|
+
reason: failed ? "Could not safely detach the legacy Codex integration; kept recovery metadata. Run ai-battery reset settings codex for details."
|
|
2271
2286
|
: "Codex command and configuration are left under Codex's control. Use ai-battery hud or ai-battery-run -- codex for usage display."
|
|
2272
2287
|
};
|
|
2273
2288
|
// An explicit status-line request is applied after legacy restoration.
|
|
@@ -2379,30 +2394,24 @@ function runTeardown(args) {
|
|
|
2379
2394
|
runStep("hud", uninstallHud);
|
|
2380
2395
|
}
|
|
2381
2396
|
if (targets.includes("codex")) runStep("rowpty", uninstallRowPtyHost);
|
|
2382
|
-
const
|
|
2383
|
-
if (
|
|
2397
|
+
const fullReset = !args.targets.length || args.targets.includes("all");
|
|
2398
|
+
if (fullReset && !teardownResultFailed({ results })) {
|
|
2384
2399
|
const pending = Object.keys(readConfig({ strict: true }).integrationFiles || {});
|
|
2385
2400
|
if (pending.length) {
|
|
2386
|
-
results.recovery = { error: "Unrestored integration files remain; kept recovery metadata
|
|
2387
|
-
return { targets,
|
|
2388
|
-
}
|
|
2389
|
-
const plan = planPackageRemoval(path.resolve(scriptDir(), ".."));
|
|
2390
|
-
if (plan.error) {
|
|
2391
|
-
results.package = plan;
|
|
2392
|
-
} else {
|
|
2393
|
-
const roots = [stateDir(), dataDir(), path.join(os.tmpdir(), "ai-battery")];
|
|
2394
|
-
if (process.platform === "win32" && process.env.LOCALAPPDATA) roots.push(path.join(process.env.LOCALAPPDATA, "ai-battery"));
|
|
2395
|
-
results.artifacts = cleanupBatteryArtifacts({
|
|
2396
|
-
roots,
|
|
2397
|
-
home: userHome(),
|
|
2398
|
-
protectedRoots: [codexRuntimeHome(), homePath(".claude"), path.resolve(scriptDir(), "..")]
|
|
2399
|
-
});
|
|
2400
|
-
if (!results.artifacts.errors.length) results.package = removeInstalledPackage(plan, { home: userHome() });
|
|
2401
|
+
results.recovery = { error: "Unrestored integration files remain; kept recovery metadata", paths: pending };
|
|
2402
|
+
return { targets, fullReset, results };
|
|
2401
2403
|
}
|
|
2404
|
+
const roots = [stateDir(), dataDir(), path.join(os.tmpdir(), "ai-battery")];
|
|
2405
|
+
if (process.platform === "win32" && process.env.LOCALAPPDATA) roots.push(path.join(process.env.LOCALAPPDATA, "ai-battery"));
|
|
2406
|
+
results.artifacts = cleanupBatteryArtifacts({
|
|
2407
|
+
roots,
|
|
2408
|
+
home: userHome(),
|
|
2409
|
+
protectedRoots: [codexRuntimeHome(), homePath(".claude"), path.resolve(scriptDir(), "..")]
|
|
2410
|
+
});
|
|
2402
2411
|
}
|
|
2403
2412
|
return {
|
|
2404
2413
|
targets,
|
|
2405
|
-
|
|
2414
|
+
fullReset,
|
|
2406
2415
|
results
|
|
2407
2416
|
};
|
|
2408
2417
|
}
|
|
@@ -5030,7 +5039,7 @@ function printTeardownResult(result) {
|
|
|
5030
5039
|
}
|
|
5031
5040
|
const artifacts = result.results.artifacts;
|
|
5032
5041
|
for (const [name, item] of Object.entries(result.results)) {
|
|
5033
|
-
if (["codex", "claude", "hud", "artifacts"
|
|
5042
|
+
if (["codex", "claude", "hud", "artifacts"].includes(name)) continue;
|
|
5034
5043
|
if (item.error) console.log(`${name} cleanup error: ${item.error}`);
|
|
5035
5044
|
for (const error of item.errors || []) console.log(`${name} cleanup error: ${error.path}: ${error.error}`);
|
|
5036
5045
|
for (const file of item.paths || []) console.log(`Recovery pending: ${file}`);
|
|
@@ -5040,10 +5049,12 @@ function printTeardownResult(result) {
|
|
|
5040
5049
|
for (const file of artifacts.retained) console.log(`Preserved unrecognized or user-owned file: ${file}`);
|
|
5041
5050
|
for (const item of artifacts.errors) console.log(`Cleanup error: ${item.path}: ${item.error}`);
|
|
5042
5051
|
}
|
|
5043
|
-
|
|
5044
|
-
|
|
5045
|
-
else
|
|
5046
|
-
|
|
5052
|
+
if (teardownResultFailed(result)) {
|
|
5053
|
+
console.log("Settings reset incomplete; recovery metadata and npm package were preserved.");
|
|
5054
|
+
} else {
|
|
5055
|
+
console.log("AI Battery settings reset; npm package was left unchanged.");
|
|
5056
|
+
console.log("To remove the package: npm uninstall -g ai-battery");
|
|
5057
|
+
}
|
|
5047
5058
|
if (result.targets.includes("codex") && process.platform !== "win32") {
|
|
5048
5059
|
console.log("In this existing Bash terminal, run: hash -r (zsh: rehash). A child process cannot clear its parent shell's cached command paths.");
|
|
5049
5060
|
}
|
|
@@ -5078,7 +5089,7 @@ async function main() {
|
|
|
5078
5089
|
}
|
|
5079
5090
|
if (result.codex?.standalone) {
|
|
5080
5091
|
console.log(result.codex.reason);
|
|
5081
|
-
if (result.codex.legacyCleanup.changed) {
|
|
5092
|
+
if (process.platform !== "win32" && result.codex.legacyCleanup.changed) {
|
|
5082
5093
|
console.log("Removed legacy Codex integration. In this existing Bash terminal run: hash -r (zsh: rehash).");
|
|
5083
5094
|
}
|
|
5084
5095
|
} else if (result.codex?.ok) {
|
|
@@ -5122,10 +5133,10 @@ async function main() {
|
|
|
5122
5133
|
if (result.codex?.retainedConfig) {
|
|
5123
5134
|
console.log("Kept the Codex recovery record because the configured wrapper could not be safely removed.");
|
|
5124
5135
|
}
|
|
5125
|
-
if (process.platform === "win32" && result.codex && !result.codex.standalone) {
|
|
5136
|
+
if (process.platform === "win32" && result.codex?.ok && !result.codex.standalone) {
|
|
5126
5137
|
console.log("Windows terminal note: Codex uses fullscreen PTY composition by default, with a private VT-capable Node runtime when needed and a native HUD fallback. Open a new cmd/PowerShell after setup.");
|
|
5127
5138
|
}
|
|
5128
|
-
console.log("To
|
|
5139
|
+
console.log("To restore settings later, run: ai-battery reset settings");
|
|
5129
5140
|
const note = codexRestartNote();
|
|
5130
5141
|
if (result.codex && note) console.log(note);
|
|
5131
5142
|
}
|
|
@@ -5133,7 +5144,10 @@ async function main() {
|
|
|
5133
5144
|
return;
|
|
5134
5145
|
}
|
|
5135
5146
|
|
|
5136
|
-
if (
|
|
5147
|
+
if (["reset", "teardown", "uninstall"].includes(args.command)) {
|
|
5148
|
+
if (!args.silent && !args.json && args.command !== "reset") {
|
|
5149
|
+
console.log(`\"${args.command}\" is a compatibility alias for \"reset settings\"; npm package removal is separate.`);
|
|
5150
|
+
}
|
|
5137
5151
|
const result = runTeardown(args);
|
|
5138
5152
|
if (args.json) {
|
|
5139
5153
|
console.log(JSON.stringify(result, null, 2));
|
package/lib/core/uninstall.js
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import fs from "node:fs";
|
|
2
2
|
import os from "node:os";
|
|
3
3
|
import path from "node:path";
|
|
4
|
-
import { spawnSync } from "node:child_process";
|
|
5
4
|
|
|
6
|
-
const ALIASES = ["ai-battery", "ai-battery-hud", "ai-battery-run", "ai-battery-run-win", "claudex-battery", "claudex-battery-hud", "claudex-battery-run"];
|
|
7
5
|
const STATE_FILES = /^(?:(?:codex-status|windows-processes|wsl-windows-processes|claude-rate-limit-hit)-scan-cache\.json|claude-statusline\.json|codex-account-usage\.json|windows-state-dir|hud-position\.json|hud-snapshot-[\w-]+\.json|(?:tui|hud)-dock-(?:request|host)(?:-\d+)?\.json|macos-menu-(?:bar|detail)\.svg|codex-menu-bar-transparent\.png)(?:\.\d+(?:\.\d+)?(?:\.[a-z0-9]+)?\.tmp)?$/;
|
|
8
6
|
const HUD_FILES = new Set(["main.ps1", "controls.ps1", "dock.ps1", "native.ps1", "rendering.ps1", "snapshot.ps1", "windowing.ps1", "ai-battery-hud.ps1"]);
|
|
9
7
|
|
|
@@ -85,61 +83,3 @@ export function cleanupBatteryArtifacts({ roots, home = os.homedir(), protectedR
|
|
|
85
83
|
}
|
|
86
84
|
return result;
|
|
87
85
|
}
|
|
88
|
-
|
|
89
|
-
export function removeBatteryAliases({ packageRoot, packageJson, home = os.homedir() }) {
|
|
90
|
-
const removed = [];
|
|
91
|
-
for (const name of ALIASES) {
|
|
92
|
-
const target = packageJson.bin?.[name];
|
|
93
|
-
if (!target) continue;
|
|
94
|
-
const alias = path.join(home, ".local", "bin", name);
|
|
95
|
-
if (!lstat(alias)?.isSymbolicLink()) continue;
|
|
96
|
-
const resolved = path.resolve(path.dirname(alias), fs.readlinkSync(alias));
|
|
97
|
-
if (resolved !== path.resolve(packageRoot, target)) continue;
|
|
98
|
-
fs.unlinkSync(alias);
|
|
99
|
-
removed.push(alias);
|
|
100
|
-
}
|
|
101
|
-
return removed;
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
export function planPackageRemoval(packageRoot, { node = process.execPath } = {}) {
|
|
105
|
-
const root = path.resolve(packageRoot);
|
|
106
|
-
const packageJson = readJson(path.join(root, "package.json"));
|
|
107
|
-
if (packageJson?.name !== "ai-battery" || !packageJson.bin || typeof packageJson.bin !== "object"
|
|
108
|
-
|| Object.entries(packageJson.bin).some(([name, target]) => !ALIASES.includes(name)
|
|
109
|
-
|| typeof target !== "string" || path.isAbsolute(target) || !inside(path.resolve(root, target), root))) {
|
|
110
|
-
return { error: "Package identity or command ownership could not be verified" };
|
|
111
|
-
}
|
|
112
|
-
if (path.basename(path.dirname(root)) !== "node_modules" || /[\\/]_npx[\\/]/.test(root)) {
|
|
113
|
-
return { skipped: true, reason: "Development checkout or temporary npx installation; no npm project was changed" };
|
|
114
|
-
}
|
|
115
|
-
const modules = path.dirname(root);
|
|
116
|
-
const parent = path.dirname(modules);
|
|
117
|
-
const localProject = readJson(path.join(parent, "package.json"));
|
|
118
|
-
const declaredLocal = [localProject?.dependencies, localProject?.devDependencies, localProject?.optionalDependencies]
|
|
119
|
-
.some(deps => Object.hasOwn(deps || {}, "ai-battery"));
|
|
120
|
-
const global = !declaredLocal && !fs.existsSync(path.join(parent, "package.json"));
|
|
121
|
-
const prefix = global && process.platform !== "win32" && path.basename(parent) === "lib" ? path.dirname(parent) : parent;
|
|
122
|
-
const candidates = [
|
|
123
|
-
path.join(modules, "npm", "bin", "npm-cli.js"),
|
|
124
|
-
path.join(path.dirname(node), "node_modules", "npm", "bin", "npm-cli.js"),
|
|
125
|
-
path.resolve(path.dirname(node), "../lib/node_modules/npm/bin/npm-cli.js")
|
|
126
|
-
];
|
|
127
|
-
const npm = candidates.find(file => lstat(file)?.isFile());
|
|
128
|
-
if (!npm) return { error: "Could not locate npm for the installed package; package was left intact" };
|
|
129
|
-
if (!global) {
|
|
130
|
-
const project = readJson(path.join(prefix, "package.json"));
|
|
131
|
-
if (![project?.dependencies, project?.devDependencies, project?.optionalDependencies].some(deps => Object.hasOwn(deps || {}, "ai-battery"))) {
|
|
132
|
-
return { error: "The parent npm project does not declare ai-battery; refusing to change it" };
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
return { node, npm, prefix, packageRoot: root, packageJson, global, args: ["uninstall", ...(global ? ["--global"] : []), "--prefix", prefix, "ai-battery", "--ignore-scripts", "--no-audit", "--no-fund"] };
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
export function removeInstalledPackage(plan, { home = os.homedir(), run = spawnSync } = {}) {
|
|
139
|
-
if (plan.error || plan.skipped) return plan;
|
|
140
|
-
const result = run(plan.node, [plan.npm, ...plan.args], { encoding: "utf8", windowsHide: true, stdio: ["ignore", "pipe", "pipe"], timeout: 120000 });
|
|
141
|
-
if (result.status !== 0 || result.error || lstat(plan.packageRoot)) {
|
|
142
|
-
return { error: result.error?.message || result.stderr?.trim() || "npm did not remove the installed package", prefix: plan.prefix };
|
|
143
|
-
}
|
|
144
|
-
return { removed: true, prefix: plan.prefix, global: plan.global, aliases: removeBatteryAliases({ ...plan, home }) };
|
|
145
|
-
}
|