gm-plugkit 2.0.1174 → 2.0.1176

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.1174",
3
+ "version": "2.0.1176",
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": {
@@ -987,30 +987,47 @@ async function runSpoolWatcher(instance, spoolDir) {
987
987
  fs.mkdirSync(outDir, { recursive: true });
988
988
 
989
989
  const LOCK_PATH = path.join(spoolDir, '.watcher.lock');
990
+ let _ownWrapperSha12 = '';
991
+ try {
992
+ const _crypto = require('crypto');
993
+ const _wp = path.join(os.homedir(), '.claude', 'gm-tools', 'plugkit-wasm-wrapper.js');
994
+ _ownWrapperSha12 = _crypto.createHash('sha256').update(fs.readFileSync(_wp)).digest('hex').slice(0, 12);
995
+ } catch (_) {}
996
+ function lockBody() { return `${process.pid}|${Date.now()}|${_ownWrapperSha12}`; }
990
997
  function acquireLock() {
991
998
  try {
992
999
  if (fs.existsSync(LOCK_PATH)) {
993
1000
  const content = fs.readFileSync(LOCK_PATH, 'utf-8').trim();
994
- const [pidStr, tsStr] = content.split('|');
1001
+ const parts = content.split('|');
1002
+ const pidStr = parts[0];
1003
+ const tsStr = parts[1];
1004
+ const holderSha = parts[2] || '';
995
1005
  const lockTs = parseInt(tsStr, 10);
996
1006
  const age = Date.now() - lockTs;
997
1007
  if (age < 15000) {
998
- const msg = JSON.stringify({ ok: false, reason: 'another-watcher-active', pid: pidStr, age_ms: age });
999
- console.error(`[plugkit-wasm] ${msg}; refusing to start`);
1000
- try { fs.writeFileSync(path.join(spoolDir, '.lock-rejection.json'), msg); } catch (_) {}
1001
- try { logEvent('plugkit', 'watcher.lock-rejected', { holder_pid: pidStr, lock_age_ms: age }); } catch (_) {}
1002
- process.exit(75);
1008
+ if (_ownWrapperSha12 && holderSha && holderSha !== _ownWrapperSha12) {
1009
+ try { logEvent('plugkit', 'peer.stale-wrapper-takeover', { holder_pid: pidStr, holder_sha: holderSha, own_sha: _ownWrapperSha12, lock_age_ms: age }); } catch (_) {}
1010
+ console.error(`[plugkit-wasm] peer wrapper-sha mismatch (holder=${holderSha} own=${_ownWrapperSha12}); killing pid=${pidStr} and taking over`);
1011
+ try { process.kill(parseInt(pidStr, 10), 'SIGTERM'); } catch (_) {}
1012
+ } else {
1013
+ const msg = JSON.stringify({ ok: false, reason: 'another-watcher-active', pid: pidStr, age_ms: age });
1014
+ console.error(`[plugkit-wasm] ${msg}; refusing to start`);
1015
+ try { fs.writeFileSync(path.join(spoolDir, '.lock-rejection.json'), msg); } catch (_) {}
1016
+ try { logEvent('plugkit', 'watcher.lock-rejected', { holder_pid: pidStr, lock_age_ms: age }); } catch (_) {}
1017
+ process.exit(75);
1018
+ }
1019
+ } else {
1020
+ console.error(`[plugkit-wasm] stale lock (age=${age}ms); taking over`);
1003
1021
  }
1004
- console.error(`[plugkit-wasm] stale lock (age=${age}ms); taking over`);
1005
1022
  }
1006
- fs.writeFileSync(LOCK_PATH, `${process.pid}|${Date.now()}`);
1023
+ fs.writeFileSync(LOCK_PATH, lockBody());
1007
1024
  } catch (e) {
1008
1025
  console.error(`[plugkit-wasm] lock acquire failed: ${e.message}`);
1009
1026
  process.exit(1);
1010
1027
  }
1011
1028
  }
1012
1029
  function refreshLock() {
1013
- try { fs.writeFileSync(LOCK_PATH, `${process.pid}|${Date.now()}`); } catch (_) {}
1030
+ try { fs.writeFileSync(LOCK_PATH, lockBody()); } catch (_) {}
1014
1031
  }
1015
1032
  function releaseLock() {
1016
1033
  try {
package/plugkit.sha256 CHANGED
@@ -1 +1 @@
1
- {"plugkit.wasm":"3a2ef1778824dc57388253d2175f24bc3cd390ceb3fde6d902743c58fe03ebdb"}
1
+ {"plugkit.wasm":"6e4d5f1dd88d74e7adf2058e4668a42548a74452a14c33e6561838c8bf9acbef"}
package/plugkit.version CHANGED
@@ -1 +1 @@
1
- 0.1.424
1
+ 0.1.425