agentvibes 4.4.0 → 4.5.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/.agentvibes/config.json +4 -4
- package/.claude/config/reverb-level.txt +1 -1
- package/.claude/github-star-reminder.txt +1 -1
- package/.claude/hooks-windows/bmad-speak.ps1 +112 -0
- package/.claude/hooks-windows/play-tts-piper.ps1 +3 -4
- package/.claude/hooks-windows/play-tts-sapi.ps1 +3 -4
- package/.claude/hooks-windows/play-tts-soprano.ps1 +2 -3
- package/.claude/hooks-windows/play-tts-termux-ssh.ps1 +138 -0
- package/.claude/hooks-windows/play-tts.ps1 +14 -6
- package/.claude/hooks-windows/provider-manager.ps1 +16 -1
- package/CLAUDE.md +4 -0
- package/README.md +39 -9
- package/RELEASE_NOTES.md +39 -0
- package/bin/agent-vibes +1 -1
- package/bin/agentvibes-voice-browser.js +1 -1
- package/bin/bmad-speak.js +52 -0
- package/bin/mcp-server.js +1 -1
- package/bin/test-bmad-pr +1 -1
- package/package.json +1 -1
- package/setup-windows.ps1 +4 -4
- package/src/console/app.js +58 -11
- package/src/console/tabs/agents-tab.js +61 -65
- package/src/console/tabs/help-tab.js +107 -54
- package/src/console/tabs/install-tab.js +107 -47
- package/src/console/tabs/music-tab.js +1030 -1011
- package/src/console/tabs/placeholder-tab.js +27 -0
- package/src/console/tabs/readme-tab.js +9 -7
- package/src/console/tabs/receiver-tab.js +23 -12
- package/src/console/tabs/settings-tab.js +4001 -3732
- package/src/console/tabs/voices-tab.js +1680 -1653
- package/src/console/widgets/personality-picker.js +35 -7
- package/src/console/widgets/reverb-picker.js +9 -6
- package/src/console/widgets/track-picker.js +6 -1
- package/src/i18n/de.js +201 -0
- package/src/i18n/en.js +201 -0
- package/src/i18n/es.js +201 -0
- package/src/i18n/fr.js +201 -0
- package/src/i18n/hi.js +201 -0
- package/src/i18n/ja.js +201 -0
- package/src/i18n/ko.js +201 -0
- package/src/i18n/pt.js +201 -0
- package/src/i18n/strings.js +54 -0
- package/src/i18n/zh-CN.js +201 -0
- package/src/installer/language-screen.js +31 -0
- package/src/installer.js +92 -25
- package/src/services/language-service.js +47 -0
- package/src/services/provider-service.js +14 -3
- package/src/utils/file-ownership-verifier.js +2 -2
- package/src/utils/provider-validator.js +9 -13
- package/.claude/hooks-windows/play-tts-windows-piper.ps1 +0 -209
- package/.claude/hooks-windows/play-tts-windows-sapi.ps1 +0 -108
|
@@ -1,1011 +1,1030 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* AgentVibes TUI Console — Music Tab
|
|
3
|
-
* Epic 9: Stories 9.1-9.3
|
|
4
|
-
*
|
|
5
|
-
* Implements the Tab Component Contract:
|
|
6
|
-
* createMusicTab(screen, services) → { box, show, hide, onFocus, onBlur, getFooterText, getFooterColor }
|
|
7
|
-
*
|
|
8
|
-
* Features: dynamic track library from .claude/audio/tracks/, favorites (★), active track (▶),
|
|
9
|
-
* toggle music on/off, favorites filter, preview playback on Enter/Space (toggle).
|
|
10
|
-
*/
|
|
11
|
-
|
|
12
|
-
import fs from 'node:fs';
|
|
13
|
-
import path from 'node:path';
|
|
14
|
-
import os from 'node:os';
|
|
15
|
-
import { spawn } from 'node:child_process';
|
|
16
|
-
import { buildAudioEnv, detectMp3Player } from '../audio-env.js';
|
|
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
|
-
{ id: '
|
|
75
|
-
{ id: '
|
|
76
|
-
{ id: '
|
|
77
|
-
{ id: '
|
|
78
|
-
{ id: '
|
|
79
|
-
{ id: '
|
|
80
|
-
{ id: '
|
|
81
|
-
{ id: '
|
|
82
|
-
{ id: '
|
|
83
|
-
{ id: '
|
|
84
|
-
{ id: '
|
|
85
|
-
{ id: '
|
|
86
|
-
{ id: '
|
|
87
|
-
{ id: '
|
|
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
|
-
.replace(
|
|
115
|
-
.replace(/^
|
|
116
|
-
.replace(/
|
|
117
|
-
.replace(/
|
|
118
|
-
.replace(/
|
|
119
|
-
.replace(
|
|
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
|
-
const
|
|
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
|
-
content =
|
|
219
|
-
|
|
220
|
-
(
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
const
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
*
|
|
261
|
-
*
|
|
262
|
-
* @param {object}
|
|
263
|
-
* @param {
|
|
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
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
btn.
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
btn.
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
'',
|
|
432
|
-
` {${COLORS.
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
`
|
|
436
|
-
'',
|
|
437
|
-
` {${COLORS.
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
modal.focus();
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
//
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
_hintBase =
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
const
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
const
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
const
|
|
616
|
-
const
|
|
617
|
-
const
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
const
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
const
|
|
631
|
-
|
|
632
|
-
const
|
|
633
|
-
const
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
trackList.
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
//
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
const
|
|
752
|
-
_saveLocally();
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
const
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
cancelBtn.key(['
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
_tlBlink.sel
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
_tlBlink.
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
if (
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
items[
|
|
928
|
-
}
|
|
929
|
-
_hintIdx
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
);
|
|
945
|
-
|
|
946
|
-
})
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
if (
|
|
955
|
-
const
|
|
956
|
-
|
|
957
|
-
if (
|
|
958
|
-
const
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1
|
+
/**
|
|
2
|
+
* AgentVibes TUI Console — Music Tab
|
|
3
|
+
* Epic 9: Stories 9.1-9.3
|
|
4
|
+
*
|
|
5
|
+
* Implements the Tab Component Contract:
|
|
6
|
+
* createMusicTab(screen, services) → { box, show, hide, onFocus, onBlur, getFooterText, getFooterColor }
|
|
7
|
+
*
|
|
8
|
+
* Features: dynamic track library from .claude/audio/tracks/, favorites (★), active track (▶),
|
|
9
|
+
* toggle music on/off, favorites filter, preview playback on Enter/Space (toggle).
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import fs from 'node:fs';
|
|
13
|
+
import path from 'node:path';
|
|
14
|
+
import os from 'node:os';
|
|
15
|
+
import { spawn } from 'node:child_process';
|
|
16
|
+
import { buildAudioEnv, detectMp3Player } from '../audio-env.js';
|
|
17
|
+
import { t } from '../../i18n/strings.js';
|
|
18
|
+
|
|
19
|
+
const IS_TEST = process.env.AGENTVIBES_TEST_MODE === 'true';
|
|
20
|
+
|
|
21
|
+
let blessed;
|
|
22
|
+
if (!IS_TEST) {
|
|
23
|
+
const { default: b } = await import('blessed');
|
|
24
|
+
blessed = b;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// ---------------------------------------------------------------------------
|
|
28
|
+
|
|
29
|
+
const COLORS = {
|
|
30
|
+
contentBg: '#0a0e1a',
|
|
31
|
+
sectionHdr: '#f06292', // Light magenta — section headers for Music tab
|
|
32
|
+
labelFg: '#e3f2fd',
|
|
33
|
+
valueFg: '#f06292', // Light magenta — brand color
|
|
34
|
+
activeFg: '#69f0ae', // Green — active/playing track
|
|
35
|
+
favoriteFg: '#ffff00', // Yellow — favorite star
|
|
36
|
+
btnDefault: '#880e4f', // Dark magenta — Music tab buttons
|
|
37
|
+
btnFocus: '#2e7d32', // Green — focused/selected
|
|
38
|
+
btnFocusFg: '#ffffff',
|
|
39
|
+
btnPress: '#ff00ff',
|
|
40
|
+
borderFg: '#f06292', // Light magenta — border
|
|
41
|
+
footerBg: '#880e4f', // Dark magenta — Music tab footer
|
|
42
|
+
noticeFg: '#90a4ae',
|
|
43
|
+
dimFg: '#455a64',
|
|
44
|
+
playingFg: 'bright-cyan', // Cyan — currently previewing track indicator
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
const FOOTER_TEXT = '[↑↓/jk] Navigate [Space] Preview [Enter] Select [M] Toggle [*] Favorite [F] Filter [Q] Quit';
|
|
48
|
+
|
|
49
|
+
// ---------------------------------------------------------------------------
|
|
50
|
+
// Static catalog — correct real filenames; Soft Flamenco kept first for compat.
|
|
51
|
+
// At runtime the UI scans .claude/audio/tracks/ dynamically so new tracks appear.
|
|
52
|
+
|
|
53
|
+
// Full display names per track — emoji + label. Single-codepoint emoji only (no \uFE0F
|
|
54
|
+
// variation selectors) so blessed renders them cleanly in list widgets.
|
|
55
|
+
const TRACK_DISPLAY = Object.freeze({
|
|
56
|
+
'agentvibes_soft_flamenco_loop.mp3': '🎻 Soft Flamenco',
|
|
57
|
+
'agent_vibes_arabic_v2_loop.mp3': '🎵 Arabic Oud',
|
|
58
|
+
'agent_vibes_bachata_v1_loop.mp3': '🎺 Bachata',
|
|
59
|
+
'agent_vibes_bossa_nova_v2_loop.mp3': '🌸 Bossa Nova',
|
|
60
|
+
'agent_vibes_celtic_harp_v1_loop.mp3': '🎶 Celtic Harp',
|
|
61
|
+
'agent_vibes_chillwave_v2_loop.mp3': '🌊 Chillwave',
|
|
62
|
+
'agent_vibes_cumbia_v1_loop.mp3': '🎸 Cumbia',
|
|
63
|
+
'agent_vibes_dark_chill_step_loop.mp3': '🌙 Dark Chill Step',
|
|
64
|
+
'agent_vibes_ganawa_ambient_v2_loop.mp3': '🪘 Gnawa Ambient',
|
|
65
|
+
'agent_vibes_goa_trance_v2_loop.mp3': '🌀 Goa Trance',
|
|
66
|
+
'agent_vibes_harpsichord_v2_loop.mp3': '🎼 Harpsichord',
|
|
67
|
+
'agent_vibes_hawaiian_slack_key_guitar_v2_loop.mp3': '🌺 Hawaiian Slack Key Guitar',
|
|
68
|
+
'agent_vibes_japanese_city_pop_v1_loop.mp3': '🌆 Japanese City Pop',
|
|
69
|
+
'agent_vibes_salsa_v2_loop.mp3': '💃 Salsa',
|
|
70
|
+
'agent_vibes_tabla_dream_pop_v1_loop.mp3': '🥁 Tabla Dream Pop',
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
const BUILT_IN_TRACK_CATALOG = Object.freeze([
|
|
74
|
+
{ id: 'agentvibes_soft_flamenco_loop.mp3', label: '🎻 Soft Flamenco' },
|
|
75
|
+
{ id: 'agent_vibes_arabic_v2_loop.mp3', label: '🎵 Arabic Oud' },
|
|
76
|
+
{ id: 'agent_vibes_bachata_v1_loop.mp3', label: '🎺 Bachata' },
|
|
77
|
+
{ id: 'agent_vibes_bossa_nova_v2_loop.mp3', label: '🌸 Bossa Nova' },
|
|
78
|
+
{ id: 'agent_vibes_celtic_harp_v1_loop.mp3', label: '🎶 Celtic Harp' },
|
|
79
|
+
{ id: 'agent_vibes_chillwave_v2_loop.mp3', label: '🌊 Chillwave' },
|
|
80
|
+
{ id: 'agent_vibes_cumbia_v1_loop.mp3', label: '🎸 Cumbia' },
|
|
81
|
+
{ id: 'agent_vibes_dark_chill_step_loop.mp3', label: '🌙 Dark Chill Step' },
|
|
82
|
+
{ id: 'agent_vibes_ganawa_ambient_v2_loop.mp3', label: '🪘 Gnawa Ambient' },
|
|
83
|
+
{ id: 'agent_vibes_goa_trance_v2_loop.mp3', label: '🌀 Goa Trance' },
|
|
84
|
+
{ id: 'agent_vibes_harpsichord_v2_loop.mp3', label: '🎼 Harpsichord' },
|
|
85
|
+
{ id: 'agent_vibes_hawaiian_slack_key_guitar_v2_loop.mp3', label: '🌺 Hawaiian Slack Key Guitar' },
|
|
86
|
+
{ id: 'agent_vibes_japanese_city_pop_v1_loop.mp3', label: '🌆 Japanese City Pop' },
|
|
87
|
+
{ id: 'agent_vibes_salsa_v2_loop.mp3', label: '💃 Salsa' },
|
|
88
|
+
{ id: 'agent_vibes_tabla_dream_pop_v1_loop.mp3', label: '🥁 Tabla Dream Pop' },
|
|
89
|
+
]);
|
|
90
|
+
|
|
91
|
+
// ---------------------------------------------------------------------------
|
|
92
|
+
// Exported pure helpers (testable without blessed)
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Return the built-in track catalog (static, predictable for tests).
|
|
96
|
+
* @returns {{ id: string, label: string }[]}
|
|
97
|
+
*/
|
|
98
|
+
export function getBuiltInTracks() {
|
|
99
|
+
return [...BUILT_IN_TRACK_CATALOG];
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Generate a pretty label from a track filename.
|
|
104
|
+
* Returns the canonical display name (with emoji) for known tracks.
|
|
105
|
+
* For unknown tracks, strips agent_vibes_/agentvibes_ prefix and _loop/_vN suffixes,
|
|
106
|
+
* then title-cases the result.
|
|
107
|
+
*
|
|
108
|
+
* @param {string} filename
|
|
109
|
+
* @returns {string}
|
|
110
|
+
*/
|
|
111
|
+
export function formatTrackLabel(filename) {
|
|
112
|
+
if (TRACK_DISPLAY[filename]) return TRACK_DISPLAY[filename];
|
|
113
|
+
const label = filename
|
|
114
|
+
.replace(/\.mp3$/i, '')
|
|
115
|
+
.replace(/^agent_vibes_/i, '')
|
|
116
|
+
.replace(/^agentvibes_/i, '')
|
|
117
|
+
.replace(/_loop$/i, '')
|
|
118
|
+
.replace(/_v\d+$/i, '')
|
|
119
|
+
.replace(/_/g, ' ')
|
|
120
|
+
.replace(/\b\w/g, c => c.toUpperCase())
|
|
121
|
+
.trim();
|
|
122
|
+
return label || filename;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* Format music enabled state as readable string.
|
|
127
|
+
* @param {boolean|undefined} enabled
|
|
128
|
+
* @returns {string}
|
|
129
|
+
*/
|
|
130
|
+
export function formatMusicStatus(enabled) {
|
|
131
|
+
return enabled ? 'Enabled' : 'Disabled';
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
// ---------------------------------------------------------------------------
|
|
135
|
+
// Test stub
|
|
136
|
+
|
|
137
|
+
function createTestStub() {
|
|
138
|
+
return {
|
|
139
|
+
box: {},
|
|
140
|
+
show: () => {},
|
|
141
|
+
hide: () => {},
|
|
142
|
+
onFocus: () => {},
|
|
143
|
+
onBlur: () => {},
|
|
144
|
+
getFooterText: () => FOOTER_TEXT,
|
|
145
|
+
getFooterColor: () => COLORS.footerBg,
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
// ---------------------------------------------------------------------------
|
|
150
|
+
// Helpers (used inside createMusicTab)
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* Resolve the tracks directory for the running project.
|
|
154
|
+
* Uses process.cwd() because the TUI always runs from the project root
|
|
155
|
+
* and this function is called both internally and from exported helpers
|
|
156
|
+
* that lack configService context.
|
|
157
|
+
* @returns {string}
|
|
158
|
+
*/
|
|
159
|
+
function _getTracksDir() {
|
|
160
|
+
return path.join(process.cwd(), '.claude', 'audio', 'tracks');
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
* Scan .claude/audio/tracks/ for .mp3 files.
|
|
165
|
+
* Falls back to the static catalog if the directory is absent.
|
|
166
|
+
*
|
|
167
|
+
* @returns {{ id: string, label: string, isBuiltIn: boolean }[]}
|
|
168
|
+
*/
|
|
169
|
+
export function scanTracks() {
|
|
170
|
+
const tracksDir = _getTracksDir();
|
|
171
|
+
try {
|
|
172
|
+
const files = fs.readdirSync(tracksDir);
|
|
173
|
+
const builtInIds = new Set(BUILT_IN_TRACK_CATALOG.map(t => t.id));
|
|
174
|
+
return files
|
|
175
|
+
.filter(f => /\.mp3$/i.test(f))
|
|
176
|
+
.sort()
|
|
177
|
+
.map(f => ({ id: f, label: formatTrackLabel(f), isBuiltIn: builtInIds.has(f) }));
|
|
178
|
+
} catch {
|
|
179
|
+
// Directory not found or unreadable — use the static catalog
|
|
180
|
+
return BUILT_IN_TRACK_CATALOG.map(t => ({ ...t, isBuiltIn: true }));
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* Get music config from configService.
|
|
186
|
+
*/
|
|
187
|
+
function _getMusic(configService) {
|
|
188
|
+
const cfg = configService.getConfig();
|
|
189
|
+
// Use backgroundMusic (matches settings-tab); fall back to legacy 'music' key
|
|
190
|
+
const music = cfg.backgroundMusic ?? cfg.music ?? {};
|
|
191
|
+
return {
|
|
192
|
+
enabled: music.enabled ?? false,
|
|
193
|
+
track: music.track ?? BUILT_IN_TRACK_CATALOG[0].id,
|
|
194
|
+
volume: music.volume ?? 70,
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
* Update music config (merge, never overwrite).
|
|
200
|
+
* Writes to 'backgroundMusic' key (shared with settings-tab).
|
|
201
|
+
*/
|
|
202
|
+
function _setMusic(configService, update) {
|
|
203
|
+
const current = _getMusic(configService);
|
|
204
|
+
configService.set('backgroundMusic', { ...current, ...update });
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
/**
|
|
208
|
+
* Patch the 'default' entry in audio-effects.cfg to use the given track.
|
|
209
|
+
* play-tts-piper.sh reads the track from audio-effects.cfg (not from config.json),
|
|
210
|
+
* so any track change must be reflected here to take effect at runtime.
|
|
211
|
+
* Safe to call with invalid/missing tracks — non-fatal on failure.
|
|
212
|
+
* @param {string} track - Filename like "agent_vibes_salsa_v2_loop.mp3"
|
|
213
|
+
*/
|
|
214
|
+
export function applyTrackToAudioEffects(track) {
|
|
215
|
+
if (!track || /[|/\\]/.test(track)) return;
|
|
216
|
+
const cfgFile = path.join(process.cwd(), '.claude', 'config', 'audio-effects.cfg');
|
|
217
|
+
try {
|
|
218
|
+
let content = fs.readFileSync(cfgFile, 'utf-8');
|
|
219
|
+
content = content.replace(
|
|
220
|
+
/^default\|([^|]*)\|([^|]*)\|(.*)$/m,
|
|
221
|
+
(match, g1, g2, g3) => `default|${g1}|${track}|${g3}`,
|
|
222
|
+
);
|
|
223
|
+
fs.writeFileSync(cfgFile, content, 'utf-8');
|
|
224
|
+
} catch { /* file may not exist — non-fatal */ }
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
/**
|
|
228
|
+
* Get favorites array from config.musicFavorites.
|
|
229
|
+
*/
|
|
230
|
+
export function getMusicFavorites(configService) {
|
|
231
|
+
const favs = configService.getConfig().musicFavorites;
|
|
232
|
+
return Array.isArray(favs) ? favs : [];
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
/**
|
|
236
|
+
* Toggle a track in the favorites list.
|
|
237
|
+
*/
|
|
238
|
+
export function toggleMusicFavorite(configService, trackId) {
|
|
239
|
+
const favs = getMusicFavorites(configService);
|
|
240
|
+
const idx = favs.indexOf(trackId);
|
|
241
|
+
if (idx >= 0) {
|
|
242
|
+
favs.splice(idx, 1);
|
|
243
|
+
} else {
|
|
244
|
+
favs.push(trackId);
|
|
245
|
+
}
|
|
246
|
+
configService.set('musicFavorites', favs);
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
/**
|
|
250
|
+
* Get custom tracks from config.
|
|
251
|
+
*/
|
|
252
|
+
function _getCustomTracks(configService) {
|
|
253
|
+
const custom = configService.getConfig().customTracks;
|
|
254
|
+
return Array.isArray(custom) ? custom : [];
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
// ---------------------------------------------------------------------------
|
|
258
|
+
|
|
259
|
+
/**
|
|
260
|
+
* Create the Music tab component.
|
|
261
|
+
*
|
|
262
|
+
* @param {object} screen - Blessed screen instance (or test stub)
|
|
263
|
+
* @param {object} services
|
|
264
|
+
* @param {import('../../services/config-service.js').ConfigService} services.configService
|
|
265
|
+
* @returns {{ box, show, hide, onFocus, onBlur, getFooterText, getFooterColor }}
|
|
266
|
+
*/
|
|
267
|
+
export function createMusicTab(screen, services) {
|
|
268
|
+
if (IS_TEST) return createTestStub();
|
|
269
|
+
|
|
270
|
+
const { configService, focusMainTabBar, updateHeaderStatus, languageService } = services;
|
|
271
|
+
const _tl = (key) => languageService ? languageService.t(key) : t('en', key);
|
|
272
|
+
|
|
273
|
+
// -------------------------------------------------------------------------
|
|
274
|
+
// Container
|
|
275
|
+
|
|
276
|
+
const box = blessed.box({
|
|
277
|
+
parent: screen,
|
|
278
|
+
top: 4,
|
|
279
|
+
left: 0,
|
|
280
|
+
width: '100%',
|
|
281
|
+
bottom: 2,
|
|
282
|
+
hidden: true,
|
|
283
|
+
style: { fg: COLORS.labelFg, bg: COLORS.contentBg },
|
|
284
|
+
border: { type: 'line' },
|
|
285
|
+
borderStyle: { fg: COLORS.borderFg },
|
|
286
|
+
});
|
|
287
|
+
|
|
288
|
+
// -------------------------------------------------------------------------
|
|
289
|
+
// Section headers
|
|
290
|
+
|
|
291
|
+
const builtInHdr = blessed.text({
|
|
292
|
+
parent: box,
|
|
293
|
+
top: 1,
|
|
294
|
+
left: 2,
|
|
295
|
+
content: `{${COLORS.sectionHdr}-fg}${_tl('musicBuiltInHeader')}${'─'.repeat(48)}{/${COLORS.sectionHdr}-fg}`,
|
|
296
|
+
tags: true,
|
|
297
|
+
style: { bg: COLORS.contentBg },
|
|
298
|
+
});
|
|
299
|
+
|
|
300
|
+
// Currently selected track indicator (updated by refreshDisplay)
|
|
301
|
+
const activeTrackText = blessed.text({
|
|
302
|
+
parent: box,
|
|
303
|
+
top: 1,
|
|
304
|
+
right: 4,
|
|
305
|
+
shrink: true,
|
|
306
|
+
tags: true,
|
|
307
|
+
content: '',
|
|
308
|
+
style: { bg: COLORS.contentBg },
|
|
309
|
+
});
|
|
310
|
+
|
|
311
|
+
// -------------------------------------------------------------------------
|
|
312
|
+
// Track list
|
|
313
|
+
|
|
314
|
+
const trackList = blessed.list({
|
|
315
|
+
parent: box,
|
|
316
|
+
top: 3,
|
|
317
|
+
left: 2,
|
|
318
|
+
width: '96%',
|
|
319
|
+
height: '55%',
|
|
320
|
+
keys: true,
|
|
321
|
+
vi: true,
|
|
322
|
+
mouse: true,
|
|
323
|
+
tags: true,
|
|
324
|
+
border: { type: 'line' },
|
|
325
|
+
scrollbar: { ch: '│', style: { fg: COLORS.sectionHdr } },
|
|
326
|
+
style: {
|
|
327
|
+
fg: COLORS.labelFg,
|
|
328
|
+
bg: COLORS.contentBg,
|
|
329
|
+
border: { fg: COLORS.borderFg },
|
|
330
|
+
selected: { bg: '#3e2000', fg: COLORS.activeFg, bold: true },
|
|
331
|
+
item: { fg: COLORS.labelFg },
|
|
332
|
+
},
|
|
333
|
+
});
|
|
334
|
+
|
|
335
|
+
// -------------------------------------------------------------------------
|
|
336
|
+
// Status panel
|
|
337
|
+
|
|
338
|
+
const musicStatusHdr = blessed.text({
|
|
339
|
+
parent: box,
|
|
340
|
+
top: '64%',
|
|
341
|
+
left: 2,
|
|
342
|
+
content: `{${COLORS.sectionHdr}-fg}${_tl('musicStatusHeader')}${'─'.repeat(52)}{/${COLORS.sectionHdr}-fg}`,
|
|
343
|
+
tags: true,
|
|
344
|
+
style: { bg: COLORS.contentBg },
|
|
345
|
+
});
|
|
346
|
+
|
|
347
|
+
const statusLine = blessed.text({
|
|
348
|
+
parent: box,
|
|
349
|
+
top: '69%',
|
|
350
|
+
left: 2,
|
|
351
|
+
tags: true,
|
|
352
|
+
content: '',
|
|
353
|
+
style: { fg: COLORS.labelFg, bg: COLORS.contentBg },
|
|
354
|
+
});
|
|
355
|
+
|
|
356
|
+
const previewLine = blessed.text({
|
|
357
|
+
parent: box,
|
|
358
|
+
top: '74%',
|
|
359
|
+
left: 2,
|
|
360
|
+
tags: true,
|
|
361
|
+
content: '',
|
|
362
|
+
style: { fg: COLORS.playingFg, bg: COLORS.contentBg },
|
|
363
|
+
});
|
|
364
|
+
|
|
365
|
+
// -------------------------------------------------------------------------
|
|
366
|
+
// Buttons
|
|
367
|
+
|
|
368
|
+
function _createBtn(label, onClick) {
|
|
369
|
+
const btn = blessed.button({
|
|
370
|
+
parent: box,
|
|
371
|
+
content: label,
|
|
372
|
+
mouse: true,
|
|
373
|
+
keys: true,
|
|
374
|
+
shrink: true,
|
|
375
|
+
padding: { left: 1, right: 1 },
|
|
376
|
+
style: {
|
|
377
|
+
bg: COLORS.btnDefault,
|
|
378
|
+
fg: 'white',
|
|
379
|
+
focus: { bg: COLORS.btnFocus, fg: COLORS.btnFocusFg, bold: true },
|
|
380
|
+
hover: { bg: COLORS.btnFocus, fg: COLORS.btnFocusFg, bold: true },
|
|
381
|
+
},
|
|
382
|
+
});
|
|
383
|
+
btn.on('focus', () => {
|
|
384
|
+
btn.style.bg = COLORS.btnFocus;
|
|
385
|
+
btn.style.fg = COLORS.btnFocusFg;
|
|
386
|
+
const raw = btn.content.replace(/[►◄]/g, '').trim();
|
|
387
|
+
btn.setContent(`►${raw}◄`);
|
|
388
|
+
screen.render();
|
|
389
|
+
});
|
|
390
|
+
btn.on('blur', () => {
|
|
391
|
+
btn.style.bg = COLORS.btnDefault;
|
|
392
|
+
btn.style.fg = 'white';
|
|
393
|
+
const raw = btn.content.replace(/[►◄]/g, '').trim();
|
|
394
|
+
btn.setContent(raw);
|
|
395
|
+
screen.render();
|
|
396
|
+
});
|
|
397
|
+
btn.key(['enter', 'space'], () => {
|
|
398
|
+
btn.style.bg = COLORS.btnPress;
|
|
399
|
+
screen.render();
|
|
400
|
+
setTimeout(() => {
|
|
401
|
+
btn.style.bg = COLORS.btnDefault;
|
|
402
|
+
screen.render();
|
|
403
|
+
onClick();
|
|
404
|
+
}, 150);
|
|
405
|
+
});
|
|
406
|
+
btn.on('click', () => btn.press());
|
|
407
|
+
btn.on('mouseover', () => btn.focus());
|
|
408
|
+
return btn;
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
const toggleBtn = _createBtn(_tl('musicToggleBtn'), () => {
|
|
412
|
+
const { enabled } = _getMusic(configService);
|
|
413
|
+
_setMusic(configService, { enabled: !enabled });
|
|
414
|
+
refreshDisplay();
|
|
415
|
+
});
|
|
416
|
+
toggleBtn.bottom = 4;
|
|
417
|
+
toggleBtn.left = 4;
|
|
418
|
+
|
|
419
|
+
const addCustomTrackBtn = _createBtn(_tl('musicAddCustomBtn'), () => {
|
|
420
|
+
const modal = blessed.box({
|
|
421
|
+
parent: screen,
|
|
422
|
+
top: 'center',
|
|
423
|
+
left: 'center',
|
|
424
|
+
width: 66,
|
|
425
|
+
height: 11,
|
|
426
|
+
border: { type: 'line' },
|
|
427
|
+
tags: true,
|
|
428
|
+
label: ` {${COLORS.activeFg}-fg}Add Custom Background Track{/${COLORS.activeFg}-fg} `,
|
|
429
|
+
style: { border: { fg: COLORS.borderFg }, bg: COLORS.contentBg },
|
|
430
|
+
content: [
|
|
431
|
+
'',
|
|
432
|
+
` {${COLORS.labelFg}-fg}To add a custom track:{/${COLORS.labelFg}-fg}`,
|
|
433
|
+
'',
|
|
434
|
+
` {${COLORS.valueFg}-fg}1.{/${COLORS.valueFg}-fg} Place an MP3/OGG/WAV file in:`,
|
|
435
|
+
` {${COLORS.noticeFg}-fg}.claude/audio/tracks/{/${COLORS.noticeFg}-fg}`,
|
|
436
|
+
'',
|
|
437
|
+
` {${COLORS.valueFg}-fg}2.{/${COLORS.valueFg}-fg} Or run: {${COLORS.noticeFg}-fg}/agent-vibes:background-music{/${COLORS.noticeFg}-fg}`,
|
|
438
|
+
'',
|
|
439
|
+
` {${COLORS.dimFg}-fg}[Esc / Enter] Close{/${COLORS.dimFg}-fg}`,
|
|
440
|
+
].join('\n'),
|
|
441
|
+
});
|
|
442
|
+
modal.key(['escape', 'enter', 'q'], () => { modal.destroy(); trackList.focus(); screen.render(); });
|
|
443
|
+
modal.setFront();
|
|
444
|
+
modal.focus();
|
|
445
|
+
screen.render();
|
|
446
|
+
});
|
|
447
|
+
addCustomTrackBtn.bottom = 4;
|
|
448
|
+
addCustomTrackBtn.left = 26;
|
|
449
|
+
|
|
450
|
+
// -------------------------------------------------------------------------
|
|
451
|
+
// Hint text shown in previewLine when the list has focus and nothing is playing.
|
|
452
|
+
// Getter functions so they re-translate when language changes.
|
|
453
|
+
const _hintText = () => `{${COLORS.dimFg}-fg}${_tl('musicHintText')}{/${COLORS.dimFg}-fg}`;
|
|
454
|
+
const _rowHint = () => ` {bright-black-fg}${_tl('musicRowHint')}{/bright-black-fg}`;
|
|
455
|
+
let _listFocused = false;
|
|
456
|
+
|
|
457
|
+
// Inline selection hint appended to the currently highlighted track row.
|
|
458
|
+
// _hintBase stores the item's clean content (no hint, no █) so we never need
|
|
459
|
+
// a sentinel character — PUA chars like U+E000 render as Nerd Font icons.
|
|
460
|
+
let _hintIdx = -1;
|
|
461
|
+
let _hintBase = ''; // content of items[_hintIdx] before hint was appended
|
|
462
|
+
let _refreshing = false;
|
|
463
|
+
|
|
464
|
+
// Known limitation: _updateHint and _tlTick (blink) can interleave,
|
|
465
|
+
// causing brief visual glitches. The _refreshing guard prevents the worst
|
|
466
|
+
// cases but is not a complete fix. Acceptable for a TUI animation.
|
|
467
|
+
function _updateHint(idx) {
|
|
468
|
+
const items = trackList.items;
|
|
469
|
+
// Restore previously hinted row using its saved base content
|
|
470
|
+
if (_hintIdx >= 0 && _hintIdx !== idx && items[_hintIdx]) {
|
|
471
|
+
const hadBlink = (items[_hintIdx].content ?? '').endsWith(' █');
|
|
472
|
+
items[_hintIdx].setContent(hadBlink ? _hintBase + ' █' : _hintBase);
|
|
473
|
+
}
|
|
474
|
+
// Add hint to the new row, saving its clean base first
|
|
475
|
+
if (idx >= 0 && items[idx]) {
|
|
476
|
+
let c = items[idx].content ?? '';
|
|
477
|
+
const hasBlink = c.endsWith(' █');
|
|
478
|
+
if (hasBlink) c = c.slice(0, -2);
|
|
479
|
+
_hintBase = c;
|
|
480
|
+
items[idx].setContent(c + _rowHint() + (hasBlink ? ' █' : ''));
|
|
481
|
+
} else {
|
|
482
|
+
_hintBase = '';
|
|
483
|
+
}
|
|
484
|
+
_hintIdx = idx;
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
// -------------------------------------------------------------------------
|
|
488
|
+
// Playback state
|
|
489
|
+
|
|
490
|
+
let _playingProcess = null;
|
|
491
|
+
let _playingTrackId = null;
|
|
492
|
+
|
|
493
|
+
// Kill the entire process group so child audio processes (ffplay, play, mpg123) all die
|
|
494
|
+
function _killPlayingProcess() {
|
|
495
|
+
if (_playingProcess) {
|
|
496
|
+
const _isWin = process.platform === 'win32' && !process.env.WSL_DISTRO_NAME;
|
|
497
|
+
try {
|
|
498
|
+
if (_isWin) {
|
|
499
|
+
// Windows: kill the process tree via taskkill (process group kill doesn't work)
|
|
500
|
+
spawn('taskkill', ['/F', '/T', '/PID', String(_playingProcess.pid)], {
|
|
501
|
+
stdio: 'ignore', windowsHide: true,
|
|
502
|
+
});
|
|
503
|
+
} else {
|
|
504
|
+
process.kill(-_playingProcess.pid, 'SIGTERM');
|
|
505
|
+
}
|
|
506
|
+
} catch (e) {
|
|
507
|
+
if (e.code !== 'ESRCH') { /* ignore */ }
|
|
508
|
+
}
|
|
509
|
+
_playingProcess = null;
|
|
510
|
+
}
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
const _spawnEnv = buildAudioEnv();
|
|
514
|
+
const _detectedPlayer = detectMp3Player(_spawnEnv);
|
|
515
|
+
|
|
516
|
+
process.on('exit', () => { _killPlayingProcess(); });
|
|
517
|
+
|
|
518
|
+
/**
|
|
519
|
+
* Preview a track by spawning an audio player.
|
|
520
|
+
* Second call with the same trackId stops playback (toggle).
|
|
521
|
+
*/
|
|
522
|
+
function _playTrack(trackId) {
|
|
523
|
+
const tracksDir = _getTracksDir();
|
|
524
|
+
const trackPath = path.resolve(tracksDir, trackId);
|
|
525
|
+
|
|
526
|
+
// Guard: path must stay inside tracksDir
|
|
527
|
+
const safeBase = path.resolve(tracksDir);
|
|
528
|
+
if (!trackPath.startsWith(safeBase + path.sep) && trackPath !== safeBase) {
|
|
529
|
+
return;
|
|
530
|
+
}
|
|
531
|
+
|
|
532
|
+
// Toggle: second press on the same track → stop
|
|
533
|
+
if (_playingTrackId === trackId) {
|
|
534
|
+
_killPlayingProcess();
|
|
535
|
+
_playingTrackId = null;
|
|
536
|
+
previewLine.setContent(_listFocused ? _hintText() : '');
|
|
537
|
+
screen.render();
|
|
538
|
+
return;
|
|
539
|
+
}
|
|
540
|
+
|
|
541
|
+
// Kill any previously playing track
|
|
542
|
+
_killPlayingProcess();
|
|
543
|
+
_playingTrackId = null;
|
|
544
|
+
|
|
545
|
+
if (!_detectedPlayer) {
|
|
546
|
+
const installHint = process.platform === 'win32'
|
|
547
|
+
? 'No MP3 player found. Install ffmpeg: winget install ffmpeg'
|
|
548
|
+
: 'No MP3 player found. Install ffmpeg: sudo apt install ffmpeg';
|
|
549
|
+
previewLine.setContent(`{red-fg}${installHint}{/red-fg}`);
|
|
550
|
+
screen.render();
|
|
551
|
+
setTimeout(() => { previewLine.setContent(_listFocused ? _hintText() : ''); screen.render(); }, 5000);
|
|
552
|
+
return;
|
|
553
|
+
}
|
|
554
|
+
|
|
555
|
+
const _isWin = process.platform === 'win32' && !process.env.WSL_DISTRO_NAME;
|
|
556
|
+
// Spawn the detected player directly (no sh -c chain — avoids VLC/cvlc stderr issues)
|
|
557
|
+
_playingProcess = spawn(_detectedPlayer.bin, _detectedPlayer.args(trackPath), {
|
|
558
|
+
stdio: 'ignore', detached: !_isWin, windowsHide: true, env: _spawnEnv,
|
|
559
|
+
});
|
|
560
|
+
_playingTrackId = trackId;
|
|
561
|
+
|
|
562
|
+
const label = _allTracks.find(t => t.id === trackId)?.label ?? formatTrackLabel(trackId);
|
|
563
|
+
previewLine.setContent(`{${COLORS.playingFg}-fg}♪ Previewing: ${label} (Space again to stop){/${COLORS.playingFg}-fg}`);
|
|
564
|
+
screen.render();
|
|
565
|
+
|
|
566
|
+
_playingProcess.on('exit', () => {
|
|
567
|
+
if (_playingTrackId === trackId) {
|
|
568
|
+
_playingTrackId = null;
|
|
569
|
+
_playingProcess = null;
|
|
570
|
+
previewLine.setContent(_listFocused ? _hintText() : '');
|
|
571
|
+
refreshDisplay(); // clears (playing) label
|
|
572
|
+
}
|
|
573
|
+
});
|
|
574
|
+
|
|
575
|
+
_playingProcess.on('error', () => {
|
|
576
|
+
if (_playingTrackId === trackId) {
|
|
577
|
+
_killPlayingProcess();
|
|
578
|
+
_playingTrackId = null;
|
|
579
|
+
_playingProcess = null;
|
|
580
|
+
previewLine.setContent(_listFocused ? _hintText() : '');
|
|
581
|
+
}
|
|
582
|
+
});
|
|
583
|
+
}
|
|
584
|
+
|
|
585
|
+
// -------------------------------------------------------------------------
|
|
586
|
+
// Display state
|
|
587
|
+
|
|
588
|
+
let _showFavoritesOnly = false;
|
|
589
|
+
let _allTracks = [];
|
|
590
|
+
|
|
591
|
+
function _buildAllTracks() {
|
|
592
|
+
const scanned = scanTracks();
|
|
593
|
+
const scannedIds = new Set(scanned.map(t => t.id));
|
|
594
|
+
// Append custom tracks not already present from disk scan
|
|
595
|
+
const custom = _getCustomTracks(configService)
|
|
596
|
+
.filter(id => !scannedIds.has(id))
|
|
597
|
+
.map(id => ({ id, label: formatTrackLabel(id), isBuiltIn: false }));
|
|
598
|
+
return [...scanned, ...custom];
|
|
599
|
+
}
|
|
600
|
+
|
|
601
|
+
function _getVisibleTracks() {
|
|
602
|
+
if (!_showFavoritesOnly) return _allTracks;
|
|
603
|
+
const favs = getMusicFavorites(configService);
|
|
604
|
+
return _allTracks.filter(t => favs.includes(t.id));
|
|
605
|
+
}
|
|
606
|
+
|
|
607
|
+
function _getSelectedTrackId() {
|
|
608
|
+
const visible = _getVisibleTracks();
|
|
609
|
+
const entry = visible[trackList.selected];
|
|
610
|
+
return entry ? entry.id : null;
|
|
611
|
+
}
|
|
612
|
+
|
|
613
|
+
function _buildListItems(tracks, activeTrackId, favorites) {
|
|
614
|
+
return tracks.map(t => {
|
|
615
|
+
const isFav = favorites.includes(t.id);
|
|
616
|
+
const isActive = t.id === activeTrackId;
|
|
617
|
+
const isPrev = t.id === _playingTrackId;
|
|
618
|
+
const star = isFav ? '★' : ' ';
|
|
619
|
+
const dot = isPrev ? '♪' : (isActive ? '{green-fg}✓{/green-fg}' : ' ');
|
|
620
|
+
const tag = t.isBuiltIn ? '' : ' [custom]';
|
|
621
|
+
return ` ${star}${dot} ${t.label}${tag}${isPrev ? ' (playing)' : ''}`;
|
|
622
|
+
});
|
|
623
|
+
}
|
|
624
|
+
|
|
625
|
+
function refreshDisplay() {
|
|
626
|
+
_refreshing = true;
|
|
627
|
+
const savedIdx = trackList.selected ?? 0;
|
|
628
|
+
|
|
629
|
+
_allTracks = _buildAllTracks();
|
|
630
|
+
const { enabled, track: activeTrackId } = _getMusic(configService);
|
|
631
|
+
const favorites = getMusicFavorites(configService);
|
|
632
|
+
const visible = _getVisibleTracks();
|
|
633
|
+
const items = _buildListItems(visible, activeTrackId, favorites);
|
|
634
|
+
|
|
635
|
+
const activeTrack = _allTracks.find(t => t.id === activeTrackId);
|
|
636
|
+
const activeLabel = (activeTrack?.label ?? formatTrackLabel(activeTrackId ?? '')) || 'None';
|
|
637
|
+
|
|
638
|
+
trackList.setItems(items.length > 0 ? items : [' (no tracks match filter)']);
|
|
639
|
+
// Restore selection (setItems resets to 0)
|
|
640
|
+
const maxIdx = Math.max(0, (items.length > 0 ? items.length : 1) - 1);
|
|
641
|
+
trackList.select(Math.min(savedIdx, maxIdx));
|
|
642
|
+
|
|
643
|
+
// Re-apply inline hint if list is focused
|
|
644
|
+
if (_listFocused) {
|
|
645
|
+
_hintIdx = -1;
|
|
646
|
+
_hintBase = '';
|
|
647
|
+
_updateHint(trackList.selected ?? 0);
|
|
648
|
+
}
|
|
649
|
+
|
|
650
|
+
statusLine.setContent(
|
|
651
|
+
` ${_tl('musicStatusLabel')} ${formatMusicStatus(enabled)} | ${_tl('musicActiveTrack')} ${activeLabel} | ${_tl('musicFilterLabel')} ${_showFavoritesOnly ? _tl('musicFilterFavs') : _tl('musicFilterAll')}`
|
|
652
|
+
);
|
|
653
|
+
|
|
654
|
+
// Update "Currently Selected" header
|
|
655
|
+
activeTrackText.setContent(`{${COLORS.activeFg}-fg}✓ ${activeLabel}{/${COLORS.activeFg}-fg}`);
|
|
656
|
+
|
|
657
|
+
_refreshing = false;
|
|
658
|
+
if (typeof updateHeaderStatus === 'function') updateHeaderStatus();
|
|
659
|
+
screen.render();
|
|
660
|
+
}
|
|
661
|
+
|
|
662
|
+
// -------------------------------------------------------------------------
|
|
663
|
+
// Key bindings on trackList
|
|
664
|
+
|
|
665
|
+
// [Enter] → open save modal for selected track
|
|
666
|
+
trackList.key(['enter'], () => {
|
|
667
|
+
const trackId = _getSelectedTrackId();
|
|
668
|
+
if (!trackId) return;
|
|
669
|
+
const label = _allTracks.find(t => t.id === trackId)?.label ?? formatTrackLabel(trackId);
|
|
670
|
+
_openSaveModal(trackId, label);
|
|
671
|
+
});
|
|
672
|
+
|
|
673
|
+
/**
|
|
674
|
+
* Save-track modal: Save Locally | Save Globally & Locally | Cancel | Preview
|
|
675
|
+
*/
|
|
676
|
+
function _openSaveModal(trackId, displayName) {
|
|
677
|
+
const modal = blessed.box({
|
|
678
|
+
parent: screen,
|
|
679
|
+
top: 'center',
|
|
680
|
+
left: 'center',
|
|
681
|
+
width: 72,
|
|
682
|
+
height: 8,
|
|
683
|
+
border: { type: 'line' },
|
|
684
|
+
tags: true,
|
|
685
|
+
label: ` {${COLORS.activeFg}-fg}Set Background Track{/${COLORS.activeFg}-fg} `,
|
|
686
|
+
style: { border: { fg: COLORS.btnFocus }, bg: COLORS.contentBg },
|
|
687
|
+
});
|
|
688
|
+
|
|
689
|
+
blessed.text({
|
|
690
|
+
parent: modal,
|
|
691
|
+
top: 1,
|
|
692
|
+
left: 2,
|
|
693
|
+
right: 2,
|
|
694
|
+
content: `Set {${COLORS.valueFg}-fg}${displayName}{/${COLORS.valueFg}-fg} as your background track?`,
|
|
695
|
+
tags: true,
|
|
696
|
+
style: { bg: COLORS.contentBg },
|
|
697
|
+
});
|
|
698
|
+
|
|
699
|
+
const modalStatus = blessed.text({
|
|
700
|
+
parent: modal,
|
|
701
|
+
top: 3,
|
|
702
|
+
left: 2,
|
|
703
|
+
right: 2,
|
|
704
|
+
tags: true,
|
|
705
|
+
content: `{${COLORS.dimFg}-fg}Press Preview to audition this track{/${COLORS.dimFg}-fg}`,
|
|
706
|
+
style: { bg: COLORS.contentBg },
|
|
707
|
+
});
|
|
708
|
+
|
|
709
|
+
function _close() {
|
|
710
|
+
_killPlayingProcess();
|
|
711
|
+
_playingTrackId = null;
|
|
712
|
+
previewLine.setContent(_listFocused ? _hintText() : '');
|
|
713
|
+
modal.destroy();
|
|
714
|
+
trackList.focus();
|
|
715
|
+
screen.render();
|
|
716
|
+
}
|
|
717
|
+
|
|
718
|
+
function _makeBtn(lbl, bg, left, top, onClick) {
|
|
719
|
+
const btn = blessed.button({
|
|
720
|
+
parent: modal,
|
|
721
|
+
content: lbl,
|
|
722
|
+
top,
|
|
723
|
+
left,
|
|
724
|
+
mouse: true,
|
|
725
|
+
keys: true,
|
|
726
|
+
shrink: true,
|
|
727
|
+
padding: { left: 1, right: 1 },
|
|
728
|
+
style: {
|
|
729
|
+
bg,
|
|
730
|
+
fg: 'white',
|
|
731
|
+
focus: { bg: COLORS.btnFocus, fg: COLORS.btnFocusFg, bold: true },
|
|
732
|
+
hover: { bg: COLORS.btnFocus, fg: COLORS.btnFocusFg, bold: true },
|
|
733
|
+
},
|
|
734
|
+
});
|
|
735
|
+
btn.key(['enter', 'space'], () => { _close(); onClick(); });
|
|
736
|
+
btn.on('click', () => btn.press());
|
|
737
|
+
return btn;
|
|
738
|
+
}
|
|
739
|
+
|
|
740
|
+
function _saveLocally() {
|
|
741
|
+
_setMusic(configService, { track: trackId });
|
|
742
|
+
applyTrackToAudioEffects(trackId);
|
|
743
|
+
refreshDisplay();
|
|
744
|
+
_showTrackChangedNotice(displayName);
|
|
745
|
+
}
|
|
746
|
+
|
|
747
|
+
function _saveGlobally() {
|
|
748
|
+
configService.setGlobal('backgroundMusic', { track: trackId });
|
|
749
|
+
}
|
|
750
|
+
|
|
751
|
+
const okLocalBtn = _makeBtn('Save Locally', COLORS.btnDefault, 2, 5, () => {
|
|
752
|
+
_saveLocally();
|
|
753
|
+
});
|
|
754
|
+
const okGlobalBtn = _makeBtn('Save Globally & Locally', '#1565c0', 18, 5, () => {
|
|
755
|
+
_saveLocally();
|
|
756
|
+
_saveGlobally();
|
|
757
|
+
});
|
|
758
|
+
const cancelBtn = _makeBtn('Cancel', '#546e7a', 46, 5, () => {});
|
|
759
|
+
|
|
760
|
+
// Preview button — does NOT close the modal; plays/stops the track inline
|
|
761
|
+
const previewBtn = blessed.button({
|
|
762
|
+
parent: modal,
|
|
763
|
+
content: 'Preview',
|
|
764
|
+
top: 5,
|
|
765
|
+
left: 58,
|
|
766
|
+
mouse: true,
|
|
767
|
+
keys: true,
|
|
768
|
+
shrink: true,
|
|
769
|
+
padding: { left: 1, right: 1 },
|
|
770
|
+
style: {
|
|
771
|
+
bg: '#e65100',
|
|
772
|
+
fg: 'white',
|
|
773
|
+
focus: { bg: COLORS.btnFocus, fg: COLORS.btnFocusFg, bold: true },
|
|
774
|
+
hover: { bg: COLORS.btnFocus, fg: COLORS.btnFocusFg, bold: true },
|
|
775
|
+
},
|
|
776
|
+
});
|
|
777
|
+
previewBtn.key(['enter', 'space'], () => {
|
|
778
|
+
const isPlaying = _playingTrackId === trackId;
|
|
779
|
+
_playTrack(trackId);
|
|
780
|
+
modalStatus.setContent(isPlaying
|
|
781
|
+
? `{${COLORS.dimFg}-fg}Stopped.{/${COLORS.dimFg}-fg}`
|
|
782
|
+
: `{${COLORS.playingFg}-fg}♪ Playing: ${displayName}…{/${COLORS.playingFg}-fg}`
|
|
783
|
+
);
|
|
784
|
+
screen.render();
|
|
785
|
+
});
|
|
786
|
+
previewBtn.on('click', () => previewBtn.press());
|
|
787
|
+
|
|
788
|
+
// Tab/arrow navigation: SaveLocal → SaveGlobal → Cancel → Preview → SaveLocal
|
|
789
|
+
okLocalBtn.key(['tab', 'right'], () => { okGlobalBtn.focus(); screen.render(); });
|
|
790
|
+
okGlobalBtn.key(['tab', 'right'], () => { cancelBtn.focus(); screen.render(); });
|
|
791
|
+
cancelBtn.key(['tab', 'right'], () => { previewBtn.focus(); screen.render(); });
|
|
792
|
+
previewBtn.key(['tab', 'right'], () => { okLocalBtn.focus(); screen.render(); });
|
|
793
|
+
previewBtn.key(['left'], () => { cancelBtn.focus(); screen.render(); });
|
|
794
|
+
cancelBtn.key(['left'], () => { okGlobalBtn.focus(); screen.render(); });
|
|
795
|
+
okGlobalBtn.key(['left'], () => { okLocalBtn.focus(); screen.render(); });
|
|
796
|
+
okLocalBtn.key(['left'], () => { previewBtn.focus(); screen.render(); });
|
|
797
|
+
|
|
798
|
+
modal.key(['escape', 'q'], _close);
|
|
799
|
+
|
|
800
|
+
modal.setFront();
|
|
801
|
+
okLocalBtn.focus();
|
|
802
|
+
screen.render();
|
|
803
|
+
}
|
|
804
|
+
|
|
805
|
+
function _showTrackChangedNotice(displayName) {
|
|
806
|
+
const notice = blessed.box({
|
|
807
|
+
parent: screen,
|
|
808
|
+
top: 'center',
|
|
809
|
+
left: 'center',
|
|
810
|
+
width: 50,
|
|
811
|
+
height: 5,
|
|
812
|
+
border: { type: 'line' },
|
|
813
|
+
tags: true,
|
|
814
|
+
label: ` {${COLORS.activeFg}-fg}Done{/${COLORS.activeFg}-fg} `,
|
|
815
|
+
style: { border: { fg: COLORS.btnFocus }, bg: COLORS.contentBg },
|
|
816
|
+
content: `\n {${COLORS.activeFg}-fg}✓ Track set: ${displayName}{/${COLORS.activeFg}-fg}`,
|
|
817
|
+
});
|
|
818
|
+
notice.setFront();
|
|
819
|
+
screen.render();
|
|
820
|
+
let noticeDestroyed = false;
|
|
821
|
+
setTimeout(() => { if (!noticeDestroyed) { notice.destroy(); noticeDestroyed = true; screen.render(); } }, 2000);
|
|
822
|
+
}
|
|
823
|
+
|
|
824
|
+
// [Space] → preview/stop track (toggle)
|
|
825
|
+
trackList.key(['space'], () => {
|
|
826
|
+
const trackId = _getSelectedTrackId();
|
|
827
|
+
if (trackId) {
|
|
828
|
+
_playTrack(trackId);
|
|
829
|
+
refreshDisplay();
|
|
830
|
+
}
|
|
831
|
+
});
|
|
832
|
+
|
|
833
|
+
// [m/M] → toggle music enabled in config
|
|
834
|
+
trackList.key(['m', 'M'], () => {
|
|
835
|
+
const { enabled } = _getMusic(configService);
|
|
836
|
+
_setMusic(configService, { enabled: !enabled });
|
|
837
|
+
refreshDisplay();
|
|
838
|
+
});
|
|
839
|
+
|
|
840
|
+
// [*] → toggle favorite
|
|
841
|
+
trackList.key(['*'], () => {
|
|
842
|
+
const trackId = _getSelectedTrackId();
|
|
843
|
+
if (trackId) {
|
|
844
|
+
toggleMusicFavorite(configService, trackId);
|
|
845
|
+
refreshDisplay();
|
|
846
|
+
}
|
|
847
|
+
});
|
|
848
|
+
|
|
849
|
+
// [f/F] → toggle favorites filter
|
|
850
|
+
trackList.key(['f', 'F'], () => {
|
|
851
|
+
_showFavoritesOnly = !_showFavoritesOnly;
|
|
852
|
+
refreshDisplay();
|
|
853
|
+
});
|
|
854
|
+
|
|
855
|
+
// [↑] at top of list → jump to main header tab bar
|
|
856
|
+
trackList.key(['up'], () => {
|
|
857
|
+
if (trackList.selected === 0 && typeof focusMainTabBar === 'function') {
|
|
858
|
+
focusMainTabBar();
|
|
859
|
+
setTimeout(() => { trackList.select(0); screen.render(); }, 0);
|
|
860
|
+
}
|
|
861
|
+
});
|
|
862
|
+
|
|
863
|
+
// Escape at the list level → return to header tab bar
|
|
864
|
+
trackList.key(['escape'], () => {
|
|
865
|
+
if (typeof focusMainTabBar === 'function') { focusMainTabBar(); screen.render(); }
|
|
866
|
+
});
|
|
867
|
+
|
|
868
|
+
// ↓ at the last item → descend into the button row (Toggle Music gets focus first)
|
|
869
|
+
// Note: Tab is NOT used here — navigation.js registers screen.key(['tab']) to cycle tabs,
|
|
870
|
+
// so element.key(['tab']) + screen.key(['tab']) both fire, causing a simultaneous tab-cycle.
|
|
871
|
+
trackList.key(['down'], () => {
|
|
872
|
+
const visible = _getVisibleTracks();
|
|
873
|
+
if (trackList.selected >= visible.length - 1) {
|
|
874
|
+
toggleBtn.focus();
|
|
875
|
+
screen.render();
|
|
876
|
+
}
|
|
877
|
+
});
|
|
878
|
+
|
|
879
|
+
// ←/→ navigate between the two buttons
|
|
880
|
+
toggleBtn.key(['right'], () => { addCustomTrackBtn.focus(); screen.render(); });
|
|
881
|
+
addCustomTrackBtn.key(['right'], () => { toggleBtn.focus(); screen.render(); });
|
|
882
|
+
toggleBtn.key(['left'], () => { addCustomTrackBtn.focus(); screen.render(); });
|
|
883
|
+
addCustomTrackBtn.key(['left'], () => { toggleBtn.focus(); screen.render(); });
|
|
884
|
+
|
|
885
|
+
// ↑ or Escape from any button → back to track list
|
|
886
|
+
toggleBtn.key(['up', 'escape'], () => { trackList.focus(); screen.render(); });
|
|
887
|
+
addCustomTrackBtn.key(['up', 'escape'], () => { trackList.focus(); screen.render(); });
|
|
888
|
+
|
|
889
|
+
// Blinking █ on selected row while list is focused
|
|
890
|
+
let _tlBlink = { interval: null, on: false, sel: -1 };
|
|
891
|
+
process.on('exit', () => { if (_tlBlink.interval) clearInterval(_tlBlink.interval); });
|
|
892
|
+
function _tlTick() {
|
|
893
|
+
_tlBlink.on = !_tlBlink.on;
|
|
894
|
+
const items = trackList.items;
|
|
895
|
+
const cur = trackList.selected ?? 0;
|
|
896
|
+
if (_tlBlink.sel !== cur && _tlBlink.sel >= 0 && items[_tlBlink.sel]) {
|
|
897
|
+
items[_tlBlink.sel].setContent((items[_tlBlink.sel].content ?? '').replace(/ █$/, ''));
|
|
898
|
+
}
|
|
899
|
+
_tlBlink.sel = cur;
|
|
900
|
+
if (items[cur]) {
|
|
901
|
+
const base = (items[cur].content ?? '').replace(/ █$/, '');
|
|
902
|
+
items[cur].setContent(_tlBlink.on ? `${base} █` : base);
|
|
903
|
+
}
|
|
904
|
+
screen.render();
|
|
905
|
+
}
|
|
906
|
+
trackList.on('focus', () => {
|
|
907
|
+
_listFocused = true;
|
|
908
|
+
_tlBlink.on = true;
|
|
909
|
+
_tlBlink.sel = trackList.selected ?? 0;
|
|
910
|
+
_hintIdx = -1;
|
|
911
|
+
_hintBase = '';
|
|
912
|
+
_updateHint(_tlBlink.sel);
|
|
913
|
+
const items = trackList.items;
|
|
914
|
+
if (items[_tlBlink.sel]) items[_tlBlink.sel].setContent((items[_tlBlink.sel].content ?? '') + ' █');
|
|
915
|
+
if (!_playingTrackId) previewLine.setContent(_hintText());
|
|
916
|
+
screen.render();
|
|
917
|
+
_tlBlink.interval = setInterval(_tlTick, 500);
|
|
918
|
+
});
|
|
919
|
+
trackList.on('blur', () => {
|
|
920
|
+
_listFocused = false;
|
|
921
|
+
if (!_playingTrackId) previewLine.setContent('');
|
|
922
|
+
if (_tlBlink.interval) { clearInterval(_tlBlink.interval); _tlBlink.interval = null; }
|
|
923
|
+
const items = trackList.items;
|
|
924
|
+
const sel = trackList.selected ?? 0;
|
|
925
|
+
if (items[sel]) {
|
|
926
|
+
// Restore the hinted item to its clean base; for non-hinted items just strip █
|
|
927
|
+
items[sel].setContent(sel === _hintIdx ? _hintBase : (items[sel].content ?? '').replace(/ █$/, ''));
|
|
928
|
+
}
|
|
929
|
+
if (_hintIdx >= 0 && _hintIdx !== sel && items[_hintIdx]) {
|
|
930
|
+
items[_hintIdx].setContent(_hintBase);
|
|
931
|
+
}
|
|
932
|
+
_hintIdx = -1;
|
|
933
|
+
_hintBase = '';
|
|
934
|
+
screen.render();
|
|
935
|
+
});
|
|
936
|
+
|
|
937
|
+
// Refresh status text on cursor movement
|
|
938
|
+
trackList.on('select item', () => {
|
|
939
|
+
if (_refreshing) return;
|
|
940
|
+
_updateHint(trackList.selected ?? 0);
|
|
941
|
+
if (_tlBlink.interval) _tlTick(); // move █ to newly selected row
|
|
942
|
+
const { enabled, track: activeTrackId } = _getMusic(configService);
|
|
943
|
+
const activeTrack = _allTracks.find(t => t.id === activeTrackId);
|
|
944
|
+
const activeLabel = (activeTrack?.label ?? formatTrackLabel(activeTrackId ?? '')) || 'None';
|
|
945
|
+
statusLine.setContent(
|
|
946
|
+
` ${_tl('musicStatusLabel')} ${formatMusicStatus(enabled)} | ${_tl('musicActiveTrack')} ${activeLabel} | ${_tl('musicFilterLabel')} ${_showFavoritesOnly ? _tl('musicFilterFavs') : _tl('musicFilterAll')}`
|
|
947
|
+
);
|
|
948
|
+
screen.render();
|
|
949
|
+
});
|
|
950
|
+
|
|
951
|
+
// Type-to-jump: press a letter to jump to first track whose label starts with it
|
|
952
|
+
const _trackJumpBlocked = new Set(['j', 'k', 'g', 'h', 'l', 'd', 'u', 'm', 'f']);
|
|
953
|
+
trackList.on('keypress', (ch, key) => {
|
|
954
|
+
if (!ch || key.ctrl || key.meta) return;
|
|
955
|
+
const lower = ch.toLowerCase();
|
|
956
|
+
if (!/^[a-z]$/.test(lower)) return;
|
|
957
|
+
if (_trackJumpBlocked.has(lower)) return;
|
|
958
|
+
const tracks = _getVisibleTracks();
|
|
959
|
+
const count = tracks.length;
|
|
960
|
+
if (count === 0) return;
|
|
961
|
+
const start = trackList.selected ?? 0;
|
|
962
|
+
for (let i = 1; i <= count; i++) {
|
|
963
|
+
const idx = (start + i) % count;
|
|
964
|
+
// Strip leading emoji/symbols to get first letter of track name
|
|
965
|
+
const firstLetter = tracks[idx].label.replace(/^[^a-zA-Z]*/, '')[0]?.toLowerCase() ?? '';
|
|
966
|
+
if (firstLetter === lower) {
|
|
967
|
+
trackList.select(idx);
|
|
968
|
+
screen.render();
|
|
969
|
+
break;
|
|
970
|
+
}
|
|
971
|
+
}
|
|
972
|
+
});
|
|
973
|
+
|
|
974
|
+
// -------------------------------------------------------------------------
|
|
975
|
+
// -------------------------------------------------------------------------
|
|
976
|
+
// Language refresh
|
|
977
|
+
|
|
978
|
+
function refreshMusicLabels() {
|
|
979
|
+
builtInHdr.setContent(`{${COLORS.sectionHdr}-fg}${_tl('musicBuiltInHeader')}${'─'.repeat(48)}{/${COLORS.sectionHdr}-fg}`);
|
|
980
|
+
musicStatusHdr.setContent(`{${COLORS.sectionHdr}-fg}${_tl('musicStatusHeader')}${'─'.repeat(52)}{/${COLORS.sectionHdr}-fg}`);
|
|
981
|
+
toggleBtn.setContent(_tl('musicToggleBtn'));
|
|
982
|
+
addCustomTrackBtn.setContent(_tl('musicAddCustomBtn'));
|
|
983
|
+
refreshDisplay();
|
|
984
|
+
}
|
|
985
|
+
|
|
986
|
+
if (languageService) {
|
|
987
|
+
languageService.onChange(() => { refreshMusicLabels(); screen.render(); });
|
|
988
|
+
}
|
|
989
|
+
|
|
990
|
+
// Tab Component Contract
|
|
991
|
+
|
|
992
|
+
return {
|
|
993
|
+
box,
|
|
994
|
+
|
|
995
|
+
show() {
|
|
996
|
+
box.show();
|
|
997
|
+
refreshDisplay();
|
|
998
|
+
screen.render();
|
|
999
|
+
},
|
|
1000
|
+
|
|
1001
|
+
hide() {
|
|
1002
|
+
// Stop any preview when leaving the tab
|
|
1003
|
+
_killPlayingProcess();
|
|
1004
|
+
_playingTrackId = null;
|
|
1005
|
+
previewLine.setContent('');
|
|
1006
|
+
box.hide();
|
|
1007
|
+
screen.render();
|
|
1008
|
+
},
|
|
1009
|
+
|
|
1010
|
+
onFocus() {
|
|
1011
|
+
trackList.focus();
|
|
1012
|
+
screen.render();
|
|
1013
|
+
},
|
|
1014
|
+
|
|
1015
|
+
onBlur() {
|
|
1016
|
+
// Stop preview when focus leaves Music tab
|
|
1017
|
+
_killPlayingProcess();
|
|
1018
|
+
_playingTrackId = null;
|
|
1019
|
+
},
|
|
1020
|
+
|
|
1021
|
+
getFooterText() {
|
|
1022
|
+
return _tl('musicFooter');
|
|
1023
|
+
},
|
|
1024
|
+
|
|
1025
|
+
getFooterColor() {
|
|
1026
|
+
return COLORS.footerBg;
|
|
1027
|
+
},
|
|
1028
|
+
};
|
|
1029
|
+
|
|
1030
|
+
}
|