@lethevimlet/sshift 1.0.3 → 1.0.4

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.
@@ -33,6 +33,7 @@ class SSHIFTClient {
33
33
  this.isSyncingTabs = false; // Flag to prevent saveTabs emission during tabs-sync
34
34
  this.sftpClipboard = null; // For cut/copy/paste: { action: 'cut'|'copy', path: string, name: string, sessionId: string }
35
35
  this.terminalClipboardContent = null; // Pre-read clipboard content for context menu paste
36
+ this.osc52Buffer = null; // Buffered OSC 52 clipboard content pending write
36
37
  this.terminalColorOverride = true; // Default to true, will be loaded in initThemeAndAccent
37
38
  this.terminalBgColor = '#0d1117';
38
39
  this.terminalFgColor = '#e6edf3';
@@ -71,7 +72,7 @@ class SSHIFTClient {
71
72
  };
72
73
 
73
74
  // Terminal font size (for pinch-to-zoom on mobile)
74
- this.terminalFontSize = 14; // Default font size
75
+ this.terminalFontSize = window.innerWidth <= 768 ? 11 : 14;
75
76
  this.minFontSize = 8; // Minimum font size
76
77
  this.maxFontSize = 32; // Maximum font size
77
78
 
@@ -713,28 +714,37 @@ class SSHIFTClient {
713
714
 
714
715
  // Helper method to copy text to clipboard with fallback
715
716
  async copyToClipboard(text) {
716
- try {
717
- // Try modern clipboard API first
718
- if (navigator.clipboard && navigator.clipboard.writeText) {
717
+ // Try modern clipboard API first (requires secure context + user gesture)
718
+ if (navigator.clipboard && navigator.clipboard.writeText) {
719
+ try {
719
720
  await navigator.clipboard.writeText(text);
721
+ console.log('[SSHIFT] Clipboard API write succeeded, length:', text.length);
720
722
  return true;
723
+ } catch (err) {
724
+ console.warn('[SSHIFT] Clipboard API write failed:', err.name, err.message);
721
725
  }
722
- } catch (err) {
723
- console.warn('[SSHIFT] Modern clipboard API failed, trying fallback:', err);
726
+ } else {
727
+ console.warn('[SSHIFT] Clipboard API not available');
724
728
  }
725
729
 
726
- // Fallback to execCommand
730
+ // Fallback to execCommand (also requires user gesture in modern browsers)
727
731
  try {
728
732
  const textarea = document.createElement('textarea');
729
733
  textarea.value = text;
730
734
  textarea.style.position = 'fixed';
731
735
  textarea.style.left = '-9999px';
732
736
  textarea.style.top = '-9999px';
737
+ textarea.style.opacity = '0';
733
738
  document.body.appendChild(textarea);
734
739
  textarea.focus();
735
740
  textarea.select();
736
741
  const success = document.execCommand('copy');
737
742
  document.body.removeChild(textarea);
743
+ if (success) {
744
+ console.log('[SSHIFT] execCommand copy succeeded, length:', text.length);
745
+ } else {
746
+ console.warn('[SSHIFT] execCommand copy returned false');
747
+ }
738
748
  return success;
739
749
  } catch (err) {
740
750
  console.error('[SSHIFT] Fallback clipboard copy failed:', err);
@@ -903,7 +913,7 @@ sendChunkedInput(sessionId, data, chunkSize = 2048) {
903
913
  // Terminal Font Size Management (for pinch-to-zoom and buttons)
904
914
  loadTerminalFontSize() {
905
915
  // Don't persist - always start with default
906
- return 14; // Default font size
916
+ return window.innerWidth <= 768 ? 11 : 14;
907
917
  }
908
918
 
909
919
  saveTerminalFontSize(size) {
@@ -2437,6 +2447,8 @@ sendChunkedInput(sessionId, data, chunkSize = 2048) {
2437
2447
  // If we switched between mobile and desktop, re-apply the layout
2438
2448
  if (wasMobile !== this.isMobile && this.currentLayout) {
2439
2449
  console.log('[SSHIFT] Viewport changed, re-applying layout for', this.isMobile ? 'mobile' : 'desktop');
2450
+ this.terminalFontSize = this.isMobile ? 11 : 14;
2451
+ this.setTerminalFontSize(this.terminalFontSize);
2440
2452
  this.applyLayout(this.currentLayout);
2441
2453
  this.updateMobileTabsDropdown();
2442
2454
  }
@@ -2644,7 +2656,7 @@ const wheelHandler = (e) => {
2644
2656
  // ydisp is the current scroll position (number of lines scrolled back from bottom)
2645
2657
  // The terminal is at bottom if ydisp is 0 or very close to 0
2646
2658
  const maxYDisp = buffer.length - terminal.rows;
2647
- const currentYDisp = terminal.buffer.ydisp;
2659
+ const currentYDisp = terminal.buffer.active.viewportY;
2648
2660
 
2649
2661
  // We're at the bottom if we're within 2 lines of the bottom
2650
2662
  const isAtBottom = currentYDisp >= maxYDisp - 2;
@@ -2668,7 +2680,7 @@ const wheelHandler = (e) => {
2668
2680
  // ydisp = 0 means we're at the bottom (most recent content)
2669
2681
  // ydisp > 0 means we've scrolled up into the scrollback buffer (older content)
2670
2682
  const buffer = terminal.buffer.active;
2671
- const scrollTop = buffer.ydisp;
2683
+ const scrollTop = buffer.viewportY;
2672
2684
 
2673
2685
  // Get scroll direction
2674
2686
  const scrollDiff = scrollTop - session.lastScrollTop;
@@ -4209,6 +4221,9 @@ const wheelHandler = (e) => {
4209
4221
  // Initialize password toggle
4210
4222
  this.initPasswordToggle();
4211
4223
 
4224
+ // Initialize debug info dialog
4225
+ this.initDebugInfoDialog();
4226
+
4212
4227
  // Initialize sessions modal handlers
4213
4228
  this.initSessionsModalHandlers();
4214
4229
 
@@ -4806,8 +4821,24 @@ const wheelHandler = (e) => {
4806
4821
  }
4807
4822
 
4808
4823
  const downloadCertBtn = document.getElementById('downloadCertBtn');
4824
+ const customCertWarning = document.getElementById('customCertWarning');
4825
+
4826
+ fetch('/api/security-info').then(r => r.json()).then(info => {
4827
+ if (info.usesCustomCert) {
4828
+ if (downloadCertBtn) {
4829
+ downloadCertBtn.disabled = true;
4830
+ downloadCertBtn.style.opacity = '0.5';
4831
+ downloadCertBtn.style.cursor = 'not-allowed';
4832
+ }
4833
+ if (customCertWarning) {
4834
+ customCertWarning.style.display = 'flex';
4835
+ }
4836
+ }
4837
+ }).catch(() => {});
4838
+
4809
4839
  if (downloadCertBtn) {
4810
4840
  downloadCertBtn.addEventListener('click', () => {
4841
+ if (downloadCertBtn.disabled) return;
4811
4842
  window.open('/api/cert', '_blank');
4812
4843
  });
4813
4844
  }
@@ -4839,26 +4870,69 @@ const wheelHandler = (e) => {
4839
4870
  }
4840
4871
 
4841
4872
  openSecurityInfoDialog() {
4873
+ const swStatusIcon = document.getElementById('swStatusIcon');
4874
+ const swStatusTitle = document.getElementById('swStatusTitle');
4842
4875
  const swStatusText = document.getElementById('swStatusText');
4843
- // Re-check actual SW state from navigator API
4876
+ const swStatusContainer = document.getElementById('swStatusContainer');
4877
+
4844
4878
  let swStatus = window._swStatus;
4845
4879
  if (navigator.serviceWorker && navigator.serviceWorker.controller) {
4846
4880
  swStatus = 'active';
4847
4881
  window._swStatus = 'active';
4848
4882
  }
4849
4883
 
4850
- if (swStatusText) {
4884
+ if (swStatusIcon && swStatusTitle && swStatusText && swStatusContainer) {
4885
+ swStatusContainer.classList.remove('sw-status-active', 'sw-status-failed', 'sw-status-unsupported');
4886
+
4851
4887
  if (swStatus === 'active') {
4852
- swStatusText.innerHTML = '<i class="fas fa-check-circle" style="color: var(--accent-success, #4caf50);"></i> Service Worker is <strong>active</strong>. Offline caching is available.';
4888
+ swStatusContainer.classList.add('sw-status-active');
4889
+ swStatusIcon.innerHTML = '<i class="fas fa-check-circle"></i>';
4890
+ swStatusTitle.textContent = 'Connected';
4891
+ swStatusText.innerHTML =
4892
+ '<ul class="sw-feature-list">' +
4893
+ '<li><i class="fas fa-check"></i> No browser security warnings</li>' +
4894
+ '<li><i class="fas fa-check"></i> Installable as app (PWA)</li>' +
4895
+ '<li><i class="fas fa-check"></i> Clipboard API access</li>' +
4896
+ '</ul>';
4853
4897
  } else if (swStatus === 'failed') {
4854
- swStatusText.innerHTML = '<i class="fas fa-exclamation-triangle" style="color: var(--accent-danger, #f44336);"></i> Service Worker <strong>failed to register</strong>: ' + (window._swError || 'Unknown error') + '. This is usually caused by an untrusted HTTPS certificate. Download and install the certificate below to fix this, then reload the page.';
4898
+ swStatusContainer.classList.add('sw-status-failed');
4899
+ swStatusIcon.innerHTML = '<i class="fas fa-exclamation-triangle"></i>';
4900
+ swStatusTitle.textContent = 'Connection Failed';
4901
+ swStatusText.innerHTML =
4902
+ '<p>' + (window._swError || 'Unknown error') + '</p>' +
4903
+ '<ul class="sw-feature-list">' +
4904
+ '<li><i class="fas fa-times"></i> No browser security warnings</li>' +
4905
+ '<li><i class="fas fa-times"></i> Installable as app (PWA)</li>' +
4906
+ '<li><i class="fas fa-times"></i> Clipboard API access</li>' +
4907
+ '</ul>' +
4908
+ '<p class="sw-hint">Trust the HTTPS certificate to enable all features.</p>';
4855
4909
  } else if (swStatus === 'redundant') {
4856
- swStatusText.innerHTML = '<i class="fas fa-exclamation-triangle" style="color: var(--accent-danger, #f44336);"></i> Service Worker became <strong>redundant</strong>. ' + (window._swError || 'The HTTPS certificate may not be trusted.') + ' Download and install the certificate below, then reload the page.';
4910
+ swStatusContainer.classList.add('sw-status-failed');
4911
+ swStatusIcon.innerHTML = '<i class="fas fa-exclamation-triangle"></i>';
4912
+ swStatusTitle.textContent = 'Connection Failed';
4913
+ swStatusText.innerHTML =
4914
+ '<p>' + (window._swError || 'The HTTPS certificate may not be trusted.') + '</p>' +
4915
+ '<ul class="sw-feature-list">' +
4916
+ '<li><i class="fas fa-times"></i> No browser security warnings</li>' +
4917
+ '<li><i class="fas fa-times"></i> Installable as app (PWA)</li>' +
4918
+ '<li><i class="fas fa-times"></i> Clipboard API access</li>' +
4919
+ '</ul>' +
4920
+ '<p class="sw-hint">Trust the HTTPS certificate to enable all features.</p>';
4857
4921
  } else if (swStatus === 'unsupported') {
4858
- swStatusText.innerHTML = '<i class="fas fa-info-circle" style="color: var(--accent-warning, #ff9800);"></i> Service Workers are <strong>not supported</strong> in this browser.';
4922
+ swStatusContainer.classList.add('sw-status-unsupported');
4923
+ swStatusIcon.innerHTML = '<i class="fas fa-info-circle"></i>';
4924
+ swStatusTitle.textContent = 'Not Supported';
4925
+ swStatusText.innerHTML =
4926
+ '<p>Service Workers are not available in this browser.</p>' +
4927
+ '<ul class="sw-feature-list">' +
4928
+ '<li><i class="fas fa-times"></i> No browser security warnings</li>' +
4929
+ '<li><i class="fas fa-times"></i> Installable as app (PWA)</li>' +
4930
+ '<li><i class="fas fa-times"></i> Clipboard API access</li>' +
4931
+ '</ul>';
4859
4932
  } else {
4860
- // Still loading, retry
4861
- swStatusText.innerHTML = '<i class="fas fa-spinner fa-spin"></i> Checking...';
4933
+ swStatusIcon.innerHTML = '<i class="fas fa-spinner fa-spin"></i>';
4934
+ swStatusTitle.textContent = 'Checking...';
4935
+ swStatusText.textContent = 'Detecting service worker status';
4862
4936
  setTimeout(() => this.openSecurityInfoDialog(), 500);
4863
4937
  return;
4864
4938
  }
@@ -4867,6 +4941,63 @@ const wheelHandler = (e) => {
4867
4941
  this.openModal('securityInfoModal');
4868
4942
  }
4869
4943
 
4944
+ // Debug Info Dialog
4945
+ initDebugInfoDialog() {
4946
+ const showBtn = document.getElementById('showDebugInfoBtn');
4947
+ if (showBtn) {
4948
+ showBtn.addEventListener('click', () => {
4949
+ this.openDebugInfoDialog();
4950
+ });
4951
+ }
4952
+
4953
+ const closeBtn = document.getElementById('closeDebugInfoModal');
4954
+ if (closeBtn) {
4955
+ closeBtn.addEventListener('click', () => {
4956
+ this.closeModal('debugInfoModal');
4957
+ });
4958
+ }
4959
+
4960
+ const closeBtn2 = document.getElementById('closeDebugInfoBtn');
4961
+ if (closeBtn2) {
4962
+ closeBtn2.addEventListener('click', () => {
4963
+ this.closeModal('debugInfoModal');
4964
+ });
4965
+ }
4966
+
4967
+ const modal = document.getElementById('debugInfoModal');
4968
+ if (modal) {
4969
+ modal.addEventListener('click', (e) => {
4970
+ if (e.target === modal) {
4971
+ this.closeModal('debugInfoModal');
4972
+ }
4973
+ });
4974
+ }
4975
+ }
4976
+
4977
+ openDebugInfoDialog() {
4978
+ fetch('/api/debug-info').then(r => r.json()).then(info => {
4979
+ const configPathEl = document.getElementById('debugConfigPath');
4980
+ const dataDirEl = document.getElementById('debugDataDir');
4981
+ const certPathEl = document.getElementById('debugCertPath');
4982
+ const keyPathEl = document.getElementById('debugKeyPath');
4983
+ const certTypeEl = document.getElementById('debugCertType');
4984
+
4985
+ if (configPathEl) configPathEl.textContent = info.configPath || 'N/A';
4986
+ if (dataDirEl) dataDirEl.textContent = info.dataDir || 'N/A';
4987
+ if (certPathEl) certPathEl.textContent = info.certPath || 'N/A';
4988
+ if (keyPathEl) keyPathEl.textContent = info.keyPath || 'N/A';
4989
+ if (certTypeEl) certTypeEl.textContent = info.usesCustomCert ? 'Custom' : 'Self-signed';
4990
+ }).catch(() => {
4991
+ const ids = ['debugConfigPath', 'debugDataDir', 'debugCertPath', 'debugKeyPath', 'debugCertType'];
4992
+ ids.forEach(id => {
4993
+ const el = document.getElementById(id);
4994
+ if (el) el.textContent = 'Error loading';
4995
+ });
4996
+ });
4997
+
4998
+ this.openModal('debugInfoModal');
4999
+ }
5000
+
4870
5001
  // Sessions Modal
4871
5002
  async openSessionsModal() {
4872
5003
  this.openModal('manageSessionsModal');
@@ -6415,6 +6546,70 @@ const wheelHandler = (e) => {
6415
6546
  console.log('[SSHIFT] Image addon disabled in settings');
6416
6547
  }
6417
6548
 
6549
+ // Register OSC 52 handler for clipboard operations from remote terminals
6550
+ // This allows programs like opencode, tmux, vim, etc. to set the clipboard
6551
+ // via the OSC 52 escape sequence: \e]52;c;<base64-text>\007
6552
+ //
6553
+ // Browser Clipboard API requires a user gesture, but OSC 52 data arrives
6554
+ // asynchronously from the SSH stream. We buffer the content synchronously
6555
+ // and flush it on the next user interaction (click, keydown, touchstart).
6556
+ // Immediate writes are also attempted but may fail without a user gesture.
6557
+ try {
6558
+ const flushOsc52Buffer = () => {
6559
+ if (this.osc52Buffer !== null && this.osc52Buffer !== undefined) {
6560
+ const text = this.osc52Buffer;
6561
+ this.osc52Buffer = null;
6562
+ console.log('[SSHIFT] Flushing OSC 52 clipboard buffer, length:', text.length);
6563
+ this.copyToClipboard(text).then(success => {
6564
+ if (success) {
6565
+ console.log('[SSHIFT] OSC 52 clipboard write succeeded (flushed on user gesture)');
6566
+ this.showToast('Copied to clipboard', 'success');
6567
+ } else {
6568
+ console.warn('[SSHIFT] OSC 52 clipboard write failed after flush, re-buffering');
6569
+ this.osc52Buffer = text;
6570
+ }
6571
+ }).catch(err => {
6572
+ console.warn('[SSHIFT] OSC 52 clipboard write failed:', err);
6573
+ this.osc52Buffer = text;
6574
+ });
6575
+ }
6576
+ };
6577
+ document.addEventListener('click', flushOsc52Buffer, true);
6578
+ document.addEventListener('keydown', flushOsc52Buffer, true);
6579
+ document.addEventListener('touchstart', flushOsc52Buffer, true);
6580
+
6581
+ // Store for cleanup when the session is closed
6582
+ const sess = this.sessions.get(sessionId);
6583
+ if (sess) sess.osc52FlushListener = flushOsc52Buffer;
6584
+
6585
+ // Also register as fallback with xterm.js's OSC handler in case any
6586
+ // OSC 52 sequences slip through the data stream interceptor (e.g. from
6587
+ // screen sync restoration). The data stream interceptor is the primary handler.
6588
+ terminal.registerOscHandler(52, (data) => {
6589
+ console.log('[SSHIFT] OSC 52 handler fallback triggered (should be handled by stream interceptor)');
6590
+ const semicolonIndex = data.indexOf(';');
6591
+ if (semicolonIndex === -1) return true;
6592
+ const content = data.substring(semicolonIndex + 1);
6593
+ if (!content) {
6594
+ this.osc52Buffer = '';
6595
+ return true;
6596
+ }
6597
+ try {
6598
+ const decoded = atob(content);
6599
+ this.osc52Buffer = decoded;
6600
+ this.copyToClipboard(decoded).then(success => {
6601
+ if (success) this.osc52Buffer = null;
6602
+ }).catch(() => {});
6603
+ } catch (e) {
6604
+ console.warn('[SSHIFT] OSC 52 base64 decode failed:', e);
6605
+ }
6606
+ return true;
6607
+ });
6608
+ console.log('[SSHIFT] OSC 52 clipboard handler registered');
6609
+ } catch (e) {
6610
+ console.warn('[SSHIFT] Failed to register OSC 52 handler:', e.message);
6611
+ }
6612
+
6418
6613
  // Enable cursor blink after addons are loaded to avoid
6419
6614
  // repaint interference during initial render
6420
6615
  terminal.options.cursorBlink = true;
@@ -6609,6 +6804,7 @@ const wheelHandler = (e) => {
6609
6804
 
6610
6805
  // Ctrl+V - Paste
6611
6806
  if (event.ctrlKey && event.key === 'v' && event.type === 'keydown') {
6807
+ event.preventDefault(); // Prevent browser paste event to avoid double-paste
6612
6808
  this.readFromClipboard().then(text => {
6613
6809
  if (text) {
6614
6810
  const sess = this.sessions.get(sessionId);
@@ -6620,7 +6816,7 @@ const wheelHandler = (e) => {
6620
6816
  this.showToast('Clipboard is empty', 'info');
6621
6817
  }
6622
6818
  });
6623
- return false; // Prevent default behavior
6819
+ return false; // Prevent xterm key handling
6624
6820
  }
6625
6821
 
6626
6822
  // Ctrl+Shift+C - Force copy
@@ -6642,6 +6838,7 @@ const wheelHandler = (e) => {
6642
6838
 
6643
6839
  // Ctrl+Shift+V - Force paste
6644
6840
  if (event.ctrlKey && event.shiftKey && event.key === 'V') {
6841
+ event.preventDefault(); // Prevent browser paste event to avoid double-paste
6645
6842
  this.readFromClipboard().then(text => {
6646
6843
  if (text) {
6647
6844
  const sess = this.sessions.get(sessionId);
@@ -6693,29 +6890,6 @@ const wheelHandler = (e) => {
6693
6890
  this.showTerminalContextMenu(sessionId, terminal, e);
6694
6891
  });
6695
6892
 
6696
- // Handle native paste event from browser
6697
- container.addEventListener('paste', (e) => {
6698
- console.log('[SSHIFT] Native paste event triggered');
6699
- e.preventDefault();
6700
-
6701
- // Get pasted data from clipboard
6702
- let pastedText = '';
6703
- if (e.clipboardData && e.clipboardData.getData) {
6704
- pastedText = e.clipboardData.getData('text/plain');
6705
- }
6706
-
6707
- if (pastedText) {
6708
- console.log('[SSHIFT] Pasted text length:', pastedText.length);
6709
- const sess = this.sessions.get(sessionId);
6710
- if (sess && sess.connected) {
6711
- this.sendChunkedInput(sessionId, pastedText);
6712
- this.showToast('Pasted from clipboard', 'success');
6713
- }
6714
- } else {
6715
- this.showToast('Clipboard is empty', 'info');
6716
- }
6717
- });
6718
-
6719
6893
  session.terminal = terminal;
6720
6894
  session.fitAddon = fitAddon;
6721
6895
 
@@ -6875,6 +7049,119 @@ const wheelHandler = (e) => {
6875
7049
  }
6876
7050
  }
6877
7051
 
7052
+ // Parse and handle OSC 52 clipboard sequences from terminal data stream.
7053
+ // Extracts clipboard content, writes it to browser clipboard, and safely
7054
+ // handles sequences that span across data chunks.
7055
+ // Also handles tmux DCS passthrough: \x1bPtmux;\x1b\x1b]52;c;...\x07\x1b\\
7056
+ _handleOsc52(data) {
7057
+ if (!data || data.indexOf('52;') === -1) return data;
7058
+
7059
+ let result = data;
7060
+
7061
+ // Handle tmux/screen DCS passthrough wrapper:
7062
+ // \x1bPtmux;\x1b wraps an inner escape sequence, terminated by \x1b\\
7063
+ // \x1bP\x1b (screen) similarly
7064
+ // We unwrap these by extracting the inner OSC 52 sequence.
7065
+ while (true) {
7066
+ const tmuxStart = result.indexOf('\x1bPtmux;\x1b');
7067
+ const screenStart = result.indexOf('\x1bP\x1b');
7068
+ let dcsStart = -1;
7069
+ let dcsPrefixLen = 0;
7070
+
7071
+ if (tmuxStart !== -1 && (screenStart === -1 || tmuxStart < screenStart)) {
7072
+ dcsStart = tmuxStart;
7073
+ dcsPrefixLen = '\x1bPtmux;\x1b'.length;
7074
+ } else if (screenStart !== -1) {
7075
+ dcsStart = screenStart;
7076
+ dcsPrefixLen = '\x1bP\x1b'.length;
7077
+ }
7078
+
7079
+ if (dcsStart !== -1) {
7080
+ // Find the DCS terminator: \x1b\\ (ST)
7081
+ const dcsEnd = result.indexOf('\x1b\\', dcsStart + dcsPrefixLen);
7082
+ if (dcsEnd !== -1) {
7083
+ // Extract the inner sequence and replace the whole DCS block with just the inner sequence
7084
+ const inner = result.substring(dcsStart + dcsPrefixLen, dcsEnd);
7085
+ result = result.substring(0, dcsStart) + inner + result.substring(dcsEnd + 2);
7086
+ } else {
7087
+ break; // Incomplete DCS, leave for next chunk
7088
+ }
7089
+ } else {
7090
+ break;
7091
+ }
7092
+ }
7093
+
7094
+ // Now process plain OSC 52 sequences
7095
+ if (result.indexOf('\x1b]52;') === -1) return result;
7096
+
7097
+ let searchFrom = 0;
7098
+
7099
+ while (true) {
7100
+ const startIdx = result.indexOf('\x1b]52;', searchFrom);
7101
+ if (startIdx === -1) break;
7102
+
7103
+ // Find end of OSC sequence: BEL (\x07) or ST (\x1b\\)
7104
+ let endIdx = -1;
7105
+ let endLen = 1;
7106
+ const belIdx = result.indexOf('\x07', startIdx + 5);
7107
+ const stIdx = result.indexOf('\x1b\\', startIdx + 5);
7108
+
7109
+ if (belIdx !== -1 && (stIdx === -1 || belIdx < stIdx)) {
7110
+ endIdx = belIdx;
7111
+ endLen = 1;
7112
+ } else if (stIdx !== -1) {
7113
+ endIdx = stIdx;
7114
+ endLen = 2;
7115
+ }
7116
+
7117
+ if (endIdx === -1) {
7118
+ break;
7119
+ }
7120
+
7121
+ // Extract the payload: everything between "ESC]52;" and the terminator
7122
+ const payloadStart = startIdx + 5; // skip \x1b]52;
7123
+ const payload = result.substring(payloadStart, endIdx);
7124
+ console.log('[SSHIFT] OSC 52 intercepted from stream, payload length:', payload.length);
7125
+
7126
+ // Parse: <target>;<base64>
7127
+ const semiIdx = payload.indexOf(';');
7128
+ if (semiIdx !== -1) {
7129
+ const clipboardTarget = payload.substring(0, semiIdx);
7130
+ const content = payload.substring(semiIdx + 1);
7131
+ if (content) {
7132
+ try {
7133
+ const decoded = atob(content);
7134
+ console.log('[SSHIFT] OSC 52 decoded, target:', clipboardTarget, 'length:', decoded.length, 'preview:', decoded.substring(0, 60));
7135
+ // Buffer synchronously, then try immediate write
7136
+ this.osc52Buffer = decoded;
7137
+ this.copyToClipboard(decoded).then(success => {
7138
+ if (success) {
7139
+ this.osc52Buffer = null;
7140
+ console.log('[SSHIFT] OSC 52 immediate clipboard write succeeded');
7141
+ } else {
7142
+ console.log('[SSHIFT] OSC 52 immediate write failed, will flush on next user gesture');
7143
+ }
7144
+ }).catch(() => {
7145
+ console.log('[SSHIFT] OSC 52 immediate write rejected, will flush on next user gesture');
7146
+ });
7147
+ } catch (e) {
7148
+ console.warn('[SSHIFT] OSC 52 base64 decode failed:', e);
7149
+ }
7150
+ } else {
7151
+ // Clear clipboard request
7152
+ this.osc52Buffer = '';
7153
+ navigator.clipboard.writeText('').catch(() => {});
7154
+ }
7155
+ }
7156
+
7157
+ // Remove the OSC 52 sequence from the data so xterm.js doesn't render garbage
7158
+ result = result.substring(0, startIdx) + result.substring(endIdx + endLen);
7159
+ searchFrom = startIdx;
7160
+ }
7161
+
7162
+ return result;
7163
+ }
7164
+
6878
7165
  _flushWriteChunks(sessionId) {
6879
7166
  const session = this.sessions.get(sessionId);
6880
7167
  if (!session || !session.terminal) {
@@ -6940,6 +7227,11 @@ const wheelHandler = (e) => {
6940
7227
  }, 3000);
6941
7228
  }
6942
7229
 
7230
+ // Intercept OSC 52 clipboard sequences before writing to terminal.
7231
+ // OSC 52 format: ESC ] 52 ; <target> ; <base64> (BEL or ST)
7232
+ // This is more reliable than registerOscHandler which may not fire.
7233
+ combined = this._handleOsc52(combined);
7234
+
6943
7235
  // Cap write size per frame. terminal.write() is synchronous and blocks
6944
7236
  // the main thread. We spill overflow to the next frame via flushRemaining.
6945
7237
  const MAX_WRITE_PER_FRAME = 32768;
@@ -7556,6 +7848,13 @@ const wheelHandler = (e) => {
7556
7848
  session.wheelHandler = null;
7557
7849
  session.wheelElement = null;
7558
7850
  }
7851
+ // Clean up OSC 52 clipboard flush listeners
7852
+ if (session.osc52FlushListener) {
7853
+ document.removeEventListener('click', session.osc52FlushListener, true);
7854
+ document.removeEventListener('keydown', session.osc52FlushListener, true);
7855
+ document.removeEventListener('touchstart', session.osc52FlushListener, true);
7856
+ session.osc52FlushListener = null;
7857
+ }
7559
7858
  if (session.terminal) {
7560
7859
  session.terminal.dispose();
7561
7860
  }
@@ -7665,6 +7964,12 @@ const wheelHandler = (e) => {
7665
7964
  if (session.wheelHandler && session.wheelElement) {
7666
7965
  session.wheelElement.removeEventListener('wheel', session.wheelHandler);
7667
7966
  }
7967
+ if (session.osc52FlushListener) {
7968
+ document.removeEventListener('click', session.osc52FlushListener, true);
7969
+ document.removeEventListener('keydown', session.osc52FlushListener, true);
7970
+ document.removeEventListener('touchstart', session.osc52FlushListener, true);
7971
+ session.osc52FlushListener = null;
7972
+ }
7668
7973
  if (session.terminal) {
7669
7974
  session.terminal.dispose();
7670
7975
  }
@@ -10120,6 +10425,12 @@ async syncTabsFromServer(tabs) {
10120
10425
 
10121
10426
  const data = await response.json();
10122
10427
 
10428
+ // Check for update error from server
10429
+ if (data.updateError) {
10430
+ this.handleUpdateError(data.updateError);
10431
+ return;
10432
+ }
10433
+
10123
10434
  // Update progress based on status
10124
10435
  if (data.updating) {
10125
10436
  // Still updating
@@ -10157,23 +10468,25 @@ async syncTabsFromServer(tabs) {
10157
10468
  window.location.reload();
10158
10469
  }, 1000);
10159
10470
  } else if (data.ready && data.version === oldVersion) {
10160
- // Server restarted but version is the same
10161
- // This might mean the update failed or we need to wait longer
10162
- if (attempts < maxAttempts) {
10163
- const progress = Math.min(90, 70 + (attempts * 0.5));
10164
- if (progressBar) {
10165
- progressBar.style.width = `${progress}%`;
10166
- }
10167
-
10168
- if (statusEl) {
10169
- statusEl.textContent = `Waiting for new version... (${attempts}/${maxAttempts})`;
10170
- }
10171
-
10172
- setTimeout(poll, 1000);
10173
- } else {
10174
- // Same version after timeout - might be an error
10175
- this.handleUpdateError('Server restarted but version unchanged. Please check the update manually.');
10471
+ // Server is back and ready. Same version could mean:
10472
+ // 1. Already at the latest version (npm install succeeded but no newer version exists)
10473
+ // 2. Update failed silently
10474
+ // Either way, the server is back and functional — just reload.
10475
+ if (progressBar) {
10476
+ progressBar.style.width = '100%';
10477
+ }
10478
+
10479
+ if (messageEl) {
10480
+ messageEl.textContent = 'Server restarted. Reloading page...';
10481
+ }
10482
+
10483
+ if (statusEl) {
10484
+ statusEl.textContent = `Current version: ${data.version}`;
10176
10485
  }
10486
+
10487
+ setTimeout(() => {
10488
+ window.location.reload();
10489
+ }, 1000);
10177
10490
  } else {
10178
10491
  // Unexpected state
10179
10492
  if (attempts < maxAttempts) {