gm-plugkit 2.0.1645 → 2.0.1646

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/bootstrap.js CHANGED
@@ -460,24 +460,6 @@ function killPid(pid) {
460
460
  return true;
461
461
  }
462
462
 
463
- function killRunningDaemons(reason) {
464
- const tmp = os.tmpdir();
465
- const killedPids = [];
466
- for (const pidFile of ['glootie-runner.pid', 'plugkit-runner.pid']) {
467
- const pidPath = path.join(tmp, pidFile);
468
- if (!fs.existsSync(pidPath)) continue;
469
- try {
470
- const pid = parseInt(fs.readFileSync(pidPath, 'utf8').trim(), 10);
471
- if (killPid(pid)) {
472
- killedPids.push(pid);
473
- obsEvent('bootstrap', 'daemon.killed', { pid, pidFile, reason });
474
- }
475
- try { fs.unlinkSync(pidPath); } catch (_) {}
476
- } catch (_) {}
477
- }
478
- return killedPids;
479
- }
480
-
481
463
  function killSpoolWatcherInCwd(reason) {
482
464
  try {
483
465
  const pidPath = path.join(process.cwd(), '.gm', 'exec-spool', '.watcher.pid');
@@ -525,7 +507,6 @@ function pruneOldVersions(root, keepVersion) {
525
507
  function proactiveKillForNewInstall(installedVersion) {
526
508
  try {
527
509
  const reason = `install:v${installedVersion}`;
528
- killRunningDaemons(reason);
529
510
  killSpoolWatcherInCwd(reason);
530
511
  writeDaemonVersion(installedVersion);
531
512
  } catch (_) {}
@@ -541,7 +522,7 @@ function killStaleDaemonIfVersionChanged() {
541
522
  }
542
523
  const recorded = readDaemonVersion();
543
524
  if (recorded === currentVersion) return;
544
- if (recorded) killRunningDaemons(`version_change:${recorded}->${currentVersion}`);
525
+ if (recorded) killSpoolWatcherInCwd(`version_change:${recorded}->${currentVersion}`);
545
526
  writeDaemonVersion(currentVersion);
546
527
  }
547
528
 
@@ -967,7 +948,7 @@ async function ensureReady(opts) {
967
948
  }
968
949
 
969
950
  if (versionDrift) {
970
- try { killRunningDaemons(`version_drift:${installed}->${targetVersion}`); } catch (_) {}
951
+ try { killSpoolWatcherInCwd(`version_drift:${installed}->${targetVersion}`); } catch (_) {}
971
952
  }
972
953
 
973
954
  ensureWrapperFresh();
@@ -1096,7 +1077,6 @@ module.exports = {
1096
1077
  isReady,
1097
1078
  cacheRoot,
1098
1079
  obsEvent,
1099
- killRunningDaemons,
1100
1080
  killStaleDaemonIfVersionChanged,
1101
1081
  killSpoolWatcherInCwd,
1102
1082
  proactiveKillForNewInstall,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gm-plugkit",
3
- "version": "2.0.1645",
3
+ "version": "2.0.1646",
4
4
  "description": "Bootstrap and daemon-spawn tool for gm plugkit binary. Downloads the correct platform binary, verifies SHA256, and starts the spool watcher daemon. Includes plugkit-wasm-wrapper for WASM-based spool watching.",
5
5
  "main": "index.js",
6
6
  "bin": {
@@ -550,9 +550,11 @@ const LEGACY_BROWSER_PORTS_FILE = path.join(TMP_DIR, 'plugkit-browser-ports.json
550
550
  const LEGACY_BROWSER_SESSIONS_FILE = path.join(TMP_DIR, 'plugkit-browser-sessions.json');
551
551
 
552
552
  const __browserRootCache = new Map();
553
+ const BROWSER_ROOT_CACHE_TTL_MS = 60_000;
553
554
  function browserRootDir(cwd) {
554
555
  const start = path.resolve(cwd || process.cwd());
555
- if (__browserRootCache.has(start)) return __browserRootCache.get(start);
556
+ const cached = __browserRootCache.get(start);
557
+ if (cached && Date.now() - cached.ts < BROWSER_ROOT_CACHE_TTL_MS) return cached.root;
556
558
  let root = start;
557
559
  try {
558
560
  const r = spawnSync('git', ['rev-parse', '--git-common-dir'], { cwd: start, encoding: 'utf-8', windowsHide: true, timeout: 1500 });
@@ -563,15 +565,18 @@ function browserRootDir(cwd) {
563
565
  }
564
566
  } catch (_) {}
565
567
  root = path.resolve(root);
566
- __browserRootCache.set(start, root);
568
+ __browserRootCache.set(start, { root, ts: Date.now() });
567
569
  return root;
568
570
  }
569
571
 
570
572
  function browserStateDir(cwd) {
571
- const dir = path.join(browserRootDir(cwd), '.gm', 'exec-spool');
573
+ const dir = path.join(browserRootDir(cwd), '.gm', 'browser-state');
572
574
  try { fs.mkdirSync(dir, { recursive: true }); } catch (_) {}
573
575
  return dir;
574
576
  }
577
+ function browserStateDirLegacyCoLocated(cwd) {
578
+ return path.join(browserRootDir(cwd), '.gm', 'exec-spool');
579
+ }
575
580
  function browserPortsFile(cwd) { return path.join(browserStateDir(cwd), 'browser-ports.json'); }
576
581
  function browserSessionsFile(cwd) { return path.join(browserStateDir(cwd), 'browser-sessions.json'); }
577
582
 
@@ -609,14 +614,23 @@ function atomicWriteJson(filePath, obj) {
609
614
  function migrateLegacyBrowserState(cwd) {
610
615
  const dst1 = browserPortsFile(cwd);
611
616
  const dst2 = browserSessionsFile(cwd);
617
+ const coLocated = browserStateDirLegacyCoLocated(cwd);
618
+ const coLocatedPorts = path.join(coLocated, 'browser-ports.json');
619
+ const coLocatedSessions = path.join(coLocated, 'browser-sessions.json');
612
620
  try {
613
- if (!fs.existsSync(dst1) && fs.existsSync(LEGACY_BROWSER_PORTS_FILE)) {
621
+ if (!fs.existsSync(dst1) && fs.existsSync(coLocatedPorts)) {
622
+ const legacy = JSON.parse(fs.readFileSync(coLocatedPorts, 'utf-8'));
623
+ if (legacy && typeof legacy === 'object') atomicWriteJson(dst1, legacy);
624
+ } else if (!fs.existsSync(dst1) && fs.existsSync(LEGACY_BROWSER_PORTS_FILE)) {
614
625
  const legacy = JSON.parse(fs.readFileSync(LEGACY_BROWSER_PORTS_FILE, 'utf-8'));
615
626
  if (legacy && typeof legacy === 'object') atomicWriteJson(dst1, legacy);
616
627
  }
617
628
  } catch (_) {}
618
629
  try {
619
- if (!fs.existsSync(dst2) && fs.existsSync(LEGACY_BROWSER_SESSIONS_FILE)) {
630
+ if (!fs.existsSync(dst2) && fs.existsSync(coLocatedSessions)) {
631
+ const legacy = JSON.parse(fs.readFileSync(coLocatedSessions, 'utf-8'));
632
+ if (legacy && typeof legacy === 'object') atomicWriteJson(dst2, legacy);
633
+ } else if (!fs.existsSync(dst2) && fs.existsSync(LEGACY_BROWSER_SESSIONS_FILE)) {
620
634
  const legacy = JSON.parse(fs.readFileSync(LEGACY_BROWSER_SESSIONS_FILE, 'utf-8'));
621
635
  if (legacy && typeof legacy === 'object') atomicWriteJson(dst2, legacy);
622
636
  }
@@ -2820,8 +2834,10 @@ async function runSpoolWatcher(instance, spoolDir) {
2820
2834
  if (!_ownWrapperSha12) return;
2821
2835
  let reg = {};
2822
2836
  try { reg = JSON.parse(fs.readFileSync(PEER_REGISTRY_PATH, 'utf-8')); } catch (_) { return; }
2837
+ const ownRoot = browserRootDir(process.cwd());
2823
2838
  for (const peerCwd of Object.keys(reg)) {
2824
2839
  if (peerCwd === process.cwd()) continue;
2840
+ if (browserRootDir(peerCwd) !== ownRoot) continue;
2825
2841
  const peerLock = path.join(peerCwd, '.gm', 'exec-spool', '.watcher.lock');
2826
2842
  let content = '';
2827
2843
  try { content = fs.readFileSync(peerLock, 'utf-8').trim(); } catch (_) { continue; }