forked from smiley/hyper-robco
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
362 lines (323 loc) · 11.3 KB
/
Copy pathindex.js
File metadata and controls
362 lines (323 loc) · 11.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
const path = require('path');
const process = require('process');
const electron = require('electron');
var sounds_path = path.join(__dirname, 'sounds').replace(/\\/g, "/");
function getSoundFullPath(sound_name) {
return 'file://' + sounds_path + '/' + sound_name;
}
if (process.type === "renderer") {
global = {
settings: electron.remote.getGlobal('settings')
}
function makePlayer(sound_name) {
var audio = new Audio(getSoundFullPath(sound_name));
audio.volume = 0.2;
return audio;
}
} else {
global.settings = {
enabled: true,
notificationsEnabled: true,
notificationVerbosity: 'normal' // 'off', 'minimal', 'normal', 'verbose'
};
function makePlayer(sound_name) {
return {
'play': function(){}
};
}
}
const SOUNDS = {
'SINGLE': [
makePlayer('ui_hacking_charsingle_01.wav'),
makePlayer('ui_hacking_charsingle_02.wav'),
makePlayer('ui_hacking_charsingle_03.wav'),
makePlayer('ui_hacking_charsingle_04.wav'),
makePlayer('ui_hacking_charsingle_05.wav'),
makePlayer('ui_hacking_charsingle_06.wav'),
],
'ARROW': [
makePlayer('ui_hacking_charscroll.wav'),
makePlayer('ui_hacking_charscroll_lp.wav'),
],
'ENTER': [
makePlayer('ui_hacking_charenter_01.wav'),
makePlayer('ui_hacking_charenter_02.wav'),
makePlayer('ui_hacking_charenter_03.wav'),
],
'EVENTS': {
'OPEN': makePlayer('poweron.mp3'),
'CLOSE': makePlayer('poweroff.mp3'),
},
'NOTIFICATIONS': [
makePlayer('ui_hacking_charenter_01.wav'),
makePlayer('ui_hacking_charenter_02.wav'),
makePlayer('ui_hacking_charenter_03.wav'),
makePlayer('poweron.mp3'),
]
}
function getRandom(list) {
var limit = list.length;
var newRand = Math.floor(Math.random() * limit);
if (list._lastNum !== undefined) {
if (newRand == list._lastNum) {
newRand = (newRand + 1) % limit;
}
}
list._lastNum = newRand;
return list[newRand];
}
// Status notification patterns
// Based on research of common CI/CD and development workflow status messages
// These patterns match completion messages, success notifications, and approval requests
// Pattern matching is case-insensitive to catch variations in output
const STATUS_PATTERNS = [
/code review completed/i,
/review completed/i,
/task completed/i,
/build succeeded/i,
/build successful/i,
/tests? passed/i,
/deployment successful/i,
/deployment complete/i,
/ready for review/i,
/approval (required|requested)/i,
/waiting for approval/i,
/merge completed/i,
/successfully merged/i,
/operation completed/i
];
// Pattern categories for verbosity control (inspired by Agent Vibes TTS)
const PATTERN_CATEGORIES = {
CRITICAL: [
/error/i,
/failed/i,
/failure/i,
/fatal/i
],
COMPLETION: [
/completed/i,
/succeeded/i,
/successful/i,
/tests? passed/i,
/build succeeded/i,
/deployment complete/i
],
APPROVAL: [
/approval (required|requested)/i,
/ready for review/i,
/waiting for approval/i
]
};
// Track recent notifications to avoid spam
let lastNotificationTime = 0;
const NOTIFICATION_COOLDOWN = 3000; // 3 seconds between notifications
const NOTIFICATION_BUFFER_SIZE = 500; // Keep last 500 chars of output
function shouldPlayNotification(text) {
if (!global.settings.notificationsEnabled) {
return false;
}
const verbosity = global.settings.notificationVerbosity || 'normal';
// Off means no notifications
if (verbosity === 'off') {
return false;
}
const now = Date.now();
if (now - lastNotificationTime < NOTIFICATION_COOLDOWN) {
return false;
}
let shouldTrigger = false;
if (verbosity === 'minimal') {
// Minimal: Only critical errors and major completions (inspired by Agent Vibes)
// Reuse pattern categories to avoid duplication
const minimalPatterns = [
...PATTERN_CATEGORIES.CRITICAL,
/successfully completed/i,
...PATTERN_CATEGORIES.COMPLETION.filter(p =>
p.source.includes('build') ||
p.source.includes('test') ||
p.source.includes('deployment')
)
];
shouldTrigger = minimalPatterns.some(pattern => pattern.test(text));
} else if (verbosity === 'verbose') {
// Verbose: All status patterns (no need to merge categories as STATUS_PATTERNS is comprehensive)
shouldTrigger = STATUS_PATTERNS.some(pattern => pattern.test(text)) ||
PATTERN_CATEGORIES.CRITICAL.some(pattern => pattern.test(text));
} else {
// Normal: Current behavior with standard status patterns
shouldTrigger = STATUS_PATTERNS.some(pattern => pattern.test(text));
}
if (shouldTrigger) {
lastNotificationTime = now;
}
return shouldTrigger;
}
exports.decorateTerm = (Term, { React, notify }) => {
return class extends React.Component {
constructor (props, context) {
super(props, context);
this._onTerminal = this._onTerminal.bind(this);
this._originalWrite = null;
this._term = null;
}
_onTerminal (term) {
if (this.props && this.props.onTerminal) this.props.onTerminal(term);
const handlers = [
[
"keydown",
function(e) {
if (!global.settings.enabled) {
return true;
}
var repeatable = false;
var soundList = SOUNDS.SINGLE;
switch (e.key) {
case "ArrowDown":
case "ArrowUp":
case "ArrowLeft":
case "ArrowRight":
repeatable = true;
soundList = SOUNDS.ARROW;
break;
case "Enter":
soundList = SOUNDS.ENTER;
break;
case "Escape":
break;
default:
break;
}
if (e.repeat && !repeatable) {
return true;
}
var sound = getRandom(soundList).play();
return true;
}.bind(term.keyboard)
],
];
term.uninstallKeyboard();
for (var i = 0; i < handlers.length; i++) {
var handler = handlers[i];
term.keyboard.handlers_ = [handler].concat(term.keyboard.handlers_);
}
term.installKeyboard();
// Hook into terminal output to detect status notifications
// This implementation monitors terminal output for status messages
// and plays audio notifications when completion/status patterns are detected.
// The system uses a rolling buffer to capture recent output and avoids
// spam with a cooldown timer between notifications.
// Store original write method
const originalWrite = term.write.bind(term);
let outputBuffer = '';
// Intercept terminal write to monitor output
term.write = function(data) {
// Call original write first
const result = originalWrite(data);
if (!global.settings.enabled || !global.settings.notificationsEnabled) {
return result;
}
// Append data to buffer (convert to string if needed)
const dataStr = typeof data === 'string' ? data : String(data);
outputBuffer += dataStr;
// Keep buffer size manageable
if (outputBuffer.length > NOTIFICATION_BUFFER_SIZE) {
outputBuffer = outputBuffer.slice(-NOTIFICATION_BUFFER_SIZE);
}
// Check for notification patterns
if (shouldPlayNotification(outputBuffer)) {
getRandom(SOUNDS.NOTIFICATIONS).play();
}
return result;
};
// Store reference for cleanup
this._originalWrite = originalWrite;
this._term = term;
}
componentWillUnmount() {
// Restore original write method when component unmounts
if (this._term && this._originalWrite) {
this._term.write = this._originalWrite;
this._originalWrite = null;
this._term = null;
}
}
render () {
return React.createElement(Term, Object.assign({}, this.props, {
onTerminal: this._onTerminal
}));
}
};
};
exports.middleware = (store) => (next) => (action) => {
if (global.settings.enabled) {
if (action.type === 'TERM_GROUP_REQUEST') {
SOUNDS.EVENTS.CLOSE.currentTime = 0.0;
SOUNDS.EVENTS.OPEN.play();
}
if (action.type === 'TERM_GROUP_EXIT') {
SOUNDS.EVENTS.CLOSE.currentTime = 0.0;
SOUNDS.EVENTS.CLOSE.play();
}
}
next(action);
};
exports.decorateMenu = menu =>
menu.map(
item => {
if (item.label !== 'Plugins') return item;
const newItem = Object.assign({}, item);
newItem.submenu = newItem.submenu.concat(
{
label: 'Terminal sounds',
checked: global.settings.enabled,
type: 'checkbox',
click: (clickedItem) => {
global.settings.enabled = !global.settings.enabled;
clickedItem.checked = global.settings.enabled;
},
},
{
label: 'Status notification sounds',
submenu: [
{
label: 'Off',
type: 'radio',
checked: global.settings.notificationVerbosity === 'off',
click: () => {
global.settings.notificationsEnabled = false;
global.settings.notificationVerbosity = 'off';
}
},
{
label: 'Minimal (Critical only)',
type: 'radio',
checked: global.settings.notificationVerbosity === 'minimal',
click: () => {
global.settings.notificationsEnabled = true;
global.settings.notificationVerbosity = 'minimal';
}
},
{
label: 'Normal',
type: 'radio',
checked: global.settings.notificationVerbosity === 'normal',
click: () => {
global.settings.notificationsEnabled = true;
global.settings.notificationVerbosity = 'normal';
}
},
{
label: 'Verbose',
type: 'radio',
checked: global.settings.notificationVerbosity === 'verbose',
click: () => {
global.settings.notificationsEnabled = true;
global.settings.notificationVerbosity = 'verbose';
}
}
]
}
);
return newItem;
}
);