ai-battery 0.1.11 → 0.1.13
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/LICENSE +21 -21
- package/README.md +331 -331
- package/bin/ai-battery-hud +21 -21
- package/bin/ai-battery-hud.js +593 -593
- package/bin/ai-battery-hud.ps1 +2064 -2064
- package/bin/ai-battery-macos-status.applescript +134 -134
- package/bin/ai-battery-run +378 -378
- package/bin/ai-battery-run-win.js +696 -686
- package/bin/ai-battery.js +4437 -4323
- package/docs/claude-statusline-preview.svg +37 -37
- package/docs/terminal-preview.svg +44 -44
- package/package.json +57 -57
|
@@ -1,200 +1,209 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
import { spawn } from "node:child_process";
|
|
4
|
-
import fs from "node:fs";
|
|
5
|
-
import path from "node:path";
|
|
6
|
-
import { fileURLToPath } from "node:url";
|
|
7
|
-
|
|
8
|
-
const SCRIPT_DIR = path.dirname(fileURLToPath(import.meta.url));
|
|
9
|
-
const BATTERY_BIN = process.env.AI_BATTERY_BIN
|
|
10
|
-
|| process.env.CLAUDEX_BATTERY_BIN
|
|
11
|
-
|| path.join(SCRIPT_DIR, "ai-battery.js");
|
|
12
|
-
const ANSI_RE = /\u001b\[[0-?]*[ -/]*[@-~]/g;
|
|
13
|
-
const DEBUG_LOG = process.env.AI_BATTERY_DEBUG_LOG || process.env.CLAUDEX_BATTERY_DEBUG_LOG || "";
|
|
14
|
-
const DEFAULT_COLUMN_GUARD = 4;
|
|
15
|
-
const DEFAULT_LEFT_PADDING = 2;
|
|
16
|
-
const DEFAULT_CODEX_OVERLAY_BOTTOM_OFFSET = 1;
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
fs.
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
if (!
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
const
|
|
96
|
-
|
|
97
|
-
if (names.some((name) => name.includes("
|
|
98
|
-
return "
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
const
|
|
104
|
-
const
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
const
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
return
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
function
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
return null;
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
}
|
|
197
|
-
|
|
2
|
+
|
|
3
|
+
import { spawn } from "node:child_process";
|
|
4
|
+
import fs from "node:fs";
|
|
5
|
+
import path from "node:path";
|
|
6
|
+
import { fileURLToPath } from "node:url";
|
|
7
|
+
|
|
8
|
+
const SCRIPT_DIR = path.dirname(fileURLToPath(import.meta.url));
|
|
9
|
+
const BATTERY_BIN = process.env.AI_BATTERY_BIN
|
|
10
|
+
|| process.env.CLAUDEX_BATTERY_BIN
|
|
11
|
+
|| path.join(SCRIPT_DIR, "ai-battery.js");
|
|
12
|
+
const ANSI_RE = /\u001b\[[0-?]*[ -/]*[@-~]/g;
|
|
13
|
+
const DEBUG_LOG = process.env.AI_BATTERY_DEBUG_LOG || process.env.CLAUDEX_BATTERY_DEBUG_LOG || "";
|
|
14
|
+
const DEFAULT_COLUMN_GUARD = 4;
|
|
15
|
+
const DEFAULT_LEFT_PADDING = 2;
|
|
16
|
+
const DEFAULT_CODEX_OVERLAY_BOTTOM_OFFSET = 1;
|
|
17
|
+
const DEFAULT_VSCODE_CODEX_OVERLAY_BOTTOM_OFFSET = 2;
|
|
18
|
+
|
|
19
|
+
function usage() {
|
|
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...]
|
|
21
|
+
|
|
22
|
+
Runs COMMAND and keeps AI Battery on the terminal bottom row.
|
|
23
|
+
On Windows, the rowpty host (a native ConPTY host with a reserved bottom row) is preferred when its executable
|
|
24
|
+
is available; otherwise AI Battery falls back to a same-console overlay row.
|
|
25
|
+
--layout reserve additionally allows the legacy node-pty/ConPTY path when rowpty is missing.`);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function debugLog(event, details = {}) {
|
|
29
|
+
if (!DEBUG_LOG) return;
|
|
30
|
+
try {
|
|
31
|
+
fs.mkdirSync(path.dirname(DEBUG_LOG), { recursive: true });
|
|
32
|
+
fs.appendFileSync(DEBUG_LOG, `${JSON.stringify({
|
|
33
|
+
at: new Date().toISOString(),
|
|
34
|
+
event,
|
|
35
|
+
...details
|
|
36
|
+
})}\n`);
|
|
37
|
+
} catch {
|
|
38
|
+
// Debug logging must never interfere with launching Codex.
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function parseArgs(argv) {
|
|
43
|
+
const args = {
|
|
44
|
+
interval: Number(process.env.AI_BATTERY_INTERVAL || process.env.CLAUDEX_BATTERY_INTERVAL || 10),
|
|
45
|
+
barWidth: process.env.AI_BATTERY_BAR_WIDTH || process.env.CLAUDEX_BATTERY_BAR_WIDTH || "10",
|
|
46
|
+
provider: process.env.AI_BATTERY_PROVIDER || process.env.CLAUDEX_BATTERY_PROVIDER || "auto",
|
|
47
|
+
layout: process.env.AI_BATTERY_WIN_LAYOUT || process.env.CLAUDEX_BATTERY_WIN_LAYOUT || process.env.AI_BATTERY_LAYOUT || "auto",
|
|
48
|
+
leftPadding: Number(process.env.AI_BATTERY_LEFT_PADDING || process.env.CLAUDEX_BATTERY_LEFT_PADDING || DEFAULT_LEFT_PADDING),
|
|
49
|
+
command: []
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
for (let i = 0; i < argv.length; i += 1) {
|
|
53
|
+
const arg = argv[i];
|
|
54
|
+
if (arg === "-h" || arg === "--help") {
|
|
55
|
+
usage();
|
|
56
|
+
process.exit(0);
|
|
57
|
+
} else if (arg === "--interval") {
|
|
58
|
+
args.interval = Math.max(0.5, Number(argv[++i]) || args.interval);
|
|
59
|
+
} else if (arg === "--bar-width") {
|
|
60
|
+
args.barWidth = argv[++i] || args.barWidth;
|
|
61
|
+
} else if (arg === "--provider") {
|
|
62
|
+
args.provider = argv[++i] || args.provider;
|
|
63
|
+
if (!["auto", "all", "codex", "claude"].includes(args.provider)) {
|
|
64
|
+
throw new Error("--provider must be one of: auto, all, codex, claude");
|
|
65
|
+
}
|
|
66
|
+
} else if (arg === "--layout") {
|
|
67
|
+
args.layout = argv[++i] || args.layout;
|
|
68
|
+
if (!["auto", "reserve", "overlay"].includes(args.layout)) {
|
|
69
|
+
throw new Error("--layout must be one of: auto, reserve, overlay");
|
|
70
|
+
}
|
|
71
|
+
} else if (arg === "--left-padding") {
|
|
72
|
+
const value = Number(argv[++i]);
|
|
73
|
+
args.leftPadding = Number.isFinite(value)
|
|
74
|
+
? Math.max(0, Math.min(20, value))
|
|
75
|
+
: args.leftPadding;
|
|
76
|
+
} else if (arg === "--") {
|
|
77
|
+
args.command = argv.slice(i + 1);
|
|
78
|
+
break;
|
|
79
|
+
} else {
|
|
80
|
+
args.command = argv.slice(i);
|
|
81
|
+
break;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
if (!args.command.length) {
|
|
86
|
+
usage();
|
|
87
|
+
process.exit(2);
|
|
88
|
+
}
|
|
89
|
+
if (!Number.isFinite(args.interval)) args.interval = 10;
|
|
90
|
+
if (!["auto", "reserve", "overlay"].includes(args.layout)) args.layout = "auto";
|
|
91
|
+
return args;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
function inferProvider(command) {
|
|
95
|
+
const joined = command.join(" ").toLowerCase();
|
|
96
|
+
const names = command.map((part) => path.basename(part).toLowerCase());
|
|
97
|
+
if (names.some((name) => name.includes("codex")) || joined.includes("@openai/codex")) return "codex";
|
|
98
|
+
if (names.some((name) => name.includes("claude")) || joined.includes("@anthropic-ai/claude-code")) return "claude";
|
|
99
|
+
return "all";
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
function termSize() {
|
|
103
|
+
const windowSize = process.stdout.getWindowSize?.();
|
|
104
|
+
const cols = process.stdout.columns || windowSize?.[0] || 80;
|
|
105
|
+
const rows = process.stdout.rows || windowSize?.[1] || 24;
|
|
106
|
+
return {
|
|
107
|
+
cols: Math.max(20, cols),
|
|
108
|
+
rows: Math.max(1, rows)
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
function columnGuard() {
|
|
113
|
+
const raw = process.env.AI_BATTERY_COLUMN_GUARD || process.env.CLAUDEX_BATTERY_COLUMN_GUARD;
|
|
114
|
+
const value = Number(raw);
|
|
115
|
+
return Number.isFinite(value) ? Math.max(0, Math.min(20, Math.floor(value))) : DEFAULT_COLUMN_GUARD;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
function overlayBottomOffset(activeProvider) {
|
|
119
|
+
const raw = Number(process.env.AI_BATTERY_OVERLAY_BOTTOM_OFFSET || process.env.CLAUDEX_BATTERY_OVERLAY_BOTTOM_OFFSET);
|
|
120
|
+
if (Number.isFinite(raw)) return Math.max(0, Math.min(5, Math.floor(raw)));
|
|
121
|
+
if (activeProvider !== "codex") return 0;
|
|
122
|
+
return isVsCodeTerminal()
|
|
123
|
+
? DEFAULT_VSCODE_CODEX_OVERLAY_BOTTOM_OFFSET
|
|
124
|
+
: DEFAULT_CODEX_OVERLAY_BOTTOM_OFFSET;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
function statusRow(rows, bottomOffset = 0) {
|
|
128
|
+
const safeRows = Math.max(1, Number(rows) || 1);
|
|
129
|
+
const safeOffset = Math.max(0, Math.min(5, Math.floor(Number(bottomOffset) || 0)));
|
|
130
|
+
return Math.max(1, safeRows - safeOffset);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
function isVsCodeTerminal() {
|
|
134
|
+
return String(process.env.TERM_PROGRAM || "").toLowerCase() === "vscode"
|
|
135
|
+
|| Boolean(process.env.VSCODE_INJECTION);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
function stripAnsi(text) {
|
|
139
|
+
return String(text).replace(ANSI_RE, "");
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
function fitAnsi(text, width, pad = true) {
|
|
143
|
+
const plain = stripAnsi(text);
|
|
144
|
+
if (plain.length <= width) return text + (pad ? " ".repeat(width - plain.length) : "");
|
|
145
|
+
const suffix = pad ? " " : "";
|
|
146
|
+
return plain.slice(0, Math.max(0, width - suffix.length)) + suffix;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
function batteryCommand(args, activeProvider, maxWidth) {
|
|
150
|
+
const command = [
|
|
151
|
+
process.execPath,
|
|
152
|
+
BATTERY_BIN,
|
|
153
|
+
"--muted",
|
|
154
|
+
"--bar-width",
|
|
155
|
+
String(args.barWidth),
|
|
156
|
+
"--max-width",
|
|
157
|
+
String(maxWidth),
|
|
158
|
+
"--left-padding",
|
|
159
|
+
String(args.leftPadding)
|
|
160
|
+
];
|
|
161
|
+
if (activeProvider === "codex" || activeProvider === "claude") {
|
|
162
|
+
command.push("--active-provider", activeProvider);
|
|
163
|
+
}
|
|
164
|
+
if (args.provider !== "all") {
|
|
165
|
+
command.push("--provider", args.provider);
|
|
166
|
+
}
|
|
167
|
+
return command;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
function statusOutputText(stdout) {
|
|
171
|
+
return String(stdout || "").replace(/[\r\n]+$/g, "");
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
function rowptyExePath() {
|
|
175
|
+
const explicit = process.env.AI_BATTERY_ROWPTY || process.env.CLAUDEX_BATTERY_ROWPTY;
|
|
176
|
+
if (explicit) return fs.existsSync(explicit) ? explicit : null;
|
|
177
|
+
const candidates = [];
|
|
178
|
+
if (process.env.LOCALAPPDATA) {
|
|
179
|
+
candidates.push(path.join(process.env.LOCALAPPDATA, "ai-battery", "bin", "rowpty.exe"));
|
|
180
|
+
}
|
|
181
|
+
candidates.push(path.join(SCRIPT_DIR, "..", "..", "rowpty", "bin", "rowpty.exe"));
|
|
182
|
+
for (const candidate of candidates) {
|
|
183
|
+
if (fs.existsSync(candidate)) return candidate;
|
|
184
|
+
}
|
|
185
|
+
return null;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
function quoteWindowsCommandLineArg(value) {
|
|
189
|
+
const text = String(value ?? "");
|
|
190
|
+
if (text.length && !/[ \t"]/.test(text)) return text;
|
|
191
|
+
let quoted = "\"";
|
|
192
|
+
let backslashes = 0;
|
|
193
|
+
for (const ch of text) {
|
|
194
|
+
if (ch === "\\") {
|
|
195
|
+
backslashes += 1;
|
|
196
|
+
} else if (ch === "\"") {
|
|
197
|
+
quoted += "\\".repeat(backslashes * 2 + 1) + "\"";
|
|
198
|
+
backslashes = 0;
|
|
199
|
+
} else {
|
|
200
|
+
quoted += "\\".repeat(backslashes) + ch;
|
|
201
|
+
backslashes = 0;
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
return quoted + "\\".repeat(backslashes * 2) + "\"";
|
|
205
|
+
}
|
|
206
|
+
|
|
198
207
|
function rowptyStatusCommand(args, activeProvider) {
|
|
199
208
|
// rowpty substitutes {MAXWIDTH} with (cols - 4) before each status run.
|
|
200
209
|
return batteryCommand(args, activeProvider, "{MAXWIDTH}")
|
|
@@ -228,13 +237,13 @@ function runRowPty(args, activeProvider) {
|
|
|
228
237
|
const exe = rowptyExePath();
|
|
229
238
|
if (!exe) {
|
|
230
239
|
debugLog("rowpty:missing");
|
|
231
|
-
return Promise.resolve(null);
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
const command = windowsCommand(args.command);
|
|
235
|
-
const hostArgs = [
|
|
236
|
-
"--interval", String(Math.max(0.5, args.interval)),
|
|
237
|
-
"--reserve", "1",
|
|
240
|
+
return Promise.resolve(null);
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
const command = windowsCommand(args.command);
|
|
244
|
+
const hostArgs = [
|
|
245
|
+
"--interval", String(Math.max(0.5, args.interval)),
|
|
246
|
+
"--reserve", "1",
|
|
238
247
|
"--status-cmd", rowptyStatusCommand(args, activeProvider),
|
|
239
248
|
"--", command.file, ...command.args
|
|
240
249
|
];
|
|
@@ -246,467 +255,468 @@ function runRowPty(args, activeProvider) {
|
|
|
246
255
|
env,
|
|
247
256
|
windowsHide: false
|
|
248
257
|
});
|
|
249
|
-
|
|
250
|
-
return new Promise((resolve) => {
|
|
251
|
-
child.on("exit", (code, signal) => {
|
|
252
|
-
debugLog("rowpty:exit", { code, signal });
|
|
253
|
-
resolve(code ?? (signal ? 1 : 0));
|
|
254
|
-
});
|
|
255
|
-
child.on("error", (error) => {
|
|
256
|
-
debugLog("rowpty:error", { error: error.message });
|
|
257
|
-
resolve(null);
|
|
258
|
-
});
|
|
259
|
-
});
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
function conPtyBackspaceMode() {
|
|
263
|
-
// Windows Terminal sends 0x7f for Backspace and 0x08 for Ctrl+Backspace.
|
|
264
|
-
// Rewriting DEL to BS makes TUIs (Codex, Claude Code) treat every
|
|
265
|
-
// Backspace as delete-word, so keys pass through untouched by default.
|
|
266
|
-
const mode = String(process.env.AI_BATTERY_CONPTY_BACKSPACE || process.env.CLAUDEX_BATTERY_CONPTY_BACKSPACE || "passthrough").toLowerCase();
|
|
267
|
-
return ["bs", "del", "passthrough"].includes(mode) ? mode : "passthrough";
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
function normalizeConPtyInput(data, mode = conPtyBackspaceMode()) {
|
|
271
|
-
const text = Buffer.isBuffer(data) ? data.toString("utf8") : String(data || "");
|
|
272
|
-
if (mode === "passthrough" || mode === "del") return text;
|
|
273
|
-
return text.replace(/\x7f/g, "\x08");
|
|
274
|
-
}
|
|
275
|
-
|
|
276
|
-
function conPtyRepaintIntervalMs() {
|
|
277
|
-
const raw = Number(process.env.AI_BATTERY_CONPTY_REPAINT_MS || process.env.CLAUDEX_BATTERY_CONPTY_REPAINT_MS);
|
|
278
|
-
if (Number.isFinite(raw)) return Math.max(250, Math.min(5000, Math.floor(raw)));
|
|
279
|
-
return 1000;
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
function outputMayClearDisplay(data) {
|
|
283
|
-
const text = Buffer.isBuffer(data) ? data.toString("utf8") : String(data || "");
|
|
284
|
-
return /\x1bc|\x1b\[[0-?]*[23]J|\x1b\[\?1049[hl]/.test(text);
|
|
285
|
-
}
|
|
286
|
-
|
|
287
|
-
function scheduleRepaintBurst(status, timers) {
|
|
288
|
-
for (const delayMs of [0, 80, 250, 700, 1400]) {
|
|
289
|
-
const timer = setTimeout(() => {
|
|
290
|
-
timers.delete(timer);
|
|
291
|
-
status.paint(true);
|
|
292
|
-
}, delayMs);
|
|
293
|
-
timers.add(timer);
|
|
294
|
-
}
|
|
295
|
-
}
|
|
296
|
-
|
|
297
|
-
class StatusLine {
|
|
298
|
-
constructor(args, activeProvider, options = {}) {
|
|
299
|
-
this.args = args;
|
|
300
|
-
this.activeProvider = activeProvider;
|
|
301
|
-
this.bottomOffset = options.bottomOffset ?? 0;
|
|
302
|
-
this.text = "AI Battery starting...";
|
|
303
|
-
this.nextFetch = 0;
|
|
304
|
-
this.lastLine = "";
|
|
305
|
-
this.lastDraw = 0;
|
|
306
|
-
this.refreshInFlight = false;
|
|
307
|
-
this.refreshQueued = false;
|
|
308
|
-
this.disposed = false;
|
|
309
|
-
this.onRefresh = null;
|
|
310
|
-
this.resize();
|
|
311
|
-
}
|
|
312
|
-
|
|
313
|
-
resize() {
|
|
314
|
-
const size = termSize();
|
|
315
|
-
this.cols = size.cols;
|
|
316
|
-
this.rows = size.rows;
|
|
317
|
-
}
|
|
318
|
-
|
|
319
|
-
kickRefresh(force = false) {
|
|
320
|
-
if (this.disposed) return;
|
|
321
|
-
const now = Date.now();
|
|
322
|
-
if (!force && now < this.nextFetch) return;
|
|
323
|
-
if (this.refreshInFlight) {
|
|
324
|
-
this.refreshQueued = this.refreshQueued || force;
|
|
325
|
-
return;
|
|
326
|
-
}
|
|
327
|
-
|
|
328
|
-
this.refreshInFlight = true;
|
|
329
|
-
this.nextFetch = now + (this.args.interval * 1000);
|
|
330
|
-
const maxWidth = Math.max(20, this.cols - columnGuard());
|
|
331
|
-
const command = batteryCommand(this.args, this.activeProvider, maxWidth);
|
|
332
|
-
const child = spawn(command[0], command.slice(1), {
|
|
333
|
-
stdio: ["ignore", "pipe", "ignore"],
|
|
334
|
-
windowsHide: true
|
|
335
|
-
});
|
|
336
|
-
|
|
337
|
-
let stdout = "";
|
|
338
|
-
const timeout = setTimeout(() => child.kill(), 1500);
|
|
339
|
-
child.stdout?.setEncoding("utf8");
|
|
340
|
-
child.stdout?.on("data", (chunk) => {
|
|
341
|
-
stdout += chunk;
|
|
342
|
-
if (stdout.length > 64 * 1024) child.kill();
|
|
343
|
-
});
|
|
344
|
-
|
|
345
|
-
let settled = false;
|
|
346
|
-
const finish = (status) => {
|
|
347
|
-
if (settled) return;
|
|
348
|
-
settled = true;
|
|
349
|
-
clearTimeout(timeout);
|
|
350
|
-
this.refreshInFlight = false;
|
|
351
|
-
if (this.disposed) return;
|
|
352
|
-
const text = statusOutputText(stdout);
|
|
353
|
-
const changed = status === 0 && text && text !== this.text;
|
|
354
|
-
if (changed) {
|
|
355
|
-
this.text = text;
|
|
356
|
-
if (typeof this.onRefresh === "function") {
|
|
357
|
-
this.onRefresh();
|
|
358
|
-
} else {
|
|
359
|
-
this.paint(true);
|
|
360
|
-
}
|
|
361
|
-
}
|
|
362
|
-
if (this.refreshQueued) {
|
|
363
|
-
this.refreshQueued = false;
|
|
364
|
-
this.kickRefresh(true);
|
|
365
|
-
}
|
|
366
|
-
};
|
|
367
|
-
|
|
368
|
-
child.on("close", finish);
|
|
369
|
-
child.on("error", () => finish(1));
|
|
370
|
-
}
|
|
371
|
-
|
|
372
|
-
paint(force = false) {
|
|
373
|
-
if (this.disposed) return;
|
|
374
|
-
const now = Date.now();
|
|
375
|
-
if (!force && now - this.lastDraw < 150) return;
|
|
376
|
-
const width = Math.max(1, this.cols - 1);
|
|
377
|
-
const row = statusRow(this.rows, this.bottomOffset);
|
|
378
|
-
const line = fitAnsi(this.text, width, true);
|
|
379
|
-
if (!force && line === this.lastLine) return;
|
|
380
|
-
this.lastLine = line;
|
|
381
|
-
this.lastDraw = now;
|
|
382
|
-
process.stdout.write(`\x1b7\x1b[0m\x1b[${row};1H\r\x1b[1G${line}\x1b[K\x1b[0m\x1b8`);
|
|
383
|
-
}
|
|
384
|
-
|
|
385
|
-
draw(force = false) {
|
|
386
|
-
this.kickRefresh(force);
|
|
387
|
-
this.paint(force);
|
|
388
|
-
}
|
|
389
|
-
|
|
390
|
-
clear() {
|
|
391
|
-
this.disposed = true;
|
|
392
|
-
const row = statusRow(this.rows, this.bottomOffset);
|
|
393
|
-
process.stdout.write(`\x1b7\x1b[0m\x1b[${row};1H\r\x1b[1G\x1b[2K\x1b8`);
|
|
394
|
-
}
|
|
395
|
-
}
|
|
396
|
-
|
|
397
|
-
function normalizeWindowsCommandPath(value) {
|
|
398
|
-
let text = String(value || "").trim();
|
|
399
|
-
for (let i = 0; i < 6; i += 1) {
|
|
400
|
-
const before = text;
|
|
401
|
-
text = text.replace(/\\"/g, "\"").trim();
|
|
402
|
-
if (
|
|
403
|
-
(text.startsWith("\"") && text.endsWith("\""))
|
|
404
|
-
|| (text.startsWith("'") && text.endsWith("'"))
|
|
405
|
-
) {
|
|
406
|
-
text = text.slice(1, -1).trim();
|
|
407
|
-
}
|
|
408
|
-
if (text === before) break;
|
|
409
|
-
}
|
|
410
|
-
return text;
|
|
411
|
-
}
|
|
412
|
-
|
|
413
|
-
function resolveWindowsCommandFile(commandPath) {
|
|
414
|
-
commandPath = normalizeWindowsCommandPath(commandPath);
|
|
415
|
-
if (path.extname(commandPath)) return commandPath;
|
|
416
|
-
for (const suffix of [".cmd", ".exe", ".bat", ".ps1"]) {
|
|
417
|
-
const candidate = `${commandPath}${suffix}`;
|
|
418
|
-
if (fs.existsSync(candidate)) return candidate;
|
|
419
|
-
}
|
|
420
|
-
return commandPath;
|
|
421
|
-
}
|
|
422
|
-
|
|
423
|
-
function windowsCommand(command) {
|
|
424
|
-
const exe = resolveWindowsCommandFile(command[0]);
|
|
425
|
-
const rest = command.slice(1);
|
|
426
|
-
if (/\.(cmd|bat)$/i.test(exe)) {
|
|
427
|
-
return {
|
|
428
|
-
file: "cmd.exe",
|
|
429
|
-
args: ["/d", "/s", "/c", "call", exe, ...rest]
|
|
430
|
-
};
|
|
431
|
-
}
|
|
432
|
-
if (/\.ps1$/i.test(exe)) {
|
|
433
|
-
return {
|
|
434
|
-
file: "powershell.exe",
|
|
435
|
-
args: ["-NoProfile", "-ExecutionPolicy", "Bypass", "-File", exe, ...rest]
|
|
436
|
-
};
|
|
437
|
-
}
|
|
438
|
-
if (/\.(js|mjs|cjs)$/i.test(exe)) {
|
|
439
|
-
return {
|
|
440
|
-
file: process.execPath,
|
|
441
|
-
args: [exe, ...rest]
|
|
442
|
-
};
|
|
443
|
-
}
|
|
444
|
-
return { file: exe, args: rest };
|
|
445
|
-
}
|
|
446
|
-
|
|
447
|
-
async function loadNodePty() {
|
|
448
|
-
try {
|
|
449
|
-
const mod = await import("node-pty");
|
|
450
|
-
debugLog("node-pty:loaded");
|
|
451
|
-
return mod.default ?? mod;
|
|
452
|
-
} catch (error) {
|
|
453
|
-
debugLog("node-pty:missing", { error: error.message });
|
|
454
|
-
return null;
|
|
455
|
-
}
|
|
456
|
-
}
|
|
457
|
-
|
|
458
|
-
async function runConPty(args, activeProvider) {
|
|
459
|
-
// Nested ConPTY (node-pty) breaks host-terminal scrollback and can stall
|
|
460
|
-
// child output until the next keypress, so it is opt-in via --layout reserve.
|
|
461
|
-
if (args.layout !== "reserve") {
|
|
462
|
-
debugLog("conpty:skipped", { reason: `layout ${args.layout}` });
|
|
463
|
-
return null;
|
|
464
|
-
}
|
|
465
|
-
|
|
466
|
-
const pty = await loadNodePty();
|
|
467
|
-
if (!pty || !process.stdin.isTTY || !process.stdout.isTTY) {
|
|
468
|
-
debugLog("conpty:unavailable", {
|
|
469
|
-
hasPty: Boolean(pty),
|
|
470
|
-
stdinTty: Boolean(process.stdin.isTTY),
|
|
471
|
-
stdoutTty: Boolean(process.stdout.isTTY)
|
|
472
|
-
});
|
|
473
|
-
if (!process.stdin.isTTY || !process.stdout.isTTY) return null;
|
|
474
|
-
console.error("ai-battery-run-win: ConPTY reserve layout is unavailable in this terminal.");
|
|
475
|
-
return 2;
|
|
476
|
-
}
|
|
477
|
-
|
|
478
|
-
const status = new StatusLine(args, activeProvider);
|
|
479
|
-
const size = termSize();
|
|
480
|
-
const childRows = Math.max(1, size.rows - 1);
|
|
481
|
-
const command = windowsCommand(args.command);
|
|
482
|
-
debugLog("conpty:start", {
|
|
483
|
-
size,
|
|
484
|
-
childRows,
|
|
485
|
-
command,
|
|
486
|
-
stdoutColumns: process.stdout.columns,
|
|
487
|
-
stdoutRows: process.stdout.rows,
|
|
488
|
-
windowSize: process.stdout.getWindowSize?.() || null,
|
|
489
|
-
wtSession: Boolean(process.env.WT_SESSION)
|
|
490
|
-
});
|
|
491
|
-
const term = pty.spawn(command.file, command.args, {
|
|
492
|
-
name: "xterm-256color",
|
|
493
|
-
cols: size.cols,
|
|
494
|
-
rows: childRows,
|
|
495
|
-
cwd: process.cwd(),
|
|
496
|
-
env: process.env
|
|
497
|
-
});
|
|
498
|
-
|
|
499
|
-
const oldRaw = process.stdin.isRaw;
|
|
500
|
-
process.stdin.setRawMode?.(true);
|
|
501
|
-
process.stdin.resume();
|
|
502
|
-
const onInput = (data) => term.write(normalizeConPtyInput(data));
|
|
503
|
-
process.stdin.on("data", onInput);
|
|
504
|
-
|
|
505
|
-
let drawTimer = null;
|
|
506
|
-
let drawForce = false;
|
|
507
|
-
const scheduleDraw = (force = false, delayMs = 45) => {
|
|
508
|
-
drawForce = drawForce || force;
|
|
509
|
-
if (drawTimer) return;
|
|
510
|
-
drawTimer = setTimeout(() => {
|
|
511
|
-
drawTimer = null;
|
|
512
|
-
const forceNow = drawForce;
|
|
513
|
-
drawForce = false;
|
|
514
|
-
status.draw(forceNow);
|
|
515
|
-
}, delayMs);
|
|
516
|
-
};
|
|
517
|
-
status.onRefresh = () => scheduleDraw(true, 45);
|
|
518
|
-
|
|
519
|
-
const timers = new Set();
|
|
520
|
-
const timer = setInterval(() => scheduleDraw(false), Math.max(500, args.interval * 1000));
|
|
521
|
-
const repaintTimer = setInterval(() => status.paint(true), conPtyRepaintIntervalMs());
|
|
522
|
-
const onResize = () => {
|
|
523
|
-
status.resize();
|
|
524
|
-
term.resize(status.cols, Math.max(1, status.rows - 1));
|
|
525
|
-
scheduleDraw(true, 0);
|
|
526
|
-
scheduleRepaintBurst(status, timers);
|
|
527
|
-
};
|
|
528
|
-
process.stdout.on("resize", onResize);
|
|
529
|
-
|
|
530
|
-
const clearConPtyTimers = () => {
|
|
531
|
-
clearInterval(timer);
|
|
532
|
-
clearInterval(repaintTimer);
|
|
533
|
-
if (drawTimer) clearTimeout(drawTimer);
|
|
534
|
-
for (const timer of timers) clearTimeout(timer);
|
|
535
|
-
timers.clear();
|
|
536
|
-
};
|
|
537
|
-
|
|
538
|
-
return await new Promise((resolve) => {
|
|
539
|
-
term.onData((data) => {
|
|
540
|
-
process.stdout.write(data);
|
|
541
|
-
if (outputMayClearDisplay(data)) scheduleRepaintBurst(status, timers);
|
|
542
|
-
scheduleDraw(false);
|
|
543
|
-
});
|
|
544
|
-
term.onExit(({ exitCode }) => {
|
|
545
|
-
debugLog("conpty:exit", { exitCode });
|
|
546
|
-
clearConPtyTimers();
|
|
547
|
-
process.stdout.off("resize", onResize);
|
|
548
|
-
process.stdin.off("data", onInput);
|
|
549
|
-
process.stdin.setRawMode?.(oldRaw);
|
|
550
|
-
status.clear();
|
|
551
|
-
resolve(exitCode ?? 0);
|
|
552
|
-
});
|
|
553
|
-
scheduleDraw(true, 0);
|
|
554
|
-
scheduleRepaintBurst(status, timers);
|
|
555
|
-
});
|
|
556
|
-
}
|
|
557
|
-
|
|
558
|
-
function overlayInitialDelayMs() {
|
|
559
|
-
const raw = Number(process.env.AI_BATTERY_OVERLAY_INITIAL_DELAY_MS || process.env.CLAUDEX_BATTERY_OVERLAY_INITIAL_DELAY_MS);
|
|
560
|
-
if (Number.isFinite(raw)) return Math.max(0, Math.min(5000, Math.floor(raw)));
|
|
561
|
-
return 1200;
|
|
562
|
-
}
|
|
563
|
-
|
|
564
|
-
function overlayRepaintIntervalMs() {
|
|
565
|
-
const raw = Number(process.env.AI_BATTERY_OVERLAY_REPAINT_MS || process.env.CLAUDEX_BATTERY_OVERLAY_REPAINT_MS);
|
|
566
|
-
if (Number.isFinite(raw)) return Math.max(250, Math.min(5000, Math.floor(raw)));
|
|
567
|
-
return 1000;
|
|
568
|
-
}
|
|
569
|
-
|
|
570
|
-
function scheduleOverlayRepaintBurst(status, timers) {
|
|
571
|
-
scheduleRepaintBurst(status, timers);
|
|
572
|
-
}
|
|
573
|
-
|
|
574
|
-
function runOverlay(args, activeProvider) {
|
|
575
|
-
if (!process.stdin.isTTY || !process.stdout.isTTY) {
|
|
576
|
-
debugLog("overlay:unavailable", {
|
|
577
|
-
stdinTty: Boolean(process.stdin.isTTY),
|
|
578
|
-
stdoutTty: Boolean(process.stdout.isTTY)
|
|
579
|
-
});
|
|
580
|
-
console.error("ai-battery-run-win: stdin/stdout is not a real terminal.");
|
|
581
|
-
return 2;
|
|
582
|
-
}
|
|
583
|
-
|
|
584
|
-
const status = new StatusLine(args, activeProvider, {
|
|
585
|
-
bottomOffset: overlayBottomOffset(activeProvider)
|
|
586
|
-
});
|
|
587
|
-
const command = windowsCommand(args.command);
|
|
588
|
-
debugLog("overlay:start", {
|
|
589
|
-
size: termSize(),
|
|
590
|
-
command,
|
|
591
|
-
bottomOffset: status.bottomOffset,
|
|
592
|
-
initialDelayMs: overlayInitialDelayMs(),
|
|
593
|
-
stdoutColumns: process.stdout.columns,
|
|
594
|
-
stdoutRows: process.stdout.rows,
|
|
595
|
-
windowSize: process.stdout.getWindowSize?.() || null,
|
|
596
|
-
wtSession: Boolean(process.env.WT_SESSION)
|
|
597
|
-
});
|
|
598
|
-
const child = spawn(command.file, command.args, {
|
|
599
|
-
stdio: "inherit",
|
|
600
|
-
cwd: process.cwd(),
|
|
601
|
-
env: process.env,
|
|
602
|
-
windowsHide: false
|
|
603
|
-
});
|
|
604
|
-
|
|
605
|
-
const timers = new Set();
|
|
606
|
-
const refreshTimer = setInterval(() => status.draw(false), Math.max(1000, args.interval * 1000));
|
|
607
|
-
const repaintTimer = setInterval(() => status.paint(true), overlayRepaintIntervalMs());
|
|
608
|
-
const onResize = () => {
|
|
609
|
-
status.resize();
|
|
610
|
-
status.draw(true);
|
|
611
|
-
scheduleOverlayRepaintBurst(status, timers);
|
|
612
|
-
};
|
|
613
|
-
process.stdout.on("resize", onResize);
|
|
614
|
-
const firstDraw = setTimeout(() => {
|
|
615
|
-
status.draw(true);
|
|
616
|
-
scheduleOverlayRepaintBurst(status, timers);
|
|
617
|
-
}, overlayInitialDelayMs());
|
|
618
|
-
timers.add(firstDraw);
|
|
619
|
-
|
|
620
|
-
const clearOverlayTimers = () => {
|
|
621
|
-
clearInterval(refreshTimer);
|
|
622
|
-
clearInterval(repaintTimer);
|
|
623
|
-
for (const timer of timers) clearTimeout(timer);
|
|
624
|
-
timers.clear();
|
|
625
|
-
};
|
|
626
|
-
|
|
627
|
-
return new Promise((resolve) => {
|
|
628
|
-
child.on("exit", (code, signal) => {
|
|
629
|
-
debugLog("overlay:exit", { code, signal });
|
|
630
|
-
clearOverlayTimers();
|
|
631
|
-
process.stdout.off("resize", onResize);
|
|
632
|
-
status.clear();
|
|
633
|
-
resolve(code ?? (signal ? 1 : 0));
|
|
634
|
-
});
|
|
635
|
-
child.on("error", (error) => {
|
|
636
|
-
debugLog("overlay:error", { error: error.message });
|
|
637
|
-
clearOverlayTimers();
|
|
638
|
-
process.stdout.off("resize", onResize);
|
|
639
|
-
status.clear();
|
|
640
|
-
console.error(`ai-battery-run-win: ${error.message}`);
|
|
641
|
-
resolve(1);
|
|
642
|
-
});
|
|
643
|
-
});
|
|
644
|
-
}
|
|
645
|
-
|
|
646
|
-
function runPlain(args) {
|
|
647
|
-
const command = windowsCommand(args.command);
|
|
648
|
-
debugLog("plain:start", { command });
|
|
649
|
-
const child = spawn(command.file, command.args, {
|
|
650
|
-
stdio: "inherit",
|
|
651
|
-
cwd: process.cwd(),
|
|
652
|
-
env: process.env,
|
|
653
|
-
windowsHide: false
|
|
654
|
-
});
|
|
655
|
-
|
|
656
|
-
return new Promise((resolve) => {
|
|
657
|
-
child.on("exit", (code, signal) => {
|
|
658
|
-
debugLog("plain:exit", { code, signal });
|
|
659
|
-
resolve(code ?? (signal ? 1 : 0));
|
|
660
|
-
});
|
|
661
|
-
child.on("error", (error) => {
|
|
662
|
-
debugLog("plain:error", { error: error.message });
|
|
663
|
-
console.error(`ai-battery-run-win: ${error.message}`);
|
|
664
|
-
resolve(1);
|
|
665
|
-
});
|
|
666
|
-
});
|
|
667
|
-
}
|
|
668
|
-
|
|
669
|
-
async function main() {
|
|
670
|
-
if (process.platform !== "win32") {
|
|
671
|
-
console.error("ai-battery-run-win is only for native Windows.");
|
|
672
|
-
process.exit(2);
|
|
673
|
-
}
|
|
674
|
-
|
|
675
|
-
const args = parseArgs(process.argv.slice(2));
|
|
676
|
-
const commandProvider = inferProvider(args.command);
|
|
677
|
-
if (args.provider === "auto") args.provider = commandProvider;
|
|
678
|
-
const activeProvider = ["codex", "claude"].includes(commandProvider) ? commandProvider : null;
|
|
679
|
-
debugLog("main:start", {
|
|
680
|
-
argv: process.argv.slice(2),
|
|
681
|
-
provider: args.provider,
|
|
682
|
-
layout: args.layout,
|
|
683
|
-
commandProvider,
|
|
684
|
-
activeProvider,
|
|
685
|
-
stdinTty: Boolean(process.stdin.isTTY),
|
|
686
|
-
stdoutTty: Boolean(process.stdout.isTTY)
|
|
687
|
-
});
|
|
688
|
-
|
|
689
|
-
let exitCode = null;
|
|
690
|
-
if (args.layout !== "overlay") {
|
|
691
|
-
exitCode = await runRowPty(args, activeProvider);
|
|
692
|
-
if (exitCode === null) exitCode = await runConPty(args, activeProvider);
|
|
693
|
-
}
|
|
694
|
-
if (exitCode === null) {
|
|
695
|
-
exitCode = process.stdin.isTTY && process.stdout.isTTY
|
|
696
|
-
? await runOverlay(args, activeProvider)
|
|
697
|
-
: await runPlain(args);
|
|
698
|
-
}
|
|
699
|
-
process.exit(exitCode);
|
|
700
|
-
}
|
|
701
|
-
|
|
702
|
-
export {
|
|
703
|
-
conPtyBackspaceMode,
|
|
704
|
-
conPtyRepaintIntervalMs,
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
258
|
+
|
|
259
|
+
return new Promise((resolve) => {
|
|
260
|
+
child.on("exit", (code, signal) => {
|
|
261
|
+
debugLog("rowpty:exit", { code, signal });
|
|
262
|
+
resolve(code ?? (signal ? 1 : 0));
|
|
263
|
+
});
|
|
264
|
+
child.on("error", (error) => {
|
|
265
|
+
debugLog("rowpty:error", { error: error.message });
|
|
266
|
+
resolve(null);
|
|
267
|
+
});
|
|
268
|
+
});
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
function conPtyBackspaceMode() {
|
|
272
|
+
// Windows Terminal sends 0x7f for Backspace and 0x08 for Ctrl+Backspace.
|
|
273
|
+
// Rewriting DEL to BS makes TUIs (Codex, Claude Code) treat every
|
|
274
|
+
// Backspace as delete-word, so keys pass through untouched by default.
|
|
275
|
+
const mode = String(process.env.AI_BATTERY_CONPTY_BACKSPACE || process.env.CLAUDEX_BATTERY_CONPTY_BACKSPACE || "passthrough").toLowerCase();
|
|
276
|
+
return ["bs", "del", "passthrough"].includes(mode) ? mode : "passthrough";
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
function normalizeConPtyInput(data, mode = conPtyBackspaceMode()) {
|
|
280
|
+
const text = Buffer.isBuffer(data) ? data.toString("utf8") : String(data || "");
|
|
281
|
+
if (mode === "passthrough" || mode === "del") return text;
|
|
282
|
+
return text.replace(/\x7f/g, "\x08");
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
function conPtyRepaintIntervalMs() {
|
|
286
|
+
const raw = Number(process.env.AI_BATTERY_CONPTY_REPAINT_MS || process.env.CLAUDEX_BATTERY_CONPTY_REPAINT_MS);
|
|
287
|
+
if (Number.isFinite(raw)) return Math.max(250, Math.min(5000, Math.floor(raw)));
|
|
288
|
+
return 1000;
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
function outputMayClearDisplay(data) {
|
|
292
|
+
const text = Buffer.isBuffer(data) ? data.toString("utf8") : String(data || "");
|
|
293
|
+
return /\x1bc|\x1b\[[0-?]*[23]J|\x1b\[\?1049[hl]/.test(text);
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
function scheduleRepaintBurst(status, timers) {
|
|
297
|
+
for (const delayMs of [0, 80, 250, 700, 1400]) {
|
|
298
|
+
const timer = setTimeout(() => {
|
|
299
|
+
timers.delete(timer);
|
|
300
|
+
status.paint(true);
|
|
301
|
+
}, delayMs);
|
|
302
|
+
timers.add(timer);
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
class StatusLine {
|
|
307
|
+
constructor(args, activeProvider, options = {}) {
|
|
308
|
+
this.args = args;
|
|
309
|
+
this.activeProvider = activeProvider;
|
|
310
|
+
this.bottomOffset = options.bottomOffset ?? 0;
|
|
311
|
+
this.text = "AI Battery starting...";
|
|
312
|
+
this.nextFetch = 0;
|
|
313
|
+
this.lastLine = "";
|
|
314
|
+
this.lastDraw = 0;
|
|
315
|
+
this.refreshInFlight = false;
|
|
316
|
+
this.refreshQueued = false;
|
|
317
|
+
this.disposed = false;
|
|
318
|
+
this.onRefresh = null;
|
|
319
|
+
this.resize();
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
resize() {
|
|
323
|
+
const size = termSize();
|
|
324
|
+
this.cols = size.cols;
|
|
325
|
+
this.rows = size.rows;
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
kickRefresh(force = false) {
|
|
329
|
+
if (this.disposed) return;
|
|
330
|
+
const now = Date.now();
|
|
331
|
+
if (!force && now < this.nextFetch) return;
|
|
332
|
+
if (this.refreshInFlight) {
|
|
333
|
+
this.refreshQueued = this.refreshQueued || force;
|
|
334
|
+
return;
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
this.refreshInFlight = true;
|
|
338
|
+
this.nextFetch = now + (this.args.interval * 1000);
|
|
339
|
+
const maxWidth = Math.max(20, this.cols - columnGuard());
|
|
340
|
+
const command = batteryCommand(this.args, this.activeProvider, maxWidth);
|
|
341
|
+
const child = spawn(command[0], command.slice(1), {
|
|
342
|
+
stdio: ["ignore", "pipe", "ignore"],
|
|
343
|
+
windowsHide: true
|
|
344
|
+
});
|
|
345
|
+
|
|
346
|
+
let stdout = "";
|
|
347
|
+
const timeout = setTimeout(() => child.kill(), 1500);
|
|
348
|
+
child.stdout?.setEncoding("utf8");
|
|
349
|
+
child.stdout?.on("data", (chunk) => {
|
|
350
|
+
stdout += chunk;
|
|
351
|
+
if (stdout.length > 64 * 1024) child.kill();
|
|
352
|
+
});
|
|
353
|
+
|
|
354
|
+
let settled = false;
|
|
355
|
+
const finish = (status) => {
|
|
356
|
+
if (settled) return;
|
|
357
|
+
settled = true;
|
|
358
|
+
clearTimeout(timeout);
|
|
359
|
+
this.refreshInFlight = false;
|
|
360
|
+
if (this.disposed) return;
|
|
361
|
+
const text = statusOutputText(stdout);
|
|
362
|
+
const changed = status === 0 && text && text !== this.text;
|
|
363
|
+
if (changed) {
|
|
364
|
+
this.text = text;
|
|
365
|
+
if (typeof this.onRefresh === "function") {
|
|
366
|
+
this.onRefresh();
|
|
367
|
+
} else {
|
|
368
|
+
this.paint(true);
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
if (this.refreshQueued) {
|
|
372
|
+
this.refreshQueued = false;
|
|
373
|
+
this.kickRefresh(true);
|
|
374
|
+
}
|
|
375
|
+
};
|
|
376
|
+
|
|
377
|
+
child.on("close", finish);
|
|
378
|
+
child.on("error", () => finish(1));
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
paint(force = false) {
|
|
382
|
+
if (this.disposed) return;
|
|
383
|
+
const now = Date.now();
|
|
384
|
+
if (!force && now - this.lastDraw < 150) return;
|
|
385
|
+
const width = Math.max(1, this.cols - 1);
|
|
386
|
+
const row = statusRow(this.rows, this.bottomOffset);
|
|
387
|
+
const line = fitAnsi(this.text, width, true);
|
|
388
|
+
if (!force && line === this.lastLine) return;
|
|
389
|
+
this.lastLine = line;
|
|
390
|
+
this.lastDraw = now;
|
|
391
|
+
process.stdout.write(`\x1b7\x1b[0m\x1b[${row};1H\r\x1b[1G${line}\x1b[K\x1b[0m\x1b8`);
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
draw(force = false) {
|
|
395
|
+
this.kickRefresh(force);
|
|
396
|
+
this.paint(force);
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
clear() {
|
|
400
|
+
this.disposed = true;
|
|
401
|
+
const row = statusRow(this.rows, this.bottomOffset);
|
|
402
|
+
process.stdout.write(`\x1b7\x1b[0m\x1b[${row};1H\r\x1b[1G\x1b[2K\x1b8`);
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
function normalizeWindowsCommandPath(value) {
|
|
407
|
+
let text = String(value || "").trim();
|
|
408
|
+
for (let i = 0; i < 6; i += 1) {
|
|
409
|
+
const before = text;
|
|
410
|
+
text = text.replace(/\\"/g, "\"").trim();
|
|
411
|
+
if (
|
|
412
|
+
(text.startsWith("\"") && text.endsWith("\""))
|
|
413
|
+
|| (text.startsWith("'") && text.endsWith("'"))
|
|
414
|
+
) {
|
|
415
|
+
text = text.slice(1, -1).trim();
|
|
416
|
+
}
|
|
417
|
+
if (text === before) break;
|
|
418
|
+
}
|
|
419
|
+
return text;
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
function resolveWindowsCommandFile(commandPath) {
|
|
423
|
+
commandPath = normalizeWindowsCommandPath(commandPath);
|
|
424
|
+
if (path.extname(commandPath)) return commandPath;
|
|
425
|
+
for (const suffix of [".cmd", ".exe", ".bat", ".ps1"]) {
|
|
426
|
+
const candidate = `${commandPath}${suffix}`;
|
|
427
|
+
if (fs.existsSync(candidate)) return candidate;
|
|
428
|
+
}
|
|
429
|
+
return commandPath;
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
function windowsCommand(command) {
|
|
433
|
+
const exe = resolveWindowsCommandFile(command[0]);
|
|
434
|
+
const rest = command.slice(1);
|
|
435
|
+
if (/\.(cmd|bat)$/i.test(exe)) {
|
|
436
|
+
return {
|
|
437
|
+
file: "cmd.exe",
|
|
438
|
+
args: ["/d", "/s", "/c", "call", exe, ...rest]
|
|
439
|
+
};
|
|
440
|
+
}
|
|
441
|
+
if (/\.ps1$/i.test(exe)) {
|
|
442
|
+
return {
|
|
443
|
+
file: "powershell.exe",
|
|
444
|
+
args: ["-NoProfile", "-ExecutionPolicy", "Bypass", "-File", exe, ...rest]
|
|
445
|
+
};
|
|
446
|
+
}
|
|
447
|
+
if (/\.(js|mjs|cjs)$/i.test(exe)) {
|
|
448
|
+
return {
|
|
449
|
+
file: process.execPath,
|
|
450
|
+
args: [exe, ...rest]
|
|
451
|
+
};
|
|
452
|
+
}
|
|
453
|
+
return { file: exe, args: rest };
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
async function loadNodePty() {
|
|
457
|
+
try {
|
|
458
|
+
const mod = await import("node-pty");
|
|
459
|
+
debugLog("node-pty:loaded");
|
|
460
|
+
return mod.default ?? mod;
|
|
461
|
+
} catch (error) {
|
|
462
|
+
debugLog("node-pty:missing", { error: error.message });
|
|
463
|
+
return null;
|
|
464
|
+
}
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
async function runConPty(args, activeProvider) {
|
|
468
|
+
// Nested ConPTY (node-pty) breaks host-terminal scrollback and can stall
|
|
469
|
+
// child output until the next keypress, so it is opt-in via --layout reserve.
|
|
470
|
+
if (args.layout !== "reserve") {
|
|
471
|
+
debugLog("conpty:skipped", { reason: `layout ${args.layout}` });
|
|
472
|
+
return null;
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
const pty = await loadNodePty();
|
|
476
|
+
if (!pty || !process.stdin.isTTY || !process.stdout.isTTY) {
|
|
477
|
+
debugLog("conpty:unavailable", {
|
|
478
|
+
hasPty: Boolean(pty),
|
|
479
|
+
stdinTty: Boolean(process.stdin.isTTY),
|
|
480
|
+
stdoutTty: Boolean(process.stdout.isTTY)
|
|
481
|
+
});
|
|
482
|
+
if (!process.stdin.isTTY || !process.stdout.isTTY) return null;
|
|
483
|
+
console.error("ai-battery-run-win: ConPTY reserve layout is unavailable in this terminal.");
|
|
484
|
+
return 2;
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
const status = new StatusLine(args, activeProvider);
|
|
488
|
+
const size = termSize();
|
|
489
|
+
const childRows = Math.max(1, size.rows - 1);
|
|
490
|
+
const command = windowsCommand(args.command);
|
|
491
|
+
debugLog("conpty:start", {
|
|
492
|
+
size,
|
|
493
|
+
childRows,
|
|
494
|
+
command,
|
|
495
|
+
stdoutColumns: process.stdout.columns,
|
|
496
|
+
stdoutRows: process.stdout.rows,
|
|
497
|
+
windowSize: process.stdout.getWindowSize?.() || null,
|
|
498
|
+
wtSession: Boolean(process.env.WT_SESSION)
|
|
499
|
+
});
|
|
500
|
+
const term = pty.spawn(command.file, command.args, {
|
|
501
|
+
name: "xterm-256color",
|
|
502
|
+
cols: size.cols,
|
|
503
|
+
rows: childRows,
|
|
504
|
+
cwd: process.cwd(),
|
|
505
|
+
env: process.env
|
|
506
|
+
});
|
|
507
|
+
|
|
508
|
+
const oldRaw = process.stdin.isRaw;
|
|
509
|
+
process.stdin.setRawMode?.(true);
|
|
510
|
+
process.stdin.resume();
|
|
511
|
+
const onInput = (data) => term.write(normalizeConPtyInput(data));
|
|
512
|
+
process.stdin.on("data", onInput);
|
|
513
|
+
|
|
514
|
+
let drawTimer = null;
|
|
515
|
+
let drawForce = false;
|
|
516
|
+
const scheduleDraw = (force = false, delayMs = 45) => {
|
|
517
|
+
drawForce = drawForce || force;
|
|
518
|
+
if (drawTimer) return;
|
|
519
|
+
drawTimer = setTimeout(() => {
|
|
520
|
+
drawTimer = null;
|
|
521
|
+
const forceNow = drawForce;
|
|
522
|
+
drawForce = false;
|
|
523
|
+
status.draw(forceNow);
|
|
524
|
+
}, delayMs);
|
|
525
|
+
};
|
|
526
|
+
status.onRefresh = () => scheduleDraw(true, 45);
|
|
527
|
+
|
|
528
|
+
const timers = new Set();
|
|
529
|
+
const timer = setInterval(() => scheduleDraw(false), Math.max(500, args.interval * 1000));
|
|
530
|
+
const repaintTimer = setInterval(() => status.paint(true), conPtyRepaintIntervalMs());
|
|
531
|
+
const onResize = () => {
|
|
532
|
+
status.resize();
|
|
533
|
+
term.resize(status.cols, Math.max(1, status.rows - 1));
|
|
534
|
+
scheduleDraw(true, 0);
|
|
535
|
+
scheduleRepaintBurst(status, timers);
|
|
536
|
+
};
|
|
537
|
+
process.stdout.on("resize", onResize);
|
|
538
|
+
|
|
539
|
+
const clearConPtyTimers = () => {
|
|
540
|
+
clearInterval(timer);
|
|
541
|
+
clearInterval(repaintTimer);
|
|
542
|
+
if (drawTimer) clearTimeout(drawTimer);
|
|
543
|
+
for (const timer of timers) clearTimeout(timer);
|
|
544
|
+
timers.clear();
|
|
545
|
+
};
|
|
546
|
+
|
|
547
|
+
return await new Promise((resolve) => {
|
|
548
|
+
term.onData((data) => {
|
|
549
|
+
process.stdout.write(data);
|
|
550
|
+
if (outputMayClearDisplay(data)) scheduleRepaintBurst(status, timers);
|
|
551
|
+
scheduleDraw(false);
|
|
552
|
+
});
|
|
553
|
+
term.onExit(({ exitCode }) => {
|
|
554
|
+
debugLog("conpty:exit", { exitCode });
|
|
555
|
+
clearConPtyTimers();
|
|
556
|
+
process.stdout.off("resize", onResize);
|
|
557
|
+
process.stdin.off("data", onInput);
|
|
558
|
+
process.stdin.setRawMode?.(oldRaw);
|
|
559
|
+
status.clear();
|
|
560
|
+
resolve(exitCode ?? 0);
|
|
561
|
+
});
|
|
562
|
+
scheduleDraw(true, 0);
|
|
563
|
+
scheduleRepaintBurst(status, timers);
|
|
564
|
+
});
|
|
565
|
+
}
|
|
566
|
+
|
|
567
|
+
function overlayInitialDelayMs() {
|
|
568
|
+
const raw = Number(process.env.AI_BATTERY_OVERLAY_INITIAL_DELAY_MS || process.env.CLAUDEX_BATTERY_OVERLAY_INITIAL_DELAY_MS);
|
|
569
|
+
if (Number.isFinite(raw)) return Math.max(0, Math.min(5000, Math.floor(raw)));
|
|
570
|
+
return 1200;
|
|
571
|
+
}
|
|
572
|
+
|
|
573
|
+
function overlayRepaintIntervalMs() {
|
|
574
|
+
const raw = Number(process.env.AI_BATTERY_OVERLAY_REPAINT_MS || process.env.CLAUDEX_BATTERY_OVERLAY_REPAINT_MS);
|
|
575
|
+
if (Number.isFinite(raw)) return Math.max(250, Math.min(5000, Math.floor(raw)));
|
|
576
|
+
return 1000;
|
|
577
|
+
}
|
|
578
|
+
|
|
579
|
+
function scheduleOverlayRepaintBurst(status, timers) {
|
|
580
|
+
scheduleRepaintBurst(status, timers);
|
|
581
|
+
}
|
|
582
|
+
|
|
583
|
+
function runOverlay(args, activeProvider) {
|
|
584
|
+
if (!process.stdin.isTTY || !process.stdout.isTTY) {
|
|
585
|
+
debugLog("overlay:unavailable", {
|
|
586
|
+
stdinTty: Boolean(process.stdin.isTTY),
|
|
587
|
+
stdoutTty: Boolean(process.stdout.isTTY)
|
|
588
|
+
});
|
|
589
|
+
console.error("ai-battery-run-win: stdin/stdout is not a real terminal.");
|
|
590
|
+
return 2;
|
|
591
|
+
}
|
|
592
|
+
|
|
593
|
+
const status = new StatusLine(args, activeProvider, {
|
|
594
|
+
bottomOffset: overlayBottomOffset(activeProvider)
|
|
595
|
+
});
|
|
596
|
+
const command = windowsCommand(args.command);
|
|
597
|
+
debugLog("overlay:start", {
|
|
598
|
+
size: termSize(),
|
|
599
|
+
command,
|
|
600
|
+
bottomOffset: status.bottomOffset,
|
|
601
|
+
initialDelayMs: overlayInitialDelayMs(),
|
|
602
|
+
stdoutColumns: process.stdout.columns,
|
|
603
|
+
stdoutRows: process.stdout.rows,
|
|
604
|
+
windowSize: process.stdout.getWindowSize?.() || null,
|
|
605
|
+
wtSession: Boolean(process.env.WT_SESSION)
|
|
606
|
+
});
|
|
607
|
+
const child = spawn(command.file, command.args, {
|
|
608
|
+
stdio: "inherit",
|
|
609
|
+
cwd: process.cwd(),
|
|
610
|
+
env: process.env,
|
|
611
|
+
windowsHide: false
|
|
612
|
+
});
|
|
613
|
+
|
|
614
|
+
const timers = new Set();
|
|
615
|
+
const refreshTimer = setInterval(() => status.draw(false), Math.max(1000, args.interval * 1000));
|
|
616
|
+
const repaintTimer = setInterval(() => status.paint(true), overlayRepaintIntervalMs());
|
|
617
|
+
const onResize = () => {
|
|
618
|
+
status.resize();
|
|
619
|
+
status.draw(true);
|
|
620
|
+
scheduleOverlayRepaintBurst(status, timers);
|
|
621
|
+
};
|
|
622
|
+
process.stdout.on("resize", onResize);
|
|
623
|
+
const firstDraw = setTimeout(() => {
|
|
624
|
+
status.draw(true);
|
|
625
|
+
scheduleOverlayRepaintBurst(status, timers);
|
|
626
|
+
}, overlayInitialDelayMs());
|
|
627
|
+
timers.add(firstDraw);
|
|
628
|
+
|
|
629
|
+
const clearOverlayTimers = () => {
|
|
630
|
+
clearInterval(refreshTimer);
|
|
631
|
+
clearInterval(repaintTimer);
|
|
632
|
+
for (const timer of timers) clearTimeout(timer);
|
|
633
|
+
timers.clear();
|
|
634
|
+
};
|
|
635
|
+
|
|
636
|
+
return new Promise((resolve) => {
|
|
637
|
+
child.on("exit", (code, signal) => {
|
|
638
|
+
debugLog("overlay:exit", { code, signal });
|
|
639
|
+
clearOverlayTimers();
|
|
640
|
+
process.stdout.off("resize", onResize);
|
|
641
|
+
status.clear();
|
|
642
|
+
resolve(code ?? (signal ? 1 : 0));
|
|
643
|
+
});
|
|
644
|
+
child.on("error", (error) => {
|
|
645
|
+
debugLog("overlay:error", { error: error.message });
|
|
646
|
+
clearOverlayTimers();
|
|
647
|
+
process.stdout.off("resize", onResize);
|
|
648
|
+
status.clear();
|
|
649
|
+
console.error(`ai-battery-run-win: ${error.message}`);
|
|
650
|
+
resolve(1);
|
|
651
|
+
});
|
|
652
|
+
});
|
|
653
|
+
}
|
|
654
|
+
|
|
655
|
+
function runPlain(args) {
|
|
656
|
+
const command = windowsCommand(args.command);
|
|
657
|
+
debugLog("plain:start", { command });
|
|
658
|
+
const child = spawn(command.file, command.args, {
|
|
659
|
+
stdio: "inherit",
|
|
660
|
+
cwd: process.cwd(),
|
|
661
|
+
env: process.env,
|
|
662
|
+
windowsHide: false
|
|
663
|
+
});
|
|
664
|
+
|
|
665
|
+
return new Promise((resolve) => {
|
|
666
|
+
child.on("exit", (code, signal) => {
|
|
667
|
+
debugLog("plain:exit", { code, signal });
|
|
668
|
+
resolve(code ?? (signal ? 1 : 0));
|
|
669
|
+
});
|
|
670
|
+
child.on("error", (error) => {
|
|
671
|
+
debugLog("plain:error", { error: error.message });
|
|
672
|
+
console.error(`ai-battery-run-win: ${error.message}`);
|
|
673
|
+
resolve(1);
|
|
674
|
+
});
|
|
675
|
+
});
|
|
676
|
+
}
|
|
677
|
+
|
|
678
|
+
async function main() {
|
|
679
|
+
if (process.platform !== "win32") {
|
|
680
|
+
console.error("ai-battery-run-win is only for native Windows.");
|
|
681
|
+
process.exit(2);
|
|
682
|
+
}
|
|
683
|
+
|
|
684
|
+
const args = parseArgs(process.argv.slice(2));
|
|
685
|
+
const commandProvider = inferProvider(args.command);
|
|
686
|
+
if (args.provider === "auto") args.provider = commandProvider;
|
|
687
|
+
const activeProvider = ["codex", "claude"].includes(commandProvider) ? commandProvider : null;
|
|
688
|
+
debugLog("main:start", {
|
|
689
|
+
argv: process.argv.slice(2),
|
|
690
|
+
provider: args.provider,
|
|
691
|
+
layout: args.layout,
|
|
692
|
+
commandProvider,
|
|
693
|
+
activeProvider,
|
|
694
|
+
stdinTty: Boolean(process.stdin.isTTY),
|
|
695
|
+
stdoutTty: Boolean(process.stdout.isTTY)
|
|
696
|
+
});
|
|
697
|
+
|
|
698
|
+
let exitCode = null;
|
|
699
|
+
if (args.layout !== "overlay") {
|
|
700
|
+
exitCode = await runRowPty(args, activeProvider);
|
|
701
|
+
if (exitCode === null) exitCode = await runConPty(args, activeProvider);
|
|
702
|
+
}
|
|
703
|
+
if (exitCode === null) {
|
|
704
|
+
exitCode = process.stdin.isTTY && process.stdout.isTTY
|
|
705
|
+
? await runOverlay(args, activeProvider)
|
|
706
|
+
: await runPlain(args);
|
|
707
|
+
}
|
|
708
|
+
process.exit(exitCode);
|
|
709
|
+
}
|
|
710
|
+
|
|
711
|
+
export {
|
|
712
|
+
conPtyBackspaceMode,
|
|
713
|
+
conPtyRepaintIntervalMs,
|
|
714
|
+
isVsCodeTerminal,
|
|
715
|
+
normalizeConPtyInput,
|
|
716
|
+
outputMayClearDisplay,
|
|
717
|
+
overlayBottomOffset,
|
|
718
|
+
overlayRepaintIntervalMs,
|
|
719
|
+
parseArgs,
|
|
710
720
|
quoteWindowsCommandLineArg,
|
|
711
721
|
resolveWindowsCommandFile,
|
|
712
722
|
rowptyConptyMode,
|
|
@@ -714,25 +724,25 @@ export {
|
|
|
714
724
|
rowptySpawnEnv,
|
|
715
725
|
rowptyStatusCommand,
|
|
716
726
|
statusRow,
|
|
717
|
-
statusOutputText,
|
|
718
|
-
windowsCommand
|
|
719
|
-
};
|
|
720
|
-
|
|
721
|
-
function sameFilePath(leftPath, rightPath) {
|
|
722
|
-
try {
|
|
723
|
-
return fs.realpathSync(leftPath) === fs.realpathSync(rightPath);
|
|
724
|
-
} catch {
|
|
725
|
-
return path.resolve(leftPath) === path.resolve(rightPath);
|
|
726
|
-
}
|
|
727
|
-
}
|
|
728
|
-
|
|
729
|
-
function isDirectRun() {
|
|
730
|
-
return Boolean(process.argv[1]) && sameFilePath(fileURLToPath(import.meta.url), process.argv[1]);
|
|
731
|
-
}
|
|
732
|
-
|
|
733
|
-
if (isDirectRun()) {
|
|
734
|
-
main().catch((error) => {
|
|
735
|
-
console.error(`ai-battery-run-win: ${error.message}`);
|
|
736
|
-
process.exit(1);
|
|
737
|
-
});
|
|
738
|
-
}
|
|
727
|
+
statusOutputText,
|
|
728
|
+
windowsCommand
|
|
729
|
+
};
|
|
730
|
+
|
|
731
|
+
function sameFilePath(leftPath, rightPath) {
|
|
732
|
+
try {
|
|
733
|
+
return fs.realpathSync(leftPath) === fs.realpathSync(rightPath);
|
|
734
|
+
} catch {
|
|
735
|
+
return path.resolve(leftPath) === path.resolve(rightPath);
|
|
736
|
+
}
|
|
737
|
+
}
|
|
738
|
+
|
|
739
|
+
function isDirectRun() {
|
|
740
|
+
return Boolean(process.argv[1]) && sameFilePath(fileURLToPath(import.meta.url), process.argv[1]);
|
|
741
|
+
}
|
|
742
|
+
|
|
743
|
+
if (isDirectRun()) {
|
|
744
|
+
main().catch((error) => {
|
|
745
|
+
console.error(`ai-battery-run-win: ${error.message}`);
|
|
746
|
+
process.exit(1);
|
|
747
|
+
});
|
|
748
|
+
}
|