@lethevimlet/sshift 1.7.2 → 1.7.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.
- package/package.json +1 -1
- package/plugins/claude-attention/index.js +389 -187
- package/plugins/claude-attention/package.json +3 -3
- package/plugins/opencode-attention/index.js +373 -184
- package/plugins/opencode-attention/package.json +3 -3
- package/src/server/endpoints/ws/ssh.js +14 -0
- package/src/server/plugins/plugin-manager.js +33 -1
- package/src/server/services/ssh-manager.js +31 -0
- package/src/webapp/css/style.css +16 -12
- package/src/webapp/js/app.js +47 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "opencode-attention",
|
|
3
|
-
"version": "1.0
|
|
4
|
-
"description": "Flashes SSH tabs when
|
|
3
|
+
"version": "2.1.0",
|
|
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
|
+
}
|
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
const { loadConfig, getStickySetting, getScrollback } = require('../../utils/config');
|
|
6
6
|
const { addTab, getTab, addSocketToTab, removeSocketFromTab, removeTab, getTabOrder, setCloseTimer, clearCloseTimer, getCloseTimer } = require('../../utils/tab-manager');
|
|
7
7
|
const { sshManager } = require('../../services');
|
|
8
|
+
const pluginManager = require('../../plugins/plugin-manager');
|
|
8
9
|
|
|
9
10
|
// Per-session rate limiting for ssh-request-sync. A non-controller could
|
|
10
11
|
// otherwise trigger a 1MB serialization + base64 + emit on every
|
|
@@ -159,6 +160,10 @@ function registerSSHHandlers(socket, io) {
|
|
|
159
160
|
}
|
|
160
161
|
try {
|
|
161
162
|
sshManager.write(data.sessionId, data.data);
|
|
163
|
+
// Notify plugins that the user is actively typing in this session
|
|
164
|
+
// (attention plugins use this to stop flashing / suppress false
|
|
165
|
+
// "needs attention" transitions while the user is present).
|
|
166
|
+
try { pluginManager.onUserInput(data.sessionId, data.data); } catch (_) {}
|
|
162
167
|
} catch (err) {
|
|
163
168
|
console.error(`[SSH] ssh-data: write failed for ${data.sessionId}:`, err.message);
|
|
164
169
|
socket.emit('ssh-error', {
|
|
@@ -169,6 +174,15 @@ function registerSSHHandlers(socket, io) {
|
|
|
169
174
|
}
|
|
170
175
|
});
|
|
171
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
|
+
|
|
172
186
|
// SSH take control
|
|
173
187
|
socket.on('ssh-take-control', (data) => {
|
|
174
188
|
console.log(`[SSH] Socket ${socket.id} requesting control of session ${data.sessionId}`);
|
|
@@ -9,6 +9,8 @@
|
|
|
9
9
|
* - onSessionDisconnect(sessionId) - SSH session closed
|
|
10
10
|
* - onData(sessionId, data) - Raw terminal output data
|
|
11
11
|
* - onTerminalLine(sessionId, line) - Individual terminal lines
|
|
12
|
+
* - onUserInput(sessionId, data) - User keystrokes/input sent to the session
|
|
13
|
+
* - onSessionFocus(sessionId) - A client is looking at this session's tab
|
|
12
14
|
*
|
|
13
15
|
* Plugin actions (via context object):
|
|
14
16
|
* - ctx.flashTab(sessionId, options) - Flash a tab to get attention
|
|
@@ -16,7 +18,8 @@
|
|
|
16
18
|
* - ctx.emitToSession(sessionId, event, data) - Send WS event to session clients
|
|
17
19
|
* - ctx.emitToAll(event, data) - Broadcast WS event to all clients
|
|
18
20
|
* - ctx.writeToSession(sessionId, data) - Write data to SSH session stdin
|
|
19
|
-
* - 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)
|
|
20
23
|
* - ctx.getActiveSessions() - Get list of active session IDs
|
|
21
24
|
* - ctx.getConfig() - Get current server config
|
|
22
25
|
*/
|
|
@@ -32,6 +35,8 @@ class PluginManager {
|
|
|
32
35
|
onSessionDisconnect: [],
|
|
33
36
|
onData: [],
|
|
34
37
|
onTerminalLine: [],
|
|
38
|
+
onUserInput: [],
|
|
39
|
+
onSessionFocus: [],
|
|
35
40
|
};
|
|
36
41
|
this.io = null;
|
|
37
42
|
this.sshManager = null;
|
|
@@ -229,6 +234,13 @@ class PluginManager {
|
|
|
229
234
|
return null;
|
|
230
235
|
},
|
|
231
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
|
+
|
|
232
244
|
getActiveSessions() {
|
|
233
245
|
if (self.sshManager) {
|
|
234
246
|
return Array.from(self.sshManager.sessions.keys());
|
|
@@ -302,6 +314,26 @@ _stripAnsi(str) {
|
|
|
302
314
|
this._processLineBuffer(sessionId, data);
|
|
303
315
|
}
|
|
304
316
|
|
|
317
|
+
// User keystrokes / input written to the session (via ssh-manager.write).
|
|
318
|
+
// Lets attention-style plugins know the user is actively present so they
|
|
319
|
+
// can stop flashing and suppress false "needs attention" transitions.
|
|
320
|
+
onUserInput(sessionId, data) {
|
|
321
|
+
this.emit('onUserInput', sessionId, data);
|
|
322
|
+
}
|
|
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
|
+
|
|
305
337
|
onSessionConnect(sessionId, sessionInfo) {
|
|
306
338
|
this.emit('onSessionConnect', sessionId, sessionInfo);
|
|
307
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) {
|
package/src/webapp/css/style.css
CHANGED
|
@@ -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:
|
|
1138
|
-
border-color:
|
|
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
|
|
4910
|
-
color:
|
|
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
|
|
4919
|
-
|
|
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);
|
package/src/webapp/js/app.js
CHANGED
|
@@ -4428,12 +4428,20 @@ const wheelHandler = (e) => {
|
|
|
4428
4428
|
console.log('[SSHIFT] Tab visible and socket disconnected, triggering reconnect');
|
|
4429
4429
|
this.socket.connect();
|
|
4430
4430
|
}
|
|
4431
|
+
this.clearFlashesForVisibleSessions();
|
|
4431
4432
|
this._refreshAllWebGLSessions();
|
|
4432
4433
|
// Refit visible terminals after tab becomes visible — the container
|
|
4433
4434
|
// may have had zero dimensions while hidden (Bugs 1 & 2).
|
|
4434
4435
|
requestAnimationFrame(() => this.handleResize());
|
|
4435
4436
|
});
|
|
4436
4437
|
|
|
4438
|
+
// A window can stay "visible" while unfocused (second monitor, desktop
|
|
4439
|
+
// app behind another window), so focus is its own signal that the user
|
|
4440
|
+
// has now seen whatever tab is on screen.
|
|
4441
|
+
window.addEventListener('focus', () => {
|
|
4442
|
+
this.clearFlashesForVisibleSessions();
|
|
4443
|
+
});
|
|
4444
|
+
|
|
4437
4445
|
this.socket.on('connect_error', (error) => {
|
|
4438
4446
|
console.error('[SSHIFT] Connection error:', error);
|
|
4439
4447
|
if (error.message === 'Authentication required') {
|
|
@@ -10167,6 +10175,21 @@ if (keepaliveCountMaxInput && this.sshKeepaliveCountMax) {
|
|
|
10167
10175
|
// Tab Management
|
|
10168
10176
|
|
|
10169
10177
|
startTabFlash(sessionId, options = {}) {
|
|
10178
|
+
// Don't flash a terminal the user is already looking at: its wrapper is
|
|
10179
|
+
// visible (active in some panel) AND this browser window is focused and
|
|
10180
|
+
// visible. Each client decides locally, so a background device still
|
|
10181
|
+
// flashes while the one you're staring at stays quiet.
|
|
10182
|
+
const wrapper = document.getElementById(`terminal-wrapper-${sessionId}`);
|
|
10183
|
+
if (wrapper && wrapper.classList.contains('active') &&
|
|
10184
|
+
document.hasFocus() && !document.hidden) {
|
|
10185
|
+
console.log('[SSHIFT] Suppressing tab flash for visible+focused session:', sessionId);
|
|
10186
|
+
// Tell the server the flash was seen, otherwise it keeps this session
|
|
10187
|
+
// marked as "flashing" forever and swallows every later attention
|
|
10188
|
+
// event as a duplicate.
|
|
10189
|
+
this.notifyTabSeen(sessionId);
|
|
10190
|
+
return;
|
|
10191
|
+
}
|
|
10192
|
+
|
|
10170
10193
|
const flashingSessions = this._flashingSessions || (this._flashingSessions = new Set());
|
|
10171
10194
|
flashingSessions.add(sessionId);
|
|
10172
10195
|
|
|
@@ -10198,6 +10221,29 @@ if (keepaliveCountMaxInput && this.sshKeepaliveCountMax) {
|
|
|
10198
10221
|
this._flashApplyTimer = setTimeout(() => this.applyFlashStates(), 150);
|
|
10199
10222
|
}
|
|
10200
10223
|
|
|
10224
|
+
// Coming back to the window: any flashing tab that is actually on screen
|
|
10225
|
+
// has now been seen — clear it here and on the server.
|
|
10226
|
+
clearFlashesForVisibleSessions() {
|
|
10227
|
+
const flashingSessions = this._flashingSessions;
|
|
10228
|
+
if (!flashingSessions || flashingSessions.size === 0) return;
|
|
10229
|
+
if (document.hidden) return;
|
|
10230
|
+
for (const sessionId of Array.from(flashingSessions)) {
|
|
10231
|
+
const wrapper = document.getElementById(`terminal-wrapper-${sessionId}`);
|
|
10232
|
+
if (wrapper && wrapper.classList.contains('active')) {
|
|
10233
|
+
this.stopTabFlash(sessionId);
|
|
10234
|
+
this.notifyTabSeen(sessionId);
|
|
10235
|
+
}
|
|
10236
|
+
}
|
|
10237
|
+
}
|
|
10238
|
+
|
|
10239
|
+
// Let the server (and its attention plugins) know the user has seen this
|
|
10240
|
+
// tab. Clearing a flash only in the browser leaves the server-side plugin
|
|
10241
|
+
// stuck in "already flashing" state.
|
|
10242
|
+
notifyTabSeen(sessionId) {
|
|
10243
|
+
if (!sessionId || !this.socket || !this.socket.connected) return;
|
|
10244
|
+
this.socket.emit('tab-seen', { sessionId });
|
|
10245
|
+
}
|
|
10246
|
+
|
|
10201
10247
|
stopTabFlash(sessionId) {
|
|
10202
10248
|
const flashingSessions = this._flashingSessions;
|
|
10203
10249
|
if (flashingSessions) {
|
|
@@ -10264,6 +10310,7 @@ if (keepaliveCountMaxInput && this.sshKeepaliveCountMax) {
|
|
|
10264
10310
|
|
|
10265
10311
|
// Stop any active flash on this tab since user is viewing it
|
|
10266
10312
|
this.stopTabFlash(sessionId);
|
|
10313
|
+
this.notifyTabSeen(sessionId);
|
|
10267
10314
|
|
|
10268
10315
|
// Determine which panel this session belongs to
|
|
10269
10316
|
if (!panelId) {
|