@lethevimlet/sshift 1.7.1 → 1.7.3
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 +258 -187
- package/plugins/claude-attention/package.json +3 -3
- package/plugins/opencode-attention/index.js +246 -184
- package/plugins/opencode-attention/package.json +3 -3
- package/src/server/endpoints/ws/ssh.js +5 -0
- package/src/server/plugins/plugin-manager.js +9 -0
- package/src/webapp/css/style.css +35 -0
- package/src/webapp/index.html +36 -6
- package/src/webapp/js/app.js +88 -0
package/package.json
CHANGED
|
@@ -1,112 +1,165 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* claude-attention Plugin
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
4
|
+
* Flashes the tab when Claude Code (https://claude.ai/claude-code) finishes
|
|
5
|
+
* working and is waiting for the user (reply complete, or a permission
|
|
6
|
+
* dialog like "Do you want to make this edit?").
|
|
6
7
|
*
|
|
7
|
-
* Detection strategy:
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
8
|
+
* Detection strategy (state-transition based, not text-pattern based):
|
|
9
|
+
*
|
|
10
|
+
* 1. App detection is NON-STICKY: Claude Code is considered present only
|
|
11
|
+
* while one of its UI signatures is visible in the CURRENT viewport of
|
|
12
|
+
* the headless terminal ("Claude", the "? for shortcuts" footer hint,
|
|
13
|
+
* "esc to interrupt", edit-mode hints). When the user exits back to a
|
|
14
|
+
* shell the signatures disappear and, after a few misses, all state
|
|
15
|
+
* resets — so a shell prompt can never flash the tab (the old sticky
|
|
16
|
+
* flag caused exactly that).
|
|
17
|
+
*
|
|
18
|
+
* 2. "Working" is tracked from two signals:
|
|
19
|
+
* - working indicators visible in the viewport footer (braille
|
|
20
|
+
* spinner glyphs, the ✢✳✶✻✽ sparkle spinner frames, and the
|
|
21
|
+
* "esc to interrupt" hint Claude Code shows while running), and
|
|
22
|
+
* - sustained agent-driven output: bytes that arrive while the user
|
|
23
|
+
* has NOT typed recently (echo/UI responses to keystrokes are
|
|
24
|
+
* ignored via userEchoWindowMs).
|
|
25
|
+
* NOTE: "·" is deliberately NOT a spinner char anymore — it appears in
|
|
26
|
+
* every status line ("3.2k tokens · esc to interrupt") and made the
|
|
27
|
+
* old working-detection fire on ordinary output.
|
|
28
|
+
*
|
|
29
|
+
* 3. The tab flashes ONLY on the working → idle TRANSITION: a working
|
|
30
|
+
* episode was observed, the working indicator is gone, and no work
|
|
31
|
+
* signal has been seen for idleThreshold ms. A finished reply and a
|
|
32
|
+
* permission dialog both look like this transition, so no brittle
|
|
33
|
+
* prompt regexes ("❯", "Do you want", "allow", ...) are needed.
|
|
34
|
+
*
|
|
35
|
+
* 4. User input (keystrokes) stops an active flash immediately and
|
|
36
|
+
* suppresses flashing for cooldownMs — the user is already there.
|
|
37
|
+
*
|
|
38
|
+
* There are NO default attention text patterns: strings like "(y/n)",
|
|
39
|
+
* "allow" or "❯ " routinely appear inside chat prose, code and shell
|
|
40
|
+
* prompts and caused constant false flashes. Custom `patterns` from the
|
|
41
|
+
* config are still honored, but they are only evaluated while Claude is on
|
|
42
|
+
* screen and not working.
|
|
16
43
|
*
|
|
17
44
|
* Configuration (in config.json under plugins[].config):
|
|
18
|
-
* -
|
|
19
|
-
* -
|
|
20
|
-
* -
|
|
21
|
-
*
|
|
22
|
-
* -
|
|
23
|
-
*
|
|
24
|
-
* -
|
|
45
|
+
* - flashDuration: number - Flash duration in ms, 0 = flash until focused (default: 0)
|
|
46
|
+
* - checkInterval: number - Milliseconds between periodic viewport checks (default: 2000)
|
|
47
|
+
* - idleThreshold: number - Milliseconds without a work signal before Claude
|
|
48
|
+
* is considered idle/finished (default: 2500)
|
|
49
|
+
* - cooldownMs: number - Milliseconds to suppress flashing after user input
|
|
50
|
+
* or after a flash stops (default: 3000)
|
|
51
|
+
* - debounceMs: number - Debounce for output-driven evaluations (default: 300)
|
|
52
|
+
* - footerLines: number - Viewport bottom lines scanned for working
|
|
53
|
+
* indicators / custom patterns (default: 8)
|
|
54
|
+
* - userEchoWindowMs: number - Output arriving within this window after a
|
|
55
|
+
* keystroke counts as echo, not agent work (default: 1200)
|
|
56
|
+
* - minWorkBytes: number - Agent-driven bytes within workWindowMs that
|
|
57
|
+
* mark the session as working (default: 600)
|
|
58
|
+
* - workWindowMs: number - Rolling window for minWorkBytes (default: 2000)
|
|
59
|
+
* - appMissLimit: number - Consecutive viewport checks without an app
|
|
60
|
+
* signature before state resets (default: 3)
|
|
61
|
+
* - appPatterns: string[] - Regexes replacing the default app signatures
|
|
62
|
+
* - workingPatterns: string[] - Regexes replacing the default working indicators
|
|
63
|
+
* - patterns: string[] - Extra attention regexes (footer lines, idle only)
|
|
64
|
+
* - excludePatterns: string[] - Remove patterns (by source) from all lists
|
|
25
65
|
*/
|
|
26
66
|
|
|
27
67
|
class ClaudeAttentionPlugin {
|
|
28
68
|
constructor(ctx, config = {}) {
|
|
29
69
|
this.ctx = ctx;
|
|
30
70
|
this.config = {
|
|
31
|
-
debounceMs: config.debounceMs || 300,
|
|
32
71
|
flashDuration: config.flashDuration || 0,
|
|
33
72
|
checkInterval: config.checkInterval || 2000,
|
|
34
|
-
idleThreshold: config.idleThreshold ||
|
|
35
|
-
cooldownMs: config.cooldownMs ||
|
|
36
|
-
|
|
73
|
+
idleThreshold: config.idleThreshold || 2500,
|
|
74
|
+
cooldownMs: config.cooldownMs || 3000,
|
|
75
|
+
debounceMs: config.debounceMs || 300,
|
|
76
|
+
footerLines: config.footerLines || 8,
|
|
77
|
+
userEchoWindowMs: config.userEchoWindowMs || 1200,
|
|
78
|
+
minWorkBytes: config.minWorkBytes || 600,
|
|
79
|
+
workWindowMs: config.workWindowMs || 2000,
|
|
80
|
+
appMissLimit: config.appMissLimit || 3,
|
|
37
81
|
};
|
|
38
82
|
|
|
39
|
-
|
|
83
|
+
// App signatures. Claude Code's welcome box scrolls away in long
|
|
84
|
+
// sessions, so alongside the case-SENSITIVE "Claude" wordmark (keeps
|
|
85
|
+
// lowercase shell text like `cd claude-project` from arming the
|
|
86
|
+
// engine) we accept the persistent footer hints. A false positive
|
|
87
|
+
// here only ARMS the engine; a flash still requires a real
|
|
88
|
+
// working → idle transition.
|
|
89
|
+
this._appPatterns = this._compileList(
|
|
90
|
+
config.appPatterns || [
|
|
91
|
+
'Claude',
|
|
92
|
+
'\\? for shortcuts',
|
|
93
|
+
'esc to interrupt',
|
|
94
|
+
'accept edits',
|
|
95
|
+
'plan mode',
|
|
96
|
+
'bypass permissions',
|
|
97
|
+
],
|
|
98
|
+
'appPatterns',
|
|
99
|
+
'' // case-sensitive
|
|
100
|
+
);
|
|
101
|
+
|
|
102
|
+
// Working indicators, scanned over the viewport footer only:
|
|
103
|
+
// - the full braille block (U+2800–U+28FF) covers braille spinners,
|
|
104
|
+
// - ✢✳✶✻✽∗ are Claude Code's sparkle spinner frames,
|
|
105
|
+
// - "esc to interrupt" is shown for the whole duration of a run.
|
|
106
|
+
this._workingPatterns = this._compileList(
|
|
107
|
+
config.workingPatterns || [
|
|
108
|
+
'[\\u2800-\\u28FF]',
|
|
109
|
+
'[✢✳✶✻✽∗]',
|
|
110
|
+
'esc to interrupt',
|
|
111
|
+
],
|
|
112
|
+
'workingPatterns'
|
|
113
|
+
);
|
|
114
|
+
|
|
115
|
+
// Optional user-supplied attention patterns (none by default).
|
|
116
|
+
this._attentionPatterns = this._compileList(config.patterns || [], 'patterns');
|
|
117
|
+
|
|
118
|
+
// excludePatterns removes entries (matched by regex source) from all lists.
|
|
119
|
+
for (const p of (config.excludePatterns || [])) {
|
|
120
|
+
try {
|
|
121
|
+
const source = new RegExp(p).source;
|
|
122
|
+
this._appPatterns = this._appPatterns.filter(r => r.source !== source);
|
|
123
|
+
this._workingPatterns = this._workingPatterns.filter(r => r.source !== source);
|
|
124
|
+
this._attentionPatterns = this._attentionPatterns.filter(r => r.source !== source);
|
|
125
|
+
} catch (e) {
|
|
126
|
+
console.error(`[claude-attention] Invalid exclude pattern "${p}":`, e.message);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
40
129
|
|
|
41
|
-
this.
|
|
130
|
+
this._sessionState = new Map();
|
|
42
131
|
this._checkTimers = new Map();
|
|
132
|
+
this._dataTimers = new Map();
|
|
43
133
|
this._flashing = new Map();
|
|
44
|
-
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
_compileList(list, label, flags = 'i') {
|
|
137
|
+
const out = [];
|
|
138
|
+
for (const p of list) {
|
|
139
|
+
try { out.push(new RegExp(p, flags)); } catch (e) {
|
|
140
|
+
console.error(`[claude-attention] Invalid ${label} regex "${p}":`, e.message);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
return out;
|
|
45
144
|
}
|
|
46
145
|
|
|
47
146
|
_getSessionState(sessionId) {
|
|
48
147
|
if (!this._sessionState.has(sessionId)) {
|
|
49
148
|
this._sessionState.set(sessionId, {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
149
|
+
appVisible: false, // signature currently on screen
|
|
150
|
+
appMissStreak: 0, // consecutive checks without a signature
|
|
151
|
+
working: false, // inside a working episode
|
|
152
|
+
lastWorkSignalAt: 0, // last time any work signal was seen
|
|
153
|
+
lastUserInputAt: 0, // last user keystroke
|
|
154
|
+
lastOutputAt: 0, // last output of any kind
|
|
155
|
+
agentBytes: 0, // agent-driven bytes in the rolling window
|
|
156
|
+
agentWindowStart: 0,
|
|
53
157
|
cooldownUntil: 0,
|
|
54
|
-
idleCheckScheduled: false,
|
|
55
158
|
});
|
|
56
159
|
}
|
|
57
160
|
return this._sessionState.get(sessionId);
|
|
58
161
|
}
|
|
59
162
|
|
|
60
|
-
_isWorking(sessionId) {
|
|
61
|
-
const s = this._getSessionState(sessionId);
|
|
62
|
-
return s.wasWorking && (Date.now() - s.lastSpinnerTime) < this.config.idleThreshold;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
_buildPatterns(extraPatterns, excludePatterns) {
|
|
66
|
-
const defaultPatterns = [
|
|
67
|
-
/\> $/,
|
|
68
|
-
/\> \x1b/,
|
|
69
|
-
/❯ /,
|
|
70
|
-
/waiting for input/i,
|
|
71
|
-
/press enter/i,
|
|
72
|
-
/press any key/i,
|
|
73
|
-
/confirm\s*\?/i,
|
|
74
|
-
/\(y\/n\)/i,
|
|
75
|
-
/\(yes\/no\)/i,
|
|
76
|
-
/\[Y\/n\]/i,
|
|
77
|
-
/\[y\/N\]/i,
|
|
78
|
-
/do you want/i,
|
|
79
|
-
/allow/i,
|
|
80
|
-
/Esc to cancel/i,
|
|
81
|
-
];
|
|
82
|
-
|
|
83
|
-
let patterns = [...defaultPatterns];
|
|
84
|
-
|
|
85
|
-
for (const p of extraPatterns) {
|
|
86
|
-
try { patterns.push(new RegExp(p)); } catch (e) {
|
|
87
|
-
console.error(`[claude-attention] Invalid pattern "${p}":`, e.message);
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
for (const p of excludePatterns) {
|
|
92
|
-
try {
|
|
93
|
-
const regex = new RegExp(p);
|
|
94
|
-
patterns = patterns.filter(pat => pat.source !== regex.source);
|
|
95
|
-
} catch (e) {
|
|
96
|
-
console.error(`[claude-attention] Invalid exclude pattern "${p}":`, e.message);
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
return patterns;
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
_matchesPattern(text) {
|
|
104
|
-
for (const pattern of this.patterns) {
|
|
105
|
-
if (pattern.test(text)) return true;
|
|
106
|
-
}
|
|
107
|
-
return false;
|
|
108
|
-
}
|
|
109
|
-
|
|
110
163
|
_stripAnsi(str) {
|
|
111
164
|
return str
|
|
112
165
|
.replace(/\x1b\[[0-9;]*[a-zA-Z]/g, '')
|
|
@@ -115,149 +168,174 @@ class ClaudeAttentionPlugin {
|
|
|
115
168
|
.replace(/\x1b[\(\)]B/g, '')
|
|
116
169
|
.replace(/\x1b[0-9;]*[a-zA-Z]/g, '')
|
|
117
170
|
.replace(/\x1b[^[\]()?P]/g, '')
|
|
118
|
-
.replace(/[\x00-\x08\x0b\x0c\x0d\x0e-\x1f\x7f]/g, '')
|
|
119
|
-
|
|
171
|
+
.replace(/[\x00-\x08\x0b\x0c\x0d\x0e-\x1f\x7f]/g, '');
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
_matchesAny(patterns, text) {
|
|
175
|
+
for (const p of patterns) {
|
|
176
|
+
if (p.test(text)) return true;
|
|
177
|
+
}
|
|
178
|
+
return false;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
// Extract the current viewport (last `rows` lines) from the serialized
|
|
182
|
+
// terminal state, ANSI-stripped, one entry per screen line.
|
|
183
|
+
_getViewportLines(sessionId) {
|
|
184
|
+
const state = this.ctx.getTerminalState(sessionId);
|
|
185
|
+
if (!state || !state.state) return null;
|
|
186
|
+
const rows = state.rows || 24;
|
|
187
|
+
const lines = state.state.split('\n');
|
|
188
|
+
const viewport = lines.slice(-rows);
|
|
189
|
+
return viewport.map(l => this._stripAnsi(l));
|
|
120
190
|
}
|
|
121
191
|
|
|
122
192
|
_startFlash(sessionId) {
|
|
123
|
-
const
|
|
124
|
-
|
|
125
|
-
if (
|
|
193
|
+
const s = this._getSessionState(sessionId);
|
|
194
|
+
const now = Date.now();
|
|
195
|
+
if (now < s.cooldownUntil) return;
|
|
196
|
+
if (now - s.lastUserInputAt < this.config.userEchoWindowMs) return;
|
|
126
197
|
if (this._flashing.get(sessionId)) return;
|
|
127
198
|
this._flashing.set(sessionId, true);
|
|
128
199
|
this.ctx.flashTab(sessionId, { duration: this.config.flashDuration || 0 });
|
|
129
200
|
}
|
|
130
201
|
|
|
131
|
-
_stopFlash(sessionId) {
|
|
202
|
+
_stopFlash(sessionId, { cooldown = false } = {}) {
|
|
203
|
+
if (cooldown) {
|
|
204
|
+
const s = this._getSessionState(sessionId);
|
|
205
|
+
s.cooldownUntil = Date.now() + this.config.cooldownMs;
|
|
206
|
+
}
|
|
132
207
|
if (!this._flashing.get(sessionId)) return;
|
|
133
208
|
this._flashing.delete(sessionId);
|
|
134
209
|
this.ctx.stopFlashTab(sessionId);
|
|
135
210
|
}
|
|
136
211
|
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
const
|
|
212
|
+
_resetSession(sessionId) {
|
|
213
|
+
this._stopFlash(sessionId);
|
|
214
|
+
this._sessionState.delete(sessionId);
|
|
215
|
+
const dataTimer = this._dataTimers.get(sessionId);
|
|
216
|
+
if (dataTimer) {
|
|
217
|
+
clearTimeout(dataTimer);
|
|
141
218
|
this._dataTimers.delete(sessionId);
|
|
142
|
-
|
|
143
|
-
}, this.config.debounceMs);
|
|
144
|
-
|
|
145
|
-
this._dataTimers.set(sessionId, timer);
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
_scheduleIdleCheck(sessionId) {
|
|
149
|
-
const sessionState = this._getSessionState(sessionId);
|
|
150
|
-
if (sessionState.idleCheckScheduled) return;
|
|
151
|
-
sessionState.idleCheckScheduled = true;
|
|
152
|
-
|
|
153
|
-
const delay = this.config.idleThreshold + 200;
|
|
154
|
-
|
|
155
|
-
setTimeout(() => {
|
|
156
|
-
sessionState.idleCheckScheduled = false;
|
|
157
|
-
if (!sessionState.wasWorking) return;
|
|
158
|
-
if (this._isWorking(sessionId)) return;
|
|
159
|
-
this._checkAttention(sessionId);
|
|
160
|
-
}, delay);
|
|
219
|
+
}
|
|
161
220
|
}
|
|
162
221
|
|
|
163
|
-
|
|
164
|
-
|
|
222
|
+
_markWorking(s) {
|
|
223
|
+
const now = Date.now();
|
|
224
|
+
s.working = true;
|
|
225
|
+
s.lastWorkSignalAt = now;
|
|
165
226
|
}
|
|
166
227
|
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
if (!state || !state.state) return;
|
|
228
|
+
// Core evaluation: reads the live viewport and drives the state machine.
|
|
229
|
+
_evaluate(sessionId) {
|
|
230
|
+
const viewport = this._getViewportLines(sessionId);
|
|
231
|
+
if (!viewport) return;
|
|
172
232
|
|
|
173
|
-
const
|
|
174
|
-
const
|
|
175
|
-
|
|
176
|
-
let foundClaude = false;
|
|
177
|
-
let matchedPrompt = false;
|
|
178
|
-
|
|
179
|
-
for (const line of recentLines) {
|
|
180
|
-
const stripped = this._stripAnsi(line);
|
|
181
|
-
if (!stripped) continue;
|
|
182
|
-
|
|
183
|
-
if (/Claude/i.test(stripped)) {
|
|
184
|
-
foundClaude = true;
|
|
185
|
-
}
|
|
233
|
+
const s = this._getSessionState(sessionId);
|
|
234
|
+
const now = Date.now();
|
|
186
235
|
|
|
187
|
-
|
|
188
|
-
|
|
236
|
+
// 1) App presence (non-sticky, with a small miss streak so a single
|
|
237
|
+
// mid-redraw check can't reset state).
|
|
238
|
+
const appOnScreen = viewport.some(line => this._matchesAny(this._appPatterns, line));
|
|
239
|
+
if (appOnScreen) {
|
|
240
|
+
s.appVisible = true;
|
|
241
|
+
s.appMissStreak = 0;
|
|
242
|
+
} else {
|
|
243
|
+
s.appMissStreak++;
|
|
244
|
+
if (s.appMissStreak >= this.config.appMissLimit) {
|
|
245
|
+
// Claude left the screen (user exited to shell, switched apps).
|
|
246
|
+
const wasFlashing = this._flashing.get(sessionId);
|
|
247
|
+
s.appVisible = false;
|
|
248
|
+
s.working = false;
|
|
249
|
+
if (wasFlashing) this._stopFlash(sessionId);
|
|
189
250
|
}
|
|
251
|
+
return;
|
|
190
252
|
}
|
|
191
253
|
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
}
|
|
254
|
+
// 2) Working indicator in the footer region.
|
|
255
|
+
const footer = viewport.slice(-this.config.footerLines);
|
|
256
|
+
const workingVisible = footer.some(line => this._matchesAny(this._workingPatterns, line));
|
|
196
257
|
|
|
197
|
-
if (
|
|
258
|
+
if (workingVisible) {
|
|
259
|
+
this._markWorking(s);
|
|
260
|
+
// Working resumed — anything currently flashing is stale.
|
|
261
|
+
if (this._flashing.get(sessionId)) {
|
|
262
|
+
this._stopFlash(sessionId, { cooldown: true });
|
|
263
|
+
}
|
|
264
|
+
return;
|
|
265
|
+
}
|
|
198
266
|
|
|
199
|
-
|
|
267
|
+
// 3) Idle transition: a working episode ended (indicator gone AND no
|
|
268
|
+
// work signal for idleThreshold) → the reply finished or a
|
|
269
|
+
// permission dialog is waiting → flash.
|
|
270
|
+
if (s.working && (now - s.lastWorkSignalAt) >= this.config.idleThreshold) {
|
|
271
|
+
s.working = false;
|
|
200
272
|
this._startFlash(sessionId);
|
|
201
273
|
return;
|
|
202
274
|
}
|
|
203
275
|
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
276
|
+
// 4) Optional custom attention patterns (config-supplied only),
|
|
277
|
+
// evaluated against the footer while idle.
|
|
278
|
+
if (!s.working && this._attentionPatterns.length > 0) {
|
|
279
|
+
if (footer.some(line => this._matchesAny(this._attentionPatterns, line))) {
|
|
280
|
+
this._startFlash(sessionId);
|
|
281
|
+
}
|
|
210
282
|
}
|
|
211
283
|
}
|
|
212
284
|
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
const
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
285
|
+
_scheduleEvaluate(sessionId) {
|
|
286
|
+
if (this._dataTimers.has(sessionId)) return;
|
|
287
|
+
const timer = setTimeout(() => {
|
|
288
|
+
this._dataTimers.delete(sessionId);
|
|
289
|
+
this._evaluate(sessionId);
|
|
290
|
+
}, this.config.debounceMs);
|
|
291
|
+
this._dataTimers.set(sessionId, timer);
|
|
292
|
+
}
|
|
220
293
|
|
|
221
|
-
|
|
294
|
+
onData(sessionId, data) {
|
|
295
|
+
const s = this._getSessionState(sessionId);
|
|
296
|
+
const now = Date.now();
|
|
297
|
+
s.lastOutputAt = now;
|
|
222
298
|
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
this.
|
|
299
|
+
// Cheap inline work signal: spinner/indicator glyphs in the stream
|
|
300
|
+
// keep the working state fresh without waiting for a viewport check.
|
|
301
|
+
if (s.appVisible && this._matchesAny(this._workingPatterns, data)) {
|
|
302
|
+
this._markWorking(s);
|
|
227
303
|
if (this._flashing.get(sessionId)) {
|
|
228
|
-
this._stopFlash(sessionId);
|
|
229
|
-
sessionState.cooldownUntil = Date.now() + this.config.cooldownMs;
|
|
304
|
+
this._stopFlash(sessionId, { cooldown: true });
|
|
230
305
|
}
|
|
231
306
|
return;
|
|
232
307
|
}
|
|
233
308
|
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
sessionState.isClaude = true;
|
|
309
|
+
// Agent-driven output heuristic: bytes arriving while the user hasn't
|
|
310
|
+
// typed recently. Echo/UI reactions to keystrokes don't count.
|
|
311
|
+
if (now - s.lastUserInputAt > this.config.userEchoWindowMs) {
|
|
312
|
+
if (now - s.agentWindowStart > this.config.workWindowMs) {
|
|
313
|
+
s.agentWindowStart = now;
|
|
314
|
+
s.agentBytes = 0;
|
|
315
|
+
}
|
|
316
|
+
s.agentBytes += data.length;
|
|
317
|
+
if (s.appVisible && s.agentBytes >= this.config.minWorkBytes) {
|
|
318
|
+
this._markWorking(s);
|
|
319
|
+
if (this._flashing.get(sessionId)) {
|
|
320
|
+
this._stopFlash(sessionId, { cooldown: true });
|
|
321
|
+
}
|
|
322
|
+
}
|
|
249
323
|
}
|
|
250
324
|
|
|
251
|
-
|
|
252
|
-
|
|
325
|
+
// Debounced evaluation so a burst that ends (stream complete, dialog
|
|
326
|
+
// shown) is noticed quickly instead of waiting for the next interval.
|
|
327
|
+
this._scheduleEvaluate(sessionId);
|
|
328
|
+
}
|
|
253
329
|
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
330
|
+
onUserInput(sessionId /*, data */) {
|
|
331
|
+
const s = this._getSessionState(sessionId);
|
|
332
|
+
s.lastUserInputAt = Date.now();
|
|
333
|
+
// The user is here — stop flashing and hold off for a while.
|
|
334
|
+
this._stopFlash(sessionId, { cooldown: true });
|
|
257
335
|
}
|
|
258
336
|
|
|
259
337
|
onSessionConnect(sessionId) {
|
|
260
|
-
this.
|
|
338
|
+
this._resetSession(sessionId);
|
|
261
339
|
this._flashing.delete(sessionId);
|
|
262
340
|
|
|
263
341
|
const existingTimer = this._checkTimers.get(sessionId);
|
|
@@ -269,28 +347,21 @@ class ClaudeAttentionPlugin {
|
|
|
269
347
|
this._checkTimers.delete(sessionId);
|
|
270
348
|
return;
|
|
271
349
|
}
|
|
272
|
-
this.
|
|
350
|
+
this._evaluate(sessionId);
|
|
273
351
|
}, this.config.checkInterval);
|
|
274
352
|
|
|
275
353
|
this._checkTimers.set(sessionId, timer);
|
|
276
354
|
}
|
|
277
355
|
|
|
278
356
|
onSessionDisconnect(sessionId) {
|
|
279
|
-
this.
|
|
280
|
-
this._sessionState.delete(sessionId);
|
|
357
|
+
this._resetSession(sessionId);
|
|
281
358
|
|
|
282
359
|
const checkTimer = this._checkTimers.get(sessionId);
|
|
283
360
|
if (checkTimer) {
|
|
284
361
|
clearInterval(checkTimer);
|
|
285
362
|
this._checkTimers.delete(sessionId);
|
|
286
363
|
}
|
|
287
|
-
|
|
288
|
-
const dataTimer = this._dataTimers.get(sessionId);
|
|
289
|
-
if (dataTimer) {
|
|
290
|
-
clearTimeout(dataTimer);
|
|
291
|
-
this._dataTimers.delete(sessionId);
|
|
292
|
-
}
|
|
293
364
|
}
|
|
294
365
|
}
|
|
295
366
|
|
|
296
|
-
module.exports = ClaudeAttentionPlugin;
|
|
367
|
+
module.exports = ClaudeAttentionPlugin;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "claude-attention",
|
|
3
|
-
"version": "
|
|
4
|
-
"description": "Flashes SSH tabs when Claude is waiting for
|
|
3
|
+
"version": "2.0.0",
|
|
4
|
+
"description": "Flashes SSH tabs when Claude Code finishes working and is waiting for you (state-transition detection, no brittle prompt patterns)",
|
|
5
5
|
"type": "sshift-plugin"
|
|
6
|
-
}
|
|
6
|
+
}
|