ai-battery 0.2.0 → 0.2.1
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 +30 -14
- package/bin/ai-battery-macos-status.applescript +5 -12
- package/bin/ai-battery-run +701 -31
- package/bin/ai-battery-tmux.js +17 -0
- package/bin/terminal-compositor.js +111 -0
- package/docs/REFERENCE.md +23 -3
- package/docs/RELEASING.md +24 -7
- package/docs/WINDOWS-TERMINAL-SHARED-BAR.md +74 -0
- package/docs/hud-preview.svg +43 -20
- package/docs/terminal-vertical-preview.svg +73 -0
- package/lib/cli.js +945 -219
- package/lib/core/atomic-rename.js +18 -0
- package/lib/core/cli-help.js +35 -7
- package/lib/core/cli-messages.js +45 -1
- package/lib/core/cli-output.js +277 -72
- package/lib/core/cli-wrappers.js +410 -0
- package/lib/core/config-editor.js +177 -29
- package/lib/core/display-config.js +45 -0
- package/lib/core/integration-files.js +32 -3
- package/lib/core/shared-bar.js +603 -0
- package/lib/core/statusline-git.js +179 -15
- package/lib/core/terminal.js +25 -7
- package/lib/core/tmux-status.js +172 -0
- package/lib/core/uninstall.js +20 -7
- package/lib/core/usage-store.js +85 -0
- package/lib/hud/launcher.js +29 -31
- package/lib/platforms/linux/hud.js +1 -1
- package/lib/platforms/linux/panel.js +1 -1
- package/lib/platforms/macos/hud.js +5 -5
- package/lib/platforms/process-scanner.js +77 -29
- package/lib/platforms/windows/autostart-cleanup.js +1 -1
- package/lib/platforms/windows/codex-runner.js +178 -21
- package/lib/platforms/windows/hud/controls.ps1 +44 -10
- package/lib/platforms/windows/hud/main.ps1 +350 -43
- package/lib/platforms/windows/hud/rendering.ps1 +1227 -1
- package/lib/platforms/windows/hud/snapshot.ps1 +26 -46
- package/lib/platforms/windows/hud-launcher.js +153 -79
- package/lib/platforms/windows/shared-bar-platform.js +972 -0
- package/lib/platforms/windows/terminal-compositor.js +210 -25
- package/lib/platforms/windows/wt-bar.js +729 -0
- package/lib/platforms/windows/wt-fragment.js +665 -0
- package/lib/platforms/windows/wt-keybinding.js +300 -0
- package/lib/providers/antigravity.js +155 -8
- package/package.json +5 -2
- package/vendor/PaneContext.cs +875 -0
package/lib/hud/launcher.js
CHANGED
|
@@ -24,9 +24,10 @@ function commandExists(command) {
|
|
|
24
24
|
const result = spawnSync(command, ["-NoProfile", "-Command", "$PSVersionTable.PSVersion.Major"], {
|
|
25
25
|
encoding: "utf8",
|
|
26
26
|
stdio: "ignore",
|
|
27
|
+
timeout: 5000,
|
|
27
28
|
windowsHide: true
|
|
28
29
|
});
|
|
29
|
-
return result.status === 0;
|
|
30
|
+
return !result.error && result.status === 0;
|
|
30
31
|
}
|
|
31
32
|
|
|
32
33
|
function wslPath(filePath) {
|
|
@@ -49,6 +50,9 @@ function wslEnvPrefix() {
|
|
|
49
50
|
"AI_BATTERY_STATE_DIR",
|
|
50
51
|
"CLAUDEX_BATTERY_STATE_DIR",
|
|
51
52
|
"AI_BATTERY_SHARED_USAGE_STATE_DIR",
|
|
53
|
+
"AI_BATTERY_WINDOWS_STATE_DIR",
|
|
54
|
+
"AI_BATTERY_WINDOWS_LOCALAPPDATA",
|
|
55
|
+
"XDG_STATE_HOME",
|
|
52
56
|
"AI_BATTERY_COLUMNS",
|
|
53
57
|
"CLAUDEX_BATTERY_COLUMNS",
|
|
54
58
|
"AI_BATTERY_COLUMN_GUARD",
|
|
@@ -66,7 +70,8 @@ function psSingleQuote(value) {
|
|
|
66
70
|
}
|
|
67
71
|
|
|
68
72
|
function winArgQuote(value) {
|
|
69
|
-
|
|
73
|
+
const text = String(value);
|
|
74
|
+
return `"${text.replace(/(\\*)"/g, '$1$1\\"').replace(/(\\+)$/, "$1$1")}"`;
|
|
70
75
|
}
|
|
71
76
|
|
|
72
77
|
function buildStartProcessCommand(filePath, args) {
|
|
@@ -113,39 +118,28 @@ function isDirectRun() {
|
|
|
113
118
|
}
|
|
114
119
|
}
|
|
115
120
|
|
|
116
|
-
function snapshotHasWeekly(jsonText) {
|
|
117
|
-
try {
|
|
118
|
-
const snapshot = JSON.parse(jsonText);
|
|
119
|
-
if (!Array.isArray(snapshot.results)) return false;
|
|
120
|
-
const usageResults = snapshot.results.filter((result) => {
|
|
121
|
-
return result
|
|
122
|
-
&& result.ok
|
|
123
|
-
&& ["codex", "claude"].includes(result.provider)
|
|
124
|
-
&& typeof result.percentRemaining === "number";
|
|
125
|
-
});
|
|
126
|
-
return usageResults.length > 0 && usageResults.every((result) => result.secondary);
|
|
127
|
-
} catch {
|
|
128
|
-
return false;
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
|
|
132
121
|
function prefetchInitialJson(command, useWslCommand, batteryModulePath = path.join(scriptDir, "ai-battery.js")) {
|
|
133
122
|
if (process.env.AI_BATTERY_HUD_NO_PREFETCH) return null;
|
|
134
123
|
|
|
135
|
-
const
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
if (snapshotHasWeekly(text) || attempt === attempts - 1) return text;
|
|
144
|
-
}
|
|
145
|
-
sleepSync(180);
|
|
146
|
-
}
|
|
124
|
+
const result = useWslCommand
|
|
125
|
+
? spawnSync("bash", ["-lc", command], { encoding: "utf8", stdio: ["ignore", "pipe", "ignore"], timeout: 6000 })
|
|
126
|
+
: spawnSync(process.execPath, [batteryModulePath, "--json"], {
|
|
127
|
+
encoding: "utf8",
|
|
128
|
+
stdio: ["ignore", "pipe", "ignore"],
|
|
129
|
+
timeout: 6000,
|
|
130
|
+
windowsHide: true
|
|
131
|
+
});
|
|
147
132
|
|
|
148
|
-
return null;
|
|
133
|
+
if (result.error || result.status !== 0) return null;
|
|
134
|
+
const text = result.stdout?.trim();
|
|
135
|
+
if (!text) return null;
|
|
136
|
+
try {
|
|
137
|
+
const parsed = JSON.parse(text);
|
|
138
|
+
if (!parsed || typeof parsed !== "object" || !Array.isArray(parsed.results)) return null;
|
|
139
|
+
return JSON.stringify(parsed);
|
|
140
|
+
} catch {
|
|
141
|
+
return null;
|
|
142
|
+
}
|
|
149
143
|
}
|
|
150
144
|
|
|
151
145
|
function relevantEnvPrefix() {
|
|
@@ -153,6 +147,9 @@ function relevantEnvPrefix() {
|
|
|
153
147
|
"AI_BATTERY_STATE_DIR",
|
|
154
148
|
"CLAUDEX_BATTERY_STATE_DIR",
|
|
155
149
|
"AI_BATTERY_SHARED_USAGE_STATE_DIR",
|
|
150
|
+
"AI_BATTERY_WINDOWS_STATE_DIR",
|
|
151
|
+
"AI_BATTERY_WINDOWS_LOCALAPPDATA",
|
|
152
|
+
"XDG_STATE_HOME",
|
|
156
153
|
"AI_BATTERY_COLUMNS",
|
|
157
154
|
"CLAUDEX_BATTERY_COLUMNS",
|
|
158
155
|
"AI_BATTERY_COLUMN_GUARD",
|
|
@@ -186,6 +183,7 @@ const {
|
|
|
186
183
|
powerShellCommandArgs,
|
|
187
184
|
prefetchInitialJson,
|
|
188
185
|
ps1Path,
|
|
186
|
+
psInvocationArg,
|
|
189
187
|
psSingleQuote,
|
|
190
188
|
scriptDir,
|
|
191
189
|
shellQuote,
|
|
@@ -23,7 +23,7 @@ export function linuxHudBusName(root) {
|
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
export function parseLinuxHudArgs(argv) {
|
|
26
|
-
const options = { action: "start", autostart: "status", interval:
|
|
26
|
+
const options = { action: "start", autostart: "status", interval: 2, provider: "all", foreground: false, once: false };
|
|
27
27
|
let actionSeen = false;
|
|
28
28
|
for (let i = 0; i < argv.length; i += 1) {
|
|
29
29
|
const arg = argv[i];
|
|
@@ -89,7 +89,7 @@ function runPanel() {
|
|
|
89
89
|
const iconDir = GLib.build_filenamev([rootDir, "linux-hud"]);
|
|
90
90
|
GLib.mkdir_with_parents(iconDir, 0o700);
|
|
91
91
|
const readyFile = value("--ready");
|
|
92
|
-
const interval = Math.max(1, Number(value("--interval", "
|
|
92
|
+
const interval = Math.max(1, Number(value("--interval", "2")) || 2);
|
|
93
93
|
const provider = value("--provider", "all");
|
|
94
94
|
const pid = new Gio.Credentials().get_unix_pid();
|
|
95
95
|
let snapshot = null;
|
|
@@ -19,7 +19,7 @@ function parseMacHudArgs(cliArgs) {
|
|
|
19
19
|
stop: false,
|
|
20
20
|
subcommand: null,
|
|
21
21
|
autostartAction: "status",
|
|
22
|
-
interval:
|
|
22
|
+
interval: 2,
|
|
23
23
|
provider: "all"
|
|
24
24
|
};
|
|
25
25
|
|
|
@@ -204,7 +204,7 @@ function runMacHud(cliArgs) {
|
|
|
204
204
|
...(options.provider === "all" ? [] : ["--provider", options.provider])
|
|
205
205
|
], { encoding: "utf8", stdio: ["ignore", "pipe", "inherit"] });
|
|
206
206
|
if (result.stdout) process.stdout.write(result.stdout);
|
|
207
|
-
process.exit(result.status ??
|
|
207
|
+
process.exit(result.error ? 1 : (result.status ?? 1));
|
|
208
208
|
}
|
|
209
209
|
|
|
210
210
|
if (options.subcommand === "status") {
|
|
@@ -237,8 +237,8 @@ function runMacHud(cliArgs) {
|
|
|
237
237
|
process.exit(0);
|
|
238
238
|
}
|
|
239
239
|
const result = spawnSync("kill", pids.map(String), { stdio: "inherit" });
|
|
240
|
-
if (
|
|
241
|
-
process.exit(result.status ??
|
|
240
|
+
if (!result.error && result.status === 0) console.log("HUD: stopped");
|
|
241
|
+
process.exit(result.error ? 1 : (result.status ?? 1));
|
|
242
242
|
}
|
|
243
243
|
|
|
244
244
|
const existingPids = macHudPids();
|
|
@@ -258,7 +258,7 @@ function runMacHud(cliArgs) {
|
|
|
258
258
|
|
|
259
259
|
if (options.foreground) {
|
|
260
260
|
const result = spawnSync("osascript", osascriptArgs, { stdio: "inherit" });
|
|
261
|
-
process.exit(result.status ??
|
|
261
|
+
process.exit(result.error ? 1 : (result.status ?? 1));
|
|
262
262
|
}
|
|
263
263
|
|
|
264
264
|
const child = spawn("osascript", osascriptArgs, {
|
|
@@ -3,6 +3,7 @@ import fs from "node:fs";
|
|
|
3
3
|
import path from "node:path";
|
|
4
4
|
|
|
5
5
|
export function createProcessScanner({
|
|
6
|
+
execFileSync: runExecFileSync = execFileSync,
|
|
6
7
|
isWsl,
|
|
7
8
|
readJson,
|
|
8
9
|
readScanCache,
|
|
@@ -48,7 +49,7 @@ function codexCommandIsBackground(cmdline) {
|
|
|
48
49
|
const firstBase = commandTokenBasename(tokens[0]).toLowerCase();
|
|
49
50
|
if (tokenMatchesProviderExecutable(tokens[0], "codex")) {
|
|
50
51
|
commandIndex = 0;
|
|
51
|
-
} else if (/^node(?:\.exe)
|
|
52
|
+
} else if (/^(?:node(?:\.exe)?|python(?:\d+(?:\.\d+)*)?|(?:ba|z)?sh)$/i.test(firstBase) && tokenMatchesProviderExecutable(tokens[1], "codex")) {
|
|
52
53
|
commandIndex = 1;
|
|
53
54
|
}
|
|
54
55
|
|
|
@@ -124,7 +125,7 @@ function commandMatchesProvider(cmdline, provider) {
|
|
|
124
125
|
|
|
125
126
|
const firstBase = commandTokenBasename(tokens[0]).toLowerCase();
|
|
126
127
|
if (tokenMatchesProviderExecutable(tokens[0], provider)) return true;
|
|
127
|
-
if (/^node(?:\.exe)
|
|
128
|
+
if (/^(?:node(?:\.exe)?|python(?:\d+(?:\.\d+)*)?|(?:ba|z)?sh)$/i.test(firstBase) && tokenMatchesProviderExecutable(tokens[1], provider)) return true;
|
|
128
129
|
|
|
129
130
|
const runnerCommand = commandInvokesAiBatteryRunner(tokens)
|
|
130
131
|
? aiBatteryRunnerCommandTokens(tokens)
|
|
@@ -166,14 +167,17 @@ function processHasControllingTty(pid) {
|
|
|
166
167
|
|
|
167
168
|
function listWindowsProcessCommands() {
|
|
168
169
|
try {
|
|
169
|
-
const
|
|
170
|
+
const psExe = process.platform !== "win32" && fs.existsSync("/mnt/c/Windows/System32/WindowsPowerShell/v1.0/powershell.exe")
|
|
171
|
+
? "/mnt/c/Windows/System32/WindowsPowerShell/v1.0/powershell.exe"
|
|
172
|
+
: "powershell.exe";
|
|
173
|
+
const output = runExecFileSync(psExe, [
|
|
170
174
|
"-NoProfile",
|
|
171
175
|
"-Command",
|
|
172
176
|
"Get-CimInstance Win32_Process | ForEach-Object { $_.CommandLine }"
|
|
173
177
|
], {
|
|
174
178
|
encoding: "utf8",
|
|
175
179
|
stdio: ["ignore", "pipe", "ignore"],
|
|
176
|
-
timeout:
|
|
180
|
+
timeout: 3000,
|
|
177
181
|
windowsHide: true,
|
|
178
182
|
maxBuffer: 2 * 1024 * 1024
|
|
179
183
|
});
|
|
@@ -188,9 +192,12 @@ function listWindowsProcessCommands() {
|
|
|
188
192
|
}
|
|
189
193
|
|
|
190
194
|
function decodeCommandOutput(buffer) {
|
|
191
|
-
return
|
|
192
|
-
|
|
193
|
-
|
|
195
|
+
if (typeof buffer === "string") return buffer.replace(/^\uFEFF/, "").replace(/\0/g, "");
|
|
196
|
+
const raw = Buffer.isBuffer(buffer) ? buffer : Buffer.from(buffer || "");
|
|
197
|
+
const hasUtf16LeBom = raw.length >= 2 && raw[0] === 0xff && raw[1] === 0xfe;
|
|
198
|
+
const looksUtf16Le = hasUtf16LeBom || (raw.length >= 2 && raw.length % 2 === 0 && raw.includes(0));
|
|
199
|
+
const text = looksUtf16Le ? raw.toString("utf16le") : raw.toString("utf8");
|
|
200
|
+
return text.replace(/^\uFEFF/, "").replace(/\0/g, "");
|
|
194
201
|
}
|
|
195
202
|
|
|
196
203
|
function parseTtyProcessListOutput(output, source = null) {
|
|
@@ -203,7 +210,7 @@ function parseTtyProcessListOutput(output, source = null) {
|
|
|
203
210
|
const tty = trimmed.slice(0, space);
|
|
204
211
|
const cmdline = trimmed.slice(space + 1).trim();
|
|
205
212
|
if (!cmdline) return null;
|
|
206
|
-
const proc = { cmdline, hasTty: tty !== "??" && tty !== "-" };
|
|
213
|
+
const proc = { cmdline, hasTty: tty !== "?" && tty !== "??" && tty !== "-" };
|
|
207
214
|
if (source) proc.source = source;
|
|
208
215
|
return proc;
|
|
209
216
|
})
|
|
@@ -212,7 +219,7 @@ function parseTtyProcessListOutput(output, source = null) {
|
|
|
212
219
|
|
|
213
220
|
function listDarwinProcessCommands() {
|
|
214
221
|
try {
|
|
215
|
-
const output =
|
|
222
|
+
const output = runExecFileSync("ps", ["-axo", "tty=,args="], {
|
|
216
223
|
encoding: "utf8",
|
|
217
224
|
stdio: ["ignore", "pipe", "ignore"],
|
|
218
225
|
timeout: 1500,
|
|
@@ -227,13 +234,13 @@ function listDarwinProcessCommands() {
|
|
|
227
234
|
function runningWslDistros() {
|
|
228
235
|
if (process.platform !== "win32") return [];
|
|
229
236
|
try {
|
|
230
|
-
const output = decodeCommandOutput(
|
|
237
|
+
const output = decodeCommandOutput(runExecFileSync("wsl.exe", [
|
|
231
238
|
"--list",
|
|
232
239
|
"--running",
|
|
233
240
|
"--quiet"
|
|
234
241
|
], {
|
|
235
242
|
stdio: ["ignore", "pipe", "ignore"],
|
|
236
|
-
timeout:
|
|
243
|
+
timeout: 2500,
|
|
237
244
|
maxBuffer: 256 * 1024,
|
|
238
245
|
windowsHide: true
|
|
239
246
|
}));
|
|
@@ -242,34 +249,38 @@ function runningWslDistros() {
|
|
|
242
249
|
.map((line) => line.trim())
|
|
243
250
|
.filter(Boolean);
|
|
244
251
|
} catch {
|
|
245
|
-
return
|
|
252
|
+
return null;
|
|
246
253
|
}
|
|
247
254
|
}
|
|
248
255
|
|
|
249
256
|
function listWslProcessCommands() {
|
|
250
257
|
const distros = runningWslDistros();
|
|
258
|
+
if (distros === null) return null;
|
|
251
259
|
if (!distros.length) return [];
|
|
252
260
|
|
|
253
261
|
const commands = [];
|
|
262
|
+
let hadFailure = false;
|
|
254
263
|
for (const distro of distros) {
|
|
255
264
|
try {
|
|
256
|
-
const output = decodeCommandOutput(
|
|
265
|
+
const output = decodeCommandOutput(runExecFileSync("wsl.exe", [
|
|
257
266
|
"--distribution",
|
|
258
267
|
distro,
|
|
259
|
-
"
|
|
260
|
-
"
|
|
261
|
-
"
|
|
268
|
+
"--exec",
|
|
269
|
+
"ps",
|
|
270
|
+
"-axo",
|
|
271
|
+
"tty=,args="
|
|
262
272
|
], {
|
|
263
273
|
stdio: ["ignore", "pipe", "ignore"],
|
|
264
|
-
timeout:
|
|
274
|
+
timeout: 2500,
|
|
265
275
|
maxBuffer: 4 * 1024 * 1024,
|
|
266
276
|
windowsHide: true
|
|
267
277
|
}));
|
|
268
278
|
commands.push(...parseTtyProcessListOutput(output, "wsl"));
|
|
269
279
|
} catch {
|
|
270
|
-
|
|
280
|
+
hadFailure = true;
|
|
271
281
|
}
|
|
272
282
|
}
|
|
283
|
+
if (hadFailure && !commands.length) return null;
|
|
273
284
|
return commands;
|
|
274
285
|
}
|
|
275
286
|
|
|
@@ -302,31 +313,57 @@ function listProcProcessCommands() {
|
|
|
302
313
|
}
|
|
303
314
|
|
|
304
315
|
const PROCESS_SCAN_TTL_MS = 2000;
|
|
316
|
+
const ERROR_FALLBACK_MAX_AGE_SECONDS = 30;
|
|
317
|
+
const NONBLOCKING_STALE_MAX_AGE_SECONDS = 60;
|
|
305
318
|
let processScanMemo = null;
|
|
306
319
|
|
|
307
|
-
function
|
|
308
|
-
|
|
320
|
+
function readBoundedFallbackCache(name, maxAgeSeconds) {
|
|
321
|
+
const cached = readScanCache(name, maxAgeSeconds);
|
|
322
|
+
if (cached && Array.isArray(cached.value)) return cached.value;
|
|
323
|
+
const raw = readJson(scanCachePath(name));
|
|
324
|
+
if (!raw || !Array.isArray(raw.value)) return [];
|
|
325
|
+
const savedMs = Date.parse(raw.capturedAt || raw.savedAt || raw.timestamp || "");
|
|
326
|
+
if (Number.isFinite(savedMs) && Date.now() - savedMs <= maxAgeSeconds * 1000) {
|
|
327
|
+
return raw.value;
|
|
328
|
+
}
|
|
329
|
+
return [];
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
function scanProcessCommands(options = {}) {
|
|
333
|
+
const nonBlocking = Boolean(options?.nonBlocking);
|
|
334
|
+
const triggerBackgroundRefresh = typeof options?.triggerBackgroundRefresh === "function"
|
|
335
|
+
? options.triggerBackgroundRefresh
|
|
336
|
+
: null;
|
|
337
|
+
if (!options?.forceRefresh && processScanMemo && Date.now() - processScanMemo.at < PROCESS_SCAN_TTL_MS && (!processScanMemo.nonBlocking || nonBlocking)) {
|
|
309
338
|
return processScanMemo.commands;
|
|
310
339
|
}
|
|
311
340
|
|
|
312
341
|
let commands;
|
|
342
|
+
const ttlSeconds = scanCacheSeconds(10);
|
|
313
343
|
if (process.platform === "win32") {
|
|
314
344
|
// Spawning PowerShell for the process list is the slow part on Windows, so
|
|
315
345
|
// share one recent scan between the HUD, statusline, and watch invocations.
|
|
316
346
|
// Windows and WSL draw on the same desktop, so include running WSL distros
|
|
317
347
|
// when they are already up; --list --running avoids starting WSL just to
|
|
318
348
|
// satisfy a HUD refresh.
|
|
319
|
-
const cached = readScanCache("windows-processes",
|
|
349
|
+
const cached = !options?.forceRefresh ? readScanCache("windows-processes", ttlSeconds) : null;
|
|
320
350
|
if (cached) {
|
|
321
351
|
commands = Array.isArray(cached.value) ? cached.value : [];
|
|
352
|
+
} else if (nonBlocking) {
|
|
353
|
+
commands = readBoundedFallbackCache("windows-processes", NONBLOCKING_STALE_MAX_AGE_SECONDS);
|
|
354
|
+
triggerBackgroundRefresh?.();
|
|
322
355
|
} else {
|
|
323
356
|
const windowsCommands = listWindowsProcessCommands();
|
|
324
357
|
if (windowsCommands === null) {
|
|
325
|
-
commands =
|
|
358
|
+
commands = readBoundedFallbackCache("windows-processes", ERROR_FALLBACK_MAX_AGE_SECONDS);
|
|
326
359
|
} else {
|
|
360
|
+
const wslCommands = listWslProcessCommands();
|
|
361
|
+
const resolvedWsl = wslCommands === null
|
|
362
|
+
? readBoundedFallbackCache("windows-processes", ERROR_FALLBACK_MAX_AGE_SECONDS).filter(item => item?.source === "wsl")
|
|
363
|
+
: wslCommands;
|
|
327
364
|
commands = [
|
|
328
365
|
...windowsCommands,
|
|
329
|
-
...
|
|
366
|
+
...resolvedWsl
|
|
330
367
|
];
|
|
331
368
|
writeScanCache("windows-processes", commands);
|
|
332
369
|
}
|
|
@@ -339,17 +376,27 @@ function scanProcessCommands() {
|
|
|
339
376
|
// WSL shares a visible desktop with native Windows apps. Pull in the
|
|
340
377
|
// Windows process list too, while keeping the Linux /proc scan as the
|
|
341
378
|
// source for WSL TTY ownership.
|
|
342
|
-
const cached = readScanCache("wsl-windows-processes",
|
|
379
|
+
const cached = !options?.forceRefresh ? readScanCache("wsl-windows-processes", ttlSeconds) : null;
|
|
343
380
|
let windowsCommands = cached?.value;
|
|
344
381
|
if (!Array.isArray(windowsCommands)) {
|
|
345
|
-
|
|
346
|
-
|
|
382
|
+
if (nonBlocking) {
|
|
383
|
+
windowsCommands = readBoundedFallbackCache("wsl-windows-processes", NONBLOCKING_STALE_MAX_AGE_SECONDS);
|
|
384
|
+
triggerBackgroundRefresh?.();
|
|
385
|
+
} else {
|
|
386
|
+
const scanned = listWindowsProcessCommands();
|
|
387
|
+
if (scanned === null) {
|
|
388
|
+
windowsCommands = readBoundedFallbackCache("wsl-windows-processes", ERROR_FALLBACK_MAX_AGE_SECONDS);
|
|
389
|
+
} else {
|
|
390
|
+
windowsCommands = scanned;
|
|
391
|
+
writeScanCache("wsl-windows-processes", windowsCommands);
|
|
392
|
+
}
|
|
393
|
+
}
|
|
347
394
|
}
|
|
348
395
|
commands = [...commands, ...windowsCommands];
|
|
349
396
|
}
|
|
350
397
|
}
|
|
351
398
|
|
|
352
|
-
processScanMemo = { at: Date.now(), commands };
|
|
399
|
+
processScanMemo = { at: Date.now(), commands, nonBlocking };
|
|
353
400
|
return commands;
|
|
354
401
|
}
|
|
355
402
|
|
|
@@ -364,8 +411,8 @@ function providerRunningInProcesses(provider, processes, platform = process.plat
|
|
|
364
411
|
});
|
|
365
412
|
}
|
|
366
413
|
|
|
367
|
-
function isProviderRunning(provider) {
|
|
368
|
-
return providerRunningInProcesses(provider, scanProcessCommands());
|
|
414
|
+
function isProviderRunning(provider, options = {}) {
|
|
415
|
+
return providerRunningInProcesses(provider, scanProcessCommands(options));
|
|
369
416
|
}
|
|
370
417
|
|
|
371
418
|
function codexBackgroundReadyInProcesses(processes) {
|
|
@@ -374,6 +421,7 @@ function codexBackgroundReadyInProcesses(processes) {
|
|
|
374
421
|
return {
|
|
375
422
|
codexBackgroundReadyInProcesses,
|
|
376
423
|
commandMatchesProvider,
|
|
424
|
+
decodeCommandOutput,
|
|
377
425
|
isProviderRunning,
|
|
378
426
|
parseTtyProcessListOutput,
|
|
379
427
|
providerRunningInProcesses,
|
|
@@ -13,7 +13,7 @@ export function windowsAutostartCleanupScript({ registryPath, registryName }) {
|
|
|
13
13
|
"if ($v -and $v -ne $expected) { throw 'AiBatteryHud registry value changed; left it untouched.' }",
|
|
14
14
|
"$ownedFile = $false",
|
|
15
15
|
"if (Test-Path -LiteralPath $auto) {",
|
|
16
|
-
" $ownedFile = (Get-Content -Raw -LiteralPath $auto).StartsWith('# Generated by: ai-battery hud autostart on')",
|
|
16
|
+
" $ownedFile = ([string](Get-Content -Raw -LiteralPath $auto)).StartsWith('# Generated by: ai-battery hud autostart on')",
|
|
17
17
|
" if (-not $ownedFile) { throw 'Autostart file changed; left it and its registry value untouched.' }",
|
|
18
18
|
"}",
|
|
19
19
|
`if ($v) { Remove-ItemProperty -Path ${quote(registryPath)} -Name ${quote(registryName)} }`,
|