ai-battery 0.1.10 → 0.1.12
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 +2 -2
- package/bin/ai-battery-run +29 -12
- package/bin/ai-battery-run-win.js +37 -3
- package/bin/ai-battery.js +261 -53
- package/package.json +1 -1
- package/vendor/rowpty/RowPty.cs +107 -8
package/README.md
CHANGED
|
@@ -169,7 +169,7 @@ ai-battery setup codex
|
|
|
169
169
|
|
|
170
170
|
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 ...` 명령을 실행하세요.
|
|
171
171
|
|
|
172
|
-
Windows native `cmd`/PowerShell에서는 `codex.cmd` wrapper가 Windows runner를 실행합니다. runner는 `rowpty.exe`(별도 rowpty 프로젝트의 전용 ConPTY host)가 있으면 WSL과 같은 방식으로 하단 row를 예약합니다: 자식 프로그램은 한 줄 짧은 화면을 쓰고, 상태줄은 출력이 잠잠해진 시점에만 그려져 깜빡임 없이 하단에 고정됩니다. `rowpty.exe`는 바이너리로 배포되지 않습니다 — `ai-battery setup`이 패키지에 동봉된 소스(`vendor/rowpty/RowPty.cs`)를 Windows 내장 .NET Framework `csc.exe`로 사용자 머신에서 직접 컴파일해 `%LOCALAPPDATA%\ai-battery\bin`에 설치하고, 그 옆에 Microsoft 서명된
|
|
172
|
+
Windows native `cmd`/PowerShell에서는 `codex.cmd` wrapper가 Windows runner를 실행합니다. runner는 `rowpty.exe`(별도 rowpty 프로젝트의 전용 ConPTY host)가 있으면 WSL과 같은 방식으로 하단 row를 예약합니다: 자식 프로그램은 한 줄 짧은 화면을 쓰고, 상태줄은 출력이 잠잠해진 시점에만 그려져 깜빡임 없이 하단에 고정됩니다. `rowpty.exe`는 바이너리로 배포되지 않습니다 — `ai-battery setup`이 패키지에 동봉된 소스(`vendor/rowpty/RowPty.cs`)를 Windows 내장 .NET Framework `csc.exe`로 사용자 머신에서 직접 컴파일해 `%LOCALAPPDATA%\ai-battery\bin`에 설치하고, 그 옆에 Microsoft 서명된 ConPTY(`conpty.dll`/`OpenConsole.exe`, node-pty 패키지에서 복사)를 배치합니다. Codex 시작 지연을 피하기 위해 실행 기본값은 Windows 내장 OS ConPTY이며, 번들 provider가 필요하면 `AI_BATTERY_ROWPTY_CONPTY=bundled`로 되돌릴 수 있습니다. 서명 없는 다운로드 바이너리가 없으므로 SmartScreen/Defender류 평판 경고를 원천적으로 피하고, 소스가 텍스트로 열려 있어 감사할 수 있습니다. 직접 빌드한 exe를 쓰려면 `AI_BATTERY_ROWPTY` 환경변수로 지정합니다. rowpty가 없으면 같은 콘솔에 덧그리는 overlay layout으로 동작하며(`AI_BATTERY_WIN_LAYOUT=overlay`로 강제 가능), legacy `node-pty` reserve는 `AI_BATTERY_WIN_LAYOUT=reserve`이면서 rowpty가 없을 때만 사용됩니다. Claude statusLine은 일반 `cmd`/PowerShell 프롬프트가 아니라 Claude Code 안에서만 표시됩니다.
|
|
173
173
|
|
|
174
174
|
tmux에서는 pane마다 하단 행을 예약하면 같은 전역 배터리가 pane 수만큼 중복 표시됩니다. 대신 tmux의 status bar에 세션당 한 번만 표시할 수 있습니다.
|
|
175
175
|
|
|
@@ -177,7 +177,7 @@ tmux에서는 pane마다 하단 행을 예약하면 같은 전역 배터리가 p
|
|
|
177
177
|
ai-battery setup tmux
|
|
178
178
|
```
|
|
179
179
|
|
|
180
|
-
`~/.tmux.conf`에 관리 블록을 추가해 status-right에 배터리를 표시하고(10초 간격 갱신), 이 tmux 안에서 실행되는 `codex`는 pane별 배터리 행을 생략하고 pane 전체를 사용합니다. 적용하려면 `tmux source-file ~/.tmux.conf` 후 새 pane을 여세요. 이 블록은 기존 `status-right` 설정을 덮어쓰므로 `setup all`에 포함되지 않는 opt-in입니다. 해제는 `ai-battery uninstall tmux`, tmux 안에서도 pane별 행을 유지하려면 `AI_BATTERY_TMUX=row`를 설정합니다. Claude statusLine은 Claude Code 내부 UI라 tmux 여부와 무관하게 그대로 표시됩니다.
|
|
180
|
+
`~/.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 uninstall tmux`, tmux 안에서도 pane별 행을 유지하려면 `AI_BATTERY_TMUX=row`를 설정합니다. Claude statusLine은 Claude Code 내부 UI라 tmux 여부와 무관하게 그대로 표시됩니다.
|
|
181
181
|
|
|
182
182
|
Codex 하단 행이 보이지 않으면 진단을 실행합니다.
|
|
183
183
|
|
package/bin/ai-battery-run
CHANGED
|
@@ -223,17 +223,7 @@ class StatusLine:
|
|
|
223
223
|
def seconds_until_refresh(self):
|
|
224
224
|
return max(0.0, self.next_fetch - time.monotonic())
|
|
225
225
|
|
|
226
|
-
def
|
|
227
|
-
now = time.monotonic()
|
|
228
|
-
if not force and now - self.last_draw < 0.15:
|
|
229
|
-
return
|
|
230
|
-
self.refresh(force)
|
|
231
|
-
paint_width = max(1, self.cols - 1)
|
|
232
|
-
line = fit_ansi(self.text, paint_width, pad=True)
|
|
233
|
-
if not force and not dirty and line == self.last_line:
|
|
234
|
-
return
|
|
235
|
-
self.last_draw = now
|
|
236
|
-
self.last_line = line
|
|
226
|
+
def _write_row(self, line):
|
|
237
227
|
payload = (
|
|
238
228
|
"\x1b7"
|
|
239
229
|
"\x1b[0m"
|
|
@@ -246,6 +236,29 @@ class StatusLine:
|
|
|
246
236
|
)
|
|
247
237
|
os.write(sys.stdout.fileno(), payload.encode("utf-8", errors="replace"))
|
|
248
238
|
|
|
239
|
+
def draw_cached(self):
|
|
240
|
+
"""Repaint the cached text at the current terminal size without fetching new data.
|
|
241
|
+
Used on resize so the bar is repositioned instantly, avoiding the ~100ms
|
|
242
|
+
subprocess call that would otherwise delay the repaint."""
|
|
243
|
+
paint_width = max(1, self.cols - 1)
|
|
244
|
+
line = fit_ansi(self.text, paint_width, pad=True)
|
|
245
|
+
self.last_draw = time.monotonic()
|
|
246
|
+
self.last_line = line
|
|
247
|
+
self._write_row(line)
|
|
248
|
+
|
|
249
|
+
def draw(self, force=False, dirty=False):
|
|
250
|
+
now = time.monotonic()
|
|
251
|
+
if not force and now - self.last_draw < 0.15:
|
|
252
|
+
return
|
|
253
|
+
self.refresh(force)
|
|
254
|
+
paint_width = max(1, self.cols - 1)
|
|
255
|
+
line = fit_ansi(self.text, paint_width, pad=True)
|
|
256
|
+
if not force and not dirty and line == self.last_line:
|
|
257
|
+
return
|
|
258
|
+
self.last_draw = now
|
|
259
|
+
self.last_line = line
|
|
260
|
+
self._write_row(line)
|
|
261
|
+
|
|
249
262
|
def clear(self):
|
|
250
263
|
payload = "\x1b7" "\x1b[0m" f"\x1b[{self.rows};1H" "\r\x1b[1G" "\x1b[2K" "\x1b8"
|
|
251
264
|
os.write(sys.stdout.fileno(), payload.encode("ascii"))
|
|
@@ -306,7 +319,11 @@ def main():
|
|
|
306
319
|
os.kill(pid, signal.SIGWINCH)
|
|
307
320
|
except ProcessLookupError:
|
|
308
321
|
pass
|
|
309
|
-
|
|
322
|
+
# Repaint immediately at the new size using cached text (no subprocess call).
|
|
323
|
+
# A subprocess call here blocks signal delivery for ~100ms, causing color
|
|
324
|
+
# flicker and stutter during resize. Schedule a fresh fetch instead.
|
|
325
|
+
status.draw_cached()
|
|
326
|
+
status.next_fetch = 0.0
|
|
310
327
|
|
|
311
328
|
signal.signal(signal.SIGWINCH, on_resize)
|
|
312
329
|
|
|
@@ -14,6 +14,7 @@ const DEBUG_LOG = process.env.AI_BATTERY_DEBUG_LOG || process.env.CLAUDEX_BATTER
|
|
|
14
14
|
const DEFAULT_COLUMN_GUARD = 4;
|
|
15
15
|
const DEFAULT_LEFT_PADDING = 2;
|
|
16
16
|
const DEFAULT_CODEX_OVERLAY_BOTTOM_OFFSET = 1;
|
|
17
|
+
const DEFAULT_VSCODE_CODEX_OVERLAY_BOTTOM_OFFSET = 2;
|
|
17
18
|
|
|
18
19
|
function usage() {
|
|
19
20
|
console.log(`Usage: ai-battery-run-win [--interval SECONDS] [--bar-width N] [--provider auto|all|codex|claude] [--layout auto|reserve|overlay] [--left-padding N] -- COMMAND [ARGS...]
|
|
@@ -117,7 +118,10 @@ function columnGuard() {
|
|
|
117
118
|
function overlayBottomOffset(activeProvider) {
|
|
118
119
|
const raw = Number(process.env.AI_BATTERY_OVERLAY_BOTTOM_OFFSET || process.env.CLAUDEX_BATTERY_OVERLAY_BOTTOM_OFFSET);
|
|
119
120
|
if (Number.isFinite(raw)) return Math.max(0, Math.min(5, Math.floor(raw)));
|
|
120
|
-
|
|
121
|
+
if (activeProvider !== "codex") return 0;
|
|
122
|
+
return isVsCodeTerminal()
|
|
123
|
+
? DEFAULT_VSCODE_CODEX_OVERLAY_BOTTOM_OFFSET
|
|
124
|
+
: DEFAULT_CODEX_OVERLAY_BOTTOM_OFFSET;
|
|
121
125
|
}
|
|
122
126
|
|
|
123
127
|
function statusRow(rows, bottomOffset = 0) {
|
|
@@ -126,6 +130,11 @@ function statusRow(rows, bottomOffset = 0) {
|
|
|
126
130
|
return Math.max(1, safeRows - safeOffset);
|
|
127
131
|
}
|
|
128
132
|
|
|
133
|
+
function isVsCodeTerminal() {
|
|
134
|
+
return String(process.env.TERM_PROGRAM || "").toLowerCase() === "vscode"
|
|
135
|
+
|| Boolean(process.env.VSCODE_INJECTION);
|
|
136
|
+
}
|
|
137
|
+
|
|
129
138
|
function stripAnsi(text) {
|
|
130
139
|
return String(text).replace(ANSI_RE, "");
|
|
131
140
|
}
|
|
@@ -202,6 +211,27 @@ function rowptyStatusCommand(args, activeProvider) {
|
|
|
202
211
|
.join(" ");
|
|
203
212
|
}
|
|
204
213
|
|
|
214
|
+
function rowptyConptyMode() {
|
|
215
|
+
const raw = process.env.AI_BATTERY_ROWPTY_CONPTY ?? process.env.CLAUDEX_BATTERY_ROWPTY_CONPTY ?? "os";
|
|
216
|
+
const mode = String(raw).toLowerCase();
|
|
217
|
+
if (["bundled", "node-pty", "nodepty"].includes(mode)) return "bundled";
|
|
218
|
+
if (["auto", "default"].includes(mode)) return "auto";
|
|
219
|
+
return "os";
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
function rowptySpawnEnv() {
|
|
223
|
+
const env = { ...process.env };
|
|
224
|
+
const explicitMode = process.env.AI_BATTERY_ROWPTY_CONPTY !== undefined ||
|
|
225
|
+
process.env.CLAUDEX_BATTERY_ROWPTY_CONPTY !== undefined;
|
|
226
|
+
const mode = rowptyConptyMode();
|
|
227
|
+
if (mode === "bundled") {
|
|
228
|
+
delete env.ROWPTY_NO_CONPTY_DLL;
|
|
229
|
+
} else if (mode === "os" && (explicitMode || (!env.ROWPTY_NO_CONPTY_DLL && !env.ROWPTY_CONPTY_DLL))) {
|
|
230
|
+
env.ROWPTY_NO_CONPTY_DLL = "1";
|
|
231
|
+
}
|
|
232
|
+
return env;
|
|
233
|
+
}
|
|
234
|
+
|
|
205
235
|
function runRowPty(args, activeProvider) {
|
|
206
236
|
if (!process.stdin.isTTY || !process.stdout.isTTY) return Promise.resolve(null);
|
|
207
237
|
const exe = rowptyExePath();
|
|
@@ -217,11 +247,12 @@ function runRowPty(args, activeProvider) {
|
|
|
217
247
|
"--status-cmd", rowptyStatusCommand(args, activeProvider),
|
|
218
248
|
"--", command.file, ...command.args
|
|
219
249
|
];
|
|
220
|
-
|
|
250
|
+
const env = rowptySpawnEnv();
|
|
251
|
+
debugLog("rowpty:start", { exe, hostArgs, size: termSize(), conptyMode: rowptyConptyMode() });
|
|
221
252
|
const child = spawn(exe, hostArgs, {
|
|
222
253
|
stdio: "inherit",
|
|
223
254
|
cwd: process.cwd(),
|
|
224
|
-
env
|
|
255
|
+
env,
|
|
225
256
|
windowsHide: false
|
|
226
257
|
});
|
|
227
258
|
|
|
@@ -680,6 +711,7 @@ async function main() {
|
|
|
680
711
|
export {
|
|
681
712
|
conPtyBackspaceMode,
|
|
682
713
|
conPtyRepaintIntervalMs,
|
|
714
|
+
isVsCodeTerminal,
|
|
683
715
|
normalizeConPtyInput,
|
|
684
716
|
outputMayClearDisplay,
|
|
685
717
|
overlayBottomOffset,
|
|
@@ -687,7 +719,9 @@ export {
|
|
|
687
719
|
parseArgs,
|
|
688
720
|
quoteWindowsCommandLineArg,
|
|
689
721
|
resolveWindowsCommandFile,
|
|
722
|
+
rowptyConptyMode,
|
|
690
723
|
rowptyExePath,
|
|
724
|
+
rowptySpawnEnv,
|
|
691
725
|
rowptyStatusCommand,
|
|
692
726
|
statusRow,
|
|
693
727
|
statusOutputText,
|
package/bin/ai-battery.js
CHANGED
|
@@ -14,6 +14,8 @@ const DEFAULT_TAIL_BYTES = 4 * 1024 * 1024;
|
|
|
14
14
|
const DEFAULT_MAX_FILES = 40;
|
|
15
15
|
const CLAUDE_LIMIT_HIT_TAIL_BYTES = 256 * 1024;
|
|
16
16
|
const CLAUDE_LIMIT_HIT_MAX_FILES = 80;
|
|
17
|
+
const CLAUDE_CODEX_CACHE_SECONDS = 60;
|
|
18
|
+
const CLAUDE_CODEX_FALLBACK_CACHE_SECONDS = 15;
|
|
17
19
|
const DIVIDER = "│";
|
|
18
20
|
const PROVIDER_DIVIDER = "┃";
|
|
19
21
|
const ANSI_RE = /\u001b\[[0-?]*[ -/]*[@-~]/g;
|
|
@@ -729,6 +731,16 @@ function shellPathBlock(shimDir) {
|
|
|
729
731
|
return `\n# >>> ai-battery setup >>>\nexport PATH=${shQuote(shimDir)}:"$PATH"\n# <<< ai-battery setup <<<\n`;
|
|
730
732
|
}
|
|
731
733
|
|
|
734
|
+
function tmuxStatusBarActive() {
|
|
735
|
+
const override = String(process.env.AI_BATTERY_TMUX || process.env.CLAUDEX_BATTERY_TMUX || "").toLowerCase();
|
|
736
|
+
if (override === "row") return false;
|
|
737
|
+
if (["status", "plain", "off"].includes(override)) return true;
|
|
738
|
+
// AI_BATTERY_TMUX_STATUS=1 is set by "ai-battery setup tmux" via tmux set-environment -g.
|
|
739
|
+
// Trust it even when TMUX socket path isn't propagated to Claude Code's statusline subprocess.
|
|
740
|
+
if ((process.env.AI_BATTERY_TMUX_STATUS || process.env.CLAUDEX_BATTERY_TMUX_STATUS) === "1") return true;
|
|
741
|
+
return false;
|
|
742
|
+
}
|
|
743
|
+
|
|
732
744
|
function tmuxConfPath() {
|
|
733
745
|
return process.env.AI_BATTERY_TMUX_CONF || homePath(".tmux.conf");
|
|
734
746
|
}
|
|
@@ -740,16 +752,35 @@ function removeAiBatteryTmuxBlock(text) {
|
|
|
740
752
|
);
|
|
741
753
|
}
|
|
742
754
|
|
|
743
|
-
|
|
744
|
-
|
|
755
|
+
// Returns the last set -g status-right "..." value from confText, ignoring our managed block.
|
|
756
|
+
// Returns null when no explicit status-right is found.
|
|
757
|
+
function extractExistingStatusRight(confText) {
|
|
758
|
+
const stripped = removeAiBatteryTmuxBlock(String(confText));
|
|
759
|
+
const re = /^[ \t]*set(?:-option)?(?:[ \t]+-\w+)*[ \t]+status-right[ \t]+(?:"((?:[^"\\]|\\.)*)"|'((?:[^'\\]|\\.)*)')/gm;
|
|
760
|
+
let last = null;
|
|
761
|
+
for (let m; (m = re.exec(stripped)) !== null;) last = m[1] ?? m[2] ?? null;
|
|
762
|
+
return last;
|
|
763
|
+
}
|
|
764
|
+
|
|
765
|
+
function tmuxStatusBlock(existingStatusRight = null) {
|
|
766
|
+
// #{client_width} is expanded by tmux before running the shell command,
|
|
767
|
+
// giving the responsive layout the actual terminal width to work with.
|
|
768
|
+
const battery = `${shQuote(process.execPath)} ${shQuote(fileURLToPath(import.meta.url))} --tmux --bar-width 8 --max-width #{client_width}`;
|
|
769
|
+
const batteryPart = `#(${battery})`;
|
|
770
|
+
// Put the battery on the far right so tmux left-clips the existing text before
|
|
771
|
+
// the bar. When the block is uninstalled, the earlier set -g status-right wins.
|
|
772
|
+
const statusRightValue = existingStatusRight
|
|
773
|
+
? `${existingStatusRight} ${batteryPart} `
|
|
774
|
+
: `${batteryPart} `;
|
|
775
|
+
const rightLength = 200;
|
|
745
776
|
return [
|
|
746
777
|
"\n# >>> ai-battery tmux >>>",
|
|
747
778
|
"# AI Battery once per session in the tmux status bar; runners inside tmux",
|
|
748
779
|
"# see AI_BATTERY_TMUX_STATUS and skip their per-pane bottom row.",
|
|
749
780
|
"set-environment -g AI_BATTERY_TMUX_STATUS 1",
|
|
750
781
|
"set -g status-interval 10",
|
|
751
|
-
|
|
752
|
-
`set -g status-right "
|
|
782
|
+
`set-option -g status-right-length ${rightLength}`,
|
|
783
|
+
`set -g status-right "${statusRightValue}"`,
|
|
753
784
|
"# <<< ai-battery tmux <<<",
|
|
754
785
|
""
|
|
755
786
|
].join("\n");
|
|
@@ -765,7 +796,8 @@ function installTmuxStatus() {
|
|
|
765
796
|
existing = fs.readFileSync(confPath, "utf8");
|
|
766
797
|
} catch {}
|
|
767
798
|
const withoutBlock = removeAiBatteryTmuxBlock(existing);
|
|
768
|
-
const
|
|
799
|
+
const existingStatusRight = extractExistingStatusRight(withoutBlock);
|
|
800
|
+
const next = `${withoutBlock}${tmuxStatusBlock(existingStatusRight)}`;
|
|
769
801
|
if (next === existing) {
|
|
770
802
|
return { ok: true, confPath, changed: false };
|
|
771
803
|
}
|
|
@@ -868,6 +900,25 @@ function sameWindowsPath(left, right) {
|
|
|
868
900
|
return path.resolve(left).toLowerCase() === path.resolve(right).toLowerCase();
|
|
869
901
|
}
|
|
870
902
|
|
|
903
|
+
function staleWindowsAiBatteryTempPath(entry) {
|
|
904
|
+
if (process.platform !== "win32") return false;
|
|
905
|
+
if (!entry || fs.existsSync(entry)) return false;
|
|
906
|
+
const relative = path.relative(os.tmpdir(), entry);
|
|
907
|
+
if (!relative || relative.startsWith("..") || path.isAbsolute(relative)) return false;
|
|
908
|
+
return /^ai-battery-[^\\/]+[\\/]/i.test(relative);
|
|
909
|
+
}
|
|
910
|
+
|
|
911
|
+
function windowsUserPathWithShim(parts, shimDir) {
|
|
912
|
+
const filtered = parts.filter((entry) => (
|
|
913
|
+
!sameWindowsPath(entry, shimDir)
|
|
914
|
+
&& !staleWindowsAiBatteryTempPath(entry)
|
|
915
|
+
));
|
|
916
|
+
return {
|
|
917
|
+
parts: [shimDir, ...filtered],
|
|
918
|
+
changed: filtered.length !== parts.length || !sameWindowsPath(parts[0] || "", shimDir)
|
|
919
|
+
};
|
|
920
|
+
}
|
|
921
|
+
|
|
871
922
|
function ensureWindowsShimPath(shimDir, originalCommand) {
|
|
872
923
|
const activeNow = pathDirPrecedesOriginal(shimDir, originalCommand);
|
|
873
924
|
if (activeNow) {
|
|
@@ -887,9 +938,8 @@ function ensureWindowsShimPath(shimDir, originalCommand) {
|
|
|
887
938
|
}
|
|
888
939
|
|
|
889
940
|
const parts = windowsUserPathParts();
|
|
890
|
-
const
|
|
891
|
-
const
|
|
892
|
-
const next = [shimDir, ...filtered].join(";");
|
|
941
|
+
const nextPath = windowsUserPathWithShim(parts, shimDir);
|
|
942
|
+
const next = nextPath.parts.join(";");
|
|
893
943
|
const result = runWindowsPowerShell(`[Environment]::SetEnvironmentVariable('Path', ${psQuote(next)}, 'User')`);
|
|
894
944
|
if (result.status !== 0) {
|
|
895
945
|
return {
|
|
@@ -899,9 +949,9 @@ function ensureWindowsShimPath(shimDir, originalCommand) {
|
|
|
899
949
|
};
|
|
900
950
|
}
|
|
901
951
|
return {
|
|
902
|
-
changed,
|
|
952
|
+
changed: nextPath.changed,
|
|
903
953
|
rcPath: "Windows user PATH",
|
|
904
|
-
note: `${changed ? "Added" : "Kept"} ${shimDir} at the front of the Windows user PATH. Open a new cmd/PowerShell for plain "codex" to use AI Battery.`
|
|
954
|
+
note: `${nextPath.changed ? "Added" : "Kept"} ${shimDir} at the front of the Windows user PATH. Open a new cmd/PowerShell for plain "codex" to use AI Battery.`
|
|
905
955
|
};
|
|
906
956
|
}
|
|
907
957
|
|
|
@@ -1525,11 +1575,13 @@ function diagnoseCodex() {
|
|
|
1525
1575
|
}
|
|
1526
1576
|
const rowpty = process.platform === "win32" ? rowptyExePath() : null;
|
|
1527
1577
|
const rowptyConpty = rowpty ? fs.existsSync(path.join(path.dirname(rowpty), "conpty.dll")) : false;
|
|
1578
|
+
const requestedRowptyConpty = String(process.env.AI_BATTERY_ROWPTY_CONPTY || process.env.CLAUDEX_BATTERY_ROWPTY_CONPTY || "os").toLowerCase();
|
|
1579
|
+
const bundledRowptyConptyRequested = ["bundled", "node-pty", "nodepty", "auto", "default"].includes(requestedRowptyConpty);
|
|
1528
1580
|
if (wrapperInstalled && process.platform === "win32" && !rowpty) {
|
|
1529
1581
|
notes.push("rowpty.exe not found, so the Codex bottom row uses the overlay fallback. Run: ai-battery setup codex (compiles it locally with the in-box csc.exe).");
|
|
1530
1582
|
}
|
|
1531
|
-
if (rowpty && !rowptyConpty) {
|
|
1532
|
-
notes.push("conpty.dll is not next to rowpty.exe
|
|
1583
|
+
if (rowpty && bundledRowptyConptyRequested && !rowptyConpty) {
|
|
1584
|
+
notes.push("Bundled ConPTY was requested, but conpty.dll is not next to rowpty.exe. Run: ai-battery setup codex with the node-pty package installed, or unset AI_BATTERY_ROWPTY_CONPTY to use the faster OS ConPTY default.");
|
|
1533
1585
|
}
|
|
1534
1586
|
if (wrapperInstalled && process.platform !== "win32" && !python3) {
|
|
1535
1587
|
notes.push("Codex wrapper needs python3 for the POSIX PTY row. Install Python 3, then run plain \"codex\" again.");
|
|
@@ -1549,7 +1601,9 @@ function diagnoseCodex() {
|
|
|
1549
1601
|
wrapperInstalled,
|
|
1550
1602
|
runnerPath,
|
|
1551
1603
|
runnerExists,
|
|
1552
|
-
rowpty: process.platform === "win32"
|
|
1604
|
+
rowpty: process.platform === "win32"
|
|
1605
|
+
? { path: rowpty, installed: Boolean(rowpty), bundledConpty: rowptyConpty, bundledConptyRequested }
|
|
1606
|
+
: null,
|
|
1553
1607
|
statusLine,
|
|
1554
1608
|
python3,
|
|
1555
1609
|
originalCommand: configuredOriginal,
|
|
@@ -1712,7 +1766,9 @@ function installRowPtyHost() {
|
|
|
1712
1766
|
ok: true,
|
|
1713
1767
|
exePath,
|
|
1714
1768
|
compiled,
|
|
1715
|
-
conpty: conptyDir
|
|
1769
|
+
conpty: conptyDir
|
|
1770
|
+
? "OS default (bundled provider copied; opt in with AI_BATTERY_ROWPTY_CONPTY=bundled)"
|
|
1771
|
+
: "OS built-in"
|
|
1716
1772
|
};
|
|
1717
1773
|
}
|
|
1718
1774
|
|
|
@@ -2151,31 +2207,123 @@ function shellArg(value) {
|
|
|
2151
2207
|
return `'${text.replace(/'/g, "'\\''")}'`;
|
|
2152
2208
|
}
|
|
2153
2209
|
|
|
2210
|
+
const PROVIDER_EXECUTABLE_RE = {
|
|
2211
|
+
codex: /^codex(?:\.(?:cmd|exe|bat|js|mjs|cjs))?$/i,
|
|
2212
|
+
claude: /^(?:claude|claude-code)(?:\.(?:cmd|exe|bat|js|mjs|cjs))?$/i
|
|
2213
|
+
};
|
|
2214
|
+
const PROVIDER_PACKAGE_MARKERS = {
|
|
2215
|
+
codex: ["@openai/codex"],
|
|
2216
|
+
claude: ["@anthropic-ai/claude-code", "claude-code"]
|
|
2217
|
+
};
|
|
2218
|
+
const AI_BATTERY_RUNNER_RE = /^(?:ai-battery-run|claudex-battery-run|ai-battery-run-win\.js)$/i;
|
|
2219
|
+
const RUNNER_OPTIONS_WITH_VALUES = new Set([
|
|
2220
|
+
"--interval",
|
|
2221
|
+
"--bar-width",
|
|
2222
|
+
"--provider",
|
|
2223
|
+
"--layout",
|
|
2224
|
+
"--left-padding"
|
|
2225
|
+
]);
|
|
2226
|
+
|
|
2154
2227
|
function claudeCommandIsBackground(cmdline) {
|
|
2155
2228
|
return /(^|\s)daemon\s+run(\s|$)/.test(cmdline)
|
|
2156
2229
|
|| cmdline.includes("--bg-pty-host")
|
|
2157
2230
|
|| cmdline.includes("--bg-spare");
|
|
2158
2231
|
}
|
|
2159
2232
|
|
|
2233
|
+
function commandLineTokens(cmdline) {
|
|
2234
|
+
return (String(cmdline || "").match(/"(?:(?:\\.|[^"\\])*)"|'[^']*'|\S+/g) || [])
|
|
2235
|
+
.map((token) => token.replace(/^"(.*)"$/s, "$1").replace(/^'(.*)'$/s, "$1").replace(/\\"/g, "\""))
|
|
2236
|
+
.filter(Boolean);
|
|
2237
|
+
}
|
|
2238
|
+
|
|
2239
|
+
function commandTokenBasename(token) {
|
|
2240
|
+
return String(token || "")
|
|
2241
|
+
.replace(/^["']|["']$/g, "")
|
|
2242
|
+
.split(/[\\/]/)
|
|
2243
|
+
.filter(Boolean)
|
|
2244
|
+
.pop() || "";
|
|
2245
|
+
}
|
|
2246
|
+
|
|
2247
|
+
function tokenMatchesProviderExecutable(token, provider) {
|
|
2248
|
+
return Boolean(PROVIDER_EXECUTABLE_RE[provider]?.test(commandTokenBasename(token)));
|
|
2249
|
+
}
|
|
2250
|
+
|
|
2251
|
+
function tokenMatchesProviderPackage(token, provider) {
|
|
2252
|
+
const lower = String(token || "").toLowerCase();
|
|
2253
|
+
return (PROVIDER_PACKAGE_MARKERS[provider] || []).some((marker) => lower.includes(marker));
|
|
2254
|
+
}
|
|
2255
|
+
|
|
2256
|
+
function commandInvokesAiBatteryRunner(tokens) {
|
|
2257
|
+
return tokens.some((token) => AI_BATTERY_RUNNER_RE.test(commandTokenBasename(token)));
|
|
2258
|
+
}
|
|
2259
|
+
|
|
2260
|
+
function tokensAfterLastSeparator(tokens) {
|
|
2261
|
+
const index = tokens.lastIndexOf("--");
|
|
2262
|
+
return index >= 0 ? tokens.slice(index + 1) : [];
|
|
2263
|
+
}
|
|
2264
|
+
|
|
2265
|
+
function aiBatteryRunnerCommandTokens(tokens) {
|
|
2266
|
+
const runnerIndex = tokens.findIndex((token) => AI_BATTERY_RUNNER_RE.test(commandTokenBasename(token)));
|
|
2267
|
+
if (runnerIndex < 0) return [];
|
|
2268
|
+
|
|
2269
|
+
for (let i = runnerIndex + 1; i < tokens.length; i += 1) {
|
|
2270
|
+
const token = tokens[i];
|
|
2271
|
+
if (token === "--") return tokens.slice(i + 1);
|
|
2272
|
+
if (token.startsWith("--")) {
|
|
2273
|
+
const option = token.split("=", 1)[0];
|
|
2274
|
+
if (RUNNER_OPTIONS_WITH_VALUES.has(option) && !token.includes("=")) i += 1;
|
|
2275
|
+
continue;
|
|
2276
|
+
}
|
|
2277
|
+
if (token.startsWith("-")) continue;
|
|
2278
|
+
return tokens.slice(i);
|
|
2279
|
+
}
|
|
2280
|
+
return [];
|
|
2281
|
+
}
|
|
2282
|
+
|
|
2160
2283
|
function commandMatchesProvider(cmdline, provider) {
|
|
2284
|
+
const text = String(cmdline || "");
|
|
2285
|
+
if (provider === "claude" && claudeCommandIsBackground(text)) return false;
|
|
2161
2286
|
if (
|
|
2162
|
-
|
|
2163
|
-
&& !
|
|
2164
|
-
&& !
|
|
2165
|
-
&& !cmdline.includes("claude-code")
|
|
2287
|
+
text.includes("ai-battery.js")
|
|
2288
|
+
&& !tokenMatchesProviderPackage(text, "codex")
|
|
2289
|
+
&& !tokenMatchesProviderPackage(text, "claude")
|
|
2166
2290
|
) {
|
|
2167
2291
|
return false;
|
|
2168
2292
|
}
|
|
2169
2293
|
|
|
2170
|
-
|
|
2171
|
-
|
|
2294
|
+
const tokens = commandLineTokens(text);
|
|
2295
|
+
if (!tokens.length) return false;
|
|
2296
|
+
|
|
2297
|
+
if (tokens.some((token) => tokenMatchesProviderPackage(token, provider))) return true;
|
|
2298
|
+
|
|
2299
|
+
const firstBase = commandTokenBasename(tokens[0]).toLowerCase();
|
|
2300
|
+
if (tokenMatchesProviderExecutable(tokens[0], provider)) return true;
|
|
2301
|
+
if (/^node(?:\.exe)?$/i.test(firstBase) && tokenMatchesProviderExecutable(tokens[1], provider)) return true;
|
|
2302
|
+
|
|
2303
|
+
const runnerCommand = commandInvokesAiBatteryRunner(tokens)
|
|
2304
|
+
? aiBatteryRunnerCommandTokens(tokens)
|
|
2305
|
+
: [];
|
|
2306
|
+
if (runnerCommand.some((token) => tokenMatchesProviderExecutable(token, provider))) return true;
|
|
2307
|
+
|
|
2308
|
+
const afterSeparator = tokensAfterLastSeparator(tokens);
|
|
2309
|
+
if (
|
|
2310
|
+
/^(?:rowpty(?:\.exe)?|cmd(?:\.exe)?)$/i.test(firstBase)
|
|
2311
|
+
&& afterSeparator.some((token) => tokenMatchesProviderExecutable(token, provider))
|
|
2312
|
+
) {
|
|
2313
|
+
return true;
|
|
2172
2314
|
}
|
|
2173
|
-
|
|
2174
|
-
|
|
2175
|
-
|
|
2176
|
-
|
|
2177
|
-
|
|
2315
|
+
|
|
2316
|
+
if (/^cmd(?:\.exe)?$/i.test(firstBase)) {
|
|
2317
|
+
const callIndex = tokens.findIndex((token) => /^call$/i.test(token));
|
|
2318
|
+
if (callIndex >= 0 && tokens.slice(callIndex + 1).some((token) => tokenMatchesProviderExecutable(token, provider))) {
|
|
2319
|
+
return true;
|
|
2320
|
+
}
|
|
2178
2321
|
}
|
|
2322
|
+
|
|
2323
|
+
if (provider === "codex") {
|
|
2324
|
+
return false;
|
|
2325
|
+
}
|
|
2326
|
+
if (provider === "claude") return false;
|
|
2179
2327
|
return false;
|
|
2180
2328
|
}
|
|
2181
2329
|
|
|
@@ -2299,9 +2447,9 @@ function scanProcessCommands() {
|
|
|
2299
2447
|
return commands;
|
|
2300
2448
|
}
|
|
2301
2449
|
|
|
2302
|
-
function
|
|
2303
|
-
const needsTty =
|
|
2304
|
-
return
|
|
2450
|
+
function providerRunningInProcesses(provider, processes, platform = process.platform) {
|
|
2451
|
+
const needsTty = platform !== "win32";
|
|
2452
|
+
return processes.some((proc) => {
|
|
2305
2453
|
if (!commandMatchesProvider(proc.cmdline, provider)) return false;
|
|
2306
2454
|
if (!needsTty) return true;
|
|
2307
2455
|
if (proc.hasTty === undefined) proc.hasTty = processHasControllingTty(proc.pid);
|
|
@@ -2309,6 +2457,10 @@ function isProviderRunning(provider) {
|
|
|
2309
2457
|
});
|
|
2310
2458
|
}
|
|
2311
2459
|
|
|
2460
|
+
function isProviderRunning(provider) {
|
|
2461
|
+
return providerRunningInProcesses(provider, scanProcessCommands());
|
|
2462
|
+
}
|
|
2463
|
+
|
|
2312
2464
|
function readStdin() {
|
|
2313
2465
|
return new Promise((resolve, reject) => {
|
|
2314
2466
|
let input = "";
|
|
@@ -2820,14 +2972,34 @@ function readCodex(options = {}) {
|
|
|
2820
2972
|
writeScanCache("codex-status", scan);
|
|
2821
2973
|
}
|
|
2822
2974
|
|
|
2823
|
-
const running = options.
|
|
2824
|
-
?
|
|
2825
|
-
:
|
|
2975
|
+
const running = typeof options.runningOverride === "boolean"
|
|
2976
|
+
? options.runningOverride
|
|
2977
|
+
: (
|
|
2978
|
+
options.includeRunning === false
|
|
2979
|
+
? Boolean(scan.running)
|
|
2980
|
+
: isProviderRunning("codex")
|
|
2981
|
+
);
|
|
2826
2982
|
const result = { ...scan, running };
|
|
2827
2983
|
if (result.ok) result.ageSeconds = cacheAgeSeconds(result.timestamp ?? null);
|
|
2828
2984
|
return result;
|
|
2829
2985
|
}
|
|
2830
2986
|
|
|
2987
|
+
function readCodexForClaudeCapture() {
|
|
2988
|
+
if (process.platform !== "win32") return readCodex();
|
|
2989
|
+
|
|
2990
|
+
const cached = readCodex({
|
|
2991
|
+
cachedOnly: true,
|
|
2992
|
+
maxAgeSeconds: CLAUDE_CODEX_CACHE_SECONDS,
|
|
2993
|
+
runningOverride: false
|
|
2994
|
+
});
|
|
2995
|
+
if (cached) return cached;
|
|
2996
|
+
|
|
2997
|
+
return readCodex({
|
|
2998
|
+
maxAgeSeconds: CLAUDE_CODEX_FALLBACK_CACHE_SECONDS,
|
|
2999
|
+
runningOverride: false
|
|
3000
|
+
});
|
|
3001
|
+
}
|
|
3002
|
+
|
|
2831
3003
|
function scanCodexStatus() {
|
|
2832
3004
|
const roots = (process.env.CODEX_HOME || homePath(".codex"))
|
|
2833
3005
|
.split(",")
|
|
@@ -2913,8 +3085,10 @@ function usageTotal(usage) {
|
|
|
2913
3085
|
].reduce((sum, value) => sum + (Number(value) || 0), 0);
|
|
2914
3086
|
}
|
|
2915
3087
|
|
|
2916
|
-
function readClaude() {
|
|
2917
|
-
const running =
|
|
3088
|
+
function readClaude(options = {}) {
|
|
3089
|
+
const running = typeof options.runningOverride === "boolean"
|
|
3090
|
+
? options.runningOverride
|
|
3091
|
+
: isProviderRunning("claude");
|
|
2918
3092
|
const statuslineCache = readClaudeStatuslineCache();
|
|
2919
3093
|
if (statuslineCache) return { ...statuslineCache, running };
|
|
2920
3094
|
|
|
@@ -3007,15 +3181,17 @@ function colorize(text, color, style) {
|
|
|
3007
3181
|
gray: 90,
|
|
3008
3182
|
cyan: 36
|
|
3009
3183
|
};
|
|
3010
|
-
|
|
3011
|
-
|
|
3012
|
-
|
|
3013
|
-
|
|
3014
|
-
|
|
3015
|
-
|
|
3016
|
-
|
|
3017
|
-
|
|
3018
|
-
|
|
3184
|
+
if (style === "tmux") {
|
|
3185
|
+
// All colors: fg only (no background). The user's status-bar background
|
|
3186
|
+
// is preserved; only the glyph/text color is changed.
|
|
3187
|
+
const tmuxFg = {
|
|
3188
|
+
green: "green", orange: "colour208", red: "red",
|
|
3189
|
+
white: "black", // active provider text → black
|
|
3190
|
+
gray: "colour240", // inactive provider → slightly darker gray than 244
|
|
3191
|
+
cyan: "cyan"
|
|
3192
|
+
};
|
|
3193
|
+
return `#[fg=${tmuxFg[color] || "default"}]${text}#[default]`;
|
|
3194
|
+
}
|
|
3019
3195
|
return `\u001b[${codes[color] || 0}m${text}\u001b[0m`;
|
|
3020
3196
|
}
|
|
3021
3197
|
|
|
@@ -3042,6 +3218,13 @@ const WINDOWS_BAR_GLYPH = "❚";
|
|
|
3042
3218
|
// Plain (--no-color / non-TTY) has no color to tell the halves apart, so it
|
|
3043
3219
|
// falls back to a distinct empty glyph. This path is opt-in and not the TUI.
|
|
3044
3220
|
const BAR_EMPTY_PLAIN_GLYPH = "░";
|
|
3221
|
+
// tmux status-right: ▮ (U+25AE) and ▯ (U+25AF) are the filled/outline pair
|
|
3222
|
+
// from the same Geometric Shapes Unicode block, so they render at the same
|
|
3223
|
+
// size and baseline across terminal fonts (no cross-block fallback mismatch).
|
|
3224
|
+
// Colors are NOT applied: fg-only colors become invisible when they match the
|
|
3225
|
+
// status-bar background (e.g. green bar fill on green status-bar bg).
|
|
3226
|
+
const BAR_FILL_TMUX_GLYPH = "▮";
|
|
3227
|
+
const BAR_EMPTY_TMUX_GLYPH = "▯";
|
|
3045
3228
|
|
|
3046
3229
|
function barGlyph() {
|
|
3047
3230
|
const override = process.env.AI_BATTERY_BAR_GLYPH || process.env.CLAUDEX_BATTERY_BAR_GLYPH;
|
|
@@ -3059,13 +3242,19 @@ function bar(percent, width, chargeColor = "green", style) {
|
|
|
3059
3242
|
if (full > width) full = width;
|
|
3060
3243
|
|
|
3061
3244
|
const glyph = barGlyph();
|
|
3062
|
-
const fill = glyph.repeat(full);
|
|
3063
3245
|
const empty = width - full;
|
|
3064
3246
|
|
|
3065
3247
|
if (style === "plain") {
|
|
3066
|
-
return `${
|
|
3248
|
+
return `${glyph.repeat(full)}${BAR_EMPTY_PLAIN_GLYPH.repeat(empty)}`;
|
|
3067
3249
|
}
|
|
3068
|
-
|
|
3250
|
+
if (style === "tmux") {
|
|
3251
|
+
// No color on either half: fg-only colors become invisible when they match
|
|
3252
|
+
// the status-bar background. Shape alone distinguishes fill from empty.
|
|
3253
|
+
return `${BAR_FILL_TMUX_GLYPH.repeat(full)}${BAR_EMPTY_TMUX_GLYPH.repeat(empty)}`;
|
|
3254
|
+
}
|
|
3255
|
+
const fill = glyph.repeat(full);
|
|
3256
|
+
const emptyStr = empty ? colorize(glyph.repeat(empty), "gray", style) : "";
|
|
3257
|
+
return `${colorize(fill, chargeColor, style)}${emptyStr}`;
|
|
3069
3258
|
}
|
|
3070
3259
|
|
|
3071
3260
|
function duration(seconds) {
|
|
@@ -3102,8 +3291,10 @@ function resetClock(limit) {
|
|
|
3102
3291
|
return `${hours}:${minutes}`;
|
|
3103
3292
|
}
|
|
3104
3293
|
|
|
3294
|
+
const TMUX_FORMAT_RE = /#\[[^\]]*\]/g;
|
|
3295
|
+
|
|
3105
3296
|
function stripAnsi(text) {
|
|
3106
|
-
return String(text).replace(ANSI_RE, "");
|
|
3297
|
+
return String(text).replace(ANSI_RE, "").replace(TMUX_FORMAT_RE, "");
|
|
3107
3298
|
}
|
|
3108
3299
|
|
|
3109
3300
|
function charWidth(char) {
|
|
@@ -3479,14 +3670,20 @@ function compactNumber(value) {
|
|
|
3479
3670
|
return String(number);
|
|
3480
3671
|
}
|
|
3481
3672
|
|
|
3673
|
+
function runningOverrideForProvider(args, provider) {
|
|
3674
|
+
if (args.activeProvider === provider) return true;
|
|
3675
|
+
if (args.activeProvider && process.platform === "win32") return false;
|
|
3676
|
+
return null;
|
|
3677
|
+
}
|
|
3678
|
+
|
|
3482
3679
|
function collect(args) {
|
|
3483
3680
|
const results = [];
|
|
3484
3681
|
const includeHidden = args.provider !== "all";
|
|
3485
3682
|
if ((args.provider === "all" || args.provider === "codex") && (includeHidden || providerVisible("codex"))) {
|
|
3486
|
-
results.push(readCodex());
|
|
3683
|
+
results.push(readCodex({ runningOverride: runningOverrideForProvider(args, "codex") }));
|
|
3487
3684
|
}
|
|
3488
3685
|
if ((args.provider === "all" || args.provider === "claude") && (includeHidden || providerVisible("claude"))) {
|
|
3489
|
-
results.push(readClaude());
|
|
3686
|
+
results.push(readClaude({ runningOverride: runningOverrideForProvider(args, "claude") }));
|
|
3490
3687
|
}
|
|
3491
3688
|
return {
|
|
3492
3689
|
generatedAt: new Date().toISOString(),
|
|
@@ -4115,7 +4312,9 @@ async function main() {
|
|
|
4115
4312
|
console.log(`Codex status_line: ${result.codex.statusLine.configured ? "configured" : "missing"} (${result.codex.statusLine.configPath})`);
|
|
4116
4313
|
console.log(`AI Battery runner: ${result.codex.runnerExists ? "found" : "missing"} (${result.codex.runnerPath})`);
|
|
4117
4314
|
if (result.codex.rowpty) {
|
|
4118
|
-
const conptyLabel = result.codex.rowpty.
|
|
4315
|
+
const conptyLabel = result.codex.rowpty.bundledConptyRequested
|
|
4316
|
+
? (result.codex.rowpty.bundledConpty ? "bundled ConPTY requested" : "bundled ConPTY requested but missing")
|
|
4317
|
+
: (result.codex.rowpty.bundledConpty ? "OS ConPTY default, bundled provider available" : "OS ConPTY default");
|
|
4119
4318
|
console.log(`rowpty host: ${result.codex.rowpty.installed ? `found, ${conptyLabel} (${result.codex.rowpty.path})` : "missing (overlay fallback)"}`);
|
|
4120
4319
|
}
|
|
4121
4320
|
console.log(`python3: ${result.codex.python3 || "not found"}`);
|
|
@@ -4191,9 +4390,7 @@ async function main() {
|
|
|
4191
4390
|
if (!args.silent) {
|
|
4192
4391
|
const results = [];
|
|
4193
4392
|
if ((args.provider === "all" || args.provider === "codex") && providerVisible("codex")) {
|
|
4194
|
-
const codexData =
|
|
4195
|
-
? readCodex({ cachedOnly: true, includeRunning: true, maxAgeSeconds: 60 })
|
|
4196
|
-
: readCodex();
|
|
4393
|
+
const codexData = readCodexForClaudeCapture();
|
|
4197
4394
|
if (codexData) results.push(codexData);
|
|
4198
4395
|
}
|
|
4199
4396
|
if ((args.provider === "all" || args.provider === "claude") && providerVisible("claude")) {
|
|
@@ -4209,7 +4406,12 @@ async function main() {
|
|
|
4209
4406
|
generatedAt: new Date().toISOString(),
|
|
4210
4407
|
results
|
|
4211
4408
|
}, { ...args, activeProvider: "claude", leftPadding: 0, maxWidth: contentWidth });
|
|
4212
|
-
|
|
4409
|
+
// Inside tmux with the status-bar integration, the battery already shows
|
|
4410
|
+
// in tmux's own bar; keep the statusline to the one line tmux can't show.
|
|
4411
|
+
const text = tmuxStatusBarActive()
|
|
4412
|
+
? (header || usage)
|
|
4413
|
+
: (header && usage ? `${header}\n${usage}` : (usage || header));
|
|
4414
|
+
console.log(applyLeftPadding(text, args));
|
|
4213
4415
|
}
|
|
4214
4416
|
return;
|
|
4215
4417
|
}
|
|
@@ -4251,6 +4453,7 @@ async function main() {
|
|
|
4251
4453
|
export {
|
|
4252
4454
|
bar,
|
|
4253
4455
|
claudeHeader,
|
|
4456
|
+
commandMatchesProvider,
|
|
4254
4457
|
codexStatusLineMatches,
|
|
4255
4458
|
codexWrapperScript,
|
|
4256
4459
|
firstPercentValue,
|
|
@@ -4258,18 +4461,23 @@ export {
|
|
|
4258
4461
|
installCodexStatusLine,
|
|
4259
4462
|
installCodexWrapper,
|
|
4260
4463
|
installRowPtyHost,
|
|
4464
|
+
extractExistingStatusRight,
|
|
4261
4465
|
installTmuxStatus,
|
|
4262
4466
|
normalizeLimit,
|
|
4263
4467
|
removeAiBatteryTmuxBlock,
|
|
4468
|
+
runningOverrideForProvider,
|
|
4469
|
+
tmuxStatusBarActive,
|
|
4264
4470
|
removeOrRestoreCodexWrapper,
|
|
4265
4471
|
removeAiBatteryShellPathBlock,
|
|
4266
4472
|
percentValue,
|
|
4473
|
+
providerRunningInProcesses,
|
|
4267
4474
|
sameFilePath,
|
|
4268
4475
|
visibleWidth,
|
|
4269
4476
|
uninstallClaudeStatusline,
|
|
4270
4477
|
uninstallCodexWrapper,
|
|
4271
4478
|
uninstallRowPtyHost,
|
|
4272
4479
|
uninstallTmuxStatus,
|
|
4480
|
+
windowsUserPathWithShim,
|
|
4273
4481
|
windowsCscPath
|
|
4274
4482
|
};
|
|
4275
4483
|
|
package/package.json
CHANGED
package/vendor/rowpty/RowPty.cs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// Vendored from the rowpty project (commit
|
|
1
|
+
// Vendored from the rowpty project (commit 9a55775). Do not edit here -
|
|
2
2
|
// change it upstream in Projects/rowpty and run: node scripts/sync-rowpty.mjs
|
|
3
3
|
// "ai-battery setup" compiles this file on the user machine with the in-box
|
|
4
4
|
// .NET Framework csc.exe so no unsigned binary ships in the npm package.
|
|
@@ -89,6 +89,7 @@ internal sealed class RowPty
|
|
|
89
89
|
private int fetchMaxWidth;
|
|
90
90
|
|
|
91
91
|
private Stopwatch clock;
|
|
92
|
+
private bool childOutputSeen;
|
|
92
93
|
private bool screenDirty;
|
|
93
94
|
private long lastOutputMs;
|
|
94
95
|
private int forceRepaintCount;
|
|
@@ -526,7 +527,7 @@ internal sealed class RowPty
|
|
|
526
527
|
|
|
527
528
|
private int RunMainLoop()
|
|
528
529
|
{
|
|
529
|
-
bool forcePaint =
|
|
530
|
+
bool forcePaint = false;
|
|
530
531
|
long nextSizeCheckMs = 0;
|
|
531
532
|
long nextFetchMs = 0;
|
|
532
533
|
long intervalMs = (long)(this.options.IntervalSeconds * 1000.0);
|
|
@@ -543,6 +544,11 @@ internal sealed class RowPty
|
|
|
543
544
|
}
|
|
544
545
|
|
|
545
546
|
long nowMs = this.clock.ElapsedMilliseconds;
|
|
547
|
+
bool childOutputSeenNow;
|
|
548
|
+
lock (this.stateLock)
|
|
549
|
+
{
|
|
550
|
+
childOutputSeenNow = this.childOutputSeen;
|
|
551
|
+
}
|
|
546
552
|
|
|
547
553
|
if (nowMs >= nextSizeCheckMs)
|
|
548
554
|
{
|
|
@@ -555,14 +561,17 @@ internal sealed class RowPty
|
|
|
555
561
|
this.currentCols = cols;
|
|
556
562
|
this.currentRows = rows;
|
|
557
563
|
this.resizePseudoConsoleProvider(this.hPseudoConsole, MakeSize(cols, ChildRows(rows)));
|
|
558
|
-
|
|
559
|
-
|
|
564
|
+
if (childOutputSeenNow)
|
|
565
|
+
{
|
|
566
|
+
RequestStatusFetch(MaxStatusWidth(cols));
|
|
567
|
+
forcePaint = true;
|
|
568
|
+
}
|
|
560
569
|
}
|
|
561
570
|
}
|
|
562
571
|
nextSizeCheckMs = nowMs + 200;
|
|
563
572
|
}
|
|
564
573
|
|
|
565
|
-
if (this.options.StatusCommand != null && nowMs >= nextFetchMs)
|
|
574
|
+
if (childOutputSeenNow && this.options.StatusCommand != null && nowMs >= nextFetchMs)
|
|
566
575
|
{
|
|
567
576
|
RequestStatusFetch(MaxStatusWidth(this.currentCols));
|
|
568
577
|
nextFetchMs = nowMs + intervalMs;
|
|
@@ -580,7 +589,11 @@ internal sealed class RowPty
|
|
|
580
589
|
|
|
581
590
|
lock (this.stateLock)
|
|
582
591
|
{
|
|
583
|
-
if (this.
|
|
592
|
+
if (!this.childOutputSeen)
|
|
593
|
+
{
|
|
594
|
+
paintNow = false;
|
|
595
|
+
}
|
|
596
|
+
else if (this.forceRepaintCount > 0)
|
|
584
597
|
{
|
|
585
598
|
paintNow = true;
|
|
586
599
|
forced = true;
|
|
@@ -603,7 +616,7 @@ internal sealed class RowPty
|
|
|
603
616
|
}
|
|
604
617
|
}
|
|
605
618
|
|
|
606
|
-
if (!paintNow && version != this.paintedStatusVersion)
|
|
619
|
+
if (this.childOutputSeen && !paintNow && version != this.paintedStatusVersion)
|
|
607
620
|
{
|
|
608
621
|
paintNow = true;
|
|
609
622
|
}
|
|
@@ -821,9 +834,11 @@ internal sealed class RowPty
|
|
|
821
834
|
break;
|
|
822
835
|
}
|
|
823
836
|
|
|
837
|
+
int currentVtState = this.outputVtState;
|
|
824
838
|
bool clearSeen = ScanForClear(buffer, read);
|
|
839
|
+
bool visibleTextSeen = ScanForVisibleText(currentVtState, buffer, read);
|
|
825
840
|
int win32InputModeChange = ScanForWin32InputMode(buffer, read);
|
|
826
|
-
int nextVtState = ScanVtState(
|
|
841
|
+
int nextVtState = ScanVtState(currentVtState, buffer, read);
|
|
827
842
|
if (win32InputModeChange > 0)
|
|
828
843
|
{
|
|
829
844
|
this.win32InputModeEnabled = true;
|
|
@@ -848,6 +863,10 @@ internal sealed class RowPty
|
|
|
848
863
|
this.outputVtState = nextVtState;
|
|
849
864
|
this.outputVtStateChangedMs = nowMs;
|
|
850
865
|
}
|
|
866
|
+
if (visibleTextSeen)
|
|
867
|
+
{
|
|
868
|
+
this.childOutputSeen = true;
|
|
869
|
+
}
|
|
851
870
|
this.lastOutputMs = nowMs;
|
|
852
871
|
this.screenDirty = true;
|
|
853
872
|
if (clearSeen)
|
|
@@ -1512,6 +1531,86 @@ internal sealed class RowPty
|
|
|
1512
1531
|
return state;
|
|
1513
1532
|
}
|
|
1514
1533
|
|
|
1534
|
+
private static bool ScanForVisibleText(int state, byte[] buffer, int count)
|
|
1535
|
+
{
|
|
1536
|
+
int i;
|
|
1537
|
+
for (i = 0; i < count; i++)
|
|
1538
|
+
{
|
|
1539
|
+
byte b = buffer[i];
|
|
1540
|
+
if (state == VT_STATE_GROUND)
|
|
1541
|
+
{
|
|
1542
|
+
if (b == 27)
|
|
1543
|
+
{
|
|
1544
|
+
state = VT_STATE_ESC;
|
|
1545
|
+
}
|
|
1546
|
+
else if (b > 0x20 && b != 0x7f)
|
|
1547
|
+
{
|
|
1548
|
+
return true;
|
|
1549
|
+
}
|
|
1550
|
+
}
|
|
1551
|
+
else if (state == VT_STATE_ESC)
|
|
1552
|
+
{
|
|
1553
|
+
state = VtEscTransition(b);
|
|
1554
|
+
}
|
|
1555
|
+
else if (state == VT_STATE_CSI)
|
|
1556
|
+
{
|
|
1557
|
+
if (b >= 0x40 && b <= 0x7e)
|
|
1558
|
+
{
|
|
1559
|
+
state = VT_STATE_GROUND;
|
|
1560
|
+
}
|
|
1561
|
+
}
|
|
1562
|
+
else if (state == VT_STATE_OSC)
|
|
1563
|
+
{
|
|
1564
|
+
if (b == 7)
|
|
1565
|
+
{
|
|
1566
|
+
state = VT_STATE_GROUND;
|
|
1567
|
+
}
|
|
1568
|
+
else if (b == 27)
|
|
1569
|
+
{
|
|
1570
|
+
state = VT_STATE_OSC_ESC;
|
|
1571
|
+
}
|
|
1572
|
+
}
|
|
1573
|
+
else if (state == VT_STATE_DCS)
|
|
1574
|
+
{
|
|
1575
|
+
if (b == 7)
|
|
1576
|
+
{
|
|
1577
|
+
state = VT_STATE_GROUND;
|
|
1578
|
+
}
|
|
1579
|
+
else if (b == 27)
|
|
1580
|
+
{
|
|
1581
|
+
state = VT_STATE_DCS_ESC;
|
|
1582
|
+
}
|
|
1583
|
+
}
|
|
1584
|
+
else if (state == VT_STATE_OSC_ESC)
|
|
1585
|
+
{
|
|
1586
|
+
if (b == (byte)'\\')
|
|
1587
|
+
{
|
|
1588
|
+
state = VT_STATE_GROUND;
|
|
1589
|
+
}
|
|
1590
|
+
else
|
|
1591
|
+
{
|
|
1592
|
+
state = VtEscTransition(b);
|
|
1593
|
+
}
|
|
1594
|
+
}
|
|
1595
|
+
else if (state == VT_STATE_DCS_ESC)
|
|
1596
|
+
{
|
|
1597
|
+
if (b == (byte)'\\')
|
|
1598
|
+
{
|
|
1599
|
+
state = VT_STATE_GROUND;
|
|
1600
|
+
}
|
|
1601
|
+
else
|
|
1602
|
+
{
|
|
1603
|
+
state = VtEscTransition(b);
|
|
1604
|
+
}
|
|
1605
|
+
}
|
|
1606
|
+
else
|
|
1607
|
+
{
|
|
1608
|
+
state = VT_STATE_GROUND;
|
|
1609
|
+
}
|
|
1610
|
+
}
|
|
1611
|
+
return false;
|
|
1612
|
+
}
|
|
1613
|
+
|
|
1515
1614
|
private static int VtEscTransition(byte b)
|
|
1516
1615
|
{
|
|
1517
1616
|
if (b == (byte)'[')
|