gm-plugkit 2.0.1167 → 2.0.1169

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.1167",
3
+ "version": "2.0.1169",
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": {
@@ -56,10 +56,11 @@ function turnTick(sess, verb, taskBase, phase) {
56
56
  if (phase) { t.phases.add(phase); t.lastPhase = phase; }
57
57
  }
58
58
 
59
- let __sessCache = { value: '', mtimeMs: 0, readAt: 0 };
59
+ let __sessCache = { value: '', mtimeMs: 0, readAt: 0, srcMtimeMs: 0 };
60
60
  function readCurrentSess() {
61
61
  const now = Date.now();
62
62
  if (now - __sessCache.readAt < 1000) return __sessCache.value;
63
+ let found = '';
63
64
  try {
64
65
  const p = path.join(process.cwd(), '.gm', 'exec-spool', '.session-current');
65
66
  const st = fs.statSync(p);
@@ -67,9 +68,24 @@ function readCurrentSess() {
67
68
  __sessCache.value = fs.readFileSync(p, 'utf8').trim();
68
69
  __sessCache.mtimeMs = st.mtimeMs;
69
70
  }
71
+ found = __sessCache.value;
70
72
  } catch (_) {}
73
+ if (!found) {
74
+ try {
75
+ const sp = path.join(process.cwd(), '.gm', 'turn-state.json');
76
+ const st = fs.statSync(sp);
77
+ if (st.mtimeMs !== __sessCache.srcMtimeMs) {
78
+ const obj = JSON.parse(fs.readFileSync(sp, 'utf8'));
79
+ if (obj && typeof obj.session_id === 'string') found = obj.session_id;
80
+ __sessCache.srcMtimeMs = st.mtimeMs;
81
+ } else if (__sessCache.value) {
82
+ found = __sessCache.value;
83
+ }
84
+ } catch (_) {}
85
+ }
71
86
  __sessCache.readAt = now;
72
- return __sessCache.value || process.env.CLAUDE_SESSION_ID || process.env.GM_SESSION_ID || '';
87
+ __sessCache.value = found || process.env.CLAUDE_SESSION_ID || process.env.GM_SESSION_ID || '';
88
+ return __sessCache.value;
73
89
  }
74
90
 
75
91
  function logEvent(sub, event, fields) {
@@ -1273,8 +1289,10 @@ async function runSpoolWatcher(instance, spoolDir) {
1273
1289
  const files = [];
1274
1290
  try {
1275
1291
  for (const entry of fs.readdirSync(dir)) {
1292
+ if (/\.tmp\.\d+(\.|$)/.test(entry)) continue;
1276
1293
  const fullPath = path.join(dir, entry);
1277
- const stat = fs.statSync(fullPath);
1294
+ let stat;
1295
+ try { stat = fs.statSync(fullPath); } catch (_) { continue; }
1278
1296
  if (stat.isFile()) {
1279
1297
  files.push(fullPath);
1280
1298
  } else if (stat.isDirectory()) {
@@ -1391,10 +1409,12 @@ async function runSpoolWatcher(instance, spoolDir) {
1391
1409
  let stale = 0;
1392
1410
  const walk = (dir) => {
1393
1411
  for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
1412
+ if (/\.tmp\.\d+(\.|$)/.test(entry.name)) continue;
1394
1413
  const fp = path.join(dir, entry.name);
1395
1414
  if (entry.isDirectory()) walk(fp);
1396
1415
  else if (entry.isFile()) {
1397
- const s = fs.statSync(fp);
1416
+ let s;
1417
+ try { s = fs.statSync(fp); } catch (_) { continue; }
1398
1418
  if (s.mtimeMs < cutoff) {
1399
1419
  const rel = path.relative(inDir, fp);
1400
1420
  const verbDir = path.dirname(rel);