@lethevimlet/sshift 0.6.0 β†’ 0.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,11 +1,11 @@
1
- # SSHIFT - Web-based SSH & SFTP Terminal Client
1
+ # SSHIFT - Web-based SSH/SFTP Terminal Client for the AI Stack
2
2
 
3
3
  [![Documentation](https://img.shields.io/badge/docs-GitHub%20Pages-blue.svg)](https://lethevimlet.github.io/sshift/)
4
4
  [![npm version](https://img.shields.io/npm/v/@lethevimlet/sshift.svg)](https://www.npmjs.com/package/@lethevimlet/sshift)
5
5
  [![Docker](https://img.shields.io/badge/Docker-ghcr.io/lethevimlet/sshift-blue.svg)](https://github.com/lethevimlet/sshift/pkgs/container/sshift)
6
6
  [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
7
7
 
8
- A modern, responsive web-based SSH and SFTP terminal client built with Node.js, Express, and xterm.js. Features excellent TUI support, tabbed sessions, bookmarks, and mobile-friendly design.
8
+ A modern, responsive web-based SSH and SFTP terminal client built with Node.js, Express, and xterm.js. Designed for the AI coding workflow β€” featuring tab flash notifications that alert you when AI tools like OpenCode or Claude are waiting for your input, so you never miss a prompt while multitasking. Also features excellent TUI support, tabbed sessions, bookmarks, and mobile-friendly design.
9
9
 
10
10
  ![SSHIFT Logo](media/logo.jpg)
11
11
 
@@ -20,6 +20,7 @@ A modern, responsive web-based SSH and SFTP terminal client built with Node.js,
20
20
 
21
21
  - πŸ” **SSH Terminal** - Full xterm.js emulation with TUI support (vim, nano, htop, tmux)
22
22
  - πŸ“ **SFTP Browser** - File manager interface with upload/download
23
+ - πŸ€– **AI Attention Alerts** - Tab flash notifications when AI tools (OpenCode, Claude) need your input
23
24
  - πŸ—‚οΈ **Tabbed Interface** - Multiple concurrent sessions
24
25
  - πŸ”– **Bookmarks** - Save connection details for quick access
25
26
  - πŸ”’ **Password Protection** - Optional password lock for app access
@@ -45,6 +46,7 @@ Full documentation is available at [GitHub Pages](https://lethevimlet.github.io/
45
46
  - **[Installation](docs/installation.md)** - Detailed installation options
46
47
  - **[Docker](docs/docker.md)** - Docker deployment and usage
47
48
  - **[Configuration](docs/configuration.md)** - Configuration files and options
49
+ - **[Plugins](docs/configuration.md#plugins)** - AI attention alerts and plugin system
48
50
  - **[API Reference](docs/api-reference.md)** - Socket.IO events and API
49
51
  - **[Testing](docs/testing.md)** - Running and writing tests
50
52
  - **[Contributing](docs/contributing.md)** - How to contribute
@@ -116,6 +118,74 @@ SSHIFT uses a priority-based configuration system:
116
118
 
117
119
  See [Configuration](docs/configuration.md) for details.
118
120
 
121
+ ## πŸ”’ HTTPS on Local Network (PWA / "Not Secure" Warnings)
122
+
123
+ When accessing sshift from a LAN IP (e.g., `https://192.168.1.50:8022`), browsers show "Not Secure" warnings because the self-signed certificate is untrusted. This also blocks PWA installation.
124
+
125
+ ### Quick Fix: Chrome Flag
126
+
127
+ 1. Go to `chrome://flags/#unsafely-treat-insecure-origin-as-secure`
128
+ 2. Enter your LAN URL: `https://192.168.1.50:8022`
129
+ 3. Set to **Enabled** β†’ **Relaunch**
130
+
131
+ ### Permanent: Custom Trusted Certificate
132
+
133
+ Generate a cert for your LAN IP and configure sshift to use it:
134
+
135
+ ```json
136
+ {
137
+ "enableHttps": true,
138
+ "certPath": "/path/to/sshift-lan-cert.pem",
139
+ "keyPath": "/path/to/sshift-lan-key.pem"
140
+ }
141
+ ```
142
+
143
+ Then add the certificate to your device's trusted root store. See [Configuration > HTTPS on Local Network](docs/configuration.md) for full instructions including nginx reverse proxy and mDNS options.
144
+
145
+ ## πŸ€– AI Attention Plugins
146
+
147
+ SSHIFT includes built-in plugins that detect when AI coding tools are waiting for user input and flash the browser tab to get your attention β€” perfect for when you're multitasking across tabs.
148
+
149
+ ### OpenCode Attention
150
+
151
+ Detects when [OpenCode](https://opencode.ai) is waiting for input by tracking its spinner characters (⬝ β–  β–£) and prompt patterns. When the spinner stops or a prompt appears, the tab flashes.
152
+
153
+ ### Claude Attention
154
+
155
+ Detects when [Claude Code](https://claude.ai) is waiting for input by tracking its spinner characters (β ‹β ™β Ή braille patterns, ·✒✳✢✻✽) and prompt patterns like "❯", "Do you want", "Allow", and "Esc to cancel".
156
+
157
+ ### Enabling Plugins
158
+
159
+ Add plugins to your `config.json`:
160
+
161
+ ```json
162
+ {
163
+ "plugins": [
164
+ {
165
+ "name": "opencode-attention",
166
+ "enabled": true,
167
+ "config": {
168
+ "debounceMs": 300,
169
+ "flashDuration": 0,
170
+ "idleThreshold": 3000
171
+ }
172
+ },
173
+ {
174
+ "name": "claude-attention",
175
+ "enabled": true,
176
+ "config": {
177
+ "debounceMs": 300,
178
+ "flashDuration": 0,
179
+ "idleThreshold": 3000,
180
+ "cooldownMs": 1000
181
+ }
182
+ }
183
+ ]
184
+ }
185
+ ```
186
+
187
+ See [Configuration > Plugins](docs/configuration.md#plugins) for full details.
188
+
119
189
  ## πŸ› οΈ Technology Stack
120
190
 
121
191
  **Backend:** Node.js, Express, Socket.IO, ssh2
@@ -3,10 +3,30 @@
3
3
  "devPort": 3000,
4
4
  "bind": "0.0.0.0",
5
5
  "enableHttps": true,
6
+ "certPath": null,
7
+ "keyPath": null,
6
8
  "sticky": true,
7
9
  "sshKeepaliveInterval": 15000,
8
10
  "sshKeepaliveCountMax": 500,
9
11
  "passwordHash": null,
12
+ "plugins": [
13
+ {
14
+ "name": "opencode-attention",
15
+ "enabled": true,
16
+ "config": {
17
+ "debounceMs": 300,
18
+ "flashDuration": 0
19
+ }
20
+ },
21
+ {
22
+ "name": "claude-attention",
23
+ "enabled": true,
24
+ "config": {
25
+ "debounceMs": 300,
26
+ "flashDuration": 0
27
+ }
28
+ }
29
+ ],
10
30
  "bookmarks": [
11
31
  {
12
32
  "id": "example1",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lethevimlet/sshift",
3
- "version": "0.6.0",
3
+ "version": "0.9.0",
4
4
  "description": "Web-based SSH + SFTP terminal client with tabs and bookmarks",
5
5
  "main": "src/server/index.js",
6
6
  "bin": {
@@ -61,6 +61,7 @@
61
61
  "sshift",
62
62
  "src/server/",
63
63
  "src/webapp/",
64
+ "plugins/",
64
65
  "example.config.json",
65
66
  "README.md",
66
67
  "LICENSE"
@@ -0,0 +1,296 @@
1
+ /**
2
+ * claude-attention Plugin
3
+ *
4
+ * Detects when Claude (https://claude.ai/claude-code) is waiting for user input
5
+ * in an SSH terminal and flashes the tab to alert the user.
6
+ *
7
+ * Detection strategy:
8
+ * - Detects Claude's TUI by looking for "Claude" in the terminal state (sticky: once detected, stays true)
9
+ * - Tracks Claude's processing state via spinner characters (⠋⠙⠹⠸⠼⠴⠦⠧⠇⠏⠽⠛ ·✒✳✢✻✽)
10
+ * - While Claude is working (spinner seen within idleThreshold), ALL flashing is suppressed
11
+ * - When Claude goes idle (no spinner for > idleThreshold ms after working), flashes the tab
12
+ * - Schedules an immediate attention check when spinner stops (no delay waiting for timer)
13
+ * - Detects Claude-specific prompt patterns ("❯", "Do you want", "Allow", "Esc to cancel")
14
+ * - Prompt detection only activates in confirmed Claude sessions (isClaude gate)
15
+ * - Suppresses re-flash for a cooldown period after spinner stops a flash
16
+ *
17
+ * Configuration (in config.json under plugins[].config):
18
+ * - patterns: string[] - Additional regex patterns to detect attention
19
+ * - debounceMs: number - Milliseconds between full-state checks (default: 300)
20
+ * - flashDuration: number - Flash duration in ms, 0 = flash until focused (default: 0)
21
+ * - excludePatterns: string[] - Regex patterns to exclude from detection
22
+ * - checkInterval: number - Milliseconds between periodic terminal state checks (default: 2000)
23
+ * - idleThreshold: number - Milliseconds without spinner before considered idle (default: 3000)
24
+ * - cooldownMs: number - Milliseconds to suppress re-flash after spinner stops a flash (default: 1000)
25
+ */
26
+
27
+ class ClaudeAttentionPlugin {
28
+ constructor(ctx, config = {}) {
29
+ this.ctx = ctx;
30
+ this.config = {
31
+ debounceMs: config.debounceMs || 300,
32
+ flashDuration: config.flashDuration || 0,
33
+ checkInterval: config.checkInterval || 2000,
34
+ idleThreshold: config.idleThreshold || 3000,
35
+ cooldownMs: config.cooldownMs || 1000,
36
+ ...config,
37
+ };
38
+
39
+ this.patterns = this._buildPatterns(config.patterns || [], config.excludePatterns || []);
40
+
41
+ this._dataTimers = new Map();
42
+ this._checkTimers = new Map();
43
+ this._flashing = new Map();
44
+ this._sessionState = new Map();
45
+ }
46
+
47
+ _getSessionState(sessionId) {
48
+ if (!this._sessionState.has(sessionId)) {
49
+ this._sessionState.set(sessionId, {
50
+ isClaude: false,
51
+ lastSpinnerTime: 0,
52
+ wasWorking: false,
53
+ cooldownUntil: 0,
54
+ idleCheckScheduled: false,
55
+ });
56
+ }
57
+ return this._sessionState.get(sessionId);
58
+ }
59
+
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
+ _stripAnsi(str) {
111
+ return str
112
+ .replace(/\x1b\[[0-9;]*[a-zA-Z]/g, '')
113
+ .replace(/\x1b\][^\x07]*\x07/g, '')
114
+ .replace(/\x1b\[\?[0-9]+[hl]/g, '')
115
+ .replace(/\x1b[\(\)]B/g, '')
116
+ .replace(/\x1b[0-9;]*[a-zA-Z]/g, '')
117
+ .replace(/\x1b[^[\]()?P]/g, '')
118
+ .replace(/[\x00-\x08\x0b\x0c\x0d\x0e-\x1f\x7f]/g, '')
119
+ .trim();
120
+ }
121
+
122
+ _startFlash(sessionId) {
123
+ const sessionState = this._getSessionState(sessionId);
124
+ if (Date.now() < sessionState.cooldownUntil) return;
125
+ if (this._isWorking(sessionId)) return;
126
+ if (this._flashing.get(sessionId)) return;
127
+ this._flashing.set(sessionId, true);
128
+ this.ctx.flashTab(sessionId, { duration: this.config.flashDuration || 0 });
129
+ }
130
+
131
+ _stopFlash(sessionId) {
132
+ if (!this._flashing.get(sessionId)) return;
133
+ this._flashing.delete(sessionId);
134
+ this.ctx.stopFlashTab(sessionId);
135
+ }
136
+
137
+ _scheduleCheck(sessionId) {
138
+ if (this._dataTimers.has(sessionId)) return;
139
+
140
+ const timer = setTimeout(() => {
141
+ this._dataTimers.delete(sessionId);
142
+ this._checkAttention(sessionId);
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);
161
+ }
162
+
163
+ _isSpinnerChar(text) {
164
+ return /[β ‹β ™β Ήβ Έβ Όβ ΄β ¦β §β ‡β β ½β ›Β·βœ’βœ³βœΆβœ»βœ½]/.test(text);
165
+ }
166
+
167
+ _checkAttention(sessionId) {
168
+ if (this._isWorking(sessionId)) return;
169
+
170
+ const state = this.ctx.getTerminalState(sessionId);
171
+ if (!state || !state.state) return;
172
+
173
+ const lines = state.state.split('\n');
174
+ const recentLines = lines.slice(-30);
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
+ }
186
+
187
+ if (this._matchesPattern(stripped) || this._matchesPattern(line)) {
188
+ matchedPrompt = true;
189
+ }
190
+ }
191
+
192
+ const sessionState = this._getSessionState(sessionId);
193
+ if (foundClaude) {
194
+ sessionState.isClaude = true;
195
+ }
196
+
197
+ if (!sessionState.isClaude) return;
198
+
199
+ if (matchedPrompt) {
200
+ this._startFlash(sessionId);
201
+ return;
202
+ }
203
+
204
+ const now = Date.now();
205
+ const timeSinceSpinner = now - sessionState.lastSpinnerTime;
206
+
207
+ if (sessionState.wasWorking && timeSinceSpinner > this.config.idleThreshold) {
208
+ this._startFlash(sessionId);
209
+ sessionState.wasWorking = false;
210
+ }
211
+ }
212
+
213
+ onData(sessionId, data) {
214
+ const stripped = this._stripAnsi(data);
215
+ const sessionState = this._getSessionState(sessionId);
216
+
217
+ if (/Claude/i.test(stripped) || /Claude/i.test(data)) {
218
+ sessionState.isClaude = true;
219
+ }
220
+
221
+ const isSpinner = this._isSpinnerChar(stripped) || this._isSpinnerChar(data);
222
+
223
+ if (isSpinner) {
224
+ sessionState.lastSpinnerTime = Date.now();
225
+ sessionState.wasWorking = true;
226
+ this._scheduleIdleCheck(sessionId);
227
+ if (this._flashing.get(sessionId)) {
228
+ this._stopFlash(sessionId);
229
+ sessionState.cooldownUntil = Date.now() + this.config.cooldownMs;
230
+ }
231
+ return;
232
+ }
233
+
234
+ if (!sessionState.isClaude) return;
235
+ if (this._isWorking(sessionId)) return;
236
+
237
+ if (this._matchesPattern(stripped) || this._matchesPattern(data)) {
238
+ this._startFlash(sessionId);
239
+ } else {
240
+ this._scheduleCheck(sessionId);
241
+ }
242
+ }
243
+
244
+ onTerminalLine(sessionId, strippedLine, rawLine) {
245
+ const sessionState = this._getSessionState(sessionId);
246
+
247
+ if (/Claude/i.test(strippedLine)) {
248
+ sessionState.isClaude = true;
249
+ }
250
+
251
+ if (!sessionState.isClaude) return;
252
+ if (this._isWorking(sessionId)) return;
253
+
254
+ if (this._matchesPattern(strippedLine) || this._matchesPattern(rawLine)) {
255
+ this._startFlash(sessionId);
256
+ }
257
+ }
258
+
259
+ onSessionConnect(sessionId) {
260
+ this._sessionState.delete(sessionId);
261
+ this._flashing.delete(sessionId);
262
+
263
+ const existingTimer = this._checkTimers.get(sessionId);
264
+ if (existingTimer) clearInterval(existingTimer);
265
+
266
+ const timer = setInterval(() => {
267
+ if (!this.ctx.getActiveSessions().includes(sessionId)) {
268
+ clearInterval(timer);
269
+ this._checkTimers.delete(sessionId);
270
+ return;
271
+ }
272
+ this._checkAttention(sessionId);
273
+ }, this.config.checkInterval);
274
+
275
+ this._checkTimers.set(sessionId, timer);
276
+ }
277
+
278
+ onSessionDisconnect(sessionId) {
279
+ this._stopFlash(sessionId);
280
+ this._sessionState.delete(sessionId);
281
+
282
+ const checkTimer = this._checkTimers.get(sessionId);
283
+ if (checkTimer) {
284
+ clearInterval(checkTimer);
285
+ this._checkTimers.delete(sessionId);
286
+ }
287
+
288
+ const dataTimer = this._dataTimers.get(sessionId);
289
+ if (dataTimer) {
290
+ clearTimeout(dataTimer);
291
+ this._dataTimers.delete(sessionId);
292
+ }
293
+ }
294
+ }
295
+
296
+ module.exports = ClaudeAttentionPlugin;
@@ -0,0 +1,6 @@
1
+ {
2
+ "name": "claude-attention",
3
+ "version": "1.0.0",
4
+ "description": "Flashes SSH tabs when Claude is waiting for user input",
5
+ "type": "sshift-plugin"
6
+ }
@@ -0,0 +1,248 @@
1
+ /**
2
+ * opencode-attention Plugin
3
+ *
4
+ * Detects when opencode (https://opencode.ai) is waiting for user input
5
+ * in an SSH terminal and flashes the tab to alert the user.
6
+ *
7
+ * Detection strategy:
8
+ * - Detects opencode's TUI by looking for "OpenCode" in the terminal state
9
+ * - Tracks opencode's processing state via spinner characters (⬝ β–  β–£)
10
+ * - When opencode was working (spinner active) but goes idle for > idleThreshold ms,
11
+ * flashes the tab to alert the user that opencode is waiting for input
12
+ * - Also detects common prompt patterns like "> ", "❯ ", "(y/n)" etc.
13
+ * - Stops flashing when spinner activity resumes (opencode is busy again)
14
+ *
15
+ * Configuration (in config.json under plugins[].config):
16
+ * - patterns: string[] - Additional regex patterns to detect attention
17
+ * - debounceMs: number - Milliseconds between full-state checks (default: 300)
18
+ * - flashDuration: number - Flash duration in ms, 0 = flash until focused (default: 0)
19
+ * - excludePatterns: string[] - Regex patterns to exclude from detection
20
+ * - checkInterval: number - Milliseconds between periodic terminal state checks (default: 2000)
21
+ * - idleThreshold: number - Milliseconds without spinner before considered idle (default: 3000)
22
+ */
23
+
24
+ class OpenCodeAttentionPlugin {
25
+ constructor(ctx, config = {}) {
26
+ this.ctx = ctx;
27
+ this.config = {
28
+ debounceMs: config.debounceMs || 300,
29
+ flashDuration: config.flashDuration || 0,
30
+ checkInterval: config.checkInterval || 2000,
31
+ idleThreshold: config.idleThreshold || 3000,
32
+ ...config,
33
+ };
34
+
35
+ this.patterns = this._buildPatterns(config.patterns || [], config.excludePatterns || []);
36
+
37
+ this._dataTimers = new Map();
38
+ this._checkTimers = new Map();
39
+ this._flashing = new Map();
40
+ this._sessionState = new Map();
41
+ }
42
+
43
+ _getSessionState(sessionId) {
44
+ if (!this._sessionState.has(sessionId)) {
45
+ this._sessionState.set(sessionId, {
46
+ isOpencode: false,
47
+ lastSpinnerTime: 0,
48
+ wasWorking: false,
49
+ });
50
+ }
51
+ return this._sessionState.get(sessionId);
52
+ }
53
+
54
+ _buildPatterns(extraPatterns, excludePatterns) {
55
+ const defaultPatterns = [
56
+ /\> $/,
57
+ /\> \x1b/,
58
+ /❯ $/,
59
+ /❯ \x1b/,
60
+ /waiting for input/i,
61
+ /press enter/i,
62
+ /press any key/i,
63
+ /confirm\s*\?/i,
64
+ /\(y\/n\)/i,
65
+ /\(yes\/no\)/i,
66
+ /\[Y\/n\]/i,
67
+ /\[y\/N\]/i,
68
+ ];
69
+
70
+ let patterns = [...defaultPatterns];
71
+
72
+ for (const p of extraPatterns) {
73
+ try { patterns.push(new RegExp(p)); } catch (e) {
74
+ console.error(`[opencode-attention] Invalid pattern "${p}":`, e.message);
75
+ }
76
+ }
77
+
78
+ for (const p of excludePatterns) {
79
+ try {
80
+ const regex = new RegExp(p);
81
+ patterns = patterns.filter(pat => pat.source !== regex.source);
82
+ } catch (e) {
83
+ console.error(`[opencode-attention] Invalid exclude pattern "${p}":`, e.message);
84
+ }
85
+ }
86
+
87
+ return patterns;
88
+ }
89
+
90
+ _matchesPattern(text) {
91
+ for (const pattern of this.patterns) {
92
+ if (pattern.test(text)) return true;
93
+ }
94
+ return false;
95
+ }
96
+
97
+ _stripAnsi(str) {
98
+ return str
99
+ .replace(/\x1b\[[0-9;]*[a-zA-Z]/g, '')
100
+ .replace(/\x1b\][^\x07]*\x07/g, '')
101
+ .replace(/\x1b\[\?[0-9]+[hl]/g, '')
102
+ .replace(/\x1b[\(\)]B/g, '')
103
+ .replace(/\x1b[0-9;]*[a-zA-Z]/g, '')
104
+ .replace(/\x1b[^[\]()?P]/g, '')
105
+ .replace(/[\x00-\x08\x0b\x0c\x0d\x0e-\x1f\x7f]/g, '')
106
+ .trim();
107
+ }
108
+
109
+ _startFlash(sessionId) {
110
+ if (this._flashing.get(sessionId)) return;
111
+ this._flashing.set(sessionId, true);
112
+ this.ctx.flashTab(sessionId, { duration: this.config.flashDuration || 0 });
113
+ }
114
+
115
+ _stopFlash(sessionId) {
116
+ if (!this._flashing.get(sessionId)) return;
117
+ this._flashing.delete(sessionId);
118
+ this.ctx.stopFlashTab(sessionId);
119
+ }
120
+
121
+ _scheduleCheck(sessionId) {
122
+ if (this._dataTimers.has(sessionId)) return;
123
+
124
+ const timer = setTimeout(() => {
125
+ this._dataTimers.delete(sessionId);
126
+ this._checkAttention(sessionId);
127
+ }, this.config.debounceMs);
128
+
129
+ this._dataTimers.set(sessionId, timer);
130
+ }
131
+
132
+ _checkAttention(sessionId) {
133
+ const state = this.ctx.getTerminalState(sessionId);
134
+ if (!state || !state.state) return;
135
+
136
+ const lines = state.state.split('\n');
137
+ const recentLines = lines.slice(-20);
138
+
139
+ let isOpencode = false;
140
+ let matchedPrompt = false;
141
+
142
+ for (const line of recentLines) {
143
+ const stripped = this._stripAnsi(line);
144
+ if (!stripped) continue;
145
+
146
+ if (/OpenCode/i.test(stripped)) {
147
+ isOpencode = true;
148
+ }
149
+
150
+ if (this._matchesPattern(stripped) || this._matchesPattern(line)) {
151
+ matchedPrompt = true;
152
+ break;
153
+ }
154
+ }
155
+
156
+ const sessionState = this._getSessionState(sessionId);
157
+ sessionState.isOpencode = isOpencode;
158
+
159
+ if (matchedPrompt) {
160
+ this._startFlash(sessionId);
161
+ }
162
+
163
+ if (isOpencode && !matchedPrompt) {
164
+ const now = Date.now();
165
+ const timeSinceSpinner = now - sessionState.lastSpinnerTime;
166
+
167
+ if (sessionState.wasWorking && timeSinceSpinner > this.config.idleThreshold) {
168
+ this._startFlash(sessionId);
169
+ sessionState.wasWorking = false;
170
+ }
171
+ }
172
+ }
173
+
174
+ onData(sessionId, data) {
175
+ const stripped = this._stripAnsi(data);
176
+ const sessionState = this._getSessionState(sessionId);
177
+
178
+ const isSpinner = /[⬝■▣]/.test(stripped) || /[⬝■▣]/.test(data);
179
+
180
+ if (isSpinner) {
181
+ sessionState.lastSpinnerTime = Date.now();
182
+ sessionState.wasWorking = true;
183
+ if (this._flashing.get(sessionId)) {
184
+ this._stopFlash(sessionId);
185
+ }
186
+ }
187
+
188
+ if (/OpenCode/i.test(stripped) || /OpenCode/i.test(data)) {
189
+ sessionState.isOpencode = true;
190
+ }
191
+
192
+ if (this._matchesPattern(stripped) || this._matchesPattern(data)) {
193
+ this._startFlash(sessionId);
194
+ } else {
195
+ this._scheduleCheck(sessionId);
196
+ }
197
+ }
198
+
199
+ onTerminalLine(sessionId, strippedLine, rawLine) {
200
+ const sessionState = this._getSessionState(sessionId);
201
+
202
+ if (/OpenCode/i.test(strippedLine)) {
203
+ sessionState.isOpencode = true;
204
+ }
205
+
206
+ if (this._matchesPattern(strippedLine) || this._matchesPattern(rawLine)) {
207
+ this._startFlash(sessionId);
208
+ }
209
+ }
210
+
211
+ onSessionConnect(sessionId) {
212
+ this._sessionState.delete(sessionId);
213
+ this._flashing.delete(sessionId);
214
+
215
+ const existingTimer = this._checkTimers.get(sessionId);
216
+ if (existingTimer) clearInterval(existingTimer);
217
+
218
+ const timer = setInterval(() => {
219
+ if (!this.ctx.getActiveSessions().includes(sessionId)) {
220
+ clearInterval(timer);
221
+ this._checkTimers.delete(sessionId);
222
+ return;
223
+ }
224
+ this._checkAttention(sessionId);
225
+ }, this.config.checkInterval);
226
+
227
+ this._checkTimers.set(sessionId, timer);
228
+ }
229
+
230
+ onSessionDisconnect(sessionId) {
231
+ this._stopFlash(sessionId);
232
+ this._sessionState.delete(sessionId);
233
+
234
+ const checkTimer = this._checkTimers.get(sessionId);
235
+ if (checkTimer) {
236
+ clearInterval(checkTimer);
237
+ this._checkTimers.delete(sessionId);
238
+ }
239
+
240
+ const dataTimer = this._dataTimers.get(sessionId);
241
+ if (dataTimer) {
242
+ clearTimeout(dataTimer);
243
+ this._dataTimers.delete(sessionId);
244
+ }
245
+ }
246
+ }
247
+
248
+ module.exports = OpenCodeAttentionPlugin;