gm-plugkit 2.0.1718 → 2.0.1719

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.1718",
3
+ "version": "2.0.1719",
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": {
@@ -608,7 +608,12 @@ function stampBrowserLastUse(cwd, claudeSessionId) {
608
608
  function atomicWriteRaw(filePath, data) {
609
609
  const tmp = filePath + '.tmp.' + process.pid + '.' + Date.now() + '.' + Math.random().toString(36).slice(2, 8);
610
610
  fs.writeFileSync(tmp, data);
611
- fs.renameSync(tmp, filePath);
611
+ try {
612
+ fs.renameSync(tmp, filePath);
613
+ } catch (err) {
614
+ try { fs.unlinkSync(tmp); } catch (_) {}
615
+ throw err;
616
+ }
612
617
  }
613
618
 
614
619
  function atomicWriteJson(filePath, obj) {
@@ -2913,6 +2918,22 @@ async function runSpoolWatcher(instance, spoolDir) {
2913
2918
  }
2914
2919
  writeBootActive();
2915
2920
 
2921
+ function sweepStaleAtomicTmpFiles(dir, maxAgeMs) {
2922
+ try {
2923
+ const entries = fs.readdirSync(dir);
2924
+ const now = Date.now();
2925
+ for (const name of entries) {
2926
+ if (!/\.tmp(\.|$)/.test(name)) continue;
2927
+ const full = path.join(dir, name);
2928
+ try {
2929
+ const st = fs.statSync(full);
2930
+ if (now - st.mtimeMs > maxAgeMs) fs.unlinkSync(full);
2931
+ } catch (_) {}
2932
+ }
2933
+ } catch (_) {}
2934
+ }
2935
+ sweepStaleAtomicTmpFiles(GM_TOOLS_ROOT, 10 * 60 * 1000);
2936
+
2916
2937
  const PEER_REGISTRY_PATH = path.join(GM_TOOLS_ROOT, 'peer-registry.json');
2917
2938
  function registerSelfAsPeer() {
2918
2939
  try {
@@ -3942,12 +3963,15 @@ async function runSpoolWatcher(instance, spoolDir) {
3942
3963
  return null;
3943
3964
  }
3944
3965
  function writeSharedUpdateCache(latest, status) {
3966
+ let tmp = null;
3945
3967
  try {
3946
3968
  fs.mkdirSync(path.dirname(UPDATE_CHECK_SHARED_CACHE), { recursive: true });
3947
- const tmp = UPDATE_CHECK_SHARED_CACHE + '.tmp.' + process.pid;
3969
+ tmp = UPDATE_CHECK_SHARED_CACHE + '.tmp.' + process.pid;
3948
3970
  fs.writeFileSync(tmp, JSON.stringify({ ts: Date.now(), latest, status, by_pid: process.pid }));
3949
3971
  fs.renameSync(tmp, UPDATE_CHECK_SHARED_CACHE);
3950
- } catch (_) {}
3972
+ } catch (_) {
3973
+ if (tmp) { try { fs.unlinkSync(tmp); } catch (_) {} }
3974
+ }
3951
3975
  }
3952
3976
  const UPDATE_CHECK_ERROR_MARKER = path.join(GM_TOOLS_ROOT, '.update-check-error.json');
3953
3977
  let _lastKnownUpdateError = null;
@@ -3962,11 +3986,13 @@ async function runSpoolWatcher(instance, spoolDir) {
3962
3986
  return null;
3963
3987
  }
3964
3988
  function writeSharedUpdateErrorKey(key) {
3989
+ const tmp = UPDATE_CHECK_ERROR_MARKER + '.tmp.' + process.pid;
3965
3990
  try {
3966
- const tmp = UPDATE_CHECK_ERROR_MARKER + '.tmp';
3967
3991
  fs.writeFileSync(tmp, JSON.stringify({ ts: Date.now(), key, by_pid: process.pid }));
3968
3992
  fs.renameSync(tmp, UPDATE_CHECK_ERROR_MARKER);
3969
- } catch (_) {}
3993
+ } catch (_) {
3994
+ try { fs.unlinkSync(tmp); } catch (_) {}
3995
+ }
3970
3996
  }
3971
3997
  function clearSharedUpdateErrorKey() {
3972
3998
  try { fs.unlinkSync(UPDATE_CHECK_ERROR_MARKER); } catch (_) {}