shellpuppet 0.4.1 → 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 (87) hide show
  1. package/README.md +26 -4
  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 +275 -16
  35. package/dist/cli/index.js.map +1 -1
  36. package/dist/client/http.d.ts +8 -0
  37. package/dist/client/http.js +15 -1
  38. package/dist/client/http.js.map +1 -1
  39. package/dist/client/input.d.ts +24 -0
  40. package/dist/client/input.js +29 -0
  41. package/dist/client/input.js.map +1 -0
  42. package/dist/core/mailbox.d.ts +18 -6
  43. package/dist/core/mailbox.js +35 -10
  44. package/dist/core/mailbox.js.map +1 -1
  45. package/dist/core/manager.d.ts +1 -2
  46. package/dist/core/manager.js +35 -16
  47. package/dist/core/manager.js.map +1 -1
  48. package/dist/core/session.d.ts +29 -0
  49. package/dist/core/session.js +65 -11
  50. package/dist/core/session.js.map +1 -1
  51. package/dist/core/types.d.ts +2 -0
  52. package/dist/core/types.js +2 -0
  53. package/dist/core/types.js.map +1 -1
  54. package/dist/core/windowsPtyStart.d.ts +2 -0
  55. package/dist/core/windowsPtyStart.js +6 -0
  56. package/dist/core/windowsPtyStart.js.map +1 -1
  57. package/dist/daemon/audit.d.ts +7 -7
  58. package/dist/daemon/audit.js +19 -17
  59. package/dist/daemon/audit.js.map +1 -1
  60. package/dist/daemon/config.d.ts +1 -1
  61. package/dist/daemon/config.js +1 -1
  62. package/dist/daemon/index.js +1 -0
  63. package/dist/daemon/index.js.map +1 -1
  64. package/dist/daemon/launchProfiles.d.ts +6 -0
  65. package/dist/daemon/launchProfiles.js +21 -4
  66. package/dist/daemon/launchProfiles.js.map +1 -1
  67. package/dist/daemon/liveness.d.ts +11 -0
  68. package/dist/daemon/liveness.js +39 -0
  69. package/dist/daemon/liveness.js.map +1 -1
  70. package/dist/daemon/schedules.d.ts +1 -1
  71. package/dist/daemon/schedules.js +8 -3
  72. package/dist/daemon/schedules.js.map +1 -1
  73. package/dist/daemon/server.d.ts +17 -0
  74. package/dist/daemon/server.js +411 -143
  75. package/dist/daemon/server.js.map +1 -1
  76. package/dist/daemon/sessionFeed.d.ts +1 -1
  77. package/dist/daemon/sessionFeed.js +3 -1
  78. package/dist/daemon/sessionFeed.js.map +1 -1
  79. package/dist/mcp/tools.js +55 -35
  80. package/dist/mcp/tools.js.map +1 -1
  81. package/dist/viewer/dashboard.css +21 -8
  82. package/dist/viewer/dashboard.js +129 -34
  83. package/dist/viewer/index.html +1 -0
  84. package/dist/viewer/pane.js +267 -20
  85. package/dist/viewer/viewer.css +1 -1
  86. package/dist/viewer/viewer.js +1 -0
  87. package/package.json +1 -1
@@ -37,6 +37,14 @@ window.ShellPuppetPane = (() => {
37
37
  const MIN_FONT_PX = 6;
38
38
  const MAX_FONT_PX = 40;
39
39
  const DEFAULT_FONT_PX = 13;
40
+ const MAX_CLIPBOARD_BYTES = 1024 * 1024;
41
+ const MAX_CLIPBOARD_DISPATCH_MS = 1000;
42
+ const CLIPBOARD_GESTURE_MS = 2000;
43
+ const CLIPBOARD_KEYS = new Set(['Enter', 'Tab', 'Backspace', 'Delete', 'Escape', 'ArrowUp', 'ArrowDown',
44
+ 'ArrowLeft', 'ArrowRight', 'Home', 'End', 'PageUp', 'PageDown']);
45
+ // A printable base (including space or a supplementary character) can carry combining marks.
46
+ const PRINTABLE_KEY = /^[\p{L}\p{M}\p{N}\p{P}\p{S}\p{Zs}]\p{M}*$/u;
47
+ const recentClipboardAge = (age, limit = CLIPBOARD_GESTURE_MS) => age >= 0 && age <= limit;
40
48
  const NOTICE_HISTORY_MS = 10000;
41
49
  const NOTICE_DECISION_MS = 1200;
42
50
  const NOTICE_COVER_MARGIN_MS = 20;
@@ -64,6 +72,23 @@ window.ShellPuppetPane = (() => {
64
72
  return Math.min(MAX_FONT_PX, Math.max(MIN_FONT_PX, px));
65
73
  }
66
74
 
75
+ function decodeClipboard(data) {
76
+ const start = data.startsWith('c;') ? 2 : data.startsWith(';') ? 1 : 0;
77
+ if (!start || data.length - start > 4 * Math.ceil(MAX_CLIPBOARD_BYTES / 3)) return null;
78
+ const encoded = data.slice(start);
79
+ if (encoded.length % 4 !== 0) return null;
80
+ const padding = encoded.endsWith('==') ? 2 : encoded.endsWith('=') ? 1 : 0;
81
+ if (encoded.length / 4 * 3 - padding > MAX_CLIPBOARD_BYTES) return null;
82
+ try {
83
+ const binary = window.atob(encoded);
84
+ // atob also accepts whitespace and non-zero padding bits.
85
+ if (window.btoa(binary) !== encoded) return null;
86
+ const bytes = new Uint8Array(binary.length);
87
+ for (let i = 0; i < binary.length; i++) bytes[i] = binary.charCodeAt(i);
88
+ return new window.TextDecoder('utf-8', { fatal: true, ignoreBOM: true }).decode(bytes);
89
+ } catch { return null; }
90
+ }
91
+
67
92
  /**
68
93
  * Create a pane for one session in one container.
69
94
  *
@@ -127,7 +152,21 @@ window.ShellPuppetPane = (() => {
127
152
  let pendingTakeGrid = false;
128
153
  let pendingTakeSize = null;
129
154
  let pendingTakeSocket = null;
130
- 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;
131
170
  let transferOffered = false;
132
171
  let temporaryGeometry = false;
133
172
  let dashboardFontLimit = null;
@@ -386,6 +425,90 @@ window.ShellPuppetPane = (() => {
386
425
  outerScroll?.addEventListener('wheel', scrollOversizedPane, { capture: true, passive: false });
387
426
  const platform = navigator.userAgentData?.platform || navigator.userAgent;
388
427
  const isMac = /Mac|iPhone|iPad/i.test(platform);
428
+ // Match the browser platform list in xterm's common/Platform.ts for selection.
429
+ const macShiftSelection = ['Macintosh', 'MacIntel', 'MacPPC', 'Mac68K'].includes(navigator.platform);
430
+ let lastGesture = null;
431
+ let copyFailureShown = false;
432
+ let copyNoticeTimer;
433
+ const forgetGesture = () => { lastGesture = null; };
434
+ const terminalFocused = () => document.hasFocus() && document.activeElement === term.textarea;
435
+ const recordGesture = (event) => {
436
+ if (!event.isTrusted || !terminalFocused()) return;
437
+ if (event.type === 'keydown') {
438
+ const key = event.key;
439
+ const pasteShortcut = key === 'Paste' || event.code === 'Paste' ||
440
+ ((event.ctrlKey || event.metaKey) && (key === 'v' || key === 'V' || event.code === 'KeyV')) ||
441
+ (event.shiftKey && event.key === 'Insert');
442
+ if (pasteShortcut) { forgetGesture(); return; }
443
+ if (event.repeat !== false || typeof key !== 'string' || !(CLIPBOARD_KEYS.has(key) || PRINTABLE_KEY.test(key))) return;
444
+ } else if (event.button !== 0) return;
445
+
446
+ const age = window.performance.now() - event.timeStamp;
447
+ const wallNow = Date.now();
448
+ // Charge time already spent waiting for event dispatch to both clocks.
449
+ lastGesture = Number.isFinite(event.timeStamp) && recentClipboardAge(age, MAX_CLIPBOARD_DISPATCH_MS) && Number.isFinite(wallNow)
450
+ ? { eventTime: event.timeStamp, wallTime: wallNow - age } : null;
451
+ };
452
+ const hasRecentGesture = () => {
453
+ if (!lastGesture) return false;
454
+ if (recentClipboardAge(window.performance.now() - lastGesture.eventTime) &&
455
+ recentClipboardAge(Date.now() - lastGesture.wallTime)) return true;
456
+ forgetGesture();
457
+ return false;
458
+ };
459
+ const canWriteClipboard = () => !destroyed && terminalFocused() && hasRecentGesture();
460
+ const startShiftSelection = (event) => {
461
+ if (!event.isTrusted || event.button !== 0 || !event.shiftKey || term.modes.mouseTrackingMode === 'none') return;
462
+ // xterm chooses the drag mode on mousedown. Let its macOS handlers see
463
+ // Option for this press, then restore the option after they have run.
464
+ const previous = term.options.macOptionClickForcesSelection;
465
+ const addOption = !event.altKey;
466
+ if (addOption) Object.defineProperty(event, 'altKey', { value: true, configurable: true });
467
+ term.options.macOptionClickForcesSelection = true;
468
+ const restore = () => {
469
+ clearTimeout(timer);
470
+ term.element?.removeEventListener('mousedown', restore);
471
+ if (addOption) delete event.altKey;
472
+ if (!destroyed) term.options.macOptionClickForcesSelection = previous;
473
+ };
474
+ // A child can stop the event before it bubbles back to xterm's element.
475
+ const timer = setTimeout(restore, 0);
476
+ term.element.addEventListener('mousedown', restore);
477
+ };
478
+ const writeClipboard = async (text) => {
479
+ if (!canWriteClipboard()) return;
480
+ try {
481
+ await navigator.clipboard.writeText(text);
482
+ } catch {
483
+ if (!destroyed && !copyFailureShown) {
484
+ copyFailureShown = true;
485
+ showBanner('Could not copy selected text to the clipboard.');
486
+ }
487
+ return;
488
+ }
489
+ if (destroyed || !elements.copyNotice) return;
490
+ elements.copyNotice.hidden = false;
491
+ positionNotices();
492
+ clearTimeout(copyNoticeTimer);
493
+ copyNoticeTimer = setTimeout(() => { elements.copyNotice.hidden = true; }, 1500);
494
+ };
495
+ // Use just one press event. A compatibility mousedown after a touch can
496
+ // arrive on release, well after the original pointerdown.
497
+ const gestureEvents = [window.PointerEvent ? 'pointerdown' : 'mousedown', 'keydown'];
498
+ if (!captureMode && term.textarea) {
499
+ for (const type of gestureEvents) term.element.addEventListener(type, recordGesture, true);
500
+ term.element.addEventListener('paste', forgetGesture, true);
501
+ if (macShiftSelection) term.element.addEventListener('mousedown', startShiftSelection, true);
502
+ term.textarea.addEventListener('blur', forgetGesture);
503
+ window.addEventListener('blur', forgetGesture);
504
+ term.parser.registerOscHandler(52, data => {
505
+ if (canWriteClipboard()) {
506
+ const text = decodeClipboard(data);
507
+ if (text !== null) void writeClipboard(text);
508
+ }
509
+ return true;
510
+ });
511
+ }
389
512
  // Let the browser deliver paste to xterm's textarea on Windows and Linux.
390
513
  term.attachCustomKeyEventHandler((event) => {
391
514
  if (destroyed) return false;
@@ -1023,6 +1146,7 @@ window.ShellPuppetPane = (() => {
1023
1146
  elements.size.textContent =
1024
1147
  `${cols}×${rows}` +
1025
1148
  (controlMode === 'held' ? ' (fixed)' : controlMode === 'adopt' ? ' (following)' : '');
1149
+ elements.size.title = elements.size.textContent;
1026
1150
  }
1027
1151
  positionNotices();
1028
1152
  onGeometryChange();
@@ -1056,6 +1180,27 @@ window.ShellPuppetPane = (() => {
1056
1180
  elements.inputSource.className = `hint ${who}`;
1057
1181
  }
1058
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
+
1059
1204
  function connect() {
1060
1205
  if (destroyed) return;
1061
1206
  ws = new WebSocket(`ws://${location.host}/sessions/${encodeURIComponent(sessionId)}/stream${passive ? '?drive=0' : ''}`,
@@ -1080,9 +1225,11 @@ window.ShellPuppetPane = (() => {
1080
1225
  if (elements.banner) elements.banner.hidden = true;
1081
1226
  retriesLeft = 8;
1082
1227
  geometryDecided = false;
1228
+ pendingAuto = null;
1229
+ dirtyAuto = false;
1230
+ layoutRecoveryUsed = false;
1083
1231
  if (pendingTakeSocket !== socket) {
1084
1232
  pendingTakeGrid = false;
1085
- pendingTakeSize = null;
1086
1233
  pendingTakeSocket = null;
1087
1234
  }
1088
1235
  };
@@ -1136,6 +1283,10 @@ window.ShellPuppetPane = (() => {
1136
1283
  } else if (control && control.type === 'geometry') {
1137
1284
  const firstGeometry = !geometryDecided;
1138
1285
  geometryDecided = true;
1286
+ if (typeof control.choiceRevision === 'number') {
1287
+ if (control.choiceRevision < choiceRevision) return;
1288
+ choiceRevision = control.choiceRevision;
1289
+ }
1139
1290
  controlMode = captureMode ? 'adopt' : control.control || 'adopt';
1140
1291
  const wasOffered = transferOffered;
1141
1292
  transferOffered = controlMode === 'adopt' && control.dashboardTransferable === true;
@@ -1143,16 +1294,17 @@ window.ShellPuppetPane = (() => {
1143
1294
  temporaryGeometry = control.temporary === true;
1144
1295
  if (pendingTakeSocket !== null && pendingTakeSocket !== socket) {
1145
1296
  pendingTakeGrid = false;
1146
- pendingTakeSize = null;
1147
1297
  pendingTakeSocket = null;
1148
1298
  }
1149
1299
  if (controlMode === 'held') {
1150
1300
  pendingTakeGrid = false;
1151
- pendingTakeSize = null;
1152
1301
  pendingTakeSocket = null;
1153
1302
  }
1303
+ const previouslyFollowed = followedGrid;
1304
+ if (dashboardProof !== null && firstGeometry && controlMode === 'adopt' &&
1305
+ control.owned !== true) followedGrid = null;
1154
1306
  if (dashboardProof !== null && firstGeometry && controlMode === 'yours') {
1155
- followingExternal = false;
1307
+ followedGrid = null;
1156
1308
  pendingTakeGrid = false;
1157
1309
  pendingTakeSize = null;
1158
1310
  pendingTakeSocket = null;
@@ -1160,27 +1312,74 @@ window.ShellPuppetPane = (() => {
1160
1312
  }
1161
1313
  if (dashboardProof !== null && (!firstGeometry || control.owned === true)) {
1162
1314
  if (controlMode === 'yours' && pendingTakeGrid) {
1163
- followingExternal = false;
1315
+ followedGrid = null;
1316
+ explicitHold = false;
1164
1317
  pendingTakeGrid = false;
1165
1318
  pendingTakeSize = null;
1166
1319
  pendingTakeSocket = null;
1167
1320
  onGridTaken();
1168
- } else if (controlMode === 'adopt' && !followingExternal && !transferOffered) {
1321
+ } else if (controlMode === 'adopt' && !transferOffered) {
1169
1322
  pendingTakeGrid = false;
1170
1323
  pendingTakeSize = null;
1171
1324
  pendingTakeSocket = null;
1172
- followingExternal = true;
1173
- onOutsideGeometry();
1325
+ followedGrid = control.owned ? 'owned' : 'unowned';
1326
+ if (previouslyFollowed !== followedGrid) onOutsideGeometry();
1174
1327
  } else if (transferOffered) {
1175
- followingExternal = false;
1328
+ followedGrid = null;
1176
1329
  }
1177
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;
1178
1359
  applyGeometry(control.cols, control.rows, control.max);
1179
- 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');
1180
1378
  if (controlMode === 'yours' && !temporaryGeometry && !captureMode && dashboardProof === null) requestFit();
1181
1379
  } else if (control && control.type === 'identity') {
1182
1380
  showIdentity(control);
1183
1381
  } else if (control && control.type === 'exited') {
1382
+ pendingAuto = null;
1184
1383
  pendingTakeGrid = false;
1185
1384
  pendingTakeSize = null;
1186
1385
  pendingTakeSocket = null;
@@ -1203,9 +1402,10 @@ window.ShellPuppetPane = (() => {
1203
1402
  };
1204
1403
 
1205
1404
  ws.onclose = () => {
1405
+ pendingAuto = null;
1406
+ dirtyAuto = false;
1206
1407
  if (pendingTakeSocket === socket) {
1207
1408
  pendingTakeGrid = false;
1208
- pendingTakeSize = null;
1209
1409
  pendingTakeSocket = null;
1210
1410
  }
1211
1411
  if (destroyed) return;
@@ -1232,6 +1432,15 @@ window.ShellPuppetPane = (() => {
1232
1432
  destroy(reassigned = false) {
1233
1433
  if (destroyed) return;
1234
1434
  destroyed = true;
1435
+ if (!captureMode && term.textarea) {
1436
+ for (const type of gestureEvents) term.element.removeEventListener(type, recordGesture, true);
1437
+ term.element.removeEventListener('paste', forgetGesture, true);
1438
+ if (macShiftSelection) term.element.removeEventListener('mousedown', startShiftSelection, true);
1439
+ term.textarea.removeEventListener('blur', forgetGesture);
1440
+ window.removeEventListener('blur', forgetGesture);
1441
+ }
1442
+ clearTimeout(copyNoticeTimer);
1443
+ if (elements.copyNotice) elements.copyNotice.hidden = true;
1235
1444
  fontListeners.delete(refreshFontMetrics);
1236
1445
  resolutionListener.dispose();
1237
1446
  if (metricsFrame !== null) window.cancelAnimationFrame(metricsFrame);
@@ -1292,27 +1501,65 @@ window.ShellPuppetPane = (() => {
1292
1501
  if (geometryDecided) applyFontPreference(gridCols, gridRows);
1293
1502
  positionNotices();
1294
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
+ },
1295
1524
  autoFitGrid(floorCols = 80, floorRows = 24, force = false) {
1296
1525
  if (destroyed) return false;
1297
1526
  if (dashboardProof === null || controlMode === 'held' || (temporaryGeometry && !force) ||
1298
- (followingExternal && !force) || !geometryDecided ||
1527
+ ((followedGrid === 'owned' || explicitHold) && !force) || !geometryDecided ||
1299
1528
  !ws || ws.readyState !== 1 || sessionEnded) return false;
1300
- if (force) {
1301
- followingExternal = false;
1302
- }
1529
+ if (force) followedGrid = null;
1303
1530
  let proposed = proposeDashboardGrid();
1304
1531
  if (proposed === null) {
1305
1532
  if (container.clientWidth <= 0 || container.clientHeight <= 0) return false;
1306
1533
  proposed = { cols: floorCols, rows: floorRows };
1307
1534
  }
1308
1535
  const belowFloor = belowDashboardFloor(floorCols, floorRows);
1536
+ if (belowFloor && followedGrid === 'unowned' && !force) {
1537
+ this.withdrawAutoFit();
1538
+ return false;
1539
+ }
1309
1540
  const cols = Math.min(gridMax.cols, belowFloor ? floorCols : Math.max(floorCols, proposed.cols));
1310
1541
  const rows = Math.min(gridMax.rows, belowFloor ? floorRows : Math.max(floorRows, proposed.rows));
1311
- if (cols === gridCols && rows === gridRows && !force && !transferOffered) return false;
1312
- if (pendingTakeSocket === ws && pendingTakeSize?.cols === cols && pendingTakeSize?.rows === rows) return false;
1313
- 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;
1314
1560
  },
1315
1561
  isTemporaryGeometry() { return temporaryGeometry; },
1562
+ hasTransferOffer() { return transferOffered; },
1316
1563
  takeGrid(cols, rows, acceptOffer = false) {
1317
1564
  if (destroyed) return false;
1318
1565
  if (dashboardProof === null || !ws || ws.readyState !== 1 || !geometryDecided) return false;
@@ -1326,7 +1573,7 @@ window.ShellPuppetPane = (() => {
1326
1573
  fitGrid(floorCols = 80, floorRows = 24) {
1327
1574
  if (destroyed) return false;
1328
1575
  if (dashboardProof === null) return false;
1329
- followingExternal = false;
1576
+ followedGrid = null;
1330
1577
  const proposed = proposeDashboardGrid();
1331
1578
  if (belowDashboardFloor(floorCols, floorRows)) return this.takeGrid(floorCols, floorRows);
1332
1579
  return proposed !== null && this.takeGrid(
@@ -44,7 +44,7 @@ button.active { background: #3d2c14; border-color: #8a6d3b; color: #e8c284; }
44
44
  /* Amber, not the banner's red: a held prompt is the session waiting on YOU, not
45
45
  a fault. Deliberately loud: the whole feature exists because a held prompt
46
46
  can go unnoticed for minutes at a time. */
47
- #prompt-alert {
47
+ #prompt-alert, #copy-notice {
48
48
  padding: 8px 14px; background: #3d2f14; color: #f0c674;
49
49
  border-bottom: 1px solid #7a5c1e; font-size: 12px;
50
50
  }
@@ -58,6 +58,7 @@
58
58
  elements: {
59
59
  dot: document.getElementById('dot'),
60
60
  banner,
61
+ copyNotice: document.getElementById('copy-notice'),
61
62
  size: document.getElementById('size'),
62
63
  inputSource: document.getElementById('input-source'),
63
64
  readonly: document.getElementById('readonly'),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "shellpuppet",
3
- "version": "0.4.1",
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",