@lethevimlet/sshift 1.9.9 → 2.0.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.
package/README.md CHANGED
@@ -233,11 +233,13 @@ SSHIFT includes built-in plugins that detect when AI coding tools are waiting fo
233
233
 
234
234
  ### OpenCode Attention
235
235
 
236
- Detects when [OpenCode](https://opencode.ai) is waiting for input by tracking its spinner characters (⬝ ■ ▣) and prompt patterns. When the spinner stops or a prompt appears, the tab flashes.
236
+ Detects when [OpenCode](https://opencode.ai) finishes working (its spinner and "esc interrupt" hint disappear) and flashes the tab.
237
237
 
238
238
  ### Claude Attention
239
239
 
240
- Detects when [Claude Code](https://claude.ai) is waiting for input by tracking its spinner characters (⠋⠙⠹ braille patterns, ·✢✳✶✻✽) and prompt patterns like "❯", "Do you want", "Allow", and "Esc to cancel".
240
+ Detects when [Claude Code](https://claude.ai) finishes working or shows a permission dialog ("esc to interrupt" and the spinner disappear) and flashes the tab.
241
+
242
+ A flash stops as soon as you look at the tab and does not come back until you send the next prompt in that session. Turn each one on or off in **Settings → Sessions** (or **Settings → Plugins**).
241
243
 
242
244
  ### Enabling Plugins
243
245
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lethevimlet/sshift",
3
- "version": "1.9.9",
3
+ "version": "2.0.0",
4
4
  "description": "Web-based SSH + SFTP terminal client with tabs and bookmarks",
5
5
  "main": "src/server/index.js",
6
6
  "bin": {
@@ -209,6 +209,12 @@ class ClaudeAttentionPlugin {
209
209
  agentBytes: 0, // agent-driven bytes in the rolling window
210
210
  agentWindowStart: 0,
211
211
  cooldownUntil: 0,
212
+ // Flashing is allowed only after a prompt. Seeing a flash disarms
213
+ // it; the next real keystroke in the session re-arms it. Without
214
+ // this, a TUI repaint (resize, tab switch, status refresh) looked
215
+ // like a new working episode and the tab flashed again although
216
+ // nothing was asked.
217
+ armed: true,
212
218
  });
213
219
  }
214
220
  return this._sessionState.get(sessionId);
@@ -266,6 +272,11 @@ class ClaudeAttentionPlugin {
266
272
  _startFlash(sessionId, { force = false } = {}) {
267
273
  const s = this._getSessionState(sessionId);
268
274
  const now = Date.now();
275
+ // Already seen since the last prompt: nothing new to announce.
276
+ if (!s.armed) {
277
+ s.pendingAttention = false;
278
+ return;
279
+ }
269
280
  // Suppressed for now — pendingAttention keeps it queued for a retry
270
281
  // instead of dropping the event on the floor.
271
282
  if (now < s.cooldownUntil) return;
@@ -447,8 +458,22 @@ class ClaudeAttentionPlugin {
447
458
  this._scheduleEvaluate(sessionId);
448
459
  }
449
460
 
450
- onUserInput(sessionId /*, data */) {
461
+ // True for input the user actually typed. Terminal-generated reports
462
+ // (focus in/out when the tab gains or loses focus, mouse wheel/click
463
+ // reports) are not a prompt and must not re-arm the flash.
464
+ _isTypedInput(data) {
465
+ if (typeof data !== 'string') return !!data;
466
+ const rest = data
467
+ .replace(/\x1b\[[IO]/g, '')
468
+ .replace(/\x1b\[<\d+;\d+;\d+[Mm]/g, '')
469
+ .replace(/\x1b\[M[\s\S]{3}/g, '');
470
+ return rest.length > 0;
471
+ }
472
+
473
+ onUserInput(sessionId, data) {
451
474
  const s = this._getSessionState(sessionId);
475
+ if (data !== undefined && !this._isTypedInput(data)) return;
476
+ s.armed = true;
452
477
  s.lastUserInputAt = Date.now();
453
478
  // The user is here — stop flashing and hold off for a while. The
454
479
  // current episode is dropped as well: if the agent really is working,
@@ -461,7 +486,12 @@ class ClaudeAttentionPlugin {
461
486
  }
462
487
 
463
488
  // A client reported the user is looking at this tab.
489
+ // Once the result has been seen, stay quiet until the next prompt. A tab
490
+ // viewed while the agent is still working stays armed so the finish of
491
+ // that run is still announced.
464
492
  onSessionFocus(sessionId) {
493
+ const s = this._getSessionState(sessionId);
494
+ if (!s.workEpisode) s.armed = false;
465
495
  this._stopFlash(sessionId, { cooldown: true });
466
496
  }
467
497
 
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "claude-attention",
3
- "version": "2.1.0",
3
+ "version": "2.2.0",
4
4
  "description": "Flashes SSH tabs when Claude Code finishes working and is waiting for you (state-transition detection, no brittle prompt patterns)",
5
5
  "type": "sshift-plugin"
6
6
  }
@@ -193,6 +193,12 @@ class OpenCodeAttentionPlugin {
193
193
  agentBytes: 0, // agent-driven bytes in the rolling window
194
194
  agentWindowStart: 0,
195
195
  cooldownUntil: 0,
196
+ // Flashing is allowed only after a prompt. Seeing a flash disarms
197
+ // it; the next real keystroke in the session re-arms it. Without
198
+ // this, a TUI repaint (resize, tab switch, status refresh) looked
199
+ // like a new working episode and the tab flashed again although
200
+ // nothing was asked.
201
+ armed: true,
196
202
  });
197
203
  }
198
204
  return this._sessionState.get(sessionId);
@@ -250,6 +256,11 @@ class OpenCodeAttentionPlugin {
250
256
  _startFlash(sessionId, { force = false } = {}) {
251
257
  const s = this._getSessionState(sessionId);
252
258
  const now = Date.now();
259
+ // Already seen since the last prompt: nothing new to announce.
260
+ if (!s.armed) {
261
+ s.pendingAttention = false;
262
+ return;
263
+ }
253
264
  // Suppressed for now — pendingAttention keeps it queued for a retry
254
265
  // instead of dropping the event on the floor.
255
266
  if (now < s.cooldownUntil) return;
@@ -431,8 +442,22 @@ class OpenCodeAttentionPlugin {
431
442
  this._scheduleEvaluate(sessionId);
432
443
  }
433
444
 
434
- onUserInput(sessionId /*, data */) {
445
+ // True for input the user actually typed. Terminal-generated reports
446
+ // (focus in/out when the tab gains or loses focus, mouse wheel/click
447
+ // reports) are not a prompt and must not re-arm the flash.
448
+ _isTypedInput(data) {
449
+ if (typeof data !== 'string') return !!data;
450
+ const rest = data
451
+ .replace(/\x1b\[[IO]/g, '')
452
+ .replace(/\x1b\[<\d+;\d+;\d+[Mm]/g, '')
453
+ .replace(/\x1b\[M[\s\S]{3}/g, '');
454
+ return rest.length > 0;
455
+ }
456
+
457
+ onUserInput(sessionId, data) {
435
458
  const s = this._getSessionState(sessionId);
459
+ if (data !== undefined && !this._isTypedInput(data)) return;
460
+ s.armed = true;
436
461
  s.lastUserInputAt = Date.now();
437
462
  // The user is here — stop flashing and hold off for a while. The
438
463
  // current episode is dropped as well: if the agent really is working,
@@ -445,7 +470,12 @@ class OpenCodeAttentionPlugin {
445
470
  }
446
471
 
447
472
  // A client reported the user is looking at this tab.
473
+ // Once the result has been seen, stay quiet until the next prompt. A tab
474
+ // viewed while the agent is still working stays armed so the finish of
475
+ // that run is still announced.
448
476
  onSessionFocus(sessionId) {
477
+ const s = this._getSessionState(sessionId);
478
+ if (!s.workEpisode) s.armed = false;
449
479
  this._stopFlash(sessionId, { cooldown: true });
450
480
  }
451
481
 
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "opencode-attention",
3
- "version": "2.1.0",
3
+ "version": "2.2.0",
4
4
  "description": "Flashes SSH tabs when OpenCode finishes working and is waiting for you (state-transition detection, no brittle prompt patterns)",
5
5
  "type": "sshift-plugin"
6
6
  }
@@ -893,6 +893,34 @@
893
893
  </label>
894
894
  </div>
895
895
  </div>
896
+ <div class="setting-item">
897
+ <label class="setting-label">
898
+ <i class="fas fa-bell"></i> Flash Tab When Claude Code Waits
899
+ </label>
900
+ <div class="setting-description">
901
+ Flash the tab when Claude Code finishes working and waits for your input. A flash stops when you look at the tab and does not come back until you send the next prompt.
902
+ </div>
903
+ <div class="setting-control">
904
+ <label class="toggle-switch">
905
+ <input type="checkbox" class="attention-plugin-toggle" id="claudeAttentionToggle" data-plugin="claude-attention">
906
+ <span class="toggle-slider"></span>
907
+ </label>
908
+ </div>
909
+ </div>
910
+ <div class="setting-item">
911
+ <label class="setting-label">
912
+ <i class="fas fa-bell"></i> Flash Tab When OpenCode Waits
913
+ </label>
914
+ <div class="setting-description">
915
+ Flash the tab when OpenCode finishes working and waits for your input. A flash stops when you look at the tab and does not come back until you send the next prompt.
916
+ </div>
917
+ <div class="setting-control">
918
+ <label class="toggle-switch">
919
+ <input type="checkbox" class="attention-plugin-toggle" id="opencodeAttentionToggle" data-plugin="opencode-attention">
920
+ <span class="toggle-slider"></span>
921
+ </label>
922
+ </div>
923
+ </div>
896
924
  </div>
897
925
 
898
926
  <div class="settings-category" id="settings-category-terminal" style="display:none;">
@@ -8048,12 +8048,40 @@ if (keepaliveCountMaxInput && this.sshKeepaliveCountMax) {
8048
8048
  this.togglePlugin(pluginName, enabled, e.target);
8049
8049
  });
8050
8050
  });
8051
+ this._syncAttentionToggles(plugins);
8051
8052
  } catch (err) {
8052
8053
  console.error('[SSHIFT] Error loading plugins:', err);
8053
8054
  pluginsList.innerHTML = '<div class="plugins-loading">Failed to load plugins</div>';
8054
8055
  }
8055
8056
  }
8056
8057
 
8058
+ // Settings → Sessions has its own switches for the two tab-flash plugins
8059
+ // (the same setting as their cards in Settings → Plugins). They reflect
8060
+ // the plugin list and stay hidden for a plugin the server doesn't have.
8061
+ _syncAttentionToggles(plugins) {
8062
+ document.querySelectorAll('.attention-plugin-toggle').forEach(toggle => {
8063
+ const plugin = Array.isArray(plugins)
8064
+ ? plugins.find(p => p.name === toggle.dataset.plugin && !p.missing)
8065
+ : null;
8066
+ const item = toggle.closest('.setting-item');
8067
+ if (item) item.style.display = plugin ? '' : 'none';
8068
+ toggle.checked = !!(plugin && plugin.enabled);
8069
+ if (!toggle._attentionBound) {
8070
+ toggle._attentionBound = true;
8071
+ toggle.addEventListener('change', (e) => {
8072
+ this.togglePlugin(e.target.dataset.plugin, e.target.checked, e.target);
8073
+ });
8074
+ }
8075
+ });
8076
+ }
8077
+
8078
+ // Keep every switch for one plugin (Sessions + Plugins cards) in step.
8079
+ _setPluginToggleState(name, enabled) {
8080
+ document.querySelectorAll('.plugin-toggle, .attention-plugin-toggle').forEach(toggle => {
8081
+ if (toggle.dataset.plugin === name) toggle.checked = enabled;
8082
+ });
8083
+ }
8084
+
8057
8085
  async togglePlugin(name, enabled, toggleEl) {
8058
8086
  try {
8059
8087
  const headers = { 'Content-Type': 'application/json' };
@@ -8065,15 +8093,16 @@ if (keepaliveCountMaxInput && this.sshKeepaliveCountMax) {
8065
8093
  });
8066
8094
 
8067
8095
  if (!response.ok) {
8068
- toggleEl.checked = !enabled;
8096
+ this._setPluginToggleState(name, !enabled);
8069
8097
  this.showToast('Failed to update plugin', 'error');
8070
8098
  return;
8071
8099
  }
8072
8100
 
8101
+ this._setPluginToggleState(name, enabled);
8073
8102
  this.showToast(`Plugin "${name}" ${enabled ? 'enabled' : 'disabled'}`, 'success');
8074
8103
  } catch (err) {
8075
8104
  console.error('[SSHIFT] Error toggling plugin:', err);
8076
- toggleEl.checked = !enabled;
8105
+ this._setPluginToggleState(name, !enabled);
8077
8106
  this.showToast('Failed to update plugin', 'error');
8078
8107
  }
8079
8108
  }
@@ -13787,24 +13816,53 @@ async syncTabsFromServer(...args) {
13787
13816
  this._armDisconnectToast();
13788
13817
  return;
13789
13818
  }
13819
+ const engine = socket.io && socket.io.engine;
13820
+ // "Connected" on top of a transport that is already closing or closed
13821
+ // is dead: nothing will ever arrive on it.
13822
+ if (engine && engine.readyState !== 'open') {
13823
+ this._forceReconnect(reason + ', transport ' + engine.readyState);
13824
+ return;
13825
+ }
13790
13826
  // Connected on paper: prove it. Throttled unless this is a real wake.
13791
13827
  const now = Date.now();
13792
13828
  if (this._probeInFlight) return;
13793
13829
  if (!force && this._lastProbeAt && now - this._lastProbeAt < 15000) return;
13794
13830
  this._lastProbeAt = now;
13795
13831
  this._probeInFlight = true;
13796
- const engine = socket.io && socket.io.engine;
13797
13832
  socket.timeout(this.PROBE_TIMEOUT_MS).emit('sshift-ping', (err) => {
13798
13833
  this._probeInFlight = false;
13799
13834
  if (!err) return;
13800
13835
  // Only tear down the transport the probe was sent on.
13801
13836
  if (socket.connected && socket.io && socket.io.engine === engine) {
13802
- console.warn('[SSHIFT] Connection probe timed out (' + reason + '), reconnecting');
13803
- try { engine.close(); } catch (_) {}
13837
+ this._forceReconnect('probe timed out, ' + reason);
13804
13838
  }
13805
13839
  });
13806
13840
  }
13807
13841
 
13842
+ /**
13843
+ * Drop the current connection and dial a new one, without relying on the
13844
+ * dead transport to cooperate. engine.close() alone is NOT enough: with
13845
+ * packets queued (the probe itself, keystrokes typed after waking) it
13846
+ * waits for a "drain" that a dead socket never emits, leaving the engine
13847
+ * stuck in "closing" — the socket then claims to be connected forever and
13848
+ * every later probe is silently dropped (v1.9.9 bug: wake was detected but
13849
+ * the page only recovered with F5). socket.disconnect() closes the
13850
+ * manager regardless of the engine, and connect() opens a new engine.
13851
+ */
13852
+ _forceReconnect(reason) {
13853
+ const socket = this.socket;
13854
+ if (!socket) return;
13855
+ console.warn('[SSHIFT] Forcing a new connection (' + reason + ')');
13856
+ const engine = socket.io && socket.io.engine;
13857
+ this._lastKickAt = Date.now();
13858
+ this._probeInFlight = false;
13859
+ try { socket.disconnect(); } catch (_) {}
13860
+ // Make sure the old transport is really gone (no stray events/timers).
13861
+ try { if (engine && engine.transport) engine.transport.close(); } catch (_) {}
13862
+ socket.connect();
13863
+ this._armDisconnectToast();
13864
+ }
13865
+
13808
13866
  _cancelDisconnectToast() {
13809
13867
  if (this._disconnectToastTimer) {
13810
13868
  clearTimeout(this._disconnectToastTimer);