shellpuppet 0.2.0 → 0.2.1

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.
@@ -329,6 +329,17 @@
329
329
  arrange('window removed');
330
330
  renderShareCount();
331
331
  }
332
+ function markWindowGone(id, instance) {
333
+ if (validWindowId(instance)) {
334
+ const now = Date.now();
335
+ for (const [pair, closedAt] of goneWindows) if (now - closedAt > 600_000) goneWindows.delete(pair);
336
+ const pair = windowPair(id, instance);
337
+ goneWindows.delete(pair);
338
+ goneWindows.set(pair, now);
339
+ while (goneWindows.size > 64) goneWindows.delete(goneWindows.keys().next().value);
340
+ }
341
+ removeWindow(id, instance);
342
+ }
332
343
  function openDashboard(hash, name, features) {
333
344
  const child = window.open(`${location.origin}/dashboard${hash}`, name, features);
334
345
  if (child === null) showError('The browser blocked the window. Press the button again.');
@@ -349,14 +360,13 @@
349
360
  lastSeen.set(windowPair(id, null), Date.now());
350
361
  renderScreens();
351
362
  publishAssignment();
352
- const watch = { id, child, pair: windowPair(id, null), closedAt: null, timer: null };
363
+ const watch = { id, child, instance: null, pair: windowPair(id, null), closedAt: null, timer: null };
353
364
  watch.timer = setInterval(() => {
354
365
  if (!child.closed) return;
355
366
  if (watch.closedAt === null) { watch.closedAt = Date.now(); return; }
356
367
  if (Date.now() - watch.closedAt < 1500) return;
357
- for (const [pair, entry] of windows) {
358
- if (entry.id === id && (lastSeen.get(pair) ?? 0) <= watch.closedAt) removeWindow(entry.id, entry.instance);
359
- }
368
+ // A duplicate shares the screen id, but only this child's instance has closed.
369
+ markWindowGone(watch.id, watch.instance);
360
370
  clearInterval(watch.timer);
361
371
  childWatches.delete(watch.pair);
362
372
  }, 250);
@@ -979,13 +989,7 @@
979
989
  if (!frame || typeof frame.type !== 'string') return;
980
990
  if (frame.type === 'window-gone' && validWindowId(frame.id) && validWindowId(frame.instance)) {
981
991
  if (popSelf !== null) return;
982
- const now = Date.now();
983
- for (const [pair, closedAt] of goneWindows) if (now - closedAt > 600_000) goneWindows.delete(pair);
984
- const pair = JSON.stringify([frame.id, frame.instance]);
985
- goneWindows.delete(pair);
986
- goneWindows.set(pair, now);
987
- while (goneWindows.size > 64) goneWindows.delete(goneWindows.keys().next().value);
988
- removeWindow(frame.id, frame.instance);
992
+ markWindowGone(frame.id, frame.instance);
989
993
  return;
990
994
  }
991
995
  if (frame.type === 'snapshot' && Array.isArray(frame.sessions)) reconcile(frame.sessions, true);
@@ -1340,6 +1344,7 @@
1340
1344
  } catch { continue; }
1341
1345
  childWatches.delete(watch.pair);
1342
1346
  watch.pair = pair;
1347
+ watch.instance = data.window.instance;
1343
1348
  childWatches.set(pair, watch);
1344
1349
  }
1345
1350
  const fresh = !windows.has(pair);
@@ -1355,7 +1360,7 @@
1355
1360
  return;
1356
1361
  }
1357
1362
  if (data.type === 'window-leave' && validWindowId(data.id) && validWindowId(data.instance)) {
1358
- removeWindow(data.id, data.instance);
1363
+ markWindowGone(data.id, data.instance);
1359
1364
  return;
1360
1365
  }
1361
1366
  if (data.type === 'window-assignment' && popSelf === null && windows.size > 1 &&
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "shellpuppet",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "description": "Supervised terminal sessions for AI agents: an agent drives a real terminal while you watch, type and approve. Like Playwright, but for the terminal. An MCP server and CLI over a per-user daemon, with a live browser viewer on the same session.",
5
5
  "license": "Apache-2.0",
6
6
  "author": "Red Eagle Tech Ltd",