ask-pro 0.2.78 → 0.2.80

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.
@@ -8,7 +8,7 @@ import { fileURLToPath } from "node:url";
8
8
  import { promisify } from "node:util";
9
9
  import CDP from "chrome-remote-interface";
10
10
  import { Launcher } from "chrome-launcher";
11
- import { clearChromeLaunchStarting, cleanupStaleProfileState, hasChromeLaunchStarting, markChromeLaunchStarting, readChromePid, readDevToolsPort, verifyDevToolsReachable, } from "./profileState.js";
11
+ import { clearChromeLaunchStarting, clearIdleBrowserProfileCaches, cleanupStaleProfileState, hasChromeLaunchStarting, markChromeLaunchStarting, readChromePid, readDevToolsPort, verifyDevToolsReachable, } from "./profileState.js";
12
12
  import { delay } from "./utils.js";
13
13
  import { formatElapsed } from "./format.js";
14
14
  import { withTimeout } from "./reattachHelpers.js";
@@ -20,13 +20,14 @@ const CPU_THROTTLING_OVERRIDE_FLAGS = new Set([
20
20
  "--disable-ipc-flooding-protection",
21
21
  ]);
22
22
  const CHROME_STARTUP_HANDOFF_MS = 26_000;
23
- export async function launchChrome(config, userDataDir, logger) {
23
+ export async function launchChrome(config, userDataDir, logger, options = {}) {
24
24
  const connectHost = resolveRemoteDebugHost();
25
25
  const debugBindAddress = connectHost && connectHost !== "127.0.0.1" ? "0.0.0.0" : connectHost;
26
26
  const debugPort = config.debugPort ?? parseDebugPortEnv();
27
27
  const chromeFlags = buildChromeLaunchFlags(buildChromeFlags(config.headless ?? false, debugBindAddress, config.acceptLanguage, {
28
28
  startMinimized: shouldLaunchChromeMinimized(config),
29
29
  }));
30
+ await clearIdleBrowserProfileCaches(userDataDir, options);
30
31
  await markChromeLaunchStarting(userDataDir);
31
32
  try {
32
33
  const launcher = await launchManagedChrome({
@@ -581,6 +582,7 @@ export function buildChromeFlags(headless, debugBindAddress, acceptLanguage = "e
581
582
  const primaryLanguage = acceptLanguage.split(",", 1)[0]?.trim() || "en-US";
582
583
  const flags = [
583
584
  "--disable-background-networking",
585
+ "--disk-cache-size=16777216",
584
586
  "--disable-breakpad",
585
587
  "--disable-client-side-phishing-detection",
586
588
  "--disable-default-apps",
@@ -394,7 +394,7 @@ export async function runBrowserMode(options) {
394
394
  (await launchChrome({
395
395
  ...config,
396
396
  remoteChrome: config.remoteChrome,
397
- }, userDataDir, logger));
397
+ }, userDataDir, logger, { ignoreLockId: profileLock?.lockId }));
398
398
  // Persist profile state so future manual-login runs can reuse this Chrome.
399
399
  if (manualLogin && chrome.port) {
400
400
  await writeDevToolsActivePort(userDataDir, chrome.port);
@@ -182,6 +182,16 @@ export async function isBrowserProfileInUse(userDataDir, options = {}) {
182
182
  const lock = parseProfileRunLock(raw);
183
183
  if (lock && lock.lockId !== options.ignoreLockId && isProcessAlive(lock.pid))
184
184
  return true;
185
+ try {
186
+ const leases = await readdir(path.join(userDataDir, ASK_PRO_RUN_LEASE_DIRNAME));
187
+ if (leases.some((name) => name.endsWith(".lease") && isProcessAlive(Number(name.match(/^(\d+)-/)?.[1])))) {
188
+ return true;
189
+ }
190
+ }
191
+ catch (error) {
192
+ if (error.code !== "ENOENT")
193
+ return true;
194
+ }
185
195
  const pid = await readChromePid(userDataDir);
186
196
  const port = await readDevToolsPort(userDataDir);
187
197
  const [owner, devTools] = await Promise.all([
@@ -192,6 +202,19 @@ export async function isBrowserProfileInUse(userDataDir, options = {}) {
192
202
  return true;
193
203
  return owner === null;
194
204
  }
205
+ // Call while holding the profile's launch lock; only disposable caches are removed.
206
+ export async function clearIdleBrowserProfileCaches(userDataDir, options = {}) {
207
+ try {
208
+ if (await isBrowserProfileInUse(userDataDir, options))
209
+ return;
210
+ for (const name of ["Cache", "Code Cache"]) {
211
+ await rm(path.join(userDataDir, "Default", name), { recursive: true, force: true }).catch(() => undefined);
212
+ }
213
+ }
214
+ catch {
215
+ // Cache maintenance must never prevent a browser run.
216
+ }
217
+ }
195
218
  export async function acquireProfileRunLock(userDataDir, options) {
196
219
  const timeoutMs = options.timeoutMs;
197
220
  if (!Number.isFinite(timeoutMs) || timeoutMs <= 0) {
@@ -355,7 +355,9 @@ async function resumeBrowserSessionViaNewChrome(runtime, config, logger, deps) {
355
355
  if (!reusedChrome) {
356
356
  await seedChromeProfileLanguage(userDataDir, resolved.acceptLanguage, logger);
357
357
  }
358
- chrome = reusedChrome ?? (await launchChrome(resolved, userDataDir, logger));
358
+ chrome =
359
+ reusedChrome ??
360
+ (await launchChrome(resolved, userDataDir, logger, { ignoreLockId: launchLock?.lockId }));
359
361
  if (manualLogin) {
360
362
  reattachRunLease = {
361
363
  userDataDir,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ask-pro",
3
- "version": "0.2.78",
3
+ "version": "0.2.80",
4
4
  "description": "Browser-backed ChatGPT Pro escalation for hard engineering questions.",
5
5
  "keywords": [
6
6
  "agents",