@lethevimlet/sshift 1.7.3 → 1.7.5

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.
@@ -2,20 +2,22 @@
2
2
  * opencode-attention Plugin
3
3
  *
4
4
  * Flashes the tab when OpenCode (https://opencode.ai) finishes working and
5
- * is waiting for the user (reply complete, or a permission/question dialog).
5
+ * is waiting for the user (reply complete, or a permission/confirmation
6
+ * dialog).
6
7
  *
7
8
  * Detection strategy (state-transition based, not text-pattern based):
8
9
  *
9
10
  * 1. App detection is NON-STICKY: OpenCode is considered present only
10
- * while its UI signature (the "OpenCode" wordmark in the status bar /
11
- * splash) is visible in the CURRENT viewport of the headless terminal.
12
- * When the user exits back to a shell, the signature disappears and,
13
- * after a few misses, all state resets — so a shell prompt like "❯ "
14
- * can never flash the tab (the old sticky flag caused exactly that).
11
+ * while one of its UI signatures is visible in the CURRENT viewport of
12
+ * the headless terminal (the "OpenCode x.y.z" status bar, the
13
+ * "ctrl+p commands" hint, the "esc interrupt" hint). When the user
14
+ * exits back to a shell the signatures disappear and, after a few
15
+ * misses, no NEW working episode can start — so a shell prompt can
16
+ * never arm the engine.
15
17
  *
16
18
  * 2. "Working" is tracked from two signals:
17
- * - working indicators visible in the viewport footer (braille
18
- * spinner glyphs, legacy ⬝■▣ spinners, "esc to interrupt"), and
19
+ * - working indicators visible in the viewport footer (braille and
20
+ * block spinner glyphs, "esc to interrupt"/"esc interrupt"), and
19
21
  * - sustained agent-driven output: bytes that arrive while the user
20
22
  * has NOT typed recently (echo/UI responses to keystrokes are
21
23
  * ignored via userEchoWindowMs).
@@ -23,17 +25,34 @@
23
25
  * 3. The tab flashes ONLY on the working → idle TRANSITION: a working
24
26
  * episode was observed, the working indicator is gone, and no work
25
27
  * signal has been seen for idleThreshold ms. A finished reply and a
26
- * confirmation dialog both look like this transition, so no brittle
27
- * prompt regexes are needed.
28
+ * permission dialog both look like this transition, so no brittle
29
+ * prompt regexes ("❯ ", "(y/n)", "allow", ...) are needed — those
30
+ * match ordinary chat prose, code and shell prompts.
28
31
  *
29
- * 4. User input (keystrokes) stops an active flash immediately and
30
- * suppresses flashing for cooldownMs — the user is already there.
32
+ * 4. User input (keystrokes) ends the current working episode, stops an
33
+ * active flash and suppresses flashing for cooldownMs — the user is
34
+ * already there. A genuinely running agent re-arms the episode with
35
+ * its very next spinner frame, so nothing is lost.
31
36
  *
32
- * There are NO default attention text patterns: strings like "(y/n)",
33
- * "press enter" or "❯ " routinely appear inside chat prose, code and shell
34
- * prompts and caused constant false flashes. Custom `patterns` from the
35
- * config are still honored, but they are only evaluated while OpenCode is
36
- * on screen and not working.
37
+ * Things that made v1.7.3 miss most "waiting for input" events, and how
38
+ * they are handled now:
39
+ *
40
+ * - The viewport was read through getTerminalState(), which serializes
41
+ * the whole 10k-line scrollback and returns NULL past its 1MB guard.
42
+ * Busy agent sessions — exactly the ones worth watching — went blind.
43
+ * Now it reads getTerminalViewport() (visible screen only) and follows
44
+ * the alternate-screen marker, so OpenCode's full-screen TUI is read
45
+ * from the buffer it actually draws on.
46
+ * - A transition that landed inside the post-keystroke cooldown was
47
+ * dropped and never retried. The engine now keeps a pendingAttention
48
+ * flag and retries on every check until the flash actually goes out.
49
+ * - Losing the app signature (a dialog can cover the status bar) wiped
50
+ * the pending episode. App misses now only stop NEW episodes from
51
+ * starting; an armed one still gets to flash.
52
+ * - A flash the user dismissed by simply looking at the tab left the
53
+ * server stuck in "already flashing", swallowing every later event.
54
+ * Clients now report onSessionFocus, and a fresh transition re-emits
55
+ * the flash anyway.
37
56
  *
38
57
  * Configuration (in config.json under plugins[].config):
39
58
  * - flashDuration: number - Flash duration in ms, 0 = flash until focused (default: 0)
@@ -50,10 +69,16 @@
50
69
  * - minWorkBytes: number - Agent-driven bytes within workWindowMs that
51
70
  * mark the session as working (default: 600)
52
71
  * - workWindowMs: number - Rolling window for minWorkBytes (default: 2000)
53
- * - appMissLimit: number - Consecutive viewport checks without the app
54
- * signature before state resets (default: 3)
55
- * - appPatterns: string[] - Regexes replacing the default app signature
72
+ * - appMissLimit: number - Consecutive viewport checks without an app
73
+ * signature before new episodes are blocked (default: 3)
74
+ * - appPatterns: string[] - Regexes replacing the default app signatures
75
+ * - spinnerStaleMs: number - A bare spinner glyph only counts as "working" if
76
+ * output arrived within this window (default: 2000)
77
+ * - workStaleMs: number - A screen with no output at all for this long is
78
+ * never considered working (default: 60000)
56
79
  * - workingPatterns: string[] - Regexes replacing the default working indicators
80
+ * - workingHintPatterns: string[] - Regexes for run hints that count as working
81
+ * even on a quiet screen (default: "esc to interrupt")
57
82
  * - patterns: string[] - Extra attention regexes (footer lines, idle only)
58
83
  * - excludePatterns: string[] - Remove patterns (by source) from all lists
59
84
  */
@@ -72,15 +97,23 @@ class OpenCodeAttentionPlugin {
72
97
  minWorkBytes: config.minWorkBytes || 600,
73
98
  workWindowMs: config.workWindowMs || 2000,
74
99
  appMissLimit: config.appMissLimit || 3,
100
+ spinnerStaleMs: config.spinnerStaleMs || 2000,
101
+ workStaleMs: config.workStaleMs || 60000,
75
102
  };
76
103
 
77
- // App signature: the OpenCode TUI always renders its wordmark (status
78
- // bar "OpenCode x.y.z", splash logo). Case-SENSITIVE on purpose so
79
- // lowercase shell text (`cd opencode`, paths, package names) can't arm
80
- // the engine — and even a false positive here only ARMS it; a flash
81
- // still requires a real working → idle transition.
104
+ // App signatures: the OpenCode TUI always renders its wordmark (status
105
+ // bar "OpenCode x.y.z", splash logo) plus the command hint in the same
106
+ // bar. Case-SENSITIVE on purpose so lowercase shell text (`cd
107
+ // opencode`, paths, package names) can't arm the engine — and even a
108
+ // false positive here only ARMS it; a flash still requires a real
109
+ // working → idle transition.
82
110
  this._appPatterns = this._compileList(
83
- config.appPatterns || ['OpenCode'],
111
+ config.appPatterns || [
112
+ 'OpenCode',
113
+ 'ctrl\\+p commands',
114
+ 'esc interrupt',
115
+ 'esc to interrupt',
116
+ ],
84
117
  'appPatterns',
85
118
  '' // case-sensitive
86
119
  );
@@ -89,17 +122,30 @@ class OpenCodeAttentionPlugin {
89
122
  // - the full braille block (U+2800–U+28FF) covers every braille
90
123
  // spinner variant across OpenCode versions,
91
124
  // - ⬝■▣ are the legacy OpenCode spinner frames,
125
+ // - ◐◓◑◒◜◝◞◟ cover the arc/circle spinner frames,
92
126
  // - "esc to interrupt"-style hints cover text-based indicators.
93
127
  this._workingPatterns = this._compileList(
94
128
  config.workingPatterns || [
95
129
  '[\\u2800-\\u28FF]',
96
130
  '[⬝■▣]',
131
+ '[◐◓◑◒◜◝◞◟]',
97
132
  'esc to interrupt',
98
133
  'esc interrupt',
99
134
  ],
100
135
  'workingPatterns'
101
136
  );
102
137
 
138
+ // Text hints that stay on screen for the WHOLE run ("esc to
139
+ // interrupt"). Unlike a spinner glyph these are unambiguous, so they
140
+ // count as "working" even when the screen is completely quiet.
141
+ this._workingHintPatterns = this._compileList(
142
+ config.workingHintPatterns || [
143
+ 'esc to interrupt',
144
+ 'esc interrupt',
145
+ ],
146
+ 'workingHintPatterns'
147
+ );
148
+
103
149
  // Optional user-supplied attention patterns (none by default).
104
150
  this._attentionPatterns = this._compileList(config.patterns || [], 'patterns');
105
151
 
@@ -109,6 +155,7 @@ class OpenCodeAttentionPlugin {
109
155
  const source = new RegExp(p).source;
110
156
  this._appPatterns = this._appPatterns.filter(r => r.source !== source);
111
157
  this._workingPatterns = this._workingPatterns.filter(r => r.source !== source);
158
+ this._workingHintPatterns = this._workingHintPatterns.filter(r => r.source !== source);
112
159
  this._attentionPatterns = this._attentionPatterns.filter(r => r.source !== source);
113
160
  } catch (e) {
114
161
  console.error(`[opencode-attention] Invalid exclude pattern "${p}":`, e.message);
@@ -118,6 +165,7 @@ class OpenCodeAttentionPlugin {
118
165
  this._sessionState = new Map();
119
166
  this._checkTimers = new Map();
120
167
  this._dataTimers = new Map();
168
+ this._idleTimers = new Map();
121
169
  this._flashing = new Map();
122
170
  }
123
171
 
@@ -135,8 +183,10 @@ class OpenCodeAttentionPlugin {
135
183
  if (!this._sessionState.has(sessionId)) {
136
184
  this._sessionState.set(sessionId, {
137
185
  appVisible: false, // signature currently on screen
138
- appMissStreak: 0, // consecutive checks without the signature
139
- working: false, // inside a working episode
186
+ appMissStreak: 0, // consecutive checks without a signature
187
+ working: false, // working indicator seen recently
188
+ workEpisode: false, // a working episode is armed (not yet consumed)
189
+ pendingAttention: false, // wants to flash, hasn't managed to yet
140
190
  lastWorkSignalAt: 0, // last time any work signal was seen
141
191
  lastUserInputAt: 0, // last user keystroke
142
192
  lastOutputAt: 0, // last output of any kind
@@ -166,32 +216,58 @@ class OpenCodeAttentionPlugin {
166
216
  return false;
167
217
  }
168
218
 
169
- // Extract the current viewport (last `rows` lines) from the serialized
170
- // terminal state, ANSI-stripped, one entry per screen line.
219
+ // Extract the current viewport, ANSI-stripped, one entry per screen line.
220
+ //
221
+ // Prefers the cheap viewport-only serialization; getTerminalState() is a
222
+ // fallback for older hosts (it serializes the entire scrollback and
223
+ // returns null once that exceeds its size guard).
171
224
  _getViewportLines(sessionId) {
172
- const state = this.ctx.getTerminalState(sessionId);
225
+ let state = null;
226
+ if (typeof this.ctx.getTerminalViewport === 'function') {
227
+ state = this.ctx.getTerminalViewport(sessionId);
228
+ }
229
+ if (!state || !state.state) {
230
+ state = this.ctx.getTerminalState(sessionId);
231
+ }
173
232
  if (!state || !state.state) return null;
233
+
174
234
  const rows = state.rows || 24;
175
- const lines = state.state.split('\n');
235
+ let text = state.state;
236
+
237
+ // OpenCode's TUI runs on the alternate buffer, which the serializer
238
+ // appends after a `\x1b[?1049h` marker — everything before it is the
239
+ // scrolled-away normal buffer, not what the user is looking at.
240
+ const altMarker = text.lastIndexOf('\x1b[?1049h');
241
+ if (altMarker !== -1) {
242
+ text = text.slice(altMarker);
243
+ }
244
+
245
+ const lines = text.split('\n');
176
246
  const viewport = lines.slice(-rows);
177
247
  return viewport.map(l => this._stripAnsi(l));
178
248
  }
179
249
 
180
- _startFlash(sessionId) {
250
+ _startFlash(sessionId, { force = false } = {}) {
181
251
  const s = this._getSessionState(sessionId);
182
252
  const now = Date.now();
253
+ // Suppressed for now — pendingAttention keeps it queued for a retry
254
+ // instead of dropping the event on the floor.
183
255
  if (now < s.cooldownUntil) return;
184
256
  if (now - s.lastUserInputAt < this.config.userEchoWindowMs) return;
185
- if (this._flashing.get(sessionId)) return;
257
+ // `force` is used for a fresh transition: re-emitting is harmless and
258
+ // recovers from a flash the client cleared without telling us.
259
+ if (!force && this._flashing.get(sessionId)) return;
186
260
  this._flashing.set(sessionId, true);
261
+ s.pendingAttention = false;
187
262
  this.ctx.flashTab(sessionId, { duration: this.config.flashDuration || 0 });
188
263
  }
189
264
 
190
265
  _stopFlash(sessionId, { cooldown = false } = {}) {
266
+ const s = this._getSessionState(sessionId);
191
267
  if (cooldown) {
192
- const s = this._getSessionState(sessionId);
193
268
  s.cooldownUntil = Date.now() + this.config.cooldownMs;
194
269
  }
270
+ s.pendingAttention = false;
195
271
  if (!this._flashing.get(sessionId)) return;
196
272
  this._flashing.delete(sessionId);
197
273
  this.ctx.stopFlashTab(sessionId);
@@ -200,17 +276,30 @@ class OpenCodeAttentionPlugin {
200
276
  _resetSession(sessionId) {
201
277
  this._stopFlash(sessionId);
202
278
  this._sessionState.delete(sessionId);
203
- const dataTimer = this._dataTimers.get(sessionId);
204
- if (dataTimer) {
205
- clearTimeout(dataTimer);
206
- this._dataTimers.delete(sessionId);
279
+ this._clearTimer(this._dataTimers, sessionId);
280
+ this._clearTimer(this._idleTimers, sessionId);
281
+ }
282
+
283
+ _clearTimer(map, sessionId) {
284
+ const timer = map.get(sessionId);
285
+ if (timer) {
286
+ clearTimeout(timer);
287
+ map.delete(sessionId);
207
288
  }
208
289
  }
209
290
 
210
- _markWorking(s) {
211
- const now = Date.now();
291
+ _markWorking(s, sessionId) {
212
292
  s.working = true;
213
- s.lastWorkSignalAt = now;
293
+ s.workEpisode = true;
294
+ s.pendingAttention = false;
295
+ s.lastWorkSignalAt = Date.now();
296
+ // Re-evaluate as soon as the idle threshold could be met, so the flash
297
+ // doesn't wait for the next periodic check (up to checkInterval later).
298
+ this._clearTimer(this._idleTimers, sessionId);
299
+ this._idleTimers.set(sessionId, setTimeout(() => {
300
+ this._idleTimers.delete(sessionId);
301
+ this._evaluate(sessionId);
302
+ }, this.config.idleThreshold + 100));
214
303
  }
215
304
 
216
305
  // Core evaluation: reads the live viewport and drives the state machine.
@@ -230,40 +319,69 @@ class OpenCodeAttentionPlugin {
230
319
  } else {
231
320
  s.appMissStreak++;
232
321
  if (s.appMissStreak >= this.config.appMissLimit) {
233
- // OpenCode left the screen (user exited to shell, switched apps).
234
- const wasFlashing = this._flashing.get(sessionId);
322
+ // OpenCode is off screen: no NEW working episode may start. An
323
+ // already armed episode is kept on purpose — a dialog can hide
324
+ // every signature, and an agent that exited on its own still
325
+ // deserves its one flash. Anything the user did to leave the app
326
+ // went through onUserInput, which clears the episode.
235
327
  s.appVisible = false;
236
328
  s.working = false;
237
- if (wasFlashing) this._stopFlash(sessionId);
238
329
  }
239
- return;
240
330
  }
241
331
 
242
- // 2) Working indicator in the footer region.
332
+ // 2) Working indicator in the footer region, in two tiers:
333
+ // - a run hint ("esc to interrupt") is unambiguous and counts even
334
+ // on a completely quiet screen;
335
+ // - a bare spinner glyph only counts while output is actually
336
+ // flowing. A spinner that animates always produces output, so a
337
+ // glyph with a quiet stream is a LEFTOVER (the finished status
338
+ // line pushed up by a dialog, a braille graph, a progress bar).
339
+ // Treating those as "still working" is what kept sessions
340
+ // pinned in the working state and swallowed the flash.
243
341
  const footer = viewport.slice(-this.config.footerLines);
244
- const workingVisible = footer.some(line => this._matchesAny(this._workingPatterns, line));
342
+ const hintVisible = footer.some(line => this._matchesAny(this._workingHintPatterns, line));
343
+ const glyphVisible = !hintVisible &&
344
+ footer.some(line => this._matchesAny(this._workingPatterns, line));
345
+ const spinnerLive = (now - s.lastOutputAt) < this.config.spinnerStaleMs;
346
+ // Last resort against a permanently stuck "working" state: a run that
347
+ // is really in progress keeps repainting its elapsed-time counter, so
348
+ // a screen that has produced NOTHING for workStaleMs is showing a
349
+ // leftover, not a live run.
350
+ const outputStale = (now - s.lastOutputAt) > this.config.workStaleMs;
351
+ const workingVisible = s.appVisible && !outputStale &&
352
+ (hintVisible || (glyphVisible && spinnerLive));
245
353
 
246
354
  if (workingVisible) {
247
- this._markWorking(s);
355
+ const wasFlashing = this._flashing.get(sessionId) || s.pendingAttention;
356
+ this._markWorking(s, sessionId);
248
357
  // Working resumed — anything currently flashing is stale.
249
- if (this._flashing.get(sessionId)) {
250
- this._stopFlash(sessionId, { cooldown: true });
251
- }
358
+ if (wasFlashing) this._stopFlash(sessionId, { cooldown: true });
252
359
  return;
253
360
  }
254
361
 
255
362
  // 3) Idle transition: a working episode ended (indicator gone AND no
256
363
  // work signal for idleThreshold) → the agent finished or is waiting
257
364
  // on a dialog → flash.
258
- if (s.working && (now - s.lastWorkSignalAt) >= this.config.idleThreshold) {
365
+ if (s.workEpisode && (now - s.lastWorkSignalAt) >= this.config.idleThreshold) {
366
+ s.workEpisode = false;
259
367
  s.working = false;
368
+ s.pendingAttention = true;
369
+ this._startFlash(sessionId, { force: true });
370
+ return;
371
+ }
372
+
373
+ // 4) A transition that was suppressed (cooldown after a keystroke)
374
+ // stays queued and is retried until it goes out or the user shows up.
375
+ if (s.pendingAttention) {
260
376
  this._startFlash(sessionId);
261
377
  return;
262
378
  }
263
379
 
264
- // 4) Optional custom attention patterns (config-supplied only),
380
+ // 5) Optional custom attention patterns (config-supplied only),
265
381
  // evaluated against the footer while idle.
266
- if (!s.working && this._attentionPatterns.length > 0) {
382
+ if (s.appVisible && !s.working && this._attentionPatterns.length > 0) {
383
+ // Level-triggered (the pattern stays on screen), so the dedupe in
384
+ // _startFlash must apply — no force here.
267
385
  if (footer.some(line => this._matchesAny(this._attentionPatterns, line))) {
268
386
  this._startFlash(sessionId);
269
387
  }
@@ -287,10 +405,9 @@ class OpenCodeAttentionPlugin {
287
405
  // Cheap inline work signal: spinner/indicator glyphs in the stream
288
406
  // keep the working state fresh without waiting for a viewport check.
289
407
  if (s.appVisible && this._matchesAny(this._workingPatterns, data)) {
290
- this._markWorking(s);
291
- if (this._flashing.get(sessionId)) {
292
- this._stopFlash(sessionId, { cooldown: true });
293
- }
408
+ const wasFlashing = this._flashing.get(sessionId) || s.pendingAttention;
409
+ this._markWorking(s, sessionId);
410
+ if (wasFlashing) this._stopFlash(sessionId, { cooldown: true });
294
411
  return;
295
412
  }
296
413
 
@@ -303,10 +420,9 @@ class OpenCodeAttentionPlugin {
303
420
  }
304
421
  s.agentBytes += data.length;
305
422
  if (s.appVisible && s.agentBytes >= this.config.minWorkBytes) {
306
- this._markWorking(s);
307
- if (this._flashing.get(sessionId)) {
308
- this._stopFlash(sessionId, { cooldown: true });
309
- }
423
+ const wasFlashing = this._flashing.get(sessionId) || s.pendingAttention;
424
+ this._markWorking(s, sessionId);
425
+ if (wasFlashing) this._stopFlash(sessionId, { cooldown: true });
310
426
  }
311
427
  }
312
428
 
@@ -318,7 +434,18 @@ class OpenCodeAttentionPlugin {
318
434
  onUserInput(sessionId /*, data */) {
319
435
  const s = this._getSessionState(sessionId);
320
436
  s.lastUserInputAt = Date.now();
321
- // The user is here — stop flashing and hold off for a while.
437
+ // The user is here — stop flashing and hold off for a while. The
438
+ // current episode is dropped as well: if the agent really is working,
439
+ // its next spinner frame re-arms it within milliseconds, and if the
440
+ // keystroke was the user quitting to a shell there is nothing left to
441
+ // announce.
442
+ s.workEpisode = false;
443
+ s.working = false;
444
+ this._stopFlash(sessionId, { cooldown: true });
445
+ }
446
+
447
+ // A client reported the user is looking at this tab.
448
+ onSessionFocus(sessionId) {
322
449
  this._stopFlash(sessionId, { cooldown: true });
323
450
  }
324
451
 
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "opencode-attention",
3
- "version": "2.0.0",
3
+ "version": "2.1.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
  }
@@ -174,6 +174,15 @@ function registerSSHHandlers(socket, io) {
174
174
  }
175
175
  });
176
176
 
177
+ // The user is looking at this session's tab (switched to it, focused the
178
+ // window while it was visible, or a flash was suppressed because the tab
179
+ // was already on screen). Attention plugins use this to clear their
180
+ // "currently flashing" state so the NEXT event can flash again.
181
+ socket.on('tab-seen', (data) => {
182
+ if (!data || typeof data.sessionId !== 'string') return;
183
+ try { pluginManager.onSessionFocus(data.sessionId); } catch (_) {}
184
+ });
185
+
177
186
  // SSH take control
178
187
  socket.on('ssh-take-control', (data) => {
179
188
  console.log(`[SSH] Socket ${socket.id} requesting control of session ${data.sessionId}`);
@@ -10,6 +10,7 @@
10
10
  * - onData(sessionId, data) - Raw terminal output data
11
11
  * - onTerminalLine(sessionId, line) - Individual terminal lines
12
12
  * - onUserInput(sessionId, data) - User keystrokes/input sent to the session
13
+ * - onSessionFocus(sessionId) - A client is looking at this session's tab
13
14
  *
14
15
  * Plugin actions (via context object):
15
16
  * - ctx.flashTab(sessionId, options) - Flash a tab to get attention
@@ -17,7 +18,8 @@
17
18
  * - ctx.emitToSession(sessionId, event, data) - Send WS event to session clients
18
19
  * - ctx.emitToAll(event, data) - Broadcast WS event to all clients
19
20
  * - ctx.writeToSession(sessionId, data) - Write data to SSH session stdin
20
- * - ctx.getTerminalState(sessionId) - Get current terminal state
21
+ * - ctx.getTerminalState(sessionId) - Get current terminal state (full scrollback)
22
+ * - ctx.getTerminalViewport(sessionId) - Get the visible screen only (cheap)
21
23
  * - ctx.getActiveSessions() - Get list of active session IDs
22
24
  * - ctx.getConfig() - Get current server config
23
25
  */
@@ -34,6 +36,7 @@ class PluginManager {
34
36
  onData: [],
35
37
  onTerminalLine: [],
36
38
  onUserInput: [],
39
+ onSessionFocus: [],
37
40
  };
38
41
  this.io = null;
39
42
  this.sshManager = null;
@@ -231,6 +234,13 @@ class PluginManager {
231
234
  return null;
232
235
  },
233
236
 
237
+ getTerminalViewport(sessionId) {
238
+ if (self.sshManager && typeof self.sshManager.getTerminalViewport === 'function') {
239
+ return self.sshManager.getTerminalViewport(sessionId);
240
+ }
241
+ return null;
242
+ },
243
+
234
244
  getActiveSessions() {
235
245
  if (self.sshManager) {
236
246
  return Array.from(self.sshManager.sessions.keys());
@@ -311,6 +321,19 @@ _stripAnsi(str) {
311
321
  this.emit('onUserInput', sessionId, data);
312
322
  }
313
323
 
324
+ // A client reported that the user is actually looking at this session's
325
+ // tab (it got focused, or a flash was suppressed because the tab was
326
+ // already visible). Without this the server keeps believing the tab is
327
+ // still flashing — clients clear the highlight locally — and every later
328
+ // "needs attention" event is swallowed as a duplicate.
329
+ onSessionFocus(sessionId) {
330
+ const wasFlashing = this.flashingSessions.delete(sessionId);
331
+ this.emit('onSessionFocus', sessionId);
332
+ if (wasFlashing && this.io) {
333
+ this.io.emit('tab-flash-stop', { sessionId });
334
+ }
335
+ }
336
+
314
337
  onSessionConnect(sessionId, sessionInfo) {
315
338
  this.emit('onSessionConnect', sessionId, sessionInfo);
316
339
  }
@@ -655,6 +655,37 @@ if (this.io) {
655
655
  }
656
656
  }
657
657
 
658
+ // Get ONLY the visible viewport of a session (no scrollback).
659
+ //
660
+ // getTerminalState() serializes the full 10k-line scrollback, which for a
661
+ // busy session easily exceeds its 1MB guard — it then returns null. That
662
+ // is fine for the client sync path (a one-off manual refresh) but fatal
663
+ // for plugins that poll every couple of seconds to look at the screen:
664
+ // they went blind exactly in the sessions that produce the most output.
665
+ // This serializes the viewport only (~2KB instead of ~200KB), which is
666
+ // also two orders of magnitude cheaper to build.
667
+ getTerminalViewport(sessionId) {
668
+ const session = this.sessions.get(sessionId);
669
+ if (!session || !session.terminal || !session.serializeAddon) {
670
+ return null;
671
+ }
672
+
673
+ try {
674
+ // scrollback: 0 => last `rows` lines of the normal buffer. When the
675
+ // alternate buffer is active (full-screen TUIs) the addon appends it
676
+ // after a `\x1b[?1049h` marker, so the real screen is at the tail.
677
+ const state = session.serializeAddon.serialize({ scrollback: 0, excludeModes: true });
678
+ return {
679
+ state,
680
+ cols: session.cols,
681
+ rows: session.rows
682
+ };
683
+ } catch (err) {
684
+ console.error(`[SSH] Error getting terminal viewport:`, err.message);
685
+ return null;
686
+ }
687
+ }
688
+
658
689
  disconnect(sessionId) {
659
690
  const session = this.sessions.get(sessionId);
660
691
  if (session) {
@@ -24,6 +24,7 @@
24
24
  --accent-success: #3fb950;
25
25
  --accent-warning: #d29922;
26
26
  --accent-danger: #f85149;
27
+ --accent-danger-hover: #ff6b63;
27
28
  --accent-purple: #a371f2;
28
29
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
29
30
  --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.4);
@@ -52,6 +53,11 @@
52
53
  --text-primary: #1f2328;
53
54
  --text-secondary: #656d76;
54
55
  --text-muted: #8c959f;
56
+ /* Darker reds on light backgrounds: the dark-theme #f85149 only reaches
57
+ ~3.2:1 against the white label of .btn-danger (Logout), which is
58
+ unreadable on a light modal. #cf222e / #a40e26 give 4.8:1 / 7.6:1. */
59
+ --accent-danger: #cf222e;
60
+ --accent-danger-hover: #a40e26;
55
61
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.1);
56
62
  --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.15);
57
63
  --shadow-lg: 0 10px 15px rgba(0, 0, 0, 0.2);
@@ -1134,8 +1140,9 @@ body {
1134
1140
  }
1135
1141
 
1136
1142
  .btn-danger:hover {
1137
- background: #ff6b63;
1138
- border-color: #ff6b63;
1143
+ background: var(--accent-danger-hover);
1144
+ border-color: var(--accent-danger-hover);
1145
+ color: #fff;
1139
1146
  }
1140
1147
 
1141
1148
  /* Main Content */
@@ -4906,18 +4913,15 @@ body.dragging-tabs .tabs-container {
4906
4913
  }
4907
4914
 
4908
4915
  .session-close-btn:hover {
4909
- background: var(--danger-color);
4910
- color: white;
4911
- }
4912
-
4913
- .btn-danger {
4914
- background: var(--danger-color);
4915
- color: white;
4916
+ background: var(--accent-danger);
4917
+ color: #fff;
4916
4918
  }
4917
4919
 
4918
- .btn-danger:hover {
4919
- background: #b52628;
4920
- }
4920
+ /* NOTE: .btn-danger is defined once, near the other button styles.
4921
+ A second definition used to live here using an undefined
4922
+ `--danger-color`; that made `background` invalid at computed-value
4923
+ time (→ transparent) while still forcing `color: white`, so the
4924
+ Logout button rendered as white text on the light modal background. */
4921
4925
 
4922
4926
  .btn-secondary {
4923
4927
  background: var(--bg-tertiary);