shellpuppet 0.4.2 → 0.5.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.
Files changed (83) 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/claude/nudge.js +1 -1
  7. package/dist/agents/claude/nudge.js.map +1 -1
  8. package/dist/agents/codex/draft.js +13 -6
  9. package/dist/agents/codex/draft.js.map +1 -1
  10. package/dist/agents/codex/index.js +1 -1
  11. package/dist/agents/codex/index.js.map +1 -1
  12. package/dist/agents/codex/nudge.js +7 -1
  13. package/dist/agents/codex/nudge.js.map +1 -1
  14. package/dist/agents/grok/index.js +1 -1
  15. package/dist/agents/grok/index.js.map +1 -1
  16. package/dist/agents/grok/nudge.js +13 -5
  17. package/dist/agents/grok/nudge.js.map +1 -1
  18. package/dist/agents/hermes/frame.js +4 -4
  19. package/dist/agents/hermes/frame.js.map +1 -1
  20. package/dist/agents/hermes/index.js +1 -1
  21. package/dist/agents/hermes/index.js.map +1 -1
  22. package/dist/agents/index.d.ts +2 -0
  23. package/dist/agents/index.js +7 -0
  24. package/dist/agents/index.js.map +1 -1
  25. package/dist/agents/mimo/index.js +1 -1
  26. package/dist/agents/mimo/index.js.map +1 -1
  27. package/dist/agents/muse/index.js +1 -1
  28. package/dist/agents/muse/index.js.map +1 -1
  29. package/dist/agents/muse/nudge.js +8 -3
  30. package/dist/agents/muse/nudge.js.map +1 -1
  31. package/dist/agents/nudgeReading.d.ts +2 -0
  32. package/dist/agents/nudgeReading.js +3 -3
  33. package/dist/agents/nudgeReading.js.map +1 -1
  34. package/dist/agents/opencode/index.js +1 -1
  35. package/dist/agents/opencode/index.js.map +1 -1
  36. package/dist/agents/qoder/index.js +1 -1
  37. package/dist/agents/qoder/index.js.map +1 -1
  38. package/dist/agents/types.d.ts +4 -0
  39. package/dist/cli/index.js +244 -5
  40. package/dist/cli/index.js.map +1 -1
  41. package/dist/client/http.d.ts +3 -0
  42. package/dist/client/http.js +7 -0
  43. package/dist/client/http.js.map +1 -1
  44. package/dist/client/input.d.ts +18 -0
  45. package/dist/client/input.js +15 -0
  46. package/dist/client/input.js.map +1 -1
  47. package/dist/core/session.d.ts +43 -4
  48. package/dist/core/session.js +169 -29
  49. package/dist/core/session.js.map +1 -1
  50. package/dist/core/windowsPtyStart.d.ts +2 -0
  51. package/dist/core/windowsPtyStart.js +6 -0
  52. package/dist/core/windowsPtyStart.js.map +1 -1
  53. package/dist/daemon/audit.d.ts +1 -1
  54. package/dist/daemon/audit.js +1 -1
  55. package/dist/daemon/index.js +1 -0
  56. package/dist/daemon/index.js.map +1 -1
  57. package/dist/daemon/launchProfiles.d.ts +9 -2
  58. package/dist/daemon/launchProfiles.js +27 -8
  59. package/dist/daemon/launchProfiles.js.map +1 -1
  60. package/dist/daemon/liveness.d.ts +11 -0
  61. package/dist/daemon/liveness.js +39 -0
  62. package/dist/daemon/liveness.js.map +1 -1
  63. package/dist/daemon/schedules.d.ts +1 -1
  64. package/dist/daemon/schedules.js +8 -3
  65. package/dist/daemon/schedules.js.map +1 -1
  66. package/dist/daemon/screenshot.d.ts +2 -0
  67. package/dist/daemon/screenshot.js +21 -3
  68. package/dist/daemon/screenshot.js.map +1 -1
  69. package/dist/daemon/server.d.ts +17 -1
  70. package/dist/daemon/server.js +498 -187
  71. package/dist/daemon/server.js.map +1 -1
  72. package/dist/daemon/sessionFeed.d.ts +1 -1
  73. package/dist/daemon/sessionFeed.js +3 -1
  74. package/dist/daemon/sessionFeed.js.map +1 -1
  75. package/dist/daemon/terminalReports.d.ts +9 -1
  76. package/dist/daemon/terminalReports.js +54 -0
  77. package/dist/daemon/terminalReports.js.map +1 -1
  78. package/dist/mcp/tools.js +12 -9
  79. package/dist/mcp/tools.js.map +1 -1
  80. package/dist/viewer/dashboard.css +20 -7
  81. package/dist/viewer/dashboard.js +120 -31
  82. package/dist/viewer/pane.js +159 -26
  83. 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' }));
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * ShellPuppet pane: the terminal client for one session in one container.
3
3
  *
4
- * It owns frame handling, typing (with term.onData registered once), sizing,
4
+ * It owns frame handling, input (with term.onData and term.onBinary registered once), sizing,
5
5
  * reconnect and badges for one session. The page provides the container and
6
6
  * badge elements, and wires up its controls.
7
7
  *
@@ -9,13 +9,11 @@
9
9
  * live stream and the exit notice); TEXT frames are JSON control messages:
10
10
  * `identity`, `geometry`, `input-source`, `input-refused`, `exited`,
11
11
  * `prompt-stall`, `prompt-clear`, `session-stalled` and `session-stall-clear`.
12
- * What this pane sends is text: a JSON
13
- * resize message, or bytes for the program, which are either keystrokes or
14
- * the terminal's own answers to the program's queries. The daemon tells those
15
- * two apart.
12
+ * This pane sends text frames for JSON controls and onData input, and binary
13
+ * frames for onBinary input. The latter contains one byte per character.
16
14
  *
17
15
  * Three rules shape the pane:
18
- * - `term.onData` is registered exactly ONCE, never inside the connect path.
16
+ * - `term.onData` and `term.onBinary` are registered exactly ONCE, outside the connect path.
19
17
  * Registering per-connect would stack a listener per reconnect and send
20
18
  * every keystroke N times.
21
19
  * - The pane measures what grid this window would like, and asks
@@ -152,7 +150,21 @@ window.ShellPuppetPane = (() => {
152
150
  let pendingTakeGrid = false;
153
151
  let pendingTakeSize = null;
154
152
  let pendingTakeSocket = null;
155
- let followingExternal = false;
153
+ let followedGrid = null;
154
+ let choiceRevision = 0;
155
+ let layoutId = 0;
156
+ let realLayoutId = 0;
157
+ let nextTakeId = 0;
158
+ let pendingAuto = null;
159
+ let dirtyAuto = false;
160
+ let explicitHold = false;
161
+ let explicitHoldControllerRevision = 0;
162
+ let lastExplicitResizeRevision = 0;
163
+ let clearedExplicitResizeRevision = 0;
164
+ let pendingRealLayout = false;
165
+ let autoFitRequested = false;
166
+ let layoutEligible = false;
167
+ let layoutRecoveryUsed = false;
156
168
  let transferOffered = false;
157
169
  let temporaryGeometry = false;
158
170
  let dashboardFontLimit = null;
@@ -861,6 +873,12 @@ window.ShellPuppetPane = (() => {
861
873
  if (destroyed || sessionEnded || readOnly) return;
862
874
  if (ws && ws.readyState === 1) ws.send(data);
863
875
  });
876
+ term.onBinary((data) => {
877
+ if (destroyed || sessionEnded || readOnly || !ws || ws.readyState !== 1) return;
878
+ const bytes = new Uint8Array(data.length);
879
+ for (let i = 0; i < data.length; i++) bytes[i] = data.charCodeAt(i);
880
+ ws.send(bytes);
881
+ });
864
882
 
865
883
  function showReadOnly() {
866
884
  if (!elements.readonly) return;
@@ -1132,6 +1150,7 @@ window.ShellPuppetPane = (() => {
1132
1150
  elements.size.textContent =
1133
1151
  `${cols}×${rows}` +
1134
1152
  (controlMode === 'held' ? ' (fixed)' : controlMode === 'adopt' ? ' (following)' : '');
1153
+ elements.size.title = elements.size.textContent;
1135
1154
  }
1136
1155
  positionNotices();
1137
1156
  onGeometryChange();
@@ -1165,6 +1184,27 @@ window.ShellPuppetPane = (() => {
1165
1184
  elements.inputSource.className = `hint ${who}`;
1166
1185
  }
1167
1186
 
1187
+ function registerDashboardLayout(eligible, real) {
1188
+ if (dashboardProof === null || !ws || ws.readyState !== 1 || !geometryDecided) return false;
1189
+ autoFitRequested = eligible;
1190
+ layoutId++;
1191
+ if (real) {
1192
+ realLayoutId = layoutId;
1193
+ layoutRecoveryUsed = false;
1194
+ pendingRealLayout = false;
1195
+ }
1196
+ const allowed = eligible && (real || !explicitHold) &&
1197
+ !(followedGrid === 'unowned' && belowDashboardFloor());
1198
+ layoutEligible = allowed;
1199
+ dirtyAuto = allowed;
1200
+ if (real) {
1201
+ explicitHold = false;
1202
+ clearedExplicitResizeRevision = lastExplicitResizeRevision;
1203
+ }
1204
+ ws.send(JSON.stringify({ type: 'layout', layoutId, eligible: allowed, real }));
1205
+ return true;
1206
+ }
1207
+
1168
1208
  function connect() {
1169
1209
  if (destroyed) return;
1170
1210
  ws = new WebSocket(`ws://${location.host}/sessions/${encodeURIComponent(sessionId)}/stream${passive ? '?drive=0' : ''}`,
@@ -1189,9 +1229,11 @@ window.ShellPuppetPane = (() => {
1189
1229
  if (elements.banner) elements.banner.hidden = true;
1190
1230
  retriesLeft = 8;
1191
1231
  geometryDecided = false;
1232
+ pendingAuto = null;
1233
+ dirtyAuto = false;
1234
+ layoutRecoveryUsed = false;
1192
1235
  if (pendingTakeSocket !== socket) {
1193
1236
  pendingTakeGrid = false;
1194
- pendingTakeSize = null;
1195
1237
  pendingTakeSocket = null;
1196
1238
  }
1197
1239
  };
@@ -1245,6 +1287,10 @@ window.ShellPuppetPane = (() => {
1245
1287
  } else if (control && control.type === 'geometry') {
1246
1288
  const firstGeometry = !geometryDecided;
1247
1289
  geometryDecided = true;
1290
+ if (typeof control.choiceRevision === 'number') {
1291
+ if (control.choiceRevision < choiceRevision) return;
1292
+ choiceRevision = control.choiceRevision;
1293
+ }
1248
1294
  controlMode = captureMode ? 'adopt' : control.control || 'adopt';
1249
1295
  const wasOffered = transferOffered;
1250
1296
  transferOffered = controlMode === 'adopt' && control.dashboardTransferable === true;
@@ -1252,16 +1298,17 @@ window.ShellPuppetPane = (() => {
1252
1298
  temporaryGeometry = control.temporary === true;
1253
1299
  if (pendingTakeSocket !== null && pendingTakeSocket !== socket) {
1254
1300
  pendingTakeGrid = false;
1255
- pendingTakeSize = null;
1256
1301
  pendingTakeSocket = null;
1257
1302
  }
1258
1303
  if (controlMode === 'held') {
1259
1304
  pendingTakeGrid = false;
1260
- pendingTakeSize = null;
1261
1305
  pendingTakeSocket = null;
1262
1306
  }
1307
+ const previouslyFollowed = followedGrid;
1308
+ if (dashboardProof !== null && firstGeometry && controlMode === 'adopt' &&
1309
+ control.owned !== true) followedGrid = null;
1263
1310
  if (dashboardProof !== null && firstGeometry && controlMode === 'yours') {
1264
- followingExternal = false;
1311
+ followedGrid = null;
1265
1312
  pendingTakeGrid = false;
1266
1313
  pendingTakeSize = null;
1267
1314
  pendingTakeSocket = null;
@@ -1269,27 +1316,74 @@ window.ShellPuppetPane = (() => {
1269
1316
  }
1270
1317
  if (dashboardProof !== null && (!firstGeometry || control.owned === true)) {
1271
1318
  if (controlMode === 'yours' && pendingTakeGrid) {
1272
- followingExternal = false;
1319
+ followedGrid = null;
1320
+ explicitHold = false;
1273
1321
  pendingTakeGrid = false;
1274
1322
  pendingTakeSize = null;
1275
1323
  pendingTakeSocket = null;
1276
1324
  onGridTaken();
1277
- } else if (controlMode === 'adopt' && !followingExternal && !transferOffered) {
1325
+ } else if (controlMode === 'adopt' && !transferOffered) {
1278
1326
  pendingTakeGrid = false;
1279
1327
  pendingTakeSize = null;
1280
1328
  pendingTakeSocket = null;
1281
- followingExternal = true;
1282
- onOutsideGeometry();
1329
+ followedGrid = control.owned ? 'owned' : 'unowned';
1330
+ if (previouslyFollowed !== followedGrid) onOutsideGeometry();
1283
1331
  } else if (transferOffered) {
1284
- followingExternal = false;
1332
+ followedGrid = null;
1285
1333
  }
1286
1334
  }
1335
+ if (controlMode === 'yours') followedGrid = null;
1336
+ const controllerRevision = Number.isSafeInteger(control.controllerChoiceRevision)
1337
+ ? control.controllerChoiceRevision : 0;
1338
+ const explicitRevision = Number.isSafeInteger(control.explicitResizeRevision)
1339
+ ? control.explicitResizeRevision : 0;
1340
+ lastExplicitResizeRevision = Math.max(lastExplicitResizeRevision, explicitRevision);
1341
+ let holdCleared = false;
1342
+ if (control.clientResize) {
1343
+ explicitHold = realLayoutId <= (control.layoutFence ?? realLayoutId);
1344
+ if (explicitHold) {
1345
+ explicitHoldControllerRevision = controllerRevision;
1346
+ dirtyAuto = false;
1347
+ } else clearedExplicitResizeRevision = lastExplicitResizeRevision;
1348
+ } else if (explicitHold && controllerRevision > explicitHoldControllerRevision) {
1349
+ explicitHold = false;
1350
+ holdCleared = true;
1351
+ } else if (firstGeometry && explicitRevision > controllerRevision) {
1352
+ if (explicitRevision > clearedExplicitResizeRevision) {
1353
+ explicitHold = true;
1354
+ explicitHoldControllerRevision = controllerRevision;
1355
+ dirtyAuto = false;
1356
+ } else pendingRealLayout = true;
1357
+ }
1358
+ const resolvedAuto = pendingAuto &&
1359
+ (control.acceptedTakeId === pendingAuto.id || control.refusedTakeId === pendingAuto.id);
1360
+ const staleLayout = resolvedAuto && control.refusedTakeId === pendingAuto.id &&
1361
+ control.staleLayoutId === true && !layoutRecoveryUsed;
1362
+ if (resolvedAuto) pendingAuto = null;
1287
1363
  applyGeometry(control.cols, control.rows, control.max);
1288
- if (firstGeometry || (transferOffered && !wasOffered) || (wasTemporary && !temporaryGeometry)) onGeometryReady();
1364
+ if (holdCleared && autoFitRequested && !layoutEligible) {
1365
+ layoutRecoveryUsed = false;
1366
+ registerDashboardLayout(true, false);
1367
+ }
1368
+ const ownerLeft = previouslyFollowed === 'owned' && followedGrid === 'unowned' &&
1369
+ !control.clientResize;
1370
+ const choiceOwnerLeft = holdCleared && control.owned === false;
1371
+ let retryLayout = false;
1372
+ if (staleLayout && layoutEligible && !explicitHold && followedGrid !== 'owned' &&
1373
+ controlMode !== 'held' && !temporaryGeometry) {
1374
+ layoutRecoveryUsed = true;
1375
+ retryLayout = registerDashboardLayout(true, false);
1376
+ }
1377
+ if (firstGeometry || ownerLeft || choiceOwnerLeft || (transferOffered && !wasOffered) ||
1378
+ (wasTemporary && !temporaryGeometry) || (control.clientResize && dirtyAuto) ||
1379
+ (resolvedAuto && dirtyAuto) || retryLayout ||
1380
+ (controlMode === 'yours' && dirtyAuto && !pendingTakeGrid))
1381
+ onGeometryReady(firstGeometry ? 'connect' : ownerLeft || choiceOwnerLeft ? 'release' : 'ready');
1289
1382
  if (controlMode === 'yours' && !temporaryGeometry && !captureMode && dashboardProof === null) requestFit();
1290
1383
  } else if (control && control.type === 'identity') {
1291
1384
  showIdentity(control);
1292
1385
  } else if (control && control.type === 'exited') {
1386
+ pendingAuto = null;
1293
1387
  pendingTakeGrid = false;
1294
1388
  pendingTakeSize = null;
1295
1389
  pendingTakeSocket = null;
@@ -1312,9 +1406,10 @@ window.ShellPuppetPane = (() => {
1312
1406
  };
1313
1407
 
1314
1408
  ws.onclose = () => {
1409
+ pendingAuto = null;
1410
+ dirtyAuto = false;
1315
1411
  if (pendingTakeSocket === socket) {
1316
1412
  pendingTakeGrid = false;
1317
- pendingTakeSize = null;
1318
1413
  pendingTakeSocket = null;
1319
1414
  }
1320
1415
  if (destroyed) return;
@@ -1410,27 +1505,65 @@ window.ShellPuppetPane = (() => {
1410
1505
  if (geometryDecided) applyFontPreference(gridCols, gridRows);
1411
1506
  positionNotices();
1412
1507
  },
1508
+ registerLayout(eligible, real = true) {
1509
+ if (real && (!ws || ws.readyState !== 1 || !geometryDecided)) pendingRealLayout = true;
1510
+ registerDashboardLayout(eligible, real || pendingRealLayout);
1511
+ },
1512
+ withdrawAutoFit() {
1513
+ if (dashboardProof === null || !ws || ws.readyState !== 1 || !geometryDecided) return;
1514
+ autoFitRequested = false;
1515
+ layoutId++;
1516
+ layoutEligible = false;
1517
+ dirtyAuto = false;
1518
+ ws.send(JSON.stringify({ type: 'layout', layoutId, eligible: false, real: false }));
1519
+ },
1520
+ resumeAutoFit() {
1521
+ if (dashboardProof === null || !ws || ws.readyState !== 1 || !geometryDecided) return;
1522
+ autoFitRequested = true;
1523
+ layoutId++;
1524
+ layoutEligible = !explicitHold && !(followedGrid === 'unowned' && belowDashboardFloor());
1525
+ dirtyAuto = layoutEligible;
1526
+ ws.send(JSON.stringify({ type: 'layout', layoutId, eligible: layoutEligible, real: false }));
1527
+ },
1413
1528
  autoFitGrid(floorCols = 80, floorRows = 24, force = false) {
1414
1529
  if (destroyed) return false;
1415
1530
  if (dashboardProof === null || controlMode === 'held' || (temporaryGeometry && !force) ||
1416
- (followingExternal && !force) || !geometryDecided ||
1531
+ ((followedGrid === 'owned' || explicitHold) && !force) || !geometryDecided ||
1417
1532
  !ws || ws.readyState !== 1 || sessionEnded) return false;
1418
- if (force) {
1419
- followingExternal = false;
1420
- }
1533
+ if (force) followedGrid = null;
1421
1534
  let proposed = proposeDashboardGrid();
1422
1535
  if (proposed === null) {
1423
1536
  if (container.clientWidth <= 0 || container.clientHeight <= 0) return false;
1424
1537
  proposed = { cols: floorCols, rows: floorRows };
1425
1538
  }
1426
1539
  const belowFloor = belowDashboardFloor(floorCols, floorRows);
1540
+ if (belowFloor && followedGrid === 'unowned' && !force) {
1541
+ this.withdrawAutoFit();
1542
+ return false;
1543
+ }
1427
1544
  const cols = Math.min(gridMax.cols, belowFloor ? floorCols : Math.max(floorCols, proposed.cols));
1428
1545
  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);
1546
+ if (force || transferOffered) return this.takeGrid(cols, rows, transferOffered);
1547
+ if (pendingTakeGrid && pendingTakeSocket === ws) {
1548
+ if (pendingTakeSize?.cols !== cols || pendingTakeSize?.rows !== rows) dirtyAuto = true;
1549
+ return false;
1550
+ }
1551
+ if (pendingAuto) {
1552
+ if (pendingAuto.cols !== cols || pendingAuto.rows !== rows || pendingAuto.layoutId !== layoutId)
1553
+ dirtyAuto = true;
1554
+ return false;
1555
+ }
1556
+ if (cols === gridCols && rows === gridRows && controlMode === 'yours') return false;
1557
+ const wanted = { cols, rows };
1558
+ const id = ++nextTakeId;
1559
+ pendingAuto = { id, socket: ws, layoutId, ...wanted };
1560
+ dirtyAuto = false;
1561
+ ws.send(JSON.stringify({ type: 'resize', ...wanted, take: true, automatic: true,
1562
+ takeId: id, choiceRevision, layoutId }));
1563
+ return true;
1432
1564
  },
1433
1565
  isTemporaryGeometry() { return temporaryGeometry; },
1566
+ hasTransferOffer() { return transferOffered; },
1434
1567
  takeGrid(cols, rows, acceptOffer = false) {
1435
1568
  if (destroyed) return false;
1436
1569
  if (dashboardProof === null || !ws || ws.readyState !== 1 || !geometryDecided) return false;
@@ -1444,7 +1577,7 @@ window.ShellPuppetPane = (() => {
1444
1577
  fitGrid(floorCols = 80, floorRows = 24) {
1445
1578
  if (destroyed) return false;
1446
1579
  if (dashboardProof === null) return false;
1447
- followingExternal = false;
1580
+ followedGrid = null;
1448
1581
  const proposed = proposeDashboardGrid();
1449
1582
  if (belowDashboardFloor(floorCols, floorRows)) return this.takeGrid(floorCols, floorRows);
1450
1583
  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.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",