gm-skill 2.0.1175 → 2.0.1177

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 CHANGED
@@ -35,7 +35,7 @@ An earlier generation fanned out fifteen per-platform downstream repos (gm-cc, g
35
35
 
36
36
  ## Version
37
37
 
38
- `2.0.1175` — auto-bumped from the canonical `gm` repo. Every push to `AnEntrypoint/gm` (or any cascading sibling crate) republishes this package.
38
+ `2.0.1177` — auto-bumped from the canonical `gm` repo. Every push to `AnEntrypoint/gm` (or any cascading sibling crate) republishes this package.
39
39
 
40
40
  ## Source of truth
41
41
 
@@ -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 {
@@ -1022,6 +1039,46 @@ async function runSpoolWatcher(instance, spoolDir) {
1022
1039
  acquireLock();
1023
1040
  setInterval(refreshLock, 5000);
1024
1041
 
1042
+ const PEER_REGISTRY_PATH = path.join(os.homedir(), '.claude', 'gm-tools', 'peer-registry.json');
1043
+ function registerSelfAsPeer() {
1044
+ try {
1045
+ let reg = {};
1046
+ try { reg = JSON.parse(fs.readFileSync(PEER_REGISTRY_PATH, 'utf-8')); } catch (_) {}
1047
+ reg[process.cwd()] = { pid: process.pid, ts: Date.now(), sha: _ownWrapperSha12 };
1048
+ fs.writeFileSync(PEER_REGISTRY_PATH, JSON.stringify(reg, null, 2));
1049
+ } catch (_) {}
1050
+ }
1051
+ registerSelfAsPeer();
1052
+ setInterval(registerSelfAsPeer, 30_000);
1053
+
1054
+ function sweepStalePeers() {
1055
+ if (!_ownWrapperSha12) return;
1056
+ let reg = {};
1057
+ try { reg = JSON.parse(fs.readFileSync(PEER_REGISTRY_PATH, 'utf-8')); } catch (_) { return; }
1058
+ for (const peerCwd of Object.keys(reg)) {
1059
+ if (peerCwd === process.cwd()) continue;
1060
+ const peerLock = path.join(peerCwd, '.gm', 'exec-spool', '.watcher.lock');
1061
+ let content = '';
1062
+ try { content = fs.readFileSync(peerLock, 'utf-8').trim(); } catch (_) { continue; }
1063
+ const parts = content.split('|');
1064
+ const peerPid = parseInt(parts[0], 10);
1065
+ const peerTs = parseInt(parts[1], 10);
1066
+ const peerSha = parts[2] || '';
1067
+ if (!peerPid || !peerSha) continue;
1068
+ const age = Date.now() - peerTs;
1069
+ if (age > 15000) continue;
1070
+ if (peerSha === _ownWrapperSha12) continue;
1071
+ try {
1072
+ process.kill(peerPid, 0);
1073
+ } catch (_) { continue; }
1074
+ logEvent('plugkit', 'peer.stale-wrapper-killed', { peer_cwd: peerCwd, peer_pid: peerPid, peer_sha: peerSha, own_sha: _ownWrapperSha12, lock_age_ms: age });
1075
+ console.error(`[plugkit-wasm] peer-sweep killing stale-wrapper watcher pid=${peerPid} cwd=${peerCwd} sha=${peerSha} (own=${_ownWrapperSha12})`);
1076
+ try { process.kill(peerPid, 'SIGTERM'); } catch (_) {}
1077
+ }
1078
+ }
1079
+ setInterval(sweepStalePeers, 60_000);
1080
+ setTimeout(sweepStalePeers, 5000);
1081
+
1025
1082
  const IDLE_LIMIT_MS = parseInt(process.env.PLUGKIT_IDLE_LIMIT_MS, 10) || 15 * 60 * 1000;
1026
1083
  const IDLE_CHECK_MS = 60_000;
1027
1084
  const SHUTDOWN_REASON_PATH = path.join(spoolDir, '.shutdown-reason.json');
package/gm.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gm",
3
- "version": "2.0.1175",
3
+ "version": "2.0.1177",
4
4
  "description": "Spool-dispatch orchestration engine with unified state machine, skills, and automated git enforcement",
5
5
  "author": "AnEntrypoint",
6
6
  "license": "MIT",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gm-skill",
3
- "version": "2.0.1175",
3
+ "version": "2.0.1177",
4
4
  "description": "Canonical universal harness — AI-native software engineering via skill-driven orchestration; bootstraps plugkit for task execution and session isolation. Install in any AI coding agent host.",
5
5
  "author": "AnEntrypoint",
6
6
  "license": "MIT",
@@ -39,7 +39,7 @@
39
39
  "gm.json"
40
40
  ],
41
41
  "dependencies": {
42
- "gm-plugkit": "^2.0.1175"
42
+ "gm-plugkit": "^2.0.1177"
43
43
  },
44
44
  "engines": {
45
45
  "node": ">=16.0.0"