gm-plugkit 2.0.1223 → 2.0.1225

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gm-plugkit",
3
- "version": "2.0.1223",
3
+ "version": "2.0.1225",
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": {
@@ -733,6 +733,46 @@ function cleanDeadProfileFragments(cwd) {
733
733
  }
734
734
  }
735
735
 
736
+ function isPortReachableSync(host, port, timeoutMs) {
737
+ const r = spawnSync(process.execPath, ['-e', `
738
+ const net = require('net');
739
+ const s = net.connect({ port: ${port}, host: ${JSON.stringify(host)} });
740
+ let done = false;
741
+ s.on('connect', () => { done = true; s.destroy(); process.exit(0); });
742
+ s.on('error', () => { if (!done) process.exit(1); });
743
+ setTimeout(() => { if (!done) { s.destroy(); process.exit(1); } }, ${timeoutMs || 800});
744
+ `], { timeout: (timeoutMs || 800) + 2000 });
745
+ return r.status === 0;
746
+ }
747
+
748
+ let _acptoapiBoot = { spawned_at: 0, pid: null };
749
+ function ensureAcptoapi() {
750
+ const host = '127.0.0.1';
751
+ const port = 4800;
752
+ try {
753
+ if (isPortReachableSync(host, port, 500)) {
754
+ _acptoapiBoot = { spawned_at: 0, pid: null, status: 'already-running' };
755
+ return;
756
+ }
757
+ if (_acptoapiBoot.spawned_at && Date.now() - _acptoapiBoot.spawned_at < 30000) {
758
+ return;
759
+ }
760
+ const isWindows = process.platform === 'win32';
761
+ const cmd = isWindows ? 'bun.exe' : 'bun';
762
+ const child = spawn(cmd, ['x', 'acptoapi@latest'], {
763
+ detached: true,
764
+ stdio: 'ignore',
765
+ windowsHide: true,
766
+ shell: false,
767
+ });
768
+ child.unref();
769
+ _acptoapiBoot = { spawned_at: Date.now(), pid: child.pid, status: 'spawned' };
770
+ logEvent('bootstrap', 'acptoapi.spawned', { pid: child.pid, port });
771
+ } catch (e) {
772
+ logEvent('bootstrap', 'acptoapi.spawn-failed', { error: e && e.message });
773
+ }
774
+ }
775
+
736
776
  function findFreePortSync() {
737
777
  const r = spawnSync(process.execPath, ['-e', `
738
778
  const net = require('net');
@@ -1555,6 +1595,7 @@ async function runSpoolWatcher(instance, spoolDir) {
1555
1595
  fs.mkdirSync(outDir, { recursive: true });
1556
1596
 
1557
1597
  try { ensureSpoolPollGate(process.env.CLAUDE_PROJECT_DIR || process.cwd()); } catch (_) {}
1598
+ try { ensureAcptoapi(); } catch (_) {}
1558
1599
 
1559
1600
  const LOCK_PATH = path.join(spoolDir, '.watcher.lock');
1560
1601
  let _ownWrapperSha12 = '';
@@ -2061,6 +2102,7 @@ async function runSpoolWatcher(instance, spoolDir) {
2061
2102
  }
2062
2103
  setInterval(writeStatus, 5000);
2063
2104
  writeStatus();
2105
+ setInterval(() => { try { ensureAcptoapi(); } catch (_) {} }, 60000);
2064
2106
 
2065
2107
  const UPDATE_AVAILABLE_PATH = path.join(spoolDir, '.update-available.json');
2066
2108
  const UPDATE_CHECK_INTERVAL_MS = 5 * 60 * 1000;