shellpuppet 0.4.2 → 0.5.0

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.
Files changed (72) hide show
  1. package/README.md +16 -5
  2. package/dist/agents/agy/index.js +1 -1
  3. package/dist/agents/agy/index.js.map +1 -1
  4. package/dist/agents/claude/index.js +1 -1
  5. package/dist/agents/claude/index.js.map +1 -1
  6. package/dist/agents/codex/draft.js +13 -6
  7. package/dist/agents/codex/draft.js.map +1 -1
  8. package/dist/agents/codex/index.js +1 -1
  9. package/dist/agents/codex/index.js.map +1 -1
  10. package/dist/agents/codex/nudge.js +7 -1
  11. package/dist/agents/codex/nudge.js.map +1 -1
  12. package/dist/agents/grok/index.js +1 -1
  13. package/dist/agents/grok/index.js.map +1 -1
  14. package/dist/agents/grok/nudge.js +13 -5
  15. package/dist/agents/grok/nudge.js.map +1 -1
  16. package/dist/agents/hermes/frame.js +4 -4
  17. package/dist/agents/hermes/frame.js.map +1 -1
  18. package/dist/agents/hermes/index.js +1 -1
  19. package/dist/agents/hermes/index.js.map +1 -1
  20. package/dist/agents/mimo/index.js +1 -1
  21. package/dist/agents/mimo/index.js.map +1 -1
  22. package/dist/agents/muse/index.js +1 -1
  23. package/dist/agents/muse/index.js.map +1 -1
  24. package/dist/agents/muse/nudge.js +8 -3
  25. package/dist/agents/muse/nudge.js.map +1 -1
  26. package/dist/agents/nudgeReading.d.ts +2 -0
  27. package/dist/agents/nudgeReading.js +3 -3
  28. package/dist/agents/nudgeReading.js.map +1 -1
  29. package/dist/agents/opencode/index.js +1 -1
  30. package/dist/agents/opencode/index.js.map +1 -1
  31. package/dist/agents/qoder/index.js +1 -1
  32. package/dist/agents/qoder/index.js.map +1 -1
  33. package/dist/agents/types.d.ts +4 -0
  34. package/dist/cli/index.js +244 -5
  35. package/dist/cli/index.js.map +1 -1
  36. package/dist/client/http.d.ts +3 -0
  37. package/dist/client/http.js +7 -0
  38. package/dist/client/http.js.map +1 -1
  39. package/dist/client/input.d.ts +18 -0
  40. package/dist/client/input.js +15 -0
  41. package/dist/client/input.js.map +1 -1
  42. package/dist/core/session.d.ts +17 -2
  43. package/dist/core/session.js +52 -12
  44. package/dist/core/session.js.map +1 -1
  45. package/dist/core/windowsPtyStart.d.ts +2 -0
  46. package/dist/core/windowsPtyStart.js +6 -0
  47. package/dist/core/windowsPtyStart.js.map +1 -1
  48. package/dist/daemon/audit.d.ts +1 -1
  49. package/dist/daemon/audit.js +1 -1
  50. package/dist/daemon/index.js +1 -0
  51. package/dist/daemon/index.js.map +1 -1
  52. package/dist/daemon/launchProfiles.d.ts +6 -0
  53. package/dist/daemon/launchProfiles.js +21 -4
  54. package/dist/daemon/launchProfiles.js.map +1 -1
  55. package/dist/daemon/liveness.d.ts +11 -0
  56. package/dist/daemon/liveness.js +39 -0
  57. package/dist/daemon/liveness.js.map +1 -1
  58. package/dist/daemon/schedules.d.ts +1 -1
  59. package/dist/daemon/schedules.js +8 -3
  60. package/dist/daemon/schedules.js.map +1 -1
  61. package/dist/daemon/server.d.ts +13 -0
  62. package/dist/daemon/server.js +274 -58
  63. package/dist/daemon/server.js.map +1 -1
  64. package/dist/daemon/sessionFeed.d.ts +1 -1
  65. package/dist/daemon/sessionFeed.js +3 -1
  66. package/dist/daemon/sessionFeed.js.map +1 -1
  67. package/dist/mcp/tools.js +12 -9
  68. package/dist/mcp/tools.js.map +1 -1
  69. package/dist/viewer/dashboard.css +20 -7
  70. package/dist/viewer/dashboard.js +120 -31
  71. package/dist/viewer/pane.js +149 -20
  72. package/package.json +1 -1
@@ -119,9 +119,26 @@
119
119
  }
120
120
  function updateMessageBadge(item) {
121
121
  const count = unreadCount(item.id);
122
- item.messageCount.hidden = count === 0;
123
- item.messageCount.textContent = count ? `${count} ${count === 1 ? 'message' : 'messages'}` : '';
124
- item.messageCount.setAttribute('aria-label', `${count} unread messages for ${item.label.textContent}`);
122
+ const text = count ? `${count} ${count === 1 ? 'message' : 'messages'}` : '';
123
+ for (const button of [item.messageCount, item.menuMessageCount]) {
124
+ button.hidden = count === 0;
125
+ button.textContent = text;
126
+ button.title = text;
127
+ button.setAttribute('aria-label', `${count} unread messages for ${item.label.textContent}`);
128
+ }
129
+ updateMenuStatus(item);
130
+ }
131
+ function updateMenuStatus(item) {
132
+ const floor = item.floor.hidden ? '' : item.floor.textContent;
133
+ const full = [item.role.textContent, item.badge.textContent, item.messageCount.textContent,
134
+ item.state.textContent, item.size.textContent, floor].filter(Boolean).join(' · ');
135
+ item.menuStatus.textContent = full;
136
+ item.menuStatus.title = full;
137
+ item.menuStatus.hidden = !full;
138
+ const urgent = [item.badge.textContent, floor].filter(Boolean).join(' · ');
139
+ item.menuButton.classList.toggle('has-status', Boolean(urgent));
140
+ item.menuButton.title = urgent || 'More pane controls';
141
+ item.menuButton.setAttribute('aria-description', item.menuButton.title);
125
142
  }
126
143
  async function loadMessages() {
127
144
  messageTimer = null;
@@ -199,6 +216,7 @@
199
216
  ? saved.fontSize : saved.fontSize === null ? null
200
217
  : Number.isInteger(configuredFont) && configuredFont >= 8 && configuredFont <= 32 ? configuredFont : null;
201
218
  let autoFitTimer = null;
219
+ const pendingAutoFits = new Set();
202
220
  let fontFitFrame = null;
203
221
  let assignmentSettleUntil = 0;
204
222
  let assignmentSettleStartedAt = 0;
@@ -210,7 +228,6 @@
210
228
  } catch { /* Track sizes are optional. */ }
211
229
  let activeDivider = null;
212
230
  let endActiveDivider = null;
213
- const focusOpenFits = new Set();
214
231
  const incomingFits = new Set();
215
232
  let prefix = typeof saved.prefix === 'string' && /^[a-z]$/.test(saved.prefix) ? saved.prefix : 'a';
216
233
  let choosingPrefix = false;
@@ -398,32 +415,63 @@
398
415
  document.getElementById('text-auto').textContent = fontSize === null ? 'Auto text' : `${fontSize} px`;
399
416
  document.getElementById('text-auto').classList.toggle('active', fontSize === null);
400
417
  }
401
- function scheduleAutoFit() {
418
+ function paneFitSignature(item) {
419
+ if (!item.client || !visible(item)) return null;
420
+ return JSON.stringify([item.id, item.term.clientWidth, item.term.clientHeight,
421
+ fontSize, window.devicePixelRatio, item.metricsRevision || 0]);
422
+ }
423
+ function scheduleAutoFit(items = shown(), reason = 'layout') {
402
424
  scheduleFontFit();
425
+ for (const item of items) {
426
+ const signature = paneFitSignature(item);
427
+ const changed = signature !== item.fitSignature;
428
+ if (changed) {
429
+ item.fitSignature = signature;
430
+ item.client?.registerLayout(autoFit && signature !== null);
431
+ } else if (reason === 'connect') item.client?.registerLayout(autoFit && signature !== null, false);
432
+ if (signature !== null && (changed || reason !== 'layout')) pendingAutoFits.add(item);
433
+ if (signature === null) pendingAutoFits.delete(item);
434
+ }
403
435
  clearTimeout(autoFitTimer);
404
436
  if (activeDivider) return;
405
- if (!autoFit) { focusOpenFits.clear(); return; }
437
+ if (!autoFit) { pendingAutoFits.clear(); return; }
438
+ if (pendingAutoFits.size === 0) return;
406
439
  autoFitTimer = setTimeout(() => {
407
440
  autoFitTimer = null;
408
- if (window.performance.now() < assignmentSettleUntil) { scheduleAutoFit(); return; }
409
- assignmentSettleStartedAt = 0;
410
- assignmentSettleUntil = 0;
411
- for (const item of shown()) {
412
- if (!visible(item) || item.client?.isTemporaryGeometry()) continue;
413
- item.client?.autoFitGrid(80, 24, focusOpenFits.has(item.id) || incomingFits.has(item.id));
441
+ if (window.performance.now() < assignmentSettleUntil) {
442
+ autoFitTimer = setTimeout(() => flushAutoFits(), assignmentSettleUntil - window.performance.now());
443
+ return;
414
444
  }
445
+ flushAutoFits();
415
446
  }, assignmentSettleUntil ? Math.max(0, assignmentSettleUntil - window.performance.now()) : 250);
416
447
  }
448
+ function flushAutoFits() {
449
+ autoFitTimer = null;
450
+ if (window.performance.now() < assignmentSettleUntil) {
451
+ autoFitTimer = setTimeout(flushAutoFits, assignmentSettleUntil - window.performance.now());
452
+ return;
453
+ }
454
+ assignmentSettleStartedAt = 0;
455
+ assignmentSettleUntil = 0;
456
+ for (const item of pendingAutoFits) {
457
+ if (!visible(item) || item.client?.isTemporaryGeometry()) continue;
458
+ item.client?.autoFitGrid(80, 24,
459
+ incomingFits.has(item.id) && item.client?.hasTransferOffer());
460
+ }
461
+ pendingAutoFits.clear();
462
+ }
417
463
  function fitFonts() {
418
464
  const visiblePanes = shown().filter((item) => item.client && visible(item));
419
465
  const below = new Set();
420
466
  let shared = Infinity;
421
467
  for (const item of visiblePanes) {
422
- // The note can wrap the header. Test without it, then measure the
423
- // remaining terminal space with the note in place.
468
+ // Update the notice after measuring the terminal area.
424
469
  item.card.classList.remove('below-floor');
470
+ item.floor.hidden = true;
425
471
  const isBelow = item.client.belowDashboardFloor();
426
472
  item.card.classList.toggle('below-floor', isBelow);
473
+ item.floor.hidden = !isBelow;
474
+ updateMenuStatus(item);
427
475
  if (isBelow) {
428
476
  below.add(item);
429
477
  const font = item.client.floorFontSize();
@@ -553,11 +601,17 @@
553
601
  space.className = 'spacer';
554
602
  const size = document.createElement('span');
555
603
  size.className = 'pane-size';
604
+ const floor = document.createElement('span');
605
+ floor.className = 'pane-floor';
606
+ floor.textContent = 'Below 80×24 floor';
607
+ floor.title = floor.textContent;
608
+ floor.hidden = true;
556
609
  const overflowNote = document.createElement('div');
557
610
  overflowNote.className = 'pane-overflow-note';
558
611
  overflowNote.textContent = 'Shift+wheel or drag the scrollbars to see the rest. Enlarge or Fit to show it whole.';
559
612
  overflowNote.hidden = true;
560
- const item = { id: summary.id, summary, card, label, purpose, role, badge, messageCount, state, size, overflowNote, client: null, previousGrid: null };
613
+ const item = { id: summary.id, summary, card, label, purpose, role, badge, messageCount, state, size, floor,
614
+ overflowNote, client: null, previousGrid: null, fitRevision: 0 };
561
615
  const renameForm = document.createElement('form');
562
616
  renameForm.className = 'pane-rename';
563
617
  renameForm.hidden = true;
@@ -593,6 +647,11 @@
593
647
  item.fit = makeButton('Fit', () => { select(item.id); item.client?.fitGrid(); });
594
648
  item.enlarge = makeButton('Enlarge', () => {
595
649
  select(item.id);
650
+ // A queued Enlarge fit must not run after a later Restore of this pane.
651
+ const fitRevision = ++item.fitRevision;
652
+ const fitAfterLayout = (fit) => window.requestAnimationFrame(() => {
653
+ if (item.fitRevision === fitRevision) fit();
654
+ });
596
655
  if (enlarged === item.id) {
597
656
  enlarged = null;
598
657
  arrange('restore');
@@ -601,13 +660,13 @@
601
660
  else item.client?.takeGrid(item.previousGrid.cols, item.previousGrid.rows);
602
661
  }
603
662
  item.previousGrid = null;
604
- if (autoFit) window.requestAnimationFrame(() => item.client?.autoFitGrid(80, 24, true));
663
+ if (autoFit) fitAfterLayout(() => item.client?.autoFitGrid(80, 24, true));
605
664
  } else {
606
665
  item.previousGrid = item.client?.getGrid() || null;
607
666
  enlarged = item.id;
608
667
  arrange('enlarge');
609
- if (autoFit) window.requestAnimationFrame(() => item.client?.autoFitGrid(80, 24, true));
610
- if (!autoFit) window.requestAnimationFrame(() => item.client?.fitGrid());
668
+ if (autoFit) fitAfterLayout(() => item.client?.autoFitGrid(80, 24, true));
669
+ if (!autoFit) fitAfterLayout(() => item.client?.fitGrid());
611
670
  }
612
671
  });
613
672
  item.pin = makeButton('Pin', () => {
@@ -616,10 +675,27 @@
616
675
  });
617
676
  item.left = makeButton('Move left', () => move(item.id, -1));
618
677
  item.right = makeButton('Move right', () => move(item.id, 1));
678
+ for (const control of [item.enlarge, item.pin, item.left, item.right]) {
679
+ control.classList.add('pane-optional-control');
680
+ }
619
681
  item.menuButton = makeButton('Menu', () => { item.menu.hidden = !item.menu.hidden; });
682
+ item.menuButton.classList.add('pane-menu-button');
620
683
  const menu = document.createElement('div');
621
684
  menu.className = 'pane-menu';
622
685
  menu.hidden = true;
686
+ item.menuStatus = document.createElement('div');
687
+ item.menuStatus.className = 'pane-menu-status';
688
+ item.menuStatus.hidden = true;
689
+ item.menuMessageCount = makeButton('', () => openMessages(`session:${item.id}`));
690
+ item.menuMessageCount.className = 'pane-collapsed-control pane-menu-message-count';
691
+ item.menuMessageCount.hidden = true;
692
+ item.menuEnlarge = makeButton('Enlarge', () => item.enlarge.click());
693
+ item.menuPin = makeButton('Pin', () => item.pin.click());
694
+ item.menuLeft = makeButton('Move left', () => item.left.click());
695
+ item.menuRight = makeButton('Move right', () => item.right.click());
696
+ for (const control of [item.menuEnlarge, item.menuPin, item.menuLeft, item.menuRight]) {
697
+ control.classList.add('pane-collapsed-control');
698
+ }
623
699
  item.kill = makeButton('Kill', () => { void killSession(item.id); });
624
700
  item.kill.dataset.action = 'kill';
625
701
  item.copy = makeButton('Copy session id', () => { void copySessionId(item.id); });
@@ -630,9 +706,10 @@
630
706
  item.restart.dataset.action = 'restart';
631
707
  item.dismiss = makeButton('Dismiss', () => dismiss(item.id));
632
708
  item.dismiss.dataset.action = 'dismiss';
633
- menu.append(item.rename, item.kill, item.copy, item.pop, item.restart, item.dismiss);
709
+ menu.append(item.menuStatus, item.menuMessageCount, item.menuEnlarge, item.menuPin, item.menuLeft, item.menuRight,
710
+ item.rename, renameForm, item.kill, item.copy, item.pop, item.restart, item.dismiss);
634
711
  item.menu = menu;
635
- head.append(label, renameForm, purpose, role, badge, messageCount, state, space, size, item.fit, item.enlarge,
712
+ head.append(label, purpose, role, badge, messageCount, state, space, size, floor, item.fit, item.enlarge,
636
713
  item.pin, item.left, item.right, item.menuButton);
637
714
  head.addEventListener('dblclick', (event) => {
638
715
  if (!event.target.closest('button')) item.enlarge.click();
@@ -681,14 +758,18 @@
681
758
  function updateCard(item) {
682
759
  const summary = item.summary;
683
760
  item.label.textContent = summary.label || summary.id;
761
+ item.label.title = item.label.textContent;
684
762
  item.purpose.textContent = [summary.purpose, summary.parent && summary.startedBy && `Started by ${summary.startedBy}`].filter(Boolean).join(' · ');
685
- // Only a chair is marked in the header: a label on every pane would wrap a narrow header onto a second row.
763
+ item.purpose.title = item.purpose.textContent;
764
+ // Mark chairs explicitly; the label and purpose identify other panes.
686
765
  item.role.textContent = summary.role === 'chair' ? 'Chair' : '';
766
+ item.role.title = item.role.textContent;
687
767
  item.role.hidden = summary.role !== 'chair';
688
768
  item.card.dataset.role = summary.role === 'chair' ? 'chair' : 'delegate';
689
769
  item.badge.textContent = summary.stalled ? '● Stalled' : attention(item) ? '● Waiting' : '';
690
770
  item.badge.title = summary.stalled
691
- ? `${summary.stalled.reason} since ${summary.stalled.since}: ${summary.stalled.description}` : '';
771
+ ? `${item.badge.textContent}: ${summary.stalled.reason} since ${summary.stalled.since}: ${summary.stalled.description}`
772
+ : item.badge.textContent;
692
773
  item.card.classList.toggle('attention', attention(item));
693
774
  item.card.classList.toggle('selected', selected === item.id);
694
775
  item.card.classList.toggle('ended', summary.exited === true);
@@ -696,10 +777,15 @@
696
777
  : summary.exitCode === null || summary.exitCode === undefined
697
778
  ? 'Ended: its output failed'
698
779
  : `Ended (code ${String(summary.exitCode)})`;
780
+ item.state.title = item.state.textContent;
699
781
  item.pin.textContent = pins.includes(item.id) ? 'Unpin' : 'Pin';
700
782
  item.enlarge.textContent = enlarged === item.id ? 'Restore' : 'Enlarge';
783
+ item.menuPin.textContent = item.pin.textContent;
784
+ item.menuEnlarge.textContent = item.enlarge.textContent;
701
785
  item.pin.setAttribute('aria-label', item.pin.textContent);
702
786
  item.enlarge.setAttribute('aria-label', item.enlarge.textContent);
787
+ item.menuPin.setAttribute('aria-label', item.menuPin.textContent);
788
+ item.menuEnlarge.setAttribute('aria-label', item.menuEnlarge.textContent);
703
789
  item.restart.hidden = launchBody(launches[item.id]) === null;
704
790
  item.dismiss.hidden = summary.exited !== true;
705
791
  item.card.setAttribute('aria-label', `${item.label.textContent} ${item.purpose.textContent}`);
@@ -765,18 +851,19 @@
765
851
  elements: { banner: item.banner, copyNotice: item.copyNotice, promptAlert: item.prompt,
766
852
  size: item.size, overflowNote: item.overflowNote },
767
853
  onAttentionChange: () => updateAttention(),
768
- onGeometryReady: () => scheduleAutoFit(),
769
- onGeometryChange: () => scheduleFontFit(),
770
- onMetricsChange: () => scheduleAutoFit(),
854
+ onGeometryReady: (reason) => scheduleAutoFit([item], reason === 'connect' ? 'connect' : 'ready'),
855
+ onGeometryChange: () => { updateMenuStatus(item); scheduleFontFit(); },
856
+ onMetricsChange: () => { item.metricsRevision = (item.metricsRevision || 0) + 1; scheduleAutoFit([item]); },
771
857
  onOutsideGeometry: () => {
772
- focusOpenFits.delete(item.id);
773
858
  incomingFits.delete(item.id);
774
859
  scheduleFontFit();
775
860
  },
776
- onGridTaken: () => { focusOpenFits.delete(item.id); incomingFits.delete(item.id); },
861
+ onGridTaken: () => { incomingFits.delete(item.id); },
777
862
  });
778
863
  }
779
864
  function deactivate(item, reassigned = false) {
865
+ pendingAutoFits.delete(item);
866
+ item.fitSignature = null;
780
867
  if (!item.client) return;
781
868
  const client = item.client;
782
869
  item.client = null;
@@ -1166,7 +1253,6 @@
1166
1253
  const id = frame.move.session;
1167
1254
  movedSessions.add(id);
1168
1255
  pendingOpen.delete(id);
1169
- focusOpenFits.delete(id);
1170
1256
  for (const [target, session] of pendingWindowMoves) {
1171
1257
  if (session === id) pendingWindowMoves.delete(target);
1172
1258
  }
@@ -1238,7 +1324,6 @@
1238
1324
  pendingWindowMoves.clear();
1239
1325
  pendingOpen.clear();
1240
1326
  movedSessions.clear();
1241
- focusOpenFits.clear();
1242
1327
  endActiveDivider?.();
1243
1328
  applyAssignment([], {});
1244
1329
  root.replaceChildren();
@@ -1324,7 +1409,7 @@
1324
1409
  enlarged = null;
1325
1410
  persist();
1326
1411
  arrange('focus open');
1327
- if (autoFit) { focusOpenFits.add(id); scheduleAutoFit(); }
1412
+ if (autoFit) scheduleAutoFit([panes.get(id)], 'focus-open');
1328
1413
  else fitWhenReady(id, ownPair());
1329
1414
  }
1330
1415
  }
@@ -1530,6 +1615,8 @@
1530
1615
  if (data.type === 'preferences' && typeof data.autoFit === 'boolean' &&
1531
1616
  (data.fontSize === null || (Number.isInteger(data.fontSize) && data.fontSize >= 8 && data.fontSize <= 32))) {
1532
1617
  autoFit = data.autoFit;
1618
+ if (!autoFit) for (const item of panes.values()) item.client?.withdrawAutoFit();
1619
+ else for (const item of panes.values()) item.client?.resumeAutoFit();
1533
1620
  setFontSize(data.fontSize, false);
1534
1621
  }
1535
1622
  }
@@ -1588,7 +1675,9 @@
1588
1675
  assignmentSettleUntil = 0;
1589
1676
  assignmentSettleStartedAt = 0;
1590
1677
  autoFit = !autoFit;
1591
- renderPreferences(); persist(); scheduleAutoFit(); broadcastPreferences();
1678
+ if (!autoFit) for (const item of panes.values()) item.client?.withdrawAutoFit();
1679
+ else for (const item of panes.values()) item.client?.resumeAutoFit();
1680
+ renderPreferences(); persist(); scheduleAutoFit(shown(), 'toggle'); broadcastPreferences();
1592
1681
  });
1593
1682
  document.getElementById('designated-window').addEventListener('click', () => {
1594
1683
  if (feed?.readyState === WebSocket.OPEN) feed.send(JSON.stringify({ type: 'window-designate' }));
@@ -152,7 +152,21 @@ window.ShellPuppetPane = (() => {
152
152
  let pendingTakeGrid = false;
153
153
  let pendingTakeSize = null;
154
154
  let pendingTakeSocket = null;
155
- let followingExternal = false;
155
+ let followedGrid = null;
156
+ let choiceRevision = 0;
157
+ let layoutId = 0;
158
+ let realLayoutId = 0;
159
+ let nextTakeId = 0;
160
+ let pendingAuto = null;
161
+ let dirtyAuto = false;
162
+ let explicitHold = false;
163
+ let explicitHoldControllerRevision = 0;
164
+ let lastExplicitResizeRevision = 0;
165
+ let clearedExplicitResizeRevision = 0;
166
+ let pendingRealLayout = false;
167
+ let autoFitRequested = false;
168
+ let layoutEligible = false;
169
+ let layoutRecoveryUsed = false;
156
170
  let transferOffered = false;
157
171
  let temporaryGeometry = false;
158
172
  let dashboardFontLimit = null;
@@ -1132,6 +1146,7 @@ window.ShellPuppetPane = (() => {
1132
1146
  elements.size.textContent =
1133
1147
  `${cols}×${rows}` +
1134
1148
  (controlMode === 'held' ? ' (fixed)' : controlMode === 'adopt' ? ' (following)' : '');
1149
+ elements.size.title = elements.size.textContent;
1135
1150
  }
1136
1151
  positionNotices();
1137
1152
  onGeometryChange();
@@ -1165,6 +1180,27 @@ window.ShellPuppetPane = (() => {
1165
1180
  elements.inputSource.className = `hint ${who}`;
1166
1181
  }
1167
1182
 
1183
+ function registerDashboardLayout(eligible, real) {
1184
+ if (dashboardProof === null || !ws || ws.readyState !== 1 || !geometryDecided) return false;
1185
+ autoFitRequested = eligible;
1186
+ layoutId++;
1187
+ if (real) {
1188
+ realLayoutId = layoutId;
1189
+ layoutRecoveryUsed = false;
1190
+ pendingRealLayout = false;
1191
+ }
1192
+ const allowed = eligible && (real || !explicitHold) &&
1193
+ !(followedGrid === 'unowned' && belowDashboardFloor());
1194
+ layoutEligible = allowed;
1195
+ dirtyAuto = allowed;
1196
+ if (real) {
1197
+ explicitHold = false;
1198
+ clearedExplicitResizeRevision = lastExplicitResizeRevision;
1199
+ }
1200
+ ws.send(JSON.stringify({ type: 'layout', layoutId, eligible: allowed, real }));
1201
+ return true;
1202
+ }
1203
+
1168
1204
  function connect() {
1169
1205
  if (destroyed) return;
1170
1206
  ws = new WebSocket(`ws://${location.host}/sessions/${encodeURIComponent(sessionId)}/stream${passive ? '?drive=0' : ''}`,
@@ -1189,9 +1225,11 @@ window.ShellPuppetPane = (() => {
1189
1225
  if (elements.banner) elements.banner.hidden = true;
1190
1226
  retriesLeft = 8;
1191
1227
  geometryDecided = false;
1228
+ pendingAuto = null;
1229
+ dirtyAuto = false;
1230
+ layoutRecoveryUsed = false;
1192
1231
  if (pendingTakeSocket !== socket) {
1193
1232
  pendingTakeGrid = false;
1194
- pendingTakeSize = null;
1195
1233
  pendingTakeSocket = null;
1196
1234
  }
1197
1235
  };
@@ -1245,6 +1283,10 @@ window.ShellPuppetPane = (() => {
1245
1283
  } else if (control && control.type === 'geometry') {
1246
1284
  const firstGeometry = !geometryDecided;
1247
1285
  geometryDecided = true;
1286
+ if (typeof control.choiceRevision === 'number') {
1287
+ if (control.choiceRevision < choiceRevision) return;
1288
+ choiceRevision = control.choiceRevision;
1289
+ }
1248
1290
  controlMode = captureMode ? 'adopt' : control.control || 'adopt';
1249
1291
  const wasOffered = transferOffered;
1250
1292
  transferOffered = controlMode === 'adopt' && control.dashboardTransferable === true;
@@ -1252,16 +1294,17 @@ window.ShellPuppetPane = (() => {
1252
1294
  temporaryGeometry = control.temporary === true;
1253
1295
  if (pendingTakeSocket !== null && pendingTakeSocket !== socket) {
1254
1296
  pendingTakeGrid = false;
1255
- pendingTakeSize = null;
1256
1297
  pendingTakeSocket = null;
1257
1298
  }
1258
1299
  if (controlMode === 'held') {
1259
1300
  pendingTakeGrid = false;
1260
- pendingTakeSize = null;
1261
1301
  pendingTakeSocket = null;
1262
1302
  }
1303
+ const previouslyFollowed = followedGrid;
1304
+ if (dashboardProof !== null && firstGeometry && controlMode === 'adopt' &&
1305
+ control.owned !== true) followedGrid = null;
1263
1306
  if (dashboardProof !== null && firstGeometry && controlMode === 'yours') {
1264
- followingExternal = false;
1307
+ followedGrid = null;
1265
1308
  pendingTakeGrid = false;
1266
1309
  pendingTakeSize = null;
1267
1310
  pendingTakeSocket = null;
@@ -1269,27 +1312,74 @@ window.ShellPuppetPane = (() => {
1269
1312
  }
1270
1313
  if (dashboardProof !== null && (!firstGeometry || control.owned === true)) {
1271
1314
  if (controlMode === 'yours' && pendingTakeGrid) {
1272
- followingExternal = false;
1315
+ followedGrid = null;
1316
+ explicitHold = false;
1273
1317
  pendingTakeGrid = false;
1274
1318
  pendingTakeSize = null;
1275
1319
  pendingTakeSocket = null;
1276
1320
  onGridTaken();
1277
- } else if (controlMode === 'adopt' && !followingExternal && !transferOffered) {
1321
+ } else if (controlMode === 'adopt' && !transferOffered) {
1278
1322
  pendingTakeGrid = false;
1279
1323
  pendingTakeSize = null;
1280
1324
  pendingTakeSocket = null;
1281
- followingExternal = true;
1282
- onOutsideGeometry();
1325
+ followedGrid = control.owned ? 'owned' : 'unowned';
1326
+ if (previouslyFollowed !== followedGrid) onOutsideGeometry();
1283
1327
  } else if (transferOffered) {
1284
- followingExternal = false;
1328
+ followedGrid = null;
1285
1329
  }
1286
1330
  }
1331
+ if (controlMode === 'yours') followedGrid = null;
1332
+ const controllerRevision = Number.isSafeInteger(control.controllerChoiceRevision)
1333
+ ? control.controllerChoiceRevision : 0;
1334
+ const explicitRevision = Number.isSafeInteger(control.explicitResizeRevision)
1335
+ ? control.explicitResizeRevision : 0;
1336
+ lastExplicitResizeRevision = Math.max(lastExplicitResizeRevision, explicitRevision);
1337
+ let holdCleared = false;
1338
+ if (control.clientResize) {
1339
+ explicitHold = realLayoutId <= (control.layoutFence ?? realLayoutId);
1340
+ if (explicitHold) {
1341
+ explicitHoldControllerRevision = controllerRevision;
1342
+ dirtyAuto = false;
1343
+ } else clearedExplicitResizeRevision = lastExplicitResizeRevision;
1344
+ } else if (explicitHold && controllerRevision > explicitHoldControllerRevision) {
1345
+ explicitHold = false;
1346
+ holdCleared = true;
1347
+ } else if (firstGeometry && explicitRevision > controllerRevision) {
1348
+ if (explicitRevision > clearedExplicitResizeRevision) {
1349
+ explicitHold = true;
1350
+ explicitHoldControllerRevision = controllerRevision;
1351
+ dirtyAuto = false;
1352
+ } else pendingRealLayout = true;
1353
+ }
1354
+ const resolvedAuto = pendingAuto &&
1355
+ (control.acceptedTakeId === pendingAuto.id || control.refusedTakeId === pendingAuto.id);
1356
+ const staleLayout = resolvedAuto && control.refusedTakeId === pendingAuto.id &&
1357
+ control.staleLayoutId === true && !layoutRecoveryUsed;
1358
+ if (resolvedAuto) pendingAuto = null;
1287
1359
  applyGeometry(control.cols, control.rows, control.max);
1288
- if (firstGeometry || (transferOffered && !wasOffered) || (wasTemporary && !temporaryGeometry)) onGeometryReady();
1360
+ if (holdCleared && autoFitRequested && !layoutEligible) {
1361
+ layoutRecoveryUsed = false;
1362
+ registerDashboardLayout(true, false);
1363
+ }
1364
+ const ownerLeft = previouslyFollowed === 'owned' && followedGrid === 'unowned' &&
1365
+ !control.clientResize;
1366
+ const choiceOwnerLeft = holdCleared && control.owned === false;
1367
+ let retryLayout = false;
1368
+ if (staleLayout && layoutEligible && !explicitHold && followedGrid !== 'owned' &&
1369
+ controlMode !== 'held' && !temporaryGeometry) {
1370
+ layoutRecoveryUsed = true;
1371
+ retryLayout = registerDashboardLayout(true, false);
1372
+ }
1373
+ if (firstGeometry || ownerLeft || choiceOwnerLeft || (transferOffered && !wasOffered) ||
1374
+ (wasTemporary && !temporaryGeometry) || (control.clientResize && dirtyAuto) ||
1375
+ (resolvedAuto && dirtyAuto) || retryLayout ||
1376
+ (controlMode === 'yours' && dirtyAuto && !pendingTakeGrid))
1377
+ onGeometryReady(firstGeometry ? 'connect' : ownerLeft || choiceOwnerLeft ? 'release' : 'ready');
1289
1378
  if (controlMode === 'yours' && !temporaryGeometry && !captureMode && dashboardProof === null) requestFit();
1290
1379
  } else if (control && control.type === 'identity') {
1291
1380
  showIdentity(control);
1292
1381
  } else if (control && control.type === 'exited') {
1382
+ pendingAuto = null;
1293
1383
  pendingTakeGrid = false;
1294
1384
  pendingTakeSize = null;
1295
1385
  pendingTakeSocket = null;
@@ -1312,9 +1402,10 @@ window.ShellPuppetPane = (() => {
1312
1402
  };
1313
1403
 
1314
1404
  ws.onclose = () => {
1405
+ pendingAuto = null;
1406
+ dirtyAuto = false;
1315
1407
  if (pendingTakeSocket === socket) {
1316
1408
  pendingTakeGrid = false;
1317
- pendingTakeSize = null;
1318
1409
  pendingTakeSocket = null;
1319
1410
  }
1320
1411
  if (destroyed) return;
@@ -1410,27 +1501,65 @@ window.ShellPuppetPane = (() => {
1410
1501
  if (geometryDecided) applyFontPreference(gridCols, gridRows);
1411
1502
  positionNotices();
1412
1503
  },
1504
+ registerLayout(eligible, real = true) {
1505
+ if (real && (!ws || ws.readyState !== 1 || !geometryDecided)) pendingRealLayout = true;
1506
+ registerDashboardLayout(eligible, real || pendingRealLayout);
1507
+ },
1508
+ withdrawAutoFit() {
1509
+ if (dashboardProof === null || !ws || ws.readyState !== 1 || !geometryDecided) return;
1510
+ autoFitRequested = false;
1511
+ layoutId++;
1512
+ layoutEligible = false;
1513
+ dirtyAuto = false;
1514
+ ws.send(JSON.stringify({ type: 'layout', layoutId, eligible: false, real: false }));
1515
+ },
1516
+ resumeAutoFit() {
1517
+ if (dashboardProof === null || !ws || ws.readyState !== 1 || !geometryDecided) return;
1518
+ autoFitRequested = true;
1519
+ layoutId++;
1520
+ layoutEligible = !explicitHold && !(followedGrid === 'unowned' && belowDashboardFloor());
1521
+ dirtyAuto = layoutEligible;
1522
+ ws.send(JSON.stringify({ type: 'layout', layoutId, eligible: layoutEligible, real: false }));
1523
+ },
1413
1524
  autoFitGrid(floorCols = 80, floorRows = 24, force = false) {
1414
1525
  if (destroyed) return false;
1415
1526
  if (dashboardProof === null || controlMode === 'held' || (temporaryGeometry && !force) ||
1416
- (followingExternal && !force) || !geometryDecided ||
1527
+ ((followedGrid === 'owned' || explicitHold) && !force) || !geometryDecided ||
1417
1528
  !ws || ws.readyState !== 1 || sessionEnded) return false;
1418
- if (force) {
1419
- followingExternal = false;
1420
- }
1529
+ if (force) followedGrid = null;
1421
1530
  let proposed = proposeDashboardGrid();
1422
1531
  if (proposed === null) {
1423
1532
  if (container.clientWidth <= 0 || container.clientHeight <= 0) return false;
1424
1533
  proposed = { cols: floorCols, rows: floorRows };
1425
1534
  }
1426
1535
  const belowFloor = belowDashboardFloor(floorCols, floorRows);
1536
+ if (belowFloor && followedGrid === 'unowned' && !force) {
1537
+ this.withdrawAutoFit();
1538
+ return false;
1539
+ }
1427
1540
  const cols = Math.min(gridMax.cols, belowFloor ? floorCols : Math.max(floorCols, proposed.cols));
1428
1541
  const rows = Math.min(gridMax.rows, belowFloor ? floorRows : Math.max(floorRows, proposed.rows));
1429
- if (cols === gridCols && rows === gridRows && !force && !transferOffered) return false;
1430
- if (pendingTakeSocket === ws && pendingTakeSize?.cols === cols && pendingTakeSize?.rows === rows) return false;
1431
- return this.takeGrid(cols, rows, transferOffered);
1542
+ if (force || transferOffered) return this.takeGrid(cols, rows, transferOffered);
1543
+ if (pendingTakeGrid && pendingTakeSocket === ws) {
1544
+ if (pendingTakeSize?.cols !== cols || pendingTakeSize?.rows !== rows) dirtyAuto = true;
1545
+ return false;
1546
+ }
1547
+ if (pendingAuto) {
1548
+ if (pendingAuto.cols !== cols || pendingAuto.rows !== rows || pendingAuto.layoutId !== layoutId)
1549
+ dirtyAuto = true;
1550
+ return false;
1551
+ }
1552
+ if (cols === gridCols && rows === gridRows && controlMode === 'yours') return false;
1553
+ const wanted = { cols, rows };
1554
+ const id = ++nextTakeId;
1555
+ pendingAuto = { id, socket: ws, layoutId, ...wanted };
1556
+ dirtyAuto = false;
1557
+ ws.send(JSON.stringify({ type: 'resize', ...wanted, take: true, automatic: true,
1558
+ takeId: id, choiceRevision, layoutId }));
1559
+ return true;
1432
1560
  },
1433
1561
  isTemporaryGeometry() { return temporaryGeometry; },
1562
+ hasTransferOffer() { return transferOffered; },
1434
1563
  takeGrid(cols, rows, acceptOffer = false) {
1435
1564
  if (destroyed) return false;
1436
1565
  if (dashboardProof === null || !ws || ws.readyState !== 1 || !geometryDecided) return false;
@@ -1444,7 +1573,7 @@ window.ShellPuppetPane = (() => {
1444
1573
  fitGrid(floorCols = 80, floorRows = 24) {
1445
1574
  if (destroyed) return false;
1446
1575
  if (dashboardProof === null) return false;
1447
- followingExternal = false;
1576
+ followedGrid = null;
1448
1577
  const proposed = proposeDashboardGrid();
1449
1578
  if (belowDashboardFloor(floorCols, floorRows)) return this.takeGrid(floorCols, floorRows);
1450
1579
  return proposed !== null && this.takeGrid(
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "shellpuppet",
3
- "version": "0.4.2",
3
+ "version": "0.5.0",
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",