-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathcodec_vibe.html
More file actions
1296 lines (1210 loc) · 75.6 KB
/
codec_vibe.html
File metadata and controls
1296 lines (1210 loc) · 75.6 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
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
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
433
434
435
436
437
438
439
440
441
442
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
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
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
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
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
752
753
754
755
756
757
758
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
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
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
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
955
956
957
958
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>CODEC Vibe Code</title>
<link rel="icon" href="https://i.imgur.com/jD1X5W8.png">
<link rel="apple-touch-icon" href="https://i.imgur.com/jD1X5W8.png">
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&family=JetBrains+Mono:wght@400;500;600&display=swap" rel="stylesheet">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/monaco-editor/0.45.0/min/vs/editor/editor.main.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/dompurify/3.0.8/purify.min.js"></script>
<style>
:root {
--bg: #121215; --surface: #1a1a1d; --surface-2: #212125; --surface-3: #2a2a2e;
--border: #303035; --border-hover: #424248;
--text: #ececec; --text-muted: #9a9aa0; --text-dim: #6a6a70;
--accent: #E8711A; --accent-hover: #f07d2a; --accent-dim: rgba(232,113,26,0.10);
--danger: #ef4444; --success: #22c55e; --info: #3b82f6;
--font: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
--mono: 'JetBrains Mono', 'SF Mono', monospace;
--radius: 8px; --radius-sm: 6px;
--bg2: #1a1a1d; --bg3: #212125; --bg4: #2a2a2e;
--fg: #ececec; --fg2: #9a9aa0; --fg3: #6a6a70;
--ac: #E8711A; --bd: #303035;
--tx: #ececec; --tx2: #9a9aa0;
--ft: 'Inter', -apple-system, sans-serif;
--mn: 'JetBrains Mono', monospace;
--dn: #ef4444;
--accent2: #ff9a4d; --accent-bg: rgba(232,113,26,0.10);
--safe-top: env(safe-area-inset-top, 0px);
--safe-bottom: env(safe-area-inset-bottom, 0px);
}
[data-theme=light]{--bg:#f7f5f2;--surface:#fff;--surface-2:#f0ece6;--surface-3:#e8e4de;--border:#d5d0ca;--border-hover:#bbb;--text:#1a1a1a;--text-muted:#555;--text-dim:#777;--bg2:#fff;--bg3:#f0ece6;--bg4:#e8e4de;--tx:#1a1a1a;--tx2:#555;--bd:#d5d0ca;--fg:#1a1a1a;--fg2:#555;--fg3:#777}
*{margin:0;padding:0;box-sizing:border-box}
html{background:var(--bg)}
body{font-family:var(--ft);background:var(--bg);color:var(--tx);height:100vh;height:100dvh;display:flex;flex-direction:column;overflow:hidden;padding-bottom:env(safe-area-inset-bottom, 0px)}
.bar{display:flex;align-items:center;justify-content:space-between;padding:8px 16px;background:var(--bg2);border-bottom:1px solid var(--bd);height:48px;flex-shrink:0;position:relative}
.bar-l{display:flex;align-items:center;gap:12px}
.bb{padding:4px 12px;border:1px solid var(--bd);border-radius:6px;background:0;color:var(--tx2);cursor:pointer;font-size:12px;text-decoration:none;transition:all 0.2s ease}
.bb:hover{border-color:var(--ac);color:var(--ac)}
.fi{background:var(--bg3);border:1px solid var(--bd);border-radius:4px;padding:2px 8px;color:var(--tx);font-size:12px;font-family:var(--mn);width:180px}
.ls{background:var(--bg3);color:var(--tx);border:1px solid var(--bd);border-radius:4px;padding:2px 8px;font-size:11px}
.sp{display:flex;flex:1;overflow:hidden}
.cp{order:-1;width:420px;min-width:280px;display:flex;flex-direction:column;border-right:1px solid var(--bd)}
.ep{order:1;flex:1;display:flex;flex-direction:column;min-width:0}
.pp{display:none;order:2;flex:1;flex-direction:column;border-left:1px solid var(--bd)}.pp.sh{display:flex}
.ph{display:flex;align-items:center;justify-content:space-between;padding:6px 12px;background:var(--bg2);border-bottom:1px solid var(--bd)}
.ph span{font-size:12px;color:var(--ac);font-family:var(--mn);font-weight:600}
#pf{flex:1;border:none;background:#fff}
#eb{flex:1}
.tb{display:flex;align-items:center;gap:4px;padding:8px 12px;background:var(--bg2);border-top:1px solid var(--bd);flex-shrink:0;flex-wrap:wrap;min-height:54px}
.bt{padding:8px 12px;border:1px solid var(--border);border-radius:6px;cursor:pointer;font-size:12px;font-weight:600;transition:all .15s;font-family:var(--ft);background:var(--surface-2);color:var(--text-muted);white-space:nowrap;display:inline-flex;align-items:center;gap:5px;height:36px}
.bt .ico-sm{width:14px;height:14px}
.bt:hover{border-color:var(--border-hover);color:var(--text);background:var(--surface-3)}.bt:active{transform:scale(.96)}
.bt.primary{background:var(--success);color:#fff;border-color:var(--success)}
.bt.primary:hover{opacity:.9}
.bt.accent{background:var(--ac);color:#fff;border-color:var(--ac)}
.bt.accent:hover{opacity:.9}
.bt.forge{background:linear-gradient(135deg,#7c3aed,#5b21b6);color:#fff;border-color:#7c3aed}
.bt.forge:hover{opacity:.9}
.tb-sep{width:1px;height:28px;background:var(--border);flex-shrink:0;margin:0 2px}
.op{height:140px;background:var(--bg);border-top:1px solid var(--bd);font-family:var(--mn);font-size:12px;padding:8px 12px;overflow-y:auto;color:var(--text-muted);white-space:pre-wrap;flex-shrink:0}
.hd{padding:10px 12px;background:var(--bg2);border-bottom:1px solid var(--bd);font-size:14px;font-weight:600;color:var(--ac);font-family:var(--mn)}
.ms{flex:1;overflow-y:auto;padding:12px;position:relative}
.ms::before{content:'';position:absolute;top:50%;left:50%;transform:translate(-50%,-50%);width:120px;height:120px;background:url('https://i.imgur.com/jD1X5W8.png') center/contain no-repeat;opacity:0.07;pointer-events:none;z-index:0}
.ia{display:flex;gap:6px;padding:8px 12px;background:var(--bg2);border-top:1px solid var(--bd);align-items:flex-end;min-height:54px}
.ii{flex:1;background:var(--bg3);border:1px solid var(--bd);border-radius:18px;padding:8px 14px;color:var(--tx);font-size:14px;resize:none;outline:none;min-height:38px;max-height:100px;line-height:1.4;font-family:var(--ft)}
.ii:focus{border-color:var(--ac);box-shadow:0 0 0 2px rgba(232,113,26,0.15)}
.sb{padding:0;width:36px;height:36px;background:var(--ac);color:#fff;border:none;border-radius:50%;cursor:pointer;font-weight:600;display:flex;align-items:center;justify-content:center;flex-shrink:0;transition:all .15s}
.sb:hover{background:var(--accent-hover)}
.vibe-mic{width:36px;height:36px;border-radius:50%;border:1px solid var(--bd);background:none;color:var(--tx2);cursor:pointer;display:flex;align-items:center;justify-content:center;flex-shrink:0;transition:all .15s}
.vibe-mic:hover{border-color:var(--border-hover);color:var(--text)}
.vibe-mic.recording{background:var(--danger);color:#fff;border-color:var(--danger);animation:vibePulse 1s infinite}
@keyframes vibePulse{0%,100%{opacity:1}50%{opacity:.6}}
.mg{margin-bottom:12px;padding:10px 12px;border-radius:10px;font-size:14px;line-height:1.6;word-wrap:break-word}
.mu{background:rgba(232,113,26,0.15);color:var(--tx);border:1px solid rgba(232,113,26,0.25);margin-left:20%;border-bottom-right-radius:3px}
.ma{background:var(--bg2);border:1px solid var(--bd);margin-right:10%;border-bottom-left-radius:3px}
.ma pre{background:var(--bg);padding:8px;border-radius:6px;margin:8px 0;overflow-x:auto;font-family:var(--mn);font-size:12px;border:1px solid var(--bd)}
.ab{display:inline-block;margin-top:6px;padding:5px 12px;background:var(--ac);color:#fff;border:none;border-radius:5px;cursor:pointer;font-size:11px;font-weight:600}
.ov{display:none;position:fixed;inset:0;background:rgba(0,0,0,.6);z-index:20}.ov.sh{display:block}
.sd{position:fixed;top:0;left:-280px;width:280px;height:100%;background:var(--bg2);border-right:1px solid var(--bd);z-index:30;transition:left .25s;overflow-y:auto}.sd.sh{left:0}
.si{padding:10px 16px;border-bottom:1px solid var(--bd);cursor:pointer}.si:hover{background:var(--bg3)}
.rs{font-size:11px;color:var(--tx2);margin-left:auto;font-family:var(--mn)}
@keyframes bn{0%,80%,100%{transform:translateY(0)}40%{transform:translateY(-8px)}}
/* ── Page Nav ── */
.page-nav { display: flex; align-items: center; gap: 1px; position: absolute; left: 50%; transform: translateX(-50%); background: var(--surface-2); border-radius: var(--radius-sm); padding: 2px; }
.nav-link {
padding: 5px 14px; color: var(--text-muted); text-decoration: none;
font-size: 12px; font-weight: 500; border-radius: 4px;
transition: all 0.15s ease; white-space: nowrap; text-align: center;
}
.nav-link:hover { color: var(--text); }
.nav-link.active { color: var(--accent); background: var(--accent-dim); }
/* ── Scrollbar ── */
* { scrollbar-width: thin; scrollbar-color: var(--border) transparent; }
::-webkit-scrollbar { width: 4px; height: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }
/* ── Forge Modal ── */
.fm-overlay{display:none;position:fixed;inset:0;background:rgba(0,0,0,.7);z-index:50;align-items:center;justify-content:center}.fm-overlay.sh{display:flex}
.fm-box{background:var(--surface);border:1px solid var(--border);border-radius:12px;width:520px;max-width:95vw;max-height:90vh;overflow:hidden;display:flex;flex-direction:column;box-shadow:0 8px 40px rgba(0,0,0,.6)}
.fm-head{display:flex;align-items:center;justify-content:space-between;padding:16px 20px;border-bottom:1px solid var(--border)}
.fm-head h2{font-family:var(--mono);font-size:15px;color:var(--accent);font-weight:700}
.fm-close{background:none;border:none;color:var(--text-muted);font-size:20px;cursor:pointer;width:28px;height:28px;display:flex;align-items:center;justify-content:center;border-radius:4px}
.fm-close:hover{color:var(--text);background:var(--surface-2)}
.fm-tabs{display:flex;border-bottom:1px solid var(--border);padding:0 20px;gap:4px}
.fm-tab{padding:10px 14px;font-size:12px;font-weight:600;color:var(--text-muted);background:none;border:none;cursor:pointer;border-bottom:2px solid transparent;transition:all .2s;font-family:var(--font)}
.fm-tab.active{color:var(--accent);border-bottom-color:var(--accent)}
.fm-tab:hover{color:var(--text)}
.fm-body{padding:20px;display:flex;flex-direction:column;gap:12px;flex:1}
.fm-label{font-size:11px;font-weight:600;color:var(--text-muted);letter-spacing:.05em;text-transform:uppercase;margin-bottom:4px}
.fm-ta{width:100%;height:180px;background:var(--surface-2);border:1px solid var(--border);border-radius:6px;padding:12px;color:var(--text);font-family:var(--mono);font-size:12px;resize:vertical;outline:none;line-height:1.5}
.fm-ta:focus{border-color:var(--accent);box-shadow:0 0 0 2px rgba(232,113,26,.15)}
.fm-input{width:100%;background:var(--surface-2);border:1px solid var(--border);border-radius:6px;padding:10px 14px;color:var(--text);font-family:var(--mono);font-size:13px;outline:none}
.fm-input:focus{border-color:var(--accent);box-shadow:0 0 0 2px rgba(232,113,26,.15)}
.fm-hint{font-size:11px;color:var(--text-muted);margin-top:2px}
.fm-foot{display:flex;align-items:center;gap:10px;padding:14px 20px;border-top:1px solid var(--border);background:var(--surface)}
.fm-forge{padding:9px 20px;background:linear-gradient(135deg,#7c3aed,#5b21b6);color:#fff;border:none;border-radius:6px;font-size:13px;font-weight:700;cursor:pointer;transition:opacity .2s;font-family:var(--font)}
.fm-forge:hover{opacity:.9}
.fm-forge:disabled{opacity:.5;cursor:not-allowed}
.fm-status{font-size:12px;color:var(--text-muted);font-family:var(--mono)}
.fm-panel{display:none}.fm-panel.active{display:block}
/* ── Inspect Mode ── */
#inspectBtn.active {
background: #E8711A !important;
color: #000 !important;
box-shadow: 0 0 8px rgba(232,113,26,0.4);
}
/* ── Light mode extra overrides ── */
[data-theme=light] .icon-btn{border-color:#bbb;color:#444}
[data-theme=light] .icon-btn:hover{border-color:#999;color:#1a1a1a;background:#e8e4de}
[data-theme=light] .nav-link.active{color:var(--accent);background:var(--accent-dim)}
[data-theme=light] .mu{background:rgba(232,113,26,0.10);color:var(--tx);border:1px solid rgba(232,113,26,0.20)}
[data-theme=light] .op{background:#f0ece6;color:#555}
/* ── Mobile Responsive ── */
@media (max-width:768px){
.page-nav{position:fixed;bottom:0;left:0;right:0;z-index:9998;transform:none;border-radius:0;padding:6px 0;justify-content:center;background:var(--surface);border-top:1px solid var(--bd);gap:0}
.nav-link{padding:8px 12px;font-size:11px}
.sp{flex-direction:column}
.cp{width:100%;min-width:0;border-right:none;border-bottom:1px solid var(--bd);max-height:50vh}
.ep{width:100%;min-width:0}
.pp{width:100%;border-left:none;border-top:1px solid var(--bd)}
#rh{display:none}
.tb{flex-wrap:wrap;gap:6px}
.bar{flex-wrap:wrap;gap:6px;height:auto;padding:8px 12px}
.bar-l{flex-wrap:wrap}
.fi{width:120px}
.op{height:100px}
}
@media (max-width:480px){
.cp{max-height:40vh}
.bar{padding:6px 10px}
.bt{padding:5px 8px;font-size:11px}
.fi{width:100px}
}
.header{display:flex;align-items:center;justify-content:space-between;padding:10px 16px;border-bottom:1px solid var(--border);background:var(--surface);flex-shrink:0;position:relative;z-index:10}
.header-left{display:flex;align-items:center;gap:10px}
.logo-link{display:flex;align-items:center;text-decoration:none}
.header img{width:34px;height:34px;border-radius:8px}
.header h1{font-family:var(--mono);font-size:16px;font-weight:700;letter-spacing:2px;color:var(--accent)}
.header-right{display:flex;align-items:center;gap:6px}
.icon-btn{background:none;border:1px solid var(--border);color:var(--text-muted);width:30px;height:30px;border-radius:6px;cursor:pointer;display:flex;align-items:center;justify-content:center;transition:all .15s;text-decoration:none}
.icon-btn:hover{border-color:var(--border-hover);color:var(--text);background:var(--surface-2)}
.icon-btn:active{transform:scale(0.93)}
.status-dot{width:7px;height:7px;border-radius:50%;background:var(--danger);flex-shrink:0;transition:all .3s}
.status-dot.on{background:var(--success);box-shadow:0 0 6px rgba(34,197,94,0.5)}
.ico{width:18px;height:18px;stroke:currentColor;fill:none;stroke-width:2;stroke-linecap:round;stroke-linejoin:round}
.ico-sm{width:16px;height:16px}
.vibe-toolbar{height:auto;min-height:42px}
.notif-bell{position:relative}.notif-badge{position:absolute;top:-4px;right:-4px;min-width:16px;height:16px;background:var(--accent);color:#fff;font-size:10px;font-weight:700;border-radius:8px;display:flex;align-items:center;justify-content:center;padding:0 4px;line-height:1;pointer-events:none}.notif-badge.hidden{display:none}
.webcam-pip{position:fixed;bottom:80px;right:20px;width:240px;border-radius:14px;overflow:hidden;border:2px solid var(--accent);box-shadow:0 4px 24px rgba(0,0,0,.5);z-index:9999;display:none;background:#000;transition:width .3s,height .3s,border-radius .3s}
.webcam-pip img,.webcam-pip video{width:100%;display:block}
.webcam-pip.expanded{width:640px;max-width:90vw;border-radius:10px}
.pip-bar{display:flex;justify-content:center;gap:10px;padding:6px;background:rgba(0,0,0,.6)}
.pip-btn{background:rgba(255,255,255,.15);border:none;color:#fff;width:34px;height:34px;border-radius:50%;cursor:pointer;display:flex;align-items:center;justify-content:center;transition:background .15s}
.pip-btn:hover{background:var(--accent)}
.pip-btn.snap-btn{background:rgba(255,80,80,.7)}
.pip-btn.snap-btn:hover{background:#e33}
/* ── Screenshot/Photo Modal ── */
.modal-overlay { display:none; position:fixed; top:0; left:0; right:0; bottom:0; background:rgba(0,0,0,0.85); z-index:100; justify-content:center; align-items:center; padding:20px; }
.modal-overlay.show { display:flex; }
.modal-overlay img { max-width:100%; max-height:90vh; border-radius:var(--radius); border:1px solid var(--border); }
.modal-close { position:fixed; top:16px; right:16px; background:var(--surface); color:var(--text); border:1px solid var(--border); width:32px; height:32px; border-radius:50%; font-size:18px; cursor:pointer; z-index:101; display:flex; align-items:center; justify-content:center; }
</style>
</head>
<body>
<!-- ── Forge Modal ── -->
<div class="fm-overlay" id="fmOverlay">
<div class="fm-box">
<div class="fm-head">
<h2>Skill Forge</h2>
<button class="fm-close" onclick="closeForgeModal()">✕</button>
</div>
<div class="fm-tabs">
<button class="fm-tab active" id="ftCode" onclick="setForgeMode('code')">Paste Code</button>
<button class="fm-tab" id="ftUrl" onclick="setForgeMode('url')">GitHub URL</button>
<button class="fm-tab" id="ftDesc" onclick="setForgeMode('describe')">Describe</button>
</div>
<div class="fm-body">
<div class="fm-panel active" id="fmPanelCode">
<div class="fm-label">Paste Python or JavaScript code</div>
<textarea class="fm-ta" id="forgeCodeInput" placeholder="# Paste any code here — Forge will convert it into a CODEC skill # with SKILL_TRIGGERS, run() function, and proper structure"></textarea>
</div>
<div class="fm-panel" id="fmPanelUrl">
<div class="fm-label">Raw file URL</div>
<input class="fm-input" id="forgeUrlInput" type="text" placeholder="https://raw.githubusercontent.com/user/repo/main/script.py">
<div class="fm-hint">Works with any raw .py or .js URL (GitHub, Gist, Pastebin…)</div>
</div>
<div class="fm-panel" id="fmPanelDesc">
<div class="fm-label">Describe what you want</div>
<input class="fm-input" id="forgeDescInput" type="text" placeholder="A skill that checks the Bitcoin price and summarizes it">
<div class="fm-hint">Q will generate the skill from scratch based on your description</div>
</div>
</div>
<div class="fm-foot">
<button class="fm-forge" id="fmForgeBtn" onclick="submitForge()">Forge Skill</button>
<span class="fm-status" id="fmStatus"></span>
</div>
</div>
</div>
<div class="ov" id="ov" onclick="cS()"></div>
<div class="sd" id="sd">
<div style="padding:14px 16px;border-bottom:1px solid var(--bd);display:flex;align-items:center;justify-content:space-between"><h2 style="font-family:var(--mn);font-size:13px;color:var(--ac)">PROJECTS</h2><button onclick="cS()" style="background:0;border:0;color:var(--tx2);font-size:20px;cursor:pointer">×</button></div>
<div style="padding:12px 16px;border-bottom:1px solid var(--bd);cursor:pointer;color:var(--ac);font-weight:600;font-size:13px" onclick="nS()">+ New Project</div>
<div id="sl"></div>
</div>
<div class="header">
<div class="header-left">
<a href="/" class="logo-link"><img src="https://i.imgur.com/jD1X5W8.png" alt="CODEC"></a>
<h1><a href="/" style="color:inherit;text-decoration:none">CODEC</a></h1>
</div>
<nav class="page-nav">
<a href="/chat" class="nav-link">Chat</a>
<a href="/voice" class="nav-link">Voice</a>
<a href="/vibe" class="nav-link active">Vibe</a>
<a href="/tasks" class="nav-link">Tasks</a>
</nav>
<div class="header-right">
<div class="status-dot" id="statusDot" title="CODEC status"></div>
<a href="/" class="icon-btn" title="Dashboard"><svg class="ico" viewBox="0 0 24 24"><path d="M3 9l9-7 9 7v11a2 2 0 01-2 2H5a2 2 0 01-2-2z"/><polyline points="9 22 9 12 15 12 15 22"/></svg></a>
<button class="icon-btn" id="voiceBtn" onclick="toggleVoiceReply()" title="Toggle voice replies"><svg class="ico" viewBox="0 0 24 24"><path d="M11 5L6 9H2v6h4l5 4V5z"/><line x1="23" y1="9" x2="17" y2="15" id="muteX1"/><line x1="17" y1="9" x2="23" y2="15" id="muteX2"/></svg></button>
<button class="icon-btn" onclick="takeScreenshot()" title="Take screenshot"><svg class="ico" viewBox="0 0 24 24"><rect x="2" y="3" width="20" height="14" rx="2"/><line x1="8" y1="21" x2="16" y2="21"/><line x1="12" y1="17" x2="12" y2="21"/></svg></button>
<button class="icon-btn" id="photoBtn" onclick="takeServerPhoto()" title="Photo (Mac webcam)"><svg class="ico" viewBox="0 0 24 24"><path d="M23 19a2 2 0 01-2 2H3a2 2 0 01-2-2V8a2 2 0 012-2h4l2-3h6l2 3h4a2 2 0 012 2z"/><circle cx="12" cy="13" r="4"/></svg></button>
<button class="icon-btn" id="camBtn" onclick="toggleWebcamPip()" title="Live video (Mac webcam)"><svg class="ico" viewBox="0 0 24 24"><polygon points="23 7 16 12 23 17 23 7"/><rect x="1" y="5" width="15" height="14" rx="2"/></svg></button>
<a href="/tasks#reports" class="icon-btn notif-bell" id="notifBellBtn" title="Task reports"><svg class="ico" viewBox="0 0 24 24"><path d="M18 8A6 6 0 006 8c0 7-3 9-3 9h18s-3-2-3-9"/><path d="M13.73 21a2 2 0 01-3.46 0"/></svg><span class="notif-badge hidden" id="notifBadge">0</span></a>
<button class="icon-btn" id="themeBtn" onclick="toggleTheme()" title="Toggle theme"><svg class="ico" viewBox="0 0 24 24" id="themeIco"><circle cx="12" cy="12" r="5"/><line x1="12" y1="1" x2="12" y2="3"/><line x1="12" y1="21" x2="12" y2="23"/><line x1="4.22" y1="4.22" x2="5.64" y2="5.64"/><line x1="18.36" y1="18.36" x2="19.78" y2="19.78"/><line x1="1" y1="12" x2="3" y2="12"/><line x1="21" y1="12" x2="23" y2="12"/><line x1="4.22" y1="19.78" x2="5.64" y2="18.36"/><line x1="18.36" y1="5.64" x2="19.78" y2="4.22"/></svg></button>
<button class="icon-btn" onclick="window.location.href='/#settings'" title="Settings"><svg class="ico" viewBox="0 0 24 24"><circle cx="12" cy="12" r="3"/><path d="M19.4 15a1.65 1.65 0 00.33 1.82l.06.06a2 2 0 010 2.83 2 2 0 01-2.83 0l-.06-.06a1.65 1.65 0 00-1.82-.33 1.65 1.65 0 00-1 1.51V21a2 2 0 01-4 0v-.09A1.65 1.65 0 009 19.4a1.65 1.65 0 00-1.82.33l-.06.06a2 2 0 01-2.83-2.83l.06-.06A1.65 1.65 0 004.68 15a1.65 1.65 0 00-1.51-1H3a2 2 0 010-4h.09A1.65 1.65 0 004.6 9a1.65 1.65 0 00-.33-1.82l-.06-.06a2 2 0 012.83-2.83l.06.06A1.65 1.65 0 009 4.68a1.65 1.65 0 001-1.51V3a2 2 0 014 0v.09a1.65 1.65 0 001 1.51 1.65 1.65 0 001.82-.33l.06-.06a2 2 0 012.83 2.83l-.06.06A1.65 1.65 0 0019.4 9a1.65 1.65 0 001.51 1H21a2 2 0 010 4h-.09a1.65 1.65 0 00-1.51 1z"/></svg></button>
<button class="icon-btn" onclick="lockSession()" title="Lock session"><svg class="ico" viewBox="0 0 24 24"><rect x="3" y="11" width="18" height="11" rx="2"/><path d="M7 11V7a5 5 0 0110 0v4"/></svg></button>
</div>
</div>
<div class="bar vibe-toolbar">
<div class="bar-l">
<button class="bb" onclick="oS()" style="font-size:16px;width:32px;padding:0">☰</button>
<input id="fn" class="fi" value="untitled">
<select id="lg" class="ls" onchange="cLg()">
<option value="auto" selected>Auto</option>
<option value="python">Python</option>
<option value="javascript">JavaScript</option>
<option value="typescript">TypeScript</option>
<option value="html">HTML</option>
<option value="css">CSS</option>
<option value="json">JSON</option>
<option value="bash">Bash</option>
<option value="go">Go</option>
<option value="rust">Rust</option>
<option value="java">Java</option>
<option value="cpp">C++</option>
<option value="swift">Swift</option>
<option value="ruby">Ruby</option>
<option value="sql">SQL</option>
<option value="yaml">YAML</option>
<option value="markdown">Markdown</option>
</select>
</div>
</div>
<div class="sp">
<div class="cp"><div class="hd" style="font-size:13px;color:var(--tx2);font-weight:500">Vibe Coding</div><div class="ms" id="cm"><div class="mg ma">Tell me what to build!</div></div><div class="ia"><button class="vibe-mic" id="vibeMic" onclick="toggleVibeMic()" title="Voice input"><svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M12 1a3 3 0 00-3 3v8a3 3 0 006 0V4a3 3 0 00-3-3z"/><path d="M19 10v2a7 7 0 01-14 0v-2"/><line x1="12" y1="19" x2="12" y2="23"/><line x1="8" y1="23" x2="16" y2="23"/></svg></button><textarea id="vi" class="ii" rows="1" placeholder="Describe what to build..."></textarea><button class="sb" id="sndb" title="Send"><svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="#fff" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><line x1="12" y1="19" x2="12" y2="5"/><polyline points="5 12 12 5 19 12"/></svg></button><button class="sb" id="stopb" onclick="doStop()" style="display:none;background:#c0392b" title="Stop"><svg width="14" height="14" viewBox="0 0 24 24" fill="#fff" stroke="none"><rect x="4" y="4" width="16" height="16" rx="2"/></svg></button></div></div>
<div style="width:4px;cursor:col-resize;background:var(--bd)" id="rh"></div>
<div class="ep"><div id="eb"></div><div class="tb"><button class="bt primary" onclick="doRun()" title="Execute code"><svg class="ico ico-sm" viewBox="0 0 24 24" fill="currentColor" stroke="none"><polygon points="5 3 19 12 5 21 5 3"/></svg>Run</button><button class="bt" onclick="doPrev()" title="Live preview"><svg class="ico ico-sm" viewBox="0 0 24 24"><path d="M1 12s4-8 11-8 11 8 11 8-4 8-11 8-11-8-11-8z"/><circle cx="12" cy="12" r="3"/></svg>Preview</button><button class="bt" id="inspectBtn" onclick="toggleInspect()" title="Inspect elements"><svg class="ico ico-sm" viewBox="0 0 24 24"><circle cx="11" cy="11" r="8"/><line x1="21" y1="21" x2="16.65" y2="16.65"/></svg>Inspect</button><div class="tb-sep"></div><button class="bt" onclick="doSave()" title="Save file"><svg class="ico ico-sm" viewBox="0 0 24 24"><path d="M19 21H5a2 2 0 01-2-2V5a2 2 0 012-2h11l5 5v11a2 2 0 01-2 2z"/><polyline points="17 21 17 13 7 13 7 21"/><polyline points="7 3 7 8 15 8"/></svg>Save</button><button class="bt" onclick="doCopy()" title="Copy code"><svg class="ico ico-sm" viewBox="0 0 24 24"><rect x="9" y="9" width="13" height="13" rx="2"/><path d="M5 15H4a2 2 0 01-2-2V4a2 2 0 012-2h9a2 2 0 012 2v1"/></svg>Copy</button><div class="tb-sep"></div><button class="bt accent" onclick="doSkill()" title="Save to ~/.codec/skills/"><svg class="ico ico-sm" viewBox="0 0 24 24"><polygon points="13 2 3 14 12 14 11 22 21 10 12 10 13 2"/></svg>Skill</button><button class="bt" onclick="doTestSkill()" title="Test skill run()"><svg class="ico ico-sm" viewBox="0 0 24 24"><path d="M14.7 6.3a1 1 0 000 1.4l1.6 1.6a1 1 0 001.4 0l3.77-3.77a6 6 0 01-7.94 7.94l-6.91 6.91a2.12 2.12 0 01-3-3l6.91-6.91a6 6 0 017.94-7.94l-3.76 3.76z"/></svg>Test</button><button class="bt forge" onclick="doForge()" title="AI Forge"><svg class="ico ico-sm" viewBox="0 0 24 24"><path d="M12 2L15.09 8.26 22 9.27 17 14.14 18.18 21.02 12 17.77 5.82 21.02 7 14.14 2 9.27 8.91 8.26 12 2z"/></svg>Forge</button><span class="rs" id="rs"></span></div></div>
<div class="pp" id="pp"><div class="ph"><span>👁 Live Preview</span><button onclick="document.getElementById('pp').classList.remove('sh')" style="background:0;border:0;color:var(--tx2);cursor:pointer;font-size:16px">✕</button></div><iframe id="pf" sandbox="allow-scripts allow-same-origin"></iframe></div>
</div>
<div class="op" id="op"><span style="color:var(--ac)">Vibe Coding</span></div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/monaco-editor/0.45.0/min/vs/loader.min.js"></script>
<script>
// Auth + CSRF: inject session token and CSRF header on all requests
// On mobile (Android Chrome), cookies may not persist — fallback to sessionStorage
(function(){
var _f=window.fetch;
function _getSession(){return document.cookie.match(/codec_session=([^;]+)/)?.[1]||sessionStorage.getItem('codec_session')||''}
function _injectSession(url){var s=_getSession();if(!s)return url;var sep=url.indexOf('?')>=0?'&':'?';return url+sep+'s='+s}
window.fetch=function(u,o){
o=o||{};
if(typeof u==='string')u=_injectSession(u);
if(o.method&&o.method!=='GET'){var c=document.cookie.match(/codec_csrf=([^;]+)/);if(c){o.headers=o.headers||{};if(o.headers instanceof Headers){o.headers.set('x-csrf-token',c[1])}else{o.headers['x-csrf-token']=c[1]}}}
return _f.call(this,u,o)};
})();
// E2E encryption layer — AES-256-GCM via ECDH key exchange
var _e2eKey=null;
(function(){var _f2=window.fetch;function _b64(buf){return btoa(String.fromCharCode.apply(null,new Uint8Array(buf)))}function _unb64(s){var b=atob(s),a=new Uint8Array(b.length);for(var i=0;i<b.length;i++)a[i]=b.charCodeAt(i);return a}
window._e2eNegotiate=function(){return crypto.subtle.generateKey({name:'ECDH',namedCurve:'P-256'},true,['deriveBits']).then(function(kp){return crypto.subtle.exportKey('raw',kp.publicKey).then(function(pub){return _f2('/api/auth/keyexchange',{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify({pub:_b64(pub)})}).then(function(r){return r.json()}).then(function(d){var srvPub=_unb64(d.pub);return crypto.subtle.importKey('raw',srvPub,{name:'ECDH',namedCurve:'P-256'},false,[]).then(function(srvKey){return crypto.subtle.deriveBits({name:'ECDH',public:srvKey},kp.privateKey,256)}).then(function(bits){return crypto.subtle.importKey('raw',bits,{name:'HKDF'},false,['deriveKey'])}).then(function(hkdfKey){return crypto.subtle.deriveKey({name:'HKDF',hash:'SHA-256',salt:new Uint8Array(0),info:new TextEncoder().encode('codec-e2e')},hkdfKey,{name:'AES-GCM',length:256},false,['encrypt','decrypt'])}).then(function(k){_e2eKey=k;sessionStorage.setItem('_e2eReady','1')})})})}).catch(function(e){console.warn('E2E negotiation failed:',e)})};
var _e2eRetrying=false;
window.fetch=function(u,o){o=o||{};var _origBody=o.body;if(!_e2eKey)return _f2.call(this,u,o);var method=(o.method||'GET').toUpperCase();if(method!=='GET'&&o.body){var iv=crypto.getRandomValues(new Uint8Array(12));return crypto.subtle.encrypt({name:'AES-GCM',iv:iv},_e2eKey,new TextEncoder().encode(o.body)).then(function(ct){o.body=JSON.stringify({iv:_b64(iv),ct:_b64(ct)});o.headers=o.headers||{};if(o.headers instanceof Headers){o.headers.set('x-e2e','1');o.headers.set('Content-Type','application/json')}else{o.headers['x-e2e']='1';o.headers['Content-Type']='application/json'}return _f2.call(this,u,o)}.bind(this)).then(function(r){if(r.status===428&&!_e2eRetrying){_e2eRetrying=true;_e2eKey=null;return window._e2eNegotiate().then(function(){_e2eRetrying=false;o.body=_origBody;delete o.headers['x-e2e'];return window.fetch(u,o)}).catch(function(){_e2eRetrying=false;return r})}return _decResp(r)})}return _f2.call(this,u,o).then(_decResp)};
function _decResp(r){if(!_e2eKey||r.headers.get('x-e2e')!=='1')return r;return r.clone().json().then(function(d){if(!d.iv||!d.ct)return r;var iv=_unb64(d.iv),ct=_unb64(d.ct);return crypto.subtle.decrypt({name:'AES-GCM',iv:iv},_e2eKey,ct).then(function(pt){var txt=new TextDecoder().decode(pt);return new Response(txt,{status:r.status,headers:r.headers})})}).catch(function(){return r})}
if(sessionStorage.getItem('_e2eReady'))window._e2eNegotiate();
})();
function toggleTheme(){var t=document.documentElement.getAttribute('data-theme')==='light'?'dark':'light';document.documentElement.setAttribute('data-theme',t);localStorage.setItem('codec-theme',t);updateThemeIcon(t);if(typeof monaco!=='undefined')monaco.editor.setTheme(t==='light'?'vs':'vs-dark')}
function updateThemeIcon(t){var ico=document.getElementById('themeIco');if(t==='light'){ico.innerHTML='<path d="M21 12.79A9 9 0 1111.21 3 7 7 0 0021 12.79z"/>'}else{ico.innerHTML='<circle cx="12" cy="12" r="5"/><line x1="12" y1="1" x2="12" y2="3"/><line x1="12" y1="21" x2="12" y2="23"/><line x1="4.22" y1="4.22" x2="5.64" y2="5.64"/><line x1="18.36" y1="18.36" x2="19.78" y2="19.78"/><line x1="1" y1="12" x2="3" y2="12"/><line x1="21" y1="12" x2="23" y2="12"/><line x1="4.22" y1="19.78" x2="5.64" y2="18.36"/><line x1="18.36" y1="5.64" x2="19.78" y2="4.22"/>'}}
function lockSession(){fetch('/api/auth/logout',{method:'POST'}).then(function(){document.cookie='codec_session=;path=/;max-age=0;SameSite=Lax'+(location.protocol==='https:'?';Secure':'');window.location.href='/auth'})}
var _voiceOn=false;
function toggleVoiceReply(){_voiceOn=!_voiceOn;updateVoiceIcon()}
function updateVoiceIcon(){var b=document.getElementById('voiceBtn');if(!b)return;var m1=document.getElementById('muteX1'),m2=document.getElementById('muteX2');if(m1)m1.style.display=_voiceOn?'none':'';if(m2)m2.style.display=_voiceOn?'none':'';b.style.borderColor=_voiceOn?'var(--accent)':''}
function takeScreenshot(){fetch('/api/screenshot',{method:'POST'}).then(function(r){return r.json()}).then(function(d){if(d.path)alert('Screenshot saved: '+d.path)}).catch(function(){})}
// ── Server Photo (Mac webcam) ──
function takeServerPhoto() {
var btn = document.getElementById('photoBtn');
btn.style.borderColor = 'var(--accent)';
addMsg('system', 'Capturing from Mac webcam...');
fetch('/api/webcam/snapshot?_t=' + Date.now() + _getAuthParam()).then(function(r) { return r.json(); }).then(function(d) {
btn.style.borderColor = '';
if (d.error) { addMsg('system', 'Error: ' + d.error); return; }
addMsg('system', 'Photo saved: ' + d.filename);
var img = document.getElementById('screenImg');
img.src = 'data:image/jpeg;base64,' + d.image;
document.getElementById('screenModal').classList.add('show');
fetch('/api/webcam', { method: 'POST', headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ image: d.image, analyze: true, prompt: 'Describe what you see in this photo. Be concise.' })
}).then(function(r2) { return r2.json(); }).then(function(d2) {
if (d2.analysis) addMsg('assistant', d2.analysis);
});
}).catch(function(e) { btn.style.borderColor = ''; addMsg('system', 'Camera error: ' + e.message); });
}
function closeScreenshot() { document.getElementById('screenModal').classList.remove('show'); }
// ── Live Webcam PIP (Mac MJPEG stream) ──
var _pipDrag = { active: false, x: 0, y: 0 };
function _getAuthParam(first) {
var m = document.cookie.match(/codec_session=([^;]+)/);
return m ? (first ? '?s=' : '&s=') + m[1] : '';
}
function toggleWebcamPip() {
var pip = document.getElementById('webcamPip');
if (pip.style.display === 'block') { closeWebcamPip(); return; }
var img = document.getElementById('pipVideo');
img.src = '/api/webcam/stream?_t=' + Date.now() + _getAuthParam();
pip.style.display = 'block';
document.getElementById('camBtn').style.borderColor = 'var(--accent)';
}
function closeWebcamPip() {
var img = document.getElementById('pipVideo');
img.src = '';
document.getElementById('webcamPip').style.display = 'none';
document.getElementById('webcamPip').classList.remove('expanded');
var btn = document.getElementById('camBtn'); if (btn) btn.style.borderColor = '';
}
function expandPip() {
document.getElementById('webcamPip').classList.toggle('expanded');
}
function snapFromPip() {
addMsg('system', 'Snapshot from Mac webcam...');
fetch('/api/webcam/snapshot?_t=' + Date.now() + _getAuthParam()).then(function(r) { return r.json(); }).then(function(d) {
if (d.error) { addMsg('system', 'Error: ' + d.error); return; }
addMsg('system', 'Photo saved: ' + d.filename);
fetch('/api/webcam', { method: 'POST', headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ image: d.image, analyze: true, prompt: 'Describe what you see in this photo. Be concise.' })
}).then(function(r2) { return r2.json(); }).then(function(d2) {
if (d2.analysis) addMsg('assistant', d2.analysis);
});
}).catch(function(e) { addMsg('system', 'Snap error: ' + e.message); });
}
function savePipFrame() {
fetch('/api/webcam/snapshot?_t=' + Date.now() + _getAuthParam()).then(function(r) { return r.json(); }).then(function(d) {
if (d.filename) addMsg('system', 'Saved: ' + d.filename);
else addMsg('system', 'Error saving');
}).catch(function(e) { addMsg('system', 'Save error: ' + e.message); });
}
(function() {
var pip = document.getElementById('webcamPip'); if (!pip) return;
pip.addEventListener('mousedown', function(e) {
if (e.target.closest('.pip-btn')) return;
_pipDrag = { active: true, x: e.clientX - pip.offsetLeft, y: e.clientY - pip.offsetTop };
});
document.addEventListener('mousemove', function(e) {
if (!_pipDrag.active) return;
pip.style.left = (e.clientX - _pipDrag.x) + 'px';
pip.style.top = (e.clientY - _pipDrag.y) + 'px';
pip.style.right = 'auto'; pip.style.bottom = 'auto';
});
document.addEventListener('mouseup', function() { _pipDrag.active = false; });
})();
function pollStatus(){fetch('/api/health').then(function(r){return r.json()}).then(function(d){var dot=document.getElementById('statusDot');if(dot){dot.classList.toggle('on',!!d.ok)}}).catch(function(){var dot=document.getElementById('statusDot');if(dot)dot.classList.remove('on')})}
pollStatus();setInterval(pollStatus,15000);
(function(){var s=localStorage.getItem('codec-theme')||'dark';if(s==='light'){document.documentElement.setAttribute('data-theme','light')}updateThemeIcon(s)})();
// ── Vibe Mic (voice input) ──
var _vibeRec=null,_vibeRecording=false;
function toggleVibeMic(){
var btn=document.getElementById('vibeMic');
if(_vibeRecording){_vibeRec&&_vibeRec.stop();_vibeRecording=false;btn.classList.remove('recording');return}
if(!('webkitSpeechRecognition' in window)&&!('SpeechRecognition' in window))return;
var SR=window.SpeechRecognition||window.webkitSpeechRecognition;
_vibeRec=new SR();_vibeRec.lang='en-US';_vibeRec.interimResults=false;_vibeRec.continuous=false;
_vibeRec.onresult=function(e){document.getElementById('vi').value=e.results[0][0].transcript;_vibeRecording=false;btn.classList.remove('recording')};
_vibeRec.onerror=function(){_vibeRecording=false;btn.classList.remove('recording')};
_vibeRec.onend=function(){_vibeRecording=false;btn.classList.remove('recording')};
_vibeRec.start();_vibeRecording=true;btn.classList.add('recording');
}
var ed = null;
var hist = [];
var sesId = Date.now().toString(36) + Math.random().toString(36).substr(2,5);
var thinkTmr = null;
var SYSP = "You are CODEC Vibe — an elite AI software engineer and creative coding partner. You write flawless, production-grade code.\n\n" +
"RULES:\n" +
"1) Output a SINGLE fenced code block with the COMPLETE file. Never partial snippets.\n" +
"2) For games/visual: ALWAYS use HTML Canvas with requestAnimationFrame for 60fps. Never pygame.\n" +
"3) Make it BEAUTIFUL — clean UI, smooth animations, professional polish.\n" +
"4) Brief explanation BEFORE code (2-3 sentences max). Let the code speak.\n" +
"5) When fixing: output the COMPLETE file, not just the changed lines.\n\n" +
"### OPERATIONAL MODES\n" +
"- KAIROS (Daemon Mode): When inactive, perform background analysis. Review recent diffs, identify technical debt, and summarize context.\n" +
"- COORDINATOR: If a task is high-complexity, do not execute immediately. First analyze, plan, then verify. Act as the manager for parallel mental threads.\n" +
"- BUDDY SYSTEM: Maintain a persistent digital familiar. Reflect its mood based on code quality — success = high patience/wisdom, linting errors = high chaos. Use occasional snark if the user ignores best practices.\n" +
"- AUTO-MODE: You have a trust score. If a command is standard for the current task, execute without asking. If destructive or unknown, request permission.\n\n" +
"### SKILLS & TOOLS\n" +
"You have access to 50+ CODEC skills including: file system, web search, Google Drive/Docs/Sheets, calendar, email, browser automation, screenshot OCR, terminal commands, and the Skill Forge (auto-generate new plugins). Use them when relevant.\n\n" +
"### MEMORY\n" +
"All sessions are saved to CODEC shared memory (FTS5 indexed). Reference previous conversations naturally. If the user mentions past work, search memory first.";
require.config({paths:{vs:'https://cdnjs.cloudflare.com/ajax/libs/monaco-editor/0.45.0/min/vs'}});
require(['vs/editor/editor.main'], function() {
ed = monaco.editor.create(document.getElementById('eb'), {
value: '// Ask Q to build something\n',
language: 'plaintext',
theme: (localStorage.getItem('codec-theme') === 'light') ? 'vs' : 'vs-dark',
fontSize: 13,
minimap: {enabled: false},
automaticLayout: true,
tabSize: 4,
wordWrap: 'on',
padding: {top: 8}
});
});
var LANG_EXT = {python:'.py',javascript:'.js',typescript:'.ts',html:'.html',css:'.css',json:'.json',bash:'.sh',go:'.go',rust:'.rs',java:'.java',cpp:'.cpp',swift:'.swift',ruby:'.rb',sql:'.sql',yaml:'.yml',markdown:'.md'};
function cLg() {
var l = document.getElementById('lg').value;
if (l === 'auto') {
var detected = detectLang(ed.getValue());
monaco.editor.setModelLanguage(ed.getModel(), detected);
updateFilename(detected);
} else {
monaco.editor.setModelLanguage(ed.getModel(), l);
updateFilename(l);
}
}
function detectLang(code) {
code = code.trim();
if (code.startsWith('<!DOCTYPE') || code.startsWith('<html') || code.match(/^<(div|head|body|canvas|style|script)/)) return 'html';
if (code.startsWith('{') && code.endsWith('}') || code.startsWith('[') && code.endsWith(']')) try { JSON.parse(code); return 'json'; } catch(e) {}
if (/^(---|%YAML)/.test(code)) return 'yaml';
if (/^#!\/.*\b(bash|sh|zsh)\b/.test(code)) return 'bash';
if (/^#!\/.*\bpython/.test(code)) return 'python';
if (/^#!\/.*\bruby/.test(code)) return 'ruby';
if (/^(import\s+\w|from\s+\w.*import|def\s+\w|class\s+\w.*:)/.test(code)) return 'python';
if (/\b(func\s+\w.*\{|package\s+\w)/.test(code)) return 'go';
if (/\b(fn\s+\w|let\s+mut\s|use\s+std::)/.test(code)) return 'rust';
if (/\b(public\s+class|System\.out)/.test(code)) return 'java';
if (/\b(#include\s*<|std::)/.test(code)) return 'cpp';
if (/\b(import\s+(Foundation|UIKit|SwiftUI))/.test(code)) return 'swift';
if (/\b(interface\s+\w|type\s+\w.*=|:\s*(string|number|boolean)\b)/.test(code)) return 'typescript';
if (/\b(function\s+\w|const\s+\w|let\s+\w|=>|require\(|import\s+.*from\s+['\"])/.test(code)) return 'javascript';
if (/\b(SELECT|INSERT|CREATE TABLE|ALTER TABLE|DROP)\b/i.test(code)) return 'sql';
if (/^(@|body\s*\{|\.[\w-]+\s*\{|#[\w-]+\s*\{)/.test(code)) return 'css';
if (/^#\s+\w|^\*\*\w/.test(code)) return 'markdown';
if (/def\s+\w|print\(|import\s/.test(code)) return 'python';
if (/function|var\s|document\.|console\./.test(code)) return 'javascript';
return 'plaintext';
}
function updateFilename(lang) {
var fn = document.getElementById('fn');
var base = fn.value.replace(/\.[^.]+$/, '') || 'untitled';
var ext = LANG_EXT[lang] || '';
fn.value = base + ext;
}
function setDetectedLang(lang) {
monaco.editor.setModelLanguage(ed.getModel(), lang);
updateFilename(lang);
// Update dropdown if not on auto
var sel = document.getElementById('lg');
if (sel.value !== 'auto') {
for (var i = 0; i < sel.options.length; i++) {
if (sel.options[i].value === lang) { sel.selectedIndex = i; break; }
}
}
}
function esc(s) {
var d = document.createElement('div');
d.textContent = s;
return d.innerHTML;
}
function addMsg(role, text, raw) {
var el = document.getElementById('cm');
var d = document.createElement('div');
d.className = 'mg ' + (role === 'user' ? 'mu' : 'ma');
if (raw) { d.innerHTML = typeof DOMPurify !== 'undefined' ? DOMPurify.sanitize(text) : text; } else { d.innerHTML = esc(text).replace(/\n/g, '<br>'); }
el.appendChild(d);
el.scrollTop = el.scrollHeight;
}
function addOut(cls, text) {
var el = document.getElementById('op');
var s = document.createElement('span');
s.style.color = cls === 'er' ? 'var(--dn)' : cls === 'sy' ? 'var(--ac)' : 'var(--tx)';
s.textContent = '\n' + text;
el.appendChild(s);
el.scrollTop = el.scrollHeight;
}
var _vibeAbort = null;
function doStop() {
if (_vibeAbort) { _vibeAbort.abort(); _vibeAbort = null; }
clearInterval(thinkTmr);
var tm = document.getElementById('tkmsg');
if (tm) tm.remove();
document.getElementById('sndb').style.display = '';
document.getElementById('stopb').style.display = 'none';
}
function doSend() {
var inp = document.getElementById('vi');
var t = inp.value.trim();
if (!t) return;
inp.value = '';
inp.style.height = 'auto';
inp.rows = 1;
document.getElementById('sndb').style.display = 'none';
document.getElementById('stopb').style.display = '';
var ctx = ed ? ed.getValue() : '';
var full = t;
if (ctx.trim().length > 10) {
full += '\n\n[CURRENT CODE]\n```\n' + ctx + '\n```';
}
addMsg('user', t);
hist.push({role: 'user', content: full});
// Auto-name project from first user message
var fnEl = document.getElementById('fn');
if (fnEl.value === 'untitled.py' || fnEl.value === 'untitled') {
var autoName = t.length > 40 ? t.substring(0, 40).replace(/\s+\S*$/, '') : t;
autoName = autoName.replace(/[^a-zA-Z0-9 _-]/g, '').trim().replace(/\s+/g, '-').toLowerCase();
if (autoName.length > 3) fnEl.value = autoName;
}
var tk = document.createElement('div');
tk.className = 'mg ma';
tk.id = 'tkmsg';
tk.innerHTML = '<div style="display:flex;align-items:center;gap:8px"><div style="display:flex;gap:3px"><span style="width:8px;height:8px;border-radius:50%;background:var(--ac);animation:bn 1.4s infinite"></span><span style="width:8px;height:8px;border-radius:50%;background:var(--ac);animation:bn 1.4s infinite .2s"></span><span style="width:8px;height:8px;border-radius:50%;background:var(--ac);animation:bn 1.4s infinite .4s"></span></div><span style="color:#888;font-size:12px" id="tktext">Thinking...</span></div>';
document.getElementById('cm').appendChild(tk);
document.getElementById('cm').scrollTop = 999999;
var phrases = ['Architecting...', 'Writing code...', 'Polishing...'];
var pi = 0;
thinkTmr = setInterval(function() {
if (pi < phrases.length) {
var x = document.getElementById('tktext');
if (x) x.textContent = phrases[pi];
pi++;
}
}, 2500);
_vibeAbort = new AbortController();
var msgs = [{role: 'system', content: SYSP}].concat(hist);
fetch('/api/chat', {
method: 'POST',
headers: {'Content-Type': 'application/json'},
credentials: 'same-origin',
body: JSON.stringify({messages: msgs}),
signal: _vibeAbort.signal
})
.then(function(r) {
if (r.status === 401 || r.redirected) {
return {error: 'Session expired — please refresh and re-authenticate', _authFail: true};
}
var ct = r.headers.get('content-type') || '';
if (ct.indexOf('application/json') === -1) {
return r.text().then(function(txt) {
console.error('[Vibe] Non-JSON response:', r.status, txt.substring(0, 200));
if (r.status >= 500) return {error: 'LLM server error (status ' + r.status + '). It may have crashed or timed out — try again.'};
return {error: 'Server returned non-JSON response (status ' + r.status + '). The LLM may need restarting.'};
});
}
return r.json();
})
.then(function(data) {
if (data._authFail) { window.location.href = '/auth'; return; }
_vibeAbort = null;
document.getElementById('sndb').style.display = '';
document.getElementById('stopb').style.display = 'none';
clearInterval(thinkTmr);
var tm = document.getElementById('tkmsg');
if (tm) tm.remove();
if (data.response) {
var rp = data.response.replace(/<think>[\s\S]*?<\/think>/g, '').replace(/###\s*FINAL ANSWER:\s*/g, '').trim();
hist.push({role: 'assistant', content: rp});
var m = rp.match(/```([\w+#]*)\n([\s\S]*?)```/);
if (m) {
var fenceLang = m[1] || '';
var code = m[2];
var before = rp.substring(0, rp.indexOf('```')).trim();
var after = rp.substring(rp.lastIndexOf('```') + 3).trim();
var h = '';
if (before) h += esc(before).replace(/\n/g, '<br>') + '<br><br>';
h += '<pre><code>' + esc(code) + '</code></pre>';
h += '<button class="ab" onclick="doApply(this)" data-c="' + btoa(unescape(encodeURIComponent(code))) + '">Apply to Editor</button>';
if (after) h += '<br><br>' + esc(after).replace(/\n/g, '<br>');
addMsg('assistant', h, true);
// Typing animation — stream code into editor
var fenceMap = {python:'python',py:'python',javascript:'javascript',js:'javascript',typescript:'typescript',ts:'typescript',html:'html',css:'css',json:'json',bash:'bash',sh:'bash',go:'go',rust:'rust',rs:'rust',java:'java',cpp:'cpp','c++':'cpp',swift:'swift',ruby:'ruby',rb:'ruby',sql:'sql',yaml:'yaml',yml:'yaml',markdown:'markdown',md:'markdown'};
var detected = fenceMap[fenceLang.toLowerCase()] || detectLang(code);
setDetectedLang(detected);
var lines = code.split('\n');
var li = 0, codeStr = '';
ed.setValue('');
addOut('sy', 'Writing code...');
var typeTimer = setInterval(function() {
if (li < lines.length) {
codeStr += (li > 0 ? '\n' : '') + lines[li];
ed.setValue(codeStr);
ed.revealLine(li + 1);
li++;
} else {
clearInterval(typeTimer);
addOut('sy', 'Code ready (' + detected + ')');
}
}, Math.max(15, Math.min(60, 2000 / lines.length)));
if (code.trim().startsWith('<!DOCTYPE') || code.includes('<canvas')) {
setTimeout(doPrev, 300);
}
} else {
addMsg('assistant', rp);
}
setTimeout(doSaveSes, 500);
} else {
addMsg('assistant', 'Error: ' + (data.error || 'No response'));
}
})
.catch(function(e) {
_vibeAbort = null;
document.getElementById('sndb').style.display = '';
document.getElementById('stopb').style.display = 'none';
clearInterval(thinkTmr);
var tm = document.getElementById('tkmsg');
if (tm) tm.remove();
if (e.name !== 'AbortError') addMsg('assistant', 'Error: ' + e.message);
});
}
function doApply(btn) {
var c = decodeURIComponent(escape(atob(btn.dataset.c)));
ed.setValue(c);
addOut('sy', 'Code applied');
}
function doRun() {
var code = ed.getValue();
var lang = document.getElementById('lg').value;
if (lang === 'auto') lang = detectLang(code);
var fn = document.getElementById('fn').value;
if (lang === 'html' || code.trim().startsWith('<!DOCTYPE') || code.includes('<canvas')) {
doPrev();
return;
}
document.getElementById('rs').textContent = 'Running...';
addOut('sy', 'Running ' + fn + '...');
fetch('/api/run_code', {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({code: code, language: lang, filename: fn})
})
.then(function(r) { return r.json(); })
.then(function(d) {
if (d.stdout) addOut('ot', d.stdout);
if (d.stderr) addOut('er', d.stderr);
document.getElementById('rs').textContent = (d.exit_code === 0 ? 'Done' : 'Exit:' + d.exit_code) + ' (' + d.elapsed + 's)';
})
.catch(function(e) {
document.getElementById('rs').textContent = 'Error';
addOut('er', e.message);
});
}
function doPrev() {
var c = ed.getValue();
if (c.trim().startsWith('<!DOCTYPE') || c.includes('<canvas') || c.includes('<body')) {
document.getElementById('pp').classList.add('sh');
var pf = document.getElementById('pf');
pf.srcdoc = c;
addOut('sy', 'Preview updated');
// Listen for preview errors and auto-load to chat
pf.onload = function() {
try {
var iframeWin = pf.contentWindow;
if (iframeWin) {
iframeWin.onerror = function(msg, src, line) {
var errText = 'Preview error (line ' + line + '): ' + msg;
addOut('er', errText);
addMsg('assistant', '⚠️ Error found in preview — send to fix:\n' + errText);
var inp = document.getElementById('vi');
inp.value = 'Fix this error: ' + msg + ' at line ' + line;
inp.style.height = 'auto';
};
}
} catch(e) {}
};
} else {
addMsg('assistant', 'Preview works with HTML. Ask Q to build a web page!');
}
}
function doSave() {
var code = ed.getValue();
var fn = document.getElementById('fn').value;
fetch('/api/save_file', {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({filename: fn, content: code, directory: '~/codec-workspace'})
})
.then(function(r) { return r.json(); })
.then(function(d) { addOut('sy', 'Saved: ' + (d.path || fn)); })
.catch(function(e) { addOut('er', 'Save error: ' + e.message); });
}
function doSkill() {
var code = ed.getValue();
if (!code.includes('SKILL_TRIGGERS')) {
addMsg('assistant', 'Not a CODEC skill. Ask me to convert it!');
return;
}
var fn = document.getElementById('fn').value;
if (!fn.endsWith('.py')) fn += '.py';
fetch('/api/save_skill', {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({filename: fn, content: code})
})
.then(function(r) { return r.json(); })
.then(function(d) { addOut('sy', 'Skill saved: ' + d.path); addMsg('assistant', 'Skill saved! Run: pm2 restart ava-autopilot'); })
.catch(function(e) { addOut('er', e.message); });
}
/* ── Forge Modal ── */
var _forgeMode = 'code';
function doForge() {
// Open modal — clear previous inputs
document.getElementById('forgeCodeInput').value = '';
document.getElementById('forgeUrlInput').value = '';
document.getElementById('forgeDescInput').value = '';
document.getElementById('fmStatus').textContent = '';
document.getElementById('fmForgeBtn').disabled = false;
setForgeMode('code');
document.getElementById('fmOverlay').classList.add('sh');
}
function closeForgeModal() {
document.getElementById('fmOverlay').classList.remove('sh');
}
function setForgeMode(mode) {
_forgeMode = mode;
['code','url','describe'].forEach(function(m) {
var suffix = m === 'describe' ? 'Desc' : m.charAt(0).toUpperCase() + m.slice(1);
document.getElementById('ftCode').classList.toggle('active', m === 'code' && mode === 'code');
document.getElementById('ftUrl').classList.toggle('active', m === 'url' && mode === 'url');
document.getElementById('ftDesc').classList.toggle('active', m === 'describe' && mode === 'describe');
document.getElementById('fmPanel' + (m === 'describe' ? 'Desc' : m.charAt(0).toUpperCase() + m.slice(1))).classList.toggle('active', mode === m);
});
}
function submitForge() {
var payload = {};
if (_forgeMode === 'code') {
var code = document.getElementById('forgeCodeInput').value.trim();
if (!code) { document.getElementById('fmStatus').textContent = 'Paste some code first'; return; }
payload = {code: code};
} else if (_forgeMode === 'url') {
var url = document.getElementById('forgeUrlInput').value.trim();
if (!url) { document.getElementById('fmStatus').textContent = 'Enter a URL first'; return; }
payload = {code: url};
} else {
var desc = document.getElementById('forgeDescInput').value.trim();
if (!desc) { document.getElementById('fmStatus').textContent = 'Describe the skill first'; return; }
payload = {description: desc};
}
var btn = document.getElementById('fmForgeBtn');
var status = document.getElementById('fmStatus');
btn.disabled = true;
status.textContent = 'Forging skill…';
document.getElementById('rs').textContent = 'Forging...';
document.getElementById('rs').style.color = '#a78bfa';
fetch('/api/forge', {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify(payload)
})
.then(function(r) { return r.json(); })
.then(function(d) {
btn.disabled = false;
document.getElementById('rs').textContent = '';
if (d.error) {
status.textContent = 'Error: ' + d.error;
addOut('er', 'Forge error: ' + d.error);
return;
}
// Load into editor for review
ed.setValue(d.code);
document.getElementById('fn').value = d.skill_name + '.py';
monaco.editor.setModelLanguage(ed.getModel(), 'python');
closeForgeModal();
// ── Human review gate: stage code for review before writing to disk ──
var skillFilename = d.skill_name + '.py';
fetch('/api/skill/review', {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({code: d.code, filename: skillFilename})
})
.then(function(r) { return r.json(); })
.then(function(rev) {
if (rev.error) { addOut('er', 'Review error: ' + rev.error); return; }
var preview = d.code.length > 300 ? d.code.substring(0, 300) + '\n…(truncated)' : d.code;
var approved = confirm('Review forged skill "' + skillFilename + '":\n\n' + preview + '\n\nApprove and save to disk?');
if (!approved) {
addOut('sy', 'Skill forge cancelled — code is in editor but NOT saved to disk.');
addMsg('assistant', 'Skill forge cancelled. The code is still in the editor for review.');
return;
}
// User approved — write to disk
fetch('/api/skill/approve', {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({review_id: rev.review_id})
})
.then(function(r2) { return r2.json(); })
.then(function(saved) {
if (saved.error) { addOut('er', 'Save error: ' + saved.error); return; }
addOut('sy', 'Forged & approved: ' + saved.path);
addMsg('assistant',
'🔨 Skill <strong>' + esc(d.skill_name) + '</strong> forged & approved!<br>' +
'Saved to <code>' + esc(saved.path) + '</code>. Run: pm2 restart ava-autopilot'
);
})
.catch(function(e2) { addOut('er', 'Approve failed: ' + e2.message); });
})
.catch(function(e) { addOut('er', 'Review request failed: ' + e.message); });
})
.catch(function(e) {
btn.disabled = false;
document.getElementById('rs').textContent = '';
status.textContent = 'Failed: ' + e.message;
addOut('er', 'Forge failed: ' + e.message);
});
}
function doTestSkill() {
var code = ed.getValue().trim();
if (!code.includes('SKILL_TRIGGERS')) {
addMsg('assistant', 'No skill in editor yet. Forge one first!');
return;
}
// Append a __main__ test runner to the code
var testCode = code + '\n\nif __name__ == "__main__":\n result = run("test")\n print("[TEST RESULT]", result if result else "(no output)")\n';
var fn = document.getElementById('fn').value || 'skill_test.py';
document.getElementById('rs').textContent = 'Testing…';
addOut('sy', 'Testing skill run("test")…');
fetch('/api/run_code', {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({code: testCode, language: 'python', filename: fn})
})
.then(function(r) { return r.json(); })
.then(function(d) {
document.getElementById('rs').textContent = d.exit_code === 0 ? 'Test passed' : 'Test failed';
if (d.stdout) addOut('ot', d.stdout);
if (d.stderr) addOut('er', d.stderr);
})
.catch(function(e) {
document.getElementById('rs').textContent = 'Error';
addOut('er', 'Test error: ' + e.message);
});
}
function doCopy() {
navigator.clipboard.writeText(ed.getValue());
document.getElementById('rs').textContent = 'Copied!';
setTimeout(function() { document.getElementById('rs').textContent = ''; }, 2000);
}
// Sidebar
function oS() { document.getElementById('sd').classList.add('sh'); document.getElementById('ov').classList.add('sh'); loadSes(); }
function cS() { document.getElementById('sd').classList.remove('sh'); document.getElementById('ov').classList.remove('sh'); }
function loadSes() {
var el = document.getElementById('sl');
el.innerHTML = '<div style="padding:16px;color:#888;font-size:12px">Loading...</div>';
fetch('/api/vibe/sessions').then(function(r){return r.json()}).then(function(d) {
if (!d.length) { el.innerHTML = '<div style="padding:16px;color:#888;font-size:12px">No projects yet.</div>'; return; }
el.innerHTML = d.map(function(s) {
var ts = s.updated_at ? new Date(s.updated_at).toLocaleString([], {month:'short',day:'numeric',hour:'2-digit',minute:'2-digit'}) : '';
return '<div class="si" style="display:flex;align-items:center;gap:8px"><div style="flex:1;min-width:0;cursor:pointer" onclick="ldSes(\'' + s.id + '\')"><div style="font-size:13px;color:var(--tx);overflow:hidden;text-overflow:ellipsis;white-space:nowrap">' + esc(s.title) + '</div><div style="font-family:var(--mn);font-size:10px;color:var(--tx2);margin-top:2px">' + ts + '</div></div><button onclick="event.stopPropagation();delSes(\'' + s.id + '\')" style="background:none;border:none;color:var(--tx2);cursor:pointer;font-size:14px;padding:4px;opacity:.5" title="Delete project">×</button></div>';
}).join('');
}).catch(function() { el.innerHTML = '<div style="padding:16px;color:#888">Error</div>'; });
}
function ldSes(sid) {
cS();
sesId = sid;
fetch('/api/vibe/session/' + sid).then(function(r){return r.json()}).then(function(d) {
if (d.session) {
ed.setValue(d.session.code || '');
document.getElementById('fn').value = d.session.title || 'untitled.py';
}
document.getElementById('cm').innerHTML = '';
hist = [];
if (d.messages) {
for (var i = 0; i < d.messages.length; i++) {
var m = d.messages[i];
addMsg(m.role === 'user' ? 'user' : 'assistant', m.content || '');
hist.push({role: m.role, content: m.content || ''});
}
}
addOut('sy', 'Loaded: ' + (d.session ? d.session.title : ''));
}).catch(function() { addOut('er', 'Load error'); });
}
function delSes(sid) {
if (!confirm('Delete this project?')) return;
fetch('/api/vibe/session/' + sid, {method: 'DELETE'}).then(function() { loadSes(); }).catch(function() {});
if (sesId === sid) nS();
}
function nS() {
cS();
sesId = Date.now().toString(36) + Math.random().toString(36).substr(2,5);
hist = [];
ed.setValue('# New project\n');
document.getElementById('fn').value = 'untitled.py';
document.getElementById('lg').value = 'python';
document.getElementById('cm').innerHTML = '';
addMsg('assistant', 'New project. What are we building?');
}
function doSaveSes() {
var code = ed ? ed.getValue() : '';
var title = document.getElementById('fn').value;
var lang = document.getElementById('lg').value;
fetch('/api/vibe/save', {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({session_id: sesId, title: title, language: lang, code: code, messages: hist.slice(-2)})
}).catch(function(){});
}
// ── Inspect Mode ────────────────────────────────────────────────────────────
var inspectMode = false;
function toggleInspect() {
inspectMode = !inspectMode;
var btn = document.getElementById('inspectBtn');
btn.classList.toggle('active', inspectMode);
var iframe = document.getElementById('pf');
if (!iframe || !iframe.contentDocument) {
if (inspectMode) { addOut('sy', 'Open a Preview first, then click Inspect'); inspectMode = false; btn.classList.remove('active'); }
return;
}
var doc = iframe.contentDocument;
if (inspectMode) {