@lethevimlet/sshift 1.7.3 → 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 +181 -50
- package/plugins/claude-attention/package.json +1 -1
- package/plugins/opencode-attention/index.js +191 -64
- package/plugins/opencode-attention/package.json +1 -1
- package/src/server/endpoints/ws/ssh.js +9 -0
- package/src/server/plugins/plugin-manager.js +24 -1
- package/src/server/services/ssh-manager.js +31 -0
- package/src/webapp/css/style.css +16 -12
- package/src/webapp/js/app.js +36 -0
package/package.json
CHANGED
|
@@ -10,10 +10,10 @@
|
|
|
10
10
|
* 1. App detection is NON-STICKY: Claude Code is considered present only
|
|
11
11
|
* while one of its UI signatures is visible in the CURRENT viewport of
|
|
12
12
|
* the headless terminal ("Claude", the "? for shortcuts" footer hint,
|
|
13
|
-
* "esc to interrupt", edit-mode hints).
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
13
|
+
* "esc to interrupt", the ⎿ tool-result marker, edit-mode hints...).
|
|
14
|
+
* When the user exits back to a shell the signatures disappear and,
|
|
15
|
+
* after a few misses, no NEW working episode can start — so a shell
|
|
16
|
+
* prompt can never arm the engine.
|
|
17
17
|
*
|
|
18
18
|
* 2. "Working" is tracked from two signals:
|
|
19
19
|
* - working indicators visible in the viewport footer (braille
|
|
@@ -22,9 +22,8 @@
|
|
|
22
22
|
* - sustained agent-driven output: bytes that arrive while the user
|
|
23
23
|
* has NOT typed recently (echo/UI responses to keystrokes are
|
|
24
24
|
* ignored via userEchoWindowMs).
|
|
25
|
-
* NOTE: "·" is deliberately NOT a spinner char
|
|
26
|
-
*
|
|
27
|
-
* old working-detection fire on ordinary output.
|
|
25
|
+
* NOTE: "·" is deliberately NOT a spinner char — it appears in every
|
|
26
|
+
* status line ("3.2k tokens · esc to interrupt").
|
|
28
27
|
*
|
|
29
28
|
* 3. The tab flashes ONLY on the working → idle TRANSITION: a working
|
|
30
29
|
* episode was observed, the working indicator is gone, and no work
|
|
@@ -32,8 +31,29 @@
|
|
|
32
31
|
* permission dialog both look like this transition, so no brittle
|
|
33
32
|
* prompt regexes ("❯", "Do you want", "allow", ...) are needed.
|
|
34
33
|
*
|
|
35
|
-
* 4. User input (keystrokes)
|
|
36
|
-
* suppresses flashing for cooldownMs — the user is
|
|
34
|
+
* 4. User input (keystrokes) ends the current working episode, stops an
|
|
35
|
+
* active flash and suppresses flashing for cooldownMs — the user is
|
|
36
|
+
* already there. A genuinely running agent re-arms the episode with
|
|
37
|
+
* its very next spinner frame, so nothing is lost.
|
|
38
|
+
*
|
|
39
|
+
* Things that made v1.7.3 miss most "waiting for input" events, and how
|
|
40
|
+
* they are handled now:
|
|
41
|
+
*
|
|
42
|
+
* - The viewport was read through getTerminalState(), which serializes
|
|
43
|
+
* the whole 10k-line scrollback and returns NULL past its 1MB guard.
|
|
44
|
+
* Busy agent sessions — exactly the ones worth watching — went blind.
|
|
45
|
+
* Now it reads getTerminalViewport() (visible screen only) and follows
|
|
46
|
+
* the alternate-screen marker when a full-screen TUI is active.
|
|
47
|
+
* - A transition that landed inside the post-keystroke cooldown was
|
|
48
|
+
* dropped and never retried. The engine now keeps a pendingAttention
|
|
49
|
+
* flag and retries on every check until the flash actually goes out.
|
|
50
|
+
* - Losing the app signature (a permission dialog can cover the footer
|
|
51
|
+
* hints) wiped the pending episode. App misses now only stop NEW
|
|
52
|
+
* episodes from starting; an armed one still gets to flash.
|
|
53
|
+
* - A flash the user dismissed by simply looking at the tab left the
|
|
54
|
+
* server stuck in "already flashing", swallowing every later event.
|
|
55
|
+
* Clients now report onSessionFocus, and a fresh transition re-emits
|
|
56
|
+
* the flash anyway.
|
|
37
57
|
*
|
|
38
58
|
* There are NO default attention text patterns: strings like "(y/n)",
|
|
39
59
|
* "allow" or "❯ " routinely appear inside chat prose, code and shell
|
|
@@ -57,9 +77,15 @@
|
|
|
57
77
|
* mark the session as working (default: 600)
|
|
58
78
|
* - workWindowMs: number - Rolling window for minWorkBytes (default: 2000)
|
|
59
79
|
* - appMissLimit: number - Consecutive viewport checks without an app
|
|
60
|
-
* signature before
|
|
80
|
+
* signature before new episodes are blocked (default: 3)
|
|
61
81
|
* - appPatterns: string[] - Regexes replacing the default app signatures
|
|
82
|
+
* - spinnerStaleMs: number - A bare spinner glyph only counts as "working" if
|
|
83
|
+
* output arrived within this window (default: 2000)
|
|
84
|
+
* - workStaleMs: number - A screen with no output at all for this long is
|
|
85
|
+
* never considered working (default: 60000)
|
|
62
86
|
* - workingPatterns: string[] - Regexes replacing the default working indicators
|
|
87
|
+
* - workingHintPatterns: string[] - Regexes for run hints that count as working
|
|
88
|
+
* even on a quiet screen (default: "esc to interrupt")
|
|
63
89
|
* - patterns: string[] - Extra attention regexes (footer lines, idle only)
|
|
64
90
|
* - excludePatterns: string[] - Remove patterns (by source) from all lists
|
|
65
91
|
*/
|
|
@@ -78,22 +104,34 @@ class ClaudeAttentionPlugin {
|
|
|
78
104
|
minWorkBytes: config.minWorkBytes || 600,
|
|
79
105
|
workWindowMs: config.workWindowMs || 2000,
|
|
80
106
|
appMissLimit: config.appMissLimit || 3,
|
|
107
|
+
spinnerStaleMs: config.spinnerStaleMs || 2000,
|
|
108
|
+
workStaleMs: config.workStaleMs || 60000,
|
|
81
109
|
};
|
|
82
110
|
|
|
83
111
|
// App signatures. Claude Code's welcome box scrolls away in long
|
|
84
112
|
// sessions, so alongside the case-SENSITIVE "Claude" wordmark (keeps
|
|
85
113
|
// lowercase shell text like `cd claude-project` from arming the
|
|
86
|
-
// engine) we accept the
|
|
87
|
-
//
|
|
88
|
-
//
|
|
114
|
+
// engine) we accept the markers that survive on screen: the footer
|
|
115
|
+
// hints, the mode indicators, the ⎿ tool-result glyph and the
|
|
116
|
+
// permission-dialog headline/choices (a dialog can push every other
|
|
117
|
+
// hint off the viewport, which is precisely when we must flash).
|
|
118
|
+
// A false positive here only ARMS the engine; a flash still requires
|
|
119
|
+
// a real working → idle transition.
|
|
89
120
|
this._appPatterns = this._compileList(
|
|
90
121
|
config.appPatterns || [
|
|
91
122
|
'Claude',
|
|
92
123
|
'\\? for shortcuts',
|
|
93
124
|
'esc to interrupt',
|
|
125
|
+
'esc to cancel',
|
|
94
126
|
'accept edits',
|
|
95
127
|
'plan mode',
|
|
96
128
|
'bypass permissions',
|
|
129
|
+
'shift\\+tab to cycle',
|
|
130
|
+
'auto-compact',
|
|
131
|
+
'⎿',
|
|
132
|
+
'⏵⏵',
|
|
133
|
+
'Do you want',
|
|
134
|
+
'❯ \\d+\\.',
|
|
97
135
|
],
|
|
98
136
|
'appPatterns',
|
|
99
137
|
'' // case-sensitive
|
|
@@ -102,16 +140,28 @@ class ClaudeAttentionPlugin {
|
|
|
102
140
|
// Working indicators, scanned over the viewport footer only:
|
|
103
141
|
// - the full braille block (U+2800–U+28FF) covers braille spinners,
|
|
104
142
|
// - ✢✳✶✻✽∗ are Claude Code's sparkle spinner frames,
|
|
143
|
+
// - ◐◓◑◒◜◝◞◟ cover the arc/circle spinners used by some tools,
|
|
105
144
|
// - "esc to interrupt" is shown for the whole duration of a run.
|
|
106
145
|
this._workingPatterns = this._compileList(
|
|
107
146
|
config.workingPatterns || [
|
|
108
147
|
'[\\u2800-\\u28FF]',
|
|
109
148
|
'[✢✳✶✻✽∗]',
|
|
149
|
+
'[◐◓◑◒◜◝◞◟]',
|
|
110
150
|
'esc to interrupt',
|
|
111
151
|
],
|
|
112
152
|
'workingPatterns'
|
|
113
153
|
);
|
|
114
154
|
|
|
155
|
+
// Text hints that stay on screen for the WHOLE run ("esc to
|
|
156
|
+
// interrupt"). Unlike a spinner glyph these are unambiguous, so they
|
|
157
|
+
// count as "working" even when the screen is completely quiet.
|
|
158
|
+
this._workingHintPatterns = this._compileList(
|
|
159
|
+
config.workingHintPatterns || [
|
|
160
|
+
'esc to interrupt',
|
|
161
|
+
],
|
|
162
|
+
'workingHintPatterns'
|
|
163
|
+
);
|
|
164
|
+
|
|
115
165
|
// Optional user-supplied attention patterns (none by default).
|
|
116
166
|
this._attentionPatterns = this._compileList(config.patterns || [], 'patterns');
|
|
117
167
|
|
|
@@ -121,6 +171,7 @@ class ClaudeAttentionPlugin {
|
|
|
121
171
|
const source = new RegExp(p).source;
|
|
122
172
|
this._appPatterns = this._appPatterns.filter(r => r.source !== source);
|
|
123
173
|
this._workingPatterns = this._workingPatterns.filter(r => r.source !== source);
|
|
174
|
+
this._workingHintPatterns = this._workingHintPatterns.filter(r => r.source !== source);
|
|
124
175
|
this._attentionPatterns = this._attentionPatterns.filter(r => r.source !== source);
|
|
125
176
|
} catch (e) {
|
|
126
177
|
console.error(`[claude-attention] Invalid exclude pattern "${p}":`, e.message);
|
|
@@ -130,6 +181,7 @@ class ClaudeAttentionPlugin {
|
|
|
130
181
|
this._sessionState = new Map();
|
|
131
182
|
this._checkTimers = new Map();
|
|
132
183
|
this._dataTimers = new Map();
|
|
184
|
+
this._idleTimers = new Map();
|
|
133
185
|
this._flashing = new Map();
|
|
134
186
|
}
|
|
135
187
|
|
|
@@ -148,7 +200,9 @@ class ClaudeAttentionPlugin {
|
|
|
148
200
|
this._sessionState.set(sessionId, {
|
|
149
201
|
appVisible: false, // signature currently on screen
|
|
150
202
|
appMissStreak: 0, // consecutive checks without a signature
|
|
151
|
-
working: false, //
|
|
203
|
+
working: false, // working indicator seen recently
|
|
204
|
+
workEpisode: false, // a working episode is armed (not yet consumed)
|
|
205
|
+
pendingAttention: false, // wants to flash, hasn't managed to yet
|
|
152
206
|
lastWorkSignalAt: 0, // last time any work signal was seen
|
|
153
207
|
lastUserInputAt: 0, // last user keystroke
|
|
154
208
|
lastOutputAt: 0, // last output of any kind
|
|
@@ -178,32 +232,58 @@ class ClaudeAttentionPlugin {
|
|
|
178
232
|
return false;
|
|
179
233
|
}
|
|
180
234
|
|
|
181
|
-
// Extract the current viewport
|
|
182
|
-
//
|
|
235
|
+
// Extract the current viewport, ANSI-stripped, one entry per screen line.
|
|
236
|
+
//
|
|
237
|
+
// Prefers the cheap viewport-only serialization; getTerminalState() is a
|
|
238
|
+
// fallback for older hosts (it serializes the entire scrollback and
|
|
239
|
+
// returns null once that exceeds its size guard).
|
|
183
240
|
_getViewportLines(sessionId) {
|
|
184
|
-
|
|
241
|
+
let state = null;
|
|
242
|
+
if (typeof this.ctx.getTerminalViewport === 'function') {
|
|
243
|
+
state = this.ctx.getTerminalViewport(sessionId);
|
|
244
|
+
}
|
|
245
|
+
if (!state || !state.state) {
|
|
246
|
+
state = this.ctx.getTerminalState(sessionId);
|
|
247
|
+
}
|
|
185
248
|
if (!state || !state.state) return null;
|
|
249
|
+
|
|
186
250
|
const rows = state.rows || 24;
|
|
187
|
-
|
|
251
|
+
let text = state.state;
|
|
252
|
+
|
|
253
|
+
// Full-screen TUIs run on the alternate buffer, which the serializer
|
|
254
|
+
// appends after a `\x1b[?1049h` marker — everything before it is the
|
|
255
|
+
// scrolled-away normal buffer, not what the user is looking at.
|
|
256
|
+
const altMarker = text.lastIndexOf('\x1b[?1049h');
|
|
257
|
+
if (altMarker !== -1) {
|
|
258
|
+
text = text.slice(altMarker);
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
const lines = text.split('\n');
|
|
188
262
|
const viewport = lines.slice(-rows);
|
|
189
263
|
return viewport.map(l => this._stripAnsi(l));
|
|
190
264
|
}
|
|
191
265
|
|
|
192
|
-
_startFlash(sessionId) {
|
|
266
|
+
_startFlash(sessionId, { force = false } = {}) {
|
|
193
267
|
const s = this._getSessionState(sessionId);
|
|
194
268
|
const now = Date.now();
|
|
269
|
+
// Suppressed for now — pendingAttention keeps it queued for a retry
|
|
270
|
+
// instead of dropping the event on the floor.
|
|
195
271
|
if (now < s.cooldownUntil) return;
|
|
196
272
|
if (now - s.lastUserInputAt < this.config.userEchoWindowMs) return;
|
|
197
|
-
|
|
273
|
+
// `force` is used for a fresh transition: re-emitting is harmless and
|
|
274
|
+
// recovers from a flash the client cleared without telling us.
|
|
275
|
+
if (!force && this._flashing.get(sessionId)) return;
|
|
198
276
|
this._flashing.set(sessionId, true);
|
|
277
|
+
s.pendingAttention = false;
|
|
199
278
|
this.ctx.flashTab(sessionId, { duration: this.config.flashDuration || 0 });
|
|
200
279
|
}
|
|
201
280
|
|
|
202
281
|
_stopFlash(sessionId, { cooldown = false } = {}) {
|
|
282
|
+
const s = this._getSessionState(sessionId);
|
|
203
283
|
if (cooldown) {
|
|
204
|
-
const s = this._getSessionState(sessionId);
|
|
205
284
|
s.cooldownUntil = Date.now() + this.config.cooldownMs;
|
|
206
285
|
}
|
|
286
|
+
s.pendingAttention = false;
|
|
207
287
|
if (!this._flashing.get(sessionId)) return;
|
|
208
288
|
this._flashing.delete(sessionId);
|
|
209
289
|
this.ctx.stopFlashTab(sessionId);
|
|
@@ -212,17 +292,30 @@ class ClaudeAttentionPlugin {
|
|
|
212
292
|
_resetSession(sessionId) {
|
|
213
293
|
this._stopFlash(sessionId);
|
|
214
294
|
this._sessionState.delete(sessionId);
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
295
|
+
this._clearTimer(this._dataTimers, sessionId);
|
|
296
|
+
this._clearTimer(this._idleTimers, sessionId);
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
_clearTimer(map, sessionId) {
|
|
300
|
+
const timer = map.get(sessionId);
|
|
301
|
+
if (timer) {
|
|
302
|
+
clearTimeout(timer);
|
|
303
|
+
map.delete(sessionId);
|
|
219
304
|
}
|
|
220
305
|
}
|
|
221
306
|
|
|
222
|
-
_markWorking(s) {
|
|
223
|
-
const now = Date.now();
|
|
307
|
+
_markWorking(s, sessionId) {
|
|
224
308
|
s.working = true;
|
|
225
|
-
s.
|
|
309
|
+
s.workEpisode = true;
|
|
310
|
+
s.pendingAttention = false;
|
|
311
|
+
s.lastWorkSignalAt = Date.now();
|
|
312
|
+
// Re-evaluate as soon as the idle threshold could be met, so the flash
|
|
313
|
+
// doesn't wait for the next periodic check (up to checkInterval later).
|
|
314
|
+
this._clearTimer(this._idleTimers, sessionId);
|
|
315
|
+
this._idleTimers.set(sessionId, setTimeout(() => {
|
|
316
|
+
this._idleTimers.delete(sessionId);
|
|
317
|
+
this._evaluate(sessionId);
|
|
318
|
+
}, this.config.idleThreshold + 100));
|
|
226
319
|
}
|
|
227
320
|
|
|
228
321
|
// Core evaluation: reads the live viewport and drives the state machine.
|
|
@@ -242,40 +335,69 @@ class ClaudeAttentionPlugin {
|
|
|
242
335
|
} else {
|
|
243
336
|
s.appMissStreak++;
|
|
244
337
|
if (s.appMissStreak >= this.config.appMissLimit) {
|
|
245
|
-
// Claude
|
|
246
|
-
|
|
338
|
+
// Claude is off screen: no NEW working episode may start. An
|
|
339
|
+
// already armed episode is kept on purpose — a permission dialog
|
|
340
|
+
// can hide every signature, and an agent that exited on its own
|
|
341
|
+
// still deserves its one flash. Anything the user did to leave
|
|
342
|
+
// the app went through onUserInput, which clears the episode.
|
|
247
343
|
s.appVisible = false;
|
|
248
344
|
s.working = false;
|
|
249
|
-
if (wasFlashing) this._stopFlash(sessionId);
|
|
250
345
|
}
|
|
251
|
-
return;
|
|
252
346
|
}
|
|
253
347
|
|
|
254
|
-
// 2) Working indicator in the footer region
|
|
348
|
+
// 2) Working indicator in the footer region, in two tiers:
|
|
349
|
+
// - a run hint ("esc to interrupt") is unambiguous and counts even
|
|
350
|
+
// on a completely quiet screen;
|
|
351
|
+
// - a bare spinner glyph only counts while output is actually
|
|
352
|
+
// flowing. A spinner that animates always produces output, so a
|
|
353
|
+
// glyph with a quiet stream is a LEFTOVER (the finished status
|
|
354
|
+
// line pushed up by a dialog, a braille graph, a progress bar).
|
|
355
|
+
// Treating those as "still working" is what kept sessions
|
|
356
|
+
// pinned in the working state and swallowed the flash.
|
|
255
357
|
const footer = viewport.slice(-this.config.footerLines);
|
|
256
|
-
const
|
|
358
|
+
const hintVisible = footer.some(line => this._matchesAny(this._workingHintPatterns, line));
|
|
359
|
+
const glyphVisible = !hintVisible &&
|
|
360
|
+
footer.some(line => this._matchesAny(this._workingPatterns, line));
|
|
361
|
+
const spinnerLive = (now - s.lastOutputAt) < this.config.spinnerStaleMs;
|
|
362
|
+
// Last resort against a permanently stuck "working" state: a run that
|
|
363
|
+
// is really in progress keeps repainting its elapsed-time counter, so
|
|
364
|
+
// a screen that has produced NOTHING for workStaleMs is showing a
|
|
365
|
+
// leftover, not a live run.
|
|
366
|
+
const outputStale = (now - s.lastOutputAt) > this.config.workStaleMs;
|
|
367
|
+
const workingVisible = s.appVisible && !outputStale &&
|
|
368
|
+
(hintVisible || (glyphVisible && spinnerLive));
|
|
257
369
|
|
|
258
370
|
if (workingVisible) {
|
|
259
|
-
this.
|
|
371
|
+
const wasFlashing = this._flashing.get(sessionId) || s.pendingAttention;
|
|
372
|
+
this._markWorking(s, sessionId);
|
|
260
373
|
// Working resumed — anything currently flashing is stale.
|
|
261
|
-
if (this.
|
|
262
|
-
this._stopFlash(sessionId, { cooldown: true });
|
|
263
|
-
}
|
|
374
|
+
if (wasFlashing) this._stopFlash(sessionId, { cooldown: true });
|
|
264
375
|
return;
|
|
265
376
|
}
|
|
266
377
|
|
|
267
378
|
// 3) Idle transition: a working episode ended (indicator gone AND no
|
|
268
379
|
// work signal for idleThreshold) → the reply finished or a
|
|
269
380
|
// permission dialog is waiting → flash.
|
|
270
|
-
if (s.
|
|
381
|
+
if (s.workEpisode && (now - s.lastWorkSignalAt) >= this.config.idleThreshold) {
|
|
382
|
+
s.workEpisode = false;
|
|
271
383
|
s.working = false;
|
|
384
|
+
s.pendingAttention = true;
|
|
385
|
+
this._startFlash(sessionId, { force: true });
|
|
386
|
+
return;
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
// 4) A transition that was suppressed (cooldown after a keystroke)
|
|
390
|
+
// stays queued and is retried until it goes out or the user shows up.
|
|
391
|
+
if (s.pendingAttention) {
|
|
272
392
|
this._startFlash(sessionId);
|
|
273
393
|
return;
|
|
274
394
|
}
|
|
275
395
|
|
|
276
|
-
//
|
|
396
|
+
// 5) Optional custom attention patterns (config-supplied only),
|
|
277
397
|
// evaluated against the footer while idle.
|
|
278
|
-
if (!s.working && this._attentionPatterns.length > 0) {
|
|
398
|
+
if (s.appVisible && !s.working && this._attentionPatterns.length > 0) {
|
|
399
|
+
// Level-triggered (the pattern stays on screen), so the dedupe in
|
|
400
|
+
// _startFlash must apply — no force here.
|
|
279
401
|
if (footer.some(line => this._matchesAny(this._attentionPatterns, line))) {
|
|
280
402
|
this._startFlash(sessionId);
|
|
281
403
|
}
|
|
@@ -299,10 +421,9 @@ class ClaudeAttentionPlugin {
|
|
|
299
421
|
// Cheap inline work signal: spinner/indicator glyphs in the stream
|
|
300
422
|
// keep the working state fresh without waiting for a viewport check.
|
|
301
423
|
if (s.appVisible && this._matchesAny(this._workingPatterns, data)) {
|
|
302
|
-
this.
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
}
|
|
424
|
+
const wasFlashing = this._flashing.get(sessionId) || s.pendingAttention;
|
|
425
|
+
this._markWorking(s, sessionId);
|
|
426
|
+
if (wasFlashing) this._stopFlash(sessionId, { cooldown: true });
|
|
306
427
|
return;
|
|
307
428
|
}
|
|
308
429
|
|
|
@@ -315,10 +436,9 @@ class ClaudeAttentionPlugin {
|
|
|
315
436
|
}
|
|
316
437
|
s.agentBytes += data.length;
|
|
317
438
|
if (s.appVisible && s.agentBytes >= this.config.minWorkBytes) {
|
|
318
|
-
this.
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
}
|
|
439
|
+
const wasFlashing = this._flashing.get(sessionId) || s.pendingAttention;
|
|
440
|
+
this._markWorking(s, sessionId);
|
|
441
|
+
if (wasFlashing) this._stopFlash(sessionId, { cooldown: true });
|
|
322
442
|
}
|
|
323
443
|
}
|
|
324
444
|
|
|
@@ -330,7 +450,18 @@ class ClaudeAttentionPlugin {
|
|
|
330
450
|
onUserInput(sessionId /*, data */) {
|
|
331
451
|
const s = this._getSessionState(sessionId);
|
|
332
452
|
s.lastUserInputAt = Date.now();
|
|
333
|
-
// The user is here — stop flashing and hold off for a while.
|
|
453
|
+
// The user is here — stop flashing and hold off for a while. The
|
|
454
|
+
// current episode is dropped as well: if the agent really is working,
|
|
455
|
+
// its next spinner frame re-arms it within milliseconds, and if the
|
|
456
|
+
// keystroke was the user quitting to a shell there is nothing left to
|
|
457
|
+
// announce.
|
|
458
|
+
s.workEpisode = false;
|
|
459
|
+
s.working = false;
|
|
460
|
+
this._stopFlash(sessionId, { cooldown: true });
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
// A client reported the user is looking at this tab.
|
|
464
|
+
onSessionFocus(sessionId) {
|
|
334
465
|
this._stopFlash(sessionId, { cooldown: true });
|
|
335
466
|
}
|
|
336
467
|
|
|
@@ -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/
|
|
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
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
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,
|
|
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
|
-
*
|
|
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)
|
|
30
|
-
* suppresses flashing for cooldownMs — the user is
|
|
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
|
-
*
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
*
|
|
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
|
|
54
|
-
* signature before
|
|
55
|
-
* - appPatterns: string[] - Regexes replacing the default app
|
|
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
|
|
78
|
-
// bar "OpenCode x.y.z", splash logo)
|
|
79
|
-
// lowercase shell text (`cd
|
|
80
|
-
//
|
|
81
|
-
//
|
|
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 || [
|
|
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
|
|
139
|
-
working: false, //
|
|
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
|
|
170
|
-
//
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
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.
|
|
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
|
|
234
|
-
|
|
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
|
|
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.
|
|
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.
|
|
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.
|
|
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
|
-
//
|
|
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.
|
|
291
|
-
|
|
292
|
-
|
|
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.
|
|
307
|
-
|
|
308
|
-
|
|
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
|
|
|
@@ -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) {
|
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') {
|
|
@@ -10175,6 +10183,10 @@ if (keepaliveCountMaxInput && this.sshKeepaliveCountMax) {
|
|
|
10175
10183
|
if (wrapper && wrapper.classList.contains('active') &&
|
|
10176
10184
|
document.hasFocus() && !document.hidden) {
|
|
10177
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);
|
|
10178
10190
|
return;
|
|
10179
10191
|
}
|
|
10180
10192
|
|
|
@@ -10209,6 +10221,29 @@ if (keepaliveCountMaxInput && this.sshKeepaliveCountMax) {
|
|
|
10209
10221
|
this._flashApplyTimer = setTimeout(() => this.applyFlashStates(), 150);
|
|
10210
10222
|
}
|
|
10211
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
|
+
|
|
10212
10247
|
stopTabFlash(sessionId) {
|
|
10213
10248
|
const flashingSessions = this._flashingSessions;
|
|
10214
10249
|
if (flashingSessions) {
|
|
@@ -10275,6 +10310,7 @@ if (keepaliveCountMaxInput && this.sshKeepaliveCountMax) {
|
|
|
10275
10310
|
|
|
10276
10311
|
// Stop any active flash on this tab since user is viewing it
|
|
10277
10312
|
this.stopTabFlash(sessionId);
|
|
10313
|
+
this.notifyTabSeen(sessionId);
|
|
10278
10314
|
|
|
10279
10315
|
// Determine which panel this session belongs to
|
|
10280
10316
|
if (!panelId) {
|