gm-plugkit 2.0.1262 → 2.0.1264

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.1262",
3
+ "version": "2.0.1264",
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": {
@@ -27,6 +27,35 @@ const ORCHESTRATOR_VERBS = new Set(['instruction', 'transition', 'phase-status',
27
27
  const TURN_IDLE_MS = 30_000;
28
28
  const _turns = new Map();
29
29
 
30
+ function emitShutdownReason(reason, err) {
31
+ try {
32
+ const spoolDir = process.env.CLAUDE_PROJECT_DIR
33
+ ? path.join(process.env.CLAUDE_PROJECT_DIR, '.gm', 'exec-spool')
34
+ : path.join(process.cwd(), '.gm', 'exec-spool');
35
+ fs.mkdirSync(spoolDir, { recursive: true });
36
+ const body = {
37
+ reason,
38
+ ts: Date.now(),
39
+ pid: process.pid,
40
+ message: err && (err.message || String(err)),
41
+ stack: err && err.stack ? String(err.stack).slice(0, 4000) : null,
42
+ version: typeof PLUGKIT_VERSION !== 'undefined' ? PLUGKIT_VERSION : null,
43
+ };
44
+ fs.writeFileSync(path.join(spoolDir, '.shutdown-reason.json'), JSON.stringify(body, null, 2));
45
+ } catch (_) {}
46
+ }
47
+
48
+ process.on('uncaughtException', (err) => {
49
+ try { console.error('[plugkit-wasm] uncaught:', err && err.stack || err); } catch (_) {}
50
+ emitShutdownReason('uncaughtException', err);
51
+ process.exit(1);
52
+ });
53
+
54
+ process.on('unhandledRejection', (reason) => {
55
+ try { console.error('[plugkit-wasm] unhandled rejection:', reason && reason.stack || reason); } catch (_) {}
56
+ emitShutdownReason('unhandledRejection', reason instanceof Error ? reason : new Error(String(reason)));
57
+ process.exit(1);
58
+ });
30
59
 
31
60
  function applyDisciplineSigil(rawBody) {
32
61
  let parsed;
@@ -270,6 +299,8 @@ function readCurrentSess() {
270
299
  return __sessCache.value;
271
300
  }
272
301
 
302
+ const __lockRejectedEmitAt = new Map();
303
+
273
304
  function logEvent(sub, event, fields) {
274
305
  if (process.env.GM_LOG_DISABLE) return;
275
306
  try {
@@ -1433,7 +1464,14 @@ async function runSpoolWatcher(instance, spoolDir) {
1433
1464
  const msg = JSON.stringify({ ok: false, reason: 'another-watcher-active', pid: pidStr, age_ms: age });
1434
1465
  console.error(`[plugkit-wasm] ${msg}; refusing to start`);
1435
1466
  try { fs.writeFileSync(path.join(spoolDir, '.lock-rejection.json'), msg); } catch (_) {}
1436
- try { logEvent('plugkit', 'watcher.lock-rejected', { holder_pid: pidStr, lock_age_ms: age }); } catch (_) {}
1467
+ try {
1468
+ const __now = Date.now();
1469
+ const __last = __lockRejectedEmitAt.get(pidStr) || 0;
1470
+ if (__now - __last > 60000) {
1471
+ __lockRejectedEmitAt.set(pidStr, __now);
1472
+ logEvent('plugkit', 'watcher.lock-rejected', { severity: 'info', holder_pid: pidStr, lock_age_ms: age });
1473
+ }
1474
+ } catch (_) {}
1437
1475
  process.exit(75);
1438
1476
  }
1439
1477
  } else {